aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--po/POTFILES.in116
-rw-r--r--src/arm/Kyuafile9
-rw-r--r--src/arm/gnunet-arm.c30
-rw-r--r--src/arm/gnunet-service-arm.c1071
-rw-r--r--src/arm/test_exponential_backoff.c2
-rw-r--r--src/arm/test_gnunet_service_arm.c8
-rw-r--r--src/ats-tool/gnunet-ats.c427
-rw-r--r--src/cadet/gnunet-cadet-profiler.c2
-rw-r--r--src/cadet/gnunet-cadet.c348
-rw-r--r--src/cadet/test_cadet.c10
-rw-r--r--src/cadet/test_cadet_flow.c10
-rw-r--r--src/conversation/gnunet-conversation.c487
-rw-r--r--src/core/gnunet-core.c8
-rw-r--r--src/core/test_core_api_reliability.c4
-rw-r--r--src/core/test_core_api_start_only.c2
-rw-r--r--src/core/test_core_quota_compliance.c4
-rw-r--r--src/datacache/datacache.c126
-rw-r--r--src/datacache/perf_datacache.c16
-rw-r--r--src/datacache/plugin_datacache_sqlite.c504
-rw-r--r--src/datacache/test_datacache.c4
-rw-r--r--src/datacache/test_datacache_quota.c12
-rw-r--r--src/datastore/gnunet-datastore.c120
-rw-r--r--src/datastore/gnunet-service-datastore.c622
-rw-r--r--src/datastore/perf_datastore_api.c10
-rw-r--r--src/datastore/perf_plugin_datastore.c8
-rw-r--r--src/datastore/plugin_datastore_sqlite.c893
-rw-r--r--src/datastore/test_datastore_api.c10
-rw-r--r--src/datastore/test_datastore_api_management.c4
-rw-r--r--src/datastore/test_plugin_datastore.c8
-rw-r--r--src/dht/gnunet-dht-get.c149
-rw-r--r--src/dht/gnunet-dht-monitor.c110
-rw-r--r--src/dht/gnunet-dht-put.c118
-rw-r--r--src/dht/test_dht_api.c2
-rw-r--r--src/dht/test_dht_topo.c2
-rw-r--r--src/fragmentation/test_fragmentation.c24
-rw-r--r--src/fragmentation/test_fragmentation_parallel.c18
-rw-r--r--src/fs/fs_api.c842
-rw-r--r--src/fs/fs_dirmetascan.c217
-rw-r--r--src/fs/fs_download.c736
-rw-r--r--src/fs/fs_file_information.c181
-rw-r--r--src/fs/fs_namespace.c188
-rw-r--r--src/fs/fs_uri.c400
-rw-r--r--src/fs/gnunet-auto-share.c2
-rw-r--r--src/fs/gnunet-directory.c70
-rw-r--r--src/fs/gnunet-download.c277
-rw-r--r--src/fs/gnunet-fs.c42
-rw-r--r--src/fs/gnunet-helper-fs-publish.c194
-rw-r--r--src/fs/gnunet-publish.c530
-rw-r--r--src/fs/gnunet-search.c173
-rw-r--r--src/fs/gnunet-service-fs_indexing.c248
-rw-r--r--src/fs/gnunet-unindex.c58
-rw-r--r--src/fs/perf_gnunet_service_fs_p2p.c4
-rw-r--r--src/fs/perf_gnunet_service_fs_p2p_respect.c4
-rw-r--r--src/fs/test_fs.c4
-rw-r--r--src/fs/test_fs_directory.c4
-rw-r--r--src/fs/test_fs_download.c6
-rw-r--r--src/fs/test_fs_download_persistence.c4
-rw-r--r--src/fs/test_fs_getopt.c2
-rw-r--r--src/fs/test_fs_list_indexed.c2
-rw-r--r--src/fs/test_fs_namespace.c18
-rw-r--r--src/fs/test_fs_publish.c4
-rw-r--r--src/fs/test_fs_publish_persistence.c2
-rw-r--r--src/fs/test_fs_search.c6
-rw-r--r--src/fs/test_fs_search_persistence.c6
-rw-r--r--src/fs/test_fs_search_probes.c6
-rw-r--r--src/fs/test_fs_search_with_and.c6
-rw-r--r--src/fs/test_fs_unindex.c4
-rw-r--r--src/fs/test_fs_unindex_persistence.c2
-rw-r--r--src/fs/test_fs_uri.c4
-rw-r--r--src/fs/test_gnunet_service_fs_migration.c2
-rw-r--r--src/fs/test_gnunet_service_fs_p2p.c2
-rw-r--r--src/fs/test_plugin_block_fs.c2
-rw-r--r--src/gns/gnunet-bcd.c12
-rw-r--r--src/gns/gnutls_ca.cfg25
-rw-r--r--src/gns/plugin_gnsrecord_gns.c438
-rw-r--r--src/gnsrecord/plugin_gnsrecord_dns.c14
-rw-r--r--src/hello/gnunet-hello.c124
-rw-r--r--src/hostlist/hostlists_learn_peer2.filebin71 -> 72 bytes
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist_learning.c4
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist_reconnect.c4
-rw-r--r--src/identity/gnunet-service-identity.c394
-rw-r--r--src/include/Makefile.am2
-rw-r--r--src/include/gnunet_common.h8
-rw-r--r--src/include/platform.h20
-rw-r--r--src/include/plibc.h980
-rw-r--r--src/json/json.c2
-rw-r--r--src/namecache/gnunet-namecache.c126
-rw-r--r--src/namecache/test_plugin_namecache.c6
-rw-r--r--src/namestore/gnunet-namestore.c24
-rw-r--r--src/namestore/test_plugin_namestore.c6
-rw-r--r--src/nat-auto/gnunet-nat-auto.c149
-rw-r--r--src/nat-auto/nat_auto_api_test.c226
-rw-r--r--src/nat/gnunet-nat.c223
-rw-r--r--src/nat/gnunet-service-nat_helper.c211
-rw-r--r--src/nat/gnunet-service-nat_mini.c263
-rw-r--r--src/nse/gnunet-nse-profiler.c380
-rw-r--r--src/nse/gnunet-nse.c2
-rw-r--r--src/nse/test_nse_api.c2
-rw-r--r--src/nse/test_nse_multipeer.c2
-rw-r--r--src/peerinfo-tool/gnunet-peerinfo.c309
-rw-r--r--src/peerinfo/gnunet-service-peerinfo.c620
-rw-r--r--src/peerinfo/perf_peerinfo_api.c2
-rw-r--r--src/peerstore/test_plugin_peerstore.c6
-rw-r--r--src/reclaim/oidc_helper.c3
-rw-r--r--src/regex/gnunet-regex-simulation-profiler.c8
-rw-r--r--src/regex/test_regex_api.c2
-rw-r--r--src/regex/test_regex_integration.c2
-rw-r--r--src/revocation/gnunet-revocation.c274
-rw-r--r--src/rps/gnunet-rps.c14
-rw-r--r--src/statistics/gnunet-service-statistics.c418
-rw-r--r--src/statistics/gnunet-statistics.c42
-rw-r--r--src/testbed/generate-underlay-topology.c210
-rw-r--r--src/testbed/gnunet-helper-testbed.c2
-rw-r--r--src/testbed/test_testbed_api_3peers_3controllers.c4
-rw-r--r--src/testbed/test_testbed_api_controllerlink.c135
-rw-r--r--src/testbed/testbed_api_hosts.c332
-rw-r--r--src/testing/gnunet-testing.c212
-rw-r--r--src/testing/list-keys.c43
-rw-r--r--src/testing/testing.c450
-rw-r--r--src/topology/test_gnunet_daemon_topology.c2
-rw-r--r--src/transport/gnunet-communicator-tcp.c8
-rw-r--r--src/transport/gnunet-communicator-udp.c4
-rw-r--r--src/transport/gnunet-communicator-unix.c2
-rw-r--r--src/transport/gnunet-helper-transport-wlan-dummy.c36
-rw-r--r--src/transport/gnunet-transport-profiler.c42
-rw-r--r--src/transport/gnunet-transport.c50
-rw-r--r--src/transport/plugin_transport_smtp.c4
-rw-r--r--src/transport/plugin_transport_tcp.c1281
-rw-r--r--src/transport/plugin_transport_udp.c1187
-rw-r--r--src/transport/plugin_transport_unix.c453
-rw-r--r--src/transport/tcp_connection_legacy.c421
-rw-r--r--src/transport/tcp_service_legacy.c458
-rw-r--r--src/transport/test_plugin_hostkeybin914 -> 915 bytes
-rw-r--r--src/transport/test_quota_compliance.c6
-rw-r--r--src/transport/test_transport_address_switch.c18
-rw-r--r--src/transport/test_transport_api_reliability.c4
-rw-r--r--src/transport/test_transport_api_timeout.c4
-rw-r--r--src/transport/test_transport_blacklisting.c2
-rw-r--r--src/util/bio.c133
-rw-r--r--src/util/common_allocation.c199
-rw-r--r--src/util/common_logging.c21
-rw-r--r--src/util/configuration.c451
-rw-r--r--src/util/container_bloomfilter.c205
-rw-r--r--src/util/crypto_ecc_setup.c247
-rw-r--r--src/util/crypto_random.c10
-rw-r--r--src/util/disk.c589
-rw-r--r--src/util/dnsstub.c168
-rw-r--r--src/util/getopt.c32
-rw-r--r--src/util/getopt_helpers.c22
-rw-r--r--src/util/gnunet-ecc.c208
-rw-r--r--src/util/gnunet-resolver.c4
-rw-r--r--src/util/gnunet-scrypt.c4
-rw-r--r--src/util/helper.c221
-rw-r--r--src/util/os_installation.c64
-rw-r--r--src/util/os_priority.c604
-rw-r--r--src/util/perf_crypto_asymmetric.c2
-rw-r--r--src/util/perf_crypto_ecc_dlog.c2
-rw-r--r--src/util/plugin.c41
-rw-r--r--src/util/program.c20
-rw-r--r--src/util/service.c856
-rw-r--r--src/util/strings.c693
-rw-r--r--src/util/test_common_allocation.c2
-rw-r--r--src/util/test_common_logging.c8
-rw-r--r--src/util/test_common_logging_dummy.c2
-rw-r--r--src/util/test_common_logging_runtime_loglevels.c6
-rw-r--r--src/util/test_configuration.c14
-rw-r--r--src/util/test_container_bloomfilter.c30
-rw-r--r--src/util/test_crypto_ecc_dlog.c2
-rw-r--r--src/util/test_crypto_ecdh_eddsa.c2
-rw-r--r--src/util/test_crypto_ecdhe.c2
-rw-r--r--src/util/test_crypto_ecdsa.c18
-rw-r--r--src/util/test_crypto_eddsa.c20
-rw-r--r--src/util/test_crypto_hash.c6
-rw-r--r--src/util/test_crypto_random.c2
-rw-r--r--src/util/test_disk.c16
-rw-r--r--src/util/test_getopt.c119
-rw-r--r--src/util/test_peer.c4
-rw-r--r--src/util/test_resolver_api.c4
-rw-r--r--src/util/test_scheduler.c2
-rw-r--r--src/util/test_scheduler_delay.c14
-rw-r--r--src/util/test_service.c2
-rw-r--r--src/util/test_strings.c2
-rw-r--r--src/util/time.c125
-rw-r--r--src/vpn/gnunet-vpn.c205
185 files changed, 11399 insertions, 14276 deletions
diff --git a/ChangeLog b/ChangeLog
index dff231b7d..d03d3a4fe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
1Fri Sep 6 00:00:00 UTC 2019
2 Remove plibc, closes #5877 as discussed in
3 https://lists.gnu.org/archive/html/gnunet-developers/2019-09/msg00002.html
4 -ng0
5
1Sun Sep 1 13:25:07 2019 +0200 6Sun Sep 1 13:25:07 2019 +0200
2 Improved support for external applications/services wrt 7 Improved support for external applications/services wrt
3 localization/gettext. 8 localization/gettext.
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 2f09e8d80..f363cc68a 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -4,6 +4,14 @@ src/arm/arm_monitor_api.c
4src/arm/gnunet-arm.c 4src/arm/gnunet-arm.c
5src/arm/gnunet-service-arm.c 5src/arm/gnunet-service-arm.c
6src/arm/mockup-service.c 6src/arm/mockup-service.c
7src/ats-tests/ats-testing-experiment.c
8src/ats-tests/ats-testing-log.c
9src/ats-tests/ats-testing-preferences.c
10src/ats-tests/ats-testing-traffic.c
11src/ats-tests/ats-testing.c
12src/ats-tests/gnunet-ats-sim.c
13src/ats-tests/gnunet-solver-eval.c
14src/ats-tool/gnunet-ats.c
7src/ats/ats_api2_application.c 15src/ats/ats_api2_application.c
8src/ats/ats_api2_transport.c 16src/ats/ats_api2_transport.c
9src/ats/ats_api_connectivity.c 17src/ats/ats_api_connectivity.c
@@ -11,10 +19,10 @@ src/ats/ats_api_performance.c
11src/ats/ats_api_scanner.c 19src/ats/ats_api_scanner.c
12src/ats/ats_api_scheduling.c 20src/ats/ats_api_scheduling.c
13src/ats/gnunet-ats-solver-eval.c 21src/ats/gnunet-ats-solver-eval.c
14src/ats/gnunet-service-ats_addresses.c 22src/ats/gnunet-service-ats-new.c
15src/ats/gnunet-service-ats.c 23src/ats/gnunet-service-ats.c
24src/ats/gnunet-service-ats_addresses.c
16src/ats/gnunet-service-ats_connectivity.c 25src/ats/gnunet-service-ats_connectivity.c
17src/ats/gnunet-service-ats-new.c
18src/ats/gnunet-service-ats_normalization.c 26src/ats/gnunet-service-ats_normalization.c
19src/ats/gnunet-service-ats_performance.c 27src/ats/gnunet-service-ats_performance.c
20src/ats/gnunet-service-ats_plugins.c 28src/ats/gnunet-service-ats_plugins.c
@@ -26,14 +34,6 @@ src/ats/plugin_ats2_simple.c
26src/ats/plugin_ats_mlp.c 34src/ats/plugin_ats_mlp.c
27src/ats/plugin_ats_proportional.c 35src/ats/plugin_ats_proportional.c
28src/ats/plugin_ats_ril.c 36src/ats/plugin_ats_ril.c
29src/ats-tests/ats-testing.c
30src/ats-tests/ats-testing-experiment.c
31src/ats-tests/ats-testing-log.c
32src/ats-tests/ats-testing-preferences.c
33src/ats-tests/ats-testing-traffic.c
34src/ats-tests/gnunet-ats-sim.c
35src/ats-tests/gnunet-solver-eval.c
36src/ats-tool/gnunet-ats.c
37src/auction/gnunet-auction-create.c 37src/auction/gnunet-auction-create.c
38src/auction/gnunet-auction-info.c 38src/auction/gnunet-auction-info.c
39src/auction/gnunet-auction-join.c 39src/auction/gnunet-auction-join.c
@@ -50,8 +50,8 @@ src/cadet/cadet_api_list_peers.c
50src/cadet/cadet_api_list_tunnels.c 50src/cadet/cadet_api_list_tunnels.c
51src/cadet/cadet_test_lib.c 51src/cadet/cadet_test_lib.c
52src/cadet/desirability_table.c 52src/cadet/desirability_table.c
53src/cadet/gnunet-cadet.c
54src/cadet/gnunet-cadet-profiler.c 53src/cadet/gnunet-cadet-profiler.c
54src/cadet/gnunet-cadet.c
55src/cadet/gnunet-service-cadet.c 55src/cadet/gnunet-service-cadet.c
56src/cadet/gnunet-service-cadet_channel.c 56src/cadet/gnunet-service-cadet_channel.c
57src/cadet/gnunet-service-cadet_connection.c 57src/cadet/gnunet-service-cadet_connection.c
@@ -67,15 +67,15 @@ src/consensus/gnunet-service-consensus.c
67src/consensus/plugin_block_consensus.c 67src/consensus/plugin_block_consensus.c
68src/conversation/conversation_api.c 68src/conversation/conversation_api.c
69src/conversation/conversation_api_call.c 69src/conversation/conversation_api_call.c
70src/conversation/gnunet-conversation.c
71src/conversation/gnunet-conversation-test.c 70src/conversation/gnunet-conversation-test.c
72src/conversation/gnunet_gst.c 71src/conversation/gnunet-conversation.c
73src/conversation/gnunet_gst_test.c
74src/conversation/gnunet-helper-audio-playback.c
75src/conversation/gnunet-helper-audio-playback-gst.c 72src/conversation/gnunet-helper-audio-playback-gst.c
76src/conversation/gnunet-helper-audio-record.c 73src/conversation/gnunet-helper-audio-playback.c
77src/conversation/gnunet-helper-audio-record-gst.c 74src/conversation/gnunet-helper-audio-record-gst.c
75src/conversation/gnunet-helper-audio-record.c
78src/conversation/gnunet-service-conversation.c 76src/conversation/gnunet-service-conversation.c
77src/conversation/gnunet_gst.c
78src/conversation/gnunet_gst_test.c
79src/conversation/microphone.c 79src/conversation/microphone.c
80src/conversation/plugin_gnsrecord_conversation.c 80src/conversation/plugin_gnsrecord_conversation.c
81src/conversation/speaker.c 81src/conversation/speaker.c
@@ -112,7 +112,6 @@ src/dht/dht_api.c
112src/dht/dht_test_lib.c 112src/dht/dht_test_lib.c
113src/dht/gnunet-dht-get.c 113src/dht/gnunet-dht-get.c
114src/dht/gnunet-dht-monitor.c 114src/dht/gnunet-dht-monitor.c
115src/dht/gnunet_dht_profiler.c
116src/dht/gnunet-dht-put.c 115src/dht/gnunet-dht-put.c
117src/dht/gnunet-service-dht.c 116src/dht/gnunet-service-dht.c
118src/dht/gnunet-service-dht_clients.c 117src/dht/gnunet-service-dht_clients.c
@@ -121,6 +120,7 @@ src/dht/gnunet-service-dht_hello.c
121src/dht/gnunet-service-dht_neighbours.c 120src/dht/gnunet-service-dht_neighbours.c
122src/dht/gnunet-service-dht_nse.c 121src/dht/gnunet-service-dht_nse.c
123src/dht/gnunet-service-dht_routing.c 122src/dht/gnunet-service-dht_routing.c
123src/dht/gnunet_dht_profiler.c
124src/dht/plugin_block_dht.c 124src/dht/plugin_block_dht.c
125src/dns/dns_api.c 125src/dns/dns_api.c
126src/dns/gnunet-dns-monitor.c 126src/dns/gnunet-dns-monitor.c
@@ -130,8 +130,8 @@ src/dns/gnunet-service-dns.c
130src/dns/gnunet-zonewalk.c 130src/dns/gnunet-zonewalk.c
131src/dns/plugin_block_dns.c 131src/dns/plugin_block_dns.c
132src/exit/gnunet-daemon-exit.c 132src/exit/gnunet-daemon-exit.c
133src/exit/gnunet-helper-exit.c
134src/exit/gnunet-helper-exit-windows.c 133src/exit/gnunet-helper-exit-windows.c
134src/exit/gnunet-helper-exit.c
135src/fragmentation/defragmentation.c 135src/fragmentation/defragmentation.c
136src/fragmentation/fragmentation.c 136src/fragmentation/fragmentation.c
137src/fs/fs_api.c 137src/fs/fs_api.c
@@ -156,8 +156,8 @@ src/fs/gnunet-auto-share.c
156src/fs/gnunet-daemon-fsprofiler.c 156src/fs/gnunet-daemon-fsprofiler.c
157src/fs/gnunet-directory.c 157src/fs/gnunet-directory.c
158src/fs/gnunet-download.c 158src/fs/gnunet-download.c
159src/fs/gnunet-fs.c
160src/fs/gnunet-fs-profiler.c 159src/fs/gnunet-fs-profiler.c
160src/fs/gnunet-fs.c
161src/fs/gnunet-helper-fs-publish.c 161src/fs/gnunet-helper-fs-publish.c
162src/fs/gnunet-publish.c 162src/fs/gnunet-publish.c
163src/fs/gnunet-search.c 163src/fs/gnunet-search.c
@@ -177,10 +177,10 @@ src/gns/gns_tld_api.c
177src/gns/gnunet-bcd.c 177src/gns/gnunet-bcd.c
178src/gns/gnunet-dns2gns.c 178src/gns/gnunet-dns2gns.c
179src/gns/gnunet-gns-benchmark.c 179src/gns/gnunet-gns-benchmark.c
180src/gns/gnunet-gns.c
181src/gns/gnunet-gns-helper-service-w32.c 180src/gns/gnunet-gns-helper-service-w32.c
182src/gns/gnunet-gns-import.c 181src/gns/gnunet-gns-import.c
183src/gns/gnunet-gns-proxy.c 182src/gns/gnunet-gns-proxy.c
183src/gns/gnunet-gns.c
184src/gns/gnunet-service-gns.c 184src/gns/gnunet-service-gns.c
185src/gns/gnunet-service-gns_interceptor.c 185src/gns/gnunet-service-gns_interceptor.c
186src/gns/gnunet-service-gns_resolver.c 186src/gns/gnunet-service-gns_resolver.c
@@ -189,19 +189,19 @@ src/gns/nss/nss_gns_query.c
189src/gns/plugin_block_gns.c 189src/gns/plugin_block_gns.c
190src/gns/plugin_gnsrecord_gns.c 190src/gns/plugin_gnsrecord_gns.c
191src/gns/plugin_rest_gns.c 191src/gns/plugin_rest_gns.c
192src/gns/w32nsp-install.c
193src/gns/w32nsp-resolve.c
194src/gns/w32nsp-uninstall.c
195src/gns/w32nsp.c
192src/gnsrecord/gnsrecord.c 196src/gnsrecord/gnsrecord.c
193src/gnsrecord/gnsrecord_crypto.c 197src/gnsrecord/gnsrecord_crypto.c
194src/gnsrecord/gnsrecord_misc.c 198src/gnsrecord/gnsrecord_misc.c
195src/gnsrecord/gnsrecord_serialization.c 199src/gnsrecord/gnsrecord_serialization.c
196src/gnsrecord/plugin_gnsrecord_dns.c 200src/gnsrecord/plugin_gnsrecord_dns.c
197src/gns/w32nsp.c
198src/gns/w32nsp-install.c
199src/gns/w32nsp-resolve.c
200src/gns/w32nsp-uninstall.c
201src/hello/address.c 201src/hello/address.c
202src/hello/gnunet-hello.c 202src/hello/gnunet-hello.c
203src/hello/hello.c
204src/hello/hello-ng.c 203src/hello/hello-ng.c
204src/hello/hello.c
205src/hostlist/gnunet-daemon-hostlist.c 205src/hostlist/gnunet-daemon-hostlist.c
206src/hostlist/gnunet-daemon-hostlist_client.c 206src/hostlist/gnunet-daemon-hostlist_client.c
207src/hostlist/gnunet-daemon-hostlist_server.c 207src/hostlist/gnunet-daemon-hostlist_server.c
@@ -226,8 +226,8 @@ src/namecache/namecache_api.c
226src/namecache/plugin_namecache_flat.c 226src/namecache/plugin_namecache_flat.c
227src/namecache/plugin_namecache_postgres.c 227src/namecache/plugin_namecache_postgres.c
228src/namecache/plugin_namecache_sqlite.c 228src/namecache/plugin_namecache_sqlite.c
229src/namestore/gnunet-namestore.c
230src/namestore/gnunet-namestore-fcfsd.c 229src/namestore/gnunet-namestore-fcfsd.c
230src/namestore/gnunet-namestore.c
231src/namestore/gnunet-service-namestore.c 231src/namestore/gnunet-service-namestore.c
232src/namestore/gnunet-zoneimport.c 232src/namestore/gnunet-zoneimport.c
233src/namestore/namestore_api.c 233src/namestore/namestore_api.c
@@ -243,10 +243,10 @@ src/nat-auto/gnunet-service-nat-auto.c
243src/nat-auto/gnunet-service-nat-auto_legacy.c 243src/nat-auto/gnunet-service-nat-auto_legacy.c
244src/nat-auto/nat_auto_api.c 244src/nat-auto/nat_auto_api.c
245src/nat-auto/nat_auto_api_test.c 245src/nat-auto/nat_auto_api_test.c
246src/nat/gnunet-helper-nat-client.c
247src/nat/gnunet-helper-nat-client-windows.c 246src/nat/gnunet-helper-nat-client-windows.c
248src/nat/gnunet-helper-nat-server.c 247src/nat/gnunet-helper-nat-client.c
249src/nat/gnunet-helper-nat-server-windows.c 248src/nat/gnunet-helper-nat-server-windows.c
249src/nat/gnunet-helper-nat-server.c
250src/nat/gnunet-nat.c 250src/nat/gnunet-nat.c
251src/nat/gnunet-service-nat.c 251src/nat/gnunet-service-nat.c
252src/nat/gnunet-service-nat_externalip.c 252src/nat/gnunet-service-nat_externalip.c
@@ -255,17 +255,17 @@ src/nat/gnunet-service-nat_mini.c
255src/nat/gnunet-service-nat_stun.c 255src/nat/gnunet-service-nat_stun.c
256src/nat/nat_api.c 256src/nat/nat_api.c
257src/nat/nat_api_stun.c 257src/nat/nat_api_stun.c
258src/nse/gnunet-nse.c
259src/nse/gnunet-nse-profiler.c 258src/nse/gnunet-nse-profiler.c
259src/nse/gnunet-nse.c
260src/nse/gnunet-service-nse.c 260src/nse/gnunet-service-nse.c
261src/nse/nse_api.c 261src/nse/nse_api.c
262src/nt/nt.c 262src/nt/nt.c
263src/peerinfo/gnunet-service-peerinfo.c
264src/peerinfo/peerinfo_api.c
265src/peerinfo/peerinfo_api_notify.c
266src/peerinfo-tool/gnunet-peerinfo.c 263src/peerinfo-tool/gnunet-peerinfo.c
267src/peerinfo-tool/gnunet-peerinfo_plugins.c 264src/peerinfo-tool/gnunet-peerinfo_plugins.c
268src/peerinfo-tool/plugin_rest_peerinfo.c 265src/peerinfo-tool/plugin_rest_peerinfo.c
266src/peerinfo/gnunet-service-peerinfo.c
267src/peerinfo/peerinfo_api.c
268src/peerinfo/peerinfo_api_notify.c
269src/peerstore/gnunet-peerstore.c 269src/peerstore/gnunet-peerstore.c
270src/peerstore/gnunet-service-peerstore.c 270src/peerstore/gnunet-service-peerstore.c
271src/peerstore/peerstore_api.c 271src/peerstore/peerstore_api.c
@@ -313,22 +313,22 @@ src/revocation/gnunet-revocation.c
313src/revocation/gnunet-service-revocation.c 313src/revocation/gnunet-service-revocation.c
314src/revocation/plugin_block_revocation.c 314src/revocation/plugin_block_revocation.c
315src/revocation/revocation_api.c 315src/revocation/revocation_api.c
316src/rps/gnunet-rps.c
317src/rps/gnunet-rps-profiler.c 316src/rps/gnunet-rps-profiler.c
317src/rps/gnunet-rps.c
318src/rps/gnunet-service-rps.c 318src/rps/gnunet-service-rps.c
319src/rps/gnunet-service-rps_custommap.c 319src/rps/gnunet-service-rps_custommap.c
320src/rps/gnunet-service-rps_sampler.c 320src/rps/gnunet-service-rps_sampler.c
321src/rps/gnunet-service-rps_sampler_elem.c 321src/rps/gnunet-service-rps_sampler_elem.c
322src/rps/gnunet-service-rps_view.c 322src/rps/gnunet-service-rps_view.c
323src/rps/rps_api.c
324src/rps/rps-sampler_client.c 323src/rps/rps-sampler_client.c
325src/rps/rps-sampler_common.c 324src/rps/rps-sampler_common.c
326src/rps/rps-test_util.c 325src/rps/rps-test_util.c
326src/rps/rps_api.c
327src/scalarproduct/gnunet-scalarproduct.c 327src/scalarproduct/gnunet-scalarproduct.c
328src/scalarproduct/gnunet-service-scalarproduct_alice.c
329src/scalarproduct/gnunet-service-scalarproduct_bob.c
330src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c 328src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c
331src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c 329src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c
330src/scalarproduct/gnunet-service-scalarproduct_alice.c
331src/scalarproduct/gnunet-service-scalarproduct_bob.c
332src/scalarproduct/scalarproduct_api.c 332src/scalarproduct/scalarproduct_api.c
333src/secretsharing/gnunet-secretsharing-profiler.c 333src/secretsharing/gnunet-secretsharing-profiler.c
334src/secretsharing/gnunet-service-secretsharing.c 334src/secretsharing/gnunet-service-secretsharing.c
@@ -354,15 +354,16 @@ src/statistics/gnunet-statistics.c
354src/statistics/statistics_api.c 354src/statistics/statistics_api.c
355src/template/gnunet-service-template.c 355src/template/gnunet-service-template.c
356src/template/gnunet-template.c 356src/template/gnunet-template.c
357src/testbed-logger/gnunet-service-testbed-logger.c
358src/testbed-logger/testbed_logger_api.c
357src/testbed/generate-underlay-topology.c 359src/testbed/generate-underlay-topology.c
358src/testbed/gnunet-daemon-latency-logger.c 360src/testbed/gnunet-daemon-latency-logger.c
359src/testbed/gnunet-daemon-testbed-blacklist.c 361src/testbed/gnunet-daemon-testbed-blacklist.c
360src/testbed/gnunet-daemon-testbed-underlay.c 362src/testbed/gnunet-daemon-testbed-underlay.c
361src/testbed/gnunet-helper-testbed.c 363src/testbed/gnunet-helper-testbed.c
362src/testbed/gnunet_mpi_test.c
363src/testbed/gnunet-service-test-barriers.c 364src/testbed/gnunet-service-test-barriers.c
364src/testbed/gnunet-service-testbed_barriers.c
365src/testbed/gnunet-service-testbed.c 365src/testbed/gnunet-service-testbed.c
366src/testbed/gnunet-service-testbed_barriers.c
366src/testbed/gnunet-service-testbed_cache.c 367src/testbed/gnunet-service-testbed_cache.c
367src/testbed/gnunet-service-testbed_connectionpool.c 368src/testbed/gnunet-service-testbed_connectionpool.c
368src/testbed/gnunet-service-testbed_cpustatus.c 369src/testbed/gnunet-service-testbed_cpustatus.c
@@ -370,20 +371,19 @@ src/testbed/gnunet-service-testbed_links.c
370src/testbed/gnunet-service-testbed_meminfo.c 371src/testbed/gnunet-service-testbed_meminfo.c
371src/testbed/gnunet-service-testbed_oc.c 372src/testbed/gnunet-service-testbed_oc.c
372src/testbed/gnunet-service-testbed_peers.c 373src/testbed/gnunet-service-testbed_peers.c
373src/testbed/gnunet_testbed_mpi_spawn.c
374src/testbed/gnunet-testbed-profiler.c 374src/testbed/gnunet-testbed-profiler.c
375src/testbed-logger/gnunet-service-testbed-logger.c 375src/testbed/gnunet_mpi_test.c
376src/testbed-logger/testbed_logger_api.c 376src/testbed/gnunet_testbed_mpi_spawn.c
377src/testbed/testbed_api_barriers.c
378src/testbed/testbed_api.c 377src/testbed/testbed_api.c
378src/testbed/testbed_api_barriers.c
379src/testbed/testbed_api_hosts.c 379src/testbed/testbed_api_hosts.c
380src/testbed/testbed_api_operations.c 380src/testbed/testbed_api_operations.c
381src/testbed/testbed_api_peers.c 381src/testbed/testbed_api_peers.c
382src/testbed/testbed_api_sd.c 382src/testbed/testbed_api_sd.c
383src/testbed/testbed_api_services.c 383src/testbed/testbed_api_services.c
384src/testbed/testbed_api_statistics.c 384src/testbed/testbed_api_statistics.c
385src/testbed/testbed_api_testbed.c
386src/testbed/testbed_api_test.c 385src/testbed/testbed_api_test.c
386src/testbed/testbed_api_testbed.c
387src/testbed/testbed_api_topology.c 387src/testbed/testbed_api_topology.c
388src/testbed/testbed_api_underlay.c 388src/testbed/testbed_api_underlay.c
389src/testing/gnunet-testing.c 389src/testing/gnunet-testing.c
@@ -395,34 +395,40 @@ src/transport/gnunet-communicator-tcp.c
395src/transport/gnunet-communicator-udp.c 395src/transport/gnunet-communicator-udp.c
396src/transport/gnunet-communicator-unix.c 396src/transport/gnunet-communicator-unix.c
397src/transport/gnunet-helper-transport-bluetooth.c 397src/transport/gnunet-helper-transport-bluetooth.c
398src/transport/gnunet-helper-transport-wlan.c
399src/transport/gnunet-helper-transport-wlan-dummy.c 398src/transport/gnunet-helper-transport-wlan-dummy.c
399src/transport/gnunet-helper-transport-wlan.c
400src/transport/gnunet-service-tng.c 400src/transport/gnunet-service-tng.c
401src/transport/gnunet-service-transport_ats.c
402src/transport/gnunet-service-transport.c 401src/transport/gnunet-service-transport.c
402src/transport/gnunet-service-transport_ats.c
403src/transport/gnunet-service-transport_hello.c 403src/transport/gnunet-service-transport_hello.c
404src/transport/gnunet-service-transport_manipulation.c 404src/transport/gnunet-service-transport_manipulation.c
405src/transport/gnunet-service-transport_neighbours.c 405src/transport/gnunet-service-transport_neighbours.c
406src/transport/gnunet-service-transport_plugins.c 406src/transport/gnunet-service-transport_plugins.c
407src/transport/gnunet-service-transport_validation.c 407src/transport/gnunet-service-transport_validation.c
408src/transport/gnunet-transport.c
409src/transport/gnunet-transport-profiler.c 408src/transport/gnunet-transport-profiler.c
410src/transport/gnunet-transport-wlan-receiver.c 409src/transport/gnunet-transport-wlan-receiver.c
411src/transport/gnunet-transport-wlan-sender.c 410src/transport/gnunet-transport-wlan-sender.c
411src/transport/gnunet-transport.c
412src/transport/plugin_transport_http_client.c 412src/transport/plugin_transport_http_client.c
413src/transport/plugin_transport_http_common.c 413src/transport/plugin_transport_http_common.c
414src/transport/plugin_transport_http_server.c 414src/transport/plugin_transport_http_server.c
415src/transport/plugin_transport_smtp.c 415src/transport/plugin_transport_smtp.c
416src/transport/plugin_transport_tcp.c 416src/transport/plugin_transport_tcp.c
417src/transport/plugin_transport_template.c 417src/transport/plugin_transport_template.c
418src/transport/plugin_transport_udp_broadcasting.c
419src/transport/plugin_transport_udp.c 418src/transport/plugin_transport_udp.c
419src/transport/plugin_transport_udp_broadcasting.c
420src/transport/plugin_transport_unix.c 420src/transport/plugin_transport_unix.c
421src/transport/plugin_transport_wlan.c 421src/transport/plugin_transport_wlan.c
422src/transport/tcp_connection_legacy.c 422src/transport/tcp_connection_legacy.c
423src/transport/tcp_server_legacy.c 423src/transport/tcp_server_legacy.c
424src/transport/tcp_server_mst_legacy.c 424src/transport/tcp_server_mst_legacy.c
425src/transport/tcp_service_legacy.c 425src/transport/tcp_service_legacy.c
426src/transport/transport-testing-filenames.c
427src/transport/transport-testing-loggers.c
428src/transport/transport-testing-main.c
429src/transport/transport-testing-send.c
430src/transport/transport-testing.c
431src/transport/transport-testing2.c
426src/transport/transport_api2_application.c 432src/transport/transport_api2_application.c
427src/transport/transport_api2_communication.c 433src/transport/transport_api2_communication.c
428src/transport/transport_api2_core.c 434src/transport/transport_api2_core.c
@@ -435,12 +441,6 @@ src/transport/transport_api_manipulation.c
435src/transport/transport_api_monitor_peers.c 441src/transport/transport_api_monitor_peers.c
436src/transport/transport_api_monitor_plugins.c 442src/transport/transport_api_monitor_plugins.c
437src/transport/transport_api_offer_hello.c 443src/transport/transport_api_offer_hello.c
438src/transport/transport-testing2.c
439src/transport/transport-testing.c
440src/transport/transport-testing-filenames.c
441src/transport/transport-testing-loggers.c
442src/transport/transport-testing-main.c
443src/transport/transport-testing-send.c
444src/util/bandwidth.c 444src/util/bandwidth.c
445src/util/benchmark.c 445src/util/benchmark.c
446src/util/bio.c 446src/util/bio.c
@@ -453,8 +453,8 @@ src/util/configuration_loader.c
453src/util/container_bloomfilter.c 453src/util/container_bloomfilter.c
454src/util/container_heap.c 454src/util/container_heap.c
455src/util/container_meta_data.c 455src/util/container_meta_data.c
456src/util/container_multihashmap32.c
457src/util/container_multihashmap.c 456src/util/container_multihashmap.c
457src/util/container_multihashmap32.c
458src/util/container_multipeermap.c 458src/util/container_multipeermap.c
459src/util/container_multishortmap.c 459src/util/container_multishortmap.c
460src/util/container_multiuuidmap.c 460src/util/container_multiuuidmap.c
@@ -477,16 +477,16 @@ src/util/dnsparser.c
477src/util/dnsstub.c 477src/util/dnsstub.c
478src/util/getopt.c 478src/util/getopt.c
479src/util/getopt_helpers.c 479src/util/getopt_helpers.c
480src/util/gnunet-config.c
481src/util/gnunet-config-diff.c 480src/util/gnunet-config-diff.c
481src/util/gnunet-config.c
482src/util/gnunet-ecc.c 482src/util/gnunet-ecc.c
483src/util/gnunet-helper-w32-console.c 483src/util/gnunet-helper-w32-console.c
484src/util/gnunet-qr.c 484src/util/gnunet-qr.c
485src/util/gnunet-resolver.c 485src/util/gnunet-resolver.c
486src/util/gnunet-scrypt.c 486src/util/gnunet-scrypt.c
487src/util/gnunet-service-resolver.c 487src/util/gnunet-service-resolver.c
488src/util/gnunet-timeout.c
489src/util/gnunet-timeout-w32.c 488src/util/gnunet-timeout-w32.c
489src/util/gnunet-timeout.c
490src/util/gnunet-uri.c 490src/util/gnunet-uri.c
491src/util/helper.c 491src/util/helper.c
492src/util/load.c 492src/util/load.c
@@ -515,13 +515,13 @@ src/util/tun.c
515src/util/w32cat.c 515src/util/w32cat.c
516src/util/win.c 516src/util/win.c
517src/util/winproc.c 517src/util/winproc.c
518src/vpn/gnunet-helper-vpn.c
519src/vpn/gnunet-helper-vpn-windows.c 518src/vpn/gnunet-helper-vpn-windows.c
519src/vpn/gnunet-helper-vpn.c
520src/vpn/gnunet-service-vpn.c 520src/vpn/gnunet-service-vpn.c
521src/vpn/gnunet-vpn.c 521src/vpn/gnunet-vpn.c
522src/vpn/vpn_api.c 522src/vpn/vpn_api.c
523src/zonemaster/gnunet-service-zonemaster.c
524src/zonemaster/gnunet-service-zonemaster-monitor.c 523src/zonemaster/gnunet-service-zonemaster-monitor.c
524src/zonemaster/gnunet-service-zonemaster.c
525src/fs/fs_api.h 525src/fs/fs_api.h
526src/include/compat.h 526src/include/compat.h
527src/include/gnunet_common.h 527src/include/gnunet_common.h
diff --git a/src/arm/Kyuafile b/src/arm/Kyuafile
new file mode 100644
index 000000000..f97f05e18
--- /dev/null
+++ b/src/arm/Kyuafile
@@ -0,0 +1,9 @@
1-- Tests for gnunet-arm
2
3syntax(2)
4
5-- name of the test suite
6test_suite('arm')
7
8-- test programs
9atf_test_program{name='atf_tests.sh'}
diff --git a/src/arm/gnunet-arm.c b/src/arm/gnunet-arm.c
index 7d705733a..f96076231 100644
--- a/src/arm/gnunet-arm.c
+++ b/src/arm/gnunet-arm.c
@@ -151,7 +151,7 @@ delete_files ()
151 "Will attempt to remove configuration file %s and service directory %s\n", 151 "Will attempt to remove configuration file %s and service directory %s\n",
152 config_file, 152 config_file,
153 dir); 153 dir);
154 if (0 != UNLINK (config_file)) 154 if (0 != unlink (config_file))
155 { 155 {
156 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 156 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
157 _ ("Failed to remove configuration file %s\n"), 157 _ ("Failed to remove configuration file %s\n"),
@@ -319,7 +319,7 @@ start_callback (void *cls,
319 op = NULL; 319 op = NULL;
320 if (GNUNET_ARM_REQUEST_SENT_OK != rs) 320 if (GNUNET_ARM_REQUEST_SENT_OK != rs)
321 { 321 {
322 FPRINTF (stdout, 322 fprintf (stdout,
323 _ ("Failed to start the ARM service: %s\n"), 323 _ ("Failed to start the ARM service: %s\n"),
324 req_string (rs)); 324 req_string (rs));
325 GNUNET_SCHEDULER_shutdown (); 325 GNUNET_SCHEDULER_shutdown ();
@@ -328,7 +328,7 @@ start_callback (void *cls,
328 if ((GNUNET_ARM_RESULT_STARTING != result) && 328 if ((GNUNET_ARM_RESULT_STARTING != result) &&
329 (GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result)) 329 (GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result))
330 { 330 {
331 FPRINTF (stdout, 331 fprintf (stdout,
332 _ ("Failed to start the ARM service: %s\n"), 332 _ ("Failed to start the ARM service: %s\n"),
333 ret_string (result)); 333 ret_string (result));
334 GNUNET_SCHEDULER_shutdown (); 334 GNUNET_SCHEDULER_shutdown ();
@@ -366,7 +366,7 @@ stop_callback (void *cls,
366 "%s", 366 "%s",
367 _ ( 367 _ (
368 "Failed to send a stop request to the ARM service: %s\n")); 368 "Failed to send a stop request to the ARM service: %s\n"));
369 FPRINTF (stdout, msg, req_string (rs)); 369 fprintf (stdout, msg, req_string (rs));
370 GNUNET_free (msg); 370 GNUNET_free (msg);
371 GNUNET_SCHEDULER_shutdown (); 371 GNUNET_SCHEDULER_shutdown ();
372 return; 372 return;
@@ -375,7 +375,7 @@ stop_callback (void *cls,
375 (GNUNET_ARM_RESULT_STOPPED != result) && 375 (GNUNET_ARM_RESULT_STOPPED != result) &&
376 (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result)) 376 (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result))
377 { 377 {
378 FPRINTF (stdout, 378 fprintf (stdout,
379 _ ("Failed to stop the ARM service: %s\n"), 379 _ ("Failed to stop the ARM service: %s\n"),
380 ret_string (result)); 380 ret_string (result));
381 GNUNET_SCHEDULER_shutdown (); 381 GNUNET_SCHEDULER_shutdown ();
@@ -413,7 +413,7 @@ init_callback (void *cls,
413 op = NULL; 413 op = NULL;
414 if (GNUNET_ARM_REQUEST_SENT_OK != rs) 414 if (GNUNET_ARM_REQUEST_SENT_OK != rs)
415 { 415 {
416 FPRINTF (stdout, 416 fprintf (stdout,
417 _ ("Failed to send a request to start the `%s' service: %s\n"), 417 _ ("Failed to send a request to start the `%s' service: %s\n"),
418 init, 418 init,
419 req_string (rs)); 419 req_string (rs));
@@ -423,7 +423,7 @@ init_callback (void *cls,
423 if ((GNUNET_ARM_RESULT_STARTING != result) && 423 if ((GNUNET_ARM_RESULT_STARTING != result) &&
424 (GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result)) 424 (GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result))
425 { 425 {
426 FPRINTF (stdout, 426 fprintf (stdout,
427 _ ("Failed to start the `%s' service: %s\n"), 427 _ ("Failed to start the `%s' service: %s\n"),
428 init, 428 init,
429 ret_string (result)); 429 ret_string (result));
@@ -465,7 +465,7 @@ term_callback (void *cls,
465 _ ( 465 _ (
466 "Failed to send a request to kill the `%s' service: %%s\n"), 466 "Failed to send a request to kill the `%s' service: %%s\n"),
467 term); 467 term);
468 FPRINTF (stdout, msg, req_string (rs)); 468 fprintf (stdout, msg, req_string (rs));
469 GNUNET_free (msg); 469 GNUNET_free (msg);
470 GNUNET_SCHEDULER_shutdown (); 470 GNUNET_SCHEDULER_shutdown ();
471 return; 471 return;
@@ -473,7 +473,7 @@ term_callback (void *cls,
473 if ((GNUNET_ARM_RESULT_STOPPED != result) && 473 if ((GNUNET_ARM_RESULT_STOPPED != result) &&
474 (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result)) 474 (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result))
475 { 475 {
476 FPRINTF (stdout, 476 fprintf (stdout,
477 _ ("Failed to kill the `%s' service: %s\n"), 477 _ ("Failed to kill the `%s' service: %s\n"),
478 term, 478 term,
479 ret_string (result)); 479 ret_string (result));
@@ -515,14 +515,14 @@ list_callback (void *cls,
515 GNUNET_asprintf (&msg, 515 GNUNET_asprintf (&msg,
516 "%s", 516 "%s",
517 _ ("Failed to request a list of services: %s\n")); 517 _ ("Failed to request a list of services: %s\n"));
518 FPRINTF (stdout, msg, req_string (rs)); 518 fprintf (stdout, msg, req_string (rs));
519 GNUNET_free (msg); 519 GNUNET_free (msg);
520 ret = 3; 520 ret = 3;
521 GNUNET_SCHEDULER_shutdown (); 521 GNUNET_SCHEDULER_shutdown ();
522 } 522 }
523 if (NULL == list) 523 if (NULL == list)
524 { 524 {
525 FPRINTF (stderr, 525 fprintf (stderr,
526 "%s", 526 "%s",
527 _ ("Error communicating with ARM. ARM not running?\n")); 527 _ ("Error communicating with ARM. ARM not running?\n"));
528 GNUNET_SCHEDULER_shutdown (); 528 GNUNET_SCHEDULER_shutdown ();
@@ -530,9 +530,9 @@ list_callback (void *cls,
530 return; 530 return;
531 } 531 }
532 if (! quiet) 532 if (! quiet)
533 FPRINTF (stdout, "%s", _ ("Running services:\n")); 533 fprintf (stdout, "%s", _ ("Running services:\n"));
534 for (unsigned int i = 0; i < count; i++) 534 for (unsigned int i = 0; i < count; i++)
535 FPRINTF (stdout, "%s\n", list[i]); 535 fprintf (stdout, "%s\n", list[i]);
536 al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL); 536 al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
537} 537}
538 538
@@ -661,9 +661,9 @@ srv_status (void *cls,
661 if (! quiet) 661 if (! quiet)
662 { 662 {
663 if (NULL != msg) 663 if (NULL != msg)
664 FPRINTF (stderr, msg, service); 664 fprintf (stderr, msg, service);
665 else 665 else
666 FPRINTF (stderr, 666 fprintf (stderr,
667 _ ("Unknown status %u for service %s.\n"), 667 _ ("Unknown status %u for service %s.\n"),
668 status, 668 status,
669 service); 669 service);
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c
index 4b7cbec20..a05257563 100644
--- a/src/arm/gnunet-service-arm.c
+++ b/src/arm/gnunet-service-arm.c
@@ -29,9 +29,10 @@
29#include "gnunet_protocols.h" 29#include "gnunet_protocols.h"
30#include "arm.h" 30#include "arm.h"
31 31
32#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__) 32#define LOG(kind, ...) GNUNET_log_from (kind, "util", __VA_ARGS__)
33 33
34#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util", syscall) 34#define LOG_strerror(kind, syscall) \
35 GNUNET_log_from_strerror (kind, "util", syscall)
35 36
36 37
37#if HAVE_WAIT4 38#if HAVE_WAIT4
@@ -100,7 +101,6 @@ struct ServiceListeningInfo
100 * Task doing the accepting. 101 * Task doing the accepting.
101 */ 102 */
102 struct GNUNET_SCHEDULER_Task *accept_task; 103 struct GNUNET_SCHEDULER_Task *accept_task;
103
104}; 104};
105 105
106 106
@@ -330,9 +330,9 @@ add_unixpath (struct sockaddr **saddrs,
330 */ 330 */
331static int 331static int
332get_server_addresses (const char *service_name, 332get_server_addresses (const char *service_name,
333 const struct GNUNET_CONFIGURATION_Handle *cfg, 333 const struct GNUNET_CONFIGURATION_Handle *cfg,
334 struct sockaddr ***addrs, 334 struct sockaddr ***addrs,
335 socklen_t ** addr_lens) 335 socklen_t **addr_lens)
336{ 336{
337 int disablev6; 337 int disablev6;
338 struct GNUNET_NETWORK_Handle *desc; 338 struct GNUNET_NETWORK_Handle *desc;
@@ -353,15 +353,12 @@ get_server_addresses (const char *service_name,
353 *addrs = NULL; 353 *addrs = NULL;
354 *addr_lens = NULL; 354 *addr_lens = NULL;
355 desc = NULL; 355 desc = NULL;
356 if (GNUNET_CONFIGURATION_have_value (cfg, 356 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "DISABLEV6"))
357 service_name,
358 "DISABLEV6"))
359 { 357 {
360 if (GNUNET_SYSERR == 358 if (GNUNET_SYSERR ==
361 (disablev6 = 359 (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (cfg,
362 GNUNET_CONFIGURATION_get_value_yesno (cfg, 360 service_name,
363 service_name, 361 "DISABLEV6")))
364 "DISABLEV6")))
365 return GNUNET_SYSERR; 362 return GNUNET_SYSERR;
366 } 363 }
367 else 364 else
@@ -370,24 +367,20 @@ get_server_addresses (const char *service_name,
370 if (! disablev6) 367 if (! disablev6)
371 { 368 {
372 /* probe IPv6 support */ 369 /* probe IPv6 support */
373 desc = GNUNET_NETWORK_socket_create (PF_INET6, 370 desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
374 SOCK_STREAM,
375 0);
376 if (NULL == desc) 371 if (NULL == desc)
377 { 372 {
378 if ( (ENOBUFS == errno) || 373 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
379 (ENOMEM == errno) || 374 (EACCES == errno))
380 (ENFILE == errno) ||
381 (EACCES == errno) )
382 { 375 {
383 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, 376 LOG_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
384 "socket");
385 return GNUNET_SYSERR; 377 return GNUNET_SYSERR;
386 } 378 }
387 LOG (GNUNET_ERROR_TYPE_INFO, 379 LOG (GNUNET_ERROR_TYPE_INFO,
388 _("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), 380 _ (
381 "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
389 service_name, 382 service_name,
390 STRERROR (errno)); 383 strerror (errno));
391 disablev6 = GNUNET_YES; 384 disablev6 = GNUNET_YES;
392 } 385 }
393 else 386 else
@@ -398,38 +391,33 @@ get_server_addresses (const char *service_name,
398 } 391 }
399 392
400 port = 0; 393 port = 0;
401 if (GNUNET_CONFIGURATION_have_value (cfg, 394 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT"))
402 service_name,
403 "PORT"))
404 { 395 {
405 if (GNUNET_OK != 396 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
406 GNUNET_CONFIGURATION_get_value_number (cfg, 397 service_name,
407 service_name, 398 "PORT",
408 "PORT", 399 &port))
409 &port))
410 { 400 {
411 LOG (GNUNET_ERROR_TYPE_ERROR, 401 LOG (GNUNET_ERROR_TYPE_ERROR,
412 _("Require valid port number for service `%s' in configuration!\n"), 402 _ ("Require valid port number for service `%s' in configuration!\n"),
413 service_name); 403 service_name);
414 } 404 }
415 if (port > 65535) 405 if (port > 65535)
416 { 406 {
417 LOG (GNUNET_ERROR_TYPE_ERROR, 407 LOG (GNUNET_ERROR_TYPE_ERROR,
418 _("Require valid port number for service `%s' in configuration!\n"), 408 _ ("Require valid port number for service `%s' in configuration!\n"),
419 service_name); 409 service_name);
420 return GNUNET_SYSERR; 410 return GNUNET_SYSERR;
421 } 411 }
422 } 412 }
423 413
424 if (GNUNET_CONFIGURATION_have_value (cfg, 414 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO"))
425 service_name,
426 "BINDTO"))
427 { 415 {
428 GNUNET_break (GNUNET_OK == 416 GNUNET_break (GNUNET_OK ==
429 GNUNET_CONFIGURATION_get_value_string (cfg, 417 GNUNET_CONFIGURATION_get_value_string (cfg,
430 service_name, 418 service_name,
431 "BINDTO", 419 "BINDTO",
432 &hostname)); 420 &hostname));
433 } 421 }
434 else 422 else
435 hostname = NULL; 423 hostname = NULL;
@@ -438,14 +426,11 @@ get_server_addresses (const char *service_name,
438 abstract = GNUNET_NO; 426 abstract = GNUNET_NO;
439#ifdef AF_UNIX 427#ifdef AF_UNIX
440 if ((GNUNET_YES == 428 if ((GNUNET_YES ==
441 GNUNET_CONFIGURATION_have_value (cfg, 429 GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) &&
442 service_name, 430 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg,
443 "UNIXPATH")) && 431 service_name,
444 (GNUNET_OK == 432 "UNIXPATH",
445 GNUNET_CONFIGURATION_get_value_filename (cfg, 433 &unixpath)) &&
446 service_name,
447 "UNIXPATH",
448 &unixpath)) &&
449 (0 < strlen (unixpath))) 434 (0 < strlen (unixpath)))
450 { 435 {
451 /* probe UNIX support */ 436 /* probe UNIX support */
@@ -454,13 +439,11 @@ get_server_addresses (const char *service_name,
454 if (strlen (unixpath) >= sizeof (s_un.sun_path)) 439 if (strlen (unixpath) >= sizeof (s_un.sun_path))
455 { 440 {
456 LOG (GNUNET_ERROR_TYPE_WARNING, 441 LOG (GNUNET_ERROR_TYPE_WARNING,
457 _("UNIXPATH `%s' too long, maximum length is %llu\n"), 442 _ ("UNIXPATH `%s' too long, maximum length is %llu\n"),
458 unixpath, 443 unixpath,
459 (unsigned long long) sizeof (s_un.sun_path)); 444 (unsigned long long) sizeof (s_un.sun_path));
460 unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath); 445 unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath);
461 LOG (GNUNET_ERROR_TYPE_INFO, 446 LOG (GNUNET_ERROR_TYPE_INFO, _ ("Using `%s' instead\n"), unixpath);
462 _("Using `%s' instead\n"),
463 unixpath);
464 } 447 }
465#ifdef LINUX 448#ifdef LINUX
466 abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, 449 abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
@@ -469,32 +452,28 @@ get_server_addresses (const char *service_name,
469 if (GNUNET_SYSERR == abstract) 452 if (GNUNET_SYSERR == abstract)
470 abstract = GNUNET_NO; 453 abstract = GNUNET_NO;
471#endif 454#endif
472 if ( (GNUNET_YES != abstract) && 455 if ((GNUNET_YES != abstract) &&
473 (GNUNET_OK != 456 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (unixpath)))
474 GNUNET_DISK_directory_create_for_file (unixpath)) ) 457 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath);
475 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
476 "mkdir",
477 unixpath);
478 } 458 }
479 if (NULL != unixpath) 459 if (NULL != unixpath)
480 { 460 {
481 desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); 461 desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
482 if (NULL == desc) 462 if (NULL == desc)
483 { 463 {
484 if ( (ENOBUFS == errno) || 464 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
485 (ENOMEM == errno) || 465 (EACCES == errno))
486 (ENFILE == errno) ||
487 (EACCES == errno) )
488 { 466 {
489 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket"); 467 LOG_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
490 GNUNET_free_non_null (hostname); 468 GNUNET_free_non_null (hostname);
491 GNUNET_free (unixpath); 469 GNUNET_free (unixpath);
492 return GNUNET_SYSERR; 470 return GNUNET_SYSERR;
493 } 471 }
494 LOG (GNUNET_ERROR_TYPE_INFO, 472 LOG (GNUNET_ERROR_TYPE_INFO,
495 _("Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), 473 _ (
474 "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
496 service_name, 475 service_name,
497 STRERROR (errno)); 476 strerror (errno));
498 GNUNET_free (unixpath); 477 GNUNET_free (unixpath);
499 unixpath = NULL; 478 unixpath = NULL;
500 } 479 }
@@ -506,29 +485,23 @@ get_server_addresses (const char *service_name,
506 } 485 }
507#endif 486#endif
508 487
509 if ( (0 == port) && 488 if ((0 == port) && (NULL == unixpath))
510 (NULL == unixpath) )
511 { 489 {
512 if (GNUNET_YES == 490 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg,
513 GNUNET_CONFIGURATION_get_value_yesno (cfg, 491 service_name,
514 service_name, 492 "START_ON_DEMAND"))
515 "START_ON_DEMAND"))
516 LOG (GNUNET_ERROR_TYPE_ERROR, 493 LOG (GNUNET_ERROR_TYPE_ERROR,
517 _("Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), 494 _ (
518 service_name); 495 "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
496 service_name);
519 GNUNET_free_non_null (hostname); 497 GNUNET_free_non_null (hostname);
520 return GNUNET_SYSERR; 498 return GNUNET_SYSERR;
521 } 499 }
522 if (0 == port) 500 if (0 == port)
523 { 501 {
524 saddrs = GNUNET_new_array (2, 502 saddrs = GNUNET_new_array (2, struct sockaddr *);
525 struct sockaddr *); 503 saddrlens = GNUNET_new_array (2, socklen_t);
526 saddrlens = GNUNET_new_array (2, 504 add_unixpath (saddrs, saddrlens, unixpath, abstract);
527 socklen_t);
528 add_unixpath (saddrs,
529 saddrlens,
530 unixpath,
531 abstract);
532 GNUNET_free_non_null (unixpath); 505 GNUNET_free_non_null (unixpath);
533 GNUNET_free_non_null (hostname); 506 GNUNET_free_non_null (hostname);
534 *addrs = saddrs; 507 *addrs = saddrs;
@@ -546,14 +519,11 @@ get_server_addresses (const char *service_name,
546 if (disablev6) 519 if (disablev6)
547 hints.ai_family = AF_INET; 520 hints.ai_family = AF_INET;
548 hints.ai_protocol = IPPROTO_TCP; 521 hints.ai_protocol = IPPROTO_TCP;
549 if ((0 != (ret = getaddrinfo (hostname, 522 if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) ||
550 NULL,
551 &hints,
552 &res))) ||
553 (NULL == res)) 523 (NULL == res))
554 { 524 {
555 LOG (GNUNET_ERROR_TYPE_ERROR, 525 LOG (GNUNET_ERROR_TYPE_ERROR,
556 _("Failed to resolve `%s': %s\n"), 526 _ ("Failed to resolve `%s': %s\n"),
557 hostname, 527 hostname,
558 gai_strerror (ret)); 528 gai_strerror (ret));
559 GNUNET_free (hostname); 529 GNUNET_free (hostname);
@@ -572,7 +542,7 @@ get_server_addresses (const char *service_name,
572 if (0 == i) 542 if (0 == i)
573 { 543 {
574 LOG (GNUNET_ERROR_TYPE_ERROR, 544 LOG (GNUNET_ERROR_TYPE_ERROR,
575 _("Failed to find %saddress for `%s'.\n"), 545 _ ("Failed to find %saddress for `%s'.\n"),
576 disablev6 ? "IPv4 " : "", 546 disablev6 ? "IPv4 " : "",
577 hostname); 547 hostname);
578 freeaddrinfo (res); 548 freeaddrinfo (res);
@@ -583,10 +553,8 @@ get_server_addresses (const char *service_name,
583 resi = i; 553 resi = i;
584 if (NULL != unixpath) 554 if (NULL != unixpath)
585 resi++; 555 resi++;
586 saddrs = GNUNET_new_array (resi + 1, 556 saddrs = GNUNET_new_array (resi + 1, struct sockaddr *);
587 struct sockaddr *); 557 saddrlens = GNUNET_new_array (resi + 1, socklen_t);
588 saddrlens = GNUNET_new_array (resi + 1,
589 socklen_t);
590 i = 0; 558 i = 0;
591 if (NULL != unixpath) 559 if (NULL != unixpath)
592 { 560 {
@@ -600,11 +568,13 @@ get_server_addresses (const char *service_name,
600 if ((disablev6) && (AF_INET6 == pos->ai_family)) 568 if ((disablev6) && (AF_INET6 == pos->ai_family))
601 continue; 569 continue;
602 if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol)) 570 if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol))
603 continue; /* not TCP */ 571 continue; /* not TCP */
604 if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype)) 572 if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype))
605 continue; /* huh? */ 573 continue; /* huh? */
606 LOG (GNUNET_ERROR_TYPE_DEBUG, "Service `%s' will bind to `%s'\n", 574 LOG (GNUNET_ERROR_TYPE_DEBUG,
607 service_name, GNUNET_a2s (pos->ai_addr, pos->ai_addrlen)); 575 "Service `%s' will bind to `%s'\n",
576 service_name,
577 GNUNET_a2s (pos->ai_addr, pos->ai_addrlen));
608 if (AF_INET == pos->ai_family) 578 if (AF_INET == pos->ai_family)
609 { 579 {
610 GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen); 580 GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen);
@@ -638,10 +608,8 @@ get_server_addresses (const char *service_name,
638 if (NULL != unixpath) 608 if (NULL != unixpath)
639 resi++; 609 resi++;
640 i = 0; 610 i = 0;
641 saddrs = GNUNET_new_array (resi + 1, 611 saddrs = GNUNET_new_array (resi + 1, struct sockaddr *);
642 struct sockaddr *); 612 saddrlens = GNUNET_new_array (resi + 1, socklen_t);
643 saddrlens = GNUNET_new_array (resi + 1,
644 socklen_t);
645 if (NULL != unixpath) 613 if (NULL != unixpath)
646 { 614 {
647 add_unixpath (saddrs, saddrlens, unixpath, abstract); 615 add_unixpath (saddrs, saddrlens, unixpath, abstract);
@@ -661,17 +629,12 @@ get_server_addresses (const char *service_name,
661 resi = 2; 629 resi = 2;
662 if (NULL != unixpath) 630 if (NULL != unixpath)
663 resi++; 631 resi++;
664 saddrs = GNUNET_new_array (resi + 1, 632 saddrs = GNUNET_new_array (resi + 1, struct sockaddr *);
665 struct sockaddr *); 633 saddrlens = GNUNET_new_array (resi + 1, socklen_t);
666 saddrlens = GNUNET_new_array (resi + 1,
667 socklen_t);
668 i = 0; 634 i = 0;
669 if (NULL != unixpath) 635 if (NULL != unixpath)
670 { 636 {
671 add_unixpath (saddrs, 637 add_unixpath (saddrs, saddrlens, unixpath, abstract);
672 saddrlens,
673 unixpath,
674 abstract);
675 i++; 638 i++;
676 } 639 }
677 saddrlens[i] = sizeof (struct sockaddr_in6); 640 saddrlens[i] = sizeof (struct sockaddr_in6);
@@ -710,20 +673,18 @@ get_server_addresses (const char *service_name,
710 */ 673 */
711static void 674static void
712signal_result (struct GNUNET_SERVICE_Client *client, 675signal_result (struct GNUNET_SERVICE_Client *client,
713 const char *name, 676 const char *name,
714 uint64_t request_id, 677 uint64_t request_id,
715 enum GNUNET_ARM_Result result) 678 enum GNUNET_ARM_Result result)
716{ 679{
717 struct GNUNET_MQ_Envelope *env; 680 struct GNUNET_MQ_Envelope *env;
718 struct GNUNET_ARM_ResultMessage *msg; 681 struct GNUNET_ARM_ResultMessage *msg;
719 682
720 (void) name; 683 (void) name;
721 env = GNUNET_MQ_msg (msg, 684 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_ARM_RESULT);
722 GNUNET_MESSAGE_TYPE_ARM_RESULT);
723 msg->result = htonl (result); 685 msg->result = htonl (result);
724 msg->arm_msg.request_id = GNUNET_htonll (request_id); 686 msg->arm_msg.request_id = GNUNET_htonll (request_id);
725 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), 687 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
726 env);
727} 688}
728 689
729 690
@@ -737,8 +698,8 @@ signal_result (struct GNUNET_SERVICE_Client *client,
737 */ 698 */
738static void 699static void
739broadcast_status (const char *name, 700broadcast_status (const char *name,
740 enum GNUNET_ARM_ServiceStatus status, 701 enum GNUNET_ARM_ServiceStatus status,
741 struct GNUNET_SERVICE_Client *unicast) 702 struct GNUNET_SERVICE_Client *unicast)
742{ 703{
743 struct GNUNET_MQ_Envelope *env; 704 struct GNUNET_MQ_Envelope *env;
744 struct GNUNET_ARM_StatusMessage *msg; 705 struct GNUNET_ARM_StatusMessage *msg;
@@ -749,13 +710,9 @@ broadcast_status (const char *name,
749 (unsigned int) status, 710 (unsigned int) status,
750 name); 711 name);
751 namelen = strlen (name) + 1; 712 namelen = strlen (name) + 1;
752 env = GNUNET_MQ_msg_extra (msg, 713 env = GNUNET_MQ_msg_extra (msg, namelen, GNUNET_MESSAGE_TYPE_ARM_STATUS);
753 namelen,
754 GNUNET_MESSAGE_TYPE_ARM_STATUS);
755 msg->status = htonl ((uint32_t) (status)); 714 msg->status = htonl ((uint32_t) (status));
756 GNUNET_memcpy ((char *) &msg[1], 715 GNUNET_memcpy ((char *) &msg[1], name, namelen);
757 name,
758 namelen);
759 if (NULL == unicast) 716 if (NULL == unicast)
760 { 717 {
761 if (NULL != notifier) 718 if (NULL != notifier)
@@ -766,8 +723,7 @@ broadcast_status (const char *name,
766 } 723 }
767 else 724 else
768 { 725 {
769 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (unicast), 726 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (unicast), env);
770 env);
771 } 727 }
772} 728}
773 729
@@ -799,44 +755,37 @@ start_process (struct ServiceList *sl,
799 lsocks = NULL; 755 lsocks = NULL;
800 ls = 0; 756 ls = 0;
801 for (sli = sl->listen_head; NULL != sli; sli = sli->next) 757 for (sli = sl->listen_head; NULL != sli; sli = sli->next)
758 {
759 GNUNET_array_append (lsocks,
760 ls,
761 GNUNET_NETWORK_get_fd (sli->listen_socket));
762 if (NULL != sli->accept_task)
802 { 763 {
803 GNUNET_array_append (lsocks, ls, 764 GNUNET_SCHEDULER_cancel (sli->accept_task);
804 GNUNET_NETWORK_get_fd (sli->listen_socket)); 765 sli->accept_task = NULL;
805 if (NULL != sli->accept_task)
806 {
807 GNUNET_SCHEDULER_cancel (sli->accept_task);
808 sli->accept_task = NULL;
809 }
810 } 766 }
767 }
811#if WINDOWS 768#if WINDOWS
812 GNUNET_array_append (lsocks, 769 GNUNET_array_append (lsocks, ls, INVALID_SOCKET);
813 ls,
814 INVALID_SOCKET);
815#else 770#else
816 GNUNET_array_append (lsocks, 771 GNUNET_array_append (lsocks, ls, -1);
817 ls,
818 -1);
819#endif 772#endif
820 773
821 /* obtain configuration */ 774 /* obtain configuration */
822 if (GNUNET_OK != 775 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
823 GNUNET_CONFIGURATION_get_value_string (cfg, 776 sl->name,
824 sl->name, 777 "PREFIX",
825 "PREFIX", 778 &loprefix))
826 &loprefix))
827 loprefix = GNUNET_strdup (prefix_command); 779 loprefix = GNUNET_strdup (prefix_command);
828 else 780 else
829 loprefix = GNUNET_CONFIGURATION_expand_dollar (cfg, 781 loprefix = GNUNET_CONFIGURATION_expand_dollar (cfg, loprefix);
830 loprefix); 782 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
831 if (GNUNET_OK != 783 sl->name,
832 GNUNET_CONFIGURATION_get_value_string (cfg, 784 "OPTIONS",
833 sl->name, 785 &options))
834 "OPTIONS",
835 &options))
836 options = NULL; 786 options = NULL;
837 else 787 else
838 options = GNUNET_CONFIGURATION_expand_dollar (cfg, 788 options = GNUNET_CONFIGURATION_expand_dollar (cfg, options);
839 options);
840 { 789 {
841 char *new_options; 790 char *new_options;
842 char *optpos; 791 char *optpos;
@@ -844,8 +793,7 @@ start_process (struct ServiceList *sl,
844 793
845 fin_options = GNUNET_strdup (final_option); 794 fin_options = GNUNET_strdup (final_option);
846 /* replace '{}' with service name */ 795 /* replace '{}' with service name */
847 while (NULL != (optpos = strstr (fin_options, 796 while (NULL != (optpos = strstr (fin_options, "{}")))
848 "{}")))
849 { 797 {
850 /* terminate string at opening parenthesis */ 798 /* terminate string at opening parenthesis */
851 *optpos = 0; 799 *optpos = 0;
@@ -861,10 +809,7 @@ start_process (struct ServiceList *sl,
861 { 809 {
862 /* combine "fin_options" with "options" */ 810 /* combine "fin_options" with "options" */
863 optpos = options; 811 optpos = options;
864 GNUNET_asprintf (&options, 812 GNUNET_asprintf (&options, "%s %s", fin_options, optpos);
865 "%s %s",
866 fin_options,
867 optpos);
868 GNUNET_free (fin_options); 813 GNUNET_free (fin_options);
869 GNUNET_free (optpos); 814 GNUNET_free (optpos);
870 } 815 }
@@ -874,23 +819,19 @@ start_process (struct ServiceList *sl,
874 options = fin_options; 819 options = fin_options;
875 } 820 }
876 } 821 }
877 options = GNUNET_CONFIGURATION_expand_dollar (cfg, 822 options = GNUNET_CONFIGURATION_expand_dollar (cfg, options);
878 options); 823 use_debug = GNUNET_CONFIGURATION_get_value_yesno (cfg, sl->name, "DEBUG");
879 use_debug = GNUNET_CONFIGURATION_get_value_yesno (cfg,
880 sl->name,
881 "DEBUG");
882 { 824 {
883 const char *service_type = NULL; 825 const char *service_type = NULL;
884 const char *choices[] = { "GNUNET", "SIMPLE", NULL }; 826 const char *choices[] = {"GNUNET", "SIMPLE", NULL};
885 827
886 is_simple_service = GNUNET_NO; 828 is_simple_service = GNUNET_NO;
887 if ( (GNUNET_OK == 829 if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_choice (cfg,
888 GNUNET_CONFIGURATION_get_value_choice (cfg, 830 sl->name,
889 sl->name, 831 "TYPE",
890 "TYPE", 832 choices,
891 choices, 833 &service_type)) &&
892 &service_type)) && 834 (0 == strcasecmp (service_type, "SIMPLE")))
893 (0 == strcasecmp (service_type, "SIMPLE")) )
894 is_simple_service = GNUNET_YES; 835 is_simple_service = GNUNET_YES;
895 } 836 }
896 837
@@ -901,81 +842,79 @@ start_process (struct ServiceList *sl,
901 command line options. */ 842 command line options. */
902 binary = GNUNET_strdup (sl->binary); 843 binary = GNUNET_strdup (sl->binary);
903 binary = GNUNET_CONFIGURATION_expand_dollar (cfg, binary); 844 binary = GNUNET_CONFIGURATION_expand_dollar (cfg, binary);
904 GNUNET_asprintf (&quotedbinary, 845 GNUNET_asprintf (&quotedbinary, "\"%s\"", sl->binary);
905 "\"%s\"",
906 sl->binary);
907 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 846 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
908 "Starting simple service `%s' using binary `%s'\n", 847 "Starting simple service `%s' using binary `%s'\n",
909 sl->name, sl->binary); 848 sl->name,
849 sl->binary);
910 /* FIXME: dollar expansion should only be done outside 850 /* FIXME: dollar expansion should only be done outside
911 * of ''-quoted strings, escaping should be considered. */ 851 * of ''-quoted strings, escaping should be considered. */
912 if (NULL != options) 852 if (NULL != options)
913 options = GNUNET_CONFIGURATION_expand_dollar (cfg, options); 853 options = GNUNET_CONFIGURATION_expand_dollar (cfg, options);
914 sl->proc = 854 sl->proc = GNUNET_OS_start_process_s (sl->pipe_control,
915 GNUNET_OS_start_process_s (sl->pipe_control, 855 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
916 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 856 lsocks,
917 lsocks, 857 loprefix,
918 loprefix, 858 quotedbinary,
919 quotedbinary, 859 options,
920 options, 860 NULL);
921 NULL);
922 } 861 }
923 else 862 else
924 { 863 {
925 /* actually start process */ 864 /* actually start process */
926 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 865 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
927 "Starting service `%s' using binary `%s' and configuration `%s'\n", 866 "Starting service `%s' using binary `%s' and configuration `%s'\n",
928 sl->name, sl->binary, sl->config); 867 sl->name,
868 sl->binary,
869 sl->config);
929 binary = GNUNET_OS_get_libexec_binary_path (sl->binary); 870 binary = GNUNET_OS_get_libexec_binary_path (sl->binary);
930 GNUNET_asprintf (&quotedbinary, 871 GNUNET_asprintf (&quotedbinary, "\"%s\"", binary);
931 "\"%s\"",
932 binary);
933 872
934 if (GNUNET_YES == use_debug) 873 if (GNUNET_YES == use_debug)
935 { 874 {
936 if (NULL == sl->config) 875 if (NULL == sl->config)
937 sl->proc = 876 sl->proc = GNUNET_OS_start_process_s (sl->pipe_control,
938 GNUNET_OS_start_process_s (sl->pipe_control, 877 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
939 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 878 lsocks,
940 lsocks, 879 loprefix,
941 loprefix, 880 quotedbinary,
942 quotedbinary, 881 "-L",
943 "-L", "DEBUG", 882 "DEBUG",
944 options, 883 options,
945 NULL); 884 NULL);
946 else 885 else
947 sl->proc = 886 sl->proc = GNUNET_OS_start_process_s (sl->pipe_control,
948 GNUNET_OS_start_process_s (sl->pipe_control, 887 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
949 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 888 lsocks,
950 lsocks, 889 loprefix,
951 loprefix, 890 quotedbinary,
952 quotedbinary, 891 "-c",
953 "-c", sl->config, 892 sl->config,
954 "-L", "DEBUG", 893 "-L",
955 options, 894 "DEBUG",
956 NULL); 895 options,
896 NULL);
957 } 897 }
958 else 898 else
959 { 899 {
960 if (NULL == sl->config) 900 if (NULL == sl->config)
961 sl->proc = 901 sl->proc = GNUNET_OS_start_process_s (sl->pipe_control,
962 GNUNET_OS_start_process_s (sl->pipe_control, 902 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
963 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 903 lsocks,
964 lsocks, 904 loprefix,
965 loprefix, 905 quotedbinary,
966 quotedbinary, 906 options,
967 options, 907 NULL);
968 NULL);
969 else 908 else
970 sl->proc = 909 sl->proc = GNUNET_OS_start_process_s (sl->pipe_control,
971 GNUNET_OS_start_process_s (sl->pipe_control, 910 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
972 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 911 lsocks,
973 lsocks, 912 loprefix,
974 loprefix, 913 quotedbinary,
975 quotedbinary, 914 "-c",
976 "-c", sl->config, 915 sl->config,
977 options, 916 options,
978 NULL); 917 NULL);
979 } 918 }
980 } 919 }
981 GNUNET_free (binary); 920 GNUNET_free (binary);
@@ -983,8 +922,8 @@ start_process (struct ServiceList *sl,
983 if (NULL == sl->proc) 922 if (NULL == sl->proc)
984 { 923 {
985 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 924 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
986 _("Failed to start service `%s'\n"), 925 _ ("Failed to start service `%s'\n"),
987 sl->name); 926 sl->name);
988 if (client) 927 if (client)
989 signal_result (client, 928 signal_result (client,
990 sl->name, 929 sl->name,
@@ -994,23 +933,16 @@ start_process (struct ServiceList *sl,
994 else 933 else
995 { 934 {
996 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 935 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
997 _("Starting service `%s'\n"), 936 _ ("Starting service `%s'\n"),
998 sl->name); 937 sl->name);
999 broadcast_status (sl->name, 938 broadcast_status (sl->name, GNUNET_ARM_SERVICE_STARTING, NULL);
1000 GNUNET_ARM_SERVICE_STARTING,
1001 NULL);
1002 if (client) 939 if (client)
1003 signal_result (client, 940 signal_result (client, sl->name, request_id, GNUNET_ARM_RESULT_STARTING);
1004 sl->name,
1005 request_id,
1006 GNUNET_ARM_RESULT_STARTING);
1007 } 941 }
1008 /* clean up */ 942 /* clean up */
1009 GNUNET_free (loprefix); 943 GNUNET_free (loprefix);
1010 GNUNET_free (options); 944 GNUNET_free (options);
1011 GNUNET_array_grow (lsocks, 945 GNUNET_array_grow (lsocks, ls, 0);
1012 ls,
1013 0);
1014} 946}
1015 947
1016 948
@@ -1028,11 +960,11 @@ find_service (const char *name)
1028 960
1029 sl = running_head; 961 sl = running_head;
1030 while (sl != NULL) 962 while (sl != NULL)
1031 { 963 {
1032 if (0 == strcasecmp (sl->name, name)) 964 if (0 == strcasecmp (sl->name, name))
1033 return sl; 965 return sl;
1034 sl = sl->next; 966 sl = sl->next;
1035 } 967 }
1036 return NULL; 968 return NULL;
1037} 969}
1038 970
@@ -1066,7 +998,7 @@ accept_connection (void *cls)
1066static void 998static void
1067create_listen_socket (struct sockaddr *sa, 999create_listen_socket (struct sockaddr *sa,
1068 socklen_t addr_len, 1000 socklen_t addr_len,
1069 struct ServiceList *sl) 1001 struct ServiceList *sl)
1070{ 1002{
1071 static int on = 1; 1003 static int on = 1;
1072 struct GNUNET_NETWORK_Handle *sock; 1004 struct GNUNET_NETWORK_Handle *sock;
@@ -1079,23 +1011,16 @@ create_listen_socket (struct sockaddr *sa,
1079 switch (sa->sa_family) 1011 switch (sa->sa_family)
1080 { 1012 {
1081 case AF_INET: 1013 case AF_INET:
1082 sock = GNUNET_NETWORK_socket_create (PF_INET, 1014 sock = GNUNET_NETWORK_socket_create (PF_INET, SOCK_STREAM, 0);
1083 SOCK_STREAM,
1084 0);
1085 break; 1015 break;
1086 case AF_INET6: 1016 case AF_INET6:
1087 sock = GNUNET_NETWORK_socket_create (PF_INET6, 1017 sock = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
1088 SOCK_STREAM,
1089 0);
1090 break; 1018 break;
1091 case AF_UNIX: 1019 case AF_UNIX:
1092 if (0 == strcmp (GNUNET_a2s (sa, 1020 if (0 == strcmp (GNUNET_a2s (sa, addr_len),
1093 addr_len), 1021 "@")) /* Do not bind to blank UNIX path! */
1094 "@")) /* Do not bind to blank UNIX path! */
1095 return; 1022 return;
1096 sock = GNUNET_NETWORK_socket_create (PF_UNIX, 1023 sock = GNUNET_NETWORK_socket_create (PF_UNIX, SOCK_STREAM, 0);
1097 SOCK_STREAM,
1098 0);
1099 break; 1024 break;
1100 default: 1025 default:
1101 GNUNET_break (0); 1026 GNUNET_break (0);
@@ -1106,48 +1031,44 @@ create_listen_socket (struct sockaddr *sa,
1106 if (NULL == sock) 1031 if (NULL == sock)
1107 { 1032 {
1108 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1033 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1109 _("Unable to create socket for service `%s': %s\n"), 1034 _ ("Unable to create socket for service `%s': %s\n"),
1110 sl->name, 1035 sl->name,
1111 STRERROR (errno)); 1036 strerror (errno));
1112 GNUNET_free (sa); 1037 GNUNET_free (sa);
1113 return; 1038 return;
1114 } 1039 }
1115 if (GNUNET_OK != 1040 if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (sock,
1116 GNUNET_NETWORK_socket_setsockopt (sock, 1041 SOL_SOCKET,
1117 SOL_SOCKET, 1042 SO_REUSEADDR,
1118 SO_REUSEADDR, 1043 &on,
1119 &on, 1044 sizeof (on)))
1120 sizeof (on)))
1121 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 1045 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1122 "setsockopt"); 1046 "setsockopt");
1123#ifdef IPV6_V6ONLY 1047#ifdef IPV6_V6ONLY
1124 if ( (sa->sa_family == AF_INET6) && 1048 if ((sa->sa_family == AF_INET6) &&
1125 (GNUNET_OK != 1049 (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (sock,
1126 GNUNET_NETWORK_socket_setsockopt (sock, 1050 IPPROTO_IPV6,
1127 IPPROTO_IPV6, 1051 IPV6_V6ONLY,
1128 IPV6_V6ONLY, 1052 &on,
1129 &on, 1053 sizeof (on))))
1130 sizeof (on))) )
1131 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 1054 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1132 "setsockopt"); 1055 "setsockopt");
1133#endif 1056#endif
1134#ifndef WINDOWS 1057#ifndef WINDOWS
1135 if (AF_UNIX == sa->sa_family) 1058 if (AF_UNIX == sa->sa_family)
1136 GNUNET_NETWORK_unix_precheck ((struct sockaddr_un *) sa); 1059 GNUNET_NETWORK_unix_precheck ((struct sockaddr_un *) sa);
1137#endif 1060#endif
1138 if (GNUNET_OK != 1061 if (GNUNET_OK !=
1139 GNUNET_NETWORK_socket_bind (sock, 1062 GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) sa, addr_len))
1140 (const struct sockaddr *) sa,
1141 addr_len))
1142 { 1063 {
1143 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1064 GNUNET_log (
1144 _("Unable to bind listening socket for service `%s' to address `%s': %s\n"), 1065 GNUNET_ERROR_TYPE_WARNING,
1145 sl->name, 1066 _ (
1146 GNUNET_a2s (sa, 1067 "Unable to bind listening socket for service `%s' to address `%s': %s\n"),
1147 addr_len), 1068 sl->name,
1148 STRERROR (errno)); 1069 GNUNET_a2s (sa, addr_len),
1149 GNUNET_break (GNUNET_OK == 1070 strerror (errno));
1150 GNUNET_NETWORK_socket_close (sock)); 1071 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
1151 GNUNET_free (sa); 1072 GNUNET_free (sa);
1152 return; 1073 return;
1153 } 1074 }
@@ -1155,51 +1076,41 @@ create_listen_socket (struct sockaddr *sa,
1155 if ((AF_UNIX == sa->sa_family) 1076 if ((AF_UNIX == sa->sa_family)
1156#ifdef LINUX 1077#ifdef LINUX
1157 /* Permission settings are not required when abstract sockets are used */ 1078 /* Permission settings are not required when abstract sockets are used */
1158 && ('\0' != ((const struct sockaddr_un *)sa)->sun_path[0]) 1079 && ('\0' != ((const struct sockaddr_un *) sa)->sun_path[0])
1159#endif 1080#endif
1160 ) 1081 )
1161 { 1082 {
1162 match_uid = 1083 match_uid =
1163 GNUNET_CONFIGURATION_get_value_yesno (cfg, 1084 GNUNET_CONFIGURATION_get_value_yesno (cfg, sl->name, "UNIX_MATCH_UID");
1164 sl->name,
1165 "UNIX_MATCH_UID");
1166 match_gid = 1085 match_gid =
1167 GNUNET_CONFIGURATION_get_value_yesno (cfg, 1086 GNUNET_CONFIGURATION_get_value_yesno (cfg, sl->name, "UNIX_MATCH_GID");
1168 sl->name, 1087 GNUNET_DISK_fix_permissions (((const struct sockaddr_un *) sa)->sun_path,
1169 "UNIX_MATCH_GID");
1170 GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)sa)->sun_path,
1171 match_uid, 1088 match_uid,
1172 match_gid); 1089 match_gid);
1173
1174 } 1090 }
1175#endif 1091#endif
1176 if (GNUNET_OK != 1092 if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 5))
1177 GNUNET_NETWORK_socket_listen (sock, 5))
1178 { 1093 {
1179 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, 1094 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "listen");
1180 "listen"); 1095 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
1181 GNUNET_break (GNUNET_OK ==
1182 GNUNET_NETWORK_socket_close (sock));
1183 GNUNET_free (sa); 1096 GNUNET_free (sa);
1184 return; 1097 return;
1185 } 1098 }
1186 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1099 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1187 _("ARM now monitors connections to service `%s' at `%s'\n"), 1100 _ ("ARM now monitors connections to service `%s' at `%s'\n"),
1188 sl->name, 1101 sl->name,
1189 GNUNET_a2s (sa, 1102 GNUNET_a2s (sa, addr_len));
1190 addr_len));
1191 sli = GNUNET_new (struct ServiceListeningInfo); 1103 sli = GNUNET_new (struct ServiceListeningInfo);
1192 sli->service_addr = sa; 1104 sli->service_addr = sa;
1193 sli->service_addr_len = addr_len; 1105 sli->service_addr_len = addr_len;
1194 sli->listen_socket = sock; 1106 sli->listen_socket = sock;
1195 sli->sl = sl; 1107 sli->sl = sl;
1196 sli->accept_task 1108 sli->accept_task =
1197 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 1109 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
1198 sock, 1110 sock,
1199 &accept_connection, sli); 1111 &accept_connection,
1200 GNUNET_CONTAINER_DLL_insert (sl->listen_head, 1112 sli);
1201 sl->listen_tail, 1113 GNUNET_CONTAINER_DLL_insert (sl->listen_head, sl->listen_tail, sli);
1202 sli);
1203} 1114}
1204 1115
1205 1116
@@ -1213,9 +1124,7 @@ static void
1213free_service (struct ServiceList *sl) 1124free_service (struct ServiceList *sl)
1214{ 1125{
1215 GNUNET_assert (GNUNET_YES == in_shutdown); 1126 GNUNET_assert (GNUNET_YES == in_shutdown);
1216 GNUNET_CONTAINER_DLL_remove (running_head, 1127 GNUNET_CONTAINER_DLL_remove (running_head, running_tail, sl);
1217 running_tail,
1218 sl);
1219 GNUNET_assert (NULL == sl->listen_head); 1128 GNUNET_assert (NULL == sl->listen_head);
1220 GNUNET_free_non_null (sl->config); 1129 GNUNET_free_non_null (sl->config);
1221 GNUNET_free_non_null (sl->binary); 1130 GNUNET_free_non_null (sl->binary);
@@ -1233,8 +1142,7 @@ free_service (struct ServiceList *sl)
1233 * #GNUNET_SYSERR to close it (signal serious error) 1142 * #GNUNET_SYSERR to close it (signal serious error)
1234 */ 1143 */
1235static int 1144static int
1236check_start (void *cls, 1145check_start (void *cls, const struct GNUNET_ARM_Message *amsg)
1237 const struct GNUNET_ARM_Message *amsg)
1238{ 1146{
1239 (void) cls; 1147 (void) cls;
1240 GNUNET_MQ_check_zero_termination (amsg); 1148 GNUNET_MQ_check_zero_termination (amsg);
@@ -1249,8 +1157,7 @@ check_start (void *cls,
1249 * @param amsg the actual message 1157 * @param amsg the actual message
1250 */ 1158 */
1251static void 1159static void
1252handle_start (void *cls, 1160handle_start (void *cls, const struct GNUNET_ARM_Message *amsg)
1253 const struct GNUNET_ARM_Message *amsg)
1254{ 1161{
1255 struct GNUNET_SERVICE_Client *client = cls; 1162 struct GNUNET_SERVICE_Client *client = cls;
1256 const char *servicename; 1163 const char *servicename;
@@ -1265,7 +1172,7 @@ handle_start (void *cls,
1265 signal_result (client, 1172 signal_result (client,
1266 servicename, 1173 servicename,
1267 request_id, 1174 request_id,
1268 GNUNET_ARM_RESULT_IN_SHUTDOWN); 1175 GNUNET_ARM_RESULT_IN_SHUTDOWN);
1269 return; 1176 return;
1270 } 1177 }
1271 sl = find_service (servicename); 1178 sl = find_service (servicename);
@@ -1274,7 +1181,7 @@ handle_start (void *cls,
1274 signal_result (client, 1181 signal_result (client,
1275 servicename, 1182 servicename,
1276 request_id, 1183 request_id,
1277 GNUNET_ARM_RESULT_IS_NOT_KNOWN); 1184 GNUNET_ARM_RESULT_IS_NOT_KNOWN);
1278 return; 1185 return;
1279 } 1186 }
1280 sl->force_start = GNUNET_YES; 1187 sl->force_start = GNUNET_YES;
@@ -1283,12 +1190,10 @@ handle_start (void *cls,
1283 signal_result (client, 1190 signal_result (client,
1284 servicename, 1191 servicename,
1285 request_id, 1192 request_id,
1286 GNUNET_ARM_RESULT_IS_STARTED_ALREADY); 1193 GNUNET_ARM_RESULT_IS_STARTED_ALREADY);
1287 return; 1194 return;
1288 } 1195 }
1289 start_process (sl, 1196 start_process (sl, client, request_id);
1290 client,
1291 request_id);
1292} 1197}
1293 1198
1294 1199
@@ -1301,8 +1206,7 @@ static void
1301trigger_shutdown (void *cls) 1206trigger_shutdown (void *cls)
1302{ 1207{
1303 (void) cls; 1208 (void) cls;
1304 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Triggering shutdown\n");
1305 "Triggering shutdown\n");
1306 GNUNET_SCHEDULER_shutdown (); 1210 GNUNET_SCHEDULER_shutdown ();
1307} 1211}
1308 1212
@@ -1316,8 +1220,7 @@ trigger_shutdown (void *cls)
1316 * #GNUNET_SYSERR to close it (signal serious error) 1220 * #GNUNET_SYSERR to close it (signal serious error)
1317 */ 1221 */
1318static int 1222static int
1319check_stop (void *cls, 1223check_stop (void *cls, const struct GNUNET_ARM_Message *amsg)
1320 const struct GNUNET_ARM_Message *amsg)
1321{ 1224{
1322 (void) cls; 1225 (void) cls;
1323 GNUNET_MQ_check_zero_termination (amsg); 1226 GNUNET_MQ_check_zero_termination (amsg);
@@ -1332,8 +1235,7 @@ check_stop (void *cls,
1332 * @param amsg the actual message 1235 * @param amsg the actual message
1333 */ 1236 */
1334static void 1237static void
1335handle_stop (void *cls, 1238handle_stop (void *cls, const struct GNUNET_ARM_Message *amsg)
1336 const struct GNUNET_ARM_Message *amsg)
1337{ 1239{
1338 struct GNUNET_SERVICE_Client *client = cls; 1240 struct GNUNET_SERVICE_Client *client = cls;
1339 struct ServiceList *sl; 1241 struct ServiceList *sl;
@@ -1343,22 +1245,15 @@ handle_stop (void *cls,
1343 request_id = GNUNET_ntohll (amsg->request_id); 1245 request_id = GNUNET_ntohll (amsg->request_id);
1344 servicename = (const char *) &amsg[1]; 1246 servicename = (const char *) &amsg[1];
1345 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1247 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1346 _("Preparing to stop `%s'\n"), 1248 _ ("Preparing to stop `%s'\n"),
1347 servicename); 1249 servicename);
1348 GNUNET_SERVICE_client_continue (client); 1250 GNUNET_SERVICE_client_continue (client);
1349 if (0 == strcasecmp (servicename, 1251 if (0 == strcasecmp (servicename, "arm"))
1350 "arm"))
1351 { 1252 {
1352 broadcast_status (servicename, 1253 broadcast_status (servicename, GNUNET_ARM_SERVICE_STOPPING, NULL);
1353 GNUNET_ARM_SERVICE_STOPPING, 1254 signal_result (client, servicename, request_id, GNUNET_ARM_RESULT_STOPPING);
1354 NULL);
1355 signal_result (client,
1356 servicename,
1357 request_id,
1358 GNUNET_ARM_RESULT_STOPPING);
1359 GNUNET_SERVICE_client_persist (client); 1255 GNUNET_SERVICE_client_persist (client);
1360 GNUNET_SCHEDULER_add_now (&trigger_shutdown, 1256 GNUNET_SCHEDULER_add_now (&trigger_shutdown, NULL);
1361 NULL);
1362 return; 1257 return;
1363 } 1258 }
1364 sl = find_service (servicename); 1259 sl = find_service (servicename);
@@ -1384,32 +1279,28 @@ handle_stop (void *cls,
1384 { 1279 {
1385 /* killing already in progress */ 1280 /* killing already in progress */
1386 signal_result (client, 1281 signal_result (client,
1387 servicename, 1282 servicename,
1388 request_id, 1283 request_id,
1389 GNUNET_ARM_RESULT_IS_STOPPING_ALREADY); 1284 GNUNET_ARM_RESULT_IS_STOPPING_ALREADY);
1390 return; 1285 return;
1391 } 1286 }
1392 if (NULL == sl->proc) 1287 if (NULL == sl->proc)
1393 { 1288 {
1394 /* process is down */ 1289 /* process is down */
1395 signal_result (client, 1290 signal_result (client,
1396 servicename, 1291 servicename,
1397 request_id, 1292 request_id,
1398 GNUNET_ARM_RESULT_IS_STOPPED_ALREADY); 1293 GNUNET_ARM_RESULT_IS_STOPPED_ALREADY);
1399 return; 1294 return;
1400 } 1295 }
1401 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1296 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1402 "Sending kill signal to service `%s', waiting for process to die.\n", 1297 "Sending kill signal to service `%s', waiting for process to die.\n",
1403 servicename); 1298 servicename);
1404 broadcast_status (servicename, 1299 broadcast_status (servicename, GNUNET_ARM_SERVICE_STOPPING, NULL);
1405 GNUNET_ARM_SERVICE_STOPPING,
1406 NULL);
1407 /* no signal_start - only when it's STOPPED */ 1300 /* no signal_start - only when it's STOPPED */
1408 sl->killed_at = GNUNET_TIME_absolute_get (); 1301 sl->killed_at = GNUNET_TIME_absolute_get ();
1409 if (0 != GNUNET_OS_process_kill (sl->proc, 1302 if (0 != GNUNET_OS_process_kill (sl->proc, GNUNET_TERM_SIG))
1410 GNUNET_TERM_SIG)) 1303 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
1411 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
1412 "kill");
1413 sl->killing_client = client; 1304 sl->killing_client = client;
1414 sl->killing_client_request_id = request_id; 1305 sl->killing_client_request_id = request_id;
1415} 1306}
@@ -1422,8 +1313,7 @@ handle_stop (void *cls,
1422 * @param message the actual message 1313 * @param message the actual message
1423 */ 1314 */
1424static void 1315static void
1425handle_list (void *cls, 1316handle_list (void *cls, const struct GNUNET_ARM_Message *request)
1426 const struct GNUNET_ARM_Message *request)
1427{ 1317{
1428 struct GNUNET_SERVICE_Client *client = cls; 1318 struct GNUNET_SERVICE_Client *client = cls;
1429 struct GNUNET_MQ_Envelope *env; 1319 struct GNUNET_MQ_Envelope *env;
@@ -1461,16 +1351,11 @@ handle_list (void *cls,
1461 if (NULL != sl->proc) 1351 if (NULL != sl->proc)
1462 { 1352 {
1463 size_t s = strlen (sl->name) + strlen (sl->binary) + 4; 1353 size_t s = strlen (sl->name) + strlen (sl->binary) + 4;
1464 GNUNET_snprintf (pos, 1354 GNUNET_snprintf (pos, s, "%s (%s)", sl->name, sl->binary);
1465 s,
1466 "%s (%s)",
1467 sl->name,
1468 sl->binary);
1469 pos += s; 1355 pos += s;
1470 } 1356 }
1471 } 1357 }
1472 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), 1358 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
1473 env);
1474 GNUNET_SERVICE_client_continue (client); 1359 GNUNET_SERVICE_client_continue (client);
1475} 1360}
1476 1361
@@ -1482,18 +1367,15 @@ handle_list (void *cls,
1482 * @param message the actual message 1367 * @param message the actual message
1483 */ 1368 */
1484static void 1369static void
1485handle_test (void *cls, 1370handle_test (void *cls, const struct GNUNET_MessageHeader *message)
1486 const struct GNUNET_MessageHeader *message)
1487{ 1371{
1488 struct GNUNET_SERVICE_Client *client = cls; 1372 struct GNUNET_SERVICE_Client *client = cls;
1489 struct GNUNET_MQ_Envelope *env; 1373 struct GNUNET_MQ_Envelope *env;
1490 struct GNUNET_MessageHeader *msg; 1374 struct GNUNET_MessageHeader *msg;
1491 1375
1492 (void) message; 1376 (void) message;
1493 env = GNUNET_MQ_msg (msg, 1377 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_ARM_TEST);
1494 GNUNET_MESSAGE_TYPE_ARM_TEST); 1378 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
1495 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
1496 env);
1497 GNUNET_SERVICE_client_continue (client); 1379 GNUNET_SERVICE_client_continue (client);
1498} 1380}
1499 1381
@@ -1505,8 +1387,7 @@ handle_test (void *cls,
1505static void 1387static void
1506do_shutdown () 1388do_shutdown ()
1507{ 1389{
1508 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1390 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Last shutdown phase\n");
1509 "Last shutdown phase\n");
1510 if (NULL != notifier) 1391 if (NULL != notifier)
1511 { 1392 {
1512 GNUNET_notification_context_destroy (notifier); 1393 GNUNET_notification_context_destroy (notifier);
@@ -1538,9 +1419,7 @@ list_count (struct ServiceList *running_head)
1538 unsigned int res; 1419 unsigned int res;
1539 1420
1540 for (res = 0, i = running_head; NULL != i; i = i->next, res++) 1421 for (res = 0, i = running_head; NULL != i; i = i->next, res++)
1541 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s\n", i->name);
1542 "%s\n",
1543 i->name);
1544 return res; 1423 return res;
1545} 1424}
1546 1425
@@ -1558,8 +1437,7 @@ shutdown_task (void *cls)
1558 struct ServiceListeningInfo *sli; 1437 struct ServiceListeningInfo *sli;
1559 1438
1560 (void) cls; 1439 (void) cls;
1561 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "First shutdown phase\n");
1562 "First shutdown phase\n");
1563 if (NULL != child_restart_task) 1441 if (NULL != child_restart_task)
1564 { 1442 {
1565 GNUNET_SCHEDULER_cancel (child_restart_task); 1443 GNUNET_SCHEDULER_cancel (child_restart_task);
@@ -1571,9 +1449,7 @@ shutdown_task (void *cls)
1571 { 1449 {
1572 while (NULL != (sli = pos->listen_head)) 1450 while (NULL != (sli = pos->listen_head))
1573 { 1451 {
1574 GNUNET_CONTAINER_DLL_remove (pos->listen_head, 1452 GNUNET_CONTAINER_DLL_remove (pos->listen_head, pos->listen_tail, sli);
1575 pos->listen_tail,
1576 sli);
1577 if (NULL != sli->accept_task) 1453 if (NULL != sli->accept_task)
1578 { 1454 {
1579 GNUNET_SCHEDULER_cancel (sli->accept_task); 1455 GNUNET_SCHEDULER_cancel (sli->accept_task);
@@ -1592,14 +1468,10 @@ shutdown_task (void *cls)
1592 nxt = pos->next; 1468 nxt = pos->next;
1593 if (NULL != pos->proc) 1469 if (NULL != pos->proc)
1594 { 1470 {
1595 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1471 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stopping service `%s'\n", pos->name);
1596 "Stopping service `%s'\n",
1597 pos->name);
1598 pos->killed_at = GNUNET_TIME_absolute_get (); 1472 pos->killed_at = GNUNET_TIME_absolute_get ();
1599 if (0 != GNUNET_OS_process_kill (pos->proc, 1473 if (0 != GNUNET_OS_process_kill (pos->proc, GNUNET_TERM_SIG))
1600 GNUNET_TERM_SIG)) 1474 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
1601 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
1602 "kill");
1603 } 1475 }
1604 else 1476 else
1605 { 1477 {
@@ -1611,8 +1483,8 @@ shutdown_task (void *cls)
1611 do_shutdown (); 1483 do_shutdown ();
1612 else 1484 else
1613 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1485 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1614 "Delaying shutdown, have %u childs still running\n", 1486 "Delaying shutdown, have %u childs still running\n",
1615 list_count (running_head)); 1487 list_count (running_head));
1616} 1488}
1617 1489
1618 1490
@@ -1646,48 +1518,47 @@ delayed_restart_task (void *cls)
1646 /* restart is now allowed */ 1518 /* restart is now allowed */
1647 if (sl->force_start) 1519 if (sl->force_start)
1648 { 1520 {
1649 /* process should run by default, start immediately */ 1521 /* process should run by default, start immediately */
1650 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1522 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1651 _("Restarting service `%s'.\n"), 1523 _ ("Restarting service `%s'.\n"),
1652 sl->name); 1524 sl->name);
1653 start_process (sl, 1525 start_process (sl, NULL, 0);
1654 NULL,
1655 0);
1656 } 1526 }
1657 else 1527 else
1658 { 1528 {
1659 /* process is run on-demand, ensure it is re-started if there is demand */ 1529 /* process is run on-demand, ensure it is re-started if there is demand */
1660 for (sli = sl->listen_head; NULL != sli; sli = sli->next) 1530 for (sli = sl->listen_head; NULL != sli; sli = sli->next)
1661 if (NULL == sli->accept_task) 1531 if (NULL == sli->accept_task)
1662 { 1532 {
1663 /* accept was actually paused, so start it again */ 1533 /* accept was actually paused, so start it again */
1664 sli->accept_task 1534 sli->accept_task =
1665 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 1535 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
1666 sli->listen_socket, 1536 sli->listen_socket,
1667 &accept_connection, 1537 &accept_connection,
1668 sli); 1538 sli);
1669 } 1539 }
1670 } 1540 }
1671 } 1541 }
1672 else 1542 else
1673 { 1543 {
1674 /* update calculation for earliest time to reactivate a service */ 1544 /* update calculation for earliest time to reactivate a service */
1675 lowestRestartDelay = 1545 lowestRestartDelay =
1676 GNUNET_TIME_relative_min (lowestRestartDelay, 1546 GNUNET_TIME_relative_min (lowestRestartDelay,
1677 GNUNET_TIME_absolute_get_remaining 1547 GNUNET_TIME_absolute_get_remaining (
1678 (sl->restart_at)); 1548 sl->restart_at));
1679 } 1549 }
1680 } 1550 }
1681 if (lowestRestartDelay.rel_value_us != GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) 1551 if (lowestRestartDelay.rel_value_us !=
1552 GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
1682 { 1553 {
1683 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1554 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1684 "Will restart process in %s\n", 1555 "Will restart process in %s\n",
1685 GNUNET_STRINGS_relative_time_to_string (lowestRestartDelay, 1556 GNUNET_STRINGS_relative_time_to_string (lowestRestartDelay,
1686 GNUNET_YES)); 1557 GNUNET_YES));
1687 child_restart_task = 1558 child_restart_task =
1688 GNUNET_SCHEDULER_add_delayed_with_priority (lowestRestartDelay, 1559 GNUNET_SCHEDULER_add_delayed_with_priority (lowestRestartDelay,
1689 GNUNET_SCHEDULER_PRIORITY_IDLE, 1560 GNUNET_SCHEDULER_PRIORITY_IDLE,
1690 &delayed_restart_task, 1561 &delayed_restart_task,
1691 NULL); 1562 NULL);
1692 } 1563 }
1693} 1564}
@@ -1714,13 +1585,10 @@ maint_child_death (void *cls)
1714 const struct GNUNET_DISK_FileHandle *pr; 1585 const struct GNUNET_DISK_FileHandle *pr;
1715 1586
1716 (void) cls; 1587 (void) cls;
1717 pr = GNUNET_DISK_pipe_handle (sigpipe, 1588 pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
1718 GNUNET_DISK_PIPE_END_READ);
1719 child_death_task = NULL; 1589 child_death_task = NULL;
1720 /* consume the signal */ 1590 /* consume the signal */
1721 GNUNET_break (0 < GNUNET_DISK_file_read (pr, 1591 GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c)));
1722 &c,
1723 sizeof (c)));
1724 1592
1725 /* check for services that died (WAITPID) */ 1593 /* check for services that died (WAITPID) */
1726 next = running_head; 1594 next = running_head;
@@ -1743,10 +1611,7 @@ maint_child_death (void *cls)
1743 pid_t pid; 1611 pid_t pid;
1744 1612
1745 pid = GNUNET_OS_process_get_pid (pos->proc); 1613 pid = GNUNET_OS_process_get_pid (pos->proc);
1746 ret = wait4 (pid, 1614 ret = wait4 (pid, &status, WNOHANG, &ru);
1747 &status,
1748 WNOHANG,
1749 &ru);
1750 if (ret <= 0) 1615 if (ret <= 0)
1751 continue; /* no process done */ 1616 continue; /* no process done */
1752 if (WIFEXITED (status)) 1617 if (WIFEXITED (status))
@@ -1776,8 +1641,8 @@ maint_child_death (void *cls)
1776 statusType = GNUNET_OS_PROCESS_UNKNOWN; 1641 statusType = GNUNET_OS_PROCESS_UNKNOWN;
1777 statusCode = 0; 1642 statusCode = 0;
1778 } 1643 }
1779 if ( (GNUNET_OS_PROCESS_EXITED == statusType) || 1644 if ((GNUNET_OS_PROCESS_EXITED == statusType) ||
1780 (GNUNET_OS_PROCESS_SIGNALED == statusType) ) 1645 (GNUNET_OS_PROCESS_SIGNALED == statusType))
1781 { 1646 {
1782 double utime = ru.ru_utime.tv_sec + (ru.ru_utime.tv_usec / 10e6); 1647 double utime = ru.ru_utime.tv_sec + (ru.ru_utime.tv_usec / 10e6);
1783 double stime = ru.ru_stime.tv_sec + (ru.ru_stime.tv_usec / 10e6); 1648 double stime = ru.ru_stime.tv_sec + (ru.ru_stime.tv_usec / 10e6);
@@ -1796,48 +1661,45 @@ maint_child_death (void *cls)
1796 } 1661 }
1797 else /* continue with JUST this "if" as "else" (intentionally no brackets!) */ 1662 else /* continue with JUST this "if" as "else" (intentionally no brackets!) */
1798#endif 1663#endif
1799 if ( (GNUNET_SYSERR == 1664 if ((GNUNET_SYSERR == (ret = GNUNET_OS_process_status (pos->proc,
1800 (ret = 1665 &statusType,
1801 GNUNET_OS_process_status (pos->proc, 1666 &statusCode))) ||
1802 &statusType, 1667 (ret == GNUNET_NO) || (statusType == GNUNET_OS_PROCESS_STOPPED) ||
1803 &statusCode))) || 1668 (statusType == GNUNET_OS_PROCESS_UNKNOWN) ||
1804 (ret == GNUNET_NO) || 1669 (statusType == GNUNET_OS_PROCESS_RUNNING))
1805 (statusType == GNUNET_OS_PROCESS_STOPPED) ||
1806 (statusType == GNUNET_OS_PROCESS_UNKNOWN) ||
1807 (statusType == GNUNET_OS_PROCESS_RUNNING) )
1808 continue; 1670 continue;
1809 1671
1810 if (statusType == GNUNET_OS_PROCESS_EXITED) 1672 if (statusType == GNUNET_OS_PROCESS_EXITED)
1811 { 1673 {
1812 statstr = _( /* process termination method */ "exit"); 1674 statstr = _ (/* process termination method */ "exit");
1813 statcode = statusCode; 1675 statcode = statusCode;
1814 } 1676 }
1815 else if (statusType == GNUNET_OS_PROCESS_SIGNALED) 1677 else if (statusType == GNUNET_OS_PROCESS_SIGNALED)
1816 { 1678 {
1817 statstr = _( /* process termination method */ "signal"); 1679 statstr = _ (/* process termination method */ "signal");
1818 statcode = statusCode; 1680 statcode = statusCode;
1819 } 1681 }
1820 else 1682 else
1821 { 1683 {
1822 statstr = _( /* process termination method */ "unknown"); 1684 statstr = _ (/* process termination method */ "unknown");
1823 statcode = 0; 1685 statcode = 0;
1824 } 1686 }
1825 if (0 != pos->killed_at.abs_value_us) 1687 if (0 != pos->killed_at.abs_value_us)
1826 { 1688 {
1827 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1689 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1828 _("Service `%s' took %s to terminate\n"), 1690 _ ("Service `%s' took %s to terminate\n"),
1829 pos->name, 1691 pos->name,
1830 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (pos->killed_at), 1692 GNUNET_STRINGS_relative_time_to_string (
1831 GNUNET_YES)); 1693 GNUNET_TIME_absolute_get_duration (pos->killed_at),
1694 GNUNET_YES));
1832 } 1695 }
1833 GNUNET_OS_process_destroy (pos->proc); 1696 GNUNET_OS_process_destroy (pos->proc);
1834 pos->proc = NULL; 1697 pos->proc = NULL;
1835 broadcast_status (pos->name, 1698 broadcast_status (pos->name, GNUNET_ARM_SERVICE_STOPPED, NULL);
1836 GNUNET_ARM_SERVICE_STOPPED,
1837 NULL);
1838 if (NULL != pos->killing_client) 1699 if (NULL != pos->killing_client)
1839 { 1700 {
1840 signal_result (pos->killing_client, pos->name, 1701 signal_result (pos->killing_client,
1702 pos->name,
1841 pos->killing_client_request_id, 1703 pos->killing_client_request_id,
1842 GNUNET_ARM_RESULT_STOPPED); 1704 GNUNET_ARM_RESULT_STOPPED);
1843 pos->killing_client = NULL; 1705 pos->killing_client = NULL;
@@ -1845,14 +1707,14 @@ maint_child_death (void *cls)
1845 } 1707 }
1846 if (GNUNET_YES != in_shutdown) 1708 if (GNUNET_YES != in_shutdown)
1847 { 1709 {
1848 if ( (statusType == GNUNET_OS_PROCESS_EXITED) && 1710 if ((statusType == GNUNET_OS_PROCESS_EXITED) && (statcode == 0))
1849 (statcode == 0) )
1850 { 1711 {
1851 /* process terminated normally, allow restart at any time */ 1712 /* process terminated normally, allow restart at any time */
1852 pos->restart_at.abs_value_us = 0; 1713 pos->restart_at.abs_value_us = 0;
1853 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1714 GNUNET_log (
1854 _("Service `%s' terminated normally, will restart at any time\n"), 1715 GNUNET_ERROR_TYPE_INFO,
1855 pos->name); 1716 _ ("Service `%s' terminated normally, will restart at any time\n"),
1717 pos->name);
1856 /* process can still be re-started on-demand, ensure it is re-started if there is demand */ 1718 /* process can still be re-started on-demand, ensure it is re-started if there is demand */
1857 for (sli = pos->listen_head; NULL != sli; sli = sli->next) 1719 for (sli = pos->listen_head; NULL != sli; sli = sli->next)
1858 { 1720 {
@@ -1866,36 +1728,37 @@ maint_child_death (void *cls)
1866 } 1728 }
1867 else 1729 else
1868 { 1730 {
1869 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1731 GNUNET_log (
1870 _("Service `%s' terminated with status %s/%d, will restart in %s\n"), 1732 GNUNET_ERROR_TYPE_INFO,
1871 pos->name, 1733 _ ("Service `%s' terminated with status %s/%d, will restart in %s\n"),
1872 statstr, 1734 pos->name,
1873 statcode, 1735 statstr,
1874 GNUNET_STRINGS_relative_time_to_string (pos->backoff, 1736 statcode,
1875 GNUNET_YES)); 1737 GNUNET_STRINGS_relative_time_to_string (pos->backoff, GNUNET_YES));
1876 { 1738 {
1877 /* Reduce backoff based on runtime of the process, 1739 /* Reduce backoff based on runtime of the process,
1878 so that there is a cool-down if a process actually 1740 so that there is a cool-down if a process actually
1879 runs for a while. */ 1741 runs for a while. */
1880 struct GNUNET_TIME_Relative runtime; 1742 struct GNUNET_TIME_Relative runtime;
1881 unsigned int minutes; 1743 unsigned int minutes;
1882 1744
1883 runtime = GNUNET_TIME_absolute_get_duration (pos->restart_at); 1745 runtime = GNUNET_TIME_absolute_get_duration (pos->restart_at);
1884 minutes = runtime.rel_value_us / GNUNET_TIME_UNIT_MINUTES.rel_value_us; 1746 minutes =
1885 if (minutes > 31) 1747 runtime.rel_value_us / GNUNET_TIME_UNIT_MINUTES.rel_value_us;
1886 pos->backoff = GNUNET_TIME_UNIT_ZERO; 1748 if (minutes > 31)
1887 else 1749 pos->backoff = GNUNET_TIME_UNIT_ZERO;
1888 pos->backoff.rel_value_us <<= minutes; 1750 else
1889 } 1751 pos->backoff.rel_value_us <<= minutes;
1890 /* schedule restart */ 1752 }
1753 /* schedule restart */
1891 pos->restart_at = GNUNET_TIME_relative_to_absolute (pos->backoff); 1754 pos->restart_at = GNUNET_TIME_relative_to_absolute (pos->backoff);
1892 pos->backoff = GNUNET_TIME_STD_BACKOFF (pos->backoff); 1755 pos->backoff = GNUNET_TIME_STD_BACKOFF (pos->backoff);
1893 if (NULL != child_restart_task) 1756 if (NULL != child_restart_task)
1894 GNUNET_SCHEDULER_cancel (child_restart_task); 1757 GNUNET_SCHEDULER_cancel (child_restart_task);
1895 child_restart_task 1758 child_restart_task =
1896 = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, 1759 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
1897 &delayed_restart_task, 1760 &delayed_restart_task,
1898 NULL); 1761 NULL);
1899 } 1762 }
1900 } 1763 }
1901 else 1764 else
@@ -1903,17 +1766,17 @@ maint_child_death (void *cls)
1903 free_service (pos); 1766 free_service (pos);
1904 } 1767 }
1905 } 1768 }
1906 child_death_task = GNUNET_SCHEDULER_add_read_file ( 1769 child_death_task =
1907 GNUNET_TIME_UNIT_FOREVER_REL, 1770 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
1908 pr, 1771 pr,
1909 &maint_child_death, NULL); 1772 &maint_child_death,
1773 NULL);
1910 if ((NULL == running_head) && (GNUNET_YES == in_shutdown)) 1774 if ((NULL == running_head) && (GNUNET_YES == in_shutdown))
1911 do_shutdown (); 1775 do_shutdown ();
1912 else if (GNUNET_YES == in_shutdown) 1776 else if (GNUNET_YES == in_shutdown)
1913 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1777 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1914 "Delaying shutdown after child's death, still have %u children\n", 1778 "Delaying shutdown after child's death, still have %u children\n",
1915 list_count (running_head)); 1779 list_count (running_head));
1916
1917} 1780}
1918 1781
1919 1782
@@ -1925,14 +1788,15 @@ static void
1925sighandler_child_death () 1788sighandler_child_death ()
1926{ 1789{
1927 static char c; 1790 static char c;
1928 int old_errno = errno; /* back-up errno */ 1791 int old_errno = errno; /* back-up errno */
1929 1792
1930 GNUNET_break (1 == 1793 GNUNET_break (
1931 GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle (sigpipe, 1794 1 ==
1932 GNUNET_DISK_PIPE_END_WRITE), 1795 GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle (sigpipe,
1933 &c, 1796 GNUNET_DISK_PIPE_END_WRITE),
1934 sizeof (c))); 1797 &c,
1935 errno = old_errno; /* restore errno */ 1798 sizeof (c)));
1799 errno = old_errno; /* restore errno */
1936} 1800}
1937 1801
1938 1802
@@ -1945,8 +1809,7 @@ sighandler_child_death ()
1945 * @return #GNUNET_OK (continue) 1809 * @return #GNUNET_OK (continue)
1946 */ 1810 */
1947static void 1811static void
1948setup_service (void *cls, 1812setup_service (void *cls, const char *section)
1949 const char *section)
1950{ 1813{
1951 struct ServiceList *sl; 1814 struct ServiceList *sl;
1952 char *binary; 1815 char *binary;
@@ -1957,26 +1820,18 @@ setup_service (void *cls,
1957 int ret; 1820 int ret;
1958 1821
1959 (void) cls; 1822 (void) cls;
1960 if (0 == strcasecmp (section, 1823 if (0 == strcasecmp (section, "arm"))
1961 "arm"))
1962 return; 1824 return;
1963 if (GNUNET_OK != 1825 if (GNUNET_OK !=
1964 GNUNET_CONFIGURATION_get_value_string (cfg, 1826 GNUNET_CONFIGURATION_get_value_string (cfg, section, "BINARY", &binary))
1965 section,
1966 "BINARY",
1967 &binary))
1968 { 1827 {
1969 /* not a service section */ 1828 /* not a service section */
1970 return; 1829 return;
1971 } 1830 }
1972 if ((GNUNET_YES == 1831 if ((GNUNET_YES ==
1973 GNUNET_CONFIGURATION_have_value (cfg, 1832 GNUNET_CONFIGURATION_have_value (cfg, section, "RUN_PER_USER")) &&
1974 section,
1975 "RUN_PER_USER")) &&
1976 (GNUNET_YES == 1833 (GNUNET_YES ==
1977 GNUNET_CONFIGURATION_get_value_yesno (cfg, 1834 GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "RUN_PER_USER")))
1978 section,
1979 "RUN_PER_USER")))
1980 { 1835 {
1981 if (GNUNET_NO == start_user) 1836 if (GNUNET_NO == start_user)
1982 { 1837 {
@@ -2001,23 +1856,22 @@ setup_service (void *cls,
2001 return; 1856 return;
2002 } 1857 }
2003 config = NULL; 1858 config = NULL;
2004 if (( (GNUNET_OK != 1859 if (((GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
2005 GNUNET_CONFIGURATION_get_value_filename (cfg, 1860 section,
2006 section, 1861 "CONFIG",
2007 "CONFIG", 1862 &config)) &&
2008 &config)) && 1863 (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
2009 (GNUNET_OK != 1864 "PATHS",
2010 GNUNET_CONFIGURATION_get_value_filename (cfg, 1865 "DEFAULTCONFIG",
2011 "PATHS", 1866 &config))) ||
2012 "DEFAULTCONFIG", 1867 (0 != stat (config, &sbuf)))
2013 &config)) ) ||
2014 (0 != STAT (config, &sbuf)))
2015 { 1868 {
2016 if (NULL != config) 1869 if (NULL != config)
2017 { 1870 {
2018 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING, 1871 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING,
2019 section, "CONFIG", 1872 section,
2020 STRERROR (errno)); 1873 "CONFIG",
1874 strerror (errno));
2021 GNUNET_free (config); 1875 GNUNET_free (config);
2022 config = NULL; 1876 config = NULL;
2023 } 1877 }
@@ -2031,46 +1885,30 @@ setup_service (void *cls,
2031#if WINDOWS 1885#if WINDOWS
2032 sl->pipe_control = GNUNET_YES; 1886 sl->pipe_control = GNUNET_YES;
2033#else 1887#else
2034 if (GNUNET_CONFIGURATION_have_value (cfg, 1888 if (GNUNET_CONFIGURATION_have_value (cfg, section, "PIPECONTROL"))
2035 section, 1889 sl->pipe_control =
2036 "PIPECONTROL")) 1890 GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "PIPECONTROL");
2037 sl->pipe_control = GNUNET_CONFIGURATION_get_value_yesno (cfg,
2038 section,
2039 "PIPECONTROL");
2040#endif 1891#endif
2041 GNUNET_CONTAINER_DLL_insert (running_head, 1892 GNUNET_CONTAINER_DLL_insert (running_head, running_tail, sl);
2042 running_tail,
2043 sl);
2044 if (GNUNET_YES == 1893 if (GNUNET_YES ==
2045 GNUNET_CONFIGURATION_get_value_yesno (cfg, 1894 GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "IMMEDIATE_START"))
2046 section,
2047 "IMMEDIATE_START"))
2048 { 1895 {
2049 sl->force_start = GNUNET_YES; 1896 sl->force_start = GNUNET_YES;
2050 if (GNUNET_YES == 1897 if (GNUNET_YES ==
2051 GNUNET_CONFIGURATION_get_value_yesno (cfg, 1898 GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "NOARMBIND"))
2052 section,
2053 "NOARMBIND"))
2054 return; 1899 return;
2055 } 1900 }
2056 else 1901 else
2057 { 1902 {
2058 if (GNUNET_YES != 1903 if (GNUNET_YES !=
2059 GNUNET_CONFIGURATION_get_value_yesno (cfg, 1904 GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "START_ON_DEMAND"))
2060 section,
2061 "START_ON_DEMAND"))
2062 return; 1905 return;
2063 } 1906 }
2064 if (0 >= (ret = get_server_addresses (section, 1907 if (0 >= (ret = get_server_addresses (section, cfg, &addrs, &addr_lens)))
2065 cfg,
2066 &addrs,
2067 &addr_lens)))
2068 return; 1908 return;
2069 /* this will free (or capture) addrs[i] */ 1909 /* this will free (or capture) addrs[i] */
2070 for (unsigned int i = 0; i < (unsigned int) ret; i++) 1910 for (unsigned int i = 0; i < (unsigned int) ret; i++)
2071 create_listen_socket (addrs[i], 1911 create_listen_socket (addrs[i], addr_lens[i], sl);
2072 addr_lens[i],
2073 sl);
2074 GNUNET_free (addrs); 1912 GNUNET_free (addrs);
2075 GNUNET_free (addr_lens); 1913 GNUNET_free (addr_lens);
2076} 1914}
@@ -2128,8 +1966,7 @@ client_disconnect_cb (void *cls,
2128 * #GNUNET_SYSERR to close it (signal serious error) 1966 * #GNUNET_SYSERR to close it (signal serious error)
2129 */ 1967 */
2130static void 1968static void
2131handle_monitor (void *cls, 1969handle_monitor (void *cls, const struct GNUNET_MessageHeader *message)
2132 const struct GNUNET_MessageHeader *message)
2133{ 1970{
2134 struct GNUNET_SERVICE_Client *client = cls; 1971 struct GNUNET_SERVICE_Client *client = cls;
2135 1972
@@ -2139,9 +1976,7 @@ handle_monitor (void *cls,
2139 /* Removal is handled by the server implementation, internally. */ 1976 /* Removal is handled by the server implementation, internally. */
2140 GNUNET_notification_context_add (notifier, 1977 GNUNET_notification_context_add (notifier,
2141 GNUNET_SERVICE_client_get_mq (client)); 1978 GNUNET_SERVICE_client_get_mq (client));
2142 broadcast_status ("arm", 1979 broadcast_status ("arm", GNUNET_ARM_SERVICE_MONITORING_STARTED, client);
2143 GNUNET_ARM_SERVICE_MONITORING_STARTED,
2144 client);
2145 GNUNET_SERVICE_client_continue (client); 1980 GNUNET_SERVICE_client_continue (client);
2146} 1981}
2147 1982
@@ -2163,14 +1998,12 @@ run (void *cls,
2163 (void) cls; 1998 (void) cls;
2164 cfg = c; 1999 cfg = c;
2165 service = serv; 2000 service = serv;
2166 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 2001 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
2167 NULL); 2002 child_death_task = GNUNET_SCHEDULER_add_read_file (
2168 child_death_task = 2003 GNUNET_TIME_UNIT_FOREVER_REL,
2169 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 2004 GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ),
2170 GNUNET_DISK_pipe_handle (sigpipe, 2005 &maint_child_death,
2171 GNUNET_DISK_PIPE_END_READ), 2006 NULL);
2172 &maint_child_death,
2173 NULL);
2174#if HAVE_WAIT4 2007#if HAVE_WAIT4
2175 if (GNUNET_OK == 2008 if (GNUNET_OK ==
2176 GNUNET_CONFIGURATION_get_value_filename (cfg, 2009 GNUNET_CONFIGURATION_get_value_filename (cfg,
@@ -2178,8 +2011,7 @@ run (void *cls,
2178 "RESOURCE_DIAGNOSTICS", 2011 "RESOURCE_DIAGNOSTICS",
2179 &wait_filename)) 2012 &wait_filename))
2180 { 2013 {
2181 wait_file = fopen (wait_filename, 2014 wait_file = fopen (wait_filename, "w");
2182 "w");
2183 if (NULL == wait_file) 2015 if (NULL == wait_file)
2184 { 2016 {
2185 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 2017 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
@@ -2188,49 +2020,39 @@ run (void *cls,
2188 } 2020 }
2189 } 2021 }
2190#endif 2022#endif
2191 if (GNUNET_OK != 2023 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
2192 GNUNET_CONFIGURATION_get_value_string (cfg, 2024 "ARM",
2193 "ARM", 2025 "GLOBAL_PREFIX",
2194 "GLOBAL_PREFIX", 2026 &prefix_command))
2195 &prefix_command))
2196 prefix_command = GNUNET_strdup (""); 2027 prefix_command = GNUNET_strdup ("");
2197 else 2028 else
2198 prefix_command = GNUNET_CONFIGURATION_expand_dollar (cfg, 2029 prefix_command = GNUNET_CONFIGURATION_expand_dollar (cfg, prefix_command);
2199 prefix_command); 2030 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
2200 if (GNUNET_OK != 2031 "ARM",
2201 GNUNET_CONFIGURATION_get_value_string (cfg, 2032 "GLOBAL_POSTFIX",
2202 "ARM", 2033 &final_option))
2203 "GLOBAL_POSTFIX",
2204 &final_option))
2205 final_option = GNUNET_strdup (""); 2034 final_option = GNUNET_strdup ("");
2206 else 2035 else
2207 final_option = GNUNET_CONFIGURATION_expand_dollar (cfg, 2036 final_option = GNUNET_CONFIGURATION_expand_dollar (cfg, final_option);
2208 final_option); 2037 start_user =
2209 start_user = GNUNET_CONFIGURATION_get_value_yesno (cfg, 2038 GNUNET_CONFIGURATION_get_value_yesno (cfg, "ARM", "START_USER_SERVICES");
2210 "ARM", 2039 start_system =
2211 "START_USER_SERVICES"); 2040 GNUNET_CONFIGURATION_get_value_yesno (cfg, "ARM", "START_SYSTEM_SERVICES");
2212 start_system = GNUNET_CONFIGURATION_get_value_yesno (cfg, 2041 if ((GNUNET_NO == start_user) && (GNUNET_NO == start_system))
2213 "ARM",
2214 "START_SYSTEM_SERVICES");
2215 if ( (GNUNET_NO == start_user) &&
2216 (GNUNET_NO == start_system) )
2217 { 2042 {
2218 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2043 GNUNET_log (
2219 "Please configure either START_USER_SERVICES or START_SYSTEM_SERVICES or both.\n"); 2044 GNUNET_ERROR_TYPE_ERROR,
2045 "Please configure either START_USER_SERVICES or START_SYSTEM_SERVICES or both.\n");
2220 GNUNET_SCHEDULER_shutdown (); 2046 GNUNET_SCHEDULER_shutdown ();
2221 global_ret = 1; 2047 global_ret = 1;
2222 return; 2048 return;
2223 } 2049 }
2224 GNUNET_CONFIGURATION_iterate_sections (cfg, 2050 GNUNET_CONFIGURATION_iterate_sections (cfg, &setup_service, NULL);
2225 &setup_service,
2226 NULL);
2227 2051
2228 /* start default services... */ 2052 /* start default services... */
2229 for (sl = running_head; NULL != sl; sl = sl->next) 2053 for (sl = running_head; NULL != sl; sl = sl->next)
2230 if (GNUNET_YES == sl->force_start) 2054 if (GNUNET_YES == sl->force_start)
2231 start_process (sl, 2055 start_process (sl, NULL, 0);
2232 NULL,
2233 0);
2234 notifier = GNUNET_notification_context_create (MAX_NOTIFY_QUEUE); 2056 notifier = GNUNET_notification_context_create (MAX_NOTIFY_QUEUE);
2235} 2057}
2236 2058
@@ -2243,52 +2065,45 @@ run (void *cls,
2243 * @return 0 ok, 1 on error 2065 * @return 0 ok, 1 on error
2244 */ 2066 */
2245int 2067int
2246main (int argc, 2068main (int argc, char *const *argv)
2247 char *const *argv)
2248{ 2069{
2249 struct GNUNET_SIGNAL_Context *shc_chld; 2070 struct GNUNET_SIGNAL_Context *shc_chld;
2250 struct GNUNET_MQ_MessageHandler handlers[] = { 2071 struct GNUNET_MQ_MessageHandler handlers[] =
2251 GNUNET_MQ_hd_var_size (start, 2072 {GNUNET_MQ_hd_var_size (start,
2252 GNUNET_MESSAGE_TYPE_ARM_START, 2073 GNUNET_MESSAGE_TYPE_ARM_START,
2253 struct GNUNET_ARM_Message, 2074 struct GNUNET_ARM_Message,
2254 NULL), 2075 NULL),
2255 GNUNET_MQ_hd_var_size (stop, 2076 GNUNET_MQ_hd_var_size (stop,
2256 GNUNET_MESSAGE_TYPE_ARM_STOP, 2077 GNUNET_MESSAGE_TYPE_ARM_STOP,
2257 struct GNUNET_ARM_Message, 2078 struct GNUNET_ARM_Message,
2258 NULL), 2079 NULL),
2259 GNUNET_MQ_hd_fixed_size (monitor, 2080 GNUNET_MQ_hd_fixed_size (monitor,
2260 GNUNET_MESSAGE_TYPE_ARM_MONITOR, 2081 GNUNET_MESSAGE_TYPE_ARM_MONITOR,
2261 struct GNUNET_MessageHeader, 2082 struct GNUNET_MessageHeader,
2262 NULL), 2083 NULL),
2263 GNUNET_MQ_hd_fixed_size (list, 2084 GNUNET_MQ_hd_fixed_size (list,
2264 GNUNET_MESSAGE_TYPE_ARM_LIST, 2085 GNUNET_MESSAGE_TYPE_ARM_LIST,
2265 struct GNUNET_ARM_Message, 2086 struct GNUNET_ARM_Message,
2266 NULL), 2087 NULL),
2267 GNUNET_MQ_hd_fixed_size (test, 2088 GNUNET_MQ_hd_fixed_size (test,
2268 GNUNET_MESSAGE_TYPE_ARM_TEST, 2089 GNUNET_MESSAGE_TYPE_ARM_TEST,
2269 struct GNUNET_MessageHeader, 2090 struct GNUNET_MessageHeader,
2270 NULL), 2091 NULL),
2271 GNUNET_MQ_handler_end () 2092 GNUNET_MQ_handler_end ()};
2272 }; 2093
2273 2094 sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO);
2274 sigpipe = GNUNET_DISK_pipe (GNUNET_NO,
2275 GNUNET_NO,
2276 GNUNET_NO,
2277 GNUNET_NO);
2278 GNUNET_assert (NULL != sigpipe); 2095 GNUNET_assert (NULL != sigpipe);
2279 shc_chld = 2096 shc_chld =
2280 GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, 2097 GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death);
2281 &sighandler_child_death); 2098 if (0 != GNUNET_SERVICE_run_ (argc,
2282 if (0 != 2099 argv,
2283 GNUNET_SERVICE_run_ (argc, 2100 "arm",
2284 argv, 2101 GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN,
2285 "arm", 2102 &run,
2286 GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN, 2103 &client_connect_cb,
2287 &run, 2104 &client_disconnect_cb,
2288 &client_connect_cb, 2105 NULL,
2289 &client_disconnect_cb, 2106 handlers))
2290 NULL,
2291 handlers))
2292 global_ret = 2; 2107 global_ret = 2;
2293#if HAVE_WAIT4 2108#if HAVE_WAIT4
2294 if (NULL != wait_file) 2109 if (NULL != wait_file)
diff --git a/src/arm/test_exponential_backoff.c b/src/arm/test_exponential_backoff.c
index e3c2a399a..43984f9bf 100644
--- a/src/arm/test_exponential_backoff.c
+++ b/src/arm/test_exponential_backoff.c
@@ -370,7 +370,7 @@ init ()
370 370
371#if LOG_BACKOFF 371#if LOG_BACKOFF
372 killLogFileName = GNUNET_DISK_mktemp ("exponential-backoff-waiting.log"); 372 killLogFileName = GNUNET_DISK_mktemp ("exponential-backoff-waiting.log");
373 if (NULL == (killLogFilePtr = FOPEN (killLogFileName, 373 if (NULL == (killLogFilePtr = fopen (killLogFileName,
374 "w"))) 374 "w")))
375 { 375 {
376 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 376 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
diff --git a/src/arm/test_gnunet_service_arm.c b/src/arm/test_gnunet_service_arm.c
index 55903c499..9508581de 100644
--- a/src/arm/test_gnunet_service_arm.c
+++ b/src/arm/test_gnunet_service_arm.c
@@ -205,7 +205,7 @@ main (int argc, char *av[])
205 205
206 if (0 != (ret = getaddrinfo (hostname, NULL, NULL, &ai))) 206 if (0 != (ret = getaddrinfo (hostname, NULL, NULL, &ai)))
207 { 207 {
208 FPRINTF (stderr, 208 fprintf (stderr,
209 "Failed to resolve `%s', testcase not run.\n", 209 "Failed to resolve `%s', testcase not run.\n",
210 hostname); 210 hostname);
211 return 77; 211 return 77;
@@ -221,7 +221,7 @@ main (int argc, char *av[])
221 host = gethostbyname2 (hostname, AF_INET6); 221 host = gethostbyname2 (hostname, AF_INET6);
222 if (NULL == host) 222 if (NULL == host)
223 { 223 {
224 FPRINTF (stderr, 224 fprintf (stderr,
225 "Failed to resolve `%s', testcase not run.\n", 225 "Failed to resolve `%s', testcase not run.\n",
226 hostname); 226 hostname);
227 return 77; 227 return 77;
@@ -234,14 +234,14 @@ main (int argc, char *av[])
234 host = gethostbyname (hostname); 234 host = gethostbyname (hostname);
235 if (NULL == host) 235 if (NULL == host)
236 { 236 {
237 FPRINTF (stderr, 237 fprintf (stderr,
238 "Failed to resolve `%s', testcase not run.\n", 238 "Failed to resolve `%s', testcase not run.\n",
239 hostname); 239 hostname);
240 return 77; 240 return 77;
241 } 241 }
242 } 242 }
243#else 243#else
244 FPRINTF (stderr, 244 fprintf (stderr,
245 "libc fails to have resolver function, testcase not run.\n"); 245 "libc fails to have resolver function, testcase not run.\n");
246 return 77; 246 return 77;
247#endif 247#endif
diff --git a/src/ats-tool/gnunet-ats.c b/src/ats-tool/gnunet-ats.c
index 88c3c41e9..519f77af8 100644
--- a/src/ats-tool/gnunet-ats.c
+++ b/src/ats-tool/gnunet-ats.c
@@ -221,7 +221,6 @@ struct ATSAddress
221 * Is this an active address? 221 * Is this an active address?
222 */ 222 */
223 int active; 223 int active;
224
225}; 224};
226 225
227 226
@@ -245,16 +244,12 @@ static struct PendingResolutions *tail;
245 * @return #GNUNET_YES (always) 244 * @return #GNUNET_YES (always)
246 */ 245 */
247static int 246static int
248free_addr_it (void *cls, 247free_addr_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
249 const struct GNUNET_PeerIdentity *key,
250 void *value)
251{ 248{
252 struct ATSAddress *a = value; 249 struct ATSAddress *a = value;
253 250
254 GNUNET_assert (GNUNET_OK == 251 GNUNET_assert (GNUNET_OK ==
255 GNUNET_CONTAINER_multipeermap_remove (addresses, 252 GNUNET_CONTAINER_multipeermap_remove (addresses, key, value));
256 key,
257 value));
258 GNUNET_HELLO_address_free (a->address); 253 GNUNET_HELLO_address_free (a->address);
259 GNUNET_free (a); 254 GNUNET_free (a);
260 return GNUNET_OK; 255 return GNUNET_OK;
@@ -269,8 +264,8 @@ free_addr_it (void *cls,
269static void 264static void
270end (void *cls) 265end (void *cls)
271{ 266{
272 struct PendingResolutions * pr; 267 struct PendingResolutions *pr;
273 struct PendingResolutions * next; 268 struct PendingResolutions *next;
274 unsigned int pending; 269 unsigned int pending;
275 270
276 if (NULL != alh) 271 if (NULL != alh)
@@ -290,25 +285,21 @@ end (void *cls)
290 while (NULL != (pr = next)) 285 while (NULL != (pr = next))
291 { 286 {
292 next = pr->next; 287 next = pr->next;
293 GNUNET_CONTAINER_DLL_remove(head, tail, pr); 288 GNUNET_CONTAINER_DLL_remove (head, tail, pr);
294 GNUNET_TRANSPORT_address_to_string_cancel (pr->tats_ctx); 289 GNUNET_TRANSPORT_address_to_string_cancel (pr->tats_ctx);
295 GNUNET_free(pr->address); 290 GNUNET_free (pr->address);
296 GNUNET_free(pr); 291 GNUNET_free (pr);
297 pending++; 292 pending++;
298 } 293 }
299 GNUNET_CONTAINER_multipeermap_iterate (addresses, 294 GNUNET_CONTAINER_multipeermap_iterate (addresses, &free_addr_it, NULL);
300 &free_addr_it,
301 NULL);
302 GNUNET_CONTAINER_multipeermap_destroy (addresses); 295 GNUNET_CONTAINER_multipeermap_destroy (addresses);
303 addresses = NULL; 296 addresses = NULL;
304 297
305 if (0 < pending) 298 if (0 < pending)
306 FPRINTF (stdout, 299 fprintf (stdout, _ ("%u address resolutions had a timeout\n"), pending);
307 _("%u address resolutions had a timeout\n"),
308 pending);
309 if (opt_list_used || opt_list_all) 300 if (opt_list_used || opt_list_all)
310 FPRINTF (stdout, 301 fprintf (stdout,
311 _("ATS returned stat_results for %u addresses\n"), 302 _ ("ATS returned stat_results for %u addresses\n"),
312 stat_results); 303 stat_results);
313 304
314 if (NULL != ats_sh) 305 if (NULL != ats_sh)
@@ -342,18 +333,14 @@ end (void *cls)
342 * if #GNUNET_SYSERR: communication error (IPC error) 333 * if #GNUNET_SYSERR: communication error (IPC error)
343 */ 334 */
344static void 335static void
345transport_addr_to_str_cb (void *cls, 336transport_addr_to_str_cb (void *cls, const char *address, int res)
346 const char *address,
347 int res)
348{ 337{
349 struct PendingResolutions *pr = cls; 338 struct PendingResolutions *pr = cls;
350 339
351 if (NULL == address) 340 if (NULL == address)
352 { 341 {
353 /* We're done */ 342 /* We're done */
354 GNUNET_CONTAINER_DLL_remove (head, 343 GNUNET_CONTAINER_DLL_remove (head, tail, pr);
355 tail,
356 pr);
357 GNUNET_free (pr->address); 344 GNUNET_free (pr->address);
358 GNUNET_free (pr); 345 GNUNET_free (pr);
359 stat_pending--; 346 stat_pending--;
@@ -370,18 +357,20 @@ transport_addr_to_str_cb (void *cls,
370 switch (res) 357 switch (res)
371 { 358 {
372 case GNUNET_SYSERR: 359 case GNUNET_SYSERR:
373 FPRINTF (stderr, 360 fprintf (
374 "Failed to convert address for peer `%s' plugin `%s' length %u to string (communication error)\n", 361 stderr,
375 GNUNET_i2s (&pr->address->peer), 362 "Failed to convert address for peer `%s' plugin `%s' length %u to string (communication error)\n",
376 pr->address->transport_name, 363 GNUNET_i2s (&pr->address->peer),
377 (unsigned int) pr->address->address_length); 364 pr->address->transport_name,
365 (unsigned int) pr->address->address_length);
378 return; 366 return;
379 case GNUNET_NO: 367 case GNUNET_NO:
380 FPRINTF (stderr, 368 fprintf (
381 "Failed to convert address for peer `%s' plugin `%s' length %u to string (address invalid or not supported)\n", 369 stderr,
382 GNUNET_i2s (&pr->address->peer), 370 "Failed to convert address for peer `%s' plugin `%s' length %u to string (address invalid or not supported)\n",
383 pr->address->transport_name, 371 GNUNET_i2s (&pr->address->peer),
384 (unsigned int) pr->address->address_length); 372 pr->address->transport_name,
373 (unsigned int) pr->address->address_length);
385 return; 374 return;
386 case GNUNET_OK: 375 case GNUNET_OK:
387 /* continues below */ 376 /* continues below */
@@ -391,15 +380,17 @@ transport_addr_to_str_cb (void *cls,
391 return; 380 return;
392 } 381 }
393 382
394 FPRINTF (stdout, 383 fprintf (
395 _("Peer `%s' plugin `%s', address `%s', `%s' bw out: %u Bytes/s, bw in %u Bytes/s, %s\n"), 384 stdout,
396 GNUNET_i2s (&pr->address->peer), 385 _ (
397 pr->address->transport_name, 386 "Peer `%s' plugin `%s', address `%s', `%s' bw out: %u Bytes/s, bw in %u Bytes/s, %s\n"),
398 address, 387 GNUNET_i2s (&pr->address->peer),
399 GNUNET_NT_to_string (pr->properties.scope), 388 pr->address->transport_name,
400 ntohl (pr->bandwidth_out.value__), 389 address,
401 ntohl (pr->bandwidth_in.value__), 390 GNUNET_NT_to_string (pr->properties.scope),
402 pr->active ? _("active ") : _("inactive ")); 391 ntohl (pr->bandwidth_out.value__),
392 ntohl (pr->bandwidth_in.value__),
393 pr->active ? _ ("active ") : _ ("inactive "));
403} 394}
404 395
405 396
@@ -429,9 +420,7 @@ struct AddressFindCtx
429 * @return #GNUNET_NO if we found a match, #GNUNET_YES if not 420 * @return #GNUNET_NO if we found a match, #GNUNET_YES if not
430 */ 421 */
431static int 422static int
432find_address_it (void *cls, 423find_address_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
433 const struct GNUNET_PeerIdentity *key,
434 void *value)
435{ 424{
436 struct AddressFindCtx *actx = cls; 425 struct AddressFindCtx *actx = cls;
437 struct ATSAddress *exist = value; 426 struct ATSAddress *exist = value;
@@ -445,7 +434,6 @@ find_address_it (void *cls,
445} 434}
446 435
447 436
448
449/** 437/**
450 * Signature of a function that is called with QoS information about an address. 438 * Signature of a function that is called with QoS information about an address.
451 * 439 *
@@ -483,9 +471,7 @@ ats_perf_mon_cb (void *cls,
483 GNUNET_HELLO_address_free (cur->address); 471 GNUNET_HELLO_address_free (cur->address);
484 GNUNET_free (cur); 472 GNUNET_free (cur);
485 } 473 }
486 GNUNET_CONTAINER_multipeermap_iterate (addresses, 474 GNUNET_CONTAINER_multipeermap_iterate (addresses, &free_addr_it, NULL);
487 &free_addr_it,
488 NULL);
489 return; 475 return;
490 } 476 }
491 if (GNUNET_SYSERR == active) 477 if (GNUNET_SYSERR == active)
@@ -504,12 +490,12 @@ ats_perf_mon_cb (void *cls,
504 GNUNET_break (0); 490 GNUNET_break (0);
505 return; 491 return;
506 } 492 }
507 GNUNET_break(GNUNET_OK == 493 GNUNET_break (GNUNET_OK ==
508 GNUNET_CONTAINER_multipeermap_remove (addresses, 494 GNUNET_CONTAINER_multipeermap_remove (addresses,
509 &address->peer, 495 &address->peer,
510 actx.res)); 496 actx.res));
511 FPRINTF (stdout, 497 fprintf (stdout,
512 _("Removed address of peer `%s' with plugin `%s'\n"), 498 _ ("Removed address of peer `%s' with plugin `%s'\n"),
513 GNUNET_i2s (&address->peer), 499 GNUNET_i2s (&address->peer),
514 actx.res->address->transport_name); 500 actx.res->address->transport_name);
515 GNUNET_HELLO_address_free (actx.res); 501 GNUNET_HELLO_address_free (actx.res);
@@ -545,14 +531,15 @@ ats_perf_mon_cb (void *cls,
545 { 531 {
546 a = GNUNET_new (struct ATSAddress); 532 a = GNUNET_new (struct ATSAddress);
547 533
548 a->address = GNUNET_HELLO_address_copy(address); 534 a->address = GNUNET_HELLO_address_copy (address);
549 a->bandwidth_in = bandwidth_in; 535 a->bandwidth_in = bandwidth_in;
550 a->bandwidth_out = bandwidth_out; 536 a->bandwidth_out = bandwidth_out;
551 a->active = active; 537 a->active = active;
552 GNUNET_CONTAINER_multipeermap_put (addresses, 538 GNUNET_CONTAINER_multipeermap_put (
553 &address->peer, 539 addresses,
554 a, 540 &address->peer,
555 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 541 a,
542 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
556 } 543 }
557 } 544 }
558 545
@@ -562,11 +549,13 @@ ats_perf_mon_cb (void *cls,
562 pr->bandwidth_in = bandwidth_in; 549 pr->bandwidth_in = bandwidth_in;
563 pr->bandwidth_out = bandwidth_out; 550 pr->bandwidth_out = bandwidth_out;
564 pr->active = active; 551 pr->active = active;
565 pr->tats_ctx = GNUNET_TRANSPORT_address_to_string (cfg, address, 552 pr->tats_ctx = GNUNET_TRANSPORT_address_to_string (
566 opt_resolve_addresses_numeric, 553 cfg,
567 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), 554 address,
568 &transport_addr_to_str_cb, 555 opt_resolve_addresses_numeric,
569 pr); 556 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
557 &transport_addr_to_str_cb,
558 pr);
570 GNUNET_CONTAINER_DLL_insert (head, tail, pr); 559 GNUNET_CONTAINER_DLL_insert (head, tail, pr);
571 stat_results++; 560 stat_results++;
572 stat_pending++; 561 stat_pending++;
@@ -615,10 +604,13 @@ ats_perf_cb (void *cls,
615 pr->bandwidth_in = bandwidth_in; 604 pr->bandwidth_in = bandwidth_in;
616 pr->bandwidth_out = bandwidth_out; 605 pr->bandwidth_out = bandwidth_out;
617 pr->active = active; 606 pr->active = active;
618 pr->tats_ctx = GNUNET_TRANSPORT_address_to_string (cfg, address, 607 pr->tats_ctx = GNUNET_TRANSPORT_address_to_string (
619 opt_resolve_addresses_numeric, 608 cfg,
620 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), 609 address,
621 &transport_addr_to_str_cb, pr); 610 opt_resolve_addresses_numeric,
611 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
612 &transport_addr_to_str_cb,
613 pr);
622 GNUNET_CONTAINER_DLL_insert (head, tail, pr); 614 GNUNET_CONTAINER_DLL_insert (head, tail, pr);
623 stat_results++; 615 stat_results++;
624 stat_pending++; 616 stat_pending++;
@@ -635,10 +627,10 @@ ats_perf_cb (void *cls,
635static unsigned int 627static unsigned int
636print_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg) 628print_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg)
637{ 629{
638 char * entry_in = NULL; 630 char *entry_in = NULL;
639 char * entry_out = NULL; 631 char *entry_out = NULL;
640 char * quota_out_str; 632 char *quota_out_str;
641 char * quota_in_str; 633 char *quota_in_str;
642 unsigned long long int quota_out; 634 unsigned long long int quota_out;
643 unsigned long long int quota_in; 635 unsigned long long int quota_in;
644 int c; 636 int c;
@@ -646,32 +638,26 @@ print_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg)
646 for (c = 0; (c < GNUNET_NT_COUNT); c++) 638 for (c = 0; (c < GNUNET_NT_COUNT); c++)
647 { 639 {
648 640
649 GNUNET_asprintf (&entry_out, 641 GNUNET_asprintf (&entry_out, "%s_QUOTA_OUT", GNUNET_NT_to_string (c));
650 "%s_QUOTA_OUT", 642 GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", GNUNET_NT_to_string (c));
651 GNUNET_NT_to_string (c));
652 GNUNET_asprintf (&entry_in,
653 "%s_QUOTA_IN",
654 GNUNET_NT_to_string (c));
655 643
656 /* quota out */ 644 /* quota out */
657 if (GNUNET_OK == 645 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg,
658 GNUNET_CONFIGURATION_get_value_string (cfg, 646 "ats",
659 "ats", 647 entry_out,
660 entry_out, 648 &quota_out_str))
661 &quota_out_str))
662 { 649 {
663 if (0 == strcmp (quota_out_str, UNLIMITED_STRING) 650 if (0 == strcmp (quota_out_str, UNLIMITED_STRING) ||
664 || (GNUNET_SYSERR == 651 (GNUNET_SYSERR ==
665 GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, 652 GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &quota_out)))
666 &quota_out)))
667 quota_out = UINT32_MAX; 653 quota_out = UINT32_MAX;
668 654
669 GNUNET_free(quota_out_str); 655 GNUNET_free (quota_out_str);
670 GNUNET_asprintf (&quota_out_str, "%llu", quota_out); 656 GNUNET_asprintf (&quota_out_str, "%llu", quota_out);
671 } 657 }
672 else 658 else
673 { 659 {
674 FPRINTF (stderr, 660 fprintf (stderr,
675 "Outbound quota for network `%11s' not configured!\n", 661 "Outbound quota for network `%11s' not configured!\n",
676 GNUNET_NT_to_string (c)); 662 GNUNET_NT_to_string (c));
677 GNUNET_asprintf (&quota_out_str, "-"); 663 GNUNET_asprintf (&quota_out_str, "-");
@@ -679,35 +665,34 @@ print_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg)
679 GNUNET_free (entry_out); 665 GNUNET_free (entry_out);
680 666
681 /* quota in */ 667 /* quota in */
682 if (GNUNET_OK == 668 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg,
683 GNUNET_CONFIGURATION_get_value_string (cfg, 669 "ats",
684 "ats", 670 entry_in,
685 entry_in, 671 &quota_in_str))
686 &quota_in_str))
687 { 672 {
688 if (0 == strcmp (quota_in_str, UNLIMITED_STRING) 673 if (0 == strcmp (quota_in_str, UNLIMITED_STRING) ||
689 || (GNUNET_SYSERR == 674 (GNUNET_SYSERR ==
690 GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &quota_in))) 675 GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &quota_in)))
691 quota_in = UINT32_MAX; 676 quota_in = UINT32_MAX;
692 GNUNET_free (quota_in_str); 677 GNUNET_free (quota_in_str);
693 GNUNET_asprintf (&quota_in_str, "%llu", quota_in); 678 GNUNET_asprintf (&quota_in_str, "%llu", quota_in);
694 } 679 }
695 else 680 else
696 { 681 {
697 FPRINTF (stderr, 682 fprintf (stderr,
698 "Inbound quota for network `%11s' not configured!\n", 683 "Inbound quota for network `%11s' not configured!\n",
699 GNUNET_NT_to_string (c)); 684 GNUNET_NT_to_string (c));
700 GNUNET_asprintf (&quota_in_str, "-"); 685 GNUNET_asprintf (&quota_in_str, "-");
701 } 686 }
702 GNUNET_free(entry_in); 687 GNUNET_free (entry_in);
703 688
704 FPRINTF (stdout, 689 fprintf (stdout,
705 _("Quota for network `%11s' (in/out): %10s / %10s\n"), 690 _ ("Quota for network `%11s' (in/out): %10s / %10s\n"),
706 GNUNET_NT_to_string (c), 691 GNUNET_NT_to_string (c),
707 quota_in_str, 692 quota_in_str,
708 quota_out_str); 693 quota_out_str);
709 GNUNET_free(quota_out_str); 694 GNUNET_free (quota_out_str);
710 GNUNET_free(quota_in_str); 695 GNUNET_free (quota_in_str);
711 } 696 }
712 return GNUNET_NT_COUNT; 697 return GNUNET_NT_COUNT;
713} 698}
@@ -723,7 +708,7 @@ print_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg)
723 */ 708 */
724static void 709static void
725run (void *cls, 710run (void *cls,
726 char * const *args, 711 char *const *args,
727 const char *cfgfile, 712 const char *cfgfile,
728 const struct GNUNET_CONFIGURATION_Handle *my_cfg) 713 const struct GNUNET_CONFIGURATION_Handle *my_cfg)
729{ 714{
@@ -744,9 +729,7 @@ run (void *cls,
744 strlen (opt_pid_str), 729 strlen (opt_pid_str),
745 &pid.public_key)) 730 &pid.public_key))
746 { 731 {
747 FPRINTF (stderr, 732 fprintf (stderr, _ ("Failed to parse peer identity `%s'\n"), opt_pid_str);
748 _("Failed to parse peer identity `%s'\n"),
749 opt_pid_str);
750 return; 733 return;
751 } 734 }
752 } 735 }
@@ -757,9 +740,7 @@ run (void *cls,
757 strlen (cpid_str), 740 strlen (cpid_str),
758 &cpid.public_key)) 741 &cpid.public_key))
759 { 742 {
760 FPRINTF (stderr, 743 fprintf (stderr, _ ("Failed to parse peer identity `%s'\n"), cpid_str);
761 _("Failed to parse peer identity `%s'\n"),
762 cpid_str);
763 return; 744 return;
764 } 745 }
765 c++; 746 c++;
@@ -769,8 +750,8 @@ run (void *cls,
769 750
770 if (1 < c) 751 if (1 < c)
771 { 752 {
772 FPRINTF (stderr, 753 fprintf (stderr,
773 _("Please select one operation: %s or %s or %s or %s or %s\n"), 754 _ ("Please select one operation: %s or %s or %s or %s or %s\n"),
774 "--used", 755 "--used",
775 "--all", 756 "--all",
776 "--monitor", 757 "--monitor",
@@ -790,65 +771,56 @@ run (void *cls,
790 ph = GNUNET_ATS_performance_init (cfg, NULL, NULL); 771 ph = GNUNET_ATS_performance_init (cfg, NULL, NULL);
791 if (NULL == ph) 772 if (NULL == ph)
792 { 773 {
793 FPRINTF (stderr, 774 fprintf (stderr, "%s", _ ("Cannot connect to ATS service, exiting...\n"));
794 "%s",
795 _("Cannot connect to ATS service, exiting...\n"));
796 return; 775 return;
797 } 776 }
798 alh = GNUNET_ATS_performance_list_addresses (ph, 777 alh = GNUNET_ATS_performance_list_addresses (ph,
799 (NULL == opt_pid_str) ? NULL : &pid, 778 (NULL == opt_pid_str) ? NULL
779 : &pid,
800 GNUNET_YES, 780 GNUNET_YES,
801 &ats_perf_cb, NULL); 781 &ats_perf_cb,
782 NULL);
802 if (NULL == alh) 783 if (NULL == alh)
803 { 784 {
804 FPRINTF (stderr, 785 fprintf (stderr,
805 "%s", 786 "%s",
806 _("Cannot issue request to ATS service, exiting...\n")); 787 _ ("Cannot issue request to ATS service, exiting...\n"));
807 shutdown_task = GNUNET_SCHEDULER_add_now (&end, NULL); 788 shutdown_task = GNUNET_SCHEDULER_add_now (&end, NULL);
808 return; 789 return;
809 } 790 }
810 shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end, 791 shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end, NULL);
811 NULL);
812 return; 792 return;
813 } 793 }
814 if (opt_list_used) 794 if (opt_list_used)
815 { 795 {
816 ph = GNUNET_ATS_performance_init (cfg, NULL, NULL); 796 ph = GNUNET_ATS_performance_init (cfg, NULL, NULL);
817 if (NULL == ph) 797 if (NULL == ph)
818 FPRINTF (stderr, 798 fprintf (stderr, "%s", _ ("Cannot connect to ATS service, exiting...\n"));
819 "%s",
820 _("Cannot connect to ATS service, exiting...\n"));
821 799
822 alh = GNUNET_ATS_performance_list_addresses (ph, 800 alh = GNUNET_ATS_performance_list_addresses (ph,
823 (NULL == opt_pid_str) 801 (NULL == opt_pid_str) ? NULL
824 ? NULL 802 : &pid,
825 : &pid,
826 GNUNET_NO, 803 GNUNET_NO,
827 &ats_perf_cb, NULL); 804 &ats_perf_cb,
805 NULL);
828 if (NULL == alh) 806 if (NULL == alh)
829 { 807 {
830 FPRINTF (stderr, 808 fprintf (stderr,
831 "%s", 809 "%s",
832 _("Cannot issue request to ATS service, exiting...\n")); 810 _ ("Cannot issue request to ATS service, exiting...\n"));
833 shutdown_task = GNUNET_SCHEDULER_add_now (&end, NULL); 811 shutdown_task = GNUNET_SCHEDULER_add_now (&end, NULL);
834 return; 812 return;
835 } 813 }
836 shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end, 814 shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end, NULL);
837 NULL);
838 return; 815 return;
839 } 816 }
840 if (opt_monitor) 817 if (opt_monitor)
841 { 818 {
842 ph = GNUNET_ATS_performance_init (cfg, 819 ph = GNUNET_ATS_performance_init (cfg, &ats_perf_mon_cb, NULL);
843 &ats_perf_mon_cb, 820 shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end, NULL);
844 NULL);
845 shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end,
846 NULL);
847 if (NULL == ph) 821 if (NULL == ph)
848 { 822 {
849 FPRINTF (stderr, 823 fprintf (stderr, "%s", _ ("Cannot connect to ATS service, exiting...\n"));
850 "%s",
851 _("Cannot connect to ATS service, exiting...\n"));
852 GNUNET_SCHEDULER_shutdown (); 824 GNUNET_SCHEDULER_shutdown ();
853 } 825 }
854 return; 826 return;
@@ -857,16 +829,12 @@ run (void *cls,
857 { 829 {
858 if (NULL == opt_type_str) 830 if (NULL == opt_type_str)
859 { 831 {
860 FPRINTF (stderr, 832 fprintf (stderr, "%s", _ ("No preference type given!\n"));
861 "%s",
862 _("No preference type given!\n"));
863 return; 833 return;
864 } 834 }
865 if (NULL == opt_pid_str) 835 if (NULL == opt_pid_str)
866 { 836 {
867 FPRINTF (stderr, 837 fprintf (stderr, "%s", _ ("No peer given!\n"));
868 "%s",
869 _("No peer given!\n"));
870 return; 838 return;
871 } 839 }
872 840
@@ -882,18 +850,14 @@ run (void *cls,
882 type = GNUNET_ATS_PREFERENCE_BANDWIDTH; 850 type = GNUNET_ATS_PREFERENCE_BANDWIDTH;
883 else 851 else
884 { 852 {
885 FPRINTF (stderr, 853 fprintf (stderr, "%s", _ ("Valid type required\n"));
886 "%s",
887 _("Valid type required\n"));
888 return; 854 return;
889 } 855 }
890 856
891 /* set */ 857 /* set */
892 ph = GNUNET_ATS_performance_init (cfg, NULL, NULL); 858 ph = GNUNET_ATS_performance_init (cfg, NULL, NULL);
893 if (NULL == ph) 859 if (NULL == ph)
894 FPRINTF (stderr, 860 fprintf (stderr, "%s", _ ("Cannot connect to ATS service, exiting...\n"));
895 "%s",
896 _("Cannot connect to ATS service, exiting...\n"));
897 861
898 GNUNET_ATS_performance_change_preference (ph, 862 GNUNET_ATS_performance_change_preference (ph,
899 &pid, 863 &pid,
@@ -901,21 +865,16 @@ run (void *cls,
901 (double) opt_pref_value, 865 (double) opt_pref_value,
902 GNUNET_ATS_PREFERENCE_END); 866 GNUNET_ATS_PREFERENCE_END);
903 867
904 shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 868 shutdown_task =
905 &end, 869 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL);
906 NULL);
907 return; 870 return;
908 } 871 }
909 if (NULL != cpid_str) 872 if (NULL != cpid_str)
910 { 873 {
911 ats_ch = GNUNET_ATS_connectivity_init (cfg); 874 ats_ch = GNUNET_ATS_connectivity_init (cfg);
912 ats_sh = GNUNET_ATS_connectivity_suggest (ats_ch, 875 ats_sh = GNUNET_ATS_connectivity_suggest (ats_ch, &cpid, 1000);
913 &cpid, 876 shutdown_task =
914 1000); 877 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL);
915 shutdown_task
916 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
917 &end,
918 NULL);
919 return; 878 return;
920 } 879 }
921 ret = 1; 880 ret = 1;
@@ -930,8 +889,7 @@ run (void *cls,
930 * @return 0 ok, 1 on error 889 * @return 0 ok, 1 on error
931 */ 890 */
932int 891int
933main (int argc, 892main (int argc, char *const *argv)
934 char * const *argv)
935{ 893{
936 int res; 894 int res;
937 895
@@ -944,76 +902,83 @@ main (int argc,
944 stat_receive_done = GNUNET_NO; 902 stat_receive_done = GNUNET_NO;
945 opt_type_str = NULL; 903 opt_type_str = NULL;
946 904
947 struct GNUNET_GETOPT_CommandLineOption options[] = { 905 struct GNUNET_GETOPT_CommandLineOption options[] =
948 GNUNET_GETOPT_option_flag ('u', 906 {GNUNET_GETOPT_option_flag ('u',
949 "used", 907 "used",
950 gettext_noop ("get list of active addresses currently used"), 908 gettext_noop (
951 &opt_list_used), 909 "get list of active addresses currently used"),
952 GNUNET_GETOPT_option_flag ('a', 910 &opt_list_used),
953 "all", 911 GNUNET_GETOPT_option_flag ('a',
954 gettext_noop ("get list of all active addresses"), 912 "all",
955 &opt_list_all), 913 gettext_noop (
956 914 "get list of all active addresses"),
957 GNUNET_GETOPT_option_string ('C', 915 &opt_list_all),
958 "connect", 916
959 NULL, 917 GNUNET_GETOPT_option_string ('C',
960 gettext_noop ("connect to PEER"), 918 "connect",
961 &cpid_str), 919 NULL,
962 GNUNET_GETOPT_option_flag ('n', 920 gettext_noop ("connect to PEER"),
963 "numeric", 921 &cpid_str),
964 gettext_noop ("do not resolve IP addresses to hostnames"), 922 GNUNET_GETOPT_option_flag ('n',
965 &opt_resolve_addresses_numeric), 923 "numeric",
966 924 gettext_noop (
967 GNUNET_GETOPT_option_flag ('m', 925 "do not resolve IP addresses to hostnames"),
968 "monitor", 926 &opt_resolve_addresses_numeric),
969 gettext_noop ("monitor mode"), 927
970 &opt_monitor), 928 GNUNET_GETOPT_option_flag ('m',
971 929 "monitor",
972 GNUNET_GETOPT_option_flag ('p', 930 gettext_noop ("monitor mode"),
973 "preference", 931 &opt_monitor),
974 gettext_noop ("set preference for the given peer"), 932
975 &opt_set_pref), 933 GNUNET_GETOPT_option_flag ('p',
976 934 "preference",
977 GNUNET_GETOPT_option_flag ('q', 935 gettext_noop (
978 "quotas", 936 "set preference for the given peer"),
979 gettext_noop ("print all configured quotas"), 937 &opt_set_pref),
980 &opt_print_quotas), 938
981 GNUNET_GETOPT_option_string ('i', 939 GNUNET_GETOPT_option_flag ('q',
982 "id", 940 "quotas",
983 "TYPE", 941 gettext_noop ("print all configured quotas"),
984 gettext_noop ("peer id"), 942 &opt_print_quotas),
985 &opt_pid_str), 943 GNUNET_GETOPT_option_string ('i',
986 944 "id",
987 GNUNET_GETOPT_option_string ('t', 945 "TYPE",
988 "type", 946 gettext_noop ("peer id"),
989 "TYPE", 947 &opt_pid_str),
990 gettext_noop ("preference type to set: latency | bandwidth"), 948
991 &opt_type_str), 949 GNUNET_GETOPT_option_string ('t',
992 950 "type",
993 GNUNET_GETOPT_option_uint ('k', 951 "TYPE",
994 "value", 952 gettext_noop (
995 "VALUE", 953 "preference type to set: latency | bandwidth"),
996 gettext_noop ("preference value"), 954 &opt_type_str),
997 &opt_pref_value), 955
998 956 GNUNET_GETOPT_option_uint ('k',
999 GNUNET_GETOPT_option_flag ('V', 957 "value",
1000 "verbose", 958 "VALUE",
1001 gettext_noop ("verbose output (include ATS address properties)"), 959 gettext_noop ("preference value"),
1002 &opt_verbose), 960 &opt_pref_value),
1003 GNUNET_GETOPT_OPTION_END 961
1004 }; 962 GNUNET_GETOPT_option_flag (
963 'V',
964 "verbose",
965 gettext_noop ("verbose output (include ATS address properties)"),
966 &opt_verbose),
967 GNUNET_GETOPT_OPTION_END};
1005 968
1006 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 969 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1007 return 2; 970 return 2;
1008 971
1009 res = GNUNET_PROGRAM_run (argc, argv, 972 res = GNUNET_PROGRAM_run (argc,
973 argv,
1010 "gnunet-ats", 974 "gnunet-ats",
1011 gettext_noop ("Print information about ATS state"), 975 gettext_noop ("Print information about ATS state"),
1012 options, 976 options,
1013 &run, NULL); 977 &run,
1014 GNUNET_free_non_null(opt_pid_str); 978 NULL);
1015 GNUNET_free_non_null(opt_type_str); 979 GNUNET_free_non_null (opt_pid_str);
1016 GNUNET_free((void *) argv); 980 GNUNET_free_non_null (opt_type_str);
981 GNUNET_free ((void *) argv);
1017 982
1018 if (GNUNET_OK == res) 983 if (GNUNET_OK == res)
1019 return ret; 984 return ret;
diff --git a/src/cadet/gnunet-cadet-profiler.c b/src/cadet/gnunet-cadet-profiler.c
index 2de17dc9e..34ea53a57 100644
--- a/src/cadet/gnunet-cadet-profiler.c
+++ b/src/cadet/gnunet-cadet-profiler.c
@@ -305,7 +305,7 @@ show_end_data (void)
305 for (j = 0; j < peers_pinging; j++) 305 for (j = 0; j < peers_pinging; j++)
306 { 306 {
307 peer = &peers[j]; 307 peer = &peers[j];
308 FPRINTF (stdout, 308 fprintf (stdout,
309 "ROUND %3u PEER %3u: %10.2f / %10.2f, PINGS: %3u, PONGS: %3u\n", 309 "ROUND %3u PEER %3u: %10.2f / %10.2f, PINGS: %3u, PONGS: %3u\n",
310 i, j, peer->mean[i], sqrt (peer->var[i] / (peer->pongs[i] - 1)), 310 i, j, peer->mean[i], sqrt (peer->var[i] / (peer->pongs[i] - 1)),
311 peer->pings[i], peer->pongs[i]); 311 peer->pings[i], peer->pongs[i]);
diff --git a/src/cadet/gnunet-cadet.c b/src/cadet/gnunet-cadet.c
index 262cdf64d..4e81d52f2 100644
--- a/src/cadet/gnunet-cadet.c
+++ b/src/cadet/gnunet-cadet.c
@@ -29,7 +29,7 @@
29#include "gnunet_cadet_service.h" 29#include "gnunet_cadet_service.h"
30#include "cadet.h" 30#include "cadet.h"
31 31
32#define STREAM_BUFFER_SIZE 1024 // Pakets 32#define STREAM_BUFFER_SIZE 1024 // Pakets
33 33
34/** 34/**
35 * Option -P. 35 * Option -P.
@@ -158,16 +158,16 @@ enc_2s (uint16_t status)
158{ 158{
159 switch (status) 159 switch (status)
160 { 160 {
161 case 0: 161 case 0:
162 return "NULL "; 162 return "NULL ";
163 case 1: 163 case 1:
164 return "KSENT"; 164 return "KSENT";
165 case 2: 165 case 2:
166 return "KRECV"; 166 return "KRECV";
167 case 3: 167 case 3:
168 return "READY"; 168 return "READY";
169 default: 169 default:
170 return ""; 170 return "";
171 } 171 }
172} 172}
173 173
@@ -184,23 +184,22 @@ conn_2s (uint16_t status)
184{ 184{
185 switch (status) 185 switch (status)
186 { 186 {
187 case 0: 187 case 0:
188 return "NEW "; 188 return "NEW ";
189 case 1: 189 case 1:
190 return "SRCH "; 190 return "SRCH ";
191 case 2: 191 case 2:
192 return "WAIT "; 192 return "WAIT ";
193 case 3: 193 case 3:
194 return "READY"; 194 return "READY";
195 case 4: 195 case 4:
196 return "SHUTD"; 196 return "SHUTD";
197 default: 197 default:
198 return ""; 198 return "";
199 } 199 }
200} 200}
201 201
202 202
203
204/** 203/**
205 * Task to shut down this application. 204 * Task to shut down this application.
206 * 205 *
@@ -209,8 +208,7 @@ conn_2s (uint16_t status)
209static void 208static void
210shutdown_task (void *cls) 209shutdown_task (void *cls)
211{ 210{
212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
213 "Shutdown\n");
214 if (NULL != lp) 212 if (NULL != lp)
215 { 213 {
216 GNUNET_CADET_close_port (lp); 214 GNUNET_CADET_close_port (lp);
@@ -259,7 +257,7 @@ shutdown_task (void *cls)
259} 257}
260 258
261void 259void
262mq_cb(void *cls) 260mq_cb (void *cls)
263{ 261{
264 listen_stdio (); 262 listen_stdio ();
265} 263}
@@ -279,27 +277,21 @@ read_stdio (void *cls)
279 ssize_t data_size; 277 ssize_t data_size;
280 278
281 rd_task = NULL; 279 rd_task = NULL;
282 data_size = read (0, 280 data_size = read (0, buf, 60000);
283 buf,
284 60000);
285 if (data_size < 1) 281 if (data_size < 1)
286 { 282 {
287 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 283 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
288 "read() returned %s\n", strerror(errno)); 284 "read() returned %s\n",
289 GNUNET_SCHEDULER_shutdown(); 285 strerror (errno));
286 GNUNET_SCHEDULER_shutdown ();
290 return; 287 return;
291 } 288 }
292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 289 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
293 "Read %u bytes from stdio\n", 290 "Read %u bytes from stdio\n",
294 (unsigned int) data_size); 291 (unsigned int) data_size);
295 env = GNUNET_MQ_msg_extra (msg, 292 env = GNUNET_MQ_msg_extra (msg, data_size, GNUNET_MESSAGE_TYPE_CADET_CLI);
296 data_size, 293 GNUNET_memcpy (&msg[1], buf, data_size);
297 GNUNET_MESSAGE_TYPE_CADET_CLI); 294 GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), env);
298 GNUNET_memcpy (&msg[1],
299 buf,
300 data_size);
301 GNUNET_MQ_send (GNUNET_CADET_get_mq (ch),
302 env);
303 295
304 sent_pkt++; 296 sent_pkt++;
305 297
@@ -333,8 +325,7 @@ listen_stdio ()
333 325
334 /* FIXME: why use 'rs' here, seems overly complicated... */ 326 /* FIXME: why use 'rs' here, seems overly complicated... */
335 rs = GNUNET_NETWORK_fdset_create (); 327 rs = GNUNET_NETWORK_fdset_create ();
336 GNUNET_NETWORK_fdset_set_native (rs, 328 GNUNET_NETWORK_fdset_set_native (rs, 0); /* STDIN */
337 0); /* STDIN */
338 rd_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 329 rd_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
339 GNUNET_TIME_UNIT_FOREVER_REL, 330 GNUNET_TIME_UNIT_FOREVER_REL,
340 rs, 331 rs,
@@ -355,11 +346,9 @@ listen_stdio ()
355 * @param channel connection to the other end (henceforth invalid) 346 * @param channel connection to the other end (henceforth invalid)
356 */ 347 */
357static void 348static void
358channel_ended (void *cls, 349channel_ended (void *cls, const struct GNUNET_CADET_Channel *channel)
359 const struct GNUNET_CADET_Channel *channel)
360{ 350{
361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 351 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel ended!\n");
362 "Channel ended!\n");
363 GNUNET_assert (channel == ch); 352 GNUNET_assert (channel == ch);
364 ch = NULL; 353 ch = NULL;
365 GNUNET_SCHEDULER_shutdown (); 354 GNUNET_SCHEDULER_shutdown ();
@@ -413,10 +402,8 @@ send_echo (void *cls)
413 echo_task = NULL; 402 echo_task = NULL;
414 if (NULL == ch) 403 if (NULL == ch)
415 return; 404 return;
416 env = GNUNET_MQ_msg (msg, 405 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_CLI);
417 GNUNET_MESSAGE_TYPE_CADET_CLI); 406 GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), env);
418 GNUNET_MQ_send (GNUNET_CADET_get_mq (ch),
419 env);
420} 407}
421 408
422 409
@@ -429,8 +416,7 @@ send_echo (void *cls)
429 * #GNUNET_SYSERR to close it (signal serious error). 416 * #GNUNET_SYSERR to close it (signal serious error).
430 */ 417 */
431static int 418static int
432check_data (void *cls, 419check_data (void *cls, const struct GNUNET_MessageHeader *message)
433 const struct GNUNET_MessageHeader *message)
434{ 420{
435 return GNUNET_OK; /* all is well-formed */ 421 return GNUNET_OK; /* all is well-formed */
436} 422}
@@ -447,8 +433,7 @@ check_data (void *cls,
447 * @param message The actual message. 433 * @param message The actual message.
448 */ 434 */
449static void 435static void
450handle_data (void *cls, 436handle_data (void *cls, const struct GNUNET_MessageHeader *message)
451 const struct GNUNET_MessageHeader *message)
452{ 437{
453 size_t payload_size = ntohs (message->size) - sizeof (*message); 438 size_t payload_size = ntohs (message->size) - sizeof (*message);
454 uint16_t len; 439 uint16_t len;
@@ -464,14 +449,10 @@ handle_data (void *cls,
464 struct GNUNET_MQ_Envelope *env; 449 struct GNUNET_MQ_Envelope *env;
465 struct GNUNET_MessageHeader *msg; 450 struct GNUNET_MessageHeader *msg;
466 451
467 env = GNUNET_MQ_msg_extra (msg, 452 env =
468 payload_size, 453 GNUNET_MQ_msg_extra (msg, payload_size, GNUNET_MESSAGE_TYPE_CADET_CLI);
469 GNUNET_MESSAGE_TYPE_CADET_CLI); 454 GNUNET_memcpy (&msg[1], &message[1], payload_size);
470 GNUNET_memcpy (&msg[1], 455 GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), env);
471 &message[1],
472 payload_size);
473 GNUNET_MQ_send (GNUNET_CADET_get_mq (ch),
474 env);
475 return; 456 return;
476 } 457 }
477 else 458 else
@@ -482,8 +463,7 @@ handle_data (void *cls,
482 echo_time = GNUNET_TIME_UNIT_FOREVER_ABS; 463 echo_time = GNUNET_TIME_UNIT_FOREVER_ABS;
483 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 464 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
484 "time: %s\n", 465 "time: %s\n",
485 GNUNET_STRINGS_relative_time_to_string (latency, 466 GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_NO));
486 GNUNET_NO));
487 echo_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 467 echo_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
488 &send_echo, 468 &send_echo,
489 NULL); 469 NULL);
@@ -491,21 +471,16 @@ handle_data (void *cls,
491 } 471 }
492 472
493 len = ntohs (message->size) - sizeof (*message); 473 len = ntohs (message->size) - sizeof (*message);
494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 474 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got %u bytes\n", len);
495 "Got %u bytes\n",
496 len);
497 buf = (const char *) &message[1]; 475 buf = (const char *) &message[1];
498 off = 0; 476 off = 0;
499 while (off < len) 477 while (off < len)
500 { 478 {
501 done = write (1, 479 done = write (1, &buf[off], len - off);
502 &buf[off],
503 len - off);
504 if (done <= 0) 480 if (done <= 0)
505 { 481 {
506 if (-1 == done) 482 if (-1 == done)
507 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 483 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "write");
508 "write");
509 GNUNET_SCHEDULER_shutdown (); 484 GNUNET_SCHEDULER_shutdown ();
510 return; 485 return;
511 } 486 }
@@ -524,16 +499,15 @@ handle_data (void *cls,
524 * @param ple information about peer, or NULL on "EOF". 499 * @param ple information about peer, or NULL on "EOF".
525 */ 500 */
526static void 501static void
527peers_callback (void *cls, 502peers_callback (void *cls, const struct GNUNET_CADET_PeerListEntry *ple)
528 const struct GNUNET_CADET_PeerListEntry *ple)
529{ 503{
530 if (NULL == ple) 504 if (NULL == ple)
531 { 505 {
532 plo = NULL; 506 plo = NULL;
533 GNUNET_SCHEDULER_shutdown(); 507 GNUNET_SCHEDULER_shutdown ();
534 return; 508 return;
535 } 509 }
536 FPRINTF (stdout, 510 fprintf (stdout,
537 "%s tunnel: %c, paths: %u\n", 511 "%s tunnel: %c, paths: %u\n",
538 GNUNET_i2s_full (&ple->peer), 512 GNUNET_i2s_full (&ple->peer),
539 ple->have_tunnel ? 'Y' : 'N', 513 ple->have_tunnel ? 'Y' : 'N',
@@ -549,24 +523,20 @@ peers_callback (void *cls,
549 * @param ppd path detail 523 * @param ppd path detail
550 */ 524 */
551static void 525static void
552path_callback (void *cls, 526path_callback (void *cls, const struct GNUNET_CADET_PeerPathDetail *ppd)
553 const struct GNUNET_CADET_PeerPathDetail *ppd)
554{ 527{
555 if (NULL == ppd) 528 if (NULL == ppd)
556 { 529 {
557 gpo = NULL; 530 gpo = NULL;
558 GNUNET_SCHEDULER_shutdown(); 531 GNUNET_SCHEDULER_shutdown ();
559 return; 532 return;
560 } 533 }
561 FPRINTF (stdout, 534 fprintf (stdout, "Path of length %u: ", ppd->path_length);
562 "Path of length %u: ",
563 ppd->path_length);
564 for (unsigned int i = 0; i < ppd->path_length; i++) 535 for (unsigned int i = 0; i < ppd->path_length; i++)
565 FPRINTF (stdout, 536 fprintf (stdout,
566 (i == ppd->target_offset) ? "*%s* " : "%s ", 537 (i == ppd->target_offset) ? "*%s* " : "%s ",
567 GNUNET_i2s (&ppd->path[i])); 538 GNUNET_i2s (&ppd->path[i]));
568 FPRINTF (stdout, 539 fprintf (stdout, "\n");
569 "\n");
570} 540}
571 541
572 542
@@ -577,16 +547,15 @@ path_callback (void *cls,
577 * @param td tunnel details 547 * @param td tunnel details
578 */ 548 */
579static void 549static void
580tunnels_callback (void *cls, 550tunnels_callback (void *cls, const struct GNUNET_CADET_TunnelDetails *td)
581 const struct GNUNET_CADET_TunnelDetails *td)
582{ 551{
583 if (NULL == td) 552 if (NULL == td)
584 { 553 {
585 tio = NULL; 554 tio = NULL;
586 GNUNET_SCHEDULER_shutdown(); 555 GNUNET_SCHEDULER_shutdown ();
587 return; 556 return;
588 } 557 }
589 FPRINTF (stdout, 558 fprintf (stdout,
590 "%s [ENC: %s, CON: %s] CHs: %u, CONNs: %u\n", 559 "%s [ENC: %s, CON: %s] CHs: %u, CONNs: %u\n",
591 GNUNET_i2s_full (&td->peer), 560 GNUNET_i2s_full (&td->peer),
592 enc_2s (td->estate), 561 enc_2s (td->estate),
@@ -605,9 +574,7 @@ static void
605get_peers (void *cls) 574get_peers (void *cls)
606{ 575{
607 job = NULL; 576 job = NULL;
608 plo = GNUNET_CADET_list_peers (my_cfg, 577 plo = GNUNET_CADET_list_peers (my_cfg, &peers_callback, NULL);
609 &peers_callback,
610 NULL);
611} 578}
612 579
613 580
@@ -622,21 +589,15 @@ show_peer (void *cls)
622 struct GNUNET_PeerIdentity pid; 589 struct GNUNET_PeerIdentity pid;
623 590
624 job = NULL; 591 job = NULL;
625 if (GNUNET_OK != 592 if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
626 GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id, 593 strlen (peer_id),
627 strlen (peer_id), 594 &pid.public_key))
628 &pid.public_key))
629 { 595 {
630 fprintf (stderr, 596 fprintf (stderr, _ ("Invalid peer ID `%s'\n"), peer_id);
631 _("Invalid peer ID `%s'\n"), 597 GNUNET_SCHEDULER_shutdown ();
632 peer_id);
633 GNUNET_SCHEDULER_shutdown();
634 return; 598 return;
635 } 599 }
636 gpo = GNUNET_CADET_get_path (my_cfg, 600 gpo = GNUNET_CADET_get_path (my_cfg, &pid, &path_callback, NULL);
637 &pid,
638 &path_callback,
639 NULL);
640} 601}
641 602
642 603
@@ -649,9 +610,7 @@ static void
649get_tunnels (void *cls) 610get_tunnels (void *cls)
650{ 611{
651 job = NULL; 612 job = NULL;
652 tio = GNUNET_CADET_list_tunnels (my_cfg, 613 tio = GNUNET_CADET_list_tunnels (my_cfg, &tunnels_callback, NULL);
653 &tunnels_callback,
654 NULL);
655} 614}
656 615
657 616
@@ -695,13 +654,12 @@ run (void *cls,
695 const char *cfgfile, 654 const char *cfgfile,
696 const struct GNUNET_CONFIGURATION_Handle *cfg) 655 const struct GNUNET_CONFIGURATION_Handle *cfg)
697{ 656{
698 struct GNUNET_MQ_MessageHandler handlers[] = { 657 struct GNUNET_MQ_MessageHandler handlers[] =
699 GNUNET_MQ_hd_var_size (data, 658 {GNUNET_MQ_hd_var_size (data,
700 GNUNET_MESSAGE_TYPE_CADET_CLI, 659 GNUNET_MESSAGE_TYPE_CADET_CLI,
701 struct GNUNET_MessageHeader, 660 struct GNUNET_MessageHeader,
702 NULL), 661 NULL),
703 GNUNET_MQ_handler_end () 662 GNUNET_MQ_handler_end ()};
704 };
705 663
706 /* FIXME add option to monitor apps */ 664 /* FIXME add option to monitor apps */
707 my_cfg = cfg; 665 my_cfg = cfg;
@@ -709,58 +667,45 @@ run (void *cls,
709 if (target_id && args[1]) 667 if (target_id && args[1])
710 target_port = args[1]; 668 target_port = args[1];
711 669
712 if ( (0 != (request_peers | request_tunnels) 670 if ((0 != (request_peers | request_tunnels) || NULL != conn_id ||
713 || NULL != conn_id 671 NULL != channel_id) &&
714 || NULL != channel_id) 672 target_id != NULL)
715 && target_id != NULL)
716 { 673 {
717 FPRINTF (stderr, 674 fprintf (stderr,
718 _("Extra arguments are not applicable " 675 _ ("Extra arguments are not applicable "
719 "in combination with this option.\n")); 676 "in combination with this option.\n"));
720 return; 677 return;
721 } 678 }
722 679
723 if (NULL != peer_id) 680 if (NULL != peer_id)
724 { 681 {
725 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 682 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show peer\n");
726 "Show peer\n"); 683 job = GNUNET_SCHEDULER_add_now (&show_peer, NULL);
727 job = GNUNET_SCHEDULER_add_now (&show_peer,
728 NULL);
729 } 684 }
730 else if (NULL != channel_id) 685 else if (NULL != channel_id)
731 { 686 {
732 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show channel\n");
733 "Show channel\n"); 688 job = GNUNET_SCHEDULER_add_now (&show_channel, NULL);
734 job = GNUNET_SCHEDULER_add_now (&show_channel,
735 NULL);
736 } 689 }
737 else if (NULL != conn_id) 690 else if (NULL != conn_id)
738 { 691 {
739 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 692 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show connection\n");
740 "Show connection\n"); 693 job = GNUNET_SCHEDULER_add_now (&show_connection, NULL);
741 job = GNUNET_SCHEDULER_add_now (&show_connection,
742 NULL);
743 } 694 }
744 else if (GNUNET_YES == request_peers) 695 else if (GNUNET_YES == request_peers)
745 { 696 {
746 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 697 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all peers\n");
747 "Show all peers\n"); 698 job = GNUNET_SCHEDULER_add_now (&get_peers, NULL);
748 job = GNUNET_SCHEDULER_add_now (&get_peers,
749 NULL);
750 } 699 }
751 else if (GNUNET_YES == request_tunnels) 700 else if (GNUNET_YES == request_tunnels)
752 { 701 {
753 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 702 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all tunnels\n");
754 "Show all tunnels\n"); 703 job = GNUNET_SCHEDULER_add_now (&get_tunnels, NULL);
755 job = GNUNET_SCHEDULER_add_now (&get_tunnels,
756 NULL);
757 } 704 }
758 705
759 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 706 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CADET service\n");
760 "Connecting to CADET service\n");
761 mh = GNUNET_CADET_connect (cfg); 707 mh = GNUNET_CADET_connect (cfg);
762 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 708 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
763 NULL);
764 if (NULL == mh) 709 if (NULL == mh)
765 { 710 {
766 GNUNET_SCHEDULER_shutdown (); 711 GNUNET_SCHEDULER_shutdown ();
@@ -768,11 +713,8 @@ run (void *cls,
768 } 713 }
769 if (NULL != listen_port) 714 if (NULL != listen_port)
770 { 715 {
771 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 716 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Opening CADET listen port\n");
772 "Opening CADET listen port\n"); 717 GNUNET_CRYPTO_hash (listen_port, strlen (listen_port), &porthash);
773 GNUNET_CRYPTO_hash (listen_port,
774 strlen (listen_port),
775 &porthash);
776 lp = GNUNET_CADET_open_port (mh, 718 lp = GNUNET_CADET_open_port (mh,
777 &porthash, 719 &porthash,
778 &channel_incoming, 720 &channel_incoming,
@@ -791,7 +733,7 @@ run (void *cls,
791 &pid.public_key)) 733 &pid.public_key))
792 { 734 {
793 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 735 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
794 _("Invalid target `%s'\n"), 736 _ ("Invalid target `%s'\n"),
795 target_id); 737 target_id);
796 GNUNET_SCHEDULER_shutdown (); 738 GNUNET_SCHEDULER_shutdown ();
797 return; 739 return;
@@ -800,9 +742,7 @@ run (void *cls,
800 "Connecting to `%s:%s'\n", 742 "Connecting to `%s:%s'\n",
801 target_id, 743 target_id,
802 target_port); 744 target_port);
803 GNUNET_CRYPTO_hash (target_port, 745 GNUNET_CRYPTO_hash (target_port, strlen (target_port), &porthash);
804 strlen(target_port),
805 &porthash);
806 ch = GNUNET_CADET_channel_create (mh, 746 ch = GNUNET_CADET_channel_create (mh,
807 NULL, 747 NULL,
808 &pid, 748 &pid,
@@ -812,8 +752,7 @@ run (void *cls,
812 handlers); 752 handlers);
813 if (GNUNET_YES == echo) 753 if (GNUNET_YES == echo)
814 { 754 {
815 echo_task = GNUNET_SCHEDULER_add_now (&send_echo, 755 echo_task = GNUNET_SCHEDULER_add_now (&send_echo, NULL);
816 NULL);
817 } 756 }
818 else 757 else
819 { 758 {
@@ -821,12 +760,9 @@ run (void *cls,
821 } 760 }
822 } 761 }
823 762
824 if ( (NULL == lp) && 763 if ((NULL == lp) && (NULL == job) && (NULL == ch))
825 (NULL == job) &&
826 (NULL == ch) )
827 { 764 {
828 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 765 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, _ ("No action requested\n"));
829 _("No action requested\n"));
830 GNUNET_SCHEDULER_shutdown (); 766 GNUNET_SCHEDULER_shutdown ();
831 return; 767 return;
832 } 768 }
@@ -841,52 +777,58 @@ run (void *cls,
841 * @return 0 ok, 1 on error 777 * @return 0 ok, 1 on error
842 */ 778 */
843int 779int
844main (int argc, 780main (int argc, char *const *argv)
845 char *const *argv)
846{ 781{
847 int res; 782 int res;
848 const char helpstr[] = "Create tunnels and retrieve info about CADET's status."; 783 const char helpstr[] =
849 struct GNUNET_GETOPT_CommandLineOption options[] = { 784 "Create tunnels and retrieve info about CADET's status.";
850 /* I would use the terminology 'circuit' here... --lynX */ 785 struct GNUNET_GETOPT_CommandLineOption options[] =
851 GNUNET_GETOPT_option_string ('C', 786 {/* I would use the terminology 'circuit' here... --lynX */
852 "connection", 787 GNUNET_GETOPT_option_string (
853 "CONNECTION_ID", 788 'C',
854 gettext_noop ("Provide information about a particular connection"), 789 "connection",
855 &conn_id), 790 "CONNECTION_ID",
856 GNUNET_GETOPT_option_flag ('e', 791 gettext_noop ("Provide information about a particular connection"),
857 "echo", 792 &conn_id),
858 gettext_noop ("Activate echo mode"), 793 GNUNET_GETOPT_option_flag ('e',
859 &echo), 794 "echo",
860 GNUNET_GETOPT_option_string ('o', 795 gettext_noop ("Activate echo mode"),
861 "open-port", 796 &echo),
862 "SHARED_SECRET", 797 GNUNET_GETOPT_option_string (
863 gettext_noop ("Listen for connections using a shared secret among sender and recipient"), 798 'o',
864 &listen_port), 799 "open-port",
865 GNUNET_GETOPT_option_string ('p', 800 "SHARED_SECRET",
866 "peer", 801 gettext_noop (
867 "PEER_ID", 802 "Listen for connections using a shared secret among sender and recipient"),
868 gettext_noop ("Provide information about a patricular peer"), 803 &listen_port),
869 &peer_id), 804 GNUNET_GETOPT_option_string ('p',
870 GNUNET_GETOPT_option_flag ('P', 805 "peer",
871 "peers", 806 "PEER_ID",
872 gettext_noop ("Provide information about all peers"), 807 gettext_noop (
873 &request_peers), 808 "Provide information about a patricular peer"),
874 GNUNET_GETOPT_option_flag ('T', 809 &peer_id),
875 "tunnels", 810 GNUNET_GETOPT_option_flag ('P',
876 gettext_noop ("Provide information about all tunnels"), 811 "peers",
877 &request_tunnels), 812 gettext_noop (
878 GNUNET_GETOPT_OPTION_END 813 "Provide information about all peers"),
879 }; 814 &request_peers),
880 815 GNUNET_GETOPT_option_flag ('T',
881 if (GNUNET_OK != 816 "tunnels",
882 GNUNET_STRINGS_get_utf8_args (argc, argv, 817 gettext_noop (
883 &argc, &argv)) 818 "Provide information about all tunnels"),
819 &request_tunnels),
820 GNUNET_GETOPT_OPTION_END};
821
822 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
884 return 2; 823 return 2;
885 824
886 res = GNUNET_PROGRAM_run (argc, argv, 825 res = GNUNET_PROGRAM_run (argc,
826 argv,
887 "gnunet-cadet (OPTIONS | PEER_ID SHARED_SECRET)", 827 "gnunet-cadet (OPTIONS | PEER_ID SHARED_SECRET)",
888 gettext_noop (helpstr), 828 gettext_noop (helpstr),
889 options, &run, NULL); 829 options,
830 &run,
831 NULL);
890 832
891 GNUNET_free ((void *) argv); 833 GNUNET_free ((void *) argv);
892 834
diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c
index 80a6e8227..5a28b439e 100644
--- a/src/cadet/test_cadet.c
+++ b/src/cadet/test_cadet.c
@@ -280,16 +280,16 @@ show_end_data (void)
280 280
281 end_time = GNUNET_TIME_absolute_get (); 281 end_time = GNUNET_TIME_absolute_get ();
282 total_time = GNUNET_TIME_absolute_get_difference (start_time, end_time); 282 total_time = GNUNET_TIME_absolute_get_difference (start_time, end_time);
283 FPRINTF (stderr, 283 fprintf (stderr,
284 "\nResults of test \"%s\"\n", 284 "\nResults of test \"%s\"\n",
285 test_name); 285 test_name);
286 FPRINTF (stderr, 286 fprintf (stderr,
287 "Test time %s\n", 287 "Test time %s\n",
288 GNUNET_STRINGS_relative_time_to_string (total_time, GNUNET_YES)); 288 GNUNET_STRINGS_relative_time_to_string (total_time, GNUNET_YES));
289 FPRINTF (stderr, 289 fprintf (stderr,
290 "Test bandwidth: %f kb/s\n", 290 "Test bandwidth: %f kb/s\n",
291 4 * total_packets * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms 291 4 * total_packets * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms
292 FPRINTF (stderr, 292 fprintf (stderr,
293 "Test throughput: %f packets/s\n\n", 293 "Test throughput: %f packets/s\n\n",
294 total_packets * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms 294 total_packets * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms
295 GAUGER ("CADET", 295 GAUGER ("CADET",
@@ -1171,7 +1171,7 @@ main (int argc, char *argv[])
1171 short_time = SHORT_TIME; 1171 short_time = SHORT_TIME;
1172 if (-1 == GNUNET_GETOPT_run (argv[0], options, argc, argv)) 1172 if (-1 == GNUNET_GETOPT_run (argv[0], options, argc, argv))
1173 { 1173 {
1174 FPRINTF (stderr, "test failed: problem with CLI parameters\n"); 1174 fprintf (stderr, "test failed: problem with CLI parameters\n");
1175 exit (1); 1175 exit (1);
1176 } 1176 }
1177 1177
diff --git a/src/cadet/test_cadet_flow.c b/src/cadet/test_cadet_flow.c
index 552d0fdb3..87e7b9a03 100644
--- a/src/cadet/test_cadet_flow.c
+++ b/src/cadet/test_cadet_flow.c
@@ -216,16 +216,16 @@ show_end_data (void)
216 216
217 end_time = GNUNET_TIME_absolute_get (); 217 end_time = GNUNET_TIME_absolute_get ();
218 total_time = GNUNET_TIME_absolute_get_difference (start_time, end_time); 218 total_time = GNUNET_TIME_absolute_get_difference (start_time, end_time);
219 FPRINTF (stderr, 219 fprintf (stderr,
220 "\nResults of test \"%s\"\n", 220 "\nResults of test \"%s\"\n",
221 test_name); 221 test_name);
222 FPRINTF (stderr, 222 fprintf (stderr,
223 "Test time %s\n", 223 "Test time %s\n",
224 GNUNET_STRINGS_relative_time_to_string (total_time, GNUNET_YES)); 224 GNUNET_STRINGS_relative_time_to_string (total_time, GNUNET_YES));
225 FPRINTF (stderr, 225 fprintf (stderr,
226 "Test bandwidth: %f kb/s\n", 226 "Test bandwidth: %f kb/s\n",
227 4 * total_packets * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms 227 4 * total_packets * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms
228 FPRINTF (stderr, 228 fprintf (stderr,
229 "Test throughput: %f packets/s\n\n", 229 "Test throughput: %f packets/s\n\n",
230 total_packets * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms 230 total_packets * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms
231 GAUGER ("CADET", 231 GAUGER ("CADET",
@@ -863,7 +863,7 @@ main (int argc,
863 argc, 863 argc,
864 argv)) 864 argv))
865 { 865 {
866 FPRINTF (stderr, 866 fprintf (stderr,
867 "test failed: problem with CLI parameters\n"); 867 "test failed: problem with CLI parameters\n");
868 return 1; 868 return 1;
869 } 869 }
diff --git a/src/conversation/gnunet-conversation.c b/src/conversation/gnunet-conversation.c
index 6c3db2184..4c5407cd7 100644
--- a/src/conversation/gnunet-conversation.c
+++ b/src/conversation/gnunet-conversation.c
@@ -38,7 +38,7 @@
38 */ 38 */
39#define MAX_MESSAGE_LENGTH 1024 39#define MAX_MESSAGE_LENGTH 1024
40 40
41#define XSTRINGIFY(x) STRINGIFY(x) 41#define XSTRINGIFY(x) STRINGIFY (x)
42 42
43#define STRINGIFY(x) (#x) 43#define STRINGIFY(x) (#x)
44 44
@@ -134,11 +134,9 @@ struct CallList
134 * Unique number of the call. 134 * Unique number of the call.
135 */ 135 */
136 unsigned int caller_num; 136 unsigned int caller_num;
137
138}; 137};
139 138
140 139
141
142/** 140/**
143 * Phone handle 141 * Phone handle
144 */ 142 */
@@ -173,7 +171,7 @@ static char *line;
173/** 171/**
174 * Task which handles the commands 172 * Task which handles the commands
175 */ 173 */
176static struct GNUNET_SCHEDULER_Task * handle_cmd_task; 174static struct GNUNET_SCHEDULER_Task *handle_cmd_task;
177 175
178/** 176/**
179 * Our speaker. 177 * Our speaker.
@@ -273,33 +271,32 @@ phone_event_handler (void *cls,
273 * 271 *
274 * see https://gstreamer.freedesktop.org/documentation/application-development/highlevel/playback-components.html on how to play a wav using the gst framework being used here 272 * see https://gstreamer.freedesktop.org/documentation/application-development/highlevel/playback-components.html on how to play a wav using the gst framework being used here
275 */ 273 */
276 FPRINTF (stdout, 274 fprintf (
277 _("Incoming call from `%s'. Please /accept %u or /cancel %u the call.\n"), 275 stdout,
278 GNUNET_GNSRECORD_pkey_to_zkey (caller_id), 276 _ (
279 caller_num_gen, 277 "Incoming call from `%s'. Please /accept %u or /cancel %u the call.\n"),
280 caller_num_gen); 278 GNUNET_GNSRECORD_pkey_to_zkey (caller_id),
279 caller_num_gen,
280 caller_num_gen);
281 cl = GNUNET_new (struct CallList); 281 cl = GNUNET_new (struct CallList);
282 cl->caller = caller; 282 cl->caller = caller;
283 cl->caller_id = *caller_id; 283 cl->caller_id = *caller_id;
284 cl->caller_num = caller_num_gen++; 284 cl->caller_num = caller_num_gen++;
285 GNUNET_CONTAINER_DLL_insert (cl_head, 285 GNUNET_CONTAINER_DLL_insert (cl_head, cl_tail, cl);
286 cl_tail,
287 cl);
288 break; 286 break;
289 case GNUNET_CONVERSATION_EC_PHONE_HUNG_UP: 287 case GNUNET_CONVERSATION_EC_PHONE_HUNG_UP:
290 for (cl = cl_head; NULL != cl; cl = cl->next) 288 for (cl = cl_head; NULL != cl; cl = cl->next)
291 if (caller == cl->caller) 289 if (caller == cl->caller)
292 break; 290 break;
293 if ( (NULL == cl) && 291 if ((NULL == cl) && (caller == cl_active->caller))
294 (caller == cl_active->caller) )
295 cl = cl_active; 292 cl = cl_active;
296 if (NULL == cl) 293 if (NULL == cl)
297 { 294 {
298 GNUNET_break (0); 295 GNUNET_break (0);
299 return; 296 return;
300 } 297 }
301 FPRINTF (stdout, 298 fprintf (stdout,
302 _("Call from `%s' terminated\n"), 299 _ ("Call from `%s' terminated\n"),
303 GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id)); 300 GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id));
304 if (cl == cl_active) 301 if (cl == cl_active)
305 { 302 {
@@ -308,9 +305,7 @@ phone_event_handler (void *cls,
308 } 305 }
309 else 306 else
310 { 307 {
311 GNUNET_CONTAINER_DLL_remove (cl_head, 308 GNUNET_CONTAINER_DLL_remove (cl_head, cl_tail, cl);
312 cl_tail,
313 cl);
314 } 309 }
315 GNUNET_free (cl); 310 GNUNET_free (cl);
316 break; 311 break;
@@ -325,21 +320,20 @@ phone_event_handler (void *cls,
325 * @param code type of the event issued by the caller 320 * @param code type of the event issued by the caller
326 */ 321 */
327static void 322static void
328caller_event_handler (void *cls, 323caller_event_handler (void *cls, enum GNUNET_CONVERSATION_CallerEventCode code)
329 enum GNUNET_CONVERSATION_CallerEventCode code)
330{ 324{
331 struct CallList *cl = cls; 325 struct CallList *cl = cls;
332 326
333 switch (code) 327 switch (code)
334 { 328 {
335 case GNUNET_CONVERSATION_EC_CALLER_SUSPEND: 329 case GNUNET_CONVERSATION_EC_CALLER_SUSPEND:
336 FPRINTF (stdout, 330 fprintf (stdout,
337 _("Call from `%s' suspended by other user\n"), 331 _ ("Call from `%s' suspended by other user\n"),
338 GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id)); 332 GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id));
339 break; 333 break;
340 case GNUNET_CONVERSATION_EC_CALLER_RESUME: 334 case GNUNET_CONVERSATION_EC_CALLER_RESUME:
341 FPRINTF (stdout, 335 fprintf (stdout,
342 _("Call from `%s' resumed by other user\n"), 336 _ ("Call from `%s' resumed by other user\n"),
343 GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id)); 337 GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id));
344 break; 338 break;
345 } 339 }
@@ -356,8 +350,8 @@ start_phone ()
356 350
357 if (NULL == my_caller_id) 351 if (NULL == my_caller_id)
358 { 352 {
359 FPRINTF (stderr, 353 fprintf (stderr,
360 _("Ego `%s' no longer available, phone is now down.\n"), 354 _ ("Ego `%s' no longer available, phone is now down.\n"),
361 ego_name); 355 ego_name);
362 phone_state = PS_LOOKUP_EGO; 356 phone_state = PS_LOOKUP_EGO;
363 return; 357 return;
@@ -370,22 +364,20 @@ start_phone ()
370 /* FIXME: get record and print full GNS record info later here... */ 364 /* FIXME: get record and print full GNS record info later here... */
371 if (NULL == phone) 365 if (NULL == phone)
372 { 366 {
373 FPRINTF (stderr, 367 fprintf (stderr, "%s", _ ("Failed to setup phone (internal error)\n"));
374 "%s",
375 _("Failed to setup phone (internal error)\n"));
376 phone_state = PS_ERROR; 368 phone_state = PS_ERROR;
377 } 369 }
378 else 370 else
379 { 371 {
380 GNUNET_CONVERSATION_phone_get_record (phone, 372 GNUNET_CONVERSATION_phone_get_record (phone, &rd);
381 &rd);
382 GNUNET_free_non_null (address); 373 GNUNET_free_non_null (address);
383 address = GNUNET_GNSRECORD_value_to_string (rd.record_type, 374 address =
384 rd.data, 375 GNUNET_GNSRECORD_value_to_string (rd.record_type, rd.data, rd.data_size);
385 rd.data_size); 376 fprintf (
386 FPRINTF (stdout, 377 stdout,
387 _("Phone active at `%s'. Type `/help' for a list of available commands\n"), 378 _ (
388 address); 379 "Phone active at `%s'. Type `/help' for a list of available commands\n"),
380 address);
389 phone_state = PS_LISTEN; 381 phone_state = PS_LISTEN;
390 } 382 }
391} 383}
@@ -398,59 +390,51 @@ start_phone ()
398 * @param code type of the event on the call 390 * @param code type of the event on the call
399 */ 391 */
400static void 392static void
401call_event_handler (void *cls, 393call_event_handler (void *cls, enum GNUNET_CONVERSATION_CallEventCode code)
402 enum GNUNET_CONVERSATION_CallEventCode code)
403{ 394{
404 (void) cls; 395 (void) cls;
405 396
406 switch (code) 397 switch (code)
407 { 398 {
408 case GNUNET_CONVERSATION_EC_CALL_RINGING: 399 case GNUNET_CONVERSATION_EC_CALL_RINGING:
409 GNUNET_break (CS_RESOLVING == call_state); 400 GNUNET_break (CS_RESOLVING == call_state);
410 FPRINTF (stdout, 401 fprintf (stdout,
411 _("Resolved address of `%s'. Now ringing other party.\n"), 402 _ ("Resolved address of `%s'. Now ringing other party.\n"),
412 peer_name); 403 peer_name);
413 call_state = CS_RINGING; 404 call_state = CS_RINGING;
414 break; 405 break;
415 case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: 406 case GNUNET_CONVERSATION_EC_CALL_PICKED_UP:
416 GNUNET_break (CS_RINGING == call_state); 407 GNUNET_break (CS_RINGING == call_state);
417 FPRINTF (stdout, 408 fprintf (stdout, _ ("Connection established to `%s'\n"), peer_name);
418 _("Connection established to `%s'\n"),
419 peer_name);
420 call_state = CS_CONNECTED; 409 call_state = CS_CONNECTED;
421 break; 410 break;
422 case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: 411 case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL:
423 GNUNET_break (CS_RESOLVING == call_state); 412 GNUNET_break (CS_RESOLVING == call_state);
424 FPRINTF (stdout, 413 fprintf (stdout, _ ("Failed to resolve `%s'\n"), peer_name);
425 _("Failed to resolve `%s'\n"),
426 peer_name);
427 GNUNET_free (peer_name); 414 GNUNET_free (peer_name);
428 peer_name = NULL; 415 peer_name = NULL;
429 call = NULL; 416 call = NULL;
430 break; 417 break;
431 case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: 418 case GNUNET_CONVERSATION_EC_CALL_HUNG_UP:
432 FPRINTF (stdout, 419 fprintf (stdout, _ ("Call to `%s' terminated\n"), peer_name);
433 _("Call to `%s' terminated\n"),
434 peer_name);
435 GNUNET_free (peer_name); 420 GNUNET_free (peer_name);
436 peer_name = NULL; 421 peer_name = NULL;
437 call = NULL; 422 call = NULL;
438 break; 423 break;
439 case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: 424 case GNUNET_CONVERSATION_EC_CALL_SUSPENDED:
440 GNUNET_break (CS_CONNECTED == call_state); 425 GNUNET_break (CS_CONNECTED == call_state);
441 FPRINTF (stdout, 426 fprintf (stdout,
442 _("Connection to `%s' suspended (by other user)\n"), 427 _ ("Connection to `%s' suspended (by other user)\n"),
443 peer_name); 428 peer_name);
444 break; 429 break;
445 case GNUNET_CONVERSATION_EC_CALL_RESUMED: 430 case GNUNET_CONVERSATION_EC_CALL_RESUMED:
446 GNUNET_break (CS_CONNECTED == call_state); 431 GNUNET_break (CS_CONNECTED == call_state);
447 FPRINTF (stdout, 432 fprintf (stdout,
448 _("Connection to `%s' resumed (by other user)\n"), 433 _ ("Connection to `%s' resumed (by other user)\n"),
449 peer_name); 434 peer_name);
450 break; 435 break;
451 case GNUNET_CONVERSATION_EC_CALL_ERROR: 436 case GNUNET_CONVERSATION_EC_CALL_ERROR:
452 FPRINTF (stdout, 437 fprintf (stdout, _ ("Error with the call, restarting it\n"));
453 _("Error with the call, restarting it\n"));
454 GNUNET_free (peer_name); 438 GNUNET_free (peer_name);
455 peer_name = NULL; 439 peer_name = NULL;
456 call = NULL; 440 call = NULL;
@@ -464,8 +448,7 @@ call_event_handler (void *cls,
464 * 448 *
465 * @param arguments arguments given to the function 449 * @param arguments arguments given to the function
466 */ 450 */
467typedef void 451typedef void (*ActionFunction) (const char *arguments);
468(*ActionFunction) (const char *arguments);
469 452
470 453
471/** 454/**
@@ -520,9 +503,7 @@ do_quit (const char *args)
520static void 503static void
521do_unknown (const char *msg) 504do_unknown (const char *msg)
522{ 505{
523 FPRINTF (stderr, 506 fprintf (stderr, _ ("Unknown command `%s'\n"), msg);
524 _("Unknown command `%s'\n"),
525 msg);
526} 507}
527 508
528 509
@@ -536,31 +517,29 @@ do_call (const char *arg)
536{ 517{
537 if (NULL == my_caller_id) 518 if (NULL == my_caller_id)
538 { 519 {
539 FPRINTF (stderr, 520 fprintf (stderr, _ ("Ego `%s' not available\n"), ego_name);
540 _("Ego `%s' not available\n"),
541 ego_name);
542 return; 521 return;
543 } 522 }
544 if (NULL != call) 523 if (NULL != call)
545 { 524 {
546 FPRINTF (stderr, 525 fprintf (stderr,
547 _("You are calling someone else already, hang up first!\n")); 526 _ ("You are calling someone else already, hang up first!\n"));
548 return; 527 return;
549 } 528 }
550 switch (phone_state) 529 switch (phone_state)
551 { 530 {
552 case PS_LOOKUP_EGO: 531 case PS_LOOKUP_EGO:
553 FPRINTF (stderr, 532 fprintf (stderr, _ ("Ego `%s' not available\n"), ego_name);
554 _("Ego `%s' not available\n"),
555 ego_name);
556 return; 533 return;
557 case PS_LISTEN: 534 case PS_LISTEN:
558 /* ok to call! */ 535 /* ok to call! */
559 break; 536 break;
560 case PS_ACCEPTED: 537 case PS_ACCEPTED:
561 FPRINTF (stderr, 538 fprintf (
562 _("You are answering call from `%s', hang up or suspend that call first!\n"), 539 stderr,
563 GNUNET_GNSRECORD_pkey_to_zkey (&peer_key)); 540 _ (
541 "You are answering call from `%s', hang up or suspend that call first!\n"),
542 GNUNET_GNSRECORD_pkey_to_zkey (&peer_key));
564 return; 543 return;
565 case PS_ERROR: 544 case PS_ERROR:
566 /* ok to call */ 545 /* ok to call */
@@ -568,8 +547,7 @@ do_call (const char *arg)
568 } 547 }
569 if (NULL == arg) 548 if (NULL == arg)
570 { 549 {
571 FPRINTF (stderr, 550 fprintf (stderr, _ ("Call recipient missing.\n"));
572 _("Call recipient missing.\n"));
573 do_help ("/call"); 551 do_help ("/call");
574 return; 552 return;
575 } 553 }
@@ -581,7 +559,8 @@ do_call (const char *arg)
581 arg, 559 arg,
582 speaker, 560 speaker,
583 mic, 561 mic,
584 &call_event_handler, NULL); 562 &call_event_handler,
563 NULL);
585} 564}
586 565
587 566
@@ -596,11 +575,10 @@ do_accept (const char *args)
596 struct CallList *cl; 575 struct CallList *cl;
597 char buf[32]; 576 char buf[32];
598 577
599 if ( (NULL != call) && 578 if ((NULL != call) && (CS_SUSPENDED != call_state))
600 (CS_SUSPENDED != call_state) )
601 { 579 {
602 FPRINTF (stderr, 580 fprintf (stderr,
603 _("You are calling someone else already, hang up first!\n")); 581 _ ("You are calling someone else already, hang up first!\n"));
604 return; 582 return;
605 } 583 }
606 switch (phone_state) 584 switch (phone_state)
@@ -612,9 +590,11 @@ do_accept (const char *args)
612 /* this is the expected state */ 590 /* this is the expected state */
613 break; 591 break;
614 case PS_ACCEPTED: 592 case PS_ACCEPTED:
615 FPRINTF (stderr, 593 fprintf (
616 _("You are answering call from `%s', hang up or suspend that call first!\n"), 594 stderr,
617 GNUNET_GNSRECORD_pkey_to_zkey (&peer_key)); 595 _ (
596 "You are answering call from `%s', hang up or suspend that call first!\n"),
597 GNUNET_GNSRECORD_pkey_to_zkey (&peer_key));
618 return; 598 return;
619 case PS_ERROR: 599 case PS_ERROR:
620 GNUNET_break (0); 600 GNUNET_break (0);
@@ -623,31 +603,26 @@ do_accept (const char *args)
623 cl = cl_head; 603 cl = cl_head;
624 if (NULL == cl) 604 if (NULL == cl)
625 { 605 {
626 FPRINTF (stderr, 606 fprintf (stderr, _ ("There is no incoming call to accept here!\n"));
627 _("There is no incoming call to accept here!\n"));
628 return; 607 return;
629 } 608 }
630 if ( (NULL != cl->next) || (NULL != args) ) 609 if ((NULL != cl->next) || (NULL != args))
631 { 610 {
632 for (cl = cl_head; NULL != cl; cl = cl->next) 611 for (cl = cl_head; NULL != cl; cl = cl->next)
633 { 612 {
634 GNUNET_snprintf (buf, sizeof (buf), 613 GNUNET_snprintf (buf, sizeof (buf), "%u", cl->caller_num);
635 "%u",
636 cl->caller_num);
637 if (0 == strcmp (buf, args)) 614 if (0 == strcmp (buf, args))
638 break; 615 break;
639 } 616 }
640 } 617 }
641 if (NULL == cl) 618 if (NULL == cl)
642 { 619 {
643 FPRINTF (stderr, 620 fprintf (stderr,
644 _("There is no incoming call `%s' to accept right now!\n"), 621 _ ("There is no incoming call `%s' to accept right now!\n"),
645 args); 622 args);
646 return; 623 return;
647 } 624 }
648 GNUNET_CONTAINER_DLL_remove (cl_head, 625 GNUNET_CONTAINER_DLL_remove (cl_head, cl_tail, cl);
649 cl_tail,
650 cl);
651 cl_active = cl; 626 cl_active = cl;
652 peer_key = cl->caller_id; 627 peer_key = cl->caller_id;
653 phone_state = PS_ACCEPTED; 628 phone_state = PS_ACCEPTED;
@@ -670,14 +645,10 @@ do_address (const char *args)
670 (void) args; 645 (void) args;
671 if (NULL == address) 646 if (NULL == address)
672 { 647 {
673 FPRINTF (stdout, 648 fprintf (stdout, "%s", _ ("We currently do not have an address.\n"));
674 "%s",
675 _("We currently do not have an address.\n"));
676 return; 649 return;
677 } 650 }
678 FPRINTF (stdout, 651 fprintf (stdout, "%s\n", address);
679 "%s\n",
680 address);
681} 652}
682 653
683 654
@@ -695,24 +666,30 @@ do_status (const char *args)
695 switch (phone_state) 666 switch (phone_state)
696 { 667 {
697 case PS_LOOKUP_EGO: 668 case PS_LOOKUP_EGO:
698 FPRINTF (stdout, 669 fprintf (
699 _("We are currently trying to locate the private key for the ego `%s'.\n"), 670 stdout,
700 ego_name); 671 _ (
672 "We are currently trying to locate the private key for the ego `%s'.\n"),
673 ego_name);
701 break; 674 break;
702 case PS_LISTEN: 675 case PS_LISTEN:
703 FPRINTF (stdout, 676 fprintf (stdout,
704 _("We are listening for incoming calls for ego `%s' on line `%s'.\n"), 677 _ (
678 "We are listening for incoming calls for ego `%s' on line `%s'.\n"),
705 ego_name, 679 ego_name,
706 line); 680 line);
707 break; 681 break;
708 case PS_ACCEPTED: 682 case PS_ACCEPTED:
709 FPRINTF (stdout, 683 fprintf (stdout,
710 _("You are having a conversation with `%s'.\n"), 684 _ ("You are having a conversation with `%s'.\n"),
711 GNUNET_GNSRECORD_pkey_to_zkey (&peer_key));; 685 GNUNET_GNSRECORD_pkey_to_zkey (&peer_key));
686 ;
712 break; 687 break;
713 case PS_ERROR: 688 case PS_ERROR:
714 FPRINTF (stdout, 689 fprintf (
715 _("We had an internal error setting up our phone line. You can still make calls.\n")); 690 stdout,
691 _ (
692 "We had an internal error setting up our phone line. You can still make calls.\n"));
716 break; 693 break;
717 } 694 }
718 if (NULL != call) 695 if (NULL != call)
@@ -720,18 +697,18 @@ do_status (const char *args)
720 switch (call_state) 697 switch (call_state)
721 { 698 {
722 case CS_RESOLVING: 699 case CS_RESOLVING:
723 FPRINTF (stdout, 700 fprintf (stdout,
724 _("We are trying to find the network address to call `%s'.\n"), 701 _ ("We are trying to find the network address to call `%s'.\n"),
725 peer_name); 702 peer_name);
726 break; 703 break;
727 case CS_RINGING: 704 case CS_RINGING:
728 FPRINTF (stdout, 705 fprintf (stdout,
729 _("We are calling `%s', their phone should be ringing.\n"), 706 _ ("We are calling `%s', their phone should be ringing.\n"),
730 peer_name); 707 peer_name);
731 break; 708 break;
732 case CS_CONNECTED: 709 case CS_CONNECTED:
733 FPRINTF (stdout, 710 fprintf (stdout,
734 _("You are having a conversation with `%s'.\n"), 711 _ ("You are having a conversation with `%s'.\n"),
735 peer_name); 712 peer_name);
736 break; 713 break;
737 case CS_SUSPENDED: 714 case CS_SUSPENDED:
@@ -739,25 +716,19 @@ do_status (const char *args)
739 break; 716 break;
740 } 717 }
741 } 718 }
742 if ( (NULL != cl_head) && 719 if ((NULL != cl_head) && ((cl_head != cl_active) || (cl_head != cl_tail)))
743 ( (cl_head != cl_active) ||
744 (cl_head != cl_tail) ) )
745 { 720 {
746 FPRINTF (stdout, 721 fprintf (stdout, "%s", _ ("Calls waiting:\n"));
747 "%s",
748 _("Calls waiting:\n"));
749 for (cl = cl_head; NULL != cl; cl = cl->next) 722 for (cl = cl_head; NULL != cl; cl = cl->next)
750 { 723 {
751 if (cl == cl_active) 724 if (cl == cl_active)
752 continue; 725 continue;
753 FPRINTF (stdout, 726 fprintf (stdout,
754 _("#%u: `%s'\n"), 727 _ ("#%u: `%s'\n"),
755 cl->caller_num, 728 cl->caller_num,
756 GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id)); 729 GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id));
757 } 730 }
758 FPRINTF (stdout, 731 fprintf (stdout, "%s", "\n");
759 "%s",
760 "\n");
761 } 732 }
762} 733}
763 734
@@ -778,9 +749,9 @@ do_suspend (const char *args)
778 case CS_RESOLVING: 749 case CS_RESOLVING:
779 case CS_RINGING: 750 case CS_RINGING:
780 case CS_SUSPENDED: 751 case CS_SUSPENDED:
781 FPRINTF (stderr, 752 fprintf (stderr,
782 "%s", 753 "%s",
783 _("There is no call that could be suspended right now.\n")); 754 _ ("There is no call that could be suspended right now.\n"));
784 return; 755 return;
785 case CS_CONNECTED: 756 case CS_CONNECTED:
786 call_state = CS_SUSPENDED; 757 call_state = CS_SUSPENDED;
@@ -793,9 +764,9 @@ do_suspend (const char *args)
793 case PS_LOOKUP_EGO: 764 case PS_LOOKUP_EGO:
794 case PS_LISTEN: 765 case PS_LISTEN:
795 case PS_ERROR: 766 case PS_ERROR:
796 FPRINTF (stderr, 767 fprintf (stderr,
797 "%s", 768 "%s",
798 _("There is no call that could be suspended right now.\n")); 769 _ ("There is no call that could be suspended right now.\n"));
799 return; 770 return;
800 case PS_ACCEPTED: 771 case PS_ACCEPTED:
801 /* expected state, do rejection logic */ 772 /* expected state, do rejection logic */
@@ -826,15 +797,13 @@ do_resume (const char *args)
826 case CS_RESOLVING: 797 case CS_RESOLVING:
827 case CS_RINGING: 798 case CS_RINGING:
828 case CS_CONNECTED: 799 case CS_CONNECTED:
829 FPRINTF (stderr, 800 fprintf (stderr,
830 "%s", 801 "%s",
831 _("There is no call that could be resumed right now.\n")); 802 _ ("There is no call that could be resumed right now.\n"));
832 return; 803 return;
833 case CS_SUSPENDED: 804 case CS_SUSPENDED:
834 call_state = CS_CONNECTED; 805 call_state = CS_CONNECTED;
835 GNUNET_CONVERSATION_call_resume (call, 806 GNUNET_CONVERSATION_call_resume (call, speaker, mic);
836 speaker,
837 mic);
838 return; 807 return;
839 } 808 }
840 } 809 }
@@ -842,16 +811,16 @@ do_resume (const char *args)
842 { 811 {
843 case PS_LOOKUP_EGO: 812 case PS_LOOKUP_EGO:
844 case PS_ERROR: 813 case PS_ERROR:
845 FPRINTF (stderr, 814 fprintf (stderr,
846 "%s", 815 "%s",
847 _("There is no call that could be resumed right now.\n")); 816 _ ("There is no call that could be resumed right now.\n"));
848 return; 817 return;
849 case PS_LISTEN: 818 case PS_LISTEN:
850 /* expected state, do resume logic */ 819 /* expected state, do resume logic */
851 break; 820 break;
852 case PS_ACCEPTED: 821 case PS_ACCEPTED:
853 FPRINTF (stderr, 822 fprintf (stderr,
854 _("Already talking with `%s', cannot resume a call right now.\n"), 823 _ ("Already talking with `%s', cannot resume a call right now.\n"),
855 GNUNET_GNSRECORD_pkey_to_zkey (&peer_key)); 824 GNUNET_GNSRECORD_pkey_to_zkey (&peer_key));
856 return; 825 return;
857 } 826 }
@@ -859,32 +828,27 @@ do_resume (const char *args)
859 cl = cl_head; 828 cl = cl_head;
860 if (NULL == cl) 829 if (NULL == cl)
861 { 830 {
862 FPRINTF (stderr, 831 fprintf (stderr, _ ("There is no incoming call to resume here!\n"));
863 _("There is no incoming call to resume here!\n"));
864 return; 832 return;
865 } 833 }
866 if ( (NULL != cl->next) || (NULL != args) ) 834 if ((NULL != cl->next) || (NULL != args))
867 { 835 {
868 for (cl = cl_head; NULL != cl; cl = cl->next) 836 for (cl = cl_head; NULL != cl; cl = cl->next)
869 { 837 {
870 GNUNET_snprintf (buf, sizeof (buf), 838 GNUNET_snprintf (buf, sizeof (buf), "%u", cl->caller_num);
871 "%u",
872 cl->caller_num);
873 if (0 == strcmp (buf, args)) 839 if (0 == strcmp (buf, args))
874 break; 840 break;
875 } 841 }
876 } 842 }
877 if (NULL == cl) 843 if (NULL == cl)
878 { 844 {
879 FPRINTF (stderr, 845 fprintf (stderr,
880 _("There is no incoming call `%s' to resume right now!\n"), 846 _ ("There is no incoming call `%s' to resume right now!\n"),
881 args); 847 args);
882 return; 848 return;
883 } 849 }
884 cl_active = cl; 850 cl_active = cl;
885 GNUNET_CONVERSATION_caller_resume (cl_active->caller, 851 GNUNET_CONVERSATION_caller_resume (cl_active->caller, speaker, mic);
886 speaker,
887 mic);
888 phone_state = PS_ACCEPTED; 852 phone_state = PS_ACCEPTED;
889} 853}
890 854
@@ -910,41 +874,36 @@ do_reject (const char *args)
910 { 874 {
911 case PS_LOOKUP_EGO: 875 case PS_LOOKUP_EGO:
912 case PS_ERROR: 876 case PS_ERROR:
913 FPRINTF (stderr, 877 fprintf (stderr,
914 "%s", 878 "%s",
915 _("There is no call that could be cancelled right now.\n")); 879 _ ("There is no call that could be cancelled right now.\n"));
916 return; 880 return;
917 case PS_LISTEN: 881 case PS_LISTEN:
918 /* look for active incoming calls to refuse */ 882 /* look for active incoming calls to refuse */
919 cl = cl_head; 883 cl = cl_head;
920 if (NULL == cl) 884 if (NULL == cl)
921 { 885 {
922 FPRINTF (stderr, 886 fprintf (stderr, _ ("There is no incoming call to refuse here!\n"));
923 _("There is no incoming call to refuse here!\n"));
924 return; 887 return;
925 } 888 }
926 if ( (NULL != cl->next) || (NULL != args) ) 889 if ((NULL != cl->next) || (NULL != args))
927 { 890 {
928 for (cl = cl_head; NULL != cl; cl = cl->next) 891 for (cl = cl_head; NULL != cl; cl = cl->next)
929 { 892 {
930 GNUNET_snprintf (buf, sizeof (buf), 893 GNUNET_snprintf (buf, sizeof (buf), "%u", cl->caller_num);
931 "%u",
932 cl->caller_num);
933 if (0 == strcmp (buf, args)) 894 if (0 == strcmp (buf, args))
934 break; 895 break;
935 } 896 }
936 } 897 }
937 if (NULL == cl) 898 if (NULL == cl)
938 { 899 {
939 FPRINTF (stderr, 900 fprintf (stderr,
940 _("There is no incoming call `%s' to refuse right now!\n"), 901 _ ("There is no incoming call `%s' to refuse right now!\n"),
941 args); 902 args);
942 return; 903 return;
943 } 904 }
944 GNUNET_CONVERSATION_caller_hang_up (cl->caller); 905 GNUNET_CONVERSATION_caller_hang_up (cl->caller);
945 GNUNET_CONTAINER_DLL_remove (cl_head, 906 GNUNET_CONTAINER_DLL_remove (cl_head, cl_tail, cl);
946 cl_tail,
947 cl);
948 GNUNET_free (cl); 907 GNUNET_free (cl);
949 break; 908 break;
950 case PS_ACCEPTED: 909 case PS_ACCEPTED:
@@ -962,26 +921,34 @@ do_reject (const char *args)
962 * List of supported commands. 921 * List of supported commands.
963 */ 922 */
964static struct VoipCommand commands[] = { 923static struct VoipCommand commands[] = {
965 {"/address", &do_address, 924 {"/address",
966 gettext_noop ("Use `/address' to find out which address this phone should have in GNS")}, 925 &do_address,
967 {"/call", &do_call, 926 gettext_noop (
968 gettext_noop ("Use `/call USER.gnu' to call USER")}, 927 "Use `/address' to find out which address this phone should have in GNS")},
969 {"/accept", &do_accept, 928 {"/call", &do_call, gettext_noop ("Use `/call USER.gnu' to call USER")},
929 {"/accept",
930 &do_accept,
970 gettext_noop ("Use `/accept #NUM' to accept incoming call #NUM")}, 931 gettext_noop ("Use `/accept #NUM' to accept incoming call #NUM")},
971 {"/suspend", &do_suspend, 932 {"/suspend",
933 &do_suspend,
972 gettext_noop ("Use `/suspend' to suspend the active call")}, 934 gettext_noop ("Use `/suspend' to suspend the active call")},
973 {"/resume", &do_resume, 935 {"/resume",
974 gettext_noop ("Use `/resume [#NUM]' to resume a call, #NUM is needed to resume incoming calls, no argument is needed to resume the current outgoing call.")}, 936 &do_resume,
975 {"/cancel", &do_reject, 937 gettext_noop (
938 "Use `/resume [#NUM]' to resume a call, #NUM is needed to resume incoming calls, no argument is needed to resume the current outgoing call.")},
939 {"/cancel",
940 &do_reject,
976 gettext_noop ("Use `/cancel' to reject or terminate a call")}, 941 gettext_noop ("Use `/cancel' to reject or terminate a call")},
977 {"/status", &do_status, 942 {"/status",
943 &do_status,
978 gettext_noop ("Use `/status' to print status information")}, 944 gettext_noop ("Use `/status' to print status information")},
979 {"/quit", &do_quit, 945 {"/quit",
946 &do_quit,
980 gettext_noop ("Use `/quit' to terminate gnunet-conversation")}, 947 gettext_noop ("Use `/quit' to terminate gnunet-conversation")},
981 {"/help", &do_help, 948 {"/help",
949 &do_help,
982 gettext_noop ("Use `/help command' to get help for a specific command")}, 950 gettext_noop ("Use `/help command' to get help for a specific command")},
983 {"", &do_unknown, 951 {"", &do_unknown, NULL},
984 NULL},
985 {NULL, NULL, NULL}, 952 {NULL, NULL, NULL},
986}; 953};
987 954
@@ -997,37 +964,25 @@ do_help (const char *args)
997 unsigned int i; 964 unsigned int i;
998 965
999 i = 0; 966 i = 0;
1000 while ( (NULL != args) && 967 while ((NULL != args) && (0 != strlen (args)) &&
1001 (0 != strlen (args)) && 968 (commands[i].Action != &do_help))
1002 (commands[i].Action != &do_help))
1003 { 969 {
1004 if (0 == 970 if (0 == strncasecmp (&args[1], &commands[i].command[1], strlen (args) - 1))
1005 strncasecmp (&args[1], &commands[i].command[1], strlen (args) - 1))
1006 { 971 {
1007 FPRINTF (stdout, 972 fprintf (stdout, "%s\n", gettext (commands[i].helptext));
1008 "%s\n",
1009 gettext (commands[i].helptext));
1010 return; 973 return;
1011 } 974 }
1012 i++; 975 i++;
1013 } 976 }
1014 i = 0; 977 i = 0;
1015 FPRINTF (stdout, 978 fprintf (stdout, "%s", "Available commands:\n");
1016 "%s",
1017 "Available commands:\n");
1018 while (commands[i].Action != &do_help) 979 while (commands[i].Action != &do_help)
1019 { 980 {
1020 FPRINTF (stdout, 981 fprintf (stdout, "%s\n", gettext (commands[i].command));
1021 "%s\n",
1022 gettext (commands[i].command));
1023 i++; 982 i++;
1024 } 983 }
1025 FPRINTF (stdout, 984 fprintf (stdout, "%s", "\n");
1026 "%s", 985 fprintf (stdout, "%s\n", gettext (commands[i].helptext));
1027 "\n");
1028 FPRINTF (stdout,
1029 "%s\n",
1030 gettext (commands[i].helptext));
1031} 986}
1032 987
1033 988
@@ -1086,8 +1041,7 @@ do_stop_task (void *cls)
1086 * @param str_len number of bytes to process in @a message 1041 * @param str_len number of bytes to process in @a message
1087 */ 1042 */
1088static void 1043static void
1089handle_command_string (char *message, 1044handle_command_string (char *message, size_t str_len)
1090 size_t str_len)
1091{ 1045{
1092 size_t i; 1046 size_t i;
1093 const char *ptr; 1047 const char *ptr;
@@ -1101,9 +1055,10 @@ handle_command_string (char *message,
1101 if (0 == strlen (message)) 1055 if (0 == strlen (message))
1102 return; 1056 return;
1103 i = 0; 1057 i = 0;
1104 while ((NULL != commands[i].command) && 1058 while (
1105 (0 != strncasecmp (commands[i].command, message, 1059 (NULL != commands[i].command) &&
1106 strlen (commands[i].command)))) 1060 (0 !=
1061 strncasecmp (commands[i].command, message, strlen (commands[i].command))))
1107 i++; 1062 i++;
1108 ptr = &message[strlen (commands[i].command)]; 1063 ptr = &message[strlen (commands[i].command)];
1109 while (isspace ((unsigned char) *ptr)) 1064 while (isspace ((unsigned char) *ptr))
@@ -1159,17 +1114,13 @@ handle_command (void *cls)
1159 handle_cmd_task = 1114 handle_cmd_task =
1160 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 1115 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
1161 stdin_fh, 1116 stdin_fh,
1162 &handle_command, NULL); 1117 &handle_command,
1118 NULL);
1163 /* read message from command line and handle it */ 1119 /* read message from command line and handle it */
1164 memset (message, 1120 memset (message, 0, MAX_MESSAGE_LENGTH + 1);
1165 0, 1121 if (NULL == fgets (message, MAX_MESSAGE_LENGTH, stdin))
1166 MAX_MESSAGE_LENGTH + 1);
1167 if (NULL == fgets (message,
1168 MAX_MESSAGE_LENGTH,
1169 stdin))
1170 return; 1122 return;
1171 handle_command_string (message, 1123 handle_command_string (message, strlen (message));
1172 strlen (message));
1173} 1124}
1174 1125
1175 1126
@@ -1194,30 +1145,22 @@ identity_cb (void *cls,
1194 if (ego == my_caller_id) 1145 if (ego == my_caller_id)
1195 { 1146 {
1196 if (verbose) 1147 if (verbose)
1197 FPRINTF (stdout, 1148 fprintf (stdout, _ ("Name of our ego changed to `%s'\n"), name);
1198 _("Name of our ego changed to `%s'\n"),
1199 name);
1200 GNUNET_free (ego_name); 1149 GNUNET_free (ego_name);
1201 ego_name = GNUNET_strdup (name); 1150 ego_name = GNUNET_strdup (name);
1202 return; 1151 return;
1203 } 1152 }
1204 if (0 != strcmp (name, 1153 if (0 != strcmp (name, ego_name))
1205 ego_name))
1206 return; 1154 return;
1207 if (NULL == ego) 1155 if (NULL == ego)
1208 { 1156 {
1209 if (verbose) 1157 if (verbose)
1210 FPRINTF (stdout, 1158 fprintf (stdout, _ ("Our ego `%s' was deleted!\n"), ego_name);
1211 _("Our ego `%s' was deleted!\n"),
1212 ego_name);
1213 my_caller_id = NULL; 1159 my_caller_id = NULL;
1214 return; 1160 return;
1215 } 1161 }
1216 my_caller_id = ego; 1162 my_caller_id = ego;
1217 GNUNET_CONFIGURATION_set_value_string (cfg, 1163 GNUNET_CONFIGURATION_set_value_string (cfg, "CONVERSATION", "LINE", line);
1218 "CONVERSATION",
1219 "LINE",
1220 line);
1221 start_phone (); 1164 start_phone ();
1222} 1165}
1223 1166
@@ -1244,43 +1187,39 @@ run (void *cls,
1244 mic = GNUNET_MICROPHONE_create_from_hardware (cfg); 1187 mic = GNUNET_MICROPHONE_create_from_hardware (cfg);
1245 if (NULL == ego_name) 1188 if (NULL == ego_name)
1246 { 1189 {
1247 FPRINTF (stderr, 1190 fprintf (stderr, "%s", _ ("You must specify the NAME of an ego to use\n"));
1248 "%s",
1249 _("You must specify the NAME of an ego to use\n"));
1250 return; 1191 return;
1251 } 1192 }
1252 id = GNUNET_IDENTITY_connect (cfg, 1193 id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL);
1253 &identity_cb,
1254 NULL);
1255#ifdef WINDOWS 1194#ifdef WINDOWS
1256 if (stdin_fh == NULL) 1195 if (stdin_fh == NULL)
1257 { 1196 {
1258 static char cpid[64]; 1197 static char cpid[64];
1259 static char *args[] = {"gnunet-helper-w32-console.exe", "chars", 1198 static char *args[] = {"gnunet-helper-w32-console.exe",
1260 XSTRINGIFY (MAX_MESSAGE_LENGTH), cpid, NULL}; 1199 "chars",
1200 XSTRINGIFY (MAX_MESSAGE_LENGTH),
1201 cpid,
1202 NULL};
1261 snprintf (cpid, 64, "%d", GetCurrentProcessId ()); 1203 snprintf (cpid, 64, "%d", GetCurrentProcessId ());
1262 stdin_hlp = GNUNET_HELPER_start ( 1204 stdin_hlp = GNUNET_HELPER_start (GNUNET_NO,
1263 GNUNET_NO, 1205 "gnunet-helper-w32-console",
1264 "gnunet-helper-w32-console", 1206 args,
1265 args, 1207 console_reader_chars,
1266 console_reader_chars, 1208 NULL,
1267 NULL, 1209 NULL);
1268 NULL);
1269 if (NULL == stdin_hlp) 1210 if (NULL == stdin_hlp)
1270 { 1211 {
1271 FPRINTF (stderr, 1212 fprintf (stderr, "%s", _ ("Failed to start gnunet-helper-w32-console\n"));
1272 "%s",
1273 _("Failed to start gnunet-helper-w32-console\n"));
1274 return; 1213 return;
1275 } 1214 }
1276 } 1215 }
1277 else 1216 else
1278#endif 1217#endif
1279 handle_cmd_task = 1218 handle_cmd_task =
1280 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, 1219 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI,
1281 &handle_command, NULL); 1220 &handle_command,
1282 GNUNET_SCHEDULER_add_shutdown (&do_stop_task, 1221 NULL);
1283 NULL); 1222 GNUNET_SCHEDULER_add_shutdown (&do_stop_task, NULL);
1284} 1223}
1285 1224
1286 1225
@@ -1292,30 +1231,29 @@ run (void *cls,
1292 * @return 0 ok, 1 on error 1231 * @return 0 ok, 1 on error
1293 */ 1232 */
1294int 1233int
1295main (int argc, 1234main (int argc, char *const *argv)
1296 char *const *argv)
1297{ 1235{
1298 struct GNUNET_GETOPT_CommandLineOption options[] = { 1236 struct GNUNET_GETOPT_CommandLineOption options[] =
1299 GNUNET_GETOPT_option_string ('e', 1237 {GNUNET_GETOPT_option_string (
1300 "ego", 1238 'e',
1301 "NAME", 1239 "ego",
1302 gettext_noop ("sets the NAME of the ego to use for the caller ID"), 1240 "NAME",
1303 &ego_name), 1241 gettext_noop ("sets the NAME of the ego to use for the caller ID"),
1304 GNUNET_GETOPT_option_string ('p', 1242 &ego_name),
1305 "phone", 1243 GNUNET_GETOPT_option_string ('p',
1306 "LINE", 1244 "phone",
1307 gettext_noop ("sets the LINE to use for the phone"), 1245 "LINE",
1308 &line), 1246 gettext_noop (
1309 GNUNET_GETOPT_OPTION_END 1247 "sets the LINE to use for the phone"),
1310 }; 1248 &line),
1249 GNUNET_GETOPT_OPTION_END};
1311 int ret; 1250 int ret;
1312#ifndef WINDOWS 1251#ifndef WINDOWS
1313 int flags; 1252 int flags;
1314 flags = fcntl (0, F_GETFL, 0); 1253 flags = fcntl (0, F_GETFL, 0);
1315 flags |= O_NONBLOCK; 1254 flags |= O_NONBLOCK;
1316 if (0 != fcntl (0, F_SETFL, flags)) 1255 if (0 != fcntl (0, F_SETFL, flags))
1317 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 1256 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl");
1318 "fcntl");
1319 stdin_fh = GNUNET_DISK_get_handle_from_int_fd (0); 1257 stdin_fh = GNUNET_DISK_get_handle_from_int_fd (0);
1320#else 1258#else
1321 if (FILE_TYPE_CHAR == GetFileType ((HANDLE) _get_osfhandle (0))) 1259 if (FILE_TYPE_CHAR == GetFileType ((HANDLE) _get_osfhandle (0)))
@@ -1326,16 +1264,17 @@ main (int argc,
1326 stdin_fh = GNUNET_DISK_get_handle_from_int_fd (0); 1264 stdin_fh = GNUNET_DISK_get_handle_from_int_fd (0);
1327#endif 1265#endif
1328 1266
1329 if (GNUNET_OK != 1267 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1330 GNUNET_STRINGS_get_utf8_args (argc, argv,
1331 &argc, &argv))
1332 return 2; 1268 return 2;
1333 ret = GNUNET_PROGRAM_run (argc, 1269 ret =
1334 argv, 1270 GNUNET_PROGRAM_run (argc,
1335 "gnunet-conversation", 1271 argv,
1336 gettext_noop ("Enables having a conversation with other GNUnet users."), 1272 "gnunet-conversation",
1337 options, 1273 gettext_noop (
1338 &run, NULL); 1274 "Enables having a conversation with other GNUnet users."),
1275 options,
1276 &run,
1277 NULL);
1339 GNUNET_free ((void *) argv); 1278 GNUNET_free ((void *) argv);
1340 if (NULL != cfg) 1279 if (NULL != cfg)
1341 { 1280 {
diff --git a/src/core/gnunet-core.c b/src/core/gnunet-core.c
index 674da705a..aeb3ba61f 100644
--- a/src/core/gnunet-core.c
+++ b/src/core/gnunet-core.c
@@ -108,7 +108,7 @@ monitor_cb (void *cls,
108 case GNUNET_CORE_KX_ITERATION_FINISHED: 108 case GNUNET_CORE_KX_ITERATION_FINISHED:
109 return; 109 return;
110 case GNUNET_CORE_KX_CORE_DISCONNECT: 110 case GNUNET_CORE_KX_CORE_DISCONNECT:
111 FPRINTF (stderr, 111 fprintf (stderr,
112 "%s\n", 112 "%s\n",
113 _ ("Connection to CORE service lost (reconnecting)")); 113 _ ("Connection to CORE service lost (reconnecting)"));
114 return; 114 return;
@@ -117,7 +117,7 @@ monitor_cb (void *cls,
117 break; 117 break;
118 } 118 }
119 now_str = GNUNET_STRINGS_absolute_time_to_string (now); 119 now_str = GNUNET_STRINGS_absolute_time_to_string (now);
120 FPRINTF (stdout, 120 fprintf (stdout,
121 _ ("%24s: %-30s %4s (timeout in %6s)\n"), 121 _ ("%24s: %-30s %4s (timeout in %6s)\n"),
122 now_str, 122 now_str,
123 state_str, 123 state_str,
@@ -146,13 +146,13 @@ run (void *cls,
146 (void) cfgfile; 146 (void) cfgfile;
147 if (NULL != args[0]) 147 if (NULL != args[0])
148 { 148 {
149 FPRINTF (stderr, _ ("Invalid command line argument `%s'\n"), args[0]); 149 fprintf (stderr, _ ("Invalid command line argument `%s'\n"), args[0]);
150 return; 150 return;
151 } 151 }
152 mh = GNUNET_CORE_monitor_start (cfg, &monitor_cb, NULL); 152 mh = GNUNET_CORE_monitor_start (cfg, &monitor_cb, NULL);
153 if (NULL == mh) 153 if (NULL == mh)
154 { 154 {
155 FPRINTF (stderr, "%s", _ ("Failed to connect to CORE service!\n")); 155 fprintf (stderr, "%s", _ ("Failed to connect to CORE service!\n"));
156 return; 156 return;
157 } 157 }
158 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); 158 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
diff --git a/src/core/test_core_api_reliability.c b/src/core/test_core_api_reliability.c
index a2f7c0cf0..7bd4bfea0 100644
--- a/src/core/test_core_api_reliability.c
+++ b/src/core/test_core_api_reliability.c
@@ -147,7 +147,7 @@ do_shutdown (void *cls)
147 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; 147 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us;
148 if (0 == delta) 148 if (0 == delta)
149 delta = 1; 149 delta = 1;
150 FPRINTF (stderr, 150 fprintf (stderr,
151 "\nThroughput was %llu kb/s\n", 151 "\nThroughput was %llu kb/s\n",
152 total_bytes * 1000000LL / 1024 / delta); 152 total_bytes * 1000000LL / 1024 / delta);
153 GAUGER ("CORE", 153 GAUGER ("CORE",
@@ -301,7 +301,7 @@ handle_test (void *cls,
301 (unsigned int) ntohs (hdr->header.size)); 301 (unsigned int) ntohs (hdr->header.size));
302 n++; 302 n++;
303 if (0 == (n % (TOTAL_MSGS / 100))) 303 if (0 == (n % (TOTAL_MSGS / 100)))
304 FPRINTF (stderr, 304 fprintf (stderr,
305 "%s", 305 "%s",
306 "."); 306 ".");
307 if (n == TOTAL_MSGS) 307 if (n == TOTAL_MSGS)
diff --git a/src/core/test_core_api_start_only.c b/src/core/test_core_api_start_only.c
index 03edffe8e..92574e3d4 100644
--- a/src/core/test_core_api_start_only.c
+++ b/src/core/test_core_api_start_only.c
@@ -135,7 +135,7 @@ setup_peer (struct PeerContext *p,
135static void 135static void
136timeout_task (void *cls) 136timeout_task (void *cls)
137{ 137{
138 FPRINTF (stderr, 138 fprintf (stderr,
139 "%s", 139 "%s",
140 "Timeout.\n"); 140 "Timeout.\n");
141 if (NULL != p1.ch) 141 if (NULL != p1.ch)
diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c
index c661ff3e5..908d90ac3 100644
--- a/src/core/test_core_quota_compliance.c
+++ b/src/core/test_core_quota_compliance.c
@@ -225,7 +225,7 @@ measurement_stop (void *cls)
225 enum GNUNET_ErrorType kind = GNUNET_ERROR_TYPE_DEBUG; 225 enum GNUNET_ErrorType kind = GNUNET_ERROR_TYPE_DEBUG;
226 226
227 measure_task = NULL; 227 measure_task = NULL;
228 FPRINTF (stdout, "%s", "\n"); 228 fprintf (stdout, "%s", "\n");
229 running = GNUNET_NO; 229 running = GNUNET_NO;
230 230
231 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; 231 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us;
@@ -451,7 +451,7 @@ handle_test (void *cls,
451 ntohl (hdr->num)); 451 ntohl (hdr->num));
452 n++; 452 n++;
453 if (0 == (n % 10)) 453 if (0 == (n % 10))
454 FPRINTF (stderr, "%s", "."); 454 fprintf (stderr, "%s", ".");
455 455
456 if (GNUNET_YES == running) 456 if (GNUNET_YES == running)
457 do_transmit (NULL); 457 do_transmit (NULL);
diff --git a/src/datacache/datacache.c b/src/datacache/datacache.c
index 7dcd54fcf..57e0b0bb7 100644
--- a/src/datacache/datacache.c
+++ b/src/datacache/datacache.c
@@ -29,9 +29,10 @@
29#include "gnunet_datacache_plugin.h" 29#include "gnunet_datacache_plugin.h"
30 30
31 31
32#define LOG(kind,...) GNUNET_log_from (kind, "datacache", __VA_ARGS__) 32#define LOG(kind, ...) GNUNET_log_from (kind, "datacache", __VA_ARGS__)
33 33
34#define LOG_STRERROR_FILE(kind,op,fn) GNUNET_log_from_strerror_file (kind, "datacache", op, fn) 34#define LOG_STRERROR_FILE(kind, op, fn) \
35 GNUNET_log_from_strerror_file (kind, "datacache", op, fn)
35 36
36/** 37/**
37 * Internal state of the datacache library. 38 * Internal state of the datacache library.
@@ -89,7 +90,6 @@ struct GNUNET_DATACACHE_Handle
89 * How much space is in use right now? 90 * How much space is in use right now?
90 */ 91 */
91 unsigned long long utilization; 92 unsigned long long utilization;
92
93}; 93};
94 94
95 95
@@ -102,9 +102,7 @@ struct GNUNET_DATACACHE_Handle
102 * @param size number of bytes that were made available 102 * @param size number of bytes that were made available
103 */ 103 */
104static void 104static void
105env_delete_notify (void *cls, 105env_delete_notify (void *cls, const struct GNUNET_HashCode *key, size_t size)
106 const struct GNUNET_HashCode *key,
107 size_t size)
108{ 106{
109 struct GNUNET_DATACACHE_Handle *h = cls; 107 struct GNUNET_DATACACHE_Handle *h = cls;
110 108
@@ -113,11 +111,10 @@ env_delete_notify (void *cls,
113 GNUNET_h2s (key)); 111 GNUNET_h2s (key));
114 GNUNET_assert (h->utilization >= size); 112 GNUNET_assert (h->utilization >= size);
115 h->utilization -= size; 113 h->utilization -= size;
116 GNUNET_CONTAINER_bloomfilter_remove (h->filter, 114 GNUNET_CONTAINER_bloomfilter_remove (h->filter, key);
117 key);
118 GNUNET_STATISTICS_update (h->stats, 115 GNUNET_STATISTICS_update (h->stats,
119 gettext_noop ("# bytes stored"), 116 gettext_noop ("# bytes stored"),
120 - (long long) size, 117 -(long long) size,
121 GNUNET_NO); 118 GNUNET_NO);
122 GNUNET_STATISTICS_update (h->stats, 119 GNUNET_STATISTICS_update (h->stats,
123 gettext_noop ("# items stored"), 120 gettext_noop ("# items stored"),
@@ -144,54 +141,42 @@ GNUNET_DATACACHE_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
144 char *name; 141 char *name;
145 142
146 if (GNUNET_OK != 143 if (GNUNET_OK !=
147 GNUNET_CONFIGURATION_get_value_size (cfg, 144 GNUNET_CONFIGURATION_get_value_size (cfg, section, "QUOTA", &quota))
148 section,
149 "QUOTA",
150 &quota))
151 { 145 {
152 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 146 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, section, "QUOTA");
153 section,
154 "QUOTA");
155 return NULL; 147 return NULL;
156 } 148 }
157 if (GNUNET_OK != 149 if (GNUNET_OK !=
158 GNUNET_CONFIGURATION_get_value_string (cfg, 150 GNUNET_CONFIGURATION_get_value_string (cfg, section, "DATABASE", &name))
159 section,
160 "DATABASE",
161 &name))
162 { 151 {
163 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 152 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, section, "DATABASE");
164 section,
165 "DATABASE");
166 return NULL; 153 return NULL;
167 } 154 }
168 bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */ 155 bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */
169 156
170 ret = GNUNET_new (struct GNUNET_DATACACHE_Handle); 157 ret = GNUNET_new (struct GNUNET_DATACACHE_Handle);
171 158
172 if (GNUNET_YES != 159 if (GNUNET_YES !=
173 GNUNET_CONFIGURATION_get_value_yesno (cfg, 160 GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "DISABLE_BF"))
174 section,
175 "DISABLE_BF"))
176 { 161 {
177 if (GNUNET_YES != 162 if (GNUNET_YES !=
178 GNUNET_CONFIGURATION_get_value_yesno (cfg, 163 GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "DISABLE_BF_RC"))
179 section,
180 "DISABLE_BF_RC"))
181 { 164 {
182 ret->bloom_name = GNUNET_DISK_mktemp ("gnunet-datacachebloom"); 165 ret->bloom_name = GNUNET_DISK_mktemp ("gnunet-datacachebloom");
183 } 166 }
184 if (NULL != ret->bloom_name) 167 if (NULL != ret->bloom_name)
185 { 168 {
186 ret->filter = GNUNET_CONTAINER_bloomfilter_load (ret->bloom_name, 169 ret->filter = GNUNET_CONTAINER_bloomfilter_load (
187 quota / 1024, /* 8 bit per entry in DB, expect 1k entries */ 170 ret->bloom_name,
188 5); 171 quota / 1024, /* 8 bit per entry in DB, expect 1k entries */
172 5);
189 } 173 }
190 if (NULL == ret->filter) 174 if (NULL == ret->filter)
191 { 175 {
192 ret->filter = GNUNET_CONTAINER_bloomfilter_init (NULL, 176 ret->filter =
193 bf_size, 177 GNUNET_CONTAINER_bloomfilter_init (NULL,
194 5); /* approx. 3% false positives at max use */ 178 bf_size,
179 5); /* approx. 3% false positives at max use */
195 } 180 }
196 } 181 }
197 ret->stats = GNUNET_STATISTICS_create ("datacache", cfg); 182 ret->stats = GNUNET_STATISTICS_create ("datacache", cfg);
@@ -202,19 +187,15 @@ GNUNET_DATACACHE_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
202 ret->env.cls = ret; 187 ret->env.cls = ret;
203 ret->env.delete_notify = &env_delete_notify; 188 ret->env.delete_notify = &env_delete_notify;
204 ret->env.quota = quota; 189 ret->env.quota = quota;
205 LOG (GNUNET_ERROR_TYPE_INFO, 190 LOG (GNUNET_ERROR_TYPE_INFO, _ ("Loading `%s' datacache plugin\n"), name);
206 _("Loading `%s' datacache plugin\n"), 191 GNUNET_asprintf (&libname, "libgnunet_plugin_datacache_%s", name);
207 name);
208 GNUNET_asprintf (&libname,
209 "libgnunet_plugin_datacache_%s",
210 name);
211 ret->short_name = name; 192 ret->short_name = name;
212 ret->lib_name = libname; 193 ret->lib_name = libname;
213 ret->api = GNUNET_PLUGIN_load (libname, &ret->env); 194 ret->api = GNUNET_PLUGIN_load (libname, &ret->env);
214 if (ret->api == NULL) 195 if (ret->api == NULL)
215 { 196 {
216 LOG (GNUNET_ERROR_TYPE_ERROR, 197 LOG (GNUNET_ERROR_TYPE_ERROR,
217 _("Failed to load datacache plugin for `%s'\n"), 198 _ ("Failed to load datacache plugin for `%s'\n"),
218 name); 199 name);
219 GNUNET_DATACACHE_destroy (ret); 200 GNUNET_DATACACHE_destroy (ret);
220 return NULL; 201 return NULL;
@@ -234,23 +215,20 @@ GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h)
234 if (NULL != h->filter) 215 if (NULL != h->filter)
235 GNUNET_CONTAINER_bloomfilter_free (h->filter); 216 GNUNET_CONTAINER_bloomfilter_free (h->filter);
236 if (NULL != h->api) 217 if (NULL != h->api)
237 GNUNET_break (NULL == 218 GNUNET_break (NULL == GNUNET_PLUGIN_unload (h->lib_name, h->api));
238 GNUNET_PLUGIN_unload (h->lib_name,
239 h->api));
240 GNUNET_free (h->lib_name); 219 GNUNET_free (h->lib_name);
241 GNUNET_free (h->short_name); 220 GNUNET_free (h->short_name);
242 GNUNET_free (h->section); 221 GNUNET_free (h->section);
243 if (NULL != h->bloom_name) 222 if (NULL != h->bloom_name)
244 { 223 {
245 if (0 != UNLINK (h->bloom_name)) 224 if (0 != unlink (h->bloom_name))
246 GNUNET_log_from_strerror_file (GNUNET_ERROR_TYPE_WARNING, 225 GNUNET_log_from_strerror_file (GNUNET_ERROR_TYPE_WARNING,
247 "datacache", 226 "datacache",
248 "unlink", 227 "unlink",
249 h->bloom_name); 228 h->bloom_name);
250 GNUNET_free (h->bloom_name); 229 GNUNET_free (h->bloom_name);
251 } 230 }
252 GNUNET_STATISTICS_destroy (h->stats, 231 GNUNET_STATISTICS_destroy (h->stats, GNUNET_NO);
253 GNUNET_NO);
254 GNUNET_free (h); 232 GNUNET_free (h);
255} 233}
256 234
@@ -277,19 +255,19 @@ GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
277 const char *data, 255 const char *data,
278 enum GNUNET_BLOCK_Type type, 256 enum GNUNET_BLOCK_Type type,
279 struct GNUNET_TIME_Absolute discard_time, 257 struct GNUNET_TIME_Absolute discard_time,
280 unsigned int path_info_len, 258 unsigned int path_info_len,
281 const struct GNUNET_PeerIdentity *path_info) 259 const struct GNUNET_PeerIdentity *path_info)
282{ 260{
283 ssize_t used; 261 ssize_t used;
284 262
285 used = h->api->put (h->api->cls, 263 used = h->api->put (h->api->cls,
286 key, 264 key,
287 xor_distance, 265 xor_distance,
288 data_size, 266 data_size,
289 data, 267 data,
290 type, 268 type,
291 discard_time, 269 discard_time,
292 path_info_len, 270 path_info_len,
293 path_info); 271 path_info);
294 if (-1 == used) 272 if (-1 == used)
295 { 273 {
@@ -305,8 +283,7 @@ GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
305 "Stored data under key `%s' in cache\n", 283 "Stored data under key `%s' in cache\n",
306 GNUNET_h2s (key)); 284 GNUNET_h2s (key));
307 if (NULL != h->filter) 285 if (NULL != h->filter)
308 GNUNET_CONTAINER_bloomfilter_add (h->filter, 286 GNUNET_CONTAINER_bloomfilter_add (h->filter, key);
309 key);
310 GNUNET_STATISTICS_update (h->stats, 287 GNUNET_STATISTICS_update (h->stats,
311 gettext_noop ("# bytes stored"), 288 gettext_noop ("# bytes stored"),
312 used, 289 used,
@@ -316,8 +293,7 @@ GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
316 1, 293 1,
317 GNUNET_NO); 294 GNUNET_NO);
318 while (h->utilization + used > h->env.quota) 295 while (h->utilization + used > h->env.quota)
319 GNUNET_assert (GNUNET_OK == 296 GNUNET_assert (GNUNET_OK == h->api->del (h->api->cls));
320 h->api->del (h->api->cls));
321 h->utilization += used; 297 h->utilization += used;
322 return GNUNET_OK; 298 return GNUNET_OK;
323} 299}
@@ -348,23 +324,20 @@ GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h,
348 LOG (GNUNET_ERROR_TYPE_DEBUG, 324 LOG (GNUNET_ERROR_TYPE_DEBUG,
349 "Processing request for key `%s'\n", 325 "Processing request for key `%s'\n",
350 GNUNET_h2s (key)); 326 GNUNET_h2s (key));
351 if ( (NULL != h->filter) && 327 if ((NULL != h->filter) &&
352 (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_test (h->filter, key)) ) 328 (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_test (h->filter, key)))
353 { 329 {
354 GNUNET_STATISTICS_update (h->stats, 330 GNUNET_STATISTICS_update (h->stats,
355 gettext_noop ("# requests filtered by bloom filter"), 331 gettext_noop (
332 "# requests filtered by bloom filter"),
356 1, 333 1,
357 GNUNET_NO); 334 GNUNET_NO);
358 LOG (GNUNET_ERROR_TYPE_DEBUG, 335 LOG (GNUNET_ERROR_TYPE_DEBUG,
359 "Bloomfilter filters request for key `%s'\n", 336 "Bloomfilter filters request for key `%s'\n",
360 GNUNET_h2s (key)); 337 GNUNET_h2s (key));
361 return 0; /* can not be present */ 338 return 0; /* can not be present */
362 } 339 }
363 return h->api->get (h->api->cls, 340 return h->api->get (h->api->cls, key, type, iter, iter_cls);
364 key,
365 type,
366 iter,
367 iter_cls);
368} 341}
369 342
370 343
@@ -382,14 +355,12 @@ GNUNET_DATACACHE_get_random (struct GNUNET_DATACACHE_Handle *h,
382 void *iter_cls) 355 void *iter_cls)
383{ 356{
384 GNUNET_STATISTICS_update (h->stats, 357 GNUNET_STATISTICS_update (h->stats,
385 gettext_noop ("# requests for random value received"), 358 gettext_noop (
359 "# requests for random value received"),
386 1, 360 1,
387 GNUNET_NO); 361 GNUNET_NO);
388 LOG (GNUNET_ERROR_TYPE_DEBUG, 362 LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing request for random value\n");
389 "Processing request for random value\n"); 363 return h->api->get_random (h->api->cls, iter, iter_cls);
390 return h->api->get_random (h->api->cls,
391 iter,
392 iter_cls);
393} 364}
394 365
395 366
@@ -414,17 +385,14 @@ GNUNET_DATACACHE_get_closest (struct GNUNET_DATACACHE_Handle *h,
414 void *iter_cls) 385 void *iter_cls)
415{ 386{
416 GNUNET_STATISTICS_update (h->stats, 387 GNUNET_STATISTICS_update (h->stats,
417 gettext_noop ("# proximity search requests received"), 388 gettext_noop (
389 "# proximity search requests received"),
418 1, 390 1,
419 GNUNET_NO); 391 GNUNET_NO);
420 LOG (GNUNET_ERROR_TYPE_DEBUG, 392 LOG (GNUNET_ERROR_TYPE_DEBUG,
421 "Processing proximity search at `%s'\n", 393 "Processing proximity search at `%s'\n",
422 GNUNET_h2s (key)); 394 GNUNET_h2s (key));
423 return h->api->get_closest (h->api->cls, 395 return h->api->get_closest (h->api->cls, key, num_results, iter, iter_cls);
424 key,
425 num_results,
426 iter,
427 iter_cls);
428} 396}
429 397
430 398
diff --git a/src/datacache/perf_datacache.c b/src/datacache/perf_datacache.c
index 4381171c5..1dfb46cf1 100644
--- a/src/datacache/perf_datacache.c
+++ b/src/datacache/perf_datacache.c
@@ -74,7 +74,7 @@ run (void *cls, char *const *args, const char *cfgfile,
74 74
75 if (h == NULL) 75 if (h == NULL)
76 { 76 {
77 FPRINTF (stderr, "%s", "Failed to initialize datacache. Database likely not setup, skipping test.\n"); 77 fprintf (stderr, "%s", "Failed to initialize datacache. Database likely not setup, skipping test.\n");
78 ok = 77; /* mark test as skipped */ 78 ok = 77; /* mark test as skipped */
79 return; 79 return;
80 } 80 }
@@ -84,7 +84,7 @@ run (void *cls, char *const *args, const char *cfgfile,
84 for (i = 0; i < ITERATIONS; i++) 84 for (i = 0; i < ITERATIONS; i++)
85 { 85 {
86 if (0 == i % (ITERATIONS / 80)) 86 if (0 == i % (ITERATIONS / 80))
87 FPRINTF (stderr, "%s", "."); 87 fprintf (stderr, "%s", ".");
88 GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n); 88 GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n);
89 ASSERT (GNUNET_OK == 89 ASSERT (GNUNET_OK ==
90 GNUNET_DATACACHE_put (h, &k, sizeof (struct GNUNET_HashCode), 90 GNUNET_DATACACHE_put (h, &k, sizeof (struct GNUNET_HashCode),
@@ -92,8 +92,8 @@ run (void *cls, char *const *args, const char *cfgfile,
92 0, NULL)); 92 0, NULL));
93 k = n; 93 k = n;
94 } 94 }
95 FPRINTF (stderr, "%s", "\n"); 95 fprintf (stderr, "%s", "\n");
96 FPRINTF (stdout, "Stored %u items in %s\n", ITERATIONS, 96 fprintf (stdout, "Stored %u items in %s\n", ITERATIONS,
97 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); 97 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES));
98 GNUNET_snprintf (gstr, sizeof (gstr), "DATACACHE-%s", plugin_name); 98 GNUNET_snprintf (gstr, sizeof (gstr), "DATACACHE-%s", plugin_name);
99 GAUGER (gstr, "Time to PUT item in datacache", 99 GAUGER (gstr, "Time to PUT item in datacache",
@@ -104,13 +104,13 @@ run (void *cls, char *const *args, const char *cfgfile,
104 for (i = 0; i < ITERATIONS; i++) 104 for (i = 0; i < ITERATIONS; i++)
105 { 105 {
106 if (0 == i % (ITERATIONS / 80)) 106 if (0 == i % (ITERATIONS / 80))
107 FPRINTF (stderr, "%s", "."); 107 fprintf (stderr, "%s", ".");
108 GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n); 108 GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n);
109 GNUNET_DATACACHE_get (h, &k, 1 + i % 16, &checkIt, &n); 109 GNUNET_DATACACHE_get (h, &k, 1 + i % 16, &checkIt, &n);
110 k = n; 110 k = n;
111 } 111 }
112 FPRINTF (stderr, "%s", "\n"); 112 fprintf (stderr, "%s", "\n");
113 FPRINTF (stdout, 113 fprintf (stdout,
114 "Found %u/%u items in %s (%u were deleted during storage processing)\n", 114 "Found %u/%u items in %s (%u were deleted during storage processing)\n",
115 found, ITERATIONS, 115 found, ITERATIONS,
116 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES), 116 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES),
@@ -152,7 +152,7 @@ main (int argc, char *argv[])
152 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, 152 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv,
153 "perf-datacache", "nohelp", options, &run, NULL); 153 "perf-datacache", "nohelp", options, &run, NULL);
154 if ( (0 != ok) && (77 != ok) ) 154 if ( (0 != ok) && (77 != ok) )
155 FPRINTF (stderr, "Missed some perfcases: %d\n", ok); 155 fprintf (stderr, "Missed some perfcases: %d\n", ok);
156 return ok; 156 return ok;
157} 157}
158 158
diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c
index 07a72957a..0cf77d6e6 100644
--- a/src/datacache/plugin_datacache_sqlite.c
+++ b/src/datacache/plugin_datacache_sqlite.c
@@ -29,16 +29,17 @@
29#include "gnunet_sq_lib.h" 29#include "gnunet_sq_lib.h"
30#include <sqlite3.h> 30#include <sqlite3.h>
31 31
32#define LOG(kind,...) GNUNET_log_from (kind, "datacache-sqlite", __VA_ARGS__) 32#define LOG(kind, ...) GNUNET_log_from (kind, "datacache-sqlite", __VA_ARGS__)
33 33
34#define LOG_STRERROR_FILE(kind,op,fn) GNUNET_log_from_strerror_file (kind, "datacache-sqlite", op, fn) 34#define LOG_STRERROR_FILE(kind, op, fn) \
35 GNUNET_log_from_strerror_file (kind, "datacache-sqlite", op, fn)
35 36
36 37
37/** 38/**
38 * How much overhead do we assume per entry in the 39 * How much overhead do we assume per entry in the
39 * datacache? 40 * datacache?
40 */ 41 */
41#define OVERHEAD (sizeof(struct GNUNET_HashCode) + 36) 42#define OVERHEAD (sizeof (struct GNUNET_HashCode) + 36)
42 43
43/** 44/**
44 * Context for all functions in this plugin. 45 * Context for all functions in this plugin.
@@ -115,7 +116,16 @@ struct Plugin
115 * @param level log level 116 * @param level log level
116 * @param cmd failed command 117 * @param cmd failed command
117 */ 118 */
118#define LOG_SQLITE(db, level, cmd) do { LOG (level, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db)); } while(0) 119#define LOG_SQLITE(db, level, cmd) \
120 do \
121 { \
122 LOG (level, \
123 _ ("`%s' failed at %s:%d with error: %s\n"), \
124 cmd, \
125 __FILE__, \
126 __LINE__, \
127 sqlite3_errmsg (db)); \
128 } while (0)
119 129
120 130
121/** 131/**
@@ -124,7 +134,21 @@ struct Plugin
124 * @param db database handle 134 * @param db database handle
125 * @param cmd SQL command to execute 135 * @param cmd SQL command to execute
126 */ 136 */
127#define SQLITE3_EXEC(db, cmd) do { emsg = NULL; if (SQLITE_OK != sqlite3_exec(db, cmd, NULL, NULL, &emsg)) { LOG (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_exec", __FILE__, __LINE__, emsg); sqlite3_free(emsg); } } while(0) 137#define SQLITE3_EXEC(db, cmd) \
138 do \
139 { \
140 emsg = NULL; \
141 if (SQLITE_OK != sqlite3_exec (db, cmd, NULL, NULL, &emsg)) \
142 { \
143 LOG (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, \
144 _ ("`%s' failed at %s:%d with error: %s\n"), \
145 "sqlite3_exec", \
146 __FILE__, \
147 __LINE__, \
148 emsg); \
149 sqlite3_free (emsg); \
150 } \
151 } while (0)
128 152
129 153
130/** 154/**
@@ -137,9 +161,9 @@ struct Plugin
137 */ 161 */
138static int 162static int
139sq_prepare (sqlite3 *dbh, 163sq_prepare (sqlite3 *dbh,
140 const char *zSql, /* SQL statement, UTF-8 encoded */ 164 const char *zSql, /* SQL statement, UTF-8 encoded */
141 sqlite3_stmt **ppStmt) 165 sqlite3_stmt **ppStmt)
142{ /* OUT: Statement handle */ 166{ /* OUT: Statement handle */
143 char *dummy; 167 char *dummy;
144 168
145 return sqlite3_prepare (dbh, 169 return sqlite3_prepare (dbh,
@@ -166,58 +190,53 @@ sq_prepare (sqlite3 *dbh,
166 */ 190 */
167static ssize_t 191static ssize_t
168sqlite_plugin_put (void *cls, 192sqlite_plugin_put (void *cls,
169 const struct GNUNET_HashCode *key, 193 const struct GNUNET_HashCode *key,
170 uint32_t xor_distance, 194 uint32_t xor_distance,
171 size_t size, 195 size_t size,
172 const char *data, 196 const char *data,
173 enum GNUNET_BLOCK_Type type, 197 enum GNUNET_BLOCK_Type type,
174 struct GNUNET_TIME_Absolute discard_time, 198 struct GNUNET_TIME_Absolute discard_time,
175 unsigned int path_info_len, 199 unsigned int path_info_len,
176 const struct GNUNET_PeerIdentity *path_info) 200 const struct GNUNET_PeerIdentity *path_info)
177{ 201{
178 struct Plugin *plugin = cls; 202 struct Plugin *plugin = cls;
179 uint32_t type32 = type; 203 uint32_t type32 = type;
180 struct GNUNET_SQ_QueryParam params[] = { 204 struct GNUNET_SQ_QueryParam params[] =
181 GNUNET_SQ_query_param_uint32 (&type32), 205 {GNUNET_SQ_query_param_uint32 (&type32),
182 GNUNET_SQ_query_param_absolute_time (&discard_time), 206 GNUNET_SQ_query_param_absolute_time (&discard_time),
183 GNUNET_SQ_query_param_auto_from_type (key), 207 GNUNET_SQ_query_param_auto_from_type (key),
184 GNUNET_SQ_query_param_uint32 (&xor_distance), 208 GNUNET_SQ_query_param_uint32 (&xor_distance),
185 GNUNET_SQ_query_param_fixed_size (data, size), 209 GNUNET_SQ_query_param_fixed_size (data, size),
186 GNUNET_SQ_query_param_fixed_size (path_info, 210 GNUNET_SQ_query_param_fixed_size (path_info,
187 path_info_len * sizeof (struct GNUNET_PeerIdentity)), 211 path_info_len *
188 GNUNET_SQ_query_param_end 212 sizeof (struct GNUNET_PeerIdentity)),
189 }; 213 GNUNET_SQ_query_param_end};
190 214
191 LOG (GNUNET_ERROR_TYPE_DEBUG, 215 LOG (GNUNET_ERROR_TYPE_DEBUG,
192 "Processing PUT of %u bytes with key `%s' and expiration %s\n", 216 "Processing PUT of %u bytes with key `%s' and expiration %s\n",
193 (unsigned int) size, 217 (unsigned int) size,
194 GNUNET_h2s (key), 218 GNUNET_h2s (key),
195 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (discard_time), 219 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (
220 discard_time),
196 GNUNET_YES)); 221 GNUNET_YES));
197 if (GNUNET_OK != 222 if (GNUNET_OK != GNUNET_SQ_bind (plugin->insert_stmt, params))
198 GNUNET_SQ_bind (plugin->insert_stmt,
199 params))
200 { 223 {
201 LOG_SQLITE (plugin->dbh, 224 LOG_SQLITE (plugin->dbh,
202 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 225 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
203 "sqlite3_bind_xxx"); 226 "sqlite3_bind_xxx");
204 GNUNET_SQ_reset (plugin->dbh, 227 GNUNET_SQ_reset (plugin->dbh, plugin->insert_stmt);
205 plugin->insert_stmt);
206 return -1; 228 return -1;
207 } 229 }
208 if (SQLITE_DONE != 230 if (SQLITE_DONE != sqlite3_step (plugin->insert_stmt))
209 sqlite3_step (plugin->insert_stmt))
210 { 231 {
211 LOG_SQLITE (plugin->dbh, 232 LOG_SQLITE (plugin->dbh,
212 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 233 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
213 "sqlite3_step"); 234 "sqlite3_step");
214 GNUNET_SQ_reset (plugin->dbh, 235 GNUNET_SQ_reset (plugin->dbh, plugin->insert_stmt);
215 plugin->insert_stmt);
216 return -1; 236 return -1;
217 } 237 }
218 plugin->num_items++; 238 plugin->num_items++;
219 GNUNET_SQ_reset (plugin->dbh, 239 GNUNET_SQ_reset (plugin->dbh, plugin->insert_stmt);
220 plugin->insert_stmt);
221 return size + OVERHEAD; 240 return size + OVERHEAD;
222} 241}
223 242
@@ -251,62 +270,50 @@ sqlite_plugin_get (void *cls,
251 unsigned int total; 270 unsigned int total;
252 size_t psize; 271 size_t psize;
253 struct GNUNET_PeerIdentity *path; 272 struct GNUNET_PeerIdentity *path;
254 struct GNUNET_SQ_QueryParam params_count[] = { 273 struct GNUNET_SQ_QueryParam params_count[] =
255 GNUNET_SQ_query_param_auto_from_type (key), 274 {GNUNET_SQ_query_param_auto_from_type (key),
256 GNUNET_SQ_query_param_uint32 (&type32), 275 GNUNET_SQ_query_param_uint32 (&type32),
257 GNUNET_SQ_query_param_absolute_time (&now), 276 GNUNET_SQ_query_param_absolute_time (&now),
258 GNUNET_SQ_query_param_end 277 GNUNET_SQ_query_param_end};
259 }; 278 struct GNUNET_SQ_QueryParam params_select[] =
260 struct GNUNET_SQ_QueryParam params_select[] = { 279 {GNUNET_SQ_query_param_auto_from_type (key),
261 GNUNET_SQ_query_param_auto_from_type (key), 280 GNUNET_SQ_query_param_uint32 (&type32),
262 GNUNET_SQ_query_param_uint32 (&type32), 281 GNUNET_SQ_query_param_absolute_time (&now),
263 GNUNET_SQ_query_param_absolute_time (&now), 282 GNUNET_SQ_query_param_uint32 (&off),
264 GNUNET_SQ_query_param_uint32 (&off), 283 GNUNET_SQ_query_param_end};
265 GNUNET_SQ_query_param_end 284 struct GNUNET_SQ_ResultSpec rs[] =
266 }; 285 {GNUNET_SQ_result_spec_variable_size (&dat, &size),
267 struct GNUNET_SQ_ResultSpec rs[] = { 286 GNUNET_SQ_result_spec_absolute_time (&exp),
268 GNUNET_SQ_result_spec_variable_size (&dat, 287 GNUNET_SQ_result_spec_variable_size ((void **) &path, &psize),
269 &size), 288 GNUNET_SQ_result_spec_end};
270 GNUNET_SQ_result_spec_absolute_time (&exp),
271 GNUNET_SQ_result_spec_variable_size ((void **) &path,
272 &psize),
273 GNUNET_SQ_result_spec_end
274 };
275 289
276 now = GNUNET_TIME_absolute_get (); 290 now = GNUNET_TIME_absolute_get ();
277 LOG (GNUNET_ERROR_TYPE_DEBUG, 291 LOG (GNUNET_ERROR_TYPE_DEBUG,
278 "Processing GET for key `%s'\n", 292 "Processing GET for key `%s'\n",
279 GNUNET_h2s (key)); 293 GNUNET_h2s (key));
280 294
281 if (GNUNET_OK != 295 if (GNUNET_OK != GNUNET_SQ_bind (plugin->get_count_stmt, params_count))
282 GNUNET_SQ_bind (plugin->get_count_stmt,
283 params_count))
284 { 296 {
285 LOG_SQLITE (plugin->dbh, 297 LOG_SQLITE (plugin->dbh,
286 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 298 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
287 "sqlite3_bind_xxx"); 299 "sqlite3_bind_xxx");
288 GNUNET_SQ_reset (plugin->dbh, 300 GNUNET_SQ_reset (plugin->dbh, plugin->get_count_stmt);
289 plugin->get_count_stmt);
290 return 0; 301 return 0;
291 } 302 }
292 if (SQLITE_ROW != 303 if (SQLITE_ROW != sqlite3_step (plugin->get_count_stmt))
293 sqlite3_step (plugin->get_count_stmt))
294 { 304 {
295 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 305 LOG_SQLITE (plugin->dbh,
306 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
296 "sqlite_step"); 307 "sqlite_step");
297 GNUNET_SQ_reset (plugin->dbh, 308 GNUNET_SQ_reset (plugin->dbh, plugin->get_count_stmt);
298 plugin->get_count_stmt);
299 LOG (GNUNET_ERROR_TYPE_DEBUG, 309 LOG (GNUNET_ERROR_TYPE_DEBUG,
300 "No content found when processing GET for key `%s'\n", 310 "No content found when processing GET for key `%s'\n",
301 GNUNET_h2s (key)); 311 GNUNET_h2s (key));
302 return 0; 312 return 0;
303 } 313 }
304 total = sqlite3_column_int (plugin->get_count_stmt, 314 total = sqlite3_column_int (plugin->get_count_stmt, 0);
305 0); 315 GNUNET_SQ_reset (plugin->dbh, plugin->get_count_stmt);
306 GNUNET_SQ_reset (plugin->dbh, 316 if ((0 == total) || (NULL == iter))
307 plugin->get_count_stmt);
308 if ( (0 == total) ||
309 (NULL == iter) )
310 { 317 {
311 if (0 == total) 318 if (0 == total)
312 LOG (GNUNET_ERROR_TYPE_DEBUG, 319 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -316,32 +323,24 @@ sqlite_plugin_get (void *cls,
316 } 323 }
317 324
318 cnt = 0; 325 cnt = 0;
319 off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 326 off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, total);
320 total);
321 while (cnt < total) 327 while (cnt < total)
322 { 328 {
323 off = (off + 1) % total; 329 off = (off + 1) % total;
324 if (GNUNET_OK != 330 if (GNUNET_OK != GNUNET_SQ_bind (plugin->get_stmt, params_select))
325 GNUNET_SQ_bind (plugin->get_stmt,
326 params_select))
327 { 331 {
328 LOG_SQLITE (plugin->dbh, 332 LOG_SQLITE (plugin->dbh,
329 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 333 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
330 "sqlite3_bind_xxx"); 334 "sqlite3_bind_xxx");
331 GNUNET_SQ_reset (plugin->dbh, 335 GNUNET_SQ_reset (plugin->dbh, plugin->get_stmt);
332 plugin->get_stmt);
333 return cnt; 336 return cnt;
334 } 337 }
335 if (SQLITE_ROW != 338 if (SQLITE_ROW != sqlite3_step (plugin->get_stmt))
336 sqlite3_step (plugin->get_stmt))
337 break; 339 break;
338 if (GNUNET_OK != 340 if (GNUNET_OK != GNUNET_SQ_extract_result (plugin->get_stmt, rs))
339 GNUNET_SQ_extract_result (plugin->get_stmt,
340 rs))
341 { 341 {
342 GNUNET_break (0); 342 GNUNET_break (0);
343 GNUNET_SQ_reset (plugin->dbh, 343 GNUNET_SQ_reset (plugin->dbh, plugin->get_stmt);
344 plugin->get_stmt);
345 break; 344 break;
346 } 345 }
347 if (0 != psize % sizeof (struct GNUNET_PeerIdentity)) 346 if (0 != psize % sizeof (struct GNUNET_PeerIdentity))
@@ -356,26 +355,16 @@ sqlite_plugin_get (void *cls,
356 "Found %u-byte result when processing GET for key `%s'\n", 355 "Found %u-byte result when processing GET for key `%s'\n",
357 (unsigned int) size, 356 (unsigned int) size,
358 GNUNET_h2s (key)); 357 GNUNET_h2s (key));
359 if (GNUNET_OK != iter (iter_cls, 358 if (GNUNET_OK != iter (iter_cls, key, size, dat, type, exp, psize, path))
360 key,
361 size,
362 dat,
363 type,
364 exp,
365 psize,
366 path))
367 { 359 {
368 GNUNET_SQ_cleanup_result (rs); 360 GNUNET_SQ_cleanup_result (rs);
369 GNUNET_SQ_reset (plugin->dbh, 361 GNUNET_SQ_reset (plugin->dbh, plugin->get_stmt);
370 plugin->get_stmt);
371 break; 362 break;
372 } 363 }
373 GNUNET_SQ_cleanup_result (rs); 364 GNUNET_SQ_cleanup_result (rs);
374 GNUNET_SQ_reset (plugin->dbh, 365 GNUNET_SQ_reset (plugin->dbh, plugin->get_stmt);
375 plugin->get_stmt);
376 } 366 }
377 GNUNET_SQ_reset (plugin->dbh, 367 GNUNET_SQ_reset (plugin->dbh, plugin->get_stmt);
378 plugin->get_stmt);
379 return cnt; 368 return cnt;
380} 369}
381 370
@@ -396,94 +385,66 @@ sqlite_plugin_del (void *cls)
396 size_t dsize; 385 size_t dsize;
397 struct GNUNET_HashCode hc; 386 struct GNUNET_HashCode hc;
398 struct GNUNET_TIME_Absolute now; 387 struct GNUNET_TIME_Absolute now;
399 struct GNUNET_SQ_ResultSpec rs[] = { 388 struct GNUNET_SQ_ResultSpec rs[] =
400 GNUNET_SQ_result_spec_uint64 (&rowid), 389 {GNUNET_SQ_result_spec_uint64 (&rowid),
401 GNUNET_SQ_result_spec_auto_from_type (&hc), 390 GNUNET_SQ_result_spec_auto_from_type (&hc),
402 GNUNET_SQ_result_spec_variable_size ((void **) &data, 391 GNUNET_SQ_result_spec_variable_size ((void **) &data, &dsize),
403 &dsize), 392 GNUNET_SQ_result_spec_end};
404 GNUNET_SQ_result_spec_end 393 struct GNUNET_SQ_QueryParam params[] = {GNUNET_SQ_query_param_uint64 (&rowid),
405 }; 394 GNUNET_SQ_query_param_end};
406 struct GNUNET_SQ_QueryParam params[] = { 395 struct GNUNET_SQ_QueryParam time_params[] =
407 GNUNET_SQ_query_param_uint64 (&rowid), 396 {GNUNET_SQ_query_param_absolute_time (&now), GNUNET_SQ_query_param_end};
408 GNUNET_SQ_query_param_end 397
409 }; 398 LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing DEL\n");
410 struct GNUNET_SQ_QueryParam time_params[] = {
411 GNUNET_SQ_query_param_absolute_time (&now),
412 GNUNET_SQ_query_param_end
413 };
414
415 LOG (GNUNET_ERROR_TYPE_DEBUG,
416 "Processing DEL\n");
417 now = GNUNET_TIME_absolute_get (); 399 now = GNUNET_TIME_absolute_get ();
418 if (GNUNET_OK != 400 if (GNUNET_OK != GNUNET_SQ_bind (plugin->del_expired_stmt, time_params))
419 GNUNET_SQ_bind (plugin->del_expired_stmt,
420 time_params))
421 { 401 {
422 LOG_SQLITE (plugin->dbh, 402 LOG_SQLITE (plugin->dbh,
423 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 403 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
424 "sqlite3_bind"); 404 "sqlite3_bind");
425 GNUNET_SQ_reset (plugin->dbh, 405 GNUNET_SQ_reset (plugin->dbh, plugin->del_expired_stmt);
426 plugin->del_expired_stmt);
427 return GNUNET_SYSERR; 406 return GNUNET_SYSERR;
428 } 407 }
429 if ( (SQLITE_ROW != 408 if ((SQLITE_ROW != sqlite3_step (plugin->del_expired_stmt)) ||
430 sqlite3_step (plugin->del_expired_stmt)) || 409 (GNUNET_OK != GNUNET_SQ_extract_result (plugin->del_expired_stmt, rs)))
431 (GNUNET_OK !=
432 GNUNET_SQ_extract_result (plugin->del_expired_stmt,
433 rs)) )
434 { 410 {
435 GNUNET_SQ_reset (plugin->dbh, 411 GNUNET_SQ_reset (plugin->dbh, plugin->del_expired_stmt);
436 plugin->del_expired_stmt); 412 if (SQLITE_ROW != sqlite3_step (plugin->del_select_stmt))
437 if (SQLITE_ROW !=
438 sqlite3_step (plugin->del_select_stmt))
439 { 413 {
440 LOG_SQLITE (plugin->dbh, 414 LOG_SQLITE (plugin->dbh,
441 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 415 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
442 "sqlite3_step"); 416 "sqlite3_step");
443 GNUNET_SQ_reset (plugin->dbh, 417 GNUNET_SQ_reset (plugin->dbh, plugin->del_select_stmt);
444 plugin->del_select_stmt);
445 return GNUNET_SYSERR; 418 return GNUNET_SYSERR;
446 } 419 }
447 if (GNUNET_OK != 420 if (GNUNET_OK != GNUNET_SQ_extract_result (plugin->del_select_stmt, rs))
448 GNUNET_SQ_extract_result (plugin->del_select_stmt,
449 rs))
450 { 421 {
451 GNUNET_SQ_reset (plugin->dbh, 422 GNUNET_SQ_reset (plugin->dbh, plugin->del_select_stmt);
452 plugin->del_select_stmt);
453 GNUNET_break (0); 423 GNUNET_break (0);
454 return GNUNET_SYSERR; 424 return GNUNET_SYSERR;
455 } 425 }
456 } 426 }
457 GNUNET_SQ_cleanup_result (rs); 427 GNUNET_SQ_cleanup_result (rs);
458 GNUNET_SQ_reset (plugin->dbh, 428 GNUNET_SQ_reset (plugin->dbh, plugin->del_select_stmt);
459 plugin->del_select_stmt); 429 if (GNUNET_OK != GNUNET_SQ_bind (plugin->del_stmt, params))
460 if (GNUNET_OK !=
461 GNUNET_SQ_bind (plugin->del_stmt,
462 params))
463 { 430 {
464 LOG_SQLITE (plugin->dbh, 431 LOG_SQLITE (plugin->dbh,
465 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 432 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
466 "sqlite3_bind"); 433 "sqlite3_bind");
467 GNUNET_SQ_reset (plugin->dbh, 434 GNUNET_SQ_reset (plugin->dbh, plugin->del_stmt);
468 plugin->del_stmt);
469 return GNUNET_SYSERR; 435 return GNUNET_SYSERR;
470 } 436 }
471 if (SQLITE_DONE != 437 if (SQLITE_DONE != sqlite3_step (plugin->del_stmt))
472 sqlite3_step (plugin->del_stmt))
473 { 438 {
474 LOG_SQLITE (plugin->dbh, 439 LOG_SQLITE (plugin->dbh,
475 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 440 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
476 "sqlite3_step"); 441 "sqlite3_step");
477 GNUNET_SQ_reset (plugin->dbh, 442 GNUNET_SQ_reset (plugin->dbh, plugin->del_stmt);
478 plugin->del_stmt);
479 return GNUNET_SYSERR; 443 return GNUNET_SYSERR;
480 } 444 }
481 plugin->num_items--; 445 plugin->num_items--;
482 plugin->env->delete_notify (plugin->env->cls, 446 plugin->env->delete_notify (plugin->env->cls, &hc, dsize + OVERHEAD);
483 &hc, 447 GNUNET_SQ_reset (plugin->dbh, plugin->del_stmt);
484 dsize + OVERHEAD);
485 GNUNET_SQ_reset (plugin->dbh,
486 plugin->del_stmt);
487 return GNUNET_OK; 448 return GNUNET_OK;
488} 449}
489 450
@@ -510,48 +471,36 @@ sqlite_plugin_get_random (void *cls,
510 uint32_t type; 471 uint32_t type;
511 struct GNUNET_PeerIdentity *path; 472 struct GNUNET_PeerIdentity *path;
512 struct GNUNET_HashCode key; 473 struct GNUNET_HashCode key;
513 struct GNUNET_SQ_QueryParam params[] = { 474 struct GNUNET_SQ_QueryParam params[] = {GNUNET_SQ_query_param_uint32 (&off),
514 GNUNET_SQ_query_param_uint32 (&off), 475 GNUNET_SQ_query_param_end};
515 GNUNET_SQ_query_param_end 476 struct GNUNET_SQ_ResultSpec rs[] =
516 }; 477 {GNUNET_SQ_result_spec_variable_size (&dat, &size),
517 struct GNUNET_SQ_ResultSpec rs[] = { 478 GNUNET_SQ_result_spec_absolute_time (&exp),
518 GNUNET_SQ_result_spec_variable_size (&dat, 479 GNUNET_SQ_result_spec_variable_size ((void **) &path, &psize),
519 &size), 480 GNUNET_SQ_result_spec_auto_from_type (&key),
520 GNUNET_SQ_result_spec_absolute_time (&exp), 481 GNUNET_SQ_result_spec_uint32 (&type),
521 GNUNET_SQ_result_spec_variable_size ((void **) &path, 482 GNUNET_SQ_result_spec_end};
522 &psize),
523 GNUNET_SQ_result_spec_auto_from_type (&key),
524 GNUNET_SQ_result_spec_uint32 (&type),
525 GNUNET_SQ_result_spec_end
526 };
527 483
528 if (0 == plugin->num_items) 484 if (0 == plugin->num_items)
529 return 0; 485 return 0;
530 if (NULL == iter) 486 if (NULL == iter)
531 return 1; 487 return 1;
532 off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 488 off =
533 plugin->num_items); 489 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, plugin->num_items);
534 if (GNUNET_OK != 490 if (GNUNET_OK != GNUNET_SQ_bind (plugin->get_random_stmt, params))
535 GNUNET_SQ_bind (plugin->get_random_stmt,
536 params))
537 { 491 {
538 return 0; 492 return 0;
539 } 493 }
540 if (SQLITE_ROW != 494 if (SQLITE_ROW != sqlite3_step (plugin->get_random_stmt))
541 sqlite3_step (plugin->get_random_stmt))
542 { 495 {
543 GNUNET_break (0); 496 GNUNET_break (0);
544 GNUNET_SQ_reset (plugin->dbh, 497 GNUNET_SQ_reset (plugin->dbh, plugin->get_random_stmt);
545 plugin->get_random_stmt);
546 return 0; 498 return 0;
547 } 499 }
548 if (GNUNET_OK != 500 if (GNUNET_OK != GNUNET_SQ_extract_result (plugin->get_random_stmt, rs))
549 GNUNET_SQ_extract_result (plugin->get_random_stmt,
550 rs))
551 { 501 {
552 GNUNET_break (0); 502 GNUNET_break (0);
553 GNUNET_SQ_reset (plugin->dbh, 503 GNUNET_SQ_reset (plugin->dbh, plugin->get_random_stmt);
554 plugin->get_random_stmt);
555 return 0; 504 return 0;
556 } 505 }
557 if (0 != psize % sizeof (struct GNUNET_PeerIdentity)) 506 if (0 != psize % sizeof (struct GNUNET_PeerIdentity))
@@ -574,8 +523,7 @@ sqlite_plugin_get_random (void *cls,
574 psize, 523 psize,
575 path); 524 path);
576 GNUNET_SQ_cleanup_result (rs); 525 GNUNET_SQ_cleanup_result (rs);
577 GNUNET_SQ_reset (plugin->dbh, 526 GNUNET_SQ_reset (plugin->dbh, plugin->get_random_stmt);
578 plugin->get_random_stmt);
579 return 1; 527 return 1;
580} 528}
581 529
@@ -611,45 +559,35 @@ sqlite_plugin_get_closest (void *cls,
611 uint32_t type; 559 uint32_t type;
612 struct GNUNET_HashCode hc; 560 struct GNUNET_HashCode hc;
613 struct GNUNET_PeerIdentity *path; 561 struct GNUNET_PeerIdentity *path;
614 struct GNUNET_SQ_QueryParam params[] = { 562 struct GNUNET_SQ_QueryParam params[] =
615 GNUNET_SQ_query_param_auto_from_type (key), 563 {GNUNET_SQ_query_param_auto_from_type (key),
616 GNUNET_SQ_query_param_absolute_time (&now), 564 GNUNET_SQ_query_param_absolute_time (&now),
617 GNUNET_SQ_query_param_uint32 (&num_results32), 565 GNUNET_SQ_query_param_uint32 (&num_results32),
618 GNUNET_SQ_query_param_end 566 GNUNET_SQ_query_param_end};
619 }; 567 struct GNUNET_SQ_ResultSpec rs[] =
620 struct GNUNET_SQ_ResultSpec rs[] = { 568 {GNUNET_SQ_result_spec_variable_size (&dat, &size),
621 GNUNET_SQ_result_spec_variable_size (&dat, 569 GNUNET_SQ_result_spec_absolute_time (&exp),
622 &size), 570 GNUNET_SQ_result_spec_variable_size ((void **) &path, &psize),
623 GNUNET_SQ_result_spec_absolute_time (&exp), 571 GNUNET_SQ_result_spec_uint32 (&type),
624 GNUNET_SQ_result_spec_variable_size ((void **) &path, 572 GNUNET_SQ_result_spec_auto_from_type (&hc),
625 &psize), 573 GNUNET_SQ_result_spec_end};
626 GNUNET_SQ_result_spec_uint32 (&type),
627 GNUNET_SQ_result_spec_auto_from_type (&hc),
628 GNUNET_SQ_result_spec_end
629 };
630 574
631 now = GNUNET_TIME_absolute_get (); 575 now = GNUNET_TIME_absolute_get ();
632 LOG (GNUNET_ERROR_TYPE_DEBUG, 576 LOG (GNUNET_ERROR_TYPE_DEBUG,
633 "Processing GET_CLOSEST for key `%s'\n", 577 "Processing GET_CLOSEST for key `%s'\n",
634 GNUNET_h2s (key)); 578 GNUNET_h2s (key));
635 if (GNUNET_OK != 579 if (GNUNET_OK != GNUNET_SQ_bind (plugin->get_closest_stmt, params))
636 GNUNET_SQ_bind (plugin->get_closest_stmt,
637 params))
638 { 580 {
639 LOG_SQLITE (plugin->dbh, 581 LOG_SQLITE (plugin->dbh,
640 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 582 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
641 "sqlite3_bind_xxx"); 583 "sqlite3_bind_xxx");
642 GNUNET_SQ_reset (plugin->dbh, 584 GNUNET_SQ_reset (plugin->dbh, plugin->get_closest_stmt);
643 plugin->get_closest_stmt);
644 return 0; 585 return 0;
645 } 586 }
646 cnt = 0; 587 cnt = 0;
647 while (SQLITE_ROW == 588 while (SQLITE_ROW == sqlite3_step (plugin->get_closest_stmt))
648 sqlite3_step (plugin->get_closest_stmt))
649 { 589 {
650 if (GNUNET_OK != 590 if (GNUNET_OK != GNUNET_SQ_extract_result (plugin->get_closest_stmt, rs))
651 GNUNET_SQ_extract_result (plugin->get_closest_stmt,
652 rs))
653 { 591 {
654 GNUNET_break (0); 592 GNUNET_break (0);
655 break; 593 break;
@@ -666,22 +604,14 @@ sqlite_plugin_get_closest (void *cls,
666 "Found %u-byte result at %s when processing GET_CLOSE\n", 604 "Found %u-byte result at %s when processing GET_CLOSE\n",
667 (unsigned int) size, 605 (unsigned int) size,
668 GNUNET_h2s (&hc)); 606 GNUNET_h2s (&hc));
669 if (GNUNET_OK != iter (iter_cls, 607 if (GNUNET_OK != iter (iter_cls, &hc, size, dat, type, exp, psize, path))
670 &hc,
671 size,
672 dat,
673 type,
674 exp,
675 psize,
676 path))
677 { 608 {
678 GNUNET_SQ_cleanup_result (rs); 609 GNUNET_SQ_cleanup_result (rs);
679 break; 610 break;
680 } 611 }
681 GNUNET_SQ_cleanup_result (rs); 612 GNUNET_SQ_cleanup_result (rs);
682 } 613 }
683 GNUNET_SQ_reset (plugin->dbh, 614 GNUNET_SQ_reset (plugin->dbh, plugin->get_closest_stmt);
684 plugin->get_closest_stmt);
685 return cnt; 615 return cnt;
686} 616}
687 617
@@ -703,10 +633,9 @@ libgnunet_plugin_datacache_sqlite_init (void *cls)
703 sqlite3 *dbh; 633 sqlite3 *dbh;
704 char *emsg; 634 char *emsg;
705 635
706 if (GNUNET_YES == 636 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
707 GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 637 "datacache-sqlite",
708 "datacache-sqlite", 638 "IN_MEMORY"))
709 "IN_MEMORY"))
710 { 639 {
711 if (SQLITE_OK != sqlite3_open (":memory:", &dbh)) 640 if (SQLITE_OK != sqlite3_open (":memory:", &dbh))
712 return NULL; 641 return NULL;
@@ -716,10 +645,10 @@ libgnunet_plugin_datacache_sqlite_init (void *cls)
716 { 645 {
717 fn = GNUNET_DISK_mktemp ("gnunet-datacache"); 646 fn = GNUNET_DISK_mktemp ("gnunet-datacache");
718 if (fn == NULL) 647 if (fn == NULL)
719 { 648 {
720 GNUNET_break (0); 649 GNUNET_break (0);
721 return NULL; 650 return NULL;
722 } 651 }
723 /* fn should be UTF-8-encoded. If it isn't, it's a bug. */ 652 /* fn should be UTF-8-encoded. If it isn't, it's a bug. */
724 fn_utf8 = GNUNET_strdup (fn); 653 fn_utf8 = GNUNET_strdup (fn);
725 if (SQLITE_OK != sqlite3_open (fn_utf8, &dbh)) 654 if (SQLITE_OK != sqlite3_open (fn_utf8, &dbh))
@@ -736,10 +665,9 @@ libgnunet_plugin_datacache_sqlite_init (void *cls)
736 SQLITE3_EXEC (dbh, "PRAGMA journal_mode=OFF"); 665 SQLITE3_EXEC (dbh, "PRAGMA journal_mode=OFF");
737 SQLITE3_EXEC (dbh, "PRAGMA synchronous=OFF"); 666 SQLITE3_EXEC (dbh, "PRAGMA synchronous=OFF");
738 SQLITE3_EXEC (dbh, "PRAGMA page_size=4092"); 667 SQLITE3_EXEC (dbh, "PRAGMA page_size=4092");
739 if (GNUNET_YES == 668 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
740 GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 669 "datacache-sqlite",
741 "datacache-sqlite", 670 "IN_MEMORY"))
742 "IN_MEMORY"))
743 SQLITE3_EXEC (dbh, "PRAGMA sqlite_temp_store=3"); 671 SQLITE3_EXEC (dbh, "PRAGMA sqlite_temp_store=3");
744 672
745 SQLITE3_EXEC (dbh, 673 SQLITE3_EXEC (dbh,
@@ -749,7 +677,7 @@ libgnunet_plugin_datacache_sqlite_init (void *cls)
749 " key BLOB NOT NULL DEFAULT ''," 677 " key BLOB NOT NULL DEFAULT '',"
750 " prox INTEGER NOT NULL," 678 " prox INTEGER NOT NULL,"
751 " value BLOB NOT NULL," 679 " value BLOB NOT NULL,"
752 " path BLOB DEFAULT '')"); 680 " path BLOB DEFAULT '')");
753 SQLITE3_EXEC (dbh, "CREATE INDEX idx_hashidx ON ds091 (key,type,expire)"); 681 SQLITE3_EXEC (dbh, "CREATE INDEX idx_hashidx ON ds091 (key,type,expire)");
754 SQLITE3_EXEC (dbh, "CREATE INDEX idx_prox_expire ON ds091 (prox,expire)"); 682 SQLITE3_EXEC (dbh, "CREATE INDEX idx_prox_expire ON ds091 (prox,expire)");
755 SQLITE3_EXEC (dbh, "CREATE INDEX idx_expire_only ON ds091 (expire)"); 683 SQLITE3_EXEC (dbh, "CREATE INDEX idx_expire_only ON ds091 (expire)");
@@ -758,53 +686,46 @@ libgnunet_plugin_datacache_sqlite_init (void *cls)
758 plugin->dbh = dbh; 686 plugin->dbh = dbh;
759 plugin->fn = fn_utf8; 687 plugin->fn = fn_utf8;
760 688
761 if ( (SQLITE_OK != 689 if ((SQLITE_OK !=
762 sq_prepare (plugin->dbh, 690 sq_prepare (plugin->dbh,
763 "INSERT INTO ds091 (type, expire, key, prox, value, path) " 691 "INSERT INTO ds091 (type, expire, key, prox, value, path) "
764 "VALUES (?, ?, ?, ?, ?, ?)", 692 "VALUES (?, ?, ?, ?, ?, ?)",
765 &plugin->insert_stmt)) || 693 &plugin->insert_stmt)) ||
766 (SQLITE_OK != 694 (SQLITE_OK != sq_prepare (plugin->dbh,
767 sq_prepare (plugin->dbh, 695 "SELECT count(*) FROM ds091 "
768 "SELECT count(*) FROM ds091 " 696 "WHERE key=? AND type=? AND expire >= ?",
769 "WHERE key=? AND type=? AND expire >= ?", 697 &plugin->get_count_stmt)) ||
770 &plugin->get_count_stmt)) || 698 (SQLITE_OK !=
771 (SQLITE_OK != 699 sq_prepare (plugin->dbh,
772 sq_prepare (plugin->dbh, 700 "SELECT value,expire,path FROM ds091"
773 "SELECT value,expire,path FROM ds091" 701 " WHERE key=? AND type=? AND expire >= ? LIMIT 1 OFFSET ?",
774 " WHERE key=? AND type=? AND expire >= ? LIMIT 1 OFFSET ?", 702 &plugin->get_stmt)) ||
775 &plugin->get_stmt)) || 703 (SQLITE_OK != sq_prepare (plugin->dbh,
776 (SQLITE_OK != 704 "SELECT _ROWID_,key,value FROM ds091"
777 sq_prepare (plugin->dbh, 705 " WHERE expire < ?"
778 "SELECT _ROWID_,key,value FROM ds091" 706 " ORDER BY expire ASC LIMIT 1",
779 " WHERE expire < ?" 707 &plugin->del_expired_stmt)) ||
780 " ORDER BY expire ASC LIMIT 1", 708 (SQLITE_OK != sq_prepare (plugin->dbh,
781 &plugin->del_expired_stmt)) || 709 "SELECT _ROWID_,key,value FROM ds091"
782 (SQLITE_OK != 710 " ORDER BY prox ASC, expire ASC LIMIT 1",
783 sq_prepare (plugin->dbh, 711 &plugin->del_select_stmt)) ||
784 "SELECT _ROWID_,key,value FROM ds091" 712 (SQLITE_OK != sq_prepare (plugin->dbh,
785 " ORDER BY prox ASC, expire ASC LIMIT 1", 713 "DELETE FROM ds091 WHERE _ROWID_=?",
786 &plugin->del_select_stmt)) || 714 &plugin->del_stmt)) ||
787 (SQLITE_OK != 715 (SQLITE_OK != sq_prepare (plugin->dbh,
788 sq_prepare (plugin->dbh, 716 "SELECT value,expire,path,key,type FROM ds091 "
789 "DELETE FROM ds091 WHERE _ROWID_=?", 717 "ORDER BY key LIMIT 1 OFFSET ?",
790 &plugin->del_stmt)) || 718 &plugin->get_random_stmt)) ||
791 (SQLITE_OK != 719 (SQLITE_OK !=
792 sq_prepare (plugin->dbh, 720 sq_prepare (plugin->dbh,
793 "SELECT value,expire,path,key,type FROM ds091 " 721 "SELECT value,expire,path,type,key FROM ds091 "
794 "ORDER BY key LIMIT 1 OFFSET ?", 722 "WHERE key>=? AND expire >= ? ORDER BY KEY ASC LIMIT ?",
795 &plugin->get_random_stmt)) || 723 &plugin->get_closest_stmt)))
796 (SQLITE_OK !=
797 sq_prepare (plugin->dbh,
798 "SELECT value,expire,path,type,key FROM ds091 "
799 "WHERE key>=? AND expire >= ? ORDER BY KEY ASC LIMIT ?",
800 &plugin->get_closest_stmt))
801 )
802 { 724 {
803 LOG_SQLITE (plugin->dbh, 725 LOG_SQLITE (plugin->dbh,
804 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 726 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
805 "sq_prepare"); 727 "sq_prepare");
806 GNUNET_break (SQLITE_OK == 728 GNUNET_break (SQLITE_OK == sqlite3_close (plugin->dbh));
807 sqlite3_close (plugin->dbh));
808 GNUNET_free (plugin); 729 GNUNET_free (plugin);
809 return NULL; 730 return NULL;
810 } 731 }
@@ -816,8 +737,7 @@ libgnunet_plugin_datacache_sqlite_init (void *cls)
816 api->del = &sqlite_plugin_del; 737 api->del = &sqlite_plugin_del;
817 api->get_random = &sqlite_plugin_get_random; 738 api->get_random = &sqlite_plugin_get_random;
818 api->get_closest = &sqlite_plugin_get_closest; 739 api->get_closest = &sqlite_plugin_get_closest;
819 LOG (GNUNET_ERROR_TYPE_INFO, 740 LOG (GNUNET_ERROR_TYPE_INFO, "Sqlite datacache running\n");
820 "Sqlite datacache running\n");
821 return api; 741 return api;
822} 742}
823 743
@@ -839,12 +759,9 @@ libgnunet_plugin_datacache_sqlite_done (void *cls)
839 sqlite3_stmt *stmt; 759 sqlite3_stmt *stmt;
840#endif 760#endif
841 761
842#if !WINDOWS || defined(__CYGWIN__) 762#if ! WINDOWS || defined(__CYGWIN__)
843 if ( (NULL != plugin->fn) && 763 if ((NULL != plugin->fn) && (0 != unlink (plugin->fn)))
844 (0 != UNLINK (plugin->fn)) ) 764 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", plugin->fn);
845 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
846 "unlink",
847 plugin->fn);
848 GNUNET_free_non_null (plugin->fn); 765 GNUNET_free_non_null (plugin->fn);
849#endif 766#endif
850 sqlite3_finalize (plugin->insert_stmt); 767 sqlite3_finalize (plugin->insert_stmt);
@@ -860,7 +777,8 @@ libgnunet_plugin_datacache_sqlite_done (void *cls)
860 if (SQLITE_BUSY == result) 777 if (SQLITE_BUSY == result)
861 { 778 {
862 LOG (GNUNET_ERROR_TYPE_WARNING, 779 LOG (GNUNET_ERROR_TYPE_WARNING,
863 _("Tried to close sqlite without finalizing all prepared statements.\n")); 780 _ (
781 "Tried to close sqlite without finalizing all prepared statements.\n"));
864 stmt = sqlite3_next_stmt (plugin->dbh, NULL); 782 stmt = sqlite3_next_stmt (plugin->dbh, NULL);
865 while (NULL != stmt) 783 while (NULL != stmt)
866 { 784 {
@@ -876,16 +794,11 @@ libgnunet_plugin_datacache_sqlite_done (void *cls)
876 } 794 }
877#endif 795#endif
878 if (SQLITE_OK != result) 796 if (SQLITE_OK != result)
879 LOG_SQLITE (plugin->dbh, 797 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR, "sqlite3_close");
880 GNUNET_ERROR_TYPE_ERROR, 798
881 "sqlite3_close"); 799#if WINDOWS && ! defined(__CYGWIN__)
882 800 if ((NULL != plugin->fn) && (0 != unlink (plugin->fn)))
883#if WINDOWS && !defined(__CYGWIN__) 801 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", plugin->fn);
884 if ( (NULL != plugin->fn) &&
885 (0 != UNLINK (plugin->fn)) )
886 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
887 "unlink",
888 plugin->fn);
889 GNUNET_free_non_null (plugin->fn); 802 GNUNET_free_non_null (plugin->fn);
890#endif 803#endif
891 GNUNET_free (plugin); 804 GNUNET_free (plugin);
@@ -894,5 +807,4 @@ libgnunet_plugin_datacache_sqlite_done (void *cls)
894} 807}
895 808
896 809
897
898/* end of plugin_datacache_sqlite.c */ 810/* end of plugin_datacache_sqlite.c */
diff --git a/src/datacache/test_datacache.c b/src/datacache/test_datacache.c
index d62a31c27..572a775df 100644
--- a/src/datacache/test_datacache.c
+++ b/src/datacache/test_datacache.c
@@ -84,7 +84,7 @@ run (void *cls,
84 "testcache"); 84 "testcache");
85 if (h == NULL) 85 if (h == NULL)
86 { 86 {
87 FPRINTF (stderr, 87 fprintf (stderr,
88 "%s", 88 "%s",
89 "Failed to initialize datacache. Database likely not setup, skipping test.\n"); 89 "Failed to initialize datacache. Database likely not setup, skipping test.\n");
90 ok = 77; /* mark test as skipped */ 90 ok = 77; /* mark test as skipped */
@@ -183,7 +183,7 @@ main (int argc, char *argv[])
183 &run, 183 &run,
184 NULL); 184 NULL);
185 if ( (0 != ok) && (77 != ok) ) 185 if ( (0 != ok) && (77 != ok) )
186 FPRINTF (stderr, 186 fprintf (stderr,
187 "Missed some testcases: %d\n", 187 "Missed some testcases: %d\n",
188 ok); 188 ok);
189 return ok; 189 return ok;
diff --git a/src/datacache/test_datacache_quota.c b/src/datacache/test_datacache_quota.c
index 7c4e56ea5..0201df3b3 100644
--- a/src/datacache/test_datacache_quota.c
+++ b/src/datacache/test_datacache_quota.c
@@ -63,7 +63,7 @@ run (void *cls,
63 63
64 if (h == NULL) 64 if (h == NULL)
65 { 65 {
66 FPRINTF (stderr, 66 fprintf (stderr,
67 "%s", 67 "%s",
68 "Failed to initialize datacache. Database likely not setup, skipping test.\n"); 68 "Failed to initialize datacache. Database likely not setup, skipping test.\n");
69 return; 69 return;
@@ -73,7 +73,7 @@ run (void *cls,
73 memset (&k, 0, sizeof (struct GNUNET_HashCode)); 73 memset (&k, 0, sizeof (struct GNUNET_HashCode));
74 for (unsigned int i = 0; i < 10; i++) 74 for (unsigned int i = 0; i < 10; i++)
75 { 75 {
76 FPRINTF (stderr, 76 fprintf (stderr,
77 "%s", 77 "%s",
78 "."); 78 ".");
79 GNUNET_CRYPTO_hash (&k, 79 GNUNET_CRYPTO_hash (&k,
@@ -97,11 +97,11 @@ run (void *cls,
97 } 97 }
98 k = n; 98 k = n;
99 } 99 }
100 FPRINTF (stderr, "%s", "\n"); 100 fprintf (stderr, "%s", "\n");
101 memset (&k, 0, sizeof (struct GNUNET_HashCode)); 101 memset (&k, 0, sizeof (struct GNUNET_HashCode));
102 for (unsigned int i = 0; i < 10; i++) 102 for (unsigned int i = 0; i < 10; i++)
103 { 103 {
104 FPRINTF (stderr, "%s", "."); 104 fprintf (stderr, "%s", ".");
105 GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n); 105 GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n);
106 if (i < 2) 106 if (i < 2)
107 ASSERT (0 == GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL)); 107 ASSERT (0 == GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL));
@@ -109,7 +109,7 @@ run (void *cls,
109 ASSERT (0 < GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL)); 109 ASSERT (0 < GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL));
110 k = n; 110 k = n;
111 } 111 }
112 FPRINTF (stderr, "%s", "\n"); 112 fprintf (stderr, "%s", "\n");
113 GNUNET_DATACACHE_destroy (h); 113 GNUNET_DATACACHE_destroy (h);
114 return; 114 return;
115FAILURE: 115FAILURE:
@@ -152,7 +152,7 @@ main (int argc,
152 &run, 152 &run,
153 NULL); 153 NULL);
154 if (0 != ok) 154 if (0 != ok)
155 FPRINTF (stderr, 155 fprintf (stderr,
156 "Missed some testcases: %d\n", 156 "Missed some testcases: %d\n",
157 ok); 157 ok);
158 return ok; 158 return ok;
diff --git a/src/datastore/gnunet-datastore.c b/src/datastore/gnunet-datastore.c
index cd089071c..4cf318777 100644
--- a/src/datastore/gnunet-datastore.c
+++ b/src/datastore/gnunet-datastore.c
@@ -66,7 +66,6 @@ struct DataRecord
66 * Key under which the item can be found. 66 * Key under which the item can be found.
67 */ 67 */
68 struct GNUNET_HashCode key; 68 struct GNUNET_HashCode key;
69
70}; 69};
71GNUNET_NETWORK_STRUCT_END 70GNUNET_NETWORK_STRUCT_END
72 71
@@ -185,13 +184,11 @@ get_cb (void *cls,
185 qe = NULL; 184 qe = NULL;
186 if (NULL == key) 185 if (NULL == key)
187 { 186 {
188 FPRINTF (stderr, 187 fprintf (stderr, _ ("Dumped %" PRIu64 " records\n"), record_count);
189 _("Dumped %" PRIu64 " records\n"),
190 record_count);
191 GNUNET_DISK_file_close (file_handle); 188 GNUNET_DISK_file_close (file_handle);
192 file_handle = NULL; 189 file_handle = NULL;
193 if (insert) 190 if (insert)
194 start_insert(); 191 start_insert ();
195 else 192 else
196 { 193 {
197 ret = 0; 194 ret = 0;
@@ -213,8 +210,8 @@ get_cb (void *cls,
213 len = GNUNET_DISK_file_write (file_handle, &dr, sizeof (dr)); 210 len = GNUNET_DISK_file_write (file_handle, &dr, sizeof (dr));
214 if (sizeof (dr) != len) 211 if (sizeof (dr) != len)
215 { 212 {
216 FPRINTF (stderr, 213 fprintf (stderr,
217 _("Short write to file: %zd bytes expecting %zd\n"), 214 _ ("Short write to file: %zd bytes expecting %zd\n"),
218 len, 215 len,
219 sizeof (dr)); 216 sizeof (dr));
220 ret = 1; 217 ret = 1;
@@ -225,8 +222,8 @@ get_cb (void *cls,
225 len = GNUNET_DISK_file_write (file_handle, data, size); 222 len = GNUNET_DISK_file_write (file_handle, data, size);
226 if (size != len) 223 if (size != len)
227 { 224 {
228 FPRINTF (stderr, 225 fprintf (stderr,
229 _("Short write to file: %zd bytes expecting %zd\n"), 226 _ ("Short write to file: %zd bytes expecting %zd\n"),
230 len, 227 len,
231 size); 228 size);
232 ret = 1; 229 ret = 1;
@@ -235,7 +232,7 @@ get_cb (void *cls,
235 } 232 }
236 233
237 record_count++; 234 record_count++;
238 do_get(uid + 1); 235 do_get (uid + 1);
239} 236}
240 237
241 238
@@ -257,8 +254,7 @@ do_get (const uint64_t next_uid)
257 NULL /* proc_cls */); 254 NULL /* proc_cls */);
258 if (NULL == qe) 255 if (NULL == qe)
259 { 256 {
260 FPRINTF (stderr, 257 fprintf (stderr, _ ("Error queueing datastore GET operation\n"));
261 _("Error queueing datastore GET operation\n"));
262 ret = 1; 258 ret = 1;
263 GNUNET_SCHEDULER_shutdown (); 259 GNUNET_SCHEDULER_shutdown ();
264 } 260 }
@@ -277,15 +273,13 @@ start_dump ()
277 { 273 {
278 file_handle = GNUNET_DISK_file_open (file_name, 274 file_handle = GNUNET_DISK_file_open (file_name,
279 GNUNET_DISK_OPEN_WRITE | 275 GNUNET_DISK_OPEN_WRITE |
280 GNUNET_DISK_OPEN_TRUNCATE | 276 GNUNET_DISK_OPEN_TRUNCATE |
281 GNUNET_DISK_OPEN_CREATE, 277 GNUNET_DISK_OPEN_CREATE,
282 GNUNET_DISK_PERM_USER_READ | 278 GNUNET_DISK_PERM_USER_READ |
283 GNUNET_DISK_PERM_USER_WRITE); 279 GNUNET_DISK_PERM_USER_WRITE);
284 if (NULL == file_handle) 280 if (NULL == file_handle)
285 { 281 {
286 FPRINTF (stderr, 282 fprintf (stderr, _ ("Unable to open dump file: %s\n"), file_name);
287 _("Unable to open dump file: %s\n"),
288 file_name);
289 ret = 1; 283 ret = 1;
290 GNUNET_SCHEDULER_shutdown (); 284 GNUNET_SCHEDULER_shutdown ();
291 return; 285 return;
@@ -296,7 +290,7 @@ start_dump ()
296 file_handle = GNUNET_DISK_get_handle_from_int_fd (STDOUT_FILENO); 290 file_handle = GNUNET_DISK_get_handle_from_int_fd (STDOUT_FILENO);
297 } 291 }
298 GNUNET_DISK_file_write (file_handle, MAGIC_BYTES, MAGIC_LEN); 292 GNUNET_DISK_file_write (file_handle, MAGIC_BYTES, MAGIC_LEN);
299 do_get(0); 293 do_get (0);
300} 294}
301 295
302 296
@@ -322,9 +316,7 @@ put_cb (void *cls,
322 qe = NULL; 316 qe = NULL;
323 if (GNUNET_SYSERR == success) 317 if (GNUNET_SYSERR == success)
324 { 318 {
325 FPRINTF (stderr, 319 fprintf (stderr, _ ("Failed to store item: %s, aborting\n"), msg);
326 _("Failed to store item: %s, aborting\n"),
327 msg);
328 ret = 1; 320 ret = 1;
329 GNUNET_SCHEDULER_shutdown (); 321 GNUNET_SCHEDULER_shutdown ();
330 return; 322 return;
@@ -336,17 +328,15 @@ put_cb (void *cls,
336 len = GNUNET_DISK_file_read (file_handle, &dr, sizeof (dr)); 328 len = GNUNET_DISK_file_read (file_handle, &dr, sizeof (dr));
337 if (0 == len) 329 if (0 == len)
338 { 330 {
339 FPRINTF (stderr, 331 fprintf (stderr, _ ("Inserted %" PRIu64 " records\n"), record_count);
340 _("Inserted %" PRIu64 " records\n"),
341 record_count);
342 ret = 0; 332 ret = 0;
343 GNUNET_SCHEDULER_shutdown (); 333 GNUNET_SCHEDULER_shutdown ();
344 return; 334 return;
345 } 335 }
346 else if (sizeof (dr) != len) 336 else if (sizeof (dr) != len)
347 { 337 {
348 FPRINTF (stderr, 338 fprintf (stderr,
349 _("Short read from file: %zd bytes expecting %zd\n"), 339 _ ("Short read from file: %zd bytes expecting %zd\n"),
350 len, 340 len,
351 sizeof (dr)); 341 sizeof (dr));
352 ret = 1; 342 ret = 1;
@@ -359,8 +349,8 @@ put_cb (void *cls,
359 len = GNUNET_DISK_file_read (file_handle, data, size); 349 len = GNUNET_DISK_file_read (file_handle, data, size);
360 if (size != len) 350 if (size != len)
361 { 351 {
362 FPRINTF (stderr, 352 fprintf (stderr,
363 _("Short read from file: %zd bytes expecting %zd\n"), 353 _ ("Short read from file: %zd bytes expecting %zd\n"),
364 len, 354 len,
365 size); 355 size);
366 ret = 1; 356 ret = 1;
@@ -385,8 +375,7 @@ put_cb (void *cls,
385 NULL); 375 NULL);
386 if (NULL == qe) 376 if (NULL == qe)
387 { 377 {
388 FPRINTF (stderr, 378 fprintf (stderr, _ ("Error queueing datastore PUT operation\n"));
389 _("Error queueing datastore PUT operation\n"));
390 ret = 1; 379 ret = 1;
391 GNUNET_SCHEDULER_shutdown (); 380 GNUNET_SCHEDULER_shutdown ();
392 } 381 }
@@ -408,9 +397,7 @@ start_insert ()
408 GNUNET_DISK_PERM_NONE); 397 GNUNET_DISK_PERM_NONE);
409 if (NULL == file_handle) 398 if (NULL == file_handle)
410 { 399 {
411 FPRINTF (stderr, 400 fprintf (stderr, _ ("Unable to open dump file: %s\n"), file_name);
412 _("Unable to open dump file: %s\n"),
413 file_name);
414 ret = 1; 401 ret = 1;
415 GNUNET_SCHEDULER_shutdown (); 402 GNUNET_SCHEDULER_shutdown ();
416 return; 403 return;
@@ -425,11 +412,9 @@ start_insert ()
425 ssize_t len; 412 ssize_t len;
426 413
427 len = GNUNET_DISK_file_read (file_handle, buf, MAGIC_LEN); 414 len = GNUNET_DISK_file_read (file_handle, buf, MAGIC_LEN);
428 if (len != MAGIC_LEN || 415 if (len != MAGIC_LEN || 0 != memcmp (buf, MAGIC_BYTES, MAGIC_LEN))
429 0 != memcmp (buf, MAGIC_BYTES, MAGIC_LEN))
430 { 416 {
431 FPRINTF (stderr, 417 fprintf (stderr, _ ("Input file is not of a supported format\n"));
432 _("Input file is not of a supported format\n"));
433 return; 418 return;
434 } 419 }
435 put_cb (NULL, GNUNET_YES, GNUNET_TIME_UNIT_ZERO_ABS, NULL); 420 put_cb (NULL, GNUNET_YES, GNUNET_TIME_UNIT_ZERO_ABS, NULL);
@@ -454,20 +439,19 @@ run (void *cls,
454 datastore = GNUNET_DATASTORE_connect (cfg); 439 datastore = GNUNET_DATASTORE_connect (cfg);
455 if (NULL == datastore) 440 if (NULL == datastore)
456 { 441 {
457 FPRINTF (stderr, 442 fprintf (stderr, _ ("Failed connecting to the datastore.\n"));
458 _("Failed connecting to the datastore.\n"));
459 ret = 1; 443 ret = 1;
460 GNUNET_SCHEDULER_shutdown (); 444 GNUNET_SCHEDULER_shutdown ();
461 return; 445 return;
462 } 446 }
463 if (dump) 447 if (dump)
464 start_dump(); 448 start_dump ();
465 else if (insert) 449 else if (insert)
466 start_insert(); 450 start_insert ();
467 else 451 else
468 { 452 {
469 FPRINTF (stderr, 453 fprintf (stderr,
470 _("Please choose at least one operation: %s, %s\n"), 454 _ ("Please choose at least one operation: %s, %s\n"),
471 "dump", 455 "dump",
472 "insert"); 456 "insert");
473 ret = 1; 457 ret = 1;
@@ -484,34 +468,38 @@ run (void *cls,
484 * @return 0 ok, 1 on error 468 * @return 0 ok, 1 on error
485 */ 469 */
486int 470int
487main (int argc, 471main (int argc, char *const *argv)
488 char *const *argv)
489{ 472{
490 struct GNUNET_GETOPT_CommandLineOption options[] = { 473 struct GNUNET_GETOPT_CommandLineOption options[] =
491 GNUNET_GETOPT_option_flag ('d', 474 {GNUNET_GETOPT_option_flag ('d',
492 "dump", 475 "dump",
493 gettext_noop ("Dump all records from the datastore"), 476 gettext_noop (
494 &dump), 477 "Dump all records from the datastore"),
495 GNUNET_GETOPT_option_flag ('i', 478 &dump),
496 "insert", 479 GNUNET_GETOPT_option_flag ('i',
497 gettext_noop ("Insert records into the datastore"), 480 "insert",
498 &insert), 481 gettext_noop (
499 GNUNET_GETOPT_option_filename ('f', 482 "Insert records into the datastore"),
500 "file", 483 &insert),
501 "FILENAME", 484 GNUNET_GETOPT_option_filename ('f',
502 gettext_noop ("File to dump or insert"), 485 "file",
503 &file_name), 486 "FILENAME",
504 GNUNET_GETOPT_OPTION_END 487 gettext_noop ("File to dump or insert"),
505 }; 488 &file_name),
489 GNUNET_GETOPT_OPTION_END};
506 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 490 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
507 return 2; 491 return 2;
508 492
509 if (GNUNET_OK != 493 if (GNUNET_OK !=
510 GNUNET_PROGRAM_run (argc, argv, "gnunet-datastore", 494 GNUNET_PROGRAM_run (argc,
511 gettext_noop ("Manipulate GNUnet datastore"), 495 argv,
512 options, &run, NULL)) 496 "gnunet-datastore",
497 gettext_noop ("Manipulate GNUnet datastore"),
498 options,
499 &run,
500 NULL))
513 ret = 1; 501 ret = 1;
514 GNUNET_free ((void*) argv); 502 GNUNET_free ((void *) argv);
515 return ret; 503 return ret;
516} 504}
517 505
diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c
index 70a946ca5..4596f6131 100644
--- a/src/datastore/gnunet-service-datastore.c
+++ b/src/datastore/gnunet-service-datastore.c
@@ -45,13 +45,15 @@
45 * How long are we at most keeping "expired" content 45 * How long are we at most keeping "expired" content
46 * past the expiration date in the database? 46 * past the expiration date in the database?
47 */ 47 */
48#define MAX_EXPIRE_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) 48#define MAX_EXPIRE_DELAY \
49 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
49 50
50/** 51/**
51 * How fast are we allowed to query the database for deleting 52 * How fast are we allowed to query the database for deleting
52 * expired content? (1 item per second). 53 * expired content? (1 item per second).
53 */ 54 */
54#define MIN_EXPIRE_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) 55#define MIN_EXPIRE_DELAY \
56 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
55 57
56/** 58/**
57 * Name under which we store current space consumption. 59 * Name under which we store current space consumption.
@@ -97,7 +99,6 @@ struct DatastorePlugin
97 * for this plugin. 99 * for this plugin.
98 */ 100 */
99 struct GNUNET_DATASTORE_PluginEnvironment env; 101 struct GNUNET_DATASTORE_PluginEnvironment env;
100
101}; 102};
102 103
103 104
@@ -131,11 +132,9 @@ struct ReservationList
131 * Reservation identifier. 132 * Reservation identifier.
132 */ 133 */
133 int32_t rid; 134 int32_t rid;
134
135}; 135};
136 136
137 137
138
139/** 138/**
140 * Our datastore plugin (NULL if not available). 139 * Our datastore plugin (NULL if not available).
141 */ 140 */
@@ -234,10 +233,7 @@ static int stats_worked;
234static void 233static void
235sync_stats () 234sync_stats ()
236{ 235{
237 GNUNET_STATISTICS_set (stats, 236 GNUNET_STATISTICS_set (stats, quota_stat_name, payload, GNUNET_YES);
238 quota_stat_name,
239 payload,
240 GNUNET_YES);
241 GNUNET_STATISTICS_set (stats, 237 GNUNET_STATISTICS_set (stats,
242 "# utilization by current datastore", 238 "# utilization by current datastore",
243 payload, 239 payload,
@@ -312,9 +308,10 @@ expired_processor (void *cls,
312 if (NULL == key) 308 if (NULL == key)
313 { 309 {
314 expired_kill_task = 310 expired_kill_task =
315 GNUNET_SCHEDULER_add_delayed_with_priority (MAX_EXPIRE_DELAY, 311 GNUNET_SCHEDULER_add_delayed_with_priority (MAX_EXPIRE_DELAY,
316 GNUNET_SCHEDULER_PRIORITY_IDLE, 312 GNUNET_SCHEDULER_PRIORITY_IDLE,
317 &delete_expired, NULL); 313 &delete_expired,
314 NULL);
318 return GNUNET_SYSERR; 315 return GNUNET_SYSERR;
319 } 316 }
320 now = GNUNET_TIME_absolute_get (); 317 now = GNUNET_TIME_absolute_get ();
@@ -322,17 +319,19 @@ expired_processor (void *cls,
322 { 319 {
323 /* finished processing */ 320 /* finished processing */
324 expired_kill_task = 321 expired_kill_task =
325 GNUNET_SCHEDULER_add_delayed_with_priority (MAX_EXPIRE_DELAY, 322 GNUNET_SCHEDULER_add_delayed_with_priority (MAX_EXPIRE_DELAY,
326 GNUNET_SCHEDULER_PRIORITY_IDLE, 323 GNUNET_SCHEDULER_PRIORITY_IDLE,
327 &delete_expired, NULL); 324 &delete_expired,
325 NULL);
328 return GNUNET_SYSERR; 326 return GNUNET_SYSERR;
329 } 327 }
330 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 328 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
331 "Deleting content `%s' of type %u that expired %s ago\n", 329 "Deleting content `%s' of type %u that expired %s ago\n",
332 GNUNET_h2s (key), type, 330 GNUNET_h2s (key),
333 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_difference (expiration, 331 type,
334 now), 332 GNUNET_STRINGS_relative_time_to_string (
335 GNUNET_YES)); 333 GNUNET_TIME_absolute_get_difference (expiration, now),
334 GNUNET_YES));
336 min_expiration = now; 335 min_expiration = now;
337 GNUNET_STATISTICS_update (stats, 336 GNUNET_STATISTICS_update (stats,
338 gettext_noop ("# bytes expired"), 337 gettext_noop ("# bytes expired"),
@@ -340,9 +339,10 @@ expired_processor (void *cls,
340 GNUNET_YES); 339 GNUNET_YES);
341 GNUNET_CONTAINER_bloomfilter_remove (filter, key); 340 GNUNET_CONTAINER_bloomfilter_remove (filter, key);
342 expired_kill_task = 341 expired_kill_task =
343 GNUNET_SCHEDULER_add_delayed_with_priority (MIN_EXPIRE_DELAY, 342 GNUNET_SCHEDULER_add_delayed_with_priority (MIN_EXPIRE_DELAY,
344 GNUNET_SCHEDULER_PRIORITY_IDLE, 343 GNUNET_SCHEDULER_PRIORITY_IDLE,
345 &delete_expired, NULL); 344 &delete_expired,
345 NULL);
346 return GNUNET_NO; 346 return GNUNET_NO;
347} 347}
348 348
@@ -359,9 +359,7 @@ static void
359delete_expired (void *cls) 359delete_expired (void *cls)
360{ 360{
361 expired_kill_task = NULL; 361 expired_kill_task = NULL;
362 plugin->api->get_expiration (plugin->api->cls, 362 plugin->api->get_expiration (plugin->api->cls, &expired_processor, NULL);
363 &expired_processor,
364 NULL);
365} 363}
366 364
367 365
@@ -400,14 +398,17 @@ quota_processor (void *cls,
400 398
401 if (NULL == key) 399 if (NULL == key)
402 return GNUNET_SYSERR; 400 return GNUNET_SYSERR;
403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 401 GNUNET_log (
404 "Deleting %llu bytes of low-priority (%u) content `%s' of type %u at %s prior to expiration (still trying to free another %llu bytes)\n", 402 GNUNET_ERROR_TYPE_DEBUG,
405 (unsigned long long) (size + GNUNET_DATASTORE_ENTRY_OVERHEAD), 403 "Deleting %llu bytes of low-priority (%u) content `%s' of type %u at %s prior to expiration (still trying to free another %llu bytes)\n",
406 (unsigned int) priority, 404 (unsigned long long) (size + GNUNET_DATASTORE_ENTRY_OVERHEAD),
407 GNUNET_h2s (key), type, 405 (unsigned int) priority,
408 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (expiration), 406 GNUNET_h2s (key),
409 GNUNET_YES), 407 type,
410 *need); 408 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (
409 expiration),
410 GNUNET_YES),
411 *need);
411 if (size + GNUNET_DATASTORE_ENTRY_OVERHEAD > *need) 412 if (size + GNUNET_DATASTORE_ENTRY_OVERHEAD > *need)
412 *need = 0; 413 *need = 0;
413 else 414 else
@@ -418,7 +419,8 @@ quota_processor (void *cls,
418 min_expiration = expiration; 419 min_expiration = expiration;
419 GNUNET_STATISTICS_update (stats, 420 GNUNET_STATISTICS_update (stats,
420 gettext_noop ("# bytes purged (low-priority)"), 421 gettext_noop ("# bytes purged (low-priority)"),
421 size, GNUNET_YES); 422 size,
423 GNUNET_YES);
422 GNUNET_CONTAINER_bloomfilter_remove (filter, key); 424 GNUNET_CONTAINER_bloomfilter_remove (filter, key);
423 return GNUNET_NO; 425 return GNUNET_NO;
424} 426}
@@ -448,9 +450,7 @@ manage_space (unsigned long long need)
448 while ((need > 0) && (last != need)) 450 while ((need > 0) && (last != need))
449 { 451 {
450 last = need; 452 last = need;
451 plugin->api->get_expiration (plugin->api->cls, 453 plugin->api->get_expiration (plugin->api->cls, &quota_processor, &need);
452 &quota_processor,
453 &need);
454 } 454 }
455} 455}
456 456
@@ -473,18 +473,15 @@ transmit_status (struct GNUNET_SERVICE_Client *client,
473 473
474 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 474 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
475 "Transmitting `%s' message with value %d and message `%s'\n", 475 "Transmitting `%s' message with value %d and message `%s'\n",
476 "STATUS", code, msg != NULL ? msg : "(none)"); 476 "STATUS",
477 code,
478 msg != NULL ? msg : "(none)");
477 slen = (msg == NULL) ? 0 : strlen (msg) + 1; 479 slen = (msg == NULL) ? 0 : strlen (msg) + 1;
478 env = GNUNET_MQ_msg_extra (sm, 480 env = GNUNET_MQ_msg_extra (sm, slen, GNUNET_MESSAGE_TYPE_DATASTORE_STATUS);
479 slen,
480 GNUNET_MESSAGE_TYPE_DATASTORE_STATUS);
481 sm->status = htonl (code); 481 sm->status = htonl (code);
482 sm->min_expiration = GNUNET_TIME_absolute_hton (min_expiration); 482 sm->min_expiration = GNUNET_TIME_absolute_hton (min_expiration);
483 GNUNET_memcpy (&sm[1], 483 GNUNET_memcpy (&sm[1], msg, slen);
484 msg, 484 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
485 slen);
486 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
487 env);
488} 485}
489 486
490 487
@@ -526,19 +523,13 @@ transmit_item (void *cls,
526 if (NULL == key) 523 if (NULL == key)
527 { 524 {
528 /* transmit 'DATA_END' */ 525 /* transmit 'DATA_END' */
529 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 526 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting DATA_END message\n");
530 "Transmitting DATA_END message\n"); 527 env = GNUNET_MQ_msg (end, GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END);
531 env = GNUNET_MQ_msg (end, 528 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
532 GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END);
533 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
534 env);
535 return GNUNET_OK; 529 return GNUNET_OK;
536 } 530 }
537 GNUNET_assert (sizeof (struct DataMessage) + size < 531 GNUNET_assert (sizeof (struct DataMessage) + size < GNUNET_MAX_MESSAGE_SIZE);
538 GNUNET_MAX_MESSAGE_SIZE); 532 env = GNUNET_MQ_msg_extra (dm, size, GNUNET_MESSAGE_TYPE_DATASTORE_DATA);
539 env = GNUNET_MQ_msg_extra (dm,
540 size,
541 GNUNET_MESSAGE_TYPE_DATASTORE_DATA);
542 dm->rid = htonl (0); 533 dm->rid = htonl (0);
543 dm->size = htonl (size); 534 dm->size = htonl (size);
544 dm->type = htonl (type); 535 dm->type = htonl (type);
@@ -548,22 +539,21 @@ transmit_item (void *cls,
548 dm->expiration = GNUNET_TIME_absolute_hton (expiration); 539 dm->expiration = GNUNET_TIME_absolute_hton (expiration);
549 dm->uid = GNUNET_htonll (uid); 540 dm->uid = GNUNET_htonll (uid);
550 dm->key = *key; 541 dm->key = *key;
551 GNUNET_memcpy (&dm[1], 542 GNUNET_memcpy (&dm[1], data, size);
552 data, 543 GNUNET_log (
553 size); 544 GNUNET_ERROR_TYPE_DEBUG,
554 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 545 "Transmitting DATA message for `%s' of type %u with expiration %s (in: %s)\n",
555 "Transmitting DATA message for `%s' of type %u with expiration %s (in: %s)\n", 546 GNUNET_h2s (key),
556 GNUNET_h2s (key), 547 type,
557 type, 548 GNUNET_STRINGS_absolute_time_to_string (expiration),
558 GNUNET_STRINGS_absolute_time_to_string (expiration), 549 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (
559 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (expiration), 550 expiration),
560 GNUNET_YES)); 551 GNUNET_YES));
561 GNUNET_STATISTICS_update (stats, 552 GNUNET_STATISTICS_update (stats,
562 gettext_noop ("# results found"), 553 gettext_noop ("# results found"),
563 1, 554 1,
564 GNUNET_NO); 555 GNUNET_NO);
565 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), 556 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
566 env);
567 return GNUNET_OK; 557 return GNUNET_OK;
568} 558}
569 559
@@ -575,8 +565,7 @@ transmit_item (void *cls,
575 * @param message the actual message 565 * @param message the actual message
576 */ 566 */
577static void 567static void
578handle_reserve (void *cls, 568handle_reserve (void *cls, const struct ReserveMessage *msg)
579 const struct ReserveMessage *msg)
580{ 569{
581 /** 570 /**
582 * Static counter to produce reservation identifiers. 571 * Static counter to produce reservation identifiers.
@@ -589,20 +578,23 @@ handle_reserve (void *cls,
589 uint64_t amount; 578 uint64_t amount;
590 uint32_t entries; 579 uint32_t entries;
591 580
592 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 581 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing RESERVE request\n");
593 "Processing RESERVE request\n");
594 amount = GNUNET_ntohll (msg->amount); 582 amount = GNUNET_ntohll (msg->amount);
595 entries = ntohl (msg->entries); 583 entries = ntohl (msg->entries);
596 used = payload + reserved; 584 used = payload + reserved;
597 req = amount + ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * entries; 585 req =
586 amount + ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * entries;
598 if (used + req > quota) 587 if (used + req > quota)
599 { 588 {
600 if (quota < used) 589 if (quota < used)
601 used = quota; /* cheat a bit for error message (to avoid negative numbers) */ 590 used =
602 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 591 quota; /* cheat a bit for error message (to avoid negative numbers) */
603 _("Insufficient space (%llu bytes are available) to satisfy RESERVE request for %llu bytes\n"), 592 GNUNET_log (
604 quota - used, 593 GNUNET_ERROR_TYPE_WARNING,
605 req); 594 _ (
595 "Insufficient space (%llu bytes are available) to satisfy RESERVE request for %llu bytes\n"),
596 quota - used,
597 req);
606 if (cache_size < req) 598 if (cache_size < req)
607 { 599 {
608 /* TODO: document this in the FAQ; essentially, if this 600 /* TODO: document this in the FAQ; essentially, if this
@@ -610,15 +602,17 @@ handle_reserve (void *cls,
610 * by less-important content from migration because it is 602 * by less-important content from migration because it is
611 * larger than 1/8th of the overall available space, and 603 * larger than 1/8th of the overall available space, and
612 * we only reserve 1/8th for "fresh" insertions */ 604 * we only reserve 1/8th for "fresh" insertions */
613 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 605 GNUNET_log (
614 _("The requested amount (%llu bytes) is larger than the cache size (%llu bytes)\n"), 606 GNUNET_ERROR_TYPE_WARNING,
615 req, 607 _ (
616 cache_size); 608 "The requested amount (%llu bytes) is larger than the cache size (%llu bytes)\n"),
609 req,
610 cache_size);
617 transmit_status (client, 611 transmit_status (client,
618 0, 612 0,
619 gettext_noop 613 gettext_noop (
620 ("Insufficient space to satisfy request and " 614 "Insufficient space to satisfy request and "
621 "requested amount is larger than cache size")); 615 "requested amount is larger than cache size"));
622 } 616 }
623 else 617 else
624 { 618 {
@@ -642,10 +636,8 @@ handle_reserve (void *cls,
642 e->entries = entries; 636 e->entries = entries;
643 e->rid = ++reservation_gen; 637 e->rid = ++reservation_gen;
644 if (reservation_gen < 0) 638 if (reservation_gen < 0)
645 reservation_gen = 0; /* wrap around */ 639 reservation_gen = 0; /* wrap around */
646 transmit_status (client, 640 transmit_status (client, e->rid, NULL);
647 e->rid,
648 NULL);
649 GNUNET_SERVICE_client_continue (client); 641 GNUNET_SERVICE_client_continue (client);
650} 642}
651 643
@@ -657,8 +649,7 @@ handle_reserve (void *cls,
657 * @param message the actual message 649 * @param message the actual message
658 */ 650 */
659static void 651static void
660handle_release_reserve (void *cls, 652handle_release_reserve (void *cls, const struct ReleaseReserveMessage *msg)
661 const struct ReleaseReserveMessage *msg)
662{ 653{
663 struct GNUNET_SERVICE_Client *client = cls; 654 struct GNUNET_SERVICE_Client *client = cls;
664 struct ReservationList *pos; 655 struct ReservationList *pos;
@@ -667,8 +658,7 @@ handle_release_reserve (void *cls,
667 int rid = ntohl (msg->rid); 658 int rid = ntohl (msg->rid);
668 unsigned long long rem; 659 unsigned long long rem;
669 660
670 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 661 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing RELEASE_RESERVE request\n");
671 "Processing RELEASE_RESERVE request\n");
672 next = reservations; 662 next = reservations;
673 prev = NULL; 663 prev = NULL;
674 while (NULL != (pos = next)) 664 while (NULL != (pos = next))
@@ -681,8 +671,8 @@ handle_release_reserve (void *cls,
681 else 671 else
682 prev->next = next; 672 prev->next = next;
683 rem = 673 rem =
684 pos->amount + 674 pos->amount +
685 ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * pos->entries; 675 ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * pos->entries;
686 GNUNET_assert (reserved >= rem); 676 GNUNET_assert (reserved >= rem);
687 reserved -= rem; 677 reserved -= rem;
688 GNUNET_STATISTICS_set (stats, 678 GNUNET_STATISTICS_set (stats,
@@ -693,9 +683,7 @@ handle_release_reserve (void *cls,
693 "Returning %llu remaining reserved bytes to storage pool\n", 683 "Returning %llu remaining reserved bytes to storage pool\n",
694 rem); 684 rem);
695 GNUNET_free (pos); 685 GNUNET_free (pos);
696 transmit_status (client, 686 transmit_status (client, GNUNET_OK, NULL);
697 GNUNET_OK,
698 NULL);
699 GNUNET_SERVICE_client_continue (client); 687 GNUNET_SERVICE_client_continue (client);
700 return; 688 return;
701 } 689 }
@@ -757,8 +745,7 @@ put_continuation (void *cls,
757 gettext_noop ("# bytes stored"), 745 gettext_noop ("# bytes stored"),
758 size, 746 size,
759 GNUNET_YES); 747 GNUNET_YES);
760 GNUNET_CONTAINER_bloomfilter_add (filter, 748 GNUNET_CONTAINER_bloomfilter_add (filter, key);
761 key);
762 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 749 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
763 "Successfully stored %u bytes under key `%s'\n", 750 "Successfully stored %u bytes under key `%s'\n",
764 size, 751 size,
@@ -770,7 +757,7 @@ put_continuation (void *cls,
770 if (quota - reserved - cache_size < payload) 757 if (quota - reserved - cache_size < payload)
771 { 758 {
772 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 759 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
773 _("Need %llu bytes more space (%llu allowed, using %llu)\n"), 760 _ ("Need %llu bytes more space (%llu allowed, using %llu)\n"),
774 (unsigned long long) size + GNUNET_DATASTORE_ENTRY_OVERHEAD, 761 (unsigned long long) size + GNUNET_DATASTORE_ENTRY_OVERHEAD,
775 (unsigned long long) (quota - reserved - cache_size), 762 (unsigned long long) (quota - reserved - cache_size),
776 (unsigned long long) payload); 763 (unsigned long long) payload);
@@ -787,8 +774,7 @@ put_continuation (void *cls,
787 * @return #GNUNET_OK if @a dm is well-formed 774 * @return #GNUNET_OK if @a dm is well-formed
788 */ 775 */
789static int 776static int
790check_put (void *cls, 777check_put (void *cls, const struct DataMessage *dm)
791 const struct DataMessage *dm)
792{ 778{
793 if (GNUNET_OK != check_data (dm)) 779 if (GNUNET_OK != check_data (dm))
794 { 780 {
@@ -806,8 +792,7 @@ check_put (void *cls,
806 * @param message the actual message 792 * @param message the actual message
807 */ 793 */
808static void 794static void
809handle_put (void *cls, 795handle_put (void *cls, const struct DataMessage *dm)
810 const struct DataMessage *dm)
811{ 796{
812 struct GNUNET_SERVICE_Client *client = cls; 797 struct GNUNET_SERVICE_Client *client = cls;
813 int rid; 798 int rid;
@@ -839,8 +824,8 @@ handle_put (void *cls,
839 GNUNET_NO); 824 GNUNET_NO);
840 } 825 }
841 } 826 }
842 bool absent = GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test (filter, 827 bool absent =
843 &dm->key); 828 GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test (filter, &dm->key);
844 plugin->api->put (plugin->api->cls, 829 plugin->api->put (plugin->api->cls,
845 &dm->key, 830 &dm->key,
846 absent, 831 absent,
@@ -864,8 +849,7 @@ handle_put (void *cls,
864 * @param msg the actual message 849 * @param msg the actual message
865 */ 850 */
866static void 851static void
867handle_get (void *cls, 852handle_get (void *cls, const struct GetMessage *msg)
868 const struct GetMessage *msg)
869{ 853{
870 struct GNUNET_SERVICE_Client *client = cls; 854 struct GNUNET_SERVICE_Client *client = cls;
871 855
@@ -894,8 +878,7 @@ handle_get (void *cls,
894 * @param msg the actual message 878 * @param msg the actual message
895 */ 879 */
896static void 880static void
897handle_get_key (void *cls, 881handle_get_key (void *cls, const struct GetKeyMessage *msg)
898 const struct GetKeyMessage *msg)
899{ 882{
900 struct GNUNET_SERVICE_Client *client = cls; 883 struct GNUNET_SERVICE_Client *client = cls;
901 884
@@ -907,21 +890,25 @@ handle_get_key (void *cls,
907 gettext_noop ("# GET KEY requests received"), 890 gettext_noop ("# GET KEY requests received"),
908 1, 891 1,
909 GNUNET_NO); 892 GNUNET_NO);
910 if (GNUNET_YES != 893 if (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (filter, &msg->key))
911 GNUNET_CONTAINER_bloomfilter_test (filter,
912 &msg->key))
913 { 894 {
914 /* don't bother database... */ 895 /* don't bother database... */
915 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 896 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
916 "Empty result set for GET request for `%s' (bloomfilter).\n", 897 "Empty result set for GET request for `%s' (bloomfilter).\n",
917 GNUNET_h2s (&msg->key)); 898 GNUNET_h2s (&msg->key));
918 GNUNET_STATISTICS_update (stats, 899 GNUNET_STATISTICS_update (stats,
919 gettext_noop 900 gettext_noop (
920 ("# requests filtered by bloomfilter"), 901 "# requests filtered by bloomfilter"),
921 1, 902 1,
922 GNUNET_NO); 903 GNUNET_NO);
923 transmit_item (client, 904 transmit_item (client,
924 NULL, 0, NULL, 0, 0, 0, 0, 905 NULL,
906 0,
907 NULL,
908 0,
909 0,
910 0,
911 0,
925 GNUNET_TIME_UNIT_ZERO_ABS, 912 GNUNET_TIME_UNIT_ZERO_ABS,
926 0); 913 0);
927 GNUNET_SERVICE_client_continue (client); 914 GNUNET_SERVICE_client_continue (client);
@@ -945,20 +932,17 @@ handle_get_key (void *cls,
945 * @param message the actual message 932 * @param message the actual message
946 */ 933 */
947static void 934static void
948handle_get_replication (void *cls, 935handle_get_replication (void *cls, const struct GNUNET_MessageHeader *message)
949 const struct GNUNET_MessageHeader *message)
950{ 936{
951 struct GNUNET_SERVICE_Client *client = cls; 937 struct GNUNET_SERVICE_Client *client = cls;
952 938
953 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 939 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing GET_REPLICATION request\n");
954 "Processing GET_REPLICATION request\n");
955 GNUNET_STATISTICS_update (stats, 940 GNUNET_STATISTICS_update (stats,
956 gettext_noop ("# GET REPLICATION requests received"), 941 gettext_noop (
942 "# GET REPLICATION requests received"),
957 1, 943 1,
958 GNUNET_NO); 944 GNUNET_NO);
959 plugin->api->get_replication (plugin->api->cls, 945 plugin->api->get_replication (plugin->api->cls, &transmit_item, client);
960 &transmit_item,
961 client);
962 GNUNET_SERVICE_client_continue (client); 946 GNUNET_SERVICE_client_continue (client);
963} 947}
964 948
@@ -970,8 +954,7 @@ handle_get_replication (void *cls,
970 * @param message the actual message 954 * @param message the actual message
971 */ 955 */
972static void 956static void
973handle_get_zero_anonymity (void *cls, 957handle_get_zero_anonymity (void *cls, const struct GetZeroAnonymityMessage *msg)
974 const struct GetZeroAnonymityMessage *msg)
975{ 958{
976 struct GNUNET_SERVICE_Client *client = cls; 959 struct GNUNET_SERVICE_Client *client = cls;
977 enum GNUNET_BLOCK_Type type; 960 enum GNUNET_BLOCK_Type type;
@@ -986,7 +969,8 @@ handle_get_zero_anonymity (void *cls,
986 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 969 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
987 "Processing GET_ZERO_ANONYMITY request\n"); 970 "Processing GET_ZERO_ANONYMITY request\n");
988 GNUNET_STATISTICS_update (stats, 971 GNUNET_STATISTICS_update (stats,
989 gettext_noop ("# GET ZERO ANONYMITY requests received"), 972 gettext_noop (
973 "# GET ZERO ANONYMITY requests received"),
990 1, 974 1,
991 GNUNET_NO); 975 GNUNET_NO);
992 plugin->api->get_zero_anonymity (plugin->api->cls, 976 plugin->api->get_zero_anonymity (plugin->api->cls,
@@ -1019,21 +1003,15 @@ remove_continuation (void *cls,
1019 1003
1020 if (GNUNET_SYSERR == status) 1004 if (GNUNET_SYSERR == status)
1021 { 1005 {
1022 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1006 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "REMOVE request failed: %s.\n", msg);
1023 "REMOVE request failed: %s.\n", 1007 transmit_status (client, GNUNET_NO, msg);
1024 msg);
1025 transmit_status (client,
1026 GNUNET_NO,
1027 msg);
1028 return; 1008 return;
1029 } 1009 }
1030 if (GNUNET_NO == status) 1010 if (GNUNET_NO == status)
1031 { 1011 {
1032 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1012 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1033 "Content not found for REMOVE request.\n"); 1013 "Content not found for REMOVE request.\n");
1034 transmit_status (client, 1014 transmit_status (client, GNUNET_NO, _ ("Content not found"));
1035 GNUNET_NO,
1036 _("Content not found"));
1037 return; 1015 return;
1038 } 1016 }
1039 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1017 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1043,11 +1021,8 @@ remove_continuation (void *cls,
1043 gettext_noop ("# bytes removed (explicit request)"), 1021 gettext_noop ("# bytes removed (explicit request)"),
1044 size, 1022 size,
1045 GNUNET_YES); 1023 GNUNET_YES);
1046 GNUNET_CONTAINER_bloomfilter_remove (filter, 1024 GNUNET_CONTAINER_bloomfilter_remove (filter, key);
1047 key); 1025 transmit_status (client, GNUNET_OK, NULL);
1048 transmit_status (client,
1049 GNUNET_OK,
1050 NULL);
1051} 1026}
1052 1027
1053 1028
@@ -1059,8 +1034,7 @@ remove_continuation (void *cls,
1059 * @return #GNUNET_OK if @a dm is well-formed 1034 * @return #GNUNET_OK if @a dm is well-formed
1060 */ 1035 */
1061static int 1036static int
1062check_remove (void *cls, 1037check_remove (void *cls, const struct DataMessage *dm)
1063 const struct DataMessage *dm)
1064{ 1038{
1065 if (GNUNET_OK != check_data (dm)) 1039 if (GNUNET_OK != check_data (dm))
1066 { 1040 {
@@ -1079,14 +1053,14 @@ check_remove (void *cls,
1079 * @param message the actual message 1053 * @param message the actual message
1080 */ 1054 */
1081static void 1055static void
1082handle_remove (void *cls, 1056handle_remove (void *cls, const struct DataMessage *dm)
1083 const struct DataMessage *dm)
1084{ 1057{
1085 struct GNUNET_SERVICE_Client *client = cls; 1058 struct GNUNET_SERVICE_Client *client = cls;
1086 1059
1087 GNUNET_STATISTICS_update (stats, 1060 GNUNET_STATISTICS_update (stats,
1088 gettext_noop ("# REMOVE requests received"), 1061 gettext_noop ("# REMOVE requests received"),
1089 1, GNUNET_NO); 1062 1,
1063 GNUNET_NO);
1090 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1064 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1091 "Processing REMOVE request for `%s'\n", 1065 "Processing REMOVE request for `%s'\n",
1092 GNUNET_h2s (&dm->key)); 1066 GNUNET_h2s (&dm->key));
@@ -1107,13 +1081,11 @@ handle_remove (void *cls,
1107 * @param message the actual message 1081 * @param message the actual message
1108 */ 1082 */
1109static void 1083static void
1110handle_drop (void *cls, 1084handle_drop (void *cls, const struct GNUNET_MessageHeader *message)
1111 const struct GNUNET_MessageHeader *message)
1112{ 1085{
1113 struct GNUNET_SERVICE_Client *client = cls; 1086 struct GNUNET_SERVICE_Client *client = cls;
1114 1087
1115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1088 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing DROP request\n");
1116 "Processing DROP request\n");
1117 do_drop = GNUNET_YES; 1089 do_drop = GNUNET_YES;
1118 GNUNET_SERVICE_client_continue (client); 1090 GNUNET_SERVICE_client_continue (client);
1119} 1091}
@@ -1128,21 +1100,21 @@ handle_drop (void *cls,
1128 * 0 for "reset to empty" 1100 * 0 for "reset to empty"
1129 */ 1101 */
1130static void 1102static void
1131disk_utilization_change_cb (void *cls, 1103disk_utilization_change_cb (void *cls, int delta)
1132 int delta)
1133{ 1104{
1134 if ((delta < 0) && (payload < -delta)) 1105 if ((delta < 0) && (payload < -delta))
1135 { 1106 {
1136 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1107 GNUNET_log (
1137 _("Datastore payload must have been inaccurate (%lld < %lld). Recomputing it.\n"), 1108 GNUNET_ERROR_TYPE_WARNING,
1138 (long long) payload, 1109 _ (
1139 (long long) -delta); 1110 "Datastore payload must have been inaccurate (%lld < %lld). Recomputing it.\n"),
1140 plugin->api->estimate_size (plugin->api->cls, 1111 (long long) payload,
1141 &payload); 1112 (long long) -delta);
1113 plugin->api->estimate_size (plugin->api->cls, &payload);
1142 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1114 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1143 _("New payload: %lld\n"), 1115 _ ("New payload: %lld\n"),
1144 (long long) payload); 1116 (long long) payload);
1145 sync_stats (); 1117 sync_stats ();
1146 return; 1118 return;
1147 } 1119 }
1148 payload += delta; 1120 payload += delta;
@@ -1172,10 +1144,11 @@ process_stat_in (void *cls,
1172 GNUNET_assert (GNUNET_NO == stats_worked); 1144 GNUNET_assert (GNUNET_NO == stats_worked);
1173 stats_worked = GNUNET_YES; 1145 stats_worked = GNUNET_YES;
1174 payload += value; 1146 payload += value;
1175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1147 GNUNET_log (
1176 "Notification from statistics about existing payload (%llu), new payload is %llu\n", 1148 GNUNET_ERROR_TYPE_DEBUG,
1177 (unsigned long long) value, 1149 "Notification from statistics about existing payload (%llu), new payload is %llu\n",
1178 (unsigned long long) payload); 1150 (unsigned long long) value,
1151 (unsigned long long) payload);
1179 return GNUNET_OK; 1152 return GNUNET_OK;
1180} 1153}
1181 1154
@@ -1194,19 +1167,16 @@ load_plugin ()
1194 ret->env.duc = &disk_utilization_change_cb; 1167 ret->env.duc = &disk_utilization_change_cb;
1195 ret->env.cls = NULL; 1168 ret->env.cls = NULL;
1196 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1169 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1197 _("Loading `%s' datastore plugin\n"), 1170 _ ("Loading `%s' datastore plugin\n"),
1198 plugin_name); 1171 plugin_name);
1199 GNUNET_asprintf (&libname, 1172 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", plugin_name);
1200 "libgnunet_plugin_datastore_%s",
1201 plugin_name);
1202 ret->short_name = GNUNET_strdup (plugin_name); 1173 ret->short_name = GNUNET_strdup (plugin_name);
1203 ret->lib_name = libname; 1174 ret->lib_name = libname;
1204 ret->api = GNUNET_PLUGIN_load (libname, 1175 ret->api = GNUNET_PLUGIN_load (libname, &ret->env);
1205 &ret->env);
1206 if (NULL == ret->api) 1176 if (NULL == ret->api)
1207 { 1177 {
1208 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1178 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1209 _("Failed to load datastore plugin for `%s'\n"), 1179 _ ("Failed to load datastore plugin for `%s'\n"),
1210 plugin_name); 1180 plugin_name);
1211 GNUNET_free (ret->short_name); 1181 GNUNET_free (ret->short_name);
1212 GNUNET_free (libname); 1182 GNUNET_free (libname);
@@ -1242,10 +1212,10 @@ static void
1242begin_service () 1212begin_service ()
1243{ 1213{
1244 GNUNET_SERVICE_resume (service); 1214 GNUNET_SERVICE_resume (service);
1245 expired_kill_task 1215 expired_kill_task =
1246 = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, 1216 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
1247 &delete_expired, 1217 &delete_expired,
1248 NULL); 1218 NULL);
1249} 1219}
1250 1220
1251 1221
@@ -1258,22 +1228,21 @@ begin_service ()
1258 */ 1228 */
1259static void 1229static void
1260add_key_to_bloomfilter (void *cls, 1230add_key_to_bloomfilter (void *cls,
1261 const struct GNUNET_HashCode *key, 1231 const struct GNUNET_HashCode *key,
1262 unsigned int count) 1232 unsigned int count)
1263{ 1233{
1264 struct GNUNET_CONTAINER_BloomFilter *bf = cls; 1234 struct GNUNET_CONTAINER_BloomFilter *bf = cls;
1265 1235
1266 if (NULL == key) 1236 if (NULL == key)
1267 { 1237 {
1268 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1238 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1269 _("Bloomfilter construction complete.\n")); 1239 _ ("Bloomfilter construction complete.\n"));
1270 begin_service (); 1240 begin_service ();
1271 return; 1241 return;
1272 } 1242 }
1273 1243
1274 while (0 < count--) 1244 while (0 < count--)
1275 GNUNET_CONTAINER_bloomfilter_add (bf, 1245 GNUNET_CONTAINER_bloomfilter_add (bf, key);
1276 key);
1277} 1246}
1278 1247
1279 1248
@@ -1285,8 +1254,7 @@ add_key_to_bloomfilter (void *cls,
1285 * @param success #GNUNET_NO if we failed to read the stat 1254 * @param success #GNUNET_NO if we failed to read the stat
1286 */ 1255 */
1287static void 1256static void
1288process_stat_done (void *cls, 1257process_stat_done (void *cls, int success)
1289 int success)
1290{ 1258{
1291 stat_get = NULL; 1259 stat_get = NULL;
1292 if (NULL != stat_timeout_task) 1260 if (NULL != stat_timeout_task)
@@ -1301,8 +1269,7 @@ process_stat_done (void *cls,
1301 filter = NULL; 1269 filter = NULL;
1302 if (NULL != stats) 1270 if (NULL != stats)
1303 { 1271 {
1304 GNUNET_STATISTICS_destroy (stats, 1272 GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
1305 GNUNET_YES);
1306 stats = NULL; 1273 stats = NULL;
1307 } 1274 }
1308 return; 1275 return;
@@ -1312,28 +1279,26 @@ process_stat_done (void *cls,
1312 { 1279 {
1313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1280 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1314 "Failed to obtain value from statistics service, recomputing it\n"); 1281 "Failed to obtain value from statistics service, recomputing it\n");
1315 plugin->api->estimate_size (plugin->api->cls, 1282 plugin->api->estimate_size (plugin->api->cls, &payload);
1316 &payload);
1317 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1283 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1318 _("New payload: %lld\n"), 1284 _ ("New payload: %lld\n"),
1319 (long long) payload); 1285 (long long) payload);
1320 } 1286 }
1321 1287
1322 if (GNUNET_YES == refresh_bf) 1288 if (GNUNET_YES == refresh_bf)
1323 { 1289 {
1324 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1290 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1325 _("Rebuilding bloomfilter. Please be patient.\n")); 1291 _ ("Rebuilding bloomfilter. Please be patient.\n"));
1326 if (NULL != plugin->api->get_keys) 1292 if (NULL != plugin->api->get_keys)
1327 { 1293 {
1328 plugin->api->get_keys (plugin->api->cls, 1294 plugin->api->get_keys (plugin->api->cls, &add_key_to_bloomfilter, filter);
1329 &add_key_to_bloomfilter,
1330 filter);
1331 return; 1295 return;
1332 } 1296 }
1333 else 1297 else
1334 { 1298 {
1335 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1299 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1336 _("Plugin does not support get_keys function. Please fix!\n")); 1300 _ (
1301 "Plugin does not support get_keys function. Please fix!\n"));
1337 } 1302 }
1338 } 1303 }
1339 begin_service (); 1304 begin_service ();
@@ -1350,8 +1315,7 @@ stat_timeout (void *cls)
1350{ 1315{
1351 stat_timeout_task = NULL; 1316 stat_timeout_task = NULL;
1352 GNUNET_STATISTICS_get_cancel (stat_get); 1317 GNUNET_STATISTICS_get_cancel (stat_get);
1353 process_stat_done (NULL, 1318 process_stat_done (NULL, GNUNET_NO);
1354 GNUNET_NO);
1355} 1319}
1356 1320
1357 1321
@@ -1369,8 +1333,7 @@ cleaning_task (void *cls)
1369 } 1333 }
1370 if (GNUNET_YES == do_drop) 1334 if (GNUNET_YES == do_drop)
1371 { 1335 {
1372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dropping database!\n");
1373 "Dropping database!\n");
1374 plugin->api->drop (plugin->api->cls); 1337 plugin->api->drop (plugin->api->cls);
1375 payload = 0; 1338 payload = 0;
1376 last_sync++; 1339 last_sync++;
@@ -1401,8 +1364,7 @@ cleaning_task (void *cls)
1401 sync_stats (); 1364 sync_stats ();
1402 if (NULL != stats) 1365 if (NULL != stats)
1403 { 1366 {
1404 GNUNET_STATISTICS_destroy (stats, 1367 GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
1405 GNUNET_YES);
1406 stats = NULL; 1368 stats = NULL;
1407 } 1369 }
1408 GNUNET_free (quota_stat_name); 1370 GNUNET_free (quota_stat_name);
@@ -1420,8 +1382,8 @@ cleaning_task (void *cls)
1420 */ 1382 */
1421static void * 1383static void *
1422client_connect_cb (void *cls, 1384client_connect_cb (void *cls,
1423 struct GNUNET_SERVICE_Client *client, 1385 struct GNUNET_SERVICE_Client *client,
1424 struct GNUNET_MQ_Handle *mq) 1386 struct GNUNET_MQ_Handle *mq)
1425{ 1387{
1426 return client; 1388 return client;
1427} 1389}
@@ -1437,8 +1399,8 @@ client_connect_cb (void *cls,
1437 */ 1399 */
1438static void 1400static void
1439client_disconnect_cb (void *cls, 1401client_disconnect_cb (void *cls,
1440 struct GNUNET_SERVICE_Client *client, 1402 struct GNUNET_SERVICE_Client *client,
1441 void *app_ctx) 1403 void *app_ctx)
1442{ 1404{
1443 struct ReservationList *pos; 1405 struct ReservationList *pos;
1444 struct ReservationList *prev; 1406 struct ReservationList *prev;
@@ -1469,7 +1431,6 @@ client_disconnect_cb (void *cls,
1469 gettext_noop ("# reserved"), 1431 gettext_noop ("# reserved"),
1470 reserved, 1432 reserved,
1471 GNUNET_NO); 1433 GNUNET_NO);
1472
1473} 1434}
1474 1435
1475 1436
@@ -1491,11 +1452,10 @@ run (void *cls,
1491 1452
1492 service = serv; 1453 service = serv;
1493 cfg = c; 1454 cfg = c;
1494 if (GNUNET_OK != 1455 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
1495 GNUNET_CONFIGURATION_get_value_string (cfg, 1456 "DATASTORE",
1496 "DATASTORE", 1457 "DATABASE",
1497 "DATABASE", 1458 &plugin_name))
1498 &plugin_name))
1499 { 1459 {
1500 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 1460 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
1501 "DATABASE", 1461 "DATABASE",
@@ -1503,26 +1463,17 @@ run (void *cls,
1503 return; 1463 return;
1504 } 1464 }
1505 GNUNET_asprintf (&quota_stat_name, 1465 GNUNET_asprintf (&quota_stat_name,
1506 _("# bytes used in file-sharing datastore `%s'"), 1466 _ ("# bytes used in file-sharing datastore `%s'"),
1507 plugin_name); 1467 plugin_name);
1508 if (GNUNET_OK != 1468 if (GNUNET_OK !=
1509 GNUNET_CONFIGURATION_get_value_size (cfg, 1469 GNUNET_CONFIGURATION_get_value_size (cfg, "DATASTORE", "QUOTA", &quota))
1510 "DATASTORE",
1511 "QUOTA",
1512 &quota))
1513 { 1470 {
1514 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 1471 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "QUOTA", "DATASTORE");
1515 "QUOTA",
1516 "DATASTORE");
1517 return; 1472 return;
1518 } 1473 }
1519 stats = GNUNET_STATISTICS_create ("datastore", 1474 stats = GNUNET_STATISTICS_create ("datastore", cfg);
1520 cfg); 1475 GNUNET_STATISTICS_set (stats, gettext_noop ("# quota"), quota, GNUNET_NO);
1521 GNUNET_STATISTICS_set (stats, 1476 cache_size = quota / 8; /* Or should we make this an option? */
1522 gettext_noop ("# quota"),
1523 quota,
1524 GNUNET_NO);
1525 cache_size = quota / 8; /* Or should we make this an option? */
1526 GNUNET_STATISTICS_set (stats, 1477 GNUNET_STATISTICS_set (stats,
1527 gettext_noop ("# cache size"), 1478 gettext_noop ("# cache size"),
1528 cache_size, 1479 cache_size,
@@ -1530,17 +1481,17 @@ run (void *cls,
1530 if (quota / (32 * 1024LL) > MAX_BF_SIZE) 1481 if (quota / (32 * 1024LL) > MAX_BF_SIZE)
1531 bf_size = MAX_BF_SIZE; 1482 bf_size = MAX_BF_SIZE;
1532 else 1483 else
1533 bf_size = quota / (32 * 1024LL); /* 8 bit per entry, 1 bit per 32 kb in DB */ 1484 bf_size =
1485 quota / (32 * 1024LL); /* 8 bit per entry, 1 bit per 32 kb in DB */
1534 fn = NULL; 1486 fn = NULL;
1535 if ((GNUNET_OK != 1487 if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
1536 GNUNET_CONFIGURATION_get_value_filename (cfg, 1488 "DATASTORE",
1537 "DATASTORE", 1489 "BLOOMFILTER",
1538 "BLOOMFILTER", 1490 &fn)) ||
1539 &fn)) ||
1540 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn))) 1491 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)))
1541 { 1492 {
1542 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1493 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1543 _("Could not use specified filename `%s' for bloomfilter.\n"), 1494 _ ("Could not use specified filename `%s' for bloomfilter.\n"),
1544 NULL != fn ? fn : ""); 1495 NULL != fn ? fn : "");
1545 GNUNET_free_non_null (fn); 1496 GNUNET_free_non_null (fn);
1546 fn = NULL; 1497 fn = NULL;
@@ -1550,139 +1501,150 @@ run (void *cls,
1550 GNUNET_asprintf (&pfn, "%s.%s", fn, plugin_name); 1501 GNUNET_asprintf (&pfn, "%s.%s", fn, plugin_name);
1551 if (GNUNET_YES == GNUNET_DISK_file_test (pfn)) 1502 if (GNUNET_YES == GNUNET_DISK_file_test (pfn))
1552 { 1503 {
1553 filter = GNUNET_CONTAINER_bloomfilter_load (pfn, bf_size, 5); /* approx. 3% false positives at max use */ 1504 filter =
1505 GNUNET_CONTAINER_bloomfilter_load (pfn,
1506 bf_size,
1507 5); /* approx. 3% false positives at max use */
1554 if (NULL == filter) 1508 if (NULL == filter)
1555 { 1509 {
1556 /* file exists but not valid, remove and try again, but refresh */ 1510 /* file exists but not valid, remove and try again, but refresh */
1557 if (0 != UNLINK (pfn)) 1511 if (0 != unlink (pfn))
1558 { 1512 {
1559 /* failed to remove, run without file */ 1513 /* failed to remove, run without file */
1560 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1514 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1561 _("Failed to remove bogus bloomfilter file `%s'\n"), 1515 _ ("Failed to remove bogus bloomfilter file `%s'\n"),
1562 pfn); 1516 pfn);
1563 GNUNET_free (pfn); 1517 GNUNET_free (pfn);
1564 pfn = NULL; 1518 pfn = NULL;
1565 filter = GNUNET_CONTAINER_bloomfilter_load (NULL, bf_size, 5); /* approx. 3% false positives at max use */ 1519 filter = GNUNET_CONTAINER_bloomfilter_load (
1566 refresh_bf = GNUNET_YES; 1520 NULL,
1567 } 1521 bf_size,
1568 else 1522 5); /* approx. 3% false positives at max use */
1569 { 1523 refresh_bf = GNUNET_YES;
1570 /* try again after remove */ 1524 }
1571 filter = GNUNET_CONTAINER_bloomfilter_load (pfn, bf_size, 5); /* approx. 3% false positives at max use */ 1525 else
1572 refresh_bf = GNUNET_YES; 1526 {
1573 if (NULL == filter) 1527 /* try again after remove */
1574 { 1528 filter = GNUNET_CONTAINER_bloomfilter_load (
1575 /* failed yet again, give up on using file */ 1529 pfn,
1576 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1530 bf_size,
1577 _("Failed to remove bogus bloomfilter file `%s'\n"), 1531 5); /* approx. 3% false positives at max use */
1578 pfn); 1532 refresh_bf = GNUNET_YES;
1579 GNUNET_free (pfn); 1533 if (NULL == filter)
1580 pfn = NULL; 1534 {
1581 filter = GNUNET_CONTAINER_bloomfilter_init (NULL, bf_size, 5); /* approx. 3% false positives at max use */ 1535 /* failed yet again, give up on using file */
1582 } 1536 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1583 } 1537 _ ("Failed to remove bogus bloomfilter file `%s'\n"),
1538 pfn);
1539 GNUNET_free (pfn);
1540 pfn = NULL;
1541 filter = GNUNET_CONTAINER_bloomfilter_init (
1542 NULL,
1543 bf_size,
1544 5); /* approx. 3% false positives at max use */
1545 }
1546 }
1584 } 1547 }
1585 else 1548 else
1586 { 1549 {
1587 /* normal case: have an existing valid bf file, no need to refresh */ 1550 /* normal case: have an existing valid bf file, no need to refresh */
1588 refresh_bf = GNUNET_NO; 1551 refresh_bf = GNUNET_NO;
1589 } 1552 }
1590 } 1553 }
1591 else 1554 else
1592 { 1555 {
1593 filter = GNUNET_CONTAINER_bloomfilter_load (pfn, bf_size, 5); /* approx. 3% false positives at max use */ 1556 filter =
1557 GNUNET_CONTAINER_bloomfilter_load (pfn,
1558 bf_size,
1559 5); /* approx. 3% false positives at max use */
1594 refresh_bf = GNUNET_YES; 1560 refresh_bf = GNUNET_YES;
1595 } 1561 }
1596 GNUNET_free (pfn); 1562 GNUNET_free (pfn);
1597 } 1563 }
1598 else 1564 else
1599 { 1565 {
1600 filter = GNUNET_CONTAINER_bloomfilter_init (NULL, 1566 filter =
1601 bf_size, 1567 GNUNET_CONTAINER_bloomfilter_init (NULL,
1602 5); /* approx. 3% false positives at max use */ 1568 bf_size,
1569 5); /* approx. 3% false positives at max use */
1603 refresh_bf = GNUNET_YES; 1570 refresh_bf = GNUNET_YES;
1604 } 1571 }
1605 GNUNET_free_non_null (fn); 1572 GNUNET_free_non_null (fn);
1606 if (NULL == filter) 1573 if (NULL == filter)
1607 { 1574 {
1608 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1575 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1609 _("Failed to initialize bloomfilter.\n")); 1576 _ ("Failed to initialize bloomfilter.\n"));
1610 if (NULL != stats) 1577 if (NULL != stats)
1611 { 1578 {
1612 GNUNET_STATISTICS_destroy (stats, 1579 GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
1613 GNUNET_YES);
1614 stats = NULL; 1580 stats = NULL;
1615 } 1581 }
1616 return; 1582 return;
1617 } 1583 }
1618 GNUNET_SERVICE_suspend (service); 1584 GNUNET_SERVICE_suspend (service);
1619 stat_get = 1585 stat_get = GNUNET_STATISTICS_get (stats,
1620 GNUNET_STATISTICS_get (stats, 1586 "datastore",
1621 "datastore", 1587 quota_stat_name,
1622 quota_stat_name, 1588 &process_stat_done,
1623 &process_stat_done, 1589 &process_stat_in,
1624 &process_stat_in, 1590 NULL);
1625 NULL);
1626 if (NULL == stat_get) 1591 if (NULL == stat_get)
1627 process_stat_done (NULL, 1592 process_stat_done (NULL, GNUNET_SYSERR);
1628 GNUNET_SYSERR);
1629 else 1593 else
1630 stat_timeout_task 1594 stat_timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
1631 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 1595 &stat_timeout,
1632 &stat_timeout, 1596 NULL);
1633 NULL); 1597 GNUNET_SCHEDULER_add_shutdown (&cleaning_task, NULL);
1634 GNUNET_SCHEDULER_add_shutdown (&cleaning_task,
1635 NULL);
1636} 1598}
1637 1599
1638 1600
1639/** 1601/**
1640 * Define "main" method using service macro. 1602 * Define "main" method using service macro.
1641 */ 1603 */
1642GNUNET_SERVICE_MAIN 1604GNUNET_SERVICE_MAIN (
1643("datastore", 1605 "datastore",
1644 GNUNET_SERVICE_OPTION_NONE, 1606 GNUNET_SERVICE_OPTION_NONE,
1645 &run, 1607 &run,
1646 &client_connect_cb, 1608 &client_connect_cb,
1647 &client_disconnect_cb, 1609 &client_disconnect_cb,
1648 NULL, 1610 NULL,
1649 GNUNET_MQ_hd_fixed_size (reserve, 1611 GNUNET_MQ_hd_fixed_size (reserve,
1650 GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE, 1612 GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE,
1651 struct ReserveMessage, 1613 struct ReserveMessage,
1652 NULL), 1614 NULL),
1653 GNUNET_MQ_hd_fixed_size (release_reserve, 1615 GNUNET_MQ_hd_fixed_size (release_reserve,
1654 GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE, 1616 GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE,
1655 struct ReleaseReserveMessage, 1617 struct ReleaseReserveMessage,
1656 NULL), 1618 NULL),
1657 GNUNET_MQ_hd_var_size (put, 1619 GNUNET_MQ_hd_var_size (put,
1658 GNUNET_MESSAGE_TYPE_DATASTORE_PUT, 1620 GNUNET_MESSAGE_TYPE_DATASTORE_PUT,
1659 struct DataMessage, 1621 struct DataMessage,
1660 NULL), 1622 NULL),
1661 GNUNET_MQ_hd_fixed_size (get, 1623 GNUNET_MQ_hd_fixed_size (get,
1662 GNUNET_MESSAGE_TYPE_DATASTORE_GET, 1624 GNUNET_MESSAGE_TYPE_DATASTORE_GET,
1663 struct GetMessage, 1625 struct GetMessage,
1664 NULL), 1626 NULL),
1665 GNUNET_MQ_hd_fixed_size (get_key, 1627 GNUNET_MQ_hd_fixed_size (get_key,
1666 GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY, 1628 GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY,
1667 struct GetKeyMessage, 1629 struct GetKeyMessage,
1668 NULL), 1630 NULL),
1669 GNUNET_MQ_hd_fixed_size (get_replication, 1631 GNUNET_MQ_hd_fixed_size (get_replication,
1670 GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION, 1632 GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION,
1671 struct GNUNET_MessageHeader, 1633 struct GNUNET_MessageHeader,
1672 NULL), 1634 NULL),
1673 GNUNET_MQ_hd_fixed_size (get_zero_anonymity, 1635 GNUNET_MQ_hd_fixed_size (get_zero_anonymity,
1674 GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY, 1636 GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY,
1675 struct GetZeroAnonymityMessage, 1637 struct GetZeroAnonymityMessage,
1676 NULL), 1638 NULL),
1677 GNUNET_MQ_hd_var_size (remove, 1639 GNUNET_MQ_hd_var_size (remove,
1678 GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE, 1640 GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE,
1679 struct DataMessage, 1641 struct DataMessage,
1680 NULL), 1642 NULL),
1681 GNUNET_MQ_hd_fixed_size (drop, 1643 GNUNET_MQ_hd_fixed_size (drop,
1682 GNUNET_MESSAGE_TYPE_DATASTORE_DROP, 1644 GNUNET_MESSAGE_TYPE_DATASTORE_DROP,
1683 struct GNUNET_MessageHeader, 1645 struct GNUNET_MessageHeader,
1684 NULL), 1646 NULL),
1685 GNUNET_MQ_handler_end ()); 1647 GNUNET_MQ_handler_end ());
1686 1648
1687 1649
1688/* end of gnunet-service-datastore.c */ 1650/* end of gnunet-service-datastore.c */
diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c
index 2c261b155..96ec9e924 100644
--- a/src/datastore/perf_datastore_api.c
+++ b/src/datastore/perf_datastore_api.c
@@ -211,7 +211,7 @@ check_success (void *cls,
211 struct CpsRunContext *crc = cls; 211 struct CpsRunContext *crc = cls;
212 212
213#if REPORT_ID 213#if REPORT_ID
214 FPRINTF (stderr, "%s", (GNUNET_OK == success) ? "I" : "i"); 214 fprintf (stderr, "%s", (GNUNET_OK == success) ? "I" : "i");
215#endif 215#endif
216 if (GNUNET_OK != success) 216 if (GNUNET_OK != success)
217 { 217 {
@@ -285,7 +285,7 @@ remove_next (void *cls,
285 return; 285 return;
286 } 286 }
287#if REPORT_ID 287#if REPORT_ID
288 FPRINTF (stderr, "%s", "D"); 288 fprintf (stderr, "%s", "D");
289#endif 289#endif
290 GNUNET_assert (GNUNET_OK == success); 290 GNUNET_assert (GNUNET_OK == success);
291 GNUNET_SCHEDULER_add_now (&run_continuation, 291 GNUNET_SCHEDULER_add_now (&run_continuation,
@@ -528,7 +528,7 @@ run_tests (void *cls,
528 528
529 if (success != GNUNET_YES) 529 if (success != GNUNET_YES)
530 { 530 {
531 FPRINTF (stderr, 531 fprintf (stderr,
532 "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", 532 "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n",
533 msg); 533 msg);
534 GNUNET_DATASTORE_disconnect (datastore, 534 GNUNET_DATASTORE_disconnect (datastore,
@@ -573,7 +573,7 @@ run (void *cls,
573 0, 1, 573 0, 1,
574 &run_tests, crc)) 574 &run_tests, crc))
575 { 575 {
576 FPRINTF (stderr, 576 fprintf (stderr,
577 "%s", 577 "%s",
578 "Test 'put' operation failed.\n"); 578 "Test 'put' operation failed.\n");
579 ok = 1; 579 ok = 1;
@@ -608,7 +608,7 @@ main (int argc,
608 &run, 608 &run,
609 NULL)) 609 NULL))
610 return 1; 610 return 1;
611 FPRINTF (stderr, "%s", "\n"); 611 fprintf (stderr, "%s", "\n");
612 return ok; 612 return ok;
613} 613}
614 614
diff --git a/src/datastore/perf_plugin_datastore.c b/src/datastore/perf_plugin_datastore.c
index f68d1f389..564f8f37b 100644
--- a/src/datastore/perf_plugin_datastore.c
+++ b/src/datastore/perf_plugin_datastore.c
@@ -122,7 +122,7 @@ put_continuation (void *cls,
122 122
123 if (GNUNET_OK != status) 123 if (GNUNET_OK != status)
124 { 124 {
125 FPRINTF (stderr, "ERROR: `%s'\n", msg); 125 fprintf (stderr, "ERROR: `%s'\n", msg);
126 } 126 }
127 else 127 else
128 { 128 {
@@ -477,7 +477,7 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
477 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); 477 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
478 if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env))) 478 if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env)))
479 { 479 {
480 FPRINTF (stderr, "Failed to load plugin `%s'!\n", name); 480 fprintf (stderr, "Failed to load plugin `%s'!\n", name);
481 GNUNET_free (name); 481 GNUNET_free (name);
482 GNUNET_free (libname); 482 GNUNET_free (libname);
483 return NULL; 483 return NULL;
@@ -503,7 +503,7 @@ run (void *cls, char *const *args, const char *cfgfile,
503 api = load_plugin (c); 503 api = load_plugin (c);
504 if (api == NULL) 504 if (api == NULL)
505 { 505 {
506 FPRINTF (stderr, 506 fprintf (stderr,
507 "%s", "Could not initialize plugin, assuming database not configured. Test not run!\n"); 507 "%s", "Could not initialize plugin, assuming database not configured. Test not run!\n");
508 return; 508 return;
509 } 509 }
@@ -544,7 +544,7 @@ main (int argc, char *argv[])
544 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, 544 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv,
545 "perf-plugin-datastore", "nohelp", options, &run, NULL); 545 "perf-plugin-datastore", "nohelp", options, &run, NULL);
546 if (ok != 0) 546 if (ok != 0)
547 FPRINTF (stderr, "Missed some testcases: %u\n", ok); 547 fprintf (stderr, "Missed some testcases: %u\n", ok);
548 GNUNET_DISK_directory_remove (dir_name); 548 GNUNET_DISK_directory_remove (dir_name);
549 549
550 return ok; 550 return ok;
diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c
index d548935ea..4bd2b39cb 100644
--- a/src/datastore/plugin_datastore_sqlite.c
+++ b/src/datastore/plugin_datastore_sqlite.c
@@ -1,4 +1,4 @@
1 /* 1/*
2 * This file is part of GNUnet 2 * This file is part of GNUnet
3 * Copyright (C) 2009, 2011, 2017 GNUnet e.V. 3 * Copyright (C) 2009, 2011, 2017 GNUnet e.V.
4 * 4 *
@@ -55,7 +55,17 @@
55 * a failure of the command 'cmd' on file 'filename' 55 * a failure of the command 'cmd' on file 'filename'
56 * with the message given by strerror(errno). 56 * with the message given by strerror(errno).
57 */ 57 */
58#define LOG_SQLITE(db, level, cmd) do { GNUNET_log_from (level, "sqlite", _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); } while(0) 58#define LOG_SQLITE(db, level, cmd) \
59 do \
60 { \
61 GNUNET_log_from (level, \
62 "sqlite", \
63 _ ("`%s' failed at %s:%d with error: %s\n"), \
64 cmd, \
65 __FILE__, \
66 __LINE__, \
67 sqlite3_errmsg (db->dbh)); \
68 } while (0)
59 69
60 70
61/** 71/**
@@ -63,8 +73,23 @@
63 * a failure of the command 'cmd' on file 'filename' 73 * a failure of the command 'cmd' on file 'filename'
64 * with the message given by strerror(errno). 74 * with the message given by strerror(errno).
65 */ 75 */
66#define LOG_SQLITE_MSG(db, msg, level, cmd) do { GNUNET_log_from (level, "sqlite", _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); GNUNET_asprintf(msg, _("`%s' failed at %s:%u with error: %s"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); } while(0) 76#define LOG_SQLITE_MSG(db, msg, level, cmd) \
67 77 do \
78 { \
79 GNUNET_log_from (level, \
80 "sqlite", \
81 _ ("`%s' failed at %s:%d with error: %s\n"), \
82 cmd, \
83 __FILE__, \
84 __LINE__, \
85 sqlite3_errmsg (db->dbh)); \
86 GNUNET_asprintf (msg, \
87 _ ("`%s' failed at %s:%u with error: %s"), \
88 cmd, \
89 __FILE__, \
90 __LINE__, \
91 sqlite3_errmsg (db->dbh)); \
92 } while (0)
68 93
69 94
70/** 95/**
@@ -141,7 +166,6 @@ struct Plugin
141 * Should the database be dropped on shutdown? 166 * Should the database be dropped on shutdown?
142 */ 167 */
143 int drop_on_shutdown; 168 int drop_on_shutdown;
144
145}; 169};
146 170
147 171
@@ -154,9 +178,7 @@ struct Plugin
154 * @return 0 on success 178 * @return 0 on success
155 */ 179 */
156static int 180static int
157sq_prepare (sqlite3 *dbh, 181sq_prepare (sqlite3 *dbh, const char *zSql, sqlite3_stmt **ppStmt)
158 const char *zSql,
159 sqlite3_stmt **ppStmt)
160{ 182{
161 char *dummy; 183 char *dummy;
162 int result; 184 int result;
@@ -182,37 +204,56 @@ sq_prepare (sqlite3 *dbh,
182 * @param dbh handle to the database 204 * @param dbh handle to the database
183 */ 205 */
184static void 206static void
185create_indices (sqlite3 * dbh) 207create_indices (sqlite3 *dbh)
186{ 208{
187 /* create indices */ 209 /* create indices */
188 if (0 != 210 if (
189 (SQLITE_OK != 211 0 !=
190 sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS idx_hash ON gn091 (hash)", 212 (SQLITE_OK !=
191 NULL, NULL, NULL)) + 213 sqlite3_exec (dbh,
214 "CREATE INDEX IF NOT EXISTS idx_hash ON gn091 (hash)",
215 NULL,
216 NULL,
217 NULL)) +
192 (SQLITE_OK != 218 (SQLITE_OK !=
193 sqlite3_exec (dbh, 219 sqlite3_exec (
194 "CREATE INDEX IF NOT EXISTS idx_anon_type ON gn091 (anonLevel ASC,type)", 220 dbh,
195 NULL, NULL, NULL)) + 221 "CREATE INDEX IF NOT EXISTS idx_anon_type ON gn091 (anonLevel ASC,type)",
222 NULL,
223 NULL,
224 NULL)) +
196 (SQLITE_OK != 225 (SQLITE_OK !=
197 sqlite3_exec (dbh, 226 sqlite3_exec (dbh,
198 "CREATE INDEX IF NOT EXISTS idx_expire ON gn091 (expire ASC)", 227 "CREATE INDEX IF NOT EXISTS idx_expire ON gn091 (expire ASC)",
199 NULL, NULL, NULL)) + 228 NULL,
229 NULL,
230 NULL)) +
200 (SQLITE_OK != 231 (SQLITE_OK !=
201 sqlite3_exec (dbh, 232 sqlite3_exec (
202 "CREATE INDEX IF NOT EXISTS idx_repl_rvalue ON gn091 (repl,rvalue)", 233 dbh,
203 NULL, NULL, NULL)) ) 234 "CREATE INDEX IF NOT EXISTS idx_repl_rvalue ON gn091 (repl,rvalue)",
204 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "sqlite", 235 NULL,
205 "Failed to create indices: %s\n", sqlite3_errmsg (dbh)); 236 NULL,
237 NULL)))
238 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
239 "sqlite",
240 "Failed to create indices: %s\n",
241 sqlite3_errmsg (dbh));
206} 242}
207 243
208 244
209#if 0 245#if 0
210#define CHECK(a) GNUNET_break(a) 246#define CHECK(a) GNUNET_break (a)
211#define ENULL NULL 247#define ENULL NULL
212#else 248#else
213#define ENULL &e 249#define ENULL &e
214#define ENULL_DEFINED 1 250#define ENULL_DEFINED 1
215#define CHECK(a) if (! (a)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s\n", e); sqlite3_free(e); } 251#define CHECK(a) \
252 if (! (a)) \
253 { \
254 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", e); \
255 sqlite3_free (e); \
256 }
216#endif 257#endif
217 258
218 259
@@ -235,21 +276,19 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
235 char *e; 276 char *e;
236#endif 277#endif
237 278
238 if (GNUNET_OK != 279 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
239 GNUNET_CONFIGURATION_get_value_filename (cfg, 280 "datastore-sqlite",
240 "datastore-sqlite", 281 "FILENAME",
241 "FILENAME", 282 &afsdir))
242 &afsdir))
243 { 283 {
244 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 284 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
245 "datastore-sqlite", 285 "datastore-sqlite",
246 "FILENAME"); 286 "FILENAME");
247 return GNUNET_SYSERR; 287 return GNUNET_SYSERR;
248 } 288 }
249 if (GNUNET_OK != GNUNET_DISK_file_test (afsdir)) 289 if (GNUNET_OK != GNUNET_DISK_file_test (afsdir))
250 { 290 {
251 if (GNUNET_OK != 291 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (afsdir))
252 GNUNET_DISK_directory_create_for_file (afsdir))
253 { 292 {
254 GNUNET_break (0); 293 GNUNET_break (0);
255 GNUNET_free (afsdir); 294 GNUNET_free (afsdir);
@@ -257,48 +296,46 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
257 } 296 }
258 /* database is new or got deleted, reset payload to zero! */ 297 /* database is new or got deleted, reset payload to zero! */
259 if (NULL != plugin->env->duc) 298 if (NULL != plugin->env->duc)
260 plugin->env->duc (plugin->env->cls, 299 plugin->env->duc (plugin->env->cls, 0);
261 0);
262 } 300 }
263 /* afsdir should be UTF-8-encoded. If it isn't, it's a bug */ 301 /* afsdir should be UTF-8-encoded. If it isn't, it's a bug */
264 plugin->fn = afsdir; 302 plugin->fn = afsdir;
265 303
266 /* Open database and precompile statements */ 304 /* Open database and precompile statements */
267 if (SQLITE_OK != 305 if (SQLITE_OK != sqlite3_open (plugin->fn, &plugin->dbh))
268 sqlite3_open (plugin->fn, &plugin->dbh))
269 { 306 {
270 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "sqlite", 307 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
271 _("Unable to initialize SQLite: %s.\n"), 308 "sqlite",
309 _ ("Unable to initialize SQLite: %s.\n"),
272 sqlite3_errmsg (plugin->dbh)); 310 sqlite3_errmsg (plugin->dbh));
273 return GNUNET_SYSERR; 311 return GNUNET_SYSERR;
274 } 312 }
275 CHECK (SQLITE_OK == 313 CHECK (
276 sqlite3_exec (plugin->dbh, 314 SQLITE_OK ==
277 "PRAGMA temp_store=MEMORY", NULL, NULL, 315 sqlite3_exec (plugin->dbh, "PRAGMA temp_store=MEMORY", NULL, NULL, ENULL));
278 ENULL)); 316 CHECK (
279 CHECK (SQLITE_OK == 317 SQLITE_OK ==
280 sqlite3_exec (plugin->dbh, 318 sqlite3_exec (plugin->dbh, "PRAGMA synchronous=OFF", NULL, NULL, ENULL));
281 "PRAGMA synchronous=OFF", NULL, NULL, 319 CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh,
282 ENULL)); 320 "PRAGMA legacy_file_format=OFF",
283 CHECK (SQLITE_OK == 321 NULL,
284 sqlite3_exec (plugin->dbh, 322 NULL,
285 "PRAGMA legacy_file_format=OFF", NULL, NULL, 323 ENULL));
286 ENULL)); 324 CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh,
287 CHECK (SQLITE_OK == 325 "PRAGMA auto_vacuum=INCREMENTAL",
288 sqlite3_exec (plugin->dbh, 326 NULL,
289 "PRAGMA auto_vacuum=INCREMENTAL", NULL, 327 NULL,
290 NULL, ENULL)); 328 ENULL));
291 CHECK (SQLITE_OK == 329 CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh,
292 sqlite3_exec (plugin->dbh, 330 "PRAGMA locking_mode=EXCLUSIVE",
293 "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, 331 NULL,
294 ENULL)); 332 NULL,
295 CHECK (SQLITE_OK == 333 ENULL));
296 sqlite3_exec (plugin->dbh, 334 CHECK (
297 "PRAGMA page_size=4096", NULL, NULL, 335 SQLITE_OK ==
298 ENULL)); 336 sqlite3_exec (plugin->dbh, "PRAGMA page_size=4096", NULL, NULL, ENULL));
299 337
300 CHECK (SQLITE_OK == 338 CHECK (SQLITE_OK == sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS));
301 sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS));
302 339
303 340
304 /* We have to do it here, because otherwise precompiling SQL might fail */ 341 /* We have to do it here, because otherwise precompiling SQL might fail */
@@ -312,152 +349,135 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
312 * we do math or inequality tests, so we can't handle the entire range of uint32_t. 349 * we do math or inequality tests, so we can't handle the entire range of uint32_t.
313 * This will also cause problems for expiration times after 294247-01-10-04:00:54 UTC. 350 * This will also cause problems for expiration times after 294247-01-10-04:00:54 UTC.
314 */ 351 */
315 if ( (SQLITE_DONE == 352 if ((SQLITE_DONE == sqlite3_step (stmt)) &&
316 sqlite3_step (stmt)) && 353 (SQLITE_OK != sqlite3_exec (plugin->dbh,
317 (SQLITE_OK != 354 "CREATE TABLE gn091 ("
318 sqlite3_exec (plugin->dbh, 355 " repl INT4 NOT NULL DEFAULT 0,"
319 "CREATE TABLE gn091 (" 356 " type INT4 NOT NULL DEFAULT 0,"
320 " repl INT4 NOT NULL DEFAULT 0," 357 " prio INT4 NOT NULL DEFAULT 0,"
321 " type INT4 NOT NULL DEFAULT 0," 358 " anonLevel INT4 NOT NULL DEFAULT 0,"
322 " prio INT4 NOT NULL DEFAULT 0," 359 " expire INT8 NOT NULL DEFAULT 0,"
323 " anonLevel INT4 NOT NULL DEFAULT 0," 360 " rvalue INT8 NOT NULL,"
324 " expire INT8 NOT NULL DEFAULT 0," 361 " hash TEXT NOT NULL DEFAULT '',"
325 " rvalue INT8 NOT NULL," 362 " vhash TEXT NOT NULL DEFAULT '',"
326 " hash TEXT NOT NULL DEFAULT ''," 363 " value BLOB NOT NULL DEFAULT '')",
327 " vhash TEXT NOT NULL DEFAULT ''," 364 NULL,
328 " value BLOB NOT NULL DEFAULT '')", 365 NULL,
329 NULL, 366 NULL)))
330 NULL,
331 NULL)) )
332 { 367 {
333 LOG_SQLITE (plugin, 368 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec");
334 GNUNET_ERROR_TYPE_ERROR,
335 "sqlite3_exec");
336 sqlite3_finalize (stmt); 369 sqlite3_finalize (stmt);
337 return GNUNET_SYSERR; 370 return GNUNET_SYSERR;
338 } 371 }
339 sqlite3_finalize (stmt); 372 sqlite3_finalize (stmt);
340 create_indices (plugin->dbh); 373 create_indices (plugin->dbh);
341 374
342#define RESULT_COLUMNS "repl, type, prio, anonLevel, expire, hash, value, _ROWID_" 375#define RESULT_COLUMNS \
343 if ( (SQLITE_OK != 376 "repl, type, prio, anonLevel, expire, hash, value, _ROWID_"
344 sq_prepare (plugin->dbh, 377 if (
345 "UPDATE gn091 " 378 (SQLITE_OK != sq_prepare (plugin->dbh,
346 "SET prio = prio + ?, " 379 "UPDATE gn091 "
347 "repl = repl + ?, " 380 "SET prio = prio + ?, "
348 "expire = MAX(expire, ?) " 381 "repl = repl + ?, "
349 "WHERE hash = ? AND vhash = ?", 382 "expire = MAX(expire, ?) "
350 &plugin->update)) || 383 "WHERE hash = ? AND vhash = ?",
351 (SQLITE_OK != 384 &plugin->update)) ||
352 sq_prepare (plugin->dbh, 385 (SQLITE_OK != sq_prepare (plugin->dbh,
353 "UPDATE gn091 " "SET repl = MAX (0, repl - 1) WHERE _ROWID_ = ?", 386 "UPDATE gn091 "
354 &plugin->updRepl)) || 387 "SET repl = MAX (0, repl - 1) WHERE _ROWID_ = ?",
355 (SQLITE_OK != 388 &plugin->updRepl)) ||
356 sq_prepare (plugin->dbh, 389 (SQLITE_OK != sq_prepare (plugin->dbh,
357 "SELECT " RESULT_COLUMNS " FROM gn091 " 390 "SELECT " RESULT_COLUMNS " FROM gn091 "
358 "WHERE repl=?2 AND " " (rvalue>=?1 OR " 391 "WHERE repl=?2 AND "
359 " NOT EXISTS (SELECT 1 FROM gn091 " 392 " (rvalue>=?1 OR "
360 "WHERE repl=?2 AND rvalue>=?1 LIMIT 1) ) " 393 " NOT EXISTS (SELECT 1 FROM gn091 "
361 "ORDER BY rvalue ASC LIMIT 1", 394 "WHERE repl=?2 AND rvalue>=?1 LIMIT 1) ) "
362 &plugin->selRepl)) || 395 "ORDER BY rvalue ASC LIMIT 1",
363 (SQLITE_OK != 396 &plugin->selRepl)) ||
364 sq_prepare (plugin->dbh, 397 (SQLITE_OK != sq_prepare (plugin->dbh,
365 "SELECT MAX(repl) FROM gn091", 398 "SELECT MAX(repl) FROM gn091",
366 &plugin->maxRepl)) || 399 &plugin->maxRepl)) ||
367 (SQLITE_OK != 400 (SQLITE_OK !=
368 sq_prepare (plugin->dbh, 401 sq_prepare (plugin->dbh,
369 "SELECT " RESULT_COLUMNS " FROM gn091 " 402 "SELECT " RESULT_COLUMNS " FROM gn091 "
370 "WHERE NOT EXISTS (SELECT 1 FROM gn091 WHERE expire < ?1 LIMIT 1) OR (expire < ?1) " 403 "WHERE NOT EXISTS (SELECT 1 FROM gn091 WHERE expire < ?1 LIMIT 1) OR (expire < ?1) "
371 "ORDER BY expire ASC LIMIT 1", 404 "ORDER BY expire ASC LIMIT 1",
372 &plugin->selExpi)) || 405 &plugin->selExpi)) ||
373 (SQLITE_OK != 406 (SQLITE_OK != sq_prepare (plugin->dbh,
374 sq_prepare (plugin->dbh, 407 "SELECT " RESULT_COLUMNS " FROM gn091 "
375 "SELECT " RESULT_COLUMNS " FROM gn091 " 408 "WHERE _ROWID_ >= ? AND "
376 "WHERE _ROWID_ >= ? AND " 409 "anonLevel = 0 AND "
377 "anonLevel = 0 AND " 410 "type = ? "
378 "type = ? " 411 "ORDER BY _ROWID_ ASC LIMIT 1",
379 "ORDER BY _ROWID_ ASC LIMIT 1", 412 &plugin->selZeroAnon)) ||
380 &plugin->selZeroAnon)) || 413 (SQLITE_OK !=
381 (SQLITE_OK != 414 sq_prepare (plugin->dbh,
382 sq_prepare (plugin->dbh, 415 "INSERT INTO gn091 (repl, type, prio, anonLevel, expire, rvalue, hash, vhash, value) "
383 "INSERT INTO gn091 (repl, type, prio, anonLevel, expire, rvalue, hash, vhash, value) " 416 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
384 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", 417 &plugin->insertContent)) ||
385 &plugin->insertContent)) || 418 (SQLITE_OK != sq_prepare (plugin->dbh,
386 (SQLITE_OK != 419 "SELECT " RESULT_COLUMNS " FROM gn091 "
387 sq_prepare (plugin->dbh, 420 "WHERE _ROWID_ >= ?1 "
388 "SELECT " RESULT_COLUMNS " FROM gn091 " 421 "ORDER BY _ROWID_ ASC LIMIT 1",
389 "WHERE _ROWID_ >= ?1 " 422 &plugin->get[0])) ||
390 "ORDER BY _ROWID_ ASC LIMIT 1", 423 (SQLITE_OK != sq_prepare (plugin->dbh,
391 &plugin->get[0])) || 424 "SELECT " RESULT_COLUMNS " FROM gn091 "
392 (SQLITE_OK != 425 "WHERE _ROWID_ >= ?1 AND "
393 sq_prepare (plugin->dbh, 426 "type = ?4 "
394 "SELECT " RESULT_COLUMNS " FROM gn091 " 427 "ORDER BY _ROWID_ ASC LIMIT 1",
395 "WHERE _ROWID_ >= ?1 AND " 428 &plugin->get[1])) ||
396 "type = ?4 " 429 (SQLITE_OK != sq_prepare (plugin->dbh,
397 "ORDER BY _ROWID_ ASC LIMIT 1", 430 "SELECT " RESULT_COLUMNS " FROM gn091 "
398 &plugin->get[1])) || 431 "WHERE _ROWID_ >= ?1 AND "
399 (SQLITE_OK != 432 "hash = ?3 "
400 sq_prepare (plugin->dbh, 433 "ORDER BY _ROWID_ ASC LIMIT 1",
401 "SELECT " RESULT_COLUMNS " FROM gn091 " 434 &plugin->get[2])) ||
402 "WHERE _ROWID_ >= ?1 AND " 435 (SQLITE_OK != sq_prepare (plugin->dbh,
403 "hash = ?3 " 436 "SELECT " RESULT_COLUMNS " FROM gn091 "
404 "ORDER BY _ROWID_ ASC LIMIT 1", 437 "WHERE _ROWID_ >= ?1 AND "
405 &plugin->get[2])) || 438 "hash = ?3 AND "
406 (SQLITE_OK != 439 "type = ?4 "
407 sq_prepare (plugin->dbh, 440 "ORDER BY _ROWID_ ASC LIMIT 1",
408 "SELECT " RESULT_COLUMNS " FROM gn091 " 441 &plugin->get[3])) ||
409 "WHERE _ROWID_ >= ?1 AND " 442 (SQLITE_OK != sq_prepare (plugin->dbh,
410 "hash = ?3 AND " 443 "SELECT " RESULT_COLUMNS " FROM gn091 "
411 "type = ?4 " 444 "WHERE _ROWID_ >= ?1 AND "
412 "ORDER BY _ROWID_ ASC LIMIT 1", 445 "rvalue >= ?2 "
413 &plugin->get[3])) || 446 "ORDER BY _ROWID_ ASC LIMIT 1",
414 (SQLITE_OK != 447 &plugin->get[4])) ||
415 sq_prepare (plugin->dbh, 448 (SQLITE_OK != sq_prepare (plugin->dbh,
416 "SELECT " RESULT_COLUMNS " FROM gn091 " 449 "SELECT " RESULT_COLUMNS " FROM gn091 "
417 "WHERE _ROWID_ >= ?1 AND " 450 "WHERE _ROWID_ >= ?1 AND "
418 "rvalue >= ?2 " 451 "rvalue >= ?2 AND "
419 "ORDER BY _ROWID_ ASC LIMIT 1", 452 "type = ?4 "
420 &plugin->get[4])) || 453 "ORDER BY _ROWID_ ASC LIMIT 1",
421 (SQLITE_OK != 454 &plugin->get[5])) ||
422 sq_prepare (plugin->dbh, 455 (SQLITE_OK != sq_prepare (plugin->dbh,
423 "SELECT " RESULT_COLUMNS " FROM gn091 " 456 "SELECT " RESULT_COLUMNS " FROM gn091 "
424 "WHERE _ROWID_ >= ?1 AND " 457 "WHERE _ROWID_ >= ?1 AND "
425 "rvalue >= ?2 AND " 458 "rvalue >= ?2 AND "
426 "type = ?4 " 459 "hash = ?3 "
427 "ORDER BY _ROWID_ ASC LIMIT 1", 460 "ORDER BY _ROWID_ ASC LIMIT 1",
428 &plugin->get[5])) || 461 &plugin->get[6])) ||
429 (SQLITE_OK != 462 (SQLITE_OK != sq_prepare (plugin->dbh,
430 sq_prepare (plugin->dbh, 463 "SELECT " RESULT_COLUMNS " FROM gn091 "
431 "SELECT " RESULT_COLUMNS " FROM gn091 " 464 "WHERE _ROWID_ >= ?1 AND "
432 "WHERE _ROWID_ >= ?1 AND " 465 "rvalue >= ?2 AND "
433 "rvalue >= ?2 AND " 466 "hash = ?3 AND "
434 "hash = ?3 " 467 "type = ?4 "
435 "ORDER BY _ROWID_ ASC LIMIT 1", 468 "ORDER BY _ROWID_ ASC LIMIT 1",
436 &plugin->get[6])) || 469 &plugin->get[7])) ||
437 (SQLITE_OK != 470 (SQLITE_OK != sq_prepare (plugin->dbh,
438 sq_prepare (plugin->dbh, 471 "DELETE FROM gn091 WHERE _ROWID_ = ?",
439 "SELECT " RESULT_COLUMNS " FROM gn091 " 472 &plugin->delRow)) ||
440 "WHERE _ROWID_ >= ?1 AND " 473 (SQLITE_OK != sq_prepare (plugin->dbh,
441 "rvalue >= ?2 AND " 474 "DELETE FROM gn091 "
442 "hash = ?3 AND " 475 "WHERE hash = ? AND "
443 "type = ?4 " 476 "value = ? ",
444 "ORDER BY _ROWID_ ASC LIMIT 1", 477 &plugin->remove)) ||
445 &plugin->get[7])) || 478 false)
446 (SQLITE_OK !=
447 sq_prepare (plugin->dbh,
448 "DELETE FROM gn091 WHERE _ROWID_ = ?",
449 &plugin->delRow)) ||
450 (SQLITE_OK !=
451 sq_prepare (plugin->dbh,
452 "DELETE FROM gn091 "
453 "WHERE hash = ? AND "
454 "value = ? ",
455 &plugin->remove)) ||
456 false)
457 { 479 {
458 LOG_SQLITE (plugin, 480 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "precompiling");
459 GNUNET_ERROR_TYPE_ERROR,
460 "precompiling");
461 return GNUNET_SYSERR; 481 return GNUNET_SYSERR;
462 } 482 }
463 return GNUNET_OK; 483 return GNUNET_OK;
@@ -503,11 +523,12 @@ database_shutdown (struct Plugin *plugin)
503#if SQLITE_VERSION_NUMBER >= 3007000 523#if SQLITE_VERSION_NUMBER >= 3007000
504 if (result == SQLITE_BUSY) 524 if (result == SQLITE_BUSY)
505 { 525 {
506 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, 526 GNUNET_log_from (
507 "sqlite", 527 GNUNET_ERROR_TYPE_WARNING,
508 _("Tried to close sqlite without finalizing all prepared statements.\n")); 528 "sqlite",
509 stmt = sqlite3_next_stmt (plugin->dbh, 529 _ (
510 NULL); 530 "Tried to close sqlite without finalizing all prepared statements.\n"));
531 stmt = sqlite3_next_stmt (plugin->dbh, NULL);
511 while (NULL != stmt) 532 while (NULL != stmt)
512 { 533 {
513 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 534 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
@@ -521,16 +542,13 @@ database_shutdown (struct Plugin *plugin)
521 "Failed to close statement %p: %d\n", 542 "Failed to close statement %p: %d\n",
522 stmt, 543 stmt,
523 result); 544 result);
524 stmt = sqlite3_next_stmt (plugin->dbh, 545 stmt = sqlite3_next_stmt (plugin->dbh, NULL);
525 NULL);
526 } 546 }
527 result = sqlite3_close (plugin->dbh); 547 result = sqlite3_close (plugin->dbh);
528 } 548 }
529#endif 549#endif
530 if (SQLITE_OK != result) 550 if (SQLITE_OK != result)
531 LOG_SQLITE (plugin, 551 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite3_close");
532 GNUNET_ERROR_TYPE_ERROR,
533 "sqlite3_close");
534 GNUNET_free_non_null (plugin->fn); 552 GNUNET_free_non_null (plugin->fn);
535} 553}
536 554
@@ -543,28 +561,22 @@ database_shutdown (struct Plugin *plugin)
543 * @param rid the ID of the row to delete 561 * @param rid the ID of the row to delete
544 */ 562 */
545static int 563static int
546delete_by_rowid (struct Plugin *plugin, 564delete_by_rowid (struct Plugin *plugin, uint64_t rid)
547 uint64_t rid)
548{ 565{
549 struct GNUNET_SQ_QueryParam params[] = { 566 struct GNUNET_SQ_QueryParam params[] = {GNUNET_SQ_query_param_uint64 (&rid),
550 GNUNET_SQ_query_param_uint64 (&rid), 567 GNUNET_SQ_query_param_end};
551 GNUNET_SQ_query_param_end 568
552 }; 569 if (GNUNET_OK != GNUNET_SQ_bind (plugin->delRow, params))
553
554 if (GNUNET_OK !=
555 GNUNET_SQ_bind (plugin->delRow,
556 params))
557 return GNUNET_SYSERR; 570 return GNUNET_SYSERR;
558 if (SQLITE_DONE != sqlite3_step (plugin->delRow)) 571 if (SQLITE_DONE != sqlite3_step (plugin->delRow))
559 { 572 {
560 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 573 LOG_SQLITE (plugin,
574 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
561 "sqlite3_step"); 575 "sqlite3_step");
562 GNUNET_SQ_reset (plugin->dbh, 576 GNUNET_SQ_reset (plugin->dbh, plugin->delRow);
563 plugin->delRow);
564 return GNUNET_SYSERR; 577 return GNUNET_SYSERR;
565 } 578 }
566 GNUNET_SQ_reset (plugin->dbh, 579 GNUNET_SQ_reset (plugin->dbh, plugin->delRow);
567 plugin->delRow);
568 return GNUNET_OK; 580 return GNUNET_OK;
569} 581}
570 582
@@ -603,94 +615,78 @@ sqlite_plugin_put (void *cls,
603 struct GNUNET_HashCode vhash; 615 struct GNUNET_HashCode vhash;
604 char *msg = NULL; 616 char *msg = NULL;
605 617
606 GNUNET_CRYPTO_hash (data, 618 GNUNET_CRYPTO_hash (data, size, &vhash);
607 size,
608 &vhash);
609 619
610 if (!absent) 620 if (! absent)
611 { 621 {
612 struct GNUNET_SQ_QueryParam params[] = { 622 struct GNUNET_SQ_QueryParam params[] =
613 GNUNET_SQ_query_param_uint32 (&priority), 623 {GNUNET_SQ_query_param_uint32 (&priority),
614 GNUNET_SQ_query_param_uint32 (&replication), 624 GNUNET_SQ_query_param_uint32 (&replication),
615 GNUNET_SQ_query_param_absolute_time (&expiration), 625 GNUNET_SQ_query_param_absolute_time (&expiration),
616 GNUNET_SQ_query_param_auto_from_type (key), 626 GNUNET_SQ_query_param_auto_from_type (key),
617 GNUNET_SQ_query_param_auto_from_type (&vhash), 627 GNUNET_SQ_query_param_auto_from_type (&vhash),
618 GNUNET_SQ_query_param_end 628 GNUNET_SQ_query_param_end};
619 }; 629
620 630 if (GNUNET_OK != GNUNET_SQ_bind (plugin->update, params))
621 if (GNUNET_OK !=
622 GNUNET_SQ_bind (plugin->update,
623 params))
624 { 631 {
625 cont (cont_cls, 632 cont (cont_cls, key, size, GNUNET_SYSERR, _ ("sqlite bind failure"));
626 key,
627 size,
628 GNUNET_SYSERR,
629 _("sqlite bind failure"));
630 return; 633 return;
631 } 634 }
632 if (SQLITE_DONE != sqlite3_step (plugin->update)) 635 if (SQLITE_DONE != sqlite3_step (plugin->update))
633 { 636 {
634 LOG_SQLITE_MSG (plugin, &msg, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 637 LOG_SQLITE_MSG (plugin,
638 &msg,
639 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
635 "sqlite3_step"); 640 "sqlite3_step");
636 cont (cont_cls, 641 cont (cont_cls, key, size, GNUNET_SYSERR, msg);
637 key,
638 size,
639 GNUNET_SYSERR,
640 msg);
641 GNUNET_free_non_null (msg); 642 GNUNET_free_non_null (msg);
642 return; 643 return;
643 } 644 }
644 int changes = sqlite3_changes (plugin->dbh); 645 int changes = sqlite3_changes (plugin->dbh);
645 GNUNET_SQ_reset (plugin->dbh, 646 GNUNET_SQ_reset (plugin->dbh, plugin->update);
646 plugin->update);
647 if (0 != changes) 647 if (0 != changes)
648 { 648 {
649 cont (cont_cls, 649 cont (cont_cls, key, size, GNUNET_NO, NULL);
650 key,
651 size,
652 GNUNET_NO,
653 NULL);
654 return; 650 return;
655 } 651 }
656 } 652 }
657 653
658 uint64_t rvalue; 654 uint64_t rvalue;
659 uint32_t type32 = (uint32_t) type; 655 uint32_t type32 = (uint32_t) type;
660 struct GNUNET_SQ_QueryParam params[] = { 656 struct GNUNET_SQ_QueryParam params[] =
661 GNUNET_SQ_query_param_uint32 (&replication), 657 {GNUNET_SQ_query_param_uint32 (&replication),
662 GNUNET_SQ_query_param_uint32 (&type32), 658 GNUNET_SQ_query_param_uint32 (&type32),
663 GNUNET_SQ_query_param_uint32 (&priority), 659 GNUNET_SQ_query_param_uint32 (&priority),
664 GNUNET_SQ_query_param_uint32 (&anonymity), 660 GNUNET_SQ_query_param_uint32 (&anonymity),
665 GNUNET_SQ_query_param_absolute_time (&expiration), 661 GNUNET_SQ_query_param_absolute_time (&expiration),
666 GNUNET_SQ_query_param_uint64 (&rvalue), 662 GNUNET_SQ_query_param_uint64 (&rvalue),
667 GNUNET_SQ_query_param_auto_from_type (key), 663 GNUNET_SQ_query_param_auto_from_type (key),
668 GNUNET_SQ_query_param_auto_from_type (&vhash), 664 GNUNET_SQ_query_param_auto_from_type (&vhash),
669 GNUNET_SQ_query_param_fixed_size (data, size), 665 GNUNET_SQ_query_param_fixed_size (data, size),
670 GNUNET_SQ_query_param_end 666 GNUNET_SQ_query_param_end};
671 };
672 int n; 667 int n;
673 int ret; 668 int ret;
674 sqlite3_stmt *stmt; 669 sqlite3_stmt *stmt;
675 670
676 if (size > MAX_ITEM_SIZE) 671 if (size > MAX_ITEM_SIZE)
677 { 672 {
678 cont (cont_cls, key, size, GNUNET_SYSERR, _("Data too large")); 673 cont (cont_cls, key, size, GNUNET_SYSERR, _ ("Data too large"));
679 return; 674 return;
680 } 675 }
681 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", 676 GNUNET_log_from (
682 "Storing in database block with type %u/key `%s'/priority %u/expiration in %s (%s).\n", 677 GNUNET_ERROR_TYPE_DEBUG,
683 type, 678 "sqlite",
684 GNUNET_h2s (key), 679 "Storing in database block with type %u/key `%s'/priority %u/expiration in %s (%s).\n",
685 priority, 680 type,
686 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (expiration), 681 GNUNET_h2s (key),
687 GNUNET_YES), 682 priority,
688 GNUNET_STRINGS_absolute_time_to_string (expiration)); 683 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (
684 expiration),
685 GNUNET_YES),
686 GNUNET_STRINGS_absolute_time_to_string (expiration));
689 stmt = plugin->insertContent; 687 stmt = plugin->insertContent;
690 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); 688 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
691 if (GNUNET_OK != 689 if (GNUNET_OK != GNUNET_SQ_bind (stmt, params))
692 GNUNET_SQ_bind (stmt,
693 params))
694 { 690 {
695 cont (cont_cls, key, size, GNUNET_SYSERR, NULL); 691 cont (cont_cls, key, size, GNUNET_SYSERR, NULL);
696 return; 692 return;
@@ -702,7 +698,8 @@ sqlite_plugin_put (void *cls,
702 if (NULL != plugin->env->duc) 698 if (NULL != plugin->env->duc)
703 plugin->env->duc (plugin->env->cls, 699 plugin->env->duc (plugin->env->cls,
704 size + GNUNET_DATASTORE_ENTRY_OVERHEAD); 700 size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
705 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", 701 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
702 "sqlite",
706 "Stored new entry (%u bytes)\n", 703 "Stored new entry (%u bytes)\n",
707 size + GNUNET_DATASTORE_ENTRY_OVERHEAD); 704 size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
708 ret = GNUNET_OK; 705 ret = GNUNET_OK;
@@ -710,28 +707,26 @@ sqlite_plugin_put (void *cls,
710 case SQLITE_BUSY: 707 case SQLITE_BUSY:
711 GNUNET_break (0); 708 GNUNET_break (0);
712 LOG_SQLITE_MSG (plugin, 709 LOG_SQLITE_MSG (plugin,
713 &msg, 710 &msg,
714 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 711 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
715 "sqlite3_step"); 712 "sqlite3_step");
716 ret = GNUNET_SYSERR; 713 ret = GNUNET_SYSERR;
717 break; 714 break;
718 default: 715 default:
719 LOG_SQLITE_MSG (plugin, 716 LOG_SQLITE_MSG (plugin,
720 &msg, 717 &msg,
721 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 718 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
722 "sqlite3_step"); 719 "sqlite3_step");
723 GNUNET_SQ_reset (plugin->dbh, 720 GNUNET_SQ_reset (plugin->dbh, stmt);
724 stmt);
725 database_shutdown (plugin); 721 database_shutdown (plugin);
726 database_setup (plugin->env->cfg, plugin); 722 database_setup (plugin->env->cfg, plugin);
727 cont (cont_cls, key, size, GNUNET_SYSERR, msg); 723 cont (cont_cls, key, size, GNUNET_SYSERR, msg);
728 GNUNET_free_non_null(msg); 724 GNUNET_free_non_null (msg);
729 return; 725 return;
730 } 726 }
731 GNUNET_SQ_reset (plugin->dbh, 727 GNUNET_SQ_reset (plugin->dbh, stmt);
732 stmt);
733 cont (cont_cls, key, size, ret, msg); 728 cont (cont_cls, key, size, ret, msg);
734 GNUNET_free_non_null(msg); 729 GNUNET_free_non_null (msg);
735} 730}
736 731
737 732
@@ -761,26 +756,22 @@ execute_get (struct Plugin *plugin,
761 size_t value_size; 756 size_t value_size;
762 struct GNUNET_HashCode key; 757 struct GNUNET_HashCode key;
763 int ret; 758 int ret;
764 struct GNUNET_SQ_ResultSpec rs[] = { 759 struct GNUNET_SQ_ResultSpec rs[] =
765 GNUNET_SQ_result_spec_uint32 (&replication), 760 {GNUNET_SQ_result_spec_uint32 (&replication),
766 GNUNET_SQ_result_spec_uint32 (&type), 761 GNUNET_SQ_result_spec_uint32 (&type),
767 GNUNET_SQ_result_spec_uint32 (&priority), 762 GNUNET_SQ_result_spec_uint32 (&priority),
768 GNUNET_SQ_result_spec_uint32 (&anonymity), 763 GNUNET_SQ_result_spec_uint32 (&anonymity),
769 GNUNET_SQ_result_spec_absolute_time (&expiration), 764 GNUNET_SQ_result_spec_absolute_time (&expiration),
770 GNUNET_SQ_result_spec_auto_from_type (&key), 765 GNUNET_SQ_result_spec_auto_from_type (&key),
771 GNUNET_SQ_result_spec_variable_size (&value, 766 GNUNET_SQ_result_spec_variable_size (&value, &value_size),
772 &value_size), 767 GNUNET_SQ_result_spec_uint64 (&rowid),
773 GNUNET_SQ_result_spec_uint64 (&rowid), 768 GNUNET_SQ_result_spec_end};
774 GNUNET_SQ_result_spec_end
775 };
776 769
777 n = sqlite3_step (stmt); 770 n = sqlite3_step (stmt);
778 switch (n) 771 switch (n)
779 { 772 {
780 case SQLITE_ROW: 773 case SQLITE_ROW:
781 if (GNUNET_OK != 774 if (GNUNET_OK != GNUNET_SQ_extract_result (stmt, rs))
782 GNUNET_SQ_extract_result (stmt,
783 rs))
784 { 775 {
785 GNUNET_break (0); 776 GNUNET_break (0);
786 break; 777 break;
@@ -800,12 +791,9 @@ execute_get (struct Plugin *plugin,
800 expiration, 791 expiration,
801 rowid); 792 rowid);
802 GNUNET_SQ_cleanup_result (rs); 793 GNUNET_SQ_cleanup_result (rs);
803 GNUNET_SQ_reset (plugin->dbh, 794 GNUNET_SQ_reset (plugin->dbh, stmt);
804 stmt); 795 if ((GNUNET_NO == ret) && (GNUNET_OK == delete_by_rowid (plugin, rowid)) &&
805 if ( (GNUNET_NO == ret) && 796 (NULL != plugin->env->duc))
806 (GNUNET_OK == delete_by_rowid (plugin,
807 rowid)) &&
808 (NULL != plugin->env->duc) )
809 plugin->env->duc (plugin->env->cls, 797 plugin->env->duc (plugin->env->cls,
810 -(value_size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); 798 -(value_size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
811 return; 799 return;
@@ -819,20 +807,17 @@ execute_get (struct Plugin *plugin,
819 LOG_SQLITE (plugin, 807 LOG_SQLITE (plugin,
820 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 808 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
821 "sqlite3_step"); 809 "sqlite3_step");
822 if (SQLITE_OK != 810 if (SQLITE_OK != sqlite3_reset (stmt))
823 sqlite3_reset (stmt))
824 LOG_SQLITE (plugin, 811 LOG_SQLITE (plugin,
825 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 812 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
826 "sqlite3_reset"); 813 "sqlite3_reset");
827 GNUNET_break (0); 814 GNUNET_break (0);
828 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 815 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
829 database_shutdown (plugin); 816 database_shutdown (plugin);
830 database_setup (plugin->env->cfg, 817 database_setup (plugin->env->cfg, plugin);
831 plugin);
832 return; 818 return;
833 } 819 }
834 GNUNET_SQ_reset (plugin->dbh, 820 GNUNET_SQ_reset (plugin->dbh, stmt);
835 stmt);
836 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 821 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
837} 822}
838 823
@@ -858,16 +843,14 @@ sqlite_plugin_get_zero_anonymity (void *cls,
858{ 843{
859 struct Plugin *plugin = cls; 844 struct Plugin *plugin = cls;
860 uint32_t type32 = type; 845 uint32_t type32 = type;
861 struct GNUNET_SQ_QueryParam params[] = { 846 struct GNUNET_SQ_QueryParam params[] = {GNUNET_SQ_query_param_uint64 (
862 GNUNET_SQ_query_param_uint64 (&next_uid), 847 &next_uid),
863 GNUNET_SQ_query_param_uint32 (&type32), 848 GNUNET_SQ_query_param_uint32 (
864 GNUNET_SQ_query_param_end 849 &type32),
865 }; 850 GNUNET_SQ_query_param_end};
866 851
867 GNUNET_assert (type != GNUNET_BLOCK_TYPE_ANY); 852 GNUNET_assert (type != GNUNET_BLOCK_TYPE_ANY);
868 if (GNUNET_OK != 853 if (GNUNET_OK != GNUNET_SQ_bind (plugin->selZeroAnon, params))
869 GNUNET_SQ_bind (plugin->selZeroAnon,
870 params))
871 { 854 {
872 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 855 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
873 return; 856 return;
@@ -905,13 +888,12 @@ sqlite_plugin_get_key (void *cls,
905 int use_type = GNUNET_BLOCK_TYPE_ANY != type; 888 int use_type = GNUNET_BLOCK_TYPE_ANY != type;
906 int use_key = NULL != key; 889 int use_key = NULL != key;
907 sqlite3_stmt *stmt = plugin->get[use_rvalue * 4 + use_key * 2 + use_type]; 890 sqlite3_stmt *stmt = plugin->get[use_rvalue * 4 + use_key * 2 + use_type];
908 struct GNUNET_SQ_QueryParam params[] = { 891 struct GNUNET_SQ_QueryParam params[] =
909 GNUNET_SQ_query_param_uint64 (&next_uid), 892 {GNUNET_SQ_query_param_uint64 (&next_uid),
910 GNUNET_SQ_query_param_uint64 (&rvalue), 893 GNUNET_SQ_query_param_uint64 (&rvalue),
911 GNUNET_SQ_query_param_auto_from_type (key), 894 GNUNET_SQ_query_param_auto_from_type (key),
912 GNUNET_SQ_query_param_uint32 (&type32), 895 GNUNET_SQ_query_param_uint32 (&type32),
913 GNUNET_SQ_query_param_end 896 GNUNET_SQ_query_param_end};
914 };
915 897
916 /* SQLite doesn't like it when you try to bind a parameter greater than the 898 /* SQLite doesn't like it when you try to bind a parameter greater than the
917 * last numbered parameter, but unused parameters in the middle are OK. 899 * last numbered parameter, but unused parameters in the middle are OK.
@@ -928,24 +910,18 @@ sqlite_plugin_get_key (void *cls,
928 } 910 }
929 if (random) 911 if (random)
930 { 912 {
931 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 913 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
932 UINT64_MAX);
933 next_uid = 0; 914 next_uid = 0;
934 } 915 }
935 else 916 else
936 rvalue = 0; 917 rvalue = 0;
937 918
938 if (GNUNET_OK != 919 if (GNUNET_OK != GNUNET_SQ_bind (stmt, params))
939 GNUNET_SQ_bind (stmt,
940 params))
941 { 920 {
942 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 921 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
943 return; 922 return;
944 } 923 }
945 execute_get (plugin, 924 execute_get (plugin, stmt, proc, proc_cls);
946 stmt,
947 proc,
948 proc_cls);
949} 925}
950 926
951 927
@@ -1051,37 +1027,27 @@ sqlite_plugin_get_replication (void *cls,
1051 struct ReplCtx rc; 1027 struct ReplCtx rc;
1052 uint64_t rvalue; 1028 uint64_t rvalue;
1053 uint32_t repl; 1029 uint32_t repl;
1054 struct GNUNET_SQ_QueryParam params_sel_repl[] = { 1030 struct GNUNET_SQ_QueryParam params_sel_repl[] =
1055 GNUNET_SQ_query_param_uint64 (&rvalue), 1031 {GNUNET_SQ_query_param_uint64 (&rvalue),
1056 GNUNET_SQ_query_param_uint32 (&repl), 1032 GNUNET_SQ_query_param_uint32 (&repl),
1057 GNUNET_SQ_query_param_end 1033 GNUNET_SQ_query_param_end};
1058 }; 1034 struct GNUNET_SQ_QueryParam params_upd_repl[] =
1059 struct GNUNET_SQ_QueryParam params_upd_repl[] = { 1035 {GNUNET_SQ_query_param_uint64 (&rc.uid), GNUNET_SQ_query_param_end};
1060 GNUNET_SQ_query_param_uint64 (&rc.uid),
1061 GNUNET_SQ_query_param_end
1062 };
1063 1036
1064 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1037 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1065 "datastore-sqlite", 1038 "datastore-sqlite",
1066 "Getting random block based on replication order.\n"); 1039 "Getting random block based on replication order.\n");
1067 if (SQLITE_ROW != 1040 if (SQLITE_ROW != sqlite3_step (plugin->maxRepl))
1068 sqlite3_step (plugin->maxRepl))
1069 { 1041 {
1070 GNUNET_SQ_reset (plugin->dbh, 1042 GNUNET_SQ_reset (plugin->dbh, plugin->maxRepl);
1071 plugin->maxRepl);
1072 /* DB empty */ 1043 /* DB empty */
1073 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 1044 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1074 return; 1045 return;
1075 } 1046 }
1076 repl = sqlite3_column_int (plugin->maxRepl, 1047 repl = sqlite3_column_int (plugin->maxRepl, 0);
1077 0); 1048 GNUNET_SQ_reset (plugin->dbh, plugin->maxRepl);
1078 GNUNET_SQ_reset (plugin->dbh, 1049 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
1079 plugin->maxRepl); 1050 if (GNUNET_OK != GNUNET_SQ_bind (plugin->selRepl, params_sel_repl))
1080 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
1081 UINT64_MAX);
1082 if (GNUNET_OK !=
1083 GNUNET_SQ_bind (plugin->selRepl,
1084 params_sel_repl))
1085 { 1051 {
1086 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 1052 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1087 return; 1053 return;
@@ -1089,26 +1055,19 @@ sqlite_plugin_get_replication (void *cls,
1089 rc.have_uid = GNUNET_SYSERR; 1055 rc.have_uid = GNUNET_SYSERR;
1090 rc.proc = proc; 1056 rc.proc = proc;
1091 rc.proc_cls = proc_cls; 1057 rc.proc_cls = proc_cls;
1092 execute_get (plugin, 1058 execute_get (plugin, plugin->selRepl, &repl_proc, &rc);
1093 plugin->selRepl,
1094 &repl_proc,
1095 &rc);
1096 if (GNUNET_YES == rc.have_uid) 1059 if (GNUNET_YES == rc.have_uid)
1097 { 1060 {
1098 if (GNUNET_OK != 1061 if (GNUNET_OK != GNUNET_SQ_bind (plugin->updRepl, params_upd_repl))
1099 GNUNET_SQ_bind (plugin->updRepl,
1100 params_upd_repl))
1101 { 1062 {
1102 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 1063 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1103 return; 1064 return;
1104 } 1065 }
1105 if (SQLITE_DONE != 1066 if (SQLITE_DONE != sqlite3_step (plugin->updRepl))
1106 sqlite3_step (plugin->updRepl))
1107 LOG_SQLITE (plugin, 1067 LOG_SQLITE (plugin,
1108 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 1068 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1109 "sqlite3_step"); 1069 "sqlite3_step");
1110 GNUNET_SQ_reset (plugin->dbh, 1070 GNUNET_SQ_reset (plugin->dbh, plugin->updRepl);
1111 plugin->updRepl);
1112 } 1071 }
1113 if (GNUNET_SYSERR == rc.have_uid) 1072 if (GNUNET_SYSERR == rc.have_uid)
1114 { 1073 {
@@ -1127,25 +1086,24 @@ sqlite_plugin_get_replication (void *cls,
1127 * @param proc_cls closure for @a proc 1086 * @param proc_cls closure for @a proc
1128 */ 1087 */
1129static void 1088static void
1130sqlite_plugin_get_expiration (void *cls, PluginDatumProcessor proc, 1089sqlite_plugin_get_expiration (void *cls,
1090 PluginDatumProcessor proc,
1131 void *proc_cls) 1091 void *proc_cls)
1132{ 1092{
1133 struct Plugin *plugin = cls; 1093 struct Plugin *plugin = cls;
1134 sqlite3_stmt *stmt; 1094 sqlite3_stmt *stmt;
1135 struct GNUNET_TIME_Absolute now; 1095 struct GNUNET_TIME_Absolute now;
1136 struct GNUNET_SQ_QueryParam params[] = { 1096 struct GNUNET_SQ_QueryParam params[] = {GNUNET_SQ_query_param_absolute_time (
1137 GNUNET_SQ_query_param_absolute_time (&now), 1097 &now),
1138 GNUNET_SQ_query_param_end 1098 GNUNET_SQ_query_param_end};
1139 }; 1099
1140 1100 GNUNET_log_from (
1141 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1101 GNUNET_ERROR_TYPE_DEBUG,
1142 "sqlite", 1102 "sqlite",
1143 "Getting random block based on expiration and priority order.\n"); 1103 "Getting random block based on expiration and priority order.\n");
1144 now = GNUNET_TIME_absolute_get (); 1104 now = GNUNET_TIME_absolute_get ();
1145 stmt = plugin->selExpi; 1105 stmt = plugin->selExpi;
1146 if (GNUNET_OK != 1106 if (GNUNET_OK != GNUNET_SQ_bind (stmt, params))
1147 GNUNET_SQ_bind (stmt,
1148 params))
1149 { 1107 {
1150 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 1108 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1151 return; 1109 return;
@@ -1162,52 +1120,35 @@ sqlite_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
1162 * @param proc_cls closure for @a proc 1120 * @param proc_cls closure for @a proc
1163 */ 1121 */
1164static void 1122static void
1165sqlite_plugin_get_keys (void *cls, 1123sqlite_plugin_get_keys (void *cls, PluginKeyProcessor proc, void *proc_cls)
1166 PluginKeyProcessor proc,
1167 void *proc_cls)
1168{ 1124{
1169 struct Plugin *plugin = cls; 1125 struct Plugin *plugin = cls;
1170 struct GNUNET_HashCode key; 1126 struct GNUNET_HashCode key;
1171 struct GNUNET_SQ_ResultSpec results[] = { 1127 struct GNUNET_SQ_ResultSpec results[] =
1172 GNUNET_SQ_result_spec_auto_from_type (&key), 1128 {GNUNET_SQ_result_spec_auto_from_type (&key), GNUNET_SQ_result_spec_end};
1173 GNUNET_SQ_result_spec_end
1174 };
1175 sqlite3_stmt *stmt; 1129 sqlite3_stmt *stmt;
1176 int ret; 1130 int ret;
1177 1131
1178 GNUNET_assert (NULL != proc); 1132 GNUNET_assert (NULL != proc);
1179 if (SQLITE_OK != 1133 if (SQLITE_OK != sq_prepare (plugin->dbh, "SELECT hash FROM gn091", &stmt))
1180 sq_prepare (plugin->dbh,
1181 "SELECT hash FROM gn091",
1182 &stmt))
1183 { 1134 {
1184 LOG_SQLITE (plugin, 1135 LOG_SQLITE (plugin,
1185 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 1136 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1186 "sqlite_prepare"); 1137 "sqlite_prepare");
1187 proc (proc_cls, 1138 proc (proc_cls, NULL, 0);
1188 NULL,
1189 0);
1190 return; 1139 return;
1191 } 1140 }
1192 while (SQLITE_ROW == (ret = sqlite3_step (stmt))) 1141 while (SQLITE_ROW == (ret = sqlite3_step (stmt)))
1193 { 1142 {
1194 if (GNUNET_OK == 1143 if (GNUNET_OK == GNUNET_SQ_extract_result (stmt, results))
1195 GNUNET_SQ_extract_result (stmt, 1144 proc (proc_cls, &key, 1);
1196 results))
1197 proc (proc_cls,
1198 &key,
1199 1);
1200 else 1145 else
1201 GNUNET_break (0); 1146 GNUNET_break (0);
1202 } 1147 }
1203 if (SQLITE_DONE != ret) 1148 if (SQLITE_DONE != ret)
1204 LOG_SQLITE (plugin, 1149 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step");
1205 GNUNET_ERROR_TYPE_ERROR,
1206 "sqlite_step");
1207 sqlite3_finalize (stmt); 1150 sqlite3_finalize (stmt);
1208 proc (proc_cls, 1151 proc (proc_cls, NULL, 0);
1209 NULL,
1210 0);
1211} 1152}
1212 1153
1213 1154
@@ -1244,21 +1185,14 @@ sqlite_plugin_remove_key (void *cls,
1244 void *cont_cls) 1185 void *cont_cls)
1245{ 1186{
1246 struct Plugin *plugin = cls; 1187 struct Plugin *plugin = cls;
1247 struct GNUNET_SQ_QueryParam params[] = { 1188 struct GNUNET_SQ_QueryParam params[] =
1248 GNUNET_SQ_query_param_auto_from_type (key), 1189 {GNUNET_SQ_query_param_auto_from_type (key),
1249 GNUNET_SQ_query_param_fixed_size (data, size), 1190 GNUNET_SQ_query_param_fixed_size (data, size),
1250 GNUNET_SQ_query_param_end 1191 GNUNET_SQ_query_param_end};
1251 }; 1192
1252 1193 if (GNUNET_OK != GNUNET_SQ_bind (plugin->remove, params))
1253 if (GNUNET_OK !=
1254 GNUNET_SQ_bind (plugin->remove,
1255 params))
1256 { 1194 {
1257 cont (cont_cls, 1195 cont (cont_cls, key, size, GNUNET_SYSERR, "bind failed");
1258 key,
1259 size,
1260 GNUNET_SYSERR,
1261 "bind failed");
1262 return; 1196 return;
1263 } 1197 }
1264 if (SQLITE_DONE != sqlite3_step (plugin->remove)) 1198 if (SQLITE_DONE != sqlite3_step (plugin->remove))
@@ -1266,35 +1200,21 @@ sqlite_plugin_remove_key (void *cls,
1266 LOG_SQLITE (plugin, 1200 LOG_SQLITE (plugin,
1267 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 1201 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1268 "sqlite3_step"); 1202 "sqlite3_step");
1269 GNUNET_SQ_reset (plugin->dbh, 1203 GNUNET_SQ_reset (plugin->dbh, plugin->remove);
1270 plugin->remove); 1204 cont (cont_cls, key, size, GNUNET_SYSERR, "sqlite3_step failed");
1271 cont (cont_cls,
1272 key,
1273 size,
1274 GNUNET_SYSERR,
1275 "sqlite3_step failed");
1276 return; 1205 return;
1277 } 1206 }
1278 int changes = sqlite3_changes (plugin->dbh); 1207 int changes = sqlite3_changes (plugin->dbh);
1279 GNUNET_SQ_reset (plugin->dbh, 1208 GNUNET_SQ_reset (plugin->dbh, plugin->remove);
1280 plugin->remove);
1281 if (0 == changes) 1209 if (0 == changes)
1282 { 1210 {
1283 cont (cont_cls, 1211 cont (cont_cls, key, size, GNUNET_NO, NULL);
1284 key,
1285 size,
1286 GNUNET_NO,
1287 NULL);
1288 return; 1212 return;
1289 } 1213 }
1290 if (NULL != plugin->env->duc) 1214 if (NULL != plugin->env->duc)
1291 plugin->env->duc (plugin->env->cls, 1215 plugin->env->duc (plugin->env->cls,
1292 -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); 1216 -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
1293 cont (cont_cls, 1217 cont (cont_cls, key, size, GNUNET_OK, NULL);
1294 key,
1295 size,
1296 GNUNET_OK,
1297 NULL);
1298} 1218}
1299 1219
1300 1220
@@ -1306,8 +1226,7 @@ sqlite_plugin_remove_key (void *cls,
1306 * @return the size of the database on disk (estimate) 1226 * @return the size of the database on disk (estimate)
1307 */ 1227 */
1308static void 1228static void
1309sqlite_plugin_estimate_size (void *cls, 1229sqlite_plugin_estimate_size (void *cls, unsigned long long *estimate)
1310 unsigned long long *estimate)
1311{ 1230{
1312 struct Plugin *plugin = cls; 1231 struct Plugin *plugin = cls;
1313 sqlite3_stmt *stmt; 1232 sqlite3_stmt *stmt;
@@ -1322,45 +1241,35 @@ sqlite_plugin_estimate_size (void *cls,
1322 return; 1241 return;
1323 if (SQLITE_VERSION_NUMBER < 3006000) 1242 if (SQLITE_VERSION_NUMBER < 3006000)
1324 { 1243 {
1325 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, 1244 GNUNET_log_from (
1326 "datastore-sqlite", 1245 GNUNET_ERROR_TYPE_WARNING,
1327 _("sqlite version to old to determine size, assuming zero\n")); 1246 "datastore-sqlite",
1247 _ ("sqlite version to old to determine size, assuming zero\n"));
1328 *estimate = 0; 1248 *estimate = 0;
1329 return; 1249 return;
1330 } 1250 }
1331 CHECK (SQLITE_OK == 1251 CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh, "VACUUM", NULL, NULL, ENULL));
1332 sqlite3_exec (plugin->dbh, 1252 CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh,
1333 "VACUUM", 1253 "PRAGMA auto_vacuum=INCREMENTAL",
1334 NULL, 1254 NULL,
1335 NULL, 1255 NULL,
1336 ENULL)); 1256 ENULL));
1337 CHECK (SQLITE_OK == 1257 CHECK (SQLITE_OK == sq_prepare (plugin->dbh, "PRAGMA page_count", &stmt));
1338 sqlite3_exec (plugin->dbh,
1339 "PRAGMA auto_vacuum=INCREMENTAL",
1340 NULL,
1341 NULL, ENULL));
1342 CHECK (SQLITE_OK ==
1343 sq_prepare (plugin->dbh,
1344 "PRAGMA page_count",
1345 &stmt));
1346 if (SQLITE_ROW == sqlite3_step (stmt)) 1258 if (SQLITE_ROW == sqlite3_step (stmt))
1347 pages = sqlite3_column_int64 (stmt, 1259 pages = sqlite3_column_int64 (stmt, 0);
1348 0);
1349 else 1260 else
1350 pages = 0; 1261 pages = 0;
1351 sqlite3_finalize (stmt); 1262 sqlite3_finalize (stmt);
1352 CHECK (SQLITE_OK == 1263 CHECK (SQLITE_OK == sq_prepare (plugin->dbh, "PRAGMA page_size", &stmt));
1353 sq_prepare (plugin->dbh, 1264 CHECK (SQLITE_ROW == sqlite3_step (stmt));
1354 "PRAGMA page_size",
1355 &stmt));
1356 CHECK (SQLITE_ROW ==
1357 sqlite3_step (stmt));
1358 page_size = sqlite3_column_int64 (stmt, 0); 1265 page_size = sqlite3_column_int64 (stmt, 0);
1359 sqlite3_finalize (stmt); 1266 sqlite3_finalize (stmt);
1360 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1267 GNUNET_log (
1361 _("Using sqlite page utilization to estimate payload (%llu pages of size %llu bytes)\n"), 1268 GNUNET_ERROR_TYPE_INFO,
1362 (unsigned long long) pages, 1269 _ (
1363 (unsigned long long) page_size); 1270 "Using sqlite page utilization to estimate payload (%llu pages of size %llu bytes)\n"),
1271 (unsigned long long) pages,
1272 (unsigned long long) page_size);
1364 *estimate = pages * page_size; 1273 *estimate = pages * page_size;
1365} 1274}
1366 1275
@@ -1379,10 +1288,8 @@ libgnunet_plugin_datastore_sqlite_init (void *cls)
1379 struct GNUNET_DATASTORE_PluginFunctions *api; 1288 struct GNUNET_DATASTORE_PluginFunctions *api;
1380 1289
1381 if (NULL != plugin.env) 1290 if (NULL != plugin.env)
1382 return NULL; /* can only initialize once! */ 1291 return NULL; /* can only initialize once! */
1383 memset (&plugin, 1292 memset (&plugin, 0, sizeof (struct Plugin));
1384 0,
1385 sizeof (struct Plugin));
1386 plugin.env = env; 1293 plugin.env = env;
1387 if (GNUNET_OK != database_setup (env->cfg, &plugin)) 1294 if (GNUNET_OK != database_setup (env->cfg, &plugin))
1388 { 1295 {
@@ -1402,7 +1309,7 @@ libgnunet_plugin_datastore_sqlite_init (void *cls)
1402 api->remove_key = &sqlite_plugin_remove_key; 1309 api->remove_key = &sqlite_plugin_remove_key;
1403 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, 1310 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
1404 "sqlite", 1311 "sqlite",
1405 _("Sqlite database running\n")); 1312 _ ("Sqlite database running\n"));
1406 return api; 1313 return api;
1407} 1314}
1408 1315
@@ -1431,10 +1338,8 @@ libgnunet_plugin_datastore_sqlite_done (void *cls)
1431 GNUNET_free (api); 1338 GNUNET_free (api);
1432 if (NULL != fn) 1339 if (NULL != fn)
1433 { 1340 {
1434 if (0 != UNLINK (fn)) 1341 if (0 != unlink (fn))
1435 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 1342 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
1436 "unlink",
1437 fn);
1438 GNUNET_free (fn); 1343 GNUNET_free (fn);
1439 } 1344 }
1440 return NULL; 1345 return NULL;
diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c
index daf6cccb3..ee78a8cfc 100644
--- a/src/datastore/test_datastore_api.c
+++ b/src/datastore/test_datastore_api.c
@@ -251,11 +251,11 @@ check_value (void *cls,
251 return; 251 return;
252 } 252 }
253#if 0 253#if 0
254 FPRINTF (stderr, 254 fprintf (stderr,
255 "Check value got `%s' of size %u, type %d, expire %s\n", 255 "Check value got `%s' of size %u, type %d, expire %s\n",
256 GNUNET_h2s (key), (unsigned int) size, type, 256 GNUNET_h2s (key), (unsigned int) size, type,
257 GNUNET_STRINGS_absolute_time_to_string (expiration)); 257 GNUNET_STRINGS_absolute_time_to_string (expiration));
258 FPRINTF (stderr, 258 fprintf (stderr,
259 "Check value iteration %d wants size %u, type %d, expire %s\n", i, 259 "Check value iteration %d wants size %u, type %d, expire %s\n", i,
260 (unsigned int) get_size (i), get_type (i), 260 (unsigned int) get_size (i), get_type (i),
261 GNUNET_STRINGS_absolute_time_to_string (get_expiration(i))); 261 GNUNET_STRINGS_absolute_time_to_string (get_expiration(i)));
@@ -555,14 +555,14 @@ run_tests (void *cls,
555 crc); 555 crc);
556 return; 556 return;
557 case GNUNET_NO: 557 case GNUNET_NO:
558 FPRINTF (stderr, 558 fprintf (stderr,
559 "%s", "Test 'put' operation failed, key already exists (!?)\n"); 559 "%s", "Test 'put' operation failed, key already exists (!?)\n");
560 GNUNET_DATASTORE_disconnect (datastore, 560 GNUNET_DATASTORE_disconnect (datastore,
561 GNUNET_YES); 561 GNUNET_YES);
562 GNUNET_free (crc); 562 GNUNET_free (crc);
563 return; 563 return;
564 case GNUNET_SYSERR: 564 case GNUNET_SYSERR:
565 FPRINTF (stderr, 565 fprintf (stderr,
566 "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", 566 "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n",
567 msg); 567 msg);
568 GNUNET_DATASTORE_disconnect (datastore, 568 GNUNET_DATASTORE_disconnect (datastore,
@@ -609,7 +609,7 @@ run (void *cls,
609 0, 1, 609 0, 1,
610 &run_tests, crc)) 610 &run_tests, crc))
611 { 611 {
612 FPRINTF (stderr, 612 fprintf (stderr,
613 "%s", 613 "%s",
614 "Test 'put' operation failed.\n"); 614 "Test 'put' operation failed.\n");
615 ok = 1; 615 ok = 1;
diff --git a/src/datastore/test_datastore_api_management.c b/src/datastore/test_datastore_api_management.c
index d91fe748b..fc4c03885 100644
--- a/src/datastore/test_datastore_api_management.c
+++ b/src/datastore/test_datastore_api_management.c
@@ -272,7 +272,7 @@ run_tests (void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, c
272 272
273 if (success != GNUNET_YES) 273 if (success != GNUNET_YES)
274 { 274 {
275 FPRINTF (stderr, 275 fprintf (stderr,
276 "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", 276 "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n",
277 msg); 277 msg);
278 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); 278 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
@@ -310,7 +310,7 @@ run (void *cls,
310 &run_tests, 310 &run_tests,
311 crc)) 311 crc))
312 { 312 {
313 FPRINTF (stderr, "%s", "Test 'put' operation failed.\n"); 313 fprintf (stderr, "%s", "Test 'put' operation failed.\n");
314 GNUNET_free (crc); 314 GNUNET_free (crc);
315 ok = 1; 315 ok = 1;
316 } 316 }
diff --git a/src/datastore/test_plugin_datastore.c b/src/datastore/test_plugin_datastore.c
index c37b8ddb9..2b7bf9ae4 100644
--- a/src/datastore/test_plugin_datastore.c
+++ b/src/datastore/test_plugin_datastore.c
@@ -108,7 +108,7 @@ put_continuation (void *cls,
108 108
109 if (GNUNET_OK != status) 109 if (GNUNET_OK != status)
110 { 110 {
111 FPRINTF (stderr, 111 fprintf (stderr,
112 "ERROR: `%s'\n", 112 "ERROR: `%s'\n",
113 msg); 113 msg);
114 } 114 }
@@ -399,7 +399,7 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
399 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); 399 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
400 if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env))) 400 if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env)))
401 { 401 {
402 FPRINTF (stderr, "Failed to load plugin `%s'!\n", name); 402 fprintf (stderr, "Failed to load plugin `%s'!\n", name);
403 GNUNET_free (libname); 403 GNUNET_free (libname);
404 GNUNET_free (name); 404 GNUNET_free (name);
405 ok = 77; /* mark test as skipped */ 405 ok = 77; /* mark test as skipped */
@@ -421,7 +421,7 @@ run (void *cls, char *const *args, const char *cfgfile,
421 api = load_plugin (c); 421 api = load_plugin (c);
422 if (api == NULL) 422 if (api == NULL)
423 { 423 {
424 FPRINTF (stderr, 424 fprintf (stderr,
425 "%s", "Could not initialize plugin, assuming database not configured. Test not run!\n"); 425 "%s", "Could not initialize plugin, assuming database not configured. Test not run!\n");
426 return; 426 return;
427 } 427 }
@@ -461,7 +461,7 @@ main (int argc, char *argv[])
461 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, 461 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv,
462 "test-plugin-datastore", "nohelp", options, &run, NULL); 462 "test-plugin-datastore", "nohelp", options, &run, NULL);
463 if ( (0 != ok) && (77 != ok) ) 463 if ( (0 != ok) && (77 != ok) )
464 FPRINTF (stderr, "Missed some testcases: %u\n", ok); 464 fprintf (stderr, "Missed some testcases: %u\n", ok);
465 GNUNET_DISK_directory_remove (dir_name); 465 GNUNET_DISK_directory_remove (dir_name);
466 return ok; 466 return ok;
467} 467}
diff --git a/src/dht/gnunet-dht-get.c b/src/dht/gnunet-dht-get.c
index b42326fc5..af667584b 100644
--- a/src/dht/gnunet-dht-get.c
+++ b/src/dht/gnunet-dht-get.c
@@ -26,7 +26,7 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_dht_service.h" 27#include "gnunet_dht_service.h"
28 28
29#define LOG(kind,...) GNUNET_log_from (kind, "dht-clients",__VA_ARGS__) 29#define LOG(kind, ...) GNUNET_log_from (kind, "dht-clients", __VA_ARGS__)
30/** 30/**
31 * The type of the query 31 * The type of the query
32 */ 32 */
@@ -45,7 +45,7 @@ static char *query_key;
45/** 45/**
46 * User supplied timeout value 46 * User supplied timeout value
47 */ 47 */
48static struct GNUNET_TIME_Relative timeout_request = { 60000 }; 48static struct GNUNET_TIME_Relative timeout_request = {60000};
49 49
50/** 50/**
51 * Be verbose 51 * Be verbose
@@ -143,8 +143,9 @@ timeout_task (void *cls)
143 * @param data pointer to the result data 143 * @param data pointer to the result data
144 */ 144 */
145static void 145static void
146get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, 146get_result_iterator (void *cls,
147 const struct GNUNET_HashCode * key, 147 struct GNUNET_TIME_Absolute exp,
148 const struct GNUNET_HashCode *key,
148 const struct GNUNET_PeerIdentity *get_path, 149 const struct GNUNET_PeerIdentity *get_path,
149 unsigned int get_path_length, 150 unsigned int get_path_length,
150 const struct GNUNET_PeerIdentity *put_path, 151 const struct GNUNET_PeerIdentity *put_path,
@@ -153,32 +154,22 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
153 size_t size, 154 size_t size,
154 const void *data) 155 const void *data)
155{ 156{
156 FPRINTF (stdout, 157 fprintf (stdout,
157 (GNUNET_BLOCK_TYPE_TEST == type) 158 (GNUNET_BLOCK_TYPE_TEST == type) ? _ ("Result %d, type %d:\n%.*s\n")
158 ? _("Result %d, type %d:\n%.*s\n") 159 : _ ("Result %d, type %d:\n"),
159 : _("Result %d, type %d:\n"), 160 result_count,
160 result_count,
161 type, 161 type,
162 (unsigned int) size, 162 (unsigned int) size,
163 (char *) data); 163 (char *) data);
164 if (verbose) 164 if (verbose)
165 { 165 {
166 FPRINTF (stdout, 166 fprintf (stdout, " GET path: ");
167 " GET path: "); 167 for (unsigned int i = 0; i < get_path_length; i++)
168 for (unsigned int i=0;i<get_path_length;i++) 168 fprintf (stdout, "%s%s", (0 == i) ? "" : "-", GNUNET_i2s (&get_path[i]));
169 FPRINTF (stdout, 169 fprintf (stdout, "\n PUT path: ");
170 "%s%s", 170 for (unsigned int i = 0; i < put_path_length; i++)
171 (0 == i) ? "" : "-", 171 fprintf (stdout, "%s%s", (0 == i) ? "" : "-", GNUNET_i2s (&put_path[i]));
172 GNUNET_i2s (&get_path[i])); 172 fprintf (stdout, "\n");
173 FPRINTF (stdout,
174 "\n PUT path: ");
175 for (unsigned int i=0;i<put_path_length;i++)
176 FPRINTF (stdout,
177 "%s%s",
178 (0 == i) ? "" : "-",
179 GNUNET_i2s (&put_path[i]));
180 FPRINTF (stdout,
181 "\n");
182 } 173 }
183 result_count++; 174 result_count++;
184} 175}
@@ -193,7 +184,9 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
193 * @param c configuration 184 * @param c configuration
194 */ 185 */
195static void 186static void
196run (void *cls, char *const *args, const char *cfgfile, 187run (void *cls,
188 char *const *args,
189 const char *cfgfile,
197 const struct GNUNET_CONFIGURATION_Handle *c) 190 const struct GNUNET_CONFIGURATION_Handle *c)
198{ 191{
199 struct GNUNET_HashCode key; 192 struct GNUNET_HashCode key;
@@ -201,33 +194,37 @@ run (void *cls, char *const *args, const char *cfgfile,
201 cfg = c; 194 cfg = c;
202 if (NULL == query_key) 195 if (NULL == query_key)
203 { 196 {
204 FPRINTF (stderr, "%s", _("Must provide key for DHT GET!\n")); 197 fprintf (stderr, "%s", _ ("Must provide key for DHT GET!\n"));
205 ret = 1; 198 ret = 1;
206 return; 199 return;
207 } 200 }
208 if (NULL == (dht_handle = GNUNET_DHT_connect (cfg, 1))) 201 if (NULL == (dht_handle = GNUNET_DHT_connect (cfg, 1)))
209 { 202 {
210 FPRINTF (stderr, "%s", _("Failed to connect to DHT service!\n")); 203 fprintf (stderr, "%s", _ ("Failed to connect to DHT service!\n"));
211 ret = 1; 204 ret = 1;
212 return; 205 return;
213 } 206 }
214 if (query_type == GNUNET_BLOCK_TYPE_ANY) /* Type of data not set */ 207 if (query_type == GNUNET_BLOCK_TYPE_ANY) /* Type of data not set */
215 query_type = GNUNET_BLOCK_TYPE_TEST; 208 query_type = GNUNET_BLOCK_TYPE_TEST;
216 GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key); 209 GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key);
217 if (verbose) 210 if (verbose)
218 FPRINTF (stderr, "%s `%s' \n", 211 fprintf (stderr,
219 _("Issuing DHT GET with key"), 212 "%s `%s' \n",
213 _ ("Issuing DHT GET with key"),
220 GNUNET_h2s_full (&key)); 214 GNUNET_h2s_full (&key));
221 GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL); 215 GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL);
222 tt = GNUNET_SCHEDULER_add_delayed (timeout_request, 216 tt = GNUNET_SCHEDULER_add_delayed (timeout_request, &timeout_task, NULL);
223 &timeout_task, 217 get_handle = GNUNET_DHT_get_start (dht_handle,
218 query_type,
219 &key,
220 replication,
221 (demultixplex_everywhere)
222 ? GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE
223 : GNUNET_DHT_RO_NONE,
224 NULL,
225 0,
226 &get_result_iterator,
224 NULL); 227 NULL);
225 get_handle =
226 GNUNET_DHT_get_start (dht_handle, query_type, &key, replication,
227 (demultixplex_everywhere) ? GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE : GNUNET_DHT_RO_NONE,
228 NULL, 0,
229 &get_result_iterator,
230 NULL);
231} 228}
232 229
233 230
@@ -241,44 +238,52 @@ run (void *cls, char *const *args, const char *cfgfile,
241int 238int
242main (int argc, char *const *argv) 239main (int argc, char *const *argv)
243{ 240{
244 struct GNUNET_GETOPT_CommandLineOption options[] = { 241 struct GNUNET_GETOPT_CommandLineOption options[] =
245 GNUNET_GETOPT_option_string ('k', 242 {GNUNET_GETOPT_option_string ('k',
246 "key", 243 "key",
247 "KEY", 244 "KEY",
248 gettext_noop ("the query key"), 245 gettext_noop ("the query key"),
249 &query_key), 246 &query_key),
250 GNUNET_GETOPT_option_uint ('r', 247 GNUNET_GETOPT_option_uint (
251 "replication", 248 'r',
252 "LEVEL", 249 "replication",
253 gettext_noop ("how many parallel requests (replicas) to create"), 250 "LEVEL",
254 &replication), 251 gettext_noop ("how many parallel requests (replicas) to create"),
255 GNUNET_GETOPT_option_uint ('t', 252 &replication),
256 "type", 253 GNUNET_GETOPT_option_uint ('t',
257 "TYPE", 254 "type",
258 gettext_noop ("the type of data to look for"), 255 "TYPE",
259 &query_type), 256 gettext_noop ("the type of data to look for"),
260 GNUNET_GETOPT_option_relative_time ('T', 257 &query_type),
261 "timeout", 258 GNUNET_GETOPT_option_relative_time (
262 "TIMEOUT", 259 'T',
263 gettext_noop ("how long to execute this query before giving up?"), 260 "timeout",
264 &timeout_request), 261 "TIMEOUT",
265 GNUNET_GETOPT_option_flag ('x', 262 gettext_noop ("how long to execute this query before giving up?"),
266 "demultiplex", 263 &timeout_request),
267 gettext_noop ("use DHT's demultiplex everywhere option"), 264 GNUNET_GETOPT_option_flag ('x',
268 &demultixplex_everywhere), 265 "demultiplex",
269 GNUNET_GETOPT_option_verbose (&verbose), 266 gettext_noop (
270 GNUNET_GETOPT_OPTION_END 267 "use DHT's demultiplex everywhere option"),
271 }; 268 &demultixplex_everywhere),
272 269 GNUNET_GETOPT_option_verbose (&verbose),
270 GNUNET_GETOPT_OPTION_END};
273 271
274 272
275 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 273 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
276 return 2; 274 return 2;
277 return (GNUNET_OK == 275 return (GNUNET_OK ==
278 GNUNET_PROGRAM_run (argc, argv, "gnunet-dht-get", 276 GNUNET_PROGRAM_run (
279 gettext_noop 277 argc,
280 ("Issue a GET request to the GNUnet DHT, prints results."), 278 argv,
281 options, &run, NULL)) ? ret : 1; 279 "gnunet-dht-get",
280 gettext_noop (
281 "Issue a GET request to the GNUnet DHT, prints results."),
282 options,
283 &run,
284 NULL))
285 ? ret
286 : 1;
282} 287}
283 288
284/* end of gnunet-dht-get.c */ 289/* end of gnunet-dht-get.c */
diff --git a/src/dht/gnunet-dht-monitor.c b/src/dht/gnunet-dht-monitor.c
index 52a57473b..3787b7cfa 100644
--- a/src/dht/gnunet-dht-monitor.c
+++ b/src/dht/gnunet-dht-monitor.c
@@ -39,7 +39,7 @@ static char *query_key;
39/** 39/**
40 * User supplied timeout value (in seconds) 40 * User supplied timeout value (in seconds)
41 */ 41 */
42static struct GNUNET_TIME_Relative timeout_request = { 60000 }; 42static struct GNUNET_TIME_Relative timeout_request = {60000};
43 43
44/** 44/**
45 * Be verbose 45 * Be verbose
@@ -86,7 +86,7 @@ static void
86cleanup_task (void *cls) 86cleanup_task (void *cls)
87{ 87{
88 if (verbose) 88 if (verbose)
89 FPRINTF (stderr, "%s", "Cleaning up!\n"); 89 fprintf (stderr, "%s", "Cleaning up!\n");
90 if (NULL != monitor_handle) 90 if (NULL != monitor_handle)
91 { 91 {
92 GNUNET_DHT_monitor_stop (monitor_handle); 92 GNUNET_DHT_monitor_stop (monitor_handle);
@@ -118,7 +118,6 @@ timeout_task (void *cls)
118} 118}
119 119
120 120
121
122/** 121/**
123 * Callback called on each GET request going through the DHT. 122 * Callback called on each GET request going through the DHT.
124 * 123 *
@@ -139,13 +138,13 @@ get_callback (void *cls,
139 uint32_t desired_replication_level, 138 uint32_t desired_replication_level,
140 unsigned int path_length, 139 unsigned int path_length,
141 const struct GNUNET_PeerIdentity *path, 140 const struct GNUNET_PeerIdentity *path,
142 const struct GNUNET_HashCode * key) 141 const struct GNUNET_HashCode *key)
143{ 142{
144 FPRINTF (stdout, 143 fprintf (stdout,
145 "GET #%u: type %d, key `%s'\n", 144 "GET #%u: type %d, key `%s'\n",
146 result_count, 145 result_count,
147 (int) type, 146 (int) type,
148 GNUNET_h2s_full(key)); 147 GNUNET_h2s_full (key));
149 result_count++; 148 result_count++;
150} 149}
151 150
@@ -172,14 +171,14 @@ get_resp_callback (void *cls,
172 const struct GNUNET_PeerIdentity *put_path, 171 const struct GNUNET_PeerIdentity *put_path,
173 unsigned int put_path_length, 172 unsigned int put_path_length,
174 struct GNUNET_TIME_Absolute exp, 173 struct GNUNET_TIME_Absolute exp,
175 const struct GNUNET_HashCode * key, 174 const struct GNUNET_HashCode *key,
176 const void *data, 175 const void *data,
177 size_t size) 176 size_t size)
178{ 177{
179 FPRINTF (stdout, 178 fprintf (stdout,
180 (GNUNET_BLOCK_TYPE_TEST == type) 179 (GNUNET_BLOCK_TYPE_TEST == type)
181 ? "RESPONSE #%u (%s): type %d, key `%s', data `%.*s'\n" 180 ? "RESPONSE #%u (%s): type %d, key `%s', data `%.*s'\n"
182 : "RESPONSE #%u (%s): type %d, key `%s'\n", 181 : "RESPONSE #%u (%s): type %d, key `%s'\n",
183 result_count, 182 result_count,
184 GNUNET_STRINGS_absolute_time_to_string (exp), 183 GNUNET_STRINGS_absolute_time_to_string (exp),
185 (int) type, 184 (int) type,
@@ -214,18 +213,18 @@ put_callback (void *cls,
214 unsigned int path_length, 213 unsigned int path_length,
215 const struct GNUNET_PeerIdentity *path, 214 const struct GNUNET_PeerIdentity *path,
216 struct GNUNET_TIME_Absolute exp, 215 struct GNUNET_TIME_Absolute exp,
217 const struct GNUNET_HashCode * key, 216 const struct GNUNET_HashCode *key,
218 const void *data, 217 const void *data,
219 size_t size) 218 size_t size)
220{ 219{
221 FPRINTF (stdout, 220 fprintf (stdout,
222 (GNUNET_BLOCK_TYPE_TEST == type) 221 (GNUNET_BLOCK_TYPE_TEST == type)
223 ? "PUT %u (%s): type %d, key `%s', data `%.*s'\n" 222 ? "PUT %u (%s): type %d, key `%s', data `%.*s'\n"
224 : "PUT %u (%s): type %d, key `%s'\n", 223 : "PUT %u (%s): type %d, key `%s'\n",
225 result_count, 224 result_count,
226 GNUNET_STRINGS_absolute_time_to_string (exp), 225 GNUNET_STRINGS_absolute_time_to_string (exp),
227 (int) type, 226 (int) type,
228 GNUNET_h2s_full(key), 227 GNUNET_h2s_full (key),
229 (unsigned int) size, 228 (unsigned int) size,
230 (char *) data); 229 (char *) data);
231 result_count++; 230 result_count++;
@@ -253,33 +252,29 @@ run (void *cls,
253 252
254 if (NULL == (dht_handle = GNUNET_DHT_connect (cfg, 1))) 253 if (NULL == (dht_handle = GNUNET_DHT_connect (cfg, 1)))
255 { 254 {
256 FPRINTF (stderr, "%s", 255 fprintf (stderr, "%s", _ ("Failed to connect to DHT service!\n"));
257 _("Failed to connect to DHT service!\n"));
258 ret = 1; 256 ret = 1;
259 return; 257 return;
260 } 258 }
261 if (GNUNET_BLOCK_TYPE_ANY == block_type) /* Type of data not set */ 259 if (GNUNET_BLOCK_TYPE_ANY == block_type) /* Type of data not set */
262 block_type = GNUNET_BLOCK_TYPE_TEST; 260 block_type = GNUNET_BLOCK_TYPE_TEST;
263 if (NULL != query_key) 261 if (NULL != query_key)
264 { 262 {
265 key = &hc; 263 key = &hc;
266 if (GNUNET_OK != 264 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (query_key, key))
267 GNUNET_CRYPTO_hash_from_string (query_key, key)) 265 GNUNET_CRYPTO_hash (query_key, strlen (query_key), key);
268 GNUNET_CRYPTO_hash (query_key, strlen (query_key), key); 266 }
269 }
270 else 267 else
271 { 268 {
272 key = NULL; 269 key = NULL;
273 } 270 }
274 if (verbose) 271 if (verbose)
275 FPRINTF (stderr, 272 fprintf (stderr,
276 "Monitoring for %s\n", 273 "Monitoring for %s\n",
277 GNUNET_STRINGS_relative_time_to_string (timeout_request, GNUNET_NO)); 274 GNUNET_STRINGS_relative_time_to_string (timeout_request,
278 tt = GNUNET_SCHEDULER_add_delayed (timeout_request, 275 GNUNET_NO));
279 &timeout_task, 276 tt = GNUNET_SCHEDULER_add_delayed (timeout_request, &timeout_task, NULL);
280 NULL); 277 GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL);
281 GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
282 NULL);
283 monitor_handle = GNUNET_DHT_monitor_start (dht_handle, 278 monitor_handle = GNUNET_DHT_monitor_start (dht_handle,
284 block_type, 279 block_type,
285 key, 280 key,
@@ -308,34 +303,41 @@ main (int argc, char *const *argv)
308 &query_key), 303 &query_key),
309 304
310 GNUNET_GETOPT_option_uint ('t', 305 GNUNET_GETOPT_option_uint ('t',
311 "type", 306 "type",
312 "TYPE", 307 "TYPE",
313 gettext_noop ("the type of data to look for"), 308 gettext_noop ("the type of data to look for"),
314 &block_type), 309 &block_type),
315 310
316 GNUNET_GETOPT_option_relative_time ('T', 311 GNUNET_GETOPT_option_relative_time (
317 "timeout", 312 'T',
318 "TIMEOUT", 313 "timeout",
319 gettext_noop ("how long should the monitor command run"), 314 "TIMEOUT",
320 &timeout_request), 315 gettext_noop ("how long should the monitor command run"),
316 &timeout_request),
321 317
322 GNUNET_GETOPT_option_flag ('V', 318 GNUNET_GETOPT_option_flag ('V',
323 "verbose", 319 "verbose",
324 gettext_noop ("be verbose (print progress information)"), 320 gettext_noop (
325 &verbose), 321 "be verbose (print progress information)"),
322 &verbose),
326 323
327 GNUNET_GETOPT_OPTION_END 324 GNUNET_GETOPT_OPTION_END};
328 };
329 325
330 326
331 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 327 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
332 return 2; 328 return 2;
333 329
334 return (GNUNET_OK == 330 return (GNUNET_OK ==
335 GNUNET_PROGRAM_run (argc, argv, "gnunet-dht-monitor", 331 GNUNET_PROGRAM_run (argc,
336 gettext_noop 332 argv,
337 ("Prints all packets that go through the DHT."), 333 "gnunet-dht-monitor",
338 options, &run, NULL)) ? ret : 1; 334 gettext_noop (
335 "Prints all packets that go through the DHT."),
336 options,
337 &run,
338 NULL))
339 ? ret
340 : 1;
339} 341}
340 342
341/* end of gnunet-dht-monitor.c */ 343/* end of gnunet-dht-monitor.c */
diff --git a/src/dht/gnunet-dht-put.c b/src/dht/gnunet-dht-put.c
index 4c26f98a5..0432dc4a0 100644
--- a/src/dht/gnunet-dht-put.c
+++ b/src/dht/gnunet-dht-put.c
@@ -107,8 +107,7 @@ shutdown_task (void *cls)
107static void 107static void
108message_sent_cont (void *cls) 108message_sent_cont (void *cls)
109{ 109{
110 GNUNET_SCHEDULER_add_now (&shutdown_task, 110 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
111 NULL);
112} 111}
113 112
114 113
@@ -131,26 +130,25 @@ run (void *cls,
131 cfg = c; 130 cfg = c;
132 if ((NULL == query_key) || (NULL == data)) 131 if ((NULL == query_key) || (NULL == data))
133 { 132 {
134 FPRINTF (stderr, "%s", _("Must provide KEY and DATA for DHT put!\n")); 133 fprintf (stderr, "%s", _ ("Must provide KEY and DATA for DHT put!\n"));
135 ret = 1; 134 ret = 1;
136 return; 135 return;
137 } 136 }
138 137
139 if (NULL == (dht_handle = GNUNET_DHT_connect (cfg, 1))) 138 if (NULL == (dht_handle = GNUNET_DHT_connect (cfg, 1)))
140 { 139 {
141 FPRINTF (stderr, 140 fprintf (stderr, _ ("Could not connect to DHT service!\n"));
142 _("Could not connect to DHT service!\n"));
143 ret = 1; 141 ret = 1;
144 return; 142 return;
145 } 143 }
146 if (GNUNET_BLOCK_TYPE_ANY == query_type) /* Type of data not set */ 144 if (GNUNET_BLOCK_TYPE_ANY == query_type) /* Type of data not set */
147 query_type = GNUNET_BLOCK_TYPE_TEST; 145 query_type = GNUNET_BLOCK_TYPE_TEST;
148 146
149 GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key); 147 GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key);
150 148
151 if (verbose) 149 if (verbose)
152 FPRINTF (stderr, 150 fprintf (stderr,
153 _("Issuing put request for `%s' with data `%s'!\n"), 151 _ ("Issuing put request for `%s' with data `%s'!\n"),
154 query_key, 152 query_key,
155 data); 153 data);
156 ro = GNUNET_DHT_RO_NONE; 154 ro = GNUNET_DHT_RO_NONE;
@@ -181,60 +179,62 @@ int
181main (int argc, char *const *argv) 179main (int argc, char *const *argv)
182{ 180{
183 181
184 struct GNUNET_GETOPT_CommandLineOption options[] = { 182 struct GNUNET_GETOPT_CommandLineOption options[] =
185 GNUNET_GETOPT_option_string ('d', 183 {GNUNET_GETOPT_option_string ('d',
186 "data", 184 "data",
187 "DATA", 185 "DATA",
188 gettext_noop ("the data to insert under the key"), 186 gettext_noop (
189 &data), 187 "the data to insert under the key"),
190 GNUNET_GETOPT_option_relative_time ('e', 188 &data),
191 "expiration", 189 GNUNET_GETOPT_option_relative_time (
192 "EXPIRATION", 190 'e',
193 gettext_noop ("how long to store this entry in the dht (in seconds)"), 191 "expiration",
194 &expiration), 192 "EXPIRATION",
195 GNUNET_GETOPT_option_string ('k', 193 gettext_noop ("how long to store this entry in the dht (in seconds)"),
196 "key", 194 &expiration),
197 "KEY", 195 GNUNET_GETOPT_option_string ('k',
198 gettext_noop ("the query key"), 196 "key",
199 &query_key), 197 "KEY",
200 GNUNET_GETOPT_option_flag ('x', 198 gettext_noop ("the query key"),
201 "demultiplex", 199 &query_key),
202 gettext_noop ("use DHT's demultiplex everywhere option"), 200 GNUNET_GETOPT_option_flag ('x',
203 &demultixplex_everywhere), 201 "demultiplex",
204 GNUNET_GETOPT_option_uint ('r', 202 gettext_noop (
205 "replication", 203 "use DHT's demultiplex everywhere option"),
206 "LEVEL", 204 &demultixplex_everywhere),
207 gettext_noop ("how many replicas to create"), 205 GNUNET_GETOPT_option_uint ('r',
208 &replication), 206 "replication",
209 GNUNET_GETOPT_option_flag ('R', 207 "LEVEL",
210 "record", 208 gettext_noop ("how many replicas to create"),
211 gettext_noop ("use DHT's record route option"), 209 &replication),
212 &record_route), 210 GNUNET_GETOPT_option_flag ('R',
213 GNUNET_GETOPT_option_uint ('t', 211 "record",
214 "type", 212 gettext_noop ("use DHT's record route option"),
215 "TYPE", 213 &record_route),
216 gettext_noop ("the type to insert data as"), 214 GNUNET_GETOPT_option_uint ('t',
217 &query_type), 215 "type",
218 GNUNET_GETOPT_option_verbose (&verbose), 216 "TYPE",
219 GNUNET_GETOPT_OPTION_END 217 gettext_noop ("the type to insert data as"),
220 }; 218 &query_type),
221 219 GNUNET_GETOPT_option_verbose (&verbose),
222 220 GNUNET_GETOPT_OPTION_END};
223 if (GNUNET_OK != 221
224 GNUNET_STRINGS_get_utf8_args (argc, argv, 222
225 &argc, &argv)) 223 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
226 return 2; 224 return 2;
227 expiration = GNUNET_TIME_UNIT_HOURS; 225 expiration = GNUNET_TIME_UNIT_HOURS;
228 return (GNUNET_OK == 226 return (GNUNET_OK ==
229 GNUNET_PROGRAM_run (argc, 227 GNUNET_PROGRAM_run (
230 argv, 228 argc,
231 "gnunet-dht-put", 229 argv,
232 gettext_noop 230 "gnunet-dht-put",
233 ("Issue a PUT request to the GNUnet DHT insert DATA under KEY."), 231 gettext_noop (
234 options, 232 "Issue a PUT request to the GNUnet DHT insert DATA under KEY."),
235 &run, 233 options,
236 NULL)) 234 &run,
237 ? ret : 1; 235 NULL))
236 ? ret
237 : 1;
238} 238}
239 239
240/* end of gnunet-dht-put.c */ 240/* end of gnunet-dht-put.c */
diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c
index 38adbc219..7ec6758b7 100644
--- a/src/dht/test_dht_api.c
+++ b/src/dht/test_dht_api.c
@@ -74,7 +74,7 @@ static void
74end_badly (void *cls) 74end_badly (void *cls)
75{ 75{
76 die_task = NULL; 76 die_task = NULL;
77 FPRINTF (stderr, 77 fprintf (stderr,
78 "%s", 78 "%s",
79 "Ending on an unhappy note.\n"); 79 "Ending on an unhappy note.\n");
80 GNUNET_SCHEDULER_shutdown (); 80 GNUNET_SCHEDULER_shutdown ();
diff --git a/src/dht/test_dht_topo.c b/src/dht/test_dht_topo.c
index 2ff0e7a59..a0d80e52c 100644
--- a/src/dht/test_dht_topo.c
+++ b/src/dht/test_dht_topo.c
@@ -212,7 +212,7 @@ stats_finished (void *cls,
212 return; 212 return;
213 } 213 }
214 for (i = 0; NULL != stats[i].name; i++) 214 for (i = 0; NULL != stats[i].name; i++)
215 FPRINTF (stderr, 215 fprintf (stderr,
216 "%6s/%60s = %12llu\n", 216 "%6s/%60s = %12llu\n",
217 stats[i].subsystem, 217 stats[i].subsystem,
218 stats[i].name, 218 stats[i].name,
diff --git a/src/fragmentation/test_fragmentation.c b/src/fragmentation/test_fragmentation.c
index 0bf3b2ab1..a49f6d71a 100644
--- a/src/fragmentation/test_fragmentation.c
+++ b/src/fragmentation/test_fragmentation.c
@@ -98,7 +98,7 @@ proc_msgs (void *cls, const struct GNUNET_MessageHeader *hdr)
98 const char *buf; 98 const char *buf;
99 99
100#if DETAILS 100#if DETAILS
101 FPRINTF (stderr, "%s", "M! "); /* message complete, good! */ 101 fprintf (stderr, "%s", "M! "); /* message complete, good! */
102#endif 102#endif
103 buf = (const char *) hdr; 103 buf = (const char *) hdr;
104 for (i = sizeof (struct GNUNET_MessageHeader); i < ntohs (hdr->size); i++) 104 for (i = sizeof (struct GNUNET_MessageHeader); i < ntohs (hdr->size); i++)
@@ -106,7 +106,7 @@ proc_msgs (void *cls, const struct GNUNET_MessageHeader *hdr)
106 total++; 106 total++;
107#if ! DETAILS 107#if ! DETAILS
108 if (0 == (total % (NUM_MSGS / 100))) 108 if (0 == (total % (NUM_MSGS / 100)))
109 FPRINTF (stderr, "%s", "."); 109 fprintf (stderr, "%s", ".");
110#endif 110#endif
111 /* tolerate 10% loss, i.e. due to duplicate fragment IDs */ 111 /* tolerate 10% loss, i.e. due to duplicate fragment IDs */
112 if ((total >= NUM_MSGS - (NUM_MSGS / 10)) && (ret != 0)) 112 if ((total >= NUM_MSGS - (NUM_MSGS / 10)) && (ret != 0))
@@ -131,27 +131,27 @@ proc_frac (void *cls, const struct GNUNET_MessageHeader *hdr)
131 { 131 {
132 frag_drops++; 132 frag_drops++;
133#if DETAILS 133#if DETAILS
134 FPRINTF (stderr, "%s", "DF "); /* dropped Frag */ 134 fprintf (stderr, "%s", "DF "); /* dropped Frag */
135#endif 135#endif
136 return; /* random drop */ 136 return; /* random drop */
137 } 137 }
138 if (NULL == defrag) 138 if (NULL == defrag)
139 { 139 {
140 FPRINTF (stderr, "%s", "?E "); /* Error: frag after shutdown!? */ 140 fprintf (stderr, "%s", "?E "); /* Error: frag after shutdown!? */
141 return; 141 return;
142 } 142 }
143 ret = GNUNET_DEFRAGMENT_process_fragment (defrag, hdr); 143 ret = GNUNET_DEFRAGMENT_process_fragment (defrag, hdr);
144 if (ret == GNUNET_NO) 144 if (ret == GNUNET_NO)
145 { 145 {
146#if DETAILS 146#if DETAILS
147 FPRINTF (stderr, "%s", "FF "); /* duplicate fragment */ 147 fprintf (stderr, "%s", "FF "); /* duplicate fragment */
148#endif 148#endif
149 dups++; 149 dups++;
150 } 150 }
151 else if (ret == GNUNET_OK) 151 else if (ret == GNUNET_OK)
152 { 152 {
153#if DETAILS 153#if DETAILS
154 FPRINTF (stderr, "%s", "F! "); /* good fragment */ 154 fprintf (stderr, "%s", "F! "); /* good fragment */
155#endif 155#endif
156 fragc++; 156 fragc++;
157 } 157 }
@@ -181,7 +181,7 @@ next_transmission ()
181 if (i == NUM_MSGS) 181 if (i == NUM_MSGS)
182 return; 182 return;
183#if DETAILS 183#if DETAILS
184 FPRINTF (stderr, "%s", "T! "); /* sending message */ 184 fprintf (stderr, "%s", "T! "); /* sending message */
185#endif 185#endif
186 msg = (struct GNUNET_MessageHeader *) buf; 186 msg = (struct GNUNET_MessageHeader *) buf;
187 msg->type = htons ((uint16_t) i); 187 msg->type = htons ((uint16_t) i);
@@ -212,7 +212,7 @@ proc_acks (void *cls,
212 { 212 {
213 ack_drops++; 213 ack_drops++;
214#if DETAILS 214#if DETAILS
215 FPRINTF (stderr, "%s", "DA "); /* dropped ACK */ 215 fprintf (stderr, "%s", "DA "); /* dropped ACK */
216#endif 216#endif
217 return; /* random drop */ 217 return; /* random drop */
218 } 218 }
@@ -224,7 +224,7 @@ proc_acks (void *cls,
224 if (ret == GNUNET_OK) 224 if (ret == GNUNET_OK)
225 { 225 {
226#if DETAILS 226#if DETAILS
227 FPRINTF (stderr, "%s", "GA "); /* good ACK */ 227 fprintf (stderr, "%s", "GA "); /* good ACK */
228#endif 228#endif
229 next_transmission (); 229 next_transmission ();
230 acks++; 230 acks++;
@@ -233,14 +233,14 @@ proc_acks (void *cls,
233 if (ret == GNUNET_NO) 233 if (ret == GNUNET_NO)
234 { 234 {
235#if DETAILS 235#if DETAILS
236 FPRINTF (stderr, "%s", "AA "); /* duplciate ACK */ 236 fprintf (stderr, "%s", "AA "); /* duplciate ACK */
237#endif 237#endif
238 acks++; 238 acks++;
239 return; 239 return;
240 } 240 }
241 } 241 }
242#if DETAILS 242#if DETAILS
243 FPRINTF (stderr, "%s", "?A "); /* BAD: ack that nobody feels responsible for... */ 243 fprintf (stderr, "%s", "?A "); /* BAD: ack that nobody feels responsible for... */
244#endif 244#endif
245} 245}
246 246
@@ -293,7 +293,7 @@ main (int argc, char *argv[])
293 "test-fragmentation", "nohelp", 293 "test-fragmentation", "nohelp",
294 options, 294 options,
295 &run, NULL); 295 &run, NULL);
296 FPRINTF (stderr, 296 fprintf (stderr,
297 "\nHad %u good fragments, %u duplicate fragments, %u acks and %u simulated drops of acks\n", 297 "\nHad %u good fragments, %u duplicate fragments, %u acks and %u simulated drops of acks\n",
298 fragc, 298 fragc,
299 dups, 299 dups,
diff --git a/src/fragmentation/test_fragmentation_parallel.c b/src/fragmentation/test_fragmentation_parallel.c
index 5cde75c0b..d8e598484 100644
--- a/src/fragmentation/test_fragmentation_parallel.c
+++ b/src/fragmentation/test_fragmentation_parallel.c
@@ -90,7 +90,7 @@ proc_msgs (void *cls, const struct GNUNET_MessageHeader *hdr)
90 const char *buf; 90 const char *buf;
91 91
92#if DETAILS 92#if DETAILS
93 FPRINTF (stderr, "%s", "!"); /* message complete, good! */ 93 fprintf (stderr, "%s", "!"); /* message complete, good! */
94#endif 94#endif
95 buf = (const char *) hdr; 95 buf = (const char *) hdr;
96 for (i = sizeof (struct GNUNET_MessageHeader); i < ntohs (hdr->size); i++) 96 for (i = sizeof (struct GNUNET_MessageHeader); i < ntohs (hdr->size); i++)
@@ -98,7 +98,7 @@ proc_msgs (void *cls, const struct GNUNET_MessageHeader *hdr)
98 total++; 98 total++;
99#if ! DETAILS 99#if ! DETAILS
100 if (0 == (total % (NUM_MSGS / 100))) 100 if (0 == (total % (NUM_MSGS / 100)))
101 FPRINTF (stderr, "%s", "."); 101 fprintf (stderr, "%s", ".");
102#endif 102#endif
103 /* tolerate 10% loss, i.e. due to duplicate fragment IDs */ 103 /* tolerate 10% loss, i.e. due to duplicate fragment IDs */
104 if ((total >= NUM_MSGS - (NUM_MSGS / 10)) && (ret != 0)) 104 if ((total >= NUM_MSGS - (NUM_MSGS / 10)) && (ret != 0))
@@ -131,7 +131,7 @@ proc_acks (void *cls, uint32_t msg_id, const struct GNUNET_MessageHeader *hdr)
131 if (ret == GNUNET_OK) 131 if (ret == GNUNET_OK)
132 { 132 {
133#if DETAILS 133#if DETAILS
134 FPRINTF (stderr, "%s", "@"); /* good ACK */ 134 fprintf (stderr, "%s", "@"); /* good ACK */
135#endif 135#endif
136 GNUNET_FRAGMENT_context_destroy (frags[i], NULL, NULL); 136 GNUNET_FRAGMENT_context_destroy (frags[i], NULL, NULL);
137 frags[i] = NULL; 137 frags[i] = NULL;
@@ -141,14 +141,14 @@ proc_acks (void *cls, uint32_t msg_id, const struct GNUNET_MessageHeader *hdr)
141 if (ret == GNUNET_NO) 141 if (ret == GNUNET_NO)
142 { 142 {
143#if DETAILS 143#if DETAILS
144 FPRINTF (stderr, "%s", "@"); /* good ACK */ 144 fprintf (stderr, "%s", "@"); /* good ACK */
145#endif 145#endif
146 acks++; 146 acks++;
147 return; 147 return;
148 } 148 }
149 } 149 }
150#if DETAILS 150#if DETAILS
151 FPRINTF (stderr, "%s", "_"); /* BAD: ack that nobody feels responsible for... */ 151 fprintf (stderr, "%s", "_"); /* BAD: ack that nobody feels responsible for... */
152#endif 152#endif
153} 153}
154 154
@@ -170,21 +170,21 @@ proc_frac (void *cls, const struct GNUNET_MessageHeader *hdr)
170 } 170 }
171 if (NULL == defrag) 171 if (NULL == defrag)
172 { 172 {
173 FPRINTF (stderr, "%s", "E"); /* Error: frag after shutdown!? */ 173 fprintf (stderr, "%s", "E"); /* Error: frag after shutdown!? */
174 return; 174 return;
175 } 175 }
176 ret = GNUNET_DEFRAGMENT_process_fragment (defrag, hdr); 176 ret = GNUNET_DEFRAGMENT_process_fragment (defrag, hdr);
177 if (ret == GNUNET_NO) 177 if (ret == GNUNET_NO)
178 { 178 {
179#if DETAILS 179#if DETAILS
180 FPRINTF (stderr, "%s", "?"); /* duplicate fragment */ 180 fprintf (stderr, "%s", "?"); /* duplicate fragment */
181#endif 181#endif
182 dups++; 182 dups++;
183 } 183 }
184 else if (ret == GNUNET_OK) 184 else if (ret == GNUNET_OK)
185 { 185 {
186#if DETAILS 186#if DETAILS
187 FPRINTF (stderr, "%s", "."); /* good fragment */ 187 fprintf (stderr, "%s", "."); /* good fragment */
188#endif 188#endif
189 fragc++; 189 fragc++;
190 } 190 }
@@ -247,7 +247,7 @@ main (int argc, char *argv[])
247 100); 247 100);
248 GNUNET_PROGRAM_run (5, argv_prog, "test-fragmentation", "nohelp", options, 248 GNUNET_PROGRAM_run (5, argv_prog, "test-fragmentation", "nohelp", options,
249 &run, NULL); 249 &run, NULL);
250 FPRINTF (stderr, 250 fprintf (stderr,
251 "\nHad %u good fragments, %u duplicate fragments, %u acks and %u simulated drops of acks\n", 251 "\nHad %u good fragments, %u duplicate fragments, %u acks and %u simulated drops of acks\n",
252 fragc, dups, acks, ack_drops); 252 fragc, dups, acks, ack_drops);
253 return ret; 253 return ret;
diff --git a/src/fs/fs_api.c b/src/fs/fs_api.c
index aec5ff340..f7b64a5c9 100644
--- a/src/fs/fs_api.c
+++ b/src/fs/fs_api.c
@@ -56,12 +56,10 @@ start_job (struct GNUNET_FS_QueueEntry *qe)
56 qe->h->active_downloads++; 56 qe->h->active_downloads++;
57 qe->start_time = GNUNET_TIME_absolute_get (); 57 qe->start_time = GNUNET_TIME_absolute_get ();
58 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 58 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
59 "Starting job %p (%u active)\n", 59 "Starting job %p (%u active)\n",
60 qe, 60 qe,
61 qe->h->active_downloads); 61 qe->h->active_downloads);
62 GNUNET_CONTAINER_DLL_remove (qe->h->pending_head, 62 GNUNET_CONTAINER_DLL_remove (qe->h->pending_head, qe->h->pending_tail, qe);
63 qe->h->pending_tail,
64 qe);
65 GNUNET_CONTAINER_DLL_insert_after (qe->h->running_head, 63 GNUNET_CONTAINER_DLL_insert_after (qe->h->running_head,
66 qe->h->running_tail, 64 qe->h->running_tail,
67 qe->h->running_tail, 65 qe->h->running_tail,
@@ -83,17 +81,14 @@ stop_job (struct GNUNET_FS_QueueEntry *qe)
83 GNUNET_assert (0 < qe->h->active_downloads); 81 GNUNET_assert (0 < qe->h->active_downloads);
84 qe->h->active_downloads--; 82 qe->h->active_downloads--;
85 qe->h->active_blocks -= qe->blocks; 83 qe->h->active_blocks -= qe->blocks;
86 qe->run_time = 84 qe->run_time = GNUNET_TIME_relative_add (qe->run_time,
87 GNUNET_TIME_relative_add (qe->run_time, 85 GNUNET_TIME_absolute_get_duration (
88 GNUNET_TIME_absolute_get_duration 86 qe->start_time));
89 (qe->start_time));
90 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 87 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
91 "Stopping job %p (%u active)\n", 88 "Stopping job %p (%u active)\n",
92 qe, 89 qe,
93 qe->h->active_downloads); 90 qe->h->active_downloads);
94 GNUNET_CONTAINER_DLL_remove (qe->h->running_head, 91 GNUNET_CONTAINER_DLL_remove (qe->h->running_head, qe->h->running_tail, qe);
95 qe->h->running_tail,
96 qe);
97 GNUNET_CONTAINER_DLL_insert_after (qe->h->pending_head, 92 GNUNET_CONTAINER_DLL_insert_after (qe->h->pending_head,
98 qe->h->pending_tail, 93 qe->h->pending_tail,
99 qe->h->pending_tail, 94 qe->h->pending_tail,
@@ -167,13 +162,13 @@ process_job_queue (void *cls)
167 rst = GNUNET_TIME_absolute_get_remaining (end_time); 162 rst = GNUNET_TIME_absolute_get_remaining (end_time);
168 if (0 == rst.rel_value_us) 163 if (0 == rst.rel_value_us)
169 { 164 {
170 num_probes_expired++; 165 num_probes_expired++;
171 stop_job (qe); 166 stop_job (qe);
172 } 167 }
173 else 168 else
174 { 169 {
175 num_probes_active++; 170 num_probes_active++;
176 restart_at = GNUNET_TIME_relative_min (rst, restart_at); 171 restart_at = GNUNET_TIME_relative_min (rst, restart_at);
177 } 172 }
178 break; 173 break;
179 case GNUNET_FS_QUEUE_PRIORITY_NORMAL: 174 case GNUNET_FS_QUEUE_PRIORITY_NORMAL:
@@ -184,13 +179,13 @@ process_job_queue (void *cls)
184 rst = GNUNET_TIME_absolute_get_remaining (end_time); 179 rst = GNUNET_TIME_absolute_get_remaining (end_time);
185 if (0 == rst.rel_value_us) 180 if (0 == rst.rel_value_us)
186 { 181 {
187 num_downloads_expired++; 182 num_downloads_expired++;
188 stop_job (qe); 183 stop_job (qe);
189 } 184 }
190 else 185 else
191 { 186 {
192 num_downloads_active++; 187 num_downloads_active++;
193 restart_at = GNUNET_TIME_relative_min (rst, restart_at); 188 restart_at = GNUNET_TIME_relative_min (rst, restart_at);
194 } 189 }
195 break; 190 break;
196 default: 191 default:
@@ -201,41 +196,44 @@ process_job_queue (void *cls)
201 GNUNET_break (h->active_downloads == 196 GNUNET_break (h->active_downloads ==
202 num_downloads_active + num_probes_active); 197 num_downloads_active + num_probes_active);
203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
204 "PA: %u, PE: %u, PW: %u; DA: %u, DE: %u, DW: %u\n", 199 "PA: %u, PE: %u, PW: %u; DA: %u, DE: %u, DW: %u\n",
205 num_probes_active, 200 num_probes_active,
206 num_probes_expired, 201 num_probes_expired,
207 num_probes_waiting, 202 num_probes_waiting,
208 num_downloads_active, 203 num_downloads_active,
209 num_downloads_expired, 204 num_downloads_expired,
210 num_downloads_waiting); 205 num_downloads_waiting);
211 GNUNET_break (h->active_downloads + num_probes_active <= 206 GNUNET_break (h->active_downloads + num_probes_active <=
212 h->max_parallel_downloads); 207 h->max_parallel_downloads);
213 /* calculate start/stop decisions */ 208 /* calculate start/stop decisions */
214 if (h->active_downloads + num_downloads_waiting > h->max_parallel_downloads) 209 if (h->active_downloads + num_downloads_waiting > h->max_parallel_downloads)
215 { 210 {
216 /* stop as many probes as there are downloads and probes */ 211 /* stop as many probes as there are downloads and probes */
217 num_probes_change = - GNUNET_MIN (num_probes_active, 212 num_probes_change = -GNUNET_MIN (num_probes_active, num_downloads_waiting);
218 num_downloads_waiting);
219 /* start as many downloads as there are free slots, including those 213 /* start as many downloads as there are free slots, including those
220 we just opened up */ 214 we just opened up */
221 num_downloads_change = h->max_parallel_downloads - h->active_downloads - num_probes_change; 215 num_downloads_change =
216 h->max_parallel_downloads - h->active_downloads - num_probes_change;
222 } 217 }
223 else 218 else
224 { 219 {
225 /* start all downloads (we can) */ 220 /* start all downloads (we can) */
226 num_downloads_change = num_downloads_waiting; 221 num_downloads_change = num_downloads_waiting;
227 /* also start probes if there is room, but use a lower cap of (mpd/4) + 1 */ 222 /* also start probes if there is room, but use a lower cap of (mpd/4) + 1 */
228 if (1 + h->max_parallel_downloads / 4 >= (h->active_downloads + num_downloads_change)) 223 if (1 + h->max_parallel_downloads / 4 >=
229 num_probes_change = GNUNET_MIN (num_probes_waiting, 224 (h->active_downloads + num_downloads_change))
230 (1 + h->max_parallel_downloads / 4) - (h->active_downloads + num_downloads_change)); 225 num_probes_change =
226 GNUNET_MIN (num_probes_waiting,
227 (1 + h->max_parallel_downloads / 4) -
228 (h->active_downloads + num_downloads_change));
231 else 229 else
232 num_probes_change = 0; 230 num_probes_change = 0;
233 } 231 }
234 GNUNET_break (num_downloads_change <= num_downloads_waiting); 232 GNUNET_break (num_downloads_change <= num_downloads_waiting);
235 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
236 "Changing %d probes and %d/%u/%u downloads\n", 234 "Changing %d probes and %d/%u/%u downloads\n",
237 num_probes_change, 235 num_probes_change,
238 num_downloads_change, 236 num_downloads_change,
239 (unsigned int) h->active_downloads, 237 (unsigned int) h->active_downloads,
240 (unsigned int) h->max_parallel_downloads); 238 (unsigned int) h->max_parallel_downloads);
241 /* actually stop probes */ 239 /* actually stop probes */
@@ -250,7 +248,7 @@ process_job_queue (void *cls)
250 stop_job (qe); 248 stop_job (qe);
251 num_probes_change++; 249 num_probes_change++;
252 if (0 == num_probes_change) 250 if (0 == num_probes_change)
253 break; 251 break;
254 } 252 }
255 } 253 }
256 GNUNET_break (0 <= num_probes_change); 254 GNUNET_break (0 <= num_probes_change);
@@ -258,9 +256,8 @@ process_job_queue (void *cls)
258 /* start some more tasks if we now have empty slots */ 256 /* start some more tasks if we now have empty slots */
259 block_limit_hit = GNUNET_NO; 257 block_limit_hit = GNUNET_NO;
260 next = h->pending_head; 258 next = h->pending_head;
261 while ( (NULL != (qe = next)) && 259 while ((NULL != (qe = next)) &&
262 ( (num_probes_change > 0) || 260 ((num_probes_change > 0) || (num_downloads_change > 0)))
263 (num_downloads_change > 0) ) )
264 { 261 {
265 next = qe->next; 262 next = qe->next;
266 switch (qe->priority) 263 switch (qe->priority)
@@ -268,40 +265,40 @@ process_job_queue (void *cls)
268 case GNUNET_FS_QUEUE_PRIORITY_PROBE: 265 case GNUNET_FS_QUEUE_PRIORITY_PROBE:
269 if (num_probes_change > 0) 266 if (num_probes_change > 0)
270 { 267 {
271 start_job (qe); 268 start_job (qe);
272 num_probes_change--; 269 num_probes_change--;
273 run_time = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2); 270 run_time = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2);
274 restart_at = GNUNET_TIME_relative_min (run_time, restart_at); 271 restart_at = GNUNET_TIME_relative_min (run_time, restart_at);
275 } 272 }
276 break; 273 break;
277 case GNUNET_FS_QUEUE_PRIORITY_NORMAL: 274 case GNUNET_FS_QUEUE_PRIORITY_NORMAL:
278 if ( (num_downloads_change > 0) && 275 if ((num_downloads_change > 0) &&
279 ( (qe->blocks + h->active_blocks <= h->max_parallel_requests) || 276 ((qe->blocks + h->active_blocks <= h->max_parallel_requests) ||
280 ( (qe->blocks > h->max_parallel_requests) && 277 ((qe->blocks > h->max_parallel_requests) &&
281 (0 == h->active_downloads) ) ) ) 278 (0 == h->active_downloads))))
282 { 279 {
283 start_job (qe); 280 start_job (qe);
284 num_downloads_change--; 281 num_downloads_change--;
285 } 282 }
286 else if (num_downloads_change > 0) 283 else if (num_downloads_change > 0)
287 block_limit_hit = GNUNET_YES; 284 block_limit_hit = GNUNET_YES;
288 break; 285 break;
289 default: 286 default:
290 GNUNET_break (0); 287 GNUNET_break (0);
291 break; 288 break;
292 } 289 }
293 } 290 }
294 GNUNET_break ( (0 == num_downloads_change) || 291 GNUNET_break ((0 == num_downloads_change) || (GNUNET_YES == block_limit_hit));
295 (GNUNET_YES == block_limit_hit) );
296 GNUNET_break (0 == num_probes_change); 292 GNUNET_break (0 == num_probes_change);
297 293
298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 294 GNUNET_log (
299 "AD: %u, MP: %u; %d probes and %d downloads to start, will run again in %s\n", 295 GNUNET_ERROR_TYPE_DEBUG,
300 h->active_downloads, 296 "AD: %u, MP: %u; %d probes and %d downloads to start, will run again in %s\n",
301 h->max_parallel_requests, 297 h->active_downloads,
302 num_probes_change, 298 h->max_parallel_requests,
303 num_downloads_change, 299 num_probes_change,
304 GNUNET_STRINGS_relative_time_to_string (restart_at, GNUNET_YES)); 300 num_downloads_change,
301 GNUNET_STRINGS_relative_time_to_string (restart_at, GNUNET_YES));
305 302
306 /* make sure we run again, callbacks might have 303 /* make sure we run again, callbacks might have
307 already re-scheduled the job, so cancel such 304 already re-scheduled the job, so cancel such
@@ -309,7 +306,7 @@ process_job_queue (void *cls)
309 if (NULL != h->queue_job) 306 if (NULL != h->queue_job)
310 GNUNET_SCHEDULER_cancel (h->queue_job); 307 GNUNET_SCHEDULER_cancel (h->queue_job);
311 h->queue_job = 308 h->queue_job =
312 GNUNET_SCHEDULER_add_delayed (restart_at, &process_job_queue, h); 309 GNUNET_SCHEDULER_add_delayed (restart_at, &process_job_queue, h);
313} 310}
314 311
315 312
@@ -330,7 +327,7 @@ GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h,
330 GNUNET_SCHEDULER_TaskCallback stop, 327 GNUNET_SCHEDULER_TaskCallback stop,
331 void *cls, 328 void *cls,
332 unsigned int blocks, 329 unsigned int blocks,
333 enum GNUNET_FS_QueuePriority priority) 330 enum GNUNET_FS_QueuePriority priority)
334{ 331{
335 struct GNUNET_FS_QueueEntry *qe; 332 struct GNUNET_FS_QueueEntry *qe;
336 333
@@ -342,14 +339,14 @@ GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h,
342 qe->queue_time = GNUNET_TIME_absolute_get (); 339 qe->queue_time = GNUNET_TIME_absolute_get ();
343 qe->blocks = blocks; 340 qe->blocks = blocks;
344 qe->priority = priority; 341 qe->priority = priority;
345 GNUNET_CONTAINER_DLL_insert_after (h->pending_head, h->pending_tail, 342 GNUNET_CONTAINER_DLL_insert_after (h->pending_head,
346 h->pending_tail, qe); 343 h->pending_tail,
344 h->pending_tail,
345 qe);
347 if (NULL != h->queue_job) 346 if (NULL != h->queue_job)
348 GNUNET_SCHEDULER_cancel (h->queue_job); 347 GNUNET_SCHEDULER_cancel (h->queue_job);
349 h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h); 348 h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h);
350 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 349 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queueing job %p\n", qe);
351 "Queueing job %p\n",
352 qe);
353 return qe; 350 return qe;
354} 351}
355 352
@@ -365,19 +362,14 @@ GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe)
365 struct GNUNET_FS_Handle *h; 362 struct GNUNET_FS_Handle *h;
366 363
367 h = qe->h; 364 h = qe->h;
368 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 365 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dequeueing job %p\n", qe);
369 "Dequeueing job %p\n",
370 qe);
371 if (GNUNET_YES == qe->active) 366 if (GNUNET_YES == qe->active)
372 stop_job (qe); 367 stop_job (qe);
373 GNUNET_CONTAINER_DLL_remove (h->pending_head, 368 GNUNET_CONTAINER_DLL_remove (h->pending_head, h->pending_tail, qe);
374 h->pending_tail,
375 qe);
376 GNUNET_free (qe); 369 GNUNET_free (qe);
377 if (NULL != h->queue_job) 370 if (NULL != h->queue_job)
378 GNUNET_SCHEDULER_cancel (h->queue_job); 371 GNUNET_SCHEDULER_cancel (h->queue_job);
379 h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, 372 h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h);
380 h);
381} 373}
382 374
383 375
@@ -399,9 +391,7 @@ GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
399 ret = GNUNET_new (struct TopLevelActivity); 391 ret = GNUNET_new (struct TopLevelActivity);
400 ret->ssf = ssf; 392 ret->ssf = ssf;
401 ret->ssf_cls = ssf_cls; 393 ret->ssf_cls = ssf_cls;
402 GNUNET_CONTAINER_DLL_insert (h->top_head, 394 GNUNET_CONTAINER_DLL_insert (h->top_head, h->top_tail, ret);
403 h->top_tail,
404 ret);
405 return ret; 395 return ret;
406} 396}
407 397
@@ -413,12 +403,9 @@ GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
413 * @param top top level activity entry 403 * @param top top level activity entry
414 */ 404 */
415void 405void
416GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, 406GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, struct TopLevelActivity *top)
417 struct TopLevelActivity *top)
418{ 407{
419 GNUNET_CONTAINER_DLL_remove (h->top_head, 408 GNUNET_CONTAINER_DLL_remove (h->top_head, h->top_tail, top);
420 h->top_tail,
421 top);
422 GNUNET_free (top); 409 GNUNET_free (top);
423} 410}
424 411
@@ -489,33 +476,32 @@ GNUNET_FS_data_reader_file_ (void *cls,
489 } 476 }
490 if (NULL == fi->fd) 477 if (NULL == fi->fd)
491 { 478 {
492 fi->fd = 479 fi->fd = GNUNET_DISK_file_open (fi->filename,
493 GNUNET_DISK_file_open (fi->filename, 480 GNUNET_DISK_OPEN_READ,
494 GNUNET_DISK_OPEN_READ, 481 GNUNET_DISK_PERM_NONE);
495 GNUNET_DISK_PERM_NONE);
496 if (NULL == fi->fd) 482 if (NULL == fi->fd)
497 { 483 {
498 GNUNET_asprintf (emsg, 484 GNUNET_asprintf (emsg,
499 _("Could not open file `%s': %s"), 485 _ ("Could not open file `%s': %s"),
500 fi->filename, 486 fi->filename,
501 STRERROR (errno)); 487 strerror (errno));
502 return 0; 488 return 0;
503 } 489 }
504 } 490 }
505 if ( (GNUNET_SYSERR == 491 if ((GNUNET_SYSERR ==
506 GNUNET_DISK_file_seek (fi->fd, offset, GNUNET_DISK_SEEK_SET)) || 492 GNUNET_DISK_file_seek (fi->fd, offset, GNUNET_DISK_SEEK_SET)) ||
507 (-1 == (ret = GNUNET_DISK_file_read (fi->fd, buf, max))) ) 493 (-1 == (ret = GNUNET_DISK_file_read (fi->fd, buf, max))))
508 { 494 {
509 GNUNET_asprintf (emsg, 495 GNUNET_asprintf (emsg,
510 _("Could not read file `%s': %s"), 496 _ ("Could not read file `%s': %s"),
511 fi->filename, 497 fi->filename,
512 STRERROR (errno)); 498 strerror (errno));
513 return 0; 499 return 0;
514 } 500 }
515 if (ret != max) 501 if (ret != max)
516 { 502 {
517 GNUNET_asprintf (emsg, 503 GNUNET_asprintf (emsg,
518 _("Short read reading from file `%s'!"), 504 _ ("Short read reading from file `%s'!"),
519 fi->filename); 505 fi->filename);
520 return 0; 506 return 0;
521 } 507 }
@@ -604,13 +590,20 @@ get_serialization_file_name (struct GNUNET_FS_Handle *h,
604 char *ret; 590 char *ret;
605 591
606 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) 592 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
607 return NULL; /* persistence not requested */ 593 return NULL; /* persistence not requested */
608 if (GNUNET_OK != 594 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (h->cfg,
609 GNUNET_CONFIGURATION_get_value_filename (h->cfg, "fs", "STATE_DIR", 595 "fs",
610 &basename)) 596 "STATE_DIR",
597 &basename))
611 return NULL; 598 return NULL;
612 GNUNET_asprintf (&ret, "%s%s%s%s%s%s%s", basename, DIR_SEPARATOR_STR, 599 GNUNET_asprintf (&ret,
613 h->client_name, DIR_SEPARATOR_STR, ext, DIR_SEPARATOR_STR, 600 "%s%s%s%s%s%s%s",
601 basename,
602 DIR_SEPARATOR_STR,
603 h->client_name,
604 DIR_SEPARATOR_STR,
605 ext,
606 DIR_SEPARATOR_STR,
614 ent); 607 ent);
615 GNUNET_free (basename); 608 GNUNET_free (basename);
616 return ret; 609 return ret;
@@ -638,14 +631,23 @@ get_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h,
638 char *ret; 631 char *ret;
639 632
640 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) 633 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
641 return NULL; /* persistence not requested */ 634 return NULL; /* persistence not requested */
642 if (GNUNET_OK != 635 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (h->cfg,
643 GNUNET_CONFIGURATION_get_value_filename (h->cfg, "fs", "STATE_DIR", 636 "fs",
644 &basename)) 637 "STATE_DIR",
638 &basename))
645 return NULL; 639 return NULL;
646 GNUNET_asprintf (&ret, "%s%s%s%s%s%s%s.dir%s%s", basename, DIR_SEPARATOR_STR, 640 GNUNET_asprintf (&ret,
647 h->client_name, DIR_SEPARATOR_STR, ext, DIR_SEPARATOR_STR, 641 "%s%s%s%s%s%s%s.dir%s%s",
648 uni, DIR_SEPARATOR_STR, ent); 642 basename,
643 DIR_SEPARATOR_STR,
644 h->client_name,
645 DIR_SEPARATOR_STR,
646 ext,
647 DIR_SEPARATOR_STR,
648 uni,
649 DIR_SEPARATOR_STR,
650 ent);
649 GNUNET_free (basename); 651 GNUNET_free (basename);
650 return ret; 652 return ret;
651} 653}
@@ -660,9 +662,7 @@ get_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h,
660 * @return NULL on error 662 * @return NULL on error
661 */ 663 */
662static struct GNUNET_BIO_ReadHandle * 664static struct GNUNET_BIO_ReadHandle *
663get_read_handle (struct GNUNET_FS_Handle *h, 665get_read_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
664 const char *ext,
665 const char *ent)
666{ 666{
667 char *fn; 667 char *fn;
668 struct GNUNET_BIO_ReadHandle *ret; 668 struct GNUNET_BIO_ReadHandle *ret;
@@ -685,9 +685,7 @@ get_read_handle (struct GNUNET_FS_Handle *h,
685 * @return NULL on error 685 * @return NULL on error
686 */ 686 */
687static struct GNUNET_BIO_WriteHandle * 687static struct GNUNET_BIO_WriteHandle *
688get_write_handle (struct GNUNET_FS_Handle *h, 688get_write_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
689 const char *ext,
690 const char *ent)
691{ 689{
692 char *fn; 690 char *fn;
693 struct GNUNET_BIO_WriteHandle *ret; 691 struct GNUNET_BIO_WriteHandle *ret;
@@ -712,8 +710,10 @@ get_write_handle (struct GNUNET_FS_Handle *h,
712 * @return NULL on error 710 * @return NULL on error
713 */ 711 */
714static struct GNUNET_BIO_WriteHandle * 712static struct GNUNET_BIO_WriteHandle *
715get_write_handle_in_dir (struct GNUNET_FS_Handle *h, const char *ext, 713get_write_handle_in_dir (struct GNUNET_FS_Handle *h,
716 const char *uni, const char *ent) 714 const char *ext,
715 const char *uni,
716 const char *ent)
717{ 717{
718 char *fn; 718 char *fn;
719 struct GNUNET_BIO_WriteHandle *ret; 719 struct GNUNET_BIO_WriteHandle *ret;
@@ -749,8 +749,7 @@ GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
749 filename = get_serialization_file_name (h, ext, ent); 749 filename = get_serialization_file_name (h, ext, ent);
750 if (NULL != filename) 750 if (NULL != filename)
751 { 751 {
752 if ( (0 != UNLINK (filename)) && 752 if ((0 != unlink (filename)) && (ENOENT != errno))
753 (ENOENT != errno) )
754 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); 753 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
755 GNUNET_free (filename); 754 GNUNET_free (filename);
756 } 755 }
@@ -768,7 +767,8 @@ GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
768static void 767static void
769remove_sync_file_in_dir (struct GNUNET_FS_Handle *h, 768remove_sync_file_in_dir (struct GNUNET_FS_Handle *h,
770 const char *ext, 769 const char *ext,
771 const char *uni, const char *ent) 770 const char *uni,
771 const char *ent)
772{ 772{
773 char *filename; 773 char *filename;
774 774
@@ -780,7 +780,7 @@ remove_sync_file_in_dir (struct GNUNET_FS_Handle *h,
780 filename = get_serialization_file_name_in_dir (h, ext, uni, ent); 780 filename = get_serialization_file_name_in_dir (h, ext, uni, ent);
781 if (NULL == filename) 781 if (NULL == filename)
782 return; 782 return;
783 if (0 != UNLINK (filename)) 783 if (0 != unlink (filename))
784 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); 784 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
785 GNUNET_free (filename); 785 GNUNET_free (filename);
786} 786}
@@ -874,8 +874,7 @@ read_start_time (struct GNUNET_BIO_ReadHandle *rh,
874 * @return NULL on error 874 * @return NULL on error
875 */ 875 */
876static struct GNUNET_FS_FileInformation * 876static struct GNUNET_FS_FileInformation *
877deserialize_file_information (struct GNUNET_FS_Handle *h, 877deserialize_file_information (struct GNUNET_FS_Handle *h, const char *filename);
878 const char *filename);
879 878
880 879
881/** 880/**
@@ -915,21 +914,22 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h,
915 filename = NULL; 914 filename = NULL;
916 if ((GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) || 915 if ((GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) ||
917 (GNUNET_OK != GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32 * 1024)) || 916 (GNUNET_OK != GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32 * 1024)) ||
918 ( (NULL != ksks) && 917 ((NULL != ksks) &&
919 ( (NULL == (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL))) || 918 ((NULL == (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL))) ||
920 (GNUNET_YES != GNUNET_FS_uri_test_ksk (ret->keywords)) ) ) || 919 (GNUNET_YES != GNUNET_FS_uri_test_ksk (ret->keywords)))) ||
921 (GNUNET_OK != GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) || 920 (GNUNET_OK != GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) ||
922 ( (NULL != chks) && 921 ((NULL != chks) &&
923 ( (NULL == (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) || 922 ((NULL == (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) ||
924 (GNUNET_YES != GNUNET_FS_uri_test_chk (ret->chk_uri))) ) || 923 (GNUNET_YES != GNUNET_FS_uri_test_chk (ret->chk_uri)))) ||
925 (GNUNET_OK != GNUNET_BIO_read_string (rh, "sks-uri", &skss, 1024)) || 924 (GNUNET_OK != GNUNET_BIO_read_string (rh, "sks-uri", &skss, 1024)) ||
926 ( (NULL != skss) && 925 ((NULL != skss) &&
927 ( (NULL == (ret->sks_uri = GNUNET_FS_uri_parse (skss, NULL))) || 926 ((NULL == (ret->sks_uri = GNUNET_FS_uri_parse (skss, NULL))) ||
928 (GNUNET_YES != GNUNET_FS_uri_test_sks (ret->sks_uri))) ) || 927 (GNUNET_YES != GNUNET_FS_uri_test_sks (ret->sks_uri)))) ||
929 (GNUNET_OK != read_start_time (rh, &ret->start_time)) || 928 (GNUNET_OK != read_start_time (rh, &ret->start_time)) ||
930 (GNUNET_OK != GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16 * 1024)) 929 (GNUNET_OK !=
931 || (GNUNET_OK != 930 GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16 * 1024)) ||
932 GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) || 931 (GNUNET_OK !=
932 GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) ||
933 (GNUNET_OK != 933 (GNUNET_OK !=
934 GNUNET_BIO_read_int64 (rh, &ret->bo.expiration_time.abs_value_us)) || 934 GNUNET_BIO_read_int64 (rh, &ret->bo.expiration_time.abs_value_us)) ||
935 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.anonymity_level)) || 935 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.anonymity_level)) ||
@@ -941,7 +941,7 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h,
941 } 941 }
942 switch (b) 942 switch (b)
943 { 943 {
944 case 0: /* file-insert */ 944 case 0: /* file-insert */
945 if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) 945 if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
946 { 946 {
947 GNUNET_break (0); 947 GNUNET_break (0);
@@ -957,12 +957,13 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h,
957 { 957 {
958 ret->data.file.reader = &GNUNET_FS_data_reader_copy_; 958 ret->data.file.reader = &GNUNET_FS_data_reader_copy_;
959 ret->data.file.reader_cls = 959 ret->data.file.reader_cls =
960 GNUNET_malloc_large (ret->data.file.file_size); 960 GNUNET_malloc_large (ret->data.file.file_size);
961 if (ret->data.file.reader_cls == NULL) 961 if (ret->data.file.reader_cls == NULL)
962 goto cleanup; 962 goto cleanup;
963 if (GNUNET_OK != 963 if (GNUNET_OK != GNUNET_BIO_read (rh,
964 GNUNET_BIO_read (rh, "file-data", ret->data.file.reader_cls, 964 "file-data",
965 ret->data.file.file_size)) 965 ret->data.file.reader_cls,
966 ret->data.file.file_size))
966 { 967 {
967 GNUNET_break (0); 968 GNUNET_break (0);
968 goto cleanup; 969 goto cleanup;
@@ -972,11 +973,11 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h,
972 { 973 {
973 ret->data.file.reader = &GNUNET_FS_data_reader_file_; 974 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
974 ret->data.file.reader_cls = 975 ret->data.file.reader_cls =
975 GNUNET_FS_make_file_reader_context_ (ret->filename); 976 GNUNET_FS_make_file_reader_context_ (ret->filename);
976 } 977 }
977 } 978 }
978 break; 979 break;
979 case 1: /* file-index, no hash */ 980 case 1: /* file-index, no hash */
980 if (NULL == ret->filename) 981 if (NULL == ret->filename)
981 { 982 {
982 GNUNET_break (0); 983 GNUNET_break (0);
@@ -993,18 +994,19 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h,
993 ret->data.file.index_start_confirmed = GNUNET_NO; 994 ret->data.file.index_start_confirmed = GNUNET_NO;
994 ret->data.file.reader = &GNUNET_FS_data_reader_file_; 995 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
995 ret->data.file.reader_cls = 996 ret->data.file.reader_cls =
996 GNUNET_FS_make_file_reader_context_ (ret->filename); 997 GNUNET_FS_make_file_reader_context_ (ret->filename);
997 break; 998 break;
998 case 2: /* file-index-with-hash */ 999 case 2: /* file-index-with-hash */
999 if (NULL == ret->filename) 1000 if (NULL == ret->filename)
1000 { 1001 {
1001 GNUNET_break (0); 1002 GNUNET_break (0);
1002 goto cleanup; 1003 goto cleanup;
1003 } 1004 }
1004 if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) || 1005 if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
1005 (GNUNET_OK != 1006 (GNUNET_OK != GNUNET_BIO_read (rh,
1006 GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id, 1007 "fileid",
1007 sizeof (struct GNUNET_HashCode)))) 1008 &ret->data.file.file_id,
1009 sizeof (struct GNUNET_HashCode))))
1008 { 1010 {
1009 GNUNET_break (0); 1011 GNUNET_break (0);
1010 goto cleanup; 1012 goto cleanup;
@@ -1015,18 +1017,19 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h,
1015 ret->data.file.index_start_confirmed = GNUNET_NO; 1017 ret->data.file.index_start_confirmed = GNUNET_NO;
1016 ret->data.file.reader = &GNUNET_FS_data_reader_file_; 1018 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
1017 ret->data.file.reader_cls = 1019 ret->data.file.reader_cls =
1018 GNUNET_FS_make_file_reader_context_ (ret->filename); 1020 GNUNET_FS_make_file_reader_context_ (ret->filename);
1019 break; 1021 break;
1020 case 3: /* file-index-with-hash-confirmed */ 1022 case 3: /* file-index-with-hash-confirmed */
1021 if (NULL == ret->filename) 1023 if (NULL == ret->filename)
1022 { 1024 {
1023 GNUNET_break (0); 1025 GNUNET_break (0);
1024 goto cleanup; 1026 goto cleanup;
1025 } 1027 }
1026 if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) || 1028 if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
1027 (GNUNET_OK != 1029 (GNUNET_OK != GNUNET_BIO_read (rh,
1028 GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id, 1030 "fileid",
1029 sizeof (struct GNUNET_HashCode)))) 1031 &ret->data.file.file_id,
1032 sizeof (struct GNUNET_HashCode))))
1030 { 1033 {
1031 GNUNET_break (0); 1034 GNUNET_break (0);
1032 goto cleanup; 1035 goto cleanup;
@@ -1037,13 +1040,15 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h,
1037 ret->data.file.index_start_confirmed = GNUNET_YES; 1040 ret->data.file.index_start_confirmed = GNUNET_YES;
1038 ret->data.file.reader = &GNUNET_FS_data_reader_file_; 1041 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
1039 ret->data.file.reader_cls = 1042 ret->data.file.reader_cls =
1040 GNUNET_FS_make_file_reader_context_ (ret->filename); 1043 GNUNET_FS_make_file_reader_context_ (ret->filename);
1041 break; 1044 break;
1042 case 4: /* directory */ 1045 case 4: /* directory */
1043 ret->is_directory = GNUNET_YES; 1046 ret->is_directory = GNUNET_YES;
1044 if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dsize)) || 1047 if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dsize)) ||
1045 (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_completed)) || 1048 (GNUNET_OK !=
1046 (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_size)) || 1049 GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_completed)) ||
1050 (GNUNET_OK !=
1051 GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_size)) ||
1047 (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) || 1052 (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) ||
1048 (GNUNET_OK != 1053 (GNUNET_OK !=
1049 GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) || 1054 GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) ||
@@ -1108,8 +1113,7 @@ cleanup:
1108 * @return NULL on error 1113 * @return NULL on error
1109 */ 1114 */
1110static struct GNUNET_FS_FileInformation * 1115static struct GNUNET_FS_FileInformation *
1111deserialize_file_information (struct GNUNET_FS_Handle *h, 1116deserialize_file_information (struct GNUNET_FS_Handle *h, const char *filename)
1112 const char *filename)
1113{ 1117{
1114 struct GNUNET_FS_FileInformation *ret; 1118 struct GNUNET_FS_FileInformation *ret;
1115 struct GNUNET_BIO_ReadHandle *rh; 1119 struct GNUNET_BIO_ReadHandle *rh;
@@ -1123,17 +1127,19 @@ deserialize_file_information (struct GNUNET_FS_Handle *h,
1123 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) 1127 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
1124 { 1128 {
1125 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1129 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1126 _("Failed to resume publishing information `%s': %s\n"), 1130 _ ("Failed to resume publishing information `%s': %s\n"),
1127 filename, emsg); 1131 filename,
1132 emsg);
1128 GNUNET_free (emsg); 1133 GNUNET_free (emsg);
1129 } 1134 }
1130 if (NULL == ret) 1135 if (NULL == ret)
1131 { 1136 {
1132 fn = get_serialization_file_name (h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename); 1137 fn =
1138 get_serialization_file_name (h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename);
1133 if (NULL != fn) 1139 if (NULL != fn)
1134 { 1140 {
1135 if (0 != UNLINK (fn)) 1141 if (0 != unlink (fn))
1136 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); 1142 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
1137 GNUNET_free (fn); 1143 GNUNET_free (fn);
1138 } 1144 }
1139 } 1145 }
@@ -1184,15 +1190,14 @@ get_serialization_short_name (const char *fullname)
1184 * @return NULL on errror 1190 * @return NULL on errror
1185 */ 1191 */
1186static char * 1192static char *
1187make_serialization_file_name (struct GNUNET_FS_Handle *h, 1193make_serialization_file_name (struct GNUNET_FS_Handle *h, const char *ext)
1188 const char *ext)
1189{ 1194{
1190 char *fn; 1195 char *fn;
1191 char *dn; 1196 char *dn;
1192 char *ret; 1197 char *ret;
1193 1198
1194 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) 1199 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
1195 return NULL; /* persistence not requested */ 1200 return NULL; /* persistence not requested */
1196 dn = get_serialization_file_name (h, ext, ""); 1201 dn = get_serialization_file_name (h, ext, "");
1197 if (NULL == dn) 1202 if (NULL == dn)
1198 return NULL; 1203 return NULL;
@@ -1204,7 +1209,7 @@ make_serialization_file_name (struct GNUNET_FS_Handle *h,
1204 fn = GNUNET_DISK_mktemp (dn); 1209 fn = GNUNET_DISK_mktemp (dn);
1205 GNUNET_free (dn); 1210 GNUNET_free (dn);
1206 if (NULL == fn) 1211 if (NULL == fn)
1207 return NULL; /* epic fail */ 1212 return NULL; /* epic fail */
1208 ret = get_serialization_short_name (fn); 1213 ret = get_serialization_short_name (fn);
1209 GNUNET_free (fn); 1214 GNUNET_free (fn);
1210 return ret; 1215 return ret;
@@ -1230,7 +1235,7 @@ make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h,
1230 char *ret; 1235 char *ret;
1231 1236
1232 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) 1237 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
1233 return NULL; /* persistence not requested */ 1238 return NULL; /* persistence not requested */
1234 dn = get_serialization_file_name_in_dir (h, ext, uni, ""); 1239 dn = get_serialization_file_name_in_dir (h, ext, uni, "");
1235 if (NULL == dn) 1240 if (NULL == dn)
1236 return NULL; 1241 return NULL;
@@ -1242,7 +1247,7 @@ make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h,
1242 fn = GNUNET_DISK_mktemp (dn); 1247 fn = GNUNET_DISK_mktemp (dn);
1243 GNUNET_free (dn); 1248 GNUNET_free (dn);
1244 if (NULL == fn) 1249 if (NULL == fn)
1245 return NULL; /* epic fail */ 1250 return NULL; /* epic fail */
1246 ret = get_serialization_short_name (fn); 1251 ret = get_serialization_short_name (fn);
1247 GNUNET_free (fn); 1252 GNUNET_free (fn);
1248 return ret; 1253 return ret;
@@ -1272,7 +1277,7 @@ copy_from_reader (struct GNUNET_BIO_WriteHandle *wh,
1272 { 1277 {
1273 left = GNUNET_MIN (sizeof (buf), fi->data.file.file_size - off); 1278 left = GNUNET_MIN (sizeof (buf), fi->data.file.file_size - off);
1274 ret = 1279 ret =
1275 fi->data.file.reader (fi->data.file.reader_cls, off, left, buf, &emsg); 1280 fi->data.file.reader (fi->data.file.reader_cls, off, left, buf, &emsg);
1276 if (0 == ret) 1281 if (0 == ret)
1277 { 1282 {
1278 GNUNET_free (emsg); 1283 GNUNET_free (emsg);
@@ -1304,11 +1309,11 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi)
1304 1309
1305 if (NULL == fi->serialization) 1310 if (NULL == fi->serialization)
1306 fi->serialization = 1311 fi->serialization =
1307 make_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO); 1312 make_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO);
1308 if (NULL == fi->serialization) 1313 if (NULL == fi->serialization)
1309 return; 1314 return;
1310 wh = get_write_handle (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, 1315 wh =
1311 fi->serialization); 1316 get_write_handle (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, fi->serialization);
1312 if (NULL == wh) 1317 if (NULL == wh)
1313 { 1318 {
1314 GNUNET_free (fi->serialization); 1319 GNUNET_free (fi->serialization);
@@ -1363,7 +1368,7 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi)
1363 1368
1364 switch (b) 1369 switch (b)
1365 { 1370 {
1366 case 0: /* file-insert */ 1371 case 0: /* file-insert */
1367 if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) 1372 if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size))
1368 { 1373 {
1369 GNUNET_break (0); 1374 GNUNET_break (0);
@@ -1376,7 +1381,7 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi)
1376 goto cleanup; 1381 goto cleanup;
1377 } 1382 }
1378 break; 1383 break;
1379 case 1: /* file-index, no hash */ 1384 case 1: /* file-index, no hash */
1380 if (NULL == fi->filename) 1385 if (NULL == fi->filename)
1381 { 1386 {
1382 GNUNET_break (0); 1387 GNUNET_break (0);
@@ -1388,37 +1393,39 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi)
1388 goto cleanup; 1393 goto cleanup;
1389 } 1394 }
1390 break; 1395 break;
1391 case 2: /* file-index-with-hash */ 1396 case 2: /* file-index-with-hash */
1392 case 3: /* file-index-with-hash-confirmed */ 1397 case 3: /* file-index-with-hash-confirmed */
1393 if (NULL == fi->filename) 1398 if (NULL == fi->filename)
1394 { 1399 {
1395 GNUNET_break (0); 1400 GNUNET_break (0);
1396 goto cleanup; 1401 goto cleanup;
1397 } 1402 }
1398 if ((GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) || 1403 if ((GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) ||
1399 (GNUNET_OK != 1404 (GNUNET_OK != GNUNET_BIO_write (wh,
1400 GNUNET_BIO_write (wh, &fi->data.file.file_id, 1405 &fi->data.file.file_id,
1401 sizeof (struct GNUNET_HashCode)))) 1406 sizeof (struct GNUNET_HashCode))))
1402 { 1407 {
1403 GNUNET_break (0); 1408 GNUNET_break (0);
1404 goto cleanup; 1409 goto cleanup;
1405 } 1410 }
1406 break; 1411 break;
1407 case 4: /* directory */ 1412 case 4: /* directory */
1408 if ( (NULL != fi->data.dir.entries) && 1413 if ((NULL != fi->data.dir.entries) &&
1409 (NULL == fi->data.dir.entries->serialization) ) 1414 (NULL == fi->data.dir.entries->serialization))
1410 GNUNET_FS_file_information_sync_ (fi->data.dir.entries); 1415 GNUNET_FS_file_information_sync_ (fi->data.dir.entries);
1411 if ((GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) || 1416 if ((GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) ||
1412 (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_completed)) ||
1413 (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_size)) ||
1414 (GNUNET_OK != 1417 (GNUNET_OK !=
1415 GNUNET_BIO_write (wh, fi->data.dir.dir_data, 1418 GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_completed)) ||
1416 (uint32_t) fi->data.dir.dir_size)) || 1419 (GNUNET_OK !=
1420 GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_size)) ||
1421 (GNUNET_OK != GNUNET_BIO_write (wh,
1422 fi->data.dir.dir_data,
1423 (uint32_t) fi->data.dir.dir_size)) ||
1417 (GNUNET_OK != 1424 (GNUNET_OK !=
1418 GNUNET_BIO_write_string (wh, 1425 GNUNET_BIO_write_string (wh,
1419 (fi->data.dir.entries == 1426 (fi->data.dir.entries == NULL)
1420 NULL) ? NULL : fi->data.dir. 1427 ? NULL
1421 entries->serialization))) 1428 : fi->data.dir.entries->serialization)))
1422 { 1429 {
1423 GNUNET_break (0); 1430 GNUNET_break (0);
1424 goto cleanup; 1431 goto cleanup;
@@ -1428,13 +1435,12 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi)
1428 GNUNET_assert (0); 1435 GNUNET_assert (0);
1429 goto cleanup; 1436 goto cleanup;
1430 } 1437 }
1431 if ( (NULL != fi->next) && 1438 if ((NULL != fi->next) && (NULL == fi->next->serialization))
1432 (NULL == fi->next->serialization) )
1433 GNUNET_FS_file_information_sync_ (fi->next); 1439 GNUNET_FS_file_information_sync_ (fi->next);
1434 if (GNUNET_OK != 1440 if (GNUNET_OK != GNUNET_BIO_write_string (wh,
1435 GNUNET_BIO_write_string (wh, 1441 (fi->next != NULL)
1436 (fi->next != 1442 ? fi->next->serialization
1437 NULL) ? fi->next->serialization : NULL)) 1443 : NULL))
1438 { 1444 {
1439 GNUNET_break (0); 1445 GNUNET_break (0);
1440 goto cleanup; 1446 goto cleanup;
@@ -1445,18 +1451,19 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi)
1445 GNUNET_break (0); 1451 GNUNET_break (0);
1446 goto cleanup; 1452 goto cleanup;
1447 } 1453 }
1448 return; /* done! */ 1454 return; /* done! */
1449cleanup: 1455cleanup:
1450 if (NULL != wh) 1456 if (NULL != wh)
1451 (void) GNUNET_BIO_write_close (wh); 1457 (void) GNUNET_BIO_write_close (wh);
1452 GNUNET_free_non_null (chks); 1458 GNUNET_free_non_null (chks);
1453 GNUNET_free_non_null (ksks); 1459 GNUNET_free_non_null (ksks);
1454 GNUNET_free_non_null (skss); 1460 GNUNET_free_non_null (skss);
1455 fn = get_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, 1461 fn = get_serialization_file_name (fi->h,
1462 GNUNET_FS_SYNC_PATH_FILE_INFO,
1456 fi->serialization); 1463 fi->serialization);
1457 if (NULL != fn) 1464 if (NULL != fn)
1458 { 1465 {
1459 if (0 != UNLINK (fn)) 1466 if (0 != unlink (fn))
1460 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); 1467 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
1461 GNUNET_free (fn); 1468 GNUNET_free (fn);
1462 } 1469 }
@@ -1465,7 +1472,6 @@ cleanup:
1465} 1472}
1466 1473
1467 1474
1468
1469/** 1475/**
1470 * Find the entry in the file information struct where the 1476 * Find the entry in the file information struct where the
1471 * serialization filename matches the given name. 1477 * serialization filename matches the given name.
@@ -1475,8 +1481,7 @@ cleanup:
1475 * @return NULL if srch was not found in this subtree 1481 * @return NULL if srch was not found in this subtree
1476 */ 1482 */
1477static struct GNUNET_FS_FileInformation * 1483static struct GNUNET_FS_FileInformation *
1478find_file_position (struct GNUNET_FS_FileInformation *pos, 1484find_file_position (struct GNUNET_FS_FileInformation *pos, const char *srch)
1479 const char *srch)
1480{ 1485{
1481 struct GNUNET_FS_FileInformation *r; 1486 struct GNUNET_FS_FileInformation *r;
1482 1487
@@ -1484,8 +1489,8 @@ find_file_position (struct GNUNET_FS_FileInformation *pos,
1484 { 1489 {
1485 if (0 == strcmp (srch, pos->serialization)) 1490 if (0 == strcmp (srch, pos->serialization))
1486 return pos; 1491 return pos;
1487 if ( (GNUNET_YES == pos->is_directory) && 1492 if ((GNUNET_YES == pos->is_directory) &&
1488 (NULL != (r = find_file_position (pos->data.dir.entries, srch))) ) 1493 (NULL != (r = find_file_position (pos->data.dir.entries, srch))))
1489 return r; 1494 return r;
1490 pos = pos->next; 1495 pos = pos->next;
1491 } 1496 }
@@ -1548,8 +1553,7 @@ fip_signal_resume (void *cls,
1548 * @return #GNUNET_OK (continue to iterate) 1553 * @return #GNUNET_OK (continue to iterate)
1549 */ 1554 */
1550static int 1555static int
1551deserialize_publish_file (void *cls, 1556deserialize_publish_file (void *cls, const char *filename)
1552 const char *filename)
1553{ 1557{
1554 struct GNUNET_FS_Handle *h = cls; 1558 struct GNUNET_FS_Handle *h = cls;
1555 struct GNUNET_BIO_ReadHandle *rh; 1559 struct GNUNET_BIO_ReadHandle *rh;
@@ -1573,17 +1577,19 @@ deserialize_publish_file (void *cls,
1573 GNUNET_break (0); 1577 GNUNET_break (0);
1574 goto cleanup; 1578 goto cleanup;
1575 } 1579 }
1576 if ((GNUNET_OK != GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) 1580 if ((GNUNET_OK !=
1577 || (GNUNET_OK != 1581 GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) ||
1578 GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) || 1582 (GNUNET_OK !=
1583 GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) ||
1579 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) || 1584 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) ||
1580 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &all_done)) || 1585 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &all_done)) ||
1581 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &have_ns)) || 1586 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &have_ns)) ||
1582 (GNUNET_OK != 1587 (GNUNET_OK !=
1583 GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) || 1588 GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) ||
1584 (GNUNET_OK != GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) 1589 (GNUNET_OK !=
1585 || ( (GNUNET_YES == have_ns) && 1590 GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) ||
1586 (GNUNET_OK != GNUNET_BIO_read (rh, "publish-ns", &ns, sizeof (ns)))) ) 1591 ((GNUNET_YES == have_ns) &&
1592 (GNUNET_OK != GNUNET_BIO_read (rh, "publish-ns", &ns, sizeof (ns)))))
1587 { 1593 {
1588 GNUNET_break (0); 1594 GNUNET_break (0);
1589 goto cleanup; 1595 goto cleanup;
@@ -1636,20 +1642,19 @@ deserialize_publish_file (void *cls,
1636 { 1642 {
1637 GNUNET_assert (NULL == pc->upload_task); 1643 GNUNET_assert (NULL == pc->upload_task);
1638 pc->upload_task = 1644 pc->upload_task =
1639 GNUNET_SCHEDULER_add_with_priority 1645 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
1640 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, 1646 &GNUNET_FS_publish_main_,
1641 &GNUNET_FS_publish_main_, pc); 1647 pc);
1642 } 1648 }
1643 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) 1649 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
1644 { 1650 {
1645 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1651 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1646 _("Failure while resuming publishing operation `%s': %s\n"), 1652 _ ("Failure while resuming publishing operation `%s': %s\n"),
1647 filename, emsg); 1653 filename,
1654 emsg);
1648 GNUNET_free (emsg); 1655 GNUNET_free (emsg);
1649 } 1656 }
1650 pc->top = GNUNET_FS_make_top (h, 1657 pc->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, pc);
1651 &GNUNET_FS_publish_signal_suspend_,
1652 pc);
1653 return GNUNET_OK; 1658 return GNUNET_OK;
1654cleanup: 1659cleanup:
1655 GNUNET_free_non_null (pc->nid); 1660 GNUNET_free_non_null (pc->nid);
@@ -1659,13 +1664,14 @@ cleanup:
1659 if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))) 1664 if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)))
1660 { 1665 {
1661 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1666 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1662 _("Failed to resume publishing operation `%s': %s\n"), filename, 1667 _ ("Failed to resume publishing operation `%s': %s\n"),
1668 filename,
1663 emsg); 1669 emsg);
1664 GNUNET_free (emsg); 1670 GNUNET_free (emsg);
1665 } 1671 }
1666 if (NULL != pc->fi) 1672 if (NULL != pc->fi)
1667 GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL); 1673 GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL);
1668 if (0 != UNLINK (filename)) 1674 if (0 != unlink (filename))
1669 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); 1675 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
1670 GNUNET_free (pc->serialization); 1676 GNUNET_free (pc->serialization);
1671 GNUNET_free (pc); 1677 GNUNET_free (pc);
@@ -1689,8 +1695,7 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc)
1689 1695
1690 if (NULL == pc->serialization) 1696 if (NULL == pc->serialization)
1691 pc->serialization = 1697 pc->serialization =
1692 make_serialization_file_name (pc->h, 1698 make_serialization_file_name (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH);
1693 GNUNET_FS_SYNC_PATH_MASTER_PUBLISH);
1694 if (NULL == pc->serialization) 1699 if (NULL == pc->serialization)
1695 return; 1700 return;
1696 if (NULL == pc->fi) 1701 if (NULL == pc->fi)
@@ -1700,7 +1705,8 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc)
1700 GNUNET_break (0); 1705 GNUNET_break (0);
1701 return; 1706 return;
1702 } 1707 }
1703 wh = get_write_handle (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, 1708 wh = get_write_handle (pc->h,
1709 GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
1704 pc->serialization); 1710 pc->serialization);
1705 if (NULL == wh) 1711 if (NULL == wh)
1706 { 1712 {
@@ -1714,13 +1720,15 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc)
1714 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pc->all_done)) || 1720 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pc->all_done)) ||
1715 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, have_ns)) || 1721 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, have_ns)) ||
1716 (GNUNET_OK != GNUNET_BIO_write_string (wh, pc->fi->serialization)) || 1722 (GNUNET_OK != GNUNET_BIO_write_string (wh, pc->fi->serialization)) ||
1717 (GNUNET_OK != 1723 (GNUNET_OK != GNUNET_BIO_write_string (wh,
1718 GNUNET_BIO_write_string (wh, 1724 (NULL == pc->fi_pos)
1719 (NULL == pc->fi_pos) ? NULL : pc->fi_pos->serialization)) || 1725 ? NULL
1720 ( (NULL != pc->ns) && 1726 : pc->fi_pos->serialization)) ||
1721 (GNUNET_OK != GNUNET_BIO_write (wh, 1727 ((NULL != pc->ns) &&
1722 pc->ns, 1728 (GNUNET_OK !=
1723 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)) ) )) 1729 GNUNET_BIO_write (wh,
1730 pc->ns,
1731 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))))
1724 { 1732 {
1725 GNUNET_break (0); 1733 GNUNET_break (0);
1726 goto cleanup; 1734 goto cleanup;
@@ -1735,7 +1743,8 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc)
1735cleanup: 1743cleanup:
1736 if (NULL != wh) 1744 if (NULL != wh)
1737 (void) GNUNET_BIO_write_close (wh); 1745 (void) GNUNET_BIO_write_close (wh);
1738 GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, 1746 GNUNET_FS_remove_sync_file_ (pc->h,
1747 GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
1739 pc->serialization); 1748 pc->serialization);
1740 GNUNET_free (pc->serialization); 1749 GNUNET_free (pc->serialization);
1741 pc->serialization = NULL; 1750 pc->serialization = NULL;
@@ -1758,11 +1767,11 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc)
1758 1767
1759 if (NULL == uc->serialization) 1768 if (NULL == uc->serialization)
1760 uc->serialization = 1769 uc->serialization =
1761 make_serialization_file_name (uc->h, 1770 make_serialization_file_name (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX);
1762 GNUNET_FS_SYNC_PATH_MASTER_UNINDEX);
1763 if (NULL == uc->serialization) 1771 if (NULL == uc->serialization)
1764 return; 1772 return;
1765 wh = get_write_handle (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, 1773 wh = get_write_handle (uc->h,
1774 GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
1766 uc->serialization); 1775 uc->serialization);
1767 if (NULL == wh) 1776 if (NULL == wh)
1768 { 1777 {
@@ -1782,8 +1791,9 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc)
1782 (GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || 1791 (GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) ||
1783 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) uc->ksk_offset)) || 1792 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) uc->ksk_offset)) ||
1784 ((uc->state == UNINDEX_STATE_FS_NOTIFY) && 1793 ((uc->state == UNINDEX_STATE_FS_NOTIFY) &&
1785 (GNUNET_OK != 1794 (GNUNET_OK != GNUNET_BIO_write (wh,
1786 GNUNET_BIO_write (wh, &uc->file_id, sizeof (struct GNUNET_HashCode)))) || 1795 &uc->file_id,
1796 sizeof (struct GNUNET_HashCode)))) ||
1787 ((uc->state == UNINDEX_STATE_ERROR) && 1797 ((uc->state == UNINDEX_STATE_ERROR) &&
1788 (GNUNET_OK != GNUNET_BIO_write_string (wh, uc->emsg)))) 1798 (GNUNET_OK != GNUNET_BIO_write_string (wh, uc->emsg))))
1789 { 1799 {
@@ -1800,7 +1810,8 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc)
1800cleanup: 1810cleanup:
1801 if (NULL != wh) 1811 if (NULL != wh)
1802 (void) GNUNET_BIO_write_close (wh); 1812 (void) GNUNET_BIO_write_close (wh);
1803 GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, 1813 GNUNET_FS_remove_sync_file_ (uc->h,
1814 GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
1804 uc->serialization); 1815 uc->serialization);
1805 GNUNET_free (uc->serialization); 1816 GNUNET_free (uc->serialization);
1806 uc->serialization = NULL; 1817 uc->serialization = NULL;
@@ -1854,8 +1865,7 @@ read_download_request (struct GNUNET_BIO_ReadHandle *rh)
1854 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->num_children)) || 1865 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->num_children)) ||
1855 (dr->num_children > CHK_PER_INODE) || 1866 (dr->num_children > CHK_PER_INODE) ||
1856 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->depth)) || 1867 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->depth)) ||
1857 ( (0 == dr->depth) && 1868 ((0 == dr->depth) && (dr->num_children > 0)) ||
1858 (dr->num_children > 0) ) ||
1859 ((dr->depth > 0) && (0 == dr->num_children))) 1869 ((dr->depth > 0) && (0 == dr->num_children)))
1860 { 1870 {
1861 GNUNET_break (0); 1871 GNUNET_break (0);
@@ -1864,7 +1874,7 @@ read_download_request (struct GNUNET_BIO_ReadHandle *rh)
1864 } 1874 }
1865 if (dr->num_children > 0) 1875 if (dr->num_children > 0)
1866 dr->children = 1876 dr->children =
1867 GNUNET_malloc (dr->num_children * sizeof (struct DownloadRequest *)); 1877 GNUNET_malloc (dr->num_children * sizeof (struct DownloadRequest *));
1868 switch (dr->state) 1878 switch (dr->state)
1869 { 1879 {
1870 case BRS_INIT: 1880 case BRS_INIT:
@@ -1917,9 +1927,9 @@ get_download_sync_filename (struct GNUNET_FS_DownloadContext *dc,
1917 1927
1918 if (dc->parent == NULL) 1928 if (dc->parent == NULL)
1919 return get_serialization_file_name (dc->h, 1929 return get_serialization_file_name (dc->h,
1920 (dc->search != NULL) ? 1930 (dc->search != NULL)
1921 GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD : 1931 ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD
1922 GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, 1932 : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
1923 uni); 1933 uni);
1924 if (NULL == dc->parent->serialization) 1934 if (NULL == dc->parent->serialization)
1925 return NULL; 1935 return NULL;
@@ -2028,7 +2038,7 @@ cleanup:
2028 if (NULL != wh) 2038 if (NULL != wh)
2029 (void) GNUNET_BIO_write_close (wh); 2039 (void) GNUNET_BIO_write_close (wh);
2030 GNUNET_free_non_null (uris); 2040 GNUNET_free_non_null (uris);
2031 if (0 != UNLINK (fn)) 2041 if (0 != unlink (fn))
2032 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); 2042 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
2033 GNUNET_free (fn); 2043 GNUNET_free (fn);
2034 GNUNET_free (dc->serialization); 2044 GNUNET_free (dc->serialization);
@@ -2055,19 +2065,19 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr)
2055 uris = NULL; 2065 uris = NULL;
2056 if (NULL == sr->serialization) 2066 if (NULL == sr->serialization)
2057 sr->serialization = 2067 sr->serialization =
2058 make_serialization_file_name_in_dir (sr->h, 2068 make_serialization_file_name_in_dir (sr->h,
2059 (sr->sc->psearch_result == 2069 (sr->sc->psearch_result == NULL)
2060 NULL) ? 2070 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2061 GNUNET_FS_SYNC_PATH_MASTER_SEARCH : 2071 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2062 GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 2072 sr->sc->serialization);
2063 sr->sc->serialization);
2064 if (NULL == sr->serialization) 2073 if (NULL == sr->serialization)
2065 return; 2074 return;
2066 wh = get_write_handle_in_dir (sr->h, 2075 wh = get_write_handle_in_dir (sr->h,
2067 (sr->sc->psearch_result == 2076 (sr->sc->psearch_result == NULL)
2068 NULL) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH : 2077 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2069 GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 2078 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2070 sr->sc->serialization, sr->serialization); 2079 sr->sc->serialization,
2080 sr->serialization);
2071 if (NULL == wh) 2081 if (NULL == wh)
2072 { 2082 {
2073 GNUNET_break (0); 2083 GNUNET_break (0);
@@ -2075,28 +2085,31 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr)
2075 } 2085 }
2076 uris = GNUNET_FS_uri_to_string (sr->uri); 2086 uris = GNUNET_FS_uri_to_string (sr->uri);
2077 if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || 2087 if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) ||
2088 (GNUNET_OK != GNUNET_BIO_write_string (wh,
2089 sr->download != NULL
2090 ? sr->download->serialization
2091 : NULL)) ||
2078 (GNUNET_OK != 2092 (GNUNET_OK !=
2079 GNUNET_BIO_write_string (wh, 2093 GNUNET_BIO_write_string (wh,
2080 sr->download != 2094 sr->update_search != NULL
2081 NULL ? sr->download->serialization : NULL)) || 2095 ? sr->update_search->serialization
2096 : NULL)) ||
2097 (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, sr->meta)) ||
2082 (GNUNET_OK != 2098 (GNUNET_OK !=
2083 GNUNET_BIO_write_string (wh, 2099 GNUNET_BIO_write (wh, &sr->key, sizeof (struct GNUNET_HashCode))) ||
2084 sr->update_search != 2100 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->mandatory_missing)) ||
2085 NULL ? sr->update_search->serialization : NULL))
2086 || (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, sr->meta)) ||
2087 (GNUNET_OK != GNUNET_BIO_write (wh, &sr->key, sizeof (struct GNUNET_HashCode)))
2088 || (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->mandatory_missing)) ||
2089 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->optional_support)) || 2101 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->optional_support)) ||
2090 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_success)) || 2102 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_success)) ||
2091 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_trials)) ) 2103 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_trials)))
2092 { 2104 {
2093 GNUNET_break (0); 2105 GNUNET_break (0);
2094 goto cleanup; 2106 goto cleanup;
2095 } 2107 }
2096 if ( (NULL != sr->uri) && 2108 if ((NULL != sr->uri) && (GNUNET_FS_URI_KSK == sr->sc->uri->type) &&
2097 (GNUNET_FS_URI_KSK == sr->sc->uri->type) && 2109 (GNUNET_OK !=
2098 (GNUNET_OK != GNUNET_BIO_write (wh, sr->keyword_bitmap, 2110 GNUNET_BIO_write (wh,
2099 (sr->sc->uri->data.ksk.keywordCount + 7) / 8)) ) 2111 sr->keyword_bitmap,
2112 (sr->sc->uri->data.ksk.keywordCount + 7) / 8)))
2100 { 2113 {
2101 GNUNET_break (0); 2114 GNUNET_break (0);
2102 goto cleanup; 2115 goto cleanup;
@@ -2115,9 +2128,10 @@ cleanup:
2115 (void) GNUNET_BIO_write_close (wh); 2128 (void) GNUNET_BIO_write_close (wh);
2116 remove_sync_file_in_dir (sr->h, 2129 remove_sync_file_in_dir (sr->h,
2117 (NULL == sr->sc->psearch_result) 2130 (NULL == sr->sc->psearch_result)
2118 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH 2131 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2119 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 2132 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2120 sr->sc->serialization, sr->serialization); 2133 sr->sc->serialization,
2134 sr->serialization);
2121 GNUNET_free (sr->serialization); 2135 GNUNET_free (sr->serialization);
2122 sr->serialization = NULL; 2136 sr->serialization = NULL;
2123} 2137}
@@ -2139,10 +2153,8 @@ GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc)
2139 char in_pause; 2153 char in_pause;
2140 const char *category; 2154 const char *category;
2141 2155
2142 category = 2156 category = (NULL == sc->psearch_result) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2143 (NULL == sc->psearch_result) 2157 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH;
2144 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2145 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH;
2146 if (NULL == sc->serialization) 2158 if (NULL == sc->serialization)
2147 sc->serialization = make_serialization_file_name (sc->h, category); 2159 sc->serialization = make_serialization_file_name (sc->h, category);
2148 if (NULL == sc->serialization) 2160 if (NULL == sc->serialization)
@@ -2196,8 +2208,7 @@ cleanup:
2196 * @return #GNUNET_OK (continue to iterate) 2208 * @return #GNUNET_OK (continue to iterate)
2197 */ 2209 */
2198static int 2210static int
2199deserialize_unindex_file (void *cls, 2211deserialize_unindex_file (void *cls, const char *filename)
2200 const char *filename)
2201{ 2212{
2202 struct GNUNET_FS_Handle *h = cls; 2213 struct GNUNET_FS_Handle *h = cls;
2203 struct GNUNET_BIO_ReadHandle *rh; 2214 struct GNUNET_BIO_ReadHandle *rh;
@@ -2222,9 +2233,11 @@ deserialize_unindex_file (void *cls,
2222 (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &uc->file_size)) || 2233 (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &uc->file_size)) ||
2223 (GNUNET_OK != read_start_time (rh, &uc->start_time)) || 2234 (GNUNET_OK != read_start_time (rh, &uc->start_time)) ||
2224 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &state)) || 2235 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &state)) ||
2225 (GNUNET_OK != GNUNET_BIO_read (rh, "uri", &uc->chk, sizeof (struct ContentHashKey))) || 2236 (GNUNET_OK !=
2226 (GNUNET_OK != GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 1024)) || 2237 GNUNET_BIO_read (rh, "uri", &uc->chk, sizeof (struct ContentHashKey))) ||
2227 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &uc->ksk_offset)) ) 2238 (GNUNET_OK !=
2239 GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 1024)) ||
2240 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &uc->ksk_offset)))
2228 { 2241 {
2229 GNUNET_free_non_null (uris); 2242 GNUNET_free_non_null (uris);
2230 GNUNET_break (0); 2243 GNUNET_break (0);
@@ -2241,9 +2254,9 @@ deserialize_unindex_file (void *cls,
2241 goto cleanup; 2254 goto cleanup;
2242 } 2255 }
2243 } 2256 }
2244 if ( (uc->ksk_offset > 0) && 2257 if ((uc->ksk_offset > 0) &&
2245 ( (NULL == uc->ksk_uri) || 2258 ((NULL == uc->ksk_uri) ||
2246 (uc->ksk_offset > uc->ksk_uri->data.ksk.keywordCount) ) ) 2259 (uc->ksk_offset > uc->ksk_uri->data.ksk.keywordCount)))
2247 { 2260 {
2248 GNUNET_break (0); 2261 GNUNET_break (0);
2249 goto cleanup; 2262 goto cleanup;
@@ -2254,9 +2267,10 @@ deserialize_unindex_file (void *cls,
2254 case UNINDEX_STATE_HASHING: 2267 case UNINDEX_STATE_HASHING:
2255 break; 2268 break;
2256 case UNINDEX_STATE_FS_NOTIFY: 2269 case UNINDEX_STATE_FS_NOTIFY:
2257 if (GNUNET_OK != 2270 if (GNUNET_OK != GNUNET_BIO_read (rh,
2258 GNUNET_BIO_read (rh, "unindex-hash", &uc->file_id, 2271 "unindex-hash",
2259 sizeof (struct GNUNET_HashCode))) 2272 &uc->file_id,
2273 sizeof (struct GNUNET_HashCode)))
2260 { 2274 {
2261 GNUNET_break (0); 2275 GNUNET_break (0);
2262 goto cleanup; 2276 goto cleanup;
@@ -2280,21 +2294,22 @@ deserialize_unindex_file (void *cls,
2280 GNUNET_break (0); 2294 GNUNET_break (0);
2281 goto cleanup; 2295 goto cleanup;
2282 } 2296 }
2283 uc->top = GNUNET_FS_make_top (h, 2297 uc->top = GNUNET_FS_make_top (h, &GNUNET_FS_unindex_signal_suspend_, uc);
2284 &GNUNET_FS_unindex_signal_suspend_,
2285 uc);
2286 pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME; 2298 pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME;
2287 pi.value.unindex.specifics.resume.message = uc->emsg; 2299 pi.value.unindex.specifics.resume.message = uc->emsg;
2288 GNUNET_FS_unindex_make_status_ (&pi, uc, 2300 GNUNET_FS_unindex_make_status_ (&pi,
2289 (uc->state == 2301 uc,
2290 UNINDEX_STATE_COMPLETE) ? uc->file_size : 0); 2302 (uc->state == UNINDEX_STATE_COMPLETE)
2303 ? uc->file_size
2304 : 0);
2291 switch (uc->state) 2305 switch (uc->state)
2292 { 2306 {
2293 case UNINDEX_STATE_HASHING: 2307 case UNINDEX_STATE_HASHING:
2294 uc->fhc = 2308 uc->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE,
2295 GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, uc->filename, 2309 uc->filename,
2296 HASHING_BLOCKSIZE, 2310 HASHING_BLOCKSIZE,
2297 &GNUNET_FS_unindex_process_hash_, uc); 2311 &GNUNET_FS_unindex_process_hash_,
2312 uc);
2298 break; 2313 break;
2299 case UNINDEX_STATE_FS_NOTIFY: 2314 case UNINDEX_STATE_FS_NOTIFY:
2300 uc->state = UNINDEX_STATE_HASHING; 2315 uc->state = UNINDEX_STATE_HASHING;
@@ -2319,8 +2334,9 @@ deserialize_unindex_file (void *cls,
2319 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) 2334 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2320 { 2335 {
2321 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2336 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2322 _("Failure while resuming unindexing operation `%s': %s\n"), 2337 _ ("Failure while resuming unindexing operation `%s': %s\n"),
2323 filename, emsg); 2338 filename,
2339 emsg);
2324 GNUNET_free (emsg); 2340 GNUNET_free (emsg);
2325 } 2341 }
2326 return GNUNET_OK; 2342 return GNUNET_OK;
@@ -2329,13 +2345,14 @@ cleanup:
2329 if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))) 2345 if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)))
2330 { 2346 {
2331 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2347 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2332 _("Failed to resume unindexing operation `%s': %s\n"), 2348 _ ("Failed to resume unindexing operation `%s': %s\n"),
2333 filename, 2349 filename,
2334 emsg); 2350 emsg);
2335 GNUNET_free (emsg); 2351 GNUNET_free (emsg);
2336 } 2352 }
2337 if (NULL != uc->serialization) 2353 if (NULL != uc->serialization)
2338 GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, 2354 GNUNET_FS_remove_sync_file_ (h,
2355 GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
2339 uc->serialization); 2356 uc->serialization);
2340 GNUNET_free_non_null (uc->serialization); 2357 GNUNET_free_non_null (uc->serialization);
2341 GNUNET_free (uc); 2358 GNUNET_free (uc);
@@ -2384,8 +2401,7 @@ deserialize_search (struct GNUNET_FS_Handle *h,
2384 * @return #GNUNET_OK (continue to iterate) 2401 * @return #GNUNET_OK (continue to iterate)
2385 */ 2402 */
2386static int 2403static int
2387deserialize_search_result (void *cls, 2404deserialize_search_result (void *cls, const char *filename)
2388 const char *filename)
2389{ 2405{
2390 struct GNUNET_FS_SearchContext *sc = cls; 2406 struct GNUNET_FS_SearchContext *sc = cls;
2391 char *ser; 2407 char *ser;
@@ -2405,9 +2421,10 @@ deserialize_search_result (void *cls,
2405 { 2421 {
2406 remove_sync_file_in_dir (sc->h, 2422 remove_sync_file_in_dir (sc->h,
2407 (NULL == sc->psearch_result) 2423 (NULL == sc->psearch_result)
2408 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH 2424 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2409 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 2425 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2410 sc->serialization, ser); 2426 sc->serialization,
2427 ser);
2411 GNUNET_free (ser); 2428 GNUNET_free (ser);
2412 } 2429 }
2413 return GNUNET_OK; 2430 return GNUNET_OK;
@@ -2420,15 +2437,19 @@ deserialize_search_result (void *cls,
2420 sr->h = sc->h; 2437 sr->h = sc->h;
2421 sr->sc = sc; 2438 sr->sc = sc;
2422 sr->serialization = ser; 2439 sr->serialization = ser;
2423 if ((GNUNET_OK != GNUNET_BIO_read_string (rh, "result-uri", &uris, 10 * 1024)) 2440 if ((GNUNET_OK !=
2424 || (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) || 2441 GNUNET_BIO_read_string (rh, "result-uri", &uris, 10 * 1024)) ||
2425 (GNUNET_OK != GNUNET_BIO_read_string (rh, "download-lnk", &download, 16)) 2442 (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2426 || (GNUNET_OK !=
2427 GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) ||
2428 (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "result-meta", &sr->meta)) ||
2429 (GNUNET_OK != 2443 (GNUNET_OK !=
2430 GNUNET_BIO_read (rh, "result-key", &sr->key, sizeof (struct GNUNET_HashCode))) 2444 GNUNET_BIO_read_string (rh, "download-lnk", &download, 16)) ||
2431 || (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) || 2445 (GNUNET_OK !=
2446 GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) ||
2447 (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "result-meta", &sr->meta)) ||
2448 (GNUNET_OK != GNUNET_BIO_read (rh,
2449 "result-key",
2450 &sr->key,
2451 sizeof (struct GNUNET_HashCode))) ||
2452 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) ||
2432 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->optional_support)) || 2453 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->optional_support)) ||
2433 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_success)) || 2454 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_success)) ||
2434 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_trials))) 2455 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_trials)))
@@ -2438,10 +2459,13 @@ deserialize_search_result (void *cls,
2438 } 2459 }
2439 if (GNUNET_FS_URI_KSK == sr->sc->uri->type) 2460 if (GNUNET_FS_URI_KSK == sr->sc->uri->type)
2440 { 2461 {
2441 sr->keyword_bitmap = GNUNET_malloc ((sr->sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */ 2462 sr->keyword_bitmap = GNUNET_malloc (
2442 if (GNUNET_OK != GNUNET_BIO_read (rh, "keyword-bitmap", 2463 (sr->sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */
2443 sr->keyword_bitmap, 2464 if (GNUNET_OK !=
2444 (sr->sc->uri->data.ksk.keywordCount + 7) / 8)) 2465 GNUNET_BIO_read (rh,
2466 "keyword-bitmap",
2467 sr->keyword_bitmap,
2468 (sr->sc->uri->data.ksk.keywordCount + 7) / 8))
2445 { 2469 {
2446 GNUNET_break (0); 2470 GNUNET_break (0);
2447 goto cleanup; 2471 goto cleanup;
@@ -2457,7 +2481,7 @@ deserialize_search_result (void *cls,
2457 if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg)) 2481 if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg))
2458 { 2482 {
2459 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2483 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2460 _("Failed to resume sub-download `%s': %s\n"), 2484 _ ("Failed to resume sub-download `%s': %s\n"),
2461 download, 2485 download,
2462 emsg); 2486 emsg);
2463 GNUNET_free (emsg); 2487 GNUNET_free (emsg);
@@ -2468,14 +2492,14 @@ deserialize_search_result (void *cls,
2468 if (NULL != update_srch) 2492 if (NULL != update_srch)
2469 { 2493 {
2470 drh = 2494 drh =
2471 get_read_handle (sc->h, GNUNET_FS_SYNC_PATH_CHILD_SEARCH, update_srch); 2495 get_read_handle (sc->h, GNUNET_FS_SYNC_PATH_CHILD_SEARCH, update_srch);
2472 if (NULL != drh) 2496 if (NULL != drh)
2473 { 2497 {
2474 deserialize_search (sc->h, drh, sr, update_srch); 2498 deserialize_search (sc->h, drh, sr, update_srch);
2475 if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg)) 2499 if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg))
2476 { 2500 {
2477 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2501 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2478 _("Failed to resume sub-search `%s': %s\n"), 2502 _ ("Failed to resume sub-search `%s': %s\n"),
2479 update_srch, 2503 update_srch,
2480 emsg); 2504 emsg);
2481 GNUNET_free (emsg); 2505 GNUNET_free (emsg);
@@ -2483,15 +2507,17 @@ deserialize_search_result (void *cls,
2483 } 2507 }
2484 GNUNET_free (update_srch); 2508 GNUNET_free (update_srch);
2485 } 2509 }
2486 GNUNET_break (GNUNET_YES == 2510 GNUNET_break (GNUNET_YES == GNUNET_CONTAINER_multihashmap_put (
2487 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, 2511 sc->master_result_map,
2488 &sr->key, sr, 2512 &sr->key,
2489 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 2513 sr,
2514 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
2490 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) 2515 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2491 { 2516 {
2492 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2517 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2493 _("Failure while resuming search operation `%s': %s\n"), 2518 _ ("Failure while resuming search operation `%s': %s\n"),
2494 filename, emsg); 2519 filename,
2520 emsg);
2495 GNUNET_free (emsg); 2521 GNUNET_free (emsg);
2496 } 2522 }
2497 return GNUNET_OK; 2523 return GNUNET_OK;
@@ -2509,8 +2535,9 @@ cleanup:
2509 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) 2535 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2510 { 2536 {
2511 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2537 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2512 _("Failure while resuming search operation `%s': %s\n"), 2538 _ ("Failure while resuming search operation `%s': %s\n"),
2513 filename, emsg); 2539 filename,
2540 emsg);
2514 GNUNET_free (emsg); 2541 GNUNET_free (emsg);
2515 } 2542 }
2516 return GNUNET_OK; 2543 return GNUNET_OK;
@@ -2564,9 +2591,7 @@ signal_search_resume (struct GNUNET_FS_SearchContext *sc);
2564 * @return #GNUNET_YES (we should continue to iterate) 2591 * @return #GNUNET_YES (we should continue to iterate)
2565 */ 2592 */
2566static int 2593static int
2567signal_result_resume (void *cls, 2594signal_result_resume (void *cls, const struct GNUNET_HashCode *key, void *value)
2568 const struct GNUNET_HashCode *key,
2569 void *value)
2570{ 2595{
2571 struct GNUNET_FS_SearchContext *sc = cls; 2596 struct GNUNET_FS_SearchContext *sc = cls;
2572 struct GNUNET_FS_ProgressInfo pi; 2597 struct GNUNET_FS_ProgressInfo pi;
@@ -2579,11 +2604,11 @@ signal_result_resume (void *cls,
2579 pi.value.search.specifics.resume_result.uri = sr->uri; 2604 pi.value.search.specifics.resume_result.uri = sr->uri;
2580 pi.value.search.specifics.resume_result.result = sr; 2605 pi.value.search.specifics.resume_result.result = sr;
2581 pi.value.search.specifics.resume_result.availability_rank = 2606 pi.value.search.specifics.resume_result.availability_rank =
2582 2 * sr->availability_success - sr->availability_trials; 2607 2 * sr->availability_success - sr->availability_trials;
2583 pi.value.search.specifics.resume_result.availability_certainty = 2608 pi.value.search.specifics.resume_result.availability_certainty =
2584 sr->availability_trials; 2609 sr->availability_trials;
2585 pi.value.search.specifics.resume_result.applicability_rank = 2610 pi.value.search.specifics.resume_result.applicability_rank =
2586 sr->optional_support; 2611 sr->optional_support;
2587 sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); 2612 sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc);
2588 } 2613 }
2589 if (NULL != sr->download) 2614 if (NULL != sr->download)
@@ -2618,9 +2643,7 @@ free_search_context (struct GNUNET_FS_SearchContext *sc);
2618 * @return #GNUNET_YES (we should continue to iterate) 2643 * @return #GNUNET_YES (we should continue to iterate)
2619 */ 2644 */
2620static int 2645static int
2621free_result (void *cls, 2646free_result (void *cls, const struct GNUNET_HashCode *key, void *value)
2622 const struct GNUNET_HashCode *key,
2623 void *value)
2624{ 2647{
2625 struct GNUNET_FS_SearchResult *sr = value; 2648 struct GNUNET_FS_SearchResult *sr = value;
2626 2649
@@ -2647,14 +2670,14 @@ free_search_context (struct GNUNET_FS_SearchContext *sc)
2647 if (NULL != sc->serialization) 2670 if (NULL != sc->serialization)
2648 { 2671 {
2649 GNUNET_FS_remove_sync_file_ (sc->h, 2672 GNUNET_FS_remove_sync_file_ (sc->h,
2650 (sc->psearch_result == 2673 (sc->psearch_result == NULL)
2651 NULL) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH : 2674 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2652 GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 2675 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2653 sc->serialization); 2676 sc->serialization);
2654 GNUNET_FS_remove_sync_dir_ (sc->h, 2677 GNUNET_FS_remove_sync_dir_ (sc->h,
2655 (sc->psearch_result == 2678 (sc->psearch_result == NULL)
2656 NULL) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH : 2679 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2657 GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 2680 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2658 sc->serialization); 2681 sc->serialization);
2659 } 2682 }
2660 GNUNET_free_non_null (sc->serialization); 2683 GNUNET_free_non_null (sc->serialization);
@@ -2663,7 +2686,8 @@ free_search_context (struct GNUNET_FS_SearchContext *sc)
2663 GNUNET_FS_uri_destroy (sc->uri); 2686 GNUNET_FS_uri_destroy (sc->uri);
2664 if (NULL != sc->master_result_map) 2687 if (NULL != sc->master_result_map)
2665 { 2688 {
2666 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, &free_result, 2689 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
2690 &free_result,
2667 sc); 2691 sc);
2668 GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); 2692 GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
2669 } 2693 }
@@ -2680,8 +2704,7 @@ free_search_context (struct GNUNET_FS_SearchContext *sc)
2680 * @return #GNUNET_OK (continue to iterate) 2704 * @return #GNUNET_OK (continue to iterate)
2681 */ 2705 */
2682static int 2706static int
2683deserialize_subdownload (void *cls, 2707deserialize_subdownload (void *cls, const char *filename)
2684 const char *filename)
2685{ 2708{
2686 struct GNUNET_FS_DownloadContext *parent = cls; 2709 struct GNUNET_FS_DownloadContext *parent = cls;
2687 char *ser; 2710 char *ser;
@@ -2693,7 +2716,8 @@ deserialize_subdownload (void *cls,
2693 if (NULL == rh) 2716 if (NULL == rh)
2694 { 2717 {
2695 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2718 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2696 _("Failed to resume sub-download `%s': could not open file `%s'\n"), 2719 _ (
2720 "Failed to resume sub-download `%s': could not open file `%s'\n"),
2697 ser, 2721 ser,
2698 filename); 2722 filename);
2699 GNUNET_free (ser); 2723 GNUNET_free (ser);
@@ -2703,7 +2727,7 @@ deserialize_subdownload (void *cls,
2703 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) 2727 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2704 { 2728 {
2705 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2729 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2706 _("Failed to resume sub-download `%s': %s\n"), 2730 _ ("Failed to resume sub-download `%s': %s\n"),
2707 ser, 2731 ser,
2708 emsg); 2732 emsg);
2709 GNUNET_free (emsg); 2733 GNUNET_free (emsg);
@@ -2735,9 +2759,7 @@ free_download_context (struct GNUNET_FS_DownloadContext *dc)
2735 GNUNET_free_non_null (dc->serialization); 2759 GNUNET_free_non_null (dc->serialization);
2736 while (NULL != (dcc = dc->child_head)) 2760 while (NULL != (dcc = dc->child_head))
2737 { 2761 {
2738 GNUNET_CONTAINER_DLL_remove (dc->child_head, 2762 GNUNET_CONTAINER_DLL_remove (dc->child_head, dc->child_tail, dcc);
2739 dc->child_tail,
2740 dcc);
2741 free_download_context (dcc); 2763 free_download_context (dcc);
2742 } 2764 }
2743 GNUNET_FS_free_download_request_ (dc->top_request); 2765 GNUNET_FS_free_download_request_ (dc->top_request);
@@ -2781,14 +2803,16 @@ deserialize_download (struct GNUNET_FS_Handle *h,
2781 (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) || 2803 (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2782 ((GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) && 2804 ((GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) &&
2783 (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri))) || 2805 (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri))) ||
2784 (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta))
2785 || (GNUNET_OK !=
2786 GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10 * 1024)) ||
2787 (GNUNET_OK != 2806 (GNUNET_OK !=
2788 GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10 * 1024)) || 2807 GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta)) ||
2808 (GNUNET_OK !=
2809 GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10 * 1024)) ||
2789 (GNUNET_OK != 2810 (GNUNET_OK !=
2790 GNUNET_BIO_read_string (rh, "download-tfn", &dc->temp_filename, 2811 GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10 * 1024)) ||
2791 10 * 1024)) || 2812 (GNUNET_OK != GNUNET_BIO_read_string (rh,
2813 "download-tfn",
2814 &dc->temp_filename,
2815 10 * 1024)) ||
2792 (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->old_file_size)) || 2816 (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->old_file_size)) ||
2793 (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->offset)) || 2817 (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->offset)) ||
2794 (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->length)) || 2818 (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->length)) ||
@@ -2803,14 +2827,14 @@ deserialize_download (struct GNUNET_FS_Handle *h,
2803 } 2827 }
2804 dc->options = (enum GNUNET_FS_DownloadOptions) options; 2828 dc->options = (enum GNUNET_FS_DownloadOptions) options;
2805 dc->active = 2829 dc->active =
2806 GNUNET_CONTAINER_multihashmap_create (1 + 2 * (dc->length / DBLOCK_SIZE), GNUNET_NO); 2830 GNUNET_CONTAINER_multihashmap_create (1 + 2 * (dc->length / DBLOCK_SIZE),
2831 GNUNET_NO);
2807 dc->has_finished = (int) status; 2832 dc->has_finished = (int) status;
2808 dc->treedepth = 2833 dc->treedepth =
2809 GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri)); 2834 GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri));
2810 if (GNUNET_FS_uri_test_loc (dc->uri)) 2835 if (GNUNET_FS_uri_test_loc (dc->uri))
2811 GNUNET_assert (GNUNET_OK == 2836 GNUNET_assert (GNUNET_OK ==
2812 GNUNET_FS_uri_loc_get_peer_identity (dc->uri, 2837 GNUNET_FS_uri_loc_get_peer_identity (dc->uri, &dc->target));
2813 &dc->target));
2814 if (NULL == dc->emsg) 2838 if (NULL == dc->emsg)
2815 { 2839 {
2816 dc->top_request = read_download_request (rh); 2840 dc->top_request = read_download_request (rh);
@@ -2820,43 +2844,31 @@ deserialize_download (struct GNUNET_FS_Handle *h,
2820 goto cleanup; 2844 goto cleanup;
2821 } 2845 }
2822 } 2846 }
2823 dn = get_download_sync_filename (dc, 2847 dn = get_download_sync_filename (dc, dc->serialization, ".dir");
2824 dc->serialization,
2825 ".dir");
2826 if (NULL != dn) 2848 if (NULL != dn)
2827 { 2849 {
2828 if (GNUNET_YES == 2850 if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES))
2829 GNUNET_DISK_directory_test (dn, 2851 GNUNET_DISK_directory_scan (dn, &deserialize_subdownload, dc);
2830 GNUNET_YES))
2831 GNUNET_DISK_directory_scan (dn,
2832 &deserialize_subdownload,
2833 dc);
2834 GNUNET_free (dn); 2852 GNUNET_free (dn);
2835 } 2853 }
2836 if (NULL != parent) 2854 if (NULL != parent)
2837 { 2855 {
2838 GNUNET_CONTAINER_DLL_insert (parent->child_head, 2856 GNUNET_CONTAINER_DLL_insert (parent->child_head, parent->child_tail, dc);
2839 parent->child_tail,
2840 dc);
2841 } 2857 }
2842 if (NULL != search) 2858 if (NULL != search)
2843 { 2859 {
2844 dc->search = search; 2860 dc->search = search;
2845 search->download = dc; 2861 search->download = dc;
2846 } 2862 }
2847 if ( (NULL == parent) && 2863 if ((NULL == parent) && (NULL == search))
2848 (NULL == search) )
2849 { 2864 {
2850 dc->top 2865 dc->top =
2851 = GNUNET_FS_make_top (dc->h, 2866 GNUNET_FS_make_top (dc->h, &GNUNET_FS_download_signal_suspend_, dc);
2852 &GNUNET_FS_download_signal_suspend_,
2853 dc);
2854 signal_download_resume (dc); 2867 signal_download_resume (dc);
2855 } 2868 }
2856 GNUNET_free (uris); 2869 GNUNET_free (uris);
2857 GNUNET_assert (NULL == dc->job_queue); 2870 GNUNET_assert (NULL == dc->job_queue);
2858 dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, 2871 dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc);
2859 dc);
2860 return; 2872 return;
2861cleanup: 2873cleanup:
2862 GNUNET_free_non_null (uris); 2874 GNUNET_free_non_null (uris);
@@ -2879,11 +2891,11 @@ signal_search_resume (struct GNUNET_FS_SearchContext *sc)
2879 pi.status = GNUNET_FS_STATUS_SEARCH_RESUME; 2891 pi.status = GNUNET_FS_STATUS_SEARCH_RESUME;
2880 pi.value.search.specifics.resume.message = sc->emsg; 2892 pi.value.search.specifics.resume.message = sc->emsg;
2881 pi.value.search.specifics.resume.is_paused = 2893 pi.value.search.specifics.resume.is_paused =
2882 (NULL == sc->mq) ? GNUNET_YES : GNUNET_NO; 2894 (NULL == sc->mq) ? GNUNET_YES : GNUNET_NO;
2883 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); 2895 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc);
2884 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, 2896 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
2885 &signal_result_resume, sc); 2897 &signal_result_resume,
2886 2898 sc);
2887} 2899}
2888 2900
2889 2901
@@ -2942,10 +2954,11 @@ deserialize_search (struct GNUNET_FS_Handle *h,
2942 sc->options = (enum GNUNET_FS_SearchOptions) options; 2954 sc->options = (enum GNUNET_FS_SearchOptions) options;
2943 sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO); 2955 sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO);
2944 dn = get_serialization_file_name_in_dir (h, 2956 dn = get_serialization_file_name_in_dir (h,
2945 (NULL == sc->psearch_result) ? 2957 (NULL == sc->psearch_result)
2946 GNUNET_FS_SYNC_PATH_MASTER_SEARCH : 2958 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
2947 GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 2959 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2948 sc->serialization, ""); 2960 sc->serialization,
2961 "");
2949 if (NULL != dn) 2962 if (NULL != dn)
2950 { 2963 {
2951 if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) 2964 if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES))
@@ -2955,8 +2968,9 @@ deserialize_search (struct GNUNET_FS_Handle *h,
2955 if (('\0' == in_pause) && 2968 if (('\0' == in_pause) &&
2956 (GNUNET_OK != GNUNET_FS_search_start_searching_ (sc))) 2969 (GNUNET_OK != GNUNET_FS_search_start_searching_ (sc)))
2957 { 2970 {
2958 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2971 GNUNET_log (
2959 _("Could not resume running search, will resume as paused search\n")); 2972 GNUNET_ERROR_TYPE_WARNING,
2973 _ ("Could not resume running search, will resume as paused search\n"));
2960 } 2974 }
2961 signal_search_resume (sc); 2975 signal_search_resume (sc);
2962 GNUNET_free (uris); 2976 GNUNET_free (uris);
@@ -2978,8 +2992,7 @@ cleanup:
2978 * @return #GNUNET_OK (continue to iterate) 2992 * @return #GNUNET_OK (continue to iterate)
2979 */ 2993 */
2980static int 2994static int
2981deserialize_search_file (void *cls, 2995deserialize_search_file (void *cls, const char *filename)
2982 const char *filename)
2983{ 2996{
2984 struct GNUNET_FS_Handle *h = cls; 2997 struct GNUNET_FS_Handle *h = cls;
2985 char *ser; 2998 char *ser;
@@ -2988,7 +3001,7 @@ deserialize_search_file (void *cls,
2988 struct GNUNET_FS_SearchContext *sc; 3001 struct GNUNET_FS_SearchContext *sc;
2989 struct stat buf; 3002 struct stat buf;
2990 3003
2991 if (0 != STAT (filename, &buf)) 3004 if (0 != stat (filename, &buf))
2992 { 3005 {
2993 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); 3006 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
2994 return GNUNET_OK; 3007 return GNUNET_OK;
@@ -3013,8 +3026,9 @@ deserialize_search_file (void *cls,
3013 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) 3026 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
3014 { 3027 {
3015 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3028 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3016 _("Failure while resuming search operation `%s': %s\n"), 3029 _ ("Failure while resuming search operation `%s': %s\n"),
3017 filename, emsg); 3030 filename,
3031 emsg);
3018 GNUNET_free (emsg); 3032 GNUNET_free (emsg);
3019 } 3033 }
3020 return GNUNET_OK; 3034 return GNUNET_OK;
@@ -3041,7 +3055,7 @@ deserialize_download_file (void *cls, const char *filename)
3041 rh = GNUNET_BIO_read_open (filename); 3055 rh = GNUNET_BIO_read_open (filename);
3042 if (NULL == rh) 3056 if (NULL == rh)
3043 { 3057 {
3044 if (0 != UNLINK (filename)) 3058 if (0 != unlink (filename))
3045 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); 3059 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
3046 GNUNET_free (ser); 3060 GNUNET_free (ser);
3047 return GNUNET_OK; 3061 return GNUNET_OK;
@@ -3051,8 +3065,9 @@ deserialize_download_file (void *cls, const char *filename)
3051 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) 3065 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
3052 { 3066 {
3053 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3067 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3054 _("Failure while resuming download operation `%s': %s\n"), 3068 _ ("Failure while resuming download operation `%s': %s\n"),
3055 filename, emsg); 3069 filename,
3070 emsg);
3056 GNUNET_free (emsg); 3071 GNUNET_free (emsg);
3057 } 3072 }
3058 return GNUNET_OK; 3073 return GNUNET_OK;
@@ -3068,7 +3083,7 @@ deserialize_download_file (void *cls, const char *filename)
3068 */ 3083 */
3069static void 3084static void
3070deserialization_master (const char *master_path, 3085deserialization_master (const char *master_path,
3071 GNUNET_FileNameCallback proc, 3086 GNUNET_FileNameCallback proc,
3072 struct GNUNET_FS_Handle *h) 3087 struct GNUNET_FS_Handle *h)
3073{ 3088{
3074 char *dn; 3089 char *dn;
@@ -3098,7 +3113,8 @@ GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
3098 const char *client_name, 3113 const char *client_name,
3099 GNUNET_FS_ProgressCallback upcb, 3114 GNUNET_FS_ProgressCallback upcb,
3100 void *upcb_cls, 3115 void *upcb_cls,
3101 enum GNUNET_FS_Flags flags, ...) 3116 enum GNUNET_FS_Flags flags,
3117 ...)
3102{ 3118{
3103 struct GNUNET_FS_Handle *ret; 3119 struct GNUNET_FS_Handle *ret;
3104 enum GNUNET_FS_OPTIONS opt; 3120 enum GNUNET_FS_OPTIONS opt;
@@ -3112,9 +3128,11 @@ GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
3112 ret->flags = flags; 3128 ret->flags = flags;
3113 ret->max_parallel_downloads = DEFAULT_MAX_PARALLEL_DOWNLOADS; 3129 ret->max_parallel_downloads = DEFAULT_MAX_PARALLEL_DOWNLOADS;
3114 ret->max_parallel_requests = DEFAULT_MAX_PARALLEL_REQUESTS; 3130 ret->max_parallel_requests = DEFAULT_MAX_PARALLEL_REQUESTS;
3115 ret->avg_block_latency = GNUNET_TIME_UNIT_MINUTES; /* conservative starting point */ 3131 ret->avg_block_latency =
3132 GNUNET_TIME_UNIT_MINUTES; /* conservative starting point */
3116 va_start (ap, flags); 3133 va_start (ap, flags);
3117 while (GNUNET_FS_OPTIONS_END != (opt = GNUNET_VA_ARG_ENUM (ap,GNUNET_FS_OPTIONS))) 3134 while (GNUNET_FS_OPTIONS_END !=
3135 (opt = GNUNET_VA_ARG_ENUM (ap, GNUNET_FS_OPTIONS)))
3118 { 3136 {
3119 switch (opt) 3137 switch (opt)
3120 { 3138 {
@@ -3138,13 +3156,17 @@ GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
3138 if (0 != (GNUNET_FS_FLAGS_PERSISTENCE & flags)) 3156 if (0 != (GNUNET_FS_FLAGS_PERSISTENCE & flags))
3139 { 3157 {
3140 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, 3158 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
3141 &deserialize_publish_file, ret); 3159 &deserialize_publish_file,
3160 ret);
3142 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_SEARCH, 3161 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_SEARCH,
3143 &deserialize_search_file, ret); 3162 &deserialize_search_file,
3163 ret);
3144 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, 3164 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
3145 &deserialize_download_file, ret); 3165 &deserialize_download_file,
3166 ret);
3146 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, 3167 deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
3147 &deserialize_unindex_file, ret); 3168 &deserialize_unindex_file,
3169 ret);
3148 } 3170 }
3149 return ret; 3171 return ret;
3150} 3172}
diff --git a/src/fs/fs_dirmetascan.c b/src/fs/fs_dirmetascan.c
index 115f99391..dd207e2c9 100644
--- a/src/fs/fs_dirmetascan.c
+++ b/src/fs/fs_dirmetascan.c
@@ -80,13 +80,12 @@ struct GNUNET_FS_DirScanner
80 /** 80 /**
81 * Task scheduled when we are done. 81 * Task scheduled when we are done.
82 */ 82 */
83 struct GNUNET_SCHEDULER_Task * stop_task; 83 struct GNUNET_SCHEDULER_Task *stop_task;
84 84
85 /** 85 /**
86 * Arguments for helper. 86 * Arguments for helper.
87 */ 87 */
88 char *args[4]; 88 char *args[4];
89
90}; 89};
91 90
92 91
@@ -151,11 +150,9 @@ advance (struct GNUNET_FS_ShareTreeItem *pos)
151 150
152 GNUNET_assert (NULL != pos); 151 GNUNET_assert (NULL != pos);
153 moved = 0; /* must not terminate, even on file, otherwise "normal" */ 152 moved = 0; /* must not terminate, even on file, otherwise "normal" */
154 while ( (pos->is_directory == GNUNET_YES) || 153 while ((pos->is_directory == GNUNET_YES) || (0 == moved))
155 (0 == moved) )
156 { 154 {
157 if ( (moved != -1) && 155 if ((moved != -1) && (NULL != pos->children_head))
158 (NULL != pos->children_head) )
159 { 156 {
160 pos = pos->children_head; 157 pos = pos->children_head;
161 moved = 1; /* can terminate if file */ 158 moved = 1; /* can terminate if file */
@@ -190,8 +187,8 @@ advance (struct GNUNET_FS_ShareTreeItem *pos)
190 */ 187 */
191static struct GNUNET_FS_ShareTreeItem * 188static struct GNUNET_FS_ShareTreeItem *
192expand_tree (struct GNUNET_FS_ShareTreeItem *parent, 189expand_tree (struct GNUNET_FS_ShareTreeItem *parent,
193 const char *filename, 190 const char *filename,
194 int is_directory) 191 int is_directory)
195{ 192{
196 struct GNUNET_FS_ShareTreeItem *chld; 193 struct GNUNET_FS_ShareTreeItem *chld;
197 size_t slen; 194 size_t slen;
@@ -200,20 +197,19 @@ expand_tree (struct GNUNET_FS_ShareTreeItem *parent,
200 chld->parent = parent; 197 chld->parent = parent;
201 chld->filename = GNUNET_strdup (filename); 198 chld->filename = GNUNET_strdup (filename);
202 GNUNET_asprintf (&chld->short_filename, 199 GNUNET_asprintf (&chld->short_filename,
203 "%s%s", 200 "%s%s",
204 GNUNET_STRINGS_get_short_name (filename), 201 GNUNET_STRINGS_get_short_name (filename),
205 is_directory == GNUNET_YES ? "/" : ""); 202 is_directory == GNUNET_YES ? "/" : "");
206 /* make sure we do not end with '//' */ 203 /* make sure we do not end with '//' */
207 slen = strlen (chld->short_filename); 204 slen = strlen (chld->short_filename);
208 if ( (slen >= 2) && 205 if ((slen >= 2) && (chld->short_filename[slen - 1] == '/') &&
209 (chld->short_filename[slen-1] == '/') && 206 (chld->short_filename[slen - 2] == '/'))
210 (chld->short_filename[slen-2] == '/') ) 207 chld->short_filename[slen - 1] = '\0';
211 chld->short_filename[slen-1] = '\0';
212 chld->is_directory = is_directory; 208 chld->is_directory = is_directory;
213 if (NULL != parent) 209 if (NULL != parent)
214 GNUNET_CONTAINER_DLL_insert (parent->children_head, 210 GNUNET_CONTAINER_DLL_insert (parent->children_head,
215 parent->children_tail, 211 parent->children_tail,
216 chld); 212 chld);
217 return chld; 213 return chld;
218} 214}
219 215
@@ -235,8 +231,9 @@ finish_scan (void *cls)
235 ds->helper = NULL; 231 ds->helper = NULL;
236 } 232 }
237 ds->progress_callback (ds->progress_callback_cls, 233 ds->progress_callback (ds->progress_callback_cls,
238 NULL, GNUNET_SYSERR, 234 NULL,
239 GNUNET_FS_DIRSCANNER_FINISHED); 235 GNUNET_SYSERR,
236 GNUNET_FS_DIRSCANNER_FINISHED);
240} 237}
241 238
242 239
@@ -251,8 +248,7 @@ finish_scan (void *cls)
251 * #GNUNET_SYSERR to stop further processing with error 248 * #GNUNET_SYSERR to stop further processing with error
252 */ 249 */
253static int 250static int
254process_helper_msgs (void *cls, 251process_helper_msgs (void *cls, const struct GNUNET_MessageHeader *msg)
255 const struct GNUNET_MessageHeader *msg)
256{ 252{
257 struct GNUNET_FS_DirScanner *ds = cls; 253 struct GNUNET_FS_DirScanner *ds = cls;
258 const char *filename; 254 const char *filename;
@@ -265,34 +261,31 @@ process_helper_msgs (void *cls,
265 (unsigned int) ntohs (msg->type)); 261 (unsigned int) ntohs (msg->type));
266#endif 262#endif
267 left = ntohs (msg->size) - sizeof (struct GNUNET_MessageHeader); 263 left = ntohs (msg->size) - sizeof (struct GNUNET_MessageHeader);
268 filename = (const char*) &msg[1]; 264 filename = (const char *) &msg[1];
269 switch (ntohs (msg->type)) 265 switch (ntohs (msg->type))
270 { 266 {
271 case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE: 267 case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE:
272 if (filename[left-1] != '\0') 268 if (filename[left - 1] != '\0')
273 { 269 {
274 GNUNET_break (0); 270 GNUNET_break (0);
275 break; 271 break;
276 } 272 }
277 ds->progress_callback (ds->progress_callback_cls, 273 ds->progress_callback (ds->progress_callback_cls,
278 filename, GNUNET_NO, 274 filename,
279 GNUNET_FS_DIRSCANNER_FILE_START); 275 GNUNET_NO,
276 GNUNET_FS_DIRSCANNER_FILE_START);
280 if (NULL == ds->toplevel) 277 if (NULL == ds->toplevel)
281 { 278 {
282 ds->toplevel = expand_tree (ds->pos, 279 ds->toplevel = expand_tree (ds->pos, filename, GNUNET_NO);
283 filename,
284 GNUNET_NO);
285 } 280 }
286 else 281 else
287 { 282 {
288 GNUNET_assert (NULL != ds->pos); 283 GNUNET_assert (NULL != ds->pos);
289 (void) expand_tree (ds->pos, 284 (void) expand_tree (ds->pos, filename, GNUNET_NO);
290 filename,
291 GNUNET_NO);
292 } 285 }
293 return GNUNET_OK; 286 return GNUNET_OK;
294 case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY: 287 case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY:
295 if (filename[left-1] != '\0') 288 if (filename[left - 1] != '\0')
296 { 289 {
297 GNUNET_break (0); 290 GNUNET_break (0);
298 break; 291 break;
@@ -301,29 +294,29 @@ process_helper_msgs (void *cls,
301 { 294 {
302 if (NULL == ds->pos) 295 if (NULL == ds->pos)
303 { 296 {
304 GNUNET_break (0); 297 GNUNET_break (0);
305 break; 298 break;
306 } 299 }
307 ds->pos = ds->pos->parent; 300 ds->pos = ds->pos->parent;
308 return GNUNET_OK; 301 return GNUNET_OK;
309 } 302 }
310 ds->progress_callback (ds->progress_callback_cls, 303 ds->progress_callback (ds->progress_callback_cls,
311 filename, GNUNET_YES, 304 filename,
312 GNUNET_FS_DIRSCANNER_FILE_START); 305 GNUNET_YES,
313 ds->pos = expand_tree (ds->pos, 306 GNUNET_FS_DIRSCANNER_FILE_START);
314 filename, 307 ds->pos = expand_tree (ds->pos, filename, GNUNET_YES);
315 GNUNET_YES);
316 if (NULL == ds->toplevel) 308 if (NULL == ds->toplevel)
317 ds->toplevel = ds->pos; 309 ds->toplevel = ds->pos;
318 return GNUNET_OK; 310 return GNUNET_OK;
319 case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR: 311 case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR:
320 break; 312 break;
321 case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE: 313 case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE:
322 if ('\0' != filename[left-1]) 314 if ('\0' != filename[left - 1])
323 break; 315 break;
324 ds->progress_callback (ds->progress_callback_cls, 316 ds->progress_callback (ds->progress_callback_cls,
325 filename, GNUNET_SYSERR, 317 filename,
326 GNUNET_FS_DIRSCANNER_FILE_IGNORED); 318 GNUNET_SYSERR,
319 GNUNET_FS_DIRSCANNER_FILE_IGNORED);
327 return GNUNET_OK; 320 return GNUNET_OK;
328 case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE: 321 case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE:
329 if (0 != left) 322 if (0 != left)
@@ -334,65 +327,66 @@ process_helper_msgs (void *cls,
334 if (NULL == ds->toplevel) 327 if (NULL == ds->toplevel)
335 break; 328 break;
336 ds->progress_callback (ds->progress_callback_cls, 329 ds->progress_callback (ds->progress_callback_cls,
337 NULL, GNUNET_SYSERR, 330 NULL,
338 GNUNET_FS_DIRSCANNER_ALL_COUNTED); 331 GNUNET_SYSERR,
332 GNUNET_FS_DIRSCANNER_ALL_COUNTED);
339 ds->pos = ds->toplevel; 333 ds->pos = ds->toplevel;
340 if (GNUNET_YES == ds->pos->is_directory) 334 if (GNUNET_YES == ds->pos->is_directory)
341 ds->pos = advance (ds->pos); 335 ds->pos = advance (ds->pos);
342 return GNUNET_OK; 336 return GNUNET_OK;
343 case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA: 337 case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA: {
344 { 338 size_t nlen;
345 size_t nlen; 339 const char *end;
346 const char *end;
347 340
348 if (NULL == ds->pos) 341 if (NULL == ds->pos)
349 { 342 {
350 GNUNET_break (0); 343 GNUNET_break (0);
351 break; 344 break;
352 } 345 }
353 end = memchr (filename, 0, left); 346 end = memchr (filename, 0, left);
354 if (NULL == end) 347 if (NULL == end)
355 { 348 {
356 GNUNET_break (0); 349 GNUNET_break (0);
357 break; 350 break;
358 } 351 }
359 end++; 352 end++;
360 nlen = end - filename; 353 nlen = end - filename;
361 left -= nlen; 354 left -= nlen;
362 if (0 != strcmp (filename, 355 if (0 != strcmp (filename, ds->pos->filename))
363 ds->pos->filename)) 356 {
364 { 357 GNUNET_break (0);
365 GNUNET_break (0); 358 break;
366 break; 359 }
367 } 360 ds->progress_callback (ds->progress_callback_cls,
368 ds->progress_callback (ds->progress_callback_cls, 361 filename,
369 filename, 362 GNUNET_YES,
370 GNUNET_YES, 363 GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED);
371 GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED); 364 if (0 < left)
372 if (0 < left) 365 {
366 ds->pos->meta = GNUNET_CONTAINER_meta_data_deserialize (end, left);
367 if (NULL == ds->pos->meta)
373 { 368 {
374 ds->pos->meta = GNUNET_CONTAINER_meta_data_deserialize (end, 369 GNUNET_break (0);
375 left); 370 break;
376 if (NULL == ds->pos->meta)
377 {
378 GNUNET_break (0);
379 break;
380 }
381 /* having full filenames is too dangerous; always make sure we clean them up */
382 GNUNET_CONTAINER_meta_data_delete (ds->pos->meta,
383 EXTRACTOR_METATYPE_FILENAME,
384 NULL, 0);
385 /* instead, put in our 'safer' original filename */
386 GNUNET_CONTAINER_meta_data_insert (ds->pos->meta, "<libgnunetfs>",
387 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
388 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
389 ds->pos->short_filename,
390 strlen (ds->pos->short_filename) + 1);
391 } 371 }
392 ds->pos->ksk_uri = GNUNET_FS_uri_ksk_create_from_meta_data (ds->pos->meta); 372 /* having full filenames is too dangerous; always make sure we clean them up */
393 ds->pos = advance (ds->pos); 373 GNUNET_CONTAINER_meta_data_delete (ds->pos->meta,
394 return GNUNET_OK; 374 EXTRACTOR_METATYPE_FILENAME,
375 NULL,
376 0);
377 /* instead, put in our 'safer' original filename */
378 GNUNET_CONTAINER_meta_data_insert (ds->pos->meta,
379 "<libgnunetfs>",
380 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
381 EXTRACTOR_METAFORMAT_UTF8,
382 "text/plain",
383 ds->pos->short_filename,
384 strlen (ds->pos->short_filename) + 1);
395 } 385 }
386 ds->pos->ksk_uri = GNUNET_FS_uri_ksk_create_from_meta_data (ds->pos->meta);
387 ds->pos = advance (ds->pos);
388 return GNUNET_OK;
389 }
396 case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED: 390 case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED:
397 if (NULL != ds->pos) 391 if (NULL != ds->pos)
398 { 392 {
@@ -406,16 +400,16 @@ process_helper_msgs (void *cls,
406 } 400 }
407 if (NULL == ds->toplevel) 401 if (NULL == ds->toplevel)
408 break; 402 break;
409 ds->stop_task = GNUNET_SCHEDULER_add_now (&finish_scan, 403 ds->stop_task = GNUNET_SCHEDULER_add_now (&finish_scan, ds);
410 ds);
411 return GNUNET_OK; 404 return GNUNET_OK;
412 default: 405 default:
413 GNUNET_break (0); 406 GNUNET_break (0);
414 break; 407 break;
415 } 408 }
416 ds->progress_callback (ds->progress_callback_cls, 409 ds->progress_callback (ds->progress_callback_cls,
417 NULL, GNUNET_SYSERR, 410 NULL,
418 GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); 411 GNUNET_SYSERR,
412 GNUNET_FS_DIRSCANNER_INTERNAL_ERROR);
419 return GNUNET_OK; 413 return GNUNET_OK;
420} 414}
421 415
@@ -434,8 +428,9 @@ helper_died_cb (void *cls)
434 if (NULL != ds->stop_task) 428 if (NULL != ds->stop_task)
435 return; /* normal death, was finished */ 429 return; /* normal death, was finished */
436 ds->progress_callback (ds->progress_callback_cls, 430 ds->progress_callback (ds->progress_callback_cls,
437 NULL, GNUNET_SYSERR, 431 NULL,
438 GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); 432 GNUNET_SYSERR,
433 GNUNET_FS_DIRSCANNER_INTERNAL_ERROR);
439} 434}
440 435
441 436
@@ -452,22 +447,23 @@ helper_died_cb (void *cls)
452 */ 447 */
453struct GNUNET_FS_DirScanner * 448struct GNUNET_FS_DirScanner *
454GNUNET_FS_directory_scan_start (const char *filename, 449GNUNET_FS_directory_scan_start (const char *filename,
455 int disable_extractor, const char *ex, 450 int disable_extractor,
456 GNUNET_FS_DirScannerProgressCallback cb, 451 const char *ex,
457 void *cb_cls) 452 GNUNET_FS_DirScannerProgressCallback cb,
453 void *cb_cls)
458{ 454{
459 struct stat sbuf; 455 struct stat sbuf;
460 char *filename_expanded; 456 char *filename_expanded;
461 struct GNUNET_FS_DirScanner *ds; 457 struct GNUNET_FS_DirScanner *ds;
462 458
463 if (0 != STAT (filename, &sbuf)) 459 if (0 != stat (filename, &sbuf))
464 return NULL; 460 return NULL;
465 filename_expanded = GNUNET_STRINGS_filename_expand (filename); 461 filename_expanded = GNUNET_STRINGS_filename_expand (filename);
466 if (NULL == filename_expanded) 462 if (NULL == filename_expanded)
467 return NULL; 463 return NULL;
468 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 464 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
469 "Starting to scan directory `%s'\n", 465 "Starting to scan directory `%s'\n",
470 filename_expanded); 466 filename_expanded);
471 ds = GNUNET_new (struct GNUNET_FS_DirScanner); 467 ds = GNUNET_new (struct GNUNET_FS_DirScanner);
472 ds->progress_callback = cb; 468 ds->progress_callback = cb;
473 ds->progress_callback_cls = cb_cls; 469 ds->progress_callback_cls = cb_cls;
@@ -481,12 +477,13 @@ GNUNET_FS_directory_scan_start (const char *filename,
481 ds->args[2] = ds->ex_arg; 477 ds->args[2] = ds->ex_arg;
482 ds->args[3] = NULL; 478 ds->args[3] = NULL;
483 ds->helper = GNUNET_HELPER_start (GNUNET_NO, 479 ds->helper = GNUNET_HELPER_start (GNUNET_NO,
484 "gnunet-helper-fs-publish", 480 "gnunet-helper-fs-publish",
485 ds->args, 481 ds->args,
486 &process_helper_msgs, 482 &process_helper_msgs,
487 &helper_died_cb, ds); 483 &helper_died_cb,
484 ds);
488 if (NULL == ds->helper) 485 if (NULL == ds->helper)
489 { 486 {
490 GNUNET_free (filename_expanded); 487 GNUNET_free (filename_expanded);
491 GNUNET_free (ds); 488 GNUNET_free (ds);
492 return NULL; 489 return NULL;
diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c
index 2d64bba11..59821f8a5 100644
--- a/src/fs/fs_download.c
+++ b/src/fs/fs_download.c
@@ -37,15 +37,13 @@ static int
37is_recursive_download (struct GNUNET_FS_DownloadContext *dc) 37is_recursive_download (struct GNUNET_FS_DownloadContext *dc)
38{ 38{
39 return (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE)) && 39 return (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE)) &&
40 ( (GNUNET_YES == 40 ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (dc->meta)) ||
41 GNUNET_FS_meta_data_test_for_directory (dc->meta)) || 41 ((NULL == dc->meta) &&
42 ( (NULL == dc->meta) && 42 ((NULL == dc->filename) ||
43 ( (NULL == dc->filename) || 43 ((strlen (dc->filename) >= strlen (GNUNET_FS_DIRECTORY_EXT)) &&
44 ( (strlen (dc->filename) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && 44 (NULL != strstr (dc->filename + strlen (dc->filename) -
45 (NULL != 45 strlen (GNUNET_FS_DIRECTORY_EXT),
46 strstr (dc->filename + strlen (dc->filename) - 46 GNUNET_FS_DIRECTORY_EXT))))));
47 strlen (GNUNET_FS_DIRECTORY_EXT),
48 GNUNET_FS_DIRECTORY_EXT)) ) ) ) );
49} 47}
50 48
51 49
@@ -69,9 +67,9 @@ static uint64_t
69compute_disk_offset (uint64_t fsize, uint64_t off, unsigned int depth) 67compute_disk_offset (uint64_t fsize, uint64_t off, unsigned int depth)
70{ 68{
71 unsigned int i; 69 unsigned int i;
72 uint64_t lsize; /* what is the size of all IBlocks for depth "i"? */ 70 uint64_t lsize; /* what is the size of all IBlocks for depth "i"? */
73 uint64_t loff; /* where do IBlocks for depth "i" start? */ 71 uint64_t loff; /* where do IBlocks for depth "i" start? */
74 unsigned int ioff; /* which IBlock corresponds to "off" at depth "i"? */ 72 unsigned int ioff; /* which IBlock corresponds to "off" at depth "i"? */
75 73
76 if (0 == depth) 74 if (0 == depth)
77 return off; 75 return off;
@@ -79,8 +77,7 @@ compute_disk_offset (uint64_t fsize, uint64_t off, unsigned int depth)
79 * to full DBLOCK_SIZE */ 77 * to full DBLOCK_SIZE */
80 loff = ((fsize + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * DBLOCK_SIZE; 78 loff = ((fsize + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * DBLOCK_SIZE;
81 lsize = 79 lsize =
82 ((fsize + DBLOCK_SIZE - 80 ((fsize + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * sizeof (struct ContentHashKey);
83 1) / DBLOCK_SIZE) * sizeof (struct ContentHashKey);
84 GNUNET_assert (0 == (off % DBLOCK_SIZE)); 81 GNUNET_assert (0 == (off % DBLOCK_SIZE));
85 ioff = (off / DBLOCK_SIZE); 82 ioff = (off / DBLOCK_SIZE);
86 for (i = 1; i < depth; i++) 83 for (i = 1; i < depth; i++)
@@ -109,19 +106,19 @@ GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
109 pi->value.download.dc = dc; 106 pi->value.download.dc = dc;
110 pi->value.download.cctx = dc->client_info; 107 pi->value.download.cctx = dc->client_info;
111 pi->value.download.pctx = 108 pi->value.download.pctx =
112 (NULL == dc->parent) ? NULL : dc->parent->client_info; 109 (NULL == dc->parent) ? NULL : dc->parent->client_info;
113 pi->value.download.sctx = 110 pi->value.download.sctx =
114 (NULL == dc->search) ? NULL : dc->search->client_info; 111 (NULL == dc->search) ? NULL : dc->search->client_info;
115 pi->value.download.uri = dc->uri; 112 pi->value.download.uri = dc->uri;
116 pi->value.download.filename = dc->filename; 113 pi->value.download.filename = dc->filename;
117 pi->value.download.size = dc->length; 114 pi->value.download.size = dc->length;
118 /* FIXME: Fix duration calculation to account for pauses */ 115 /* FIXME: Fix duration calculation to account for pauses */
119 pi->value.download.duration = 116 pi->value.download.duration =
120 GNUNET_TIME_absolute_get_duration (dc->start_time); 117 GNUNET_TIME_absolute_get_duration (dc->start_time);
121 pi->value.download.completed = dc->completed; 118 pi->value.download.completed = dc->completed;
122 pi->value.download.anonymity = dc->anonymity; 119 pi->value.download.anonymity = dc->anonymity;
123 pi->value.download.eta = 120 pi->value.download.eta =
124 GNUNET_TIME_calculate_eta (dc->start_time, dc->completed, dc->length); 121 GNUNET_TIME_calculate_eta (dc->start_time, dc->completed, dc->length);
125 pi->value.download.is_active = (NULL == dc->mq) ? GNUNET_NO : GNUNET_YES; 122 pi->value.download.is_active = (NULL == dc->mq) ? GNUNET_NO : GNUNET_YES;
126 pi->fsh = dc->h; 123 pi->fsh = dc->h;
127 if (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) 124 if (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE))
@@ -181,7 +178,6 @@ struct ProcessResultClosure
181 * how often did we transmit the query? 178 * how often did we transmit the query?
182 */ 179 */
183 uint32_t num_transmissions; 180 uint32_t num_transmissions;
184
185}; 181};
186 182
187 183
@@ -196,7 +192,7 @@ struct ProcessResultClosure
196 */ 192 */
197static int 193static int
198process_result_with_request (void *cls, 194process_result_with_request (void *cls,
199 const struct GNUNET_HashCode * key, 195 const struct GNUNET_HashCode *key,
200 void *value); 196 void *value);
201 197
202 198
@@ -216,8 +212,10 @@ process_result_with_request (void *cls,
216static int 212static int
217encrypt_existing_match (struct GNUNET_FS_DownloadContext *dc, 213encrypt_existing_match (struct GNUNET_FS_DownloadContext *dc,
218 const struct ContentHashKey *chk, 214 const struct ContentHashKey *chk,
219 struct DownloadRequest *dr, const char *block, 215 struct DownloadRequest *dr,
220 size_t len, int do_store) 216 const char *block,
217 size_t len,
218 int do_store)
221{ 219{
222 struct ProcessResultClosure prc; 220 struct ProcessResultClosure prc;
223 char enc[len]; 221 char enc[len];
@@ -237,17 +235,18 @@ encrypt_existing_match (struct GNUNET_FS_DownloadContext *dc,
237 GNUNET_break_op (0); 235 GNUNET_break_op (0);
238 return GNUNET_SYSERR; 236 return GNUNET_SYSERR;
239 } 237 }
240 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 238 GNUNET_log (
241 "Matching %u byte block for `%s' at offset %llu already present, no need for download!\n", 239 GNUNET_ERROR_TYPE_DEBUG,
242 (unsigned int) len, 240 "Matching %u byte block for `%s' at offset %llu already present, no need for download!\n",
243 dc->filename, (unsigned long long) dr->offset); 241 (unsigned int) len,
242 dc->filename,
243 (unsigned long long) dr->offset);
244 /* already got it! */ 244 /* already got it! */
245 prc.dc = dc; 245 prc.dc = dc;
246 prc.data = enc; 246 prc.data = enc;
247 prc.size = len; 247 prc.size = len;
248 prc.type = 248 prc.type = (0 == dr->depth) ? GNUNET_BLOCK_TYPE_FS_DBLOCK
249 (0 == 249 : GNUNET_BLOCK_TYPE_FS_IBLOCK;
250 dr->depth) ? GNUNET_BLOCK_TYPE_FS_DBLOCK : GNUNET_BLOCK_TYPE_FS_IBLOCK;
251 prc.query = chk->query; 250 prc.query = chk->query;
252 prc.do_store = do_store; 251 prc.do_store = do_store;
253 prc.last_transmission = GNUNET_TIME_UNIT_FOREVER_ABS; 252 prc.last_transmission = GNUNET_TIME_UNIT_FOREVER_ABS;
@@ -306,8 +305,10 @@ full_recursive_download (struct GNUNET_FS_DownloadContext *dc)
306 size = (size_t) size64; 305 size = (size_t) size64;
307 if (size64 != (uint64_t) size) 306 if (size64 != (uint64_t) size)
308 { 307 {
309 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 308 GNUNET_log (
310 _("Recursive downloads of directories larger than 4 GB are not supported on 32-bit systems\n")); 309 GNUNET_ERROR_TYPE_ERROR,
310 _ (
311 "Recursive downloads of directories larger than 4 GB are not supported on 32-bit systems\n"));
311 return; 312 return;
312 } 313 }
313 if (NULL != dc->filename) 314 if (NULL != dc->filename)
@@ -324,15 +325,12 @@ full_recursive_download (struct GNUNET_FS_DownloadContext *dc)
324 GNUNET_DISK_PERM_NONE); 325 GNUNET_DISK_PERM_NONE);
325 } 326 }
326 if (NULL == h) 327 if (NULL == h)
327 return; /* oops */ 328 return; /* oops */
328 data = GNUNET_DISK_file_map (h, 329 data = GNUNET_DISK_file_map (h, &m, GNUNET_DISK_MAP_TYPE_READ, size);
329 &m,
330 GNUNET_DISK_MAP_TYPE_READ,
331 size);
332 if (NULL == data) 330 if (NULL == data)
333 { 331 {
334 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 332 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
335 _("Directory too large for system address space\n")); 333 _ ("Directory too large for system address space\n"));
336 } 334 }
337 else 335 else
338 { 336 {
@@ -343,16 +341,18 @@ full_recursive_download (struct GNUNET_FS_DownloadContext *dc)
343 &trigger_recursive_download, 341 &trigger_recursive_download,
344 dc)) 342 dc))
345 { 343 {
346 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 344 GNUNET_log (
347 _("Failed to access full directroy contents of `%s' for recursive download\n"), 345 GNUNET_ERROR_TYPE_WARNING,
348 dc->filename); 346 _ (
347 "Failed to access full directroy contents of `%s' for recursive download\n"),
348 dc->filename);
349 } 349 }
350 GNUNET_DISK_file_unmap (m); 350 GNUNET_DISK_file_unmap (m);
351 } 351 }
352 GNUNET_DISK_file_close (h); 352 GNUNET_DISK_file_close (h);
353 if (NULL == dc->filename) 353 if (NULL == dc->filename)
354 { 354 {
355 if (0 != UNLINK (dc->temp_filename)) 355 if (0 != unlink (dc->temp_filename))
356 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 356 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
357 "unlink", 357 "unlink",
358 dc->temp_filename); 358 dc->temp_filename);
@@ -384,12 +384,10 @@ check_completed (struct GNUNET_FS_DownloadContext *dc)
384 /* then, check if children are done already */ 384 /* then, check if children are done already */
385 for (pos = dc->child_head; NULL != pos; pos = pos->next) 385 for (pos = dc->child_head; NULL != pos; pos = pos->next)
386 { 386 {
387 if ( (NULL == pos->emsg) && 387 if ((NULL == pos->emsg) && (pos->completed < pos->length))
388 (pos->completed < pos->length) ) 388 return; /* not done yet */
389 return; /* not done yet */ 389 if ((NULL != pos->child_head) && (pos->has_finished != GNUNET_YES))
390 if ( (NULL != pos->child_head) && 390 return; /* not transitively done yet */
391 (pos->has_finished != GNUNET_YES) )
392 return; /* not transitively done yet */
393 } 391 }
394 /* All of our children are done, so mark this download done */ 392 /* All of our children are done, so mark this download done */
395 dc->has_finished = GNUNET_YES; 393 dc->has_finished = GNUNET_YES;
@@ -432,7 +430,9 @@ check_completed (struct GNUNET_FS_DownloadContext *dc)
432 */ 430 */
433static void 431static void
434try_match_block (struct GNUNET_FS_DownloadContext *dc, 432try_match_block (struct GNUNET_FS_DownloadContext *dc,
435 struct DownloadRequest *dr, const char *data, size_t data_len) 433 struct DownloadRequest *dr,
434 const char *data,
435 size_t data_len)
436{ 436{
437 struct GNUNET_FS_ProgressInfo pi; 437 struct GNUNET_FS_ProgressInfo pi;
438 unsigned int i; 438 unsigned int i;
@@ -455,8 +455,8 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc,
455 return; 455 return;
456 if (dr->depth > 0) 456 if (dr->depth > 0)
457 { 457 {
458 if ( (dc->offset > 0) || 458 if ((dc->offset > 0) ||
459 (dc->length < GNUNET_ntohll (dc->uri->data.chk.file_length)) ) 459 (dc->length < GNUNET_ntohll (dc->uri->data.chk.file_length)))
460 { 460 {
461 /* NOTE: this test is not tight, but should suffice; the issue 461 /* NOTE: this test is not tight, but should suffice; the issue
462 here is that 'dr->num_children' may inherently only specify a 462 here is that 'dr->num_children' may inherently only specify a
@@ -485,16 +485,13 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc,
485 else 485 else
486 { 486 {
487 if (dr->offset > data_len) 487 if (dr->offset > data_len)
488 return; /* oops */ 488 return; /* oops */
489 dlen = GNUNET_MIN (data_len - dr->offset, DBLOCK_SIZE); 489 dlen = GNUNET_MIN (data_len - dr->offset, DBLOCK_SIZE);
490 } 490 }
491 GNUNET_CRYPTO_hash (&data[dr->offset], dlen, &in_chk.key); 491 GNUNET_CRYPTO_hash (&data[dr->offset], dlen, &in_chk.key);
492 GNUNET_CRYPTO_hash_to_aes_key (&in_chk.key, &sk, &iv); 492 GNUNET_CRYPTO_hash_to_aes_key (&in_chk.key, &sk, &iv);
493 if (-1 == GNUNET_CRYPTO_symmetric_encrypt (&data[dr->offset], 493 if (-1 ==
494 dlen, 494 GNUNET_CRYPTO_symmetric_encrypt (&data[dr->offset], dlen, &sk, &iv, enc))
495 &sk,
496 &iv,
497 enc))
498 { 495 {
499 GNUNET_break (0); 496 GNUNET_break (0);
500 return; 497 return;
@@ -507,9 +504,7 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc,
507 dr->state = BRS_RECONSTRUCT_META_UP; 504 dr->state = BRS_RECONSTRUCT_META_UP;
508 break; 505 break;
509 case BRS_CHK_SET: 506 case BRS_CHK_SET:
510 if (0 != memcmp (&in_chk, 507 if (0 != memcmp (&in_chk, &dr->chk, sizeof (struct ContentHashKey)))
511 &dr->chk,
512 sizeof (struct ContentHashKey)))
513 { 508 {
514 /* other peer provided bogus meta data */ 509 /* other peer provided bogus meta data */
515 GNUNET_break_op (0); 510 GNUNET_break_op (0);
@@ -521,17 +516,17 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc,
521 { 516 {
522 fh = GNUNET_DISK_file_open (fn, 517 fh = GNUNET_DISK_file_open (fn,
523 GNUNET_DISK_OPEN_READWRITE | 518 GNUNET_DISK_OPEN_READWRITE |
524 GNUNET_DISK_OPEN_CREATE | 519 GNUNET_DISK_OPEN_CREATE |
525 GNUNET_DISK_OPEN_TRUNCATE, 520 GNUNET_DISK_OPEN_TRUNCATE,
526 GNUNET_DISK_PERM_USER_READ | 521 GNUNET_DISK_PERM_USER_READ |
527 GNUNET_DISK_PERM_USER_WRITE | 522 GNUNET_DISK_PERM_USER_WRITE |
528 GNUNET_DISK_PERM_GROUP_READ | 523 GNUNET_DISK_PERM_GROUP_READ |
529 GNUNET_DISK_PERM_OTHER_READ); 524 GNUNET_DISK_PERM_OTHER_READ);
530 if (NULL == fh) 525 if (NULL == fh)
531 { 526 {
532 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", fn); 527 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", fn);
533 GNUNET_asprintf (&dc->emsg, 528 GNUNET_asprintf (&dc->emsg,
534 _("Failed to open file `%s' for writing"), 529 _ ("Failed to open file `%s' for writing"),
535 fn); 530 fn);
536 GNUNET_DISK_file_close (fh); 531 GNUNET_DISK_file_close (fh);
537 dr->state = BRS_ERROR; 532 dr->state = BRS_ERROR;
@@ -543,7 +538,8 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc,
543 if (data_len != GNUNET_DISK_file_write (fh, odata, odata_len)) 538 if (data_len != GNUNET_DISK_file_write (fh, odata, odata_len))
544 { 539 {
545 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn); 540 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn);
546 GNUNET_asprintf (&dc->emsg, _("Failed to open file `%s' for writing"), 541 GNUNET_asprintf (&dc->emsg,
542 _ ("Failed to open file `%s' for writing"),
547 fn); 543 fn);
548 GNUNET_DISK_file_close (fh); 544 GNUNET_DISK_file_close (fh);
549 dr->state = BRS_ERROR; 545 dr->state = BRS_ERROR;
@@ -564,13 +560,14 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc,
564 pi.value.download.specifics.progress.data_len = dlen; 560 pi.value.download.specifics.progress.data_len = dlen;
565 pi.value.download.specifics.progress.depth = 0; 561 pi.value.download.specifics.progress.depth = 0;
566 pi.value.download.specifics.progress.respect_offered = 0; 562 pi.value.download.specifics.progress.respect_offered = 0;
567 pi.value.download.specifics.progress.block_download_duration = GNUNET_TIME_UNIT_ZERO; 563 pi.value.download.specifics.progress.block_download_duration =
564 GNUNET_TIME_UNIT_ZERO;
568 GNUNET_FS_download_make_status_ (&pi, dc); 565 GNUNET_FS_download_make_status_ (&pi, dc);
569 if ((NULL != dc->filename) && 566 if ((NULL != dc->filename) &&
570 (0 != 567 (0 != truncate (dc->filename,
571 TRUNCATE (dc->filename, 568 GNUNET_ntohll (dc->uri->data.chk.file_length))))
572 GNUNET_ntohll (dc->uri->data.chk.file_length)))) 569 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
573 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "truncate", 570 "truncate",
574 dc->filename); 571 dc->filename);
575 check_completed (dc); 572 check_completed (dc);
576 break; 573 break;
@@ -601,25 +598,27 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc,
601 * @return 0 to continue extracting, 1 to abort 598 * @return 0 to continue extracting, 1 to abort
602 */ 599 */
603static int 600static int
604match_full_data (void *cls, const char *plugin_name, 601match_full_data (void *cls,
605 enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, 602 const char *plugin_name,
606 const char *data_mime_type, const char *data, size_t data_len) 603 enum EXTRACTOR_MetaType type,
604 enum EXTRACTOR_MetaFormat format,
605 const char *data_mime_type,
606 const char *data,
607 size_t data_len)
607{ 608{
608 struct GNUNET_FS_DownloadContext *dc = cls; 609 struct GNUNET_FS_DownloadContext *dc = cls;
609 610
610 if (EXTRACTOR_METATYPE_GNUNET_FULL_DATA != type) 611 if (EXTRACTOR_METATYPE_GNUNET_FULL_DATA != type)
611 return 0; 612 return 0;
612 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u bytes of FD!\n", 613 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
614 "Found %u bytes of FD!\n",
613 (unsigned int) data_len); 615 (unsigned int) data_len);
614 if (GNUNET_FS_uri_chk_get_file_size (dc->uri) != data_len) 616 if (GNUNET_FS_uri_chk_get_file_size (dc->uri) != data_len)
615 { 617 {
616 GNUNET_break_op (0); 618 GNUNET_break_op (0);
617 return 1; /* bogus meta data */ 619 return 1; /* bogus meta data */
618 } 620 }
619 try_match_block (dc, 621 try_match_block (dc, dc->top_request, data, data_len);
620 dc->top_request,
621 data,
622 data_len);
623 return 1; 622 return 1;
624} 623}
625 624
@@ -644,8 +643,7 @@ propagate_up (struct DownloadRequest *dr)
644 for (i = 0; i < dr->num_children; i++) 643 for (i = 0; i < dr->num_children; i++)
645 if (dr->children[i]->state != BRS_DOWNLOAD_UP) 644 if (dr->children[i]->state != BRS_DOWNLOAD_UP)
646 break; 645 break;
647 } 646 } while (i == dr->num_children);
648 while (i == dr->num_children);
649} 647}
650 648
651 649
@@ -682,20 +680,20 @@ try_top_down_reconstruction (struct GNUNET_FS_DownloadContext *dc,
682 GNUNET_assert (len <= DBLOCK_SIZE); 680 GNUNET_assert (len <= DBLOCK_SIZE);
683 off = compute_disk_offset (total, dr->offset, dr->depth); 681 off = compute_disk_offset (total, dr->offset, dr->depth);
684 if (dc->old_file_size < off + len) 682 if (dc->old_file_size < off + len)
685 return; /* failure */ 683 return; /* failure */
686 if (off != GNUNET_DISK_file_seek (dc->rfh, off, GNUNET_DISK_SEEK_SET)) 684 if (off != GNUNET_DISK_file_seek (dc->rfh, off, GNUNET_DISK_SEEK_SET))
687 { 685 {
688 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "seek", dc->filename); 686 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "seek", dc->filename);
689 return; /* failure */ 687 return; /* failure */
690 } 688 }
691 if (len != GNUNET_DISK_file_read (dc->rfh, block, len)) 689 if (len != GNUNET_DISK_file_read (dc->rfh, block, len))
692 { 690 {
693 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "read", dc->filename); 691 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "read", dc->filename);
694 return; /* failure */ 692 return; /* failure */
695 } 693 }
696 GNUNET_CRYPTO_hash (block, len, &key); 694 GNUNET_CRYPTO_hash (block, len, &key);
697 if (0 != memcmp (&key, &dr->chk.key, sizeof (struct GNUNET_HashCode))) 695 if (0 != memcmp (&key, &dr->chk.key, sizeof (struct GNUNET_HashCode)))
698 return; /* mismatch */ 696 return; /* mismatch */
699 if (GNUNET_OK != 697 if (GNUNET_OK !=
700 encrypt_existing_match (dc, &dr->chk, dr, block, len, GNUNET_NO)) 698 encrypt_existing_match (dc, &dr->chk, dr, block, len, GNUNET_NO))
701 { 699 {
@@ -728,10 +726,10 @@ try_top_down_reconstruction (struct GNUNET_FS_DownloadContext *dc,
728 try_top_down_reconstruction (dc, drc); 726 try_top_down_reconstruction (dc, drc);
729 } 727 }
730 if (BRS_DOWNLOAD_UP != drc->state) 728 if (BRS_DOWNLOAD_UP != drc->state)
731 up_done = GNUNET_NO; /* children not all done */ 729 up_done = GNUNET_NO; /* children not all done */
732 } 730 }
733 if (GNUNET_YES == up_done) 731 if (GNUNET_YES == up_done)
734 propagate_up (dr); /* children all done (or no children...) */ 732 propagate_up (dr); /* children all done (or no children...) */
735} 733}
736 734
737 735
@@ -744,17 +742,14 @@ try_top_down_reconstruction (struct GNUNET_FS_DownloadContext *dc,
744 * @return #GNUNET_OK 742 * @return #GNUNET_OK
745 */ 743 */
746static int 744static int
747retry_entry (void *cls, 745retry_entry (void *cls, const struct GNUNET_HashCode *key, void *entry)
748 const struct GNUNET_HashCode *key,
749 void *entry)
750{ 746{
751 struct GNUNET_FS_DownloadContext *dc = cls; 747 struct GNUNET_FS_DownloadContext *dc = cls;
752 struct DownloadRequest *dr = entry; 748 struct DownloadRequest *dr = entry;
753 struct SearchMessage *sm; 749 struct SearchMessage *sm;
754 struct GNUNET_MQ_Envelope *env; 750 struct GNUNET_MQ_Envelope *env;
755 751
756 env = GNUNET_MQ_msg (sm, 752 env = GNUNET_MQ_msg (sm, GNUNET_MESSAGE_TYPE_FS_START_SEARCH);
757 GNUNET_MESSAGE_TYPE_FS_START_SEARCH);
758 if (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY)) 753 if (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY))
759 sm->options = htonl (GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY); 754 sm->options = htonl (GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY);
760 else 755 else
@@ -766,8 +761,7 @@ retry_entry (void *cls,
766 sm->anonymity_level = htonl (dc->anonymity); 761 sm->anonymity_level = htonl (dc->anonymity);
767 sm->target = dc->target; 762 sm->target = dc->target;
768 sm->query = dr->chk.query; 763 sm->query = dr->chk.query;
769 GNUNET_MQ_send (dc->mq, 764 GNUNET_MQ_send (dc->mq, env);
770 env);
771 return GNUNET_OK; 765 return GNUNET_OK;
772} 766}
773 767
@@ -817,20 +811,17 @@ schedule_block_download (struct GNUNET_FS_DownloadContext *dc,
817 (unsigned long long) dr->offset, 811 (unsigned long long) dr->offset,
818 dr->depth, 812 dr->depth,
819 GNUNET_h2s (&dr->chk.query)); 813 GNUNET_h2s (&dr->chk.query));
820 if (GNUNET_NO != 814 if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains_value (dc->active,
821 GNUNET_CONTAINER_multihashmap_contains_value (dc->active, 815 &dr->chk.query,
822 &dr->chk.query, 816 dr))
823 dr)) 817 return; /* already active */
824 return; /* already active */
825 GNUNET_CONTAINER_multihashmap_put (dc->active, 818 GNUNET_CONTAINER_multihashmap_put (dc->active,
826 &dr->chk.query, 819 &dr->chk.query,
827 dr, 820 dr,
828 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 821 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
829 if (NULL == dc->mq) 822 if (NULL == dc->mq)
830 return; /* download not active */ 823 return; /* download not active */
831 retry_entry (dc, 824 retry_entry (dc, &dr->chk.query, dr);
832 &dr->chk.query,
833 dr);
834} 825}
835 826
836 827
@@ -867,7 +858,7 @@ trigger_recursive_download (void *cls,
867 char *sfn; 858 char *sfn;
868 859
869 if (NULL == uri) 860 if (NULL == uri)
870 return; /* entry for the directory itself */ 861 return; /* entry for the directory itself */
871 cpos = dc->child_head; 862 cpos = dc->child_head;
872 while (NULL != cpos) 863 while (NULL != cpos)
873 { 864 {
@@ -877,7 +868,7 @@ trigger_recursive_download (void *cls,
877 cpos = cpos->next; 868 cpos = cpos->next;
878 } 869 }
879 if (NULL != cpos) 870 if (NULL != cpos)
880 return; /* already exists */ 871 return; /* already exists */
881 fn = NULL; 872 fn = NULL;
882 if (NULL == filename) 873 if (NULL == filename)
883 { 874 {
@@ -892,7 +883,9 @@ trigger_recursive_download (void *cls,
892 { 883 {
893 ext = fn; 884 ext = fn;
894 us = GNUNET_FS_uri_to_string (uri); 885 us = GNUNET_FS_uri_to_string (uri);
895 GNUNET_asprintf (&fn, "%s%s", &us[strlen (GNUNET_FS_URI_CHK_PREFIX)], 886 GNUNET_asprintf (&fn,
887 "%s%s",
888 &us[strlen (GNUNET_FS_URI_CHK_PREFIX)],
896 ext); 889 ext);
897 GNUNET_free (ext); 890 GNUNET_free (ext);
898 GNUNET_free (us); 891 GNUNET_free (us);
@@ -920,25 +913,28 @@ trigger_recursive_download (void *cls,
920 else 913 else
921 { 914 {
922 dn = GNUNET_strdup (dc->filename); 915 dn = GNUNET_strdup (dc->filename);
923 GNUNET_break ((strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && 916 GNUNET_break (
924 (NULL != 917 (strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) &&
925 strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT), 918 (NULL != strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT),
926 GNUNET_FS_DIRECTORY_EXT))); 919 GNUNET_FS_DIRECTORY_EXT)));
927 sfn = GNUNET_strdup (filename); 920 sfn = GNUNET_strdup (filename);
928 while ((strlen (sfn) > 0) && ('/' == filename[strlen (sfn) - 1])) 921 while ((strlen (sfn) > 0) && ('/' == filename[strlen (sfn) - 1]))
929 sfn[strlen (sfn) - 1] = '\0'; 922 sfn[strlen (sfn) - 1] = '\0';
930 if ((strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && 923 if ((strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) &&
931 (NULL != 924 (NULL != strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT),
932 strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT), 925 GNUNET_FS_DIRECTORY_EXT)))
933 GNUNET_FS_DIRECTORY_EXT)))
934 dn[strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT)] = '\0'; 926 dn[strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT)] = '\0';
935 if ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (meta)) && 927 if ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (meta)) &&
936 ((strlen (filename) < strlen (GNUNET_FS_DIRECTORY_EXT)) || 928 ((strlen (filename) < strlen (GNUNET_FS_DIRECTORY_EXT)) ||
937 (NULL == 929 (NULL == strstr (filename + strlen (filename) -
938 strstr (filename + strlen (filename) - 930 strlen (GNUNET_FS_DIRECTORY_EXT),
939 strlen (GNUNET_FS_DIRECTORY_EXT), GNUNET_FS_DIRECTORY_EXT)))) 931 GNUNET_FS_DIRECTORY_EXT))))
940 { 932 {
941 GNUNET_asprintf (&full_name, "%s%s%s%s", dn, DIR_SEPARATOR_STR, sfn, 933 GNUNET_asprintf (&full_name,
934 "%s%s%s%s",
935 dn,
936 DIR_SEPARATOR_STR,
937 sfn,
942 GNUNET_FS_DIRECTORY_EXT); 938 GNUNET_FS_DIRECTORY_EXT);
943 } 939 }
944 else 940 else
@@ -952,8 +948,8 @@ trigger_recursive_download (void *cls,
952 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (full_name))) 948 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (full_name)))
953 { 949 {
954 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 950 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
955 _ 951 _ (
956 ("Failed to create directory for recursive download of `%s'\n"), 952 "Failed to create directory for recursive download of `%s'\n"),
957 full_name); 953 full_name);
958 GNUNET_free (full_name); 954 GNUNET_free (full_name);
959 GNUNET_free_non_null (fn); 955 GNUNET_free_non_null (fn);
@@ -964,8 +960,8 @@ trigger_recursive_download (void *cls,
964 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 960 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
965 "Triggering recursive download of size %llu with %u bytes MD\n", 961 "Triggering recursive download of size %llu with %u bytes MD\n",
966 (unsigned long long) GNUNET_FS_uri_chk_get_file_size (uri), 962 (unsigned long long) GNUNET_FS_uri_chk_get_file_size (uri),
967 (unsigned int) 963 (unsigned int) GNUNET_CONTAINER_meta_data_get_serialized_size (
968 GNUNET_CONTAINER_meta_data_get_serialized_size (meta)); 964 meta));
969 GNUNET_FS_download_start (dc->h, 965 GNUNET_FS_download_start (dc->h,
970 uri, 966 uri,
971 meta, 967 meta,
@@ -1029,26 +1025,29 @@ process_result_with_request (void *cls,
1029 int i; 1025 int i;
1030 struct ContentHashKey *chkarr; 1026 struct ContentHashKey *chkarr;
1031 1027
1032 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1028 GNUNET_log (
1033 "Received %u byte block `%s' matching pending request at depth %u and offset %llu/%llu\n", 1029 GNUNET_ERROR_TYPE_DEBUG,
1034 (unsigned int) prc->size, 1030 "Received %u byte block `%s' matching pending request at depth %u and offset %llu/%llu\n",
1035 GNUNET_h2s (key), 1031 (unsigned int) prc->size,
1036 dr->depth, 1032 GNUNET_h2s (key),
1037 (unsigned long long) dr->offset, 1033 dr->depth,
1038 (unsigned long long) GNUNET_ntohll (dc->uri->data. 1034 (unsigned long long) dr->offset,
1039 chk.file_length)); 1035 (unsigned long long) GNUNET_ntohll (dc->uri->data.chk.file_length));
1040 bs = GNUNET_FS_tree_calculate_block_size (GNUNET_ntohll 1036 bs = GNUNET_FS_tree_calculate_block_size (GNUNET_ntohll (
1041 (dc->uri->data.chk.file_length), 1037 dc->uri->data.chk.file_length),
1042 dr->offset, dr->depth); 1038 dr->offset,
1039 dr->depth);
1043 if (prc->size != bs) 1040 if (prc->size != bs)
1044 { 1041 {
1045 GNUNET_asprintf (&dc->emsg, 1042 GNUNET_asprintf (
1046 _ 1043 &dc->emsg,
1047 ("Internal error or bogus download URI (expected %u bytes at depth %u and offset %llu/%llu, got %u bytes)"), 1044 _ (
1048 bs, dr->depth, (unsigned long long) dr->offset, 1045 "Internal error or bogus download URI (expected %u bytes at depth %u and offset %llu/%llu, got %u bytes)"),
1049 (unsigned long long) GNUNET_ntohll (dc->uri->data. 1046 bs,
1050 chk.file_length), 1047 dr->depth,
1051 prc->size); 1048 (unsigned long long) dr->offset,
1049 (unsigned long long) GNUNET_ntohll (dc->uri->data.chk.file_length),
1050 prc->size);
1052 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s\n", dc->emsg); 1051 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s\n", dc->emsg);
1053 while (NULL != dr->parent) 1052 while (NULL != dr->parent)
1054 { 1053 {
@@ -1059,69 +1058,61 @@ process_result_with_request (void *cls,
1059 goto signal_error; 1058 goto signal_error;
1060 } 1059 }
1061 1060
1062 (void) GNUNET_CONTAINER_multihashmap_remove (dc->active, 1061 (void) GNUNET_CONTAINER_multihashmap_remove (dc->active, &prc->query, dr);
1063 &prc->query, 1062 GNUNET_CRYPTO_hash_to_aes_key (&dr->chk.key, &skey, &iv);
1064 dr); 1063 if (-1 ==
1065 GNUNET_CRYPTO_hash_to_aes_key (&dr->chk.key, 1064 GNUNET_CRYPTO_symmetric_decrypt (prc->data, prc->size, &skey, &iv, pt))
1066 &skey,
1067 &iv);
1068 if (-1 == GNUNET_CRYPTO_symmetric_decrypt (prc->data,
1069 prc->size,
1070 &skey,
1071 &iv,
1072 pt))
1073 { 1065 {
1074 GNUNET_break (0); 1066 GNUNET_break (0);
1075 dc->emsg = GNUNET_strdup (_("internal error decrypting content")); 1067 dc->emsg = GNUNET_strdup (_ ("internal error decrypting content"));
1076 goto signal_error; 1068 goto signal_error;
1077 } 1069 }
1078 off = 1070 off = compute_disk_offset (GNUNET_ntohll (dc->uri->data.chk.file_length),
1079 compute_disk_offset (GNUNET_ntohll (dc->uri->data.chk.file_length), 1071 dr->offset,
1080 dr->offset, 1072 dr->depth);
1081 dr->depth);
1082 /* save to disk */ 1073 /* save to disk */
1083 if ((GNUNET_YES == prc->do_store) && 1074 if ((GNUNET_YES == prc->do_store) &&
1084 ((NULL != dc->filename) || (is_recursive_download (dc))) && 1075 ((NULL != dc->filename) || (is_recursive_download (dc))) &&
1085 ((dr->depth == dc->treedepth) || 1076 ((dr->depth == dc->treedepth) ||
1086 (0 == (dc->options & GNUNET_FS_DOWNLOAD_NO_TEMPORARIES)))) 1077 (0 == (dc->options & GNUNET_FS_DOWNLOAD_NO_TEMPORARIES))))
1087 { 1078 {
1088 fh = GNUNET_DISK_file_open (NULL != dc->filename 1079 fh = GNUNET_DISK_file_open (NULL != dc->filename ? dc->filename
1089 ? dc->filename : dc->temp_filename, 1080 : dc->temp_filename,
1090 GNUNET_DISK_OPEN_READWRITE | 1081 GNUNET_DISK_OPEN_READWRITE |
1091 GNUNET_DISK_OPEN_CREATE, 1082 GNUNET_DISK_OPEN_CREATE,
1092 GNUNET_DISK_PERM_USER_READ | 1083 GNUNET_DISK_PERM_USER_READ |
1093 GNUNET_DISK_PERM_USER_WRITE | 1084 GNUNET_DISK_PERM_USER_WRITE |
1094 GNUNET_DISK_PERM_GROUP_READ | 1085 GNUNET_DISK_PERM_GROUP_READ |
1095 GNUNET_DISK_PERM_OTHER_READ); 1086 GNUNET_DISK_PERM_OTHER_READ);
1096 if (NULL == fh) 1087 if (NULL == fh)
1097 { 1088 {
1098 GNUNET_asprintf (&dc->emsg, 1089 GNUNET_asprintf (&dc->emsg,
1099 _("Download failed: could not open file `%s': %s"), 1090 _ ("Download failed: could not open file `%s': %s"),
1100 dc->filename, STRERROR (errno)); 1091 dc->filename,
1092 strerror (errno));
1101 goto signal_error; 1093 goto signal_error;
1102 } 1094 }
1103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1095 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1104 "Saving decrypted block to disk at offset %llu\n", 1096 "Saving decrypted block to disk at offset %llu\n",
1105 (unsigned long long) off); 1097 (unsigned long long) off);
1106 if ((off != GNUNET_DISK_file_seek (fh, 1098 if ((off != GNUNET_DISK_file_seek (fh, off, GNUNET_DISK_SEEK_SET)))
1107 off,
1108 GNUNET_DISK_SEEK_SET)))
1109 { 1099 {
1110 GNUNET_asprintf (&dc->emsg, 1100 GNUNET_asprintf (&dc->emsg,
1111 _("Failed to seek to offset %llu in file `%s': %s"), 1101 _ ("Failed to seek to offset %llu in file `%s': %s"),
1112 (unsigned long long) off, 1102 (unsigned long long) off,
1113 dc->filename, 1103 dc->filename,
1114 STRERROR (errno)); 1104 strerror (errno));
1115 goto signal_error; 1105 goto signal_error;
1116 } 1106 }
1117 if (prc->size != GNUNET_DISK_file_write (fh, pt, prc->size)) 1107 if (prc->size != GNUNET_DISK_file_write (fh, pt, prc->size))
1118 { 1108 {
1119 GNUNET_asprintf (&dc->emsg, 1109 GNUNET_asprintf (
1120 _("Failed to write block of %u bytes at offset %llu in file `%s': %s"), 1110 &dc->emsg,
1121 (unsigned int) prc->size, 1111 _ ("Failed to write block of %u bytes at offset %llu in file `%s': %s"),
1122 (unsigned long long) off, 1112 (unsigned int) prc->size,
1123 dc->filename, 1113 (unsigned long long) off,
1124 STRERROR (errno)); 1114 dc->filename,
1115 strerror (errno));
1125 goto signal_error; 1116 goto signal_error;
1126 } 1117 }
1127 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh)); 1118 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh));
@@ -1153,8 +1144,11 @@ process_result_with_request (void *cls,
1153 * says it is a directory or if no meta data is given AND filename 1144 * says it is a directory or if no meta data is given AND filename
1154 * ends in '.gnd' (top-level case) */ 1145 * ends in '.gnd' (top-level case) */
1155 if (is_recursive_download (dc)) 1146 if (is_recursive_download (dc))
1156 GNUNET_FS_directory_list_contents (prc->size, pt, off, 1147 GNUNET_FS_directory_list_contents (prc->size,
1157 &trigger_recursive_download, dc); 1148 pt,
1149 off,
1150 &trigger_recursive_download,
1151 dc);
1158 } 1152 }
1159 GNUNET_assert (dc->completed <= dc->length); 1153 GNUNET_assert (dc->completed <= dc->length);
1160 dr->state = BRS_DOWNLOAD_DOWN; 1154 dr->state = BRS_DOWNLOAD_DOWN;
@@ -1164,13 +1158,15 @@ process_result_with_request (void *cls,
1164 pi.value.download.specifics.progress.data_len = prc->size; 1158 pi.value.download.specifics.progress.data_len = prc->size;
1165 pi.value.download.specifics.progress.depth = dr->depth; 1159 pi.value.download.specifics.progress.depth = dr->depth;
1166 pi.value.download.specifics.progress.respect_offered = prc->respect_offered; 1160 pi.value.download.specifics.progress.respect_offered = prc->respect_offered;
1167 pi.value.download.specifics.progress.num_transmissions = prc->num_transmissions; 1161 pi.value.download.specifics.progress.num_transmissions =
1168 if (prc->last_transmission.abs_value_us != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) 1162 prc->num_transmissions;
1169 pi.value.download.specifics.progress.block_download_duration 1163 if (prc->last_transmission.abs_value_us !=
1170 = GNUNET_TIME_absolute_get_duration (prc->last_transmission); 1164 GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
1165 pi.value.download.specifics.progress.block_download_duration =
1166 GNUNET_TIME_absolute_get_duration (prc->last_transmission);
1171 else 1167 else
1172 pi.value.download.specifics.progress.block_download_duration 1168 pi.value.download.specifics.progress.block_download_duration =
1173 = GNUNET_TIME_UNIT_ZERO; /* found locally */ 1169 GNUNET_TIME_UNIT_ZERO; /* found locally */
1174 GNUNET_FS_download_make_status_ (&pi, dc); 1170 GNUNET_FS_download_make_status_ (&pi, dc);
1175 if (0 == dr->depth) 1171 if (0 == dr->depth)
1176 propagate_up (dr); 1172 propagate_up (dr);
@@ -1180,15 +1176,15 @@ process_result_with_request (void *cls,
1180 /* download completed, signal */ 1176 /* download completed, signal */
1181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1182 "Download completed, truncating file to desired length %llu\n", 1178 "Download completed, truncating file to desired length %llu\n",
1183 (unsigned long long) GNUNET_ntohll (dc->uri->data. 1179 (unsigned long long) GNUNET_ntohll (
1184 chk.file_length)); 1180 dc->uri->data.chk.file_length));
1185 /* truncate file to size (since we store IBlocks at the end) */ 1181 /* truncate file to size (since we store IBlocks at the end) */
1186 if (NULL != dc->filename) 1182 if (NULL != dc->filename)
1187 { 1183 {
1188 if (0 != 1184 if (0 != truncate (dc->filename,
1189 TRUNCATE (dc->filename, 1185 GNUNET_ntohll (dc->uri->data.chk.file_length)))
1190 GNUNET_ntohll (dc->uri->data.chk.file_length))) 1186 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
1191 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "truncate", 1187 "truncate",
1192 dc->filename); 1188 dc->filename);
1193 } 1189 }
1194 GNUNET_assert (0 == dr->depth); 1190 GNUNET_assert (0 == dr->depth);
@@ -1201,9 +1197,11 @@ process_result_with_request (void *cls,
1201 return GNUNET_YES; 1197 return GNUNET_YES;
1202 } 1198 }
1203 1199
1204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1200 GNUNET_log (
1205 "Triggering downloads of children (this block was at depth %u and offset %llu)\n", 1201 GNUNET_ERROR_TYPE_DEBUG,
1206 dr->depth, (unsigned long long) dr->offset); 1202 "Triggering downloads of children (this block was at depth %u and offset %llu)\n",
1203 dr->depth,
1204 (unsigned long long) dr->offset);
1207 GNUNET_assert (0 == (prc->size % sizeof (struct ContentHashKey))); 1205 GNUNET_assert (0 == (prc->size % sizeof (struct ContentHashKey)));
1208 chkarr = (struct ContentHashKey *) pt; 1206 chkarr = (struct ContentHashKey *) pt;
1209 for (i = dr->num_children - 1; i >= 0; i--) 1207 for (i = dr->num_children - 1; i >= 0; i--)
@@ -1214,16 +1212,17 @@ process_result_with_request (void *cls,
1214 case BRS_INIT: 1212 case BRS_INIT:
1215 if ((drc->chk_idx + 1) * sizeof (struct ContentHashKey) > prc->size) 1213 if ((drc->chk_idx + 1) * sizeof (struct ContentHashKey) > prc->size)
1216 { 1214 {
1217 /* 'chkarr' does not have enough space for this chk_idx; 1215 /* 'chkarr' does not have enough space for this chk_idx;
1218 internal error! */ 1216 internal error! */
1219 GNUNET_break (0); GNUNET_assert (0); 1217 GNUNET_break (0);
1220 dc->emsg = GNUNET_strdup (_("internal error decoding tree")); 1218 GNUNET_assert (0);
1221 goto signal_error; 1219 dc->emsg = GNUNET_strdup (_ ("internal error decoding tree"));
1220 goto signal_error;
1222 } 1221 }
1223 drc->chk = chkarr[drc->chk_idx]; 1222 drc->chk = chkarr[drc->chk_idx];
1224 drc->state = BRS_CHK_SET; 1223 drc->state = BRS_CHK_SET;
1225 if (GNUNET_YES == dc->issue_requests) 1224 if (GNUNET_YES == dc->issue_requests)
1226 schedule_block_download (dc, drc); 1225 schedule_block_download (dc, drc);
1227 break; 1226 break;
1228 case BRS_RECONSTRUCT_DOWN: 1227 case BRS_RECONSTRUCT_DOWN:
1229 GNUNET_assert (0); 1228 GNUNET_assert (0);
@@ -1282,8 +1281,7 @@ signal_error:
1282 * @param msg message received 1281 * @param msg message received
1283 */ 1282 */
1284static int 1283static int
1285check_put (void *cls, 1284check_put (void *cls, const struct ClientPutMessage *cm)
1286 const struct ClientPutMessage *cm)
1287{ 1285{
1288 /* any varsize length is OK */ 1286 /* any varsize length is OK */
1289 return GNUNET_OK; 1287 return GNUNET_OK;
@@ -1298,8 +1296,7 @@ check_put (void *cls,
1298 * @param msg message received 1296 * @param msg message received
1299 */ 1297 */
1300static void 1298static void
1301handle_put (void *cls, 1299handle_put (void *cls, const struct ClientPutMessage *cm)
1302 const struct ClientPutMessage *cm)
1303{ 1300{
1304 struct GNUNET_FS_DownloadContext *dc = cls; 1301 struct GNUNET_FS_DownloadContext *dc = cls;
1305 uint16_t msize = ntohs (cm->header.size) - sizeof (*cm); 1302 uint16_t msize = ntohs (cm->header.size) - sizeof (*cm);
@@ -1313,9 +1310,7 @@ handle_put (void *cls,
1313 prc.do_store = GNUNET_YES; 1310 prc.do_store = GNUNET_YES;
1314 prc.respect_offered = ntohl (cm->respect_offered); 1311 prc.respect_offered = ntohl (cm->respect_offered);
1315 prc.num_transmissions = ntohl (cm->num_transmissions); 1312 prc.num_transmissions = ntohl (cm->num_transmissions);
1316 GNUNET_CRYPTO_hash (prc.data, 1313 GNUNET_CRYPTO_hash (prc.data, msize, &prc.query);
1317 msize,
1318 &prc.query);
1319 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1320 "Received result for query `%s' from FS service\n", 1315 "Received result for query `%s' from FS service\n",
1321 GNUNET_h2s (&prc.query)); 1316 GNUNET_h2s (&prc.query));
@@ -1335,8 +1330,7 @@ handle_put (void *cls,
1335 * @param error error code 1330 * @param error error code
1336 */ 1331 */
1337static void 1332static void
1338download_mq_error_handler (void *cls, 1333download_mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
1339 enum GNUNET_MQ_Error error)
1340{ 1334{
1341 struct GNUNET_FS_DownloadContext *dc = cls; 1335 struct GNUNET_FS_DownloadContext *dc = cls;
1342 1336
@@ -1360,13 +1354,12 @@ static void
1360do_reconnect (void *cls) 1354do_reconnect (void *cls)
1361{ 1355{
1362 struct GNUNET_FS_DownloadContext *dc = cls; 1356 struct GNUNET_FS_DownloadContext *dc = cls;
1363 struct GNUNET_MQ_MessageHandler handlers[] = { 1357 struct GNUNET_MQ_MessageHandler handlers[] =
1364 GNUNET_MQ_hd_var_size (put, 1358 {GNUNET_MQ_hd_var_size (put,
1365 GNUNET_MESSAGE_TYPE_FS_PUT, 1359 GNUNET_MESSAGE_TYPE_FS_PUT,
1366 struct ClientPutMessage, 1360 struct ClientPutMessage,
1367 dc), 1361 dc),
1368 GNUNET_MQ_handler_end () 1362 GNUNET_MQ_handler_end ()};
1369 };
1370 1363
1371 dc->task = NULL; 1364 dc->task = NULL;
1372 dc->mq = GNUNET_CLIENT_connect (dc->h->cfg, 1365 dc->mq = GNUNET_CLIENT_connect (dc->h->cfg,
@@ -1377,13 +1370,12 @@ do_reconnect (void *cls)
1377 if (NULL == dc->mq) 1370 if (NULL == dc->mq)
1378 { 1371 {
1379 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1372 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1380 "Connecting to `%s'-service failed, will try again.\n", "FS"); 1373 "Connecting to `%s'-service failed, will try again.\n",
1374 "FS");
1381 try_reconnect (dc); 1375 try_reconnect (dc);
1382 return; 1376 return;
1383 } 1377 }
1384 GNUNET_CONTAINER_multihashmap_iterate (dc->active, 1378 GNUNET_CONTAINER_multihashmap_iterate (dc->active, &retry_entry, dc);
1385 &retry_entry,
1386 dc);
1387} 1379}
1388 1380
1389 1381
@@ -1411,13 +1403,11 @@ try_reconnect (struct GNUNET_FS_DownloadContext *dc)
1411 1403
1412 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1404 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1413 "Will try to reconnect in %s\n", 1405 "Will try to reconnect in %s\n",
1414 GNUNET_STRINGS_relative_time_to_string (dc->reconnect_backoff, 1406 GNUNET_STRINGS_relative_time_to_string (dc->reconnect_backoff,
1415 GNUNET_YES)); 1407 GNUNET_YES));
1416 GNUNET_break (NULL != dc->job_queue); 1408 GNUNET_break (NULL != dc->job_queue);
1417 dc->task = 1409 dc->task =
1418 GNUNET_SCHEDULER_add_delayed (dc->reconnect_backoff, 1410 GNUNET_SCHEDULER_add_delayed (dc->reconnect_backoff, &do_reconnect, dc);
1419 &do_reconnect,
1420 dc);
1421} 1411}
1422 1412
1423 1413
@@ -1437,11 +1427,9 @@ activate_fs_download (void *cls)
1437 GNUNET_assert (NULL != dc->active); 1427 GNUNET_assert (NULL != dc->active);
1438 do_reconnect (dc); 1428 do_reconnect (dc);
1439 if (NULL != dc->mq) 1429 if (NULL != dc->mq)
1440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1430 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download activated\n");
1441 "Download activated\n");
1442 pi.status = GNUNET_FS_STATUS_DOWNLOAD_ACTIVE; 1431 pi.status = GNUNET_FS_STATUS_DOWNLOAD_ACTIVE;
1443 GNUNET_FS_download_make_status_ (&pi, 1432 GNUNET_FS_download_make_status_ (&pi, dc);
1444 dc);
1445} 1433}
1446 1434
1447 1435
@@ -1456,16 +1444,14 @@ deactivate_fs_download (void *cls)
1456 struct GNUNET_FS_DownloadContext *dc = cls; 1444 struct GNUNET_FS_DownloadContext *dc = cls;
1457 struct GNUNET_FS_ProgressInfo pi; 1445 struct GNUNET_FS_ProgressInfo pi;
1458 1446
1459 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1447 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download deactivated\n");
1460 "Download deactivated\n");
1461 if (NULL != dc->mq) 1448 if (NULL != dc->mq)
1462 { 1449 {
1463 GNUNET_MQ_destroy (dc->mq); 1450 GNUNET_MQ_destroy (dc->mq);
1464 dc->mq = NULL; 1451 dc->mq = NULL;
1465 } 1452 }
1466 pi.status = GNUNET_FS_STATUS_DOWNLOAD_INACTIVE; 1453 pi.status = GNUNET_FS_STATUS_DOWNLOAD_INACTIVE;
1467 GNUNET_FS_download_make_status_ (&pi, 1454 GNUNET_FS_download_make_status_ (&pi, dc);
1468 dc);
1469} 1455}
1470 1456
1471 1457
@@ -1490,8 +1476,8 @@ deactivate_fs_download (void *cls)
1490 */ 1476 */
1491static struct DownloadRequest * 1477static struct DownloadRequest *
1492create_download_request (struct DownloadRequest *parent, 1478create_download_request (struct DownloadRequest *parent,
1493 unsigned int chk_idx, 1479 unsigned int chk_idx,
1494 unsigned int depth, 1480 unsigned int depth,
1495 uint64_t dr_offset, 1481 uint64_t dr_offset,
1496 uint64_t file_start_offset, 1482 uint64_t file_start_offset,
1497 uint64_t desired_length) 1483 uint64_t desired_length)
@@ -1523,36 +1509,35 @@ create_download_request (struct DownloadRequest *parent,
1523 } 1509 }
1524 1510
1525 /* calculate index of last block at this level that is interesting (rounded up) */ 1511 /* calculate index of last block at this level that is interesting (rounded up) */
1526 dr->num_children = (file_start_offset + desired_length - dr_offset) / child_block_size; 1512 dr->num_children =
1513 (file_start_offset + desired_length - dr_offset) / child_block_size;
1527 if (dr->num_children * child_block_size < 1514 if (dr->num_children * child_block_size <
1528 file_start_offset + desired_length - dr_offset) 1515 file_start_offset + desired_length - dr_offset)
1529 dr->num_children++; /* round up */ 1516 dr->num_children++; /* round up */
1530 GNUNET_assert (dr->num_children > head_skip); 1517 GNUNET_assert (dr->num_children > head_skip);
1531 dr->num_children -= head_skip; 1518 dr->num_children -= head_skip;
1532 if (dr->num_children > CHK_PER_INODE) 1519 if (dr->num_children > CHK_PER_INODE)
1533 dr->num_children = CHK_PER_INODE; /* cap at max */ 1520 dr->num_children = CHK_PER_INODE; /* cap at max */
1534 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1535 "Block at offset %llu and depth %u has %u children\n", 1522 "Block at offset %llu and depth %u has %u children\n",
1536 (unsigned long long) dr_offset, 1523 (unsigned long long) dr_offset,
1537 depth, 1524 depth,
1538 dr->num_children); 1525 dr->num_children);
1539 1526
1540 /* now we can get the total number of *interesting* children for this block */ 1527 /* now we can get the total number of *interesting* children for this block */
1541 1528
1542 /* why else would we have gotten here to begin with? (that'd be a bad logic error) */ 1529 /* why else would we have gotten here to begin with? (that'd be a bad logic error) */
1543 GNUNET_assert (dr->num_children > 0); 1530 GNUNET_assert (dr->num_children > 0);
1544 1531
1545 dr->children = 1532 dr->children = GNUNET_new_array (dr->num_children, struct DownloadRequest *);
1546 GNUNET_new_array (dr->num_children,
1547 struct DownloadRequest *);
1548 for (i = 0; i < dr->num_children; i++) 1533 for (i = 0; i < dr->num_children; i++)
1549 { 1534 {
1550 dr->children[i] = 1535 dr->children[i] =
1551 create_download_request (dr, 1536 create_download_request (dr,
1552 i + head_skip, 1537 i + head_skip,
1553 depth - 1, 1538 depth - 1,
1554 dr_offset + (i + head_skip) * child_block_size, 1539 dr_offset + (i + head_skip) * child_block_size,
1555 file_start_offset, 1540 file_start_offset,
1556 desired_length); 1541 desired_length);
1557 } 1542 }
1558 return dr; 1543 return dr;
@@ -1583,8 +1568,7 @@ reconstruct_cont (void *cls)
1583 } 1568 }
1584 /* start "normal" download */ 1569 /* start "normal" download */
1585 dc->issue_requests = GNUNET_YES; 1570 dc->issue_requests = GNUNET_YES;
1586 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1571 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting normal download\n");
1587 "Starting normal download\n");
1588 schedule_block_download (dc, dc->top_request); 1572 schedule_block_download (dc, dc->top_request);
1589} 1573}
1590 1574
@@ -1646,29 +1630,29 @@ reconstruct_cb (void *cls,
1646 if (chld < dr->children[0]->chk_idx) 1630 if (chld < dr->children[0]->chk_idx)
1647 { 1631 {
1648 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1632 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1649 "Block %u < %u irrelevant for our range\n", 1633 "Block %u < %u irrelevant for our range\n",
1650 chld, 1634 chld,
1651 dr->children[0]->chk_idx); 1635 dr->children[0]->chk_idx);
1652 dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, 1636 dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc);
1653 dc);
1654 return; /* irrelevant block */ 1637 return; /* irrelevant block */
1655 } 1638 }
1656 if (chld > dr->children[dr->num_children-1]->chk_idx) 1639 if (chld > dr->children[dr->num_children - 1]->chk_idx)
1657 { 1640 {
1658 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1641 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1659 "Block %u > %u irrelevant for our range\n", 1642 "Block %u > %u irrelevant for our range\n",
1660 chld, 1643 chld,
1661 dr->children[dr->num_children-1]->chk_idx); 1644 dr->children[dr->num_children - 1]->chk_idx);
1662 dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc); 1645 dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc);
1663 return; /* irrelevant block */ 1646 return; /* irrelevant block */
1664 } 1647 }
1665 dr = dr->children[chld - dr->children[0]->chk_idx]; 1648 dr = dr->children[chld - dr->children[0]->chk_idx];
1666 } 1649 }
1667 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1650 GNUNET_log (
1668 "Matched TE block with request at offset %llu and depth %u in state %d\n", 1651 GNUNET_ERROR_TYPE_DEBUG,
1669 (unsigned long long) dr->offset, 1652 "Matched TE block with request at offset %llu and depth %u in state %d\n",
1670 dr->depth, 1653 (unsigned long long) dr->offset,
1671 dr->state); 1654 dr->depth,
1655 dr->state);
1672 /* FIXME: this code needs more testing and might 1656 /* FIXME: this code needs more testing and might
1673 need to handle more states... */ 1657 need to handle more states... */
1674 switch (dr->state) 1658 switch (dr->state)
@@ -1684,10 +1668,11 @@ reconstruct_cb (void *cls,
1684 case BRS_CHK_SET: 1668 case BRS_CHK_SET:
1685 if (0 == memcmp (chk, &dr->chk, sizeof (struct ContentHashKey))) 1669 if (0 == memcmp (chk, &dr->chk, sizeof (struct ContentHashKey)))
1686 { 1670 {
1687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1671 GNUNET_log (
1688 "Reconstruction succeeded, can use block at offset %llu, depth %u\n", 1672 GNUNET_ERROR_TYPE_DEBUG,
1689 (unsigned long long) offset, 1673 "Reconstruction succeeded, can use block at offset %llu, depth %u\n",
1690 depth); 1674 (unsigned long long) offset,
1675 depth);
1691 /* block matches, hence tree below matches; 1676 /* block matches, hence tree below matches;
1692 * this request is done! */ 1677 * this request is done! */
1693 dr->state = BRS_DOWNLOAD_UP; 1678 dr->state = BRS_DOWNLOAD_UP;
@@ -1707,32 +1692,34 @@ reconstruct_cb (void *cls,
1707 pi.value.download.specifics.progress.data_len = 0; 1692 pi.value.download.specifics.progress.data_len = 0;
1708 pi.value.download.specifics.progress.depth = 0; 1693 pi.value.download.specifics.progress.depth = 0;
1709 pi.value.download.specifics.progress.respect_offered = 0; 1694 pi.value.download.specifics.progress.respect_offered = 0;
1710 pi.value.download.specifics.progress.block_download_duration = GNUNET_TIME_UNIT_ZERO; 1695 pi.value.download.specifics.progress.block_download_duration =
1696 GNUNET_TIME_UNIT_ZERO;
1711 GNUNET_FS_download_make_status_ (&pi, dc); 1697 GNUNET_FS_download_make_status_ (&pi, dc);
1712 /* FIXME: duplicated code from 'process_result_with_request - refactor */ 1698 /* FIXME: duplicated code from 'process_result_with_request - refactor */
1713 if (dc->completed == dc->length) 1699 if (dc->completed == dc->length)
1714 { 1700 {
1715 /* download completed, signal */ 1701 /* download completed, signal */
1716 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1702 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1717 "Download completed, truncating file to desired length %llu\n", 1703 "Download completed, truncating file to desired length %llu\n",
1718 (unsigned long long) GNUNET_ntohll (dc->uri->data. 1704 (unsigned long long) GNUNET_ntohll (
1719 chk.file_length)); 1705 dc->uri->data.chk.file_length));
1720 /* truncate file to size (since we store IBlocks at the end) */ 1706 /* truncate file to size (since we store IBlocks at the end) */
1721 if (NULL != dc->filename) 1707 if (NULL != dc->filename)
1722 { 1708 {
1723 if (0 != 1709 if (0 != truncate (dc->filename,
1724 TRUNCATE (dc->filename, 1710 GNUNET_ntohll (dc->uri->data.chk.file_length)))
1725 GNUNET_ntohll (dc->uri->data.chk.file_length))) 1711 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
1726 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "truncate", 1712 "truncate",
1727 dc->filename); 1713 dc->filename);
1728 } 1714 }
1729 } 1715 }
1730 } 1716 }
1731 else 1717 else
1732 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1718 GNUNET_log (
1733 "Reconstruction failed, need to download block at offset %llu, depth %u\n", 1719 GNUNET_ERROR_TYPE_DEBUG,
1734 (unsigned long long) offset, 1720 "Reconstruction failed, need to download block at offset %llu, depth %u\n",
1735 depth); 1721 (unsigned long long) offset,
1722 depth);
1736 break; 1723 break;
1737 case BRS_DOWNLOAD_DOWN: 1724 case BRS_DOWNLOAD_DOWN:
1738 break; 1725 break;
@@ -1744,10 +1731,8 @@ reconstruct_cb (void *cls,
1744 GNUNET_assert (0); 1731 GNUNET_assert (0);
1745 break; 1732 break;
1746 } 1733 }
1747 dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, 1734 dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc);
1748 dc); 1735 if ((dr == dc->top_request) && (dr->state == BRS_DOWNLOAD_UP))
1749 if ( (dr == dc->top_request) &&
1750 (dr->state == BRS_DOWNLOAD_UP) )
1751 check_completed (dc); 1736 check_completed (dc);
1752} 1737}
1753 1738
@@ -1803,8 +1788,7 @@ GNUNET_FS_download_start_task_ (void *cls)
1803 struct GNUNET_FS_ProgressInfo pi; 1788 struct GNUNET_FS_ProgressInfo pi;
1804 struct GNUNET_DISK_FileHandle *fh; 1789 struct GNUNET_DISK_FileHandle *fh;
1805 1790
1806 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1791 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start task running...\n");
1807 "Start task running...\n");
1808 dc->task = NULL; 1792 dc->task = NULL;
1809 if (0 == dc->length) 1793 if (0 == dc->length)
1810 { 1794 {
@@ -1813,14 +1797,15 @@ GNUNET_FS_download_start_task_ (void *cls)
1813 { 1797 {
1814 fh = GNUNET_DISK_file_open (dc->filename, 1798 fh = GNUNET_DISK_file_open (dc->filename,
1815 GNUNET_DISK_OPEN_READWRITE | 1799 GNUNET_DISK_OPEN_READWRITE |
1816 GNUNET_DISK_OPEN_CREATE | 1800 GNUNET_DISK_OPEN_CREATE |
1817 ((0 == 1801 ((0 ==
1818 GNUNET_FS_uri_chk_get_file_size (dc->uri)) ? 1802 GNUNET_FS_uri_chk_get_file_size (dc->uri))
1819 GNUNET_DISK_OPEN_TRUNCATE : 0), 1803 ? GNUNET_DISK_OPEN_TRUNCATE
1804 : 0),
1820 GNUNET_DISK_PERM_USER_READ | 1805 GNUNET_DISK_PERM_USER_READ |
1821 GNUNET_DISK_PERM_USER_WRITE | 1806 GNUNET_DISK_PERM_USER_WRITE |
1822 GNUNET_DISK_PERM_GROUP_READ | 1807 GNUNET_DISK_PERM_GROUP_READ |
1823 GNUNET_DISK_PERM_OTHER_READ); 1808 GNUNET_DISK_PERM_OTHER_READ);
1824 GNUNET_DISK_file_close (fh); 1809 GNUNET_DISK_file_close (fh);
1825 } 1810 }
1826 GNUNET_FS_download_sync_ (dc); 1811 GNUNET_FS_download_sync_ (dc);
@@ -1834,13 +1819,16 @@ GNUNET_FS_download_start_task_ (void *cls)
1834 return; 1819 return;
1835 if (NULL == dc->top_request) 1820 if (NULL == dc->top_request)
1836 { 1821 {
1837 dc->top_request = 1822 dc->top_request = create_download_request (NULL,
1838 create_download_request (NULL, 0, dc->treedepth - 1, 0, dc->offset, 1823 0,
1839 dc->length); 1824 dc->treedepth - 1,
1825 0,
1826 dc->offset,
1827 dc->length);
1840 dc->top_request->state = BRS_CHK_SET; 1828 dc->top_request->state = BRS_CHK_SET;
1841 dc->top_request->chk = 1829 dc->top_request->chk = (dc->uri->type == GNUNET_FS_URI_CHK)
1842 (dc->uri->type == 1830 ? dc->uri->data.chk.chk
1843 GNUNET_FS_URI_CHK) ? dc->uri->data.chk.chk : dc->uri->data.loc.fi.chk; 1831 : dc->uri->data.loc.fi.chk;
1844 /* signal start */ 1832 /* signal start */
1845 GNUNET_FS_download_sync_ (dc); 1833 GNUNET_FS_download_sync_ (dc);
1846 if (NULL != dc->search) 1834 if (NULL != dc->search)
@@ -1852,23 +1840,24 @@ GNUNET_FS_download_start_task_ (void *cls)
1852 GNUNET_FS_download_start_downloading_ (dc); 1840 GNUNET_FS_download_start_downloading_ (dc);
1853 /* attempt reconstruction from disk */ 1841 /* attempt reconstruction from disk */
1854 if (GNUNET_YES == GNUNET_DISK_file_test (dc->filename)) 1842 if (GNUNET_YES == GNUNET_DISK_file_test (dc->filename))
1855 dc->rfh = 1843 dc->rfh = GNUNET_DISK_file_open (dc->filename,
1856 GNUNET_DISK_file_open (dc->filename, GNUNET_DISK_OPEN_READ, 1844 GNUNET_DISK_OPEN_READ,
1857 GNUNET_DISK_PERM_NONE); 1845 GNUNET_DISK_PERM_NONE);
1858 if (dc->top_request->state == BRS_CHK_SET) 1846 if (dc->top_request->state == BRS_CHK_SET)
1859 { 1847 {
1860 if (NULL != dc->rfh) 1848 if (NULL != dc->rfh)
1861 { 1849 {
1862 /* first, try top-down */ 1850 /* first, try top-down */
1863 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1851 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1864 "Trying top-down reconstruction for `%s'\n", dc->filename); 1852 "Trying top-down reconstruction for `%s'\n",
1853 dc->filename);
1865 try_top_down_reconstruction (dc, dc->top_request); 1854 try_top_down_reconstruction (dc, dc->top_request);
1866 switch (dc->top_request->state) 1855 switch (dc->top_request->state)
1867 { 1856 {
1868 case BRS_CHK_SET: 1857 case BRS_CHK_SET:
1869 break; /* normal */ 1858 break; /* normal */
1870 case BRS_DOWNLOAD_DOWN: 1859 case BRS_DOWNLOAD_DOWN:
1871 break; /* normal, some blocks already down */ 1860 break; /* normal, some blocks already down */
1872 case BRS_DOWNLOAD_UP: 1861 case BRS_DOWNLOAD_UP:
1873 /* already done entirely, party! */ 1862 /* already done entirely, party! */
1874 if (NULL != dc->rfh) 1863 if (NULL != dc->rfh)
@@ -1880,7 +1869,7 @@ GNUNET_FS_download_start_task_ (void *cls)
1880 } 1869 }
1881 return; 1870 return;
1882 case BRS_ERROR: 1871 case BRS_ERROR:
1883 GNUNET_asprintf (&dc->emsg, _("Invalid URI")); 1872 GNUNET_asprintf (&dc->emsg, _ ("Invalid URI"));
1884 GNUNET_FS_download_sync_ (dc); 1873 GNUNET_FS_download_sync_ (dc);
1885 pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; 1874 pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR;
1886 pi.value.download.specifics.error.message = dc->emsg; 1875 pi.value.download.specifics.error.message = dc->emsg;
@@ -1896,11 +1885,11 @@ GNUNET_FS_download_start_task_ (void *cls)
1896 if ((GNUNET_FS_uri_chk_get_file_size (dc->uri) <= MAX_INLINE_SIZE) && 1885 if ((GNUNET_FS_uri_chk_get_file_size (dc->uri) <= MAX_INLINE_SIZE) &&
1897 (NULL != dc->meta)) 1886 (NULL != dc->meta))
1898 { 1887 {
1899 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1888 GNUNET_log (
1900 "Trying to find embedded meta data for download of size %llu with %u bytes MD\n", 1889 GNUNET_ERROR_TYPE_DEBUG,
1901 (unsigned long long) GNUNET_FS_uri_chk_get_file_size (dc->uri), 1890 "Trying to find embedded meta data for download of size %llu with %u bytes MD\n",
1902 (unsigned int) 1891 (unsigned long long) GNUNET_FS_uri_chk_get_file_size (dc->uri),
1903 GNUNET_CONTAINER_meta_data_get_serialized_size (dc->meta)); 1892 (unsigned int) GNUNET_CONTAINER_meta_data_get_serialized_size (dc->meta));
1904 GNUNET_CONTAINER_meta_data_iterate (dc->meta, &match_full_data, dc); 1893 GNUNET_CONTAINER_meta_data_iterate (dc->meta, &match_full_data, dc);
1905 if (BRS_DOWNLOAD_UP == dc->top_request->state) 1894 if (BRS_DOWNLOAD_UP == dc->top_request->state)
1906 { 1895 {
@@ -1911,24 +1900,24 @@ GNUNET_FS_download_start_task_ (void *cls)
1911 GNUNET_DISK_file_close (dc->rfh); 1900 GNUNET_DISK_file_close (dc->rfh);
1912 dc->rfh = NULL; 1901 dc->rfh = NULL;
1913 } 1902 }
1914 return; /* finished, status update was already done for us */ 1903 return; /* finished, status update was already done for us */
1915 } 1904 }
1916 } 1905 }
1917 if (NULL != dc->rfh) 1906 if (NULL != dc->rfh)
1918 { 1907 {
1919 /* finally, actually run bottom-up */ 1908 /* finally, actually run bottom-up */
1920 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1909 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1921 "Trying bottom-up reconstruction of file `%s'\n", dc->filename); 1910 "Trying bottom-up reconstruction of file `%s'\n",
1911 dc->filename);
1922 dc->te = 1912 dc->te =
1923 GNUNET_FS_tree_encoder_create (dc->h, 1913 GNUNET_FS_tree_encoder_create (dc->h,
1924 GNUNET_FS_uri_chk_get_file_size (dc->uri), 1914 GNUNET_FS_uri_chk_get_file_size (dc->uri),
1925 dc, 1915 dc,
1926 &fh_reader, 1916 &fh_reader,
1927 &reconstruct_cb, 1917 &reconstruct_cb,
1928 NULL, 1918 NULL,
1929 &reconstruct_cont); 1919 &reconstruct_cont);
1930 dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, 1920 dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc);
1931 dc);
1932 } 1921 }
1933 else 1922 else
1934 { 1923 {
@@ -1968,7 +1957,8 @@ GNUNET_FS_download_signal_suspend_ (void *cls)
1968 dc->job_queue = NULL; 1957 dc->job_queue = NULL;
1969 } 1958 }
1970 if (NULL != dc->parent) 1959 if (NULL != dc->parent)
1971 GNUNET_CONTAINER_DLL_remove (dc->parent->child_head, dc->parent->child_tail, 1960 GNUNET_CONTAINER_DLL_remove (dc->parent->child_head,
1961 dc->parent->child_tail,
1972 dc); 1962 dc);
1973 if (NULL != dc->task) 1963 if (NULL != dc->task)
1974 { 1964 {
@@ -2024,14 +2014,14 @@ GNUNET_FS_download_signal_suspend_ (void *cls)
2024 */ 2014 */
2025struct GNUNET_FS_DownloadContext * 2015struct GNUNET_FS_DownloadContext *
2026create_download_context (struct GNUNET_FS_Handle *h, 2016create_download_context (struct GNUNET_FS_Handle *h,
2027 const struct GNUNET_FS_Uri *uri, 2017 const struct GNUNET_FS_Uri *uri,
2028 const struct GNUNET_CONTAINER_MetaData *meta, 2018 const struct GNUNET_CONTAINER_MetaData *meta,
2029 const char *filename, 2019 const char *filename,
2030 const char *tempname, 2020 const char *tempname,
2031 uint64_t offset, 2021 uint64_t offset,
2032 uint64_t length, 2022 uint64_t length,
2033 uint32_t anonymity, 2023 uint32_t anonymity,
2034 enum GNUNET_FS_DownloadOptions options, 2024 enum GNUNET_FS_DownloadOptions options,
2035 void *cctx) 2025 void *cctx)
2036{ 2026{
2037 struct GNUNET_FS_DownloadContext *dc; 2027 struct GNUNET_FS_DownloadContext *dc;
@@ -2045,10 +2035,10 @@ create_download_context (struct GNUNET_FS_Handle *h,
2045 } 2035 }
2046 dc = GNUNET_new (struct GNUNET_FS_DownloadContext); 2036 dc = GNUNET_new (struct GNUNET_FS_DownloadContext);
2047 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2037 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2048 "Starting download %p, %u bytes at offset %llu\n", 2038 "Starting download %p, %u bytes at offset %llu\n",
2049 dc, 2039 dc,
2050 (unsigned int) length, 2040 (unsigned int) length,
2051 (unsigned long long) offset); 2041 (unsigned long long) offset);
2052 dc->h = h; 2042 dc->h = h;
2053 dc->uri = GNUNET_FS_uri_dup (uri); 2043 dc->uri = GNUNET_FS_uri_dup (uri);
2054 dc->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); 2044 dc->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
@@ -2058,7 +2048,10 @@ create_download_context (struct GNUNET_FS_Handle *h,
2058 { 2048 {
2059 dc->filename = GNUNET_strdup (filename); 2049 dc->filename = GNUNET_strdup (filename);
2060 if (GNUNET_YES == GNUNET_DISK_file_test (filename)) 2050 if (GNUNET_YES == GNUNET_DISK_file_test (filename))
2061 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_size (filename, &dc->old_file_size, GNUNET_YES, GNUNET_YES)); 2051 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_size (filename,
2052 &dc->old_file_size,
2053 GNUNET_YES,
2054 GNUNET_YES));
2062 } 2055 }
2063 if (GNUNET_FS_uri_test_loc (dc->uri)) 2056 if (GNUNET_FS_uri_test_loc (dc->uri))
2064 GNUNET_assert (GNUNET_OK == 2057 GNUNET_assert (GNUNET_OK ==
@@ -2068,9 +2061,10 @@ create_download_context (struct GNUNET_FS_Handle *h,
2068 dc->anonymity = anonymity; 2061 dc->anonymity = anonymity;
2069 dc->options = options; 2062 dc->options = options;
2070 dc->active = 2063 dc->active =
2071 GNUNET_CONTAINER_multihashmap_create (1 + 2 * (length / DBLOCK_SIZE), GNUNET_NO); 2064 GNUNET_CONTAINER_multihashmap_create (1 + 2 * (length / DBLOCK_SIZE),
2065 GNUNET_NO);
2072 dc->treedepth = 2066 dc->treedepth =
2073 GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri)); 2067 GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri));
2074 if ((NULL == filename) && (is_recursive_download (dc))) 2068 if ((NULL == filename) && (is_recursive_download (dc)))
2075 { 2069 {
2076 if (NULL != tempname) 2070 if (NULL != tempname)
@@ -2079,13 +2073,12 @@ create_download_context (struct GNUNET_FS_Handle *h,
2079 dc->temp_filename = GNUNET_DISK_mktemp ("gnunet-directory-download-tmp"); 2073 dc->temp_filename = GNUNET_DISK_mktemp ("gnunet-directory-download-tmp");
2080 } 2074 }
2081 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2075 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2082 "Starting download `%s' of %llu bytes with tree depth %u\n", 2076 "Starting download `%s' of %llu bytes with tree depth %u\n",
2083 filename, 2077 filename,
2084 (unsigned long long) length, 2078 (unsigned long long) length,
2085 dc->treedepth); 2079 dc->treedepth);
2086 GNUNET_assert (NULL == dc->job_queue); 2080 GNUNET_assert (NULL == dc->job_queue);
2087 dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, 2081 dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc);
2088 dc);
2089 return dc; 2082 return dc;
2090} 2083}
2091 2084
@@ -2140,7 +2133,7 @@ GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2140 meta, 2133 meta,
2141 filename, 2134 filename,
2142 tempname, 2135 tempname,
2143 offset, 2136 offset,
2144 length, 2137 length,
2145 anonymity, 2138 anonymity,
2146 options, 2139 options,
@@ -2150,9 +2143,9 @@ GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2150 dc->parent = parent; 2143 dc->parent = parent;
2151 if (NULL != parent) 2144 if (NULL != parent)
2152 GNUNET_CONTAINER_DLL_insert (parent->child_head, parent->child_tail, dc); 2145 GNUNET_CONTAINER_DLL_insert (parent->child_head, parent->child_tail, dc);
2153 else if (0 == (GNUNET_FS_DOWNLOAD_IS_PROBE & options) ) 2146 else if (0 == (GNUNET_FS_DOWNLOAD_IS_PROBE & options))
2154 dc->top = 2147 dc->top =
2155 GNUNET_FS_make_top (dc->h, &GNUNET_FS_download_signal_suspend_, dc); 2148 GNUNET_FS_make_top (dc->h, &GNUNET_FS_download_signal_suspend_, dc);
2156 return dc; 2149 return dc;
2157} 2150}
2158 2151
@@ -2214,7 +2207,7 @@ GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h,
2214 sr->meta, 2207 sr->meta,
2215 filename, 2208 filename,
2216 tempname, 2209 tempname,
2217 offset, 2210 offset,
2218 length, 2211 length,
2219 anonymity, 2212 anonymity,
2220 options, 2213 options,
@@ -2248,19 +2241,19 @@ GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc)
2248 GNUNET_assert (NULL == dc->job_queue); 2241 GNUNET_assert (NULL == dc->job_queue);
2249 GNUNET_assert (NULL == dc->task); 2242 GNUNET_assert (NULL == dc->task);
2250 GNUNET_assert (NULL != dc->active); 2243 GNUNET_assert (NULL != dc->active);
2251 dc->job_queue 2244 dc->job_queue =
2252 = GNUNET_FS_queue_ (dc->h, 2245 GNUNET_FS_queue_ (dc->h,
2253 &activate_fs_download, 2246 &activate_fs_download,
2254 &deactivate_fs_download, 2247 &deactivate_fs_download,
2255 dc, 2248 dc,
2256 (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE, 2249 (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE,
2257 (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) 2250 (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE))
2258 ? GNUNET_FS_QUEUE_PRIORITY_NORMAL 2251 ? GNUNET_FS_QUEUE_PRIORITY_NORMAL
2259 : GNUNET_FS_QUEUE_PRIORITY_PROBE); 2252 : GNUNET_FS_QUEUE_PRIORITY_PROBE);
2260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2261 "Download %p put into queue as job %p\n", 2254 "Download %p put into queue as job %p\n",
2262 dc, 2255 dc,
2263 dc->job_queue); 2256 dc->job_queue);
2264} 2257}
2265 2258
2266/** 2259/**
@@ -2271,7 +2264,7 @@ GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc)
2271void 2264void
2272GNUNET_FS_download_suspend (struct GNUNET_FS_DownloadContext *dc) 2265GNUNET_FS_download_suspend (struct GNUNET_FS_DownloadContext *dc)
2273{ 2266{
2274 deactivate_fs_download(dc); 2267 deactivate_fs_download (dc);
2275} 2268}
2276 2269
2277 2270
@@ -2289,15 +2282,15 @@ GNUNET_FS_download_resume (struct GNUNET_FS_DownloadContext *dc)
2289 GNUNET_FS_download_make_status_ (&pi, dc); 2282 GNUNET_FS_download_make_status_ (&pi, dc);
2290 2283
2291 GNUNET_assert (NULL == dc->task); 2284 GNUNET_assert (NULL == dc->task);
2292 dc->job_queue 2285 dc->job_queue =
2293 = GNUNET_FS_queue_ (dc->h, 2286 GNUNET_FS_queue_ (dc->h,
2294 &activate_fs_download, 2287 &activate_fs_download,
2295 &deactivate_fs_download, 2288 &deactivate_fs_download,
2296 dc, (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE, 2289 dc,
2297 (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) 2290 (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE,
2291 (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE))
2298 ? GNUNET_FS_QUEUE_PRIORITY_NORMAL 2292 ? GNUNET_FS_QUEUE_PRIORITY_NORMAL
2299 : GNUNET_FS_QUEUE_PRIORITY_PROBE); 2293 : GNUNET_FS_QUEUE_PRIORITY_PROBE);
2300
2301} 2294}
2302 2295
2303 2296
@@ -2308,8 +2301,7 @@ GNUNET_FS_download_resume (struct GNUNET_FS_DownloadContext *dc)
2308 * @param do_delete delete files of incomplete downloads 2301 * @param do_delete delete files of incomplete downloads
2309 */ 2302 */
2310void 2303void
2311GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, 2304GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete)
2312 int do_delete)
2313{ 2305{
2314 struct GNUNET_FS_ProgressInfo pi; 2306 struct GNUNET_FS_ProgressInfo pi;
2315 int have_children; 2307 int have_children;
@@ -2348,14 +2340,15 @@ GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc,
2348 dc); 2340 dc);
2349 if (NULL != dc->serialization) 2341 if (NULL != dc->serialization)
2350 GNUNET_FS_remove_sync_file_ (dc->h, 2342 GNUNET_FS_remove_sync_file_ (dc->h,
2351 ((NULL != dc->parent) || 2343 ((NULL != dc->parent) || (! search_was_null))
2352 (! search_was_null)) ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD : 2344 ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD
2353 GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, 2345 : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
2354 dc->serialization); 2346 dc->serialization);
2355 if ((GNUNET_YES == have_children) && (NULL == dc->parent)) 2347 if ((GNUNET_YES == have_children) && (NULL == dc->parent))
2356 GNUNET_FS_remove_sync_dir_ (dc->h, 2348 GNUNET_FS_remove_sync_dir_ (dc->h,
2357 (! search_was_null) ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD : 2349 (! search_was_null)
2358 GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, 2350 ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD
2351 : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
2359 dc->serialization); 2352 dc->serialization);
2360 pi.status = GNUNET_FS_STATUS_DOWNLOAD_STOPPED; 2353 pi.status = GNUNET_FS_STATUS_DOWNLOAD_STOPPED;
2361 GNUNET_FS_download_make_status_ (&pi, dc); 2354 GNUNET_FS_download_make_status_ (&pi, dc);
@@ -2370,8 +2363,7 @@ GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc,
2370 { 2363 {
2371 if ((dc->completed != dc->length) && (GNUNET_YES == do_delete)) 2364 if ((dc->completed != dc->length) && (GNUNET_YES == do_delete))
2372 { 2365 {
2373 if ( (0 != UNLINK (dc->filename)) && 2366 if ((0 != unlink (dc->filename)) && (ENOENT != errno))
2374 (ENOENT != errno) )
2375 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 2367 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
2376 "unlink", 2368 "unlink",
2377 dc->filename); 2369 dc->filename);
@@ -2382,7 +2374,7 @@ GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc,
2382 GNUNET_FS_uri_destroy (dc->uri); 2374 GNUNET_FS_uri_destroy (dc->uri);
2383 if (NULL != dc->temp_filename) 2375 if (NULL != dc->temp_filename)
2384 { 2376 {
2385 if (0 != UNLINK (dc->temp_filename)) 2377 if (0 != unlink (dc->temp_filename))
2386 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 2378 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
2387 "unlink", 2379 "unlink",
2388 dc->temp_filename); 2380 dc->temp_filename);
diff --git a/src/fs/fs_file_information.c b/src/fs/fs_file_information.c
index 49cfc1a68..fbf3181ef 100644
--- a/src/fs/fs_file_information.c
+++ b/src/fs/fs_file_information.c
@@ -97,16 +97,14 @@ GNUNET_FS_file_information_set_filename (struct GNUNET_FS_FileInformation *s,
97 * @return publish structure entry for the file 97 * @return publish structure entry for the file
98 */ 98 */
99struct GNUNET_FS_FileInformation * 99struct GNUNET_FS_FileInformation *
100GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h, 100GNUNET_FS_file_information_create_from_file (
101 void *client_info, 101 struct GNUNET_FS_Handle *h,
102 const char *filename, 102 void *client_info,
103 const struct GNUNET_FS_Uri 103 const char *filename,
104 *keywords, 104 const struct GNUNET_FS_Uri *keywords,
105 const struct 105 const struct GNUNET_CONTAINER_MetaData *meta,
106 GNUNET_CONTAINER_MetaData *meta, 106 int do_index,
107 int do_index, 107 const struct GNUNET_FS_BlockOptions *bo)
108 const struct GNUNET_FS_BlockOptions
109 *bo)
110{ 108{
111 struct FileInfo *fi; 109 struct FileInfo *fi;
112 uint64_t fsize; 110 uint64_t fsize;
@@ -119,7 +117,8 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
119#endif 117#endif
120 118
121 /* FIXME: should include_symbolic_links be GNUNET_NO or GNUNET_YES here? */ 119 /* FIXME: should include_symbolic_links be GNUNET_NO or GNUNET_YES here? */
122 if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fsize, GNUNET_NO, GNUNET_YES)) 120 if (GNUNET_OK !=
121 GNUNET_DISK_file_size (filename, &fsize, GNUNET_NO, GNUNET_YES))
123 { 122 {
124 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); 123 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
125 return NULL; 124 return NULL;
@@ -131,16 +130,20 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
131 return NULL; 130 return NULL;
132 } 131 }
133 ret = 132 ret =
134 GNUNET_FS_file_information_create_from_reader (h, client_info, 133 GNUNET_FS_file_information_create_from_reader (h,
135 fsize, 134 client_info,
136 &GNUNET_FS_data_reader_file_, 135 fsize,
137 fi, keywords, meta, 136 &GNUNET_FS_data_reader_file_,
138 do_index, bo); 137 fi,
138 keywords,
139 meta,
140 do_index,
141 bo);
139 if (ret == NULL) 142 if (ret == NULL)
140 return NULL; 143 return NULL;
141 ret->h = h; 144 ret->h = h;
142 ret->filename = GNUNET_strdup (filename); 145 ret->filename = GNUNET_strdup (filename);
143#if !WINDOWS 146#if ! WINDOWS
144 fn = filename; 147 fn = filename;
145#else 148#else
146 plibc_conv_to_win_path (filename, fn_conv); 149 plibc_conv_to_win_path (filename, fn_conv);
@@ -151,16 +154,22 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
151/* FIXME: If we assume that on other platforms CRT is UTF-8-aware, then 154/* FIXME: If we assume that on other platforms CRT is UTF-8-aware, then
152 * this should be changed to EXTRACTOR_METAFORMAT_UTF8 155 * this should be changed to EXTRACTOR_METAFORMAT_UTF8
153 */ 156 */
154#if !WINDOWS 157#if ! WINDOWS
155 GNUNET_CONTAINER_meta_data_insert (ret->meta, "<gnunet>", 158 GNUNET_CONTAINER_meta_data_insert (ret->meta,
159 "<gnunet>",
156 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, 160 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
157 EXTRACTOR_METAFORMAT_C_STRING, 161 EXTRACTOR_METAFORMAT_C_STRING,
158 "text/plain", fn, strlen (fn) + 1); 162 "text/plain",
163 fn,
164 strlen (fn) + 1);
159#else 165#else
160 GNUNET_CONTAINER_meta_data_insert (ret->meta, "<gnunet>", 166 GNUNET_CONTAINER_meta_data_insert (ret->meta,
167 "<gnunet>",
161 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, 168 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
162 EXTRACTOR_METAFORMAT_UTF8, 169 EXTRACTOR_METAFORMAT_UTF8,
163 "text/plain", fn, strlen (fn) + 1); 170 "text/plain",
171 fn,
172 strlen (fn) + 1);
164#endif 173#endif
165 return ret; 174 return ret;
166} 175}
@@ -183,26 +192,30 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
183 * @return publish structure entry for the file 192 * @return publish structure entry for the file
184 */ 193 */
185struct GNUNET_FS_FileInformation * 194struct GNUNET_FS_FileInformation *
186GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h, 195GNUNET_FS_file_information_create_from_data (
187 void *client_info, uint64_t length, 196 struct GNUNET_FS_Handle *h,
188 void *data, 197 void *client_info,
189 const struct GNUNET_FS_Uri 198 uint64_t length,
190 *keywords, 199 void *data,
191 const struct 200 const struct GNUNET_FS_Uri *keywords,
192 GNUNET_CONTAINER_MetaData *meta, 201 const struct GNUNET_CONTAINER_MetaData *meta,
193 int do_index, 202 int do_index,
194 const struct GNUNET_FS_BlockOptions 203 const struct GNUNET_FS_BlockOptions *bo)
195 *bo)
196{ 204{
197 if (GNUNET_YES == do_index) 205 if (GNUNET_YES == do_index)
198 { 206 {
199 GNUNET_break (0); 207 GNUNET_break (0);
200 return NULL; 208 return NULL;
201 } 209 }
202 return GNUNET_FS_file_information_create_from_reader (h, client_info, length, 210 return GNUNET_FS_file_information_create_from_reader (h,
211 client_info,
212 length,
203 &GNUNET_FS_data_reader_copy_, 213 &GNUNET_FS_data_reader_copy_,
204 data, keywords, meta, 214 data,
205 do_index, bo); 215 keywords,
216 meta,
217 do_index,
218 bo);
206} 219}
207 220
208 221
@@ -223,18 +236,16 @@ GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
223 * @return publish structure entry for the file 236 * @return publish structure entry for the file
224 */ 237 */
225struct GNUNET_FS_FileInformation * 238struct GNUNET_FS_FileInformation *
226GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h, 239GNUNET_FS_file_information_create_from_reader (
227 void *client_info, 240 struct GNUNET_FS_Handle *h,
228 uint64_t length, 241 void *client_info,
229 GNUNET_FS_DataReader reader, 242 uint64_t length,
230 void *reader_cls, 243 GNUNET_FS_DataReader reader,
231 const struct GNUNET_FS_Uri 244 void *reader_cls,
232 *keywords, 245 const struct GNUNET_FS_Uri *keywords,
233 const struct 246 const struct GNUNET_CONTAINER_MetaData *meta,
234 GNUNET_CONTAINER_MetaData *meta, 247 int do_index,
235 int do_index, 248 const struct GNUNET_FS_BlockOptions *bo)
236 const struct
237 GNUNET_FS_BlockOptions *bo)
238{ 249{
239 struct GNUNET_FS_FileInformation *ret; 250 struct GNUNET_FS_FileInformation *ret;
240 251
@@ -266,8 +277,8 @@ GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
266 * @return #GNUNET_YES if so, #GNUNET_NO if not 277 * @return #GNUNET_YES if so, #GNUNET_NO if not
267 */ 278 */
268int 279int
269GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation 280GNUNET_FS_file_information_is_directory (
270 *ent) 281 const struct GNUNET_FS_FileInformation *ent)
271{ 282{
272 return ent->is_directory; 283 return ent->is_directory;
273} 284}
@@ -286,16 +297,13 @@ GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation
286 * @return publish structure entry for the directory , NULL on error 297 * @return publish structure entry for the directory , NULL on error
287 */ 298 */
288struct GNUNET_FS_FileInformation * 299struct GNUNET_FS_FileInformation *
289GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h, 300GNUNET_FS_file_information_create_empty_directory (
290 void *client_info, 301 struct GNUNET_FS_Handle *h,
291 const struct GNUNET_FS_Uri 302 void *client_info,
292 *keywords, 303 const struct GNUNET_FS_Uri *keywords,
293 const struct 304 const struct GNUNET_CONTAINER_MetaData *meta,
294 GNUNET_CONTAINER_MetaData 305 const struct GNUNET_FS_BlockOptions *bo,
295 *meta, 306 const char *filename)
296 const struct
297 GNUNET_FS_BlockOptions *bo,
298 const char *filename)
299{ 307{
300 struct GNUNET_FS_FileInformation *ret; 308 struct GNUNET_FS_FileInformation *ret;
301 309
@@ -327,7 +335,8 @@ int
327GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir, 335GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
328 struct GNUNET_FS_FileInformation *ent) 336 struct GNUNET_FS_FileInformation *ent)
329{ 337{
330 if ((ent->dir != NULL) || (ent->next != NULL) || (dir->is_directory != GNUNET_YES)) 338 if ((ent->dir != NULL) || (ent->next != NULL) ||
339 (dir->is_directory != GNUNET_YES))
331 { 340 {
332 GNUNET_break (0); 341 GNUNET_break (0);
333 return GNUNET_SYSERR; 342 return GNUNET_SYSERR;
@@ -364,10 +373,13 @@ GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
364 373
365 no = GNUNET_NO; 374 no = GNUNET_NO;
366 if (GNUNET_OK != 375 if (GNUNET_OK !=
367 proc (proc_cls, dir, 376 proc (proc_cls,
368 (dir->is_directory == GNUNET_YES) ? dir->data.dir.dir_size : dir->data. 377 dir,
369 file.file_size, 378 (dir->is_directory == GNUNET_YES) ? dir->data.dir.dir_size
370 dir->meta, &dir->keywords, &dir->bo, 379 : dir->data.file.file_size,
380 dir->meta,
381 &dir->keywords,
382 &dir->bo,
371 (dir->is_directory == GNUNET_YES) ? &no : &dir->data.file.do_index, 383 (dir->is_directory == GNUNET_YES) ? &no : &dir->data.file.do_index,
372 &dir->client_info)) 384 &dir->client_info))
373 return; 385 return;
@@ -378,10 +390,15 @@ GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
378 { 390 {
379 no = GNUNET_NO; 391 no = GNUNET_NO;
380 if (GNUNET_OK != 392 if (GNUNET_OK !=
381 proc (proc_cls, pos, 393 proc (proc_cls,
382 (pos->is_directory == GNUNET_YES) ? pos->data.dir.dir_size : pos->data. 394 pos,
383 file.file_size, pos->meta, &pos->keywords, &pos->bo, 395 (pos->is_directory == GNUNET_YES) ? pos->data.dir.dir_size
384 (pos->is_directory == GNUNET_YES) ? &no : &pos->data.file.do_index, 396 : pos->data.file.file_size,
397 pos->meta,
398 &pos->keywords,
399 &pos->bo,
400 (pos->is_directory == GNUNET_YES) ? &no
401 : &pos->data.file.do_index,
385 &pos->client_info)) 402 &pos->client_info))
386 break; 403 break;
387 pos = pos->next; 404 pos = pos->next;
@@ -418,8 +435,14 @@ GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
418 } 435 }
419 /* clean up client-info */ 436 /* clean up client-info */
420 if (NULL != cleaner) 437 if (NULL != cleaner)
421 cleaner (cleaner_cls, fi, fi->data.dir.dir_size, fi->meta, &fi->keywords, 438 cleaner (cleaner_cls,
422 &fi->bo, &no, &fi->client_info); 439 fi,
440 fi->data.dir.dir_size,
441 fi->meta,
442 &fi->keywords,
443 &fi->bo,
444 &no,
445 &fi->client_info);
423 GNUNET_free_non_null (fi->data.dir.dir_data); 446 GNUNET_free_non_null (fi->data.dir.dir_data);
424 } 447 }
425 else 448 else
@@ -432,19 +455,25 @@ GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
432 } 455 }
433 /* clean up client-info */ 456 /* clean up client-info */
434 if (NULL != cleaner) 457 if (NULL != cleaner)
435 cleaner (cleaner_cls, fi, fi->data.file.file_size, fi->meta, 458 cleaner (cleaner_cls,
436 &fi->keywords, &fi->bo, &fi->data.file.do_index, 459 fi,
460 fi->data.file.file_size,
461 fi->meta,
462 &fi->keywords,
463 &fi->bo,
464 &fi->data.file.do_index,
437 &fi->client_info); 465 &fi->client_info);
438 } 466 }
439 GNUNET_free_non_null (fi->filename); 467 GNUNET_free_non_null (fi->filename);
440 GNUNET_free_non_null (fi->emsg); 468 GNUNET_free_non_null (fi->emsg);
441 if (NULL != fi->sks_uri) 469 if (NULL != fi->sks_uri)
442 GNUNET_FS_uri_destroy (fi->sks_uri); 470 GNUNET_FS_uri_destroy (fi->sks_uri);
443 if (NULL != fi->chk_uri) 471 if (NULL != fi->chk_uri)
444 GNUNET_FS_uri_destroy (fi->chk_uri); 472 GNUNET_FS_uri_destroy (fi->chk_uri);
445 /* clean up serialization */ 473 /* clean up serialization */
446 if ((NULL != fi->serialization) && (0 != UNLINK (fi->serialization))) 474 if ((NULL != fi->serialization) && (0 != unlink (fi->serialization)))
447 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", 475 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
476 "unlink",
448 fi->serialization); 477 fi->serialization);
449 if (NULL != fi->keywords) 478 if (NULL != fi->keywords)
450 GNUNET_FS_uri_destroy (fi->keywords); 479 GNUNET_FS_uri_destroy (fi->keywords);
diff --git a/src/fs/fs_namespace.c b/src/fs/fs_namespace.c
index 675253b90..11a137a09 100644
--- a/src/fs/fs_namespace.c
+++ b/src/fs/fs_namespace.c
@@ -69,7 +69,6 @@ struct NamespaceUpdateNode
69 * TREE this entry belongs to (if nug is current). 69 * TREE this entry belongs to (if nug is current).
70 */ 70 */
71 unsigned int tree_id; 71 unsigned int tree_id;
72
73}; 72};
74 73
75 74
@@ -126,8 +125,9 @@ struct GNUNET_FS_UpdateInformationGraph
126 * @return NULL on error, otherwise the name of the directory 125 * @return NULL on error, otherwise the name of the directory
127 */ 126 */
128static char * 127static char *
129get_update_information_directory (struct GNUNET_FS_Handle *h, 128get_update_information_directory (
130 const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns) 129 struct GNUNET_FS_Handle *h,
130 const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns)
131{ 131{
132 char *dn; 132 char *dn;
133 char *ret; 133 char *ret;
@@ -136,21 +136,19 @@ get_update_information_directory (struct GNUNET_FS_Handle *h,
136 struct GNUNET_CRYPTO_HashAsciiEncoded enc; 136 struct GNUNET_CRYPTO_HashAsciiEncoded enc;
137 137
138 if (GNUNET_OK != 138 if (GNUNET_OK !=
139 GNUNET_CONFIGURATION_get_value_filename (h->cfg, "FS", "UPDATE_DIR", 139 GNUNET_CONFIGURATION_get_value_filename (h->cfg, "FS", "UPDATE_DIR", &dn))
140 &dn))
141 { 140 {
142 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 141 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "fs", "UPDATE_DIR");
143 "fs", "UPDATE_DIR");
144 return NULL; 142 return NULL;
145 } 143 }
146 GNUNET_CRYPTO_ecdsa_key_get_public (ns, &pub); 144 GNUNET_CRYPTO_ecdsa_key_get_public (ns, &pub);
147 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &hc); 145 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &hc);
148 GNUNET_CRYPTO_hash_to_enc (&hc, 146 GNUNET_CRYPTO_hash_to_enc (&hc, &enc);
149 &enc); 147 GNUNET_asprintf (&ret,
150 GNUNET_asprintf (&ret, "%s%s%s", 148 "%s%s%s",
151 dn, 149 dn,
152 DIR_SEPARATOR_STR, 150 DIR_SEPARATOR_STR,
153 (const char *) enc.encoding); 151 (const char *) enc.encoding);
154 GNUNET_free (dn); 152 GNUNET_free (dn);
155 return ret; 153 return ret;
156} 154}
@@ -176,8 +174,7 @@ free_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig)
176 GNUNET_free (nsn->update); 174 GNUNET_free (nsn->update);
177 GNUNET_free (nsn); 175 GNUNET_free (nsn);
178 } 176 }
179 GNUNET_array_grow (uig->update_nodes, uig->update_node_count, 177 GNUNET_array_grow (uig->update_nodes, uig->update_node_count, 0);
180 0);
181 if (NULL != uig->update_map) 178 if (NULL != uig->update_map)
182 GNUNET_CONTAINER_multihashmap_destroy (uig->update_map); 179 GNUNET_CONTAINER_multihashmap_destroy (uig->update_map);
183 GNUNET_free (uig); 180 GNUNET_free (uig);
@@ -198,15 +195,14 @@ write_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig)
198 struct NamespaceUpdateNode *n; 195 struct NamespaceUpdateNode *n;
199 char *uris; 196 char *uris;
200 197
201 fn = get_update_information_directory (uig->h, 198 fn = get_update_information_directory (uig->h, &uig->ns);
202 &uig->ns);
203 wh = GNUNET_BIO_write_open (fn); 199 wh = GNUNET_BIO_write_open (fn);
204 if (NULL == wh) 200 if (NULL == wh)
205 { 201 {
206 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 202 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
207 _("Failed to open `%s' for writing: %s\n"), 203 _ ("Failed to open `%s' for writing: %s\n"),
208 fn, 204 fn,
209 STRERROR (errno)); 205 strerror (errno));
210 GNUNET_free (fn); 206 GNUNET_free (fn);
211 return; 207 return;
212 } 208 }
@@ -229,9 +225,9 @@ write_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig)
229END: 225END:
230 if (GNUNET_OK != GNUNET_BIO_write_close (wh)) 226 if (GNUNET_OK != GNUNET_BIO_write_close (wh))
231 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 227 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
232 _("Failed to write `%s': %s\n"), 228 _ ("Failed to write `%s': %s\n"),
233 fn, 229 fn,
234 STRERROR (errno)); 230 strerror (errno));
235 GNUNET_free (fn); 231 GNUNET_free (fn);
236} 232}
237 233
@@ -245,7 +241,7 @@ END:
245 */ 241 */
246static struct GNUNET_FS_UpdateInformationGraph * 242static struct GNUNET_FS_UpdateInformationGraph *
247read_update_information_graph (struct GNUNET_FS_Handle *h, 243read_update_information_graph (struct GNUNET_FS_Handle *h,
248 const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns) 244 const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns)
249{ 245{
250 struct GNUNET_FS_UpdateInformationGraph *uig; 246 struct GNUNET_FS_UpdateInformationGraph *uig;
251 char *fn; 247 char *fn;
@@ -289,8 +285,9 @@ read_update_information_graph (struct GNUNET_FS_Handle *h,
289 for (i = 0; i < count; i++) 285 for (i = 0; i < count; i++)
290 { 286 {
291 n = GNUNET_new (struct NamespaceUpdateNode); 287 n = GNUNET_new (struct NamespaceUpdateNode);
292 if ((GNUNET_OK != GNUNET_BIO_read_string (rh, "identifier", &n->id, 1024)) 288 if ((GNUNET_OK !=
293 || (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "meta", &n->md)) || 289 GNUNET_BIO_read_string (rh, "identifier", &n->id, 1024)) ||
290 (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "meta", &n->md)) ||
294 (GNUNET_OK != 291 (GNUNET_OK !=
295 GNUNET_BIO_read_string (rh, "update-id", &n->update, 1024)) || 292 GNUNET_BIO_read_string (rh, "update-id", &n->update, 1024)) ||
296 (GNUNET_OK != GNUNET_BIO_read_string (rh, "uri", &uris, 1024 * 2))) 293 (GNUNET_OK != GNUNET_BIO_read_string (rh, "uri", &uris, 1024 * 2)))
@@ -318,11 +315,13 @@ read_update_information_graph (struct GNUNET_FS_Handle *h,
318 uig->update_nodes[i] = n; 315 uig->update_nodes[i] = n;
319 } 316 }
320 uig->update_node_count = i; 317 uig->update_node_count = i;
321 END: 318END:
322 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) 319 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
323 { 320 {
324 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to read `%s': %s\n"), 321 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
325 fn, emsg); 322 _ ("Failed to read `%s': %s\n"),
323 fn,
324 emsg);
326 GNUNET_free (emsg); 325 GNUNET_free (emsg);
327 } 326 }
328 GNUNET_free (fn); 327 GNUNET_free (fn);
@@ -387,8 +386,7 @@ struct GNUNET_FS_PublishSksContext
387 * @param msg error message (or NULL) 386 * @param msg error message (or NULL)
388 */ 387 */
389static void 388static void
390sks_publish_cont (void *cls, 389sks_publish_cont (void *cls, const char *msg)
391 const char *msg)
392{ 390{
393 struct GNUNET_FS_PublishSksContext *psc = cls; 391 struct GNUNET_FS_PublishSksContext *psc = cls;
394 struct GNUNET_FS_UpdateInformationGraph *uig; 392 struct GNUNET_FS_UpdateInformationGraph *uig;
@@ -406,11 +404,8 @@ sks_publish_cont (void *cls,
406 /* FIXME: this can be done much more 404 /* FIXME: this can be done much more
407 * efficiently by simply appending to the 405 * efficiently by simply appending to the
408 * file and overwriting the 4-byte header */ 406 * file and overwriting the 4-byte header */
409 uig = read_update_information_graph (psc->h, 407 uig = read_update_information_graph (psc->h, &psc->ns);
410 &psc->ns); 408 GNUNET_array_append (uig->update_nodes, uig->update_node_count, psc->nsn);
411 GNUNET_array_append (uig->update_nodes,
412 uig->update_node_count,
413 psc->nsn);
414 psc->nsn = NULL; 409 psc->nsn = NULL;
415 write_update_information_graph (uig); 410 write_update_information_graph (uig);
416 free_update_information_graph (uig); 411 free_update_information_graph (uig);
@@ -439,12 +434,14 @@ sks_publish_cont (void *cls,
439struct GNUNET_FS_PublishSksContext * 434struct GNUNET_FS_PublishSksContext *
440GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, 435GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
441 const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, 436 const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns,
442 const char *identifier, const char *update, 437 const char *identifier,
438 const char *update,
443 const struct GNUNET_CONTAINER_MetaData *meta, 439 const struct GNUNET_CONTAINER_MetaData *meta,
444 const struct GNUNET_FS_Uri *uri, 440 const struct GNUNET_FS_Uri *uri,
445 const struct GNUNET_FS_BlockOptions *bo, 441 const struct GNUNET_FS_BlockOptions *bo,
446 enum GNUNET_FS_PublishOptions options, 442 enum GNUNET_FS_PublishOptions options,
447 GNUNET_FS_PublishContinuation cont, void *cont_cls) 443 GNUNET_FS_PublishContinuation cont,
444 void *cont_cls)
448{ 445{
449 struct GNUNET_FS_PublishSksContext *psc; 446 struct GNUNET_FS_PublishSksContext *psc;
450 struct GNUNET_FS_Uri *sks_uri; 447 struct GNUNET_FS_Uri *sks_uri;
@@ -452,8 +449,7 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
452 sks_uri = GNUNET_new (struct GNUNET_FS_Uri); 449 sks_uri = GNUNET_new (struct GNUNET_FS_Uri);
453 sks_uri->type = GNUNET_FS_URI_SKS; 450 sks_uri->type = GNUNET_FS_URI_SKS;
454 sks_uri->data.sks.identifier = GNUNET_strdup (identifier); 451 sks_uri->data.sks.identifier = GNUNET_strdup (identifier);
455 GNUNET_CRYPTO_ecdsa_key_get_public (ns, 452 GNUNET_CRYPTO_ecdsa_key_get_public (ns, &sks_uri->data.sks.ns);
456 &sks_uri->data.sks.ns);
457 453
458 psc = GNUNET_new (struct GNUNET_FS_PublishSksContext); 454 psc = GNUNET_new (struct GNUNET_FS_PublishSksContext);
459 psc->h = h; 455 psc->h = h;
@@ -466,8 +462,7 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
466 psc->dsh = GNUNET_DATASTORE_connect (h->cfg); 462 psc->dsh = GNUNET_DATASTORE_connect (h->cfg);
467 if (NULL == psc->dsh) 463 if (NULL == psc->dsh)
468 { 464 {
469 sks_publish_cont (psc, 465 sks_publish_cont (psc, _ ("Failed to connect to datastore."));
470 _("Failed to connect to datastore."));
471 return NULL; 466 return NULL;
472 } 467 }
473 } 468 }
@@ -480,16 +475,16 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
480 psc->nsn->uri = GNUNET_FS_uri_dup (uri); 475 psc->nsn->uri = GNUNET_FS_uri_dup (uri);
481 } 476 }
482 psc->uc = GNUNET_FS_publish_ublock_ (h, 477 psc->uc = GNUNET_FS_publish_ublock_ (h,
483 psc->dsh, 478 psc->dsh,
484 identifier, 479 identifier,
485 update, 480 update,
486 ns, 481 ns,
487 meta, 482 meta,
488 uri, 483 uri,
489 bo, 484 bo,
490 options, 485 options,
491 &sks_publish_cont, 486 &sks_publish_cont,
492 psc); 487 psc);
493 return psc; 488 return psc;
494} 489}
495 490
@@ -553,18 +548,12 @@ struct ProcessUpdateClosure
553 * GNUNET_NO if not. 548 * GNUNET_NO if not.
554 */ 549 */
555static int 550static int
556process_update_node (void *cls, 551process_update_node (void *cls, const struct GNUNET_HashCode *key, void *value)
557 const struct GNUNET_HashCode *key,
558 void *value)
559{ 552{
560 struct ProcessUpdateClosure *pc = cls; 553 struct ProcessUpdateClosure *pc = cls;
561 struct NamespaceUpdateNode *nsn = value; 554 struct NamespaceUpdateNode *nsn = value;
562 555
563 pc->ip (pc->ip_cls, 556 pc->ip (pc->ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update);
564 nsn->id,
565 nsn->uri,
566 nsn->md,
567 nsn->update);
568 return GNUNET_YES; 557 return GNUNET_YES;
569} 558}
570 559
@@ -622,9 +611,7 @@ struct FindTreeClosure
622 * GNUNET_NO if not. 611 * GNUNET_NO if not.
623 */ 612 */
624static int 613static int
625find_trees (void *cls, 614find_trees (void *cls, const struct GNUNET_HashCode *key, void *value)
626 const struct GNUNET_HashCode *key,
627 void *value)
628{ 615{
629 struct FindTreeClosure *fc = cls; 616 struct FindTreeClosure *fc = cls;
630 struct NamespaceUpdateNode *nsn = value; 617 struct NamespaceUpdateNode *nsn = value;
@@ -633,26 +620,28 @@ find_trees (void *cls,
633 if (nsn->nug == fc->nug) 620 if (nsn->nug == fc->nug)
634 { 621 {
635 if (UINT_MAX == nsn->tree_id) 622 if (UINT_MAX == nsn->tree_id)
636 return GNUNET_YES; /* circular */ 623 return GNUNET_YES; /* circular */
637 GNUNET_assert (nsn->tree_id < fc->tree_array_size); 624 GNUNET_assert (nsn->tree_id < fc->tree_array_size);
638 if (fc->tree_array[nsn->tree_id] != nsn) 625 if (fc->tree_array[nsn->tree_id] != nsn)
639 return GNUNET_YES; /* part of "another" (directed) TREE, 626 return GNUNET_YES; /* part of "another" (directed) TREE,
640 * and not root of it, end trace */ 627 * and not root of it, end trace */
641 if (nsn->tree_id == fc->id) 628 if (nsn->tree_id == fc->id)
642 return GNUNET_YES; /* that's our own root (can this be?) */ 629 return GNUNET_YES; /* that's our own root (can this be?) */
643 /* merge existing TREE, we have a root for both */ 630 /* merge existing TREE, we have a root for both */
644 fc->tree_array[nsn->tree_id] = NULL; 631 fc->tree_array[nsn->tree_id] = NULL;
645 if (UINT_MAX == fc->id) 632 if (UINT_MAX == fc->id)
646 fc->id = nsn->tree_id; /* take over ID */ 633 fc->id = nsn->tree_id; /* take over ID */
647 } 634 }
648 else 635 else
649 { 636 {
650 nsn->nug = fc->nug; 637 nsn->nug = fc->nug;
651 nsn->tree_id = UINT_MAX; /* mark as undef */ 638 nsn->tree_id = UINT_MAX; /* mark as undef */
652 /* trace */ 639 /* trace */
653 GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc); 640 GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc);
654 GNUNET_CONTAINER_multihashmap_get_multiple (fc->uig->update_map, &hc, 641 GNUNET_CONTAINER_multihashmap_get_multiple (fc->uig->update_map,
655 &find_trees, fc); 642 &hc,
643 &find_trees,
644 fc);
656 } 645 }
657 return GNUNET_YES; 646 return GNUNET_YES;
658} 647}
@@ -682,11 +671,12 @@ find_trees (void *cls,
682 * @param ip_cls closure for ip 671 * @param ip_cls closure for ip
683 */ 672 */
684void 673void
685GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h, 674GNUNET_FS_namespace_list_updateable (
686 const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, 675 struct GNUNET_FS_Handle *h,
687 const char *next_id, 676 const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns,
688 GNUNET_FS_IdentifierProcessor ip, 677 const char *next_id,
689 void *ip_cls) 678 GNUNET_FS_IdentifierProcessor ip,
679 void *ip_cls)
690{ 680{
691 unsigned int i; 681 unsigned int i;
692 unsigned int nug; 682 unsigned int nug;
@@ -700,29 +690,33 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h,
700 if (NULL == uig->update_nodes) 690 if (NULL == uig->update_nodes)
701 { 691 {
702 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 692 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
703 "No updateable nodes found for ID `%s'\n", next_id); 693 "No updateable nodes found for ID `%s'\n",
694 next_id);
704 free_update_information_graph (uig); 695 free_update_information_graph (uig);
705 return; /* no nodes */ 696 return; /* no nodes */
706 } 697 }
707 uig->update_map = 698 uig->update_map =
708 GNUNET_CONTAINER_multihashmap_create (2 + 699 GNUNET_CONTAINER_multihashmap_create (2 + 3 * uig->update_node_count / 4,
709 3 * uig->update_node_count / 700 GNUNET_NO);
710 4,
711 GNUNET_NO);
712 for (i = 0; i < uig->update_node_count; i++) 701 for (i = 0; i < uig->update_node_count; i++)
713 { 702 {
714 nsn = uig->update_nodes[i]; 703 nsn = uig->update_nodes[i];
715 GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc); 704 GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc);
716 GNUNET_CONTAINER_multihashmap_put (uig->update_map, &hc, nsn, 705 GNUNET_CONTAINER_multihashmap_put (
717 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 706 uig->update_map,
707 &hc,
708 nsn,
709 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
718 } 710 }
719 if (NULL != next_id) 711 if (NULL != next_id)
720 { 712 {
721 GNUNET_CRYPTO_hash (next_id, strlen (next_id), &hc); 713 GNUNET_CRYPTO_hash (next_id, strlen (next_id), &hc);
722 pc.ip = ip; 714 pc.ip = ip;
723 pc.ip_cls = ip_cls; 715 pc.ip_cls = ip_cls;
724 GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, &hc, 716 GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map,
725 &process_update_node, &pc); 717 &hc,
718 &process_update_node,
719 &pc);
726 free_update_information_graph (uig); 720 free_update_information_graph (uig);
727 return; 721 return;
728 } 722 }
@@ -738,9 +732,11 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h,
738 nsn = uig->update_nodes[i]; 732 nsn = uig->update_nodes[i];
739 if (nsn->nug == nug) 733 if (nsn->nug == nug)
740 { 734 {
741 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TREE of node `%s' is %u\n", nsn->id, 735 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
736 "TREE of node `%s' is %u\n",
737 nsn->id,
742 nsn->nug); 738 nsn->nug);
743 continue; /* already placed in TREE */ 739 continue; /* already placed in TREE */
744 } 740 }
745 GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc); 741 GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc);
746 nsn->nug = nug; 742 nsn->nug = nug;
@@ -748,8 +744,10 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h,
748 fc.id = UINT_MAX; 744 fc.id = UINT_MAX;
749 fc.nug = nug; 745 fc.nug = nug;
750 fc.uig = uig; 746 fc.uig = uig;
751 GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, &hc, 747 GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map,
752 &find_trees, &fc); 748 &hc,
749 &find_trees,
750 &fc);
753 if (UINT_MAX == fc.id) 751 if (UINT_MAX == fc.id)
754 { 752 {
755 /* start new TREE */ 753 /* start new TREE */
@@ -768,15 +766,18 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h,
768 nsn->tree_id = fc.id; 766 nsn->tree_id = fc.id;
769 } 767 }
770 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 768 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
771 "Starting new TREE %u with node `%s'\n", nsn->tree_id, 769 "Starting new TREE %u with node `%s'\n",
770 nsn->tree_id,
772 nsn->id); 771 nsn->id);
773 /* put all nodes with same identifier into this TREE */ 772 /* put all nodes with same identifier into this TREE */
774 GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc); 773 GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc);
775 fc.id = nsn->tree_id; 774 fc.id = nsn->tree_id;
776 fc.nug = nug; 775 fc.nug = nug;
777 fc.uig = uig; 776 fc.uig = uig;
778 GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, &hc, 777 GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map,
779 &find_trees, &fc); 778 &hc,
779 &find_trees,
780 &fc);
780 } 781 }
781 else 782 else
782 { 783 {
@@ -785,7 +786,8 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h,
785 nsn->tree_id = fc.id; 786 nsn->tree_id = fc.id;
786 } 787 }
787 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 788 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
788 "TREE of node `%s' is %u\n", nsn->id, 789 "TREE of node `%s' is %u\n",
790 nsn->id,
789 fc.id); 791 fc.id);
790 } 792 }
791 for (i = 0; i < fc.tree_array_size; i++) 793 for (i = 0; i < fc.tree_array_size; i++)
@@ -793,7 +795,9 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h,
793 nsn = fc.tree_array[i]; 795 nsn = fc.tree_array[i];
794 if (NULL != nsn) 796 if (NULL != nsn)
795 { 797 {
796 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Root of TREE %u is node `%s'\n", i, 798 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
799 "Root of TREE %u is node `%s'\n",
800 i,
797 nsn->id); 801 nsn->id);
798 ip (ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update); 802 ip (ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update);
799 } 803 }
diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c
index 9097d9884..5a67afbc0 100644
--- a/src/fs/fs_uri.c
+++ b/src/fs/fs_uri.c
@@ -91,7 +91,6 @@
91#include <unistdio.h> 91#include <unistdio.h>
92 92
93 93
94
95/** 94/**
96 * Get a unique key from a URI. This is for putting URIs 95 * Get a unique key from a URI. This is for putting URIs
97 * into HashMaps. The key may change between FS implementations. 96 * into HashMaps. The key may change between FS implementations.
@@ -102,7 +101,7 @@
102 */ 101 */
103int 102int
104GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, 103GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
105 struct GNUNET_HashCode *key) 104 struct GNUNET_HashCode *key)
106{ 105{
107 switch (uri->type) 106 switch (uri->type)
108 { 107 {
@@ -112,14 +111,14 @@ GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
112 case GNUNET_FS_URI_SKS: 111 case GNUNET_FS_URI_SKS:
113 GNUNET_CRYPTO_hash (uri->data.sks.identifier, 112 GNUNET_CRYPTO_hash (uri->data.sks.identifier,
114 strlen (uri->data.sks.identifier), 113 strlen (uri->data.sks.identifier),
115 key); 114 key);
116 return GNUNET_OK; 115 return GNUNET_OK;
117 case GNUNET_FS_URI_KSK: 116 case GNUNET_FS_URI_KSK:
118 if (uri->data.ksk.keywordCount > 0) 117 if (uri->data.ksk.keywordCount > 0)
119 { 118 {
120 GNUNET_CRYPTO_hash (uri->data.ksk.keywords[0], 119 GNUNET_CRYPTO_hash (uri->data.ksk.keywords[0],
121 strlen (uri->data.ksk.keywords[0]), 120 strlen (uri->data.ksk.keywords[0]),
122 key); 121 key);
123 return GNUNET_OK; 122 return GNUNET_OK;
124 } 123 }
125 else 124 else
@@ -131,7 +130,7 @@ GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
131 case GNUNET_FS_URI_LOC: 130 case GNUNET_FS_URI_LOC:
132 GNUNET_CRYPTO_hash (&uri->data.loc.fi, 131 GNUNET_CRYPTO_hash (&uri->data.loc.fi,
133 sizeof (struct FileIdentifier) + 132 sizeof (struct FileIdentifier) +
134 sizeof (struct GNUNET_PeerIdentity), 133 sizeof (struct GNUNET_PeerIdentity),
135 key); 134 key);
136 return GNUNET_OK; 135 return GNUNET_OK;
137 default: 136 default:
@@ -213,8 +212,7 @@ GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri)
213 * @return decodded string with leading space (or preserved plus) 212 * @return decodded string with leading space (or preserved plus)
214 */ 213 */
215static char * 214static char *
216percent_decode_keyword (const char *in, 215percent_decode_keyword (const char *in, char **emsg)
217 char **emsg)
218{ 216{
219 char *out; 217 char *out;
220 char *ret; 218 char *ret;
@@ -229,16 +227,17 @@ percent_decode_keyword (const char *in,
229 { 227 {
230 if (out[rpos] == '%') 228 if (out[rpos] == '%')
231 { 229 {
232 if (1 != SSCANF (&out[rpos + 1], "%2X", &hx)) 230 if (1 != sscanf (&out[rpos + 1], "%2X", &hx))
233 { 231 {
234 GNUNET_free (out); 232 GNUNET_free (out);
235 *emsg = GNUNET_strdup (_(/* xgettext:no-c-format */ 233 *emsg = GNUNET_strdup (
236 "Malformed KSK URI (`%' must be followed by HEX number)")); 234 _ (/* xgettext:no-c-format */
235 "Malformed KSK URI (`%' must be followed by HEX number)"));
237 return NULL; 236 return NULL;
238 } 237 }
239 rpos += 3; 238 rpos += 3;
240 if (hx == '"') 239 if (hx == '"')
241 continue; /* skip double quote */ 240 continue; /* skip double quote */
242 out[wpos++] = (char) hx; 241 out[wpos++] = (char) hx;
243 } 242 }
244 else 243 else
@@ -272,8 +271,7 @@ percent_decode_keyword (const char *in,
272 * @return NULL on error, otherwise the KSK URI 271 * @return NULL on error, otherwise the KSK URI
273 */ 272 */
274static struct GNUNET_FS_Uri * 273static struct GNUNET_FS_Uri *
275uri_ksk_parse (const char *s, 274uri_ksk_parse (const char *s, char **emsg)
276 char **emsg)
277{ 275{
278 struct GNUNET_FS_Uri *ret; 276 struct GNUNET_FS_Uri *ret;
279 char **keywords; 277 char **keywords;
@@ -288,11 +286,11 @@ uri_ksk_parse (const char *s,
288 slen = strlen (s); 286 slen = strlen (s);
289 pos = strlen (GNUNET_FS_URI_KSK_PREFIX); 287 pos = strlen (GNUNET_FS_URI_KSK_PREFIX);
290 if ((slen <= pos) || (0 != strncmp (s, GNUNET_FS_URI_KSK_PREFIX, pos))) 288 if ((slen <= pos) || (0 != strncmp (s, GNUNET_FS_URI_KSK_PREFIX, pos)))
291 return NULL; /* not KSK URI */ 289 return NULL; /* not KSK URI */
292 if ((s[slen - 1] == '+') || (s[pos] == '+')) 290 if ((s[slen - 1] == '+') || (s[pos] == '+'))
293 { 291 {
294 *emsg = 292 *emsg =
295 GNUNET_strdup (_("Malformed KSK URI (must not begin or end with `+')")); 293 GNUNET_strdup (_ ("Malformed KSK URI (must not begin or end with `+')"));
296 return NULL; 294 return NULL;
297 } 295 }
298 max = 1; 296 max = 1;
@@ -310,20 +308,19 @@ uri_ksk_parse (const char *s,
310 max++; 308 max++;
311 if (s[i - 1] == '+') 309 if (s[i - 1] == '+')
312 { 310 {
313 *emsg = GNUNET_strdup (_("Malformed KSK URI (`++' not allowed)")); 311 *emsg = GNUNET_strdup (_ ("Malformed KSK URI (`++' not allowed)"));
314 return NULL; 312 return NULL;
315 } 313 }
316 } 314 }
317 } 315 }
318 if (saw_quote == 1) 316 if (saw_quote == 1)
319 { 317 {
320 *emsg = GNUNET_strdup (_("Malformed KSK URI (quotes not balanced)")); 318 *emsg = GNUNET_strdup (_ ("Malformed KSK URI (quotes not balanced)"));
321 return NULL; 319 return NULL;
322 } 320 }
323 iret = max; 321 iret = max;
324 dup = GNUNET_strdup (s); 322 dup = GNUNET_strdup (s);
325 keywords = GNUNET_new_array (max, 323 keywords = GNUNET_new_array (max, char *);
326 char *);
327 for (i = slen - 1; i >= (int) pos; i--) 324 for (i = slen - 1; i >= (int) pos; i--)
328 { 325 {
329 if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22"))) 326 if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22")))
@@ -368,8 +365,7 @@ CLEANUP:
368 * @return NULL on error, SKS URI otherwise 365 * @return NULL on error, SKS URI otherwise
369 */ 366 */
370static struct GNUNET_FS_Uri * 367static struct GNUNET_FS_Uri *
371uri_sks_parse (const char *s, 368uri_sks_parse (const char *s, char **emsg)
372 char **emsg)
373{ 369{
374 struct GNUNET_FS_Uri *ret; 370 struct GNUNET_FS_Uri *ret;
375 struct GNUNET_CRYPTO_EcdsaPublicKey ns; 371 struct GNUNET_CRYPTO_EcdsaPublicKey ns;
@@ -378,16 +374,15 @@ uri_sks_parse (const char *s,
378 374
379 pos = strlen (GNUNET_FS_URI_SKS_PREFIX); 375 pos = strlen (GNUNET_FS_URI_SKS_PREFIX);
380 if ((strlen (s) <= pos) || (0 != strncmp (s, GNUNET_FS_URI_SKS_PREFIX, pos))) 376 if ((strlen (s) <= pos) || (0 != strncmp (s, GNUNET_FS_URI_SKS_PREFIX, pos)))
381 return NULL; /* not an SKS URI */ 377 return NULL; /* not an SKS URI */
382 end = strchr (&s[pos], '/'); 378 end = strchr (&s[pos], '/');
383 if ( (NULL == end) || 379 if ((NULL == end) ||
384 (GNUNET_OK != 380 (GNUNET_OK != GNUNET_STRINGS_string_to_data (&s[pos],
385 GNUNET_STRINGS_string_to_data (&s[pos], 381 end - &s[pos],
386 end - &s[pos], 382 &ns,
387 &ns, 383 sizeof (ns))))
388 sizeof (ns))) )
389 { 384 {
390 *emsg = GNUNET_strdup (_("Malformed SKS URI (wrong syntax)")); 385 *emsg = GNUNET_strdup (_ ("Malformed SKS URI (wrong syntax)"));
391 return NULL; /* malformed */ 386 return NULL; /* malformed */
392 } 387 }
393 end++; /* skip over '/' */ 388 end++; /* skip over '/' */
@@ -409,8 +404,7 @@ uri_sks_parse (const char *s,
409 * @return NULL on error, CHK URI otherwise 404 * @return NULL on error, CHK URI otherwise
410 */ 405 */
411static struct GNUNET_FS_Uri * 406static struct GNUNET_FS_Uri *
412uri_chk_parse (const char *s, 407uri_chk_parse (const char *s, char **emsg)
413 char **emsg)
414{ 408{
415 struct GNUNET_FS_Uri *ret; 409 struct GNUNET_FS_Uri *ret;
416 struct FileIdentifier fi; 410 struct FileIdentifier fi;
@@ -424,26 +418,28 @@ uri_chk_parse (const char *s,
424 pos = strlen (GNUNET_FS_URI_CHK_PREFIX); 418 pos = strlen (GNUNET_FS_URI_CHK_PREFIX);
425 if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || 419 if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) ||
426 (0 != strncmp (s, GNUNET_FS_URI_CHK_PREFIX, pos))) 420 (0 != strncmp (s, GNUNET_FS_URI_CHK_PREFIX, pos)))
427 return NULL; /* not a CHK URI */ 421 return NULL; /* not a CHK URI */
428 if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || 422 if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') ||
429 (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) 423 (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.'))
430 { 424 {
431 *emsg = GNUNET_strdup (_("Malformed CHK URI (wrong syntax)")); 425 *emsg = GNUNET_strdup (_ ("Malformed CHK URI (wrong syntax)"));
432 return NULL; 426 return NULL;
433 } 427 }
434 GNUNET_memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); 428 GNUNET_memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
435 h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; 429 h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
436 GNUNET_memcpy (h2, &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)], 430 GNUNET_memcpy (h2,
437 sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); 431 &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)],
432 sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
438 h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; 433 h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
439 434
440 if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &fi.chk.key)) || 435 if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &fi.chk.key)) ||
441 (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &fi.chk.query)) || 436 (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &fi.chk.query)) ||
442 (1 != 437 (1 !=
443 SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], 438 sscanf (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2],
444 "%llu", &flen))) 439 "%llu",
440 &flen)))
445 { 441 {
446 *emsg = GNUNET_strdup (_("Malformed CHK URI (failed to decode CHK)")); 442 *emsg = GNUNET_strdup (_ ("Malformed CHK URI (failed to decode CHK)"));
447 return NULL; 443 return NULL;
448 } 444 }
449 fi.file_length = GNUNET_htonll (flen); 445 fi.file_length = GNUNET_htonll (flen);
@@ -481,7 +477,6 @@ struct LocUriAssembly
481 * Peer offering the file. 477 * Peer offering the file.
482 */ 478 */
483 struct GNUNET_PeerIdentity peer; 479 struct GNUNET_PeerIdentity peer;
484
485}; 480};
486GNUNET_NETWORK_STRUCT_END 481GNUNET_NETWORK_STRUCT_END
487 482
@@ -499,8 +494,7 @@ GNUNET_NETWORK_STRUCT_END
499 * @return NULL on error, valid LOC URI otherwise 494 * @return NULL on error, valid LOC URI otherwise
500 */ 495 */
501static struct GNUNET_FS_Uri * 496static struct GNUNET_FS_Uri *
502uri_loc_parse (const char *s, 497uri_loc_parse (const char *s, char **emsg)
503 char **emsg)
504{ 498{
505 struct GNUNET_FS_Uri *uri; 499 struct GNUNET_FS_Uri *uri;
506 char h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]; 500 char h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)];
@@ -518,26 +512,28 @@ uri_loc_parse (const char *s,
518 pos = strlen (GNUNET_FS_URI_LOC_PREFIX); 512 pos = strlen (GNUNET_FS_URI_LOC_PREFIX);
519 if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || 513 if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) ||
520 (0 != strncmp (s, GNUNET_FS_URI_LOC_PREFIX, pos))) 514 (0 != strncmp (s, GNUNET_FS_URI_LOC_PREFIX, pos)))
521 return NULL; /* not a LOC URI */ 515 return NULL; /* not a LOC URI */
522 if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || 516 if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') ||
523 (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) 517 (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.'))
524 { 518 {
525 *emsg = GNUNET_strdup (_("LOC URI malformed (wrong syntax)")); 519 *emsg = GNUNET_strdup (_ ("LOC URI malformed (wrong syntax)"));
526 return NULL; 520 return NULL;
527 } 521 }
528 GNUNET_memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); 522 GNUNET_memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
529 h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; 523 h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
530 GNUNET_memcpy (h2, &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)], 524 GNUNET_memcpy (h2,
531 sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); 525 &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)],
526 sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
532 h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; 527 h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
533 528
534 if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &ass.fi.chk.key)) || 529 if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &ass.fi.chk.key)) ||
535 (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &ass.fi.chk.query)) || 530 (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &ass.fi.chk.query)) ||
536 (1 != 531 (1 !=
537 SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], 532 sscanf (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2],
538 "%llu", &flen))) 533 "%llu",
534 &flen)))
539 { 535 {
540 *emsg = GNUNET_strdup (_("LOC URI malformed (no CHK)")); 536 *emsg = GNUNET_strdup (_ ("LOC URI malformed (no CHK)"));
541 return NULL; 537 return NULL;
542 } 538 }
543 ass.fi.file_length = GNUNET_htonll (flen); 539 ass.fi.file_length = GNUNET_htonll (flen);
@@ -547,56 +543,61 @@ uri_loc_parse (const char *s,
547 npos++; 543 npos++;
548 if (s[npos] == '\0') 544 if (s[npos] == '\0')
549 { 545 {
550 *emsg = GNUNET_strdup (_("LOC URI malformed (missing LOC)")); 546 *emsg = GNUNET_strdup (_ ("LOC URI malformed (missing LOC)"));
551 goto ERR; 547 goto ERR;
552 } 548 }
553 npos++; 549 npos++;
554 if ( (strlen (&s[npos]) <= GNUNET_CRYPTO_PKEY_ASCII_LENGTH + 1) || 550 if ((strlen (&s[npos]) <= GNUNET_CRYPTO_PKEY_ASCII_LENGTH + 1) ||
555 ('.' != s[npos+GNUNET_CRYPTO_PKEY_ASCII_LENGTH]) ) 551 ('.' != s[npos + GNUNET_CRYPTO_PKEY_ASCII_LENGTH]))
556 { 552 {
557 *emsg = 553 *emsg =
558 GNUNET_strdup (_("LOC URI malformed (wrong syntax for public key)")); 554 GNUNET_strdup (_ ("LOC URI malformed (wrong syntax for public key)"));
559 } 555 }
560 if (GNUNET_OK != 556 if (
561 GNUNET_CRYPTO_eddsa_public_key_from_string (&s[npos], 557 GNUNET_OK !=
562 GNUNET_CRYPTO_PKEY_ASCII_LENGTH, 558 GNUNET_CRYPTO_eddsa_public_key_from_string (&s[npos],
563 &ass.peer.public_key)) 559 GNUNET_CRYPTO_PKEY_ASCII_LENGTH,
560 &ass.peer.public_key))
564 { 561 {
565 *emsg = 562 *emsg =
566 GNUNET_strdup (_("LOC URI malformed (could not decode public key)")); 563 GNUNET_strdup (_ ("LOC URI malformed (could not decode public key)"));
567 goto ERR; 564 goto ERR;
568 } 565 }
569 npos += GNUNET_CRYPTO_PKEY_ASCII_LENGTH; 566 npos += GNUNET_CRYPTO_PKEY_ASCII_LENGTH;
570 if (s[npos++] != '.') 567 if (s[npos++] != '.')
571 { 568 {
572 *emsg = GNUNET_strdup (_("LOC URI malformed (could not find signature)")); 569 *emsg = GNUNET_strdup (_ ("LOC URI malformed (could not find signature)"));
573 goto ERR; 570 goto ERR;
574 } 571 }
575 if ( (strlen (&s[npos]) <= SIGNATURE_ASCII_LENGTH + 1) || 572 if ((strlen (&s[npos]) <= SIGNATURE_ASCII_LENGTH + 1) ||
576 ('.' != s[npos + SIGNATURE_ASCII_LENGTH]) ) 573 ('.' != s[npos + SIGNATURE_ASCII_LENGTH]))
577 { 574 {
578 *emsg = GNUNET_strdup (_("LOC URI malformed (wrong syntax for signature)")); 575 *emsg =
576 GNUNET_strdup (_ ("LOC URI malformed (wrong syntax for signature)"));
579 goto ERR; 577 goto ERR;
580 } 578 }
581 if (GNUNET_OK != 579 if (GNUNET_OK !=
582 GNUNET_STRINGS_string_to_data (&s[npos], 580 GNUNET_STRINGS_string_to_data (&s[npos],
583 SIGNATURE_ASCII_LENGTH, 581 SIGNATURE_ASCII_LENGTH,
584 &sig, 582 &sig,
585 sizeof (struct GNUNET_CRYPTO_EddsaSignature))) 583 sizeof (
584 struct GNUNET_CRYPTO_EddsaSignature)))
586 { 585 {
587 *emsg = GNUNET_strdup (_("LOC URI malformed (could not decode signature)")); 586 *emsg =
587 GNUNET_strdup (_ ("LOC URI malformed (could not decode signature)"));
588 goto ERR; 588 goto ERR;
589 } 589 }
590 npos += SIGNATURE_ASCII_LENGTH; 590 npos += SIGNATURE_ASCII_LENGTH;
591 if (s[npos++] != '.') 591 if (s[npos++] != '.')
592 { 592 {
593 *emsg = GNUNET_strdup (_("LOC URI malformed (wrong syntax for expiration time)")); 593 *emsg = GNUNET_strdup (
594 _ ("LOC URI malformed (wrong syntax for expiration time)"));
594 goto ERR; 595 goto ERR;
595 } 596 }
596 if (1 != SSCANF (&s[npos], "%llu", &exptime)) 597 if (1 != sscanf (&s[npos], "%llu", &exptime))
597 { 598 {
598 *emsg = 599 *emsg =
599 GNUNET_strdup (_("LOC URI malformed (could not parse expiration time)")); 600 GNUNET_strdup (_ ("LOC URI malformed (could not parse expiration time)"));
600 goto ERR; 601 goto ERR;
601 } 602 }
602 ass.purpose.size = htonl (sizeof (struct LocUriAssembly)); 603 ass.purpose.size = htonl (sizeof (struct LocUriAssembly));
@@ -605,10 +606,12 @@ uri_loc_parse (const char *s,
605 ass.exptime = GNUNET_TIME_absolute_hton (et); 606 ass.exptime = GNUNET_TIME_absolute_hton (et);
606 if (GNUNET_OK != 607 if (GNUNET_OK !=
607 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT, 608 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT,
608 &ass.purpose, &sig, &ass.peer.public_key)) 609 &ass.purpose,
610 &sig,
611 &ass.peer.public_key))
609 { 612 {
610 *emsg = 613 *emsg =
611 GNUNET_strdup (_("LOC URI malformed (signature failed validation)")); 614 GNUNET_strdup (_ ("LOC URI malformed (signature failed validation)"));
612 goto ERR; 615 goto ERR;
613 } 616 }
614 uri = GNUNET_new (struct GNUNET_FS_Uri); 617 uri = GNUNET_new (struct GNUNET_FS_Uri);
@@ -632,8 +635,7 @@ ERR:
632 * @return NULL on error 635 * @return NULL on error
633 */ 636 */
634struct GNUNET_FS_Uri * 637struct GNUNET_FS_Uri *
635GNUNET_FS_uri_parse (const char *uri, 638GNUNET_FS_uri_parse (const char *uri, char **emsg)
636 char **emsg)
637{ 639{
638 struct GNUNET_FS_Uri *ret; 640 struct GNUNET_FS_Uri *ret;
639 char *msg; 641 char *msg;
@@ -642,7 +644,7 @@ GNUNET_FS_uri_parse (const char *uri,
642 { 644 {
643 GNUNET_break (0); 645 GNUNET_break (0);
644 if (NULL != emsg) 646 if (NULL != emsg)
645 *emsg = GNUNET_strdup (_("invalid argument")); 647 *emsg = GNUNET_strdup (_ ("invalid argument"));
646 return NULL; 648 return NULL;
647 } 649 }
648 if (NULL == emsg) 650 if (NULL == emsg)
@@ -654,7 +656,7 @@ GNUNET_FS_uri_parse (const char *uri,
654 (NULL != (ret = uri_loc_parse (uri, emsg)))) 656 (NULL != (ret = uri_loc_parse (uri, emsg))))
655 return ret; 657 return ret;
656 if (NULL == *emsg) 658 if (NULL == *emsg)
657 *emsg = GNUNET_strdup (_("Unrecognized URI type")); 659 *emsg = GNUNET_strdup (_ ("Unrecognized URI type"));
658 if (emsg == &msg) 660 if (emsg == &msg)
659 GNUNET_free (msg); 661 GNUNET_free (msg);
660 return NULL; 662 return NULL;
@@ -789,8 +791,9 @@ GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri,
789 if (0 == strcmp (&old[1], keyword)) 791 if (0 == strcmp (&old[1], keyword))
790 { 792 {
791 uri->data.ksk.keywords[i] = 793 uri->data.ksk.keywords[i] =
792 uri->data.ksk.keywords[uri->data.ksk.keywordCount - 1]; 794 uri->data.ksk.keywords[uri->data.ksk.keywordCount - 1];
793 GNUNET_array_grow (uri->data.ksk.keywords, uri->data.ksk.keywordCount, 795 GNUNET_array_grow (uri->data.ksk.keywords,
796 uri->data.ksk.keywordCount,
794 uri->data.ksk.keywordCount - 1); 797 uri->data.ksk.keywordCount - 1);
795 GNUNET_free (old); 798 GNUNET_free (old);
796 return; 799 return;
@@ -877,8 +880,7 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *base_uri,
877 return NULL; 880 return NULL;
878 /* we round expiration time to full seconds for SKS URIs */ 881 /* we round expiration time to full seconds for SKS URIs */
879 et.abs_value_us = (expiration_time.abs_value_us / 1000000LL) * 1000000LL; 882 et.abs_value_us = (expiration_time.abs_value_us / 1000000LL) * 1000000LL;
880 GNUNET_CRYPTO_eddsa_key_get_public (sign_key, 883 GNUNET_CRYPTO_eddsa_key_get_public (sign_key, &my_public_key);
881 &my_public_key);
882 ass.purpose.size = htonl (sizeof (struct LocUriAssembly)); 884 ass.purpose.size = htonl (sizeof (struct LocUriAssembly));
883 ass.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); 885 ass.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT);
884 ass.exptime = GNUNET_TIME_absolute_hton (et); 886 ass.exptime = GNUNET_TIME_absolute_hton (et);
@@ -906,7 +908,7 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *base_uri,
906 */ 908 */
907struct GNUNET_FS_Uri * 909struct GNUNET_FS_Uri *
908GNUNET_FS_uri_sks_create (const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, 910GNUNET_FS_uri_sks_create (const struct GNUNET_CRYPTO_EcdsaPublicKey *ns,
909 const char *id) 911 const char *id)
910{ 912{
911 struct GNUNET_FS_Uri *ns_uri; 913 struct GNUNET_FS_Uri *ns_uri;
912 914
@@ -951,8 +953,7 @@ GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
951 return NULL; 953 return NULL;
952 } 954 }
953 kc = u1->data.ksk.keywordCount; 955 kc = u1->data.ksk.keywordCount;
954 kl = GNUNET_new_array (kc + u2->data.ksk.keywordCount, 956 kl = GNUNET_new_array (kc + u2->data.ksk.keywordCount, char *);
955 char *);
956 for (i = 0; i < u1->data.ksk.keywordCount; i++) 957 for (i = 0; i < u1->data.ksk.keywordCount; i++)
957 kl[i] = GNUNET_strdup (u1->data.ksk.keywords[i]); 958 kl[i] = GNUNET_strdup (u1->data.ksk.keywords[i]);
958 for (i = 0; i < u2->data.ksk.keywordCount; i++) 959 for (i = 0; i < u2->data.ksk.keywordCount; i++)
@@ -1006,14 +1007,13 @@ GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri)
1006 } 1007 }
1007 if (ret->data.ksk.keywordCount > 0) 1008 if (ret->data.ksk.keywordCount > 0)
1008 { 1009 {
1009 ret->data.ksk.keywords 1010 ret->data.ksk.keywords =
1010 = GNUNET_new_array (ret->data.ksk.keywordCount, 1011 GNUNET_new_array (ret->data.ksk.keywordCount, char *);
1011 char *);
1012 for (i = 0; i < ret->data.ksk.keywordCount; i++) 1012 for (i = 0; i < ret->data.ksk.keywordCount; i++)
1013 ret->data.ksk.keywords[i] = GNUNET_strdup (uri->data.ksk.keywords[i]); 1013 ret->data.ksk.keywords[i] = GNUNET_strdup (uri->data.ksk.keywords[i]);
1014 } 1014 }
1015 else 1015 else
1016 ret->data.ksk.keywords = NULL; /* just to be sure */ 1016 ret->data.ksk.keywords = NULL; /* just to be sure */
1017 break; 1017 break;
1018 case GNUNET_FS_URI_SKS: 1018 case GNUNET_FS_URI_SKS:
1019 ret->data.sks.identifier = GNUNET_strdup (uri->data.sks.identifier); 1019 ret->data.sks.identifier = GNUNET_strdup (uri->data.sks.identifier);
@@ -1045,8 +1045,7 @@ GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri)
1045 * if keywords is not legal (i.e. empty). 1045 * if keywords is not legal (i.e. empty).
1046 */ 1046 */
1047struct GNUNET_FS_Uri * 1047struct GNUNET_FS_Uri *
1048GNUNET_FS_uri_ksk_create (const char *keywords, 1048GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg)
1049 char **emsg)
1050{ 1049{
1051 char **keywordarr; 1050 char **keywordarr;
1052 unsigned int num_Words; 1051 unsigned int num_Words;
@@ -1058,7 +1057,7 @@ GNUNET_FS_uri_ksk_create (const char *keywords,
1058 1057
1059 if (keywords == NULL) 1058 if (keywords == NULL)
1060 { 1059 {
1061 *emsg = GNUNET_strdup (_("No keywords specified!\n")); 1060 *emsg = GNUNET_strdup (_ ("No keywords specified!\n"));
1062 GNUNET_break (0); 1061 GNUNET_break (0);
1063 return NULL; 1062 return NULL;
1064 } 1063 }
@@ -1085,17 +1084,16 @@ GNUNET_FS_uri_ksk_create (const char *keywords,
1085 if (num_Words == 0) 1084 if (num_Words == 0)
1086 { 1085 {
1087 GNUNET_free (searchString); 1086 GNUNET_free (searchString);
1088 *emsg = GNUNET_strdup (_("No keywords specified!\n")); 1087 *emsg = GNUNET_strdup (_ ("No keywords specified!\n"));
1089 return NULL; 1088 return NULL;
1090 } 1089 }
1091 if (saw_quote != 0) 1090 if (saw_quote != 0)
1092 { 1091 {
1093 GNUNET_free (searchString); 1092 GNUNET_free (searchString);
1094 *emsg = GNUNET_strdup (_("Number of double-quotes not balanced!\n")); 1093 *emsg = GNUNET_strdup (_ ("Number of double-quotes not balanced!\n"));
1095 return NULL; 1094 return NULL;
1096 } 1095 }
1097 keywordarr = GNUNET_new_array (num_Words, 1096 keywordarr = GNUNET_new_array (num_Words, char *);
1098 char *);
1099 num_Words = 0; 1097 num_Words = 0;
1100 inWord = 0; 1098 inWord = 0;
1101 pos = searchString; 1099 pos = searchString;
@@ -1117,8 +1115,7 @@ GNUNET_FS_uri_ksk_create (const char *keywords,
1117 pos++; 1115 pos++;
1118 } 1116 }
1119 uri = 1117 uri =
1120 GNUNET_FS_uri_ksk_create_from_args (num_Words, 1118 GNUNET_FS_uri_ksk_create_from_args (num_Words, (const char **) keywordarr);
1121 (const char **) keywordarr);
1122 GNUNET_free (keywordarr); 1119 GNUNET_free (keywordarr);
1123 GNUNET_free (searchString); 1120 GNUNET_free (searchString);
1124 return uri; 1121 return uri;
@@ -1143,8 +1140,7 @@ GNUNET_FS_uri_ksk_create (const char *keywords,
1143 * if keywords is not legal (i.e. empty). 1140 * if keywords is not legal (i.e. empty).
1144 */ 1141 */
1145struct GNUNET_FS_Uri * 1142struct GNUNET_FS_Uri *
1146GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, 1143GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv)
1147 const char **argv)
1148{ 1144{
1149 unsigned int i; 1145 unsigned int i;
1150 struct GNUNET_FS_Uri *uri; 1146 struct GNUNET_FS_Uri *uri;
@@ -1160,16 +1156,16 @@ GNUNET_FS_uri_ksk_create_from_args (unsigned int argc,
1160 * handle accordingly */ 1156 * handle accordingly */
1161 emsg = NULL; 1157 emsg = NULL;
1162 if ((argc == 1) && (strlen (argv[0]) > strlen (GNUNET_FS_URI_PREFIX)) && 1158 if ((argc == 1) && (strlen (argv[0]) > strlen (GNUNET_FS_URI_PREFIX)) &&
1163 (0 == 1159 (0 == strncmp (argv[0],
1164 strncmp (argv[0], GNUNET_FS_URI_PREFIX, strlen (GNUNET_FS_URI_PREFIX))) 1160 GNUNET_FS_URI_PREFIX,
1165 && (NULL != (uri = GNUNET_FS_uri_parse (argv[0], &emsg)))) 1161 strlen (GNUNET_FS_URI_PREFIX))) &&
1162 (NULL != (uri = GNUNET_FS_uri_parse (argv[0], &emsg))))
1166 return uri; 1163 return uri;
1167 GNUNET_free_non_null (emsg); 1164 GNUNET_free_non_null (emsg);
1168 uri = GNUNET_new (struct GNUNET_FS_Uri); 1165 uri = GNUNET_new (struct GNUNET_FS_Uri);
1169 uri->type = GNUNET_FS_URI_KSK; 1166 uri->type = GNUNET_FS_URI_KSK;
1170 uri->data.ksk.keywordCount = argc; 1167 uri->data.ksk.keywordCount = argc;
1171 uri->data.ksk.keywords = GNUNET_new_array (argc, 1168 uri->data.ksk.keywords = GNUNET_new_array (argc, char *);
1172 char *);
1173 for (i = 0; i < argc; i++) 1169 for (i = 0; i < argc; i++)
1174 { 1170 {
1175 keyword = argv[i]; 1171 keyword = argv[i];
@@ -1220,9 +1216,9 @@ GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
1220 return GNUNET_YES; 1216 return GNUNET_YES;
1221 return GNUNET_NO; 1217 return GNUNET_NO;
1222 case GNUNET_FS_URI_SKS: 1218 case GNUNET_FS_URI_SKS:
1223 if ((0 == 1219 if ((0 == memcmp (&u1->data.sks.ns,
1224 memcmp (&u1->data.sks.ns, &u2->data.sks.ns, 1220 &u2->data.sks.ns,
1225 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) && 1221 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) &&
1226 (0 == strcmp (u1->data.sks.identifier, u2->data.sks.identifier))) 1222 (0 == strcmp (u1->data.sks.identifier, u2->data.sks.identifier)))
1227 1223
1228 return GNUNET_YES; 1224 return GNUNET_YES;
@@ -1246,12 +1242,12 @@ GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
1246 } 1242 }
1247 return GNUNET_YES; 1243 return GNUNET_YES;
1248 case GNUNET_FS_URI_LOC: 1244 case GNUNET_FS_URI_LOC:
1249 if (memcmp 1245 if (memcmp (&u1->data.loc,
1250 (&u1->data.loc, &u2->data.loc, 1246 &u2->data.loc,
1251 sizeof (struct FileIdentifier) + 1247 sizeof (struct FileIdentifier) +
1252 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) + 1248 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) +
1253 sizeof (struct GNUNET_TIME_Absolute) + sizeof (unsigned short) + 1249 sizeof (struct GNUNET_TIME_Absolute) +
1254 sizeof (unsigned short)) != 0) 1250 sizeof (unsigned short) + sizeof (unsigned short)) != 0)
1255 return GNUNET_NO; 1251 return GNUNET_NO;
1256 return GNUNET_YES; 1252 return GNUNET_YES;
1257 default: 1253 default:
@@ -1285,7 +1281,7 @@ int
1285GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri, 1281GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
1286 struct GNUNET_CRYPTO_EcdsaPublicKey *pseudonym) 1282 struct GNUNET_CRYPTO_EcdsaPublicKey *pseudonym)
1287{ 1283{
1288 if (!GNUNET_FS_uri_test_sks (uri)) 1284 if (! GNUNET_FS_uri_test_sks (uri))
1289 { 1285 {
1290 GNUNET_break (0); 1286 GNUNET_break (0);
1291 return GNUNET_SYSERR; 1287 return GNUNET_SYSERR;
@@ -1304,7 +1300,7 @@ GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
1304char * 1300char *
1305GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri) 1301GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri)
1306{ 1302{
1307 if (!GNUNET_FS_uri_test_sks (uri)) 1303 if (! GNUNET_FS_uri_test_sks (uri))
1308 { 1304 {
1309 GNUNET_break (0); 1305 GNUNET_break (0);
1310 return NULL; 1306 return NULL;
@@ -1327,7 +1323,7 @@ GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri)
1327 1323
1328 if (uri->type == GNUNET_FS_URI_KSK) 1324 if (uri->type == GNUNET_FS_URI_KSK)
1329 { 1325 {
1330 for (i=0;i < uri->data.ksk.keywordCount; i++) 1326 for (i = 0; i < uri->data.ksk.keywordCount; i++)
1331 GNUNET_assert (uri->data.ksk.keywords[i] != NULL); 1327 GNUNET_assert (uri->data.ksk.keywords[i] != NULL);
1332 } 1328 }
1333#endif 1329#endif
@@ -1356,7 +1352,7 @@ GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri)
1356 * @return size of the file as specified in the CHK URI 1352 * @return size of the file as specified in the CHK URI
1357 */ 1353 */
1358uint64_t 1354uint64_t
1359GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri * uri) 1355GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri)
1360{ 1356{
1361 switch (uri->type) 1357 switch (uri->type)
1362 { 1358 {
@@ -1367,7 +1363,7 @@ GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri * uri)
1367 default: 1363 default:
1368 GNUNET_assert (0); 1364 GNUNET_assert (0);
1369 } 1365 }
1370 return 0; /* unreachable */ 1366 return 0; /* unreachable */
1371} 1367}
1372 1368
1373 1369
@@ -1394,9 +1390,7 @@ GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri)
1394 * @param index offset where to add the keyword 1390 * @param index offset where to add the keyword
1395 */ 1391 */
1396static void 1392static void
1397insert_non_mandatory_keyword (const char *s, 1393insert_non_mandatory_keyword (const char *s, char **array, int index)
1398 char **array,
1399 int index)
1400{ 1394{
1401 char *nkword; 1395 char *nkword;
1402 1396
@@ -1417,9 +1411,7 @@ insert_non_mandatory_keyword (const char *s,
1417 * @return #GNUNET_YES if the keyword exists, #GNUNET_NO if not 1411 * @return #GNUNET_YES if the keyword exists, #GNUNET_NO if not
1418 */ 1412 */
1419static int 1413static int
1420find_duplicate (const char *s, 1414find_duplicate (const char *s, const char **array, int array_length)
1421 const char **array,
1422 int array_length)
1423{ 1415{
1424 int j; 1416 int j;
1425 1417
@@ -1455,12 +1447,19 @@ normalize_metadata (enum EXTRACTOR_MetaFormat format,
1455 } 1447 }
1456 if (format == EXTRACTOR_METAFORMAT_C_STRING) 1448 if (format == EXTRACTOR_METAFORMAT_C_STRING)
1457 { 1449 {
1458 free_str = u8_strconv_from_encoding (data, locale_charset (), iconveh_escape_sequence); 1450 free_str = u8_strconv_from_encoding (data,
1451 locale_charset (),
1452 iconveh_escape_sequence);
1459 if (free_str == NULL) 1453 if (free_str == NULL)
1460 return NULL; 1454 return NULL;
1461 } 1455 }
1462 1456
1463 normalized = u8_tolower (str_to_normalize, strlen ((char *) str_to_normalize), NULL, UNINORM_NFD, NULL, &r_len); 1457 normalized = u8_tolower (str_to_normalize,
1458 strlen ((char *) str_to_normalize),
1459 NULL,
1460 UNINORM_NFD,
1461 NULL,
1462 &r_len);
1464 /* free_str is allocated by libunistring internally, use free() */ 1463 /* free_str is allocated by libunistring internally, use free() */
1465 if (free_str != NULL) 1464 if (free_str != NULL)
1466 free (free_str); 1465 free (free_str);
@@ -1512,9 +1511,7 @@ u8_strcount (const uint8_t *s)
1512 * were duplicates (when extracting). 1511 * were duplicates (when extracting).
1513 */ 1512 */
1514static int 1513static int
1515get_keywords_from_parens (const char *s, 1514get_keywords_from_parens (const char *s, char **array, int index)
1516 char **array,
1517 int index)
1518{ 1515{
1519 int count = 0; 1516 int count = 0;
1520 char *open_paren; 1517 char *open_paren;
@@ -1564,28 +1561,33 @@ get_keywords_from_parens (const char *s,
1564 { 1561 {
1565 char *normalized; 1562 char *normalized;
1566 if (GNUNET_NO == find_duplicate ((const char *) &open_paren[1], 1563 if (GNUNET_NO == find_duplicate ((const char *) &open_paren[1],
1567 (const char **) array, index + count)) 1564 (const char **) array,
1565 index + count))
1568 { 1566 {
1569 insert_non_mandatory_keyword ((const char *) &open_paren[1], array, 1567 insert_non_mandatory_keyword ((const char *) &open_paren[1],
1570 index + count); 1568 array,
1569 index + count);
1571 count++; 1570 count++;
1572 } 1571 }
1573 normalized = normalize_metadata (EXTRACTOR_METAFORMAT_UTF8, 1572 normalized = normalize_metadata (EXTRACTOR_METAFORMAT_UTF8,
1574 &open_paren[1], close_paren - &open_paren[1]); 1573 &open_paren[1],
1574 close_paren - &open_paren[1]);
1575 if (normalized != NULL) 1575 if (normalized != NULL)
1576 { 1576 {
1577 if (GNUNET_NO == find_duplicate ((const char *) normalized, 1577 if (GNUNET_NO == find_duplicate ((const char *) normalized,
1578 (const char **) array, index + count)) 1578 (const char **) array,
1579 index + count))
1579 { 1580 {
1580 insert_non_mandatory_keyword ((const char *) normalized, array, 1581 insert_non_mandatory_keyword ((const char *) normalized,
1581 index + count); 1582 array,
1583 index + count);
1582 count++; 1584 count++;
1583 } 1585 }
1584 GNUNET_free (normalized); 1586 GNUNET_free (normalized);
1585 } 1587 }
1586 } 1588 }
1587 else 1589 else
1588 count++; 1590 count++;
1589 close_paren[0] = tmp; 1591 close_paren[0] = tmp;
1590 } 1592 }
1591 } 1593 }
@@ -1614,9 +1616,7 @@ get_keywords_from_parens (const char *s,
1614 * duplicates (when extracting). 1616 * duplicates (when extracting).
1615 */ 1617 */
1616static int 1618static int
1617get_keywords_from_tokens (const char *s, 1619get_keywords_from_tokens (const char *s, char **array, int index)
1618 char **array,
1619 int index)
1620{ 1620{
1621 char *p; 1621 char *p;
1622 char *ss; 1622 char *ss;
@@ -1633,19 +1633,20 @@ get_keywords_from_tokens (const char *s,
1633 char *normalized; 1633 char *normalized;
1634 if (GNUNET_NO == find_duplicate (p, (const char **) array, index + seps)) 1634 if (GNUNET_NO == find_duplicate (p, (const char **) array, index + seps))
1635 { 1635 {
1636 insert_non_mandatory_keyword (p, array, 1636 insert_non_mandatory_keyword (p, array, index + seps);
1637 index + seps); 1637 seps++;
1638 seps++;
1639 } 1638 }
1640 normalized = normalize_metadata (EXTRACTOR_METAFORMAT_UTF8, 1639 normalized =
1641 p, strlen (p)); 1640 normalize_metadata (EXTRACTOR_METAFORMAT_UTF8, p, strlen (p));
1642 if (normalized != NULL) 1641 if (normalized != NULL)
1643 { 1642 {
1644 if (GNUNET_NO == find_duplicate ((const char *) normalized, 1643 if (GNUNET_NO == find_duplicate ((const char *) normalized,
1645 (const char **) array, index + seps)) 1644 (const char **) array,
1645 index + seps))
1646 { 1646 {
1647 insert_non_mandatory_keyword ((const char *) normalized, array, 1647 insert_non_mandatory_keyword ((const char *) normalized,
1648 index + seps); 1648 array,
1649 index + seps);
1649 seps++; 1650 seps++;
1650 } 1651 }
1651 GNUNET_free (normalized); 1652 GNUNET_free (normalized);
@@ -1678,7 +1679,8 @@ get_keywords_from_tokens (const char *s,
1678 * @return 0 (always) 1679 * @return 0 (always)
1679 */ 1680 */
1680static int 1681static int
1681gather_uri_data (void *cls, const char *plugin_name, 1682gather_uri_data (void *cls,
1683 const char *plugin_name,
1682 enum EXTRACTOR_MetaType type, 1684 enum EXTRACTOR_MetaType type,
1683 enum EXTRACTOR_MetaFormat format, 1685 enum EXTRACTOR_MetaFormat format,
1684 const char *data_mime_type, 1686 const char *data_mime_type,
@@ -1699,16 +1701,12 @@ gather_uri_data (void *cls, const char *plugin_name,
1699 */ 1701 */
1700 if (u8_strcount ((const uint8_t *) data) <= 2) 1702 if (u8_strcount ((const uint8_t *) data) <= 2)
1701 return 0; 1703 return 0;
1702 if ( (EXTRACTOR_METATYPE_MIMETYPE == type) && 1704 if ((EXTRACTOR_METATYPE_MIMETYPE == type) &&
1703 (NULL != (sep = memchr (data, '/', data_len))) && 1705 (NULL != (sep = memchr (data, '/', data_len))) && (sep != data))
1704 (sep != data) )
1705 { 1706 {
1706 char *xtra; 1707 char *xtra;
1707 1708
1708 GNUNET_asprintf (&xtra, 1709 GNUNET_asprintf (&xtra, "mimetype:%.*s", (int) (sep - data), data);
1709 "mimetype:%.*s",
1710 (int) (sep - data),
1711 data);
1712 if (! find_duplicate (xtra, 1710 if (! find_duplicate (xtra,
1713 (const char **) uri->data.ksk.keywords, 1711 (const char **) uri->data.ksk.keywords,
1714 uri->data.ksk.keywordCount)) 1712 uri->data.ksk.keywordCount))
@@ -1727,17 +1725,19 @@ gather_uri_data (void *cls, const char *plugin_name,
1727 uri->data.ksk.keywordCount)) 1725 uri->data.ksk.keywordCount))
1728 { 1726 {
1729 insert_non_mandatory_keyword (data, 1727 insert_non_mandatory_keyword (data,
1730 uri->data.ksk.keywords, uri->data.ksk.keywordCount); 1728 uri->data.ksk.keywords,
1729 uri->data.ksk.keywordCount);
1731 uri->data.ksk.keywordCount++; 1730 uri->data.ksk.keywordCount++;
1732 } 1731 }
1733 if (NULL != normalized_data) 1732 if (NULL != normalized_data)
1734 { 1733 {
1735 if (! find_duplicate (normalized_data, 1734 if (! find_duplicate (normalized_data,
1736 (const char **) uri->data.ksk.keywords, 1735 (const char **) uri->data.ksk.keywords,
1737 uri->data.ksk.keywordCount)) 1736 uri->data.ksk.keywordCount))
1738 { 1737 {
1739 insert_non_mandatory_keyword (normalized_data, 1738 insert_non_mandatory_keyword (normalized_data,
1740 uri->data.ksk.keywords, uri->data.ksk.keywordCount); 1739 uri->data.ksk.keywords,
1740 uri->data.ksk.keywordCount);
1741 uri->data.ksk.keywordCount++; 1741 uri->data.ksk.keywordCount++;
1742 } 1742 }
1743 GNUNET_free (normalized_data); 1743 GNUNET_free (normalized_data);
@@ -1755,7 +1755,8 @@ gather_uri_data (void *cls, const char *plugin_name,
1755 * @return NULL on error, otherwise a KSK URI 1755 * @return NULL on error, otherwise a KSK URI
1756 */ 1756 */
1757struct GNUNET_FS_Uri * 1757struct GNUNET_FS_Uri *
1758GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData *md) 1758GNUNET_FS_uri_ksk_create_from_meta_data (
1759 const struct GNUNET_CONTAINER_MetaData *md)
1759{ 1760{
1760 struct GNUNET_FS_Uri *ret; 1761 struct GNUNET_FS_Uri *ret;
1761 char *filename; 1762 char *filename;
@@ -1772,8 +1773,10 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
1772 ent = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL); 1773 ent = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL);
1773 if (ent > 0) 1774 if (ent > 0)
1774 { 1775 {
1775 full_name = GNUNET_CONTAINER_meta_data_get_first_by_types (md, 1776 full_name = GNUNET_CONTAINER_meta_data_get_first_by_types (
1776 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, -1); 1777 md,
1778 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
1779 -1);
1777 if (NULL != full_name) 1780 if (NULL != full_name)
1778 { 1781 {
1779 filename = full_name; 1782 filename = full_name;
@@ -1784,19 +1787,20 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
1784 } 1787 }
1785 /* x3 because there might be a normalized variant of every keyword, 1788 /* x3 because there might be a normalized variant of every keyword,
1786 plus theoretically one more for mime... */ 1789 plus theoretically one more for mime... */
1787 ret->data.ksk.keywords 1790 ret->data.ksk.keywords =
1788 = GNUNET_new_array ((ent + tok_keywords + paren_keywords) * 3, 1791 GNUNET_new_array ((ent + tok_keywords + paren_keywords) * 3, char *);
1789 char *);
1790 GNUNET_CONTAINER_meta_data_iterate (md, &gather_uri_data, ret); 1792 GNUNET_CONTAINER_meta_data_iterate (md, &gather_uri_data, ret);
1791 } 1793 }
1792 if (tok_keywords > 0) 1794 if (tok_keywords > 0)
1793 ret->data.ksk.keywordCount += get_keywords_from_tokens (filename, 1795 ret->data.ksk.keywordCount +=
1794 ret->data.ksk.keywords, 1796 get_keywords_from_tokens (filename,
1795 ret->data.ksk.keywordCount); 1797 ret->data.ksk.keywords,
1798 ret->data.ksk.keywordCount);
1796 if (paren_keywords > 0) 1799 if (paren_keywords > 0)
1797 ret->data.ksk.keywordCount += get_keywords_from_parens (filename, 1800 ret->data.ksk.keywordCount +=
1798 ret->data.ksk.keywords, 1801 get_keywords_from_parens (filename,
1799 ret->data.ksk.keywordCount); 1802 ret->data.ksk.keywords,
1803 ret->data.ksk.keywordCount);
1800 if (ent > 0) 1804 if (ent > 0)
1801 GNUNET_free_non_null (full_name); 1805 GNUNET_free_non_null (full_name);
1802 return ret; 1806 return ret;
@@ -1810,9 +1814,8 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
1810static int 1814static int
1811needs_percent (char c) 1815needs_percent (char c)
1812{ 1816{
1813 return (! 1817 return (! ((isalnum ((unsigned char) c)) || (c == '-') || (c == '_') ||
1814 ((isalnum ((unsigned char) c)) || (c == '-') || (c == '_') || 1818 (c == '.') || (c == '~')));
1815 (c == '.') || (c == '~')));
1816} 1819}
1817 1820
1818 1821
@@ -1851,10 +1854,10 @@ uri_ksk_to_string (const struct GNUNET_FS_Uri *uri)
1851 if ((j == 0) && (keyword[j] == ' ')) 1854 if ((j == 0) && (keyword[j] == ' '))
1852 { 1855 {
1853 n--; 1856 n--;
1854 continue; /* skip leading space */ 1857 continue; /* skip leading space */
1855 } 1858 }
1856 if (needs_percent (keyword[j])) 1859 if (needs_percent (keyword[j]))
1857 n += 2; /* will use %-encoding */ 1860 n += 2; /* will use %-encoding */
1858 } 1861 }
1859 } 1862 }
1860 ret = GNUNET_malloc (n); 1863 ret = GNUNET_malloc (n);
@@ -1868,7 +1871,7 @@ uri_ksk_to_string (const struct GNUNET_FS_Uri *uri)
1868 for (j = 0; j < slen; j++) 1871 for (j = 0; j < slen; j++)
1869 { 1872 {
1870 if ((j == 0) && (keyword[j] == ' ')) 1873 if ((j == 0) && (keyword[j] == ' '))
1871 continue; /* skip leading space */ 1874 continue; /* skip leading space */
1872 if (needs_percent (keyword[j])) 1875 if (needs_percent (keyword[j]))
1873 { 1876 {
1874 sprintf (&ret[wpos], "%%%02X", (unsigned char) keyword[j]); 1877 sprintf (&ret[wpos], "%%%02X", (unsigned char) keyword[j]);
@@ -1900,15 +1903,19 @@ uri_sks_to_string (const struct GNUNET_FS_Uri *uri)
1900 1903
1901 if (GNUNET_FS_URI_SKS != uri->type) 1904 if (GNUNET_FS_URI_SKS != uri->type)
1902 return NULL; 1905 return NULL;
1903 ret = GNUNET_STRINGS_data_to_string (&uri->data.sks.ns, 1906 ret =
1904 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), 1907 GNUNET_STRINGS_data_to_string (&uri->data.sks.ns,
1905 buf, 1908 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey),
1906 sizeof (buf)); 1909 buf,
1910 sizeof (buf));
1907 GNUNET_assert (NULL != ret); 1911 GNUNET_assert (NULL != ret);
1908 ret[0] = '\0'; 1912 ret[0] = '\0';
1909 GNUNET_asprintf (&ret, "%s%s%s/%s", GNUNET_FS_URI_PREFIX, 1913 GNUNET_asprintf (&ret,
1910 GNUNET_FS_URI_SKS_INFIX, buf, 1914 "%s%s%s/%s",
1911 uri->data.sks.identifier); 1915 GNUNET_FS_URI_PREFIX,
1916 GNUNET_FS_URI_SKS_INFIX,
1917 buf,
1918 uri->data.sks.identifier);
1912 return ret; 1919 return ret;
1913} 1920}
1914 1921
@@ -1933,9 +1940,13 @@ uri_chk_to_string (const struct GNUNET_FS_Uri *uri)
1933 GNUNET_CRYPTO_hash_to_enc (&fi->chk.key, &keyhash); 1940 GNUNET_CRYPTO_hash_to_enc (&fi->chk.key, &keyhash);
1934 GNUNET_CRYPTO_hash_to_enc (&fi->chk.query, &queryhash); 1941 GNUNET_CRYPTO_hash_to_enc (&fi->chk.query, &queryhash);
1935 1942
1936 GNUNET_asprintf (&ret, "%s%s%s.%s.%llu", GNUNET_FS_URI_PREFIX, 1943 GNUNET_asprintf (&ret,
1937 GNUNET_FS_URI_CHK_INFIX, (const char *) &keyhash, 1944 "%s%s%s.%s.%llu",
1938 (const char *) &queryhash, GNUNET_ntohll (fi->file_length)); 1945 GNUNET_FS_URI_PREFIX,
1946 GNUNET_FS_URI_CHK_INFIX,
1947 (const char *) &keyhash,
1948 (const char *) &queryhash,
1949 GNUNET_ntohll (fi->file_length));
1939 return ret; 1950 return ret;
1940} 1951}
1941 1952
@@ -1959,20 +1970,25 @@ uri_loc_to_string (const struct GNUNET_FS_Uri *uri)
1959 GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.query, &queryhash); 1970 GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.query, &queryhash);
1960 peer_id = 1971 peer_id =
1961 GNUNET_CRYPTO_eddsa_public_key_to_string (&uri->data.loc.peer.public_key); 1972 GNUNET_CRYPTO_eddsa_public_key_to_string (&uri->data.loc.peer.public_key);
1962 GNUNET_assert (NULL != 1973 GNUNET_assert (
1963 GNUNET_STRINGS_data_to_string (&uri->data.loc.contentSignature, 1974 NULL !=
1964 sizeof (struct GNUNET_CRYPTO_EddsaSignature), 1975 GNUNET_STRINGS_data_to_string (&uri->data.loc.contentSignature,
1965 peer_sig, 1976 sizeof (struct GNUNET_CRYPTO_EddsaSignature),
1966 sizeof (peer_sig))); 1977 peer_sig,
1978 sizeof (peer_sig)));
1967 GNUNET_asprintf (&ret, 1979 GNUNET_asprintf (&ret,
1968 "%s%s%s.%s.%llu.%s.%s.%llu", GNUNET_FS_URI_PREFIX, 1980 "%s%s%s.%s.%llu.%s.%s.%llu",
1969 GNUNET_FS_URI_LOC_INFIX, (const char *) &keyhash, 1981 GNUNET_FS_URI_PREFIX,
1982 GNUNET_FS_URI_LOC_INFIX,
1983 (const char *) &keyhash,
1970 (const char *) &queryhash, 1984 (const char *) &queryhash,
1971 (unsigned long long) GNUNET_ntohll (uri->data.loc. 1985 (unsigned long long) GNUNET_ntohll (
1972 fi.file_length), 1986 uri->data.loc.fi.file_length),
1973 peer_id, 1987 peer_id,
1974 peer_sig, 1988 peer_sig,
1975 (unsigned long long) uri->data.loc.expirationTime.abs_value_us / 1000000LL); 1989 (unsigned long long)
1990 uri->data.loc.expirationTime.abs_value_us /
1991 1000000LL);
1976 GNUNET_free (peer_id); 1992 GNUNET_free (peer_id);
1977 return ret; 1993 return ret;
1978} 1994}
diff --git a/src/fs/gnunet-auto-share.c b/src/fs/gnunet-auto-share.c
index ba28c5c23..8b04e474d 100644
--- a/src/fs/gnunet-auto-share.c
+++ b/src/fs/gnunet-auto-share.c
@@ -512,7 +512,7 @@ determine_id (void *cls, const char *filename)
512 struct GNUNET_HashCode fx[2]; 512 struct GNUNET_HashCode fx[2];
513 struct GNUNET_HashCode ft; 513 struct GNUNET_HashCode ft;
514 514
515 if (0 != STAT (filename, &sbuf)) 515 if (0 != stat (filename, &sbuf))
516 { 516 {
517 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); 517 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
518 return GNUNET_OK; 518 return GNUNET_OK;
diff --git a/src/fs/gnunet-directory.c b/src/fs/gnunet-directory.c
index 097dd4406..4cce69d72 100644
--- a/src/fs/gnunet-directory.c
+++ b/src/fs/gnunet-directory.c
@@ -50,7 +50,7 @@ item_printer (void *cls,
50{ 50{
51 if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA) 51 if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA)
52 { 52 {
53 printf (_("\t<original file embedded in %u bytes of meta data>\n"), 53 printf (_ ("\t<original file embedded in %u bytes of meta data>\n"),
54 (unsigned int) data_size); 54 (unsigned int) data_size);
55 return 0; 55 return 0;
56 } 56 }
@@ -63,17 +63,14 @@ item_printer (void *cls,
63 printf ("\t%20s: %s\n", 63 printf ("\t%20s: %s\n",
64 dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, 64 dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN,
65 EXTRACTOR_metatype_to_string (type)), 65 EXTRACTOR_metatype_to_string (type)),
66 data);
67#else
68 printf ("\t%20d: %s\n",
69 type,
70 data); 66 data);
67#else
68 printf ("\t%20d: %s\n", type, data);
71#endif 69#endif
72 return 0; 70 return 0;
73} 71}
74 72
75 73
76
77/** 74/**
78 * Print an entry in a directory. 75 * Print an entry in a directory.
79 * 76 *
@@ -90,22 +87,25 @@ item_printer (void *cls,
90 * @param data data available for the file (length bytes) 87 * @param data data available for the file (length bytes)
91 */ 88 */
92static void 89static void
93print_entry (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, 90print_entry (void *cls,
94 const struct GNUNET_CONTAINER_MetaData *meta, size_t length, 91 const char *filename,
92 const struct GNUNET_FS_Uri *uri,
93 const struct GNUNET_CONTAINER_MetaData *meta,
94 size_t length,
95 const void *data) 95 const void *data)
96{ 96{
97 char *string; 97 char *string;
98 char *name; 98 char *name;
99 99
100 name = 100 name = GNUNET_CONTAINER_meta_data_get_by_type (
101 GNUNET_CONTAINER_meta_data_get_by_type (meta, 101 meta,
102 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); 102 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
103 if (uri == NULL) 103 if (uri == NULL)
104 { 104 {
105 printf (_("Directory `%s' meta data:\n"), name ? name : ""); 105 printf (_ ("Directory `%s' meta data:\n"), name ? name : "");
106 GNUNET_CONTAINER_meta_data_iterate (meta, &item_printer, NULL); 106 GNUNET_CONTAINER_meta_data_iterate (meta, &item_printer, NULL);
107 printf ("\n"); 107 printf ("\n");
108 printf (_("Directory `%s' contents:\n"), name ? name : ""); 108 printf (_ ("Directory `%s' contents:\n"), name ? name : "");
109 GNUNET_free_non_null (name); 109 GNUNET_free_non_null (name);
110 return; 110 return;
111 } 111 }
@@ -127,7 +127,9 @@ print_entry (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri,
127 * @param cfg configuration 127 * @param cfg configuration
128 */ 128 */
129static void 129static void
130run (void *cls, char *const *args, const char *cfgfile, 130run (void *cls,
131 char *const *args,
132 const char *cfgfile,
131 const struct GNUNET_CONFIGURATION_Handle *cfg) 133 const struct GNUNET_CONFIGURATION_Handle *cfg)
132{ 134{
133 struct GNUNET_DISK_MapHandle *map; 135 struct GNUNET_DISK_MapHandle *map;
@@ -140,20 +142,21 @@ run (void *cls, char *const *args, const char *cfgfile,
140 142
141 if (NULL == args[0]) 143 if (NULL == args[0])
142 { 144 {
143 FPRINTF (stderr, "%s", _("You must specify a filename to inspect.\n")); 145 fprintf (stderr, "%s", _ ("You must specify a filename to inspect.\n"));
144 ret = 1; 146 ret = 1;
145 return; 147 return;
146 } 148 }
147 i = 0; 149 i = 0;
148 while (NULL != (filename = args[i++])) 150 while (NULL != (filename = args[i++]))
149 { 151 {
150 if ((GNUNET_OK != GNUNET_DISK_file_size (filename, &size, GNUNET_YES, GNUNET_YES)) || 152 if ((GNUNET_OK !=
151 (NULL == 153 GNUNET_DISK_file_size (filename, &size, GNUNET_YES, GNUNET_YES)) ||
152 (h = 154 (NULL == (h = GNUNET_DISK_file_open (filename,
153 GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, 155 GNUNET_DISK_OPEN_READ,
154 GNUNET_DISK_PERM_NONE)))) 156 GNUNET_DISK_PERM_NONE))))
155 { 157 {
156 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to read directory `%s'\n"), 158 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
159 _ ("Failed to read directory `%s'\n"),
157 filename); 160 filename);
158 ret = 1; 161 ret = 1;
159 continue; 162 continue;
@@ -161,9 +164,9 @@ run (void *cls, char *const *args, const char *cfgfile,
161 len = (size_t) size; 164 len = (size_t) size;
162 data = GNUNET_DISK_file_map (h, &map, GNUNET_DISK_MAP_TYPE_READ, len); 165 data = GNUNET_DISK_file_map (h, &map, GNUNET_DISK_MAP_TYPE_READ, len);
163 GNUNET_assert (NULL != data); 166 GNUNET_assert (NULL != data);
164 if (GNUNET_OK != GNUNET_FS_directory_list_contents (len, data, 0, &print_entry, NULL)) 167 if (GNUNET_OK !=
165 fprintf (stdout, _("`%s' is not a GNUnet directory\n"), 168 GNUNET_FS_directory_list_contents (len, data, 0, &print_entry, NULL))
166 filename); 169 fprintf (stdout, _ ("`%s' is not a GNUnet directory\n"), filename);
167 else 170 else
168 printf ("\n"); 171 printf ("\n");
169 GNUNET_DISK_file_unmap (map); 172 GNUNET_DISK_file_unmap (map);
@@ -182,18 +185,23 @@ int
182main (int argc, char *const *argv) 185main (int argc, char *const *argv)
183{ 186{
184 static struct GNUNET_GETOPT_CommandLineOption options[] = { 187 static struct GNUNET_GETOPT_CommandLineOption options[] = {
185 GNUNET_GETOPT_OPTION_END 188 GNUNET_GETOPT_OPTION_END};
186 };
187 189
188 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 190 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
189 return 2; 191 return 2;
190 192
191 ret = (GNUNET_OK == 193 ret = (GNUNET_OK ==
192 GNUNET_PROGRAM_run (argc, argv, "gnunet-directory [OPTIONS] FILENAME", 194 GNUNET_PROGRAM_run (argc,
193 gettext_noop 195 argv,
194 ("Display contents of a GNUnet directory"), 196 "gnunet-directory [OPTIONS] FILENAME",
195 options, &run, NULL)) ? ret : 1; 197 gettext_noop (
196 GNUNET_free ((void*) argv); 198 "Display contents of a GNUnet directory"),
199 options,
200 &run,
201 NULL))
202 ? ret
203 : 1;
204 GNUNET_free ((void *) argv);
197 return ret; 205 return ret;
198} 206}
199 207
diff --git a/src/fs/gnunet-download.c b/src/fs/gnunet-download.c
index 31e62c603..00e8336a2 100644
--- a/src/fs/gnunet-download.c
+++ b/src/fs/gnunet-download.c
@@ -80,33 +80,30 @@ shutdown_task (void *cls)
80 * @param w desired number of steps in the progress bar 80 * @param w desired number of steps in the progress bar
81 */ 81 */
82static void 82static void
83display_bar (unsigned long long x, 83display_bar (unsigned long long x, unsigned long long n, unsigned int w)
84 unsigned long long n,
85 unsigned int w)
86{ 84{
87 char buf[w + 20]; 85 char buf[w + 20];
88 unsigned int p; 86 unsigned int p;
89 unsigned int endeq; 87 unsigned int endeq;
90 float ratio_complete; 88 float ratio_complete;
91 89
92#if !WINDOWS 90#if ! WINDOWS
93 if (0 == isatty (1)) 91 if (0 == isatty (1))
94 return; 92 return;
95#else 93#else
96 if (FILE_TYPE_CHAR != GetFileType (GetStdHandle (STD_OUTPUT_HANDLE))) 94 if (FILE_TYPE_CHAR != GetFileType (GetStdHandle (STD_OUTPUT_HANDLE)))
97 return; 95 return;
98#endif 96#endif
99 ratio_complete = x/(float)n; 97 ratio_complete = x / (float) n;
100 endeq = ratio_complete * w; 98 endeq = ratio_complete * w;
101 GNUNET_snprintf (buf, sizeof (buf), 99 GNUNET_snprintf (buf, sizeof (buf), "%3d%% [", (int) (ratio_complete * 100));
102 "%3d%% [", (int)(ratio_complete*100) ); 100 for (p = 0; p < endeq; p++)
103 for (p=0; p<endeq; p++)
104 strcat (buf, "="); 101 strcat (buf, "=");
105 for (p=endeq; p<w; p++) 102 for (p = endeq; p < w; p++)
106 strcat (buf, " "); 103 strcat (buf, " ");
107 strcat (buf, "]\r"); 104 strcat (buf, "]\r");
108 printf ("%s", buf); 105 printf ("%s", buf);
109 fflush(stdout); 106 fflush (stdout);
110} 107}
111 108
112 109
@@ -124,8 +121,7 @@ display_bar (unsigned long long x,
124 * field in the `struct GNUNET_FS_ProgressInfo` 121 * field in the `struct GNUNET_FS_ProgressInfo`
125 */ 122 */
126static void * 123static void *
127progress_cb (void *cls, 124progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
128 const struct GNUNET_FS_ProgressInfo *info)
129{ 125{
130 char *s; 126 char *s;
131 const char *s2; 127 const char *s2;
@@ -135,71 +131,75 @@ progress_cb (void *cls,
135 { 131 {
136 case GNUNET_FS_STATUS_DOWNLOAD_START: 132 case GNUNET_FS_STATUS_DOWNLOAD_START:
137 if (verbose > 1) 133 if (verbose > 1)
138 FPRINTF (stderr, 134 fprintf (stderr,
139 _("Starting download `%s'.\n"), 135 _ ("Starting download `%s'.\n"),
140 info->value.download.filename); 136 info->value.download.filename);
141 break; 137 break;
142 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: 138 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
143 if (verbose) 139 if (verbose)
144 { 140 {
145 s = GNUNET_strdup (GNUNET_STRINGS_relative_time_to_string (info->value.download.eta, 141 s = GNUNET_strdup (
146 GNUNET_YES)); 142 GNUNET_STRINGS_relative_time_to_string (info->value.download.eta,
147 if (info->value.download.specifics.progress.block_download_duration.rel_value_us 143 GNUNET_YES));
148 == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) 144 if (info->value.download.specifics.progress.block_download_duration
149 s2 = _("<unknown time>"); 145 .rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
146 s2 = _ ("<unknown time>");
150 else 147 else
151 s2 = GNUNET_STRINGS_relative_time_to_string (info->value.download.specifics.progress.block_download_duration, 148 s2 = GNUNET_STRINGS_relative_time_to_string (info->value.download
152 GNUNET_YES); 149 .specifics.progress
153 t = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed * 150 .block_download_duration,
154 1000LL / 151 GNUNET_YES);
155 (info->value.download. 152 t = GNUNET_STRINGS_byte_size_fancy (
156 duration.rel_value_us + 1)); 153 info->value.download.completed * 1000LL /
157 FPRINTF (stdout, 154 (info->value.download.duration.rel_value_us + 1));
158 _("Downloading `%s' at %llu/%llu (%s remaining, %s/s). Block took %s to download\n"), 155 fprintf (
159 info->value.download.filename, 156 stdout,
160 (unsigned long long) info->value.download.completed, 157 _ (
161 (unsigned long long) info->value.download.size, 158 "Downloading `%s' at %llu/%llu (%s remaining, %s/s). Block took %s to download\n"),
162 s, 159 info->value.download.filename,
163 t, 160 (unsigned long long) info->value.download.completed,
164 s2); 161 (unsigned long long) info->value.download.size,
162 s,
163 t,
164 s2);
165 GNUNET_free (s); 165 GNUNET_free (s);
166 GNUNET_free (t); 166 GNUNET_free (t);
167 } 167 }
168 else 168 else
169 { 169 {
170 display_bar (info->value.download.completed, 170 display_bar (info->value.download.completed,
171 info->value.download.size, 171 info->value.download.size,
172 60); 172 60);
173 } 173 }
174 break; 174 break;
175 case GNUNET_FS_STATUS_DOWNLOAD_ERROR: 175 case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
176#if !WINDOWS 176#if ! WINDOWS
177 if (0 != isatty (1)) 177 if (0 != isatty (1))
178 fprintf (stdout, "\n"); 178 fprintf (stdout, "\n");
179#else 179#else
180 if (FILE_TYPE_CHAR == 180 if (FILE_TYPE_CHAR == GetFileType (GetStdHandle (STD_OUTPUT_HANDLE)))
181 GetFileType (GetStdHandle (STD_OUTPUT_HANDLE)))
182 fprintf (stdout, "\n"); 181 fprintf (stdout, "\n");
183#endif 182#endif
184 FPRINTF (stderr, _("Error downloading: %s.\n"), 183 fprintf (stderr,
184 _ ("Error downloading: %s.\n"),
185 info->value.download.specifics.error.message); 185 info->value.download.specifics.error.message);
186 GNUNET_SCHEDULER_shutdown (); 186 GNUNET_SCHEDULER_shutdown ();
187 break; 187 break;
188 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: 188 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
189 s = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed * 1000 / 189 s = GNUNET_STRINGS_byte_size_fancy (
190 (info->value.download. 190 info->value.download.completed * 1000 /
191 duration.rel_value_us + 1)); 191 (info->value.download.duration.rel_value_us + 1));
192#if !WINDOWS 192#if ! WINDOWS
193 if (0 != isatty (1)) 193 if (0 != isatty (1))
194 fprintf (stdout, "\n"); 194 fprintf (stdout, "\n");
195#else 195#else
196 if (FILE_TYPE_CHAR == 196 if (FILE_TYPE_CHAR == GetFileType (GetStdHandle (STD_OUTPUT_HANDLE)))
197 GetFileType (GetStdHandle (STD_OUTPUT_HANDLE)))
198 fprintf (stdout, "\n"); 197 fprintf (stdout, "\n");
199#endif 198#endif
200 FPRINTF (stdout, 199 fprintf (stdout,
201 _("Downloading `%s' done (%s/s).\n"), 200 _ ("Downloading `%s' done (%s/s).\n"),
202 info->value.download.filename, s); 201 info->value.download.filename,
202 s);
203 GNUNET_free (s); 203 GNUNET_free (s);
204 if (info->value.download.dc == dc) 204 if (info->value.download.dc == dc)
205 GNUNET_SCHEDULER_shutdown (); 205 GNUNET_SCHEDULER_shutdown ();
@@ -212,9 +212,7 @@ progress_cb (void *cls,
212 case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: 212 case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
213 break; 213 break;
214 default: 214 default:
215 FPRINTF (stderr, 215 fprintf (stderr, _ ("Unexpected status: %d\n"), info->status);
216 _("Unexpected status: %d\n"),
217 info->status);
218 break; 216 break;
219 } 217 }
220 return NULL; 218 return NULL;
@@ -241,55 +239,45 @@ run (void *cls,
241 239
242 if (NULL == args[0]) 240 if (NULL == args[0])
243 { 241 {
244 FPRINTF (stderr, 242 fprintf (stderr, "%s", _ ("You need to specify a URI argument.\n"));
245 "%s",
246 _("You need to specify a URI argument.\n"));
247 return; 243 return;
248 } 244 }
249 uri = GNUNET_FS_uri_parse (args[0], &emsg); 245 uri = GNUNET_FS_uri_parse (args[0], &emsg);
250 if (NULL == uri) 246 if (NULL == uri)
251 { 247 {
252 FPRINTF (stderr, 248 fprintf (stderr, _ ("Failed to parse URI: %s\n"), emsg);
253 _("Failed to parse URI: %s\n"),
254 emsg);
255 GNUNET_free (emsg); 249 GNUNET_free (emsg);
256 ret = 1; 250 ret = 1;
257 return; 251 return;
258 } 252 }
259 if ( (! GNUNET_FS_uri_test_chk (uri)) && 253 if ((! GNUNET_FS_uri_test_chk (uri)) && (! GNUNET_FS_uri_test_loc (uri)))
260 (! GNUNET_FS_uri_test_loc (uri)))
261 { 254 {
262 FPRINTF (stderr, 255 fprintf (stderr, "%s", _ ("Only CHK or LOC URIs supported.\n"));
263 "%s",
264 _("Only CHK or LOC URIs supported.\n"));
265 ret = 1; 256 ret = 1;
266 GNUNET_FS_uri_destroy (uri); 257 GNUNET_FS_uri_destroy (uri);
267 return; 258 return;
268 } 259 }
269 if (NULL == filename) 260 if (NULL == filename)
270 { 261 {
271 FPRINTF (stderr, 262 fprintf (stderr, "%s", _ ("Target filename must be specified.\n"));
272 "%s",
273 _("Target filename must be specified.\n"));
274 ret = 1; 263 ret = 1;
275 GNUNET_FS_uri_destroy (uri); 264 GNUNET_FS_uri_destroy (uri);
276 return; 265 return;
277 } 266 }
278 cfg = c; 267 cfg = c;
279 ctx = GNUNET_FS_start (cfg, 268 ctx = GNUNET_FS_start (cfg,
280 "gnunet-download", 269 "gnunet-download",
281 &progress_cb, NULL, 270 &progress_cb,
282 GNUNET_FS_FLAGS_NONE, 271 NULL,
283 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, 272 GNUNET_FS_FLAGS_NONE,
284 parallelism, 273 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM,
285 GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, 274 parallelism,
286 request_parallelism, 275 GNUNET_FS_OPTIONS_REQUEST_PARALLELISM,
287 GNUNET_FS_OPTIONS_END); 276 request_parallelism,
277 GNUNET_FS_OPTIONS_END);
288 if (NULL == ctx) 278 if (NULL == ctx)
289 { 279 {
290 FPRINTF (stderr, 280 fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS");
291 _("Could not initialize `%s' subsystem.\n"),
292 "FS");
293 GNUNET_FS_uri_destroy (uri); 281 GNUNET_FS_uri_destroy (uri);
294 ret = 1; 282 ret = 1;
295 return; 283 return;
@@ -300,16 +288,16 @@ run (void *cls,
300 if (local_only) 288 if (local_only)
301 options |= GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY; 289 options |= GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY;
302 dc = GNUNET_FS_download_start (ctx, 290 dc = GNUNET_FS_download_start (ctx,
303 uri, 291 uri,
304 NULL, 292 NULL,
305 filename, 293 filename,
306 NULL, 294 NULL,
307 0, 295 0,
308 GNUNET_FS_uri_chk_get_file_size (uri), 296 GNUNET_FS_uri_chk_get_file_size (uri),
309 anonymity, 297 anonymity,
310 options, 298 options,
311 NULL, 299 NULL,
312 NULL); 300 NULL);
313 GNUNET_FS_uri_destroy (uri); 301 GNUNET_FS_uri_destroy (uri);
314 if (dc == NULL) 302 if (dc == NULL)
315 { 303 {
@@ -317,8 +305,7 @@ run (void *cls,
317 ctx = NULL; 305 ctx = NULL;
318 return; 306 return;
319 } 307 }
320 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 308 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
321 NULL);
322} 309}
323 310
324 311
@@ -332,61 +319,73 @@ run (void *cls,
332int 319int
333main (int argc, char *const *argv) 320main (int argc, char *const *argv)
334{ 321{
335 struct GNUNET_GETOPT_CommandLineOption options[] = { 322 struct GNUNET_GETOPT_CommandLineOption options[] =
336 GNUNET_GETOPT_option_uint ('a', 323 {GNUNET_GETOPT_option_uint ('a',
337 "anonymity", 324 "anonymity",
338 "LEVEL", 325 "LEVEL",
339 gettext_noop ("set the desired LEVEL of receiver-anonymity"), 326 gettext_noop (
340 &anonymity), 327 "set the desired LEVEL of receiver-anonymity"),
341 328 &anonymity),
342 GNUNET_GETOPT_option_flag ('D', 329
343 "delete-incomplete", 330 GNUNET_GETOPT_option_flag (
344 gettext_noop ("delete incomplete downloads (when aborted with CTRL-C)"), 331 'D',
345 &delete_incomplete), 332 "delete-incomplete",
346 333 gettext_noop ("delete incomplete downloads (when aborted with CTRL-C)"),
347 GNUNET_GETOPT_option_flag ('n', 334 &delete_incomplete),
348 "no-network", 335
349 gettext_noop ("only search the local peer (no P2P network search)"), 336 GNUNET_GETOPT_option_flag (
350 &local_only), 337 'n',
351 GNUNET_GETOPT_option_string ('o', 338 "no-network",
352 "output", 339 gettext_noop ("only search the local peer (no P2P network search)"),
353 "FILENAME", 340 &local_only),
354 gettext_noop ("write the file to FILENAME"), 341 GNUNET_GETOPT_option_string ('o',
355 &filename), 342 "output",
356 GNUNET_GETOPT_option_uint ('p', 343 "FILENAME",
357 "parallelism", 344 gettext_noop ("write the file to FILENAME"),
358 "DOWNLOADS", 345 &filename),
359 gettext_noop ("set the maximum number of parallel downloads that is allowed"), 346 GNUNET_GETOPT_option_uint (
360 &parallelism), 347 'p',
361 GNUNET_GETOPT_option_uint ('r', 348 "parallelism",
362 "request-parallelism", 349 "DOWNLOADS",
363 "REQUESTS", 350 gettext_noop (
364 gettext_noop ("set the maximum number of parallel requests for blocks that is allowed"), 351 "set the maximum number of parallel downloads that is allowed"),
365 &request_parallelism), 352 &parallelism),
366 GNUNET_GETOPT_option_flag ('R', 353 GNUNET_GETOPT_option_uint (
367 "recursive", 354 'r',
368 gettext_noop ("download a GNUnet directory recursively"), 355 "request-parallelism",
369 &do_recursive), 356 "REQUESTS",
370 GNUNET_GETOPT_option_increment_uint ('V', 357 gettext_noop (
371 "verbose", 358 "set the maximum number of parallel requests for blocks that is allowed"),
372 gettext_noop ("be verbose (print progress information)"), 359 &request_parallelism),
373 &verbose), 360 GNUNET_GETOPT_option_flag ('R',
374 GNUNET_GETOPT_OPTION_END 361 "recursive",
375 }; 362 gettext_noop (
376 363 "download a GNUnet directory recursively"),
377 if (GNUNET_OK != 364 &do_recursive),
378 GNUNET_STRINGS_get_utf8_args (argc, argv, 365 GNUNET_GETOPT_option_increment_uint (
379 &argc, &argv)) 366 'V',
367 "verbose",
368 gettext_noop ("be verbose (print progress information)"),
369 &verbose),
370 GNUNET_GETOPT_OPTION_END};
371
372 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
380 return 2; 373 return 2;
381 374
382 ret = (GNUNET_OK == 375 ret =
383 GNUNET_PROGRAM_run (argc, argv, 376 (GNUNET_OK ==
384 "gnunet-download [OPTIONS] URI", 377 GNUNET_PROGRAM_run (
385 gettext_noop 378 argc,
386 ("Download files from GNUnet using a GNUnet CHK or LOC URI (gnunet://fs/chk/...)"), 379 argv,
387 options, 380 "gnunet-download [OPTIONS] URI",
388 &run, NULL)) ? ret : 1; 381 gettext_noop (
389 GNUNET_free ((void*) argv); 382 "Download files from GNUnet using a GNUnet CHK or LOC URI (gnunet://fs/chk/...)"),
383 options,
384 &run,
385 NULL))
386 ? ret
387 : 1;
388 GNUNET_free ((void *) argv);
390 return ret; 389 return ret;
391} 390}
392 391
diff --git a/src/fs/gnunet-fs.c b/src/fs/gnunet-fs.c
index 26970c06a..ad2a8d6c5 100644
--- a/src/fs/gnunet-fs.c
+++ b/src/fs/gnunet-fs.c
@@ -55,7 +55,9 @@ static unsigned int verbose;
55 * @return GNUNET_OK to continue iteration 55 * @return GNUNET_OK to continue iteration
56 */ 56 */
57static int 57static int
58print_indexed (void *cls, const char *filename, const struct GNUNET_HashCode * file_id) 58print_indexed (void *cls,
59 const char *filename,
60 const struct GNUNET_HashCode *file_id)
59{ 61{
60 if (NULL == filename) 62 if (NULL == filename)
61 { 63 {
@@ -64,9 +66,9 @@ print_indexed (void *cls, const char *filename, const struct GNUNET_HashCode * f
64 return GNUNET_OK; 66 return GNUNET_OK;
65 } 67 }
66 if (verbose) 68 if (verbose)
67 FPRINTF (stdout, "%s: %s\n", GNUNET_h2s (file_id), filename); 69 fprintf (stdout, "%s: %s\n", GNUNET_h2s (file_id), filename);
68 else 70 else
69 FPRINTF (stdout, "%s\n", filename); 71 fprintf (stdout, "%s\n", filename);
70 return GNUNET_OK; 72 return GNUNET_OK;
71} 73}
72 74
@@ -80,12 +82,18 @@ print_indexed (void *cls, const char *filename, const struct GNUNET_HashCode * f
80 * @param cfg configuration 82 * @param cfg configuration
81 */ 83 */
82static void 84static void
83run (void *cls, char *const *args, const char *cfgfile, 85run (void *cls,
86 char *const *args,
87 const char *cfgfile,
84 const struct GNUNET_CONFIGURATION_Handle *cfg) 88 const struct GNUNET_CONFIGURATION_Handle *cfg)
85{ 89{
86 if (list_indexed_files) 90 if (list_indexed_files)
87 { 91 {
88 fs = GNUNET_FS_start (cfg, "gnunet-fs", NULL, NULL, GNUNET_FS_FLAGS_NONE, 92 fs = GNUNET_FS_start (cfg,
93 "gnunet-fs",
94 NULL,
95 NULL,
96 GNUNET_FS_FLAGS_NONE,
89 GNUNET_FS_OPTIONS_END); 97 GNUNET_FS_OPTIONS_END);
90 if (NULL == fs) 98 if (NULL == fs)
91 { 99 {
@@ -115,21 +123,27 @@ main (int argc, char *const *argv)
115 struct GNUNET_GETOPT_CommandLineOption options[] = { 123 struct GNUNET_GETOPT_CommandLineOption options[] = {
116 124
117 GNUNET_GETOPT_option_flag ('i', 125 GNUNET_GETOPT_option_flag ('i',
118 "list-indexed", 126 "list-indexed",
119 gettext_noop ("print a list of all indexed files"), 127 gettext_noop (
120 &list_indexed_files), 128 "print a list of all indexed files"),
129 &list_indexed_files),
121 130
122 GNUNET_GETOPT_option_verbose (&verbose), 131 GNUNET_GETOPT_option_verbose (&verbose),
123 GNUNET_GETOPT_OPTION_END 132 GNUNET_GETOPT_OPTION_END};
124 };
125 133
126 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 134 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
127 return 2; 135 return 2;
128 ret = (GNUNET_OK == 136 ret = (GNUNET_OK ==
129 GNUNET_PROGRAM_run (argc, argv, "gnunet-fs [OPTIONS]", 137 GNUNET_PROGRAM_run (argc,
130 gettext_noop ("Special file-sharing operations"), 138 argv,
131 options, &run, NULL)) ? ret : 1; 139 "gnunet-fs [OPTIONS]",
132 GNUNET_free ((void*) argv); 140 gettext_noop ("Special file-sharing operations"),
141 options,
142 &run,
143 NULL))
144 ? ret
145 : 1;
146 GNUNET_free ((void *) argv);
133 return ret; 147 return ret;
134} 148}
135 149
diff --git a/src/fs/gnunet-helper-fs-publish.c b/src/fs/gnunet-helper-fs-publish.c
index fefb33e14..dcb4b47cd 100644
--- a/src/fs/gnunet-helper-fs-publish.c
+++ b/src/fs/gnunet-helper-fs-publish.c
@@ -78,7 +78,6 @@ struct ScanTreeNode
78 * #GNUNET_YES if this is a directory 78 * #GNUNET_YES if this is a directory
79 */ 79 */
80 int is_directory; 80 int is_directory;
81
82}; 81};
83 82
84 83
@@ -124,20 +123,30 @@ add_to_md (void *cls,
124{ 123{
125 struct GNUNET_CONTAINER_MetaData *md = cls; 124 struct GNUNET_CONTAINER_MetaData *md = cls;
126 125
127 if ( ((EXTRACTOR_METAFORMAT_UTF8 == format) || 126 if (((EXTRACTOR_METAFORMAT_UTF8 == format) ||
128 (EXTRACTOR_METAFORMAT_C_STRING == format)) && 127 (EXTRACTOR_METAFORMAT_C_STRING == format)) &&
129 ('\0' != data[data_len - 1]) ) 128 ('\0' != data[data_len - 1]))
130 { 129 {
131 char zdata[data_len + 1]; 130 char zdata[data_len + 1];
132 GNUNET_memcpy (zdata, data, data_len); 131 GNUNET_memcpy (zdata, data, data_len);
133 zdata[data_len] = '\0'; 132 zdata[data_len] = '\0';
134 (void) GNUNET_CONTAINER_meta_data_insert (md, plugin_name, type, format, 133 (void) GNUNET_CONTAINER_meta_data_insert (md,
135 data_mime_type, zdata, data_len + 1); 134 plugin_name,
135 type,
136 format,
137 data_mime_type,
138 zdata,
139 data_len + 1);
136 } 140 }
137 else 141 else
138 { 142 {
139 (void) GNUNET_CONTAINER_meta_data_insert (md, plugin_name, type, format, 143 (void) GNUNET_CONTAINER_meta_data_insert (md,
140 data_mime_type, data, data_len); 144 plugin_name,
145 type,
146 format,
147 data_mime_type,
148 data,
149 data_len);
141 } 150 }
142 return 0; 151 return 0;
143} 152}
@@ -158,8 +167,8 @@ free_tree (struct ScanTreeNode *tree)
158 free_tree (pos); 167 free_tree (pos);
159 if (NULL != tree->parent) 168 if (NULL != tree->parent)
160 GNUNET_CONTAINER_DLL_remove (tree->parent->children_head, 169 GNUNET_CONTAINER_DLL_remove (tree->parent->children_head,
161 tree->parent->children_tail, 170 tree->parent->children_tail,
162 tree); 171 tree);
163 GNUNET_free (tree->filename); 172 GNUNET_free (tree->filename);
164 GNUNET_free (tree); 173 GNUNET_free (tree);
165} 174}
@@ -173,8 +182,7 @@ free_tree (struct ScanTreeNode *tree)
173 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 182 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
174 */ 183 */
175static int 184static int
176write_all (const void *buf, 185write_all (const void *buf, size_t size)
177 size_t size)
178{ 186{
179 const char *cbuf = buf; 187 const char *cbuf = buf;
180 size_t total; 188 size_t total;
@@ -183,16 +191,14 @@ write_all (const void *buf,
183 total = 0; 191 total = 0;
184 do 192 do
185 { 193 {
186 wr = write (output_stream, 194 wr = write (output_stream, &cbuf[total], size - total);
187 &cbuf[total],
188 size - total);
189 if (wr > 0) 195 if (wr > 0)
190 total += wr; 196 total += wr;
191 } while ( (wr > 0) && (total < size) ); 197 } while ((wr > 0) && (total < size));
192 if (wr <= 0) 198 if (wr <= 0)
193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
194 "Failed to write to stdout: %s\n", 200 "Failed to write to stdout: %s\n",
195 strerror (errno)); 201 strerror (errno));
196 return (total == size) ? GNUNET_OK : GNUNET_SYSERR; 202 return (total == size) ? GNUNET_OK : GNUNET_SYSERR;
197} 203}
198 204
@@ -206,9 +212,7 @@ write_all (const void *buf,
206 * @return #GNUNET_SYSERR to stop scanning (the pipe was broken somehow) 212 * @return #GNUNET_SYSERR to stop scanning (the pipe was broken somehow)
207 */ 213 */
208static int 214static int
209write_message (uint16_t message_type, 215write_message (uint16_t message_type, const char *data, size_t data_length)
210 const char *data,
211 size_t data_length)
212{ 216{
213 struct GNUNET_MessageHeader hdr; 217 struct GNUNET_MessageHeader hdr;
214 218
@@ -220,12 +224,8 @@ write_message (uint16_t message_type,
220#endif 224#endif
221 hdr.type = htons (message_type); 225 hdr.type = htons (message_type);
222 hdr.size = htons (sizeof (struct GNUNET_MessageHeader) + data_length); 226 hdr.size = htons (sizeof (struct GNUNET_MessageHeader) + data_length);
223 if ( (GNUNET_OK != 227 if ((GNUNET_OK != write_all (&hdr, sizeof (hdr))) ||
224 write_all (&hdr, 228 (GNUNET_OK != write_all (data, data_length)))
225 sizeof (hdr))) ||
226 (GNUNET_OK !=
227 write_all (data,
228 data_length)) )
229 return GNUNET_SYSERR; 229 return GNUNET_SYSERR;
230 return GNUNET_OK; 230 return GNUNET_OK;
231} 231}
@@ -242,8 +242,7 @@ write_message (uint16_t message_type,
242 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 242 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
243 */ 243 */
244static int 244static int
245preprocess_file (const char *filename, 245preprocess_file (const char *filename, struct ScanTreeNode **dst);
246 struct ScanTreeNode **dst);
247 246
248 247
249/** 248/**
@@ -273,15 +272,12 @@ struct RecursionContext
273 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 272 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
274 */ 273 */
275static int 274static int
276scan_callback (void *cls, 275scan_callback (void *cls, const char *filename)
277 const char *filename)
278{ 276{
279 struct RecursionContext *rc = cls; 277 struct RecursionContext *rc = cls;
280 struct ScanTreeNode *chld; 278 struct ScanTreeNode *chld;
281 279
282 if (GNUNET_OK != 280 if (GNUNET_OK != preprocess_file (filename, &chld))
283 preprocess_file (filename,
284 &chld))
285 { 281 {
286 rc->stop = GNUNET_YES; 282 rc->stop = GNUNET_YES;
287 return GNUNET_SYSERR; 283 return GNUNET_SYSERR;
@@ -290,8 +286,8 @@ scan_callback (void *cls,
290 return GNUNET_OK; 286 return GNUNET_OK;
291 chld->parent = rc->parent; 287 chld->parent = rc->parent;
292 GNUNET_CONTAINER_DLL_insert (rc->parent->children_head, 288 GNUNET_CONTAINER_DLL_insert (rc->parent->children_head,
293 rc->parent->children_tail, 289 rc->parent->children_tail,
294 chld); 290 chld);
295 return GNUNET_OK; 291 return GNUNET_OK;
296} 292}
297 293
@@ -307,22 +303,23 @@ scan_callback (void *cls,
307 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 303 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
308 */ 304 */
309static int 305static int
310preprocess_file (const char *filename, 306preprocess_file (const char *filename, struct ScanTreeNode **dst)
311 struct ScanTreeNode **dst)
312{ 307{
313 struct ScanTreeNode *item; 308 struct ScanTreeNode *item;
314 struct stat sbuf; 309 struct stat sbuf;
315 uint64_t fsize = 0; 310 uint64_t fsize = 0;
316 311
317 if ((0 != STAT (filename, &sbuf)) || 312 if ((0 != stat (filename, &sbuf)) ||
318 ((!S_ISDIR (sbuf.st_mode)) && (GNUNET_OK != GNUNET_DISK_file_size ( 313 ((! S_ISDIR (sbuf.st_mode)) &&
319 filename, &fsize, GNUNET_NO, GNUNET_YES)))) 314 (GNUNET_OK !=
315 GNUNET_DISK_file_size (filename, &fsize, GNUNET_NO, GNUNET_YES))))
320 { 316 {
321 /* If the file doesn't exist (or is not stat-able for any other reason) 317 /* If the file doesn't exist (or is not stat-able for any other reason)
322 skip it (but report it), but do continue. */ 318 skip it (but report it), but do continue. */
323 if (GNUNET_OK != 319 if (GNUNET_OK !=
324 write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE, 320 write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE,
325 filename, strlen (filename) + 1)) 321 filename,
322 strlen (filename) + 1))
326 return GNUNET_SYSERR; 323 return GNUNET_SYSERR;
327 /* recoverable error, store 'NULL' in *dst */ 324 /* recoverable error, store 'NULL' in *dst */
328 *dst = NULL; 325 *dst = NULL;
@@ -330,11 +327,13 @@ preprocess_file (const char *filename,
330 } 327 }
331 328
332 /* Report the progress */ 329 /* Report the progress */
333 if (GNUNET_OK != 330 if (
334 write_message (S_ISDIR (sbuf.st_mode) 331 GNUNET_OK !=
335 ? GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY 332 write_message (S_ISDIR (sbuf.st_mode)
336 : GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE, 333 ? GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY
337 filename, strlen (filename) + 1)) 334 : GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE,
335 filename,
336 strlen (filename) + 1))
338 return GNUNET_SYSERR; 337 return GNUNET_SYSERR;
339 item = GNUNET_new (struct ScanTreeNode); 338 item = GNUNET_new (struct ScanTreeNode);
340 item->filename = GNUNET_strdup (filename); 339 item->filename = GNUNET_strdup (filename);
@@ -346,13 +345,13 @@ preprocess_file (const char *filename,
346 345
347 rc.parent = item; 346 rc.parent = item;
348 rc.stop = GNUNET_NO; 347 rc.stop = GNUNET_NO;
349 GNUNET_DISK_directory_scan (filename, 348 GNUNET_DISK_directory_scan (filename, &scan_callback, &rc);
350 &scan_callback, 349 if (
351 &rc); 350 (GNUNET_YES == rc.stop) ||
352 if ( (GNUNET_YES == rc.stop) || 351 (GNUNET_OK !=
353 (GNUNET_OK != 352 write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY,
354 write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY, 353 "..",
355 "..", 3)) ) 354 3)))
356 { 355 {
357 free_tree (item); 356 free_tree (item);
358 return GNUNET_SYSERR; 357 return GNUNET_SYSERR;
@@ -383,20 +382,15 @@ extract_files (struct ScanTreeNode *item)
383 struct ScanTreeNode *pos; 382 struct ScanTreeNode *pos;
384 383
385 for (pos = item->children_head; NULL != pos; pos = pos->next) 384 for (pos = item->children_head; NULL != pos; pos = pos->next)
386 if (GNUNET_OK != 385 if (GNUNET_OK != extract_files (pos))
387 extract_files (pos)) 386 return GNUNET_SYSERR;
388 return GNUNET_SYSERR;
389 return GNUNET_OK; 387 return GNUNET_OK;
390 } 388 }
391 389
392 /* this is the expensive operation, *afterwards* we'll check for aborts */ 390 /* this is the expensive operation, *afterwards* we'll check for aborts */
393 meta = GNUNET_CONTAINER_meta_data_create (); 391 meta = GNUNET_CONTAINER_meta_data_create ();
394#if HAVE_LIBEXTRACTOR 392#if HAVE_LIBEXTRACTOR
395 EXTRACTOR_extract (plugins, 393 EXTRACTOR_extract (plugins, item->filename, NULL, 0, &add_to_md, meta);
396 item->filename,
397 NULL, 0,
398 &add_to_md,
399 meta);
400#endif 394#endif
401 slen = strlen (item->filename) + 1; 395 slen = strlen (item->filename) + 1;
402 size = GNUNET_CONTAINER_meta_data_get_serialized_size (meta); 396 size = GNUNET_CONTAINER_meta_data_get_serialized_size (meta);
@@ -405,8 +399,9 @@ extract_files (struct ScanTreeNode *item)
405 /* no meta data */ 399 /* no meta data */
406 GNUNET_CONTAINER_meta_data_destroy (meta); 400 GNUNET_CONTAINER_meta_data_destroy (meta);
407 if (GNUNET_OK != 401 if (GNUNET_OK !=
408 write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, 402 write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA,
409 item->filename, slen)) 403 item->filename,
404 slen))
410 return GNUNET_SYSERR; 405 return GNUNET_SYSERR;
411 return GNUNET_OK; 406 return GNUNET_OK;
412 } 407 }
@@ -420,9 +415,11 @@ extract_files (struct ScanTreeNode *item)
420 char *dst = &buf[slen]; 415 char *dst = &buf[slen];
421 416
422 GNUNET_memcpy (buf, item->filename, slen); 417 GNUNET_memcpy (buf, item->filename, slen);
423 size = GNUNET_CONTAINER_meta_data_serialize (meta, 418 size = GNUNET_CONTAINER_meta_data_serialize (
424 &dst, size, 419 meta,
425 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); 420 &dst,
421 size,
422 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
426 if (size < 0) 423 if (size < 0)
427 { 424 {
428 GNUNET_break (0); 425 GNUNET_break (0);
@@ -430,9 +427,9 @@ extract_files (struct ScanTreeNode *item)
430 } 427 }
431 GNUNET_CONTAINER_meta_data_destroy (meta); 428 GNUNET_CONTAINER_meta_data_destroy (meta);
432 if (GNUNET_OK != 429 if (GNUNET_OK !=
433 write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, 430 write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA,
434 buf, 431 buf,
435 slen + size)) 432 slen + size))
436 return GNUNET_SYSERR; 433 return GNUNET_SYSERR;
437 } 434 }
438 return GNUNET_OK; 435 return GNUNET_OK;
@@ -453,13 +450,14 @@ ignore_sigpipe ()
453 sig.sa_handler = SIG_IGN; 450 sig.sa_handler = SIG_IGN;
454 sigemptyset (&sig.sa_mask); 451 sigemptyset (&sig.sa_mask);
455#ifdef SA_INTERRUPT 452#ifdef SA_INTERRUPT
456 sig.sa_flags = SA_INTERRUPT; /* SunOS */ 453 sig.sa_flags = SA_INTERRUPT; /* SunOS */
457#else 454#else
458 sig.sa_flags = SA_RESTART; 455 sig.sa_flags = SA_RESTART;
459#endif 456#endif
460 if (0 != sigaction (SIGPIPE, &sig, &oldsig)) 457 if (0 != sigaction (SIGPIPE, &sig, &oldsig))
461 fprintf (stderr, 458 fprintf (stderr,
462 "Failed to install SIGPIPE handler: %s\n", strerror (errno)); 459 "Failed to install SIGPIPE handler: %s\n",
460 strerror (errno));
463} 461}
464 462
465 463
@@ -470,8 +468,7 @@ ignore_sigpipe ()
470 * @param flags flags to use (O_RDONLY or O_WRONLY) 468 * @param flags flags to use (O_RDONLY or O_WRONLY)
471 */ 469 */
472static void 470static void
473make_dev_zero (int fd, 471make_dev_zero (int fd, int flags)
474 int flags)
475{ 472{
476 int z; 473 int z;
477 474
@@ -498,8 +495,7 @@ make_dev_zero (int fd,
498 * @return 0 on success 495 * @return 0 on success
499 */ 496 */
500int 497int
501main (int argc, 498main (int argc, char *const *argv)
502 char *const *argv)
503{ 499{
504 const char *filename_expanded; 500 const char *filename_expanded;
505 const char *ex; 501 const char *ex;
@@ -524,79 +520,83 @@ main (int argc,
524#endif 520#endif
525 521
526 /* parse command line */ 522 /* parse command line */
527 if ( (3 != argc) && (2 != argc) ) 523 if ((3 != argc) && (2 != argc))
528 { 524 {
529 FPRINTF (stderr, 525 fprintf (stderr,
530 "%s", 526 "%s",
531 "gnunet-helper-fs-publish needs exactly one or two arguments\n"); 527 "gnunet-helper-fs-publish needs exactly one or two arguments\n");
532#if WINDOWS 528#if WINDOWS
533 GNUNET_free ((void*) argv); 529 GNUNET_free ((void *) argv);
534#endif 530#endif
535 return 1; 531 return 1;
536 } 532 }
537 filename_expanded = argv[1]; 533 filename_expanded = argv[1];
538 ex = argv[2]; 534 ex = argv[2];
539 if ( (NULL == ex) || 535 if ((NULL == ex) || (0 != strcmp (ex, "-")))
540 (0 != strcmp (ex, "-")) )
541 { 536 {
542#if HAVE_LIBEXTRACTOR 537#if HAVE_LIBEXTRACTOR
543 plugins = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY); 538 plugins = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY);
544 if (NULL != ex) 539 if (NULL != ex)
545 plugins = EXTRACTOR_plugin_add_config (plugins, ex, 540 plugins = EXTRACTOR_plugin_add_config (plugins,
546 EXTRACTOR_OPTION_DEFAULT_POLICY); 541 ex,
542 EXTRACTOR_OPTION_DEFAULT_POLICY);
547#endif 543#endif
548 } 544 }
549 545
550 /* scan tree to find out how much work there is to be done */ 546 /* scan tree to find out how much work there is to be done */
551 if (GNUNET_OK != preprocess_file (filename_expanded, 547 if (GNUNET_OK != preprocess_file (filename_expanded, &root))
552 &root))
553 { 548 {
554 (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, NULL, 0); 549 (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, NULL, 0);
555#if HAVE_LIBEXTRACTOR 550#if HAVE_LIBEXTRACTOR
556 EXTRACTOR_plugin_remove_all (plugins); 551 EXTRACTOR_plugin_remove_all (plugins);
557#endif 552#endif
558#if WINDOWS 553#if WINDOWS
559 GNUNET_free ((void*) argv); 554 GNUNET_free ((void *) argv);
560#endif 555#endif
561 return 2; 556 return 2;
562 } 557 }
563 /* signal that we're done counting files, so that a percentage of 558 /* signal that we're done counting files, so that a percentage of
564 progress can now be calculated */ 559 progress can now be calculated */
565 if (GNUNET_OK != 560 if (GNUNET_OK !=
566 write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE, NULL, 0)) 561 write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE,
562 NULL,
563 0))
567 { 564 {
568#if HAVE_LIBEXTRACTOR 565#if HAVE_LIBEXTRACTOR
569 EXTRACTOR_plugin_remove_all (plugins); 566 EXTRACTOR_plugin_remove_all (plugins);
570#endif 567#endif
571#if WINDOWS 568#if WINDOWS
572 GNUNET_free ((void*) argv); 569 GNUNET_free ((void *) argv);
573#endif 570#endif
574 return 3; 571 return 3;
575 } 572 }
576 if (NULL != root) 573 if (NULL != root)
577 { 574 {
578 if (GNUNET_OK != 575 if (GNUNET_OK != extract_files (root))
579 extract_files (root))
580 { 576 {
581 (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, NULL, 0); 577 (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR,
578 NULL,
579 0);
582 free_tree (root); 580 free_tree (root);
583#if HAVE_LIBEXTRACTOR 581#if HAVE_LIBEXTRACTOR
584 EXTRACTOR_plugin_remove_all (plugins); 582 EXTRACTOR_plugin_remove_all (plugins);
585#endif 583#endif
586#if WINDOWS 584#if WINDOWS
587 GNUNET_free ((void*) argv); 585 GNUNET_free ((void *) argv);
588#endif 586#endif
589 return 4; 587 return 4;
590 } 588 }
591 free_tree (root); 589 free_tree (root);
592 } 590 }
593 /* enable "clean" shutdown by telling parent that we are done */ 591 /* enable "clean" shutdown by telling parent that we are done */
594 (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED, NULL, 0); 592 (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED,
593 NULL,
594 0);
595#if HAVE_LIBEXTRACTOR 595#if HAVE_LIBEXTRACTOR
596 EXTRACTOR_plugin_remove_all (plugins); 596 EXTRACTOR_plugin_remove_all (plugins);
597#endif 597#endif
598#if WINDOWS 598#if WINDOWS
599 GNUNET_free ((void*) argv); 599 GNUNET_free ((void *) argv);
600#endif 600#endif
601 return 0; 601 return 0;
602} 602}
diff --git a/src/fs/gnunet-publish.c b/src/fs/gnunet-publish.c
index fbf32c2a7..84cbf0aac 100644
--- a/src/fs/gnunet-publish.c
+++ b/src/fs/gnunet-publish.c
@@ -67,7 +67,7 @@ static struct GNUNET_FS_Uri *topKeywords;
67/** 67/**
68 * Options we set for published blocks. 68 * Options we set for published blocks.
69 */ 69 */
70static struct GNUNET_FS_BlockOptions bo = { {0LL}, 1, 365, 1 }; 70static struct GNUNET_FS_BlockOptions bo = {{0LL}, 1, 365, 1};
71 71
72/** 72/**
73 * Value of URI provided on command-line (when not publishing 73 * Value of URI provided on command-line (when not publishing
@@ -200,8 +200,7 @@ do_stop_task (void *cls)
200 * field in the GNUNET_FS_ProgressInfo struct. 200 * field in the GNUNET_FS_ProgressInfo struct.
201 */ 201 */
202static void * 202static void *
203progress_cb (void *cls, 203progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
204 const struct GNUNET_FS_ProgressInfo *info)
205{ 204{
206 const char *s; 205 const char *s;
207 char *suri; 206 char *suri;
@@ -214,50 +213,51 @@ progress_cb (void *cls,
214 if (verbose) 213 if (verbose)
215 { 214 {
216 s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.eta, 215 s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.eta,
217 GNUNET_YES); 216 GNUNET_YES);
218 FPRINTF (stdout, 217 fprintf (stdout,
219 _("Publishing `%s' at %llu/%llu (%s remaining)\n"), 218 _ ("Publishing `%s' at %llu/%llu (%s remaining)\n"),
220 info->value.publish.filename, 219 info->value.publish.filename,
221 (unsigned long long) info->value.publish.completed, 220 (unsigned long long) info->value.publish.completed,
222 (unsigned long long) info->value.publish.size, s); 221 (unsigned long long) info->value.publish.size,
222 s);
223 } 223 }
224 break; 224 break;
225 case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: 225 case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY:
226 if (verbose) 226 if (verbose)
227 { 227 {
228 s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.specifics.progress_directory.eta, 228 s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.specifics
229 GNUNET_YES); 229 .progress_directory.eta,
230 FPRINTF (stdout, 230 GNUNET_YES);
231 _("Publishing `%s' at %llu/%llu (%s remaining)\n"), 231 fprintf (stdout,
232 _ ("Publishing `%s' at %llu/%llu (%s remaining)\n"),
232 info->value.publish.filename, 233 info->value.publish.filename,
233 (unsigned long long) info->value.publish.specifics.progress_directory.completed, 234 (unsigned long long)
234 (unsigned long long) info->value.publish.specifics.progress_directory.total, s); 235 info->value.publish.specifics.progress_directory.completed,
236 (unsigned long long)
237 info->value.publish.specifics.progress_directory.total,
238 s);
235 } 239 }
236 break; 240 break;
237 case GNUNET_FS_STATUS_PUBLISH_ERROR: 241 case GNUNET_FS_STATUS_PUBLISH_ERROR:
238 FPRINTF (stderr, 242 fprintf (stderr,
239 _("Error publishing: %s.\n"), 243 _ ("Error publishing: %s.\n"),
240 info->value.publish.specifics.error.message); 244 info->value.publish.specifics.error.message);
241 ret = 1; 245 ret = 1;
242 GNUNET_SCHEDULER_shutdown (); 246 GNUNET_SCHEDULER_shutdown ();
243 break; 247 break;
244 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 248 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
245 FPRINTF (stdout, 249 fprintf (stdout,
246 _("Publishing `%s' done.\n"), 250 _ ("Publishing `%s' done.\n"),
247 info->value.publish.filename); 251 info->value.publish.filename);
248 suri = GNUNET_FS_uri_to_string (info->value.publish.specifics. 252 suri =
249 completed.chk_uri); 253 GNUNET_FS_uri_to_string (info->value.publish.specifics.completed.chk_uri);
250 FPRINTF (stdout, 254 fprintf (stdout, _ ("URI is `%s'.\n"), suri);
251 _("URI is `%s'.\n"),
252 suri);
253 GNUNET_free (suri); 255 GNUNET_free (suri);
254 if (NULL != info->value.publish.specifics.completed.sks_uri) 256 if (NULL != info->value.publish.specifics.completed.sks_uri)
255 { 257 {
256 suri = GNUNET_FS_uri_to_string (info->value.publish.specifics. 258 suri = GNUNET_FS_uri_to_string (
257 completed.sks_uri); 259 info->value.publish.specifics.completed.sks_uri);
258 FPRINTF (stdout, 260 fprintf (stdout, _ ("Namespace URI is `%s'.\n"), suri);
259 _("Namespace URI is `%s'.\n"),
260 suri);
261 GNUNET_free (suri); 261 GNUNET_free (suri);
262 } 262 }
263 if (NULL == info->value.publish.pctx) 263 if (NULL == info->value.publish.pctx)
@@ -270,33 +270,25 @@ progress_cb (void *cls,
270 GNUNET_break (NULL == pc); 270 GNUNET_break (NULL == pc);
271 return NULL; 271 return NULL;
272 case GNUNET_FS_STATUS_UNINDEX_START: 272 case GNUNET_FS_STATUS_UNINDEX_START:
273 FPRINTF (stderr, 273 fprintf (stderr, "%s", _ ("Starting cleanup after abort\n"));
274 "%s",
275 _("Starting cleanup after abort\n"));
276 return NULL; 274 return NULL;
277 case GNUNET_FS_STATUS_UNINDEX_PROGRESS: 275 case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
278 return NULL; 276 return NULL;
279 case GNUNET_FS_STATUS_UNINDEX_COMPLETED: 277 case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
280 FPRINTF (stderr, 278 fprintf (stderr, "%s", _ ("Cleanup after abort completed.\n"));
281 "%s",
282 _("Cleanup after abort completed.\n"));
283 GNUNET_FS_unindex_stop (info->value.unindex.uc); 279 GNUNET_FS_unindex_stop (info->value.unindex.uc);
284 return NULL; 280 return NULL;
285 case GNUNET_FS_STATUS_UNINDEX_ERROR: 281 case GNUNET_FS_STATUS_UNINDEX_ERROR:
286 FPRINTF (stderr, 282 fprintf (stderr, "%s", _ ("Cleanup after abort failed.\n"));
287 "%s",
288 _("Cleanup after abort failed.\n"));
289 GNUNET_FS_unindex_stop (info->value.unindex.uc); 283 GNUNET_FS_unindex_stop (info->value.unindex.uc);
290 return NULL; 284 return NULL;
291 case GNUNET_FS_STATUS_UNINDEX_STOPPED: 285 case GNUNET_FS_STATUS_UNINDEX_STOPPED:
292 return NULL; 286 return NULL;
293 default: 287 default:
294 FPRINTF (stderr, 288 fprintf (stderr, _ ("Unexpected status: %d\n"), info->status);
295 _("Unexpected status: %d\n"),
296 info->status);
297 return NULL; 289 return NULL;
298 } 290 }
299 return ""; /* non-null */ 291 return ""; /* non-null */
300} 292}
301 293
302 294
@@ -319,7 +311,8 @@ meta_printer (void *cls,
319 enum EXTRACTOR_MetaType type, 311 enum EXTRACTOR_MetaType type,
320 enum EXTRACTOR_MetaFormat format, 312 enum EXTRACTOR_MetaFormat format,
321 const char *data_mime_type, 313 const char *data_mime_type,
322 const char *data, size_t data_size) 314 const char *data,
315 size_t data_size)
323{ 316{
324 if ((EXTRACTOR_METAFORMAT_UTF8 != format) && 317 if ((EXTRACTOR_METAFORMAT_UTF8 != format) &&
325 (EXTRACTOR_METAFORMAT_C_STRING != format)) 318 (EXTRACTOR_METAFORMAT_C_STRING != format))
@@ -327,15 +320,9 @@ meta_printer (void *cls,
327 if (EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME == type) 320 if (EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME == type)
328 return 0; 321 return 0;
329#if HAVE_LIBEXTRACTOR 322#if HAVE_LIBEXTRACTOR
330 FPRINTF (stdout, 323 fprintf (stdout, "\t%s - %s\n", EXTRACTOR_metatype_to_string (type), data);
331 "\t%s - %s\n",
332 EXTRACTOR_metatype_to_string (type),
333 data);
334#else 324#else
335 FPRINTF (stdout, 325 fprintf (stdout, "\t%d - %s\n", type, data);
336 "\t%d - %s\n",
337 type,
338 data);
339#endif 326#endif
340 return 0; 327 return 0;
341} 328}
@@ -350,11 +337,9 @@ meta_printer (void *cls,
350 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to abort 337 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to abort
351 */ 338 */
352static int 339static int
353keyword_printer (void *cls, 340keyword_printer (void *cls, const char *keyword, int is_mandatory)
354 const char *keyword,
355 int is_mandatory)
356{ 341{
357 FPRINTF (stdout, "\t%s\n", keyword); 342 fprintf (stdout, "\t%s\n", keyword);
358 return GNUNET_OK; 343 return GNUNET_OK;
359} 344}
360 345
@@ -392,8 +377,7 @@ publish_inspector (void *cls,
392 377
393 if (cls == fi) 378 if (cls == fi)
394 return GNUNET_OK; 379 return GNUNET_OK;
395 if ( (disable_extractor) && 380 if ((disable_extractor) && (NULL != *uri))
396 (NULL != *uri) )
397 { 381 {
398 GNUNET_FS_uri_destroy (*uri); 382 GNUNET_FS_uri_destroy (*uri);
399 *uri = NULL; 383 *uri = NULL;
@@ -423,29 +407,21 @@ publish_inspector (void *cls,
423 GNUNET_CONTAINER_meta_data_add_publication_date (m); 407 GNUNET_CONTAINER_meta_data_add_publication_date (m);
424 if (extract_only) 408 if (extract_only)
425 { 409 {
426 fn = GNUNET_CONTAINER_meta_data_get_by_type (m, 410 fn = GNUNET_CONTAINER_meta_data_get_by_type (
427 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); 411 m,
412 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
428 fs = GNUNET_STRINGS_byte_size_fancy (length); 413 fs = GNUNET_STRINGS_byte_size_fancy (length);
429 FPRINTF (stdout, 414 fprintf (stdout, _ ("Meta data for file `%s' (%s)\n"), fn, fs);
430 _("Meta data for file `%s' (%s)\n"),
431 fn,
432 fs);
433 GNUNET_CONTAINER_meta_data_iterate (m, &meta_printer, NULL); 415 GNUNET_CONTAINER_meta_data_iterate (m, &meta_printer, NULL);
434 FPRINTF (stdout, 416 fprintf (stdout, _ ("Keywords for file `%s' (%s)\n"), fn, fs);
435 _("Keywords for file `%s' (%s)\n"),
436 fn,
437 fs);
438 GNUNET_free (fn); 417 GNUNET_free (fn);
439 GNUNET_free (fs); 418 GNUNET_free (fs);
440 if (NULL != *uri) 419 if (NULL != *uri)
441 GNUNET_FS_uri_ksk_get_keywords (*uri, &keyword_printer, NULL); 420 GNUNET_FS_uri_ksk_get_keywords (*uri, &keyword_printer, NULL);
442 FPRINTF (stdout, 421 fprintf (stdout, "%s", "\n");
443 "%s",
444 "\n");
445 } 422 }
446 if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (m)) 423 if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (m))
447 GNUNET_FS_file_information_inspect (fi, 424 GNUNET_FS_file_information_inspect (fi, &publish_inspector, fi);
448 &publish_inspector, fi);
449 return GNUNET_OK; 425 return GNUNET_OK;
450} 426}
451 427
@@ -466,9 +442,7 @@ uri_sks_continuation (void *cls,
466{ 442{
467 if (NULL != emsg) 443 if (NULL != emsg)
468 { 444 {
469 FPRINTF (stderr, 445 fprintf (stderr, "%s\n", emsg);
470 "%s\n",
471 emsg);
472 ret = 1; 446 ret = 1;
473 } 447 }
474 GNUNET_SCHEDULER_shutdown (); 448 GNUNET_SCHEDULER_shutdown ();
@@ -493,9 +467,7 @@ uri_ksk_continuation (void *cls,
493 467
494 if (NULL != emsg) 468 if (NULL != emsg)
495 { 469 {
496 FPRINTF (stderr, 470 fprintf (stderr, "%s\n", emsg);
497 "%s\n",
498 emsg);
499 ret = 1; 471 ret = 1;
500 } 472 }
501 if (NULL == namespace) 473 if (NULL == namespace)
@@ -505,15 +477,15 @@ uri_ksk_continuation (void *cls,
505 } 477 }
506 priv = GNUNET_IDENTITY_ego_get_private_key (namespace); 478 priv = GNUNET_IDENTITY_ego_get_private_key (namespace);
507 GNUNET_FS_publish_sks (ctx, 479 GNUNET_FS_publish_sks (ctx,
508 priv, 480 priv,
509 this_id, 481 this_id,
510 next_id, 482 next_id,
511 meta, 483 meta,
512 uri, 484 uri,
513 &bo, 485 &bo,
514 GNUNET_FS_PUBLISH_OPTION_NONE, 486 GNUNET_FS_PUBLISH_OPTION_NONE,
515 &uri_sks_continuation, 487 &uri_sks_continuation,
516 NULL); 488 NULL);
517} 489}
518 490
519 491
@@ -536,8 +508,9 @@ get_file_information (struct GNUNET_FS_ShareTreeItem *item)
536 if (NULL == item->meta) 508 if (NULL == item->meta)
537 item->meta = GNUNET_CONTAINER_meta_data_create (); 509 item->meta = GNUNET_CONTAINER_meta_data_create ();
538 GNUNET_CONTAINER_meta_data_delete (item->meta, 510 GNUNET_CONTAINER_meta_data_delete (item->meta,
539 EXTRACTOR_METATYPE_MIMETYPE, 511 EXTRACTOR_METATYPE_MIMETYPE,
540 NULL, 0); 512 NULL,
513 0);
541 GNUNET_FS_meta_data_make_directory (item->meta); 514 GNUNET_FS_meta_data_make_directory (item->meta);
542 if (NULL == item->ksk_uri) 515 if (NULL == item->ksk_uri)
543 { 516 {
@@ -545,12 +518,15 @@ get_file_information (struct GNUNET_FS_ShareTreeItem *item)
545 item->ksk_uri = GNUNET_FS_uri_ksk_create_from_args (1, &mime); 518 item->ksk_uri = GNUNET_FS_uri_ksk_create_from_args (1, &mime);
546 } 519 }
547 else 520 else
548 GNUNET_FS_uri_ksk_add_keyword (item->ksk_uri, GNUNET_FS_DIRECTORY_MIME, 521 GNUNET_FS_uri_ksk_add_keyword (item->ksk_uri,
549 GNUNET_NO); 522 GNUNET_FS_DIRECTORY_MIME,
550 fi = GNUNET_FS_file_information_create_empty_directory (ctx, NULL, 523 GNUNET_NO);
551 item->ksk_uri, 524 fi = GNUNET_FS_file_information_create_empty_directory (ctx,
552 item->meta, 525 NULL,
553 &bo, item->filename); 526 item->ksk_uri,
527 item->meta,
528 &bo,
529 item->filename);
554 for (child = item->children_head; child; child = child->next) 530 for (child = item->children_head; child; child = child->next)
555 { 531 {
556 fic = get_file_information (child); 532 fic = get_file_information (child);
@@ -559,11 +535,13 @@ get_file_information (struct GNUNET_FS_ShareTreeItem *item)
559 } 535 }
560 else 536 else
561 { 537 {
562 fi = GNUNET_FS_file_information_create_from_file (ctx, NULL, 538 fi = GNUNET_FS_file_information_create_from_file (ctx,
563 item->filename, 539 NULL,
564 item->ksk_uri, item->meta, 540 item->filename,
565 !do_insert, 541 item->ksk_uri,
566 &bo); 542 item->meta,
543 ! do_insert,
544 &bo);
567 } 545 }
568 return fi; 546 return fi;
569} 547}
@@ -585,9 +563,7 @@ directory_trim_complete (struct GNUNET_FS_ShareTreeItem *directory_scan_result)
585 GNUNET_FS_share_tree_free (directory_scan_result); 563 GNUNET_FS_share_tree_free (directory_scan_result);
586 if (NULL == fi) 564 if (NULL == fi)
587 { 565 {
588 FPRINTF (stderr, 566 fprintf (stderr, "%s", _ ("Could not publish\n"));
589 "%s",
590 _("Could not publish\n"));
591 ret = 1; 567 ret = 1;
592 GNUNET_SCHEDULER_shutdown (); 568 GNUNET_SCHEDULER_shutdown ();
593 return; 569 return;
@@ -603,16 +579,17 @@ directory_trim_complete (struct GNUNET_FS_ShareTreeItem *directory_scan_result)
603 priv = NULL; 579 priv = NULL;
604 else 580 else
605 priv = GNUNET_IDENTITY_ego_get_private_key (namespace); 581 priv = GNUNET_IDENTITY_ego_get_private_key (namespace);
606 pc = GNUNET_FS_publish_start (ctx, fi, 582 pc = GNUNET_FS_publish_start (ctx,
607 priv, this_id, next_id, 583 fi,
608 (do_simulate) ? 584 priv,
609 GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY : 585 this_id,
610 GNUNET_FS_PUBLISH_OPTION_NONE); 586 next_id,
587 (do_simulate)
588 ? GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY
589 : GNUNET_FS_PUBLISH_OPTION_NONE);
611 if (NULL == pc) 590 if (NULL == pc)
612 { 591 {
613 FPRINTF (stderr, 592 fprintf (stderr, "%s", _ ("Could not start publishing.\n"));
614 "%s",
615 _("Could not start publishing.\n"));
616 ret = 1; 593 ret = 1;
617 GNUNET_SCHEDULER_shutdown (); 594 GNUNET_SCHEDULER_shutdown ();
618 return; 595 return;
@@ -633,9 +610,9 @@ directory_trim_complete (struct GNUNET_FS_ShareTreeItem *directory_scan_result)
633 */ 610 */
634static void 611static void
635directory_scan_cb (void *cls, 612directory_scan_cb (void *cls,
636 const char *filename, 613 const char *filename,
637 int is_directory, 614 int is_directory,
638 enum GNUNET_FS_DirScannerProgressUpdateReason reason) 615 enum GNUNET_FS_DirScannerProgressUpdateReason reason)
639{ 616{
640 struct GNUNET_FS_ShareTreeItem *directory_scan_result; 617 struct GNUNET_FS_ShareTreeItem *directory_scan_result;
641 618
@@ -645,46 +622,36 @@ directory_scan_cb (void *cls,
645 if (verbose > 1) 622 if (verbose > 1)
646 { 623 {
647 if (is_directory == GNUNET_YES) 624 if (is_directory == GNUNET_YES)
648 FPRINTF (stdout, 625 fprintf (stdout, _ ("Scanning directory `%s'.\n"), filename);
649 _("Scanning directory `%s'.\n"),
650 filename);
651 else 626 else
652 FPRINTF (stdout, 627 fprintf (stdout, _ ("Scanning file `%s'.\n"), filename);
653 _("Scanning file `%s'.\n"),
654 filename);
655 } 628 }
656 break; 629 break;
657 case GNUNET_FS_DIRSCANNER_FILE_IGNORED: 630 case GNUNET_FS_DIRSCANNER_FILE_IGNORED:
658 FPRINTF (stderr, 631 fprintf (stderr,
659 _("There was trouble processing file `%s', skipping it.\n"), 632 _ ("There was trouble processing file `%s', skipping it.\n"),
660 filename); 633 filename);
661 break; 634 break;
662 case GNUNET_FS_DIRSCANNER_ALL_COUNTED: 635 case GNUNET_FS_DIRSCANNER_ALL_COUNTED:
663 if (verbose) 636 if (verbose)
664 FPRINTF (stdout, 637 fprintf (stdout, "%s", _ ("Preprocessing complete.\n"));
665 "%s",
666 _("Preprocessing complete.\n"));
667 break; 638 break;
668 case GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED: 639 case GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED:
669 if (verbose > 2) 640 if (verbose > 2)
670 FPRINTF (stdout, 641 fprintf (stdout,
671 _("Extracting meta data from file `%s' complete.\n"), 642 _ ("Extracting meta data from file `%s' complete.\n"),
672 filename); 643 filename);
673 break; 644 break;
674 case GNUNET_FS_DIRSCANNER_FINISHED: 645 case GNUNET_FS_DIRSCANNER_FINISHED:
675 if (verbose > 1) 646 if (verbose > 1)
676 FPRINTF (stdout, 647 fprintf (stdout, "%s", _ ("Meta data extraction has finished.\n"));
677 "%s",
678 _("Meta data extraction has finished.\n"));
679 directory_scan_result = GNUNET_FS_directory_scan_get_result (ds); 648 directory_scan_result = GNUNET_FS_directory_scan_get_result (ds);
680 ds = NULL; 649 ds = NULL;
681 GNUNET_FS_share_tree_trim (directory_scan_result); 650 GNUNET_FS_share_tree_trim (directory_scan_result);
682 directory_trim_complete (directory_scan_result); 651 directory_trim_complete (directory_scan_result);
683 break; 652 break;
684 case GNUNET_FS_DIRSCANNER_INTERNAL_ERROR: 653 case GNUNET_FS_DIRSCANNER_INTERNAL_ERROR:
685 FPRINTF (stdout, 654 fprintf (stdout, "%s", _ ("Error scanning directory.\n"));
686 "%s",
687 _("Error scanning directory.\n"));
688 ret = 1; 655 ret = 1;
689 GNUNET_SCHEDULER_shutdown (); 656 GNUNET_SCHEDULER_shutdown ();
690 break; 657 break;
@@ -708,12 +675,9 @@ identity_continuation (const char *args0)
708 char *ex; 675 char *ex;
709 char *emsg; 676 char *emsg;
710 677
711 if ( (NULL != pseudonym) && 678 if ((NULL != pseudonym) && (NULL == namespace))
712 (NULL == namespace) )
713 { 679 {
714 FPRINTF (stderr, 680 fprintf (stderr, _ ("Selected pseudonym `%s' unknown\n"), pseudonym);
715 _("Selected pseudonym `%s' unknown\n"),
716 pseudonym);
717 ret = 1; 681 ret = 1;
718 GNUNET_SCHEDULER_shutdown (); 682 GNUNET_SCHEDULER_shutdown ();
719 return; 683 return;
@@ -723,17 +687,16 @@ identity_continuation (const char *args0)
723 emsg = NULL; 687 emsg = NULL;
724 if (NULL == (uri = GNUNET_FS_uri_parse (uri_string, &emsg))) 688 if (NULL == (uri = GNUNET_FS_uri_parse (uri_string, &emsg)))
725 { 689 {
726 FPRINTF (stderr, 690 fprintf (stderr, _ ("Failed to parse URI: %s\n"), emsg);
727 _("Failed to parse URI: %s\n"),
728 emsg);
729 GNUNET_free (emsg); 691 GNUNET_free (emsg);
730 ret = 1; 692 ret = 1;
731 GNUNET_SCHEDULER_shutdown (); 693 GNUNET_SCHEDULER_shutdown ();
732 return; 694 return;
733 } 695 }
734 GNUNET_FS_publish_ksk (ctx, 696 GNUNET_FS_publish_ksk (ctx,
735 topKeywords, 697 topKeywords,
736 meta, uri, 698 meta,
699 uri,
737 &bo, 700 &bo,
738 GNUNET_FS_PUBLISH_OPTION_NONE, 701 GNUNET_FS_PUBLISH_OPTION_NONE,
739 &uri_ksk_continuation, 702 &uri_ksk_continuation,
@@ -743,24 +706,27 @@ identity_continuation (const char *args0)
743 if (GNUNET_OK != 706 if (GNUNET_OK !=
744 GNUNET_CONFIGURATION_get_value_string (cfg, "FS", "EXTRACTORS", &ex)) 707 GNUNET_CONFIGURATION_get_value_string (cfg, "FS", "EXTRACTORS", &ex))
745 ex = NULL; 708 ex = NULL;
746 if (0 != ACCESS (args0, R_OK)) 709 if (0 != access (args0, R_OK))
747 { 710 {
748 FPRINTF (stderr, 711 fprintf (stderr,
749 _("Failed to access `%s': %s\n"), 712 _ ("Failed to access `%s': %s\n"),
750 args0, 713 args0,
751 STRERROR (errno)); 714 strerror (errno));
752 GNUNET_free_non_null (ex); 715 GNUNET_free_non_null (ex);
753 return; 716 return;
754 } 717 }
755 ds = GNUNET_FS_directory_scan_start (args0, 718 ds = GNUNET_FS_directory_scan_start (args0,
756 disable_extractor, 719 disable_extractor,
757 ex, 720 ex,
758 &directory_scan_cb, NULL); 721 &directory_scan_cb,
722 NULL);
759 if (NULL == ds) 723 if (NULL == ds)
760 { 724 {
761 FPRINTF (stderr, 725 fprintf (
762 "%s", 726 stderr,
763 _("Failed to start meta directory scanner. Is gnunet-helper-publish-fs installed?\n")); 727 "%s",
728 _ (
729 "Failed to start meta directory scanner. Is gnunet-helper-publish-fs installed?\n"));
764 GNUNET_free_non_null (ex); 730 GNUNET_free_non_null (ex);
765 return; 731 return;
766 } 732 }
@@ -781,9 +747,9 @@ identity_continuation (const char *args0)
781 */ 747 */
782static void 748static void
783identity_cb (void *cls, 749identity_cb (void *cls,
784 struct GNUNET_IDENTITY_Ego *ego, 750 struct GNUNET_IDENTITY_Ego *ego,
785 void **ctx, 751 void **ctx,
786 const char *name) 752 const char *name)
787{ 753{
788 const char *args0 = cls; 754 const char *args0 = cls;
789 755
@@ -795,7 +761,7 @@ identity_cb (void *cls,
795 if (NULL == name) 761 if (NULL == name)
796 return; 762 return;
797 if (0 == strcmp (name, pseudonym)) 763 if (0 == strcmp (name, pseudonym))
798 namespace = ego; 764 namespace = ego;
799} 765}
800 766
801 767
@@ -816,20 +782,20 @@ run (void *cls,
816 /* check arguments */ 782 /* check arguments */
817 if ((NULL != uri_string) && (extract_only)) 783 if ((NULL != uri_string) && (extract_only))
818 { 784 {
819 printf (_("Cannot extract metadata from a URI!\n")); 785 printf (_ ("Cannot extract metadata from a URI!\n"));
820 ret = -1; 786 ret = -1;
821 return; 787 return;
822 } 788 }
823 if (((NULL == uri_string) || (extract_only)) && 789 if (((NULL == uri_string) || (extract_only)) &&
824 ((NULL == args[0]) || (NULL != args[1]))) 790 ((NULL == args[0]) || (NULL != args[1])))
825 { 791 {
826 printf (_("You must specify one and only one filename for insertion.\n")); 792 printf (_ ("You must specify one and only one filename for insertion.\n"));
827 ret = -1; 793 ret = -1;
828 return; 794 return;
829 } 795 }
830 if ((NULL != uri_string) && (NULL != args[0])) 796 if ((NULL != uri_string) && (NULL != args[0]))
831 { 797 {
832 printf (_("You must NOT specify an URI and a filename.\n")); 798 printf (_ ("You must NOT specify an URI and a filename.\n"));
833 ret = -1; 799 ret = -1;
834 return; 800 return;
835 } 801 }
@@ -837,49 +803,51 @@ run (void *cls,
837 { 803 {
838 if (NULL == this_id) 804 if (NULL == this_id)
839 { 805 {
840 FPRINTF (stderr, _("Option `%s' is required when using option `%s'.\n"), 806 fprintf (stderr,
841 "-t", "-P"); 807 _ ("Option `%s' is required when using option `%s'.\n"),
808 "-t",
809 "-P");
842 ret = -1; 810 ret = -1;
843 return; 811 return;
844 } 812 }
845 } 813 }
846 else 814 else
847 { /* ordinary insertion checks */ 815 { /* ordinary insertion checks */
848 if (NULL != next_id) 816 if (NULL != next_id)
849 { 817 {
850 FPRINTF (stderr, 818 fprintf (stderr,
851 _("Option `%s' makes no sense without option `%s'.\n"), 819 _ ("Option `%s' makes no sense without option `%s'.\n"),
852 "-N", "-P"); 820 "-N",
821 "-P");
853 ret = -1; 822 ret = -1;
854 return; 823 return;
855 } 824 }
856 if (NULL != this_id) 825 if (NULL != this_id)
857 { 826 {
858 FPRINTF (stderr, 827 fprintf (stderr,
859 _("Option `%s' makes no sense without option `%s'.\n"), 828 _ ("Option `%s' makes no sense without option `%s'.\n"),
860 "-t", "-P"); 829 "-t",
830 "-P");
861 ret = -1; 831 ret = -1;
862 return; 832 return;
863 } 833 }
864 } 834 }
865 cfg = c; 835 cfg = c;
866 ctx = 836 ctx = GNUNET_FS_start (cfg,
867 GNUNET_FS_start (cfg, "gnunet-publish", &progress_cb, NULL, 837 "gnunet-publish",
868 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); 838 &progress_cb,
839 NULL,
840 GNUNET_FS_FLAGS_NONE,
841 GNUNET_FS_OPTIONS_END);
869 if (NULL == ctx) 842 if (NULL == ctx)
870 { 843 {
871 FPRINTF (stderr, 844 fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS");
872 _("Could not initialize `%s' subsystem.\n"),
873 "FS");
874 ret = 1; 845 ret = 1;
875 return; 846 return;
876 } 847 }
877 GNUNET_SCHEDULER_add_shutdown (&do_stop_task, 848 GNUNET_SCHEDULER_add_shutdown (&do_stop_task, NULL);
878 NULL);
879 if (NULL != pseudonym) 849 if (NULL != pseudonym)
880 identity = GNUNET_IDENTITY_connect (cfg, 850 identity = GNUNET_IDENTITY_connect (cfg, &identity_cb, args[0]);
881 &identity_cb,
882 args[0]);
883 else 851 else
884 identity_continuation (args[0]); 852 identity_continuation (args[0]);
885} 853}
@@ -893,104 +861,120 @@ run (void *cls,
893 * @return 0 ok, 1 on error 861 * @return 0 ok, 1 on error
894 */ 862 */
895int 863int
896main (int argc, 864main (int argc, char *const *argv)
897 char *const *argv)
898{ 865{
899 struct GNUNET_GETOPT_CommandLineOption options[] = { 866 struct GNUNET_GETOPT_CommandLineOption options[] =
900 GNUNET_GETOPT_option_uint ('a', 867 {GNUNET_GETOPT_option_uint ('a',
901 "anonymity", 868 "anonymity",
902 "LEVEL", 869 "LEVEL",
903 gettext_noop ("set the desired LEVEL of sender-anonymity"), 870 gettext_noop (
904 &bo.anonymity_level), 871 "set the desired LEVEL of sender-anonymity"),
905 GNUNET_GETOPT_option_flag ('D', 872 &bo.anonymity_level),
906 "disable-extractor", 873 GNUNET_GETOPT_option_flag (
907 gettext_noop ("do not use libextractor to add keywords or metadata"), 874 'D',
908 &disable_extractor), 875 "disable-extractor",
909 GNUNET_GETOPT_option_flag ('E', 876 gettext_noop ("do not use libextractor to add keywords or metadata"),
910 "enable-creation-time", 877 &disable_extractor),
911 gettext_noop ("enable adding the creation time to the " 878 GNUNET_GETOPT_option_flag ('E',
912 "metadata of the uploaded file"), 879 "enable-creation-time",
913 &enable_creation_time), 880 gettext_noop (
914 GNUNET_GETOPT_option_flag ('e', 881 "enable adding the creation time to the "
915 "extract", 882 "metadata of the uploaded file"),
916 gettext_noop ("print list of extracted keywords that would " 883 &enable_creation_time),
917 "be used, but do not perform upload"), 884 GNUNET_GETOPT_option_flag ('e',
918 &extract_only), 885 "extract",
919 GNUNET_FS_GETOPT_KEYWORDS ('k', 886 gettext_noop (
920 "key", 887 "print list of extracted keywords that would "
921 "KEYWORD", 888 "be used, but do not perform upload"),
922 gettext_noop ("add an additional keyword for the top-level " 889 &extract_only),
923 "file or directory (this option can be specified multiple times)"), 890 GNUNET_FS_GETOPT_KEYWORDS (
924 &topKeywords), 891 'k',
925 GNUNET_FS_GETOPT_METADATA ('m', 892 "key",
926 "meta", 893 "KEYWORD",
927 "TYPE:VALUE", 894 gettext_noop (
928 gettext_noop ("set the meta-data for the given TYPE to the given VALUE"), 895 "add an additional keyword for the top-level "
929 &meta), 896 "file or directory (this option can be specified multiple times)"),
930 GNUNET_GETOPT_option_flag ('n', 897 &topKeywords),
931 "noindex", 898 GNUNET_FS_GETOPT_METADATA (
932 gettext_noop ("do not index, perform full insertion (stores " 899 'm',
933 "entire file in encrypted form in GNUnet database)"), 900 "meta",
934 &do_insert), 901 "TYPE:VALUE",
935 GNUNET_GETOPT_option_string ('N', 902 gettext_noop ("set the meta-data for the given TYPE to the given VALUE"),
936 "next", 903 &meta),
937 "ID", 904 GNUNET_GETOPT_option_flag (
938 gettext_noop ("specify ID of an updated version to be " 905 'n',
939 "published in the future (for namespace insertions only)"), 906 "noindex",
940 &next_id), 907 gettext_noop ("do not index, perform full insertion (stores "
941 GNUNET_GETOPT_option_uint ('p', 908 "entire file in encrypted form in GNUnet database)"),
942 "priority", 909 &do_insert),
943 "PRIORITY", 910 GNUNET_GETOPT_option_string (
944 gettext_noop ("specify the priority of the content"), 911 'N',
945 &bo.content_priority), 912 "next",
946 GNUNET_GETOPT_option_string ('P', 913 "ID",
947 "pseudonym", 914 gettext_noop ("specify ID of an updated version to be "
948 "NAME", 915 "published in the future (for namespace insertions only)"),
949 gettext_noop ("publish the files under the pseudonym " 916 &next_id),
950 "NAME (place file into namespace)"), 917 GNUNET_GETOPT_option_uint ('p',
951 &pseudonym), 918 "priority",
952 GNUNET_GETOPT_option_uint ('r', 919 "PRIORITY",
953 "replication", 920 gettext_noop (
954 "LEVEL", 921 "specify the priority of the content"),
955 gettext_noop ("set the desired replication LEVEL"), 922 &bo.content_priority),
956 &bo.replication_level), 923 GNUNET_GETOPT_option_string ('P',
957 GNUNET_GETOPT_option_flag ('s', 924 "pseudonym",
958 "simulate-only", 925 "NAME",
959 gettext_noop ("only simulate the process but do not do " 926 gettext_noop (
960 "any actual publishing (useful to compute URIs)"), 927 "publish the files under the pseudonym "
961 &do_simulate), 928 "NAME (place file into namespace)"),
962 GNUNET_GETOPT_option_string ('t', 929 &pseudonym),
963 "this", 930 GNUNET_GETOPT_option_uint ('r',
964 "ID", 931 "replication",
965 gettext_noop ("set the ID of this version of the publication " 932 "LEVEL",
966 "(for namespace insertions only)"), 933 gettext_noop (
967 &this_id), 934 "set the desired replication LEVEL"),
968 GNUNET_GETOPT_option_string ('u', 935 &bo.replication_level),
969 "uri", 936 GNUNET_GETOPT_option_flag ('s',
970 "URI", 937 "simulate-only",
971 gettext_noop ("URI to be published (can be used instead of passing a " 938 gettext_noop (
972 "file to add keywords to the file with the respective URI)"), 939 "only simulate the process but do not do "
973 &uri_string), 940 "any actual publishing (useful to compute URIs)"),
974 941 &do_simulate),
975 GNUNET_GETOPT_option_verbose (&verbose), 942 GNUNET_GETOPT_option_string ('t',
976 943 "this",
977 GNUNET_GETOPT_OPTION_END 944 "ID",
978 }; 945 gettext_noop (
946 "set the ID of this version of the publication "
947 "(for namespace insertions only)"),
948 &this_id),
949 GNUNET_GETOPT_option_string (
950 'u',
951 "uri",
952 "URI",
953 gettext_noop (
954 "URI to be published (can be used instead of passing a "
955 "file to add keywords to the file with the respective URI)"),
956 &uri_string),
957
958 GNUNET_GETOPT_option_verbose (&verbose),
959
960 GNUNET_GETOPT_OPTION_END};
979 bo.expiration_time = 961 bo.expiration_time =
980 GNUNET_TIME_year_to_time (GNUNET_TIME_get_current_year () + 2); 962 GNUNET_TIME_year_to_time (GNUNET_TIME_get_current_year () + 2);
981 963
982 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 964 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
983 return 2; 965 return 2;
984 ret = (GNUNET_OK == 966 ret =
985 GNUNET_PROGRAM_run (argc, 967 (GNUNET_OK ==
986 argv, 968 GNUNET_PROGRAM_run (argc,
987 "gnunet-publish [OPTIONS] FILENAME", 969 argv,
988 gettext_noop 970 "gnunet-publish [OPTIONS] FILENAME",
989 ("Publish a file or directory on GNUnet"), 971 gettext_noop ("Publish a file or directory on GNUnet"),
990 options, 972 options,
991 &run, 973 &run,
992 NULL)) ? ret : 1; 974 NULL))
993 GNUNET_free ((void*) argv); 975 ? ret
976 : 1;
977 GNUNET_free ((void *) argv);
994 return ret; 978 return ret;
995} 979}
996 980
diff --git a/src/fs/gnunet-search.c b/src/fs/gnunet-search.c
index 3995b1b5b..7d6ff4c6b 100644
--- a/src/fs/gnunet-search.c
+++ b/src/fs/gnunet-search.c
@@ -92,11 +92,10 @@ item_printer (void *cls,
92#if HAVE_LIBEXTRACTOR 92#if HAVE_LIBEXTRACTOR
93 printf ("\t%20s: %s\n", 93 printf ("\t%20s: %s\n",
94 dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, 94 dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN,
95 EXTRACTOR_metatype_to_string (type)), data); 95 EXTRACTOR_metatype_to_string (type)),
96#else
97 printf ("\t%20d: %s\n",
98 type,
99 data); 96 data);
97#else
98 printf ("\t%20d: %s\n", type, data);
100#endif 99#endif
101 return 0; 100 return 0;
102} 101}
@@ -118,13 +117,14 @@ clean_task (void *cls)
118 GNUNET_free (output_filename); 117 GNUNET_free (output_filename);
119 return; 118 return;
120 } 119 }
121 if (dsize != 120 if (dsize != GNUNET_DISK_fn_write (output_filename,
122 GNUNET_DISK_fn_write (output_filename, ddata, dsize, 121 ddata,
123 GNUNET_DISK_PERM_USER_READ | 122 dsize,
124 GNUNET_DISK_PERM_USER_WRITE)) 123 GNUNET_DISK_PERM_USER_READ |
124 GNUNET_DISK_PERM_USER_WRITE))
125 { 125 {
126 FPRINTF (stderr, 126 fprintf (stderr,
127 _("Failed to write directory with search results to `%s'\n"), 127 _ ("Failed to write directory with search results to `%s'\n"),
128 output_filename); 128 output_filename);
129 } 129 }
130 GNUNET_free_non_null (ddata); 130 GNUNET_free_non_null (ddata);
@@ -165,31 +165,35 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
165 NULL); 165 NULL);
166 uri = GNUNET_FS_uri_to_string (info->value.search.specifics.result.uri); 166 uri = GNUNET_FS_uri_to_string (info->value.search.specifics.result.uri);
167 printf ("#%u:\n", ++cnt); 167 printf ("#%u:\n", ++cnt);
168 filename = 168 filename = GNUNET_CONTAINER_meta_data_get_by_type (
169 GNUNET_CONTAINER_meta_data_get_by_type (info->value.search. 169 info->value.search.specifics.result.meta,
170 specifics.result.meta, 170 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
171 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); 171 is_directory = GNUNET_FS_meta_data_test_for_directory (
172 is_directory = 172 info->value.search.specifics.result.meta);
173 GNUNET_FS_meta_data_test_for_directory (info->value.search.
174 specifics.result.meta);
175 if (NULL != filename) 173 if (NULL != filename)
176 { 174 {
177 while ( (filename[0] != '\0') && 175 while ((filename[0] != '\0') && ('/' == filename[strlen (filename) - 1]))
178 ('/' == filename[strlen(filename)-1]) ) 176 filename[strlen (filename) - 1] = '\0';
179 filename[strlen(filename)-1] = '\0';
180 GNUNET_DISK_filename_canonicalize (filename); 177 GNUNET_DISK_filename_canonicalize (filename);
181 if (GNUNET_YES == is_directory) 178 if (GNUNET_YES == is_directory)
182 printf ("gnunet-download -o \"%s%s\" -R %s\n", filename, GNUNET_FS_DIRECTORY_EXT, uri); 179 printf ("gnunet-download -o \"%s%s\" -R %s\n",
180 filename,
181 GNUNET_FS_DIRECTORY_EXT,
182 uri);
183 else 183 else
184 printf ("gnunet-download -o \"%s\" %s\n", filename, uri); 184 printf ("gnunet-download -o \"%s\" %s\n", filename, uri);
185 } 185 }
186 else if (GNUNET_YES == is_directory) 186 else if (GNUNET_YES == is_directory)
187 printf ("gnunet-download -o \"collection%s\" -R %s\n", GNUNET_FS_DIRECTORY_EXT, uri); 187 printf ("gnunet-download -o \"collection%s\" -R %s\n",
188 GNUNET_FS_DIRECTORY_EXT,
189 uri);
188 else 190 else
189 printf ("gnunet-download %s\n", uri); 191 printf ("gnunet-download %s\n", uri);
190 if (verbose) 192 if (verbose)
191 GNUNET_CONTAINER_meta_data_iterate (info->value.search.specifics. 193 GNUNET_CONTAINER_meta_data_iterate (info->value.search.specifics.result
192 result.meta, &item_printer, NULL); 194 .meta,
195 &item_printer,
196 NULL);
193 printf ("\n"); 197 printf ("\n");
194 fflush (stdout); 198 fflush (stdout);
195 GNUNET_free_non_null (filename); 199 GNUNET_free_non_null (filename);
@@ -204,7 +208,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
204 /* ignore */ 208 /* ignore */
205 break; 209 break;
206 case GNUNET_FS_STATUS_SEARCH_ERROR: 210 case GNUNET_FS_STATUS_SEARCH_ERROR:
207 FPRINTF (stderr, _("Error searching: %s.\n"), 211 fprintf (stderr,
212 _ ("Error searching: %s.\n"),
208 info->value.search.specifics.error.message); 213 info->value.search.specifics.error.message);
209 GNUNET_SCHEDULER_shutdown (); 214 GNUNET_SCHEDULER_shutdown ();
210 break; 215 break;
@@ -212,7 +217,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
212 GNUNET_SCHEDULER_add_now (&clean_task, NULL); 217 GNUNET_SCHEDULER_add_now (&clean_task, NULL);
213 break; 218 break;
214 default: 219 default:
215 FPRINTF (stderr, _("Unexpected status: %d\n"), info->status); 220 fprintf (stderr, _ ("Unexpected status: %d\n"), info->status);
216 break; 221 break;
217 } 222 }
218 return NULL; 223 return NULL;
@@ -247,7 +252,9 @@ timeout_task (void *cls)
247 * @param c configuration 252 * @param c configuration
248 */ 253 */
249static void 254static void
250run (void *cls, char *const *args, const char *cfgfile, 255run (void *cls,
256 char *const *args,
257 const char *cfgfile,
251 const struct GNUNET_CONFIGURATION_Handle *c) 258 const struct GNUNET_CONFIGURATION_Handle *c)
252{ 259{
253 struct GNUNET_FS_Uri *uri; 260 struct GNUNET_FS_Uri *uri;
@@ -260,17 +267,22 @@ run (void *cls, char *const *args, const char *cfgfile,
260 uri = GNUNET_FS_uri_ksk_create_from_args (argc, (const char **) args); 267 uri = GNUNET_FS_uri_ksk_create_from_args (argc, (const char **) args);
261 if (NULL == uri) 268 if (NULL == uri)
262 { 269 {
263 FPRINTF (stderr, "%s", _("Could not create keyword URI from arguments.\n")); 270 fprintf (stderr,
271 "%s",
272 _ ("Could not create keyword URI from arguments.\n"));
264 ret = 1; 273 ret = 1;
265 return; 274 return;
266 } 275 }
267 cfg = c; 276 cfg = c;
268 ctx = 277 ctx = GNUNET_FS_start (cfg,
269 GNUNET_FS_start (cfg, "gnunet-search", &progress_cb, NULL, 278 "gnunet-search",
270 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); 279 &progress_cb,
280 NULL,
281 GNUNET_FS_FLAGS_NONE,
282 GNUNET_FS_OPTIONS_END);
271 if (NULL == ctx) 283 if (NULL == ctx)
272 { 284 {
273 FPRINTF (stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); 285 fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS");
274 GNUNET_FS_uri_destroy (uri); 286 GNUNET_FS_uri_destroy (uri);
275 ret = 1; 287 ret = 1;
276 return; 288 return;
@@ -284,17 +296,14 @@ run (void *cls, char *const *args, const char *cfgfile,
284 GNUNET_FS_uri_destroy (uri); 296 GNUNET_FS_uri_destroy (uri);
285 if (NULL == sc) 297 if (NULL == sc)
286 { 298 {
287 FPRINTF (stderr, "%s", _("Could not start searching.\n")); 299 fprintf (stderr, "%s", _ ("Could not start searching.\n"));
288 GNUNET_FS_stop (ctx); 300 GNUNET_FS_stop (ctx);
289 ret = 1; 301 ret = 1;
290 return; 302 return;
291 } 303 }
292 if (0 != timeout.rel_value_us) 304 if (0 != timeout.rel_value_us)
293 tt = GNUNET_SCHEDULER_add_delayed (timeout, 305 tt = GNUNET_SCHEDULER_add_delayed (timeout, &timeout_task, NULL);
294 &timeout_task, 306 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
295 NULL);
296 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
297 NULL);
298} 307}
299 308
300 309
@@ -308,49 +317,55 @@ run (void *cls, char *const *args, const char *cfgfile,
308int 317int
309main (int argc, char *const *argv) 318main (int argc, char *const *argv)
310{ 319{
311 struct GNUNET_GETOPT_CommandLineOption options[] = { 320 struct GNUNET_GETOPT_CommandLineOption options[] =
312 GNUNET_GETOPT_option_uint ('a', 321 {GNUNET_GETOPT_option_uint ('a',
313 "anonymity", 322 "anonymity",
314 "LEVEL", 323 "LEVEL",
315 gettext_noop ("set the desired LEVEL of receiver-anonymity"), 324 gettext_noop (
316 &anonymity), 325 "set the desired LEVEL of receiver-anonymity"),
317 GNUNET_GETOPT_option_flag ('n', 326 &anonymity),
318 "no-network", 327 GNUNET_GETOPT_option_flag (
319 gettext_noop ("only search the local peer (no P2P network search)"), 328 'n',
320 &local_only), 329 "no-network",
321 GNUNET_GETOPT_option_string ('o', 330 gettext_noop ("only search the local peer (no P2P network search)"),
322 "output", 331 &local_only),
323 "PREFIX", 332 GNUNET_GETOPT_option_string (
324 gettext_noop ("write search results to file starting with PREFIX"), 333 'o',
325 &output_filename), 334 "output",
326 GNUNET_GETOPT_option_relative_time ('t', 335 "PREFIX",
327 "timeout", 336 gettext_noop ("write search results to file starting with PREFIX"),
328 "DELAY", 337 &output_filename),
329 gettext_noop ("automatically terminate search after DELAY"), 338 GNUNET_GETOPT_option_relative_time (
330 &timeout), 339 't',
331 GNUNET_GETOPT_option_verbose (&verbose), 340 "timeout",
332 GNUNET_GETOPT_option_uint ('N', 341 "DELAY",
333 "results", 342 gettext_noop ("automatically terminate search after DELAY"),
334 "VALUE", 343 &timeout),
335 gettext_noop ("automatically terminate search " 344 GNUNET_GETOPT_option_verbose (&verbose),
336 "after VALUE results are found"), 345 GNUNET_GETOPT_option_uint ('N',
337 &results_limit), 346 "results",
338 GNUNET_GETOPT_OPTION_END 347 "VALUE",
339 }; 348 gettext_noop ("automatically terminate search "
340 349 "after VALUE results are found"),
341 if (GNUNET_OK != 350 &results_limit),
342 GNUNET_STRINGS_get_utf8_args (argc, argv, 351 GNUNET_GETOPT_OPTION_END};
343 &argc, &argv)) 352
353 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
344 return 2; 354 return 2;
345 355
346 ret = (GNUNET_OK == 356 ret =
347 GNUNET_PROGRAM_run (argc, 357 (GNUNET_OK ==
348 argv, 358 GNUNET_PROGRAM_run (argc,
349 "gnunet-search [OPTIONS] KEYWORD", 359 argv,
350 gettext_noop 360 "gnunet-search [OPTIONS] KEYWORD",
351 ("Search GNUnet for files that were published on GNUnet"), 361 gettext_noop (
352 options, &run, NULL)) ? ret : 1; 362 "Search GNUnet for files that were published on GNUnet"),
353 GNUNET_free ((void*) argv); 363 options,
364 &run,
365 NULL))
366 ? ret
367 : 1;
368 GNUNET_free ((void *) argv);
354 return ret; 369 return ret;
355} 370}
356 371
diff --git a/src/fs/gnunet-service-fs_indexing.c b/src/fs/gnunet-service-fs_indexing.c
index 0e8e62fc7..df5f70b3d 100644
--- a/src/fs/gnunet-service-fs_indexing.c
+++ b/src/fs/gnunet-service-fs_indexing.c
@@ -73,7 +73,6 @@ struct IndexInfo
73 * Hash of the contents of the file. 73 * Hash of the contents of the file.
74 */ 74 */
75 struct GNUNET_HashCode file_id; 75 struct GNUNET_HashCode file_id;
76
77}; 76};
78 77
79 78
@@ -118,12 +117,10 @@ write_index_list ()
118 struct IndexInfo *pos; 117 struct IndexInfo *pos;
119 118
120 if (GNUNET_OK != 119 if (GNUNET_OK !=
121 GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", 120 GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn))
122 "INDEXDB",
123 &fn))
124 { 121 {
125 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 122 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
126 "fs", 123 "fs",
127 "INDEXDB"); 124 "INDEXDB");
128 return; 125 return;
129 } 126 }
@@ -131,24 +128,21 @@ write_index_list ()
131 if (NULL == wh) 128 if (NULL == wh)
132 { 129 {
133 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 130 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
134 _("Could not open `%s'.\n"), 131 _ ("Could not open `%s'.\n"),
135 fn); 132 fn);
136 GNUNET_free (fn); 133 GNUNET_free (fn);
137 return; 134 return;
138 } 135 }
139 for (pos = indexed_files_head; NULL != pos; pos = pos->next) 136 for (pos = indexed_files_head; NULL != pos; pos = pos->next)
140 if ((GNUNET_OK != 137 if ((GNUNET_OK != GNUNET_BIO_write (wh,
141 GNUNET_BIO_write (wh, 138 &pos->file_id,
142 &pos->file_id, 139 sizeof (struct GNUNET_HashCode))) ||
143 sizeof (struct GNUNET_HashCode))) || 140 (GNUNET_OK != GNUNET_BIO_write_string (wh, pos->filename)))
144 (GNUNET_OK !=
145 GNUNET_BIO_write_string (wh,
146 pos->filename)))
147 break; 141 break;
148 if (GNUNET_OK != GNUNET_BIO_write_close (wh)) 142 if (GNUNET_OK != GNUNET_BIO_write_close (wh))
149 { 143 {
150 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 144 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
151 _("Error writing `%s'.\n"), 145 _ ("Error writing `%s'.\n"),
152 fn); 146 fn);
153 GNUNET_free (fn); 147 GNUNET_free (fn);
154 return; 148 return;
@@ -172,13 +166,10 @@ read_index_list ()
172 char *emsg; 166 char *emsg;
173 167
174 if (GNUNET_OK != 168 if (GNUNET_OK !=
175 GNUNET_CONFIGURATION_get_value_filename (cfg, 169 GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn))
176 "FS",
177 "INDEXDB",
178 &fn))
179 { 170 {
180 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 171 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
181 "fs", 172 "fs",
182 "INDEXDB"); 173 "INDEXDB");
183 return; 174 return;
184 } 175 }
@@ -192,39 +183,36 @@ read_index_list ()
192 if (NULL == rh) 183 if (NULL == rh)
193 { 184 {
194 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 185 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
195 _("Could not open `%s'.\n"), 186 _ ("Could not open `%s'.\n"),
196 fn); 187 fn);
197 GNUNET_free (fn); 188 GNUNET_free (fn);
198 return; 189 return;
199 } 190 }
200 while ( (GNUNET_OK == 191 while (
201 GNUNET_BIO_read (rh, 192 (GNUNET_OK == GNUNET_BIO_read (rh,
202 "Hash of indexed file", 193 "Hash of indexed file",
203 &hc, 194 &hc,
204 sizeof (struct GNUNET_HashCode))) && 195 sizeof (struct GNUNET_HashCode))) &&
205 (GNUNET_OK == 196 (GNUNET_OK ==
206 GNUNET_BIO_read_string (rh, 197 GNUNET_BIO_read_string (rh, "Name of indexed file", &fname, 1024 * 16)) &&
207 "Name of indexed file", 198 (fname != NULL))
208 &fname,
209 1024 * 16)) &&
210 (fname != NULL) )
211 { 199 {
212 slen = strlen (fname) + 1; 200 slen = strlen (fname) + 1;
213 pos = GNUNET_malloc (sizeof (struct IndexInfo) + slen); 201 pos = GNUNET_malloc (sizeof (struct IndexInfo) + slen);
214 pos->file_id = hc; 202 pos->file_id = hc;
215 pos->filename = (const char *) &pos[1]; 203 pos->filename = (const char *) &pos[1];
216 GNUNET_memcpy (&pos[1], fname, slen); 204 GNUNET_memcpy (&pos[1], fname, slen);
217 if (GNUNET_SYSERR == 205 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
218 GNUNET_CONTAINER_multihashmap_put (ifm, &pos->file_id, pos, 206 ifm,
219 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 207 &pos->file_id,
208 pos,
209 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
220 { 210 {
221 GNUNET_free (pos); 211 GNUNET_free (pos);
222 } 212 }
223 else 213 else
224 { 214 {
225 GNUNET_CONTAINER_DLL_insert (indexed_files_head, 215 GNUNET_CONTAINER_DLL_insert (indexed_files_head, indexed_files_tail, pos);
226 indexed_files_tail,
227 pos);
228 } 216 }
229 GNUNET_free (fname); 217 GNUNET_free (fname);
230 } 218 }
@@ -244,13 +232,15 @@ read_index_list ()
244 * @param msg error message 232 * @param msg error message
245 */ 233 */
246static void 234static void
247remove_cont (void *cls, int success, 235remove_cont (void *cls,
248 struct GNUNET_TIME_Absolute min_expiration, 236 int success,
249 const char *msg) 237 struct GNUNET_TIME_Absolute min_expiration,
238 const char *msg)
250{ 239{
251 if (GNUNET_OK != success) 240 if (GNUNET_OK != success)
252 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 241 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
253 _("Failed to delete bogus block: %s\n"), msg); 242 _ ("Failed to delete bogus block: %s\n"),
243 msg);
254} 244}
255 245
256 246
@@ -275,7 +265,7 @@ remove_cont (void *cls, int success,
275 * @return GNUNET_OK on success 265 * @return GNUNET_OK on success
276 */ 266 */
277int 267int
278GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode * key, 268GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode *key,
279 uint32_t size, 269 uint32_t size,
280 const void *data, 270 const void *data,
281 enum GNUNET_BLOCK_Type type, 271 enum GNUNET_BLOCK_Type type,
@@ -303,19 +293,12 @@ GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode * key,
303 if (size != sizeof (struct OnDemandBlock)) 293 if (size != sizeof (struct OnDemandBlock))
304 { 294 {
305 GNUNET_break (0); 295 GNUNET_break (0);
306 GNUNET_DATASTORE_remove (dsh, 296 GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL);
307 key,
308 size,
309 data,
310 -1,
311 -1,
312 &remove_cont, NULL);
313 return GNUNET_SYSERR; 297 return GNUNET_SYSERR;
314 } 298 }
315 odb = (const struct OnDemandBlock *) data; 299 odb = (const struct OnDemandBlock *) data;
316 off = GNUNET_ntohll (odb->offset); 300 off = GNUNET_ntohll (odb->offset);
317 ii = GNUNET_CONTAINER_multihashmap_get (ifm, 301 ii = GNUNET_CONTAINER_multihashmap_get (ifm, &odb->file_id);
318 &odb->file_id);
319 if (NULL == ii) 302 if (NULL == ii)
320 { 303 {
321 GNUNET_break (0); 304 GNUNET_break (0);
@@ -325,83 +308,46 @@ GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode * key,
325 return GNUNET_SYSERR; 308 return GNUNET_SYSERR;
326 } 309 }
327 fn = ii->filename; 310 fn = ii->filename;
328 if ((NULL == fn) || (0 != ACCESS (fn, R_OK))) 311 if ((NULL == fn) || (0 != access (fn, R_OK)))
329 { 312 {
330 GNUNET_STATISTICS_update (GSF_stats, 313 GNUNET_STATISTICS_update (
331 gettext_noop ("# index blocks removed: original file inaccessible"), 314 GSF_stats,
332 1, 315 gettext_noop ("# index blocks removed: original file inaccessible"),
333 GNUNET_YES); 316 1,
334 GNUNET_DATASTORE_remove (dsh, 317 GNUNET_YES);
335 key, 318 GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL);
336 size,
337 data,
338 -1,
339 -1,
340 &remove_cont,
341 NULL);
342 return GNUNET_SYSERR; 319 return GNUNET_SYSERR;
343 } 320 }
344 if ( (NULL == 321 if ((NULL == (fh = GNUNET_DISK_file_open (fn,
345 (fh = 322 GNUNET_DISK_OPEN_READ,
346 GNUNET_DISK_file_open (fn, 323 GNUNET_DISK_PERM_NONE))) ||
347 GNUNET_DISK_OPEN_READ, 324 (off != GNUNET_DISK_file_seek (fh, off, GNUNET_DISK_SEEK_SET)) ||
348 GNUNET_DISK_PERM_NONE))) || 325 (-1 == (nsize = GNUNET_DISK_file_read (fh, ndata, sizeof (ndata)))))
349 (off != GNUNET_DISK_file_seek (fh,
350 off,
351 GNUNET_DISK_SEEK_SET)) ||
352 (-1 == (nsize = GNUNET_DISK_file_read (fh,
353 ndata,
354 sizeof (ndata)))) )
355 { 326 {
356 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 327 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
357 _("Could not access indexed file `%s' (%s) at offset %llu: %s\n"), 328 _ (
329 "Could not access indexed file `%s' (%s) at offset %llu: %s\n"),
358 GNUNET_h2s (&odb->file_id), 330 GNUNET_h2s (&odb->file_id),
359 fn, 331 fn,
360 (unsigned long long) off, 332 (unsigned long long) off,
361 (fn == NULL) ? _("not indexed") : STRERROR (errno)); 333 (fn == NULL) ? _ ("not indexed") : strerror (errno));
362 if (fh != NULL) 334 if (fh != NULL)
363 GNUNET_DISK_file_close (fh); 335 GNUNET_DISK_file_close (fh);
364 GNUNET_DATASTORE_remove (dsh, 336 GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL);
365 key,
366 size,
367 data,
368 -1,
369 -1,
370 &remove_cont,
371 NULL);
372 return GNUNET_SYSERR; 337 return GNUNET_SYSERR;
373 } 338 }
374 GNUNET_DISK_file_close (fh); 339 GNUNET_DISK_file_close (fh);
375 GNUNET_CRYPTO_hash (ndata, 340 GNUNET_CRYPTO_hash (ndata, nsize, &nkey);
376 nsize, 341 GNUNET_CRYPTO_hash_to_aes_key (&nkey, &skey, &iv);
377 &nkey); 342 GNUNET_CRYPTO_symmetric_encrypt (ndata, nsize, &skey, &iv, edata);
378 GNUNET_CRYPTO_hash_to_aes_key (&nkey, 343 GNUNET_CRYPTO_hash (edata, nsize, &query);
379 &skey, 344 if (0 != memcmp (&query, key, sizeof (struct GNUNET_HashCode)))
380 &iv);
381 GNUNET_CRYPTO_symmetric_encrypt (ndata,
382 nsize,
383 &skey,
384 &iv,
385 edata);
386 GNUNET_CRYPTO_hash (edata,
387 nsize,
388 &query);
389 if (0 != memcmp (&query,
390 key,
391 sizeof (struct GNUNET_HashCode)))
392 { 345 {
393 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 346 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
394 _("Indexed file `%s' changed at offset %llu\n"), 347 _ ("Indexed file `%s' changed at offset %llu\n"),
395 fn, 348 fn,
396 (unsigned long long) off); 349 (unsigned long long) off);
397 GNUNET_DATASTORE_remove (dsh, 350 GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL);
398 key,
399 size,
400 data,
401 -1,
402 -1,
403 &remove_cont,
404 NULL);
405 return GNUNET_SYSERR; 351 return GNUNET_SYSERR;
406 } 352 }
407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 353 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -440,27 +386,20 @@ GNUNET_FS_indexing_send_list (struct GNUNET_MQ_Handle *mq)
440 { 386 {
441 fn = pos->filename; 387 fn = pos->filename;
442 slen = strlen (fn) + 1; 388 slen = strlen (fn) + 1;
443 if (slen + sizeof (struct IndexInfoMessage) >= 389 if (slen + sizeof (struct IndexInfoMessage) >= GNUNET_MAX_MESSAGE_SIZE)
444 GNUNET_MAX_MESSAGE_SIZE)
445 { 390 {
446 GNUNET_break (0); 391 GNUNET_break (0);
447 break; 392 break;
448 } 393 }
449 env = GNUNET_MQ_msg_extra (iim, 394 env =
450 slen, 395 GNUNET_MQ_msg_extra (iim, slen, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY);
451 GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY);
452 iim->reserved = 0; 396 iim->reserved = 0;
453 iim->file_id = pos->file_id; 397 iim->file_id = pos->file_id;
454 GNUNET_memcpy (&iim[1], 398 GNUNET_memcpy (&iim[1], fn, slen);
455 fn, 399 GNUNET_MQ_send (mq, env);
456 slen);
457 GNUNET_MQ_send (mq,
458 env);
459 } 400 }
460 env = GNUNET_MQ_msg (iem, 401 env = GNUNET_MQ_msg (iem, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END);
461 GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END); 402 GNUNET_MQ_send (mq, env);
462 GNUNET_MQ_send (mq,
463 env);
464} 403}
465 404
466 405
@@ -477,17 +416,12 @@ GNUNET_FS_indexing_do_unindex (const struct GNUNET_HashCode *fid)
477 416
478 for (pos = indexed_files_head; NULL != pos; pos = pos->next) 417 for (pos = indexed_files_head; NULL != pos; pos = pos->next)
479 { 418 {
480 if (0 == memcmp (&pos->file_id, 419 if (0 == memcmp (&pos->file_id, fid, sizeof (struct GNUNET_HashCode)))
481 fid,
482 sizeof (struct GNUNET_HashCode)))
483 { 420 {
484 GNUNET_CONTAINER_DLL_remove (indexed_files_head, 421 GNUNET_CONTAINER_DLL_remove (indexed_files_head, indexed_files_tail, pos);
485 indexed_files_tail, 422 GNUNET_break (
486 pos); 423 GNUNET_OK ==
487 GNUNET_break (GNUNET_OK == 424 GNUNET_CONTAINER_multihashmap_remove (ifm, &pos->file_id, pos));
488 GNUNET_CONTAINER_multihashmap_remove (ifm,
489 &pos->file_id,
490 pos));
491 GNUNET_free (pos); 425 GNUNET_free (pos);
492 write_index_list (); 426 write_index_list ();
493 return GNUNET_YES; 427 return GNUNET_YES;
@@ -510,14 +444,15 @@ GNUNET_FS_add_to_index (const char *filename,
510 struct IndexInfo *ii; 444 struct IndexInfo *ii;
511 size_t slen; 445 size_t slen;
512 446
513 ii = GNUNET_CONTAINER_multihashmap_get (ifm, 447 ii = GNUNET_CONTAINER_multihashmap_get (ifm, file_id);
514 file_id);
515 if (NULL != ii) 448 if (NULL != ii)
516 { 449 {
517 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 450 GNUNET_log (
518 _("Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"), 451 GNUNET_ERROR_TYPE_INFO,
519 filename, 452 _ (
520 ii->filename); 453 "Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"),
454 filename,
455 ii->filename);
521 return; 456 return;
522 } 457 }
523 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -528,17 +463,14 @@ GNUNET_FS_add_to_index (const char *filename,
528 ii = GNUNET_malloc (sizeof (struct IndexInfo) + slen); 463 ii = GNUNET_malloc (sizeof (struct IndexInfo) + slen);
529 ii->file_id = *file_id; 464 ii->file_id = *file_id;
530 ii->filename = (const char *) &ii[1]; 465 ii->filename = (const char *) &ii[1];
531 GNUNET_memcpy (&ii[1], 466 GNUNET_memcpy (&ii[1], filename, slen);
532 filename, 467 GNUNET_CONTAINER_DLL_insert (indexed_files_head, indexed_files_tail, ii);
533 slen);
534 GNUNET_CONTAINER_DLL_insert (indexed_files_head,
535 indexed_files_tail,
536 ii);
537 GNUNET_assert (GNUNET_OK == 468 GNUNET_assert (GNUNET_OK ==
538 GNUNET_CONTAINER_multihashmap_put (ifm, 469 GNUNET_CONTAINER_multihashmap_put (
539 &ii->file_id, 470 ifm,
540 ii, 471 &ii->file_id,
541 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 472 ii,
473 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
542 write_index_list (); 474 write_index_list ();
543} 475}
544 476
@@ -553,15 +485,12 @@ GNUNET_FS_indexing_done ()
553 485
554 while (NULL != (pos = indexed_files_head)) 486 while (NULL != (pos = indexed_files_head))
555 { 487 {
556 GNUNET_CONTAINER_DLL_remove (indexed_files_head, 488 GNUNET_CONTAINER_DLL_remove (indexed_files_head, indexed_files_tail, pos);
557 indexed_files_tail,
558 pos);
559 if (pos->fhc != NULL) 489 if (pos->fhc != NULL)
560 GNUNET_CRYPTO_hash_file_cancel (pos->fhc); 490 GNUNET_CRYPTO_hash_file_cancel (pos->fhc);
561 GNUNET_break (GNUNET_OK == 491 GNUNET_break (
562 GNUNET_CONTAINER_multihashmap_remove (ifm, 492 GNUNET_OK ==
563 &pos->file_id, 493 GNUNET_CONTAINER_multihashmap_remove (ifm, &pos->file_id, pos));
564 pos));
565 GNUNET_free (pos); 494 GNUNET_free (pos);
566 } 495 }
567 GNUNET_CONTAINER_multihashmap_destroy (ifm); 496 GNUNET_CONTAINER_multihashmap_destroy (ifm);
@@ -582,8 +511,7 @@ GNUNET_FS_indexing_init (const struct GNUNET_CONFIGURATION_Handle *c,
582{ 511{
583 cfg = c; 512 cfg = c;
584 dsh = d; 513 dsh = d;
585 ifm = GNUNET_CONTAINER_multihashmap_create (128, 514 ifm = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_YES);
586 GNUNET_YES);
587 read_index_list (); 515 read_index_list ();
588 return GNUNET_OK; 516 return GNUNET_OK;
589} 517}
diff --git a/src/fs/gnunet-unindex.c b/src/fs/gnunet-unindex.c
index f9a3f8f3a..4d13e7ef3 100644
--- a/src/fs/gnunet-unindex.c
+++ b/src/fs/gnunet-unindex.c
@@ -85,26 +85,30 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
85 case GNUNET_FS_STATUS_UNINDEX_PROGRESS: 85 case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
86 if (verbose) 86 if (verbose)
87 { 87 {
88 s = GNUNET_STRINGS_relative_time_to_string (info->value.unindex.eta, GNUNET_YES); 88 s = GNUNET_STRINGS_relative_time_to_string (info->value.unindex.eta,
89 FPRINTF (stdout, _("Unindexing at %llu/%llu (%s remaining)\n"), 89 GNUNET_YES);
90 fprintf (stdout,
91 _ ("Unindexing at %llu/%llu (%s remaining)\n"),
90 (unsigned long long) info->value.unindex.completed, 92 (unsigned long long) info->value.unindex.completed,
91 (unsigned long long) info->value.unindex.size, s); 93 (unsigned long long) info->value.unindex.size,
94 s);
92 } 95 }
93 break; 96 break;
94 case GNUNET_FS_STATUS_UNINDEX_ERROR: 97 case GNUNET_FS_STATUS_UNINDEX_ERROR:
95 FPRINTF (stderr, _("Error unindexing: %s.\n"), 98 fprintf (stderr,
99 _ ("Error unindexing: %s.\n"),
96 info->value.unindex.specifics.error.message); 100 info->value.unindex.specifics.error.message);
97 GNUNET_SCHEDULER_shutdown (); 101 GNUNET_SCHEDULER_shutdown ();
98 break; 102 break;
99 case GNUNET_FS_STATUS_UNINDEX_COMPLETED: 103 case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
100 FPRINTF (stdout, "%s", _("Unindexing done.\n")); 104 fprintf (stdout, "%s", _ ("Unindexing done.\n"));
101 GNUNET_SCHEDULER_shutdown (); 105 GNUNET_SCHEDULER_shutdown ();
102 break; 106 break;
103 case GNUNET_FS_STATUS_UNINDEX_STOPPED: 107 case GNUNET_FS_STATUS_UNINDEX_STOPPED:
104 GNUNET_SCHEDULER_add_now (&cleanup_task, NULL); 108 GNUNET_SCHEDULER_add_now (&cleanup_task, NULL);
105 break; 109 break;
106 default: 110 default:
107 FPRINTF (stderr, _("Unexpected status: %d\n"), info->status); 111 fprintf (stderr, _ ("Unexpected status: %d\n"), info->status);
108 break; 112 break;
109 } 113 }
110 return NULL; 114 return NULL;
@@ -120,35 +124,39 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
120 * @param c configuration 124 * @param c configuration
121 */ 125 */
122static void 126static void
123run (void *cls, char *const *args, const char *cfgfile, 127run (void *cls,
128 char *const *args,
129 const char *cfgfile,
124 const struct GNUNET_CONFIGURATION_Handle *c) 130 const struct GNUNET_CONFIGURATION_Handle *c)
125{ 131{
126 /* check arguments */ 132 /* check arguments */
127 if ((args[0] == NULL) || (args[1] != NULL)) 133 if ((args[0] == NULL) || (args[1] != NULL))
128 { 134 {
129 printf (_("You must specify one and only one filename for unindexing.\n")); 135 printf (_ ("You must specify one and only one filename for unindexing.\n"));
130 ret = -1; 136 ret = -1;
131 return; 137 return;
132 } 138 }
133 cfg = c; 139 cfg = c;
134 ctx = 140 ctx = GNUNET_FS_start (cfg,
135 GNUNET_FS_start (cfg, "gnunet-unindex", &progress_cb, NULL, 141 "gnunet-unindex",
136 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); 142 &progress_cb,
143 NULL,
144 GNUNET_FS_FLAGS_NONE,
145 GNUNET_FS_OPTIONS_END);
137 if (NULL == ctx) 146 if (NULL == ctx)
138 { 147 {
139 FPRINTF (stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); 148 fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS");
140 ret = 1; 149 ret = 1;
141 return; 150 return;
142 } 151 }
143 uc = GNUNET_FS_unindex_start (ctx, args[0], NULL); 152 uc = GNUNET_FS_unindex_start (ctx, args[0], NULL);
144 if (NULL == uc) 153 if (NULL == uc)
145 { 154 {
146 FPRINTF (stderr, "%s", _("Could not start unindex operation.\n")); 155 fprintf (stderr, "%s", _ ("Could not start unindex operation.\n"));
147 GNUNET_FS_stop (ctx); 156 GNUNET_FS_stop (ctx);
148 return; 157 return;
149 } 158 }
150 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 159 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
151 NULL);
152} 160}
153 161
154 162
@@ -166,18 +174,24 @@ main (int argc, char *const *argv)
166 174
167 GNUNET_GETOPT_option_verbose (&verbose), 175 GNUNET_GETOPT_option_verbose (&verbose),
168 176
169 GNUNET_GETOPT_OPTION_END 177 GNUNET_GETOPT_OPTION_END};
170 };
171 178
172 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 179 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
173 return 2; 180 return 2;
174 181
175 ret = (GNUNET_OK == 182 ret = (GNUNET_OK ==
176 GNUNET_PROGRAM_run (argc, argv, "gnunet-unindex [OPTIONS] FILENAME", 183 GNUNET_PROGRAM_run (
177 gettext_noop 184 argc,
178 ("Unindex a file that was previously indexed with gnunet-publish."), 185 argv,
179 options, &run, NULL)) ? ret : 1; 186 "gnunet-unindex [OPTIONS] FILENAME",
180 GNUNET_free ((void*) argv); 187 gettext_noop (
188 "Unindex a file that was previously indexed with gnunet-publish."),
189 options,
190 &run,
191 NULL))
192 ? ret
193 : 1;
194 GNUNET_free ((void *) argv);
181 return ret; 195 return ret;
182} 196}
183 197
diff --git a/src/fs/perf_gnunet_service_fs_p2p.c b/src/fs/perf_gnunet_service_fs_p2p.c
index 61f859235..0d76dfc3d 100644
--- a/src/fs/perf_gnunet_service_fs_p2p.c
+++ b/src/fs/perf_gnunet_service_fs_p2p.c
@@ -116,7 +116,7 @@ print_stat (void *cls, const char *subsystem, const char *name, uint64_t value,
116{ 116{
117 struct StatMaster *sm = cls; 117 struct StatMaster *sm = cls;
118 118
119 FPRINTF (stderr, 119 fprintf (stderr,
120 "Peer %2u: %12s/%50s = %12llu\n", 120 "Peer %2u: %12s/%50s = %12llu\n",
121 sm->daemon, 121 sm->daemon,
122 subsystem, 122 subsystem,
@@ -267,7 +267,7 @@ do_report (void *cls)
267 fancy = 267 fancy =
268 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * 268 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
269 1000000LL / del.rel_value_us); 269 1000000LL / del.rel_value_us);
270 FPRINTF (stdout, 270 fprintf (stdout,
271 "Download speed was %s/s\n", 271 "Download speed was %s/s\n",
272 fancy); 272 fancy);
273 GNUNET_free (fancy); 273 GNUNET_free (fancy);
diff --git a/src/fs/perf_gnunet_service_fs_p2p_respect.c b/src/fs/perf_gnunet_service_fs_p2p_respect.c
index afde310a0..9b14b9eb6 100644
--- a/src/fs/perf_gnunet_service_fs_p2p_respect.c
+++ b/src/fs/perf_gnunet_service_fs_p2p_respect.c
@@ -168,7 +168,7 @@ print_stat (void *cls, const char *subsystem, const char *name, uint64_t value,
168{ 168{
169 struct StatMaster *sm = cls; 169 struct StatMaster *sm = cls;
170 170
171 FPRINTF (stderr, "Peer %2u: %12s/%50s = %12llu\n", sm->daemon, subsystem, 171 fprintf (stderr, "Peer %2u: %12s/%50s = %12llu\n", sm->daemon, subsystem,
172 name, (unsigned long long) value); 172 name, (unsigned long long) value);
173 return GNUNET_OK; 173 return GNUNET_OK;
174} 174}
@@ -304,7 +304,7 @@ do_report (void *cls)
304 fancy = 304 fancy =
305 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * 305 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
306 1000000LL / del.rel_value_us); 306 1000000LL / del.rel_value_us);
307 FPRINTF (stderr, "Download speed of type `%s' was %s/s\n", type, fancy); 307 fprintf (stderr, "Download speed of type `%s' was %s/s\n", type, fancy);
308 GNUNET_free (fancy); 308 GNUNET_free (fancy);
309 if (NUM_DAEMONS != ++download_counter) 309 if (NUM_DAEMONS != ++download_counter)
310 return; /* more downloads to come */ 310 return; /* more downloads to come */
diff --git a/src/fs/test_fs.c b/src/fs/test_fs.c
index 95368f108..e88c74464 100644
--- a/src/fs/test_fs.c
+++ b/src/fs/test_fs.c
@@ -226,7 +226,7 @@ FAILURE:
226 GNUNET_FSUI_stop (ctx); 226 GNUNET_FSUI_stop (ctx);
227 if (filename != NULL) 227 if (filename != NULL)
228 { 228 {
229 UNLINK (filename); 229 unlink (filename);
230 GNUNET_free (filename); 230 GNUNET_free (filename);
231 } 231 }
232 if (download != NULL) 232 if (download != NULL)
@@ -236,7 +236,7 @@ FAILURE:
236 } 236 }
237 filename = makeName (43); 237 filename = makeName (43);
238 /* TODO: verify file 'filename(42)' == file 'filename(43)' */ 238 /* TODO: verify file 'filename(42)' == file 'filename(43)' */
239 UNLINK (filename); 239 unlink (filename);
240 GNUNET_free (filename); 240 GNUNET_free (filename);
241 241
242#if START_DAEMON 242#if START_DAEMON
diff --git a/src/fs/test_fs_directory.c b/src/fs/test_fs_directory.c
index a2d131ca1..5cdbd9d07 100644
--- a/src/fs/test_fs_directory.c
+++ b/src/fs/test_fs_directory.c
@@ -59,7 +59,7 @@ processor (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri,
59 return; 59 return;
60 } 60 }
61 } 61 }
62 FPRINTF (stderr, "Error at %s:%d\n", __FILE__, __LINE__); 62 fprintf (stderr, "Error at %s:%d\n", __FILE__, __LINE__);
63} 63}
64 64
65static int 65static int
@@ -136,7 +136,7 @@ testDirectory (unsigned int i)
136 s = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration 136 s = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration
137 (start), 137 (start),
138 GNUNET_YES); 138 GNUNET_YES);
139 FPRINTF (stdout, 139 fprintf (stdout,
140 "Creating directory with %u entires and total size %llu took %s\n", 140 "Creating directory with %u entires and total size %llu took %s\n",
141 i, (unsigned long long) dlen, s); 141 i, (unsigned long long) dlen, s);
142 if (i < 100) 142 if (i < 100)
diff --git a/src/fs/test_fs_download.c b/src/fs/test_fs_download.c
index 135e2d378..242e6f1aa 100644
--- a/src/fs/test_fs_download.c
+++ b/src/fs/test_fs_download.c
@@ -195,14 +195,14 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
195 progress.offset); 195 progress.offset);
196 break; 196 break;
197 case GNUNET_FS_STATUS_PUBLISH_ERROR: 197 case GNUNET_FS_STATUS_PUBLISH_ERROR:
198 FPRINTF (stderr, "Error publishing file: %s\n", 198 fprintf (stderr, "Error publishing file: %s\n",
199 event->value.publish.specifics.error.message); 199 event->value.publish.specifics.error.message);
200 GNUNET_break (0); 200 GNUNET_break (0);
201 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); 201 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
202 GNUNET_SCHEDULER_shutdown (); 202 GNUNET_SCHEDULER_shutdown ();
203 break; 203 break;
204 case GNUNET_FS_STATUS_DOWNLOAD_ERROR: 204 case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
205 FPRINTF (stderr, "Error downloading file: %s\n", 205 fprintf (stderr, "Error downloading file: %s\n",
206 event->value.download.specifics.error.message); 206 event->value.download.specifics.error.message);
207 GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); 207 GNUNET_SCHEDULER_add_now (&abort_download_task, NULL);
208 GNUNET_SCHEDULER_shutdown (); 208 GNUNET_SCHEDULER_shutdown ();
@@ -342,7 +342,7 @@ main (int argc, char *argv[])
342 return 1; 342 return 1;
343 if (NULL != fn1) 343 if (NULL != fn1)
344 { 344 {
345 UNLINK (fn1); 345 unlink (fn1);
346 GNUNET_free (fn1); 346 GNUNET_free (fn1);
347 } 347 }
348 return err; 348 return err;
diff --git a/src/fs/test_fs_download_persistence.c b/src/fs/test_fs_download_persistence.c
index 183a407e0..97c2a338c 100644
--- a/src/fs/test_fs_download_persistence.c
+++ b/src/fs/test_fs_download_persistence.c
@@ -198,13 +198,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
198 progress.offset); 198 progress.offset);
199 break; 199 break;
200 case GNUNET_FS_STATUS_PUBLISH_ERROR: 200 case GNUNET_FS_STATUS_PUBLISH_ERROR:
201 FPRINTF (stderr, "Error publishing file: %s\n", 201 fprintf (stderr, "Error publishing file: %s\n",
202 event->value.publish.specifics.error.message); 202 event->value.publish.specifics.error.message);
203 GNUNET_break (0); 203 GNUNET_break (0);
204 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); 204 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
205 break; 205 break;
206 case GNUNET_FS_STATUS_DOWNLOAD_ERROR: 206 case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
207 FPRINTF (stderr, "Error downloading file: %s\n", 207 fprintf (stderr, "Error downloading file: %s\n",
208 event->value.download.specifics.error.message); 208 event->value.download.specifics.error.message);
209 GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); 209 GNUNET_SCHEDULER_add_now (&abort_download_task, NULL);
210 break; 210 break;
diff --git a/src/fs/test_fs_getopt.c b/src/fs/test_fs_getopt.c
index 03de383a4..3562069e1 100644
--- a/src/fs/test_fs_getopt.c
+++ b/src/fs/test_fs_getopt.c
@@ -32,6 +32,6 @@ main (int argc, char *argv[])
32 GNUNET_log_setup ("test_fs_getopt", 32 GNUNET_log_setup ("test_fs_getopt",
33 "WARNING", 33 "WARNING",
34 NULL); 34 NULL);
35 FPRINTF (stderr, "%s", "WARNING: testcase not yet written.\n"); 35 fprintf (stderr, "%s", "WARNING: testcase not yet written.\n");
36 return 0; /* testcase passed */ 36 return 0; /* testcase passed */
37} 37}
diff --git a/src/fs/test_fs_list_indexed.c b/src/fs/test_fs_list_indexed.c
index 632cba43e..a4e7eb53f 100644
--- a/src/fs/test_fs_list_indexed.c
+++ b/src/fs/test_fs_list_indexed.c
@@ -117,7 +117,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
117 break; 117 break;
118 case GNUNET_FS_STATUS_PUBLISH_ERROR: 118 case GNUNET_FS_STATUS_PUBLISH_ERROR:
119 ret = event->value.publish.cctx; 119 ret = event->value.publish.cctx;
120 FPRINTF (stderr, "Error publishing file: %s\n", 120 fprintf (stderr, "Error publishing file: %s\n",
121 event->value.publish.specifics.error.message); 121 event->value.publish.specifics.error.message);
122 err = 1; 122 err = 1;
123 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx)) 123 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx))
diff --git a/src/fs/test_fs_namespace.c b/src/fs/test_fs_namespace.c
index 56a36825c..43c899b72 100644
--- a/src/fs/test_fs_namespace.c
+++ b/src/fs/test_fs_namespace.c
@@ -85,7 +85,7 @@ static void
85do_timeout (void *cls) 85do_timeout (void *cls)
86{ 86{
87 err = 1; 87 err = 1;
88 FPRINTF (stderr, "%s", "Operation timed out\n"); 88 fprintf (stderr, "%s", "Operation timed out\n");
89 kill_task = NULL; 89 kill_task = NULL;
90 abort_sks_search_task (NULL); 90 abort_sks_search_task (NULL);
91 abort_ksk_search_task (NULL); 91 abort_ksk_search_task (NULL);
@@ -103,7 +103,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
103 if (!GNUNET_FS_uri_test_equal 103 if (!GNUNET_FS_uri_test_equal
104 (sks_expect_uri, event->value.search.specifics.result.uri)) 104 (sks_expect_uri, event->value.search.specifics.result.uri))
105 { 105 {
106 FPRINTF (stderr, "%s", "Wrong result for sks search!\n"); 106 fprintf (stderr, "%s", "Wrong result for sks search!\n");
107 err = 1; 107 err = 1;
108 } 108 }
109 /* give system 1ms to initiate update search! */ 109 /* give system 1ms to initiate update search! */
@@ -115,19 +115,19 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
115 if (!GNUNET_FS_uri_test_equal 115 if (!GNUNET_FS_uri_test_equal
116 (ksk_expect_uri, event->value.search.specifics.result.uri)) 116 (ksk_expect_uri, event->value.search.specifics.result.uri))
117 { 117 {
118 FPRINTF (stderr, "%s", "Wrong result for ksk search!\n"); 118 fprintf (stderr, "%s", "Wrong result for ksk search!\n");
119 err = 1; 119 err = 1;
120 } 120 }
121 GNUNET_SCHEDULER_add_now (&abort_ksk_search_task, NULL); 121 GNUNET_SCHEDULER_add_now (&abort_ksk_search_task, NULL);
122 } 122 }
123 else 123 else
124 { 124 {
125 FPRINTF (stderr, "%s", "Unexpected search result received!\n"); 125 fprintf (stderr, "%s", "Unexpected search result received!\n");
126 GNUNET_break (0); 126 GNUNET_break (0);
127 } 127 }
128 break; 128 break;
129 case GNUNET_FS_STATUS_SEARCH_ERROR: 129 case GNUNET_FS_STATUS_SEARCH_ERROR:
130 FPRINTF (stderr, "Error searching file: %s\n", 130 fprintf (stderr, "Error searching file: %s\n",
131 event->value.search.specifics.error.message); 131 event->value.search.specifics.error.message);
132 if (sks_search == event->value.search.sc) 132 if (sks_search == event->value.search.sc)
133 GNUNET_SCHEDULER_add_now (&abort_sks_search_task, NULL); 133 GNUNET_SCHEDULER_add_now (&abort_sks_search_task, NULL);
@@ -152,7 +152,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
152 case GNUNET_FS_STATUS_SEARCH_STOPPED: 152 case GNUNET_FS_STATUS_SEARCH_STOPPED:
153 return NULL; 153 return NULL;
154 default: 154 default:
155 FPRINTF (stderr, "Unexpected event: %d\n", event->status); 155 fprintf (stderr, "Unexpected event: %d\n", event->status);
156 break; 156 break;
157 } 157 }
158 return event->value.search.cctx; 158 return event->value.search.cctx;
@@ -170,7 +170,7 @@ publish_cont (void *cls, const struct GNUNET_FS_Uri *ksk_uri, const char *emsg)
170 170
171 if (NULL != emsg) 171 if (NULL != emsg)
172 { 172 {
173 FPRINTF (stderr, "Error publishing: %s\n", emsg); 173 fprintf (stderr, "Error publishing: %s\n", emsg);
174 err = 1; 174 err = 1;
175 GNUNET_FS_stop (fs); 175 GNUNET_FS_stop (fs);
176 return; 176 return;
@@ -182,7 +182,7 @@ publish_cont (void *cls, const struct GNUNET_FS_Uri *ksk_uri, const char *emsg)
182 sks_uri = GNUNET_FS_uri_parse (sbuf, &msg); 182 sks_uri = GNUNET_FS_uri_parse (sbuf, &msg);
183 if (NULL == sks_uri) 183 if (NULL == sks_uri)
184 { 184 {
185 FPRINTF (stderr, "failed to parse URI `%s': %s\n", sbuf, msg); 185 fprintf (stderr, "failed to parse URI `%s': %s\n", sbuf, msg);
186 err = 1; 186 err = 1;
187 GNUNET_FS_stop (fs); 187 GNUNET_FS_stop (fs);
188 GNUNET_free_non_null (msg); 188 GNUNET_free_non_null (msg);
@@ -239,7 +239,7 @@ adv_cont (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
239 239
240 if (NULL != emsg) 240 if (NULL != emsg)
241 { 241 {
242 FPRINTF (stderr, "Error publishing: %s\n", emsg); 242 fprintf (stderr, "Error publishing: %s\n", emsg);
243 err = 1; 243 err = 1;
244 GNUNET_FS_stop (fs); 244 GNUNET_FS_stop (fs);
245 return; 245 return;
diff --git a/src/fs/test_fs_publish.c b/src/fs/test_fs_publish.c
index bc38d316a..fe54bb552 100644
--- a/src/fs/test_fs_publish.c
+++ b/src/fs/test_fs_publish.c
@@ -105,12 +105,12 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
105 break; 105 break;
106 case GNUNET_FS_STATUS_PUBLISH_ERROR: 106 case GNUNET_FS_STATUS_PUBLISH_ERROR:
107 ret = event->value.publish.cctx; 107 ret = event->value.publish.cctx;
108 FPRINTF (stderr, "Error publishing file: %s\n", 108 fprintf (stderr, "Error publishing file: %s\n",
109 event->value.publish.specifics.error.message); 109 event->value.publish.specifics.error.message);
110 err = 1; 110 err = 1;
111 if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) 111 if (0 == strcmp ("publish-context-dir", event->value.publish.cctx))
112 { 112 {
113 FPRINTF (stderr, "Scheduling abort task for error on `%s'\n", 113 fprintf (stderr, "Scheduling abort task for error on `%s'\n",
114 (const char *) event->value.publish.cctx); 114 (const char *) event->value.publish.cctx);
115 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); 115 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
116 } 116 }
diff --git a/src/fs/test_fs_publish_persistence.c b/src/fs/test_fs_publish_persistence.c
index 4d27b1509..6242e66f8 100644
--- a/src/fs/test_fs_publish_persistence.c
+++ b/src/fs/test_fs_publish_persistence.c
@@ -177,7 +177,7 @@ progress_cb (void *cls,
177 break; 177 break;
178 case GNUNET_FS_STATUS_PUBLISH_ERROR: 178 case GNUNET_FS_STATUS_PUBLISH_ERROR:
179 ret = event->value.publish.cctx; 179 ret = event->value.publish.cctx;
180 FPRINTF (stderr, "Error publishing file: %s\n", 180 fprintf (stderr, "Error publishing file: %s\n",
181 event->value.publish.specifics.error.message); 181 event->value.publish.specifics.error.message);
182 err = 1; 182 err = 1;
183 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); 183 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
diff --git a/src/fs/test_fs_search.c b/src/fs/test_fs_search.c
index 2377cb1a2..2a7f4b1dd 100644
--- a/src/fs/test_fs_search.c
+++ b/src/fs/test_fs_search.c
@@ -140,13 +140,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
140 GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); 140 GNUNET_SCHEDULER_add_now (&abort_search_task, NULL);
141 break; 141 break;
142 case GNUNET_FS_STATUS_PUBLISH_ERROR: 142 case GNUNET_FS_STATUS_PUBLISH_ERROR:
143 FPRINTF (stderr, "Error publishing file: %s\n", 143 fprintf (stderr, "Error publishing file: %s\n",
144 event->value.publish.specifics.error.message); 144 event->value.publish.specifics.error.message);
145 GNUNET_break (0); 145 GNUNET_break (0);
146 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); 146 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
147 break; 147 break;
148 case GNUNET_FS_STATUS_SEARCH_ERROR: 148 case GNUNET_FS_STATUS_SEARCH_ERROR:
149 FPRINTF (stderr, "Error searching file: %s\n", 149 fprintf (stderr, "Error searching file: %s\n",
150 event->value.search.specifics.error.message); 150 event->value.search.specifics.error.message);
151 GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); 151 GNUNET_SCHEDULER_add_now (&abort_search_task, NULL);
152 break; 152 break;
@@ -176,7 +176,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
176 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); 176 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
177 break; 177 break;
178 default: 178 default:
179 FPRINTF (stderr, "Unexpected event: %d\n", event->status); 179 fprintf (stderr, "Unexpected event: %d\n", event->status);
180 break; 180 break;
181 } 181 }
182 return NULL; 182 return NULL;
diff --git a/src/fs/test_fs_search_persistence.c b/src/fs/test_fs_search_persistence.c
index a0483e723..68e3a4a62 100644
--- a/src/fs/test_fs_search_persistence.c
+++ b/src/fs/test_fs_search_persistence.c
@@ -187,13 +187,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
187 GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); 187 GNUNET_SCHEDULER_add_now (&abort_search_task, NULL);
188 break; 188 break;
189 case GNUNET_FS_STATUS_PUBLISH_ERROR: 189 case GNUNET_FS_STATUS_PUBLISH_ERROR:
190 FPRINTF (stderr, "Error publishing file: %s\n", 190 fprintf (stderr, "Error publishing file: %s\n",
191 event->value.publish.specifics.error.message); 191 event->value.publish.specifics.error.message);
192 GNUNET_break (0); 192 GNUNET_break (0);
193 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); 193 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
194 break; 194 break;
195 case GNUNET_FS_STATUS_SEARCH_ERROR: 195 case GNUNET_FS_STATUS_SEARCH_ERROR:
196 FPRINTF (stderr, "Error searching file: %s\n", 196 fprintf (stderr, "Error searching file: %s\n",
197 event->value.search.specifics.error.message); 197 event->value.search.specifics.error.message);
198 GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); 198 GNUNET_SCHEDULER_add_now (&abort_search_task, NULL);
199 break; 199 break;
@@ -237,7 +237,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
237 search = NULL; 237 search = NULL;
238 break; 238 break;
239 default: 239 default:
240 FPRINTF (stderr, "Unexpected event: %d\n", event->status); 240 fprintf (stderr, "Unexpected event: %d\n", event->status);
241 break; 241 break;
242 } 242 }
243 return NULL; 243 return NULL;
diff --git a/src/fs/test_fs_search_probes.c b/src/fs/test_fs_search_probes.c
index ca504c08e..c65649108 100644
--- a/src/fs/test_fs_search_probes.c
+++ b/src/fs/test_fs_search_probes.c
@@ -137,13 +137,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
137 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Search complete.\n"); 137 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Search complete.\n");
138 break; 138 break;
139 case GNUNET_FS_STATUS_PUBLISH_ERROR: 139 case GNUNET_FS_STATUS_PUBLISH_ERROR:
140 FPRINTF (stderr, "Error publishing file: %s\n", 140 fprintf (stderr, "Error publishing file: %s\n",
141 event->value.publish.specifics.error.message); 141 event->value.publish.specifics.error.message);
142 GNUNET_break (0); 142 GNUNET_break (0);
143 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); 143 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
144 break; 144 break;
145 case GNUNET_FS_STATUS_SEARCH_ERROR: 145 case GNUNET_FS_STATUS_SEARCH_ERROR:
146 FPRINTF (stderr, "Error searching file: %s\n", 146 fprintf (stderr, "Error searching file: %s\n",
147 event->value.search.specifics.error.message); 147 event->value.search.specifics.error.message);
148 GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); 148 GNUNET_SCHEDULER_add_now (&abort_search_task, NULL);
149 break; 149 break;
@@ -178,7 +178,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
178 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); 178 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
179 break; 179 break;
180 default: 180 default:
181 FPRINTF (stderr, 181 fprintf (stderr,
182 "Unexpected event: %d\n", 182 "Unexpected event: %d\n",
183 event->status); 183 event->status);
184 break; 184 break;
diff --git a/src/fs/test_fs_search_with_and.c b/src/fs/test_fs_search_with_and.c
index daaf38a19..f1072a4a1 100644
--- a/src/fs/test_fs_search_with_and.c
+++ b/src/fs/test_fs_search_with_and.c
@@ -153,13 +153,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
153 GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); 153 GNUNET_SCHEDULER_add_now (&abort_search_task, NULL);
154 break; 154 break;
155 case GNUNET_FS_STATUS_PUBLISH_ERROR: 155 case GNUNET_FS_STATUS_PUBLISH_ERROR:
156 FPRINTF (stderr, "Error publishing file: %s\n", 156 fprintf (stderr, "Error publishing file: %s\n",
157 event->value.publish.specifics.error.message); 157 event->value.publish.specifics.error.message);
158 GNUNET_break (0); 158 GNUNET_break (0);
159 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); 159 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
160 break; 160 break;
161 case GNUNET_FS_STATUS_SEARCH_ERROR: 161 case GNUNET_FS_STATUS_SEARCH_ERROR:
162 FPRINTF (stderr, "Error searching file: %s\n", 162 fprintf (stderr, "Error searching file: %s\n",
163 event->value.search.specifics.error.message); 163 event->value.search.specifics.error.message);
164 GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); 164 GNUNET_SCHEDULER_add_now (&abort_search_task, NULL);
165 break; 165 break;
@@ -189,7 +189,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
189 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); 189 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
190 break; 190 break;
191 default: 191 default:
192 FPRINTF (stderr, "Unexpected event: %d\n", event->status); 192 fprintf (stderr, "Unexpected event: %d\n", event->status);
193 break; 193 break;
194 } 194 }
195 return NULL; 195 return NULL;
diff --git a/src/fs/test_fs_unindex.c b/src/fs/test_fs_unindex.c
index 9e358dade..b4bdc1b80 100644
--- a/src/fs/test_fs_unindex.c
+++ b/src/fs/test_fs_unindex.c
@@ -121,13 +121,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
121 progress.offset); 121 progress.offset);
122 break; 122 break;
123 case GNUNET_FS_STATUS_PUBLISH_ERROR: 123 case GNUNET_FS_STATUS_PUBLISH_ERROR:
124 FPRINTF (stderr, "Error publishing file: %s\n", 124 fprintf (stderr, "Error publishing file: %s\n",
125 event->value.publish.specifics.error.message); 125 event->value.publish.specifics.error.message);
126 GNUNET_break (0); 126 GNUNET_break (0);
127 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); 127 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
128 break; 128 break;
129 case GNUNET_FS_STATUS_UNINDEX_ERROR: 129 case GNUNET_FS_STATUS_UNINDEX_ERROR:
130 FPRINTF (stderr, "Error unindexing file: %s\n", 130 fprintf (stderr, "Error unindexing file: %s\n",
131 event->value.unindex.specifics.error.message); 131 event->value.unindex.specifics.error.message);
132 GNUNET_SCHEDULER_add_now (&abort_unindex_task, NULL); 132 GNUNET_SCHEDULER_add_now (&abort_unindex_task, NULL);
133 break; 133 break;
diff --git a/src/fs/test_fs_unindex_persistence.c b/src/fs/test_fs_unindex_persistence.c
index 4d6d63c6a..50d45708a 100644
--- a/src/fs/test_fs_unindex_persistence.c
+++ b/src/fs/test_fs_unindex_persistence.c
@@ -183,7 +183,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
183 unindex = event->value.unindex.uc; 183 unindex = event->value.unindex.uc;
184 return "unindex"; 184 return "unindex";
185 case GNUNET_FS_STATUS_PUBLISH_ERROR: 185 case GNUNET_FS_STATUS_PUBLISH_ERROR:
186 FPRINTF (stderr, "Error publishing file: %s\n", 186 fprintf (stderr, "Error publishing file: %s\n",
187 event->value.publish.specifics.error.message); 187 event->value.publish.specifics.error.message);
188 GNUNET_break (0); 188 GNUNET_break (0);
189 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); 189 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
diff --git a/src/fs/test_fs_uri.c b/src/fs/test_fs_uri.c
index d4ee8c302..e0a2ecea7 100644
--- a/src/fs/test_fs_uri.c
+++ b/src/fs/test_fs_uri.c
@@ -314,11 +314,11 @@ main (int argc, char *argv[])
314 failureCount += testLocation (); 314 failureCount += testLocation ();
315 for (i = 0; i < 255; i++) 315 for (i = 0; i < 255; i++)
316 { 316 {
317 /* FPRINTF (stderr, "%s", "."); */ 317 /* fprintf (stderr, "%s", "."); */
318 failureCount += testNamespace (i); 318 failureCount += testNamespace (i);
319 failureCount += testFile (i); 319 failureCount += testFile (i);
320 } 320 }
321 /* FPRINTF (stderr, "%s", "\n"); */ 321 /* fprintf (stderr, "%s", "\n"); */
322 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-uri"); 322 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-uri");
323 if (failureCount != 0) 323 if (failureCount != 0)
324 return 1; 324 return 1;
diff --git a/src/fs/test_gnunet_service_fs_migration.c b/src/fs/test_gnunet_service_fs_migration.c
index 4a3bf67c7..f7daf6b1a 100644
--- a/src/fs/test_gnunet_service_fs_migration.c
+++ b/src/fs/test_gnunet_service_fs_migration.c
@@ -86,7 +86,7 @@ do_stop (void *cls)
86 fancy = 86 fancy =
87 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * 87 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
88 1000000LL / del.rel_value_us); 88 1000000LL / del.rel_value_us);
89 FPRINTF (stdout, 89 fprintf (stdout,
90 "Download speed was %s/s\n", 90 "Download speed was %s/s\n",
91 fancy); 91 fancy);
92 GNUNET_free (fancy); 92 GNUNET_free (fancy);
diff --git a/src/fs/test_gnunet_service_fs_p2p.c b/src/fs/test_gnunet_service_fs_p2p.c
index e33df8502..2050b0835 100644
--- a/src/fs/test_gnunet_service_fs_p2p.c
+++ b/src/fs/test_gnunet_service_fs_p2p.c
@@ -77,7 +77,7 @@ do_stop (void *cls)
77 fancy = 77 fancy =
78 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * 78 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
79 1000000LL / del.rel_value_us); 79 1000000LL / del.rel_value_us);
80 FPRINTF (stdout, 80 fprintf (stdout,
81 "Download speed was %s/s\n", 81 "Download speed was %s/s\n",
82 fancy); 82 fancy);
83 GNUNET_free (fancy); 83 GNUNET_free (fancy);
diff --git a/src/fs/test_plugin_block_fs.c b/src/fs/test_plugin_block_fs.c
index 30981abc5..3b17b6917 100644
--- a/src/fs/test_plugin_block_fs.c
+++ b/src/fs/test_plugin_block_fs.c
@@ -84,7 +84,7 @@ main (int argc, char *argv[])
84 GNUNET_BLOCK_context_destroy (ctx); 84 GNUNET_BLOCK_context_destroy (ctx);
85 GNUNET_CONFIGURATION_destroy (cfg); 85 GNUNET_CONFIGURATION_destroy (cfg);
86 if (ret != 0) 86 if (ret != 0)
87 FPRINTF (stderr, "Tests failed: %d\n", ret); 87 fprintf (stderr, "Tests failed: %d\n", ret);
88 return ret; 88 return ret;
89} 89}
90 90
diff --git a/src/gns/gnunet-bcd.c b/src/gns/gnunet-bcd.c
index f3249eee0..7906ffd4d 100644
--- a/src/gns/gnunet-bcd.c
+++ b/src/gns/gnunet-bcd.c
@@ -179,7 +179,7 @@ access_handler_callback (void *cls,
179 return MHD_NO; 179 return MHD_NO;
180 } 180 }
181 GNUNET_asprintf (&deffile, "%s%s%s", tmp, DIR_SEPARATOR_STR, "def.tex"); 181 GNUNET_asprintf (&deffile, "%s%s%s", tmp, DIR_SEPARATOR_STR, "def.tex");
182 f = FOPEN (deffile, "w"); 182 f = fopen (deffile, "w");
183 if (NULL == f) 183 if (NULL == f)
184 { 184 {
185 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", deffile); 185 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", deffile);
@@ -194,9 +194,9 @@ access_handler_callback (void *cls,
194 MHD_GET_ARGUMENT_KIND, 194 MHD_GET_ARGUMENT_KIND,
195 map[i].formname); 195 map[i].formname);
196 if (NULL != val) 196 if (NULL != val)
197 FPRINTF (f, "\\def\\%s{%s}\n", map[i].texname, val); 197 fprintf (f, "\\def\\%s{%s}\n", map[i].texname, val);
198 else 198 else
199 FPRINTF (f, "\\def\\%s{}\n", map[i].texname); 199 fprintf (f, "\\def\\%s{}\n", map[i].texname);
200 } 200 }
201 if (NULL != gpg_fp) 201 if (NULL != gpg_fp)
202 { 202 {
@@ -206,15 +206,15 @@ access_handler_callback (void *cls,
206 slen = strlen (gpg_fp); 206 slen = strlen (gpg_fp);
207 gpg1 = GNUNET_strndup (gpg_fp, slen / 2); 207 gpg1 = GNUNET_strndup (gpg_fp, slen / 2);
208 gpg2 = GNUNET_strdup (&gpg_fp[slen / 2]); 208 gpg2 = GNUNET_strdup (&gpg_fp[slen / 2]);
209 FPRINTF (f, "\\def\\gpglineone{%s}\n\\def\\gpglinetwo{%s}\n", gpg1, gpg2); 209 fprintf (f, "\\def\\gpglineone{%s}\n\\def\\gpglinetwo{%s}\n", gpg1, gpg2);
210 GNUNET_free (gpg2); 210 GNUNET_free (gpg2);
211 GNUNET_free (gpg1); 211 GNUNET_free (gpg1);
212 } 212 }
213 FPRINTF (f, 213 fprintf (f,
214 "\\def\\gns{%s/%s}\n", 214 "\\def\\gns{%s/%s}\n",
215 gnskey, 215 gnskey,
216 (NULL == gns_nick) ? "" : gns_nick); 216 (NULL == gns_nick) ? "" : gns_nick);
217 FCLOSE (f); 217 fclose (f);
218 GNUNET_asprintf ( 218 GNUNET_asprintf (
219 &p, 219 &p,
220 "cd %s; cp %s gns-bcd.tex | pdflatex --enable-write18 gns-bcd.tex > /dev/null 2> /dev/null", 220 "cd %s; cp %s gns-bcd.tex | pdflatex --enable-write18 gns-bcd.tex > /dev/null 2> /dev/null",
diff --git a/src/gns/gnutls_ca.cfg b/src/gns/gnutls_ca.cfg
new file mode 100644
index 000000000..f551ae8ab
--- /dev/null
+++ b/src/gns/gnutls_ca.cfg
@@ -0,0 +1,25 @@
1# This template file specifies that the certificate is a certificate
2# authority that will be used to sign other certificates, and
3# certificate revocations. Set additional properties (e.g. a CRL URI)
4# as appropriate.
5
6# Certificate authority template
7organization = "Example"
8cn = "Your CA name here"
9expiration_days = 3650
10
11# This CA can not issue subsidiary CAs
12path_len = 0
13
14# Is a CA
15ca
16
17# Signs certificates and certificate revocation lists
18cert_signing_key
19crl_signing_key
20
21# Name constraints (recommended); new in GnuTLS 3.3.x
22# Setting this will allow this CA to only issue
23# certificates for this domain
24nc_permit_dns = "example.com"
25#nc_exclude_dns = "test.example.com"
diff --git a/src/gns/plugin_gnsrecord_gns.c b/src/gns/plugin_gnsrecord_gns.c
index ebba0db47..8cb76cffe 100644
--- a/src/gns/plugin_gnsrecord_gns.c
+++ b/src/gns/plugin_gnsrecord_gns.c
@@ -61,85 +61,68 @@ gns_value_to_string (void *cls,
61 return GNUNET_strndup (data, data_size); 61 return GNUNET_strndup (data, data_size);
62 case GNUNET_GNSRECORD_TYPE_LEHO: 62 case GNUNET_GNSRECORD_TYPE_LEHO:
63 return GNUNET_strndup (data, data_size); 63 return GNUNET_strndup (data, data_size);
64 case GNUNET_GNSRECORD_TYPE_GNS2DNS: 64 case GNUNET_GNSRECORD_TYPE_GNS2DNS: {
65 char *ns;
66 char *ip;
67 size_t off;
68 char *nstr;
69
70 off = 0;
71 ns = GNUNET_DNSPARSER_parse_name (data, data_size, &off);
72 ip = GNUNET_DNSPARSER_parse_name (data, data_size, &off);
73 if ((NULL == ns) || (NULL == ip) || (off != data_size))
65 { 74 {
66 char *ns; 75 GNUNET_break_op (0);
67 char *ip;
68 size_t off;
69 char *nstr;
70
71 off = 0;
72 ns = GNUNET_DNSPARSER_parse_name (data,
73 data_size,
74 &off);
75 ip = GNUNET_DNSPARSER_parse_name (data,
76 data_size,
77 &off);
78 if ( (NULL == ns) ||
79 (NULL == ip) ||
80 (off != data_size) )
81 {
82 GNUNET_break_op (0);
83 GNUNET_free_non_null (ns);
84 GNUNET_free_non_null (ip);
85 return NULL;
86 }
87 GNUNET_asprintf (&nstr,
88 "%s@%s",
89 ns,
90 ip);
91 GNUNET_free_non_null (ns); 76 GNUNET_free_non_null (ns);
92 GNUNET_free_non_null (ip); 77 GNUNET_free_non_null (ip);
93 return nstr; 78 return NULL;
94 }
95 case GNUNET_GNSRECORD_TYPE_VPN:
96 {
97 struct GNUNET_TUN_GnsVpnRecord vpn;
98 char* vpn_str;
99
100 cdata = data;
101 if ( (data_size <= sizeof (vpn)) ||
102 ('\0' != cdata[data_size - 1]) )
103 return NULL; /* malformed */
104 /* need to memcpy for alignment */
105 GNUNET_memcpy (&vpn,
106 data,
107 sizeof (vpn));
108 GNUNET_asprintf (&vpn_str,
109 "%u %s %s",
110 (unsigned int) ntohs (vpn.proto),
111 (const char*) GNUNET_i2s_full (&vpn.peer),
112 (const char*) &cdata[sizeof (vpn)]);
113 return vpn_str;
114 }
115 case GNUNET_GNSRECORD_TYPE_BOX:
116 {
117 struct GNUNET_GNSRECORD_BoxRecord box;
118 uint32_t rt;
119 char *box_str;
120 char *ival;
121
122 cdata = data;
123 if (data_size < sizeof (struct GNUNET_GNSRECORD_BoxRecord))
124 return NULL; /* malformed */
125 GNUNET_memcpy (&box,
126 data,
127 sizeof (box));
128 rt = ntohl (box.record_type);
129 ival = GNUNET_GNSRECORD_value_to_string (rt,
130 &cdata[sizeof (box)],
131 data_size - sizeof (box));
132 if (NULL == ival)
133 return NULL; /* malformed */
134 GNUNET_asprintf (&box_str,
135 "%u %u %u %s",
136 (unsigned int) ntohs (box.protocol),
137 (unsigned int) ntohs (box.service),
138 (unsigned int) rt,
139 ival);
140 GNUNET_free (ival);
141 return box_str;
142 } 79 }
80 GNUNET_asprintf (&nstr, "%s@%s", ns, ip);
81 GNUNET_free_non_null (ns);
82 GNUNET_free_non_null (ip);
83 return nstr;
84 }
85 case GNUNET_GNSRECORD_TYPE_VPN: {
86 struct GNUNET_TUN_GnsVpnRecord vpn;
87 char *vpn_str;
88
89 cdata = data;
90 if ((data_size <= sizeof (vpn)) || ('\0' != cdata[data_size - 1]))
91 return NULL; /* malformed */
92 /* need to memcpy for alignment */
93 GNUNET_memcpy (&vpn, data, sizeof (vpn));
94 GNUNET_asprintf (&vpn_str,
95 "%u %s %s",
96 (unsigned int) ntohs (vpn.proto),
97 (const char *) GNUNET_i2s_full (&vpn.peer),
98 (const char *) &cdata[sizeof (vpn)]);
99 return vpn_str;
100 }
101 case GNUNET_GNSRECORD_TYPE_BOX: {
102 struct GNUNET_GNSRECORD_BoxRecord box;
103 uint32_t rt;
104 char *box_str;
105 char *ival;
106
107 cdata = data;
108 if (data_size < sizeof (struct GNUNET_GNSRECORD_BoxRecord))
109 return NULL; /* malformed */
110 GNUNET_memcpy (&box, data, sizeof (box));
111 rt = ntohl (box.record_type);
112 ival = GNUNET_GNSRECORD_value_to_string (rt,
113 &cdata[sizeof (box)],
114 data_size - sizeof (box));
115 if (NULL == ival)
116 return NULL; /* malformed */
117 GNUNET_asprintf (&box_str,
118 "%u %u %u %s",
119 (unsigned int) ntohs (box.protocol),
120 (unsigned int) ntohs (box.service),
121 (unsigned int) rt,
122 ival);
123 GNUNET_free (ival);
124 return box_str;
125 }
143 default: 126 default:
144 return NULL; 127 return NULL;
145 } 128 }
@@ -171,154 +154,128 @@ gns_string_to_value (void *cls,
171 switch (type) 154 switch (type)
172 { 155 {
173 156
174 case GNUNET_GNSRECORD_TYPE_PKEY: 157 case GNUNET_GNSRECORD_TYPE_PKEY:
175 if (GNUNET_OK != 158 if (GNUNET_OK !=
176 GNUNET_CRYPTO_ecdsa_public_key_from_string (s, 159 GNUNET_CRYPTO_ecdsa_public_key_from_string (s, strlen (s), &pkey))
177 strlen (s), 160 {
178 &pkey)) 161 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
179 { 162 _ ("Unable to parse PKEY record `%s'\n"),
180 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 163 s);
181 _("Unable to parse PKEY record `%s'\n"), 164 return GNUNET_SYSERR;
182 s); 165 }
183 return GNUNET_SYSERR; 166 *data = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
184 } 167 GNUNET_memcpy (*data, &pkey, sizeof (pkey));
185 *data = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); 168 *data_size = sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey);
186 GNUNET_memcpy (*data, 169 return GNUNET_OK;
187 &pkey, 170
188 sizeof (pkey)); 171 case GNUNET_GNSRECORD_TYPE_NICK:
189 *data_size = sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey); 172 *data = GNUNET_strdup (s);
190 return GNUNET_OK; 173 *data_size = strlen (s);
191 174 return GNUNET_OK;
192 case GNUNET_GNSRECORD_TYPE_NICK: 175 case GNUNET_GNSRECORD_TYPE_LEHO:
193 *data = GNUNET_strdup (s); 176 *data = GNUNET_strdup (s);
194 *data_size = strlen (s); 177 *data_size = strlen (s);
195 return GNUNET_OK; 178 return GNUNET_OK;
196 case GNUNET_GNSRECORD_TYPE_LEHO: 179 case GNUNET_GNSRECORD_TYPE_GNS2DNS: {
197 *data = GNUNET_strdup (s); 180 char nsbuf[514];
198 *data_size = strlen (s); 181 char *cpy;
199 return GNUNET_OK; 182 char *at;
200 case GNUNET_GNSRECORD_TYPE_GNS2DNS: 183 size_t off;
201 { 184
202 char nsbuf[514]; 185 cpy = GNUNET_strdup (s);
203 char *cpy; 186 at = strchr (cpy, '@');
204 char *at; 187 if (NULL == at)
205 size_t off; 188 {
206 189 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
207 cpy = GNUNET_strdup (s); 190 _ ("Unable to parse GNS2DNS record `%s'\n"),
208 at = strchr (cpy, '@'); 191 s);
209 if (NULL == at) 192 GNUNET_free (cpy);
210 { 193 return GNUNET_SYSERR;
211 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 194 }
212 _("Unable to parse GNS2DNS record `%s'\n"), 195 *at = '\0';
213 s); 196 at++;
214 GNUNET_free (cpy); 197
215 return GNUNET_SYSERR; 198 off = 0;
216 } 199 if ((GNUNET_OK != GNUNET_DNSPARSER_builder_add_name (nsbuf,
217 *at = '\0'; 200 sizeof (nsbuf),
218 at++; 201 &off,
219 202 cpy)) ||
220 off = 0; 203 (GNUNET_OK !=
221 if ( (GNUNET_OK != 204 GNUNET_DNSPARSER_builder_add_name (nsbuf, sizeof (nsbuf), &off, at)))
222 GNUNET_DNSPARSER_builder_add_name (nsbuf, 205 {
223 sizeof (nsbuf), 206 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
224 &off, 207 _ ("Failed to serialize GNS2DNS record with value `%s'\n"),
225 cpy)) || 208 s);
226 (GNUNET_OK != 209 GNUNET_free (cpy);
227 GNUNET_DNSPARSER_builder_add_name (nsbuf,
228 sizeof (nsbuf),
229 &off,
230 at)) )
231 {
232 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
233 _("Failed to serialize GNS2DNS record with value `%s'\n"),
234 s);
235 GNUNET_free (cpy);
236 return GNUNET_SYSERR;
237 }
238 GNUNET_free (cpy);
239 *data_size = off;
240 *data = GNUNET_malloc (off);
241 GNUNET_memcpy (*data,
242 nsbuf,
243 off);
244 return GNUNET_OK;
245 }
246 case GNUNET_GNSRECORD_TYPE_VPN:
247 {
248 struct GNUNET_TUN_GnsVpnRecord *vpn;
249 char s_peer[103 + 1];
250 char s_serv[253 + 1];
251 unsigned int proto;
252
253 if (3 != SSCANF (s,
254 "%u %103s %253s",
255 &proto, s_peer, s_serv))
256 {
257 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
258 _("Unable to parse VPN record string `%s'\n"),
259 s);
260 return GNUNET_SYSERR;
261 }
262 *data_size = sizeof (struct GNUNET_TUN_GnsVpnRecord) + strlen (s_serv) + 1;
263 *data = vpn = GNUNET_malloc (*data_size);
264 if (GNUNET_OK !=
265 GNUNET_CRYPTO_eddsa_public_key_from_string ((char*) s_peer,
266 strlen (s_peer),
267 &vpn->peer.public_key))
268 {
269 GNUNET_free (vpn);
270 *data_size = 0;
271 return GNUNET_SYSERR;
272 }
273 vpn->proto = htons ((uint16_t) proto);
274 strcpy ((char*)&vpn[1], s_serv);
275 return GNUNET_OK;
276 }
277 case GNUNET_GNSRECORD_TYPE_BOX:
278 {
279 struct GNUNET_GNSRECORD_BoxRecord *box;
280 size_t rest;
281 unsigned int protocol;
282 unsigned int service;
283 unsigned int record_type;
284 void *bval;
285 size_t bval_size;
286
287 if (3 != SSCANF (s,
288 "%u %u %u ",
289 &protocol,
290 &service,
291 &record_type))
292 {
293 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
294 _("Unable to parse BOX record string `%s'\n"),
295 s);
296 return GNUNET_SYSERR;
297 }
298 rest = snprintf (NULL, 0,
299 "%u %u %u ",
300 protocol,
301 service,
302 record_type);
303 if (GNUNET_OK !=
304 GNUNET_GNSRECORD_string_to_value (record_type,
305 &s[rest],
306 &bval,
307 &bval_size))
308 return GNUNET_SYSERR;
309 *data_size = sizeof (struct GNUNET_GNSRECORD_BoxRecord) + bval_size;
310 *data = box = GNUNET_malloc (*data_size);
311 box->protocol = htons (protocol);
312 box->service = htons (service);
313 box->record_type = htonl (record_type);
314 GNUNET_memcpy (&box[1],
315 bval,
316 bval_size);
317 GNUNET_free (bval);
318 return GNUNET_OK;
319 }
320 default:
321 return GNUNET_SYSERR; 210 return GNUNET_SYSERR;
211 }
212 GNUNET_free (cpy);
213 *data_size = off;
214 *data = GNUNET_malloc (off);
215 GNUNET_memcpy (*data, nsbuf, off);
216 return GNUNET_OK;
217 }
218 case GNUNET_GNSRECORD_TYPE_VPN: {
219 struct GNUNET_TUN_GnsVpnRecord *vpn;
220 char s_peer[103 + 1];
221 char s_serv[253 + 1];
222 unsigned int proto;
223
224 if (3 != sscanf (s, "%u %103s %253s", &proto, s_peer, s_serv))
225 {
226 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
227 _ ("Unable to parse VPN record string `%s'\n"),
228 s);
229 return GNUNET_SYSERR;
230 }
231 *data_size = sizeof (struct GNUNET_TUN_GnsVpnRecord) + strlen (s_serv) + 1;
232 *data = vpn = GNUNET_malloc (*data_size);
233 if (GNUNET_OK !=
234 GNUNET_CRYPTO_eddsa_public_key_from_string ((char *) s_peer,
235 strlen (s_peer),
236 &vpn->peer.public_key))
237 {
238 GNUNET_free (vpn);
239 *data_size = 0;
240 return GNUNET_SYSERR;
241 }
242 vpn->proto = htons ((uint16_t) proto);
243 strcpy ((char *) &vpn[1], s_serv);
244 return GNUNET_OK;
245 }
246 case GNUNET_GNSRECORD_TYPE_BOX: {
247 struct GNUNET_GNSRECORD_BoxRecord *box;
248 size_t rest;
249 unsigned int protocol;
250 unsigned int service;
251 unsigned int record_type;
252 void *bval;
253 size_t bval_size;
254
255 if (3 != sscanf (s, "%u %u %u ", &protocol, &service, &record_type))
256 {
257 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
258 _ ("Unable to parse BOX record string `%s'\n"),
259 s);
260 return GNUNET_SYSERR;
261 }
262 rest = snprintf (NULL, 0, "%u %u %u ", protocol, service, record_type);
263 if (GNUNET_OK != GNUNET_GNSRECORD_string_to_value (record_type,
264 &s[rest],
265 &bval,
266 &bval_size))
267 return GNUNET_SYSERR;
268 *data_size = sizeof (struct GNUNET_GNSRECORD_BoxRecord) + bval_size;
269 *data = box = GNUNET_malloc (*data_size);
270 box->protocol = htons (protocol);
271 box->service = htons (service);
272 box->record_type = htonl (record_type);
273 GNUNET_memcpy (&box[1], bval, bval_size);
274 GNUNET_free (bval);
275 return GNUNET_OK;
276 }
277 default:
278 return GNUNET_SYSERR;
322 } 279 }
323} 280}
324 281
@@ -327,18 +284,17 @@ gns_string_to_value (void *cls,
327 * Mapping of record type numbers to human-readable 284 * Mapping of record type numbers to human-readable
328 * record type names. 285 * record type names.
329 */ 286 */
330static struct { 287static struct
288{
331 const char *name; 289 const char *name;
332 uint32_t number; 290 uint32_t number;
333} gns_name_map[] = { 291} gns_name_map[] = {{"PKEY", GNUNET_GNSRECORD_TYPE_PKEY},
334 { "PKEY", GNUNET_GNSRECORD_TYPE_PKEY }, 292 {"NICK", GNUNET_GNSRECORD_TYPE_NICK},
335 { "NICK", GNUNET_GNSRECORD_TYPE_NICK }, 293 {"LEHO", GNUNET_GNSRECORD_TYPE_LEHO},
336 { "LEHO", GNUNET_GNSRECORD_TYPE_LEHO }, 294 {"VPN", GNUNET_GNSRECORD_TYPE_VPN},
337 { "VPN", GNUNET_GNSRECORD_TYPE_VPN }, 295 {"GNS2DNS", GNUNET_GNSRECORD_TYPE_GNS2DNS},
338 { "GNS2DNS", GNUNET_GNSRECORD_TYPE_GNS2DNS }, 296 {"BOX", GNUNET_GNSRECORD_TYPE_BOX},
339 { "BOX", GNUNET_GNSRECORD_TYPE_BOX }, 297 {NULL, UINT32_MAX}};
340 { NULL, UINT32_MAX }
341};
342 298
343 299
344/** 300/**
@@ -349,15 +305,13 @@ static struct {
349 * @return corresponding number, UINT32_MAX on error 305 * @return corresponding number, UINT32_MAX on error
350 */ 306 */
351static uint32_t 307static uint32_t
352gns_typename_to_number (void *cls, 308gns_typename_to_number (void *cls, const char *gns_typename)
353 const char *gns_typename)
354{ 309{
355 unsigned int i; 310 unsigned int i;
356 311
357 i=0; 312 i = 0;
358 while ( (NULL != gns_name_map[i].name) && 313 while ((NULL != gns_name_map[i].name) &&
359 (0 != strcasecmp (gns_typename, 314 (0 != strcasecmp (gns_typename, gns_name_map[i].name)))
360 gns_name_map[i].name)) )
361 i++; 315 i++;
362 return gns_name_map[i].number; 316 return gns_name_map[i].number;
363} 317}
@@ -371,14 +325,12 @@ gns_typename_to_number (void *cls,
371 * @return corresponding typestring, NULL on error 325 * @return corresponding typestring, NULL on error
372 */ 326 */
373static const char * 327static const char *
374gns_number_to_typename (void *cls, 328gns_number_to_typename (void *cls, uint32_t type)
375 uint32_t type)
376{ 329{
377 unsigned int i; 330 unsigned int i;
378 331
379 i=0; 332 i = 0;
380 while ( (NULL != gns_name_map[i].name) && 333 while ((NULL != gns_name_map[i].name) && (type != gns_name_map[i].number))
381 (type != gns_name_map[i].number) )
382 i++; 334 i++;
383 return gns_name_map[i].name; 335 return gns_name_map[i].name;
384} 336}
diff --git a/src/gnsrecord/plugin_gnsrecord_dns.c b/src/gnsrecord/plugin_gnsrecord_dns.c
index 636a73403..3f62d3d77 100644
--- a/src/gnsrecord/plugin_gnsrecord_dns.c
+++ b/src/gnsrecord/plugin_gnsrecord_dns.c
@@ -415,13 +415,13 @@ dns_string_to_value (void *cls,
415 typep = strtok (sdup, " "); 415 typep = strtok (sdup, " ");
416 if ((NULL == typep) || 416 if ((NULL == typep) ||
417 ((0 == (type = rfc4398_mnemonic_to_value (typep))) && 417 ((0 == (type = rfc4398_mnemonic_to_value (typep))) &&
418 ((1 != SSCANF (typep, "%u", &type)) || (type > UINT16_MAX)))) 418 ((1 != sscanf (typep, "%u", &type)) || (type > UINT16_MAX))))
419 { 419 {
420 GNUNET_free (sdup); 420 GNUNET_free (sdup);
421 return GNUNET_SYSERR; 421 return GNUNET_SYSERR;
422 } 422 }
423 keyp = strtok (NULL, " "); 423 keyp = strtok (NULL, " ");
424 if ((NULL == keyp) || (1 != SSCANF (keyp, "%u", &key)) || 424 if ((NULL == keyp) || (1 != sscanf (keyp, "%u", &key)) ||
425 (key > UINT16_MAX)) 425 (key > UINT16_MAX))
426 { 426 {
427 GNUNET_free (sdup); 427 GNUNET_free (sdup);
@@ -486,7 +486,7 @@ dns_string_to_value (void *cls,
486 unsigned int soa_min; 486 unsigned int soa_min;
487 size_t off; 487 size_t off;
488 488
489 if (7 != SSCANF (s, 489 if (7 != sscanf (s,
490 "rname=%253s mname=%253s %u,%u,%u,%u,%u", 490 "rname=%253s mname=%253s %u,%u,%u,%u,%u",
491 soa_rname, 491 soa_rname,
492 soa_mname, 492 soa_mname,
@@ -549,7 +549,7 @@ dns_string_to_value (void *cls,
549 unsigned int mx_pref; 549 unsigned int mx_pref;
550 size_t off; 550 size_t off;
551 551
552 if (2 != SSCANF (s, "%u,%253s", &mx_pref, mxhost)) 552 if (2 != sscanf (s, "%u,%253s", &mx_pref, mxhost))
553 { 553 {
554 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 554 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
555 _ ("Unable to parse MX record `%s'\n"), 555 _ ("Unable to parse MX record `%s'\n"),
@@ -582,7 +582,7 @@ dns_string_to_value (void *cls,
582 unsigned int port; 582 unsigned int port;
583 size_t off; 583 size_t off;
584 584
585 if (4 != SSCANF (s, "%u %u %u %253s", &priority, &weight, &port, srvtarget)) 585 if (4 != sscanf (s, "%u %u %u %253s", &priority, &weight, &port, srvtarget))
586 { 586 {
587 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 587 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
588 _ ("Unable to parse SRV record `%s'\n"), 588 _ ("Unable to parse SRV record `%s'\n"),
@@ -630,7 +630,7 @@ dns_string_to_value (void *cls,
630 size_t slen = strlen (s) + 1; 630 size_t slen = strlen (s) + 1;
631 char hex[slen]; 631 char hex[slen];
632 632
633 if (4 != SSCANF (s, "%u %u %u %s", &usage, &selector, &matching_type, hex)) 633 if (4 != sscanf (s, "%u %u %u %s", &usage, &selector, &matching_type, hex))
634 { 634 {
635 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 635 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
636 _ ("Unable to parse TLSA record string `%s'\n"), 636 _ ("Unable to parse TLSA record string `%s'\n"),
@@ -662,7 +662,7 @@ dns_string_to_value (void *cls,
662 char tag[15]; //Max tag length 15 662 char tag[15]; //Max tag length 15
663 char value[strlen (s) + 1]; //Should be more than enough 663 char value[strlen (s) + 1]; //Should be more than enough
664 664
665 if (3 != SSCANF (s, "%u %s %[^\n]", &flags, tag, value)) 665 if (3 != sscanf (s, "%u %s %[^\n]", &flags, tag, value))
666 { 666 {
667 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 667 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
668 _ ("Unable to parse CAA record string `%s'\n"), 668 _ ("Unable to parse CAA record string `%s'\n"),
diff --git a/src/hello/gnunet-hello.c b/src/hello/gnunet-hello.c
index 0b176ac79..612b5110a 100644
--- a/src/hello/gnunet-hello.c
+++ b/src/hello/gnunet-hello.c
@@ -67,13 +67,13 @@ add_to_buf (void *cls,
67 size_t ret; 67 size_t ret;
68 68
69 ret = GNUNET_HELLO_add_address (address, 69 ret = GNUNET_HELLO_add_address (address,
70 GNUNET_TIME_UNIT_FOREVER_ABS, 70 GNUNET_TIME_UNIT_FOREVER_ABS,
71 ac->buf, 71 ac->buf,
72 ac->max); 72 ac->max);
73 ac->buf += ret; 73 ac->buf += ret;
74 ac->max -= ret; 74 ac->max -= ret;
75 ac->ret += ret; 75 ac->ret += ret;
76 address_count ++; 76 address_count++;
77 return GNUNET_OK; 77 return GNUNET_OK;
78} 78}
79 79
@@ -87,9 +87,7 @@ add_to_buf (void *cls,
87 * @return number of bytes added, 0 to terminate 87 * @return number of bytes added, 0 to terminate
88 */ 88 */
89static ssize_t 89static ssize_t
90add_from_hello (void *cls, 90add_from_hello (void *cls, size_t max, void *buf)
91 size_t max,
92 void *buf)
93{ 91{
94 struct GNUNET_HELLO_Message **orig = cls; 92 struct GNUNET_HELLO_Message **orig = cls;
95 struct AddContext ac; 93 struct AddContext ac;
@@ -99,10 +97,9 @@ add_from_hello (void *cls,
99 ac.buf = buf; 97 ac.buf = buf;
100 ac.max = max; 98 ac.max = max;
101 ac.ret = 0; 99 ac.ret = 0;
102 GNUNET_assert (NULL == 100 GNUNET_assert (
103 GNUNET_HELLO_iterate_addresses (*orig, 101 NULL ==
104 GNUNET_NO, &add_to_buf, 102 GNUNET_HELLO_iterate_addresses (*orig, GNUNET_NO, &add_to_buf, &ac));
105 &ac));
106 *orig = NULL; 103 *orig = NULL;
107 return ac.ret; 104 return ac.ret;
108} 105}
@@ -121,67 +118,58 @@ main (int argc, char *argv[])
121 GNUNET_log_setup ("gnunet-hello", "INFO", NULL); 118 GNUNET_log_setup ("gnunet-hello", "INFO", NULL);
122 if (argc != 2) 119 if (argc != 2)
123 { 120 {
124 FPRINTF (stderr, 121 fprintf (stderr, "%s", _ ("Call with name of HELLO file to modify.\n"));
125 "%s",
126 _("Call with name of HELLO file to modify.\n"));
127 return 1; 122 return 1;
128 } 123 }
129 if (GNUNET_OK != GNUNET_DISK_file_size (argv[1], &fsize, GNUNET_YES, GNUNET_YES)) 124 if (GNUNET_OK !=
125 GNUNET_DISK_file_size (argv[1], &fsize, GNUNET_YES, GNUNET_YES))
130 { 126 {
131 FPRINTF (stderr, 127 fprintf (stderr,
132 _("Error accessing file `%s': %s\n"), 128 _ ("Error accessing file `%s': %s\n"),
133 argv[1], 129 argv[1],
134 STRERROR (errno)); 130 strerror (errno));
135 return 1; 131 return 1;
136 } 132 }
137 if (fsize > 65536) 133 if (fsize > 65536)
138 { 134 {
139 FPRINTF (stderr, 135 fprintf (stderr, _ ("File `%s' is too big to be a HELLO\n"), argv[1]);
140 _("File `%s' is too big to be a HELLO\n"),
141 argv[1]);
142 return 1; 136 return 1;
143 } 137 }
144 if (fsize < sizeof (struct GNUNET_MessageHeader)) 138 if (fsize < sizeof (struct GNUNET_MessageHeader))
145 { 139 {
146 FPRINTF (stderr, 140 fprintf (stderr, _ ("File `%s' is too small to be a HELLO\n"), argv[1]);
147 _("File `%s' is too small to be a HELLO\n"),
148 argv[1]);
149 return 1; 141 return 1;
150 } 142 }
151 fh = GNUNET_DISK_file_open (argv[1], 143 fh = GNUNET_DISK_file_open (argv[1],
152 GNUNET_DISK_OPEN_READ, 144 GNUNET_DISK_OPEN_READ,
153 GNUNET_DISK_PERM_USER_READ); 145 GNUNET_DISK_PERM_USER_READ);
154 if (NULL == fh) 146 if (NULL == fh)
155 { 147 {
156 FPRINTF (stderr, 148 fprintf (stderr,
157 _("Error opening file `%s': %s\n"), 149 _ ("Error opening file `%s': %s\n"),
158 argv[1], 150 argv[1],
159 STRERROR (errno)); 151 strerror (errno));
160 return 1; 152 return 1;
161 } 153 }
162 { 154 {
163 char buf[fsize] GNUNET_ALIGN; 155 char buf[fsize] GNUNET_ALIGN;
164 156
165 GNUNET_assert (fsize == 157 GNUNET_assert (fsize == GNUNET_DISK_file_read (fh, buf, fsize));
166 GNUNET_DISK_file_read (fh, buf, fsize));
167 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); 158 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
168 orig = (struct GNUNET_HELLO_Message *) buf; 159 orig = (struct GNUNET_HELLO_Message *) buf;
169 if ( (fsize < GNUNET_HELLO_size (orig)) || 160 if ((fsize < GNUNET_HELLO_size (orig)) ||
170 (GNUNET_OK != GNUNET_HELLO_get_id (orig, 161 (GNUNET_OK != GNUNET_HELLO_get_id (orig, &pid)))
171 &pid)) )
172 { 162 {
173 FPRINTF (stderr, 163 fprintf (stderr,
174 _("Did not find well-formed HELLO in file `%s'\n"), 164 _ ("Did not find well-formed HELLO in file `%s'\n"),
175 argv[1]); 165 argv[1]);
176 return 1; 166 return 1;
177 } 167 }
178 { 168 {
179 char *pids; 169 char *pids;
180 170
181 pids = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid.public_key); 171 pids = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid.public_key);
182 fprintf (stdout, 172 fprintf (stdout, "Processing HELLO for peer `%s'\n", pids);
183 "Processing HELLO for peer `%s'\n",
184 pids);
185 GNUNET_free (pids); 173 GNUNET_free (pids);
186 } 174 }
187 result = GNUNET_HELLO_create (&pid.public_key, 175 result = GNUNET_HELLO_create (&pid.public_key,
@@ -189,34 +177,34 @@ main (int argc, char *argv[])
189 &orig, 177 &orig,
190 GNUNET_HELLO_is_friend_only (orig)); 178 GNUNET_HELLO_is_friend_only (orig));
191 GNUNET_assert (NULL != result); 179 GNUNET_assert (NULL != result);
192 fh = GNUNET_DISK_file_open (argv[1], 180 fh =
193 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE, 181 GNUNET_DISK_file_open (argv[1],
194 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); 182 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE,
195 if (NULL == fh) 183 GNUNET_DISK_PERM_USER_READ |
196 { 184 GNUNET_DISK_PERM_USER_WRITE);
197 FPRINTF (stderr, 185 if (NULL == fh)
198 _("Error opening file `%s': %s\n"), 186 {
199 argv[1], 187 fprintf (stderr,
200 STRERROR (errno)); 188 _ ("Error opening file `%s': %s\n"),
201 GNUNET_free (result); 189 argv[1],
202 return 1; 190 strerror (errno));
203 } 191 GNUNET_free (result);
204 fsize = GNUNET_HELLO_size (result); 192 return 1;
205 if (fsize != GNUNET_DISK_file_write (fh, 193 }
206 result, 194 fsize = GNUNET_HELLO_size (result);
207 fsize)) 195 if (fsize != GNUNET_DISK_file_write (fh, result, fsize))
208 { 196 {
209 FPRINTF (stderr, 197 fprintf (stderr,
210 _("Error writing HELLO to file `%s': %s\n"), 198 _ ("Error writing HELLO to file `%s': %s\n"),
211 argv[1], 199 argv[1],
212 STRERROR (errno)); 200 strerror (errno));
213 (void) GNUNET_DISK_file_close (fh); 201 (void) GNUNET_DISK_file_close (fh);
214 return 1; 202 return 1;
215 } 203 }
216 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); 204 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
217 } 205 }
218 FPRINTF (stderr, 206 fprintf (stderr,
219 _("Modified %u addresses, wrote %u bytes\n"), 207 _ ("Modified %u addresses, wrote %u bytes\n"),
220 address_count, 208 address_count,
221 (unsigned int) fsize); 209 (unsigned int) fsize);
222 return 0; 210 return 0;
diff --git a/src/hostlist/hostlists_learn_peer2.file b/src/hostlist/hostlists_learn_peer2.file
index 79df4dfe8..19d031c3e 100644
--- a/src/hostlist/hostlists_learn_peer2.file
+++ b/src/hostlist/hostlists_learn_peer2.file
Binary files differ
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_learning.c b/src/hostlist/test_gnunet_daemon_hostlist_learning.c
index f92215679..a18255e6d 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist_learning.c
+++ b/src/hostlist/test_gnunet_daemon_hostlist_learning.c
@@ -424,7 +424,7 @@ setup_learn_peer (struct PeerContext *p,
424 { 424 {
425 if (GNUNET_YES == GNUNET_DISK_file_test (filename)) 425 if (GNUNET_YES == GNUNET_DISK_file_test (filename))
426 { 426 {
427 result = UNLINK (filename); 427 result = unlink (filename);
428 if (result == 0) 428 if (result == 0)
429 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 429 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
430 _("Hostlist file `%s' was removed\n"), 430 _("Hostlist file `%s' was removed\n"),
@@ -577,7 +577,7 @@ main (int argc, char *argv[])
577 if (GNUNET_YES == 577 if (GNUNET_YES ==
578 GNUNET_DISK_file_test ("hostlists_learn_peer.file")) 578 GNUNET_DISK_file_test ("hostlists_learn_peer.file"))
579 { 579 {
580 if (0 == UNLINK ("hostlists_learn_peer.file")) 580 if (0 == unlink ("hostlists_learn_peer.file"))
581 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 581 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
582 "Hostlist file hostlists_learn_peer.file was removed\n"); 582 "Hostlist file hostlists_learn_peer.file was removed\n");
583 } 583 }
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
index 28b2db0de..6aaa7ae2e 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
+++ b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
@@ -237,7 +237,7 @@ main (int argcx, char *argvx[])
237 &ok); 237 &ok);
238 if (0 == ok) 238 if (0 == ok)
239 { 239 {
240 FPRINTF (stderr, "%s", "."); 240 fprintf (stderr, "%s", ".");
241 /* now do it again */ 241 /* now do it again */
242 ok = 1; 242 ok = 1;
243 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 243 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
@@ -247,7 +247,7 @@ main (int argcx, char *argvx[])
247 options, 247 options,
248 &run, 248 &run,
249 &ok); 249 &ok);
250 FPRINTF (stderr, "%s", ".\n"); 250 fprintf (stderr, "%s", ".\n");
251 } 251 }
252 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf", 252 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf",
253 "GNUNET_TEST_HOME"); 253 "GNUNET_TEST_HOME");
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c
index 3e92a04cd..34fad3272 100644
--- a/src/identity/gnunet-service-identity.c
+++ b/src/identity/gnunet-service-identity.c
@@ -64,7 +64,6 @@ struct Ego
64 * String identifier for the ego. 64 * String identifier for the ego.
65 */ 65 */
66 char *identifier; 66 char *identifier;
67
68}; 67};
69 68
70 69
@@ -122,10 +121,10 @@ get_ego_filename (struct Ego *ego)
122 char *filename; 121 char *filename;
123 122
124 GNUNET_asprintf (&filename, 123 GNUNET_asprintf (&filename,
125 "%s%s%s", 124 "%s%s%s",
126 ego_directory, 125 ego_directory,
127 DIR_SEPARATOR_STR, 126 DIR_SEPARATOR_STR,
128 ego->identifier); 127 ego->identifier);
129 return filename; 128 return filename;
130} 129}
131 130
@@ -141,9 +140,7 @@ client_disconnect_cb (void *cls,
141 struct GNUNET_SERVICE_Client *client, 140 struct GNUNET_SERVICE_Client *client,
142 void *app_ctx) 141 void *app_ctx)
143{ 142{
144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client);
145 "Client %p disconnected\n",
146 client);
147} 144}
148 145
149 146
@@ -208,8 +205,8 @@ shutdown_task (void *cls)
208 */ 205 */
209static void 206static void
210send_result_code (struct GNUNET_SERVICE_Client *client, 207send_result_code (struct GNUNET_SERVICE_Client *client,
211 uint32_t result_code, 208 uint32_t result_code,
212 const char *emsg) 209 const char *emsg)
213{ 210{
214 struct ResultCodeMessage *rcm; 211 struct ResultCodeMessage *rcm;
215 struct GNUNET_MQ_Envelope *env; 212 struct GNUNET_MQ_Envelope *env;
@@ -219,9 +216,8 @@ send_result_code (struct GNUNET_SERVICE_Client *client,
219 elen = 0; 216 elen = 0;
220 else 217 else
221 elen = strlen (emsg) + 1; 218 elen = strlen (emsg) + 1;
222 env = GNUNET_MQ_msg_extra (rcm, 219 env =
223 elen, 220 GNUNET_MQ_msg_extra (rcm, elen, GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE);
224 GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE);
225 rcm->result_code = htonl (result_code); 221 rcm->result_code = htonl (result_code);
226 if (0 < elen) 222 if (0 < elen)
227 GNUNET_memcpy (&rcm[1], emsg, elen); 223 GNUNET_memcpy (&rcm[1], emsg, elen);
@@ -247,9 +243,7 @@ create_update_message (struct Ego *ego)
247 size_t name_len; 243 size_t name_len;
248 244
249 name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1); 245 name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1);
250 env = GNUNET_MQ_msg_extra (um, 246 env = GNUNET_MQ_msg_extra (um, name_len, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
251 name_len,
252 GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
253 um->name_len = htons (name_len); 247 um->name_len = htons (name_len);
254 um->end_of_list = htons (GNUNET_NO); 248 um->end_of_list = htons (GNUNET_NO);
255 um->private_key = *ego->pk; 249 um->private_key = *ego->pk;
@@ -266,8 +260,7 @@ create_update_message (struct Ego *ego)
266 * @return corresponding set default message 260 * @return corresponding set default message
267 */ 261 */
268static struct GNUNET_MQ_Envelope * 262static struct GNUNET_MQ_Envelope *
269create_set_default_message (struct Ego *ego, 263create_set_default_message (struct Ego *ego, const char *servicename)
270 const char *servicename)
271{ 264{
272 struct SetDefaultMessage *sdm; 265 struct SetDefaultMessage *sdm;
273 struct GNUNET_MQ_Envelope *env; 266 struct GNUNET_MQ_Envelope *env;
@@ -295,31 +288,26 @@ create_set_default_message (struct Ego *ego,
295 * @param message the message received 288 * @param message the message received
296 */ 289 */
297static void 290static void
298handle_start_message (void *cls, 291handle_start_message (void *cls, const struct GNUNET_MessageHeader *message)
299 const struct GNUNET_MessageHeader *message)
300{ 292{
301 struct GNUNET_SERVICE_Client *client = cls; 293 struct GNUNET_SERVICE_Client *client = cls;
302 struct UpdateMessage *ume; 294 struct UpdateMessage *ume;
303 struct GNUNET_MQ_Envelope *env; 295 struct GNUNET_MQ_Envelope *env;
304 struct Ego *ego; 296 struct Ego *ego;
305 297
306 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n");
307 "Received START message from client\n");
308 GNUNET_SERVICE_client_mark_monitor (client); 299 GNUNET_SERVICE_client_mark_monitor (client);
309 GNUNET_SERVICE_client_disable_continue_warning (client); 300 GNUNET_SERVICE_client_disable_continue_warning (client);
310 GNUNET_notification_context_add (nc, 301 GNUNET_notification_context_add (nc, GNUNET_SERVICE_client_get_mq (client));
311 GNUNET_SERVICE_client_get_mq(client));
312 for (ego = ego_head; NULL != ego; ego = ego->next) 302 for (ego = ego_head; NULL != ego; ego = ego->next)
313 { 303 {
314 env = create_update_message (ego); 304 env = create_update_message (ego);
315 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq(client), env); 305 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
316 } 306 }
317 env = GNUNET_MQ_msg_extra (ume, 307 env = GNUNET_MQ_msg_extra (ume, 0, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
318 0,
319 GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
320 ume->end_of_list = htons (GNUNET_YES); 308 ume->end_of_list = htons (GNUNET_YES);
321 ume->name_len = htons (0); 309 ume->name_len = htons (0);
322 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq(client), env); 310 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
323 GNUNET_SERVICE_client_continue (client); 311 GNUNET_SERVICE_client_continue (client);
324} 312}
325 313
@@ -333,8 +321,7 @@ handle_start_message (void *cls,
333 * @return #GNUNET_SYSERR if message was ill-formed 321 * @return #GNUNET_SYSERR if message was ill-formed
334 */ 322 */
335static int 323static int
336check_lookup_message (void *cls, 324check_lookup_message (void *cls, const struct LookupMessage *message)
337 const struct LookupMessage *message)
338{ 325{
339 GNUNET_MQ_check_zero_termination (message); 326 GNUNET_MQ_check_zero_termination (message);
340 return GNUNET_OK; 327 return GNUNET_OK;
@@ -349,30 +336,25 @@ check_lookup_message (void *cls,
349 * @param message the message received 336 * @param message the message received
350 */ 337 */
351static void 338static void
352handle_lookup_message (void *cls, 339handle_lookup_message (void *cls, const struct LookupMessage *message)
353 const struct LookupMessage *message)
354{ 340{
355 struct GNUNET_SERVICE_Client *client = cls; 341 struct GNUNET_SERVICE_Client *client = cls;
356 const char *name; 342 const char *name;
357 struct GNUNET_MQ_Envelope *env; 343 struct GNUNET_MQ_Envelope *env;
358 struct Ego *ego; 344 struct Ego *ego;
359 345
360 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 346 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received LOOKUP message from client\n");
361 "Received LOOKUP message from client\n");
362 name = (const char *) &message[1]; 347 name = (const char *) &message[1];
363 for (ego = ego_head; NULL != ego; ego = ego->next) 348 for (ego = ego_head; NULL != ego; ego = ego->next)
364 { 349 {
365 if (0 != strcasecmp (name, 350 if (0 != strcasecmp (name, ego->identifier))
366 ego->identifier))
367 continue; 351 continue;
368 env = create_update_message (ego); 352 env = create_update_message (ego);
369 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); 353 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
370 GNUNET_SERVICE_client_continue (client); 354 GNUNET_SERVICE_client_continue (client);
371 return; 355 return;
372 } 356 }
373 send_result_code (client, 357 send_result_code (client, 0, "ego not found");
374 0,
375 "ego not found");
376 GNUNET_SERVICE_client_continue (client); 358 GNUNET_SERVICE_client_continue (client);
377} 359}
378 360
@@ -386,8 +368,7 @@ handle_lookup_message (void *cls,
386 * @return #GNUNET_SYSERR if message was ill-formed 368 * @return #GNUNET_SYSERR if message was ill-formed
387 */ 369 */
388static int 370static int
389check_lookup_by_suffix_message (void *cls, 371check_lookup_by_suffix_message (void *cls, const struct LookupMessage *message)
390 const struct LookupMessage *message)
391{ 372{
392 GNUNET_MQ_check_zero_termination (message); 373 GNUNET_MQ_check_zero_termination (message);
393 return GNUNET_OK; 374 return GNUNET_OK;
@@ -402,8 +383,7 @@ check_lookup_by_suffix_message (void *cls,
402 * @param message the message received 383 * @param message the message received
403 */ 384 */
404static void 385static void
405handle_lookup_by_suffix_message (void *cls, 386handle_lookup_by_suffix_message (void *cls, const struct LookupMessage *message)
406 const struct LookupMessage *message)
407{ 387{
408 struct GNUNET_SERVICE_Client *client = cls; 388 struct GNUNET_SERVICE_Client *client = cls;
409 const char *name; 389 const char *name;
@@ -419,10 +399,9 @@ handle_lookup_by_suffix_message (void *cls,
419 399
420 if ((strlen (ego->identifier) <= strlen (name)) && 400 if ((strlen (ego->identifier) <= strlen (name)) &&
421 (0 == strcmp (ego->identifier, 401 (0 == strcmp (ego->identifier,
422 &name[strlen (name) - strlen (ego->identifier)])) && 402 &name[strlen (name) - strlen (ego->identifier)])) &&
423 ((strlen (name) == strlen (ego->identifier)) || 403 ((strlen (name) == strlen (ego->identifier)) ||
424 ('.' == name[strlen (name) - 404 ('.' == name[strlen (name) - strlen (ego->identifier) - 1])) &&
425 strlen (ego->identifier) - 1])) &&
426 ((NULL == lprefix) || 405 ((NULL == lprefix) ||
427 (strlen (ego->identifier) > strlen (lprefix->identifier)))) 406 (strlen (ego->identifier) > strlen (lprefix->identifier))))
428 { 407 {
@@ -437,9 +416,7 @@ handle_lookup_by_suffix_message (void *cls,
437 GNUNET_SERVICE_client_continue (client); 416 GNUNET_SERVICE_client_continue (client);
438 return; 417 return;
439 } 418 }
440 send_result_code (client, 419 send_result_code (client, 0, "ego not found");
441 0,
442 "ego not found");
443 GNUNET_SERVICE_client_continue (client); 420 GNUNET_SERVICE_client_continue (client);
444} 421}
445 422
@@ -452,8 +429,7 @@ handle_lookup_by_suffix_message (void *cls,
452 * @return #GNUNET_OK if @a msg is well-formed 429 * @return #GNUNET_OK if @a msg is well-formed
453 */ 430 */
454static int 431static int
455check_get_default_message (void *cls, 432check_get_default_message (void *cls, const struct GetDefaultMessage *msg)
456 const struct GetDefaultMessage *msg)
457{ 433{
458 uint16_t size; 434 uint16_t size;
459 uint16_t name_len; 435 uint16_t name_len;
@@ -467,9 +443,8 @@ check_get_default_message (void *cls,
467 } 443 }
468 name = (const char *) &msg[1]; 444 name = (const char *) &msg[1];
469 name_len = ntohs (msg->name_len); 445 name_len = ntohs (msg->name_len);
470 if ( (name_len + sizeof (struct GetDefaultMessage) != size) || 446 if ((name_len + sizeof (struct GetDefaultMessage) != size) ||
471 (0 != ntohs (msg->reserved)) || 447 (0 != ntohs (msg->reserved)) || ('\0' != name[name_len - 1]))
472 ('\0' != name[name_len - 1]) )
473 { 448 {
474 GNUNET_break (0); 449 GNUNET_break (0);
475 return GNUNET_SYSERR; 450 return GNUNET_SYSERR;
@@ -487,8 +462,7 @@ check_get_default_message (void *cls,
487 * @param message the message received 462 * @param message the message received
488 */ 463 */
489static void 464static void
490handle_get_default_message (void *cls, 465handle_get_default_message (void *cls, const struct GetDefaultMessage *gdm)
491 const struct GetDefaultMessage *gdm)
492{ 466{
493 struct GNUNET_MQ_Envelope *env; 467 struct GNUNET_MQ_Envelope *env;
494 struct GNUNET_SERVICE_Client *client = cls; 468 struct GNUNET_SERVICE_Client *client = cls;
@@ -502,11 +476,10 @@ handle_get_default_message (void *cls,
502 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 476 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
503 "Received GET_DEFAULT for service `%s' from client\n", 477 "Received GET_DEFAULT for service `%s' from client\n",
504 name); 478 name);
505 if (GNUNET_OK != 479 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
506 GNUNET_CONFIGURATION_get_value_string (subsystem_cfg, 480 name,
507 name, 481 "DEFAULT_IDENTIFIER",
508 "DEFAULT_IDENTIFIER", 482 &identifier))
509 &identifier))
510 { 483 {
511 send_result_code (client, 1, gettext_noop ("no default known")); 484 send_result_code (client, 1, gettext_noop ("no default known"));
512 GNUNET_SERVICE_client_continue (client); 485 GNUNET_SERVICE_client_continue (client);
@@ -515,11 +488,9 @@ handle_get_default_message (void *cls,
515 } 488 }
516 for (ego = ego_head; NULL != ego; ego = ego->next) 489 for (ego = ego_head; NULL != ego; ego = ego->next)
517 { 490 {
518 if (0 == strcmp (ego->identifier, 491 if (0 == strcmp (ego->identifier, identifier))
519 identifier))
520 { 492 {
521 env = create_set_default_message (ego, 493 env = create_set_default_message (ego, name);
522 name);
523 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); 494 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
524 GNUNET_SERVICE_client_continue (client); 495 GNUNET_SERVICE_client_continue (client);
525 GNUNET_free (identifier); 496 GNUNET_free (identifier);
@@ -528,12 +499,12 @@ handle_get_default_message (void *cls,
528 } 499 }
529 } 500 }
530 GNUNET_free (identifier); 501 GNUNET_free (identifier);
531 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 502 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to find ego `%s'\n", name);
532 "Failed to find ego `%s'\n",
533 name);
534 GNUNET_free (name); 503 GNUNET_free (name);
535 send_result_code (client, 1, 504 send_result_code (client,
536 gettext_noop ("default configured, but ego unknown (internal error)")); 505 1,
506 gettext_noop (
507 "default configured, but ego unknown (internal error)"));
537 GNUNET_SERVICE_client_continue (client); 508 GNUNET_SERVICE_client_continue (client);
538} 509}
539 510
@@ -560,8 +531,7 @@ key_cmp (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk1,
560 * @return #GNUNET_OK if @a msg is well-formed 531 * @return #GNUNET_OK if @a msg is well-formed
561 */ 532 */
562static int 533static int
563check_set_default_message (void *cls, 534check_set_default_message (void *cls, const struct SetDefaultMessage *msg)
564 const struct SetDefaultMessage *msg)
565{ 535{
566 uint16_t size; 536 uint16_t size;
567 uint16_t name_len; 537 uint16_t name_len;
@@ -598,8 +568,7 @@ check_set_default_message (void *cls,
598 * @param message the message received 568 * @param message the message received
599 */ 569 */
600static void 570static void
601handle_set_default_message (void *cls, 571handle_set_default_message (void *cls, const struct SetDefaultMessage *sdm)
602 const struct SetDefaultMessage *sdm)
603{ 572{
604 struct Ego *ego; 573 struct Ego *ego;
605 struct GNUNET_SERVICE_Client *client = cls; 574 struct GNUNET_SERVICE_Client *client = cls;
@@ -613,26 +582,27 @@ handle_set_default_message (void *cls,
613 str); 582 str);
614 for (ego = ego_head; NULL != ego; ego = ego->next) 583 for (ego = ego_head; NULL != ego; ego = ego->next)
615 { 584 {
616 if (0 == key_cmp (ego->pk, 585 if (0 == key_cmp (ego->pk, &sdm->private_key))
617 &sdm->private_key))
618 { 586 {
619 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg, 587 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
620 str, 588 str,
621 "DEFAULT_IDENTIFIER", 589 "DEFAULT_IDENTIFIER",
622 ego->identifier); 590 ego->identifier);
623 if (GNUNET_OK != 591 if (GNUNET_OK !=
624 GNUNET_CONFIGURATION_write (subsystem_cfg, 592 GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file))
625 subsystem_cfg_file)) 593 GNUNET_log (
626 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 594 GNUNET_ERROR_TYPE_ERROR,
627 _("Failed to write subsystem default identifier map to `%s'.\n"), 595 _ ("Failed to write subsystem default identifier map to `%s'.\n"),
628 subsystem_cfg_file); 596 subsystem_cfg_file);
629 send_result_code (client, 0, NULL); 597 send_result_code (client, 0, NULL);
630 GNUNET_SERVICE_client_continue (client); 598 GNUNET_SERVICE_client_continue (client);
631 GNUNET_free (str); 599 GNUNET_free (str);
632 return; 600 return;
633 } 601 }
634 } 602 }
635 send_result_code (client, 1, _("Unknown ego specified for service (internal error)")); 603 send_result_code (client,
604 1,
605 _ ("Unknown ego specified for service (internal error)"));
636 GNUNET_free (str); 606 GNUNET_free (str);
637 GNUNET_SERVICE_client_continue (client); 607 GNUNET_SERVICE_client_continue (client);
638} 608}
@@ -657,9 +627,7 @@ notify_listeners (struct Ego *ego)
657 um->end_of_list = htons (GNUNET_NO); 627 um->end_of_list = htons (GNUNET_NO);
658 um->private_key = *ego->pk; 628 um->private_key = *ego->pk;
659 GNUNET_memcpy (&um[1], ego->identifier, name_len); 629 GNUNET_memcpy (&um[1], ego->identifier, name_len);
660 GNUNET_notification_context_broadcast (nc, 630 GNUNET_notification_context_broadcast (nc, &um->header, GNUNET_NO);
661 &um->header,
662 GNUNET_NO);
663 GNUNET_free (um); 631 GNUNET_free (um);
664} 632}
665 633
@@ -671,10 +639,9 @@ notify_listeners (struct Ego *ego)
671 * @return #GNUNET_OK if @a msg is well-formed 639 * @return #GNUNET_OK if @a msg is well-formed
672 */ 640 */
673static int 641static int
674check_create_message (void *cls, 642check_create_message (void *cls, const struct CreateRequestMessage *msg)
675 const struct CreateRequestMessage *msg)
676{ 643{
677 644
678 uint16_t size; 645 uint16_t size;
679 uint16_t name_len; 646 uint16_t name_len;
680 const char *str; 647 const char *str;
@@ -699,7 +666,7 @@ check_create_message (void *cls,
699 return GNUNET_SYSERR; 666 return GNUNET_SYSERR;
700 } 667 }
701 return GNUNET_OK; 668 return GNUNET_OK;
702} 669}
703 670
704/** 671/**
705 * Handler for CREATE message from client, creates 672 * Handler for CREATE message from client, creates
@@ -710,24 +677,24 @@ check_create_message (void *cls,
710 * @param message the message received 677 * @param message the message received
711 */ 678 */
712static void 679static void
713handle_create_message (void *cls, 680handle_create_message (void *cls, const struct CreateRequestMessage *crm)
714 const struct CreateRequestMessage *crm)
715{ 681{
716 struct GNUNET_SERVICE_Client *client = cls; 682 struct GNUNET_SERVICE_Client *client = cls;
717 struct Ego *ego; 683 struct Ego *ego;
718 char *str; 684 char *str;
719 char *fn; 685 char *fn;
720 686
721 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received CREATE message from client\n");
722 "Received CREATE message from client\n");
723 str = GNUNET_strdup ((const char *) &crm[1]); 688 str = GNUNET_strdup ((const char *) &crm[1]);
724 GNUNET_STRINGS_utf8_tolower ((const char *) &crm[1], str); 689 GNUNET_STRINGS_utf8_tolower ((const char *) &crm[1], str);
725 for (ego = ego_head; NULL != ego; ego = ego->next) 690 for (ego = ego_head; NULL != ego; ego = ego->next)
726 { 691 {
727 if (0 == strcmp (ego->identifier, 692 if (0 == strcmp (ego->identifier, str))
728 str))
729 { 693 {
730 send_result_code (client, 1, gettext_noop ("identifier already in use for another ego")); 694 send_result_code (client,
695 1,
696 gettext_noop (
697 "identifier already in use for another ego"));
731 GNUNET_SERVICE_client_continue (client); 698 GNUNET_SERVICE_client_continue (client);
732 GNUNET_free (str); 699 GNUNET_free (str);
733 return; 700 return;
@@ -737,9 +704,7 @@ handle_create_message (void *cls,
737 ego->pk = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey); 704 ego->pk = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey);
738 *ego->pk = crm->private_key; 705 *ego->pk = crm->private_key;
739 ego->identifier = GNUNET_strdup (str); 706 ego->identifier = GNUNET_strdup (str);
740 GNUNET_CONTAINER_DLL_insert (ego_head, 707 GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego);
741 ego_tail,
742 ego);
743 send_result_code (client, 0, NULL); 708 send_result_code (client, 0, NULL);
744 fn = get_ego_filename (ego); 709 fn = get_ego_filename (ego);
745 (void) GNUNET_DISK_directory_create_for_file (fn); 710 (void) GNUNET_DISK_directory_create_for_file (fn);
@@ -748,9 +713,8 @@ handle_create_message (void *cls,
748 &crm->private_key, 713 &crm->private_key,
749 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), 714 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
750 GNUNET_DISK_PERM_USER_READ | 715 GNUNET_DISK_PERM_USER_READ |
751 GNUNET_DISK_PERM_USER_WRITE)) 716 GNUNET_DISK_PERM_USER_WRITE))
752 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 717 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn);
753 "write", fn);
754 GNUNET_free (fn); 718 GNUNET_free (fn);
755 GNUNET_free (str); 719 GNUNET_free (str);
756 notify_listeners (ego); 720 notify_listeners (ego);
@@ -782,17 +746,15 @@ struct RenameContext
782 * @param section a section in the configuration to process 746 * @param section a section in the configuration to process
783 */ 747 */
784static void 748static void
785handle_ego_rename (void *cls, 749handle_ego_rename (void *cls, const char *section)
786 const char *section)
787{ 750{
788 struct RenameContext *rc = cls; 751 struct RenameContext *rc = cls;
789 char *id; 752 char *id;
790 753
791 if (GNUNET_OK != 754 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
792 GNUNET_CONFIGURATION_get_value_string (subsystem_cfg, 755 section,
793 section, 756 "DEFAULT_IDENTIFIER",
794 "DEFAULT_IDENTIFIER", 757 &id))
795 &id))
796 return; 758 return;
797 if (0 != strcmp (id, rc->old_name)) 759 if (0 != strcmp (id, rc->old_name))
798 { 760 {
@@ -814,8 +776,7 @@ handle_ego_rename (void *cls,
814 * @return #GNUNET_OK if @a msg is well-formed 776 * @return #GNUNET_OK if @a msg is well-formed
815 */ 777 */
816static int 778static int
817check_rename_message (void *cls, 779check_rename_message (void *cls, const struct RenameMessage *msg)
818 const struct RenameMessage *msg)
819{ 780{
820 uint16_t size; 781 uint16_t size;
821 uint16_t old_name_len; 782 uint16_t old_name_len;
@@ -833,9 +794,9 @@ check_rename_message (void *cls,
833 new_name_len = ntohs (msg->new_name_len); 794 new_name_len = ntohs (msg->new_name_len);
834 old_name = (const char *) &msg[1]; 795 old_name = (const char *) &msg[1];
835 new_name = &old_name[old_name_len]; 796 new_name = &old_name[old_name_len];
836 if ( (old_name_len + new_name_len + sizeof (struct RenameMessage) != size) || 797 if ((old_name_len + new_name_len + sizeof (struct RenameMessage) != size) ||
837 ('\0' != old_name[old_name_len - 1]) || 798 ('\0' != old_name[old_name_len - 1]) ||
838 ('\0' != new_name[new_name_len - 1]) ) 799 ('\0' != new_name[new_name_len - 1]))
839 { 800 {
840 GNUNET_break (0); 801 GNUNET_break (0);
841 return GNUNET_SYSERR; 802 return GNUNET_SYSERR;
@@ -843,7 +804,7 @@ check_rename_message (void *cls,
843 804
844 return GNUNET_OK; 805 return GNUNET_OK;
845} 806}
846 807
847 808
848/** 809/**
849 * Handler for RENAME message from client, creates 810 * Handler for RENAME message from client, creates
@@ -854,8 +815,7 @@ check_rename_message (void *cls,
854 * @param message the message received 815 * @param message the message received
855 */ 816 */
856static void 817static void
857handle_rename_message (void *cls, 818handle_rename_message (void *cls, const struct RenameMessage *rm)
858 const struct RenameMessage *rm)
859{ 819{
860 uint16_t old_name_len; 820 uint16_t old_name_len;
861 struct Ego *ego; 821 struct Ego *ego;
@@ -867,8 +827,7 @@ handle_rename_message (void *cls,
867 char *fn_new; 827 char *fn_new;
868 const char *old_name_tmp; 828 const char *old_name_tmp;
869 829
870 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 830 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received RENAME message from client\n");
871 "Received RENAME message from client\n");
872 old_name_len = ntohs (rm->old_name_len); 831 old_name_len = ntohs (rm->old_name_len);
873 old_name_tmp = (const char *) &rm[1]; 832 old_name_tmp = (const char *) &rm[1];
874 old_name = GNUNET_strdup (old_name_tmp); 833 old_name = GNUNET_strdup (old_name_tmp);
@@ -879,8 +838,7 @@ handle_rename_message (void *cls,
879 /* check if new name is already in use */ 838 /* check if new name is already in use */
880 for (ego = ego_head; NULL != ego; ego = ego->next) 839 for (ego = ego_head; NULL != ego; ego = ego->next)
881 { 840 {
882 if (0 == strcmp (ego->identifier, 841 if (0 == strcmp (ego->identifier, new_name))
883 new_name))
884 { 842 {
885 send_result_code (client, 1, gettext_noop ("target name already exists")); 843 send_result_code (client, 1, gettext_noop ("target name already exists"));
886 GNUNET_SERVICE_client_continue (client); 844 GNUNET_SERVICE_client_continue (client);
@@ -893,8 +851,7 @@ handle_rename_message (void *cls,
893 /* locate old name and, if found, perform rename */ 851 /* locate old name and, if found, perform rename */
894 for (ego = ego_head; NULL != ego; ego = ego->next) 852 for (ego = ego_head; NULL != ego; ego = ego->next)
895 { 853 {
896 if (0 == strcmp (ego->identifier, 854 if (0 == strcmp (ego->identifier, old_name))
897 old_name))
898 { 855 {
899 fn_old = get_ego_filename (ego); 856 fn_old = get_ego_filename (ego);
900 GNUNET_free (ego->identifier); 857 GNUNET_free (ego->identifier);
@@ -904,14 +861,14 @@ handle_rename_message (void *cls,
904 &handle_ego_rename, 861 &handle_ego_rename,
905 &rename_ctx); 862 &rename_ctx);
906 if (GNUNET_OK != 863 if (GNUNET_OK !=
907 GNUNET_CONFIGURATION_write (subsystem_cfg, 864 GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file))
908 subsystem_cfg_file)) 865 GNUNET_log (
909 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 866 GNUNET_ERROR_TYPE_ERROR,
910 _("Failed to write subsystem default identifier map to `%s'.\n"), 867 _ ("Failed to write subsystem default identifier map to `%s'.\n"),
911 subsystem_cfg_file); 868 subsystem_cfg_file);
912 ego->identifier = GNUNET_strdup (new_name); 869 ego->identifier = GNUNET_strdup (new_name);
913 fn_new = get_ego_filename (ego); 870 fn_new = get_ego_filename (ego);
914 if (0 != RENAME (fn_old, fn_new)) 871 if (0 != rename (fn_old, fn_new))
915 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rename", fn_old); 872 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rename", fn_old);
916 GNUNET_free (fn_old); 873 GNUNET_free (fn_old);
917 GNUNET_free (fn_new); 874 GNUNET_free (fn_new);
@@ -940,17 +897,15 @@ handle_rename_message (void *cls,
940 * @param section a section in the configuration to process 897 * @param section a section in the configuration to process
941 */ 898 */
942static void 899static void
943handle_ego_delete (void *cls, 900handle_ego_delete (void *cls, const char *section)
944 const char *section)
945{ 901{
946 const char *identifier = cls; 902 const char *identifier = cls;
947 char *id; 903 char *id;
948 904
949 if (GNUNET_OK != 905 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
950 GNUNET_CONFIGURATION_get_value_string (subsystem_cfg, 906 section,
951 section, 907 "DEFAULT_IDENTIFIER",
952 "DEFAULT_IDENTIFIER", 908 &id))
953 &id))
954 return; 909 return;
955 if (0 != strcmp (id, identifier)) 910 if (0 != strcmp (id, identifier))
956 { 911 {
@@ -972,8 +927,7 @@ handle_ego_delete (void *cls,
972 * @return #GNUNET_OK if @a msg is well-formed 927 * @return #GNUNET_OK if @a msg is well-formed
973 */ 928 */
974static int 929static int
975check_delete_message (void *cls, 930check_delete_message (void *cls, const struct DeleteMessage *msg)
976 const struct DeleteMessage *msg)
977{ 931{
978 uint16_t size; 932 uint16_t size;
979 uint16_t name_len; 933 uint16_t name_len;
@@ -987,9 +941,8 @@ check_delete_message (void *cls,
987 } 941 }
988 name = (const char *) &msg[1]; 942 name = (const char *) &msg[1];
989 name_len = ntohs (msg->name_len); 943 name_len = ntohs (msg->name_len);
990 if ( (name_len + sizeof (struct DeleteMessage) != size) || 944 if ((name_len + sizeof (struct DeleteMessage) != size) ||
991 (0 != ntohs (msg->reserved)) || 945 (0 != ntohs (msg->reserved)) || ('\0' != name[name_len - 1]))
992 ('\0' != name[name_len - 1]) )
993 { 946 {
994 GNUNET_break (0); 947 GNUNET_break (0);
995 return GNUNET_SYSERR; 948 return GNUNET_SYSERR;
@@ -1007,38 +960,33 @@ check_delete_message (void *cls,
1007 * @param message the message received 960 * @param message the message received
1008 */ 961 */
1009static void 962static void
1010handle_delete_message (void *cls, 963handle_delete_message (void *cls, const struct DeleteMessage *dm)
1011 const struct DeleteMessage *dm)
1012{ 964{
1013 struct Ego *ego; 965 struct Ego *ego;
1014 char *name; 966 char *name;
1015 char *fn; 967 char *fn;
1016 struct GNUNET_SERVICE_Client *client = cls; 968 struct GNUNET_SERVICE_Client *client = cls;
1017 969
1018 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 970 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received DELETE message from client\n");
1019 "Received DELETE message from client\n");
1020 name = GNUNET_strdup ((const char *) &dm[1]); 971 name = GNUNET_strdup ((const char *) &dm[1]);
1021 GNUNET_STRINGS_utf8_tolower ((const char *) &dm[1], name); 972 GNUNET_STRINGS_utf8_tolower ((const char *) &dm[1], name);
1022 973
1023 for (ego = ego_head; NULL != ego; ego = ego->next) 974 for (ego = ego_head; NULL != ego; ego = ego->next)
1024 { 975 {
1025 if (0 == strcmp (ego->identifier, 976 if (0 == strcmp (ego->identifier, name))
1026 name))
1027 { 977 {
1028 GNUNET_CONTAINER_DLL_remove (ego_head, 978 GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, ego);
1029 ego_tail,
1030 ego);
1031 GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg, 979 GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg,
1032 &handle_ego_delete, 980 &handle_ego_delete,
1033 ego->identifier); 981 ego->identifier);
1034 if (GNUNET_OK != 982 if (GNUNET_OK !=
1035 GNUNET_CONFIGURATION_write (subsystem_cfg, 983 GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file))
1036 subsystem_cfg_file)) 984 GNUNET_log (
1037 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 985 GNUNET_ERROR_TYPE_ERROR,
1038 _("Failed to write subsystem default identifier map to `%s'.\n"), 986 _ ("Failed to write subsystem default identifier map to `%s'.\n"),
1039 subsystem_cfg_file); 987 subsystem_cfg_file);
1040 fn = get_ego_filename (ego); 988 fn = get_ego_filename (ego);
1041 if (0 != UNLINK (fn)) 989 if (0 != unlink (fn))
1042 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); 990 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
1043 GNUNET_free (fn); 991 GNUNET_free (fn);
1044 GNUNET_free (ego->identifier); 992 GNUNET_free (ego->identifier);
@@ -1070,8 +1018,7 @@ handle_delete_message (void *cls,
1070 * #GNUNET_SYSERR to abort iteration with error! 1018 * #GNUNET_SYSERR to abort iteration with error!
1071 */ 1019 */
1072static int 1020static int
1073process_ego_file (void *cls, 1021process_ego_file (void *cls, const char *filename)
1074 const char *filename)
1075{ 1022{
1076 struct Ego *ego; 1023 struct Ego *ego;
1077 const char *fn; 1024 const char *fn;
@@ -1088,17 +1035,13 @@ process_ego_file (void *cls,
1088 { 1035 {
1089 GNUNET_free (ego); 1036 GNUNET_free (ego);
1090 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1037 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1091 _("Failed to parse ego information in `%s'\n"), 1038 _ ("Failed to parse ego information in `%s'\n"),
1092 filename); 1039 filename);
1093 return GNUNET_OK; 1040 return GNUNET_OK;
1094 } 1041 }
1095 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1042 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded ego `%s'\n", fn + 1);
1096 "Loaded ego `%s'\n",
1097 fn + 1);
1098 ego->identifier = GNUNET_strdup (fn + 1); 1043 ego->identifier = GNUNET_strdup (fn + 1);
1099 GNUNET_CONTAINER_DLL_insert (ego_head, 1044 GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego);
1100 ego_tail,
1101 ego);
1102 return GNUNET_OK; 1045 return GNUNET_OK;
1103} 1046}
1104 1047
@@ -1117,21 +1060,24 @@ run (void *cls,
1117{ 1060{
1118 cfg = c; 1061 cfg = c;
1119 nc = GNUNET_notification_context_create (1); 1062 nc = GNUNET_notification_context_create (1);
1120 if (GNUNET_OK != 1063 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
1121 GNUNET_CONFIGURATION_get_value_filename (cfg, "identity", 1064 "identity",
1122 "EGODIR", 1065 "EGODIR",
1123 &ego_directory)) 1066 &ego_directory))
1124 { 1067 {
1125 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "EGODIR"); 1068 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "EGODIR");
1126 GNUNET_SCHEDULER_shutdown (); 1069 GNUNET_SCHEDULER_shutdown ();
1127 return; 1070 return;
1128 } 1071 }
1129 if (GNUNET_OK != 1072 if (GNUNET_OK !=
1130 GNUNET_CONFIGURATION_get_value_filename (cfg, "identity", 1073 GNUNET_CONFIGURATION_get_value_filename (cfg,
1074 "identity",
1131 "SUBSYSTEM_CFG", 1075 "SUBSYSTEM_CFG",
1132 &subsystem_cfg_file)) 1076 &subsystem_cfg_file))
1133 { 1077 {
1134 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "SUBSYSTEM_CFG"); 1078 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
1079 "identity",
1080 "SUBSYSTEM_CFG");
1135 GNUNET_SCHEDULER_shutdown (); 1081 GNUNET_SCHEDULER_shutdown ();
1136 return; 1082 return;
1137 } 1083 }
@@ -1139,78 +1085,72 @@ run (void *cls,
1139 "Loading subsystem configuration `%s'\n", 1085 "Loading subsystem configuration `%s'\n",
1140 subsystem_cfg_file); 1086 subsystem_cfg_file);
1141 subsystem_cfg = GNUNET_CONFIGURATION_create (); 1087 subsystem_cfg = GNUNET_CONFIGURATION_create ();
1142 if ( (GNUNET_YES == 1088 if ((GNUNET_YES == GNUNET_DISK_file_test (subsystem_cfg_file)) &&
1143 GNUNET_DISK_file_test (subsystem_cfg_file)) && 1089 (GNUNET_OK !=
1144 (GNUNET_OK != 1090 GNUNET_CONFIGURATION_parse (subsystem_cfg, subsystem_cfg_file)))
1145 GNUNET_CONFIGURATION_parse (subsystem_cfg,
1146 subsystem_cfg_file)) )
1147 { 1091 {
1148 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1092 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1149 _("Failed to parse subsystem identity configuration file `%s'\n"), 1093 _ (
1094 "Failed to parse subsystem identity configuration file `%s'\n"),
1150 subsystem_cfg_file); 1095 subsystem_cfg_file);
1151 GNUNET_SCHEDULER_shutdown (); 1096 GNUNET_SCHEDULER_shutdown ();
1152 return; 1097 return;
1153 } 1098 }
1154 stats = GNUNET_STATISTICS_create ("identity", cfg); 1099 stats = GNUNET_STATISTICS_create ("identity", cfg);
1155 if (GNUNET_OK != 1100 if (GNUNET_OK != GNUNET_DISK_directory_create (ego_directory))
1156 GNUNET_DISK_directory_create (ego_directory))
1157 { 1101 {
1158 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1102 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1159 _("Failed to create directory `%s' for storing egos\n"), 1103 _ ("Failed to create directory `%s' for storing egos\n"),
1160 ego_directory); 1104 ego_directory);
1161 } 1105 }
1162 GNUNET_DISK_directory_scan (ego_directory, 1106 GNUNET_DISK_directory_scan (ego_directory, &process_ego_file, NULL);
1163 &process_ego_file, 1107 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1164 NULL);
1165 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
1166 NULL);
1167} 1108}
1168 1109
1169 1110
1170/** 1111/**
1171 * Define "main" method using service macro. 1112 * Define "main" method using service macro.
1172 */ 1113 */
1173GNUNET_SERVICE_MAIN 1114GNUNET_SERVICE_MAIN (
1174("identity", 1115 "identity",
1175 GNUNET_SERVICE_OPTION_NONE, 1116 GNUNET_SERVICE_OPTION_NONE,
1176 &run, 1117 &run,
1177 &client_connect_cb, 1118 &client_connect_cb,
1178 &client_disconnect_cb, 1119 &client_disconnect_cb,
1179 NULL, 1120 NULL,
1180 GNUNET_MQ_hd_fixed_size (start_message, 1121 GNUNET_MQ_hd_fixed_size (start_message,
1181 GNUNET_MESSAGE_TYPE_IDENTITY_START, 1122 GNUNET_MESSAGE_TYPE_IDENTITY_START,
1182 struct GNUNET_MessageHeader, 1123 struct GNUNET_MessageHeader,
1183 NULL), 1124 NULL),
1184 GNUNET_MQ_hd_var_size (lookup_message, 1125 GNUNET_MQ_hd_var_size (lookup_message,
1185 GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP, 1126 GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP,
1186 struct LookupMessage, 1127 struct LookupMessage,
1187 NULL), 1128 NULL),
1188 GNUNET_MQ_hd_var_size (lookup_by_suffix_message, 1129 GNUNET_MQ_hd_var_size (lookup_by_suffix_message,
1189 GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX, 1130 GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX,
1190 struct LookupMessage, 1131 struct LookupMessage,
1191 NULL), 1132 NULL),
1192 GNUNET_MQ_hd_var_size (get_default_message, 1133 GNUNET_MQ_hd_var_size (get_default_message,
1193 GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT, 1134 GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT,
1194 struct GetDefaultMessage, 1135 struct GetDefaultMessage,
1195 NULL), 1136 NULL),
1196 GNUNET_MQ_hd_var_size (set_default_message, 1137 GNUNET_MQ_hd_var_size (set_default_message,
1197 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, 1138 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT,
1198 struct SetDefaultMessage, 1139 struct SetDefaultMessage,
1199 NULL), 1140 NULL),
1200 GNUNET_MQ_hd_var_size (create_message, 1141 GNUNET_MQ_hd_var_size (create_message,
1201 GNUNET_MESSAGE_TYPE_IDENTITY_CREATE, 1142 GNUNET_MESSAGE_TYPE_IDENTITY_CREATE,
1202 struct CreateRequestMessage, 1143 struct CreateRequestMessage,
1203 NULL), 1144 NULL),
1204 GNUNET_MQ_hd_var_size (rename_message, 1145 GNUNET_MQ_hd_var_size (rename_message,
1205 GNUNET_MESSAGE_TYPE_IDENTITY_RENAME, 1146 GNUNET_MESSAGE_TYPE_IDENTITY_RENAME,
1206 struct RenameMessage, 1147 struct RenameMessage,
1207 NULL), 1148 NULL),
1208 GNUNET_MQ_hd_var_size (delete_message, 1149 GNUNET_MQ_hd_var_size (delete_message,
1209 GNUNET_MESSAGE_TYPE_IDENTITY_DELETE, 1150 GNUNET_MESSAGE_TYPE_IDENTITY_DELETE,
1210 struct DeleteMessage, 1151 struct DeleteMessage,
1211 NULL), 1152 NULL),
1212 GNUNET_MQ_handler_end()); 1153 GNUNET_MQ_handler_end ());
1213
1214 1154
1215 1155
1216/* end of gnunet-service-identity.c */ 1156/* end of gnunet-service-identity.c */
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index 3525a0607..775257768 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -25,7 +25,7 @@ gnunetinclude_HEADERS = \
25else 25else
26 26
27gnunetinclude_HEADERS = \ 27gnunetinclude_HEADERS = \
28 platform.h plibc.h $(WINPROC) gettext.h \ 28 platform.h $(WINPROC) gettext.h \
29 compat.h \ 29 compat.h \
30 gnunet_applications.h \ 30 gnunet_applications.h \
31 gnunet_arm_service.h \ 31 gnunet_arm_service.h \
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index 66d0b8ac3..6eed12ddb 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -964,7 +964,7 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
964 cmd, \ 964 cmd, \
965 __FILE__, \ 965 __FILE__, \
966 __LINE__, \ 966 __LINE__, \
967 STRERROR (errno)); \ 967 strerror (errno)); \
968 } while (0) 968 } while (0)
969 969
970 970
@@ -983,7 +983,7 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
983 cmd, \ 983 cmd, \
984 __FILE__, \ 984 __FILE__, \
985 __LINE__, \ 985 __LINE__, \
986 STRERROR (errno)); \ 986 strerror (errno)); \
987 } while (0) 987 } while (0)
988 988
989 989
@@ -1002,7 +1002,7 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
1002 filename, \ 1002 filename, \
1003 __FILE__, \ 1003 __FILE__, \
1004 __LINE__, \ 1004 __LINE__, \
1005 STRERROR (errno)); \ 1005 strerror (errno)); \
1006 } while (0) 1006 } while (0)
1007 1007
1008 1008
@@ -1022,7 +1022,7 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
1022 filename, \ 1022 filename, \
1023 __FILE__, \ 1023 __FILE__, \
1024 __LINE__, \ 1024 __LINE__, \
1025 STRERROR (errno)); \ 1025 strerror (errno)); \
1026 } while (0) 1026 } while (0)
1027 1027
1028/* ************************* endianess conversion ****************** */ 1028/* ************************* endianess conversion ****************** */
diff --git a/src/include/platform.h b/src/include/platform.h
index 0e3144ee8..6a3e8e4b8 100644
--- a/src/include/platform.h
+++ b/src/include/platform.h
@@ -196,7 +196,25 @@
196#include <sys/endian.h> 196#include <sys/endian.h>
197#endif 197#endif
198 198
199#include "plibc.h" 199/* From plibc. */
200#ifdef Q_OS_WIN32
201#define WINDOWS 1
202#endif
203
204#ifndef WINDOWS
205#define DIR_SEPARATOR '/'
206#define DIR_SEPARATOR_STR "/"
207#define PATH_SEPARATOR ':'
208#define PATH_SEPARATOR_STR ":"
209#define NEWLINE "\n"
210#else
211#define DIR_SEPARATOR '\\'
212#define DIR_SEPARATOR_STR "\\"
213#define PATH_SEPARATOR ';'
214#define PATH_SEPARATOR_STR ";"
215#define NEWLINE "\r\n"
216#endif
217
200#include "compat.h" 218#include "compat.h"
201 219
202#include <locale.h> 220#include <locale.h>
diff --git a/src/include/plibc.h b/src/include/plibc.h
deleted file mode 100644
index 9c1d954e9..000000000
--- a/src/include/plibc.h
+++ /dev/null
@@ -1,980 +0,0 @@
1/*
2 This file is part of PlibC.
3 Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Nils Durner (and other contributing authors)
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*/
19
20/**
21 * @file
22 * PlibC header
23 *
24 * @attention This file is usually not installed under Unix,
25 * so ship it with your application
26 *
27 * @version $Revision: 158 $
28 */
29
30#ifndef _PLIBC_H_
31#define _PLIBC_H_
32
33#ifndef SIGALRM
34 #define SIGALRM 14
35#endif
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41#include <stddef.h>
42
43#ifdef Q_OS_WIN32
44 #define WINDOWS 1
45#endif
46
47#define HAVE_PLIBC_FD 0
48
49#ifdef WINDOWS
50
51#if ENABLE_NLS
52 #include "langinfo.h"
53#endif
54
55#include <ws2tcpip.h>
56#include <windows.h>
57#include <sys/types.h>
58#include <time.h>
59#include <stdio.h>
60#include <sys/types.h>
61#include <sys/stat.h>
62#include <dirent.h>
63#include <errno.h>
64#include <stdarg.h>
65
66#define __BYTE_ORDER BYTE_ORDER
67#define __BIG_ENDIAN BIG_ENDIAN
68
69/* Conflicts with our definitions */
70#define __G_WIN32_H__
71
72/* Convert LARGE_INTEGER to double */
73#define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + \
74 (double)((x).LowPart))
75#ifndef HAVE_DECL__STATI64
76struct _stati64
77{
78 _dev_t st_dev;
79 _ino_t st_ino;
80 _mode_t st_mode;
81 short st_nlink;
82 short st_uid;
83 short st_gid;
84 _dev_t st_rdev;
85 __int64 st_size;
86 time_t st_atime;
87 time_t st_mtime;
88 time_t st_ctime;
89};
90#endif
91typedef unsigned int sa_family_t;
92
93struct sockaddr_un {
94 short sun_family; /*AF_UNIX*/
95 char sun_path[108]; /*path name */
96};
97
98#ifndef pid_t
99 #define pid_t DWORD
100#endif
101
102#ifndef error_t
103 #define error_t int
104#endif
105
106#ifndef WEXITSTATUS
107 #define WEXITSTATUS(status) (((status) & 0xff00) >> 8)
108#endif
109
110#ifndef MSG_DONTWAIT
111 #define MSG_DONTWAIT 0
112#endif
113
114enum
115{
116 _SC_PAGESIZE = 30,
117 _SC_PAGE_SIZE = 30
118};
119
120#if !defined(EACCESS)
121# define EACCESS EACCES
122#endif
123
124/* Thanks to the Cygwin project */
125#if !defined(ENOCSI)
126# define ENOCSI 43 /* No CSI structure available */
127#endif
128#if !defined(EL2HLT)
129# define EL2HLT 44 /* Level 2 halted */
130#endif
131#if !defined(EDEADLK)
132# define EDEADLK 45 /* Deadlock condition */
133#endif
134#if !defined(ENOLCK)
135# define ENOLCK 46 /* No record locks available */
136#endif
137#if !defined(EBADE)
138# define EBADE 50 /* Invalid exchange */
139#endif
140#if !defined(EBADR)
141# define EBADR 51 /* Invalid request descriptor */
142#endif
143#if !defined(EXFULL)
144# define EXFULL 52 /* Exchange full */
145#endif
146#if !defined(ENOANO)
147# define ENOANO 53 /* No anode */
148#endif
149#if !defined(EBADRQC)
150# define EBADRQC 54 /* Invalid request code */
151#endif
152#if !defined(EBADSLT)
153# define EBADSLT 55 /* Invalid slot */
154#endif
155#if !defined(EDEADLOCK)
156# define EDEADLOCK EDEADLK /* File locking deadlock error */
157#endif
158#if !defined(EBFONT)
159# define EBFONT 57 /* Bad font file fmt */
160#endif
161#if !defined(ENOSTR)
162# define ENOSTR 60 /* Device not a stream */
163#endif
164#if !defined(ENODATA)
165# define ENODATA 61 /* No data (for no delay io) */
166#endif
167#if !defined(ETIME)
168# define ETIME 62 /* Timer expired */
169#endif
170#if !defined(ENOSR)
171# define ENOSR 63 /* Out of streams resources */
172#endif
173#if !defined(ENONET)
174# define ENONET 64 /* Machine is not on the network */
175#endif
176#if !defined(ENOPKG)
177# define ENOPKG 65 /* Package not installed */
178#endif
179#if !defined(EREMOTE)
180# define EREMOTE 66 /* The object is remote */
181#endif
182#if !defined(ENOLINK)
183# define ENOLINK 67 /* The link has been severed */
184#endif
185#if !defined(EADV)
186# define EADV 68 /* Advertise error */
187#endif
188#if !defined(ESRMNT)
189# define ESRMNT 69 /* Srmount error */
190#endif
191#if !defined(ECOMM)
192# define ECOMM 70 /* Communication error on send */
193#endif
194#if !defined(EMULTIHOP)
195# define EMULTIHOP 74 /* Multihop attempted */
196#endif
197#if !defined(ELBIN)
198# define ELBIN 75 /* Inode is remote (not really error) */
199#endif
200#if !defined(EDOTDOT)
201# define EDOTDOT 76 /* Cross mount point (not really error) */
202#endif
203#if !defined(EBADMSG)
204# define EBADMSG 77 /* Trying to read unreadable message */
205#endif
206#if !defined(ENOTUNIQ)
207# define ENOTUNIQ 80 /* Given log. name not unique */
208#endif
209#if !defined(EBADFD)
210# define EBADFD 81 /* f.d. invalid for this operation */
211#endif
212#if !defined(EREMCHG)
213# define EREMCHG 82 /* Remote address changed */
214#endif
215#if !defined(ELIBACC)
216# define ELIBACC 83 /* Can't access a needed shared lib */
217#endif
218#if !defined(ELIBBAD)
219# define ELIBBAD 84 /* Accessing a corrupted shared lib */
220#endif
221#if !defined(ELIBSCN)
222# define ELIBSCN 85 /* .lib section in a.out corrupted */
223#endif
224#if !defined(ELIBMAX)
225# define ELIBMAX 86 /* Attempting to link in too many libs */
226#endif
227#if !defined(ELIBEXEC)
228# define ELIBEXEC 87 /* Attempting to exec a shared library */
229#endif
230#if !defined(ENOSYS)
231# define ENOSYS 88 /* Function not implemented */
232#endif
233#if !defined(ENMFILE)
234# define ENMFILE 89 /* No more files */
235#endif
236#if !defined(ENOTEMPTY)
237# define ENOTEMPTY 90 /* Directory not empty */
238#endif
239#if !defined(ENAMETOOLONG)
240# define ENAMETOOLONG 91 /* File or path name too long */
241#endif
242#if !defined(EPFNOSUPPORT)
243# define EPFNOSUPPORT 96 /* Protocol family not supported */
244#endif
245#if !defined(ENOSHARE)
246# define ENOSHARE 97 /* No such host or network path */
247#endif
248#if !defined(ENOMEDIUM)
249# define ENOMEDIUM 98 /* No medium (in tape drive) */
250#endif
251#if !defined(ESHUTDOWN)
252# define ESHUTDOWN 99 /* Can't send after socket shutdown */
253#endif
254#if !defined(EADDRINUSE)
255# define EADDRINUSE 100 /* Address already in use */
256#endif
257#if !defined(EADDRNOTAVAIL)
258# define EADDRNOTAVAIL 101 /* Address not available */
259#endif
260#if !defined(EAFNOSUPPORT)
261# define EAFNOSUPPORT 102 /* Address family not supported by protocol family */
262#endif
263#if !defined(EALREADY)
264# define EALREADY 103 /* Socket already connected */
265#endif
266#if !defined(ECANCELED)
267# define ECANCELED 105 /* Connection cancelled */
268#endif
269#if !defined(ECONNABORTED)
270# define ECONNABORTED 106 /* Connection aborted */
271#endif
272#if !defined(ECONNREFUSED)
273# define ECONNREFUSED 107 /* Connection refused */
274#endif
275#if !defined(ECONNRESET)
276# define ECONNRESET 108 /* Connection reset by peer */
277#endif
278#if !defined(EDESTADDRREQ)
279# define EDESTADDRREQ 109 /* Destination address required */
280#endif
281#if !defined(EHOSTUNREACH)
282# define EHOSTUNREACH 110 /* Host is unreachable */
283#endif
284#if !defined(ECONNABORTED)
285# define ECONNABORTED 111 /* Connection aborted */
286#endif
287#if !defined(EINPROGRESS)
288# define EINPROGRESS 112 /* Connection already in progress */
289#endif
290#if !defined(EISCONN)
291# define EISCONN 113 /* Socket is already connected */
292#endif
293#if !defined(ELOOP)
294# define ELOOP 114 /* Too many symbolic links */
295#endif
296#if !defined(EMSGSIZE)
297# define EMSGSIZE 115 /* Message too long */
298#endif
299#if !defined(ENETDOWN)
300# define ENETDOWN 116 /* Network interface is not configured */
301#endif
302#if !defined(ENETRESET)
303# define ENETRESET 117 /* Connection aborted by network */
304#endif
305#if !defined(ENETUNREACH)
306# define ENETUNREACH 118 /* Network is unreachable */
307#endif
308#if !defined(ENOBUFS)
309# define ENOBUFS 119 /* No buffer space available */
310#endif
311#if !defined(EHOSTDOWN)
312# define EHOSTDOWN 120 /* Host is down */
313#endif
314#if !defined(EPROCLIM)
315# define EPROCLIM 121 /* Too many processes */
316#endif
317#if !defined(EDQUOT)
318# define EDQUOT 122 /* Disk quota exceeded */
319#endif
320#if !defined(ENOPROTOOPT)
321# define ENOPROTOOPT 123 /* Protocol not available */
322#endif
323#if !defined(ESOCKTNOSUPPORT)
324# define ESOCKTNOSUPPORT 124 /* Socket type not supported */
325#endif
326#if !defined(ESTALE)
327# define ESTALE 125 /* Unknown error */
328#endif
329#if !defined(ENOTCONN)
330# define ENOTCONN 126 /* Socket is not connected */
331#endif
332#if !defined(ETOOMANYREFS)
333# define ETOOMANYREFS 127 /* Too many references: cannot splice */
334#endif
335#if !defined(ENOTSOCK)
336# define ENOTSOCK 128 /* Socket operation on non-socket */
337#endif
338#if !defined(ENOTSUP)
339# define ENOTSUP 129 /* Not supported */
340#endif
341#if !defined(EOPNOTSUPP)
342# define EOPNOTSUPP 130 /* Operation not supported on transport endpoint */
343#endif
344#if !defined(EUSERS)
345# define EUSERS 131 /* Too many users */
346#endif
347#if !defined(EOVERFLOW)
348# define EOVERFLOW 132 /* Value too large for defined data type */
349#endif
350#if !defined(EOWNERDEAD)
351# define EOWNERDEAD 133 /* Unknown error */
352#endif
353#if !defined(EPROTO)
354# define EPROTO 134 /* Protocol error */
355#endif
356#if !defined(EPROTONOSUPPORT)
357# define EPROTONOSUPPORT 135 /* Unknown protocol */
358#endif
359#if !defined(EPROTOTYPE)
360# define EPROTOTYPE 136 /* Protocol wrong type for socket */
361#endif
362#if !defined(ECASECLASH)
363# define ECASECLASH 137 /* Filename exists with different case */
364#endif
365#if !defined(ETIMEDOUT)
366/* Make sure it's the same as WSATIMEDOUT */
367# define ETIMEDOUT 138 /* Connection timed out */
368#endif
369#if !defined(EWOULDBLOCK) || EWOULDBLOCK == 140
370# undef EWOULDBLOCK /* MinGW-w64 defines it as 140, but we want it as EAGAIN */
371# define EWOULDBLOCK EAGAIN /* Operation would block */
372#endif
373
374#undef HOST_NOT_FOUND
375#define HOST_NOT_FOUND 1
376#undef TRY_AGAIN
377#define TRY_AGAIN 2
378#undef NO_RECOVERY
379#define NO_RECOVERY 3
380#undef NO_ADDRESS
381#define NO_ADDRESS 4
382
383#define PROT_READ 0x1
384#define PROT_WRITE 0x2
385#define MAP_SHARED 0x1
386#define MAP_PRIVATE 0x2 /* unsupported */
387#define MAP_FIXED 0x10
388#define MAP_ANONYMOUS 0x20 /* unsupported */
389#define MAP_FAILED ((void *)-1)
390
391#define MS_ASYNC 1 /* sync memory asynchronously */
392#define MS_INVALIDATE 2 /* invalidate the caches */
393#define MS_SYNC 4 /* synchronous memory sync */
394
395struct statfs
396{
397 long f_type; /* type of filesystem (see below) */
398 long f_bsize; /* optimal transfer block size */
399 long f_blocks; /* total data blocks in file system */
400 long f_bfree; /* free blocks in fs */
401 long f_bavail; /* free blocks avail to non-superuser */
402 long f_files; /* total file nodes in file system */
403 long f_ffree; /* free file nodes in fs */
404 long f_fsid; /* file system id */
405 long f_namelen; /* maximum length of filenames */
406 long f_spare[6]; /* spare for later */
407};
408#define sleep(secs) (Sleep(secs * 1000))
409
410/*********************** statfs *****************************/
411/* fake block size */
412#define FAKED_BLOCK_SIZE 512
413
414/* linux-compatible values for fs type */
415#define MSDOS_SUPER_MAGIC 0x4d44
416#define NTFS_SUPER_MAGIC 0x5346544E
417
418/*********************** End of statfs ***********************/
419
420#define SHUT_RDWR SD_BOTH
421
422/* Operations for flock() */
423#define LOCK_SH 1 /* shared lock */
424#define LOCK_EX 2 /* exclusive lock */
425#define LOCK_NB 4 /* or'd with one of the above to prevent
426 blocking */
427#define LOCK_UN 8 /* remove lock */
428
429/* Not supported under MinGW */
430#ifndef S_IRGRP
431#define S_IRGRP 0
432#endif
433#ifndef S_IWGRP
434#define S_IWGRP 0
435#endif
436#ifndef S_IROTH
437#define S_IROTH 0
438#endif
439#ifndef S_IXGRP
440#define S_IXGRP 0
441#endif
442#ifndef S_IWOTH
443#define S_IWOTH 0
444#endif
445#ifndef S_IXOTH
446#define S_IXOTH 0
447#endif
448#ifndef S_ISUID
449#define S_ISUID 0
450#endif
451#ifndef S_ISGID
452#define S_ISGID 0
453#endif
454#ifndef S_ISVTX
455#define S_ISVTX 0
456#endif
457#ifndef S_IRWXG
458#define S_IRWXG 0
459#endif
460#ifndef S_IRWXO
461#define S_IRWXO 0
462#endif
463
464#define SHUT_WR SD_SEND
465#define SHUT_RD SD_RECEIVE
466#define SHUT_RDWR SD_BOTH
467
468#define SIGKILL 9
469#define SIGTERM 15
470
471#define SetErrnoFromWinError(e) _SetErrnoFromWinError(e, __FILE__, __LINE__)
472
473BOOL _plibc_CreateShortcut(const char *pszSrc, const char *pszDest);
474BOOL _plibc_CreateShortcutW(const wchar_t *pwszSrc, const wchar_t *pwszDest);
475BOOL _plibc_DereferenceShortcut(char *pszShortcut);
476BOOL _plibc_DereferenceShortcutW(wchar_t *pwszShortcut);
477char *plibc_ChooseDir(char *pszTitle, unsigned long ulFlags);
478wchar_t *plibc_ChooseDirW(wchar_t *pwszTitle, unsigned long ulFlags);
479char *plibc_ChooseFile(char *pszTitle, unsigned long ulFlags);
480wchar_t *plibc_ChooseFileW(wchar_t *pwszTitle, unsigned long ulFlags);
481
482long QueryRegistry(HKEY hMainKey, const char *pszKey, const char *pszSubKey,
483 char *pszBuffer, long *pdLength);
484long QueryRegistryW(HKEY hMainKey, const wchar_t *pszKey, const wchar_t *pszSubKey,
485 wchar_t *pszBuffer, long *pdLength);
486
487BOOL __win_IsHandleMarkedAsBlocking(int hHandle);
488void __win_SetHandleBlockingMode(int s, BOOL bBlocking);
489void __win_DiscardHandleBlockingMode(int s);
490int _win_isSocketValid(int s);
491int plibc_conv_to_win_path(const char *pszUnix, char *pszWindows);
492int plibc_conv_to_win_pathw(const wchar_t *pszUnix, wchar_t *pwszWindows);
493
494int plibc_conv_to_win_pathwconv(const char *pszUnix, wchar_t *pwszWindows);
495int plibc_conv_to_win_pathwconv_ex(const char *pszUnix, wchar_t *pszWindows, int derefLinks);
496
497unsigned plibc_get_handle_count();
498
499typedef void (*TPanicProc) (int, char *);
500void plibc_set_panic_proc(TPanicProc proc);
501void plibc_set_stat_size_size(int iLength);
502void plibc_set_stat_time_size(int iLength);
503
504int flock(int fd, int operation);
505int fsync(int fildes);
506int inet_pton(int af, const char *src, void *dst);
507int inet_pton4(const char *src, u_char *dst, int pton);
508#if USE_IPV6
509int inet_pton6(const char *src, u_char *dst);
510#endif
511int statfs(const char *path, struct statfs *buf);
512const char *hstrerror(int err);
513int mkstemp(char *tmplate);
514char *strptime (const char *buf, const char *format, struct tm *tm);
515const char *inet_ntop(int af, const void *src, char *dst, size_t size);
516#ifndef gmtime_r
517struct tm *gmtime_r(const time_t *clock, struct tm *result);
518#endif
519
520int plibc_init(char *pszOrg, char *pszApp);
521int plibc_init_utf8(char *pszOrg, char *pszApp, int utf8_mode);
522void plibc_shutdown();
523int plibc_initialized();
524
525void _SetErrnoFromWinError(long lWinError, char *pszCaller, int iLine);
526void SetErrnoFromWinsockError(long lWinError);
527void SetHErrnoFromWinError(long lWinError);
528void SetErrnoFromHRESULT(HRESULT hRes);
529int GetErrnoFromWinsockError(long lWinError);
530FILE *_win_fopen(const char *filename, const char *mode);
531int _win_fclose(FILE *);
532DIR *_win_opendir(const char *dirname);
533struct dirent *_win_readdir(DIR *dirp);
534int _win_closedir(DIR *dirp);
535int _win_open(const char *filename, int oflag, ...);
536#ifdef ENABLE_NLS
537char *_win_bindtextdomain(const char *domainname, const char *dirname);
538#endif
539int _win_chdir(const char *path);
540int _win_close(int fd);
541int _win_creat(const char *path, mode_t mode);
542char *_win_ctime(const time_t *clock);
543char *_win_ctime_r(const time_t *clock, char *buf);
544int _win_fstat(int handle, struct stat *buffer);
545int _win_ftruncate(int fildes, off_t length);
546int _win_truncate(const char *fname, int distance);
547int _win_kill(pid_t pid, int sig);
548int _win_pipe(int *phandles);
549int _win_mkfifo(const char *path, mode_t mode);
550int _win_rmdir(const char *path);
551int _win_access( const char *path, int mode );
552int _win_chmod(const char *filename, int pmode);
553char *realpath(const char *file_name, char *resolved_name);
554long _win_random(void);
555void _win_srandom(unsigned int seed);
556int _win_remove(const char *path);
557int _win_rename(const char *oldname, const char *newname);
558int _win_stat(const char *path, struct stat *buffer);
559int _win_stati64(const char *path, struct _stati64 *buffer);
560long _win_sysconf(int name);
561int _win_unlink(const char *filename);
562int _win_write(int fildes, const void *buf, size_t nbyte);
563int _win_read(int fildes, void *buf, size_t nbyte);
564size_t _win_fwrite(const void *buffer, size_t size, size_t count, FILE *stream);
565size_t _win_fread( void *buffer, size_t size, size_t count, FILE *stream );
566int _win_symlink(const char *path1, const char *path2);
567void *_win_mmap(void *start, size_t len, int access, int flags, int fd,
568 unsigned long long offset);
569int _win_msync(void *start, size_t length, int flags);
570int _win_munmap(void *start, size_t length);
571int _win_lstat(const char *path, struct stat *buf);
572int _win_lstati64(const char *path, struct _stati64 *buf);
573int _win_readlink(const char *path, char *buf, size_t bufsize);
574int _win_accept(int s, struct sockaddr *addr, int *addrlen);
575
576pid_t _win_waitpid(pid_t pid, int *stat_loc, int options);
577int _win_bind(int s, const struct sockaddr *name, int namelen);
578int _win_connect(int s,const struct sockaddr *name, int namelen);
579int _win_getpeername(int s, struct sockaddr *name,
580 int *namelen);
581int _win_getsockname(int s, struct sockaddr *name,
582 int *namelen);
583int _win_getsockopt(int s, int level, int optname, char *optval,
584 int *optlen);
585int _win_listen(int s, int backlog);
586int _win_recv(int s, char *buf, int len, int flags);
587int _win_recvfrom(int s, void *buf, int len, int flags,
588 struct sockaddr *from, int *fromlen);
589int _win_select(int max_fd, fd_set * rfds, fd_set * wfds, fd_set * efds,
590 const struct timeval *tv);
591int _win_send(int s, const char *buf, int len, int flags);
592int _win_sendto(int s, const char *buf, int len, int flags,
593 const struct sockaddr *to, int tolen);
594int _win_setsockopt(int s, int level, int optname, const void *optval,
595 int optlen);
596int _win_shutdown(int s, int how);
597int _win_socket(int af, int type, int protocol);
598int _win_socketpair(int af, int type, int protocol, int socket_vector[2]);
599struct hostent *_win_gethostbyaddr(const char *addr, int len, int type);
600struct hostent *_win_gethostbyname(const char *name);
601struct hostent *gethostbyname2(const char *name, int af);
602char *_win_strerror(int errnum);
603int IsWinNT();
604char *index(const char *s, int c);
605char *_win_strtok_r (char *ptr, const char *sep, char **end);
606
607#if !HAVE_STRNDUP
608char *strndup (const char *s, size_t n);
609#endif
610#if !HAVE_STRNLEN && (!defined(__MINGW64_VERSION_MAJOR) || !defined(_INC_STRING))
611size_t strnlen (const char *str, size_t maxlen);
612#endif
613char *stpcpy(char *dest, const char *src);
614char *strcasestr(const char *haystack_start, const char *needle_start);
615#ifndef __MINGW64_VERSION_MAJOR
616#define strcasecmp(a, b) stricmp(a, b)
617#define strncasecmp(a, b, c) strnicmp(a, b, c)
618#endif
619#ifndef wcscasecmp
620#define wcscasecmp(a, b) wcsicmp(a, b)
621#endif
622#ifndef wcsncasecmp
623#define wcsncasecmp(a, b, c) wcsnicmp(a, b, c)
624#endif
625#ifndef strtok_r /* winpthreads defines it in pthread.h */
626#define strtok_r _win_strtok_r
627#endif
628#endif /* WINDOWS */
629
630#ifndef WINDOWS
631 #define DIR_SEPARATOR '/'
632 #define DIR_SEPARATOR_STR "/"
633 #define PATH_SEPARATOR ':'
634 #define PATH_SEPARATOR_STR ":"
635 #define NEWLINE "\n"
636
637#ifdef ENABLE_NLS
638 #define BINDTEXTDOMAIN(d, n) bindtextdomain(d, n)
639#endif
640 #define CREAT(p, m) creat(p, m)
641 #define PLIBC_CTIME(c) ctime(c)
642 #define CTIME_R(c, b) ctime_r(c, b)
643 #undef FOPEN
644 #define FOPEN(f, m) fopen(f, m)
645 #define FCLOSE(f) fclose(f)
646 #define FTRUNCATE(f, l) ftruncate(f, l)
647 #define TRUNCATE(f, l) truncate(f, l)
648 #define OPENDIR(d) opendir(d)
649 #define CLOSEDIR(d) closedir(d)
650 #define READDIR(d) readdir(d)
651 #define OPEN open
652 #define CHDIR(d) chdir(d)
653 #define CLOSE(f) close(f)
654 #define LSEEK(f, o, w) lseek(f, o, w)
655 #define RMDIR(f) rmdir(f)
656 #define ACCESS(p, m) access(p, m)
657 #define CHMOD(f, p) chmod(f, p)
658 #define FSTAT(h, b) fstat(h, b)
659 #define PLIBC_KILL(p, s) kill(p, s)
660 #define PIPE(h) pipe(h)
661 #define REMOVE(p) remove(p)
662 #define RENAME(o, n) rename(o, n)
663 #define STAT(p, b) stat(p, b)
664 #define STAT64(p, b) stat64(p, b)
665 #define SYSCONF(n) sysconf(n)
666 #define UNLINK(f) unlink(f)
667 #define WRITE(f, b, n) write(f, b, n)
668 #define READ(f, b, n) read(f, b, n)
669 #define GN_FREAD(b, s, c, f) fread(b, s, c, f)
670 #define GN_FWRITE(b, s, c, f) fwrite(b, s, c, f)
671 #define SYMLINK(a, b) symlink(a, b)
672 #define MMAP(s, l, p, f, d, o) mmap(s, l, p, f, d, o)
673 #define MKFIFO(p, m) mkfifo(p, m)
674 #define MSYNC(s, l, f) msync(s, l, f)
675 #define MUNMAP(s, l) munmap(s, l)
676 #define STRERROR(i) strerror(i)
677 #define RANDOM() random()
678 #define SRANDOM(s) srandom(s)
679 #define READLINK(p, b, s) readlink(p, b, s)
680 #define LSTAT(p, b) lstat(p, b)
681 #define LSTAT64(p, b) lstat64(p, b)
682 #define PRINTF printf
683 #define FPRINTF fprintf
684 #define VPRINTF(f, a) vprintf(f, a)
685 #define VFPRINTF(s, f, a) vfprintf(s, f, a)
686 #define VSPRINTF(d, f, a) vsprintf(d, f, a)
687 #define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a)
688 #define _REAL_SNPRINTF snprintf
689 #define SPRINTF sprintf
690 #define VSSCANF(s, f, a) vsscanf(s, f, a)
691 #define SSCANF sscanf
692 #define VFSCANF(s, f, a) vfscanf(s, f, a)
693 #define VSCANF(f, a) vscanf(f, a)
694 #define SCANF scanf
695 #define FSCANF fscanf
696 #define WAITPID(p, s, o) waitpid(p, s, o)
697 #define ACCEPT(s, a, l) accept(s, a, l)
698 #define BIND(s, n, l) bind(s, n, l)
699 #define CONNECT(s, n, l) connect(s, n, l)
700 #define GETPEERNAME(s, n, l) getpeername(s, n, l)
701 #define GETSOCKNAME(s, n, l) getsockname(s, n, l)
702 #define GETSOCKOPT(s, l, o, v, p) getsockopt(s, l, o, v, p)
703 #define LISTEN(s, b) listen(s, b)
704 #define RECV(s, b, l, f) recv(s, b, l, f)
705 #define RECVFROM(s, b, l, f, r, o) recvfrom(s, b, l, f, r, o)
706 #define SELECT(n, r, w, e, t) select(n, r, w, e, t)
707 #define SEND(s, b, l, f) send(s, b, l, f)
708 #define SENDTO(s, b, l, f, o, n) sendto(s, b, l, f, o, n)
709 #define SETSOCKOPT(s, l, o, v, n) setsockopt(s, l, o, v, n)
710 #define SHUTDOWN(s, h) shutdown(s, h)
711 #define SOCKET(a, t, p) socket(a, t, p)
712 #define SOCKETPAIR(a, t, p, v) socketpair(a, t, p, v)
713 #define GETHOSTBYADDR(a, l, t) gethostbyaddr(a, l, t)
714 #define GETHOSTBYNAME(n) gethostbyname(n)
715 #define GETTIMEOFDAY(t, n) gettimeofday(t, n)
716 #define INSQUE(e, p) insque(e, p)
717 #define REMQUE(e) remque(e)
718 #define HSEARCH(i, a) hsearch(i, a)
719 #define HCREATE(n) hcreate(n)
720 #define HDESTROY() hdestroy()
721 #define HSEARCH_R(i, a, r, h) hsearch_r(i, a, r, h)
722 #define HCREATE_R(n, h) hcreate_r(n, h)
723 #define HDESTROY_R(h) hdestroy_r(h)
724 #define TSEARCH(k, r, c) tsearch(k, r, c)
725 #define TFIND(k, r, c) tfind(k, r, c)
726 #define TDELETE(k, r, c) tdelete(k, r, c)
727 #define TWALK(r, a) twalk(r, a)
728 #define TDESTROY(r, f) tdestroy(r, f)
729 #define LFIND(k, b, n, s, c) lfind(k, b, n, s, c)
730 #define LSEARCH(k, b, n, s, c) lsearch(k, b, n, s, c)
731 #define STRUCT_STAT64 struct stat64
732#else
733 #define DIR_SEPARATOR '\\'
734 #define DIR_SEPARATOR_STR "\\"
735 #define PATH_SEPARATOR ';'
736 #define PATH_SEPARATOR_STR ";"
737 #define NEWLINE "\r\n"
738
739#ifdef ENABLE_NLS
740 #define BINDTEXTDOMAIN(d, n) _win_bindtextdomain(d, n)
741#endif
742 #define CREAT(p, m) _win_creat(p, m)
743 #define PLIBC_CTIME(c) _win_ctime(c)
744 #define CTIME_R(c, b) _win_ctime_r(c, b)
745 #define FOPEN(f, m) _win_fopen(f, m)
746 #define FCLOSE(f) _win_fclose(f)
747 #define FTRUNCATE(f, l) _win_ftruncate(f, l)
748 #define TRUNCATE(f, l) _win_truncate(f, l)
749 #define OPENDIR(d) _win_opendir(d)
750 #define CLOSEDIR(d) _win_closedir(d)
751 #define READDIR(d) _win_readdir(d)
752 #define OPEN _win_open
753 #define CHDIR(d) _win_chdir(d)
754 #define CLOSE(f) _win_close(f)
755 #define PLIBC_KILL(p, s) _win_kill(p, s)
756 #define LSEEK(f, o, w) lseek(f, o, w)
757 #define FSTAT(h, b) _win_fstat(h, b)
758 #define RMDIR(f) _win_rmdir(f)
759 #define ACCESS(p, m) _win_access(p, m)
760 #define CHMOD(f, p) _win_chmod(f, p)
761 #define PIPE(h) _win_pipe(h)
762 #define RANDOM() _win_random()
763 #define SRANDOM(s) _win_srandom(s)
764 #define REMOVE(p) _win_remove(p)
765 #define RENAME(o, n) _win_rename(o, n)
766 #define STAT(p, b) _win_stat(p, b)
767 #define STAT64(p, b) _win_stati64(p, b)
768 #define SYSCONF(n) _win_sysconf(n)
769 #define UNLINK(f) _win_unlink(f)
770 #define WRITE(f, b, n) _win_write(f, b, n)
771 #define READ(f, b, n) _win_read(f, b, n)
772 #define GN_FREAD(b, s, c, f) _win_fread(b, s, c, f)
773 #define GN_FWRITE(b, s, c, f) _win_fwrite(b, s, c, f)
774 #define SYMLINK(a, b) _win_symlink(a, b)
775 #define MMAP(s, l, p, f, d, o) _win_mmap(s, l, p, f, d, o)
776 #define MKFIFO(p, m) _win_mkfifo(p, m)
777 #define MSYNC(s, l, f) _win_msync(s, l, f)
778 #define MUNMAP(s, l) _win_munmap(s, l)
779 #define STRERROR(i) _win_strerror(i)
780 #define READLINK(p, b, s) _win_readlink(p, b, s)
781 #define LSTAT(p, b) _win_lstat(p, b)
782 #define LSTAT64(p, b) _win_lstati64(p, b)
783 #define PRINTF printf
784 #define FPRINTF fprintf
785 #define VPRINTF(f, a) vprintf(f, a)
786 #define VFPRINTF(s, f, a) vfprintf(s, f, a)
787 #define VSPRINTF(d, f, a) vsprintf(d, f, a)
788 #define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a)
789 #define _REAL_SNPRINTF snprintf
790 #define SPRINTF sprintf
791 #define VSSCANF(s, f, a) vsscanf(s, f, a)
792 #define SSCANF sscanf
793 #define VFSCANF(s, f, a) vfscanf(s, f, a)
794 #define VSCANF(f, a) vscanf(f, a)
795 #define SCANF scanf
796 #define FSCANF fscanf
797 #define WAITPID(p, s, o) _win_waitpid(p, s, o)
798 #define ACCEPT(s, a, l) _win_accept(s, a, l)
799 #define BIND(s, n, l) _win_bind(s, n, l)
800 #define CONNECT(s, n, l) _win_connect(s, n, l)
801 #define GETPEERNAME(s, n, l) _win_getpeername(s, n, l)
802 #define GETSOCKNAME(s, n, l) _win_getsockname(s, n, l)
803 #define GETSOCKOPT(s, l, o, v, p) _win_getsockopt(s, l, o, v, p)
804 #define LISTEN(s, b) _win_listen(s, b)
805 #define RECV(s, b, l, f) _win_recv(s, b, l, f)
806 #define RECVFROM(s, b, l, f, r, o) _win_recvfrom(s, b, l, f, r, o)
807 #define SELECT(n, r, w, e, t) _win_select(n, r, w, e, t)
808 #define SEND(s, b, l, f) _win_send(s, b, l, f)
809 #define SENDTO(s, b, l, f, o, n) _win_sendto(s, b, l, f, o, n)
810 #define SETSOCKOPT(s, l, o, v, n) _win_setsockopt(s, l, o, v, n)
811 #define SHUTDOWN(s, h) _win_shutdown(s, h)
812 #define SOCKET(a, t, p) _win_socket(a, t, p)
813 #define SOCKETPAIR(a, t, p, v) _win_socketpair(a, t, p, v)
814 #define GETHOSTBYADDR(a, l, t) _win_gethostbyaddr(a, l, t)
815 #define GETHOSTBYNAME(n) _win_gethostbyname(n)
816 #define GETTIMEOFDAY(t, n) gettimeofday(t, n)
817 #define INSQUE(e, p) _win_insque(e, p)
818 #define REMQUE(e) _win_remque(e)
819 #define HSEARCH(i, a) _win_hsearch(i, a)
820 #define HCREATE(n) _win_hcreate(n)
821 #define HDESTROY() _win_hdestroy()
822 #define HSEARCH_R(i, a, r, h) _win_hsearch_r(i, a, r, h)
823 #define HCREATE_R(n, h) _win_hcreate_r(n, h)
824 #define HDESTROY_R(h) _win_hdestroy_r(h)
825 #define TSEARCH(k, r, c) _win_tsearch(k, r, c)
826 #define TFIND(k, r, c) _win_tfind(k, r, c)
827 #define TDELETE(k, r, c) _win_tdelete(k, r, c)
828 #define TWALK(r, a) _win_twalk(r, a)
829 #define TDESTROY(r, f) _win_tdestroy(r, f)
830 #define LFIND(k, b, n, s, c) _win_lfind(k, b, n, s, c)
831 #define LSEARCH(k, b, n, s, c) _win_lsearch(k, b, n, s, c)
832 #define STRUCT_STAT64 struct _stati64
833#endif
834
835/* search.h */
836
837/* Prototype structure for a linked-list data structure.
838 This is the type used by the `insque' and `remque' functions. */
839
840struct PLIBC_SEARCH_QELEM
841 {
842 struct qelem *q_forw;
843 struct qelem *q_back;
844 char q_data[1];
845 };
846
847
848/* Insert ELEM into a doubly-linked list, after PREV. */
849void _win_insque (void *__elem, void *__prev);
850
851/* Unlink ELEM from the doubly-linked list that it is in. */
852void _win_remque (void *__elem);
853
854
855/* For use with hsearch(3). */
856typedef int (*PLIBC_SEARCH__compar_fn_t) (__const void *, __const void *);
857
858typedef PLIBC_SEARCH__compar_fn_t _win_comparison_fn_t;
859
860/* Action which shall be performed in the call the hsearch. */
861typedef enum
862 {
863 PLIBC_SEARCH_FIND,
864 PLIBC_SEARCH_ENTER
865 }
866PLIBC_SEARCH_ACTION;
867
868typedef struct PLIBC_SEARCH_entry
869 {
870 char *key;
871 void *data;
872 }
873PLIBC_SEARCH_ENTRY;
874
875/* The reentrant version has no static variables to maintain the state.
876 Instead the interface of all functions is extended to take an argument
877 which describes the current status. */
878typedef struct _PLIBC_SEARCH_ENTRY
879{
880 unsigned int used;
881 PLIBC_SEARCH_ENTRY entry;
882}
883_PLIBC_SEARCH_ENTRY;
884
885
886/* Family of hash table handling functions. The functions also
887 have reentrant counterparts ending with _r. The non-reentrant
888 functions all work on a signle internal hashing table. */
889
890/* Search for entry matching ITEM.key in internal hash table. If
891 ACTION is `FIND' return found entry or signal error by returning
892 NULL. If ACTION is `ENTER' replace existing data (if any) with
893 ITEM.data. */
894PLIBC_SEARCH_ENTRY *_win_hsearch (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action);
895
896/* Create a new hashing table which will at most contain NEL elements. */
897int _win_hcreate (size_t __nel);
898
899/* Destroy current internal hashing table. */
900void _win_hdestroy (void);
901
902/* Data type for reentrant functions. */
903struct PLIBC_SEARCH_hsearch_data
904 {
905 struct _PLIBC_SEARCH_ENTRY *table;
906 unsigned int size;
907 unsigned int filled;
908 };
909
910/* Reentrant versions which can handle multiple hashing tables at the
911 same time. */
912int _win_hsearch_r (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action, PLIBC_SEARCH_ENTRY **__retval,
913 struct PLIBC_SEARCH_hsearch_data *__htab);
914int _win_hcreate_r (size_t __nel, struct PLIBC_SEARCH_hsearch_data *__htab);
915void _win_hdestroy_r (struct PLIBC_SEARCH_hsearch_data *__htab);
916
917
918/* The tsearch routines are very interesting. They make many
919 assumptions about the compiler. It assumes that the first field
920 in node must be the "key" field, which points to the datum.
921 Everything depends on that. */
922/* For tsearch */
923typedef enum
924{
925 PLIBC_SEARCH_preorder,
926 PLIBC_SEARCH_postorder,
927 PLIBC_SEARCH_endorder,
928 PLIBC_SEARCH_leaf
929}
930PLIBC_SEARCH_VISIT;
931
932/* Search for an entry matching the given KEY in the tree pointed to
933 by *ROOTP and insert a new element if not found. */
934void *_win_tsearch (__const void *__key, void **__rootp,
935 PLIBC_SEARCH__compar_fn_t __compar);
936
937/* Search for an entry matching the given KEY in the tree pointed to
938 by *ROOTP. If no matching entry is available return NULL. */
939void *_win_tfind (__const void *__key, void *__const *__rootp,
940 PLIBC_SEARCH__compar_fn_t __compar);
941
942/* Remove the element matching KEY from the tree pointed to by *ROOTP. */
943void *_win_tdelete (__const void *__restrict __key,
944 void **__restrict __rootp,
945 PLIBC_SEARCH__compar_fn_t __compar);
946
947typedef void (*PLIBC_SEARCH__action_fn_t) (__const void *__nodep, PLIBC_SEARCH_VISIT __value,
948 int __level);
949
950/* Walk through the whole tree and call the ACTION callback for every node
951 or leaf. */
952void _win_twalk (__const void *__root, PLIBC_SEARCH__action_fn_t __action);
953
954/* Callback type for function to free a tree node. If the keys are atomic
955 data this function should do nothing. */
956typedef void (*PLIBC_SEARCH__free_fn_t) (void *__nodep);
957
958/* Destroy the whole tree, call FREEFCT for each node or leaf. */
959void _win_tdestroy (void *__root, PLIBC_SEARCH__free_fn_t __freefct);
960
961
962/* Perform linear search for KEY by comparing by COMPAR in an array
963 [BASE,BASE+NMEMB*SIZE). */
964void *_win_lfind (__const void *__key, __const void *__base,
965 size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t __compar);
966
967/* Perform linear search for KEY by comparing by COMPAR function in
968 array [BASE,BASE+NMEMB*SIZE) and insert entry if not found. */
969void *_win_lsearch (__const void *__key, void *__base,
970 size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t __compar);
971
972
973#ifdef __cplusplus
974}
975#endif
976
977
978#endif //_PLIBC_H_
979
980/* end of plibc.h */
diff --git a/src/json/json.c b/src/json/json.c
index 068214f4e..fe6117c20 100644
--- a/src/json/json.c
+++ b/src/json/json.c
@@ -129,7 +129,7 @@ set_json (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
129 *json = json_loads (value, JSON_REJECT_DUPLICATES, &error); 129 *json = json_loads (value, JSON_REJECT_DUPLICATES, &error);
130 if (NULL == *json) 130 if (NULL == *json)
131 { 131 {
132 FPRINTF (stderr, 132 fprintf (stderr,
133 _ ("Failed to parse JSON in option `%s': %s (%s)\n"), 133 _ ("Failed to parse JSON in option `%s': %s (%s)\n"),
134 option, 134 option,
135 error.text, 135 error.text,
diff --git a/src/namecache/gnunet-namecache.c b/src/namecache/gnunet-namecache.c
index d1927934d..509f86fc0 100644
--- a/src/namecache/gnunet-namecache.c
+++ b/src/namecache/gnunet-namecache.c
@@ -94,8 +94,8 @@ do_shutdown (void *cls)
94 */ 94 */
95static void 95static void
96display_records_from_block (void *cls, 96display_records_from_block (void *cls,
97 unsigned int rd_len, 97 unsigned int rd_len,
98 const struct GNUNET_GNSRECORD_Data *rd) 98 const struct GNUNET_GNSRECORD_Data *rd)
99{ 99{
100 const char *typestring; 100 const char *typestring;
101 char *s; 101 char *s;
@@ -103,33 +103,27 @@ display_records_from_block (void *cls,
103 103
104 if (0 == rd_len) 104 if (0 == rd_len)
105 { 105 {
106 FPRINTF (stdout, 106 fprintf (stdout, _ ("No records found for `%s'"), name);
107 _("No records found for `%s'"),
108 name);
109 return; 107 return;
110 } 108 }
111 FPRINTF (stdout, 109 fprintf (stdout, "%s:\n", name);
112 "%s:\n", 110 for (i = 0; i < rd_len; i++)
113 name);
114 for (i=0;i<rd_len;i++)
115 { 111 {
116 typestring = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type); 112 typestring = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type);
117 s = GNUNET_GNSRECORD_value_to_string (rd[i].record_type, 113 s = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
118 rd[i].data, 114 rd[i].data,
119 rd[i].data_size); 115 rd[i].data_size);
120 if (NULL == s) 116 if (NULL == s)
121 { 117 {
122 FPRINTF (stdout, _("\tCorrupt or unsupported record of type %u\n"), 118 fprintf (stdout,
123 (unsigned int) rd[i].record_type); 119 _ ("\tCorrupt or unsupported record of type %u\n"),
120 (unsigned int) rd[i].record_type);
124 continue; 121 continue;
125 } 122 }
126 FPRINTF (stdout, 123 fprintf (stdout, "\t%s: %s\n", typestring, s);
127 "\t%s: %s\n",
128 typestring,
129 s);
130 GNUNET_free (s); 124 GNUNET_free (s);
131 } 125 }
132 FPRINTF (stdout, "%s", "\n"); 126 fprintf (stdout, "%s", "\n");
133} 127}
134 128
135 129
@@ -140,24 +134,21 @@ display_records_from_block (void *cls,
140 * @param block NULL if not found 134 * @param block NULL if not found
141 */ 135 */
142static void 136static void
143handle_block (void *cls, 137handle_block (void *cls, const struct GNUNET_GNSRECORD_Block *block)
144 const struct GNUNET_GNSRECORD_Block *block)
145{ 138{
146 qe = NULL; 139 qe = NULL;
147 if (NULL == block) 140 if (NULL == block)
148 { 141 {
149 fprintf (stderr, 142 fprintf (stderr, "No matching block found\n");
150 "No matching block found\n");
151 } 143 }
152 else if (GNUNET_OK != 144 else if (GNUNET_OK !=
153 GNUNET_GNSRECORD_block_decrypt (block, 145 GNUNET_GNSRECORD_block_decrypt (block,
154 &pubkey, 146 &pubkey,
155 name, 147 name,
156 &display_records_from_block, 148 &display_records_from_block,
157 NULL)) 149 NULL))
158 { 150 {
159 fprintf (stderr, 151 fprintf (stderr, "Failed to decrypt block!\n");
160 "Failed to decrypt block!\n");
161 } 152 }
162 GNUNET_SCHEDULER_shutdown (); 153 GNUNET_SCHEDULER_shutdown ();
163} 154}
@@ -172,46 +163,36 @@ handle_block (void *cls,
172 * @param cfg configuration 163 * @param cfg configuration
173 */ 164 */
174static void 165static void
175run (void *cls, char *const *args, const char *cfgfile, 166run (void *cls,
167 char *const *args,
168 const char *cfgfile,
176 const struct GNUNET_CONFIGURATION_Handle *cfg) 169 const struct GNUNET_CONFIGURATION_Handle *cfg)
177{ 170{
178 struct GNUNET_HashCode dhash; 171 struct GNUNET_HashCode dhash;
179 172
180 if (NULL == pkey) 173 if (NULL == pkey)
181 { 174 {
182 fprintf (stderr, 175 fprintf (stderr, _ ("You must specify which zone should be accessed\n"));
183 _("You must specify which zone should be accessed\n"));
184 return; 176 return;
185 } 177 }
186 178
187 if (GNUNET_OK != 179 if (GNUNET_OK !=
188 GNUNET_CRYPTO_ecdsa_public_key_from_string (pkey, 180 GNUNET_CRYPTO_ecdsa_public_key_from_string (pkey, strlen (pkey), &pubkey))
189 strlen (pkey),
190 &pubkey))
191 { 181 {
192 fprintf (stderr, 182 fprintf (stderr, _ ("Invalid public key for zone `%s'\n"), pkey);
193 _("Invalid public key for zone `%s'\n"),
194 pkey);
195 GNUNET_SCHEDULER_shutdown (); 183 GNUNET_SCHEDULER_shutdown ();
196 return; 184 return;
197 } 185 }
198 if (NULL == name) 186 if (NULL == name)
199 { 187 {
200 fprintf (stderr, 188 fprintf (stderr, _ ("You must specify a name\n"));
201 _("You must specify a name\n"));
202 return; 189 return;
203 } 190 }
204 191
205 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 192 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
206 NULL);
207 ns = GNUNET_NAMECACHE_connect (cfg); 193 ns = GNUNET_NAMECACHE_connect (cfg);
208 GNUNET_GNSRECORD_query_from_public_key (&pubkey, 194 GNUNET_GNSRECORD_query_from_public_key (&pubkey, name, &dhash);
209 name, 195 qe = GNUNET_NAMECACHE_lookup_block (ns, &dhash, &handle_block, NULL);
210 &dhash);
211 qe = GNUNET_NAMECACHE_lookup_block (ns,
212 &dhash,
213 &handle_block,
214 NULL);
215} 196}
216 197
217 198
@@ -225,36 +206,39 @@ run (void *cls, char *const *args, const char *cfgfile,
225int 206int
226main (int argc, char *const *argv) 207main (int argc, char *const *argv)
227{ 208{
228 struct GNUNET_GETOPT_CommandLineOption options[] = { 209 struct GNUNET_GETOPT_CommandLineOption options[] =
229 GNUNET_GETOPT_option_string ('n', 210 {GNUNET_GETOPT_option_string ('n',
230 "name", 211 "name",
231 "NAME", 212 "NAME",
232 gettext_noop ("name of the record to add/delete/display"), 213 gettext_noop (
233 &name), 214 "name of the record to add/delete/display"),
234 215 &name),
235 GNUNET_GETOPT_option_string ('z', 216
236 "zone", 217 GNUNET_GETOPT_option_string (
237 "PKEY", 218 'z',
238 gettext_noop ("specifies the public key of the zone to look in"), 219 "zone",
239 &pkey), 220 "PKEY",
240 221 gettext_noop ("specifies the public key of the zone to look in"),
241 GNUNET_GETOPT_OPTION_END 222 &pkey),
242 }; 223
224 GNUNET_GETOPT_OPTION_END};
243 225
244 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 226 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
245 return 2; 227 return 2;
246 228
247 GNUNET_log_setup ("gnunet-namecache", "WARNING", NULL); 229 GNUNET_log_setup ("gnunet-namecache", "WARNING", NULL);
248 if (GNUNET_OK != 230 if (GNUNET_OK != GNUNET_PROGRAM_run (argc,
249 GNUNET_PROGRAM_run (argc, argv, "gnunet-namecache", 231 argv,
250 _("GNUnet zone manipulation tool"), 232 "gnunet-namecache",
251 options, 233 _ ("GNUnet zone manipulation tool"),
252 &run, NULL)) 234 options,
235 &run,
236 NULL))
253 { 237 {
254 GNUNET_free ((void*) argv); 238 GNUNET_free ((void *) argv);
255 return 1; 239 return 1;
256 } 240 }
257 GNUNET_free ((void*) argv); 241 GNUNET_free ((void *) argv);
258 return ret; 242 return ret;
259} 243}
260 244
diff --git a/src/namecache/test_plugin_namecache.c b/src/namecache/test_plugin_namecache.c
index 20900a3f6..4939bc4b6 100644
--- a/src/namecache/test_plugin_namecache.c
+++ b/src/namecache/test_plugin_namecache.c
@@ -70,7 +70,7 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
70 GNUNET_asprintf (&libname, "libgnunet_plugin_namecache_%s", plugin_name); 70 GNUNET_asprintf (&libname, "libgnunet_plugin_namecache_%s", plugin_name);
71 if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void*) cfg))) 71 if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void*) cfg)))
72 { 72 {
73 FPRINTF (stderr, "Failed to load plugin `%s'!\n", plugin_name); 73 fprintf (stderr, "Failed to load plugin `%s'!\n", plugin_name);
74 GNUNET_free (libname); 74 GNUNET_free (libname);
75 return NULL; 75 return NULL;
76 } 76 }
@@ -89,7 +89,7 @@ run (void *cls, char *const *args, const char *cfgfile,
89 nsp = load_plugin (cfg); 89 nsp = load_plugin (cfg);
90 if (NULL == nsp) 90 if (NULL == nsp)
91 { 91 {
92 FPRINTF (stderr, 92 fprintf (stderr,
93 "%s", 93 "%s",
94 "Failed to initialize namecache. Database likely not setup, skipping test.\n"); 94 "Failed to initialize namecache. Database likely not setup, skipping test.\n");
95 return; 95 return;
@@ -123,7 +123,7 @@ main (int argc, char *argv[])
123 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, 123 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv,
124 "test-plugin-namecache", "nohelp", options, &run, NULL); 124 "test-plugin-namecache", "nohelp", options, &run, NULL);
125 if (ok != 0) 125 if (ok != 0)
126 FPRINTF (stderr, "Missed some testcases: %d\n", ok); 126 fprintf (stderr, "Missed some testcases: %d\n", ok);
127 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-plugin-namecache-sqlite"); 127 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-plugin-namecache-sqlite");
128 return ok; 128 return ok;
129} 129}
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c
index 5d292525e..2b814206b 100644
--- a/src/namestore/gnunet-namestore.c
+++ b/src/namestore/gnunet-namestore.c
@@ -437,7 +437,7 @@ display_record (const char *rname,
437 } 437 }
438 if (GNUNET_NO == have_record) 438 if (GNUNET_NO == have_record)
439 return; 439 return;
440 FPRINTF (stdout, "%s:\n", rname); 440 fprintf (stdout, "%s:\n", rname);
441 if (NULL != typestring) 441 if (NULL != typestring)
442 type = GNUNET_GNSRECORD_typename_to_number (typestring); 442 type = GNUNET_GNSRECORD_typename_to_number (typestring);
443 else 443 else
@@ -455,7 +455,7 @@ display_record (const char *rname,
455 rd[i].data_size); 455 rd[i].data_size);
456 if (NULL == s) 456 if (NULL == s)
457 { 457 {
458 FPRINTF (stdout, 458 fprintf (stdout,
459 _ ("\tCorrupt or unsupported record of type %u\n"), 459 _ ("\tCorrupt or unsupported record of type %u\n"),
460 (unsigned int) rd[i].record_type); 460 (unsigned int) rd[i].record_type);
461 continue; 461 continue;
@@ -470,7 +470,7 @@ display_record (const char *rname,
470 at.abs_value_us = rd[i].expiration_time; 470 at.abs_value_us = rd[i].expiration_time;
471 ets = GNUNET_STRINGS_absolute_time_to_string (at); 471 ets = GNUNET_STRINGS_absolute_time_to_string (at);
472 } 472 }
473 FPRINTF (stdout, 473 fprintf (stdout,
474 "\t%s: %s (%s)\t%s\t%s\n", 474 "\t%s: %s (%s)\t%s\t%s\n",
475 typestr, 475 typestr,
476 s, 476 s,
@@ -481,7 +481,7 @@ display_record (const char *rname,
481 : ""); 481 : "");
482 GNUNET_free (s); 482 GNUNET_free (s);
483 } 483 }
484 FPRINTF (stdout, "%s", "\n"); 484 fprintf (stdout, "%s", "\n");
485} 485}
486 486
487 487
@@ -564,7 +564,7 @@ static void
564sync_cb (void *cls) 564sync_cb (void *cls)
565{ 565{
566 (void) cls; 566 (void) cls;
567 FPRINTF (stdout, "%s", "Monitor is now in sync.\n"); 567 fprintf (stdout, "%s", "Monitor is now in sync.\n");
568} 568}
569 569
570 570
@@ -577,7 +577,7 @@ static void
577monitor_error_cb (void *cls) 577monitor_error_cb (void *cls)
578{ 578{
579 (void) cls; 579 (void) cls;
580 FPRINTF (stderr, "%s", "Monitor disconnected and out of sync.\n"); 580 fprintf (stderr, "%s", "Monitor disconnected and out of sync.\n");
581} 581}
582 582
583 583
@@ -591,7 +591,7 @@ lookup_error_cb (void *cls)
591{ 591{
592 (void) cls; 592 (void) cls;
593 get_qe = NULL; 593 get_qe = NULL;
594 FPRINTF (stderr, "%s", "Failed to lookup record.\n"); 594 fprintf (stderr, "%s", "Failed to lookup record.\n");
595 test_finished (); 595 test_finished ();
596} 596}
597 597
@@ -761,7 +761,7 @@ reverse_error_cb (void *cls)
761{ 761{
762 (void) cls; 762 (void) cls;
763 reverse_qe = NULL; 763 reverse_qe = NULL;
764 FPRINTF (stdout, "%s.zkey\n", reverse_pkey); 764 fprintf (stdout, "%s.zkey\n", reverse_pkey);
765} 765}
766 766
767 767
@@ -788,9 +788,9 @@ handle_reverse_lookup (void *cls,
788 (void) rd; 788 (void) rd;
789 reverse_qe = NULL; 789 reverse_qe = NULL;
790 if (NULL == label) 790 if (NULL == label)
791 FPRINTF (stdout, "%s\n", reverse_pkey); 791 fprintf (stdout, "%s\n", reverse_pkey);
792 else 792 else
793 FPRINTF (stdout, "%s.%s\n", label, ego_name); 793 fprintf (stdout, "%s.%s\n", label, ego_name);
794 test_finished (); 794 test_finished ();
795} 795}
796 796
@@ -837,7 +837,7 @@ del_monitor (void *cls,
837 del_qe = NULL; 837 del_qe = NULL;
838 if (0 == rd_count) 838 if (0 == rd_count)
839 { 839 {
840 FPRINTF (stderr, 840 fprintf (stderr,
841 _ ( 841 _ (
842 "There are no records under label `%s' that could be deleted.\n"), 842 "There are no records under label `%s' that could be deleted.\n"),
843 label); 843 label);
@@ -879,7 +879,7 @@ del_monitor (void *cls,
879 if (rd_count == rd_left) 879 if (rd_count == rd_left)
880 { 880 {
881 /* nothing got deleted */ 881 /* nothing got deleted */
882 FPRINTF ( 882 fprintf (
883 stderr, 883 stderr,
884 _ ( 884 _ (
885 "There are no records under label `%s' that match the request for deletion.\n"), 885 "There are no records under label `%s' that match the request for deletion.\n"),
diff --git a/src/namestore/test_plugin_namestore.c b/src/namestore/test_plugin_namestore.c
index 0cb99dcb9..b4ed4c70d 100644
--- a/src/namestore/test_plugin_namestore.c
+++ b/src/namestore/test_plugin_namestore.c
@@ -73,7 +73,7 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
73 GNUNET_asprintf (&libname, "libgnunet_plugin_namestore_%s", plugin_name); 73 GNUNET_asprintf (&libname, "libgnunet_plugin_namestore_%s", plugin_name);
74 if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void *) cfg))) 74 if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void *) cfg)))
75 { 75 {
76 FPRINTF (stderr, "Failed to load plugin `%s'!\n", plugin_name); 76 fprintf (stderr, "Failed to load plugin `%s'!\n", plugin_name);
77 GNUNET_free (libname); 77 GNUNET_free (libname);
78 return NULL; 78 return NULL;
79 } 79 }
@@ -159,7 +159,7 @@ run (void *cls,
159 nsp = load_plugin (cfg); 159 nsp = load_plugin (cfg);
160 if (NULL == nsp) 160 if (NULL == nsp)
161 { 161 {
162 FPRINTF ( 162 fprintf (
163 stderr, 163 stderr,
164 "%s", 164 "%s",
165 "Failed to initialize namestore. Database likely not setup, skipping test.\n"); 165 "Failed to initialize namestore. Database likely not setup, skipping test.\n");
@@ -195,7 +195,7 @@ main (int argc, char *argv[])
195 NULL); 195 NULL);
196 GNUNET_DISK_purge_cfg_dir (cfg_name, "GNUNET_TMP"); 196 GNUNET_DISK_purge_cfg_dir (cfg_name, "GNUNET_TMP");
197 if (ok != 0) 197 if (ok != 0)
198 FPRINTF (stderr, "Missed some testcases: %d\n", ok); 198 fprintf (stderr, "Missed some testcases: %d\n", ok);
199 return ok; 199 return ok;
200} 200}
201 201
diff --git a/src/nat-auto/gnunet-nat-auto.c b/src/nat-auto/gnunet-nat-auto.c
index bd8f4ff45..106d60228 100644
--- a/src/nat-auto/gnunet-nat-auto.c
+++ b/src/nat-auto/gnunet-nat-auto.c
@@ -116,14 +116,9 @@ auto_conf_iter (void *cls,
116{ 116{
117 struct GNUNET_CONFIGURATION_Handle *new_cfg = cls; 117 struct GNUNET_CONFIGURATION_Handle *new_cfg = cls;
118 118
119 PRINTF ("%s: %s\n", 119 printf ("%s: %s\n", option, value);
120 option,
121 value);
122 if (NULL != new_cfg) 120 if (NULL != new_cfg)
123 GNUNET_CONFIGURATION_set_value_string (new_cfg, 121 GNUNET_CONFIGURATION_set_value_string (new_cfg, section, option, value);
124 section,
125 option,
126 value);
127} 122}
128 123
129 124
@@ -138,9 +133,9 @@ auto_conf_iter (void *cls,
138 */ 133 */
139static void 134static void
140auto_config_cb (void *cls, 135auto_config_cb (void *cls,
141 const struct GNUNET_CONFIGURATION_Handle *diff, 136 const struct GNUNET_CONFIGURATION_Handle *diff,
142 enum GNUNET_NAT_StatusCode result, 137 enum GNUNET_NAT_StatusCode result,
143 enum GNUNET_NAT_Type type) 138 enum GNUNET_NAT_Type type)
144{ 139{
145 const char *nat_type; 140 const char *nat_type;
146 char unknown_type[64]; 141 char unknown_type[64];
@@ -162,24 +157,21 @@ auto_config_cb (void *cls,
162 nat_type = "NAT but UPNP opened the ports"; 157 nat_type = "NAT but UPNP opened the ports";
163 break; 158 break;
164 default: 159 default:
165 SPRINTF (unknown_type, 160 sprintf (unknown_type, "NAT unknown, type %u", type);
166 "NAT unknown, type %u",
167 type);
168 nat_type = unknown_type; 161 nat_type = unknown_type;
169 break; 162 break;
170 } 163 }
171 164
172 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 165 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
173 "NAT status: %s/%s\n", 166 "NAT status: %s/%s\n",
174 GNUNET_NAT_AUTO_status2string (result), 167 GNUNET_NAT_AUTO_status2string (result),
175 nat_type); 168 nat_type);
176 169
177 if (NULL == diff) 170 if (NULL == diff)
178 return; 171 return;
179 172
180 /* Shortcut: if there are no changes suggested, bail out early. */ 173 /* Shortcut: if there are no changes suggested, bail out early. */
181 if (GNUNET_NO == 174 if (GNUNET_NO == GNUNET_CONFIGURATION_is_dirty (diff))
182 GNUNET_CONFIGURATION_is_dirty (diff))
183 { 175 {
184 test_finished (); 176 test_finished ();
185 return; 177 return;
@@ -190,7 +182,7 @@ auto_config_cb (void *cls,
190 new_cfg = write_cfg ? GNUNET_CONFIGURATION_dup (cfg) : NULL; 182 new_cfg = write_cfg ? GNUNET_CONFIGURATION_dup (cfg) : NULL;
191 183
192 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 184 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
193 _("Suggested configuration changes:\n")); 185 _ ("Suggested configuration changes:\n"));
194 GNUNET_CONFIGURATION_iterate_section_values (diff, 186 GNUNET_CONFIGURATION_iterate_section_values (diff,
195 "nat", 187 "nat",
196 &auto_conf_iter, 188 &auto_conf_iter,
@@ -202,29 +194,22 @@ auto_config_cb (void *cls,
202 { 194 {
203 struct GNUNET_CONFIGURATION_Handle *def_cfg; 195 struct GNUNET_CONFIGURATION_Handle *def_cfg;
204 196
205 GNUNET_CONFIGURATION_set_value_string (new_cfg, 197 GNUNET_CONFIGURATION_set_value_string (new_cfg, "ARM", "CONFIG", NULL);
206 "ARM",
207 "CONFIG",
208 NULL);
209 def_cfg = GNUNET_CONFIGURATION_create (); 198 def_cfg = GNUNET_CONFIGURATION_create ();
210 GNUNET_break (GNUNET_OK == 199 GNUNET_break (GNUNET_OK == GNUNET_CONFIGURATION_load (def_cfg, NULL));
211 GNUNET_CONFIGURATION_load (def_cfg,
212 NULL));
213 if (GNUNET_OK != 200 if (GNUNET_OK !=
214 GNUNET_CONFIGURATION_write_diffs (def_cfg, 201 GNUNET_CONFIGURATION_write_diffs (def_cfg, new_cfg, cfg_file))
215 new_cfg,
216 cfg_file))
217 { 202 {
218 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 203 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
219 _("Failed to write configuration to `%s'\n"), 204 _ ("Failed to write configuration to `%s'\n"),
220 cfg_file); 205 cfg_file);
221 global_ret = 1; 206 global_ret = 1;
222 } 207 }
223 else 208 else
224 { 209 {
225 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 210 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
226 _("Wrote updated configuration to `%s'\n"), 211 _ ("Wrote updated configuration to `%s'\n"),
227 cfg_file); 212 cfg_file);
228 } 213 }
229 GNUNET_CONFIGURATION_destroy (def_cfg); 214 GNUNET_CONFIGURATION_destroy (def_cfg);
230 } 215 }
@@ -243,12 +228,10 @@ auto_config_cb (void *cls,
243 * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code 228 * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
244 */ 229 */
245static void 230static void
246test_report_cb (void *cls, 231test_report_cb (void *cls, enum GNUNET_NAT_StatusCode result)
247 enum GNUNET_NAT_StatusCode result)
248{ 232{
249 nt = NULL; 233 nt = NULL;
250 PRINTF ("NAT test result: %s\n", 234 printf ("NAT test result: %s\n", GNUNET_NAT_AUTO_status2string (result));
251 GNUNET_NAT_AUTO_status2string (result));
252 test_finished (); 235 test_finished ();
253} 236}
254 237
@@ -291,22 +274,18 @@ run (void *cls,
291 cfg_file = cfgfile; 274 cfg_file = cfgfile;
292 cfg = c; 275 cfg = c;
293 276
294 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 277 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
295 NULL);
296 278
297 if (do_auto) 279 if (do_auto)
298 { 280 {
299 ah = GNUNET_NAT_AUTO_autoconfig_start (c, 281 ah = GNUNET_NAT_AUTO_autoconfig_start (c, &auto_config_cb, NULL);
300 &auto_config_cb,
301 NULL);
302 } 282 }
303 283
304 if (use_tcp && use_udp) 284 if (use_tcp && use_udp)
305 { 285 {
306 if (do_auto) 286 if (do_auto)
307 return; 287 return;
308 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 288 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "Cannot use TCP and UDP\n");
309 "Cannot use TCP and UDP\n");
310 global_ret = 1; 289 global_ret = 1;
311 return; 290 return;
312 } 291 }
@@ -319,10 +298,10 @@ run (void *cls,
319 if (NULL != section_name) 298 if (NULL != section_name)
320 { 299 {
321 nt = GNUNET_NAT_AUTO_test_start (c, 300 nt = GNUNET_NAT_AUTO_test_start (c,
322 proto, 301 proto,
323 section_name, 302 section_name,
324 &test_report_cb, 303 &test_report_cb,
325 NULL); 304 NULL);
326 } 305 }
327 test_finished (); 306 test_finished ();
328} 307}
@@ -336,53 +315,47 @@ run (void *cls,
336 * @return 0 on success, -1 on error 315 * @return 0 on success, -1 on error
337 */ 316 */
338int 317int
339main (int argc, 318main (int argc, char *const argv[])
340 char *const argv[])
341{ 319{
342 struct GNUNET_GETOPT_CommandLineOption options[] = { 320 struct GNUNET_GETOPT_CommandLineOption options[] =
343 GNUNET_GETOPT_option_flag ('a', 321 {GNUNET_GETOPT_option_flag ('a',
344 "auto", 322 "auto",
345 gettext_noop ("run autoconfiguration"), 323 gettext_noop ("run autoconfiguration"),
346 &do_auto), 324 &do_auto),
347 325
348 GNUNET_GETOPT_option_string ('S', 326 GNUNET_GETOPT_option_string (
349 "section", 327 'S',
350 "NAME", 328 "section",
351 gettext_noop ("section name providing the configuration for the adapter"), 329 "NAME",
352 &section_name), 330 gettext_noop (
353 331 "section name providing the configuration for the adapter"),
354 GNUNET_GETOPT_option_flag ('t', 332 &section_name),
355 "tcp", 333
356 gettext_noop ("use TCP"), 334 GNUNET_GETOPT_option_flag ('t', "tcp", gettext_noop ("use TCP"), &use_tcp),
357 &use_tcp), 335
358 336 GNUNET_GETOPT_option_flag ('u', "udp", gettext_noop ("use UDP"), &use_udp),
359 GNUNET_GETOPT_option_flag ('u', 337
360 "udp", 338 GNUNET_GETOPT_option_flag (
361 gettext_noop ("use UDP"), 339 'w',
362 &use_udp), 340 "write",
363 341 gettext_noop ("write configuration file (for autoconfiguration)"),
364 GNUNET_GETOPT_option_flag ('w', 342 &write_cfg),
365 "write", 343 GNUNET_GETOPT_OPTION_END};
366 gettext_noop ("write configuration file (for autoconfiguration)"), 344
367 &write_cfg), 345 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
368 GNUNET_GETOPT_OPTION_END
369 };
370
371 if (GNUNET_OK !=
372 GNUNET_STRINGS_get_utf8_args (argc, argv,
373 &argc, &argv))
374 return 2; 346 return 2;
375 if (GNUNET_OK != 347 if (GNUNET_OK !=
376 GNUNET_PROGRAM_run (argc, argv, 348 GNUNET_PROGRAM_run (argc,
377 "gnunet-nat-auto [options]", 349 argv,
378 _("GNUnet NAT traversal autoconfiguration"), 350 "gnunet-nat-auto [options]",
379 options, 351 _ ("GNUnet NAT traversal autoconfiguration"),
352 options,
380 &run, 353 &run,
381 NULL)) 354 NULL))
382 { 355 {
383 global_ret = 1; 356 global_ret = 1;
384 } 357 }
385 GNUNET_free ((void*) argv); 358 GNUNET_free ((void *) argv);
386 return global_ret; 359 return global_ret;
387} 360}
388 361
diff --git a/src/nat-auto/nat_auto_api_test.c b/src/nat-auto/nat_auto_api_test.c
index 1511d91ba..56a2b8d72 100644
--- a/src/nat-auto/nat_auto_api_test.c
+++ b/src/nat-auto/nat_auto_api_test.c
@@ -28,9 +28,10 @@
28#include "gnunet_nat_auto_service.h" 28#include "gnunet_nat_auto_service.h"
29#include "nat-auto.h" 29#include "nat-auto.h"
30 30
31#define LOG(kind,...) GNUNET_log_from (kind, "nat-auto", __VA_ARGS__) 31#define LOG(kind, ...) GNUNET_log_from (kind, "nat-auto", __VA_ARGS__)
32 32
33#define NAT_SERVER_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 33#define NAT_SERVER_TIMEOUT \
34 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
34 35
35/** 36/**
36 * Entry we keep for each incoming connection. 37 * Entry we keep for each incoming connection.
@@ -88,7 +89,6 @@ struct ClientActivity
88 * Handle to overall NAT test. 89 * Handle to overall NAT test.
89 */ 90 */
90 struct GNUNET_NAT_AUTO_Test *h; 91 struct GNUNET_NAT_AUTO_Test *h;
91
92}; 92};
93 93
94 94
@@ -184,9 +184,7 @@ struct GNUNET_NAT_AUTO_Test
184 * @param addrlen actual lenght of the @a addr 184 * @param addrlen actual lenght of the @a addr
185 */ 185 */
186static void 186static void
187reversal_cb (void *cls, 187reversal_cb (void *cls, const struct sockaddr *addr, socklen_t addrlen)
188 const struct sockaddr *addr,
189 socklen_t addrlen)
190{ 188{
191 struct GNUNET_NAT_AUTO_Test *h = cls; 189 struct GNUNET_NAT_AUTO_Test *h = cls;
192 const struct sockaddr_in *sa; 190 const struct sockaddr_in *sa;
@@ -198,11 +196,10 @@ reversal_cb (void *cls,
198 { 196 {
199 LOG (GNUNET_ERROR_TYPE_DEBUG, 197 LOG (GNUNET_ERROR_TYPE_DEBUG,
200 "Received connection reversal request for wrong port\n"); 198 "Received connection reversal request for wrong port\n");
201 return; /* wrong port */ 199 return; /* wrong port */
202 } 200 }
203 /* report success */ 201 /* report success */
204 h->report (h->report_cls, 202 h->report (h->report_cls, GNUNET_NAT_ERROR_SUCCESS);
205 GNUNET_NAT_ERROR_SUCCESS);
206} 203}
207 204
208 205
@@ -220,22 +217,17 @@ do_udp_read (void *cls)
220 const struct GNUNET_SCHEDULER_TaskContext *tc; 217 const struct GNUNET_SCHEDULER_TaskContext *tc;
221 218
222 tc = GNUNET_SCHEDULER_get_task_context (); 219 tc = GNUNET_SCHEDULER_get_task_context ();
223 tst->ltask = 220 tst->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
224 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 221 tst->lsock,
225 tst->lsock, 222 &do_udp_read,
226 &do_udp_read, 223 tst);
227 tst);
228 if ((NULL != tc->write_ready) && 224 if ((NULL != tc->write_ready) &&
229 (GNUNET_NETWORK_fdset_isset (tc->read_ready, 225 (GNUNET_NETWORK_fdset_isset (tc->read_ready, tst->lsock)) &&
230 tst->lsock)) &&
231 (sizeof (data) == 226 (sizeof (data) ==
232 GNUNET_NETWORK_socket_recv (tst->lsock, 227 GNUNET_NETWORK_socket_recv (tst->lsock, &data, sizeof (data))))
233 &data,
234 sizeof (data))))
235 { 228 {
236 if (data == tst->data) 229 if (data == tst->data)
237 tst->report (tst->report_cls, 230 tst->report (tst->report_cls, GNUNET_NAT_ERROR_SUCCESS);
238 GNUNET_NAT_ERROR_SUCCESS);
239 else 231 else
240 LOG (GNUNET_ERROR_TYPE_DEBUG, 232 LOG (GNUNET_ERROR_TYPE_DEBUG,
241 "Received data mismatches expected value\n"); 233 "Received data mismatches expected value\n");
@@ -263,20 +255,14 @@ do_read (void *cls)
263 tc = GNUNET_SCHEDULER_get_task_context (); 255 tc = GNUNET_SCHEDULER_get_task_context ();
264 na->rtask = NULL; 256 na->rtask = NULL;
265 tst = na->h; 257 tst = na->h;
266 GNUNET_CONTAINER_DLL_remove (tst->na_head, 258 GNUNET_CONTAINER_DLL_remove (tst->na_head, tst->na_tail, na);
267 tst->na_tail,
268 na);
269 if ((NULL != tc->write_ready) && 259 if ((NULL != tc->write_ready) &&
270 (GNUNET_NETWORK_fdset_isset (tc->read_ready, 260 (GNUNET_NETWORK_fdset_isset (tc->read_ready, na->sock)) &&
271 na->sock)) &&
272 (sizeof (data) == 261 (sizeof (data) ==
273 GNUNET_NETWORK_socket_recv (na->sock, 262 GNUNET_NETWORK_socket_recv (na->sock, &data, sizeof (data))))
274 &data,
275 sizeof (data))))
276 { 263 {
277 if (data == tst->data) 264 if (data == tst->data)
278 tst->report (tst->report_cls, 265 tst->report (tst->report_cls, GNUNET_NAT_ERROR_SUCCESS);
279 GNUNET_NAT_ERROR_SUCCESS);
280 else 266 else
281 LOG (GNUNET_ERROR_TYPE_DEBUG, 267 LOG (GNUNET_ERROR_TYPE_DEBUG,
282 "Received data does not match expected value\n"); 268 "Received data does not match expected value\n");
@@ -306,28 +292,22 @@ do_accept (void *cls)
306 tst->lsock, 292 tst->lsock,
307 &do_accept, 293 &do_accept,
308 tst); 294 tst);
309 s = GNUNET_NETWORK_socket_accept (tst->lsock, 295 s = GNUNET_NETWORK_socket_accept (tst->lsock, NULL, NULL);
310 NULL,
311 NULL);
312 if (NULL == s) 296 if (NULL == s)
313 { 297 {
314 GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, 298 GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "accept");
315 "accept"); 299 return; /* odd error */
316 return; /* odd error */
317 } 300 }
318 LOG (GNUNET_ERROR_TYPE_DEBUG, 301 LOG (GNUNET_ERROR_TYPE_DEBUG,
319 "Got an inbound connection, waiting for data\n"); 302 "Got an inbound connection, waiting for data\n");
320 wl = GNUNET_new (struct NatActivity); 303 wl = GNUNET_new (struct NatActivity);
321 wl->sock = s; 304 wl->sock = s;
322 wl->h = tst; 305 wl->h = tst;
323 wl->rtask = 306 wl->rtask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
324 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 307 wl->sock,
325 wl->sock, 308 &do_read,
326 &do_read, 309 wl);
327 wl); 310 GNUNET_CONTAINER_DLL_insert (tst->na_head, tst->na_tail, wl);
328 GNUNET_CONTAINER_DLL_insert (tst->na_head,
329 tst->na_tail,
330 wl);
331} 311}
332 312
333 313
@@ -339,15 +319,12 @@ do_accept (void *cls)
339 * @param error error code 319 * @param error error code
340 */ 320 */
341static void 321static void
342mq_error_handler (void *cls, 322mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
343 enum GNUNET_MQ_Error error)
344{ 323{
345 struct ClientActivity *ca = cls; 324 struct ClientActivity *ca = cls;
346 struct GNUNET_NAT_AUTO_Test *tst = ca->h; 325 struct GNUNET_NAT_AUTO_Test *tst = ca->h;
347 326
348 GNUNET_CONTAINER_DLL_remove (tst->ca_head, 327 GNUNET_CONTAINER_DLL_remove (tst->ca_head, tst->ca_tail, ca);
349 tst->ca_tail,
350 ca);
351 GNUNET_MQ_destroy (ca->mq); 328 GNUNET_MQ_destroy (ca->mq);
352 GNUNET_free (ca); 329 GNUNET_free (ca);
353} 330}
@@ -367,7 +344,7 @@ mq_error_handler (void *cls,
367 */ 344 */
368static void 345static void
369addr_cb (void *cls, 346addr_cb (void *cls,
370 void **app_ctx, 347 void **app_ctx,
371 int add_remove, 348 int add_remove,
372 enum GNUNET_NAT_AddressClass ac, 349 enum GNUNET_NAT_AddressClass ac,
373 const struct sockaddr *addr, 350 const struct sockaddr *addr,
@@ -385,15 +362,13 @@ addr_cb (void *cls,
385 if (addrlen != sizeof (struct sockaddr_in)) 362 if (addrlen != sizeof (struct sockaddr_in))
386 { 363 {
387 LOG (GNUNET_ERROR_TYPE_DEBUG, 364 LOG (GNUNET_ERROR_TYPE_DEBUG,
388 "NAT test ignores IPv6 address `%s' returned from NAT library\n", 365 "NAT test ignores IPv6 address `%s' returned from NAT library\n",
389 GNUNET_a2s (addr, 366 GNUNET_a2s (addr, addrlen));
390 addrlen)); 367 return; /* ignore IPv6 here */
391 return; /* ignore IPv6 here */
392 } 368 }
393 LOG (GNUNET_ERROR_TYPE_INFO, 369 LOG (GNUNET_ERROR_TYPE_INFO,
394 "Asking gnunet-nat-server to connect to `%s'\n", 370 "Asking gnunet-nat-server to connect to `%s'\n",
395 GNUNET_a2s (addr, 371 GNUNET_a2s (addr, addrlen));
396 addrlen));
397 372
398 ca = GNUNET_new (struct ClientActivity); 373 ca = GNUNET_new (struct ClientActivity);
399 ca->h = h; 374 ca->h = h;
@@ -406,21 +381,17 @@ addr_cb (void *cls,
406 { 381 {
407 GNUNET_free (ca); 382 GNUNET_free (ca);
408 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 383 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
409 _("Failed to connect to `gnunet-nat-server'\n")); 384 _ ("Failed to connect to `gnunet-nat-server'\n"));
410 return; 385 return;
411 } 386 }
412 GNUNET_CONTAINER_DLL_insert (h->ca_head, 387 GNUNET_CONTAINER_DLL_insert (h->ca_head, h->ca_tail, ca);
413 h->ca_tail,
414 ca);
415 sa = (const struct sockaddr_in *) addr; 388 sa = (const struct sockaddr_in *) addr;
416 env = GNUNET_MQ_msg (msg, 389 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAT_TEST);
417 GNUNET_MESSAGE_TYPE_NAT_TEST);
418 msg->dst_ipv4 = sa->sin_addr.s_addr; 390 msg->dst_ipv4 = sa->sin_addr.s_addr;
419 msg->dport = sa->sin_port; 391 msg->dport = sa->sin_port;
420 msg->data = h->data; 392 msg->data = h->data;
421 msg->is_tcp = htonl ((uint32_t) (h->proto == IPPROTO_TCP)); 393 msg->is_tcp = htonl ((uint32_t) (h->proto == IPPROTO_TCP));
422 GNUNET_MQ_send (ca->mq, 394 GNUNET_MQ_send (ca->mq, env);
423 env);
424} 395}
425 396
426 397
@@ -437,8 +408,7 @@ do_fail (void *cls)
437 struct GNUNET_NAT_AUTO_Test *nh = cls; 408 struct GNUNET_NAT_AUTO_Test *nh = cls;
438 409
439 nh->ttask = NULL; 410 nh->ttask = NULL;
440 nh->report (nh->report_cls, 411 nh->report (nh->report_cls, nh->status);
441 nh->status);
442} 412}
443 413
444 414
@@ -455,30 +425,25 @@ do_fail (void *cls)
455 */ 425 */
456struct GNUNET_NAT_AUTO_Test * 426struct GNUNET_NAT_AUTO_Test *
457GNUNET_NAT_AUTO_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, 427GNUNET_NAT_AUTO_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
458 uint8_t proto, 428 uint8_t proto,
459 const char *section_name, 429 const char *section_name,
460 GNUNET_NAT_TestCallback report, 430 GNUNET_NAT_TestCallback report,
461 void *report_cls) 431 void *report_cls)
462{ 432{
463 struct GNUNET_NAT_AUTO_Test *nh; 433 struct GNUNET_NAT_AUTO_Test *nh;
464 unsigned long long bnd_port; 434 unsigned long long bnd_port;
465 struct sockaddr_in sa; 435 struct sockaddr_in sa;
466 const struct sockaddr *addrs[] = { 436 const struct sockaddr *addrs[] = {(const struct sockaddr *) &sa};
467 (const struct sockaddr *) &sa 437 const socklen_t addrlens[] = {sizeof (sa)};
468 }; 438
469 const socklen_t addrlens[] = { 439 if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
470 sizeof (sa) 440 section_name,
471 }; 441 "PORT",
472 442 &bnd_port)) ||
473 if ( (GNUNET_OK != 443 (bnd_port > 65535))
474 GNUNET_CONFIGURATION_get_value_number (cfg,
475 section_name,
476 "PORT",
477 &bnd_port)) ||
478 (bnd_port > 65535) )
479 { 444 {
480 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 445 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
481 _("Failed to find valid PORT in section `%s'\n"), 446 _ ("Failed to find valid PORT in section `%s'\n"),
482 section_name); 447 section_name);
483 return NULL; 448 return NULL;
484 } 449 }
@@ -499,67 +464,60 @@ GNUNET_NAT_AUTO_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
499 nh->status = GNUNET_NAT_ERROR_SUCCESS; 464 nh->status = GNUNET_NAT_ERROR_SUCCESS;
500 if (0 == bnd_port) 465 if (0 == bnd_port)
501 { 466 {
502 nh->nat 467 nh->nat = GNUNET_NAT_register (cfg,
503 = GNUNET_NAT_register (cfg, 468 section_name,
504 section_name, 469 proto,
505 proto, 470 0,
506 0, NULL, NULL, 471 NULL,
507 &addr_cb, 472 NULL,
508 &reversal_cb, 473 &addr_cb,
509 nh); 474 &reversal_cb,
475 nh);
510 } 476 }
511 else 477 else
512 { 478 {
513 nh->lsock 479 nh->lsock =
514 = GNUNET_NETWORK_socket_create (AF_INET, 480 GNUNET_NETWORK_socket_create (AF_INET,
515 (IPPROTO_UDP == proto) 481 (IPPROTO_UDP == proto) ? SOCK_DGRAM
516 ? SOCK_DGRAM 482 : SOCK_STREAM,
517 : SOCK_STREAM, 483 proto);
518 proto); 484 if ((NULL == nh->lsock) ||
519 if ( (NULL == nh->lsock) || 485 (GNUNET_OK != GNUNET_NETWORK_socket_bind (nh->lsock,
520 (GNUNET_OK != 486 (const struct sockaddr *) &sa,
521 GNUNET_NETWORK_socket_bind (nh->lsock, 487 sizeof (sa))))
522 (const struct sockaddr *) &sa,
523 sizeof (sa))))
524 { 488 {
525 LOG (GNUNET_ERROR_TYPE_ERROR, 489 LOG (GNUNET_ERROR_TYPE_ERROR,
526 _("Failed to create socket bound to `%s' for NAT test: %s\n"), 490 _ ("Failed to create socket bound to `%s' for NAT test: %s\n"),
527 GNUNET_a2s ((const struct sockaddr *) &sa, 491 GNUNET_a2s ((const struct sockaddr *) &sa, sizeof (sa)),
528 sizeof (sa)), 492 strerror (errno));
529 STRERROR (errno));
530 if (NULL != nh->lsock) 493 if (NULL != nh->lsock)
531 { 494 {
532 GNUNET_NETWORK_socket_close (nh->lsock); 495 GNUNET_NETWORK_socket_close (nh->lsock);
533 nh->lsock = NULL; 496 nh->lsock = NULL;
534 } 497 }
535 nh->status = GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR; 498 nh->status = GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR;
536 nh->ttask = GNUNET_SCHEDULER_add_now (&do_fail, 499 nh->ttask = GNUNET_SCHEDULER_add_now (&do_fail, nh);
537 nh);
538 return nh; 500 return nh;
539 } 501 }
540 if (IPPROTO_TCP == proto) 502 if (IPPROTO_TCP == proto)
541 { 503 {
542 GNUNET_break (GNUNET_OK == 504 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_listen (nh->lsock, 5));
543 GNUNET_NETWORK_socket_listen (nh->lsock, 505 nh->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
544 5)); 506 nh->lsock,
545 nh->ltask = 507 &do_accept,
546 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 508 nh);
547 nh->lsock,
548 &do_accept,
549 nh);
550 } 509 }
551 else 510 else
552 { 511 {
553 nh->ltask = 512 nh->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
554 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 513 nh->lsock,
555 nh->lsock, 514 &do_udp_read,
556 &do_udp_read, 515 nh);
557 nh);
558 } 516 }
559 LOG (GNUNET_ERROR_TYPE_INFO, 517 LOG (GNUNET_ERROR_TYPE_INFO,
560 "NAT test listens on port %llu (%s)\n", 518 "NAT test listens on port %llu (%s)\n",
561 bnd_port, 519 bnd_port,
562 (IPPROTO_TCP == proto) ? "tcp" : "udp"); 520 (IPPROTO_TCP == proto) ? "tcp" : "udp");
563 nh->nat = GNUNET_NAT_register (cfg, 521 nh->nat = GNUNET_NAT_register (cfg,
564 section_name, 522 section_name,
565 proto, 523 proto,
@@ -572,7 +530,7 @@ GNUNET_NAT_AUTO_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
572 if (NULL == nh->nat) 530 if (NULL == nh->nat)
573 { 531 {
574 LOG (GNUNET_ERROR_TYPE_INFO, 532 LOG (GNUNET_ERROR_TYPE_INFO,
575 _("NAT test failed to start NAT library\n")); 533 _ ("NAT test failed to start NAT library\n"));
576 if (NULL != nh->ltask) 534 if (NULL != nh->ltask)
577 { 535 {
578 GNUNET_SCHEDULER_cancel (nh->ltask); 536 GNUNET_SCHEDULER_cancel (nh->ltask);
@@ -584,8 +542,7 @@ GNUNET_NAT_AUTO_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
584 nh->lsock = NULL; 542 nh->lsock = NULL;
585 } 543 }
586 nh->status = GNUNET_NAT_ERROR_NAT_REGISTER_FAILED; 544 nh->status = GNUNET_NAT_ERROR_NAT_REGISTER_FAILED;
587 nh->ttask = GNUNET_SCHEDULER_add_now (&do_fail, 545 nh->ttask = GNUNET_SCHEDULER_add_now (&do_fail, nh);
588 nh);
589 return nh; 546 return nh;
590 } 547 }
591 } 548 }
@@ -604,21 +561,16 @@ GNUNET_NAT_AUTO_test_stop (struct GNUNET_NAT_AUTO_Test *tst)
604 struct NatActivity *pos; 561 struct NatActivity *pos;
605 struct ClientActivity *cpos; 562 struct ClientActivity *cpos;
606 563
607 LOG (GNUNET_ERROR_TYPE_DEBUG, 564 LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping NAT test\n");
608 "Stopping NAT test\n");
609 while (NULL != (cpos = tst->ca_head)) 565 while (NULL != (cpos = tst->ca_head))
610 { 566 {
611 GNUNET_CONTAINER_DLL_remove (tst->ca_head, 567 GNUNET_CONTAINER_DLL_remove (tst->ca_head, tst->ca_tail, cpos);
612 tst->ca_tail,
613 cpos);
614 GNUNET_MQ_destroy (cpos->mq); 568 GNUNET_MQ_destroy (cpos->mq);
615 GNUNET_free (cpos); 569 GNUNET_free (cpos);
616 } 570 }
617 while (NULL != (pos = tst->na_head)) 571 while (NULL != (pos = tst->na_head))
618 { 572 {
619 GNUNET_CONTAINER_DLL_remove (tst->na_head, 573 GNUNET_CONTAINER_DLL_remove (tst->na_head, tst->na_tail, pos);
620 tst->na_tail,
621 pos);
622 GNUNET_SCHEDULER_cancel (pos->rtask); 574 GNUNET_SCHEDULER_cancel (pos->rtask);
623 GNUNET_NETWORK_socket_close (pos->sock); 575 GNUNET_NETWORK_socket_close (pos->sock);
624 GNUNET_free (pos); 576 GNUNET_free (pos);
diff --git a/src/nat/gnunet-nat.c b/src/nat/gnunet-nat.c
index 275553203..6c533374e 100644
--- a/src/nat/gnunet-nat.c
+++ b/src/nat/gnunet-nat.c
@@ -120,20 +120,19 @@ test_finished ()
120 */ 120 */
121static void 121static void
122address_cb (void *cls, 122address_cb (void *cls,
123 void **app_ctx, 123 void **app_ctx,
124 int add_remove, 124 int add_remove,
125 enum GNUNET_NAT_AddressClass ac, 125 enum GNUNET_NAT_AddressClass ac,
126 const struct sockaddr *addr, 126 const struct sockaddr *addr,
127 socklen_t addrlen) 127 socklen_t addrlen)
128{ 128{
129 (void) cls; 129 (void) cls;
130 (void) app_ctx; 130 (void) app_ctx;
131 131
132 fprintf (stdout, 132 fprintf (stdout,
133 "%s %s (%d)\n", 133 "%s %s (%d)\n",
134 add_remove ? "+" : "-", 134 add_remove ? "+" : "-",
135 GNUNET_a2s (addr, 135 GNUNET_a2s (addr, addrlen),
136 addrlen),
137 (int) ac); 136 (int) ac);
138} 137}
139 138
@@ -149,13 +148,12 @@ address_cb (void *cls,
149 */ 148 */
150static void 149static void
151reversal_cb (void *cls, 150reversal_cb (void *cls,
152 const struct sockaddr *remote_addr, 151 const struct sockaddr *remote_addr,
153 socklen_t remote_addrlen) 152 socklen_t remote_addrlen)
154{ 153{
155 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 154 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
156 "Connection reversal requested by %s\n", 155 "Connection reversal requested by %s\n",
157 GNUNET_a2s (remote_addr, 156 GNUNET_a2s (remote_addr, remote_addrlen));
158 remote_addrlen));
159} 157}
160 158
161 159
@@ -194,9 +192,9 @@ stun_read_task (void *cls)
194 ssize_t size; 192 ssize_t size;
195 193
196 rtask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 194 rtask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
197 ls, 195 ls,
198 &stun_read_task, 196 &stun_read_task,
199 NULL); 197 NULL);
200 size = GNUNET_NETWORK_socket_recvfrom_amount (ls); 198 size = GNUNET_NETWORK_socket_recvfrom_amount (ls);
201 if (size > 0) 199 if (size > 0)
202 { 200 {
@@ -212,10 +210,10 @@ stun_read_task (void *cls)
212 ssize_t ret; 210 ssize_t ret;
213 211
214 ret = GNUNET_NETWORK_socket_recvfrom (ls, 212 ret = GNUNET_NETWORK_socket_recvfrom (ls,
215 buf, 213 buf,
216 size + 1, 214 size + 1,
217 (struct sockaddr *) &sa, 215 (struct sockaddr *) &sa,
218 &salen); 216 &salen);
219 if (ret != size) 217 if (ret != size)
220 { 218 {
221 GNUNET_break (0); 219 GNUNET_break (0);
@@ -224,10 +222,10 @@ stun_read_task (void *cls)
224 return; 222 return;
225 } 223 }
226 (void) GNUNET_NAT_stun_handle_packet (nh, 224 (void) GNUNET_NAT_stun_handle_packet (nh,
227 (const struct sockaddr *) &sa, 225 (const struct sockaddr *) &sa,
228 salen, 226 salen,
229 buf, 227 buf,
230 ret); 228 ret);
231 } 229 }
232} 230}
233 231
@@ -254,8 +252,7 @@ run (void *cls,
254 252
255 if (use_tcp && use_udp) 253 if (use_tcp && use_udp)
256 { 254 {
257 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 255 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "Cannot use TCP and UDP\n");
258 "Cannot use TCP and UDP\n");
259 global_ret = 1; 256 global_ret = 1;
260 return; 257 return;
261 } 258 }
@@ -265,13 +262,11 @@ run (void *cls,
265 if (use_udp) 262 if (use_udp)
266 proto = IPPROTO_UDP; 263 proto = IPPROTO_UDP;
267 264
268 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 265 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
269 NULL);
270 266
271 if (0 == proto) 267 if (0 == proto)
272 { 268 {
273 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 269 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "Must specify either TCP or UDP\n");
274 "Must specify either TCP or UDP\n");
275 global_ret = 1; 270 global_ret = 1;
276 return; 271 return;
277 } 272 }
@@ -281,28 +276,26 @@ run (void *cls,
281 remote_sa = NULL; 276 remote_sa = NULL;
282 if (NULL != local_addr) 277 if (NULL != local_addr)
283 { 278 {
284 local_len = (socklen_t) GNUNET_STRINGS_parse_socket_addr (local_addr, 279 local_len =
285 &af, 280 (socklen_t) GNUNET_STRINGS_parse_socket_addr (local_addr, &af, &local_sa);
286 &local_sa);
287 if (0 == local_len) 281 if (0 == local_len)
288 { 282 {
289 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 283 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
290 "Invalid socket address `%s'\n", 284 "Invalid socket address `%s'\n",
291 local_addr); 285 local_addr);
292 goto fail_and_shutdown; 286 goto fail_and_shutdown;
293 } 287 }
294 } 288 }
295 289
296 if (NULL != remote_addr) 290 if (NULL != remote_addr)
297 { 291 {
298 remote_len = GNUNET_STRINGS_parse_socket_addr (remote_addr, 292 remote_len =
299 &af, 293 GNUNET_STRINGS_parse_socket_addr (remote_addr, &af, &remote_sa);
300 &remote_sa);
301 if (0 == remote_len) 294 if (0 == remote_len)
302 { 295 {
303 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 296 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
304 "Invalid socket address `%s'\n", 297 "Invalid socket address `%s'\n",
305 remote_addr); 298 remote_addr);
306 goto fail_and_shutdown; 299 goto fail_and_shutdown;
307 } 300 }
308 } 301 }
@@ -312,19 +305,19 @@ run (void *cls,
312 if (NULL == section_name) 305 if (NULL == section_name)
313 section_name = GNUNET_strdup ("undefined"); 306 section_name = GNUNET_strdup ("undefined");
314 nh = GNUNET_NAT_register (c, 307 nh = GNUNET_NAT_register (c,
315 section_name, 308 section_name,
316 proto, 309 proto,
317 1, 310 1,
318 (const struct sockaddr **) &local_sa, 311 (const struct sockaddr **) &local_sa,
319 &local_len, 312 &local_len,
320 &address_cb, 313 &address_cb,
321 (listen_reversal) ? &reversal_cb : NULL, 314 (listen_reversal) ? &reversal_cb : NULL,
322 NULL); 315 NULL);
323 } 316 }
324 else if (listen_reversal) 317 else if (listen_reversal)
325 { 318 {
326 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 319 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
327 "Use of `-W` only effective in combination with `-i`\n"); 320 "Use of `-W` only effective in combination with `-i`\n");
328 goto fail_and_shutdown; 321 goto fail_and_shutdown;
329 } 322 }
330 323
@@ -332,33 +325,32 @@ run (void *cls,
332 { 325 {
333 int ret; 326 int ret;
334 327
335 if ( (NULL == nh) || 328 if ((NULL == nh) || (sizeof (struct sockaddr_in) != local_len))
336 (sizeof (struct sockaddr_in) != local_len) )
337 { 329 {
338 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 330 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
339 "Require IPv4 local address to initiate connection reversal\n"); 331 "Require IPv4 local address to initiate connection reversal\n");
340 goto fail_and_shutdown; 332 goto fail_and_shutdown;
341 } 333 }
342 if (sizeof (struct sockaddr_in) != remote_len) 334 if (sizeof (struct sockaddr_in) != remote_len)
343 { 335 {
344 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 336 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
345 "Require IPv4 reversal target address\n"); 337 "Require IPv4 reversal target address\n");
346 goto fail_and_shutdown; 338 goto fail_and_shutdown;
347 } 339 }
348 GNUNET_assert (AF_INET == local_sa->sa_family); 340 GNUNET_assert (AF_INET == local_sa->sa_family);
349 GNUNET_assert (AF_INET == remote_sa->sa_family); 341 GNUNET_assert (AF_INET == remote_sa->sa_family);
350 ret = GNUNET_NAT_request_reversal (nh, 342 ret = GNUNET_NAT_request_reversal (nh,
351 (const struct sockaddr_in *) local_sa, 343 (const struct sockaddr_in *) local_sa,
352 (const struct sockaddr_in *) remote_sa); 344 (const struct sockaddr_in *) remote_sa);
353 switch (ret) 345 switch (ret)
354 { 346 {
355 case GNUNET_SYSERR: 347 case GNUNET_SYSERR:
356 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 348 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
357 "Connection reversal internal error\n"); 349 "Connection reversal internal error\n");
358 break; 350 break;
359 case GNUNET_NO: 351 case GNUNET_NO:
360 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 352 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
361 "Connection reversal unavailable\n"); 353 "Connection reversal unavailable\n");
362 break; 354 break;
363 case GNUNET_OK: 355 case GNUNET_OK:
364 /* operation in progress */ 356 /* operation in progress */
@@ -371,46 +363,38 @@ run (void *cls,
371 if (NULL == local_addr) 363 if (NULL == local_addr)
372 { 364 {
373 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 365 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
374 "Require local address to support STUN requests\n"); 366 "Require local address to support STUN requests\n");
375 goto fail_and_shutdown; 367 goto fail_and_shutdown;
376 } 368 }
377 if (IPPROTO_UDP != proto) 369 if (IPPROTO_UDP != proto)
378 { 370 {
379 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 371 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "STUN only supported over UDP\n");
380 "STUN only supported over UDP\n");
381 goto fail_and_shutdown; 372 goto fail_and_shutdown;
382 } 373 }
383 ls = GNUNET_NETWORK_socket_create (af, 374 ls = GNUNET_NETWORK_socket_create (af, SOCK_DGRAM, IPPROTO_UDP);
384 SOCK_DGRAM,
385 IPPROTO_UDP);
386 if (NULL == ls) 375 if (NULL == ls)
387 { 376 {
388 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 377 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "Failed to create socket\n");
389 "Failed to create socket\n");
390 goto fail_and_shutdown; 378 goto fail_and_shutdown;
391 } 379 }
392 if (GNUNET_OK != 380 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (ls, local_sa, local_len))
393 GNUNET_NETWORK_socket_bind (ls,
394 local_sa,
395 local_len))
396 { 381 {
397 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 382 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
398 "Failed to bind to %s: %s\n", 383 "Failed to bind to %s: %s\n",
399 GNUNET_a2s (local_sa, 384 GNUNET_a2s (local_sa, local_len),
400 local_len), 385 strerror (errno));
401 STRERROR (errno));
402 goto fail_and_shutdown; 386 goto fail_and_shutdown;
403 } 387 }
404 rtask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 388 rtask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
405 ls, 389 ls,
406 &stun_read_task, 390 &stun_read_task,
407 NULL); 391 NULL);
408 } 392 }
409 GNUNET_free_non_null (remote_sa); 393 GNUNET_free_non_null (remote_sa);
410 GNUNET_free_non_null (local_sa); 394 GNUNET_free_non_null (local_sa);
411 test_finished (); 395 test_finished ();
412 return; 396 return;
413 fail_and_shutdown: 397fail_and_shutdown:
414 global_ret = 1; 398 global_ret = 1;
415 GNUNET_SCHEDULER_shutdown (); 399 GNUNET_SCHEDULER_shutdown ();
416 GNUNET_free_non_null (remote_sa); 400 GNUNET_free_non_null (remote_sa);
@@ -426,66 +410,63 @@ run (void *cls,
426 * @return 0 on success, -1 on error 410 * @return 0 on success, -1 on error
427 */ 411 */
428int 412int
429main (int argc, 413main (int argc, char *const argv[])
430 char *const argv[])
431{ 414{
432 struct GNUNET_GETOPT_CommandLineOption options[] = { 415 struct GNUNET_GETOPT_CommandLineOption options[] = {
433 416
434 GNUNET_GETOPT_option_string ('i', 417 GNUNET_GETOPT_option_string (
435 "in", 418 'i',
436 "ADDRESS", 419 "in",
437 gettext_noop ("which IP and port are we locally using to bind/listen to"), 420 "ADDRESS",
438 &local_addr), 421 gettext_noop ("which IP and port are we locally using to bind/listen to"),
439 422 &local_addr),
440 GNUNET_GETOPT_option_string ('r', 423
441 "remote", 424 GNUNET_GETOPT_option_string (
442 "ADDRESS", 425 'r',
443 gettext_noop ("which remote IP and port should be asked for connection reversal"), 426 "remote",
444 &remote_addr), 427 "ADDRESS",
445 428 gettext_noop (
446 GNUNET_GETOPT_option_string ('S', 429 "which remote IP and port should be asked for connection reversal"),
447 "section", 430 &remote_addr),
448 NULL, 431
449 gettext_noop ("name of configuration section to find additional options, such as manual host punching data"), 432 GNUNET_GETOPT_option_string (
450 &section_name), 433 'S',
434 "section",
435 NULL,
436 gettext_noop (
437 "name of configuration section to find additional options, such as manual host punching data"),
438 &section_name),
451 439
452 GNUNET_GETOPT_option_flag ('s', 440 GNUNET_GETOPT_option_flag ('s',
453 "stun", 441 "stun",
454 gettext_noop ("enable STUN processing"), 442 gettext_noop ("enable STUN processing"),
455 &do_stun), 443 &do_stun),
456 444
457 GNUNET_GETOPT_option_flag ('t', 445 GNUNET_GETOPT_option_flag ('t', "tcp", gettext_noop ("use TCP"), &use_tcp),
458 "tcp",
459 gettext_noop ("use TCP"),
460 &use_tcp),
461 446
462 GNUNET_GETOPT_option_flag ('u', 447 GNUNET_GETOPT_option_flag ('u', "udp", gettext_noop ("use UDP"), &use_udp),
463 "udp",
464 gettext_noop ("use UDP"),
465 &use_udp),
466 448
467 GNUNET_GETOPT_option_flag ('W', 449 GNUNET_GETOPT_option_flag ('W',
468 "watch", 450 "watch",
469 gettext_noop ("watch for connection reversal requests"), 451 gettext_noop (
470 &listen_reversal), 452 "watch for connection reversal requests"),
471 GNUNET_GETOPT_OPTION_END 453 &listen_reversal),
472 }; 454 GNUNET_GETOPT_OPTION_END};
473 455
474 if (GNUNET_OK != 456 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
475 GNUNET_STRINGS_get_utf8_args (argc, argv,
476 &argc, &argv))
477 return 2; 457 return 2;
478 if (GNUNET_OK != 458 if (GNUNET_OK !=
479 GNUNET_PROGRAM_run (argc, argv, 459 GNUNET_PROGRAM_run (argc,
480 "gnunet-nat [options]", 460 argv,
481 _("GNUnet NAT traversal autoconfigure daemon"), 461 "gnunet-nat [options]",
482 options, 462 _ ("GNUnet NAT traversal autoconfigure daemon"),
463 options,
483 &run, 464 &run,
484 NULL)) 465 NULL))
485 { 466 {
486 global_ret = 1; 467 global_ret = 1;
487 } 468 }
488 GNUNET_free ((void*) argv); 469 GNUNET_free ((void *) argv);
489 return global_ret; 470 return global_ret;
490} 471}
491 472
diff --git a/src/nat/gnunet-service-nat_helper.c b/src/nat/gnunet-service-nat_helper.c
index 43ac54adf..cf5038dd7 100644
--- a/src/nat/gnunet-service-nat_helper.c
+++ b/src/nat/gnunet-service-nat_helper.c
@@ -101,12 +101,10 @@ static void
101try_again (struct HelperContext *h) 101try_again (struct HelperContext *h)
102{ 102{
103 GNUNET_assert (NULL == h->server_read_task); 103 GNUNET_assert (NULL == h->server_read_task);
104 h->server_retry_delay 104 h->server_retry_delay = GNUNET_TIME_STD_BACKOFF (h->server_retry_delay);
105 = GNUNET_TIME_STD_BACKOFF (h->server_retry_delay); 105 h->server_read_task = GNUNET_SCHEDULER_add_delayed (h->server_retry_delay,
106 h->server_read_task 106 &restart_nat_server,
107 = GNUNET_SCHEDULER_add_delayed (h->server_retry_delay, 107 h);
108 &restart_nat_server,
109 h);
110} 108}
111 109
112 110
@@ -128,23 +126,16 @@ nat_server_read (void *cls)
128 struct sockaddr_in sin_addr; 126 struct sockaddr_in sin_addr;
129 127
130 h->server_read_task = NULL; 128 h->server_read_task = NULL;
131 memset (mybuf, 129 memset (mybuf, 0, sizeof (mybuf));
132 0, 130 bytes =
133 sizeof (mybuf)); 131 GNUNET_DISK_file_read (h->server_stdout_handle, mybuf, sizeof (mybuf));
134 bytes
135 = GNUNET_DISK_file_read (h->server_stdout_handle,
136 mybuf,
137 sizeof (mybuf));
138 if (bytes < 1) 132 if (bytes < 1)
139 { 133 {
140 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 134 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
141 "Finished reading from server stdout with code: %d\n", 135 "Finished reading from server stdout with code: %d\n",
142 (int) bytes); 136 (int) bytes);
143 if (0 != GNUNET_OS_process_kill (h->server_proc, 137 if (0 != GNUNET_OS_process_kill (h->server_proc, GNUNET_TERM_SIG))
144 GNUNET_TERM_SIG)) 138 GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, "nat", "kill");
145 GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING,
146 "nat",
147 "kill");
148 GNUNET_OS_process_wait (h->server_proc); 139 GNUNET_OS_process_wait (h->server_proc);
149 GNUNET_OS_process_destroy (h->server_proc); 140 GNUNET_OS_process_destroy (h->server_proc);
150 h->server_proc = NULL; 141 h->server_proc = NULL;
@@ -171,44 +162,37 @@ nat_server_read (void *cls)
171 } 162 }
172 163
173 /* construct socket address of sender */ 164 /* construct socket address of sender */
174 memset (&sin_addr, 165 memset (&sin_addr, 0, sizeof (sin_addr));
175 0,
176 sizeof (sin_addr));
177 sin_addr.sin_family = AF_INET; 166 sin_addr.sin_family = AF_INET;
178#if HAVE_SOCKADDR_IN_SIN_LEN 167#if HAVE_SOCKADDR_IN_SIN_LEN
179 sin_addr.sin_len = sizeof (sin_addr); 168 sin_addr.sin_len = sizeof (sin_addr);
180#endif 169#endif
181 if ( (NULL == port_start) || 170 if ((NULL == port_start) || (1 != sscanf (port_start, "%d", &port)) ||
182 (1 != SSCANF (port_start, 171 (-1 == inet_pton (AF_INET, mybuf, &sin_addr.sin_addr)))
183 "%d",
184 &port)) ||
185 (-1 == inet_pton (AF_INET,
186 mybuf,
187 &sin_addr.sin_addr)))
188 { 172 {
189 /* should we restart gnunet-helper-nat-server? */ 173 /* should we restart gnunet-helper-nat-server? */
190 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 174 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
191 _("gnunet-helper-nat-server generated malformed address `%s'\n"), 175 _ (
192 mybuf); 176 "gnunet-helper-nat-server generated malformed address `%s'\n"),
193 h->server_read_task 177 mybuf);
194 = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 178 h->server_read_task =
195 h->server_stdout_handle, 179 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
196 &nat_server_read, 180 h->server_stdout_handle,
197 h); 181 &nat_server_read,
182 h);
198 return; 183 return;
199 } 184 }
200 sin_addr.sin_port = htons ((uint16_t) port); 185 sin_addr.sin_port = htons ((uint16_t) port);
201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
202 "gnunet-helper-nat-server read: %s:%d\n", 187 "gnunet-helper-nat-server read: %s:%d\n",
203 mybuf, 188 mybuf,
204 port); 189 port);
205 h->cb (h->cb_cls, 190 h->cb (h->cb_cls, &sin_addr);
206 &sin_addr); 191 h->server_read_task =
207 h->server_read_task 192 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
208 = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 193 h->server_stdout_handle,
209 h->server_stdout_handle, 194 &nat_server_read,
210 &nat_server_read, 195 h);
211 h);
212} 196}
213 197
214 198
@@ -227,71 +211,59 @@ restart_nat_server (void *cls)
227 211
228 h->server_read_task = NULL; 212 h->server_read_task = NULL;
229 GNUNET_assert (NULL != 213 GNUNET_assert (NULL !=
230 inet_ntop (AF_INET, 214 inet_ntop (AF_INET, &h->internal_address, ia, sizeof (ia)));
231 &h->internal_address,
232 ia,
233 sizeof (ia)));
234 /* Start the server process */ 215 /* Start the server process */
235 binary = GNUNET_OS_get_suid_binary_path (h->cfg, "gnunet-helper-nat-server"); 216 binary = GNUNET_OS_get_suid_binary_path (h->cfg, "gnunet-helper-nat-server");
236 if (GNUNET_YES != 217 if (GNUNET_YES != GNUNET_OS_check_helper_binary (binary, GNUNET_YES, ia))
237 GNUNET_OS_check_helper_binary (binary,
238 GNUNET_YES,
239 ia))
240 { 218 {
241 /* move instantly to max delay, as this is unlikely to be fixed */ 219 /* move instantly to max delay, as this is unlikely to be fixed */
242 h->server_retry_delay 220 h->server_retry_delay = GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD;
243 = GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD;
244 GNUNET_free (binary); 221 GNUNET_free (binary);
245 try_again (h); 222 try_again (h);
246 return; 223 return;
247 } 224 }
248 h->server_stdout 225 h->server_stdout =
249 = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, 226 GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
250 GNUNET_NO, GNUNET_YES);
251 if (NULL == h->server_stdout) 227 if (NULL == h->server_stdout)
252 { 228 {
253 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, 229 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "pipe");
254 "pipe");
255 GNUNET_free (binary); 230 GNUNET_free (binary);
256 try_again (h); 231 try_again (h);
257 return; 232 return;
258 } 233 }
259 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
260 "Starting `%s' at `%s'\n", 235 "Starting `%s' at `%s'\n",
261 "gnunet-helper-nat-server", 236 "gnunet-helper-nat-server",
262 ia); 237 ia);
263 h->server_proc 238 h->server_proc = GNUNET_OS_start_process (GNUNET_NO,
264 = GNUNET_OS_start_process (GNUNET_NO, 239 0,
265 0, 240 NULL,
266 NULL, 241 h->server_stdout,
267 h->server_stdout, 242 NULL,
268 NULL, 243 binary,
269 binary, 244 "gnunet-helper-nat-server",
270 "gnunet-helper-nat-server", 245 ia,
271 ia, 246 NULL);
272 NULL);
273 GNUNET_free (binary); 247 GNUNET_free (binary);
274 if (NULL == h->server_proc) 248 if (NULL == h->server_proc)
275 { 249 {
276 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 250 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
277 _("Failed to start %s\n"), 251 _ ("Failed to start %s\n"),
278 "gnunet-helper-nat-server"); 252 "gnunet-helper-nat-server");
279 GNUNET_DISK_pipe_close (h->server_stdout); 253 GNUNET_DISK_pipe_close (h->server_stdout);
280 h->server_stdout = NULL; 254 h->server_stdout = NULL;
281 try_again (h); 255 try_again (h);
282 return; 256 return;
283 } 257 }
284 /* Close the write end of the read pipe */ 258 /* Close the write end of the read pipe */
285 GNUNET_DISK_pipe_close_end (h->server_stdout, 259 GNUNET_DISK_pipe_close_end (h->server_stdout, GNUNET_DISK_PIPE_END_WRITE);
286 GNUNET_DISK_PIPE_END_WRITE); 260 h->server_stdout_handle =
287 h->server_stdout_handle 261 GNUNET_DISK_pipe_handle (h->server_stdout, GNUNET_DISK_PIPE_END_READ);
288 = GNUNET_DISK_pipe_handle (h->server_stdout, 262 h->server_read_task =
289 GNUNET_DISK_PIPE_END_READ); 263 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
290 h->server_read_task 264 h->server_stdout_handle,
291 = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 265 &nat_server_read,
292 h->server_stdout_handle, 266 h);
293 &nat_server_read,
294 h);
295} 267}
296 268
297 269
@@ -307,9 +279,9 @@ restart_nat_server (void *cls)
307 */ 279 */
308struct HelperContext * 280struct HelperContext *
309GN_start_gnunet_nat_server_ (const struct in_addr *internal_address, 281GN_start_gnunet_nat_server_ (const struct in_addr *internal_address,
310 GN_ReversalCallback cb, 282 GN_ReversalCallback cb,
311 void *cb_cls, 283 void *cb_cls,
312 const struct GNUNET_CONFIGURATION_Handle *cfg) 284 const struct GNUNET_CONFIGURATION_Handle *cfg)
313{ 285{
314 struct HelperContext *h; 286 struct HelperContext *h;
315 287
@@ -344,10 +316,8 @@ GN_stop_gnunet_nat_server_ (struct HelperContext *h)
344 } 316 }
345 if (NULL != h->server_proc) 317 if (NULL != h->server_proc)
346 { 318 {
347 if (0 != GNUNET_OS_process_kill (h->server_proc, 319 if (0 != GNUNET_OS_process_kill (h->server_proc, GNUNET_TERM_SIG))
348 GNUNET_TERM_SIG)) 320 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
349 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
350 "kill");
351 GNUNET_OS_process_wait (h->server_proc); 321 GNUNET_OS_process_wait (h->server_proc);
352 GNUNET_OS_process_destroy (h->server_proc); 322 GNUNET_OS_process_destroy (h->server_proc);
353 h->server_proc = NULL; 323 h->server_proc = NULL;
@@ -379,9 +349,9 @@ GN_stop_gnunet_nat_server_ (struct HelperContext *h)
379 */ 349 */
380int 350int
381GN_request_connection_reversal (const struct in_addr *internal_address, 351GN_request_connection_reversal (const struct in_addr *internal_address,
382 uint16_t internal_port, 352 uint16_t internal_port,
383 const struct in_addr *remote_v4, 353 const struct in_addr *remote_v4,
384 const struct GNUNET_CONFIGURATION_Handle *cfg) 354 const struct GNUNET_CONFIGURATION_Handle *cfg)
385{ 355{
386 char intv4[INET_ADDRSTRLEN]; 356 char intv4[INET_ADDRSTRLEN];
387 char remv4[INET_ADDRSTRLEN]; 357 char remv4[INET_ADDRSTRLEN];
@@ -389,22 +359,14 @@ GN_request_connection_reversal (const struct in_addr *internal_address,
389 struct GNUNET_OS_Process *proc; 359 struct GNUNET_OS_Process *proc;
390 char *binary; 360 char *binary;
391 361
392 if (NULL == inet_ntop (AF_INET, 362 if (NULL == inet_ntop (AF_INET, internal_address, intv4, INET_ADDRSTRLEN))
393 internal_address,
394 intv4,
395 INET_ADDRSTRLEN))
396 { 363 {
397 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 364 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
398 "inet_ntop");
399 return GNUNET_SYSERR; 365 return GNUNET_SYSERR;
400 } 366 }
401 if (NULL == inet_ntop (AF_INET, 367 if (NULL == inet_ntop (AF_INET, remote_v4, remv4, INET_ADDRSTRLEN))
402 remote_v4,
403 remv4,
404 INET_ADDRSTRLEN))
405 { 368 {
406 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 369 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
407 "inet_ntop");
408 return GNUNET_SYSERR; 370 return GNUNET_SYSERR;
409 } 371 }
410 GNUNET_snprintf (port_as_string, 372 GNUNET_snprintf (port_as_string,
@@ -412,23 +374,22 @@ GN_request_connection_reversal (const struct in_addr *internal_address,
412 "%d", 374 "%d",
413 internal_port); 375 internal_port);
414 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 376 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
415 "Running gnunet-helper-nat-client %s %s %u\n", 377 "Running gnunet-helper-nat-client %s %s %u\n",
416 intv4, 378 intv4,
417 remv4, 379 remv4,
418 internal_port); 380 internal_port);
419 binary = GNUNET_OS_get_suid_binary_path (cfg, "gnunet-helper-nat-client"); 381 binary = GNUNET_OS_get_suid_binary_path (cfg, "gnunet-helper-nat-client");
420 proc 382 proc = GNUNET_OS_start_process (GNUNET_NO,
421 = GNUNET_OS_start_process (GNUNET_NO, 383 0,
422 0, 384 NULL,
423 NULL, 385 NULL,
424 NULL, 386 NULL,
425 NULL, 387 binary,
426 binary, 388 "gnunet-helper-nat-client",
427 "gnunet-helper-nat-client", 389 intv4,
428 intv4, 390 remv4,
429 remv4, 391 port_as_string,
430 port_as_string, 392 NULL);
431 NULL);
432 GNUNET_free (binary); 393 GNUNET_free (binary);
433 if (NULL == proc) 394 if (NULL == proc)
434 return GNUNET_SYSERR; 395 return GNUNET_SYSERR;
diff --git a/src/nat/gnunet-service-nat_mini.c b/src/nat/gnunet-service-nat_mini.c
index c156d0eb0..375188ff2 100644
--- a/src/nat/gnunet-service-nat_mini.c
+++ b/src/nat/gnunet-service-nat_mini.c
@@ -29,7 +29,7 @@
29#include "gnunet-service-nat_mini.h" 29#include "gnunet-service-nat_mini.h"
30#include "nat.h" 30#include "nat.h"
31 31
32#define LOG(kind,...) GNUNET_log_from (kind, "nat", __VA_ARGS__) 32#define LOG(kind, ...) GNUNET_log_from (kind, "nat", __VA_ARGS__)
33 33
34/** 34/**
35 * How long do we give upnpc to create a mapping? 35 * How long do we give upnpc to create a mapping?
@@ -39,12 +39,14 @@
39/** 39/**
40 * How long do we give upnpc to remove a mapping? 40 * How long do we give upnpc to remove a mapping?
41 */ 41 */
42#define UNMAP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) 42#define UNMAP_TIMEOUT \
43 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
43 44
44/** 45/**
45 * How often do we check for changes in the mapping? 46 * How often do we check for changes in the mapping?
46 */ 47 */
47#define MAP_REFRESH_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) 48#define MAP_REFRESH_FREQ \
49 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
48 50
49 51
50/* ************************* external-ip calling ************************ */ 52/* ************************* external-ip calling ************************ */
@@ -117,30 +119,27 @@ read_external_ipv4 (void *cls)
117 119
118 eh->task = NULL; 120 eh->task = NULL;
119 ret = GNUNET_DISK_file_read (eh->r, 121 ret = GNUNET_DISK_file_read (eh->r,
120 &eh->buf[eh->off], 122 &eh->buf[eh->off],
121 sizeof (eh->buf) - eh->off); 123 sizeof (eh->buf) - eh->off);
122 if (ret > 0) 124 if (ret > 0)
123 { 125 {
124 /* try to read more */ 126 /* try to read more */
125 eh->off += ret; 127 eh->off += ret;
126 eh->task 128 eh->task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
127 = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 129 eh->r,
128 eh->r, 130 &read_external_ipv4,
129 &read_external_ipv4, 131 eh);
130 eh);
131 return; 132 return;
132 } 133 }
133 eh->ret = GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_OUTPUT_INVALID; 134 eh->ret = GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_OUTPUT_INVALID;
134 if ( (eh->off > 7) && 135 if ((eh->off > 7) && (eh->buf[eh->off - 1] == '\n'))
135 (eh->buf[eh->off - 1] == '\n') )
136 { 136 {
137 eh->buf[eh->off - 1] = '\0'; 137 eh->buf[eh->off - 1] = '\0';
138 if (1 == inet_pton (AF_INET, 138 if (1 == inet_pton (AF_INET, eh->buf, &addr))
139 eh->buf,
140 &addr))
141 { 139 {
142 if (0 == addr.s_addr) 140 if (0 == addr.s_addr)
143 eh->ret = GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID; /* got 0.0.0.0 */ 141 eh->ret =
142 GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID; /* got 0.0.0.0 */
144 else 143 else
145 eh->ret = GNUNET_NAT_ERROR_SUCCESS; 144 eh->ret = GNUNET_NAT_ERROR_SUCCESS;
146 } 145 }
@@ -163,9 +162,7 @@ signal_external_ip_error (void *cls)
163 struct GNUNET_NAT_ExternalHandle *eh = cls; 162 struct GNUNET_NAT_ExternalHandle *eh = cls;
164 163
165 eh->task = NULL; 164 eh->task = NULL;
166 eh->cb (eh->cb_cls, 165 eh->cb (eh->cb_cls, NULL, eh->ret);
167 NULL,
168 eh->ret);
169 GNUNET_free (eh); 166 GNUNET_free (eh);
170} 167}
171 168
@@ -178,8 +175,7 @@ signal_external_ip_error (void *cls)
178 * @return handle for cancellation (can only be used until @a cb is called), never NULL 175 * @return handle for cancellation (can only be used until @a cb is called), never NULL
179 */ 176 */
180struct GNUNET_NAT_ExternalHandle * 177struct GNUNET_NAT_ExternalHandle *
181GNUNET_NAT_mini_get_external_ipv4_ (GNUNET_NAT_IPCallback cb, 178GNUNET_NAT_mini_get_external_ipv4_ (GNUNET_NAT_IPCallback cb, void *cb_cls)
182 void *cb_cls)
183{ 179{
184 struct GNUNET_NAT_ExternalHandle *eh; 180 struct GNUNET_NAT_ExternalHandle *eh;
185 181
@@ -188,56 +184,43 @@ GNUNET_NAT_mini_get_external_ipv4_ (GNUNET_NAT_IPCallback cb,
188 eh->cb_cls = cb_cls; 184 eh->cb_cls = cb_cls;
189 eh->ret = GNUNET_NAT_ERROR_SUCCESS; 185 eh->ret = GNUNET_NAT_ERROR_SUCCESS;
190 if (GNUNET_SYSERR == 186 if (GNUNET_SYSERR ==
191 GNUNET_OS_check_helper_binary ("external-ip", 187 GNUNET_OS_check_helper_binary ("external-ip", GNUNET_NO, NULL))
192 GNUNET_NO,
193 NULL))
194 { 188 {
195 LOG (GNUNET_ERROR_TYPE_INFO, 189 LOG (GNUNET_ERROR_TYPE_INFO, _ ("`external-ip' command not found\n"));
196 _("`external-ip' command not found\n"));
197 eh->ret = GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND; 190 eh->ret = GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND;
198 eh->task = GNUNET_SCHEDULER_add_now (&signal_external_ip_error, 191 eh->task = GNUNET_SCHEDULER_add_now (&signal_external_ip_error, eh);
199 eh);
200 return eh; 192 return eh;
201 } 193 }
202 LOG (GNUNET_ERROR_TYPE_DEBUG, 194 LOG (GNUNET_ERROR_TYPE_DEBUG,
203 "Running `external-ip' to determine our external IP\n"); 195 "Running `external-ip' to determine our external IP\n");
204 eh->opipe = GNUNET_DISK_pipe (GNUNET_YES, 196 eh->opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
205 GNUNET_YES,
206 GNUNET_NO,
207 GNUNET_YES);
208 if (NULL == eh->opipe) 197 if (NULL == eh->opipe)
209 { 198 {
210 eh->ret = GNUNET_NAT_ERROR_IPC_FAILURE; 199 eh->ret = GNUNET_NAT_ERROR_IPC_FAILURE;
211 eh->task = GNUNET_SCHEDULER_add_now (&signal_external_ip_error, 200 eh->task = GNUNET_SCHEDULER_add_now (&signal_external_ip_error, eh);
212 eh);
213 return eh; 201 return eh;
214 } 202 }
215 eh->eip = 203 eh->eip = GNUNET_OS_start_process (GNUNET_NO,
216 GNUNET_OS_start_process (GNUNET_NO, 204 0,
217 0, 205 NULL,
218 NULL, 206 eh->opipe,
219 eh->opipe, 207 NULL,
220 NULL, 208 "external-ip",
221 "external-ip", 209 "external-ip",
222 "external-ip", 210 NULL);
223 NULL);
224 if (NULL == eh->eip) 211 if (NULL == eh->eip)
225 { 212 {
226 GNUNET_DISK_pipe_close (eh->opipe); 213 GNUNET_DISK_pipe_close (eh->opipe);
227 eh->ret = GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED; 214 eh->ret = GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED;
228 eh->task = GNUNET_SCHEDULER_add_now (&signal_external_ip_error, 215 eh->task = GNUNET_SCHEDULER_add_now (&signal_external_ip_error, eh);
229 eh);
230 return eh; 216 return eh;
231 } 217 }
232 GNUNET_DISK_pipe_close_end (eh->opipe, 218 GNUNET_DISK_pipe_close_end (eh->opipe, GNUNET_DISK_PIPE_END_WRITE);
233 GNUNET_DISK_PIPE_END_WRITE); 219 eh->r = GNUNET_DISK_pipe_handle (eh->opipe, GNUNET_DISK_PIPE_END_READ);
234 eh->r = GNUNET_DISK_pipe_handle (eh->opipe, 220 eh->task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
235 GNUNET_DISK_PIPE_END_READ); 221 eh->r,
236 eh->task 222 &read_external_ipv4,
237 = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 223 eh);
238 eh->r,
239 &read_external_ipv4,
240 eh);
241 return eh; 224 return eh;
242} 225}
243 226
@@ -252,10 +235,8 @@ GNUNET_NAT_mini_get_external_ipv4_cancel_ (struct GNUNET_NAT_ExternalHandle *eh)
252{ 235{
253 if (NULL != eh->eip) 236 if (NULL != eh->eip)
254 { 237 {
255 (void) GNUNET_OS_process_kill (eh->eip, 238 (void) GNUNET_OS_process_kill (eh->eip, SIGKILL);
256 SIGKILL); 239 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (eh->eip));
257 GNUNET_break (GNUNET_OK ==
258 GNUNET_OS_process_wait (eh->eip));
259 GNUNET_OS_process_destroy (eh->eip); 240 GNUNET_OS_process_destroy (eh->eip);
260 } 241 }
261 if (NULL != eh->opipe) 242 if (NULL != eh->opipe)
@@ -336,7 +317,6 @@ struct GNUNET_NAT_MiniHandle
336 * Which port are we mapping? 317 * Which port are we mapping?
337 */ 318 */
338 uint16_t port; 319 uint16_t port;
339
340}; 320};
341 321
342 322
@@ -356,8 +336,7 @@ do_refresh (void *cls);
356 * @param line line of output, NULL at the end 336 * @param line line of output, NULL at the end
357 */ 337 */
358static void 338static void
359process_map_output (void *cls, 339process_map_output (void *cls, const char *line);
360 const char *line);
361 340
362 341
363/** 342/**
@@ -370,26 +349,22 @@ run_upnpc_r (struct GNUNET_NAT_MiniHandle *mini)
370{ 349{
371 char pstr[6]; 350 char pstr[6];
372 351
373 GNUNET_snprintf (pstr, 352 GNUNET_snprintf (pstr, sizeof (pstr), "%u", (unsigned int) mini->port);
374 sizeof (pstr), 353 mini->map_cmd = GNUNET_OS_command_run (&process_map_output,
375 "%u", 354 mini,
376 (unsigned int) mini->port); 355 MAP_TIMEOUT,
377 mini->map_cmd 356 "upnpc",
378 = GNUNET_OS_command_run (&process_map_output, 357 "upnpc",
379 mini, 358 "-r",
380 MAP_TIMEOUT, 359 pstr,
381 "upnpc", 360 mini->is_tcp ? "tcp" : "udp",
382 "upnpc", 361 NULL);
383 "-r",
384 pstr,
385 mini->is_tcp ? "tcp" : "udp",
386 NULL);
387 if (NULL == mini->map_cmd) 362 if (NULL == mini->map_cmd)
388 { 363 {
389 mini->ac (mini->ac_cls, 364 mini->ac (mini->ac_cls,
390 GNUNET_SYSERR, 365 GNUNET_SYSERR,
391 NULL, 366 NULL,
392 0, 367 0,
393 GNUNET_NAT_ERROR_UPNPC_FAILED); 368 GNUNET_NAT_ERROR_UPNPC_FAILED);
394 return; 369 return;
395 } 370 }
@@ -404,8 +379,7 @@ run_upnpc_r (struct GNUNET_NAT_MiniHandle *mini)
404 * @param line line of output, NULL at the end 379 * @param line line of output, NULL at the end
405 */ 380 */
406static void 381static void
407process_refresh_output (void *cls, 382process_refresh_output (void *cls, const char *line)
408 const char *line)
409{ 383{
410 struct GNUNET_NAT_MiniHandle *mini = cls; 384 struct GNUNET_NAT_MiniHandle *mini = cls;
411 char pstr[9]; 385 char pstr[9];
@@ -434,31 +408,28 @@ process_refresh_output (void *cls,
434 return; 408 return;
435 } 409 }
436 if (! mini->did_map) 410 if (! mini->did_map)
437 return; /* never mapped, won't find our mapping anyway */ 411 return; /* never mapped, won't find our mapping anyway */
438 412
439 /* we're looking for output of the form: 413 /* we're looking for output of the form:
440 * "ExternalIPAddress = 12.134.41.124" */ 414 * "ExternalIPAddress = 12.134.41.124" */
441 415
442 s = strstr (line, 416 s = strstr (line, "ExternalIPAddress = ");
443 "ExternalIPAddress = ");
444 if (NULL != s) 417 if (NULL != s)
445 { 418 {
446 s += strlen ("ExternalIPAddress = "); 419 s += strlen ("ExternalIPAddress = ");
447 if (1 != inet_pton (AF_INET, 420 if (1 != inet_pton (AF_INET, s, &exip))
448 s, 421 return; /* skip */
449 &exip))
450 return; /* skip */
451 if (exip.s_addr == mini->current_addr.sin_addr.s_addr) 422 if (exip.s_addr == mini->current_addr.sin_addr.s_addr)
452 return; /* no change */ 423 return; /* no change */
453 /* update mapping */ 424 /* update mapping */
454 mini->ac (mini->ac_cls, 425 mini->ac (mini->ac_cls,
455 GNUNET_NO, 426 GNUNET_NO,
456 (const struct sockaddr *) &mini->current_addr, 427 (const struct sockaddr *) &mini->current_addr,
457 sizeof (mini->current_addr), 428 sizeof (mini->current_addr),
458 GNUNET_NAT_ERROR_SUCCESS); 429 GNUNET_NAT_ERROR_SUCCESS);
459 mini->current_addr.sin_addr = exip; 430 mini->current_addr.sin_addr = exip;
460 mini->ac (mini->ac_cls, 431 mini->ac (mini->ac_cls,
461 GNUNET_YES, 432 GNUNET_YES,
462 (const struct sockaddr *) &mini->current_addr, 433 (const struct sockaddr *) &mini->current_addr,
463 sizeof (mini->current_addr), 434 sizeof (mini->current_addr),
464 GNUNET_NAT_ERROR_SUCCESS); 435 GNUNET_NAT_ERROR_SUCCESS);
@@ -475,32 +446,29 @@ process_refresh_output (void *cls,
475 * "%s TCP PORT->STRING:OURPORT *" or 446 * "%s TCP PORT->STRING:OURPORT *" or
476 * "%s UDP PORT->STRING:OURPORT *" 447 * "%s UDP PORT->STRING:OURPORT *"
477 */ 448 */
478 GNUNET_snprintf (pstr, 449 GNUNET_snprintf (pstr, sizeof (pstr), ":%u ", mini->port);
479 sizeof (pstr),
480 ":%u ",
481 mini->port);
482 if (NULL == (s = strstr (line, "->"))) 450 if (NULL == (s = strstr (line, "->")))
483 return; /* skip */ 451 return; /* skip */
484 if (NULL == strstr (s, pstr)) 452 if (NULL == strstr (s, pstr))
485 return; /* skip */ 453 return; /* skip */
486 if (1 != 454 if (1 != sscanf (line,
487 SSCANF (line, 455 (mini->is_tcp) ? "%*u TCP %u->%*s:%*u %*s"
488 (mini->is_tcp) ? "%*u TCP %u->%*s:%*u %*s" : 456 : "%*u UDP %u->%*s:%*u %*s",
489 "%*u UDP %u->%*s:%*u %*s", &nport)) 457 &nport))
490 return; /* skip */ 458 return; /* skip */
491 mini->found = GNUNET_YES; 459 mini->found = GNUNET_YES;
492 if (nport == ntohs (mini->current_addr.sin_port)) 460 if (nport == ntohs (mini->current_addr.sin_port))
493 return; /* no change */ 461 return; /* no change */
494 462
495 /* external port changed, update mapping */ 463 /* external port changed, update mapping */
496 mini->ac (mini->ac_cls, 464 mini->ac (mini->ac_cls,
497 GNUNET_NO, 465 GNUNET_NO,
498 (const struct sockaddr *) &mini->current_addr, 466 (const struct sockaddr *) &mini->current_addr,
499 sizeof (mini->current_addr), 467 sizeof (mini->current_addr),
500 GNUNET_NAT_ERROR_SUCCESS); 468 GNUNET_NAT_ERROR_SUCCESS);
501 mini->current_addr.sin_port = htons ((uint16_t) nport); 469 mini->current_addr.sin_port = htons ((uint16_t) nport);
502 mini->ac (mini->ac_cls, 470 mini->ac (mini->ac_cls,
503 GNUNET_YES, 471 GNUNET_YES,
504 (const struct sockaddr *) &mini->current_addr, 472 (const struct sockaddr *) &mini->current_addr,
505 sizeof (mini->current_addr), 473 sizeof (mini->current_addr),
506 GNUNET_NAT_ERROR_SUCCESS); 474 GNUNET_NAT_ERROR_SUCCESS);
@@ -518,10 +486,8 @@ do_refresh (void *cls)
518 struct GNUNET_NAT_MiniHandle *mini = cls; 486 struct GNUNET_NAT_MiniHandle *mini = cls;
519 int ac; 487 int ac;
520 488
521 mini->refresh_task 489 mini->refresh_task =
522 = GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ, 490 GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ, &do_refresh, mini);
523 &do_refresh,
524 mini);
525 LOG (GNUNET_ERROR_TYPE_DEBUG, 491 LOG (GNUNET_ERROR_TYPE_DEBUG,
526 "Running `upnpc' to check if our mapping still exists\n"); 492 "Running `upnpc' to check if our mapping still exists\n");
527 mini->found = GNUNET_NO; 493 mini->found = GNUNET_NO;
@@ -540,19 +506,18 @@ do_refresh (void *cls)
540 mini->refresh_cmd = NULL; 506 mini->refresh_cmd = NULL;
541 ac = GNUNET_YES; 507 ac = GNUNET_YES;
542 } 508 }
543 mini->refresh_cmd 509 mini->refresh_cmd = GNUNET_OS_command_run (&process_refresh_output,
544 = GNUNET_OS_command_run (&process_refresh_output, 510 mini,
545 mini, 511 MAP_TIMEOUT,
546 MAP_TIMEOUT, 512 "upnpc",
547 "upnpc", 513 "upnpc",
548 "upnpc", 514 "-l",
549 "-l", 515 NULL);
550 NULL);
551 if (GNUNET_YES == ac) 516 if (GNUNET_YES == ac)
552 mini->ac (mini->ac_cls, 517 mini->ac (mini->ac_cls,
553 GNUNET_SYSERR, 518 GNUNET_SYSERR,
554 NULL, 519 NULL,
555 0, 520 0,
556 GNUNET_NAT_ERROR_UPNPC_TIMEOUT); 521 GNUNET_NAT_ERROR_UPNPC_TIMEOUT);
557} 522}
558 523
@@ -564,8 +529,7 @@ do_refresh (void *cls)
564 * @param line line of output, NULL at the end 529 * @param line line of output, NULL at the end
565 */ 530 */
566static void 531static void
567process_map_output (void *cls, 532process_map_output (void *cls, const char *line)
568 const char *line)
569{ 533{
570 struct GNUNET_NAT_MiniHandle *mini = cls; 534 struct GNUNET_NAT_MiniHandle *mini = cls;
571 const char *ipaddr; 535 const char *ipaddr;
@@ -581,13 +545,11 @@ process_map_output (void *cls,
581 mini->ac (mini->ac_cls, 545 mini->ac (mini->ac_cls,
582 GNUNET_SYSERR, 546 GNUNET_SYSERR,
583 NULL, 547 NULL,
584 0, 548 0,
585 GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED); 549 GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED);
586 if (NULL == mini->refresh_task) 550 if (NULL == mini->refresh_task)
587 mini->refresh_task 551 mini->refresh_task =
588 = GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ, 552 GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ, &do_refresh, mini);
589 &do_refresh,
590 mini);
591 return; 553 return;
592 } 554 }
593 /* 555 /*
@@ -597,18 +559,16 @@ process_map_output (void *cls,
597 */ 559 */
598 if ((NULL == (ipaddr = strstr (line, " "))) || 560 if ((NULL == (ipaddr = strstr (line, " "))) ||
599 (NULL == (pstr = strstr (ipaddr, ":"))) || 561 (NULL == (pstr = strstr (ipaddr, ":"))) ||
600 (1 != SSCANF (pstr + 1, "%u", &port))) 562 (1 != sscanf (pstr + 1, "%u", &port)))
601 { 563 {
602 return; /* skip line */ 564 return; /* skip line */
603 } 565 }
604 ipa = GNUNET_strdup (ipaddr + 1); 566 ipa = GNUNET_strdup (ipaddr + 1);
605 strstr (ipa, ":")[0] = '\0'; 567 strstr (ipa, ":")[0] = '\0';
606 if (1 != inet_pton (AF_INET, 568 if (1 != inet_pton (AF_INET, ipa, &mini->current_addr.sin_addr))
607 ipa,
608 &mini->current_addr.sin_addr))
609 { 569 {
610 GNUNET_free (ipa); 570 GNUNET_free (ipa);
611 return; /* skip line */ 571 return; /* skip line */
612 } 572 }
613 GNUNET_free (ipa); 573 GNUNET_free (ipa);
614 574
@@ -619,7 +579,7 @@ process_map_output (void *cls,
619#endif 579#endif
620 mini->did_map = GNUNET_YES; 580 mini->did_map = GNUNET_YES;
621 mini->ac (mini->ac_cls, 581 mini->ac (mini->ac_cls,
622 GNUNET_YES, 582 GNUNET_YES,
623 (const struct sockaddr *) &mini->current_addr, 583 (const struct sockaddr *) &mini->current_addr,
624 sizeof (mini->current_addr), 584 sizeof (mini->current_addr),
625 GNUNET_NAT_ERROR_SUCCESS); 585 GNUNET_NAT_ERROR_SUCCESS);
@@ -647,30 +607,20 @@ GNUNET_NAT_mini_map_start (uint16_t port,
647{ 607{
648 struct GNUNET_NAT_MiniHandle *ret; 608 struct GNUNET_NAT_MiniHandle *ret;
649 609
650 if (GNUNET_SYSERR == 610 if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary ("upnpc", GNUNET_NO, NULL))
651 GNUNET_OS_check_helper_binary ("upnpc",
652 GNUNET_NO,
653 NULL))
654 { 611 {
655 LOG (GNUNET_ERROR_TYPE_INFO, 612 LOG (GNUNET_ERROR_TYPE_INFO, _ ("`upnpc' command not found\n"));
656 _("`upnpc' command not found\n")); 613 ac (ac_cls, GNUNET_SYSERR, NULL, 0, GNUNET_NAT_ERROR_UPNPC_NOT_FOUND);
657 ac (ac_cls,
658 GNUNET_SYSERR,
659 NULL, 0,
660 GNUNET_NAT_ERROR_UPNPC_NOT_FOUND);
661 return NULL; 614 return NULL;
662 } 615 }
663 LOG (GNUNET_ERROR_TYPE_DEBUG, 616 LOG (GNUNET_ERROR_TYPE_DEBUG, "Running `upnpc' to install mapping\n");
664 "Running `upnpc' to install mapping\n");
665 ret = GNUNET_new (struct GNUNET_NAT_MiniHandle); 617 ret = GNUNET_new (struct GNUNET_NAT_MiniHandle);
666 ret->ac = ac; 618 ret->ac = ac;
667 ret->ac_cls = ac_cls; 619 ret->ac_cls = ac_cls;
668 ret->is_tcp = is_tcp; 620 ret->is_tcp = is_tcp;
669 ret->port = port; 621 ret->port = port;
670 ret->refresh_task = 622 ret->refresh_task =
671 GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ, 623 GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ, &do_refresh, ret);
672 &do_refresh,
673 ret);
674 run_upnpc_r (ret); 624 run_upnpc_r (ret);
675 return ret; 625 return ret;
676} 626}
@@ -683,15 +633,13 @@ GNUNET_NAT_mini_map_start (uint16_t port,
683 * @param line line of output, NULL at the end 633 * @param line line of output, NULL at the end
684 */ 634 */
685static void 635static void
686process_unmap_output (void *cls, 636process_unmap_output (void *cls, const char *line)
687 const char *line)
688{ 637{
689 struct GNUNET_NAT_MiniHandle *mini = cls; 638 struct GNUNET_NAT_MiniHandle *mini = cls;
690 639
691 if (NULL == line) 640 if (NULL == line)
692 { 641 {
693 LOG (GNUNET_ERROR_TYPE_DEBUG, 642 LOG (GNUNET_ERROR_TYPE_DEBUG, "UPnP unmap done\n");
694 "UPnP unmap done\n");
695 GNUNET_OS_command_stop (mini->unmap_cmd); 643 GNUNET_OS_command_stop (mini->unmap_cmd);
696 mini->unmap_cmd = NULL; 644 mini->unmap_cmd = NULL;
697 GNUNET_free (mini); 645 GNUNET_free (mini);
@@ -735,7 +683,7 @@ GNUNET_NAT_mini_map_stop (struct GNUNET_NAT_MiniHandle *mini)
735 return; 683 return;
736 } 684 }
737 mini->ac (mini->ac_cls, 685 mini->ac (mini->ac_cls,
738 GNUNET_NO, 686 GNUNET_NO,
739 (const struct sockaddr *) &mini->current_addr, 687 (const struct sockaddr *) &mini->current_addr,
740 sizeof (mini->current_addr), 688 sizeof (mini->current_addr),
741 GNUNET_NAT_ERROR_SUCCESS); 689 GNUNET_NAT_ERROR_SUCCESS);
@@ -749,16 +697,15 @@ GNUNET_NAT_mini_map_stop (struct GNUNET_NAT_MiniHandle *mini)
749 LOG (GNUNET_ERROR_TYPE_DEBUG, 697 LOG (GNUNET_ERROR_TYPE_DEBUG,
750 "Unmapping port %u with UPnP\n", 698 "Unmapping port %u with UPnP\n",
751 ntohs (mini->current_addr.sin_port)); 699 ntohs (mini->current_addr.sin_port));
752 mini->unmap_cmd 700 mini->unmap_cmd = GNUNET_OS_command_run (&process_unmap_output,
753 = GNUNET_OS_command_run (&process_unmap_output, 701 mini,
754 mini, 702 UNMAP_TIMEOUT,
755 UNMAP_TIMEOUT, 703 "upnpc",
756 "upnpc", 704 "upnpc",
757 "upnpc", 705 "-d",
758 "-d", 706 pstr,
759 pstr, 707 mini->is_tcp ? "tcp" : "udp",
760 mini->is_tcp ? "tcp" : "udp", 708 NULL);
761 NULL);
762} 709}
763 710
764 711
diff --git a/src/nse/gnunet-nse-profiler.c b/src/nse/gnunet-nse-profiler.c
index a6b847f3a..12f5f37fb 100644
--- a/src/nse/gnunet-nse-profiler.c
+++ b/src/nse/gnunet-nse-profiler.c
@@ -36,14 +36,12 @@
36/** 36/**
37 * Generic loggins shorthand 37 * Generic loggins shorthand
38 */ 38 */
39#define LOG(kind,...) \ 39#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
40 GNUNET_log (kind, __VA_ARGS__)
41 40
42/** 41/**
43 * Debug logging shorthand 42 * Debug logging shorthand
44 */ 43 */
45#define LOG_DEBUG(...) \ 44#define LOG_DEBUG(...) LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
46 LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
47 45
48 46
49/** 47/**
@@ -210,7 +208,7 @@ static char *data_filename;
210 * How long to wait before triggering next round? 208 * How long to wait before triggering next round?
211 * Default: 60 s. 209 * Default: 60 s.
212 */ 210 */
213static struct GNUNET_TIME_Relative wait_time = { 60 * 1000 }; 211static struct GNUNET_TIME_Relative wait_time = {60 * 1000};
214 212
215/** 213/**
216 * DLL head for operation list 214 * DLL head for operation list
@@ -300,30 +298,34 @@ shutdown_task (void *cls)
300 */ 298 */
301static void 299static void
302handle_estimate (void *cls, 300handle_estimate (void *cls,
303 struct GNUNET_TIME_Absolute timestamp, 301 struct GNUNET_TIME_Absolute timestamp,
304 double estimate, double std_dev) 302 double estimate,
303 double std_dev)
305{ 304{
306 struct NSEPeer *peer = cls; 305 struct NSEPeer *peer = cls;
307 char output_buffer[512]; 306 char output_buffer[512];
308 size_t size; 307 size_t size;
309 308
310 if (NULL == output_file) 309 if (NULL == output_file)
311 { 310 {
312 FPRINTF (stderr, 311 fprintf (stderr,
313 "Received network size estimate from peer %p. Size: %f std.dev. %f\n", 312 "Received network size estimate from peer %p. Size: %f std.dev. %f\n",
314 peer, estimate, std_dev); 313 peer,
315 return; 314 estimate,
316 } 315 std_dev);
316 return;
317 }
317 size = GNUNET_snprintf (output_buffer, 318 size = GNUNET_snprintf (output_buffer,
318 sizeof (output_buffer), 319 sizeof (output_buffer),
319 "%p %llu %llu %f %f %f\n", 320 "%p %llu %llu %f %f %f\n",
320 peer, peers_running, 321 peer,
321 (unsigned long long) timestamp.abs_value_us, 322 peers_running,
322 GNUNET_NSE_log_estimate_to_n (estimate), estimate, 323 (unsigned long long) timestamp.abs_value_us,
323 std_dev); 324 GNUNET_NSE_log_estimate_to_n (estimate),
325 estimate,
326 std_dev);
324 if (size != GNUNET_DISK_file_write (output_file, output_buffer, size)) 327 if (size != GNUNET_DISK_file_write (output_file, output_buffer, size))
325 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 328 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
326 "Unable to write to file!\n");
327} 329}
328 330
329 331
@@ -338,8 +340,7 @@ handle_estimate (void *cls,
338 * @return service handle to return in 'op_result', NULL on error 340 * @return service handle to return in 'op_result', NULL on error
339 */ 341 */
340static void * 342static void *
341nse_connect_adapter (void *cls, 343nse_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
342 const struct GNUNET_CONFIGURATION_Handle *cfg)
343{ 344{
344 struct NSEPeer *current_peer = cls; 345 struct NSEPeer *current_peer = cls;
345 346
@@ -355,8 +356,7 @@ nse_connect_adapter (void *cls,
355 * @param op_result service handle returned from the connect adapter 356 * @param op_result service handle returned from the connect adapter
356 */ 357 */
357static void 358static void
358nse_disconnect_adapter (void *cls, 359nse_disconnect_adapter (void *cls, void *op_result)
359 void *op_result)
360{ 360{
361 GNUNET_NSE_disconnect (op_result); 361 GNUNET_NSE_disconnect (op_result);
362} 362}
@@ -389,9 +389,11 @@ stat_iterator (void *cls,
389 flag = strcasecmp (subsystem, "core"); 389 flag = strcasecmp (subsystem, "core");
390 if (0 != flag) 390 if (0 != flag)
391 flag = 1; 391 flag = 1;
392 size = GNUNET_asprintf (&output_buffer, "%llu %llu %u\n", 392 size = GNUNET_asprintf (&output_buffer,
393 "%llu %llu %u\n",
393 now.abs_value_us / 1000LL / 1000LL, 394 now.abs_value_us / 1000LL / 1000LL,
394 value, flag); 395 value,
396 flag);
395 if (0 > size) 397 if (0 > size)
396 { 398 {
397 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Error formatting output buffer.\n"); 399 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Error formatting output buffer.\n");
@@ -419,8 +421,7 @@ stat_iterator (void *cls,
419 * @return service handle to return in 'op_result', NULL on error 421 * @return service handle to return in 'op_result', NULL on error
420 */ 422 */
421static void * 423static void *
422stat_connect_adapter (void *cls, 424stat_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
423 const struct GNUNET_CONFIGURATION_Handle *cfg)
424{ 425{
425 struct NSEPeer *peer = cls; 426 struct NSEPeer *peer = cls;
426 427
@@ -440,12 +441,18 @@ stat_disconnect_adapter (void *cls, void *op_result)
440{ 441{
441 struct NSEPeer *peer = cls; 442 struct NSEPeer *peer = cls;
442 443
443 GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel 444 GNUNET_break (GNUNET_OK ==
444 (peer->sh, "core", "# peers connected", 445 GNUNET_STATISTICS_watch_cancel (peer->sh,
445 stat_iterator, peer)); 446 "core",
446 GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel 447 "# peers connected",
447 (peer->sh, "nse", "# peers connected", 448 stat_iterator,
448 stat_iterator, peer)); 449 peer));
450 GNUNET_break (GNUNET_OK ==
451 GNUNET_STATISTICS_watch_cancel (peer->sh,
452 "nse",
453 "# peers connected",
454 stat_iterator,
455 peer));
449 GNUNET_STATISTICS_destroy (op_result, GNUNET_NO); 456 GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
450 peer->sh = NULL; 457 peer->sh = NULL;
451} 458}
@@ -462,8 +469,10 @@ stat_disconnect_adapter (void *cls, void *op_result)
462 * operation has executed successfully. 469 * operation has executed successfully.
463 */ 470 */
464static void 471static void
465stat_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, 472stat_comp_cb (void *cls,
466 void *ca_result, const char *emsg ) 473 struct GNUNET_TESTBED_Operation *op,
474 void *ca_result,
475 const char *emsg)
467{ 476{
468 struct GNUNET_STATISTICS_Handle *sh = ca_result; 477 struct GNUNET_STATISTICS_Handle *sh = ca_result;
469 struct NSEPeer *peer = cls; 478 struct NSEPeer *peer = cls;
@@ -473,12 +482,16 @@ stat_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
473 GNUNET_break (0); 482 GNUNET_break (0);
474 return; 483 return;
475 } 484 }
476 GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch 485 GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch (sh,
477 (sh, "core", "# peers connected", 486 "core",
478 stat_iterator, peer)); 487 "# peers connected",
479 GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch 488 stat_iterator,
480 (sh, "nse", "# peers connected", 489 peer));
481 stat_iterator, peer)); 490 GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch (sh,
491 "nse",
492 "# peers connected",
493 stat_iterator,
494 peer));
482} 495}
483 496
484 497
@@ -500,29 +513,30 @@ connect_nse_service ()
500 for (i = 0; i < num_peers_in_round[current_round]; i++) 513 for (i = 0; i < num_peers_in_round[current_round]; i++)
501 { 514 {
502 if ((num_peers_in_round[current_round] > connection_limit) && 515 if ((num_peers_in_round[current_round] > connection_limit) &&
503 (0 != (i % (num_peers_in_round[current_round] / connection_limit)))) 516 (0 != (i % (num_peers_in_round[current_round] / connection_limit))))
504 continue; 517 continue;
505 LOG_DEBUG ("Connecting to nse service of peer %d\n", i); 518 LOG_DEBUG ("Connecting to nse service of peer %d\n", i);
506 current_peer = GNUNET_new (struct NSEPeer); 519 current_peer = GNUNET_new (struct NSEPeer);
507 current_peer->daemon = daemons[i]; 520 current_peer->daemon = daemons[i];
508 current_peer->nse_op 521 current_peer->nse_op =
509 = GNUNET_TESTBED_service_connect (NULL, 522 GNUNET_TESTBED_service_connect (NULL,
510 current_peer->daemon, 523 current_peer->daemon,
511 "nse", 524 "nse",
512 NULL, NULL, 525 NULL,
513 &nse_connect_adapter, 526 NULL,
514 &nse_disconnect_adapter, 527 &nse_connect_adapter,
515 current_peer); 528 &nse_disconnect_adapter,
529 current_peer);
516 if (NULL != data_file) 530 if (NULL != data_file)
517 current_peer->stat_op 531 current_peer->stat_op =
518 = GNUNET_TESTBED_service_connect (NULL, 532 GNUNET_TESTBED_service_connect (NULL,
519 current_peer->daemon, 533 current_peer->daemon,
520 "statistics", 534 "statistics",
521 stat_comp_cb, 535 stat_comp_cb,
522 current_peer, 536 current_peer,
523 &stat_connect_adapter, 537 &stat_connect_adapter,
524 &stat_disconnect_adapter, 538 &stat_disconnect_adapter,
525 current_peer); 539 current_peer);
526 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer); 540 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer);
527 if (++connections == connection_limit) 541 if (++connections == connection_limit)
528 break; 542 break;
@@ -549,9 +563,7 @@ next_round (void *cls);
549static void 563static void
550finish_round (void *cls) 564finish_round (void *cls)
551{ 565{
552 LOG (GNUNET_ERROR_TYPE_INFO, 566 LOG (GNUNET_ERROR_TYPE_INFO, "Have %u connections\n", total_connections);
553 "Have %u connections\n",
554 total_connections);
555 close_monitor_connections (); 567 close_monitor_connections ();
556 round_task = GNUNET_SCHEDULER_add_now (&next_round, NULL); 568 round_task = GNUNET_SCHEDULER_add_now (&next_round, NULL);
557} 569}
@@ -565,12 +577,9 @@ finish_round (void *cls)
565static void 577static void
566run_round () 578run_round ()
567{ 579{
568 LOG_DEBUG ("Running round %u\n", 580 LOG_DEBUG ("Running round %u\n", current_round);
569 current_round);
570 connect_nse_service (); 581 connect_nse_service ();
571 GNUNET_SCHEDULER_add_delayed (wait_time, 582 GNUNET_SCHEDULER_add_delayed (wait_time, &finish_round, NULL);
572 &finish_round,
573 NULL);
574} 583}
575 584
576 585
@@ -583,9 +592,7 @@ make_oplist_entry ()
583 struct OpListEntry *entry; 592 struct OpListEntry *entry;
584 593
585 entry = GNUNET_new (struct OpListEntry); 594 entry = GNUNET_new (struct OpListEntry);
586 GNUNET_CONTAINER_DLL_insert_tail (oplist_head, 595 GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry);
587 oplist_tail,
588 entry);
589 return entry; 596 return entry;
590} 597}
591 598
@@ -599,7 +606,7 @@ make_oplist_entry ()
599 */ 606 */
600static void 607static void
601manage_service_cb (void *cls, 608manage_service_cb (void *cls,
602 struct GNUNET_TESTBED_Operation *op, 609 struct GNUNET_TESTBED_Operation *op,
603 const char *emsg) 610 const char *emsg)
604{ 611{
605 struct OpListEntry *entry = cls; 612 struct OpListEntry *entry = cls;
@@ -613,9 +620,7 @@ manage_service_cb (void *cls,
613 } 620 }
614 GNUNET_assert (0 != entry->delta); 621 GNUNET_assert (0 != entry->delta);
615 peers_running += entry->delta; 622 peers_running += entry->delta;
616 GNUNET_CONTAINER_DLL_remove (oplist_head, 623 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
617 oplist_tail,
618 entry);
619 GNUNET_free (entry); 624 GNUNET_free (entry);
620 if (num_peers_in_round[current_round] == peers_running) 625 if (num_peers_in_round[current_round] == peers_running)
621 run_round (); 626 run_round ();
@@ -633,7 +638,7 @@ adjust_running_peers ()
633 unsigned int i; 638 unsigned int i;
634 639
635 /* start peers if we have too few */ 640 /* start peers if we have too few */
636 for (i=peers_running;i<num_peers_in_round[current_round];i++) 641 for (i = peers_running; i < num_peers_in_round[current_round]; i++)
637 { 642 {
638 entry = make_oplist_entry (); 643 entry = make_oplist_entry ();
639 entry->delta = 1; 644 entry->delta = 1;
@@ -645,16 +650,16 @@ adjust_running_peers ()
645 1); 650 1);
646 } 651 }
647 /* stop peers if we have too many */ 652 /* stop peers if we have too many */
648 for (i=num_peers_in_round[current_round];i<peers_running;i++) 653 for (i = num_peers_in_round[current_round]; i < peers_running; i++)
649 { 654 {
650 entry = make_oplist_entry (); 655 entry = make_oplist_entry ();
651 entry->delta = -1; 656 entry->delta = -1;
652 entry->op = GNUNET_TESTBED_peer_manage_service (NULL, 657 entry->op = GNUNET_TESTBED_peer_manage_service (NULL,
653 daemons[i], 658 daemons[i],
654 "nse", 659 "nse",
655 &manage_service_cb, 660 &manage_service_cb,
656 entry, 661 entry,
657 0); 662 0);
658 } 663 }
659} 664}
660 665
@@ -697,19 +702,19 @@ next_round (void *cls)
697 */ 702 */
698static void 703static void
699master_controller_cb (void *cls, 704master_controller_cb (void *cls,
700 const struct GNUNET_TESTBED_EventInformation *event) 705 const struct GNUNET_TESTBED_EventInformation *event)
701{ 706{
702 switch (event->type) 707 switch (event->type)
703 { 708 {
704 case GNUNET_TESTBED_ET_CONNECT: 709 case GNUNET_TESTBED_ET_CONNECT:
705 total_connections++; 710 total_connections++;
706 break; 711 break;
707 case GNUNET_TESTBED_ET_DISCONNECT: 712 case GNUNET_TESTBED_ET_DISCONNECT:
708 total_connections--; 713 total_connections--;
709 break; 714 break;
710 default: 715 default:
711 break; 716 break;
712 } 717 }
713} 718}
714 719
715 720
@@ -761,7 +766,9 @@ test_master (void *cls,
761 * @param cfg configuration handle 766 * @param cfg configuration handle
762 */ 767 */
763static void 768static void
764run (void *cls, char *const *args, const char *cfgfile, 769run (void *cls,
770 char *const *args,
771 const char *cfgfile,
765 const struct GNUNET_CONFIGURATION_Handle *cfg) 772 const struct GNUNET_CONFIGURATION_Handle *cfg)
766{ 773{
767 char *tok; 774 char *tok;
@@ -777,46 +784,43 @@ run (void *cls, char *const *args, const char *cfgfile,
777 return; 784 return;
778 } 785 }
779 for (tok = strtok (num_peer_spec, ","); NULL != tok; tok = strtok (NULL, ",")) 786 for (tok = strtok (num_peer_spec, ","); NULL != tok; tok = strtok (NULL, ","))
787 {
788 if (1 != sscanf (tok, "%u", &num))
780 { 789 {
781 if (1 != sscanf (tok, "%u", &num)) 790 fprintf (stderr, "You need to specify numbers, not `%s'\n", tok);
782 { 791 return;
783 fprintf (stderr, "You need to specify numbers, not `%s'\n", tok);
784 return;
785 }
786 if (0 == num)
787 {
788 fprintf (stderr, "Refusing to run a round with 0 peers\n");
789 return;
790 }
791 GNUNET_array_append (num_peers_in_round, num_rounds, num);
792 num_peers = GNUNET_MAX (num_peers, num);
793 } 792 }
794 if (0 == num_peers) 793 if (0 == num)
795 { 794 {
796 fprintf (stderr, "Refusing to run a testbed with no rounds\n"); 795 fprintf (stderr, "Refusing to run a round with 0 peers\n");
797 return; 796 return;
798 } 797 }
799 if ( (NULL != data_filename) && 798 GNUNET_array_append (num_peers_in_round, num_rounds, num);
800 (NULL == (data_file = 799 num_peers = GNUNET_MAX (num_peers, num);
801 GNUNET_DISK_file_open (data_filename, 800 }
802 GNUNET_DISK_OPEN_READWRITE | 801 if (0 == num_peers)
803 GNUNET_DISK_OPEN_TRUNCATE | 802 {
804 GNUNET_DISK_OPEN_CREATE, 803 fprintf (stderr, "Refusing to run a testbed with no rounds\n");
805 GNUNET_DISK_PERM_USER_READ | 804 return;
806 GNUNET_DISK_PERM_USER_WRITE))) ) 805 }
807 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 806 if ((NULL != data_filename) &&
808 "open", 807 (NULL ==
809 data_filename); 808 (data_file = GNUNET_DISK_file_open (data_filename,
810 809 GNUNET_DISK_OPEN_READWRITE |
811 if ( (NULL != output_filename) && 810 GNUNET_DISK_OPEN_TRUNCATE |
812 (NULL == (output_file = 811 GNUNET_DISK_OPEN_CREATE,
813 GNUNET_DISK_file_open (output_filename, 812 GNUNET_DISK_PERM_USER_READ |
814 GNUNET_DISK_OPEN_READWRITE | 813 GNUNET_DISK_PERM_USER_WRITE))))
815 GNUNET_DISK_OPEN_CREATE, 814 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", data_filename);
816 GNUNET_DISK_PERM_USER_READ | 815
817 GNUNET_DISK_PERM_USER_WRITE))) ) 816 if ((NULL != output_filename) &&
818 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", 817 (NULL ==
819 output_filename); 818 (output_file = GNUNET_DISK_file_open (output_filename,
819 GNUNET_DISK_OPEN_READWRITE |
820 GNUNET_DISK_OPEN_CREATE,
821 GNUNET_DISK_PERM_USER_READ |
822 GNUNET_DISK_PERM_USER_WRITE))))
823 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", output_filename);
820 event_mask = 0LL; 824 event_mask = 0LL;
821 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); 825 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
822 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); 826 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
@@ -827,9 +831,9 @@ run (void *cls, char *const *args, const char *cfgfile,
827 num_peers, 831 num_peers,
828 event_mask, 832 event_mask,
829 master_controller_cb, 833 master_controller_cb,
830 NULL, /* master_controller_cb cls */ 834 NULL, /* master_controller_cb cls */
831 &test_master, 835 &test_master,
832 NULL); /* test_master cls */ 836 NULL); /* test_master cls */
833 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); 837 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
834} 838}
835 839
@@ -842,56 +846,70 @@ run (void *cls, char *const *args, const char *cfgfile,
842int 846int
843main (int argc, char *const *argv) 847main (int argc, char *const *argv)
844{ 848{
845 struct GNUNET_GETOPT_CommandLineOption options[] = { 849 struct GNUNET_GETOPT_CommandLineOption options[] =
846 GNUNET_GETOPT_option_uint ('C', 850 {GNUNET_GETOPT_option_uint (
847 "connections", 851 'C',
848 "COUNT", 852 "connections",
849 gettext_noop ("limit to the number of connections to NSE services, 0 for none"), 853 "COUNT",
850 &connection_limit), 854 gettext_noop (
851 GNUNET_GETOPT_option_string ('d', 855 "limit to the number of connections to NSE services, 0 for none"),
852 "details", 856 &connection_limit),
853 "FILENAME", 857 GNUNET_GETOPT_option_string (
854 gettext_noop ("name of the file for writing connection information and statistics"), 858 'd',
855 &data_filename), 859 "details",
856 860 "FILENAME",
857 GNUNET_GETOPT_option_string ('H', 861 gettext_noop (
858 "hosts", 862 "name of the file for writing connection information and statistics"),
859 "FILENAME", 863 &data_filename),
860 gettext_noop ("name of the file with the login information for the testbed"), 864
861 &hosts_file), 865 GNUNET_GETOPT_option_string (
862 866 'H',
863 GNUNET_GETOPT_option_string ('o', 867 "hosts",
864 "output", 868 "FILENAME",
865 "FILENAME", 869 gettext_noop (
866 gettext_noop ("name of the file for writing the main results"), 870 "name of the file with the login information for the testbed"),
867 &output_filename), 871 &hosts_file),
868 872
869 873 GNUNET_GETOPT_option_string (
870 GNUNET_GETOPT_option_string ('p', 874 'o',
871 "peers", 875 "output",
872 "NETWORKSIZESPEC", 876 "FILENAME",
873 gettext_noop ("Number of peers to run in each round, separated by commas"), 877 gettext_noop ("name of the file for writing the main results"),
874 &num_peer_spec), 878 &output_filename),
875 879
876 GNUNET_GETOPT_option_increment_uint ('V', 880
877 "verbose", 881 GNUNET_GETOPT_option_string (
878 gettext_noop ("be verbose (print progress information)"), 882 'p',
879 &verbose), 883 "peers",
880 884 "NETWORKSIZESPEC",
881 GNUNET_GETOPT_option_relative_time ('w', 885 gettext_noop (
882 "wait", 886 "Number of peers to run in each round, separated by commas"),
883 "DELAY", 887 &num_peer_spec),
884 gettext_noop ("delay between rounds"), 888
885 &wait_time), 889 GNUNET_GETOPT_option_increment_uint (
886 GNUNET_GETOPT_OPTION_END 890 'V',
887 }; 891 "verbose",
892 gettext_noop ("be verbose (print progress information)"),
893 &verbose),
894
895 GNUNET_GETOPT_option_relative_time ('w',
896 "wait",
897 "DELAY",
898 gettext_noop ("delay between rounds"),
899 &wait_time),
900 GNUNET_GETOPT_OPTION_END};
888 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 901 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
889 return 2; 902 return 2;
890 if (GNUNET_OK != 903 if (
891 GNUNET_PROGRAM_run (argc, argv, "nse-profiler", 904 GNUNET_OK !=
892 gettext_noop 905 GNUNET_PROGRAM_run (argc,
893 ("Measure quality and performance of the NSE service."), 906 argv,
894 options, &run, NULL)) 907 "nse-profiler",
908 gettext_noop (
909 "Measure quality and performance of the NSE service."),
910 options,
911 &run,
912 NULL))
895 ok = 1; 913 ok = 1;
896 return ok; 914 return ok;
897} 915}
diff --git a/src/nse/gnunet-nse.c b/src/nse/gnunet-nse.c
index c8ffa152e..73b80e28b 100644
--- a/src/nse/gnunet-nse.c
+++ b/src/nse/gnunet-nse.c
@@ -72,7 +72,7 @@ handle_estimate (void *cls,
72{ 72{
73 (void) cls; 73 (void) cls;
74 status = 0; 74 status = 0;
75 FPRINTF (stdout, 75 fprintf (stdout,
76 "%llu %f %f %f\n", 76 "%llu %f %f %f\n",
77 (unsigned long long) timestamp.abs_value_us, 77 (unsigned long long) timestamp.abs_value_us,
78 GNUNET_NSE_log_estimate_to_n (estimate), 78 GNUNET_NSE_log_estimate_to_n (estimate),
diff --git a/src/nse/test_nse_api.c b/src/nse/test_nse_api.c
index e427e393b..67ca17127 100644
--- a/src/nse/test_nse_api.c
+++ b/src/nse/test_nse_api.c
@@ -63,7 +63,7 @@ check_nse_message (void *cls, struct GNUNET_TIME_Absolute timestamp,
63{ 63{
64 int *ok = cls; 64 int *ok = cls;
65 65
66 FPRINTF (stderr, 66 fprintf (stderr,
67 "Received NSE message, estimate %f, standard deviation %f.\n", 67 "Received NSE message, estimate %f, standard deviation %f.\n",
68 estimate, std_dev); 68 estimate, std_dev);
69 /* Fantastic check below. Expect NaN, the only thing not equal to itself. */ 69 /* Fantastic check below. Expect NaN, the only thing not equal to itself. */
diff --git a/src/nse/test_nse_multipeer.c b/src/nse/test_nse_multipeer.c
index 6a6046173..ec5a94f76 100644
--- a/src/nse/test_nse_multipeer.c
+++ b/src/nse/test_nse_multipeer.c
@@ -98,7 +98,7 @@ handle_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp,
98{ 98{
99 struct NSEPeer *peer = cls; 99 struct NSEPeer *peer = cls;
100 100
101 FPRINTF (stderr, 101 fprintf (stderr,
102 "Received network size estimate from peer %u. logSize: %f std.dev. %f (%f/%u)\n", 102 "Received network size estimate from peer %u. logSize: %f std.dev. %f (%f/%u)\n",
103 (unsigned int) (peer - nse_peers), 103 (unsigned int) (peer - nse_peers),
104 estimate, std_dev, 104 estimate, std_dev,
diff --git a/src/peerinfo-tool/gnunet-peerinfo.c b/src/peerinfo-tool/gnunet-peerinfo.c
index 109416600..fdcaaba58 100644
--- a/src/peerinfo-tool/gnunet-peerinfo.c
+++ b/src/peerinfo-tool/gnunet-peerinfo.c
@@ -114,7 +114,6 @@ struct PrintContext
114 * Hello was friend only, #GNUNET_YES or #GNUNET_NO 114 * Hello was friend only, #GNUNET_YES or #GNUNET_NO
115 */ 115 */
116 int friend_only; 116 int friend_only;
117
118}; 117};
119 118
120 119
@@ -236,29 +235,26 @@ dump_pc (struct PrintContext *pc)
236{ 235{
237 unsigned int i; 236 unsigned int i;
238 237
239 printf (_("%sPeer `%s'\n"), 238 printf (_ ("%sPeer `%s'\n"),
240 (GNUNET_YES == pc->friend_only) ? "F2F: " : "", 239 (GNUNET_YES == pc->friend_only) ? "F2F: " : "",
241 GNUNET_i2s_full (&pc->peer)); 240 GNUNET_i2s_full (&pc->peer));
242 for (i = 0; i < pc->num_addresses; i++) 241 for (i = 0; i < pc->num_addresses; i++)
243 { 242 {
244 if (NULL != pc->address_list[i].result) 243 if (NULL != pc->address_list[i].result)
245 { 244 {
246 printf (_("\tExpires: %s \t %s\n"), 245 printf (_ ("\tExpires: %s \t %s\n"),
247 GNUNET_STRINGS_absolute_time_to_string (pc->address_list[i].expiration), 246 GNUNET_STRINGS_absolute_time_to_string (
247 pc->address_list[i].expiration),
248 pc->address_list[i].result); 248 pc->address_list[i].result);
249 GNUNET_free (pc->address_list[i].result); 249 GNUNET_free (pc->address_list[i].result);
250 } 250 }
251 } 251 }
252 printf ("\n"); 252 printf ("\n");
253 GNUNET_free_non_null (pc->address_list); 253 GNUNET_free_non_null (pc->address_list);
254 GNUNET_CONTAINER_DLL_remove (pc_head, 254 GNUNET_CONTAINER_DLL_remove (pc_head, pc_tail, pc);
255 pc_tail,
256 pc);
257 GNUNET_free (pc); 255 GNUNET_free (pc);
258 if ( (NULL == pc_head) && 256 if ((NULL == pc_head) && (NULL == pic))
259 (NULL == pic) ) 257 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
260 tt = GNUNET_SCHEDULER_add_now (&state_machine,
261 NULL);
262} 258}
263 259
264 260
@@ -276,9 +272,7 @@ dump_pc (struct PrintContext *pc)
276 * if #GNUNET_SYSERR: address is invalid 272 * if #GNUNET_SYSERR: address is invalid
277 */ 273 */
278static void 274static void
279process_resolved_address (void *cls, 275process_resolved_address (void *cls, const char *address, int res)
280 const char *address,
281 int res)
282{ 276{
283 struct AddressRecord *ar = cls; 277 struct AddressRecord *ar = cls;
284 struct PrintContext *pc = ar->pc; 278 struct PrintContext *pc = ar->pc;
@@ -296,7 +290,7 @@ process_resolved_address (void *cls,
296 ar->atsc = NULL; 290 ar->atsc = NULL;
297 if (GNUNET_SYSERR == res) 291 if (GNUNET_SYSERR == res)
298 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 292 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
299 _("Failure: Cannot convert address to string for peer `%s'\n"), 293 _ ("Failure: Cannot convert address to string for peer `%s'\n"),
300 GNUNET_i2s (&ar->pc->peer)); 294 GNUNET_i2s (&ar->pc->peer));
301 pc->num_addresses++; 295 pc->num_addresses++;
302 if (pc->num_addresses == pc->address_list_size) 296 if (pc->num_addresses == pc->address_list_size)
@@ -352,8 +346,9 @@ print_address (void *cls,
352 ar->atsc = GNUNET_TRANSPORT_address_to_string (cfg, 346 ar->atsc = GNUNET_TRANSPORT_address_to_string (cfg,
353 address, 347 address,
354 no_resolve, 348 no_resolve,
355 TIMEOUT, 349 TIMEOUT,
356 &process_resolved_address, ar); 350 &process_resolved_address,
351 ar);
357 return GNUNET_OK; 352 return GNUNET_OK;
358} 353}
359 354
@@ -381,9 +376,9 @@ print_peer_info (void *cls,
381 pic = NULL; /* end of iteration */ 376 pic = NULL; /* end of iteration */
382 if (NULL != err_msg) 377 if (NULL != err_msg)
383 { 378 {
384 FPRINTF (stderr, 379 fprintf (stderr,
385 _("Error in communication with PEERINFO service: %s\n"), 380 _ ("Error in communication with PEERINFO service: %s\n"),
386 err_msg); 381 err_msg);
387 } 382 }
388 if (NULL == pc_head) 383 if (NULL == pc_head)
389 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL); 384 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
@@ -391,25 +386,19 @@ print_peer_info (void *cls,
391 } 386 }
392 friend_only = GNUNET_NO; 387 friend_only = GNUNET_NO;
393 if (NULL != hello) 388 if (NULL != hello)
394 friend_only = GNUNET_HELLO_is_friend_only (hello); 389 friend_only = GNUNET_HELLO_is_friend_only (hello);
395 if ( (GNUNET_YES == be_quiet) || 390 if ((GNUNET_YES == be_quiet) || (NULL == hello))
396 (NULL == hello) )
397 { 391 {
398 printf ("%s%s\n", 392 printf ("%s%s\n",
399 (GNUNET_YES == friend_only) ? "F2F: " : "", 393 (GNUNET_YES == friend_only) ? "F2F: " : "",
400 GNUNET_i2s_full (peer)); 394 GNUNET_i2s_full (peer));
401 return; 395 return;
402 } 396 }
403 pc = GNUNET_new (struct PrintContext); 397 pc = GNUNET_new (struct PrintContext);
404 GNUNET_CONTAINER_DLL_insert (pc_head, 398 GNUNET_CONTAINER_DLL_insert (pc_head, pc_tail, pc);
405 pc_tail,
406 pc);
407 pc->peer = *peer; 399 pc->peer = *peer;
408 pc->friend_only = friend_only; 400 pc->friend_only = friend_only;
409 GNUNET_HELLO_iterate_addresses (hello, 401 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &count_address, pc);
410 GNUNET_NO,
411 &count_address,
412 pc);
413 if (0 == pc->off) 402 if (0 == pc->off)
414 { 403 {
415 dump_pc (pc); 404 dump_pc (pc);
@@ -417,10 +406,7 @@ print_peer_info (void *cls,
417 } 406 }
418 pc->address_list_size = pc->off; 407 pc->address_list_size = pc->off;
419 pc->address_list = GNUNET_malloc (sizeof (struct AddressRecord) * pc->off); 408 pc->address_list = GNUNET_malloc (sizeof (struct AddressRecord) * pc->off);
420 GNUNET_HELLO_iterate_addresses (hello, 409 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &print_address, pc);
421 GNUNET_NO,
422 &print_address,
423 pc);
424} 410}
425 411
426/* ************************* DUMP Hello ************************** */ 412/* ************************* DUMP Hello ************************** */
@@ -462,45 +448,40 @@ dump_my_hello ()
462 size = GNUNET_HELLO_size (my_hello); 448 size = GNUNET_HELLO_size (my_hello);
463 if (0 == size) 449 if (0 == size)
464 { 450 {
465 FPRINTF (stderr, 451 fprintf (stderr, _ ("Failure: Received invalid %s\n"), "HELLO");
466 _("Failure: Received invalid %s\n"),
467 "HELLO");
468 return; 452 return;
469 } 453 }
470 if (GNUNET_SYSERR == 454 if (GNUNET_SYSERR == GNUNET_DISK_fn_write (dump_hello,
471 GNUNET_DISK_fn_write (dump_hello, 455 my_hello,
472 my_hello, 456 size,
473 size, 457 GNUNET_DISK_PERM_USER_READ |
474 GNUNET_DISK_PERM_USER_READ | 458 GNUNET_DISK_PERM_USER_WRITE |
475 GNUNET_DISK_PERM_USER_WRITE | 459 GNUNET_DISK_PERM_GROUP_READ |
476 GNUNET_DISK_PERM_GROUP_READ | 460 GNUNET_DISK_PERM_OTHER_READ))
477 GNUNET_DISK_PERM_OTHER_READ))
478 { 461 {
479 FPRINTF (stderr, 462 fprintf (stderr,
480 _("Failed to write HELLO with %u bytes to file `%s'\n"), 463 _ ("Failed to write HELLO with %u bytes to file `%s'\n"),
481 size, 464 size,
482 dump_hello); 465 dump_hello);
483 if (0 != UNLINK (dump_hello)) 466 if (0 != unlink (dump_hello))
484 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | 467 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
485 GNUNET_ERROR_TYPE_BULK, 468 GNUNET_ERROR_TYPE_BULK,
486 "unlink", 469 "unlink",
487 dump_hello); 470 dump_hello);
488
489 } 471 }
490 c_addr = 0; 472 c_addr = 0;
491 GNUNET_HELLO_iterate_addresses (my_hello, 473 GNUNET_HELLO_iterate_addresses (my_hello, GNUNET_NO, count_addr, &c_addr);
492 GNUNET_NO,
493 count_addr,
494 &c_addr);
495 474
496 if (! be_quiet) 475 if (! be_quiet)
497 { 476 {
498 FPRINTF (stderr, 477 fprintf (
499 _("Wrote %s HELLO containing %u addresses with %u bytes to file `%s'\n"), 478 stderr,
500 (GNUNET_YES == GNUNET_HELLO_is_friend_only (my_hello)) ? "friend-only": "public", 479 _ ("Wrote %s HELLO containing %u addresses with %u bytes to file `%s'\n"),
501 c_addr, 480 (GNUNET_YES == GNUNET_HELLO_is_friend_only (my_hello)) ? "friend-only"
502 size, 481 : "public",
503 dump_hello); 482 c_addr,
483 size,
484 dump_hello);
504 } 485 }
505 GNUNET_free (dump_hello); 486 GNUNET_free (dump_hello);
506 dump_hello = NULL; 487 dump_hello = NULL;
@@ -522,7 +503,7 @@ static void
522print_my_uri (void *cls, 503print_my_uri (void *cls,
523 const struct GNUNET_PeerIdentity *peer, 504 const struct GNUNET_PeerIdentity *peer,
524 const struct GNUNET_HELLO_Message *hello, 505 const struct GNUNET_HELLO_Message *hello,
525 const char *err_msg) 506 const char *err_msg)
526{ 507{
527 char *uri; 508 char *uri;
528 509
@@ -530,21 +511,19 @@ print_my_uri (void *cls,
530 { 511 {
531 pic = NULL; 512 pic = NULL;
532 if (NULL != err_msg) 513 if (NULL != err_msg)
533 FPRINTF (stderr, 514 fprintf (stderr,
534 _("Error in communication with PEERINFO service: %s\n"), 515 _ ("Error in communication with PEERINFO service: %s\n"),
535 err_msg); 516 err_msg);
536 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL); 517 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
537 return; 518 return;
538 } 519 }
539 520
540 if (NULL == hello) 521 if (NULL == hello)
541 return; 522 return;
542 uri = GNUNET_HELLO_compose_uri (hello, 523 uri = GNUNET_HELLO_compose_uri (hello, &GPI_plugins_find);
543 &GPI_plugins_find);
544 if (NULL != uri) 524 if (NULL != uri)
545 { 525 {
546 printf ("%s\n", 526 printf ("%s\n", (const char *) uri);
547 (const char *) uri);
548 GNUNET_free (uri); 527 GNUNET_free (uri);
549 } 528 }
550} 529}
@@ -589,10 +568,7 @@ parse_hello_uri (const char *put_uri)
589 { 568 {
590 /* WARNING: this adds the address from URI WITHOUT verification! */ 569 /* WARNING: this adds the address from URI WITHOUT verification! */
591 if (GNUNET_OK == ret) 570 if (GNUNET_OK == ret)
592 ac = GNUNET_PEERINFO_add_peer (peerinfo, 571 ac = GNUNET_PEERINFO_add_peer (peerinfo, hello, &add_continuation, NULL);
593 hello,
594 &add_continuation,
595 NULL);
596 else 572 else
597 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL); 573 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
598 GNUNET_free (hello); 574 GNUNET_free (hello);
@@ -639,17 +615,15 @@ shutdown_task (void *cls)
639 } 615 }
640 while (NULL != (pc = pc_head)) 616 while (NULL != (pc = pc_head))
641 { 617 {
642 GNUNET_CONTAINER_DLL_remove (pc_head, 618 GNUNET_CONTAINER_DLL_remove (pc_head, pc_tail, pc);
643 pc_tail, 619 for (i = 0; i < pc->address_list_size; i++)
644 pc);
645 for (i=0;i<pc->address_list_size;i++)
646 { 620 {
647 ar = &pc->address_list[i]; 621 ar = &pc->address_list[i];
648 GNUNET_free_non_null (ar->result); 622 GNUNET_free_non_null (ar->result);
649 if (NULL != ar->atsc) 623 if (NULL != ar->atsc)
650 { 624 {
651 GNUNET_TRANSPORT_address_to_string_cancel (ar->atsc); 625 GNUNET_TRANSPORT_address_to_string_cancel (ar->atsc);
652 ar->atsc = NULL; 626 ar->atsc = NULL;
653 } 627 }
654 } 628 }
655 GNUNET_free_non_null (pc->address_list); 629 GNUNET_free_non_null (pc->address_list);
@@ -677,20 +651,17 @@ shutdown_task (void *cls)
677 * @param hello the HELLO message 651 * @param hello the HELLO message
678 */ 652 */
679static void 653static void
680hello_callback (void *cls, 654hello_callback (void *cls, const struct GNUNET_MessageHeader *hello)
681 const struct GNUNET_MessageHeader *hello)
682{ 655{
683 if (NULL == hello) 656 if (NULL == hello)
684 { 657 {
685 fprintf (stderr, 658 fprintf (stderr, "Failed to get my own HELLO from this peer!\n");
686 "Failed to get my own HELLO from this peer!\n");
687 GNUNET_SCHEDULER_shutdown (); 659 GNUNET_SCHEDULER_shutdown ();
688 return; 660 return;
689 } 661 }
690 my_hello = (struct GNUNET_HELLO_Message *) GNUNET_copy_message (hello); 662 my_hello = (struct GNUNET_HELLO_Message *) GNUNET_copy_message (hello);
691 GNUNET_assert (GNUNET_OK == 663 GNUNET_assert (GNUNET_OK ==
692 GNUNET_HELLO_get_id (my_hello, 664 GNUNET_HELLO_get_id (my_hello, &my_peer_identity));
693 &my_peer_identity));
694 GNUNET_TRANSPORT_hello_get_cancel (gh); 665 GNUNET_TRANSPORT_hello_get_cancel (gh);
695 gh = NULL; 666 gh = NULL;
696 if (NULL != dump_hello) 667 if (NULL != dump_hello)
@@ -714,44 +685,35 @@ run (void *cls,
714 const struct GNUNET_CONFIGURATION_Handle *c) 685 const struct GNUNET_CONFIGURATION_Handle *c)
715{ 686{
716 cfg = c; 687 cfg = c;
717 if ( (NULL != args[0]) && 688 if ((NULL != args[0]) && (NULL == put_uri) &&
718 (NULL == put_uri) && 689 (args[0] == strcasestr (args[0], "gnunet://hello/")))
719 (args[0] == strcasestr (args[0],
720 "gnunet://hello/")) )
721 { 690 {
722 put_uri = GNUNET_strdup (args[0]); 691 put_uri = GNUNET_strdup (args[0]);
723 args++; 692 args++;
724 } 693 }
725 if (NULL != args[0]) 694 if (NULL != args[0])
726 { 695 {
727 FPRINTF (stderr, 696 fprintf (stderr, _ ("Invalid command line argument `%s'\n"), args[0]);
728 _("Invalid command line argument `%s'\n"),
729 args[0]);
730 return; 697 return;
731 } 698 }
732 if (NULL == (peerinfo = GNUNET_PEERINFO_connect (cfg))) 699 if (NULL == (peerinfo = GNUNET_PEERINFO_connect (cfg)))
733 { 700 {
734 FPRINTF (stderr, 701 fprintf (stderr, "%s", "Could not access PEERINFO service. Exiting.\n");
735 "%s",
736 "Could not access PEERINFO service. Exiting.\n");
737 return; 702 return;
738 } 703 }
739 if ( (GNUNET_YES == get_self) || 704 if ((GNUNET_YES == get_self) || (GNUNET_YES == get_uri) ||
740 (GNUNET_YES == get_uri) || 705 (NULL != dump_hello))
741 (NULL != dump_hello) )
742 { 706 {
743 gh = GNUNET_TRANSPORT_hello_get (cfg, 707 gh = GNUNET_TRANSPORT_hello_get (cfg,
744 GNUNET_TRANSPORT_AC_ANY, 708 GNUNET_TRANSPORT_AC_ANY,
745 &hello_callback, 709 &hello_callback,
746 NULL); 710 NULL);
747 } 711 }
748 else 712 else
749 { 713 {
750 tt = GNUNET_SCHEDULER_add_now (&state_machine, 714 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
751 NULL);
752 } 715 }
753 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 716 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
754 NULL);
755} 717}
756 718
757 719
@@ -771,9 +733,7 @@ state_machine (void *cls)
771 GPI_plugins_load (cfg); 733 GPI_plugins_load (cfg);
772 if (GNUNET_SYSERR == parse_hello_uri (put_uri)) 734 if (GNUNET_SYSERR == parse_hello_uri (put_uri))
773 { 735 {
774 fprintf (stderr, 736 fprintf (stderr, _ ("Invalid URI `%s'\n"), put_uri);
775 _("Invalid URI `%s'\n"),
776 put_uri);
777 GNUNET_SCHEDULER_shutdown (); 737 GNUNET_SCHEDULER_shutdown ();
778 } 738 }
779 GNUNET_free (put_uri); 739 GNUNET_free (put_uri);
@@ -786,20 +746,17 @@ state_machine (void *cls)
786 pic = GNUNET_PEERINFO_iterate (peerinfo, 746 pic = GNUNET_PEERINFO_iterate (peerinfo,
787 include_friend_only, 747 include_friend_only,
788 NULL, 748 NULL,
789 &print_peer_info, 749 &print_peer_info,
790 NULL); 750 NULL);
791 } 751 }
792 else if (GNUNET_YES == get_self) 752 else if (GNUNET_YES == get_self)
793 { 753 {
794 get_self = GNUNET_NO; 754 get_self = GNUNET_NO;
795 if (be_quiet) 755 if (be_quiet)
796 printf ("%s\n", 756 printf ("%s\n", GNUNET_i2s_full (&my_peer_identity));
797 GNUNET_i2s_full (&my_peer_identity));
798 else 757 else
799 printf (_("I am peer `%s'.\n"), 758 printf (_ ("I am peer `%s'.\n"), GNUNET_i2s_full (&my_peer_identity));
800 GNUNET_i2s_full (&my_peer_identity)); 759 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
801 tt = GNUNET_SCHEDULER_add_now (&state_machine,
802 NULL);
803 } 760 }
804 else if (GNUNET_YES == get_uri) 761 else if (GNUNET_YES == get_uri)
805 { 762 {
@@ -808,7 +765,7 @@ state_machine (void *cls)
808 include_friend_only, 765 include_friend_only,
809 &my_peer_identity, 766 &my_peer_identity,
810 &print_my_uri, 767 &print_my_uri,
811 NULL); 768 NULL);
812 get_uri = GNUNET_NO; 769 get_uri = GNUNET_NO;
813 } 770 }
814 else if (GNUNET_YES == default_operation) 771 else if (GNUNET_YES == default_operation)
@@ -816,8 +773,7 @@ state_machine (void *cls)
816 /* default operation list all */ 773 /* default operation list all */
817 default_operation = GNUNET_NO; 774 default_operation = GNUNET_NO;
818 get_info = GNUNET_YES; 775 get_info = GNUNET_YES;
819 tt = GNUNET_SCHEDULER_add_now (&state_machine, 776 tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
820 NULL);
821 } 777 }
822 else 778 else
823 { 779 {
@@ -837,68 +793,69 @@ state_machine (void *cls)
837int 793int
838main (int argc, char *const *argv) 794main (int argc, char *const *argv)
839{ 795{
840 struct GNUNET_GETOPT_CommandLineOption options[] = { 796 struct GNUNET_GETOPT_CommandLineOption options[] =
841 GNUNET_GETOPT_option_flag ('n', 797 {GNUNET_GETOPT_option_flag ('n',
842 "numeric", 798 "numeric",
843 gettext_noop ("don't resolve host names"), 799 gettext_noop ("don't resolve host names"),
844 &no_resolve), 800 &no_resolve),
845 801
846 GNUNET_GETOPT_option_flag ('q', 802 GNUNET_GETOPT_option_flag ('q',
847 "quiet", 803 "quiet",
848 gettext_noop ("output only the identity strings"), 804 gettext_noop (
849 &be_quiet), 805 "output only the identity strings"),
850 GNUNET_GETOPT_option_flag ('f', 806 &be_quiet),
851 "friends", 807 GNUNET_GETOPT_option_flag ('f',
852 gettext_noop ("include friend-only information"), 808 "friends",
853 &include_friend_only), 809 gettext_noop (
854 810 "include friend-only information"),
855 GNUNET_GETOPT_option_flag ('s', 811 &include_friend_only),
856 "self", 812
857 gettext_noop ("output our own identity only"), 813 GNUNET_GETOPT_option_flag ('s',
858 &get_self), 814 "self",
859 815 gettext_noop ("output our own identity only"),
860 GNUNET_GETOPT_option_flag ('i', 816 &get_self),
861 "info", 817
862 gettext_noop ("list all known peers"), 818 GNUNET_GETOPT_option_flag ('i',
863 &get_info), 819 "info",
864 820 gettext_noop ("list all known peers"),
865 GNUNET_GETOPT_option_string ('d', 821 &get_info),
866 "dump-hello", 822
867 NULL, 823 GNUNET_GETOPT_option_string ('d',
868 gettext_noop ("dump hello to file"), 824 "dump-hello",
869 &dump_hello), 825 NULL,
870 826 gettext_noop ("dump hello to file"),
871 GNUNET_GETOPT_option_flag ('g', 827 &dump_hello),
872 "get-hello", 828
873 gettext_noop ("also output HELLO uri(s)"), 829 GNUNET_GETOPT_option_flag ('g',
874 &get_uri), 830 "get-hello",
875 831 gettext_noop ("also output HELLO uri(s)"),
876 GNUNET_GETOPT_option_string ('p', 832 &get_uri),
877 "put-hello", 833
878 "HELLO", 834 GNUNET_GETOPT_option_string ('p',
879 gettext_noop ("add given HELLO uri to the database"), 835 "put-hello",
880 &put_uri), 836 "HELLO",
881 837 gettext_noop (
882 GNUNET_GETOPT_OPTION_END 838 "add given HELLO uri to the database"),
883 }; 839 &put_uri),
840
841 GNUNET_GETOPT_OPTION_END};
884 int ret; 842 int ret;
885 843
886 default_operation = GNUNET_YES; 844 default_operation = GNUNET_YES;
887 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, 845 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
888 argv,
889 &argc,
890 &argv))
891 return 2; 846 return 2;
892 847
893 ret = (GNUNET_OK == 848 ret = (GNUNET_OK ==
894 GNUNET_PROGRAM_run (argc, 849 GNUNET_PROGRAM_run (argc,
895 argv, 850 argv,
896 "gnunet-peerinfo", 851 "gnunet-peerinfo",
897 gettext_noop ("Print information about peers."), 852 gettext_noop ("Print information about peers."),
898 options, 853 options,
899 &run, 854 &run,
900 NULL)) ? 0 : 1; 855 NULL))
901 GNUNET_free ((void*) argv); 856 ? 0
857 : 1;
858 GNUNET_free ((void *) argv);
902 return ret; 859 return ret;
903} 860}
904 861
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c
index 61fdd0f24..a884c5b76 100644
--- a/src/peerinfo/gnunet-service-peerinfo.c
+++ b/src/peerinfo/gnunet-service-peerinfo.c
@@ -38,12 +38,14 @@
38/** 38/**
39 * How often do we scan the HOST_DIR for new entries? 39 * How often do we scan the HOST_DIR for new entries?
40 */ 40 */
41#define DATA_HOST_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) 41#define DATA_HOST_FREQ \
42 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
42 43
43/** 44/**
44 * How often do we discard old entries in data/hosts/? 45 * How often do we discard old entries in data/hosts/?
45 */ 46 */
46#define DATA_HOST_CLEAN_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 60) 47#define DATA_HOST_CLEAN_FREQ \
48 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 60)
47 49
48 50
49/** 51/**
@@ -66,7 +68,6 @@ struct HostEntry
66 * Friend only hello for the peer (can be NULL) 68 * Friend only hello for the peer (can be NULL)
67 */ 69 */
68 struct GNUNET_HELLO_Message *friend_only_hello; 70 struct GNUNET_HELLO_Message *friend_only_hello;
69
70}; 71};
71 72
72 73
@@ -134,8 +135,7 @@ static struct GNUNET_SCHEDULER_Task *cron_scan;
134 * @return generated notification message 135 * @return generated notification message
135 */ 136 */
136static struct InfoMessage * 137static struct InfoMessage *
137make_info_message (const struct HostEntry *he, 138make_info_message (const struct HostEntry *he, int include_friend_only)
138 int include_friend_only)
139{ 139{
140 struct InfoMessage *im; 140 struct InfoMessage *im;
141 struct GNUNET_HELLO_Message *src; 141 struct GNUNET_HELLO_Message *src;
@@ -150,9 +150,7 @@ make_info_message (const struct HostEntry *he,
150 im->header.size = htons (hs + sizeof (struct InfoMessage)); 150 im->header.size = htons (hs + sizeof (struct InfoMessage));
151 im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO); 151 im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
152 im->peer = he->identity; 152 im->peer = he->identity;
153 GNUNET_memcpy (&im[1], 153 GNUNET_memcpy (&im[1], src, hs);
154 src,
155 hs);
156 return im; 154 return im;
157} 155}
158 156
@@ -175,7 +173,7 @@ discard_expired (void *cls,
175 if (now->abs_value_us > expiration.abs_value_us) 173 if (now->abs_value_us > expiration.abs_value_us)
176 { 174 {
177 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 175 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
178 _("Removing expired address of transport `%s'\n"), 176 _ ("Removing expired address of transport `%s'\n"),
179 address->transport_name); 177 address->transport_name);
180 return GNUNET_NO; 178 return GNUNET_NO;
181 } 179 }
@@ -241,16 +239,14 @@ notify_all (struct HostEntry *entry)
241 struct InfoMessage *msg_friend; 239 struct InfoMessage *msg_friend;
242 240
243 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
244 "Notifying all clients about peer `%s'\n", 242 "Notifying all clients about peer `%s'\n",
245 GNUNET_i2s(&entry->identity)); 243 GNUNET_i2s (&entry->identity));
246 msg_pub = make_info_message (entry, 244 msg_pub = make_info_message (entry, GNUNET_NO);
247 GNUNET_NO);
248 GNUNET_notification_context_broadcast (notify_list, 245 GNUNET_notification_context_broadcast (notify_list,
249 &msg_pub->header, 246 &msg_pub->header,
250 GNUNET_NO); 247 GNUNET_NO);
251 GNUNET_free (msg_pub); 248 GNUNET_free (msg_pub);
252 msg_friend = make_info_message (entry, 249 msg_friend = make_info_message (entry, GNUNET_YES);
253 GNUNET_YES);
254 GNUNET_notification_context_broadcast (notify_friend_only_list, 250 GNUNET_notification_context_broadcast (notify_friend_only_list,
255 &msg_friend->header, 251 &msg_friend->header,
256 GNUNET_NO); 252 GNUNET_NO);
@@ -299,26 +295,21 @@ read_host_file (const char *fn,
299 295
300 if (GNUNET_YES != GNUNET_DISK_file_test (fn)) 296 if (GNUNET_YES != GNUNET_DISK_file_test (fn))
301 return; 297 return;
302 size_total = GNUNET_DISK_fn_read (fn, 298 size_total = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer));
303 buffer,
304 sizeof (buffer));
305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
306 "Read %d bytes from `%s'\n", 300 "Read %d bytes from `%s'\n",
307 (int) size_total, 301 (int) size_total,
308 fn); 302 fn);
309 if ( (size_total < 0) || 303 if ((size_total < 0) ||
310 (((size_t) size_total) < sizeof (struct GNUNET_MessageHeader)) ) 304 (((size_t) size_total) < sizeof (struct GNUNET_MessageHeader)))
311 { 305 {
312 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 306 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
313 _("Failed to parse HELLO in file `%s': %s\n"), 307 _ ("Failed to parse HELLO in file `%s': %s\n"),
314 fn, 308 fn,
315 "File has invalid size"); 309 "File has invalid size");
316 if ( (GNUNET_YES == unlink_garbage) && 310 if ((GNUNET_YES == unlink_garbage) && (0 != unlink (fn)) &&
317 (0 != UNLINK (fn)) && 311 (ENOENT != errno))
318 (ENOENT != errno) ) 312 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
319 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
320 "unlink",
321 fn);
322 return; 313 return;
323 } 314 }
324 315
@@ -327,29 +318,22 @@ read_host_file (const char *fn,
327 { 318 {
328 hello = (const struct GNUNET_HELLO_Message *) &buffer[read_pos]; 319 hello = (const struct GNUNET_HELLO_Message *) &buffer[read_pos];
329 size_hello = GNUNET_HELLO_size (hello); 320 size_hello = GNUNET_HELLO_size (hello);
330 if ( (0 == size_hello) || 321 if ((0 == size_hello) || (((size_t) size_total) - read_pos < size_hello))
331 (((size_t) size_total) - read_pos < size_hello) )
332 { 322 {
333 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 323 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
334 _("Failed to parse HELLO in file `%s'\n"), 324 _ ("Failed to parse HELLO in file `%s'\n"),
335 fn); 325 fn);
336 if (0 == read_pos) 326 if (0 == read_pos)
337 { 327 {
338 if ((GNUNET_YES == unlink_garbage) && 328 if ((GNUNET_YES == unlink_garbage) && (0 != unlink (fn)) &&
339 (0 != UNLINK (fn)) && 329 (ENOENT != errno))
340 (ENOENT != errno) ) 330 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
341 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
342 "unlink",
343 fn);
344 } 331 }
345 else 332 else
346 { 333 {
347 if ( (GNUNET_YES == unlink_garbage) && 334 if ((GNUNET_YES == unlink_garbage) && (0 != truncate (fn, read_pos)) &&
348 (0 != TRUNCATE (fn, read_pos)) && 335 (ENOENT != errno))
349 (ENOENT != errno) ) 336 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "truncate", fn);
350 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
351 "truncate",
352 fn);
353 } 337 }
354 return; 338 return;
355 } 339 }
@@ -357,25 +341,22 @@ read_host_file (const char *fn,
357 now = GNUNET_TIME_absolute_get (); 341 now = GNUNET_TIME_absolute_get ();
358 hello_clean = GNUNET_HELLO_iterate_addresses (hello, 342 hello_clean = GNUNET_HELLO_iterate_addresses (hello,
359 GNUNET_YES, 343 GNUNET_YES,
360 &discard_expired, 344 &discard_expired,
361 &now); 345 &now);
362 if (NULL == hello_clean) 346 if (NULL == hello_clean)
363 { 347 {
364 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 348 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
365 _("Failed to parse HELLO in file `%s'\n"), 349 _ ("Failed to parse HELLO in file `%s'\n"),
366 fn); 350 fn);
367 if ((GNUNET_YES == unlink_garbage) && 351 if ((GNUNET_YES == unlink_garbage) && (0 != unlink (fn)) &&
368 (0 != UNLINK (fn)) && 352 (ENOENT != errno))
369 (ENOENT != errno) ) 353 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
370 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
371 "unlink",
372 fn);
373 return; 354 return;
374 } 355 }
375 left = 0; 356 left = 0;
376 (void) GNUNET_HELLO_iterate_addresses (hello_clean, 357 (void) GNUNET_HELLO_iterate_addresses (hello_clean,
377 GNUNET_NO, 358 GNUNET_NO,
378 &count_addresses, 359 &count_addresses,
379 &left); 360 &left);
380 361
381 if (0 == left) 362 if (0 == left)
@@ -387,23 +368,23 @@ read_host_file (const char *fn,
387 if (GNUNET_NO == GNUNET_HELLO_is_friend_only (hello_clean)) 368 if (GNUNET_NO == GNUNET_HELLO_is_friend_only (hello_clean))
388 { 369 {
389 if (NULL == r->hello) 370 if (NULL == r->hello)
390 r->hello = hello_clean; 371 r->hello = hello_clean;
391 else 372 else
392 { 373 {
393 GNUNET_break (0); 374 GNUNET_break (0);
394 GNUNET_free (r->hello); 375 GNUNET_free (r->hello);
395 r->hello = hello_clean; 376 r->hello = hello_clean;
396 } 377 }
397 } 378 }
398 else 379 else
399 { 380 {
400 if (NULL == r->friend_only_hello) 381 if (NULL == r->friend_only_hello)
401 r->friend_only_hello = hello_clean; 382 r->friend_only_hello = hello_clean;
402 else 383 else
403 { 384 {
404 GNUNET_break (0); 385 GNUNET_break (0);
405 GNUNET_free (r->friend_only_hello); 386 GNUNET_free (r->friend_only_hello);
406 r->friend_only_hello = hello_clean; 387 r->friend_only_hello = hello_clean;
407 } 388 }
408 } 389 }
409 read_pos += size_hello; 390 read_pos += size_hello;
@@ -412,16 +393,14 @@ read_host_file (const char *fn,
412 if (0 == left) 393 if (0 == left)
413 { 394 {
414 /* no addresses left, remove from disk */ 395 /* no addresses left, remove from disk */
415 if ( (GNUNET_YES == unlink_garbage) && 396 if ((GNUNET_YES == unlink_garbage) && (0 != unlink (fn)))
416 (0 != UNLINK (fn)) ) 397 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
417 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
418 "unlink",
419 fn);
420 } 398 }
421 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
422 "Found `%s' and `%s' HELLO message in file\n", 400 "Found `%s' and `%s' HELLO message in file\n",
423 (NULL != r->hello) ? "public" : "NON-public", 401 (NULL != r->hello) ? "public" : "NON-public",
424 (NULL != r->friend_only_hello) ? "friend only" : "NO friend only"); 402 (NULL != r->friend_only_hello) ? "friend only"
403 : "NO friend only");
425} 404}
426 405
427 406
@@ -438,8 +417,7 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity)
438 struct ReadHostFileContext r; 417 struct ReadHostFileContext r;
439 char *fn; 418 char *fn;
440 419
441 entry = GNUNET_CONTAINER_multipeermap_get (hostmap, 420 entry = GNUNET_CONTAINER_multipeermap_get (hostmap, identity);
442 identity);
443 if (NULL == entry) 421 if (NULL == entry)
444 { 422 {
445 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 423 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -448,27 +426,24 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity)
448 GNUNET_STATISTICS_update (stats, 426 GNUNET_STATISTICS_update (stats,
449 gettext_noop ("# peers known"), 427 gettext_noop ("# peers known"),
450 1, 428 1,
451 GNUNET_NO); 429 GNUNET_NO);
452 entry = GNUNET_new (struct HostEntry); 430 entry = GNUNET_new (struct HostEntry);
453 entry->identity = *identity; 431 entry->identity = *identity;
454 GNUNET_assert (GNUNET_OK == 432 GNUNET_assert (GNUNET_OK ==
455 GNUNET_CONTAINER_multipeermap_put (hostmap, 433 GNUNET_CONTAINER_multipeermap_put (
456 &entry->identity, 434 hostmap,
457 entry, 435 &entry->identity,
458 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 436 entry,
437 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
459 notify_all (entry); 438 notify_all (entry);
460 fn = get_host_filename (identity); 439 fn = get_host_filename (identity);
461 if (NULL != fn) 440 if (NULL != fn)
462 { 441 {
463 read_host_file (fn, 442 read_host_file (fn, GNUNET_YES, &r);
464 GNUNET_YES,
465 &r);
466 if (NULL != r.hello) 443 if (NULL != r.hello)
467 update_hello (identity, 444 update_hello (identity, r.hello);
468 r.hello);
469 if (NULL != r.friend_only_hello) 445 if (NULL != r.friend_only_hello)
470 update_hello (identity, 446 update_hello (identity, r.friend_only_hello);
471 r.friend_only_hello);
472 GNUNET_free_non_null (r.hello); 447 GNUNET_free_non_null (r.hello);
473 GNUNET_free_non_null (r.friend_only_hello); 448 GNUNET_free_non_null (r.friend_only_hello);
474 GNUNET_free (fn); 449 GNUNET_free (fn);
@@ -487,11 +462,13 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity)
487static void 462static void
488remove_garbage (const char *fullname) 463remove_garbage (const char *fullname)
489{ 464{
490 if (0 == UNLINK (fullname)) 465 if (0 == unlink (fullname))
491 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, 466 GNUNET_log (
492 _("File `%s' in directory `%s' does not match naming convention. Removed.\n"), 467 GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
493 fullname, 468 _ (
494 networkIdDirectory); 469 "File `%s' in directory `%s' does not match naming convention. Removed.\n"),
470 fullname,
471 networkIdDirectory);
495 else 472 else
496 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 473 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
497 "unlink", 474 "unlink",
@@ -529,8 +506,7 @@ struct DirScanContext
529 * @return #GNUNET_OK (continue iteration) 506 * @return #GNUNET_OK (continue iteration)
530 */ 507 */
531static int 508static int
532hosts_directory_scan_callback (void *cls, 509hosts_directory_scan_callback (void *cls, const char *fullname)
533 const char *fullname)
534{ 510{
535 struct DirScanContext *dsc = cls; 511 struct DirScanContext *dsc = cls;
536 struct GNUNET_PeerIdentity identity; 512 struct GNUNET_PeerIdentity identity;
@@ -541,51 +517,40 @@ hosts_directory_scan_callback (void *cls,
541 struct GNUNET_PeerIdentity id; 517 struct GNUNET_PeerIdentity id;
542 518
543 if (GNUNET_YES != GNUNET_DISK_file_test (fullname)) 519 if (GNUNET_YES != GNUNET_DISK_file_test (fullname))
544 return GNUNET_OK; /* ignore non-files */ 520 return GNUNET_OK; /* ignore non-files */
545 521
546 filename = strrchr (fullname, 522 filename = strrchr (fullname, DIR_SEPARATOR);
547 DIR_SEPARATOR); 523 if ((NULL == filename) || (1 > strlen (filename)))
548 if ( (NULL == filename) ||
549 (1 > strlen (filename)) )
550 filename = fullname; 524 filename = fullname;
551 else 525 else
552 filename ++; 526 filename++;
553 527
554 read_host_file (fullname, 528 read_host_file (fullname, dsc->remove_files, &r);
555 dsc->remove_files, 529 if ((NULL == r.hello) && (NULL == r.friend_only_hello))
556 &r);
557 if ( (NULL == r.hello) &&
558 (NULL == r.friend_only_hello))
559 return GNUNET_OK; 530 return GNUNET_OK;
560 if (NULL != r.friend_only_hello) 531 if (NULL != r.friend_only_hello)
561 { 532 {
562 if (GNUNET_OK != 533 if (GNUNET_OK != GNUNET_HELLO_get_id (r.friend_only_hello, &id_friend))
563 GNUNET_HELLO_get_id (r.friend_only_hello,
564 &id_friend))
565 { 534 {
566 if (GNUNET_YES == dsc->remove_files) 535 if (GNUNET_YES == dsc->remove_files)
567 remove_garbage (fullname); 536 remove_garbage (fullname);
568 return GNUNET_OK; 537 return GNUNET_OK;
569 } 538 }
570 id = id_friend; 539 id = id_friend;
571 } 540 }
572 if (NULL != r.hello) 541 if (NULL != r.hello)
573 { 542 {
574 if (GNUNET_OK != 543 if (GNUNET_OK != GNUNET_HELLO_get_id (r.hello, &id_public))
575 GNUNET_HELLO_get_id (r.hello,
576 &id_public))
577 { 544 {
578 if (GNUNET_YES == dsc->remove_files) 545 if (GNUNET_YES == dsc->remove_files)
579 remove_garbage (fullname); 546 remove_garbage (fullname);
580 return GNUNET_OK; 547 return GNUNET_OK;
581 } 548 }
582 id = id_public; 549 id = id_public;
583 } 550 }
584 551
585 if ( (NULL != r.hello) && 552 if ((NULL != r.hello) && (NULL != r.friend_only_hello) &&
586 (NULL != r.friend_only_hello) && 553 (0 != GNUNET_memcmp (&id_friend, &id_public)))
587 (0 != GNUNET_memcmp (&id_friend,
588 &id_public)) )
589 { 554 {
590 /* HELLOs are not for the same peer */ 555 /* HELLOs are not for the same peer */
591 GNUNET_break (0); 556 GNUNET_break (0);
@@ -603,7 +568,7 @@ hosts_directory_scan_callback (void *cls,
603 /* HELLOs are not for the same peer */ 568 /* HELLOs are not for the same peer */
604 GNUNET_break (0); 569 GNUNET_break (0);
605 if (GNUNET_YES == dsc->remove_files) 570 if (GNUNET_YES == dsc->remove_files)
606 remove_garbage (fullname); 571 remove_garbage (fullname);
607 return GNUNET_OK; 572 return GNUNET_OK;
608 } 573 }
609 } 574 }
@@ -614,7 +579,7 @@ hosts_directory_scan_callback (void *cls,
614 { 579 {
615 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 580 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
616 "Updating peer `%s' public HELLO \n", 581 "Updating peer `%s' public HELLO \n",
617 GNUNET_i2s (&id)); 582 GNUNET_i2s (&id));
618 update_hello (&id, r.hello); 583 update_hello (&id, r.hello);
619 GNUNET_free (r.hello); 584 GNUNET_free (r.hello);
620 } 585 }
@@ -622,7 +587,7 @@ hosts_directory_scan_callback (void *cls,
622 { 587 {
623 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 588 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
624 "Updating peer `%s' friend only HELLO \n", 589 "Updating peer `%s' friend only HELLO \n",
625 GNUNET_i2s (&id)); 590 GNUNET_i2s (&id));
626 update_hello (&id, r.friend_only_hello); 591 update_hello (&id, r.friend_only_hello);
627 GNUNET_free (r.friend_only_hello); 592 GNUNET_free (r.friend_only_hello);
628 } 593 }
@@ -644,31 +609,32 @@ cron_scan_directory_data_hosts (void *cls)
644 609
645 (void) cls; 610 (void) cls;
646 cron_scan = NULL; 611 cron_scan = NULL;
647 if (GNUNET_SYSERR == 612 if (GNUNET_SYSERR == GNUNET_DISK_directory_create (networkIdDirectory))
648 GNUNET_DISK_directory_create (networkIdDirectory))
649 { 613 {
650 cron_scan = GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ, 614 cron_scan =
651 GNUNET_SCHEDULER_PRIORITY_IDLE, 615 GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ,
652 &cron_scan_directory_data_hosts, NULL); 616 GNUNET_SCHEDULER_PRIORITY_IDLE,
617 &cron_scan_directory_data_hosts,
618 NULL);
653 return; 619 return;
654 } 620 }
655 dsc.matched = 0; 621 dsc.matched = 0;
656 dsc.remove_files = GNUNET_YES; 622 dsc.remove_files = GNUNET_YES;
657 GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, 623 GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
658 _("Scanning directory `%s'\n"), 624 _ ("Scanning directory `%s'\n"),
659 networkIdDirectory); 625 networkIdDirectory);
660 GNUNET_DISK_directory_scan (networkIdDirectory, 626 GNUNET_DISK_directory_scan (networkIdDirectory,
661 &hosts_directory_scan_callback, 627 &hosts_directory_scan_callback,
662 &dsc); 628 &dsc);
663 if ( (0 == dsc.matched) && 629 if ((0 == dsc.matched) && (0 == (++retries & 31)))
664 (0 == (++retries & 31)) )
665 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, 630 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
666 _("Still no peers found in `%s'!\n"), 631 _ ("Still no peers found in `%s'!\n"),
667 networkIdDirectory); 632 networkIdDirectory);
668 cron_scan = GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ, 633 cron_scan =
669 GNUNET_SCHEDULER_PRIORITY_IDLE, 634 GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ,
670 &cron_scan_directory_data_hosts, 635 GNUNET_SCHEDULER_PRIORITY_IDLE,
671 NULL); 636 &cron_scan_directory_data_hosts,
637 NULL);
672} 638}
673 639
674 640
@@ -681,31 +647,25 @@ cron_scan_directory_data_hosts (void *cls)
681 */ 647 */
682static struct GNUNET_HELLO_Message * 648static struct GNUNET_HELLO_Message *
683update_friend_hello (const struct GNUNET_HELLO_Message *hello, 649update_friend_hello (const struct GNUNET_HELLO_Message *hello,
684 const struct GNUNET_HELLO_Message *friend_hello) 650 const struct GNUNET_HELLO_Message *friend_hello)
685{ 651{
686 struct GNUNET_HELLO_Message * res; 652 struct GNUNET_HELLO_Message *res;
687 struct GNUNET_HELLO_Message * tmp; 653 struct GNUNET_HELLO_Message *tmp;
688 struct GNUNET_PeerIdentity pid; 654 struct GNUNET_PeerIdentity pid;
689 655
690 if (NULL != friend_hello) 656 if (NULL != friend_hello)
691 { 657 {
692 res = GNUNET_HELLO_merge (hello, 658 res = GNUNET_HELLO_merge (hello, friend_hello);
693 friend_hello); 659 GNUNET_assert (GNUNET_YES == GNUNET_HELLO_is_friend_only (res));
694 GNUNET_assert (GNUNET_YES ==
695 GNUNET_HELLO_is_friend_only (res));
696 return res; 660 return res;
697 } 661 }
698 662
699 if (GNUNET_OK != 663 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid))
700 GNUNET_HELLO_get_id (hello, &pid))
701 { 664 {
702 GNUNET_break (0); 665 GNUNET_break (0);
703 return NULL; 666 return NULL;
704 } 667 }
705 tmp = GNUNET_HELLO_create (&pid.public_key, 668 tmp = GNUNET_HELLO_create (&pid.public_key, NULL, NULL, GNUNET_YES);
706 NULL,
707 NULL,
708 GNUNET_YES);
709 res = GNUNET_HELLO_merge (hello, tmp); 669 res = GNUNET_HELLO_merge (hello, tmp);
710 GNUNET_free (tmp); 670 GNUNET_free (tmp);
711 GNUNET_assert (GNUNET_YES == GNUNET_HELLO_is_friend_only (res)); 671 GNUNET_assert (GNUNET_YES == GNUNET_HELLO_is_friend_only (res));
@@ -762,11 +722,8 @@ update_hello (const struct GNUNET_PeerIdentity *peer,
762 } 722 }
763 else 723 else
764 { 724 {
765 mrg = GNUNET_HELLO_merge ((*dest), 725 mrg = GNUNET_HELLO_merge ((*dest), hello);
766 hello); 726 delta = GNUNET_HELLO_equals (mrg, (*dest), GNUNET_TIME_absolute_get ());
767 delta = GNUNET_HELLO_equals (mrg,
768 (*dest),
769 GNUNET_TIME_absolute_get ());
770 if (delta.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) 727 if (delta.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
771 { 728 {
772 /* no differences, just ignore the update */ 729 /* no differences, just ignore the update */
@@ -781,35 +738,30 @@ update_hello (const struct GNUNET_PeerIdentity *peer,
781 (*dest) = mrg; 738 (*dest) = mrg;
782 } 739 }
783 740
784 if ( (NULL != (host->hello)) && 741 if ((NULL != (host->hello)) && (GNUNET_NO == friend_hello_type))
785 (GNUNET_NO == friend_hello_type) )
786 { 742 {
787 /* Update friend only hello */ 743 /* Update friend only hello */
788 mrg = update_friend_hello (host->hello, 744 mrg = update_friend_hello (host->hello, host->friend_only_hello);
789 host->friend_only_hello);
790 if (NULL != host->friend_only_hello) 745 if (NULL != host->friend_only_hello)
791 GNUNET_free (host->friend_only_hello); 746 GNUNET_free (host->friend_only_hello);
792 host->friend_only_hello = mrg; 747 host->friend_only_hello = mrg;
793 } 748 }
794 749
795 if (NULL != host->hello) 750 if (NULL != host->hello)
796 GNUNET_assert ((GNUNET_NO == 751 GNUNET_assert ((GNUNET_NO == GNUNET_HELLO_is_friend_only (host->hello)));
797 GNUNET_HELLO_is_friend_only (host->hello)));
798 if (NULL != host->friend_only_hello) 752 if (NULL != host->friend_only_hello)
799 GNUNET_assert ((GNUNET_YES == 753 GNUNET_assert (
800 GNUNET_HELLO_is_friend_only (host->friend_only_hello))); 754 (GNUNET_YES == GNUNET_HELLO_is_friend_only (host->friend_only_hello)));
801 755
802 fn = get_host_filename (peer); 756 fn = get_host_filename (peer);
803 if ( (NULL != fn) && 757 if ((NULL != fn) && (GNUNET_OK == GNUNET_DISK_directory_create_for_file (fn)))
804 (GNUNET_OK ==
805 GNUNET_DISK_directory_create_for_file (fn)) )
806 { 758 {
807 store_hello = GNUNET_NO; 759 store_hello = GNUNET_NO;
808 size = 0; 760 size = 0;
809 cnt = 0; 761 cnt = 0;
810 if (NULL != host->hello) 762 if (NULL != host->hello)
811 (void) GNUNET_HELLO_iterate_addresses (host->hello, 763 (void) GNUNET_HELLO_iterate_addresses (host->hello,
812 GNUNET_NO, 764 GNUNET_NO,
813 &count_addresses, 765 &count_addresses,
814 &cnt); 766 &cnt);
815 if (cnt > 0) 767 if (cnt > 0)
@@ -821,7 +773,7 @@ update_hello (const struct GNUNET_PeerIdentity *peer,
821 if (NULL != host->friend_only_hello) 773 if (NULL != host->friend_only_hello)
822 (void) GNUNET_HELLO_iterate_addresses (host->friend_only_hello, 774 (void) GNUNET_HELLO_iterate_addresses (host->friend_only_hello,
823 GNUNET_NO, 775 GNUNET_NO,
824 &count_addresses, 776 &count_addresses,
825 &cnt); 777 &cnt);
826 store_friend_hello = GNUNET_NO; 778 store_friend_hello = GNUNET_NO;
827 if (0 < cnt) 779 if (0 < cnt)
@@ -830,12 +782,11 @@ update_hello (const struct GNUNET_PeerIdentity *peer,
830 size += GNUNET_HELLO_size (host->friend_only_hello); 782 size += GNUNET_HELLO_size (host->friend_only_hello);
831 } 783 }
832 784
833 if ( (GNUNET_NO == store_hello) && 785 if ((GNUNET_NO == store_hello) && (GNUNET_NO == store_friend_hello))
834 (GNUNET_NO == store_friend_hello) )
835 { 786 {
836 /* no valid addresses, don't put HELLO on disk; in fact, 787 /* no valid addresses, don't put HELLO on disk; in fact,
837 if one exists on disk, remove it */ 788 if one exists on disk, remove it */
838 (void) UNLINK (fn); 789 (void) unlink (fn);
839 } 790 }
840 else 791 else
841 { 792 {
@@ -844,32 +795,32 @@ update_hello (const struct GNUNET_PeerIdentity *peer,
844 795
845 if (GNUNET_YES == store_hello) 796 if (GNUNET_YES == store_hello)
846 { 797 {
847 GNUNET_memcpy (buffer, 798 GNUNET_memcpy (buffer, host->hello, GNUNET_HELLO_size (host->hello));
848 host->hello, 799 pos += GNUNET_HELLO_size (host->hello);
849 GNUNET_HELLO_size (host->hello));
850 pos += GNUNET_HELLO_size (host->hello);
851 } 800 }
852 if (GNUNET_YES == store_friend_hello) 801 if (GNUNET_YES == store_friend_hello)
853 { 802 {
854 GNUNET_memcpy (&buffer[pos], 803 GNUNET_memcpy (&buffer[pos],
855 host->friend_only_hello, 804 host->friend_only_hello,
856 GNUNET_HELLO_size (host->friend_only_hello)); 805 GNUNET_HELLO_size (host->friend_only_hello));
857 pos += GNUNET_HELLO_size (host->friend_only_hello); 806 pos += GNUNET_HELLO_size (host->friend_only_hello);
858 } 807 }
859 GNUNET_assert (pos == size); 808 GNUNET_assert (pos == size);
860 809
861 if (GNUNET_SYSERR == GNUNET_DISK_fn_write (fn, buffer, size, 810 if (GNUNET_SYSERR == GNUNET_DISK_fn_write (fn,
862 GNUNET_DISK_PERM_USER_READ | 811 buffer,
863 GNUNET_DISK_PERM_USER_WRITE | 812 size,
864 GNUNET_DISK_PERM_GROUP_READ | 813 GNUNET_DISK_PERM_USER_READ |
865 GNUNET_DISK_PERM_OTHER_READ)) 814 GNUNET_DISK_PERM_USER_WRITE |
866 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); 815 GNUNET_DISK_PERM_GROUP_READ |
816 GNUNET_DISK_PERM_OTHER_READ))
817 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn);
867 else 818 else
868 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 819 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
869 "Stored %s %s HELLO in %s with total size %u\n", 820 "Stored %s %s HELLO in %s with total size %u\n",
870 (GNUNET_YES == store_friend_hello) ? "friend-only": "", 821 (GNUNET_YES == store_friend_hello) ? "friend-only" : "",
871 (GNUNET_YES == store_hello) ? "public": "", 822 (GNUNET_YES == store_hello) ? "public" : "",
872 fn, 823 fn,
873 size); 824 size);
874 GNUNET_free (buffer); 825 GNUNET_free (buffer);
875 } 826 }
@@ -905,9 +856,7 @@ struct TransmitContext
905 * @return #GNUNET_YES (continue to iterate) 856 * @return #GNUNET_YES (continue to iterate)
906 */ 857 */
907static int 858static int
908add_to_tc (void *cls, 859add_to_tc (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
909 const struct GNUNET_PeerIdentity *key,
910 void *value)
911{ 860{
912 struct TransmitContext *tc = cls; 861 struct TransmitContext *tc = cls;
913 struct HostEntry *pos = value; 862 struct HostEntry *pos = value;
@@ -917,53 +866,39 @@ add_to_tc (void *cls,
917 866
918 hs = 0; 867 hs = 0;
919 868
920 if ( (NULL != pos->hello) && 869 if ((NULL != pos->hello) && (GNUNET_NO == tc->friend_only))
921 (GNUNET_NO == tc->friend_only) )
922 { 870 {
923 /* Copy public HELLO */ 871 /* Copy public HELLO */
924 hs = GNUNET_HELLO_size (pos->hello); 872 hs = GNUNET_HELLO_size (pos->hello);
925 GNUNET_assert (hs < GNUNET_MAX_MESSAGE_SIZE - 873 GNUNET_assert (hs < GNUNET_MAX_MESSAGE_SIZE - sizeof (struct InfoMessage));
926 sizeof (struct InfoMessage)); 874 env = GNUNET_MQ_msg_extra (im, hs, GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
927 env = GNUNET_MQ_msg_extra (im, 875 GNUNET_memcpy (&im[1], pos->hello, hs);
928 hs,
929 GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
930 GNUNET_memcpy (&im[1],
931 pos->hello,
932 hs);
933 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 876 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
934 "Sending public HELLO with size %u for peer `%s'\n", 877 "Sending public HELLO with size %u for peer `%s'\n",
935 hs, 878 hs,
936 GNUNET_i2s (key)); 879 GNUNET_i2s (key));
937 } 880 }
938 else if ( (NULL != pos->friend_only_hello) && 881 else if ((NULL != pos->friend_only_hello) && (GNUNET_YES == tc->friend_only))
939 (GNUNET_YES == tc->friend_only) )
940 { 882 {
941 /* Copy friend only HELLO */ 883 /* Copy friend only HELLO */
942 hs = GNUNET_HELLO_size (pos->friend_only_hello); 884 hs = GNUNET_HELLO_size (pos->friend_only_hello);
943 GNUNET_assert (hs < GNUNET_MAX_MESSAGE_SIZE - 885 GNUNET_assert (hs < GNUNET_MAX_MESSAGE_SIZE - sizeof (struct InfoMessage));
944 sizeof (struct InfoMessage)); 886 env = GNUNET_MQ_msg_extra (im, hs, GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
945 env = GNUNET_MQ_msg_extra (im, 887 GNUNET_memcpy (&im[1], pos->friend_only_hello, hs);
946 hs,
947 GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
948 GNUNET_memcpy (&im[1],
949 pos->friend_only_hello,
950 hs);
951 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 888 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
952 "Sending friend-only HELLO with size %u for peer `%s'\n", 889 "Sending friend-only HELLO with size %u for peer `%s'\n",
953 hs, 890 hs,
954 GNUNET_i2s (key)); 891 GNUNET_i2s (key));
955 } 892 }
956 else 893 else
957 { 894 {
958 env = GNUNET_MQ_msg (im, 895 env = GNUNET_MQ_msg (im, GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
959 GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
960 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 896 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
961 "Adding no HELLO for peer `%s'\n", 897 "Adding no HELLO for peer `%s'\n",
962 GNUNET_i2s (key)); 898 GNUNET_i2s (key));
963 } 899 }
964 im->peer = pos->identity; 900 im->peer = pos->identity;
965 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (tc->client), 901 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (tc->client), env);
966 env);
967 return GNUNET_YES; 902 return GNUNET_YES;
968} 903}
969 904
@@ -976,8 +911,7 @@ add_to_tc (void *cls,
976 * @return #GNUNET_OK (continue iteration) 911 * @return #GNUNET_OK (continue iteration)
977 */ 912 */
978static int 913static int
979discard_hosts_helper (void *cls, 914discard_hosts_helper (void *cls, const char *fn)
980 const char *fn)
981{ 915{
982 struct GNUNET_TIME_Absolute *now = cls; 916 struct GNUNET_TIME_Absolute *now = cls;
983 char buffer[GNUNET_MAX_MESSAGE_SIZE - 1] GNUNET_ALIGN; 917 char buffer[GNUNET_MAX_MESSAGE_SIZE - 1] GNUNET_ALIGN;
@@ -991,31 +925,25 @@ discard_hosts_helper (void *cls,
991 unsigned int cnt; 925 unsigned int cnt;
992 char *writebuffer; 926 char *writebuffer;
993 uint64_t fsize; 927 uint64_t fsize;
994 928
995 if (GNUNET_OK != 929 if (GNUNET_OK != GNUNET_DISK_file_size (fn, &fsize, GNUNET_YES, GNUNET_YES))
996 GNUNET_DISK_file_size (fn,
997 &fsize,
998 GNUNET_YES,
999 GNUNET_YES))
1000 { 930 {
1001 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | 931 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
1002 GNUNET_ERROR_TYPE_BULK, 932 GNUNET_ERROR_TYPE_BULK,
1003 "fstat", 933 "fstat",
1004 fn); 934 fn);
1005 return GNUNET_OK; 935 return GNUNET_OK;
1006 } 936 }
1007 read_size = GNUNET_DISK_fn_read (fn, 937 read_size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer));
1008 buffer,
1009 sizeof (buffer));
1010 938
1011 if ( (read_size < (int) sizeof (struct GNUNET_MessageHeader)) || 939 if ((read_size < (int) sizeof (struct GNUNET_MessageHeader)) ||
1012 (fsize > GNUNET_MAX_MESSAGE_SIZE) ) 940 (fsize > GNUNET_MAX_MESSAGE_SIZE))
1013 { 941 {
1014 if (0 != UNLINK (fn)) 942 if (0 != unlink (fn))
1015 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | 943 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
1016 GNUNET_ERROR_TYPE_BULK, 944 GNUNET_ERROR_TYPE_BULK,
1017 "unlink", 945 "unlink",
1018 fn); 946 fn);
1019 return GNUNET_OK; 947 return GNUNET_OK;
1020 } 948 }
1021 949
@@ -1030,31 +958,27 @@ discard_hosts_helper (void *cls,
1030 if (0 == cur_hello_size) 958 if (0 == cur_hello_size)
1031 { 959 {
1032 /* Invalid data, discard */ 960 /* Invalid data, discard */
1033 if (0 != UNLINK (fn)) 961 if (0 != unlink (fn))
1034 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | 962 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
1035 GNUNET_ERROR_TYPE_BULK, 963 GNUNET_ERROR_TYPE_BULK,
1036 "unlink", 964 "unlink",
1037 fn); 965 fn);
1038 GNUNET_free (writebuffer); 966 GNUNET_free (writebuffer);
1039 return GNUNET_OK; 967 return GNUNET_OK;
1040 } 968 }
1041 new_hello = GNUNET_HELLO_iterate_addresses (hello, 969 new_hello =
1042 GNUNET_YES, 970 GNUNET_HELLO_iterate_addresses (hello, GNUNET_YES, &discard_expired, now);
1043 &discard_expired,
1044 now);
1045 cnt = 0; 971 cnt = 0;
1046 if (NULL != new_hello) 972 if (NULL != new_hello)
1047 (void) GNUNET_HELLO_iterate_addresses (hello, 973 (void) GNUNET_HELLO_iterate_addresses (hello,
1048 GNUNET_NO, 974 GNUNET_NO,
1049 &count_addresses, 975 &count_addresses,
1050 &cnt); 976 &cnt);
1051 if ( (NULL != new_hello) && (0 < cnt) ) 977 if ((NULL != new_hello) && (0 < cnt))
1052 { 978 {
1053 /* Store new HELLO to write it when done */ 979 /* Store new HELLO to write it when done */
1054 new_hello_size = GNUNET_HELLO_size (new_hello); 980 new_hello_size = GNUNET_HELLO_size (new_hello);
1055 GNUNET_memcpy (&writebuffer[write_pos], 981 GNUNET_memcpy (&writebuffer[write_pos], new_hello, new_hello_size);
1056 new_hello,
1057 new_hello_size);
1058 write_pos += new_hello_size; 982 write_pos += new_hello_size;
1059 } 983 }
1060 read_pos += cur_hello_size; 984 read_pos += cur_hello_size;
@@ -1067,14 +991,15 @@ discard_hosts_helper (void *cls,
1067 writebuffer, 991 writebuffer,
1068 write_pos, 992 write_pos,
1069 GNUNET_DISK_PERM_USER_READ | 993 GNUNET_DISK_PERM_USER_READ |
1070 GNUNET_DISK_PERM_USER_WRITE | 994 GNUNET_DISK_PERM_USER_WRITE |
1071 GNUNET_DISK_PERM_GROUP_READ | 995 GNUNET_DISK_PERM_GROUP_READ |
1072 GNUNET_DISK_PERM_OTHER_READ); 996 GNUNET_DISK_PERM_OTHER_READ);
1073 } 997 }
1074 else if (0 != UNLINK (fn)) 998 else if (0 != unlink (fn))
1075 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | 999 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
1076 GNUNET_ERROR_TYPE_BULK, 1000 GNUNET_ERROR_TYPE_BULK,
1077 "unlink", fn); 1001 "unlink",
1002 fn);
1078 1003
1079 GNUNET_free (writebuffer); 1004 GNUNET_free (writebuffer);
1080 return GNUNET_OK; 1005 return GNUNET_OK;
@@ -1096,14 +1021,12 @@ cron_clean_data_hosts (void *cls)
1096 cron_clean = NULL; 1021 cron_clean = NULL;
1097 now = GNUNET_TIME_absolute_get (); 1022 now = GNUNET_TIME_absolute_get ();
1098 GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, 1023 GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
1099 _("Cleaning up directory `%s'\n"), 1024 _ ("Cleaning up directory `%s'\n"),
1100 networkIdDirectory); 1025 networkIdDirectory);
1101 GNUNET_DISK_directory_scan (networkIdDirectory, 1026 GNUNET_DISK_directory_scan (networkIdDirectory, &discard_hosts_helper, &now);
1102 &discard_hosts_helper,
1103 &now);
1104 cron_clean = GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ, 1027 cron_clean = GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ,
1105 &cron_clean_data_hosts, 1028 &cron_clean_data_hosts,
1106 NULL); 1029 NULL);
1107} 1030}
1108 1031
1109 1032
@@ -1115,15 +1038,12 @@ cron_clean_data_hosts (void *cls)
1115 * @return #GNUNET_OK if @a hello is well-formed 1038 * @return #GNUNET_OK if @a hello is well-formed
1116 */ 1039 */
1117static int 1040static int
1118check_hello (void *cls, 1041check_hello (void *cls, const struct GNUNET_HELLO_Message *hello)
1119 const struct GNUNET_HELLO_Message *hello)
1120{ 1042{
1121 struct GNUNET_PeerIdentity pid; 1043 struct GNUNET_PeerIdentity pid;
1122 1044
1123 (void) cls; 1045 (void) cls;
1124 if (GNUNET_OK != 1046 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid))
1125 GNUNET_HELLO_get_id (hello,
1126 &pid))
1127 { 1047 {
1128 GNUNET_break (0); 1048 GNUNET_break (0);
1129 return GNUNET_SYSERR; 1049 return GNUNET_SYSERR;
@@ -1139,21 +1059,17 @@ check_hello (void *cls,
1139 * @param hello the actual message 1059 * @param hello the actual message
1140 */ 1060 */
1141static void 1061static void
1142handle_hello (void *cls, 1062handle_hello (void *cls, const struct GNUNET_HELLO_Message *hello)
1143 const struct GNUNET_HELLO_Message *hello)
1144{ 1063{
1145 struct GNUNET_SERVICE_Client *client = cls; 1064 struct GNUNET_SERVICE_Client *client = cls;
1146 struct GNUNET_PeerIdentity pid; 1065 struct GNUNET_PeerIdentity pid;
1147 1066
1148 GNUNET_assert (GNUNET_OK == 1067 GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_id (hello, &pid));
1149 GNUNET_HELLO_get_id (hello,
1150 &pid));
1151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1068 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1152 "HELLO message received for peer `%s'\n", 1069 "HELLO message received for peer `%s'\n",
1153 GNUNET_i2s (&pid)); 1070 GNUNET_i2s (&pid));
1154 add_host_to_known_hosts (&pid); 1071 add_host_to_known_hosts (&pid);
1155 update_hello (&pid, 1072 update_hello (&pid, hello);
1156 hello);
1157 GNUNET_SERVICE_client_continue (client); 1073 GNUNET_SERVICE_client_continue (client);
1158} 1074}
1159 1075
@@ -1165,8 +1081,7 @@ handle_hello (void *cls,
1165 * @param lpm the actual message 1081 * @param lpm the actual message
1166 */ 1082 */
1167static void 1083static void
1168handle_get (void *cls, 1084handle_get (void *cls, const struct ListPeerMessage *lpm)
1169 const struct ListPeerMessage *lpm)
1170{ 1085{
1171 struct GNUNET_SERVICE_Client *client = cls; 1086 struct GNUNET_SERVICE_Client *client = cls;
1172 struct TransmitContext tcx; 1087 struct TransmitContext tcx;
@@ -1182,10 +1097,8 @@ handle_get (void *cls,
1182 &lpm->peer, 1097 &lpm->peer,
1183 &add_to_tc, 1098 &add_to_tc,
1184 &tcx); 1099 &tcx);
1185 env = GNUNET_MQ_msg (msg, 1100 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
1186 GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); 1101 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
1187 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
1188 env);
1189 GNUNET_SERVICE_client_continue (client); 1102 GNUNET_SERVICE_client_continue (client);
1190} 1103}
1191 1104
@@ -1197,25 +1110,19 @@ handle_get (void *cls,
1197 * @param lapm the actual message 1110 * @param lapm the actual message
1198 */ 1111 */
1199static void 1112static void
1200handle_get_all (void *cls, 1113handle_get_all (void *cls, const struct ListAllPeersMessage *lapm)
1201 const struct ListAllPeersMessage *lapm)
1202{ 1114{
1203 struct GNUNET_SERVICE_Client *client = cls; 1115 struct GNUNET_SERVICE_Client *client = cls;
1204 struct TransmitContext tcx; 1116 struct TransmitContext tcx;
1205 struct GNUNET_MQ_Envelope *env; 1117 struct GNUNET_MQ_Envelope *env;
1206 struct GNUNET_MessageHeader *msg; 1118 struct GNUNET_MessageHeader *msg;
1207 1119
1208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GET_ALL message received\n");
1209 "GET_ALL message received\n");
1210 tcx.friend_only = ntohl (lapm->include_friend_only); 1121 tcx.friend_only = ntohl (lapm->include_friend_only);
1211 tcx.client = client; 1122 tcx.client = client;
1212 GNUNET_CONTAINER_multipeermap_iterate (hostmap, 1123 GNUNET_CONTAINER_multipeermap_iterate (hostmap, &add_to_tc, &tcx);
1213 &add_to_tc, 1124 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
1214 &tcx); 1125 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
1215 env = GNUNET_MQ_msg (msg,
1216 GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
1217 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
1218 env);
1219 GNUNET_SERVICE_client_continue (client); 1126 GNUNET_SERVICE_client_continue (client);
1220} 1127}
1221 1128
@@ -1227,8 +1134,7 @@ handle_get_all (void *cls,
1227 * @param nm the actual message 1134 * @param nm the actual message
1228 */ 1135 */
1229static void 1136static void
1230handle_notify (void *cls, 1137handle_notify (void *cls, const struct NotifyMessage *nm)
1231 const struct NotifyMessage *nm)
1232{ 1138{
1233 struct GNUNET_SERVICE_Client *client = cls; 1139 struct GNUNET_SERVICE_Client *client = cls;
1234 struct GNUNET_MQ_Handle *mq; 1140 struct GNUNET_MQ_Handle *mq;
@@ -1236,25 +1142,18 @@ handle_notify (void *cls,
1236 struct GNUNET_MQ_Envelope *env; 1142 struct GNUNET_MQ_Envelope *env;
1237 struct GNUNET_MessageHeader *msg; 1143 struct GNUNET_MessageHeader *msg;
1238 1144
1239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "NOTIFY message received\n");
1240 "NOTIFY message received\n");
1241 mq = GNUNET_SERVICE_client_get_mq (client); 1146 mq = GNUNET_SERVICE_client_get_mq (client);
1242 GNUNET_SERVICE_client_mark_monitor (client); 1147 GNUNET_SERVICE_client_mark_monitor (client);
1243 if (ntohl (nm->include_friend_only)) 1148 if (ntohl (nm->include_friend_only))
1244 GNUNET_notification_context_add (notify_friend_only_list, 1149 GNUNET_notification_context_add (notify_friend_only_list, mq);
1245 mq);
1246 else 1150 else
1247 GNUNET_notification_context_add (notify_list, 1151 GNUNET_notification_context_add (notify_list, mq);
1248 mq);
1249 tcx.friend_only = ntohl (nm->include_friend_only); 1152 tcx.friend_only = ntohl (nm->include_friend_only);
1250 tcx.client = client; 1153 tcx.client = client;
1251 GNUNET_CONTAINER_multipeermap_iterate (hostmap, 1154 GNUNET_CONTAINER_multipeermap_iterate (hostmap, &add_to_tc, &tcx);
1252 &add_to_tc, 1155 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
1253 &tcx); 1156 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
1254 env = GNUNET_MQ_msg (msg,
1255 GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
1256 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
1257 env);
1258 GNUNET_SERVICE_client_continue (client); 1157 GNUNET_SERVICE_client_continue (client);
1259} 1158}
1260 1159
@@ -1304,9 +1203,7 @@ client_disconnect_cb (void *cls,
1304 * @return #GNUNET_YES (continue to iterate) 1203 * @return #GNUNET_YES (continue to iterate)
1305 */ 1204 */
1306static int 1205static int
1307free_host_entry (void *cls, 1206free_host_entry (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
1308 const struct GNUNET_PeerIdentity *key,
1309 void *value)
1310{ 1207{
1311 struct HostEntry *he = value; 1208 struct HostEntry *he = value;
1312 1209
@@ -1333,14 +1230,11 @@ shutdown_task (void *cls)
1333 GNUNET_notification_context_destroy (notify_friend_only_list); 1230 GNUNET_notification_context_destroy (notify_friend_only_list);
1334 notify_friend_only_list = NULL; 1231 notify_friend_only_list = NULL;
1335 1232
1336 GNUNET_CONTAINER_multipeermap_iterate (hostmap, 1233 GNUNET_CONTAINER_multipeermap_iterate (hostmap, &free_host_entry, NULL);
1337 &free_host_entry,
1338 NULL);
1339 GNUNET_CONTAINER_multipeermap_destroy (hostmap); 1234 GNUNET_CONTAINER_multipeermap_destroy (hostmap);
1340 if (NULL != stats) 1235 if (NULL != stats)
1341 { 1236 {
1342 GNUNET_STATISTICS_destroy (stats, 1237 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
1343 GNUNET_NO);
1344 stats = NULL; 1238 stats = NULL;
1345 } 1239 }
1346 if (NULL != cron_clean) 1240 if (NULL != cron_clean)
@@ -1381,60 +1275,48 @@ run (void *cls,
1381 1275
1382 (void) cls; 1276 (void) cls;
1383 (void) service; 1277 (void) service;
1384 hostmap 1278 hostmap = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES);
1385 = GNUNET_CONTAINER_multipeermap_create (1024, 1279 stats = GNUNET_STATISTICS_create ("peerinfo", cfg);
1386 GNUNET_YES); 1280 notify_list = GNUNET_notification_context_create (0);
1387 stats 1281 notify_friend_only_list = GNUNET_notification_context_create (0);
1388 = GNUNET_STATISTICS_create ("peerinfo", 1282 noio = GNUNET_CONFIGURATION_get_value_yesno (cfg, "peerinfo", "NO_IO");
1389 cfg); 1283 use_included = GNUNET_CONFIGURATION_get_value_yesno (cfg,
1390 notify_list 1284 "peerinfo",
1391 = GNUNET_notification_context_create (0); 1285 "USE_INCLUDED_HELLOS");
1392 notify_friend_only_list
1393 = GNUNET_notification_context_create (0);
1394 noio = GNUNET_CONFIGURATION_get_value_yesno (cfg,
1395 "peerinfo",
1396 "NO_IO");
1397 use_included
1398 = GNUNET_CONFIGURATION_get_value_yesno (cfg,
1399 "peerinfo",
1400 "USE_INCLUDED_HELLOS");
1401 if (GNUNET_SYSERR == use_included) 1286 if (GNUNET_SYSERR == use_included)
1402 use_included = GNUNET_NO; 1287 use_included = GNUNET_NO;
1403 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 1288 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1404 NULL);
1405 if (GNUNET_YES != noio) 1289 if (GNUNET_YES != noio)
1406 { 1290 {
1407 GNUNET_assert (GNUNET_OK == 1291 GNUNET_assert (
1408 GNUNET_CONFIGURATION_get_value_filename (cfg, 1292 GNUNET_OK ==
1409 "peerinfo", 1293 GNUNET_CONFIGURATION_get_value_filename (cfg,
1410 "HOSTS", 1294 "peerinfo",
1411 &networkIdDirectory)); 1295 "HOSTS",
1412 if (GNUNET_OK != 1296 &networkIdDirectory));
1413 GNUNET_DISK_directory_create (networkIdDirectory)) 1297 if (GNUNET_OK != GNUNET_DISK_directory_create (networkIdDirectory))
1414 { 1298 {
1415 GNUNET_SCHEDULER_shutdown (); 1299 GNUNET_SCHEDULER_shutdown ();
1416 return; 1300 return;
1417 } 1301 }
1418 1302
1419 cron_scan 1303 cron_scan =
1420 = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, 1304 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
1421 &cron_scan_directory_data_hosts, 1305 &cron_scan_directory_data_hosts,
1422 NULL); 1306 NULL);
1423 1307
1424 cron_clean 1308 cron_clean =
1425 = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, 1309 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
1426 &cron_clean_data_hosts, 1310 &cron_clean_data_hosts,
1427 NULL); 1311 NULL);
1428 if (GNUNET_YES == use_included) 1312 if (GNUNET_YES == use_included)
1429 { 1313 {
1430 ip = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); 1314 ip = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
1431 GNUNET_asprintf (&peerdir, 1315 GNUNET_asprintf (&peerdir, "%shellos", ip);
1432 "%shellos",
1433 ip);
1434 GNUNET_free (ip); 1316 GNUNET_free (ip);
1435 1317
1436 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1318 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1437 _("Importing HELLOs from `%s'\n"), 1319 _ ("Importing HELLOs from `%s'\n"),
1438 peerdir); 1320 peerdir);
1439 dsc.matched = 0; 1321 dsc.matched = 0;
1440 dsc.remove_files = GNUNET_NO; 1322 dsc.remove_files = GNUNET_NO;
@@ -1447,7 +1329,7 @@ run (void *cls,
1447 else 1329 else
1448 { 1330 {
1449 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1331 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1450 _("Skipping import of included HELLOs\n")); 1332 _ ("Skipping import of included HELLOs\n"));
1451 } 1333 }
1452 } 1334 }
1453} 1335}
@@ -1456,30 +1338,30 @@ run (void *cls,
1456/** 1338/**
1457 * Define "main" method using service macro. 1339 * Define "main" method using service macro.
1458 */ 1340 */
1459GNUNET_SERVICE_MAIN 1341GNUNET_SERVICE_MAIN (
1460("peerinfo", 1342 "peerinfo",
1461 GNUNET_SERVICE_OPTION_NONE, 1343 GNUNET_SERVICE_OPTION_NONE,
1462 &run, 1344 &run,
1463 &client_connect_cb, 1345 &client_connect_cb,
1464 &client_disconnect_cb, 1346 &client_disconnect_cb,
1465 NULL, 1347 NULL,
1466 GNUNET_MQ_hd_var_size (hello, 1348 GNUNET_MQ_hd_var_size (hello,
1467 GNUNET_MESSAGE_TYPE_HELLO, 1349 GNUNET_MESSAGE_TYPE_HELLO,
1468 struct GNUNET_HELLO_Message, 1350 struct GNUNET_HELLO_Message,
1469 NULL), 1351 NULL),
1470 GNUNET_MQ_hd_fixed_size (get, 1352 GNUNET_MQ_hd_fixed_size (get,
1471 GNUNET_MESSAGE_TYPE_PEERINFO_GET, 1353 GNUNET_MESSAGE_TYPE_PEERINFO_GET,
1472 struct ListPeerMessage, 1354 struct ListPeerMessage,
1473 NULL), 1355 NULL),
1474 GNUNET_MQ_hd_fixed_size (get_all, 1356 GNUNET_MQ_hd_fixed_size (get_all,
1475 GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL, 1357 GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL,
1476 struct ListAllPeersMessage, 1358 struct ListAllPeersMessage,
1477 NULL), 1359 NULL),
1478 GNUNET_MQ_hd_fixed_size (notify, 1360 GNUNET_MQ_hd_fixed_size (notify,
1479 GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY, 1361 GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY,
1480 struct NotifyMessage, 1362 struct NotifyMessage,
1481 NULL), 1363 NULL),
1482 GNUNET_MQ_handler_end ()); 1364 GNUNET_MQ_handler_end ());
1483 1365
1484 1366
1485/* end of gnunet-service-peerinfo.c */ 1367/* end of gnunet-service-peerinfo.c */
diff --git a/src/peerinfo/perf_peerinfo_api.c b/src/peerinfo/perf_peerinfo_api.c
index 29c27c48c..d56e0c558 100644
--- a/src/peerinfo/perf_peerinfo_api.c
+++ b/src/peerinfo/perf_peerinfo_api.c
@@ -177,7 +177,7 @@ main (int argc,
177 "test_peerinfo_api_data.conf", 177 "test_peerinfo_api_data.conf",
178 &run, NULL)) 178 &run, NULL))
179 return 1; 179 return 1;
180 FPRINTF (stderr, 180 fprintf (stderr,
181 "Received %u/%u calls before timeout\n", 181 "Received %u/%u calls before timeout\n",
182 numpeers, 182 numpeers,
183 NUM_REQUESTS * NUM_REQUESTS / 2); 183 NUM_REQUESTS * NUM_REQUESTS / 2);
diff --git a/src/peerstore/test_plugin_peerstore.c b/src/peerstore/test_plugin_peerstore.c
index d6be5f06d..24b5723ff 100644
--- a/src/peerstore/test_plugin_peerstore.c
+++ b/src/peerstore/test_plugin_peerstore.c
@@ -83,7 +83,7 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
83 if (NULL == (ret = GNUNET_PLUGIN_load (libname, 83 if (NULL == (ret = GNUNET_PLUGIN_load (libname,
84 (void*) cfg))) 84 (void*) cfg)))
85 { 85 {
86 FPRINTF (stderr, 86 fprintf (stderr,
87 "Failed to load plugin `%s'!\n", 87 "Failed to load plugin `%s'!\n",
88 plugin_name); 88 plugin_name);
89 GNUNET_free (libname); 89 GNUNET_free (libname);
@@ -174,7 +174,7 @@ run (void *cls,
174 psp = load_plugin (cfg); 174 psp = load_plugin (cfg);
175 if (NULL == psp) 175 if (NULL == psp)
176 { 176 {
177 FPRINTF (stderr, 177 fprintf (stderr,
178 "%s", 178 "%s",
179 "Failed to initialize peerstore. Database likely not setup, skipping test.\n"); 179 "Failed to initialize peerstore. Database likely not setup, skipping test.\n");
180 return; 180 return;
@@ -215,7 +215,7 @@ main (int argc, char *argv[])
215 &run, 215 &run,
216 NULL); 216 NULL);
217 if (ok != 0) 217 if (ok != 0)
218 FPRINTF (stderr, 218 fprintf (stderr,
219 "Missed some testcases: %d\n", 219 "Missed some testcases: %d\n",
220 ok); 220 ok);
221 return ok; 221 return ok;
diff --git a/src/reclaim/oidc_helper.c b/src/reclaim/oidc_helper.c
index 4769ed2d1..d47460edf 100644
--- a/src/reclaim/oidc_helper.c
+++ b/src/reclaim/oidc_helper.c
@@ -476,7 +476,7 @@ OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer,
476 payload_len = sizeof (struct OIDC_Parameters); 476 payload_len = sizeof (struct OIDC_Parameters);
477 if (NULL != nonce_str && strcmp ("", nonce_str) != 0) 477 if (NULL != nonce_str && strcmp ("", nonce_str) != 0)
478 { 478 {
479 if ((1 != SSCANF (nonce_str, "%u", &nonce)) || (nonce > UINT32_MAX)) 479 if ((1 != sscanf (nonce_str, "%u", &nonce)) || (nonce > UINT32_MAX))
480 { 480 {
481 GNUNET_break (0); 481 GNUNET_break (0);
482 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid nonce %s\n", nonce_str); 482 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid nonce %s\n", nonce_str);
@@ -754,4 +754,3 @@ OIDC_access_token_new ()
754 &access_token); 754 &access_token);
755 return access_token; 755 return access_token;
756} 756}
757
diff --git a/src/regex/gnunet-regex-simulation-profiler.c b/src/regex/gnunet-regex-simulation-profiler.c
index e8f6d867b..d82b7800a 100644
--- a/src/regex/gnunet-regex-simulation-profiler.c
+++ b/src/regex/gnunet-regex-simulation-profiler.c
@@ -205,17 +205,17 @@ update_meter (struct ProgressMeter *meter)
205 { 205 {
206 if (meter->completed == 0) 206 if (meter->completed == 0)
207 { 207 {
208 FPRINTF (stdout, "%sProgress: [0%%", meter->startup_string); 208 fprintf (stdout, "%sProgress: [0%%", meter->startup_string);
209 } 209 }
210 else 210 else
211 FPRINTF (stdout, "%d%%", 211 fprintf (stdout, "%d%%",
212 (int) (((float) meter->completed / meter->total) * 100)); 212 (int) (((float) meter->completed / meter->total) * 100));
213 } 213 }
214 else if (meter->completed % meter->dotnum == 0) 214 else if (meter->completed % meter->dotnum == 0)
215 FPRINTF (stdout, "%s", "."); 215 fprintf (stdout, "%s", ".");
216 216
217 if (meter->completed + 1 == meter->total) 217 if (meter->completed + 1 == meter->total)
218 FPRINTF (stdout, "%d%%]\n", 100); 218 fprintf (stdout, "%d%%]\n", 100);
219 fflush (stdout); 219 fflush (stdout);
220 } 220 }
221 meter->completed++; 221 meter->completed++;
diff --git a/src/regex/test_regex_api.c b/src/regex/test_regex_api.c
index 099f9f68c..7016bf9c4 100644
--- a/src/regex/test_regex_api.c
+++ b/src/regex/test_regex_api.c
@@ -64,7 +64,7 @@ static void
64end_badly () 64end_badly ()
65{ 65{
66 die_task = NULL; 66 die_task = NULL;
67 FPRINTF (stderr, "%s", "Testcase failed (timeout).\n"); 67 fprintf (stderr, "%s", "Testcase failed (timeout).\n");
68 GNUNET_REGEX_announce_cancel (a); 68 GNUNET_REGEX_announce_cancel (a);
69 a = NULL; 69 a = NULL;
70 GNUNET_REGEX_search_cancel (s); 70 GNUNET_REGEX_search_cancel (s);
diff --git a/src/regex/test_regex_integration.c b/src/regex/test_regex_integration.c
index d7a58b994..f264c4fae 100644
--- a/src/regex/test_regex_integration.c
+++ b/src/regex/test_regex_integration.c
@@ -75,7 +75,7 @@ end (void *cls)
75static void 75static void
76end_badly () 76end_badly ()
77{ 77{
78 FPRINTF (stderr, "%s", "Testcase failed (timeout).\n"); 78 fprintf (stderr, "%s", "Testcase failed (timeout).\n");
79 end (NULL); 79 end (NULL);
80 ok = 1; 80 ok = 1;
81} 81}
diff --git a/src/revocation/gnunet-revocation.c b/src/revocation/gnunet-revocation.c
index 4b8fa15bb..b5be65a5f 100644
--- a/src/revocation/gnunet-revocation.c
+++ b/src/revocation/gnunet-revocation.c
@@ -118,26 +118,19 @@ do_shutdown (void *cls)
118 * @param is_valid #GNUNET_YES if the key is still valid, #GNUNET_NO if not, #GNUNET_SYSERR on error 118 * @param is_valid #GNUNET_YES if the key is still valid, #GNUNET_NO if not, #GNUNET_SYSERR on error
119 */ 119 */
120static void 120static void
121print_query_result (void *cls, 121print_query_result (void *cls, int is_valid)
122 int is_valid)
123{ 122{
124 q = NULL; 123 q = NULL;
125 switch (is_valid) 124 switch (is_valid)
126 { 125 {
127 case GNUNET_YES: 126 case GNUNET_YES:
128 FPRINTF (stdout, 127 fprintf (stdout, _ ("Key `%s' is valid\n"), test_ego);
129 _("Key `%s' is valid\n"),
130 test_ego);
131 break; 128 break;
132 case GNUNET_NO: 129 case GNUNET_NO:
133 FPRINTF (stdout, 130 fprintf (stdout, _ ("Key `%s' has been revoked\n"), test_ego);
134 _("Key `%s' has been revoked\n"),
135 test_ego);
136 break; 131 break;
137 case GNUNET_SYSERR: 132 case GNUNET_SYSERR:
138 FPRINTF (stdout, 133 fprintf (stdout, "%s", _ ("Internal error\n"));
139 "%s",
140 _("Internal error\n"));
141 break; 134 break;
142 default: 135 default:
143 GNUNET_break (0); 136 GNUNET_break (0);
@@ -154,36 +147,31 @@ print_query_result (void *cls,
154 * @param is_valid #GNUNET_YES if the key is still valid, #GNUNET_NO if not, #GNUNET_SYSERR on error 147 * @param is_valid #GNUNET_YES if the key is still valid, #GNUNET_NO if not, #GNUNET_SYSERR on error
155 */ 148 */
156static void 149static void
157print_revocation_result (void *cls, 150print_revocation_result (void *cls, int is_valid)
158 int is_valid)
159{ 151{
160 h = NULL; 152 h = NULL;
161 switch (is_valid) 153 switch (is_valid)
162 { 154 {
163 case GNUNET_YES: 155 case GNUNET_YES:
164 if (NULL != revoke_ego) 156 if (NULL != revoke_ego)
165 FPRINTF (stdout, 157 fprintf (stdout,
166 _("Key for ego `%s' is still valid, revocation failed (!)\n"), 158 _ ("Key for ego `%s' is still valid, revocation failed (!)\n"),
167 revoke_ego); 159 revoke_ego);
168 else 160 else
169 FPRINTF (stdout, 161 fprintf (stdout, "%s", _ ("Revocation failed (!)\n"));
170 "%s",
171 _("Revocation failed (!)\n"));
172 break; 162 break;
173 case GNUNET_NO: 163 case GNUNET_NO:
174 if (NULL != revoke_ego) 164 if (NULL != revoke_ego)
175 FPRINTF (stdout, 165 fprintf (stdout,
176 _("Key for ego `%s' has been successfully revoked\n"), 166 _ ("Key for ego `%s' has been successfully revoked\n"),
177 revoke_ego); 167 revoke_ego);
178 else 168 else
179 FPRINTF (stdout, 169 fprintf (stdout, "%s", _ ("Revocation successful.\n"));
180 "%s",
181 _("Revocation successful.\n"));
182 break; 170 break;
183 case GNUNET_SYSERR: 171 case GNUNET_SYSERR:
184 FPRINTF (stdout, 172 fprintf (stdout,
185 "%s", 173 "%s",
186 _("Internal error, key revocation might have failed\n")); 174 _ ("Internal error, key revocation might have failed\n"));
187 break; 175 break;
188 default: 176 default:
189 GNUNET_break (0); 177 GNUNET_break (0);
@@ -239,16 +227,14 @@ perform_revocation (const struct RevocationData *rd)
239static void 227static void
240sync_rd (const struct RevocationData *rd) 228sync_rd (const struct RevocationData *rd)
241{ 229{
242 if ( (NULL != filename) && 230 if ((NULL != filename) &&
243 (sizeof (struct RevocationData) == 231 (sizeof (struct RevocationData) ==
244 GNUNET_DISK_fn_write (filename, 232 GNUNET_DISK_fn_write (filename,
245 &rd, 233 &rd,
246 sizeof (rd), 234 sizeof (rd),
247 GNUNET_DISK_PERM_USER_READ | 235 GNUNET_DISK_PERM_USER_READ |
248 GNUNET_DISK_PERM_USER_WRITE)) ) 236 GNUNET_DISK_PERM_USER_WRITE)))
249 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 237 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename);
250 "write",
251 filename);
252} 238}
253 239
254 240
@@ -287,48 +273,44 @@ calculate_pow (void *cls)
287 if (0 == (rd->pow % 128)) 273 if (0 == (rd->pow % 128))
288 sync_rd (rd); 274 sync_rd (rd);
289 /* display progress estimate */ 275 /* display progress estimate */
290 if ( (0 == ((1 << matching_bits) / 100 / 50)) || 276 if ((0 == ((1 << matching_bits) / 100 / 50)) ||
291 (0 == (rd->pow % ((1 << matching_bits) / 100 / 50))) ) 277 (0 == (rd->pow % ((1 << matching_bits) / 100 / 50))))
292 FPRINTF (stderr, "%s", "."); 278 fprintf (stderr, "%s", ".");
293 if ( (0 != rd->pow) && 279 if ((0 != rd->pow) && ((0 == ((1 << matching_bits) / 100)) ||
294 ( (0 == ((1 << matching_bits) / 100)) || 280 (0 == (rd->pow % ((1 << matching_bits) / 100)))))
295 (0 == (rd->pow % ((1 << matching_bits) / 100))) ) ) 281 fprintf (stderr,
296 FPRINTF (stderr, " - @ %3u%% (estimate)\n", 282 " - @ %3u%% (estimate)\n",
297 (unsigned int) (rd->pow * 100) / (1 << matching_bits)); 283 (unsigned int) (rd->pow * 100) / (1 << matching_bits));
298 /* actually do POW calculation */ 284 /* actually do POW calculation */
299 rd->pow++; 285 rd->pow++;
300 if (GNUNET_OK == 286 if (GNUNET_OK == GNUNET_REVOCATION_check_pow (&rd->key,
301 GNUNET_REVOCATION_check_pow (&rd->key, 287 rd->pow,
302 rd->pow, 288 (unsigned int) matching_bits))
303 (unsigned int) matching_bits))
304 { 289 {
305 if ( (NULL != filename) && 290 if ((NULL != filename) &&
306 (sizeof (struct RevocationData) != 291 (sizeof (struct RevocationData) !=
307 GNUNET_DISK_fn_write (filename, 292 GNUNET_DISK_fn_write (filename,
308 rd, 293 rd,
309 sizeof (struct RevocationData), 294 sizeof (struct RevocationData),
310 GNUNET_DISK_PERM_USER_READ | 295 GNUNET_DISK_PERM_USER_READ |
311 GNUNET_DISK_PERM_USER_WRITE)) ) 296 GNUNET_DISK_PERM_USER_WRITE)))
312 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 297 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename);
313 "write",
314 filename);
315 if (perform) 298 if (perform)
316 { 299 {
317 perform_revocation (rd); 300 perform_revocation (rd);
318 } 301 }
319 else 302 else
320 { 303 {
321 FPRINTF (stderr, "%s", "\n"); 304 fprintf (stderr, "%s", "\n");
322 FPRINTF (stderr, 305 fprintf (stderr,
323 _("Revocation certificate for `%s' stored in `%s'\n"), 306 _ ("Revocation certificate for `%s' stored in `%s'\n"),
324 revoke_ego, 307 revoke_ego,
325 filename); 308 filename);
326 GNUNET_SCHEDULER_shutdown (); 309 GNUNET_SCHEDULER_shutdown ();
327 } 310 }
328 return; 311 return;
329 } 312 }
330 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, 313 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, rd);
331 rd);
332} 314}
333 315
334 316
@@ -339,8 +321,7 @@ calculate_pow (void *cls)
339 * @param ego the ego, NULL if not found 321 * @param ego the ego, NULL if not found
340 */ 322 */
341static void 323static void
342ego_callback (void *cls, 324ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
343 const struct GNUNET_IDENTITY_Ego *ego)
344{ 325{
345 struct RevocationData *rd; 326 struct RevocationData *rd;
346 struct GNUNET_CRYPTO_EcdsaPublicKey key; 327 struct GNUNET_CRYPTO_EcdsaPublicKey key;
@@ -348,28 +329,20 @@ ego_callback (void *cls,
348 el = NULL; 329 el = NULL;
349 if (NULL == ego) 330 if (NULL == ego)
350 { 331 {
351 FPRINTF (stdout, 332 fprintf (stdout, _ ("Ego `%s' not found.\n"), revoke_ego);
352 _("Ego `%s' not found.\n"),
353 revoke_ego);
354 GNUNET_SCHEDULER_shutdown (); 333 GNUNET_SCHEDULER_shutdown ();
355 return; 334 return;
356 } 335 }
357 GNUNET_IDENTITY_ego_get_public_key (ego, 336 GNUNET_IDENTITY_ego_get_public_key (ego, &key);
358 &key);
359 rd = GNUNET_new (struct RevocationData); 337 rd = GNUNET_new (struct RevocationData);
360 if ( (NULL != filename) && 338 if ((NULL != filename) && (GNUNET_YES == GNUNET_DISK_file_test (filename)) &&
361 (GNUNET_YES == 339 (sizeof (struct RevocationData) ==
362 GNUNET_DISK_file_test (filename)) && 340 GNUNET_DISK_fn_read (filename, rd, sizeof (struct RevocationData))))
363 (sizeof (struct RevocationData) ==
364 GNUNET_DISK_fn_read (filename,
365 rd,
366 sizeof (struct RevocationData))) )
367 { 341 {
368 if (0 != GNUNET_memcmp (&rd->key, 342 if (0 != GNUNET_memcmp (&rd->key, &key))
369 &key))
370 { 343 {
371 fprintf (stderr, 344 fprintf (stderr,
372 _("Error: revocation certificate in `%s' is not for `%s'\n"), 345 _ ("Error: revocation certificate in `%s' is not for `%s'\n"),
373 filename, 346 filename,
374 revoke_ego); 347 revoke_ego);
375 GNUNET_free (rd); 348 GNUNET_free (rd);
@@ -378,18 +351,15 @@ ego_callback (void *cls,
378 } 351 }
379 else 352 else
380 { 353 {
381 GNUNET_REVOCATION_sign_revocation (GNUNET_IDENTITY_ego_get_private_key (ego), 354 GNUNET_REVOCATION_sign_revocation (GNUNET_IDENTITY_ego_get_private_key (
355 ego),
382 &rd->sig); 356 &rd->sig);
383 rd->key = key; 357 rd->key = key;
384 } 358 }
385 if (GNUNET_YES == 359 if (GNUNET_YES ==
386 GNUNET_REVOCATION_check_pow (&key, 360 GNUNET_REVOCATION_check_pow (&key, rd->pow, (unsigned int) matching_bits))
387 rd->pow,
388 (unsigned int) matching_bits))
389 { 361 {
390 FPRINTF (stderr, 362 fprintf (stderr, "%s", _ ("Revocation certificate ready\n"));
391 "%s",
392 _("Revocation certificate ready\n"));
393 if (perform) 363 if (perform)
394 perform_revocation (rd); 364 perform_revocation (rd);
395 else 365 else
@@ -397,13 +367,11 @@ ego_callback (void *cls,
397 GNUNET_free (rd); 367 GNUNET_free (rd);
398 return; 368 return;
399 } 369 }
400 FPRINTF (stderr, 370 fprintf (stderr,
401 "%s", 371 "%s",
402 _("Revocation certificate not ready, calculating proof of work\n")); 372 _ ("Revocation certificate not ready, calculating proof of work\n"));
403 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, 373 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, rd);
404 rd); 374 GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, rd);
405 GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown,
406 rd);
407} 375}
408 376
409 377
@@ -429,31 +397,26 @@ run (void *cls,
429 { 397 {
430 if (GNUNET_OK != 398 if (GNUNET_OK !=
431 GNUNET_CRYPTO_ecdsa_public_key_from_string (test_ego, 399 GNUNET_CRYPTO_ecdsa_public_key_from_string (test_ego,
432 strlen (test_ego), 400 strlen (test_ego),
433 &pk)) 401 &pk))
434 { 402 {
435 FPRINTF (stderr, 403 fprintf (stderr, _ ("Public key `%s' malformed\n"), test_ego);
436 _("Public key `%s' malformed\n"),
437 test_ego);
438 return; 404 return;
439 } 405 }
440 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 406 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
441 NULL); 407 q = GNUNET_REVOCATION_query (cfg, &pk, &print_query_result, NULL);
442 q = GNUNET_REVOCATION_query (cfg,
443 &pk,
444 &print_query_result,
445 NULL);
446 if (NULL != revoke_ego) 408 if (NULL != revoke_ego)
447 FPRINTF (stderr, 409 fprintf (
448 "%s", 410 stderr,
449 _("Testing and revoking at the same time is not allowed, only executing test.\n")); 411 "%s",
412 _ (
413 "Testing and revoking at the same time is not allowed, only executing test.\n"));
450 return; 414 return;
451 } 415 }
452 if (GNUNET_OK != 416 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
453 GNUNET_CONFIGURATION_get_value_number (cfg, 417 "REVOCATION",
454 "REVOCATION", 418 "WORKBITS",
455 "WORKBITS", 419 &matching_bits))
456 &matching_bits))
457 { 420 {
458 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 421 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
459 "REVOCATION", 422 "REVOCATION",
@@ -462,37 +425,28 @@ run (void *cls,
462 } 425 }
463 if (NULL != revoke_ego) 426 if (NULL != revoke_ego)
464 { 427 {
465 if ( !perform && (NULL == filename) ) 428 if (! perform && (NULL == filename))
466 { 429 {
467 FPRINTF (stderr, 430 fprintf (stderr,
468 "%s", 431 "%s",
469 _("No filename to store revocation certificate given.\n")); 432 _ ("No filename to store revocation certificate given.\n"));
470 return; 433 return;
471 } 434 }
472 /* main code here */ 435 /* main code here */
473 el = GNUNET_IDENTITY_ego_lookup (cfg, 436 el = GNUNET_IDENTITY_ego_lookup (cfg, revoke_ego, &ego_callback, NULL);
474 revoke_ego, 437 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
475 &ego_callback,
476 NULL);
477 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
478 NULL);
479 return; 438 return;
480 } 439 }
481 if ( (NULL != filename) && 440 if ((NULL != filename) && (perform))
482 (perform) )
483 { 441 {
484 if (sizeof (rd) != 442 if (sizeof (rd) != GNUNET_DISK_fn_read (filename, &rd, sizeof (rd)))
485 GNUNET_DISK_fn_read (filename,
486 &rd,
487 sizeof (rd)))
488 { 443 {
489 fprintf (stderr, 444 fprintf (stderr,
490 _("Failed to read revocation certificate from `%s'\n"), 445 _ ("Failed to read revocation certificate from `%s'\n"),
491 filename); 446 filename);
492 return; 447 return;
493 } 448 }
494 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 449 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
495 NULL);
496 if (GNUNET_YES != 450 if (GNUNET_YES !=
497 GNUNET_REVOCATION_check_pow (&rd.key, 451 GNUNET_REVOCATION_check_pow (&rd.key,
498 rd.pow, 452 rd.pow,
@@ -501,18 +455,14 @@ run (void *cls,
501 struct RevocationData *cp = GNUNET_new (struct RevocationData); 455 struct RevocationData *cp = GNUNET_new (struct RevocationData);
502 456
503 *cp = rd; 457 *cp = rd;
504 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, 458 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, cp);
505 cp); 459 GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, cp);
506 GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown,
507 cp);
508 return; 460 return;
509 } 461 }
510 perform_revocation (&rd); 462 perform_revocation (&rd);
511 return; 463 return;
512 } 464 }
513 FPRINTF (stderr, 465 fprintf (stderr, "%s", _ ("No action specified. Nothing to do.\n"));
514 "%s",
515 _("No action specified. Nothing to do.\n"));
516} 466}
517 467
518 468
@@ -531,36 +481,46 @@ main (int argc, char *const *argv)
531 GNUNET_GETOPT_option_string ('f', 481 GNUNET_GETOPT_option_string ('f',
532 "filename", 482 "filename",
533 "NAME", 483 "NAME",
534 gettext_noop ("use NAME for the name of the revocation file"), 484 gettext_noop (
485 "use NAME for the name of the revocation file"),
535 &filename), 486 &filename),
536 487
537 GNUNET_GETOPT_option_string ('R', 488 GNUNET_GETOPT_option_string (
538 "revoke", 489 'R',
539 "NAME", 490 "revoke",
540 gettext_noop ("revoke the private key associated for the the private key associated with the ego NAME "), 491 "NAME",
541 &revoke_ego), 492 gettext_noop (
542 493 "revoke the private key associated for the the private key associated with the ego NAME "),
543 GNUNET_GETOPT_option_flag ('p', 494 &revoke_ego),
544 "perform", 495
545 gettext_noop ("actually perform revocation, otherwise we just do the precomputation"), 496 GNUNET_GETOPT_option_flag (
546 &perform), 497 'p',
498 "perform",
499 gettext_noop (
500 "actually perform revocation, otherwise we just do the precomputation"),
501 &perform),
547 502
548 GNUNET_GETOPT_option_string ('t', 503 GNUNET_GETOPT_option_string ('t',
549 "test", 504 "test",
550 "KEY", 505 "KEY",
551 gettext_noop ("test if the public key KEY has been revoked"), 506 gettext_noop (
552 &test_ego), 507 "test if the public key KEY has been revoked"),
508 &test_ego),
553 509
554 GNUNET_GETOPT_OPTION_END 510 GNUNET_GETOPT_OPTION_END};
555 };
556 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 511 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
557 return 2; 512 return 2;
558 513
559 ret = (GNUNET_OK == 514 ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc,
560 GNUNET_PROGRAM_run (argc, argv, "gnunet-revocation", 515 argv,
561 gettext_noop ("help text"), options, &run, 516 "gnunet-revocation",
562 NULL)) ? ret : 1; 517 gettext_noop ("help text"),
563 GNUNET_free ((void*) argv); 518 options,
519 &run,
520 NULL))
521 ? ret
522 : 1;
523 GNUNET_free ((void *) argv);
564 return ret; 524 return ret;
565} 525}
566 526
diff --git a/src/rps/gnunet-rps.c b/src/rps/gnunet-rps.c
index 50b5b6739..d731ffa55 100644
--- a/src/rps/gnunet-rps.c
+++ b/src/rps/gnunet-rps.c
@@ -97,7 +97,7 @@ reply_handle (void *cls,
97 req_handle = NULL; 97 req_handle = NULL;
98 for (i = 0; i < n; i++) 98 for (i = 0; i < n; i++)
99 { 99 {
100 FPRINTF (stdout, "%s\n", 100 fprintf (stdout, "%s\n",
101 GNUNET_i2s_full (&recv_peers[i])); 101 GNUNET_i2s_full (&recv_peers[i]));
102 } 102 }
103 ret = 0; 103 ret = 0;
@@ -122,12 +122,12 @@ view_update_handle (void *cls,
122 122
123 if (0 == n) 123 if (0 == n)
124 { 124 {
125 FPRINTF (stdout, "Empty view\n"); 125 fprintf (stdout, "Empty view\n");
126 } 126 }
127 req_handle = NULL; 127 req_handle = NULL;
128 for (i = 0; i < n; i++) 128 for (i = 0; i < n; i++)
129 { 129 {
130 FPRINTF (stdout, "%s\n", 130 fprintf (stdout, "%s\n",
131 GNUNET_i2s_full (&recv_peers[i])); 131 GNUNET_i2s_full (&recv_peers[i]));
132 } 132 }
133 133
@@ -159,12 +159,12 @@ stream_input_handle (void *cls,
159 159
160 if (0 == num_peers) 160 if (0 == num_peers)
161 { 161 {
162 FPRINTF (stdout, "No peer was returned\n"); 162 fprintf (stdout, "No peer was returned\n");
163 } 163 }
164 req_handle = NULL; 164 req_handle = NULL;
165 for (i = 0; i < num_peers; i++) 165 for (i = 0; i < num_peers; i++)
166 { 166 {
167 FPRINTF (stdout, "%s\n", 167 fprintf (stdout, "%s\n",
168 GNUNET_i2s_full (&recv_peers[i])); 168 GNUNET_i2s_full (&recv_peers[i]));
169 } 169 }
170} 170}
@@ -192,7 +192,7 @@ run (void *cls,
192 rps_handle = GNUNET_RPS_connect (cfg); 192 rps_handle = GNUNET_RPS_connect (cfg);
193 if (NULL == rps_handle) 193 if (NULL == rps_handle)
194 { 194 {
195 FPRINTF (stderr, "Failed to connect to the rps service\n"); 195 fprintf (stderr, "Failed to connect to the rps service\n");
196 return; 196 return;
197 } 197 }
198 198
@@ -235,7 +235,7 @@ run (void *cls,
235 else 235 else
236 { /* Seed PeerID */ 236 { /* Seed PeerID */
237 GNUNET_RPS_seed_ids (rps_handle, 1, &peer_id); 237 GNUNET_RPS_seed_ids (rps_handle, 1, &peer_id);
238 FPRINTF (stdout, "Seeded PeerID %s\n", GNUNET_i2s_full (&peer_id)); 238 fprintf (stdout, "Seeded PeerID %s\n", GNUNET_i2s_full (&peer_id));
239 ret = 0; 239 ret = 0;
240 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 240 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
241 } 241 }
diff --git a/src/statistics/gnunet-service-statistics.c b/src/statistics/gnunet-service-statistics.c
index 5ce54d768..18905f458 100644
--- a/src/statistics/gnunet-service-statistics.c
+++ b/src/statistics/gnunet-service-statistics.c
@@ -71,7 +71,6 @@ struct WatchEntry
71 * #GNUNET_NO : last_value is n/a, #GNUNET_YES: last_value is valid 71 * #GNUNET_NO : last_value is n/a, #GNUNET_YES: last_value is valid
72 */ 72 */
73 int last_value_set; 73 int last_value_set;
74
75}; 74};
76 75
77 76
@@ -138,7 +137,6 @@ struct StatsEntry
138 * #GNUNET_NO: value is n/a, #GNUNET_YES: value is valid 137 * #GNUNET_NO: value is n/a, #GNUNET_YES: value is valid
139 */ 138 */
140 int set; 139 int set;
141
142}; 140};
143 141
144 142
@@ -173,7 +171,6 @@ struct SubsystemEntry
173 * the end of this struct, do not free(). 171 * the end of this struct, do not free().
174 */ 172 */
175 const char *service; 173 const char *service;
176
177}; 174};
178 175
179 176
@@ -201,7 +198,6 @@ struct ClientEntry
201 * Maximum watch ID used by this client so far. 198 * Maximum watch ID used by this client so far.
202 */ 199 */
203 uint32_t max_wid; 200 uint32_t max_wid;
204
205}; 201};
206 202
207 203
@@ -257,11 +253,10 @@ save ()
257 size_t slen; 253 size_t slen;
258 struct GNUNET_STATISTICS_SetMessage *msg; 254 struct GNUNET_STATISTICS_SetMessage *msg;
259 255
260 if (GNUNET_OK != 256 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
261 GNUNET_CONFIGURATION_get_value_filename (cfg, 257 "STATISTICS",
262 "STATISTICS", 258 "DATABASE",
263 "DATABASE", 259 &fn))
264 &fn))
265 { 260 {
266 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 261 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
267 "STATISTICS", 262 "STATISTICS",
@@ -273,17 +268,12 @@ save ()
273 total = 0; 268 total = 0;
274 while (NULL != (se = sub_head)) 269 while (NULL != (se = sub_head))
275 { 270 {
276 GNUNET_CONTAINER_DLL_remove (sub_head, 271 GNUNET_CONTAINER_DLL_remove (sub_head, sub_tail, se);
277 sub_tail,
278 se);
279 slen = strlen (se->service) + 1; 272 slen = strlen (se->service) + 1;
280 while (NULL != (pos = se->stat_head)) 273 while (NULL != (pos = se->stat_head))
281 { 274 {
282 GNUNET_CONTAINER_DLL_remove (se->stat_head, 275 GNUNET_CONTAINER_DLL_remove (se->stat_head, se->stat_tail, pos);
283 se->stat_tail, 276 if ((pos->persistent) && (NULL != wh))
284 pos);
285 if ( (pos->persistent) &&
286 (NULL != wh) )
287 { 277 {
288 nlen = strlen (pos->name) + 1; 278 nlen = strlen (pos->name) + 1;
289 size = sizeof (struct GNUNET_STATISTICS_SetMessage) + nlen + slen; 279 size = sizeof (struct GNUNET_STATISTICS_SetMessage) + nlen + slen;
@@ -298,19 +288,14 @@ save ()
298 2, 288 2,
299 se->service, 289 se->service,
300 pos->name)); 290 pos->name));
301 msg->flags = htonl (pos->persistent ? GNUNET_STATISTICS_SETFLAG_PERSISTENT : 0); 291 msg->flags =
292 htonl (pos->persistent ? GNUNET_STATISTICS_SETFLAG_PERSISTENT : 0);
302 msg->value = GNUNET_htonll (pos->value); 293 msg->value = GNUNET_htonll (pos->value);
303 if (GNUNET_OK != GNUNET_BIO_write (wh, 294 if (GNUNET_OK != GNUNET_BIO_write (wh, msg, size))
304 msg,
305 size))
306 { 295 {
307 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 296 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn);
308 "write",
309 fn);
310 if (GNUNET_OK != GNUNET_BIO_write_close (wh)) 297 if (GNUNET_OK != GNUNET_BIO_write_close (wh))
311 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 298 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "close", fn);
312 "close",
313 fn);
314 wh = NULL; 299 wh = NULL;
315 } 300 }
316 else 301 else
@@ -325,17 +310,13 @@ save ()
325 } 310 }
326 if (NULL != wh) 311 if (NULL != wh)
327 { 312 {
328 if (GNUNET_OK != 313 if (GNUNET_OK != GNUNET_BIO_write_close (wh))
329 GNUNET_BIO_write_close (wh)) 314 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "close", fn);
330 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
331 "close",
332 fn);
333 if (0 == total) 315 if (0 == total)
334 GNUNET_break (0 == 316 GNUNET_break (0 == unlink (fn));
335 UNLINK (fn));
336 else 317 else
337 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 318 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
338 _("Wrote %llu bytes of statistics to `%s'\n"), 319 _ ("Wrote %llu bytes of statistics to `%s'\n"),
339 total, 320 total,
340 fn); 321 fn);
341 } 322 }
@@ -350,37 +331,31 @@ save ()
350 * @param e value to transmit 331 * @param e value to transmit
351 */ 332 */
352static void 333static void
353transmit (struct ClientEntry *ce, 334transmit (struct ClientEntry *ce, const struct StatsEntry *e)
354 const struct StatsEntry *e)
355{ 335{
356 struct GNUNET_MQ_Envelope *env; 336 struct GNUNET_MQ_Envelope *env;
357 struct GNUNET_STATISTICS_ReplyMessage *m; 337 struct GNUNET_STATISTICS_ReplyMessage *m;
358 size_t size; 338 size_t size;
359 339
360 size = strlen (e->subsystem->service) + 1 + 340 size = strlen (e->subsystem->service) + 1 + strlen (e->name) + 1;
361 strlen (e->name) + 1;
362 GNUNET_assert (size < GNUNET_MAX_MESSAGE_SIZE); 341 GNUNET_assert (size < GNUNET_MAX_MESSAGE_SIZE);
363 env = GNUNET_MQ_msg_extra (m, 342 env = GNUNET_MQ_msg_extra (m, size, GNUNET_MESSAGE_TYPE_STATISTICS_VALUE);
364 size,
365 GNUNET_MESSAGE_TYPE_STATISTICS_VALUE);
366 m->uid = htonl (e->uid); 343 m->uid = htonl (e->uid);
367 if (e->persistent) 344 if (e->persistent)
368 m->uid |= htonl (GNUNET_STATISTICS_PERSIST_BIT); 345 m->uid |= htonl (GNUNET_STATISTICS_PERSIST_BIT);
369 m->value = GNUNET_htonll (e->value); 346 m->value = GNUNET_htonll (e->value);
370 GNUNET_assert (size == 347 GNUNET_assert (size == GNUNET_STRINGS_buffer_fill ((char *) &m[1],
371 GNUNET_STRINGS_buffer_fill ((char *) &m[1], 348 size,
372 size, 349 2,
373 2, 350 e->subsystem->service,
374 e->subsystem->service, 351 e->name));
375 e->name));
376 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 352 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
377 "Transmitting value for `%s:%s' (%d): %llu\n", 353 "Transmitting value for `%s:%s' (%d): %llu\n",
378 e->subsystem->service, 354 e->subsystem->service,
379 e->name, 355 e->name,
380 e->persistent, 356 e->persistent,
381 (unsigned long long) e->value); 357 (unsigned long long) e->value);
382 GNUNET_MQ_send (ce->mq, 358 GNUNET_MQ_send (ce->mq, env);
383 env);
384} 359}
385 360
386 361
@@ -394,8 +369,8 @@ transmit (struct ClientEntry *ce,
394 */ 369 */
395static void * 370static void *
396client_connect_cb (void *cls, 371client_connect_cb (void *cls,
397 struct GNUNET_SERVICE_Client *c, 372 struct GNUNET_SERVICE_Client *c,
398 struct GNUNET_MQ_Handle *mq) 373 struct GNUNET_MQ_Handle *mq)
399{ 374{
400 struct ClientEntry *ce; 375 struct ClientEntry *ce;
401 376
@@ -403,8 +378,7 @@ client_connect_cb (void *cls,
403 ce->client = c; 378 ce->client = c;
404 ce->mq = mq; 379 ce->mq = mq;
405 client_count++; 380 client_count++;
406 GNUNET_notification_context_add (nc, 381 GNUNET_notification_context_add (nc, mq);
407 mq);
408 return ce; 382 return ce;
409} 383}
410 384
@@ -417,20 +391,18 @@ client_connect_cb (void *cls,
417 * @return #GNUNET_OK if @a message is well-formed 391 * @return #GNUNET_OK if @a message is well-formed
418 */ 392 */
419static int 393static int
420check_get (void *cls, 394check_get (void *cls, const struct GNUNET_MessageHeader *message)
421 const struct GNUNET_MessageHeader *message)
422{ 395{
423 const char *service; 396 const char *service;
424 const char *name; 397 const char *name;
425 size_t size; 398 size_t size;
426 399
427 size = ntohs (message->size) - sizeof (struct GNUNET_MessageHeader); 400 size = ntohs (message->size) - sizeof (struct GNUNET_MessageHeader);
428 if (size != 401 if (size != GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1],
429 GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1], 402 size,
430 size, 403 2,
431 2, 404 &service,
432 &service, 405 &name))
433 &name))
434 { 406 {
435 GNUNET_break (0); 407 GNUNET_break (0);
436 return GNUNET_SYSERR; 408 return GNUNET_SYSERR;
@@ -446,8 +418,7 @@ check_get (void *cls,
446 * @param message the actual message 418 * @param message the actual message
447 */ 419 */
448static void 420static void
449handle_get (void *cls, 421handle_get (void *cls, const struct GNUNET_MessageHeader *message)
450 const struct GNUNET_MessageHeader *message)
451{ 422{
452 struct ClientEntry *ce = cls; 423 struct ClientEntry *ce = cls;
453 struct GNUNET_MQ_Envelope *env; 424 struct GNUNET_MQ_Envelope *env;
@@ -462,11 +433,11 @@ handle_get (void *cls,
462 433
463 size = ntohs (message->size) - sizeof (struct GNUNET_MessageHeader); 434 size = ntohs (message->size) - sizeof (struct GNUNET_MessageHeader);
464 GNUNET_assert (size == 435 GNUNET_assert (size ==
465 GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1], 436 GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1],
466 size, 437 size,
467 2, 438 2,
468 &service, 439 &service,
469 &name)); 440 &name));
470 slen = strlen (service); 441 slen = strlen (service);
471 nlen = strlen (name); 442 nlen = strlen (name);
472 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -475,23 +446,17 @@ handle_get (void *cls,
475 nlen ? name : "*"); 446 nlen ? name : "*");
476 for (se = sub_head; NULL != se; se = se->next) 447 for (se = sub_head; NULL != se; se = se->next)
477 { 448 {
478 if (! ( (0 == slen) || 449 if (! ((0 == slen) || (0 == strcmp (service, se->service))))
479 (0 == strcmp (service, se->service))) )
480 continue; 450 continue;
481 for (pos = se->stat_head; NULL != pos; pos = pos->next) 451 for (pos = se->stat_head; NULL != pos; pos = pos->next)
482 { 452 {
483 if (! ( (0 == nlen) || 453 if (! ((0 == nlen) || (0 == strcmp (name, pos->name))))
484 (0 == strcmp (name,
485 pos->name))) )
486 continue; 454 continue;
487 transmit (ce, 455 transmit (ce, pos);
488 pos);
489 } 456 }
490 } 457 }
491 env = GNUNET_MQ_msg (end, 458 env = GNUNET_MQ_msg (end, GNUNET_MESSAGE_TYPE_STATISTICS_END);
492 GNUNET_MESSAGE_TYPE_STATISTICS_END); 459 GNUNET_MQ_send (ce->mq, env);
493 GNUNET_MQ_send (ce->mq,
494 env);
495 GNUNET_SERVICE_client_continue (ce->client); 460 GNUNET_SERVICE_client_continue (ce->client);
496} 461}
497 462
@@ -519,14 +484,13 @@ notify_change (struct StatsEntry *se)
519 { 484 {
520 pos->last_value_set = GNUNET_YES; 485 pos->last_value_set = GNUNET_YES;
521 } 486 }
522 env = GNUNET_MQ_msg (wvm, 487 env = GNUNET_MQ_msg (wvm, GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE);
523 GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE); 488 wvm->flags =
524 wvm->flags = htonl (se->persistent ? GNUNET_STATISTICS_SETFLAG_PERSISTENT : 0); 489 htonl (se->persistent ? GNUNET_STATISTICS_SETFLAG_PERSISTENT : 0);
525 wvm->wid = htonl (pos->wid); 490 wvm->wid = htonl (pos->wid);
526 wvm->reserved = htonl (0); 491 wvm->reserved = htonl (0);
527 wvm->value = GNUNET_htonll (se->value); 492 wvm->value = GNUNET_htonll (se->value);
528 GNUNET_MQ_send (pos->ce->mq, 493 GNUNET_MQ_send (pos->ce->mq, env);
529 env);
530 pos->last_value = se->value; 494 pos->last_value = se->value;
531 } 495 }
532} 496}
@@ -541,8 +505,7 @@ notify_change (struct StatsEntry *se)
541 * @return subsystem entry, never NULL (subsystem entry is created if necessary) 505 * @return subsystem entry, never NULL (subsystem entry is created if necessary)
542 */ 506 */
543static struct SubsystemEntry * 507static struct SubsystemEntry *
544find_subsystem_entry (struct ClientEntry *ce, 508find_subsystem_entry (struct ClientEntry *ce, const char *service)
545 const char *service)
546{ 509{
547 size_t slen; 510 size_t slen;
548 struct SubsystemEntry *se; 511 struct SubsystemEntry *se;
@@ -551,13 +514,10 @@ find_subsystem_entry (struct ClientEntry *ce,
551 se = ce->subsystem; 514 se = ce->subsystem;
552 else 515 else
553 se = NULL; 516 se = NULL;
554 if ( (NULL == se) || 517 if ((NULL == se) || (0 != strcmp (service, se->service)))
555 (0 != strcmp (service,
556 se->service)) )
557 { 518 {
558 for (se = sub_head; NULL != se; se = se->next) 519 for (se = sub_head; NULL != se; se = se->next)
559 if (0 == strcmp (service, 520 if (0 == strcmp (service, se->service))
560 se->service))
561 break; 521 break;
562 if (NULL != ce) 522 if (NULL != ce)
563 ce->subsystem = se; 523 ce->subsystem = se;
@@ -568,15 +528,10 @@ find_subsystem_entry (struct ClientEntry *ce,
568 "Allocating new subsystem entry `%s'\n", 528 "Allocating new subsystem entry `%s'\n",
569 service); 529 service);
570 slen = strlen (service) + 1; 530 slen = strlen (service) + 1;
571 se = GNUNET_malloc (sizeof (struct SubsystemEntry) + 531 se = GNUNET_malloc (sizeof (struct SubsystemEntry) + slen);
572 slen); 532 GNUNET_memcpy (&se[1], service, slen);
573 GNUNET_memcpy (&se[1],
574 service,
575 slen);
576 se->service = (const char *) &se[1]; 533 se->service = (const char *) &se[1];
577 GNUNET_CONTAINER_DLL_insert (sub_head, 534 GNUNET_CONTAINER_DLL_insert (sub_head, sub_tail, se);
578 sub_tail,
579 se);
580 if (NULL != ce) 535 if (NULL != ce)
581 ce->subsystem = se; 536 ce->subsystem = se;
582 return se; 537 return se;
@@ -591,13 +546,12 @@ find_subsystem_entry (struct ClientEntry *ce,
591 * @return statistis entry, or NULL if not found 546 * @return statistis entry, or NULL if not found
592 */ 547 */
593static struct StatsEntry * 548static struct StatsEntry *
594find_stat_entry (struct SubsystemEntry *se, 549find_stat_entry (struct SubsystemEntry *se, const char *name)
595 const char *name)
596{ 550{
597 struct StatsEntry *pos; 551 struct StatsEntry *pos;
598 552
599 for (pos = se->stat_head; NULL != pos; pos = pos->next) 553 for (pos = se->stat_head; NULL != pos; pos = pos->next)
600 if (0 == strcmp (name, pos->name)) 554 if (0 == strcmp (name, pos->name))
601 return pos; 555 return pos;
602 return NULL; 556 return NULL;
603} 557}
@@ -611,20 +565,18 @@ find_stat_entry (struct SubsystemEntry *se,
611 * @return #GNUNET_OK if message is well-formed 565 * @return #GNUNET_OK if message is well-formed
612 */ 566 */
613static int 567static int
614check_set (void *cls, 568check_set (void *cls, const struct GNUNET_STATISTICS_SetMessage *msg)
615 const struct GNUNET_STATISTICS_SetMessage *msg)
616{ 569{
617 const char *service; 570 const char *service;
618 const char *name; 571 const char *name;
619 size_t msize; 572 size_t msize;
620 573
621 msize = ntohs (msg->header.size) - sizeof (*msg); 574 msize = ntohs (msg->header.size) - sizeof (*msg);
622 if (msize != 575 if (msize != GNUNET_STRINGS_buffer_tokenize ((const char *) &msg[1],
623 GNUNET_STRINGS_buffer_tokenize ((const char *) &msg[1], 576 msize,
624 msize, 577 2,
625 2, 578 &service,
626 &service, 579 &name))
627 &name))
628 { 580 {
629 GNUNET_break (0); 581 GNUNET_break (0);
630 return GNUNET_SYSERR; 582 return GNUNET_SYSERR;
@@ -640,8 +592,7 @@ check_set (void *cls,
640 * @param message the actual message 592 * @param message the actual message
641 */ 593 */
642static void 594static void
643handle_set (void *cls, 595handle_set (void *cls, const struct GNUNET_STATISTICS_SetMessage *msg)
644 const struct GNUNET_STATISTICS_SetMessage *msg)
645{ 596{
646 struct ClientEntry *ce = cls; 597 struct ClientEntry *ce = cls;
647 const char *service; 598 const char *service;
@@ -659,14 +610,12 @@ handle_set (void *cls,
659 610
660 msize = ntohs (msg->header.size); 611 msize = ntohs (msg->header.size);
661 size = msize - sizeof (struct GNUNET_STATISTICS_SetMessage); 612 size = msize - sizeof (struct GNUNET_STATISTICS_SetMessage);
662 GNUNET_assert (size == 613 GNUNET_assert (size == GNUNET_STRINGS_buffer_tokenize ((const char *) &msg[1],
663 GNUNET_STRINGS_buffer_tokenize ((const char *) &msg[1], 614 size,
664 size, 615 2,
665 2, 616 &service,
666 &service, 617 &name));
667 &name)); 618 se = find_subsystem_entry (ce, service);
668 se = find_subsystem_entry (ce,
669 service);
670 flags = ntohl (msg->flags); 619 flags = ntohl (msg->flags);
671 value = GNUNET_ntohll (msg->value); 620 value = GNUNET_ntohll (msg->value);
672 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 621 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -675,8 +624,7 @@ handle_set (void *cls,
675 name, 624 name,
676 (unsigned int) flags, 625 (unsigned int) flags,
677 (unsigned long long) value); 626 (unsigned long long) value);
678 pos = find_stat_entry (se, 627 pos = find_stat_entry (se, name);
679 name);
680 if (NULL != pos) 628 if (NULL != pos)
681 { 629 {
682 initial_set = 0; 630 initial_set = 0;
@@ -696,8 +644,7 @@ handle_set (void *cls,
696 else 644 else
697 { 645 {
698 changed = (0 != delta); 646 changed = (0 != delta);
699 GNUNET_break ( (delta <= 0) || 647 GNUNET_break ((delta <= 0) || (pos->value + delta > pos->value));
700 (pos->value + delta > pos->value) );
701 pos->value += delta; 648 pos->value += delta;
702 } 649 }
703 } 650 }
@@ -710,12 +657,8 @@ handle_set (void *cls,
710 if (pos != se->stat_head) 657 if (pos != se->stat_head)
711 { 658 {
712 /* move to front for faster setting next time! */ 659 /* move to front for faster setting next time! */
713 GNUNET_CONTAINER_DLL_remove (se->stat_head, 660 GNUNET_CONTAINER_DLL_remove (se->stat_head, se->stat_tail, pos);
714 se->stat_tail, 661 GNUNET_CONTAINER_DLL_insert (se->stat_head, se->stat_tail, pos);
715 pos);
716 GNUNET_CONTAINER_DLL_insert (se->stat_head,
717 se->stat_tail,
718 pos);
719 } 662 }
720 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 663 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
721 "Statistic `%s:%s' updated to value %llu (%d).\n", 664 "Statistic `%s:%s' updated to value %llu (%d).\n",
@@ -723,8 +666,7 @@ handle_set (void *cls,
723 name, 666 name,
724 (unsigned long long) pos->value, 667 (unsigned long long) pos->value,
725 pos->persistent); 668 pos->persistent);
726 if ( (changed) || 669 if ((changed) || (1 == initial_set))
727 (1 == initial_set) )
728 notify_change (pos); 670 notify_change (pos);
729 GNUNET_SERVICE_client_continue (ce->client); 671 GNUNET_SERVICE_client_continue (ce->client);
730 return; 672 return;
@@ -732,13 +674,11 @@ handle_set (void *cls,
732 /* not found, create a new entry */ 674 /* not found, create a new entry */
733 nlen = strlen (name) + 1; 675 nlen = strlen (name) + 1;
734 pos = GNUNET_malloc (sizeof (struct StatsEntry) + nlen); 676 pos = GNUNET_malloc (sizeof (struct StatsEntry) + nlen);
735 GNUNET_memcpy (&pos[1], 677 GNUNET_memcpy (&pos[1], name, nlen);
736 name,
737 nlen);
738 pos->name = (const char *) &pos[1]; 678 pos->name = (const char *) &pos[1];
739 pos->subsystem = se; 679 pos->subsystem = se;
740 if ( (0 == (flags & GNUNET_STATISTICS_SETFLAG_RELATIVE)) || 680 if ((0 == (flags & GNUNET_STATISTICS_SETFLAG_RELATIVE)) ||
741 (0 < (int64_t) GNUNET_ntohll (msg->value)) ) 681 (0 < (int64_t) GNUNET_ntohll (msg->value)))
742 { 682 {
743 pos->value = GNUNET_ntohll (msg->value); 683 pos->value = GNUNET_ntohll (msg->value);
744 pos->set = GNUNET_YES; 684 pos->set = GNUNET_YES;
@@ -749,9 +689,7 @@ handle_set (void *cls,
749 } 689 }
750 pos->uid = uidgen++; 690 pos->uid = uidgen++;
751 pos->persistent = (0 != (flags & GNUNET_STATISTICS_SETFLAG_PERSISTENT)); 691 pos->persistent = (0 != (flags & GNUNET_STATISTICS_SETFLAG_PERSISTENT));
752 GNUNET_CONTAINER_DLL_insert (se->stat_head, 692 GNUNET_CONTAINER_DLL_insert (se->stat_head, se->stat_tail, pos);
753 se->stat_tail,
754 pos);
755 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 693 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
756 "New statistic on `%s:%s' with value %llu created.\n", 694 "New statistic on `%s:%s' with value %llu created.\n",
757 service, 695 service,
@@ -770,20 +708,18 @@ handle_set (void *cls,
770 * @return #GNUNET_OK if message is well-formed 708 * @return #GNUNET_OK if message is well-formed
771 */ 709 */
772static int 710static int
773check_watch (void *cls, 711check_watch (void *cls, const struct GNUNET_MessageHeader *message)
774 const struct GNUNET_MessageHeader *message)
775{ 712{
776 size_t size; 713 size_t size;
777 const char *service; 714 const char *service;
778 const char *name; 715 const char *name;
779 716
780 size = ntohs (message->size) - sizeof (struct GNUNET_MessageHeader); 717 size = ntohs (message->size) - sizeof (struct GNUNET_MessageHeader);
781 if (size != 718 if (size != GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1],
782 GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1], 719 size,
783 size, 720 2,
784 2, 721 &service,
785 &service, 722 &name))
786 &name))
787 { 723 {
788 GNUNET_break (0); 724 GNUNET_break (0);
789 return GNUNET_SYSERR; 725 return GNUNET_SYSERR;
@@ -799,8 +735,7 @@ check_watch (void *cls,
799 * @param message the actual message 735 * @param message the actual message
800 */ 736 */
801static void 737static void
802handle_watch (void *cls, 738handle_watch (void *cls, const struct GNUNET_MessageHeader *message)
803 const struct GNUNET_MessageHeader *message)
804{ 739{
805 struct ClientEntry *ce = cls; 740 struct ClientEntry *ce = cls;
806 const char *service; 741 const char *service;
@@ -821,32 +756,25 @@ handle_watch (void *cls,
821 msize = ntohs (message->size); 756 msize = ntohs (message->size);
822 size = msize - sizeof (struct GNUNET_MessageHeader); 757 size = msize - sizeof (struct GNUNET_MessageHeader);
823 GNUNET_assert (size == 758 GNUNET_assert (size ==
824 GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1], 759 GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1],
825 size, 760 size,
826 2, 761 2,
827 &service, 762 &service,
828 &name)); 763 &name));
829 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 764 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
830 "Received request to watch statistic on `%s:%s'\n", 765 "Received request to watch statistic on `%s:%s'\n",
831 service, 766 service,
832 name); 767 name);
833 se = find_subsystem_entry (ce, 768 se = find_subsystem_entry (ce, service);
834 service); 769 pos = find_stat_entry (se, name);
835 pos = find_stat_entry (se,
836 name);
837 if (NULL == pos) 770 if (NULL == pos)
838 { 771 {
839 nlen = strlen (name) + 1; 772 nlen = strlen (name) + 1;
840 pos = GNUNET_malloc (sizeof (struct StatsEntry) + 773 pos = GNUNET_malloc (sizeof (struct StatsEntry) + nlen);
841 nlen); 774 GNUNET_memcpy (&pos[1], name, nlen);
842 GNUNET_memcpy (&pos[1],
843 name,
844 nlen);
845 pos->name = (const char *) &pos[1]; 775 pos->name = (const char *) &pos[1];
846 pos->subsystem = se; 776 pos->subsystem = se;
847 GNUNET_CONTAINER_DLL_insert (se->stat_head, 777 GNUNET_CONTAINER_DLL_insert (se->stat_head, se->stat_tail, pos);
848 se->stat_tail,
849 pos);
850 pos->uid = uidgen++; 778 pos->uid = uidgen++;
851 pos->set = GNUNET_NO; 779 pos->set = GNUNET_NO;
852 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 780 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -859,9 +787,7 @@ handle_watch (void *cls,
859 we->ce = ce; 787 we->ce = ce;
860 we->last_value_set = GNUNET_NO; 788 we->last_value_set = GNUNET_NO;
861 we->wid = ce->max_wid++; 789 we->wid = ce->max_wid++;
862 GNUNET_CONTAINER_DLL_insert (pos->we_head, 790 GNUNET_CONTAINER_DLL_insert (pos->we_head, pos->we_tail, we);
863 pos->we_tail,
864 we);
865 if (0 != pos->value) 791 if (0 != pos->value)
866 notify_change (pos); 792 notify_change (pos);
867 GNUNET_SERVICE_client_continue (ce->client); 793 GNUNET_SERVICE_client_continue (ce->client);
@@ -877,17 +803,14 @@ handle_watch (void *cls,
877 * @param message the actual message 803 * @param message the actual message
878 */ 804 */
879static void 805static void
880handle_disconnect (void *cls, 806handle_disconnect (void *cls, const struct GNUNET_MessageHeader *message)
881 const struct GNUNET_MessageHeader *message)
882{ 807{
883 struct ClientEntry *ce = cls; 808 struct ClientEntry *ce = cls;
884 struct GNUNET_MQ_Envelope *env; 809 struct GNUNET_MQ_Envelope *env;
885 struct GNUNET_MessageHeader *msg; 810 struct GNUNET_MessageHeader *msg;
886 811
887 env = GNUNET_MQ_msg (msg, 812 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT_CONFIRM);
888 GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT_CONFIRM); 813 GNUNET_MQ_send (ce->mq, env);
889 GNUNET_MQ_send (ce->mq,
890 env);
891 GNUNET_SERVICE_client_continue (ce->client); 814 GNUNET_SERVICE_client_continue (ce->client);
892} 815}
893 816
@@ -910,20 +833,14 @@ do_shutdown ()
910 GNUNET_assert (0 == client_count); 833 GNUNET_assert (0 == client_count);
911 while (NULL != (se = sub_head)) 834 while (NULL != (se = sub_head))
912 { 835 {
913 GNUNET_CONTAINER_DLL_remove (sub_head, 836 GNUNET_CONTAINER_DLL_remove (sub_head, sub_tail, se);
914 sub_tail,
915 se);
916 while (NULL != (pos = se->stat_head)) 837 while (NULL != (pos = se->stat_head))
917 { 838 {
918 GNUNET_CONTAINER_DLL_remove (se->stat_head, 839 GNUNET_CONTAINER_DLL_remove (se->stat_head, se->stat_tail, pos);
919 se->stat_tail,
920 pos);
921 while (NULL != (we = pos->we_head)) 840 while (NULL != (we = pos->we_head))
922 { 841 {
923 GNUNET_break (0); 842 GNUNET_break (0);
924 GNUNET_CONTAINER_DLL_remove (pos->we_head, 843 GNUNET_CONTAINER_DLL_remove (pos->we_head, pos->we_tail, we);
925 pos->we_tail,
926 we);
927 GNUNET_free (we); 844 GNUNET_free (we);
928 } 845 }
929 GNUNET_free (pos); 846 GNUNET_free (pos);
@@ -957,8 +874,8 @@ shutdown_task (void *cls)
957 */ 874 */
958static void 875static void
959client_disconnect_cb (void *cls, 876client_disconnect_cb (void *cls,
960 struct GNUNET_SERVICE_Client *client, 877 struct GNUNET_SERVICE_Client *client,
961 void *app_cls) 878 void *app_cls)
962{ 879{
963 struct ClientEntry *ce = app_cls; 880 struct ClientEntry *ce = app_cls;
964 struct WatchEntry *we; 881 struct WatchEntry *we;
@@ -977,16 +894,13 @@ client_disconnect_cb (void *cls,
977 wen = we->next; 894 wen = we->next;
978 if (we->ce != ce) 895 if (we->ce != ce)
979 continue; 896 continue;
980 GNUNET_CONTAINER_DLL_remove (pos->we_head, 897 GNUNET_CONTAINER_DLL_remove (pos->we_head, pos->we_tail, we);
981 pos->we_tail,
982 we);
983 GNUNET_free (we); 898 GNUNET_free (we);
984 } 899 }
985 } 900 }
986 } 901 }
987 GNUNET_free (ce); 902 GNUNET_free (ce);
988 if ( (0 == client_count) && 903 if ((0 == client_count) && (GNUNET_YES == in_shutdown))
989 (GNUNET_YES == in_shutdown) )
990 do_shutdown (); 904 do_shutdown ();
991} 905}
992 906
@@ -1003,23 +917,19 @@ client_disconnect_cb (void *cls,
1003 * #GNUNET_SYSERR to stop further processing with error 917 * #GNUNET_SYSERR to stop further processing with error
1004 */ 918 */
1005static int 919static int
1006inject_message (void *cls, 920inject_message (void *cls, const struct GNUNET_MessageHeader *message)
1007 const struct GNUNET_MessageHeader *message)
1008{ 921{
1009 uint16_t msize = ntohs (message->size); 922 uint16_t msize = ntohs (message->size);
1010 const struct GNUNET_STATISTICS_SetMessage *sm; 923 const struct GNUNET_STATISTICS_SetMessage *sm;
1011 924
1012 sm = (const struct GNUNET_STATISTICS_SetMessage *) message; 925 sm = (const struct GNUNET_STATISTICS_SetMessage *) message;
1013 if ( (sizeof (struct GNUNET_STATISTICS_SetMessage) > msize) || 926 if ((sizeof (struct GNUNET_STATISTICS_SetMessage) > msize) ||
1014 (GNUNET_OK != 927 (GNUNET_OK != check_set (NULL, sm)))
1015 check_set (NULL,
1016 sm)) )
1017 { 928 {
1018 GNUNET_break (0); 929 GNUNET_break (0);
1019 return GNUNET_SYSERR; 930 return GNUNET_SYSERR;
1020 } 931 }
1021 handle_set (NULL, 932 handle_set (NULL, sm);
1022 sm);
1023 return GNUNET_OK; 933 return GNUNET_OK;
1024} 934}
1025 935
@@ -1037,23 +947,19 @@ load ()
1037 char *buf; 947 char *buf;
1038 struct GNUNET_MessageStreamTokenizer *mst; 948 struct GNUNET_MessageStreamTokenizer *mst;
1039 949
1040 if (GNUNET_OK != 950 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
1041 GNUNET_CONFIGURATION_get_value_filename (cfg, 951 "STATISTICS",
1042 "STATISTICS", 952 "DATABASE",
1043 "DATABASE", 953 &fn))
1044 &fn))
1045 { 954 {
1046 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 955 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
1047 "STATISTICS", 956 "STATISTICS",
1048 "DATABASE"); 957 "DATABASE");
1049 return; 958 return;
1050 } 959 }
1051 if ( (GNUNET_OK != 960 if ((GNUNET_OK !=
1052 GNUNET_DISK_file_size (fn, 961 GNUNET_DISK_file_size (fn, &fsize, GNUNET_NO, GNUNET_YES)) ||
1053 &fsize, 962 (0 == fsize))
1054 GNUNET_NO,
1055 GNUNET_YES)) ||
1056 (0 == fsize) )
1057 { 963 {
1058 GNUNET_free (fn); 964 GNUNET_free (fn);
1059 return; 965 return;
@@ -1066,39 +972,25 @@ load ()
1066 GNUNET_free (fn); 972 GNUNET_free (fn);
1067 return; 973 return;
1068 } 974 }
1069 if (GNUNET_OK != 975 if (GNUNET_OK != GNUNET_BIO_read (rh, fn, buf, fsize))
1070 GNUNET_BIO_read (rh,
1071 fn,
1072 buf,
1073 fsize))
1074 { 976 {
1075 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 977 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "read", fn);
1076 "read", 978 GNUNET_break (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL));
1077 fn);
1078 GNUNET_break (GNUNET_OK ==
1079 GNUNET_BIO_read_close (rh,
1080 NULL));
1081 GNUNET_free (buf); 979 GNUNET_free (buf);
1082 GNUNET_free (fn); 980 GNUNET_free (fn);
1083 return; 981 return;
1084 } 982 }
1085 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 983 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1086 _("Loading %llu bytes of statistics from `%s'\n"), 984 _ ("Loading %llu bytes of statistics from `%s'\n"),
1087 (unsigned long long) fsize, 985 (unsigned long long) fsize,
1088 fn); 986 fn);
1089 mst = GNUNET_MST_create (&inject_message, 987 mst = GNUNET_MST_create (&inject_message, NULL);
1090 NULL); 988 GNUNET_break (
1091 GNUNET_break (GNUNET_OK == 989 GNUNET_OK ==
1092 GNUNET_MST_from_buffer (mst, 990 GNUNET_MST_from_buffer (mst, buf, (size_t) fsize, GNUNET_YES, GNUNET_NO));
1093 buf,
1094 (size_t) fsize,
1095 GNUNET_YES,
1096 GNUNET_NO));
1097 GNUNET_MST_destroy (mst); 991 GNUNET_MST_destroy (mst);
1098 GNUNET_free (buf); 992 GNUNET_free (buf);
1099 GNUNET_break (GNUNET_OK == 993 GNUNET_break (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL));
1100 GNUNET_BIO_read_close (rh,
1101 NULL));
1102 GNUNET_free (fn); 994 GNUNET_free (fn);
1103} 995}
1104 996
@@ -1118,38 +1010,37 @@ run (void *cls,
1118 cfg = c; 1010 cfg = c;
1119 nc = GNUNET_notification_context_create (16); 1011 nc = GNUNET_notification_context_create (16);
1120 load (); 1012 load ();
1121 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 1013 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1122 NULL);
1123} 1014}
1124 1015
1125 1016
1126/** 1017/**
1127 * Define "main" method using service macro. 1018 * Define "main" method using service macro.
1128 */ 1019 */
1129GNUNET_SERVICE_MAIN 1020GNUNET_SERVICE_MAIN (
1130("statistics", 1021 "statistics",
1131 GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, 1022 GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN,
1132 &run, 1023 &run,
1133 &client_connect_cb, 1024 &client_connect_cb,
1134 &client_disconnect_cb, 1025 &client_disconnect_cb,
1135 NULL, 1026 NULL,
1136 GNUNET_MQ_hd_var_size (set, 1027 GNUNET_MQ_hd_var_size (set,
1137 GNUNET_MESSAGE_TYPE_STATISTICS_SET, 1028 GNUNET_MESSAGE_TYPE_STATISTICS_SET,
1138 struct GNUNET_STATISTICS_SetMessage, 1029 struct GNUNET_STATISTICS_SetMessage,
1139 NULL), 1030 NULL),
1140 GNUNET_MQ_hd_var_size (get, 1031 GNUNET_MQ_hd_var_size (get,
1141 GNUNET_MESSAGE_TYPE_STATISTICS_GET, 1032 GNUNET_MESSAGE_TYPE_STATISTICS_GET,
1142 struct GNUNET_MessageHeader, 1033 struct GNUNET_MessageHeader,
1143 NULL), 1034 NULL),
1144 GNUNET_MQ_hd_var_size (watch, 1035 GNUNET_MQ_hd_var_size (watch,
1145 GNUNET_MESSAGE_TYPE_STATISTICS_WATCH, 1036 GNUNET_MESSAGE_TYPE_STATISTICS_WATCH,
1146 struct GNUNET_MessageHeader, 1037 struct GNUNET_MessageHeader,
1147 NULL), 1038 NULL),
1148 GNUNET_MQ_hd_fixed_size (disconnect, 1039 GNUNET_MQ_hd_fixed_size (disconnect,
1149 GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT, 1040 GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT,
1150 struct GNUNET_MessageHeader, 1041 struct GNUNET_MessageHeader,
1151 NULL), 1042 NULL),
1152 GNUNET_MQ_handler_end ()); 1043 GNUNET_MQ_handler_end ());
1153 1044
1154 1045
1155#if defined(LINUX) && defined(__GLIBC__) 1046#if defined(LINUX) && defined(__GLIBC__)
@@ -1158,8 +1049,7 @@ GNUNET_SERVICE_MAIN
1158/** 1049/**
1159 * MINIMIZE heap size (way below 128k) since this process doesn't need much. 1050 * MINIMIZE heap size (way below 128k) since this process doesn't need much.
1160 */ 1051 */
1161void __attribute__ ((constructor)) 1052void __attribute__ ((constructor)) GNUNET_STATISTICS_memory_init ()
1162GNUNET_STATISTICS_memory_init ()
1163{ 1053{
1164 mallopt (M_TRIM_THRESHOLD, 4 * 1024); 1054 mallopt (M_TRIM_THRESHOLD, 4 * 1024);
1165 mallopt (M_TOP_PAD, 1 * 1024); 1055 mallopt (M_TOP_PAD, 1 * 1024);
diff --git a/src/statistics/gnunet-statistics.c b/src/statistics/gnunet-statistics.c
index bc30670e9..f1ea8cb19 100644
--- a/src/statistics/gnunet-statistics.c
+++ b/src/statistics/gnunet-statistics.c
@@ -216,7 +216,7 @@ printer (void *cls, const struct GNUNET_HashCode *key, void *value)
216 if (GNUNET_YES == watch) 216 if (GNUNET_YES == watch)
217 { 217 {
218 now_str = GNUNET_STRINGS_absolute_time_to_string (now); 218 now_str = GNUNET_STRINGS_absolute_time_to_string (now);
219 FPRINTF (stdout, 219 fprintf (stdout,
220 "%24s%s %s%s%12s%s %s%50s%s%s ", 220 "%24s%s %s%s%12s%s %s%50s%s%s ",
221 now_str, 221 now_str,
222 csv_separator, 222 csv_separator,
@@ -231,7 +231,7 @@ printer (void *cls, const struct GNUNET_HashCode *key, void *value)
231 } 231 }
232 else 232 else
233 { 233 {
234 FPRINTF (stdout, 234 fprintf (stdout,
235 "%s%s%12s%s %s%50s%s%s ", 235 "%s%s%12s%s %s%50s%s%s ",
236 value_set->is_persistent ? "!" : " ", 236 value_set->is_persistent ? "!" : " ",
237 csv_separator, 237 csv_separator,
@@ -245,12 +245,12 @@ printer (void *cls, const struct GNUNET_HashCode *key, void *value)
245 } 245 }
246 for (unsigned i = 0; i < num_nodes; i++) 246 for (unsigned i = 0; i < num_nodes; i++)
247 { 247 {
248 FPRINTF (stdout, 248 fprintf (stdout,
249 "%16llu%s", 249 "%16llu%s",
250 (unsigned long long) value_set->values[i], 250 (unsigned long long) value_set->values[i],
251 csv_separator); 251 csv_separator);
252 } 252 }
253 FPRINTF (stdout, "\n"); 253 fprintf (stdout, "\n");
254 GNUNET_free (value_set->subsystem); 254 GNUNET_free (value_set->subsystem);
255 GNUNET_free (value_set->name); 255 GNUNET_free (value_set->name);
256 GNUNET_free (value_set->values); 256 GNUNET_free (value_set->values);
@@ -283,7 +283,7 @@ printer_watch (void *cls,
283 if (GNUNET_YES == watch) 283 if (GNUNET_YES == watch)
284 { 284 {
285 now_str = GNUNET_STRINGS_absolute_time_to_string (now); 285 now_str = GNUNET_STRINGS_absolute_time_to_string (now);
286 FPRINTF (stdout, 286 fprintf (stdout,
287 "%24s%s %s%s%12s%s %s%50s%s%s %16llu\n", 287 "%24s%s %s%s%12s%s %s%50s%s%s %16llu\n",
288 now_str, 288 now_str,
289 csv_separator, 289 csv_separator,
@@ -299,7 +299,7 @@ printer_watch (void *cls,
299 } 299 }
300 else 300 else
301 { 301 {
302 FPRINTF (stdout, 302 fprintf (stdout,
303 "%s%s%12s%s %s%50s%s%s %16llu\n", 303 "%s%s%12s%s %s%50s%s%s %16llu\n",
304 is_persistent ? "!" : " ", 304 is_persistent ? "!" : " ",
305 csv_separator, 305 csv_separator,
@@ -313,7 +313,7 @@ printer_watch (void *cls,
313 } 313 }
314 } 314 }
315 else 315 else
316 FPRINTF (stdout, "%llu\n", (unsigned long long) value); 316 fprintf (stdout, "%llu\n", (unsigned long long) value);
317 317
318 return GNUNET_OK; 318 return GNUNET_OK;
319} 319}
@@ -401,9 +401,9 @@ continuation_print (void *cls, int success)
401 if (GNUNET_OK != success) 401 if (GNUNET_OK != success)
402 { 402 {
403 if (NULL == remote_host) 403 if (NULL == remote_host)
404 FPRINTF (stderr, "%s", _ ("Failed to obtain statistics.\n")); 404 fprintf (stderr, "%s", _ ("Failed to obtain statistics.\n"));
405 else 405 else
406 FPRINTF (stderr, 406 fprintf (stderr,
407 _ ("Failed to obtain statistics from host `%s:%llu'\n"), 407 _ ("Failed to obtain statistics from host `%s:%llu'\n"),
408 remote_host, 408 remote_host,
409 remote_port); 409 remote_port);
@@ -439,9 +439,9 @@ cleanup (void *cls, int success)
439 if (GNUNET_OK != success) 439 if (GNUNET_OK != success)
440 { 440 {
441 if (NULL == remote_host) 441 if (NULL == remote_host)
442 FPRINTF (stderr, "%s", _ ("Failed to obtain statistics.\n")); 442 fprintf (stderr, "%s", _ ("Failed to obtain statistics.\n"));
443 else 443 else
444 FPRINTF (stderr, 444 fprintf (stderr,
445 _ ("Failed to obtain statistics from host `%s:%llu'\n"), 445 _ ("Failed to obtain statistics from host `%s:%llu'\n"),
446 remote_host, 446 remote_host,
447 remote_port); 447 remote_port);
@@ -478,7 +478,7 @@ collector (void *cls,
478 478
479 len_subsys_name = strlen (subsystem) + 3 + strlen (name) + 1; 479 len_subsys_name = strlen (subsystem) + 3 + strlen (name) + 1;
480 subsys_name = GNUNET_malloc (len_subsys_name); 480 subsys_name = GNUNET_malloc (len_subsys_name);
481 SPRINTF (subsys_name, "%s---%s", subsystem, name); 481 sprintf (subsys_name, "%s---%s", subsystem, name);
482 key = &hc; 482 key = &hc;
483 GNUNET_CRYPTO_hash (subsys_name, len_subsys_name, key); 483 GNUNET_CRYPTO_hash (subsys_name, len_subsys_name, key);
484 GNUNET_free (subsys_name); 484 GNUNET_free (subsys_name);
@@ -515,13 +515,13 @@ main_task (void *cls)
515 { 515 {
516 if (NULL == subsystem) 516 if (NULL == subsystem)
517 { 517 {
518 FPRINTF (stderr, "%s", _ ("Missing argument: subsystem \n")); 518 fprintf (stderr, "%s", _ ("Missing argument: subsystem \n"));
519 ret = 1; 519 ret = 1;
520 return; 520 return;
521 } 521 }
522 if (NULL == name) 522 if (NULL == name)
523 { 523 {
524 FPRINTF (stderr, "%s", _ ("Missing argument: name\n")); 524 fprintf (stderr, "%s", _ ("Missing argument: name\n"));
525 ret = 1; 525 ret = 1;
526 return; 526 return;
527 } 527 }
@@ -605,7 +605,7 @@ iter_check_config (void *cls, const char *filename)
605 if (GNUNET_OK != 605 if (GNUNET_OK !=
606 GNUNET_CONFIGURATION_load (nodes[num_nodes - 1].conf, filename)) 606 GNUNET_CONFIGURATION_load (nodes[num_nodes - 1].conf, filename))
607 { 607 {
608 FPRINTF (stderr, "Failed loading config `%s'\n", filename); 608 fprintf (stderr, "Failed loading config `%s'\n", filename);
609 return GNUNET_SYSERR; 609 return GNUNET_SYSERR;
610 } 610 }
611 return GNUNET_NO; 611 return GNUNET_NO;
@@ -636,7 +636,7 @@ iter_testbed_path (void *cls, const char *filename)
636 unsigned index_node; 636 unsigned index_node;
637 637
638 GNUNET_assert (NULL != filename); 638 GNUNET_assert (NULL != filename);
639 if (1 == SSCANF (GNUNET_STRINGS_get_short_name (filename), "%u", &index_node)) 639 if (1 == sscanf (GNUNET_STRINGS_get_short_name (filename), "%u", &index_node))
640 { 640 {
641 if (-1 == GNUNET_DISK_directory_scan (filename, iter_check_config, NULL)) 641 if (-1 == GNUNET_DISK_directory_scan (filename, iter_check_config, NULL))
642 { 642 {
@@ -665,7 +665,7 @@ discover_testbed_nodes (const char *path_testbed)
665 GNUNET_DISK_directory_scan (path_testbed, iter_testbed_path, NULL); 665 GNUNET_DISK_directory_scan (path_testbed, iter_testbed_path, NULL);
666 if (-1 == num_dir_entries) 666 if (-1 == num_dir_entries)
667 { 667 {
668 FPRINTF (stderr, "Failure during scanning directory `%s'\n", path_testbed); 668 fprintf (stderr, "Failure during scanning directory `%s'\n", path_testbed);
669 return -1; 669 return -1;
670 } 670 }
671 return 0; 671 return 0;
@@ -693,9 +693,9 @@ run (void *cls,
693 csv_separator = ""; 693 csv_separator = "";
694 if (NULL != args[0]) 694 if (NULL != args[0])
695 { 695 {
696 if (1 != SSCANF (args[0], "%llu", &set_val)) 696 if (1 != sscanf (args[0], "%llu", &set_val))
697 { 697 {
698 FPRINTF (stderr, _ ("Invalid argument `%s'\n"), args[0]); 698 fprintf (stderr, _ ("Invalid argument `%s'\n"), args[0]);
699 ret = 1; 699 ret = 1;
700 return; 700 return;
701 } 701 }
@@ -710,7 +710,7 @@ run (void *cls,
710 "PORT", 710 "PORT",
711 &remote_port)) 711 &remote_port))
712 { 712 {
713 FPRINTF (stderr, 713 fprintf (stderr,
714 _ ("A port is required to connect to host `%s'\n"), 714 _ ("A port is required to connect to host `%s'\n"),
715 remote_host); 715 remote_host);
716 return; 716 return;
@@ -718,7 +718,7 @@ run (void *cls,
718 } 718 }
719 else if (65535 <= remote_port) 719 else if (65535 <= remote_port)
720 { 720 {
721 FPRINTF (stderr, 721 fprintf (stderr,
722 _ ( 722 _ (
723 "A port has to be between 1 and 65535 to connect to host `%s'\n"), 723 "A port has to be between 1 and 65535 to connect to host `%s'\n"),
724 remote_host); 724 remote_host);
diff --git a/src/testbed/generate-underlay-topology.c b/src/testbed/generate-underlay-topology.c
index 1bfbfda50..7857652e0 100644
--- a/src/testbed/generate-underlay-topology.c
+++ b/src/testbed/generate-underlay-topology.c
@@ -30,26 +30,34 @@
30#include "testbed_api_topology.h" 30#include "testbed_api_topology.h"
31#include "sqlite3.h" 31#include "sqlite3.h"
32 32
33#define LOG(type, ...) \ 33#define LOG(type, ...) GNUNET_log (type, __VA_ARGS__)
34 GNUNET_log (type, __VA_ARGS__)
35 34
36 35
37#define LOG_ERROR(...) \ 36#define LOG_ERROR(...) LOG (GNUNET_ERROR_TYPE_ERROR, __VA_ARGS__)
38 LOG (GNUNET_ERROR_TYPE_ERROR, __VA_ARGS__)
39 37
40/** 38/**
41 * Log an error message at log-level 'level' that indicates 39 * Log an error message at log-level 'level' that indicates
42 * a failure of the command 'cmd' on file 'filename' 40 * a failure of the command 'cmd' on file 'filename'
43 * with the message given by strerror(errno). 41 * with the message given by strerror(errno).
44 */ 42 */
45#define LOG_SQLITE(db, msg, level, cmd) \ 43#define LOG_SQLITE(db, msg, level, cmd) \
46 do { \ 44 do \
47 GNUNET_log_from (level, "sqlite", _("`%s' failed at %s:%d with error: %s\n"), \ 45 { \
48 cmd, __FILE__,__LINE__, sqlite3_errmsg(db)); \ 46 GNUNET_log_from (level, \
49 if (msg != NULL) \ 47 "sqlite", \
50 GNUNET_asprintf(msg, _("`%s' failed at %s:%u with error: %s"), cmd, \ 48 _ ("`%s' failed at %s:%d with error: %s\n"), \
51 __FILE__, __LINE__, sqlite3_errmsg(db)); \ 49 cmd, \
52 } while(0) 50 __FILE__, \
51 __LINE__, \
52 sqlite3_errmsg (db)); \
53 if (msg != NULL) \
54 GNUNET_asprintf (msg, \
55 _ ("`%s' failed at %s:%u with error: %s"), \
56 cmd, \
57 __FILE__, \
58 __LINE__, \
59 sqlite3_errmsg (db)); \
60 } while (0)
53 61
54 62
55/** 63/**
@@ -97,11 +105,11 @@ link_processor (void *cls,
97 unsigned int latency, 105 unsigned int latency,
98 unsigned int loss) 106 unsigned int loss)
99{ 107{
100 if ( (SQLITE_OK != sqlite3_bind_int (stmt_insert, 1, A)) || 108 if ((SQLITE_OK != sqlite3_bind_int (stmt_insert, 1, A)) ||
101 (SQLITE_OK != sqlite3_bind_int (stmt_insert, 2, B)) || 109 (SQLITE_OK != sqlite3_bind_int (stmt_insert, 2, B)) ||
102 (SQLITE_OK != sqlite3_bind_int (stmt_insert, 3, bandwidth)) || 110 (SQLITE_OK != sqlite3_bind_int (stmt_insert, 3, bandwidth)) ||
103 (SQLITE_OK != sqlite3_bind_int (stmt_insert, 4, latency)) || 111 (SQLITE_OK != sqlite3_bind_int (stmt_insert, 4, latency)) ||
104 (SQLITE_OK != sqlite3_bind_int (stmt_insert, 5, loss)) ) 112 (SQLITE_OK != sqlite3_bind_int (stmt_insert, 5, loss)))
105 { 113 {
106 LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_int"); 114 LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_int");
107 return GNUNET_SYSERR; 115 return GNUNET_SYSERR;
@@ -111,11 +119,11 @@ link_processor (void *cls,
111 LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_step"); 119 LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_step");
112 return GNUNET_SYSERR; 120 return GNUNET_SYSERR;
113 } 121 }
114 FPRINTF (stdout, "%u -> %u\n", A, B); 122 fprintf (stdout, "%u -> %u\n", A, B);
115 GNUNET_break (SQLITE_OK == sqlite3_reset (stmt_insert)); 123 GNUNET_break (SQLITE_OK == sqlite3_reset (stmt_insert));
116 //GNUNET_break (SQLITE_OK == sqlite3_clear_bindings (stmt_insert)); 124 //GNUNET_break (SQLITE_OK == sqlite3_clear_bindings (stmt_insert));
117 if ( (SQLITE_OK != sqlite3_bind_int (stmt_insert, 1, B)) || 125 if ((SQLITE_OK != sqlite3_bind_int (stmt_insert, 1, B)) ||
118 (SQLITE_OK != sqlite3_bind_int (stmt_insert, 2, A)) ) 126 (SQLITE_OK != sqlite3_bind_int (stmt_insert, 2, A)))
119 { 127 {
120 LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_int"); 128 LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_int");
121 return GNUNET_SYSERR; 129 return GNUNET_SYSERR;
@@ -125,7 +133,7 @@ link_processor (void *cls,
125 LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_step"); 133 LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_step");
126 return GNUNET_SYSERR; 134 return GNUNET_SYSERR;
127 } 135 }
128 FPRINTF (stdout, "%u -> %u\n", B, A); 136 fprintf (stdout, "%u -> %u\n", B, A);
129 GNUNET_break (SQLITE_OK == sqlite3_reset (stmt_insert)); 137 GNUNET_break (SQLITE_OK == sqlite3_reset (stmt_insert));
130 return GNUNET_OK; 138 return GNUNET_OK;
131} 139}
@@ -142,31 +150,29 @@ link_processor (void *cls,
142static int 150static int
143setup_db (const char *dbfile) 151setup_db (const char *dbfile)
144{ 152{
145 const char *query_create = 153 const char *query_create = "CREATE TABLE whitelist ("
146 "CREATE TABLE whitelist (" 154 "id INTEGER,"
147 "id INTEGER," 155 "oid INTEGER,"
148 "oid INTEGER," 156 "bandwidth INTEGER DEFAULT NULL,"
149 "bandwidth INTEGER DEFAULT NULL," 157 "latency INTEGER DEFAULT NULL,"
150 "latency INTEGER DEFAULT NULL," 158 "loss INTEGER DEFAULT NULL,"
151 "loss INTEGER DEFAULT NULL," 159 " UNIQUE ("
152 " UNIQUE (" 160 " id,"
153 " id," 161 " oid"
154 " oid" 162 " ) ON CONFLICT IGNORE"
155 " ) ON CONFLICT IGNORE" 163 ");";
156 ");"; 164 const char *query_insert = "INSERT INTO whitelist("
157 const char *query_insert = 165 " id,"
158 "INSERT INTO whitelist(" 166 " oid,"
159 " id," 167 " bandwidth,"
160 " oid," 168 " latency,"
161 " bandwidth," 169 " loss"
162 " latency," 170 ") VALUES ("
163 " loss" 171 " ?1,"
164 ") VALUES (" 172 " ?2,"
165 " ?1," 173 " ?3,"
166 " ?2," 174 " ?4,"
167 " ?3," 175 " ?5);";
168 " ?4,"
169 " ?5);";
170 int ret; 176 int ret;
171 177
172 ret = GNUNET_SYSERR; 178 ret = GNUNET_SYSERR;
@@ -178,21 +184,23 @@ setup_db (const char *dbfile)
178 if (0 != sqlite3_exec (db, query_create, NULL, NULL, NULL)) 184 if (0 != sqlite3_exec (db, query_create, NULL, NULL, NULL))
179 { 185 {
180 LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec"); 186 LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec");
181 FPRINTF (stderr, "Error: %d. Perhaps the database `%s' already exits.\n", 187 fprintf (stderr,
188 "Error: %d. Perhaps the database `%s' already exits.\n",
182 sqlite3_errcode (db), 189 sqlite3_errcode (db),
183 dbfile); 190 dbfile);
184 goto err_ret; 191 goto err_ret;
185 } 192 }
186 GNUNET_break (0 == sqlite3_exec (db, "PRAGMA synchronous = 0;", NULL, NULL, NULL)); 193 GNUNET_break (0 ==
187 if (SQLITE_OK != sqlite3_prepare_v2 (db, query_insert, -1, 194 sqlite3_exec (db, "PRAGMA synchronous = 0;", NULL, NULL, NULL));
188 &stmt_insert, NULL)) 195 if (SQLITE_OK !=
196 sqlite3_prepare_v2 (db, query_insert, -1, &stmt_insert, NULL))
189 { 197 {
190 LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_prepare_v2"); 198 LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_prepare_v2");
191 goto err_ret; 199 goto err_ret;
192 } 200 }
193 ret = GNUNET_OK; 201 ret = GNUNET_OK;
194 202
195 err_ret: 203err_ret:
196 return ret; 204 return ret;
197} 205}
198 206
@@ -206,7 +214,9 @@ setup_db (const char *dbfile)
206 * @param cfg the configuration file handle 214 * @param cfg the configuration file handle
207 */ 215 */
208static void 216static void
209run (void *cls, char *const *args, const char *cfgfile, 217run (void *cls,
218 char *const *args,
219 const char *cfgfile,
210 const struct GNUNET_CONFIGURATION_Handle *config) 220 const struct GNUNET_CONFIGURATION_Handle *config)
211{ 221{
212 const char *dbfile; 222 const char *dbfile;
@@ -222,24 +232,24 @@ run (void *cls, char *const *args, const char *cfgfile,
222 arg_uint2 = 0; /* make compilers happy */ 232 arg_uint2 = 0; /* make compilers happy */
223 if (NULL == args) 233 if (NULL == args)
224 { 234 {
225 LOG_ERROR (_("Need at least 2 arguments\n")); 235 LOG_ERROR (_ ("Need at least 2 arguments\n"));
226 return; 236 return;
227 } 237 }
228 if (NULL == (dbfile = args[argc++])) 238 if (NULL == (dbfile = args[argc++]))
229 { 239 {
230 LOG_ERROR (_("Database filename missing\n")); 240 LOG_ERROR (_ ("Database filename missing\n"));
231 return; 241 return;
232 } 242 }
233 if (GNUNET_OK != setup_db (dbfile)) 243 if (GNUNET_OK != setup_db (dbfile))
234 return; 244 return;
235 if (NULL == (topology_string = args[argc++])) 245 if (NULL == (topology_string = args[argc++]))
236 { 246 {
237 LOG_ERROR (_("Topology string missing\n")); 247 LOG_ERROR (_ ("Topology string missing\n"));
238 return; 248 return;
239 } 249 }
240 if (GNUNET_YES != GNUNET_TESTBED_topology_get_ (&topology, topology_string)) 250 if (GNUNET_YES != GNUNET_TESTBED_topology_get_ (&topology, topology_string))
241 { 251 {
242 LOG_ERROR (_("Invalid topology: %s\n"), topology_string); 252 LOG_ERROR (_ ("Invalid topology: %s\n"), topology_string);
243 return; 253 return;
244 } 254 }
245 arg_str1 = NULL; 255 arg_str1 = NULL;
@@ -252,13 +262,13 @@ run (void *cls, char *const *args, const char *cfgfile,
252 case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: 262 case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE:
253 if (NULL == (value = args[argc++])) 263 if (NULL == (value = args[argc++]))
254 { 264 {
255 LOG_ERROR (_("An argument is missing for given topology `%s'\n"), 265 LOG_ERROR (_ ("An argument is missing for given topology `%s'\n"),
256 topology_string); 266 topology_string);
257 return; 267 return;
258 } 268 }
259 if (-1 == SSCANF (value, "%u", &arg_uint1)) 269 if (-1 == sscanf (value, "%u", &arg_uint1))
260 { 270 {
261 LOG_ERROR (_("Invalid argument `%s' given as topology argument\n"), 271 LOG_ERROR (_ ("Invalid argument `%s' given as topology argument\n"),
262 value); 272 value);
263 return; 273 return;
264 } 274 }
@@ -266,7 +276,7 @@ run (void *cls, char *const *args, const char *cfgfile,
266 case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: 276 case GNUNET_TESTBED_TOPOLOGY_FROM_FILE:
267 if (NULL == (arg_str1 = args[argc++])) 277 if (NULL == (arg_str1 = args[argc++]))
268 { 278 {
269 LOG_ERROR (_("Filename argument missing for topology `%s'\n"), 279 LOG_ERROR (_ ("Filename argument missing for topology `%s'\n"),
270 topology_string); 280 topology_string);
271 return; 281 return;
272 } 282 }
@@ -280,13 +290,13 @@ run (void *cls, char *const *args, const char *cfgfile,
280 case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: 290 case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE:
281 if (NULL == (value = args[argc++])) 291 if (NULL == (value = args[argc++]))
282 { 292 {
283 LOG_ERROR (_("Second argument for topology `%s' is missing\n"), 293 LOG_ERROR (_ ("Second argument for topology `%s' is missing\n"),
284 topology_string); 294 topology_string);
285 return; 295 return;
286 } 296 }
287 if (-1 == SSCANF (value, "%u", &arg_uint2)) 297 if (-1 == sscanf (value, "%u", &arg_uint2))
288 { 298 {
289 LOG_ERROR (_("Invalid argument `%s'; expecting unsigned int\n"), value); 299 LOG_ERROR (_ ("Invalid argument `%s'; expecting unsigned int\n"), value);
290 return; 300 return;
291 } 301 }
292 break; 302 break;
@@ -301,23 +311,31 @@ run (void *cls, char *const *args, const char *cfgfile,
301 case GNUNET_TESTBED_TOPOLOGY_STAR: 311 case GNUNET_TESTBED_TOPOLOGY_STAR:
302 case GNUNET_TESTBED_TOPOLOGY_CLIQUE: 312 case GNUNET_TESTBED_TOPOLOGY_CLIQUE:
303 case GNUNET_TESTBED_TOPOLOGY_2D_TORUS: 313 case GNUNET_TESTBED_TOPOLOGY_2D_TORUS:
304 GNUNET_TESTBED_underlay_construct_ (num_peers, link_processor, NULL, 314 GNUNET_TESTBED_underlay_construct_ (num_peers,
315 link_processor,
316 NULL,
305 topology); 317 topology);
306 break; 318 break;
307 case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: 319 case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI:
308 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: 320 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING:
309 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: 321 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD:
310 GNUNET_TESTBED_underlay_construct_ (num_peers, link_processor, NULL, 322 GNUNET_TESTBED_underlay_construct_ (num_peers,
323 link_processor,
324 NULL,
311 topology, 325 topology,
312 arg_uint1); 326 arg_uint1);
313 break; 327 break;
314 case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: 328 case GNUNET_TESTBED_TOPOLOGY_FROM_FILE:
315 GNUNET_TESTBED_underlay_construct_ (num_peers, link_processor, NULL, 329 GNUNET_TESTBED_underlay_construct_ (num_peers,
330 link_processor,
331 NULL,
316 topology, 332 topology,
317 arg_str1); 333 arg_str1);
318 break; 334 break;
319 case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: 335 case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE:
320 GNUNET_TESTBED_underlay_construct_ (num_peers, link_processor, NULL, 336 GNUNET_TESTBED_underlay_construct_ (num_peers,
337 link_processor,
338 NULL,
321 topology, 339 topology,
322 arg_uint1, 340 arg_uint1,
323 arg_uint2); 341 arg_uint2);
@@ -337,37 +355,41 @@ main (int argc, char *const argv[])
337 struct GNUNET_GETOPT_CommandLineOption option[] = { 355 struct GNUNET_GETOPT_CommandLineOption option[] = {
338 356
339 GNUNET_GETOPT_option_uint ('p', 357 GNUNET_GETOPT_option_uint ('p',
340 "num-peers", 358 "num-peers",
341 "COUNT", 359 "COUNT",
342 gettext_noop ("create COUNT number of peers"), 360 gettext_noop ("create COUNT number of peers"),
343 &num_peers), 361 &num_peers),
344 GNUNET_GETOPT_OPTION_END 362 GNUNET_GETOPT_OPTION_END};
345 };
346 363
347 int ret; 364 int ret;
348 365
349 exit_result = GNUNET_SYSERR; 366 exit_result = GNUNET_SYSERR;
350 ret = 367 ret = GNUNET_PROGRAM_run (
351 GNUNET_PROGRAM_run (argc, argv, "gnunet-underlay-topology", 368 argc,
352 _("Generates SQLite3 database representing a given underlay topology.\n" 369 argv,
353 "Usage: gnunet-underlay-topology [OPTIONS] db-filename TOPO [TOPOOPTS]\n" 370 "gnunet-underlay-topology",
354 "The following options are available for TOPO followed by TOPOOPTS if applicable:\n" 371 _ (
355 "\t LINE\n" 372 "Generates SQLite3 database representing a given underlay topology.\n"
356 "\t RING\n" 373 "Usage: gnunet-underlay-topology [OPTIONS] db-filename TOPO [TOPOOPTS]\n"
357 "\t RANDOM <num_rnd_links>\n" 374 "The following options are available for TOPO followed by TOPOOPTS if applicable:\n"
358 "\t SMALL_WORLD <num_rnd_links>\n" 375 "\t LINE\n"
359 "\t SMALL_WORLD_RING <num_rnd_links>\n" 376 "\t RING\n"
360 "\t CLIQUE\n" 377 "\t RANDOM <num_rnd_links>\n"
361 "\t 2D_TORUS\n" 378 "\t SMALL_WORLD <num_rnd_links>\n"
362 "\t SCALE_FREE <cap> <m>\n" 379 "\t SMALL_WORLD_RING <num_rnd_links>\n"
363 "\t FROM_FILE <filename>\n" 380 "\t CLIQUE\n"
364 "TOPOOPTS:\n" 381 "\t 2D_TORUS\n"
365 "\t num_rnd_links: The number of random links\n" 382 "\t SCALE_FREE <cap> <m>\n"
366 "\t cap: the maximum number of links a node can have\n" 383 "\t FROM_FILE <filename>\n"
367 "\t m: the number of links a node should have while joining the network\n" 384 "TOPOOPTS:\n"
368 "\t filename: the path of the file which contains topology information\n" 385 "\t num_rnd_links: The number of random links\n"
369 "NOTE: the format of the above file is descibed here: https://www.gnunet.org/content/topology-file-format\n"), 386 "\t cap: the maximum number of links a node can have\n"
370 option, &run, NULL); 387 "\t m: the number of links a node should have while joining the network\n"
388 "\t filename: the path of the file which contains topology information\n"
389 "NOTE: the format of the above file is descibed here: https://www.gnunet.org/content/topology-file-format\n"),
390 option,
391 &run,
392 NULL);
371 if (NULL != stmt_insert) 393 if (NULL != stmt_insert)
372 sqlite3_finalize (stmt_insert); 394 sqlite3_finalize (stmt_insert);
373 if (NULL != db) 395 if (NULL != db)
diff --git a/src/testbed/gnunet-helper-testbed.c b/src/testbed/gnunet-helper-testbed.c
index 72d7fe16f..a45f8de03 100644
--- a/src/testbed/gnunet-helper-testbed.c
+++ b/src/testbed/gnunet-helper-testbed.c
@@ -267,7 +267,7 @@ child_death_task (void *cls)
267 GNUNET_OS_process_destroy (testbed); 267 GNUNET_OS_process_destroy (testbed);
268 testbed = NULL; 268 testbed = NULL;
269 /* Send SIGTERM to our process group */ 269 /* Send SIGTERM to our process group */
270 if (0 != PLIBC_KILL (0, GNUNET_TERM_SIG)) 270 if (0 != kill (0, GNUNET_TERM_SIG))
271 { 271 {
272 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "signal"); 272 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "signal");
273 GNUNET_SCHEDULER_shutdown (); /* Couldn't send the signal, we shutdown frowning */ 273 GNUNET_SCHEDULER_shutdown (); /* Couldn't send the signal, we shutdown frowning */
diff --git a/src/testbed/test_testbed_api_3peers_3controllers.c b/src/testbed/test_testbed_api_3peers_3controllers.c
index 8c976e13b..1d1d1ce44 100644
--- a/src/testbed/test_testbed_api_3peers_3controllers.c
+++ b/src/testbed/test_testbed_api_3peers_3controllers.c
@@ -853,7 +853,7 @@ host_habitable_cb (void *cls,
853 hc_handle = NULL; 853 hc_handle = NULL;
854 if (GNUNET_NO == status) 854 if (GNUNET_NO == status)
855 { 855 {
856 (void) PRINTF ("%s", 856 (void) printf ("%s",
857 "Unable to run the test as this system is not configured " 857 "Unable to run the test as this system is not configured "
858 "to use password less SSH logins to localhost.\n" 858 "to use password less SSH logins to localhost.\n"
859 "Skipping test\n"); 859 "Skipping test\n");
@@ -895,7 +895,7 @@ run (void *cls, char *const *args, const char *cfgfile,
895 { 895 {
896 GNUNET_TESTBED_host_destroy (host); 896 GNUNET_TESTBED_host_destroy (host);
897 host = NULL; 897 host = NULL;
898 (void) PRINTF ("%s", 898 (void) printf ("%s",
899 "Unable to run the test as this system is not configured " 899 "Unable to run the test as this system is not configured "
900 "to use password less SSH logins to localhost.\n" 900 "to use password less SSH logins to localhost.\n"
901 "Skipping test\n"); 901 "Skipping test\n");
diff --git a/src/testbed/test_testbed_api_controllerlink.c b/src/testbed/test_testbed_api_controllerlink.c
index 181d7d86d..6c1a24f9c 100644
--- a/src/testbed/test_testbed_api_controllerlink.c
+++ b/src/testbed/test_testbed_api_controllerlink.c
@@ -45,14 +45,12 @@
45/** 45/**
46 * Generic logging shortcut 46 * Generic logging shortcut
47 */ 47 */
48#define LOG(kind,...) \ 48#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
49 GNUNET_log (kind, __VA_ARGS__)
50 49
51/** 50/**
52 * Debug logging shorthand 51 * Debug logging shorthand
53 */ 52 */
54#define LOG_DEBUG(...) \ 53#define LOG_DEBUG(...) LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
55 LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
56 54
57/** 55/**
58 * Different stages in testing 56 * Different stages in testing
@@ -294,15 +292,18 @@ static enum Stage result;
294/** 292/**
295 * shortcut to exit during failure 293 * shortcut to exit during failure
296 */ 294 */
297#define FAIL_TEST(cond) do { \ 295#define FAIL_TEST(cond) \
298 if (!(cond)) { \ 296 do \
299 GNUNET_break(0); \ 297 { \
300 if (NULL != abort_task) \ 298 if (! (cond)) \
301 GNUNET_SCHEDULER_cancel (abort_task); \ 299 { \
302 abort_task = NULL; \ 300 GNUNET_break (0); \
303 GNUNET_SCHEDULER_shutdown (); \ 301 if (NULL != abort_task) \
304 return; \ 302 GNUNET_SCHEDULER_cancel (abort_task); \
305 } \ 303 abort_task = NULL; \
304 GNUNET_SCHEDULER_shutdown (); \
305 return; \
306 } \
306 } while (0) 307 } while (0)
307 308
308 309
@@ -357,9 +358,7 @@ do_shutdown (void *cls)
357static void 358static void
358do_abort (void *cls) 359do_abort (void *cls)
359{ 360{
360 LOG (GNUNET_ERROR_TYPE_WARNING, 361 LOG (GNUNET_ERROR_TYPE_WARNING, "Aborting in stage %d\n", result);
361 "Aborting in stage %d\n",
362 result);
363 abort_task = NULL; 362 abort_task = NULL;
364 GNUNET_SCHEDULER_shutdown (); 363 GNUNET_SCHEDULER_shutdown ();
365} 364}
@@ -430,9 +429,7 @@ delay_task (void *cls)
430 * @param emsg NULL if peer is not NULL; else MAY contain the error description 429 * @param emsg NULL if peer is not NULL; else MAY contain the error description
431 */ 430 */
432static void 431static void
433peer_create_cb (void *cls, 432peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
434 struct GNUNET_TESTBED_Peer *peer,
435 const char *emsg)
436{ 433{
437 FAIL_TEST (NULL != peer); 434 FAIL_TEST (NULL != peer);
438 FAIL_TEST (NULL == emsg); 435 FAIL_TEST (NULL == emsg);
@@ -455,11 +452,10 @@ peer_create_cb (void *cls,
455 slave2_peer = peer; 452 slave2_peer = peer;
456 GNUNET_TESTBED_operation_done (op); 453 GNUNET_TESTBED_operation_done (op);
457 op = NULL; 454 op = NULL;
458 delay_task_id = 455 delay_task_id = GNUNET_SCHEDULER_add_delayed (
459 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 456 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
460 (GNUNET_TIME_UNIT_SECONDS, 1), 457 &delay_task,
461 &delay_task, 458 NULL);
462 NULL);
463 return; 459 return;
464 case SLAVE3_STARTED: 460 case SLAVE3_STARTED:
465 result = SLAVE3_PEER_CREATE_SUCCESS; 461 result = SLAVE3_PEER_CREATE_SUCCESS;
@@ -500,8 +496,7 @@ check_operation_success (const struct GNUNET_TESTBED_EventInformation *event)
500 * @param event information about the event 496 * @param event information about the event
501 */ 497 */
502static void 498static void
503controller_cb (void *cls, 499controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
504 const struct GNUNET_TESTBED_EventInformation *event)
505{ 500{
506 switch (result) 501 switch (result)
507 { 502 {
@@ -558,8 +553,8 @@ controller_cb (void *cls,
558 result = SLAVE3_PEER_START_SUCCESS; 553 result = SLAVE3_PEER_START_SUCCESS;
559 sleep (1); 554 sleep (1);
560 LOG_DEBUG ("**************************************\n"); 555 LOG_DEBUG ("**************************************\n");
561 op = GNUNET_TESTBED_overlay_connect (mc, NULL, NULL, slave2_peer, 556 op =
562 slave3_peer); 557 GNUNET_TESTBED_overlay_connect (mc, NULL, NULL, slave2_peer, slave3_peer);
563 FAIL_TEST (NULL != op); 558 FAIL_TEST (NULL != op);
564 break; 559 break;
565 case SLAVE3_PEER_START_SUCCESS: 560 case SLAVE3_PEER_START_SUCCESS:
@@ -570,10 +565,10 @@ controller_cb (void *cls,
570 result = SLAVE2_SLAVE3_PEERS_CONNECTED; 565 result = SLAVE2_SLAVE3_PEERS_CONNECTED;
571 GNUNET_TESTBED_operation_done (op); 566 GNUNET_TESTBED_operation_done (op);
572 op = NULL; 567 op = NULL;
573 delay_task_id = 568 delay_task_id = GNUNET_SCHEDULER_add_delayed (
574 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 569 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
575 (GNUNET_TIME_UNIT_SECONDS, 1), &delay_task, 570 &delay_task,
576 NULL); 571 NULL);
577 break; 572 break;
578 case SLAVE1_PEER_STOP_SUCCESS: 573 case SLAVE1_PEER_STOP_SUCCESS:
579 FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type); 574 FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type);
@@ -581,8 +576,8 @@ controller_cb (void *cls,
581 FAIL_TEST (event->details.peer_start.peer == slave2_peer); 576 FAIL_TEST (event->details.peer_start.peer == slave2_peer);
582 GNUNET_TESTBED_operation_done (op); 577 GNUNET_TESTBED_operation_done (op);
583 result = SLAVE2_PEER_START_SUCCESS; 578 result = SLAVE2_PEER_START_SUCCESS;
584 op = GNUNET_TESTBED_overlay_connect (mc, NULL, NULL, master_peer, 579 op =
585 slave2_peer); 580 GNUNET_TESTBED_overlay_connect (mc, NULL, NULL, master_peer, slave2_peer);
586 break; 581 break;
587 case SLAVE2_PEER_START_SUCCESS: 582 case SLAVE2_PEER_START_SUCCESS:
588 FAIL_TEST (NULL != event); 583 FAIL_TEST (NULL != event);
@@ -592,10 +587,10 @@ controller_cb (void *cls,
592 result = MASTER_SLAVE2_PEERS_CONNECTED; 587 result = MASTER_SLAVE2_PEERS_CONNECTED;
593 GNUNET_TESTBED_operation_done (op); 588 GNUNET_TESTBED_operation_done (op);
594 op = NULL; 589 op = NULL;
595 delay_task_id = 590 delay_task_id = GNUNET_SCHEDULER_add_delayed (
596 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 591 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
597 (GNUNET_TIME_UNIT_SECONDS, 1), &delay_task, 592 &delay_task,
598 NULL); 593 NULL);
599 break; 594 break;
600 case SLAVE2_SLAVE3_PEERS_CONNECTED: 595 case SLAVE2_SLAVE3_PEERS_CONNECTED:
601 FAIL_TEST (GNUNET_TESTBED_ET_PEER_STOP == event->type); 596 FAIL_TEST (GNUNET_TESTBED_ET_PEER_STOP == event->type);
@@ -714,7 +709,8 @@ registration_cont (void *cls, const char *emsg)
714 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case 709 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
715 */ 710 */
716static void 711static void
717status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, 712status_cb (void *cls,
713 const struct GNUNET_CONFIGURATION_Handle *config,
718 int status) 714 int status)
719{ 715{
720 switch (result) 716 switch (result)
@@ -726,8 +722,10 @@ status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config,
726 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); 722 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP);
727 event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); 723 event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT);
728 event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); 724 event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED);
729 mc = GNUNET_TESTBED_controller_connect (host, event_mask, 725 mc = GNUNET_TESTBED_controller_connect (host,
730 &controller_cb, NULL); 726 event_mask,
727 &controller_cb,
728 NULL);
731 FAIL_TEST (NULL != mc); 729 FAIL_TEST (NULL != mc);
732 result = MASTER_STARTED; 730 result = MASTER_STARTED;
733 op = GNUNET_TESTBED_peer_create (mc, host, cfg, peer_create_cb, NULL); 731 op = GNUNET_TESTBED_peer_create (mc, host, cfg, peer_create_cb, NULL);
@@ -759,7 +757,7 @@ host_habitable_cb (void *cls,
759 hc_handle = NULL; 757 hc_handle = NULL;
760 if (GNUNET_NO == status) 758 if (GNUNET_NO == status)
761 { 759 {
762 (void) PRINTF ("%s", 760 (void) printf ("%s",
763 "Unable to run the test as this system is not configured " 761 "Unable to run the test as this system is not configured "
764 "to use password less SSH logins to localhost.\n" 762 "to use password less SSH logins to localhost.\n"
765 "Skipping test\n"); 763 "Skipping test\n");
@@ -769,8 +767,7 @@ host_habitable_cb (void *cls,
769 result = SKIP; 767 result = SKIP;
770 return; 768 return;
771 } 769 }
772 cp = GNUNET_TESTBED_controller_start ("127.0.0.1", host, status_cb, 770 cp = GNUNET_TESTBED_controller_start ("127.0.0.1", host, status_cb, NULL);
773 NULL);
774} 771}
775 772
776 773
@@ -783,34 +780,35 @@ host_habitable_cb (void *cls,
783 * @param cfg the configuration file handle 780 * @param cfg the configuration file handle
784 */ 781 */
785static void 782static void
786run (void *cls, char *const *args, const char *cfgfile, 783run (void *cls,
784 char *const *args,
785 const char *cfgfile,
787 const struct GNUNET_CONFIGURATION_Handle *config) 786 const struct GNUNET_CONFIGURATION_Handle *config)
788{ 787{
789 cfg = GNUNET_CONFIGURATION_dup (config); 788 cfg = GNUNET_CONFIGURATION_dup (config);
790 host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0); 789 host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0);
791 FAIL_TEST (NULL != host); 790 FAIL_TEST (NULL != host);
792 if (NULL == 791 if (NULL == (hc_handle = GNUNET_TESTBED_is_host_habitable (host,
793 (hc_handle = 792 config,
794 GNUNET_TESTBED_is_host_habitable (host, config, &host_habitable_cb, 793 &host_habitable_cb,
795 NULL))) 794 NULL)))
796 { 795 {
797 GNUNET_TESTBED_host_destroy (host); 796 GNUNET_TESTBED_host_destroy (host);
798 GNUNET_CONFIGURATION_destroy (cfg); 797 GNUNET_CONFIGURATION_destroy (cfg);
799 cfg = NULL; 798 cfg = NULL;
800 host = NULL; 799 host = NULL;
801 (void) PRINTF ("%s", 800 (void) printf ("%s",
802 "Unable to run the test as this system is not configured " 801 "Unable to run the test as this system is not configured "
803 "to use password less SSH logins to localhost.\n" 802 "to use password less SSH logins to localhost.\n"
804 "Marking test as successful\n"); 803 "Marking test as successful\n");
805 result = SKIP; 804 result = SKIP;
806 return; 805 return;
807 } 806 }
808 abort_task = 807 abort_task = GNUNET_SCHEDULER_add_delayed (
809 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 808 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5),
810 (GNUNET_TIME_UNIT_MINUTES, 5), &do_abort, 809 &do_abort,
811 NULL); 810 NULL);
812 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 811 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
813 NULL);
814} 812}
815 813
816 814
@@ -820,20 +818,21 @@ run (void *cls, char *const *args, const char *cfgfile,
820int 818int
821main (int argc, char **argv) 819main (int argc, char **argv)
822{ 820{
823 char *const argv2[] = { "test_testbed_api_controllerlink", 821 char *const argv2[] = {"test_testbed_api_controllerlink",
824 "-c", "test_testbed_api.conf", 822 "-c",
825 NULL 823 "test_testbed_api.conf",
826 }; 824 NULL};
827 struct GNUNET_GETOPT_CommandLineOption options[] = { 825 struct GNUNET_GETOPT_CommandLineOption options[] = {GNUNET_GETOPT_OPTION_END};
828 GNUNET_GETOPT_OPTION_END
829 };
830 int ret; 826 int ret;
831 827
832 result = INIT; 828 result = INIT;
833 ret = 829 ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1,
834 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, 830 argv2,
835 "test_testbed_api_controllerlink", "nohelp", options, 831 "test_testbed_api_controllerlink",
836 &run, NULL); 832 "nohelp",
833 options,
834 &run,
835 NULL);
837 if (GNUNET_OK != ret) 836 if (GNUNET_OK != ret)
838 return 1; 837 return 1;
839 switch (result) 838 switch (result)
@@ -841,7 +840,7 @@ main (int argc, char **argv)
841 case SUCCESS: 840 case SUCCESS:
842 return 0; 841 return 0;
843 case SKIP: 842 case SKIP:
844 return 77; /* Mark test as skipped */ 843 return 77; /* Mark test as skipped */
845 default: 844 default:
846 return 1; 845 return 1;
847 } 846 }
diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c
index 6dbd99bc9..e824a5f23 100644
--- a/src/testbed/testbed_api_hosts.c
+++ b/src/testbed/testbed_api_hosts.c
@@ -42,31 +42,39 @@
42/** 42/**
43 * Generic logging shorthand 43 * Generic logging shorthand
44 */ 44 */
45#define LOG(kind, ...) \ 45#define LOG(kind, ...) GNUNET_log_from (kind, "testbed-api-hosts", __VA_ARGS__);
46 GNUNET_log_from (kind, "testbed-api-hosts", __VA_ARGS__);
47 46
48/** 47/**
49 * Debug logging shorthand 48 * Debug logging shorthand
50 */ 49 */
51#define LOG_DEBUG(...) \ 50#define LOG_DEBUG(...) LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__);
52 LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__);
53 51
54/** 52/**
55 * Prints API violation message 53 * Prints API violation message
56 */ 54 */
57#define API_VIOLATION(cond,errstr) \ 55#define API_VIOLATION(cond, errstr) \
58 do { \ 56 do \
59 if (cond) \ 57 { \
60 break; \ 58 if (cond) \
59 break; \
61 LOG (GNUNET_ERROR_TYPE_ERROR, "API violation detected: %s\n", errstr); \ 60 LOG (GNUNET_ERROR_TYPE_ERROR, "API violation detected: %s\n", errstr); \
62 GNUNET_assert (0); \ 61 GNUNET_assert (0); \
63 } while (0) 62 } while (0)
64 63
65/** 64/**
66 * Log an error message at log-level 'level' that indicates a failure of the 65 * Log an error message at log-level 'level' that indicates a failure of the
67 * command 'cmd' with the message given by gai_strerror(rc). 66 * command 'cmd' with the message given by gai_strerror(rc).
68 */ 67 */
69#define LOG_GAI(level, cmd, rc) do { LOG(level, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, gai_strerror(rc)); } while(0) 68#define LOG_GAI(level, cmd, rc) \
69 do \
70 { \
71 LOG (level, \
72 _ ("`%s' failed at %s:%d with error: %s\n"), \
73 cmd, \
74 __FILE__, \
75 __LINE__, \
76 gai_strerror (rc)); \
77 } while (0)
70 78
71/** 79/**
72 * Number of extra elements we create space for when we grow host list 80 * Number of extra elements we create space for when we grow host list
@@ -157,7 +165,6 @@ struct GNUNET_TESTBED_Host
157 * The port which is to be used for SSH 165 * The port which is to be used for SSH
158 */ 166 */
159 uint16_t port; 167 uint16_t port;
160
161}; 168};
162 169
163 170
@@ -201,8 +208,9 @@ GNUNET_TESTBED_host_lookup_by_id_ (uint32_t id)
201 * @return handle to the host, NULL on error 208 * @return handle to the host, NULL on error
202 */ 209 */
203struct GNUNET_TESTBED_Host * 210struct GNUNET_TESTBED_Host *
204GNUNET_TESTBED_host_create_by_id_ (uint32_t id, 211GNUNET_TESTBED_host_create_by_id_ (
205 const struct GNUNET_CONFIGURATION_Handle *cfg) 212 uint32_t id,
213 const struct GNUNET_CONFIGURATION_Handle *cfg)
206{ 214{
207 return GNUNET_TESTBED_host_create_with_id (id, NULL, NULL, cfg, 0); 215 return GNUNET_TESTBED_host_create_with_id (id, NULL, NULL, cfg, 0);
208} 216}
@@ -216,7 +224,7 @@ GNUNET_TESTBED_host_create_by_id_ (uint32_t id,
216 * 'localhost', but then obviously not globally unique) 224 * 'localhost', but then obviously not globally unique)
217 */ 225 */
218uint32_t 226uint32_t
219GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host * host) 227GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host *host)
220{ 228{
221 return host->id; 229 return host->id;
222} 230}
@@ -255,7 +263,7 @@ GNUNET_TESTBED_host_get_username_ (const struct GNUNET_TESTBED_Host *host)
255 * @return username to login to the host 263 * @return username to login to the host
256 */ 264 */
257uint16_t 265uint16_t
258GNUNET_TESTBED_host_get_ssh_port_ (const struct GNUNET_TESTBED_Host * host) 266GNUNET_TESTBED_host_get_ssh_port_ (const struct GNUNET_TESTBED_Host *host)
259{ 267{
260 return host->port; 268 return host->port;
261} 269}
@@ -294,8 +302,9 @@ GNUNET_TESTBED_host_get_cfg_ (const struct GNUNET_TESTBED_Host *host)
294 * @param new_cfg the new configuration to replace the old one 302 * @param new_cfg the new configuration to replace the old one
295 */ 303 */
296void 304void
297GNUNET_TESTBED_host_replace_cfg_ (struct GNUNET_TESTBED_Host *host, 305GNUNET_TESTBED_host_replace_cfg_ (
298 const struct GNUNET_CONFIGURATION_Handle *new_cfg) 306 struct GNUNET_TESTBED_Host *host,
307 const struct GNUNET_CONFIGURATION_Handle *new_cfg)
299{ 308{
300 GNUNET_CONFIGURATION_destroy (host->cfg); 309 GNUNET_CONFIGURATION_destroy (host->cfg);
301 host->cfg = GNUNET_CONFIGURATION_dup (new_cfg); 310 host->cfg = GNUNET_CONFIGURATION_dup (new_cfg);
@@ -316,11 +325,12 @@ GNUNET_TESTBED_host_replace_cfg_ (struct GNUNET_TESTBED_Host *host,
316 * @return handle to the host, NULL on error 325 * @return handle to the host, NULL on error
317 */ 326 */
318struct GNUNET_TESTBED_Host * 327struct GNUNET_TESTBED_Host *
319GNUNET_TESTBED_host_create_with_id (uint32_t id, const char *hostname, 328GNUNET_TESTBED_host_create_with_id (
320 const char *username, 329 uint32_t id,
321 const struct GNUNET_CONFIGURATION_Handle 330 const char *hostname,
322 *cfg, 331 const char *username,
323 uint16_t port) 332 const struct GNUNET_CONFIGURATION_Handle *cfg,
333 uint16_t port)
324{ 334{
325 struct GNUNET_TESTBED_Host *host; 335 struct GNUNET_TESTBED_Host *host;
326 unsigned int new_size; 336 unsigned int new_size;
@@ -337,8 +347,8 @@ GNUNET_TESTBED_host_create_with_id (uint32_t id, const char *hostname,
337 host->port = (0 == port) ? 22 : port; 347 host->port = (0 == port) ? 22 : port;
338 host->cfg = GNUNET_CONFIGURATION_dup (cfg); 348 host->cfg = GNUNET_CONFIGURATION_dup (cfg);
339 host->opq_parallel_overlay_connect_operations = 349 host->opq_parallel_overlay_connect_operations =
340 GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_ADAPTIVE, 350 GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_ADAPTIVE,
341 UINT_MAX); 351 UINT_MAX);
342 new_size = host_list_size; 352 new_size = host_list_size;
343 while (id >= new_size) 353 while (id >= new_size)
344 new_size += HOST_LIST_GROW_STEP; 354 new_size += HOST_LIST_GROW_STEP;
@@ -363,17 +373,24 @@ GNUNET_TESTBED_host_create_with_id (uint32_t id, const char *hostname,
363 * @return handle to the host, NULL on error 373 * @return handle to the host, NULL on error
364 */ 374 */
365struct GNUNET_TESTBED_Host * 375struct GNUNET_TESTBED_Host *
366GNUNET_TESTBED_host_create (const char *hostname, const char *username, 376GNUNET_TESTBED_host_create (const char *hostname,
377 const char *username,
367 const struct GNUNET_CONFIGURATION_Handle *cfg, 378 const struct GNUNET_CONFIGURATION_Handle *cfg,
368 uint16_t port) 379 uint16_t port)
369{ 380{
370 static uint32_t uid_generator; 381 static uint32_t uid_generator;
371 382
372 if (NULL == hostname) 383 if (NULL == hostname)
373 return GNUNET_TESTBED_host_create_with_id (0, hostname, username, 384 return GNUNET_TESTBED_host_create_with_id (0,
374 cfg, port); 385 hostname,
375 return GNUNET_TESTBED_host_create_with_id (++uid_generator, hostname, 386 username,
376 username, cfg, port); 387 cfg,
388 port);
389 return GNUNET_TESTBED_host_create_with_id (++uid_generator,
390 hostname,
391 username,
392 cfg,
393 port);
377} 394}
378 395
379 396
@@ -389,10 +406,10 @@ GNUNET_TESTBED_host_create (const char *hostname, const char *username,
389 * @return number of hosts returned in 'hosts', 0 on error 406 * @return number of hosts returned in 'hosts', 0 on error
390 */ 407 */
391unsigned int 408unsigned int
392GNUNET_TESTBED_hosts_load_from_file (const char *filename, 409GNUNET_TESTBED_hosts_load_from_file (
393 const struct GNUNET_CONFIGURATION_Handle 410 const char *filename,
394 *cfg, 411 const struct GNUNET_CONFIGURATION_Handle *cfg,
395 struct GNUNET_TESTBED_Host ***hosts) 412 struct GNUNET_TESTBED_Host ***hosts)
396{ 413{
397 struct GNUNET_TESTBED_Host *starting_host; 414 struct GNUNET_TESTBED_Host *starting_host;
398 char *data; 415 char *data;
@@ -410,7 +427,7 @@ GNUNET_TESTBED_hosts_load_from_file (const char *filename,
410 GNUNET_assert (NULL != filename); 427 GNUNET_assert (NULL != filename);
411 if (GNUNET_YES != GNUNET_DISK_file_test (filename)) 428 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
412 { 429 {
413 LOG (GNUNET_ERROR_TYPE_WARNING, _("Hosts file %s not found\n"), filename); 430 LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Hosts file %s not found\n"), filename);
414 return 0; 431 return 0;
415 } 432 }
416 if (GNUNET_OK != 433 if (GNUNET_OK !=
@@ -418,14 +435,17 @@ GNUNET_TESTBED_hosts_load_from_file (const char *filename,
418 fs = 0; 435 fs = 0;
419 if (0 == fs) 436 if (0 == fs)
420 { 437 {
421 LOG (GNUNET_ERROR_TYPE_WARNING, _("Hosts file %s has no data\n"), filename); 438 LOG (GNUNET_ERROR_TYPE_WARNING,
439 _ ("Hosts file %s has no data\n"),
440 filename);
422 return 0; 441 return 0;
423 } 442 }
424 data = GNUNET_malloc (fs); 443 data = GNUNET_malloc (fs);
425 if (fs != GNUNET_DISK_fn_read (filename, data, fs)) 444 if (fs != GNUNET_DISK_fn_read (filename, data, fs))
426 { 445 {
427 GNUNET_free (data); 446 GNUNET_free (data);
428 LOG (GNUNET_ERROR_TYPE_WARNING, _("Hosts file %s cannot be read\n"), 447 LOG (GNUNET_ERROR_TYPE_WARNING,
448 _ ("Hosts file %s cannot be read\n"),
429 filename); 449 filename);
430 return 0; 450 return 0;
431 } 451 }
@@ -450,11 +470,12 @@ GNUNET_TESTBED_hosts_load_from_file (const char *filename,
450 username = NULL; 470 username = NULL;
451 hostname = NULL; 471 hostname = NULL;
452 port = 0; 472 port = 0;
453 if ((REG_NOMATCH == regexec (&rex, buf, 6, pmatch, 0)) 473 if ((REG_NOMATCH == regexec (&rex, buf, 6, pmatch, 0)) ||
454 || (-1 == pmatch[3].rm_so)) 474 (-1 == pmatch[3].rm_so))
455 { 475 {
456 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 476 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
457 "Error reading line `%s' in hostfile\n", buf); 477 "Error reading line `%s' in hostfile\n",
478 buf);
458 buf = &data[offset + 1]; 479 buf = &data[offset + 1];
459 continue; 480 continue;
460 } 481 }
@@ -462,19 +483,17 @@ GNUNET_TESTBED_hosts_load_from_file (const char *filename,
462 { 483 {
463 size = pmatch[2].rm_eo - pmatch[2].rm_so; 484 size = pmatch[2].rm_eo - pmatch[2].rm_so;
464 username = GNUNET_malloc (size + 1); 485 username = GNUNET_malloc (size + 1);
465 GNUNET_assert(0 != GNUNET_strlcpy (username, 486 GNUNET_assert (
466 buf + pmatch[2].rm_so, 487 0 != GNUNET_strlcpy (username, buf + pmatch[2].rm_so, size + 1));
467 size + 1));
468 } 488 }
469 if (-1 != pmatch[5].rm_so) 489 if (-1 != pmatch[5].rm_so)
470 { 490 {
471 (void) SSCANF (buf + pmatch[5].rm_so, "%5hd", &port); 491 (void) sscanf (buf + pmatch[5].rm_so, "%5hd", &port);
472 } 492 }
473 size = pmatch[3].rm_eo - pmatch[3].rm_so; 493 size = pmatch[3].rm_eo - pmatch[3].rm_so;
474 hostname = GNUNET_malloc (size + 1); 494 hostname = GNUNET_malloc (size + 1);
475 GNUNET_assert(0 != GNUNET_strlcpy (hostname, 495 GNUNET_assert (
476 buf + pmatch[3].rm_so, 496 0 != GNUNET_strlcpy (hostname, buf + pmatch[3].rm_so, size + 1));
477 size + 1));
478 LOG (GNUNET_ERROR_TYPE_DEBUG, 497 LOG (GNUNET_ERROR_TYPE_DEBUG,
479 "Successfully read host %s, port %d and user %s from file\n", 498 "Successfully read host %s, port %d and user %s from file\n",
480 (NULL == hostname) ? "NULL" : hostname, 499 (NULL == hostname) ? "NULL" : hostname,
@@ -483,8 +502,8 @@ GNUNET_TESTBED_hosts_load_from_file (const char *filename,
483 /* We store hosts in a static list; hence we only require the starting 502 /* We store hosts in a static list; hence we only require the starting
484 * host pointer in that list to access the newly created list of hosts */ 503 * host pointer in that list to access the newly created list of hosts */
485 if (NULL == starting_host) 504 if (NULL == starting_host)
486 starting_host = GNUNET_TESTBED_host_create (hostname, username, cfg, 505 starting_host =
487 port); 506 GNUNET_TESTBED_host_create (hostname, username, cfg, port);
488 else 507 else
489 (void) GNUNET_TESTBED_host_create (hostname, username, cfg, port); 508 (void) GNUNET_TESTBED_host_create (hostname, username, cfg, port);
490 count++; 509 count++;
@@ -522,7 +541,7 @@ simple_resolve (const char *host)
522 struct addrinfo hint; 541 struct addrinfo hint;
523 unsigned int rc; 542 unsigned int rc;
524 543
525 hint.ai_family = AF_INET; /* IPv4 */ 544 hint.ai_family = AF_INET; /* IPv4 */
526 hint.ai_socktype = 0; 545 hint.ai_socktype = 0;
527 hint.ai_protocol = 0; 546 hint.ai_protocol = 0;
528 hint.ai_addrlen = 0; 547 hint.ai_addrlen = 0;
@@ -562,13 +581,13 @@ simple_resolve (const char *host)
562 * @return number of hosts returned in 'hosts', 0 on error 581 * @return number of hosts returned in 'hosts', 0 on error
563 */ 582 */
564unsigned int 583unsigned int
565GNUNET_TESTBED_hosts_load_from_loadleveler (const struct 584GNUNET_TESTBED_hosts_load_from_loadleveler (
566 GNUNET_CONFIGURATION_Handle *cfg, 585 const struct GNUNET_CONFIGURATION_Handle *cfg,
567 struct GNUNET_TESTBED_Host ***hosts) 586 struct GNUNET_TESTBED_Host ***hosts)
568{ 587{
569#if !ENABLE_SUPERMUC 588#if ! ENABLE_SUPERMUC
570 LOG (GNUNET_ERROR_TYPE_ERROR, 589 LOG (GNUNET_ERROR_TYPE_ERROR,
571 _("The function %s is only available when compiled with (--with-ll)\n"), 590 _ ("The function %s is only available when compiled with (--with-ll)\n"),
572 __func__); 591 __func__);
573 GNUNET_assert (0); 592 GNUNET_assert (0);
574#else 593#else
@@ -607,8 +626,8 @@ GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host)
607 } 626 }
608 GNUNET_free_non_null ((char *) host->username); 627 GNUNET_free_non_null ((char *) host->username);
609 GNUNET_free_non_null ((char *) host->hostname); 628 GNUNET_free_non_null ((char *) host->hostname);
610 GNUNET_TESTBED_operation_queue_destroy_ 629 GNUNET_TESTBED_operation_queue_destroy_ (
611 (host->opq_parallel_overlay_connect_operations); 630 host->opq_parallel_overlay_connect_operations);
612 GNUNET_CONFIGURATION_destroy (host->cfg); 631 GNUNET_CONFIGURATION_destroy (host->cfg);
613 GNUNET_free (host); 632 GNUNET_free (host);
614 while (host_list_size >= HOST_LIST_GROW_STEP) 633 while (host_list_size >= HOST_LIST_GROW_STEP)
@@ -624,8 +643,8 @@ GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host)
624 host_list_size -= HOST_LIST_GROW_STEP; 643 host_list_size -= HOST_LIST_GROW_STEP;
625 } 644 }
626 host_list = 645 host_list =
627 GNUNET_realloc (host_list, 646 GNUNET_realloc (host_list,
628 sizeof (struct GNUNET_TESTBED_Host *) * host_list_size); 647 sizeof (struct GNUNET_TESTBED_Host *) * host_list_size);
629} 648}
630 649
631 650
@@ -636,15 +655,15 @@ GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host)
636 * @param controller the controller at which this host is registered 655 * @param controller the controller at which this host is registered
637 */ 656 */
638void 657void
639GNUNET_TESTBED_mark_host_registered_at_ (struct GNUNET_TESTBED_Host *host, 658GNUNET_TESTBED_mark_host_registered_at_ (
640 const struct GNUNET_TESTBED_Controller 659 struct GNUNET_TESTBED_Host *host,
641 *const controller) 660 const struct GNUNET_TESTBED_Controller *const controller)
642{ 661{
643 struct RegisteredController *rc; 662 struct RegisteredController *rc;
644 663
645 for (rc = host->rc_head; NULL != rc; rc = rc->next) 664 for (rc = host->rc_head; NULL != rc; rc = rc->next)
646 { 665 {
647 if (controller == rc->controller) /* already registered at controller */ 666 if (controller == rc->controller) /* already registered at controller */
648 { 667 {
649 GNUNET_break (0); 668 GNUNET_break (0);
650 return; 669 return;
@@ -663,13 +682,13 @@ GNUNET_TESTBED_mark_host_registered_at_ (struct GNUNET_TESTBED_Host *host,
663 * @param controller the controller at which this host has to be unmarked 682 * @param controller the controller at which this host has to be unmarked
664 */ 683 */
665void 684void
666GNUNET_TESTBED_deregister_host_at_ (struct GNUNET_TESTBED_Host *host, 685GNUNET_TESTBED_deregister_host_at_ (
667 const struct GNUNET_TESTBED_Controller 686 struct GNUNET_TESTBED_Host *host,
668 *const controller) 687 const struct GNUNET_TESTBED_Controller *const controller)
669{ 688{
670 struct RegisteredController *rc; 689 struct RegisteredController *rc;
671 690
672 for (rc = host->rc_head; NULL != rc; rc=rc->next) 691 for (rc = host->rc_head; NULL != rc; rc = rc->next)
673 if (controller == rc->controller) 692 if (controller == rc->controller)
674 break; 693 break;
675 if (NULL == rc) 694 if (NULL == rc)
@@ -690,15 +709,15 @@ GNUNET_TESTBED_deregister_host_at_ (struct GNUNET_TESTBED_Host *host,
690 * @return GNUNET_YES if registered; GNUNET_NO if not 709 * @return GNUNET_YES if registered; GNUNET_NO if not
691 */ 710 */
692int 711int
693GNUNET_TESTBED_is_host_registered_ (const struct GNUNET_TESTBED_Host *host, 712GNUNET_TESTBED_is_host_registered_ (
694 const struct GNUNET_TESTBED_Controller 713 const struct GNUNET_TESTBED_Host *host,
695 *const controller) 714 const struct GNUNET_TESTBED_Controller *const controller)
696{ 715{
697 struct RegisteredController *rc; 716 struct RegisteredController *rc;
698 717
699 for (rc = host->rc_head; NULL != rc; rc = rc->next) 718 for (rc = host->rc_head; NULL != rc; rc = rc->next)
700 { 719 {
701 if (controller == rc->controller) /* already registered at controller */ 720 if (controller == rc->controller) /* already registered at controller */
702 { 721 {
703 return GNUNET_YES; 722 return GNUNET_YES;
704 } 723 }
@@ -746,7 +765,6 @@ struct GNUNET_TESTBED_ControllerProc
746 * The message corresponding to send handle 765 * The message corresponding to send handle
747 */ 766 */
748 struct GNUNET_MessageHeader *msg; 767 struct GNUNET_MessageHeader *msg;
749
750}; 768};
751 769
752 770
@@ -763,7 +781,8 @@ copy_argv (const char *const *argv)
763 unsigned int argp; 781 unsigned int argp;
764 782
765 GNUNET_assert (NULL != argv); 783 GNUNET_assert (NULL != argv);
766 for (argp = 0; NULL != argv[argp]; argp++) ; 784 for (argp = 0; NULL != argv[argp]; argp++)
785 ;
767 argv_dup = GNUNET_malloc (sizeof (char *) * (argp + 1)); 786 argv_dup = GNUNET_malloc (sizeof (char *) * (argp + 1));
768 for (argp = 0; NULL != argv[argp]; argp++) 787 for (argp = 0; NULL != argv[argp]; argp++)
769 argv_dup[argp] = GNUNET_strdup (argv[argp]); 788 argv_dup[argp] = GNUNET_strdup (argv[argp]);
@@ -836,19 +855,18 @@ free_argv (char **argv)
836static char ** 855static char **
837gen_rsh_args (const char *port, const char *hostname, const char *username) 856gen_rsh_args (const char *port, const char *hostname, const char *username)
838{ 857{
839 static const char *default_ssh_args[] = { 858 static const char *default_ssh_args[] =
840 "ssh", 859 {"ssh",
841 "-o", 860 "-o",
842 "BatchMode=yes", 861 "BatchMode=yes",
843 "-o", 862 "-o",
844 "NoHostAuthenticationForLocalhost=yes", 863 "NoHostAuthenticationForLocalhost=yes",
845 "-o", 864 "-o",
846 "StrictHostKeyChecking=no", 865 "StrictHostKeyChecking=no",
847 "-o", 866 "-o",
848 "PasswordAuthentication=no", 867 "PasswordAuthentication=no",
849 "%h", 868 "%h",
850 NULL 869 NULL};
851 };
852 char **ssh_args; 870 char **ssh_args;
853 char *ssh_cmd; 871 char *ssh_cmd;
854 char *ssh_cmd_cp; 872 char *ssh_cmd_cp;
@@ -915,7 +933,7 @@ gen_rsh_args (const char *port, const char *hostname, const char *username)
915 * @return NULL-terminated args 933 * @return NULL-terminated args
916 */ 934 */
917static char ** 935static char **
918gen_rsh_suffix_args (const char * const *append_args) 936gen_rsh_suffix_args (const char *const *append_args)
919{ 937{
920 char **rshell_args; 938 char **rshell_args;
921 char *rshell_cmd; 939 char *rshell_cmd;
@@ -937,7 +955,9 @@ gen_rsh_suffix_args (const char * const *append_args)
937 if (NULL != append_args) 955 if (NULL != append_args)
938 { 956 {
939 for (append_cnt = 0; NULL != append_args[append_cnt]; append_cnt++) 957 for (append_cnt = 0; NULL != append_args[append_cnt]; append_cnt++)
940 GNUNET_array_append (rshell_args, cnt, GNUNET_strdup (append_args[append_cnt])); 958 GNUNET_array_append (rshell_args,
959 cnt,
960 GNUNET_strdup (append_args[append_cnt]));
941 } 961 }
942 GNUNET_array_append (rshell_args, cnt, NULL); 962 GNUNET_array_append (rshell_args, cnt, NULL);
943 return rshell_args; 963 return rshell_args;
@@ -957,8 +977,7 @@ gen_rsh_suffix_args (const char * const *append_args)
957 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing 977 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
958 */ 978 */
959static int 979static int
960helper_mst (void *cls, 980helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
961 const struct GNUNET_MessageHeader *message)
962{ 981{
963 struct GNUNET_TESTBED_ControllerProc *cp = cls; 982 struct GNUNET_TESTBED_ControllerProc *cp = cls;
964 const struct GNUNET_TESTBED_HelperReply *msg; 983 const struct GNUNET_TESTBED_HelperReply *msg;
@@ -973,27 +992,28 @@ helper_mst (void *cls,
973 GNUNET_assert (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY == 992 GNUNET_assert (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY ==
974 ntohs (msg->header.type)); 993 ntohs (msg->header.type));
975 config_size = (uLongf) ntohs (msg->config_size); 994 config_size = (uLongf) ntohs (msg->config_size);
976 xconfig_size = 995 xconfig_size = (uLongf) (ntohs (msg->header.size) -
977 (uLongf) (ntohs (msg->header.size) - 996 sizeof (struct GNUNET_TESTBED_HelperReply));
978 sizeof (struct GNUNET_TESTBED_HelperReply));
979 config = GNUNET_malloc (config_size); 997 config = GNUNET_malloc (config_size);
980 GNUNET_assert (Z_OK == 998 GNUNET_assert (Z_OK == uncompress ((Bytef *) config,
981 uncompress ((Bytef *) config, &config_size, 999 &config_size,
982 (const Bytef *) &msg[1], xconfig_size)); 1000 (const Bytef *) &msg[1],
1001 xconfig_size));
983 /* Replace the configuration template present in the host with the 1002 /* Replace the configuration template present in the host with the
984 controller's running configuration */ 1003 controller's running configuration */
985 GNUNET_CONFIGURATION_destroy (cp->host->cfg); 1004 GNUNET_CONFIGURATION_destroy (cp->host->cfg);
986 cp->host->cfg = GNUNET_CONFIGURATION_create (); 1005 cp->host->cfg = GNUNET_CONFIGURATION_create ();
987 GNUNET_assert (GNUNET_CONFIGURATION_deserialize 1006 GNUNET_assert (GNUNET_CONFIGURATION_deserialize (cp->host->cfg,
988 (cp->host->cfg, 1007 config,
989 config, 1008 config_size,
990 config_size, 1009 NULL));
991 NULL));
992 GNUNET_free (config); 1010 GNUNET_free (config);
993 if (NULL == (hostname = GNUNET_TESTBED_host_get_hostname (cp->host))) 1011 if (NULL == (hostname = GNUNET_TESTBED_host_get_hostname (cp->host)))
994 hostname = "localhost"; 1012 hostname = "localhost";
995 /* Change the hostname so that we can connect to it */ 1013 /* Change the hostname so that we can connect to it */
996 GNUNET_CONFIGURATION_set_value_string (cp->host->cfg, "testbed", "hostname", 1014 GNUNET_CONFIGURATION_set_value_string (cp->host->cfg,
1015 "testbed",
1016 "hostname",
997 hostname); 1017 hostname);
998 cp->host->locked = GNUNET_NO; 1018 cp->host->locked = GNUNET_NO;
999 cp->host->controller_started = GNUNET_YES; 1019 cp->host->controller_started = GNUNET_YES;
@@ -1077,24 +1097,27 @@ GNUNET_TESTBED_controller_start (const char *trusted_ip,
1077 struct GNUNET_TESTBED_HelperInit *msg; 1097 struct GNUNET_TESTBED_HelperInit *msg;
1078 const struct GNUNET_CONFIGURATION_Handle *cfg; 1098 const struct GNUNET_CONFIGURATION_Handle *cfg;
1079 const char *hostname; 1099 const char *hostname;
1080 static char *const binary_argv[] = { 1100 static char *const binary_argv[] = {HELPER_TESTBED_BINARY, NULL};
1081 HELPER_TESTBED_BINARY, NULL
1082 };
1083 1101
1084 GNUNET_assert (NULL != host); 1102 GNUNET_assert (NULL != host);
1085 GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (host))); 1103 GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (host)));
1086 hostname = NULL; 1104 hostname = NULL;
1087 API_VIOLATION (GNUNET_NO == host->locked, 1105 API_VIOLATION (
1088 "Host is already locked by a previous call to GNUNET_TESTBED_controller_start()"); 1106 GNUNET_NO == host->locked,
1107 "Host is already locked by a previous call to GNUNET_TESTBED_controller_start()");
1089 host->locked = GNUNET_YES; 1108 host->locked = GNUNET_YES;
1090 API_VIOLATION (GNUNET_NO == host->controller_started, 1109 API_VIOLATION (
1091 "Attempting to start a controller on a host which is already started a controller"); 1110 GNUNET_NO == host->controller_started,
1111 "Attempting to start a controller on a host which is already started a controller");
1092 cp = GNUNET_new (struct GNUNET_TESTBED_ControllerProc); 1112 cp = GNUNET_new (struct GNUNET_TESTBED_ControllerProc);
1093 if (0 == GNUNET_TESTBED_host_get_id_ (host)) 1113 if (0 == GNUNET_TESTBED_host_get_id_ (host))
1094 { 1114 {
1095 cp->helper = 1115 cp->helper = GNUNET_HELPER_start (GNUNET_YES,
1096 GNUNET_HELPER_start (GNUNET_YES, HELPER_TESTBED_BINARY, binary_argv, 1116 HELPER_TESTBED_BINARY,
1097 &helper_mst, &helper_exp_cb, cp); 1117 binary_argv,
1118 &helper_mst,
1119 &helper_exp_cb,
1120 cp);
1098 } 1121 }
1099 else 1122 else
1100 { 1123 {
@@ -1112,16 +1135,18 @@ GNUNET_TESTBED_controller_start (const char *trusted_ip,
1112 GNUNET_asprintf (&port, "%u", host->port); 1135 GNUNET_asprintf (&port, "%u", host->port);
1113 LOG_DEBUG ("Starting remote connection to destination %s\n", hostname); 1136 LOG_DEBUG ("Starting remote connection to destination %s\n", hostname);
1114 if (GNUNET_OK != 1137 if (GNUNET_OK !=
1115 GNUNET_CONFIGURATION_get_value_filename (cfg, "testbed", 1138 GNUNET_CONFIGURATION_get_value_filename (cfg,
1116 "HELPER_BINARY_PATH", 1139 "testbed",
1117 &helper_binary_path_args[0])) 1140 "HELPER_BINARY_PATH",
1141 &helper_binary_path_args[0]))
1118 helper_binary_path_args[0] = 1142 helper_binary_path_args[0] =
1119 GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY); 1143 GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY);
1120 helper_binary_path_args[1] = NULL; 1144 helper_binary_path_args[1] = NULL;
1121 rsh_args = gen_rsh_args (port, hostname, username); 1145 rsh_args = gen_rsh_args (port, hostname, username);
1122 rsh_suffix_args = gen_rsh_suffix_args ((const char **) helper_binary_path_args); 1146 rsh_suffix_args =
1147 gen_rsh_suffix_args ((const char **) helper_binary_path_args);
1123 cp->helper_argv = 1148 cp->helper_argv =
1124 join_argv ((const char **) rsh_args, (const char **) rsh_suffix_args); 1149 join_argv ((const char **) rsh_args, (const char **) rsh_suffix_args);
1125 free_argv (rsh_args); 1150 free_argv (rsh_args);
1126 free_argv (rsh_suffix_args); 1151 free_argv (rsh_suffix_args);
1127 GNUNET_free (port); 1152 GNUNET_free (port);
@@ -1129,14 +1154,18 @@ GNUNET_TESTBED_controller_start (const char *trusted_ip,
1129 for (cnt = 0; NULL != cp->helper_argv[cnt]; cnt++) 1154 for (cnt = 0; NULL != cp->helper_argv[cnt]; cnt++)
1130 { 1155 {
1131 aux = argstr; 1156 aux = argstr;
1132 GNUNET_assert (0 < GNUNET_asprintf (&argstr, "%s %s", aux, cp->helper_argv[cnt])); 1157 GNUNET_assert (
1158 0 < GNUNET_asprintf (&argstr, "%s %s", aux, cp->helper_argv[cnt]));
1133 GNUNET_free (aux); 1159 GNUNET_free (aux);
1134 } 1160 }
1135 LOG_DEBUG ("Helper cmd str: %s\n", argstr); 1161 LOG_DEBUG ("Helper cmd str: %s\n", argstr);
1136 GNUNET_free (argstr); 1162 GNUNET_free (argstr);
1137 cp->helper = 1163 cp->helper = GNUNET_HELPER_start (GNUNET_NO,
1138 GNUNET_HELPER_start (GNUNET_NO, cp->helper_argv[0], cp->helper_argv, &helper_mst, 1164 cp->helper_argv[0],
1139 &helper_exp_cb, cp); 1165 cp->helper_argv,
1166 &helper_mst,
1167 &helper_exp_cb,
1168 cp);
1140 GNUNET_free (helper_binary_path_args[0]); 1169 GNUNET_free (helper_binary_path_args[0]);
1141 } 1170 }
1142 if (NULL == cp->helper) 1171 if (NULL == cp->helper)
@@ -1152,7 +1181,7 @@ GNUNET_TESTBED_controller_start (const char *trusted_ip,
1152 msg = GNUNET_TESTBED_create_helper_init_msg_ (trusted_ip, hostname, cfg); 1181 msg = GNUNET_TESTBED_create_helper_init_msg_ (trusted_ip, hostname, cfg);
1153 cp->msg = &msg->header; 1182 cp->msg = &msg->header;
1154 cp->shandle = 1183 cp->shandle =
1155 GNUNET_HELPER_send (cp->helper, &msg->header, GNUNET_NO, &clear_msg, cp); 1184 GNUNET_HELPER_send (cp->helper, &msg->header, GNUNET_NO, &clear_msg, cp);
1156 if (NULL == cp->shandle) 1185 if (NULL == cp->shandle)
1157 { 1186 {
1158 GNUNET_free (msg); 1187 GNUNET_free (msg);
@@ -1249,14 +1278,13 @@ struct GNUNET_TESTBED_HostHabitableCheckHandle
1249 /** 1278 /**
1250 * Task id for the habitability check task 1279 * Task id for the habitability check task
1251 */ 1280 */
1252 struct GNUNET_SCHEDULER_Task * habitability_check_task; 1281 struct GNUNET_SCHEDULER_Task *habitability_check_task;
1253 1282
1254 /** 1283 /**
1255 * How long we wait before checking the process status. Should grow 1284 * How long we wait before checking the process status. Should grow
1256 * exponentially 1285 * exponentially
1257 */ 1286 */
1258 struct GNUNET_TIME_Relative wait_time; 1287 struct GNUNET_TIME_Relative wait_time;
1259
1260}; 1288};
1261 1289
1262 1290
@@ -1288,7 +1316,7 @@ habitability_check (void *cls)
1288 { 1316 {
1289 h->wait_time = GNUNET_TIME_STD_BACKOFF (h->wait_time); 1317 h->wait_time = GNUNET_TIME_STD_BACKOFF (h->wait_time);
1290 h->habitability_check_task = 1318 h->habitability_check_task =
1291 GNUNET_SCHEDULER_add_delayed (h->wait_time, &habitability_check, h); 1319 GNUNET_SCHEDULER_add_delayed (h->wait_time, &habitability_check, h);
1292 return; 1320 return;
1293 } 1321 }
1294 GNUNET_OS_process_destroy (h->auxp); 1322 GNUNET_OS_process_destroy (h->auxp);
@@ -1320,11 +1348,11 @@ call_cb:
1320 * GNUNET_TESTBED_is_host_habitable_cancel() 1348 * GNUNET_TESTBED_is_host_habitable_cancel()
1321 */ 1349 */
1322struct GNUNET_TESTBED_HostHabitableCheckHandle * 1350struct GNUNET_TESTBED_HostHabitableCheckHandle *
1323GNUNET_TESTBED_is_host_habitable (const struct GNUNET_TESTBED_Host *host, 1351GNUNET_TESTBED_is_host_habitable (
1324 const struct GNUNET_CONFIGURATION_Handle 1352 const struct GNUNET_TESTBED_Host *host,
1325 *config, 1353 const struct GNUNET_CONFIGURATION_Handle *config,
1326 GNUNET_TESTBED_HostHabitableCallback cb, 1354 GNUNET_TESTBED_HostHabitableCallback cb,
1327 void *cb_cls) 1355 void *cb_cls)
1328{ 1356{
1329 struct GNUNET_TESTBED_HostHabitableCheckHandle *h; 1357 struct GNUNET_TESTBED_HostHabitableCheckHandle *h;
1330 char **rsh_args; 1358 char **rsh_args;
@@ -1339,11 +1367,11 @@ GNUNET_TESTBED_is_host_habitable (const struct GNUNET_TESTBED_Host *host,
1339 h->host = host; 1367 h->host = host;
1340 hostname = (NULL == host->hostname) ? "127.0.0.1" : host->hostname; 1368 hostname = (NULL == host->hostname) ? "127.0.0.1" : host->hostname;
1341 if (GNUNET_OK != 1369 if (GNUNET_OK !=
1342 GNUNET_CONFIGURATION_get_value_filename (config, "testbed", 1370 GNUNET_CONFIGURATION_get_value_filename (config,
1343 "HELPER_BINARY_PATH", 1371 "testbed",
1344 &stat_args[1])) 1372 "HELPER_BINARY_PATH",
1345 stat_args[1] = 1373 &stat_args[1]))
1346 GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY); 1374 stat_args[1] = GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY);
1347 GNUNET_asprintf (&port, "%u", host->port); 1375 GNUNET_asprintf (&port, "%u", host->port);
1348 rsh_args = gen_rsh_args (port, hostname, host->username); 1376 rsh_args = gen_rsh_args (port, hostname, host->username);
1349 GNUNET_free (port); 1377 GNUNET_free (port);
@@ -1352,22 +1380,26 @@ GNUNET_TESTBED_is_host_habitable (const struct GNUNET_TESTBED_Host *host,
1352 stat_args[2] = NULL; 1380 stat_args[2] = NULL;
1353 rsh_suffix_args = gen_rsh_suffix_args ((const char **) stat_args); 1381 rsh_suffix_args = gen_rsh_suffix_args ((const char **) stat_args);
1354 GNUNET_free (stat_args[1]); 1382 GNUNET_free (stat_args[1]);
1355 h->helper_argv = join_argv ((const char **) rsh_args, 1383 h->helper_argv =
1356 (const char **) rsh_suffix_args); 1384 join_argv ((const char **) rsh_args, (const char **) rsh_suffix_args);
1357 free_argv (rsh_suffix_args); 1385 free_argv (rsh_suffix_args);
1358 free_argv (rsh_args); 1386 free_argv (rsh_args);
1359 h->auxp = 1387 h->auxp = GNUNET_OS_start_process_vap (GNUNET_NO,
1360 GNUNET_OS_start_process_vap (GNUNET_NO, GNUNET_OS_INHERIT_STD_ERR, NULL, 1388 GNUNET_OS_INHERIT_STD_ERR,
1361 NULL, NULL, h->helper_argv[0], h->helper_argv); 1389 NULL,
1390 NULL,
1391 NULL,
1392 h->helper_argv[0],
1393 h->helper_argv);
1362 if (NULL == h->auxp) 1394 if (NULL == h->auxp)
1363 { 1395 {
1364 GNUNET_break (0); /* Cannot exec SSH? */ 1396 GNUNET_break (0); /* Cannot exec SSH? */
1365 GNUNET_free (h); 1397 GNUNET_free (h);
1366 return NULL; 1398 return NULL;
1367 } 1399 }
1368 h->wait_time = GNUNET_TIME_STD_BACKOFF (h->wait_time); 1400 h->wait_time = GNUNET_TIME_STD_BACKOFF (h->wait_time);
1369 h->habitability_check_task = 1401 h->habitability_check_task =
1370 GNUNET_SCHEDULER_add_delayed (h->wait_time, &habitability_check, h); 1402 GNUNET_SCHEDULER_add_delayed (h->wait_time, &habitability_check, h);
1371 return h; 1403 return h;
1372} 1404}
1373 1405
@@ -1378,9 +1410,8 @@ GNUNET_TESTBED_is_host_habitable (const struct GNUNET_TESTBED_Host *host,
1378 * @param handle the habitability check handle 1410 * @param handle the habitability check handle
1379 */ 1411 */
1380void 1412void
1381GNUNET_TESTBED_is_host_habitable_cancel (struct 1413GNUNET_TESTBED_is_host_habitable_cancel (
1382 GNUNET_TESTBED_HostHabitableCheckHandle 1414 struct GNUNET_TESTBED_HostHabitableCheckHandle *handle)
1383 *handle)
1384{ 1415{
1385 GNUNET_SCHEDULER_cancel (handle->habitability_check_task); 1416 GNUNET_SCHEDULER_cancel (handle->habitability_check_task);
1386 (void) GNUNET_OS_process_kill (handle->auxp, GNUNET_TERM_SIG); 1417 (void) GNUNET_OS_process_kill (handle->auxp, GNUNET_TERM_SIG);
@@ -1427,7 +1458,8 @@ GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
1427 hostname = GNUNET_TESTBED_host_get_hostname (host); 1458 hostname = GNUNET_TESTBED_host_get_hostname (host);
1428 if (GNUNET_YES == GNUNET_TESTBED_is_host_registered_ (host, controller)) 1459 if (GNUNET_YES == GNUNET_TESTBED_is_host_registered_ (host, controller))
1429 { 1460 {
1430 LOG (GNUNET_ERROR_TYPE_WARNING, "Host hostname: %s already registered\n", 1461 LOG (GNUNET_ERROR_TYPE_WARNING,
1462 "Host hostname: %s already registered\n",
1431 (NULL == hostname) ? "localhost" : hostname); 1463 (NULL == hostname) ? "localhost" : hostname);
1432 return NULL; 1464 return NULL;
1433 } 1465 }
@@ -1486,8 +1518,8 @@ GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
1486 * @param handle the registration handle to cancel 1518 * @param handle the registration handle to cancel
1487 */ 1519 */
1488void 1520void
1489GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle 1521GNUNET_TESTBED_cancel_registration (
1490 *handle) 1522 struct GNUNET_TESTBED_HostRegistrationHandle *handle)
1491{ 1523{
1492 if (handle != handle->c->rh) 1524 if (handle != handle->c->rh)
1493 { 1525 {
@@ -1511,8 +1543,8 @@ void
1511GNUNET_TESTBED_host_queue_oc_ (struct GNUNET_TESTBED_Host *h, 1543GNUNET_TESTBED_host_queue_oc_ (struct GNUNET_TESTBED_Host *h,
1512 struct GNUNET_TESTBED_Operation *op) 1544 struct GNUNET_TESTBED_Operation *op)
1513{ 1545{
1514 GNUNET_TESTBED_operation_queue_insert_ 1546 GNUNET_TESTBED_operation_queue_insert_ (h->opq_parallel_overlay_connect_operations,
1515 (h->opq_parallel_overlay_connect_operations, op); 1547 op);
1516} 1548}
1517 1549
1518 1550
diff --git a/src/testing/gnunet-testing.c b/src/testing/gnunet-testing.c
index ec611ba4c..bc402227c 100644
--- a/src/testing/gnunet-testing.c
+++ b/src/testing/gnunet-testing.c
@@ -28,8 +28,7 @@
28#include "gnunet_testing_lib.h" 28#include "gnunet_testing_lib.h"
29 29
30 30
31#define LOG(kind,...) \ 31#define LOG(kind, ...) GNUNET_log_from (kind, "gnunet-testing", __VA_ARGS__)
32 GNUNET_log_from (kind, "gnunet-testing", __VA_ARGS__)
33 32
34 33
35/** 34/**
@@ -84,9 +83,8 @@ static struct GNUNET_SCHEDULER_Task *tid;
84static struct GNUNET_TESTING_Peer *my_peer; 83static struct GNUNET_TESTING_Peer *my_peer;
85 84
86 85
87
88static int 86static int
89create_unique_cfgs (const char * template, const unsigned int no) 87create_unique_cfgs (const char *template, const unsigned int no)
90{ 88{
91 struct GNUNET_TESTING_System *system; 89 struct GNUNET_TESTING_System *system;
92 int fail; 90 int fail;
@@ -95,54 +93,67 @@ create_unique_cfgs (const char * template, const unsigned int no)
95 struct GNUNET_CONFIGURATION_Handle *cfg_new; 93 struct GNUNET_CONFIGURATION_Handle *cfg_new;
96 struct GNUNET_CONFIGURATION_Handle *cfg_tmpl; 94 struct GNUNET_CONFIGURATION_Handle *cfg_tmpl;
97 95
98 if (GNUNET_NO == GNUNET_DISK_file_test(template)) 96 if (GNUNET_NO == GNUNET_DISK_file_test (template))
99 { 97 {
100 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Configuration template `%s': file not found\n", create_cfg_template); 98 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
99 "Configuration template `%s': file not found\n",
100 create_cfg_template);
101 return 1; 101 return 1;
102 } 102 }
103 cfg_tmpl = GNUNET_CONFIGURATION_create(); 103 cfg_tmpl = GNUNET_CONFIGURATION_create ();
104 104
105 /* load template */ 105 /* load template */
106 if ((create_cfg_template != NULL) && (GNUNET_OK != GNUNET_CONFIGURATION_load(cfg_tmpl, create_cfg_template))) 106 if ((create_cfg_template != NULL) &&
107 (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg_tmpl, create_cfg_template)))
107 { 108 {
108 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not load template `%s'\n", create_cfg_template); 109 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
110 "Could not load template `%s'\n",
111 create_cfg_template);
109 GNUNET_CONFIGURATION_destroy (cfg_tmpl); 112 GNUNET_CONFIGURATION_destroy (cfg_tmpl);
110 113
111 return 1; 114 return 1;
112 } 115 }
113 /* load defaults */ 116 /* load defaults */
114 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg_tmpl, NULL)) 117 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg_tmpl, NULL))
115 { 118 {
116 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not load template `%s'\n", create_cfg_template); 119 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
120 "Could not load template `%s'\n",
121 create_cfg_template);
117 GNUNET_CONFIGURATION_destroy (cfg_tmpl); 122 GNUNET_CONFIGURATION_destroy (cfg_tmpl);
118 return 1; 123 return 1;
119 } 124 }
120 125
121 fail = GNUNET_NO; 126 fail = GNUNET_NO;
122 system = GNUNET_TESTING_system_create ("testing", NULL /* controller */, 127 system =
123 NULL, NULL); 128 GNUNET_TESTING_system_create ("testing", NULL /* controller */, NULL, NULL);
124 for (cur = 0; cur < no; cur++) 129 for (cur = 0; cur < no; cur++)
125 { 130 {
126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating configuration no. %u \n", cur); 131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
132 "Creating configuration no. %u \n",
133 cur);
127 if (create_cfg_template != NULL) 134 if (create_cfg_template != NULL)
128 GNUNET_asprintf (&cur_file,"%04u-%s",cur, create_cfg_template); 135 GNUNET_asprintf (&cur_file, "%04u-%s", cur, create_cfg_template);
129 else 136 else
130 GNUNET_asprintf (&cur_file,"%04u%s",cur, ".conf"); 137 GNUNET_asprintf (&cur_file, "%04u%s", cur, ".conf");
131 138
132 cfg_new = GNUNET_CONFIGURATION_dup (cfg_tmpl); 139 cfg_new = GNUNET_CONFIGURATION_dup (cfg_tmpl);
133 if (GNUNET_OK != 140 if (GNUNET_OK != GNUNET_TESTING_configuration_create (system, cfg_new))
134 GNUNET_TESTING_configuration_create (system, cfg_new))
135 { 141 {
136 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not create another configuration\n"); 142 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
143 "Could not create another configuration\n");
137 GNUNET_CONFIGURATION_destroy (cfg_new); 144 GNUNET_CONFIGURATION_destroy (cfg_new);
138 fail = GNUNET_YES; 145 fail = GNUNET_YES;
139 break; 146 break;
140 } 147 }
141 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
142 "Writing configuration no. %u to file `%s' \n", cur, cur_file); 149 "Writing configuration no. %u to file `%s' \n",
143 if (GNUNET_OK != GNUNET_CONFIGURATION_write(cfg_new, cur_file)) 150 cur,
151 cur_file);
152 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg_new, cur_file))
144 { 153 {
145 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to write configuration no. %u \n", cur); 154 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
155 "Failed to write configuration no. %u \n",
156 cur);
146 fail = GNUNET_YES; 157 fail = GNUNET_YES;
147 } 158 }
148 GNUNET_CONFIGURATION_destroy (cfg_new); 159 GNUNET_CONFIGURATION_destroy (cfg_new);
@@ -150,7 +161,7 @@ create_unique_cfgs (const char * template, const unsigned int no)
150 if (GNUNET_YES == fail) 161 if (GNUNET_YES == fail)
151 break; 162 break;
152 } 163 }
153 GNUNET_CONFIGURATION_destroy(cfg_tmpl); 164 GNUNET_CONFIGURATION_destroy (cfg_tmpl);
154 GNUNET_TESTING_system_destroy (system, GNUNET_NO); 165 GNUNET_TESTING_system_destroy (system, GNUNET_NO);
155 if (GNUNET_YES == fail) 166 if (GNUNET_YES == fail)
156 return 1; 167 return 1;
@@ -170,22 +181,27 @@ create_hostkeys (const unsigned int no)
170 pk = GNUNET_TESTING_hostkey_get (system, create_no, &id); 181 pk = GNUNET_TESTING_hostkey_get (system, create_no, &id);
171 if (NULL == pk) 182 if (NULL == pk)
172 { 183 {
173 fprintf (stderr, _("Could not extract hostkey %u (offset too large?)\n"), create_no); 184 fprintf (stderr,
185 _ ("Could not extract hostkey %u (offset too large?)\n"),
186 create_no);
174 GNUNET_TESTING_system_destroy (system, GNUNET_YES); 187 GNUNET_TESTING_system_destroy (system, GNUNET_YES);
175 return 1; 188 return 1;
176 } 189 }
177 (void) GNUNET_DISK_directory_create_for_file (create_hostkey); 190 (void) GNUNET_DISK_directory_create_for_file (create_hostkey);
178 fd = GNUNET_DISK_file_open (create_hostkey, 191 fd =
179 GNUNET_DISK_OPEN_READWRITE | 192 GNUNET_DISK_file_open (create_hostkey,
180 GNUNET_DISK_OPEN_CREATE, 193 GNUNET_DISK_OPEN_READWRITE | GNUNET_DISK_OPEN_CREATE,
181 GNUNET_DISK_PERM_USER_READ | 194 GNUNET_DISK_PERM_USER_READ |
182 GNUNET_DISK_PERM_USER_WRITE); 195 GNUNET_DISK_PERM_USER_WRITE);
183 GNUNET_assert (fd != NULL); 196 GNUNET_assert (fd != NULL);
184 ret = GNUNET_DISK_file_write (fd, pk, 197 ret = GNUNET_DISK_file_write (fd,
185 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)); 198 pk,
199 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey));
186 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); 200 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd));
187 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", 201 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
188 "Wrote hostkey to file: `%s'\n", create_hostkey); 202 "transport-testing",
203 "Wrote hostkey to file: `%s'\n",
204 create_hostkey);
189 GNUNET_free (pk); 205 GNUNET_free (pk);
190 GNUNET_TESTING_system_destroy (system, GNUNET_YES); 206 GNUNET_TESTING_system_destroy (system, GNUNET_YES);
191 return 0; 207 return 0;
@@ -203,8 +219,10 @@ cleanup (void *cls)
203{ 219{
204 if (NULL != tmpfilename) 220 if (NULL != tmpfilename)
205 { 221 {
206 if (0 != UNLINK (tmpfilename)) 222 if (0 != unlink (tmpfilename))
207 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", tmpfilename); 223 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
224 "unlink",
225 tmpfilename);
208 } 226 }
209 if (NULL != tid) 227 if (NULL != tid)
210 { 228 {
@@ -250,12 +268,14 @@ stdin_cb (void *cls)
250 /* ignore whitespace */ 268 /* ignore whitespace */
251 break; 269 break;
252 default: 270 default:
253 fprintf (stderr, _("Unknown command, use 'q' to quit or 'r' to restart peer\n")); 271 fprintf (stderr,
272 _ ("Unknown command, use 'q' to quit or 'r' to restart peer\n"));
254 break; 273 break;
255 } 274 }
256 tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 275 tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
257 fh, 276 fh,
258 &stdin_cb, NULL); 277 &stdin_cb,
278 NULL);
259} 279}
260 280
261 281
@@ -268,7 +288,8 @@ stdin_cb (void *cls)
268 * @param peer handle to the peer 288 * @param peer handle to the peer
269 */ 289 */
270static void 290static void
271testing_main (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, 291testing_main (void *cls,
292 const struct GNUNET_CONFIGURATION_Handle *cfg,
272 struct GNUNET_TESTING_Peer *peer) 293 struct GNUNET_TESTING_Peer *peer)
273{ 294{
274 my_peer = peer; 295 my_peer = peer;
@@ -285,17 +306,17 @@ testing_main (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
285 GNUNET_break (0); 306 GNUNET_break (0);
286 return; 307 return;
287 } 308 }
288 printf("ok\n%s\n", tmpfilename); 309 printf ("ok\n%s\n", tmpfilename);
289 fflush(stdout); 310 fflush (stdout);
290 GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); 311 GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL);
291 fh = GNUNET_DISK_get_handle_from_native (stdin); 312 fh = GNUNET_DISK_get_handle_from_native (stdin);
292 tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 313 tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
293 fh, 314 fh,
294 &stdin_cb, NULL); 315 &stdin_cb,
316 NULL);
295} 317}
296 318
297 319
298
299/** 320/**
300 * Main function that will be running without scheduler. 321 * Main function that will be running without scheduler.
301 * 322 *
@@ -305,13 +326,18 @@ testing_main (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
305 * @param cfg configuration 326 * @param cfg configuration
306 */ 327 */
307static void 328static void
308run_no_scheduler (void *cls, char *const *args, const char *cfgfile, 329run_no_scheduler (void *cls,
309 const struct GNUNET_CONFIGURATION_Handle *cfg) 330 char *const *args,
331 const char *cfgfile,
332 const struct GNUNET_CONFIGURATION_Handle *cfg)
310{ 333{
311 if (NULL != run_service_name) 334 if (NULL != run_service_name)
312 { 335 {
313 ret = GNUNET_TESTING_service_run ("gnunet_service_test", run_service_name, 336 ret = GNUNET_TESTING_service_run ("gnunet_service_test",
314 cfgfile, &testing_main, NULL); 337 run_service_name,
338 cfgfile,
339 &testing_main,
340 NULL);
315 return; 341 return;
316 } 342 }
317 343
@@ -320,7 +346,9 @@ run_no_scheduler (void *cls, char *const *args, const char *cfgfile,
320 if (create_no > 0) 346 if (create_no > 0)
321 { 347 {
322 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 348 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
323 "Creating %u configuration files based on template `%s'\n", create_no, create_cfg_template); 349 "Creating %u configuration files based on template `%s'\n",
350 create_no,
351 create_cfg_template);
324 ret = create_unique_cfgs (create_cfg_template, create_no); 352 ret = create_unique_cfgs (create_cfg_template, create_no);
325 } 353 }
326 else 354 else
@@ -348,37 +376,42 @@ run_no_scheduler (void *cls, char *const *args, const char *cfgfile,
348int 376int
349main (int argc, char *const *argv) 377main (int argc, char *const *argv)
350{ 378{
351 struct GNUNET_GETOPT_CommandLineOption options[] = { 379 struct GNUNET_GETOPT_CommandLineOption options[] =
352 GNUNET_GETOPT_option_flag ('C', 380 {GNUNET_GETOPT_option_flag ('C',
353 "cfg", 381 "cfg",
354 gettext_noop ("create unique configuration files"), 382 gettext_noop (
355 &create_cfg), 383 "create unique configuration files"),
356 GNUNET_GETOPT_option_string ('k', 384 &create_cfg),
357 "key", 385 GNUNET_GETOPT_option_string (
358 "FILENAME", 386 'k',
359 gettext_noop ("extract hostkey file from pre-computed hostkey list"), 387 "key",
360 &create_hostkey), 388 "FILENAME",
361 389 gettext_noop ("extract hostkey file from pre-computed hostkey list"),
362 GNUNET_GETOPT_option_uint ('n', 390 &create_hostkey),
363 "number", 391
364 "NUMBER", 392 GNUNET_GETOPT_option_uint (
365 gettext_noop ("number of unique configuration files to create, or number of the hostkey to extract"), 393 'n',
366 &create_no), 394 "number",
367 395 "NUMBER",
368 396 gettext_noop (
369 GNUNET_GETOPT_option_string ('t', 397 "number of unique configuration files to create, or number of the hostkey to extract"),
370 "template", 398 &create_no),
371 "FILENAME", 399
372 gettext_noop ("configuration template"), 400
373 &create_cfg_template), 401 GNUNET_GETOPT_option_string ('t',
374 402 "template",
375 GNUNET_GETOPT_option_string ('r', 403 "FILENAME",
376 "run", 404 gettext_noop ("configuration template"),
377 "SERVICE", 405 &create_cfg_template),
378 gettext_noop ("run the given service, wait on stdin for 'r' (restart) or 'q' (quit)"), 406
379 &run_service_name), 407 GNUNET_GETOPT_option_string (
380 GNUNET_GETOPT_OPTION_END 408 'r',
381 }; 409 "run",
410 "SERVICE",
411 gettext_noop (
412 "run the given service, wait on stdin for 'r' (restart) or 'q' (quit)"),
413 &run_service_name),
414 GNUNET_GETOPT_OPTION_END};
382 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 415 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
383 return 2; 416 return 2;
384 417
@@ -386,11 +419,20 @@ main (int argc, char *const *argv)
386 * GNUNET_TESTING_service_run, which starts the scheduler on its own. 419 * GNUNET_TESTING_service_run, which starts the scheduler on its own.
387 * Furthermore, the other functionality currently does not require the scheduler, too, 420 * Furthermore, the other functionality currently does not require the scheduler, too,
388 * but beware when extending gnunet-testing. */ 421 * but beware when extending gnunet-testing. */
389 ret = (GNUNET_OK == 422 ret =
390 GNUNET_PROGRAM_run2 (argc, argv, "gnunet-testing", 423 (GNUNET_OK ==
391 gettext_noop ("Command line tool to access the testing library"), options, &run_no_scheduler, 424 GNUNET_PROGRAM_run2 (argc,
392 NULL, GNUNET_YES)) ? ret : 1; 425 argv,
393 GNUNET_free ((void*) argv); 426 "gnunet-testing",
427 gettext_noop (
428 "Command line tool to access the testing library"),
429 options,
430 &run_no_scheduler,
431 NULL,
432 GNUNET_YES))
433 ? ret
434 : 1;
435 GNUNET_free ((void *) argv);
394 return ret; 436 return ret;
395} 437}
396 438
diff --git a/src/testing/list-keys.c b/src/testing/list-keys.c
index 9210486d3..39a48d071 100644
--- a/src/testing/list-keys.c
+++ b/src/testing/list-keys.c
@@ -15,7 +15,9 @@ static int result;
15 * @param cfg the configuration file handle 15 * @param cfg the configuration file handle
16 */ 16 */
17static void 17static void
18run (void *cls, char *const *args, const char *cfgfile, 18run (void *cls,
19 char *const *args,
20 const char *cfgfile,
19 const struct GNUNET_CONFIGURATION_Handle *config) 21 const struct GNUNET_CONFIGURATION_Handle *config)
20{ 22{
21 char *idfile; 23 char *idfile;
@@ -30,7 +32,7 @@ run (void *cls, char *const *args, const char *cfgfile,
30 32
31 if ((NULL == args) || (NULL == args[0])) 33 if ((NULL == args) || (NULL == args[0]))
32 { 34 {
33 FPRINTF (stderr, "Need the hostkey file\n"); 35 fprintf (stderr, "Need the hostkey file\n");
34 return; 36 return;
35 } 37 }
36 idfile = args[0]; 38 idfile = args[0];
@@ -42,11 +44,11 @@ run (void *cls, char *const *args, const char *cfgfile,
42 } 44 }
43 if (0 != (fsize % GNUNET_TESTING_HOSTKEYFILESIZE)) 45 if (0 != (fsize % GNUNET_TESTING_HOSTKEYFILESIZE))
44 { 46 {
45 FPRINTF (stderr, 47 fprintf (stderr, _ ("Incorrect hostkey file format: %s\n"), idfile);
46 _("Incorrect hostkey file format: %s\n"), idfile);
47 return; 48 return;
48 } 49 }
49 f = GNUNET_DISK_file_open (idfile, GNUNET_DISK_OPEN_READ, 50 f = GNUNET_DISK_file_open (idfile,
51 GNUNET_DISK_OPEN_READ,
50 GNUNET_DISK_PERM_NONE); 52 GNUNET_DISK_PERM_NONE);
51 if (NULL == f) 53 if (NULL == f)
52 { 54 {
@@ -65,14 +67,14 @@ run (void *cls, char *const *args, const char *cfgfile,
65 { 67 {
66 if (nskip + cnt >= nmax) 68 if (nskip + cnt >= nmax)
67 { 69 {
68 PRINTF ("Max keys %u reached\n", nmax); 70 printf ("Max keys %u reached\n", nmax);
69 break; 71 break;
70 } 72 }
71 GNUNET_memcpy (&pkey, 73 GNUNET_memcpy (&pkey,
72 data + (cnt * GNUNET_TESTING_HOSTKEYFILESIZE), 74 data + (cnt * GNUNET_TESTING_HOSTKEYFILESIZE),
73 GNUNET_TESTING_HOSTKEYFILESIZE); 75 GNUNET_TESTING_HOSTKEYFILESIZE);
74 GNUNET_CRYPTO_eddsa_key_get_public (&pkey, &id.public_key); 76 GNUNET_CRYPTO_eddsa_key_get_public (&pkey, &id.public_key);
75 PRINTF ("Key %u: %s\n", cnt, GNUNET_i2s_full (&id)); 77 printf ("Key %u: %s\n", cnt, GNUNET_i2s_full (&id));
76 } 78 }
77 result = GNUNET_OK; 79 result = GNUNET_OK;
78 GNUNET_DISK_file_unmap (map); 80 GNUNET_DISK_file_unmap (map);
@@ -80,23 +82,28 @@ run (void *cls, char *const *args, const char *cfgfile,
80} 82}
81 83
82 84
83int main (int argc, char *argv[]) 85int
86main (int argc, char *argv[])
84{ 87{
85 struct GNUNET_GETOPT_CommandLineOption option[] = { 88 struct GNUNET_GETOPT_CommandLineOption option[] =
86 GNUNET_GETOPT_option_uint ('n', 89 {GNUNET_GETOPT_option_uint ('n',
87 "num-keys", 90 "num-keys",
88 "COUNT", 91 "COUNT",
89 gettext_noop ("list COUNT number of keys"), 92 gettext_noop ("list COUNT number of keys"),
90 &nkeys), 93 &nkeys),
91 GNUNET_GETOPT_OPTION_END 94 GNUNET_GETOPT_OPTION_END};
92 };
93 int ret; 95 int ret;
94 96
95 result = GNUNET_SYSERR; 97 result = GNUNET_SYSERR;
96 nkeys = 10; 98 nkeys = 10;
97 ret = 99 ret =
98 GNUNET_PROGRAM_run (argc, argv, "list-keys", "Lists the peer IDs corresponding to the given keys file\n", 100 GNUNET_PROGRAM_run (argc,
99 option, &run, NULL); 101 argv,
102 "list-keys",
103 "Lists the peer IDs corresponding to the given keys file\n",
104 option,
105 &run,
106 NULL);
100 if (GNUNET_OK != ret) 107 if (GNUNET_OK != ret)
101 return 1; 108 return 1;
102 if (GNUNET_SYSERR == result) 109 if (GNUNET_SYSERR == result)
diff --git a/src/testing/testing.c b/src/testing/testing.c
index 7dbd97294..c5c240b37 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -34,8 +34,7 @@
34#include "gnunet_arm_service.h" 34#include "gnunet_arm_service.h"
35#include "gnunet_testing_lib.h" 35#include "gnunet_testing_lib.h"
36 36
37#define LOG(kind,...) \ 37#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
38 GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
39 38
40 39
41/** 40/**
@@ -269,7 +268,8 @@ hostkeys_load (struct GNUNET_TESTING_System *system)
269 if (GNUNET_YES != GNUNET_DISK_file_test (filename)) 268 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
270 { 269 {
271 LOG (GNUNET_ERROR_TYPE_ERROR, 270 LOG (GNUNET_ERROR_TYPE_ERROR,
272 _("Hostkeys file not found: %s\n"), filename); 271 _ ("Hostkeys file not found: %s\n"),
272 filename);
273 GNUNET_free (filename); 273 GNUNET_free (filename);
274 return GNUNET_SYSERR; 274 return GNUNET_SYSERR;
275 } 275 }
@@ -280,17 +280,19 @@ hostkeys_load (struct GNUNET_TESTING_System *system)
280 if (0 == fs) 280 if (0 == fs)
281 { 281 {
282 GNUNET_free (filename); 282 GNUNET_free (filename);
283 return GNUNET_SYSERR; /* File is empty */ 283 return GNUNET_SYSERR; /* File is empty */
284 } 284 }
285 if (0 != (fs % GNUNET_TESTING_HOSTKEYFILESIZE)) 285 if (0 != (fs % GNUNET_TESTING_HOSTKEYFILESIZE))
286 { 286 {
287 LOG (GNUNET_ERROR_TYPE_ERROR, 287 LOG (GNUNET_ERROR_TYPE_ERROR,
288 _("Incorrect hostkey file format: %s\n"), filename); 288 _ ("Incorrect hostkey file format: %s\n"),
289 filename);
289 GNUNET_free (filename); 290 GNUNET_free (filename);
290 return GNUNET_SYSERR; 291 return GNUNET_SYSERR;
291 } 292 }
292 fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, 293 fd = GNUNET_DISK_file_open (filename,
293 GNUNET_DISK_PERM_NONE); 294 GNUNET_DISK_OPEN_READ,
295 GNUNET_DISK_PERM_NONE);
294 if (NULL == fd) 296 if (NULL == fd)
295 { 297 {
296 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename); 298 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename);
@@ -298,10 +300,8 @@ hostkeys_load (struct GNUNET_TESTING_System *system)
298 return GNUNET_SYSERR; 300 return GNUNET_SYSERR;
299 } 301 }
300 GNUNET_free (filename); 302 GNUNET_free (filename);
301 system->hostkeys_data = GNUNET_DISK_file_map (fd, 303 system->hostkeys_data =
302 &system->map, 304 GNUNET_DISK_file_map (fd, &system->map, GNUNET_DISK_MAP_TYPE_READ, fs);
303 GNUNET_DISK_MAP_TYPE_READ,
304 fs);
305 GNUNET_DISK_file_close (fd); 305 GNUNET_DISK_file_close (fd);
306 if (NULL == system->hostkeys_data) 306 if (NULL == system->hostkeys_data)
307 return GNUNET_SYSERR; 307 return GNUNET_SYSERR;
@@ -336,8 +336,10 @@ hostkeys_unload (struct GNUNET_TESTING_System *system)
336 * @param value value of the option 336 * @param value value of the option
337 */ 337 */
338static void 338static void
339cfg_copy_iterator (void *cls, const char *section, 339cfg_copy_iterator (void *cls,
340 const char *option, const char *value) 340 const char *section,
341 const char *option,
342 const char *value)
341{ 343{
342 struct GNUNET_CONFIGURATION_Handle *cfg2 = cls; 344 struct GNUNET_CONFIGURATION_Handle *cfg2 = cls;
343 345
@@ -367,14 +369,13 @@ cfg_copy_iterator (void *cls, const char *section,
367 * @return handle to this system, NULL on error 369 * @return handle to this system, NULL on error
368 */ 370 */
369struct GNUNET_TESTING_System * 371struct GNUNET_TESTING_System *
370GNUNET_TESTING_system_create_with_portrange (const char *testdir, 372GNUNET_TESTING_system_create_with_portrange (
371 const char *trusted_ip, 373 const char *testdir,
372 const char *hostname, 374 const char *trusted_ip,
373 const struct 375 const char *hostname,
374 GNUNET_TESTING_SharedService * 376 const struct GNUNET_TESTING_SharedService *shared_services,
375 shared_services, 377 uint16_t lowport,
376 uint16_t lowport, 378 uint16_t highport)
377 uint16_t highport)
378{ 379{
379 struct GNUNET_TESTING_System *system; 380 struct GNUNET_TESTING_System *system;
380 struct GNUNET_TESTING_SharedService tss; 381 struct GNUNET_TESTING_SharedService tss;
@@ -411,14 +412,21 @@ GNUNET_TESTING_system_create_with_portrange (const char *testdir,
411 ss = GNUNET_new (struct SharedService); 412 ss = GNUNET_new (struct SharedService);
412 ss->sname = GNUNET_strdup (tss.service); 413 ss->sname = GNUNET_strdup (tss.service);
413 ss->cfg = GNUNET_CONFIGURATION_create (); 414 ss->cfg = GNUNET_CONFIGURATION_create ();
414 GNUNET_CONFIGURATION_iterate_section_values (tss.cfg, ss->sname, 415 GNUNET_CONFIGURATION_iterate_section_values (tss.cfg,
415 &cfg_copy_iterator, ss->cfg); 416 ss->sname,
416 GNUNET_CONFIGURATION_iterate_section_values (tss.cfg, "TESTING", 417 &cfg_copy_iterator,
417 &cfg_copy_iterator, ss->cfg); 418 ss->cfg);
418 GNUNET_CONFIGURATION_iterate_section_values (tss.cfg, "PATHS", 419 GNUNET_CONFIGURATION_iterate_section_values (tss.cfg,
419 &cfg_copy_iterator, ss->cfg); 420 "TESTING",
421 &cfg_copy_iterator,
422 ss->cfg);
423 GNUNET_CONFIGURATION_iterate_section_values (tss.cfg,
424 "PATHS",
425 &cfg_copy_iterator,
426 ss->cfg);
420 ss->share = tss.share; 427 ss->share = tss.share;
421 GNUNET_array_append (system->shared_services, system->n_shared_services, 428 GNUNET_array_append (system->shared_services,
429 system->n_shared_services,
422 ss); 430 ss);
423 } 431 }
424 return system; 432 return system;
@@ -446,18 +454,18 @@ GNUNET_TESTING_system_create_with_portrange (const char *testdir,
446 * @return handle to this system, NULL on error 454 * @return handle to this system, NULL on error
447 */ 455 */
448struct GNUNET_TESTING_System * 456struct GNUNET_TESTING_System *
449GNUNET_TESTING_system_create (const char *testdir, 457GNUNET_TESTING_system_create (
450 const char *trusted_ip, 458 const char *testdir,
451 const char *hostname, 459 const char *trusted_ip,
452 const struct GNUNET_TESTING_SharedService * 460 const char *hostname,
453 shared_services) 461 const struct GNUNET_TESTING_SharedService *shared_services)
454{ 462{
455 return GNUNET_TESTING_system_create_with_portrange (testdir, 463 return GNUNET_TESTING_system_create_with_portrange (testdir,
456 trusted_ip, 464 trusted_ip,
457 hostname, 465 hostname,
458 shared_services, 466 shared_services,
459 LOW_PORT, 467 LOW_PORT,
460 HIGH_PORT); 468 HIGH_PORT);
461} 469}
462 470
463 471
@@ -490,7 +498,9 @@ start_shared_service_instance (struct SharedServiceInstance *i)
490 GNUNET_free (binary); 498 GNUNET_free (binary);
491 i->proc = GNUNET_OS_start_process (PIPE_CONTROL, 499 i->proc = GNUNET_OS_start_process (PIPE_CONTROL,
492 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 500 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
493 NULL, NULL, NULL, 501 NULL,
502 NULL,
503 NULL,
494 libexec_binary, 504 libexec_binary,
495 libexec_binary, 505 libexec_binary,
496 "-c", 506 "-c",
@@ -509,7 +519,8 @@ stop_shared_service_instance (struct SharedServiceInstance *i)
509 GNUNET_break (0 == i->n_refs); 519 GNUNET_break (0 == i->n_refs);
510 if (0 != GNUNET_OS_process_kill (i->proc, GNUNET_TERM_SIG)) 520 if (0 != GNUNET_OS_process_kill (i->proc, GNUNET_TERM_SIG))
511 LOG (GNUNET_ERROR_TYPE_WARNING, 521 LOG (GNUNET_ERROR_TYPE_WARNING,
512 "Killing shared service instance (%s) failed\n", i->ss->sname); 522 "Killing shared service instance (%s) failed\n",
523 i->ss->sname);
513 (void) GNUNET_OS_process_wait (i->proc); 524 (void) GNUNET_OS_process_wait (i->proc);
514 GNUNET_OS_process_destroy (i->proc); 525 GNUNET_OS_process_destroy (i->proc);
515 i->proc = NULL; 526 i->proc = NULL;
@@ -525,7 +536,7 @@ stop_shared_service_instance (struct SharedServiceInstance *i)
525 */ 536 */
526void 537void
527GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system, 538GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system,
528 int remove_paths) 539 int remove_paths)
529{ 540{
530 struct SharedService *ss; 541 struct SharedService *ss;
531 struct SharedServiceInstance *i; 542 struct SharedServiceInstance *i;
@@ -589,19 +600,20 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system)
589 On system with either IPv4 or IPv6. A port is considered open if it's 600 On system with either IPv4 or IPv6. A port is considered open if it's
590 open in the respective address family 601 open in the respective address family
591 */ 602 */
592 hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */ 603 hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */
593 hint.ai_socktype = 0; 604 hint.ai_socktype = 0;
594 hint.ai_protocol = 0; 605 hint.ai_protocol = 0;
595 hint.ai_addrlen = 0; 606 hint.ai_addrlen = 0;
596 hint.ai_addr = NULL; 607 hint.ai_addr = NULL;
597 hint.ai_canonname = NULL; 608 hint.ai_canonname = NULL;
598 hint.ai_next = NULL; 609 hint.ai_next = NULL;
599 hint.ai_flags = AI_PASSIVE | AI_NUMERICSERV; /* Wild card address */ 610 hint.ai_flags = AI_PASSIVE | AI_NUMERICSERV; /* Wild card address */
600 port_buckets = system->reserved_ports; 611 port_buckets = system->reserved_ports;
601 for (index = (system->lowport / 32) + 1; index < (system->highport / 32); index++) 612 for (index = (system->lowport / 32) + 1; index < (system->highport / 32);
613 index++)
602 { 614 {
603 xor_image = (UINT32_MAX ^ port_buckets[index]); 615 xor_image = (UINT32_MAX ^ port_buckets[index]);
604 if (0 == xor_image) /* Ports in the bucket are full */ 616 if (0 == xor_image) /* Ports in the bucket are full */
605 continue; 617 continue;
606 pos = system->lowport % 32; 618 pos = system->lowport % 32;
607 while (pos < 32) 619 while (pos < 32)
@@ -613,7 +625,7 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system)
613 } 625 }
614 open_port = (index * 32) + pos; 626 open_port = (index * 32) + pos;
615 if (open_port >= system->highport) 627 if (open_port >= system->highport)
616 return 0; 628 return 0;
617 GNUNET_asprintf (&open_port_str, "%u", (unsigned int) open_port); 629 GNUNET_asprintf (&open_port_str, "%u", (unsigned int) open_port);
618 ret = NULL; 630 ret = NULL;
619 GNUNET_assert (0 == getaddrinfo (NULL, open_port_str, &hint, &ret)); 631 GNUNET_assert (0 == getaddrinfo (NULL, open_port_str, &hint, &ret));
@@ -624,18 +636,16 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system)
624 socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_STREAM, 0); 636 socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_STREAM, 0);
625 if (NULL == socket) 637 if (NULL == socket)
626 continue; 638 continue;
627 bind_status = GNUNET_NETWORK_socket_bind (socket, 639 bind_status =
628 ai->ai_addr, 640 GNUNET_NETWORK_socket_bind (socket, ai->ai_addr, ai->ai_addrlen);
629 ai->ai_addrlen);
630 GNUNET_NETWORK_socket_close (socket); 641 GNUNET_NETWORK_socket_close (socket);
631 if (GNUNET_OK != bind_status) 642 if (GNUNET_OK != bind_status)
632 break; 643 break;
633 socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_DGRAM, 0); 644 socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_DGRAM, 0);
634 if (NULL == socket) 645 if (NULL == socket)
635 continue; 646 continue;
636 bind_status = GNUNET_NETWORK_socket_bind (socket, 647 bind_status =
637 ai->ai_addr, 648 GNUNET_NETWORK_socket_bind (socket, ai->ai_addr, ai->ai_addrlen);
638 ai->ai_addrlen);
639 GNUNET_NETWORK_socket_close (socket); 649 GNUNET_NETWORK_socket_close (socket);
640 if (GNUNET_OK != bind_status) 650 if (GNUNET_OK != bind_status)
641 break; 651 break;
@@ -645,8 +655,9 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system)
645 if (GNUNET_OK == bind_status) 655 if (GNUNET_OK == bind_status)
646 { 656 {
647 LOG (GNUNET_ERROR_TYPE_DEBUG, 657 LOG (GNUNET_ERROR_TYPE_DEBUG,
648 "Found a free port %u\n", (unsigned int) open_port); 658 "Found a free port %u\n",
649 return open_port; 659 (unsigned int) open_port);
660 return open_port;
650 } 661 }
651 pos++; 662 pos++;
652 } 663 }
@@ -664,7 +675,7 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system)
664 */ 675 */
665void 676void
666GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system, 677GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system,
667 uint16_t port) 678 uint16_t port)
668{ 679{
669 uint32_t *port_buckets; 680 uint32_t *port_buckets;
670 uint16_t bucket; 681 uint16_t bucket;
@@ -676,7 +687,7 @@ GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system,
676 LOG (GNUNET_ERROR_TYPE_DEBUG, "Releasing port %u\n", port); 687 LOG (GNUNET_ERROR_TYPE_DEBUG, "Releasing port %u\n", port);
677 if (0 == (port_buckets[bucket] & (1U << pos))) 688 if (0 == (port_buckets[bucket] & (1U << pos)))
678 { 689 {
679 GNUNET_break(0); /* Port was not reserved by us using reserve_port() */ 690 GNUNET_break (0); /* Port was not reserved by us using reserve_port() */
680 return; 691 return;
681 } 692 }
682 port_buckets[bucket] &= ~(1U << pos); 693 port_buckets[bucket] &= ~(1U << pos);
@@ -702,8 +713,8 @@ GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system,
702 */ 713 */
703struct GNUNET_CRYPTO_EddsaPrivateKey * 714struct GNUNET_CRYPTO_EddsaPrivateKey *
704GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system, 715GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system,
705 uint32_t key_number, 716 uint32_t key_number,
706 struct GNUNET_PeerIdentity *id) 717 struct GNUNET_PeerIdentity *id)
707{ 718{
708 struct GNUNET_CRYPTO_EddsaPrivateKey *private_key; 719 struct GNUNET_CRYPTO_EddsaPrivateKey *private_key;
709 720
@@ -712,17 +723,16 @@ GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system,
712 if (key_number >= system->total_hostkeys) 723 if (key_number >= system->total_hostkeys)
713 { 724 {
714 LOG (GNUNET_ERROR_TYPE_ERROR, 725 LOG (GNUNET_ERROR_TYPE_ERROR,
715 _("Key number %u does not exist\n"), 726 _ ("Key number %u does not exist\n"),
716 key_number); 727 key_number);
717 return NULL; 728 return NULL;
718 } 729 }
719 private_key = GNUNET_new (struct GNUNET_CRYPTO_EddsaPrivateKey); 730 private_key = GNUNET_new (struct GNUNET_CRYPTO_EddsaPrivateKey);
720 GNUNET_memcpy (private_key, 731 GNUNET_memcpy (private_key,
721 system->hostkeys_data + 732 system->hostkeys_data +
722 (key_number * GNUNET_TESTING_HOSTKEYFILESIZE), 733 (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
723 GNUNET_TESTING_HOSTKEYFILESIZE); 734 GNUNET_TESTING_HOSTKEYFILESIZE);
724 GNUNET_CRYPTO_eddsa_key_get_public (private_key, 735 GNUNET_CRYPTO_eddsa_key_get_public (private_key, &id->public_key);
725 &id->public_key);
726 return private_key; 736 return private_key;
727} 737}
728 738
@@ -794,18 +804,17 @@ update_config (void *cls,
794 804
795 if (GNUNET_OK != uc->status) 805 if (GNUNET_OK != uc->status)
796 return; 806 return;
797 if (! ((0 == strcmp (option, "PORT")) 807 if (! ((0 == strcmp (option, "PORT")) || (0 == strcmp (option, "UNIXPATH")) ||
798 || (0 == strcmp (option, "UNIXPATH")) 808 (0 == strcmp (option, "HOSTNAME"))))
799 || (0 == strcmp (option, "HOSTNAME"))))
800 return; 809 return;
801 GNUNET_asprintf (&single_variable, "single_%s_per_host", section); 810 GNUNET_asprintf (&single_variable, "single_%s_per_host", section);
802 GNUNET_asprintf (&per_host_variable, "num_%s_per_host", section); 811 GNUNET_asprintf (&per_host_variable, "num_%s_per_host", section);
803 if ((0 == strcmp (option, "PORT")) && (1 == SSCANF (value, "%u", &ival))) 812 if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival)))
804 { 813 {
805 if ((ival != 0) && 814 if ((ival != 0) &&
806 (GNUNET_YES != 815 (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno (uc->cfg,
807 GNUNET_CONFIGURATION_get_value_yesno (uc->cfg, "testing", 816 "testing",
808 single_variable))) 817 single_variable)))
809 { 818 {
810 new_port = GNUNET_TESTING_reserve_port (uc->system); 819 new_port = GNUNET_TESTING_reserve_port (uc->system);
811 if (0 == new_port) 820 if (0 == new_port)
@@ -821,37 +830,41 @@ update_config (void *cls,
821 } 830 }
822 else if ((ival != 0) && 831 else if ((ival != 0) &&
823 (GNUNET_YES == 832 (GNUNET_YES ==
824 GNUNET_CONFIGURATION_get_value_yesno (uc->cfg, "testing", 833 GNUNET_CONFIGURATION_get_value_yesno (uc->cfg,
834 "testing",
825 single_variable)) && 835 single_variable)) &&
826 GNUNET_CONFIGURATION_get_value_number (uc->cfg, "testing", 836 GNUNET_CONFIGURATION_get_value_number (uc->cfg,
837 "testing",
827 per_host_variable, 838 per_host_variable,
828 &num_per_host)) 839 &num_per_host))
829 { 840 {
830 /* GNUNET_snprintf (cval, sizeof (cval), "%u", */ 841 /* GNUNET_snprintf (cval, sizeof (cval), "%u", */
831 /* ival + ctx->fdnum % num_per_host); */ 842 /* ival + ctx->fdnum % num_per_host); */
832 /* value = cval; */ 843 /* value = cval; */
833 GNUNET_break (0); /* FIXME */ 844 GNUNET_break (0); /* FIXME */
834 } 845 }
835 } 846 }
836 if (0 == strcmp (option, "UNIXPATH")) 847 if (0 == strcmp (option, "UNIXPATH"))
837 { 848 {
838 if (GNUNET_YES != 849 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno (uc->cfg,
839 GNUNET_CONFIGURATION_get_value_yesno (uc->cfg, "testing", 850 "testing",
840 single_variable)) 851 single_variable))
841 { 852 {
842 GNUNET_snprintf (uval, 853 GNUNET_snprintf (uval,
843 sizeof (uval), 854 sizeof (uval),
844 "%s/%s.sock", 855 "%s/%s.sock",
845 uc->gnunet_home, section); 856 uc->gnunet_home,
857 section);
846 value = uval; 858 value = uval;
847 } 859 }
848 else if ((GNUNET_YES == 860 else if ((GNUNET_YES ==
849 GNUNET_CONFIGURATION_get_value_number (uc->cfg, "testing", 861 GNUNET_CONFIGURATION_get_value_number (uc->cfg,
862 "testing",
850 per_host_variable, 863 per_host_variable,
851 &num_per_host)) && 864 &num_per_host)) &&
852 (num_per_host > 0)) 865 (num_per_host > 0))
853 { 866 {
854 GNUNET_break(0); /* FIXME */ 867 GNUNET_break (0); /* FIXME */
855 } 868 }
856 } 869 }
857 if (0 == strcmp (option, "HOSTNAME")) 870 if (0 == strcmp (option, "HOSTNAME"))
@@ -872,8 +885,7 @@ update_config (void *cls,
872 * @param section name of the section 885 * @param section name of the section
873 */ 886 */
874static void 887static void
875update_config_sections (void *cls, 888update_config_sections (void *cls, const char *section)
876 const char *section)
877{ 889{
878 struct UpdateContext *uc = cls; 890 struct UpdateContext *uc = cls;
879 char **ikeys; 891 char **ikeys;
@@ -889,13 +901,14 @@ update_config_sections (void *cls,
889 val = NULL; 901 val = NULL;
890 /* Ignore certain options from sections. See 902 /* Ignore certain options from sections. See
891 https://gnunet.org/bugs/view.php?id=2476 */ 903 https://gnunet.org/bugs/view.php?id=2476 */
892 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (uc->cfg, section, 904 if (GNUNET_YES ==
893 "TESTING_IGNORE_KEYS")) 905 GNUNET_CONFIGURATION_have_value (uc->cfg, section, "TESTING_IGNORE_KEYS"))
894 { 906 {
895 GNUNET_assert 907 GNUNET_assert (GNUNET_YES ==
896 (GNUNET_YES == 908 GNUNET_CONFIGURATION_get_value_string (uc->cfg,
897 GNUNET_CONFIGURATION_get_value_string (uc->cfg, section, 909 section,
898 "TESTING_IGNORE_KEYS", &val)); 910 "TESTING_IGNORE_KEYS",
911 &val));
899 ptr = val; 912 ptr = val;
900 for (ikeys_cnt = 0; NULL != (ptr = strstr (ptr, ";")); ikeys_cnt++) 913 for (ikeys_cnt = 0; NULL != (ptr = strstr (ptr, ";")); ikeys_cnt++)
901 ptr++; 914 ptr++;
@@ -920,18 +933,22 @@ update_config_sections (void *cls,
920 for (key = 0; key < ikeys_cnt; key++) 933 for (key = 0; key < ikeys_cnt; key++)
921 { 934 {
922 if (NULL != strstr (ikeys[key], "ADVERTISED_PORT")) 935 if (NULL != strstr (ikeys[key], "ADVERTISED_PORT"))
923 break; 936 break;
924 } 937 }
925 if ((key == ikeys_cnt) && 938 if ((key == ikeys_cnt) &&
926 (GNUNET_YES == GNUNET_CONFIGURATION_have_value (uc->cfg, section, 939 (GNUNET_YES ==
927 "ADVERTISED_PORT"))) 940 GNUNET_CONFIGURATION_have_value (uc->cfg, section, "ADVERTISED_PORT")))
928 { 941 {
929 if (GNUNET_OK == 942 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (uc->cfg,
930 GNUNET_CONFIGURATION_get_value_string (uc->cfg, section, "PORT", &ptr)) 943 section,
944 "PORT",
945 &ptr))
931 { 946 {
932 GNUNET_CONFIGURATION_set_value_string (uc->cfg, section, 947 GNUNET_CONFIGURATION_set_value_string (uc->cfg,
933 "ADVERTISED_PORT", ptr); 948 section,
934 GNUNET_free (ptr); 949 "ADVERTISED_PORT",
950 ptr);
951 GNUNET_free (ptr);
935 } 952 }
936 } 953 }
937 for (key = 0; key < ikeys_cnt; key++) 954 for (key = 0; key < ikeys_cnt; key++)
@@ -950,19 +967,24 @@ update_config_sections (void *cls,
950 if ((NULL != uc->system->trusted_ip) && 967 if ((NULL != uc->system->trusted_ip) &&
951 (NULL != strstr (uc->system->trusted_ip, ":"))) /* IPv6 in use */ 968 (NULL != strstr (uc->system->trusted_ip, ":"))) /* IPv6 in use */
952 ACCEPT_FROM_key = "ACCEPT_FROM6"; 969 ACCEPT_FROM_key = "ACCEPT_FROM6";
953 if (GNUNET_OK != 970 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (uc->cfg,
954 GNUNET_CONFIGURATION_get_value_string (uc->cfg, section, ACCEPT_FROM_key, 971 section,
955 &orig_allowed_hosts)) 972 ACCEPT_FROM_key,
973 &orig_allowed_hosts))
956 { 974 {
957 orig_allowed_hosts = GNUNET_strdup ("127.0.0.1;"); 975 orig_allowed_hosts = GNUNET_strdup ("127.0.0.1;");
958 } 976 }
959 if (NULL == uc->system->trusted_ip) 977 if (NULL == uc->system->trusted_ip)
960 allowed_hosts = GNUNET_strdup (orig_allowed_hosts); 978 allowed_hosts = GNUNET_strdup (orig_allowed_hosts);
961 else 979 else
962 GNUNET_asprintf (&allowed_hosts, "%s%s;", orig_allowed_hosts, 980 GNUNET_asprintf (&allowed_hosts,
981 "%s%s;",
982 orig_allowed_hosts,
963 uc->system->trusted_ip); 983 uc->system->trusted_ip);
964 GNUNET_free (orig_allowed_hosts); 984 GNUNET_free (orig_allowed_hosts);
965 GNUNET_CONFIGURATION_set_value_string (uc->cfg, section, ACCEPT_FROM_key, 985 GNUNET_CONFIGURATION_set_value_string (uc->cfg,
986 section,
987 ACCEPT_FROM_key,
966 allowed_hosts); 988 allowed_hosts);
967 GNUNET_free (allowed_hosts); 989 GNUNET_free (allowed_hosts);
968} 990}
@@ -979,15 +1001,17 @@ associate_shared_service (struct GNUNET_TESTING_System *system,
979 uint32_t port; 1001 uint32_t port;
980 1002
981 ss->n_peers++; 1003 ss->n_peers++;
982 if ( ((0 == ss->share) && (NULL == ss->instances)) 1004 if (((0 == ss->share) && (NULL == ss->instances)) ||
983 || 1005 ((0 != ss->share) &&
984 ( (0 != ss->share) 1006 (ss->n_instances < ((ss->n_peers + ss->share - 1) / ss->share))))
985 && (ss->n_instances < ((ss->n_peers + ss->share - 1) / ss->share)) ) )
986 { 1007 {
987 i = GNUNET_new (struct SharedServiceInstance); 1008 i = GNUNET_new (struct SharedServiceInstance);
988 i->ss = ss; 1009 i->ss = ss;
989 (void) GNUNET_asprintf (&gnunet_home, "%s/shared/%s/%u", 1010 (void) GNUNET_asprintf (&gnunet_home,
990 system->tmppath, ss->sname, ss->n_instances); 1011 "%s/shared/%s/%u",
1012 system->tmppath,
1013 ss->sname,
1014 ss->n_instances);
991 (void) GNUNET_asprintf (&i->unix_sock, "%s/sock", gnunet_home); 1015 (void) GNUNET_asprintf (&i->unix_sock, "%s/sock", gnunet_home);
992 port = GNUNET_TESTING_reserve_port (system); 1016 port = GNUNET_TESTING_reserve_port (system);
993 if (0 == port) 1017 if (0 == port)
@@ -1000,12 +1024,18 @@ associate_shared_service (struct GNUNET_TESTING_System *system,
1000 temp = GNUNET_CONFIGURATION_dup (ss->cfg); 1024 temp = GNUNET_CONFIGURATION_dup (ss->cfg);
1001 (void) GNUNET_asprintf (&i->port_str, "%u", port); 1025 (void) GNUNET_asprintf (&i->port_str, "%u", port);
1002 (void) GNUNET_asprintf (&i->cfg_fn, "%s/config", gnunet_home); 1026 (void) GNUNET_asprintf (&i->cfg_fn, "%s/config", gnunet_home);
1003 GNUNET_CONFIGURATION_set_value_string (temp, "PATHS", "GNUNET_HOME", 1027 GNUNET_CONFIGURATION_set_value_string (temp,
1028 "PATHS",
1029 "GNUNET_HOME",
1004 gnunet_home); 1030 gnunet_home);
1005 GNUNET_free (gnunet_home); 1031 GNUNET_free (gnunet_home);
1006 GNUNET_CONFIGURATION_set_value_string (temp, ss->sname, "UNIXPATH", 1032 GNUNET_CONFIGURATION_set_value_string (temp,
1033 ss->sname,
1034 "UNIXPATH",
1007 i->unix_sock); 1035 i->unix_sock);
1008 GNUNET_CONFIGURATION_set_value_string (temp, ss->sname, "PORT", 1036 GNUNET_CONFIGURATION_set_value_string (temp,
1037 ss->sname,
1038 "PORT",
1009 i->port_str); 1039 i->port_str);
1010 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_write (temp, i->cfg_fn)) 1040 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_write (temp, i->cfg_fn))
1011 { 1041 {
@@ -1021,9 +1051,13 @@ associate_shared_service (struct GNUNET_TESTING_System *system,
1021 GNUNET_assert (0 < ss->n_instances); 1051 GNUNET_assert (0 < ss->n_instances);
1022 i = ss->instances[ss->n_instances - 1]; 1052 i = ss->instances[ss->n_instances - 1];
1023 } 1053 }
1024 GNUNET_CONFIGURATION_iterate_section_values(ss->cfg, ss->sname, 1054 GNUNET_CONFIGURATION_iterate_section_values (ss->cfg,
1025 &cfg_copy_iterator, cfg); 1055 ss->sname,
1026 GNUNET_CONFIGURATION_set_value_string (cfg, ss->sname, "UNIXPATH", 1056 &cfg_copy_iterator,
1057 cfg);
1058 GNUNET_CONFIGURATION_set_value_string (cfg,
1059 ss->sname,
1060 "UNIXPATH",
1027 i->unix_sock); 1061 i->unix_sock);
1028 GNUNET_CONFIGURATION_set_value_string (cfg, ss->sname, "PORT", i->port_str); 1062 GNUNET_CONFIGURATION_set_value_string (cfg, ss->sname, "PORT", i->port_str);
1029 return i; 1063 return i;
@@ -1063,24 +1097,27 @@ GNUNET_TESTING_configuration_create_ (struct GNUNET_TESTING_System *system,
1063 uc.status = GNUNET_OK; 1097 uc.status = GNUNET_OK;
1064 uc.ports = NULL; 1098 uc.ports = NULL;
1065 uc.nports = 0; 1099 uc.nports = 0;
1066 GNUNET_asprintf (&uc.gnunet_home, "%s/%u", system->tmppath, 1100 GNUNET_asprintf (&uc.gnunet_home,
1101 "%s/%u",
1102 system->tmppath,
1067 system->path_counter++); 1103 system->path_counter++);
1068 GNUNET_asprintf (&default_config, "%s/config", uc.gnunet_home); 1104 GNUNET_asprintf (&default_config, "%s/config", uc.gnunet_home);
1069 GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG", 1105 GNUNET_CONFIGURATION_set_value_string (cfg,
1070 default_config); 1106 "PATHS",
1071 GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG", 1107 "DEFAULTCONFIG",
1072 default_config); 1108 default_config);
1109 GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG", default_config);
1073 GNUNET_free (default_config); 1110 GNUNET_free (default_config);
1074 GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "GNUNET_HOME", 1111 GNUNET_CONFIGURATION_set_value_string (cfg,
1112 "PATHS",
1113 "GNUNET_HOME",
1075 uc.gnunet_home); 1114 uc.gnunet_home);
1076 /* make PORTs and UNIXPATHs unique */ 1115 /* make PORTs and UNIXPATHs unique */
1077 GNUNET_CONFIGURATION_iterate (cfg, &update_config, &uc); 1116 GNUNET_CONFIGURATION_iterate (cfg, &update_config, &uc);
1078 /* allow connections to services from system trusted_ip host */ 1117 /* allow connections to services from system trusted_ip host */
1079 GNUNET_CONFIGURATION_iterate_sections (cfg, &update_config_sections, &uc); 1118 GNUNET_CONFIGURATION_iterate_sections (cfg, &update_config_sections, &uc);
1080 /* enable loopback-based connections between peers */ 1119 /* enable loopback-based connections between peers */
1081 GNUNET_CONFIGURATION_set_value_string (cfg, 1120 GNUNET_CONFIGURATION_set_value_string (cfg, "nat", "USE_LOCALADDR", "YES");
1082 "nat",
1083 "USE_LOCALADDR", "YES");
1084 GNUNET_free (uc.gnunet_home); 1121 GNUNET_free (uc.gnunet_home);
1085 if ((NULL != ports) && (NULL != nports)) 1122 if ((NULL != ports) && (NULL != nports))
1086 { 1123 {
@@ -1111,7 +1148,7 @@ GNUNET_TESTING_configuration_create_ (struct GNUNET_TESTING_System *system,
1111 */ 1148 */
1112int 1149int
1113GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system, 1150GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system,
1114 struct GNUNET_CONFIGURATION_Handle *cfg) 1151 struct GNUNET_CONFIGURATION_Handle *cfg)
1115{ 1152{
1116 return GNUNET_TESTING_configuration_create_ (system, cfg, NULL, NULL); 1153 return GNUNET_TESTING_configuration_create_ (system, cfg, NULL, NULL);
1117} 1154}
@@ -1132,10 +1169,10 @@ GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system,
1132 */ 1169 */
1133struct GNUNET_TESTING_Peer * 1170struct GNUNET_TESTING_Peer *
1134GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, 1171GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
1135 struct GNUNET_CONFIGURATION_Handle *cfg, 1172 struct GNUNET_CONFIGURATION_Handle *cfg,
1136 uint32_t key_number, 1173 uint32_t key_number,
1137 struct GNUNET_PeerIdentity *id, 1174 struct GNUNET_PeerIdentity *id,
1138 char **emsg) 1175 char **emsg)
1139{ 1176{
1140 struct GNUNET_TESTING_Peer *peer; 1177 struct GNUNET_TESTING_Peer *peer;
1141 struct GNUNET_DISK_FileHandle *fd; 1178 struct GNUNET_DISK_FileHandle *fd;
@@ -1157,9 +1194,11 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
1157 *emsg = NULL; 1194 *emsg = NULL;
1158 if (key_number >= system->total_hostkeys) 1195 if (key_number >= system->total_hostkeys)
1159 { 1196 {
1160 GNUNET_asprintf (&emsg_, 1197 GNUNET_asprintf (
1161 _("You attempted to create a testbed with more than %u hosts. Please precompute more hostkeys first.\n"), 1198 &emsg_,
1162 (unsigned int) system->total_hostkeys); 1199 _ (
1200 "You attempted to create a testbed with more than %u hosts. Please precompute more hostkeys first.\n"),
1201 (unsigned int) system->total_hostkeys);
1163 goto err_ret; 1202 goto err_ret;
1164 } 1203 }
1165 pk = NULL; 1204 pk = NULL;
@@ -1167,17 +1206,17 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
1167 (NULL == (pk = GNUNET_TESTING_hostkey_get (system, key_number, id)))) 1206 (NULL == (pk = GNUNET_TESTING_hostkey_get (system, key_number, id))))
1168 { 1207 {
1169 GNUNET_asprintf (&emsg_, 1208 GNUNET_asprintf (&emsg_,
1170 _("Failed to initialize hostkey for peer %u\n"), 1209 _ ("Failed to initialize hostkey for peer %u\n"),
1171 (unsigned int) key_number); 1210 (unsigned int) key_number);
1172 goto err_ret; 1211 goto err_ret;
1173 } 1212 }
1174 if (NULL != pk) 1213 if (NULL != pk)
1175 GNUNET_free (pk); 1214 GNUNET_free (pk);
1176 if (GNUNET_NO == 1215 if (GNUNET_NO == GNUNET_CONFIGURATION_have_value (cfg, "PEER", "PRIVATE_KEY"))
1177 GNUNET_CONFIGURATION_have_value (cfg, "PEER", "PRIVATE_KEY"))
1178 { 1216 {
1179 GNUNET_asprintf (&emsg_, 1217 GNUNET_asprintf (
1180 _("PRIVATE_KEY option in PEER section missing in configuration\n")); 1218 &emsg_,
1219 _ ("PRIVATE_KEY option in PEER section missing in configuration\n"));
1181 goto err_ret; 1220 goto err_ret;
1182 } 1221 }
1183 /* Remove sections for shared services */ 1222 /* Remove sections for shared services */
@@ -1186,46 +1225,50 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
1186 ss = system->shared_services[cnt]; 1225 ss = system->shared_services[cnt];
1187 GNUNET_CONFIGURATION_remove_section (cfg, ss->sname); 1226 GNUNET_CONFIGURATION_remove_section (cfg, ss->sname);
1188 } 1227 }
1189 if (GNUNET_OK != GNUNET_TESTING_configuration_create_ (system, cfg, 1228 if (GNUNET_OK !=
1190 &ports, &nports)) 1229 GNUNET_TESTING_configuration_create_ (system, cfg, &ports, &nports))
1191 { 1230 {
1192 GNUNET_asprintf (&emsg_, 1231 GNUNET_asprintf (&emsg_,
1193 _("Failed to create configuration for peer " 1232 _ ("Failed to create configuration for peer "
1194 "(not enough free ports?)\n")); 1233 "(not enough free ports?)\n"));
1195 goto err_ret; 1234 goto err_ret;
1196 } 1235 }
1197 GNUNET_assert (GNUNET_OK == 1236 GNUNET_assert (GNUNET_OK ==
1198 GNUNET_CONFIGURATION_get_value_filename (cfg, "PEER", 1237 GNUNET_CONFIGURATION_get_value_filename (cfg,
1199 "PRIVATE_KEY", 1238 "PEER",
1200 &hostkey_filename)); 1239 "PRIVATE_KEY",
1240 &hostkey_filename));
1201 fd = GNUNET_DISK_file_open (hostkey_filename, 1241 fd = GNUNET_DISK_file_open (hostkey_filename,
1202 GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_WRITE, 1242 GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_WRITE,
1203 GNUNET_DISK_PERM_USER_READ 1243 GNUNET_DISK_PERM_USER_READ |
1204 | GNUNET_DISK_PERM_USER_WRITE); 1244 GNUNET_DISK_PERM_USER_WRITE);
1205 if (NULL == fd) 1245 if (NULL == fd)
1206 { 1246 {
1207 GNUNET_asprintf (&emsg_, _("Cannot open hostkey file `%s': %s\n"), 1247 GNUNET_asprintf (&emsg_,
1208 hostkey_filename, STRERROR (errno)); 1248 _ ("Cannot open hostkey file `%s': %s\n"),
1249 hostkey_filename,
1250 strerror (errno));
1209 GNUNET_free (hostkey_filename); 1251 GNUNET_free (hostkey_filename);
1210 goto err_ret; 1252 goto err_ret;
1211 } 1253 }
1212 GNUNET_free (hostkey_filename); 1254 GNUNET_free (hostkey_filename);
1213 if (GNUNET_TESTING_HOSTKEYFILESIZE != 1255 if (GNUNET_TESTING_HOSTKEYFILESIZE !=
1214 GNUNET_DISK_file_write (fd, system->hostkeys_data 1256 GNUNET_DISK_file_write (fd,
1215 + (key_number * GNUNET_TESTING_HOSTKEYFILESIZE), 1257 system->hostkeys_data +
1216 GNUNET_TESTING_HOSTKEYFILESIZE)) 1258 (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
1259 GNUNET_TESTING_HOSTKEYFILESIZE))
1217 { 1260 {
1218 GNUNET_asprintf (&emsg_, 1261 GNUNET_asprintf (&emsg_,
1219 _("Failed to write hostkey file for peer %u: %s\n"), 1262 _ ("Failed to write hostkey file for peer %u: %s\n"),
1220 (unsigned int) key_number, 1263 (unsigned int) key_number,
1221 STRERROR (errno)); 1264 strerror (errno));
1222 GNUNET_DISK_file_close (fd); 1265 GNUNET_DISK_file_close (fd);
1223 goto err_ret; 1266 goto err_ret;
1224 } 1267 }
1225 GNUNET_DISK_file_close (fd); 1268 GNUNET_DISK_file_close (fd);
1226 ss_instances = GNUNET_malloc (sizeof (struct SharedServiceInstance *) 1269 ss_instances = GNUNET_malloc (sizeof (struct SharedServiceInstance *) *
1227 * system->n_shared_services); 1270 system->n_shared_services);
1228 for (cnt=0; cnt < system->n_shared_services; cnt++) 1271 for (cnt = 0; cnt < system->n_shared_services; cnt++)
1229 { 1272 {
1230 ss = system->shared_services[cnt]; 1273 ss = system->shared_services[cnt];
1231 ss_instances[cnt] = associate_shared_service (system, ss, cfg); 1274 ss_instances[cnt] = associate_shared_service (system, ss, cfg);
@@ -1236,15 +1279,18 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
1236 } 1279 }
1237 } 1280 }
1238 GNUNET_assert (GNUNET_OK == 1281 GNUNET_assert (GNUNET_OK ==
1239 GNUNET_CONFIGURATION_get_value_filename 1282 GNUNET_CONFIGURATION_get_value_filename (cfg,
1240 (cfg, "PATHS", "DEFAULTCONFIG", &config_filename)); 1283 "PATHS",
1284 "DEFAULTCONFIG",
1285 &config_filename));
1241 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config_filename)) 1286 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config_filename))
1242 { 1287 {
1243 GNUNET_asprintf (&emsg_, 1288 GNUNET_asprintf (&emsg_,
1244 _("Failed to write configuration file `%s' for peer %u: %s\n"), 1289 _ (
1245 config_filename, 1290 "Failed to write configuration file `%s' for peer %u: %s\n"),
1246 (unsigned int) key_number, 1291 config_filename,
1247 STRERROR (errno)); 1292 (unsigned int) key_number,
1293 strerror (errno));
1248 GNUNET_free (config_filename); 1294 GNUNET_free (config_filename);
1249 goto err_ret; 1295 goto err_ret;
1250 } 1296 }
@@ -1253,10 +1299,14 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
1253 peer->cfgfile = config_filename; /* Free in peer_destroy */ 1299 peer->cfgfile = config_filename; /* Free in peer_destroy */
1254 peer->cfg = GNUNET_CONFIGURATION_dup (cfg); 1300 peer->cfg = GNUNET_CONFIGURATION_dup (cfg);
1255 libexec_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); 1301 libexec_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
1256 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "arm", "PREFIX", &peer->main_binary)) 1302 if (GNUNET_SYSERR ==
1303 GNUNET_CONFIGURATION_get_value_string (cfg,
1304 "arm",
1305 "PREFIX",
1306 &peer->main_binary))
1257 { 1307 {
1258 /* No prefix */ 1308 /* No prefix */
1259 GNUNET_asprintf(&peer->main_binary, "%s", libexec_binary); 1309 GNUNET_asprintf (&peer->main_binary, "%s", libexec_binary);
1260 peer->args = GNUNET_strdup (""); 1310 peer->args = GNUNET_strdup ("");
1261 } 1311 }
1262 else 1312 else
@@ -1266,11 +1316,11 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
1266 peer->system = system; 1316 peer->system = system;
1267 peer->key_number = key_number; 1317 peer->key_number = key_number;
1268 GNUNET_free (libexec_binary); 1318 GNUNET_free (libexec_binary);
1269 peer->ports = ports; /* Free in peer_destroy */ 1319 peer->ports = ports; /* Free in peer_destroy */
1270 peer->nports = nports; 1320 peer->nports = nports;
1271 return peer; 1321 return peer;
1272 1322
1273 err_ret: 1323err_ret:
1274 GNUNET_free_non_null (ss_instances); 1324 GNUNET_free_non_null (ss_instances);
1275 GNUNET_free_non_null (ports); 1325 GNUNET_free_non_null (ports);
1276 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", emsg_); 1326 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", emsg_);
@@ -1290,7 +1340,7 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
1290 */ 1340 */
1291void 1341void
1292GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer, 1342GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer,
1293 struct GNUNET_PeerIdentity *id) 1343 struct GNUNET_PeerIdentity *id)
1294{ 1344{
1295 if (NULL != peer->id) 1345 if (NULL != peer->id)
1296 { 1346 {
@@ -1298,9 +1348,8 @@ GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer,
1298 return; 1348 return;
1299 } 1349 }
1300 peer->id = GNUNET_new (struct GNUNET_PeerIdentity); 1350 peer->id = GNUNET_new (struct GNUNET_PeerIdentity);
1301 GNUNET_free (GNUNET_TESTING_hostkey_get (peer->system, 1351 GNUNET_free (
1302 peer->key_number, 1352 GNUNET_TESTING_hostkey_get (peer->system, peer->key_number, peer->id));
1303 peer->id));
1304 GNUNET_memcpy (id, peer->id, sizeof (struct GNUNET_PeerIdentity)); 1353 GNUNET_memcpy (id, peer->id, sizeof (struct GNUNET_PeerIdentity));
1305} 1354}
1306 1355
@@ -1326,26 +1375,28 @@ GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer)
1326 for (cnt = 0; cnt < peer->system->n_shared_services; cnt++) 1375 for (cnt = 0; cnt < peer->system->n_shared_services; cnt++)
1327 { 1376 {
1328 i = peer->ss_instances[cnt]; 1377 i = peer->ss_instances[cnt];
1329 if ((0 == i->n_refs) 1378 if ((0 == i->n_refs) &&
1330 && (GNUNET_SYSERR == start_shared_service_instance (i)) ) 1379 (GNUNET_SYSERR == start_shared_service_instance (i)))
1331 return GNUNET_SYSERR; 1380 return GNUNET_SYSERR;
1332 i->n_refs++; 1381 i->n_refs++;
1333 } 1382 }
1334 peer->main_binary = GNUNET_CONFIGURATION_expand_dollar (peer->cfg, peer->main_binary); 1383 peer->main_binary =
1335 peer->main_process = GNUNET_OS_start_process_s (PIPE_CONTROL, 1384 GNUNET_CONFIGURATION_expand_dollar (peer->cfg, peer->main_binary);
1336 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 1385 peer->main_process =
1337 NULL, 1386 GNUNET_OS_start_process_s (PIPE_CONTROL,
1338 peer->main_binary, 1387 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
1339 peer->args, 1388 NULL,
1340 "-c", 1389 peer->main_binary,
1341 peer->cfgfile, 1390 peer->args,
1342 NULL); 1391 "-c",
1392 peer->cfgfile,
1393 NULL);
1343 if (NULL == peer->main_process) 1394 if (NULL == peer->main_process)
1344 { 1395 {
1345 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1396 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1346 _("Failed to start `%s': %s\n"), 1397 _ ("Failed to start `%s': %s\n"),
1347 peer->main_binary, 1398 peer->main_binary,
1348 STRERROR (errno)); 1399 strerror (errno));
1349 return GNUNET_SYSERR; 1400 return GNUNET_SYSERR;
1350 } 1401 }
1351 return GNUNET_OK; 1402 return GNUNET_OK;
@@ -1433,8 +1484,7 @@ GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer)
1433 * #GNUNET_SYSERR on error. 1484 * #GNUNET_SYSERR on error.
1434 */ 1485 */
1435static void 1486static void
1436disconn_status (void *cls, 1487disconn_status (void *cls, int connected)
1437 int connected)
1438{ 1488{
1439 struct GNUNET_TESTING_Peer *peer = cls; 1489 struct GNUNET_TESTING_Peer *peer = cls;
1440 1490
@@ -1551,12 +1601,11 @@ GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer)
1551 */ 1601 */
1552int 1602int
1553GNUNET_TESTING_peer_run (const char *testdir, 1603GNUNET_TESTING_peer_run (const char *testdir,
1554 const char *cfgfilename, 1604 const char *cfgfilename,
1555 GNUNET_TESTING_TestMain tm, 1605 GNUNET_TESTING_TestMain tm,
1556 void *tm_cls) 1606 void *tm_cls)
1557{ 1607{
1558 return GNUNET_TESTING_service_run (testdir, "arm", 1608 return GNUNET_TESTING_service_run (testdir, "arm", cfgfilename, tm, tm_cls);
1559 cfgfilename, tm, tm_cls);
1560} 1609}
1561 1610
1562 1611
@@ -1624,10 +1673,10 @@ service_run_main (void *cls)
1624 */ 1673 */
1625int 1674int
1626GNUNET_TESTING_service_run (const char *testdir, 1675GNUNET_TESTING_service_run (const char *testdir,
1627 const char *service_name, 1676 const char *service_name,
1628 const char *cfgfilename, 1677 const char *cfgfilename,
1629 GNUNET_TESTING_TestMain tm, 1678 GNUNET_TESTING_TestMain tm,
1630 void *tm_cls) 1679 void *tm_cls)
1631{ 1680{
1632 struct ServiceContext sc; 1681 struct ServiceContext sc;
1633 struct GNUNET_TESTING_System *system; 1682 struct GNUNET_TESTING_System *system;
@@ -1636,9 +1685,7 @@ GNUNET_TESTING_service_run (const char *testdir,
1636 char *binary; 1685 char *binary;
1637 char *libexec_binary; 1686 char *libexec_binary;
1638 1687
1639 GNUNET_log_setup (testdir, 1688 GNUNET_log_setup (testdir, "WARNING", NULL);
1640 "WARNING",
1641 NULL);
1642 system = GNUNET_TESTING_system_create (testdir, "127.0.0.1", NULL, NULL); 1689 system = GNUNET_TESTING_system_create (testdir, "127.0.0.1", NULL, NULL);
1643 if (NULL == system) 1690 if (NULL == system)
1644 return 1; 1691 return 1;
@@ -1646,7 +1693,8 @@ GNUNET_TESTING_service_run (const char *testdir,
1646 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfgfilename)) 1693 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfgfilename))
1647 { 1694 {
1648 LOG (GNUNET_ERROR_TYPE_ERROR, 1695 LOG (GNUNET_ERROR_TYPE_ERROR,
1649 _("Failed to load configuration from %s\n"), cfgfilename); 1696 _ ("Failed to load configuration from %s\n"),
1697 cfgfilename);
1650 GNUNET_CONFIGURATION_destroy (cfg); 1698 GNUNET_CONFIGURATION_destroy (cfg);
1651 GNUNET_TESTING_system_destroy (system, GNUNET_YES); 1699 GNUNET_TESTING_system_destroy (system, GNUNET_YES);
1652 return 1; 1700 return 1;
@@ -1663,10 +1711,14 @@ GNUNET_TESTING_service_run (const char *testdir,
1663 GNUNET_free (peer->args); 1711 GNUNET_free (peer->args);
1664 GNUNET_asprintf (&binary, "gnunet-service-%s", service_name); 1712 GNUNET_asprintf (&binary, "gnunet-service-%s", service_name);
1665 libexec_binary = GNUNET_OS_get_libexec_binary_path (binary); 1713 libexec_binary = GNUNET_OS_get_libexec_binary_path (binary);
1666 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, service_name, "PREFIX", &peer->main_binary)) 1714 if (GNUNET_SYSERR ==
1715 GNUNET_CONFIGURATION_get_value_string (cfg,
1716 service_name,
1717 "PREFIX",
1718 &peer->main_binary))
1667 { 1719 {
1668 /* No prefix */ 1720 /* No prefix */
1669 GNUNET_asprintf(&peer->main_binary, "%s", libexec_binary); 1721 GNUNET_asprintf (&peer->main_binary, "%s", libexec_binary);
1670 peer->args = GNUNET_strdup (""); 1722 peer->args = GNUNET_strdup ("");
1671 } 1723 }
1672 else 1724 else
diff --git a/src/topology/test_gnunet_daemon_topology.c b/src/topology/test_gnunet_daemon_topology.c
index 477d218ce..6b2c58208 100644
--- a/src/topology/test_gnunet_daemon_topology.c
+++ b/src/topology/test_gnunet_daemon_topology.c
@@ -208,7 +208,7 @@ notify_connect_complete (void *cls,
208 GNUNET_TESTBED_operation_done (op); 208 GNUNET_TESTBED_operation_done (op);
209 if (NULL != emsg) 209 if (NULL != emsg)
210 { 210 {
211 FPRINTF (stderr, "Failed to connect two peers: %s\n", emsg); 211 fprintf (stderr, "Failed to connect two peers: %s\n", emsg);
212 result = GNUNET_SYSERR; 212 result = GNUNET_SYSERR;
213 GNUNET_SCHEDULER_shutdown (); 213 GNUNET_SCHEDULER_shutdown ();
214 return; 214 return;
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c
index 576c20278..c883166c6 100644
--- a/src/transport/gnunet-communicator-tcp.c
+++ b/src/transport/gnunet-communicator-tcp.c
@@ -1103,7 +1103,7 @@ tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
1103 char *colon; 1103 char *colon;
1104 char *cp; 1104 char *cp;
1105 1105
1106 if (1 == SSCANF (bindto, "%u%1s", &port, dummy)) 1106 if (1 == sscanf (bindto, "%u%1s", &port, dummy))
1107 { 1107 {
1108 /* interpreting value as just a PORT number */ 1108 /* interpreting value as just a PORT number */
1109 if (port > UINT16_MAX) 1109 if (port > UINT16_MAX)
@@ -1146,7 +1146,7 @@ tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
1146 /* interpet value after colon as port */ 1146 /* interpet value after colon as port */
1147 *colon = '\0'; 1147 *colon = '\0';
1148 colon++; 1148 colon++;
1149 if (1 == SSCANF (colon, "%u%1s", &port, dummy)) 1149 if (1 == sscanf (colon, "%u%1s", &port, dummy))
1150 { 1150 {
1151 /* interpreting value as just a PORT number */ 1151 /* interpreting value as just a PORT number */
1152 if (port > UINT16_MAX) 1152 if (port > UINT16_MAX)
@@ -1877,7 +1877,7 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
1877 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1877 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1878 "socket(%d) failed: %s", 1878 "socket(%d) failed: %s",
1879 in->sa_family, 1879 in->sa_family,
1880 STRERROR (errno)); 1880 strerror (errno));
1881 GNUNET_free (in); 1881 GNUNET_free (in);
1882 return GNUNET_SYSERR; 1882 return GNUNET_SYSERR;
1883 } 1883 }
@@ -1886,7 +1886,7 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
1886 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1886 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1887 "connect to `%s' failed: %s", 1887 "connect to `%s' failed: %s",
1888 address, 1888 address,
1889 STRERROR (errno)); 1889 strerror (errno));
1890 GNUNET_NETWORK_socket_close (sock); 1890 GNUNET_NETWORK_socket_close (sock);
1891 GNUNET_free (in); 1891 GNUNET_free (in);
1892 return GNUNET_SYSERR; 1892 return GNUNET_SYSERR;
diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c
index 68635b5bf..2c8893d75 100644
--- a/src/transport/gnunet-communicator-udp.c
+++ b/src/transport/gnunet-communicator-udp.c
@@ -1725,7 +1725,7 @@ udp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
1725 char *colon; 1725 char *colon;
1726 char *cp; 1726 char *cp;
1727 1727
1728 if (1 == SSCANF (bindto, "%u%1s", &port, dummy)) 1728 if (1 == sscanf (bindto, "%u%1s", &port, dummy))
1729 { 1729 {
1730 /* interpreting value as just a PORT number */ 1730 /* interpreting value as just a PORT number */
1731 if (port > UINT16_MAX) 1731 if (port > UINT16_MAX)
@@ -1768,7 +1768,7 @@ udp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
1768 /* interpet value after colon as port */ 1768 /* interpet value after colon as port */
1769 *colon = '\0'; 1769 *colon = '\0';
1770 colon++; 1770 colon++;
1771 if (1 == SSCANF (colon, "%u%1s", &port, dummy)) 1771 if (1 == sscanf (colon, "%u%1s", &port, dummy))
1772 { 1772 {
1773 /* interpreting value as just a PORT number */ 1773 /* interpreting value as just a PORT number */
1774 if (port > UINT16_MAX) 1774 if (port > UINT16_MAX)
diff --git a/src/transport/gnunet-communicator-unix.c b/src/transport/gnunet-communicator-unix.c
index 1d5029f20..cb1fbc230 100644
--- a/src/transport/gnunet-communicator-unix.c
+++ b/src/transport/gnunet-communicator-unix.c
@@ -430,7 +430,7 @@ resend:
430 GNUNET_i2s (&queue->target), 430 GNUNET_i2s (&queue->target),
431 (int) sent, 431 (int) sent,
432 (unsigned int) msg_size, 432 (unsigned int) msg_size,
433 (sent < 0) ? STRERROR (errno) : "ok"); 433 (sent < 0) ? strerror (errno) : "ok");
434 if (-1 != sent) 434 if (-1 != sent)
435 { 435 {
436 GNUNET_STATISTICS_update (stats, 436 GNUNET_STATISTICS_update (stats,
diff --git a/src/transport/gnunet-helper-transport-wlan-dummy.c b/src/transport/gnunet-helper-transport-wlan-dummy.c
index dbd9014cb..c7ed1b903 100644
--- a/src/transport/gnunet-helper-transport-wlan-dummy.c
+++ b/src/transport/gnunet-helper-transport-wlan-dummy.c
@@ -140,13 +140,13 @@ stdin_send (void *cls,
140 if ( (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) || 140 if ( (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) ||
141 (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) > sendsize) ) 141 (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) > sendsize) )
142 { 142 {
143 FPRINTF (stderr, "%s", "Received malformed message\n"); 143 fprintf (stderr, "%s", "Received malformed message\n");
144 exit (1); 144 exit (1);
145 } 145 }
146 payload_size = sendsize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage); 146 payload_size = sendsize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage);
147 if ((payload_size + sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + write_pout->size) > MAXLINE * 2) 147 if ((payload_size + sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + write_pout->size) > MAXLINE * 2)
148 { 148 {
149 FPRINTF (stderr, "%s", "Packet too big for buffer\n"); 149 fprintf (stderr, "%s", "Packet too big for buffer\n");
150 exit (1); 150 exit (1);
151 } 151 }
152 memset (&newheader, 0, sizeof (newheader)); 152 memset (&newheader, 0, sizeof (newheader));
@@ -184,7 +184,7 @@ file_in_send (void *cls,
184 sendsize = ntohs (hdr->size); 184 sendsize = ntohs (hdr->size);
185 if ((sendsize + write_std->size) > MAXLINE * 2) 185 if ((sendsize + write_std->size) > MAXLINE * 2)
186 { 186 {
187 FPRINTF (stderr, "%s", "Packet too big for buffer\n"); 187 fprintf (stderr, "%s", "Packet too big for buffer\n");
188 exit (1); 188 exit (1);
189 } 189 }
190 GNUNET_memcpy (write_std->buf + write_std->size, hdr, sendsize); 190 GNUNET_memcpy (write_std->buf + write_std->size, hdr, sendsize);
@@ -227,7 +227,7 @@ main (int argc, char *argv[])
227 if ( (2 != argc) || 227 if ( (2 != argc) ||
228 ((0 != strcmp (argv[1], "1")) && (0 != strcmp (argv[1], "2"))) ) 228 ((0 != strcmp (argv[1], "1")) && (0 != strcmp (argv[1], "2"))) )
229 { 229 {
230 FPRINTF (stderr, 230 fprintf (stderr,
231 "%s", 231 "%s",
232 "This program must be started with the operating mode (1 or 2) as the only argument.\n"); 232 "This program must be started with the operating mode (1 or 2) as the only argument.\n");
233 return 1; 233 return 1;
@@ -238,7 +238,7 @@ main (int argc, char *argv[])
238 if ( (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE1)) || 238 if ( (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE1)) ||
239 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE2)) ) 239 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE2)) )
240 { 240 {
241 FPRINTF (stderr, 241 fprintf (stderr,
242 "Failed to create directory for file `%s'\n", 242 "Failed to create directory for file `%s'\n",
243 FIFO_FILE1); 243 FIFO_FILE1);
244 return 1; 244 return 1;
@@ -249,7 +249,7 @@ main (int argc, char *argv[])
249 { 249 {
250 erg = mkfifo (FIFO_FILE1, 0666); 250 erg = mkfifo (FIFO_FILE1, 0666);
251 if ( (0 != erg) && (EEXIST != errno) ) 251 if ( (0 != erg) && (EEXIST != errno) )
252 FPRINTF (stderr, "Error in mkfifo(%s): %s\n", FIFO_FILE1, 252 fprintf (stderr, "Error in mkfifo(%s): %s\n", FIFO_FILE1,
253 strerror (errno)); 253 strerror (errno));
254 } 254 }
255 } 255 }
@@ -259,7 +259,7 @@ main (int argc, char *argv[])
259 { 259 {
260 GNUNET_break (0 == (erg = mkfifo (FIFO_FILE2, 0666))); 260 GNUNET_break (0 == (erg = mkfifo (FIFO_FILE2, 0666)));
261 if ( (0 != erg) && (EEXIST != errno) ) 261 if ( (0 != erg) && (EEXIST != errno) )
262 FPRINTF (stderr, 262 fprintf (stderr,
263 "Error in mkfifo(%s): %s\n", 263 "Error in mkfifo(%s): %s\n",
264 FIFO_FILE2, 264 FIFO_FILE2,
265 strerror (errno)); 265 strerror (errno));
@@ -272,7 +272,7 @@ main (int argc, char *argv[])
272 fpin = fopen (FIFO_FILE1, "r"); 272 fpin = fopen (FIFO_FILE1, "r");
273 if (NULL == fpin) 273 if (NULL == fpin)
274 { 274 {
275 FPRINTF (stderr, 275 fprintf (stderr,
276 "fopen of read FIFO_FILE1 failed: %s\n", 276 "fopen of read FIFO_FILE1 failed: %s\n",
277 STRERROR (errno)); 277 STRERROR (errno));
278 goto end; 278 goto end;
@@ -284,7 +284,7 @@ main (int argc, char *argv[])
284 } 284 }
285 if (NULL == fpout) 285 if (NULL == fpout)
286 { 286 {
287 FPRINTF (stderr, 287 fprintf (stderr,
288 "fopen of write FIFO_FILE2 failed: %s\n", 288 "fopen of write FIFO_FILE2 failed: %s\n",
289 STRERROR (errno)); 289 STRERROR (errno));
290 goto end; 290 goto end;
@@ -300,7 +300,7 @@ main (int argc, char *argv[])
300 } 300 }
301 if (NULL == fpout) 301 if (NULL == fpout)
302 { 302 {
303 FPRINTF (stderr, 303 fprintf (stderr,
304 "fopen of write FIFO_FILE1 failed: %s\n", 304 "fopen of write FIFO_FILE1 failed: %s\n",
305 STRERROR (errno)); 305 STRERROR (errno));
306 goto end; 306 goto end;
@@ -308,7 +308,7 @@ main (int argc, char *argv[])
308 fpin = fopen (FIFO_FILE2, "r"); 308 fpin = fopen (FIFO_FILE2, "r");
309 if (NULL == fpin) 309 if (NULL == fpin)
310 { 310 {
311 FPRINTF (stderr, 311 fprintf (stderr,
312 "fopen of read FIFO_FILE2 failed: %s\n", 312 "fopen of read FIFO_FILE2 failed: %s\n",
313 STRERROR (errno)); 313 STRERROR (errno));
314 goto end; 314 goto end;
@@ -319,7 +319,7 @@ main (int argc, char *argv[])
319 GNUNET_assert (fpin >= 0); 319 GNUNET_assert (fpin >= 0);
320 if (fdpin >= FD_SETSIZE) 320 if (fdpin >= FD_SETSIZE)
321 { 321 {
322 FPRINTF (stderr, 322 fprintf (stderr,
323 "File fdpin number too large (%d > %u)\n", 323 "File fdpin number too large (%d > %u)\n",
324 fdpin, 324 fdpin,
325 (unsigned int) FD_SETSIZE); 325 (unsigned int) FD_SETSIZE);
@@ -331,7 +331,7 @@ main (int argc, char *argv[])
331 331
332 if (fdpout >= FD_SETSIZE) 332 if (fdpout >= FD_SETSIZE)
333 { 333 {
334 FPRINTF (stderr, 334 fprintf (stderr,
335 "File fdpout number too large (%d > %u)\n", 335 "File fdpout number too large (%d > %u)\n",
336 fdpout, 336 fdpout,
337 (unsigned int) FD_SETSIZE); 337 (unsigned int) FD_SETSIZE);
@@ -395,7 +395,7 @@ main (int argc, char *argv[])
395 continue; 395 continue;
396 if (0 > retval) 396 if (0 > retval)
397 { 397 {
398 FPRINTF (stderr, "select failed: %s\n", STRERROR (errno)); 398 fprintf (stderr, "select failed: %s\n", STRERROR (errno));
399 closeprog = 1; 399 closeprog = 1;
400 break; 400 break;
401 } 401 }
@@ -408,7 +408,7 @@ main (int argc, char *argv[])
408 if (0 > ret) 408 if (0 > ret)
409 { 409 {
410 closeprog = 1; 410 closeprog = 1;
411 FPRINTF (stderr, "Write ERROR to STDOUT_FILENO: %s\n", 411 fprintf (stderr, "Write ERROR to STDOUT_FILENO: %s\n",
412 STRERROR (errno)); 412 STRERROR (errno));
413 break; 413 break;
414 } 414 }
@@ -433,7 +433,7 @@ main (int argc, char *argv[])
433 if (0 > ret) 433 if (0 > ret)
434 { 434 {
435 closeprog = 1; 435 closeprog = 1;
436 FPRINTF (stderr, "Write ERROR to fdpout failed: %s\n", STRERROR (errno)); 436 fprintf (stderr, "Write ERROR to fdpout failed: %s\n", STRERROR (errno));
437 } 437 }
438 else 438 else
439 { 439 {
@@ -454,7 +454,7 @@ main (int argc, char *argv[])
454 if (0 > readsize) 454 if (0 > readsize)
455 { 455 {
456 closeprog = 1; 456 closeprog = 1;
457 FPRINTF (stderr, "Error reading from STDIN_FILENO: %s\n", 457 fprintf (stderr, "Error reading from STDIN_FILENO: %s\n",
458 STRERROR (errno)); 458 STRERROR (errno));
459 } 459 }
460 else if (0 < readsize) 460 else if (0 < readsize)
@@ -477,7 +477,7 @@ main (int argc, char *argv[])
477 if (0 > readsize) 477 if (0 > readsize)
478 { 478 {
479 closeprog = 1; 479 closeprog = 1;
480 FPRINTF (stderr, "Error reading from fdpin: %s\n", STRERROR (errno)); 480 fprintf (stderr, "Error reading from fdpin: %s\n", STRERROR (errno));
481 break; 481 break;
482 } 482 }
483 else if (0 < readsize) 483 else if (0 < readsize)
diff --git a/src/transport/gnunet-transport-profiler.c b/src/transport/gnunet-transport-profiler.c
index 89f5b4108..d4f8589d1 100644
--- a/src/transport/gnunet-transport-profiler.c
+++ b/src/transport/gnunet-transport-profiler.c
@@ -195,7 +195,7 @@ shutdown_task (void *cls)
195 } 195 }
196 196
197 if (verbosity > 0) 197 if (verbosity > 0)
198 FPRINTF (stdout, "\n"); 198 fprintf (stdout, "\n");
199 199
200 /* Output format: 200 /* Output format:
201 * All time values in ms 201 * All time values in ms
@@ -216,7 +216,7 @@ shutdown_task (void *cls)
216 icur->rate = ((benchmark_count * benchmark_size) / 1024) / 216 icur->rate = ((benchmark_count * benchmark_size) / 1024) /
217 ((float) icur->dur.rel_value_us / (1000 * 1000)); 217 ((float) icur->dur.rel_value_us / (1000 * 1000));
218 if (verbosity > 0) 218 if (verbosity > 0)
219 FPRINTF (stdout, 219 fprintf (stdout,
220 _ ("%llu B in %llu ms == %.2f KB/s!\n"), 220 _ ("%llu B in %llu ms == %.2f KB/s!\n"),
221 ((long long unsigned int) benchmark_count * benchmark_size), 221 ((long long unsigned int) benchmark_count * benchmark_size),
222 ((long long unsigned int) icur->dur.rel_value_us / 1000), 222 ((long long unsigned int) icur->dur.rel_value_us / 1000),
@@ -252,7 +252,7 @@ shutdown_task (void *cls)
252 stddev_duration = sqrtf (stddev_duration); 252 stddev_duration = sqrtf (stddev_duration);
253 253
254 /* Output */ 254 /* Output */
255 FPRINTF (stdout, 255 fprintf (stdout,
256 "%u;%u;%llu;%llu;%.2f;%.2f", 256 "%u;%u;%llu;%llu;%.2f;%.2f",
257 benchmark_count, 257 benchmark_count,
258 benchmark_size, 258 benchmark_size,
@@ -267,7 +267,7 @@ shutdown_task (void *cls)
267 inext = icur->next; 267 inext = icur->next;
268 GNUNET_CONTAINER_DLL_remove (ihead, itail, icur); 268 GNUNET_CONTAINER_DLL_remove (ihead, itail, icur);
269 269
270 FPRINTF (stdout, 270 fprintf (stdout,
271 ";%llu;%.2f", 271 ";%llu;%.2f",
272 (long long unsigned int) (icur->dur.rel_value_us / 1000), 272 (long long unsigned int) (icur->dur.rel_value_us / 1000),
273 icur->rate); 273 icur->rate);
@@ -279,14 +279,14 @@ shutdown_task (void *cls)
279 if (benchmark_receive) 279 if (benchmark_receive)
280 { 280 {
281 duration = GNUNET_TIME_absolute_get_duration (start_time); 281 duration = GNUNET_TIME_absolute_get_duration (start_time);
282 FPRINTF (stdout, 282 fprintf (stdout,
283 "Received %llu bytes/s (%llu bytes in %s)\n", 283 "Received %llu bytes/s (%llu bytes in %s)\n",
284 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us), 284 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us),
285 traffic_received, 285 traffic_received,
286 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES)); 286 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
287 } 287 }
288#endif 288#endif
289 FPRINTF (stdout, "\n"); 289 fprintf (stdout, "\n");
290} 290}
291 291
292 292
@@ -326,7 +326,7 @@ send_msg (void *cls)
326 } 326 }
327 GNUNET_MQ_send (mq, env); 327 GNUNET_MQ_send (mq, env);
328 if ((verbosity > 0) && (0 == itail->msgs_sent % 10)) 328 if ((verbosity > 0) && (0 == itail->msgs_sent % 10))
329 FPRINTF (stdout, "."); 329 fprintf (stdout, ".");
330} 330}
331 331
332 332
@@ -343,7 +343,7 @@ iteration_start ()
343 GNUNET_CONTAINER_DLL_insert_tail (ihead, itail, icur); 343 GNUNET_CONTAINER_DLL_insert_tail (ihead, itail, icur);
344 icur->start = GNUNET_TIME_absolute_get (); 344 icur->start = GNUNET_TIME_absolute_get ();
345 if (verbosity > 0) 345 if (verbosity > 0)
346 FPRINTF ( 346 fprintf (
347 stdout, 347 stdout,
348 "\nStarting benchmark, starting to send %u messages in %u byte blocks\n", 348 "\nStarting benchmark, starting to send %u messages in %u byte blocks\n",
349 benchmark_count, 349 benchmark_count,
@@ -385,12 +385,12 @@ notify_connect (void *cls,
385{ 385{
386 if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) 386 if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity)))
387 { 387 {
388 FPRINTF (stdout, "Connected to different peer `%s'\n", GNUNET_i2s (&pid)); 388 fprintf (stdout, "Connected to different peer `%s'\n", GNUNET_i2s (&pid));
389 return NULL; 389 return NULL;
390 } 390 }
391 391
392 if (verbosity > 0) 392 if (verbosity > 0)
393 FPRINTF (stdout, "Successfully connected to `%s'\n", GNUNET_i2s (&pid)); 393 fprintf (stdout, "Successfully connected to `%s'\n", GNUNET_i2s (&pid));
394 mq = m; 394 mq = m;
395 iteration_start (); 395 iteration_start ();
396 return NULL; 396 return NULL;
@@ -415,7 +415,7 @@ notify_disconnect (void *cls,
415 mq = NULL; 415 mq = NULL;
416 if (GNUNET_YES == benchmark_running) 416 if (GNUNET_YES == benchmark_running)
417 { 417 {
418 FPRINTF (stdout, 418 fprintf (stdout,
419 "Disconnected from peer `%s' while benchmarking\n", 419 "Disconnected from peer `%s' while benchmarking\n",
420 GNUNET_i2s (&pid)); 420 GNUNET_i2s (&pid));
421 return; 421 return;
@@ -449,7 +449,7 @@ handle_dummy (void *cls, const struct GNUNET_MessageHeader *message)
449 if (! benchmark_receive) 449 if (! benchmark_receive)
450 return; 450 return;
451 if (verbosity > 0) 451 if (verbosity > 0)
452 FPRINTF (stdout, 452 fprintf (stdout,
453 "Received %u bytes\n", 453 "Received %u bytes\n",
454 (unsigned int) ntohs (message->size)); 454 (unsigned int) ntohs (message->size));
455} 455}
@@ -461,7 +461,7 @@ blacklist_cb (void *cls, const struct GNUNET_PeerIdentity *peer)
461 if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) 461 if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity)))
462 { 462 {
463 if (verbosity > 0) 463 if (verbosity > 0)
464 FPRINTF (stdout, "Denying connection to `%s'\n", GNUNET_i2s (peer)); 464 fprintf (stdout, "Denying connection to `%s'\n", GNUNET_i2s (peer));
465 return GNUNET_SYSERR; 465 return GNUNET_SYSERR;
466 } 466 }
467 return GNUNET_OK; 467 return GNUNET_OK;
@@ -494,26 +494,26 @@ run (void *cls,
494 ret = 1; 494 ret = 1;
495 if (GNUNET_MAX_MESSAGE_SIZE <= benchmark_size) 495 if (GNUNET_MAX_MESSAGE_SIZE <= benchmark_size)
496 { 496 {
497 FPRINTF (stderr, "Message size too big!\n"); 497 fprintf (stderr, "Message size too big!\n");
498 return; 498 return;
499 } 499 }
500 500
501 if (NULL == cpid) 501 if (NULL == cpid)
502 { 502 {
503 FPRINTF (stderr, "No peer identity given\n"); 503 fprintf (stderr, "No peer identity given\n");
504 return; 504 return;
505 } 505 }
506 if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (cpid, 506 if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (cpid,
507 strlen (cpid), 507 strlen (cpid),
508 &pid.public_key)) 508 &pid.public_key))
509 { 509 {
510 FPRINTF (stderr, "Failed to parse peer identity `%s'\n", cpid); 510 fprintf (stderr, "Failed to parse peer identity `%s'\n", cpid);
511 return; 511 return;
512 } 512 }
513 if (1 == benchmark_send) 513 if (1 == benchmark_send)
514 { 514 {
515 if (verbosity > 0) 515 if (verbosity > 0)
516 FPRINTF (stderr, 516 fprintf (stderr,
517 "Trying to send %u messages with size %u to peer `%s'\n", 517 "Trying to send %u messages with size %u to peer `%s'\n",
518 benchmark_count, 518 benchmark_count,
519 benchmark_size, 519 benchmark_size,
@@ -521,20 +521,20 @@ run (void *cls,
521 } 521 }
522 else if (1 == benchmark_receive) 522 else if (1 == benchmark_receive)
523 { 523 {
524 FPRINTF (stderr, 524 fprintf (stderr,
525 "Trying to receive messages from peer `%s'\n", 525 "Trying to receive messages from peer `%s'\n",
526 GNUNET_i2s (&pid)); 526 GNUNET_i2s (&pid));
527 } 527 }
528 else 528 else
529 { 529 {
530 FPRINTF (stderr, "No operation given\n"); 530 fprintf (stderr, "No operation given\n");
531 return; 531 return;
532 } 532 }
533 533
534 ats = GNUNET_ATS_connectivity_init (cfg); 534 ats = GNUNET_ATS_connectivity_init (cfg);
535 if (NULL == ats) 535 if (NULL == ats)
536 { 536 {
537 FPRINTF (stderr, "Failed to connect to ATS service\n"); 537 fprintf (stderr, "Failed to connect to ATS service\n");
538 ret = 1; 538 ret = 1;
539 return; 539 return;
540 } 540 }
@@ -548,7 +548,7 @@ run (void *cls,
548 NULL); 548 NULL);
549 if (NULL == handle) 549 if (NULL == handle)
550 { 550 {
551 FPRINTF (stderr, "Failed to connect to transport service\n"); 551 fprintf (stderr, "Failed to connect to transport service\n");
552 GNUNET_ATS_connectivity_done (ats); 552 GNUNET_ATS_connectivity_done (ats);
553 ats = NULL; 553 ats = NULL;
554 ret = 1; 554 ret = 1;
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c
index 36c8fc451..ebc3f402d 100644
--- a/src/transport/gnunet-transport.c
+++ b/src/transport/gnunet-transport.c
@@ -402,7 +402,7 @@ shutdown_task (void *cls)
402 if (benchmark_send) 402 if (benchmark_send)
403 { 403 {
404 duration = GNUNET_TIME_absolute_get_duration (start_time); 404 duration = GNUNET_TIME_absolute_get_duration (start_time);
405 FPRINTF (stdout, 405 fprintf (stdout,
406 _ ("Transmitted %llu bytes/s (%llu bytes in %s)\n"), 406 _ ("Transmitted %llu bytes/s (%llu bytes in %s)\n"),
407 1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us), 407 1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us),
408 traffic_sent, 408 traffic_sent,
@@ -411,7 +411,7 @@ shutdown_task (void *cls)
411 if (benchmark_receive) 411 if (benchmark_receive)
412 { 412 {
413 duration = GNUNET_TIME_absolute_get_duration (start_time); 413 duration = GNUNET_TIME_absolute_get_duration (start_time);
414 FPRINTF (stdout, 414 fprintf (stdout,
415 _ ("Received %llu bytes/s (%llu bytes in %s)\n"), 415 _ ("Received %llu bytes/s (%llu bytes in %s)\n"),
416 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us), 416 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us),
417 traffic_received, 417 traffic_received,
@@ -451,7 +451,7 @@ operation_timeout (void *cls)
451 op_timeout = NULL; 451 op_timeout = NULL;
452 if ((benchmark_send) || (benchmark_receive)) 452 if ((benchmark_send) || (benchmark_receive))
453 { 453 {
454 FPRINTF (stdout, _ ("Failed to connect to `%s'\n"), GNUNET_i2s_full (&pid)); 454 fprintf (stdout, _ ("Failed to connect to `%s'\n"), GNUNET_i2s_full (&pid));
455 GNUNET_SCHEDULER_shutdown (); 455 GNUNET_SCHEDULER_shutdown ();
456 ret = 1; 456 ret = 1;
457 return; 457 return;
@@ -462,7 +462,7 @@ operation_timeout (void *cls)
462 while (NULL != (cur = next)) 462 while (NULL != (cur = next))
463 { 463 {
464 next = cur->next; 464 next = cur->next;
465 FPRINTF (stdout, 465 fprintf (stdout,
466 _ ("Failed to resolve address for peer `%s'\n"), 466 _ ("Failed to resolve address for peer `%s'\n"),
467 GNUNET_i2s (&cur->addrcp->peer)); 467 GNUNET_i2s (&cur->addrcp->peer));
468 468
@@ -472,7 +472,7 @@ operation_timeout (void *cls)
472 GNUNET_free (cur->addrcp); 472 GNUNET_free (cur->addrcp);
473 GNUNET_free (cur); 473 GNUNET_free (cur);
474 } 474 }
475 FPRINTF (stdout, 475 fprintf (stdout,
476 "%s", 476 "%s",
477 _ ("Failed to list connections, timeout occurred\n")); 477 _ ("Failed to list connections, timeout occurred\n"));
478 GNUNET_SCHEDULER_shutdown (); 478 GNUNET_SCHEDULER_shutdown ();
@@ -500,7 +500,7 @@ do_send (void *cls)
500 traffic_sent += BLOCKSIZE * 1024; 500 traffic_sent += BLOCKSIZE * 1024;
501 GNUNET_MQ_notify_sent (env, &do_send, mq); 501 GNUNET_MQ_notify_sent (env, &do_send, mq);
502 if (verbosity > 0) 502 if (verbosity > 0)
503 FPRINTF (stdout, 503 fprintf (stdout,
504 _ ("Transmitting %u bytes\n"), 504 _ ("Transmitting %u bytes\n"),
505 (unsigned int) BLOCKSIZE * 1024); 505 (unsigned int) BLOCKSIZE * 1024);
506 GNUNET_MQ_send (mq, env); 506 GNUNET_MQ_send (mq, env);
@@ -531,7 +531,7 @@ notify_connect (void *cls,
531 op_timeout = NULL; 531 op_timeout = NULL;
532 } 532 }
533 if (verbosity > 0) 533 if (verbosity > 0)
534 FPRINTF ( 534 fprintf (
535 stdout, 535 stdout,
536 _ ( 536 _ (
537 "Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"), 537 "Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"),
@@ -562,7 +562,7 @@ notify_disconnect (void *cls,
562 return; /* not about target peer */ 562 return; /* not about target peer */
563 if (! benchmark_send) 563 if (! benchmark_send)
564 return; /* not transmitting */ 564 return; /* not transmitting */
565 FPRINTF (stdout, 565 fprintf (stdout,
566 _ ("Disconnected from peer `%s' while benchmarking\n"), 566 _ ("Disconnected from peer `%s' while benchmarking\n"),
567 GNUNET_i2s (&pid)); 567 GNUNET_i2s (&pid));
568} 568}
@@ -586,7 +586,7 @@ monitor_notify_connect (void *cls,
586 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now); 586 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
587 587
588 monitor_connect_counter++; 588 monitor_connect_counter++;
589 FPRINTF (stdout, 589 fprintf (stdout,
590 _ ("%24s: %-17s %4s (%u connections in total)\n"), 590 _ ("%24s: %-17s %4s (%u connections in total)\n"),
591 now_str, 591 now_str,
592 _ ("Connected to"), 592 _ ("Connected to"),
@@ -615,7 +615,7 @@ monitor_notify_disconnect (void *cls,
615 GNUNET_assert (monitor_connect_counter > 0); 615 GNUNET_assert (monitor_connect_counter > 0);
616 monitor_connect_counter--; 616 monitor_connect_counter--;
617 617
618 FPRINTF (stdout, 618 fprintf (stdout,
619 _ ("%24s: %-17s %4s (%u connections in total)\n"), 619 _ ("%24s: %-17s %4s (%u connections in total)\n"),
620 now_str, 620 now_str,
621 _ ("Disconnected from"), 621 _ ("Disconnected from"),
@@ -650,7 +650,7 @@ handle_dummy (void *cls, const struct GNUNET_MessageHeader *message)
650 if (! benchmark_receive) 650 if (! benchmark_receive)
651 return; 651 return;
652 if (verbosity > 0) 652 if (verbosity > 0)
653 FPRINTF (stdout, 653 fprintf (stdout,
654 _ ("Received %u bytes\n"), 654 _ ("Received %u bytes\n"),
655 (unsigned int) ntohs (message->size)); 655 (unsigned int) ntohs (message->size));
656 if (0 == traffic_received) 656 if (0 == traffic_received)
@@ -686,7 +686,7 @@ print_info (const struct GNUNET_PeerIdentity *id,
686 if (((GNUNET_YES == iterate_connections) && (GNUNET_YES == iterate_all)) || 686 if (((GNUNET_YES == iterate_connections) && (GNUNET_YES == iterate_all)) ||
687 (GNUNET_YES == monitor_connections)) 687 (GNUNET_YES == monitor_connections))
688 { 688 {
689 FPRINTF (stdout, 689 fprintf (stdout,
690 _ ("Peer `%s': %s %s in state `%s' until %s\n"), 690 _ ("Peer `%s': %s %s in state `%s' until %s\n"),
691 GNUNET_i2s (id), 691 GNUNET_i2s (id),
692 (NULL == transport) ? "<none>" : transport, 692 (NULL == transport) ? "<none>" : transport,
@@ -698,7 +698,7 @@ print_info (const struct GNUNET_PeerIdentity *id,
698 (GNUNET_TRANSPORT_is_connected (state))) 698 (GNUNET_TRANSPORT_is_connected (state)))
699 { 699 {
700 /* Only connected peers, skip state */ 700 /* Only connected peers, skip state */
701 FPRINTF (stdout, 701 fprintf (stdout,
702 _ ("Peer `%s': %s %s\n"), 702 _ ("Peer `%s': %s %s\n"),
703 GNUNET_i2s (id), 703 GNUNET_i2s (id),
704 transport, 704 transport,
@@ -732,7 +732,7 @@ process_peer_string (void *cls, const char *address, int res)
732 { 732 {
733 if (GNUNET_SYSERR == res) 733 if (GNUNET_SYSERR == res)
734 { 734 {
735 FPRINTF ( 735 fprintf (
736 stderr, 736 stderr,
737 "Failed to convert address for peer `%s' plugin `%s' length %u to string \n", 737 "Failed to convert address for peer `%s' plugin `%s' length %u to string \n",
738 GNUNET_i2s (&rc->addrcp->peer), 738 GNUNET_i2s (&rc->addrcp->peer),
@@ -1094,7 +1094,7 @@ process_peer_monitoring_cb (void *cls,
1094 1094
1095 if (NULL == peer) 1095 if (NULL == peer)
1096 { 1096 {
1097 FPRINTF (stdout, 1097 fprintf (stdout,
1098 "%s", 1098 "%s",
1099 _ ( 1099 _ (
1100 "Monitor disconnected from transport service. Reconnecting.\n")); 1100 "Monitor disconnected from transport service. Reconnecting.\n"));
@@ -1189,7 +1189,7 @@ run (void *cls,
1189 1189
1190 if (1 < counter) 1190 if (1 < counter)
1191 { 1191 {
1192 FPRINTF ( 1192 fprintf (
1193 stderr, 1193 stderr,
1194 _ ( 1194 _ (
1195 "Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s %s\n"), 1195 "Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s %s\n"),
@@ -1204,7 +1204,7 @@ run (void *cls,
1204 } 1204 }
1205 if (0 == counter) 1205 if (0 == counter)
1206 { 1206 {
1207 FPRINTF ( 1207 fprintf (
1208 stderr, 1208 stderr,
1209 _ ( 1209 _ (
1210 "No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s, %s\n"), 1210 "No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s, %s\n"),
@@ -1222,7 +1222,7 @@ run (void *cls,
1222 { 1222 {
1223 if (0 == memcmp (&zero_pid, &pid, sizeof (pid))) 1223 if (0 == memcmp (&zero_pid, &pid, sizeof (pid)))
1224 { 1224 {
1225 FPRINTF (stderr, 1225 fprintf (stderr,
1226 _ ("Option `%s' makes no sense without option `%s'.\n"), 1226 _ ("Option `%s' makes no sense without option `%s'.\n"),
1227 "-D", 1227 "-D",
1228 "-p"); 1228 "-p");
@@ -1232,14 +1232,14 @@ run (void *cls,
1232 blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_cb, NULL); 1232 blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_cb, NULL);
1233 if (NULL == blacklist) 1233 if (NULL == blacklist)
1234 { 1234 {
1235 FPRINTF (stderr, 1235 fprintf (stderr,
1236 "%s", 1236 "%s",
1237 _ ( 1237 _ (
1238 "Failed to connect to transport service for disconnection\n")); 1238 "Failed to connect to transport service for disconnection\n"));
1239 ret = 1; 1239 ret = 1;
1240 return; 1240 return;
1241 } 1241 }
1242 FPRINTF (stdout, 1242 fprintf (stdout,
1243 "%s", 1243 "%s",
1244 _ ("Blacklisting request in place, stop with CTRL-C\n")); 1244 _ ("Blacklisting request in place, stop with CTRL-C\n"));
1245 } 1245 }
@@ -1247,7 +1247,7 @@ run (void *cls,
1247 { 1247 {
1248 if (0 == memcmp (&zero_pid, &pid, sizeof (pid))) 1248 if (0 == memcmp (&zero_pid, &pid, sizeof (pid)))
1249 { 1249 {
1250 FPRINTF (stderr, 1250 fprintf (stderr,
1251 _ ("Option `%s' makes no sense without option `%s'.\n"), 1251 _ ("Option `%s' makes no sense without option `%s'.\n"),
1252 "-s", 1252 "-s",
1253 "-p"); 1253 "-p");
@@ -1263,7 +1263,7 @@ run (void *cls,
1263 NULL); 1263 NULL);
1264 if (NULL == handle) 1264 if (NULL == handle)
1265 { 1265 {
1266 FPRINTF (stderr, "%s", _ ("Failed to connect to transport service\n")); 1266 fprintf (stderr, "%s", _ ("Failed to connect to transport service\n"));
1267 ret = 1; 1267 ret = 1;
1268 return; 1268 return;
1269 } 1269 }
@@ -1289,12 +1289,12 @@ run (void *cls,
1289 NULL); 1289 NULL);
1290 if (NULL == handle) 1290 if (NULL == handle)
1291 { 1291 {
1292 FPRINTF (stderr, "%s", _ ("Failed to connect to transport service\n")); 1292 fprintf (stderr, "%s", _ ("Failed to connect to transport service\n"));
1293 ret = 1; 1293 ret = 1;
1294 return; 1294 return;
1295 } 1295 }
1296 if (verbosity > 0) 1296 if (verbosity > 0)
1297 FPRINTF (stdout, "%s", _ ("Starting to receive benchmark data\n")); 1297 fprintf (stdout, "%s", _ ("Starting to receive benchmark data\n"));
1298 start_time = GNUNET_TIME_absolute_get (); 1298 start_time = GNUNET_TIME_absolute_get ();
1299 } 1299 }
1300 else if (iterate_connections) /* -i: List information about peers once */ 1300 else if (iterate_connections) /* -i: List information about peers once */
@@ -1335,7 +1335,7 @@ run (void *cls,
1335 NULL); 1335 NULL);
1336 if (NULL == handle) 1336 if (NULL == handle)
1337 { 1337 {
1338 FPRINTF (stderr, "%s", _ ("Failed to connect to transport service\n")); 1338 fprintf (stderr, "%s", _ ("Failed to connect to transport service\n"));
1339 ret = 1; 1339 ret = 1;
1340 return; 1340 return;
1341 } 1341 }
diff --git a/src/transport/plugin_transport_smtp.c b/src/transport/plugin_transport_smtp.c
index 705c91b85..1c61f07d7 100644
--- a/src/transport/plugin_transport_smtp.c
+++ b/src/transport/plugin_transport_smtp.c
@@ -667,7 +667,7 @@ inittransport_smtp (struct GNUNET_CoreAPIForTransport * core)
667 stats->create (gettext_noop ("# bytes dropped by SMTP (outgoing)")); 667 stats->create (gettext_noop ("# bytes dropped by SMTP (outgoing)"));
668 } 668 }
669 GNUNET_GC_get_configuration_value_filename (core_api->cfg, "SMTP", "PIPE", &pipename); 669 GNUNET_GC_get_configuration_value_filename (core_api->cfg, "SMTP", "PIPE", &pipename);
670 UNLINK (pipename); 670 unlink (pipename);
671 if (0 != mkfifo (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH)) 671 if (0 != mkfifo (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH))
672 { 672 {
673 GNUNET_GE_LOG_STRERROR (ectx, 673 GNUNET_GE_LOG_STRERROR (ectx,
@@ -722,7 +722,7 @@ donetransport_smtp ()
722 } 722 }
723 GNUNET_mutex_destroy (lock); 723 GNUNET_mutex_destroy (lock);
724 lock = NULL; 724 lock = NULL;
725 UNLINK (pipename); 725 unlink (pipename);
726 GNUNET_free (pipename); 726 GNUNET_free (pipename);
727 pipename = NULL; 727 pipename = NULL;
728 GNUNET_free (email); 728 GNUNET_free (email);
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index a0dd80617..0ea0bf460 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -35,7 +35,7 @@
35#include "gnunet_transport_plugin.h" 35#include "gnunet_transport_plugin.h"
36#include "transport.h" 36#include "transport.h"
37 37
38#define LOG(kind,...) GNUNET_log_from (kind, "transport-tcp",__VA_ARGS__) 38#define LOG(kind, ...) GNUNET_log_from (kind, "transport-tcp", __VA_ARGS__)
39 39
40#define PLUGIN_NAME "tcp" 40#define PLUGIN_NAME "tcp"
41 41
@@ -86,7 +86,6 @@ void
86LEGACY_SERVICE_stop (struct LEGACY_SERVICE_Context *srv); 86LEGACY_SERVICE_stop (struct LEGACY_SERVICE_Context *srv);
87 87
88 88
89
90/** 89/**
91 * Function called to notify a client about the connection begin ready 90 * Function called to notify a client about the connection begin ready
92 * to queue more data. @a buf will be NULL and @a size zero if the 91 * to queue more data. @a buf will be NULL and @a size zero if the
@@ -97,10 +96,9 @@ LEGACY_SERVICE_stop (struct LEGACY_SERVICE_Context *srv);
97 * @param buf where the callee should write the message 96 * @param buf where the callee should write the message
98 * @return number of bytes written to @a buf 97 * @return number of bytes written to @a buf
99 */ 98 */
100typedef size_t 99typedef size_t (*GNUNET_CONNECTION_TransmitReadyNotify) (void *cls,
101(*GNUNET_CONNECTION_TransmitReadyNotify) (void *cls, 100 size_t size,
102 size_t size, 101 void *buf);
103 void *buf);
104 102
105/** 103/**
106 * Credentials for UNIX domain sockets. 104 * Credentials for UNIX domain sockets.
@@ -127,9 +125,9 @@ struct GNUNET_CONNECTION_Credentials
127 * @param client identification of the client; NULL 125 * @param client identification of the client; NULL
128 * for the last call when the server is destroyed 126 * for the last call when the server is destroyed
129 */ 127 */
130typedef void 128typedef void (*GNUNET_SERVER_DisconnectCallback) (
131(*GNUNET_SERVER_DisconnectCallback) (void *cls, 129 void *cls,
132 struct GNUNET_SERVER_Client *client); 130 struct GNUNET_SERVER_Client *client);
133 131
134 132
135/** 133/**
@@ -139,11 +137,9 @@ typedef void
139 * @param cls closure 137 * @param cls closure
140 * @param client identification of the client 138 * @param client identification of the client
141 */ 139 */
142typedef void 140typedef void (*GNUNET_SERVER_ConnectCallback) (
143(*GNUNET_SERVER_ConnectCallback) (void *cls, 141 void *cls,
144 struct GNUNET_SERVER_Client *client); 142 struct GNUNET_SERVER_Client *client);
145
146
147 143
148 144
149/** 145/**
@@ -156,13 +152,11 @@ typedef void
156 * @return GNUNET_YES to allow, GNUNET_NO to deny, GNUNET_SYSERR 152 * @return GNUNET_YES to allow, GNUNET_NO to deny, GNUNET_SYSERR
157 * for unknown address family (will be denied). 153 * for unknown address family (will be denied).
158 */ 154 */
159typedef int 155typedef int (*GNUNET_CONNECTION_AccessCheck) (
160(*GNUNET_CONNECTION_AccessCheck) (void *cls, 156 void *cls,
161 const struct 157 const struct GNUNET_CONNECTION_Credentials *ucred,
162 GNUNET_CONNECTION_Credentials * 158 const struct sockaddr *addr,
163 ucred, 159 socklen_t addrlen);
164 const struct sockaddr * addr,
165 socklen_t addrlen);
166 160
167/** 161/**
168 * Callback function for data received from the network. Note that 162 * Callback function for data received from the network. Note that
@@ -176,12 +170,12 @@ typedef int
176 * @param addrlen size of addr 170 * @param addrlen size of addr
177 * @param errCode value of errno (on errors receiving) 171 * @param errCode value of errno (on errors receiving)
178 */ 172 */
179typedef void 173typedef void (*GNUNET_CONNECTION_Receiver) (void *cls,
180(*GNUNET_CONNECTION_Receiver) (void *cls, const void *buf, 174 const void *buf,
181 size_t available, 175 size_t available,
182 const struct sockaddr * addr, 176 const struct sockaddr *addr,
183 socklen_t addrlen, int errCode); 177 socklen_t addrlen,
184 178 int errCode);
185 179
186 180
187/** 181/**
@@ -202,9 +196,9 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection);
202 * @param client handle to client the tokenzier will be used for 196 * @param client handle to client the tokenzier will be used for
203 * @return handle to custom tokenizer ('mst') 197 * @return handle to custom tokenizer ('mst')
204 */ 198 */
205typedef void* 199typedef void *(*GNUNET_SERVER_MstCreateCallback) (
206(*GNUNET_SERVER_MstCreateCallback) (void *cls, 200 void *cls,
207 struct GNUNET_SERVER_Client *client); 201 struct GNUNET_SERVER_Client *client);
208 202
209 203
210/** 204/**
@@ -213,9 +207,7 @@ typedef void*
213 * @param cls closure from #GNUNET_SERVER_set_callbacks 207 * @param cls closure from #GNUNET_SERVER_set_callbacks
214 * @param mst custom tokenizer handle 208 * @param mst custom tokenizer handle
215 */ 209 */
216typedef void 210typedef void (*GNUNET_SERVER_MstDestroyCallback) (void *cls, void *mst);
217(*GNUNET_SERVER_MstDestroyCallback) (void *cls,
218 void *mst);
219 211
220/** 212/**
221 * Signature of a function to receive data for a custom tokenizer. 213 * Signature of a function to receive data for a custom tokenizer.
@@ -233,13 +225,14 @@ typedef void
233 * #GNUNET_NO if one_shot was set and we have another message ready 225 * #GNUNET_NO if one_shot was set and we have another message ready
234 * #GNUNET_SYSERR if the data stream is corrupt 226 * #GNUNET_SYSERR if the data stream is corrupt
235 */ 227 */
236typedef int 228typedef int (*GNUNET_SERVER_MstReceiveCallback) (
237(*GNUNET_SERVER_MstReceiveCallback) (void *cls, void *mst, 229 void *cls,
238 struct GNUNET_SERVER_Client *client, 230 void *mst,
239 const char *buf, 231 struct GNUNET_SERVER_Client *client,
240 size_t size, 232 const char *buf,
241 int purge, 233 size_t size,
242 int one_shot); 234 int purge,
235 int one_shot);
243/** 236/**
244 * Functions with this signature are called whenever a message is 237 * Functions with this signature are called whenever a message is
245 * received. 238 * received.
@@ -248,10 +241,10 @@ typedef int
248 * @param client identification of the client 241 * @param client identification of the client
249 * @param message the actual message 242 * @param message the actual message
250 */ 243 */
251typedef void 244typedef void (*GNUNET_SERVER_MessageCallback) (
252(*GNUNET_SERVER_MessageCallback) (void *cls, 245 void *cls,
253 struct GNUNET_SERVER_Client *client, 246 struct GNUNET_SERVER_Client *client,
254 const struct GNUNET_MessageHeader *message); 247 const struct GNUNET_MessageHeader *message);
255 248
256/** 249/**
257 * Message handler. Each struct specifies how to handle on particular 250 * Message handler. Each struct specifies how to handle on particular
@@ -281,7 +274,6 @@ struct GNUNET_SERVER_MessageHandler
281 * if they do not have the right size. 274 * if they do not have the right size.
282 */ 275 */
283 uint16_t expected_size; 276 uint16_t expected_size;
284
285}; 277};
286 278
287 279
@@ -311,7 +303,6 @@ enum LEGACY_SERVICE_Options
311}; 303};
312 304
313 305
314
315/** 306/**
316 * Ask the server to disconnect from the given client. This is the 307 * Ask the server to disconnect from the given client. This is the
317 * same as passing #GNUNET_SYSERR to #GNUNET_SERVER_receive_done, 308 * same as passing #GNUNET_SYSERR to #GNUNET_SERVER_receive_done,
@@ -348,10 +339,10 @@ GNUNET_SERVER_client_get_user_context_ (struct GNUNET_SERVER_Client *client,
348 * @param message the actual message 339 * @param message the actual message
349 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing 340 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
350 */ 341 */
351typedef int 342typedef int (*GNUNET_SERVER_MessageTokenizerCallback) (
352(*GNUNET_SERVER_MessageTokenizerCallback) (void *cls, 343 void *cls,
353 void *client, 344 void *client,
354 const struct GNUNET_MessageHeader *message); 345 const struct GNUNET_MessageHeader *message);
355 346
356 347
357/** 348/**
@@ -384,9 +375,10 @@ GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb,
384int 375int
385GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst, 376GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
386 void *client_identity, 377 void *client_identity,
387 const char *buf, size_t size, 378 const char *buf,
388 int purge, int one_shot); 379 size_t size,
389 380 int purge,
381 int one_shot);
390 382
391 383
392/** 384/**
@@ -417,7 +409,7 @@ GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client,
417 * @param type expected return type (i.e. 'struct Foo') 409 * @param type expected return type (i.e. 'struct Foo')
418 * @return pointer to user context of type 'type *'. 410 * @return pointer to user context of type 'type *'.
419 */ 411 */
420#define GNUNET_SERVER_client_get_user_context(client,type) \ 412#define GNUNET_SERVER_client_get_user_context(client, type) \
421 (type *) GNUNET_SERVER_client_get_user_context_ (client, sizeof (type)) 413 (type *) GNUNET_SERVER_client_get_user_context_ (client, sizeof (type))
422 414
423/** 415/**
@@ -426,11 +418,10 @@ GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client,
426 * @param client client to query 418 * @param client client to query
427 * @param value pointer to user context 419 * @param value pointer to user context
428 */ 420 */
429#define GNUNET_SERVER_client_set_user_context(client,value) \ 421#define GNUNET_SERVER_client_set_user_context(client, value) \
430 GNUNET_SERVER_client_set_user_context_ (client, value, sizeof (*value)) 422 GNUNET_SERVER_client_set_user_context_ (client, value, sizeof (*value))
431 423
432 424
433
434/** 425/**
435 * Notify us when the server has enough space to transmit 426 * Notify us when the server has enough space to transmit
436 * a message of the given size to the given client. 427 * a message of the given size to the given client.
@@ -447,11 +438,12 @@ GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client,
447 * NULL if we are already going to notify someone else (busy) 438 * NULL if we are already going to notify someone else (busy)
448 */ 439 */
449struct GNUNET_SERVER_TransmitHandle * 440struct GNUNET_SERVER_TransmitHandle *
450GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client, 441GNUNET_SERVER_notify_transmit_ready (
451 size_t size, 442 struct GNUNET_SERVER_Client *client,
452 struct GNUNET_TIME_Relative timeout, 443 size_t size,
453 GNUNET_CONNECTION_TransmitReadyNotify callback, 444 struct GNUNET_TIME_Relative timeout,
454 void *callback_cls); 445 GNUNET_CONNECTION_TransmitReadyNotify callback,
446 void *callback_cls);
455 447
456/** 448/**
457 * Abort transmission request. 449 * Abort transmission request.
@@ -459,9 +451,8 @@ GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client,
459 * @param th request to abort 451 * @param th request to abort
460 */ 452 */
461void 453void
462GNUNET_SERVER_notify_transmit_ready_cancel (struct GNUNET_SERVER_TransmitHandle *th); 454GNUNET_SERVER_notify_transmit_ready_cancel (
463 455 struct GNUNET_SERVER_TransmitHandle *th);
464
465 456
466 457
467/** 458/**
@@ -495,11 +486,10 @@ GNUNET_SERVER_client_drop (struct GNUNET_SERVER_Client *client);
495 * @param server the initialized server 486 * @param server the initialized server
496 * @param cfg configuration to use 487 * @param cfg configuration to use
497 */ 488 */
498typedef void 489typedef void (*LEGACY_SERVICE_Main) (
499(*LEGACY_SERVICE_Main) (void *cls, 490 void *cls,
500 struct GNUNET_SERVER_Handle *server, 491 struct GNUNET_SERVER_Handle *server,
501 const struct GNUNET_CONFIGURATION_Handle *cfg); 492 const struct GNUNET_CONFIGURATION_Handle *cfg);
502
503 493
504 494
505/** 495/**
@@ -527,11 +517,12 @@ GNUNET_SERVER_suspend (struct GNUNET_SERVER_Handle *server);
527 * NULL if we are already going to notify someone else (busy) 517 * NULL if we are already going to notify someone else (busy)
528 */ 518 */
529struct GNUNET_SERVER_TransmitHandle * 519struct GNUNET_SERVER_TransmitHandle *
530GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client, 520GNUNET_SERVER_notify_transmit_ready (
531 size_t size, 521 struct GNUNET_SERVER_Client *client,
532 struct GNUNET_TIME_Relative timeout, 522 size_t size,
533 GNUNET_CONNECTION_TransmitReadyNotify callback, 523 struct GNUNET_TIME_Relative timeout,
534 void *callback_cls); 524 GNUNET_CONNECTION_TransmitReadyNotify callback,
525 void *callback_cls);
535 526
536 527
537/** 528/**
@@ -567,8 +558,6 @@ void
567GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *server); 558GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *server);
568 559
569 560
570
571
572#include "tcp_connection_legacy.c" 561#include "tcp_connection_legacy.c"
573#include "tcp_server_mst_legacy.c" 562#include "tcp_server_mst_legacy.c"
574#include "tcp_server_legacy.c" 563#include "tcp_server_legacy.c"
@@ -590,7 +579,6 @@ struct WelcomeMessage
590 * Identity of the node connecting (TCP client) 579 * Identity of the node connecting (TCP client)
591 */ 580 */
592 struct GNUNET_PeerIdentity clientIdentity; 581 struct GNUNET_PeerIdentity clientIdentity;
593
594}; 582};
595 583
596/** 584/**
@@ -608,7 +596,6 @@ struct TCP_NAT_ProbeMessage
608 * Identity of the sender of the message. 596 * Identity of the sender of the message.
609 */ 597 */
610 struct GNUNET_PeerIdentity clientIdentity; 598 struct GNUNET_PeerIdentity clientIdentity;
611
612}; 599};
613GNUNET_NETWORK_STRUCT_END 600GNUNET_NETWORK_STRUCT_END
614 601
@@ -693,7 +680,6 @@ struct IPv4TcpAddress
693 * Port number, in network byte order. 680 * Port number, in network byte order.
694 */ 681 */
695 uint16_t t4_port GNUNET_PACKED; 682 uint16_t t4_port GNUNET_PACKED;
696
697}; 683};
698 684
699/** 685/**
@@ -716,7 +702,6 @@ struct IPv6TcpAddress
716 * Port number, in network byte order. 702 * Port number, in network byte order.
717 */ 703 */
718 uint16_t t6_port GNUNET_PACKED; 704 uint16_t t6_port GNUNET_PACKED;
719
720}; 705};
721GNUNET_NETWORK_STRUCT_END 706GNUNET_NETWORK_STRUCT_END
722 707
@@ -770,7 +755,6 @@ struct PendingMessage
770 * instead of just a `struct GNUNET_MessageHeader`. 755 * instead of just a `struct GNUNET_MessageHeader`.
771 */ 756 */
772 size_t message_size; 757 size_t message_size;
773
774}; 758};
775 759
776/** 760/**
@@ -872,7 +856,6 @@ struct GNUNET_ATS_Session
872 * Was this session created using NAT traversal? 856 * Was this session created using NAT traversal?
873 */ 857 */
874 int is_nat; 858 int is_nat;
875
876}; 859};
877 860
878 861
@@ -1045,7 +1028,6 @@ struct Plugin
1045 * rest of the world. 1028 * rest of the world.
1046 */ 1029 */
1047 uint16_t adv_port; 1030 uint16_t adv_port;
1048
1049}; 1031};
1050 1032
1051 1033
@@ -1071,9 +1053,9 @@ struct Plugin
1071 */ 1053 */
1072static int 1054static int
1073get_server_addresses (const char *service_name, 1055get_server_addresses (const char *service_name,
1074 const struct GNUNET_CONFIGURATION_Handle *cfg, 1056 const struct GNUNET_CONFIGURATION_Handle *cfg,
1075 struct sockaddr ***addrs, 1057 struct sockaddr ***addrs,
1076 socklen_t ** addr_lens) 1058 socklen_t **addr_lens)
1077{ 1059{
1078 int disablev6; 1060 int disablev6;
1079 struct GNUNET_NETWORK_Handle *desc; 1061 struct GNUNET_NETWORK_Handle *desc;
@@ -1097,8 +1079,9 @@ get_server_addresses (const char *service_name,
1097 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "DISABLEV6")) 1079 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "DISABLEV6"))
1098 { 1080 {
1099 if (GNUNET_SYSERR == 1081 if (GNUNET_SYSERR ==
1100 (disablev6 = 1082 (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (cfg,
1101 GNUNET_CONFIGURATION_get_value_yesno (cfg, service_name, "DISABLEV6"))) 1083 service_name,
1084 "DISABLEV6")))
1102 return GNUNET_SYSERR; 1085 return GNUNET_SYSERR;
1103 } 1086 }
1104 else 1087 else
@@ -1117,8 +1100,10 @@ get_server_addresses (const char *service_name,
1117 return GNUNET_SYSERR; 1100 return GNUNET_SYSERR;
1118 } 1101 }
1119 LOG (GNUNET_ERROR_TYPE_INFO, 1102 LOG (GNUNET_ERROR_TYPE_INFO,
1120 _("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), 1103 _ (
1121 service_name, STRERROR (errno)); 1104 "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
1105 service_name,
1106 strerror (errno));
1122 disablev6 = GNUNET_YES; 1107 disablev6 = GNUNET_YES;
1123 } 1108 }
1124 else 1109 else
@@ -1131,18 +1116,19 @@ get_server_addresses (const char *service_name,
1131 port = 0; 1116 port = 0;
1132 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT")) 1117 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT"))
1133 { 1118 {
1134 if (GNUNET_OK != 1119 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
1135 GNUNET_CONFIGURATION_get_value_number (cfg, service_name, 1120 service_name,
1136 "PORT", &port)) 1121 "PORT",
1122 &port))
1137 { 1123 {
1138 LOG (GNUNET_ERROR_TYPE_ERROR, 1124 LOG (GNUNET_ERROR_TYPE_ERROR,
1139 _("Require valid port number for service `%s' in configuration!\n"), 1125 _ ("Require valid port number for service `%s' in configuration!\n"),
1140 service_name); 1126 service_name);
1141 } 1127 }
1142 if (port > 65535) 1128 if (port > 65535)
1143 { 1129 {
1144 LOG (GNUNET_ERROR_TYPE_ERROR, 1130 LOG (GNUNET_ERROR_TYPE_ERROR,
1145 _("Require valid port number for service `%s' in configuration!\n"), 1131 _ ("Require valid port number for service `%s' in configuration!\n"),
1146 service_name); 1132 service_name);
1147 return GNUNET_SYSERR; 1133 return GNUNET_SYSERR;
1148 } 1134 }
@@ -1151,8 +1137,10 @@ get_server_addresses (const char *service_name,
1151 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO")) 1137 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO"))
1152 { 1138 {
1153 GNUNET_break (GNUNET_OK == 1139 GNUNET_break (GNUNET_OK ==
1154 GNUNET_CONFIGURATION_get_value_string (cfg, service_name, 1140 GNUNET_CONFIGURATION_get_value_string (cfg,
1155 "BINDTO", &hostname)); 1141 service_name,
1142 "BINDTO",
1143 &hostname));
1156 } 1144 }
1157 else 1145 else
1158 hostname = NULL; 1146 hostname = NULL;
@@ -1162,9 +1150,10 @@ get_server_addresses (const char *service_name,
1162#ifdef AF_UNIX 1150#ifdef AF_UNIX
1163 if ((GNUNET_YES == 1151 if ((GNUNET_YES ==
1164 GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) && 1152 GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) &&
1165 (GNUNET_OK == 1153 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg,
1166 GNUNET_CONFIGURATION_get_value_filename (cfg, service_name, "UNIXPATH", 1154 service_name,
1167 &unixpath)) && 1155 "UNIXPATH",
1156 &unixpath)) &&
1168 (0 < strlen (unixpath))) 1157 (0 < strlen (unixpath)))
1169 { 1158 {
1170 /* probe UNIX support */ 1159 /* probe UNIX support */
@@ -1173,12 +1162,11 @@ get_server_addresses (const char *service_name,
1173 if (strlen (unixpath) >= sizeof (s_un.sun_path)) 1162 if (strlen (unixpath) >= sizeof (s_un.sun_path))
1174 { 1163 {
1175 LOG (GNUNET_ERROR_TYPE_WARNING, 1164 LOG (GNUNET_ERROR_TYPE_WARNING,
1176 _("UNIXPATH `%s' too long, maximum length is %llu\n"), unixpath, 1165 _ ("UNIXPATH `%s' too long, maximum length is %llu\n"),
1166 unixpath,
1177 (unsigned long long) sizeof (s_un.sun_path)); 1167 (unsigned long long) sizeof (s_un.sun_path));
1178 unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath); 1168 unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath);
1179 LOG (GNUNET_ERROR_TYPE_INFO, 1169 LOG (GNUNET_ERROR_TYPE_INFO, _ ("Using `%s' instead\n"), unixpath);
1180 _("Using `%s' instead\n"),
1181 unixpath);
1182 } 1170 }
1183#ifdef LINUX 1171#ifdef LINUX
1184 abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1172 abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
@@ -1187,12 +1175,9 @@ get_server_addresses (const char *service_name,
1187 if (GNUNET_SYSERR == abstract) 1175 if (GNUNET_SYSERR == abstract)
1188 abstract = GNUNET_NO; 1176 abstract = GNUNET_NO;
1189#endif 1177#endif
1190 if ((GNUNET_YES != abstract) 1178 if ((GNUNET_YES != abstract) &&
1191 && (GNUNET_OK != 1179 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (unixpath)))
1192 GNUNET_DISK_directory_create_for_file (unixpath))) 1180 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath);
1193 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
1194 "mkdir",
1195 unixpath);
1196 } 1181 }
1197 if (NULL != unixpath) 1182 if (NULL != unixpath)
1198 { 1183 {
@@ -1208,9 +1193,10 @@ get_server_addresses (const char *service_name,
1208 return GNUNET_SYSERR; 1193 return GNUNET_SYSERR;
1209 } 1194 }
1210 LOG (GNUNET_ERROR_TYPE_INFO, 1195 LOG (GNUNET_ERROR_TYPE_INFO,
1211 _("Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), 1196 _ (
1197 "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
1212 service_name, 1198 service_name,
1213 STRERROR (errno)); 1199 strerror (errno));
1214 GNUNET_free (unixpath); 1200 GNUNET_free (unixpath);
1215 unixpath = NULL; 1201 unixpath = NULL;
1216 } 1202 }
@@ -1225,7 +1211,8 @@ get_server_addresses (const char *service_name,
1225 if ((0 == port) && (NULL == unixpath)) 1211 if ((0 == port) && (NULL == unixpath))
1226 { 1212 {
1227 LOG (GNUNET_ERROR_TYPE_ERROR, 1213 LOG (GNUNET_ERROR_TYPE_ERROR,
1228 _("Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), 1214 _ (
1215 "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
1229 service_name); 1216 service_name);
1230 GNUNET_free_non_null (hostname); 1217 GNUNET_free_non_null (hostname);
1231 return GNUNET_SYSERR; 1218 return GNUNET_SYSERR;
@@ -1256,7 +1243,7 @@ get_server_addresses (const char *service_name,
1256 (NULL == res)) 1243 (NULL == res))
1257 { 1244 {
1258 LOG (GNUNET_ERROR_TYPE_ERROR, 1245 LOG (GNUNET_ERROR_TYPE_ERROR,
1259 _("Failed to resolve `%s': %s\n"), 1246 _ ("Failed to resolve `%s': %s\n"),
1260 hostname, 1247 hostname,
1261 gai_strerror (ret)); 1248 gai_strerror (ret));
1262 GNUNET_free (hostname); 1249 GNUNET_free (hostname);
@@ -1275,7 +1262,7 @@ get_server_addresses (const char *service_name,
1275 if (0 == i) 1262 if (0 == i)
1276 { 1263 {
1277 LOG (GNUNET_ERROR_TYPE_ERROR, 1264 LOG (GNUNET_ERROR_TYPE_ERROR,
1278 _("Failed to find %saddress for `%s'.\n"), 1265 _ ("Failed to find %saddress for `%s'.\n"),
1279 disablev6 ? "IPv4 " : "", 1266 disablev6 ? "IPv4 " : "",
1280 hostname); 1267 hostname);
1281 freeaddrinfo (res); 1268 freeaddrinfo (res);
@@ -1301,11 +1288,13 @@ get_server_addresses (const char *service_name,
1301 if ((disablev6) && (AF_INET6 == pos->ai_family)) 1288 if ((disablev6) && (AF_INET6 == pos->ai_family))
1302 continue; 1289 continue;
1303 if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol)) 1290 if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol))
1304 continue; /* not TCP */ 1291 continue; /* not TCP */
1305 if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype)) 1292 if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype))
1306 continue; /* huh? */ 1293 continue; /* huh? */
1307 LOG (GNUNET_ERROR_TYPE_DEBUG, "Service `%s' will bind to `%s'\n", 1294 LOG (GNUNET_ERROR_TYPE_DEBUG,
1308 service_name, GNUNET_a2s (pos->ai_addr, pos->ai_addrlen)); 1295 "Service `%s' will bind to `%s'\n",
1296 service_name,
1297 GNUNET_a2s (pos->ai_addr, pos->ai_addrlen));
1309 if (AF_INET == pos->ai_family) 1298 if (AF_INET == pos->ai_family)
1310 { 1299 {
1311 GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen); 1300 GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen);
@@ -1412,17 +1401,16 @@ notify_session_monitor (struct Plugin *plugin,
1412 return; 1401 return;
1413 memset (&info, 0, sizeof (info)); 1402 memset (&info, 0, sizeof (info));
1414 info.state = state; 1403 info.state = state;
1415 info.is_inbound = GNUNET_HELLO_address_check_option (session->address, 1404 info.is_inbound =
1416 GNUNET_HELLO_ADDRESS_INFO_INBOUND); 1405 GNUNET_HELLO_address_check_option (session->address,
1406 GNUNET_HELLO_ADDRESS_INFO_INBOUND);
1417 info.num_msg_pending = session->msgs_in_queue; 1407 info.num_msg_pending = session->msgs_in_queue;
1418 info.num_bytes_pending = session->bytes_in_queue; 1408 info.num_bytes_pending = session->bytes_in_queue;
1419 if (NULL != session->receive_delay_task) 1409 if (NULL != session->receive_delay_task)
1420 info.receive_delay = session->receive_delay; 1410 info.receive_delay = session->receive_delay;
1421 info.session_timeout = session->timeout; 1411 info.session_timeout = session->timeout;
1422 info.address = session->address; 1412 info.address = session->address;
1423 plugin->sic (plugin->sic_cls, 1413 plugin->sic (plugin->sic_cls, session, &info);
1424 session,
1425 &info);
1426} 1414}
1427 1415
1428 1416
@@ -1440,10 +1428,10 @@ notify_session_monitor (struct Plugin *plugin,
1440 */ 1428 */
1441static void 1429static void
1442tcp_nat_port_map_callback (void *cls, 1430tcp_nat_port_map_callback (void *cls,
1443 void **app_ctx, 1431 void **app_ctx,
1444 int add_remove, 1432 int add_remove,
1445 enum GNUNET_NAT_AddressClass ac, 1433 enum GNUNET_NAT_AddressClass ac,
1446 const struct sockaddr *addr, 1434 const struct sockaddr *addr,
1447 socklen_t addrlen) 1435 socklen_t addrlen)
1448{ 1436{
1449 struct Plugin *plugin = cls; 1437 struct Plugin *plugin = cls;
@@ -1462,8 +1450,8 @@ tcp_nat_port_map_callback (void *cls,
1462 switch (addr->sa_family) 1450 switch (addr->sa_family)
1463 { 1451 {
1464 case AF_INET: 1452 case AF_INET:
1465 GNUNET_assert(addrlen == sizeof(struct sockaddr_in)); 1453 GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
1466 memset (&t4, 0, sizeof(t4)); 1454 memset (&t4, 0, sizeof (t4));
1467 t4.options = htonl (plugin->myoptions); 1455 t4.options = htonl (plugin->myoptions);
1468 t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; 1456 t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
1469 t4.t4_port = ((struct sockaddr_in *) addr)->sin_port; 1457 t4.t4_port = ((struct sockaddr_in *) addr)->sin_port;
@@ -1477,32 +1465,30 @@ tcp_nat_port_map_callback (void *cls,
1477 #tcp_plugin_check_address() */ 1465 #tcp_plugin_check_address() */
1478 return; 1466 return;
1479 } 1467 }
1480 GNUNET_assert(addrlen == sizeof(struct sockaddr_in6)); 1468 GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
1481 memset (&t6, 0, sizeof(t6)); 1469 memset (&t6, 0, sizeof (t6));
1482 GNUNET_memcpy (&t6.ipv6_addr, 1470 GNUNET_memcpy (&t6.ipv6_addr,
1483 &((struct sockaddr_in6 *) addr)->sin6_addr, 1471 &((struct sockaddr_in6 *) addr)->sin6_addr,
1484 sizeof(struct in6_addr)); 1472 sizeof (struct in6_addr));
1485 t6.options = htonl (plugin->myoptions); 1473 t6.options = htonl (plugin->myoptions);
1486 t6.t6_port = ((struct sockaddr_in6 *) addr)->sin6_port; 1474 t6.t6_port = ((struct sockaddr_in6 *) addr)->sin6_port;
1487 arg = &t6; 1475 arg = &t6;
1488 args = sizeof (t6); 1476 args = sizeof (t6);
1489 break; 1477 break;
1490 default: 1478 default:
1491 GNUNET_break(0); 1479 GNUNET_break (0);
1492 return; 1480 return;
1493 } 1481 }
1494 /* modify our published address list */ 1482 /* modify our published address list */
1495 GNUNET_assert ((args == sizeof (struct IPv4TcpAddress)) || 1483 GNUNET_assert ((args == sizeof (struct IPv4TcpAddress)) ||
1496 (args == sizeof (struct IPv6TcpAddress))); 1484 (args == sizeof (struct IPv6TcpAddress)));
1497 /* TODO: use 'ac' here in the future... */ 1485 /* TODO: use 'ac' here in the future... */
1498 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, 1486 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
1499 PLUGIN_NAME, 1487 PLUGIN_NAME,
1500 arg, 1488 arg,
1501 args, 1489 args,
1502 GNUNET_HELLO_ADDRESS_INFO_NONE); 1490 GNUNET_HELLO_ADDRESS_INFO_NONE);
1503 plugin->env->notify_address (plugin->env->cls, 1491 plugin->env->notify_address (plugin->env->cls, add_remove, address);
1504 add_remove,
1505 address);
1506 GNUNET_HELLO_address_free (address); 1492 GNUNET_HELLO_address_free (address);
1507} 1493}
1508 1494
@@ -1519,9 +1505,7 @@ tcp_nat_port_map_callback (void *cls,
1519 * @return string representing the same address 1505 * @return string representing the same address
1520 */ 1506 */
1521static const char * 1507static const char *
1522tcp_plugin_address_to_string (void *cls, 1508tcp_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
1523 const void *addr,
1524 size_t addrlen)
1525{ 1509{
1526 static char rbuf[INET6_ADDRSTRLEN + 12]; 1510 static char rbuf[INET6_ADDRSTRLEN + 12];
1527 char buf[INET6_ADDRSTRLEN]; 1511 char buf[INET6_ADDRSTRLEN];
@@ -1536,35 +1520,35 @@ tcp_plugin_address_to_string (void *cls,
1536 1520
1537 switch (addrlen) 1521 switch (addrlen)
1538 { 1522 {
1539 case sizeof(struct IPv6TcpAddress): 1523 case sizeof (struct IPv6TcpAddress):
1540 t6 = addr; 1524 t6 = addr;
1541 af = AF_INET6; 1525 af = AF_INET6;
1542 port = ntohs (t6->t6_port); 1526 port = ntohs (t6->t6_port);
1543 options = ntohl (t6->options); 1527 options = ntohl (t6->options);
1544 GNUNET_memcpy (&a6, &t6->ipv6_addr, sizeof(a6)); 1528 GNUNET_memcpy (&a6, &t6->ipv6_addr, sizeof (a6));
1545 sb = &a6; 1529 sb = &a6;
1546 break; 1530 break;
1547 case sizeof(struct IPv4TcpAddress): 1531 case sizeof (struct IPv4TcpAddress):
1548 t4 = addr; 1532 t4 = addr;
1549 af = AF_INET; 1533 af = AF_INET;
1550 port = ntohs (t4->t4_port); 1534 port = ntohs (t4->t4_port);
1551 options = ntohl (t4->options); 1535 options = ntohl (t4->options);
1552 GNUNET_memcpy (&a4, &t4->ipv4_addr, sizeof(a4)); 1536 GNUNET_memcpy (&a4, &t4->ipv4_addr, sizeof (a4));
1553 sb = &a4; 1537 sb = &a4;
1554 break; 1538 break;
1555 default: 1539 default:
1556 LOG (GNUNET_ERROR_TYPE_WARNING, 1540 LOG (GNUNET_ERROR_TYPE_WARNING,
1557 _("Unexpected address length: %u bytes\n"), 1541 _ ("Unexpected address length: %u bytes\n"),
1558 (unsigned int) addrlen); 1542 (unsigned int) addrlen);
1559 return NULL ; 1543 return NULL;
1560 } 1544 }
1561 if (NULL == inet_ntop (af, sb, buf, INET6_ADDRSTRLEN)) 1545 if (NULL == inet_ntop (af, sb, buf, INET6_ADDRSTRLEN))
1562 { 1546 {
1563 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 1547 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
1564 "inet_ntop"); 1548 return NULL;
1565 return NULL ;
1566 } 1549 }
1567 GNUNET_snprintf (rbuf, sizeof(rbuf), 1550 GNUNET_snprintf (rbuf,
1551 sizeof (rbuf),
1568 (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", 1552 (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u",
1569 PLUGIN_NAME, 1553 PLUGIN_NAME,
1570 options, 1554 options,
@@ -1605,25 +1589,25 @@ tcp_plugin_string_to_address (void *cls,
1605 optionstr = NULL; 1589 optionstr = NULL;
1606 if ((NULL == addr) || (0 == addrlen)) 1590 if ((NULL == addr) || (0 == addrlen))
1607 { 1591 {
1608 GNUNET_break(0); 1592 GNUNET_break (0);
1609 return GNUNET_SYSERR; 1593 return GNUNET_SYSERR;
1610 } 1594 }
1611 if ('\0' != addr[addrlen - 1]) 1595 if ('\0' != addr[addrlen - 1])
1612 { 1596 {
1613 GNUNET_break(0); 1597 GNUNET_break (0);
1614 return GNUNET_SYSERR; 1598 return GNUNET_SYSERR;
1615 } 1599 }
1616 if (strlen (addr) != addrlen - 1) 1600 if (strlen (addr) != addrlen - 1)
1617 { 1601 {
1618 GNUNET_break(0); 1602 GNUNET_break (0);
1619 return GNUNET_SYSERR; 1603 return GNUNET_SYSERR;
1620 } 1604 }
1621 plugin = GNUNET_strdup (addr); 1605 plugin = GNUNET_strdup (addr);
1622 optionstr = strchr (plugin, '.'); 1606 optionstr = strchr (plugin, '.');
1623 if (NULL == optionstr) 1607 if (NULL == optionstr)
1624 { 1608 {
1625 GNUNET_break(0); 1609 GNUNET_break (0);
1626 GNUNET_free(plugin); 1610 GNUNET_free (plugin);
1627 return GNUNET_SYSERR; 1611 return GNUNET_SYSERR;
1628 } 1612 }
1629 optionstr[0] = '\0'; 1613 optionstr[0] = '\0';
@@ -1632,28 +1616,25 @@ tcp_plugin_string_to_address (void *cls,
1632 address = strchr (optionstr, '.'); 1616 address = strchr (optionstr, '.');
1633 if (NULL == address) 1617 if (NULL == address)
1634 { 1618 {
1635 GNUNET_break(0); 1619 GNUNET_break (0);
1636 GNUNET_free(plugin); 1620 GNUNET_free (plugin);
1637 return GNUNET_SYSERR; 1621 return GNUNET_SYSERR;
1638 } 1622 }
1639 address[0] = '\0'; 1623 address[0] = '\0';
1640 address++; 1624 address++;
1641 1625
1642 if (GNUNET_OK != 1626 if (GNUNET_OK !=
1643 GNUNET_STRINGS_to_address_ip (address, 1627 GNUNET_STRINGS_to_address_ip (address, strlen (address), &socket_address))
1644 strlen (address),
1645 &socket_address))
1646 { 1628 {
1647 GNUNET_break(0); 1629 GNUNET_break (0);
1648 GNUNET_free(plugin); 1630 GNUNET_free (plugin);
1649 return GNUNET_SYSERR; 1631 return GNUNET_SYSERR;
1650 } 1632 }
1651 1633
1652 GNUNET_free(plugin); 1634 GNUNET_free (plugin);
1653 switch (socket_address.ss_family) 1635 switch (socket_address.ss_family)
1654 { 1636 {
1655 case AF_INET: 1637 case AF_INET: {
1656 {
1657 struct IPv4TcpAddress *t4; 1638 struct IPv4TcpAddress *t4;
1658 struct sockaddr_in *in4 = (struct sockaddr_in *) &socket_address; 1639 struct sockaddr_in *in4 = (struct sockaddr_in *) &socket_address;
1659 t4 = GNUNET_new (struct IPv4TcpAddress); 1640 t4 = GNUNET_new (struct IPv4TcpAddress);
@@ -1661,11 +1642,10 @@ tcp_plugin_string_to_address (void *cls,
1661 t4->ipv4_addr = in4->sin_addr.s_addr; 1642 t4->ipv4_addr = in4->sin_addr.s_addr;
1662 t4->t4_port = in4->sin_port; 1643 t4->t4_port = in4->sin_port;
1663 *buf = t4; 1644 *buf = t4;
1664 *added = sizeof(struct IPv4TcpAddress); 1645 *added = sizeof (struct IPv4TcpAddress);
1665 return GNUNET_OK; 1646 return GNUNET_OK;
1666 } 1647 }
1667 case AF_INET6: 1648 case AF_INET6: {
1668 {
1669 struct IPv6TcpAddress *t6; 1649 struct IPv6TcpAddress *t6;
1670 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &socket_address; 1650 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &socket_address;
1671 t6 = GNUNET_new (struct IPv6TcpAddress); 1651 t6 = GNUNET_new (struct IPv6TcpAddress);
@@ -1673,7 +1653,7 @@ tcp_plugin_string_to_address (void *cls,
1673 t6->ipv6_addr = in6->sin6_addr; 1653 t6->ipv6_addr = in6->sin6_addr;
1674 t6->t6_port = in6->sin6_port; 1654 t6->t6_port = in6->sin6_port;
1675 *buf = t6; 1655 *buf = t6;
1676 *added = sizeof(struct IPv6TcpAddress); 1656 *added = sizeof (struct IPv6TcpAddress);
1677 return GNUNET_OK; 1657 return GNUNET_OK;
1678 } 1658 }
1679 default: 1659 default:
@@ -1711,8 +1691,7 @@ lookup_session_by_client (struct Plugin *plugin,
1711 * @return #GNUNET_OK on success 1691 * @return #GNUNET_OK on success
1712 */ 1692 */
1713static int 1693static int
1714tcp_plugin_disconnect_session (void *cls, 1694tcp_plugin_disconnect_session (void *cls, struct GNUNET_ATS_Session *session)
1715 struct GNUNET_ATS_Session *session)
1716{ 1695{
1717 struct Plugin *plugin = cls; 1696 struct Plugin *plugin = cls;
1718 struct PendingMessage *pm; 1697 struct PendingMessage *pm;
@@ -1731,26 +1710,24 @@ tcp_plugin_disconnect_session (void *cls,
1731 session->timeout = GNUNET_TIME_UNIT_ZERO_ABS; 1710 session->timeout = GNUNET_TIME_UNIT_ZERO_ABS;
1732 } 1711 }
1733 1712
1734 if (GNUNET_YES == 1713 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (plugin->sessionmap,
1735 GNUNET_CONTAINER_multipeermap_remove (plugin->sessionmap, 1714 &session->target,
1736 &session->target, 1715 session))
1737 session))
1738 { 1716 {
1739 GNUNET_STATISTICS_update (session->plugin->env->stats, 1717 GNUNET_STATISTICS_update (session->plugin->env->stats,
1740 gettext_noop ("# TCP sessions active"), 1718 gettext_noop ("# TCP sessions active"),
1741 -1, 1719 -1,
1742 GNUNET_NO); 1720 GNUNET_NO);
1743 } 1721 }
1744 else 1722 else
1745 { 1723 {
1746 GNUNET_assert (GNUNET_YES == 1724 GNUNET_assert (GNUNET_YES ==
1747 GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns, 1725 GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns,
1748 &session->target, 1726 &session->target,
1749 session)); 1727 session));
1750 } 1728 }
1751 if (NULL != session->client) 1729 if (NULL != session->client)
1752 GNUNET_SERVER_client_set_user_context (session->client, 1730 GNUNET_SERVER_client_set_user_context (session->client, NULL);
1753 NULL);
1754 1731
1755 /* clean up state */ 1732 /* clean up state */
1756 if (NULL != session->transmit_handle) 1733 if (NULL != session->transmit_handle)
@@ -1772,17 +1749,19 @@ tcp_plugin_disconnect_session (void *cls,
1772 { 1749 {
1773 LOG (GNUNET_ERROR_TYPE_DEBUG, 1750 LOG (GNUNET_ERROR_TYPE_DEBUG,
1774 (NULL != pm->transmit_cont) 1751 (NULL != pm->transmit_cont)
1775 ? "Could not deliver message to `%s' at %s.\n" 1752 ? "Could not deliver message to `%s' at %s.\n"
1776 : "Could not deliver message to `%s' at %s, notifying.\n", 1753 : "Could not deliver message to `%s' at %s, notifying.\n",
1777 GNUNET_i2s (&session->target), 1754 GNUNET_i2s (&session->target),
1778 tcp_plugin_address_to_string (session->plugin, 1755 tcp_plugin_address_to_string (session->plugin,
1779 session->address->address, 1756 session->address->address,
1780 session->address->address_length)); 1757 session->address->address_length));
1781 GNUNET_STATISTICS_update (session->plugin->env->stats, 1758 GNUNET_STATISTICS_update (session->plugin->env->stats,
1782 gettext_noop ("# bytes currently in TCP buffers"), 1759 gettext_noop ("# bytes currently in TCP buffers"),
1783 -(int64_t) pm->message_size, GNUNET_NO); 1760 -(int64_t) pm->message_size,
1761 GNUNET_NO);
1784 GNUNET_STATISTICS_update (session->plugin->env->stats, 1762 GNUNET_STATISTICS_update (session->plugin->env->stats,
1785 gettext_noop ("# bytes discarded by TCP (disconnect)"), 1763 gettext_noop (
1764 "# bytes discarded by TCP (disconnect)"),
1786 pm->message_size, 1765 pm->message_size,
1787 GNUNET_NO); 1766 GNUNET_NO);
1788 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, 1767 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
@@ -1802,9 +1781,7 @@ tcp_plugin_disconnect_session (void *cls,
1802 } 1781 }
1803 GNUNET_assert (0 == session->msgs_in_queue); 1782 GNUNET_assert (0 == session->msgs_in_queue);
1804 GNUNET_assert (0 == session->bytes_in_queue); 1783 GNUNET_assert (0 == session->bytes_in_queue);
1805 notify_session_monitor (session->plugin, 1784 notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_DONE);
1806 session,
1807 GNUNET_TRANSPORT_SS_DONE);
1808 1785
1809 if (NULL != session->receive_delay_task) 1786 if (NULL != session->receive_delay_task)
1810 { 1787 {
@@ -1855,22 +1832,18 @@ session_timeout (void *cls)
1855 { 1832 {
1856 /* not actually our turn yet, but let's at least update 1833 /* not actually our turn yet, but let's at least update
1857 the monitor, it may think we're about to die ... */ 1834 the monitor, it may think we're about to die ... */
1858 notify_session_monitor (s->plugin, 1835 notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE);
1859 s, 1836 s->timeout_task = GNUNET_SCHEDULER_add_delayed (left, &session_timeout, s);
1860 GNUNET_TRANSPORT_SS_UPDATE);
1861 s->timeout_task = GNUNET_SCHEDULER_add_delayed (left,
1862 &session_timeout,
1863 s);
1864 return; 1837 return;
1865 } 1838 }
1866 LOG (GNUNET_ERROR_TYPE_DEBUG, 1839 LOG (GNUNET_ERROR_TYPE_DEBUG,
1867 "Session %p was idle for %s, disconnecting\n", 1840 "Session %p was idle for %s, disconnecting\n",
1868 s, 1841 s,
1869 GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1842 GNUNET_STRINGS_relative_time_to_string (
1870 GNUNET_YES)); 1843 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1844 GNUNET_YES));
1871 /* call session destroy function */ 1845 /* call session destroy function */
1872 tcp_plugin_disconnect_session (s->plugin, 1846 tcp_plugin_disconnect_session (s->plugin, s);
1873 s);
1874} 1847}
1875 1848
1876 1849
@@ -1883,7 +1856,8 @@ static void
1883reschedule_session_timeout (struct GNUNET_ATS_Session *s) 1856reschedule_session_timeout (struct GNUNET_ATS_Session *s)
1884{ 1857{
1885 GNUNET_assert (NULL != s->timeout_task); 1858 GNUNET_assert (NULL != s->timeout_task);
1886 s->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 1859 s->timeout =
1860 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1887} 1861}
1888 1862
1889 1863
@@ -1927,46 +1901,41 @@ create_session (struct Plugin *plugin,
1927 if (NULL != client) 1901 if (NULL != client)
1928 { 1902 {
1929 session->client = client; 1903 session->client = client;
1930 GNUNET_SERVER_client_set_user_context (client, 1904 GNUNET_SERVER_client_set_user_context (client, session);
1931 session);
1932 } 1905 }
1933 session->address = GNUNET_HELLO_address_copy (address); 1906 session->address = GNUNET_HELLO_address_copy (address);
1934 session->target = address->peer; 1907 session->target = address->peer;
1935 session->expecting_welcome = GNUNET_YES; 1908 session->expecting_welcome = GNUNET_YES;
1936 session->scope = scope; 1909 session->scope = scope;
1937 pm = GNUNET_malloc (sizeof (struct PendingMessage) + 1910 pm = GNUNET_malloc (sizeof (struct PendingMessage) +
1938 sizeof (struct WelcomeMessage)); 1911 sizeof (struct WelcomeMessage));
1939 pm->msg = (const char *) &pm[1]; 1912 pm->msg = (const char *) &pm[1];
1940 pm->message_size = sizeof(struct WelcomeMessage); 1913 pm->message_size = sizeof (struct WelcomeMessage);
1941 GNUNET_memcpy (&pm[1], 1914 GNUNET_memcpy (&pm[1], &plugin->my_welcome, sizeof (struct WelcomeMessage));
1942 &plugin->my_welcome,
1943 sizeof(struct WelcomeMessage));
1944 pm->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; 1915 pm->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
1945 GNUNET_STATISTICS_update (plugin->env->stats, 1916 GNUNET_STATISTICS_update (plugin->env->stats,
1946 gettext_noop ("# bytes currently in TCP buffers"), 1917 gettext_noop ("# bytes currently in TCP buffers"),
1947 pm->message_size, 1918 pm->message_size,
1948 GNUNET_NO); 1919 GNUNET_NO);
1949 GNUNET_CONTAINER_DLL_insert (session->pending_messages_head, 1920 GNUNET_CONTAINER_DLL_insert (session->pending_messages_head,
1950 session->pending_messages_tail, 1921 session->pending_messages_tail,
1951 pm); 1922 pm);
1952 session->msgs_in_queue++; 1923 session->msgs_in_queue++;
1953 session->bytes_in_queue += pm->message_size; 1924 session->bytes_in_queue += pm->message_size;
1954 session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 1925 session->timeout =
1955 session->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1926 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1956 &session_timeout, 1927 session->timeout_task =
1957 session); 1928 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1958 notify_session_monitor (session->plugin, 1929 &session_timeout,
1959 session, 1930 session);
1960 GNUNET_TRANSPORT_SS_INIT); 1931 notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_INIT);
1961 if (GNUNET_YES != is_nat) 1932 if (GNUNET_YES != is_nat)
1962 { 1933 {
1963 GNUNET_STATISTICS_update (plugin->env->stats, 1934 GNUNET_STATISTICS_update (plugin->env->stats,
1964 gettext_noop ("# TCP sessions active"), 1935 gettext_noop ("# TCP sessions active"),
1965 1, 1936 1,
1966 GNUNET_NO); 1937 GNUNET_NO);
1967 notify_session_monitor (session->plugin, 1938 notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_UP);
1968 session,
1969 GNUNET_TRANSPORT_SS_UP);
1970 } 1939 }
1971 else 1940 else
1972 { 1941 {
@@ -2000,9 +1969,7 @@ process_pending_messages (struct GNUNET_ATS_Session *session);
2000 * @return number of bytes written to @a buf 1969 * @return number of bytes written to @a buf
2001 */ 1970 */
2002static size_t 1971static size_t
2003do_transmit (void *cls, 1972do_transmit (void *cls, size_t size, void *buf)
2004 size_t size,
2005 void *buf)
2006{ 1973{
2007 struct GNUNET_ATS_Session *session = cls; 1974 struct GNUNET_ATS_Session *session = cls;
2008 struct GNUNET_PeerIdentity pid; 1975 struct GNUNET_PeerIdentity pid;
@@ -2026,8 +1993,8 @@ do_transmit (void *cls,
2026 tl = NULL; 1993 tl = NULL;
2027 ret = 0; 1994 ret = 0;
2028 now = GNUNET_TIME_absolute_get (); 1995 now = GNUNET_TIME_absolute_get ();
2029 while ( (NULL != (pos = session->pending_messages_head)) && 1996 while ((NULL != (pos = session->pending_messages_head)) &&
2030 (pos->timeout.abs_value_us <= now.abs_value_us) ) 1997 (pos->timeout.abs_value_us <= now.abs_value_us))
2031 { 1998 {
2032 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, 1999 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
2033 session->pending_messages_tail, 2000 session->pending_messages_tail,
@@ -2041,10 +2008,7 @@ do_transmit (void *cls,
2041 pos->message_size, 2008 pos->message_size,
2042 GNUNET_i2s (&session->target)); 2009 GNUNET_i2s (&session->target));
2043 ret += pos->message_size; 2010 ret += pos->message_size;
2044 GNUNET_CONTAINER_DLL_insert_after (hd, 2011 GNUNET_CONTAINER_DLL_insert_after (hd, tl, tl, pos);
2045 tl,
2046 tl,
2047 pos);
2048 } 2012 }
2049 /* do this call before callbacks (so that if callbacks destroy 2013 /* do this call before callbacks (so that if callbacks destroy
2050 * session, they have a chance to cancel actions done by this 2014 * session, they have a chance to cancel actions done by this
@@ -2055,9 +2019,7 @@ do_transmit (void *cls,
2055 * the callbacks may abort the session */ 2019 * the callbacks may abort the session */
2056 while (NULL != (pos = hd)) 2020 while (NULL != (pos = hd))
2057 { 2021 {
2058 GNUNET_CONTAINER_DLL_remove (hd, 2022 GNUNET_CONTAINER_DLL_remove (hd, tl, pos);
2059 tl,
2060 pos);
2061 if (NULL != pos->transmit_cont) 2023 if (NULL != pos->transmit_cont)
2062 pos->transmit_cont (pos->transmit_cont_cls, 2024 pos->transmit_cont (pos->transmit_cont_cls,
2063 &pid, 2025 &pid,
@@ -2067,10 +2029,12 @@ do_transmit (void *cls,
2067 GNUNET_free (pos); 2029 GNUNET_free (pos);
2068 } 2030 }
2069 GNUNET_STATISTICS_update (plugin->env->stats, 2031 GNUNET_STATISTICS_update (plugin->env->stats,
2070 gettext_noop ("# bytes currently in TCP buffers"), -(int64_t) ret, 2032 gettext_noop ("# bytes currently in TCP buffers"),
2033 -(int64_t) ret,
2071 GNUNET_NO); 2034 GNUNET_NO);
2072 GNUNET_STATISTICS_update (plugin->env->stats, 2035 GNUNET_STATISTICS_update (plugin->env->stats,
2073 gettext_noop ("# bytes discarded by TCP (timeout)"), 2036 gettext_noop (
2037 "# bytes discarded by TCP (timeout)"),
2074 ret, 2038 ret,
2075 GNUNET_NO); 2039 GNUNET_NO);
2076 if (0 < ret) 2040 if (0 < ret)
@@ -2095,7 +2059,7 @@ do_transmit (void *cls,
2095 session->msgs_in_queue--; 2059 session->msgs_in_queue--;
2096 GNUNET_assert (pos->message_size <= session->bytes_in_queue); 2060 GNUNET_assert (pos->message_size <= session->bytes_in_queue);
2097 session->bytes_in_queue -= pos->message_size; 2061 session->bytes_in_queue -= pos->message_size;
2098 GNUNET_assert(size >= pos->message_size); 2062 GNUNET_assert (size >= pos->message_size);
2099 LOG (GNUNET_ERROR_TYPE_DEBUG, 2063 LOG (GNUNET_ERROR_TYPE_DEBUG,
2100 "Transmitting message of type %u size %u to peer %s at %s\n", 2064 "Transmitting message of type %u size %u to peer %s at %s\n",
2101 ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type), 2065 ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type),
@@ -2105,19 +2069,13 @@ do_transmit (void *cls,
2105 session->address->address, 2069 session->address->address,
2106 session->address->address_length)); 2070 session->address->address_length));
2107 /* FIXME: this GNUNET_memcpy can be up to 7% of our total runtime */ 2071 /* FIXME: this GNUNET_memcpy can be up to 7% of our total runtime */
2108 GNUNET_memcpy (cbuf, 2072 GNUNET_memcpy (cbuf, pos->msg, pos->message_size);
2109 pos->msg,
2110 pos->message_size);
2111 cbuf += pos->message_size; 2073 cbuf += pos->message_size;
2112 ret += pos->message_size; 2074 ret += pos->message_size;
2113 size -= pos->message_size; 2075 size -= pos->message_size;
2114 GNUNET_CONTAINER_DLL_insert_tail (hd, 2076 GNUNET_CONTAINER_DLL_insert_tail (hd, tl, pos);
2115 tl,
2116 pos);
2117 } 2077 }
2118 notify_session_monitor (session->plugin, 2078 notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_UPDATE);
2119 session,
2120 GNUNET_TRANSPORT_SS_UPDATE);
2121 /* schedule 'continuation' before callbacks so that callbacks that 2079 /* schedule 'continuation' before callbacks so that callbacks that
2122 * cancel everything don't cause us to use a session that no longer 2080 * cancel everything don't cause us to use a session that no longer
2123 * exists... */ 2081 * exists... */
@@ -2141,7 +2099,7 @@ do_transmit (void *cls,
2141 GNUNET_assert (NULL == tl); 2099 GNUNET_assert (NULL == tl);
2142 GNUNET_STATISTICS_update (plugin->env->stats, 2100 GNUNET_STATISTICS_update (plugin->env->stats,
2143 gettext_noop ("# bytes currently in TCP buffers"), 2101 gettext_noop ("# bytes currently in TCP buffers"),
2144 - (int64_t) ret, 2102 -(int64_t) ret,
2145 GNUNET_NO); 2103 GNUNET_NO);
2146 GNUNET_STATISTICS_update (plugin->env->stats, 2104 GNUNET_STATISTICS_update (plugin->env->stats,
2147 gettext_noop ("# bytes transmitted via TCP"), 2105 gettext_noop ("# bytes transmitted via TCP"),
@@ -2168,12 +2126,13 @@ process_pending_messages (struct GNUNET_ATS_Session *session)
2168 if (NULL == (pm = session->pending_messages_head)) 2126 if (NULL == (pm = session->pending_messages_head))
2169 return; 2127 return;
2170 2128
2171 session->transmit_handle 2129 session->transmit_handle =
2172 = GNUNET_SERVER_notify_transmit_ready (session->client, 2130 GNUNET_SERVER_notify_transmit_ready (session->client,
2173 pm->message_size, 2131 pm->message_size,
2174 GNUNET_TIME_absolute_get_remaining (pm->timeout), 2132 GNUNET_TIME_absolute_get_remaining (
2175 &do_transmit, 2133 pm->timeout),
2176 session); 2134 &do_transmit,
2135 session);
2177} 2136}
2178 2137
2179 2138
@@ -2214,7 +2173,7 @@ tcp_plugin_send (void *cls,
2214 GNUNET_TRANSPORT_TransmitContinuation cont, 2173 GNUNET_TRANSPORT_TransmitContinuation cont,
2215 void *cont_cls) 2174 void *cont_cls)
2216{ 2175{
2217 struct Plugin * plugin = cls; 2176 struct Plugin *plugin = cls;
2218 struct PendingMessage *pm; 2177 struct PendingMessage *pm;
2219 2178
2220 /* create new message entry */ 2179 /* create new message entry */
@@ -2265,7 +2224,8 @@ tcp_plugin_send (void *cls,
2265 "This NAT WAIT session for peer `%s' is not yet ready!\n", 2224 "This NAT WAIT session for peer `%s' is not yet ready!\n",
2266 GNUNET_i2s (&session->target)); 2225 GNUNET_i2s (&session->target));
2267 GNUNET_STATISTICS_update (plugin->env->stats, 2226 GNUNET_STATISTICS_update (plugin->env->stats,
2268 gettext_noop ("# bytes currently in TCP buffers"), msgbuf_size, 2227 gettext_noop ("# bytes currently in TCP buffers"),
2228 msgbuf_size,
2269 GNUNET_NO); 2229 GNUNET_NO);
2270 /* append pm to pending_messages list */ 2230 /* append pm to pending_messages list */
2271 GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head, 2231 GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head,
@@ -2278,15 +2238,9 @@ tcp_plugin_send (void *cls,
2278 GNUNET_TRANSPORT_SS_HANDSHAKE); 2238 GNUNET_TRANSPORT_SS_HANDSHAKE);
2279 return msgbuf_size; 2239 return msgbuf_size;
2280 } 2240 }
2281 LOG (GNUNET_ERROR_TYPE_ERROR, 2241 LOG (GNUNET_ERROR_TYPE_ERROR, "Invalid session %p\n", session);
2282 "Invalid session %p\n",
2283 session);
2284 if (NULL != cont) 2242 if (NULL != cont)
2285 cont (cont_cls, 2243 cont (cont_cls, &session->target, GNUNET_SYSERR, pm->message_size, 0);
2286 &session->target,
2287 GNUNET_SYSERR,
2288 pm->message_size,
2289 0);
2290 GNUNET_break (0); 2244 GNUNET_break (0);
2291 GNUNET_free (pm); 2245 GNUNET_free (pm);
2292 return GNUNET_SYSERR; /* session does not exist here */ 2246 return GNUNET_SYSERR; /* session does not exist here */
@@ -2307,7 +2261,6 @@ struct GNUNET_ATS_SessionItCtx
2307 * Where to store the session (if we found it). 2261 * Where to store the session (if we found it).
2308 */ 2262 */
2309 struct GNUNET_ATS_Session *result; 2263 struct GNUNET_ATS_Session *result;
2310
2311}; 2264};
2312 2265
2313 2266
@@ -2327,9 +2280,7 @@ session_lookup_it (void *cls,
2327 struct GNUNET_ATS_SessionItCtx *si_ctx = cls; 2280 struct GNUNET_ATS_SessionItCtx *si_ctx = cls;
2328 struct GNUNET_ATS_Session *session = value; 2281 struct GNUNET_ATS_Session *session = value;
2329 2282
2330 if (0 != 2283 if (0 != GNUNET_HELLO_address_cmp (si_ctx->address, session->address))
2331 GNUNET_HELLO_address_cmp (si_ctx->address,
2332 session->address))
2333 return GNUNET_YES; 2284 return GNUNET_YES;
2334 si_ctx->result = session; 2285 si_ctx->result = session;
2335 return GNUNET_NO; 2286 return GNUNET_NO;
@@ -2353,8 +2304,7 @@ nat_connect_timeout (void *cls)
2353 tcp_plugin_address_to_string (session->plugin, 2304 tcp_plugin_address_to_string (session->plugin,
2354 session->address->address, 2305 session->address->address,
2355 session->address->address_length)); 2306 session->address->address_length));
2356 tcp_plugin_disconnect_session (session->plugin, 2307 tcp_plugin_disconnect_session (session->plugin, session);
2357 session);
2358} 2308}
2359 2309
2360 2310
@@ -2389,8 +2339,7 @@ delayed_done (void *cls)
2389 2339
2390 session->receive_delay_task = NULL; 2340 session->receive_delay_task = NULL;
2391 reschedule_session_timeout (session); 2341 reschedule_session_timeout (session);
2392 GNUNET_SERVER_receive_done (session->client, 2342 GNUNET_SERVER_receive_done (session->client, GNUNET_OK);
2393 GNUNET_OK);
2394} 2343}
2395 2344
2396 2345
@@ -2414,13 +2363,11 @@ tcp_plugin_update_inbound_delay (void *cls,
2414 return; 2363 return;
2415 LOG (GNUNET_ERROR_TYPE_DEBUG, 2364 LOG (GNUNET_ERROR_TYPE_DEBUG,
2416 "New inbound delay %s\n", 2365 "New inbound delay %s\n",
2417 GNUNET_STRINGS_relative_time_to_string (delay, 2366 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_NO));
2418 GNUNET_NO));
2419 session->receive_delay = GNUNET_TIME_relative_to_absolute (delay); 2367 session->receive_delay = GNUNET_TIME_relative_to_absolute (delay);
2420 GNUNET_SCHEDULER_cancel (session->receive_delay_task); 2368 GNUNET_SCHEDULER_cancel (session->receive_delay_task);
2421 session->receive_delay_task = GNUNET_SCHEDULER_add_delayed (delay, 2369 session->receive_delay_task =
2422 &delayed_done, 2370 GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session);
2423 session);
2424} 2371}
2425 2372
2426 2373
@@ -2434,8 +2381,7 @@ tcp_plugin_update_inbound_delay (void *cls,
2434 * @return the session if the address is valid, NULL otherwise 2381 * @return the session if the address is valid, NULL otherwise
2435 */ 2382 */
2436static struct GNUNET_ATS_Session * 2383static struct GNUNET_ATS_Session *
2437tcp_plugin_get_session (void *cls, 2384tcp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address)
2438 const struct GNUNET_HELLO_Address *address)
2439{ 2385{
2440 struct Plugin *plugin = cls; 2386 struct Plugin *plugin = cls;
2441 struct GNUNET_ATS_Session *session = NULL; 2387 struct GNUNET_ATS_Session *session = NULL;
@@ -2471,9 +2417,8 @@ tcp_plugin_get_session (void *cls,
2471 } 2417 }
2472 2418
2473 /* look for existing session */ 2419 /* look for existing session */
2474 if (GNUNET_YES == 2420 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (plugin->sessionmap,
2475 GNUNET_CONTAINER_multipeermap_contains (plugin->sessionmap, 2421 &address->peer))
2476 &address->peer))
2477 { 2422 {
2478 struct GNUNET_ATS_SessionItCtx si_ctx; 2423 struct GNUNET_ATS_SessionItCtx si_ctx;
2479 2424
@@ -2482,7 +2427,7 @@ tcp_plugin_get_session (void *cls,
2482 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap, 2427 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap,
2483 &address->peer, 2428 &address->peer,
2484 &session_lookup_it, 2429 &session_lookup_it,
2485 &si_ctx); 2430 &si_ctx);
2486 if (NULL != si_ctx.result) 2431 if (NULL != si_ctx.result)
2487 { 2432 {
2488 session = si_ctx.result; 2433 session = si_ctx.result;
@@ -2503,13 +2448,13 @@ tcp_plugin_get_session (void *cls,
2503 peer pair at the same time. */ 2448 peer pair at the same time. */
2504 } 2449 }
2505 2450
2506 if (addrlen == sizeof(struct IPv6TcpAddress)) 2451 if (addrlen == sizeof (struct IPv6TcpAddress))
2507 { 2452 {
2508 GNUNET_assert (NULL != address->address); /* make static analysis happy */ 2453 GNUNET_assert (NULL != address->address); /* make static analysis happy */
2509 t6 = address->address; 2454 t6 = address->address;
2510 options = t6->options; 2455 options = t6->options;
2511 af = AF_INET6; 2456 af = AF_INET6;
2512 memset (&a6, 0, sizeof(a6)); 2457 memset (&a6, 0, sizeof (a6));
2513#if HAVE_SOCKADDR_IN_SIN_LEN 2458#if HAVE_SOCKADDR_IN_SIN_LEN
2514 a6.sin6_len = sizeof (a6); 2459 a6.sin6_len = sizeof (a6);
2515#endif 2460#endif
@@ -2517,17 +2462,17 @@ tcp_plugin_get_session (void *cls,
2517 a6.sin6_port = t6->t6_port; 2462 a6.sin6_port = t6->t6_port;
2518 if (t6->t6_port == 0) 2463 if (t6->t6_port == 0)
2519 is_natd = GNUNET_YES; 2464 is_natd = GNUNET_YES;
2520 GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); 2465 GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr));
2521 sb = &a6; 2466 sb = &a6;
2522 sbs = sizeof(a6); 2467 sbs = sizeof (a6);
2523 } 2468 }
2524 else if (addrlen == sizeof(struct IPv4TcpAddress)) 2469 else if (addrlen == sizeof (struct IPv4TcpAddress))
2525 { 2470 {
2526 GNUNET_assert(NULL != address->address); /* make static analysis happy */ 2471 GNUNET_assert (NULL != address->address); /* make static analysis happy */
2527 t4 = address->address; 2472 t4 = address->address;
2528 options = t4->options; 2473 options = t4->options;
2529 af = AF_INET; 2474 af = AF_INET;
2530 memset (&a4, 0, sizeof(a4)); 2475 memset (&a4, 0, sizeof (a4));
2531#if HAVE_SOCKADDR_IN_SIN_LEN 2476#if HAVE_SOCKADDR_IN_SIN_LEN
2532 a4.sin_len = sizeof (a4); 2477 a4.sin_len = sizeof (a4);
2533#endif 2478#endif
@@ -2537,24 +2482,22 @@ tcp_plugin_get_session (void *cls,
2537 is_natd = GNUNET_YES; 2482 is_natd = GNUNET_YES;
2538 a4.sin_addr.s_addr = t4->ipv4_addr; 2483 a4.sin_addr.s_addr = t4->ipv4_addr;
2539 sb = &a4; 2484 sb = &a4;
2540 sbs = sizeof(a4); 2485 sbs = sizeof (a4);
2541 } 2486 }
2542 else 2487 else
2543 { 2488 {
2544 GNUNET_STATISTICS_update (plugin->env->stats, 2489 GNUNET_STATISTICS_update (
2545 gettext_noop ("# requests to create session with invalid address"), 2490 plugin->env->stats,
2546 1, 2491 gettext_noop ("# requests to create session with invalid address"),
2547 GNUNET_NO); 2492 1,
2493 GNUNET_NO);
2548 return NULL; 2494 return NULL;
2549 } 2495 }
2550 2496
2551 net_type = plugin->env->get_address_type (plugin->env->cls, 2497 net_type = plugin->env->get_address_type (plugin->env->cls, sb, sbs);
2552 sb,
2553 sbs);
2554 GNUNET_break (net_type != GNUNET_NT_UNSPECIFIED); 2498 GNUNET_break (net_type != GNUNET_NT_UNSPECIFIED);
2555 2499
2556 if ( (is_natd == GNUNET_YES) && 2500 if ((is_natd == GNUNET_YES) && (addrlen == sizeof (struct IPv6TcpAddress)))
2557 (addrlen == sizeof(struct IPv6TcpAddress)) )
2558 { 2501 {
2559 /* NAT client only works with IPv4 addresses */ 2502 /* NAT client only works with IPv4 addresses */
2560 return NULL; 2503 return NULL;
@@ -2566,62 +2509,51 @@ tcp_plugin_get_session (void *cls,
2566 return NULL; 2509 return NULL;
2567 } 2510 }
2568 2511
2569 if ( (is_natd == GNUNET_YES) && 2512 if ((is_natd == GNUNET_YES) &&
2570 (GNUNET_YES == 2513 (GNUNET_YES ==
2571 GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns, 2514 GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns,
2572 &address->peer))) 2515 &address->peer)))
2573 { 2516 {
2574 /* Only do one NAT punch attempt per peer identity */ 2517 /* Only do one NAT punch attempt per peer identity */
2575 return NULL; 2518 return NULL;
2576 } 2519 }
2577 2520
2578 if ( (is_natd == GNUNET_YES) && 2521 if ((is_natd == GNUNET_YES) && (NULL != plugin->nat) &&
2579 (NULL != plugin->nat) && 2522 (GNUNET_NO ==
2580 (GNUNET_NO == 2523 GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns,
2581 GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns, 2524 &address->peer)))
2582 &address->peer)))
2583 { 2525 {
2584 struct sockaddr_in local_sa; 2526 struct sockaddr_in local_sa;
2585 2527
2586 LOG (GNUNET_ERROR_TYPE_DEBUG, 2528 LOG (GNUNET_ERROR_TYPE_DEBUG,
2587 "Found valid IPv4 NAT address (creating session)!\n"); 2529 "Found valid IPv4 NAT address (creating session)!\n");
2588 session = create_session (plugin, 2530 session = create_session (plugin, address, net_type, NULL, GNUNET_YES);
2589 address, 2531 session->nat_connection_timeout =
2590 net_type, 2532 GNUNET_SCHEDULER_add_delayed (NAT_TIMEOUT, &nat_connect_timeout, session);
2591 NULL,
2592 GNUNET_YES);
2593 session->nat_connection_timeout = GNUNET_SCHEDULER_add_delayed (NAT_TIMEOUT,
2594 &nat_connect_timeout,
2595 session);
2596 GNUNET_assert (GNUNET_OK == 2533 GNUNET_assert (GNUNET_OK ==
2597 GNUNET_CONTAINER_multipeermap_put (plugin->nat_wait_conns, 2534 GNUNET_CONTAINER_multipeermap_put (
2598 &session->target, 2535 plugin->nat_wait_conns,
2599 session, 2536 &session->target,
2600 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 2537 session,
2538 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
2601 2539
2602 LOG (GNUNET_ERROR_TYPE_DEBUG, 2540 LOG (GNUNET_ERROR_TYPE_DEBUG,
2603 "Created NAT WAIT connection to `%s' at `%s'\n", 2541 "Created NAT WAIT connection to `%s' at `%s'\n",
2604 GNUNET_i2s (&session->target), 2542 GNUNET_i2s (&session->target),
2605 GNUNET_a2s (sb, sbs)); 2543 GNUNET_a2s (sb, sbs));
2606 memset (&local_sa, 2544 memset (&local_sa, 0, sizeof (local_sa));
2607 0,
2608 sizeof (local_sa));
2609 local_sa.sin_family = AF_INET; 2545 local_sa.sin_family = AF_INET;
2610 local_sa.sin_port = htons (plugin->open_port); 2546 local_sa.sin_port = htons (plugin->open_port);
2611 /* We leave sin_address at 0, let the kernel figure it out, 2547 /* We leave sin_address at 0, let the kernel figure it out,
2612 even if our bind() is more specific. (May want to reconsider 2548 even if our bind() is more specific. (May want to reconsider
2613 later.) */ 2549 later.) */
2614 if (GNUNET_OK == 2550 if (GNUNET_OK == GNUNET_NAT_request_reversal (plugin->nat, &local_sa, &a4))
2615 GNUNET_NAT_request_reversal (plugin->nat,
2616 &local_sa,
2617 &a4))
2618 return session; 2551 return session;
2619 LOG (GNUNET_ERROR_TYPE_DEBUG, 2552 LOG (GNUNET_ERROR_TYPE_DEBUG,
2620 "Running NAT client for `%s' at `%s' failed\n", 2553 "Running NAT client for `%s' at `%s' failed\n",
2621 GNUNET_i2s (&session->target), 2554 GNUNET_i2s (&session->target),
2622 GNUNET_a2s (sb, sbs)); 2555 GNUNET_a2s (sb, sbs));
2623 tcp_plugin_disconnect_session (plugin, 2556 tcp_plugin_disconnect_session (plugin, session);
2624 session);
2625 return NULL; 2557 return NULL;
2626 } 2558 }
2627 2559
@@ -2638,22 +2570,22 @@ tcp_plugin_get_session (void *cls,
2638 } 2570 }
2639 else 2571 else
2640 { 2572 {
2641 if ( (GNUNET_OK != 2573 if ((GNUNET_OK !=
2642 GNUNET_NETWORK_socket_setsockopt (s, 2574 GNUNET_NETWORK_socket_setsockopt (s,
2643 IPPROTO_TCP, 2575 IPPROTO_TCP,
2644 TCP_STEALTH, 2576 TCP_STEALTH,
2645 &session->target, 2577 &session->target,
2646 sizeof (struct GNUNET_PeerIdentity))) || 2578 sizeof (
2647 (GNUNET_OK != 2579 struct GNUNET_PeerIdentity))) ||
2648 GNUNET_NETWORK_socket_setsockopt (s, 2580 (GNUNET_OK !=
2649 IPPROTO_TCP, 2581 GNUNET_NETWORK_socket_setsockopt (s,
2650 TCP_STEALTH_INTEGRITY, 2582 IPPROTO_TCP,
2651 &plugin->my_welcome, 2583 TCP_STEALTH_INTEGRITY,
2652 sizeof (struct WelcomeMessage))) ) 2584 &plugin->my_welcome,
2585 sizeof (struct WelcomeMessage))))
2653 { 2586 {
2654 /* TCP STEALTH not supported by kernel */ 2587 /* TCP STEALTH not supported by kernel */
2655 GNUNET_break (GNUNET_OK == 2588 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s));
2656 GNUNET_NETWORK_socket_close (s));
2657 sa = NULL; 2589 sa = NULL;
2658 } 2590 }
2659 else 2591 else
@@ -2685,13 +2617,13 @@ tcp_plugin_get_session (void *cls,
2685 session = create_session (plugin, 2617 session = create_session (plugin,
2686 address, 2618 address,
2687 net_type, 2619 net_type,
2688 GNUNET_SERVER_connect_socket (plugin->server, 2620 GNUNET_SERVER_connect_socket (plugin->server, sa),
2689 sa),
2690 GNUNET_NO); 2621 GNUNET_NO);
2691 (void) GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, 2622 (void) GNUNET_CONTAINER_multipeermap_put (
2692 &session->target, 2623 plugin->sessionmap,
2693 session, 2624 &session->target,
2694 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 2625 session,
2626 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2695 /* Send TCP Welcome */ 2627 /* Send TCP Welcome */
2696 process_pending_messages (session); 2628 process_pending_messages (session);
2697 2629
@@ -2718,11 +2650,11 @@ session_disconnect_it (void *cls,
2718 struct GNUNET_ATS_Session *session = value; 2650 struct GNUNET_ATS_Session *session = value;
2719 2651
2720 GNUNET_STATISTICS_update (session->plugin->env->stats, 2652 GNUNET_STATISTICS_update (session->plugin->env->stats,
2721 gettext_noop ("# transport-service disconnect requests for TCP"), 2653 gettext_noop (
2654 "# transport-service disconnect requests for TCP"),
2722 1, 2655 1,
2723 GNUNET_NO); 2656 GNUNET_NO);
2724 tcp_plugin_disconnect_session (plugin, 2657 tcp_plugin_disconnect_session (plugin, session);
2725 session);
2726 return GNUNET_YES; 2658 return GNUNET_YES;
2727} 2659}
2728 2660
@@ -2744,8 +2676,7 @@ session_disconnect_it (void *cls,
2744 * to be cancelled 2676 * to be cancelled
2745 */ 2677 */
2746static void 2678static void
2747tcp_plugin_disconnect (void *cls, 2679tcp_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
2748 const struct GNUNET_PeerIdentity *target)
2749{ 2680{
2750 struct Plugin *plugin = cls; 2681 struct Plugin *plugin = cls;
2751 2682
@@ -2774,8 +2705,7 @@ tcp_plugin_disconnect (void *cls,
2774 * @param hostname hostname part of the address 2705 * @param hostname hostname part of the address
2775 */ 2706 */
2776static void 2707static void
2777append_port (void *cls, 2708append_port (void *cls, const char *hostname)
2778 const char *hostname)
2779{ 2709{
2780 struct PrettyPrinterContext *ppc = cls; 2710 struct PrettyPrinterContext *ppc = cls;
2781 struct Plugin *plugin = ppc->plugin; 2711 struct Plugin *plugin = ppc->plugin;
@@ -2791,9 +2721,7 @@ append_port (void *cls,
2791 GNUNET_CONTAINER_DLL_remove (plugin->ppc_dll_head, 2721 GNUNET_CONTAINER_DLL_remove (plugin->ppc_dll_head,
2792 plugin->ppc_dll_tail, 2722 plugin->ppc_dll_tail,
2793 ppc); 2723 ppc);
2794 ppc->asc (ppc->asc_cls, 2724 ppc->asc (ppc->asc_cls, NULL, GNUNET_OK);
2795 NULL,
2796 GNUNET_OK);
2797 GNUNET_free (ppc); 2725 GNUNET_free (ppc);
2798 return; 2726 return;
2799 } 2727 }
@@ -2811,9 +2739,7 @@ append_port (void *cls,
2811 ppc->options, 2739 ppc->options,
2812 hostname, 2740 hostname,
2813 ppc->port); 2741 ppc->port);
2814 ppc->asc (ppc->asc_cls, 2742 ppc->asc (ppc->asc_cls, ret, GNUNET_OK);
2815 ret,
2816 GNUNET_OK);
2817 GNUNET_free (ret); 2743 GNUNET_free (ret);
2818} 2744}
2819 2745
@@ -2852,35 +2778,35 @@ tcp_plugin_address_pretty_printer (void *cls,
2852 uint16_t port; 2778 uint16_t port;
2853 uint32_t options; 2779 uint32_t options;
2854 2780
2855 if (sizeof(struct IPv6TcpAddress) == addrlen) 2781 if (sizeof (struct IPv6TcpAddress) == addrlen)
2856 { 2782 {
2857 t6 = addr; 2783 t6 = addr;
2858 memset (&a6, 0, sizeof(a6)); 2784 memset (&a6, 0, sizeof (a6));
2859 a6.sin6_family = AF_INET6; 2785 a6.sin6_family = AF_INET6;
2860 a6.sin6_port = t6->t6_port; 2786 a6.sin6_port = t6->t6_port;
2861 GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); 2787 GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr));
2862 port = ntohs (t6->t6_port); 2788 port = ntohs (t6->t6_port);
2863 options = ntohl (t6->options); 2789 options = ntohl (t6->options);
2864 sb = &a6; 2790 sb = &a6;
2865 sbs = sizeof(a6); 2791 sbs = sizeof (a6);
2866 } 2792 }
2867 else if (sizeof(struct IPv4TcpAddress) == addrlen) 2793 else if (sizeof (struct IPv4TcpAddress) == addrlen)
2868 { 2794 {
2869 t4 = addr; 2795 t4 = addr;
2870 memset (&a4, 0, sizeof(a4)); 2796 memset (&a4, 0, sizeof (a4));
2871 a4.sin_family = AF_INET; 2797 a4.sin_family = AF_INET;
2872 a4.sin_port = t4->t4_port; 2798 a4.sin_port = t4->t4_port;
2873 a4.sin_addr.s_addr = t4->ipv4_addr; 2799 a4.sin_addr.s_addr = t4->ipv4_addr;
2874 port = ntohs (t4->t4_port); 2800 port = ntohs (t4->t4_port);
2875 options = ntohl (t4->options); 2801 options = ntohl (t4->options);
2876 sb = &a4; 2802 sb = &a4;
2877 sbs = sizeof(a4); 2803 sbs = sizeof (a4);
2878 } 2804 }
2879 else 2805 else
2880 { 2806 {
2881 /* invalid address */ 2807 /* invalid address */
2882 LOG (GNUNET_ERROR_TYPE_WARNING, 2808 LOG (GNUNET_ERROR_TYPE_WARNING,
2883 _("Unexpected address length: %u bytes\n"), 2809 _ ("Unexpected address length: %u bytes\n"),
2884 (unsigned int) addrlen); 2810 (unsigned int) addrlen);
2885 asc (asc_cls, NULL, GNUNET_SYSERR); 2811 asc (asc_cls, NULL, GNUNET_SYSERR);
2886 asc (asc_cls, NULL, GNUNET_OK); 2812 asc (asc_cls, NULL, GNUNET_OK);
@@ -2888,7 +2814,7 @@ tcp_plugin_address_pretty_printer (void *cls,
2888 } 2814 }
2889 ppc = GNUNET_new (struct PrettyPrinterContext); 2815 ppc = GNUNET_new (struct PrettyPrinterContext);
2890 ppc->plugin = plugin; 2816 ppc->plugin = plugin;
2891 if (addrlen == sizeof(struct IPv6TcpAddress)) 2817 if (addrlen == sizeof (struct IPv6TcpAddress))
2892 ppc->ipv6 = GNUNET_YES; 2818 ppc->ipv6 = GNUNET_YES;
2893 else 2819 else
2894 ppc->ipv6 = GNUNET_NO; 2820 ppc->ipv6 = GNUNET_NO;
@@ -2896,23 +2822,20 @@ tcp_plugin_address_pretty_printer (void *cls,
2896 ppc->asc_cls = asc_cls; 2822 ppc->asc_cls = asc_cls;
2897 ppc->port = port; 2823 ppc->port = port;
2898 ppc->options = options; 2824 ppc->options = options;
2899 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2825 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting DNS reverse lookup\n");
2900 "Starting DNS reverse lookup\n");
2901 ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, 2826 ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb,
2902 sbs, 2827 sbs,
2903 ! numeric, 2828 ! numeric,
2904 timeout, 2829 timeout,
2905 &append_port, 2830 &append_port,
2906 ppc); 2831 ppc);
2907 if (NULL == ppc->resolver_handle) 2832 if (NULL == ppc->resolver_handle)
2908 { 2833 {
2909 GNUNET_break (0); 2834 GNUNET_break (0);
2910 GNUNET_free (ppc); 2835 GNUNET_free (ppc);
2911 return; 2836 return;
2912 } 2837 }
2913 GNUNET_CONTAINER_DLL_insert (plugin->ppc_dll_head, 2838 GNUNET_CONTAINER_DLL_insert (plugin->ppc_dll_head, plugin->ppc_dll_tail, ppc);
2914 plugin->ppc_dll_tail,
2915 ppc);
2916} 2839}
2917 2840
2918 2841
@@ -2932,29 +2855,25 @@ tcp_plugin_address_pretty_printer (void *cls,
2932 * and transport, #GNUNET_SYSERR if not 2855 * and transport, #GNUNET_SYSERR if not
2933 */ 2856 */
2934static int 2857static int
2935tcp_plugin_check_address (void *cls, 2858tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen)
2936 const void *addr,
2937 size_t addrlen)
2938{ 2859{
2939 struct Plugin *plugin = cls; 2860 struct Plugin *plugin = cls;
2940 const struct IPv4TcpAddress *v4; 2861 const struct IPv4TcpAddress *v4;
2941 const struct IPv6TcpAddress *v6; 2862 const struct IPv6TcpAddress *v6;
2942 2863
2943 if ( (addrlen != sizeof(struct IPv4TcpAddress)) && 2864 if ((addrlen != sizeof (struct IPv4TcpAddress)) &&
2944 (addrlen != sizeof(struct IPv6TcpAddress)) ) 2865 (addrlen != sizeof (struct IPv6TcpAddress)))
2945 { 2866 {
2946 GNUNET_break_op (0); 2867 GNUNET_break_op (0);
2947 return GNUNET_SYSERR; 2868 return GNUNET_SYSERR;
2948 } 2869 }
2949 2870
2950 if (addrlen == sizeof(struct IPv4TcpAddress)) 2871 if (addrlen == sizeof (struct IPv4TcpAddress))
2951 { 2872 {
2952 struct sockaddr_in s4; 2873 struct sockaddr_in s4;
2953 2874
2954 v4 = (const struct IPv4TcpAddress *) addr; 2875 v4 = (const struct IPv4TcpAddress *) addr;
2955 if (0 != memcmp (&v4->options, 2876 if (0 != memcmp (&v4->options, &plugin->myoptions, sizeof (uint32_t)))
2956 &plugin->myoptions,
2957 sizeof(uint32_t)))
2958 { 2877 {
2959 GNUNET_break (0); 2878 GNUNET_break (0);
2960 return GNUNET_SYSERR; 2879 return GNUNET_SYSERR;
@@ -2968,9 +2887,7 @@ tcp_plugin_check_address (void *cls,
2968 s4.sin_addr.s_addr = v4->ipv4_addr; 2887 s4.sin_addr.s_addr = v4->ipv4_addr;
2969 2888
2970 if (GNUNET_OK != 2889 if (GNUNET_OK !=
2971 GNUNET_NAT_test_address (plugin->nat, 2890 GNUNET_NAT_test_address (plugin->nat, &s4, sizeof (struct sockaddr_in)))
2972 &s4,
2973 sizeof (struct sockaddr_in)))
2974 return GNUNET_SYSERR; 2891 return GNUNET_SYSERR;
2975 } 2892 }
2976 else 2893 else
@@ -2983,9 +2900,7 @@ tcp_plugin_check_address (void *cls,
2983 GNUNET_break_op (0); 2900 GNUNET_break_op (0);
2984 return GNUNET_SYSERR; 2901 return GNUNET_SYSERR;
2985 } 2902 }
2986 if (0 != memcmp (&v6->options, 2903 if (0 != memcmp (&v6->options, &plugin->myoptions, sizeof (uint32_t)))
2987 &plugin->myoptions,
2988 sizeof (uint32_t)))
2989 { 2904 {
2990 GNUNET_break (0); 2905 GNUNET_break (0);
2991 return GNUNET_SYSERR; 2906 return GNUNET_SYSERR;
@@ -2998,10 +2913,9 @@ tcp_plugin_check_address (void *cls,
2998 s6.sin6_port = v6->t6_port; 2913 s6.sin6_port = v6->t6_port;
2999 s6.sin6_addr = v6->ipv6_addr; 2914 s6.sin6_addr = v6->ipv6_addr;
3000 2915
3001 if (GNUNET_OK != 2916 if (GNUNET_OK != GNUNET_NAT_test_address (plugin->nat,
3002 GNUNET_NAT_test_address (plugin->nat, 2917 &s6,
3003 &s6, 2918 sizeof (struct sockaddr_in6)))
3004 sizeof(struct sockaddr_in6)))
3005 return GNUNET_SYSERR; 2919 return GNUNET_SYSERR;
3006 } 2920 }
3007 return GNUNET_OK; 2921 return GNUNET_OK;
@@ -3032,29 +2946,27 @@ handle_tcp_nat_probe (void *cls,
3032 const struct sockaddr_in *s4; 2946 const struct sockaddr_in *s4;
3033 const struct sockaddr_in6 *s6; 2947 const struct sockaddr_in6 *s6;
3034 2948
3035 LOG (GNUNET_ERROR_TYPE_DEBUG, 2949 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received NAT probe\n");
3036 "Received NAT probe\n");
3037 /* We have received a TCP NAT probe, meaning we (hopefully) initiated 2950 /* We have received a TCP NAT probe, meaning we (hopefully) initiated
3038 * a connection to this peer by running gnunet-nat-client. This peer 2951 * a connection to this peer by running gnunet-nat-client. This peer
3039 * received the punch message and now wants us to use the new connection 2952 * received the punch message and now wants us to use the new connection
3040 * as the default for that peer. Do so and then send a WELCOME message 2953 * as the default for that peer. Do so and then send a WELCOME message
3041 * so we can really be connected! 2954 * so we can really be connected!
3042 */ 2955 */
3043 if (ntohs (message->size) != sizeof(struct TCP_NAT_ProbeMessage)) 2956 if (ntohs (message->size) != sizeof (struct TCP_NAT_ProbeMessage))
3044 { 2957 {
3045 GNUNET_break_op(0); 2958 GNUNET_break_op (0);
3046 GNUNET_SERVER_receive_done (client, 2959 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3047 GNUNET_SYSERR);
3048 return; 2960 return;
3049 } 2961 }
3050 2962
3051 tcp_nat_probe = (const struct TCP_NAT_ProbeMessage *) message; 2963 tcp_nat_probe = (const struct TCP_NAT_ProbeMessage *) message;
3052 if (0 == memcmp (&tcp_nat_probe->clientIdentity, plugin->env->my_identity, 2964 if (0 == memcmp (&tcp_nat_probe->clientIdentity,
3053 sizeof(struct GNUNET_PeerIdentity))) 2965 plugin->env->my_identity,
2966 sizeof (struct GNUNET_PeerIdentity)))
3054 { 2967 {
3055 /* refuse connections from ourselves */ 2968 /* refuse connections from ourselves */
3056 GNUNET_SERVER_receive_done (client, 2969 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3057 GNUNET_SYSERR);
3058 return; 2970 return;
3059 } 2971 }
3060 2972
@@ -3062,14 +2974,11 @@ handle_tcp_nat_probe (void *cls,
3062 &tcp_nat_probe->clientIdentity); 2974 &tcp_nat_probe->clientIdentity);
3063 if (NULL == session) 2975 if (NULL == session)
3064 { 2976 {
3065 LOG (GNUNET_ERROR_TYPE_DEBUG, 2977 LOG (GNUNET_ERROR_TYPE_DEBUG, "Did NOT find session for NAT probe!\n");
3066 "Did NOT find session for NAT probe!\n"); 2978 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3067 GNUNET_SERVER_receive_done (client,
3068 GNUNET_OK);
3069 return; 2979 return;
3070 } 2980 }
3071 LOG (GNUNET_ERROR_TYPE_DEBUG, 2981 LOG (GNUNET_ERROR_TYPE_DEBUG, "Found session for NAT probe!\n");
3072 "Found session for NAT probe!\n");
3073 2982
3074 if (NULL != session->nat_connection_timeout) 2983 if (NULL != session->nat_connection_timeout)
3075 { 2984 {
@@ -3077,28 +2986,24 @@ handle_tcp_nat_probe (void *cls,
3077 session->nat_connection_timeout = NULL; 2986 session->nat_connection_timeout = NULL;
3078 } 2987 }
3079 2988
3080 if (GNUNET_OK != 2989 if (GNUNET_OK != GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
3081 GNUNET_SERVER_client_get_address (client,
3082 &vaddr,
3083 &alen))
3084 { 2990 {
3085 GNUNET_break(0); 2991 GNUNET_break (0);
3086 GNUNET_SERVER_receive_done (client, 2992 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3087 GNUNET_SYSERR); 2993 tcp_plugin_disconnect_session (plugin, session);
3088 tcp_plugin_disconnect_session (plugin,
3089 session);
3090 return; 2994 return;
3091 } 2995 }
3092 GNUNET_assert (GNUNET_YES == 2996 GNUNET_assert (
3093 GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns, 2997 GNUNET_YES ==
3094 &tcp_nat_probe->clientIdentity, 2998 GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns,
3095 session)); 2999 &tcp_nat_probe->clientIdentity,
3096 GNUNET_SERVER_client_set_user_context (client, 3000 session));
3097 session); 3001 GNUNET_SERVER_client_set_user_context (client, session);
3098 (void) GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, 3002 (void) GNUNET_CONTAINER_multipeermap_put (
3099 &session->target, 3003 plugin->sessionmap,
3100 session, 3004 &session->target,
3101 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 3005 session,
3006 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
3102 session->last_activity = GNUNET_TIME_absolute_get (); 3007 session->last_activity = GNUNET_TIME_absolute_get ();
3103 LOG (GNUNET_ERROR_TYPE_DEBUG, 3008 LOG (GNUNET_ERROR_TYPE_DEBUG,
3104 "Found address `%s' for incoming connection\n", 3009 "Found address `%s' for incoming connection\n",
@@ -3111,45 +3016,43 @@ handle_tcp_nat_probe (void *cls,
3111 t4->options = htonl (TCP_OPTIONS_NONE); 3016 t4->options = htonl (TCP_OPTIONS_NONE);
3112 t4->t4_port = s4->sin_port; 3017 t4->t4_port = s4->sin_port;
3113 t4->ipv4_addr = s4->sin_addr.s_addr; 3018 t4->ipv4_addr = s4->sin_addr.s_addr;
3114 session->address = GNUNET_HELLO_address_allocate (&tcp_nat_probe->clientIdentity, 3019 session->address =
3115 PLUGIN_NAME, 3020 GNUNET_HELLO_address_allocate (&tcp_nat_probe->clientIdentity,
3116 &t4, 3021 PLUGIN_NAME,
3117 sizeof(struct IPv4TcpAddress), 3022 &t4,
3118 GNUNET_HELLO_ADDRESS_INFO_NONE); 3023 sizeof (struct IPv4TcpAddress),
3024 GNUNET_HELLO_ADDRESS_INFO_NONE);
3119 break; 3025 break;
3120 case AF_INET6: 3026 case AF_INET6:
3121 s6 = vaddr; 3027 s6 = vaddr;
3122 t6 = GNUNET_new (struct IPv6TcpAddress); 3028 t6 = GNUNET_new (struct IPv6TcpAddress);
3123 t6->options = htonl (TCP_OPTIONS_NONE); 3029 t6->options = htonl (TCP_OPTIONS_NONE);
3124 t6->t6_port = s6->sin6_port; 3030 t6->t6_port = s6->sin6_port;
3125 GNUNET_memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr)); 3031 GNUNET_memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr));
3126 session->address = GNUNET_HELLO_address_allocate (&tcp_nat_probe->clientIdentity, 3032 session->address =
3127 PLUGIN_NAME, 3033 GNUNET_HELLO_address_allocate (&tcp_nat_probe->clientIdentity,
3128 &t6, 3034 PLUGIN_NAME,
3129 sizeof(struct IPv6TcpAddress), 3035 &t6,
3130 GNUNET_HELLO_ADDRESS_INFO_NONE); 3036 sizeof (struct IPv6TcpAddress),
3037 GNUNET_HELLO_ADDRESS_INFO_NONE);
3131 break; 3038 break;
3132 default: 3039 default:
3133 GNUNET_break_op(0); 3040 GNUNET_break_op (0);
3134 LOG(GNUNET_ERROR_TYPE_DEBUG, 3041 LOG (GNUNET_ERROR_TYPE_DEBUG, "Bad address for incoming connection!\n");
3135 "Bad address for incoming connection!\n"); 3042 GNUNET_free (vaddr);
3136 GNUNET_free(vaddr); 3043 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3137 GNUNET_SERVER_receive_done (client, 3044 tcp_plugin_disconnect_session (plugin, session);
3138 GNUNET_SYSERR);
3139 tcp_plugin_disconnect_session (plugin,
3140 session);
3141 return; 3045 return;
3142 } 3046 }
3143 GNUNET_free (vaddr); 3047 GNUNET_free (vaddr);
3144 GNUNET_break (NULL == session->client); 3048 GNUNET_break (NULL == session->client);
3145 session->client = client; 3049 session->client = client;
3146 GNUNET_STATISTICS_update (plugin->env->stats, 3050 GNUNET_STATISTICS_update (plugin->env->stats,
3147 gettext_noop ("# TCP sessions active"), 3051 gettext_noop ("# TCP sessions active"),
3148 1, 3052 1,
3149 GNUNET_NO); 3053 GNUNET_NO);
3150 process_pending_messages (session); 3054 process_pending_messages (session);
3151 GNUNET_SERVER_receive_done (client, 3055 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3152 GNUNET_OK);
3153} 3056}
3154 3057
3155 3058
@@ -3179,13 +3082,10 @@ handle_tcp_welcome (void *cls,
3179 3082
3180 if (0 == memcmp (&wm->clientIdentity, 3083 if (0 == memcmp (&wm->clientIdentity,
3181 plugin->env->my_identity, 3084 plugin->env->my_identity,
3182 sizeof(struct GNUNET_PeerIdentity))) 3085 sizeof (struct GNUNET_PeerIdentity)))
3183 { 3086 {
3184 /* refuse connections from ourselves */ 3087 /* refuse connections from ourselves */
3185 if (GNUNET_OK == 3088 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
3186 GNUNET_SERVER_client_get_address (client,
3187 &vaddr,
3188 &alen))
3189 { 3089 {
3190 LOG (GNUNET_ERROR_TYPE_INFO, 3090 LOG (GNUNET_ERROR_TYPE_INFO,
3191 "Received WELCOME message from my own identity `%s' on address `%s'\n", 3091 "Received WELCOME message from my own identity `%s' on address `%s'\n",
@@ -3193,34 +3093,26 @@ handle_tcp_welcome (void *cls,
3193 GNUNET_a2s (vaddr, alen)); 3093 GNUNET_a2s (vaddr, alen));
3194 GNUNET_free (vaddr); 3094 GNUNET_free (vaddr);
3195 } 3095 }
3196 GNUNET_SERVER_receive_done (client, 3096 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3197 GNUNET_SYSERR);
3198 return; 3097 return;
3199 } 3098 }
3200 3099
3201 if (GNUNET_OK == 3100 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
3202 GNUNET_SERVER_client_get_address (client,
3203 &vaddr,
3204 &alen))
3205 { 3101 {
3206 LOG(GNUNET_ERROR_TYPE_DEBUG, 3102 LOG (GNUNET_ERROR_TYPE_DEBUG,
3207 "Received WELCOME message from `%s' on address `%s'\n", 3103 "Received WELCOME message from `%s' on address `%s'\n",
3208 GNUNET_i2s (&wm->clientIdentity), 3104 GNUNET_i2s (&wm->clientIdentity),
3209 GNUNET_a2s (vaddr, alen)); 3105 GNUNET_a2s (vaddr, alen));
3210 GNUNET_free (vaddr); 3106 GNUNET_free (vaddr);
3211 } 3107 }
3212 GNUNET_STATISTICS_update (plugin->env->stats, 3108 GNUNET_STATISTICS_update (plugin->env->stats,
3213 gettext_noop ("# TCP WELCOME messages received"), 3109 gettext_noop ("# TCP WELCOME messages received"),
3214 1, 3110 1,
3215 GNUNET_NO); 3111 GNUNET_NO);
3216 session = lookup_session_by_client (plugin, 3112 session = lookup_session_by_client (plugin, client);
3217 client);
3218 if (NULL != session) 3113 if (NULL != session)
3219 { 3114 {
3220 if (GNUNET_OK == 3115 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
3221 GNUNET_SERVER_client_get_address (client,
3222 &vaddr,
3223 &alen))
3224 { 3116 {
3225 LOG (GNUNET_ERROR_TYPE_DEBUG, 3117 LOG (GNUNET_ERROR_TYPE_DEBUG,
3226 "Found existing session %p for peer `%s'\n", 3118 "Found existing session %p for peer `%s'\n",
@@ -3231,41 +3123,41 @@ handle_tcp_welcome (void *cls,
3231 } 3123 }
3232 else 3124 else
3233 { 3125 {
3234 if (GNUNET_OK == 3126 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
3235 GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
3236 { 3127 {
3237 if (alen == sizeof(struct sockaddr_in)) 3128 if (alen == sizeof (struct sockaddr_in))
3238 { 3129 {
3239 s4 = vaddr; 3130 s4 = vaddr;
3240 memset (&t4, '\0', sizeof (t4)); 3131 memset (&t4, '\0', sizeof (t4));
3241 t4.options = htonl (TCP_OPTIONS_NONE); 3132 t4.options = htonl (TCP_OPTIONS_NONE);
3242 t4.t4_port = s4->sin_port; 3133 t4.t4_port = s4->sin_port;
3243 t4.ipv4_addr = s4->sin_addr.s_addr; 3134 t4.ipv4_addr = s4->sin_addr.s_addr;
3244 address = GNUNET_HELLO_address_allocate (&wm->clientIdentity, 3135 address =
3245 PLUGIN_NAME, 3136 GNUNET_HELLO_address_allocate (&wm->clientIdentity,
3246 &t4, 3137 PLUGIN_NAME,
3247 sizeof(t4), 3138 &t4,
3248 GNUNET_HELLO_ADDRESS_INFO_INBOUND); 3139 sizeof (t4),
3140 GNUNET_HELLO_ADDRESS_INFO_INBOUND);
3249 } 3141 }
3250 else if (alen == sizeof(struct sockaddr_in6)) 3142 else if (alen == sizeof (struct sockaddr_in6))
3251 { 3143 {
3252 s6 = vaddr; 3144 s6 = vaddr;
3253 memset (&t6, '\0', sizeof (t6)); 3145 memset (&t6, '\0', sizeof (t6));
3254 t6.options = htonl (TCP_OPTIONS_NONE); 3146 t6.options = htonl (TCP_OPTIONS_NONE);
3255 t6.t6_port = s6->sin6_port; 3147 t6.t6_port = s6->sin6_port;
3256 GNUNET_memcpy (&t6.ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr)); 3148 GNUNET_memcpy (&t6.ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr));
3257 address = GNUNET_HELLO_address_allocate (&wm->clientIdentity, 3149 address =
3258 PLUGIN_NAME, 3150 GNUNET_HELLO_address_allocate (&wm->clientIdentity,
3259 &t6, 3151 PLUGIN_NAME,
3260 sizeof (t6), 3152 &t6,
3261 GNUNET_HELLO_ADDRESS_INFO_INBOUND); 3153 sizeof (t6),
3154 GNUNET_HELLO_ADDRESS_INFO_INBOUND);
3262 } 3155 }
3263 else 3156 else
3264 { 3157 {
3265 GNUNET_break (0); 3158 GNUNET_break (0);
3266 GNUNET_free_non_null (vaddr); 3159 GNUNET_free_non_null (vaddr);
3267 GNUNET_SERVER_receive_done (client, 3160 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3268 GNUNET_SYSERR);
3269 return; 3161 return;
3270 } 3162 }
3271 session = create_session (plugin, 3163 session = create_session (plugin,
@@ -3281,17 +3173,19 @@ handle_tcp_welcome (void *cls,
3281 "Creating new%s session %p for peer `%s' client %p\n", 3173 "Creating new%s session %p for peer `%s' client %p\n",
3282 GNUNET_HELLO_address_check_option (session->address, 3174 GNUNET_HELLO_address_check_option (session->address,
3283 GNUNET_HELLO_ADDRESS_INFO_INBOUND) 3175 GNUNET_HELLO_ADDRESS_INFO_INBOUND)
3284 ? " inbound" : "", 3176 ? " inbound"
3177 : "",
3285 session, 3178 session,
3286 tcp_plugin_address_to_string (plugin, 3179 tcp_plugin_address_to_string (plugin,
3287 session->address->address, 3180 session->address->address,
3288 session->address->address_length), 3181 session->address->address_length),
3289 client); 3182 client);
3290 GNUNET_free (vaddr); 3183 GNUNET_free (vaddr);
3291 (void) GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, 3184 (void) GNUNET_CONTAINER_multipeermap_put (
3292 &session->target, 3185 plugin->sessionmap,
3293 session, 3186 &session->target,
3294 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 3187 session,
3188 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
3295 /* Notify transport and ATS about new session */ 3189 /* Notify transport and ATS about new session */
3296 plugin->env->session_start (plugin->env->cls, 3190 plugin->env->session_start (plugin->env->cls,
3297 session->address, 3191 session->address,
@@ -3300,11 +3194,10 @@ handle_tcp_welcome (void *cls,
3300 } 3194 }
3301 else 3195 else
3302 { 3196 {
3303 LOG(GNUNET_ERROR_TYPE_DEBUG, 3197 LOG (GNUNET_ERROR_TYPE_DEBUG,
3304 "Did not obtain TCP socket address for incoming connection\n"); 3198 "Did not obtain TCP socket address for incoming connection\n");
3305 GNUNET_break(0); 3199 GNUNET_break (0);
3306 GNUNET_SERVER_receive_done (client, 3200 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3307 GNUNET_SYSERR);
3308 return; 3201 return;
3309 } 3202 }
3310 } 3203 }
@@ -3312,8 +3205,7 @@ handle_tcp_welcome (void *cls,
3312 if (GNUNET_YES != session->expecting_welcome) 3205 if (GNUNET_YES != session->expecting_welcome)
3313 { 3206 {
3314 GNUNET_break_op (0); 3207 GNUNET_break_op (0);
3315 GNUNET_SERVER_receive_done (client, 3208 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3316 GNUNET_SYSERR);
3317 return; 3209 return;
3318 } 3210 }
3319 session->last_activity = GNUNET_TIME_absolute_get (); 3211 session->last_activity = GNUNET_TIME_absolute_get ();
@@ -3322,8 +3214,7 @@ handle_tcp_welcome (void *cls,
3322 process_pending_messages (session); 3214 process_pending_messages (session);
3323 GNUNET_SERVER_client_set_timeout (client, 3215 GNUNET_SERVER_client_set_timeout (client,
3324 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 3216 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
3325 GNUNET_SERVER_receive_done (client, 3217 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3326 GNUNET_OK);
3327} 3218}
3328 3219
3329 3220
@@ -3346,12 +3237,11 @@ handle_tcp_data (void *cls,
3346 uint16_t type; 3237 uint16_t type;
3347 3238
3348 type = ntohs (message->type); 3239 type = ntohs (message->type);
3349 if ( (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) || 3240 if ((GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) ||
3350 (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type) ) 3241 (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type))
3351 { 3242 {
3352 /* We don't want to propagate WELCOME and NAT Probe messages up! */ 3243 /* We don't want to propagate WELCOME and NAT Probe messages up! */
3353 GNUNET_SERVER_receive_done (client, 3244 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3354 GNUNET_OK);
3355 return; 3245 return;
3356 } 3246 }
3357 session = lookup_session_by_client (plugin, client); 3247 session = lookup_session_by_client (plugin, client);
@@ -3362,18 +3252,14 @@ handle_tcp_data (void *cls,
3362 size_t alen; 3252 size_t alen;
3363 3253
3364 GNUNET_assert (GNUNET_OK == 3254 GNUNET_assert (GNUNET_OK ==
3365 GNUNET_SERVER_client_get_address (client, 3255 GNUNET_SERVER_client_get_address (client, &vaddr, &alen));
3366 &vaddr,
3367 &alen));
3368 LOG (GNUNET_ERROR_TYPE_ERROR, 3256 LOG (GNUNET_ERROR_TYPE_ERROR,
3369 "Received unexpected %u bytes of type %u from `%s'\n", 3257 "Received unexpected %u bytes of type %u from `%s'\n",
3370 (unsigned int) ntohs (message->size), 3258 (unsigned int) ntohs (message->size),
3371 (unsigned int) ntohs (message->type), 3259 (unsigned int) ntohs (message->type),
3372 GNUNET_a2s (vaddr, 3260 GNUNET_a2s (vaddr, alen));
3373 alen)); 3261 GNUNET_break_op (0);
3374 GNUNET_break_op(0); 3262 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3375 GNUNET_SERVER_receive_done (client,
3376 GNUNET_SYSERR);
3377 GNUNET_free_non_null (vaddr); 3263 GNUNET_free_non_null (vaddr);
3378 return; 3264 return;
3379 } 3265 }
@@ -3383,17 +3269,14 @@ handle_tcp_data (void *cls,
3383 void *vaddr = NULL; 3269 void *vaddr = NULL;
3384 size_t alen; 3270 size_t alen;
3385 3271
3386 GNUNET_SERVER_client_get_address (client, 3272 GNUNET_SERVER_client_get_address (client, &vaddr, &alen);
3387 &vaddr,
3388 &alen);
3389 LOG (GNUNET_ERROR_TYPE_ERROR, 3273 LOG (GNUNET_ERROR_TYPE_ERROR,
3390 "Received unexpected %u bytes of type %u from `%s'\n", 3274 "Received unexpected %u bytes of type %u from `%s'\n",
3391 (unsigned int) ntohs (message->size), 3275 (unsigned int) ntohs (message->size),
3392 (unsigned int) ntohs (message->type), 3276 (unsigned int) ntohs (message->type),
3393 GNUNET_a2s (vaddr, alen)); 3277 GNUNET_a2s (vaddr, alen));
3394 GNUNET_break_op(0); 3278 GNUNET_break_op (0);
3395 GNUNET_SERVER_receive_done (client, 3279 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3396 GNUNET_SYSERR);
3397 GNUNET_free_non_null (vaddr); 3280 GNUNET_free_non_null (vaddr);
3398 return; 3281 return;
3399 } 3282 }
@@ -3403,9 +3286,7 @@ handle_tcp_data (void *cls,
3403 void *vaddr = NULL; 3286 void *vaddr = NULL;
3404 size_t alen; 3287 size_t alen;
3405 3288
3406 GNUNET_SERVER_client_get_address (client, 3289 GNUNET_SERVER_client_get_address (client, &vaddr, &alen);
3407 &vaddr,
3408 &alen);
3409 LOG (GNUNET_ERROR_TYPE_DEBUG, 3290 LOG (GNUNET_ERROR_TYPE_DEBUG,
3410 "Passing %u bytes of type %u from `%s' at %s to transport service.\n", 3291 "Passing %u bytes of type %u from `%s' at %s to transport service.\n",
3411 (unsigned int) ntohs (message->size), 3292 (unsigned int) ntohs (message->size),
@@ -3420,31 +3301,27 @@ handle_tcp_data (void *cls,
3420 ntohs (message->size), 3301 ntohs (message->size),
3421 GNUNET_NO); 3302 GNUNET_NO);
3422 3303
3423 GNUNET_assert (GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, 3304 GNUNET_assert (
3424 &session->target, 3305 GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap,
3425 session)); 3306 &session->target,
3426 delay = plugin->env->receive (plugin->env->cls, 3307 session));
3427 session->address, 3308 delay =
3428 session, 3309 plugin->env->receive (plugin->env->cls, session->address, session, message);
3429 message);
3430 reschedule_session_timeout (session); 3310 reschedule_session_timeout (session);
3431 if (0 == delay.rel_value_us) 3311 if (0 == delay.rel_value_us)
3432 { 3312 {
3433 GNUNET_SERVER_receive_done (client, 3313 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3434 GNUNET_OK);
3435 } 3314 }
3436 else 3315 else
3437 { 3316 {
3438 LOG (GNUNET_ERROR_TYPE_DEBUG, 3317 LOG (GNUNET_ERROR_TYPE_DEBUG,
3439 "Throttling receiving from `%s' for %s\n", 3318 "Throttling receiving from `%s' for %s\n",
3440 GNUNET_i2s (&session->target), 3319 GNUNET_i2s (&session->target),
3441 GNUNET_STRINGS_relative_time_to_string (delay, 3320 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
3442 GNUNET_YES));
3443 GNUNET_SERVER_disable_receive_done_warning (client); 3321 GNUNET_SERVER_disable_receive_done_warning (client);
3444 GNUNET_assert (NULL == session->receive_delay_task); 3322 GNUNET_assert (NULL == session->receive_delay_task);
3445 session->receive_delay_task = GNUNET_SCHEDULER_add_delayed (delay, 3323 session->receive_delay_task =
3446 &delayed_done, 3324 GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session);
3447 session);
3448 } 3325 }
3449} 3326}
3450 3327
@@ -3458,8 +3335,7 @@ handle_tcp_data (void *cls,
3458 * @param client identification of the client 3335 * @param client identification of the client
3459 */ 3336 */
3460static void 3337static void
3461connect_notify (void *cls, 3338connect_notify (void *cls, struct GNUNET_SERVER_Client *client)
3462 struct GNUNET_SERVER_Client *client)
3463{ 3339{
3464 struct Plugin *plugin = cls; 3340 struct Plugin *plugin = cls;
3465 3341
@@ -3471,18 +3347,19 @@ connect_notify (void *cls,
3471 plugin->cur_connections, 3347 plugin->cur_connections,
3472 GNUNET_NO); 3348 GNUNET_NO);
3473 GNUNET_STATISTICS_update (plugin->env->stats, 3349 GNUNET_STATISTICS_update (plugin->env->stats,
3474 gettext_noop ("# TCP server connect events"), 3350 gettext_noop ("# TCP server connect events"),
3475 1, 3351 1,
3476 GNUNET_NO); 3352 GNUNET_NO);
3477 if (plugin->cur_connections != plugin->max_connections) 3353 if (plugin->cur_connections != plugin->max_connections)
3478 return; 3354 return;
3479 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3355 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3480 _("TCP connection limit reached, suspending server\n")); 3356 _ ("TCP connection limit reached, suspending server\n"));
3481 GNUNET_STATISTICS_update (plugin->env->stats, 3357 GNUNET_STATISTICS_update (plugin->env->stats,
3482 gettext_noop ("# TCP service suspended"), 3358 gettext_noop ("# TCP service suspended"),
3483 1, 3359 1,
3484 GNUNET_NO); 3360 GNUNET_NO);
3485 GNUNET_SERVER_suspend (plugin->server); /* Maximum number of connections rechead */ 3361 GNUNET_SERVER_suspend (
3362 plugin->server); /* Maximum number of connections rechead */
3486} 3363}
3487 3364
3488 3365
@@ -3495,8 +3372,7 @@ connect_notify (void *cls,
3495 * @param client identification of the client 3372 * @param client identification of the client
3496 */ 3373 */
3497static void 3374static void
3498disconnect_notify (void *cls, 3375disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client)
3499 struct GNUNET_SERVER_Client *client)
3500{ 3376{
3501 struct Plugin *plugin = cls; 3377 struct Plugin *plugin = cls;
3502 struct GNUNET_ATS_Session *session; 3378 struct GNUNET_ATS_Session *session;
@@ -3505,8 +3381,7 @@ disconnect_notify (void *cls,
3505 return; 3381 return;
3506 GNUNET_assert (plugin->cur_connections >= 1); 3382 GNUNET_assert (plugin->cur_connections >= 1);
3507 plugin->cur_connections--; 3383 plugin->cur_connections--;
3508 session = lookup_session_by_client (plugin, 3384 session = lookup_session_by_client (plugin, client);
3509 client);
3510 if (NULL == session) 3385 if (NULL == session)
3511 return; /* unknown, nothing to do */ 3386 return; /* unknown, nothing to do */
3512 LOG (GNUNET_ERROR_TYPE_DEBUG, 3387 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -3529,11 +3404,11 @@ disconnect_notify (void *cls,
3529 plugin->cur_connections, 3404 plugin->cur_connections,
3530 GNUNET_NO); 3405 GNUNET_NO);
3531 GNUNET_STATISTICS_update (session->plugin->env->stats, 3406 GNUNET_STATISTICS_update (session->plugin->env->stats,
3532 gettext_noop ("# network-level TCP disconnect events"), 3407 gettext_noop (
3408 "# network-level TCP disconnect events"),
3533 1, 3409 1,
3534 GNUNET_NO); 3410 GNUNET_NO);
3535 tcp_plugin_disconnect_session (plugin, 3411 tcp_plugin_disconnect_session (plugin, session);
3536 session);
3537} 3412}
3538 3413
3539 3414
@@ -3546,9 +3421,7 @@ disconnect_notify (void *cls,
3546 * @return number of bytes copied into @a buf 3421 * @return number of bytes copied into @a buf
3547 */ 3422 */
3548static size_t 3423static size_t
3549notify_send_probe (void *cls, 3424notify_send_probe (void *cls, size_t size, void *buf)
3550 size_t size,
3551 void *buf)
3552{ 3425{
3553 struct TCPProbeContext *tcp_probe_ctx = cls; 3426 struct TCPProbeContext *tcp_probe_ctx = cls;
3554 struct Plugin *plugin = tcp_probe_ctx->plugin; 3427 struct Plugin *plugin = tcp_probe_ctx->plugin;
@@ -3561,16 +3434,14 @@ notify_send_probe (void *cls,
3561 if (NULL == buf) 3434 if (NULL == buf)
3562 { 3435 {
3563 GNUNET_CONNECTION_destroy (tcp_probe_ctx->sock); 3436 GNUNET_CONNECTION_destroy (tcp_probe_ctx->sock);
3564 GNUNET_free(tcp_probe_ctx); 3437 GNUNET_free (tcp_probe_ctx);
3565 return 0; 3438 return 0;
3566 } 3439 }
3567 GNUNET_assert(size >= sizeof(tcp_probe_ctx->message)); 3440 GNUNET_assert (size >= sizeof (tcp_probe_ctx->message));
3568 GNUNET_memcpy (buf, 3441 GNUNET_memcpy (buf, &tcp_probe_ctx->message, sizeof (tcp_probe_ctx->message));
3569 &tcp_probe_ctx->message,
3570 sizeof(tcp_probe_ctx->message));
3571 GNUNET_SERVER_connect_socket (tcp_probe_ctx->plugin->server, 3442 GNUNET_SERVER_connect_socket (tcp_probe_ctx->plugin->server,
3572 tcp_probe_ctx->sock); 3443 tcp_probe_ctx->sock);
3573 ret = sizeof(tcp_probe_ctx->message); 3444 ret = sizeof (tcp_probe_ctx->message);
3574 GNUNET_free (tcp_probe_ctx); 3445 GNUNET_free (tcp_probe_ctx);
3575 return ret; 3446 return ret;
3576} 3447}
@@ -3598,9 +3469,7 @@ try_connection_reversal (void *cls,
3598 * We have received an ICMP response, ostensibly from a peer 3469 * We have received an ICMP response, ostensibly from a peer
3599 * that wants to connect to us! Send a message to establish a connection. 3470 * that wants to connect to us! Send a message to establish a connection.
3600 */ 3471 */
3601 sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, 3472 sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, addr, addrlen);
3602 addr,
3603 addrlen);
3604 if (NULL == sock) 3473 if (NULL == sock)
3605 { 3474 {
3606 /* failed for some odd reason (out of sockets?); ignore attempt */ 3475 /* failed for some odd reason (out of sockets?); ignore attempt */
@@ -3608,23 +3477,23 @@ try_connection_reversal (void *cls,
3608 } 3477 }
3609 3478
3610 tcp_probe_ctx = GNUNET_new (struct TCPProbeContext); 3479 tcp_probe_ctx = GNUNET_new (struct TCPProbeContext);
3611 tcp_probe_ctx->message.header.size 3480 tcp_probe_ctx->message.header.size =
3612 = htons (sizeof (struct TCP_NAT_ProbeMessage)); 3481 htons (sizeof (struct TCP_NAT_ProbeMessage));
3613 tcp_probe_ctx->message.header.type 3482 tcp_probe_ctx->message.header.type =
3614 = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE); 3483 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE);
3615 tcp_probe_ctx->message.clientIdentity 3484 tcp_probe_ctx->message.clientIdentity = *plugin->env->my_identity;
3616 = *plugin->env->my_identity;
3617 tcp_probe_ctx->plugin = plugin; 3485 tcp_probe_ctx->plugin = plugin;
3618 tcp_probe_ctx->sock = sock; 3486 tcp_probe_ctx->sock = sock;
3619 GNUNET_CONTAINER_DLL_insert (plugin->probe_head, 3487 GNUNET_CONTAINER_DLL_insert (plugin->probe_head,
3620 plugin->probe_tail, 3488 plugin->probe_tail,
3621 tcp_probe_ctx); 3489 tcp_probe_ctx);
3622 tcp_probe_ctx->transmit_handle 3490 tcp_probe_ctx->transmit_handle =
3623 = GNUNET_CONNECTION_notify_transmit_ready (sock, 3491 GNUNET_CONNECTION_notify_transmit_ready (sock,
3624 ntohs (tcp_probe_ctx->message.header.size), 3492 ntohs (tcp_probe_ctx->message
3625 GNUNET_TIME_UNIT_FOREVER_REL, 3493 .header.size),
3626 &notify_send_probe, 3494 GNUNET_TIME_UNIT_FOREVER_REL,
3627 tcp_probe_ctx); 3495 &notify_send_probe,
3496 tcp_probe_ctx);
3628} 3497}
3629 3498
3630 3499
@@ -3636,8 +3505,7 @@ try_connection_reversal (void *cls,
3636 * @return the network type in HBO or #GNUNET_SYSERR 3505 * @return the network type in HBO or #GNUNET_SYSERR
3637 */ 3506 */
3638static enum GNUNET_NetworkType 3507static enum GNUNET_NetworkType
3639tcp_plugin_get_network (void *cls, 3508tcp_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session)
3640 struct GNUNET_ATS_Session *session)
3641{ 3509{
3642 return session->scope; 3510 return session->scope;
3643} 3511}
@@ -3664,25 +3532,25 @@ tcp_plugin_get_network_for_address (void *cls,
3664 size_t sbs; 3532 size_t sbs;
3665 3533
3666 addrlen = address->address_length; 3534 addrlen = address->address_length;
3667 if (addrlen == sizeof(struct IPv6TcpAddress)) 3535 if (addrlen == sizeof (struct IPv6TcpAddress))
3668 { 3536 {
3669 GNUNET_assert (NULL != address->address); /* make static analysis happy */ 3537 GNUNET_assert (NULL != address->address); /* make static analysis happy */
3670 t6 = address->address; 3538 t6 = address->address;
3671 memset (&a6, 0, sizeof(a6)); 3539 memset (&a6, 0, sizeof (a6));
3672#if HAVE_SOCKADDR_IN_SIN_LEN 3540#if HAVE_SOCKADDR_IN_SIN_LEN
3673 a6.sin6_len = sizeof (a6); 3541 a6.sin6_len = sizeof (a6);
3674#endif 3542#endif
3675 a6.sin6_family = AF_INET6; 3543 a6.sin6_family = AF_INET6;
3676 a6.sin6_port = t6->t6_port; 3544 a6.sin6_port = t6->t6_port;
3677 GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); 3545 GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr));
3678 sb = &a6; 3546 sb = &a6;
3679 sbs = sizeof(a6); 3547 sbs = sizeof (a6);
3680 } 3548 }
3681 else if (addrlen == sizeof(struct IPv4TcpAddress)) 3549 else if (addrlen == sizeof (struct IPv4TcpAddress))
3682 { 3550 {
3683 GNUNET_assert (NULL != address->address); /* make static analysis happy */ 3551 GNUNET_assert (NULL != address->address); /* make static analysis happy */
3684 t4 = address->address; 3552 t4 = address->address;
3685 memset (&a4, 0, sizeof(a4)); 3553 memset (&a4, 0, sizeof (a4));
3686#if HAVE_SOCKADDR_IN_SIN_LEN 3554#if HAVE_SOCKADDR_IN_SIN_LEN
3687 a4.sin_len = sizeof (a4); 3555 a4.sin_len = sizeof (a4);
3688#endif 3556#endif
@@ -3690,16 +3558,14 @@ tcp_plugin_get_network_for_address (void *cls,
3690 a4.sin_port = t4->t4_port; 3558 a4.sin_port = t4->t4_port;
3691 a4.sin_addr.s_addr = t4->ipv4_addr; 3559 a4.sin_addr.s_addr = t4->ipv4_addr;
3692 sb = &a4; 3560 sb = &a4;
3693 sbs = sizeof(a4); 3561 sbs = sizeof (a4);
3694 } 3562 }
3695 else 3563 else
3696 { 3564 {
3697 GNUNET_break (0); 3565 GNUNET_break (0);
3698 return GNUNET_NT_UNSPECIFIED; 3566 return GNUNET_NT_UNSPECIFIED;
3699 } 3567 }
3700 return plugin->env->get_address_type (plugin->env->cls, 3568 return plugin->env->get_address_type (plugin->env->cls, sb, sbs);
3701 sb,
3702 sbs);
3703} 3569}
3704 3570
3705 3571
@@ -3720,14 +3586,10 @@ send_session_info_iter (void *cls,
3720 struct Plugin *plugin = cls; 3586 struct Plugin *plugin = cls;
3721 struct GNUNET_ATS_Session *session = value; 3587 struct GNUNET_ATS_Session *session = value;
3722 3588
3723 notify_session_monitor (plugin, 3589 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT);
3724 session,
3725 GNUNET_TRANSPORT_SS_INIT);
3726 /* FIXME: cannot tell if this is up or not from current 3590 /* FIXME: cannot tell if this is up or not from current
3727 session state... */ 3591 session state... */
3728 notify_session_monitor (plugin, 3592 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP);
3729 session,
3730 GNUNET_TRANSPORT_SS_UP);
3731 return GNUNET_OK; 3593 return GNUNET_OK;
3732} 3594}
3733 3595
@@ -3773,17 +3635,17 @@ tcp_plugin_setup_monitor (void *cls,
3773void * 3635void *
3774libgnunet_plugin_transport_tcp_init (void *cls) 3636libgnunet_plugin_transport_tcp_init (void *cls)
3775{ 3637{
3776 static const struct GNUNET_SERVER_MessageHandler my_handlers[] = { 3638 static const struct GNUNET_SERVER_MessageHandler my_handlers[] =
3777 { &handle_tcp_welcome, NULL, 3639 {{&handle_tcp_welcome,
3640 NULL,
3778 GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME, 3641 GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME,
3779 sizeof(struct WelcomeMessage) }, 3642 sizeof (struct WelcomeMessage)},
3780 { &handle_tcp_nat_probe, NULL, 3643 {&handle_tcp_nat_probe,
3644 NULL,
3781 GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE, 3645 GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE,
3782 sizeof(struct TCP_NAT_ProbeMessage) }, 3646 sizeof (struct TCP_NAT_ProbeMessage)},
3783 { &handle_tcp_data, NULL, 3647 {&handle_tcp_data, NULL, GNUNET_MESSAGE_TYPE_ALL, 0},
3784 GNUNET_MESSAGE_TYPE_ALL, 0 }, 3648 {NULL, NULL, 0, 0}};
3785 { NULL, NULL, 0, 0 }
3786 };
3787 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; 3649 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
3788 struct GNUNET_TRANSPORT_PluginFunctions *api; 3650 struct GNUNET_TRANSPORT_PluginFunctions *api;
3789 struct Plugin *plugin; 3651 struct Plugin *plugin;
@@ -3794,7 +3656,7 @@ libgnunet_plugin_transport_tcp_init (void *cls)
3794 unsigned int i; 3656 unsigned int i;
3795 struct GNUNET_TIME_Relative idle_timeout; 3657 struct GNUNET_TIME_Relative idle_timeout;
3796#ifdef TCP_STEALTH 3658#ifdef TCP_STEALTH
3797 struct GNUNET_NETWORK_Handle *const*lsocks; 3659 struct GNUNET_NETWORK_Handle *const *lsocks;
3798#endif 3660#endif
3799 int ret; 3661 int ret;
3800 int ret_s; 3662 int ret_s;
@@ -3814,27 +3676,28 @@ libgnunet_plugin_transport_tcp_init (void *cls)
3814 } 3676 }
3815 3677
3816 GNUNET_assert (NULL != env->cfg); 3678 GNUNET_assert (NULL != env->cfg);
3817 if (GNUNET_OK != 3679 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg,
3818 GNUNET_CONFIGURATION_get_value_number (env->cfg, 3680 "transport-tcp",
3819 "transport-tcp", 3681 "MAX_CONNECTIONS",
3820 "MAX_CONNECTIONS", 3682 &max_connections))
3821 &max_connections))
3822 max_connections = 128; 3683 max_connections = 128;
3823 3684
3824 aport = 0; 3685 aport = 0;
3825 if ((GNUNET_OK != 3686 if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg,
3826 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp", 3687 "transport-tcp",
3827 "PORT", &bport)) || 3688 "PORT",
3689 &bport)) ||
3828 (bport > 65535) || 3690 (bport > 65535) ||
3829 ((GNUNET_OK == 3691 ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (env->cfg,
3830 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp", 3692 "transport-tcp",
3831 "ADVERTISED-PORT", &aport)) && 3693 "ADVERTISED-PORT",
3832 (aport > 65535) )) 3694 &aport)) &&
3695 (aport > 65535)))
3833 { 3696 {
3834 LOG(GNUNET_ERROR_TYPE_ERROR, 3697 LOG (GNUNET_ERROR_TYPE_ERROR,
3835 _("Require valid port number for service `%s' in configuration!\n"), 3698 _ ("Require valid port number for service `%s' in configuration!\n"),
3836 "transport-tcp"); 3699 "transport-tcp");
3837 return NULL ; 3700 return NULL;
3838 } 3701 }
3839 if (0 == aport) 3702 if (0 == aport)
3840 aport = bport; 3703 aport = bport;
@@ -3847,8 +3710,7 @@ libgnunet_plugin_transport_tcp_init (void *cls)
3847 LEGACY_SERVICE_OPTION_NONE); 3710 LEGACY_SERVICE_OPTION_NONE);
3848 if (NULL == service) 3711 if (NULL == service)
3849 { 3712 {
3850 LOG (GNUNET_ERROR_TYPE_WARNING, 3713 LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Failed to start service.\n"));
3851 _("Failed to start service.\n"));
3852 return NULL; 3714 return NULL;
3853 } 3715 }
3854 } 3716 }
@@ -3857,21 +3719,21 @@ libgnunet_plugin_transport_tcp_init (void *cls)
3857 3719
3858 api = NULL; 3720 api = NULL;
3859 plugin = GNUNET_new (struct Plugin); 3721 plugin = GNUNET_new (struct Plugin);
3860 plugin->sessionmap = GNUNET_CONTAINER_multipeermap_create (max_connections, 3722 plugin->sessionmap =
3861 GNUNET_YES); 3723 GNUNET_CONTAINER_multipeermap_create (max_connections, GNUNET_YES);
3862 plugin->max_connections = max_connections; 3724 plugin->max_connections = max_connections;
3863 plugin->open_port = bport; 3725 plugin->open_port = bport;
3864 plugin->adv_port = aport; 3726 plugin->adv_port = aport;
3865 plugin->env = env; 3727 plugin->env = env;
3866 plugin->my_welcome.header.size = htons (sizeof(struct WelcomeMessage)); 3728 plugin->my_welcome.header.size = htons (sizeof (struct WelcomeMessage));
3867 plugin->my_welcome.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME); 3729 plugin->my_welcome.header.type =
3730 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME);
3868 plugin->my_welcome.clientIdentity = *plugin->env->my_identity; 3731 plugin->my_welcome.clientIdentity = *plugin->env->my_identity;
3869 3732
3870 if ( (NULL != service) && 3733 if ((NULL != service) &&
3871 (GNUNET_YES == 3734 (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
3872 GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 3735 "transport-tcp",
3873 "transport-tcp", 3736 "TCP_STEALTH")))
3874 "TCP_STEALTH")) )
3875 { 3737 {
3876#ifdef TCP_STEALTH 3738#ifdef TCP_STEALTH
3877 plugin->myoptions |= TCP_OPTIONS_TCP_STEALTH; 3739 plugin->myoptions |= TCP_OPTIONS_TCP_STEALTH;
@@ -3880,59 +3742,57 @@ libgnunet_plugin_transport_tcp_init (void *cls)
3880 { 3742 {
3881 uint32_t len = sizeof (struct WelcomeMessage); 3743 uint32_t len = sizeof (struct WelcomeMessage);
3882 3744
3883 for (i=0;NULL!=lsocks[i];i++) 3745 for (i = 0; NULL != lsocks[i]; i++)
3884 { 3746 {
3885 if ( (GNUNET_OK != 3747 if (
3886 GNUNET_NETWORK_socket_setsockopt (lsocks[i], 3748 (GNUNET_OK !=
3887 IPPROTO_TCP, 3749 GNUNET_NETWORK_socket_setsockopt (lsocks[i],
3888 TCP_STEALTH, 3750 IPPROTO_TCP,
3889 env->my_identity, 3751 TCP_STEALTH,
3890 sizeof (struct GNUNET_PeerIdentity))) || 3752 env->my_identity,
3891 (GNUNET_OK != 3753 sizeof (
3892 GNUNET_NETWORK_socket_setsockopt (lsocks[i], 3754 struct GNUNET_PeerIdentity))) ||
3893 IPPROTO_TCP, 3755 (GNUNET_OK !=
3894 TCP_STEALTH_INTEGRITY_LEN, 3756 GNUNET_NETWORK_socket_setsockopt (lsocks[i],
3895 &len, 3757 IPPROTO_TCP,
3896 sizeof (len))) ) 3758 TCP_STEALTH_INTEGRITY_LEN,
3759 &len,
3760 sizeof (len))))
3897 { 3761 {
3898 /* TCP STEALTH not supported by kernel */ 3762 /* TCP STEALTH not supported by kernel */
3899 GNUNET_assert (0 == i); 3763 GNUNET_assert (0 == i);
3900 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 3764 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3901 _("TCP_STEALTH not supported on this platform.\n")); 3765 _ ("TCP_STEALTH not supported on this platform.\n"));
3902 goto die; 3766 goto die;
3903 } 3767 }
3904 } 3768 }
3905 } 3769 }
3906#else 3770#else
3907 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 3771 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3908 _("TCP_STEALTH not supported on this platform.\n")); 3772 _ ("TCP_STEALTH not supported on this platform.\n"));
3909 goto die; 3773 goto die;
3910#endif 3774#endif
3911 } 3775 }
3912 3776
3913 if ( (NULL != service) && 3777 if ((NULL != service) &&
3914 (GNUNET_SYSERR != 3778 (GNUNET_SYSERR !=
3915 (ret_s = 3779 (ret_s =
3916 get_server_addresses ("transport-tcp", 3780 get_server_addresses ("transport-tcp", env->cfg, &addrs, &addrlens))))
3917 env->cfg,
3918 &addrs,
3919 &addrlens))))
3920 { 3781 {
3921 for (ret = ret_s-1; ret >= 0; ret--) 3782 for (ret = ret_s - 1; ret >= 0; ret--)
3922 LOG (GNUNET_ERROR_TYPE_INFO, 3783 LOG (GNUNET_ERROR_TYPE_INFO,
3923 "Binding to address `%s'\n", 3784 "Binding to address `%s'\n",
3924 GNUNET_a2s (addrs[ret], addrlens[ret])); 3785 GNUNET_a2s (addrs[ret], addrlens[ret]));
3925 plugin->nat 3786 plugin->nat = GNUNET_NAT_register (env->cfg,
3926 = GNUNET_NAT_register (env->cfg, 3787 "transport-tcp",
3927 "transport-tcp", 3788 IPPROTO_TCP,
3928 IPPROTO_TCP, 3789 (unsigned int) ret_s,
3929 (unsigned int) ret_s, 3790 (const struct sockaddr **) addrs,
3930 (const struct sockaddr **) addrs, 3791 addrlens,
3931 addrlens, 3792 &tcp_nat_port_map_callback,
3932 &tcp_nat_port_map_callback, 3793 &try_connection_reversal,
3933 &try_connection_reversal, 3794 plugin);
3934 plugin); 3795 for (ret = ret_s - 1; ret >= 0; ret--)
3935 for (ret = ret_s -1; ret >= 0; ret--)
3936 GNUNET_free (addrs[ret]); 3796 GNUNET_free (addrs[ret]);
3937 GNUNET_free_non_null (addrs); 3797 GNUNET_free_non_null (addrs);
3938 GNUNET_free_non_null (addrlens); 3798 GNUNET_free_non_null (addrlens);
@@ -3941,7 +3801,7 @@ libgnunet_plugin_transport_tcp_init (void *cls)
3941 { 3801 {
3942 plugin->nat = GNUNET_NAT_register (plugin->env->cfg, 3802 plugin->nat = GNUNET_NAT_register (plugin->env->cfg,
3943 "transport-tcp", 3803 "transport-tcp",
3944 IPPROTO_TCP, 3804 IPPROTO_TCP,
3945 0, 3805 0,
3946 NULL, 3806 NULL,
3947 NULL, 3807 NULL,
@@ -3972,52 +3832,44 @@ libgnunet_plugin_transport_tcp_init (void *cls)
3972 } 3832 }
3973 else 3833 else
3974 { 3834 {
3975 if (GNUNET_OK != 3835 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (env->cfg,
3976 GNUNET_CONFIGURATION_get_value_time (env->cfg, 3836 "transport-tcp",
3977 "transport-tcp", 3837 "TIMEOUT",
3978 "TIMEOUT", 3838 &idle_timeout))
3979 &idle_timeout))
3980 { 3839 {
3981 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 3840 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
3982 "transport-tcp", 3841 "transport-tcp",
3983 "TIMEOUT"); 3842 "TIMEOUT");
3984 goto die; 3843 goto die;
3985 } 3844 }
3986 plugin->server 3845 plugin->server = GNUNET_SERVER_create_with_sockets (NULL,
3987 = GNUNET_SERVER_create_with_sockets (NULL, 3846 plugin,
3988 plugin, 3847 NULL,
3989 NULL, 3848 idle_timeout,
3990 idle_timeout, 3849 GNUNET_YES);
3991 GNUNET_YES);
3992 } 3850 }
3993 plugin->handlers = GNUNET_malloc (sizeof (my_handlers)); 3851 plugin->handlers = GNUNET_malloc (sizeof (my_handlers));
3994 GNUNET_memcpy (plugin->handlers, 3852 GNUNET_memcpy (plugin->handlers, my_handlers, sizeof (my_handlers));
3995 my_handlers, 3853 for (i = 0;
3996 sizeof(my_handlers)); 3854 i < sizeof (my_handlers) / sizeof (struct GNUNET_SERVER_MessageHandler);
3997 for (i = 0;i < sizeof(my_handlers) / sizeof(struct GNUNET_SERVER_MessageHandler);i++) 3855 i++)
3998 plugin->handlers[i].callback_cls = plugin; 3856 plugin->handlers[i].callback_cls = plugin;
3999 3857
4000 GNUNET_SERVER_add_handlers (plugin->server, 3858 GNUNET_SERVER_add_handlers (plugin->server, plugin->handlers);
4001 plugin->handlers); 3859 GNUNET_SERVER_connect_notify (plugin->server, &connect_notify, plugin);
4002 GNUNET_SERVER_connect_notify (plugin->server, 3860 GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin);
4003 &connect_notify, 3861 plugin->nat_wait_conns =
4004 plugin); 3862 GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES);
4005 GNUNET_SERVER_disconnect_notify (plugin->server,
4006 &disconnect_notify,
4007 plugin);
4008 plugin->nat_wait_conns = GNUNET_CONTAINER_multipeermap_create (16,
4009 GNUNET_YES);
4010 if (0 != bport) 3863 if (0 != bport)
4011 LOG (GNUNET_ERROR_TYPE_INFO, 3864 LOG (GNUNET_ERROR_TYPE_INFO,
4012 _("TCP transport listening on port %llu\n"), 3865 _ ("TCP transport listening on port %llu\n"),
4013 bport); 3866 bport);
4014 else 3867 else
4015 LOG (GNUNET_ERROR_TYPE_INFO, 3868 LOG (GNUNET_ERROR_TYPE_INFO,
4016 _("TCP transport not listening on any port (client only)\n")); 3869 _ ("TCP transport not listening on any port (client only)\n"));
4017 if ( (aport != bport) && 3870 if ((aport != bport) && (0 != bport))
4018 (0 != bport) )
4019 LOG (GNUNET_ERROR_TYPE_INFO, 3871 LOG (GNUNET_ERROR_TYPE_INFO,
4020 _("TCP transport advertises itself as being on port %llu\n"), 3872 _ ("TCP transport advertises itself as being on port %llu\n"),
4021 aport); 3873 aport);
4022 /* Initially set connections to 0 */ 3874 /* Initially set connections to 0 */
4023 GNUNET_STATISTICS_set (plugin->env->stats, 3875 GNUNET_STATISTICS_set (plugin->env->stats,
@@ -4026,7 +3878,7 @@ libgnunet_plugin_transport_tcp_init (void *cls)
4026 GNUNET_NO); 3878 GNUNET_NO);
4027 return api; 3879 return api;
4028 3880
4029 die: 3881die:
4030 if (NULL != plugin->nat) 3882 if (NULL != plugin->nat)
4031 GNUNET_NAT_unregister (plugin->nat); 3883 GNUNET_NAT_unregister (plugin->nat);
4032 GNUNET_CONTAINER_multipeermap_destroy (plugin->sessionmap); 3884 GNUNET_CONTAINER_multipeermap_destroy (plugin->sessionmap);
@@ -4055,11 +3907,10 @@ libgnunet_plugin_transport_tcp_done (void *cls)
4055 3907
4056 if (NULL == plugin) 3908 if (NULL == plugin)
4057 { 3909 {
4058 GNUNET_free(api); 3910 GNUNET_free (api);
4059 return NULL ; 3911 return NULL;
4060 } 3912 }
4061 LOG (GNUNET_ERROR_TYPE_DEBUG, 3913 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down TCP plugin\n");
4062 "Shutting down TCP plugin\n");
4063 3914
4064 /* Removing leftover sessions */ 3915 /* Removing leftover sessions */
4065 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, 3916 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap,
@@ -4077,9 +3928,7 @@ libgnunet_plugin_transport_tcp_done (void *cls)
4077 plugin->ppc_dll_tail, 3928 plugin->ppc_dll_tail,
4078 cur); 3929 cur);
4079 GNUNET_RESOLVER_request_cancel (cur->resolver_handle); 3930 GNUNET_RESOLVER_request_cancel (cur->resolver_handle);
4080 cur->asc (cur->asc_cls, 3931 cur->asc (cur->asc_cls, NULL, GNUNET_OK);
4081 NULL,
4082 GNUNET_OK);
4083 GNUNET_free (cur); 3932 GNUNET_free (cur);
4084 } 3933 }
4085 3934
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index b05192e06..1d34cdd1a 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -40,12 +40,13 @@
40#include "gnunet_transport_plugin.h" 40#include "gnunet_transport_plugin.h"
41#include "transport.h" 41#include "transport.h"
42 42
43#define LOG(kind,...) GNUNET_log_from (kind, "transport-udp", __VA_ARGS__) 43#define LOG(kind, ...) GNUNET_log_from (kind, "transport-udp", __VA_ARGS__)
44 44
45/** 45/**
46 * After how much inactivity should a UDP session time out? 46 * After how much inactivity should a UDP session time out?
47 */ 47 */
48#define UDP_SESSION_TIME_OUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) 48#define UDP_SESSION_TIME_OUT \
49 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
49 50
50/** 51/**
51 * Number of messages we can defragment in parallel. We only really 52 * Number of messages we can defragment in parallel. We only really
@@ -86,7 +87,6 @@ struct UDPMessage
86 * What is the identity of the sender 87 * What is the identity of the sender
87 */ 88 */
88 struct GNUNET_PeerIdentity sender; 89 struct GNUNET_PeerIdentity sender;
89
90}; 90};
91 91
92 92
@@ -144,7 +144,6 @@ struct PrettyPrinterContext
144 * Port to add after the IP address. 144 * Port to add after the IP address.
145 */ 145 */
146 uint16_t port; 146 uint16_t port;
147
148}; 147};
149 148
150 149
@@ -248,7 +247,6 @@ struct GNUNET_ATS_Session
248}; 247};
249 248
250 249
251
252/** 250/**
253 * Data structure to track defragmentation contexts based 251 * Data structure to track defragmentation contexts based
254 * on the source of the UDP traffic. 252 * on the source of the UDP traffic.
@@ -374,7 +372,6 @@ struct UDP_FragmentationContext
374 * Bytes used to send all fragments on wire including UDP overhead 372 * Bytes used to send all fragments on wire including UDP overhead
375 */ 373 */
376 size_t on_wire_size; 374 size_t on_wire_size;
377
378}; 375};
379 376
380 377
@@ -388,10 +385,9 @@ struct UDP_FragmentationContext
388 * #GNUNET_SYSERR if the target disconnected 385 * #GNUNET_SYSERR if the target disconnected
389 * or we had a timeout or other trouble sending 386 * or we had a timeout or other trouble sending
390 */ 387 */
391typedef void 388typedef void (*QueueContinuation) (void *cls,
392(*QueueContinuation) (void *cls, 389 struct UDP_MessageWrapper *udpw,
393 struct UDP_MessageWrapper *udpw, 390 int result);
394 int result);
395 391
396 392
397/** 393/**
@@ -474,7 +470,6 @@ struct UDP_MessageWrapper
474 * Payload size of original message. 470 * Payload size of original message.
475 */ 471 */
476 size_t payload_size; 472 size_t payload_size;
477
478}; 473};
479 474
480 475
@@ -501,7 +496,6 @@ struct UDP_ACK_Message
501 * What is the identity of the sender 496 * What is the identity of the sender
502 */ 497 */
503 struct GNUNET_PeerIdentity sender; 498 struct GNUNET_PeerIdentity sender;
504
505}; 499};
506 500
507GNUNET_NETWORK_STRUCT_END 501GNUNET_NETWORK_STRUCT_END
@@ -529,9 +523,7 @@ notify_session_monitor (struct Plugin *plugin,
529 return; 523 return;
530 if (GNUNET_YES == session->in_destroy) 524 if (GNUNET_YES == session->in_destroy)
531 return; /* already destroyed, just RC>0 left-over actions */ 525 return; /* already destroyed, just RC>0 left-over actions */
532 memset (&info, 526 memset (&info, 0, sizeof (info));
533 0,
534 sizeof (info));
535 info.state = state; 527 info.state = state;
536 info.is_inbound = GNUNET_SYSERR; /* hard to say */ 528 info.is_inbound = GNUNET_SYSERR; /* hard to say */
537 info.num_msg_pending = session->msgs_in_queue; 529 info.num_msg_pending = session->msgs_in_queue;
@@ -541,9 +533,7 @@ notify_session_monitor (struct Plugin *plugin,
541 to receive from others) */ 533 to receive from others) */
542 info.session_timeout = session->timeout; 534 info.session_timeout = session->timeout;
543 info.address = session->address; 535 info.address = session->address;
544 plugin->sic (plugin->sic_cls, 536 plugin->sic (plugin->sic_cls, session, &info);
545 session,
546 &info);
547} 537}
548 538
549 539
@@ -563,12 +553,8 @@ send_session_info_iter (void *cls,
563 struct Plugin *plugin = cls; 553 struct Plugin *plugin = cls;
564 struct GNUNET_ATS_Session *session = value; 554 struct GNUNET_ATS_Session *session = value;
565 555
566 notify_session_monitor (plugin, 556 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT);
567 session, 557 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP);
568 GNUNET_TRANSPORT_SS_INIT);
569 notify_session_monitor (plugin,
570 session,
571 GNUNET_TRANSPORT_SS_UP);
572 return GNUNET_OK; 558 return GNUNET_OK;
573} 559}
574 560
@@ -600,9 +586,7 @@ udp_plugin_setup_monitor (void *cls,
600 &send_session_info_iter, 586 &send_session_info_iter,
601 plugin); 587 plugin);
602 /* signal end of first iteration */ 588 /* signal end of first iteration */
603 sic (sic_cls, 589 sic (sic_cls, NULL, NULL);
604 NULL,
605 NULL);
606 } 590 }
607} 591}
608 592
@@ -625,9 +609,7 @@ free_session (struct GNUNET_ATS_Session *s)
625 } 609 }
626 if (NULL != s->frag_ctx) 610 if (NULL != s->frag_ctx)
627 { 611 {
628 GNUNET_FRAGMENT_context_destroy (s->frag_ctx->frag, 612 GNUNET_FRAGMENT_context_destroy (s->frag_ctx->frag, NULL, NULL);
629 NULL,
630 NULL);
631 GNUNET_free (s->frag_ctx); 613 GNUNET_free (s->frag_ctx);
632 s->frag_ctx = NULL; 614 s->frag_ctx = NULL;
633 } 615 }
@@ -663,8 +645,7 @@ udp_query_keepalive_factor (void *cls)
663 * @return the network type 645 * @return the network type
664 */ 646 */
665static enum GNUNET_NetworkType 647static enum GNUNET_NetworkType
666udp_plugin_get_network (void *cls, 648udp_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session)
667 struct GNUNET_ATS_Session *session)
668{ 649{
669 return session->scope; 650 return session->scope;
670} 651}
@@ -691,25 +672,25 @@ udp_plugin_get_network_for_address (void *cls,
691 size_t sbs; 672 size_t sbs;
692 673
693 addrlen = address->address_length; 674 addrlen = address->address_length;
694 if (addrlen == sizeof(struct IPv6UdpAddress)) 675 if (addrlen == sizeof (struct IPv6UdpAddress))
695 { 676 {
696 GNUNET_assert (NULL != address->address); /* make static analysis happy */ 677 GNUNET_assert (NULL != address->address); /* make static analysis happy */
697 u6 = address->address; 678 u6 = address->address;
698 memset (&a6, 0, sizeof(a6)); 679 memset (&a6, 0, sizeof (a6));
699#if HAVE_SOCKADDR_IN_SIN_LEN 680#if HAVE_SOCKADDR_IN_SIN_LEN
700 a6.sin6_len = sizeof (a6); 681 a6.sin6_len = sizeof (a6);
701#endif 682#endif
702 a6.sin6_family = AF_INET6; 683 a6.sin6_family = AF_INET6;
703 a6.sin6_port = u6->u6_port; 684 a6.sin6_port = u6->u6_port;
704 GNUNET_memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof(struct in6_addr)); 685 GNUNET_memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof (struct in6_addr));
705 sb = &a6; 686 sb = &a6;
706 sbs = sizeof(a6); 687 sbs = sizeof (a6);
707 } 688 }
708 else if (addrlen == sizeof(struct IPv4UdpAddress)) 689 else if (addrlen == sizeof (struct IPv4UdpAddress))
709 { 690 {
710 GNUNET_assert (NULL != address->address); /* make static analysis happy */ 691 GNUNET_assert (NULL != address->address); /* make static analysis happy */
711 u4 = address->address; 692 u4 = address->address;
712 memset (&a4, 0, sizeof(a4)); 693 memset (&a4, 0, sizeof (a4));
713#if HAVE_SOCKADDR_IN_SIN_LEN 694#if HAVE_SOCKADDR_IN_SIN_LEN
714 a4.sin_len = sizeof (a4); 695 a4.sin_len = sizeof (a4);
715#endif 696#endif
@@ -717,16 +698,14 @@ udp_plugin_get_network_for_address (void *cls,
717 a4.sin_port = u4->u4_port; 698 a4.sin_port = u4->u4_port;
718 a4.sin_addr.s_addr = u4->ipv4_addr; 699 a4.sin_addr.s_addr = u4->ipv4_addr;
719 sb = &a4; 700 sb = &a4;
720 sbs = sizeof(a4); 701 sbs = sizeof (a4);
721 } 702 }
722 else 703 else
723 { 704 {
724 GNUNET_break (0); 705 GNUNET_break (0);
725 return GNUNET_NT_UNSPECIFIED; 706 return GNUNET_NT_UNSPECIFIED;
726 } 707 }
727 return plugin->env->get_address_type (plugin->env->cls, 708 return plugin->env->get_address_type (plugin->env->cls, sb, sbs);
728 sb,
729 sbs);
730} 709}
731 710
732 711
@@ -767,8 +746,7 @@ schedule_select_v4 (struct Plugin *plugin)
767 struct UDP_MessageWrapper *udpw; 746 struct UDP_MessageWrapper *udpw;
768 struct UDP_MessageWrapper *min_udpw; 747 struct UDP_MessageWrapper *min_udpw;
769 748
770 if ( (GNUNET_YES == plugin->enable_ipv4) && 749 if ((GNUNET_YES == plugin->enable_ipv4) && (NULL != plugin->sockv4))
771 (NULL != plugin->sockv4) )
772 { 750 {
773 /* Find a message ready to send: 751 /* Find a message ready to send:
774 * Flow delay from other peer is expired or not set (0) */ 752 * Flow delay from other peer is expired or not set (0) */
@@ -804,11 +782,11 @@ schedule_select_v4 (struct Plugin *plugin)
804 GNUNET_i2s (&min_udpw->session->target)); 782 GNUNET_i2s (&min_udpw->session->target));
805 } 783 }
806 } 784 }
807 plugin->select_task_v4 785 plugin->select_task_v4 =
808 = GNUNET_SCHEDULER_add_read_net (min_delay, 786 GNUNET_SCHEDULER_add_read_net (min_delay,
809 plugin->sockv4, 787 plugin->sockv4,
810 &udp_plugin_select_v4, 788 &udp_plugin_select_v4,
811 plugin); 789 plugin);
812 } 790 }
813} 791}
814 792
@@ -826,8 +804,7 @@ schedule_select_v6 (struct Plugin *plugin)
826 struct UDP_MessageWrapper *udpw; 804 struct UDP_MessageWrapper *udpw;
827 struct UDP_MessageWrapper *min_udpw; 805 struct UDP_MessageWrapper *min_udpw;
828 806
829 if ( (GNUNET_YES == plugin->enable_ipv6) && 807 if ((GNUNET_YES == plugin->enable_ipv6) && (NULL != plugin->sockv6))
830 (NULL != plugin->sockv6) )
831 { 808 {
832 min_delay = GNUNET_TIME_UNIT_FOREVER_REL; 809 min_delay = GNUNET_TIME_UNIT_FOREVER_REL;
833 min_udpw = NULL; 810 min_udpw = NULL;
@@ -861,11 +838,11 @@ schedule_select_v6 (struct Plugin *plugin)
861 GNUNET_i2s (&min_udpw->session->target)); 838 GNUNET_i2s (&min_udpw->session->target));
862 } 839 }
863 } 840 }
864 plugin->select_task_v6 841 plugin->select_task_v6 =
865 = GNUNET_SCHEDULER_add_read_net (min_delay, 842 GNUNET_SCHEDULER_add_read_net (min_delay,
866 plugin->sockv6, 843 plugin->sockv6,
867 &udp_plugin_select_v6, 844 &udp_plugin_select_v6,
868 plugin); 845 plugin);
869 } 846 }
870} 847}
871 848
@@ -885,9 +862,7 @@ schedule_select_v6 (struct Plugin *plugin)
885 * @return string representing the same address 862 * @return string representing the same address
886 */ 863 */
887const char * 864const char *
888udp_address_to_string (void *cls, 865udp_address_to_string (void *cls, const void *addr, size_t addrlen)
889 const void *addr,
890 size_t addrlen)
891{ 866{
892 static char rbuf[INET6_ADDRSTRLEN + 10]; 867 static char rbuf[INET6_ADDRSTRLEN + 10];
893 char buf[INET6_ADDRSTRLEN]; 868 char buf[INET6_ADDRSTRLEN];
@@ -906,7 +881,7 @@ udp_address_to_string (void *cls,
906 return NULL; 881 return NULL;
907 } 882 }
908 883
909 if (addrlen == sizeof(struct IPv6UdpAddress)) 884 if (addrlen == sizeof (struct IPv6UdpAddress))
910 { 885 {
911 t6 = addr; 886 t6 = addr;
912 af = AF_INET6; 887 af = AF_INET6;
@@ -915,7 +890,7 @@ udp_address_to_string (void *cls,
915 a6 = t6->ipv6_addr; 890 a6 = t6->ipv6_addr;
916 sb = &a6; 891 sb = &a6;
917 } 892 }
918 else if (addrlen == sizeof(struct IPv4UdpAddress)) 893 else if (addrlen == sizeof (struct IPv4UdpAddress))
919 { 894 {
920 t4 = addr; 895 t4 = addr;
921 af = AF_INET; 896 af = AF_INET;
@@ -929,15 +904,10 @@ udp_address_to_string (void *cls,
929 GNUNET_break_op (0); 904 GNUNET_break_op (0);
930 return NULL; 905 return NULL;
931 } 906 }
932 inet_ntop (af, 907 inet_ntop (af, sb, buf, INET6_ADDRSTRLEN);
933 sb,
934 buf,
935 INET6_ADDRSTRLEN);
936 GNUNET_snprintf (rbuf, 908 GNUNET_snprintf (rbuf,
937 sizeof(rbuf), 909 sizeof (rbuf),
938 (af == AF_INET6) 910 (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u",
939 ? "%s.%u.[%s]:%u"
940 : "%s.%u.%s:%u",
941 PLUGIN_NAME, 911 PLUGIN_NAME,
942 options, 912 options,
943 buf, 913 buf,
@@ -1012,44 +982,42 @@ udp_string_to_address (void *cls,
1012 address++; 982 address++;
1013 983
1014 if (GNUNET_OK != 984 if (GNUNET_OK !=
1015 GNUNET_STRINGS_to_address_ip (address, 985 GNUNET_STRINGS_to_address_ip (address, strlen (address), &socket_address))
1016 strlen (address),
1017 &socket_address))
1018 { 986 {
1019 GNUNET_break (0); 987 GNUNET_break (0);
1020 GNUNET_free (plugin); 988 GNUNET_free (plugin);
1021 return GNUNET_SYSERR; 989 return GNUNET_SYSERR;
1022 } 990 }
1023 GNUNET_free(plugin); 991 GNUNET_free (plugin);
1024 992
1025 switch (socket_address.ss_family) 993 switch (socket_address.ss_family)
1026 { 994 {
1027 case AF_INET: 995 case AF_INET: {
1028 { 996 struct IPv4UdpAddress *u4;
1029 struct IPv4UdpAddress *u4; 997 const struct sockaddr_in *in4 =
1030 const struct sockaddr_in *in4 = (const struct sockaddr_in *) &socket_address; 998 (const struct sockaddr_in *) &socket_address;
1031 999
1032 u4 = GNUNET_new (struct IPv4UdpAddress); 1000 u4 = GNUNET_new (struct IPv4UdpAddress);
1033 u4->options = htonl (options); 1001 u4->options = htonl (options);
1034 u4->ipv4_addr = in4->sin_addr.s_addr; 1002 u4->ipv4_addr = in4->sin_addr.s_addr;
1035 u4->u4_port = in4->sin_port; 1003 u4->u4_port = in4->sin_port;
1036 *buf = u4; 1004 *buf = u4;
1037 *added = sizeof (struct IPv4UdpAddress); 1005 *added = sizeof (struct IPv4UdpAddress);
1038 return GNUNET_OK; 1006 return GNUNET_OK;
1039 } 1007 }
1040 case AF_INET6: 1008 case AF_INET6: {
1041 { 1009 struct IPv6UdpAddress *u6;
1042 struct IPv6UdpAddress *u6; 1010 const struct sockaddr_in6 *in6 =
1043 const struct sockaddr_in6 *in6 = (const struct sockaddr_in6 *) &socket_address; 1011 (const struct sockaddr_in6 *) &socket_address;
1044 1012
1045 u6 = GNUNET_new (struct IPv6UdpAddress); 1013 u6 = GNUNET_new (struct IPv6UdpAddress);
1046 u6->options = htonl (options); 1014 u6->options = htonl (options);
1047 u6->ipv6_addr = in6->sin6_addr; 1015 u6->ipv6_addr = in6->sin6_addr;
1048 u6->u6_port = in6->sin6_port; 1016 u6->u6_port = in6->sin6_port;
1049 *buf = u6; 1017 *buf = u6;
1050 *added = sizeof (struct IPv6UdpAddress); 1018 *added = sizeof (struct IPv6UdpAddress);
1051 return GNUNET_OK; 1019 return GNUNET_OK;
1052 } 1020 }
1053 default: 1021 default:
1054 GNUNET_break (0); 1022 GNUNET_break (0);
1055 return GNUNET_SYSERR; 1023 return GNUNET_SYSERR;
@@ -1064,8 +1032,7 @@ udp_string_to_address (void *cls,
1064 * @param hostname result from DNS resolver 1032 * @param hostname result from DNS resolver
1065 */ 1033 */
1066static void 1034static void
1067append_port (void *cls, 1035append_port (void *cls, const char *hostname)
1068 const char *hostname)
1069{ 1036{
1070 struct PrettyPrinterContext *ppc = cls; 1037 struct PrettyPrinterContext *ppc = cls;
1071 struct Plugin *plugin = ppc->plugin; 1038 struct Plugin *plugin = ppc->plugin;
@@ -1078,9 +1045,7 @@ append_port (void *cls,
1078 plugin->ppc_dll_tail, 1045 plugin->ppc_dll_tail,
1079 ppc); 1046 ppc);
1080 ppc->resolver_handle = NULL; 1047 ppc->resolver_handle = NULL;
1081 ppc->asc (ppc->asc_cls, 1048 ppc->asc (ppc->asc_cls, NULL, GNUNET_OK);
1082 NULL,
1083 GNUNET_OK);
1084 GNUNET_free (ppc); 1049 GNUNET_free (ppc);
1085 return; 1050 return;
1086 } 1051 }
@@ -1098,9 +1063,7 @@ append_port (void *cls,
1098 ppc->options, 1063 ppc->options,
1099 hostname, 1064 hostname,
1100 ppc->port); 1065 ppc->port);
1101 ppc->asc (ppc->asc_cls, 1066 ppc->asc (ppc->asc_cls, ret, GNUNET_OK);
1102 ret,
1103 GNUNET_OK);
1104 GNUNET_free (ret); 1067 GNUNET_free (ret);
1105} 1068}
1106 1069
@@ -1140,12 +1103,10 @@ udp_plugin_address_pretty_printer (void *cls,
1140 uint16_t port; 1103 uint16_t port;
1141 uint32_t options; 1104 uint32_t options;
1142 1105
1143 if (addrlen == sizeof(struct IPv6UdpAddress)) 1106 if (addrlen == sizeof (struct IPv6UdpAddress))
1144 { 1107 {
1145 u6 = addr; 1108 u6 = addr;
1146 memset (&a6, 1109 memset (&a6, 0, sizeof (a6));
1147 0,
1148 sizeof (a6));
1149 a6.sin6_family = AF_INET6; 1110 a6.sin6_family = AF_INET6;
1150#if HAVE_SOCKADDR_IN_SIN_LEN 1111#if HAVE_SOCKADDR_IN_SIN_LEN
1151 a6.sin6_len = sizeof (a6); 1112 a6.sin6_len = sizeof (a6);
@@ -1160,9 +1121,7 @@ udp_plugin_address_pretty_printer (void *cls,
1160 else if (addrlen == sizeof (struct IPv4UdpAddress)) 1121 else if (addrlen == sizeof (struct IPv4UdpAddress))
1161 { 1122 {
1162 u4 = addr; 1123 u4 = addr;
1163 memset (&a4, 1124 memset (&a4, 0, sizeof (a4));
1164 0,
1165 sizeof(a4));
1166 a4.sin_family = AF_INET; 1125 a4.sin_family = AF_INET;
1167#if HAVE_SOCKADDR_IN_SIN_LEN 1126#if HAVE_SOCKADDR_IN_SIN_LEN
1168 a4.sin_len = sizeof (a4); 1127 a4.sin_len = sizeof (a4);
@@ -1172,18 +1131,14 @@ udp_plugin_address_pretty_printer (void *cls,
1172 port = ntohs (u4->u4_port); 1131 port = ntohs (u4->u4_port);
1173 options = ntohl (u4->options); 1132 options = ntohl (u4->options);
1174 sb = (const struct sockaddr *) &a4; 1133 sb = (const struct sockaddr *) &a4;
1175 sbs = sizeof(a4); 1134 sbs = sizeof (a4);
1176 } 1135 }
1177 else 1136 else
1178 { 1137 {
1179 /* invalid address */ 1138 /* invalid address */
1180 GNUNET_break_op (0); 1139 GNUNET_break_op (0);
1181 asc (asc_cls, 1140 asc (asc_cls, NULL, GNUNET_SYSERR);
1182 NULL, 1141 asc (asc_cls, NULL, GNUNET_OK);
1183 GNUNET_SYSERR);
1184 asc (asc_cls,
1185 NULL,
1186 GNUNET_OK);
1187 return; 1142 return;
1188 } 1143 }
1189 ppc = GNUNET_new (struct PrettyPrinterContext); 1144 ppc = GNUNET_new (struct PrettyPrinterContext);
@@ -1196,16 +1151,13 @@ udp_plugin_address_pretty_printer (void *cls,
1196 ppc->ipv6 = GNUNET_YES; 1151 ppc->ipv6 = GNUNET_YES;
1197 else 1152 else
1198 ppc->ipv6 = GNUNET_NO; 1153 ppc->ipv6 = GNUNET_NO;
1199 GNUNET_CONTAINER_DLL_insert (plugin->ppc_dll_head, 1154 GNUNET_CONTAINER_DLL_insert (plugin->ppc_dll_head, plugin->ppc_dll_tail, ppc);
1200 plugin->ppc_dll_tail, 1155 ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb,
1201 ppc); 1156 sbs,
1202 ppc->resolver_handle 1157 ! numeric,
1203 = GNUNET_RESOLVER_hostname_get (sb, 1158 timeout,
1204 sbs, 1159 &append_port,
1205 ! numeric, 1160 ppc);
1206 timeout,
1207 &append_port,
1208 ppc);
1209} 1161}
1210 1162
1211 1163
@@ -1219,11 +1171,9 @@ udp_plugin_address_pretty_printer (void *cls,
1219 * @return #GNUNET_OK if port is either our open or advertised port 1171 * @return #GNUNET_OK if port is either our open or advertised port
1220 */ 1172 */
1221static int 1173static int
1222check_port (const struct Plugin *plugin, 1174check_port (const struct Plugin *plugin, uint16_t in_port)
1223 uint16_t in_port)
1224{ 1175{
1225 if ( (plugin->port == in_port) || 1176 if ((plugin->port == in_port) || (plugin->aport == in_port))
1226 (plugin->aport == in_port) )
1227 return GNUNET_OK; 1177 return GNUNET_OK;
1228 return GNUNET_SYSERR; 1178 return GNUNET_SYSERR;
1229} 1179}
@@ -1245,21 +1195,18 @@ check_port (const struct Plugin *plugin,
1245 * and transport, #GNUNET_SYSERR if not 1195 * and transport, #GNUNET_SYSERR if not
1246 */ 1196 */
1247static int 1197static int
1248udp_plugin_check_address (void *cls, 1198udp_plugin_check_address (void *cls, const void *addr, size_t addrlen)
1249 const void *addr,
1250 size_t addrlen)
1251{ 1199{
1252 struct Plugin *plugin = cls; 1200 struct Plugin *plugin = cls;
1253 const struct IPv4UdpAddress *v4; 1201 const struct IPv4UdpAddress *v4;
1254 const struct IPv6UdpAddress *v6; 1202 const struct IPv6UdpAddress *v6;
1255 1203
1256 if (sizeof(struct IPv4UdpAddress) == addrlen) 1204 if (sizeof (struct IPv4UdpAddress) == addrlen)
1257 { 1205 {
1258 struct sockaddr_in s4; 1206 struct sockaddr_in s4;
1259 1207
1260 v4 = (const struct IPv4UdpAddress *) addr; 1208 v4 = (const struct IPv4UdpAddress *) addr;
1261 if (GNUNET_OK != check_port (plugin, 1209 if (GNUNET_OK != check_port (plugin, ntohs (v4->u4_port)))
1262 ntohs (v4->u4_port)))
1263 return GNUNET_SYSERR; 1210 return GNUNET_SYSERR;
1264 memset (&s4, 0, sizeof (s4)); 1211 memset (&s4, 0, sizeof (s4));
1265 s4.sin_family = AF_INET; 1212 s4.sin_family = AF_INET;
@@ -1270,12 +1217,10 @@ udp_plugin_check_address (void *cls,
1270 s4.sin_addr.s_addr = v4->ipv4_addr; 1217 s4.sin_addr.s_addr = v4->ipv4_addr;
1271 1218
1272 if (GNUNET_OK != 1219 if (GNUNET_OK !=
1273 GNUNET_NAT_test_address (plugin->nat, 1220 GNUNET_NAT_test_address (plugin->nat, &s4, sizeof (struct sockaddr_in)))
1274 &s4,
1275 sizeof (struct sockaddr_in)))
1276 return GNUNET_SYSERR; 1221 return GNUNET_SYSERR;
1277 } 1222 }
1278 else if (sizeof(struct IPv6UdpAddress) == addrlen) 1223 else if (sizeof (struct IPv6UdpAddress) == addrlen)
1279 { 1224 {
1280 struct sockaddr_in6 s6; 1225 struct sockaddr_in6 s6;
1281 1226
@@ -1290,10 +1235,9 @@ udp_plugin_check_address (void *cls,
1290 s6.sin6_port = v6->u6_port; 1235 s6.sin6_port = v6->u6_port;
1291 s6.sin6_addr = v6->ipv6_addr; 1236 s6.sin6_addr = v6->ipv6_addr;
1292 1237
1293 if (GNUNET_OK != 1238 if (GNUNET_OK != GNUNET_NAT_test_address (plugin->nat,
1294 GNUNET_NAT_test_address (plugin->nat, 1239 &s6,
1295 &s6, 1240 sizeof (struct sockaddr_in6)))
1296 sizeof(struct sockaddr_in6)))
1297 return GNUNET_SYSERR; 1241 return GNUNET_SYSERR;
1298 } 1242 }
1299 else 1243 else
@@ -1319,9 +1263,9 @@ udp_plugin_check_address (void *cls,
1319 */ 1263 */
1320static void 1264static void
1321udp_nat_port_map_callback (void *cls, 1265udp_nat_port_map_callback (void *cls,
1322 void **app_ctx, 1266 void **app_ctx,
1323 int add_remove, 1267 int add_remove,
1324 enum GNUNET_NAT_AddressClass ac, 1268 enum GNUNET_NAT_AddressClass ac,
1325 const struct sockaddr *addr, 1269 const struct sockaddr *addr,
1326 socklen_t addrlen) 1270 socklen_t addrlen)
1327{ 1271{
@@ -1334,50 +1278,42 @@ udp_nat_port_map_callback (void *cls,
1334 1278
1335 (void) app_ctx; 1279 (void) app_ctx;
1336 LOG (GNUNET_ERROR_TYPE_DEBUG, 1280 LOG (GNUNET_ERROR_TYPE_DEBUG,
1337 (GNUNET_YES == add_remove) 1281 (GNUNET_YES == add_remove) ? "NAT notification to add address `%s'\n"
1338 ? "NAT notification to add address `%s'\n" 1282 : "NAT notification to remove address `%s'\n",
1339 : "NAT notification to remove address `%s'\n", 1283 GNUNET_a2s (addr, addrlen));
1340 GNUNET_a2s (addr,
1341 addrlen));
1342 /* convert 'address' to our internal format */ 1284 /* convert 'address' to our internal format */
1343 switch (addr->sa_family) 1285 switch (addr->sa_family)
1344 { 1286 {
1345 case AF_INET: 1287 case AF_INET: {
1346 { 1288 const struct sockaddr_in *i4;
1347 const struct sockaddr_in *i4; 1289
1348 1290 GNUNET_assert (sizeof (struct sockaddr_in) == addrlen);
1349 GNUNET_assert (sizeof(struct sockaddr_in) == addrlen); 1291 i4 = (const struct sockaddr_in *) addr;
1350 i4 = (const struct sockaddr_in *) addr; 1292 if (0 == ntohs (i4->sin_port))
1351 if (0 == ntohs (i4->sin_port)) 1293 return; /* Port = 0 means unmapped, ignore these for UDP. */
1352 return; /* Port = 0 means unmapped, ignore these for UDP. */ 1294 memset (&u4, 0, sizeof (u4));
1353 memset (&u4, 1295 u4.options = htonl (plugin->myoptions);
1354 0, 1296 u4.ipv4_addr = i4->sin_addr.s_addr;
1355 sizeof(u4)); 1297 u4.u4_port = i4->sin_port;
1356 u4.options = htonl (plugin->myoptions); 1298 arg = &u4;
1357 u4.ipv4_addr = i4->sin_addr.s_addr; 1299 args = sizeof (struct IPv4UdpAddress);
1358 u4.u4_port = i4->sin_port; 1300 break;
1359 arg = &u4; 1301 }
1360 args = sizeof (struct IPv4UdpAddress); 1302 case AF_INET6: {
1361 break; 1303 const struct sockaddr_in6 *i6;
1362 } 1304
1363 case AF_INET6: 1305 GNUNET_assert (sizeof (struct sockaddr_in6) == addrlen);
1364 { 1306 i6 = (const struct sockaddr_in6 *) addr;
1365 const struct sockaddr_in6 *i6; 1307 if (0 == ntohs (i6->sin6_port))
1366 1308 return; /* Port = 0 means unmapped, ignore these for UDP. */
1367 GNUNET_assert (sizeof(struct sockaddr_in6) == addrlen); 1309 memset (&u6, 0, sizeof (u6));
1368 i6 = (const struct sockaddr_in6 *) addr; 1310 u6.options = htonl (plugin->myoptions);
1369 if (0 == ntohs (i6->sin6_port)) 1311 u6.ipv6_addr = i6->sin6_addr;
1370 return; /* Port = 0 means unmapped, ignore these for UDP. */ 1312 u6.u6_port = i6->sin6_port;
1371 memset (&u6, 1313 arg = &u6;
1372 0, 1314 args = sizeof (struct IPv6UdpAddress);
1373 sizeof(u6)); 1315 break;
1374 u6.options = htonl (plugin->myoptions); 1316 }
1375 u6.ipv6_addr = i6->sin6_addr;
1376 u6.u6_port = i6->sin6_port;
1377 arg = &u6;
1378 args = sizeof (struct IPv6UdpAddress);
1379 break;
1380 }
1381 default: 1317 default:
1382 GNUNET_break (0); 1318 GNUNET_break (0);
1383 return; 1319 return;
@@ -1389,9 +1325,7 @@ udp_nat_port_map_callback (void *cls,
1389 arg, 1325 arg,
1390 args, 1326 args,
1391 GNUNET_HELLO_ADDRESS_INFO_NONE); 1327 GNUNET_HELLO_ADDRESS_INFO_NONE);
1392 plugin->env->notify_address (plugin->env->cls, 1328 plugin->env->notify_address (plugin->env->cls, add_remove, address);
1393 add_remove,
1394 address);
1395 GNUNET_HELLO_address_free (address); 1329 GNUNET_HELLO_address_free (address);
1396} 1330}
1397 1331
@@ -1425,15 +1359,12 @@ struct GNUNET_ATS_SessionCompareContext
1425 * @return #GNUNET_NO if we found the session, #GNUNET_OK if not 1359 * @return #GNUNET_NO if we found the session, #GNUNET_OK if not
1426 */ 1360 */
1427static int 1361static int
1428session_cmp_it (void *cls, 1362session_cmp_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
1429 const struct GNUNET_PeerIdentity *key,
1430 void *value)
1431{ 1363{
1432 struct GNUNET_ATS_SessionCompareContext *cctx = cls; 1364 struct GNUNET_ATS_SessionCompareContext *cctx = cls;
1433 struct GNUNET_ATS_Session *s = value; 1365 struct GNUNET_ATS_Session *s = value;
1434 1366
1435 if (0 == GNUNET_HELLO_address_cmp (s->address, 1367 if (0 == GNUNET_HELLO_address_cmp (s->address, cctx->address))
1436 cctx->address))
1437 { 1368 {
1438 GNUNET_assert (GNUNET_NO == s->in_destroy); 1369 GNUNET_assert (GNUNET_NO == s->in_destroy);
1439 cctx->res = s; 1370 cctx->res = s;
@@ -1466,7 +1397,7 @@ udp_plugin_lookup_session (void *cls,
1466 GNUNET_break (0); 1397 GNUNET_break (0);
1467 return NULL; 1398 return NULL;
1468 } 1399 }
1469 if (sizeof(struct IPv4UdpAddress) == address->address_length) 1400 if (sizeof (struct IPv4UdpAddress) == address->address_length)
1470 { 1401 {
1471 if (NULL == plugin->sockv4) 1402 if (NULL == plugin->sockv4)
1472 return NULL; 1403 return NULL;
@@ -1477,7 +1408,7 @@ udp_plugin_lookup_session (void *cls,
1477 return NULL; 1408 return NULL;
1478 } 1409 }
1479 } 1410 }
1480 else if (sizeof(struct IPv6UdpAddress) == address->address_length) 1411 else if (sizeof (struct IPv6UdpAddress) == address->address_length)
1481 { 1412 {
1482 if (NULL == plugin->sockv6) 1413 if (NULL == plugin->sockv6)
1483 return NULL; 1414 return NULL;
@@ -1509,9 +1440,7 @@ udp_plugin_lookup_session (void *cls,
1509 &cctx); 1440 &cctx);
1510 if (NULL == cctx.res) 1441 if (NULL == cctx.res)
1511 return NULL; 1442 return NULL;
1512 LOG (GNUNET_ERROR_TYPE_DEBUG, 1443 LOG (GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p\n", cctx.res);
1513 "Found existing session %p\n",
1514 cctx.res);
1515 return cctx.res; 1444 return cctx.res;
1516} 1445}
1517 1446
@@ -1534,7 +1463,6 @@ reschedule_session_timeout (struct GNUNET_ATS_Session *s)
1534} 1463}
1535 1464
1536 1465
1537
1538/** 1466/**
1539 * Function that will be called whenever the transport service wants to 1467 * Function that will be called whenever the transport service wants to
1540 * notify the plugin that a session is still active and in use and 1468 * notify the plugin that a session is still active and in use and
@@ -1575,8 +1503,7 @@ udp_plugin_update_session_timeout (void *cls,
1575 * @param udpw message wrapper to dequeue 1503 * @param udpw message wrapper to dequeue
1576 */ 1504 */
1577static void 1505static void
1578dequeue (struct Plugin *plugin, 1506dequeue (struct Plugin *plugin, struct UDP_MessageWrapper *udpw)
1579 struct UDP_MessageWrapper *udpw)
1580{ 1507{
1581 struct GNUNET_ATS_Session *session = udpw->session; 1508 struct GNUNET_ATS_Session *session = udpw->session;
1582 1509
@@ -1588,7 +1515,7 @@ dequeue (struct Plugin *plugin,
1588 { 1515 {
1589 GNUNET_STATISTICS_update (plugin->env->stats, 1516 GNUNET_STATISTICS_update (plugin->env->stats,
1590 "# UDP, total bytes in send buffers", 1517 "# UDP, total bytes in send buffers",
1591 - (long long) udpw->msg_size, 1518 -(long long) udpw->msg_size,
1592 GNUNET_NO); 1519 GNUNET_NO);
1593 plugin->bytes_in_buffer -= udpw->msg_size; 1520 plugin->bytes_in_buffer -= udpw->msg_size;
1594 } 1521 }
@@ -1596,13 +1523,14 @@ dequeue (struct Plugin *plugin,
1596 "# UDP, total messages in send buffers", 1523 "# UDP, total messages in send buffers",
1597 -1, 1524 -1,
1598 GNUNET_NO); 1525 GNUNET_NO);
1599 if (sizeof(struct IPv4UdpAddress) == udpw->session->address->address_length) 1526 if (sizeof (struct IPv4UdpAddress) == udpw->session->address->address_length)
1600 { 1527 {
1601 GNUNET_CONTAINER_DLL_remove (plugin->ipv4_queue_head, 1528 GNUNET_CONTAINER_DLL_remove (plugin->ipv4_queue_head,
1602 plugin->ipv4_queue_tail, 1529 plugin->ipv4_queue_tail,
1603 udpw); 1530 udpw);
1604 } 1531 }
1605 else if (sizeof(struct IPv6UdpAddress) == udpw->session->address->address_length) 1532 else if (sizeof (struct IPv6UdpAddress) ==
1533 udpw->session->address->address_length)
1606 { 1534 {
1607 GNUNET_CONTAINER_DLL_remove (plugin->ipv6_queue_head, 1535 GNUNET_CONTAINER_DLL_remove (plugin->ipv6_queue_head,
1608 plugin->ipv6_queue_tail, 1536 plugin->ipv6_queue_tail,
@@ -1627,8 +1555,7 @@ dequeue (struct Plugin *plugin,
1627 * @param udpw message wrapper to queue 1555 * @param udpw message wrapper to queue
1628 */ 1556 */
1629static void 1557static void
1630enqueue (struct Plugin *plugin, 1558enqueue (struct Plugin *plugin, struct UDP_MessageWrapper *udpw)
1631 struct UDP_MessageWrapper *udpw)
1632{ 1559{
1633 struct GNUNET_ATS_Session *session = udpw->session; 1560 struct GNUNET_ATS_Session *session = udpw->session;
1634 1561
@@ -1656,11 +1583,12 @@ enqueue (struct Plugin *plugin,
1656 GNUNET_NO); 1583 GNUNET_NO);
1657 if (sizeof (struct IPv4UdpAddress) == udpw->session->address->address_length) 1584 if (sizeof (struct IPv4UdpAddress) == udpw->session->address->address_length)
1658 { 1585 {
1659 GNUNET_CONTAINER_DLL_insert(plugin->ipv4_queue_head, 1586 GNUNET_CONTAINER_DLL_insert (plugin->ipv4_queue_head,
1660 plugin->ipv4_queue_tail, 1587 plugin->ipv4_queue_tail,
1661 udpw); 1588 udpw);
1662 } 1589 }
1663 else if (sizeof (struct IPv6UdpAddress) == udpw->session->address->address_length) 1590 else if (sizeof (struct IPv6UdpAddress) ==
1591 udpw->session->address->address_length)
1664 { 1592 {
1665 GNUNET_CONTAINER_DLL_insert (plugin->ipv6_queue_head, 1593 GNUNET_CONTAINER_DLL_insert (plugin->ipv6_queue_head,
1666 plugin->ipv6_queue_tail, 1594 plugin->ipv6_queue_tail,
@@ -1693,8 +1621,7 @@ enqueue (struct Plugin *plugin,
1693 * #GNUNET_SYSERR if the transmission failed 1621 * #GNUNET_SYSERR if the transmission failed
1694 */ 1622 */
1695static void 1623static void
1696fragmented_message_done (struct UDP_FragmentationContext *frag_ctx, 1624fragmented_message_done (struct UDP_FragmentationContext *frag_ctx, int result)
1697 int result)
1698{ 1625{
1699 struct Plugin *plugin = frag_ctx->plugin; 1626 struct Plugin *plugin = frag_ctx->plugin;
1700 struct GNUNET_ATS_Session *s = frag_ctx->session; 1627 struct GNUNET_ATS_Session *s = frag_ctx->session;
@@ -1717,16 +1644,14 @@ fragmented_message_done (struct UDP_FragmentationContext *frag_ctx,
1717 { 1644 {
1718 LOG (GNUNET_ERROR_TYPE_WARNING, 1645 LOG (GNUNET_ERROR_TYPE_WARNING,
1719 "Fragmented message acknowledged after %s (expected at %s)\n", 1646 "Fragmented message acknowledged after %s (expected at %s)\n",
1720 GNUNET_STRINGS_relative_time_to_string (delay, 1647 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES),
1721 GNUNET_YES),
1722 GNUNET_STRINGS_absolute_time_to_string (frag_ctx->next_frag_time)); 1648 GNUNET_STRINGS_absolute_time_to_string (frag_ctx->next_frag_time));
1723 } 1649 }
1724 else 1650 else
1725 { 1651 {
1726 LOG (GNUNET_ERROR_TYPE_DEBUG, 1652 LOG (GNUNET_ERROR_TYPE_DEBUG,
1727 "Fragmented message acknowledged after %s (expected at %s)\n", 1653 "Fragmented message acknowledged after %s (expected at %s)\n",
1728 GNUNET_STRINGS_relative_time_to_string (delay, 1654 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES),
1729 GNUNET_YES),
1730 GNUNET_STRINGS_absolute_time_to_string (frag_ctx->next_frag_time)); 1655 GNUNET_STRINGS_absolute_time_to_string (frag_ctx->next_frag_time));
1731 } 1656 }
1732 1657
@@ -1751,10 +1676,11 @@ fragmented_message_done (struct UDP_FragmentationContext *frag_ctx,
1751 "# UDP, fragmented msgs, bytes payload, sent, success", 1676 "# UDP, fragmented msgs, bytes payload, sent, success",
1752 s->frag_ctx->payload_size, 1677 s->frag_ctx->payload_size,
1753 GNUNET_NO); 1678 GNUNET_NO);
1754 GNUNET_STATISTICS_update (plugin->env->stats, 1679 GNUNET_STATISTICS_update (
1755 "# UDP, fragmented msgs, bytes overhead, sent, success", 1680 plugin->env->stats,
1756 overhead, 1681 "# UDP, fragmented msgs, bytes overhead, sent, success",
1757 GNUNET_NO); 1682 overhead,
1683 GNUNET_NO);
1758 GNUNET_STATISTICS_update (plugin->env->stats, 1684 GNUNET_STATISTICS_update (plugin->env->stats,
1759 "# UDP, total, bytes overhead, sent", 1685 "# UDP, total, bytes overhead, sent",
1760 overhead, 1686 overhead,
@@ -1786,41 +1712,35 @@ fragmented_message_done (struct UDP_FragmentationContext *frag_ctx,
1786 1712
1787 /* Remove remaining fragments from queue, no need to transmit those 1713 /* Remove remaining fragments from queue, no need to transmit those
1788 any longer. */ 1714 any longer. */
1789 if (s->address->address_length == sizeof(struct IPv6UdpAddress)) 1715 if (s->address->address_length == sizeof (struct IPv6UdpAddress))
1790 { 1716 {
1791 udpw = plugin->ipv6_queue_head; 1717 udpw = plugin->ipv6_queue_head;
1792 while (NULL != udpw) 1718 while (NULL != udpw)
1793 { 1719 {
1794 tmp = udpw->next; 1720 tmp = udpw->next;
1795 if ( (udpw->frag_ctx != NULL) && 1721 if ((udpw->frag_ctx != NULL) && (udpw->frag_ctx == frag_ctx))
1796 (udpw->frag_ctx == frag_ctx) )
1797 { 1722 {
1798 dequeue (plugin, 1723 dequeue (plugin, udpw);
1799 udpw); 1724 GNUNET_free (udpw);
1800 GNUNET_free (udpw);
1801 } 1725 }
1802 udpw = tmp; 1726 udpw = tmp;
1803 } 1727 }
1804 } 1728 }
1805 if (s->address->address_length == sizeof(struct IPv4UdpAddress)) 1729 if (s->address->address_length == sizeof (struct IPv4UdpAddress))
1806 { 1730 {
1807 udpw = plugin->ipv4_queue_head; 1731 udpw = plugin->ipv4_queue_head;
1808 while (NULL != udpw) 1732 while (NULL != udpw)
1809 { 1733 {
1810 tmp = udpw->next; 1734 tmp = udpw->next;
1811 if ( (NULL != udpw->frag_ctx) && 1735 if ((NULL != udpw->frag_ctx) && (udpw->frag_ctx == frag_ctx))
1812 (udpw->frag_ctx == frag_ctx) )
1813 { 1736 {
1814 dequeue (plugin, 1737 dequeue (plugin, udpw);
1815 udpw);
1816 GNUNET_free (udpw); 1738 GNUNET_free (udpw);
1817 } 1739 }
1818 udpw = tmp; 1740 udpw = tmp;
1819 } 1741 }
1820 } 1742 }
1821 notify_session_monitor (s->plugin, 1743 notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE);
1822 s,
1823 GNUNET_TRANSPORT_SS_UPDATE);
1824 GNUNET_FRAGMENT_context_destroy (frag_ctx->frag, 1744 GNUNET_FRAGMENT_context_destroy (frag_ctx->frag,
1825 &s->last_expected_msg_delay, 1745 &s->last_expected_msg_delay,
1826 &s->last_expected_ack_delay); 1746 &s->last_expected_ack_delay);
@@ -1838,9 +1758,7 @@ fragmented_message_done (struct UDP_FragmentationContext *frag_ctx,
1838 * @param result #GNUNET_OK on success, #GNUNET_SYSERR on failure 1758 * @param result #GNUNET_OK on success, #GNUNET_SYSERR on failure
1839 */ 1759 */
1840static void 1760static void
1841qc_fragment_sent (void *cls, 1761qc_fragment_sent (void *cls, struct UDP_MessageWrapper *udpw, int result)
1842 struct UDP_MessageWrapper *udpw,
1843 int result)
1844{ 1762{
1845 struct Plugin *plugin = cls; 1763 struct Plugin *plugin = cls;
1846 1764
@@ -1856,10 +1774,11 @@ qc_fragment_sent (void *cls,
1856 "# UDP, fragmented msgs, fragments, sent, success", 1774 "# UDP, fragmented msgs, fragments, sent, success",
1857 1, 1775 1,
1858 GNUNET_NO); 1776 GNUNET_NO);
1859 GNUNET_STATISTICS_update (plugin->env->stats, 1777 GNUNET_STATISTICS_update (
1860 "# UDP, fragmented msgs, fragments bytes, sent, success", 1778 plugin->env->stats,
1861 udpw->msg_size, 1779 "# UDP, fragmented msgs, fragments bytes, sent, success",
1862 GNUNET_NO); 1780 udpw->msg_size,
1781 GNUNET_NO);
1863 } 1782 }
1864 else 1783 else
1865 { 1784 {
@@ -1867,16 +1786,16 @@ qc_fragment_sent (void *cls,
1867 "Failed to transmit fragment of message with %u bytes to %s\n", 1786 "Failed to transmit fragment of message with %u bytes to %s\n",
1868 (unsigned int) udpw->payload_size, 1787 (unsigned int) udpw->payload_size,
1869 GNUNET_i2s (&udpw->session->target)); 1788 GNUNET_i2s (&udpw->session->target));
1870 fragmented_message_done (udpw->frag_ctx, 1789 fragmented_message_done (udpw->frag_ctx, GNUNET_SYSERR);
1871 GNUNET_SYSERR);
1872 GNUNET_STATISTICS_update (plugin->env->stats, 1790 GNUNET_STATISTICS_update (plugin->env->stats,
1873 "# UDP, fragmented msgs, fragments, sent, failure", 1791 "# UDP, fragmented msgs, fragments, sent, failure",
1874 1, 1792 1,
1875 GNUNET_NO); 1793 GNUNET_NO);
1876 GNUNET_STATISTICS_update (plugin->env->stats, 1794 GNUNET_STATISTICS_update (
1877 "# UDP, fragmented msgs, fragments bytes, sent, failure", 1795 plugin->env->stats,
1878 udpw->msg_size, 1796 "# UDP, fragmented msgs, fragments bytes, sent, failure",
1879 GNUNET_NO); 1797 udpw->msg_size,
1798 GNUNET_NO);
1880 } 1799 }
1881} 1800}
1882 1801
@@ -1891,8 +1810,7 @@ qc_fragment_sent (void *cls,
1891 * @param msg the message that was created 1810 * @param msg the message that was created
1892 */ 1811 */
1893static void 1812static void
1894enqueue_fragment (void *cls, 1813enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg)
1895 const struct GNUNET_MessageHeader *msg)
1896{ 1814{
1897 struct UDP_FragmentationContext *frag_ctx = cls; 1815 struct UDP_FragmentationContext *frag_ctx = cls;
1898 struct Plugin *plugin = frag_ctx->plugin; 1816 struct Plugin *plugin = frag_ctx->plugin;
@@ -1900,9 +1818,7 @@ enqueue_fragment (void *cls,
1900 struct GNUNET_ATS_Session *session = frag_ctx->session; 1818 struct GNUNET_ATS_Session *session = frag_ctx->session;
1901 size_t msg_len = ntohs (msg->size); 1819 size_t msg_len = ntohs (msg->size);
1902 1820
1903 LOG (GNUNET_ERROR_TYPE_DEBUG, 1821 LOG (GNUNET_ERROR_TYPE_DEBUG, "Enqueuing fragment with %u bytes\n", msg_len);
1904 "Enqueuing fragment with %u bytes\n",
1905 msg_len);
1906 udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msg_len); 1822 udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msg_len);
1907 udpw->session = session; 1823 udpw->session = session;
1908 udpw->msg_buf = (char *) &udpw[1]; 1824 udpw->msg_buf = (char *) &udpw[1];
@@ -1911,17 +1827,14 @@ enqueue_fragment (void *cls,
1911 udpw->timeout = frag_ctx->timeout; 1827 udpw->timeout = frag_ctx->timeout;
1912 udpw->start_time = frag_ctx->start_time; 1828 udpw->start_time = frag_ctx->start_time;
1913 udpw->transmission_time = frag_ctx->next_frag_time; 1829 udpw->transmission_time = frag_ctx->next_frag_time;
1914 frag_ctx->next_frag_time 1830 frag_ctx->next_frag_time =
1915 = GNUNET_TIME_absolute_add (frag_ctx->next_frag_time, 1831 GNUNET_TIME_absolute_add (frag_ctx->next_frag_time,
1916 frag_ctx->flow_delay_from_other_peer); 1832 frag_ctx->flow_delay_from_other_peer);
1917 udpw->frag_ctx = frag_ctx; 1833 udpw->frag_ctx = frag_ctx;
1918 udpw->qc = &qc_fragment_sent; 1834 udpw->qc = &qc_fragment_sent;
1919 udpw->qc_cls = plugin; 1835 udpw->qc_cls = plugin;
1920 GNUNET_memcpy (udpw->msg_buf, 1836 GNUNET_memcpy (udpw->msg_buf, msg, msg_len);
1921 msg, 1837 enqueue (plugin, udpw);
1922 msg_len);
1923 enqueue (plugin,
1924 udpw);
1925 if (session->address->address_length == sizeof (struct IPv4UdpAddress)) 1838 if (session->address->address_length == sizeof (struct IPv4UdpAddress))
1926 schedule_select_v4 (plugin); 1839 schedule_select_v4 (plugin);
1927 else 1840 else
@@ -1938,9 +1851,7 @@ enqueue_fragment (void *cls,
1938 * @param result #GNUNET_OK on success, #GNUNET_SYSERR on failure 1851 * @param result #GNUNET_OK on success, #GNUNET_SYSERR on failure
1939 */ 1852 */
1940static void 1853static void
1941qc_message_sent (void *cls, 1854qc_message_sent (void *cls, struct UDP_MessageWrapper *udpw, int result)
1942 struct UDP_MessageWrapper *udpw,
1943 int result)
1944{ 1855{
1945 struct Plugin *plugin = cls; 1856 struct Plugin *plugin = cls;
1946 size_t overhead; 1857 size_t overhead;
@@ -1958,15 +1869,13 @@ qc_message_sent (void *cls,
1958 { 1869 {
1959 LOG (GNUNET_ERROR_TYPE_WARNING, 1870 LOG (GNUNET_ERROR_TYPE_WARNING,
1960 "Message sent via UDP with delay of %s\n", 1871 "Message sent via UDP with delay of %s\n",
1961 GNUNET_STRINGS_relative_time_to_string (delay, 1872 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
1962 GNUNET_YES));
1963 } 1873 }
1964 else 1874 else
1965 { 1875 {
1966 LOG (GNUNET_ERROR_TYPE_DEBUG, 1876 LOG (GNUNET_ERROR_TYPE_DEBUG,
1967 "Message sent via UDP with delay of %s\n", 1877 "Message sent via UDP with delay of %s\n",
1968 GNUNET_STRINGS_relative_time_to_string (delay, 1878 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
1969 GNUNET_YES));
1970 } 1879 }
1971 udpw->cont (udpw->cont_cls, 1880 udpw->cont (udpw->cont_cls,
1972 &udpw->session->target, 1881 &udpw->session->target,
@@ -1980,14 +1889,16 @@ qc_message_sent (void *cls,
1980 "# UDP, unfragmented msgs, messages, sent, success", 1889 "# UDP, unfragmented msgs, messages, sent, success",
1981 1, 1890 1,
1982 GNUNET_NO); 1891 GNUNET_NO);
1983 GNUNET_STATISTICS_update (plugin->env->stats, 1892 GNUNET_STATISTICS_update (
1984 "# UDP, unfragmented msgs, bytes payload, sent, success", 1893 plugin->env->stats,
1985 udpw->payload_size, 1894 "# UDP, unfragmented msgs, bytes payload, sent, success",
1986 GNUNET_NO); 1895 udpw->payload_size,
1987 GNUNET_STATISTICS_update (plugin->env->stats, 1896 GNUNET_NO);
1988 "# UDP, unfragmented msgs, bytes overhead, sent, success", 1897 GNUNET_STATISTICS_update (
1989 overhead, 1898 plugin->env->stats,
1990 GNUNET_NO); 1899 "# UDP, unfragmented msgs, bytes overhead, sent, success",
1900 overhead,
1901 GNUNET_NO);
1991 GNUNET_STATISTICS_update (plugin->env->stats, 1902 GNUNET_STATISTICS_update (plugin->env->stats,
1992 "# UDP, total, bytes overhead, sent", 1903 "# UDP, total, bytes overhead, sent",
1993 overhead, 1904 overhead,
@@ -2003,14 +1914,16 @@ qc_message_sent (void *cls,
2003 "# UDP, unfragmented msgs, messages, sent, failure", 1914 "# UDP, unfragmented msgs, messages, sent, failure",
2004 1, 1915 1,
2005 GNUNET_NO); 1916 GNUNET_NO);
2006 GNUNET_STATISTICS_update (plugin->env->stats, 1917 GNUNET_STATISTICS_update (
2007 "# UDP, unfragmented msgs, bytes payload, sent, failure", 1918 plugin->env->stats,
2008 udpw->payload_size, 1919 "# UDP, unfragmented msgs, bytes payload, sent, failure",
2009 GNUNET_NO); 1920 udpw->payload_size,
2010 GNUNET_STATISTICS_update (plugin->env->stats, 1921 GNUNET_NO);
2011 "# UDP, unfragmented msgs, bytes overhead, sent, failure", 1922 GNUNET_STATISTICS_update (
2012 overhead, 1923 plugin->env->stats,
2013 GNUNET_NO); 1924 "# UDP, unfragmented msgs, bytes overhead, sent, failure",
1925 overhead,
1926 GNUNET_NO);
2014 } 1927 }
2015} 1928}
2016 1929
@@ -2053,18 +1966,18 @@ udp_plugin_send (void *cls,
2053 void *cont_cls) 1966 void *cont_cls)
2054{ 1967{
2055 struct Plugin *plugin = cls; 1968 struct Plugin *plugin = cls;
2056 size_t udpmlen = msgbuf_size + sizeof(struct UDPMessage); 1969 size_t udpmlen = msgbuf_size + sizeof (struct UDPMessage);
2057 struct UDP_FragmentationContext *frag_ctx; 1970 struct UDP_FragmentationContext *frag_ctx;
2058 struct UDP_MessageWrapper *udpw; 1971 struct UDP_MessageWrapper *udpw;
2059 struct UDPMessage *udp; 1972 struct UDPMessage *udp;
2060 char mbuf[udpmlen] GNUNET_ALIGN; 1973 char mbuf[udpmlen] GNUNET_ALIGN;
2061 struct GNUNET_TIME_Relative latency; 1974 struct GNUNET_TIME_Relative latency;
2062 1975
2063 if ( (sizeof(struct IPv6UdpAddress) == s->address->address_length) && 1976 if ((sizeof (struct IPv6UdpAddress) == s->address->address_length) &&
2064 (NULL == plugin->sockv6) ) 1977 (NULL == plugin->sockv6))
2065 return GNUNET_SYSERR; 1978 return GNUNET_SYSERR;
2066 if ( (sizeof(struct IPv4UdpAddress) == s->address->address_length) && 1979 if ((sizeof (struct IPv4UdpAddress) == s->address->address_length) &&
2067 (NULL == plugin->sockv4) ) 1980 (NULL == plugin->sockv4))
2068 return GNUNET_SYSERR; 1981 return GNUNET_SYSERR;
2069 if (udpmlen >= GNUNET_MAX_MESSAGE_SIZE) 1982 if (udpmlen >= GNUNET_MAX_MESSAGE_SIZE)
2070 { 1983 {
@@ -2112,22 +2025,19 @@ udp_plugin_send (void *cls,
2112 udpw->start_time = GNUNET_TIME_absolute_get (); 2025 udpw->start_time = GNUNET_TIME_absolute_get ();
2113 udpw->timeout = GNUNET_TIME_relative_to_absolute (to); 2026 udpw->timeout = GNUNET_TIME_relative_to_absolute (to);
2114 udpw->transmission_time = s->last_transmit_time; 2027 udpw->transmission_time = s->last_transmit_time;
2115 s->last_transmit_time 2028 s->last_transmit_time =
2116 = GNUNET_TIME_absolute_add (s->last_transmit_time, 2029 GNUNET_TIME_absolute_add (s->last_transmit_time,
2117 s->flow_delay_from_other_peer); 2030 s->flow_delay_from_other_peer);
2118 udpw->cont = cont; 2031 udpw->cont = cont;
2119 udpw->cont_cls = cont_cls; 2032 udpw->cont_cls = cont_cls;
2120 udpw->frag_ctx = NULL; 2033 udpw->frag_ctx = NULL;
2121 udpw->qc = &qc_message_sent; 2034 udpw->qc = &qc_message_sent;
2122 udpw->qc_cls = plugin; 2035 udpw->qc_cls = plugin;
2123 GNUNET_memcpy (udpw->msg_buf, 2036 GNUNET_memcpy (udpw->msg_buf, udp, sizeof (struct UDPMessage));
2124 udp, 2037 GNUNET_memcpy (&udpw->msg_buf[sizeof (struct UDPMessage)],
2125 sizeof (struct UDPMessage)); 2038 msgbuf,
2126 GNUNET_memcpy (&udpw->msg_buf[sizeof(struct UDPMessage)], 2039 msgbuf_size);
2127 msgbuf, 2040 enqueue (plugin, udpw);
2128 msgbuf_size);
2129 enqueue (plugin,
2130 udpw);
2131 GNUNET_STATISTICS_update (plugin->env->stats, 2041 GNUNET_STATISTICS_update (plugin->env->stats,
2132 "# UDP, unfragmented messages queued total", 2042 "# UDP, unfragmented messages queued total",
2133 1, 2043 1,
@@ -2146,9 +2056,7 @@ udp_plugin_send (void *cls,
2146 /* fragmented message */ 2056 /* fragmented message */
2147 if (NULL != s->frag_ctx) 2057 if (NULL != s->frag_ctx)
2148 return GNUNET_SYSERR; 2058 return GNUNET_SYSERR;
2149 GNUNET_memcpy (&udp[1], 2059 GNUNET_memcpy (&udp[1], msgbuf, msgbuf_size);
2150 msgbuf,
2151 msgbuf_size);
2152 frag_ctx = GNUNET_new (struct UDP_FragmentationContext); 2060 frag_ctx = GNUNET_new (struct UDP_FragmentationContext);
2153 frag_ctx->plugin = plugin; 2061 frag_ctx->plugin = plugin;
2154 frag_ctx->session = s; 2062 frag_ctx->session = s;
@@ -2156,12 +2064,12 @@ udp_plugin_send (void *cls,
2156 frag_ctx->cont_cls = cont_cls; 2064 frag_ctx->cont_cls = cont_cls;
2157 frag_ctx->start_time = GNUNET_TIME_absolute_get (); 2065 frag_ctx->start_time = GNUNET_TIME_absolute_get ();
2158 frag_ctx->next_frag_time = s->last_transmit_time; 2066 frag_ctx->next_frag_time = s->last_transmit_time;
2159 frag_ctx->flow_delay_from_other_peer 2067 frag_ctx->flow_delay_from_other_peer =
2160 = GNUNET_TIME_relative_divide (s->flow_delay_from_other_peer, 2068 GNUNET_TIME_relative_divide (s->flow_delay_from_other_peer,
2161 1 + (msgbuf_size / 2069 1 + (msgbuf_size / UDP_MTU));
2162 UDP_MTU));
2163 frag_ctx->timeout = GNUNET_TIME_relative_to_absolute (to); 2070 frag_ctx->timeout = GNUNET_TIME_relative_to_absolute (to);
2164 frag_ctx->payload_size = msgbuf_size; /* unfragmented message size without UDP overhead */ 2071 frag_ctx->payload_size =
2072 msgbuf_size; /* unfragmented message size without UDP overhead */
2165 frag_ctx->on_wire_size = 0; /* bytes with UDP and fragmentation overhead */ 2073 frag_ctx->on_wire_size = 0; /* bytes with UDP and fragmentation overhead */
2166 frag_ctx->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats, 2074 frag_ctx->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats,
2167 UDP_MTU, 2075 UDP_MTU,
@@ -2177,15 +2085,13 @@ udp_plugin_send (void *cls,
2177 if (latency.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 2085 if (latency.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
2178 LOG (GNUNET_ERROR_TYPE_WARNING, 2086 LOG (GNUNET_ERROR_TYPE_WARNING,
2179 "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n", 2087 "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n",
2180 GNUNET_STRINGS_relative_time_to_string (latency, 2088 GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_YES),
2181 GNUNET_YES),
2182 GNUNET_i2s (&s->target), 2089 GNUNET_i2s (&s->target),
2183 (unsigned int) s->msgs_in_queue); 2090 (unsigned int) s->msgs_in_queue);
2184 else 2091 else
2185 LOG (GNUNET_ERROR_TYPE_DEBUG, 2092 LOG (GNUNET_ERROR_TYPE_DEBUG,
2186 "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n", 2093 "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n",
2187 GNUNET_STRINGS_relative_time_to_string (latency, 2094 GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_YES),
2188 GNUNET_YES),
2189 GNUNET_i2s (&s->target), 2095 GNUNET_i2s (&s->target),
2190 (unsigned int) s->msgs_in_queue); 2096 (unsigned int) s->msgs_in_queue);
2191 2097
@@ -2202,9 +2108,7 @@ udp_plugin_send (void *cls,
2202 frag_ctx->payload_size, 2108 frag_ctx->payload_size,
2203 GNUNET_NO); 2109 GNUNET_NO);
2204 } 2110 }
2205 notify_session_monitor (s->plugin, 2111 notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE);
2206 s,
2207 GNUNET_TRANSPORT_SS_UPDATE);
2208 return udpmlen; 2112 return udpmlen;
2209} 2113}
2210 2114
@@ -2236,7 +2140,6 @@ struct FindReceiveContext
2236 * Number of bytes in @e udp_addr. 2140 * Number of bytes in @e udp_addr.
2237 */ 2141 */
2238 size_t udp_addr_len; 2142 size_t udp_addr_len;
2239
2240}; 2143};
2241 2144
2242 2145
@@ -2259,10 +2162,8 @@ find_receive_context (void *cls,
2259 struct FindReceiveContext *frc = cls; 2162 struct FindReceiveContext *frc = cls;
2260 struct DefragContext *e = element; 2163 struct DefragContext *e = element;
2261 2164
2262 if ( (frc->udp_addr_len == e->udp_addr_len) && 2165 if ((frc->udp_addr_len == e->udp_addr_len) &&
2263 (0 == memcmp (frc->udp_addr, 2166 (0 == memcmp (frc->udp_addr, e->udp_addr, frc->udp_addr_len)))
2264 e->udp_addr,
2265 frc->udp_addr_len)) )
2266 { 2167 {
2267 frc->rc = e; 2168 frc->rc = e;
2268 return GNUNET_NO; 2169 return GNUNET_NO;
@@ -2280,8 +2181,7 @@ find_receive_context (void *cls,
2280 * @return #GNUNET_OK on success 2181 * @return #GNUNET_OK on success
2281 */ 2182 */
2282static int 2183static int
2283udp_disconnect_session (void *cls, 2184udp_disconnect_session (void *cls, struct GNUNET_ATS_Session *s)
2284 struct GNUNET_ATS_Session *s)
2285{ 2185{
2286 struct Plugin *plugin = cls; 2186 struct Plugin *plugin = cls;
2287 struct UDP_MessageWrapper *udpw; 2187 struct UDP_MessageWrapper *udpw;
@@ -2304,13 +2204,11 @@ udp_disconnect_session (void *cls,
2304 if (NULL != s->frag_ctx) 2204 if (NULL != s->frag_ctx)
2305 { 2205 {
2306 /* Remove fragmented message due to disconnect */ 2206 /* Remove fragmented message due to disconnect */
2307 fragmented_message_done (s->frag_ctx, 2207 fragmented_message_done (s->frag_ctx, GNUNET_SYSERR);
2308 GNUNET_SYSERR);
2309 } 2208 }
2310 GNUNET_assert (GNUNET_YES == 2209 GNUNET_assert (
2311 GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, 2210 GNUNET_YES ==
2312 &s->target, 2211 GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, &s->target, s));
2313 s));
2314 frc.rc = NULL; 2212 frc.rc = NULL;
2315 frc.udp_addr = s->address->address; 2213 frc.udp_addr = s->address->address;
2316 frc.udp_addr_len = s->address->address_length; 2214 frc.udp_addr_len = s->address->address_length;
@@ -2336,11 +2234,8 @@ udp_disconnect_session (void *cls,
2336 next = udpw->next; 2234 next = udpw->next;
2337 if (udpw->session == s) 2235 if (udpw->session == s)
2338 { 2236 {
2339 dequeue (plugin, 2237 dequeue (plugin, udpw);
2340 udpw); 2238 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR);
2341 udpw->qc (udpw->qc_cls,
2342 udpw,
2343 GNUNET_SYSERR);
2344 GNUNET_free (udpw); 2239 GNUNET_free (udpw);
2345 } 2240 }
2346 } 2241 }
@@ -2350,16 +2245,12 @@ udp_disconnect_session (void *cls,
2350 next = udpw->next; 2245 next = udpw->next;
2351 if (udpw->session == s) 2246 if (udpw->session == s)
2352 { 2247 {
2353 dequeue (plugin, 2248 dequeue (plugin, udpw);
2354 udpw); 2249 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR);
2355 udpw->qc (udpw->qc_cls,
2356 udpw,
2357 GNUNET_SYSERR);
2358 GNUNET_free (udpw); 2250 GNUNET_free (udpw);
2359 } 2251 }
2360 } 2252 }
2361 if ( (NULL != s->frag_ctx) && 2253 if ((NULL != s->frag_ctx) && (NULL != s->frag_ctx->cont))
2362 (NULL != s->frag_ctx->cont) )
2363 { 2254 {
2364 /* The 'frag_ctx' itself will be freed in #free_session() a bit 2255 /* The 'frag_ctx' itself will be freed in #free_session() a bit
2365 later, as it might be in use right now */ 2256 later, as it might be in use right now */
@@ -2372,12 +2263,8 @@ udp_disconnect_session (void *cls,
2372 s->frag_ctx->payload_size, 2263 s->frag_ctx->payload_size,
2373 s->frag_ctx->on_wire_size); 2264 s->frag_ctx->on_wire_size);
2374 } 2265 }
2375 notify_session_monitor (s->plugin, 2266 notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_DONE);
2376 s, 2267 plugin->env->session_end (plugin->env->cls, s->address, s);
2377 GNUNET_TRANSPORT_SS_DONE);
2378 plugin->env->session_end (plugin->env->cls,
2379 s->address,
2380 s);
2381 GNUNET_STATISTICS_set (plugin->env->stats, 2268 GNUNET_STATISTICS_set (plugin->env->stats,
2382 "# UDP sessions active", 2269 "# UDP sessions active",
2383 GNUNET_CONTAINER_multipeermap_size (plugin->sessions), 2270 GNUNET_CONTAINER_multipeermap_size (plugin->sessions),
@@ -2409,17 +2296,17 @@ read_process_ack (struct Plugin *plugin,
2409 struct GNUNET_TIME_Relative flow_delay; 2296 struct GNUNET_TIME_Relative flow_delay;
2410 2297
2411 /* check message format */ 2298 /* check message format */
2412 if (ntohs (msg->size) 2299 if (ntohs (msg->size) <
2413 < sizeof(struct UDP_ACK_Message) + sizeof(struct GNUNET_MessageHeader)) 2300 sizeof (struct UDP_ACK_Message) + sizeof (struct GNUNET_MessageHeader))
2414 { 2301 {
2415 GNUNET_break_op (0); 2302 GNUNET_break_op (0);
2416 return; 2303 return;
2417 } 2304 }
2418 udp_ack = (const struct UDP_ACK_Message *) msg; 2305 udp_ack = (const struct UDP_ACK_Message *) msg;
2419 ack = (const struct GNUNET_MessageHeader *) &udp_ack[1]; 2306 ack = (const struct GNUNET_MessageHeader *) &udp_ack[1];
2420 if (ntohs (ack->size) != ntohs (msg->size) - sizeof(struct UDP_ACK_Message)) 2307 if (ntohs (ack->size) != ntohs (msg->size) - sizeof (struct UDP_ACK_Message))
2421 { 2308 {
2422 GNUNET_break_op(0); 2309 GNUNET_break_op (0);
2423 return; 2310 return;
2424 } 2311 }
2425 2312
@@ -2429,8 +2316,7 @@ read_process_ack (struct Plugin *plugin,
2429 udp_addr, 2316 udp_addr,
2430 udp_addr_len, 2317 udp_addr_len,
2431 GNUNET_HELLO_ADDRESS_INFO_NONE); 2318 GNUNET_HELLO_ADDRESS_INFO_NONE);
2432 s = udp_plugin_lookup_session (plugin, 2319 s = udp_plugin_lookup_session (plugin, address);
2433 address);
2434 if (NULL == s) 2320 if (NULL == s)
2435 { 2321 {
2436 LOG (GNUNET_ERROR_TYPE_WARNING, 2322 LOG (GNUNET_ERROR_TYPE_WARNING,
@@ -2461,39 +2347,32 @@ read_process_ack (struct Plugin *plugin,
2461 LOG (GNUNET_ERROR_TYPE_INFO, 2347 LOG (GNUNET_ERROR_TYPE_INFO,
2462 "Asked to disconnect UDP session of %s\n", 2348 "Asked to disconnect UDP session of %s\n",
2463 GNUNET_i2s (&udp_ack->sender)); 2349 GNUNET_i2s (&udp_ack->sender));
2464 udp_disconnect_session (plugin, 2350 udp_disconnect_session (plugin, s);
2465 s);
2466 return; 2351 return;
2467 } 2352 }
2468 flow_delay.rel_value_us = (uint64_t) ntohl (udp_ack->delay); 2353 flow_delay.rel_value_us = (uint64_t) ntohl (udp_ack->delay);
2469 if (flow_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 2354 if (flow_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
2470 LOG (GNUNET_ERROR_TYPE_WARNING, 2355 LOG (GNUNET_ERROR_TYPE_WARNING,
2471 "We received a sending delay of %s for %s\n", 2356 "We received a sending delay of %s for %s\n",
2472 GNUNET_STRINGS_relative_time_to_string (flow_delay, 2357 GNUNET_STRINGS_relative_time_to_string (flow_delay, GNUNET_YES),
2473 GNUNET_YES),
2474 GNUNET_i2s (&udp_ack->sender)); 2358 GNUNET_i2s (&udp_ack->sender));
2475 else 2359 else
2476 LOG (GNUNET_ERROR_TYPE_DEBUG, 2360 LOG (GNUNET_ERROR_TYPE_DEBUG,
2477 "We received a sending delay of %s for %s\n", 2361 "We received a sending delay of %s for %s\n",
2478 GNUNET_STRINGS_relative_time_to_string (flow_delay, 2362 GNUNET_STRINGS_relative_time_to_string (flow_delay, GNUNET_YES),
2479 GNUNET_YES),
2480 GNUNET_i2s (&udp_ack->sender)); 2363 GNUNET_i2s (&udp_ack->sender));
2481 /* Flow delay is for the reassembled packet, however, our delay 2364 /* Flow delay is for the reassembled packet, however, our delay
2482 is per packet, so we need to adjust: */ 2365 is per packet, so we need to adjust: */
2483 s->flow_delay_from_other_peer = flow_delay; 2366 s->flow_delay_from_other_peer = flow_delay;
2484 2367
2485 /* Handle ACK */ 2368 /* Handle ACK */
2486 if (GNUNET_OK != 2369 if (GNUNET_OK != GNUNET_FRAGMENT_process_ack (s->frag_ctx->frag, ack))
2487 GNUNET_FRAGMENT_process_ack (s->frag_ctx->frag,
2488 ack))
2489 { 2370 {
2490 LOG (GNUNET_ERROR_TYPE_DEBUG, 2371 LOG (GNUNET_ERROR_TYPE_DEBUG,
2491 "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", 2372 "UDP processes %u-byte acknowledgement from `%s' at `%s'\n",
2492 (unsigned int) ntohs (msg->size), 2373 (unsigned int) ntohs (msg->size),
2493 GNUNET_i2s (&udp_ack->sender), 2374 GNUNET_i2s (&udp_ack->sender),
2494 udp_address_to_string (plugin, 2375 udp_address_to_string (plugin, udp_addr, udp_addr_len));
2495 udp_addr,
2496 udp_addr_len));
2497 /* Expect more ACKs to arrive */ 2376 /* Expect more ACKs to arrive */
2498 return; 2377 return;
2499 } 2378 }
@@ -2502,11 +2381,8 @@ read_process_ack (struct Plugin *plugin,
2502 LOG (GNUNET_ERROR_TYPE_DEBUG, 2381 LOG (GNUNET_ERROR_TYPE_DEBUG,
2503 "Message from %s at %s full ACK'ed\n", 2382 "Message from %s at %s full ACK'ed\n",
2504 GNUNET_i2s (&udp_ack->sender), 2383 GNUNET_i2s (&udp_ack->sender),
2505 udp_address_to_string (plugin, 2384 udp_address_to_string (plugin, udp_addr, udp_addr_len));
2506 udp_addr, 2385 fragmented_message_done (s->frag_ctx, GNUNET_OK);
2507 udp_addr_len));
2508 fragmented_message_done (s->frag_ctx,
2509 GNUNET_OK);
2510} 2386}
2511 2387
2512 2388
@@ -2528,11 +2404,8 @@ process_inbound_tokenized_messages (void *cls,
2528 if (GNUNET_YES == session->in_destroy) 2404 if (GNUNET_YES == session->in_destroy)
2529 return GNUNET_OK; 2405 return GNUNET_OK;
2530 reschedule_session_timeout (session); 2406 reschedule_session_timeout (session);
2531 session->flow_delay_for_other_peer 2407 session->flow_delay_for_other_peer =
2532 = plugin->env->receive (plugin->env->cls, 2408 plugin->env->receive (plugin->env->cls, session->address, session, hdr);
2533 session->address,
2534 session,
2535 hdr);
2536 return GNUNET_OK; 2409 return GNUNET_OK;
2537} 2410}
2538 2411
@@ -2552,8 +2425,7 @@ disconnect_and_free_it (void *cls,
2552{ 2425{
2553 struct Plugin *plugin = cls; 2426 struct Plugin *plugin = cls;
2554 2427
2555 udp_disconnect_session (plugin, 2428 udp_disconnect_session (plugin, value);
2556 value);
2557 return GNUNET_OK; 2429 return GNUNET_OK;
2558} 2430}
2559 2431
@@ -2567,8 +2439,7 @@ disconnect_and_free_it (void *cls,
2567 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed 2439 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed
2568 */ 2440 */
2569static void 2441static void
2570udp_disconnect (void *cls, 2442udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
2571 const struct GNUNET_PeerIdentity *target)
2572{ 2443{
2573 struct Plugin *plugin = cls; 2444 struct Plugin *plugin = cls;
2574 2445
@@ -2600,12 +2471,8 @@ session_timeout (void *cls)
2600 { 2471 {
2601 /* not actually our turn yet, but let's at least update 2472 /* not actually our turn yet, but let's at least update
2602 the monitor, it may think we're about to die ... */ 2473 the monitor, it may think we're about to die ... */
2603 notify_session_monitor (s->plugin, 2474 notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE);
2604 s, 2475 s->timeout_task = GNUNET_SCHEDULER_add_delayed (left, &session_timeout, s);
2605 GNUNET_TRANSPORT_SS_UPDATE);
2606 s->timeout_task = GNUNET_SCHEDULER_add_delayed (left,
2607 &session_timeout,
2608 s);
2609 return; 2476 return;
2610 } 2477 }
2611 LOG (GNUNET_ERROR_TYPE_DEBUG, 2478 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -2614,8 +2481,7 @@ session_timeout (void *cls)
2614 GNUNET_STRINGS_relative_time_to_string (UDP_SESSION_TIME_OUT, 2481 GNUNET_STRINGS_relative_time_to_string (UDP_SESSION_TIME_OUT,
2615 GNUNET_YES)); 2482 GNUNET_YES));
2616 /* call session destroy function */ 2483 /* call session destroy function */
2617 udp_disconnect_session (plugin, 2484 udp_disconnect_session (plugin, s);
2618 s);
2619} 2485}
2620 2486
2621 2487
@@ -2639,21 +2505,19 @@ udp_plugin_create_session (void *cls,
2639 struct GNUNET_ATS_Session *s; 2505 struct GNUNET_ATS_Session *s;
2640 2506
2641 s = GNUNET_new (struct GNUNET_ATS_Session); 2507 s = GNUNET_new (struct GNUNET_ATS_Session);
2642 s->mst = GNUNET_MST_create (&process_inbound_tokenized_messages, 2508 s->mst = GNUNET_MST_create (&process_inbound_tokenized_messages, s);
2643 s);
2644 s->plugin = plugin; 2509 s->plugin = plugin;
2645 s->address = GNUNET_HELLO_address_copy (address); 2510 s->address = GNUNET_HELLO_address_copy (address);
2646 s->target = address->peer; 2511 s->target = address->peer;
2647 s->last_transmit_time = GNUNET_TIME_absolute_get (); 2512 s->last_transmit_time = GNUNET_TIME_absolute_get ();
2648 s->last_expected_ack_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 2513 s->last_expected_ack_delay =
2649 250); 2514 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250);
2650 s->last_expected_msg_delay = GNUNET_TIME_UNIT_MILLISECONDS; 2515 s->last_expected_msg_delay = GNUNET_TIME_UNIT_MILLISECONDS;
2651 s->flow_delay_from_other_peer = GNUNET_TIME_UNIT_ZERO; 2516 s->flow_delay_from_other_peer = GNUNET_TIME_UNIT_ZERO;
2652 s->flow_delay_for_other_peer = GNUNET_TIME_UNIT_ZERO; 2517 s->flow_delay_for_other_peer = GNUNET_TIME_UNIT_ZERO;
2653 s->timeout = GNUNET_TIME_relative_to_absolute (UDP_SESSION_TIME_OUT); 2518 s->timeout = GNUNET_TIME_relative_to_absolute (UDP_SESSION_TIME_OUT);
2654 s->timeout_task = GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT, 2519 s->timeout_task =
2655 &session_timeout, 2520 GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT, &session_timeout, s);
2656 s);
2657 s->scope = network_type; 2521 s->scope = network_type;
2658 2522
2659 LOG (GNUNET_ERROR_TYPE_DEBUG, 2523 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -2663,18 +2527,16 @@ udp_plugin_create_session (void *cls,
2663 udp_address_to_string (plugin, 2527 udp_address_to_string (plugin,
2664 address->address, 2528 address->address,
2665 address->address_length)); 2529 address->address_length));
2666 GNUNET_assert (GNUNET_OK == 2530 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (
2667 GNUNET_CONTAINER_multipeermap_put (plugin->sessions, 2531 plugin->sessions,
2668 &s->target, 2532 &s->target,
2669 s, 2533 s,
2670 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 2534 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
2671 GNUNET_STATISTICS_set (plugin->env->stats, 2535 GNUNET_STATISTICS_set (plugin->env->stats,
2672 "# UDP sessions active", 2536 "# UDP sessions active",
2673 GNUNET_CONTAINER_multipeermap_size (plugin->sessions), 2537 GNUNET_CONTAINER_multipeermap_size (plugin->sessions),
2674 GNUNET_NO); 2538 GNUNET_NO);
2675 notify_session_monitor (plugin, 2539 notify_session_monitor (plugin, s, GNUNET_TRANSPORT_SS_INIT);
2676 s,
2677 GNUNET_TRANSPORT_SS_INIT);
2678 return s; 2540 return s;
2679} 2541}
2680 2542
@@ -2688,8 +2550,7 @@ udp_plugin_create_session (void *cls,
2688 * @return the session or NULL of max connections exceeded 2550 * @return the session or NULL of max connections exceeded
2689 */ 2551 */
2690static struct GNUNET_ATS_Session * 2552static struct GNUNET_ATS_Session *
2691udp_plugin_get_session (void *cls, 2553udp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address)
2692 const struct GNUNET_HELLO_Address *address)
2693{ 2554{
2694 struct Plugin *plugin = cls; 2555 struct Plugin *plugin = cls;
2695 struct GNUNET_ATS_Session *s; 2556 struct GNUNET_ATS_Session *s;
@@ -2702,14 +2563,13 @@ udp_plugin_get_session (void *cls,
2702 GNUNET_break (0); 2563 GNUNET_break (0);
2703 return NULL; 2564 return NULL;
2704 } 2565 }
2705 if ( (address->address_length != sizeof(struct IPv4UdpAddress)) && 2566 if ((address->address_length != sizeof (struct IPv4UdpAddress)) &&
2706 (address->address_length != sizeof(struct IPv6UdpAddress)) ) 2567 (address->address_length != sizeof (struct IPv6UdpAddress)))
2707 { 2568 {
2708 GNUNET_break_op (0); 2569 GNUNET_break_op (0);
2709 return NULL; 2570 return NULL;
2710 } 2571 }
2711 if (NULL != (s = udp_plugin_lookup_session (cls, 2572 if (NULL != (s = udp_plugin_lookup_session (cls, address)))
2712 address)))
2713 return s; 2573 return s;
2714 2574
2715 /* need to create new session */ 2575 /* need to create new session */
@@ -2746,9 +2606,7 @@ udp_plugin_get_session (void *cls,
2746 sizeof (v6)); 2606 sizeof (v6));
2747 } 2607 }
2748 GNUNET_break (GNUNET_NT_UNSPECIFIED != network_type); 2608 GNUNET_break (GNUNET_NT_UNSPECIFIED != network_type);
2749 return udp_plugin_create_session (cls, 2609 return udp_plugin_create_session (cls, address, network_type);
2750 address,
2751 network_type);
2752} 2610}
2753 2611
2754 2612
@@ -2774,13 +2632,13 @@ process_udp_message (struct Plugin *plugin,
2774 GNUNET_break (GNUNET_NT_UNSPECIFIED != network_type); 2632 GNUNET_break (GNUNET_NT_UNSPECIFIED != network_type);
2775 if (0 != ntohl (msg->reserved)) 2633 if (0 != ntohl (msg->reserved))
2776 { 2634 {
2777 GNUNET_break_op(0); 2635 GNUNET_break_op (0);
2778 return; 2636 return;
2779 } 2637 }
2780 if (ntohs (msg->header.size) 2638 if (ntohs (msg->header.size) <
2781 < sizeof(struct GNUNET_MessageHeader) + sizeof(struct UDPMessage)) 2639 sizeof (struct GNUNET_MessageHeader) + sizeof (struct UDPMessage))
2782 { 2640 {
2783 GNUNET_break_op(0); 2641 GNUNET_break_op (0);
2784 return; 2642 return;
2785 } 2643 }
2786 2644
@@ -2789,32 +2647,22 @@ process_udp_message (struct Plugin *plugin,
2789 udp_addr, 2647 udp_addr,
2790 udp_addr_len, 2648 udp_addr_len,
2791 GNUNET_HELLO_ADDRESS_INFO_NONE); 2649 GNUNET_HELLO_ADDRESS_INFO_NONE);
2792 if (NULL == 2650 if (NULL == (s = udp_plugin_lookup_session (plugin, address)))
2793 (s = udp_plugin_lookup_session (plugin,
2794 address)))
2795 { 2651 {
2796 s = udp_plugin_create_session (plugin, 2652 s = udp_plugin_create_session (plugin, address, network_type);
2797 address, 2653 plugin->env->session_start (plugin->env->cls, address, s, s->scope);
2798 network_type); 2654 notify_session_monitor (plugin, s, GNUNET_TRANSPORT_SS_UP);
2799 plugin->env->session_start (plugin->env->cls,
2800 address,
2801 s,
2802 s->scope);
2803 notify_session_monitor (plugin,
2804 s,
2805 GNUNET_TRANSPORT_SS_UP);
2806 } 2655 }
2807 GNUNET_free (address); 2656 GNUNET_free (address);
2808 2657
2809 s->rc++; 2658 s->rc++;
2810 GNUNET_MST_from_buffer (s->mst, 2659 GNUNET_MST_from_buffer (s->mst,
2811 (const char *) &msg[1], 2660 (const char *) &msg[1],
2812 ntohs (msg->header.size) - sizeof(struct UDPMessage), 2661 ntohs (msg->header.size) - sizeof (struct UDPMessage),
2813 GNUNET_YES, 2662 GNUNET_YES,
2814 GNUNET_NO); 2663 GNUNET_NO);
2815 s->rc--; 2664 s->rc--;
2816 if ( (0 == s->rc) && 2665 if ((0 == s->rc) && (GNUNET_YES == s->in_destroy))
2817 (GNUNET_YES == s->in_destroy) )
2818 free_session (s); 2666 free_session (s);
2819} 2667}
2820 2668
@@ -2826,8 +2674,7 @@ process_udp_message (struct Plugin *plugin,
2826 * @param msg the message 2674 * @param msg the message
2827 */ 2675 */
2828static void 2676static void
2829fragment_msg_proc (void *cls, 2677fragment_msg_proc (void *cls, const struct GNUNET_MessageHeader *msg)
2830 const struct GNUNET_MessageHeader *msg)
2831{ 2678{
2832 struct DefragContext *dc = cls; 2679 struct DefragContext *dc = cls;
2833 const struct UDPMessage *um; 2680 const struct UDPMessage *um;
@@ -2837,7 +2684,7 @@ fragment_msg_proc (void *cls,
2837 GNUNET_break_op (0); 2684 GNUNET_break_op (0);
2838 return; 2685 return;
2839 } 2686 }
2840 if (ntohs (msg->size) < sizeof(struct UDPMessage)) 2687 if (ntohs (msg->size) < sizeof (struct UDPMessage))
2841 { 2688 {
2842 GNUNET_break_op (0); 2689 GNUNET_break_op (0);
2843 return; 2690 return;
@@ -2863,9 +2710,7 @@ fragment_msg_proc (void *cls,
2863 * #GNUNET_SYSERR if we failed to send the ACK 2710 * #GNUNET_SYSERR if we failed to send the ACK
2864 */ 2711 */
2865static void 2712static void
2866ack_message_sent (void *cls, 2713ack_message_sent (void *cls, struct UDP_MessageWrapper *udpw, int result)
2867 struct UDP_MessageWrapper *udpw,
2868 int result)
2869{ 2714{
2870 struct Plugin *plugin = cls; 2715 struct Plugin *plugin = cls;
2871 2716
@@ -2894,13 +2739,11 @@ ack_message_sent (void *cls,
2894 * @param msg ack to transmit 2739 * @param msg ack to transmit
2895 */ 2740 */
2896static void 2741static void
2897ack_proc (void *cls, 2742ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
2898 uint32_t id,
2899 const struct GNUNET_MessageHeader *msg)
2900{ 2743{
2901 struct DefragContext *rc = cls; 2744 struct DefragContext *rc = cls;
2902 struct Plugin *plugin = rc->plugin; 2745 struct Plugin *plugin = rc->plugin;
2903 size_t msize = sizeof(struct UDP_ACK_Message) + ntohs (msg->size); 2746 size_t msize = sizeof (struct UDP_ACK_Message) + ntohs (msg->size);
2904 struct UDP_ACK_Message *udp_ack; 2747 struct UDP_ACK_Message *udp_ack;
2905 uint32_t delay; 2748 uint32_t delay;
2906 struct UDP_MessageWrapper *udpw; 2749 struct UDP_MessageWrapper *udpw;
@@ -2922,16 +2765,13 @@ ack_proc (void *cls,
2922 rc->udp_addr, 2765 rc->udp_addr,
2923 rc->udp_addr_len, 2766 rc->udp_addr_len,
2924 GNUNET_HELLO_ADDRESS_INFO_NONE); 2767 GNUNET_HELLO_ADDRESS_INFO_NONE);
2925 s = udp_plugin_lookup_session (plugin, 2768 s = udp_plugin_lookup_session (plugin, address);
2926 address);
2927 GNUNET_HELLO_address_free (address); 2769 GNUNET_HELLO_address_free (address);
2928 if (NULL == s) 2770 if (NULL == s)
2929 { 2771 {
2930 LOG (GNUNET_ERROR_TYPE_ERROR, 2772 LOG (GNUNET_ERROR_TYPE_ERROR,
2931 "Trying to transmit ACK to peer `%s' but no session found!\n", 2773 "Trying to transmit ACK to peer `%s' but no session found!\n",
2932 udp_address_to_string (plugin, 2774 udp_address_to_string (plugin, rc->udp_addr, rc->udp_addr_len));
2933 rc->udp_addr,
2934 rc->udp_addr_len));
2935 GNUNET_CONTAINER_heap_remove_node (rc->hnode); 2775 GNUNET_CONTAINER_heap_remove_node (rc->hnode);
2936 GNUNET_DEFRAGMENT_context_destroy (rc->defrag); 2776 GNUNET_DEFRAGMENT_context_destroy (rc->defrag);
2937 GNUNET_free (rc); 2777 GNUNET_free (rc);
@@ -2950,9 +2790,7 @@ ack_proc (void *cls,
2950 delay = UINT32_MAX - 1; /* largest value we can communicate */ 2790 delay = UINT32_MAX - 1; /* largest value we can communicate */
2951 LOG (GNUNET_ERROR_TYPE_DEBUG, 2791 LOG (GNUNET_ERROR_TYPE_DEBUG,
2952 "Sending ACK to `%s' including delay of %s\n", 2792 "Sending ACK to `%s' including delay of %s\n",
2953 udp_address_to_string (plugin, 2793 udp_address_to_string (plugin, rc->udp_addr, rc->udp_addr_len),
2954 rc->udp_addr,
2955 rc->udp_addr_len),
2956 GNUNET_STRINGS_relative_time_to_string (s->flow_delay_for_other_peer, 2794 GNUNET_STRINGS_relative_time_to_string (s->flow_delay_for_other_peer,
2957 GNUNET_YES)); 2795 GNUNET_YES));
2958 udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msize); 2796 udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msize);
@@ -2969,14 +2807,9 @@ ack_proc (void *cls,
2969 udp_ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK); 2807 udp_ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK);
2970 udp_ack->delay = htonl (delay); 2808 udp_ack->delay = htonl (delay);
2971 udp_ack->sender = *plugin->env->my_identity; 2809 udp_ack->sender = *plugin->env->my_identity;
2972 GNUNET_memcpy (&udp_ack[1], 2810 GNUNET_memcpy (&udp_ack[1], msg, ntohs (msg->size));
2973 msg, 2811 enqueue (plugin, udpw);
2974 ntohs (msg->size)); 2812 notify_session_monitor (plugin, s, GNUNET_TRANSPORT_SS_UPDATE);
2975 enqueue (plugin,
2976 udpw);
2977 notify_session_monitor (plugin,
2978 s,
2979 GNUNET_TRANSPORT_SS_UPDATE);
2980 if (s->address->address_length == sizeof (struct IPv4UdpAddress)) 2813 if (s->address->address_length == sizeof (struct IPv4UdpAddress))
2981 schedule_select_v4 (plugin); 2814 schedule_select_v4 (plugin);
2982 else 2815 else
@@ -3019,46 +2852,41 @@ read_process_fragment (struct Plugin *plugin,
3019 { 2852 {
3020 /* Create a new defragmentation context */ 2853 /* Create a new defragmentation context */
3021 d_ctx = GNUNET_malloc (sizeof (struct DefragContext) + udp_addr_len); 2854 d_ctx = GNUNET_malloc (sizeof (struct DefragContext) + udp_addr_len);
3022 GNUNET_memcpy (&d_ctx[1], 2855 GNUNET_memcpy (&d_ctx[1], udp_addr, udp_addr_len);
3023 udp_addr,
3024 udp_addr_len);
3025 d_ctx->udp_addr = (const union UdpAddress *) &d_ctx[1]; 2856 d_ctx->udp_addr = (const union UdpAddress *) &d_ctx[1];
3026 d_ctx->udp_addr_len = udp_addr_len; 2857 d_ctx->udp_addr_len = udp_addr_len;
3027 d_ctx->network_type = network_type; 2858 d_ctx->network_type = network_type;
3028 d_ctx->plugin = plugin; 2859 d_ctx->plugin = plugin;
3029 d_ctx->defrag = GNUNET_DEFRAGMENT_context_create (plugin->env->stats, 2860 d_ctx->defrag =
3030 UDP_MTU, 2861 GNUNET_DEFRAGMENT_context_create (plugin->env->stats,
3031 UDP_MAX_MESSAGES_IN_DEFRAG, 2862 UDP_MTU,
3032 d_ctx, 2863 UDP_MAX_MESSAGES_IN_DEFRAG,
3033 &fragment_msg_proc, 2864 d_ctx,
3034 &ack_proc); 2865 &fragment_msg_proc,
2866 &ack_proc);
3035 d_ctx->hnode = GNUNET_CONTAINER_heap_insert (plugin->defrag_ctxs, 2867 d_ctx->hnode = GNUNET_CONTAINER_heap_insert (plugin->defrag_ctxs,
3036 d_ctx, 2868 d_ctx,
3037 (GNUNET_CONTAINER_HeapCostType) now.abs_value_us); 2869 (GNUNET_CONTAINER_HeapCostType)
2870 now.abs_value_us);
3038 LOG (GNUNET_ERROR_TYPE_DEBUG, 2871 LOG (GNUNET_ERROR_TYPE_DEBUG,
3039 "Created new defragmentation context for %u-byte fragment from `%s'\n", 2872 "Created new defragmentation context for %u-byte fragment from `%s'\n",
3040 (unsigned int) ntohs (msg->size), 2873 (unsigned int) ntohs (msg->size),
3041 udp_address_to_string (plugin, 2874 udp_address_to_string (plugin, udp_addr, udp_addr_len));
3042 udp_addr,
3043 udp_addr_len));
3044 } 2875 }
3045 else 2876 else
3046 { 2877 {
3047 LOG (GNUNET_ERROR_TYPE_DEBUG, 2878 LOG (GNUNET_ERROR_TYPE_DEBUG,
3048 "Found existing defragmentation context for %u-byte fragment from `%s'\n", 2879 "Found existing defragmentation context for %u-byte fragment from `%s'\n",
3049 (unsigned int) ntohs (msg->size), 2880 (unsigned int) ntohs (msg->size),
3050 udp_address_to_string (plugin, 2881 udp_address_to_string (plugin, udp_addr, udp_addr_len));
3051 udp_addr,
3052 udp_addr_len));
3053 } 2882 }
3054 2883
3055 if (GNUNET_OK == 2884 if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (d_ctx->defrag, msg))
3056 GNUNET_DEFRAGMENT_process_fragment (d_ctx->defrag,
3057 msg))
3058 { 2885 {
3059 /* keep this 'rc' from expiring */ 2886 /* keep this 'rc' from expiring */
3060 GNUNET_CONTAINER_heap_update_cost (d_ctx->hnode, 2887 GNUNET_CONTAINER_heap_update_cost (d_ctx->hnode,
3061 (GNUNET_CONTAINER_HeapCostType) now.abs_value_us); 2888 (GNUNET_CONTAINER_HeapCostType)
2889 now.abs_value_us);
3062 } 2890 }
3063 if (GNUNET_CONTAINER_heap_get_size (plugin->defrag_ctxs) > 2891 if (GNUNET_CONTAINER_heap_get_size (plugin->defrag_ctxs) >
3064 UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG) 2892 UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG)
@@ -3083,8 +2911,7 @@ read_process_fragment (struct Plugin *plugin,
3083 * @param rsock socket to read from 2911 * @param rsock socket to read from
3084 */ 2912 */
3085static void 2913static void
3086udp_select_read (struct Plugin *plugin, 2914udp_select_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
3087 struct GNUNET_NETWORK_Handle *rsock)
3088{ 2915{
3089 socklen_t fromlen; 2916 socklen_t fromlen;
3090 struct sockaddr_storage addr; 2917 struct sockaddr_storage addr;
@@ -3101,9 +2928,7 @@ udp_select_read (struct Plugin *plugin,
3101 enum GNUNET_NetworkType network_type; 2928 enum GNUNET_NetworkType network_type;
3102 2929
3103 fromlen = sizeof (addr); 2930 fromlen = sizeof (addr);
3104 memset (&addr, 2931 memset (&addr, 0, sizeof (addr));
3105 0,
3106 sizeof(addr));
3107 size = GNUNET_NETWORK_socket_recvfrom (rsock, 2932 size = GNUNET_NETWORK_socket_recvfrom (rsock,
3108 buf, 2933 buf,
3109 sizeof (buf), 2934 sizeof (buf),
@@ -3121,15 +2946,14 @@ udp_select_read (struct Plugin *plugin,
3121 * error indicates a previous send operation resulted in an ICMP Port 2946 * error indicates a previous send operation resulted in an ICMP Port
3122 * Unreachable message. 2947 * Unreachable message.
3123 */ 2948 */
3124 if ( (-1 == size) && 2949 if ((-1 == size) && (ECONNRESET == errno))
3125 (ECONNRESET == errno) )
3126 return; 2950 return;
3127#endif 2951#endif
3128 if (-1 == size) 2952 if (-1 == size)
3129 { 2953 {
3130 LOG (GNUNET_ERROR_TYPE_DEBUG, 2954 LOG (GNUNET_ERROR_TYPE_DEBUG,
3131 "UDP failed to receive data: %s\n", 2955 "UDP failed to receive data: %s\n",
3132 STRERROR (errno)); 2956 strerror (errno));
3133 /* Connection failure or something. Not a protocol violation. */ 2957 /* Connection failure or something. Not a protocol violation. */
3134 return; 2958 return;
3135 } 2959 }
@@ -3137,19 +2961,18 @@ udp_select_read (struct Plugin *plugin,
3137 /* Check if this is a STUN packet */ 2961 /* Check if this is a STUN packet */
3138 if (GNUNET_NO != 2962 if (GNUNET_NO !=
3139 GNUNET_NAT_stun_handle_packet (plugin->nat, 2963 GNUNET_NAT_stun_handle_packet (plugin->nat,
3140 (const struct sockaddr *) &addr, 2964 (const struct sockaddr *) &addr,
3141 fromlen, 2965 fromlen,
3142 buf, 2966 buf,
3143 size)) 2967 size))
3144 return; /* was STUN, do not process further */ 2968 return; /* was STUN, do not process further */
3145 2969
3146 if (size < sizeof(struct GNUNET_MessageHeader)) 2970 if (size < sizeof (struct GNUNET_MessageHeader))
3147 { 2971 {
3148 LOG (GNUNET_ERROR_TYPE_WARNING, 2972 LOG (GNUNET_ERROR_TYPE_WARNING,
3149 "UDP got %u bytes from %s, which is not enough for a GNUnet message header\n", 2973 "UDP got %u bytes from %s, which is not enough for a GNUnet message header\n",
3150 (unsigned int ) size, 2974 (unsigned int) size,
3151 GNUNET_a2s (sa, 2975 GNUNET_a2s (sa, fromlen));
3152 fromlen));
3153 /* _MAY_ be a connection failure (got partial message) */ 2976 /* _MAY_ be a connection failure (got partial message) */
3154 /* But it _MAY_ also be that the other side uses non-GNUnet protocol. */ 2977 /* But it _MAY_ also be that the other side uses non-GNUnet protocol. */
3155 GNUNET_break_op (0); 2978 GNUNET_break_op (0);
@@ -3160,16 +2983,14 @@ udp_select_read (struct Plugin *plugin,
3160 LOG (GNUNET_ERROR_TYPE_DEBUG, 2983 LOG (GNUNET_ERROR_TYPE_DEBUG,
3161 "UDP received %u-byte message from `%s' type %u\n", 2984 "UDP received %u-byte message from `%s' type %u\n",
3162 (unsigned int) size, 2985 (unsigned int) size,
3163 GNUNET_a2s (sa, 2986 GNUNET_a2s (sa, fromlen),
3164 fromlen),
3165 ntohs (msg->type)); 2987 ntohs (msg->type));
3166 if (size != ntohs (msg->size)) 2988 if (size != ntohs (msg->size))
3167 { 2989 {
3168 LOG (GNUNET_ERROR_TYPE_WARNING, 2990 LOG (GNUNET_ERROR_TYPE_WARNING,
3169 "UDP malformed message (size %u) header from %s\n", 2991 "UDP malformed message (size %u) header from %s\n",
3170 (unsigned int) size, 2992 (unsigned int) size,
3171 GNUNET_a2s (sa, 2993 GNUNET_a2s (sa, fromlen));
3172 fromlen));
3173 GNUNET_break_op (0); 2994 GNUNET_break_op (0);
3174 return; 2995 return;
3175 } 2996 }
@@ -3177,9 +2998,7 @@ udp_select_read (struct Plugin *plugin,
3177 "# UDP, total bytes received", 2998 "# UDP, total bytes received",
3178 size, 2999 size,
3179 GNUNET_NO); 3000 GNUNET_NO);
3180 network_type = plugin->env->get_address_type (plugin->env->cls, 3001 network_type = plugin->env->get_address_type (plugin->env->cls, sa, fromlen);
3181 sa,
3182 fromlen);
3183 switch (sa->sa_family) 3002 switch (sa->sa_family)
3184 { 3003 {
3185 case AF_INET: 3004 case AF_INET:
@@ -3215,9 +3034,9 @@ udp_select_read (struct Plugin *plugin,
3215 network_type); 3034 network_type);
3216 return; 3035 return;
3217 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE: 3036 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE:
3218 if (ntohs (msg->size) < sizeof(struct UDPMessage)) 3037 if (ntohs (msg->size) < sizeof (struct UDPMessage))
3219 { 3038 {
3220 GNUNET_break_op(0); 3039 GNUNET_break_op (0);
3221 return; 3040 return;
3222 } 3041 }
3223 process_udp_message (plugin, 3042 process_udp_message (plugin,
@@ -3227,20 +3046,13 @@ udp_select_read (struct Plugin *plugin,
3227 network_type); 3046 network_type);
3228 return; 3047 return;
3229 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK: 3048 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK:
3230 read_process_ack (plugin, 3049 read_process_ack (plugin, msg, int_addr, int_addr_len);
3231 msg,
3232 int_addr,
3233 int_addr_len);
3234 return; 3050 return;
3235 case GNUNET_MESSAGE_TYPE_FRAGMENT: 3051 case GNUNET_MESSAGE_TYPE_FRAGMENT:
3236 read_process_fragment (plugin, 3052 read_process_fragment (plugin, msg, int_addr, int_addr_len, network_type);
3237 msg,
3238 int_addr,
3239 int_addr_len,
3240 network_type);
3241 return; 3053 return;
3242 default: 3054 default:
3243 GNUNET_break_op(0); 3055 GNUNET_break_op (0);
3244 return; 3056 return;
3245 } 3057 }
3246} 3058}
@@ -3265,9 +3077,8 @@ remove_timeout_messages_and_select (struct Plugin *plugin,
3265 int removed; 3077 int removed;
3266 3078
3267 removed = GNUNET_NO; 3079 removed = GNUNET_NO;
3268 udpw = (sock == plugin->sockv4) 3080 udpw = (sock == plugin->sockv4) ? plugin->ipv4_queue_head
3269 ? plugin->ipv4_queue_head 3081 : plugin->ipv6_queue_head;
3270 : plugin->ipv6_queue_head;
3271 while (NULL != udpw) 3082 while (NULL != udpw)
3272 { 3083 {
3273 session = udpw->session; 3084 session = udpw->session;
@@ -3277,11 +3088,8 @@ remove_timeout_messages_and_select (struct Plugin *plugin,
3277 { 3088 {
3278 /* Message timed out */ 3089 /* Message timed out */
3279 removed = GNUNET_YES; 3090 removed = GNUNET_YES;
3280 dequeue (plugin, 3091 dequeue (plugin, udpw);
3281 udpw); 3092 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR);
3282 udpw->qc (udpw->qc_cls,
3283 udpw,
3284 GNUNET_SYSERR);
3285 GNUNET_free (udpw); 3093 GNUNET_free (udpw);
3286 3094
3287 if (sock == plugin->sockv4) 3095 if (sock == plugin->sockv4)
@@ -3321,9 +3129,8 @@ remove_timeout_messages_and_select (struct Plugin *plugin,
3321 LOG (GNUNET_ERROR_TYPE_DEBUG, 3129 LOG (GNUNET_ERROR_TYPE_DEBUG,
3322 "Message for peer `%s' (%u bytes) is delayed for %s\n", 3130 "Message for peer `%s' (%u bytes) is delayed for %s\n",
3323 GNUNET_i2s (&udpw->session->target), 3131 GNUNET_i2s (&udpw->session->target),
3324 udpw->payload_size, 3132 udpw->payload_size,
3325 GNUNET_STRINGS_relative_time_to_string (remaining, 3133 GNUNET_STRINGS_relative_time_to_string (remaining, GNUNET_YES));
3326 GNUNET_YES));
3327 udpw = udpw->next; 3134 udpw = udpw->next;
3328 } 3135 }
3329 } 3136 }
@@ -3353,13 +3160,9 @@ analyze_send_error (struct Plugin *plugin,
3353{ 3160{
3354 enum GNUNET_NetworkType type; 3161 enum GNUNET_NetworkType type;
3355 3162
3356 type = plugin->env->get_address_type (plugin->env->cls, 3163 type = plugin->env->get_address_type (plugin->env->cls, sa, slen);
3357 sa, 3164 if (((GNUNET_NT_LAN == type) || (GNUNET_NT_WAN == type)) &&
3358 slen); 3165 ((ENETUNREACH == errno) || (ENETDOWN == errno)))
3359 if ( ( (GNUNET_NT_LAN == type) ||
3360 (GNUNET_NT_WAN == type) ) &&
3361 ( (ENETUNREACH == errno) ||
3362 (ENETDOWN == errno) ) )
3363 { 3166 {
3364 if (slen == sizeof (struct sockaddr_in)) 3167 if (slen == sizeof (struct sockaddr_in))
3365 { 3168 {
@@ -3368,10 +3171,9 @@ analyze_send_error (struct Plugin *plugin,
3368 * This indicates we do not have connectivity 3171 * This indicates we do not have connectivity
3369 */ 3172 */
3370 LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, 3173 LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
3371 _("UDP could not transmit message to `%s': " 3174 _ ("UDP could not transmit message to `%s': "
3372 "Network seems down, please check your network configuration\n"), 3175 "Network seems down, please check your network configuration\n"),
3373 GNUNET_a2s (sa, 3176 GNUNET_a2s (sa, slen));
3374 slen));
3375 } 3177 }
3376 if (slen == sizeof (struct sockaddr_in6)) 3178 if (slen == sizeof (struct sockaddr_in6))
3377 { 3179 {
@@ -3382,7 +3184,8 @@ analyze_send_error (struct Plugin *plugin,
3382 * connectivity 3184 * connectivity
3383 */ 3185 */
3384 LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, 3186 LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
3385 _("UDP could not transmit IPv6 message! " 3187 _ (
3188 "UDP could not transmit IPv6 message! "
3386 "Please check your network configuration and disable IPv6 if your " 3189 "Please check your network configuration and disable IPv6 if your "
3387 "connection does not have a global IPv6 address\n")); 3190 "connection does not have a global IPv6 address\n"));
3388 } 3191 }
@@ -3391,9 +3194,8 @@ analyze_send_error (struct Plugin *plugin,
3391 { 3194 {
3392 LOG (GNUNET_ERROR_TYPE_WARNING, 3195 LOG (GNUNET_ERROR_TYPE_WARNING,
3393 "UDP could not transmit message to `%s': `%s'\n", 3196 "UDP could not transmit message to `%s': `%s'\n",
3394 GNUNET_a2s (sa, 3197 GNUNET_a2s (sa, slen),
3395 slen), 3198 strerror (error));
3396 STRERROR (error));
3397 } 3199 }
3398} 3200}
3399 3201
@@ -3406,8 +3208,7 @@ analyze_send_error (struct Plugin *plugin,
3406 * @param sock which socket (v4/v6) to send on 3208 * @param sock which socket (v4/v6) to send on
3407 */ 3209 */
3408static void 3210static void
3409udp_select_send (struct Plugin *plugin, 3211udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
3410 struct GNUNET_NETWORK_Handle *sock)
3411{ 3212{
3412 ssize_t sent; 3213 ssize_t sent;
3413 socklen_t slen; 3214 socklen_t slen;
@@ -3419,15 +3220,13 @@ udp_select_send (struct Plugin *plugin,
3419 struct UDP_MessageWrapper *udpw; 3220 struct UDP_MessageWrapper *udpw;
3420 3221
3421 /* Find message(s) to send */ 3222 /* Find message(s) to send */
3422 while (NULL != (udpw = remove_timeout_messages_and_select (plugin, 3223 while (NULL != (udpw = remove_timeout_messages_and_select (plugin, sock)))
3423 sock)))
3424 { 3224 {
3425 if (sizeof (struct IPv4UdpAddress) == udpw->session->address->address_length) 3225 if (sizeof (struct IPv4UdpAddress) ==
3226 udpw->session->address->address_length)
3426 { 3227 {
3427 u4 = udpw->session->address->address; 3228 u4 = udpw->session->address->address;
3428 memset (&a4, 3229 memset (&a4, 0, sizeof (a4));
3429 0,
3430 sizeof(a4));
3431 a4.sin_family = AF_INET; 3230 a4.sin_family = AF_INET;
3432#if HAVE_SOCKADDR_IN_SIN_LEN 3231#if HAVE_SOCKADDR_IN_SIN_LEN
3433 a4.sin_len = sizeof (a4); 3232 a4.sin_len = sizeof (a4);
@@ -3437,12 +3236,11 @@ udp_select_send (struct Plugin *plugin,
3437 a = (const struct sockaddr *) &a4; 3236 a = (const struct sockaddr *) &a4;
3438 slen = sizeof (a4); 3237 slen = sizeof (a4);
3439 } 3238 }
3440 else if (sizeof (struct IPv6UdpAddress) == udpw->session->address->address_length) 3239 else if (sizeof (struct IPv6UdpAddress) ==
3240 udpw->session->address->address_length)
3441 { 3241 {
3442 u6 = udpw->session->address->address; 3242 u6 = udpw->session->address->address;
3443 memset (&a6, 3243 memset (&a6, 0, sizeof (a6));
3444 0,
3445 sizeof(a6));
3446 a6.sin6_family = AF_INET6; 3244 a6.sin6_family = AF_INET6;
3447#if HAVE_SOCKADDR_IN_SIN_LEN 3245#if HAVE_SOCKADDR_IN_SIN_LEN
3448 a6.sin6_len = sizeof (a6); 3246 a6.sin6_len = sizeof (a6);
@@ -3455,11 +3253,8 @@ udp_select_send (struct Plugin *plugin,
3455 else 3253 else
3456 { 3254 {
3457 GNUNET_break (0); 3255 GNUNET_break (0);
3458 dequeue (plugin, 3256 dequeue (plugin, udpw);
3459 udpw); 3257 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR);
3460 udpw->qc (udpw->qc_cls,
3461 udpw,
3462 GNUNET_SYSERR);
3463 notify_session_monitor (plugin, 3258 notify_session_monitor (plugin,
3464 udpw->session, 3259 udpw->session,
3465 GNUNET_TRANSPORT_SS_UPDATE); 3260 GNUNET_TRANSPORT_SS_UPDATE);
@@ -3471,21 +3266,15 @@ udp_select_send (struct Plugin *plugin,
3471 udpw->msg_size, 3266 udpw->msg_size,
3472 a, 3267 a,
3473 slen); 3268 slen);
3474 udpw->session->last_transmit_time 3269 udpw->session->last_transmit_time =
3475 = GNUNET_TIME_absolute_max (GNUNET_TIME_absolute_get (), 3270 GNUNET_TIME_absolute_max (GNUNET_TIME_absolute_get (),
3476 udpw->session->last_transmit_time); 3271 udpw->session->last_transmit_time);
3477 dequeue (plugin, 3272 dequeue (plugin, udpw);
3478 udpw);
3479 if (GNUNET_SYSERR == sent) 3273 if (GNUNET_SYSERR == sent)
3480 { 3274 {
3481 /* Failure */ 3275 /* Failure */
3482 analyze_send_error (plugin, 3276 analyze_send_error (plugin, a, slen, errno);
3483 a, 3277 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR);
3484 slen,
3485 errno);
3486 udpw->qc (udpw->qc_cls,
3487 udpw,
3488 GNUNET_SYSERR);
3489 GNUNET_STATISTICS_update (plugin->env->stats, 3278 GNUNET_STATISTICS_update (plugin->env->stats,
3490 "# UDP, total, bytes, sent, failure", 3279 "# UDP, total, bytes, sent, failure",
3491 sent, 3280 sent,
@@ -3502,10 +3291,9 @@ udp_select_send (struct Plugin *plugin,
3502 "UDP transmitted %u-byte message to `%s' `%s' (%d: %s)\n", 3291 "UDP transmitted %u-byte message to `%s' `%s' (%d: %s)\n",
3503 (unsigned int) (udpw->msg_size), 3292 (unsigned int) (udpw->msg_size),
3504 GNUNET_i2s (&udpw->session->target), 3293 GNUNET_i2s (&udpw->session->target),
3505 GNUNET_a2s (a, 3294 GNUNET_a2s (a, slen),
3506 slen), 3295 (int) sent,
3507 (int ) sent, 3296 (sent < 0) ? strerror (errno) : "ok");
3508 (sent < 0) ? STRERROR (errno) : "ok");
3509 GNUNET_STATISTICS_update (plugin->env->stats, 3297 GNUNET_STATISTICS_update (plugin->env->stats,
3510 "# UDP, total, bytes, sent, success", 3298 "# UDP, total, bytes, sent, success",
3511 sent, 3299 sent,
@@ -3516,13 +3304,9 @@ udp_select_send (struct Plugin *plugin,
3516 GNUNET_NO); 3304 GNUNET_NO);
3517 if (NULL != udpw->frag_ctx) 3305 if (NULL != udpw->frag_ctx)
3518 udpw->frag_ctx->on_wire_size += udpw->msg_size; 3306 udpw->frag_ctx->on_wire_size += udpw->msg_size;
3519 udpw->qc (udpw->qc_cls, 3307 udpw->qc (udpw->qc_cls, udpw, GNUNET_OK);
3520 udpw,
3521 GNUNET_OK);
3522 } 3308 }
3523 notify_session_monitor (plugin, 3309 notify_session_monitor (plugin, udpw->session, GNUNET_TRANSPORT_SS_UPDATE);
3524 udpw->session,
3525 GNUNET_TRANSPORT_SS_UPDATE);
3526 GNUNET_free (udpw); 3310 GNUNET_free (udpw);
3527 } 3311 }
3528} 3312}
@@ -3549,12 +3333,9 @@ udp_plugin_select_v4 (void *cls)
3549 return; 3333 return;
3550 tc = GNUNET_SCHEDULER_get_task_context (); 3334 tc = GNUNET_SCHEDULER_get_task_context ();
3551 if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) && 3335 if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
3552 (GNUNET_NETWORK_fdset_isset (tc->read_ready, 3336 (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv4)))
3553 plugin->sockv4))) 3337 udp_select_read (plugin, plugin->sockv4);
3554 udp_select_read (plugin, 3338 udp_select_send (plugin, plugin->sockv4);
3555 plugin->sockv4);
3556 udp_select_send (plugin,
3557 plugin->sockv4);
3558 schedule_select_v4 (plugin); 3339 schedule_select_v4 (plugin);
3559} 3340}
3560 3341
@@ -3576,14 +3357,11 @@ udp_plugin_select_v6 (void *cls)
3576 if (NULL == plugin->sockv6) 3357 if (NULL == plugin->sockv6)
3577 return; 3358 return;
3578 tc = GNUNET_SCHEDULER_get_task_context (); 3359 tc = GNUNET_SCHEDULER_get_task_context ();
3579 if ( (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) && 3360 if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
3580 (GNUNET_NETWORK_fdset_isset (tc->read_ready, 3361 (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv6)))
3581 plugin->sockv6)) ) 3362 udp_select_read (plugin, plugin->sockv6);
3582 udp_select_read (plugin, 3363
3583 plugin->sockv6); 3364 udp_select_send (plugin, plugin->sockv6);
3584
3585 udp_select_send (plugin,
3586 plugin->sockv6);
3587 schedule_select_v6 (plugin); 3365 schedule_select_v6 (plugin);
3588} 3366}
3589 3367
@@ -3618,20 +3396,16 @@ setup_sockets (struct Plugin *plugin,
3618 eno = EINVAL; 3396 eno = EINVAL;
3619 if (GNUNET_YES == plugin->enable_ipv6) 3397 if (GNUNET_YES == plugin->enable_ipv6)
3620 { 3398 {
3621 plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, 3399 plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0);
3622 SOCK_DGRAM,
3623 0);
3624 if (NULL == plugin->sockv6) 3400 if (NULL == plugin->sockv6)
3625 { 3401 {
3626 LOG (GNUNET_ERROR_TYPE_INFO, 3402 LOG (GNUNET_ERROR_TYPE_INFO,
3627 _("Disabling IPv6 since it is not supported on this system!\n")); 3403 _ ("Disabling IPv6 since it is not supported on this system!\n"));
3628 plugin->enable_ipv6 = GNUNET_NO; 3404 plugin->enable_ipv6 = GNUNET_NO;
3629 } 3405 }
3630 else 3406 else
3631 { 3407 {
3632 memset (&server_addrv6, 3408 memset (&server_addrv6, 0, sizeof (struct sockaddr_in6));
3633 0,
3634 sizeof(struct sockaddr_in6));
3635#if HAVE_SOCKADDR_IN_SIN_LEN 3409#if HAVE_SOCKADDR_IN_SIN_LEN
3636 server_addrv6.sin6_len = sizeof (struct sockaddr_in6); 3410 server_addrv6.sin6_len = sizeof (struct sockaddr_in6);
3637#endif 3411#endif
@@ -3642,10 +3416,9 @@ setup_sockets (struct Plugin *plugin,
3642 server_addrv6.sin6_addr = in6addr_any; 3416 server_addrv6.sin6_addr = in6addr_any;
3643 3417
3644 if (0 == plugin->port) /* autodetect */ 3418 if (0 == plugin->port) /* autodetect */
3645 server_addrv6.sin6_port 3419 server_addrv6.sin6_port = htons (
3646 = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 3420 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) +
3647 33537) 3421 32000);
3648 + 32000);
3649 else 3422 else
3650 server_addrv6.sin6_port = htons (plugin->port); 3423 server_addrv6.sin6_port = htons (plugin->port);
3651 addrlen = sizeof (struct sockaddr_in6); 3424 addrlen = sizeof (struct sockaddr_in6);
@@ -3654,15 +3427,12 @@ setup_sockets (struct Plugin *plugin,
3654 tries = 0; 3427 tries = 0;
3655 while (tries < 10) 3428 while (tries < 10)
3656 { 3429 {
3657 LOG(GNUNET_ERROR_TYPE_DEBUG, 3430 LOG (GNUNET_ERROR_TYPE_DEBUG,
3658 "Binding to IPv6 `%s'\n", 3431 "Binding to IPv6 `%s'\n",
3659 GNUNET_a2s (server_addr, 3432 GNUNET_a2s (server_addr, addrlen));
3660 addrlen));
3661 /* binding */ 3433 /* binding */
3662 if (GNUNET_OK == 3434 if (GNUNET_OK ==
3663 GNUNET_NETWORK_socket_bind (plugin->sockv6, 3435 GNUNET_NETWORK_socket_bind (plugin->sockv6, server_addr, addrlen))
3664 server_addr,
3665 addrlen))
3666 break; 3436 break;
3667 eno = errno; 3437 eno = errno;
3668 if (0 != plugin->port) 3438 if (0 != plugin->port)
@@ -3671,10 +3441,9 @@ setup_sockets (struct Plugin *plugin,
3671 break; /* bind failed on specific port */ 3441 break; /* bind failed on specific port */
3672 } 3442 }
3673 /* autodetect */ 3443 /* autodetect */
3674 server_addrv6.sin6_port 3444 server_addrv6.sin6_port = htons (
3675 = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 3445 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) +
3676 33537) 3446 32000);
3677 + 32000);
3678 tries++; 3447 tries++;
3679 } 3448 }
3680 if (tries >= 10) 3449 if (tries >= 10)
@@ -3691,8 +3460,7 @@ setup_sockets (struct Plugin *plugin,
3691 { 3460 {
3692 LOG (GNUNET_ERROR_TYPE_DEBUG, 3461 LOG (GNUNET_ERROR_TYPE_DEBUG,
3693 "IPv6 UDP socket created listinging at %s\n", 3462 "IPv6 UDP socket created listinging at %s\n",
3694 GNUNET_a2s (server_addr, 3463 GNUNET_a2s (server_addr, addrlen));
3695 addrlen));
3696 addrs[sockets_created] = server_addr; 3464 addrs[sockets_created] = server_addr;
3697 addrlens[sockets_created] = addrlen; 3465 addrlens[sockets_created] = addrlen;
3698 sockets_created++; 3466 sockets_created++;
@@ -3700,32 +3468,26 @@ setup_sockets (struct Plugin *plugin,
3700 else 3468 else
3701 { 3469 {
3702 LOG (GNUNET_ERROR_TYPE_WARNING, 3470 LOG (GNUNET_ERROR_TYPE_WARNING,
3703 _("Failed to bind UDP socket to %s: %s\n"), 3471 _ ("Failed to bind UDP socket to %s: %s\n"),
3704 GNUNET_a2s (server_addr, 3472 GNUNET_a2s (server_addr, addrlen),
3705 addrlen), 3473 strerror (eno));
3706 STRERROR (eno));
3707 } 3474 }
3708 } 3475 }
3709 } 3476 }
3710 3477
3711 /* Create IPv4 socket */ 3478 /* Create IPv4 socket */
3712 eno = EINVAL; 3479 eno = EINVAL;
3713 plugin->sockv4 = GNUNET_NETWORK_socket_create (PF_INET, 3480 plugin->sockv4 = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0);
3714 SOCK_DGRAM,
3715 0);
3716 if (NULL == plugin->sockv4) 3481 if (NULL == plugin->sockv4)
3717 { 3482 {
3718 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 3483 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
3719 "socket");
3720 LOG (GNUNET_ERROR_TYPE_INFO, 3484 LOG (GNUNET_ERROR_TYPE_INFO,
3721 _("Disabling IPv4 since it is not supported on this system!\n")); 3485 _ ("Disabling IPv4 since it is not supported on this system!\n"));
3722 plugin->enable_ipv4 = GNUNET_NO; 3486 plugin->enable_ipv4 = GNUNET_NO;
3723 } 3487 }
3724 else 3488 else
3725 { 3489 {
3726 memset (&server_addrv4, 3490 memset (&server_addrv4, 0, sizeof (struct sockaddr_in));
3727 0,
3728 sizeof(struct sockaddr_in));
3729#if HAVE_SOCKADDR_IN_SIN_LEN 3491#if HAVE_SOCKADDR_IN_SIN_LEN
3730 server_addrv4.sin_len = sizeof (struct sockaddr_in); 3492 server_addrv4.sin_len = sizeof (struct sockaddr_in);
3731#endif 3493#endif
@@ -3737,10 +3499,8 @@ setup_sockets (struct Plugin *plugin,
3737 3499
3738 if (0 == plugin->port) 3500 if (0 == plugin->port)
3739 /* autodetect */ 3501 /* autodetect */
3740 server_addrv4.sin_port 3502 server_addrv4.sin_port = htons (
3741 = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 3503 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000);
3742 33537)
3743 + 32000);
3744 else 3504 else
3745 server_addrv4.sin_port = htons (plugin->port); 3505 server_addrv4.sin_port = htons (plugin->port);
3746 3506
@@ -3752,14 +3512,11 @@ setup_sockets (struct Plugin *plugin,
3752 { 3512 {
3753 LOG (GNUNET_ERROR_TYPE_DEBUG, 3513 LOG (GNUNET_ERROR_TYPE_DEBUG,
3754 "Binding to IPv4 `%s'\n", 3514 "Binding to IPv4 `%s'\n",
3755 GNUNET_a2s (server_addr, 3515 GNUNET_a2s (server_addr, addrlen));
3756 addrlen));
3757 3516
3758 /* binding */ 3517 /* binding */
3759 if (GNUNET_OK == 3518 if (GNUNET_OK ==
3760 GNUNET_NETWORK_socket_bind (plugin->sockv4, 3519 GNUNET_NETWORK_socket_bind (plugin->sockv4, server_addr, addrlen))
3761 server_addr,
3762 addrlen))
3763 break; 3520 break;
3764 eno = errno; 3521 eno = errno;
3765 if (0 != plugin->port) 3522 if (0 != plugin->port)
@@ -3769,10 +3526,8 @@ setup_sockets (struct Plugin *plugin,
3769 } 3526 }
3770 3527
3771 /* autodetect */ 3528 /* autodetect */
3772 server_addrv4.sin_port 3529 server_addrv4.sin_port = htons (
3773 = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 3530 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000);
3774 33537)
3775 + 32000);
3776 tries++; 3531 tries++;
3777 } 3532 }
3778 if (tries >= 10) 3533 if (tries >= 10)
@@ -3790,8 +3545,7 @@ setup_sockets (struct Plugin *plugin,
3790 { 3545 {
3791 LOG (GNUNET_ERROR_TYPE_DEBUG, 3546 LOG (GNUNET_ERROR_TYPE_DEBUG,
3792 "IPv4 socket created on port %s\n", 3547 "IPv4 socket created on port %s\n",
3793 GNUNET_a2s (server_addr, 3548 GNUNET_a2s (server_addr, addrlen));
3794 addrlen));
3795 addrs[sockets_created] = server_addr; 3549 addrs[sockets_created] = server_addr;
3796 addrlens[sockets_created] = addrlen; 3550 addrlens[sockets_created] = addrlen;
3797 sockets_created++; 3551 sockets_created++;
@@ -3799,24 +3553,22 @@ setup_sockets (struct Plugin *plugin,
3799 else 3553 else
3800 { 3554 {
3801 LOG (GNUNET_ERROR_TYPE_ERROR, 3555 LOG (GNUNET_ERROR_TYPE_ERROR,
3802 _("Failed to bind UDP socket to %s: %s\n"), 3556 _ ("Failed to bind UDP socket to %s: %s\n"),
3803 GNUNET_a2s (server_addr, 3557 GNUNET_a2s (server_addr, addrlen),
3804 addrlen), 3558 strerror (eno));
3805 STRERROR (eno));
3806 } 3559 }
3807 } 3560 }
3808 3561
3809 if (0 == sockets_created) 3562 if (0 == sockets_created)
3810 { 3563 {
3811 LOG (GNUNET_ERROR_TYPE_WARNING, 3564 LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Failed to open UDP sockets\n"));
3812 _("Failed to open UDP sockets\n"));
3813 return 0; /* No sockets created, return */ 3565 return 0; /* No sockets created, return */
3814 } 3566 }
3815 schedule_select_v4 (plugin); 3567 schedule_select_v4 (plugin);
3816 schedule_select_v6 (plugin); 3568 schedule_select_v6 (plugin);
3817 plugin->nat = GNUNET_NAT_register (plugin->env->cfg, 3569 plugin->nat = GNUNET_NAT_register (plugin->env->cfg,
3818 "transport-udp", 3570 "transport-udp",
3819 IPPROTO_UDP, 3571 IPPROTO_UDP,
3820 sockets_created, 3572 sockets_created,
3821 addrs, 3573 addrs,
3822 addrlens, 3574 addrlens,
@@ -3869,64 +3621,55 @@ libgnunet_plugin_transport_udp_init (void *cls)
3869 3621
3870 /* Get port number: port == 0 : autodetect a port, 3622 /* Get port number: port == 0 : autodetect a port,
3871 * > 0 : use this port, not given : 2086 default */ 3623 * > 0 : use this port, not given : 2086 default */
3872 if (GNUNET_OK != 3624 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg,
3873 GNUNET_CONFIGURATION_get_value_number (env->cfg, 3625 "transport-udp",
3874 "transport-udp", 3626 "PORT",
3875 "PORT", 3627 &port))
3876 &port))
3877 port = 2086; 3628 port = 2086;
3878 if (port > 65535) 3629 if (port > 65535)
3879 { 3630 {
3880 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, 3631 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
3881 "transport-udp", 3632 "transport-udp",
3882 "PORT", 3633 "PORT",
3883 _("must be in [0,65535]")); 3634 _ ("must be in [0,65535]"));
3884 return NULL; 3635 return NULL;
3885 } 3636 }
3886 if (GNUNET_OK != 3637 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg,
3887 GNUNET_CONFIGURATION_get_value_number (env->cfg, 3638 "transport-udp",
3888 "transport-udp", 3639 "ADVERTISED_PORT",
3889 "ADVERTISED_PORT", 3640 &aport))
3890 &aport))
3891 aport = port; 3641 aport = port;
3892 if (aport > 65535) 3642 if (aport > 65535)
3893 { 3643 {
3894 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, 3644 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
3895 "transport-udp", 3645 "transport-udp",
3896 "ADVERTISED_PORT", 3646 "ADVERTISED_PORT",
3897 _("must be in [0,65535]")); 3647 _ ("must be in [0,65535]"));
3898 return NULL; 3648 return NULL;
3899 } 3649 }
3900 3650
3901 if (GNUNET_YES == 3651 if (GNUNET_YES ==
3902 GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 3652 GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "nat", "DISABLEV6"))
3903 "nat",
3904 "DISABLEV6"))
3905 enable_v6 = GNUNET_NO; 3653 enable_v6 = GNUNET_NO;
3906 else 3654 else
3907 enable_v6 = GNUNET_YES; 3655 enable_v6 = GNUNET_YES;
3908 3656
3909 have_bind4 = GNUNET_NO; 3657 have_bind4 = GNUNET_NO;
3910 memset (&server_addrv4, 3658 memset (&server_addrv4, 0, sizeof (server_addrv4));
3911 0, 3659 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (env->cfg,
3912 sizeof (server_addrv4)); 3660 "transport-udp",
3913 if (GNUNET_YES == 3661 "BINDTO",
3914 GNUNET_CONFIGURATION_get_value_string (env->cfg, 3662 &bind4_address))
3915 "transport-udp",
3916 "BINDTO",
3917 &bind4_address))
3918 { 3663 {
3919 LOG (GNUNET_ERROR_TYPE_DEBUG, 3664 LOG (GNUNET_ERROR_TYPE_DEBUG,
3920 "Binding UDP plugin to specific address: `%s'\n", 3665 "Binding UDP plugin to specific address: `%s'\n",
3921 bind4_address); 3666 bind4_address);
3922 if (1 != inet_pton (AF_INET, 3667 if (1 != inet_pton (AF_INET, bind4_address, &server_addrv4.sin_addr))
3923 bind4_address,
3924 &server_addrv4.sin_addr))
3925 { 3668 {
3926 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, 3669 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
3927 "transport-udp", 3670 "transport-udp",
3928 "BINDTO", 3671 "BINDTO",
3929 _("must be valid IPv4 address")); 3672 _ ("must be valid IPv4 address"));
3930 GNUNET_free (bind4_address); 3673 GNUNET_free (bind4_address);
3931 return NULL; 3674 return NULL;
3932 } 3675 }
@@ -3934,26 +3677,21 @@ libgnunet_plugin_transport_udp_init (void *cls)
3934 } 3677 }
3935 GNUNET_free_non_null (bind4_address); 3678 GNUNET_free_non_null (bind4_address);
3936 have_bind6 = GNUNET_NO; 3679 have_bind6 = GNUNET_NO;
3937 memset (&server_addrv6, 3680 memset (&server_addrv6, 0, sizeof (server_addrv6));
3938 0, 3681 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (env->cfg,
3939 sizeof (server_addrv6)); 3682 "transport-udp",
3940 if (GNUNET_YES == 3683 "BINDTO6",
3941 GNUNET_CONFIGURATION_get_value_string (env->cfg, 3684 &bind6_address))
3942 "transport-udp",
3943 "BINDTO6",
3944 &bind6_address))
3945 { 3685 {
3946 LOG (GNUNET_ERROR_TYPE_DEBUG, 3686 LOG (GNUNET_ERROR_TYPE_DEBUG,
3947 "Binding udp plugin to specific address: `%s'\n", 3687 "Binding udp plugin to specific address: `%s'\n",
3948 bind6_address); 3688 bind6_address);
3949 if (1 != inet_pton (AF_INET6, 3689 if (1 != inet_pton (AF_INET6, bind6_address, &server_addrv6.sin6_addr))
3950 bind6_address,
3951 &server_addrv6.sin6_addr))
3952 { 3690 {
3953 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, 3691 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
3954 "transport-udp", 3692 "transport-udp",
3955 "BINDTO6", 3693 "BINDTO6",
3956 _("must be valid IPv6 address")); 3694 _ ("must be valid IPv6 address"));
3957 GNUNET_free (bind6_address); 3695 GNUNET_free (bind6_address);
3958 return NULL; 3696 return NULL;
3959 } 3697 }
@@ -3967,9 +3705,10 @@ libgnunet_plugin_transport_udp_init (void *cls)
3967 if (enable_broadcasting == GNUNET_SYSERR) 3705 if (enable_broadcasting == GNUNET_SYSERR)
3968 enable_broadcasting = GNUNET_NO; 3706 enable_broadcasting = GNUNET_NO;
3969 3707
3970 enable_broadcasting_recv = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 3708 enable_broadcasting_recv =
3971 "transport-udp", 3709 GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
3972 "BROADCAST_RECEIVE"); 3710 "transport-udp",
3711 "BROADCAST_RECEIVE");
3973 if (enable_broadcasting_recv == GNUNET_SYSERR) 3712 if (enable_broadcasting_recv == GNUNET_SYSERR)
3974 enable_broadcasting_recv = GNUNET_YES; 3713 enable_broadcasting_recv = GNUNET_YES;
3975 3714
@@ -3979,14 +3718,12 @@ libgnunet_plugin_transport_udp_init (void *cls)
3979 "BROADCAST_INTERVAL", 3718 "BROADCAST_INTERVAL",
3980 &interval)) 3719 &interval))
3981 { 3720 {
3982 interval = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3721 interval = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10);
3983 10);
3984 } 3722 }
3985 if (GNUNET_OK != 3723 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg,
3986 GNUNET_CONFIGURATION_get_value_number (env->cfg, 3724 "transport-udp",
3987 "transport-udp", 3725 "MAX_BPS",
3988 "MAX_BPS", 3726 &udp_max_bps))
3989 &udp_max_bps))
3990 { 3727 {
3991 /* 50 MB/s == infinity for practical purposes */ 3728 /* 50 MB/s == infinity for practical purposes */
3992 udp_max_bps = 1024 * 1024 * 50; 3729 udp_max_bps = 1024 * 1024 * 50;
@@ -4001,23 +3738,21 @@ libgnunet_plugin_transport_udp_init (void *cls)
4001 p->enable_broadcasting = enable_broadcasting; 3738 p->enable_broadcasting = enable_broadcasting;
4002 p->enable_broadcasting_receiving = enable_broadcasting_recv; 3739 p->enable_broadcasting_receiving = enable_broadcasting_recv;
4003 p->env = env; 3740 p->env = env;
4004 p->sessions = GNUNET_CONTAINER_multipeermap_create (16, 3741 p->sessions = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_NO);
4005 GNUNET_NO); 3742 p->defrag_ctxs =
4006 p->defrag_ctxs = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 3743 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
4007 GNUNET_BANDWIDTH_tracker_init (&p->tracker, 3744 GNUNET_BANDWIDTH_tracker_init (&p->tracker,
4008 NULL, 3745 NULL,
4009 NULL, 3746 NULL,
4010 GNUNET_BANDWIDTH_value_init ((uint32_t) udp_max_bps), 3747 GNUNET_BANDWIDTH_value_init (
3748 (uint32_t) udp_max_bps),
4011 30); 3749 30);
4012 res = setup_sockets (p, 3750 res = setup_sockets (p,
4013 (GNUNET_YES == have_bind6) ? &server_addrv6 : NULL, 3751 (GNUNET_YES == have_bind6) ? &server_addrv6 : NULL,
4014 (GNUNET_YES == have_bind4) ? &server_addrv4 : NULL); 3752 (GNUNET_YES == have_bind4) ? &server_addrv4 : NULL);
4015 if ( (0 == res) || 3753 if ((0 == res) || ((NULL == p->sockv4) && (NULL == p->sockv6)))
4016 ( (NULL == p->sockv4) &&
4017 (NULL == p->sockv6) ) )
4018 { 3754 {
4019 LOG (GNUNET_ERROR_TYPE_ERROR, 3755 LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Failed to create UDP network sockets\n"));
4020 _("Failed to create UDP network sockets\n"));
4021 GNUNET_CONTAINER_multipeermap_destroy (p->sessions); 3756 GNUNET_CONTAINER_multipeermap_destroy (p->sessions);
4022 GNUNET_CONTAINER_heap_destroy (p->defrag_ctxs); 3757 GNUNET_CONTAINER_heap_destroy (p->defrag_ctxs);
4023 if (NULL != p->nat) 3758 if (NULL != p->nat)
@@ -4027,9 +3762,7 @@ libgnunet_plugin_transport_udp_init (void *cls)
4027 } 3762 }
4028 3763
4029 /* Setup broadcasting and receiving beacons */ 3764 /* Setup broadcasting and receiving beacons */
4030 setup_broadcast (p, 3765 setup_broadcast (p, &server_addrv6, &server_addrv4);
4031 &server_addrv6,
4032 &server_addrv4);
4033 3766
4034 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); 3767 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
4035 api->cls = p; 3768 api->cls = p;
@@ -4108,14 +3841,12 @@ libgnunet_plugin_transport_udp_done (void *cls)
4108 } 3841 }
4109 if (NULL != plugin->sockv4) 3842 if (NULL != plugin->sockv4)
4110 { 3843 {
4111 GNUNET_break (GNUNET_OK == 3844 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4));
4112 GNUNET_NETWORK_socket_close (plugin->sockv4));
4113 plugin->sockv4 = NULL; 3845 plugin->sockv4 = NULL;
4114 } 3846 }
4115 if (NULL != plugin->sockv6) 3847 if (NULL != plugin->sockv6)
4116 { 3848 {
4117 GNUNET_break (GNUNET_OK == 3849 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6));
4118 GNUNET_NETWORK_socket_close (plugin->sockv6));
4119 plugin->sockv6 = NULL; 3850 plugin->sockv6 = NULL;
4120 } 3851 }
4121 if (NULL != plugin->nat) 3852 if (NULL != plugin->nat)
@@ -4133,20 +3864,14 @@ libgnunet_plugin_transport_udp_done (void *cls)
4133 } 3864 }
4134 while (NULL != (udpw = plugin->ipv4_queue_head)) 3865 while (NULL != (udpw = plugin->ipv4_queue_head))
4135 { 3866 {
4136 dequeue (plugin, 3867 dequeue (plugin, udpw);
4137 udpw); 3868 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR);
4138 udpw->qc (udpw->qc_cls,
4139 udpw,
4140 GNUNET_SYSERR);
4141 GNUNET_free (udpw); 3869 GNUNET_free (udpw);
4142 } 3870 }
4143 while (NULL != (udpw = plugin->ipv6_queue_head)) 3871 while (NULL != (udpw = plugin->ipv6_queue_head))
4144 { 3872 {
4145 dequeue (plugin, 3873 dequeue (plugin, udpw);
4146 udpw); 3874 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR);
4147 udpw->qc (udpw->qc_cls,
4148 udpw,
4149 GNUNET_SYSERR);
4150 GNUNET_free (udpw); 3875 GNUNET_free (udpw);
4151 } 3876 }
4152 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, 3877 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions,
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c
index 5d095236d..2c408ebf5 100644
--- a/src/transport/plugin_transport_unix.c
+++ b/src/transport/plugin_transport_unix.c
@@ -68,9 +68,10 @@ enum UNIX_ADDRESS_OPTIONS
68/** 68/**
69 * How long until we give up on transmitting the welcome message? 69 * How long until we give up on transmitting the welcome message?
70 */ 70 */
71#define HOSTNAME_RESOLVE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) 71#define HOSTNAME_RESOLVE_TIMEOUT \
72 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
72 73
73#define LOG(kind,...) GNUNET_log_from (kind, "transport-unix",__VA_ARGS__) 74#define LOG(kind, ...) GNUNET_log_from (kind, "transport-unix", __VA_ARGS__)
74 75
75 76
76GNUNET_NETWORK_STRUCT_BEGIN 77GNUNET_NETWORK_STRUCT_BEGIN
@@ -108,7 +109,6 @@ struct UNIXMessage
108 * What is the identity of the sender (GNUNET_hash of public key) 109 * What is the identity of the sender (GNUNET_hash of public key)
109 */ 110 */
110 struct GNUNET_PeerIdentity sender; 111 struct GNUNET_PeerIdentity sender;
111
112}; 112};
113 113
114GNUNET_NETWORK_STRUCT_END 114GNUNET_NETWORK_STRUCT_END
@@ -218,13 +218,12 @@ struct GNUNET_ATS_Session
218 /** 218 /**
219 * Session timeout task. 219 * Session timeout task.
220 */ 220 */
221 struct GNUNET_SCHEDULER_Task * timeout_task; 221 struct GNUNET_SCHEDULER_Task *timeout_task;
222 222
223 /** 223 /**
224 * Number of messages we currently have in our write queue. 224 * Number of messages we currently have in our write queue.
225 */ 225 */
226 unsigned int msgs_in_queue; 226 unsigned int msgs_in_queue;
227
228}; 227};
229 228
230 229
@@ -255,17 +254,17 @@ struct Plugin
255 /** 254 /**
256 * ID of task used to update our addresses when one expires. 255 * ID of task used to update our addresses when one expires.
257 */ 256 */
258 struct GNUNET_SCHEDULER_Task * address_update_task; 257 struct GNUNET_SCHEDULER_Task *address_update_task;
259 258
260 /** 259 /**
261 * ID of read task 260 * ID of read task
262 */ 261 */
263 struct GNUNET_SCHEDULER_Task * read_task; 262 struct GNUNET_SCHEDULER_Task *read_task;
264 263
265 /** 264 /**
266 * ID of write task 265 * ID of write task
267 */ 266 */
268 struct GNUNET_SCHEDULER_Task * write_task; 267 struct GNUNET_SCHEDULER_Task *write_task;
269 268
270 /** 269 /**
271 * Number of bytes we currently have in our write queues. 270 * Number of bytes we currently have in our write queues.
@@ -321,7 +320,6 @@ struct Plugin
321 * Are we using an abstract UNIX domain socket? 320 * Are we using an abstract UNIX domain socket?
322 */ 321 */
323 int is_abstract; 322 int is_abstract;
324
325}; 323};
326 324
327 325
@@ -352,9 +350,7 @@ notify_session_monitor (struct Plugin *plugin,
352 to receive from others) */ 350 to receive from others) */
353 info.session_timeout = session->timeout; 351 info.session_timeout = session->timeout;
354 info.address = session->address; 352 info.address = session->address;
355 plugin->sic (plugin->sic_cls, 353 plugin->sic (plugin->sic_cls, session, &info);
356 session,
357 &info);
358} 354}
359 355
360 356
@@ -370,9 +366,7 @@ notify_session_monitor (struct Plugin *plugin,
370 * @return string representing the same address 366 * @return string representing the same address
371 */ 367 */
372static const char * 368static const char *
373unix_plugin_address_to_string (void *cls, 369unix_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
374 const void *addr,
375 size_t addrlen)
376{ 370{
377 static char rbuf[1024]; 371 static char rbuf[1024];
378 struct UnixAddress *ua = (struct UnixAddress *) addr; 372 struct UnixAddress *ua = (struct UnixAddress *) addr;
@@ -382,25 +376,25 @@ unix_plugin_address_to_string (void *cls,
382 376
383 if ((NULL == addr) || (sizeof (struct UnixAddress) > addrlen)) 377 if ((NULL == addr) || (sizeof (struct UnixAddress) > addrlen))
384 { 378 {
385 GNUNET_break(0); 379 GNUNET_break (0);
386 return NULL; 380 return NULL;
387 } 381 }
388 addrstr = (char *) &ua[1]; 382 addrstr = (char *) &ua[1];
389 addr_str_len = ntohl (ua->addrlen); 383 addr_str_len = ntohl (ua->addrlen);
390 384
391 if (addr_str_len != addrlen - sizeof(struct UnixAddress)) 385 if (addr_str_len != addrlen - sizeof (struct UnixAddress))
392 { 386 {
393 GNUNET_break(0); 387 GNUNET_break (0);
394 return NULL; 388 return NULL;
395 } 389 }
396 if ('\0' != addrstr[addr_str_len - 1]) 390 if ('\0' != addrstr[addr_str_len - 1])
397 { 391 {
398 GNUNET_break(0); 392 GNUNET_break (0);
399 return NULL; 393 return NULL;
400 } 394 }
401 if (strlen (addrstr) + 1 != addr_str_len) 395 if (strlen (addrstr) + 1 != addr_str_len)
402 { 396 {
403 GNUNET_break(0); 397 GNUNET_break (0);
404 return NULL; 398 return NULL;
405 } 399 }
406 400
@@ -430,8 +424,7 @@ unix_plugin_address_to_string (void *cls,
430 * @return #GNUNET_OK on success 424 * @return #GNUNET_OK on success
431 */ 425 */
432static int 426static int
433unix_plugin_session_disconnect (void *cls, 427unix_plugin_session_disconnect (void *cls, struct GNUNET_ATS_Session *session)
434 struct GNUNET_ATS_Session *session)
435{ 428{
436 struct Plugin *plugin = cls; 429 struct Plugin *plugin = cls;
437 struct UNIXMessageWrapper *msgw; 430 struct UNIXMessageWrapper *msgw;
@@ -443,9 +436,7 @@ unix_plugin_session_disconnect (void *cls,
443 unix_plugin_address_to_string (NULL, 436 unix_plugin_address_to_string (NULL,
444 session->address->address, 437 session->address->address,
445 session->address->address_length)); 438 session->address->address_length));
446 plugin->env->session_end (plugin->env->cls, 439 plugin->env->session_end (plugin->env->cls, session->address, session);
447 session->address,
448 session);
449 next = plugin->msg_head; 440 next = plugin->msg_head;
450 while (NULL != next) 441 while (NULL != next)
451 { 442 {
@@ -453,9 +444,7 @@ unix_plugin_session_disconnect (void *cls,
453 next = msgw->next; 444 next = msgw->next;
454 if (msgw->session != session) 445 if (msgw->session != session)
455 continue; 446 continue;
456 GNUNET_CONTAINER_DLL_remove (plugin->msg_head, 447 GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw);
457 plugin->msg_tail,
458 msgw);
459 session->msgs_in_queue--; 448 session->msgs_in_queue--;
460 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); 449 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
461 session->bytes_in_queue -= msgw->msgsize; 450 session->bytes_in_queue -= msgw->msgsize;
@@ -465,27 +454,27 @@ unix_plugin_session_disconnect (void *cls,
465 msgw->cont (msgw->cont_cls, 454 msgw->cont (msgw->cont_cls,
466 &msgw->session->target, 455 &msgw->session->target,
467 GNUNET_SYSERR, 456 GNUNET_SYSERR,
468 msgw->payload, 0); 457 msgw->payload,
458 0);
469 GNUNET_free (msgw->msg); 459 GNUNET_free (msgw->msg);
470 GNUNET_free (msgw); 460 GNUNET_free (msgw);
471 } 461 }
472 GNUNET_assert (GNUNET_YES == 462 GNUNET_assert (GNUNET_YES ==
473 GNUNET_CONTAINER_multipeermap_remove (plugin->session_map, 463 GNUNET_CONTAINER_multipeermap_remove (plugin->session_map,
474 &session->target, 464 &session->target,
475 session)); 465 session));
476 GNUNET_STATISTICS_set (plugin->env->stats, 466 GNUNET_STATISTICS_set (plugin->env->stats,
477 "# UNIX sessions active", 467 "# UNIX sessions active",
478 GNUNET_CONTAINER_multipeermap_size (plugin->session_map), 468 GNUNET_CONTAINER_multipeermap_size (
479 GNUNET_NO); 469 plugin->session_map),
470 GNUNET_NO);
480 if (NULL != session->timeout_task) 471 if (NULL != session->timeout_task)
481 { 472 {
482 GNUNET_SCHEDULER_cancel (session->timeout_task); 473 GNUNET_SCHEDULER_cancel (session->timeout_task);
483 session->timeout_task = NULL; 474 session->timeout_task = NULL;
484 session->timeout = GNUNET_TIME_UNIT_ZERO_ABS; 475 session->timeout = GNUNET_TIME_UNIT_ZERO_ABS;
485 } 476 }
486 notify_session_monitor (plugin, 477 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_DONE);
487 session,
488 GNUNET_TRANSPORT_SS_DONE);
489 GNUNET_HELLO_address_free (session->address); 478 GNUNET_HELLO_address_free (session->address);
490 GNUNET_break (0 == session->bytes_in_queue); 479 GNUNET_break (0 == session->bytes_in_queue);
491 GNUNET_break (0 == session->msgs_in_queue); 480 GNUNET_break (0 == session->msgs_in_queue);
@@ -514,16 +503,16 @@ session_timeout (void *cls)
514 notify_session_monitor (session->plugin, 503 notify_session_monitor (session->plugin,
515 session, 504 session,
516 GNUNET_TRANSPORT_SS_UPDATE); 505 GNUNET_TRANSPORT_SS_UPDATE);
517 session->timeout_task = GNUNET_SCHEDULER_add_delayed (left, 506 session->timeout_task =
518 &session_timeout, 507 GNUNET_SCHEDULER_add_delayed (left, &session_timeout, session);
519 session);
520 return; 508 return;
521 } 509 }
522 LOG (GNUNET_ERROR_TYPE_DEBUG, 510 LOG (GNUNET_ERROR_TYPE_DEBUG,
523 "Session %p was idle for %s, disconnecting\n", 511 "Session %p was idle for %s, disconnecting\n",
524 session, 512 session,
525 GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 513 GNUNET_STRINGS_relative_time_to_string (
526 GNUNET_YES)); 514 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
515 GNUNET_YES));
527 unix_plugin_session_disconnect (session->plugin, session); 516 unix_plugin_session_disconnect (session->plugin, session);
528} 517}
529 518
@@ -539,7 +528,8 @@ static void
539reschedule_session_timeout (struct GNUNET_ATS_Session *session) 528reschedule_session_timeout (struct GNUNET_ATS_Session *session)
540{ 529{
541 GNUNET_assert (NULL != session->timeout_task); 530 GNUNET_assert (NULL != session->timeout_task);
542 session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 531 session->timeout =
532 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
543} 533}
544 534
545 535
@@ -551,13 +541,12 @@ reschedule_session_timeout (struct GNUNET_ATS_Session *session)
551 * @return converted unix path 541 * @return converted unix path
552 */ 542 */
553static struct sockaddr_un * 543static struct sockaddr_un *
554unix_address_to_sockaddr (const char *unixpath, 544unix_address_to_sockaddr (const char *unixpath, socklen_t *sock_len)
555 socklen_t *sock_len)
556{ 545{
557 struct sockaddr_un *un; 546 struct sockaddr_un *un;
558 size_t slen; 547 size_t slen;
559 548
560 GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ 549 GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
561 un = GNUNET_new (struct sockaddr_un); 550 un = GNUNET_new (struct sockaddr_un);
562 un->sun_family = AF_UNIX; 551 un->sun_family = AF_UNIX;
563 slen = strlen (unixpath); 552 slen = strlen (unixpath);
@@ -601,14 +590,13 @@ struct LookupCtx
601 */ 590 */
602static int 591static int
603lookup_session_it (void *cls, 592lookup_session_it (void *cls,
604 const struct GNUNET_PeerIdentity * key, 593 const struct GNUNET_PeerIdentity *key,
605 void *value) 594 void *value)
606{ 595{
607 struct LookupCtx *lctx = cls; 596 struct LookupCtx *lctx = cls;
608 struct GNUNET_ATS_Session *session = value; 597 struct GNUNET_ATS_Session *session = value;
609 598
610 if (0 == GNUNET_HELLO_address_cmp (lctx->address, 599 if (0 == GNUNET_HELLO_address_cmp (lctx->address, session->address))
611 session->address))
612 { 600 {
613 lctx->res = session; 601 lctx->res = session;
614 return GNUNET_NO; 602 return GNUNET_NO;
@@ -633,8 +621,9 @@ lookup_session (struct Plugin *plugin,
633 lctx.address = address; 621 lctx.address = address;
634 lctx.res = NULL; 622 lctx.res = NULL;
635 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, 623 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map,
636 &address->peer, 624 &address->peer,
637 &lookup_session_it, &lctx); 625 &lookup_session_it,
626 &lctx);
638 return lctx.res; 627 return lctx.res;
639} 628}
640 629
@@ -707,16 +696,15 @@ unix_real_send (void *cls,
707 } 696 }
708 697
709 /* Prepare address */ 698 /* Prepare address */
710 unixpath = (const char *) &addr[1]; 699 unixpath = (const char *) &addr[1];
711 if (NULL == (un = unix_address_to_sockaddr (unixpath, 700 if (NULL == (un = unix_address_to_sockaddr (unixpath, &un_len)))
712 &un_len)))
713 { 701 {
714 GNUNET_break (0); 702 GNUNET_break (0);
715 return -1; 703 return -1;
716 } 704 }
717 705
718 if ((GNUNET_YES == plugin->is_abstract) && 706 if ((GNUNET_YES == plugin->is_abstract) &&
719 (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & ntohl(addr->options) )) ) 707 (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & ntohl (addr->options))))
720 { 708 {
721 un->sun_path[0] = '\0'; 709 un->sun_path[0] = '\0';
722 } 710 }
@@ -729,8 +717,7 @@ resend:
729 un_len); 717 un_len);
730 if (GNUNET_SYSERR == sent) 718 if (GNUNET_SYSERR == sent)
731 { 719 {
732 if ( (EAGAIN == errno) || 720 if ((EAGAIN == errno) || (ENOBUFS == errno))
733 (ENOBUFS == errno) )
734 { 721 {
735 GNUNET_free (un); 722 GNUNET_free (un);
736 return RETRY; /* We have to retry later */ 723 return RETRY; /* We have to retry later */
@@ -741,7 +728,10 @@ resend:
741 socklen_t len = sizeof (size); 728 socklen_t len = sizeof (size);
742 729
743 GNUNET_NETWORK_socket_getsockopt ((struct GNUNET_NETWORK_Handle *) 730 GNUNET_NETWORK_socket_getsockopt ((struct GNUNET_NETWORK_Handle *)
744 send_handle, SOL_SOCKET, SO_SNDBUF, &size, 731 send_handle,
732 SOL_SOCKET,
733 SO_SNDBUF,
734 &size,
745 &len); 735 &len);
746 if (size < msgbuf_size) 736 if (size < msgbuf_size)
747 { 737 {
@@ -752,9 +742,12 @@ resend:
752 (unsigned int) msgbuf_size); 742 (unsigned int) msgbuf_size);
753 size = ((msgbuf_size / 1000) + 2) * 1000; 743 size = ((msgbuf_size / 1000) + 2) * 1000;
754 if (GNUNET_OK == 744 if (GNUNET_OK ==
755 GNUNET_NETWORK_socket_setsockopt ((struct GNUNET_NETWORK_Handle *) send_handle, 745 GNUNET_NETWORK_socket_setsockopt ((struct GNUNET_NETWORK_Handle *)
756 SOL_SOCKET, SO_SNDBUF, 746 send_handle,
757 &size, sizeof (size))) 747 SOL_SOCKET,
748 SO_SNDBUF,
749 &size,
750 sizeof (size)))
758 goto resend; /* Increased buffer size, retry sending */ 751 goto resend; /* Increased buffer size, retry sending */
759 else 752 else
760 { 753 {
@@ -778,9 +771,9 @@ resend:
778 LOG (GNUNET_ERROR_TYPE_DEBUG, 771 LOG (GNUNET_ERROR_TYPE_DEBUG,
779 "UNIX transmitted %u-byte message to %s (%d: %s)\n", 772 "UNIX transmitted %u-byte message to %s (%d: %s)\n",
780 (unsigned int) msgbuf_size, 773 (unsigned int) msgbuf_size,
781 GNUNET_a2s ((const struct sockaddr *)un, un_len), 774 GNUNET_a2s ((const struct sockaddr *) un, un_len),
782 (int) sent, 775 (int) sent,
783 (sent < 0) ? STRERROR (errno) : "ok"); 776 (sent < 0) ? strerror (errno) : "ok");
784 GNUNET_free (un); 777 GNUNET_free (un);
785 return sent; 778 return sent;
786} 779}
@@ -794,8 +787,7 @@ resend:
794 * @return the network type in HBO or #GNUNET_SYSERR 787 * @return the network type in HBO or #GNUNET_SYSERR
795 */ 788 */
796static enum GNUNET_NetworkType 789static enum GNUNET_NetworkType
797unix_plugin_get_network (void *cls, 790unix_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session)
798 struct GNUNET_ATS_Session *session)
799{ 791{
800 GNUNET_assert (NULL != session); 792 GNUNET_assert (NULL != session);
801 return GNUNET_NT_LOOPBACK; 793 return GNUNET_NT_LOOPBACK;
@@ -827,19 +819,18 @@ unix_plugin_get_network_for_address (void *cls,
827 * @return the session or NULL of max connections exceeded 819 * @return the session or NULL of max connections exceeded
828 */ 820 */
829static struct GNUNET_ATS_Session * 821static struct GNUNET_ATS_Session *
830unix_plugin_get_session (void *cls, 822unix_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address)
831 const struct GNUNET_HELLO_Address *address)
832{ 823{
833 struct Plugin *plugin = cls; 824 struct Plugin *plugin = cls;
834 struct GNUNET_ATS_Session *session; 825 struct GNUNET_ATS_Session *session;
835 struct UnixAddress *ua; 826 struct UnixAddress *ua;
836 char * addrstr; 827 char *addrstr;
837 uint32_t addr_str_len; 828 uint32_t addr_str_len;
838 uint32_t addr_option; 829 uint32_t addr_option;
839 830
840 ua = (struct UnixAddress *) address->address; 831 ua = (struct UnixAddress *) address->address;
841 if ((NULL == address->address) || (0 == address->address_length) || 832 if ((NULL == address->address) || (0 == address->address_length) ||
842 (sizeof (struct UnixAddress) > address->address_length)) 833 (sizeof (struct UnixAddress) > address->address_length))
843 { 834 {
844 GNUNET_break (0); 835 GNUNET_break (0);
845 return NULL; 836 return NULL;
@@ -848,8 +839,8 @@ unix_plugin_get_session (void *cls,
848 addr_str_len = ntohl (ua->addrlen); 839 addr_str_len = ntohl (ua->addrlen);
849 addr_option = ntohl (ua->options); 840 addr_option = ntohl (ua->options);
850 841
851 if ( (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & addr_option)) && 842 if ((0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & addr_option)) &&
852 (GNUNET_NO == plugin->is_abstract)) 843 (GNUNET_NO == plugin->is_abstract))
853 { 844 {
854 return NULL; 845 return NULL;
855 } 846 }
@@ -871,13 +862,12 @@ unix_plugin_get_session (void *cls,
871 } 862 }
872 863
873 /* Check if a session for this address already exists */ 864 /* Check if a session for this address already exists */
874 if (NULL != (session = lookup_session (plugin, 865 if (NULL != (session = lookup_session (plugin, address)))
875 address))) 866 {
876 {
877 LOG (GNUNET_ERROR_TYPE_DEBUG, 867 LOG (GNUNET_ERROR_TYPE_DEBUG,
878 "Found existing session %p for address `%s'\n", 868 "Found existing session %p for address `%s'\n",
879 session, 869 session,
880 unix_plugin_address_to_string (NULL, 870 unix_plugin_address_to_string (NULL,
881 address->address, 871 address->address,
882 address->address_length)); 872 address->address_length));
883 return session; 873 return session;
@@ -888,29 +878,30 @@ unix_plugin_get_session (void *cls,
888 session->target = address->peer; 878 session->target = address->peer;
889 session->address = GNUNET_HELLO_address_copy (address); 879 session->address = GNUNET_HELLO_address_copy (address);
890 session->plugin = plugin; 880 session->plugin = plugin;
891 session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 881 session->timeout =
892 session->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 882 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
893 &session_timeout, 883 session->timeout_task =
894 session); 884 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
885 &session_timeout,
886 session);
895 LOG (GNUNET_ERROR_TYPE_DEBUG, 887 LOG (GNUNET_ERROR_TYPE_DEBUG,
896 "Creating a new session %p for address `%s'\n", 888 "Creating a new session %p for address `%s'\n",
897 session, 889 session,
898 unix_plugin_address_to_string (NULL, 890 unix_plugin_address_to_string (NULL,
899 address->address, 891 address->address,
900 address->address_length)); 892 address->address_length));
901 (void) GNUNET_CONTAINER_multipeermap_put (plugin->session_map, 893 (void) GNUNET_CONTAINER_multipeermap_put (
902 &address->peer, session, 894 plugin->session_map,
903 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 895 &address->peer,
896 session,
897 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
904 GNUNET_STATISTICS_set (plugin->env->stats, 898 GNUNET_STATISTICS_set (plugin->env->stats,
905 "# UNIX sessions active", 899 "# UNIX sessions active",
906 GNUNET_CONTAINER_multipeermap_size (plugin->session_map), 900 GNUNET_CONTAINER_multipeermap_size (
907 GNUNET_NO); 901 plugin->session_map),
908 notify_session_monitor (plugin, 902 GNUNET_NO);
909 session, 903 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT);
910 GNUNET_TRANSPORT_SS_INIT); 904 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP);
911 notify_session_monitor (plugin,
912 session,
913 GNUNET_TRANSPORT_SS_UP);
914 return session; 905 return session;
915} 906}
916 907
@@ -967,15 +958,17 @@ unix_demultiplexer (struct Plugin *plugin,
967 "Received message from %s\n", 958 "Received message from %s\n",
968 unix_plugin_address_to_string (NULL, ua, ua_len)); 959 unix_plugin_address_to_string (NULL, ua, ua_len));
969 GNUNET_STATISTICS_update (plugin->env->stats, 960 GNUNET_STATISTICS_update (plugin->env->stats,
970 "# bytes received via UNIX", 961 "# bytes received via UNIX",
971 ntohs (currhdr->size), 962 ntohs (currhdr->size),
972 GNUNET_NO); 963 GNUNET_NO);
973 964
974 /* Look for existing session */ 965 /* Look for existing session */
975 address = GNUNET_HELLO_address_allocate (sender, 966 address = GNUNET_HELLO_address_allocate (
976 PLUGIN_NAME, 967 sender,
977 ua, ua_len, 968 PLUGIN_NAME,
978 GNUNET_HELLO_ADDRESS_INFO_NONE); /* UNIX does not have "inbound" sessions */ 969 ua,
970 ua_len,
971 GNUNET_HELLO_ADDRESS_INFO_NONE); /* UNIX does not have "inbound" sessions */
979 session = lookup_session (plugin, address); 972 session = lookup_session (plugin, address);
980 if (NULL == session) 973 if (NULL == session)
981 { 974 {
@@ -991,10 +984,7 @@ unix_demultiplexer (struct Plugin *plugin,
991 reschedule_session_timeout (session); 984 reschedule_session_timeout (session);
992 } 985 }
993 GNUNET_HELLO_address_free (address); 986 GNUNET_HELLO_address_free (address);
994 plugin->env->receive (plugin->env->cls, 987 plugin->env->receive (plugin->env->cls, session->address, session, currhdr);
995 session->address,
996 session,
997 currhdr);
998} 988}
999 989
1000 990
@@ -1024,23 +1014,23 @@ unix_plugin_do_read (struct Plugin *plugin)
1024 addrlen = sizeof (un); 1014 addrlen = sizeof (un);
1025 memset (&un, 0, sizeof (un)); 1015 memset (&un, 0, sizeof (un));
1026 ret = GNUNET_NETWORK_socket_recvfrom (plugin->unix_sock.desc, 1016 ret = GNUNET_NETWORK_socket_recvfrom (plugin->unix_sock.desc,
1027 buf, sizeof (buf), 1017 buf,
1018 sizeof (buf),
1028 (struct sockaddr *) &un, 1019 (struct sockaddr *) &un,
1029 &addrlen); 1020 &addrlen);
1030 if ((GNUNET_SYSERR == ret) && ((errno == EAGAIN) || (errno == ENOBUFS))) 1021 if ((GNUNET_SYSERR == ret) && ((errno == EAGAIN) || (errno == ENOBUFS)))
1031 return; 1022 return;
1032 if (GNUNET_SYSERR == ret) 1023 if (GNUNET_SYSERR == ret)
1033 { 1024 {
1034 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 1025 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom");
1035 "recvfrom");
1036 return; 1026 return;
1037 } 1027 }
1038 else 1028 else
1039 { 1029 {
1040 LOG (GNUNET_ERROR_TYPE_DEBUG, 1030 LOG (GNUNET_ERROR_TYPE_DEBUG,
1041 "Read %d bytes from socket %s\n", 1031 "Read %d bytes from socket %s\n",
1042 (int) ret, 1032 (int) ret,
1043 un.sun_path); 1033 un.sun_path);
1044 } 1034 }
1045 1035
1046 GNUNET_assert (AF_UNIX == (un.sun_family)); 1036 GNUNET_assert (AF_UNIX == (un.sun_family));
@@ -1053,12 +1043,12 @@ unix_plugin_do_read (struct Plugin *plugin)
1053 1043
1054 ua_len = sizeof (struct UnixAddress) + strlen (un.sun_path) + 1; 1044 ua_len = sizeof (struct UnixAddress) + strlen (un.sun_path) + 1;
1055 ua = GNUNET_malloc (ua_len); 1045 ua = GNUNET_malloc (ua_len);
1056 ua->addrlen = htonl (strlen (&un.sun_path[0]) +1); 1046 ua->addrlen = htonl (strlen (&un.sun_path[0]) + 1);
1057 GNUNET_memcpy (&ua[1], &un.sun_path[0], strlen (un.sun_path) + 1); 1047 GNUNET_memcpy (&ua[1], &un.sun_path[0], strlen (un.sun_path) + 1);
1058 if (is_abstract) 1048 if (is_abstract)
1059 ua->options = htonl(UNIX_OPTIONS_USE_ABSTRACT_SOCKETS); 1049 ua->options = htonl (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS);
1060 else 1050 else
1061 ua->options = htonl(UNIX_OPTIONS_NONE); 1051 ua->options = htonl (UNIX_OPTIONS_NONE);
1062 1052
1063 msg = (struct UNIXMessage *) buf; 1053 msg = (struct UNIXMessage *) buf;
1064 csize = ntohs (msg->header.size); 1054 csize = ntohs (msg->header.size);
@@ -1069,9 +1059,7 @@ unix_plugin_do_read (struct Plugin *plugin)
1069 return; 1059 return;
1070 } 1060 }
1071 msgbuf = (char *) &msg[1]; 1061 msgbuf = (char *) &msg[1];
1072 GNUNET_memcpy (&sender, 1062 GNUNET_memcpy (&sender, &msg->sender, sizeof (struct GNUNET_PeerIdentity));
1073 &msg->sender,
1074 sizeof (struct GNUNET_PeerIdentity));
1075 offset = 0; 1063 offset = 0;
1076 tsize = csize - sizeof (struct UNIXMessage); 1064 tsize = csize - sizeof (struct UNIXMessage);
1077 while (offset + sizeof (struct GNUNET_MessageHeader) <= tsize) 1065 while (offset + sizeof (struct GNUNET_MessageHeader) <= tsize)
@@ -1113,11 +1101,9 @@ unix_plugin_do_write (struct Plugin *plugin)
1113 /* Message has a timeout */ 1101 /* Message has a timeout */
1114 did_delete = GNUNET_YES; 1102 did_delete = GNUNET_YES;
1115 LOG (GNUNET_ERROR_TYPE_DEBUG, 1103 LOG (GNUNET_ERROR_TYPE_DEBUG,
1116 "Timeout for message with %u bytes \n", 1104 "Timeout for message with %u bytes \n",
1117 (unsigned int) msgw->msgsize); 1105 (unsigned int) msgw->msgsize);
1118 GNUNET_CONTAINER_DLL_remove (plugin->msg_head, 1106 GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw);
1119 plugin->msg_tail,
1120 msgw);
1121 session = msgw->session; 1107 session = msgw->session;
1122 session->msgs_in_queue--; 1108 session->msgs_in_queue--;
1123 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); 1109 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
@@ -1125,28 +1111,26 @@ unix_plugin_do_write (struct Plugin *plugin)
1125 GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize); 1111 GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize);
1126 plugin->bytes_in_queue -= msgw->msgsize; 1112 plugin->bytes_in_queue -= msgw->msgsize;
1127 GNUNET_STATISTICS_set (plugin->env->stats, 1113 GNUNET_STATISTICS_set (plugin->env->stats,
1128 "# bytes currently in UNIX buffers", 1114 "# bytes currently in UNIX buffers",
1129 plugin->bytes_in_queue, 1115 plugin->bytes_in_queue,
1130 GNUNET_NO); 1116 GNUNET_NO);
1131 GNUNET_STATISTICS_update (plugin->env->stats, 1117 GNUNET_STATISTICS_update (plugin->env->stats,
1132 "# UNIX bytes discarded", 1118 "# UNIX bytes discarded",
1133 msgw->msgsize, 1119 msgw->msgsize,
1134 GNUNET_NO); 1120 GNUNET_NO);
1135 if (NULL != msgw->cont) 1121 if (NULL != msgw->cont)
1136 msgw->cont (msgw->cont_cls, 1122 msgw->cont (msgw->cont_cls,
1137 &msgw->session->target, 1123 &msgw->session->target,
1138 GNUNET_SYSERR, 1124 GNUNET_SYSERR,
1139 msgw->payload, 1125 msgw->payload,
1140 0); 1126 0);
1141 GNUNET_free (msgw->msg); 1127 GNUNET_free (msgw->msg);
1142 GNUNET_free (msgw); 1128 GNUNET_free (msgw);
1143 } 1129 }
1144 if (NULL == msgw) 1130 if (NULL == msgw)
1145 { 1131 {
1146 if (GNUNET_YES == did_delete) 1132 if (GNUNET_YES == did_delete)
1147 notify_session_monitor (plugin, 1133 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE);
1148 session,
1149 GNUNET_TRANSPORT_SS_UPDATE);
1150 return; /* Nothing to send at the moment */ 1134 return; /* Nothing to send at the moment */
1151 } 1135 }
1152 session = msgw->session; 1136 session = msgw->session;
@@ -1160,20 +1144,18 @@ unix_plugin_do_write (struct Plugin *plugin)
1160 msgw->session->address->address, 1144 msgw->session->address->address,
1161 msgw->session->address->address_length, 1145 msgw->session->address->address_length,
1162 msgw->payload, 1146 msgw->payload,
1163 msgw->cont, msgw->cont_cls); 1147 msgw->cont,
1148 msgw->cont_cls);
1164 if (RETRY == sent) 1149 if (RETRY == sent)
1165 { 1150 {
1166 GNUNET_STATISTICS_update (plugin->env->stats, 1151 GNUNET_STATISTICS_update (plugin->env->stats,
1167 "# UNIX retry attempts", 1152 "# UNIX retry attempts",
1168 1, GNUNET_NO); 1153 1,
1169 notify_session_monitor (plugin, 1154 GNUNET_NO);
1170 session, 1155 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE);
1171 GNUNET_TRANSPORT_SS_UPDATE);
1172 return; 1156 return;
1173 } 1157 }
1174 GNUNET_CONTAINER_DLL_remove (plugin->msg_head, 1158 GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw);
1175 plugin->msg_tail,
1176 msgw);
1177 session->msgs_in_queue--; 1159 session->msgs_in_queue--;
1178 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); 1160 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
1179 session->bytes_in_queue -= msgw->msgsize; 1161 session->bytes_in_queue -= msgw->msgsize;
@@ -1181,10 +1163,9 @@ unix_plugin_do_write (struct Plugin *plugin)
1181 plugin->bytes_in_queue -= msgw->msgsize; 1163 plugin->bytes_in_queue -= msgw->msgsize;
1182 GNUNET_STATISTICS_set (plugin->env->stats, 1164 GNUNET_STATISTICS_set (plugin->env->stats,
1183 "# bytes currently in UNIX buffers", 1165 "# bytes currently in UNIX buffers",
1184 plugin->bytes_in_queue, GNUNET_NO); 1166 plugin->bytes_in_queue,
1185 notify_session_monitor (plugin, 1167 GNUNET_NO);
1186 session, 1168 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE);
1187 GNUNET_TRANSPORT_SS_UPDATE);
1188 if (GNUNET_SYSERR == sent) 1169 if (GNUNET_SYSERR == sent)
1189 { 1170 {
1190 /* failed and no retry */ 1171 /* failed and no retry */
@@ -1192,11 +1173,12 @@ unix_plugin_do_write (struct Plugin *plugin)
1192 msgw->cont (msgw->cont_cls, 1173 msgw->cont (msgw->cont_cls,
1193 &msgw->session->target, 1174 &msgw->session->target,
1194 GNUNET_SYSERR, 1175 GNUNET_SYSERR,
1195 msgw->payload, 0); 1176 msgw->payload,
1177 0);
1196 GNUNET_STATISTICS_update (plugin->env->stats, 1178 GNUNET_STATISTICS_update (plugin->env->stats,
1197 "# UNIX bytes discarded", 1179 "# UNIX bytes discarded",
1198 msgw->msgsize, 1180 msgw->msgsize,
1199 GNUNET_NO); 1181 GNUNET_NO);
1200 GNUNET_free (msgw->msg); 1182 GNUNET_free (msgw->msg);
1201 GNUNET_free (msgw); 1183 GNUNET_free (msgw);
1202 return; 1184 return;
@@ -1204,15 +1186,15 @@ unix_plugin_do_write (struct Plugin *plugin)
1204 /* successfully sent bytes */ 1186 /* successfully sent bytes */
1205 GNUNET_break (sent > 0); 1187 GNUNET_break (sent > 0);
1206 GNUNET_STATISTICS_update (plugin->env->stats, 1188 GNUNET_STATISTICS_update (plugin->env->stats,
1207 "# bytes transmitted via UNIX", 1189 "# bytes transmitted via UNIX",
1208 msgw->msgsize, 1190 msgw->msgsize,
1209 GNUNET_NO); 1191 GNUNET_NO);
1210 if (NULL != msgw->cont) 1192 if (NULL != msgw->cont)
1211 msgw->cont (msgw->cont_cls, 1193 msgw->cont (msgw->cont_cls,
1212 &msgw->session->target, 1194 &msgw->session->target,
1213 GNUNET_OK, 1195 GNUNET_OK,
1214 msgw->payload, 1196 msgw->payload,
1215 msgw->msgsize); 1197 msgw->msgsize);
1216 GNUNET_free (msgw->msg); 1198 GNUNET_free (msgw->msg);
1217 GNUNET_free (msgw); 1199 GNUNET_free (msgw);
1218} 1200}
@@ -1237,7 +1219,8 @@ unix_plugin_select_read (void *cls)
1237 plugin->read_task = 1219 plugin->read_task =
1238 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 1220 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
1239 plugin->unix_sock.desc, 1221 plugin->unix_sock.desc,
1240 &unix_plugin_select_read, plugin); 1222 &unix_plugin_select_read,
1223 plugin);
1241} 1224}
1242 1225
1243 1226
@@ -1262,7 +1245,8 @@ unix_plugin_select_write (void *cls)
1262 plugin->write_task = 1245 plugin->write_task =
1263 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 1246 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
1264 plugin->unix_sock.desc, 1247 plugin->unix_sock.desc,
1265 &unix_plugin_select_write, plugin); 1248 &unix_plugin_select_write,
1249 plugin);
1266} 1250}
1267 1251
1268 1252
@@ -1310,13 +1294,13 @@ unix_plugin_send (void *cls,
1310 1294
1311 if (GNUNET_OK != 1295 if (GNUNET_OK !=
1312 GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map, 1296 GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map,
1313 &session->target, 1297 &session->target,
1314 session)) 1298 session))
1315 { 1299 {
1316 LOG (GNUNET_ERROR_TYPE_ERROR, 1300 LOG (GNUNET_ERROR_TYPE_ERROR,
1317 "Invalid session for peer `%s' `%s'\n", 1301 "Invalid session for peer `%s' `%s'\n",
1318 GNUNET_i2s (&session->target), 1302 GNUNET_i2s (&session->target),
1319 unix_plugin_address_to_string (NULL, 1303 unix_plugin_address_to_string (NULL,
1320 session->address->address, 1304 session->address->address,
1321 session->address->address_length)); 1305 session->address->address_length));
1322 GNUNET_break (0); 1306 GNUNET_break (0);
@@ -1333,16 +1317,16 @@ unix_plugin_send (void *cls,
1333 message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size); 1317 message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size);
1334 message->header.size = htons (ssize); 1318 message->header.size = htons (ssize);
1335 message->header.type = htons (0); 1319 message->header.type = htons (0);
1336 GNUNET_memcpy (&message->sender, plugin->env->my_identity, 1320 GNUNET_memcpy (&message->sender,
1337 sizeof (struct GNUNET_PeerIdentity)); 1321 plugin->env->my_identity,
1322 sizeof (struct GNUNET_PeerIdentity));
1338 GNUNET_memcpy (&message[1], msgbuf, msgbuf_size); 1323 GNUNET_memcpy (&message[1], msgbuf, msgbuf_size);
1339 wrapper = GNUNET_new (struct UNIXMessageWrapper); 1324 wrapper = GNUNET_new (struct UNIXMessageWrapper);
1340 wrapper->msg = message; 1325 wrapper->msg = message;
1341 wrapper->msgsize = ssize; 1326 wrapper->msgsize = ssize;
1342 wrapper->payload = msgbuf_size; 1327 wrapper->payload = msgbuf_size;
1343 wrapper->priority = priority; 1328 wrapper->priority = priority;
1344 wrapper->timeout = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), 1329 wrapper->timeout = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), to);
1345 to);
1346 wrapper->cont = cont; 1330 wrapper->cont = cont;
1347 wrapper->cont_cls = cont_cls; 1331 wrapper->cont_cls = cont_cls;
1348 wrapper->session = session; 1332 wrapper->session = session;
@@ -1353,17 +1337,16 @@ unix_plugin_send (void *cls,
1353 session->bytes_in_queue += ssize; 1337 session->bytes_in_queue += ssize;
1354 session->msgs_in_queue++; 1338 session->msgs_in_queue++;
1355 GNUNET_STATISTICS_set (plugin->env->stats, 1339 GNUNET_STATISTICS_set (plugin->env->stats,
1356 "# bytes currently in UNIX buffers", 1340 "# bytes currently in UNIX buffers",
1357 plugin->bytes_in_queue, 1341 plugin->bytes_in_queue,
1358 GNUNET_NO); 1342 GNUNET_NO);
1359 notify_session_monitor (plugin, 1343 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE);
1360 session,
1361 GNUNET_TRANSPORT_SS_UPDATE);
1362 if (NULL == plugin->write_task) 1344 if (NULL == plugin->write_task)
1363 plugin->write_task = 1345 plugin->write_task =
1364 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 1346 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
1365 plugin->unix_sock.desc, 1347 plugin->unix_sock.desc,
1366 &unix_plugin_select_write, plugin); 1348 &unix_plugin_select_write,
1349 plugin);
1367 return ssize; 1350 return ssize;
1368} 1351}
1369 1352
@@ -1381,15 +1364,14 @@ unix_transport_server_start (void *cls)
1381 struct sockaddr_un *un; 1364 struct sockaddr_un *un;
1382 socklen_t un_len; 1365 socklen_t un_len;
1383 1366
1384 un = unix_address_to_sockaddr (plugin->unix_socket_path, 1367 un = unix_address_to_sockaddr (plugin->unix_socket_path, &un_len);
1385 &un_len);
1386 if (GNUNET_YES == plugin->is_abstract) 1368 if (GNUNET_YES == plugin->is_abstract)
1387 { 1369 {
1388 plugin->unix_socket_path[0] = '@'; 1370 plugin->unix_socket_path[0] = '@';
1389 un->sun_path[0] = '\0'; 1371 un->sun_path[0] = '\0';
1390 } 1372 }
1391 plugin->unix_sock.desc = 1373 plugin->unix_sock.desc =
1392 GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0); 1374 GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0);
1393 if (NULL == plugin->unix_sock.desc) 1375 if (NULL == plugin->unix_sock.desc)
1394 { 1376 {
1395 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); 1377 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
@@ -1400,33 +1382,32 @@ unix_transport_server_start (void *cls)
1400 { 1382 {
1401 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (un->sun_path)) 1383 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (un->sun_path))
1402 { 1384 {
1403 LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot create path to `%s'\n"), 1385 LOG (GNUNET_ERROR_TYPE_ERROR,
1404 un->sun_path); 1386 _ ("Cannot create path to `%s'\n"),
1387 un->sun_path);
1405 GNUNET_NETWORK_socket_close (plugin->unix_sock.desc); 1388 GNUNET_NETWORK_socket_close (plugin->unix_sock.desc);
1406 plugin->unix_sock.desc = NULL; 1389 plugin->unix_sock.desc = NULL;
1407 GNUNET_free (un); 1390 GNUNET_free (un);
1408 return GNUNET_SYSERR; 1391 return GNUNET_SYSERR;
1409 } 1392 }
1410 } 1393 }
1411 if (GNUNET_OK != 1394 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc,
1412 GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc, 1395 (const struct sockaddr *) un,
1413 (const struct sockaddr *) un, un_len)) 1396 un_len))
1414 { 1397 {
1415 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); 1398 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
1416 LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot bind to `%s'\n"), 1399 LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Cannot bind to `%s'\n"), un->sun_path);
1417 un->sun_path);
1418 GNUNET_NETWORK_socket_close (plugin->unix_sock.desc); 1400 GNUNET_NETWORK_socket_close (plugin->unix_sock.desc);
1419 plugin->unix_sock.desc = NULL; 1401 plugin->unix_sock.desc = NULL;
1420 GNUNET_free (un); 1402 GNUNET_free (un);
1421 return GNUNET_SYSERR; 1403 return GNUNET_SYSERR;
1422 } 1404 }
1423 LOG (GNUNET_ERROR_TYPE_DEBUG, 1405 LOG (GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", plugin->unix_socket_path);
1424 "Bound to `%s'\n",
1425 plugin->unix_socket_path);
1426 plugin->read_task = 1406 plugin->read_task =
1427 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 1407 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
1428 plugin->unix_sock.desc, 1408 plugin->unix_sock.desc,
1429 &unix_plugin_select_read, plugin); 1409 &unix_plugin_select_read,
1410 plugin);
1430 GNUNET_free (un); 1411 GNUNET_free (un);
1431 return 1; 1412 return 1;
1432} 1413}
@@ -1449,18 +1430,15 @@ unix_transport_server_start (void *cls)
1449 * 1430 *
1450 */ 1431 */
1451static int 1432static int
1452unix_plugin_check_address (void *cls, 1433unix_plugin_check_address (void *cls, const void *addr, size_t addrlen)
1453 const void *addr,
1454 size_t addrlen)
1455{ 1434{
1456 struct Plugin* plugin = cls; 1435 struct Plugin *plugin = cls;
1457 const struct UnixAddress *ua = addr; 1436 const struct UnixAddress *ua = addr;
1458 char *addrstr; 1437 char *addrstr;
1459 size_t addr_str_len; 1438 size_t addr_str_len;
1460 1439
1461 if ( (NULL == addr) || 1440 if ((NULL == addr) || (0 == addrlen) ||
1462 (0 == addrlen) || 1441 (sizeof (struct UnixAddress) > addrlen))
1463 (sizeof (struct UnixAddress) > addrlen) )
1464 { 1442 {
1465 GNUNET_break (0); 1443 GNUNET_break (0);
1466 return GNUNET_SYSERR; 1444 return GNUNET_SYSERR;
@@ -1479,7 +1457,7 @@ unix_plugin_check_address (void *cls,
1479 } 1457 }
1480 1458
1481 if (0 == strcmp (plugin->unix_socket_path, addrstr)) 1459 if (0 == strcmp (plugin->unix_socket_path, addrstr))
1482 return GNUNET_OK; 1460 return GNUNET_OK;
1483 return GNUNET_SYSERR; 1461 return GNUNET_SYSERR;
1484} 1462}
1485 1463
@@ -1499,7 +1477,8 @@ unix_plugin_check_address (void *cls,
1499 * @param asc_cls closure for @a asc 1477 * @param asc_cls closure for @a asc
1500 */ 1478 */
1501static void 1479static void
1502unix_plugin_address_pretty_printer (void *cls, const char *type, 1480unix_plugin_address_pretty_printer (void *cls,
1481 const char *type,
1503 const void *addr, 1482 const void *addr,
1504 size_t addrlen, 1483 size_t addrlen,
1505 int numeric, 1484 int numeric,
@@ -1509,15 +1488,11 @@ unix_plugin_address_pretty_printer (void *cls, const char *type,
1509{ 1488{
1510 const char *ret; 1489 const char *ret;
1511 1490
1512 if ( (NULL != addr) && (addrlen > 0)) 1491 if ((NULL != addr) && (addrlen > 0))
1513 ret = unix_plugin_address_to_string (NULL, 1492 ret = unix_plugin_address_to_string (NULL, addr, addrlen);
1514 addr,
1515 addrlen);
1516 else 1493 else
1517 ret = NULL; 1494 ret = NULL;
1518 asc (asc_cls, 1495 asc (asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
1519 ret,
1520 (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
1521 asc (asc_cls, NULL, GNUNET_OK); 1496 asc (asc_cls, NULL, GNUNET_OK);
1522} 1497}
1523 1498
@@ -1538,7 +1513,8 @@ static int
1538unix_plugin_string_to_address (void *cls, 1513unix_plugin_string_to_address (void *cls,
1539 const char *addr, 1514 const char *addr,
1540 uint16_t addrlen, 1515 uint16_t addrlen,
1541 void **buf, size_t *added) 1516 void **buf,
1517 size_t *added)
1542{ 1518{
1543 struct UnixAddress *ua; 1519 struct UnixAddress *ua;
1544 char *address; 1520 char *address;
@@ -1587,7 +1563,7 @@ unix_plugin_string_to_address (void *cls,
1587 } 1563 }
1588 address[0] = '\0'; 1564 address[0] = '\0';
1589 address++; 1565 address++;
1590 if (0 != strcmp(plugin, PLUGIN_NAME)) 1566 if (0 != strcmp (plugin, PLUGIN_NAME))
1591 { 1567 {
1592 GNUNET_break (0); 1568 GNUNET_break (0);
1593 GNUNET_free (plugin); 1569 GNUNET_free (plugin);
@@ -1624,9 +1600,11 @@ address_notification (void *cls)
1624 len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1; 1600 len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1;
1625 ua = GNUNET_malloc (len); 1601 ua = GNUNET_malloc (len);
1626 ua->options = htonl (plugin->myoptions); 1602 ua->options = htonl (plugin->myoptions);
1627 ua->addrlen = htonl(strlen (plugin->unix_socket_path) + 1); 1603 ua->addrlen = htonl (strlen (plugin->unix_socket_path) + 1);
1628 unix_path = (char *) &ua[1]; 1604 unix_path = (char *) &ua[1];
1629 GNUNET_memcpy (unix_path, plugin->unix_socket_path, strlen (plugin->unix_socket_path) + 1); 1605 GNUNET_memcpy (unix_path,
1606 plugin->unix_socket_path,
1607 strlen (plugin->unix_socket_path) + 1);
1630 1608
1631 plugin->address_update_task = NULL; 1609 plugin->address_update_task = NULL;
1632 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, 1610 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
@@ -1634,9 +1612,7 @@ address_notification (void *cls)
1634 ua, 1612 ua,
1635 len, 1613 len,
1636 GNUNET_HELLO_ADDRESS_INFO_NONE); 1614 GNUNET_HELLO_ADDRESS_INFO_NONE);
1637 plugin->env->notify_address (plugin->env->cls, 1615 plugin->env->notify_address (plugin->env->cls, GNUNET_YES, address);
1638 GNUNET_YES,
1639 address);
1640 GNUNET_free (ua); 1616 GNUNET_free (ua);
1641 GNUNET_free (address); 1617 GNUNET_free (address);
1642} 1618}
@@ -1652,8 +1628,8 @@ address_notification (void *cls)
1652 */ 1628 */
1653static int 1629static int
1654get_session_delete_it (void *cls, 1630get_session_delete_it (void *cls,
1655 const struct GNUNET_PeerIdentity *key, 1631 const struct GNUNET_PeerIdentity *key,
1656 void *value) 1632 void *value)
1657{ 1633{
1658 struct Plugin *plugin = cls; 1634 struct Plugin *plugin = cls;
1659 struct GNUNET_ATS_Session *session = value; 1635 struct GNUNET_ATS_Session *session = value;
@@ -1677,8 +1653,9 @@ unix_plugin_peer_disconnect (void *cls,
1677 struct Plugin *plugin = cls; 1653 struct Plugin *plugin = cls;
1678 1654
1679 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, 1655 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map,
1680 target, 1656 target,
1681 &get_session_delete_it, plugin); 1657 &get_session_delete_it,
1658 plugin);
1682} 1659}
1683 1660
1684 1661
@@ -1699,12 +1676,8 @@ send_session_info_iter (void *cls,
1699 struct Plugin *plugin = cls; 1676 struct Plugin *plugin = cls;
1700 struct GNUNET_ATS_Session *session = value; 1677 struct GNUNET_ATS_Session *session = value;
1701 1678
1702 notify_session_monitor (plugin, 1679 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT);
1703 session, 1680 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP);
1704 GNUNET_TRANSPORT_SS_INIT);
1705 notify_session_monitor (plugin,
1706 session,
1707 GNUNET_TRANSPORT_SS_UP);
1708 return GNUNET_OK; 1681 return GNUNET_OK;
1709} 1682}
1710 1683
@@ -1786,9 +1759,10 @@ libgnunet_plugin_transport_unix_init (void *cls)
1786 1759
1787 /* Initialize my flags */ 1760 /* Initialize my flags */
1788#ifdef LINUX 1761#ifdef LINUX
1789 plugin->is_abstract = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, 1762 plugin->is_abstract =
1790 "testing", 1763 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg,
1791 "USE_ABSTRACT_SOCKETS"); 1764 "testing",
1765 "USE_ABSTRACT_SOCKETS");
1792#endif 1766#endif
1793 plugin->myoptions = UNIX_OPTIONS_NONE; 1767 plugin->myoptions = UNIX_OPTIONS_NONE;
1794 if (GNUNET_YES == plugin->is_abstract) 1768 if (GNUNET_YES == plugin->is_abstract)
@@ -1812,16 +1786,15 @@ libgnunet_plugin_transport_unix_init (void *cls)
1812 sockets_created = unix_transport_server_start (plugin); 1786 sockets_created = unix_transport_server_start (plugin);
1813 if ((0 == sockets_created) || (GNUNET_SYSERR == sockets_created)) 1787 if ((0 == sockets_created) || (GNUNET_SYSERR == sockets_created))
1814 { 1788 {
1815 LOG (GNUNET_ERROR_TYPE_WARNING, 1789 LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Failed to open UNIX listen socket\n"));
1816 _("Failed to open UNIX listen socket\n"));
1817 GNUNET_free (api); 1790 GNUNET_free (api);
1818 GNUNET_free (plugin->unix_socket_path); 1791 GNUNET_free (plugin->unix_socket_path);
1819 GNUNET_free (plugin); 1792 GNUNET_free (plugin);
1820 return NULL; 1793 return NULL;
1821 } 1794 }
1822 plugin->session_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); 1795 plugin->session_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1823 plugin->address_update_task = GNUNET_SCHEDULER_add_now (&address_notification, 1796 plugin->address_update_task =
1824 plugin); 1797 GNUNET_SCHEDULER_add_now (&address_notification, plugin);
1825 return api; 1798 return api;
1826} 1799}
1827 1800
@@ -1838,7 +1811,7 @@ libgnunet_plugin_transport_unix_done (void *cls)
1838 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 1811 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
1839 struct Plugin *plugin = api->cls; 1812 struct Plugin *plugin = api->cls;
1840 struct GNUNET_HELLO_Address *address; 1813 struct GNUNET_HELLO_Address *address;
1841 struct UNIXMessageWrapper * msgw; 1814 struct UNIXMessageWrapper *msgw;
1842 struct UnixAddress *ua; 1815 struct UnixAddress *ua;
1843 size_t len; 1816 size_t len;
1844 struct GNUNET_ATS_Session *session; 1817 struct GNUNET_ATS_Session *session;
@@ -1851,26 +1824,23 @@ libgnunet_plugin_transport_unix_done (void *cls)
1851 len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1; 1824 len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1;
1852 ua = GNUNET_malloc (len); 1825 ua = GNUNET_malloc (len);
1853 ua->options = htonl (plugin->myoptions); 1826 ua->options = htonl (plugin->myoptions);
1854 ua->addrlen = htonl(strlen (plugin->unix_socket_path) + 1); 1827 ua->addrlen = htonl (strlen (plugin->unix_socket_path) + 1);
1855 GNUNET_memcpy (&ua[1], 1828 GNUNET_memcpy (&ua[1],
1856 plugin->unix_socket_path, 1829 plugin->unix_socket_path,
1857 strlen (plugin->unix_socket_path) + 1); 1830 strlen (plugin->unix_socket_path) + 1);
1858 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, 1831 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
1859 PLUGIN_NAME, 1832 PLUGIN_NAME,
1860 ua, len, 1833 ua,
1834 len,
1861 GNUNET_HELLO_ADDRESS_INFO_NONE); 1835 GNUNET_HELLO_ADDRESS_INFO_NONE);
1862 plugin->env->notify_address (plugin->env->cls, 1836 plugin->env->notify_address (plugin->env->cls, GNUNET_NO, address);
1863 GNUNET_NO,
1864 address);
1865 1837
1866 GNUNET_free (address); 1838 GNUNET_free (address);
1867 GNUNET_free (ua); 1839 GNUNET_free (ua);
1868 1840
1869 while (NULL != (msgw = plugin->msg_head)) 1841 while (NULL != (msgw = plugin->msg_head))
1870 { 1842 {
1871 GNUNET_CONTAINER_DLL_remove (plugin->msg_head, 1843 GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw);
1872 plugin->msg_tail,
1873 msgw);
1874 session = msgw->session; 1844 session = msgw->session;
1875 session->msgs_in_queue--; 1845 session->msgs_in_queue--;
1876 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); 1846 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
@@ -1881,7 +1851,8 @@ libgnunet_plugin_transport_unix_done (void *cls)
1881 msgw->cont (msgw->cont_cls, 1851 msgw->cont (msgw->cont_cls,
1882 &msgw->session->target, 1852 &msgw->session->target,
1883 GNUNET_SYSERR, 1853 GNUNET_SYSERR,
1884 msgw->payload, 0); 1854 msgw->payload,
1855 0);
1885 GNUNET_free (msgw->msg); 1856 GNUNET_free (msgw->msg);
1886 GNUNET_free (msgw); 1857 GNUNET_free (msgw);
1887 } 1858 }
@@ -1908,7 +1879,7 @@ libgnunet_plugin_transport_unix_done (void *cls)
1908 plugin->unix_sock.desc = NULL; 1879 plugin->unix_sock.desc = NULL;
1909 } 1880 }
1910 GNUNET_CONTAINER_multipeermap_iterate (plugin->session_map, 1881 GNUNET_CONTAINER_multipeermap_iterate (plugin->session_map,
1911 &get_session_delete_it, 1882 &get_session_delete_it,
1912 plugin); 1883 plugin);
1913 GNUNET_CONTAINER_multipeermap_destroy (plugin->session_map); 1884 GNUNET_CONTAINER_multipeermap_destroy (plugin->session_map);
1914 GNUNET_break (0 == plugin->bytes_in_queue); 1885 GNUNET_break (0 == plugin->bytes_in_queue);
diff --git a/src/transport/tcp_connection_legacy.c b/src/transport/tcp_connection_legacy.c
index cfb088361..999e8827a 100644
--- a/src/transport/tcp_connection_legacy.c
+++ b/src/transport/tcp_connection_legacy.c
@@ -41,11 +41,12 @@
41 * is this value divided by the number of address families. 41 * is this value divided by the number of address families.
42 * Default is 5s. 42 * Default is 5s.
43 */ 43 */
44#define CONNECT_RETRY_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) 44#define CONNECT_RETRY_TIMEOUT \
45 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
45 46
46 47
47 48#define LOG_STRERROR(kind, syscall) \
48#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-connection", syscall) 49 GNUNET_log_from_strerror (kind, "util-connection", syscall)
49 50
50 51
51/** 52/**
@@ -78,14 +79,13 @@ struct GNUNET_CONNECTION_TransmitHandle
78 /** 79 /**
79 * Task called on timeout. 80 * Task called on timeout.
80 */ 81 */
81 struct GNUNET_SCHEDULER_Task * timeout_task; 82 struct GNUNET_SCHEDULER_Task *timeout_task;
82 83
83 /** 84 /**
84 * At what number of bytes available in the 85 * At what number of bytes available in the
85 * write buffer should the notify method be called? 86 * write buffer should the notify method be called?
86 */ 87 */
87 size_t notify_size; 88 size_t notify_size;
88
89}; 89};
90 90
91 91
@@ -129,7 +129,7 @@ struct AddressProbe
129 /** 129 /**
130 * Task waiting for the connection to finish connecting. 130 * Task waiting for the connection to finish connecting.
131 */ 131 */
132 struct GNUNET_SCHEDULER_Task * task; 132 struct GNUNET_SCHEDULER_Task *task;
133}; 133};
134 134
135 135
@@ -263,7 +263,6 @@ struct GNUNET_CONNECTION_Handle
263 * Handle to subsequent connection after proxy handshake completes, 263 * Handle to subsequent connection after proxy handshake completes,
264 */ 264 */
265 struct GNUNET_CONNECTION_Handle *proxy_handshake; 265 struct GNUNET_CONNECTION_Handle *proxy_handshake;
266
267}; 266};
268 267
269 268
@@ -357,9 +356,7 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb,
357 356
358 addrlen = sizeof (addr); 357 addrlen = sizeof (addr);
359 sock = 358 sock =
360 GNUNET_NETWORK_socket_accept (lsock, 359 GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen);
361 (struct sockaddr *) &addr,
362 &addrlen);
363 if (NULL == sock) 360 if (NULL == sock)
364 { 361 {
365 if (EAGAIN != errno) 362 if (EAGAIN != errno)
@@ -375,8 +372,7 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb,
375 372
376 sa = (struct sockaddr *) addr; 373 sa = (struct sockaddr *) addr;
377 v6 = (struct sockaddr_in6 *) addr; 374 v6 = (struct sockaddr_in6 *) addr;
378 if ( (AF_INET6 == sa->sa_family) && 375 if ((AF_INET6 == sa->sa_family) && (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr)))
379 (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr)) )
380 { 376 {
381 /* convert to V4 address */ 377 /* convert to V4 address */
382 v4 = GNUNET_new (struct sockaddr_in); 378 v4 = GNUNET_new (struct sockaddr_in);
@@ -386,9 +382,9 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb,
386 v4->sin_len = (u_char) sizeof (struct sockaddr_in); 382 v4->sin_len = (u_char) sizeof (struct sockaddr_in);
387#endif 383#endif
388 GNUNET_memcpy (&v4->sin_addr, 384 GNUNET_memcpy (&v4->sin_addr,
389 &((char *) &v6->sin6_addr)[sizeof (struct in6_addr) - 385 &((char *) &v6->sin6_addr)[sizeof (struct in6_addr) -
390 sizeof (struct in_addr)], 386 sizeof (struct in_addr)],
391 sizeof (struct in_addr)); 387 sizeof (struct in_addr));
392 v4->sin_port = v6->sin6_port; 388 v4->sin_port = v6->sin6_port;
393 uaddr = v4; 389 uaddr = v4;
394 addrlen = sizeof (struct sockaddr_in); 390 addrlen = sizeof (struct sockaddr_in);
@@ -403,21 +399,18 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb,
403 { 399 {
404#if HAVE_GETPEEREID 400#if HAVE_GETPEEREID
405 /* most BSDs */ 401 /* most BSDs */
406 if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), 402 if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), &gc.uid, &gc.gid))
407 &gc.uid,
408 &gc.gid))
409 gcp = &gc; 403 gcp = &gc;
410#else 404#else
411#ifdef SO_PEERCRED 405#ifdef SO_PEERCRED
412 /* largely traditional GNU/Linux */ 406 /* largely traditional GNU/Linux */
413 olen = sizeof (uc); 407 olen = sizeof (uc);
414 if ( (0 == 408 if ((0 == getsockopt (GNUNET_NETWORK_get_fd (sock),
415 getsockopt (GNUNET_NETWORK_get_fd (sock), 409 SOL_SOCKET,
416 SOL_SOCKET, 410 SO_PEERCRED,
417 SO_PEERCRED, 411 &uc,
418 &uc, 412 &olen)) &&
419 &olen)) && 413 (olen == sizeof (uc)))
420 (olen == sizeof (uc)) )
421 { 414 {
422 gc.uid = uc.uid; 415 gc.uid = uc.uid;
423 gc.gid = uc.gid; 416 gc.gid = uc.gid;
@@ -441,20 +434,15 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb,
441#endif 434#endif
442 } 435 }
443 436
444 if ( (NULL != access_cb) && 437 if ((NULL != access_cb) &&
445 (GNUNET_YES != (aret = access_cb (access_cb_cls, 438 (GNUNET_YES != (aret = access_cb (access_cb_cls, gcp, uaddr, addrlen))))
446 gcp,
447 uaddr,
448 addrlen))) )
449 { 439 {
450 if (GNUNET_NO == aret) 440 if (GNUNET_NO == aret)
451 LOG (GNUNET_ERROR_TYPE_INFO, 441 LOG (GNUNET_ERROR_TYPE_INFO,
452 _("Access denied to `%s'\n"), 442 _ ("Access denied to `%s'\n"),
453 GNUNET_a2s (uaddr, 443 GNUNET_a2s (uaddr, addrlen));
454 addrlen));
455 GNUNET_break (GNUNET_OK == 444 GNUNET_break (GNUNET_OK ==
456 GNUNET_NETWORK_socket_shutdown (sock, 445 GNUNET_NETWORK_socket_shutdown (sock, SHUT_RDWR));
457 SHUT_RDWR));
458 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); 446 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
459 GNUNET_free (uaddr); 447 GNUNET_free (uaddr);
460 return NULL; 448 return NULL;
@@ -466,9 +454,8 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb,
466 connection->addrlen = addrlen; 454 connection->addrlen = addrlen;
467 connection->sock = sock; 455 connection->sock = sock;
468 LOG (GNUNET_ERROR_TYPE_INFO, 456 LOG (GNUNET_ERROR_TYPE_INFO,
469 _("Accepting connection from `%s': %p\n"), 457 _ ("Accepting connection from `%s': %p\n"),
470 GNUNET_a2s (uaddr, 458 GNUNET_a2s (uaddr, addrlen),
471 addrlen),
472 connection); 459 connection);
473 return connection; 460 return connection;
474} 461}
@@ -503,14 +490,13 @@ GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *connection,
503 * @param errcode error code to send 490 * @param errcode error code to send
504 */ 491 */
505static void 492static void
506signal_receive_error (struct GNUNET_CONNECTION_Handle *connection, 493signal_receive_error (struct GNUNET_CONNECTION_Handle *connection, int errcode)
507 int errcode)
508{ 494{
509 GNUNET_CONNECTION_Receiver receiver; 495 GNUNET_CONNECTION_Receiver receiver;
510 496
511 LOG (GNUNET_ERROR_TYPE_DEBUG, 497 LOG (GNUNET_ERROR_TYPE_DEBUG,
512 "Receive encounters error (%s), connection closed (%p)\n", 498 "Receive encounters error (%s), connection closed (%p)\n",
513 STRERROR (errcode), 499 strerror (errcode),
514 connection); 500 connection);
515 GNUNET_assert (NULL != (receiver = connection->receiver)); 501 GNUNET_assert (NULL != (receiver = connection->receiver));
516 connection->receiver = NULL; 502 connection->receiver = NULL;
@@ -549,21 +535,18 @@ signal_receive_timeout (struct GNUNET_CONNECTION_Handle *connection)
549 * @param ecode error code (errno) 535 * @param ecode error code (errno)
550 */ 536 */
551static void 537static void
552signal_transmit_error (struct GNUNET_CONNECTION_Handle *connection, 538signal_transmit_error (struct GNUNET_CONNECTION_Handle *connection, int ecode)
553 int ecode)
554{ 539{
555 GNUNET_CONNECTION_TransmitReadyNotify notify; 540 GNUNET_CONNECTION_TransmitReadyNotify notify;
556 541
557 LOG (GNUNET_ERROR_TYPE_DEBUG, 542 LOG (GNUNET_ERROR_TYPE_DEBUG,
558 "Transmission encounterd error (%s), connection closed (%p)\n", 543 "Transmission encounterd error (%s), connection closed (%p)\n",
559 STRERROR (ecode), 544 strerror (ecode),
560 connection); 545 connection);
561 if (NULL != connection->sock) 546 if (NULL != connection->sock)
562 { 547 {
563 (void) GNUNET_NETWORK_socket_shutdown (connection->sock, 548 (void) GNUNET_NETWORK_socket_shutdown (connection->sock, SHUT_RDWR);
564 SHUT_RDWR); 549 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock));
565 GNUNET_break (GNUNET_OK ==
566 GNUNET_NETWORK_socket_close (connection->sock));
567 connection->sock = NULL; 550 connection->sock = NULL;
568 GNUNET_assert (NULL == connection->write_task); 551 GNUNET_assert (NULL == connection->write_task);
569 } 552 }
@@ -576,12 +559,10 @@ signal_transmit_error (struct GNUNET_CONNECTION_Handle *connection,
576 return; 559 return;
577 } 560 }
578 if (NULL == connection->nth.notify_ready) 561 if (NULL == connection->nth.notify_ready)
579 return; /* nobody to tell about it */ 562 return; /* nobody to tell about it */
580 notify = connection->nth.notify_ready; 563 notify = connection->nth.notify_ready;
581 connection->nth.notify_ready = NULL; 564 connection->nth.notify_ready = NULL;
582 notify (connection->nth.notify_ready_cls, 565 notify (connection->nth.notify_ready_cls, 0, NULL);
583 0,
584 NULL);
585} 566}
586 567
587 568
@@ -597,7 +578,7 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *connection)
597 LOG (GNUNET_ERROR_TYPE_INFO, 578 LOG (GNUNET_ERROR_TYPE_INFO,
598 "Failed to establish TCP connection to `%s:%u', no further addresses to try.\n", 579 "Failed to establish TCP connection to `%s:%u', no further addresses to try.\n",
599 connection->hostname, 580 connection->hostname,
600 connection->port); 581 connection->port);
601 GNUNET_break (NULL == connection->ap_head); 582 GNUNET_break (NULL == connection->ap_head);
602 GNUNET_break (NULL == connection->ap_tail); 583 GNUNET_break (NULL == connection->ap_tail);
603 GNUNET_break (GNUNET_NO == connection->dns_active); 584 GNUNET_break (GNUNET_NO == connection->dns_active);
@@ -608,15 +589,13 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *connection)
608 /* signal errors for jobs that used to wait on the connection */ 589 /* signal errors for jobs that used to wait on the connection */
609 connection->destroy_later = 1; 590 connection->destroy_later = 1;
610 if (NULL != connection->receiver) 591 if (NULL != connection->receiver)
611 signal_receive_error (connection, 592 signal_receive_error (connection, ECONNREFUSED);
612 ECONNREFUSED);
613 if (NULL != connection->nth.notify_ready) 593 if (NULL != connection->nth.notify_ready)
614 { 594 {
615 GNUNET_assert (NULL != connection->nth.timeout_task); 595 GNUNET_assert (NULL != connection->nth.timeout_task);
616 GNUNET_SCHEDULER_cancel (connection->nth.timeout_task); 596 GNUNET_SCHEDULER_cancel (connection->nth.timeout_task);
617 connection->nth.timeout_task = NULL; 597 connection->nth.timeout_task = NULL;
618 signal_transmit_error (connection, 598 signal_transmit_error (connection, ECONNREFUSED);
619 ECONNREFUSED);
620 } 599 }
621 if (-1 == connection->destroy_later) 600 if (-1 == connection->destroy_later)
622 { 601 {
@@ -658,21 +637,21 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *connection)
658{ 637{
659 LOG (GNUNET_ERROR_TYPE_DEBUG, 638 LOG (GNUNET_ERROR_TYPE_DEBUG,
660 "Connection to `%s' succeeded! (%p)\n", 639 "Connection to `%s' succeeded! (%p)\n",
661 GNUNET_a2s (connection->addr, 640 GNUNET_a2s (connection->addr, connection->addrlen),
662 connection->addrlen),
663 connection); 641 connection);
664 /* trigger jobs that waited for the connection */ 642 /* trigger jobs that waited for the connection */
665 if (NULL != connection->receiver) 643 if (NULL != connection->receiver)
666 { 644 {
667 LOG (GNUNET_ERROR_TYPE_DEBUG, 645 LOG (GNUNET_ERROR_TYPE_DEBUG,
668 "Connection succeeded, starting with receiving data (%p)\n", 646 "Connection succeeded, starting with receiving data (%p)\n",
669 connection); 647 connection);
670 GNUNET_assert (NULL == connection->read_task); 648 GNUNET_assert (NULL == connection->read_task);
671 connection->read_task = 649 connection->read_task =
672 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining 650 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining (
673 (connection->receive_timeout), 651 connection->receive_timeout),
674 connection->sock, 652 connection->sock,
675 &receive_ready, connection); 653 &receive_ready,
654 connection);
676 } 655 }
677 if (NULL != connection->nth.notify_ready) 656 if (NULL != connection->nth.notify_ready)
678 { 657 {
@@ -684,9 +663,11 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *connection)
684 connection->nth.timeout_task = NULL; 663 connection->nth.timeout_task = NULL;
685 GNUNET_assert (connection->write_task == NULL); 664 GNUNET_assert (connection->write_task == NULL);
686 connection->write_task = 665 connection->write_task =
687 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining 666 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining (
688 (connection->nth.transmit_timeout), connection->sock, 667 connection->nth.transmit_timeout),
689 &transmit_ready, connection); 668 connection->sock,
669 &transmit_ready,
670 connection);
690 } 671 }
691} 672}
692 673
@@ -708,28 +689,24 @@ connect_probe_continuation (void *cls)
708 socklen_t len; 689 socklen_t len;
709 690
710 GNUNET_assert (NULL != ap->sock); 691 GNUNET_assert (NULL != ap->sock);
711 GNUNET_CONTAINER_DLL_remove (connection->ap_head, 692 GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, ap);
712 connection->ap_tail,
713 ap);
714 len = sizeof (error); 693 len = sizeof (error);
715 errno = 0; 694 errno = 0;
716 error = 0; 695 error = 0;
717 tc = GNUNET_SCHEDULER_get_task_context (); 696 tc = GNUNET_SCHEDULER_get_task_context ();
718 if ( (0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) || 697 if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) ||
719 (GNUNET_OK != 698 (GNUNET_OK != GNUNET_NETWORK_socket_getsockopt (ap->sock,
720 GNUNET_NETWORK_socket_getsockopt (ap->sock, 699 SOL_SOCKET,
721 SOL_SOCKET, 700 SO_ERROR,
722 SO_ERROR, 701 &error,
723 &error, 702 &len)) ||
724 &len)) || 703 (0 != error))
725 (0 != error) )
726 { 704 {
727 GNUNET_break (GNUNET_OK == 705 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock));
728 GNUNET_NETWORK_socket_close (ap->sock));
729 GNUNET_free (ap); 706 GNUNET_free (ap);
730 if ( (NULL == connection->ap_head) && 707 if ((NULL == connection->ap_head) &&
731 (GNUNET_NO == connection->dns_active) && 708 (GNUNET_NO == connection->dns_active) &&
732 (NULL == connection->proxy_handshake) ) 709 (NULL == connection->proxy_handshake))
733 connect_fail_continuation (connection); 710 connect_fail_continuation (connection);
734 return; 711 return;
735 } 712 }
@@ -745,9 +722,7 @@ connect_probe_continuation (void *cls)
745 { 722 {
746 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); 723 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock));
747 GNUNET_SCHEDULER_cancel (pos->task); 724 GNUNET_SCHEDULER_cancel (pos->task);
748 GNUNET_CONTAINER_DLL_remove (connection->ap_head, 725 GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos);
749 connection->ap_tail,
750 pos);
751 GNUNET_free (pos); 726 GNUNET_free (pos);
752 } 727 }
753 connect_success_continuation (connection); 728 connect_success_continuation (connection);
@@ -774,14 +749,13 @@ try_connect_using_address (void *cls,
774 if (NULL == addr) 749 if (NULL == addr)
775 { 750 {
776 connection->dns_active = NULL; 751 connection->dns_active = NULL;
777 if ((NULL == connection->ap_head) && 752 if ((NULL == connection->ap_head) && (NULL == connection->sock) &&
778 (NULL == connection->sock) &&
779 (NULL == connection->proxy_handshake)) 753 (NULL == connection->proxy_handshake))
780 connect_fail_continuation (connection); 754 connect_fail_continuation (connection);
781 return; 755 return;
782 } 756 }
783 if (NULL != connection->sock) 757 if (NULL != connection->sock)
784 return; /* already connected */ 758 return; /* already connected */
785 GNUNET_assert (NULL == connection->addr); 759 GNUNET_assert (NULL == connection->addr);
786 /* try to connect */ 760 /* try to connect */
787 LOG (GNUNET_ERROR_TYPE_DEBUG, 761 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -807,23 +781,20 @@ try_connect_using_address (void *cls,
807 default: 781 default:
808 GNUNET_break (0); 782 GNUNET_break (0);
809 GNUNET_free (ap); 783 GNUNET_free (ap);
810 return; /* not supported by us */ 784 return; /* not supported by us */
811 } 785 }
812 ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, 786 ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, SOCK_STREAM, 0);
813 SOCK_STREAM, 0);
814 if (NULL == ap->sock) 787 if (NULL == ap->sock)
815 { 788 {
816 GNUNET_free (ap); 789 GNUNET_free (ap);
817 return; /* not supported by OS */ 790 return; /* not supported by OS */
818 } 791 }
819 LOG (GNUNET_ERROR_TYPE_INFO, 792 LOG (GNUNET_ERROR_TYPE_INFO,
820 "Trying to connect to `%s' (%p)\n", 793 "Trying to connect to `%s' (%p)\n",
821 GNUNET_a2s (ap->addr, ap->addrlen), 794 GNUNET_a2s (ap->addr, ap->addrlen),
822 connection); 795 connection);
823 if ((GNUNET_OK != 796 if ((GNUNET_OK !=
824 GNUNET_NETWORK_socket_connect (ap->sock, 797 GNUNET_NETWORK_socket_connect (ap->sock, ap->addr, ap->addrlen)) &&
825 ap->addr,
826 ap->addrlen)) &&
827 (EINPROGRESS != errno)) 798 (EINPROGRESS != errno))
828 { 799 {
829 /* maybe refused / unsupported address, try next */ 800 /* maybe refused / unsupported address, try next */
@@ -836,14 +807,16 @@ try_connect_using_address (void *cls,
836 delay = CONNECT_RETRY_TIMEOUT; 807 delay = CONNECT_RETRY_TIMEOUT;
837 if (NULL != connection->nth.notify_ready) 808 if (NULL != connection->nth.notify_ready)
838 delay = GNUNET_TIME_relative_min (delay, 809 delay = GNUNET_TIME_relative_min (delay,
839 GNUNET_TIME_absolute_get_remaining (connection->nth.transmit_timeout)); 810 GNUNET_TIME_absolute_get_remaining (
811 connection->nth.transmit_timeout));
840 if (NULL != connection->receiver) 812 if (NULL != connection->receiver)
841 delay = GNUNET_TIME_relative_min (delay, 813 delay = GNUNET_TIME_relative_min (delay,
842 GNUNET_TIME_absolute_get_remaining (connection->receive_timeout)); 814 GNUNET_TIME_absolute_get_remaining (
815 connection->receive_timeout));
843 ap->task = GNUNET_SCHEDULER_add_write_net (delay, 816 ap->task = GNUNET_SCHEDULER_add_write_net (delay,
844 ap->sock, 817 ap->sock,
845 &connect_probe_continuation, 818 &connect_probe_continuation,
846 ap); 819 ap);
847} 820}
848 821
849 822
@@ -858,25 +831,25 @@ try_connect_using_address (void *cls,
858 * @return the connection handle 831 * @return the connection handle
859 */ 832 */
860struct GNUNET_CONNECTION_Handle * 833struct GNUNET_CONNECTION_Handle *
861GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 834GNUNET_CONNECTION_create_from_connect (
862 const char *hostname, 835 const struct GNUNET_CONFIGURATION_Handle *cfg,
863 uint16_t port) 836 const char *hostname,
837 uint16_t port)
864{ 838{
865 struct GNUNET_CONNECTION_Handle *connection; 839 struct GNUNET_CONNECTION_Handle *connection;
866 840
867 GNUNET_assert (0 < strlen (hostname)); /* sanity check */ 841 GNUNET_assert (0 < strlen (hostname)); /* sanity check */
868 connection = GNUNET_new (struct GNUNET_CONNECTION_Handle); 842 connection = GNUNET_new (struct GNUNET_CONNECTION_Handle);
869 connection->cfg = cfg; 843 connection->cfg = cfg;
870 connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE; 844 connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE;
871 connection->write_buffer = GNUNET_malloc (connection->write_buffer_size); 845 connection->write_buffer = GNUNET_malloc (connection->write_buffer_size);
872 connection->port = port; 846 connection->port = port;
873 connection->hostname = GNUNET_strdup (hostname); 847 connection->hostname = GNUNET_strdup (hostname);
874 connection->dns_active = 848 connection->dns_active = GNUNET_RESOLVER_ip_get (connection->hostname,
875 GNUNET_RESOLVER_ip_get (connection->hostname, 849 AF_UNSPEC,
876 AF_UNSPEC, 850 CONNECT_RETRY_TIMEOUT,
877 CONNECT_RETRY_TIMEOUT, 851 &try_connect_using_address,
878 &try_connect_using_address, 852 connection);
879 connection);
880 return connection; 853 return connection;
881} 854}
882 855
@@ -891,14 +864,15 @@ GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle
891 * @return the connection handle, NULL on systems without UNIX support 864 * @return the connection handle, NULL on systems without UNIX support
892 */ 865 */
893struct GNUNET_CONNECTION_Handle * 866struct GNUNET_CONNECTION_Handle *
894GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURATION_Handle *cfg, 867GNUNET_CONNECTION_create_from_connect_to_unixpath (
895 const char *unixpath) 868 const struct GNUNET_CONFIGURATION_Handle *cfg,
869 const char *unixpath)
896{ 870{
897#ifdef AF_UNIX 871#ifdef AF_UNIX
898 struct GNUNET_CONNECTION_Handle *connection; 872 struct GNUNET_CONNECTION_Handle *connection;
899 struct sockaddr_un *un; 873 struct sockaddr_un *un;
900 874
901 GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ 875 GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
902 un = GNUNET_new (struct sockaddr_un); 876 un = GNUNET_new (struct sockaddr_un);
903 un->sun_family = AF_UNIX; 877 un->sun_family = AF_UNIX;
904 GNUNET_strlcpy (un->sun_path, unixpath, sizeof (un->sun_path)); 878 GNUNET_strlcpy (un->sun_path, unixpath, sizeof (un->sun_path));
@@ -907,7 +881,7 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURA
907 int abstract; 881 int abstract;
908 882
909 abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, 883 abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
910 "TESTING", 884 "TESTING",
911 "USE_ABSTRACT_SOCKETS"); 885 "USE_ABSTRACT_SOCKETS");
912 if (GNUNET_YES == abstract) 886 if (GNUNET_YES == abstract)
913 un->sun_path[0] = '\0'; 887 un->sun_path[0] = '\0';
@@ -924,9 +898,7 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURA
924 connection->hostname = NULL; 898 connection->hostname = NULL;
925 connection->addr = (struct sockaddr *) un; 899 connection->addr = (struct sockaddr *) un;
926 connection->addrlen = sizeof (struct sockaddr_un); 900 connection->addrlen = sizeof (struct sockaddr_un);
927 connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX, 901 connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
928 SOCK_STREAM,
929 0);
930 if (NULL == connection->sock) 902 if (NULL == connection->sock)
931 { 903 {
932 GNUNET_free (connection->addr); 904 GNUNET_free (connection->addr);
@@ -934,15 +906,13 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURA
934 GNUNET_free (connection); 906 GNUNET_free (connection);
935 return NULL; 907 return NULL;
936 } 908 }
937 if ( (GNUNET_OK != 909 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (connection->sock,
938 GNUNET_NETWORK_socket_connect (connection->sock, 910 connection->addr,
939 connection->addr, 911 connection->addrlen)) &&
940 connection->addrlen)) && 912 (EINPROGRESS != errno))
941 (EINPROGRESS != errno) )
942 { 913 {
943 /* Just return; we expect everything to work eventually so don't fail HARD */ 914 /* Just return; we expect everything to work eventually so don't fail HARD */
944 GNUNET_break (GNUNET_OK == 915 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock));
945 GNUNET_NETWORK_socket_close (connection->sock));
946 connection->sock = NULL; 916 connection->sock = NULL;
947 return connection; 917 return connection;
948 } 918 }
@@ -971,17 +941,14 @@ GNUNET_CONNECTION_connect_socket (struct GNUNET_NETWORK_Handle *s,
971{ 941{
972 struct GNUNET_CONNECTION_Handle *connection; 942 struct GNUNET_CONNECTION_Handle *connection;
973 943
974 if ( (GNUNET_OK != 944 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) &&
975 GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) && 945 (EINPROGRESS != errno))
976 (EINPROGRESS != errno) )
977 { 946 {
978 /* maybe refused / unsupported address, try next */ 947 /* maybe refused / unsupported address, try next */
979 LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, 948 LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "connect");
980 "connect");
981 LOG (GNUNET_ERROR_TYPE_DEBUG, 949 LOG (GNUNET_ERROR_TYPE_DEBUG,
982 "Attempt to connect to `%s' failed\n", 950 "Attempt to connect to `%s' failed\n",
983 GNUNET_a2s (serv_addr, 951 GNUNET_a2s (serv_addr, addrlen));
984 addrlen));
985 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); 952 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s));
986 return NULL; 953 return NULL;
987 } 954 }
@@ -1018,13 +985,10 @@ GNUNET_CONNECTION_create_from_sockaddr (int af_family,
1018 s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0); 985 s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0);
1019 if (NULL == s) 986 if (NULL == s)
1020 { 987 {
1021 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, 988 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "socket");
1022 "socket");
1023 return NULL; 989 return NULL;
1024 } 990 }
1025 return GNUNET_CONNECTION_connect_socket (s, 991 return GNUNET_CONNECTION_connect_socket (s, serv_addr, addrlen);
1026 serv_addr,
1027 addrlen);
1028} 992}
1029 993
1030 994
@@ -1039,12 +1003,10 @@ GNUNET_CONNECTION_create_from_sockaddr (int af_family,
1039int 1003int
1040GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *connection) 1004GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *connection)
1041{ 1005{
1042 if ((NULL != connection->ap_head) || 1006 if ((NULL != connection->ap_head) || (NULL != connection->dns_active) ||
1043 (NULL != connection->dns_active) ||
1044 (NULL != connection->proxy_handshake)) 1007 (NULL != connection->proxy_handshake))
1045 return GNUNET_YES; /* still trying to connect */ 1008 return GNUNET_YES; /* still trying to connect */
1046 if ( (0 != connection->destroy_later) || 1009 if ((0 != connection->destroy_later) || (NULL == connection->sock))
1047 (NULL == connection->sock) )
1048 return GNUNET_NO; 1010 return GNUNET_NO;
1049 return GNUNET_YES; 1011 return GNUNET_YES;
1050} 1012}
@@ -1067,9 +1029,7 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection)
1067 connection->destroy_later = -1; 1029 connection->destroy_later = -1;
1068 return; 1030 return;
1069 } 1031 }
1070 LOG (GNUNET_ERROR_TYPE_DEBUG, 1032 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down connection (%p)\n", connection);
1071 "Shutting down connection (%p)\n",
1072 connection);
1073 GNUNET_assert (NULL == connection->nth.notify_ready); 1033 GNUNET_assert (NULL == connection->nth.notify_ready);
1074 GNUNET_assert (NULL == connection->receiver); 1034 GNUNET_assert (NULL == connection->receiver);
1075 if (NULL != connection->write_task) 1035 if (NULL != connection->write_task)
@@ -1098,27 +1058,21 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection)
1098 { 1058 {
1099 /* GNUNET_CONNECTION_destroy (connection->proxy_handshake); */ 1059 /* GNUNET_CONNECTION_destroy (connection->proxy_handshake); */
1100 connection->proxy_handshake->destroy_later = -1; 1060 connection->proxy_handshake->destroy_later = -1;
1101 connection->proxy_handshake = NULL; /* Not leaked ??? */ 1061 connection->proxy_handshake = NULL; /* Not leaked ??? */
1102 } 1062 }
1103 while (NULL != (pos = connection->ap_head)) 1063 while (NULL != (pos = connection->ap_head))
1104 { 1064 {
1105 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); 1065 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock));
1106 GNUNET_SCHEDULER_cancel (pos->task); 1066 GNUNET_SCHEDULER_cancel (pos->task);
1107 GNUNET_CONTAINER_DLL_remove (connection->ap_head, 1067 GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos);
1108 connection->ap_tail,
1109 pos);
1110 GNUNET_free (pos); 1068 GNUNET_free (pos);
1111 } 1069 }
1112 if ( (NULL != connection->sock) && 1070 if ((NULL != connection->sock) && (GNUNET_YES != connection->persist))
1113 (GNUNET_YES != connection->persist) )
1114 { 1071 {
1115 if ((GNUNET_OK != 1072 if ((GNUNET_OK !=
1116 GNUNET_NETWORK_socket_shutdown (connection->sock, 1073 GNUNET_NETWORK_socket_shutdown (connection->sock, SHUT_RDWR)) &&
1117 SHUT_RDWR)) && 1074 (ENOTCONN != errno) && (ECONNRESET != errno))
1118 (ENOTCONN != errno) && 1075 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "shutdown");
1119 (ECONNRESET != errno) )
1120 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
1121 "shutdown");
1122 } 1076 }
1123 if (NULL != connection->sock) 1077 if (NULL != connection->sock)
1124 { 1078 {
@@ -1129,7 +1083,8 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection)
1129 } 1083 }
1130 else 1084 else
1131 { 1085 {
1132 GNUNET_NETWORK_socket_free_memory_only_ (connection->sock); /* at least no memory leak (we deliberately 1086 GNUNET_NETWORK_socket_free_memory_only_ (
1087 connection->sock); /* at least no memory leak (we deliberately
1133 * leak the socket in this special case) ... */ 1088 * leak the socket in this special case) ... */
1134 } 1089 }
1135 } 1090 }
@@ -1160,12 +1115,12 @@ receive_ready (void *cls)
1160 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) 1115 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
1161 { 1116 {
1162 LOG (GNUNET_ERROR_TYPE_DEBUG, 1117 LOG (GNUNET_ERROR_TYPE_DEBUG,
1163 "Receive from `%s' encounters error: timeout (%s, %p)\n", 1118 "Receive from `%s' encounters error: timeout (%s, %p)\n",
1164 GNUNET_a2s (connection->addr, 1119 GNUNET_a2s (connection->addr, connection->addrlen),
1165 connection->addrlen), 1120 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (
1166 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (connection->receive_timeout), 1121 connection->receive_timeout),
1167 GNUNET_YES), 1122 GNUNET_YES),
1168 connection); 1123 connection);
1169 signal_receive_timeout (connection); 1124 signal_receive_timeout (connection);
1170 return; 1125 return;
1171 } 1126 }
@@ -1175,12 +1130,9 @@ receive_ready (void *cls)
1175 signal_receive_error (connection, ECONNREFUSED); 1130 signal_receive_error (connection, ECONNREFUSED);
1176 return; 1131 return;
1177 } 1132 }
1178 GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, 1133 GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, connection->sock));
1179 connection->sock));
1180RETRY: 1134RETRY:
1181 ret = GNUNET_NETWORK_socket_recv (connection->sock, 1135 ret = GNUNET_NETWORK_socket_recv (connection->sock, buffer, connection->max);
1182 buffer,
1183 connection->max);
1184 if (-1 == ret) 1136 if (-1 == ret)
1185 { 1137 {
1186 if (EINTR == errno) 1138 if (EINTR == errno)
@@ -1192,8 +1144,7 @@ RETRY:
1192 "receive_ready read %u/%u bytes from `%s' (%p)!\n", 1144 "receive_ready read %u/%u bytes from `%s' (%p)!\n",
1193 (unsigned int) ret, 1145 (unsigned int) ret,
1194 connection->max, 1146 connection->max,
1195 GNUNET_a2s (connection->addr, 1147 GNUNET_a2s (connection->addr, connection->addrlen),
1196 connection->addrlen),
1197 connection); 1148 connection);
1198 GNUNET_assert (NULL != (receiver = connection->receiver)); 1149 GNUNET_assert (NULL != (receiver = connection->receiver));
1199 connection->receiver = NULL; 1150 connection->receiver = NULL;
@@ -1238,22 +1189,18 @@ GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection,
1238 if (NULL != connection->sock) 1189 if (NULL != connection->sock)
1239 { 1190 {
1240 connection->read_task = 1191 connection->read_task =
1241 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining 1192 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining (
1242 (connection->receive_timeout), 1193 connection->receive_timeout),
1243 connection->sock, 1194 connection->sock,
1244 &receive_ready, 1195 &receive_ready,
1245 connection); 1196 connection);
1246 return GNUNET_OK; 1197 return GNUNET_OK;
1247 } 1198 }
1248 if ((NULL == connection->dns_active) && 1199 if ((NULL == connection->dns_active) && (NULL == connection->ap_head) &&
1249 (NULL == connection->ap_head) &&
1250 (NULL == connection->proxy_handshake)) 1200 (NULL == connection->proxy_handshake))
1251 { 1201 {
1252 connection->receiver = NULL; 1202 connection->receiver = NULL;
1253 receiver (receiver_cls, 1203 receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT);
1254 NULL, 0,
1255 NULL, 0,
1256 ETIMEDOUT);
1257 return GNUNET_SYSERR; 1204 return GNUNET_SYSERR;
1258 } 1205 }
1259 return GNUNET_OK; 1206 return GNUNET_OK;
@@ -1297,13 +1244,11 @@ process_notify (struct GNUNET_CONNECTION_Handle *connection)
1297 size_t size; 1244 size_t size;
1298 GNUNET_CONNECTION_TransmitReadyNotify notify; 1245 GNUNET_CONNECTION_TransmitReadyNotify notify;
1299 1246
1300 LOG (GNUNET_ERROR_TYPE_DEBUG, 1247 LOG (GNUNET_ERROR_TYPE_DEBUG, "process_notify is running\n");
1301 "process_notify is running\n");
1302 GNUNET_assert (NULL == connection->write_task); 1248 GNUNET_assert (NULL == connection->write_task);
1303 if (NULL == (notify = connection->nth.notify_ready)) 1249 if (NULL == (notify = connection->nth.notify_ready))
1304 { 1250 {
1305 LOG (GNUNET_ERROR_TYPE_DEBUG, 1251 LOG (GNUNET_ERROR_TYPE_DEBUG, "No one to notify\n");
1306 "No one to notify\n");
1307 return GNUNET_NO; 1252 return GNUNET_NO;
1308 } 1253 }
1309 used = connection->write_buffer_off - connection->write_buffer_pos; 1254 used = connection->write_buffer_off - connection->write_buffer_pos;
@@ -1311,8 +1256,7 @@ process_notify (struct GNUNET_CONNECTION_Handle *connection)
1311 size = connection->nth.notify_size; 1256 size = connection->nth.notify_size;
1312 if (size > avail) 1257 if (size > avail)
1313 { 1258 {
1314 LOG (GNUNET_ERROR_TYPE_DEBUG, 1259 LOG (GNUNET_ERROR_TYPE_DEBUG, "Not enough buffer\n");
1315 "Not enough buffer\n");
1316 return GNUNET_NO; 1260 return GNUNET_NO;
1317 } 1261 }
1318 connection->nth.notify_ready = NULL; 1262 connection->nth.notify_ready = NULL;
@@ -1327,9 +1271,9 @@ process_notify (struct GNUNET_CONNECTION_Handle *connection)
1327 } 1271 }
1328 avail = connection->write_buffer_size - connection->write_buffer_off; 1272 avail = connection->write_buffer_size - connection->write_buffer_off;
1329 GNUNET_assert (avail >= size); 1273 GNUNET_assert (avail >= size);
1330 size = 1274 size = notify (connection->nth.notify_ready_cls,
1331 notify (connection->nth.notify_ready_cls, avail, 1275 avail,
1332 &connection->write_buffer[connection->write_buffer_off]); 1276 &connection->write_buffer[connection->write_buffer_off]);
1333 GNUNET_assert (size <= avail); 1277 GNUNET_assert (size <= avail);
1334 if (0 != size) 1278 if (0 != size)
1335 connection->write_buffer_off += size; 1279 connection->write_buffer_off += size;
@@ -1358,15 +1302,12 @@ transmit_timeout (void *cls)
1358 "Transmit to `%s:%u/%s' fails, time out reached (%p).\n", 1302 "Transmit to `%s:%u/%s' fails, time out reached (%p).\n",
1359 connection->hostname, 1303 connection->hostname,
1360 connection->port, 1304 connection->port,
1361 GNUNET_a2s (connection->addr, 1305 GNUNET_a2s (connection->addr, connection->addrlen),
1362 connection->addrlen),
1363 connection); 1306 connection);
1364 notify = connection->nth.notify_ready; 1307 notify = connection->nth.notify_ready;
1365 GNUNET_assert (NULL != notify); 1308 GNUNET_assert (NULL != notify);
1366 connection->nth.notify_ready = NULL; 1309 connection->nth.notify_ready = NULL;
1367 notify (connection->nth.notify_ready_cls, 1310 notify (connection->nth.notify_ready_cls, 0, NULL);
1368 0,
1369 NULL);
1370} 1311}
1371 1312
1372 1313
@@ -1393,9 +1334,7 @@ connect_error (void *cls)
1393 connection->write_task = NULL; 1334 connection->write_task = NULL;
1394 notify = connection->nth.notify_ready; 1335 notify = connection->nth.notify_ready;
1395 connection->nth.notify_ready = NULL; 1336 connection->nth.notify_ready = NULL;
1396 notify (connection->nth.notify_ready_cls, 1337 notify (connection->nth.notify_ready_cls, 0, NULL);
1397 0,
1398 NULL);
1399} 1338}
1400 1339
1401 1340
@@ -1413,9 +1352,7 @@ transmit_ready (void *cls)
1413 ssize_t ret; 1352 ssize_t ret;
1414 size_t have; 1353 size_t have;
1415 1354
1416 LOG (GNUNET_ERROR_TYPE_DEBUG, 1355 LOG (GNUNET_ERROR_TYPE_DEBUG, "transmit_ready running (%p).\n", connection);
1417 "transmit_ready running (%p).\n",
1418 connection);
1419 GNUNET_assert (NULL != connection->write_task); 1356 GNUNET_assert (NULL != connection->write_task);
1420 connection->write_task = NULL; 1357 connection->write_task = NULL;
1421 GNUNET_assert (NULL == connection->nth.timeout_task); 1358 GNUNET_assert (NULL == connection->nth.timeout_task);
@@ -1424,8 +1361,7 @@ transmit_ready (void *cls)
1424 { 1361 {
1425 LOG (GNUNET_ERROR_TYPE_DEBUG, 1362 LOG (GNUNET_ERROR_TYPE_DEBUG,
1426 "Transmit to `%s' fails, time out reached (%p).\n", 1363 "Transmit to `%s' fails, time out reached (%p).\n",
1427 GNUNET_a2s (connection->addr, 1364 GNUNET_a2s (connection->addr, connection->addrlen),
1428 connection->addrlen),
1429 connection); 1365 connection);
1430 notify = connection->nth.notify_ready; 1366 notify = connection->nth.notify_ready;
1431 GNUNET_assert (NULL != notify); 1367 GNUNET_assert (NULL != notify);
@@ -1441,8 +1377,7 @@ transmit_ready (void *cls)
1441 * Hence retry. */ 1377 * Hence retry. */
1442 goto SCHEDULE_WRITE; 1378 goto SCHEDULE_WRITE;
1443 } 1379 }
1444 if (! GNUNET_NETWORK_fdset_isset (tc->write_ready, 1380 if (! GNUNET_NETWORK_fdset_isset (tc->write_ready, connection->sock))
1445 connection->sock))
1446 { 1381 {
1447 GNUNET_assert (NULL == connection->write_task); 1382 GNUNET_assert (NULL == connection->write_task);
1448 /* special circumstances (in particular, shutdown): not yet ready 1383 /* special circumstances (in particular, shutdown): not yet ready
@@ -1454,7 +1389,7 @@ transmit_ready (void *cls)
1454 (connection->write_buffer_size < connection->nth.notify_size)) 1389 (connection->write_buffer_size < connection->nth.notify_size))
1455 { 1390 {
1456 connection->write_buffer = 1391 connection->write_buffer =
1457 GNUNET_realloc (connection->write_buffer, connection->nth.notify_size); 1392 GNUNET_realloc (connection->write_buffer, connection->nth.notify_size);
1458 connection->write_buffer_size = connection->nth.notify_size; 1393 connection->write_buffer_size = connection->nth.notify_size;
1459 } 1394 }
1460 process_notify (connection); 1395 process_notify (connection);
@@ -1465,13 +1400,15 @@ transmit_ready (void *cls)
1465 return; 1400 return;
1466 } 1401 }
1467 GNUNET_assert (have <= connection->write_buffer_size); 1402 GNUNET_assert (have <= connection->write_buffer_size);
1468 GNUNET_assert (have + connection->write_buffer_pos <= connection->write_buffer_size); 1403 GNUNET_assert (have + connection->write_buffer_pos <=
1404 connection->write_buffer_size);
1469 GNUNET_assert (connection->write_buffer_pos <= connection->write_buffer_size); 1405 GNUNET_assert (connection->write_buffer_pos <= connection->write_buffer_size);
1470RETRY: 1406RETRY:
1471 ret = 1407 ret =
1472 GNUNET_NETWORK_socket_send (connection->sock, 1408 GNUNET_NETWORK_socket_send (connection->sock,
1473 &connection->write_buffer[connection->write_buffer_pos], 1409 &connection
1474 have); 1410 ->write_buffer[connection->write_buffer_pos],
1411 have);
1475 if (-1 == ret) 1412 if (-1 == ret)
1476 { 1413 {
1477 if (EINTR == errno) 1414 if (EINTR == errno)
@@ -1488,8 +1425,7 @@ RETRY:
1488 "Connection transmitted %u/%u bytes to `%s' (%p)\n", 1425 "Connection transmitted %u/%u bytes to `%s' (%p)\n",
1489 (unsigned int) ret, 1426 (unsigned int) ret,
1490 have, 1427 have,
1491 GNUNET_a2s (connection->addr, 1428 GNUNET_a2s (connection->addr, connection->addrlen),
1492 connection->addrlen),
1493 connection); 1429 connection);
1494 connection->write_buffer_pos += ret; 1430 connection->write_buffer_pos += ret;
1495 if (connection->write_buffer_pos == connection->write_buffer_off) 1431 if (connection->write_buffer_pos == connection->write_buffer_off)
@@ -1498,25 +1434,25 @@ RETRY:
1498 connection->write_buffer_pos = 0; 1434 connection->write_buffer_pos = 0;
1499 connection->write_buffer_off = 0; 1435 connection->write_buffer_off = 0;
1500 } 1436 }
1501 if ( (0 == connection->write_buffer_off) && 1437 if ((0 == connection->write_buffer_off) &&
1502 (NULL == connection->nth.notify_ready) ) 1438 (NULL == connection->nth.notify_ready))
1503 return; /* all data sent! */ 1439 return; /* all data sent! */
1504 /* not done writing, schedule more */ 1440 /* not done writing, schedule more */
1505SCHEDULE_WRITE: 1441SCHEDULE_WRITE:
1506 LOG (GNUNET_ERROR_TYPE_DEBUG, 1442 LOG (GNUNET_ERROR_TYPE_DEBUG,
1507 "Re-scheduling transmit_ready (more to do) (%p).\n", 1443 "Re-scheduling transmit_ready (more to do) (%p).\n",
1508 connection); 1444 connection);
1509 have = connection->write_buffer_off - connection->write_buffer_pos; 1445 have = connection->write_buffer_off - connection->write_buffer_pos;
1510 GNUNET_assert ( (NULL != connection->nth.notify_ready) || 1446 GNUNET_assert ((NULL != connection->nth.notify_ready) || (have > 0));
1511 (have > 0) );
1512 if (NULL == connection->write_task) 1447 if (NULL == connection->write_task)
1513 connection->write_task = 1448 connection->write_task =
1514 GNUNET_SCHEDULER_add_write_net ((connection->nth.notify_ready == 1449 GNUNET_SCHEDULER_add_write_net ((connection->nth.notify_ready == NULL)
1515 NULL) ? GNUNET_TIME_UNIT_FOREVER_REL : 1450 ? GNUNET_TIME_UNIT_FOREVER_REL
1516 GNUNET_TIME_absolute_get_remaining 1451 : GNUNET_TIME_absolute_get_remaining (
1517 (connection->nth.transmit_timeout), 1452 connection->nth.transmit_timeout),
1518 connection->sock, 1453 connection->sock,
1519 &transmit_ready, connection); 1454 &transmit_ready,
1455 connection);
1520} 1456}
1521 1457
1522 1458
@@ -1535,11 +1471,12 @@ SCHEDULE_WRITE:
1535 * NULL if we are already going to notify someone else (busy) 1471 * NULL if we are already going to notify someone else (busy)
1536 */ 1472 */
1537struct GNUNET_CONNECTION_TransmitHandle * 1473struct GNUNET_CONNECTION_TransmitHandle *
1538GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connection, 1474GNUNET_CONNECTION_notify_transmit_ready (
1539 size_t size, 1475 struct GNUNET_CONNECTION_Handle *connection,
1540 struct GNUNET_TIME_Relative timeout, 1476 size_t size,
1541 GNUNET_CONNECTION_TransmitReadyNotify notify, 1477 struct GNUNET_TIME_Relative timeout,
1542 void *notify_cls) 1478 GNUNET_CONNECTION_TransmitReadyNotify notify,
1479 void *notify_cls)
1543{ 1480{
1544 if (NULL != connection->nth.notify_ready) 1481 if (NULL != connection->nth.notify_ready)
1545 { 1482 {
@@ -1557,15 +1494,13 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connec
1557 connection->nth.notify_size = size; 1494 connection->nth.notify_size = size;
1558 connection->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute (timeout); 1495 connection->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1559 GNUNET_assert (NULL == connection->nth.timeout_task); 1496 GNUNET_assert (NULL == connection->nth.timeout_task);
1560 if ((NULL == connection->sock) && 1497 if ((NULL == connection->sock) && (NULL == connection->ap_head) &&
1561 (NULL == connection->ap_head) && 1498 (NULL == connection->dns_active) && (NULL == connection->proxy_handshake))
1562 (NULL == connection->dns_active) &&
1563 (NULL == connection->proxy_handshake))
1564 { 1499 {
1565 if (NULL != connection->write_task) 1500 if (NULL != connection->write_task)
1566 GNUNET_SCHEDULER_cancel (connection->write_task); 1501 GNUNET_SCHEDULER_cancel (connection->write_task);
1567 connection->write_task = GNUNET_SCHEDULER_add_now (&connect_error, 1502 connection->write_task =
1568 connection); 1503 GNUNET_SCHEDULER_add_now (&connect_error, connection);
1569 return &connection->nth; 1504 return &connection->nth;
1570 } 1505 }
1571 if (NULL != connection->write_task) 1506 if (NULL != connection->write_task)
@@ -1577,10 +1512,11 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connec
1577 "Scheduling transmission (%p).\n", 1512 "Scheduling transmission (%p).\n",
1578 connection); 1513 connection);
1579 connection->write_task = 1514 connection->write_task =
1580 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining 1515 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining (
1581 (connection->nth.transmit_timeout), 1516 connection->nth.transmit_timeout),
1582 connection->sock, 1517 connection->sock,
1583 &transmit_ready, connection); 1518 &transmit_ready,
1519 connection);
1584 return &connection->nth; 1520 return &connection->nth;
1585 } 1521 }
1586 /* not yet connected, wait for connection */ 1522 /* not yet connected, wait for connection */
@@ -1588,9 +1524,7 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connec
1588 "Need to wait to schedule transmission for connection, adding timeout task (%p).\n", 1524 "Need to wait to schedule transmission for connection, adding timeout task (%p).\n",
1589 connection); 1525 connection);
1590 connection->nth.timeout_task = 1526 connection->nth.timeout_task =
1591 GNUNET_SCHEDULER_add_delayed (timeout, 1527 GNUNET_SCHEDULER_add_delayed (timeout, &transmit_timeout, connection);
1592 &transmit_timeout,
1593 connection);
1594 return &connection->nth; 1528 return &connection->nth;
1595} 1529}
1596 1530
@@ -1601,7 +1535,8 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connec
1601 * @param th notification to cancel 1535 * @param th notification to cancel
1602 */ 1536 */
1603void 1537void
1604GNUNET_CONNECTION_notify_transmit_ready_cancel (struct GNUNET_CONNECTION_TransmitHandle *th) 1538GNUNET_CONNECTION_notify_transmit_ready_cancel (
1539 struct GNUNET_CONNECTION_TransmitHandle *th)
1605{ 1540{
1606 GNUNET_assert (NULL != th->notify_ready); 1541 GNUNET_assert (NULL != th->notify_ready);
1607 th->notify_ready = NULL; 1542 th->notify_ready = NULL;
@@ -1625,9 +1560,11 @@ GNUNET_CONNECTION_notify_transmit_ready_cancel (struct GNUNET_CONNECTION_Transmi
1625 * @return connection to be proxied 1560 * @return connection to be proxied
1626 */ 1561 */
1627struct GNUNET_CONNECTION_Handle * 1562struct GNUNET_CONNECTION_Handle *
1628GNUNET_CONNECTION_create_proxied_from_handshake (struct GNUNET_CONNECTION_Handle *cph) 1563GNUNET_CONNECTION_create_proxied_from_handshake (
1564 struct GNUNET_CONNECTION_Handle *cph)
1629{ 1565{
1630 struct GNUNET_CONNECTION_Handle *proxied = GNUNET_CONNECTION_create_from_existing (NULL); 1566 struct GNUNET_CONNECTION_Handle *proxied =
1567 GNUNET_CONNECTION_create_from_existing (NULL);
1631 1568
1632 proxied->proxy_handshake = cph; 1569 proxied->proxy_handshake = cph;
1633 return proxied; 1570 return proxied;
diff --git a/src/transport/tcp_service_legacy.c b/src/transport/tcp_service_legacy.c
index 19508a39f..e59fa4a1c 100644
--- a/src/transport/tcp_service_legacy.c
+++ b/src/transport/tcp_service_legacy.c
@@ -224,7 +224,6 @@ struct LEGACY_SERVICE_Context
224 * Our options. 224 * Our options.
225 */ 225 */
226 enum LEGACY_SERVICE_Options options; 226 enum LEGACY_SERVICE_Options options;
227
228}; 227};
229 228
230 229
@@ -247,7 +246,7 @@ write_test (void *cls, size_t size, void *buf)
247 if (size < sizeof (struct GNUNET_MessageHeader)) 246 if (size < sizeof (struct GNUNET_MessageHeader))
248 { 247 {
249 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 248 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
250 return 0; /* client disconnected */ 249 return 0; /* client disconnected */
251 } 250 }
252 msg = (struct GNUNET_MessageHeader *) buf; 251 msg = (struct GNUNET_MessageHeader *) buf;
253 msg->type = htons (GNUNET_MESSAGE_TYPE_TEST); 252 msg->type = htons (GNUNET_MESSAGE_TYPE_TEST);
@@ -265,7 +264,8 @@ write_test (void *cls, size_t size, void *buf)
265 * @param message the actual message 264 * @param message the actual message
266 */ 265 */
267static void 266static void
268handle_test (void *cls, struct GNUNET_SERVER_Client *client, 267handle_test (void *cls,
268 struct GNUNET_SERVER_Client *client,
269 const struct GNUNET_MessageHeader *message) 269 const struct GNUNET_MessageHeader *message)
270{ 270{
271 /* simply bounce message back to acknowledge */ 271 /* simply bounce message back to acknowledge */
@@ -273,7 +273,8 @@ handle_test (void *cls, struct GNUNET_SERVER_Client *client,
273 GNUNET_SERVER_notify_transmit_ready (client, 273 GNUNET_SERVER_notify_transmit_ready (client,
274 sizeof (struct GNUNET_MessageHeader), 274 sizeof (struct GNUNET_MessageHeader),
275 GNUNET_TIME_UNIT_FOREVER_REL, 275 GNUNET_TIME_UNIT_FOREVER_REL,
276 &write_test, client)) 276 &write_test,
277 client))
277 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 278 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
278} 279}
279 280
@@ -283,11 +284,12 @@ handle_test (void *cls, struct GNUNET_SERVER_Client *client,
283 * "callback_cls" fields will be replaced with the specific service 284 * "callback_cls" fields will be replaced with the specific service
284 * struct. 285 * struct.
285 */ 286 */
286static const struct GNUNET_SERVER_MessageHandler defhandlers[] = { 287static const struct GNUNET_SERVER_MessageHandler defhandlers[] =
287 {&handle_test, NULL, GNUNET_MESSAGE_TYPE_TEST, 288 {{&handle_test,
288 sizeof (struct GNUNET_MessageHeader)}, 289 NULL,
289 {NULL, NULL, 0, 0} 290 GNUNET_MESSAGE_TYPE_TEST,
290}; 291 sizeof (struct GNUNET_MessageHeader)},
292 {NULL, NULL, 0, 0}};
291 293
292 294
293/* ****************** service core routines ************** */ 295/* ****************** service core routines ************** */
@@ -304,8 +306,10 @@ static const struct GNUNET_SERVER_MessageHandler defhandlers[] = {
304 * for unknown address family (will be denied). 306 * for unknown address family (will be denied).
305 */ 307 */
306static int 308static int
307check_access (void *cls, const struct GNUNET_CONNECTION_Credentials *uc, 309check_access (void *cls,
308 const struct sockaddr *addr, socklen_t addrlen) 310 const struct GNUNET_CONNECTION_Credentials *uc,
311 const struct sockaddr *addr,
312 socklen_t addrlen)
309{ 313{
310 struct LEGACY_SERVICE_Context *sctx = cls; 314 struct LEGACY_SERVICE_Context *sctx = cls;
311 const struct sockaddr_in *i4; 315 const struct sockaddr_in *i4;
@@ -319,32 +323,33 @@ check_access (void *cls, const struct GNUNET_CONNECTION_Credentials *uc,
319 i4 = (const struct sockaddr_in *) addr; 323 i4 = (const struct sockaddr_in *) addr;
320 ret = ((NULL == sctx->v4_allowed) || 324 ret = ((NULL == sctx->v4_allowed) ||
321 (check_ipv4_listed (sctx->v4_allowed, &i4->sin_addr))) && 325 (check_ipv4_listed (sctx->v4_allowed, &i4->sin_addr))) &&
322 ((NULL == sctx->v4_denied) || 326 ((NULL == sctx->v4_denied) ||
323 (!check_ipv4_listed (sctx->v4_denied, &i4->sin_addr))); 327 (! check_ipv4_listed (sctx->v4_denied, &i4->sin_addr)));
324 break; 328 break;
325 case AF_INET6: 329 case AF_INET6:
326 GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); 330 GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
327 i6 = (const struct sockaddr_in6 *) addr; 331 i6 = (const struct sockaddr_in6 *) addr;
328 ret = ((NULL == sctx->v6_allowed) || 332 ret = ((NULL == sctx->v6_allowed) ||
329 (check_ipv6_listed (sctx->v6_allowed, &i6->sin6_addr))) && 333 (check_ipv6_listed (sctx->v6_allowed, &i6->sin6_addr))) &&
330 ((NULL == sctx->v6_denied) || 334 ((NULL == sctx->v6_denied) ||
331 (!check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr))); 335 (! check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr)));
332 break; 336 break;
333#ifndef WINDOWS 337#ifndef WINDOWS
334 case AF_UNIX: 338 case AF_UNIX:
335 ret = GNUNET_OK; /* controlled using file-system ACL now */ 339 ret = GNUNET_OK; /* controlled using file-system ACL now */
336 break; 340 break;
337#endif 341#endif
338 default: 342 default:
339 LOG (GNUNET_ERROR_TYPE_WARNING, _("Unknown address family %d\n"), 343 LOG (GNUNET_ERROR_TYPE_WARNING,
344 _ ("Unknown address family %d\n"),
340 addr->sa_family); 345 addr->sa_family);
341 return GNUNET_SYSERR; 346 return GNUNET_SYSERR;
342 } 347 }
343 if (GNUNET_OK != ret) 348 if (GNUNET_OK != ret)
344 { 349 {
345 LOG (GNUNET_ERROR_TYPE_WARNING, 350 LOG (GNUNET_ERROR_TYPE_WARNING,
346 _("Access from `%s' denied to service `%s'\n"), 351 _ ("Access from `%s' denied to service `%s'\n"),
347 GNUNET_a2s (addr, addrlen), 352 GNUNET_a2s (addr, addrlen),
348 sctx->service_name); 353 sctx->service_name);
349 } 354 }
350 return ret; 355 return ret;
@@ -363,9 +368,10 @@ get_pid_file_name (struct LEGACY_SERVICE_Context *sctx)
363{ 368{
364 char *pif; 369 char *pif;
365 370
366 if (GNUNET_OK != 371 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (sctx->cfg,
367 GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, sctx->service_name, 372 sctx->service_name,
368 "PIDFILE", &pif)) 373 "PIDFILE",
374 &pif))
369 return NULL; 375 return NULL;
370 return pif; 376 return pif;
371} 377}
@@ -387,7 +393,7 @@ process_acl4 (struct GNUNET_STRINGS_IPv4NetworkPolicy **ret,
387{ 393{
388 char *opt; 394 char *opt;
389 395
390 if (!GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, option)) 396 if (! GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, option))
391 { 397 {
392 *ret = NULL; 398 *ret = NULL;
393 return GNUNET_OK; 399 return GNUNET_OK;
@@ -395,12 +401,15 @@ process_acl4 (struct GNUNET_STRINGS_IPv4NetworkPolicy **ret,
395 GNUNET_break (GNUNET_OK == 401 GNUNET_break (GNUNET_OK ==
396 GNUNET_CONFIGURATION_get_value_string (sctx->cfg, 402 GNUNET_CONFIGURATION_get_value_string (sctx->cfg,
397 sctx->service_name, 403 sctx->service_name,
398 option, &opt)); 404 option,
405 &opt));
399 if (NULL == (*ret = GNUNET_STRINGS_parse_ipv4_policy (opt))) 406 if (NULL == (*ret = GNUNET_STRINGS_parse_ipv4_policy (opt)))
400 { 407 {
401 LOG (GNUNET_ERROR_TYPE_WARNING, 408 LOG (GNUNET_ERROR_TYPE_WARNING,
402 _("Could not parse IPv4 network specification `%s' for `%s:%s'\n"), 409 _ ("Could not parse IPv4 network specification `%s' for `%s:%s'\n"),
403 opt, sctx->service_name, option); 410 opt,
411 sctx->service_name,
412 option);
404 GNUNET_free (opt); 413 GNUNET_free (opt);
405 return GNUNET_SYSERR; 414 return GNUNET_SYSERR;
406 } 415 }
@@ -425,7 +434,7 @@ process_acl6 (struct GNUNET_STRINGS_IPv6NetworkPolicy **ret,
425{ 434{
426 char *opt; 435 char *opt;
427 436
428 if (!GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, option)) 437 if (! GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, option))
429 { 438 {
430 *ret = NULL; 439 *ret = NULL;
431 return GNUNET_OK; 440 return GNUNET_OK;
@@ -433,12 +442,15 @@ process_acl6 (struct GNUNET_STRINGS_IPv6NetworkPolicy **ret,
433 GNUNET_break (GNUNET_OK == 442 GNUNET_break (GNUNET_OK ==
434 GNUNET_CONFIGURATION_get_value_string (sctx->cfg, 443 GNUNET_CONFIGURATION_get_value_string (sctx->cfg,
435 sctx->service_name, 444 sctx->service_name,
436 option, &opt)); 445 option,
446 &opt));
437 if (NULL == (*ret = GNUNET_STRINGS_parse_ipv6_policy (opt))) 447 if (NULL == (*ret = GNUNET_STRINGS_parse_ipv6_policy (opt)))
438 { 448 {
439 LOG (GNUNET_ERROR_TYPE_WARNING, 449 LOG (GNUNET_ERROR_TYPE_WARNING,
440 _("Could not parse IPv6 network specification `%s' for `%s:%s'\n"), 450 _ ("Could not parse IPv6 network specification `%s' for `%s:%s'\n"),
441 opt, sctx->service_name, option); 451 opt,
452 sctx->service_name,
453 option);
442 GNUNET_free (opt); 454 GNUNET_free (opt);
443 return GNUNET_SYSERR; 455 return GNUNET_SYSERR;
444 } 456 }
@@ -507,10 +519,11 @@ add_unixpath (struct sockaddr **saddrs,
507 * set to NULL). 519 * set to NULL).
508 */ 520 */
509int 521int
510LEGACY_SERVICE_get_server_addresses (const char *service_name, 522LEGACY_SERVICE_get_server_addresses (
511 const struct GNUNET_CONFIGURATION_Handle *cfg, 523 const char *service_name,
512 struct sockaddr ***addrs, 524 const struct GNUNET_CONFIGURATION_Handle *cfg,
513 socklen_t ** addr_lens) 525 struct sockaddr ***addrs,
526 socklen_t **addr_lens)
514{ 527{
515 int disablev6; 528 int disablev6;
516 struct GNUNET_NETWORK_Handle *desc; 529 struct GNUNET_NETWORK_Handle *desc;
@@ -534,8 +547,9 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name,
534 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "DISABLEV6")) 547 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "DISABLEV6"))
535 { 548 {
536 if (GNUNET_SYSERR == 549 if (GNUNET_SYSERR ==
537 (disablev6 = 550 (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (cfg,
538 GNUNET_CONFIGURATION_get_value_yesno (cfg, service_name, "DISABLEV6"))) 551 service_name,
552 "DISABLEV6")))
539 return GNUNET_SYSERR; 553 return GNUNET_SYSERR;
540 } 554 }
541 else 555 else
@@ -554,8 +568,10 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name,
554 return GNUNET_SYSERR; 568 return GNUNET_SYSERR;
555 } 569 }
556 LOG (GNUNET_ERROR_TYPE_INFO, 570 LOG (GNUNET_ERROR_TYPE_INFO,
557 _("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), 571 _ (
558 service_name, STRERROR (errno)); 572 "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
573 service_name,
574 strerror (errno));
559 disablev6 = GNUNET_YES; 575 disablev6 = GNUNET_YES;
560 } 576 }
561 else 577 else
@@ -568,18 +584,19 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name,
568 port = 0; 584 port = 0;
569 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT")) 585 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT"))
570 { 586 {
571 if (GNUNET_OK != 587 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
572 GNUNET_CONFIGURATION_get_value_number (cfg, service_name, 588 service_name,
573 "PORT", &port)) 589 "PORT",
590 &port))
574 { 591 {
575 LOG (GNUNET_ERROR_TYPE_ERROR, 592 LOG (GNUNET_ERROR_TYPE_ERROR,
576 _("Require valid port number for service `%s' in configuration!\n"), 593 _ ("Require valid port number for service `%s' in configuration!\n"),
577 service_name); 594 service_name);
578 } 595 }
579 if (port > 65535) 596 if (port > 65535)
580 { 597 {
581 LOG (GNUNET_ERROR_TYPE_ERROR, 598 LOG (GNUNET_ERROR_TYPE_ERROR,
582 _("Require valid port number for service `%s' in configuration!\n"), 599 _ ("Require valid port number for service `%s' in configuration!\n"),
583 service_name); 600 service_name);
584 return GNUNET_SYSERR; 601 return GNUNET_SYSERR;
585 } 602 }
@@ -588,8 +605,10 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name,
588 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO")) 605 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO"))
589 { 606 {
590 GNUNET_break (GNUNET_OK == 607 GNUNET_break (GNUNET_OK ==
591 GNUNET_CONFIGURATION_get_value_string (cfg, service_name, 608 GNUNET_CONFIGURATION_get_value_string (cfg,
592 "BINDTO", &hostname)); 609 service_name,
610 "BINDTO",
611 &hostname));
593 } 612 }
594 else 613 else
595 hostname = NULL; 614 hostname = NULL;
@@ -599,9 +618,10 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name,
599#ifdef AF_UNIX 618#ifdef AF_UNIX
600 if ((GNUNET_YES == 619 if ((GNUNET_YES ==
601 GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) && 620 GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) &&
602 (GNUNET_OK == 621 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg,
603 GNUNET_CONFIGURATION_get_value_filename (cfg, service_name, "UNIXPATH", 622 service_name,
604 &unixpath)) && 623 "UNIXPATH",
624 &unixpath)) &&
605 (0 < strlen (unixpath))) 625 (0 < strlen (unixpath)))
606 { 626 {
607 /* probe UNIX support */ 627 /* probe UNIX support */
@@ -610,12 +630,11 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name,
610 if (strlen (unixpath) >= sizeof (s_un.sun_path)) 630 if (strlen (unixpath) >= sizeof (s_un.sun_path))
611 { 631 {
612 LOG (GNUNET_ERROR_TYPE_WARNING, 632 LOG (GNUNET_ERROR_TYPE_WARNING,
613 _("UNIXPATH `%s' too long, maximum length is %llu\n"), unixpath, 633 _ ("UNIXPATH `%s' too long, maximum length is %llu\n"),
634 unixpath,
614 (unsigned long long) sizeof (s_un.sun_path)); 635 (unsigned long long) sizeof (s_un.sun_path));
615 unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath); 636 unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath);
616 LOG (GNUNET_ERROR_TYPE_INFO, 637 LOG (GNUNET_ERROR_TYPE_INFO, _ ("Using `%s' instead\n"), unixpath);
617 _("Using `%s' instead\n"),
618 unixpath);
619 } 638 }
620#ifdef LINUX 639#ifdef LINUX
621 abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, 640 abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
@@ -624,12 +643,9 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name,
624 if (GNUNET_SYSERR == abstract) 643 if (GNUNET_SYSERR == abstract)
625 abstract = GNUNET_NO; 644 abstract = GNUNET_NO;
626#endif 645#endif
627 if ((GNUNET_YES != abstract) 646 if ((GNUNET_YES != abstract) &&
628 && (GNUNET_OK != 647 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (unixpath)))
629 GNUNET_DISK_directory_create_for_file (unixpath))) 648 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath);
630 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
631 "mkdir",
632 unixpath);
633 } 649 }
634 if (NULL != unixpath) 650 if (NULL != unixpath)
635 { 651 {
@@ -645,9 +661,10 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name,
645 return GNUNET_SYSERR; 661 return GNUNET_SYSERR;
646 } 662 }
647 LOG (GNUNET_ERROR_TYPE_INFO, 663 LOG (GNUNET_ERROR_TYPE_INFO,
648 _("Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), 664 _ (
665 "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
649 service_name, 666 service_name,
650 STRERROR (errno)); 667 strerror (errno));
651 GNUNET_free (unixpath); 668 GNUNET_free (unixpath);
652 unixpath = NULL; 669 unixpath = NULL;
653 } 670 }
@@ -662,7 +679,8 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name,
662 if ((0 == port) && (NULL == unixpath)) 679 if ((0 == port) && (NULL == unixpath))
663 { 680 {
664 LOG (GNUNET_ERROR_TYPE_ERROR, 681 LOG (GNUNET_ERROR_TYPE_ERROR,
665 _("Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), 682 _ (
683 "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
666 service_name); 684 service_name);
667 GNUNET_free_non_null (hostname); 685 GNUNET_free_non_null (hostname);
668 return GNUNET_SYSERR; 686 return GNUNET_SYSERR;
@@ -693,7 +711,7 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name,
693 (NULL == res)) 711 (NULL == res))
694 { 712 {
695 LOG (GNUNET_ERROR_TYPE_ERROR, 713 LOG (GNUNET_ERROR_TYPE_ERROR,
696 _("Failed to resolve `%s': %s\n"), 714 _ ("Failed to resolve `%s': %s\n"),
697 hostname, 715 hostname,
698 gai_strerror (ret)); 716 gai_strerror (ret));
699 GNUNET_free (hostname); 717 GNUNET_free (hostname);
@@ -712,7 +730,7 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name,
712 if (0 == i) 730 if (0 == i)
713 { 731 {
714 LOG (GNUNET_ERROR_TYPE_ERROR, 732 LOG (GNUNET_ERROR_TYPE_ERROR,
715 _("Failed to find %saddress for `%s'.\n"), 733 _ ("Failed to find %saddress for `%s'.\n"),
716 disablev6 ? "IPv4 " : "", 734 disablev6 ? "IPv4 " : "",
717 hostname); 735 hostname);
718 freeaddrinfo (res); 736 freeaddrinfo (res);
@@ -738,11 +756,13 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name,
738 if ((disablev6) && (AF_INET6 == pos->ai_family)) 756 if ((disablev6) && (AF_INET6 == pos->ai_family))
739 continue; 757 continue;
740 if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol)) 758 if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol))
741 continue; /* not TCP */ 759 continue; /* not TCP */
742 if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype)) 760 if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype))
743 continue; /* huh? */ 761 continue; /* huh? */
744 LOG (GNUNET_ERROR_TYPE_DEBUG, "Service `%s' will bind to `%s'\n", 762 LOG (GNUNET_ERROR_TYPE_DEBUG,
745 service_name, GNUNET_a2s (pos->ai_addr, pos->ai_addrlen)); 763 "Service `%s' will bind to `%s'\n",
764 service_name,
765 GNUNET_a2s (pos->ai_addr, pos->ai_addrlen));
746 if (AF_INET == pos->ai_family) 766 if (AF_INET == pos->ai_family)
747 { 767 {
748 GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen); 768 GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen);
@@ -854,7 +874,7 @@ receive_sockets_from_parent (struct LEGACY_SERVICE_Context *sctx)
854 * to create a GNUnet API that boxes a HANDLE (the way it is done with socks) 874 * to create a GNUnet API that boxes a HANDLE (the way it is done with socks)
855 */ 875 */
856 lsocks_pipe = (HANDLE) strtoul (env_buf, NULL, 10); 876 lsocks_pipe = (HANDLE) strtoul (env_buf, NULL, 10);
857 if ( (0 == lsocks_pipe) || (INVALID_HANDLE_VALUE == lsocks_pipe)) 877 if ((0 == lsocks_pipe) || (INVALID_HANDLE_VALUE == lsocks_pipe))
858 return GNUNET_NO; 878 return GNUNET_NO;
859 fail = 1; 879 fail = 1;
860 do 880 do
@@ -867,7 +887,7 @@ receive_sockets_from_parent (struct LEGACY_SERVICE_Context *sctx)
867 if ((0 == ret) || (sizeof (count) != rd) || (0 == count)) 887 if ((0 == ret) || (sizeof (count) != rd) || (0 == count))
868 break; 888 break;
869 sctx->lsocks = 889 sctx->lsocks =
870 GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (count + 1)); 890 GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (count + 1));
871 891
872 fail2 = 1; 892 fail2 = 1;
873 for (i = 0; i < count; i++) 893 for (i = 0; i < count; i++)
@@ -877,12 +897,17 @@ receive_sockets_from_parent (struct LEGACY_SERVICE_Context *sctx)
877 SOCKET s; 897 SOCKET s;
878 898
879 ret = ReadFile (lsocks_pipe, &size, sizeof (size), &rd, NULL); 899 ret = ReadFile (lsocks_pipe, &size, sizeof (size), &rd, NULL);
880 if ( (0 == ret) || (sizeof (size) != rd) || (sizeof (pi) != size) ) 900 if ((0 == ret) || (sizeof (size) != rd) || (sizeof (pi) != size))
881 break; 901 break;
882 ret = ReadFile (lsocks_pipe, &pi, sizeof (pi), &rd, NULL); 902 ret = ReadFile (lsocks_pipe, &pi, sizeof (pi), &rd, NULL);
883 if ( (0 == ret) || (sizeof (pi) != rd)) 903 if ((0 == ret) || (sizeof (pi) != rd))
884 break; 904 break;
885 s = WSASocketA (pi.iAddressFamily, pi.iSocketType, pi.iProtocol, &pi, 0, WSA_FLAG_OVERLAPPED); 905 s = WSASocketA (pi.iAddressFamily,
906 pi.iSocketType,
907 pi.iProtocol,
908 &pi,
909 0,
910 WSA_FLAG_OVERLAPPED);
886 sctx->lsocks[i] = GNUNET_NETWORK_socket_box_native (s); 911 sctx->lsocks[i] = GNUNET_NETWORK_socket_box_native (s);
887 if (NULL == sctx->lsocks[i]) 912 if (NULL == sctx->lsocks[i])
888 break; 913 break;
@@ -893,15 +918,14 @@ receive_sockets_from_parent (struct LEGACY_SERVICE_Context *sctx)
893 break; 918 break;
894 sctx->lsocks[count] = NULL; 919 sctx->lsocks[count] = NULL;
895 fail = 0; 920 fail = 0;
896 } 921 } while (fail);
897 while (fail);
898 922
899 CloseHandle (lsocks_pipe); 923 CloseHandle (lsocks_pipe);
900 924
901 if (fail) 925 if (fail)
902 { 926 {
903 LOG (GNUNET_ERROR_TYPE_ERROR, 927 LOG (GNUNET_ERROR_TYPE_ERROR,
904 _("Could not access a pre-bound socket, will try to bind myself\n")); 928 _ ("Could not access a pre-bound socket, will try to bind myself\n"));
905 for (i = 0; (i < count) && (NULL != sctx->lsocks[i]); i++) 929 for (i = 0; (i < count) && (NULL != sctx->lsocks[i]); i++)
906 GNUNET_break (0 == GNUNET_NETWORK_socket_close (sctx->lsocks[i])); 930 GNUNET_break (0 == GNUNET_NETWORK_socket_close (sctx->lsocks[i]));
907 GNUNET_free_non_null (sctx->lsocks); 931 GNUNET_free_non_null (sctx->lsocks);
@@ -943,15 +967,19 @@ setup_service (struct LEGACY_SERVICE_Context *sctx)
943 int flags; 967 int flags;
944#endif 968#endif
945 969
946 if (GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, "TIMEOUT")) 970 if (GNUNET_CONFIGURATION_have_value (sctx->cfg,
971 sctx->service_name,
972 "TIMEOUT"))
947 { 973 {
948 if (GNUNET_OK != 974 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (sctx->cfg,
949 GNUNET_CONFIGURATION_get_value_time (sctx->cfg, sctx->service_name, 975 sctx->service_name,
950 "TIMEOUT", &idleout)) 976 "TIMEOUT",
977 &idleout))
951 { 978 {
952 LOG (GNUNET_ERROR_TYPE_ERROR, 979 LOG (GNUNET_ERROR_TYPE_ERROR,
953 _("Specified value for `%s' of service `%s' is invalid\n"), 980 _ ("Specified value for `%s' of service `%s' is invalid\n"),
954 "TIMEOUT", sctx->service_name); 981 "TIMEOUT",
982 sctx->service_name);
955 return GNUNET_SYSERR; 983 return GNUNET_SYSERR;
956 } 984 }
957 sctx->timeout = idleout; 985 sctx->timeout = idleout;
@@ -959,17 +987,19 @@ setup_service (struct LEGACY_SERVICE_Context *sctx)
959 else 987 else
960 sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; 988 sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
961 989
962 if (GNUNET_CONFIGURATION_have_value 990 if (GNUNET_CONFIGURATION_have_value (sctx->cfg,
963 (sctx->cfg, sctx->service_name, "TOLERANT")) 991 sctx->service_name,
992 "TOLERANT"))
964 { 993 {
965 if (GNUNET_SYSERR == 994 if (GNUNET_SYSERR ==
966 (tolerant = 995 (tolerant = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg,
967 GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->service_name, 996 sctx->service_name,
968 "TOLERANT"))) 997 "TOLERANT")))
969 { 998 {
970 LOG (GNUNET_ERROR_TYPE_ERROR, 999 LOG (GNUNET_ERROR_TYPE_ERROR,
971 _("Specified value for `%s' of service `%s' is invalid\n"), 1000 _ ("Specified value for `%s' of service `%s' is invalid\n"),
972 "TOLERANT", sctx->service_name); 1001 "TOLERANT",
1002 sctx->service_name);
973 return GNUNET_SYSERR; 1003 return GNUNET_SYSERR;
974 } 1004 }
975 } 1005 }
@@ -979,11 +1009,11 @@ setup_service (struct LEGACY_SERVICE_Context *sctx)
979#ifndef MINGW 1009#ifndef MINGW
980 errno = 0; 1010 errno = 0;
981 if ((NULL != (nfds = getenv ("LISTEN_FDS"))) && 1011 if ((NULL != (nfds = getenv ("LISTEN_FDS"))) &&
982 (1 == SSCANF (nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) && 1012 (1 == sscanf (nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) &&
983 (cnt + 4 < FD_SETSIZE)) 1013 (cnt + 4 < FD_SETSIZE))
984 { 1014 {
985 sctx->lsocks = 1015 sctx->lsocks =
986 GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (cnt + 1)); 1016 GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (cnt + 1));
987 while (0 < cnt--) 1017 while (0 < cnt--)
988 { 1018 {
989 flags = fcntl (3 + cnt, F_GETFD); 1019 flags = fcntl (3 + cnt, F_GETFD);
@@ -992,8 +1022,8 @@ setup_service (struct LEGACY_SERVICE_Context *sctx)
992 (sctx->lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt)))) 1022 (sctx->lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt))))
993 { 1023 {
994 LOG (GNUNET_ERROR_TYPE_ERROR, 1024 LOG (GNUNET_ERROR_TYPE_ERROR,
995 _ 1025 _ (
996 ("Could not access pre-bound socket %u, will try to bind myself\n"), 1026 "Could not access pre-bound socket %u, will try to bind myself\n"),
997 (unsigned int) 3 + cnt); 1027 (unsigned int) 3 + cnt);
998 cnt++; 1028 cnt++;
999 while (sctx->lsocks[cnt] != NULL) 1029 while (sctx->lsocks[cnt] != NULL)
@@ -1014,17 +1044,18 @@ setup_service (struct LEGACY_SERVICE_Context *sctx)
1014#endif 1044#endif
1015 1045
1016 if ((NULL == sctx->lsocks) && 1046 if ((NULL == sctx->lsocks) &&
1017 (GNUNET_SYSERR == 1047 (GNUNET_SYSERR == LEGACY_SERVICE_get_server_addresses (sctx->service_name,
1018 LEGACY_SERVICE_get_server_addresses (sctx->service_name, sctx->cfg, 1048 sctx->cfg,
1019 &sctx->addrs, &sctx->addrlens))) 1049 &sctx->addrs,
1050 &sctx->addrlens)))
1020 return GNUNET_SYSERR; 1051 return GNUNET_SYSERR;
1021 sctx->require_found = tolerant ? GNUNET_NO : GNUNET_YES; 1052 sctx->require_found = tolerant ? GNUNET_NO : GNUNET_YES;
1022 sctx->match_uid = 1053 sctx->match_uid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg,
1023 GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->service_name, 1054 sctx->service_name,
1024 "UNIX_MATCH_UID"); 1055 "UNIX_MATCH_UID");
1025 sctx->match_gid = 1056 sctx->match_gid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg,
1026 GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->service_name, 1057 sctx->service_name,
1027 "UNIX_MATCH_GID"); 1058 "UNIX_MATCH_GID");
1028 process_acl4 (&sctx->v4_denied, sctx, "REJECT_FROM"); 1059 process_acl4 (&sctx->v4_denied, sctx, "REJECT_FROM");
1029 process_acl4 (&sctx->v4_allowed, sctx, "ACCEPT_FROM"); 1060 process_acl4 (&sctx->v4_allowed, sctx, "ACCEPT_FROM");
1030 process_acl6 (&sctx->v6_denied, sctx, "REJECT_FROM6"); 1061 process_acl6 (&sctx->v6_denied, sctx, "REJECT_FROM6");
@@ -1046,9 +1077,10 @@ get_user_name (struct LEGACY_SERVICE_Context *sctx)
1046{ 1077{
1047 char *un; 1078 char *un;
1048 1079
1049 if (GNUNET_OK != 1080 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (sctx->cfg,
1050 GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, sctx->service_name, 1081 sctx->service_name,
1051 "USERNAME", &un)) 1082 "USERNAME",
1083 &un))
1052 return NULL; 1084 return NULL;
1053 return un; 1085 return un;
1054} 1086}
@@ -1071,14 +1103,14 @@ write_pid_file (struct LEGACY_SERVICE_Context *sctx, pid_t pid)
1071 int len; 1103 int len;
1072 1104
1073 if (NULL == (pif = get_pid_file_name (sctx))) 1105 if (NULL == (pif = get_pid_file_name (sctx)))
1074 return GNUNET_OK; /* no file desired */ 1106 return GNUNET_OK; /* no file desired */
1075 user = get_user_name (sctx); 1107 user = get_user_name (sctx);
1076 rdir = GNUNET_strdup (pif); 1108 rdir = GNUNET_strdup (pif);
1077 len = strlen (rdir); 1109 len = strlen (rdir);
1078 while ((len > 0) && (rdir[len] != DIR_SEPARATOR)) 1110 while ((len > 0) && (rdir[len] != DIR_SEPARATOR))
1079 len--; 1111 len--;
1080 rdir[len] = '\0'; 1112 rdir[len] = '\0';
1081 if (0 != ACCESS (rdir, F_OK)) 1113 if (0 != access (rdir, F_OK))
1082 { 1114 {
1083 /* we get to create a directory -- and claim it 1115 /* we get to create a directory -- and claim it
1084 * as ours! */ 1116 * as ours! */
@@ -1086,7 +1118,7 @@ write_pid_file (struct LEGACY_SERVICE_Context *sctx, pid_t pid)
1086 if ((NULL != user) && (0 < strlen (user))) 1118 if ((NULL != user) && (0 < strlen (user)))
1087 GNUNET_DISK_file_change_owner (rdir, user); 1119 GNUNET_DISK_file_change_owner (rdir, user);
1088 } 1120 }
1089 if (0 != ACCESS (rdir, W_OK | X_OK)) 1121 if (0 != access (rdir, W_OK | X_OK))
1090 { 1122 {
1091 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", rdir); 1123 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", rdir);
1092 GNUNET_free (rdir); 1124 GNUNET_free (rdir);
@@ -1095,7 +1127,7 @@ write_pid_file (struct LEGACY_SERVICE_Context *sctx, pid_t pid)
1095 return GNUNET_SYSERR; 1127 return GNUNET_SYSERR;
1096 } 1128 }
1097 GNUNET_free (rdir); 1129 GNUNET_free (rdir);
1098 pidfd = FOPEN (pif, "w"); 1130 pidfd = fopen (pif, "w");
1099 if (NULL == pidfd) 1131 if (NULL == pidfd)
1100 { 1132 {
1101 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "fopen", pif); 1133 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "fopen", pif);
@@ -1103,9 +1135,9 @@ write_pid_file (struct LEGACY_SERVICE_Context *sctx, pid_t pid)
1103 GNUNET_free_non_null (user); 1135 GNUNET_free_non_null (user);
1104 return GNUNET_SYSERR; 1136 return GNUNET_SYSERR;
1105 } 1137 }
1106 if (0 > FPRINTF (pidfd, "%u", pid)) 1138 if (0 > fprintf (pidfd, "%u", pid))
1107 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", pif); 1139 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", pif);
1108 GNUNET_break (0 == FCLOSE (pidfd)); 1140 GNUNET_break (0 == fclose (pidfd));
1109 if ((NULL != user) && (0 < strlen (user))) 1141 if ((NULL != user) && (0 < strlen (user)))
1110 GNUNET_DISK_file_change_owner (pif, user); 1142 GNUNET_DISK_file_change_owner (pif, user);
1111 GNUNET_free_non_null (user); 1143 GNUNET_free_non_null (user);
@@ -1146,29 +1178,37 @@ service_task (void *cls)
1146 1178
1147 GNUNET_RESOLVER_connect (sctx->cfg); 1179 GNUNET_RESOLVER_connect (sctx->cfg);
1148 if (NULL != sctx->lsocks) 1180 if (NULL != sctx->lsocks)
1149 sctx->server 1181 sctx->server = GNUNET_SERVER_create_with_sockets (&check_access,
1150 = GNUNET_SERVER_create_with_sockets (&check_access, sctx, sctx->lsocks, 1182 sctx,
1151 sctx->timeout, sctx->require_found); 1183 sctx->lsocks,
1184 sctx->timeout,
1185 sctx->require_found);
1152 else 1186 else
1153 sctx->server 1187 sctx->server = GNUNET_SERVER_create (&check_access,
1154 = GNUNET_SERVER_create (&check_access, sctx, sctx->addrs, sctx->addrlens, 1188 sctx,
1155 sctx->timeout, sctx->require_found); 1189 sctx->addrs,
1190 sctx->addrlens,
1191 sctx->timeout,
1192 sctx->require_found);
1156 if (NULL == sctx->server) 1193 if (NULL == sctx->server)
1157 { 1194 {
1158 if (NULL != sctx->addrs) 1195 if (NULL != sctx->addrs)
1159 for (i = 0; NULL != sctx->addrs[i]; i++) 1196 for (i = 0; NULL != sctx->addrs[i]; i++)
1160 LOG (GNUNET_ERROR_TYPE_INFO, 1197 LOG (GNUNET_ERROR_TYPE_INFO,
1161 _("Failed to start `%s' at `%s'\n"), 1198 _ ("Failed to start `%s' at `%s'\n"),
1162 sctx->service_name, GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i])); 1199 sctx->service_name,
1200 GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
1163 sctx->ret = GNUNET_SYSERR; 1201 sctx->ret = GNUNET_SYSERR;
1164 return; 1202 return;
1165 } 1203 }
1166#ifndef WINDOWS 1204#ifndef WINDOWS
1167 if (NULL != sctx->addrs) 1205 if (NULL != sctx->addrs)
1168 for (i = 0; NULL != sctx->addrs[i]; i++) 1206 for (i = 0; NULL != sctx->addrs[i]; i++)
1169 if ((AF_UNIX == sctx->addrs[i]->sa_family) 1207 if ((AF_UNIX == sctx->addrs[i]->sa_family) &&
1170 && ('\0' != ((const struct sockaddr_un *)sctx->addrs[i])->sun_path[0])) 1208 ('\0' != ((const struct sockaddr_un *) sctx->addrs[i])->sun_path[0]))
1171 GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)sctx->addrs[i])->sun_path, 1209 GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)
1210 sctx->addrs[i])
1211 ->sun_path,
1172 sctx->match_uid, 1212 sctx->match_uid,
1173 sctx->match_gid); 1213 sctx->match_gid);
1174#endif 1214#endif
@@ -1178,8 +1218,7 @@ service_task (void *cls)
1178 { 1218 {
1179 /* install a task that will kill the server 1219 /* install a task that will kill the server
1180 * process if the scheduler ever gets a shutdown signal */ 1220 * process if the scheduler ever gets a shutdown signal */
1181 sctx->shutdown_task = GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 1221 sctx->shutdown_task = GNUNET_SCHEDULER_add_shutdown (&shutdown_task, sctx);
1182 sctx);
1183 } 1222 }
1184 sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers)); 1223 sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers));
1185 GNUNET_memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers)); 1224 GNUNET_memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers));
@@ -1189,8 +1228,8 @@ service_task (void *cls)
1189 GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers); 1228 GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers);
1190 if (-1 != sctx->ready_confirm_fd) 1229 if (-1 != sctx->ready_confirm_fd)
1191 { 1230 {
1192 GNUNET_break (1 == WRITE (sctx->ready_confirm_fd, ".", 1)); 1231 GNUNET_break (1 == write (sctx->ready_confirm_fd, ".", 1));
1193 GNUNET_break (0 == CLOSE (sctx->ready_confirm_fd)); 1232 GNUNET_break (0 == close (sctx->ready_confirm_fd));
1194 sctx->ready_confirm_fd = -1; 1233 sctx->ready_confirm_fd = -1;
1195 write_pid_file (sctx, getpid ()); 1234 write_pid_file (sctx, getpid ());
1196 } 1235 }
@@ -1199,8 +1238,10 @@ service_task (void *cls)
1199 i = 0; 1238 i = 0;
1200 while (NULL != sctx->addrs[i]) 1239 while (NULL != sctx->addrs[i])
1201 { 1240 {
1202 LOG (GNUNET_ERROR_TYPE_INFO, _("Service `%s' runs at %s\n"), 1241 LOG (GNUNET_ERROR_TYPE_INFO,
1203 sctx->service_name, GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i])); 1242 _ ("Service `%s' runs at %s\n"),
1243 sctx->service_name,
1244 GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
1204 i++; 1245 i++;
1205 } 1246 }
1206 } 1247 }
@@ -1222,7 +1263,7 @@ detach_terminal (struct LEGACY_SERVICE_Context *sctx)
1222 int nullfd; 1263 int nullfd;
1223 int filedes[2]; 1264 int filedes[2];
1224 1265
1225 if (0 != PIPE (filedes)) 1266 if (0 != pipe (filedes))
1226 { 1267 {
1227 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe"); 1268 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe");
1228 return GNUNET_SYSERR; 1269 return GNUNET_SYSERR;
@@ -1238,9 +1279,9 @@ detach_terminal (struct LEGACY_SERVICE_Context *sctx)
1238 /* Parent */ 1279 /* Parent */
1239 char c; 1280 char c;
1240 1281
1241 GNUNET_break (0 == CLOSE (filedes[1])); 1282 GNUNET_break (0 == close (filedes[1]));
1242 c = 'X'; 1283 c = 'X';
1243 if (1 != READ (filedes[0], &c, sizeof (char))) 1284 if (1 != read (filedes[0], &c, sizeof (char)))
1244 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "read"); 1285 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "read");
1245 fflush (stdout); 1286 fflush (stdout);
1246 switch (c) 1287 switch (c)
@@ -1248,33 +1289,34 @@ detach_terminal (struct LEGACY_SERVICE_Context *sctx)
1248 case '.': 1289 case '.':
1249 exit (0); 1290 exit (0);
1250 case 'I': 1291 case 'I':
1251 LOG (GNUNET_ERROR_TYPE_INFO, _("Service process failed to initialize\n")); 1292 LOG (GNUNET_ERROR_TYPE_INFO,
1293 _ ("Service process failed to initialize\n"));
1252 break; 1294 break;
1253 case 'S': 1295 case 'S':
1254 LOG (GNUNET_ERROR_TYPE_INFO, 1296 LOG (GNUNET_ERROR_TYPE_INFO,
1255 _("Service process could not initialize server function\n")); 1297 _ ("Service process could not initialize server function\n"));
1256 break; 1298 break;
1257 case 'X': 1299 case 'X':
1258 LOG (GNUNET_ERROR_TYPE_INFO, 1300 LOG (GNUNET_ERROR_TYPE_INFO,
1259 _("Service process failed to report status\n")); 1301 _ ("Service process failed to report status\n"));
1260 break; 1302 break;
1261 } 1303 }
1262 exit (1); /* child reported error */ 1304 exit (1); /* child reported error */
1263 } 1305 }
1264 GNUNET_break (0 == CLOSE (0)); 1306 GNUNET_break (0 == close (0));
1265 GNUNET_break (0 == CLOSE (1)); 1307 GNUNET_break (0 == close (1));
1266 GNUNET_break (0 == CLOSE (filedes[0])); 1308 GNUNET_break (0 == close (filedes[0]));
1267 nullfd = OPEN ("/dev/null", O_RDWR | O_APPEND); 1309 nullfd = open ("/dev/null", O_RDWR | O_APPEND);
1268 if (nullfd < 0) 1310 if (nullfd < 0)
1269 return GNUNET_SYSERR; 1311 return GNUNET_SYSERR;
1270 /* set stdin/stdout to /dev/null */ 1312 /* set stdin/stdout to /dev/null */
1271 if ((dup2 (nullfd, 0) < 0) || (dup2 (nullfd, 1) < 0)) 1313 if ((dup2 (nullfd, 0) < 0) || (dup2 (nullfd, 1) < 0))
1272 { 1314 {
1273 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2"); 1315 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
1274 (void) CLOSE (nullfd); 1316 (void) close (nullfd);
1275 return GNUNET_SYSERR; 1317 return GNUNET_SYSERR;
1276 } 1318 }
1277 (void) CLOSE (nullfd); 1319 (void) close (nullfd);
1278 /* Detach from controlling terminal */ 1320 /* Detach from controlling terminal */
1279 pid = setsid (); 1321 pid = setsid ();
1280 if (-1 == pid) 1322 if (-1 == pid)
@@ -1301,7 +1343,7 @@ set_user_id (struct LEGACY_SERVICE_Context *sctx)
1301 char *user; 1343 char *user;
1302 1344
1303 if (NULL == (user = get_user_name (sctx))) 1345 if (NULL == (user = get_user_name (sctx)))
1304 return GNUNET_OK; /* keep */ 1346 return GNUNET_OK; /* keep */
1305#ifndef MINGW 1347#ifndef MINGW
1306 struct passwd *pws; 1348 struct passwd *pws;
1307 1349
@@ -1310,8 +1352,9 @@ set_user_id (struct LEGACY_SERVICE_Context *sctx)
1310 if (NULL == pws) 1352 if (NULL == pws)
1311 { 1353 {
1312 LOG (GNUNET_ERROR_TYPE_ERROR, 1354 LOG (GNUNET_ERROR_TYPE_ERROR,
1313 _("Cannot obtain information about user `%s': %s\n"), user, 1355 _ ("Cannot obtain information about user `%s': %s\n"),
1314 errno == 0 ? _("No such user") : STRERROR (errno)); 1356 user,
1357 errno == 0 ? _ ("No such user") : strerror (errno));
1315 GNUNET_free (user); 1358 GNUNET_free (user);
1316 return GNUNET_SYSERR; 1359 return GNUNET_SYSERR;
1317 } 1360 }
@@ -1324,8 +1367,10 @@ set_user_id (struct LEGACY_SERVICE_Context *sctx)
1324 if ((0 != setregid (pws->pw_gid, pws->pw_gid)) || 1367 if ((0 != setregid (pws->pw_gid, pws->pw_gid)) ||
1325 (0 != setreuid (pws->pw_uid, pws->pw_uid))) 1368 (0 != setreuid (pws->pw_uid, pws->pw_uid)))
1326 { 1369 {
1327 LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot change user/group to `%s': %s\n"), 1370 LOG (GNUNET_ERROR_TYPE_ERROR,
1328 user, STRERROR (errno)); 1371 _ ("Cannot change user/group to `%s': %s\n"),
1372 user,
1373 strerror (errno));
1329 GNUNET_free (user); 1374 GNUNET_free (user);
1330 return GNUNET_SYSERR; 1375 return GNUNET_SYSERR;
1331 } 1376 }
@@ -1347,8 +1392,8 @@ pid_file_delete (struct LEGACY_SERVICE_Context *sctx)
1347 char *pif = get_pid_file_name (sctx); 1392 char *pif = get_pid_file_name (sctx);
1348 1393
1349 if (NULL == pif) 1394 if (NULL == pif)
1350 return; /* no PID file */ 1395 return; /* no PID file */
1351 if (0 != UNLINK (pif)) 1396 if (0 != unlink (pif))
1352 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", pif); 1397 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", pif);
1353 GNUNET_free (pif); 1398 GNUNET_free (pif);
1354} 1399}
@@ -1368,13 +1413,19 @@ pid_file_delete (struct LEGACY_SERVICE_Context *sctx)
1368 * if we shutdown nicely 1413 * if we shutdown nicely
1369 */ 1414 */
1370int 1415int
1371LEGACY_SERVICE_run (int argc, char *const *argv, 1416LEGACY_SERVICE_run (int argc,
1417 char *const *argv,
1372 const char *service_name, 1418 const char *service_name,
1373 enum LEGACY_SERVICE_Options options, 1419 enum LEGACY_SERVICE_Options options,
1374 LEGACY_SERVICE_Main task, 1420 LEGACY_SERVICE_Main task,
1375 void *task_cls) 1421 void *task_cls)
1376{ 1422{
1377#define HANDLE_ERROR do { GNUNET_break (0); goto shutdown; } while (0) 1423#define HANDLE_ERROR \
1424 do \
1425 { \
1426 GNUNET_break (0); \
1427 goto shutdown; \
1428 } while (0)
1378 1429
1379 int err; 1430 int err;
1380 int ret; 1431 int ret;
@@ -1391,18 +1442,18 @@ LEGACY_SERVICE_run (int argc, char *const *argv,
1391 struct GNUNET_CONFIGURATION_Handle *cfg; 1442 struct GNUNET_CONFIGURATION_Handle *cfg;
1392 const char *xdg; 1443 const char *xdg;
1393 1444
1394 struct GNUNET_GETOPT_CommandLineOption service_options[] = { 1445 struct GNUNET_GETOPT_CommandLineOption service_options[] =
1395 GNUNET_GETOPT_option_cfgfile (&opt_cfg_fn), 1446 {GNUNET_GETOPT_option_cfgfile (&opt_cfg_fn),
1396 GNUNET_GETOPT_option_flag ('d', 1447 GNUNET_GETOPT_option_flag ('d',
1397 "daemonize", 1448 "daemonize",
1398 gettext_noop ("do daemonize (detach from terminal)"), 1449 gettext_noop (
1399 &do_daemonize), 1450 "do daemonize (detach from terminal)"),
1400 GNUNET_GETOPT_option_help (NULL), 1451 &do_daemonize),
1401 GNUNET_GETOPT_option_loglevel (&loglev), 1452 GNUNET_GETOPT_option_help (NULL),
1402 GNUNET_GETOPT_option_logfile (&logfile), 1453 GNUNET_GETOPT_option_loglevel (&loglev),
1403 GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION), 1454 GNUNET_GETOPT_option_logfile (&logfile),
1404 GNUNET_GETOPT_OPTION_END 1455 GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
1405 }; 1456 GNUNET_GETOPT_OPTION_END};
1406 err = 1; 1457 err = 1;
1407 do_daemonize = 0; 1458 do_daemonize = 0;
1408 logfile = NULL; 1459 logfile = NULL;
@@ -1445,7 +1496,7 @@ LEGACY_SERVICE_run (int argc, char *const *argv,
1445 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, opt_cfg_fn)) 1496 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, opt_cfg_fn))
1446 { 1497 {
1447 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1498 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1448 _("Malformed configuration file `%s', exit ...\n"), 1499 _ ("Malformed configuration file `%s', exit ...\n"),
1449 opt_cfg_fn); 1500 opt_cfg_fn);
1450 goto shutdown; 1501 goto shutdown;
1451 } 1502 }
@@ -1455,13 +1506,13 @@ LEGACY_SERVICE_run (int argc, char *const *argv,
1455 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, NULL)) 1506 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, NULL))
1456 { 1507 {
1457 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1508 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1458 _("Malformed configuration, exit ...\n")); 1509 _ ("Malformed configuration, exit ...\n"));
1459 goto shutdown; 1510 goto shutdown;
1460 } 1511 }
1461 if (0 != strcmp (opt_cfg_fn, cfg_fn)) 1512 if (0 != strcmp (opt_cfg_fn, cfg_fn))
1462 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1513 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1463 _("Could not access configuration file `%s'\n"), 1514 _ ("Could not access configuration file `%s'\n"),
1464 opt_cfg_fn); 1515 opt_cfg_fn);
1465 } 1516 }
1466 if (GNUNET_OK != setup_service (&sctx)) 1517 if (GNUNET_OK != setup_service (&sctx))
1467 goto shutdown; 1518 goto shutdown;
@@ -1473,12 +1524,14 @@ LEGACY_SERVICE_run (int argc, char *const *argv,
1473 "Service `%s' runs with configuration from `%s'\n", 1524 "Service `%s' runs with configuration from `%s'\n",
1474 service_name, 1525 service_name,
1475 opt_cfg_fn); 1526 opt_cfg_fn);
1476 if ((GNUNET_OK == 1527 if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sctx.cfg,
1477 GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "TESTING", 1528 "TESTING",
1478 "SKEW_OFFSET", &skew_offset)) && 1529 "SKEW_OFFSET",
1479 (GNUNET_OK == 1530 &skew_offset)) &&
1480 GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "TESTING", 1531 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sctx.cfg,
1481 "SKEW_VARIANCE", &skew_variance))) 1532 "TESTING",
1533 "SKEW_VARIANCE",
1534 &skew_variance)))
1482 { 1535 {
1483 clock_offset = skew_offset - skew_variance; 1536 clock_offset = skew_offset - skew_variance;
1484 GNUNET_TIME_set_offset (clock_offset); 1537 GNUNET_TIME_set_offset (clock_offset);
@@ -1495,21 +1548,21 @@ LEGACY_SERVICE_run (int argc, char *const *argv,
1495shutdown: 1548shutdown:
1496 if (-1 != sctx.ready_confirm_fd) 1549 if (-1 != sctx.ready_confirm_fd)
1497 { 1550 {
1498 if (1 != WRITE (sctx.ready_confirm_fd, err ? "I" : "S", 1)) 1551 if (1 != write (sctx.ready_confirm_fd, err ? "I" : "S", 1))
1499 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "write"); 1552 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "write");
1500 GNUNET_break (0 == CLOSE (sctx.ready_confirm_fd)); 1553 GNUNET_break (0 == close (sctx.ready_confirm_fd));
1501 } 1554 }
1502#if HAVE_MALLINFO 1555#if HAVE_MALLINFO
1503 { 1556 {
1504 char *counter; 1557 char *counter;
1505 1558
1506 if ( (GNUNET_YES == 1559 if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (sctx.cfg,
1507 GNUNET_CONFIGURATION_have_value (sctx.cfg, service_name, 1560 service_name,
1508 "GAUGER_HEAP")) && 1561 "GAUGER_HEAP")) &&
1509 (GNUNET_OK == 1562 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (sctx.cfg,
1510 GNUNET_CONFIGURATION_get_value_string (sctx.cfg, service_name, 1563 service_name,
1511 "GAUGER_HEAP", 1564 "GAUGER_HEAP",
1512 &counter)) ) 1565 &counter)))
1513 { 1566 {
1514 struct mallinfo mi; 1567 struct mallinfo mi;
1515 1568
@@ -1551,13 +1604,13 @@ shutdown:
1551struct LEGACY_SERVICE_Context * 1604struct LEGACY_SERVICE_Context *
1552LEGACY_SERVICE_start (const char *service_name, 1605LEGACY_SERVICE_start (const char *service_name,
1553 const struct GNUNET_CONFIGURATION_Handle *cfg, 1606 const struct GNUNET_CONFIGURATION_Handle *cfg,
1554 enum LEGACY_SERVICE_Options options) 1607 enum LEGACY_SERVICE_Options options)
1555{ 1608{
1556 int i; 1609 int i;
1557 struct LEGACY_SERVICE_Context *sctx; 1610 struct LEGACY_SERVICE_Context *sctx;
1558 1611
1559 sctx = GNUNET_new (struct LEGACY_SERVICE_Context); 1612 sctx = GNUNET_new (struct LEGACY_SERVICE_Context);
1560 sctx->ready_confirm_fd = -1; /* no daemonizing */ 1613 sctx->ready_confirm_fd = -1; /* no daemonizing */
1561 sctx->ret = GNUNET_OK; 1614 sctx->ret = GNUNET_OK;
1562 sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; 1615 sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
1563 sctx->service_name = service_name; 1616 sctx->service_name = service_name;
@@ -1571,13 +1624,18 @@ LEGACY_SERVICE_start (const char *service_name,
1571 return NULL; 1624 return NULL;
1572 } 1625 }
1573 if (NULL != sctx->lsocks) 1626 if (NULL != sctx->lsocks)
1574 sctx->server = 1627 sctx->server = GNUNET_SERVER_create_with_sockets (&check_access,
1575 GNUNET_SERVER_create_with_sockets (&check_access, sctx, sctx->lsocks, 1628 sctx,
1576 sctx->timeout, sctx->require_found); 1629 sctx->lsocks,
1630 sctx->timeout,
1631 sctx->require_found);
1577 else 1632 else
1578 sctx->server = 1633 sctx->server = GNUNET_SERVER_create (&check_access,
1579 GNUNET_SERVER_create (&check_access, sctx, sctx->addrs, sctx->addrlens, 1634 sctx,
1580 sctx->timeout, sctx->require_found); 1635 sctx->addrs,
1636 sctx->addrlens,
1637 sctx->timeout,
1638 sctx->require_found);
1581 1639
1582 if (NULL == sctx->server) 1640 if (NULL == sctx->server)
1583 { 1641 {
@@ -1587,9 +1645,11 @@ LEGACY_SERVICE_start (const char *service_name,
1587#ifndef WINDOWS 1645#ifndef WINDOWS
1588 if (NULL != sctx->addrs) 1646 if (NULL != sctx->addrs)
1589 for (i = 0; NULL != sctx->addrs[i]; i++) 1647 for (i = 0; NULL != sctx->addrs[i]; i++)
1590 if ((AF_UNIX == sctx->addrs[i]->sa_family) 1648 if ((AF_UNIX == sctx->addrs[i]->sa_family) &&
1591 && ('\0' != ((const struct sockaddr_un *)sctx->addrs[i])->sun_path[0])) 1649 ('\0' != ((const struct sockaddr_un *) sctx->addrs[i])->sun_path[0]))
1592 GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)sctx->addrs[i])->sun_path, 1650 GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)
1651 sctx->addrs[i])
1652 ->sun_path,
1593 sctx->match_uid, 1653 sctx->match_uid,
1594 sctx->match_gid); 1654 sctx->match_gid);
1595#endif 1655#endif
@@ -1624,7 +1684,7 @@ LEGACY_SERVICE_get_server (struct LEGACY_SERVICE_Context *ctx)
1624 * @return NULL if there are no listen sockets, otherwise NULL-terminated 1684 * @return NULL if there are no listen sockets, otherwise NULL-terminated
1625 * array of listen sockets. 1685 * array of listen sockets.
1626 */ 1686 */
1627struct GNUNET_NETWORK_Handle *const* 1687struct GNUNET_NETWORK_Handle *const *
1628LEGACY_SERVICE_get_listen_sockets (struct LEGACY_SERVICE_Context *ctx) 1688LEGACY_SERVICE_get_listen_sockets (struct LEGACY_SERVICE_Context *ctx)
1629{ 1689{
1630 return ctx->lsocks; 1690 return ctx->lsocks;
@@ -1645,13 +1705,13 @@ LEGACY_SERVICE_stop (struct LEGACY_SERVICE_Context *sctx)
1645 { 1705 {
1646 char *counter; 1706 char *counter;
1647 1707
1648 if ( (GNUNET_YES == 1708 if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (sctx->cfg,
1649 GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, 1709 sctx->service_name,
1650 "GAUGER_HEAP")) && 1710 "GAUGER_HEAP")) &&
1651 (GNUNET_OK == 1711 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (sctx->cfg,
1652 GNUNET_CONFIGURATION_get_value_string (sctx->cfg, sctx->service_name, 1712 sctx->service_name,
1653 "GAUGER_HEAP", 1713 "GAUGER_HEAP",
1654 &counter)) ) 1714 &counter)))
1655 { 1715 {
1656 struct mallinfo mi; 1716 struct mallinfo mi;
1657 1717
diff --git a/src/transport/test_plugin_hostkey b/src/transport/test_plugin_hostkey
index 13f1dc9b3..e7b1ad012 100644
--- a/src/transport/test_plugin_hostkey
+++ b/src/transport/test_plugin_hostkey
Binary files differ
diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c
index 0c94fa5c9..2c6ce8e5f 100644
--- a/src/transport/test_quota_compliance.c
+++ b/src/transport/test_quota_compliance.c
@@ -71,7 +71,7 @@ report ()
71 delta = 1; 71 delta = 1;
72 datarate = (total_bytes_recv * 1000 * 1000) / delta; 72 datarate = (total_bytes_recv * 1000 * 1000) / delta;
73 73
74 FPRINTF (stderr, 74 fprintf (stderr,
75 "Throughput was %llu b/s\n", 75 "Throughput was %llu b/s\n",
76 datarate); 76 datarate);
77 ccc->global_ret = GNUNET_OK; 77 ccc->global_ret = GNUNET_OK;
@@ -160,11 +160,11 @@ measure (void *cls)
160 counter++; 160 counter++;
161 if ((DURATION.rel_value_us / 1000 / 1000LL) < counter) 161 if ((DURATION.rel_value_us / 1000 / 1000LL) < counter)
162 { 162 {
163 FPRINTF (stderr, "%s", ".\n"); 163 fprintf (stderr, "%s", ".\n");
164 GNUNET_SCHEDULER_shutdown (); 164 GNUNET_SCHEDULER_shutdown ();
165 return; 165 return;
166 } 166 }
167 FPRINTF (stderr, "%s", "."); 167 fprintf (stderr, "%s", ".");
168 measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 168 measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
169 &measure, 169 &measure,
170 NULL); 170 NULL);
diff --git a/src/transport/test_transport_address_switch.c b/src/transport/test_transport_address_switch.c
index 98f1170ff..4cc63766e 100644
--- a/src/transport/test_transport_address_switch.c
+++ b/src/transport/test_transport_address_switch.c
@@ -217,10 +217,10 @@ custom_shutdown (void *cls)
217 } 217 }
218 218
219 result = 0; 219 result = 0;
220 FPRINTF (stderr, "\n"); 220 fprintf (stderr, "\n");
221 if (stats[0].switch_attempts > 0) 221 if (stats[0].switch_attempts > 0)
222 { 222 {
223 FPRINTF ( 223 fprintf (
224 stderr, 224 stderr,
225 "Peer 1 tried %u times to switch and succeeded %u times, failed %u times\n", 225 "Peer 1 tried %u times to switch and succeeded %u times, failed %u times\n",
226 stats[0].switch_attempts, 226 stats[0].switch_attempts,
@@ -234,13 +234,13 @@ custom_shutdown (void *cls)
234 } 234 }
235 else if (stats[0].addresses_avail > 1) 235 else if (stats[0].addresses_avail > 1)
236 { 236 {
237 FPRINTF (stderr, 237 fprintf (stderr,
238 "Peer 1 had %u addresses available, but did not try to switch\n", 238 "Peer 1 had %u addresses available, but did not try to switch\n",
239 stats[0].addresses_avail); 239 stats[0].addresses_avail);
240 } 240 }
241 if (stats[1].switch_attempts > 0) 241 if (stats[1].switch_attempts > 0)
242 { 242 {
243 FPRINTF ( 243 fprintf (
244 stderr, 244 stderr,
245 "Peer 2 tried %u times to switch and succeeded %u times, failed %u times\n", 245 "Peer 2 tried %u times to switch and succeeded %u times, failed %u times\n",
246 stats[1].switch_attempts, 246 stats[1].switch_attempts,
@@ -254,7 +254,7 @@ custom_shutdown (void *cls)
254 } 254 }
255 else if (stats[1].addresses_avail > 1) 255 else if (stats[1].addresses_avail > 1)
256 { 256 {
257 FPRINTF (stderr, 257 fprintf (stderr,
258 "Peer 2 had %u addresses available, but did not try to switch\n", 258 "Peer 2 had %u addresses available, but did not try to switch\n",
259 stats[1].addresses_avail); 259 stats[1].addresses_avail);
260 } 260 }
@@ -262,14 +262,14 @@ custom_shutdown (void *cls)
262 if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) && 262 if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) &&
263 (bytes_sent_after_switch == 0)) 263 (bytes_sent_after_switch == 0))
264 { 264 {
265 FPRINTF (stderr, "No data sent after switching!\n"); 265 fprintf (stderr, "No data sent after switching!\n");
266 GNUNET_break (0); 266 GNUNET_break (0);
267 result++; 267 result++;
268 } 268 }
269 if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) && 269 if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) &&
270 (bytes_recv_after_switch == 0)) 270 (bytes_recv_after_switch == 0))
271 { 271 {
272 FPRINTF (stderr, "No data received after switching!\n"); 272 fprintf (stderr, "No data received after switching!\n");
273 GNUNET_break (0); 273 GNUNET_break (0);
274 result++; 274 result++;
275 } 275 }
@@ -353,11 +353,11 @@ progress_indicator (void *cls)
353 counter++; 353 counter++;
354 if ((TIMEOUT.rel_value_us / 1000 / 1000LL) < counter) 354 if ((TIMEOUT.rel_value_us / 1000 / 1000LL) < counter)
355 { 355 {
356 FPRINTF (stderr, "%s", ".\n"); 356 fprintf (stderr, "%s", ".\n");
357 } 357 }
358 else 358 else
359 { 359 {
360 FPRINTF (stderr, "%s", "."); 360 fprintf (stderr, "%s", ".");
361 measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 361 measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
362 &progress_indicator, 362 &progress_indicator,
363 NULL); 363 NULL);
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c
index 8442b92e8..a26a92880 100644
--- a/src/transport/test_transport_api_reliability.c
+++ b/src/transport/test_transport_api_reliability.c
@@ -179,7 +179,7 @@ custom_shutdown (void *cls)
179 if (0 == delta) 179 if (0 == delta)
180 delta = 1; 180 delta = 1;
181 rate = (1000LL* 1000ll * total_bytes) / (1024 * delta); 181 rate = (1000LL* 1000ll * total_bytes) / (1024 * delta);
182 FPRINTF (stderr, 182 fprintf (stderr,
183 "\nThroughput was %llu KiBytes/s\n", 183 "\nThroughput was %llu KiBytes/s\n",
184 rate); 184 rate);
185 { 185 {
@@ -274,7 +274,7 @@ notify_receive (void *cls,
274 } 274 }
275 if (0 == (n % (TOTAL_MSGS / xhdr / 100))) 275 if (0 == (n % (TOTAL_MSGS / xhdr / 100)))
276 { 276 {
277 FPRINTF (stderr, "%s", "."); 277 fprintf (stderr, "%s", ".");
278 } 278 }
279 if (n == TOTAL_MSGS / xhdr) 279 if (n == TOTAL_MSGS / xhdr)
280 { 280 {
diff --git a/src/transport/test_transport_api_timeout.c b/src/transport/test_transport_api_timeout.c
index a00e0aeb6..f562dd196 100644
--- a/src/transport/test_transport_api_timeout.c
+++ b/src/transport/test_transport_api_timeout.c
@@ -120,13 +120,13 @@ timer (void *cls)
120 if (time_running.rel_value_us == 120 if (time_running.rel_value_us ==
121 GNUNET_TIME_relative_max (time_running, WAIT).rel_value_us) 121 GNUNET_TIME_relative_max (time_running, WAIT).rel_value_us)
122 { 122 {
123 FPRINTF (stderr, "%s", "100%%\n"); 123 fprintf (stderr, "%s", "100%%\n");
124 shutdown_flag = GNUNET_YES; 124 shutdown_flag = GNUNET_YES;
125 GNUNET_SCHEDULER_shutdown (); 125 GNUNET_SCHEDULER_shutdown ();
126 } 126 }
127 else 127 else
128 { 128 {
129 FPRINTF (stderr, 129 fprintf (stderr,
130 "%u%%..", 130 "%u%%..",
131 percentage); 131 percentage);
132 timer_task = 132 timer_task =
diff --git a/src/transport/test_transport_blacklisting.c b/src/transport/test_transport_blacklisting.c
index 1cd244115..0ecd6fda1 100644
--- a/src/transport/test_transport_blacklisting.c
+++ b/src/transport/test_transport_blacklisting.c
@@ -80,7 +80,7 @@ static struct GNUNET_SCHEDULER_Task * timeout_task;
80static struct GNUNET_SCHEDULER_Task * stage_task; 80static struct GNUNET_SCHEDULER_Task * stage_task;
81 81
82#if VERBOSE 82#if VERBOSE
83#define OKPP do { ok++; FPRINTF (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) 83#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0)
84#else 84#else
85#define OKPP do { ok++; } while (0) 85#define OKPP do { ok++; } while (0)
86#endif 86#endif
diff --git a/src/util/bio.c b/src/util/bio.c
index def9b02e1..1df249e40 100644
--- a/src/util/bio.c
+++ b/src/util/bio.c
@@ -25,7 +25,7 @@
25#include "platform.h" 25#include "platform.h"
26#include "gnunet_util_lib.h" 26#include "gnunet_util_lib.h"
27 27
28#define LOG(kind,...) GNUNET_log_from (kind, "util-bio",__VA_ARGS__) 28#define LOG(kind, ...) GNUNET_log_from (kind, "util-bio", __VA_ARGS__)
29 29
30#ifndef PATH_MAX 30#ifndef PATH_MAX
31/** 31/**
@@ -116,8 +116,7 @@ GNUNET_BIO_read_open (const char *fn)
116 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 116 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
117 */ 117 */
118int 118int
119GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, 119GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg)
120 char **emsg)
121{ 120{
122 int err; 121 int err;
123 122
@@ -144,7 +143,8 @@ GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h,
144int 143int
145GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, 144GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
146 const char *what, 145 const char *what,
147 void *result, size_t len) 146 void *result,
147 size_t len)
148{ 148{
149 char *dst = result; 149 char *dst = result;
150 size_t min; 150 size_t min;
@@ -162,39 +162,34 @@ GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
162 { 162 {
163 if (min > len - pos) 163 if (min > len - pos)
164 min = len - pos; 164 min = len - pos;
165 GNUNET_memcpy (&dst[pos], 165 GNUNET_memcpy (&dst[pos], &h->buffer[h->pos], min);
166 &h->buffer[h->pos],
167 min);
168 h->pos += min; 166 h->pos += min;
169 pos += min; 167 pos += min;
170 } 168 }
171 if (pos == len) 169 if (pos == len)
172 return GNUNET_OK; /* done! */ 170 return GNUNET_OK; /* done! */
173 GNUNET_assert (((off_t) h->have) == h->pos); 171 GNUNET_assert (((off_t) h->have) == h->pos);
174 /* fill buffer */ 172 /* fill buffer */
175 ret = GNUNET_DISK_file_read (h->fd, 173 ret = GNUNET_DISK_file_read (h->fd, h->buffer, h->size);
176 h->buffer,
177 h->size);
178 if (-1 == ret) 174 if (-1 == ret)
179 { 175 {
180 GNUNET_asprintf (&h->emsg, 176 GNUNET_asprintf (&h->emsg,
181 _("Error reading `%s': %s"), 177 _ ("Error reading `%s': %s"),
182 what, 178 what,
183 STRERROR (errno)); 179 strerror (errno));
184 return GNUNET_SYSERR; 180 return GNUNET_SYSERR;
185 } 181 }
186 if (0 == ret) 182 if (0 == ret)
187 { 183 {
188 GNUNET_asprintf (&h->emsg, 184 GNUNET_asprintf (&h->emsg,
189 _("Error reading `%s': %s"), 185 _ ("Error reading `%s': %s"),
190 what, 186 what,
191 _("End of file")); 187 _ ("End of file"));
192 return GNUNET_SYSERR; 188 return GNUNET_SYSERR;
193 } 189 }
194 h->pos = 0; 190 h->pos = 0;
195 h->have = ret; 191 h->have = ret;
196 } 192 } while (pos < len); /* should always be true */
197 while (pos < len); /* should always be true */
198 return GNUNET_OK; 193 return GNUNET_OK;
199} 194}
200 195
@@ -245,7 +240,7 @@ GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h,
245 if (GNUNET_OK != GNUNET_BIO_read_int32 (h, &big)) 240 if (GNUNET_OK != GNUNET_BIO_read_int32 (h, &big))
246 { 241 {
247 GNUNET_free_non_null (h->emsg); 242 GNUNET_free_non_null (h->emsg);
248 GNUNET_asprintf (&h->emsg, _("Error reading length of string `%s'"), what); 243 GNUNET_asprintf (&h->emsg, _ ("Error reading length of string `%s'"), what);
249 return GNUNET_SYSERR; 244 return GNUNET_SYSERR;
250 } 245 }
251 if (0 == big) 246 if (0 == big)
@@ -255,8 +250,11 @@ GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h,
255 } 250 }
256 if (big > max_length) 251 if (big > max_length)
257 { 252 {
258 GNUNET_asprintf (&h->emsg, _("String `%s' longer than allowed (%u > %u)"), 253 GNUNET_asprintf (&h->emsg,
259 what, big, max_length); 254 _ ("String `%s' longer than allowed (%u > %u)"),
255 what,
256 big,
257 max_length);
260 return GNUNET_SYSERR; 258 return GNUNET_SYSERR;
261 } 259 }
262 buf = GNUNET_malloc (big); 260 buf = GNUNET_malloc (big);
@@ -291,9 +289,7 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
291 char *buf; 289 char *buf;
292 struct GNUNET_CONTAINER_MetaData *meta; 290 struct GNUNET_CONTAINER_MetaData *meta;
293 291
294 if (GNUNET_OK != 292 if (GNUNET_OK != GNUNET_BIO_read_int32 (h, (int32_t *) &size))
295 GNUNET_BIO_read_int32 (h,
296 (int32_t *) & size))
297 return GNUNET_SYSERR; 293 return GNUNET_SYSERR;
298 if (size == 0) 294 if (size == 0)
299 { 295 {
@@ -303,30 +299,23 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
303 if (size > MAX_META_DATA) 299 if (size > MAX_META_DATA)
304 { 300 {
305 GNUNET_asprintf (&h->emsg, 301 GNUNET_asprintf (&h->emsg,
306 _("Serialized metadata `%s' larger than allowed (%u>%u)"), 302 _ ("Serialized metadata `%s' larger than allowed (%u>%u)"),
307 what, 303 what,
308 size, 304 size,
309 MAX_META_DATA); 305 MAX_META_DATA);
310 return GNUNET_SYSERR; 306 return GNUNET_SYSERR;
311 } 307 }
312 buf = GNUNET_malloc (size); 308 buf = GNUNET_malloc (size);
313 if (GNUNET_OK != 309 if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, size))
314 GNUNET_BIO_read (h,
315 what,
316 buf,
317 size))
318 { 310 {
319 GNUNET_free (buf); 311 GNUNET_free (buf);
320 return GNUNET_SYSERR; 312 return GNUNET_SYSERR;
321 } 313 }
322 meta = GNUNET_CONTAINER_meta_data_deserialize (buf, 314 meta = GNUNET_CONTAINER_meta_data_deserialize (buf, size);
323 size);
324 if (NULL == meta) 315 if (NULL == meta)
325 { 316 {
326 GNUNET_free (buf); 317 GNUNET_free (buf);
327 GNUNET_asprintf (&h->emsg, 318 GNUNET_asprintf (&h->emsg, _ ("Metadata `%s' failed to deserialize"), what);
328 _("Metadata `%s' failed to deserialize"),
329 what);
330 return GNUNET_SYSERR; 319 return GNUNET_SYSERR;
331 } 320 }
332 GNUNET_free (buf); 321 GNUNET_free (buf);
@@ -346,18 +335,13 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
346 */ 335 */
347int 336int
348GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, 337GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h,
349 const char *file, 338 const char *file,
350 int line, 339 int line,
351 int32_t * i) 340 int32_t *i)
352{ 341{
353 int32_t big; 342 int32_t big;
354 343
355 if (GNUNET_OK != 344 if (GNUNET_OK != GNUNET_BIO_read_fn (h, file, line, &big, sizeof (int32_t)))
356 GNUNET_BIO_read_fn (h,
357 file,
358 line,
359 &big,
360 sizeof (int32_t)))
361 return GNUNET_SYSERR; 345 return GNUNET_SYSERR;
362 *i = ntohl (big); 346 *i = ntohl (big);
363 return GNUNET_OK; 347 return GNUNET_OK;
@@ -381,12 +365,7 @@ GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h,
381{ 365{
382 int64_t big; 366 int64_t big;
383 367
384 if (GNUNET_OK != 368 if (GNUNET_OK != GNUNET_BIO_read_fn (h, file, line, &big, sizeof (int64_t)))
385 GNUNET_BIO_read_fn (h,
386 file,
387 line,
388 &big,
389 sizeof (int64_t)))
390 return GNUNET_SYSERR; 369 return GNUNET_SYSERR;
391 *i = GNUNET_ntohll (big); 370 *i = GNUNET_ntohll (big);
392 return GNUNET_OK; 371 return GNUNET_OK;
@@ -432,11 +411,12 @@ GNUNET_BIO_write_open (const char *fn)
432 struct GNUNET_DISK_FileHandle *fd; 411 struct GNUNET_DISK_FileHandle *fd;
433 struct GNUNET_BIO_WriteHandle *h; 412 struct GNUNET_BIO_WriteHandle *h;
434 413
435 fd = GNUNET_DISK_file_open (fn, 414 fd =
436 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE 415 GNUNET_DISK_file_open (fn,
437 | GNUNET_DISK_OPEN_CREATE, 416 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE |
438 GNUNET_DISK_PERM_USER_READ | 417 GNUNET_DISK_OPEN_CREATE,
439 GNUNET_DISK_PERM_USER_WRITE); 418 GNUNET_DISK_PERM_USER_READ |
419 GNUNET_DISK_PERM_USER_WRITE);
440 if (NULL == fd) 420 if (NULL == fd)
441 return NULL; 421 return NULL;
442 h = GNUNET_malloc (sizeof (struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE); 422 h = GNUNET_malloc (sizeof (struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE);
@@ -459,8 +439,7 @@ GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h)
459 int ret; 439 int ret;
460 440
461 ret = GNUNET_SYSERR; 441 ret = GNUNET_SYSERR;
462 if ( (NULL != h->fd) && 442 if ((NULL != h->fd) && (GNUNET_OK == (ret = GNUNET_BIO_flush (h))))
463 (GNUNET_OK == (ret = GNUNET_BIO_flush (h))) )
464 GNUNET_DISK_file_close (h->fd); 443 GNUNET_DISK_file_close (h->fd);
465 GNUNET_free (h); 444 GNUNET_free (h);
466 return ret; 445 return ret;
@@ -479,14 +458,12 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h)
479{ 458{
480 ssize_t ret; 459 ssize_t ret;
481 460
482 ret = GNUNET_DISK_file_write (h->fd, 461 ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->have);
483 h->buffer,
484 h->have);
485 if (ret != (ssize_t) h->have) 462 if (ret != (ssize_t) h->have)
486 { 463 {
487 GNUNET_DISK_file_close (h->fd); 464 GNUNET_DISK_file_close (h->fd);
488 h->fd = NULL; 465 h->fd = NULL;
489 return GNUNET_SYSERR; /* error */ 466 return GNUNET_SYSERR; /* error */
490 } 467 }
491 h->have = 0; 468 h->have = 0;
492 return GNUNET_OK; 469 return GNUNET_OK;
@@ -503,7 +480,7 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h)
503 */ 480 */
504int 481int
505GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, 482GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
506 const void *buffer, 483 const void *buffer,
507 size_t n) 484 size_t n)
508{ 485{
509 const char *src = buffer; 486 const char *src = buffer;
@@ -519,18 +496,15 @@ GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
519 min = h->size - h->have; 496 min = h->size - h->have;
520 if (min > n - pos) 497 if (min > n - pos)
521 min = n - pos; 498 min = n - pos;
522 GNUNET_memcpy (&h->buffer[h->have], 499 GNUNET_memcpy (&h->buffer[h->have], &src[pos], min);
523 &src[pos],
524 min);
525 pos += min; 500 pos += min;
526 h->have += min; 501 h->have += min;
527 if (pos == n) 502 if (pos == n)
528 return GNUNET_OK; /* done */ 503 return GNUNET_OK; /* done */
529 GNUNET_assert (h->have == h->size); 504 GNUNET_assert (h->have == h->size);
530 if (GNUNET_OK != GNUNET_BIO_flush (h)) 505 if (GNUNET_OK != GNUNET_BIO_flush (h))
531 return GNUNET_SYSERR; /* error */ 506 return GNUNET_SYSERR; /* error */
532 } 507 } while (pos < n); /* should always be true */
533 while (pos < n); /* should always be true */
534 GNUNET_break (0); 508 GNUNET_break (0);
535 return GNUNET_OK; 509 return GNUNET_OK;
536} 510}
@@ -544,8 +518,7 @@ GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
544 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 518 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
545 */ 519 */
546int 520int
547GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, 521GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, const char *s)
548 const char *s)
549{ 522{
550 uint32_t slen; 523 uint32_t slen;
551 524
@@ -575,9 +548,11 @@ GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
575 if (m == NULL) 548 if (m == NULL)
576 return GNUNET_BIO_write_int32 (h, 0); 549 return GNUNET_BIO_write_int32 (h, 0);
577 buf = NULL; 550 buf = NULL;
578 size = 551 size = GNUNET_CONTAINER_meta_data_serialize (
579 GNUNET_CONTAINER_meta_data_serialize (m, &buf, MAX_META_DATA, 552 m,
580 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); 553 &buf,
554 MAX_META_DATA,
555 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
581 if (size == -1) 556 if (size == -1)
582 { 557 {
583 GNUNET_free (buf); 558 GNUNET_free (buf);
@@ -602,8 +577,7 @@ GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
602 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 577 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
603 */ 578 */
604int 579int
605GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, 580GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, int32_t i)
606 int32_t i)
607{ 581{
608 int32_t big; 582 int32_t big;
609 583
@@ -620,8 +594,7 @@ GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h,
620 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 594 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
621 */ 595 */
622int 596int
623GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, 597GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, int64_t i)
624 int64_t i)
625{ 598{
626 int64_t big; 599 int64_t big;
627 600
diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c
index 20333ce56..94890a7f4 100644
--- a/src/util/common_allocation.c
+++ b/src/util/common_allocation.c
@@ -32,9 +32,11 @@
32#include <malloc/malloc.h> 32#include <malloc/malloc.h>
33#endif 33#endif
34 34
35#define LOG(kind,...) GNUNET_log_from (kind, "util-common-allocation",__VA_ARGS__) 35#define LOG(kind, ...) \
36 GNUNET_log_from (kind, "util-common-allocation", __VA_ARGS__)
36 37
37#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-common-allocation", syscall) 38#define LOG_STRERROR(kind, syscall) \
39 GNUNET_log_from_strerror (kind, "util-common-allocation", syscall)
38 40
39#ifndef INT_MAX 41#ifndef INT_MAX
40#define INT_MAX 0x7FFFFFFF 42#define INT_MAX 0x7FFFFFFF
@@ -61,24 +63,17 @@ static LONG mem_used = 0;
61 * @return pointer to size bytes of memory 63 * @return pointer to size bytes of memory
62 */ 64 */
63void * 65void *
64GNUNET_xmalloc_ (size_t size, 66GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber)
65 const char *filename,
66 int linenumber)
67{ 67{
68 void *ret; 68 void *ret;
69 69
70 /* As a security precaution, we generally do not allow very large 70 /* As a security precaution, we generally do not allow very large
71 * allocations using the default 'GNUNET_malloc()' macro */ 71 * allocations using the default 'GNUNET_malloc()' macro */
72 GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, 72 GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber);
73 filename, 73 ret = GNUNET_xmalloc_unchecked_ (size, filename, linenumber);
74 linenumber);
75 ret = GNUNET_xmalloc_unchecked_ (size,
76 filename,
77 linenumber);
78 if (NULL == ret) 74 if (NULL == ret)
79 { 75 {
80 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, 76 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "malloc");
81 "malloc");
82 GNUNET_assert (0); 77 GNUNET_assert (0);
83 } 78 }
84 return ret; 79 return ret;
@@ -101,21 +96,22 @@ GNUNET_xmalloc_ (size_t size,
101 */ 96 */
102void ** 97void **
103GNUNET_xnew_array_2d_ (size_t n, 98GNUNET_xnew_array_2d_ (size_t n,
104 size_t m, 99 size_t m,
105 size_t elementSize, 100 size_t elementSize,
106 const char *filename, 101 const char *filename,
107 int linenumber) 102 int linenumber)
108{ 103{
109 /* use char pointer internally to avoid void pointer arithmetic warnings */ 104 /* use char pointer internally to avoid void pointer arithmetic warnings */
110 char **ret = GNUNET_xmalloc_ (n * sizeof (void *) + /* 1. dim header */ 105 char **ret = GNUNET_xmalloc_ (n * sizeof (void *) + /* 1. dim header */
111 n * m * elementSize, /* element data */ 106 n * m * elementSize, /* element data */
112 filename, linenumber); 107 filename,
113 108 linenumber);
114 for (size_t i = 0; i < n; i++) 109
115 ret[i] = (char *)ret + /* base address */ 110 for (size_t i = 0; i < n; i++)
116 n * sizeof (void *) + /* skip 1. dim header */ 111 ret[i] = (char *) ret + /* base address */
117 i * m * elementSize; /* skip to 2. dim row header */ 112 n * sizeof (void *) + /* skip 1. dim header */
118 return (void **)ret; 113 i * m * elementSize; /* skip to 2. dim row header */
114 return (void **) ret;
119} 115}
120 116
121 117
@@ -135,29 +131,34 @@ GNUNET_xnew_array_2d_ (size_t n,
135 * @return allocated memory, never NULL 131 * @return allocated memory, never NULL
136 */ 132 */
137void *** 133void ***
138GNUNET_xnew_array_3d_ (size_t n, size_t m, size_t o, size_t elementSize, 134GNUNET_xnew_array_3d_ (size_t n,
139 const char *filename, int linenumber) 135 size_t m,
136 size_t o,
137 size_t elementSize,
138 const char *filename,
139 int linenumber)
140{ 140{
141 /* use char pointer internally to avoid void pointer arithmetic warnings */ 141 /* use char pointer internally to avoid void pointer arithmetic warnings */
142 char ***ret = GNUNET_xmalloc_ (n * sizeof (void **) + /* 1. dim header */ 142 char ***ret = GNUNET_xmalloc_ (n * sizeof (void **) + /* 1. dim header */
143 n * m * sizeof (void *) + /* 2. dim header */ 143 n * m * sizeof (void *) + /* 2. dim header */
144 n * m * o * elementSize, /* element data */ 144 n * m * o * elementSize, /* element data */
145 filename, linenumber); 145 filename,
146 146 linenumber);
147 for (size_t i = 0; i < n; i++) 147
148 { 148 for (size_t i = 0; i < n; i++)
149 /* need to cast to (char *) temporarily for byte level acuracy */ 149 {
150 ret[i] = (char **)((char *)ret + /* base address */ 150 /* need to cast to (char *) temporarily for byte level acuracy */
151 n * sizeof (void **) + /* skip 1. dim header */ 151 ret[i] = (char **) ((char *) ret + /* base address */
152 i * m * sizeof (void *)); /* skip to 2. dim header */ 152 n * sizeof (void **) + /* skip 1. dim header */
153 for (size_t j = 0; j < m; j++) 153 i * m * sizeof (void *)); /* skip to 2. dim header */
154 ret[i][j] = (char *)ret + /* base address */ 154 for (size_t j = 0; j < m; j++)
155 n * sizeof (void **) + /* skip 1. dim header */ 155 ret[i][j] = (char *) ret + /* base address */
156 n * m * sizeof (void *) + /* skip 2. dim header */ 156 n * sizeof (void **) + /* skip 1. dim header */
157 i * m * o * elementSize + /* skip to 2. dim part */ 157 n * m * sizeof (void *) + /* skip 2. dim header */
158 j * o * elementSize; /* skip to 3. dim row data */ 158 i * m * o * elementSize + /* skip to 2. dim part */
159 } 159 j * o * elementSize; /* skip to 3. dim row data */
160 return (void ***)ret; 160 }
161 return (void ***) ret;
161} 162}
162 163
163 164
@@ -174,8 +175,8 @@ GNUNET_xnew_array_3d_ (size_t n, size_t m, size_t o, size_t elementSize,
174 */ 175 */
175void * 176void *
176GNUNET_xmemdup_ (const void *buf, 177GNUNET_xmemdup_ (const void *buf,
177 size_t size, 178 size_t size,
178 const char *filename, 179 const char *filename,
179 int linenumber) 180 int linenumber)
180{ 181{
181 void *ret; 182 void *ret;
@@ -215,9 +216,7 @@ GNUNET_xmemdup_ (const void *buf,
215 * @return pointer to size bytes of memory, NULL if we do not have enough memory 216 * @return pointer to size bytes of memory, NULL if we do not have enough memory
216 */ 217 */
217void * 218void *
218GNUNET_xmalloc_unchecked_ (size_t size, 219GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber)
219 const char *filename,
220 int linenumber)
221{ 220{
222 void *result; 221 void *result;
223 222
@@ -256,10 +255,7 @@ GNUNET_xmalloc_unchecked_ (size_t size,
256 * @return pointer to size bytes of memory 255 * @return pointer to size bytes of memory
257 */ 256 */
258void * 257void *
259GNUNET_xrealloc_ (void *ptr, 258GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber)
260 size_t n,
261 const char *filename,
262 int linenumber)
263{ 259{
264 (void) filename; 260 (void) filename;
265 (void) linenumber; 261 (void) linenumber;
@@ -272,8 +268,7 @@ GNUNET_xrealloc_ (void *ptr,
272 ptr = realloc (ptr, n); 268 ptr = realloc (ptr, n);
273 if ((NULL == ptr) && (n > 0)) 269 if ((NULL == ptr) && (n > 0))
274 { 270 {
275 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, 271 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "realloc");
276 "realloc");
277 GNUNET_assert (0); 272 GNUNET_assert (0);
278 } 273 }
279#ifdef W32_MEM_LIMIT 274#ifdef W32_MEM_LIMIT
@@ -283,10 +278,10 @@ GNUNET_xrealloc_ (void *ptr,
283} 278}
284 279
285 280
286# if __BYTE_ORDER == __LITTLE_ENDIAN 281#if __BYTE_ORDER == __LITTLE_ENDIAN
287#define BAADFOOD_STR "\x0D\xF0\xAD\xBA" 282#define BAADFOOD_STR "\x0D\xF0\xAD\xBA"
288#endif 283#endif
289# if __BYTE_ORDER == __BIG_ENDIAN 284#if __BYTE_ORDER == __BIG_ENDIAN
290#define BAADFOOD_STR "\xBA\xAD\xF0\x0D" 285#define BAADFOOD_STR "\xBA\xAD\xF0\x0D"
291#endif 286#endif
292 287
@@ -311,13 +306,9 @@ GNUNET_xrealloc_ (void *ptr,
311 * @param linenumber where in the code was the call to GNUNET_free 306 * @param linenumber where in the code was the call to GNUNET_free
312 */ 307 */
313void 308void
314GNUNET_xfree_ (void *ptr, 309GNUNET_xfree_ (void *ptr, const char *filename, int linenumber)
315 const char *filename,
316 int linenumber)
317{ 310{
318 GNUNET_assert_at (NULL != ptr, 311 GNUNET_assert_at (NULL != ptr, filename, linenumber);
319 filename,
320 linenumber);
321#ifdef W32_MEM_LIMIT 312#ifdef W32_MEM_LIMIT
322 ptr = &((size_t *) ptr)[-1]; 313 ptr = &((size_t *) ptr)[-1];
323 mem_used -= *((size_t *) ptr); 314 mem_used -= *((size_t *) ptr);
@@ -330,9 +321,9 @@ GNUNET_xfree_ (void *ptr,
330 size_t s = M_SIZE (ptr); 321 size_t s = M_SIZE (ptr);
331 size_t i; 322 size_t i;
332 323
333 for (i=0;i<s/8;i++) 324 for (i = 0; i < s / 8; i++)
334 base[i] = baadfood; 325 base[i] = baadfood;
335 GNUNET_memcpy (&base[s/8], &baadfood, s % 8); 326 GNUNET_memcpy (&base[s / 8], &baadfood, s % 8);
336 } 327 }
337#endif 328#endif
338#endif 329#endif
@@ -349,31 +340,22 @@ GNUNET_xfree_ (void *ptr,
349 * @return `strdup(@a str)` 340 * @return `strdup(@a str)`
350 */ 341 */
351char * 342char *
352GNUNET_xstrdup_ (const char *str, 343GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber)
353 const char *filename,
354 int linenumber)
355{ 344{
356 char *res; 345 char *res;
357 size_t slen; 346 size_t slen;
358 347
359 GNUNET_assert_at (str != NULL, 348 GNUNET_assert_at (str != NULL, filename, linenumber);
360 filename,
361 linenumber);
362 slen = strlen (str) + 1; 349 slen = strlen (str) + 1;
363 res = GNUNET_xmalloc_ (slen, 350 res = GNUNET_xmalloc_ (slen, filename, linenumber);
364 filename, 351 GNUNET_memcpy (res, str, slen);
365 linenumber);
366 GNUNET_memcpy (res,
367 str,
368 slen);
369 return res; 352 return res;
370} 353}
371 354
372 355
373#if ! HAVE_STRNLEN 356#if ! HAVE_STRNLEN
374static size_t 357static size_t
375strnlen (const char *s, 358strnlen (const char *s, size_t n)
376 size_t n)
377{ 359{
378 const char *e; 360 const char *e;
379 361
@@ -396,22 +378,17 @@ strnlen (const char *s,
396 */ 378 */
397char * 379char *
398GNUNET_xstrndup_ (const char *str, 380GNUNET_xstrndup_ (const char *str,
399 size_t len, 381 size_t len,
400 const char *filename, 382 const char *filename,
401 int linenumber) 383 int linenumber)
402{ 384{
403 char *res; 385 char *res;
404 386
405 if (0 == len) 387 if (0 == len)
406 return GNUNET_strdup (""); 388 return GNUNET_strdup ("");
407 GNUNET_assert_at (NULL != str, 389 GNUNET_assert_at (NULL != str, filename, linenumber);
408 filename, 390 len = strnlen (str, len);
409 linenumber); 391 res = GNUNET_xmalloc_ (len + 1, filename, linenumber);
410 len = strnlen (str,
411 len);
412 res = GNUNET_xmalloc_ (len + 1,
413 filename,
414 linenumber);
415 GNUNET_memcpy (res, str, len); 392 GNUNET_memcpy (res, str, len);
416 /* res[len] = '\0'; 'malloc' zeros out anyway */ 393 /* res[len] = '\0'; 'malloc' zeros out anyway */
417 return res; 394 return res;
@@ -432,11 +409,11 @@ GNUNET_xstrndup_ (const char *str,
432 */ 409 */
433void 410void
434GNUNET_xgrow_ (void **old, 411GNUNET_xgrow_ (void **old,
435 size_t elementSize, 412 size_t elementSize,
436 unsigned int *oldCount, 413 unsigned int *oldCount,
437 unsigned int newCount, 414 unsigned int newCount,
438 const char *filename, 415 const char *filename,
439 int linenumber) 416 int linenumber)
440{ 417{
441 void *tmp; 418 void *tmp;
442 size_t size; 419 size_t size;
@@ -452,7 +429,7 @@ GNUNET_xgrow_ (void **old,
452 tmp = GNUNET_xmalloc_ (size, filename, linenumber); 429 tmp = GNUNET_xmalloc_ (size, filename, linenumber);
453 if (NULL != *old) 430 if (NULL != *old)
454 { 431 {
455 GNUNET_memcpy (tmp, *old, elementSize * GNUNET_MIN(*oldCount, newCount)); 432 GNUNET_memcpy (tmp, *old, elementSize * GNUNET_MIN (*oldCount, newCount));
456 } 433 }
457 } 434 }
458 435
@@ -474,20 +451,18 @@ GNUNET_xgrow_ (void **old,
474 * @return number of bytes in `*@a buf`, excluding 0-termination 451 * @return number of bytes in `*@a buf`, excluding 0-termination
475 */ 452 */
476int 453int
477GNUNET_asprintf (char **buf, 454GNUNET_asprintf (char **buf, const char *format, ...)
478 const char *format,
479 ...)
480{ 455{
481 int ret; 456 int ret;
482 va_list args; 457 va_list args;
483 458
484 va_start (args, format); 459 va_start (args, format);
485 ret = VSNPRINTF (NULL, 0, format, args); 460 ret = vsnprintf (NULL, 0, format, args);
486 va_end (args); 461 va_end (args);
487 GNUNET_assert (ret >= 0); 462 GNUNET_assert (ret >= 0);
488 *buf = GNUNET_malloc (ret + 1); 463 *buf = GNUNET_malloc (ret + 1);
489 va_start (args, format); 464 va_start (args, format);
490 ret = VSPRINTF (*buf, format, args); 465 ret = vsprintf (*buf, format, args);
491 va_end (args); 466 va_end (args);
492 return ret; 467 return ret;
493} 468}
@@ -503,21 +478,15 @@ GNUNET_asprintf (char **buf,
503 * @return number of bytes written to buf or negative value on error 478 * @return number of bytes written to buf or negative value on error
504 */ 479 */
505int 480int
506GNUNET_snprintf (char *buf, 481GNUNET_snprintf (char *buf, size_t size, const char *format, ...)
507 size_t size,
508 const char *format, ...)
509{ 482{
510 int ret; 483 int ret;
511 va_list args; 484 va_list args;
512 485
513 va_start (args, format); 486 va_start (args, format);
514 ret = VSNPRINTF (buf, 487 ret = vsnprintf (buf, size, format, args);
515 size,
516 format,
517 args);
518 va_end (args); 488 va_end (args);
519 GNUNET_assert ( (ret >= 0) && 489 GNUNET_assert ((ret >= 0) && (((size_t) ret) < size));
520 (((size_t) ret) < size) );
521 return ret; 490 return ret;
522} 491}
523 492
@@ -537,9 +506,7 @@ GNUNET_copy_message (const struct GNUNET_MessageHeader *msg)
537 msize = ntohs (msg->size); 506 msize = ntohs (msg->size);
538 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader)); 507 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
539 ret = GNUNET_malloc (msize); 508 ret = GNUNET_malloc (msize);
540 GNUNET_memcpy (ret, 509 GNUNET_memcpy (ret, msg, msize);
541 msg,
542 msize);
543 return ret; 510 return ret;
544} 511}
545 512
diff --git a/src/util/common_logging.c b/src/util/common_logging.c
index 19bbbdb81..d3666ae7d 100644
--- a/src/util/common_logging.c
+++ b/src/util/common_logging.c
@@ -107,8 +107,7 @@ static __thread struct GNUNET_AsyncScopeSave current_async_scope;
107 * Note that this message maybe truncated to the first BULK_TRACK_SIZE 107 * Note that this message maybe truncated to the first BULK_TRACK_SIZE
108 * characters, in which case it is NOT 0-terminated! 108 * characters, in which case it is NOT 0-terminated!
109 */ 109 */
110static GNUNET_THREAD_LOCAL char last_bulk[BULK_TRACK_SIZE] 110static GNUNET_THREAD_LOCAL char last_bulk[BULK_TRACK_SIZE] __nonstring;
111 __nonstring;
112 111
113/** 112/**
114 * Type of the last bulk message. 113 * Type of the last bulk message.
@@ -325,7 +324,7 @@ log_rotate (const char *new_name)
325 { 324 {
326 /* Note: can't log errors during logging (recursion!), so this 325 /* Note: can't log errors during logging (recursion!), so this
327 operation MUST silently fail... */ 326 operation MUST silently fail... */
328 (void) UNLINK (discard); 327 (void) unlink (discard);
329 GNUNET_free (discard); 328 GNUNET_free (discard);
330 } 329 }
331 rotation[rotation_off % ROTATION_KEEP] = GNUNET_strdup (new_name); 330 rotation[rotation_off % ROTATION_KEEP] = GNUNET_strdup (new_name);
@@ -377,14 +376,14 @@ setup_log_file (const struct tm *tm)
377 fprintf (stderr, 376 fprintf (stderr,
378 "Failed to create directory for `%s': %s\n", 377 "Failed to create directory for `%s': %s\n",
379 fn, 378 fn,
380 STRERROR (errno)); 379 strerror (errno));
381 return GNUNET_SYSERR; 380 return GNUNET_SYSERR;
382 } 381 }
383#if WINDOWS 382#if WINDOWS
384 altlog_fd = 383 altlog_fd =
385 OPEN (fn, O_APPEND | O_BINARY | O_WRONLY | O_CREAT, _S_IREAD | _S_IWRITE); 384 open (fn, O_APPEND | O_BINARY | O_WRONLY | O_CREAT, _S_IREAD | _S_IWRITE);
386#else 385#else
387 altlog_fd = OPEN (fn, 386 altlog_fd = open (fn,
388 O_APPEND | O_WRONLY | O_CREAT, 387 O_APPEND | O_WRONLY | O_CREAT,
389 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); 388 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
390#endif 389#endif
@@ -841,7 +840,7 @@ output_message (enum GNUNET_ErrorType kind,
841 * this way if the output is going to logfiles or robots 840 * this way if the output is going to logfiles or robots
842 * instead. 841 * instead.
843 */ 842 */
844 FPRINTF (GNUNET_stderr, "* %s", msg); 843 fprintf (GNUNET_stderr, "* %s", msg);
845 } 844 }
846 else if (GNUNET_YES == current_async_scope.have_scope) 845 else if (GNUNET_YES == current_async_scope.have_scope)
847 { 846 {
@@ -857,7 +856,7 @@ output_message (enum GNUNET_ErrorType kind,
857 GNUNET_assert (NULL != end); 856 GNUNET_assert (NULL != end);
858 *end = '\0'; 857 *end = '\0';
859 skip_log = 0; 858 skip_log = 0;
860 FPRINTF (GNUNET_stderr, 859 fprintf (GNUNET_stderr,
861 "%s %s(%s) %s %s", 860 "%s %s(%s) %s %s",
862 datestr, 861 datestr,
863 comp, 862 comp,
@@ -867,7 +866,7 @@ output_message (enum GNUNET_ErrorType kind,
867 } 866 }
868 else 867 else
869 { 868 {
870 FPRINTF (GNUNET_stderr, 869 fprintf (GNUNET_stderr,
871 "%s %s %s %s", 870 "%s %s %s %s",
872 datestr, 871 datestr,
873 comp, 872 comp,
@@ -991,7 +990,7 @@ mylog (enum GNUNET_ErrorType kind,
991 va_list vacp; 990 va_list vacp;
992 991
993 va_copy (vacp, va); 992 va_copy (vacp, va);
994 size = VSNPRINTF (NULL, 0, message, vacp) + 1; 993 size = vsnprintf (NULL, 0, message, vacp) + 1;
995 GNUNET_assert (0 != size); 994 GNUNET_assert (0 != size);
996 va_end (vacp); 995 va_end (vacp);
997 memset (date, 0, DATE_STR_SIZE); 996 memset (date, 0, DATE_STR_SIZE);
@@ -1065,7 +1064,7 @@ mylog (enum GNUNET_ErrorType kind,
1065 abort (); 1064 abort ();
1066 } 1065 }
1067#endif 1066#endif
1068 VSNPRINTF (buf, size, message, va); 1067 vsnprintf (buf, size, message, va);
1069#if ! (defined(GNUNET_CULL_LOGGING) || TALER_WALLET_ONLY) 1068#if ! (defined(GNUNET_CULL_LOGGING) || TALER_WALLET_ONLY)
1070 if (NULL != tmptr) 1069 if (NULL != tmptr)
1071 (void) setup_log_file (tmptr); 1070 (void) setup_log_file (tmptr);
diff --git a/src/util/configuration.c b/src/util/configuration.c
index a38438ba8..f327071de 100644
--- a/src/util/configuration.c
+++ b/src/util/configuration.c
@@ -30,9 +30,10 @@
30#include "gnunet_configuration_lib.h" 30#include "gnunet_configuration_lib.h"
31#include "gnunet_disk_lib.h" 31#include "gnunet_disk_lib.h"
32 32
33#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__) 33#define LOG(kind, ...) GNUNET_log_from (kind, "util", __VA_ARGS__)
34 34
35#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename) 35#define LOG_STRERROR_FILE(kind, syscall, filename) \
36 GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
36 37
37/** 38/**
38 * @brief configuration entry 39 * @brief configuration entry
@@ -95,7 +96,6 @@ struct GNUNET_CONFIGURATION_Handle
95 * #GNUNET_SYSERR on error (i.e. last save failed) 96 * #GNUNET_SYSERR on error (i.e. last save failed)
96 */ 97 */
97 int dirty; 98 int dirty;
98
99}; 99};
100 100
101 101
@@ -152,23 +152,20 @@ GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg)
152 */ 152 */
153int 153int
154GNUNET_CONFIGURATION_parse_and_run (const char *filename, 154GNUNET_CONFIGURATION_parse_and_run (const char *filename,
155 GNUNET_CONFIGURATION_Callback cb, 155 GNUNET_CONFIGURATION_Callback cb,
156 void *cb_cls) 156 void *cb_cls)
157{ 157{
158 struct GNUNET_CONFIGURATION_Handle *cfg; 158 struct GNUNET_CONFIGURATION_Handle *cfg;
159 int ret; 159 int ret;
160 160
161 cfg = GNUNET_CONFIGURATION_create (); 161 cfg = GNUNET_CONFIGURATION_create ();
162 if (GNUNET_OK != 162 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, filename))
163 GNUNET_CONFIGURATION_load (cfg,
164 filename))
165 { 163 {
166 GNUNET_break (0); 164 GNUNET_break (0);
167 GNUNET_CONFIGURATION_destroy (cfg); 165 GNUNET_CONFIGURATION_destroy (cfg);
168 return GNUNET_SYSERR; 166 return GNUNET_SYSERR;
169 } 167 }
170 ret = cb (cb_cls, 168 ret = cb (cb_cls, cfg);
171 cfg);
172 GNUNET_CONFIGURATION_destroy (cfg); 169 GNUNET_CONFIGURATION_destroy (cfg);
173 return ret; 170 return ret;
174} 171}
@@ -187,9 +184,9 @@ GNUNET_CONFIGURATION_parse_and_run (const char *filename,
187 */ 184 */
188int 185int
189GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, 186GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
190 const char *mem, 187 const char *mem,
191 size_t size, 188 size_t size,
192 const char *basedir) 189 const char *basedir)
193{ 190{
194 char *line; 191 char *line;
195 char *line_orig; 192 char *line_orig;
@@ -224,7 +221,8 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
224 } 221 }
225 else 222 else
226 { 223 {
227 line_orig = GNUNET_strndup (&mem[r_bytes], line_size = (pos - &mem[r_bytes])); 224 line_orig =
225 GNUNET_strndup (&mem[r_bytes], line_size = (pos - &mem[r_bytes]));
228 r_bytes += line_size + 1; 226 r_bytes += line_size + 1;
229 } 227 }
230 line = line_orig; 228 line = line_orig;
@@ -246,51 +244,46 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
246 continue; 244 continue;
247 245
248 /* remove tailing whitespace */ 246 /* remove tailing whitespace */
249 for (i = line_size - 1; (i >= 1) && (isspace ((unsigned char) line[i]));i--) 247 for (i = line_size - 1; (i >= 1) && (isspace ((unsigned char) line[i]));
248 i--)
250 line[i] = '\0'; 249 line[i] = '\0';
251 250
252 /* remove leading whitespace */ 251 /* remove leading whitespace */
253 for (; line[0] != '\0' && (isspace ((unsigned char) line[0])); line++); 252 for (; line[0] != '\0' && (isspace ((unsigned char) line[0])); line++)
253 ;
254 254
255 /* ignore comments */ 255 /* ignore comments */
256 if ( ('#' == line[0]) || ('%' == line[0]) ) 256 if (('#' == line[0]) || ('%' == line[0]))
257 continue; 257 continue;
258 258
259 /* handle special "@INLINE@" directive */ 259 /* handle special "@INLINE@" directive */
260 if (0 == strncasecmp (line, 260 if (0 == strncasecmp (line, "@INLINE@ ", strlen ("@INLINE@ ")))
261 "@INLINE@ ",
262 strlen ("@INLINE@ ")))
263 { 261 {
264 /* @INLINE@ value */ 262 /* @INLINE@ value */
265 value = &line[strlen ("@INLINE@ ")]; 263 value = &line[strlen ("@INLINE@ ")];
266 if (NULL != basedir) 264 if (NULL != basedir)
267 { 265 {
268 char *fn; 266 char *fn;
269 267
270 GNUNET_asprintf (&fn, 268 GNUNET_asprintf (&fn, "%s/%s", basedir, value);
271 "%s/%s", 269 if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, fn))
272 basedir, 270 {
273 value); 271 GNUNET_free (fn);
274 if (GNUNET_OK != 272 ret = GNUNET_SYSERR; /* failed to parse included config */
275 GNUNET_CONFIGURATION_parse (cfg, 273 break;
276 fn)) 274 }
277 { 275 GNUNET_free (fn);
278 GNUNET_free (fn);
279 ret = GNUNET_SYSERR; /* failed to parse included config */
280 break;
281 }
282 GNUNET_free (fn);
283 } 276 }
284 else 277 else
285 { 278 {
286 LOG (GNUNET_ERROR_TYPE_DEBUG, 279 LOG (GNUNET_ERROR_TYPE_DEBUG,
287 "Ignoring parsing @INLINE@ configurations, not allowed!\n"); 280 "Ignoring parsing @INLINE@ configurations, not allowed!\n");
288 ret = GNUNET_SYSERR; 281 ret = GNUNET_SYSERR;
289 break; 282 break;
290 } 283 }
291 continue; 284 continue;
292 } 285 }
293 if ( ('[' == line[0]) && (']' == line[line_size - 1]) ) 286 if (('[' == line[0]) && (']' == line[line_size - 1]))
294 { 287 {
295 /* [value] */ 288 /* [value] */
296 line[line_size - 1] = '\0'; 289 line[line_size - 1] = '\0';
@@ -304,23 +297,25 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
304 /* tag = value */ 297 /* tag = value */
305 tag = GNUNET_strndup (line, eq - line); 298 tag = GNUNET_strndup (line, eq - line);
306 /* remove tailing whitespace */ 299 /* remove tailing whitespace */
307 for (i = strlen (tag) - 1; (i >= 1) && (isspace ((unsigned char) tag[i]));i--) 300 for (i = strlen (tag) - 1; (i >= 1) && (isspace ((unsigned char) tag[i]));
308 tag[i] = '\0'; 301 i--)
302 tag[i] = '\0';
309 303
310 /* Strip whitespace */ 304 /* Strip whitespace */
311 value = eq + 1; 305 value = eq + 1;
312 while (isspace ((unsigned char) value[0])) 306 while (isspace ((unsigned char) value[0]))
313 value++; 307 value++;
314 for (i = strlen (value) - 1; (i >= 1) && (isspace ((unsigned char) value[i]));i--) 308 for (i = strlen (value) - 1;
315 value[i] = '\0'; 309 (i >= 1) && (isspace ((unsigned char) value[i]));
310 i--)
311 value[i] = '\0';
316 312
317 /* remove quotes */ 313 /* remove quotes */
318 i = 0; 314 i = 0;
319 if ( ('"' == value[0]) && 315 if (('"' == value[0]) && ('"' == value[strlen (value) - 1]))
320 ('"' == value[strlen (value) - 1]) )
321 { 316 {
322 value[strlen (value) - 1] = '\0'; 317 value[strlen (value) - 1] = '\0';
323 value++; 318 value++;
324 } 319 }
325 GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, &value[i]); 320 GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, &value[i]);
326 GNUNET_free (tag); 321 GNUNET_free (tag);
@@ -328,14 +323,14 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
328 } 323 }
329 /* parse error */ 324 /* parse error */
330 LOG (GNUNET_ERROR_TYPE_WARNING, 325 LOG (GNUNET_ERROR_TYPE_WARNING,
331 _("Syntax error while deserializing in line %u\n"), 326 _ ("Syntax error while deserializing in line %u\n"),
332 nr); 327 nr);
333 ret = GNUNET_SYSERR; 328 ret = GNUNET_SYSERR;
334 break; 329 break;
335 } 330 }
336 GNUNET_free_non_null (line_orig); 331 GNUNET_free_non_null (line_orig);
337 GNUNET_free (section); 332 GNUNET_free (section);
338 GNUNET_assert ( (GNUNET_OK != ret) || (r_bytes == size) ); 333 GNUNET_assert ((GNUNET_OK != ret) || (r_bytes == size));
339 return ret; 334 return ret;
340} 335}
341 336
@@ -362,55 +357,40 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
362 ssize_t sret; 357 ssize_t sret;
363 358
364 fn = GNUNET_STRINGS_filename_expand (filename); 359 fn = GNUNET_STRINGS_filename_expand (filename);
365 LOG (GNUNET_ERROR_TYPE_DEBUG, 360 LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to parse config file `%s'\n", fn);
366 "Asked to parse config file `%s'\n",
367 fn);
368 if (NULL == fn) 361 if (NULL == fn)
369 return GNUNET_SYSERR; 362 return GNUNET_SYSERR;
370 dirty = cfg->dirty; /* back up value! */ 363 dirty = cfg->dirty; /* back up value! */
371 if (GNUNET_SYSERR == 364 if (GNUNET_SYSERR ==
372 GNUNET_DISK_file_size (fn, 365 GNUNET_DISK_file_size (fn, &fs64, GNUNET_YES, GNUNET_YES))
373 &fs64,
374 GNUNET_YES,
375 GNUNET_YES))
376 { 366 {
377 LOG (GNUNET_ERROR_TYPE_WARNING, 367 LOG (GNUNET_ERROR_TYPE_WARNING,
378 "Error while determining the file size of `%s'\n", 368 "Error while determining the file size of `%s'\n",
379 fn); 369 fn);
380 GNUNET_free (fn); 370 GNUNET_free (fn);
381 return GNUNET_SYSERR; 371 return GNUNET_SYSERR;
382 } 372 }
383 if (fs64 > SIZE_MAX) 373 if (fs64 > SIZE_MAX)
384 { 374 {
385 GNUNET_break (0); /* File size is more than the heap size */ 375 GNUNET_break (0); /* File size is more than the heap size */
386 GNUNET_free (fn); 376 GNUNET_free (fn);
387 return GNUNET_SYSERR; 377 return GNUNET_SYSERR;
388 } 378 }
389 fs = fs64; 379 fs = fs64;
390 mem = GNUNET_malloc (fs); 380 mem = GNUNET_malloc (fs);
391 sret = GNUNET_DISK_fn_read (fn, 381 sret = GNUNET_DISK_fn_read (fn, mem, fs);
392 mem, 382 if ((sret < 0) || (fs != (size_t) sret))
393 fs);
394 if ( (sret < 0) ||
395 (fs != (size_t) sret) )
396 { 383 {
397 LOG (GNUNET_ERROR_TYPE_WARNING, 384 LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Error while reading file `%s'\n"), fn);
398 _("Error while reading file `%s'\n"),
399 fn);
400 GNUNET_free (fn); 385 GNUNET_free (fn);
401 GNUNET_free (mem); 386 GNUNET_free (mem);
402 return GNUNET_SYSERR; 387 return GNUNET_SYSERR;
403 } 388 }
404 LOG (GNUNET_ERROR_TYPE_DEBUG, 389 LOG (GNUNET_ERROR_TYPE_DEBUG, "Deserializing contents of file `%s'\n", fn);
405 "Deserializing contents of file `%s'\n",
406 fn);
407 endsep = strrchr (fn, (int) '/'); 390 endsep = strrchr (fn, (int) '/');
408 if (NULL != endsep) 391 if (NULL != endsep)
409 *endsep = '\0'; 392 *endsep = '\0';
410 ret = GNUNET_CONFIGURATION_deserialize (cfg, 393 ret = GNUNET_CONFIGURATION_deserialize (cfg, mem, fs, fn);
411 mem,
412 fs,
413 fn);
414 GNUNET_free (fn); 394 GNUNET_free (fn);
415 GNUNET_free (mem); 395 GNUNET_free (mem);
416 /* restore dirty flag - anything we set in the meantime 396 /* restore dirty flag - anything we set in the meantime
@@ -444,7 +424,7 @@ GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg)
444 */ 424 */
445char * 425char *
446GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, 426GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg,
447 size_t *size) 427 size_t *size)
448{ 428{
449 struct ConfigSection *sec; 429 struct ConfigSection *sec;
450 struct ConfigEntry *ent; 430 struct ConfigEntry *ent;
@@ -466,16 +446,16 @@ GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg,
466 { 446 {
467 if (NULL != ent->val) 447 if (NULL != ent->val)
468 { 448 {
469 /* if val has any '\n' then they occupy +1 character as '\n'->'\\','n' */ 449 /* if val has any '\n' then they occupy +1 character as '\n'->'\\','n' */
470 pos = ent->val; 450 pos = ent->val;
471 while (NULL != (pos = strstr (pos, "\n"))) 451 while (NULL != (pos = strstr (pos, "\n")))
472 { 452 {
473 m_size++; 453 m_size++;
474 pos++; 454 pos++;
475 } 455 }
476 /* For each key = value pair we need to add 4 characters (2 456 /* For each key = value pair we need to add 4 characters (2
477 spaces and 1 equal-to character and 1 new line) */ 457 spaces and 1 equal-to character and 1 new line) */
478 m_size += strlen (ent->key) + strlen (ent->val) + 4; 458 m_size += strlen (ent->key) + strlen (ent->val) + 4;
479 } 459 }
480 } 460 }
481 /* A new line after section end */ 461 /* A new line after section end */
@@ -498,23 +478,23 @@ GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg,
498 { 478 {
499 if (NULL != ent->val) 479 if (NULL != ent->val)
500 { 480 {
501 val = GNUNET_malloc (strlen (ent->val) * 2 + 1); 481 val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
502 strcpy (val, ent->val); 482 strcpy (val, ent->val);
503 while (NULL != (pos = strstr (val, "\n"))) 483 while (NULL != (pos = strstr (val, "\n")))
504 { 484 {
505 memmove (&pos[2], &pos[1], strlen (&pos[1])); 485 memmove (&pos[2], &pos[1], strlen (&pos[1]));
506 pos[0] = '\\'; 486 pos[0] = '\\';
507 pos[1] = 'n'; 487 pos[1] = 'n';
508 } 488 }
509 len = GNUNET_asprintf (&cbuf, "%s = %s\n", ent->key, val); 489 len = GNUNET_asprintf (&cbuf, "%s = %s\n", ent->key, val);
510 GNUNET_free (val); 490 GNUNET_free (val);
511 GNUNET_memcpy (mem + c_size, cbuf, len); 491 GNUNET_memcpy (mem + c_size, cbuf, len);
512 c_size += len; 492 c_size += len;
513 GNUNET_free (cbuf); 493 GNUNET_free (cbuf);
514 } 494 }
515 } 495 }
516 GNUNET_memcpy (mem + c_size, "\n", 1); 496 GNUNET_memcpy (mem + c_size, "\n", 1);
517 c_size ++; 497 c_size++;
518 sec = sec->next; 498 sec = sec->next;
519 } 499 }
520 GNUNET_assert (c_size == m_size); 500 GNUNET_assert (c_size == m_size);
@@ -548,25 +528,26 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
548 return GNUNET_SYSERR; 528 return GNUNET_SYSERR;
549 } 529 }
550 cfg_buf = GNUNET_CONFIGURATION_serialize (cfg, &size); 530 cfg_buf = GNUNET_CONFIGURATION_serialize (cfg, &size);
551 sret = GNUNET_DISK_fn_write (fn, cfg_buf, size, 531 sret = GNUNET_DISK_fn_write (fn,
552 GNUNET_DISK_PERM_USER_READ 532 cfg_buf,
553 | GNUNET_DISK_PERM_USER_WRITE 533 size,
554 | GNUNET_DISK_PERM_GROUP_READ 534 GNUNET_DISK_PERM_USER_READ |
555 | GNUNET_DISK_PERM_GROUP_WRITE); 535 GNUNET_DISK_PERM_USER_WRITE |
556 if ( (sret < 0) || 536 GNUNET_DISK_PERM_GROUP_READ |
557 (size != (size_t) sret) ) 537 GNUNET_DISK_PERM_GROUP_WRITE);
538 if ((sret < 0) || (size != (size_t) sret))
558 { 539 {
559 GNUNET_free (fn); 540 GNUNET_free (fn);
560 GNUNET_free (cfg_buf); 541 GNUNET_free (cfg_buf);
561 LOG (GNUNET_ERROR_TYPE_WARNING, 542 LOG (GNUNET_ERROR_TYPE_WARNING,
562 "Writing configuration to file `%s' failed\n", 543 "Writing configuration to file `%s' failed\n",
563 filename); 544 filename);
564 cfg->dirty = GNUNET_SYSERR; /* last write failed */ 545 cfg->dirty = GNUNET_SYSERR; /* last write failed */
565 return GNUNET_SYSERR; 546 return GNUNET_SYSERR;
566 } 547 }
567 GNUNET_free (fn); 548 GNUNET_free (fn);
568 GNUNET_free (cfg_buf); 549 GNUNET_free (cfg_buf);
569 cfg->dirty = GNUNET_NO; /* last write succeeded */ 550 cfg->dirty = GNUNET_NO; /* last write succeeded */
570 return GNUNET_OK; 551 return GNUNET_OK;
571} 552}
572 553
@@ -589,7 +570,7 @@ GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
589 for (spos = cfg->sections; NULL != spos; spos = spos->next) 570 for (spos = cfg->sections; NULL != spos; spos = spos->next)
590 for (epos = spos->entries; NULL != epos; epos = epos->next) 571 for (epos = spos->entries; NULL != epos; epos = epos->next)
591 if (NULL != epos->val) 572 if (NULL != epos->val)
592 iter (iter_cls, spos->name, epos->key, epos->val); 573 iter (iter_cls, spos->name, epos->key, epos->val);
593} 574}
594 575
595 576
@@ -602,11 +583,11 @@ GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
602 * @param iter_cls closure for @a iter 583 * @param iter_cls closure for @a iter
603 */ 584 */
604void 585void
605GNUNET_CONFIGURATION_iterate_section_values (const struct 586GNUNET_CONFIGURATION_iterate_section_values (
606 GNUNET_CONFIGURATION_Handle *cfg, 587 const struct GNUNET_CONFIGURATION_Handle *cfg,
607 const char *section, 588 const char *section,
608 GNUNET_CONFIGURATION_Iterator iter, 589 GNUNET_CONFIGURATION_Iterator iter,
609 void *iter_cls) 590 void *iter_cls)
610{ 591{
611 struct ConfigSection *spos; 592 struct ConfigSection *spos;
612 struct ConfigEntry *epos; 593 struct ConfigEntry *epos;
@@ -630,9 +611,10 @@ GNUNET_CONFIGURATION_iterate_section_values (const struct
630 * @param iter_cls closure for @a iter 611 * @param iter_cls closure for @a iter
631 */ 612 */
632void 613void
633GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle *cfg, 614GNUNET_CONFIGURATION_iterate_sections (
634 GNUNET_CONFIGURATION_Section_Iterator iter, 615 const struct GNUNET_CONFIGURATION_Handle *cfg,
635 void *iter_cls) 616 GNUNET_CONFIGURATION_Section_Iterator iter,
617 void *iter_cls)
636{ 618{
637 struct ConfigSection *spos; 619 struct ConfigSection *spos;
638 struct ConfigSection *next; 620 struct ConfigSection *next;
@@ -757,8 +739,8 @@ find_section (const struct GNUNET_CONFIGURATION_Handle *cfg,
757 */ 739 */
758static struct ConfigEntry * 740static struct ConfigEntry *
759find_entry (const struct GNUNET_CONFIGURATION_Handle *cfg, 741find_entry (const struct GNUNET_CONFIGURATION_Handle *cfg,
760 const char *section, 742 const char *section,
761 const char *key) 743 const char *key)
762{ 744{
763 struct ConfigSection *sec; 745 struct ConfigSection *sec;
764 struct ConfigEntry *pos; 746 struct ConfigEntry *pos;
@@ -786,15 +768,14 @@ static void
786compare_entries (void *cls, 768compare_entries (void *cls,
787 const char *section, 769 const char *section,
788 const char *option, 770 const char *option,
789 const char *value) 771 const char *value)
790{ 772{
791 struct DiffHandle *dh = cls; 773 struct DiffHandle *dh = cls;
792 struct ConfigEntry *entNew; 774 struct ConfigEntry *entNew;
793 775
794 entNew = find_entry (dh->cfg_default, section, option); 776 entNew = find_entry (dh->cfg_default, section, option);
795 if ( (NULL != entNew) && 777 if ((NULL != entNew) && (NULL != entNew->val) &&
796 (NULL != entNew->val) && 778 (0 == strcmp (entNew->val, value)))
797 (0 == strcmp (entNew->val, value)) )
798 return; 779 return;
799 GNUNET_CONFIGURATION_set_value_string (dh->cfgDiff, section, option, value); 780 GNUNET_CONFIGURATION_set_value_string (dh->cfgDiff, section, option, value);
800} 781}
@@ -808,8 +789,9 @@ compare_entries (void *cls,
808 * @return configuration with only the differences, never NULL 789 * @return configuration with only the differences, never NULL
809 */ 790 */
810struct GNUNET_CONFIGURATION_Handle * 791struct GNUNET_CONFIGURATION_Handle *
811GNUNET_CONFIGURATION_get_diff (const struct GNUNET_CONFIGURATION_Handle *cfg_default, 792GNUNET_CONFIGURATION_get_diff (
812 const struct GNUNET_CONFIGURATION_Handle *cfg_new) 793 const struct GNUNET_CONFIGURATION_Handle *cfg_default,
794 const struct GNUNET_CONFIGURATION_Handle *cfg_new)
813{ 795{
814 struct DiffHandle diffHandle; 796 struct DiffHandle diffHandle;
815 797
@@ -829,10 +811,10 @@ GNUNET_CONFIGURATION_get_diff (const struct GNUNET_CONFIGURATION_Handle *cfg_def
829 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 811 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
830 */ 812 */
831int 813int
832GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle 814GNUNET_CONFIGURATION_write_diffs (
833 *cfg_default, 815 const struct GNUNET_CONFIGURATION_Handle *cfg_default,
834 const struct GNUNET_CONFIGURATION_Handle 816 const struct GNUNET_CONFIGURATION_Handle *cfg_new,
835 *cfg_new, const char *filename) 817 const char *filename)
836{ 818{
837 int ret; 819 int ret;
838 struct GNUNET_CONFIGURATION_Handle *diff; 820 struct GNUNET_CONFIGURATION_Handle *diff;
@@ -854,7 +836,8 @@ GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle
854 */ 836 */
855void 837void
856GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg, 838GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
857 const char *section, const char *option, 839 const char *section,
840 const char *option,
858 const char *value) 841 const char *value)
859{ 842{
860 struct ConfigSection *sec; 843 struct ConfigSection *sec;
@@ -904,19 +887,13 @@ GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
904void 887void
905GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg, 888GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
906 const char *section, 889 const char *section,
907 const char *option, 890 const char *option,
908 unsigned long long number) 891 unsigned long long number)
909{ 892{
910 char s[64]; 893 char s[64];
911 894
912 GNUNET_snprintf (s, 895 GNUNET_snprintf (s, 64, "%llu", number);
913 64, 896 GNUNET_CONFIGURATION_set_value_string (cfg, section, option, s);
914 "%llu",
915 number);
916 GNUNET_CONFIGURATION_set_value_string (cfg,
917 section,
918 option,
919 s);
920} 897}
921 898
922 899
@@ -930,10 +907,11 @@ GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
930 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 907 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
931 */ 908 */
932int 909int
933GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle *cfg, 910GNUNET_CONFIGURATION_get_value_number (
934 const char *section, 911 const struct GNUNET_CONFIGURATION_Handle *cfg,
935 const char *option, 912 const char *section,
936 unsigned long long *number) 913 const char *option,
914 unsigned long long *number)
937{ 915{
938 struct ConfigEntry *e; 916 struct ConfigEntry *e;
939 char dummy[2]; 917 char dummy[2];
@@ -942,10 +920,7 @@ GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle
942 return GNUNET_SYSERR; 920 return GNUNET_SYSERR;
943 if (NULL == e->val) 921 if (NULL == e->val)
944 return GNUNET_SYSERR; 922 return GNUNET_SYSERR;
945 if (1 != SSCANF (e->val, 923 if (1 != sscanf (e->val, "%llu%1s", number, dummy))
946 "%llu%1s",
947 number,
948 dummy))
949 return GNUNET_SYSERR; 924 return GNUNET_SYSERR;
950 return GNUNET_OK; 925 return GNUNET_OK;
951} 926}
@@ -961,10 +936,11 @@ GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle
961 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 936 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
962 */ 937 */
963int 938int
964GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle *cfg, 939GNUNET_CONFIGURATION_get_value_float (
965 const char *section, 940 const struct GNUNET_CONFIGURATION_Handle *cfg,
966 const char *option, 941 const char *section,
967 float *number) 942 const char *option,
943 float *number)
968{ 944{
969 struct ConfigEntry *e; 945 struct ConfigEntry *e;
970 char dummy[2]; 946 char dummy[2];
@@ -973,16 +949,12 @@ GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle
973 return GNUNET_SYSERR; 949 return GNUNET_SYSERR;
974 if (NULL == e->val) 950 if (NULL == e->val)
975 return GNUNET_SYSERR; 951 return GNUNET_SYSERR;
976 if (1 != SSCANF (e->val, 952 if (1 != sscanf (e->val, "%f%1s", number, dummy))
977 "%f%1s",
978 number,
979 dummy))
980 return GNUNET_SYSERR; 953 return GNUNET_SYSERR;
981 return GNUNET_OK; 954 return GNUNET_OK;
982} 955}
983 956
984 957
985
986/** 958/**
987 * Get a configuration value that should be a relative time. 959 * Get a configuration value that should be a relative time.
988 * 960 *
@@ -993,27 +965,25 @@ GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle
993 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 965 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
994 */ 966 */
995int 967int
996GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle *cfg, 968GNUNET_CONFIGURATION_get_value_time (
997 const char *section, 969 const struct GNUNET_CONFIGURATION_Handle *cfg,
998 const char *option, 970 const char *section,
999 struct GNUNET_TIME_Relative *time) 971 const char *option,
972 struct GNUNET_TIME_Relative *time)
1000{ 973{
1001 struct ConfigEntry *e; 974 struct ConfigEntry *e;
1002 int ret; 975 int ret;
1003 976
1004 if (NULL == (e = find_entry (cfg, 977 if (NULL == (e = find_entry (cfg, section, option)))
1005 section,
1006 option)))
1007 return GNUNET_SYSERR; 978 return GNUNET_SYSERR;
1008 if (NULL == e->val) 979 if (NULL == e->val)
1009 return GNUNET_SYSERR; 980 return GNUNET_SYSERR;
1010 ret = GNUNET_STRINGS_fancy_time_to_relative (e->val, 981 ret = GNUNET_STRINGS_fancy_time_to_relative (e->val, time);
1011 time);
1012 if (GNUNET_OK != ret) 982 if (GNUNET_OK != ret)
1013 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, 983 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
1014 section, 984 section,
1015 option, 985 option,
1016 _("Not a valid relative time specification")); 986 _ ("Not a valid relative time specification"));
1017 return ret; 987 return ret;
1018} 988}
1019 989
@@ -1028,10 +998,11 @@ GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle *c
1028 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 998 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1029 */ 999 */
1030int 1000int
1031GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle *cfg, 1001GNUNET_CONFIGURATION_get_value_size (
1032 const char *section, 1002 const struct GNUNET_CONFIGURATION_Handle *cfg,
1033 const char *option, 1003 const char *section,
1034 unsigned long long *size) 1004 const char *option,
1005 unsigned long long *size)
1035{ 1006{
1036 struct ConfigEntry *e; 1007 struct ConfigEntry *e;
1037 1008
@@ -1054,15 +1025,15 @@ GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle *c
1054 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 1025 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1055 */ 1026 */
1056int 1027int
1057GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle *cfg, 1028GNUNET_CONFIGURATION_get_value_string (
1058 const char *section, 1029 const struct GNUNET_CONFIGURATION_Handle *cfg,
1059 const char *option, 1030 const char *section,
1060 char **value) 1031 const char *option,
1032 char **value)
1061{ 1033{
1062 struct ConfigEntry *e; 1034 struct ConfigEntry *e;
1063 1035
1064 if ( (NULL == (e = find_entry (cfg, section, option))) || 1036 if ((NULL == (e = find_entry (cfg, section, option))) || (NULL == e->val))
1065 (NULL == e->val) )
1066 { 1037 {
1067 *value = NULL; 1038 *value = NULL;
1068 return GNUNET_SYSERR; 1039 return GNUNET_SYSERR;
@@ -1085,11 +1056,12 @@ GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle
1085 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 1056 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1086 */ 1057 */
1087int 1058int
1088GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle *cfg, 1059GNUNET_CONFIGURATION_get_value_choice (
1089 const char *section, 1060 const struct GNUNET_CONFIGURATION_Handle *cfg,
1090 const char *option, 1061 const char *section,
1091 const char *const *choices, 1062 const char *option,
1092 const char **value) 1063 const char *const *choices,
1064 const char **value)
1093{ 1065{
1094 struct ConfigEntry *e; 1066 struct ConfigEntry *e;
1095 unsigned int i; 1067 unsigned int i;
@@ -1102,8 +1074,8 @@ GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle
1102 if (NULL == choices[i]) 1074 if (NULL == choices[i])
1103 { 1075 {
1104 LOG (GNUNET_ERROR_TYPE_ERROR, 1076 LOG (GNUNET_ERROR_TYPE_ERROR,
1105 _("Configuration value '%s' for '%s'" 1077 _ ("Configuration value '%s' for '%s'"
1106 " in section '%s' is not in set of legal choices\n"), 1078 " in section '%s' is not in set of legal choices\n"),
1107 e->val, 1079 e->val,
1108 option, 1080 option,
1109 section); 1081 section);
@@ -1138,10 +1110,8 @@ GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg,
1138 size_t data_size; 1110 size_t data_size;
1139 1111
1140 if (GNUNET_OK != 1112 if (GNUNET_OK !=
1141 (res = GNUNET_CONFIGURATION_get_value_string (cfg, 1113 (res =
1142 section, 1114 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &enc)))
1143 option,
1144 &enc)))
1145 return res; 1115 return res;
1146 data_size = (strlen (enc) * 5) / 8; 1116 data_size = (strlen (enc) * 5) / 8;
1147 if (data_size != buf_size) 1117 if (data_size != buf_size)
@@ -1150,9 +1120,7 @@ GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg,
1150 return GNUNET_SYSERR; 1120 return GNUNET_SYSERR;
1151 } 1121 }
1152 if (GNUNET_OK != 1122 if (GNUNET_OK !=
1153 GNUNET_STRINGS_string_to_data (enc, 1123 GNUNET_STRINGS_string_to_data (enc, strlen (enc), buf, buf_size))
1154 strlen (enc),
1155 buf, buf_size))
1156 { 1124 {
1157 GNUNET_free (enc); 1125 GNUNET_free (enc);
1158 return GNUNET_SYSERR; 1126 return GNUNET_SYSERR;
@@ -1221,17 +1189,15 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
1221 if (depth > 128) 1189 if (depth > 128)
1222 { 1190 {
1223 LOG (GNUNET_ERROR_TYPE_WARNING, 1191 LOG (GNUNET_ERROR_TYPE_WARNING,
1224 _("Recursive expansion suspected, aborting $-expansion for term `%s'\n"), 1192 _ (
1193 "Recursive expansion suspected, aborting $-expansion for term `%s'\n"),
1225 orig); 1194 orig);
1226 return orig; 1195 return orig;
1227 } 1196 }
1228 LOG (GNUNET_ERROR_TYPE_DEBUG, 1197 LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to $-expand %s\n", orig);
1229 "Asked to $-expand %s\n",
1230 orig);
1231 if ('$' != orig[0]) 1198 if ('$' != orig[0])
1232 { 1199 {
1233 LOG (GNUNET_ERROR_TYPE_DEBUG, 1200 LOG (GNUNET_ERROR_TYPE_DEBUG, "Doesn't start with $ - not expanding\n");
1234 "Doesn't start with $ - not expanding\n");
1235 return orig; 1201 return orig;
1236 } 1202 }
1237 erased_char = 0; 1203 erased_char = 0;
@@ -1254,7 +1220,7 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
1254 break; 1220 break;
1255 case '\0': 1221 case '\0':
1256 LOG (GNUNET_ERROR_TYPE_WARNING, 1222 LOG (GNUNET_ERROR_TYPE_WARNING,
1257 _("Missing closing `%s' in option `%s'\n"), 1223 _ ("Missing closing `%s' in option `%s'\n"),
1258 "}", 1224 "}",
1259 orig); 1225 orig);
1260 return orig; 1226 return orig;
@@ -1271,8 +1237,7 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
1271 { 1237 {
1272 *def = '\0'; 1238 *def = '\0';
1273 def++; 1239 def++;
1274 if ( ('-' == *def) || 1240 if (('-' == *def) || ('=' == *def))
1275 ('=' == *def) )
1276 def++; 1241 def++;
1277 def = GNUNET_strdup (def); 1242 def = GNUNET_strdup (def);
1278 } 1243 }
@@ -1282,10 +1247,8 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
1282 start = &orig[1]; 1247 start = &orig[1];
1283 def = NULL; 1248 def = NULL;
1284 i = 0; 1249 i = 0;
1285 while ( (orig[i] != '/') && 1250 while ((orig[i] != '/') && (orig[i] != '\\') && (orig[i] != '\0') &&
1286 (orig[i] != '\\') && 1251 (orig[i] != ' '))
1287 (orig[i] != '\0') &&
1288 (orig[i] != ' ') )
1289 i++; 1252 i++;
1290 if (orig[i] == '\0') 1253 if (orig[i] == '\0')
1291 { 1254 {
@@ -1305,10 +1268,7 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
1305 post, 1268 post,
1306 def); 1269 def);
1307 if (GNUNET_OK != 1270 if (GNUNET_OK !=
1308 GNUNET_CONFIGURATION_get_value_string (cfg, 1271 GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", start, &prefix))
1309 "PATHS",
1310 start,
1311 &prefix))
1312 { 1272 {
1313 if (NULL == (env = getenv (start))) 1273 if (NULL == (env = getenv (start)))
1314 { 1274 {
@@ -1322,15 +1282,17 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
1322 if (erased_pos) 1282 if (erased_pos)
1323 *erased_pos = erased_char; 1283 *erased_pos = erased_char;
1324 LOG (GNUNET_ERROR_TYPE_WARNING, 1284 LOG (GNUNET_ERROR_TYPE_WARNING,
1325 _("Failed to expand `%s' in `%s' as it is neither found in [PATHS] nor defined as an environmental variable\n"), 1285 _ (
1326 start, orig); 1286 "Failed to expand `%s' in `%s' as it is neither found in [PATHS] nor defined as an environmental variable\n"),
1287 start,
1288 orig);
1327 GNUNET_free (start); 1289 GNUNET_free (start);
1328 return orig; 1290 return orig;
1329 } 1291 }
1330 prefix = GNUNET_strdup (env); 1292 prefix = GNUNET_strdup (env);
1331 } 1293 }
1332 prefix = GNUNET_CONFIGURATION_expand_dollar (cfg, prefix); 1294 prefix = GNUNET_CONFIGURATION_expand_dollar (cfg, prefix);
1333 if ( (erased_pos) && ('}' != erased_char) ) 1295 if ((erased_pos) && ('}' != erased_char))
1334 { 1296 {
1335 len = strlen (prefix) + 1; 1297 len = strlen (prefix) + 1;
1336 prefix = GNUNET_realloc (prefix, len + 1); 1298 prefix = GNUNET_realloc (prefix, len + 1);
@@ -1364,8 +1326,9 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
1364 * @return $-expanded string 1326 * @return $-expanded string
1365 */ 1327 */
1366char * 1328char *
1367GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg, 1329GNUNET_CONFIGURATION_expand_dollar (
1368 char *orig) 1330 const struct GNUNET_CONFIGURATION_Handle *cfg,
1331 char *orig)
1369{ 1332{
1370 char *dup; 1333 char *dup;
1371 size_t i; 1334 size_t i;
@@ -1397,18 +1360,18 @@ GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cf
1397 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 1360 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1398 */ 1361 */
1399int 1362int
1400GNUNET_CONFIGURATION_get_value_filename (const struct GNUNET_CONFIGURATION_Handle *cfg, 1363GNUNET_CONFIGURATION_get_value_filename (
1401 const char *section, 1364 const struct GNUNET_CONFIGURATION_Handle *cfg,
1402 const char *option, 1365 const char *section,
1403 char **value) 1366 const char *option,
1367 char **value)
1404{ 1368{
1405 char *tmp; 1369 char *tmp;
1406 1370
1407 if (GNUNET_OK != 1371 if (GNUNET_OK !=
1408 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &tmp)) 1372 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &tmp))
1409 { 1373 {
1410 LOG (GNUNET_ERROR_TYPE_DEBUG, 1374 LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to retrieve filename\n");
1411 "Failed to retrieve filename\n");
1412 *value = NULL; 1375 *value = NULL;
1413 return GNUNET_SYSERR; 1376 return GNUNET_SYSERR;
1414 } 1377 }
@@ -1431,16 +1394,17 @@ GNUNET_CONFIGURATION_get_value_filename (const struct GNUNET_CONFIGURATION_Handl
1431 * @return #GNUNET_YES, #GNUNET_NO or #GNUNET_SYSERR 1394 * @return #GNUNET_YES, #GNUNET_NO or #GNUNET_SYSERR
1432 */ 1395 */
1433int 1396int
1434GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle *cfg, 1397GNUNET_CONFIGURATION_get_value_yesno (
1435 const char *section, 1398 const struct GNUNET_CONFIGURATION_Handle *cfg,
1436 const char *option) 1399 const char *section,
1400 const char *option)
1437{ 1401{
1438 static const char *yesno[] = { "YES", "NO", NULL }; 1402 static const char *yesno[] = {"YES", "NO", NULL};
1439 const char *val; 1403 const char *val;
1440 int ret; 1404 int ret;
1441 1405
1442 ret = 1406 ret =
1443 GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val); 1407 GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val);
1444 if (ret == GNUNET_SYSERR) 1408 if (ret == GNUNET_SYSERR)
1445 return ret; 1409 return ret;
1446 if (val == yesno[0]) 1410 if (val == yesno[0])
@@ -1460,11 +1424,12 @@ GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle *
1460 * @return number of filenames iterated over, -1 on error 1424 * @return number of filenames iterated over, -1 on error
1461 */ 1425 */
1462int 1426int
1463GNUNET_CONFIGURATION_iterate_value_filenames (const struct GNUNET_CONFIGURATION_Handle *cfg, 1427GNUNET_CONFIGURATION_iterate_value_filenames (
1464 const char *section, 1428 const struct GNUNET_CONFIGURATION_Handle *cfg,
1465 const char *option, 1429 const char *section,
1466 GNUNET_FileNameCallback cb, 1430 const char *option,
1467 void *cb_cls) 1431 GNUNET_FileNameCallback cb,
1432 void *cb_cls)
1468{ 1433{
1469 char *list; 1434 char *list;
1470 char *pos; 1435 char *pos;
@@ -1590,20 +1555,23 @@ test_match (void *cls, const char *fn)
1590 * #GNUNET_SYSERR on error 1555 * #GNUNET_SYSERR on error
1591 */ 1556 */
1592int 1557int
1593GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle *cfg, 1558GNUNET_CONFIGURATION_append_value_filename (
1594 const char *section, 1559 struct GNUNET_CONFIGURATION_Handle *cfg,
1595 const char *option, 1560 const char *section,
1596 const char *value) 1561 const char *option,
1562 const char *value)
1597{ 1563{
1598 char *escaped; 1564 char *escaped;
1599 char *old; 1565 char *old;
1600 char *nw; 1566 char *nw;
1601 1567
1602 if (GNUNET_SYSERR == 1568 if (GNUNET_SYSERR ==
1603 GNUNET_CONFIGURATION_iterate_value_filenames (cfg, section, option, 1569 GNUNET_CONFIGURATION_iterate_value_filenames (cfg,
1570 section,
1571 option,
1604 &test_match, 1572 &test_match,
1605 (void *) value)) 1573 (void *) value))
1606 return GNUNET_NO; /* already exists */ 1574 return GNUNET_NO; /* already exists */
1607 if (GNUNET_OK != 1575 if (GNUNET_OK !=
1608 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old)) 1576 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old))
1609 old = GNUNET_strdup (""); 1577 old = GNUNET_strdup ("");
@@ -1634,10 +1602,11 @@ GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle *
1634 * #GNUNET_SYSERR on error 1602 * #GNUNET_SYSERR on error
1635 */ 1603 */
1636int 1604int
1637GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle 1605GNUNET_CONFIGURATION_remove_value_filename (
1638 *cfg, const char *section, 1606 struct GNUNET_CONFIGURATION_Handle *cfg,
1639 const char *option, 1607 const char *section,
1640 const char *value) 1608 const char *option,
1609 const char *value)
1641{ 1610{
1642 char *list; 1611 char *list;
1643 char *pos; 1612 char *pos;
@@ -1719,16 +1688,14 @@ static int
1719parse_configuration_file (void *cls, const char *filename) 1688parse_configuration_file (void *cls, const char *filename)
1720{ 1689{
1721 struct GNUNET_CONFIGURATION_Handle *cfg = cls; 1690 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
1722 char * ext; 1691 char *ext;
1723 int ret; 1692 int ret;
1724 1693
1725 /* Examine file extension */ 1694 /* Examine file extension */
1726 ext = strrchr (filename, '.'); 1695 ext = strrchr (filename, '.');
1727 if ((NULL == ext) || (0 != strcmp (ext, ".conf"))) 1696 if ((NULL == ext) || (0 != strcmp (ext, ".conf")))
1728 { 1697 {
1729 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1698 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Skipping file `%s'\n", filename);
1730 "Skipping file `%s'\n",
1731 filename);
1732 return GNUNET_OK; 1699 return GNUNET_OK;
1733 } 1700 }
1734 1701
@@ -1747,13 +1714,11 @@ parse_configuration_file (void *cls, const char *filename)
1747 */ 1714 */
1748int 1715int
1749GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, 1716GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg,
1750 const char *defaults_d) 1717 const char *defaults_d)
1751{ 1718{
1752 if (GNUNET_SYSERR == 1719 if (GNUNET_SYSERR ==
1753 GNUNET_DISK_directory_scan (defaults_d, 1720 GNUNET_DISK_directory_scan (defaults_d, &parse_configuration_file, cfg))
1754 &parse_configuration_file, 1721 return GNUNET_SYSERR; /* no configuration at all found */
1755 cfg))
1756 return GNUNET_SYSERR; /* no configuration at all found */
1757 return GNUNET_OK; 1722 return GNUNET_OK;
1758} 1723}
1759 1724
diff --git a/src/util/container_bloomfilter.c b/src/util/container_bloomfilter.c
index a41c0cf8a..fe7d86421 100644
--- a/src/util/container_bloomfilter.c
+++ b/src/util/container_bloomfilter.c
@@ -42,11 +42,17 @@
42#include "platform.h" 42#include "platform.h"
43#include "gnunet_util_lib.h" 43#include "gnunet_util_lib.h"
44 44
45#define LOG(kind,...) GNUNET_log_from (kind, "util-container-bloomfilter", __VA_ARGS__) 45#define LOG(kind, ...) \
46 GNUNET_log_from (kind, "util-container-bloomfilter", __VA_ARGS__)
46 47
47#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-container-bloomfilter", syscall) 48#define LOG_strerror(kind, syscall) \
49 GNUNET_log_from_strerror (kind, "util-container-bloomfilter", syscall)
48 50
49#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-container-bloomfilter", syscall, filename) 51#define LOG_strerror_FILE(kind, syscall, filename) \
52 GNUNET_log_from_strerror_file (kind, \
53 "util-container-bloomfilter", \
54 syscall, \
55 filename)
50 56
51struct GNUNET_CONTAINER_BloomFilter 57struct GNUNET_CONTAINER_BloomFilter
52{ 58{
@@ -75,7 +81,6 @@ struct GNUNET_CONTAINER_BloomFilter
75 * Size of bitArray in bytes 81 * Size of bitArray in bytes
76 */ 82 */
77 size_t bitArraySize; 83 size_t bitArraySize;
78
79}; 84};
80 85
81 86
@@ -86,8 +91,8 @@ struct GNUNET_CONTAINER_BloomFilter
86 * @return addresses set per element in the bf 91 * @return addresses set per element in the bf
87 */ 92 */
88size_t 93size_t
89GNUNET_CONTAINER_bloomfilter_get_element_addresses (const struct GNUNET_CONTAINER_BloomFilter 94GNUNET_CONTAINER_bloomfilter_get_element_addresses (
90 *bf) 95 const struct GNUNET_CONTAINER_BloomFilter *bf)
91{ 96{
92 if (bf == NULL) 97 if (bf == NULL)
93 return 0; 98 return 0;
@@ -102,8 +107,8 @@ GNUNET_CONTAINER_bloomfilter_get_element_addresses (const struct GNUNET_CONTAINE
102 * @return number of bytes used for the data of the bloom filter 107 * @return number of bytes used for the data of the bloom filter
103 */ 108 */
104size_t 109size_t
105GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter 110GNUNET_CONTAINER_bloomfilter_get_size (
106 *bf) 111 const struct GNUNET_CONTAINER_BloomFilter *bf)
107{ 112{
108 if (bf == NULL) 113 if (bf == NULL)
109 return 0; 114 return 0;
@@ -118,10 +123,11 @@ GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter
118 * @return copy of the bf 123 * @return copy of the bf
119 */ 124 */
120struct GNUNET_CONTAINER_BloomFilter * 125struct GNUNET_CONTAINER_BloomFilter *
121GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter 126GNUNET_CONTAINER_bloomfilter_copy (
122 *bf) 127 const struct GNUNET_CONTAINER_BloomFilter *bf)
123{ 128{
124 return GNUNET_CONTAINER_bloomfilter_init (bf->bitArray, bf->bitArraySize, 129 return GNUNET_CONTAINER_bloomfilter_init (bf->bitArray,
130 bf->bitArraySize,
125 bf->addressesPerElement); 131 bf->addressesPerElement);
126} 132}
127 133
@@ -193,7 +199,8 @@ testBit (char *bitArray, unsigned int bitIdx)
193 * @param fh A file to keep the 4 bit address usage counters in 199 * @param fh A file to keep the 4 bit address usage counters in
194 */ 200 */
195static void 201static void
196incrementBit (char *bitArray, unsigned int bitIdx, 202incrementBit (char *bitArray,
203 unsigned int bitIdx,
197 const struct GNUNET_DISK_FileHandle *fh) 204 const struct GNUNET_DISK_FileHandle *fh)
198{ 205{
199 off_t fileSlot; 206 off_t fileSlot;
@@ -241,7 +248,8 @@ incrementBit (char *bitArray, unsigned int bitIdx,
241 * @param fh A file to keep the 4bit address usage counters in 248 * @param fh A file to keep the 4bit address usage counters in
242 */ 249 */
243static void 250static void
244decrementBit (char *bitArray, unsigned int bitIdx, 251decrementBit (char *bitArray,
252 unsigned int bitIdx,
245 const struct GNUNET_DISK_FileHandle *fh) 253 const struct GNUNET_DISK_FileHandle *fh)
246{ 254{
247 off_t fileslot; 255 off_t fileslot;
@@ -251,15 +259,16 @@ decrementBit (char *bitArray, unsigned int bitIdx,
251 unsigned int targetLoc; 259 unsigned int targetLoc;
252 260
253 if (GNUNET_DISK_handle_invalid (fh)) 261 if (GNUNET_DISK_handle_invalid (fh))
254 return; /* cannot decrement! */ 262 return; /* cannot decrement! */
255 /* Each char slot in the counter file holds two 4 bit counters */ 263 /* Each char slot in the counter file holds two 4 bit counters */
256 fileslot = bitIdx / 2; 264 fileslot = bitIdx / 2;
257 targetLoc = bitIdx % 2; 265 targetLoc = bitIdx % 2;
258 if (GNUNET_SYSERR == GNUNET_DISK_file_seek (fh, fileslot, GNUNET_DISK_SEEK_SET)) 266 if (GNUNET_SYSERR ==
259 { 267 GNUNET_DISK_file_seek (fh, fileslot, GNUNET_DISK_SEEK_SET))
260 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "seek"); 268 {
261 return; 269 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "seek");
262 } 270 return;
271 }
263 if (1 != GNUNET_DISK_file_read (fh, &value, 1)) 272 if (1 != GNUNET_DISK_file_read (fh, &value, 1))
264 value = 0; 273 value = 0;
265 low = value & 0xF; 274 low = value & 0xF;
@@ -285,11 +294,12 @@ decrementBit (char *bitArray, unsigned int bitIdx,
285 } 294 }
286 } 295 }
287 value = ((high << 4) | low); 296 value = ((high << 4) | low);
288 if (GNUNET_SYSERR == GNUNET_DISK_file_seek (fh, fileslot, GNUNET_DISK_SEEK_SET)) 297 if (GNUNET_SYSERR ==
289 { 298 GNUNET_DISK_file_seek (fh, fileslot, GNUNET_DISK_SEEK_SET))
290 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "seek"); 299 {
291 return; 300 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "seek");
292 } 301 return;
302 }
293 GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1)); 303 GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1));
294} 304}
295 305
@@ -319,13 +329,13 @@ make_empty_file (const struct GNUNET_DISK_FileHandle *fh, size_t size)
319 { 329 {
320 res = GNUNET_DISK_file_write (fh, buffer, sizeof (buffer)); 330 res = GNUNET_DISK_file_write (fh, buffer, sizeof (buffer));
321 if (res >= 0) 331 if (res >= 0)
322 bytesleft -= res; 332 bytesleft -= res;
323 } 333 }
324 else 334 else
325 { 335 {
326 res = GNUNET_DISK_file_write (fh, buffer, bytesleft); 336 res = GNUNET_DISK_file_write (fh, buffer, bytesleft);
327 if (res >= 0) 337 if (res >= 0)
328 bytesleft -= res; 338 bytesleft -= res;
329 } 339 }
330 if (GNUNET_SYSERR == res) 340 if (GNUNET_SYSERR == res)
331 return GNUNET_SYSERR; 341 return GNUNET_SYSERR;
@@ -346,7 +356,7 @@ make_empty_file (const struct GNUNET_DISK_FileHandle *fh, size_t size)
346 * @return GNUNET_YES to continue, GNUNET_NO to stop early 356 * @return GNUNET_YES to continue, GNUNET_NO to stop early
347 */ 357 */
348typedef int (*BitIterator) (void *cls, 358typedef int (*BitIterator) (void *cls,
349 const struct GNUNET_CONTAINER_BloomFilter * bf, 359 const struct GNUNET_CONTAINER_BloomFilter *bf,
350 unsigned int bit); 360 unsigned int bit);
351 361
352 362
@@ -361,7 +371,9 @@ typedef int (*BitIterator) (void *cls,
361 */ 371 */
362static void 372static void
363iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf, 373iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf,
364 BitIterator callback, void *arg, const struct GNUNET_HashCode *key) 374 BitIterator callback,
375 void *arg,
376 const struct GNUNET_HashCode *key)
365{ 377{
366 struct GNUNET_HashCode tmp[2]; 378 struct GNUNET_HashCode tmp[2];
367 int bitCount; 379 int bitCount;
@@ -378,9 +390,10 @@ iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf,
378 while (slot < (sizeof (struct GNUNET_HashCode) / sizeof (uint32_t))) 390 while (slot < (sizeof (struct GNUNET_HashCode) / sizeof (uint32_t)))
379 { 391 {
380 if (GNUNET_YES != 392 if (GNUNET_YES !=
381 callback (arg, bf, 393 callback (arg,
382 ntohl ((((uint32_t *) & tmp[round & 1])[slot])) % 394 bf,
383 ((bf->bitArraySize * 8LL)))) 395 ntohl ((((uint32_t *) &tmp[round & 1])[slot])) %
396 ((bf->bitArraySize * 8LL))))
384 return; 397 return;
385 slot++; 398 slot++;
386 bitCount--; 399 bitCount--;
@@ -389,7 +402,8 @@ iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf,
389 } 402 }
390 if (bitCount > 0) 403 if (bitCount > 0)
391 { 404 {
392 GNUNET_CRYPTO_hash (&tmp[round & 1], sizeof (struct GNUNET_HashCode), 405 GNUNET_CRYPTO_hash (&tmp[round & 1],
406 sizeof (struct GNUNET_HashCode),
393 &tmp[(round + 1) & 1]); 407 &tmp[(round + 1) & 1]);
394 round++; 408 round++;
395 slot = 0; 409 slot = 0;
@@ -407,7 +421,8 @@ iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf,
407 * @return GNUNET_YES 421 * @return GNUNET_YES
408 */ 422 */
409static int 423static int
410incrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, 424incrementBitCallback (void *cls,
425 const struct GNUNET_CONTAINER_BloomFilter *bf,
411 unsigned int bit) 426 unsigned int bit)
412{ 427{
413 struct GNUNET_CONTAINER_BloomFilter *b = cls; 428 struct GNUNET_CONTAINER_BloomFilter *b = cls;
@@ -426,7 +441,8 @@ incrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf,
426 * @return GNUNET_YES 441 * @return GNUNET_YES
427 */ 442 */
428static int 443static int
429decrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, 444decrementBitCallback (void *cls,
445 const struct GNUNET_CONTAINER_BloomFilter *bf,
430 unsigned int bit) 446 unsigned int bit)
431{ 447{
432 struct GNUNET_CONTAINER_BloomFilter *b = cls; 448 struct GNUNET_CONTAINER_BloomFilter *b = cls;
@@ -445,7 +461,8 @@ decrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf,
445 * @return YES if the bit is set, NO if not 461 * @return YES if the bit is set, NO if not
446 */ 462 */
447static int 463static int
448testBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, 464testBitCallback (void *cls,
465 const struct GNUNET_CONTAINER_BloomFilter *bf,
449 unsigned int bit) 466 unsigned int bit)
450{ 467{
451 int *arg = cls; 468 int *arg = cls;
@@ -472,7 +489,8 @@ testBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf,
472 * @return the bloomfilter 489 * @return the bloomfilter
473 */ 490 */
474struct GNUNET_CONTAINER_BloomFilter * 491struct GNUNET_CONTAINER_BloomFilter *
475GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, 492GNUNET_CONTAINER_bloomfilter_load (const char *filename,
493 size_t size,
476 unsigned int k) 494 unsigned int k)
477{ 495{
478 struct GNUNET_CONTAINER_BloomFilter *bf; 496 struct GNUNET_CONTAINER_BloomFilter *bf;
@@ -489,25 +507,22 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
489 if (size < BUFFSIZE) 507 if (size < BUFFSIZE)
490 size = BUFFSIZE; 508 size = BUFFSIZE;
491 ui = 1; 509 ui = 1;
492 while ( (ui < size) && 510 while ((ui < size) && (ui * 2 > ui))
493 (ui * 2 > ui) )
494 ui *= 2; 511 ui *= 2;
495 size = ui; /* make sure it's a power of 2 */ 512 size = ui; /* make sure it's a power of 2 */
496 513
497 bf = GNUNET_new (struct GNUNET_CONTAINER_BloomFilter); 514 bf = GNUNET_new (struct GNUNET_CONTAINER_BloomFilter);
498 /* Try to open a bloomfilter file */ 515 /* Try to open a bloomfilter file */
499 if (GNUNET_YES == GNUNET_DISK_file_test (filename)) 516 if (GNUNET_YES == GNUNET_DISK_file_test (filename))
500 bf->fh = 517 bf->fh = GNUNET_DISK_file_open (filename,
501 GNUNET_DISK_file_open (filename, 518 GNUNET_DISK_OPEN_READWRITE,
502 GNUNET_DISK_OPEN_READWRITE, 519 GNUNET_DISK_PERM_USER_READ |
503 GNUNET_DISK_PERM_USER_READ | 520 GNUNET_DISK_PERM_USER_WRITE);
504 GNUNET_DISK_PERM_USER_WRITE);
505 if (NULL != bf->fh) 521 if (NULL != bf->fh)
506 { 522 {
507 /* file existed, try to read it! */ 523 /* file existed, try to read it! */
508 must_read = GNUNET_YES; 524 must_read = GNUNET_YES;
509 if (GNUNET_OK != 525 if (GNUNET_OK != GNUNET_DISK_file_handle_size (bf->fh, &fsize))
510 GNUNET_DISK_file_handle_size (bf->fh, &fsize))
511 { 526 {
512 GNUNET_DISK_file_close (bf->fh); 527 GNUNET_DISK_file_close (bf->fh);
513 GNUNET_free (bf); 528 GNUNET_free (bf);
@@ -516,22 +531,22 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
516 if (0 == fsize) 531 if (0 == fsize)
517 { 532 {
518 /* found existing empty file, just overwrite */ 533 /* found existing empty file, just overwrite */
519 if (GNUNET_OK != 534 if (GNUNET_OK != make_empty_file (bf->fh, size * 4LL))
520 make_empty_file (bf->fh, size * 4LL))
521 { 535 {
522 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 536 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "write");
523 "write"); 537 GNUNET_DISK_file_close (bf->fh);
524 GNUNET_DISK_file_close (bf->fh); 538 GNUNET_free (bf);
525 GNUNET_free (bf); 539 return NULL;
526 return NULL;
527 } 540 }
528 } 541 }
529 else if (fsize != ((off_t) size) * 4LL) 542 else if (fsize != ((off_t) size) * 4LL)
530 { 543 {
531 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 544 GNUNET_log (
532 _("Size of file on disk is incorrect for this Bloom filter (want %llu, have %llu)\n"), 545 GNUNET_ERROR_TYPE_ERROR,
533 (unsigned long long) (size * 4LL), 546 _ (
534 (unsigned long long) fsize); 547 "Size of file on disk is incorrect for this Bloom filter (want %llu, have %llu)\n"),
548 (unsigned long long) (size * 4LL),
549 (unsigned long long) fsize);
535 GNUNET_DISK_file_close (bf->fh); 550 GNUNET_DISK_file_close (bf->fh);
536 GNUNET_free (bf); 551 GNUNET_free (bf);
537 return NULL; 552 return NULL;
@@ -541,21 +556,19 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
541 { 556 {
542 /* file did not exist, don't read, just create */ 557 /* file did not exist, don't read, just create */
543 must_read = GNUNET_NO; 558 must_read = GNUNET_NO;
544 bf->fh = 559 bf->fh = GNUNET_DISK_file_open (filename,
545 GNUNET_DISK_file_open (filename, 560 GNUNET_DISK_OPEN_CREATE |
546 GNUNET_DISK_OPEN_CREATE | 561 GNUNET_DISK_OPEN_READWRITE,
547 GNUNET_DISK_OPEN_READWRITE, 562 GNUNET_DISK_PERM_USER_READ |
548 GNUNET_DISK_PERM_USER_READ | 563 GNUNET_DISK_PERM_USER_WRITE);
549 GNUNET_DISK_PERM_USER_WRITE);
550 if (NULL == bf->fh) 564 if (NULL == bf->fh)
551 { 565 {
552 GNUNET_free (bf); 566 GNUNET_free (bf);
553 return NULL; 567 return NULL;
554 } 568 }
555 if (GNUNET_OK != make_empty_file (bf->fh, size * 4LL)) 569 if (GNUNET_OK != make_empty_file (bf->fh, size * 4LL))
556 { 570 {
557 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 571 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "write");
558 "write");
559 GNUNET_DISK_file_close (bf->fh); 572 GNUNET_DISK_file_close (bf->fh);
560 GNUNET_free (bf); 573 GNUNET_free (bf);
561 return NULL; 574 return NULL;
@@ -583,14 +596,10 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
583 { 596 {
584 int res; 597 int res;
585 598
586 res = GNUNET_DISK_file_read (bf->fh, 599 res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE);
587 rbuff,
588 BUFFSIZE);
589 if (res == -1) 600 if (res == -1)
590 { 601 {
591 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, 602 LOG_strerror_FILE (GNUNET_ERROR_TYPE_WARNING, "read", bf->filename);
592 "read",
593 bf->filename);
594 GNUNET_free (rbuff); 603 GNUNET_free (rbuff);
595 GNUNET_free (bf->filename); 604 GNUNET_free (bf->filename);
596 GNUNET_DISK_file_close (bf->fh); 605 GNUNET_DISK_file_close (bf->fh);
@@ -598,7 +607,7 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
598 return NULL; 607 return NULL;
599 } 608 }
600 if (res == 0) 609 if (res == 0)
601 break; /* is ok! we just did not use that many bits yet */ 610 break; /* is ok! we just did not use that many bits yet */
602 for (i = 0; i < res; i++) 611 for (i = 0; i < res; i++)
603 { 612 {
604 if ((rbuff[i] & 0x0F) != 0) 613 if ((rbuff[i] & 0x0F) != 0)
@@ -608,7 +617,7 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
608 } 617 }
609 if (res < BUFFSIZE) 618 if (res < BUFFSIZE)
610 break; 619 break;
611 pos += BUFFSIZE * 2; /* 2 bits per byte in the buffer */ 620 pos += BUFFSIZE * 2; /* 2 bits per byte in the buffer */
612 } 621 }
613 GNUNET_free (rbuff); 622 GNUNET_free (rbuff);
614 return bf; 623 return bf;
@@ -629,7 +638,8 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
629 * @return the bloomfilter 638 * @return the bloomfilter
630 */ 639 */
631struct GNUNET_CONTAINER_BloomFilter * 640struct GNUNET_CONTAINER_BloomFilter *
632GNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size, 641GNUNET_CONTAINER_bloomfilter_init (const char *data,
642 size_t size,
633 unsigned int k) 643 unsigned int k)
634{ 644{
635 struct GNUNET_CONTAINER_BloomFilter *bf; 645 struct GNUNET_CONTAINER_BloomFilter *bf;
@@ -663,9 +673,10 @@ GNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size,
663 * @return #GNUNET_SYSERR if the data array is not big enough 673 * @return #GNUNET_SYSERR if the data array is not big enough
664 */ 674 */
665int 675int
666GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct 676GNUNET_CONTAINER_bloomfilter_get_raw_data (
667 GNUNET_CONTAINER_BloomFilter *bf, 677 const struct GNUNET_CONTAINER_BloomFilter *bf,
668 char *data, size_t size) 678 char *data,
679 size_t size)
669{ 680{
670 if (NULL == bf) 681 if (NULL == bf)
671 return GNUNET_SYSERR; 682 return GNUNET_SYSERR;
@@ -721,8 +732,9 @@ GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter *bf)
721 * @return #GNUNET_YES if the element is in the filter, #GNUNET_NO if not 732 * @return #GNUNET_YES if the element is in the filter, #GNUNET_NO if not
722 */ 733 */
723int 734int
724GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter *bf, 735GNUNET_CONTAINER_bloomfilter_test (
725 const struct GNUNET_HashCode * e) 736 const struct GNUNET_CONTAINER_BloomFilter *bf,
737 const struct GNUNET_HashCode *e)
726{ 738{
727 int res; 739 int res;
728 740
@@ -742,7 +754,7 @@ GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter *bf
742 */ 754 */
743void 755void
744GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf, 756GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf,
745 const struct GNUNET_HashCode * e) 757 const struct GNUNET_HashCode *e)
746{ 758{
747 if (NULL == bf) 759 if (NULL == bf)
748 return; 760 return;
@@ -763,7 +775,7 @@ GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf,
763int 775int
764GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, 776GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
765 const char *data, 777 const char *data,
766 size_t size) 778 size_t size)
767{ 779{
768 unsigned int i; 780 unsigned int i;
769 unsigned int n; 781 unsigned int n;
@@ -796,8 +808,9 @@ GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
796 * @return #GNUNET_OK on success 808 * @return #GNUNET_OK on success
797 */ 809 */
798int 810int
799GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf, 811GNUNET_CONTAINER_bloomfilter_or2 (
800 const struct GNUNET_CONTAINER_BloomFilter *to_or) 812 struct GNUNET_CONTAINER_BloomFilter *bf,
813 const struct GNUNET_CONTAINER_BloomFilter *to_or)
801{ 814{
802 unsigned int i; 815 unsigned int i;
803 unsigned int n; 816 unsigned int n;
@@ -839,10 +852,7 @@ GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf,
839 return; 852 return;
840 if (NULL == bf->filename) 853 if (NULL == bf->filename)
841 return; 854 return;
842 iterateBits (bf, 855 iterateBits (bf, &decrementBitCallback, bf, e);
843 &decrementBitCallback,
844 bf,
845 e);
846} 856}
847 857
848/** 858/**
@@ -860,7 +870,7 @@ void
860GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf, 870GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf,
861 GNUNET_CONTAINER_HashCodeIterator iterator, 871 GNUNET_CONTAINER_HashCodeIterator iterator,
862 void *iterator_cls, 872 void *iterator_cls,
863 size_t size, 873 size_t size,
864 unsigned int k) 874 unsigned int k)
865{ 875{
866 struct GNUNET_HashCode hc; 876 struct GNUNET_HashCode hc;
@@ -870,17 +880,14 @@ GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf,
870 i = 1; 880 i = 1;
871 while (i < size) 881 while (i < size)
872 i *= 2; 882 i *= 2;
873 size = i; /* make sure it's a power of 2 */ 883 size = i; /* make sure it's a power of 2 */
874 bf->addressesPerElement = k; 884 bf->addressesPerElement = k;
875 bf->bitArraySize = size; 885 bf->bitArraySize = size;
876 bf->bitArray = GNUNET_malloc (size); 886 bf->bitArray = GNUNET_malloc (size);
877 if (NULL != bf->filename) 887 if (NULL != bf->filename)
878 make_empty_file (bf->fh, 888 make_empty_file (bf->fh, bf->bitArraySize * 4LL);
879 bf->bitArraySize * 4LL); 889 while (GNUNET_YES == iterator (iterator_cls, &hc))
880 while (GNUNET_YES == iterator (iterator_cls, 890 GNUNET_CONTAINER_bloomfilter_add (bf, &hc);
881 &hc))
882 GNUNET_CONTAINER_bloomfilter_add (bf,
883 &hc);
884} 891}
885 892
886/* end of container_bloomfilter.c */ 893/* end of container_bloomfilter.c */
diff --git a/src/util/crypto_ecc_setup.c b/src/util/crypto_ecc_setup.c
index 1031b302e..c556d805d 100644
--- a/src/util/crypto_ecc_setup.c
+++ b/src/util/crypto_ecc_setup.c
@@ -27,18 +27,29 @@
27#include <gcrypt.h> 27#include <gcrypt.h>
28#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
29 29
30#define LOG(kind,...) GNUNET_log_from (kind, "util-crypto-ecc", __VA_ARGS__) 30#define LOG(kind, ...) GNUNET_log_from (kind, "util-crypto-ecc", __VA_ARGS__)
31 31
32#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-crypto-ecc", syscall) 32#define LOG_STRERROR(kind, syscall) \
33 GNUNET_log_from_strerror (kind, "util-crypto-ecc", syscall)
33 34
34#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-crypto-ecc", syscall, filename) 35#define LOG_STRERROR_FILE(kind, syscall, filename) \
36 GNUNET_log_from_strerror_file (kind, "util-crypto-ecc", syscall, filename)
35 37
36/** 38/**
37 * Log an error message at log-level 'level' that indicates 39 * Log an error message at log-level 'level' that indicates
38 * a failure of the command 'cmd' with the message given 40 * a failure of the command 'cmd' with the message given
39 * by gcry_strerror(rc). 41 * by gcry_strerror(rc).
40 */ 42 */
41#define LOG_GCRY(level, cmd, rc) do { LOG(level, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, gcry_strerror(rc)); } while(0) 43#define LOG_GCRY(level, cmd, rc) \
44 do \
45 { \
46 LOG (level, \
47 _ ("`%s' failed at %s:%d with error: %s\n"), \
48 cmd, \
49 __FILE__, \
50 __LINE__, \
51 gcry_strerror (rc)); \
52 } while (0)
42 53
43 54
44/** 55/**
@@ -86,11 +97,12 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename)
86 return NULL; 97 return NULL;
87 while (GNUNET_YES != GNUNET_DISK_file_test (filename)) 98 while (GNUNET_YES != GNUNET_DISK_file_test (filename))
88 { 99 {
89 fd = GNUNET_DISK_file_open (filename, 100 fd =
90 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE 101 GNUNET_DISK_file_open (filename,
91 | GNUNET_DISK_OPEN_FAILIFEXISTS, 102 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE |
92 GNUNET_DISK_PERM_USER_READ | 103 GNUNET_DISK_OPEN_FAILIFEXISTS,
93 GNUNET_DISK_PERM_USER_WRITE); 104 GNUNET_DISK_PERM_USER_READ |
105 GNUNET_DISK_PERM_USER_WRITE);
94 if (NULL == fd) 106 if (NULL == fd)
95 { 107 {
96 if (EEXIST == errno) 108 if (EEXIST == errno)
@@ -98,10 +110,10 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename)
98 if (GNUNET_YES != GNUNET_DISK_file_test (filename)) 110 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
99 { 111 {
100 /* must exist but not be accessible, fail for good! */ 112 /* must exist but not be accessible, fail for good! */
101 if (0 != ACCESS (filename, R_OK)) 113 if (0 != access (filename, R_OK))
102 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", filename); 114 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", filename);
103 else 115 else
104 GNUNET_break (0); /* what is going on!? */ 116 GNUNET_break (0); /* what is going on!? */
105 return NULL; 117 return NULL;
106 } 118 }
107 continue; 119 continue;
@@ -111,7 +123,8 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename)
111 } 123 }
112 cnt = 0; 124 cnt = 0;
113 while (GNUNET_YES != 125 while (GNUNET_YES !=
114 GNUNET_DISK_file_lock (fd, 0, 126 GNUNET_DISK_file_lock (fd,
127 0,
115 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey), 128 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey),
116 GNUNET_YES)) 129 GNUNET_YES))
117 { 130 {
@@ -120,27 +133,29 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename)
120 { 133 {
121 ec = errno; 134 ec = errno;
122 LOG (GNUNET_ERROR_TYPE_ERROR, 135 LOG (GNUNET_ERROR_TYPE_ERROR,
123 _("Could not acquire lock on file `%s': %s...\n"), 136 _ ("Could not acquire lock on file `%s': %s...\n"),
124 filename, 137 filename,
125 STRERROR (ec)); 138 strerror (ec));
126 } 139 }
127 } 140 }
128 LOG (GNUNET_ERROR_TYPE_INFO, 141 LOG (GNUNET_ERROR_TYPE_INFO,
129 _("Creating a new private key. This may take a while.\n")); 142 _ ("Creating a new private key. This may take a while.\n"));
130 priv = GNUNET_CRYPTO_eddsa_key_create (); 143 priv = GNUNET_CRYPTO_eddsa_key_create ();
131 GNUNET_assert (NULL != priv); 144 GNUNET_assert (NULL != priv);
132 GNUNET_assert (sizeof (*priv) == 145 GNUNET_assert (sizeof (*priv) ==
133 GNUNET_DISK_file_write (fd, priv, sizeof (*priv))); 146 GNUNET_DISK_file_write (fd, priv, sizeof (*priv)));
134 GNUNET_DISK_file_sync (fd); 147 GNUNET_DISK_file_sync (fd);
135 if (GNUNET_YES != 148 if (GNUNET_YES !=
136 GNUNET_DISK_file_unlock (fd, 0, 149 GNUNET_DISK_file_unlock (fd,
150 0,
137 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey))) 151 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)))
138 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); 152 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
139 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); 153 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
140 return priv; 154 return priv;
141 } 155 }
142 /* key file exists already, read it! */ 156 /* key file exists already, read it! */
143 fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, 157 fd = GNUNET_DISK_file_open (filename,
158 GNUNET_DISK_OPEN_READ,
144 GNUNET_DISK_PERM_NONE); 159 GNUNET_DISK_PERM_NONE);
145 if (NULL == fd) 160 if (NULL == fd)
146 { 161 {
@@ -151,7 +166,8 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename)
151 while (1) 166 while (1)
152 { 167 {
153 if (GNUNET_YES != 168 if (GNUNET_YES !=
154 GNUNET_DISK_file_lock (fd, 0, 169 GNUNET_DISK_file_lock (fd,
170 0,
155 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey), 171 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey),
156 GNUNET_NO)) 172 GNUNET_NO))
157 { 173 {
@@ -159,11 +175,13 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename)
159 { 175 {
160 ec = errno; 176 ec = errno;
161 LOG (GNUNET_ERROR_TYPE_ERROR, 177 LOG (GNUNET_ERROR_TYPE_ERROR,
162 _("Could not acquire lock on file `%s': %s...\n"), filename, 178 _ ("Could not acquire lock on file `%s': %s...\n"),
163 STRERROR (ec)); 179 filename,
164 LOG (GNUNET_ERROR_TYPE_ERROR, 180 strerror (ec));
165 _ 181 LOG (
166 ("This may be ok if someone is currently generating a private key.\n")); 182 GNUNET_ERROR_TYPE_ERROR,
183 _ (
184 "This may be ok if someone is currently generating a private key.\n"));
167 } 185 }
168 short_wait (); 186 short_wait ();
169 continue; 187 continue;
@@ -173,57 +191,56 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename)
173 /* eh, what!? File we opened is now gone!? */ 191 /* eh, what!? File we opened is now gone!? */
174 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", filename); 192 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
175 if (GNUNET_YES != 193 if (GNUNET_YES !=
176 GNUNET_DISK_file_unlock (fd, 0, 194 GNUNET_DISK_file_unlock (fd,
177 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey))) 195 0,
196 sizeof (
197 struct GNUNET_CRYPTO_EddsaPrivateKey)))
178 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); 198 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
179 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); 199 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd));
180 200
181 return NULL; 201 return NULL;
182 } 202 }
183 if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES)) 203 if (GNUNET_OK !=
204 GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
184 fs = 0; 205 fs = 0;
185 if (fs < sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)) 206 if (fs < sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey))
186 { 207 {
187 /* maybe we got the read lock before the key generating 208 /* maybe we got the read lock before the key generating
188 * process had a chance to get the write lock; give it up! */ 209 * process had a chance to get the write lock; give it up! */
189 if (GNUNET_YES != 210 if (GNUNET_YES !=
190 GNUNET_DISK_file_unlock (fd, 0, 211 GNUNET_DISK_file_unlock (fd,
191 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey))) 212 0,
213 sizeof (
214 struct GNUNET_CRYPTO_EddsaPrivateKey)))
192 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); 215 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
193 if (0 == ++cnt % 10) 216 if (0 == ++cnt % 10)
194 { 217 {
195 LOG (GNUNET_ERROR_TYPE_ERROR, 218 LOG (GNUNET_ERROR_TYPE_ERROR,
196 _("When trying to read key file `%s' I found %u bytes but I need at least %u.\n"), 219 _ (
220 "When trying to read key file `%s' I found %u bytes but I need at least %u.\n"),
197 filename, 221 filename,
198 (unsigned int) fs, 222 (unsigned int) fs,
199 (unsigned int) sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)); 223 (unsigned int) sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey));
200 LOG (GNUNET_ERROR_TYPE_ERROR, 224 LOG (GNUNET_ERROR_TYPE_ERROR,
201 _("This may be ok if someone is currently generating a key.\n")); 225 _ ("This may be ok if someone is currently generating a key.\n"));
202 } 226 }
203 short_wait (); /* wait a bit longer! */ 227 short_wait (); /* wait a bit longer! */
204 continue; 228 continue;
205 } 229 }
206 break; 230 break;
207 } 231 }
208 fs = sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey); 232 fs = sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey);
209 priv = GNUNET_malloc (fs); 233 priv = GNUNET_malloc (fs);
210 sret = GNUNET_DISK_file_read (fd, 234 sret = GNUNET_DISK_file_read (fd, priv, fs);
211 priv, 235 GNUNET_assert ((sret >= 0) && (fs == (size_t) sret));
212 fs);
213 GNUNET_assert ( (sret >= 0) &&
214 (fs == (size_t) sret) );
215 if (GNUNET_YES != 236 if (GNUNET_YES !=
216 GNUNET_DISK_file_unlock (fd, 237 GNUNET_DISK_file_unlock (fd,
217 0, 238 0,
218 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey))) 239 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)))
219 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, 240 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
220 "fcntl", 241 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
221 filename);
222 GNUNET_assert (GNUNET_YES ==
223 GNUNET_DISK_file_close (fd));
224#if CRYPTO_BUG 242#if CRYPTO_BUG
225 if (GNUNET_OK != 243 if (GNUNET_OK != check_eddsa_key (priv))
226 check_eddsa_key (priv))
227 { 244 {
228 GNUNET_break (0); 245 GNUNET_break (0);
229 GNUNET_free (priv); 246 GNUNET_free (priv);
@@ -258,16 +275,16 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename)
258 uint64_t fs; 275 uint64_t fs;
259 ssize_t sret; 276 ssize_t sret;
260 277
261 if (GNUNET_SYSERR == 278 if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename))
262 GNUNET_DISK_directory_create_for_file (filename))
263 return NULL; 279 return NULL;
264 while (GNUNET_YES != GNUNET_DISK_file_test (filename)) 280 while (GNUNET_YES != GNUNET_DISK_file_test (filename))
265 { 281 {
266 fd = GNUNET_DISK_file_open (filename, 282 fd =
267 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE 283 GNUNET_DISK_file_open (filename,
268 | GNUNET_DISK_OPEN_FAILIFEXISTS, 284 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE |
269 GNUNET_DISK_PERM_USER_READ | 285 GNUNET_DISK_OPEN_FAILIFEXISTS,
270 GNUNET_DISK_PERM_USER_WRITE); 286 GNUNET_DISK_PERM_USER_READ |
287 GNUNET_DISK_PERM_USER_WRITE);
271 if (NULL == fd) 288 if (NULL == fd)
272 { 289 {
273 if (EEXIST == errno) 290 if (EEXIST == errno)
@@ -275,25 +292,21 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename)
275 if (GNUNET_YES != GNUNET_DISK_file_test (filename)) 292 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
276 { 293 {
277 /* must exist but not be accessible, fail for good! */ 294 /* must exist but not be accessible, fail for good! */
278 if (0 != ACCESS (filename, R_OK)) 295 if (0 != access (filename, R_OK))
279 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, 296 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", filename);
280 "access",
281 filename);
282 else 297 else
283 GNUNET_break (0); /* what is going on!? */ 298 GNUNET_break (0); /* what is going on!? */
284 return NULL; 299 return NULL;
285 } 300 }
286 continue; 301 continue;
287 } 302 }
288 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, 303 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename);
289 "open",
290 filename);
291 return NULL; 304 return NULL;
292 } 305 }
293 cnt = 0; 306 cnt = 0;
294 while (GNUNET_YES != 307 while (GNUNET_YES !=
295 GNUNET_DISK_file_lock (fd, 308 GNUNET_DISK_file_lock (fd,
296 0, 309 0,
297 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), 310 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
298 GNUNET_YES)) 311 GNUNET_YES))
299 { 312 {
@@ -302,46 +315,41 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename)
302 { 315 {
303 ec = errno; 316 ec = errno;
304 LOG (GNUNET_ERROR_TYPE_ERROR, 317 LOG (GNUNET_ERROR_TYPE_ERROR,
305 _("Could not acquire lock on file `%s': %s...\n"), 318 _ ("Could not acquire lock on file `%s': %s...\n"),
306 filename, 319 filename,
307 STRERROR (ec)); 320 strerror (ec));
308 } 321 }
309 } 322 }
310 LOG (GNUNET_ERROR_TYPE_INFO, 323 LOG (GNUNET_ERROR_TYPE_INFO,
311 _("Creating a new private key. This may take a while.\n")); 324 _ ("Creating a new private key. This may take a while.\n"));
312 priv = GNUNET_CRYPTO_ecdsa_key_create (); 325 priv = GNUNET_CRYPTO_ecdsa_key_create ();
313 GNUNET_assert (NULL != priv); 326 GNUNET_assert (NULL != priv);
314 GNUNET_assert (sizeof (*priv) == 327 GNUNET_assert (sizeof (*priv) ==
315 GNUNET_DISK_file_write (fd, 328 GNUNET_DISK_file_write (fd, priv, sizeof (*priv)));
316 priv,
317 sizeof (*priv)));
318 GNUNET_DISK_file_sync (fd); 329 GNUNET_DISK_file_sync (fd);
319 if (GNUNET_YES != 330 if (GNUNET_YES !=
320 GNUNET_DISK_file_unlock (fd, 0, 331 GNUNET_DISK_file_unlock (fd,
332 0,
321 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 333 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
322 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, 334 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
323 "fcntl", 335 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
324 filename);
325 GNUNET_assert (GNUNET_YES ==
326 GNUNET_DISK_file_close (fd));
327 return priv; 336 return priv;
328 } 337 }
329 /* key file exists already, read it! */ 338 /* key file exists already, read it! */
330 fd = GNUNET_DISK_file_open (filename, 339 fd = GNUNET_DISK_file_open (filename,
331 GNUNET_DISK_OPEN_READ, 340 GNUNET_DISK_OPEN_READ,
332 GNUNET_DISK_PERM_NONE); 341 GNUNET_DISK_PERM_NONE);
333 if (NULL == fd) 342 if (NULL == fd)
334 { 343 {
335 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, 344 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename);
336 "open",
337 filename);
338 return NULL; 345 return NULL;
339 } 346 }
340 cnt = 0; 347 cnt = 0;
341 while (1) 348 while (1)
342 { 349 {
343 if (GNUNET_YES != 350 if (GNUNET_YES !=
344 GNUNET_DISK_file_lock (fd, 0, 351 GNUNET_DISK_file_lock (fd,
352 0,
345 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), 353 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
346 GNUNET_NO)) 354 GNUNET_NO))
347 { 355 {
@@ -349,78 +357,70 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename)
349 { 357 {
350 ec = errno; 358 ec = errno;
351 LOG (GNUNET_ERROR_TYPE_ERROR, 359 LOG (GNUNET_ERROR_TYPE_ERROR,
352 _("Could not acquire lock on file `%s': %s...\n"), 360 _ ("Could not acquire lock on file `%s': %s...\n"),
353 filename, 361 filename,
354 STRERROR (ec)); 362 strerror (ec));
355 LOG (GNUNET_ERROR_TYPE_ERROR, 363 LOG (
356 _("This may be ok if someone is currently generating a private key.\n")); 364 GNUNET_ERROR_TYPE_ERROR,
365 _ (
366 "This may be ok if someone is currently generating a private key.\n"));
357 } 367 }
358 short_wait (); 368 short_wait ();
359 continue; 369 continue;
360 } 370 }
361 if (GNUNET_YES != 371 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
362 GNUNET_DISK_file_test (filename))
363 { 372 {
364 /* eh, what!? File we opened is now gone!? */ 373 /* eh, what!? File we opened is now gone!? */
365 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, 374 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
366 "stat",
367 filename);
368 if (GNUNET_YES != 375 if (GNUNET_YES !=
369 GNUNET_DISK_file_unlock (fd, 0, 376 GNUNET_DISK_file_unlock (fd,
370 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 377 0,
371 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, 378 sizeof (
372 "fcntl", 379 struct GNUNET_CRYPTO_EcdsaPrivateKey)))
373 filename); 380 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
374 GNUNET_assert (GNUNET_OK == 381 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd));
375 GNUNET_DISK_file_close (fd));
376 382
377 return NULL; 383 return NULL;
378 } 384 }
379 if (GNUNET_OK != 385 if (GNUNET_OK !=
380 GNUNET_DISK_file_size (filename, 386 GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
381 &fs,
382 GNUNET_YES,
383 GNUNET_YES))
384 fs = 0; 387 fs = 0;
385 if (fs < sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)) 388 if (fs < sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))
386 { 389 {
387 /* maybe we got the read lock before the key generating 390 /* maybe we got the read lock before the key generating
388 * process had a chance to get the write lock; give it up! */ 391 * process had a chance to get the write lock; give it up! */
389 if (GNUNET_YES != 392 if (GNUNET_YES !=
390 GNUNET_DISK_file_unlock (fd, 0, 393 GNUNET_DISK_file_unlock (fd,
391 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 394 0,
392 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, 395 sizeof (
393 "fcntl", 396 struct GNUNET_CRYPTO_EcdsaPrivateKey)))
394 filename); 397 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
395 if (0 == ++cnt % 10) 398 if (0 == ++cnt % 10)
396 { 399 {
397 LOG (GNUNET_ERROR_TYPE_ERROR, 400 LOG (GNUNET_ERROR_TYPE_ERROR,
398 _("When trying to read key file `%s' I found %u bytes but I need at least %u.\n"), 401 _ (
399 filename, (unsigned int) fs, 402 "When trying to read key file `%s' I found %u bytes but I need at least %u.\n"),
403 filename,
404 (unsigned int) fs,
400 (unsigned int) sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); 405 (unsigned int) sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
401 LOG (GNUNET_ERROR_TYPE_ERROR, 406 LOG (GNUNET_ERROR_TYPE_ERROR,
402 _("This may be ok if someone is currently generating a key.\n")); 407 _ ("This may be ok if someone is currently generating a key.\n"));
403 } 408 }
404 short_wait (); /* wait a bit longer! */ 409 short_wait (); /* wait a bit longer! */
405 continue; 410 continue;
406 } 411 }
407 break; 412 break;
408 } 413 }
409 fs = sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey); 414 fs = sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey);
410 priv = GNUNET_malloc (fs); 415 priv = GNUNET_malloc (fs);
411 sret = GNUNET_DISK_file_read (fd, 416 sret = GNUNET_DISK_file_read (fd, priv, fs);
412 priv, 417 GNUNET_assert ((sret >= 0) && (fs == (size_t) sret));
413 fs);
414 GNUNET_assert ( (sret >= 0) &&
415 (fs == (size_t) sret) );
416 if (GNUNET_YES != 418 if (GNUNET_YES !=
417 GNUNET_DISK_file_unlock (fd, 0, 419 GNUNET_DISK_file_unlock (fd,
420 0,
418 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 421 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
419 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, 422 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
420 "fcntl", 423 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
421 filename);
422 GNUNET_assert (GNUNET_YES ==
423 GNUNET_DISK_file_close (fd));
424 return priv; 424 return priv;
425} 425}
426 426
@@ -434,7 +434,8 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename)
434 * permission denied) 434 * permission denied)
435 */ 435 */
436struct GNUNET_CRYPTO_EddsaPrivateKey * 436struct GNUNET_CRYPTO_EddsaPrivateKey *
437GNUNET_CRYPTO_eddsa_key_create_from_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg) 437GNUNET_CRYPTO_eddsa_key_create_from_configuration (
438 const struct GNUNET_CONFIGURATION_Handle *cfg)
438{ 439{
439 struct GNUNET_CRYPTO_EddsaPrivateKey *priv; 440 struct GNUNET_CRYPTO_EddsaPrivateKey *priv;
440 char *fn; 441 char *fn;
@@ -465,7 +466,7 @@ GNUNET_CRYPTO_get_peer_identity (const struct GNUNET_CONFIGURATION_Handle *cfg,
465 if (NULL == (priv = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg))) 466 if (NULL == (priv = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg)))
466 { 467 {
467 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 468 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
468 _("Could not load peer's private key\n")); 469 _ ("Could not load peer's private key\n"));
469 return GNUNET_SYSERR; 470 return GNUNET_SYSERR;
470 } 471 }
471 GNUNET_CRYPTO_eddsa_key_get_public (priv, &dst->public_key); 472 GNUNET_CRYPTO_eddsa_key_get_public (priv, &dst->public_key);
diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c
index 71eaab87a..58cab082e 100644
--- a/src/util/crypto_random.c
+++ b/src/util/crypto_random.c
@@ -80,7 +80,7 @@ glibc_weak_rand32 ()
80static double 80static double
81get_weak_random () 81get_weak_random ()
82{ 82{
83 return ((double) RANDOM () / RAND_MAX); 83 return ((double) random () / RAND_MAX);
84} 84}
85 85
86 86
@@ -93,7 +93,7 @@ get_weak_random ()
93void 93void
94GNUNET_CRYPTO_seed_weak_random (int32_t seed) 94GNUNET_CRYPTO_seed_weak_random (int32_t seed)
95{ 95{
96 SRANDOM (seed); 96 srandom (seed);
97} 97}
98 98
99 99
@@ -324,7 +324,7 @@ void __attribute__ ((constructor)) GNUNET_CRYPTO_random_init ()
324 324
325 if (! gcry_check_version (NEED_LIBGCRYPT_VERSION)) 325 if (! gcry_check_version (NEED_LIBGCRYPT_VERSION))
326 { 326 {
327 FPRINTF ( 327 fprintf (
328 stderr, 328 stderr,
329 _ ("libgcrypt has not the expected version (version %s is required).\n"), 329 _ ("libgcrypt has not the expected version (version %s is required).\n"),
330 NEED_LIBGCRYPT_VERSION); 330 NEED_LIBGCRYPT_VERSION);
@@ -334,14 +334,14 @@ void __attribute__ ((constructor)) GNUNET_CRYPTO_random_init ()
334 gcry_set_allocation_handler (&w_malloc, &w_malloc, &w_check, &realloc, &free); 334 gcry_set_allocation_handler (&w_malloc, &w_malloc, &w_check, &realloc, &free);
335 /* Disable use of secure memory */ 335 /* Disable use of secure memory */
336 if ((rc = gcry_control (GCRYCTL_DISABLE_SECMEM, 0))) 336 if ((rc = gcry_control (GCRYCTL_DISABLE_SECMEM, 0)))
337 FPRINTF (stderr, 337 fprintf (stderr,
338 "Failed to set libgcrypt option %s: %s\n", 338 "Failed to set libgcrypt option %s: %s\n",
339 "DISABLE_SECMEM", 339 "DISABLE_SECMEM",
340 gcry_strerror (rc)); 340 gcry_strerror (rc));
341 /* Otherwise gnunet-ecc takes forever to complete, besides 341 /* Otherwise gnunet-ecc takes forever to complete, besides
342 we are fine with "just" using GCRY_STRONG_RANDOM */ 342 we are fine with "just" using GCRY_STRONG_RANDOM */
343 if ((rc = gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0))) 343 if ((rc = gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0)))
344 FPRINTF (stderr, 344 fprintf (stderr,
345 "Failed to set libgcrypt option %s: %s\n", 345 "Failed to set libgcrypt option %s: %s\n",
346 "ENABLE_QUICK_RANDOM", 346 "ENABLE_QUICK_RANDOM",
347 gcry_strerror (rc)); 347 gcry_strerror (rc));
diff --git a/src/util/disk.c b/src/util/disk.c
index f395a375e..c1f24e4c8 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -28,11 +28,13 @@
28#include "gnunet_strings_lib.h" 28#include "gnunet_strings_lib.h"
29#include "gnunet_disk_lib.h" 29#include "gnunet_disk_lib.h"
30 30
31#define LOG(kind,...) GNUNET_log_from (kind, "util-disk", __VA_ARGS__) 31#define LOG(kind, ...) GNUNET_log_from (kind, "util-disk", __VA_ARGS__)
32 32
33#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-disk", syscall) 33#define LOG_STRERROR(kind, syscall) \
34 GNUNET_log_from_strerror (kind, "util-disk", syscall)
34 35
35#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-disk", syscall, filename) 36#define LOG_STRERROR_FILE(kind, syscall, filename) \
37 GNUNET_log_from_strerror_file (kind, "util-disk", syscall, filename)
36 38
37/** 39/**
38 * Block size for IO for copying files. 40 * Block size for IO for copying files.
@@ -54,9 +56,9 @@
54#endif 56#endif
55 57
56#ifndef S_ISLNK 58#ifndef S_ISLNK
57#define _IFMT 0170000 /* type of file */ 59#define _IFMT 0170000 /* type of file */
58#define _IFLNK 0120000 /* symbolic link */ 60#define _IFLNK 0120000 /* symbolic link */
59#define S_ISLNK(m) (((m)&_IFMT) == _IFLNK) 61#define S_ISLNK(m) (((m) &_IFMT) == _IFLNK)
60#endif 62#endif
61 63
62 64
@@ -147,7 +149,8 @@ getSizeRec (void *cls, const char *fn)
147{ 149{
148 struct GetFileSizeData *gfsd = cls; 150 struct GetFileSizeData *gfsd = cls;
149 151
150#if defined (HAVE_STAT64) && !(defined (_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) 152#if defined(HAVE_STAT64) && \
153 ! (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64)
151 STRUCT_STAT64 buf; 154 STRUCT_STAT64 buf;
152 155
153 if (0 != STAT64 (fn, &buf)) 156 if (0 != STAT64 (fn, &buf))
@@ -158,7 +161,7 @@ getSizeRec (void *cls, const char *fn)
158#else 161#else
159 struct stat buf; 162 struct stat buf;
160 163
161 if (0 != STAT (fn, &buf)) 164 if (0 != stat (fn, &buf))
162 { 165 {
163 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_DEBUG, "stat", fn); 166 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_DEBUG, "stat", fn);
164 return GNUNET_SYSERR; 167 return GNUNET_SYSERR;
@@ -169,10 +172,10 @@ getSizeRec (void *cls, const char *fn)
169 errno = EISDIR; 172 errno = EISDIR;
170 return GNUNET_SYSERR; 173 return GNUNET_SYSERR;
171 } 174 }
172 if ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES)) 175 if ((! S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES))
173 gfsd->total += buf.st_size; 176 gfsd->total += buf.st_size;
174 if ((S_ISDIR (buf.st_mode)) && (0 == ACCESS (fn, X_OK)) && 177 if ((S_ISDIR (buf.st_mode)) && (0 == access (fn, X_OK)) &&
175 ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES))) 178 ((! S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES)))
176 { 179 {
177 if (GNUNET_SYSERR == GNUNET_DISK_directory_scan (fn, &getSizeRec, gfsd)) 180 if (GNUNET_SYSERR == GNUNET_DISK_directory_scan (fn, &getSizeRec, gfsd))
178 return GNUNET_SYSERR; 181 return GNUNET_SYSERR;
@@ -191,9 +194,9 @@ int
191GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h) 194GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h)
192{ 195{
193#ifdef MINGW 196#ifdef MINGW
194 return ((!h) || (h->h == INVALID_HANDLE_VALUE)) ? GNUNET_YES : GNUNET_NO; 197 return ((! h) || (h->h == INVALID_HANDLE_VALUE)) ? GNUNET_YES : GNUNET_NO;
195#else 198#else
196 return ((!h) || (h->fd == -1)) ? GNUNET_YES : GNUNET_NO; 199 return ((! h) || (h->fd == -1)) ? GNUNET_YES : GNUNET_NO;
197#endif 200#endif
198} 201}
199 202
@@ -205,14 +208,13 @@ GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h)
205 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 208 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
206 */ 209 */
207int 210int
208GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh, 211GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh, off_t *size)
209 off_t *size)
210{ 212{
211#if WINDOWS 213#if WINDOWS
212 BOOL b; 214 BOOL b;
213 LARGE_INTEGER li; 215 LARGE_INTEGER li;
214 b = GetFileSizeEx (fh->h, &li); 216 b = GetFileSizeEx (fh->h, &li);
215 if (!b) 217 if (! b)
216 { 218 {
217 SetErrnoFromWinError (GetLastError ()); 219 SetErrnoFromWinError (GetLastError ());
218 return GNUNET_SYSERR; 220 return GNUNET_SYSERR;
@@ -221,7 +223,7 @@ GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh,
221#else 223#else
222 struct stat sbuf; 224 struct stat sbuf;
223 225
224 if (0 != FSTAT (fh->fd, &sbuf)) 226 if (0 != fstat (fh->fd, &sbuf))
225 return GNUNET_SYSERR; 227 return GNUNET_SYSERR;
226 *size = sbuf.st_size; 228 *size = sbuf.st_size;
227#endif 229#endif
@@ -239,7 +241,7 @@ GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh,
239 */ 241 */
240off_t 242off_t
241GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, 243GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h,
242 off_t offset, 244 off_t offset,
243 enum GNUNET_DISK_Seek whence) 245 enum GNUNET_DISK_Seek whence)
244{ 246{
245 if (h == NULL) 247 if (h == NULL)
@@ -253,7 +255,7 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h,
253 LARGE_INTEGER new_pos; 255 LARGE_INTEGER new_pos;
254 BOOL b; 256 BOOL b;
255 257
256 static DWORD t[] = { FILE_BEGIN, FILE_CURRENT, FILE_END }; 258 static DWORD t[] = {FILE_BEGIN, FILE_CURRENT, FILE_END};
257 li.QuadPart = offset; 259 li.QuadPart = offset;
258 260
259 b = SetFilePointerEx (h->h, li, &new_pos, t[whence]); 261 b = SetFilePointerEx (h->h, li, &new_pos, t[whence]);
@@ -264,7 +266,7 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h,
264 } 266 }
265 return (off_t) new_pos.QuadPart; 267 return (off_t) new_pos.QuadPart;
266#else 268#else
267 static int t[] = { SEEK_SET, SEEK_CUR, SEEK_END }; 269 static int t[] = {SEEK_SET, SEEK_CUR, SEEK_END};
268 270
269 return lseek (h->fd, offset, t[whence]); 271 return lseek (h->fd, offset, t[whence]);
270#endif 272#endif
@@ -287,9 +289,9 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h,
287 */ 289 */
288int 290int
289GNUNET_DISK_file_size (const char *filename, 291GNUNET_DISK_file_size (const char *filename,
290 uint64_t * size, 292 uint64_t *size,
291 int include_symbolic_links, 293 int include_symbolic_links,
292 int single_file_mode) 294 int single_file_mode)
293{ 295{
294 struct GetFileSizeData gfsd; 296 struct GetFileSizeData gfsd;
295 int ret; 297 int ret;
@@ -320,8 +322,9 @@ GNUNET_DISK_file_size (const char *filename,
320 * @return #GNUNET_OK on success 322 * @return #GNUNET_OK on success
321 */ 323 */
322int 324int
323GNUNET_DISK_file_get_identifiers (const char *filename, uint64_t * dev, 325GNUNET_DISK_file_get_identifiers (const char *filename,
324 uint64_t * ino) 326 uint64_t *dev,
327 uint64_t *ino)
325{ 328{
326#if WINDOWS 329#if WINDOWS
327 { 330 {
@@ -337,12 +340,13 @@ GNUNET_DISK_file_get_identifiers (const char *filename, uint64_t * dev,
337 return GNUNET_SYSERR; 340 return GNUNET_SYSERR;
338 succ = GetFileInformationByHandle (fh->h, &info); 341 succ = GetFileInformationByHandle (fh->h, &info);
339 GNUNET_DISK_file_close (fh); 342 GNUNET_DISK_file_close (fh);
340 if (!succ) 343 if (! succ)
341 { 344 {
342 return GNUNET_SYSERR; 345 return GNUNET_SYSERR;
343 } 346 }
344 *dev = info.dwVolumeSerialNumber; 347 *dev = info.dwVolumeSerialNumber;
345 *ino = ((((uint64_t) info.nFileIndexHigh) << (sizeof (DWORD) * 8)) | info.nFileIndexLow); 348 *ino = ((((uint64_t) info.nFileIndexHigh) << (sizeof (DWORD) * 8)) |
349 info.nFileIndexLow);
346 } 350 }
347#else /* !WINDOWS */ 351#else /* !WINDOWS */
348#if HAVE_STAT 352#if HAVE_STAT
@@ -376,8 +380,8 @@ GNUNET_DISK_file_get_identifiers (const char *filename, uint64_t * dev,
376 { 380 {
377 return GNUNET_SYSERR; 381 return GNUNET_SYSERR;
378 } 382 }
379 *dev = ((uint64_t) fbuf.f_fsid.val[0]) << 32 || 383 *dev =
380 ((uint64_t) fbuf.f_fsid.val[1]); 384 ((uint64_t) fbuf.f_fsid.val[0]) << 32 || ((uint64_t) fbuf.f_fsid.val[1]);
381 } 385 }
382#else 386#else
383 *dev = 0; 387 *dev = 0;
@@ -402,9 +406,9 @@ mktemp_name (const char *t)
402 406
403 if ((t[0] != '/') && (t[0] != '\\') 407 if ((t[0] != '/') && (t[0] != '\\')
404#if WINDOWS 408#if WINDOWS
405 && !(isalpha ((int) t[0]) && (t[0] != '\0') && (t[1] == ':')) 409 && ! (isalpha ((int) t[0]) && (t[0] != '\0') && (t[1] == ':'))
406#endif 410#endif
407 ) 411 )
408 { 412 {
409 /* FIXME: This uses system codepage on W32, not UTF-8 */ 413 /* FIXME: This uses system codepage on W32, not UTF-8 */
410 tmpdir = getenv ("TMPDIR"); 414 tmpdir = getenv ("TMPDIR");
@@ -506,11 +510,10 @@ GNUNET_DISK_fix_permissions (const char *fn,
506 else if (GNUNET_YES == require_gid_match) 510 else if (GNUNET_YES == require_gid_match)
507 mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP; 511 mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP;
508 else 512 else
509 mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH; 513 mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH |
514 S_IWOTH | S_IXOTH;
510 if (0 != chmod (fn, mode)) 515 if (0 != chmod (fn, mode))
511 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 516 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "chmod", fn);
512 "chmod",
513 fn);
514} 517}
515 518
516#endif 519#endif
@@ -565,15 +568,10 @@ GNUNET_DISK_file_backup (const char *fil)
565 num = 0; 568 num = 0;
566 do 569 do
567 { 570 {
568 GNUNET_snprintf (target, slen, 571 GNUNET_snprintf (target, slen, "%s.%u~", fil, num++);
569 "%s.%u~",
570 fil,
571 num++);
572 } while (0 == access (target, F_OK)); 572 } while (0 == access (target, F_OK));
573 if (0 != rename (fil, target)) 573 if (0 != rename (fil, target))
574 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 574 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "rename", fil);
575 "rename",
576 fil);
577 GNUNET_free (target); 575 GNUNET_free (target);
578} 576}
579 577
@@ -606,7 +604,7 @@ GNUNET_DISK_mktemp (const char *t)
606 return NULL; 604 return NULL;
607 } 605 }
608 umask (omask); 606 umask (omask);
609 if (0 != CLOSE (fd)) 607 if (0 != close (fd))
610 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "close", fn); 608 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "close", fn);
611 return fn; 609 return fn;
612} 610}
@@ -625,29 +623,29 @@ GNUNET_DISK_mktemp (const char *t)
625 * does not exist or stat'ed 623 * does not exist or stat'ed
626 */ 624 */
627int 625int
628GNUNET_DISK_directory_test (const char *fil, 626GNUNET_DISK_directory_test (const char *fil, int is_readable)
629 int is_readable)
630{ 627{
631 struct stat filestat; 628 struct stat filestat;
632 int ret; 629 int ret;
633 630
634 ret = STAT (fil, &filestat); 631 ret = stat (fil, &filestat);
635 if (ret != 0) 632 if (ret != 0)
636 { 633 {
637 if (errno != ENOENT) 634 if (errno != ENOENT)
638 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", fil); 635 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", fil);
639 return GNUNET_SYSERR; 636 return GNUNET_SYSERR;
640 } 637 }
641 if (!S_ISDIR (filestat.st_mode)) 638 if (! S_ISDIR (filestat.st_mode))
642 { 639 {
643 LOG (GNUNET_ERROR_TYPE_INFO, 640 LOG (GNUNET_ERROR_TYPE_INFO,
644 "A file already exits with the same name %s\n", fil); 641 "A file already exits with the same name %s\n",
642 fil);
645 return GNUNET_NO; 643 return GNUNET_NO;
646 } 644 }
647 if (GNUNET_YES == is_readable) 645 if (GNUNET_YES == is_readable)
648 ret = ACCESS (fil, R_OK | X_OK); 646 ret = access (fil, R_OK | X_OK);
649 else 647 else
650 ret = ACCESS (fil, X_OK); 648 ret = access (fil, X_OK);
651 if (ret < 0) 649 if (ret < 0)
652 { 650 {
653 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", fil); 651 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", fil);
@@ -676,7 +674,7 @@ GNUNET_DISK_file_test (const char *fil)
676 if (rdir == NULL) 674 if (rdir == NULL)
677 return GNUNET_SYSERR; 675 return GNUNET_SYSERR;
678 676
679 ret = STAT (rdir, &filestat); 677 ret = stat (rdir, &filestat);
680 if (ret != 0) 678 if (ret != 0)
681 { 679 {
682 if (errno != ENOENT) 680 if (errno != ENOENT)
@@ -688,12 +686,12 @@ GNUNET_DISK_file_test (const char *fil)
688 GNUNET_free (rdir); 686 GNUNET_free (rdir);
689 return GNUNET_NO; 687 return GNUNET_NO;
690 } 688 }
691 if (!S_ISREG (filestat.st_mode)) 689 if (! S_ISREG (filestat.st_mode))
692 { 690 {
693 GNUNET_free (rdir); 691 GNUNET_free (rdir);
694 return GNUNET_NO; 692 return GNUNET_NO;
695 } 693 }
696 if (ACCESS (rdir, F_OK) < 0) 694 if (access (rdir, F_OK) < 0)
697 { 695 {
698 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", rdir); 696 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", rdir);
699 GNUNET_free (rdir); 697 GNUNET_free (rdir);
@@ -728,7 +726,7 @@ GNUNET_DISK_directory_create (const char *dir)
728 726
729 len = strlen (rdir); 727 len = strlen (rdir);
730#ifndef MINGW 728#ifndef MINGW
731 pos = 1; /* skip heading '/' */ 729 pos = 1; /* skip heading '/' */
732#else 730#else
733 /* Local or Network path? */ 731 /* Local or Network path? */
734 if (strncmp (rdir, "\\\\", 2) == 0) 732 if (strncmp (rdir, "\\\\", 2) == 0)
@@ -746,7 +744,7 @@ GNUNET_DISK_directory_create (const char *dir)
746 } 744 }
747 else 745 else
748 { 746 {
749 pos = 3; /* strlen("C:\\") */ 747 pos = 3; /* strlen("C:\\") */
750 } 748 }
751#endif 749#endif
752 /* Check which low level directories already exist */ 750 /* Check which low level directories already exist */
@@ -796,11 +794,13 @@ GNUNET_DISK_directory_create (const char *dir)
796 if (GNUNET_SYSERR == ret) 794 if (GNUNET_SYSERR == ret)
797 { 795 {
798#ifndef MINGW 796#ifndef MINGW
799 ret = mkdir (rdir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); /* 755 */ 797 ret = mkdir (rdir,
798 S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH |
799 S_IXOTH); /* 755 */
800#else 800#else
801 wchar_t wrdir[MAX_PATH + 1]; 801 wchar_t wrdir[MAX_PATH + 1];
802 if (ERROR_SUCCESS == plibc_conv_to_win_pathwconv(rdir, wrdir)) 802 if (ERROR_SUCCESS == plibc_conv_to_win_pathwconv (rdir, wrdir))
803 ret = !CreateDirectoryW (wrdir, NULL); 803 ret = ! CreateDirectoryW (wrdir, NULL);
804 else 804 else
805 ret = 1; 805 ret = 1;
806#endif 806#endif
@@ -843,7 +843,7 @@ GNUNET_DISK_directory_create_for_file (const char *filename)
843 errno = EINVAL; 843 errno = EINVAL;
844 return GNUNET_SYSERR; 844 return GNUNET_SYSERR;
845 } 845 }
846 if (0 == ACCESS (rdir, W_OK)) 846 if (0 == access (rdir, W_OK))
847 { 847 {
848 GNUNET_free (rdir); 848 GNUNET_free (rdir);
849 return GNUNET_OK; 849 return GNUNET_OK;
@@ -860,7 +860,7 @@ GNUNET_DISK_directory_create_for_file (const char *filename)
860 rdir = GNUNET_strdup ("/"); 860 rdir = GNUNET_strdup ("/");
861 } 861 }
862 ret = GNUNET_DISK_directory_create (rdir); 862 ret = GNUNET_DISK_directory_create (rdir);
863 if ((GNUNET_OK == ret) && (0 != ACCESS (rdir, W_OK))) 863 if ((GNUNET_OK == ret) && (0 != access (rdir, W_OK)))
864 ret = GNUNET_NO; 864 ret = GNUNET_NO;
865 eno = errno; 865 eno = errno;
866 GNUNET_free (rdir); 866 GNUNET_free (rdir);
@@ -893,7 +893,7 @@ GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h,
893 893
894 if (h->type == GNUNET_DISK_HANLDE_TYPE_FILE) 894 if (h->type == GNUNET_DISK_HANLDE_TYPE_FILE)
895 { 895 {
896 if (!ReadFile (h->h, result, len, &bytes_read, NULL)) 896 if (! ReadFile (h->h, result, len, &bytes_read, NULL))
897 { 897 {
898 SetErrnoFromWinError (GetLastError ()); 898 SetErrnoFromWinError (GetLastError ());
899 return GNUNET_SYSERR; 899 return GNUNET_SYSERR;
@@ -901,7 +901,7 @@ GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h,
901 } 901 }
902 else if (h->type == GNUNET_DISK_HANLDE_TYPE_PIPE) 902 else if (h->type == GNUNET_DISK_HANLDE_TYPE_PIPE)
903 { 903 {
904 if (!ReadFile (h->h, result, len, &bytes_read, h->oOverlapRead)) 904 if (! ReadFile (h->h, result, len, &bytes_read, h->oOverlapRead))
905 { 905 {
906 if (GetLastError () != ERROR_IO_PENDING) 906 if (GetLastError () != ERROR_IO_PENDING)
907 { 907 {
@@ -939,8 +939,8 @@ GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h,
939 */ 939 */
940ssize_t 940ssize_t
941GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle *h, 941GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle *h,
942 void *result, 942 void *result,
943 size_t len) 943 size_t len)
944{ 944{
945 if (NULL == h) 945 if (NULL == h)
946 { 946 {
@@ -953,7 +953,7 @@ GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle *h,
953 953
954 if (h->type == GNUNET_DISK_HANLDE_TYPE_FILE) 954 if (h->type == GNUNET_DISK_HANLDE_TYPE_FILE)
955 { 955 {
956 if (!ReadFile (h->h, result, len, &bytes_read, NULL)) 956 if (! ReadFile (h->h, result, len, &bytes_read, NULL))
957 { 957 {
958 SetErrnoFromWinError (GetLastError ()); 958 SetErrnoFromWinError (GetLastError ());
959 return GNUNET_SYSERR; 959 return GNUNET_SYSERR;
@@ -961,26 +961,25 @@ GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle *h,
961 } 961 }
962 else if (h->type == GNUNET_DISK_HANLDE_TYPE_PIPE) 962 else if (h->type == GNUNET_DISK_HANLDE_TYPE_PIPE)
963 { 963 {
964 if (!ReadFile (h->h, result, len, &bytes_read, h->oOverlapRead)) 964 if (! ReadFile (h->h, result, len, &bytes_read, h->oOverlapRead))
965 { 965 {
966 if (GetLastError () != ERROR_IO_PENDING) 966 if (GetLastError () != ERROR_IO_PENDING)
967 { 967 {
968 LOG (GNUNET_ERROR_TYPE_DEBUG, "Error reading from pipe: %u\n", GetLastError ()); 968 LOG (GNUNET_ERROR_TYPE_DEBUG,
969 "Error reading from pipe: %u\n",
970 GetLastError ());
969 SetErrnoFromWinError (GetLastError ()); 971 SetErrnoFromWinError (GetLastError ());
970 return GNUNET_SYSERR; 972 return GNUNET_SYSERR;
971 } 973 }
972 else 974 else
973 { 975 {
974 LOG (GNUNET_ERROR_TYPE_DEBUG, 976 LOG (GNUNET_ERROR_TYPE_DEBUG, "ReadFile() queued a read, cancelling\n");
975 "ReadFile() queued a read, cancelling\n");
976 CancelIo (h->h); 977 CancelIo (h->h);
977 errno = EAGAIN; 978 errno = EAGAIN;
978 return GNUNET_SYSERR; 979 return GNUNET_SYSERR;
979 } 980 }
980 } 981 }
981 LOG (GNUNET_ERROR_TYPE_DEBUG, 982 LOG (GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes\n", bytes_read);
982 "Read %u bytes\n",
983 bytes_read);
984 } 983 }
985 else 984 else
986 { 985 {
@@ -997,11 +996,11 @@ GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle *h,
997 (void) fcntl (h->fd, F_SETFL, flags | O_NONBLOCK); 996 (void) fcntl (h->fd, F_SETFL, flags | O_NONBLOCK);
998 ret = read (h->fd, result, len); 997 ret = read (h->fd, result, len);
999 if (0 == (flags & O_NONBLOCK)) 998 if (0 == (flags & O_NONBLOCK))
1000 { 999 {
1001 int eno = errno; 1000 int eno = errno;
1002 (void) fcntl (h->fd, F_SETFL, flags); 1001 (void) fcntl (h->fd, F_SETFL, flags);
1003 errno = eno; 1002 errno = eno;
1004 } 1003 }
1005 return ret; 1004 return ret;
1006#endif 1005#endif
1007} 1006}
@@ -1016,17 +1015,13 @@ GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle *h,
1016 * @return number of bytes read, #GNUNET_SYSERR on failure 1015 * @return number of bytes read, #GNUNET_SYSERR on failure
1017 */ 1016 */
1018ssize_t 1017ssize_t
1019GNUNET_DISK_fn_read (const char *fn, 1018GNUNET_DISK_fn_read (const char *fn, void *result, size_t len)
1020 void *result,
1021 size_t len)
1022{ 1019{
1023 struct GNUNET_DISK_FileHandle *fh; 1020 struct GNUNET_DISK_FileHandle *fh;
1024 ssize_t ret; 1021 ssize_t ret;
1025 int eno; 1022 int eno;
1026 1023
1027 fh = GNUNET_DISK_file_open (fn, 1024 fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE);
1028 GNUNET_DISK_OPEN_READ,
1029 GNUNET_DISK_PERM_NONE);
1030 if (NULL == fh) 1025 if (NULL == fh)
1031 return GNUNET_SYSERR; 1026 return GNUNET_SYSERR;
1032 ret = GNUNET_DISK_file_read (fh, result, len); 1027 ret = GNUNET_DISK_file_read (fh, result, len);
@@ -1046,9 +1041,9 @@ GNUNET_DISK_fn_read (const char *fn,
1046 * @return number of bytes written on success, #GNUNET_SYSERR on error 1041 * @return number of bytes written on success, #GNUNET_SYSERR on error
1047 */ 1042 */
1048ssize_t 1043ssize_t
1049GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h, 1044GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h,
1050 const void *buffer, 1045 const void *buffer,
1051 size_t n) 1046 size_t n)
1052{ 1047{
1053 if (NULL == h) 1048 if (NULL == h)
1054 { 1049 {
@@ -1061,7 +1056,7 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h,
1061 1056
1062 if (h->type == GNUNET_DISK_HANLDE_TYPE_FILE) 1057 if (h->type == GNUNET_DISK_HANLDE_TYPE_FILE)
1063 { 1058 {
1064 if (!WriteFile (h->h, buffer, n, &bytes_written, NULL)) 1059 if (! WriteFile (h->h, buffer, n, &bytes_written, NULL))
1065 { 1060 {
1066 SetErrnoFromWinError (GetLastError ()); 1061 SetErrnoFromWinError (GetLastError ());
1067 return GNUNET_SYSERR; 1062 return GNUNET_SYSERR;
@@ -1070,46 +1065,50 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h,
1070 else if (h->type == GNUNET_DISK_HANLDE_TYPE_PIPE) 1065 else if (h->type == GNUNET_DISK_HANLDE_TYPE_PIPE)
1071 { 1066 {
1072 LOG (GNUNET_ERROR_TYPE_DEBUG, "It is a pipe trying to write %u bytes\n", n); 1067 LOG (GNUNET_ERROR_TYPE_DEBUG, "It is a pipe trying to write %u bytes\n", n);
1073 if (!WriteFile (h->h, buffer, n, &bytes_written, h->oOverlapWrite)) 1068 if (! WriteFile (h->h, buffer, n, &bytes_written, h->oOverlapWrite))
1074 { 1069 {
1075 if (GetLastError () != ERROR_IO_PENDING) 1070 if (GetLastError () != ERROR_IO_PENDING)
1076 { 1071 {
1077 SetErrnoFromWinError (GetLastError ()); 1072 SetErrnoFromWinError (GetLastError ());
1078 LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe: %u\n", 1073 LOG (GNUNET_ERROR_TYPE_DEBUG,
1079 GetLastError ()); 1074 "Error writing to pipe: %u\n",
1075 GetLastError ());
1080 return GNUNET_SYSERR; 1076 return GNUNET_SYSERR;
1081 } 1077 }
1082 LOG (GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n"); 1078 LOG (GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n");
1083 if (!GetOverlappedResult (h->h, h->oOverlapWrite, &bytes_written, TRUE)) 1079 if (! GetOverlappedResult (h->h, h->oOverlapWrite, &bytes_written, TRUE))
1084 { 1080 {
1085 SetErrnoFromWinError (GetLastError ()); 1081 SetErrnoFromWinError (GetLastError ());
1086 LOG (GNUNET_ERROR_TYPE_DEBUG, 1082 LOG (GNUNET_ERROR_TYPE_DEBUG,
1087 "Error getting overlapped result while writing to pipe: %u\n", 1083 "Error getting overlapped result while writing to pipe: %u\n",
1088 GetLastError ()); 1084 GetLastError ());
1089 return GNUNET_SYSERR; 1085 return GNUNET_SYSERR;
1090 } 1086 }
1091 } 1087 }
1092 else 1088 else
1093 { 1089 {
1094 DWORD ovr; 1090 DWORD ovr;
1095 if (!GetOverlappedResult (h->h, h->oOverlapWrite, &ovr, TRUE)) 1091 if (! GetOverlappedResult (h->h, h->oOverlapWrite, &ovr, TRUE))
1096 { 1092 {
1097 LOG (GNUNET_ERROR_TYPE_DEBUG, 1093 LOG (GNUNET_ERROR_TYPE_DEBUG,
1098 "Error getting control overlapped result while writing to pipe: %u\n", 1094 "Error getting control overlapped result while writing to pipe: %u\n",
1099 GetLastError ()); 1095 GetLastError ());
1100 } 1096 }
1101 else 1097 else
1102 { 1098 {
1103 LOG (GNUNET_ERROR_TYPE_DEBUG, 1099 LOG (GNUNET_ERROR_TYPE_DEBUG,
1104 "Wrote %u bytes (ovr says %u), picking the greatest\n", 1100 "Wrote %u bytes (ovr says %u), picking the greatest\n",
1105 bytes_written, ovr); 1101 bytes_written,
1102 ovr);
1106 } 1103 }
1107 } 1104 }
1108 if (bytes_written == 0) 1105 if (bytes_written == 0)
1109 { 1106 {
1110 if (n > 0) 1107 if (n > 0)
1111 { 1108 {
1112 LOG (GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes, returning -1 with EAGAIN\n", bytes_written); 1109 LOG (GNUNET_ERROR_TYPE_DEBUG,
1110 "Wrote %u bytes, returning -1 with EAGAIN\n",
1111 bytes_written);
1113 errno = EAGAIN; 1112 errno = EAGAIN;
1114 return GNUNET_SYSERR; 1113 return GNUNET_SYSERR;
1115 } 1114 }
@@ -1136,7 +1135,7 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h,
1136 * @return number of bytes written on success, #GNUNET_SYSERR on error 1135 * @return number of bytes written on success, #GNUNET_SYSERR on error
1137 */ 1136 */
1138ssize_t 1137ssize_t
1139GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle * h, 1138GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle *h,
1140 const void *buffer, 1139 const void *buffer,
1141 size_t n) 1140 size_t n)
1142{ 1141{
@@ -1150,28 +1149,28 @@ GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle * h,
1150 DWORD bytes_written; 1149 DWORD bytes_written;
1151 /* We do a non-overlapped write, which is as blocking as it gets */ 1150 /* We do a non-overlapped write, which is as blocking as it gets */
1152 LOG (GNUNET_ERROR_TYPE_DEBUG, "Writing %u bytes\n", n); 1151 LOG (GNUNET_ERROR_TYPE_DEBUG, "Writing %u bytes\n", n);
1153 if (!WriteFile (h->h, buffer, n, &bytes_written, NULL)) 1152 if (! WriteFile (h->h, buffer, n, &bytes_written, NULL))
1154 { 1153 {
1155 SetErrnoFromWinError (GetLastError ()); 1154 SetErrnoFromWinError (GetLastError ());
1156 LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe: %u\n", 1155 LOG (GNUNET_ERROR_TYPE_DEBUG,
1157 GetLastError ()); 1156 "Error writing to pipe: %u\n",
1157 GetLastError ());
1158 return GNUNET_SYSERR; 1158 return GNUNET_SYSERR;
1159 } 1159 }
1160 if (bytes_written == 0 && n > 0) 1160 if (bytes_written == 0 && n > 0)
1161 { 1161 {
1162 LOG (GNUNET_ERROR_TYPE_DEBUG, "Waiting for pipe to clean\n"); 1162 LOG (GNUNET_ERROR_TYPE_DEBUG, "Waiting for pipe to clean\n");
1163 WaitForSingleObject (h->h, INFINITE); 1163 WaitForSingleObject (h->h, INFINITE);
1164 if (!WriteFile (h->h, buffer, n, &bytes_written, NULL)) 1164 if (! WriteFile (h->h, buffer, n, &bytes_written, NULL))
1165 { 1165 {
1166 SetErrnoFromWinError (GetLastError ()); 1166 SetErrnoFromWinError (GetLastError ());
1167 LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe: %u\n", 1167 LOG (GNUNET_ERROR_TYPE_DEBUG,
1168 GetLastError ()); 1168 "Error writing to pipe: %u\n",
1169 GetLastError ());
1169 return GNUNET_SYSERR; 1170 return GNUNET_SYSERR;
1170 } 1171 }
1171 } 1172 }
1172 LOG (GNUNET_ERROR_TYPE_DEBUG, 1173 LOG (GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes\n", bytes_written);
1173 "Wrote %u bytes\n",
1174 bytes_written);
1175 return bytes_written; 1174 return bytes_written;
1176#else 1175#else
1177 int flags; 1176 int flags;
@@ -1208,9 +1207,11 @@ GNUNET_DISK_fn_write (const char *fn,
1208 struct GNUNET_DISK_FileHandle *fh; 1207 struct GNUNET_DISK_FileHandle *fh;
1209 ssize_t ret; 1208 ssize_t ret;
1210 1209
1211 fh = GNUNET_DISK_file_open (fn, 1210 fh =
1212 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE 1211 GNUNET_DISK_file_open (fn,
1213 | GNUNET_DISK_OPEN_CREATE, mode); 1212 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE |
1213 GNUNET_DISK_OPEN_CREATE,
1214 mode);
1214 if (! fh) 1215 if (! fh)
1215 return GNUNET_SYSERR; 1216 return GNUNET_SYSERR;
1216 ret = GNUNET_DISK_file_write (fh, buffer, n); 1217 ret = GNUNET_DISK_file_write (fh, buffer, n);
@@ -1248,45 +1249,39 @@ GNUNET_DISK_directory_scan (const char *dir_name,
1248 dname = GNUNET_STRINGS_filename_expand (dir_name); 1249 dname = GNUNET_STRINGS_filename_expand (dir_name);
1249 if (NULL == dname) 1250 if (NULL == dname)
1250 return GNUNET_SYSERR; 1251 return GNUNET_SYSERR;
1251 while ( (strlen (dname) > 0) && 1252 while ((strlen (dname) > 0) && (dname[strlen (dname) - 1] == DIR_SEPARATOR))
1252 (dname[strlen (dname) - 1] == DIR_SEPARATOR) )
1253 dname[strlen (dname) - 1] = '\0'; 1253 dname[strlen (dname) - 1] = '\0';
1254 if (0 != STAT (dname, &istat)) 1254 if (0 != stat (dname, &istat))
1255 { 1255 {
1256 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, 1256 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", dname);
1257 "stat",
1258 dname);
1259 GNUNET_free (dname); 1257 GNUNET_free (dname);
1260 return GNUNET_SYSERR; 1258 return GNUNET_SYSERR;
1261 } 1259 }
1262 if (! S_ISDIR (istat.st_mode)) 1260 if (! S_ISDIR (istat.st_mode))
1263 { 1261 {
1264 LOG (GNUNET_ERROR_TYPE_WARNING, 1262 LOG (GNUNET_ERROR_TYPE_WARNING,
1265 _("Expected `%s' to be a directory!\n"), 1263 _ ("Expected `%s' to be a directory!\n"),
1266 dir_name); 1264 dir_name);
1267 GNUNET_free (dname); 1265 GNUNET_free (dname);
1268 return GNUNET_SYSERR; 1266 return GNUNET_SYSERR;
1269 } 1267 }
1270 errno = 0; 1268 errno = 0;
1271 dinfo = OPENDIR (dname); 1269 dinfo = opendir (dname);
1272 if ( (EACCES == errno) || 1270 if ((EACCES == errno) || (NULL == dinfo))
1273 (NULL == dinfo) )
1274 { 1271 {
1275 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, 1272 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "opendir", dname);
1276 "opendir",
1277 dname);
1278 if (NULL != dinfo) 1273 if (NULL != dinfo)
1279 CLOSEDIR (dinfo); 1274 closedir (dinfo);
1280 GNUNET_free (dname); 1275 GNUNET_free (dname);
1281 return GNUNET_SYSERR; 1276 return GNUNET_SYSERR;
1282 } 1277 }
1283 name_len = 256; 1278 name_len = 256;
1284 n_size = strlen (dname) + name_len + strlen (DIR_SEPARATOR_STR) + 1; 1279 n_size = strlen (dname) + name_len + strlen (DIR_SEPARATOR_STR) + 1;
1285 name = GNUNET_malloc (n_size); 1280 name = GNUNET_malloc (n_size);
1286 while (NULL != (finfo = READDIR (dinfo))) 1281 while (NULL != (finfo = readdir (dinfo)))
1287 { 1282 {
1288 if ( (0 == strcmp (finfo->d_name, ".")) || 1283 if ((0 == strcmp (finfo->d_name, ".")) ||
1289 (0 == strcmp (finfo->d_name, "..")) ) 1284 (0 == strcmp (finfo->d_name, "..")))
1290 continue; 1285 continue;
1291 if (NULL != callback) 1286 if (NULL != callback)
1292 { 1287 {
@@ -1304,16 +1299,14 @@ GNUNET_DISK_directory_scan (const char *dir_name,
1304 n_size, 1299 n_size,
1305 "%s%s%s", 1300 "%s%s%s",
1306 dname, 1301 dname,
1307 (0 == strcmp (dname, 1302 (0 == strcmp (dname, DIR_SEPARATOR_STR))
1308 DIR_SEPARATOR_STR)) 1303 ? ""
1309 ? "" 1304 : DIR_SEPARATOR_STR,
1310 : DIR_SEPARATOR_STR,
1311 finfo->d_name); 1305 finfo->d_name);
1312 ret = callback (callback_cls, 1306 ret = callback (callback_cls, name);
1313 name);
1314 if (GNUNET_OK != ret) 1307 if (GNUNET_OK != ret)
1315 { 1308 {
1316 CLOSEDIR (dinfo); 1309 closedir (dinfo);
1317 GNUNET_free (name); 1310 GNUNET_free (name);
1318 GNUNET_free (dname); 1311 GNUNET_free (dname);
1319 if (GNUNET_NO == ret) 1312 if (GNUNET_NO == ret)
@@ -1323,7 +1316,7 @@ GNUNET_DISK_directory_scan (const char *dir_name,
1323 } 1316 }
1324 count++; 1317 count++;
1325 } 1318 }
1326 CLOSEDIR (dinfo); 1319 closedir (dinfo);
1327 GNUNET_free (name); 1320 GNUNET_free (name);
1328 GNUNET_free (dname); 1321 GNUNET_free (dname);
1329 return count; 1322 return count;
@@ -1339,8 +1332,7 @@ GNUNET_DISK_directory_scan (const char *dir_name,
1339 * @return #GNUNET_OK 1332 * @return #GNUNET_OK
1340 */ 1333 */
1341static int 1334static int
1342remove_helper (void *unused, 1335remove_helper (void *unused, const char *fn)
1343 const char *fn)
1344{ 1336{
1345 (void) unused; 1337 (void) unused;
1346 (void) GNUNET_DISK_directory_remove (fn); 1338 (void) GNUNET_DISK_directory_remove (fn);
@@ -1365,35 +1357,26 @@ GNUNET_DISK_directory_remove (const char *filename)
1365 GNUNET_break (0); 1357 GNUNET_break (0);
1366 return GNUNET_SYSERR; 1358 return GNUNET_SYSERR;
1367 } 1359 }
1368 if (0 != LSTAT (filename, &istat)) 1360 if (0 != lstat (filename, &istat))
1369 return GNUNET_NO; /* file may not exist... */ 1361 return GNUNET_NO; /* file may not exist... */
1370 (void) CHMOD (filename, 1362 (void) chmod (filename, S_IWUSR | S_IRUSR | S_IXUSR);
1371 S_IWUSR | S_IRUSR | S_IXUSR); 1363 if (0 == unlink (filename))
1372 if (0 == UNLINK (filename))
1373 return GNUNET_OK; 1364 return GNUNET_OK;
1374 if ( (errno != EISDIR) && 1365 if ((errno != EISDIR) &&
1375 /* EISDIR is not sufficient in all cases, e.g. 1366 /* EISDIR is not sufficient in all cases, e.g.
1376 * sticky /tmp directory may result in EPERM on BSD. 1367 * sticky /tmp directory may result in EPERM on BSD.
1377 * So we also explicitly check "isDirectory" */ 1368 * So we also explicitly check "isDirectory" */
1378 (GNUNET_YES != 1369 (GNUNET_YES != GNUNET_DISK_directory_test (filename, GNUNET_YES)))
1379 GNUNET_DISK_directory_test (filename,
1380 GNUNET_YES)) )
1381 { 1370 {
1382 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, 1371 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "rmdir", filename);
1383 "rmdir",
1384 filename);
1385 return GNUNET_SYSERR; 1372 return GNUNET_SYSERR;
1386 } 1373 }
1387 if (GNUNET_SYSERR == 1374 if (GNUNET_SYSERR ==
1388 GNUNET_DISK_directory_scan (filename, 1375 GNUNET_DISK_directory_scan (filename, &remove_helper, NULL))
1389 &remove_helper,
1390 NULL))
1391 return GNUNET_SYSERR; 1376 return GNUNET_SYSERR;
1392 if (0 != RMDIR (filename)) 1377 if (0 != rmdir (filename))
1393 { 1378 {
1394 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, 1379 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "rmdir", filename);
1395 "rmdir",
1396 filename);
1397 return GNUNET_SYSERR; 1380 return GNUNET_SYSERR;
1398 } 1381 }
1399 return GNUNET_OK; 1382 return GNUNET_OK;
@@ -1408,8 +1391,7 @@ GNUNET_DISK_directory_remove (const char *filename)
1408 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 1391 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1409 */ 1392 */
1410int 1393int
1411GNUNET_DISK_file_copy (const char *src, 1394GNUNET_DISK_file_copy (const char *src, const char *dst)
1412 const char *dst)
1413{ 1395{
1414 char *buf; 1396 char *buf;
1415 uint64_t pos; 1397 uint64_t pos;
@@ -1419,41 +1401,30 @@ GNUNET_DISK_file_copy (const char *src,
1419 struct GNUNET_DISK_FileHandle *in; 1401 struct GNUNET_DISK_FileHandle *in;
1420 struct GNUNET_DISK_FileHandle *out; 1402 struct GNUNET_DISK_FileHandle *out;
1421 1403
1422 if (GNUNET_OK != 1404 if (GNUNET_OK != GNUNET_DISK_file_size (src, &size, GNUNET_YES, GNUNET_YES))
1423 GNUNET_DISK_file_size (src, 1405 {
1424 &size, 1406 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "stat", src);
1425 GNUNET_YES,
1426 GNUNET_YES))
1427 {
1428 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
1429 "stat",
1430 src);
1431 return GNUNET_SYSERR; 1407 return GNUNET_SYSERR;
1432 } 1408 }
1433 pos = 0; 1409 pos = 0;
1434 in = GNUNET_DISK_file_open (src, 1410 in =
1435 GNUNET_DISK_OPEN_READ, 1411 GNUNET_DISK_file_open (src, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE);
1436 GNUNET_DISK_PERM_NONE);
1437 if (! in) 1412 if (! in)
1438 { 1413 {
1439 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 1414 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", src);
1440 "open",
1441 src);
1442 return GNUNET_SYSERR; 1415 return GNUNET_SYSERR;
1443 } 1416 }
1444 out = 1417 out =
1445 GNUNET_DISK_file_open (dst, 1418 GNUNET_DISK_file_open (dst,
1446 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE | 1419 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE |
1447 GNUNET_DISK_OPEN_FAILIFEXISTS, 1420 GNUNET_DISK_OPEN_FAILIFEXISTS,
1448 GNUNET_DISK_PERM_USER_READ | 1421 GNUNET_DISK_PERM_USER_READ |
1449 GNUNET_DISK_PERM_USER_WRITE | 1422 GNUNET_DISK_PERM_USER_WRITE |
1450 GNUNET_DISK_PERM_GROUP_READ | 1423 GNUNET_DISK_PERM_GROUP_READ |
1451 GNUNET_DISK_PERM_GROUP_WRITE); 1424 GNUNET_DISK_PERM_GROUP_WRITE);
1452 if (!out) 1425 if (! out)
1453 { 1426 {
1454 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 1427 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", dst);
1455 "open",
1456 dst);
1457 GNUNET_DISK_file_close (in); 1428 GNUNET_DISK_file_close (in);
1458 return GNUNET_SYSERR; 1429 return GNUNET_SYSERR;
1459 } 1430 }
@@ -1463,17 +1434,11 @@ GNUNET_DISK_file_copy (const char *src,
1463 len = COPY_BLK_SIZE; 1434 len = COPY_BLK_SIZE;
1464 if (len > size - pos) 1435 if (len > size - pos)
1465 len = size - pos; 1436 len = size - pos;
1466 sret = GNUNET_DISK_file_read (in, 1437 sret = GNUNET_DISK_file_read (in, buf, len);
1467 buf, 1438 if ((sret < 0) || (len != (size_t) sret))
1468 len);
1469 if ( (sret < 0) ||
1470 (len != (size_t) sret) )
1471 goto FAIL; 1439 goto FAIL;
1472 sret = GNUNET_DISK_file_write (out, 1440 sret = GNUNET_DISK_file_write (out, buf, len);
1473 buf, 1441 if ((sret < 0) || (len != (size_t) sret))
1474 len);
1475 if ( (sret < 0) ||
1476 (len != (size_t) sret) )
1477 goto FAIL; 1442 goto FAIL;
1478 pos += len; 1443 pos += len;
1479 } 1444 }
@@ -1503,8 +1468,7 @@ GNUNET_DISK_filename_canonicalize (char *fn)
1503 { 1468 {
1504 c = *idx; 1469 c = *idx;
1505 1470
1506 if (c == '/' || c == '\\' || c == ':' || 1471 if (c == '/' || c == '\\' || c == ':' || c == '*' || c == '?' || c == '"' ||
1507 c == '*' || c == '?' || c == '"' ||
1508 c == '<' || c == '>' || c == '|') 1472 c == '<' || c == '>' || c == '|')
1509 { 1473 {
1510 *idx = '_'; 1474 *idx = '_';
@@ -1513,7 +1477,6 @@ GNUNET_DISK_filename_canonicalize (char *fn)
1513} 1477}
1514 1478
1515 1479
1516
1517/** 1480/**
1518 * @brief Change owner of a file 1481 * @brief Change owner of a file
1519 * 1482 *
@@ -1522,8 +1485,7 @@ GNUNET_DISK_filename_canonicalize (char *fn)
1522 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 1485 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
1523 */ 1486 */
1524int 1487int
1525GNUNET_DISK_file_change_owner (const char *filename, 1488GNUNET_DISK_file_change_owner (const char *filename, const char *user)
1526 const char *user)
1527{ 1489{
1528#ifndef MINGW 1490#ifndef MINGW
1529 struct passwd *pws; 1491 struct passwd *pws;
@@ -1532,18 +1494,14 @@ GNUNET_DISK_file_change_owner (const char *filename,
1532 if (NULL == pws) 1494 if (NULL == pws)
1533 { 1495 {
1534 LOG (GNUNET_ERROR_TYPE_ERROR, 1496 LOG (GNUNET_ERROR_TYPE_ERROR,
1535 _("Cannot obtain information about user `%s': %s\n"), 1497 _ ("Cannot obtain information about user `%s': %s\n"),
1536 user, 1498 user,
1537 STRERROR (errno)); 1499 strerror (errno));
1538 return GNUNET_SYSERR; 1500 return GNUNET_SYSERR;
1539 } 1501 }
1540 if (0 != chown (filename, 1502 if (0 != chown (filename, pws->pw_uid, pws->pw_gid))
1541 pws->pw_uid,
1542 pws->pw_gid))
1543 { 1503 {
1544 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, 1504 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "chown", filename);
1545 "chown",
1546 filename);
1547 return GNUNET_SYSERR; 1505 return GNUNET_SYSERR;
1548 } 1506 }
1549#endif 1507#endif
@@ -1590,12 +1548,18 @@ GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh,
1590 diff_high = (DWORD) ((diff >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF); 1548 diff_high = (DWORD) ((diff >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF);
1591 1549
1592 memset (&o, 0, sizeof (OVERLAPPED)); 1550 memset (&o, 0, sizeof (OVERLAPPED));
1593 o.Offset = (DWORD) (lock_start & 0xFFFFFFFF);; 1551 o.Offset = (DWORD) (lock_start & 0xFFFFFFFF);
1594 o.OffsetHigh = (DWORD) (((lock_start & ~0xFFFFFFFF) >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF); 1552 ;
1595 1553 o.OffsetHigh =
1596 if (!LockFileEx 1554 (DWORD) (((lock_start & ~0xFFFFFFFF) >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF);
1597 (fh->h, (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0) | LOCKFILE_FAIL_IMMEDIATELY, 1555
1598 0, diff_low, diff_high, &o)) 1556 if (! LockFileEx (fh->h,
1557 (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0) |
1558 LOCKFILE_FAIL_IMMEDIATELY,
1559 0,
1560 diff_low,
1561 diff_high,
1562 &o))
1599 { 1563 {
1600 SetErrnoFromWinError (GetLastError ()); 1564 SetErrnoFromWinError (GetLastError ());
1601 return GNUNET_SYSERR; 1565 return GNUNET_SYSERR;
@@ -1643,10 +1607,12 @@ GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh,
1643 diff_high = (DWORD) ((diff >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF); 1607 diff_high = (DWORD) ((diff >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF);
1644 1608
1645 memset (&o, 0, sizeof (OVERLAPPED)); 1609 memset (&o, 0, sizeof (OVERLAPPED));
1646 o.Offset = (DWORD) (unlock_start & 0xFFFFFFFF);; 1610 o.Offset = (DWORD) (unlock_start & 0xFFFFFFFF);
1647 o.OffsetHigh = (DWORD) (((unlock_start & ~0xFFFFFFFF) >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF); 1611 ;
1612 o.OffsetHigh = (DWORD) (
1613 ((unlock_start & ~0xFFFFFFFF) >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF);
1648 1614
1649 if (!UnlockFileEx (fh->h, 0, diff_low, diff_high, &o)) 1615 if (! UnlockFileEx (fh->h, 0, diff_low, diff_high, &o))
1650 { 1616 {
1651 SetErrnoFromWinError (GetLastError ()); 1617 SetErrnoFromWinError (GetLastError ());
1652 return GNUNET_SYSERR; 1618 return GNUNET_SYSERR;
@@ -1694,7 +1660,7 @@ GNUNET_DISK_file_open (const char *fn,
1694#ifndef MINGW 1660#ifndef MINGW
1695 mode = 0; 1661 mode = 0;
1696 if (GNUNET_DISK_OPEN_READWRITE == (flags & GNUNET_DISK_OPEN_READWRITE)) 1662 if (GNUNET_DISK_OPEN_READWRITE == (flags & GNUNET_DISK_OPEN_READWRITE))
1697 oflags = O_RDWR; /* note: O_RDWR is NOT always O_RDONLY | O_WRONLY */ 1663 oflags = O_RDWR; /* note: O_RDWR is NOT always O_RDONLY | O_WRONLY */
1698 else if (flags & GNUNET_DISK_OPEN_READ) 1664 else if (flags & GNUNET_DISK_OPEN_READ)
1699 oflags = O_RDONLY; 1665 oflags = O_RDONLY;
1700 else if (flags & GNUNET_DISK_OPEN_WRITE) 1666 else if (flags & GNUNET_DISK_OPEN_WRITE)
@@ -1706,26 +1672,28 @@ GNUNET_DISK_file_open (const char *fn,
1706 return NULL; 1672 return NULL;
1707 } 1673 }
1708 if (flags & GNUNET_DISK_OPEN_FAILIFEXISTS) 1674 if (flags & GNUNET_DISK_OPEN_FAILIFEXISTS)
1709 oflags |= (O_CREAT | O_EXCL); 1675 oflags |= (O_CREAT | O_EXCL);
1710 if (flags & GNUNET_DISK_OPEN_TRUNCATE) 1676 if (flags & GNUNET_DISK_OPEN_TRUNCATE)
1711 oflags |= O_TRUNC; 1677 oflags |= O_TRUNC;
1712 if (flags & GNUNET_DISK_OPEN_APPEND) 1678 if (flags & GNUNET_DISK_OPEN_APPEND)
1713 oflags |= O_APPEND; 1679 oflags |= O_APPEND;
1714 if(GNUNET_NO == GNUNET_DISK_file_test(fn)) 1680 if (GNUNET_NO == GNUNET_DISK_file_test (fn))
1715 { 1681 {
1716 if (flags & GNUNET_DISK_OPEN_CREATE ) 1682 if (flags & GNUNET_DISK_OPEN_CREATE)
1717 { 1683 {
1718 (void) GNUNET_DISK_directory_create_for_file (expfn); 1684 (void) GNUNET_DISK_directory_create_for_file (expfn);
1719 oflags |= O_CREAT; 1685 oflags |= O_CREAT;
1720 mode = translate_unix_perms (perm); 1686 mode = translate_unix_perms (perm);
1721 } 1687 }
1722 } 1688 }
1723 1689
1724 fd = open (expfn, oflags 1690 fd = open (expfn,
1691 oflags
1725#if O_CLOEXEC 1692#if O_CLOEXEC
1726 | O_CLOEXEC 1693 | O_CLOEXEC
1727#endif 1694#endif
1728 | O_LARGEFILE, mode); 1695 | O_LARGEFILE,
1696 mode);
1729 if (fd == -1) 1697 if (fd == -1)
1730 { 1698 {
1731 if (0 == (flags & GNUNET_DISK_OPEN_FAILIFEXISTS)) 1699 if (0 == (flags & GNUNET_DISK_OPEN_FAILIFEXISTS))
@@ -1767,10 +1735,14 @@ GNUNET_DISK_file_open (const char *fn,
1767 disp = OPEN_EXISTING; 1735 disp = OPEN_EXISTING;
1768 } 1736 }
1769 1737
1770 if (ERROR_SUCCESS == plibc_conv_to_win_pathwconv(expfn, wexpfn)) 1738 if (ERROR_SUCCESS == plibc_conv_to_win_pathwconv (expfn, wexpfn))
1771 h = CreateFileW (wexpfn, access, 1739 h = CreateFileW (wexpfn,
1772 FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, 1740 access,
1773 disp, FILE_ATTRIBUTE_NORMAL, NULL); 1741 FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
1742 NULL,
1743 disp,
1744 FILE_ATTRIBUTE_NORMAL,
1745 NULL);
1774 else 1746 else
1775 h = INVALID_HANDLE_VALUE; 1747 h = INVALID_HANDLE_VALUE;
1776 if (h == INVALID_HANDLE_VALUE) 1748 if (h == INVALID_HANDLE_VALUE)
@@ -1844,7 +1816,7 @@ GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h)
1844 } 1816 }
1845 if (h->oOverlapWrite) 1817 if (h->oOverlapWrite)
1846 { 1818 {
1847 if (!CloseHandle (h->oOverlapWrite->hEvent)) 1819 if (! CloseHandle (h->oOverlapWrite->hEvent))
1848 { 1820 {
1849 SetErrnoFromWinError (GetLastError ()); 1821 SetErrnoFromWinError (GetLastError ());
1850 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "close"); 1822 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "close");
@@ -1888,8 +1860,8 @@ GNUNET_DISK_get_handle_from_w32_handle (HANDLE osfh)
1888 ftype = GNUNET_DISK_HANLDE_TYPE_PIPE; 1860 ftype = GNUNET_DISK_HANLDE_TYPE_PIPE;
1889 break; 1861 break;
1890 case FILE_TYPE_UNKNOWN: 1862 case FILE_TYPE_UNKNOWN:
1891 if ( (GetLastError () == NO_ERROR) || 1863 if ((GetLastError () == NO_ERROR) ||
1892 (GetLastError () == ERROR_INVALID_HANDLE) ) 1864 (GetLastError () == ERROR_INVALID_HANDLE))
1893 { 1865 {
1894 if (0 != ResetEvent (osfh)) 1866 if (0 != ResetEvent (osfh))
1895 ftype = GNUNET_DISK_HANLDE_TYPE_EVENT; 1867 ftype = GNUNET_DISK_HANLDE_TYPE_EVENT;
@@ -1938,8 +1910,7 @@ GNUNET_DISK_get_handle_from_int_fd (int fno)
1938{ 1910{
1939 struct GNUNET_DISK_FileHandle *fh; 1911 struct GNUNET_DISK_FileHandle *fh;
1940 1912
1941 if ( (((off_t) -1) == lseek (fno, 0, SEEK_CUR)) && 1913 if ((((off_t) -1) == lseek (fno, 0, SEEK_CUR)) && (EBADF == errno))
1942 (EBADF == errno) )
1943 return NULL; /* invalid FD */ 1914 return NULL; /* invalid FD */
1944 1915
1945#ifndef WINDOWS 1916#ifndef WINDOWS
@@ -2019,7 +1990,8 @@ struct GNUNET_DISK_MapHandle
2019void * 1990void *
2020GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h, 1991GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h,
2021 struct GNUNET_DISK_MapHandle **m, 1992 struct GNUNET_DISK_MapHandle **m,
2022 enum GNUNET_DISK_MapType access, size_t len) 1993 enum GNUNET_DISK_MapType access,
1994 size_t len)
2023{ 1995{
2024 if (NULL == h) 1996 if (NULL == h)
2025 { 1997 {
@@ -2062,7 +2034,7 @@ GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h,
2062 } 2034 }
2063 2035
2064 (*m)->addr = MapViewOfFile ((*m)->h, mapAccess, 0, 0, len); 2036 (*m)->addr = MapViewOfFile ((*m)->h, mapAccess, 0, 0, len);
2065 if (!(*m)->addr) 2037 if (! (*m)->addr)
2066 { 2038 {
2067 SetErrnoFromWinError (GetLastError ()); 2039 SetErrnoFromWinError (GetLastError ());
2068 CloseHandle ((*m)->h); 2040 CloseHandle ((*m)->h);
@@ -2111,7 +2083,7 @@ GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h)
2111 ret = UnmapViewOfFile (h->addr) ? GNUNET_OK : GNUNET_SYSERR; 2083 ret = UnmapViewOfFile (h->addr) ? GNUNET_OK : GNUNET_SYSERR;
2112 if (ret != GNUNET_OK) 2084 if (ret != GNUNET_OK)
2113 SetErrnoFromWinError (GetLastError ()); 2085 SetErrnoFromWinError (GetLastError ());
2114 if (!CloseHandle (h->h) && (ret == GNUNET_OK)) 2086 if (! CloseHandle (h->h) && (ret == GNUNET_OK))
2115 { 2087 {
2116 ret = GNUNET_SYSERR; 2088 ret = GNUNET_SYSERR;
2117 SetErrnoFromWinError (GetLastError ()); 2089 SetErrnoFromWinError (GetLastError ());
@@ -2155,7 +2127,7 @@ GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h)
2155 2127
2156#if WINDOWS 2128#if WINDOWS
2157#ifndef PIPE_BUF 2129#ifndef PIPE_BUF
2158#define PIPE_BUF 512 2130#define PIPE_BUF 512
2159#endif 2131#endif
2160/* Copyright Bob Byrnes <byrnes <at> curl.com> 2132/* Copyright Bob Byrnes <byrnes <at> curl.com>
2161 http://permalink.gmane.org/gmane.os.cygwin.patches/2121 2133 http://permalink.gmane.org/gmane.os.cygwin.patches/2121
@@ -2168,9 +2140,12 @@ GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h)
2168 Note that the return value is either NO_ERROR or GetLastError, 2140 Note that the return value is either NO_ERROR or GetLastError,
2169 unlike CreatePipe, which returns a bool for success or failure. */ 2141 unlike CreatePipe, which returns a bool for success or failure. */
2170static int 2142static int
2171create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr, 2143create_selectable_pipe (PHANDLE read_pipe_ptr,
2172 LPSECURITY_ATTRIBUTES sa_ptr, DWORD psize, 2144 PHANDLE write_pipe_ptr,
2173 DWORD dwReadMode, DWORD dwWriteMode) 2145 LPSECURITY_ATTRIBUTES sa_ptr,
2146 DWORD psize,
2147 DWORD dwReadMode,
2148 DWORD dwWriteMode)
2174{ 2149{
2175 /* Default to error. */ 2150 /* Default to error. */
2176 *read_pipe_ptr = *write_pipe_ptr = INVALID_HANDLE_VALUE; 2151 *read_pipe_ptr = *write_pipe_ptr = INVALID_HANDLE_VALUE;
@@ -2191,10 +2166,15 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr,
2191 { 2166 {
2192 static volatile LONG pipe_unique_id; 2167 static volatile LONG pipe_unique_id;
2193 2168
2194 snprintf (pipename, sizeof pipename, "\\\\.\\pipe\\gnunet-%d-%ld", 2169 snprintf (pipename,
2195 getpid (), InterlockedIncrement ((LONG *) & pipe_unique_id)); 2170 sizeof pipename,
2196 LOG (GNUNET_ERROR_TYPE_DEBUG, "CreateNamedPipe: name = %s, size = %lu\n", 2171 "\\\\.\\pipe\\gnunet-%d-%ld",
2197 pipename, psize); 2172 getpid (),
2173 InterlockedIncrement ((LONG *) &pipe_unique_id));
2174 LOG (GNUNET_ERROR_TYPE_DEBUG,
2175 "CreateNamedPipe: name = %s, size = %lu\n",
2176 pipename,
2177 psize);
2198 /* Use CreateNamedPipe instead of CreatePipe, because the latter 2178 /* Use CreateNamedPipe instead of CreatePipe, because the latter
2199 * returns a write handle that does not permit FILE_READ_ATTRIBUTES 2179 * returns a write handle that does not permit FILE_READ_ATTRIBUTES
2200 * access, on versions of win32 earlier than WinXP SP2. 2180 * access, on versions of win32 earlier than WinXP SP2.
@@ -2203,10 +2183,15 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr,
2203 * It's important to only allow a single instance, to ensure that 2183 * It's important to only allow a single instance, to ensure that
2204 * the pipe was not created earlier by some other process, even if 2184 * the pipe was not created earlier by some other process, even if
2205 * the pid has been reused. */ 2185 * the pid has been reused. */
2206 read_pipe = CreateNamedPipeA (pipename, PIPE_ACCESS_INBOUND | FILE_FLAG_FIRST_PIPE_INSTANCE | dwReadMode, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 1, /* max instances */ 2186 read_pipe = CreateNamedPipeA (pipename,
2207 psize, /* output buffer size */ 2187 PIPE_ACCESS_INBOUND |
2208 psize, /* input buffer size */ 2188 FILE_FLAG_FIRST_PIPE_INSTANCE | dwReadMode,
2209 NMPWAIT_USE_DEFAULT_WAIT, sa_ptr); 2189 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE,
2190 1, /* max instances */
2191 psize, /* output buffer size */
2192 psize, /* input buffer size */
2193 NMPWAIT_USE_DEFAULT_WAIT,
2194 sa_ptr);
2210 2195
2211 if (read_pipe != INVALID_HANDLE_VALUE) 2196 if (read_pipe != INVALID_HANDLE_VALUE)
2212 { 2197 {
@@ -2233,10 +2218,12 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr,
2233 * Return an anonymous pipe as the best approximation. */ 2218 * Return an anonymous pipe as the best approximation. */
2234 LOG (GNUNET_ERROR_TYPE_DEBUG, 2219 LOG (GNUNET_ERROR_TYPE_DEBUG,
2235 "CreateNamedPipe not implemented, resorting to " 2220 "CreateNamedPipe not implemented, resorting to "
2236 "CreatePipe: size = %lu\n", psize); 2221 "CreatePipe: size = %lu\n",
2222 psize);
2237 if (CreatePipe (read_pipe_ptr, write_pipe_ptr, sa_ptr, psize)) 2223 if (CreatePipe (read_pipe_ptr, write_pipe_ptr, sa_ptr, psize))
2238 { 2224 {
2239 LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p, write handle = %p\n", 2225 LOG (GNUNET_ERROR_TYPE_DEBUG,
2226 "pipe read handle = %p, write handle = %p\n",
2240 *read_pipe_ptr, 2227 *read_pipe_ptr,
2241 *write_pipe_ptr); 2228 *write_pipe_ptr);
2242 return GNUNET_OK; 2229 return GNUNET_OK;
@@ -2254,8 +2241,12 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr,
2254 2241
2255 /* Open the named pipe for writing. 2242 /* Open the named pipe for writing.
2256 * Be sure to permit FILE_READ_ATTRIBUTES access. */ 2243 * Be sure to permit FILE_READ_ATTRIBUTES access. */
2257 write_pipe = CreateFileA (pipename, GENERIC_WRITE | FILE_READ_ATTRIBUTES, 0, /* share mode */ 2244 write_pipe = CreateFileA (pipename,
2258 sa_ptr, OPEN_EXISTING, dwWriteMode, /* flags and attributes */ 2245 GENERIC_WRITE | FILE_READ_ATTRIBUTES,
2246 0, /* share mode */
2247 sa_ptr,
2248 OPEN_EXISTING,
2249 dwWriteMode, /* flags and attributes */
2259 0); /* handle to template file */ 2250 0); /* handle to template file */
2260 2251
2261 if (write_pipe == INVALID_HANDLE_VALUE) 2252 if (write_pipe == INVALID_HANDLE_VALUE)
@@ -2287,9 +2278,9 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr,
2287 */ 2278 */
2288struct GNUNET_DISK_PipeHandle * 2279struct GNUNET_DISK_PipeHandle *
2289GNUNET_DISK_pipe (int blocking_read, 2280GNUNET_DISK_pipe (int blocking_read,
2290 int blocking_write, 2281 int blocking_write,
2291 int inherit_read, 2282 int inherit_read,
2292 int inherit_write) 2283 int inherit_write)
2293{ 2284{
2294#ifndef MINGW 2285#ifndef MINGW
2295 int fd[2]; 2286 int fd[2];
@@ -2302,14 +2293,11 @@ GNUNET_DISK_pipe (int blocking_read,
2302 if (ret == -1) 2293 if (ret == -1)
2303 { 2294 {
2304 eno = errno; 2295 eno = errno;
2305 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, 2296 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe");
2306 "pipe");
2307 errno = eno; 2297 errno = eno;
2308 return NULL; 2298 return NULL;
2309 } 2299 }
2310 return GNUNET_DISK_pipe_from_fd (blocking_read, 2300 return GNUNET_DISK_pipe_from_fd (blocking_read, blocking_write, fd);
2311 blocking_write,
2312 fd);
2313#else 2301#else
2314 struct GNUNET_DISK_PipeHandle *p; 2302 struct GNUNET_DISK_PipeHandle *p;
2315 BOOL ret; 2303 BOOL ret;
@@ -2329,11 +2317,13 @@ GNUNET_DISK_pipe (int blocking_read,
2329 * Pipes are not seekable, and need no offsets, which is 2317 * Pipes are not seekable, and need no offsets, which is
2330 * probably why it works for them. 2318 * probably why it works for them.
2331 */ 2319 */
2332 ret = 2320 ret = create_selectable_pipe (&p->fd[0]->h,
2333 create_selectable_pipe (&p->fd[0]->h, &p->fd[1]->h, NULL, 0, 2321 &p->fd[1]->h,
2334 FILE_FLAG_OVERLAPPED, 2322 NULL,
2335 FILE_FLAG_OVERLAPPED); 2323 0,
2336 if (!ret) 2324 FILE_FLAG_OVERLAPPED,
2325 FILE_FLAG_OVERLAPPED);
2326 if (! ret)
2337 { 2327 {
2338 SetErrnoFromWinError (GetLastError ()); 2328 SetErrnoFromWinError (GetLastError ());
2339 save_errno = errno; 2329 save_errno = errno;
@@ -2343,9 +2333,13 @@ GNUNET_DISK_pipe (int blocking_read,
2343 errno = save_errno; 2333 errno = save_errno;
2344 return NULL; 2334 return NULL;
2345 } 2335 }
2346 if (!DuplicateHandle 2336 if (! DuplicateHandle (GetCurrentProcess (),
2347 (GetCurrentProcess (), p->fd[0]->h, GetCurrentProcess (), &tmp_handle, 0, 2337 p->fd[0]->h,
2348 inherit_read == GNUNET_YES ? TRUE : FALSE, DUPLICATE_SAME_ACCESS)) 2338 GetCurrentProcess (),
2339 &tmp_handle,
2340 0,
2341 inherit_read == GNUNET_YES ? TRUE : FALSE,
2342 DUPLICATE_SAME_ACCESS))
2349 { 2343 {
2350 SetErrnoFromWinError (GetLastError ()); 2344 SetErrnoFromWinError (GetLastError ());
2351 save_errno = errno; 2345 save_errno = errno;
@@ -2360,9 +2354,13 @@ GNUNET_DISK_pipe (int blocking_read,
2360 CloseHandle (p->fd[0]->h); 2354 CloseHandle (p->fd[0]->h);
2361 p->fd[0]->h = tmp_handle; 2355 p->fd[0]->h = tmp_handle;
2362 2356
2363 if (!DuplicateHandle 2357 if (! DuplicateHandle (GetCurrentProcess (),
2364 (GetCurrentProcess (), p->fd[1]->h, GetCurrentProcess (), &tmp_handle, 0, 2358 p->fd[1]->h,
2365 inherit_write == GNUNET_YES ? TRUE : FALSE, DUPLICATE_SAME_ACCESS)) 2359 GetCurrentProcess (),
2360 &tmp_handle,
2361 0,
2362 inherit_write == GNUNET_YES ? TRUE : FALSE,
2363 DUPLICATE_SAME_ACCESS))
2366 { 2364 {
2367 SetErrnoFromWinError (GetLastError ()); 2365 SetErrnoFromWinError (GetLastError ());
2368 save_errno = errno; 2366 save_errno = errno;
@@ -2423,14 +2421,14 @@ GNUNET_DISK_pipe_from_fd (int blocking_read, int blocking_write, int fd[2])
2423 { 2421 {
2424 p->fd[0] = GNUNET_new (struct GNUNET_DISK_FileHandle); 2422 p->fd[0] = GNUNET_new (struct GNUNET_DISK_FileHandle);
2425 p->fd[0]->fd = fd[0]; 2423 p->fd[0]->fd = fd[0];
2426 if (!blocking_read) 2424 if (! blocking_read)
2427 { 2425 {
2428 flags = fcntl (fd[0], F_GETFL); 2426 flags = fcntl (fd[0], F_GETFL);
2429 flags |= O_NONBLOCK; 2427 flags |= O_NONBLOCK;
2430 if (0 > fcntl (fd[0], F_SETFL, flags)) 2428 if (0 > fcntl (fd[0], F_SETFL, flags))
2431 { 2429 {
2432 ret = -1; 2430 ret = -1;
2433 eno = errno; 2431 eno = errno;
2434 } 2432 }
2435 } 2433 }
2436 flags = fcntl (fd[0], F_GETFD); 2434 flags = fcntl (fd[0], F_GETFD);
@@ -2446,14 +2444,14 @@ GNUNET_DISK_pipe_from_fd (int blocking_read, int blocking_write, int fd[2])
2446 { 2444 {
2447 p->fd[1] = GNUNET_new (struct GNUNET_DISK_FileHandle); 2445 p->fd[1] = GNUNET_new (struct GNUNET_DISK_FileHandle);
2448 p->fd[1]->fd = fd[1]; 2446 p->fd[1]->fd = fd[1];
2449 if (!blocking_write) 2447 if (! blocking_write)
2450 { 2448 {
2451 flags = fcntl (fd[1], F_GETFL); 2449 flags = fcntl (fd[1], F_GETFL);
2452 flags |= O_NONBLOCK; 2450 flags |= O_NONBLOCK;
2453 if (0 > fcntl (fd[1], F_SETFL, flags)) 2451 if (0 > fcntl (fd[1], F_SETFL, flags))
2454 { 2452 {
2455 ret = -1; 2453 ret = -1;
2456 eno = errno; 2454 eno = errno;
2457 } 2455 }
2458 } 2456 }
2459 flags = fcntl (fd[1], F_GETFD); 2457 flags = fcntl (fd[1], F_GETFD);
@@ -2663,7 +2661,8 @@ GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p,
2663 */ 2661 */
2664int 2662int
2665GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh, 2663GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh,
2666 void *dst, size_t dst_len) 2664 void *dst,
2665 size_t dst_len)
2667{ 2666{
2668 if (NULL == fh) 2667 if (NULL == fh)
2669 return GNUNET_SYSERR; 2668 return GNUNET_SYSERR;
@@ -2689,29 +2688,20 @@ GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh,
2689 * @return #GNUNET_OK on success 2688 * @return #GNUNET_OK on success
2690 */ 2689 */
2691static int 2690static int
2692purge_cfg_dir (void *cls, 2691purge_cfg_dir (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
2693 const struct GNUNET_CONFIGURATION_Handle *cfg)
2694{ 2692{
2695 const char *option = cls; 2693 const char *option = cls;
2696 char *tmpname; 2694 char *tmpname;
2697 2695
2698 if (GNUNET_OK != 2696 if (GNUNET_OK !=
2699 GNUNET_CONFIGURATION_get_value_filename (cfg, 2697 GNUNET_CONFIGURATION_get_value_filename (cfg, "PATHS", option, &tmpname))
2700 "PATHS", 2698 {
2701 option, 2699 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "PATHS", option);
2702 &tmpname))
2703 {
2704 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
2705 "PATHS",
2706 option);
2707 return GNUNET_NO; 2700 return GNUNET_NO;
2708 } 2701 }
2709 if (GNUNET_SYSERR == 2702 if (GNUNET_SYSERR == GNUNET_DISK_directory_remove (tmpname))
2710 GNUNET_DISK_directory_remove (tmpname))
2711 { 2703 {
2712 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 2704 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "remove", tmpname);
2713 "remove",
2714 tmpname);
2715 GNUNET_free (tmpname); 2705 GNUNET_free (tmpname);
2716 return GNUNET_OK; 2706 return GNUNET_OK;
2717 } 2707 }
@@ -2728,13 +2718,12 @@ purge_cfg_dir (void *cls,
2728 * @param option option with the dir name to purge 2718 * @param option option with the dir name to purge
2729 */ 2719 */
2730void 2720void
2731GNUNET_DISK_purge_cfg_dir (const char *cfg_filename, 2721GNUNET_DISK_purge_cfg_dir (const char *cfg_filename, const char *option)
2732 const char *option)
2733{ 2722{
2734 GNUNET_break (GNUNET_OK == 2723 GNUNET_break (GNUNET_OK ==
2735 GNUNET_CONFIGURATION_parse_and_run (cfg_filename, 2724 GNUNET_CONFIGURATION_parse_and_run (cfg_filename,
2736 &purge_cfg_dir, 2725 &purge_cfg_dir,
2737 (void *) option)); 2726 (void *) option));
2738} 2727}
2739 2728
2740 2729
diff --git a/src/util/dnsstub.c b/src/util/dnsstub.c
index a16a9a7dd..aa0c2191a 100644
--- a/src/util/dnsstub.c
+++ b/src/util/dnsstub.c
@@ -28,7 +28,8 @@
28/** 28/**
29 * Timeout for retrying DNS queries. 29 * Timeout for retrying DNS queries.
30 */ 30 */
31#define DNS_RETRANSMIT_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250) 31#define DNS_RETRANSMIT_DELAY \
32 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250)
32 33
33 34
34/** 35/**
@@ -92,7 +93,6 @@ struct GNUNET_DNSSTUB_RequestSocket
92 * Number of bytes in @a request. 93 * Number of bytes in @a request.
93 */ 94 */
94 size_t request_len; 95 size_t request_len;
95
96}; 96};
97 97
98 98
@@ -149,7 +149,6 @@ struct GNUNET_DNSSTUB_Context
149 * Length of @e sockets array. 149 * Length of @e sockets array.
150 */ 150 */
151 unsigned int num_sockets; 151 unsigned int num_sockets;
152
153}; 152};
154 153
155 154
@@ -223,13 +222,11 @@ open_socket (int af)
223 return NULL; 222 return NULL;
224 } 223 }
225 sa->sa_family = af; 224 sa->sa_family = af;
226 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (ret, 225 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (ret, sa, alen))
227 sa,
228 alen))
229 { 226 {
230 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 227 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
231 _("Could not bind to any port: %s\n"), 228 _ ("Could not bind to any port: %s\n"),
232 STRERROR (errno)); 229 strerror (errno));
233 GNUNET_NETWORK_socket_close (ret); 230 GNUNET_NETWORK_socket_close (ret);
234 return NULL; 231 return NULL;
235 } 232 }
@@ -249,7 +246,7 @@ get_request_socket (struct GNUNET_DNSSTUB_Context *ctx)
249{ 246{
250 struct GNUNET_DNSSTUB_RequestSocket *rs; 247 struct GNUNET_DNSSTUB_RequestSocket *rs;
251 248
252 for (unsigned int i=0;i<256;i++) 249 for (unsigned int i = 0; i < 256; i++)
253 { 250 {
254 rs = &ctx->sockets[GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 251 rs = &ctx->sockets[GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
255 ctx->num_sockets)]; 252 ctx->num_sockets)];
@@ -259,9 +256,7 @@ get_request_socket (struct GNUNET_DNSSTUB_Context *ctx)
259 if (NULL != rs->rc) 256 if (NULL != rs->rc)
260 { 257 {
261 /* signal "failure" */ 258 /* signal "failure" */
262 rs->rc (rs->rc_cls, 259 rs->rc (rs->rc_cls, NULL, 0);
263 NULL,
264 0);
265 rs->rc = NULL; 260 rs->rc = NULL;
266 } 261 }
267 if (NULL != rs->read_task) 262 if (NULL != rs->read_task)
@@ -294,16 +289,14 @@ get_request_socket (struct GNUNET_DNSSTUB_Context *ctx)
294 */ 289 */
295static int 290static int
296do_dns_read (struct GNUNET_DNSSTUB_RequestSocket *rs, 291do_dns_read (struct GNUNET_DNSSTUB_RequestSocket *rs,
297 struct GNUNET_NETWORK_Handle *dnsout) 292 struct GNUNET_NETWORK_Handle *dnsout)
298{ 293{
299 struct GNUNET_DNSSTUB_Context *ctx = rs->ctx; 294 struct GNUNET_DNSSTUB_Context *ctx = rs->ctx;
300 ssize_t r; 295 ssize_t r;
301 int len; 296 int len;
302 297
303#ifndef MINGW 298#ifndef MINGW
304 if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout), 299 if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout), FIONREAD, &len))
305 FIONREAD,
306 &len))
307 { 300 {
308 /* conservative choice: */ 301 /* conservative choice: */
309 len = UINT16_MAX; 302 len = UINT16_MAX;
@@ -312,9 +305,7 @@ do_dns_read (struct GNUNET_DNSSTUB_RequestSocket *rs,
312 /* port the code above? */ 305 /* port the code above? */
313 len = UINT16_MAX; 306 len = UINT16_MAX;
314#endif 307#endif
315 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 308 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving %d byte DNS reply\n", len);
316 "Receiving %d byte DNS reply\n",
317 len);
318 { 309 {
319 unsigned char buf[len] GNUNET_ALIGN; 310 unsigned char buf[len] GNUNET_ALIGN;
320 int found; 311 int found;
@@ -323,18 +314,15 @@ do_dns_read (struct GNUNET_DNSSTUB_RequestSocket *rs,
323 struct GNUNET_TUN_DnsHeader *dns; 314 struct GNUNET_TUN_DnsHeader *dns;
324 315
325 addrlen = sizeof (addr); 316 addrlen = sizeof (addr);
326 memset (&addr, 317 memset (&addr, 0, sizeof (addr));
327 0,
328 sizeof (addr));
329 r = GNUNET_NETWORK_socket_recvfrom (dnsout, 318 r = GNUNET_NETWORK_socket_recvfrom (dnsout,
330 buf, 319 buf,
331 sizeof (buf), 320 sizeof (buf),
332 (struct sockaddr*) &addr, 321 (struct sockaddr *) &addr,
333 &addrlen); 322 &addrlen);
334 if (-1 == r) 323 if (-1 == r)
335 { 324 {
336 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, 325 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "recvfrom");
337 "recvfrom");
338 GNUNET_NETWORK_socket_close (dnsout); 326 GNUNET_NETWORK_socket_close (dnsout);
339 return GNUNET_SYSERR; 327 return GNUNET_SYSERR;
340 } 328 }
@@ -343,8 +331,7 @@ do_dns_read (struct GNUNET_DNSSTUB_RequestSocket *rs,
343 { 331 {
344 if (0 == memcmp (&addr, 332 if (0 == memcmp (&addr,
345 &ds->ss, 333 &ds->ss,
346 GNUNET_MIN (sizeof (struct sockaddr_storage), 334 GNUNET_MIN (sizeof (struct sockaddr_storage), addrlen)))
347 addrlen)))
348 { 335 {
349 found = GNUNET_YES; 336 found = GNUNET_YES;
350 break; 337 break;
@@ -353,26 +340,24 @@ do_dns_read (struct GNUNET_DNSSTUB_RequestSocket *rs,
353 if (GNUNET_NO == found) 340 if (GNUNET_NO == found)
354 { 341 {
355 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 342 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
356 "Received DNS response from server we never asked (ignored)"); 343 "Received DNS response from server we never asked (ignored)");
357 return GNUNET_NO; 344 return GNUNET_NO;
358 } 345 }
359 if (sizeof (struct GNUNET_TUN_DnsHeader) > (size_t) r) 346 if (sizeof (struct GNUNET_TUN_DnsHeader) > (size_t) r)
360 { 347 {
361 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 348 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
362 _("Received DNS response that is too small (%u bytes)"), 349 _ ("Received DNS response that is too small (%u bytes)"),
363 (unsigned int) r); 350 (unsigned int) r);
364 return GNUNET_NO; 351 return GNUNET_NO;
365 } 352 }
366 dns = (struct GNUNET_TUN_DnsHeader *) buf; 353 dns = (struct GNUNET_TUN_DnsHeader *) buf;
367 if (NULL == rs->rc) 354 if (NULL == rs->rc)
368 { 355 {
369 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 356 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
370 "Request timeout or cancelled; ignoring reply\n"); 357 "Request timeout or cancelled; ignoring reply\n");
371 return GNUNET_NO; 358 return GNUNET_NO;
372 } 359 }
373 rs->rc (rs->rc_cls, 360 rs->rc (rs->rc_cls, dns, r);
374 dns,
375 r);
376 } 361 }
377 return GNUNET_OK; 362 return GNUNET_OK;
378} 363}
@@ -401,17 +386,16 @@ schedule_read (struct GNUNET_DNSSTUB_RequestSocket *rs)
401 GNUNET_SCHEDULER_cancel (rs->read_task); 386 GNUNET_SCHEDULER_cancel (rs->read_task);
402 rset = GNUNET_NETWORK_fdset_create (); 387 rset = GNUNET_NETWORK_fdset_create ();
403 if (NULL != rs->dnsout4) 388 if (NULL != rs->dnsout4)
404 GNUNET_NETWORK_fdset_set (rset, 389 GNUNET_NETWORK_fdset_set (rset, rs->dnsout4);
405 rs->dnsout4);
406 if (NULL != rs->dnsout6) 390 if (NULL != rs->dnsout6)
407 GNUNET_NETWORK_fdset_set (rset, 391 GNUNET_NETWORK_fdset_set (rset, rs->dnsout6);
408 rs->dnsout6); 392 rs->read_task =
409 rs->read_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 393 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
410 GNUNET_TIME_UNIT_FOREVER_REL, 394 GNUNET_TIME_UNIT_FOREVER_REL,
411 rset, 395 rset,
412 NULL, 396 NULL,
413 &read_response, 397 &read_response,
414 rs); 398 rs);
415 GNUNET_NETWORK_fdset_destroy (rset); 399 GNUNET_NETWORK_fdset_destroy (rset);
416} 400}
417 401
@@ -430,19 +414,13 @@ read_response (void *cls)
430 rs->read_task = NULL; 414 rs->read_task = NULL;
431 tc = GNUNET_SCHEDULER_get_task_context (); 415 tc = GNUNET_SCHEDULER_get_task_context ();
432 /* read and process ready sockets */ 416 /* read and process ready sockets */
433 if ( (NULL != rs->dnsout4) && 417 if ((NULL != rs->dnsout4) &&
434 (GNUNET_NETWORK_fdset_isset (tc->read_ready, 418 (GNUNET_NETWORK_fdset_isset (tc->read_ready, rs->dnsout4)) &&
435 rs->dnsout4)) && 419 (GNUNET_SYSERR == do_dns_read (rs, rs->dnsout4)))
436 (GNUNET_SYSERR ==
437 do_dns_read (rs,
438 rs->dnsout4)) )
439 rs->dnsout4 = NULL; 420 rs->dnsout4 = NULL;
440 if ( (NULL != rs->dnsout6) && 421 if ((NULL != rs->dnsout6) &&
441 (GNUNET_NETWORK_fdset_isset (tc->read_ready, 422 (GNUNET_NETWORK_fdset_isset (tc->read_ready, rs->dnsout6)) &&
442 rs->dnsout6)) && 423 (GNUNET_SYSERR == do_dns_read (rs, rs->dnsout6)))
443 (GNUNET_SYSERR ==
444 do_dns_read (rs,
445 rs->dnsout6)) )
446 rs->dnsout6 = NULL; 424 rs->dnsout6 = NULL;
447 /* re-schedule read task */ 425 /* re-schedule read task */
448 schedule_read (rs); 426 schedule_read (rs);
@@ -465,9 +443,8 @@ transmit_query (void *cls)
465 struct DnsServer *ds; 443 struct DnsServer *ds;
466 struct GNUNET_NETWORK_Handle *dnsout; 444 struct GNUNET_NETWORK_Handle *dnsout;
467 445
468 rs->retry_task = GNUNET_SCHEDULER_add_delayed (ctx->retry_freq, 446 rs->retry_task =
469 &transmit_query, 447 GNUNET_SCHEDULER_add_delayed (ctx->retry_freq, &transmit_query, rs);
470 rs);
471 ds = rs->ds_pos; 448 ds = rs->ds_pos;
472 rs->ds_pos = ds->next; 449 rs->ds_pos = ds->next;
473 if (NULL == rs->ds_pos) 450 if (NULL == rs->ds_pos)
@@ -499,22 +476,19 @@ transmit_query (void *cls)
499 "Unable to use configure DNS server, skipping\n"); 476 "Unable to use configure DNS server, skipping\n");
500 return; 477 return;
501 } 478 }
502 if (GNUNET_SYSERR == 479 if (GNUNET_SYSERR == GNUNET_NETWORK_socket_sendto (dnsout,
503 GNUNET_NETWORK_socket_sendto (dnsout, 480 rs->request,
504 rs->request, 481 rs->request_len,
505 rs->request_len, 482 sa,
506 sa, 483 salen))
507 salen))
508 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 484 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
509 _("Failed to send DNS request to %s: %s\n"), 485 _ ("Failed to send DNS request to %s: %s\n"),
510 GNUNET_a2s (sa, 486 GNUNET_a2s (sa, salen),
511 salen), 487 strerror (errno));
512 STRERROR (errno));
513 else 488 else
514 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
515 _("Sent DNS request to %s\n"), 490 _ ("Sent DNS request to %s\n"),
516 GNUNET_a2s (sa, 491 GNUNET_a2s (sa, salen));
517 salen));
518 schedule_read (rs); 492 schedule_read (rs);
519} 493}
520 494
@@ -531,10 +505,10 @@ transmit_query (void *cls)
531 */ 505 */
532struct GNUNET_DNSSTUB_RequestSocket * 506struct GNUNET_DNSSTUB_RequestSocket *
533GNUNET_DNSSTUB_resolve (struct GNUNET_DNSSTUB_Context *ctx, 507GNUNET_DNSSTUB_resolve (struct GNUNET_DNSSTUB_Context *ctx,
534 const void *request, 508 const void *request,
535 size_t request_len, 509 size_t request_len,
536 GNUNET_DNSSTUB_ResultCallback rc, 510 GNUNET_DNSSTUB_ResultCallback rc,
537 void *rc_cls) 511 void *rc_cls)
538{ 512{
539 struct GNUNET_DNSSTUB_RequestSocket *rs; 513 struct GNUNET_DNSSTUB_RequestSocket *rs;
540 514
@@ -553,11 +527,9 @@ GNUNET_DNSSTUB_resolve (struct GNUNET_DNSSTUB_Context *ctx,
553 rs->ds_pos = ctx->dns_head; 527 rs->ds_pos = ctx->dns_head;
554 rs->rc = rc; 528 rs->rc = rc;
555 rs->rc_cls = rc_cls; 529 rs->rc_cls = rc_cls;
556 rs->request = GNUNET_memdup (request, 530 rs->request = GNUNET_memdup (request, request_len);
557 request_len);
558 rs->request_len = request_len; 531 rs->request_len = request_len;
559 rs->retry_task = GNUNET_SCHEDULER_add_now (&transmit_query, 532 rs->retry_task = GNUNET_SCHEDULER_add_now (&transmit_query, rs);
560 rs);
561 return rs; 533 return rs;
562} 534}
563 535
@@ -603,8 +575,8 @@ GNUNET_DNSSTUB_start (unsigned int num_sockets)
603 } 575 }
604 ctx = GNUNET_new (struct GNUNET_DNSSTUB_Context); 576 ctx = GNUNET_new (struct GNUNET_DNSSTUB_Context);
605 ctx->num_sockets = num_sockets; 577 ctx->num_sockets = num_sockets;
606 ctx->sockets = GNUNET_new_array (num_sockets, 578 ctx->sockets =
607 struct GNUNET_DNSSTUB_RequestSocket); 579 GNUNET_new_array (num_sockets, struct GNUNET_DNSSTUB_RequestSocket);
608 ctx->retry_freq = DNS_RETRANSMIT_DELAY; 580 ctx->retry_freq = DNS_RETRANSMIT_DELAY;
609 return ctx; 581 return ctx;
610} 582}
@@ -627,9 +599,7 @@ GNUNET_DNSSTUB_add_dns_ip (struct GNUNET_DNSSTUB_Context *ctx,
627 struct in6_addr i6; 599 struct in6_addr i6;
628 600
629 ds = GNUNET_new (struct DnsServer); 601 ds = GNUNET_new (struct DnsServer);
630 if (1 == inet_pton (AF_INET, 602 if (1 == inet_pton (AF_INET, dns_ip, &i4))
631 dns_ip,
632 &i4))
633 { 603 {
634 struct sockaddr_in *s4 = (struct sockaddr_in *) &ds->ss; 604 struct sockaddr_in *s4 = (struct sockaddr_in *) &ds->ss;
635 605
@@ -640,9 +610,7 @@ GNUNET_DNSSTUB_add_dns_ip (struct GNUNET_DNSSTUB_Context *ctx,
640 s4->sin_len = (u_char) sizeof (struct sockaddr_in); 610 s4->sin_len = (u_char) sizeof (struct sockaddr_in);
641#endif 611#endif
642 } 612 }
643 else if (1 == inet_pton (AF_INET6, 613 else if (1 == inet_pton (AF_INET6, dns_ip, &i6))
644 dns_ip,
645 &i6))
646 { 614 {
647 struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) &ds->ss; 615 struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) &ds->ss;
648 616
@@ -661,9 +629,7 @@ GNUNET_DNSSTUB_add_dns_ip (struct GNUNET_DNSSTUB_Context *ctx,
661 GNUNET_free (ds); 629 GNUNET_free (ds);
662 return GNUNET_SYSERR; 630 return GNUNET_SYSERR;
663 } 631 }
664 GNUNET_CONTAINER_DLL_insert (ctx->dns_head, 632 GNUNET_CONTAINER_DLL_insert (ctx->dns_head, ctx->dns_tail, ds);
665 ctx->dns_tail,
666 ds);
667 return GNUNET_OK; 633 return GNUNET_OK;
668} 634}
669 635
@@ -686,23 +652,17 @@ GNUNET_DNSSTUB_add_dns_sa (struct GNUNET_DNSSTUB_Context *ctx,
686 switch (sa->sa_family) 652 switch (sa->sa_family)
687 { 653 {
688 case AF_INET: 654 case AF_INET:
689 GNUNET_memcpy (&ds->ss, 655 GNUNET_memcpy (&ds->ss, sa, sizeof (struct sockaddr_in));
690 sa,
691 sizeof (struct sockaddr_in));
692 break; 656 break;
693 case AF_INET6: 657 case AF_INET6:
694 GNUNET_memcpy (&ds->ss, 658 GNUNET_memcpy (&ds->ss, sa, sizeof (struct sockaddr_in6));
695 sa,
696 sizeof (struct sockaddr_in6));
697 break; 659 break;
698 default: 660 default:
699 GNUNET_break (0); 661 GNUNET_break (0);
700 GNUNET_free (ds); 662 GNUNET_free (ds);
701 return GNUNET_SYSERR; 663 return GNUNET_SYSERR;
702 } 664 }
703 GNUNET_CONTAINER_DLL_insert (ctx->dns_head, 665 GNUNET_CONTAINER_DLL_insert (ctx->dns_head, ctx->dns_tail, ds);
704 ctx->dns_tail,
705 ds);
706 return GNUNET_OK; 666 return GNUNET_OK;
707} 667}
708 668
@@ -734,12 +694,10 @@ GNUNET_DNSSTUB_stop (struct GNUNET_DNSSTUB_Context *ctx)
734 694
735 while (NULL != (ds = ctx->dns_head)) 695 while (NULL != (ds = ctx->dns_head))
736 { 696 {
737 GNUNET_CONTAINER_DLL_remove (ctx->dns_head, 697 GNUNET_CONTAINER_DLL_remove (ctx->dns_head, ctx->dns_tail, ds);
738 ctx->dns_tail,
739 ds);
740 GNUNET_free (ds); 698 GNUNET_free (ds);
741 } 699 }
742 for (unsigned int i=0;i<ctx->num_sockets;i++) 700 for (unsigned int i = 0; i < ctx->num_sockets; i++)
743 cleanup_rs (&ctx->sockets[i]); 701 cleanup_rs (&ctx->sockets[i]);
744 GNUNET_free (ctx->sockets); 702 GNUNET_free (ctx->sockets);
745 GNUNET_free (ctx); 703 GNUNET_free (ctx);
diff --git a/src/util/getopt.c b/src/util/getopt.c
index 048f52ee0..678e2a61f 100644
--- a/src/util/getopt.c
+++ b/src/util/getopt.c
@@ -563,7 +563,7 @@ GN_getopt_internal (int argc,
563 if (ambig && ! exact) 563 if (ambig && ! exact)
564 { 564 {
565 if (GNopterr) 565 if (GNopterr)
566 FPRINTF (stderr, 566 fprintf (stderr,
567 _ ("%s: option `%s' is ambiguous\n"), 567 _ ("%s: option `%s' is ambiguous\n"),
568 argv[0], 568 argv[0],
569 argv[GNoptind]); 569 argv[GNoptind]);
@@ -588,13 +588,13 @@ GN_getopt_internal (int argc,
588 { 588 {
589 if (argv[GNoptind - 1][1] == '-') 589 if (argv[GNoptind - 1][1] == '-')
590 /* --option */ 590 /* --option */
591 FPRINTF (stderr, 591 fprintf (stderr,
592 _ ("%s: option `--%s' does not allow an argument\n"), 592 _ ("%s: option `--%s' does not allow an argument\n"),
593 argv[0], 593 argv[0],
594 pfound->name); 594 pfound->name);
595 else 595 else
596 /* +option or -option */ 596 /* +option or -option */
597 FPRINTF (stderr, 597 fprintf (stderr,
598 _ ("%s: option `%c%s' does not allow an argument\n"), 598 _ ("%s: option `%c%s' does not allow an argument\n"),
599 argv[0], 599 argv[0],
600 argv[GNoptind - 1][0], 600 argv[GNoptind - 1][0],
@@ -614,7 +614,7 @@ GN_getopt_internal (int argc,
614 { 614 {
615 if (GNopterr) 615 if (GNopterr)
616 { 616 {
617 FPRINTF (stderr, 617 fprintf (stderr,
618 _ ("%s: option `%s' requires an argument\n"), 618 _ ("%s: option `%s' requires an argument\n"),
619 argv[0], 619 argv[0],
620 argv[GNoptind - 1]); 620 argv[GNoptind - 1]);
@@ -645,13 +645,13 @@ GN_getopt_internal (int argc,
645 { 645 {
646 if (argv[GNoptind][1] == '-') 646 if (argv[GNoptind][1] == '-')
647 /* --option */ 647 /* --option */
648 FPRINTF (stderr, 648 fprintf (stderr,
649 _ ("%s: unrecognized option `--%s'\n"), 649 _ ("%s: unrecognized option `--%s'\n"),
650 argv[0], 650 argv[0],
651 nextchar); 651 nextchar);
652 else 652 else
653 /* +option or -option */ 653 /* +option or -option */
654 FPRINTF (stderr, 654 fprintf (stderr,
655 _ ("%s: unrecognized option `%c%s'\n"), 655 _ ("%s: unrecognized option `%c%s'\n"),
656 argv[0], 656 argv[0],
657 argv[GNoptind][0], 657 argv[GNoptind][0],
@@ -679,9 +679,9 @@ GN_getopt_internal (int argc,
679 { 679 {
680 if (posixly_correct) 680 if (posixly_correct)
681 /* 1003.2 specifies the format of this message. */ 681 /* 1003.2 specifies the format of this message. */
682 FPRINTF (stderr, _ ("%s: illegal option -- %c\n"), argv[0], c); 682 fprintf (stderr, _ ("%s: illegal option -- %c\n"), argv[0], c);
683 else 683 else
684 FPRINTF (stderr, _ ("%s: invalid option -- %c\n"), argv[0], c); 684 fprintf (stderr, _ ("%s: invalid option -- %c\n"), argv[0], c);
685 } 685 }
686 return '?'; 686 return '?';
687 } 687 }
@@ -709,7 +709,7 @@ GN_getopt_internal (int argc,
709 if (GNopterr) 709 if (GNopterr)
710 { 710 {
711 /* 1003.2 specifies the format of this message. */ 711 /* 1003.2 specifies the format of this message. */
712 FPRINTF (stderr, 712 fprintf (stderr,
713 _ ("%s: option requires an argument -- %c\n"), 713 _ ("%s: option requires an argument -- %c\n"),
714 argv[0], 714 argv[0],
715 c); 715 c);
@@ -759,7 +759,7 @@ GN_getopt_internal (int argc,
759 if (ambig && ! exact) 759 if (ambig && ! exact)
760 { 760 {
761 if (GNopterr) 761 if (GNopterr)
762 FPRINTF (stderr, 762 fprintf (stderr,
763 _ ("%s: option `-W %s' is ambiguous\n"), 763 _ ("%s: option `-W %s' is ambiguous\n"),
764 argv[0], 764 argv[0],
765 argv[GNoptind]); 765 argv[GNoptind]);
@@ -779,7 +779,7 @@ GN_getopt_internal (int argc,
779 else 779 else
780 { 780 {
781 if (GNopterr) 781 if (GNopterr)
782 FPRINTF (stderr, 782 fprintf (stderr,
783 _ ("%s: option `-W %s' does not allow an argument\n"), 783 _ ("%s: option `-W %s' does not allow an argument\n"),
784 argv[0], 784 argv[0],
785 pfound->name); 785 pfound->name);
@@ -795,7 +795,7 @@ GN_getopt_internal (int argc,
795 else 795 else
796 { 796 {
797 if (GNopterr) 797 if (GNopterr)
798 FPRINTF (stderr, 798 fprintf (stderr,
799 _ ("%s: option `%s' requires an argument\n"), 799 _ ("%s: option `%s' requires an argument\n"),
800 argv[0], 800 argv[0],
801 argv[GNoptind - 1]); 801 argv[GNoptind - 1]);
@@ -845,7 +845,7 @@ GN_getopt_internal (int argc,
845 if (GNopterr) 845 if (GNopterr)
846 { 846 {
847 /* 1003.2 specifies the format of this message. */ 847 /* 1003.2 specifies the format of this message. */
848 FPRINTF (stderr, 848 fprintf (stderr,
849 _ ("%s: option requires an argument -- %c\n"), 849 _ ("%s: option requires an argument -- %c\n"),
850 argv[0], 850 argv[0],
851 c); 851 c);
@@ -972,7 +972,7 @@ GNUNET_GETOPT_run (const char *binaryOptions,
972 } 972 }
973 if (i == count) 973 if (i == count)
974 { 974 {
975 FPRINTF (stderr, _ ("Use %s to get a list of options.\n"), "--help"); 975 fprintf (stderr, _ ("Use %s to get a list of options.\n"), "--help");
976 cont = GNUNET_SYSERR; 976 cont = GNUNET_SYSERR;
977 } 977 }
978 } 978 }
@@ -983,7 +983,7 @@ GNUNET_GETOPT_run (const char *binaryOptions,
983 is the only option that was provided */ 983 is the only option that was provided */
984 if ((NULL != have_exclusive) && (optmatch > 1)) 984 if ((NULL != have_exclusive) && (optmatch > 1))
985 { 985 {
986 FPRINTF (stderr, 986 fprintf (stderr,
987 _ ("Option `%s' can't be used with other options.\n"), 987 _ ("Option `%s' can't be used with other options.\n"),
988 have_exclusive); 988 have_exclusive);
989 cont = GNUNET_SYSERR; 989 cont = GNUNET_SYSERR;
@@ -995,7 +995,7 @@ GNUNET_GETOPT_run (const char *binaryOptions,
995 { 995 {
996 if ((0 == seen[count]) && (allOptions[count].option_mandatory)) 996 if ((0 == seen[count]) && (allOptions[count].option_mandatory))
997 { 997 {
998 FPRINTF (stderr, 998 fprintf (stderr,
999 _ ("Missing mandatory option `%s'.\n"), 999 _ ("Missing mandatory option `%s'.\n"),
1000 allOptions[count].name); 1000 allOptions[count].name);
1001 cont = GNUNET_SYSERR; 1001 cont = GNUNET_SYSERR;
diff --git a/src/util/getopt_helpers.c b/src/util/getopt_helpers.c
index 80d1037bb..f53441508 100644
--- a/src/util/getopt_helpers.c
+++ b/src/util/getopt_helpers.c
@@ -184,7 +184,7 @@ format_help (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
184 184
185 if (0 != pd->is_gnu) 185 if (0 != pd->is_gnu)
186 printf ("General help using GNU software: http://www.gnu.org/gethelp/\n"); 186 printf ("General help using GNU software: http://www.gnu.org/gethelp/\n");
187 187
188 return GNUNET_NO; 188 return GNUNET_NO;
189} 189}
190 190
@@ -544,9 +544,9 @@ set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
544 char dummy[2]; 544 char dummy[2];
545 545
546 (void) ctx; 546 (void) ctx;
547 if (1 != SSCANF (value, "%llu%1s", val, dummy)) 547 if (1 != sscanf (value, "%llu%1s", val, dummy))
548 { 548 {
549 FPRINTF (stderr, 549 fprintf (stderr,
550 _ ("You must pass a number to the `%s' option.\n"), 550 _ ("You must pass a number to the `%s' option.\n"),
551 option); 551 option);
552 return GNUNET_SYSERR; 552 return GNUNET_SYSERR;
@@ -607,7 +607,7 @@ set_relative_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
607 (void) ctx; 607 (void) ctx;
608 if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (value, val)) 608 if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (value, val))
609 { 609 {
610 FPRINTF (stderr, 610 fprintf (stderr,
611 _ ("You must pass relative time to the `%s' option.\n"), 611 _ ("You must pass relative time to the `%s' option.\n"),
612 option); 612 option);
613 return GNUNET_SYSERR; 613 return GNUNET_SYSERR;
@@ -669,7 +669,7 @@ set_absolute_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
669 (void) ctx; 669 (void) ctx;
670 if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_absolute (value, val)) 670 if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_absolute (value, val))
671 { 671 {
672 FPRINTF (stderr, 672 fprintf (stderr,
673 _ ("You must pass absolute time to the `%s' option.\n"), 673 _ ("You must pass absolute time to the `%s' option.\n"),
674 option); 674 option);
675 return GNUNET_SYSERR; 675 return GNUNET_SYSERR;
@@ -732,15 +732,15 @@ set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
732 (void) ctx; 732 (void) ctx;
733 if ('-' == *value) 733 if ('-' == *value)
734 { 734 {
735 FPRINTF (stderr, 735 fprintf (stderr,
736 _ ( 736 _ (
737 "Your input for the '%s' option has to be a non negative number \n"), 737 "Your input for the '%s' option has to be a non negative number \n"),
738 option); 738 option);
739 return GNUNET_SYSERR; 739 return GNUNET_SYSERR;
740 } 740 }
741 if (1 != SSCANF (value, "%u%1s", val, dummy)) 741 if (1 != sscanf (value, "%u%1s", val, dummy))
742 { 742 {
743 FPRINTF (stderr, 743 fprintf (stderr,
744 _ ("You must pass a number to the `%s' option.\n"), 744 _ ("You must pass a number to the `%s' option.\n"),
745 option); 745 option);
746 return GNUNET_SYSERR; 746 return GNUNET_SYSERR;
@@ -801,16 +801,16 @@ set_uint16 (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
801 char dummy[2]; 801 char dummy[2];
802 802
803 (void) ctx; 803 (void) ctx;
804 if (1 != SSCANF (value, "%u%1s", &v, dummy)) 804 if (1 != sscanf (value, "%u%1s", &v, dummy))
805 { 805 {
806 FPRINTF (stderr, 806 fprintf (stderr,
807 _ ("You must pass a number to the `%s' option.\n"), 807 _ ("You must pass a number to the `%s' option.\n"),
808 option); 808 option);
809 return GNUNET_SYSERR; 809 return GNUNET_SYSERR;
810 } 810 }
811 if (v > UINT16_MAX) 811 if (v > UINT16_MAX)
812 { 812 {
813 FPRINTF (stderr, 813 fprintf (stderr,
814 _ ("You must pass a number below %u to the `%s' option.\n"), 814 _ ("You must pass a number below %u to the `%s' option.\n"),
815 (unsigned int) UINT16_MAX, 815 (unsigned int) UINT16_MAX,
816 option); 816 option);
diff --git a/src/util/gnunet-ecc.c b/src/util/gnunet-ecc.c
index d2253337c..e7a170b81 100644
--- a/src/util/gnunet-ecc.c
+++ b/src/util/gnunet-ecc.c
@@ -31,7 +31,7 @@
31/** 31/**
32 * Number of characters a Base32-encoded public key requires. 32 * Number of characters a Base32-encoded public key requires.
33 */ 33 */
34#define KEY_STR_LEN sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)*8/5+1 34#define KEY_STR_LEN sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) * 8 / 5 + 1
35 35
36/** 36/**
37 * Flag for listing public key. 37 * Flag for listing public key.
@@ -91,7 +91,7 @@ create_keys (const char *fn, const char *prefix)
91 91
92 if (NULL == (f = fopen (fn, "w+"))) 92 if (NULL == (f = fopen (fn, "w+")))
93 { 93 {
94 fprintf (stderr, _("Failed to open `%s': %s\n"), fn, STRERROR (errno)); 94 fprintf (stderr, _ ("Failed to open `%s': %s\n"), fn, strerror (errno));
95 return; 95 return;
96 } 96 }
97 if (NULL != prefix) 97 if (NULL != prefix)
@@ -116,7 +116,7 @@ create_keys (const char *fn, const char *prefix)
116 * rest = 5%8 = 5 (bits) 116 * rest = 5%8 = 5 (bits)
117 * mask = ~(2**(8 - 5) - 1) = ~(2**3 - 1) = ~(8 - 1) = ~b111 = b11111000 117 * mask = ~(2**(8 - 5) - 1) = ~(2**3 - 1) = ~(8 - 1) = ~b111 = b11111000
118 */ 118 */
119 mask = ~ ((int)pow (2, 8 - rest) - 1); 119 mask = ~((int) pow (2, 8 - rest) - 1);
120 target_byte = ((unsigned char *) &target_pub)[n] & mask; 120 target_byte = ((unsigned char *) &target_pub)[n] & mask;
121 } 121 }
122 else 122 else
@@ -126,21 +126,15 @@ create_keys (const char *fn, const char *prefix)
126 } 126 }
127 s = GNUNET_CRYPTO_eddsa_public_key_to_string (&target_pub); 127 s = GNUNET_CRYPTO_eddsa_public_key_to_string (&target_pub);
128 fprintf (stderr, 128 fprintf (stderr,
129 _("Generating %u keys like %s, please wait"), 129 _ ("Generating %u keys like %s, please wait"),
130 make_keys, 130 make_keys,
131 s); 131 s);
132 GNUNET_free (s); 132 GNUNET_free (s);
133 fprintf (stderr, 133 fprintf (stderr, "\nattempt %s [%u, %X]\n", vanity, (unsigned int) n, mask);
134 "\nattempt %s [%u, %X]\n",
135 vanity,
136 (unsigned int) n,
137 mask);
138 } 134 }
139 else 135 else
140 { 136 {
141 fprintf (stderr, 137 fprintf (stderr, _ ("Generating %u keys, please wait"), make_keys);
142 _("Generating %u keys, please wait"),
143 make_keys);
144 /* Just so old (debian) versions of GCC calm down with the warnings. */ 138 /* Just so old (debian) versions of GCC calm down with the warnings. */
145 n = rest = target_byte = mask = 0; 139 n = rest = target_byte = mask = 0;
146 } 140 }
@@ -150,8 +144,8 @@ create_keys (const char *fn, const char *prefix)
150 fprintf (stderr, "."); 144 fprintf (stderr, ".");
151 if (NULL == (pk = GNUNET_CRYPTO_eddsa_key_create ())) 145 if (NULL == (pk = GNUNET_CRYPTO_eddsa_key_create ()))
152 { 146 {
153 GNUNET_break (0); 147 GNUNET_break (0);
154 break; 148 break;
155 } 149 }
156 if (NULL != prefix) 150 if (NULL != prefix)
157 { 151 {
@@ -176,38 +170,32 @@ create_keys (const char *fn, const char *prefix)
176 } 170 }
177 } 171 }
178 if (GNUNET_TESTING_HOSTKEYFILESIZE != 172 if (GNUNET_TESTING_HOSTKEYFILESIZE !=
179 fwrite (pk, 1, 173 fwrite (pk, 1, GNUNET_TESTING_HOSTKEYFILESIZE, f))
180 GNUNET_TESTING_HOSTKEYFILESIZE, f))
181 { 174 {
182 fprintf (stderr, 175 fprintf (stderr,
183 _("\nFailed to write to `%s': %s\n"), 176 _ ("\nFailed to write to `%s': %s\n"),
184 fn, 177 fn,
185 STRERROR (errno)); 178 strerror (errno));
186 GNUNET_free (pk); 179 GNUNET_free (pk);
187 break; 180 break;
188 } 181 }
189 GNUNET_free (pk); 182 GNUNET_free (pk);
190 } 183 }
191 if (UINT_MAX == make_keys) 184 if (UINT_MAX == make_keys)
192 fprintf (stderr, 185 fprintf (stderr, _ ("\nFinished!\n"));
193 _("\nFinished!\n"));
194 else 186 else
195 fprintf (stderr, 187 fprintf (stderr, _ ("\nError, %u keys not generated\n"), make_keys);
196 _("\nError, %u keys not generated\n"),
197 make_keys);
198 fclose (f); 188 fclose (f);
199} 189}
200 190
201 191
202static void 192static void
203print_hex (const char *msg, 193print_hex (const char *msg, const void *buf, size_t size)
204 const void *buf,
205 size_t size)
206{ 194{
207 printf ("%s: ", msg); 195 printf ("%s: ", msg);
208 for (size_t i = 0; i < size; i++) 196 for (size_t i = 0; i < size; i++)
209 { 197 {
210 printf ("%02hhx", ((const uint8_t *)buf)[i]); 198 printf ("%02hhx", ((const uint8_t *) buf)[i]);
211 } 199 }
212 printf ("\n"); 200 printf ("\n");
213} 201}
@@ -230,7 +218,8 @@ print_examples_ecdh ()
230 GNUNET_CRYPTO_ecdhe_key_get_public (dh_priv1, dh_pub1); 218 GNUNET_CRYPTO_ecdhe_key_get_public (dh_priv1, dh_pub1);
231 GNUNET_CRYPTO_ecdhe_key_get_public (dh_priv2, dh_pub2); 219 GNUNET_CRYPTO_ecdhe_key_get_public (dh_priv2, dh_pub2);
232 220
233 GNUNET_assert (NULL != GNUNET_STRINGS_data_to_string (dh_priv1, 32, buf, 128)); 221 GNUNET_assert (NULL !=
222 GNUNET_STRINGS_data_to_string (dh_priv1, 32, buf, 128));
234 printf ("ECDHE key 1:\n"); 223 printf ("ECDHE key 1:\n");
235 printf ("private: %s\n", buf); 224 printf ("private: %s\n", buf);
236 print_hex ("private(hex)", dh_priv1, sizeof *dh_priv1); 225 print_hex ("private(hex)", dh_priv1, sizeof *dh_priv1);
@@ -238,7 +227,8 @@ print_examples_ecdh ()
238 printf ("public: %s\n", buf); 227 printf ("public: %s\n", buf);
239 print_hex ("public(hex)", dh_pub1, sizeof *dh_pub1); 228 print_hex ("public(hex)", dh_pub1, sizeof *dh_pub1);
240 229
241 GNUNET_assert (NULL != GNUNET_STRINGS_data_to_string (dh_priv2, 32, buf, 128)); 230 GNUNET_assert (NULL !=
231 GNUNET_STRINGS_data_to_string (dh_priv2, 32, buf, 128));
242 printf ("ECDHE key 2:\n"); 232 printf ("ECDHE key 2:\n");
243 printf ("private: %s\n", buf); 233 printf ("private: %s\n", buf);
244 print_hex ("private(hex)", dh_priv2, sizeof *dh_priv2); 234 print_hex ("private(hex)", dh_priv2, sizeof *dh_priv2);
@@ -246,7 +236,8 @@ print_examples_ecdh ()
246 printf ("public: %s\n", buf); 236 printf ("public: %s\n", buf);
247 print_hex ("public(hex)", dh_pub2, sizeof *dh_pub2); 237 print_hex ("public(hex)", dh_pub2, sizeof *dh_pub2);
248 238
249 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecc_ecdh (dh_priv1, dh_pub2, &hash)); 239 GNUNET_assert (GNUNET_OK ==
240 GNUNET_CRYPTO_ecc_ecdh (dh_priv1, dh_pub2, &hash));
250 GNUNET_assert (NULL != GNUNET_STRINGS_data_to_string (&hash, 64, buf, 128)); 241 GNUNET_assert (NULL != GNUNET_STRINGS_data_to_string (&hash, 64, buf, 128));
251 printf ("ECDH shared secret: %s\n", buf); 242 printf ("ECDH shared secret: %s\n", buf);
252 243
@@ -282,56 +273,39 @@ print_key (const char *filename)
282 unsigned int c; 273 unsigned int c;
283 ssize_t sret; 274 ssize_t sret;
284 275
285 if (GNUNET_YES != 276 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
286 GNUNET_DISK_file_test (filename))
287 { 277 {
288 fprintf (stderr, 278 fprintf (stderr, _ ("Hostkeys file `%s' not found\n"), filename);
289 _("Hostkeys file `%s' not found\n"),
290 filename);
291 return; 279 return;
292 } 280 }
293 281
294 /* Check hostkey file size, read entire thing into memory */ 282 /* Check hostkey file size, read entire thing into memory */
295 if (GNUNET_OK != 283 if (GNUNET_OK !=
296 GNUNET_DISK_file_size (filename, 284 GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
297 &fs,
298 GNUNET_YES,
299 GNUNET_YES))
300 fs = 0; 285 fs = 0;
301 if (0 == fs) 286 if (0 == fs)
302 { 287 {
303 fprintf (stderr, 288 fprintf (stderr, _ ("Hostkeys file `%s' is empty\n"), filename);
304 _("Hostkeys file `%s' is empty\n"), 289 return; /* File is empty */
305 filename);
306 return; /* File is empty */
307 } 290 }
308 if (0 != (fs % GNUNET_TESTING_HOSTKEYFILESIZE)) 291 if (0 != (fs % GNUNET_TESTING_HOSTKEYFILESIZE))
309 { 292 {
310 fprintf (stderr, 293 fprintf (stderr, _ ("Incorrect hostkey file format: %s\n"), filename);
311 _("Incorrect hostkey file format: %s\n"),
312 filename);
313 return; 294 return;
314 } 295 }
315 fd = GNUNET_DISK_file_open (filename, 296 fd = GNUNET_DISK_file_open (filename,
316 GNUNET_DISK_OPEN_READ, 297 GNUNET_DISK_OPEN_READ,
317 GNUNET_DISK_PERM_NONE); 298 GNUNET_DISK_PERM_NONE);
318 if (NULL == fd) 299 if (NULL == fd)
319 { 300 {
320 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 301 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename);
321 "open",
322 filename);
323 return; 302 return;
324 } 303 }
325 hostkeys_data = GNUNET_malloc (fs); 304 hostkeys_data = GNUNET_malloc (fs);
326 sret = GNUNET_DISK_file_read (fd, 305 sret = GNUNET_DISK_file_read (fd, hostkeys_data, fs);
327 hostkeys_data, 306 if ((sret < 0) || (fs != (size_t) sret))
328 fs);
329 if ( (sret < 0) ||
330 (fs != (size_t) sret) )
331 { 307 {
332 fprintf (stderr, 308 fprintf (stderr, _ ("Could not read hostkey file: %s\n"), filename);
333 _("Could not read hostkey file: %s\n"),
334 filename);
335 GNUNET_free (hostkeys_data); 309 GNUNET_free (hostkeys_data);
336 GNUNET_DISK_file_close (fd); 310 GNUNET_DISK_file_close (fd);
337 return; 311 return;
@@ -344,8 +318,8 @@ print_key (const char *filename)
344 for (c = 0; (c < total_hostkeys) && (c < list_keys_count); c++) 318 for (c = 0; (c < total_hostkeys) && (c < list_keys_count); c++)
345 { 319 {
346 GNUNET_memcpy (&private_key, 320 GNUNET_memcpy (&private_key,
347 hostkeys_data + (c * GNUNET_TESTING_HOSTKEYFILESIZE), 321 hostkeys_data + (c * GNUNET_TESTING_HOSTKEYFILESIZE),
348 GNUNET_TESTING_HOSTKEYFILESIZE); 322 GNUNET_TESTING_HOSTKEYFILESIZE);
349 GNUNET_CRYPTO_eddsa_key_get_public (&private_key, &public_key); 323 GNUNET_CRYPTO_eddsa_key_get_public (&private_key, &public_key);
350 hostkey_str = GNUNET_CRYPTO_eddsa_public_key_to_string (&public_key); 324 hostkey_str = GNUNET_CRYPTO_eddsa_public_key_to_string (&public_key);
351 if (NULL != hostkey_str) 325 if (NULL != hostkey_str)
@@ -377,7 +351,7 @@ run (void *cls,
377 (void) cls; 351 (void) cls;
378 (void) cfgfile; 352 (void) cfgfile;
379 (void) cfg; 353 (void) cfg;
380 354
381 if (print_examples_flag) 355 if (print_examples_flag)
382 { 356 {
383 print_examples (); 357 print_examples ();
@@ -385,9 +359,7 @@ run (void *cls,
385 } 359 }
386 if (NULL == args[0]) 360 if (NULL == args[0])
387 { 361 {
388 FPRINTF (stderr, 362 fprintf (stderr, "%s", _ ("No hostkey file specified on command line\n"));
389 "%s",
390 _("No hostkey file specified on command line\n"));
391 return; 363 return;
392 } 364 }
393 if (list_keys) 365 if (list_keys)
@@ -407,12 +379,12 @@ run (void *cls,
407 struct GNUNET_CRYPTO_EddsaPrivateKey pk; 379 struct GNUNET_CRYPTO_EddsaPrivateKey pk;
408 struct GNUNET_CRYPTO_EddsaPublicKey pub; 380 struct GNUNET_CRYPTO_EddsaPublicKey pub;
409 381
410 keyfile = GNUNET_DISK_file_open (args[0], GNUNET_DISK_OPEN_READ, 382 keyfile = GNUNET_DISK_file_open (args[0],
383 GNUNET_DISK_OPEN_READ,
411 GNUNET_DISK_PERM_NONE); 384 GNUNET_DISK_PERM_NONE);
412 if (NULL == keyfile) 385 if (NULL == keyfile)
413 return; 386 return;
414 while (sizeof (pk) == 387 while (sizeof (pk) == GNUNET_DISK_file_read (keyfile, &pk, sizeof (pk)))
415 GNUNET_DISK_file_read (keyfile, &pk, sizeof (pk)))
416 { 388 {
417 GNUNET_CRYPTO_eddsa_key_get_public (&pk, &pub); 389 GNUNET_CRYPTO_eddsa_key_get_public (&pk, &pub);
418 if (print_public_key_hex) 390 if (print_public_key_hex)
@@ -422,19 +394,18 @@ run (void *cls,
422 else if (print_public_key) 394 else if (print_public_key)
423 { 395 {
424 str = GNUNET_CRYPTO_eddsa_public_key_to_string (&pub); 396 str = GNUNET_CRYPTO_eddsa_public_key_to_string (&pub);
425 FPRINTF (stdout, "%s\n", str); 397 fprintf (stdout, "%s\n", str);
426 GNUNET_free (str); 398 GNUNET_free (str);
427 } 399 }
428 else if (print_private_key) 400 else if (print_private_key)
429 { 401 {
430 str = GNUNET_CRYPTO_eddsa_private_key_to_string (&pk); 402 str = GNUNET_CRYPTO_eddsa_private_key_to_string (&pk);
431 FPRINTF (stdout, "%s\n", str); 403 fprintf (stdout, "%s\n", str);
432 GNUNET_free (str); 404 GNUNET_free (str);
433 } 405 }
434 } 406 }
435 GNUNET_DISK_file_close (keyfile); 407 GNUNET_DISK_file_close (keyfile);
436 } 408 }
437
438} 409}
439 410
440 411
@@ -446,59 +417,66 @@ run (void *cls,
446 * @return 0 ok, 1 on error 417 * @return 0 ok, 1 on error
447 */ 418 */
448int 419int
449main (int argc, 420main (int argc, char *const *argv)
450 char *const *argv)
451{ 421{
452 struct GNUNET_GETOPT_CommandLineOption options[] = { 422 struct GNUNET_GETOPT_CommandLineOption options[] =
453 GNUNET_GETOPT_option_flag ('i', 423 {GNUNET_GETOPT_option_flag ('i',
454 "iterate", 424 "iterate",
455 gettext_noop ("list keys included in a file (for testing)"), 425 gettext_noop (
456 &list_keys), 426 "list keys included in a file (for testing)"),
457 GNUNET_GETOPT_option_uint ('e', 427 &list_keys),
458 "end=", 428 GNUNET_GETOPT_option_uint (
459 "COUNT", 429 'e',
460 gettext_noop ("number of keys to list included in a file (for testing)"), 430 "end=",
461 &list_keys_count), 431 "COUNT",
462 GNUNET_GETOPT_option_uint ('g', 432 gettext_noop ("number of keys to list included in a file (for testing)"),
463 "generate-keys", 433 &list_keys_count),
464 "COUNT", 434 GNUNET_GETOPT_option_uint (
465 gettext_noop ("create COUNT public-private key pairs (for testing)"), 435 'g',
466 &make_keys), 436 "generate-keys",
467 GNUNET_GETOPT_option_flag ('p', 437 "COUNT",
468 "print-public-key", 438 gettext_noop ("create COUNT public-private key pairs (for testing)"),
469 gettext_noop ("print the public key in ASCII format"), 439 &make_keys),
470 &print_public_key), 440 GNUNET_GETOPT_option_flag ('p',
471 GNUNET_GETOPT_option_flag ('P', 441 "print-public-key",
472 "print-private-key", 442 gettext_noop (
473 gettext_noop ("print the private key in ASCII format"), 443 "print the public key in ASCII format"),
474 &print_private_key), 444 &print_public_key),
475 GNUNET_GETOPT_option_flag ('x', 445 GNUNET_GETOPT_option_flag ('P',
476 "print-hex", 446 "print-private-key",
477 gettext_noop ("print the public key in HEX format"), 447 gettext_noop (
478 &print_public_key_hex), 448 "print the private key in ASCII format"),
479 GNUNET_GETOPT_option_flag ('E', 449 &print_private_key),
480 "examples", 450 GNUNET_GETOPT_option_flag ('x',
481 gettext_noop ("print examples of ECC operations (used for compatibility testing)"), 451 "print-hex",
482 &print_examples_flag), 452 gettext_noop (
483 GNUNET_GETOPT_OPTION_END 453 "print the public key in HEX format"),
484 }; 454 &print_public_key_hex),
455 GNUNET_GETOPT_option_flag (
456 'E',
457 "examples",
458 gettext_noop (
459 "print examples of ECC operations (used for compatibility testing)"),
460 &print_examples_flag),
461 GNUNET_GETOPT_OPTION_END};
485 int ret; 462 int ret;
486 463
487 list_keys_count = UINT32_MAX; 464 list_keys_count = UINT32_MAX;
488 if (GNUNET_OK != 465 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
489 GNUNET_STRINGS_get_utf8_args (argc, argv,
490 &argc, &argv))
491 return 2; 466 return 2;
492 467
493 ret = (GNUNET_OK == 468 ret = (GNUNET_OK ==
494 GNUNET_PROGRAM_run (argc, 469 GNUNET_PROGRAM_run (argc,
495 argv, 470 argv,
496 "gnunet-ecc [OPTIONS] keyfile [VANITY_PREFIX]", 471 "gnunet-ecc [OPTIONS] keyfile [VANITY_PREFIX]",
497 gettext_noop ("Manipulate GNUnet private ECC key files"), 472 gettext_noop (
498 options, 473 "Manipulate GNUnet private ECC key files"),
474 options,
499 &run, 475 &run,
500 NULL)) ? 0 : 1; 476 NULL))
501 GNUNET_free ((void*) argv); 477 ? 0
478 : 1;
479 GNUNET_free ((void *) argv);
502 return ret; 480 return ret;
503} 481}
504 482
diff --git a/src/util/gnunet-resolver.c b/src/util/gnunet-resolver.c
index e5d58b4b6..3aba5fb1e 100644
--- a/src/util/gnunet-resolver.c
+++ b/src/util/gnunet-resolver.c
@@ -49,7 +49,7 @@ print_hostname (void *cls,
49 (void) cls; 49 (void) cls;
50 if (NULL == hostname) 50 if (NULL == hostname)
51 return; 51 return;
52 FPRINTF (stdout, 52 fprintf (stdout,
53 "%s\n", 53 "%s\n",
54 hostname); 54 hostname);
55} 55}
@@ -70,7 +70,7 @@ print_sockaddr (void *cls,
70 (void) cls; 70 (void) cls;
71 if (NULL == addr) 71 if (NULL == addr)
72 return; 72 return;
73 FPRINTF (stdout, 73 fprintf (stdout,
74 "%s\n", 74 "%s\n",
75 GNUNET_a2s (addr, 75 GNUNET_a2s (addr,
76 addrlen)); 76 addrlen));
diff --git a/src/util/gnunet-scrypt.c b/src/util/gnunet-scrypt.c
index f4149a398..6f9690c99 100644
--- a/src/util/gnunet-scrypt.c
+++ b/src/util/gnunet-scrypt.c
@@ -144,7 +144,7 @@ find_proof (void *cls)
144 if (nse_work_required <= count_leading_zeroes (&result)) 144 if (nse_work_required <= count_leading_zeroes (&result))
145 { 145 {
146 proof = counter; 146 proof = counter;
147 FPRINTF (stdout, 147 fprintf (stdout,
148 "Proof of work found: %llu!\n", 148 "Proof of work found: %llu!\n",
149 (unsigned long long) proof); 149 (unsigned long long) proof);
150 GNUNET_SCHEDULER_shutdown (); 150 GNUNET_SCHEDULER_shutdown ();
@@ -236,7 +236,7 @@ run (void *cls,
236 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Private Key file: %s\n", pkfn); 236 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Private Key file: %s\n", pkfn);
237 if (NULL == (pk = GNUNET_CRYPTO_eddsa_key_create_from_file (pkfn))) 237 if (NULL == (pk = GNUNET_CRYPTO_eddsa_key_create_from_file (pkfn)))
238 { 238 {
239 FPRINTF (stderr, _ ("Loading hostkey from `%s' failed.\n"), pkfn); 239 fprintf (stderr, _ ("Loading hostkey from `%s' failed.\n"), pkfn);
240 GNUNET_free (pkfn); 240 GNUNET_free (pkfn);
241 return; 241 return;
242 } 242 }
diff --git a/src/util/helper.c b/src/util/helper.c
index 7eb2ce6d9..aa452d22b 100644
--- a/src/util/helper.c
+++ b/src/util/helper.c
@@ -70,7 +70,6 @@ struct GNUNET_HELPER_SendHandle
70 * Current write position. 70 * Current write position.
71 */ 71 */
72 unsigned int wpos; 72 unsigned int wpos;
73
74}; 73};
75 74
76 75
@@ -177,17 +176,14 @@ struct GNUNET_HELPER_Handle
177 * @return #GNUNET_OK on success; #GNUNET_SYSERR on error 176 * @return #GNUNET_OK on success; #GNUNET_SYSERR on error
178 */ 177 */
179int 178int
180GNUNET_HELPER_kill (struct GNUNET_HELPER_Handle *h, 179GNUNET_HELPER_kill (struct GNUNET_HELPER_Handle *h, int soft_kill)
181 int soft_kill)
182{ 180{
183 struct GNUNET_HELPER_SendHandle *sh; 181 struct GNUNET_HELPER_SendHandle *sh;
184 int ret; 182 int ret;
185 183
186 while (NULL != (sh = h->sh_head)) 184 while (NULL != (sh = h->sh_head))
187 { 185 {
188 GNUNET_CONTAINER_DLL_remove (h->sh_head, 186 GNUNET_CONTAINER_DLL_remove (h->sh_head, h->sh_tail, sh);
189 h->sh_tail,
190 sh);
191 if (NULL != sh->cont) 187 if (NULL != sh->cont)
192 sh->cont (sh->cont_cls, GNUNET_NO); 188 sh->cont (sh->cont_cls, GNUNET_NO);
193 GNUNET_free (sh); 189 GNUNET_free (sh);
@@ -264,19 +260,14 @@ GNUNET_HELPER_wait (struct GNUNET_HELPER_Handle *h)
264 } 260 }
265 while (NULL != (sh = h->sh_head)) 261 while (NULL != (sh = h->sh_head))
266 { 262 {
267 GNUNET_CONTAINER_DLL_remove (h->sh_head, 263 GNUNET_CONTAINER_DLL_remove (h->sh_head, h->sh_tail, sh);
268 h->sh_tail,
269 sh);
270 if (NULL != sh->cont) 264 if (NULL != sh->cont)
271 sh->cont (sh->cont_cls, GNUNET_NO); 265 sh->cont (sh->cont_cls, GNUNET_NO);
272 GNUNET_free (sh); 266 GNUNET_free (sh);
273 } 267 }
274 /* purge MST buffer */ 268 /* purge MST buffer */
275 if (NULL != h->mst) 269 if (NULL != h->mst)
276 (void) GNUNET_MST_from_buffer (h->mst, 270 (void) GNUNET_MST_from_buffer (h->mst, NULL, 0, GNUNET_YES, GNUNET_NO);
277 NULL, 0,
278 GNUNET_YES,
279 GNUNET_NO);
280 return ret; 271 return ret;
281} 272}
282 273
@@ -289,8 +280,7 @@ GNUNET_HELPER_wait (struct GNUNET_HELPER_Handle *h)
289 * stdin; #GNUNET_NO to signal termination by sending SIGTERM to helper 280 * stdin; #GNUNET_NO to signal termination by sending SIGTERM to helper
290 */ 281 */
291static void 282static void
292stop_helper (struct GNUNET_HELPER_Handle *h, 283stop_helper (struct GNUNET_HELPER_Handle *h, int soft_kill)
293 int soft_kill)
294{ 284{
295 if (NULL != h->restart_task) 285 if (NULL != h->restart_task)
296 { 286 {
@@ -332,9 +322,9 @@ helper_read (void *cls)
332 { 322 {
333 /* On read-error, restart the helper */ 323 /* On read-error, restart the helper */
334 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 324 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
335 _("Error reading from `%s': %s\n"), 325 _ ("Error reading from `%s': %s\n"),
336 h->binary_name, 326 h->binary_name,
337 STRERROR (errno)); 327 strerror (errno));
338 if (NULL != h->exp_cb) 328 if (NULL != h->exp_cb)
339 { 329 {
340 h->exp_cb (h->cb_cls); 330 h->exp_cb (h->cb_cls);
@@ -343,9 +333,11 @@ helper_read (void *cls)
343 } 333 }
344 stop_helper (h, GNUNET_NO); 334 stop_helper (h, GNUNET_NO);
345 /* Restart the helper */ 335 /* Restart the helper */
346 h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 336 h->restart_task = GNUNET_SCHEDULER_add_delayed (
347 h->retry_back_off), 337 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
348 &restart_task, h); 338 h->retry_back_off),
339 &restart_task,
340 h);
349 return; 341 return;
350 } 342 }
351 if (0 == t) 343 if (0 == t)
@@ -353,8 +345,8 @@ helper_read (void *cls)
353 /* this happens if the helper is shut down via a 345 /* this happens if the helper is shut down via a
354 signal, so it is not a "hard" error */ 346 signal, so it is not a "hard" error */
355 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 347 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
356 "Got 0 bytes from helper `%s' (EOF)\n", 348 "Got 0 bytes from helper `%s' (EOF)\n",
357 h->binary_name); 349 h->binary_name);
358 if (NULL != h->exp_cb) 350 if (NULL != h->exp_cb)
359 { 351 {
360 h->exp_cb (h->cb_cls); 352 h->exp_cb (h->cb_cls);
@@ -363,28 +355,27 @@ helper_read (void *cls)
363 } 355 }
364 stop_helper (h, GNUNET_NO); 356 stop_helper (h, GNUNET_NO);
365 /* Restart the helper */ 357 /* Restart the helper */
366 h->restart_task 358 h->restart_task = GNUNET_SCHEDULER_add_delayed (
367 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 359 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
368 h->retry_back_off), 360 h->retry_back_off),
369 &restart_task, h); 361 &restart_task,
362 h);
370 return; 363 return;
371 } 364 }
372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 365 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
373 "Got %u bytes from helper `%s'\n", 366 "Got %u bytes from helper `%s'\n",
374 (unsigned int) t, 367 (unsigned int) t,
375 h->binary_name); 368 h->binary_name);
376 h->read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 369 h->read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
377 h->fh_from_helper, 370 h->fh_from_helper,
378 &helper_read, h); 371 &helper_read,
372 h);
379 if (GNUNET_SYSERR == 373 if (GNUNET_SYSERR ==
380 GNUNET_MST_from_buffer (h->mst, 374 GNUNET_MST_from_buffer (h->mst, buf, t, GNUNET_NO, GNUNET_NO))
381 buf, t,
382 GNUNET_NO,
383 GNUNET_NO))
384 { 375 {
385 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 376 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
386 _("Failed to parse inbound message from helper `%s'\n"), 377 _ ("Failed to parse inbound message from helper `%s'\n"),
387 h->binary_name); 378 h->binary_name);
388 if (NULL != h->exp_cb) 379 if (NULL != h->exp_cb)
389 { 380 {
390 h->exp_cb (h->cb_cls); 381 h->exp_cb (h->cb_cls);
@@ -393,9 +384,11 @@ helper_read (void *cls)
393 } 384 }
394 stop_helper (h, GNUNET_NO); 385 stop_helper (h, GNUNET_NO);
395 /* Restart the helper */ 386 /* Restart the helper */
396 h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 387 h->restart_task = GNUNET_SCHEDULER_add_delayed (
397 h->retry_back_off), 388 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
398 &restart_task, h); 389 h->retry_back_off),
390 &restart_task,
391 h);
399 return; 392 return;
400 } 393 }
401} 394}
@@ -409,46 +402,53 @@ helper_read (void *cls)
409static void 402static void
410start_helper (struct GNUNET_HELPER_Handle *h) 403start_helper (struct GNUNET_HELPER_Handle *h)
411{ 404{
412 h->helper_in = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO); 405 h->helper_in =
413 h->helper_out = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES); 406 GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO);
414 if ( (h->helper_in == NULL) || (h->helper_out == NULL)) 407 h->helper_out =
408 GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
409 if ((h->helper_in == NULL) || (h->helper_out == NULL))
415 { 410 {
416 /* out of file descriptors? try again later... */ 411 /* out of file descriptors? try again later... */
417 stop_helper (h, GNUNET_NO); 412 stop_helper (h, GNUNET_NO);
418 h->restart_task = 413 h->restart_task = GNUNET_SCHEDULER_add_delayed (
419 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 414 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
420 h->retry_back_off), 415 h->retry_back_off),
421 &restart_task, h); 416 &restart_task,
417 h);
422 return; 418 return;
423 } 419 }
424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
425 "Starting HELPER process `%s'\n", 421 "Starting HELPER process `%s'\n",
426 h->binary_name); 422 h->binary_name);
427 h->fh_from_helper = 423 h->fh_from_helper =
428 GNUNET_DISK_pipe_handle (h->helper_out, GNUNET_DISK_PIPE_END_READ); 424 GNUNET_DISK_pipe_handle (h->helper_out, GNUNET_DISK_PIPE_END_READ);
429 h->fh_to_helper = 425 h->fh_to_helper =
430 GNUNET_DISK_pipe_handle (h->helper_in, GNUNET_DISK_PIPE_END_WRITE); 426 GNUNET_DISK_pipe_handle (h->helper_in, GNUNET_DISK_PIPE_END_WRITE);
431 h->helper_proc = 427 h->helper_proc = GNUNET_OS_start_process_vap (h->with_control_pipe,
432 GNUNET_OS_start_process_vap (h->with_control_pipe, GNUNET_OS_INHERIT_STD_ERR, 428 GNUNET_OS_INHERIT_STD_ERR,
433 h->helper_in, h->helper_out, NULL, 429 h->helper_in,
434 h->binary_name, 430 h->helper_out,
435 h->binary_argv); 431 NULL,
432 h->binary_name,
433 h->binary_argv);
436 if (NULL == h->helper_proc) 434 if (NULL == h->helper_proc)
437 { 435 {
438 /* failed to start process? try again later... */ 436 /* failed to start process? try again later... */
439 stop_helper (h, GNUNET_NO); 437 stop_helper (h, GNUNET_NO);
440 h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 438 h->restart_task = GNUNET_SCHEDULER_add_delayed (
441 h->retry_back_off), 439 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
442 &restart_task, h); 440 h->retry_back_off),
441 &restart_task,
442 h);
443 return; 443 return;
444 } 444 }
445 GNUNET_DISK_pipe_close_end (h->helper_out, GNUNET_DISK_PIPE_END_WRITE); 445 GNUNET_DISK_pipe_close_end (h->helper_out, GNUNET_DISK_PIPE_END_WRITE);
446 GNUNET_DISK_pipe_close_end (h->helper_in, GNUNET_DISK_PIPE_END_READ); 446 GNUNET_DISK_pipe_close_end (h->helper_in, GNUNET_DISK_PIPE_END_READ);
447 if (NULL != h->mst) 447 if (NULL != h->mst)
448 h->read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 448 h->read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
449 h->fh_from_helper, 449 h->fh_from_helper,
450 &helper_read, 450 &helper_read,
451 h); 451 h);
452} 452}
453 453
454 454
@@ -460,7 +460,7 @@ start_helper (struct GNUNET_HELPER_Handle *h)
460static void 460static void
461restart_task (void *cls) 461restart_task (void *cls)
462{ 462{
463 struct GNUNET_HELPER_Handle*h = cls; 463 struct GNUNET_HELPER_Handle *h = cls;
464 464
465 h->restart_task = NULL; 465 h->restart_task = NULL;
466 h->retry_back_off++; 466 h->retry_back_off++;
@@ -489,11 +489,11 @@ restart_task (void *cls)
489 */ 489 */
490struct GNUNET_HELPER_Handle * 490struct GNUNET_HELPER_Handle *
491GNUNET_HELPER_start (int with_control_pipe, 491GNUNET_HELPER_start (int with_control_pipe,
492 const char *binary_name, 492 const char *binary_name,
493 char *const binary_argv[], 493 char *const binary_argv[],
494 GNUNET_MessageTokenizerCallback cb, 494 GNUNET_MessageTokenizerCallback cb,
495 GNUNET_HELPER_ExceptionCallback exp_cb, 495 GNUNET_HELPER_ExceptionCallback exp_cb,
496 void *cb_cls) 496 void *cb_cls)
497{ 497{
498 struct GNUNET_HELPER_Handle *h; 498 struct GNUNET_HELPER_Handle *h;
499 unsigned int c; 499 unsigned int c;
@@ -505,15 +505,15 @@ GNUNET_HELPER_start (int with_control_pipe,
505 h->binary_name = GNUNET_OS_get_libexec_binary_path (binary_name); 505 h->binary_name = GNUNET_OS_get_libexec_binary_path (binary_name);
506 else 506 else
507 h->binary_name = GNUNET_strdup (binary_name); 507 h->binary_name = GNUNET_strdup (binary_name);
508 for (c = 0; NULL != binary_argv[c]; c++); 508 for (c = 0; NULL != binary_argv[c]; c++)
509 ;
509 h->binary_argv = GNUNET_malloc (sizeof (char *) * (c + 1)); 510 h->binary_argv = GNUNET_malloc (sizeof (char *) * (c + 1));
510 for (c = 0; NULL != binary_argv[c]; c++) 511 for (c = 0; NULL != binary_argv[c]; c++)
511 h->binary_argv[c] = GNUNET_strdup (binary_argv[c]); 512 h->binary_argv[c] = GNUNET_strdup (binary_argv[c]);
512 h->binary_argv[c] = NULL; 513 h->binary_argv[c] = NULL;
513 h->cb_cls = cb_cls; 514 h->cb_cls = cb_cls;
514 if (NULL != cb) 515 if (NULL != cb)
515 h->mst = GNUNET_MST_create (cb, 516 h->mst = GNUNET_MST_create (cb, h->cb_cls);
516 h->cb_cls);
517 h->exp_cb = exp_cb; 517 h->exp_cb = exp_cb;
518 h->retry_back_off = 0; 518 h->retry_back_off = 0;
519 start_helper (h); 519 start_helper (h);
@@ -541,9 +541,7 @@ GNUNET_HELPER_destroy (struct GNUNET_HELPER_Handle *h)
541 GNUNET_assert (NULL == h->restart_task); 541 GNUNET_assert (NULL == h->restart_task);
542 while (NULL != (sh = h->sh_head)) 542 while (NULL != (sh = h->sh_head))
543 { 543 {
544 GNUNET_CONTAINER_DLL_remove (h->sh_head, 544 GNUNET_CONTAINER_DLL_remove (h->sh_head, h->sh_tail, sh);
545 h->sh_tail,
546 sh);
547 if (NULL != sh->cont) 545 if (NULL != sh->cont)
548 sh->cont (sh->cont_cls, GNUNET_SYSERR); 546 sh->cont (sh->cont_cls, GNUNET_SYSERR);
549 GNUNET_free (sh); 547 GNUNET_free (sh);
@@ -566,8 +564,7 @@ GNUNET_HELPER_destroy (struct GNUNET_HELPER_Handle *h)
566 * stdin; #GNUNET_NO to signal termination by sending SIGTERM to helper 564 * stdin; #GNUNET_NO to signal termination by sending SIGTERM to helper
567 */ 565 */
568void 566void
569GNUNET_HELPER_stop (struct GNUNET_HELPER_Handle *h, 567GNUNET_HELPER_stop (struct GNUNET_HELPER_Handle *h, int soft_kill)
570 int soft_kill)
571{ 568{
572 h->exp_cb = NULL; 569 h->exp_cb = NULL;
573 stop_helper (h, soft_kill); 570 stop_helper (h, soft_kill);
@@ -591,21 +588,20 @@ helper_write (void *cls)
591 h->write_task = NULL; 588 h->write_task = NULL;
592 if (NULL == (sh = h->sh_head)) 589 if (NULL == (sh = h->sh_head))
593 { 590 {
594 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 591 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Helper write had no work!\n");
595 "Helper write had no work!\n");
596 return; /* how did this happen? */ 592 return; /* how did this happen? */
597 } 593 }
598 buf = (const char*) sh->msg; 594 buf = (const char *) sh->msg;
599 t = GNUNET_DISK_file_write (h->fh_to_helper, 595 t = GNUNET_DISK_file_write (h->fh_to_helper,
600 &buf[sh->wpos], 596 &buf[sh->wpos],
601 ntohs (sh->msg->size) - sh->wpos); 597 ntohs (sh->msg->size) - sh->wpos);
602 if (-1 == t) 598 if (-1 == t)
603 { 599 {
604 /* On write-error, restart the helper */ 600 /* On write-error, restart the helper */
605 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 601 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
606 _("Error writing to `%s': %s\n"), 602 _ ("Error writing to `%s': %s\n"),
607 h->binary_name, 603 h->binary_name,
608 STRERROR (errno)); 604 strerror (errno));
609 if (NULL != h->exp_cb) 605 if (NULL != h->exp_cb)
610 { 606 {
611 h->exp_cb (h->cb_cls); 607 h->exp_cb (h->cb_cls);
@@ -613,33 +609,34 @@ helper_write (void *cls)
613 return; 609 return;
614 } 610 }
615 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 611 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
616 "Stopping and restarting helper task!\n"); 612 "Stopping and restarting helper task!\n");
617 stop_helper (h, GNUNET_NO); 613 stop_helper (h, GNUNET_NO);
618 /* Restart the helper */ 614 /* Restart the helper */
619 h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 615 h->restart_task = GNUNET_SCHEDULER_add_delayed (
620 h->retry_back_off), 616 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
621 &restart_task, h); 617 h->retry_back_off),
618 &restart_task,
619 h);
622 return; 620 return;
623 } 621 }
624 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 622 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
625 "Transmitted %u bytes to %s\n", 623 "Transmitted %u bytes to %s\n",
626 (unsigned int) t, 624 (unsigned int) t,
627 h->binary_name); 625 h->binary_name);
628 sh->wpos += t; 626 sh->wpos += t;
629 if (sh->wpos == ntohs (sh->msg->size)) 627 if (sh->wpos == ntohs (sh->msg->size))
630 { 628 {
631 GNUNET_CONTAINER_DLL_remove (h->sh_head, 629 GNUNET_CONTAINER_DLL_remove (h->sh_head, h->sh_tail, sh);
632 h->sh_tail,
633 sh);
634 if (NULL != sh->cont) 630 if (NULL != sh->cont)
635 sh->cont (sh->cont_cls, GNUNET_YES); 631 sh->cont (sh->cont_cls, GNUNET_YES);
636 GNUNET_free (sh); 632 GNUNET_free (sh);
637 } 633 }
638 if (NULL != h->sh_head) 634 if (NULL != h->sh_head)
639 h->write_task = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, 635 h->write_task =
640 h->fh_to_helper, 636 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
641 &helper_write, 637 h->fh_to_helper,
642 h); 638 &helper_write,
639 h);
643} 640}
644 641
645 642
@@ -658,34 +655,32 @@ helper_write (void *cls)
658 */ 655 */
659struct GNUNET_HELPER_SendHandle * 656struct GNUNET_HELPER_SendHandle *
660GNUNET_HELPER_send (struct GNUNET_HELPER_Handle *h, 657GNUNET_HELPER_send (struct GNUNET_HELPER_Handle *h,
661 const struct GNUNET_MessageHeader *msg, 658 const struct GNUNET_MessageHeader *msg,
662 int can_drop, 659 int can_drop,
663 GNUNET_HELPER_Continuation cont, 660 GNUNET_HELPER_Continuation cont,
664 void *cont_cls) 661 void *cont_cls)
665{ 662{
666 struct GNUNET_HELPER_SendHandle *sh; 663 struct GNUNET_HELPER_SendHandle *sh;
667 uint16_t mlen; 664 uint16_t mlen;
668 665
669 if (NULL == h->fh_to_helper) 666 if (NULL == h->fh_to_helper)
670 return NULL; 667 return NULL;
671 if ( (GNUNET_YES == can_drop) && 668 if ((GNUNET_YES == can_drop) && (NULL != h->sh_head))
672 (NULL != h->sh_head) )
673 return NULL; 669 return NULL;
674 mlen = ntohs (msg->size); 670 mlen = ntohs (msg->size);
675 sh = GNUNET_malloc (sizeof (struct GNUNET_HELPER_SendHandle) + mlen); 671 sh = GNUNET_malloc (sizeof (struct GNUNET_HELPER_SendHandle) + mlen);
676 sh->msg = (const struct GNUNET_MessageHeader*) &sh[1]; 672 sh->msg = (const struct GNUNET_MessageHeader *) &sh[1];
677 GNUNET_memcpy (&sh[1], msg, mlen); 673 GNUNET_memcpy (&sh[1], msg, mlen);
678 sh->h = h; 674 sh->h = h;
679 sh->cont = cont; 675 sh->cont = cont;
680 sh->cont_cls = cont_cls; 676 sh->cont_cls = cont_cls;
681 GNUNET_CONTAINER_DLL_insert_tail (h->sh_head, 677 GNUNET_CONTAINER_DLL_insert_tail (h->sh_head, h->sh_tail, sh);
682 h->sh_tail,
683 sh);
684 if (NULL == h->write_task) 678 if (NULL == h->write_task)
685 h->write_task = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, 679 h->write_task =
686 h->fh_to_helper, 680 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
687 &helper_write, 681 h->fh_to_helper,
688 h); 682 &helper_write,
683 h);
689 684
690 return sh; 685 return sh;
691} 686}
diff --git a/src/util/os_installation.c b/src/util/os_installation.c
index 8dacd431d..3e5a99811 100644
--- a/src/util/os_installation.c
+++ b/src/util/os_installation.c
@@ -107,7 +107,7 @@ GNUNET_OS_project_data_get ()
107 { 107 {
108 char *path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR); 108 char *path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR);
109 if (NULL != path) 109 if (NULL != path)
110 BINDTEXTDOMAIN (PACKAGE, path); 110 bindtextdomain (PACKAGE, path);
111 GNUNET_free (path); 111 GNUNET_free (path);
112 gettextinit = 1; 112 gettextinit = 1;
113 } 113 }
@@ -127,7 +127,7 @@ GNUNET_OS_init (const struct GNUNET_OS_ProjectData *pd)
127 { 127 {
128 char *path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR); 128 char *path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR);
129 if (NULL != path) 129 if (NULL != path)
130 BINDTEXTDOMAIN (PACKAGE, path); 130 bindtextdomain (PACKAGE, path);
131 GNUNET_free (path); 131 GNUNET_free (path);
132 gettextinit = 1; 132 gettextinit = 1;
133 } 133 }
@@ -152,7 +152,7 @@ get_path_from_proc_maps ()
152 char *lgu; 152 char *lgu;
153 153
154 GNUNET_snprintf (fn, sizeof (fn), "/proc/%u/maps", getpid ()); 154 GNUNET_snprintf (fn, sizeof (fn), "/proc/%u/maps", getpid ());
155 if (NULL == (f = FOPEN (fn, "r"))) 155 if (NULL == (f = fopen (fn, "r")))
156 return NULL; 156 return NULL;
157 while (NULL != fgets (line, sizeof (line), f)) 157 while (NULL != fgets (line, sizeof (line), f))
158 { 158 {
@@ -162,11 +162,11 @@ get_path_from_proc_maps ()
162 (NULL != (lgu = strstr (dir, current_pd->libname)))) 162 (NULL != (lgu = strstr (dir, current_pd->libname))))
163 { 163 {
164 lgu[0] = '\0'; 164 lgu[0] = '\0';
165 FCLOSE (f); 165 fclose (f);
166 return GNUNET_strdup (dir); 166 return GNUNET_strdup (dir);
167 } 167 }
168 } 168 }
169 FCLOSE (f); 169 fclose (f);
170 return NULL; 170 return NULL;
171} 171}
172 172
@@ -666,7 +666,7 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
666 { 666 {
667 GNUNET_asprintf (&dirname, 667 GNUNET_asprintf (&dirname,
668 DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR 668 DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR
669 "%s" DIR_SEPARATOR_STR, 669 "%s" DIR_SEPARATOR_STR,
670 current_pd->project_dirname); 670 current_pd->project_dirname);
671 GNUNET_asprintf (&tmp, "%s%s", execpath, dirname); 671 GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
672 } 672 }
@@ -674,7 +674,7 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
674 { 674 {
675 GNUNET_asprintf (&dirname, 675 GNUNET_asprintf (&dirname,
676 DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR 676 DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR
677 "%s" DIR_SEPARATOR_STR, 677 "%s" DIR_SEPARATOR_STR,
678 current_pd->project_dirname); 678 current_pd->project_dirname);
679 GNUNET_asprintf (&tmp, "%s%s", execpath, dirname); 679 GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
680 } 680 }
@@ -696,22 +696,22 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
696 case GNUNET_OS_IPK_DATADIR: 696 case GNUNET_OS_IPK_DATADIR:
697 GNUNET_asprintf (&dirname, 697 GNUNET_asprintf (&dirname,
698 DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR 698 DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR
699 "%s" DIR_SEPARATOR_STR, 699 "%s" DIR_SEPARATOR_STR,
700 current_pd->project_dirname); 700 current_pd->project_dirname);
701 break; 701 break;
702 case GNUNET_OS_IPK_LOCALEDIR: 702 case GNUNET_OS_IPK_LOCALEDIR:
703 dirname = GNUNET_strdup (DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR 703 dirname = GNUNET_strdup (DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR
704 "locale" DIR_SEPARATOR_STR); 704 "locale" DIR_SEPARATOR_STR);
705 break; 705 break;
706 case GNUNET_OS_IPK_ICONDIR: 706 case GNUNET_OS_IPK_ICONDIR:
707 dirname = GNUNET_strdup (DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR 707 dirname = GNUNET_strdup (DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR
708 "icons" DIR_SEPARATOR_STR); 708 "icons" DIR_SEPARATOR_STR);
709 break; 709 break;
710 case GNUNET_OS_IPK_DOCDIR: 710 case GNUNET_OS_IPK_DOCDIR:
711 GNUNET_asprintf (&dirname, 711 GNUNET_asprintf (&dirname,
712 DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR 712 DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR
713 "doc" DIR_SEPARATOR_STR 713 "doc" DIR_SEPARATOR_STR
714 "%s" DIR_SEPARATOR_STR, 714 "%s" DIR_SEPARATOR_STR,
715 current_pd->project_dirname); 715 current_pd->project_dirname);
716 break; 716 break;
717 case GNUNET_OS_IPK_LIBEXECDIR: 717 case GNUNET_OS_IPK_LIBEXECDIR:
@@ -719,7 +719,7 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
719 { 719 {
720 GNUNET_asprintf (&dirname, 720 GNUNET_asprintf (&dirname,
721 DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR 721 DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR
722 "libexec" DIR_SEPARATOR_STR, 722 "libexec" DIR_SEPARATOR_STR,
723 current_pd->project_dirname); 723 current_pd->project_dirname);
724 GNUNET_asprintf (&tmp, 724 GNUNET_asprintf (&tmp,
725 "%s%s%s%s", 725 "%s%s%s%s",
@@ -740,8 +740,8 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
740 { 740 {
741 GNUNET_asprintf (&dirname, 741 GNUNET_asprintf (&dirname,
742 DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR 742 DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR
743 "%s" DIR_SEPARATOR_STR 743 "%s" DIR_SEPARATOR_STR
744 "libexec" DIR_SEPARATOR_STR, 744 "libexec" DIR_SEPARATOR_STR,
745 current_pd->project_dirname); 745 current_pd->project_dirname);
746 GNUNET_asprintf (&tmp, "%s%s", execpath, dirname); 746 GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
747 } 747 }
@@ -749,8 +749,8 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
749 { 749 {
750 GNUNET_asprintf (&dirname, 750 GNUNET_asprintf (&dirname,
751 DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR 751 DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR
752 "%s" DIR_SEPARATOR_STR 752 "%s" DIR_SEPARATOR_STR
753 "libexec" DIR_SEPARATOR_STR, 753 "libexec" DIR_SEPARATOR_STR,
754 current_pd->project_dirname); 754 current_pd->project_dirname);
755 GNUNET_asprintf (&tmp, "%s%s", execpath, dirname); 755 GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
756 } 756 }
@@ -766,7 +766,7 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
766 } 766 }
767 GNUNET_asprintf (&dirname, 767 GNUNET_asprintf (&dirname,
768 DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR 768 DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR
769 "libexec" DIR_SEPARATOR_STR, 769 "libexec" DIR_SEPARATOR_STR,
770 current_pd->project_dirname); 770 current_pd->project_dirname);
771 break; 771 break;
772 default: 772 default:
@@ -844,14 +844,14 @@ GNUNET_OS_get_suid_binary_path (const struct GNUNET_CONFIGURATION_Handle *cfg,
844 "PATHS", 844 "PATHS",
845 "SUID_BINARY_PATH", 845 "SUID_BINARY_PATH",
846 &path); 846 &path);
847 if ((NULL == path)||(0 == strlen (path))) 847 if ((NULL == path) || (0 == strlen (path)))
848 return GNUNET_OS_get_libexec_binary_path (progname); 848 return GNUNET_OS_get_libexec_binary_path (progname);
849 path_len = strlen (path); 849 path_len = strlen (path);
850 GNUNET_asprintf (&binary, 850 GNUNET_asprintf (&binary,
851 "%s%s%s", 851 "%s%s%s",
852 path, 852 path,
853 (path[path_len - 1] == DIR_SEPARATOR) ? "" 853 (path[path_len - 1] == DIR_SEPARATOR) ? ""
854 : DIR_SEPARATOR_STR, 854 : DIR_SEPARATOR_STR,
855 progname); 855 progname);
856 cache = path; 856 cache = path;
857 return binary; 857 return binary;
@@ -926,7 +926,7 @@ GNUNET_OS_check_helper_binary (const char *binary,
926 binary); 926 binary);
927 return GNUNET_SYSERR; 927 return GNUNET_SYSERR;
928 } 928 }
929 if (0 != ACCESS (p, X_OK)) 929 if (0 != access (p, X_OK))
930 { 930 {
931 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", p); 931 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", p);
932 GNUNET_free (p); 932 GNUNET_free (p);
@@ -940,7 +940,7 @@ GNUNET_OS_check_helper_binary (const char *binary,
940 return GNUNET_YES; 940 return GNUNET_YES;
941 } 941 }
942#endif 942#endif
943 if (0 != STAT (p, &statbuf)) 943 if (0 != stat (p, &statbuf))
944 { 944 {
945 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", p); 945 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", p);
946 GNUNET_free (p); 946 GNUNET_free (p);
@@ -973,16 +973,16 @@ GNUNET_OS_check_helper_binary (const char *binary,
973 973
974 // Start the child process. 974 // Start the child process.
975 if (! (CreateProcess ( 975 if (! (CreateProcess (
976 p, // current windows (2k3 and up can handle / instead of \ in paths)) 976 p, // current windows (2k3 and up can handle / instead of \ in paths))
977 parameters, // execute dryrun/priviliege checking mode 977 parameters, // execute dryrun/priviliege checking mode
978 NULL, // Process handle not inheritable 978 NULL, // Process handle not inheritable
979 NULL, // Thread handle not inheritable 979 NULL, // Thread handle not inheritable
980 FALSE, // Set handle inheritance to FALSE 980 FALSE, // Set handle inheritance to FALSE
981 CREATE_DEFAULT_ERROR_MODE, // No creation flags 981 CREATE_DEFAULT_ERROR_MODE, // No creation flags
982 NULL, // Use parent's environment block 982 NULL, // Use parent's environment block
983 NULL, // Use parent's starting directory 983 NULL, // Use parent's starting directory
984 &start, // Pointer to STARTUPINFO structure 984 &start, // Pointer to STARTUPINFO structure
985 &proc) // Pointer to PROCESS_INFORMATION structure 985 &proc) // Pointer to PROCESS_INFORMATION structure
986 )) 986 ))
987 { 987 {
988 LOG (GNUNET_ERROR_TYPE_ERROR, 988 LOG (GNUNET_ERROR_TYPE_ERROR,
diff --git a/src/util/os_priority.c b/src/util/os_priority.c
index 03d4bde9e..17baa0df8 100644
--- a/src/util/os_priority.c
+++ b/src/util/os_priority.c
@@ -29,11 +29,13 @@
29#include "disk.h" 29#include "disk.h"
30#include <unistr.h> 30#include <unistr.h>
31 31
32#define LOG(kind,...) GNUNET_log_from (kind, "util-os-priority", __VA_ARGS__) 32#define LOG(kind, ...) GNUNET_log_from (kind, "util-os-priority", __VA_ARGS__)
33 33
34#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-os-priority", syscall) 34#define LOG_STRERROR(kind, syscall) \
35 GNUNET_log_from_strerror (kind, "util-os-priority", syscall)
35 36
36#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-os-priority", syscall, filename) 37#define LOG_STRERROR_FILE(kind, syscall, filename) \
38 GNUNET_log_from_strerror_file (kind, "util-os-priority", syscall, filename)
37 39
38#define GNUNET_OS_CONTROL_PIPE "GNUNET_OS_CONTROL_PIPE" 40#define GNUNET_OS_CONTROL_PIPE "GNUNET_OS_CONTROL_PIPE"
39 41
@@ -107,16 +109,12 @@ parent_control_handler (void *cls)
107 ssize_t ret; 109 ssize_t ret;
108 110
109 pch = NULL; 111 pch = NULL;
110 ret = GNUNET_DISK_file_read (control_pipe, 112 ret = GNUNET_DISK_file_read (control_pipe, &sig, sizeof (sig));
111 &sig,
112 sizeof (sig));
113 if (sizeof (sig) != ret) 113 if (sizeof (sig) != ret)
114 { 114 {
115 if (-1 == ret) 115 if (-1 == ret)
116 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, 116 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DISK_file_read");
117 "GNUNET_DISK_file_read"); 117 LOG (GNUNET_ERROR_TYPE_DEBUG, "Closing control pipe\n");
118 LOG (GNUNET_ERROR_TYPE_DEBUG,
119 "Closing control pipe\n");
120 GNUNET_DISK_file_close (control_pipe); 118 GNUNET_DISK_file_close (control_pipe);
121 control_pipe = NULL; 119 control_pipe = NULL;
122 GNUNET_SCHEDULER_cancel (spch); 120 GNUNET_SCHEDULER_cancel (spch);
@@ -124,16 +122,15 @@ parent_control_handler (void *cls)
124 return; 122 return;
125 } 123 }
126 pipe_fd = getenv (GNUNET_OS_CONTROL_PIPE); 124 pipe_fd = getenv (GNUNET_OS_CONTROL_PIPE);
127 GNUNET_assert ( (NULL == pipe_fd) || 125 GNUNET_assert ((NULL == pipe_fd) || (strlen (pipe_fd) <= 0));
128 (strlen (pipe_fd) <= 0) );
129 LOG (GNUNET_ERROR_TYPE_DEBUG, 126 LOG (GNUNET_ERROR_TYPE_DEBUG,
130 "Got control code %d from parent via pipe %s\n", 127 "Got control code %d from parent via pipe %s\n",
131 sig, 128 sig,
132 pipe_fd); 129 pipe_fd);
133 pch = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 130 pch = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
134 control_pipe, 131 control_pipe,
135 &parent_control_handler, 132 &parent_control_handler,
136 control_pipe); 133 control_pipe);
137 GNUNET_SIGNAL_raise ((int) sig); 134 GNUNET_SIGNAL_raise ((int) sig);
138} 135}
139 136
@@ -162,10 +159,10 @@ GNUNET_OS_install_parent_control_handler (void *cls)
162 return; 159 return;
163 } 160 }
164 env_buf = getenv (GNUNET_OS_CONTROL_PIPE); 161 env_buf = getenv (GNUNET_OS_CONTROL_PIPE);
165 if ( (NULL == env_buf) || (strlen (env_buf) <= 0) ) 162 if ((NULL == env_buf) || (strlen (env_buf) <= 0))
166 { 163 {
167 LOG (GNUNET_ERROR_TYPE_DEBUG, 164 LOG (GNUNET_ERROR_TYPE_DEBUG,
168 "Not installing a handler because $%s is empty\n", 165 "Not installing a handler because $%s is empty\n",
169 GNUNET_OS_CONTROL_PIPE); 166 GNUNET_OS_CONTROL_PIPE);
170 putenv (GNUNET_OS_CONTROL_PIPE "="); 167 putenv (GNUNET_OS_CONTROL_PIPE "=");
171 return; 168 return;
@@ -174,35 +171,32 @@ GNUNET_OS_install_parent_control_handler (void *cls)
174 pipe_fd = strtoull (env_buf, &env_buf_end, 16); 171 pipe_fd = strtoull (env_buf, &env_buf_end, 16);
175 if ((0 != errno) || (env_buf == env_buf_end)) 172 if ((0 != errno) || (env_buf == env_buf_end))
176 { 173 {
177 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, 174 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "strtoull", env_buf);
178 "strtoull",
179 env_buf);
180 putenv (GNUNET_OS_CONTROL_PIPE "="); 175 putenv (GNUNET_OS_CONTROL_PIPE "=");
181 return; 176 return;
182 } 177 }
183#if !defined (WINDOWS) 178#if ! defined(WINDOWS)
184 if (pipe_fd >= FD_SETSIZE) 179 if (pipe_fd >= FD_SETSIZE)
185#else 180#else
186 if ((FILE_TYPE_UNKNOWN == GetFileType ((HANDLE) (uintptr_t) pipe_fd)) 181 if ((FILE_TYPE_UNKNOWN == GetFileType ((HANDLE) (uintptr_t) pipe_fd)) &&
187 && (0 != GetLastError ())) 182 (0 != GetLastError ()))
188#endif 183#endif
189 { 184 {
190 LOG (GNUNET_ERROR_TYPE_ERROR, 185 LOG (GNUNET_ERROR_TYPE_ERROR,
191 "GNUNET_OS_CONTROL_PIPE `%s' contains garbage?\n", 186 "GNUNET_OS_CONTROL_PIPE `%s' contains garbage?\n",
192 env_buf); 187 env_buf);
193 putenv (GNUNET_OS_CONTROL_PIPE "="); 188 putenv (GNUNET_OS_CONTROL_PIPE "=");
194 return; 189 return;
195 } 190 }
196#if WINDOWS 191#if WINDOWS
197 control_pipe = GNUNET_DISK_get_handle_from_w32_handle ((HANDLE) (uintptr_t) pipe_fd); 192 control_pipe =
193 GNUNET_DISK_get_handle_from_w32_handle ((HANDLE) (uintptr_t) pipe_fd);
198#else 194#else
199 control_pipe = GNUNET_DISK_get_handle_from_int_fd ((int) pipe_fd); 195 control_pipe = GNUNET_DISK_get_handle_from_int_fd ((int) pipe_fd);
200#endif 196#endif
201 if (NULL == control_pipe) 197 if (NULL == control_pipe)
202 { 198 {
203 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, 199 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", env_buf);
204 "open",
205 env_buf);
206 putenv (GNUNET_OS_CONTROL_PIPE "="); 200 putenv (GNUNET_OS_CONTROL_PIPE "=");
207 return; 201 return;
208 } 202 }
@@ -210,11 +204,10 @@ GNUNET_OS_install_parent_control_handler (void *cls)
210 "Adding parent control handler pipe `%s' to the scheduler\n", 204 "Adding parent control handler pipe `%s' to the scheduler\n",
211 env_buf); 205 env_buf);
212 pch = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 206 pch = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
213 control_pipe, 207 control_pipe,
214 &parent_control_handler, 208 &parent_control_handler,
215 control_pipe);
216 spch = GNUNET_SCHEDULER_add_shutdown (&shutdown_pch,
217 control_pipe); 209 control_pipe);
210 spch = GNUNET_SCHEDULER_add_shutdown (&shutdown_pch, control_pipe);
218 putenv (GNUNET_OS_CONTROL_PIPE "="); 211 putenv (GNUNET_OS_CONTROL_PIPE "=");
219} 212}
220 213
@@ -248,8 +241,7 @@ GNUNET_OS_process_current ()
248 * @return 0 on success, -1 on error 241 * @return 0 on success, -1 on error
249 */ 242 */
250int 243int
251GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, 244GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig)
252 int sig)
253{ 245{
254 int ret; 246 int ret;
255 char csig; 247 char csig;
@@ -258,19 +250,17 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc,
258 if (NULL != proc->control_pipe) 250 if (NULL != proc->control_pipe)
259 { 251 {
260 LOG (GNUNET_ERROR_TYPE_DEBUG, 252 LOG (GNUNET_ERROR_TYPE_DEBUG,
261 "Sending signal %d to pid: %u via pipe\n", 253 "Sending signal %d to pid: %u via pipe\n",
262 sig, 254 sig,
263 proc->pid); 255 proc->pid);
264 ret = GNUNET_DISK_file_write (proc->control_pipe, 256 ret = GNUNET_DISK_file_write (proc->control_pipe, &csig, sizeof (csig));
265 &csig,
266 sizeof (csig));
267 if (sizeof (csig) == ret) 257 if (sizeof (csig) == ret)
268 return 0; 258 return 0;
269 } 259 }
270 /* pipe failed or non-existent, try other methods */ 260 /* pipe failed or non-existent, try other methods */
271 switch (sig) 261 switch (sig)
272 { 262 {
273#if !defined (WINDOWS) 263#if ! defined(WINDOWS)
274 case SIGHUP: 264 case SIGHUP:
275#endif 265#endif
276 case SIGINT: 266 case SIGINT:
@@ -279,62 +269,62 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc,
279#if (SIGTERM != GNUNET_TERM_SIG) 269#if (SIGTERM != GNUNET_TERM_SIG)
280 case GNUNET_TERM_SIG: 270 case GNUNET_TERM_SIG:
281#endif 271#endif
282#if defined(WINDOWS) && !defined(__CYGWIN__) 272#if defined(WINDOWS) && ! defined(__CYGWIN__)
273 {
274 DWORD exitcode;
275 int must_kill = GNUNET_YES;
276 if (0 != GetExitCodeProcess (proc->handle, &exitcode))
277 must_kill = (exitcode == STILL_ACTIVE) ? GNUNET_YES : GNUNET_NO;
278 if (GNUNET_YES == must_kill)
283 { 279 {
284 DWORD exitcode; 280 if (0 == SafeTerminateProcess (proc->handle, 0, 0))
285 int must_kill = GNUNET_YES;
286 if (0 != GetExitCodeProcess (proc->handle, &exitcode))
287 must_kill = (exitcode == STILL_ACTIVE) ? GNUNET_YES : GNUNET_NO;
288 if (GNUNET_YES == must_kill)
289 { 281 {
290 if (0 == SafeTerminateProcess (proc->handle, 0, 0)) 282 DWORD error_code = GetLastError ();
283 if ((error_code != WAIT_TIMEOUT) &&
284 (error_code != ERROR_PROCESS_ABORTED))
291 { 285 {
292 DWORD error_code = GetLastError (); 286 LOG ((error_code == ERROR_ACCESS_DENIED) ? GNUNET_ERROR_TYPE_INFO
293 if ( (error_code != WAIT_TIMEOUT) && 287 : GNUNET_ERROR_TYPE_WARNING,
294 (error_code != ERROR_PROCESS_ABORTED) ) 288 "SafeTermiateProcess failed with code %lu\n",
295 { 289 error_code);
296 LOG ((error_code == ERROR_ACCESS_DENIED) ? 290 /* The problem here is that a process that is already dying
297 GNUNET_ERROR_TYPE_INFO : GNUNET_ERROR_TYPE_WARNING,
298 "SafeTermiateProcess failed with code %lu\n",
299 error_code);
300 /* The problem here is that a process that is already dying
301 * might cause SafeTerminateProcess to fail with 291 * might cause SafeTerminateProcess to fail with
302 * ERROR_ACCESS_DENIED, but the process WILL die eventually. 292 * ERROR_ACCESS_DENIED, but the process WILL die eventually.
303 * If we really had a permissions problem, hanging up (which 293 * If we really had a permissions problem, hanging up (which
304 * is what will happen in process_wait() in that case) is 294 * is what will happen in process_wait() in that case) is
305 * a valid option. 295 * a valid option.
306 */ 296 */
307 if (ERROR_ACCESS_DENIED == error_code) 297 if (ERROR_ACCESS_DENIED == error_code)
308 { 298 {
309 errno = 0; 299 errno = 0;
310 } 300 }
311 else 301 else
312 { 302 {
313 SetErrnoFromWinError (error_code); 303 SetErrnoFromWinError (error_code);
314 return -1; 304 return -1;
315 }
316 } 305 }
317 } 306 }
318 } 307 }
319 } 308 }
309 }
320 return 0; 310 return 0;
321#else 311#else
322 LOG (GNUNET_ERROR_TYPE_DEBUG, 312 LOG (GNUNET_ERROR_TYPE_DEBUG,
323 "Sending signal %d to pid: %u via system call\n", 313 "Sending signal %d to pid: %u via system call\n",
324 sig, 314 sig,
325 proc->pid); 315 proc->pid);
326 return PLIBC_KILL (proc->pid, sig); 316 return kill (proc->pid, sig);
327#endif 317#endif
328 default: 318 default:
329#if defined (WINDOWS) 319#if defined(WINDOWS)
330 errno = EINVAL; 320 errno = EINVAL;
331 return -1; 321 return -1;
332#else 322#else
333 LOG (GNUNET_ERROR_TYPE_DEBUG, 323 LOG (GNUNET_ERROR_TYPE_DEBUG,
334 "Sending signal %d to pid: %u via system call\n", 324 "Sending signal %d to pid: %u via system call\n",
335 sig, 325 sig,
336 proc->pid); 326 proc->pid);
337 return PLIBC_KILL (proc->pid, sig); 327 return kill (proc->pid, sig);
338#endif 328#endif
339 } 329 }
340} 330}
@@ -348,7 +338,7 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc,
348 * @return the current process id 338 * @return the current process id
349 */ 339 */
350pid_t 340pid_t
351GNUNET_OS_process_get_pid (struct GNUNET_OS_Process * proc) 341GNUNET_OS_process_get_pid (struct GNUNET_OS_Process *proc)
352{ 342{
353 return proc->pid; 343 return proc->pid;
354} 344}
@@ -365,7 +355,7 @@ GNUNET_OS_process_destroy (struct GNUNET_OS_Process *proc)
365{ 355{
366 if (NULL != proc->control_pipe) 356 if (NULL != proc->control_pipe)
367 GNUNET_DISK_file_close (proc->control_pipe); 357 GNUNET_DISK_file_close (proc->control_pipe);
368#if defined (WINDOWS) 358#if defined(WINDOWS)
369 if (NULL != proc->handle) 359 if (NULL != proc->handle)
370 CloseHandle (proc->handle); 360 CloseHandle (proc->handle);
371#endif 361#endif
@@ -425,7 +415,8 @@ CreateCustomEnvTable (char **vars)
425 win32_env_table = GetEnvironmentStringsA (); 415 win32_env_table = GetEnvironmentStringsA ();
426 if (NULL == win32_env_table) 416 if (NULL == win32_env_table)
427 return NULL; 417 return NULL;
428 for (c = 0, var_ptr = vars; *var_ptr; var_ptr += 2, c++) ; 418 for (c = 0, var_ptr = vars; *var_ptr; var_ptr += 2, c++)
419 ;
429 n_var = c; 420 n_var = c;
430 index = GNUNET_malloc (sizeof (char *) * n_var); 421 index = GNUNET_malloc (sizeof (char *) * n_var);
431 for (c = 0; c < n_var; c++) 422 for (c = 0; c < n_var; c++)
@@ -448,7 +439,7 @@ CreateCustomEnvTable (char **vars)
448 break; 439 break;
449 } 440 }
450 } 441 }
451 if (!found) 442 if (! found)
452 tablesize += len + 1; 443 tablesize += len + 1;
453 ptr += len + 1; 444 ptr += len + 1;
454 } 445 }
@@ -476,7 +467,7 @@ CreateCustomEnvTable (char **vars)
476 break; 467 break;
477 } 468 }
478 } 469 }
479 if (!found) 470 if (! found)
480 { 471 {
481 strcpy (result_ptr, ptr); 472 strcpy (result_ptr, ptr);
482 result_ptr += len + 1; 473 result_ptr += len + 1;
@@ -519,17 +510,14 @@ CreateCustomEnvTable (char **vars)
519 * @param flags open flags (O_RDONLY, O_WRONLY) 510 * @param flags open flags (O_RDONLY, O_WRONLY)
520 */ 511 */
521static void 512static void
522open_dev_null (int target_fd, 513open_dev_null (int target_fd, int flags)
523 int flags)
524{ 514{
525 int fd; 515 int fd;
526 516
527 fd = open ("/dev/null", flags); 517 fd = open ("/dev/null", flags);
528 if (-1 == fd) 518 if (-1 == fd)
529 { 519 {
530 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 520 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", "/dev/null");
531 "open",
532 "/dev/null");
533 return; 521 return;
534 } 522 }
535 if (fd == target_fd) 523 if (fd == target_fd)
@@ -565,12 +553,12 @@ open_dev_null (int target_fd,
565static struct GNUNET_OS_Process * 553static struct GNUNET_OS_Process *
566start_process (int pipe_control, 554start_process (int pipe_control,
567 enum GNUNET_OS_InheritStdioFlags std_inheritance, 555 enum GNUNET_OS_InheritStdioFlags std_inheritance,
568 struct GNUNET_DISK_PipeHandle *pipe_stdin, 556 struct GNUNET_DISK_PipeHandle *pipe_stdin,
569 struct GNUNET_DISK_PipeHandle *pipe_stdout, 557 struct GNUNET_DISK_PipeHandle *pipe_stdout,
570 struct GNUNET_DISK_PipeHandle *pipe_stderr, 558 struct GNUNET_DISK_PipeHandle *pipe_stderr,
571 const SOCKTYPE *lsocks, 559 const SOCKTYPE *lsocks,
572 const char *filename, 560 const char *filename,
573 char *const argv[]) 561 char *const argv[])
574{ 562{
575#ifndef MINGW 563#ifndef MINGW
576 pid_t ret; 564 pid_t ret;
@@ -601,22 +589,19 @@ start_process (int pipe_control,
601 struct GNUNET_DISK_PipeHandle *childpipe; 589 struct GNUNET_DISK_PipeHandle *childpipe;
602 int dup_childpipe_read_fd = -1; 590 int dup_childpipe_read_fd = -1;
603 591
604 childpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, 592 childpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES, GNUNET_NO);
605 GNUNET_YES, GNUNET_NO);
606 if (NULL == childpipe) 593 if (NULL == childpipe)
607 return NULL; 594 return NULL;
608 childpipe_read = GNUNET_DISK_pipe_detach_end (childpipe, 595 childpipe_read =
609 GNUNET_DISK_PIPE_END_READ); 596 GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_READ);
610 childpipe_write = GNUNET_DISK_pipe_detach_end (childpipe, 597 childpipe_write =
611 GNUNET_DISK_PIPE_END_WRITE); 598 GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_WRITE);
612 GNUNET_DISK_pipe_close (childpipe); 599 GNUNET_DISK_pipe_close (childpipe);
613 if ( (NULL == childpipe_read) || 600 if ((NULL == childpipe_read) || (NULL == childpipe_write) ||
614 (NULL == childpipe_write) || 601 (GNUNET_OK != GNUNET_DISK_internal_file_handle_ (childpipe_read,
615 (GNUNET_OK != 602 &childpipe_read_fd,
616 GNUNET_DISK_internal_file_handle_ (childpipe_read, 603 sizeof (int))) ||
617 &childpipe_read_fd, 604 (-1 == (dup_childpipe_read_fd = dup (childpipe_read_fd))))
618 sizeof (int))) ||
619 (-1 == (dup_childpipe_read_fd = dup (childpipe_read_fd))))
620 { 605 {
621 if (NULL != childpipe_read) 606 if (NULL != childpipe_read)
622 GNUNET_DISK_file_close (childpipe_read); 607 GNUNET_DISK_file_close (childpipe_read);
@@ -636,39 +621,48 @@ start_process (int pipe_control,
636 } 621 }
637 if (NULL != pipe_stdin) 622 if (NULL != pipe_stdin)
638 { 623 {
639 GNUNET_assert (GNUNET_OK == 624 GNUNET_assert (
640 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle 625 GNUNET_OK ==
641 (pipe_stdin, GNUNET_DISK_PIPE_END_READ), 626 GNUNET_DISK_internal_file_handle_ (
642 &fd_stdin_read, sizeof (int))); 627 GNUNET_DISK_pipe_handle (pipe_stdin, GNUNET_DISK_PIPE_END_READ),
643 GNUNET_assert (GNUNET_OK == 628 &fd_stdin_read,
644 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle 629 sizeof (int)));
645 (pipe_stdin, GNUNET_DISK_PIPE_END_WRITE), 630 GNUNET_assert (
646 &fd_stdin_write, sizeof (int))); 631 GNUNET_OK ==
632 GNUNET_DISK_internal_file_handle_ (
633 GNUNET_DISK_pipe_handle (pipe_stdin, GNUNET_DISK_PIPE_END_WRITE),
634 &fd_stdin_write,
635 sizeof (int)));
647 } 636 }
648 if (NULL != pipe_stdout) 637 if (NULL != pipe_stdout)
649 { 638 {
650 GNUNET_assert (GNUNET_OK == 639 GNUNET_assert (
651 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle 640 GNUNET_OK ==
652 (pipe_stdout, 641 GNUNET_DISK_internal_file_handle_ (
653 GNUNET_DISK_PIPE_END_WRITE), 642 GNUNET_DISK_pipe_handle (pipe_stdout, GNUNET_DISK_PIPE_END_WRITE),
654 &fd_stdout_write, sizeof (int))); 643 &fd_stdout_write,
655 GNUNET_assert (GNUNET_OK == 644 sizeof (int)));
656 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle 645 GNUNET_assert (
657 (pipe_stdout, GNUNET_DISK_PIPE_END_READ), 646 GNUNET_OK ==
658 &fd_stdout_read, sizeof (int))); 647 GNUNET_DISK_internal_file_handle_ (
648 GNUNET_DISK_pipe_handle (pipe_stdout, GNUNET_DISK_PIPE_END_READ),
649 &fd_stdout_read,
650 sizeof (int)));
659 } 651 }
660 if (NULL != pipe_stderr) 652 if (NULL != pipe_stderr)
661 { 653 {
662 GNUNET_assert (GNUNET_OK == 654 GNUNET_assert (
663 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle 655 GNUNET_OK ==
664 (pipe_stderr, 656 GNUNET_DISK_internal_file_handle_ (
665 GNUNET_DISK_PIPE_END_READ), 657 GNUNET_DISK_pipe_handle (pipe_stderr, GNUNET_DISK_PIPE_END_READ),
666 &fd_stderr_read, sizeof (int))); 658 &fd_stderr_read,
667 GNUNET_assert (GNUNET_OK == 659 sizeof (int)));
668 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle 660 GNUNET_assert (
669 (pipe_stderr, 661 GNUNET_OK ==
670 GNUNET_DISK_PIPE_END_WRITE), 662 GNUNET_DISK_internal_file_handle_ (
671 &fd_stderr_write, sizeof (int))); 663 GNUNET_DISK_pipe_handle (pipe_stderr, GNUNET_DISK_PIPE_END_WRITE),
664 &fd_stderr_write,
665 sizeof (int)));
672 } 666 }
673 lscp = NULL; 667 lscp = NULL;
674 ls = 0; 668 ls = 0;
@@ -819,7 +813,7 @@ start_process (int pipe_control,
819 int argcount = 0; 813 int argcount = 0;
820 struct GNUNET_OS_Process *gnunet_proc; 814 struct GNUNET_OS_Process *gnunet_proc;
821 char path[MAX_PATH + 1]; 815 char path[MAX_PATH + 1];
822 char *our_env[7] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL }; 816 char *our_env[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
823 char *env_block = NULL; 817 char *env_block = NULL;
824 char *pathbuf; 818 char *pathbuf;
825 DWORD pathbuf_len; 819 DWORD pathbuf_len;
@@ -849,7 +843,8 @@ start_process (int pipe_control,
849 DWORD error_code; 843 DWORD error_code;
850 DWORD create_no_window; 844 DWORD create_no_window;
851 845
852 if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary (filename, GNUNET_NO, NULL)) 846 if (GNUNET_SYSERR ==
847 GNUNET_OS_check_helper_binary (filename, GNUNET_NO, NULL))
853 return NULL; /* not executable */ 848 return NULL; /* not executable */
854 849
855 /* Search in prefix dir (hopefully - the directory from which 850 /* Search in prefix dir (hopefully - the directory from which
@@ -861,9 +856,8 @@ start_process (int pipe_control,
861 856
862 pathbuf_len = GetEnvironmentVariableA ("PATH", (char *) &pathbuf, 0); 857 pathbuf_len = GetEnvironmentVariableA ("PATH", (char *) &pathbuf, 0);
863 858
864 alloc_len = 859 alloc_len = pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 +
865 pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 + 860 strlen (libdir);
866 strlen (libdir);
867 861
868 pathbuf = GNUNET_malloc (alloc_len * sizeof (char)); 862 pathbuf = GNUNET_malloc (alloc_len * sizeof (char));
869 863
@@ -877,21 +871,23 @@ start_process (int pipe_control,
877 if (alloc_len != pathbuf_len - 1) 871 if (alloc_len != pathbuf_len - 1)
878 { 872 {
879 GNUNET_free (pathbuf); 873 GNUNET_free (pathbuf);
880 errno = ENOSYS; /* PATH changed on the fly. What kind of error is that? */ 874 errno = ENOSYS; /* PATH changed on the fly. What kind of error is that? */
881 return NULL; 875 return NULL;
882 } 876 }
883 877
884 cmdlen = strlen (filename); 878 cmdlen = strlen (filename);
885 if ( (cmdlen < 5) || (0 != strcmp (&filename[cmdlen - 4], ".exe")) ) 879 if ((cmdlen < 5) || (0 != strcmp (&filename[cmdlen - 4], ".exe")))
886 GNUNET_asprintf (&non_const_filename, "%s.exe", filename); 880 GNUNET_asprintf (&non_const_filename, "%s.exe", filename);
887 else 881 else
888 GNUNET_asprintf (&non_const_filename, "%s", filename); 882 GNUNET_asprintf (&non_const_filename, "%s", filename);
889 883
890 /* It could be in POSIX form, convert it to a DOS path early on */ 884 /* It could be in POSIX form, convert it to a DOS path early on */
891 if (ERROR_SUCCESS != (lRet = plibc_conv_to_win_path (non_const_filename, win_path))) 885 if (ERROR_SUCCESS !=
886 (lRet = plibc_conv_to_win_path (non_const_filename, win_path)))
892 { 887 {
893 SetErrnoFromWinError (lRet); 888 SetErrnoFromWinError (lRet);
894 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "plibc_conv_to_win_path", 889 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR,
890 "plibc_conv_to_win_path",
895 non_const_filename); 891 non_const_filename);
896 GNUNET_free (non_const_filename); 892 GNUNET_free (non_const_filename);
897 GNUNET_free (pathbuf); 893 GNUNET_free (pathbuf);
@@ -899,7 +895,7 @@ start_process (int pipe_control,
899 } 895 }
900 GNUNET_free (non_const_filename); 896 GNUNET_free (non_const_filename);
901 non_const_filename = GNUNET_strdup (win_path); 897 non_const_filename = GNUNET_strdup (win_path);
902 /* Check that this is the full path. If it isn't, search. */ 898 /* Check that this is the full path. If it isn't, search. */
903 /* FIXME: convert it to wchar_t and use SearchPathW? 899 /* FIXME: convert it to wchar_t and use SearchPathW?
904 * Remember: arguments to _start_process() are technically in UTF-8... 900 * Remember: arguments to _start_process() are technically in UTF-8...
905 */ 901 */
@@ -907,22 +903,27 @@ start_process (int pipe_control,
907 { 903 {
908 snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename); 904 snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename);
909 LOG (GNUNET_ERROR_TYPE_DEBUG, 905 LOG (GNUNET_ERROR_TYPE_DEBUG,
910 "Using path `%s' as-is. PATH is %s\n", path, ptr); 906 "Using path `%s' as-is. PATH is %s\n",
907 path,
908 ptr);
911 } 909 }
912 else if (!SearchPathA 910 else if (! SearchPathA (pathbuf,
913 (pathbuf, non_const_filename, NULL, sizeof (path) / sizeof (char), 911 non_const_filename,
914 path, NULL)) 912 NULL,
913 sizeof (path) / sizeof (char),
914 path,
915 NULL))
915 { 916 {
916 SetErrnoFromWinError (GetLastError ()); 917 SetErrnoFromWinError (GetLastError ());
917 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "SearchPath", 918 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR,
919 "SearchPath",
918 non_const_filename); 920 non_const_filename);
919 GNUNET_free (non_const_filename); 921 GNUNET_free (non_const_filename);
920 GNUNET_free (pathbuf); 922 GNUNET_free (pathbuf);
921 return NULL; 923 return NULL;
922 } 924 }
923 else 925 else
924 LOG (GNUNET_ERROR_TYPE_DEBUG, 926 LOG (GNUNET_ERROR_TYPE_DEBUG, "Found `%s' in PATH `%s'\n", path, pathbuf);
925 "Found `%s' in PATH `%s'\n", path, pathbuf);
926 GNUNET_free (pathbuf); 927 GNUNET_free (pathbuf);
927 GNUNET_free (non_const_filename); 928 GNUNET_free (non_const_filename);
928 929
@@ -966,8 +967,11 @@ start_process (int pipe_control,
966 while (*arg) 967 while (*arg)
967 { 968 {
968 char arg_last_char = (*arg)[strlen (*arg) - 1]; 969 char arg_last_char = (*arg)[strlen (*arg) - 1];
969 idx += sprintf (idx, "\"%s%s\"%s", *arg, 970 idx += sprintf (idx,
970 arg_last_char == '\\' ? "\\" : "", *(arg + 1) ? " " : ""); 971 "\"%s%s\"%s",
972 *arg,
973 arg_last_char == '\\' ? "\\" : "",
974 *(arg + 1) ? " " : "");
971 arg++; 975 arg++;
972 } 976 }
973 977
@@ -984,9 +988,10 @@ start_process (int pipe_control,
984 GetHandleInformation (stdih, &stdif); 988 GetHandleInformation (stdih, &stdif);
985 if (pipe_stdin != NULL) 989 if (pipe_stdin != NULL)
986 { 990 {
987 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle 991 GNUNET_DISK_internal_file_handle_ (
988 (pipe_stdin, GNUNET_DISK_PIPE_END_READ), 992 GNUNET_DISK_pipe_handle (pipe_stdin, GNUNET_DISK_PIPE_END_READ),
989 &stdin_handle, sizeof (HANDLE)); 993 &stdin_handle,
994 sizeof (HANDLE));
990 start.hStdInput = stdin_handle; 995 start.hStdInput = stdin_handle;
991 } 996 }
992 else if (stdih) 997 else if (stdih)
@@ -1006,10 +1011,10 @@ start_process (int pipe_control,
1006 GetHandleInformation (stdoh, &stdof); 1011 GetHandleInformation (stdoh, &stdof);
1007 if (NULL != pipe_stdout) 1012 if (NULL != pipe_stdout)
1008 { 1013 {
1009 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle 1014 GNUNET_DISK_internal_file_handle_ (
1010 (pipe_stdout, 1015 GNUNET_DISK_pipe_handle (pipe_stdout, GNUNET_DISK_PIPE_END_WRITE),
1011 GNUNET_DISK_PIPE_END_WRITE), 1016 &stdout_handle,
1012 &stdout_handle, sizeof (HANDLE)); 1017 sizeof (HANDLE));
1013 start.hStdOutput = stdout_handle; 1018 start.hStdOutput = stdout_handle;
1014 } 1019 }
1015 else if (stdoh) 1020 else if (stdoh)
@@ -1043,12 +1048,15 @@ start_process (int pipe_control,
1043 childpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES, GNUNET_NO); 1048 childpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES, GNUNET_NO);
1044 if (NULL == childpipe) 1049 if (NULL == childpipe)
1045 return NULL; 1050 return NULL;
1046 childpipe_read = GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_READ); 1051 childpipe_read =
1047 childpipe_write = GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_WRITE); 1052 GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_READ);
1053 childpipe_write =
1054 GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_WRITE);
1048 GNUNET_DISK_pipe_close (childpipe); 1055 GNUNET_DISK_pipe_close (childpipe);
1049 if ((NULL == childpipe_read) || (NULL == childpipe_write) || 1056 if ((NULL == childpipe_read) || (NULL == childpipe_write) ||
1050 (GNUNET_OK != GNUNET_DISK_internal_file_handle_ (childpipe_read, 1057 (GNUNET_OK != GNUNET_DISK_internal_file_handle_ (childpipe_read,
1051 &childpipe_read_handle, sizeof (HANDLE)))) 1058 &childpipe_read_handle,
1059 sizeof (HANDLE))))
1052 { 1060 {
1053 if (childpipe_read) 1061 if (childpipe_read)
1054 GNUNET_DISK_file_close (childpipe_read); 1062 GNUNET_DISK_file_close (childpipe_read);
@@ -1070,7 +1078,8 @@ start_process (int pipe_control,
1070 1078
1071 if (lsocks != NULL && lsocks[0] != INVALID_SOCKET) 1079 if (lsocks != NULL && lsocks[0] != INVALID_SOCKET)
1072 { 1080 {
1073 lsocks_pipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO); 1081 lsocks_pipe =
1082 GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO);
1074 1083
1075 if (lsocks_pipe == NULL) 1084 if (lsocks_pipe == NULL)
1076 { 1085 {
@@ -1083,13 +1092,15 @@ start_process (int pipe_control,
1083 } 1092 }
1084 return NULL; 1093 return NULL;
1085 } 1094 }
1086 lsocks_write_fd = GNUNET_DISK_pipe_handle (lsocks_pipe, 1095 lsocks_write_fd =
1087 GNUNET_DISK_PIPE_END_WRITE); 1096 GNUNET_DISK_pipe_handle (lsocks_pipe, GNUNET_DISK_PIPE_END_WRITE);
1088 GNUNET_DISK_internal_file_handle_ (lsocks_write_fd, 1097 GNUNET_DISK_internal_file_handle_ (lsocks_write_fd,
1089 &lsocks_write, sizeof (HANDLE)); 1098 &lsocks_write,
1090 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle 1099 sizeof (HANDLE));
1091 (lsocks_pipe, GNUNET_DISK_PIPE_END_READ), 1100 GNUNET_DISK_internal_file_handle_ (
1092 &lsocks_read, sizeof (HANDLE)); 1101 GNUNET_DISK_pipe_handle (lsocks_pipe, GNUNET_DISK_PIPE_END_READ),
1102 &lsocks_read,
1103 sizeof (HANDLE));
1093 } 1104 }
1094 else 1105 else
1095 { 1106 {
@@ -1103,7 +1114,7 @@ start_process (int pipe_control,
1103 GNUNET_asprintf (&our_env[env_off++], "%s=", GNUNET_OS_CONTROL_PIPE); 1114 GNUNET_asprintf (&our_env[env_off++], "%s=", GNUNET_OS_CONTROL_PIPE);
1104 GNUNET_asprintf (&our_env[env_off++], "%p", childpipe_read_handle); 1115 GNUNET_asprintf (&our_env[env_off++], "%p", childpipe_read_handle);
1105 } 1116 }
1106 if ( (lsocks != NULL) && (lsocks[0] != INVALID_SOCKET)) 1117 if ((lsocks != NULL) && (lsocks[0] != INVALID_SOCKET))
1107 { 1118 {
1108 /*This will tell the child that we're going to send lsocks over the pipe*/ 1119 /*This will tell the child that we're going to send lsocks over the pipe*/
1109 GNUNET_asprintf (&our_env[env_off++], "%s=", "GNUNET_OS_READ_LSOCKS"); 1120 GNUNET_asprintf (&our_env[env_off++], "%s=", "GNUNET_OS_READ_LSOCKS");
@@ -1115,10 +1126,14 @@ start_process (int pipe_control,
1115 GNUNET_free_non_null (our_env[--env_off]); 1126 GNUNET_free_non_null (our_env[--env_off]);
1116 1127
1117 wpath_len = 0; 1128 wpath_len = 0;
1118 if (NULL == (wpath = u8_to_u16 ((uint8_t *) path, 1 + strlen (path), NULL, &wpath_len))) 1129 if (NULL ==
1130 (wpath =
1131 u8_to_u16 ((uint8_t *) path, 1 + strlen (path), NULL, &wpath_len)))
1119 { 1132 {
1120 LOG (GNUNET_ERROR_TYPE_DEBUG, 1133 LOG (GNUNET_ERROR_TYPE_DEBUG,
1121 "Failed to convert `%s' from UTF-8 to UTF-16: %d\n", path, errno); 1134 "Failed to convert `%s' from UTF-8 to UTF-16: %d\n",
1135 path,
1136 errno);
1122 GNUNET_free (env_block); 1137 GNUNET_free (env_block);
1123 GNUNET_free (cmd); 1138 GNUNET_free (cmd);
1124 if (lsocks_pipe) 1139 if (lsocks_pipe)
@@ -1132,7 +1147,8 @@ start_process (int pipe_control,
1132 } 1147 }
1133 1148
1134 wcmd_len = 0; 1149 wcmd_len = 0;
1135 if (NULL == (wcmd = u8_to_u16 ((uint8_t *) cmd, 1 + strlen (cmd), NULL, &wcmd_len))) 1150 if (NULL ==
1151 (wcmd = u8_to_u16 ((uint8_t *) cmd, 1 + strlen (cmd), NULL, &wcmd_len)))
1136 { 1152 {
1137 LOG (GNUNET_ERROR_TYPE_DEBUG, 1153 LOG (GNUNET_ERROR_TYPE_DEBUG,
1138 "Failed to convert `%s' from UTF-8 to UTF-16: %d\n", 1154 "Failed to convert `%s' from UTF-8 to UTF-16: %d\n",
@@ -1153,15 +1169,29 @@ start_process (int pipe_control,
1153 1169
1154 create_no_window = 0; 1170 create_no_window = 0;
1155 { 1171 {
1156 HANDLE console_input = CreateFile ("CONIN$", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); 1172 HANDLE console_input = CreateFile ("CONIN$",
1173 GENERIC_READ,
1174 FILE_SHARE_READ | FILE_SHARE_WRITE,
1175 NULL,
1176 OPEN_EXISTING,
1177 0,
1178 NULL);
1157 if (INVALID_HANDLE_VALUE == console_input) 1179 if (INVALID_HANDLE_VALUE == console_input)
1158 create_no_window = CREATE_NO_WINDOW; 1180 create_no_window = CREATE_NO_WINDOW;
1159 else 1181 else
1160 CloseHandle (console_input); 1182 CloseHandle (console_input);
1161 } 1183 }
1162 1184
1163 bresult = CreateProcessW (wpath, wcmd, NULL, NULL, GNUNET_YES, 1185 bresult = CreateProcessW (wpath,
1164 create_no_window | CREATE_SUSPENDED, env_block, NULL, &start, &proc); 1186 wcmd,
1187 NULL,
1188 NULL,
1189 GNUNET_YES,
1190 create_no_window | CREATE_SUSPENDED,
1191 env_block,
1192 NULL,
1193 &start,
1194 &proc);
1165 error_code = GetLastError (); 1195 error_code = GetLastError ();
1166 1196
1167 if ((NULL == pipe_stdin) && (stdih)) 1197 if ((NULL == pipe_stdin) && (stdih))
@@ -1174,7 +1204,7 @@ start_process (int pipe_control,
1174 if (stdeh) 1204 if (stdeh)
1175 SetHandleInformation (stdeh, HANDLE_FLAG_INHERIT, stdef); 1205 SetHandleInformation (stdeh, HANDLE_FLAG_INHERIT, stdef);
1176 1206
1177 if (!bresult) 1207 if (! bresult)
1178 LOG (GNUNET_ERROR_TYPE_ERROR, 1208 LOG (GNUNET_ERROR_TYPE_ERROR,
1179 "CreateProcess(%s, %s) failed: %lu\n", 1209 "CreateProcess(%s, %s) failed: %lu\n",
1180 path, 1210 path,
@@ -1190,7 +1220,7 @@ start_process (int pipe_control,
1190 GNUNET_DISK_file_close (childpipe_read); 1220 GNUNET_DISK_file_close (childpipe_read);
1191 } 1221 }
1192 1222
1193 if (!bresult) 1223 if (! bresult)
1194 { 1224 {
1195 if (GNUNET_YES == pipe_control) 1225 if (GNUNET_YES == pipe_control)
1196 { 1226 {
@@ -1212,7 +1242,7 @@ start_process (int pipe_control,
1212 ResumeThread (proc.hThread); 1242 ResumeThread (proc.hThread);
1213 CloseHandle (proc.hThread); 1243 CloseHandle (proc.hThread);
1214 1244
1215 if ( (NULL == lsocks) || (INVALID_SOCKET == lsocks[0]) ) 1245 if ((NULL == lsocks) || (INVALID_SOCKET == lsocks[0]))
1216 return gnunet_proc; 1246 return gnunet_proc;
1217 1247
1218 GNUNET_DISK_pipe_close_end (lsocks_pipe, GNUNET_DISK_PIPE_END_READ); 1248 GNUNET_DISK_pipe_close_end (lsocks_pipe, GNUNET_DISK_PIPE_END_READ);
@@ -1227,25 +1257,29 @@ start_process (int pipe_control,
1227 unsigned int i; 1257 unsigned int i;
1228 1258
1229 /* Tell the number of sockets */ 1259 /* Tell the number of sockets */
1230 for (count = 0; lsocks && lsocks[count] != INVALID_SOCKET; count++); 1260 for (count = 0; lsocks && lsocks[count] != INVALID_SOCKET; count++)
1261 ;
1231 1262
1232 wrote = GNUNET_DISK_file_write (lsocks_write_fd, &count, sizeof (count)); 1263 wrote = GNUNET_DISK_file_write (lsocks_write_fd, &count, sizeof (count));
1233 if (sizeof (count) != wrote) 1264 if (sizeof (count) != wrote)
1234 { 1265 {
1235 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1266 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1236 "Failed to write %u count bytes to the child: %lu\n", 1267 "Failed to write %u count bytes to the child: %lu\n",
1237 sizeof (count), GetLastError ()); 1268 sizeof (count),
1269 GetLastError ());
1238 break; 1270 break;
1239 } 1271 }
1240 for (i = 0; lsocks && lsocks[i] != INVALID_SOCKET; i++) 1272 for (i = 0; lsocks && lsocks[i] != INVALID_SOCKET; i++)
1241 { 1273 {
1242 WSAPROTOCOL_INFOA pi; 1274 WSAPROTOCOL_INFOA pi;
1243 /* Get a socket duplication info */ 1275 /* Get a socket duplication info */
1244 if (SOCKET_ERROR == WSADuplicateSocketA (lsocks[i], gnunet_proc->pid, &pi)) 1276 if (SOCKET_ERROR ==
1277 WSADuplicateSocketA (lsocks[i], gnunet_proc->pid, &pi))
1245 { 1278 {
1246 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1279 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1247 "Failed to duplicate an socket[%u]: %lu\n", i, 1280 "Failed to duplicate an socket[%u]: %lu\n",
1248 GetLastError ()); 1281 i,
1282 GetLastError ());
1249 break; 1283 break;
1250 } 1284 }
1251 /* Synchronous I/O is not nice, but we can't schedule this: 1285 /* Synchronous I/O is not nice, but we can't schedule this:
@@ -1261,8 +1295,10 @@ start_process (int pipe_control,
1261 if (sizeof (size) != wrote) 1295 if (sizeof (size) != wrote)
1262 { 1296 {
1263 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1297 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1264 "Failed to write %u size[%u] bytes to the child: %lu\n", 1298 "Failed to write %u size[%u] bytes to the child: %lu\n",
1265 sizeof (size), i, GetLastError ()); 1299 sizeof (size),
1300 i,
1301 GetLastError ());
1266 break; 1302 break;
1267 } 1303 }
1268 /* Finally! Send the data */ 1304 /* Finally! Send the data */
@@ -1270,8 +1306,10 @@ start_process (int pipe_control,
1270 if (sizeof (pi) != wrote) 1306 if (sizeof (pi) != wrote)
1271 { 1307 {
1272 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1308 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1273 "Failed to write %u socket[%u] bytes to the child: %lu\n", 1309 "Failed to write %u socket[%u] bytes to the child: %lu\n",
1274 sizeof (pi), i, GetLastError ()); 1310 sizeof (pi),
1311 i,
1312 GetLastError ());
1275 break; 1313 break;
1276 } 1314 }
1277 } 1315 }
@@ -1282,8 +1320,7 @@ start_process (int pipe_control,
1282 */ 1320 */
1283 wrote = GNUNET_DISK_file_write (lsocks_write_fd, &count, sizeof (count)); 1321 wrote = GNUNET_DISK_file_write (lsocks_write_fd, &count, sizeof (count));
1284 fail = 0; 1322 fail = 0;
1285 } 1323 } while (fail);
1286 while (fail);
1287 1324
1288 GNUNET_DISK_file_sync (lsocks_write_fd); 1325 GNUNET_DISK_file_sync (lsocks_write_fd);
1289 GNUNET_DISK_pipe_close (lsocks_pipe); 1326 GNUNET_DISK_pipe_close (lsocks_pipe);
@@ -1320,20 +1357,20 @@ start_process (int pipe_control,
1320struct GNUNET_OS_Process * 1357struct GNUNET_OS_Process *
1321GNUNET_OS_start_process_vap (int pipe_control, 1358GNUNET_OS_start_process_vap (int pipe_control,
1322 enum GNUNET_OS_InheritStdioFlags std_inheritance, 1359 enum GNUNET_OS_InheritStdioFlags std_inheritance,
1323 struct GNUNET_DISK_PipeHandle *pipe_stdin, 1360 struct GNUNET_DISK_PipeHandle *pipe_stdin,
1324 struct GNUNET_DISK_PipeHandle *pipe_stdout, 1361 struct GNUNET_DISK_PipeHandle *pipe_stdout,
1325 struct GNUNET_DISK_PipeHandle *pipe_stderr, 1362 struct GNUNET_DISK_PipeHandle *pipe_stderr,
1326 const char *filename, 1363 const char *filename,
1327 char *const argv[]) 1364 char *const argv[])
1328{ 1365{
1329 return start_process (pipe_control, 1366 return start_process (pipe_control,
1330 std_inheritance, 1367 std_inheritance,
1331 pipe_stdin, 1368 pipe_stdin,
1332 pipe_stdout, 1369 pipe_stdout,
1333 pipe_stderr, 1370 pipe_stderr,
1334 NULL, 1371 NULL,
1335 filename, 1372 filename,
1336 argv); 1373 argv);
1337} 1374}
1338 1375
1339 1376
@@ -1352,10 +1389,11 @@ GNUNET_OS_start_process_vap (int pipe_control,
1352struct GNUNET_OS_Process * 1389struct GNUNET_OS_Process *
1353GNUNET_OS_start_process_va (int pipe_control, 1390GNUNET_OS_start_process_va (int pipe_control,
1354 enum GNUNET_OS_InheritStdioFlags std_inheritance, 1391 enum GNUNET_OS_InheritStdioFlags std_inheritance,
1355 struct GNUNET_DISK_PipeHandle *pipe_stdin, 1392 struct GNUNET_DISK_PipeHandle *pipe_stdin,
1356 struct GNUNET_DISK_PipeHandle *pipe_stdout, 1393 struct GNUNET_DISK_PipeHandle *pipe_stdout,
1357 struct GNUNET_DISK_PipeHandle *pipe_stderr, 1394 struct GNUNET_DISK_PipeHandle *pipe_stderr,
1358 const char *filename, va_list va) 1395 const char *filename,
1396 va_list va)
1359{ 1397{
1360 struct GNUNET_OS_Process *ret; 1398 struct GNUNET_OS_Process *ret;
1361 va_list ap; 1399 va_list ap;
@@ -1375,11 +1413,11 @@ GNUNET_OS_start_process_va (int pipe_control,
1375 va_end (ap); 1413 va_end (ap);
1376 ret = GNUNET_OS_start_process_vap (pipe_control, 1414 ret = GNUNET_OS_start_process_vap (pipe_control,
1377 std_inheritance, 1415 std_inheritance,
1378 pipe_stdin, 1416 pipe_stdin,
1379 pipe_stdout, 1417 pipe_stdout,
1380 pipe_stderr, 1418 pipe_stderr,
1381 filename, 1419 filename,
1382 argv); 1420 argv);
1383 GNUNET_free (argv); 1421 GNUNET_free (argv);
1384 return ret; 1422 return ret;
1385} 1423}
@@ -1399,10 +1437,11 @@ GNUNET_OS_start_process_va (int pipe_control,
1399struct GNUNET_OS_Process * 1437struct GNUNET_OS_Process *
1400GNUNET_OS_start_process (int pipe_control, 1438GNUNET_OS_start_process (int pipe_control,
1401 enum GNUNET_OS_InheritStdioFlags std_inheritance, 1439 enum GNUNET_OS_InheritStdioFlags std_inheritance,
1402 struct GNUNET_DISK_PipeHandle *pipe_stdin, 1440 struct GNUNET_DISK_PipeHandle *pipe_stdin,
1403 struct GNUNET_DISK_PipeHandle *pipe_stdout, 1441 struct GNUNET_DISK_PipeHandle *pipe_stdout,
1404 struct GNUNET_DISK_PipeHandle *pipe_stderr, 1442 struct GNUNET_DISK_PipeHandle *pipe_stderr,
1405 const char *filename, ...) 1443 const char *filename,
1444 ...)
1406{ 1445{
1407 struct GNUNET_OS_Process *ret; 1446 struct GNUNET_OS_Process *ret;
1408 va_list ap; 1447 va_list ap;
@@ -1411,7 +1450,7 @@ GNUNET_OS_start_process (int pipe_control,
1411 ret = GNUNET_OS_start_process_va (pipe_control, 1450 ret = GNUNET_OS_start_process_va (pipe_control,
1412 std_inheritance, 1451 std_inheritance,
1413 pipe_stdin, 1452 pipe_stdin,
1414 pipe_stdout, 1453 pipe_stdout,
1415 pipe_stderr, 1454 pipe_stderr,
1416 filename, 1455 filename,
1417 ap); 1456 ap);
@@ -1437,18 +1476,18 @@ GNUNET_OS_start_process (int pipe_control,
1437struct GNUNET_OS_Process * 1476struct GNUNET_OS_Process *
1438GNUNET_OS_start_process_v (int pipe_control, 1477GNUNET_OS_start_process_v (int pipe_control,
1439 enum GNUNET_OS_InheritStdioFlags std_inheritance, 1478 enum GNUNET_OS_InheritStdioFlags std_inheritance,
1440 const SOCKTYPE *lsocks, 1479 const SOCKTYPE *lsocks,
1441 const char *filename, 1480 const char *filename,
1442 char *const argv[]) 1481 char *const argv[])
1443{ 1482{
1444 return start_process (pipe_control, 1483 return start_process (pipe_control,
1445 std_inheritance, 1484 std_inheritance,
1446 NULL,
1447 NULL,
1448 NULL, 1485 NULL,
1449 lsocks, 1486 NULL,
1450 filename, 1487 NULL,
1451 argv); 1488 lsocks,
1489 filename,
1490 argv);
1452} 1491}
1453 1492
1454 1493
@@ -1473,8 +1512,9 @@ GNUNET_OS_start_process_v (int pipe_control,
1473struct GNUNET_OS_Process * 1512struct GNUNET_OS_Process *
1474GNUNET_OS_start_process_s (int pipe_control, 1513GNUNET_OS_start_process_s (int pipe_control,
1475 unsigned int std_inheritance, 1514 unsigned int std_inheritance,
1476 const SOCKTYPE * lsocks, 1515 const SOCKTYPE *lsocks,
1477 const char *filename, ...) 1516 const char *filename,
1517 ...)
1478{ 1518{
1479 va_list ap; 1519 va_list ap;
1480 char **argv; 1520 char **argv;
@@ -1502,29 +1542,28 @@ GNUNET_OS_start_process_s (int pipe_control,
1502 { 1542 {
1503 if ('"' == *rpos) 1543 if ('"' == *rpos)
1504 { 1544 {
1505 if (1 == quote_on) 1545 if (1 == quote_on)
1506 quote_on = 0; 1546 quote_on = 0;
1507 else 1547 else
1508 quote_on = 1; 1548 quote_on = 1;
1509 } 1549 }
1510 if ( (' ' == *rpos) && (0 == quote_on) ) 1550 if ((' ' == *rpos) && (0 == quote_on))
1511 { 1551 {
1512 if (NULL != last) 1552 if (NULL != last)
1513 argv_size++; 1553 argv_size++;
1514 last = NULL; 1554 last = NULL;
1515 rpos++; 1555 rpos++;
1516 while (' ' == *rpos) 1556 while (' ' == *rpos)
1517 rpos++; 1557 rpos++;
1518 } 1558 }
1519 if ( (NULL == last) && ('\0' != *rpos) ) // FIXME: == or !=? 1559 if ((NULL == last) && ('\0' != *rpos)) // FIXME: == or !=?
1520 last = rpos; 1560 last = rpos;
1521 if ('\0' != *rpos) 1561 if ('\0' != *rpos)
1522 rpos++; 1562 rpos++;
1523 } 1563 }
1524 if (NULL != last) 1564 if (NULL != last)
1525 argv_size++; 1565 argv_size++;
1526 } 1566 } while (NULL != (arg = (va_arg (ap, const char *))));
1527 while (NULL != (arg = (va_arg (ap, const char*))));
1528 va_end (ap); 1567 va_end (ap);
1529 1568
1530 argv = GNUNET_malloc (argv_size * sizeof (char *)); 1569 argv = GNUNET_malloc (argv_size * sizeof (char *));
@@ -1541,47 +1580,49 @@ GNUNET_OS_start_process_s (int pipe_control,
1541 { 1580 {
1542 if ('"' == *pos) 1581 if ('"' == *pos)
1543 { 1582 {
1544 if (1 == quote_on) 1583 if (1 == quote_on)
1545 quote_on = 0; 1584 quote_on = 0;
1546 else 1585 else
1547 quote_on = 1; 1586 quote_on = 1;
1548 } 1587 }
1549 if ( (' ' == *pos) && (0 == quote_on) ) 1588 if ((' ' == *pos) && (0 == quote_on))
1550 { 1589 {
1551 *pos = '\0'; 1590 *pos = '\0';
1552 if (NULL != last) 1591 if (NULL != last)
1553 argv[argv_size++] = GNUNET_strdup (last); 1592 argv[argv_size++] = GNUNET_strdup (last);
1554 last = NULL; 1593 last = NULL;
1555 pos++; 1594 pos++;
1556 while (' ' == *pos) 1595 while (' ' == *pos)
1557 pos++; 1596 pos++;
1558 } 1597 }
1559 if ( (NULL == last) && ('\0' != *pos)) // FIXME: == or !=? 1598 if ((NULL == last) && ('\0' != *pos)) // FIXME: == or !=?
1560 last = pos; 1599 last = pos;
1561 if ('\0' != *pos) 1600 if ('\0' != *pos)
1562 pos++; 1601 pos++;
1563 } 1602 }
1564 if (NULL != last) 1603 if (NULL != last)
1565 argv[argv_size++] = GNUNET_strdup (last); 1604 argv[argv_size++] = GNUNET_strdup (last);
1566 last = NULL; 1605 last = NULL;
1567 GNUNET_free (cp); 1606 GNUNET_free (cp);
1568 } 1607 } while (NULL != (arg = (va_arg (ap, const char *))));
1569 while (NULL != (arg = (va_arg (ap, const char*))));
1570 va_end (ap); 1608 va_end (ap);
1571 argv[argv_size] = NULL; 1609 argv[argv_size] = NULL;
1572 1610
1573 for(i = 0; i < argv_size; i++) 1611 for (i = 0; i < argv_size; i++)
1574 { 1612 {
1575 len = strlen (argv[i]); 1613 len = strlen (argv[i]);
1576 if ( (argv[i][0] == '"') && (argv[i][len-1] == '"')) 1614 if ((argv[i][0] == '"') && (argv[i][len - 1] == '"'))
1577 { 1615 {
1578 memmove (&argv[i][0], &argv[i][1], len - 2); 1616 memmove (&argv[i][0], &argv[i][1], len - 2);
1579 argv[i][len-2] = '\0'; 1617 argv[i][len - 2] = '\0';
1580 } 1618 }
1581 } 1619 }
1582 binary_path = argv[0]; 1620 binary_path = argv[0];
1583 proc = GNUNET_OS_start_process_v (pipe_control, std_inheritance, lsocks, 1621 proc = GNUNET_OS_start_process_v (pipe_control,
1584 binary_path, argv); 1622 std_inheritance,
1623 lsocks,
1624 binary_path,
1625 argv);
1585 while (argv_size > 0) 1626 while (argv_size > 0)
1586 GNUNET_free (argv[--argv_size]); 1627 GNUNET_free (argv[--argv_size]);
1587 GNUNET_free (argv); 1628 GNUNET_free (argv);
@@ -1613,8 +1654,7 @@ process_status (struct GNUNET_OS_Process *proc,
1613 ret = waitpid (proc->pid, &status, options); 1654 ret = waitpid (proc->pid, &status, options);
1614 if (ret < 0) 1655 if (ret < 0)
1615 { 1656 {
1616 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, 1657 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid");
1617 "waitpid");
1618 return GNUNET_SYSERR; 1658 return GNUNET_SYSERR;
1619 } 1659 }
1620 if (0 == ret) 1660 if (0 == ret)
@@ -1657,7 +1697,7 @@ process_status (struct GNUNET_OS_Process *proc,
1657 } 1697 }
1658#else 1698#else
1659#ifndef WNOHANG 1699#ifndef WNOHANG
1660#define WNOHANG 42 /* just a flag for W32, purely internal at this point */ 1700#define WNOHANG 42 /* just a flag for W32, purely internal at this point */
1661#endif 1701#endif
1662 1702
1663 HANDLE h; 1703 HANDLE h;
@@ -1669,7 +1709,8 @@ process_status (struct GNUNET_OS_Process *proc,
1669 { 1709 {
1670 LOG (GNUNET_ERROR_TYPE_WARNING, 1710 LOG (GNUNET_ERROR_TYPE_WARNING,
1671 "Invalid process information {%d, %08X}\n", 1711 "Invalid process information {%d, %08X}\n",
1672 ret, h); 1712 ret,
1713 h);
1673 return GNUNET_SYSERR; 1714 return GNUNET_SYSERR;
1674 } 1715 }
1675 if (h == NULL) 1716 if (h == NULL)
@@ -1720,10 +1761,7 @@ GNUNET_OS_process_status (struct GNUNET_OS_Process *proc,
1720 enum GNUNET_OS_ProcessStatusType *type, 1761 enum GNUNET_OS_ProcessStatusType *type,
1721 unsigned long *code) 1762 unsigned long *code)
1722{ 1763{
1723 return process_status (proc, 1764 return process_status (proc, type, code, WNOHANG);
1724 type,
1725 code,
1726 WNOHANG);
1727} 1765}
1728 1766
1729 1767
@@ -1741,10 +1779,7 @@ GNUNET_OS_process_wait_status (struct GNUNET_OS_Process *proc,
1741 enum GNUNET_OS_ProcessStatusType *type, 1779 enum GNUNET_OS_ProcessStatusType *type,
1742 unsigned long *code) 1780 unsigned long *code)
1743{ 1781{
1744 return process_status (proc, 1782 return process_status (proc, type, code, 0);
1745 type,
1746 code,
1747 0);
1748} 1783}
1749 1784
1750 1785
@@ -1765,12 +1800,11 @@ GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc)
1765 pid_t pid = proc->pid; 1800 pid_t pid = proc->pid;
1766 pid_t ret; 1801 pid_t ret;
1767 1802
1768 while ( (pid != (ret = waitpid (pid, NULL, 0))) && 1803 while ((pid != (ret = waitpid (pid, NULL, 0))) && (EINTR == errno))
1769 (EINTR == errno) ) ; 1804 ;
1770 if (pid != ret) 1805 if (pid != ret)
1771 { 1806 {
1772 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, 1807 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid");
1773 "waitpid");
1774 return GNUNET_SYSERR; 1808 return GNUNET_SYSERR;
1775 } 1809 }
1776 return GNUNET_OK; 1810 return GNUNET_OK;
@@ -1782,7 +1816,8 @@ GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc)
1782 { 1816 {
1783 LOG (GNUNET_ERROR_TYPE_WARNING, 1817 LOG (GNUNET_ERROR_TYPE_WARNING,
1784 "Invalid process information {%d, %08X}\n", 1818 "Invalid process information {%d, %08X}\n",
1785 proc->pid, h); 1819 proc->pid,
1820 h);
1786 return GNUNET_SYSERR; 1821 return GNUNET_SYSERR;
1787 } 1822 }
1788 if (NULL == h) 1823 if (NULL == h)
@@ -1890,9 +1925,7 @@ cmd_read (void *cls)
1890 1925
1891 cmd->rtask = NULL; 1926 cmd->rtask = NULL;
1892 tc = GNUNET_SCHEDULER_get_task_context (); 1927 tc = GNUNET_SCHEDULER_get_task_context ();
1893 if (GNUNET_YES != 1928 if (GNUNET_YES != GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, cmd->r))
1894 GNUNET_NETWORK_fdset_handle_isset (tc->read_ready,
1895 cmd->r))
1896 { 1929 {
1897 /* timeout */ 1930 /* timeout */
1898 proc = cmd->proc; 1931 proc = cmd->proc;
@@ -1901,8 +1934,8 @@ cmd_read (void *cls)
1901 return; 1934 return;
1902 } 1935 }
1903 ret = GNUNET_DISK_file_read (cmd->r, 1936 ret = GNUNET_DISK_file_read (cmd->r,
1904 &cmd->buf[cmd->off], 1937 &cmd->buf[cmd->off],
1905 sizeof (cmd->buf) - cmd->off); 1938 sizeof (cmd->buf) - cmd->off);
1906 if (ret <= 0) 1939 if (ret <= 0)
1907 { 1940 {
1908 if ((cmd->off > 0) && (cmd->off < sizeof (cmd->buf))) 1941 if ((cmd->off > 0) && (cmd->off < sizeof (cmd->buf)))
@@ -1925,11 +1958,12 @@ cmd_read (void *cls)
1925 cmd->off -= (end + 1 - cmd->buf); 1958 cmd->off -= (end + 1 - cmd->buf);
1926 end = memchr (cmd->buf, '\n', cmd->off); 1959 end = memchr (cmd->buf, '\n', cmd->off);
1927 } 1960 }
1928 cmd->rtask 1961 cmd->rtask =
1929 = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining 1962 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining (
1930 (cmd->timeout), 1963 cmd->timeout),
1931 cmd->r, 1964 cmd->r,
1932 &cmd_read, cmd); 1965 &cmd_read,
1966 cmd);
1933} 1967}
1934 1968
1935 1969
@@ -1956,15 +1990,13 @@ GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc,
1956 struct GNUNET_DISK_PipeHandle *opipe; 1990 struct GNUNET_DISK_PipeHandle *opipe;
1957 va_list ap; 1991 va_list ap;
1958 1992
1959 opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, 1993 opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
1960 GNUNET_NO, GNUNET_YES);
1961 if (NULL == opipe) 1994 if (NULL == opipe)
1962 return NULL; 1995 return NULL;
1963 va_start (ap, binary); 1996 va_start (ap, binary);
1964 /* redirect stdout, don't inherit stderr/stdin */ 1997 /* redirect stdout, don't inherit stderr/stdin */
1965 eip = GNUNET_OS_start_process_va (GNUNET_NO, 0, NULL, 1998 eip =
1966 opipe, NULL, binary, 1999 GNUNET_OS_start_process_va (GNUNET_NO, 0, NULL, opipe, NULL, binary, ap);
1967 ap);
1968 va_end (ap); 2000 va_end (ap);
1969 if (NULL == eip) 2001 if (NULL == eip)
1970 { 2002 {
@@ -1978,12 +2010,8 @@ GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc,
1978 cmd->opipe = opipe; 2010 cmd->opipe = opipe;
1979 cmd->proc = proc; 2011 cmd->proc = proc;
1980 cmd->proc_cls = proc_cls; 2012 cmd->proc_cls = proc_cls;
1981 cmd->r = GNUNET_DISK_pipe_handle (opipe, 2013 cmd->r = GNUNET_DISK_pipe_handle (opipe, GNUNET_DISK_PIPE_END_READ);
1982 GNUNET_DISK_PIPE_END_READ); 2014 cmd->rtask = GNUNET_SCHEDULER_add_read_file (timeout, cmd->r, &cmd_read, cmd);
1983 cmd->rtask = GNUNET_SCHEDULER_add_read_file (timeout,
1984 cmd->r,
1985 &cmd_read,
1986 cmd);
1987 return cmd; 2015 return cmd;
1988} 2016}
1989 2017
diff --git a/src/util/perf_crypto_asymmetric.c b/src/util/perf_crypto_asymmetric.c
index a2cb3a6ce..f42706bda 100644
--- a/src/util/perf_crypto_asymmetric.c
+++ b/src/util/perf_crypto_asymmetric.c
@@ -49,7 +49,7 @@ log_duration (const char *cryptosystem,
49 sprintf (s, "%6s %15s", cryptosystem, description); 49 sprintf (s, "%6s %15s", cryptosystem, description);
50 t = GNUNET_TIME_absolute_get_duration (start); 50 t = GNUNET_TIME_absolute_get_duration (start);
51 t = GNUNET_TIME_relative_divide (t, l); 51 t = GNUNET_TIME_relative_divide (t, l);
52 FPRINTF (stdout, 52 fprintf (stdout,
53 "%s: %10s\n", 53 "%s: %10s\n",
54 s, 54 s,
55 GNUNET_STRINGS_relative_time_to_string (t, 55 GNUNET_STRINGS_relative_time_to_string (t,
diff --git a/src/util/perf_crypto_ecc_dlog.c b/src/util/perf_crypto_ecc_dlog.c
index 59fa08d3a..2729241e2 100644
--- a/src/util/perf_crypto_ecc_dlog.c
+++ b/src/util/perf_crypto_ecc_dlog.c
@@ -130,7 +130,7 @@ main (int argc, char *argv[])
130 130
131 if (! gcry_check_version ("1.6.0")) 131 if (! gcry_check_version ("1.6.0"))
132 { 132 {
133 FPRINTF (stderr, 133 fprintf (stderr,
134 _ 134 _
135 ("libgcrypt has not the expected version (version %s is required).\n"), 135 ("libgcrypt has not the expected version (version %s is required).\n"),
136 "1.6.0"); 136 "1.6.0");
diff --git a/src/util/plugin.c b/src/util/plugin.c
index 4b922340d..19169f070 100644
--- a/src/util/plugin.c
+++ b/src/util/plugin.c
@@ -28,7 +28,7 @@
28#include <ltdl.h> 28#include <ltdl.h>
29#include "gnunet_util_lib.h" 29#include "gnunet_util_lib.h"
30 30
31#define LOG(kind,...) GNUNET_log_from (kind, "util-plugin", __VA_ARGS__) 31#define LOG(kind, ...) GNUNET_log_from (kind, "util-plugin", __VA_ARGS__)
32 32
33/** 33/**
34 * Linked list of active plugins. 34 * Linked list of active plugins.
@@ -82,8 +82,8 @@ plugin_init ()
82 err = lt_dlinit (); 82 err = lt_dlinit ();
83 if (err > 0) 83 if (err > 0)
84 { 84 {
85 FPRINTF (stderr, 85 fprintf (stderr,
86 _("Initialization of plugin mechanism failed: %s!\n"), 86 _ ("Initialization of plugin mechanism failed: %s!\n"),
87 lt_dlerror ()); 87 lt_dlerror ());
88 return; 88 return;
89 } 89 }
@@ -133,24 +133,21 @@ plugin_fini ()
133 * @return NULL if the symbol was not found 133 * @return NULL if the symbol was not found
134 */ 134 */
135static GNUNET_PLUGIN_Callback 135static GNUNET_PLUGIN_Callback
136resolve_function (struct PluginList *plug, 136resolve_function (struct PluginList *plug, const char *name)
137 const char *name)
138{ 137{
139 char *initName; 138 char *initName;
140 void *mptr; 139 void *mptr;
141 140
142 GNUNET_asprintf (&initName, 141 GNUNET_asprintf (&initName, "_%s_%s", plug->name, name);
143 "_%s_%s",
144 plug->name,
145 name);
146 mptr = lt_dlsym (plug->handle, &initName[1]); 142 mptr = lt_dlsym (plug->handle, &initName[1]);
147 if (NULL == mptr) 143 if (NULL == mptr)
148 mptr = lt_dlsym (plug->handle, initName); 144 mptr = lt_dlsym (plug->handle, initName);
149 if (NULL == mptr) 145 if (NULL == mptr)
150 LOG (GNUNET_ERROR_TYPE_ERROR, 146 LOG (GNUNET_ERROR_TYPE_ERROR,
151 _("`%s' failed to resolve method '%s' with error: %s\n"), 147 _ ("`%s' failed to resolve method '%s' with error: %s\n"),
152 "lt_dlsym", 148 "lt_dlsym",
153 &initName[1], lt_dlerror ()); 149 &initName[1],
150 lt_dlerror ());
154 GNUNET_free (initName); 151 GNUNET_free (initName);
155 return mptr; 152 return mptr;
156} 153}
@@ -214,7 +211,7 @@ GNUNET_PLUGIN_load (const char *library_name, void *arg)
214 GNUNET_PLUGIN_Callback init; 211 GNUNET_PLUGIN_Callback init;
215 void *ret; 212 void *ret;
216 213
217 if (!initialized) 214 if (! initialized)
218 { 215 {
219 initialized = GNUNET_YES; 216 initialized = GNUNET_YES;
220 plugin_init (); 217 plugin_init ();
@@ -223,9 +220,10 @@ GNUNET_PLUGIN_load (const char *library_name, void *arg)
223 if (libhandle == NULL) 220 if (libhandle == NULL)
224 { 221 {
225 LOG (GNUNET_ERROR_TYPE_ERROR, 222 LOG (GNUNET_ERROR_TYPE_ERROR,
226 _("`%s' failed for library `%s' with error: %s\n"), 223 _ ("`%s' failed for library `%s' with error: %s\n"),
227 "lt_dlopenext", 224 "lt_dlopenext",
228 library_name, lt_dlerror ()); 225 library_name,
226 lt_dlerror ());
229 return NULL; 227 return NULL;
230 } 228 }
231 plug = GNUNET_new (struct PluginList); 229 plug = GNUNET_new (struct PluginList);
@@ -255,8 +253,7 @@ GNUNET_PLUGIN_load (const char *library_name, void *arg)
255 * @return whatever the shutdown function returned 253 * @return whatever the shutdown function returned
256 */ 254 */
257void * 255void *
258GNUNET_PLUGIN_unload (const char *library_name, 256GNUNET_PLUGIN_unload (const char *library_name, void *arg)
259 void *arg)
260{ 257{
261 struct PluginList *pos; 258 struct PluginList *pos;
262 struct PluginList *prev; 259 struct PluginList *prev;
@@ -345,9 +342,9 @@ find_libraries (void *cls, const char *filename)
345 libname = slashpos + 1; 342 libname = slashpos + 1;
346 n = strlen (libname); 343 n = strlen (libname);
347 if (0 != strncmp (lac->basename, libname, strlen (lac->basename))) 344 if (0 != strncmp (lac->basename, libname, strlen (lac->basename)))
348 return GNUNET_OK; /* wrong name */ 345 return GNUNET_OK; /* wrong name */
349 if ((n > 3) && (0 == strcmp (&libname[n - 3], ".la"))) 346 if ((n > 3) && (0 == strcmp (&libname[n - 3], ".la")))
350 return GNUNET_OK; /* .la file */ 347 return GNUNET_OK; /* .la file */
351 basename = GNUNET_strdup (libname); 348 basename = GNUNET_strdup (libname);
352 if (NULL != (dot = strstr (basename, "."))) 349 if (NULL != (dot = strstr (basename, ".")))
353 *dot = '\0'; 350 *dot = '\0';
@@ -372,8 +369,10 @@ find_libraries (void *cls, const char *filename)
372 * @param cb_cls closure for @a cb 369 * @param cb_cls closure for @a cb
373 */ 370 */
374void 371void
375GNUNET_PLUGIN_load_all (const char *basename, void *arg, 372GNUNET_PLUGIN_load_all (const char *basename,
376 GNUNET_PLUGIN_LoaderCallback cb, void *cb_cls) 373 void *arg,
374 GNUNET_PLUGIN_LoaderCallback cb,
375 void *cb_cls)
377{ 376{
378 struct LoadAllContext lac; 377 struct LoadAllContext lac;
379 char *path; 378 char *path;
@@ -382,7 +381,7 @@ GNUNET_PLUGIN_load_all (const char *basename, void *arg,
382 if (NULL == path) 381 if (NULL == path)
383 { 382 {
384 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 383 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
385 _("Could not determine plugin installation path.\n")); 384 _ ("Could not determine plugin installation path.\n"));
386 return; 385 return;
387 } 386 }
388 lac.basename = basename; 387 lac.basename = basename;
diff --git a/src/util/program.c b/src/util/program.c
index 73beb8d57..77f4ea3ae 100644
--- a/src/util/program.c
+++ b/src/util/program.c
@@ -201,18 +201,18 @@ GNUNET_PROGRAM_run2 (int argc,
201 /* prepare */ 201 /* prepare */
202#if ENABLE_NLS 202#if ENABLE_NLS
203 if (NULL != pd->gettext_domain) 203 if (NULL != pd->gettext_domain)
204 {
205 setlocale (LC_ALL, "");
206 path = (NULL == pd->gettext_path)
207 ? GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR)
208 : GNUNET_strdup (pd->gettext_path);
209 if (NULL != path)
204 { 210 {
205 setlocale (LC_ALL, ""); 211 bindtextdomain (pd->gettext_domain, path);
206 path = (NULL == pd->gettext_path) 212 GNUNET_free (path);
207 ? GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR)
208 : GNUNET_strdup (pd->gettext_path);
209 if (NULL != path)
210 {
211 BINDTEXTDOMAIN (pd->gettext_domain, path);
212 GNUNET_free (path);
213 }
214 textdomain (pd->gettext_domain);
215 } 213 }
214 textdomain (pd->gettext_domain);
215 }
216#endif 216#endif
217 cnt = 0; 217 cnt = 0;
218 while (NULL != options[cnt].name) 218 while (NULL != options[cnt].name)
diff --git a/src/util/service.c b/src/util/service.c
index 73a73cbea..fba5a2f20 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -37,14 +37,13 @@
37#endif 37#endif
38 38
39 39
40#define LOG(kind,...) GNUNET_log_from (kind, "util-service", __VA_ARGS__) 40#define LOG(kind, ...) GNUNET_log_from (kind, "util-service", __VA_ARGS__)
41 41
42#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, \ 42#define LOG_STRERROR(kind, syscall) \
43 "util-service", \ 43 GNUNET_log_from_strerror (kind, "util-service", syscall)
44 syscall)
45 44
46#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file ( \ 45#define LOG_STRERROR_FILE(kind, syscall, filename) \
47 kind, "util-service", syscall, filename) 46 GNUNET_log_from_strerror_file (kind, "util-service", syscall, filename)
48 47
49 48
50/** 49/**
@@ -77,7 +76,6 @@ struct ServiceListenContext
77 * Task scheduled to do the listening. 76 * Task scheduled to do the listening.
78 */ 77 */
79 struct GNUNET_SCHEDULER_Task *listen_task; 78 struct GNUNET_SCHEDULER_Task *listen_task;
80
81}; 79};
82 80
83 81
@@ -363,8 +361,7 @@ struct GNUNET_SERVICE_Client
363static int 361static int
364have_non_monitor_clients (struct GNUNET_SERVICE_Handle *sh) 362have_non_monitor_clients (struct GNUNET_SERVICE_Handle *sh)
365{ 363{
366 for (struct GNUNET_SERVICE_Client *client = sh->clients_head; 364 for (struct GNUNET_SERVICE_Client *client = sh->clients_head; NULL != client;
367 NULL != client;
368 client = client->next) 365 client = client->next)
369 { 366 {
370 if (client->is_monitor) 367 if (client->is_monitor)
@@ -383,8 +380,7 @@ have_non_monitor_clients (struct GNUNET_SERVICE_Handle *sh)
383 * @param sr reason for suspending accepting connections 380 * @param sr reason for suspending accepting connections
384 */ 381 */
385static void 382static void
386do_suspend (struct GNUNET_SERVICE_Handle *sh, 383do_suspend (struct GNUNET_SERVICE_Handle *sh, enum SuspendReason sr)
387 enum SuspendReason sr)
388{ 384{
389 struct ServiceListenContext *slc; 385 struct ServiceListenContext *slc;
390 386
@@ -426,8 +422,7 @@ service_shutdown (void *cls)
426 break; 422 break;
427 case GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN: 423 case GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN:
428 if (0 == (sh->suspend_state & SUSPEND_STATE_SHUTDOWN)) 424 if (0 == (sh->suspend_state & SUSPEND_STATE_SHUTDOWN))
429 do_suspend (sh, 425 do_suspend (sh, SUSPEND_STATE_SHUTDOWN);
430 SUSPEND_STATE_SHUTDOWN);
431 if (GNUNET_NO == have_non_monitor_clients (sh)) 426 if (GNUNET_NO == have_non_monitor_clients (sh))
432 GNUNET_SERVICE_shutdown (sh); 427 GNUNET_SERVICE_shutdown (sh);
433 break; 428 break;
@@ -451,8 +446,7 @@ check_ipv4_listed (const struct GNUNET_STRINGS_IPv4NetworkPolicy *list,
451 if (NULL == list) 446 if (NULL == list)
452 return GNUNET_NO; 447 return GNUNET_NO;
453 i = 0; 448 i = 0;
454 while ( (0 != list[i].network.s_addr) || 449 while ((0 != list[i].network.s_addr) || (0 != list[i].netmask.s_addr))
455 (0 != list[i].netmask.s_addr) )
456 { 450 {
457 if ((add->s_addr & list[i].netmask.s_addr) == 451 if ((add->s_addr & list[i].netmask.s_addr) ==
458 (list[i].network.s_addr & list[i].netmask.s_addr)) 452 (list[i].network.s_addr & list[i].netmask.s_addr))
@@ -480,7 +474,7 @@ check_ipv6_listed (const struct GNUNET_STRINGS_IPv6NetworkPolicy *list,
480 if (NULL == list) 474 if (NULL == list)
481 return GNUNET_NO; 475 return GNUNET_NO;
482 i = 0; 476 i = 0;
483 NEXT: 477NEXT:
484 while (0 != GNUNET_is_zero (&list[i].network)) 478 while (0 != GNUNET_is_zero (&list[i].network))
485 { 479 {
486 for (j = 0; j < sizeof (struct in6_addr) / sizeof (int); j++) 480 for (j = 0; j < sizeof (struct in6_addr) / sizeof (int); j++)
@@ -518,22 +512,17 @@ do_send (void *cls)
518 client->send_task = NULL; 512 client->send_task = NULL;
519 buf = (const char *) client->msg; 513 buf = (const char *) client->msg;
520 left = ntohs (client->msg->size) - client->msg_pos; 514 left = ntohs (client->msg->size) - client->msg_pos;
521 ret = GNUNET_NETWORK_socket_send (client->sock, 515 ret = GNUNET_NETWORK_socket_send (client->sock, &buf[client->msg_pos], left);
522 &buf[client->msg_pos],
523 left);
524 GNUNET_assert (ret <= (ssize_t) left); 516 GNUNET_assert (ret <= (ssize_t) left);
525 if (0 == ret) 517 if (0 == ret)
526 { 518 {
527 LOG (GNUNET_ERROR_TYPE_DEBUG, 519 LOG (GNUNET_ERROR_TYPE_DEBUG, "no data send");
528 "no data send"); 520 GNUNET_MQ_inject_error (client->mq, GNUNET_MQ_ERROR_WRITE);
529 GNUNET_MQ_inject_error (client->mq,
530 GNUNET_MQ_ERROR_WRITE);
531 return; 521 return;
532 } 522 }
533 if (-1 == ret) 523 if (-1 == ret)
534 { 524 {
535 if ( (EAGAIN == errno) || 525 if ((EAGAIN == errno) || (EINTR == errno))
536 (EINTR == errno) )
537 { 526 {
538 /* ignore */ 527 /* ignore */
539 ret = 0; 528 ret = 0;
@@ -541,13 +530,11 @@ do_send (void *cls)
541 else 530 else
542 { 531 {
543 if (EPIPE != errno) 532 if (EPIPE != errno)
544 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 533 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send");
545 "send");
546 LOG (GNUNET_ERROR_TYPE_DEBUG, 534 LOG (GNUNET_ERROR_TYPE_DEBUG,
547 "socket send returned with error code %i", 535 "socket send returned with error code %i",
548 errno); 536 errno);
549 GNUNET_MQ_inject_error (client->mq, 537 GNUNET_MQ_inject_error (client->mq, GNUNET_MQ_ERROR_WRITE);
550 GNUNET_MQ_ERROR_WRITE);
551 return; 538 return;
552 } 539 }
553 } 540 }
@@ -559,11 +546,11 @@ do_send (void *cls)
559 if (left > (size_t) ret) 546 if (left > (size_t) ret)
560 { 547 {
561 GNUNET_assert (NULL == client->drop_task); 548 GNUNET_assert (NULL == client->drop_task);
562 client->send_task 549 client->send_task =
563 = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 550 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
564 client->sock, 551 client->sock,
565 &do_send, 552 &do_send,
566 client); 553 client);
567 return; 554 return;
568 } 555 }
569 GNUNET_MQ_impl_send_continue (client->mq); 556 GNUNET_MQ_impl_send_continue (client->mq);
@@ -595,11 +582,11 @@ service_mq_send (struct GNUNET_MQ_Handle *mq,
595 ntohs (msg->size)); 582 ntohs (msg->size));
596 client->msg = msg; 583 client->msg = msg;
597 client->msg_pos = 0; 584 client->msg_pos = 0;
598 client->send_task 585 client->send_task =
599 = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 586 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
600 client->sock, 587 client->sock,
601 &do_send, 588 &do_send,
602 client); 589 client);
603} 590}
604 591
605 592
@@ -610,8 +597,7 @@ service_mq_send (struct GNUNET_MQ_Handle *mq,
610 * @param impl_state state specific to the implementation 597 * @param impl_state state specific to the implementation
611 */ 598 */
612static void 599static void
613service_mq_cancel (struct GNUNET_MQ_Handle *mq, 600service_mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
614 void *impl_state)
615{ 601{
616 struct GNUNET_SERVICE_Client *client = impl_state; 602 struct GNUNET_SERVICE_Client *client = impl_state;
617 603
@@ -633,14 +619,12 @@ service_mq_cancel (struct GNUNET_MQ_Handle *mq,
633 * @param error error code 619 * @param error error code
634 */ 620 */
635static void 621static void
636service_mq_error_handler (void *cls, 622service_mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
637 enum GNUNET_MQ_Error error)
638{ 623{
639 struct GNUNET_SERVICE_Client *client = cls; 624 struct GNUNET_SERVICE_Client *client = cls;
640 struct GNUNET_SERVICE_Handle *sh = client->sh; 625 struct GNUNET_SERVICE_Handle *sh = client->sh;
641 626
642 if ( (GNUNET_MQ_ERROR_NO_MATCH == error) && 627 if ((GNUNET_MQ_ERROR_NO_MATCH == error) && (GNUNET_NO == sh->require_found))
643 (GNUNET_NO == sh->require_found) )
644 { 628 {
645 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 629 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
646 "No handler for message of type %u found\n", 630 "No handler for message of type %u found\n",
@@ -662,18 +646,20 @@ warn_no_client_continue (void *cls)
662{ 646{
663 struct GNUNET_SERVICE_Client *client = cls; 647 struct GNUNET_SERVICE_Client *client = cls;
664 648
665 GNUNET_break (0 != client->warn_type); /* type should never be 0 here, as we don't use 0 */ 649 GNUNET_break (
666 client->warn_task 650 0 !=
667 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 651 client->warn_type); /* type should never be 0 here, as we don't use 0 */
668 &warn_no_client_continue, 652 client->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
669 client); 653 &warn_no_client_continue,
670 LOG (GNUNET_ERROR_TYPE_WARNING, 654 client);
671 _ ( 655 LOG (
672 "Processing code for message of type %u did not call `GNUNET_SERVICE_client_continue' after %s\n"), 656 GNUNET_ERROR_TYPE_WARNING,
673 (unsigned int) client->warn_type, 657 _ (
674 GNUNET_STRINGS_relative_time_to_string ( 658 "Processing code for message of type %u did not call `GNUNET_SERVICE_client_continue' after %s\n"),
675 GNUNET_TIME_absolute_get_duration (client->warn_start), 659 (unsigned int) client->warn_type,
676 GNUNET_YES)); 660 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (
661 client->warn_start),
662 GNUNET_YES));
677} 663}
678 664
679 665
@@ -689,8 +675,7 @@ warn_no_client_continue (void *cls)
689 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the client was dropped 675 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the client was dropped
690 */ 676 */
691static int 677static int
692service_client_mst_cb (void *cls, 678service_client_mst_cb (void *cls, const struct GNUNET_MessageHeader *message)
693 const struct GNUNET_MessageHeader *message)
694{ 679{
695 struct GNUNET_SERVICE_Client *client = cls; 680 struct GNUNET_SERVICE_Client *client = cls;
696 681
@@ -703,12 +688,10 @@ service_client_mst_cb (void *cls,
703 client->warn_type = ntohs (message->type); 688 client->warn_type = ntohs (message->type);
704 client->warn_start = GNUNET_TIME_absolute_get (); 689 client->warn_start = GNUNET_TIME_absolute_get ();
705 GNUNET_assert (NULL == client->warn_task); 690 GNUNET_assert (NULL == client->warn_task);
706 client->warn_task 691 client->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
707 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 692 &warn_no_client_continue,
708 &warn_no_client_continue, 693 client);
709 client); 694 GNUNET_MQ_inject_message (client->mq, message);
710 GNUNET_MQ_inject_message (client->mq,
711 message);
712 if (NULL != client->drop_task) 695 if (NULL != client->drop_task)
713 return GNUNET_SYSERR; 696 return GNUNET_SYSERR;
714 return GNUNET_OK; 697 return GNUNET_OK;
@@ -728,10 +711,7 @@ service_client_recv (void *cls)
728 int ret; 711 int ret;
729 712
730 client->recv_task = NULL; 713 client->recv_task = NULL;
731 ret = GNUNET_MST_read (client->mst, 714 ret = GNUNET_MST_read (client->mst, client->sock, GNUNET_NO, GNUNET_YES);
732 client->sock,
733 GNUNET_NO,
734 GNUNET_YES);
735 if (GNUNET_SYSERR == ret) 715 if (GNUNET_SYSERR == ret)
736 { 716 {
737 /* client closed connection (or IO error) */ 717 /* client closed connection (or IO error) */
@@ -751,11 +731,11 @@ service_client_recv (void *cls)
751 if (NULL != client->recv_task) 731 if (NULL != client->recv_task)
752 return; 732 return;
753 /* MST needs more data, re-schedule read job */ 733 /* MST needs more data, re-schedule read job */
754 client->recv_task 734 client->recv_task =
755 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 735 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
756 client->sock, 736 client->sock,
757 &service_client_recv, 737 &service_client_recv,
758 client); 738 client);
759} 739}
760 740
761 741
@@ -773,9 +753,7 @@ start_client (struct GNUNET_SERVICE_Handle *sh,
773 struct GNUNET_SERVICE_Client *client; 753 struct GNUNET_SERVICE_Client *client;
774 754
775 client = GNUNET_new (struct GNUNET_SERVICE_Client); 755 client = GNUNET_new (struct GNUNET_SERVICE_Client);
776 GNUNET_CONTAINER_DLL_insert (sh->clients_head, 756 GNUNET_CONTAINER_DLL_insert (sh->clients_head, sh->clients_tail, client);
777 sh->clients_tail,
778 client);
779 client->sh = sh; 757 client->sh = sh;
780 client->sock = csock; 758 client->sock = csock;
781 client->mq = GNUNET_MQ_queue_for_callbacks (&service_mq_send, 759 client->mq = GNUNET_MQ_queue_for_callbacks (&service_mq_send,
@@ -785,19 +763,15 @@ start_client (struct GNUNET_SERVICE_Handle *sh,
785 sh->handlers, 763 sh->handlers,
786 &service_mq_error_handler, 764 &service_mq_error_handler,
787 client); 765 client);
788 client->mst = GNUNET_MST_create (&service_client_mst_cb, 766 client->mst = GNUNET_MST_create (&service_client_mst_cb, client);
789 client);
790 if (NULL != sh->connect_cb) 767 if (NULL != sh->connect_cb)
791 client->user_context = sh->connect_cb (sh->cb_cls, 768 client->user_context = sh->connect_cb (sh->cb_cls, client, client->mq);
792 client, 769 GNUNET_MQ_set_handlers_closure (client->mq, client->user_context);
793 client->mq); 770 client->recv_task =
794 GNUNET_MQ_set_handlers_closure (client->mq, 771 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
795 client->user_context); 772 client->sock,
796 client->recv_task 773 &service_client_recv,
797 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 774 client);
798 client->sock,
799 &service_client_recv,
800 client);
801} 775}
802 776
803 777
@@ -830,11 +804,9 @@ accept_client (void *cls)
830 if (NULL == sock) 804 if (NULL == sock)
831 { 805 {
832 if (EMFILE == errno) 806 if (EMFILE == errno)
833 do_suspend (sh, 807 do_suspend (sh, SUSPEND_STATE_EMFILE);
834 SUSPEND_STATE_EMFILE);
835 else if (EAGAIN != errno) 808 else if (EAGAIN != errno)
836 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 809 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "accept");
837 "accept");
838 break; 810 break;
839 } 811 }
840 switch (sa.ss_family) 812 switch (sa.ss_family)
@@ -842,26 +814,22 @@ accept_client (void *cls)
842 case AF_INET: 814 case AF_INET:
843 GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); 815 GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
844 v4 = (const struct sockaddr_in *) &sa; 816 v4 = (const struct sockaddr_in *) &sa;
845 ok = ( ( (NULL == sh->v4_allowed) || 817 ok = (((NULL == sh->v4_allowed) ||
846 (check_ipv4_listed (sh->v4_allowed, 818 (check_ipv4_listed (sh->v4_allowed, &v4->sin_addr))) &&
847 &v4->sin_addr))) && 819 ((NULL == sh->v4_denied) ||
848 ( (NULL == sh->v4_denied) || 820 (! check_ipv4_listed (sh->v4_denied, &v4->sin_addr))));
849 (! check_ipv4_listed (sh->v4_denied,
850 &v4->sin_addr)) ) );
851 break; 821 break;
852 case AF_INET6: 822 case AF_INET6:
853 GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); 823 GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
854 v6 = (const struct sockaddr_in6 *) &sa; 824 v6 = (const struct sockaddr_in6 *) &sa;
855 ok = ( ( (NULL == sh->v6_allowed) || 825 ok = (((NULL == sh->v6_allowed) ||
856 (check_ipv6_listed (sh->v6_allowed, 826 (check_ipv6_listed (sh->v6_allowed, &v6->sin6_addr))) &&
857 &v6->sin6_addr))) && 827 ((NULL == sh->v6_denied) ||
858 ( (NULL == sh->v6_denied) || 828 (! check_ipv6_listed (sh->v6_denied, &v6->sin6_addr))));
859 (! check_ipv6_listed (sh->v6_denied,
860 &v6->sin6_addr)) ) );
861 break; 829 break;
862#ifndef WINDOWS 830#ifndef WINDOWS
863 case AF_UNIX: 831 case AF_UNIX:
864 ok = GNUNET_OK; /* controlled using file-system ACL now */ 832 ok = GNUNET_OK; /* controlled using file-system ACL now */
865 break; 833 break;
866#endif 834#endif
867 default: 835 default:
@@ -874,26 +842,22 @@ accept_client (void *cls)
874 { 842 {
875 LOG (GNUNET_ERROR_TYPE_DEBUG, 843 LOG (GNUNET_ERROR_TYPE_DEBUG,
876 "Service rejected incoming connection from %s due to policy.\n", 844 "Service rejected incoming connection from %s due to policy.\n",
877 GNUNET_a2s ((const struct sockaddr *) &sa, 845 GNUNET_a2s ((const struct sockaddr *) &sa, addrlen));
878 addrlen)); 846 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
879 GNUNET_break (GNUNET_OK ==
880 GNUNET_NETWORK_socket_close (sock));
881 continue; 847 continue;
882 } 848 }
883 LOG (GNUNET_ERROR_TYPE_DEBUG, 849 LOG (GNUNET_ERROR_TYPE_DEBUG,
884 "Service accepted incoming connection from %s.\n", 850 "Service accepted incoming connection from %s.\n",
885 GNUNET_a2s ((const struct sockaddr *) &sa, 851 GNUNET_a2s ((const struct sockaddr *) &sa, addrlen));
886 addrlen)); 852 start_client (slc->sh, sock);
887 start_client (slc->sh,
888 sock);
889 } 853 }
890 if (0 != sh->suspend_state) 854 if (0 != sh->suspend_state)
891 return; 855 return;
892 slc->listen_task 856 slc->listen_task =
893 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 857 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
894 slc->listen_socket, 858 slc->listen_socket,
895 &accept_client, 859 &accept_client,
896 slc); 860 slc);
897} 861}
898 862
899 863
@@ -905,24 +869,22 @@ accept_client (void *cls)
905 * or #SUSPEND_STATE_NONE on first startup 869 * or #SUSPEND_STATE_NONE on first startup
906 */ 870 */
907static void 871static void
908do_resume (struct GNUNET_SERVICE_Handle *sh, 872do_resume (struct GNUNET_SERVICE_Handle *sh, enum SuspendReason sr)
909 enum SuspendReason sr)
910{ 873{
911 struct ServiceListenContext *slc; 874 struct ServiceListenContext *slc;
912 875
913 GNUNET_assert ( (SUSPEND_STATE_NONE == sr) || 876 GNUNET_assert ((SUSPEND_STATE_NONE == sr) || (0 != (sh->suspend_state & sr)));
914 (0 != (sh->suspend_state & sr)) );
915 sh->suspend_state -= sr; 877 sh->suspend_state -= sr;
916 if (SUSPEND_STATE_NONE != sh->suspend_state) 878 if (SUSPEND_STATE_NONE != sh->suspend_state)
917 return; 879 return;
918 for (slc = sh->slc_head; NULL != slc; slc = slc->next) 880 for (slc = sh->slc_head; NULL != slc; slc = slc->next)
919 { 881 {
920 GNUNET_assert (NULL == slc->listen_task); 882 GNUNET_assert (NULL == slc->listen_task);
921 slc->listen_task 883 slc->listen_task =
922 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 884 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
923 slc->listen_socket, 885 slc->listen_socket,
924 &accept_client, 886 &accept_client,
925 slc); 887 slc);
926 } 888 }
927} 889}
928 890
@@ -940,22 +902,18 @@ service_main (void *cls)
940 struct GNUNET_SERVICE_Handle *sh = cls; 902 struct GNUNET_SERVICE_Handle *sh = cls;
941 903
942 if (GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN != sh->options) 904 if (GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN != sh->options)
943 GNUNET_SCHEDULER_add_shutdown (&service_shutdown, 905 GNUNET_SCHEDULER_add_shutdown (&service_shutdown, sh);
944 sh); 906 do_resume (sh, SUSPEND_STATE_NONE);
945 do_resume (sh,
946 SUSPEND_STATE_NONE);
947 907
948 if (-1 != sh->ready_confirm_fd) 908 if (-1 != sh->ready_confirm_fd)
949 { 909 {
950 GNUNET_break (1 == WRITE (sh->ready_confirm_fd, ".", 1)); 910 GNUNET_break (1 == write (sh->ready_confirm_fd, ".", 1));
951 GNUNET_break (0 == CLOSE (sh->ready_confirm_fd)); 911 GNUNET_break (0 == close (sh->ready_confirm_fd));
952 sh->ready_confirm_fd = -1; 912 sh->ready_confirm_fd = -1;
953 } 913 }
954 914
955 if (NULL != sh->service_init_cb) 915 if (NULL != sh->service_init_cb)
956 sh->service_init_cb (sh->cb_cls, 916 sh->service_init_cb (sh->cb_cls, sh->cfg, sh);
957 sh->cfg,
958 sh);
959} 917}
960 918
961 919
@@ -975,9 +933,7 @@ process_acl4 (struct GNUNET_STRINGS_IPv4NetworkPolicy **ret,
975{ 933{
976 char *opt; 934 char *opt;
977 935
978 if (! GNUNET_CONFIGURATION_have_value (sh->cfg, 936 if (! GNUNET_CONFIGURATION_have_value (sh->cfg, sh->service_name, option))
979 sh->service_name,
980 option))
981 { 937 {
982 *ret = NULL; 938 *ret = NULL;
983 return GNUNET_OK; 939 return GNUNET_OK;
@@ -1018,9 +974,7 @@ process_acl6 (struct GNUNET_STRINGS_IPv6NetworkPolicy **ret,
1018{ 974{
1019 char *opt; 975 char *opt;
1020 976
1021 if (! GNUNET_CONFIGURATION_have_value (sh->cfg, 977 if (! GNUNET_CONFIGURATION_have_value (sh->cfg, sh->service_name, option))
1022 sh->service_name,
1023 option))
1024 { 978 {
1025 *ret = NULL; 979 *ret = NULL;
1026 return GNUNET_OK; 980 return GNUNET_OK;
@@ -1066,9 +1020,7 @@ add_unixpath (struct sockaddr **saddrs,
1066 1020
1067 un = GNUNET_new (struct sockaddr_un); 1021 un = GNUNET_new (struct sockaddr_un);
1068 un->sun_family = AF_UNIX; 1022 un->sun_family = AF_UNIX;
1069 GNUNET_strlcpy (un->sun_path, 1023 GNUNET_strlcpy (un->sun_path, unixpath, sizeof (un->sun_path));
1070 unixpath,
1071 sizeof (un->sun_path));
1072#ifdef LINUX 1024#ifdef LINUX
1073 if (GNUNET_YES == abstract) 1025 if (GNUNET_YES == abstract)
1074 un->sun_path[0] = '\0'; 1026 un->sun_path[0] = '\0';
@@ -1132,24 +1084,18 @@ get_server_addresses (const char *service_name,
1132 *addr_lens = NULL; 1084 *addr_lens = NULL;
1133 desc = NULL; 1085 desc = NULL;
1134 disablev6 = GNUNET_NO; 1086 disablev6 = GNUNET_NO;
1135 if ( (GNUNET_NO == 1087 if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
1136 GNUNET_NETWORK_test_pf (PF_INET6)) || 1088 (GNUNET_YES ==
1137 (GNUNET_YES == 1089 GNUNET_CONFIGURATION_get_value_yesno (cfg, service_name, "DISABLEV6")))
1138 GNUNET_CONFIGURATION_get_value_yesno (cfg,
1139 service_name,
1140 "DISABLEV6") ) )
1141 disablev6 = GNUNET_YES; 1090 disablev6 = GNUNET_YES;
1142 1091
1143 port = 0; 1092 port = 0;
1144 if (GNUNET_CONFIGURATION_have_value (cfg, 1093 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT"))
1145 service_name,
1146 "PORT"))
1147 { 1094 {
1148 if (GNUNET_OK != 1095 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
1149 GNUNET_CONFIGURATION_get_value_number (cfg, 1096 service_name,
1150 service_name, 1097 "PORT",
1151 "PORT", 1098 &port))
1152 &port))
1153 { 1099 {
1154 LOG (GNUNET_ERROR_TYPE_ERROR, 1100 LOG (GNUNET_ERROR_TYPE_ERROR,
1155 _ ("Require valid port number for service `%s' in configuration!\n"), 1101 _ ("Require valid port number for service `%s' in configuration!\n"),
@@ -1164,9 +1110,7 @@ get_server_addresses (const char *service_name,
1164 } 1110 }
1165 } 1111 }
1166 1112
1167 if (GNUNET_CONFIGURATION_have_value (cfg, 1113 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO"))
1168 service_name,
1169 "BINDTO"))
1170 { 1114 {
1171 GNUNET_break (GNUNET_OK == 1115 GNUNET_break (GNUNET_OK ==
1172 GNUNET_CONFIGURATION_get_value_string (cfg, 1116 GNUNET_CONFIGURATION_get_value_string (cfg,
@@ -1181,14 +1125,11 @@ get_server_addresses (const char *service_name,
1181 abstract = GNUNET_NO; 1125 abstract = GNUNET_NO;
1182#ifdef AF_UNIX 1126#ifdef AF_UNIX
1183 if ((GNUNET_YES == 1127 if ((GNUNET_YES ==
1184 GNUNET_CONFIGURATION_have_value (cfg, 1128 GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) &&
1185 service_name, 1129 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg,
1186 "UNIXPATH")) && 1130 service_name,
1187 (GNUNET_OK == 1131 "UNIXPATH",
1188 GNUNET_CONFIGURATION_get_value_filename (cfg, 1132 &unixpath)) &&
1189 service_name,
1190 "UNIXPATH",
1191 &unixpath)) &&
1192 (0 < strlen (unixpath))) 1133 (0 < strlen (unixpath)))
1193 { 1134 {
1194 /* probe UNIX support */ 1135 /* probe UNIX support */
@@ -1201,9 +1142,7 @@ get_server_addresses (const char *service_name,
1201 unixpath, 1142 unixpath,
1202 (unsigned long long) sizeof (s_un.sun_path)); 1143 (unsigned long long) sizeof (s_un.sun_path));
1203 unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath); 1144 unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath);
1204 LOG (GNUNET_ERROR_TYPE_INFO, 1145 LOG (GNUNET_ERROR_TYPE_INFO, _ ("Using `%s' instead\n"), unixpath);
1205 _ ("Using `%s' instead\n"),
1206 unixpath);
1207 } 1146 }
1208#ifdef LINUX 1147#ifdef LINUX
1209 abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1148 abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
@@ -1212,27 +1151,19 @@ get_server_addresses (const char *service_name,
1212 if (GNUNET_SYSERR == abstract) 1151 if (GNUNET_SYSERR == abstract)
1213 abstract = GNUNET_NO; 1152 abstract = GNUNET_NO;
1214#endif 1153#endif
1215 if ( (GNUNET_YES != abstract) && 1154 if ((GNUNET_YES != abstract) &&
1216 (GNUNET_OK != 1155 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (unixpath)))
1217 GNUNET_DISK_directory_create_for_file (unixpath)) ) 1156 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath);
1218 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
1219 "mkdir",
1220 unixpath);
1221 } 1157 }
1222 if (NULL != unixpath) 1158 if (NULL != unixpath)
1223 { 1159 {
1224 desc = GNUNET_NETWORK_socket_create (AF_UNIX, 1160 desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
1225 SOCK_STREAM,
1226 0);
1227 if (NULL == desc) 1161 if (NULL == desc)
1228 { 1162 {
1229 if ((ENOBUFS == errno) || 1163 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
1230 (ENOMEM == errno) ||
1231 (ENFILE == errno) ||
1232 (EACCES == errno)) 1164 (EACCES == errno))
1233 { 1165 {
1234 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, 1166 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
1235 "socket");
1236 GNUNET_free_non_null (hostname); 1167 GNUNET_free_non_null (hostname);
1237 GNUNET_free (unixpath); 1168 GNUNET_free (unixpath);
1238 return GNUNET_SYSERR; 1169 return GNUNET_SYSERR;
@@ -1241,14 +1172,13 @@ get_server_addresses (const char *service_name,
1241 _ ( 1172 _ (
1242 "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), 1173 "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
1243 service_name, 1174 service_name,
1244 STRERROR (errno)); 1175 strerror (errno));
1245 GNUNET_free (unixpath); 1176 GNUNET_free (unixpath);
1246 unixpath = NULL; 1177 unixpath = NULL;
1247 } 1178 }
1248 else 1179 else
1249 { 1180 {
1250 GNUNET_break (GNUNET_OK == 1181 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
1251 GNUNET_NETWORK_socket_close (desc));
1252 desc = NULL; 1182 desc = NULL;
1253 } 1183 }
1254 } 1184 }
@@ -1265,14 +1195,9 @@ get_server_addresses (const char *service_name,
1265 } 1195 }
1266 if (0 == port) 1196 if (0 == port)
1267 { 1197 {
1268 saddrs = GNUNET_new_array (2, 1198 saddrs = GNUNET_new_array (2, struct sockaddr *);
1269 struct sockaddr *); 1199 saddrlens = GNUNET_new_array (2, socklen_t);
1270 saddrlens = GNUNET_new_array (2, 1200 add_unixpath (saddrs, saddrlens, unixpath, abstract);
1271 socklen_t);
1272 add_unixpath (saddrs,
1273 saddrlens,
1274 unixpath,
1275 abstract);
1276 GNUNET_free_non_null (unixpath); 1201 GNUNET_free_non_null (unixpath);
1277 GNUNET_free_non_null (hostname); 1202 GNUNET_free_non_null (hostname);
1278 *addrs = saddrs; 1203 *addrs = saddrs;
@@ -1286,16 +1211,11 @@ get_server_addresses (const char *service_name,
1286 "Resolving `%s' since that is where `%s' will bind to.\n", 1211 "Resolving `%s' since that is where `%s' will bind to.\n",
1287 hostname, 1212 hostname,
1288 service_name); 1213 service_name);
1289 memset (&hints, 1214 memset (&hints, 0, sizeof (struct addrinfo));
1290 0,
1291 sizeof (struct addrinfo));
1292 if (disablev6) 1215 if (disablev6)
1293 hints.ai_family = AF_INET; 1216 hints.ai_family = AF_INET;
1294 hints.ai_protocol = IPPROTO_TCP; 1217 hints.ai_protocol = IPPROTO_TCP;
1295 if ((0 != (ret = getaddrinfo (hostname, 1218 if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) ||
1296 NULL,
1297 &hints,
1298 &res))) ||
1299 (NULL == res)) 1219 (NULL == res))
1300 { 1220 {
1301 LOG (GNUNET_ERROR_TYPE_ERROR, 1221 LOG (GNUNET_ERROR_TYPE_ERROR,
@@ -1311,8 +1231,7 @@ get_server_addresses (const char *service_name,
1311 while (NULL != (pos = next)) 1231 while (NULL != (pos = next))
1312 { 1232 {
1313 next = pos->ai_next; 1233 next = pos->ai_next;
1314 if ( (disablev6) && 1234 if ((disablev6) && (pos->ai_family == AF_INET6))
1315 (pos->ai_family == AF_INET6) )
1316 continue; 1235 continue;
1317 i++; 1236 i++;
1318 } 1237 }
@@ -1330,45 +1249,34 @@ get_server_addresses (const char *service_name,
1330 resi = i; 1249 resi = i;
1331 if (NULL != unixpath) 1250 if (NULL != unixpath)
1332 resi++; 1251 resi++;
1333 saddrs = GNUNET_new_array (resi + 1, 1252 saddrs = GNUNET_new_array (resi + 1, struct sockaddr *);
1334 struct sockaddr *); 1253 saddrlens = GNUNET_new_array (resi + 1, socklen_t);
1335 saddrlens = GNUNET_new_array (resi + 1,
1336 socklen_t);
1337 i = 0; 1254 i = 0;
1338 if (NULL != unixpath) 1255 if (NULL != unixpath)
1339 { 1256 {
1340 add_unixpath (saddrs, 1257 add_unixpath (saddrs, saddrlens, unixpath, abstract);
1341 saddrlens,
1342 unixpath,
1343 abstract);
1344 i++; 1258 i++;
1345 } 1259 }
1346 next = res; 1260 next = res;
1347 while (NULL != (pos = next)) 1261 while (NULL != (pos = next))
1348 { 1262 {
1349 next = pos->ai_next; 1263 next = pos->ai_next;
1350 if ( (disablev6) && 1264 if ((disablev6) && (AF_INET6 == pos->ai_family))
1351 (AF_INET6 == pos->ai_family) )
1352 continue; 1265 continue;
1353 if ( (IPPROTO_TCP != pos->ai_protocol) && 1266 if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol))
1354 (0 != pos->ai_protocol) ) 1267 continue; /* not TCP */
1355 continue; /* not TCP */ 1268 if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype))
1356 if ( (SOCK_STREAM != pos->ai_socktype) && 1269 continue; /* huh? */
1357 (0 != pos->ai_socktype) )
1358 continue; /* huh? */
1359 LOG (GNUNET_ERROR_TYPE_DEBUG, 1270 LOG (GNUNET_ERROR_TYPE_DEBUG,
1360 "Service `%s' will bind to `%s'\n", 1271 "Service `%s' will bind to `%s'\n",
1361 service_name, 1272 service_name,
1362 GNUNET_a2s (pos->ai_addr, 1273 GNUNET_a2s (pos->ai_addr, pos->ai_addrlen));
1363 pos->ai_addrlen));
1364 if (AF_INET == pos->ai_family) 1274 if (AF_INET == pos->ai_family)
1365 { 1275 {
1366 GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen); 1276 GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen);
1367 saddrlens[i] = pos->ai_addrlen; 1277 saddrlens[i] = pos->ai_addrlen;
1368 saddrs[i] = GNUNET_malloc (saddrlens[i]); 1278 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1369 GNUNET_memcpy (saddrs[i], 1279 GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
1370 pos->ai_addr,
1371 saddrlens[i]);
1372 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); 1280 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
1373 } 1281 }
1374 else 1282 else
@@ -1377,9 +1285,7 @@ get_server_addresses (const char *service_name,
1377 GNUNET_assert (sizeof (struct sockaddr_in6) == pos->ai_addrlen); 1285 GNUNET_assert (sizeof (struct sockaddr_in6) == pos->ai_addrlen);
1378 saddrlens[i] = pos->ai_addrlen; 1286 saddrlens[i] = pos->ai_addrlen;
1379 saddrs[i] = GNUNET_malloc (saddrlens[i]); 1287 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1380 GNUNET_memcpy (saddrs[i], 1288 GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
1381 pos->ai_addr,
1382 saddrlens[i]);
1383 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); 1289 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
1384 } 1290 }
1385 i++; 1291 i++;
@@ -1398,16 +1304,11 @@ get_server_addresses (const char *service_name,
1398 if (NULL != unixpath) 1304 if (NULL != unixpath)
1399 resi++; 1305 resi++;
1400 i = 0; 1306 i = 0;
1401 saddrs = GNUNET_new_array (resi + 1, 1307 saddrs = GNUNET_new_array (resi + 1, struct sockaddr *);
1402 struct sockaddr *); 1308 saddrlens = GNUNET_new_array (resi + 1, socklen_t);
1403 saddrlens = GNUNET_new_array (resi + 1,
1404 socklen_t);
1405 if (NULL != unixpath) 1309 if (NULL != unixpath)
1406 { 1310 {
1407 add_unixpath (saddrs, 1311 add_unixpath (saddrs, saddrlens, unixpath, abstract);
1408 saddrlens,
1409 unixpath,
1410 abstract);
1411 i++; 1312 i++;
1412 } 1313 }
1413 saddrlens[i] = sizeof (struct sockaddr_in); 1314 saddrlens[i] = sizeof (struct sockaddr_in);
@@ -1424,17 +1325,12 @@ get_server_addresses (const char *service_name,
1424 resi = 2; 1325 resi = 2;
1425 if (NULL != unixpath) 1326 if (NULL != unixpath)
1426 resi++; 1327 resi++;
1427 saddrs = GNUNET_new_array (resi + 1, 1328 saddrs = GNUNET_new_array (resi + 1, struct sockaddr *);
1428 struct sockaddr *); 1329 saddrlens = GNUNET_new_array (resi + 1, socklen_t);
1429 saddrlens = GNUNET_new_array (resi + 1,
1430 socklen_t);
1431 i = 0; 1330 i = 0;
1432 if (NULL != unixpath) 1331 if (NULL != unixpath)
1433 { 1332 {
1434 add_unixpath (saddrs, 1333 add_unixpath (saddrs, saddrlens, unixpath, abstract);
1435 saddrlens,
1436 unixpath,
1437 abstract);
1438 i++; 1334 i++;
1439 } 1335 }
1440 saddrlens[i] = sizeof (struct sockaddr_in6); 1336 saddrlens[i] = sizeof (struct sockaddr_in6);
@@ -1480,18 +1376,14 @@ receive_sockets_from_parent (struct GNUNET_SERVICE_Handle *sh)
1480 HANDLE lsocks_pipe; 1376 HANDLE lsocks_pipe;
1481 1377
1482 env_buf = getenv ("GNUNET_OS_READ_LSOCKS"); 1378 env_buf = getenv ("GNUNET_OS_READ_LSOCKS");
1483 if ( (NULL == env_buf) || 1379 if ((NULL == env_buf) || (strlen (env_buf) <= 0))
1484 (strlen (env_buf) <= 0) )
1485 return NULL; 1380 return NULL;
1486 /* Using W32 API directly here, because this pipe will 1381 /* Using W32 API directly here, because this pipe will
1487 * never be used outside of this function, and it's just too much of a bother 1382 * never be used outside of this function, and it's just too much of a bother
1488 * to create a GNUnet API that boxes a HANDLE (the way it is done with socks) 1383 * to create a GNUnet API that boxes a HANDLE (the way it is done with socks)
1489 */ 1384 */
1490 lsocks_pipe = (HANDLE) strtoul (env_buf, 1385 lsocks_pipe = (HANDLE) strtoul (env_buf, NULL, 10);
1491 NULL, 1386 if ((0 == lsocks_pipe) || (INVALID_HANDLE_VALUE == lsocks_pipe))
1492 10);
1493 if ( (0 == lsocks_pipe) ||
1494 (INVALID_HANDLE_VALUE == lsocks_pipe))
1495 return NULL; 1387 return NULL;
1496 fail = 1; 1388 fail = 1;
1497 do 1389 do
@@ -1500,17 +1392,10 @@ receive_sockets_from_parent (struct GNUNET_SERVICE_Handle *sh)
1500 int fail2; 1392 int fail2;
1501 DWORD rd; 1393 DWORD rd;
1502 1394
1503 ret = ReadFile (lsocks_pipe, 1395 ret = ReadFile (lsocks_pipe, &count, sizeof (count), &rd, NULL);
1504 &count, 1396 if ((0 == ret) || (sizeof (count) != rd) || (0 == count))
1505 sizeof (count),
1506 &rd,
1507 NULL);
1508 if ( (0 == ret) ||
1509 (sizeof (count) != rd) ||
1510 (0 == count) )
1511 break; 1397 break;
1512 lsocks = GNUNET_new_array (count + 1, 1398 lsocks = GNUNET_new_array (count + 1, struct GNUNET_NETWORK_Handle *);
1513 struct GNUNET_NETWORK_Handle *);
1514 1399
1515 fail2 = 1; 1400 fail2 = 1;
1516 for (i = 0; i < count; i++) 1401 for (i = 0; i < count; i++)
@@ -1519,22 +1404,11 @@ receive_sockets_from_parent (struct GNUNET_SERVICE_Handle *sh)
1519 uint64_t size; 1404 uint64_t size;
1520 SOCKET s; 1405 SOCKET s;
1521 1406
1522 ret = ReadFile (lsocks_pipe, 1407 ret = ReadFile (lsocks_pipe, &size, sizeof (size), &rd, NULL);
1523 &size, 1408 if ((0 == ret) || (sizeof (size) != rd) || (sizeof (pi) != size))
1524 sizeof (size),
1525 &rd,
1526 NULL);
1527 if ( (0 == ret) ||
1528 (sizeof (size) != rd) ||
1529 (sizeof (pi) != size) )
1530 break; 1409 break;
1531 ret = ReadFile (lsocks_pipe, 1410 ret = ReadFile (lsocks_pipe, &pi, sizeof (pi), &rd, NULL);
1532 &pi, 1411 if ((0 == ret) || (sizeof (pi) != rd))
1533 sizeof (pi),
1534 &rd,
1535 NULL);
1536 if ( (0 == ret) ||
1537 (sizeof (pi) != rd))
1538 break; 1412 break;
1539 s = WSASocketA (pi.iAddressFamily, 1413 s = WSASocketA (pi.iAddressFamily,
1540 pi.iSocketType, 1414 pi.iSocketType,
@@ -1552,8 +1426,7 @@ receive_sockets_from_parent (struct GNUNET_SERVICE_Handle *sh)
1552 break; 1426 break;
1553 lsocks[count] = NULL; 1427 lsocks[count] = NULL;
1554 fail = 0; 1428 fail = 0;
1555 } 1429 } while (fail);
1556 while (fail);
1557 CloseHandle (lsocks_pipe); 1430 CloseHandle (lsocks_pipe);
1558 1431
1559 if (fail) 1432 if (fail)
@@ -1561,8 +1434,7 @@ receive_sockets_from_parent (struct GNUNET_SERVICE_Handle *sh)
1561 LOG (GNUNET_ERROR_TYPE_ERROR, 1434 LOG (GNUNET_ERROR_TYPE_ERROR,
1562 _ ("Could not access a pre-bound socket, will try to bind myself\n")); 1435 _ ("Could not access a pre-bound socket, will try to bind myself\n"));
1563 for (i = 0; (i < count) && (NULL != lsocks[i]); i++) 1436 for (i = 0; (i < count) && (NULL != lsocks[i]); i++)
1564 GNUNET_break (GNUNET_OK == 1437 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (lsocks[i]));
1565 GNUNET_NETWORK_socket_close (lsocks[i]));
1566 GNUNET_free (lsocks); 1438 GNUNET_free (lsocks);
1567 return NULL; 1439 return NULL;
1568 } 1440 }
@@ -1579,8 +1451,7 @@ receive_sockets_from_parent (struct GNUNET_SERVICE_Handle *sh)
1579 * @return NULL on error, otherwise the listen socket 1451 * @return NULL on error, otherwise the listen socket
1580 */ 1452 */
1581static struct GNUNET_NETWORK_Handle * 1453static struct GNUNET_NETWORK_Handle *
1582open_listen_socket (const struct sockaddr *server_addr, 1454open_listen_socket (const struct sockaddr *server_addr, socklen_t socklen)
1583 socklen_t socklen)
1584{ 1455{
1585 struct GNUNET_NETWORK_Handle *sock; 1456 struct GNUNET_NETWORK_Handle *sock;
1586 uint16_t port; 1457 uint16_t port;
@@ -1602,20 +1473,15 @@ open_listen_socket (const struct sockaddr *server_addr,
1602 port = 0; 1473 port = 0;
1603 break; 1474 break;
1604 } 1475 }
1605 sock = GNUNET_NETWORK_socket_create (server_addr->sa_family, 1476 sock = GNUNET_NETWORK_socket_create (server_addr->sa_family, SOCK_STREAM, 0);
1606 SOCK_STREAM,
1607 0);
1608 if (NULL == sock) 1477 if (NULL == sock)
1609 { 1478 {
1610 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, 1479 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
1611 "socket");
1612 errno = 0; 1480 errno = 0;
1613 return NULL; 1481 return NULL;
1614 } 1482 }
1615 /* bind the socket */ 1483 /* bind the socket */
1616 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock, 1484 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock, server_addr, socklen))
1617 server_addr,
1618 socklen))
1619 { 1485 {
1620 eno = errno; 1486 eno = errno;
1621 if (EADDRINUSE != errno) 1487 if (EADDRINUSE != errno)
@@ -1631,8 +1497,7 @@ open_listen_socket (const struct sockaddr *server_addr,
1631 port, 1497 port,
1632 (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6"); 1498 (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6");
1633 else 1499 else
1634 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, 1500 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "bind");
1635 "bind");
1636 eno = 0; 1501 eno = 0;
1637 } 1502 }
1638 else 1503 else
@@ -1640,7 +1505,8 @@ open_listen_socket (const struct sockaddr *server_addr,
1640 if (0 != port) 1505 if (0 != port)
1641 LOG (GNUNET_ERROR_TYPE_WARNING, 1506 LOG (GNUNET_ERROR_TYPE_WARNING,
1642 _ ("`%s' failed for port %d (%s): address already in use\n"), 1507 _ ("`%s' failed for port %d (%s): address already in use\n"),
1643 "bind", port, 1508 "bind",
1509 port,
1644 (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6"); 1510 (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6");
1645 else if (AF_UNIX == server_addr->sa_family) 1511 else if (AF_UNIX == server_addr->sa_family)
1646 { 1512 {
@@ -1650,18 +1516,14 @@ open_listen_socket (const struct sockaddr *server_addr,
1650 GNUNET_a2s (server_addr, socklen)); 1516 GNUNET_a2s (server_addr, socklen));
1651 } 1517 }
1652 } 1518 }
1653 GNUNET_break (GNUNET_OK == 1519 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
1654 GNUNET_NETWORK_socket_close (sock));
1655 errno = eno; 1520 errno = eno;
1656 return NULL; 1521 return NULL;
1657 } 1522 }
1658 if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 1523 if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 5))
1659 5))
1660 { 1524 {
1661 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, 1525 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "listen");
1662 "listen"); 1526 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
1663 GNUNET_break (GNUNET_OK ==
1664 GNUNET_NETWORK_socket_close (sock));
1665 errno = 0; 1527 errno = 0;
1666 return NULL; 1528 return NULL;
1667 } 1529 }
@@ -1701,16 +1563,12 @@ setup_service (struct GNUNET_SERVICE_Handle *sh)
1701 char dummy[2]; 1563 char dummy[2];
1702#endif 1564#endif
1703 1565
1704 if (GNUNET_CONFIGURATION_have_value 1566 if (GNUNET_CONFIGURATION_have_value (sh->cfg, sh->service_name, "TOLERANT"))
1705 (sh->cfg,
1706 sh->service_name,
1707 "TOLERANT"))
1708 { 1567 {
1709 if (GNUNET_SYSERR == 1568 if (GNUNET_SYSERR ==
1710 (tolerant = 1569 (tolerant = GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
1711 GNUNET_CONFIGURATION_get_value_yesno (sh->cfg, 1570 sh->service_name,
1712 sh->service_name, 1571 "TOLERANT")))
1713 "TOLERANT")))
1714 { 1572 {
1715 LOG (GNUNET_ERROR_TYPE_ERROR, 1573 LOG (GNUNET_ERROR_TYPE_ERROR,
1716 _ ("Specified value for `%s' of service `%s' is invalid\n"), 1574 _ ("Specified value for `%s' of service `%s' is invalid\n"),
@@ -1725,25 +1583,16 @@ setup_service (struct GNUNET_SERVICE_Handle *sh)
1725 lsocks = NULL; 1583 lsocks = NULL;
1726#ifndef MINGW 1584#ifndef MINGW
1727 errno = 0; 1585 errno = 0;
1728 if ( (NULL != (nfds = getenv ("LISTEN_FDS"))) && 1586 if ((NULL != (nfds = getenv ("LISTEN_FDS"))) &&
1729 (1 == SSCANF (nfds, 1587 (1 == sscanf (nfds, "%u%1s", &cnt, dummy)) && (cnt > 0) &&
1730 "%u%1s", 1588 (cnt < FD_SETSIZE) && (cnt + 4 < FD_SETSIZE))
1731 &cnt,
1732 dummy)) &&
1733 (cnt > 0) &&
1734 (cnt < FD_SETSIZE) &&
1735 (cnt + 4 < FD_SETSIZE) )
1736 { 1589 {
1737 lsocks = GNUNET_new_array (cnt + 1, 1590 lsocks = GNUNET_new_array (cnt + 1, struct GNUNET_NETWORK_Handle *);
1738 struct GNUNET_NETWORK_Handle *);
1739 while (0 < cnt--) 1591 while (0 < cnt--)
1740 { 1592 {
1741 flags = fcntl (3 + cnt, 1593 flags = fcntl (3 + cnt, F_GETFD);
1742 F_GETFD); 1594 if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) ||
1743 if ( (flags < 0) || 1595 (NULL == (lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt))))
1744 (0 != (flags & FD_CLOEXEC)) ||
1745 (NULL ==
1746 (lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt))))
1747 { 1596 {
1748 LOG (GNUNET_ERROR_TYPE_ERROR, 1597 LOG (GNUNET_ERROR_TYPE_ERROR,
1749 _ ( 1598 _ (
@@ -1780,9 +1629,7 @@ setup_service (struct GNUNET_SERVICE_Handle *sh)
1780 slc = GNUNET_new (struct ServiceListenContext); 1629 slc = GNUNET_new (struct ServiceListenContext);
1781 slc->sh = sh; 1630 slc->sh = sh;
1782 slc->listen_socket = *ls; 1631 slc->listen_socket = *ls;
1783 GNUNET_CONTAINER_DLL_insert (sh->slc_head, 1632 GNUNET_CONTAINER_DLL_insert (sh->slc_head, sh->slc_tail, slc);
1784 sh->slc_tail,
1785 slc);
1786 } 1633 }
1787 GNUNET_free (lsocks); 1634 GNUNET_free (lsocks);
1788 } 1635 }
@@ -1792,10 +1639,7 @@ setup_service (struct GNUNET_SERVICE_Handle *sh)
1792 socklen_t *addrlens; 1639 socklen_t *addrlens;
1793 int num; 1640 int num;
1794 1641
1795 num = get_server_addresses (sh->service_name, 1642 num = get_server_addresses (sh->service_name, sh->cfg, &addrs, &addrlens);
1796 sh->cfg,
1797 &addrs,
1798 &addrlens);
1799 if (GNUNET_SYSERR == num) 1643 if (GNUNET_SYSERR == num)
1800 return GNUNET_SYSERR; 1644 return GNUNET_SYSERR;
1801 1645
@@ -1805,54 +1649,40 @@ setup_service (struct GNUNET_SERVICE_Handle *sh)
1805 1649
1806 slc = GNUNET_new (struct ServiceListenContext); 1650 slc = GNUNET_new (struct ServiceListenContext);
1807 slc->sh = sh; 1651 slc->sh = sh;
1808 slc->listen_socket = open_listen_socket (addrs[i], 1652 slc->listen_socket = open_listen_socket (addrs[i], addrlens[i]);
1809 addrlens[i]);
1810 GNUNET_free (addrs[i]); 1653 GNUNET_free (addrs[i]);
1811 if (NULL == slc->listen_socket) 1654 if (NULL == slc->listen_socket)
1812 { 1655 {
1813 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, 1656 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
1814 "bind");
1815 GNUNET_free (slc); 1657 GNUNET_free (slc);
1816 continue; 1658 continue;
1817 } 1659 }
1818 GNUNET_CONTAINER_DLL_insert (sh->slc_head, 1660 GNUNET_CONTAINER_DLL_insert (sh->slc_head, sh->slc_tail, slc);
1819 sh->slc_tail,
1820 slc);
1821 } 1661 }
1822 GNUNET_free_non_null (addrlens); 1662 GNUNET_free_non_null (addrlens);
1823 GNUNET_free_non_null (addrs); 1663 GNUNET_free_non_null (addrs);
1824 if ( (0 != num) && 1664 if ((0 != num) && (NULL == sh->slc_head))
1825 (NULL == sh->slc_head) )
1826 { 1665 {
1827 /* All attempts to bind failed, hard failure */ 1666 /* All attempts to bind failed, hard failure */
1828 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1667 GNUNET_log (
1829 _ ( 1668 GNUNET_ERROR_TYPE_ERROR,
1830 "Could not bind to any of the ports I was supposed to, refusing to run!\n")); 1669 _ (
1670 "Could not bind to any of the ports I was supposed to, refusing to run!\n"));
1831 return GNUNET_SYSERR; 1671 return GNUNET_SYSERR;
1832 } 1672 }
1833 } 1673 }
1834 1674
1835 sh->require_found = tolerant ? GNUNET_NO : GNUNET_YES; 1675 sh->require_found = tolerant ? GNUNET_NO : GNUNET_YES;
1836 sh->match_uid 1676 sh->match_uid = GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
1837 = GNUNET_CONFIGURATION_get_value_yesno (sh->cfg, 1677 sh->service_name,
1838 sh->service_name, 1678 "UNIX_MATCH_UID");
1839 "UNIX_MATCH_UID"); 1679 sh->match_gid = GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
1840 sh->match_gid 1680 sh->service_name,
1841 = GNUNET_CONFIGURATION_get_value_yesno (sh->cfg, 1681 "UNIX_MATCH_GID");
1842 sh->service_name, 1682 process_acl4 (&sh->v4_denied, sh, "REJECT_FROM");
1843 "UNIX_MATCH_GID"); 1683 process_acl4 (&sh->v4_allowed, sh, "ACCEPT_FROM");
1844 process_acl4 (&sh->v4_denied, 1684 process_acl6 (&sh->v6_denied, sh, "REJECT_FROM6");
1845 sh, 1685 process_acl6 (&sh->v6_allowed, sh, "ACCEPT_FROM6");
1846 "REJECT_FROM");
1847 process_acl4 (&sh->v4_allowed,
1848 sh,
1849 "ACCEPT_FROM");
1850 process_acl6 (&sh->v6_denied,
1851 sh,
1852 "REJECT_FROM6");
1853 process_acl6 (&sh->v6_allowed,
1854 sh,
1855 "ACCEPT_FROM6");
1856 return GNUNET_OK; 1686 return GNUNET_OK;
1857} 1687}
1858 1688
@@ -1869,11 +1699,10 @@ get_user_name (struct GNUNET_SERVICE_Handle *sh)
1869{ 1699{
1870 char *un; 1700 char *un;
1871 1701
1872 if (GNUNET_OK != 1702 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (sh->cfg,
1873 GNUNET_CONFIGURATION_get_value_filename (sh->cfg, 1703 sh->service_name,
1874 sh->service_name, 1704 "USERNAME",
1875 "USERNAME", 1705 &un))
1876 &un))
1877 return NULL; 1706 return NULL;
1878 return un; 1707 return un;
1879} 1708}
@@ -1891,7 +1720,7 @@ set_user_id (struct GNUNET_SERVICE_Handle *sh)
1891 char *user; 1720 char *user;
1892 1721
1893 if (NULL == (user = get_user_name (sh))) 1722 if (NULL == (user = get_user_name (sh)))
1894 return GNUNET_OK; /* keep */ 1723 return GNUNET_OK; /* keep */
1895#ifndef MINGW 1724#ifndef MINGW
1896 struct passwd *pws; 1725 struct passwd *pws;
1897 1726
@@ -1902,28 +1731,23 @@ set_user_id (struct GNUNET_SERVICE_Handle *sh)
1902 LOG (GNUNET_ERROR_TYPE_ERROR, 1731 LOG (GNUNET_ERROR_TYPE_ERROR,
1903 _ ("Cannot obtain information about user `%s': %s\n"), 1732 _ ("Cannot obtain information about user `%s': %s\n"),
1904 user, 1733 user,
1905 errno == 0 ? _ ("No such user") : STRERROR (errno)); 1734 errno == 0 ? _ ("No such user") : strerror (errno));
1906 GNUNET_free (user); 1735 GNUNET_free (user);
1907 return GNUNET_SYSERR; 1736 return GNUNET_SYSERR;
1908 } 1737 }
1909 if ( (0 != setgid (pws->pw_gid)) || 1738 if ((0 != setgid (pws->pw_gid)) || (0 != setegid (pws->pw_gid)) ||
1910 (0 != setegid (pws->pw_gid)) ||
1911#if HAVE_INITGROUPS 1739#if HAVE_INITGROUPS
1912 (0 != initgroups (user, 1740 (0 != initgroups (user, pws->pw_gid)) ||
1913 pws->pw_gid)) ||
1914#endif 1741#endif
1915 (0 != setuid (pws->pw_uid)) || 1742 (0 != setuid (pws->pw_uid)) || (0 != seteuid (pws->pw_uid)))
1916 (0 != seteuid (pws->pw_uid)))
1917 { 1743 {
1918 if ((0 != setregid (pws->pw_gid, 1744 if ((0 != setregid (pws->pw_gid, pws->pw_gid)) ||
1919 pws->pw_gid)) || 1745 (0 != setreuid (pws->pw_uid, pws->pw_uid)))
1920 (0 != setreuid (pws->pw_uid,
1921 pws->pw_uid)))
1922 { 1746 {
1923 LOG (GNUNET_ERROR_TYPE_ERROR, 1747 LOG (GNUNET_ERROR_TYPE_ERROR,
1924 _ ("Cannot change user/group to `%s': %s\n"), 1748 _ ("Cannot change user/group to `%s': %s\n"),
1925 user, 1749 user,
1926 STRERROR (errno)); 1750 strerror (errno));
1927 GNUNET_free (user); 1751 GNUNET_free (user);
1928 return GNUNET_SYSERR; 1752 return GNUNET_SYSERR;
1929 } 1753 }
@@ -1946,11 +1770,10 @@ get_pid_file_name (struct GNUNET_SERVICE_Handle *sh)
1946{ 1770{
1947 char *pif; 1771 char *pif;
1948 1772
1949 if (GNUNET_OK != 1773 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (sh->cfg,
1950 GNUNET_CONFIGURATION_get_value_filename (sh->cfg, 1774 sh->service_name,
1951 sh->service_name, 1775 "PIDFILE",
1952 "PIDFILE", 1776 &pif))
1953 &pif))
1954 return NULL; 1777 return NULL;
1955 return pif; 1778 return pif;
1956} 1779}
@@ -1967,11 +1790,9 @@ pid_file_delete (struct GNUNET_SERVICE_Handle *sh)
1967 char *pif = get_pid_file_name (sh); 1790 char *pif = get_pid_file_name (sh);
1968 1791
1969 if (NULL == pif) 1792 if (NULL == pif)
1970 return; /* no PID file */ 1793 return; /* no PID file */
1971 if (0 != UNLINK (pif)) 1794 if (0 != unlink (pif))
1972 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, 1795 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", pif);
1973 "unlink",
1974 pif);
1975 GNUNET_free (pif); 1796 GNUNET_free (pif);
1976} 1797}
1977 1798
@@ -1990,17 +1811,15 @@ detach_terminal (struct GNUNET_SERVICE_Handle *sh)
1990 int nullfd; 1811 int nullfd;
1991 int filedes[2]; 1812 int filedes[2];
1992 1813
1993 if (0 != PIPE (filedes)) 1814 if (0 != pipe (filedes))
1994 { 1815 {
1995 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, 1816 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe");
1996 "pipe");
1997 return GNUNET_SYSERR; 1817 return GNUNET_SYSERR;
1998 } 1818 }
1999 pid = fork (); 1819 pid = fork ();
2000 if (pid < 0) 1820 if (pid < 0)
2001 { 1821 {
2002 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, 1822 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork");
2003 "fork");
2004 return GNUNET_SYSERR; 1823 return GNUNET_SYSERR;
2005 } 1824 }
2006 if (0 != pid) 1825 if (0 != pid)
@@ -2008,13 +1827,10 @@ detach_terminal (struct GNUNET_SERVICE_Handle *sh)
2008 /* Parent */ 1827 /* Parent */
2009 char c; 1828 char c;
2010 1829
2011 GNUNET_break (0 == CLOSE (filedes[1])); 1830 GNUNET_break (0 == close (filedes[1]));
2012 c = 'X'; 1831 c = 'X';
2013 if (1 != READ (filedes[0], 1832 if (1 != read (filedes[0], &c, sizeof (char)))
2014 &c, 1833 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "read");
2015 sizeof (char)))
2016 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
2017 "read");
2018 fflush (stdout); 1834 fflush (stdout);
2019 switch (c) 1835 switch (c)
2020 { 1836 {
@@ -2033,30 +1849,26 @@ detach_terminal (struct GNUNET_SERVICE_Handle *sh)
2033 _ ("Service process failed to report status\n")); 1849 _ ("Service process failed to report status\n"));
2034 break; 1850 break;
2035 } 1851 }
2036 exit (1); /* child reported error */ 1852 exit (1); /* child reported error */
2037 } 1853 }
2038 GNUNET_break (0 == CLOSE (0)); 1854 GNUNET_break (0 == close (0));
2039 GNUNET_break (0 == CLOSE (1)); 1855 GNUNET_break (0 == close (1));
2040 GNUNET_break (0 == CLOSE (filedes[0])); 1856 GNUNET_break (0 == close (filedes[0]));
2041 nullfd = OPEN ("/dev/null", 1857 nullfd = open ("/dev/null", O_RDWR | O_APPEND);
2042 O_RDWR | O_APPEND);
2043 if (nullfd < 0) 1858 if (nullfd < 0)
2044 return GNUNET_SYSERR; 1859 return GNUNET_SYSERR;
2045 /* set stdin/stdout to /dev/null */ 1860 /* set stdin/stdout to /dev/null */
2046 if ( (dup2 (nullfd, 0) < 0) || 1861 if ((dup2 (nullfd, 0) < 0) || (dup2 (nullfd, 1) < 0))
2047 (dup2 (nullfd, 1) < 0) )
2048 { 1862 {
2049 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, 1863 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
2050 "dup2"); 1864 (void) close (nullfd);
2051 (void) CLOSE (nullfd);
2052 return GNUNET_SYSERR; 1865 return GNUNET_SYSERR;
2053 } 1866 }
2054 (void) CLOSE (nullfd); 1867 (void) close (nullfd);
2055 /* Detach from controlling terminal */ 1868 /* Detach from controlling terminal */
2056 pid = setsid (); 1869 pid = setsid ();
2057 if (-1 == pid) 1870 if (-1 == pid)
2058 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, 1871 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "setsid");
2059 "setsid");
2060 sh->ready_confirm_fd = filedes[1]; 1872 sh->ready_confirm_fd = filedes[1];
2061#else 1873#else
2062 /* FIXME: we probably need to do something else 1874 /* FIXME: we probably need to do something else
@@ -2084,9 +1896,7 @@ teardown_service (struct GNUNET_SERVICE_Handle *sh)
2084 GNUNET_free_non_null (sh->v6_allowed); 1896 GNUNET_free_non_null (sh->v6_allowed);
2085 while (NULL != (slc = sh->slc_head)) 1897 while (NULL != (slc = sh->slc_head))
2086 { 1898 {
2087 GNUNET_CONTAINER_DLL_remove (sh->slc_head, 1899 GNUNET_CONTAINER_DLL_remove (sh->slc_head, sh->slc_tail, slc);
2088 sh->slc_tail,
2089 slc);
2090 if (NULL != slc->listen_task) 1900 if (NULL != slc->listen_task)
2091 GNUNET_SCHEDULER_cancel (slc->listen_task); 1901 GNUNET_SCHEDULER_cancel (slc->listen_task);
2092 GNUNET_break (GNUNET_OK == 1902 GNUNET_break (GNUNET_OK ==
@@ -2103,8 +1913,7 @@ teardown_service (struct GNUNET_SERVICE_Handle *sh)
2103 * @param msg AGPL request 1913 * @param msg AGPL request
2104 */ 1914 */
2105static void 1915static void
2106return_agpl (void *cls, 1916return_agpl (void *cls, const struct GNUNET_MessageHeader *msg)
2107 const struct GNUNET_MessageHeader *msg)
2108{ 1917{
2109 struct GNUNET_SERVICE_Client *client = cls; 1918 struct GNUNET_SERVICE_Client *client = cls;
2110 struct GNUNET_MQ_Handle *mq; 1919 struct GNUNET_MQ_Handle *mq;
@@ -2114,15 +1923,10 @@ return_agpl (void *cls,
2114 1923
2115 (void) msg; 1924 (void) msg;
2116 slen = strlen (GNUNET_AGPL_URL) + 1; 1925 slen = strlen (GNUNET_AGPL_URL) + 1;
2117 env = GNUNET_MQ_msg_extra (res, 1926 env = GNUNET_MQ_msg_extra (res, GNUNET_MESSAGE_TYPE_RESPONSE_AGPL, slen);
2118 GNUNET_MESSAGE_TYPE_RESPONSE_AGPL, 1927 memcpy (&res[1], GNUNET_AGPL_URL, slen);
2119 slen);
2120 memcpy (&res[1],
2121 GNUNET_AGPL_URL,
2122 slen);
2123 mq = GNUNET_SERVICE_client_get_mq (client); 1928 mq = GNUNET_SERVICE_client_get_mq (client);
2124 GNUNET_MQ_send (mq, 1929 GNUNET_MQ_send (mq, env);
2125 env);
2126 GNUNET_SERVICE_client_continue (client); 1930 GNUNET_SERVICE_client_continue (client);
2127} 1931}
2128 1932
@@ -2179,17 +1983,14 @@ GNUNET_SERVICE_start (const char *service_name,
2179 sh->connect_cb = connect_cb; 1983 sh->connect_cb = connect_cb;
2180 sh->disconnect_cb = disconnect_cb; 1984 sh->disconnect_cb = disconnect_cb;
2181 sh->cb_cls = cls; 1985 sh->cb_cls = cls;
2182 sh->handlers = GNUNET_MQ_copy_handlers2 (handlers, 1986 sh->handlers = GNUNET_MQ_copy_handlers2 (handlers, &return_agpl, NULL);
2183 &return_agpl,
2184 NULL);
2185 if (GNUNET_OK != setup_service (sh)) 1987 if (GNUNET_OK != setup_service (sh))
2186 { 1988 {
2187 GNUNET_free_non_null (sh->handlers); 1989 GNUNET_free_non_null (sh->handlers);
2188 GNUNET_free (sh); 1990 GNUNET_free (sh);
2189 return NULL; 1991 return NULL;
2190 } 1992 }
2191 do_resume (sh, 1993 do_resume (sh, SUSPEND_STATE_NONE);
2192 SUSPEND_STATE_NONE);
2193 return sh; 1994 return sh;
2194} 1995}
2195 1996
@@ -2279,24 +2080,21 @@ GNUNET_SERVICE_run_ (int argc,
2279 int ret; 2080 int ret;
2280 int err; 2081 int err;
2281 2082
2282 struct GNUNET_GETOPT_CommandLineOption service_options[] = { 2083 struct GNUNET_GETOPT_CommandLineOption service_options[] =
2283 GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename), 2084 {GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename),
2284 GNUNET_GETOPT_option_flag ('d', 2085 GNUNET_GETOPT_option_flag ('d',
2285 "daemonize", 2086 "daemonize",
2286 gettext_noop ( 2087 gettext_noop (
2287 "do daemonize (detach from terminal)"), 2088 "do daemonize (detach from terminal)"),
2288 &do_daemonize), 2089 &do_daemonize),
2289 GNUNET_GETOPT_option_help (NULL), 2090 GNUNET_GETOPT_option_help (NULL),
2290 GNUNET_GETOPT_option_loglevel (&loglev), 2091 GNUNET_GETOPT_option_loglevel (&loglev),
2291 GNUNET_GETOPT_option_logfile (&logfile), 2092 GNUNET_GETOPT_option_logfile (&logfile),
2292 GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION), 2093 GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
2293 GNUNET_GETOPT_OPTION_END 2094 GNUNET_GETOPT_OPTION_END};
2294 };
2295 2095
2296 err = 1; 2096 err = 1;
2297 memset (&sh, 2097 memset (&sh, 0, sizeof (sh));
2298 0,
2299 sizeof (sh));
2300 xdg = getenv ("XDG_CONFIG_HOME"); 2098 xdg = getenv ("XDG_CONFIG_HOME");
2301 if (NULL != xdg) 2099 if (NULL != xdg)
2302 GNUNET_asprintf (&cfg_filename, 2100 GNUNET_asprintf (&cfg_filename,
@@ -2305,8 +2103,8 @@ GNUNET_SERVICE_run_ (int argc,
2305 DIR_SEPARATOR_STR, 2103 DIR_SEPARATOR_STR,
2306 GNUNET_OS_project_data_get ()->config_file); 2104 GNUNET_OS_project_data_get ()->config_file);
2307 else 2105 else
2308 cfg_filename = GNUNET_strdup ( 2106 cfg_filename =
2309 GNUNET_OS_project_data_get ()->user_config_file); 2107 GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file);
2310 sh.ready_confirm_fd = -1; 2108 sh.ready_confirm_fd = -1;
2311 sh.options = options; 2109 sh.options = options;
2312 sh.cfg = cfg = GNUNET_CONFIGURATION_create (); 2110 sh.cfg = cfg = GNUNET_CONFIGURATION_create ();
@@ -2322,10 +2120,7 @@ GNUNET_SERVICE_run_ (int argc,
2322 logfile = NULL; 2120 logfile = NULL;
2323 opt_cfg_filename = NULL; 2121 opt_cfg_filename = NULL;
2324 do_daemonize = 0; 2122 do_daemonize = 0;
2325 ret = GNUNET_GETOPT_run (service_name, 2123 ret = GNUNET_GETOPT_run (service_name, service_options, argc, argv);
2326 service_options,
2327 argc,
2328 argv);
2329 if (GNUNET_SYSERR == ret) 2124 if (GNUNET_SYSERR == ret)
2330 goto shutdown; 2125 goto shutdown;
2331 if (GNUNET_NO == ret) 2126 if (GNUNET_NO == ret)
@@ -2333,20 +2128,15 @@ GNUNET_SERVICE_run_ (int argc,
2333 err = 0; 2128 err = 0;
2334 goto shutdown; 2129 goto shutdown;
2335 } 2130 }
2336 if (GNUNET_OK != GNUNET_log_setup (service_name, 2131 if (GNUNET_OK != GNUNET_log_setup (service_name, loglev, logfile))
2337 loglev,
2338 logfile))
2339 { 2132 {
2340 GNUNET_break (0); 2133 GNUNET_break (0);
2341 goto shutdown; 2134 goto shutdown;
2342 } 2135 }
2343 if (NULL != opt_cfg_filename) 2136 if (NULL != opt_cfg_filename)
2344 { 2137 {
2345 if ( (GNUNET_YES != 2138 if ((GNUNET_YES != GNUNET_DISK_file_test (opt_cfg_filename)) ||
2346 GNUNET_DISK_file_test (opt_cfg_filename)) || 2139 (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, opt_cfg_filename)))
2347 (GNUNET_SYSERR ==
2348 GNUNET_CONFIGURATION_load (cfg,
2349 opt_cfg_filename)) )
2350 { 2140 {
2351 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2141 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2352 _ ("Malformed configuration file `%s', exit ...\n"), 2142 _ ("Malformed configuration file `%s', exit ...\n"),
@@ -2356,12 +2146,9 @@ GNUNET_SERVICE_run_ (int argc,
2356 } 2146 }
2357 else 2147 else
2358 { 2148 {
2359 if (GNUNET_YES == 2149 if (GNUNET_YES == GNUNET_DISK_file_test (cfg_filename))
2360 GNUNET_DISK_file_test (cfg_filename))
2361 { 2150 {
2362 if (GNUNET_SYSERR == 2151 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, cfg_filename))
2363 GNUNET_CONFIGURATION_load (cfg,
2364 cfg_filename))
2365 { 2152 {
2366 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2153 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2367 _ ("Malformed configuration file `%s', exit ...\n"), 2154 _ ("Malformed configuration file `%s', exit ...\n"),
@@ -2371,9 +2158,7 @@ GNUNET_SERVICE_run_ (int argc,
2371 } 2158 }
2372 else 2159 else
2373 { 2160 {
2374 if (GNUNET_SYSERR == 2161 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, NULL))
2375 GNUNET_CONFIGURATION_load (cfg,
2376 NULL))
2377 { 2162 {
2378 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2163 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2379 _ ("Malformed configuration, exit ...\n")); 2164 _ ("Malformed configuration, exit ...\n"));
@@ -2383,8 +2168,7 @@ GNUNET_SERVICE_run_ (int argc,
2383 } 2168 }
2384 if (GNUNET_OK != setup_service (&sh)) 2169 if (GNUNET_OK != setup_service (&sh))
2385 goto shutdown; 2170 goto shutdown;
2386 if ( (1 == do_daemonize) && 2171 if ((1 == do_daemonize) && (GNUNET_OK != detach_terminal (&sh)))
2387 (GNUNET_OK != detach_terminal (&sh)) )
2388 { 2172 {
2389 GNUNET_break (0); 2173 GNUNET_break (0);
2390 goto shutdown; 2174 goto shutdown;
@@ -2395,64 +2179,51 @@ GNUNET_SERVICE_run_ (int argc,
2395 "Service `%s' runs with configuration from `%s'\n", 2179 "Service `%s' runs with configuration from `%s'\n",
2396 service_name, 2180 service_name,
2397 (NULL != opt_cfg_filename) ? opt_cfg_filename : cfg_filename); 2181 (NULL != opt_cfg_filename) ? opt_cfg_filename : cfg_filename);
2398 if ((GNUNET_OK == 2182 if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sh.cfg,
2399 GNUNET_CONFIGURATION_get_value_number (sh.cfg, 2183 "TESTING",
2400 "TESTING", 2184 "SKEW_OFFSET",
2401 "SKEW_OFFSET", 2185 &skew_offset)) &&
2402 &skew_offset)) && 2186 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sh.cfg,
2403 (GNUNET_OK == 2187 "TESTING",
2404 GNUNET_CONFIGURATION_get_value_number (sh.cfg, 2188 "SKEW_VARIANCE",
2405 "TESTING", 2189 &skew_variance)))
2406 "SKEW_VARIANCE",
2407 &skew_variance)))
2408 { 2190 {
2409 clock_offset = skew_offset - skew_variance; 2191 clock_offset = skew_offset - skew_variance;
2410 GNUNET_TIME_set_offset (clock_offset); 2192 GNUNET_TIME_set_offset (clock_offset);
2411 LOG (GNUNET_ERROR_TYPE_DEBUG, 2193 LOG (GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll ms\n", clock_offset);
2412 "Skewing clock by %dll ms\n",
2413 clock_offset);
2414 } 2194 }
2415 GNUNET_RESOLVER_connect (sh.cfg); 2195 GNUNET_RESOLVER_connect (sh.cfg);
2416 2196
2417 /* actually run service */ 2197 /* actually run service */
2418 err = 0; 2198 err = 0;
2419 GNUNET_SCHEDULER_run (&service_main, 2199 GNUNET_SCHEDULER_run (&service_main, &sh);
2420 &sh);
2421 /* shutdown */ 2200 /* shutdown */
2422 if (1 == do_daemonize) 2201 if (1 == do_daemonize)
2423 pid_file_delete (&sh); 2202 pid_file_delete (&sh);
2424 2203
2425 shutdown: 2204shutdown:
2426 if (-1 != sh.ready_confirm_fd) 2205 if (-1 != sh.ready_confirm_fd)
2427 { 2206 {
2428 if (1 != WRITE (sh.ready_confirm_fd, 2207 if (1 != write (sh.ready_confirm_fd, err ? "I" : "S", 1))
2429 err ? "I" : "S", 2208 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "write");
2430 1)) 2209 GNUNET_break (0 == close (sh.ready_confirm_fd));
2431 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
2432 "write");
2433 GNUNET_break (0 == CLOSE (sh.ready_confirm_fd));
2434 } 2210 }
2435#if HAVE_MALLINFO 2211#if HAVE_MALLINFO
2436 { 2212 {
2437 char *counter; 2213 char *counter;
2438 2214
2439 if ( (GNUNET_YES == 2215 if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (sh.cfg,
2440 GNUNET_CONFIGURATION_have_value (sh.cfg, 2216 service_name,
2441 service_name, 2217 "GAUGER_HEAP")) &&
2442 "GAUGER_HEAP")) && 2218 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (sh.cfg,
2443 (GNUNET_OK == 2219 service_name,
2444 GNUNET_CONFIGURATION_get_value_string (sh.cfg, 2220 "GAUGER_HEAP",
2445 service_name, 2221 &counter)))
2446 "GAUGER_HEAP",
2447 &counter)) )
2448 { 2222 {
2449 struct mallinfo mi; 2223 struct mallinfo mi;
2450 2224
2451 mi = mallinfo (); 2225 mi = mallinfo ();
2452 GAUGER (service_name, 2226 GAUGER (service_name, counter, mi.usmblks, "blocks");
2453 counter,
2454 mi.usmblks,
2455 "blocks");
2456 GNUNET_free (counter); 2227 GNUNET_free (counter);
2457 } 2228 }
2458 } 2229 }
@@ -2479,8 +2250,7 @@ GNUNET_SERVICE_run_ (int argc,
2479void 2250void
2480GNUNET_SERVICE_suspend (struct GNUNET_SERVICE_Handle *sh) 2251GNUNET_SERVICE_suspend (struct GNUNET_SERVICE_Handle *sh)
2481{ 2252{
2482 do_suspend (sh, 2253 do_suspend (sh, SUSPEND_STATE_APP);
2483 SUSPEND_STATE_APP);
2484} 2254}
2485 2255
2486 2256
@@ -2492,8 +2262,7 @@ GNUNET_SERVICE_suspend (struct GNUNET_SERVICE_Handle *sh)
2492void 2262void
2493GNUNET_SERVICE_resume (struct GNUNET_SERVICE_Handle *sh) 2263GNUNET_SERVICE_resume (struct GNUNET_SERVICE_Handle *sh)
2494{ 2264{
2495 do_resume (sh, 2265 do_resume (sh, SUSPEND_STATE_APP);
2496 SUSPEND_STATE_APP);
2497} 2266}
2498 2267
2499 2268
@@ -2511,8 +2280,7 @@ resume_client_receive (void *cls)
2511 2280
2512 c->recv_task = NULL; 2281 c->recv_task = NULL;
2513 /* first, check if there is still something in the buffer */ 2282 /* first, check if there is still something in the buffer */
2514 ret = GNUNET_MST_next (c->mst, 2283 ret = GNUNET_MST_next (c->mst, GNUNET_YES);
2515 GNUNET_YES);
2516 if (GNUNET_SYSERR == ret) 2284 if (GNUNET_SYSERR == ret)
2517 { 2285 {
2518 if (NULL == c->drop_task) 2286 if (NULL == c->drop_task)
@@ -2527,11 +2295,10 @@ resume_client_receive (void *cls)
2527 /* need to receive more data from the network first */ 2295 /* need to receive more data from the network first */
2528 if (NULL != c->recv_task) 2296 if (NULL != c->recv_task)
2529 return; 2297 return;
2530 c->recv_task 2298 c->recv_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
2531 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 2299 c->sock,
2532 c->sock, 2300 &service_client_recv,
2533 &service_client_recv, 2301 c);
2534 c);
2535} 2302}
2536 2303
2537 2304
@@ -2553,9 +2320,7 @@ GNUNET_SERVICE_client_continue (struct GNUNET_SERVICE_Client *c)
2553 GNUNET_SCHEDULER_cancel (c->warn_task); 2320 GNUNET_SCHEDULER_cancel (c->warn_task);
2554 c->warn_task = NULL; 2321 c->warn_task = NULL;
2555 } 2322 }
2556 c->recv_task 2323 c->recv_task = GNUNET_SCHEDULER_add_now (&resume_client_receive, c);
2557 = GNUNET_SCHEDULER_add_now (&resume_client_receive,
2558 c);
2559} 2324}
2560 2325
2561 2326
@@ -2598,20 +2363,18 @@ finish_client_drop (void *cls)
2598 GNUNET_MQ_destroy (c->mq); 2363 GNUNET_MQ_destroy (c->mq);
2599 if (GNUNET_NO == c->persist) 2364 if (GNUNET_NO == c->persist)
2600 { 2365 {
2601 GNUNET_break (GNUNET_OK == 2366 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (c->sock));
2602 GNUNET_NETWORK_socket_close (c->sock)); 2367 if ((0 != (SUSPEND_STATE_EMFILE & sh->suspend_state)) &&
2603 if ( (0 != (SUSPEND_STATE_EMFILE & sh->suspend_state)) && 2368 (0 == (SUSPEND_STATE_SHUTDOWN & sh->suspend_state)))
2604 (0 == (SUSPEND_STATE_SHUTDOWN & sh->suspend_state)) ) 2369 do_resume (sh, SUSPEND_STATE_EMFILE);
2605 do_resume (sh,
2606 SUSPEND_STATE_EMFILE);
2607 } 2370 }
2608 else 2371 else
2609 { 2372 {
2610 GNUNET_NETWORK_socket_free_memory_only_ (c->sock); 2373 GNUNET_NETWORK_socket_free_memory_only_ (c->sock);
2611 } 2374 }
2612 GNUNET_free (c); 2375 GNUNET_free (c);
2613 if ( (0 != (SUSPEND_STATE_SHUTDOWN & sh->suspend_state)) && 2376 if ((0 != (SUSPEND_STATE_SHUTDOWN & sh->suspend_state)) &&
2614 (GNUNET_NO == have_non_monitor_clients (sh)) ) 2377 (GNUNET_NO == have_non_monitor_clients (sh)))
2615 GNUNET_SERVICE_shutdown (sh); 2378 GNUNET_SERVICE_shutdown (sh);
2616} 2379}
2617 2380
@@ -2640,8 +2403,7 @@ GNUNET_SERVICE_client_drop (struct GNUNET_SERVICE_Client *c)
2640 void *backtrace_array[MAX_TRACE_DEPTH]; 2403 void *backtrace_array[MAX_TRACE_DEPTH];
2641 int num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH); 2404 int num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH);
2642 char **backtrace_strings = 2405 char **backtrace_strings =
2643 backtrace_symbols (backtrace_array, 2406 backtrace_symbols (backtrace_array, t->num_backtrace_strings);
2644 t->num_backtrace_strings);
2645 for (unsigned int i = 0; i < num_backtrace_strings; i++) 2407 for (unsigned int i = 0; i < num_backtrace_strings; i++)
2646 LOG (GNUNET_ERROR_TYPE_DEBUG, 2408 LOG (GNUNET_ERROR_TYPE_DEBUG,
2647 "client drop trace %u: %s\n", 2409 "client drop trace %u: %s\n",
@@ -2655,13 +2417,9 @@ GNUNET_SERVICE_client_drop (struct GNUNET_SERVICE_Client *c)
2655 GNUNET_assert (0); 2417 GNUNET_assert (0);
2656 return; 2418 return;
2657 } 2419 }
2658 GNUNET_CONTAINER_DLL_remove (sh->clients_head, 2420 GNUNET_CONTAINER_DLL_remove (sh->clients_head, sh->clients_tail, c);
2659 sh->clients_tail,
2660 c);
2661 if (NULL != sh->disconnect_cb) 2421 if (NULL != sh->disconnect_cb)
2662 sh->disconnect_cb (sh->cb_cls, 2422 sh->disconnect_cb (sh->cb_cls, c, c->user_context);
2663 c,
2664 c->user_context);
2665 if (NULL != c->warn_task) 2423 if (NULL != c->warn_task)
2666 { 2424 {
2667 GNUNET_SCHEDULER_cancel (c->warn_task); 2425 GNUNET_SCHEDULER_cancel (c->warn_task);
@@ -2677,8 +2435,7 @@ GNUNET_SERVICE_client_drop (struct GNUNET_SERVICE_Client *c)
2677 GNUNET_SCHEDULER_cancel (c->send_task); 2435 GNUNET_SCHEDULER_cancel (c->send_task);
2678 c->send_task = NULL; 2436 c->send_task = NULL;
2679 } 2437 }
2680 c->drop_task = GNUNET_SCHEDULER_add_now (&finish_client_drop, 2438 c->drop_task = GNUNET_SCHEDULER_add_now (&finish_client_drop, c);
2681 c);
2682} 2439}
2683 2440
2684 2441
@@ -2693,8 +2450,7 @@ GNUNET_SERVICE_shutdown (struct GNUNET_SERVICE_Handle *sh)
2693 struct GNUNET_SERVICE_Client *client; 2450 struct GNUNET_SERVICE_Client *client;
2694 2451
2695 if (0 == (sh->suspend_state & SUSPEND_STATE_SHUTDOWN)) 2452 if (0 == (sh->suspend_state & SUSPEND_STATE_SHUTDOWN))
2696 do_suspend (sh, 2453 do_suspend (sh, SUSPEND_STATE_SHUTDOWN);
2697 SUSPEND_STATE_SHUTDOWN);
2698 while (NULL != (client = sh->clients_head)) 2454 while (NULL != (client = sh->clients_head))
2699 GNUNET_SERVICE_client_drop (client); 2455 GNUNET_SERVICE_client_drop (client);
2700} 2456}
@@ -2716,8 +2472,8 @@ void
2716GNUNET_SERVICE_client_mark_monitor (struct GNUNET_SERVICE_Client *c) 2472GNUNET_SERVICE_client_mark_monitor (struct GNUNET_SERVICE_Client *c)
2717{ 2473{
2718 c->is_monitor = GNUNET_YES; 2474 c->is_monitor = GNUNET_YES;
2719 if ( ((0 != (SUSPEND_STATE_SHUTDOWN & c->sh->suspend_state))&& 2475 if (((0 != (SUSPEND_STATE_SHUTDOWN & c->sh->suspend_state)) &&
2720 (GNUNET_NO == have_non_monitor_clients (c->sh)) ) ) 2476 (GNUNET_NO == have_non_monitor_clients (c->sh))))
2721 GNUNET_SERVICE_shutdown (c->sh); 2477 GNUNET_SERVICE_shutdown (c->sh);
2722} 2478}
2723 2479
diff --git a/src/util/strings.c b/src/util/strings.c
index 8cd591288..ef9fdd693 100644
--- a/src/util/strings.c
+++ b/src/util/strings.c
@@ -34,9 +34,10 @@
34#include <unistr.h> 34#include <unistr.h>
35#include <uniconv.h> 35#include <uniconv.h>
36 36
37#define LOG(kind,...) GNUNET_log_from (kind, "util-strings", __VA_ARGS__) 37#define LOG(kind, ...) GNUNET_log_from (kind, "util-strings", __VA_ARGS__)
38 38
39#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-strings", syscall) 39#define LOG_STRERROR(kind, syscall) \
40 GNUNET_log_from_strerror (kind, "util-strings", syscall)
40 41
41 42
42/** 43/**
@@ -105,15 +106,13 @@ GNUNET_STRINGS_pp2s (const struct GNUNET_PeerIdentity *pids,
105 106
106 off = 0; 107 off = 0;
107 buf = GNUNET_malloc (plen); 108 buf = GNUNET_malloc (plen);
108 for (unsigned int i = 0; 109 for (unsigned int i = 0; i < num_pids; i++)
109 i < num_pids;
110 i++)
111 { 110 {
112 off += GNUNET_snprintf (&buf[off], 111 off += GNUNET_snprintf (&buf[off],
113 plen - off, 112 plen - off,
114 "%s%s", 113 "%s%s",
115 GNUNET_i2s (&pids[i]), 114 GNUNET_i2s (&pids[i]),
116 (i == num_pids -1) ? "" : "-"); 115 (i == num_pids - 1) ? "" : "-");
117 } 116 }
118 return buf; 117 return buf;
119} 118}
@@ -133,8 +132,10 @@ GNUNET_STRINGS_pp2s (const struct GNUNET_PeerIdentity *pids,
133 * in the buffer, or 0 on error. 132 * in the buffer, or 0 on error.
134 */ 133 */
135unsigned int 134unsigned int
136GNUNET_STRINGS_buffer_tokenize (const char *buffer, size_t size, 135GNUNET_STRINGS_buffer_tokenize (const char *buffer,
137 unsigned int count, ...) 136 size_t size,
137 unsigned int count,
138 ...)
138{ 139{
139 unsigned int start; 140 unsigned int start;
140 unsigned int needed; 141 unsigned int needed;
@@ -153,10 +154,10 @@ GNUNET_STRINGS_buffer_tokenize (const char *buffer, size_t size,
153 if (needed == size) 154 if (needed == size)
154 { 155 {
155 va_end (ap); 156 va_end (ap);
156 return 0; /* error */ 157 return 0; /* error */
157 } 158 }
158 *r = &buffer[start]; 159 *r = &buffer[start];
159 needed++; /* skip 0-termination */ 160 needed++; /* skip 0-termination */
160 count--; 161 count--;
161 } 162 }
162 va_end (ap); 163 va_end (ap);
@@ -173,7 +174,7 @@ GNUNET_STRINGS_buffer_tokenize (const char *buffer, size_t size,
173char * 174char *
174GNUNET_STRINGS_byte_size_fancy (unsigned long long size) 175GNUNET_STRINGS_byte_size_fancy (unsigned long long size)
175{ 176{
176 const char *unit = _( /* size unit */ "b"); 177 const char *unit = _ (/* size unit */ "b");
177 char *ret; 178 char *ret;
178 179
179 if (size > 5 * 1024) 180 if (size > 5 * 1024)
@@ -215,7 +216,7 @@ GNUNET_STRINGS_byte_size_fancy (unsigned long long size)
215 * null byte 216 * null byte
216 */ 217 */
217size_t 218size_t
218GNUNET_strlcpy(char *dst, const char *src, size_t n) 219GNUNET_strlcpy (char *dst, const char *src, size_t n)
219{ 220{
220 size_t slen; 221 size_t slen;
221 222
@@ -257,8 +258,8 @@ struct ConversionTable
257 */ 258 */
258static int 259static int
259convert_with_table (const char *input, 260convert_with_table (const char *input,
260 const struct ConversionTable *table, 261 const struct ConversionTable *table,
261 unsigned long long *output) 262 unsigned long long *output)
262{ 263{
263 unsigned long long ret; 264 unsigned long long ret;
264 char *in; 265 char *in;
@@ -290,7 +291,7 @@ convert_with_table (const char *input,
290 if ((0 != errno) || (endptr == tok)) 291 if ((0 != errno) || (endptr == tok))
291 { 292 {
292 GNUNET_free (in); 293 GNUNET_free (in);
293 return GNUNET_SYSERR; /* expected number */ 294 return GNUNET_SYSERR; /* expected number */
294 } 295 }
295 if ('\0' == endptr[0]) 296 if ('\0' == endptr[0])
296 break; /* next tok */ 297 break; /* next tok */
@@ -318,26 +319,22 @@ GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size,
318 unsigned long long *size) 319 unsigned long long *size)
319{ 320{
320 static const struct ConversionTable table[] = 321 static const struct ConversionTable table[] =
321 { 322 {{"B", 1},
322 { "B", 1}, 323 {"KiB", 1024},
323 { "KiB", 1024}, 324 {"kB", 1000},
324 { "kB", 1000}, 325 {"MiB", 1024 * 1024},
325 { "MiB", 1024 * 1024}, 326 {"MB", 1000 * 1000},
326 { "MB", 1000 * 1000}, 327 {"GiB", 1024 * 1024 * 1024},
327 { "GiB", 1024 * 1024 * 1024}, 328 {"GB", 1000 * 1000 * 1000},
328 { "GB", 1000 * 1000 * 1000}, 329 {"TiB", 1024LL * 1024LL * 1024LL * 1024LL},
329 { "TiB", 1024LL * 1024LL * 1024LL * 1024LL}, 330 {"TB", 1000LL * 1000LL * 1000LL * 1024LL},
330 { "TB", 1000LL * 1000LL * 1000LL * 1024LL}, 331 {"PiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL},
331 { "PiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL}, 332 {"PB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL},
332 { "PB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL}, 333 {"EiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL},
333 { "EiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL}, 334 {"EB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL * 1000LL},
334 { "EB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL * 1000LL}, 335 {NULL, 0}};
335 { NULL, 0} 336
336 }; 337 return convert_with_table (fancy_size, table, size);
337
338 return convert_with_table (fancy_size,
339 table,
340 size);
341} 338}
342 339
343 340
@@ -354,31 +351,29 @@ GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time,
354 struct GNUNET_TIME_Relative *rtime) 351 struct GNUNET_TIME_Relative *rtime)
355{ 352{
356 static const struct ConversionTable table[] = 353 static const struct ConversionTable table[] =
357 { 354 {{"us", 1},
358 { "us", 1}, 355 {"ms", 1000},
359 { "ms", 1000 }, 356 {"s", 1000 * 1000LL},
360 { "s", 1000 * 1000LL }, 357 {"second", 1000 * 1000LL},
361 { "second", 1000 * 1000LL }, 358 {"seconds", 1000 * 1000LL},
362 { "seconds", 1000 * 1000LL }, 359 {"\"", 1000 * 1000LL},
363 { "\"", 1000 * 1000LL }, 360 {"m", 60 * 1000 * 1000LL},
364 { "m", 60 * 1000 * 1000LL}, 361 {"min", 60 * 1000 * 1000LL},
365 { "min", 60 * 1000 * 1000LL}, 362 {"minute", 60 * 1000 * 1000LL},
366 { "minute", 60 * 1000 * 1000LL}, 363 {"minutes", 60 * 1000 * 1000LL},
367 { "minutes", 60 * 1000 * 1000LL}, 364 {"'", 60 * 1000 * 1000LL},
368 { "'", 60 * 1000 * 1000LL}, 365 {"h", 60 * 60 * 1000 * 1000LL},
369 { "h", 60 * 60 * 1000 * 1000LL}, 366 {"hour", 60 * 60 * 1000 * 1000LL},
370 { "hour", 60 * 60 * 1000 * 1000LL}, 367 {"hours", 60 * 60 * 1000 * 1000LL},
371 { "hours", 60 * 60 * 1000 * 1000LL}, 368 {"d", 24 * 60 * 60 * 1000LL * 1000LL},
372 { "d", 24 * 60 * 60 * 1000LL * 1000LL}, 369 {"day", 24 * 60 * 60 * 1000LL * 1000LL},
373 { "day", 24 * 60 * 60 * 1000LL * 1000LL}, 370 {"days", 24 * 60 * 60 * 1000LL * 1000LL},
374 { "days", 24 * 60 * 60 * 1000LL * 1000LL}, 371 {"week", 7 * 24 * 60 * 60 * 1000LL * 1000LL},
375 { "week", 7 * 24 * 60 * 60 * 1000LL * 1000LL}, 372 {"weeks", 7 * 24 * 60 * 60 * 1000LL * 1000LL},
376 { "weeks", 7 * 24 * 60 * 60 * 1000LL * 1000LL}, 373 {"year", 31536000000000LL /* year */},
377 { "year", 31536000000000LL /* year */ }, 374 {"years", 31536000000000LL /* year */},
378 { "years", 31536000000000LL /* year */ }, 375 {"a", 31536000000000LL /* year */},
379 { "a", 31536000000000LL /* year */ }, 376 {NULL, 0}};
380 { NULL, 0}
381 };
382 int ret; 377 int ret;
383 unsigned long long val; 378 unsigned long long val;
384 379
@@ -387,9 +382,7 @@ GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time,
387 *rtime = GNUNET_TIME_UNIT_FOREVER_REL; 382 *rtime = GNUNET_TIME_UNIT_FOREVER_REL;
388 return GNUNET_OK; 383 return GNUNET_OK;
389 } 384 }
390 ret = convert_with_table (fancy_time, 385 ret = convert_with_table (fancy_time, table, &val);
391 table,
392 &val);
393 rtime->rel_value_us = (uint64_t) val; 386 rtime->rel_value_us = (uint64_t) val;
394 return ret; 387 return ret;
395} 388}
@@ -412,24 +405,23 @@ GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time,
412 time_t t; 405 time_t t;
413 const char *eos; 406 const char *eos;
414 407
415 if (0 == strcasecmp ("end of time", 408 if (0 == strcasecmp ("end of time", fancy_time))
416 fancy_time))
417 { 409 {
418 *atime = GNUNET_TIME_UNIT_FOREVER_ABS; 410 *atime = GNUNET_TIME_UNIT_FOREVER_ABS;
419 return GNUNET_OK; 411 return GNUNET_OK;
420 } 412 }
421 eos = &fancy_time[strlen (fancy_time)]; 413 eos = &fancy_time[strlen (fancy_time)];
422 memset (&tv, 0, sizeof (tv)); 414 memset (&tv, 0, sizeof (tv));
423 if ( (eos != strptime (fancy_time, "%a %b %d %H:%M:%S %Y", &tv)) && 415 if ((eos != strptime (fancy_time, "%a %b %d %H:%M:%S %Y", &tv)) &&
424 (eos != strptime (fancy_time, "%c", &tv)) && 416 (eos != strptime (fancy_time, "%c", &tv)) &&
425 (eos != strptime (fancy_time, "%Ec", &tv)) && 417 (eos != strptime (fancy_time, "%Ec", &tv)) &&
426 (eos != strptime (fancy_time, "%Y-%m-%d %H:%M:%S", &tv)) && 418 (eos != strptime (fancy_time, "%Y-%m-%d %H:%M:%S", &tv)) &&
427 (eos != strptime (fancy_time, "%Y-%m-%d %H:%M", &tv)) && 419 (eos != strptime (fancy_time, "%Y-%m-%d %H:%M", &tv)) &&
428 (eos != strptime (fancy_time, "%x", &tv)) && 420 (eos != strptime (fancy_time, "%x", &tv)) &&
429 (eos != strptime (fancy_time, "%Ex", &tv)) && 421 (eos != strptime (fancy_time, "%Ex", &tv)) &&
430 (eos != strptime (fancy_time, "%Y-%m-%d", &tv)) && 422 (eos != strptime (fancy_time, "%Y-%m-%d", &tv)) &&
431 (eos != strptime (fancy_time, "%Y-%m", &tv)) && 423 (eos != strptime (fancy_time, "%Y-%m", &tv)) &&
432 (eos != strptime (fancy_time, "%Y", &tv)) ) 424 (eos != strptime (fancy_time, "%Y", &tv)))
433 return GNUNET_SYSERR; 425 return GNUNET_SYSERR;
434 t = mktime (&tv); 426 t = mktime (&tv);
435 atime->abs_value_us = (uint64_t) ((uint64_t) t * 1000LL * 1000LL); 427 atime->abs_value_us = (uint64_t) ((uint64_t) t * 1000LL * 1000LL);
@@ -452,9 +444,9 @@ GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time,
452 */ 444 */
453char * 445char *
454GNUNET_STRINGS_conv (const char *input, 446GNUNET_STRINGS_conv (const char *input,
455 size_t len, 447 size_t len,
456 const char *input_charset, 448 const char *input_charset,
457 const char *output_charset) 449 const char *output_charset)
458{ 450{
459 char *ret; 451 char *ret;
460 uint8_t *u8_string; 452 uint8_t *u8_string;
@@ -463,10 +455,12 @@ GNUNET_STRINGS_conv (const char *input,
463 size_t encoded_string_length; 455 size_t encoded_string_length;
464 456
465 u8_string = u8_conv_from_encoding (input_charset, 457 u8_string = u8_conv_from_encoding (input_charset,
466 iconveh_error, 458 iconveh_error,
467 input, len, 459 input,
468 NULL, NULL, 460 len,
469 &u8_string_length); 461 NULL,
462 NULL,
463 &u8_string_length);
470 if (NULL == u8_string) 464 if (NULL == u8_string)
471 { 465 {
472 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "u8_conv_from_encoding"); 466 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "u8_conv_from_encoding");
@@ -480,10 +474,13 @@ GNUNET_STRINGS_conv (const char *input,
480 free (u8_string); 474 free (u8_string);
481 return ret; 475 return ret;
482 } 476 }
483 encoded_string = u8_conv_to_encoding (output_charset, iconveh_error, 477 encoded_string = u8_conv_to_encoding (output_charset,
484 u8_string, u8_string_length, 478 iconveh_error,
485 NULL, NULL, 479 u8_string,
486 &encoded_string_length); 480 u8_string_length,
481 NULL,
482 NULL,
483 &encoded_string_length);
487 free (u8_string); 484 free (u8_string);
488 if (NULL == encoded_string) 485 if (NULL == encoded_string)
489 { 486 {
@@ -495,10 +492,11 @@ GNUNET_STRINGS_conv (const char *input,
495 ret[encoded_string_length] = '\0'; 492 ret[encoded_string_length] = '\0';
496 free (encoded_string); 493 free (encoded_string);
497 return ret; 494 return ret;
498 fail: 495fail:
499 LOG (GNUNET_ERROR_TYPE_WARNING, 496 LOG (GNUNET_ERROR_TYPE_WARNING,
500 _("Character sets requested were `%s'->`%s'\n"), 497 _ ("Character sets requested were `%s'->`%s'\n"),
501 "UTF-8", output_charset); 498 "UTF-8",
499 output_charset);
502 ret = GNUNET_malloc (len + 1); 500 ret = GNUNET_malloc (len + 1);
503 GNUNET_memcpy (ret, input, len); 501 GNUNET_memcpy (ret, input, len);
504 ret[len] = '\0'; 502 ret[len] = '\0';
@@ -519,9 +517,7 @@ GNUNET_STRINGS_conv (const char *input,
519 * string is returned. 517 * string is returned.
520 */ 518 */
521char * 519char *
522GNUNET_STRINGS_to_utf8 (const char *input, 520GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset)
523 size_t len,
524 const char *charset)
525{ 521{
526 return GNUNET_STRINGS_conv (input, len, charset, "UTF-8"); 522 return GNUNET_STRINGS_conv (input, len, charset, "UTF-8");
527} 523}
@@ -539,9 +535,7 @@ GNUNET_STRINGS_to_utf8 (const char *input,
539 * string is returned. 535 * string is returned.
540 */ 536 */
541char * 537char *
542GNUNET_STRINGS_from_utf8 (const char *input, 538GNUNET_STRINGS_from_utf8 (const char *input, size_t len, const char *charset)
543 size_t len,
544 const char *charset)
545{ 539{
546 return GNUNET_STRINGS_conv (input, len, "UTF-8", charset); 540 return GNUNET_STRINGS_conv (input, len, "UTF-8", charset);
547} 541}
@@ -555,17 +549,20 @@ GNUNET_STRINGS_from_utf8 (const char *input,
555 * @param output output buffer 549 * @param output output buffer
556 */ 550 */
557void 551void
558GNUNET_STRINGS_utf8_tolower (const char *input, 552GNUNET_STRINGS_utf8_tolower (const char *input, char *output)
559 char *output)
560{ 553{
561 uint8_t *tmp_in; 554 uint8_t *tmp_in;
562 size_t len; 555 size_t len;
563 556
564 tmp_in = u8_tolower ((uint8_t*)input, strlen ((char *) input), 557 tmp_in = u8_tolower ((uint8_t *) input,
565 NULL, UNINORM_NFD, NULL, &len); 558 strlen ((char *) input),
566 GNUNET_memcpy(output, tmp_in, len); 559 NULL,
560 UNINORM_NFD,
561 NULL,
562 &len);
563 GNUNET_memcpy (output, tmp_in, len);
567 output[len] = '\0'; 564 output[len] = '\0';
568 free(tmp_in); 565 free (tmp_in);
569} 566}
570 567
571 568
@@ -577,14 +574,17 @@ GNUNET_STRINGS_utf8_tolower (const char *input,
577 * @param output output buffer 574 * @param output output buffer
578 */ 575 */
579void 576void
580GNUNET_STRINGS_utf8_toupper(const char *input, 577GNUNET_STRINGS_utf8_toupper (const char *input, char *output)
581 char *output)
582{ 578{
583 uint8_t *tmp_in; 579 uint8_t *tmp_in;
584 size_t len; 580 size_t len;
585 581
586 tmp_in = u8_toupper ((uint8_t*)input, strlen ((char *) input), 582 tmp_in = u8_toupper ((uint8_t *) input,
587 NULL, UNINORM_NFD, NULL, &len); 583 strlen ((char *) input),
584 NULL,
585 UNINORM_NFD,
586 NULL,
587 &len);
588 GNUNET_memcpy (output, tmp_in, len); 588 GNUNET_memcpy (output, tmp_in, len);
589 output[len] = '\0'; 589 output[len] = '\0';
590 free (tmp_in); 590 free (tmp_in);
@@ -624,7 +624,7 @@ GNUNET_STRINGS_filename_expand (const char *fil)
624 if (fm == NULL) 624 if (fm == NULL)
625 { 625 {
626 LOG (GNUNET_ERROR_TYPE_WARNING, 626 LOG (GNUNET_ERROR_TYPE_WARNING,
627 _("Failed to expand `$HOME': environment variable `HOME' not set")); 627 _ ("Failed to expand `$HOME': environment variable `HOME' not set"));
628 return NULL; 628 return NULL;
629 } 629 }
630 fm = GNUNET_strdup (fm); 630 fm = GNUNET_strdup (fm);
@@ -660,20 +660,20 @@ GNUNET_STRINGS_filename_expand (const char *fil)
660 } 660 }
661 if (fm == NULL) 661 if (fm == NULL)
662 { 662 {
663 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, 663 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "getcwd");
664 "getcwd"); 664 buffer = getenv ("PWD"); /* alternative */
665 buffer = getenv ("PWD"); /* alternative */
666 if (buffer != NULL) 665 if (buffer != NULL)
667 fm = GNUNET_strdup (buffer); 666 fm = GNUNET_strdup (buffer);
668 } 667 }
669 if (fm == NULL) 668 if (fm == NULL)
670 fm = GNUNET_strdup ("./"); /* give up */ 669 fm = GNUNET_strdup ("./"); /* give up */
671 } 670 }
672 GNUNET_asprintf (&buffer, 671 GNUNET_asprintf (&buffer,
673 "%s%s%s", 672 "%s%s%s",
674 fm, 673 fm,
675 (fm[strlen (fm) - 1] == 674 (fm[strlen (fm) - 1] == DIR_SEPARATOR) ? ""
676 DIR_SEPARATOR) ? "" : DIR_SEPARATOR_STR, fil_ptr); 675 : DIR_SEPARATOR_STR,
676 fil_ptr);
677 GNUNET_free (fm); 677 GNUNET_free (fm);
678 return buffer; 678 return buffer;
679#else 679#else
@@ -682,29 +682,22 @@ GNUNET_STRINGS_filename_expand (const char *fil)
682 if ((lRet = plibc_conv_to_win_path (fil, fn)) != ERROR_SUCCESS) 682 if ((lRet = plibc_conv_to_win_path (fil, fn)) != ERROR_SUCCESS)
683 { 683 {
684 SetErrnoFromWinError (lRet); 684 SetErrnoFromWinError (lRet);
685 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, 685 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "plibc_conv_to_win_path");
686 "plibc_conv_to_win_path");
687 return NULL; 686 return NULL;
688 } 687 }
689 /* is the path relative? */ 688 /* is the path relative? */
690 if ( (0 != strncmp (fn + 1, ":\\", 2)) && 689 if ((0 != strncmp (fn + 1, ":\\", 2)) && (0 != strncmp (fn, "\\\\", 2)))
691 (0 != strncmp (fn, "\\\\", 2)) )
692 { 690 {
693 char szCurDir[MAX_PATH + 1]; 691 char szCurDir[MAX_PATH + 1];
694 692
695 lRet = GetCurrentDirectory (MAX_PATH + 1, 693 lRet = GetCurrentDirectory (MAX_PATH + 1, szCurDir);
696 szCurDir);
697 if (lRet + strlen (fn) + 1 > (MAX_PATH + 1)) 694 if (lRet + strlen (fn) + 1 > (MAX_PATH + 1))
698 { 695 {
699 SetErrnoFromWinError (ERROR_BUFFER_OVERFLOW); 696 SetErrnoFromWinError (ERROR_BUFFER_OVERFLOW);
700 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, 697 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "GetCurrentDirectory");
701 "GetCurrentDirectory");
702 return NULL; 698 return NULL;
703 } 699 }
704 GNUNET_asprintf (&buffer, 700 GNUNET_asprintf (&buffer, "%s\\%s", szCurDir, fn);
705 "%s\\%s",
706 szCurDir,
707 fn);
708 GNUNET_free (fn); 701 GNUNET_free (fn);
709 fn = buffer; 702 fn = buffer;
710 } 703 }
@@ -725,56 +718,46 @@ GNUNET_STRINGS_filename_expand (const char *fil)
725 */ 718 */
726const char * 719const char *
727GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta, 720GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta,
728 int do_round) 721 int do_round)
729{ 722{
730 static char buf[128]; 723 static char buf[128];
731 const char *unit = _( /* time unit */ "µs"); 724 const char *unit = _ (/* time unit */ "µs");
732 uint64_t dval = delta.rel_value_us; 725 uint64_t dval = delta.rel_value_us;
733 726
734 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == delta.rel_value_us) 727 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == delta.rel_value_us)
735 return _("forever"); 728 return _ ("forever");
736 if (0 == delta.rel_value_us) 729 if (0 == delta.rel_value_us)
737 return _("0 ms"); 730 return _ ("0 ms");
738 if ( ( (GNUNET_YES == do_round) && 731 if (((GNUNET_YES == do_round) && (dval > 5 * 1000)) || (0 == (dval % 1000)))
739 (dval > 5 * 1000) ) ||
740 (0 == (dval % 1000) ))
741 { 732 {
742 dval = dval / 1000; 733 dval = dval / 1000;
743 unit = _( /* time unit */ "ms"); 734 unit = _ (/* time unit */ "ms");
744 if ( ( (GNUNET_YES == do_round) && 735 if (((GNUNET_YES == do_round) && (dval > 5 * 1000)) || (0 == (dval % 1000)))
745 (dval > 5 * 1000) ) ||
746 (0 == (dval % 1000) ))
747 { 736 {
748 dval = dval / 1000; 737 dval = dval / 1000;
749 unit = _( /* time unit */ "s"); 738 unit = _ (/* time unit */ "s");
750 if ( ( (GNUNET_YES == do_round) && 739 if (((GNUNET_YES == do_round) && (dval > 5 * 60)) || (0 == (dval % 60)))
751 (dval > 5 * 60) ) ||
752 (0 == (dval % 60) ) )
753 { 740 {
754 dval = dval / 60; 741 dval = dval / 60;
755 unit = _( /* time unit */ "m"); 742 unit = _ (/* time unit */ "m");
756 if ( ( (GNUNET_YES == do_round) && 743 if (((GNUNET_YES == do_round) && (dval > 5 * 60)) || (0 == (dval % 60)))
757 (dval > 5 * 60) ) || 744 {
758 (0 == (dval % 60) )) 745 dval = dval / 60;
759 { 746 unit = _ (/* time unit */ "h");
760 dval = dval / 60; 747 if (((GNUNET_YES == do_round) && (dval > 5 * 24)) ||
761 unit = _( /* time unit */ "h"); 748 (0 == (dval % 24)))
762 if ( ( (GNUNET_YES == do_round) && 749 {
763 (dval > 5 * 24) ) || 750 dval = dval / 24;
764 (0 == (dval % 24)) ) 751 if (1 == dval)
765 { 752 unit = _ (/* time unit */ "day");
766 dval = dval / 24; 753 else
767 if (1 == dval) 754 unit = _ (/* time unit */ "days");
768 unit = _( /* time unit */ "day"); 755 }
769 else 756 }
770 unit = _( /* time unit */ "days");
771 }
772 }
773 } 757 }
774 } 758 }
775 } 759 }
776 GNUNET_snprintf (buf, sizeof (buf), 760 GNUNET_snprintf (buf, sizeof (buf), "%llu %s", dval, unit);
777 "%llu %s", dval, unit);
778 return buf; 761 return buf;
779} 762}
780 763
@@ -796,7 +779,7 @@ GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t)
796 struct tm *tp; 779 struct tm *tp;
797 780
798 if (t.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) 781 if (t.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
799 return _("end of time"); 782 return _ ("end of time");
800 tt = t.abs_value_us / 1000LL / 1000LL; 783 tt = t.abs_value_us / 1000LL / 1000LL;
801 tp = localtime (&tt); 784 tp = localtime (&tt);
802 /* This is hacky, but i don't know a way to detect libc character encoding. 785 /* This is hacky, but i don't know a way to detect libc character encoding.
@@ -813,12 +796,16 @@ GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t)
813 uint8_t *conved; 796 uint8_t *conved;
814 size_t ssize; 797 size_t ssize;
815 798
816 wcsftime (wbuf, sizeof (wbuf) / sizeof (wchar_t), 799 wcsftime (wbuf,
817 L"%a %b %d %H:%M:%S %Y", tp); 800 sizeof (wbuf) / sizeof (wchar_t),
801 L"%a %b %d %H:%M:%S %Y",
802 tp);
818 803
819 ssize = sizeof (buf); 804 ssize = sizeof (buf);
820 conved = u16_to_u8 (wbuf, sizeof (wbuf) / sizeof (wchar_t), 805 conved = u16_to_u8 (wbuf,
821 (uint8_t *) buf, &ssize); 806 sizeof (wbuf) / sizeof (wchar_t),
807 (uint8_t *) buf,
808 &ssize);
822 if (conved != (uint8_t *) buf) 809 if (conved != (uint8_t *) buf)
823 { 810 {
824 GNUNET_strlcpy (buf, (char *) conved, sizeof (buf)); 811 GNUNET_strlcpy (buf, (char *) conved, sizeof (buf));
@@ -847,8 +834,7 @@ GNUNET_STRINGS_get_short_name (const char *filename)
847 const char *short_fn = filename; 834 const char *short_fn = filename;
848 const char *ss; 835 const char *ss;
849 836
850 while (NULL != (ss = strstr (short_fn, DIR_SEPARATOR_STR)) 837 while (NULL != (ss = strstr (short_fn, DIR_SEPARATOR_STR)) && (ss[1] != '\0'))
851 && (ss[1] != '\0'))
852 short_fn = 1 + ss; 838 short_fn = 1 + ss;
853 return short_fn; 839 return short_fn;
854} 840}
@@ -890,7 +876,7 @@ getValue__ (unsigned char a)
890 return a - '0'; 876 return a - '0';
891 if ((a >= 'a') && (a <= 'z')) 877 if ((a >= 'a') && (a <= 'z'))
892 a = toupper (a); 878 a = toupper (a);
893 /* return (a - 'a' + 10); */ 879 /* return (a - 'a' + 10); */
894 dec = 0; 880 dec = 0;
895 if ((a >= 'A') && (a <= 'Z')) 881 if ((a >= 'A') && (a <= 'Z'))
896 { 882 {
@@ -950,12 +936,12 @@ GNUNET_STRINGS_data_to_string (const void *data,
950 { 936 {
951 if ((rpos < size) && (vbit < 5)) 937 if ((rpos < size) && (vbit < 5))
952 { 938 {
953 bits = (bits << 8) | udata[rpos++]; /* eat 8 more bits */ 939 bits = (bits << 8) | udata[rpos++]; /* eat 8 more bits */
954 vbit += 8; 940 vbit += 8;
955 } 941 }
956 if (vbit < 5) 942 if (vbit < 5)
957 { 943 {
958 bits <<= (5 - vbit); /* zero-padding */ 944 bits <<= (5 - vbit); /* zero-padding */
959 GNUNET_assert (vbit == ((size * 8) % 5)); 945 GNUNET_assert (vbit == ((size * 8) % 5));
960 vbit = 5; 946 vbit = 5;
961 } 947 }
@@ -985,8 +971,7 @@ GNUNET_STRINGS_data_to_string (const void *data,
985 * @return freshly allocated, null-terminated string 971 * @return freshly allocated, null-terminated string
986 */ 972 */
987char * 973char *
988GNUNET_STRINGS_data_to_string_alloc (const void *buf, 974GNUNET_STRINGS_data_to_string_alloc (const void *buf, size_t size)
989 size_t size)
990{ 975{
991 char *str_buf; 976 char *str_buf;
992 size_t len = size * 8; 977 size_t len = size * 8;
@@ -1018,8 +1003,10 @@ GNUNET_STRINGS_data_to_string_alloc (const void *buf,
1018 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding 1003 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding
1019 */ 1004 */
1020int 1005int
1021GNUNET_STRINGS_string_to_data (const char *enc, size_t enclen, 1006GNUNET_STRINGS_string_to_data (const char *enc,
1022 void *out, size_t out_size) 1007 size_t enclen,
1008 void *out,
1009 size_t out_size)
1023{ 1010{
1024 unsigned int rpos; 1011 unsigned int rpos;
1025 unsigned int wpos; 1012 unsigned int wpos;
@@ -1073,8 +1060,7 @@ GNUNET_STRINGS_string_to_data (const char *enc, size_t enclen,
1073 vbit -= 8; 1060 vbit -= 8;
1074 } 1061 }
1075 } 1062 }
1076 if ( (0 != rpos) || 1063 if ((0 != rpos) || (0 != vbit))
1077 (0 != vbit) )
1078 return GNUNET_SYSERR; 1064 return GNUNET_SYSERR;
1079 return GNUNET_OK; 1065 return GNUNET_OK;
1080} 1066}
@@ -1098,8 +1084,8 @@ GNUNET_STRINGS_string_to_data (const char *enc, size_t enclen,
1098 */ 1084 */
1099int 1085int
1100GNUNET_STRINGS_parse_uri (const char *path, 1086GNUNET_STRINGS_parse_uri (const char *path,
1101 char **scheme_part, 1087 char **scheme_part,
1102 const char **path_part) 1088 const char **path_part)
1103{ 1089{
1104 size_t len; 1090 size_t len;
1105 size_t i; 1091 size_t i;
@@ -1107,19 +1093,20 @@ GNUNET_STRINGS_parse_uri (const char *path,
1107 int pp_state = 0; 1093 int pp_state = 0;
1108 const char *post_scheme_part = NULL; 1094 const char *post_scheme_part = NULL;
1109 len = strlen (path); 1095 len = strlen (path);
1110 for (end = 0, i = 0; !end && i < len; i++) 1096 for (end = 0, i = 0; ! end && i < len; i++)
1111 { 1097 {
1112 switch (pp_state) 1098 switch (pp_state)
1113 { 1099 {
1114 case 0: 1100 case 0:
1115 if ( (path[i] == ':') && (i > 0) ) 1101 if ((path[i] == ':') && (i > 0))
1116 { 1102 {
1117 pp_state += 1; 1103 pp_state += 1;
1118 continue; 1104 continue;
1119 } 1105 }
1120 if (!((path[i] >= 'A' && path[i] <= 'Z') || (path[i] >= 'a' && path[i] <= 'z') 1106 if (! ((path[i] >= 'A' && path[i] <= 'Z') ||
1121 || (path[i] >= '0' && path[i] <= '9') || path[i] == '+' || path[i] == '-' 1107 (path[i] >= 'a' && path[i] <= 'z') ||
1122 || (path[i] == '.'))) 1108 (path[i] >= '0' && path[i] <= '9') || path[i] == '+' ||
1109 path[i] == '-' || (path[i] == '.')))
1123 end = 1; 1110 end = 1;
1124 break; 1111 break;
1125 case 1: 1112 case 1:
@@ -1178,7 +1165,7 @@ GNUNET_STRINGS_path_is_absolute (const char *filename,
1178#endif 1165#endif
1179 const char *post_scheme_path; 1166 const char *post_scheme_path;
1180 int is_uri; 1167 int is_uri;
1181 char * uri; 1168 char *uri;
1182 /* consider POSIX paths to be absolute too, even on W32, 1169 /* consider POSIX paths to be absolute too, even on W32,
1183 * as plibc expansion will fix them for us. 1170 * as plibc expansion will fix them for us.
1184 */ 1171 */
@@ -1196,14 +1183,17 @@ GNUNET_STRINGS_path_is_absolute (const char *filename,
1196 else 1183 else
1197 GNUNET_free_non_null (uri); 1184 GNUNET_free_non_null (uri);
1198#if WINDOWS 1185#if WINDOWS
1199 len = strlen(post_scheme_path); 1186 len = strlen (post_scheme_path);
1200 /* Special check for file:///c:/blah 1187 /* Special check for file:///c:/blah
1201 * We want to parse 'c:/', not '/c:/' 1188 * We want to parse 'c:/', not '/c:/'
1202 */ 1189 */
1203 if (post_scheme_path[0] == '/' && len >= 3 && post_scheme_path[2] == ':') 1190 if (post_scheme_path[0] == '/' && len >= 3 && post_scheme_path[2] == ':')
1204 post_scheme_path = &post_scheme_path[1]; 1191 post_scheme_path = &post_scheme_path[1];
1205#endif 1192#endif
1206 return GNUNET_STRINGS_path_is_absolute (post_scheme_path, GNUNET_NO, NULL, NULL); 1193 return GNUNET_STRINGS_path_is_absolute (post_scheme_path,
1194 GNUNET_NO,
1195 NULL,
1196 NULL);
1207 } 1197 }
1208 } 1198 }
1209 else 1199 else
@@ -1214,18 +1204,18 @@ GNUNET_STRINGS_path_is_absolute (const char *filename,
1214#if WINDOWS 1204#if WINDOWS
1215 len = strlen (filename); 1205 len = strlen (filename);
1216 if (len >= 3 && 1206 if (len >= 3 &&
1217 ((filename[0] >= 'A' && filename[0] <= 'Z') 1207 ((filename[0] >= 'A' && filename[0] <= 'Z') ||
1218 || (filename[0] >= 'a' && filename[0] <= 'z')) 1208 (filename[0] >= 'a' && filename[0] <= 'z')) &&
1219 && filename[1] == ':' && (filename[2] == '/' || filename[2] == '\\')) 1209 filename[1] == ':' && (filename[2] == '/' || filename[2] == '\\'))
1220 return GNUNET_YES; 1210 return GNUNET_YES;
1221#endif 1211#endif
1222 return GNUNET_NO; 1212 return GNUNET_NO;
1223} 1213}
1224 1214
1225#if MINGW 1215#if MINGW
1226#define _IFMT 0170000 /* type of file */ 1216#define _IFMT 0170000 /* type of file */
1227#define _IFLNK 0120000 /* symbolic link */ 1217#define _IFLNK 0120000 /* symbolic link */
1228#define S_ISLNK(m) (((m)&_IFMT) == _IFLNK) 1218#define S_ISLNK(m) (((m) &_IFMT) == _IFLNK)
1229#endif 1219#endif
1230 1220
1231 1221
@@ -1239,19 +1229,19 @@ GNUNET_STRINGS_path_is_absolute (const char *filename,
1239 */ 1229 */
1240int 1230int
1241GNUNET_STRINGS_check_filename (const char *filename, 1231GNUNET_STRINGS_check_filename (const char *filename,
1242 enum GNUNET_STRINGS_FilenameCheck checks) 1232 enum GNUNET_STRINGS_FilenameCheck checks)
1243{ 1233{
1244 struct stat st; 1234 struct stat st;
1245 if ( (NULL == filename) || (filename[0] == '\0') ) 1235 if ((NULL == filename) || (filename[0] == '\0'))
1246 return GNUNET_SYSERR; 1236 return GNUNET_SYSERR;
1247 if (0 != (checks & GNUNET_STRINGS_CHECK_IS_ABSOLUTE)) 1237 if (0 != (checks & GNUNET_STRINGS_CHECK_IS_ABSOLUTE))
1248 if (!GNUNET_STRINGS_path_is_absolute (filename, GNUNET_NO, NULL, NULL)) 1238 if (! GNUNET_STRINGS_path_is_absolute (filename, GNUNET_NO, NULL, NULL))
1249 return GNUNET_NO; 1239 return GNUNET_NO;
1250 if (0 != (checks & (GNUNET_STRINGS_CHECK_EXISTS 1240 if (0 != (checks &
1251 | GNUNET_STRINGS_CHECK_IS_DIRECTORY 1241 (GNUNET_STRINGS_CHECK_EXISTS | GNUNET_STRINGS_CHECK_IS_DIRECTORY |
1252 | GNUNET_STRINGS_CHECK_IS_LINK))) 1242 GNUNET_STRINGS_CHECK_IS_LINK)))
1253 { 1243 {
1254 if (0 != STAT (filename, &st)) 1244 if (0 != stat (filename, &st))
1255 { 1245 {
1256 if (0 != (checks & GNUNET_STRINGS_CHECK_EXISTS)) 1246 if (0 != (checks & GNUNET_STRINGS_CHECK_EXISTS))
1257 return GNUNET_NO; 1247 return GNUNET_NO;
@@ -1260,10 +1250,10 @@ GNUNET_STRINGS_check_filename (const char *filename,
1260 } 1250 }
1261 } 1251 }
1262 if (0 != (checks & GNUNET_STRINGS_CHECK_IS_DIRECTORY)) 1252 if (0 != (checks & GNUNET_STRINGS_CHECK_IS_DIRECTORY))
1263 if (!S_ISDIR (st.st_mode)) 1253 if (! S_ISDIR (st.st_mode))
1264 return GNUNET_NO; 1254 return GNUNET_NO;
1265 if (0 != (checks & GNUNET_STRINGS_CHECK_IS_LINK)) 1255 if (0 != (checks & GNUNET_STRINGS_CHECK_IS_LINK))
1266 if (!S_ISLNK (st.st_mode)) 1256 if (! S_ISLNK (st.st_mode))
1267 return GNUNET_NO; 1257 return GNUNET_NO;
1268 return GNUNET_YES; 1258 return GNUNET_YES;
1269} 1259}
@@ -1283,8 +1273,8 @@ GNUNET_STRINGS_check_filename (const char *filename,
1283 */ 1273 */
1284int 1274int
1285GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr, 1275GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
1286 uint16_t addrlen, 1276 uint16_t addrlen,
1287 struct sockaddr_in6 *r_buf) 1277 struct sockaddr_in6 *r_buf)
1288{ 1278{
1289 char zbuf[addrlen + 1]; 1279 char zbuf[addrlen + 1];
1290 int ret; 1280 int ret;
@@ -1298,7 +1288,7 @@ GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
1298 if ('[' != zbuf[0]) 1288 if ('[' != zbuf[0])
1299 { 1289 {
1300 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1290 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1301 _("IPv6 address did not start with `['\n")); 1291 _ ("IPv6 address did not start with `['\n"));
1302 return GNUNET_SYSERR; 1292 return GNUNET_SYSERR;
1303 } 1293 }
1304 zbuf[addrlen] = '\0'; 1294 zbuf[addrlen] = '\0';
@@ -1306,34 +1296,33 @@ GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
1306 if (NULL == port_colon) 1296 if (NULL == port_colon)
1307 { 1297 {
1308 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1298 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1309 _("IPv6 address did contain ':' to separate port number\n")); 1299 _ ("IPv6 address did contain ':' to separate port number\n"));
1310 return GNUNET_SYSERR; 1300 return GNUNET_SYSERR;
1311 } 1301 }
1312 if (']' != *(port_colon - 1)) 1302 if (']' != *(port_colon - 1))
1313 { 1303 {
1314 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1304 GNUNET_log (
1315 _("IPv6 address did contain ']' before ':' to separate port number\n")); 1305 GNUNET_ERROR_TYPE_WARNING,
1306 _ ("IPv6 address did contain ']' before ':' to separate port number\n"));
1316 return GNUNET_SYSERR; 1307 return GNUNET_SYSERR;
1317 } 1308 }
1318 ret = SSCANF (port_colon, 1309 ret = sscanf (port_colon, ":%u%1s", &port, dummy);
1319 ":%u%1s", 1310 if ((1 != ret) || (port > 65535))
1320 &port,
1321 dummy);
1322 if ( (1 != ret) || (port > 65535) )
1323 { 1311 {
1324 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1312 GNUNET_log (
1325 _("IPv6 address did contain a valid port number after the last ':'\n")); 1313 GNUNET_ERROR_TYPE_WARNING,
1314 _ ("IPv6 address did contain a valid port number after the last ':'\n"));
1326 return GNUNET_SYSERR; 1315 return GNUNET_SYSERR;
1327 } 1316 }
1328 *(port_colon-1) = '\0'; 1317 *(port_colon - 1) = '\0';
1329 memset (r_buf, 0, sizeof (struct sockaddr_in6)); 1318 memset (r_buf, 0, sizeof (struct sockaddr_in6));
1330 ret = inet_pton (AF_INET6, &zbuf[1], &r_buf->sin6_addr); 1319 ret = inet_pton (AF_INET6, &zbuf[1], &r_buf->sin6_addr);
1331 if (ret <= 0) 1320 if (ret <= 0)
1332 { 1321 {
1333 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1322 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1334 _("Invalid IPv6 address `%s': %s\n"), 1323 _ ("Invalid IPv6 address `%s': %s\n"),
1335 &zbuf[1], 1324 &zbuf[1],
1336 STRERROR (errno)); 1325 strerror (errno));
1337 return GNUNET_SYSERR; 1326 return GNUNET_SYSERR;
1338 } 1327 }
1339 r_buf->sin6_port = htons (port); 1328 r_buf->sin6_port = htons (port);
@@ -1358,8 +1347,8 @@ GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
1358 */ 1347 */
1359int 1348int
1360GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr, 1349GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr,
1361 uint16_t addrlen, 1350 uint16_t addrlen,
1362 struct sockaddr_in *r_buf) 1351 struct sockaddr_in *r_buf)
1363{ 1352{
1364 unsigned int temps[4]; 1353 unsigned int temps[4];
1365 unsigned int port; 1354 unsigned int port;
@@ -1368,14 +1357,14 @@ GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr,
1368 1357
1369 if (addrlen < 9) 1358 if (addrlen < 9)
1370 return GNUNET_SYSERR; 1359 return GNUNET_SYSERR;
1371 cnt = SSCANF (zt_addr, 1360 cnt = sscanf (zt_addr,
1372 "%u.%u.%u.%u:%u%1s", 1361 "%u.%u.%u.%u:%u%1s",
1373 &temps[0], 1362 &temps[0],
1374 &temps[1], 1363 &temps[1],
1375 &temps[2], 1364 &temps[2],
1376 &temps[3], 1365 &temps[3],
1377 &port, 1366 &port,
1378 dummy); 1367 dummy);
1379 if (5 != cnt) 1368 if (5 != cnt)
1380 return GNUNET_SYSERR; 1369 return GNUNET_SYSERR;
1381 for (cnt = 0; cnt < 4; cnt++) 1370 for (cnt = 0; cnt < 4; cnt++)
@@ -1385,8 +1374,8 @@ GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr,
1385 return GNUNET_SYSERR; 1374 return GNUNET_SYSERR;
1386 r_buf->sin_family = AF_INET; 1375 r_buf->sin_family = AF_INET;
1387 r_buf->sin_port = htons (port); 1376 r_buf->sin_port = htons (port);
1388 r_buf->sin_addr.s_addr = htonl ((temps[0] << 24) + (temps[1] << 16) + 1377 r_buf->sin_addr.s_addr =
1389 (temps[2] << 8) + temps[3]); 1378 htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + temps[3]);
1390#if HAVE_SOCKADDR_IN_SIN_LEN 1379#if HAVE_SOCKADDR_IN_SIN_LEN
1391 r_buf->sin_len = (u_char) sizeof (struct sockaddr_in); 1380 r_buf->sin_len = (u_char) sizeof (struct sockaddr_in);
1392#endif 1381#endif
@@ -1407,8 +1396,8 @@ GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr,
1407 */ 1396 */
1408int 1397int
1409GNUNET_STRINGS_to_address_ip (const char *addr, 1398GNUNET_STRINGS_to_address_ip (const char *addr,
1410 uint16_t addrlen, 1399 uint16_t addrlen,
1411 struct sockaddr_storage *r_buf) 1400 struct sockaddr_storage *r_buf)
1412{ 1401{
1413 if (addr[0] == '[') 1402 if (addr[0] == '[')
1414 return GNUNET_STRINGS_to_address_ipv6 (addr, 1403 return GNUNET_STRINGS_to_address_ipv6 (addr,
@@ -1431,8 +1420,8 @@ GNUNET_STRINGS_to_address_ip (const char *addr,
1431 */ 1420 */
1432size_t 1421size_t
1433GNUNET_STRINGS_parse_socket_addr (const char *addr, 1422GNUNET_STRINGS_parse_socket_addr (const char *addr,
1434 uint8_t *af, 1423 uint8_t *af,
1435 struct sockaddr **sa) 1424 struct sockaddr **sa)
1436{ 1425{
1437 char *cp = GNUNET_strdup (addr); 1426 char *cp = GNUNET_strdup (addr);
1438 1427
@@ -1442,9 +1431,9 @@ GNUNET_STRINGS_parse_socket_addr (const char *addr,
1442 /* IPv6 */ 1431 /* IPv6 */
1443 *sa = GNUNET_malloc (sizeof (struct sockaddr_in6)); 1432 *sa = GNUNET_malloc (sizeof (struct sockaddr_in6));
1444 if (GNUNET_OK != 1433 if (GNUNET_OK !=
1445 GNUNET_STRINGS_to_address_ipv6 (cp, 1434 GNUNET_STRINGS_to_address_ipv6 (cp,
1446 strlen (cp), 1435 strlen (cp),
1447 (struct sockaddr_in6 *) *sa)) 1436 (struct sockaddr_in6 *) *sa))
1448 { 1437 {
1449 GNUNET_free (*sa); 1438 GNUNET_free (*sa);
1450 *sa = NULL; 1439 *sa = NULL;
@@ -1460,9 +1449,9 @@ GNUNET_STRINGS_parse_socket_addr (const char *addr,
1460 /* IPv4 */ 1449 /* IPv4 */
1461 *sa = GNUNET_malloc (sizeof (struct sockaddr_in)); 1450 *sa = GNUNET_malloc (sizeof (struct sockaddr_in));
1462 if (GNUNET_OK != 1451 if (GNUNET_OK !=
1463 GNUNET_STRINGS_to_address_ipv4 (cp, 1452 GNUNET_STRINGS_to_address_ipv4 (cp,
1464 strlen (cp), 1453 strlen (cp),
1465 (struct sockaddr_in *) *sa)) 1454 (struct sockaddr_in *) *sa))
1466 { 1455 {
1467 GNUNET_free (*sa); 1456 GNUNET_free (*sa);
1468 *sa = NULL; 1457 *sa = NULL;
@@ -1481,8 +1470,7 @@ GNUNET_STRINGS_parse_socket_addr (const char *addr,
1481 * freed with a single call to GNUNET_free(); 1470 * freed with a single call to GNUNET_free();
1482 */ 1471 */
1483static char *const * 1472static char *const *
1484_make_continuous_arg_copy (int argc, 1473_make_continuous_arg_copy (int argc, char *const *argv)
1485 char *const *argv)
1486{ 1474{
1487 size_t argvsize = 0; 1475 size_t argvsize = 0;
1488 int i; 1476 int i;
@@ -1519,9 +1507,9 @@ _make_continuous_arg_copy (int argc,
1519 */ 1507 */
1520int 1508int
1521GNUNET_STRINGS_get_utf8_args (int argc, 1509GNUNET_STRINGS_get_utf8_args (int argc,
1522 char *const *argv, 1510 char *const *argv,
1523 int *u8argc, 1511 int *u8argc,
1524 char *const **u8argv) 1512 char *const **u8argv)
1525{ 1513{
1526#if WINDOWS 1514#if WINDOWS
1527 wchar_t *wcmd; 1515 wchar_t *wcmd;
@@ -1543,7 +1531,8 @@ GNUNET_STRINGS_get_utf8_args (int argc,
1543 { 1531 {
1544 size_t strl; 1532 size_t strl;
1545 /* Hopefully it will allocate us NUL-terminated strings... */ 1533 /* Hopefully it will allocate us NUL-terminated strings... */
1546 split_u8argv[i] = (char *) u16_to_u8 (wargv[i], wcslen (wargv[i]) + 1, NULL, &strl); 1534 split_u8argv[i] =
1535 (char *) u16_to_u8 (wargv[i], wcslen (wargv[i]) + 1, NULL, &strl);
1547 if (NULL == split_u8argv[i]) 1536 if (NULL == split_u8argv[i])
1548 { 1537 {
1549 int j; 1538 int j;
@@ -1563,7 +1552,8 @@ GNUNET_STRINGS_get_utf8_args (int argc,
1563 free (split_u8argv); 1552 free (split_u8argv);
1564 return GNUNET_OK; 1553 return GNUNET_OK;
1565#else 1554#else
1566 char *const *new_argv = (char *const *) _make_continuous_arg_copy (argc, argv); 1555 char *const *new_argv =
1556 (char *const *) _make_continuous_arg_copy (argc, argv);
1567 *u8argv = new_argv; 1557 *u8argv = new_argv;
1568 *u8argc = argc; 1558 *u8argc = argc;
1569 return GNUNET_OK; 1559 return GNUNET_OK;
@@ -1595,35 +1585,22 @@ parse_port_policy (const char *port_policy,
1595 pp->negate_portrange = GNUNET_YES; 1585 pp->negate_portrange = GNUNET_YES;
1596 pos++; 1586 pos++;
1597 } 1587 }
1598 if (2 == sscanf (pos, 1588 if (2 == sscanf (pos, "%u-%u%1s", &s, &e, eol))
1599 "%u-%u%1s",
1600 &s,
1601 &e,
1602 eol))
1603 { 1589 {
1604 if ( (0 == s) || 1590 if ((0 == s) || (s > 0xFFFF) || (e < s) || (e > 0xFFFF))
1605 (s > 0xFFFF) ||
1606 (e < s) ||
1607 (e > 0xFFFF) )
1608 { 1591 {
1609 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1592 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Port not in range\n"));
1610 _("Port not in range\n"));
1611 return GNUNET_SYSERR; 1593 return GNUNET_SYSERR;
1612 } 1594 }
1613 pp->start_port = (uint16_t) s; 1595 pp->start_port = (uint16_t) s;
1614 pp->end_port = (uint16_t) e; 1596 pp->end_port = (uint16_t) e;
1615 return GNUNET_OK; 1597 return GNUNET_OK;
1616 } 1598 }
1617 if (1 == sscanf (pos, 1599 if (1 == sscanf (pos, "%u%1s", &s, eol))
1618 "%u%1s",
1619 &s,
1620 eol))
1621 { 1600 {
1622 if ( (0 == s) || 1601 if ((0 == s) || (s > 0xFFFF))
1623 (s > 0xFFFF) )
1624 { 1602 {
1625 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1603 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Port not in range\n"));
1626 _("Port not in range\n"));
1627 return GNUNET_SYSERR; 1604 return GNUNET_SYSERR;
1628 } 1605 }
1629 1606
@@ -1632,7 +1609,7 @@ parse_port_policy (const char *port_policy,
1632 return GNUNET_OK; 1609 return GNUNET_OK;
1633 } 1610 }
1634 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1611 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1635 _("Malformed port policy `%s'\n"), 1612 _ ("Malformed port policy `%s'\n"),
1636 port_policy); 1613 port_policy);
1637 return GNUNET_SYSERR; 1614 return GNUNET_SYSERR;
1638} 1615}
@@ -1666,7 +1643,7 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX)
1666 int end; 1643 int end;
1667 char *routeList; 1644 char *routeList;
1668 char dummy[2]; 1645 char dummy[2];
1669 1646
1670 if (NULL == routeListX) 1647 if (NULL == routeListX)
1671 return NULL; 1648 return NULL;
1672 len = strlen (routeListX); 1649 len = strlen (routeListX);
@@ -1677,14 +1654,14 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX)
1677 for (i = 0; i < len; i++) 1654 for (i = 0; i < len; i++)
1678 if (routeList[i] == ';') 1655 if (routeList[i] == ';')
1679 count++; 1656 count++;
1680 result = GNUNET_malloc (sizeof (struct GNUNET_STRINGS_IPv4NetworkPolicy) * (count + 1)); 1657 result = GNUNET_malloc (sizeof (struct GNUNET_STRINGS_IPv4NetworkPolicy) *
1658 (count + 1));
1681 i = 0; 1659 i = 0;
1682 pos = 0; 1660 pos = 0;
1683 while (i < count) 1661 while (i < count)
1684 { 1662 {
1685 for (colon = pos; ':' != routeList[colon]; colon++) 1663 for (colon = pos; ':' != routeList[colon]; colon++)
1686 if ( (';' == routeList[colon]) || 1664 if ((';' == routeList[colon]) || ('\0' == routeList[colon]))
1687 ('\0' == routeList[colon]) )
1688 break; 1665 break;
1689 for (end = colon; ';' != routeList[end]; end++) 1666 for (end = colon; ';' != routeList[end]; end++)
1690 if ('\0' == routeList[end]) 1667 if ('\0' == routeList[end])
@@ -1695,76 +1672,70 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX)
1695 if (':' == routeList[colon]) 1672 if (':' == routeList[colon])
1696 { 1673 {
1697 routeList[colon] = '\0'; 1674 routeList[colon] = '\0';
1698 if (GNUNET_OK != parse_port_policy (&routeList[colon + 1], 1675 if (GNUNET_OK != parse_port_policy (&routeList[colon + 1], &result[i].pp))
1699 &result[i].pp))
1700 break; 1676 break;
1701 } 1677 }
1702 cnt = 1678 cnt = sscanf (&routeList[pos],
1703 SSCANF (&routeList[pos], 1679 "%u.%u.%u.%u/%u.%u.%u.%u%1s",
1704 "%u.%u.%u.%u/%u.%u.%u.%u%1s", 1680 &temps[0],
1705 &temps[0], 1681 &temps[1],
1706 &temps[1], 1682 &temps[2],
1707 &temps[2], 1683 &temps[3],
1708 &temps[3], 1684 &temps[4],
1709 &temps[4], 1685 &temps[5],
1710 &temps[5], 1686 &temps[6],
1711 &temps[6], 1687 &temps[7],
1712 &temps[7], 1688 dummy);
1713 dummy);
1714 if (8 == cnt) 1689 if (8 == cnt)
1715 { 1690 {
1716 for (j = 0; j < 8; j++) 1691 for (j = 0; j < 8; j++)
1717 if (temps[j] > 0xFF) 1692 if (temps[j] > 0xFF)
1718 { 1693 {
1719 LOG (GNUNET_ERROR_TYPE_WARNING, 1694 LOG (GNUNET_ERROR_TYPE_WARNING,
1720 _("Invalid format for IP: `%s'\n"), 1695 _ ("Invalid format for IP: `%s'\n"),
1721 &routeList[pos]); 1696 &routeList[pos]);
1722 GNUNET_free (result); 1697 GNUNET_free (result);
1723 GNUNET_free (routeList); 1698 GNUNET_free (routeList);
1724 return NULL; 1699 return NULL;
1725 } 1700 }
1726 result[i].network.s_addr = 1701 result[i].network.s_addr = htonl ((temps[0] << 24) + (temps[1] << 16) +
1727 htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + 1702 (temps[2] << 8) + temps[3]);
1728 temps[3]); 1703 result[i].netmask.s_addr = htonl ((temps[4] << 24) + (temps[5] << 16) +
1729 result[i].netmask.s_addr = 1704 (temps[6] << 8) + temps[7]);
1730 htonl ((temps[4] << 24) + (temps[5] << 16) + (temps[6] << 8) +
1731 temps[7]);
1732 pos = end + 1; 1705 pos = end + 1;
1733 i++; 1706 i++;
1734 continue; 1707 continue;
1735 } 1708 }
1736 /* try second notation */ 1709 /* try second notation */
1737 cnt = 1710 cnt = sscanf (&routeList[pos],
1738 SSCANF (&routeList[pos], 1711 "%u.%u.%u.%u/%u%1s",
1739 "%u.%u.%u.%u/%u%1s", 1712 &temps[0],
1740 &temps[0], 1713 &temps[1],
1741 &temps[1], 1714 &temps[2],
1742 &temps[2], 1715 &temps[3],
1743 &temps[3], 1716 &slash,
1744 &slash, 1717 dummy);
1745 dummy);
1746 if (5 == cnt) 1718 if (5 == cnt)
1747 { 1719 {
1748 for (j = 0; j < 4; j++) 1720 for (j = 0; j < 4; j++)
1749 if (temps[j] > 0xFF) 1721 if (temps[j] > 0xFF)
1750 { 1722 {
1751 LOG (GNUNET_ERROR_TYPE_WARNING, 1723 LOG (GNUNET_ERROR_TYPE_WARNING,
1752 _("Invalid format for IP: `%s'\n"), 1724 _ ("Invalid format for IP: `%s'\n"),
1753 &routeList[pos]); 1725 &routeList[pos]);
1754 GNUNET_free (result); 1726 GNUNET_free (result);
1755 GNUNET_free (routeList); 1727 GNUNET_free (routeList);
1756 return NULL; 1728 return NULL;
1757 } 1729 }
1758 result[i].network.s_addr = 1730 result[i].network.s_addr = htonl ((temps[0] << 24) + (temps[1] << 16) +
1759 htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + 1731 (temps[2] << 8) + temps[3]);
1760 temps[3]);
1761 if ((slash <= 32) && (slash >= 0)) 1732 if ((slash <= 32) && (slash >= 0))
1762 { 1733 {
1763 result[i].netmask.s_addr = 0; 1734 result[i].netmask.s_addr = 0;
1764 while (slash > 0) 1735 while (slash > 0)
1765 { 1736 {
1766 result[i].netmask.s_addr = 1737 result[i].netmask.s_addr =
1767 (result[i].netmask.s_addr >> 1) + 0x80000000; 1738 (result[i].netmask.s_addr >> 1) + 0x80000000;
1768 slash--; 1739 slash--;
1769 } 1740 }
1770 result[i].netmask.s_addr = htonl (result[i].netmask.s_addr); 1741 result[i].netmask.s_addr = htonl (result[i].netmask.s_addr);
@@ -1775,38 +1746,36 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX)
1775 else 1746 else
1776 { 1747 {
1777 LOG (GNUNET_ERROR_TYPE_WARNING, 1748 LOG (GNUNET_ERROR_TYPE_WARNING,
1778 _("Invalid network notation ('/%d' is not legal in IPv4 CIDR)."), 1749 _ ("Invalid network notation ('/%d' is not legal in IPv4 CIDR)."),
1779 slash); 1750 slash);
1780 GNUNET_free (result); 1751 GNUNET_free (result);
1781 GNUNET_free (routeList); 1752 GNUNET_free (routeList);
1782 return NULL; /* error */ 1753 return NULL; /* error */
1783 } 1754 }
1784 } 1755 }
1785 /* try third notation */ 1756 /* try third notation */
1786 slash = 32; 1757 slash = 32;
1787 cnt = 1758 cnt = sscanf (&routeList[pos],
1788 SSCANF (&routeList[pos], 1759 "%u.%u.%u.%u%1s",
1789 "%u.%u.%u.%u%1s", 1760 &temps[0],
1790 &temps[0], 1761 &temps[1],
1791 &temps[1], 1762 &temps[2],
1792 &temps[2], 1763 &temps[3],
1793 &temps[3], 1764 dummy);
1794 dummy);
1795 if (4 == cnt) 1765 if (4 == cnt)
1796 { 1766 {
1797 for (j = 0; j < 4; j++) 1767 for (j = 0; j < 4; j++)
1798 if (temps[j] > 0xFF) 1768 if (temps[j] > 0xFF)
1799 { 1769 {
1800 LOG (GNUNET_ERROR_TYPE_WARNING, 1770 LOG (GNUNET_ERROR_TYPE_WARNING,
1801 _("Invalid format for IP: `%s'\n"), 1771 _ ("Invalid format for IP: `%s'\n"),
1802 &routeList[pos]); 1772 &routeList[pos]);
1803 GNUNET_free (result); 1773 GNUNET_free (result);
1804 GNUNET_free (routeList); 1774 GNUNET_free (routeList);
1805 return NULL; 1775 return NULL;
1806 } 1776 }
1807 result[i].network.s_addr = 1777 result[i].network.s_addr = htonl ((temps[0] << 24) + (temps[1] << 16) +
1808 htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + 1778 (temps[2] << 8) + temps[3]);
1809 temps[3]);
1810 result[i].netmask.s_addr = 0; 1779 result[i].netmask.s_addr = 0;
1811 while (slash > 0) 1780 while (slash > 0)
1812 { 1781 {
@@ -1819,23 +1788,23 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX)
1819 continue; 1788 continue;
1820 } 1789 }
1821 LOG (GNUNET_ERROR_TYPE_WARNING, 1790 LOG (GNUNET_ERROR_TYPE_WARNING,
1822 _("Invalid format for IP: `%s'\n"), 1791 _ ("Invalid format for IP: `%s'\n"),
1823 &routeList[pos]); 1792 &routeList[pos]);
1824 GNUNET_free (result); 1793 GNUNET_free (result);
1825 GNUNET_free (routeList); 1794 GNUNET_free (routeList);
1826 return NULL; /* error */ 1795 return NULL; /* error */
1827 } 1796 }
1828 if (pos < strlen (routeList)) 1797 if (pos < strlen (routeList))
1829 { 1798 {
1830 LOG (GNUNET_ERROR_TYPE_WARNING, 1799 LOG (GNUNET_ERROR_TYPE_WARNING,
1831 _("Invalid format: `%s'\n"), 1800 _ ("Invalid format: `%s'\n"),
1832 &routeListX[pos]); 1801 &routeListX[pos]);
1833 GNUNET_free (result); 1802 GNUNET_free (result);
1834 GNUNET_free (routeList); 1803 GNUNET_free (routeList);
1835 return NULL; /* oops */ 1804 return NULL; /* oops */
1836 } 1805 }
1837 GNUNET_free (routeList); 1806 GNUNET_free (routeList);
1838 return result; /* ok */ 1807 return result; /* ok */
1839} 1808}
1840 1809
1841 1810
@@ -1867,7 +1836,7 @@ GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX)
1867 int save; 1836 int save;
1868 int colon; 1837 int colon;
1869 char dummy[2]; 1838 char dummy[2];
1870 1839
1871 if (NULL == routeListX) 1840 if (NULL == routeListX)
1872 return NULL; 1841 return NULL;
1873 len = strlen (routeListX); 1842 len = strlen (routeListX);
@@ -1881,13 +1850,14 @@ GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX)
1881 if (';' != routeList[len - 1]) 1850 if (';' != routeList[len - 1])
1882 { 1851 {
1883 LOG (GNUNET_ERROR_TYPE_WARNING, 1852 LOG (GNUNET_ERROR_TYPE_WARNING,
1884 _("Invalid network notation (does not end with ';': `%s')\n"), 1853 _ ("Invalid network notation (does not end with ';': `%s')\n"),
1885 routeList); 1854 routeList);
1886 GNUNET_free (routeList); 1855 GNUNET_free (routeList);
1887 return NULL; 1856 return NULL;
1888 } 1857 }
1889 1858
1890 result = GNUNET_malloc (sizeof (struct GNUNET_STRINGS_IPv6NetworkPolicy) * (count + 1)); 1859 result = GNUNET_malloc (sizeof (struct GNUNET_STRINGS_IPv6NetworkPolicy) *
1860 (count + 1));
1891 i = 0; 1861 i = 0;
1892 pos = 0; 1862 pos = 0;
1893 while (i < count) 1863 while (i < count)
@@ -1901,9 +1871,7 @@ GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX)
1901 1871
1902 if (slash < start) 1872 if (slash < start)
1903 { 1873 {
1904 memset (&result[i].netmask, 1874 memset (&result[i].netmask, 0xFF, sizeof (struct in6_addr));
1905 0xFF,
1906 sizeof (struct in6_addr));
1907 slash = pos; 1875 slash = pos;
1908 } 1876 }
1909 else 1877 else
@@ -1915,8 +1883,8 @@ GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX)
1915 if (':' == routeList[colon]) 1883 if (':' == routeList[colon])
1916 { 1884 {
1917 routeList[colon] = '\0'; 1885 routeList[colon] = '\0';
1918 if (GNUNET_OK != parse_port_policy (&routeList[colon + 1], 1886 if (GNUNET_OK !=
1919 &result[i].pp)) 1887 parse_port_policy (&routeList[colon + 1], &result[i].pp))
1920 { 1888 {
1921 GNUNET_free (result); 1889 GNUNET_free (result);
1922 GNUNET_free (routeList); 1890 GNUNET_free (routeList);
@@ -1927,15 +1895,12 @@ GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX)
1927 if (ret <= 0) 1895 if (ret <= 0)
1928 { 1896 {
1929 save = errno; 1897 save = errno;
1930 if ( (1 != SSCANF (&routeList[slash + 1], 1898 if ((1 != sscanf (&routeList[slash + 1], "%u%1s", &bits, dummy)) ||
1931 "%u%1s", 1899 (bits > 128))
1932 &bits,
1933 dummy)) ||
1934 (bits > 128) )
1935 { 1900 {
1936 if (0 == ret) 1901 if (0 == ret)
1937 LOG (GNUNET_ERROR_TYPE_WARNING, 1902 LOG (GNUNET_ERROR_TYPE_WARNING,
1938 _("Wrong format `%s' for netmask\n"), 1903 _ ("Wrong format `%s' for netmask\n"),
1939 &routeList[slash + 1]); 1904 &routeList[slash + 1]);
1940 else 1905 else
1941 { 1906 {
@@ -1955,7 +1920,7 @@ GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX)
1955 while (bits > 0) 1920 while (bits > 0)
1956 { 1921 {
1957 result[i].netmask.s6_addr[off] = 1922 result[i].netmask.s6_addr[off] =
1958 (result[i].netmask.s6_addr[off] >> 1) + 0x80; 1923 (result[i].netmask.s6_addr[off] >> 1) + 0x80;
1959 bits--; 1924 bits--;
1960 } 1925 }
1961 } 1926 }
@@ -1966,11 +1931,10 @@ GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX)
1966 { 1931 {
1967 if (0 == ret) 1932 if (0 == ret)
1968 LOG (GNUNET_ERROR_TYPE_WARNING, 1933 LOG (GNUNET_ERROR_TYPE_WARNING,
1969 _("Wrong format `%s' for network\n"), 1934 _ ("Wrong format `%s' for network\n"),
1970 &routeList[slash + 1]); 1935 &routeList[slash + 1]);
1971 else 1936 else
1972 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, 1937 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "inet_pton");
1973 "inet_pton");
1974 GNUNET_free (result); 1938 GNUNET_free (result);
1975 GNUNET_free (routeList); 1939 GNUNET_free (routeList);
1976 return NULL; 1940 return NULL;
@@ -1983,12 +1947,12 @@ GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX)
1983} 1947}
1984 1948
1985 1949
1986
1987/** ******************** Base64 encoding ***********/ 1950/** ******************** Base64 encoding ***********/
1988 1951
1989#define FILLCHAR '=' 1952#define FILLCHAR '='
1990static char *cvt = 1953static char *cvt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1991 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789+/"; 1954 "abcdefghijklmnopqrstuvwxyz"
1955 "0123456789+/";
1992 1956
1993 1957
1994/** 1958/**
@@ -2001,9 +1965,7 @@ static char *cvt =
2001 * @return the size of the output 1965 * @return the size of the output
2002 */ 1966 */
2003size_t 1967size_t
2004GNUNET_STRINGS_base64_encode (const void *in, 1968GNUNET_STRINGS_base64_encode (const void *in, size_t len, char **output)
2005 size_t len,
2006 char **output)
2007{ 1969{
2008 const char *data = in; 1970 const char *data = in;
2009 size_t ret; 1971 size_t ret;
@@ -2047,11 +2009,14 @@ GNUNET_STRINGS_base64_encode (const void *in,
2047 return ret; 2009 return ret;
2048} 2010}
2049 2011
2050#define cvtfind(a)( (((a) >= 'A')&&((a) <= 'Z'))? (a)-'A'\ 2012#define cvtfind(a) \
2051 :(((a)>='a')&&((a)<='z')) ? (a)-'a'+26\ 2013 ((((a) >= 'A') && ((a) <= 'Z')) \
2052 :(((a)>='0')&&((a)<='9')) ? (a)-'0'+52\ 2014 ? (a) - 'A' \
2053 :((a) == '+') ? 62\ 2015 : (((a) >= 'a') && ((a) <= 'z')) \
2054 :((a) == '/') ? 63 : -1) 2016 ? (a) - 'a' + 26 \
2017 : (((a) >= '0') && ((a) <= '9')) \
2018 ? (a) - '0' + 52 \
2019 : ((a) == '+') ? 62 : ((a) == '/') ? 63 : -1)
2055 2020
2056 2021
2057/** 2022/**
@@ -2064,18 +2029,20 @@ GNUNET_STRINGS_base64_encode (const void *in,
2064 * @return the size of the output 2029 * @return the size of the output
2065 */ 2030 */
2066size_t 2031size_t
2067GNUNET_STRINGS_base64_decode (const char *data, 2032GNUNET_STRINGS_base64_decode (const char *data, size_t len, void **out)
2068 size_t len,
2069 void **out)
2070{ 2033{
2071 char *output; 2034 char *output;
2072 size_t ret = 0; 2035 size_t ret = 0;
2073 2036
2074#define CHECK_CRLF while (data[i] == '\r' || data[i] == '\n') {\ 2037#define CHECK_CRLF \
2075 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, "ignoring CR/LF\n"); \ 2038 while (data[i] == '\r' || data[i] == '\n') \
2076 i++; \ 2039 { \
2077 if (i >= len) goto END; \ 2040 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, \
2078 } 2041 "ignoring CR/LF\n"); \
2042 i++; \
2043 if (i >= len) \
2044 goto END; \
2045 }
2079 2046
2080 output = GNUNET_malloc ((len * 3 / 4) + 8); 2047 output = GNUNET_malloc ((len * 3 / 4) + 8);
2081 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2048 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/util/test_common_allocation.c b/src/util/test_common_allocation.c
index 476934b3f..fcc453d6b 100644
--- a/src/util/test_common_allocation.c
+++ b/src/util/test_common_allocation.c
@@ -144,7 +144,7 @@ main (int argc, char *argv[])
144 NULL); 144 NULL);
145 ret = check (); 145 ret = check ();
146 if (ret != 0) 146 if (ret != 0)
147 FPRINTF (stderr, 147 fprintf (stderr,
148 "ERROR %d.\n", 148 "ERROR %d.\n",
149 ret); 149 ret);
150 return ret; 150 return ret;
diff --git a/src/util/test_common_logging.c b/src/util/test_common_logging.c
index 396bf3966..6ae50b36b 100644
--- a/src/util/test_common_logging.c
+++ b/src/util/test_common_logging.c
@@ -44,7 +44,7 @@ main (int argc, char *argv[])
44 unsigned int logs = 0; 44 unsigned int logs = 0;
45 45
46 if (0 != putenv ("GNUNET_FORCE_LOG=")) 46 if (0 != putenv ("GNUNET_FORCE_LOG="))
47 FPRINTF (stderr, "Failed to putenv: %s\n", strerror (errno)); 47 fprintf (stderr, "Failed to putenv: %s\n", strerror (errno));
48 GNUNET_log_setup ("test-common-logging", "DEBUG", "/dev/null"); 48 GNUNET_log_setup ("test-common-logging", "DEBUG", "/dev/null");
49 GNUNET_logger_add (&my_log, &logs); 49 GNUNET_logger_add (&my_log, &logs);
50 GNUNET_logger_add (&my_log, &logs); 50 GNUNET_logger_add (&my_log, &logs);
@@ -60,7 +60,7 @@ main (int argc, char *argv[])
60 GNUNET_logger_remove (&my_log, &logs); 60 GNUNET_logger_remove (&my_log, &logs);
61 if (logs != 4) 61 if (logs != 4)
62 { 62 {
63 FPRINTF (stdout, "Expected 4 log calls, got %u\n", logs); 63 fprintf (stdout, "Expected 4 log calls, got %u\n", logs);
64 failureCount++; 64 failureCount++;
65 } 65 }
66 GNUNET_break (0 == 66 GNUNET_break (0 ==
@@ -84,13 +84,13 @@ main (int argc, char *argv[])
84 GNUNET_logger_remove (&my_log, &logs); 84 GNUNET_logger_remove (&my_log, &logs);
85 if (logs != 1) 85 if (logs != 1)
86 { 86 {
87 FPRINTF (stdout, "Expected 1 log call, got %u\n", logs); 87 fprintf (stdout, "Expected 1 log call, got %u\n", logs);
88 failureCount++; 88 failureCount++;
89 } 89 }
90 90
91 if (failureCount != 0) 91 if (failureCount != 0)
92 { 92 {
93 FPRINTF (stdout, "%u TESTS FAILED!\n", failureCount); 93 fprintf (stdout, "%u TESTS FAILED!\n", failureCount);
94 return -1; 94 return -1;
95 } 95 }
96 return 0; 96 return 0;
diff --git a/src/util/test_common_logging_dummy.c b/src/util/test_common_logging_dummy.c
index 5c3709206..d3c6e3452 100644
--- a/src/util/test_common_logging_dummy.c
+++ b/src/util/test_common_logging_dummy.c
@@ -51,7 +51,7 @@ my_log (void *ctx,
51 (void) date; 51 (void) date;
52 if (strncmp ("test-common-logging-dummy", component, 25) != 0) 52 if (strncmp ("test-common-logging-dummy", component, 25) != 0)
53 return; 53 return;
54 FPRINTF (stdout, "%s", msg); 54 fprintf (stdout, "%s", msg);
55 fflush (stdout); 55 fflush (stdout);
56} 56}
57 57
diff --git a/src/util/test_common_logging_runtime_loglevels.c b/src/util/test_common_logging_runtime_loglevels.c
index 7c72acf7d..8da808760 100644
--- a/src/util/test_common_logging_runtime_loglevels.c
+++ b/src/util/test_common_logging_runtime_loglevels.c
@@ -237,7 +237,7 @@ read_call (void *cls)
237 buf_ptr += rd; 237 buf_ptr += rd;
238 bytes += rd; 238 bytes += rd;
239#if VERBOSE 239#if VERBOSE
240 FPRINTF (stderr, "got %d bytes, reading more\n", rd); 240 fprintf (stderr, "got %d bytes, reading more\n", rd);
241#endif 241#endif
242 read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 242 read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
243 stdout_read_handle, 243 stdout_read_handle,
@@ -247,7 +247,7 @@ read_call (void *cls)
247 } 247 }
248 248
249#if VERBOSE 249#if VERBOSE
250 FPRINTF (stderr, "bytes is %d:%s\n", bytes, buf); 250 fprintf (stderr, "bytes is %d:%s\n", bytes, buf);
251#endif 251#endif
252 252
253 /* +------CHILD OUTPUT-- 253 /* +------CHILD OUTPUT--
@@ -334,7 +334,7 @@ read_call (void *cls)
334 &bytes, &delays[7], level))) 334 &bytes, &delays[7], level)))
335 { 335 {
336 if (bytes == LOG_BUFFER_SIZE) 336 if (bytes == LOG_BUFFER_SIZE)
337 FPRINTF (stderr, "%s", "Ran out of buffer space!\n"); 337 fprintf (stderr, "%s", "Ran out of buffer space!\n");
338 GNUNET_break (0); 338 GNUNET_break (0);
339 ok = 2; 339 ok = 2;
340 GNUNET_SCHEDULER_cancel (die_task); 340 GNUNET_SCHEDULER_cancel (die_task);
diff --git a/src/util/test_configuration.c b/src/util/test_configuration.c
index 96f13eefe..67e532f40 100644
--- a/src/util/test_configuration.c
+++ b/src/util/test_configuration.c
@@ -236,14 +236,14 @@ checkDiffs (struct GNUNET_CONFIGURATION_Handle *cfg_default, int option)
236 GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &cbData); 236 GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &cbData);
237 if (1 == (ret = cbData.status)) 237 if (1 == (ret = cbData.status))
238 { 238 {
239 FPRINTF (stderr, "%s", 239 fprintf (stderr, "%s",
240 "Incorrect Configuration Diffs: Diffs may contain data not actually edited\n"); 240 "Incorrect Configuration Diffs: Diffs may contain data not actually edited\n");
241 goto housekeeping; 241 goto housekeeping;
242 } 242 }
243 cbData.cfgDiffs = cfg; 243 cbData.cfgDiffs = cfg;
244 GNUNET_CONFIGURATION_iterate (cfgDiffs, diffsCallBack, &cbData); 244 GNUNET_CONFIGURATION_iterate (cfgDiffs, diffsCallBack, &cbData);
245 if ((ret = cbData.status) == 1) 245 if ((ret = cbData.status) == 1)
246 FPRINTF (stderr, "%s", 246 fprintf (stderr, "%s",
247 "Incorrect Configuration Diffs: Data may be missing in diffs\n"); 247 "Incorrect Configuration Diffs: Data may be missing in diffs\n");
248 248
249housekeeping: 249housekeeping:
@@ -273,7 +273,7 @@ testConfig ()
273 return 1; 273 return 1;
274 if (0 != strcmp ("b", c)) 274 if (0 != strcmp ("b", c))
275 { 275 {
276 FPRINTF (stderr, "Got `%s'\n", c); 276 fprintf (stderr, "Got `%s'\n", c);
277 GNUNET_free (c); 277 GNUNET_free (c);
278 return 2; 278 return 2;
279 } 279 }
@@ -466,7 +466,7 @@ main (int argc, char *argv[])
466 if (GNUNET_OK != 466 if (GNUNET_OK !=
467 GNUNET_CONFIGURATION_parse (cfg, "test_configuration_data.conf")) 467 GNUNET_CONFIGURATION_parse (cfg, "test_configuration_data.conf"))
468 { 468 {
469 FPRINTF (stderr, "%s", "Failed to parse configuration file\n"); 469 fprintf (stderr, "%s", "Failed to parse configuration file\n");
470 GNUNET_CONFIGURATION_destroy (cfg); 470 GNUNET_CONFIGURATION_destroy (cfg);
471 return 1; 471 return 1;
472 } 472 }
@@ -480,12 +480,12 @@ main (int argc, char *argv[])
480 480
481 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, "/tmp/gnunet-test.conf")) 481 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, "/tmp/gnunet-test.conf"))
482 { 482 {
483 FPRINTF (stderr, "%s", "Failed to write configuration file\n"); 483 fprintf (stderr, "%s", "Failed to write configuration file\n");
484 GNUNET_CONFIGURATION_destroy (cfg); 484 GNUNET_CONFIGURATION_destroy (cfg);
485 return 1; 485 return 1;
486 } 486 }
487 GNUNET_CONFIGURATION_destroy (cfg); 487 GNUNET_CONFIGURATION_destroy (cfg);
488 GNUNET_assert (0 == UNLINK ("/tmp/gnunet-test.conf")); 488 GNUNET_assert (0 == unlink ("/tmp/gnunet-test.conf"));
489 489
490 cfg = GNUNET_CONFIGURATION_create (); 490 cfg = GNUNET_CONFIGURATION_create ();
491 if (GNUNET_OK != 491 if (GNUNET_OK !=
@@ -542,7 +542,7 @@ main (int argc, char *argv[])
542error: 542error:
543 if (failureCount != 0) 543 if (failureCount != 0)
544 { 544 {
545 FPRINTF (stderr, "Test failed: %u\n", failureCount); 545 fprintf (stderr, "Test failed: %u\n", failureCount);
546 return 1; 546 return 1;
547 } 547 }
548 return 0; 548 return 0;
diff --git a/src/util/test_container_bloomfilter.c b/src/util/test_container_bloomfilter.c
index 42849af97..043eacafd 100644
--- a/src/util/test_container_bloomfilter.c
+++ b/src/util/test_container_bloomfilter.c
@@ -35,13 +35,13 @@
35 * Generate a random hashcode. 35 * Generate a random hashcode.
36 */ 36 */
37static void 37static void
38nextHC (struct GNUNET_HashCode * hc) 38nextHC (struct GNUNET_HashCode *hc)
39{ 39{
40 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, hc); 40 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, hc);
41} 41}
42 42
43static int 43static int
44add_iterator (void *cls, struct GNUNET_HashCode * next) 44add_iterator (void *cls, struct GNUNET_HashCode *next)
45{ 45{
46 int *ret = cls; 46 int *ret = cls;
47 struct GNUNET_HashCode pos; 47 struct GNUNET_HashCode pos;
@@ -68,8 +68,8 @@ main (int argc, char *argv[])
68 68
69 GNUNET_log_setup ("test-container-bloomfilter", "WARNING", NULL); 69 GNUNET_log_setup ("test-container-bloomfilter", "WARNING", NULL);
70 GNUNET_CRYPTO_seed_weak_random (1); 70 GNUNET_CRYPTO_seed_weak_random (1);
71 if (0 == STAT (TESTFILE, &sbuf)) 71 if (0 == stat (TESTFILE, &sbuf))
72 if (0 != UNLINK (TESTFILE)) 72 if (0 != unlink (TESTFILE))
73 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "unlink", TESTFILE); 73 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "unlink", TESTFILE);
74 bf = GNUNET_CONTAINER_bloomfilter_load (TESTFILE, SIZE, K); 74 bf = GNUNET_CONTAINER_bloomfilter_load (TESTFILE, SIZE, K);
75 75
@@ -88,7 +88,9 @@ main (int argc, char *argv[])
88 } 88 }
89 if (ok1 != 200) 89 if (ok1 != 200)
90 { 90 {
91 printf ("Got %d elements out of" "200 expected after insertion.\n", ok1); 91 printf ("Got %d elements out of"
92 "200 expected after insertion.\n",
93 ok1);
92 GNUNET_CONTAINER_bloomfilter_free (bf); 94 GNUNET_CONTAINER_bloomfilter_free (bf);
93 return -1; 95 return -1;
94 } 96 }
@@ -118,7 +120,9 @@ main (int argc, char *argv[])
118 } 120 }
119 if (ok1 != 200) 121 if (ok1 != 200)
120 { 122 {
121 printf ("Got %d elements out of 200 " "expected after reloading.\n", ok1); 123 printf ("Got %d elements out of 200 "
124 "expected after reloading.\n",
125 ok1);
122 GNUNET_CONTAINER_bloomfilter_free (bf); 126 GNUNET_CONTAINER_bloomfilter_free (bf);
123 GNUNET_CONTAINER_bloomfilter_free (bfi); 127 GNUNET_CONTAINER_bloomfilter_free (bfi);
124 return -1; 128 return -1;
@@ -126,7 +130,8 @@ main (int argc, char *argv[])
126 130
127 if (ok2 != 200) 131 if (ok2 != 200)
128 { 132 {
129 printf ("Got %d elements out of 200 " "expected after initialization.\n", 133 printf ("Got %d elements out of 200 "
134 "expected after initialization.\n",
130 ok2); 135 ok2);
131 GNUNET_CONTAINER_bloomfilter_free (bf); 136 GNUNET_CONTAINER_bloomfilter_free (bf);
132 GNUNET_CONTAINER_bloomfilter_free (bfi); 137 GNUNET_CONTAINER_bloomfilter_free (bfi);
@@ -157,7 +162,8 @@ main (int argc, char *argv[])
157 if (ok1 != 100) 162 if (ok1 != 100)
158 { 163 {
159 printf ("Expected 100 elements in loaded filter" 164 printf ("Expected 100 elements in loaded filter"
160 " after adding 200 and deleting 100, got %d\n", ok1); 165 " after adding 200 and deleting 100, got %d\n",
166 ok1);
161 GNUNET_CONTAINER_bloomfilter_free (bf); 167 GNUNET_CONTAINER_bloomfilter_free (bf);
162 GNUNET_CONTAINER_bloomfilter_free (bfi); 168 GNUNET_CONTAINER_bloomfilter_free (bfi);
163 return -1; 169 return -1;
@@ -220,7 +226,8 @@ main (int argc, char *argv[])
220 if (ok1 != 20) 226 if (ok1 != 20)
221 { 227 {
222 printf ("Expected 20 elements in resized file-backed filter" 228 printf ("Expected 20 elements in resized file-backed filter"
223 " after adding 20, got %d\n", ok1); 229 " after adding 20, got %d\n",
230 ok1);
224 GNUNET_CONTAINER_bloomfilter_free (bf); 231 GNUNET_CONTAINER_bloomfilter_free (bf);
225 GNUNET_CONTAINER_bloomfilter_free (bfi); 232 GNUNET_CONTAINER_bloomfilter_free (bfi);
226 return -1; 233 return -1;
@@ -228,7 +235,8 @@ main (int argc, char *argv[])
228 if (ok2 != 20) 235 if (ok2 != 20)
229 { 236 {
230 printf ("Expected 20 elements in resized filter" 237 printf ("Expected 20 elements in resized filter"
231 " after adding 20, got %d\n", ok2); 238 " after adding 20, got %d\n",
239 ok2);
232 GNUNET_CONTAINER_bloomfilter_free (bf); 240 GNUNET_CONTAINER_bloomfilter_free (bf);
233 GNUNET_CONTAINER_bloomfilter_free (bfi); 241 GNUNET_CONTAINER_bloomfilter_free (bfi);
234 return -1; 242 return -1;
@@ -238,6 +246,6 @@ main (int argc, char *argv[])
238 GNUNET_CONTAINER_bloomfilter_free (bf); 246 GNUNET_CONTAINER_bloomfilter_free (bf);
239 GNUNET_CONTAINER_bloomfilter_free (bfi); 247 GNUNET_CONTAINER_bloomfilter_free (bfi);
240 248
241 GNUNET_break (0 == UNLINK (TESTFILE)); 249 GNUNET_break (0 == unlink (TESTFILE));
242 return 0; 250 return 0;
243} 251}
diff --git a/src/util/test_crypto_ecc_dlog.c b/src/util/test_crypto_ecc_dlog.c
index 0b0b8d57c..c0828c354 100644
--- a/src/util/test_crypto_ecc_dlog.c
+++ b/src/util/test_crypto_ecc_dlog.c
@@ -172,7 +172,7 @@ main (int argc, char *argv[])
172 172
173 if (! gcry_check_version ("1.6.0")) 173 if (! gcry_check_version ("1.6.0"))
174 { 174 {
175 FPRINTF (stderr, 175 fprintf (stderr,
176 _ 176 _
177 ("libgcrypt has not the expected version (version %s is required).\n"), 177 ("libgcrypt has not the expected version (version %s is required).\n"),
178 "1.6.0"); 178 "1.6.0");
diff --git a/src/util/test_crypto_ecdh_eddsa.c b/src/util/test_crypto_ecdh_eddsa.c
index 721f831d0..00f85033e 100644
--- a/src/util/test_crypto_ecdh_eddsa.c
+++ b/src/util/test_crypto_ecdh_eddsa.c
@@ -74,7 +74,7 @@ main (int argc, char *argv[])
74{ 74{
75 if (! gcry_check_version ("1.6.0")) 75 if (! gcry_check_version ("1.6.0"))
76 { 76 {
77 FPRINTF (stderr, 77 fprintf (stderr,
78 _("libgcrypt has not the expected version (version %s is required).\n"), 78 _("libgcrypt has not the expected version (version %s is required).\n"),
79 "1.6.0"); 79 "1.6.0");
80 return 0; 80 return 0;
diff --git a/src/util/test_crypto_ecdhe.c b/src/util/test_crypto_ecdhe.c
index c4392ca5a..71fe9b570 100644
--- a/src/util/test_crypto_ecdhe.c
+++ b/src/util/test_crypto_ecdhe.c
@@ -40,7 +40,7 @@ main (int argc, char *argv[])
40 40
41 if (! gcry_check_version ("1.6.0")) 41 if (! gcry_check_version ("1.6.0"))
42 { 42 {
43 FPRINTF (stderr, 43 fprintf (stderr,
44 _ 44 _
45 ("libgcrypt has not the expected version (version %s is required).\n"), 45 ("libgcrypt has not the expected version (version %s is required).\n"),
46 "1.6.0"); 46 "1.6.0");
diff --git a/src/util/test_crypto_ecdsa.c b/src/util/test_crypto_ecdsa.c
index 8fa5eb486..00cc72af4 100644
--- a/src/util/test_crypto_ecdsa.c
+++ b/src/util/test_crypto_ecdsa.c
@@ -46,7 +46,7 @@ testSignVerify ()
46 struct GNUNET_TIME_Absolute start; 46 struct GNUNET_TIME_Absolute start;
47 int ok = GNUNET_OK; 47 int ok = GNUNET_OK;
48 48
49 FPRINTF (stderr, "%s", "W"); 49 fprintf (stderr, "%s", "W");
50 GNUNET_CRYPTO_ecdsa_key_get_public (key, &pkey); 50 GNUNET_CRYPTO_ecdsa_key_get_public (key, &pkey);
51 start = GNUNET_TIME_absolute_get (); 51 start = GNUNET_TIME_absolute_get ();
52 purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose)); 52 purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose));
@@ -54,10 +54,10 @@ testSignVerify ()
54 54
55 for (i = 0; i < ITER; i++) 55 for (i = 0; i < ITER; i++)
56 { 56 {
57 FPRINTF (stderr, "%s", "."); fflush (stderr); 57 fprintf (stderr, "%s", "."); fflush (stderr);
58 if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdsa_sign (key, &purp, &sig)) 58 if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdsa_sign (key, &purp, &sig))
59 { 59 {
60 FPRINTF (stderr, 60 fprintf (stderr,
61 "%s", 61 "%s",
62 "GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n"); 62 "GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n");
63 ok = GNUNET_SYSERR; 63 ok = GNUNET_SYSERR;
@@ -103,7 +103,7 @@ testDeriveSignVerify ()
103 103
104 if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdsa_sign (dpriv, &purp, &sig)) 104 if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdsa_sign (dpriv, &purp, &sig))
105 { 105 {
106 FPRINTF (stderr, "%s", "GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n"); 106 fprintf (stderr, "%s", "GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n");
107 GNUNET_free (dpriv); 107 GNUNET_free (dpriv);
108 return GNUNET_SYSERR; 108 return GNUNET_SYSERR;
109 } 109 }
@@ -151,15 +151,15 @@ testSignPerformance ()
151 151
152 purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose)); 152 purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose));
153 purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); 153 purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
154 FPRINTF (stderr, "%s", "W"); 154 fprintf (stderr, "%s", "W");
155 GNUNET_CRYPTO_ecdsa_key_get_public (key, &pkey); 155 GNUNET_CRYPTO_ecdsa_key_get_public (key, &pkey);
156 start = GNUNET_TIME_absolute_get (); 156 start = GNUNET_TIME_absolute_get ();
157 for (i = 0; i < ITER; i++) 157 for (i = 0; i < ITER; i++)
158 { 158 {
159 FPRINTF (stderr, "%s", "."); fflush (stderr); 159 fprintf (stderr, "%s", "."); fflush (stderr);
160 if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdsa_sign (key, &purp, &sig)) 160 if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdsa_sign (key, &purp, &sig))
161 { 161 {
162 FPRINTF (stderr, "%s", 162 fprintf (stderr, "%s",
163 "GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n"); 163 "GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n");
164 ok = GNUNET_SYSERR; 164 ok = GNUNET_SYSERR;
165 continue; 165 continue;
@@ -180,7 +180,7 @@ perf_keygen ()
180 struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; 180 struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
181 int i; 181 int i;
182 182
183 FPRINTF (stderr, "%s", "W"); 183 fprintf (stderr, "%s", "W");
184 start = GNUNET_TIME_absolute_get (); 184 start = GNUNET_TIME_absolute_get ();
185 for (i=0;i<10;i++) 185 for (i=0;i<10;i++)
186 { 186 {
@@ -203,7 +203,7 @@ main (int argc, char *argv[])
203 203
204 if (! gcry_check_version ("1.6.0")) 204 if (! gcry_check_version ("1.6.0"))
205 { 205 {
206 FPRINTF (stderr, 206 fprintf (stderr,
207 _ 207 _
208 ("libgcrypt has not the expected version (version %s is required).\n"), 208 ("libgcrypt has not the expected version (version %s is required).\n"),
209 "1.6.0"); 209 "1.6.0");
diff --git a/src/util/test_crypto_eddsa.c b/src/util/test_crypto_eddsa.c
index e738f7e6c..acb5fbdf5 100644
--- a/src/util/test_crypto_eddsa.c
+++ b/src/util/test_crypto_eddsa.c
@@ -48,7 +48,7 @@ testSignVerify ()
48 struct GNUNET_TIME_Absolute start; 48 struct GNUNET_TIME_Absolute start;
49 int ok = GNUNET_OK; 49 int ok = GNUNET_OK;
50 50
51 FPRINTF (stderr, "%s", "W"); 51 fprintf (stderr, "%s", "W");
52 GNUNET_CRYPTO_eddsa_key_get_public (key, &pkey); 52 GNUNET_CRYPTO_eddsa_key_get_public (key, &pkey);
53 start = GNUNET_TIME_absolute_get (); 53 start = GNUNET_TIME_absolute_get ();
54 purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose)); 54 purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose));
@@ -56,10 +56,10 @@ testSignVerify ()
56 56
57 for (i = 0; i < ITER; i++) 57 for (i = 0; i < ITER; i++)
58 { 58 {
59 FPRINTF (stderr, "%s", "."); fflush (stderr); 59 fprintf (stderr, "%s", "."); fflush (stderr);
60 if (GNUNET_SYSERR == GNUNET_CRYPTO_eddsa_sign (key, &purp, &sig)) 60 if (GNUNET_SYSERR == GNUNET_CRYPTO_eddsa_sign (key, &purp, &sig))
61 { 61 {
62 FPRINTF (stderr, "%s", "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n"); 62 fprintf (stderr, "%s", "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n");
63 ok = GNUNET_SYSERR; 63 ok = GNUNET_SYSERR;
64 continue; 64 continue;
65 } 65 }
@@ -99,15 +99,15 @@ testSignPerformance ()
99 99
100 purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose)); 100 purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose));
101 purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); 101 purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
102 FPRINTF (stderr, "%s", "W"); 102 fprintf (stderr, "%s", "W");
103 GNUNET_CRYPTO_eddsa_key_get_public (key, &pkey); 103 GNUNET_CRYPTO_eddsa_key_get_public (key, &pkey);
104 start = GNUNET_TIME_absolute_get (); 104 start = GNUNET_TIME_absolute_get ();
105 for (i = 0; i < ITER; i++) 105 for (i = 0; i < ITER; i++)
106 { 106 {
107 FPRINTF (stderr, "%s", "."); fflush (stderr); 107 fprintf (stderr, "%s", "."); fflush (stderr);
108 if (GNUNET_SYSERR == GNUNET_CRYPTO_eddsa_sign (key, &purp, &sig)) 108 if (GNUNET_SYSERR == GNUNET_CRYPTO_eddsa_sign (key, &purp, &sig))
109 { 109 {
110 FPRINTF (stderr, "%s", "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n"); 110 fprintf (stderr, "%s", "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n");
111 ok = GNUNET_SYSERR; 111 ok = GNUNET_SYSERR;
112 continue; 112 continue;
113 } 113 }
@@ -135,7 +135,7 @@ testCreateFromFile ()
135 GNUNET_CRYPTO_eddsa_key_get_public (key, &p2); 135 GNUNET_CRYPTO_eddsa_key_get_public (key, &p2);
136 GNUNET_assert (0 == memcmp (&p1, &p2, sizeof (p1))); 136 GNUNET_assert (0 == memcmp (&p1, &p2, sizeof (p1)));
137 GNUNET_free (key); 137 GNUNET_free (key);
138 GNUNET_assert (0 == UNLINK (KEYFILE)); 138 GNUNET_assert (0 == unlink (KEYFILE));
139 key = GNUNET_CRYPTO_eddsa_key_create_from_file (KEYFILE); 139 key = GNUNET_CRYPTO_eddsa_key_create_from_file (KEYFILE);
140 GNUNET_assert (NULL != key); 140 GNUNET_assert (NULL != key);
141 GNUNET_CRYPTO_eddsa_key_get_public (key, &p2); 141 GNUNET_CRYPTO_eddsa_key_get_public (key, &p2);
@@ -152,7 +152,7 @@ perf_keygen ()
152 struct GNUNET_CRYPTO_EddsaPrivateKey *pk; 152 struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
153 int i; 153 int i;
154 154
155 FPRINTF (stderr, "%s", "W"); 155 fprintf (stderr, "%s", "W");
156 start = GNUNET_TIME_absolute_get (); 156 start = GNUNET_TIME_absolute_get ();
157 for (i=0;i<10;i++) 157 for (i=0;i<10;i++)
158 { 158 {
@@ -175,7 +175,7 @@ main (int argc, char *argv[])
175 175
176 if (! gcry_check_version ("1.6.0")) 176 if (! gcry_check_version ("1.6.0"))
177 { 177 {
178 FPRINTF (stderr, 178 fprintf (stderr,
179 _("libgcrypt has not the expected version (version %s is required).\n"), 179 _("libgcrypt has not the expected version (version %s is required).\n"),
180 "1.6.0"); 180 "1.6.0");
181 return 0; 181 return 0;
@@ -193,7 +193,7 @@ main (int argc, char *argv[])
193 GNUNET_free (key); 193 GNUNET_free (key);
194 if (GNUNET_OK != testCreateFromFile ()) 194 if (GNUNET_OK != testCreateFromFile ())
195 failure_count++; 195 failure_count++;
196 GNUNET_assert (0 == UNLINK (KEYFILE)); 196 GNUNET_assert (0 == unlink (KEYFILE));
197 perf_keygen (); 197 perf_keygen ();
198 198
199 if (0 != failure_count) 199 if (0 != failure_count)
diff --git a/src/util/test_crypto_hash.c b/src/util/test_crypto_hash.c
index 52e24718d..e08348e53 100644
--- a/src/util/test_crypto_hash.c
+++ b/src/util/test_crypto_hash.c
@@ -130,12 +130,12 @@ testFileHash ()
130 130
131 memset (block, 42, sizeof (block) / 2); 131 memset (block, 42, sizeof (block) / 2);
132 memset (&block[sizeof (block) / 2], 43, sizeof (block) / 2); 132 memset (&block[sizeof (block) / 2], 43, sizeof (block) / 2);
133 GNUNET_assert (NULL != (f = FOPEN (FILENAME, "w+"))); 133 GNUNET_assert (NULL != (f = fopen (FILENAME, "w+")));
134 GNUNET_break (sizeof (block) == fwrite (block, 1, sizeof (block), f)); 134 GNUNET_break (sizeof (block) == fwrite (block, 1, sizeof (block), f));
135 GNUNET_break (0 == FCLOSE (f)); 135 GNUNET_break (0 == fclose (f));
136 ret = 1; 136 ret = 1;
137 GNUNET_SCHEDULER_run (&file_hasher, &ret); 137 GNUNET_SCHEDULER_run (&file_hasher, &ret);
138 GNUNET_break (0 == UNLINK (FILENAME)); 138 GNUNET_break (0 == unlink (FILENAME));
139 return ret; 139 return ret;
140} 140}
141 141
diff --git a/src/util/test_crypto_random.c b/src/util/test_crypto_random.c
index dec58086a..6386c79db 100644
--- a/src/util/test_crypto_random.c
+++ b/src/util/test_crypto_random.c
@@ -42,7 +42,7 @@ test (enum GNUNET_CRYPTO_Quality mode)
42 b2 = GNUNET_CRYPTO_random_permute (mode, 1024); 42 b2 = GNUNET_CRYPTO_random_permute (mode, 1024);
43 if (0 == memcmp (b2, buf, sizeof (buf))) 43 if (0 == memcmp (b2, buf, sizeof (buf)))
44 { 44 {
45 FPRINTF (stderr, "%s", "!"); 45 fprintf (stderr, "%s", "!");
46 GNUNET_free (b2); 46 GNUNET_free (b2);
47 continue; 47 continue;
48 } 48 }
diff --git a/src/util/test_disk.c b/src/util/test_disk.c
index 267d4d4f9..5746aa96e 100644
--- a/src/util/test_disk.c
+++ b/src/util/test_disk.c
@@ -45,13 +45,13 @@ testReadWrite ()
45 ret = GNUNET_DISK_fn_read (".testfile", tmp, sizeof (tmp) - 1); 45 ret = GNUNET_DISK_fn_read (".testfile", tmp, sizeof (tmp) - 1);
46 if (ret < 0) 46 if (ret < 0)
47 { 47 {
48 FPRINTF (stderr, "Error reading file `%s' in testReadWrite\n", ".testfile"); 48 fprintf (stderr, "Error reading file `%s' in testReadWrite\n", ".testfile");
49 return 1; 49 return 1;
50 } 50 }
51 tmp[ret] = '\0'; 51 tmp[ret] = '\0';
52 if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1)) 52 if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1))
53 { 53 {
54 FPRINTF (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", tmp, 54 fprintf (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", tmp,
55 TESTSTRING, ".testfile"); 55 TESTSTRING, ".testfile");
56 return 1; 56 return 1;
57 } 57 }
@@ -60,20 +60,20 @@ testReadWrite ()
60 ret = GNUNET_DISK_fn_read (".testfile2", tmp, sizeof (tmp) - 1); 60 ret = GNUNET_DISK_fn_read (".testfile2", tmp, sizeof (tmp) - 1);
61 if (ret < 0) 61 if (ret < 0)
62 { 62 {
63 FPRINTF (stderr, "Error reading file `%s' in testReadWrite\n", 63 fprintf (stderr, "Error reading file `%s' in testReadWrite\n",
64 ".testfile2"); 64 ".testfile2");
65 return 1; 65 return 1;
66 } 66 }
67 tmp[ret] = '\0'; 67 tmp[ret] = '\0';
68 if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1)) 68 if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1))
69 { 69 {
70 FPRINTF (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", tmp, 70 fprintf (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", tmp,
71 TESTSTRING, ".testfile2"); 71 TESTSTRING, ".testfile2");
72 return 1; 72 return 1;
73 } 73 }
74 74
75 GNUNET_break (0 == UNLINK (".testfile")); 75 GNUNET_break (0 == unlink (".testfile"));
76 GNUNET_break (0 == UNLINK (".testfile2")); 76 GNUNET_break (0 == unlink (".testfile2"));
77 if (GNUNET_NO != GNUNET_DISK_file_test (".testfile")) 77 if (GNUNET_NO != GNUNET_DISK_file_test (".testfile"))
78 return 1; 78 return 1;
79 79
@@ -99,7 +99,7 @@ testOpenClose ()
99 GNUNET_DISK_file_size (".testfile", &size, GNUNET_NO, GNUNET_YES)); 99 GNUNET_DISK_file_size (".testfile", &size, GNUNET_NO, GNUNET_YES));
100 if (size != 5) 100 if (size != 5)
101 return 1; 101 return 1;
102 GNUNET_break (0 == UNLINK (".testfile")); 102 GNUNET_break (0 == unlink (".testfile"));
103 103
104 return 0; 104 return 0;
105} 105}
@@ -281,7 +281,7 @@ main (int argc, char *argv[])
281 failureCount += testDirMani (); 281 failureCount += testDirMani ();
282 if (0 != failureCount) 282 if (0 != failureCount)
283 { 283 {
284 FPRINTF (stderr, 284 fprintf (stderr,
285 "\n%u TESTS FAILED!\n", 285 "\n%u TESTS FAILED!\n",
286 failureCount); 286 failureCount);
287 return -1; 287 return -1;
diff --git a/src/util/test_getopt.c b/src/util/test_getopt.c
index 4294117a6..d9dd7121f 100644
--- a/src/util/test_getopt.c
+++ b/src/util/test_getopt.c
@@ -28,13 +28,9 @@
28static int 28static int
29testMinimal () 29testMinimal ()
30{ 30{
31 char *const emptyargv[] = { 31 char *const emptyargv[] = {"test", NULL};
32 "test",
33 NULL
34 };
35 const struct GNUNET_GETOPT_CommandLineOption emptyoptionlist[] = { 32 const struct GNUNET_GETOPT_CommandLineOption emptyoptionlist[] = {
36 GNUNET_GETOPT_OPTION_END 33 GNUNET_GETOPT_OPTION_END};
37 };
38 34
39 if (1 != GNUNET_GETOPT_run ("test", emptyoptionlist, 1, emptyargv)) 35 if (1 != GNUNET_GETOPT_run ("test", emptyoptionlist, 1, emptyargv))
40 return 1; 36 return 1;
@@ -46,19 +42,11 @@ testMinimal ()
46static int 42static int
47testVerbose () 43testVerbose ()
48{ 44{
49 char *const myargv[] = { 45 char *const myargv[] = {"test", "-V", "-V", "more", NULL};
50 "test",
51 "-V",
52 "-V",
53 "more",
54 NULL
55 };
56 unsigned int vflags = 0; 46 unsigned int vflags = 0;
57 47
58 const struct GNUNET_GETOPT_CommandLineOption verboseoptionlist[] = { 48 const struct GNUNET_GETOPT_CommandLineOption verboseoptionlist[] =
59 GNUNET_GETOPT_option_verbose (&vflags), 49 {GNUNET_GETOPT_option_verbose (&vflags), GNUNET_GETOPT_OPTION_END};
60 GNUNET_GETOPT_OPTION_END
61 };
62 50
63 if (3 != GNUNET_GETOPT_run ("test", verboseoptionlist, 4, myargv)) 51 if (3 != GNUNET_GETOPT_run ("test", verboseoptionlist, 4, myargv))
64 { 52 {
@@ -77,15 +65,10 @@ testVerbose ()
77static int 65static int
78testVersion () 66testVersion ()
79{ 67{
80 char *const myargv[] = { 68 char *const myargv[] = {"test_getopt", "-v", NULL};
81 "test_getopt", 69 const struct GNUNET_GETOPT_CommandLineOption versionoptionlist[] =
82 "-v", 70 {GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
83 NULL 71 GNUNET_GETOPT_OPTION_END};
84 };
85 const struct GNUNET_GETOPT_CommandLineOption versionoptionlist[] = {
86 GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
87 GNUNET_GETOPT_OPTION_END
88 };
89 72
90 if (0 != GNUNET_GETOPT_run ("test_getopt", versionoptionlist, 2, myargv)) 73 if (0 != GNUNET_GETOPT_run ("test_getopt", versionoptionlist, 2, myargv))
91 { 74 {
@@ -99,15 +82,9 @@ testVersion ()
99static int 82static int
100testAbout () 83testAbout ()
101{ 84{
102 char *const myargv[] = { 85 char *const myargv[] = {"test_getopt", "-h", NULL};
103 "test_getopt", 86 const struct GNUNET_GETOPT_CommandLineOption aboutoptionlist[] =
104 "-h", 87 {GNUNET_GETOPT_option_help ("Testing"), GNUNET_GETOPT_OPTION_END};
105 NULL
106 };
107 const struct GNUNET_GETOPT_CommandLineOption aboutoptionlist[] = {
108 GNUNET_GETOPT_option_help ("Testing"),
109 GNUNET_GETOPT_OPTION_END
110 };
111 88
112 if (0 != GNUNET_GETOPT_run ("test_getopt", aboutoptionlist, 2, myargv)) 89 if (0 != GNUNET_GETOPT_run ("test_getopt", aboutoptionlist, 2, myargv))
113 { 90 {
@@ -121,31 +98,23 @@ testAbout ()
121static int 98static int
122testLogOpts () 99testLogOpts ()
123{ 100{
124 char *const myargv[] = { 101 char *const myargv[] =
125 "test_getopt", 102 {"test_getopt", "-l", "filename", "-L", "WARNING", NULL};
126 "-l", "filename",
127 "-L", "WARNING",
128 NULL
129 };
130 char *level = GNUNET_strdup ("stuff"); 103 char *level = GNUNET_strdup ("stuff");
131 char *fn = NULL; 104 char *fn = NULL;
132 105
133 const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] = { 106 const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] =
134 GNUNET_GETOPT_option_logfile (&fn), 107 {GNUNET_GETOPT_option_logfile (&fn),
135 GNUNET_GETOPT_option_loglevel (&level), 108 GNUNET_GETOPT_option_loglevel (&level),
136 GNUNET_GETOPT_OPTION_END 109 GNUNET_GETOPT_OPTION_END};
137 };
138 110
139 if (5 != GNUNET_GETOPT_run ("test_getopt", 111 if (5 != GNUNET_GETOPT_run ("test_getopt", logoptionlist, 5, myargv))
140 logoptionlist,
141 5, myargv))
142 { 112 {
143 GNUNET_break (0); 113 GNUNET_break (0);
144 return 1; 114 return 1;
145 } 115 }
146 GNUNET_assert (NULL != fn); 116 GNUNET_assert (NULL != fn);
147 if ( (0 != strcmp (level, "WARNING")) || 117 if ((0 != strcmp (level, "WARNING")) || (NULL == strstr (fn, "/filename")))
148 (NULL == strstr (fn, "/filename")) )
149 { 118 {
150 GNUNET_break (0); 119 GNUNET_break (0);
151 GNUNET_free (level); 120 GNUNET_free (level);
@@ -161,47 +130,23 @@ testLogOpts ()
161static int 130static int
162testFlagNum () 131testFlagNum ()
163{ 132{
164 char *const myargv[] = { 133 char *const myargv[] = {"test_getopt", "-f", "-n", "42", "-N", "42", NULL};
165 "test_getopt",
166 "-f",
167 "-n", "42",
168 "-N", "42",
169 NULL
170 };
171 int flag = 0; 134 int flag = 0;
172 unsigned int num = 0; 135 unsigned int num = 0;
173 unsigned long long lnum = 0; 136 unsigned long long lnum = 0;
174 137
175 const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] = { 138 const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] =
176 GNUNET_GETOPT_option_flag ('f', 139 {GNUNET_GETOPT_option_flag ('f', "--flag", "helptext", &flag),
177 "--flag", 140 GNUNET_GETOPT_option_uint ('n', "--num", "ARG", "helptext", &num),
178 "helptext", 141 GNUNET_GETOPT_option_ulong ('N', "--lnum", "ARG", "helptext", &lnum),
179 &flag), 142 GNUNET_GETOPT_OPTION_END};
180 GNUNET_GETOPT_option_uint ('n', 143
181 "--num", 144 if (6 != GNUNET_GETOPT_run ("test_getopt", logoptionlist, 6, myargv))
182 "ARG",
183 "helptext",
184 &num),
185 GNUNET_GETOPT_option_ulong ('N',
186 "--lnum",
187 "ARG",
188 "helptext",
189 &lnum),
190 GNUNET_GETOPT_OPTION_END
191 };
192
193 if (6 !=
194 GNUNET_GETOPT_run ("test_getopt",
195 logoptionlist,
196 6,
197 myargv))
198 { 145 {
199 GNUNET_break (0); 146 GNUNET_break (0);
200 return 1; 147 return 1;
201 } 148 }
202 if ( (1 != flag) || 149 if ((1 != flag) || (42 != num) || (42 != lnum))
203 (42 != num) ||
204 (42 != lnum))
205 { 150 {
206 GNUNET_break (0); 151 GNUNET_break (0);
207 return 1; 152 return 1;
@@ -215,12 +160,10 @@ main (int argc, char *argv[])
215{ 160{
216 int errCnt = 0; 161 int errCnt = 0;
217 162
218 GNUNET_log_setup ("test_getopt", 163 GNUNET_log_setup ("test_getopt", "WARNING", NULL);
219 "WARNING",
220 NULL);
221 /* suppress output from -h, -v options */ 164 /* suppress output from -h, -v options */
222#ifndef MINGW 165#ifndef MINGW
223 GNUNET_break (0 == CLOSE (1)); 166 GNUNET_break (0 == close (1));
224#endif 167#endif
225 if (0 != testMinimal ()) 168 if (0 != testMinimal ())
226 errCnt++; 169 errCnt++;
diff --git a/src/util/test_peer.c b/src/util/test_peer.c
index 248836b4c..b059f2cf3 100644
--- a/src/util/test_peer.c
+++ b/src/util/test_peer.c
@@ -65,7 +65,7 @@ check ()
65 pid = GNUNET_PEER_intern (&pidArr[i]); 65 pid = GNUNET_PEER_intern (&pidArr[i]);
66 if (pid != (i + 1)) 66 if (pid != (i + 1))
67 { 67 {
68 FPRINTF (stderr, "%s", "Unexpected Peer ID returned by intern function\n"); 68 fprintf (stderr, "%s", "Unexpected Peer ID returned by intern function\n");
69 return 1; 69 return 1;
70 } 70 }
71 } 71 }
@@ -76,7 +76,7 @@ check ()
76 pid = GNUNET_PEER_intern (&pidArr[i]); 76 pid = GNUNET_PEER_intern (&pidArr[i]);
77 if (pid != (i + 1)) 77 if (pid != (i + 1))
78 { 78 {
79 FPRINTF (stderr, "%s", "Unexpected Peer ID returned by intern function\n"); 79 fprintf (stderr, "%s", "Unexpected Peer ID returned by intern function\n");
80 return 1; 80 return 1;
81 } 81 }
82 } 82 }
diff --git a/src/util/test_resolver_api.c b/src/util/test_resolver_api.c
index 686301694..f4184aa84 100644
--- a/src/util/test_resolver_api.c
+++ b/src/util/test_resolver_api.c
@@ -229,7 +229,7 @@ run (void *cls, char *const *args, const char *cfgfile,
229 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 229 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
230 _("gethostbyname() could not lookup IP address: %s\n"), 230 _("gethostbyname() could not lookup IP address: %s\n"),
231 hstrerror (h_errno)); 231 hstrerror (h_errno));
232 FPRINTF (stderr, 232 fprintf (stderr,
233 "%s", 233 "%s",
234 "System seems to be off-line, will not run all DNS tests\n"); 234 "System seems to be off-line, will not run all DNS tests\n");
235 *ok = 0; /* mark test as passing anyway */ 235 *ok = 0; /* mark test as passing anyway */
@@ -373,7 +373,7 @@ main (int argc, char *argv[])
373 GNUNET_OS_process_destroy (proc); 373 GNUNET_OS_process_destroy (proc);
374 proc = NULL; 374 proc = NULL;
375 if (0 != ok) 375 if (0 != ok)
376 FPRINTF (stderr, "Missed some resolutions: %u\n", ok); 376 fprintf (stderr, "Missed some resolutions: %u\n", ok);
377 return ok; 377 return ok;
378} 378}
379 379
diff --git a/src/util/test_scheduler.c b/src/util/test_scheduler.c
index c38af8a0a..234a2aae1 100644
--- a/src/util/test_scheduler.c
+++ b/src/util/test_scheduler.c
@@ -224,7 +224,7 @@ taskSig (void *cls)
224 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), 224 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
225 &taskNeverRun, 225 &taskNeverRun,
226 NULL); 226 NULL);
227 GNUNET_break (0 == PLIBC_KILL (getpid (), 227 GNUNET_break (0 == kill (getpid (),
228 GNUNET_TERM_SIG)); 228 GNUNET_TERM_SIG));
229} 229}
230 230
diff --git a/src/util/test_scheduler_delay.c b/src/util/test_scheduler_delay.c
index 6c25531f2..1ec86c647 100644
--- a/src/util/test_scheduler_delay.c
+++ b/src/util/test_scheduler_delay.c
@@ -55,10 +55,10 @@ test_task (void *cls)
55 target = 55 target =
56 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply 56 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
57 (GNUNET_TIME_UNIT_MICROSECONDS, i)); 57 (GNUNET_TIME_UNIT_MICROSECONDS, i));
58 FPRINTF (stderr, "%s", "."); 58 fprintf (stderr, "%s", ".");
59 if (i > MAXV) 59 if (i > MAXV)
60 { 60 {
61 FPRINTF (stderr, "%s", "\n"); 61 fprintf (stderr, "%s", "\n");
62 return; 62 return;
63 } 63 }
64 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 64 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
@@ -77,17 +77,17 @@ main (int argc, char *argv[])
77 NULL); 77 NULL);
78 target = GNUNET_TIME_absolute_get (); 78 target = GNUNET_TIME_absolute_get ();
79 GNUNET_SCHEDULER_run (&test_task, NULL); 79 GNUNET_SCHEDULER_run (&test_task, NULL);
80 FPRINTF (stdout, 80 fprintf (stdout,
81 "Sleep precision: %llu microseconds (average delta). ", 81 "Sleep precision: %llu microseconds (average delta). ",
82 cumDelta / (MAXV / INCR)); 82 cumDelta / (MAXV / INCR));
83 if (cumDelta <= 500 * MAXV / INCR) 83 if (cumDelta <= 500 * MAXV / INCR)
84 FPRINTF (stdout, "%s", "Timer precision is excellent.\n"); 84 fprintf (stdout, "%s", "Timer precision is excellent.\n");
85 else if (cumDelta <= 5000 * MAXV / INCR) /* 5 ms average deviation */ 85 else if (cumDelta <= 5000 * MAXV / INCR) /* 5 ms average deviation */
86 FPRINTF (stdout, "%s", "Timer precision is good.\n"); 86 fprintf (stdout, "%s", "Timer precision is good.\n");
87 else if (cumDelta > 25000 * MAXV / INCR) 87 else if (cumDelta > 25000 * MAXV / INCR)
88 FPRINTF (stdout, "%s", "Timer precision is awful.\n"); 88 fprintf (stdout, "%s", "Timer precision is awful.\n");
89 else 89 else
90 FPRINTF (stdout, "%s", "Timer precision is acceptable.\n"); 90 fprintf (stdout, "%s", "Timer precision is acceptable.\n");
91 return 0; 91 return 0;
92} 92}
93 93
diff --git a/src/util/test_service.c b/src/util/test_service.c
index 72bd1f371..dc8bc59c1 100644
--- a/src/util/test_service.c
+++ b/src/util/test_service.c
@@ -222,7 +222,7 @@ main (int argc,
222 "socket"); 222 "socket");
223 return 1; 223 return 1;
224 } 224 }
225 FPRINTF (stderr, 225 fprintf (stderr,
226 "IPv6 support seems to not be available (%s), not testing it!\n", 226 "IPv6 support seems to not be available (%s), not testing it!\n",
227 strerror (errno)); 227 strerror (errno));
228 } 228 }
diff --git a/src/util/test_strings.c b/src/util/test_strings.c
index 652c3be23..9e4e808ef 100644
--- a/src/util/test_strings.c
+++ b/src/util/test_strings.c
@@ -93,7 +93,7 @@ main (int argc, char *argv[])
93 * however, the "0:05 19" should always be there; hence: */ 93 * however, the "0:05 19" should always be there; hence: */
94 if (NULL == strstr (bc, "0:05 19")) 94 if (NULL == strstr (bc, "0:05 19"))
95 { 95 {
96 FPRINTF (stderr, "Got %s\n", bc); 96 fprintf (stderr, "Got %s\n", bc);
97 GNUNET_break (0); 97 GNUNET_break (0);
98 return 1; 98 return 1;
99 } 99 }
diff --git a/src/util/time.c b/src/util/time.c
index 758921718..85a781aff 100644
--- a/src/util/time.c
+++ b/src/util/time.c
@@ -37,7 +37,7 @@
37#endif 37#endif
38#endif 38#endif
39 39
40#define LOG(kind,...) GNUNET_log_from (kind, "util-time", __VA_ARGS__) 40#define LOG(kind, ...) GNUNET_log_from (kind, "util-time", __VA_ARGS__)
41 41
42/** 42/**
43 * Variable used to simulate clock skew. Used for testing, never in production. 43 * Variable used to simulate clock skew. Used for testing, never in production.
@@ -120,10 +120,10 @@ GNUNET_TIME_absolute_get ()
120 struct GNUNET_TIME_Absolute ret; 120 struct GNUNET_TIME_Absolute ret;
121 struct timeval tv; 121 struct timeval tv;
122 122
123 GETTIMEOFDAY (&tv, NULL); 123 gettimeofday (&tv, NULL);
124 ret.abs_value_us = 124 ret.abs_value_us = (uint64_t) (((uint64_t) tv.tv_sec * 1000LL * 1000LL) +
125 (uint64_t) (((uint64_t) tv.tv_sec * 1000LL * 1000LL) + 125 ((uint64_t) tv.tv_usec)) +
126 ((uint64_t) tv.tv_usec)) + timestamp_offset; 126 timestamp_offset;
127 return ret; 127 return ret;
128} 128}
129 129
@@ -158,7 +158,7 @@ GNUNET_TIME_absolute_get_zero_ ()
158struct GNUNET_TIME_Relative 158struct GNUNET_TIME_Relative
159GNUNET_TIME_relative_get_unit_ () 159GNUNET_TIME_relative_get_unit_ ()
160{ 160{
161 static struct GNUNET_TIME_Relative one = { 1 }; 161 static struct GNUNET_TIME_Relative one = {1};
162 162
163 return one; 163 return one;
164} 164}
@@ -170,7 +170,7 @@ GNUNET_TIME_relative_get_unit_ ()
170struct GNUNET_TIME_Relative 170struct GNUNET_TIME_Relative
171GNUNET_TIME_relative_get_millisecond_ () 171GNUNET_TIME_relative_get_millisecond_ ()
172{ 172{
173 static struct GNUNET_TIME_Relative one = { 1000 }; 173 static struct GNUNET_TIME_Relative one = {1000};
174 174
175 return one; 175 return one;
176} 176}
@@ -182,7 +182,7 @@ GNUNET_TIME_relative_get_millisecond_ ()
182struct GNUNET_TIME_Relative 182struct GNUNET_TIME_Relative
183GNUNET_TIME_relative_get_second_ () 183GNUNET_TIME_relative_get_second_ ()
184{ 184{
185 static struct GNUNET_TIME_Relative one = { 1000 * 1000LL }; 185 static struct GNUNET_TIME_Relative one = {1000 * 1000LL};
186 186
187 return one; 187 return one;
188} 188}
@@ -194,7 +194,7 @@ GNUNET_TIME_relative_get_second_ ()
194struct GNUNET_TIME_Relative 194struct GNUNET_TIME_Relative
195GNUNET_TIME_relative_get_minute_ () 195GNUNET_TIME_relative_get_minute_ ()
196{ 196{
197 static struct GNUNET_TIME_Relative one = { 60 * 1000 * 1000LL }; 197 static struct GNUNET_TIME_Relative one = {60 * 1000 * 1000LL};
198 198
199 return one; 199 return one;
200} 200}
@@ -206,7 +206,7 @@ GNUNET_TIME_relative_get_minute_ ()
206struct GNUNET_TIME_Relative 206struct GNUNET_TIME_Relative
207GNUNET_TIME_relative_get_hour_ () 207GNUNET_TIME_relative_get_hour_ ()
208{ 208{
209 static struct GNUNET_TIME_Relative one = { 60 * 60 * 1000 * 1000LL }; 209 static struct GNUNET_TIME_Relative one = {60 * 60 * 1000 * 1000LL};
210 210
211 return one; 211 return one;
212} 212}
@@ -218,7 +218,7 @@ GNUNET_TIME_relative_get_hour_ ()
218struct GNUNET_TIME_Relative 218struct GNUNET_TIME_Relative
219GNUNET_TIME_relative_get_forever_ () 219GNUNET_TIME_relative_get_forever_ ()
220{ 220{
221 static struct GNUNET_TIME_Relative forever = { UINT64_MAX }; 221 static struct GNUNET_TIME_Relative forever = {UINT64_MAX};
222 222
223 return forever; 223 return forever;
224} 224}
@@ -230,7 +230,7 @@ GNUNET_TIME_relative_get_forever_ ()
230struct GNUNET_TIME_Absolute 230struct GNUNET_TIME_Absolute
231GNUNET_TIME_absolute_get_forever_ () 231GNUNET_TIME_absolute_get_forever_ ()
232{ 232{
233 static struct GNUNET_TIME_Absolute forever = { UINT64_MAX }; 233 static struct GNUNET_TIME_Absolute forever = {UINT64_MAX};
234 return forever; 234 return forever;
235} 235}
236 236
@@ -252,7 +252,7 @@ GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel)
252 252
253 if (rel.rel_value_us + now.abs_value_us < rel.rel_value_us) 253 if (rel.rel_value_us + now.abs_value_us < rel.rel_value_us)
254 { 254 {
255 GNUNET_break (0); /* overflow... */ 255 GNUNET_break (0); /* overflow... */
256 return GNUNET_TIME_UNIT_FOREVER_ABS; 256 return GNUNET_TIME_UNIT_FOREVER_ABS;
257 } 257 }
258 ret.abs_value_us = rel.rel_value_us + now.abs_value_us; 258 ret.abs_value_us = rel.rel_value_us + now.abs_value_us;
@@ -290,7 +290,6 @@ GNUNET_TIME_relative_max (struct GNUNET_TIME_Relative t1,
290} 290}
291 291
292 292
293
294/** 293/**
295 * Return the minimum of two relative time values. 294 * Return the minimum of two relative time values.
296 * 295 *
@@ -395,7 +394,8 @@ GNUNET_TIME_absolute_add (struct GNUNET_TIME_Absolute start,
395{ 394{
396 struct GNUNET_TIME_Absolute ret; 395 struct GNUNET_TIME_Absolute ret;
397 396
398 if ((start.abs_value_us == UINT64_MAX) || (duration.rel_value_us == UINT64_MAX)) 397 if ((start.abs_value_us == UINT64_MAX) ||
398 (duration.rel_value_us == UINT64_MAX))
399 return GNUNET_TIME_UNIT_FOREVER_ABS; 399 return GNUNET_TIME_UNIT_FOREVER_ABS;
400 if (start.abs_value_us + duration.rel_value_us < start.abs_value_us) 400 if (start.abs_value_us + duration.rel_value_us < start.abs_value_us)
401 { 401 {
@@ -462,8 +462,7 @@ GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel,
462 * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor 462 * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor
463 */ 463 */
464struct GNUNET_TIME_Relative 464struct GNUNET_TIME_Relative
465relative_multiply_double (struct GNUNET_TIME_Relative rel, 465relative_multiply_double (struct GNUNET_TIME_Relative rel, double factor)
466 double factor)
467{ 466{
468 struct GNUNET_TIME_Relative out; 467 struct GNUNET_TIME_Relative out;
469 double m; 468 double m;
@@ -546,7 +545,8 @@ GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel,
546 * assuming it continues at the same speed 545 * assuming it continues at the same speed
547 */ 546 */
548struct GNUNET_TIME_Relative 547struct GNUNET_TIME_Relative
549GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start, uint64_t finished, 548GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start,
549 uint64_t finished,
550 uint64_t total) 550 uint64_t total)
551{ 551{
552 struct GNUNET_TIME_Relative dur; 552 struct GNUNET_TIME_Relative dur;
@@ -673,7 +673,6 @@ GNUNET_TIME_absolute_ntoh (struct GNUNET_TIME_AbsoluteNBO a)
673 673
674 ret.abs_value_us = GNUNET_ntohll (a.abs_value_us__); 674 ret.abs_value_us = GNUNET_ntohll (a.abs_value_us__);
675 return ret; 675 return ret;
676
677} 676}
678 677
679 678
@@ -706,12 +705,11 @@ GNUNET_TIME_time_to_year (struct GNUNET_TIME_Absolute at)
706 struct tm *t; 705 struct tm *t;
707 time_t tp; 706 time_t tp;
708 707
709 tp = at.abs_value_us / 1000LL / 1000LL; /* microseconds to seconds */ 708 tp = at.abs_value_us / 1000LL / 1000LL; /* microseconds to seconds */
710 t = gmtime (&tp); 709 t = gmtime (&tp);
711 if (t == NULL) 710 if (t == NULL)
712 return 0; 711 return 0;
713 return t->tm_year + 1900; 712 return t->tm_year + 1900;
714
715} 713}
716 714
717 715
@@ -740,8 +738,8 @@ GNUNET_TIME_year_to_time (unsigned int year)
740 t.tm_wday = 1; 738 t.tm_wday = 1;
741 t.tm_yday = 1; 739 t.tm_yday = 1;
742 tp = mktime (&t); 740 tp = mktime (&t);
743 GNUNET_break (tp != (time_t) - 1); 741 GNUNET_break (tp != (time_t) -1);
744 ret.abs_value_us = tp * 1000LL * 1000LL; /* seconds to microseconds */ 742 ret.abs_value_us = tp * 1000LL * 1000LL; /* seconds to microseconds */
745 return ret; 743 return ret;
746} 744}
747 745
@@ -756,16 +754,16 @@ GNUNET_TIME_year_to_time (unsigned int year)
756 * @return the next backoff time 754 * @return the next backoff time
757 */ 755 */
758struct GNUNET_TIME_Relative 756struct GNUNET_TIME_Relative
759GNUNET_TIME_randomized_backoff(struct GNUNET_TIME_Relative rt, struct GNUNET_TIME_Relative threshold) 757GNUNET_TIME_randomized_backoff (struct GNUNET_TIME_Relative rt,
758 struct GNUNET_TIME_Relative threshold)
760{ 759{
761 double r = (rand() % 500) / 1000.0; 760 double r = (rand () % 500) / 1000.0;
762 struct GNUNET_TIME_Relative t; 761 struct GNUNET_TIME_Relative t;
763 762
764 t = relative_multiply_double (GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS, 763 t = relative_multiply_double (
765 rt), 764 GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS, rt),
766 2 + r); 765 2 + r);
767 return GNUNET_TIME_relative_min (threshold, 766 return GNUNET_TIME_relative_min (threshold, t);
768 t);
769} 767}
770 768
771 769
@@ -778,10 +776,9 @@ GNUNET_TIME_randomized_backoff(struct GNUNET_TIME_Relative rt, struct GNUNET_TIM
778struct GNUNET_TIME_Relative 776struct GNUNET_TIME_Relative
779GNUNET_TIME_randomize (struct GNUNET_TIME_Relative r) 777GNUNET_TIME_randomize (struct GNUNET_TIME_Relative r)
780{ 778{
781 double d = ((rand() % 1001) - 500) / 1000.0; 779 double d = ((rand () % 1001) - 500) / 1000.0;
782 780
783 return relative_multiply_double (r, 781 return relative_multiply_double (r, d);
784 d);
785} 782}
786 783
787 784
@@ -804,7 +801,8 @@ GNUNET_TIME_randomize (struct GNUNET_TIME_Relative r)
804 * @return monotonically increasing time 801 * @return monotonically increasing time
805 */ 802 */
806struct GNUNET_TIME_Absolute 803struct GNUNET_TIME_Absolute
807GNUNET_TIME_absolute_get_monotonic (const struct GNUNET_CONFIGURATION_Handle *cfg) 804GNUNET_TIME_absolute_get_monotonic (
805 const struct GNUNET_CONFIGURATION_Handle *cfg)
808{ 806{
809 static const struct GNUNET_CONFIGURATION_Handle *last_cfg; 807 static const struct GNUNET_CONFIGURATION_Handle *last_cfg;
810 static struct GNUNET_TIME_Absolute last_time; 808 static struct GNUNET_TIME_Absolute last_time;
@@ -825,23 +823,26 @@ GNUNET_TIME_absolute_get_monotonic (const struct GNUNET_CONFIGURATION_Handle *cf
825 map = NULL; 823 map = NULL;
826 824
827 last_cfg = cfg; 825 last_cfg = cfg;
828 if ( (NULL != cfg) && 826 if ((NULL != cfg) &&
829 (GNUNET_OK == 827 (GNUNET_OK ==
830 GNUNET_CONFIGURATION_get_value_filename (cfg, 828 GNUNET_CONFIGURATION_get_value_filename (cfg,
831 "util", 829 "util",
832 "MONOTONIC_TIME_FILENAME", 830 "MONOTONIC_TIME_FILENAME",
833 &filename)) ) 831 &filename)))
834 { 832 {
835 struct GNUNET_DISK_FileHandle *fh; 833 struct GNUNET_DISK_FileHandle *fh;
836 834
837 fh = GNUNET_DISK_file_open (filename, 835 fh = GNUNET_DISK_file_open (filename,
838 GNUNET_DISK_OPEN_READWRITE | GNUNET_DISK_OPEN_CREATE, 836 GNUNET_DISK_OPEN_READWRITE |
839 GNUNET_DISK_PERM_USER_WRITE | GNUNET_DISK_PERM_GROUP_WRITE | 837 GNUNET_DISK_OPEN_CREATE,
840 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_GROUP_READ); 838 GNUNET_DISK_PERM_USER_WRITE |
839 GNUNET_DISK_PERM_GROUP_WRITE |
840 GNUNET_DISK_PERM_USER_READ |
841 GNUNET_DISK_PERM_GROUP_READ);
841 if (NULL == fh) 842 if (NULL == fh)
842 { 843 {
843 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 844 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
844 _("Failed to map `%s', cannot assure monotonic time!\n"), 845 _ ("Failed to map `%s', cannot assure monotonic time!\n"),
845 filename); 846 filename);
846 } 847 }
847 else 848 else
@@ -849,18 +850,13 @@ GNUNET_TIME_absolute_get_monotonic (const struct GNUNET_CONFIGURATION_Handle *cf
849 off_t size; 850 off_t size;
850 851
851 size = 0; 852 size = 0;
852 GNUNET_break (GNUNET_OK == 853 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_handle_size (fh, &size));
853 GNUNET_DISK_file_handle_size (fh,
854 &size));
855 if (size < (off_t) sizeof (*map)) 854 if (size < (off_t) sizeof (*map))
856 { 855 {
857 struct GNUNET_TIME_AbsoluteNBO o; 856 struct GNUNET_TIME_AbsoluteNBO o;
858 857
859 o = GNUNET_TIME_absolute_hton (now); 858 o = GNUNET_TIME_absolute_hton (now);
860 if (sizeof (o) != 859 if (sizeof (o) != GNUNET_DISK_file_write (fh, &o, sizeof (o)))
861 GNUNET_DISK_file_write (fh,
862 &o,
863 sizeof (o)))
864 size = 0; 860 size = 0;
865 else 861 else
866 size = sizeof (o); 862 size = sizeof (o);
@@ -873,14 +869,17 @@ GNUNET_TIME_absolute_get_monotonic (const struct GNUNET_CONFIGURATION_Handle *cf
873 sizeof (*map)); 869 sizeof (*map));
874 if (NULL == map) 870 if (NULL == map)
875 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 871 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
876 _("Failed to map `%s', cannot assure monotonic time!\n"), 872 _ (
873 "Failed to map `%s', cannot assure monotonic time!\n"),
877 filename); 874 filename);
878 } 875 }
879 else 876 else
880 { 877 {
881 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 878 GNUNET_log (
882 _("Failed to setup monotonic time file `%s', cannot assure monotonic time!\n"), 879 GNUNET_ERROR_TYPE_WARNING,
883 filename); 880 _ (
881 "Failed to setup monotonic time file `%s', cannot assure monotonic time!\n"),
882 filename);
884 } 883 }
885 } 884 }
886 GNUNET_DISK_file_close (fh); 885 GNUNET_DISK_file_close (fh);
@@ -900,11 +899,11 @@ GNUNET_TIME_absolute_get_monotonic (const struct GNUNET_CONFIGURATION_Handle *cf
900#else 899#else
901 mt.abs_value_us__ = atomic_load (map); 900 mt.abs_value_us__ = atomic_load (map);
902#endif 901#endif
903 last_time = GNUNET_TIME_absolute_max (GNUNET_TIME_absolute_ntoh (mt), 902 last_time =
904 last_time); 903 GNUNET_TIME_absolute_max (GNUNET_TIME_absolute_ntoh (mt), last_time);
905 } 904 }
906 if (now.abs_value_us <= last_time.abs_value_us) 905 if (now.abs_value_us <= last_time.abs_value_us)
907 now.abs_value_us = last_time.abs_value_us+1; 906 now.abs_value_us = last_time.abs_value_us + 1;
908 last_time = now; 907 last_time = now;
909 if (NULL != map) 908 if (NULL != map)
910 { 909 {
@@ -913,11 +912,10 @@ GNUNET_TIME_absolute_get_monotonic (const struct GNUNET_CONFIGURATION_Handle *cf
913#if __GNUC__ 912#if __GNUC__
914 (void) __sync_lock_test_and_set (map, val); 913 (void) __sync_lock_test_and_set (map, val);
915#else 914#else
916 *map = val; /* godspeed, pray this is atomic */ 915 *map = val; /* godspeed, pray this is atomic */
917#endif 916#endif
918#else 917#else
919 atomic_store (map, 918 atomic_store (map, val);
920 val);
921#endif 919#endif
922 } 920 }
923 return now; 921 return now;
@@ -927,8 +925,7 @@ GNUNET_TIME_absolute_get_monotonic (const struct GNUNET_CONFIGURATION_Handle *cf
927/** 925/**
928 * Destructor 926 * Destructor
929 */ 927 */
930void __attribute__ ((destructor)) 928void __attribute__ ((destructor)) GNUNET_util_time_fini ()
931GNUNET_util_time_fini ()
932{ 929{
933 (void) GNUNET_TIME_absolute_get_monotonic (NULL); 930 (void) GNUNET_TIME_absolute_get_monotonic (NULL);
934} 931}
diff --git a/src/vpn/gnunet-vpn.c b/src/vpn/gnunet-vpn.c
index 38ead2023..1651767f4 100644
--- a/src/vpn/gnunet-vpn.c
+++ b/src/vpn/gnunet-vpn.c
@@ -88,7 +88,7 @@ static int ret;
88/** 88/**
89 * Option '-d': duration of the mapping 89 * Option '-d': duration of the mapping
90 */ 90 */
91static struct GNUNET_TIME_Relative duration = { 5 * 60 * 1000} ; 91static struct GNUNET_TIME_Relative duration = {5 * 60 * 1000};
92 92
93 93
94/** 94/**
@@ -127,9 +127,7 @@ do_disconnect (void *cls)
127 * specified target peer; NULL on error 127 * specified target peer; NULL on error
128 */ 128 */
129static void 129static void
130allocation_cb (void *cls, 130allocation_cb (void *cls, int af, const void *address)
131 int af,
132 const void *address)
133{ 131{
134 char buf[INET6_ADDRSTRLEN]; 132 char buf[INET6_ADDRSTRLEN];
135 133
@@ -138,13 +136,10 @@ allocation_cb (void *cls,
138 { 136 {
139 case AF_INET6: 137 case AF_INET6:
140 case AF_INET: 138 case AF_INET:
141 FPRINTF (stdout, 139 fprintf (stdout, "%s\n", inet_ntop (af, address, buf, sizeof (buf)));
142 "%s\n",
143 inet_ntop (af, address, buf, sizeof (buf)));
144 break; 140 break;
145 case AF_UNSPEC: 141 case AF_UNSPEC:
146 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 142 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Error creating tunnel\n"));
147 _("Error creating tunnel\n"));
148 ret = 1; 143 ret = 1;
149 break; 144 break;
150 default: 145 default:
@@ -188,8 +183,10 @@ run (void *cls,
188 { 183 {
189 if (ipv6) 184 if (ipv6)
190 { 185 {
191 FPRINTF (stderr, _("Option `%s' makes no sense with option `%s'.\n"), 186 fprintf (stderr,
192 "-4", "-6"); 187 _ ("Option `%s' makes no sense with option `%s'.\n"),
188 "-4",
189 "-6");
193 goto error; 190 goto error;
194 } 191 }
195 req_af = AF_INET; 192 req_af = AF_INET;
@@ -201,26 +198,32 @@ run (void *cls,
201 { 198 {
202 if (NULL == service_name) 199 if (NULL == service_name)
203 { 200 {
204 FPRINTF (stderr, _("Option `%s' or `%s' is required.\n"), 201 fprintf (stderr, _ ("Option `%s' or `%s' is required.\n"), "-i", "-s");
205 "-i", "-s");
206 goto error; 202 goto error;
207 } 203 }
208 if (NULL == peer_id) 204 if (NULL == peer_id)
209 { 205 {
210 FPRINTF (stderr, _("Option `%s' is required when using option `%s'.\n"), 206 fprintf (stderr,
211 "-p", "-s"); 207 _ ("Option `%s' is required when using option `%s'.\n"),
208 "-p",
209 "-s");
212 goto error; 210 goto error;
213 } 211 }
214 if (! (tcp | udp) ) 212 if (! (tcp | udp))
215 { 213 {
216 FPRINTF (stderr, _("Option `%s' or `%s' is required when using option `%s'.\n"), 214 fprintf (stderr,
217 "-t", "-u", "-s"); 215 _ ("Option `%s' or `%s' is required when using option `%s'.\n"),
216 "-t",
217 "-u",
218 "-s");
218 goto error; 219 goto error;
219 } 220 }
220 if (tcp & udp) 221 if (tcp & udp)
221 { 222 {
222 FPRINTF (stderr, _("Option `%s' makes no sense with option `%s'.\n"), 223 fprintf (stderr,
223 "-t", "-u"); 224 _ ("Option `%s' makes no sense with option `%s'.\n"),
225 "-t",
226 "-u");
224 goto error; 227 goto error;
225 } 228 }
226 if (tcp) 229 if (tcp)
@@ -228,24 +231,22 @@ run (void *cls,
228 if (udp) 231 if (udp)
229 protocol = IPPROTO_UDP; 232 protocol = IPPROTO_UDP;
230 if (GNUNET_OK != 233 if (GNUNET_OK !=
231 GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id, 234 GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
232 strlen (peer_id), 235 strlen (peer_id),
233 &peer.public_key)) 236 &peer.public_key))
234 { 237 {
235 FPRINTF (stderr, 238 fprintf (stderr, _ ("`%s' is not a valid peer identifier.\n"), peer_id);
236 _("`%s' is not a valid peer identifier.\n"),
237 peer_id);
238 goto error; 239 goto error;
239 } 240 }
240 GNUNET_TUN_service_name_to_hash (service_name, 241 GNUNET_TUN_service_name_to_hash (service_name, &sd);
241 &sd);
242 request = GNUNET_VPN_redirect_to_peer (handle, 242 request = GNUNET_VPN_redirect_to_peer (handle,
243 req_af, 243 req_af,
244 protocol, 244 protocol,
245 &peer, 245 &peer,
246 &sd, 246 &sd,
247 etime, 247 etime,
248 &allocation_cb, NULL); 248 &allocation_cb,
249 NULL);
249 } 250 }
250 else 251 else
251 { 252 {
@@ -253,14 +254,13 @@ run (void *cls,
253 { 254 {
254 if (1 != inet_pton (AF_INET, target_ip, &v4)) 255 if (1 != inet_pton (AF_INET, target_ip, &v4))
255 { 256 {
256 FPRINTF (stderr, _("`%s' is not a valid IP address.\n"), 257 fprintf (stderr, _ ("`%s' is not a valid IP address.\n"), target_ip);
257 target_ip); 258 goto error;
258 goto error;
259 } 259 }
260 else 260 else
261 { 261 {
262 dst_af = AF_INET; 262 dst_af = AF_INET;
263 addr = &v4; 263 addr = &v4;
264 } 264 }
265 } 265 }
266 else 266 else
@@ -269,15 +269,16 @@ run (void *cls,
269 addr = &v6; 269 addr = &v6;
270 } 270 }
271 request = GNUNET_VPN_redirect_to_ip (handle, 271 request = GNUNET_VPN_redirect_to_ip (handle,
272 req_af, 272 req_af,
273 dst_af, 273 dst_af,
274 addr, 274 addr,
275 etime, 275 etime,
276 &allocation_cb, NULL); 276 &allocation_cb,
277 NULL);
277 } 278 }
278 return; 279 return;
279 280
280 error: 281error:
281 GNUNET_SCHEDULER_shutdown (); 282 GNUNET_SCHEDULER_shutdown ();
282 ret = 1; 283 ret = 1;
283} 284}
@@ -286,63 +287,73 @@ run (void *cls,
286int 287int
287main (int argc, char *const *argv) 288main (int argc, char *const *argv)
288{ 289{
289 struct GNUNET_GETOPT_CommandLineOption options[] = { 290 struct GNUNET_GETOPT_CommandLineOption options[] =
290 GNUNET_GETOPT_option_flag ('4', 291 {GNUNET_GETOPT_option_flag ('4',
291 "ipv4", 292 "ipv4",
292 gettext_noop ("request that result should be an IPv4 address"), 293 gettext_noop (
293 &ipv4), 294 "request that result should be an IPv4 address"),
294 295 &ipv4),
295 GNUNET_GETOPT_option_flag ('6', 296
296 "ipv6", 297 GNUNET_GETOPT_option_flag ('6',
297 gettext_noop ("request that result should be an IPv6 address"), 298 "ipv6",
298 &ipv6), 299 gettext_noop (
299 300 "request that result should be an IPv6 address"),
300 GNUNET_GETOPT_option_relative_time ('d', 301 &ipv6),
301 "duration", 302
302 "TIME", 303 GNUNET_GETOPT_option_relative_time (
303 gettext_noop ("how long should the mapping be valid for new tunnels?"), 304 'd',
304 &duration), 305 "duration",
305 306 "TIME",
306 GNUNET_GETOPT_option_string ('i', 307 gettext_noop ("how long should the mapping be valid for new tunnels?"),
307 "ip", 308 &duration),
308 "IP", 309
309 gettext_noop ("destination IP for the tunnel"), 310 GNUNET_GETOPT_option_string ('i',
310 &target_ip), 311 "ip",
311 312 "IP",
312 GNUNET_GETOPT_option_string ('p', 313 gettext_noop (
313 "peer", 314 "destination IP for the tunnel"),
314 "PEERID", 315 &target_ip),
315 gettext_noop ("peer offering the service we would like to access"), 316
316 &peer_id), 317 GNUNET_GETOPT_option_string (
317 318 'p',
318 GNUNET_GETOPT_option_string ('s', 319 "peer",
319 "service", 320 "PEERID",
320 "NAME", 321 gettext_noop ("peer offering the service we would like to access"),
321 gettext_noop ("name of the service we would like to access"), 322 &peer_id),
322 &service_name), 323
323 324 GNUNET_GETOPT_option_string ('s',
324 GNUNET_GETOPT_option_flag ('t', 325 "service",
325 "tcp", 326 "NAME",
326 gettext_noop ("service is offered via TCP"), 327 gettext_noop (
327 &tcp), 328 "name of the service we would like to access"),
328 329 &service_name),
329 GNUNET_GETOPT_option_flag ('u', 330
330 "udp", 331 GNUNET_GETOPT_option_flag ('t',
331 gettext_noop ("service is offered via UDP"), 332 "tcp",
332 &udp), 333 gettext_noop ("service is offered via TCP"),
333 334 &tcp),
334 GNUNET_GETOPT_option_verbose (&verbosity), 335
335 336 GNUNET_GETOPT_option_flag ('u',
336 GNUNET_GETOPT_OPTION_END 337 "udp",
337 }; 338 gettext_noop ("service is offered via UDP"),
339 &udp),
340
341 GNUNET_GETOPT_option_verbose (&verbosity),
342
343 GNUNET_GETOPT_OPTION_END};
338 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 344 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
339 return 2; 345 return 2;
340 346
341 ret = (GNUNET_OK == 347 ret =
342 GNUNET_PROGRAM_run (argc, argv, "gnunet-vpn", 348 (GNUNET_OK == GNUNET_PROGRAM_run (argc,
343 gettext_noop 349 argv,
344 ("Setup tunnels via VPN."), options, 350 "gnunet-vpn",
345 &run, NULL)) ? ret : 1; 351 gettext_noop ("Setup tunnels via VPN."),
352 options,
353 &run,
354 NULL))
355 ? ret
356 : 1;
346 GNUNET_free ((void *) argv); 357 GNUNET_free ((void *) argv);
347 return ret; 358 return ret;
348} 359}