aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
commit5746309cb4be2073d550ad7a6885e918631dbc38 (patch)
tree89455bc4aadf977816b38df13f990372cd81d71a
parent6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff)
downloadgnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz
gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip
indentation
-rw-r--r--src/arm/arm_api.c63
-rw-r--r--src/arm/gnunet-arm.c42
-rw-r--r--src/arm/gnunet-service-arm.c153
-rw-r--r--src/arm/gnunet-service-arm_interceptor.c155
-rw-r--r--src/arm/mockup-service.c15
-rw-r--r--src/arm/test_arm_api.c10
-rw-r--r--src/arm/test_exponential_backoff.c49
-rw-r--r--src/arm/test_gnunet_service_manager.c18
-rw-r--r--src/ats/ats_api.c103
-rw-r--r--src/block/block.c23
-rw-r--r--src/block/plugin_block_dht.c26
-rw-r--r--src/block/plugin_block_dns.c17
-rw-r--r--src/block/plugin_block_fs.c40
-rw-r--r--src/block/plugin_block_template.c16
-rw-r--r--src/block/plugin_block_test.c17
-rw-r--r--src/block/test_block.c20
-rw-r--r--src/chat/chat.c103
-rw-r--r--src/chat/gnunet-chat.c116
-rw-r--r--src/chat/gnunet-service-chat.c266
-rw-r--r--src/chat/test_chat.c107
-rw-r--r--src/chat/test_chat_private.c113
-rw-r--r--src/core/core_api.c109
-rw-r--r--src/core/core_api_iterate_peers.c36
-rw-r--r--src/core/gnunet-core-list-connections.c12
-rw-r--r--src/core/gnunet-service-core.c808
-rw-r--r--src/core/test_core_api.c82
-rw-r--r--src/core/test_core_api_preferences.c123
-rw-r--r--src/core/test_core_api_reliability.c92
-rw-r--r--src/core/test_core_api_send_to_self.c40
-rw-r--r--src/core/test_core_api_start_only.c48
-rw-r--r--src/core/test_core_quota_compliance.c183
-rw-r--r--src/datacache/datacache.c37
-rw-r--r--src/datacache/perf_datacache.c47
-rw-r--r--src/datacache/plugin_datacache_mysql.c247
-rw-r--r--src/datacache/plugin_datacache_postgres.c170
-rw-r--r--src/datacache/plugin_datacache_sqlite.c161
-rw-r--r--src/datacache/plugin_datacache_template.c14
-rw-r--r--src/datacache/test_datacache.c39
-rw-r--r--src/datacache/test_datacache_quota.c15
-rw-r--r--src/datastore/datastore_api.c191
-rw-r--r--src/datastore/gnunet-service-datastore.c299
-rw-r--r--src/datastore/perf_datastore_api.c83
-rw-r--r--src/datastore/perf_plugin_datastore.c89
-rw-r--r--src/datastore/plugin_datastore_mysql.c315
-rw-r--r--src/datastore/plugin_datastore_postgres.c376
-rw-r--r--src/datastore/plugin_datastore_sqlite.c429
-rw-r--r--src/datastore/plugin_datastore_template.c36
-rw-r--r--src/datastore/test_datastore_api.c280
-rw-r--r--src/datastore/test_datastore_api_management.c125
-rw-r--r--src/datastore/test_plugin_datastore.c63
-rw-r--r--src/dht/dht_api.c118
-rw-r--r--src/dht/dht_api_find_peer.c12
-rw-r--r--src/dht/dht_api_get_put.c43
-rw-r--r--src/dht/dhtlog.c8
-rw-r--r--src/dht/gnunet-dht-driver.c1029
-rw-r--r--src/dht/gnunet-dht-get-peer.c17
-rw-r--r--src/dht/gnunet-dht-get.c28
-rw-r--r--src/dht/gnunet-dht-put.c15
-rw-r--r--src/dht/gnunet-service-dht.c572
-rw-r--r--src/dht/plugin_dhtlog_dummy.c31
-rw-r--r--src/dht/plugin_dhtlog_mysql.c678
-rw-r--r--src/dht/plugin_dhtlog_mysql_dump.c107
-rw-r--r--src/dht/plugin_dhtlog_mysql_dump_load.c109
-rw-r--r--src/dht/test_dht_api.c53
-rw-r--r--src/dht/test_dht_multipeer.c96
-rw-r--r--src/dht/test_dht_twopeer.c90
-rw-r--r--src/dht/test_dht_twopeer_path_tracking.c74
-rw-r--r--src/dht/test_dht_twopeer_put_get.c103
-rw-r--r--src/dht/test_dhtlog.c9
-rw-r--r--src/dv/dv_api.c49
-rw-r--r--src/dv/gnunet-service-dv.c280
-rw-r--r--src/dv/plugin_transport_dv.c50
-rw-r--r--src/dv/test_transport_api_dv.c183
-rw-r--r--src/fragmentation/defragmentation.c30
-rw-r--r--src/fragmentation/fragmentation.c35
-rw-r--r--src/fragmentation/test_fragmentation.c12
-rw-r--r--src/fs/fs.c521
-rw-r--r--src/fs/fs_directory.c53
-rw-r--r--src/fs/fs_download.c370
-rw-r--r--src/fs/fs_file_information.c108
-rw-r--r--src/fs/fs_getopt.c15
-rw-r--r--src/fs/fs_list_indexed.c21
-rw-r--r--src/fs/fs_misc.c49
-rw-r--r--src/fs/fs_namespace.c163
-rw-r--r--src/fs/fs_publish.c297
-rw-r--r--src/fs/fs_search.c154
-rw-r--r--src/fs/fs_test_lib.c139
-rw-r--r--src/fs/fs_tree.c46
-rw-r--r--src/fs/fs_unindex.c57
-rw-r--r--src/fs/fs_uri.c111
-rw-r--r--src/fs/gnunet-directory.c46
-rw-r--r--src/fs/gnunet-download.c52
-rw-r--r--src/fs/gnunet-pseudonym.c38
-rw-r--r--src/fs/gnunet-publish.c121
-rw-r--r--src/fs/gnunet-search.c46
-rw-r--r--src/fs/gnunet-service-fs.c61
-rw-r--r--src/fs/gnunet-service-fs_cp.c220
-rw-r--r--src/fs/gnunet-service-fs_indexing.c129
-rw-r--r--src/fs/gnunet-service-fs_lc.c54
-rw-r--r--src/fs/gnunet-service-fs_pe.c75
-rw-r--r--src/fs/gnunet-service-fs_pr.c419
-rw-r--r--src/fs/gnunet-service-fs_push.c50
-rw-r--r--src/fs/gnunet-service-fs_put.c58
-rw-r--r--src/fs/gnunet-unindex.c29
-rw-r--r--src/fs/perf_gnunet_service_fs_p2p.c84
-rw-r--r--src/fs/perf_gnunet_service_fs_p2p_trust.c102
-rw-r--r--src/fs/test_fs.c25
-rw-r--r--src/fs/test_fs_directory.c30
-rw-r--r--src/fs/test_fs_download.c94
-rw-r--r--src/fs/test_fs_download_indexed.c100
-rw-r--r--src/fs/test_fs_download_persistence.c86
-rw-r--r--src/fs/test_fs_download_recursive.c38
-rw-r--r--src/fs/test_fs_file_information.c65
-rw-r--r--src/fs/test_fs_list_indexed.c103
-rw-r--r--src/fs/test_fs_namespace.c48
-rw-r--r--src/fs/test_fs_namespace_list_updateable.c45
-rw-r--r--src/fs/test_fs_publish.c90
-rw-r--r--src/fs/test_fs_publish_persistence.c96
-rw-r--r--src/fs/test_fs_search.c70
-rw-r--r--src/fs/test_fs_search_persistence.c74
-rw-r--r--src/fs/test_fs_search_ranking.c25
-rw-r--r--src/fs/test_fs_start_stop.c28
-rw-r--r--src/fs/test_fs_test_lib.c37
-rw-r--r--src/fs/test_fs_unindex.c77
-rw-r--r--src/fs/test_fs_unindex_persistence.c81
-rw-r--r--src/fs/test_fs_uri.c10
-rw-r--r--src/fs/test_gnunet_service_fs_migration.c38
-rw-r--r--src/fs/test_gnunet_service_fs_p2p.c39
-rw-r--r--src/hello/hello.c78
-rw-r--r--src/hello/test_hello.c44
-rw-r--r--src/hostlist/gnunet-daemon-hostlist.c48
-rw-r--r--src/hostlist/hostlist-client.c151
-rw-r--r--src/hostlist/hostlist-server.c125
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist.c34
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist_learning.c131
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist_reconnect.c34
-rw-r--r--src/mesh/gnunet-service-mesh.c307
-rw-r--r--src/mesh/mesh_api.c77
-rw-r--r--src/mesh/mesh_api_new.c67
-rw-r--r--src/mesh/test_mesh_api.c28
-rw-r--r--src/mesh/test_mesh_small.c169
-rw-r--r--src/nat/gnunet-helper-nat-client-windows.c61
-rw-r--r--src/nat/gnunet-helper-nat-client.c55
-rw-r--r--src/nat/gnunet-helper-nat-server-windows.c53
-rw-r--r--src/nat/gnunet-helper-nat-server.c55
-rw-r--r--src/nat/gnunet-nat-server.c45
-rw-r--r--src/nat/nat.c282
-rw-r--r--src/nat/nat_mini.c90
-rw-r--r--src/nat/nat_test.c95
-rw-r--r--src/nat/test_nat.c26
-rw-r--r--src/nat/test_nat_mini.c17
-rw-r--r--src/nat/test_nat_test.c24
-rw-r--r--src/nse/gnunet-nse-profiler.c208
-rw-r--r--src/nse/gnunet-service-nse.c181
-rw-r--r--src/nse/nse_api.c27
-rw-r--r--src/nse/test_nse_api.c25
-rw-r--r--src/nse/test_nse_multipeer.c52
-rw-r--r--src/peerinfo-tool/gnunet-peerinfo.c50
-rw-r--r--src/peerinfo/gnunet-service-peerinfo.c101
-rw-r--r--src/peerinfo/peerinfo_api.c46
-rw-r--r--src/peerinfo/peerinfo_api_notify.c21
-rwxr-xr-xsrc/peerinfo/perf_peerinfo_api.c50
-rw-r--r--src/peerinfo/test_peerinfo_api.c44
-rw-r--r--src/statistics/gnunet-service-statistics.c92
-rw-r--r--src/statistics/gnunet-statistics.c30
-rw-r--r--src/statistics/statistics_api.c109
-rw-r--r--src/statistics/test_statistics_api.c60
-rw-r--r--src/statistics/test_statistics_api_loop.c23
-rw-r--r--src/statistics/test_statistics_api_watch.c39
-rw-r--r--src/template/gnunet-service-template.c11
-rw-r--r--src/template/gnunet-template.c13
-rw-r--r--src/testing/test_testing.c12
-rw-r--r--src/testing/test_testing_connect.c32
-rw-r--r--src/testing/test_testing_group.c17
-rw-r--r--src/testing/test_testing_group_remote.c22
-rw-r--r--src/testing/test_testing_large_topology.c190
-rw-r--r--src/testing/test_testing_peergroup.c15
-rw-r--r--src/testing/test_testing_reconnect.c32
-rw-r--r--src/testing/test_testing_topology.c208
-rw-r--r--src/testing/test_testing_topology_blacklist.c90
-rw-r--r--src/testing/test_testing_topology_churn.c42
-rw-r--r--src/testing/testing.c484
-rw-r--r--src/testing/testing_group.c973
-rw-r--r--src/testing/testing_peergroup.c221
-rw-r--r--src/topology/gnunet-daemon-topology.c210
-rw-r--r--src/topology/test_gnunet_daemon_topology.c27
-rw-r--r--src/transport/gnunet-service-transport-new.c102
-rw-r--r--src/transport/gnunet-service-transport.c900
-rw-r--r--src/transport/gnunet-service-transport_ats.c176
-rw-r--r--src/transport/gnunet-service-transport_blacklist.c64
-rw-r--r--src/transport/gnunet-service-transport_clients.c117
-rw-r--r--src/transport/gnunet-service-transport_hello.c31
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c88
-rw-r--r--src/transport/gnunet-service-transport_plugins.c15
-rw-r--r--src/transport/gnunet-service-transport_validation.c147
-rw-r--r--src/transport/gnunet-transport-certificate-creation.c17
-rw-r--r--src/transport/gnunet-transport-list-connections.c12
-rw-r--r--src/transport/gnunet-transport-wlan-helper.c66
-rw-r--r--src/transport/perf_transport_ats.c7
-rw-r--r--src/transport/plugin_transport_http.c476
-rw-r--r--src/transport/plugin_transport_smtp.c151
-rw-r--r--src/transport/plugin_transport_tcp.c398
-rw-r--r--src/transport/plugin_transport_template.c20
-rw-r--r--src/transport/plugin_transport_udp.c216
-rw-r--r--src/transport/plugin_transport_unix.c103
-rw-r--r--src/transport/plugin_transport_wlan.c289
-rw-r--r--src/transport/test_plugin_transport.c42
-rw-r--r--src/transport/test_plugin_transport_http.c160
-rw-r--r--src/transport/test_plugin_transport_https.c67
-rw-r--r--src/transport/test_plugin_transport_udp.c39
-rw-r--r--src/transport/test_plugin_transport_wlan_dummy.c22
-rw-r--r--src/transport/test_quota_compliance.c88
-rw-r--r--src/transport/test_transport_api.c51
-rw-r--r--src/transport/test_transport_api_disconnect.c65
-rw-r--r--src/transport/test_transport_api_multiaddress.c47
-rw-r--r--src/transport/test_transport_api_reliability.c79
-rw-r--r--src/transport/test_transport_api_unreliability.c88
-rw-r--r--src/transport/test_transport_ats.c29
-rw-r--r--src/transport/test_transport_ats_multiple_peers.c158
-rw-r--r--src/transport/test_transport_testing.c26
-rw-r--r--src/transport/transport-testing.c51
-rw-r--r--src/transport/transport_api.c85
-rw-r--r--src/transport/transport_api_address_iterate.c9
-rw-r--r--src/transport/transport_api_address_lookup.c15
-rw-r--r--src/transport/transport_api_blacklist.c40
-rw-r--r--src/transport/transport_api_peer_address_lookup.c9
-rw-r--r--src/transport/wlan/radiotap-parser.c17
-rw-r--r--src/util/bandwidth.c45
-rw-r--r--src/util/bio.c50
-rw-r--r--src/util/client.c172
-rw-r--r--src/util/common_allocation.c4
-rw-r--r--src/util/common_logging.c22
-rw-r--r--src/util/configuration.c109
-rw-r--r--src/util/connection.c184
-rw-r--r--src/util/container_bloomfilter.c46
-rw-r--r--src/util/container_heap.c42
-rw-r--r--src/util/container_meta_data.c93
-rw-r--r--src/util/container_multihashmap.c19
-rw-r--r--src/util/container_slist.c9
-rw-r--r--src/util/crypto_aes.c34
-rw-r--r--src/util/crypto_hash.c35
-rw-r--r--src/util/crypto_hkdf.c28
-rw-r--r--src/util/crypto_kdf.c11
-rw-r--r--src/util/crypto_ksk.c46
-rw-r--r--src/util/crypto_random.c21
-rw-r--r--src/util/crypto_rsa.c153
-rw-r--r--src/util/disk.c102
-rw-r--r--src/util/getopt.c75
-rw-r--r--src/util/getopt_helpers.c15
-rw-r--r--src/util/gnunet-config-diff.c3
-rw-r--r--src/util/gnunet-resolver.c12
-rw-r--r--src/util/gnunet-service-resolver.c71
-rw-r--r--src/util/network.c27
-rw-r--r--src/util/os_installation.c10
-rw-r--r--src/util/os_network.c33
-rw-r--r--src/util/os_priority.c110
-rw-r--r--src/util/peer.c11
-rw-r--r--src/util/perf_crypto_hash.c8
-rw-r--r--src/util/plugin.c3
-rw-r--r--src/util/program.c15
-rw-r--r--src/util/pseudonym.c50
-rw-r--r--src/util/resolver_api.c80
-rw-r--r--src/util/scheduler.c149
-rw-r--r--src/util/server.c77
-rw-r--r--src/util/server_mst.c5
-rw-r--r--src/util/server_nc.c37
-rw-r--r--src/util/server_tc.c14
-rw-r--r--src/util/service.c257
-rw-r--r--src/util/strings.c7
-rw-r--r--src/util/test_client.c22
-rw-r--r--src/util/test_common_endian.c4
-rw-r--r--src/util/test_common_logging.c4
-rw-r--r--src/util/test_configuration.c70
-rw-r--r--src/util/test_connection.c25
-rw-r--r--src/util/test_connection_addressing.c34
-rw-r--r--src/util/test_connection_receive_cancel.c19
-rw-r--r--src/util/test_connection_timeout.c10
-rw-r--r--src/util/test_connection_timeout_no_connect.c7
-rw-r--r--src/util/test_connection_transmit_cancel.c7
-rw-r--r--src/util/test_container_bloomfilter.c4
-rw-r--r--src/util/test_container_heap.c3
-rw-r--r--src/util/test_container_meta_data.c93
-rw-r--r--src/util/test_container_multihashmap.c35
-rw-r--r--src/util/test_container_slist.c9
-rw-r--r--src/util/test_crypto_aes.c33
-rw-r--r--src/util/test_crypto_aes_weak.c15
-rw-r--r--src/util/test_crypto_hkdf.c8
-rw-r--r--src/util/test_crypto_ksk.c43
-rw-r--r--src/util/test_crypto_rsa.c77
-rw-r--r--src/util/test_disk.c30
-rw-r--r--src/util/test_os_network.c11
-rw-r--r--src/util/test_os_start_process.c5
-rw-r--r--src/util/test_program.c29
-rw-r--r--src/util/test_pseudonym.c45
-rw-r--r--src/util/test_resolver_api.c37
-rw-r--r--src/util/test_scheduler.c20
-rw-r--r--src/util/test_scheduler_delay.c8
-rw-r--r--src/util/test_server.c10
-rw-r--r--src/util/test_server_disconnect.c3
-rw-r--r--src/util/test_server_with_client.c17
-rw-r--r--src/util/test_server_with_client_unix.c17
-rw-r--r--src/util/test_service.c52
-rw-r--r--src/util/test_time.c7
-rw-r--r--src/util/time.c29
-rw-r--r--src/util/winproc.c105
-rw-r--r--src/vpn/gnunet-daemon-exit.c121
-rw-r--r--src/vpn/gnunet-daemon-vpn-dns.c8
-rw-r--r--src/vpn/gnunet-daemon-vpn-helper.c109
-rw-r--r--src/vpn/gnunet-daemon-vpn.c59
-rw-r--r--src/vpn/gnunet-dns-parser.c4
-rw-r--r--src/vpn/gnunet-helper-vpn-api.c19
-rw-r--r--src/vpn/gnunet-helper-vpn.c49
-rw-r--r--src/vpn/gnunet-service-dns.c174
313 files changed, 12717 insertions, 16341 deletions
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c
index 0db9e5c3e..cc75e46da 100644
--- a/src/arm/arm_api.c
+++ b/src/arm/arm_api.c
@@ -141,8 +141,7 @@ service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg)
141 "Received confirmation for service shutdown.\n"); 141 "Received confirmation for service shutdown.\n");
142#endif 142#endif
143 shutdown_ctx->confirmed = GNUNET_YES; 143 shutdown_ctx->confirmed = GNUNET_YES;
144 GNUNET_CLIENT_receive (shutdown_ctx->sock, 144 GNUNET_CLIENT_receive (shutdown_ctx->sock, &service_shutdown_handler,
145 &service_shutdown_handler,
146 shutdown_ctx, GNUNET_TIME_UNIT_FOREVER_REL); 145 shutdown_ctx, GNUNET_TIME_UNIT_FOREVER_REL);
147 break; 146 break;
148 default: /* Fall through */ 147 default: /* Fall through */
@@ -206,9 +205,8 @@ write_shutdown (void *cls, size_t size, void *buf)
206 return 0; /* client disconnected */ 205 return 0; /* client disconnected */
207 } 206 }
208 207
209 GNUNET_CLIENT_receive (shutdown_ctx->sock, 208 GNUNET_CLIENT_receive (shutdown_ctx->sock, &service_shutdown_handler,
210 &service_shutdown_handler, shutdown_ctx, 209 shutdown_ctx, GNUNET_TIME_UNIT_FOREVER_REL);
211 GNUNET_TIME_UNIT_FOREVER_REL);
212 shutdown_ctx->cancel_task = 210 shutdown_ctx->cancel_task =
213 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining 211 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
214 (shutdown_ctx->timeout), 212 (shutdown_ctx->timeout),
@@ -246,11 +244,9 @@ arm_service_shutdown (struct GNUNET_CLIENT_Connection *sock,
246 shutdown_ctx->sock = sock; 244 shutdown_ctx->sock = sock;
247 shutdown_ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout); 245 shutdown_ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
248 GNUNET_CLIENT_notify_transmit_ready (sock, 246 GNUNET_CLIENT_notify_transmit_ready (sock,
249 sizeof (struct 247 sizeof (struct GNUNET_MessageHeader),
250 GNUNET_MessageHeader), 248 timeout, GNUNET_YES, &write_shutdown,
251 timeout, 249 shutdown_ctx);
252 GNUNET_YES,
253 &write_shutdown, shutdown_ctx);
254} 250}
255 251
256 252
@@ -378,16 +374,16 @@ arm_service_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
378 "gnunet-service-arm"); 374 "gnunet-service-arm");
379#endif 375#endif
380 if (GNUNET_OK != 376 if (GNUNET_OK !=
381 GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, 377 GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, "arm", "PREFIX",
382 "arm", "PREFIX", &loprefix)) 378 &loprefix))
383 loprefix = GNUNET_strdup (""); 379 loprefix = GNUNET_strdup ("");
384 if (GNUNET_OK != 380 if (GNUNET_OK !=
385 GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, 381 GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, "arm", "OPTIONS",
386 "arm", "OPTIONS", &lopostfix)) 382 &lopostfix))
387 lopostfix = GNUNET_strdup (""); 383 lopostfix = GNUNET_strdup ("");
388 if (GNUNET_OK != 384 if (GNUNET_OK !=
389 GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, 385 GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, "arm", "BINARY",
390 "arm", "BINARY", &binary)) 386 &binary))
391 { 387 {
392 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 388 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
393 _ 389 _
@@ -401,8 +397,8 @@ arm_service_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
401 return; 397 return;
402 } 398 }
403 if (GNUNET_OK != 399 if (GNUNET_OK !=
404 GNUNET_CONFIGURATION_get_value_filename (pos->h->cfg, 400 GNUNET_CONFIGURATION_get_value_filename (pos->h->cfg, "arm", "CONFIG",
405 "arm", "CONFIG", &config)) 401 &config))
406 { 402 {
407 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 403 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
408 _ 404 _
@@ -519,10 +515,9 @@ handle_response (void *cls, const struct GNUNET_MessageHeader *msg)
519 * @param type type of the request 515 * @param type type of the request
520 */ 516 */
521static void 517static void
522change_service (struct GNUNET_ARM_Handle *h, 518change_service (struct GNUNET_ARM_Handle *h, const char *service_name,
523 const char *service_name, 519 struct GNUNET_TIME_Relative timeout, GNUNET_ARM_Callback cb,
524 struct GNUNET_TIME_Relative timeout, 520 void *cb_cls, uint16_t type)
525 GNUNET_ARM_Callback cb, void *cb_cls, uint16_t type)
526{ 521{
527 struct RequestContext *sctx; 522 struct RequestContext *sctx;
528 size_t slen; 523 size_t slen;
@@ -539,9 +534,10 @@ change_service (struct GNUNET_ARM_Handle *h,
539 } 534 }
540#if DEBUG_ARM 535#if DEBUG_ARM
541 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 536 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
542 (type == GNUNET_MESSAGE_TYPE_ARM_START) 537 (type ==
543 ? _("Requesting start of service `%s'.\n") 538 GNUNET_MESSAGE_TYPE_ARM_START) ?
544 : _("Requesting termination of service `%s'.\n"), service_name); 539 _("Requesting start of service `%s'.\n") :
540 _("Requesting termination of service `%s'.\n"), service_name);
545#endif 541#endif
546 sctx = GNUNET_malloc (sizeof (struct RequestContext) + slen); 542 sctx = GNUNET_malloc (sizeof (struct RequestContext) + slen);
547 sctx->h = h; 543 sctx->h = h;
@@ -555,15 +551,14 @@ change_service (struct GNUNET_ARM_Handle *h,
555 msg->type = htons (sctx->type); 551 msg->type = htons (sctx->type);
556 memcpy (&msg[1], service_name, slen); 552 memcpy (&msg[1], service_name, slen);
557 if (GNUNET_OK != 553 if (GNUNET_OK !=
558 GNUNET_CLIENT_transmit_and_get_response (sctx->h->client, 554 GNUNET_CLIENT_transmit_and_get_response (sctx->h->client, msg,
559 msg,
560 GNUNET_TIME_absolute_get_remaining 555 GNUNET_TIME_absolute_get_remaining
561 (sctx->timeout), GNUNET_YES, 556 (sctx->timeout), GNUNET_YES,
562 &handle_response, sctx)) 557 &handle_response, sctx))
563 { 558 {
564 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 559 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
565 (type == GNUNET_MESSAGE_TYPE_ARM_START) 560 (type ==
566 ? 561 GNUNET_MESSAGE_TYPE_ARM_START) ?
567 _ 562 _
568 ("Error while trying to transmit request to start `%s' to ARM\n") 563 ("Error while trying to transmit request to start `%s' to ARM\n")
569 : 564 :
@@ -590,8 +585,7 @@ change_service (struct GNUNET_ARM_Handle *h,
590 * @param cb_cls closure for callback 585 * @param cb_cls closure for callback
591 */ 586 */
592void 587void
593GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h, 588GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h, const char *service_name,
594 const char *service_name,
595 struct GNUNET_TIME_Relative timeout, 589 struct GNUNET_TIME_Relative timeout,
596 GNUNET_ARM_Callback cb, void *cb_cls) 590 GNUNET_ARM_Callback cb, void *cb_cls)
597{ 591{
@@ -616,8 +610,8 @@ GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h,
616 sctx->cls = cb_cls; 610 sctx->cls = cb_cls;
617 sctx->timeout = GNUNET_TIME_relative_to_absolute (timeout); 611 sctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
618 memcpy (&sctx[1], service_name, slen); 612 memcpy (&sctx[1], service_name, slen);
619 GNUNET_CLIENT_service_test ("arm", 613 GNUNET_CLIENT_service_test ("arm", h->cfg, timeout, &arm_service_report,
620 h->cfg, timeout, &arm_service_report, sctx); 614 sctx);
621 return; 615 return;
622 } 616 }
623 if (h->client == NULL) 617 if (h->client == NULL)
@@ -670,8 +664,7 @@ arm_shutdown_callback (void *cls, int reason)
670 * @param cb_cls closure for callback 664 * @param cb_cls closure for callback
671 */ 665 */
672void 666void
673GNUNET_ARM_stop_service (struct GNUNET_ARM_Handle *h, 667GNUNET_ARM_stop_service (struct GNUNET_ARM_Handle *h, const char *service_name,
674 const char *service_name,
675 struct GNUNET_TIME_Relative timeout, 668 struct GNUNET_TIME_Relative timeout,
676 GNUNET_ARM_Callback cb, void *cb_cls) 669 GNUNET_ARM_Callback cb, void *cb_cls)
677{ 670{
diff --git a/src/arm/gnunet-arm.c b/src/arm/gnunet-arm.c
index f7ff536be..cf5e1592a 100644
--- a/src/arm/gnunet-arm.c
+++ b/src/arm/gnunet-arm.c
@@ -177,14 +177,14 @@ confirm_cb (void *cls, int success)
177 break; 177 break;
178 case GNUNET_SYSERR: 178 case GNUNET_SYSERR:
179 if (quiet != GNUNET_YES) 179 if (quiet != GNUNET_YES)
180 fprintf (stdout, 180 fprintf (stdout, _("Some error communicating with service `%s'.\n"),
181 _("Some error communicating with service `%s'.\n"), service); 181 service);
182 ret = 1; 182 ret = 1;
183 break; 183 break;
184 } 184 }
185 185
186 GNUNET_SCHEDULER_add_continuation (&cps_loop, 186 GNUNET_SCHEDULER_add_continuation (&cps_loop, NULL,
187 NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 187 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
188} 188}
189 189
190 190
@@ -210,8 +210,8 @@ confirm_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
210 if (quiet != GNUNET_YES) 210 if (quiet != GNUNET_YES)
211 fprintf (stdout, _("Service `%s' is not running.\n"), service); 211 fprintf (stdout, _("Service `%s' is not running.\n"), service);
212 } 212 }
213 GNUNET_SCHEDULER_add_continuation (&cps_loop, 213 GNUNET_SCHEDULER_add_continuation (&cps_loop, NULL,
214 NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 214 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
215} 215}
216 216
217 217
@@ -224,9 +224,8 @@ confirm_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
224 * @param c configuration 224 * @param c configuration
225 */ 225 */
226static void 226static void
227run (void *cls, 227run (void *cls, char *const *args, const char *cfgfile,
228 char *const *args, 228 const struct GNUNET_CONFIGURATION_Handle *c)
229 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
230{ 229{
231 cfg = c; 230 cfg = c;
232 config_file = cfgfile; 231 config_file = cfgfile;
@@ -247,8 +246,8 @@ run (void *cls,
247 ret = 1; 246 ret = 1;
248 return; 247 return;
249 } 248 }
250 GNUNET_SCHEDULER_add_continuation (&cps_loop, 249 GNUNET_SCHEDULER_add_continuation (&cps_loop, NULL,
251 NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 250 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
252} 251}
253 252
254/** 253/**
@@ -306,8 +305,9 @@ cps_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
306 { 305 {
307 GNUNET_ARM_stop_service (h, "arm", 306 GNUNET_ARM_stop_service (h, "arm",
308 (0 == 307 (0 ==
309 timeout.rel_value) ? STOP_TIMEOUT_ARM : 308 timeout.
310 timeout, &confirm_cb, "arm"); 309 rel_value) ? STOP_TIMEOUT_ARM : timeout,
310 &confirm_cb, "arm");
311 return; 311 return;
312 } 312 }
313 break; 313 break;
@@ -336,8 +336,9 @@ cps_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
336 { 336 {
337 GNUNET_CLIENT_service_test (test, cfg, 337 GNUNET_CLIENT_service_test (test, cfg,
338 (0 == 338 (0 ==
339 timeout.rel_value) ? TEST_TIMEOUT : 339 timeout.
340 timeout, &confirm_task, test); 340 rel_value) ? TEST_TIMEOUT : timeout,
341 &confirm_task, test);
341 return; 342 return;
342 } 343 }
343 break; 344 break;
@@ -412,12 +413,11 @@ main (int argc, char *const *argv)
412 if (temp_timeout_ms > 0) 413 if (temp_timeout_ms > 0)
413 timeout.rel_value = temp_timeout_ms; 414 timeout.rel_value = temp_timeout_ms;
414 415
415 if (GNUNET_OK == GNUNET_PROGRAM_run (argc, 416 if (GNUNET_OK ==
416 argv, 417 GNUNET_PROGRAM_run (argc, argv, "gnunet-arm",
417 "gnunet-arm", 418 gettext_noop
418 gettext_noop 419 ("Control services and the Automated Restart Manager (ARM)"),
419 ("Control services and the Automated Restart Manager (ARM)"), 420 options, &run, NULL))
420 options, &run, NULL))
421 { 421 {
422 return ret; 422 return ret;
423 } 423 }
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c
index e4a8e7c6c..ddccb7fa0 100644
--- a/src/arm/gnunet-service-arm.c
+++ b/src/arm/gnunet-service-arm.c
@@ -198,8 +198,8 @@ config_change_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
198 while (pos != NULL) 198 while (pos != NULL)
199 { 199 {
200 /* FIXME: this test for config change may be a bit too coarse grained */ 200 /* FIXME: this test for config change may be a bit too coarse grained */
201 if ((0 == STAT (pos->config, &sbuf)) && 201 if ((0 == STAT (pos->config, &sbuf)) && (pos->mtime < sbuf.st_mtime) &&
202 (pos->mtime < sbuf.st_mtime) && (pos->proc != NULL)) 202 (pos->proc != NULL))
203 { 203 {
204 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 204 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
205 _ 205 _
@@ -235,8 +235,8 @@ write_result (void *cls, size_t size, void *buf)
235 return 0; /* error, not much we can do */ 235 return 0; /* error, not much we can do */
236 } 236 }
237#if DEBUG_ARM 237#if DEBUG_ARM
238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending status response %u to client\n",
239 "Sending status response %u to client\n", (unsigned int) *res); 239 (unsigned int) *res);
240#endif 240#endif
241 GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); 241 GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
242 msg = buf; 242 msg = buf;
@@ -257,8 +257,8 @@ write_result (void *cls, size_t size, void *buf)
257 * @return NULL if it was not found 257 * @return NULL if it was not found
258 */ 258 */
259static void 259static void
260signal_result (struct GNUNET_SERVER_Client *client, 260signal_result (struct GNUNET_SERVER_Client *client, const char *name,
261 const char *name, uint16_t result) 261 uint16_t result)
262{ 262{
263 uint16_t *res; 263 uint16_t *res;
264 264
@@ -270,8 +270,8 @@ signal_result (struct GNUNET_SERVER_Client *client,
270 } 270 }
271#if DEBUG_ARM 271#if DEBUG_ARM
272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
273 "Telling client that service `%s' is now %s\n", 273 "Telling client that service `%s' is now %s\n", name,
274 name, result == GNUNET_MESSAGE_TYPE_ARM_IS_DOWN ? "down" : "up"); 274 result == GNUNET_MESSAGE_TYPE_ARM_IS_DOWN ? "down" : "up");
275#endif 275#endif
276 res = GNUNET_malloc (sizeof (uint16_t)); 276 res = GNUNET_malloc (sizeof (uint16_t));
277 *res = result; 277 *res = result;
@@ -344,12 +344,12 @@ start_process (struct ServiceList *sl, const int *lsocks)
344 344
345 /* start service */ 345 /* start service */
346 if (GNUNET_OK != 346 if (GNUNET_OK !=
347 GNUNET_CONFIGURATION_get_value_string (cfg, 347 GNUNET_CONFIGURATION_get_value_string (cfg, sl->name, "PREFIX",
348 sl->name, "PREFIX", &loprefix)) 348 &loprefix))
349 loprefix = GNUNET_strdup (prefix_command); 349 loprefix = GNUNET_strdup (prefix_command);
350 if (GNUNET_OK != 350 if (GNUNET_OK !=
351 GNUNET_CONFIGURATION_get_value_string (cfg, 351 GNUNET_CONFIGURATION_get_value_string (cfg, sl->name, "OPTIONS",
352 sl->name, "OPTIONS", &options)) 352 &options))
353 { 353 {
354 options = GNUNET_strdup (final_option); 354 options = GNUNET_strdup (final_option);
355 if (NULL == strstr (options, "%")) 355 if (NULL == strstr (options, "%"))
@@ -376,8 +376,8 @@ start_process (struct ServiceList *sl, const int *lsocks)
376 next = optend + 1; 376 next = optend + 1;
377 *optend = '\0'; 377 *optend = '\0';
378 if (GNUNET_OK != 378 if (GNUNET_OK !=
379 GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", 379 GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", optpos + 1,
380 optpos + 1, &val)) 380 &val))
381 val = GNUNET_strdup (""); 381 val = GNUNET_strdup ("");
382 *optpos = '\0'; 382 *optpos = '\0';
383 GNUNET_asprintf (&optpos, "%s%s%c%s", options, val, b, next); 383 GNUNET_asprintf (&optpos, "%s%s%c%s", options, val, b, next);
@@ -395,18 +395,16 @@ start_process (struct ServiceList *sl, const int *lsocks)
395 sl->name, sl->binary, sl->config); 395 sl->name, sl->binary, sl->config);
396#endif 396#endif
397 if (GNUNET_YES == use_debug) 397 if (GNUNET_YES == use_debug)
398 sl->proc = do_start_process (lsocks, 398 sl->proc =
399 loprefix, 399 do_start_process (lsocks, loprefix, sl->binary, "-c", sl->config, "-L",
400 sl->binary, 400 "DEBUG", options, NULL);
401 "-c", sl->config,
402 "-L", "DEBUG", options, NULL);
403 else 401 else
404 sl->proc = do_start_process (lsocks, 402 sl->proc =
405 loprefix, 403 do_start_process (lsocks, loprefix, sl->binary, "-c", sl->config,
406 sl->binary, "-c", sl->config, options, NULL); 404 options, NULL);
407 if (sl->proc == NULL) 405 if (sl->proc == NULL)
408 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 406 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to start service `%s'\n"),
409 _("Failed to start service `%s'\n"), sl->name); 407 sl->name);
410 else 408 else
411 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Starting service `%s'\n"), sl->name); 409 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Starting service `%s'\n"), sl->name);
412 GNUNET_free (loprefix); 410 GNUNET_free (loprefix);
@@ -423,8 +421,8 @@ start_process (struct ServiceList *sl, const int *lsocks)
423 * @return GNUNET_OK on success, GNUNET_SYSERR on error 421 * @return GNUNET_OK on success, GNUNET_SYSERR on error
424 */ 422 */
425int 423int
426start_service (struct GNUNET_SERVER_Client *client, 424start_service (struct GNUNET_SERVER_Client *client, const char *servicename,
427 const char *servicename, const int *lsocks) 425 const int *lsocks)
428{ 426{
429 struct ServiceList *sl; 427 struct ServiceList *sl;
430 char *binary; 428 char *binary;
@@ -442,14 +440,14 @@ start_service (struct GNUNET_SERVER_Client *client,
442 sl = find_service (servicename); 440 sl = find_service (servicename);
443 if (sl != NULL) 441 if (sl != NULL)
444 { 442 {
445 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Service `%s' already running.\n"),
446 _("Service `%s' already running.\n"), servicename); 444 servicename);
447 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UP); 445 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UP);
448 return GNUNET_SYSERR; 446 return GNUNET_SYSERR;
449 } 447 }
450 if (GNUNET_OK != 448 if (GNUNET_OK !=
451 GNUNET_CONFIGURATION_get_value_string (cfg, 449 GNUNET_CONFIGURATION_get_value_string (cfg, servicename, "BINARY",
452 servicename, "BINARY", &binary)) 450 &binary))
453 { 451 {
454 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 452 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
455 _("Binary implementing service `%s' not known!\n"), 453 _("Binary implementing service `%s' not known!\n"),
@@ -458,9 +456,7 @@ start_service (struct GNUNET_SERVER_Client *client,
458 return GNUNET_SYSERR; 456 return GNUNET_SYSERR;
459 } 457 }
460 if ((GNUNET_OK != 458 if ((GNUNET_OK !=
461 GNUNET_CONFIGURATION_get_value_filename (cfg, 459 GNUNET_CONFIGURATION_get_value_filename (cfg, servicename, "CONFIG",
462 servicename,
463 "CONFIG",
464 &config)) || 460 &config)) ||
465 (0 != STAT (config, &sbuf))) 461 (0 != STAT (config, &sbuf)))
466 { 462 {
@@ -499,8 +495,8 @@ stop_service (struct GNUNET_SERVER_Client *client, const char *servicename)
499{ 495{
500 struct ServiceList *pos; 496 struct ServiceList *pos;
501 497
502 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 498 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Preparing to stop `%s'\n"),
503 _("Preparing to stop `%s'\n"), servicename); 499 servicename);
504 pos = find_service (servicename); 500 pos = find_service (servicename);
505 if (pos == NULL) 501 if (pos == NULL)
506 { 502 {
@@ -515,8 +511,8 @@ stop_service (struct GNUNET_SERVER_Client *client, const char *servicename)
515 { 511 {
516 /* killing already in progress */ 512 /* killing already in progress */
517#if DEBUG_ARM 513#if DEBUG_ARM
518 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 514 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service `%s' is already down\n",
519 "Service `%s' is already down\n", servicename); 515 servicename);
520#endif 516#endif
521 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); 517 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
522 GNUNET_SERVER_receive_done (client, GNUNET_OK); 518 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -564,8 +560,7 @@ stop_service (struct GNUNET_SERVER_Client *client, const char *servicename)
564 * GNUNET_SYSERR to close it (signal serious error) 560 * GNUNET_SYSERR to close it (signal serious error)
565 */ 561 */
566static void 562static void
567handle_start (void *cls, 563handle_start (void *cls, struct GNUNET_SERVER_Client *client,
568 struct GNUNET_SERVER_Client *client,
569 const struct GNUNET_MessageHeader *message) 564 const struct GNUNET_MessageHeader *message)
570{ 565{
571 const char *servicename; 566 const char *servicename;
@@ -595,8 +590,7 @@ handle_start (void *cls,
595 * GNUNET_SYSERR to close it (signal serious error) 590 * GNUNET_SYSERR to close it (signal serious error)
596 */ 591 */
597static void 592static void
598handle_stop (void *cls, 593handle_stop (void *cls, struct GNUNET_SERVER_Client *client,
599 struct GNUNET_SERVER_Client *client,
600 const struct GNUNET_MessageHeader *message) 594 const struct GNUNET_MessageHeader *message)
601{ 595{
602 const char *servicename; 596 const char *servicename;
@@ -720,16 +714,16 @@ delayed_restart_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
720 { 714 {
721 if (GNUNET_TIME_absolute_get_remaining (pos->restartAt).rel_value == 0) 715 if (GNUNET_TIME_absolute_get_remaining (pos->restartAt).rel_value == 0)
722 { 716 {
723 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 717 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Restarting service `%s'.\n"),
724 _("Restarting service `%s'.\n"), pos->name); 718 pos->name);
725 start_process (pos, NULL); 719 start_process (pos, NULL);
726 } 720 }
727 else 721 else
728 { 722 {
729 lowestRestartDelay 723 lowestRestartDelay =
730 = GNUNET_TIME_relative_min (lowestRestartDelay, 724 GNUNET_TIME_relative_min (lowestRestartDelay,
731 GNUNET_TIME_absolute_get_remaining 725 GNUNET_TIME_absolute_get_remaining (pos->
732 (pos->restartAt)); 726 restartAt));
733 } 727 }
734 } 728 }
735 pos = pos->next; 729 pos = pos->next;
@@ -737,13 +731,12 @@ delayed_restart_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
737 if (lowestRestartDelay.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value) 731 if (lowestRestartDelay.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
738 { 732 {
739#if DEBUG_ARM 733#if DEBUG_ARM
740 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 734 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Will restart process in %llums\n",
741 "Will restart process in %llums\n",
742 (unsigned long long) lowestRestartDelay.rel_value); 735 (unsigned long long) lowestRestartDelay.rel_value);
743#endif 736#endif
744 child_restart_task 737 child_restart_task =
745 = GNUNET_SCHEDULER_add_delayed (lowestRestartDelay, 738 GNUNET_SCHEDULER_add_delayed (lowestRestartDelay, &delayed_restart_task,
746 &delayed_restart_task, NULL); 739 NULL);
747 } 740 }
748} 741}
749 742
@@ -786,12 +779,10 @@ maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
786 next = pos->next; 779 next = pos->next;
787 if (pos->proc == NULL) 780 if (pos->proc == NULL)
788 continue; 781 continue;
789 if ((GNUNET_SYSERR == (ret = GNUNET_OS_process_status (pos->proc, 782 if ((GNUNET_SYSERR ==
790 &statusType, 783 (ret = GNUNET_OS_process_status (pos->proc, &statusType, &statusCode)))
791 &statusCode))) || 784 || ((ret == GNUNET_NO) || (statusType == GNUNET_OS_PROCESS_STOPPED) ||
792 ((ret == GNUNET_NO) || 785 (statusType == GNUNET_OS_PROCESS_RUNNING)))
793 (statusType == GNUNET_OS_PROCESS_STOPPED) ||
794 (statusType == GNUNET_OS_PROCESS_RUNNING)))
795 continue; 786 continue;
796 787
797 if (statusType == GNUNET_OS_PROCESS_EXITED) 788 if (statusType == GNUNET_OS_PROCESS_EXITED)
@@ -813,10 +804,10 @@ maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
813 pos->proc = NULL; 804 pos->proc = NULL;
814 if (NULL != pos->killing_client) 805 if (NULL != pos->killing_client)
815 { 806 {
816 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 807 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Service `%s' stopped\n"),
817 _("Service `%s' stopped\n"), pos->name); 808 pos->name);
818 signal_result (pos->killing_client, 809 signal_result (pos->killing_client, pos->name,
819 pos->name, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); 810 GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
820 GNUNET_SERVER_receive_done (pos->killing_client, GNUNET_OK); 811 GNUNET_SERVER_receive_done (pos->killing_client, GNUNET_OK);
821 GNUNET_SERVER_client_drop (pos->killing_client); 812 GNUNET_SERVER_client_drop (pos->killing_client);
822 free_service (pos); 813 free_service (pos);
@@ -835,15 +826,15 @@ maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
835 pos->backoff = GNUNET_TIME_relative_multiply (pos->backoff, 2); 826 pos->backoff = GNUNET_TIME_relative_multiply (pos->backoff, 2);
836 if (GNUNET_SCHEDULER_NO_TASK != child_restart_task) 827 if (GNUNET_SCHEDULER_NO_TASK != child_restart_task)
837 GNUNET_SCHEDULER_cancel (child_restart_task); 828 GNUNET_SCHEDULER_cancel (child_restart_task);
838 child_restart_task 829 child_restart_task =
839 = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, 830 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
840 &delayed_restart_task, NULL); 831 &delayed_restart_task, NULL);
841 } 832 }
842#if DEBUG_ARM 833#if DEBUG_ARM
843 else 834 else
844 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 835 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
845 "Service `%s' terminated with status %s/%d\n", 836 "Service `%s' terminated with status %s/%d\n", pos->name,
846 pos->name, statstr, statcode); 837 statstr, statcode);
847#endif 838#endif
848 } 839 }
849 child_death_task = 840 child_death_task =
@@ -893,8 +884,7 @@ transmit_shutdown_ack (void *cls, size_t size, void *buf)
893 * @param message the actual message 884 * @param message the actual message
894 */ 885 */
895static void 886static void
896handle_shutdown (void *cls, 887handle_shutdown (void *cls, struct GNUNET_SERVER_Client *client,
897 struct GNUNET_SERVER_Client *client,
898 const struct GNUNET_MessageHeader *message) 888 const struct GNUNET_MessageHeader *message)
899{ 889{
900 GNUNET_SERVER_client_keep (client); 890 GNUNET_SERVER_client_keep (client);
@@ -935,8 +925,7 @@ sighandler_child_death ()
935 * @param c configuration to use 925 * @param c configuration to use
936 */ 926 */
937static void 927static void
938run (void *cls, 928run (void *cls, struct GNUNET_SERVER_Handle *serv,
939 struct GNUNET_SERVER_Handle *serv,
940 const struct GNUNET_CONFIGURATION_Handle *c) 929 const struct GNUNET_CONFIGURATION_Handle *c)
941{ 930{
942 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 931 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
@@ -955,32 +944,28 @@ run (void *cls,
955 pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ); 944 pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
956 GNUNET_assert (pr != NULL); 945 GNUNET_assert (pr != NULL);
957 GNUNET_SERVER_ignore_shutdown (serv, GNUNET_YES); 946 GNUNET_SERVER_ignore_shutdown (serv, GNUNET_YES);
958 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 947 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
959 &shutdown_task, NULL); 948 NULL);
960 child_death_task = 949 child_death_task =
961 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr, 950 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr,
962 &maint_child_death, NULL); 951 &maint_child_death, NULL);
963 952
964 if (GNUNET_OK != 953 if (GNUNET_OK !=
965 GNUNET_CONFIGURATION_get_value_string (cfg, 954 GNUNET_CONFIGURATION_get_value_string (cfg, "ARM", "GLOBAL_PREFIX",
966 "ARM", 955 &prefix_command))
967 "GLOBAL_PREFIX", &prefix_command))
968 prefix_command = GNUNET_strdup (""); 956 prefix_command = GNUNET_strdup ("");
969 if (GNUNET_OK != 957 if (GNUNET_OK !=
970 GNUNET_CONFIGURATION_get_value_string (cfg, 958 GNUNET_CONFIGURATION_get_value_string (cfg, "ARM", "GLOBAL_POSTFIX",
971 "ARM", 959 &final_option))
972 "GLOBAL_POSTFIX", &final_option))
973 final_option = GNUNET_strdup (""); 960 final_option = GNUNET_strdup ("");
974 /* start default services... */ 961 /* start default services... */
975 if (GNUNET_OK == 962 if (GNUNET_OK ==
976 GNUNET_CONFIGURATION_get_value_string (cfg, 963 GNUNET_CONFIGURATION_get_value_string (cfg, "ARM", "DEFAULTSERVICES",
977 "ARM",
978 "DEFAULTSERVICES",
979 &defaultservices)) 964 &defaultservices))
980 { 965 {
981#if DEBUG_ARM 966#if DEBUG_ARM
982 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 967 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting default services `%s'\n",
983 "Starting default services `%s'\n", defaultservices); 968 defaultservices);
984#endif 969#endif
985 if (0 < strlen (defaultservices)) 970 if (0 < strlen (defaultservices))
986 { 971 {
diff --git a/src/arm/gnunet-service-arm_interceptor.c b/src/arm/gnunet-service-arm_interceptor.c
index b99b076da..6d417ba37 100644
--- a/src/arm/gnunet-service-arm_interceptor.c
+++ b/src/arm/gnunet-service-arm_interceptor.c
@@ -356,8 +356,8 @@ closeClientAndServiceSockets (struct ForwardedConnection *fc, int reason)
356 * @param cls callback data, struct ForwardedConnection for the communication between client and service 356 * @param cls callback data, struct ForwardedConnection for the communication between client and service
357 * @param tc context 357 * @param tc context
358 */ 358 */
359static void 359static void receiveFromClient (void *cls,
360receiveFromClient (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 360 const struct GNUNET_SCHEDULER_TaskContext *tc);
361 361
362 362
363/** 363/**
@@ -366,15 +366,15 @@ receiveFromClient (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
366 * @param cls callback data, struct ForwardedConnection for the communication between client and service 366 * @param cls callback data, struct ForwardedConnection for the communication between client and service
367 * @param tc scheduler context 367 * @param tc scheduler context
368 */ 368 */
369static void 369static void receiveFromService (void *cls,
370receiveFromService (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 370 const struct GNUNET_SCHEDULER_TaskContext *tc);
371 371
372 372
373/** 373/**
374 * 374 *
375 */ 375 */
376static void 376static void start_forwarding (void *cls,
377start_forwarding (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 377 const struct GNUNET_SCHEDULER_TaskContext *tc);
378 378
379 379
380 380
@@ -391,13 +391,13 @@ forwardToClient (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
391 ssize_t numberOfBytesSent; 391 ssize_t numberOfBytesSent;
392 392
393 fc->service_to_client_task = GNUNET_SCHEDULER_NO_TASK; 393 fc->service_to_client_task = GNUNET_SCHEDULER_NO_TASK;
394 if (GNUNET_YES != GNUNET_NETWORK_fdset_isset (tc->write_ready, 394 if (GNUNET_YES !=
395 fc->armClientSocket)) 395 GNUNET_NETWORK_fdset_isset (tc->write_ready, fc->armClientSocket))
396 { 396 {
397 fc->service_to_client_task = 397 fc->service_to_client_task =
398 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 398 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
399 fc->armClientSocket, 399 fc->armClientSocket, &forwardToClient,
400 &forwardToClient, fc); 400 fc);
401 return; 401 return;
402 } 402 }
403 /* Forwarding service response to client */ 403 /* Forwarding service response to client */
@@ -415,8 +415,8 @@ forwardToClient (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
415 return; 415 return;
416 } 416 }
417#if DEBUG_SERVICE_MANAGER 417#if DEBUG_SERVICE_MANAGER
418 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 418 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Forwarded %d bytes to client\n",
419 "Forwarded %d bytes to client\n", numberOfBytesSent); 419 numberOfBytesSent);
420#endif 420#endif
421 if (numberOfBytesSent < fc->service_to_client_bufferDataLength) 421 if (numberOfBytesSent < fc->service_to_client_bufferDataLength)
422 { 422 {
@@ -424,14 +424,14 @@ forwardToClient (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
424 fc->service_to_client_bufferDataLength -= numberOfBytesSent; 424 fc->service_to_client_bufferDataLength -= numberOfBytesSent;
425 fc->service_to_client_task = 425 fc->service_to_client_task =
426 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 426 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
427 fc->armClientSocket, 427 fc->armClientSocket, &forwardToClient,
428 &forwardToClient, fc); 428 fc);
429 return; 429 return;
430 } 430 }
431 fc->service_to_client_task = 431 fc->service_to_client_task =
432 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 432 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
433 fc->armServiceSocket, 433 fc->armServiceSocket, &receiveFromService,
434 &receiveFromService, fc); 434 fc);
435} 435}
436 436
437 437
@@ -454,8 +454,8 @@ receiveFromService (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
454 closeClientAndServiceSockets (fc, REASON_ERROR); 454 closeClientAndServiceSockets (fc, REASON_ERROR);
455 return; 455 return;
456 } 456 }
457 if (GNUNET_YES != GNUNET_NETWORK_fdset_isset (tc->read_ready, 457 if (GNUNET_YES !=
458 fc->armServiceSocket)) 458 GNUNET_NETWORK_fdset_isset (tc->read_ready, fc->armServiceSocket))
459 { 459 {
460 fc->service_to_client_task = 460 fc->service_to_client_task =
461 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 461 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
@@ -497,12 +497,12 @@ receiveFromService (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
497 GNUNET_a2s (fc->listen_info->service_addr, 497 GNUNET_a2s (fc->listen_info->service_addr,
498 fc->listen_info->service_addr_len), 498 fc->listen_info->service_addr_len),
499 (unsigned long long) GNUNET_TIME_relative_min (fc->back_off, 499 (unsigned long long) GNUNET_TIME_relative_min (fc->back_off,
500 rem).rel_value); 500 rem).
501 rel_value);
501#endif 502#endif
502 rem = GNUNET_TIME_absolute_get_remaining (fc->timeout); 503 rem = GNUNET_TIME_absolute_get_remaining (fc->timeout);
503 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == fc->start_task); 504 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == fc->start_task);
504 fc->start_task 505 fc->start_task =
505 =
506 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_min 506 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_min
507 (fc->back_off, rem), &start_forwarding, 507 (fc->back_off, rem), &start_forwarding,
508 fc); 508 fc);
@@ -520,14 +520,13 @@ receiveFromService (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
520 } 520 }
521 fc->first_write_done = GNUNET_YES; 521 fc->first_write_done = GNUNET_YES;
522#if DEBUG_SERVICE_MANAGER 522#if DEBUG_SERVICE_MANAGER
523 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 523 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %d bytes for client\n",
524 "Received %d bytes for client\n",
525 fc->service_to_client_bufferDataLength); 524 fc->service_to_client_bufferDataLength);
526#endif 525#endif
527 fc->service_to_client_task = 526 fc->service_to_client_task =
528 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 527 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
529 fc->armClientSocket, 528 fc->armClientSocket, &forwardToClient,
530 &forwardToClient, fc); 529 fc);
531} 530}
532 531
533 532
@@ -551,13 +550,13 @@ forwardToService (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
551 closeClientAndServiceSockets (fc, REASON_ERROR); 550 closeClientAndServiceSockets (fc, REASON_ERROR);
552 return; 551 return;
553 } 552 }
554 if (GNUNET_YES != GNUNET_NETWORK_fdset_isset (tc->write_ready, 553 if (GNUNET_YES !=
555 fc->armServiceSocket)) 554 GNUNET_NETWORK_fdset_isset (tc->write_ready, fc->armServiceSocket))
556 { 555 {
557 fc->client_to_service_task = 556 fc->client_to_service_task =
558 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 557 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
559 fc->armServiceSocket, 558 fc->armServiceSocket, &forwardToService,
560 &forwardToService, fc); 559 fc);
561 return; 560 return;
562 } 561 }
563 numberOfBytesSent = 562 numberOfBytesSent =
@@ -585,12 +584,12 @@ forwardToService (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
585 GNUNET_a2s (fc->listen_info->service_addr, 584 GNUNET_a2s (fc->listen_info->service_addr,
586 fc->listen_info->service_addr_len), 585 fc->listen_info->service_addr_len),
587 (unsigned long long) GNUNET_TIME_relative_min (fc->back_off, 586 (unsigned long long) GNUNET_TIME_relative_min (fc->back_off,
588 rem).rel_value); 587 rem).
588 rel_value);
589#endif 589#endif
590 rem = GNUNET_TIME_absolute_get_remaining (fc->timeout); 590 rem = GNUNET_TIME_absolute_get_remaining (fc->timeout);
591 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == fc->start_task); 591 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == fc->start_task);
592 fc->start_task 592 fc->start_task =
593 =
594 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_min 593 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_min
595 (fc->back_off, rem), &start_forwarding, 594 (fc->back_off, rem), &start_forwarding,
596 fc); 595 fc);
@@ -606,8 +605,8 @@ forwardToService (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
606 return; 605 return;
607 } 606 }
608#if DEBUG_SERVICE_MANAGER 607#if DEBUG_SERVICE_MANAGER
609 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 608 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Forwarded %d bytes to service\n",
610 "Forwarded %d bytes to service\n", numberOfBytesSent); 609 numberOfBytesSent);
611#endif 610#endif
612 fc->first_write_done = GNUNET_YES; 611 fc->first_write_done = GNUNET_YES;
613 if (numberOfBytesSent < fc->client_to_service_bufferDataLength) 612 if (numberOfBytesSent < fc->client_to_service_bufferDataLength)
@@ -616,14 +615,14 @@ forwardToService (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
616 fc->client_to_service_bufferDataLength -= numberOfBytesSent; 615 fc->client_to_service_bufferDataLength -= numberOfBytesSent;
617 fc->client_to_service_task = 616 fc->client_to_service_task =
618 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 617 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
619 fc->armServiceSocket, 618 fc->armServiceSocket, &forwardToService,
620 &forwardToService, fc); 619 fc);
621 return; 620 return;
622 } 621 }
623 fc->client_to_service_task = 622 fc->client_to_service_task =
624 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 623 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
625 fc->armClientSocket, 624 fc->armClientSocket, &receiveFromClient,
626 &receiveFromClient, fc); 625 fc);
627} 626}
628 627
629 628
@@ -639,13 +638,13 @@ receiveFromClient (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
639 struct ForwardedConnection *fc = cls; 638 struct ForwardedConnection *fc = cls;
640 639
641 fc->client_to_service_task = GNUNET_SCHEDULER_NO_TASK; 640 fc->client_to_service_task = GNUNET_SCHEDULER_NO_TASK;
642 if (GNUNET_YES != GNUNET_NETWORK_fdset_isset (tc->read_ready, 641 if (GNUNET_YES !=
643 fc->armClientSocket)) 642 GNUNET_NETWORK_fdset_isset (tc->read_ready, fc->armClientSocket))
644 { 643 {
645 fc->client_to_service_task = 644 fc->client_to_service_task =
646 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 645 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
647 fc->armClientSocket, 646 fc->armClientSocket, &receiveFromClient,
648 &receiveFromClient, fc); 647 fc);
649 return; 648 return;
650 } 649 }
651 fc->client_to_service_bufferPos = fc->client_to_service_buffer; 650 fc->client_to_service_bufferPos = fc->client_to_service_buffer;
@@ -665,23 +664,22 @@ receiveFromClient (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
665 else 664 else
666 { 665 {
667#if DEBUG_SERVICE_MANAGER 666#if DEBUG_SERVICE_MANAGER
668 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 667 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error receiving from client: %s\n",
669 "Error receiving from client: %s\n", STRERROR (errno)); 668 STRERROR (errno));
670#endif 669#endif
671 } 670 }
672 closeClientAndServiceSockets (fc, REASON_CLIENT_TO_SERVICE); 671 closeClientAndServiceSockets (fc, REASON_CLIENT_TO_SERVICE);
673 return; 672 return;
674 } 673 }
675#if DEBUG_SERVICE_MANAGER 674#if DEBUG_SERVICE_MANAGER
676 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 675 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %d bytes for service\n",
677 "Received %d bytes for service\n",
678 fc->client_to_service_bufferDataLength); 676 fc->client_to_service_bufferDataLength);
679#endif 677#endif
680 if (fc->armServiceSocket != NULL) 678 if (fc->armServiceSocket != NULL)
681 fc->client_to_service_task = 679 fc->client_to_service_task =
682 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 680 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
683 fc->armServiceSocket, 681 fc->armServiceSocket, &forwardToService,
684 &forwardToService, fc); 682 fc);
685 else 683 else
686 /* We have not added any task with fc as a closure, so we're 684 /* We have not added any task with fc as a closure, so we're
687 * dropping our reference to fc 685 * dropping our reference to fc
@@ -742,8 +740,8 @@ fc_acceptConnection (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
742 else 740 else
743 fc->service_to_client_task = 741 fc->service_to_client_task =
744 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 742 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
745 fc->armClientSocket, 743 fc->armClientSocket, &forwardToClient,
746 &forwardToClient, fc); 744 fc);
747 fc->reference_count += 1; 745 fc->reference_count += 1;
748 } 746 }
749 GNUNET_free (sli); 747 GNUNET_free (sli);
@@ -751,9 +749,8 @@ fc_acceptConnection (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
751 749
752 750
753static struct ServiceListeningInfo * 751static struct ServiceListeningInfo *
754service_try_to_connect (const struct sockaddr *addr, 752service_try_to_connect (const struct sockaddr *addr, int pf, socklen_t addrlen,
755 int pf, 753 struct ForwardedConnection *fc)
756 socklen_t addrlen, struct ForwardedConnection *fc)
757{ 754{
758 struct GNUNET_NETWORK_Handle *sock; 755 struct GNUNET_NETWORK_Handle *sock;
759 struct ServiceListeningInfo *serviceListeningInfo; 756 struct ServiceListeningInfo *serviceListeningInfo;
@@ -839,8 +836,8 @@ start_forwarding (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
839 target_ipv4.sin_port = v4->sin_port; 836 target_ipv4.sin_port = v4->sin_port;
840 v4 = &target_ipv4; 837 v4 = &target_ipv4;
841 } 838 }
842 sc = service_try_to_connect ((const struct sockaddr *) v4, 839 sc = service_try_to_connect ((const struct sockaddr *) v4, PF_INET,
843 PF_INET, sizeof (struct sockaddr_in), fc); 840 sizeof (struct sockaddr_in), fc);
844 break; 841 break;
845 case AF_INET6: 842 case AF_INET6:
846 v6 = (struct sockaddr_in6 *) fc->listen_info->service_addr; 843 v6 = (struct sockaddr_in6 *) fc->listen_info->service_addr;
@@ -855,12 +852,11 @@ start_forwarding (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
855 target_ipv6.sin6_port = v6->sin6_port; 852 target_ipv6.sin6_port = v6->sin6_port;
856 v6 = &target_ipv6; 853 v6 = &target_ipv6;
857 } 854 }
858 sc = service_try_to_connect ((const struct sockaddr *) v6, 855 sc = service_try_to_connect ((const struct sockaddr *) v6, PF_INET6,
859 PF_INET6, sizeof (struct sockaddr_in6), fc); 856 sizeof (struct sockaddr_in6), fc);
860 break; 857 break;
861 case AF_UNIX: 858 case AF_UNIX:
862 sc = service_try_to_connect (fc->listen_info->service_addr, 859 sc = service_try_to_connect (fc->listen_info->service_addr, PF_UNIX,
863 PF_UNIX,
864 fc->listen_info->service_addr_len, fc); 860 fc->listen_info->service_addr_len, fc);
865 break; 861 break;
866 default: 862 default:
@@ -917,8 +913,8 @@ stop_listening (const char *serviceName)
917 * @param cls callback data, struct ServiceListeningInfo describing a listen socket 913 * @param cls callback data, struct ServiceListeningInfo describing a listen socket
918 * @param tc context 914 * @param tc context
919 */ 915 */
920static void 916static void acceptConnection (void *cls,
921acceptConnection (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 917 const struct GNUNET_SCHEDULER_TaskContext *tc);
922 918
923 919
924static void 920static void
@@ -952,18 +948,18 @@ accept_and_forward (struct ServiceListeningInfo *serviceListeningInfo)
952 return; 948 return;
953 } 949 }
954 GNUNET_break (GNUNET_OK == 950 GNUNET_break (GNUNET_OK ==
955 GNUNET_NETWORK_socket_close 951 GNUNET_NETWORK_socket_close (serviceListeningInfo->
956 (serviceListeningInfo->listeningSocket)); 952 listeningSocket));
957 start_service (NULL, serviceListeningInfo->serviceName, NULL); 953 start_service (NULL, serviceListeningInfo->serviceName, NULL);
958 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 954 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Service `%s' started\n"),
959 _("Service `%s' started\n"), fc->listen_info->serviceName); 955 fc->listen_info->serviceName);
960 fc->timeout = 956 fc->timeout =
961 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_SERVICE_TIMEOUT); 957 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_SERVICE_TIMEOUT);
962 fc->back_off = GNUNET_TIME_UNIT_MILLISECONDS; 958 fc->back_off = GNUNET_TIME_UNIT_MILLISECONDS;
963 fc->client_to_service_task = 959 fc->client_to_service_task =
964 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 960 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
965 fc->armClientSocket, 961 fc->armClientSocket, &receiveFromClient,
966 &receiveFromClient, fc); 962 fc);
967 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == fc->start_task); 963 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == fc->start_task);
968 /* We're creating another chain of tasks for this fc that 964 /* We're creating another chain of tasks for this fc that
969 * will have its own reference to it. 965 * will have its own reference to it.
@@ -997,12 +993,12 @@ acceptConnection (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
997 serviceListeningInfoList_tail, sli); 993 serviceListeningInfoList_tail, sli);
998#ifndef MINGW 994#ifndef MINGW
999 use_lsocks = GNUNET_NO; 995 use_lsocks = GNUNET_NO;
1000 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (cfg, 996 if (GNUNET_YES ==
1001 sli->serviceName, 997 GNUNET_CONFIGURATION_have_value (cfg, sli->serviceName,
1002 "DISABLE_SOCKET_FORWARDING")) 998 "DISABLE_SOCKET_FORWARDING"))
1003 use_lsocks = GNUNET_CONFIGURATION_get_value_yesno (cfg, 999 use_lsocks =
1004 sli->serviceName, 1000 GNUNET_CONFIGURATION_get_value_yesno (cfg, sli->serviceName,
1005 "DISABLE_SOCKET_FORWARDING"); 1001 "DISABLE_SOCKET_FORWARDING");
1006#else 1002#else
1007 use_lsocks = GNUNET_YES; 1003 use_lsocks = GNUNET_YES;
1008#endif 1004#endif
@@ -1100,8 +1096,8 @@ createListeningSocket (struct sockaddr *sa, socklen_t addr_len,
1100 "setsockopt"); 1096 "setsockopt");
1101#endif 1097#endif
1102 1098
1103 if (GNUNET_NETWORK_socket_bind 1099 if (GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) sa, addr_len)
1104 (sock, (const struct sockaddr *) sa, addr_len) != GNUNET_OK) 1100 != GNUNET_OK)
1105 { 1101 {
1106 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1102 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1107 _ 1103 _
@@ -1145,8 +1141,8 @@ createListeningSocket (struct sockaddr *sa, socklen_t addr_len,
1145 * @param value the option's value 1141 * @param value the option's value
1146 */ 1142 */
1147static void 1143static void
1148checkPortNumberCB (void *cls, 1144checkPortNumberCB (void *cls, const char *section, const char *option,
1149 const char *section, const char *option, const char *value) 1145 const char *value)
1150{ 1146{
1151 struct sockaddr **addrs; 1147 struct sockaddr **addrs;
1152 socklen_t *addr_lens; 1148 socklen_t *addr_lens;
@@ -1158,8 +1154,9 @@ checkPortNumberCB (void *cls,
1158 (strcasecmp (value, "YES") != 0) || 1154 (strcasecmp (value, "YES") != 0) ||
1159 (isInDefaultList (section) == GNUNET_YES)) 1155 (isInDefaultList (section) == GNUNET_YES))
1160 return; 1156 return;
1161 if (0 >= (ret = GNUNET_SERVICE_get_server_addresses (section, cfg, &addrs, 1157 if (0 >=
1162 &addr_lens))) 1158 (ret =
1159 GNUNET_SERVICE_get_server_addresses (section, cfg, &addrs, &addr_lens)))
1163 return; 1160 return;
1164 /* this will free (or capture) addrs[i] */ 1161 /* this will free (or capture) addrs[i] */
1165 for (i = 0; i < ret; i++) 1162 for (i = 0; i < ret; i++)
diff --git a/src/arm/mockup-service.c b/src/arm/mockup-service.c
index 0a0e1de5a..53a502fa8 100644
--- a/src/arm/mockup-service.c
+++ b/src/arm/mockup-service.c
@@ -61,8 +61,7 @@ transmit_shutdown_ack (void *cls, size_t size, void *buf)
61 * @param message the actual message 61 * @param message the actual message
62 */ 62 */
63static void 63static void
64handle_shutdown (void *cls, 64handle_shutdown (void *cls, struct GNUNET_SERVER_Client *client,
65 struct GNUNET_SERVER_Client *client,
66 const struct GNUNET_MessageHeader *message) 65 const struct GNUNET_MessageHeader *message)
67{ 66{
68 GNUNET_SERVER_client_keep (client); 67 GNUNET_SERVER_client_keep (client);
@@ -79,8 +78,7 @@ handle_shutdown (void *cls,
79 78
80 79
81static void 80static void
82run (void *cls, 81run (void *cls, struct GNUNET_SERVER_Handle *server,
83 struct GNUNET_SERVER_Handle *server,
84 const struct GNUNET_CONFIGURATION_Handle *cfg) 82 const struct GNUNET_CONFIGURATION_Handle *cfg)
85{ 83{
86 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 84 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
@@ -99,10 +97,9 @@ main (int argc, char *const *argv)
99{ 97{
100 int ret; 98 int ret;
101 99
102 ret = (GNUNET_OK == 100 ret =
103 GNUNET_SERVICE_run (argc, 101 (GNUNET_OK ==
104 argv, 102 GNUNET_SERVICE_run (argc, argv, "do-nothing", GNUNET_SERVICE_OPTION_NONE,
105 "do-nothing", GNUNET_SERVICE_OPTION_NONE, 103 &run, NULL)) ? 0 : 1;
106 &run, NULL)) ? 0 : 1;
107 return ret; 104 return ret;
108} 105}
diff --git a/src/arm/test_arm_api.c b/src/arm/test_arm_api.c
index 1e9d84202..11c245ea1 100644
--- a/src/arm/test_arm_api.c
+++ b/src/arm/test_arm_api.c
@@ -114,9 +114,8 @@ arm_notify (void *cls, int success)
114 114
115 115
116static void 116static void
117task (void *cls, 117task (void *cls, char *const *args, const char *cfgfile,
118 char *const *args, 118 const struct GNUNET_CONFIGURATION_Handle *c)
119 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
120{ 119{
121 cfg = c; 120 cfg = c;
122 arm = GNUNET_ARM_connect (cfg, NULL); 121 arm = GNUNET_ARM_connect (cfg, NULL);
@@ -145,9 +144,8 @@ check ()
145 }; 144 };
146 GNUNET_assert (GNUNET_OK == 145 GNUNET_assert (GNUNET_OK ==
147 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 146 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
148 argv, 147 argv, "test-arm-api", "nohelp", options,
149 "test-arm-api", 148 &task, NULL));
150 "nohelp", options, &task, NULL));
151 return ok; 149 return ok;
152} 150}
153 151
diff --git a/src/arm/test_exponential_backoff.c b/src/arm/test_exponential_backoff.c
index eb6421d5f..04c52d0eb 100644
--- a/src/arm/test_exponential_backoff.c
+++ b/src/arm/test_exponential_backoff.c
@@ -136,8 +136,7 @@ service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg)
136 "Received confirmation for service shutdown.\n"); 136 "Received confirmation for service shutdown.\n");
137#endif 137#endif
138 shutdown_ctx->confirmed = GNUNET_YES; 138 shutdown_ctx->confirmed = GNUNET_YES;
139 GNUNET_CLIENT_receive (shutdown_ctx->sock, 139 GNUNET_CLIENT_receive (shutdown_ctx->sock, &service_shutdown_handler,
140 &service_shutdown_handler,
141 shutdown_ctx, GNUNET_TIME_UNIT_FOREVER_REL); 140 shutdown_ctx, GNUNET_TIME_UNIT_FOREVER_REL);
142 break; 141 break;
143 default: /* Fall through */ 142 default: /* Fall through */
@@ -197,9 +196,8 @@ write_shutdown (void *cls, size_t size, void *buf)
197 return 0; /* client disconnected */ 196 return 0; /* client disconnected */
198 } 197 }
199 198
200 GNUNET_CLIENT_receive (shutdown_ctx->sock, 199 GNUNET_CLIENT_receive (shutdown_ctx->sock, &service_shutdown_handler,
201 &service_shutdown_handler, shutdown_ctx, 200 shutdown_ctx, GNUNET_TIME_UNIT_FOREVER_REL);
202 GNUNET_TIME_UNIT_FOREVER_REL);
203 shutdown_ctx->cancel_task = 201 shutdown_ctx->cancel_task =
204 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining 202 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
205 (shutdown_ctx->timeout), 203 (shutdown_ctx->timeout),
@@ -237,11 +235,9 @@ arm_service_shutdown (struct GNUNET_CLIENT_Connection *sock,
237 shutdown_ctx->sock = sock; 235 shutdown_ctx->sock = sock;
238 shutdown_ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout); 236 shutdown_ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
239 GNUNET_CLIENT_notify_transmit_ready (sock, 237 GNUNET_CLIENT_notify_transmit_ready (sock,
240 sizeof (struct 238 sizeof (struct GNUNET_MessageHeader),
241 GNUNET_MessageHeader), 239 timeout, GNUNET_NO, &write_shutdown,
242 timeout, 240 shutdown_ctx);
243 GNUNET_NO,
244 &write_shutdown, shutdown_ctx);
245} 241}
246 242
247 243
@@ -255,8 +251,8 @@ arm_notify_stop (void *cls, int success)
255} 251}
256 252
257 253
258static void 254static void kill_task (void *cbData,
259kill_task (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc); 255 const struct GNUNET_SCHEDULER_TaskContext *tc);
260 256
261 257
262static void 258static void
@@ -272,13 +268,13 @@ static void
272arm_notify (void *cls, int success) 268arm_notify (void *cls, int success)
273{ 269{
274 GNUNET_assert (success == GNUNET_YES); 270 GNUNET_assert (success == GNUNET_YES);
275 GNUNET_ARM_start_service (arm, 271 GNUNET_ARM_start_service (arm, "do-nothing", TIMEOUT, &do_nothing_notify,
276 "do-nothing", TIMEOUT, &do_nothing_notify, NULL); 272 NULL);
277} 273}
278 274
279 275
280static void 276static void kill_task (void *cbData,
281kill_task (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc); 277 const struct GNUNET_SCHEDULER_TaskContext *tc);
282 278
283 279
284static void 280static void
@@ -310,8 +306,7 @@ do_nothing_restarted_notify_task (void *cls,
310static void 306static void
311do_test (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc) 307do_test (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc)
312{ 308{
313 GNUNET_CLIENT_service_test ("do-nothing", 309 GNUNET_CLIENT_service_test ("do-nothing", cfg, TIMEOUT,
314 cfg, TIMEOUT,
315 &do_nothing_restarted_notify_task, NULL); 310 &do_nothing_restarted_notify_task, NULL);
316} 311}
317 312
@@ -335,8 +330,8 @@ kill_task (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc)
335 waitedFor = GNUNET_TIME_absolute_get_duration (startedWaitingAt); 330 waitedFor = GNUNET_TIME_absolute_get_duration (startedWaitingAt);
336 331
337#if LOG_BACKOFF 332#if LOG_BACKOFF
338 fprintf (killLogFilePtr, 333 fprintf (killLogFilePtr, "Waited for: %llu ms\n",
339 "Waited for: %llu ms\n", (unsigned long long) waitedFor.rel_value); 334 (unsigned long long) waitedFor.rel_value);
340#endif 335#endif
341 } 336 }
342 else 337 else
@@ -349,8 +344,8 @@ kill_task (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc)
349 if (trialCount == 12) 344 if (trialCount == 12)
350 { 345 {
351 GNUNET_CLIENT_disconnect (doNothingConnection, GNUNET_NO); 346 GNUNET_CLIENT_disconnect (doNothingConnection, GNUNET_NO);
352 GNUNET_ARM_stop_service (arm, 347 GNUNET_ARM_stop_service (arm, "do-nothing", TIMEOUT, &arm_notify_stop,
353 "do-nothing", TIMEOUT, &arm_notify_stop, NULL); 348 NULL);
354 ok = 0; 349 ok = 0;
355 return; 350 return;
356 } 351 }
@@ -360,9 +355,8 @@ kill_task (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc)
360 355
361 356
362static void 357static void
363task (void *cls, 358task (void *cls, char *const *args, const char *cfgfile,
364 char *const *args, 359 const struct GNUNET_CONFIGURATION_Handle *c)
365 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
366{ 360{
367 cfg = c; 361 cfg = c;
368 362
@@ -393,9 +387,8 @@ check ()
393 /* Running ARM and running the do_nothing task */ 387 /* Running ARM and running the do_nothing task */
394 GNUNET_assert (GNUNET_OK == 388 GNUNET_assert (GNUNET_OK ==
395 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 389 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
396 argv, 390 argv, "test-exponential-backoff", "nohelp",
397 "test-exponential-backoff", 391 options, &task, NULL));
398 "nohelp", options, &task, NULL));
399 392
400 393
401 return ok; 394 return ok;
diff --git a/src/arm/test_gnunet_service_manager.c b/src/arm/test_gnunet_service_manager.c
index 4c4de9242..4f863ed19 100644
--- a/src/arm/test_gnunet_service_manager.c
+++ b/src/arm/test_gnunet_service_manager.c
@@ -101,9 +101,9 @@ arm_notify (void *cls, int success)
101 } 101 }
102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to resolve our own hostname!\n"); 102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to resolve our own hostname!\n");
103 /* connect to the resolver service */ 103 /* connect to the resolver service */
104 if (NULL == GNUNET_RESOLVER_hostname_resolve (AF_UNSPEC, 104 if (NULL ==
105 TIMEOUT, 105 GNUNET_RESOLVER_hostname_resolve (AF_UNSPEC, TIMEOUT, &hostNameResolveCB,
106 &hostNameResolveCB, NULL)) 106 NULL))
107 { 107 {
108 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 108 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
109 "Unable initiate connection to resolver service\n"); 109 "Unable initiate connection to resolver service\n");
@@ -116,9 +116,8 @@ arm_notify (void *cls, int success)
116 116
117 117
118static void 118static void
119run (void *cls, 119run (void *cls, char *const *args, const char *cfgfile,
120 char *const *args, 120 const struct GNUNET_CONFIGURATION_Handle *c)
121 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
122{ 121{
123 cfg = c; 122 cfg = c;
124#if START_ARM 123#if START_ARM
@@ -146,8 +145,7 @@ check ()
146 }; 145 };
147 GNUNET_assert (GNUNET_OK == 146 GNUNET_assert (GNUNET_OK ==
148 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 147 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
149 argv, 148 argv, "test-gnunet-service-manager",
150 "test-gnunet-service-manager",
151 "nohelp", options, &run, NULL)); 149 "nohelp", options, &run, NULL));
152} 150}
153 151
@@ -159,8 +157,8 @@ main (int argc, char *argv[])
159 157
160 if (0 != gethostname (hostname, sizeof (hostname) - 1)) 158 if (0 != gethostname (hostname, sizeof (hostname) - 1))
161 { 159 {
162 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | 160 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
163 GNUNET_ERROR_TYPE_BULK, "gethostname"); 161 "gethostname");
164 fprintf (stderr, 162 fprintf (stderr,
165 "Failed to determine my own hostname, testcase not run.\n"); 163 "Failed to determine my own hostname, testcase not run.\n");
166 return 0; 164 return 0;
diff --git a/src/ats/ats_api.c b/src/ats/ats_api.c
index 6cd8a82ba..ca0954173 100644
--- a/src/ats/ats_api.c
+++ b/src/ats/ats_api.c
@@ -216,18 +216,16 @@ set_bw_connections (void *cls, const GNUNET_HashCode * key, void *value)
216 ar->bandwidth = sbc->bw; 216 ar->bandwidth = sbc->bw;
217 sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls, 217 sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
218 (const struct GNUNET_PeerIdentity *) key, 218 (const struct GNUNET_PeerIdentity *) key,
219 ar->plugin_name, 219 ar->plugin_name, ar->session, ar->plugin_addr,
220 ar->session, 220 ar->plugin_addr_len, ar->bandwidth);
221 ar->plugin_addr, ar->plugin_addr_len, ar->bandwidth);
222 } 221 }
223 else if (ntohl (ar->bandwidth.value__) > 0) 222 else if (ntohl (ar->bandwidth.value__) > 0)
224 { 223 {
225 ar->bandwidth = GNUNET_BANDWIDTH_value_init (0); 224 ar->bandwidth = GNUNET_BANDWIDTH_value_init (0);
226 sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls, 225 sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
227 (const struct GNUNET_PeerIdentity *) key, 226 (const struct GNUNET_PeerIdentity *) key,
228 ar->plugin_name, 227 ar->plugin_name, ar->session, ar->plugin_addr,
229 ar->session, 228 ar->plugin_addr_len, ar->bandwidth);
230 ar->plugin_addr, ar->plugin_addr_len, ar->bandwidth);
231 } 229 }
232 return GNUNET_YES; 230 return GNUNET_YES;
233} 231}
@@ -286,13 +284,10 @@ suggest_address (void *cls, const GNUNET_HashCode * key, void *value)
286 struct AllocationRecord *ar = value; 284 struct AllocationRecord *ar = value;
287 285
288 /* trivial strategy: pick first available address... */ 286 /* trivial strategy: pick first available address... */
289 asc->cb (asc->cb_cls, 287 asc->cb (asc->cb_cls, &asc->target, ar->plugin_name, ar->plugin_addr,
290 &asc->target,
291 ar->plugin_name,
292 ar->plugin_addr,
293 ar->plugin_addr_len, 288 ar->plugin_addr_len,
294 GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32), 289 GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32), ar->ats,
295 ar->ats, ar->ats_count); 290 ar->ats_count);
296 asc->cb = NULL; 291 asc->cb = NULL;
297 return GNUNET_NO; 292 return GNUNET_NO;
298} 293}
@@ -320,17 +315,14 @@ GNUNET_ATS_suggest_address (struct GNUNET_ATS_Handle *atc,
320 asc->cb_cls = cb_cls; 315 asc->cb_cls = cb_cls;
321 asc->atc = atc; 316 asc->atc = atc;
322 asc->target = *peer; 317 asc->target = *peer;
323 GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers, 318 GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers, &peer->hashPubKey,
324 &peer->hashPubKey,
325 &suggest_address, asc); 319 &suggest_address, asc);
326 if (NULL == asc->cb) 320 if (NULL == asc->cb)
327 { 321 {
328 GNUNET_free (asc); 322 GNUNET_free (asc);
329 return NULL; 323 return NULL;
330 } 324 }
331 GNUNET_CONTAINER_multihashmap_put (atc->notify_map, 325 GNUNET_CONTAINER_multihashmap_put (atc->notify_map, &peer->hashPubKey, asc,
332 &peer->hashPubKey,
333 asc,
334 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 326 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
335 return asc; 327 return asc;
336} 328}
@@ -372,9 +364,8 @@ GNUNET_ATS_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
372 atc->alloc_cb = alloc_cb; 364 atc->alloc_cb = alloc_cb;
373 atc->alloc_cb_cls = alloc_cb_cls; 365 atc->alloc_cb_cls = alloc_cb_cls;
374 atc->peers = GNUNET_CONTAINER_multihashmap_create (256); 366 atc->peers = GNUNET_CONTAINER_multihashmap_create (256);
375 GNUNET_CONFIGURATION_get_value_number (cfg, 367 GNUNET_CONFIGURATION_get_value_number (cfg, "core", "TOTAL_QUOTA_OUT",
376 "core", 368 &atc->total_bps);
377 "TOTAL_QUOTA_OUT", &atc->total_bps);
378 return atc; 369 return atc;
379} 370}
380 371
@@ -412,8 +403,8 @@ GNUNET_ATS_shutdown (struct GNUNET_ATS_Handle *atc)
412 GNUNET_SCHEDULER_cancel (atc->ba_task); 403 GNUNET_SCHEDULER_cancel (atc->ba_task);
413 atc->ba_task = GNUNET_SCHEDULER_NO_TASK; 404 atc->ba_task = GNUNET_SCHEDULER_NO_TASK;
414 } 405 }
415 GNUNET_CONTAINER_multihashmap_iterate (atc->peers, 406 GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &destroy_allocation_record,
416 &destroy_allocation_record, NULL); 407 NULL);
417 GNUNET_CONTAINER_multihashmap_destroy (atc->peers); 408 GNUNET_CONTAINER_multihashmap_destroy (atc->peers);
418 GNUNET_assert (GNUNET_CONTAINER_multihashmap_size (atc->notify_map) == 0); 409 GNUNET_assert (GNUNET_CONTAINER_multihashmap_size (atc->notify_map) == 0);
419 GNUNET_CONTAINER_multihashmap_destroy (atc->notify_map); 410 GNUNET_CONTAINER_multihashmap_destroy (atc->notify_map);
@@ -461,8 +452,9 @@ update_session (void *cls, const GNUNET_HashCode * key, void *value)
461 if ((arnew->session == arold->session) || 452 if ((arnew->session == arold->session) ||
462 ((arold->session == NULL) && 453 ((arold->session == NULL) &&
463 (arold->plugin_addr_len == arnew->plugin_addr_len) && 454 (arold->plugin_addr_len == arnew->plugin_addr_len) &&
464 (0 == memcmp (arold->plugin_addr, 455 (0 ==
465 arnew->plugin_addr, arnew->plugin_addr_len)))) 456 memcmp (arold->plugin_addr, arnew->plugin_addr,
457 arnew->plugin_addr_len))))
466 { 458 {
467 change = GNUNET_NO; 459 change = GNUNET_NO;
468 /* records match */ 460 /* records match */
@@ -497,10 +489,8 @@ update_session (void *cls, const GNUNET_HashCode * key, void *value)
497 * @param ats_count number of performance records in 'ats' 489 * @param ats_count number of performance records in 'ats'
498 */ 490 */
499static struct AllocationRecord * 491static struct AllocationRecord *
500create_allocation_record (const char *plugin_name, 492create_allocation_record (const char *plugin_name, struct Session *session,
501 struct Session *session, 493 const void *plugin_addr, size_t plugin_addr_len,
502 const void *plugin_addr,
503 size_t plugin_addr_len,
504 const struct GNUNET_TRANSPORT_ATS_Information *ats, 494 const struct GNUNET_TRANSPORT_ATS_Information *ats,
505 uint32_t ats_count) 495 uint32_t ats_count)
506{ 496{
@@ -513,8 +503,8 @@ create_allocation_record (const char *plugin_name,
513 ar->session = session; 503 ar->session = session;
514 ar->plugin_addr_len = plugin_addr_len; 504 ar->plugin_addr_len = plugin_addr_len;
515 GNUNET_array_grow (ar->ats, ar->ats_count, ats_count); 505 GNUNET_array_grow (ar->ats, ar->ats_count, ats_count);
516 memcpy (ar->ats, 506 memcpy (ar->ats, ats,
517 ats, ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); 507 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
518 return ar; 508 return ar;
519} 509}
520 510
@@ -559,21 +549,18 @@ disconnect_peer (void *cls, const GNUNET_HashCode * key, void *value)
559void 549void
560GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc, 550GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc,
561 const struct GNUNET_PeerIdentity *peer, 551 const struct GNUNET_PeerIdentity *peer,
562 const char *plugin_name, 552 const char *plugin_name, struct Session *session,
563 struct Session *session, 553 const void *plugin_addr, size_t plugin_addr_len,
564 const void *plugin_addr,
565 size_t plugin_addr_len,
566 const struct GNUNET_TRANSPORT_ATS_Information *ats, 554 const struct GNUNET_TRANSPORT_ATS_Information *ats,
567 uint32_t ats_count) 555 uint32_t ats_count)
568{ 556{
569 struct AllocationRecord *ar; 557 struct AllocationRecord *ar;
570 struct UpdateSessionContext usc; 558 struct UpdateSessionContext usc;
571 559
572 (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers, 560 (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &disconnect_peer,
573 &disconnect_peer, atc); 561 atc);
574 ar = create_allocation_record (plugin_name, 562 ar = create_allocation_record (plugin_name, session, plugin_addr,
575 session, 563 plugin_addr_len, ats, ats_count);
576 plugin_addr, plugin_addr_len, ats, ats_count);
577 ar->connected = GNUNET_YES; 564 ar->connected = GNUNET_YES;
578 usc.atc = atc; 565 usc.atc = atc;
579 usc.arnew = ar; 566 usc.arnew = ar;
@@ -585,8 +572,7 @@ GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc,
585 } 572 }
586 GNUNET_assert (GNUNET_OK == 573 GNUNET_assert (GNUNET_OK ==
587 GNUNET_CONTAINER_multihashmap_put (atc->peers, 574 GNUNET_CONTAINER_multihashmap_put (atc->peers,
588 &peer->hashPubKey, 575 &peer->hashPubKey, ar,
589 ar,
590 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 576 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
591} 577}
592 578
@@ -646,8 +632,8 @@ destroy_session (void *cls, const GNUNET_HashCode * key, void *value)
646 if (ar->plugin_addr != NULL) 632 if (ar->plugin_addr != NULL)
647 return GNUNET_OK; 633 return GNUNET_OK;
648 GNUNET_assert (GNUNET_OK == 634 GNUNET_assert (GNUNET_OK ==
649 GNUNET_CONTAINER_multihashmap_remove (sdc->atc->peers, 635 GNUNET_CONTAINER_multihashmap_remove (sdc->atc->peers, key,
650 key, ar)); 636 ar));
651 if (GNUNET_YES == ar->connected) ; 637 if (GNUNET_YES == ar->connected) ;
652 { 638 {
653 /* FIXME: is this supposed to be allowed? What to do then? */ 639 /* FIXME: is this supposed to be allowed? What to do then? */
@@ -674,8 +660,8 @@ GNUNET_ATS_session_destroyed (struct GNUNET_ATS_Handle *atc,
674 660
675 sdc.atc = atc; 661 sdc.atc = atc;
676 sdc.session = session; 662 sdc.session = session;
677 (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers, 663 (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &destroy_session,
678 &destroy_session, &sdc); 664 &sdc);
679} 665}
680 666
681 667
@@ -693,13 +679,10 @@ notify_valid (void *cls, const GNUNET_HashCode * key, void *value)
693 struct AllocationRecord *ar = cls; 679 struct AllocationRecord *ar = cls;
694 struct GNUNET_ATS_SuggestionContext *asc = value; 680 struct GNUNET_ATS_SuggestionContext *asc = value;
695 681
696 asc->cb (asc->cb_cls, 682 asc->cb (asc->cb_cls, &asc->target, ar->plugin_name, ar->plugin_addr,
697 &asc->target,
698 ar->plugin_name,
699 ar->plugin_addr,
700 ar->plugin_addr_len, 683 ar->plugin_addr_len,
701 GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32), 684 GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32), ar->ats,
702 ar->ats, ar->ats_count); 685 ar->ats_count);
703 GNUNET_ATS_suggest_address_cancel (asc); 686 GNUNET_ATS_suggest_address_cancel (asc);
704 return GNUNET_OK; 687 return GNUNET_OK;
705} 688}
@@ -727,19 +710,16 @@ void
727GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc, 710GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc,
728 const struct GNUNET_PeerIdentity *peer, 711 const struct GNUNET_PeerIdentity *peer,
729 struct GNUNET_TIME_Absolute valid_until, 712 struct GNUNET_TIME_Absolute valid_until,
730 const char *plugin_name, 713 const char *plugin_name, struct Session *session,
731 struct Session *session, 714 const void *plugin_addr, size_t plugin_addr_len,
732 const void *plugin_addr,
733 size_t plugin_addr_len,
734 const struct GNUNET_TRANSPORT_ATS_Information *ats, 715 const struct GNUNET_TRANSPORT_ATS_Information *ats,
735 uint32_t ats_count) 716 uint32_t ats_count)
736{ 717{
737 struct AllocationRecord *ar; 718 struct AllocationRecord *ar;
738 struct UpdateSessionContext usc; 719 struct UpdateSessionContext usc;
739 720
740 ar = create_allocation_record (plugin_name, 721 ar = create_allocation_record (plugin_name, session, plugin_addr,
741 session, 722 plugin_addr_len, ats, ats_count);
742 plugin_addr, plugin_addr_len, ats, ats_count);
743 usc.atc = atc; 723 usc.atc = atc;
744 usc.arnew = ar; 724 usc.arnew = ar;
745 if (GNUNET_SYSERR == 725 if (GNUNET_SYSERR ==
@@ -750,12 +730,11 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc,
750 } 730 }
751 GNUNET_assert (GNUNET_OK == 731 GNUNET_assert (GNUNET_OK ==
752 GNUNET_CONTAINER_multihashmap_put (atc->peers, 732 GNUNET_CONTAINER_multihashmap_put (atc->peers,
753 &peer->hashPubKey, 733 &peer->hashPubKey, ar,
754 ar,
755 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 734 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
756 GNUNET_CONTAINER_multihashmap_get_multiple (atc->notify_map, 735 GNUNET_CONTAINER_multihashmap_get_multiple (atc->notify_map,
757 &peer->hashPubKey, 736 &peer->hashPubKey, &notify_valid,
758 &notify_valid, ar); 737 ar);
759} 738}
760 739
761/* end of file gnunet-service-transport_ats.c */ 740/* end of file gnunet-service-transport_ats.c */
diff --git a/src/block/block.c b/src/block/block.c
index bdef55aa3..ac466337c 100644
--- a/src/block/block.c
+++ b/src/block/block.c
@@ -72,8 +72,8 @@ struct GNUNET_BLOCK_Context
72 * @param hc where to store the result. 72 * @param hc where to store the result.
73 */ 73 */
74void 74void
75GNUNET_BLOCK_mingle_hash (const GNUNET_HashCode * in, 75GNUNET_BLOCK_mingle_hash (const GNUNET_HashCode * in, uint32_t mingle_number,
76 uint32_t mingle_number, GNUNET_HashCode * hc) 76 GNUNET_HashCode * hc)
77{ 77{
78 GNUNET_HashCode m; 78 GNUNET_HashCode m;
79 79
@@ -105,8 +105,8 @@ GNUNET_BLOCK_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg)
105 if (GNUNET_OK == 105 if (GNUNET_OK ==
106 GNUNET_CONFIGURATION_get_value_string (cfg, "block", "PLUGINS", &plugs)) 106 GNUNET_CONFIGURATION_get_value_string (cfg, "block", "PLUGINS", &plugs))
107 { 107 {
108 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 108 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading block plugins `%s'\n"),
109 _("Loading block plugins `%s'\n"), plugs); 109 plugs);
110 pos = strtok (plugs, " "); 110 pos = strtok (plugs, " ");
111 while (pos != NULL) 111 while (pos != NULL)
112 { 112 {
@@ -212,18 +212,16 @@ GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx,
212 enum GNUNET_BLOCK_Type type, 212 enum GNUNET_BLOCK_Type type,
213 const GNUNET_HashCode * query, 213 const GNUNET_HashCode * query,
214 struct GNUNET_CONTAINER_BloomFilter **bf, 214 struct GNUNET_CONTAINER_BloomFilter **bf,
215 int32_t bf_mutator, 215 int32_t bf_mutator, const void *xquery,
216 const void *xquery, 216 size_t xquery_size, const void *reply_block,
217 size_t xquery_size, 217 size_t reply_block_size)
218 const void *reply_block, size_t reply_block_size)
219{ 218{
220 struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx, type); 219 struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx, type);
221 220
222 if (plugin == NULL) 221 if (plugin == NULL)
223 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; 222 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
224 return plugin->evaluate (plugin->cls, 223 return plugin->evaluate (plugin->cls, type, query, bf, bf_mutator, xquery,
225 type, query, bf, bf_mutator, 224 xquery_size, reply_block, reply_block_size);
226 xquery, xquery_size, reply_block, reply_block_size);
227} 225}
228 226
229 227
@@ -240,8 +238,7 @@ GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx,
240 */ 238 */
241int 239int
242GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx, 240GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx,
243 enum GNUNET_BLOCK_Type type, 241 enum GNUNET_BLOCK_Type type, const void *block,
244 const void *block,
245 size_t block_size, GNUNET_HashCode * key) 242 size_t block_size, GNUNET_HashCode * key)
246{ 243{
247 struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx, type); 244 struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx, type);
diff --git a/src/block/plugin_block_dht.c b/src/block/plugin_block_dht.c
index 1fe51e1a3..614628a40 100644
--- a/src/block/plugin_block_dht.c
+++ b/src/block/plugin_block_dht.c
@@ -49,14 +49,12 @@
49 * @return characterization of result 49 * @return characterization of result
50 */ 50 */
51static enum GNUNET_BLOCK_EvaluationResult 51static enum GNUNET_BLOCK_EvaluationResult
52block_plugin_dht_evaluate (void *cls, 52block_plugin_dht_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
53 enum GNUNET_BLOCK_Type type,
54 const GNUNET_HashCode * query, 53 const GNUNET_HashCode * query,
55 struct GNUNET_CONTAINER_BloomFilter **bf, 54 struct GNUNET_CONTAINER_BloomFilter **bf,
56 int32_t bf_mutator, 55 int32_t bf_mutator, const void *xquery,
57 const void *xquery, 56 size_t xquery_size, const void *reply_block,
58 size_t xquery_size, 57 size_t reply_block_size)
59 const void *reply_block, size_t reply_block_size)
60{ 58{
61 switch (type) 59 switch (type)
62 { 60 {
@@ -85,10 +83,9 @@ block_plugin_dht_evaluate (void *cls,
85 * (or if extracting a key from a block of this type does not work) 83 * (or if extracting a key from a block of this type does not work)
86 */ 84 */
87static int 85static int
88block_plugin_dht_get_key (void *cls, 86block_plugin_dht_get_key (void *cls, enum GNUNET_BLOCK_Type type,
89 enum GNUNET_BLOCK_Type type, 87 const void *block, size_t block_size,
90 const void *block, 88 GNUNET_HashCode * key)
91 size_t block_size, GNUNET_HashCode * key)
92{ 89{
93 const struct GNUNET_MessageHeader *msg; 90 const struct GNUNET_MessageHeader *msg;
94 const struct GNUNET_HELLO_Message *hello; 91 const struct GNUNET_HELLO_Message *hello;
@@ -98,16 +95,14 @@ block_plugin_dht_get_key (void *cls,
98 return GNUNET_SYSERR; 95 return GNUNET_SYSERR;
99 if (block_size < sizeof (struct GNUNET_MessageHeader)) 96 if (block_size < sizeof (struct GNUNET_MessageHeader))
100 { 97 {
101 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 98 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "block-dht",
102 "block-dht",
103 _("Block not of type %u\n"), GNUNET_BLOCK_TYPE_DHT_HELLO); 99 _("Block not of type %u\n"), GNUNET_BLOCK_TYPE_DHT_HELLO);
104 return GNUNET_NO; 100 return GNUNET_NO;
105 } 101 }
106 msg = block; 102 msg = block;
107 if (block_size != ntohs (msg->size)) 103 if (block_size != ntohs (msg->size))
108 { 104 {
109 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 105 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "block-dht",
110 "block-dht",
111 _("Size mismatch for block\n"), 106 _("Size mismatch for block\n"),
112 GNUNET_BLOCK_TYPE_DHT_HELLO); 107 GNUNET_BLOCK_TYPE_DHT_HELLO);
113 return GNUNET_NO; 108 return GNUNET_NO;
@@ -116,8 +111,7 @@ block_plugin_dht_get_key (void *cls,
116 pid = (struct GNUNET_PeerIdentity *) key; 111 pid = (struct GNUNET_PeerIdentity *) key;
117 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, pid)) 112 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, pid))
118 { 113 {
119 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 114 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "block-dht",
120 "block-dht",
121 _("Block of type %u is malformed\n"), 115 _("Block of type %u is malformed\n"),
122 GNUNET_BLOCK_TYPE_DHT_HELLO); 116 GNUNET_BLOCK_TYPE_DHT_HELLO);
123 return GNUNET_NO; 117 return GNUNET_NO;
diff --git a/src/block/plugin_block_dns.c b/src/block/plugin_block_dns.c
index 0cf8c50e9..e20370685 100644
--- a/src/block/plugin_block_dns.c
+++ b/src/block/plugin_block_dns.c
@@ -47,14 +47,12 @@
47 * @return characterization of result 47 * @return characterization of result
48 */ 48 */
49static enum GNUNET_BLOCK_EvaluationResult 49static enum GNUNET_BLOCK_EvaluationResult
50block_plugin_dns_evaluate (void *cls, 50block_plugin_dns_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
51 enum GNUNET_BLOCK_Type type,
52 const GNUNET_HashCode * query, 51 const GNUNET_HashCode * query,
53 struct GNUNET_CONTAINER_BloomFilter **bf, 52 struct GNUNET_CONTAINER_BloomFilter **bf,
54 int32_t bf_mutator, 53 int32_t bf_mutator, const void *xquery,
55 const void *xquery, 54 size_t xquery_size, const void *reply_block,
56 size_t xquery_size, 55 size_t reply_block_size)
57 const void *reply_block, size_t reply_block_size)
58{ 56{
59 switch (type) 57 switch (type)
60 { 58 {
@@ -123,10 +121,9 @@ block_plugin_dns_evaluate (void *cls,
123 * (or if extracting a key from a block of this type does not work) 121 * (or if extracting a key from a block of this type does not work)
124 */ 122 */
125static int 123static int
126block_plugin_dns_get_key (void *cls, 124block_plugin_dns_get_key (void *cls, enum GNUNET_BLOCK_Type type,
127 enum GNUNET_BLOCK_Type type, 125 const void *block, size_t block_size,
128 const void *block, 126 GNUNET_HashCode * key)
129 size_t block_size, GNUNET_HashCode * key)
130{ 127{
131 if (type != GNUNET_BLOCK_TYPE_DNS) 128 if (type != GNUNET_BLOCK_TYPE_DNS)
132 return GNUNET_SYSERR; 129 return GNUNET_SYSERR;
diff --git a/src/block/plugin_block_fs.c b/src/block/plugin_block_fs.c
index db8e59991..627f21a10 100644
--- a/src/block/plugin_block_fs.c
+++ b/src/block/plugin_block_fs.c
@@ -56,14 +56,12 @@
56 * @return characterization of result 56 * @return characterization of result
57 */ 57 */
58static enum GNUNET_BLOCK_EvaluationResult 58static enum GNUNET_BLOCK_EvaluationResult
59block_plugin_fs_evaluate (void *cls, 59block_plugin_fs_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
60 enum GNUNET_BLOCK_Type type,
61 const GNUNET_HashCode * query, 60 const GNUNET_HashCode * query,
62 struct GNUNET_CONTAINER_BloomFilter **bf, 61 struct GNUNET_CONTAINER_BloomFilter **bf,
63 int32_t bf_mutator, 62 int32_t bf_mutator, const void *xquery,
64 const void *xquery, 63 size_t xquery_size, const void *reply_block,
65 size_t xquery_size, 64 size_t reply_block_size)
66 const void *reply_block, size_t reply_block_size)
67{ 65{
68 const struct SBlock *sb; 66 const struct SBlock *sb;
69 GNUNET_HashCode chash; 67 GNUNET_HashCode chash;
@@ -125,8 +123,7 @@ block_plugin_fs_evaluate (void *cls,
125 &sh); 123 &sh);
126 if (0 != memcmp (nsid, &sh, sizeof (GNUNET_HashCode))) 124 if (0 != memcmp (nsid, &sh, sizeof (GNUNET_HashCode)))
127 { 125 {
128 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, 126 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "block-fs",
129 "block-fs",
130 _ 127 _
131 ("Reply mismatched in terms of namespace. Discarded.\n")); 128 ("Reply mismatched in terms of namespace. Discarded.\n"));
132 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 129 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
@@ -162,10 +159,9 @@ block_plugin_fs_evaluate (void *cls,
162 * (or if extracting a key from a block of this type does not work) 159 * (or if extracting a key from a block of this type does not work)
163 */ 160 */
164static int 161static int
165block_plugin_fs_get_key (void *cls, 162block_plugin_fs_get_key (void *cls, enum GNUNET_BLOCK_Type type,
166 enum GNUNET_BLOCK_Type type, 163 const void *block, size_t block_size,
167 const void *block, 164 GNUNET_HashCode * key)
168 size_t block_size, GNUNET_HashCode * key)
169{ 165{
170 const struct KBlock *kb; 166 const struct KBlock *kb;
171 const struct SBlock *sb; 167 const struct SBlock *sb;
@@ -185,9 +181,9 @@ block_plugin_fs_get_key (void *cls,
185 } 181 }
186 kb = block; 182 kb = block;
187 if (block_size - sizeof (struct KBlock) != 183 if (block_size - sizeof (struct KBlock) !=
188 ntohl (kb->purpose.size) 184 ntohl (kb->purpose.size) -
189 - sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) 185 sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) -
190 - sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)) 186 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))
191 { 187 {
192 GNUNET_break_op (0); 188 GNUNET_break_op (0);
193 return GNUNET_NO; 189 return GNUNET_NO;
@@ -236,9 +232,9 @@ block_plugin_fs_get_key (void *cls,
236 } 232 }
237 nb = block; 233 nb = block;
238 if (block_size - sizeof (struct NBlock) != 234 if (block_size - sizeof (struct NBlock) !=
239 ntohl (nb->ns_purpose.size) 235 ntohl (nb->ns_purpose.size) -
240 - sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) 236 sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) -
241 - sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)) 237 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))
242 { 238 {
243 GNUNET_break_op (0); 239 GNUNET_break_op (0);
244 return GNUNET_NO; 240 return GNUNET_NO;
@@ -252,16 +248,16 @@ block_plugin_fs_get_key (void *cls,
252 } 248 }
253 if (GNUNET_OK != 249 if (GNUNET_OK !=
254 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK_KSIG, 250 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK_KSIG,
255 &nb->ksk_purpose, 251 &nb->ksk_purpose, &nb->ksk_signature,
256 &nb->ksk_signature, &nb->keyspace)) 252 &nb->keyspace))
257 { 253 {
258 GNUNET_break_op (0); 254 GNUNET_break_op (0);
259 return GNUNET_NO; 255 return GNUNET_NO;
260 } 256 }
261 if (GNUNET_OK != 257 if (GNUNET_OK !=
262 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK, 258 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK,
263 &nb->ns_purpose, 259 &nb->ns_purpose, &nb->ns_signature,
264 &nb->ns_signature, &nb->subspace)) 260 &nb->subspace))
265 { 261 {
266 GNUNET_break_op (0); 262 GNUNET_break_op (0);
267 return GNUNET_NO; 263 return GNUNET_NO;
diff --git a/src/block/plugin_block_template.c b/src/block/plugin_block_template.c
index 9eb84ac4b..7ce3004eb 100644
--- a/src/block/plugin_block_template.c
+++ b/src/block/plugin_block_template.c
@@ -46,14 +46,11 @@
46 * @return characterization of result 46 * @return characterization of result
47 */ 47 */
48static enum GNUNET_BLOCK_EvaluationResult 48static enum GNUNET_BLOCK_EvaluationResult
49block_plugin_template_evaluate (void *cls, 49block_plugin_template_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
50 enum GNUNET_BLOCK_Type type,
51 const GNUNET_HashCode * query, 50 const GNUNET_HashCode * query,
52 struct GNUNET_CONTAINER_BloomFilter **bf, 51 struct GNUNET_CONTAINER_BloomFilter **bf,
53 int32_t bf_mutator, 52 int32_t bf_mutator, const void *xquery,
54 const void *xquery, 53 size_t xquery_size, const void *reply_block,
55 size_t xquery_size,
56 const void *reply_block,
57 size_t reply_block_size) 54 size_t reply_block_size)
58{ 55{
59 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; 56 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
@@ -72,10 +69,9 @@ block_plugin_template_evaluate (void *cls,
72 * (or if extracting a key from a block of this type does not work) 69 * (or if extracting a key from a block of this type does not work)
73 */ 70 */
74static int 71static int
75block_plugin_template_get_key (void *cls, 72block_plugin_template_get_key (void *cls, enum GNUNET_BLOCK_Type type,
76 enum GNUNET_BLOCK_Type type, 73 const void *block, size_t block_size,
77 const void *block, 74 GNUNET_HashCode * key)
78 size_t block_size, GNUNET_HashCode * key)
79{ 75{
80 return GNUNET_SYSERR; 76 return GNUNET_SYSERR;
81} 77}
diff --git a/src/block/plugin_block_test.c b/src/block/plugin_block_test.c
index b5c03eea9..6fa535afe 100644
--- a/src/block/plugin_block_test.c
+++ b/src/block/plugin_block_test.c
@@ -53,14 +53,12 @@
53 * @return characterization of result 53 * @return characterization of result
54 */ 54 */
55static enum GNUNET_BLOCK_EvaluationResult 55static enum GNUNET_BLOCK_EvaluationResult
56block_plugin_test_evaluate (void *cls, 56block_plugin_test_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
57 enum GNUNET_BLOCK_Type type,
58 const GNUNET_HashCode * query, 57 const GNUNET_HashCode * query,
59 struct GNUNET_CONTAINER_BloomFilter **bf, 58 struct GNUNET_CONTAINER_BloomFilter **bf,
60 int32_t bf_mutator, 59 int32_t bf_mutator, const void *xquery,
61 const void *xquery, 60 size_t xquery_size, const void *reply_block,
62 size_t xquery_size, 61 size_t reply_block_size)
63 const void *reply_block, size_t reply_block_size)
64{ 62{
65 GNUNET_HashCode chash; 63 GNUNET_HashCode chash;
66 GNUNET_HashCode mhash; 64 GNUNET_HashCode mhash;
@@ -100,10 +98,9 @@ block_plugin_test_evaluate (void *cls,
100 * (or if extracting a key from a block of this type does not work) 98 * (or if extracting a key from a block of this type does not work)
101 */ 99 */
102static int 100static int
103block_plugin_test_get_key (void *cls, 101block_plugin_test_get_key (void *cls, enum GNUNET_BLOCK_Type type,
104 enum GNUNET_BLOCK_Type type, 102 const void *block, size_t block_size,
105 const void *block, 103 GNUNET_HashCode * key)
106 size_t block_size, GNUNET_HashCode * key)
107{ 104{
108 /* always fails since there is no fixed relationship between 105 /* always fails since there is no fixed relationship between
109 * keys and values for test values */ 106 * keys and values for test values */
diff --git a/src/block/test_block.c b/src/block/test_block.c
index 4bfd63ceb..f7a3422e0 100644
--- a/src/block/test_block.c
+++ b/src/block/test_block.c
@@ -37,25 +37,21 @@ test_fs (struct GNUNET_BLOCK_Context *ctx)
37 37
38 memset (block, 1, sizeof (block)); 38 memset (block, 1, sizeof (block));
39 if (GNUNET_OK != 39 if (GNUNET_OK !=
40 GNUNET_BLOCK_get_key (ctx, 40 GNUNET_BLOCK_get_key (ctx, GNUNET_BLOCK_TYPE_FS_DBLOCK, block,
41 GNUNET_BLOCK_TYPE_FS_DBLOCK, 41 sizeof (block), &key))
42 block, sizeof (block), &key))
43 return 1; 42 return 1;
44 if (GNUNET_BLOCK_EVALUATION_OK_LAST != 43 if (GNUNET_BLOCK_EVALUATION_OK_LAST !=
45 GNUNET_BLOCK_evaluate (ctx, 44 GNUNET_BLOCK_evaluate (ctx, GNUNET_BLOCK_TYPE_FS_DBLOCK, &key, NULL, 0,
46 GNUNET_BLOCK_TYPE_FS_DBLOCK, 45 NULL, 0, block, sizeof (block)))
47 &key, NULL, 0, NULL, 0, block, sizeof (block)))
48 return 2; 46 return 2;
49 if (GNUNET_BLOCK_EVALUATION_REQUEST_VALID != 47 if (GNUNET_BLOCK_EVALUATION_REQUEST_VALID !=
50 GNUNET_BLOCK_evaluate (ctx, 48 GNUNET_BLOCK_evaluate (ctx, GNUNET_BLOCK_TYPE_FS_DBLOCK, &key, NULL, 0,
51 GNUNET_BLOCK_TYPE_FS_DBLOCK, 49 NULL, 0, NULL, 0))
52 &key, NULL, 0, NULL, 0, NULL, 0))
53 return 4; 50 return 4;
54 GNUNET_log_skip (1, GNUNET_NO); 51 GNUNET_log_skip (1, GNUNET_NO);
55 if (GNUNET_BLOCK_EVALUATION_REQUEST_INVALID != 52 if (GNUNET_BLOCK_EVALUATION_REQUEST_INVALID !=
56 GNUNET_BLOCK_evaluate (ctx, 53 GNUNET_BLOCK_evaluate (ctx, GNUNET_BLOCK_TYPE_FS_DBLOCK, &key, NULL, 0,
57 GNUNET_BLOCK_TYPE_FS_DBLOCK, 54 "bogus", 5, NULL, 0))
58 &key, NULL, 0, "bogus", 5, NULL, 0))
59 return 8; 55 return 8;
60 GNUNET_log_skip (0, GNUNET_YES); 56 GNUNET_log_skip (0, GNUNET_YES);
61 return 0; 57 return 0;
diff --git a/src/chat/chat.c b/src/chat/chat.c
index 1e90a6369..74dde678c 100644
--- a/src/chat/chat.c
+++ b/src/chat/chat.c
@@ -194,10 +194,10 @@ transmit_acknowledge_request (void *cls, size_t size, void *buf)
194 receipt->author = src->received_msg->sender; 194 receipt->author = src->received_msg->sender;
195 receipt->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT); 195 receipt->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT);
196 receipt->purpose.size = 196 receipt->purpose.size =
197 htonl (msg_size - 197 htonl (msg_size - sizeof (struct GNUNET_MessageHeader) -
198 sizeof (struct GNUNET_MessageHeader) -
199 sizeof (uint32_t) - sizeof (struct GNUNET_CRYPTO_RsaSignature)); 198 sizeof (uint32_t) - sizeof (struct GNUNET_CRYPTO_RsaSignature));
200 msg_len = ntohs (src->received_msg->header.size) - 199 msg_len =
200 ntohs (src->received_msg->header.size) -
201 sizeof (struct ReceiveNotificationMessage); 201 sizeof (struct ReceiveNotificationMessage);
202 GNUNET_CRYPTO_hash (&src->received_msg[1], msg_len, &receipt->content); 202 GNUNET_CRYPTO_hash (&src->received_msg[1], msg_len, &receipt->content);
203 GNUNET_assert (GNUNET_OK == 203 GNUNET_assert (GNUNET_OK ==
@@ -269,9 +269,9 @@ process_result (struct GNUNET_CHAT_Room *room,
269 if (GNUNET_NO == room->is_joined) 269 if (GNUNET_NO == room->is_joined)
270 { 270 {
271 GNUNET_CRYPTO_rsa_key_get_public (room->my_private_key, &pkey); 271 GNUNET_CRYPTO_rsa_key_get_public (room->my_private_key, &pkey);
272 if (0 == memcmp (&join_msg->public_key, 272 if (0 ==
273 &pkey, 273 memcmp (&join_msg->public_key, &pkey,
274 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))) 274 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
275 { 275 {
276 room->join_callback (room->join_callback_cls); 276 room->join_callback (room->join_callback_cls);
277 room->is_joined = GNUNET_YES; 277 room->is_joined = GNUNET_YES;
@@ -285,8 +285,8 @@ process_result (struct GNUNET_CHAT_Room *room,
285 } 285 }
286 } 286 }
287 else 287 else
288 room->member_list_callback (room->member_list_callback_cls, 288 room->member_list_callback (room->member_list_callback_cls, meta,
289 meta, &join_msg->public_key, 289 &join_msg->public_key,
290 ntohl (join_msg->msg_options)); 290 ntohl (join_msg->msg_options));
291 break; 291 break;
292 case GNUNET_MESSAGE_TYPE_CHAT_LEAVE_NOTIFICATION: 292 case GNUNET_MESSAGE_TYPE_CHAT_LEAVE_NOTIFICATION:
@@ -299,9 +299,8 @@ process_result (struct GNUNET_CHAT_Room *room,
299 return; 299 return;
300 } 300 }
301 leave_msg = (struct LeaveNotificationMessage *) reply; 301 leave_msg = (struct LeaveNotificationMessage *) reply;
302 room->member_list_callback (room->member_list_callback_cls, 302 room->member_list_callback (room->member_list_callback_cls, NULL,
303 NULL, &leave_msg->user, 303 &leave_msg->user, GNUNET_CHAT_MSG_OPTION_NONE);
304 GNUNET_CHAT_MSG_OPTION_NONE);
305 GNUNET_CRYPTO_hash (&leave_msg->user, 304 GNUNET_CRYPTO_hash (&leave_msg->user,
306 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 305 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
307 &id); 306 &id);
@@ -346,21 +345,20 @@ process_result (struct GNUNET_CHAT_Room *room,
346 msg_len = size - sizeof (struct ReceiveNotificationMessage); 345 msg_len = size - sizeof (struct ReceiveNotificationMessage);
347 if (0 != (ntohl (received_msg->msg_options) & GNUNET_CHAT_MSG_PRIVATE)) 346 if (0 != (ntohl (received_msg->msg_options) & GNUNET_CHAT_MSG_PRIVATE))
348 { 347 {
349 if (-1 == GNUNET_CRYPTO_rsa_decrypt (room->my_private_key, 348 if (-1 ==
350 &received_msg->encrypted_key, 349 GNUNET_CRYPTO_rsa_decrypt (room->my_private_key,
351 &key, 350 &received_msg->encrypted_key, &key,
352 sizeof (struct 351 sizeof (struct
353 GNUNET_CRYPTO_AesSessionKey))) 352 GNUNET_CRYPTO_AesSessionKey)))
354 { 353 {
355 GNUNET_break (0); 354 GNUNET_break (0);
356 return; 355 return;
357 } 356 }
358 msg_len = GNUNET_CRYPTO_aes_decrypt (&received_msg[1], 357 msg_len =
359 msg_len, 358 GNUNET_CRYPTO_aes_decrypt (&received_msg[1], msg_len, &key,
360 &key, 359 (const struct
361 (const struct 360 GNUNET_CRYPTO_AesInitializationVector *)
362 GNUNET_CRYPTO_AesInitializationVector 361 INITVALUE, decrypted_msg);
363 *) INITVALUE, decrypted_msg);
364 message_content = decrypted_msg; 362 message_content = decrypted_msg;
365 } 363 }
366 else 364 else
@@ -378,17 +376,15 @@ process_result (struct GNUNET_CHAT_Room *room,
378 { 376 {
379 pos = room->members; 377 pos = room->members;
380 while ((NULL != pos) && 378 while ((NULL != pos) &&
381 (0 != memcmp (&pos->id, 379 (0 !=
382 &received_msg->sender, sizeof (GNUNET_HashCode)))) 380 memcmp (&pos->id, &received_msg->sender,
381 sizeof (GNUNET_HashCode))))
383 pos = pos->next; 382 pos = pos->next;
384 GNUNET_assert (NULL != pos); 383 GNUNET_assert (NULL != pos);
385 sender = &received_msg->sender; 384 sender = &received_msg->sender;
386 meta = pos->meta; 385 meta = pos->meta;
387 } 386 }
388 room->message_callback (room->message_callback_cls, 387 room->message_callback (room->message_callback_cls, room, sender, meta,
389 room,
390 sender,
391 meta,
392 message_content, 388 message_content,
393 GNUNET_TIME_absolute_ntoh (received_msg->timestamp), 389 GNUNET_TIME_absolute_ntoh (received_msg->timestamp),
394 ntohl (received_msg->msg_options)); 390 ntohl (received_msg->msg_options));
@@ -406,15 +402,15 @@ process_result (struct GNUNET_CHAT_Room *room,
406 } 402 }
407 receipt = (struct ConfirmationReceiptMessage *) reply; 403 receipt = (struct ConfirmationReceiptMessage *) reply;
408 if (NULL != room->confirmation_callback) 404 if (NULL != room->confirmation_callback)
409 room->confirmation_callback (room->confirmation_cls, 405 room->confirmation_callback (room->confirmation_cls, room,
410 room,
411 ntohl (receipt->sequence_number), 406 ntohl (receipt->sequence_number),
412 GNUNET_TIME_absolute_ntoh 407 GNUNET_TIME_absolute_ntoh (receipt->
413 (receipt->timestamp), &receipt->target); 408 timestamp),
409 &receipt->target);
414 break; 410 break;
415 default: 411 default:
416 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 412 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Unknown message type: '%u'\n"),
417 _("Unknown message type: '%u'\n"), ntohs (reply->type)); 413 ntohs (reply->type));
418 GNUNET_break_op (0); 414 GNUNET_break_op (0);
419 break; 415 break;
420 } 416 }
@@ -448,9 +444,8 @@ receive_results (void *cls, const struct GNUNET_MessageHeader *msg)
448 if (NULL == chat_room->client) 444 if (NULL == chat_room->client)
449 return; /* fatal error */ 445 return; /* fatal error */
450 /* continue receiving */ 446 /* continue receiving */
451 GNUNET_CLIENT_receive (chat_room->client, 447 GNUNET_CLIENT_receive (chat_room->client, &receive_results, chat_room,
452 &receive_results, 448 GNUNET_TIME_UNIT_FOREVER_REL);
453 chat_room, GNUNET_TIME_UNIT_FOREVER_REL);
454} 449}
455 450
456 451
@@ -557,17 +552,15 @@ transmit_join_request (void *cls, size_t size, void *buf)
557 memcpy (room, chat_room->room_name, room_len); 552 memcpy (room, chat_room->room_name, room_len);
558 meta = &room[room_len]; 553 meta = &room[room_len];
559 if (GNUNET_SYSERR == 554 if (GNUNET_SYSERR ==
560 GNUNET_CONTAINER_meta_data_serialize (chat_room->member_info, 555 GNUNET_CONTAINER_meta_data_serialize (chat_room->member_info, &meta,
561 &meta,
562 meta_len, 556 meta_len,
563 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL)) 557 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL))
564 { 558 {
565 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not serialize metadata\n")); 559 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not serialize metadata\n"));
566 return 0; 560 return 0;
567 } 561 }
568 GNUNET_CLIENT_receive (chat_room->client, 562 GNUNET_CLIENT_receive (chat_room->client, &receive_results, chat_room,
569 &receive_results, 563 GNUNET_TIME_UNIT_FOREVER_REL);
570 chat_room, GNUNET_TIME_UNIT_FOREVER_REL);
571 return size_of_join; 564 return size_of_join;
572} 565}
573 566
@@ -580,15 +573,15 @@ rejoin_room (struct GNUNET_CHAT_Room *chat_room)
580{ 573{
581 size_t size_of_join; 574 size_t size_of_join;
582 575
583 size_of_join = sizeof (struct JoinRequestMessage) + 576 size_of_join =
577 sizeof (struct JoinRequestMessage) +
584 GNUNET_CONTAINER_meta_data_get_serialized_size (chat_room->member_info) + 578 GNUNET_CONTAINER_meta_data_get_serialized_size (chat_room->member_info) +
585 strlen (chat_room->room_name); 579 strlen (chat_room->room_name);
586 if (NULL == 580 if (NULL ==
587 GNUNET_CLIENT_notify_transmit_ready (chat_room->client, 581 GNUNET_CLIENT_notify_transmit_ready (chat_room->client, size_of_join,
588 size_of_join,
589 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 582 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
590 GNUNET_YES, 583 GNUNET_YES, &transmit_join_request,
591 &transmit_join_request, chat_room)) 584 chat_room))
592 return GNUNET_SYSERR; 585 return GNUNET_SYSERR;
593 return GNUNET_OK; 586 return GNUNET_OK;
594} 587}
@@ -603,8 +596,8 @@ GNUNET_CHAT_leave_room (struct GNUNET_CHAT_Room *chat_room)
603 struct MemberList *pos; 596 struct MemberList *pos;
604 597
605#if DEBUG_CHAT 598#if DEBUG_CHAT
606 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 599 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Leaving the room '%s'\n",
607 "Leaving the room '%s'\n", chat_room->room_name); 600 chat_room->room_name);
608#endif 601#endif
609 GNUNET_CLIENT_disconnect (chat_room->client, GNUNET_NO); 602 GNUNET_CLIENT_disconnect (chat_room->client, GNUNET_NO);
610 GNUNET_free (chat_room->room_name); 603 GNUNET_free (chat_room->room_name);
@@ -650,8 +643,7 @@ GNUNET_CHAT_join_room (const struct GNUNET_CONFIGURATION_Handle *cfg,
650 struct GNUNET_CONTAINER_MetaData *member_info, 643 struct GNUNET_CONTAINER_MetaData *member_info,
651 const char *room_name, 644 const char *room_name,
652 enum GNUNET_CHAT_MsgOptions msg_options, 645 enum GNUNET_CHAT_MsgOptions msg_options,
653 GNUNET_CHAT_JoinCallback joinCallback, 646 GNUNET_CHAT_JoinCallback joinCallback, void *join_cls,
654 void *join_cls,
655 GNUNET_CHAT_MessageCallback messageCallback, 647 GNUNET_CHAT_MessageCallback messageCallback,
656 void *message_cls, 648 void *message_cls,
657 GNUNET_CHAT_MemberListCallback memberCallback, 649 GNUNET_CHAT_MemberListCallback memberCallback,
@@ -778,8 +770,7 @@ transmit_send_request (void *cls, size_t size, void *buf)
778 msg_to_send->purpose.purpose = 770 msg_to_send->purpose.purpose =
779 htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE); 771 htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE);
780 msg_to_send->purpose.size = 772 msg_to_send->purpose.size =
781 htonl (msg_size - 773 htonl (msg_size - sizeof (struct GNUNET_MessageHeader) -
782 sizeof (struct GNUNET_MessageHeader) -
783 sizeof (struct GNUNET_CRYPTO_RsaSignature)); 774 sizeof (struct GNUNET_CRYPTO_RsaSignature));
784 GNUNET_assert (GNUNET_OK == 775 GNUNET_assert (GNUNET_OK ==
785 GNUNET_CRYPTO_rsa_sign (smc->chat_room->my_private_key, 776 GNUNET_CRYPTO_rsa_sign (smc->chat_room->my_private_key,
@@ -802,8 +793,7 @@ transmit_send_request (void *cls, size_t size, void *buf)
802 * @param sequence_number where to write the sequence id of the message 793 * @param sequence_number where to write the sequence id of the message
803 */ 794 */
804void 795void
805GNUNET_CHAT_send_message (struct GNUNET_CHAT_Room *room, 796GNUNET_CHAT_send_message (struct GNUNET_CHAT_Room *room, const char *message,
806 const char *message,
807 enum GNUNET_CHAT_MsgOptions options, 797 enum GNUNET_CHAT_MsgOptions options,
808 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded 798 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
809 *receiver, uint32_t * sequence_number) 799 *receiver, uint32_t * sequence_number)
@@ -824,8 +814,7 @@ GNUNET_CHAT_send_message (struct GNUNET_CHAT_Room *room,
824 smc->receiver = receiver; 814 smc->receiver = receiver;
825 smc->sequence_number = room->sequence_number; 815 smc->sequence_number = room->sequence_number;
826 msg_size = strlen (message) + sizeof (struct TransmitRequestMessage); 816 msg_size = strlen (message) + sizeof (struct TransmitRequestMessage);
827 GNUNET_CLIENT_notify_transmit_ready (room->client, 817 GNUNET_CLIENT_notify_transmit_ready (room->client, msg_size,
828 msg_size,
829 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 818 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
830 GNUNET_YES, &transmit_send_request, smc); 819 GNUNET_YES, &transmit_send_request, smc);
831} 820}
diff --git a/src/chat/gnunet-chat.c b/src/chat/gnunet-chat.c
index 6dba4dda5..c656d1cad 100644
--- a/src/chat/gnunet-chat.c
+++ b/src/chat/gnunet-chat.c
@@ -107,12 +107,10 @@ join_cb (void *cls)
107 * accept (but user is away), GNUNET_SYSERR to signal denied delivery 107 * accept (but user is away), GNUNET_SYSERR to signal denied delivery
108 */ 108 */
109static int 109static int
110receive_cb (void *cls, 110receive_cb (void *cls, struct GNUNET_CHAT_Room *room,
111 struct GNUNET_CHAT_Room *room,
112 const GNUNET_HashCode * sender, 111 const GNUNET_HashCode * sender,
113 const struct GNUNET_CONTAINER_MetaData *member_info, 112 const struct GNUNET_CONTAINER_MetaData *member_info,
114 const char *message, 113 const char *message, struct GNUNET_TIME_Absolute timestamp,
115 struct GNUNET_TIME_Absolute timestamp,
116 enum GNUNET_CHAT_MsgOptions options) 114 enum GNUNET_CHAT_MsgOptions options)
117{ 115{
118 char *nick; 116 char *nick;
@@ -183,8 +181,7 @@ receive_cb (void *cls,
183 * confirmations from anyone for this message 181 * confirmations from anyone for this message
184 */ 182 */
185static int 183static int
186confirmation_cb (void *cls, 184confirmation_cb (void *cls, struct GNUNET_CHAT_Room *room,
187 struct GNUNET_CHAT_Room *room,
188 uint32_t orig_seq_number, 185 uint32_t orig_seq_number,
189 struct GNUNET_TIME_Absolute timestamp, 186 struct GNUNET_TIME_Absolute timestamp,
190 const GNUNET_HashCode * receiver) 187 const GNUNET_HashCode * receiver)
@@ -208,8 +205,7 @@ confirmation_cb (void *cls,
208 * @return GNUNET_OK 205 * @return GNUNET_OK
209 */ 206 */
210static int 207static int
211member_list_cb (void *cls, 208member_list_cb (void *cls, const struct GNUNET_CONTAINER_MetaData *member_info,
212 const struct GNUNET_CONTAINER_MetaData *member_info,
213 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *member_id, 209 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *member_id,
214 enum GNUNET_CHAT_MsgOptions options) 210 enum GNUNET_CHAT_MsgOptions options)
215{ 211{
@@ -222,8 +218,10 @@ member_list_cb (void *cls,
222 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 218 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
223 &id); 219 &id);
224 nick = GNUNET_PSEUDONYM_id_to_name (cfg, &id); 220 nick = GNUNET_PSEUDONYM_id_to_name (cfg, &id);
225 fprintf (stdout, member_info != NULL 221 fprintf (stdout,
226 ? _("`%s' entered the room\n") : _("`%s' left the room\n"), nick); 222 member_info !=
223 NULL ? _("`%s' entered the room\n") : _("`%s' left the room\n"),
224 nick);
227 GNUNET_free (nick); 225 GNUNET_free (nick);
228 if (NULL != member_info) 226 if (NULL != member_info)
229 { 227 {
@@ -240,10 +238,9 @@ member_list_cb (void *cls,
240 prev = NULL; 238 prev = NULL;
241 pos = users; 239 pos = users;
242 while ((NULL != pos) && 240 while ((NULL != pos) &&
243 (0 != memcmp (&pos->pkey, 241 (0 !=
244 member_id, 242 memcmp (&pos->pkey, member_id,
245 sizeof (struct 243 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))))
246 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))))
247 { 244 {
248 prev = pos; 245 prev = pos;
249 pos = pos->next; 246 pos = pos->next;
@@ -277,15 +274,10 @@ do_join (const char *arg, const void *xtra)
277 free_user_list (); 274 free_user_list ();
278 GNUNET_free (room_name); 275 GNUNET_free (room_name);
279 room_name = GNUNET_strdup (arg); 276 room_name = GNUNET_strdup (arg);
280 room = GNUNET_CHAT_join_room (cfg, 277 room =
281 nickname, 278 GNUNET_CHAT_join_room (cfg, nickname, meta, room_name, -1, &join_cb, NULL,
282 meta, 279 &receive_cb, NULL, &member_list_cb, NULL,
283 room_name, 280 &confirmation_cb, NULL, &me);
284 -1,
285 &join_cb, NULL,
286 &receive_cb, NULL,
287 &member_list_cb, NULL,
288 &confirmation_cb, NULL, &me);
289 if (NULL == room) 281 if (NULL == room)
290 { 282 {
291 fprintf (stdout, _("Could not change username\n")); 283 fprintf (stdout, _("Could not change username\n"));
@@ -311,21 +303,13 @@ do_nick (const char *msg, const void *xtra)
311 GNUNET_CONTAINER_meta_data_destroy (meta); 303 GNUNET_CONTAINER_meta_data_destroy (meta);
312 nickname = GNUNET_strdup (msg); 304 nickname = GNUNET_strdup (msg);
313 meta = GNUNET_CONTAINER_meta_data_create (); 305 meta = GNUNET_CONTAINER_meta_data_create ();
314 GNUNET_CONTAINER_meta_data_insert (meta, 306 GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet>", EXTRACTOR_METATYPE_TITLE,
315 "<gnunet>", 307 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
316 EXTRACTOR_METATYPE_TITLE,
317 EXTRACTOR_METAFORMAT_UTF8,
318 "text/plain",
319 nickname, strlen (nickname) + 1); 308 nickname, strlen (nickname) + 1);
320 room = GNUNET_CHAT_join_room (cfg, 309 room =
321 nickname, 310 GNUNET_CHAT_join_room (cfg, nickname, meta, room_name, -1, &join_cb, NULL,
322 meta, 311 &receive_cb, NULL, &member_list_cb, NULL,
323 room_name, 312 &confirmation_cb, NULL, &me);
324 -1,
325 &join_cb, NULL,
326 &receive_cb, NULL,
327 &member_list_cb, NULL,
328 &confirmation_cb, NULL, &me);
329 if (NULL == room) 313 if (NULL == room)
330 { 314 {
331 fprintf (stdout, _("Could not change username\n")); 315 fprintf (stdout, _("Could not change username\n"));
@@ -411,8 +395,8 @@ do_send_pm (const char *msg, const void *xtra)
411 GNUNET_free (user); 395 GNUNET_free (user);
412 return GNUNET_OK; 396 return GNUNET_OK;
413 } 397 }
414 GNUNET_CHAT_send_message (room, 398 GNUNET_CHAT_send_message (room, msg, GNUNET_CHAT_MSG_PRIVATE, &pos->pkey,
415 msg, GNUNET_CHAT_MSG_PRIVATE, &pos->pkey, &seq); 399 &seq);
416 GNUNET_free (user); 400 GNUNET_free (user);
417 return GNUNET_OK; 401 return GNUNET_OK;
418} 402}
@@ -423,8 +407,8 @@ do_send_sig (const char *msg, const void *xtra)
423{ 407{
424 uint32_t seq; 408 uint32_t seq;
425 409
426 GNUNET_CHAT_send_message (room, 410 GNUNET_CHAT_send_message (room, msg, GNUNET_CHAT_MSG_AUTHENTICATED, NULL,
427 msg, GNUNET_CHAT_MSG_AUTHENTICATED, NULL, &seq); 411 &seq);
428 return GNUNET_OK; 412 return GNUNET_OK;
429} 413}
430 414
@@ -434,8 +418,8 @@ do_send_ack (const char *msg, const void *xtra)
434{ 418{
435 uint32_t seq; 419 uint32_t seq;
436 420
437 GNUNET_CHAT_send_message (room, 421 GNUNET_CHAT_send_message (room, msg, GNUNET_CHAT_MSG_ACKNOWLEDGED, NULL,
438 msg, GNUNET_CHAT_MSG_ACKNOWLEDGED, NULL, &seq); 422 &seq);
439 return GNUNET_OK; 423 return GNUNET_OK;
440} 424}
441 425
@@ -520,8 +504,8 @@ do_help (const char *args, const void *xtra)
520 int i; 504 int i;
521 505
522 i = 0; 506 i = 0;
523 while ((NULL != args) && 507 while ((NULL != args) && (0 != strlen (args)) &&
524 (0 != strlen (args)) && (commands[i].Action != &do_help)) 508 (commands[i].Action != &do_help))
525 { 509 {
526 if (0 == strncasecmp (&args[1], &commands[i].command[1], strlen (args) - 1)) 510 if (0 == strncasecmp (&args[1], &commands[i].command[1], strlen (args) - 1))
527 { 511 {
@@ -577,8 +561,9 @@ handle_command (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
577 goto next; 561 goto next;
578 i = 0; 562 i = 0;
579 while ((NULL != commands[i].command) && 563 while ((NULL != commands[i].command) &&
580 (0 != strncasecmp (commands[i].command, 564 (0 !=
581 message, strlen (commands[i].command)))) 565 strncasecmp (commands[i].command, message,
566 strlen (commands[i].command))))
582 i++; 567 i++;
583 if (GNUNET_OK != 568 if (GNUNET_OK !=
584 commands[i].Action (&message[strlen (commands[i].command)], NULL)) 569 commands[i].Action (&message[strlen (commands[i].command)], NULL))
@@ -606,9 +591,8 @@ out:
606 * @param c configuration 591 * @param c configuration
607 */ 592 */
608static void 593static void
609run (void *cls, 594run (void *cls, char *const *args, const char *cfgfile,
610 char *const *args, 595 const struct GNUNET_CONFIGURATION_Handle *c)
611 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
612{ 596{
613 GNUNET_HashCode me; 597 GNUNET_HashCode me;
614 char *my_name; 598 char *my_name;
@@ -624,21 +608,13 @@ run (void *cls,
624 if (NULL == room_name) 608 if (NULL == room_name)
625 room_name = GNUNET_strdup ("gnunet"); 609 room_name = GNUNET_strdup ("gnunet");
626 meta = GNUNET_CONTAINER_meta_data_create (); 610 meta = GNUNET_CONTAINER_meta_data_create ();
627 GNUNET_CONTAINER_meta_data_insert (meta, 611 GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet>", EXTRACTOR_METATYPE_TITLE,
628 "<gnunet>", 612 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
629 EXTRACTOR_METATYPE_TITLE,
630 EXTRACTOR_METAFORMAT_UTF8,
631 "text/plain",
632 nickname, strlen (nickname) + 1); 613 nickname, strlen (nickname) + 1);
633 room = GNUNET_CHAT_join_room (cfg, 614 room =
634 nickname, 615 GNUNET_CHAT_join_room (cfg, nickname, meta, room_name, -1, &join_cb, NULL,
635 meta, 616 &receive_cb, NULL, &member_list_cb, NULL,
636 room_name, 617 &confirmation_cb, NULL, &me);
637 -1,
638 &join_cb, NULL,
639 &receive_cb, NULL,
640 &member_list_cb, NULL,
641 &confirmation_cb, NULL, &me);
642 if (NULL == room) 618 if (NULL == room)
643 { 619 {
644 fprintf (stderr, _("Failed to join room `%s'\n"), room_name); 620 fprintf (stderr, _("Failed to join room `%s'\n"), room_name);
@@ -655,8 +631,8 @@ run (void *cls,
655 handle_cmd_task = 631 handle_cmd_task =
656 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, 632 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI,
657 &handle_command, NULL); 633 &handle_command, NULL);
658 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 634 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_stop_task,
659 &do_stop_task, NULL); 635 NULL);
660} 636}
661 637
662 638
@@ -688,11 +664,9 @@ main (int argc, char *const *argv)
688 fcntl (0, F_SETFL, flags); 664 fcntl (0, F_SETFL, flags);
689#endif 665#endif
690 return (GNUNET_OK == 666 return (GNUNET_OK ==
691 GNUNET_PROGRAM_run (argc, 667 GNUNET_PROGRAM_run (argc, argv, "gnunet-chat",
692 argv, 668 gettext_noop ("Join a chat on GNUnet."), options,
693 "gnunet-chat", 669 &run, NULL)) ? ret : 1;
694 gettext_noop ("Join a chat on GNUnet."),
695 options, &run, NULL)) ? ret : 1;
696} 670}
697 671
698/* end of gnunet-chat.c */ 672/* end of gnunet-chat.c */
diff --git a/src/chat/gnunet-service-chat.c b/src/chat/gnunet-service-chat.c
index 7afa18d68..e04d8d099 100644
--- a/src/chat/gnunet-service-chat.c
+++ b/src/chat/gnunet-service-chat.c
@@ -254,18 +254,15 @@ send_message_noficiation (void *cls, const GNUNET_HashCode * key, void *value)
254 254
255 GNUNET_PEER_resolve (cp->pid, &pid); 255 GNUNET_PEER_resolve (cp->pid, &pid);
256#if DEBUG_CHAT_SERVICE 256#if DEBUG_CHAT_SERVICE
257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message notification to `%s'\n",
258 "Sending message notification to `%s'\n", GNUNET_i2s (&pid)); 258 GNUNET_i2s (&pid));
259#endif 259#endif
260 my_msg = GNUNET_memdup (msg, ntohs (msg->header.size)); 260 my_msg = GNUNET_memdup (msg, ntohs (msg->header.size));
261 if (NULL == GNUNET_CORE_notify_transmit_ready (core, 261 if (NULL ==
262 GNUNET_NO, 262 GNUNET_CORE_notify_transmit_ready (core, GNUNET_NO, 1, MAX_TRANSMIT_DELAY,
263 1, 263 &pid, ntohs (msg->header.size),
264 MAX_TRANSMIT_DELAY, 264 &transmit_message_notification_to_peer,
265 &pid, 265 my_msg))
266 ntohs (msg->header.size),
267 &transmit_message_notification_to_peer,
268 my_msg))
269 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 266 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
270 _("Failed to queue a message notification\n")); 267 _("Failed to queue a message notification\n"));
271 return GNUNET_YES; 268 return GNUNET_YES;
@@ -281,8 +278,7 @@ send_message_noficiation (void *cls, const GNUNET_HashCode * key, void *value)
281 * @param message the actual message 278 * @param message the actual message
282 */ 279 */
283static void 280static void
284handle_transmit_request (void *cls, 281handle_transmit_request (void *cls, struct GNUNET_SERVER_Client *client,
285 struct GNUNET_SERVER_Client *client,
286 const struct GNUNET_MessageHeader *message) 282 const struct GNUNET_MessageHeader *message)
287{ 283{
288 static GNUNET_HashCode all_zeros; 284 static GNUNET_HashCode all_zeros;
@@ -316,12 +312,11 @@ handle_transmit_request (void *cls,
316 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting the message text\n"); 312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting the message text\n");
317#endif 313#endif
318 GNUNET_CRYPTO_aes_create_session_key (&key); 314 GNUNET_CRYPTO_aes_create_session_key (&key);
319 msg_len = GNUNET_CRYPTO_aes_encrypt (&trmsg[1], 315 msg_len =
320 msg_len, 316 GNUNET_CRYPTO_aes_encrypt (&trmsg[1], msg_len, &key,
321 &key, 317 (const struct
322 (const struct 318 GNUNET_CRYPTO_AesInitializationVector *)
323 GNUNET_CRYPTO_AesInitializationVector 319 INITVALUE, encrypted_msg);
324 *) INITVALUE, encrypted_msg);
325 if (-1 == msg_len) 320 if (-1 == msg_len)
326 { 321 {
327 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 322 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -332,8 +327,8 @@ handle_transmit_request (void *cls,
332 } 327 }
333 } 328 }
334 rnmsg = GNUNET_malloc (sizeof (struct ReceiveNotificationMessage) + msg_len); 329 rnmsg = GNUNET_malloc (sizeof (struct ReceiveNotificationMessage) + msg_len);
335 rnmsg->header.size = htons (sizeof (struct ReceiveNotificationMessage) + 330 rnmsg->header.size =
336 msg_len); 331 htons (sizeof (struct ReceiveNotificationMessage) + msg_len);
337 rnmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_MESSAGE_NOTIFICATION); 332 rnmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_MESSAGE_NOTIFICATION);
338 rnmsg->msg_options = trmsg->msg_options; 333 rnmsg->msg_options = trmsg->msg_options;
339 rnmsg->timestamp = trmsg->timestamp; 334 rnmsg->timestamp = trmsg->timestamp;
@@ -382,8 +377,8 @@ handle_transmit_request (void *cls,
382 memcpy (&rnmsg[1], encrypted_msg, msg_len); 377 memcpy (&rnmsg[1], encrypted_msg, msg_len);
383 target = client_list_head; 378 target = client_list_head;
384 while ((NULL != target) && 379 while ((NULL != target) &&
385 (0 != memcmp (&target->id, 380 (0 !=
386 &trmsg->target, sizeof (GNUNET_HashCode)))) 381 memcmp (&target->id, &trmsg->target, sizeof (GNUNET_HashCode))))
387 target = target->next; 382 target = target->next;
388 if (NULL == target) 383 if (NULL == target)
389 { 384 {
@@ -394,11 +389,10 @@ handle_transmit_request (void *cls,
394 GNUNET_free (rnmsg); 389 GNUNET_free (rnmsg);
395 return; 390 return;
396 } 391 }
397 if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_encrypt (&key, 392 if (GNUNET_SYSERR ==
398 sizeof (struct 393 GNUNET_CRYPTO_rsa_encrypt (&key,
399 GNUNET_CRYPTO_AesSessionKey), 394 sizeof (struct GNUNET_CRYPTO_AesSessionKey),
400 &target->public_key, 395 &target->public_key, &rnmsg->encrypted_key))
401 &rnmsg->encrypted_key))
402 { 396 {
403 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 397 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
404 "Could not encrypt the session key\n"); 398 "Could not encrypt the session key\n");
@@ -419,17 +413,14 @@ handle_transmit_request (void *cls,
419#endif 413#endif
420 while (NULL != pos) 414 while (NULL != pos)
421 { 415 {
422 if ((0 == strcmp (room, pos->room)) && 416 if ((0 == strcmp (room, pos->room)) && (NULL != pos->client) &&
423 (NULL != pos->client) && (pos->client != client)) 417 (pos->client != client))
424 { 418 {
425 if (((!is_priv) || 419 if (((!is_priv) ||
426 (0 == memcmp (&trmsg->target, 420 (0 == memcmp (&trmsg->target, &pos->id, sizeof (GNUNET_HashCode))))
427 &pos->id, 421 && (0 == (ntohl (trmsg->msg_options) & (~pos->msg_options))))
428 sizeof (GNUNET_HashCode)))) &&
429 (0 == (ntohl (trmsg->msg_options) & (~pos->msg_options))))
430 { 422 {
431 GNUNET_SERVER_notification_context_unicast (nc, 423 GNUNET_SERVER_notification_context_unicast (nc, pos->client,
432 pos->client,
433 &rnmsg->header, GNUNET_NO); 424 &rnmsg->header, GNUNET_NO);
434 } 425 }
435 } 426 }
@@ -442,8 +433,9 @@ handle_transmit_request (void *cls,
442 if (is_anon) 433 if (is_anon)
443 { 434 {
444 room_len = strlen (room); 435 room_len = strlen (room);
445 p2p_rnmsg = GNUNET_malloc (sizeof (struct P2PReceiveNotificationMessage) + 436 p2p_rnmsg =
446 msg_len + room_len); 437 GNUNET_malloc (sizeof (struct P2PReceiveNotificationMessage) + msg_len +
438 room_len);
447 p2p_rnmsg->header.size = 439 p2p_rnmsg->header.size =
448 htons (sizeof (struct P2PReceiveNotificationMessage) + msg_len + 440 htons (sizeof (struct P2PReceiveNotificationMessage) + msg_len +
449 room_len); 441 room_len);
@@ -453,15 +445,14 @@ handle_transmit_request (void *cls,
453 } 445 }
454 else 446 else
455 { 447 {
456 p2p_rnmsg = GNUNET_malloc (sizeof (struct P2PReceiveNotificationMessage) + 448 p2p_rnmsg =
457 msg_len); 449 GNUNET_malloc (sizeof (struct P2PReceiveNotificationMessage) + msg_len);
458 p2p_rnmsg->header.size = 450 p2p_rnmsg->header.size =
459 htons (sizeof (struct P2PReceiveNotificationMessage) + msg_len); 451 htons (sizeof (struct P2PReceiveNotificationMessage) + msg_len);
460 if (is_priv) 452 if (is_priv)
461 { 453 {
462 memcpy (&p2p_rnmsg[1], encrypted_msg, msg_len); 454 memcpy (&p2p_rnmsg[1], encrypted_msg, msg_len);
463 memcpy (&p2p_rnmsg->encrypted_key, 455 memcpy (&p2p_rnmsg->encrypted_key, &rnmsg->encrypted_key,
464 &rnmsg->encrypted_key,
465 sizeof (struct GNUNET_CRYPTO_RsaEncryptedData)); 456 sizeof (struct GNUNET_CRYPTO_RsaEncryptedData));
466 } 457 }
467 else 458 else
@@ -540,19 +531,17 @@ send_join_noficiation (void *cls, const GNUNET_HashCode * key, void *value)
540 531
541 GNUNET_PEER_resolve (cp->pid, &pid); 532 GNUNET_PEER_resolve (cp->pid, &pid);
542#if DEBUG_CHAT_SERVICE 533#if DEBUG_CHAT_SERVICE
543 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 534 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending join notification to `%s'\n",
544 "Sending join notification to `%s'\n", GNUNET_i2s (&pid)); 535 GNUNET_i2s (&pid));
545#endif 536#endif
546 msg_size = sizeof (struct P2PJoinNotificationMessage) + 537 msg_size =
547 strlen (entry->room) + entry->meta_len; 538 sizeof (struct P2PJoinNotificationMessage) + strlen (entry->room) +
548 if (NULL == GNUNET_CORE_notify_transmit_ready (core, 539 entry->meta_len;
549 GNUNET_NO, 540 if (NULL ==
550 1, 541 GNUNET_CORE_notify_transmit_ready (core, GNUNET_NO, 1, MAX_TRANSMIT_DELAY,
551 MAX_TRANSMIT_DELAY, 542 &pid, msg_size,
552 &pid, 543 &transmit_join_notification_to_peer,
553 msg_size, 544 entry))
554 &transmit_join_notification_to_peer,
555 entry))
556 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 545 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
557 _("Failed to queue a join notification\n")); 546 _("Failed to queue a join notification\n"));
558 return GNUNET_YES; 547 return GNUNET_YES;
@@ -568,8 +557,7 @@ send_join_noficiation (void *cls, const GNUNET_HashCode * key, void *value)
568 * @param message the actual message 557 * @param message the actual message
569 */ 558 */
570static void 559static void
571handle_join_request (void *cls, 560handle_join_request (void *cls, struct GNUNET_SERVER_Client *client,
572 struct GNUNET_SERVER_Client *client,
573 const struct GNUNET_MessageHeader *message) 561 const struct GNUNET_MessageHeader *message)
574{ 562{
575 const struct JoinRequestMessage *jrmsg; 563 const struct JoinRequestMessage *jrmsg;
@@ -644,8 +632,7 @@ handle_join_request (void *cls,
644 if (0 == strcmp (room_name, entry->room)) 632 if (0 == strcmp (room_name, entry->room))
645 { 633 {
646 if (NULL != entry->client) 634 if (NULL != entry->client)
647 GNUNET_SERVER_notification_context_unicast (nc, 635 GNUNET_SERVER_notification_context_unicast (nc, entry->client,
648 entry->client,
649 &jnmsg->header, GNUNET_NO); 636 &jnmsg->header, GNUNET_NO);
650 if (entry->client != client) 637 if (entry->client != client)
651 { 638 {
@@ -659,8 +646,7 @@ handle_join_request (void *cls,
659 entry_jnmsg->msg_options = entry->msg_options; 646 entry_jnmsg->msg_options = entry->msg_options;
660 entry_jnmsg->public_key = entry->public_key; 647 entry_jnmsg->public_key = entry->public_key;
661 memcpy (&entry_jnmsg[1], entry->member_info, entry->meta_len); 648 memcpy (&entry_jnmsg[1], entry->member_info, entry->meta_len);
662 GNUNET_SERVER_notification_context_unicast (nc, 649 GNUNET_SERVER_notification_context_unicast (nc, client,
663 client,
664 &entry_jnmsg->header, 650 &entry_jnmsg->header,
665 GNUNET_NO); 651 GNUNET_NO);
666 GNUNET_free (entry_jnmsg); 652 GNUNET_free (entry_jnmsg);
@@ -728,20 +714,17 @@ send_confirmation_receipt (void *cls, const GNUNET_HashCode * key, void *value)
728 714
729 GNUNET_PEER_resolve (cp->pid, &pid); 715 GNUNET_PEER_resolve (cp->pid, &pid);
730#if DEBUG_CHAT_SERVICE 716#if DEBUG_CHAT_SERVICE
731 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 717 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending confirmation receipt to `%s'\n",
732 "Sending confirmation receipt to `%s'\n", GNUNET_i2s (&pid)); 718 GNUNET_i2s (&pid));
733#endif 719#endif
734 msg_size = sizeof (struct P2PConfirmationReceiptMessage); 720 msg_size = sizeof (struct P2PConfirmationReceiptMessage);
735 my_receipt = GNUNET_memdup (receipt, 721 my_receipt =
736 sizeof (struct P2PConfirmationReceiptMessage)); 722 GNUNET_memdup (receipt, sizeof (struct P2PConfirmationReceiptMessage));
737 if (NULL == GNUNET_CORE_notify_transmit_ready (core, 723 if (NULL ==
738 GNUNET_YES, 724 GNUNET_CORE_notify_transmit_ready (core, GNUNET_YES, 1,
739 1, 725 MAX_TRANSMIT_DELAY, &pid, msg_size,
740 MAX_TRANSMIT_DELAY, 726 &transmit_confirmation_receipt_to_peer,
741 &pid, 727 my_receipt))
742 msg_size,
743 &transmit_confirmation_receipt_to_peer,
744 my_receipt))
745 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 728 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
746 _("Failed to queue a confirmation receipt\n")); 729 _("Failed to queue a confirmation receipt\n"));
747 return GNUNET_YES; 730 return GNUNET_YES;
@@ -758,8 +741,7 @@ send_confirmation_receipt (void *cls, const GNUNET_HashCode * key, void *value)
758 * @param message the actual message 741 * @param message the actual message
759 */ 742 */
760static void 743static void
761handle_acknowledge_request (void *cls, 744handle_acknowledge_request (void *cls, struct GNUNET_SERVER_Client *client,
762 struct GNUNET_SERVER_Client *client,
763 const struct GNUNET_MessageHeader *message) 745 const struct GNUNET_MessageHeader *message)
764{ 746{
765 const struct ConfirmationReceiptMessage *receipt; 747 const struct ConfirmationReceiptMessage *receipt;
@@ -772,8 +754,8 @@ handle_acknowledge_request (void *cls,
772 receipt = (const struct ConfirmationReceiptMessage *) message; 754 receipt = (const struct ConfirmationReceiptMessage *) message;
773 author = client_list_head; 755 author = client_list_head;
774 while ((NULL != author) && 756 while ((NULL != author) &&
775 (0 != memcmp (&receipt->author, 757 (0 !=
776 &author->id, sizeof (GNUNET_HashCode)))) 758 memcmp (&receipt->author, &author->id, sizeof (GNUNET_HashCode))))
777 author = author->next; 759 author = author->next;
778 if (NULL == author) 760 if (NULL == author)
779 { 761 {
@@ -785,8 +767,8 @@ handle_acknowledge_request (void *cls,
785 } 767 }
786 target = client_list_head; 768 target = client_list_head;
787 while ((NULL != target) && 769 while ((NULL != target) &&
788 (0 != memcmp (&receipt->target, 770 (0 !=
789 &target->id, sizeof (GNUNET_HashCode)))) 771 memcmp (&receipt->target, &target->id, sizeof (GNUNET_HashCode))))
790 target = target->next; 772 target = target->next;
791 if (NULL == target) 773 if (NULL == target)
792 { 774 {
@@ -831,8 +813,8 @@ handle_acknowledge_request (void *cls,
831#endif 813#endif
832 if (GNUNET_OK != 814 if (GNUNET_OK !=
833 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT, 815 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT,
834 &receipt->purpose, 816 &receipt->purpose, &receipt->signature,
835 &receipt->signature, &target->public_key)) 817 &target->public_key))
836 { 818 {
837 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 819 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
838 "Invalid signature of the receipt\n"); 820 "Invalid signature of the receipt\n");
@@ -909,13 +891,13 @@ send_leave_noficiation (void *cls, const GNUNET_HashCode * key, void *value)
909 891
910 GNUNET_PEER_resolve (cp->pid, &pid); 892 GNUNET_PEER_resolve (cp->pid, &pid);
911#if DEBUG_CHAT_SERVICE 893#if DEBUG_CHAT_SERVICE
912 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 894 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending leave notification to `%s'\n",
913 "Sending leave notification to `%s'\n", GNUNET_i2s (&pid)); 895 GNUNET_i2s (&pid));
914#endif 896#endif
915 msg_size = sizeof (struct P2PLeaveNotificationMessage); 897 msg_size = sizeof (struct P2PLeaveNotificationMessage);
916 public_key = GNUNET_memdup (&entry->public_key, 898 public_key =
917 sizeof (struct 899 GNUNET_memdup (&entry->public_key,
918 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 900 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
919 if (NULL == 901 if (NULL ==
920 GNUNET_CORE_notify_transmit_ready (core, GNUNET_YES, 1, 902 GNUNET_CORE_notify_transmit_ready (core, GNUNET_YES, 1,
921 MAX_TRANSMIT_DELAY, &pid, msg_size, 903 MAX_TRANSMIT_DELAY, &pid, msg_size,
@@ -975,8 +957,7 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
975 { 957 {
976 if ((0 == strcmp (pos->room, entry->room)) && (NULL != entry->client)) 958 if ((0 == strcmp (pos->room, entry->room)) && (NULL != entry->client))
977 { 959 {
978 GNUNET_SERVER_notification_context_unicast (nc, 960 GNUNET_SERVER_notification_context_unicast (nc, entry->client,
979 entry->client,
980 &lnmsg.header, GNUNET_NO); 961 &lnmsg.header, GNUNET_NO);
981 } 962 }
982 entry = entry->next; 963 entry = entry->next;
@@ -1093,8 +1074,7 @@ handle_p2p_join_notification (void *cls,
1093 { 1074 {
1094 if ((0 == strcmp (room_name, entry->room)) && (NULL != entry->client)) 1075 if ((0 == strcmp (room_name, entry->room)) && (NULL != entry->client))
1095 { 1076 {
1096 GNUNET_SERVER_notification_context_unicast (nc, 1077 GNUNET_SERVER_notification_context_unicast (nc, entry->client,
1097 entry->client,
1098 &jnmsg->header, GNUNET_NO); 1078 &jnmsg->header, GNUNET_NO);
1099 } 1079 }
1100 entry = entry->next; 1080 entry = entry->next;
@@ -1173,8 +1153,7 @@ handle_p2p_leave_notification (void *cls,
1173 { 1153 {
1174 if (0 == strcmp (pos->room, entry->room) && (NULL != entry->client)) 1154 if (0 == strcmp (pos->room, entry->room) && (NULL != entry->client))
1175 { 1155 {
1176 GNUNET_SERVER_notification_context_unicast (nc, 1156 GNUNET_SERVER_notification_context_unicast (nc, entry->client,
1177 entry->client,
1178 &lnmsg.header, GNUNET_NO); 1157 &lnmsg.header, GNUNET_NO);
1179 } 1158 }
1180 entry = entry->next; 1159 entry = entry->next;
@@ -1230,7 +1209,8 @@ handle_p2p_message_notification (void *cls,
1230 return GNUNET_SYSERR; 1209 return GNUNET_SYSERR;
1231 } 1210 }
1232 p2p_rnmsg = (const struct P2PReceiveNotificationMessage *) message; 1211 p2p_rnmsg = (const struct P2PReceiveNotificationMessage *) message;
1233 msg_len = ntohs (p2p_rnmsg->header.size) - 1212 msg_len =
1213 ntohs (p2p_rnmsg->header.size) -
1234 sizeof (struct P2PReceiveNotificationMessage); 1214 sizeof (struct P2PReceiveNotificationMessage);
1235 1215
1236 is_anon = (0 != (ntohl (p2p_rnmsg->msg_options) & GNUNET_CHAT_MSG_ANONYMOUS)); 1216 is_anon = (0 != (ntohl (p2p_rnmsg->msg_options) & GNUNET_CHAT_MSG_ANONYMOUS));
@@ -1263,8 +1243,8 @@ handle_p2p_message_notification (void *cls,
1263 { 1243 {
1264 sender = client_list_head; 1244 sender = client_list_head;
1265 while ((NULL != sender) && 1245 while ((NULL != sender) &&
1266 (0 != memcmp (&sender->id, 1246 (0 !=
1267 &p2p_rnmsg->sender, sizeof (GNUNET_HashCode)))) 1247 memcmp (&sender->id, &p2p_rnmsg->sender, sizeof (GNUNET_HashCode))))
1268 sender = sender->next; 1248 sender = sender->next;
1269 if (NULL == sender) 1249 if (NULL == sender)
1270 { 1250 {
@@ -1297,18 +1277,17 @@ handle_p2p_message_notification (void *cls,
1297 "Sending message to local room members\n"); 1277 "Sending message to local room members\n");
1298#endif 1278#endif
1299 rnmsg = GNUNET_malloc (sizeof (struct ReceiveNotificationMessage) + msg_len); 1279 rnmsg = GNUNET_malloc (sizeof (struct ReceiveNotificationMessage) + msg_len);
1300 rnmsg->header.size = htons (sizeof (struct ReceiveNotificationMessage) + 1280 rnmsg->header.size =
1301 msg_len); 1281 htons (sizeof (struct ReceiveNotificationMessage) + msg_len);
1302 rnmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_MESSAGE_NOTIFICATION); 1282 rnmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_MESSAGE_NOTIFICATION);
1303 rnmsg->msg_options = p2p_rnmsg->msg_options; 1283 rnmsg->msg_options = p2p_rnmsg->msg_options;
1304 rnmsg->sequence_number = p2p_rnmsg->sequence_number; 1284 rnmsg->sequence_number = p2p_rnmsg->sequence_number;
1305 rnmsg->reserved = htonl (0); 1285 rnmsg->reserved = htonl (0);
1306 rnmsg->timestamp = p2p_rnmsg->timestamp; 1286 rnmsg->timestamp = p2p_rnmsg->timestamp;
1307 is_priv = (0 != memcmp (&all_zeros, 1287 is_priv =
1308 &p2p_rnmsg->target, sizeof (GNUNET_HashCode))); 1288 (0 != memcmp (&all_zeros, &p2p_rnmsg->target, sizeof (GNUNET_HashCode)));
1309 if (is_priv) 1289 if (is_priv)
1310 memcpy (&rnmsg->encrypted_key, 1290 memcpy (&rnmsg->encrypted_key, &p2p_rnmsg->encrypted_key,
1311 &p2p_rnmsg->encrypted_key,
1312 sizeof (struct GNUNET_CRYPTO_RsaEncryptedData)); 1291 sizeof (struct GNUNET_CRYPTO_RsaEncryptedData));
1313 rnmsg->sender = p2p_rnmsg->sender; 1292 rnmsg->sender = p2p_rnmsg->sender;
1314 memcpy (&rnmsg[1], text, msg_len); 1293 memcpy (&rnmsg[1], text, msg_len);
@@ -1318,13 +1297,11 @@ handle_p2p_message_notification (void *cls,
1318 if ((0 == strcmp (room_name, pos->room)) && (NULL != pos->client)) 1297 if ((0 == strcmp (room_name, pos->room)) && (NULL != pos->client))
1319 { 1298 {
1320 if (((!is_priv) || 1299 if (((!is_priv) ||
1321 (0 == memcmp (&p2p_rnmsg->target, 1300 (0 ==
1322 &pos->id, 1301 memcmp (&p2p_rnmsg->target, &pos->id, sizeof (GNUNET_HashCode)))) &&
1323 sizeof (GNUNET_HashCode)))) &&
1324 (0 == (ntohl (p2p_rnmsg->msg_options) & (~pos->msg_options)))) 1302 (0 == (ntohl (p2p_rnmsg->msg_options) & (~pos->msg_options))))
1325 { 1303 {
1326 GNUNET_SERVER_notification_context_unicast (nc, 1304 GNUNET_SERVER_notification_context_unicast (nc, pos->client,
1327 pos->client,
1328 &rnmsg->header, GNUNET_NO); 1305 &rnmsg->header, GNUNET_NO);
1329 } 1306 }
1330 } 1307 }
@@ -1356,8 +1333,7 @@ handle_p2p_message_notification (void *cls,
1356 * GNUNET_SYSERR to close it (signal serious error) 1333 * GNUNET_SYSERR to close it (signal serious error)
1357 */ 1334 */
1358static int 1335static int
1359handle_p2p_sync_request (void *cls, 1336handle_p2p_sync_request (void *cls, const struct GNUNET_PeerIdentity *other,
1360 const struct GNUNET_PeerIdentity *other,
1361 const struct GNUNET_MessageHeader *message, 1337 const struct GNUNET_MessageHeader *message,
1362 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 1338 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1363{ 1339{
@@ -1373,14 +1349,11 @@ handle_p2p_sync_request (void *cls,
1373 entry = client_list_head; 1349 entry = client_list_head;
1374 while (NULL != entry) 1350 while (NULL != entry)
1375 { 1351 {
1376 msg_size = sizeof (struct P2PJoinNotificationMessage) + 1352 msg_size =
1377 strlen (entry->room) + entry->meta_len; 1353 sizeof (struct P2PJoinNotificationMessage) + strlen (entry->room) +
1378 th = GNUNET_CORE_notify_transmit_ready (core, 1354 entry->meta_len;
1379 GNUNET_NO, 1355 th = GNUNET_CORE_notify_transmit_ready (core, GNUNET_NO, 1,
1380 1, 1356 MAX_TRANSMIT_DELAY, other, msg_size,
1381 MAX_TRANSMIT_DELAY,
1382 other,
1383 msg_size,
1384 &transmit_join_notification_to_peer, 1357 &transmit_join_notification_to_peer,
1385 entry); 1358 entry);
1386 GNUNET_assert (NULL != th); 1359 GNUNET_assert (NULL != th);
@@ -1417,8 +1390,8 @@ handle_p2p_confirmation_receipt (void *cls,
1417 p2p_crmsg = (const struct P2PConfirmationReceiptMessage *) message; 1390 p2p_crmsg = (const struct P2PConfirmationReceiptMessage *) message;
1418 target = client_list_head; 1391 target = client_list_head;
1419 while ((NULL != target) && 1392 while ((NULL != target) &&
1420 (0 != memcmp (&target->id, 1393 (0 !=
1421 &p2p_crmsg->target, sizeof (GNUNET_HashCode)))) 1394 memcmp (&target->id, &p2p_crmsg->target, sizeof (GNUNET_HashCode))))
1422 target = target->next; 1395 target = target->next;
1423 if (NULL == target) 1396 if (NULL == target)
1424 { 1397 {
@@ -1441,8 +1414,8 @@ handle_p2p_confirmation_receipt (void *cls,
1441 target->rcpt_sequence_number = ntohl (p2p_crmsg->sequence_number); 1414 target->rcpt_sequence_number = ntohl (p2p_crmsg->sequence_number);
1442 author = client_list_head; 1415 author = client_list_head;
1443 while ((NULL != author) && 1416 while ((NULL != author) &&
1444 (0 != memcmp (&author->id, 1417 (0 !=
1445 &p2p_crmsg->author, sizeof (GNUNET_HashCode)))) 1418 memcmp (&author->id, &p2p_crmsg->author, sizeof (GNUNET_HashCode))))
1446 author = author->next; 1419 author = author->next;
1447 if (NULL == author) 1420 if (NULL == author)
1448 { 1421 {
@@ -1488,8 +1461,8 @@ handle_p2p_confirmation_receipt (void *cls,
1488 crmsg->content = p2p_crmsg->content; 1461 crmsg->content = p2p_crmsg->content;
1489 if (GNUNET_OK != 1462 if (GNUNET_OK !=
1490 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT, 1463 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT,
1491 &crmsg->purpose, 1464 &crmsg->purpose, &crmsg->signature,
1492 &crmsg->signature, &target->public_key)) 1465 &target->public_key))
1493 { 1466 {
1494 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1467 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1495 "Invalid signature of the receipt\n"); 1468 "Invalid signature of the receipt\n");
@@ -1501,8 +1474,7 @@ handle_p2p_confirmation_receipt (void *cls,
1501 "The author of the original message is a local client." 1474 "The author of the original message is a local client."
1502 " Sending receipt to the client\n"); 1475 " Sending receipt to the client\n");
1503#endif 1476#endif
1504 GNUNET_SERVER_notification_context_unicast (nc, 1477 GNUNET_SERVER_notification_context_unicast (nc, author->client,
1505 author->client,
1506 &crmsg->header, GNUNET_NO); 1478 &crmsg->header, GNUNET_NO);
1507 GNUNET_free (crmsg); 1479 GNUNET_free (crmsg);
1508 } 1480 }
@@ -1545,8 +1517,7 @@ transmit_sync_request_to_peer (void *cls, size_t size, void *buf)
1545 * @param atsi performance data 1517 * @param atsi performance data
1546 */ 1518 */
1547static void 1519static void
1548peer_connect_handler (void *cls, 1520peer_connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
1549 const struct GNUNET_PeerIdentity *peer,
1550 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 1521 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1551{ 1522{
1552 struct ConnectedPeer *cp; 1523 struct ConnectedPeer *cp;
@@ -1554,13 +1525,10 @@ peer_connect_handler (void *cls,
1554 1525
1555 if (0 == memcmp (peer, me, sizeof (struct GNUNET_PeerIdentity))) 1526 if (0 == memcmp (peer, me, sizeof (struct GNUNET_PeerIdentity)))
1556 return; 1527 return;
1557 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1528 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer connected: %s\n",
1558 "Peer connected: %s\n", GNUNET_i2s (peer)); 1529 GNUNET_i2s (peer));
1559 th = GNUNET_CORE_notify_transmit_ready (core, 1530 th = GNUNET_CORE_notify_transmit_ready (core, GNUNET_YES, 1,
1560 GNUNET_YES, 1531 MAX_TRANSMIT_DELAY, peer,
1561 1,
1562 MAX_TRANSMIT_DELAY,
1563 peer,
1564 sizeof (struct GNUNET_MessageHeader), 1532 sizeof (struct GNUNET_MessageHeader),
1565 &transmit_sync_request_to_peer, NULL); 1533 &transmit_sync_request_to_peer, NULL);
1566 GNUNET_assert (NULL != th); 1534 GNUNET_assert (NULL != th);
@@ -1574,8 +1542,7 @@ peer_connect_handler (void *cls,
1574 cp->pid = GNUNET_PEER_intern (peer); 1542 cp->pid = GNUNET_PEER_intern (peer);
1575 GNUNET_break (GNUNET_OK == 1543 GNUNET_break (GNUNET_OK ==
1576 GNUNET_CONTAINER_multihashmap_put (connected_peers, 1544 GNUNET_CONTAINER_multihashmap_put (connected_peers,
1577 &peer->hashPubKey, 1545 &peer->hashPubKey, cp,
1578 cp,
1579 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1546 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1580} 1547}
1581 1548
@@ -1619,8 +1586,8 @@ peer_disconnect_handler (void *cls, const struct GNUNET_PeerIdentity *peer)
1619 1586
1620 if (0 == memcmp (peer, me, sizeof (struct GNUNET_PeerIdentity))) 1587 if (0 == memcmp (peer, me, sizeof (struct GNUNET_PeerIdentity)))
1621 return; 1588 return;
1622 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1589 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer disconnected: %s\n",
1623 "Peer disconnected: %s\n", GNUNET_i2s (peer)); 1590 GNUNET_i2s (peer));
1624 clean_peer (NULL, (const GNUNET_HashCode *) peer, NULL); 1591 clean_peer (NULL, (const GNUNET_HashCode *) peer, NULL);
1625} 1592}
1626 1593
@@ -1677,8 +1644,7 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1677 * @param publicKey the public key of this peer 1644 * @param publicKey the public key of this peer
1678 */ 1645 */
1679static void 1646static void
1680core_init (void *cls, 1647core_init (void *cls, struct GNUNET_CORE_Handle *server,
1681 struct GNUNET_CORE_Handle *server,
1682 const struct GNUNET_PeerIdentity *my_identity, 1648 const struct GNUNET_PeerIdentity *my_identity,
1683 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) 1649 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
1684{ 1650{
@@ -1695,8 +1661,7 @@ core_init (void *cls,
1695 * @param c configuration to use 1661 * @param c configuration to use
1696 */ 1662 */
1697static void 1663static void
1698run (void *cls, 1664run (void *cls, struct GNUNET_SERVER_Handle *server,
1699 struct GNUNET_SERVER_Handle *server,
1700 const struct GNUNET_CONFIGURATION_Handle *c) 1665 const struct GNUNET_CONFIGURATION_Handle *c)
1701{ 1666{
1702 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 1667 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
@@ -1738,17 +1703,14 @@ run (void *cls,
1738 connected_peers = 1703 connected_peers =
1739 GNUNET_CONTAINER_multihashmap_create (EXPECTED_NEIGHBOUR_COUNT); 1704 GNUNET_CONTAINER_multihashmap_create (EXPECTED_NEIGHBOUR_COUNT);
1740 GNUNET_SERVER_add_handlers (server, handlers); 1705 GNUNET_SERVER_add_handlers (server, handlers);
1741 core = GNUNET_CORE_connect (cfg, 1706 core =
1742 QUEUE_SIZE, 1707 GNUNET_CORE_connect (cfg, QUEUE_SIZE, NULL, &core_init,
1743 NULL, 1708 &peer_connect_handler, &peer_disconnect_handler,
1744 &core_init, 1709 NULL, NULL, GNUNET_NO, NULL, GNUNET_NO,
1745 &peer_connect_handler, 1710 p2p_handlers);
1746 &peer_disconnect_handler,
1747 NULL,
1748 NULL, GNUNET_NO, NULL, GNUNET_NO, p2p_handlers);
1749 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); 1711 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
1750 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 1712 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
1751 &cleanup_task, NULL); 1713 NULL);
1752} 1714}
1753 1715
1754 1716
@@ -1763,10 +1725,8 @@ int
1763main (int argc, char *const *argv) 1725main (int argc, char *const *argv)
1764{ 1726{
1765 return (GNUNET_OK == 1727 return (GNUNET_OK ==
1766 GNUNET_SERVICE_run (argc, 1728 GNUNET_SERVICE_run (argc, argv, "chat", GNUNET_SERVICE_OPTION_NONE,
1767 argv, 1729 &run, NULL)) ? 0 : 1;
1768 "chat",
1769 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
1770} 1730}
1771 1731
1772/* end of gnunet-service-chat.c */ 1732/* end of gnunet-service-chat.c */
diff --git a/src/chat/test_chat.c b/src/chat/test_chat.c
index 0953a895b..7cf8b19cf 100644
--- a/src/chat/test_chat.c
+++ b/src/chat/test_chat.c
@@ -118,12 +118,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
118{ 118{
119 p->cfg = GNUNET_CONFIGURATION_create (); 119 p->cfg = GNUNET_CONFIGURATION_create ();
120#if START_ARM 120#if START_ARM
121 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 121 p->arm_proc =
122 "gnunet-service-arm", 122 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
123 "gnunet-service-arm",
123#if VERBOSE 124#if VERBOSE
124 "-L", "DEBUG", 125 "-L", "DEBUG",
125#endif 126#endif
126 "-c", cfgname, NULL); 127 "-c", cfgname, NULL);
127#endif 128#endif
128 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 129 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
129} 130}
@@ -137,8 +138,7 @@ stop_arm (struct PeerContext *p)
137 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 138 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
138 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 139 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
139 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 140 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
140 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 141 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
141 "ARM process %u stopped\n",
142 GNUNET_OS_process_get_pid (p->arm_proc)); 142 GNUNET_OS_process_get_pid (p->arm_proc));
143 GNUNET_OS_process_close (p->arm_proc); 143 GNUNET_OS_process_close (p->arm_proc);
144 p->arm_proc = NULL; 144 p->arm_proc = NULL;
@@ -196,8 +196,7 @@ join_cb (void *cls)
196 196
197 197
198static int 198static int
199member_list_cb (void *cls, 199member_list_cb (void *cls, const struct GNUNET_CONTAINER_MetaData *member_info,
200 const struct GNUNET_CONTAINER_MetaData *member_info,
201 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *member_id, 200 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *member_id,
202 enum GNUNET_CHAT_MsgOptions options) 201 enum GNUNET_CHAT_MsgOptions options)
203{ 202{
@@ -205,24 +204,19 @@ member_list_cb (void *cls,
205 GNUNET_HashCode sender; 204 GNUNET_HashCode sender;
206 205
207#if VERBOSE 206#if VERBOSE
208 printf ("%s - told that %s has %s\n", 207 printf ("%s - told that %s has %s\n", want->me,
209 want->me, 208 member_info ==
210 member_info == NULL ? NULL 209 NULL ? NULL : GNUNET_CONTAINER_meta_data_get_by_type (member_info,
211 : GNUNET_CONTAINER_meta_data_get_by_type (member_info, 210 EXTRACTOR_METATYPE_TITLE),
212 EXTRACTOR_METATYPE_TITLE),
213 member_info == NULL ? "left" : "joined"); 211 member_info == NULL ? "left" : "joined");
214#endif 212#endif
215 GNUNET_CRYPTO_hash (member_id, 213 GNUNET_CRYPTO_hash (member_id,
216 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 214 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
217 &sender); 215 &sender);
218 if ((0 == memcmp (&sender, want->sender, 216 if ((0 == memcmp (&sender, want->sender, sizeof (GNUNET_HashCode))) &&
219 sizeof (GNUNET_HashCode))) && 217 (((member_info == NULL) && (want->meta == NULL)) ||
220 (((member_info == NULL) && 218 ((member_info != NULL) && (want->meta != NULL) &&
221 (want->meta == NULL)) || 219 (GNUNET_CONTAINER_meta_data_test_equal (member_info, want->meta)))) &&
222 ((member_info != NULL) &&
223 (want->meta != NULL) &&
224 (GNUNET_CONTAINER_meta_data_test_equal (member_info,
225 want->meta)))) &&
226 (options == want->opt)) 220 (options == want->opt))
227 { 221 {
228 if (NULL != want->next_task) 222 if (NULL != want->next_task)
@@ -239,29 +233,24 @@ member_list_cb (void *cls,
239 233
240 234
241static int 235static int
242receive_cb (void *cls, 236receive_cb (void *cls, struct GNUNET_CHAT_Room *room,
243 struct GNUNET_CHAT_Room *room,
244 const GNUNET_HashCode * sender, 237 const GNUNET_HashCode * sender,
245 const struct GNUNET_CONTAINER_MetaData *meta, 238 const struct GNUNET_CONTAINER_MetaData *meta, const char *message,
246 const char *message,
247 struct GNUNET_TIME_Absolute timestamp, 239 struct GNUNET_TIME_Absolute timestamp,
248 enum GNUNET_CHAT_MsgOptions options) 240 enum GNUNET_CHAT_MsgOptions options)
249{ 241{
250 struct Wanted *want = cls; 242 struct Wanted *want = cls;
251 243
252#if VERBOSE 244#if VERBOSE
253 printf ("%s - told that %s said %s\n", 245 printf ("%s - told that %s said %s\n", want->me,
254 want->me, 246 meta == NULL ? NULL : GNUNET_CONTAINER_meta_data_get_by_type (meta,
255 meta == NULL ? NULL 247 EXTRACTOR_METATYPE_TITLE),
256 : GNUNET_CONTAINER_meta_data_get_by_type (meta,
257 EXTRACTOR_METATYPE_TITLE),
258 message); 248 message);
259#endif 249#endif
260 if ((0 == strcmp (message, want->msg)) && 250 if ((0 == strcmp (message, want->msg)) &&
261 (((sender == NULL) && (want->sender == NULL)) || 251 (((sender == NULL) && (want->sender == NULL)) ||
262 ((sender != NULL) && (want->sender != NULL) && 252 ((sender != NULL) && (want->sender != NULL) &&
263 (0 == memcmp (sender, want->sender, 253 (0 == memcmp (sender, want->sender, sizeof (GNUNET_HashCode))))) &&
264 sizeof (GNUNET_HashCode))))) &&
265 (GNUNET_CONTAINER_meta_data_test_equal (meta, want->meta)) && 254 (GNUNET_CONTAINER_meta_data_test_equal (meta, want->meta)) &&
266 (options == want->opt) && 255 (options == want->opt) &&
267 /* Not == since the library sets the actual timestamp, so it may be 256 /* Not == since the library sets the actual timestamp, so it may be
@@ -283,8 +272,7 @@ receive_cb (void *cls,
283 272
284 273
285static int 274static int
286confirmation_cb (void *cls, 275confirmation_cb (void *cls, struct GNUNET_CHAT_Room *room,
287 struct GNUNET_CHAT_Room *room,
288 uint32_t orig_seq_number, 276 uint32_t orig_seq_number,
289 struct GNUNET_TIME_Absolute timestamp, 277 struct GNUNET_TIME_Absolute timestamp,
290 const GNUNET_HashCode * receiver) 278 const GNUNET_HashCode * receiver)
@@ -292,14 +280,12 @@ confirmation_cb (void *cls,
292 struct Wanted *want = cls; 280 struct Wanted *want = cls;
293 281
294#if VERBOSE 282#if VERBOSE
295 printf ("%s - told that %s acknowledged message #%d\n", 283 printf ("%s - told that %s acknowledged message #%d\n", want->me,
296 want->me,
297 GNUNET_CONTAINER_meta_data_get_by_type (want->meta, 284 GNUNET_CONTAINER_meta_data_get_by_type (want->meta,
298 EXTRACTOR_METATYPE_TITLE), 285 EXTRACTOR_METATYPE_TITLE),
299 orig_seq_number); 286 orig_seq_number);
300#endif 287#endif
301 if ((0 == memcmp (receiver, want->sender, 288 if ((0 == memcmp (receiver, want->sender, sizeof (GNUNET_HashCode))) &&
302 sizeof (GNUNET_HashCode))) &&
303 (orig_seq_number == want->sequence_number) && 289 (orig_seq_number == want->sequence_number) &&
304 (timestamp.abs_value >= want->timestamp.abs_value)) 290 (timestamp.abs_value >= want->timestamp.abs_value))
305 { 291 {
@@ -390,9 +376,8 @@ send_to_alice (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
390 alice_wanted.timestamp = GNUNET_TIME_absolute_get (); 376 alice_wanted.timestamp = GNUNET_TIME_absolute_get ();
391 alice_wanted.next_task = &disconnect_bob; 377 alice_wanted.next_task = &disconnect_bob;
392 alice_wanted.next_task_cls = NULL; 378 alice_wanted.next_task_cls = NULL;
393 GNUNET_CHAT_send_message (bob_room, 379 GNUNET_CHAT_send_message (bob_room, "Hi Alice!", GNUNET_CHAT_MSG_OPTION_NONE,
394 "Hi Alice!", 380 NULL, NULL);
395 GNUNET_CHAT_MSG_OPTION_NONE, NULL, NULL);
396} 381}
397 382
398 383
@@ -476,11 +461,9 @@ join_bob_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
476 bob_wanted.next_task_cls = NULL; 461 bob_wanted.next_task_cls = NULL;
477 is_ready = GNUNET_NO; 462 is_ready = GNUNET_NO;
478 bob_room = 463 bob_room =
479 GNUNET_CHAT_join_room (is_p2p ? p2.cfg : p1.cfg, "bob", bob_meta, 464 GNUNET_CHAT_join_room (is_p2p ? p2.cfg : p1.cfg, "bob", bob_meta, "test",
480 "test", -1, 465 -1, &join_cb, &bob_wanted, &receive_cb,
481 &join_cb, &bob_wanted, 466 &bob_wanted, &member_list_cb, &bob_wanted,
482 &receive_cb, &bob_wanted,
483 &member_list_cb, &bob_wanted,
484 &confirmation_cb, &bob_wanted, &bob); 467 &confirmation_cb, &bob_wanted, &bob);
485 if (NULL == bob_room) 468 if (NULL == bob_room)
486 { 469 {
@@ -502,12 +485,10 @@ join_alice_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
502 alice_wanted.next_task = &join_bob_task; 485 alice_wanted.next_task = &join_bob_task;
503 alice_wanted.next_task_cls = NULL; 486 alice_wanted.next_task_cls = NULL;
504 alice_room = 487 alice_room =
505 GNUNET_CHAT_join_room (p1.cfg, "alice", alice_meta, 488 GNUNET_CHAT_join_room (p1.cfg, "alice", alice_meta, "test", -1, &join_cb,
506 "test", -1, 489 &alice_wanted, &receive_cb, &alice_wanted,
507 &join_cb, &alice_wanted, 490 &member_list_cb, &alice_wanted, &confirmation_cb,
508 &receive_cb, &alice_wanted, 491 &alice_wanted, &alice);
509 &member_list_cb, &alice_wanted,
510 &confirmation_cb, &alice_wanted, &alice);
511 if (NULL == alice_room) 492 if (NULL == alice_room)
512 { 493 {
513 GNUNET_SCHEDULER_cancel (kill_task); 494 GNUNET_SCHEDULER_cancel (kill_task);
@@ -518,9 +499,8 @@ join_alice_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
518 499
519 500
520static void 501static void
521run (void *cls, 502run (void *cls, char *const *args, const char *cfgfile,
522 char *const *args, 503 const struct GNUNET_CONFIGURATION_Handle *cfg)
523 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
524{ 504{
525 if (is_p2p) 505 if (is_p2p)
526 { 506 {
@@ -535,18 +515,15 @@ run (void *cls,
535 alice_wanted.me = "Alice"; 515 alice_wanted.me = "Alice";
536 bob_wanted.me = "Bob"; 516 bob_wanted.me = "Bob";
537 alice_meta = GNUNET_CONTAINER_meta_data_create (); 517 alice_meta = GNUNET_CONTAINER_meta_data_create ();
538 GNUNET_CONTAINER_meta_data_insert (alice_meta, 518 GNUNET_CONTAINER_meta_data_insert (alice_meta, "<gnunet>",
539 "<gnunet>",
540 EXTRACTOR_METATYPE_TITLE, 519 EXTRACTOR_METATYPE_TITLE,
541 EXTRACTOR_METAFORMAT_UTF8, 520 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
542 "text/plain",
543 "Alice", strlen ("Alice") + 1); 521 "Alice", strlen ("Alice") + 1);
544 bob_meta = GNUNET_CONTAINER_meta_data_create (); 522 bob_meta = GNUNET_CONTAINER_meta_data_create ();
545 GNUNET_CONTAINER_meta_data_insert (bob_meta, 523 GNUNET_CONTAINER_meta_data_insert (bob_meta, "<gnunet>",
546 "<gnunet>",
547 EXTRACTOR_METATYPE_TITLE, 524 EXTRACTOR_METATYPE_TITLE,
548 EXTRACTOR_METAFORMAT_UTF8, 525 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
549 "text/plain", "Bob", strlen ("Bob") + 1); 526 "Bob", strlen ("Bob") + 1);
550 kill_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_kill, NULL); 527 kill_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_kill, NULL);
551 GNUNET_SCHEDULER_add_now (&join_alice_task, NULL); 528 GNUNET_SCHEDULER_add_now (&join_alice_task, NULL);
552} 529}
@@ -591,8 +568,8 @@ main (int argc, char *argv[])
591 { 568 {
592 is_auth = GNUNET_YES; 569 is_auth = GNUNET_YES;
593 } 570 }
594 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 571 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
595 argvx, "test-chat", "nohelp", options, &run, NULL); 572 "test-chat", "nohelp", options, &run, NULL);
596 stop_arm (&p1); 573 stop_arm (&p1);
597 GNUNET_CONTAINER_meta_data_destroy (alice_meta); 574 GNUNET_CONTAINER_meta_data_destroy (alice_meta);
598 GNUNET_CONTAINER_meta_data_destroy (bob_meta); 575 GNUNET_CONTAINER_meta_data_destroy (bob_meta);
diff --git a/src/chat/test_chat_private.c b/src/chat/test_chat_private.c
index 507e333c9..acec5bcf0 100644
--- a/src/chat/test_chat_private.c
+++ b/src/chat/test_chat_private.c
@@ -132,12 +132,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
132{ 132{
133 p->cfg = GNUNET_CONFIGURATION_create (); 133 p->cfg = GNUNET_CONFIGURATION_create ();
134#if START_ARM 134#if START_ARM
135 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 135 p->arm_proc =
136 "gnunet-service-arm", 136 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
137 "gnunet-service-arm",
137#if VERBOSE 138#if VERBOSE
138 "-L", "DEBUG", 139 "-L", "DEBUG",
139#endif 140#endif
140 "-c", cfgname, NULL); 141 "-c", cfgname, NULL);
141#endif 142#endif
142 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 143 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
143} 144}
@@ -151,8 +152,7 @@ stop_arm (struct PeerContext *p)
151 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 152 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
152 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 153 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
153 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 154 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
155 "ARM process %u stopped\n",
156 GNUNET_OS_process_get_pid (p->arm_proc)); 156 GNUNET_OS_process_get_pid (p->arm_proc));
157 GNUNET_OS_process_close (p->arm_proc); 157 GNUNET_OS_process_close (p->arm_proc);
158 p->arm_proc = NULL; 158 p->arm_proc = NULL;
@@ -215,8 +215,7 @@ join_cb (void *cls)
215 215
216 216
217static int 217static int
218member_list_cb (void *cls, 218member_list_cb (void *cls, const struct GNUNET_CONTAINER_MetaData *member_info,
219 const struct GNUNET_CONTAINER_MetaData *member_info,
220 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *member_id, 219 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *member_id,
221 enum GNUNET_CHAT_MsgOptions options) 220 enum GNUNET_CHAT_MsgOptions options)
222{ 221{
@@ -224,11 +223,10 @@ member_list_cb (void *cls,
224 GNUNET_HashCode sender; 223 GNUNET_HashCode sender;
225 224
226#if VERBOSE 225#if VERBOSE
227 printf ("%s - told that %s has %s\n", 226 printf ("%s - told that %s has %s\n", want->me,
228 want->me, 227 member_info ==
229 member_info == NULL ? NULL 228 NULL ? NULL : GNUNET_CONTAINER_meta_data_get_by_type (member_info,
230 : GNUNET_CONTAINER_meta_data_get_by_type (member_info, 229 EXTRACTOR_METATYPE_TITLE),
231 EXTRACTOR_METATYPE_TITLE),
232 member_info == NULL ? "left" : "joined"); 230 member_info == NULL ? "left" : "joined");
233#endif 231#endif
234 GNUNET_CRYPTO_hash (member_id, 232 GNUNET_CRYPTO_hash (member_id,
@@ -241,12 +239,10 @@ member_list_cb (void *cls,
241 (((member_info == NULL) && (want->meta == NULL)) || 239 (((member_info == NULL) && (want->meta == NULL)) ||
242 ((member_info != NULL) && 240 ((member_info != NULL) &&
243 (((want->meta != NULL) && 241 (((want->meta != NULL) &&
244 GNUNET_CONTAINER_meta_data_test_equal (member_info, 242 GNUNET_CONTAINER_meta_data_test_equal (member_info, want->meta)) ||
245 want->meta)) ||
246 ((want->meta2 != NULL) && 243 ((want->meta2 != NULL) &&
247 GNUNET_CONTAINER_meta_data_test_equal (member_info, 244 GNUNET_CONTAINER_meta_data_test_equal (member_info, want->meta2)))))
248 want->meta2))))) && 245 && (options == want->opt))
249 (options == want->opt))
250 { 246 {
251 /* remember Bob's public key, we need it to send private message */ 247 /* remember Bob's public key, we need it to send private message */
252 if (NULL == bob_public_key && 248 if (NULL == bob_public_key &&
@@ -280,30 +276,25 @@ member_list_cb (void *cls,
280 276
281 277
282static int 278static int
283receive_cb (void *cls, 279receive_cb (void *cls, struct GNUNET_CHAT_Room *room,
284 struct GNUNET_CHAT_Room *room,
285 const GNUNET_HashCode * sender, 280 const GNUNET_HashCode * sender,
286 const struct GNUNET_CONTAINER_MetaData *meta, 281 const struct GNUNET_CONTAINER_MetaData *meta, const char *message,
287 const char *message,
288 struct GNUNET_TIME_Absolute timestamp, 282 struct GNUNET_TIME_Absolute timestamp,
289 enum GNUNET_CHAT_MsgOptions options) 283 enum GNUNET_CHAT_MsgOptions options)
290{ 284{
291 struct Wanted *want = cls; 285 struct Wanted *want = cls;
292 286
293#if VERBOSE 287#if VERBOSE
294 printf ("%s - told that %s said '%s'\n", 288 printf ("%s - told that %s said '%s'\n", want->me,
295 want->me, 289 meta == NULL ? NULL : GNUNET_CONTAINER_meta_data_get_by_type (meta,
296 meta == NULL ? NULL 290 EXTRACTOR_METATYPE_TITLE),
297 : GNUNET_CONTAINER_meta_data_get_by_type (meta,
298 EXTRACTOR_METATYPE_TITLE),
299 message); 291 message);
300#endif 292#endif
301 293
302 if ((want->msg != NULL) && (0 == strcmp (message, want->msg)) && 294 if ((want->msg != NULL) && (0 == strcmp (message, want->msg)) &&
303 (((sender == NULL) && (want->sender == NULL)) || 295 (((sender == NULL) && (want->sender == NULL)) ||
304 ((sender != NULL) && (want->sender != NULL) && 296 ((sender != NULL) && (want->sender != NULL) &&
305 (0 == memcmp (sender, want->sender, 297 (0 == memcmp (sender, want->sender, sizeof (GNUNET_HashCode))))) &&
306 sizeof (GNUNET_HashCode))))) &&
307 (GNUNET_CONTAINER_meta_data_test_equal (meta, want->meta)) && 298 (GNUNET_CONTAINER_meta_data_test_equal (meta, want->meta)) &&
308 (options == want->opt) && 299 (options == want->opt) &&
309 /* Not == since the library sets the actual timestamp, so it may be 300 /* Not == since the library sets the actual timestamp, so it may be
@@ -444,12 +435,11 @@ send_from_alice_to_bob (void *cls,
444 carol_wanted.opt = 0; 435 carol_wanted.opt = 0;
445 carol_wanted.next_task = NULL; 436 carol_wanted.next_task = NULL;
446 carol_wanted.next_task_cls = NULL; 437 carol_wanted.next_task_cls = NULL;
447 GNUNET_CHAT_send_message (alice_room, 438 GNUNET_CHAT_send_message (alice_room, "Hi Bob!", GNUNET_CHAT_MSG_PRIVATE,
448 "Hi Bob!", 439 bob_public_key, &seq);
449 GNUNET_CHAT_MSG_PRIVATE, bob_public_key, &seq); 440 finish_task =
450 finish_task = GNUNET_SCHEDULER_add_delayed (PM_TIMEOUT, 441 GNUNET_SCHEDULER_add_delayed (PM_TIMEOUT, &wait_until_all_ready,
451 &wait_until_all_ready, 442 &disconnect_carol);
452 &disconnect_carol);
453} 443}
454 444
455 445
@@ -508,10 +498,8 @@ join_carol_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
508 carol_wanted.next_task_cls = NULL; 498 carol_wanted.next_task_cls = NULL;
509 carol_room = 499 carol_room =
510 GNUNET_CHAT_join_room (is_p2p ? p3.cfg : p1.cfg, "carol", carol_meta, 500 GNUNET_CHAT_join_room (is_p2p ? p3.cfg : p1.cfg, "carol", carol_meta,
511 "test", -1, 501 "test", -1, &join_cb, &carol_wanted, &receive_cb,
512 &join_cb, &carol_wanted, 502 &carol_wanted, &member_list_cb, &carol_wanted,
513 &receive_cb, &carol_wanted,
514 &member_list_cb, &carol_wanted,
515 NULL, NULL, &carol); 503 NULL, NULL, &carol);
516 if (NULL == carol_room) 504 if (NULL == carol_room)
517 { 505 {
@@ -543,11 +531,10 @@ join_bob_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
543 bob_wanted.next_task_cls = NULL; 531 bob_wanted.next_task_cls = NULL;
544 bob_ready = GNUNET_NO; 532 bob_ready = GNUNET_NO;
545 bob_room = 533 bob_room =
546 GNUNET_CHAT_join_room (is_p2p ? p2.cfg : p1.cfg, "bob", bob_meta, 534 GNUNET_CHAT_join_room (is_p2p ? p2.cfg : p1.cfg, "bob", bob_meta, "test",
547 "test", -1, 535 -1, &join_cb, &bob_wanted, &receive_cb,
548 &join_cb, &bob_wanted, 536 &bob_wanted, &member_list_cb, &bob_wanted, NULL,
549 &receive_cb, &bob_wanted, 537 NULL, &bob);
550 &member_list_cb, &bob_wanted, NULL, NULL, &bob);
551 if (NULL == bob_room) 538 if (NULL == bob_room)
552 { 539 {
553 GNUNET_SCHEDULER_cancel (kill_task); 540 GNUNET_SCHEDULER_cancel (kill_task);
@@ -568,12 +555,10 @@ join_alice_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
568 alice_wanted.next_task = &join_bob_task; 555 alice_wanted.next_task = &join_bob_task;
569 alice_wanted.next_task_cls = NULL; 556 alice_wanted.next_task_cls = NULL;
570 alice_room = 557 alice_room =
571 GNUNET_CHAT_join_room (p1.cfg, "alice", alice_meta, 558 GNUNET_CHAT_join_room (p1.cfg, "alice", alice_meta, "test", -1, &join_cb,
572 "test", -1, 559 &alice_wanted, &receive_cb, &alice_wanted,
573 &join_cb, &alice_wanted, 560 &member_list_cb, &alice_wanted, NULL, NULL,
574 &receive_cb, &alice_wanted, 561 &alice);
575 &member_list_cb, &alice_wanted,
576 NULL, NULL, &alice);
577 if (NULL == alice_room) 562 if (NULL == alice_room)
578 { 563 {
579 GNUNET_SCHEDULER_cancel (kill_task); 564 GNUNET_SCHEDULER_cancel (kill_task);
@@ -584,9 +569,8 @@ join_alice_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
584 569
585 570
586static void 571static void
587run (void *cls, 572run (void *cls, char *const *args, const char *cfgfile,
588 char *const *args, 573 const struct GNUNET_CONFIGURATION_Handle *cfg)
589 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
590{ 574{
591 if (is_p2p) 575 if (is_p2p)
592 { 576 {
@@ -604,24 +588,19 @@ run (void *cls,
604 bob_wanted.me = "Bob"; 588 bob_wanted.me = "Bob";
605 carol_wanted.me = "Carol"; 589 carol_wanted.me = "Carol";
606 alice_meta = GNUNET_CONTAINER_meta_data_create (); 590 alice_meta = GNUNET_CONTAINER_meta_data_create ();
607 GNUNET_CONTAINER_meta_data_insert (alice_meta, 591 GNUNET_CONTAINER_meta_data_insert (alice_meta, "<gnunet>",
608 "<gnunet>",
609 EXTRACTOR_METATYPE_TITLE, 592 EXTRACTOR_METATYPE_TITLE,
610 EXTRACTOR_METAFORMAT_UTF8, 593 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
611 "text/plain",
612 "Alice", strlen ("Alice") + 1); 594 "Alice", strlen ("Alice") + 1);
613 bob_meta = GNUNET_CONTAINER_meta_data_create (); 595 bob_meta = GNUNET_CONTAINER_meta_data_create ();
614 GNUNET_CONTAINER_meta_data_insert (bob_meta, 596 GNUNET_CONTAINER_meta_data_insert (bob_meta, "<gnunet>",
615 "<gnunet>",
616 EXTRACTOR_METATYPE_TITLE, 597 EXTRACTOR_METATYPE_TITLE,
617 EXTRACTOR_METAFORMAT_UTF8, 598 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
618 "text/plain", "Bob", strlen ("Bob") + 1); 599 "Bob", strlen ("Bob") + 1);
619 carol_meta = GNUNET_CONTAINER_meta_data_create (); 600 carol_meta = GNUNET_CONTAINER_meta_data_create ();
620 GNUNET_CONTAINER_meta_data_insert (carol_meta, 601 GNUNET_CONTAINER_meta_data_insert (carol_meta, "<gnunet>",
621 "<gnunet>",
622 EXTRACTOR_METATYPE_TITLE, 602 EXTRACTOR_METATYPE_TITLE,
623 EXTRACTOR_METAFORMAT_UTF8, 603 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
624 "text/plain",
625 "Carol", strlen ("Carol") + 1); 604 "Carol", strlen ("Carol") + 1);
626 kill_task = GNUNET_SCHEDULER_add_delayed (KILL_TIMEOUT, &timeout_kill, NULL); 605 kill_task = GNUNET_SCHEDULER_add_delayed (KILL_TIMEOUT, &timeout_kill, NULL);
627 GNUNET_SCHEDULER_add_now (&join_alice_task, NULL); 606 GNUNET_SCHEDULER_add_now (&join_alice_task, NULL);
@@ -655,8 +634,8 @@ main (int argc, char *argv[])
655 { 634 {
656 is_p2p = GNUNET_YES; 635 is_p2p = GNUNET_YES;
657 } 636 }
658 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 637 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
659 argvx, "test-chat", "nohelp", options, &run, NULL); 638 "test-chat", "nohelp", options, &run, NULL);
660 stop_arm (&p1); 639 stop_arm (&p1);
661 GNUNET_CONTAINER_meta_data_destroy (alice_meta); 640 GNUNET_CONTAINER_meta_data_destroy (alice_meta);
662 GNUNET_CONTAINER_meta_data_destroy (bob_meta); 641 GNUNET_CONTAINER_meta_data_destroy (bob_meta);
diff --git a/src/core/core_api.c b/src/core/core_api.c
index c6fcc0b47..5ec48d68c 100644
--- a/src/core/core_api.c
+++ b/src/core/core_api.c
@@ -404,8 +404,8 @@ reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
404 * @return GNUNET_YES (continue) 404 * @return GNUNET_YES (continue)
405 */ 405 */
406static int 406static int
407disconnect_and_free_peer_entry (void *cls, 407disconnect_and_free_peer_entry (void *cls, const GNUNET_HashCode * key,
408 const GNUNET_HashCode * key, void *value) 408 void *value)
409{ 409{
410 static struct GNUNET_BANDWIDTH_Value32NBO zero; 410 static struct GNUNET_BANDWIDTH_Value32NBO zero;
411 struct GNUNET_CORE_Handle *h = cls; 411 struct GNUNET_CORE_Handle *h = cls;
@@ -485,8 +485,8 @@ reconnect_later (struct GNUNET_CORE_Handle *h)
485 } 485 }
486 h->currently_down = GNUNET_YES; 486 h->currently_down = GNUNET_YES;
487 GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK); 487 GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK);
488 h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->retry_backoff, 488 h->reconnect_task =
489 &reconnect_task, h); 489 GNUNET_SCHEDULER_add_delayed (h->retry_backoff, &reconnect_task, h);
490 while (NULL != (cm = h->control_pending_head)) 490 while (NULL != (cm = h->control_pending_head))
491 { 491 {
492 GNUNET_CONTAINER_DLL_remove (h->control_pending_head, 492 GNUNET_CONTAINER_DLL_remove (h->control_pending_head,
@@ -502,8 +502,8 @@ reconnect_later (struct GNUNET_CORE_Handle *h)
502 while (NULL != (pr = h->ready_peer_head)) 502 while (NULL != (pr = h->ready_peer_head))
503 GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr); 503 GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr);
504 GNUNET_assert (h->control_pending_head == NULL); 504 GNUNET_assert (h->control_pending_head == NULL);
505 h->retry_backoff = GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, 505 h->retry_backoff =
506 h->retry_backoff); 506 GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, h->retry_backoff);
507 h->retry_backoff = GNUNET_TIME_relative_multiply (h->retry_backoff, 2); 507 h->retry_backoff = GNUNET_TIME_relative_multiply (h->retry_backoff, 2);
508} 508}
509 509
@@ -515,8 +515,8 @@ reconnect_later (struct GNUNET_CORE_Handle *h)
515 * @param h core handle 515 * @param h core handle
516 * @param ignore_currently_down transmit message even if not initialized? 516 * @param ignore_currently_down transmit message even if not initialized?
517 */ 517 */
518static void 518static void trigger_next_request (struct GNUNET_CORE_Handle *h,
519trigger_next_request (struct GNUNET_CORE_Handle *h, int ignore_currently_down); 519 int ignore_currently_down);
520 520
521 521
522/** 522/**
@@ -526,8 +526,9 @@ trigger_next_request (struct GNUNET_CORE_Handle *h, int ignore_currently_down);
526 * @param cls the transmit handle of the request that timed out 526 * @param cls the transmit handle of the request that timed out
527 * @param tc context, can be NULL (!) 527 * @param tc context, can be NULL (!)
528 */ 528 */
529static void 529static void transmission_timeout (void *cls,
530transmission_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 530 const struct GNUNET_SCHEDULER_TaskContext
531 *tc);
531 532
532 533
533/** 534/**
@@ -702,8 +703,9 @@ transmit_message (void *cls, size_t size, void *buf)
702 sm->peer = pr->peer; 703 sm->peer = pr->peer;
703 sm->cork = htonl ((uint32_t) th->cork); 704 sm->cork = htonl ((uint32_t) th->cork);
704 sm->reserved = htonl (0); 705 sm->reserved = htonl (0);
705 ret = th->get_message (th->get_message_cls, 706 ret =
706 size - sizeof (struct SendMessage), &sm[1]); 707 th->get_message (th->get_message_cls,
708 size - sizeof (struct SendMessage), &sm[1]);
707 709
708#if DEBUG_CORE 710#if DEBUG_CORE
709 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -774,8 +776,8 @@ trigger_next_request (struct GNUNET_CORE_Handle *h, int ignore_currently_down)
774 } 776 }
775 if (h->control_pending_head != NULL) 777 if (h->control_pending_head != NULL)
776 msize = 778 msize =
777 ntohs (((struct GNUNET_MessageHeader *) &h-> 779 ntohs (((struct GNUNET_MessageHeader *) &h->control_pending_head[1])->
778 control_pending_head[1])->size); 780 size);
779 else if (h->ready_peer_head != NULL) 781 else if (h->ready_peer_head != NULL)
780 msize = 782 msize =
781 h->ready_peer_head->pending_head->msize + sizeof (struct SendMessage); 783 h->ready_peer_head->pending_head->msize + sizeof (struct SendMessage);
@@ -787,11 +789,10 @@ trigger_next_request (struct GNUNET_CORE_Handle *h, int ignore_currently_down)
787#endif 789#endif
788 return; /* no pending message */ 790 return; /* no pending message */
789 } 791 }
790 h->cth = GNUNET_CLIENT_notify_transmit_ready (h->client, 792 h->cth =
791 msize, 793 GNUNET_CLIENT_notify_transmit_ready (h->client, msize,
792 GNUNET_TIME_UNIT_FOREVER_REL, 794 GNUNET_TIME_UNIT_FOREVER_REL,
793 GNUNET_NO, 795 GNUNET_NO, &transmit_message, h);
794 &transmit_message, h);
795} 796}
796 797
797 798
@@ -857,8 +858,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
857 } 858 }
858 h->retry_backoff = GNUNET_TIME_UNIT_MILLISECONDS; 859 h->retry_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
859 GNUNET_CRYPTO_hash (&m->publicKey, 860 GNUNET_CRYPTO_hash (&m->publicKey,
860 sizeof (struct 861 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
861 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
862 &h->me.hashPubKey); 862 &h->me.hashPubKey);
863 if (NULL != (init = h->init)) 863 if (NULL != (init = h->init))
864 { 864 {
@@ -886,8 +886,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
886 pr->ch = h; 886 pr->ch = h;
887 GNUNET_assert (GNUNET_YES == 887 GNUNET_assert (GNUNET_YES ==
888 GNUNET_CONTAINER_multihashmap_put (h->peers, 888 GNUNET_CONTAINER_multihashmap_put (h->peers,
889 &h->me.hashPubKey, 889 &h->me.hashPubKey, pr,
890 pr,
891 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); 890 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
892 if (NULL != h->connects) 891 if (NULL != h->connects)
893 h->connects (h->cls, &h->me, NULL); 892 h->connects (h->cls, &h->me, NULL);
@@ -934,8 +933,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
934 pr->ch = h; 933 pr->ch = h;
935 GNUNET_assert (GNUNET_YES == 934 GNUNET_assert (GNUNET_YES ==
936 GNUNET_CONTAINER_multihashmap_put (h->peers, 935 GNUNET_CONTAINER_multihashmap_put (h->peers,
937 &cnm->peer.hashPubKey, 936 &cnm->peer.hashPubKey, pr,
938 pr,
939 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); 937 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
940 if (NULL != h->connects) 938 if (NULL != h->connects)
941 h->connects (h->cls, &cnm->peer, &cnm->ats); 939 h->connects (h->cls, &cnm->peer, &cnm->ats);
@@ -967,8 +965,8 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
967 reconnect_later (h); 965 reconnect_later (h);
968 return; 966 return;
969 } 967 }
970 trigger = ((pr->prev != NULL) || 968 trigger = ((pr->prev != NULL) || (pr->next != NULL) ||
971 (pr->next != NULL) || (h->ready_peer_head == pr)); 969 (h->ready_peer_head == pr));
972 disconnect_and_free_peer_entry (h, &dnm->peer.hashPubKey, pr); 970 disconnect_and_free_peer_entry (h, &dnm->peer.hashPubKey, pr);
973 if (trigger) 971 if (trigger)
974 trigger_next_request (h, GNUNET_NO); 972 trigger_next_request (h, GNUNET_NO);
@@ -1015,9 +1013,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
1015 reconnect_later (h); 1013 reconnect_later (h);
1016 return; 1014 return;
1017 } 1015 }
1018 h->status_events (h->cls, 1016 h->status_events (h->cls, &psnm->peer, psnm->bandwidth_in,
1019 &psnm->peer,
1020 psnm->bandwidth_in,
1021 psnm->bandwidth_out, 1017 psnm->bandwidth_out,
1022 GNUNET_TIME_absolute_ntoh (psnm->timeout), &psnm->ats); 1018 GNUNET_TIME_absolute_ntoh (psnm->timeout), &psnm->ats);
1023 break; 1019 break;
@@ -1056,7 +1052,8 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
1056 return; 1052 return;
1057 } 1053 }
1058 if ((GNUNET_NO == h->inbound_hdr_only) && 1054 if ((GNUNET_NO == h->inbound_hdr_only) &&
1059 (msize != ntohs (em->size) + sizeof (struct NotifyTrafficMessage) + 1055 (msize !=
1056 ntohs (em->size) + sizeof (struct NotifyTrafficMessage) +
1060 +ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information))) 1057 +ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)))
1061 { 1058 {
1062 GNUNET_break (0); 1059 GNUNET_break (0);
@@ -1124,8 +1121,9 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
1124 GNUNET_i2s (&ntm->peer)); 1121 GNUNET_i2s (&ntm->peer));
1125#endif 1122#endif
1126 if ((GNUNET_NO == h->outbound_hdr_only) && 1123 if ((GNUNET_NO == h->outbound_hdr_only) &&
1127 (msize != ntohs (em->size) + sizeof (struct NotifyTrafficMessage) 1124 (msize !=
1128 + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information))) 1125 ntohs (em->size) + sizeof (struct NotifyTrafficMessage) +
1126 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)))
1129 { 1127 {
1130 GNUNET_break (0); 1128 GNUNET_break (0);
1131 reconnect_later (h); 1129 reconnect_later (h);
@@ -1221,10 +1219,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
1221 GNUNET_free_non_null (pr->pcic_ptr); 1219 GNUNET_free_non_null (pr->pcic_ptr);
1222 pr->pcic_ptr = NULL; 1220 pr->pcic_ptr = NULL;
1223 if (pcic != NULL) 1221 if (pcic != NULL)
1224 pcic (pr->pcic_cls, 1222 pcic (pr->pcic_cls, &pr->peer, cim->bw_out, ntohl (cim->reserved_amount),
1225 &pr->peer,
1226 cim->bw_out,
1227 ntohl (cim->reserved_amount),
1228 GNUNET_TIME_relative_ntoh (cim->reserve_delay), 1223 GNUNET_TIME_relative_ntoh (cim->reserve_delay),
1229 GNUNET_ntohll (cim->preference)); 1224 GNUNET_ntohll (cim->preference));
1230 break; 1225 break;
@@ -1232,8 +1227,8 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
1232 reconnect_later (h); 1227 reconnect_later (h);
1233 return; 1228 return;
1234 } 1229 }
1235 GNUNET_CLIENT_receive (h->client, 1230 GNUNET_CLIENT_receive (h->client, &main_notify_handler, h,
1236 &main_notify_handler, h, GNUNET_TIME_UNIT_FOREVER_REL); 1231 GNUNET_TIME_UNIT_FOREVER_REL);
1237} 1232}
1238 1233
1239 1234
@@ -1261,8 +1256,8 @@ init_done_task (void *cls, int success)
1261 reconnect_later (h); 1256 reconnect_later (h);
1262 return; 1257 return;
1263 } 1258 }
1264 GNUNET_CLIENT_receive (h->client, 1259 GNUNET_CLIENT_receive (h->client, &main_notify_handler, h,
1265 &main_notify_handler, h, GNUNET_TIME_UNIT_FOREVER_REL); 1260 GNUNET_TIME_UNIT_FOREVER_REL);
1266} 1261}
1267 1262
1268 1263
@@ -1321,8 +1316,8 @@ reconnect (struct GNUNET_CORE_Handle *h)
1321 ts = (uint16_t *) & init[1]; 1316 ts = (uint16_t *) & init[1];
1322 for (hpos = 0; hpos < h->hcnt; hpos++) 1317 for (hpos = 0; hpos < h->hcnt; hpos++)
1323 ts[hpos] = htons (h->handlers[hpos].type); 1318 ts[hpos] = htons (h->handlers[hpos].type);
1324 GNUNET_CONTAINER_DLL_insert (h->control_pending_head, 1319 GNUNET_CONTAINER_DLL_insert (h->control_pending_head, h->control_pending_tail,
1325 h->control_pending_tail, cm); 1320 cm);
1326 trigger_next_request (h, GNUNET_YES); 1321 trigger_next_request (h, GNUNET_YES);
1327} 1322}
1328 1323
@@ -1354,8 +1349,7 @@ reconnect (struct GNUNET_CORE_Handle *h)
1354 */ 1349 */
1355struct GNUNET_CORE_Handle * 1350struct GNUNET_CORE_Handle *
1356GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 1351GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
1357 unsigned int queue_size, 1352 unsigned int queue_size, void *cls,
1358 void *cls,
1359 GNUNET_CORE_StartupCallback init, 1353 GNUNET_CORE_StartupCallback init,
1360 GNUNET_CORE_ConnectEventHandler connects, 1354 GNUNET_CORE_ConnectEventHandler connects,
1361 GNUNET_CORE_DisconnectEventHandler disconnects, 1355 GNUNET_CORE_DisconnectEventHandler disconnects,
@@ -1485,8 +1479,7 @@ run_request_next_transmission (void *cls,
1485 * memory); if NULL is returned, "notify" will NOT be called. 1479 * memory); if NULL is returned, "notify" will NOT be called.
1486 */ 1480 */
1487struct GNUNET_CORE_TransmitHandle * 1481struct GNUNET_CORE_TransmitHandle *
1488GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle, 1482GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle, int cork,
1489 int cork,
1490 uint32_t priority, 1483 uint32_t priority,
1491 struct GNUNET_TIME_Relative maxdelay, 1484 struct GNUNET_TIME_Relative maxdelay,
1492 const struct GNUNET_PeerIdentity *target, 1485 const struct GNUNET_PeerIdentity *target,
@@ -1562,8 +1555,8 @@ GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle,
1562 /* Order entries by deadline, but SKIP 'HEAD' if 1555 /* Order entries by deadline, but SKIP 'HEAD' if
1563 * we're in the 'ready_peer_*' DLL */ 1556 * we're in the 'ready_peer_*' DLL */
1564 pos = pr->pending_head; 1557 pos = pr->pending_head;
1565 if ((pr->prev != NULL) || 1558 if ((pr->prev != NULL) || (pr->next != NULL) ||
1566 (pr->next != NULL) || (pr == handle->ready_peer_head)) 1559 (pr == handle->ready_peer_head))
1567 { 1560 {
1568 GNUNET_assert (pos != NULL); 1561 GNUNET_assert (pos != NULL);
1569 pos = pos->next; /* skip head */ 1562 pos = pos->next; /* skip head */
@@ -1576,17 +1569,16 @@ GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle,
1576 prev = pos; 1569 prev = pos;
1577 pos = pos->next; 1570 pos = pos->next;
1578 } 1571 }
1579 GNUNET_CONTAINER_DLL_insert_after (pr->pending_head, 1572 GNUNET_CONTAINER_DLL_insert_after (pr->pending_head, pr->pending_tail, prev,
1580 pr->pending_tail, prev, th); 1573 th);
1581 pr->queue_size++; 1574 pr->queue_size++;
1582 /* was the request queue previously empty? */ 1575 /* was the request queue previously empty? */
1583#if DEBUG_CORE 1576#if DEBUG_CORE
1584 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission request added to queue\n"); 1577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission request added to queue\n");
1585#endif 1578#endif
1586 if ((pr->pending_head == th) && 1579 if ((pr->pending_head == th) && (pr->ntr_task == GNUNET_SCHEDULER_NO_TASK) &&
1587 (pr->ntr_task == GNUNET_SCHEDULER_NO_TASK) && 1580 (pr->next == NULL) && (pr->prev == NULL) &&
1588 (pr->next == NULL) && 1581 (handle->ready_peer_head != pr))
1589 (pr->prev == NULL) && (handle->ready_peer_head != pr))
1590 pr->ntr_task = 1582 pr->ntr_task =
1591 GNUNET_SCHEDULER_add_now (&run_request_next_transmission, pr); 1583 GNUNET_SCHEDULER_add_now (&run_request_next_transmission, pr);
1592 return th; 1584 return th;
@@ -1760,8 +1752,8 @@ GNUNET_CORE_peer_request_connect_cancel (struct GNUNET_CORE_PeerRequestHandle
1760 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1752 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1761 "A CHANGE PREFERENCE request was cancelled!\n"); 1753 "A CHANGE PREFERENCE request was cancelled!\n");
1762#endif 1754#endif
1763 GNUNET_CONTAINER_DLL_remove (h->control_pending_head, 1755 GNUNET_CONTAINER_DLL_remove (h->control_pending_head, h->control_pending_tail,
1764 h->control_pending_tail, cm); 1756 cm);
1765 GNUNET_free (cm); 1757 GNUNET_free (cm);
1766 GNUNET_free (req); 1758 GNUNET_free (req);
1767} 1759}
@@ -1834,8 +1826,7 @@ GNUNET_CORE_peer_change_preference (struct GNUNET_CORE_Handle *h,
1834 const struct GNUNET_PeerIdentity *peer, 1826 const struct GNUNET_PeerIdentity *peer,
1835 struct GNUNET_TIME_Relative timeout, 1827 struct GNUNET_TIME_Relative timeout,
1836 struct GNUNET_BANDWIDTH_Value32NBO bw_out, 1828 struct GNUNET_BANDWIDTH_Value32NBO bw_out,
1837 int32_t amount, 1829 int32_t amount, uint64_t preference,
1838 uint64_t preference,
1839 GNUNET_CORE_PeerConfigurationInfoCallback 1830 GNUNET_CORE_PeerConfigurationInfoCallback
1840 info, void *info_cls) 1831 info, void *info_cls)
1841{ 1832{
diff --git a/src/core/core_api_iterate_peers.c b/src/core/core_api_iterate_peers.c
index 1bad9a768..0cc28e538 100644
--- a/src/core/core_api_iterate_peers.c
+++ b/src/core/core_api_iterate_peers.c
@@ -114,10 +114,9 @@ receive_info (void *cls, const struct GNUNET_MessageHeader *msg)
114 } 114 }
115 /* Normal case */ 115 /* Normal case */
116 if (request_context->peer_cb != NULL) 116 if (request_context->peer_cb != NULL)
117 request_context->peer_cb (request_context->cb_cls, 117 request_context->peer_cb (request_context->cb_cls, &connect_message->peer,
118 &connect_message->peer, &connect_message->ats); 118 &connect_message->ats);
119 GNUNET_CLIENT_receive (request_context->client, 119 GNUNET_CLIENT_receive (request_context->client, &receive_info,
120 &receive_info,
121 request_context, GNUNET_TIME_UNIT_FOREVER_REL); 120 request_context, GNUNET_TIME_UNIT_FOREVER_REL);
122} 121}
123 122
@@ -194,16 +193,13 @@ GNUNET_CORE_is_peer_connected (const struct GNUNET_CONFIGURATION_Handle *cfg,
194 request_context->cb_cls = cb_cls; 193 request_context->cb_cls = cb_cls;
195 request_context->peer = peer; 194 request_context->peer = peer;
196 195
197 request_context->th = GNUNET_CLIENT_notify_transmit_ready (client, 196 request_context->th =
198 sizeof (struct 197 GNUNET_CLIENT_notify_transmit_ready (client,
199 GNUNET_MessageHeader) 198 sizeof (struct GNUNET_MessageHeader)
200 + 199 +
201 sizeof (struct 200 sizeof (struct GNUNET_PeerIdentity),
202 GNUNET_PeerIdentity), 201 GNUNET_TIME_relative_get_forever (),
203 GNUNET_TIME_relative_get_forever 202 GNUNET_YES, &transmit_request, peer);
204 (), GNUNET_YES,
205 &transmit_request,
206 peer);
207 GNUNET_assert (request_context->th != NULL); 203 GNUNET_assert (request_context->th != NULL);
208 GNUNET_CLIENT_receive (client, &receive_info, request_context, 204 GNUNET_CLIENT_receive (client, &receive_info, request_context,
209 GNUNET_TIME_relative_get_forever ()); 205 GNUNET_TIME_relative_get_forever ());
@@ -238,13 +234,11 @@ GNUNET_CORE_iterate_peers (const struct GNUNET_CONFIGURATION_Handle *cfg,
238 request_context->peer_cb = peer_cb; 234 request_context->peer_cb = peer_cb;
239 request_context->cb_cls = cb_cls; 235 request_context->cb_cls = cb_cls;
240 236
241 request_context->th = GNUNET_CLIENT_notify_transmit_ready (client, 237 request_context->th =
242 sizeof (struct 238 GNUNET_CLIENT_notify_transmit_ready (client,
243 GNUNET_MessageHeader), 239 sizeof (struct GNUNET_MessageHeader),
244 GNUNET_TIME_relative_get_forever 240 GNUNET_TIME_relative_get_forever (),
245 (), GNUNET_YES, 241 GNUNET_YES, &transmit_request, NULL);
246 &transmit_request,
247 NULL);
248 242
249 GNUNET_CLIENT_receive (client, &receive_info, request_context, 243 GNUNET_CLIENT_receive (client, &receive_info, request_context,
250 GNUNET_TIME_relative_get_forever ()); 244 GNUNET_TIME_relative_get_forever ());
diff --git a/src/core/gnunet-core-list-connections.c b/src/core/gnunet-core-list-connections.c
index 284a79f69..fe037f73b 100644
--- a/src/core/gnunet-core-list-connections.c
+++ b/src/core/gnunet-core-list-connections.c
@@ -135,8 +135,7 @@ connected_peer_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
135#endif 135#endif
136 pc = GNUNET_malloc (sizeof (struct PrintContext)); 136 pc = GNUNET_malloc (sizeof (struct PrintContext));
137 pc->peer = *peer; 137 pc->peer = *peer;
138 GNUNET_TRANSPORT_peer_address_lookup (cfg, peer, 138 GNUNET_TRANSPORT_peer_address_lookup (cfg, peer, GNUNET_TIME_UNIT_MINUTES,
139 GNUNET_TIME_UNIT_MINUTES,
140 &process_resolved_address, pc); 139 &process_resolved_address, pc);
141 } 140 }
142#if VERBOSE 141#if VERBOSE
@@ -157,9 +156,8 @@ connected_peer_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
157 * @param c configuration 156 * @param c configuration
158 */ 157 */
159static void 158static void
160run (void *cls, 159run (void *cls, char *const *args, const char *cfgfile,
161 char *const *args, 160 const struct GNUNET_CONFIGURATION_Handle *c)
162 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
163{ 161{
164 162
165 cfg = c; 163 cfg = c;
@@ -191,9 +189,7 @@ main (int argc, char *const *argv)
191 GNUNET_GETOPT_OPTION_END 189 GNUNET_GETOPT_OPTION_END
192 }; 190 };
193 return (GNUNET_OK == 191 return (GNUNET_OK ==
194 GNUNET_PROGRAM_run (argc, 192 GNUNET_PROGRAM_run (argc, argv, "gnunet-list-connections",
195 argv,
196 "gnunet-list-connections",
197 gettext_noop 193 gettext_noop
198 ("Print information about connected peers."), 194 ("Print information about connected peers."),
199 options, &run, NULL)) ? 0 : 1; 195 options, &run, NULL)) ? 0 : 1;
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c
index 95e182448..e97e9fe46 100644
--- a/src/core/gnunet-service-core.c
+++ b/src/core/gnunet-service-core.c
@@ -821,21 +821,17 @@ static unsigned long long bandwidth_target_out_bps;
821 */ 821 */
822static void 822static void
823derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey, 823derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey,
824 const struct GNUNET_CRYPTO_AesSessionKey *skey, 824 const struct GNUNET_CRYPTO_AesSessionKey *skey, uint32_t seed,
825 uint32_t seed, struct GNUNET_TIME_Absolute creation_time) 825 struct GNUNET_TIME_Absolute creation_time)
826{ 826{
827 static const char ctx[] = "authentication key"; 827 static const char ctx[] = "authentication key";
828 struct GNUNET_TIME_AbsoluteNBO ctbe; 828 struct GNUNET_TIME_AbsoluteNBO ctbe;
829 829
830 830
831 ctbe = GNUNET_TIME_absolute_hton (creation_time); 831 ctbe = GNUNET_TIME_absolute_hton (creation_time);
832 GNUNET_CRYPTO_hmac_derive_key (akey, 832 GNUNET_CRYPTO_hmac_derive_key (akey, skey, &seed, sizeof (seed), &skey->key,
833 skey, 833 sizeof (skey->key), &ctbe, sizeof (ctbe), ctx,
834 &seed, 834 sizeof (ctx), NULL);
835 sizeof (seed),
836 &skey->key,
837 sizeof (skey->key),
838 &ctbe, sizeof (ctbe), ctx, sizeof (ctx), NULL);
839} 835}
840 836
841 837
@@ -849,13 +845,10 @@ derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv,
849{ 845{
850 static const char ctx[] = "initialization vector"; 846 static const char ctx[] = "initialization vector";
851 847
852 GNUNET_CRYPTO_aes_derive_iv (iv, 848 GNUNET_CRYPTO_aes_derive_iv (iv, skey, &seed, sizeof (seed),
853 skey,
854 &seed,
855 sizeof (seed),
856 &identity->hashPubKey.bits, 849 &identity->hashPubKey.bits,
857 sizeof (identity->hashPubKey.bits), 850 sizeof (identity->hashPubKey.bits), ctx,
858 ctx, sizeof (ctx), NULL); 851 sizeof (ctx), NULL);
859} 852}
860 853
861/** 854/**
@@ -868,13 +861,9 @@ derive_pong_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv,
868{ 861{
869 static const char ctx[] = "pong initialization vector"; 862 static const char ctx[] = "pong initialization vector";
870 863
871 GNUNET_CRYPTO_aes_derive_iv (iv, 864 GNUNET_CRYPTO_aes_derive_iv (iv, skey, &seed, sizeof (seed),
872 skey,
873 &seed,
874 sizeof (seed),
875 &identity->hashPubKey.bits, 865 &identity->hashPubKey.bits,
876 sizeof (identity->hashPubKey.bits), 866 sizeof (identity->hashPubKey.bits), &challenge,
877 &challenge,
878 sizeof (challenge), ctx, sizeof (ctx), NULL); 867 sizeof (challenge), ctx, sizeof (ctx), NULL);
879} 868}
880 869
@@ -926,8 +915,8 @@ update_preference_sum (unsigned long long inc)
926 return; /* done! */ 915 return; /* done! */
927 /* overflow! compensate by cutting all values in half! */ 916 /* overflow! compensate by cutting all values in half! */
928 preference_sum = 0; 917 preference_sum = 0;
929 GNUNET_CONTAINER_multihashmap_iterate (neighbours, 918 GNUNET_CONTAINER_multihashmap_iterate (neighbours, &update_preference,
930 &update_preference, &preference_sum); 919 &preference_sum);
931 GNUNET_STATISTICS_set (stats, gettext_noop ("# total peer preference"), 920 GNUNET_STATISTICS_set (stats, gettext_noop ("# total peer preference"),
932 preference_sum, GNUNET_NO); 921 preference_sum, GNUNET_NO);
933} 922}
@@ -956,8 +945,8 @@ find_neighbour (const struct GNUNET_PeerIdentity *peer)
956 * client's queue is getting too large? 945 * client's queue is getting too large?
957 */ 946 */
958static void 947static void
959send_to_client (struct Client *client, 948send_to_client (struct Client *client, const struct GNUNET_MessageHeader *msg,
960 const struct GNUNET_MessageHeader *msg, int can_drop) 949 int can_drop)
961{ 950{
962#if DEBUG_CORE_CLIENT 951#if DEBUG_CORE_CLIENT
963 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 952 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -965,8 +954,7 @@ send_to_client (struct Client *client,
965 (unsigned int) ntohs (msg->size), 954 (unsigned int) ntohs (msg->size),
966 (unsigned int) ntohs (msg->type)); 955 (unsigned int) ntohs (msg->type));
967#endif 956#endif
968 GNUNET_SERVER_notification_context_unicast (notifier, 957 GNUNET_SERVER_notification_context_unicast (notifier, client->client_handle,
969 client->client_handle,
970 msg, can_drop); 958 msg, can_drop);
971} 959}
972 960
@@ -980,8 +968,8 @@ send_to_client (struct Client *client,
980 * @param options mask to use 968 * @param options mask to use
981 */ 969 */
982static void 970static void
983send_to_all_clients (const struct GNUNET_MessageHeader *msg, 971send_to_all_clients (const struct GNUNET_MessageHeader *msg, int can_drop,
984 int can_drop, int options) 972 int options)
985{ 973{
986 struct Client *c; 974 struct Client *c;
987 975
@@ -1019,17 +1007,19 @@ handle_peer_status_change (struct Neighbour *n)
1019 if ((!n->is_connected) || (n->status != PEER_STATE_KEY_CONFIRMED)) 1007 if ((!n->is_connected) || (n->status != PEER_STATE_KEY_CONFIRMED))
1020 return; 1008 return;
1021#if DEBUG_CORE > 1 1009#if DEBUG_CORE > 1
1022 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1010 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' changed status\n",
1023 "Peer `%4s' changed status\n", GNUNET_i2s (&n->peer)); 1011 GNUNET_i2s (&n->peer));
1024#endif 1012#endif
1025 size = sizeof (struct PeerStatusNotifyMessage) + 1013 size =
1014 sizeof (struct PeerStatusNotifyMessage) +
1026 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); 1015 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
1027 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 1016 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1028 { 1017 {
1029 GNUNET_break (0); 1018 GNUNET_break (0);
1030 /* recovery strategy: throw away performance data */ 1019 /* recovery strategy: throw away performance data */
1031 GNUNET_array_grow (n->ats, n->ats_count, 0); 1020 GNUNET_array_grow (n->ats, n->ats_count, 0);
1032 size = sizeof (struct PeerStatusNotifyMessage) + 1021 size =
1022 sizeof (struct PeerStatusNotifyMessage) +
1033 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); 1023 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
1034 } 1024 }
1035 psnm = (struct PeerStatusNotifyMessage *) buf; 1025 psnm = (struct PeerStatusNotifyMessage *) buf;
@@ -1041,16 +1031,14 @@ handle_peer_status_change (struct Neighbour *n)
1041 psnm->peer = n->peer; 1031 psnm->peer = n->peer;
1042 psnm->ats_count = htonl (n->ats_count); 1032 psnm->ats_count = htonl (n->ats_count);
1043 ats = &psnm->ats; 1033 ats = &psnm->ats;
1044 memcpy (ats, 1034 memcpy (ats, n->ats,
1045 n->ats,
1046 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); 1035 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
1047 ats[n->ats_count].type = htonl (0); 1036 ats[n->ats_count].type = htonl (0);
1048 ats[n->ats_count].value = htonl (0); 1037 ats[n->ats_count].value = htonl (0);
1049 send_to_all_clients (&psnm->header, 1038 send_to_all_clients (&psnm->header, GNUNET_YES,
1050 GNUNET_YES, GNUNET_CORE_OPTION_SEND_STATUS_CHANGE); 1039 GNUNET_CORE_OPTION_SEND_STATUS_CHANGE);
1051 GNUNET_STATISTICS_update (stats, 1040 GNUNET_STATISTICS_update (stats, gettext_noop ("# peer status changes"), 1,
1052 gettext_noop ("# peer status changes"), 1041 GNUNET_NO);
1053 1, GNUNET_NO);
1054} 1042}
1055 1043
1056 1044
@@ -1149,10 +1137,9 @@ compute_type_map_message ()
1149 hdr = GNUNET_malloc (dlen + sizeof (struct GNUNET_MessageHeader)); 1137 hdr = GNUNET_malloc (dlen + sizeof (struct GNUNET_MessageHeader));
1150 hdr->size = htons ((uint16_t) dlen + sizeof (struct GNUNET_MessageHeader)); 1138 hdr->size = htons ((uint16_t) dlen + sizeof (struct GNUNET_MessageHeader));
1151 tmp = (char *) &hdr[1]; 1139 tmp = (char *) &hdr[1];
1152 if ((Z_OK != compress2 ((Bytef *) tmp, 1140 if ((Z_OK !=
1153 &dlen, (const Bytef *) my_type_map, 1141 compress2 ((Bytef *) tmp, &dlen, (const Bytef *) my_type_map,
1154 sizeof (my_type_map), 9)) || 1142 sizeof (my_type_map), 9)) || (dlen >= sizeof (my_type_map)))
1155 (dlen >= sizeof (my_type_map)))
1156 { 1143 {
1157 dlen = sizeof (my_type_map); 1144 dlen = sizeof (my_type_map);
1158 memcpy (tmp, my_type_map, sizeof (my_type_map)); 1145 memcpy (tmp, my_type_map, sizeof (my_type_map));
@@ -1220,8 +1207,7 @@ broadcast_my_type_map ()
1220 * Handle CORE_SEND_REQUEST message. 1207 * Handle CORE_SEND_REQUEST message.
1221 */ 1208 */
1222static void 1209static void
1223handle_client_send_request (void *cls, 1210handle_client_send_request (void *cls, struct GNUNET_SERVER_Client *client,
1224 struct GNUNET_SERVER_Client *client,
1225 const struct GNUNET_MessageHeader *message) 1211 const struct GNUNET_MessageHeader *message)
1226{ 1212{
1227 const struct SendMessageRequest *req; 1213 const struct SendMessageRequest *req;
@@ -1230,13 +1216,12 @@ handle_client_send_request (void *cls,
1230 struct ClientActiveRequest *car; 1216 struct ClientActiveRequest *car;
1231 1217
1232 req = (const struct SendMessageRequest *) message; 1218 req = (const struct SendMessageRequest *) message;
1233 if (0 == memcmp (&req->peer, 1219 if (0 ==
1234 &my_identity, sizeof (struct GNUNET_PeerIdentity))) 1220 memcmp (&req->peer, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
1235 n = &self; 1221 n = &self;
1236 else 1222 else
1237 n = find_neighbour (&req->peer); 1223 n = find_neighbour (&req->peer);
1238 if ((n == NULL) || 1224 if ((n == NULL) || (GNUNET_YES != n->is_connected) ||
1239 (GNUNET_YES != n->is_connected) ||
1240 (n->status != PEER_STATE_KEY_CONFIRMED)) 1225 (n->status != PEER_STATE_KEY_CONFIRMED))
1241 { 1226 {
1242 /* neighbour must have disconnected since request was issued, 1227 /* neighbour must have disconnected since request was issued,
@@ -1297,8 +1282,8 @@ handle_client_send_request (void *cls,
1297 * Notify client about an existing connection to one of our neighbours. 1282 * Notify client about an existing connection to one of our neighbours.
1298 */ 1283 */
1299static int 1284static int
1300notify_client_about_neighbour (void *cls, 1285notify_client_about_neighbour (void *cls, const GNUNET_HashCode * key,
1301 const GNUNET_HashCode * key, void *value) 1286 void *value)
1302{ 1287{
1303 struct Client *c = cls; 1288 struct Client *c = cls;
1304 struct Neighbour *n = value; 1289 struct Neighbour *n = value;
@@ -1307,14 +1292,16 @@ notify_client_about_neighbour (void *cls,
1307 struct GNUNET_TRANSPORT_ATS_Information *ats; 1292 struct GNUNET_TRANSPORT_ATS_Information *ats;
1308 struct ConnectNotifyMessage *cnm; 1293 struct ConnectNotifyMessage *cnm;
1309 1294
1310 size = sizeof (struct ConnectNotifyMessage) + 1295 size =
1296 sizeof (struct ConnectNotifyMessage) +
1311 (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); 1297 (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
1312 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 1298 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1313 { 1299 {
1314 GNUNET_break (0); 1300 GNUNET_break (0);
1315 /* recovery strategy: throw away performance data */ 1301 /* recovery strategy: throw away performance data */
1316 GNUNET_array_grow (n->ats, n->ats_count, 0); 1302 GNUNET_array_grow (n->ats, n->ats_count, 0);
1317 size = sizeof (struct ConnectNotifyMessage) + 1303 size =
1304 sizeof (struct ConnectNotifyMessage) +
1318 (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); 1305 (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
1319 } 1306 }
1320 cnm = (struct ConnectNotifyMessage *) buf; 1307 cnm = (struct ConnectNotifyMessage *) buf;
@@ -1322,16 +1309,15 @@ notify_client_about_neighbour (void *cls,
1322 cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); 1309 cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
1323 cnm->ats_count = htonl (n->ats_count); 1310 cnm->ats_count = htonl (n->ats_count);
1324 ats = &cnm->ats; 1311 ats = &cnm->ats;
1325 memcpy (ats, 1312 memcpy (ats, n->ats,
1326 n->ats,
1327 sizeof (struct GNUNET_TRANSPORT_ATS_Information) * n->ats_count); 1313 sizeof (struct GNUNET_TRANSPORT_ATS_Information) * n->ats_count);
1328 ats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 1314 ats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
1329 ats[n->ats_count].value = htonl (0); 1315 ats[n->ats_count].value = htonl (0);
1330 if (n->status == PEER_STATE_KEY_CONFIRMED) 1316 if (n->status == PEER_STATE_KEY_CONFIRMED)
1331 { 1317 {
1332#if DEBUG_CORE_CLIENT 1318#if DEBUG_CORE_CLIENT
1333 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1319 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message to client.\n",
1334 "Sending `%s' message to client.\n", "NOTIFY_CONNECT"); 1320 "NOTIFY_CONNECT");
1335#endif 1321#endif
1336 cnm->peer = n->peer; 1322 cnm->peer = n->peer;
1337 send_to_client (c, &cnm->header, GNUNET_NO); 1323 send_to_client (c, &cnm->header, GNUNET_NO);
@@ -1345,8 +1331,7 @@ notify_client_about_neighbour (void *cls,
1345 * Handle CORE_INIT request. 1331 * Handle CORE_INIT request.
1346 */ 1332 */
1347static void 1333static void
1348handle_client_init (void *cls, 1334handle_client_init (void *cls, struct GNUNET_SERVER_Client *client,
1349 struct GNUNET_SERVER_Client *client,
1350 const struct GNUNET_MessageHeader *message) 1335 const struct GNUNET_MessageHeader *message)
1351{ 1336{
1352 const struct InitMessage *im; 1337 const struct InitMessage *im;
@@ -1401,19 +1386,18 @@ handle_client_init (void *cls,
1401 c->options = ntohl (im->options); 1386 c->options = ntohl (im->options);
1402#if DEBUG_CORE_CLIENT 1387#if DEBUG_CORE_CLIENT
1403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1388 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1404 "Client %p is interested in %u message types\n", 1389 "Client %p is interested in %u message types\n", c,
1405 c, (unsigned int) c->tcnt); 1390 (unsigned int) c->tcnt);
1406#endif 1391#endif
1407 /* send init reply message */ 1392 /* send init reply message */
1408 irm.header.size = htons (sizeof (struct InitReplyMessage)); 1393 irm.header.size = htons (sizeof (struct InitReplyMessage));
1409 irm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY); 1394 irm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY);
1410 irm.reserved = htonl (0); 1395 irm.reserved = htonl (0);
1411 memcpy (&irm.publicKey, 1396 memcpy (&irm.publicKey, &my_public_key,
1412 &my_public_key,
1413 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 1397 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
1414#if DEBUG_CORE_CLIENT 1398#if DEBUG_CORE_CLIENT
1415 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message to client.\n",
1416 "Sending `%s' message to client.\n", "INIT_REPLY"); 1400 "INIT_REPLY");
1417#endif 1401#endif
1418 send_to_client (c, &irm.header, GNUNET_NO); 1402 send_to_client (c, &irm.header, GNUNET_NO);
1419 if (0 != (c->options & GNUNET_CORE_OPTION_SEND_CONNECT)) 1403 if (0 != (c->options & GNUNET_CORE_OPTION_SEND_CONNECT))
@@ -1435,8 +1419,8 @@ handle_client_init (void *cls,
1435 * @return GNUNET_YES (continue iteration) 1419 * @return GNUNET_YES (continue iteration)
1436 */ 1420 */
1437static int 1421static int
1438destroy_active_client_request (void *cls, 1422destroy_active_client_request (void *cls, const GNUNET_HashCode * key,
1439 const GNUNET_HashCode * key, void *value) 1423 void *value)
1440{ 1424{
1441 struct ClientActiveRequest *car = value; 1425 struct ClientActiveRequest *car = value;
1442 struct Neighbour *n; 1426 struct Neighbour *n;
@@ -1532,14 +1516,16 @@ queue_connect_message (void *cls, const GNUNET_HashCode * key, void *value)
1532 cnm = (struct ConnectNotifyMessage *) buf; 1516 cnm = (struct ConnectNotifyMessage *) buf;
1533 if (n->status != PEER_STATE_KEY_CONFIRMED) 1517 if (n->status != PEER_STATE_KEY_CONFIRMED)
1534 return GNUNET_OK; 1518 return GNUNET_OK;
1535 size = sizeof (struct ConnectNotifyMessage) + 1519 size =
1520 sizeof (struct ConnectNotifyMessage) +
1536 (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); 1521 (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
1537 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 1522 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1538 { 1523 {
1539 GNUNET_break (0); 1524 GNUNET_break (0);
1540 /* recovery strategy: throw away performance data */ 1525 /* recovery strategy: throw away performance data */
1541 GNUNET_array_grow (n->ats, n->ats_count, 0); 1526 GNUNET_array_grow (n->ats, n->ats_count, 0);
1542 size = sizeof (struct PeerStatusNotifyMessage) + 1527 size =
1528 sizeof (struct PeerStatusNotifyMessage) +
1543 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); 1529 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
1544 } 1530 }
1545 cnm = (struct ConnectNotifyMessage *) buf; 1531 cnm = (struct ConnectNotifyMessage *) buf;
@@ -1547,14 +1533,13 @@ queue_connect_message (void *cls, const GNUNET_HashCode * key, void *value)
1547 cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); 1533 cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
1548 cnm->ats_count = htonl (n->ats_count); 1534 cnm->ats_count = htonl (n->ats_count);
1549 ats = &cnm->ats; 1535 ats = &cnm->ats;
1550 memcpy (ats, 1536 memcpy (ats, n->ats,
1551 n->ats,
1552 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); 1537 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
1553 ats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 1538 ats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
1554 ats[n->ats_count].value = htonl (0); 1539 ats[n->ats_count].value = htonl (0);
1555#if DEBUG_CORE_CLIENT 1540#if DEBUG_CORE_CLIENT
1556 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1541 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message to client.\n",
1557 "Sending `%s' message to client.\n", "NOTIFY_CONNECT"); 1542 "NOTIFY_CONNECT");
1558#endif 1543#endif
1559 cnm->peer = n->peer; 1544 cnm->peer = n->peer;
1560 GNUNET_SERVER_transmit_context_append_message (tc, &cnm->header); 1545 GNUNET_SERVER_transmit_context_append_message (tc, &cnm->header);
@@ -1570,8 +1555,7 @@ queue_connect_message (void *cls, const GNUNET_HashCode * key, void *value)
1570 * @param message iteration request message 1555 * @param message iteration request message
1571 */ 1556 */
1572static void 1557static void
1573handle_client_iterate_peers (void *cls, 1558handle_client_iterate_peers (void *cls, struct GNUNET_SERVER_Client *client,
1574 struct GNUNET_SERVER_Client *client,
1575 const struct GNUNET_MessageHeader *message) 1559 const struct GNUNET_MessageHeader *message)
1576{ 1560{
1577 struct GNUNET_MessageHeader done_msg; 1561 struct GNUNET_MessageHeader done_msg;
@@ -1603,8 +1587,7 @@ handle_client_iterate_peers (void *cls,
1603 * @param message iteration request message 1587 * @param message iteration request message
1604 */ 1588 */
1605static void 1589static void
1606handle_client_have_peer (void *cls, 1590handle_client_have_peer (void *cls, struct GNUNET_SERVER_Client *client,
1607 struct GNUNET_SERVER_Client *client,
1608 const struct GNUNET_MessageHeader *message) 1591 const struct GNUNET_MessageHeader *message)
1609{ 1592{
1610 struct GNUNET_MessageHeader done_msg; 1593 struct GNUNET_MessageHeader done_msg;
@@ -1613,8 +1596,7 @@ handle_client_have_peer (void *cls,
1613 1596
1614 tc = GNUNET_SERVER_transmit_context_create (client); 1597 tc = GNUNET_SERVER_transmit_context_create (client);
1615 peer = (struct GNUNET_PeerIdentity *) &message[1]; 1598 peer = (struct GNUNET_PeerIdentity *) &message[1];
1616 GNUNET_CONTAINER_multihashmap_get_multiple (neighbours, 1599 GNUNET_CONTAINER_multihashmap_get_multiple (neighbours, &peer->hashPubKey,
1617 &peer->hashPubKey,
1618 &queue_connect_message, tc); 1600 &queue_connect_message, tc);
1619 done_msg.size = htons (sizeof (struct GNUNET_MessageHeader)); 1601 done_msg.size = htons (sizeof (struct GNUNET_MessageHeader));
1620 done_msg.type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END); 1602 done_msg.type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END);
@@ -1631,8 +1613,7 @@ handle_client_have_peer (void *cls,
1631 * @param message iteration request message 1613 * @param message iteration request message
1632 */ 1614 */
1633static void 1615static void
1634handle_client_request_info (void *cls, 1616handle_client_request_info (void *cls, struct GNUNET_SERVER_Client *client,
1635 struct GNUNET_SERVER_Client *client,
1636 const struct GNUNET_MessageHeader *message) 1617 const struct GNUNET_MessageHeader *message)
1637{ 1618{
1638 const struct RequestInfoMessage *rcm; 1619 const struct RequestInfoMessage *rcm;
@@ -1646,8 +1627,8 @@ handle_client_request_info (void *cls,
1646 1627
1647 rdelay = GNUNET_TIME_relative_get_zero (); 1628 rdelay = GNUNET_TIME_relative_get_zero ();
1648#if DEBUG_CORE_CLIENT 1629#if DEBUG_CORE_CLIENT
1649 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service receives `%s' request.\n",
1650 "Core service receives `%s' request.\n", "REQUEST_INFO"); 1631 "REQUEST_INFO");
1651#endif 1632#endif
1652 pos = clients; 1633 pos = clients;
1653 while (pos != NULL) 1634 while (pos != NULL)
@@ -1676,8 +1657,9 @@ handle_client_request_info (void *cls,
1676 GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit, 1657 GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit,
1677 n->bw_out_external_limit).value__) 1658 n->bw_out_external_limit).value__)
1678 { 1659 {
1679 n->bw_out = GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit, 1660 n->bw_out =
1680 n->bw_out_external_limit); 1661 GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit,
1662 n->bw_out_external_limit);
1681 GNUNET_BANDWIDTH_tracker_update_quota (&n->available_recv_window, 1663 GNUNET_BANDWIDTH_tracker_update_quota (&n->available_recv_window,
1682 n->bw_out); 1664 n->bw_out);
1683 GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out); 1665 GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out);
@@ -1690,8 +1672,9 @@ handle_client_request_info (void *cls,
1690 } 1672 }
1691 else if (want_reserv > 0) 1673 else if (want_reserv > 0)
1692 { 1674 {
1693 rdelay = GNUNET_BANDWIDTH_tracker_get_delay (&n->available_recv_window, 1675 rdelay =
1694 want_reserv); 1676 GNUNET_BANDWIDTH_tracker_get_delay (&n->available_recv_window,
1677 want_reserv);
1695 if (rdelay.rel_value == 0) 1678 if (rdelay.rel_value == 0)
1696 got_reserv = want_reserv; 1679 got_reserv = want_reserv;
1697 else 1680 else
@@ -1711,9 +1694,8 @@ handle_client_request_info (void *cls,
1711#if DEBUG_CORE_QUOTA 1694#if DEBUG_CORE_QUOTA
1712 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1695 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1713 "Received reservation request for %d bytes for peer `%4s', reserved %d bytes, suggesting delay of %llu ms\n", 1696 "Received reservation request for %d bytes for peer `%4s', reserved %d bytes, suggesting delay of %llu ms\n",
1714 (int) want_reserv, 1697 (int) want_reserv, GNUNET_i2s (&rcm->peer), (int) got_reserv,
1715 GNUNET_i2s (&rcm->peer), 1698 (unsigned long long) rdelay.rel_value);
1716 (int) got_reserv, (unsigned long long) rdelay.rel_value);
1717#endif 1699#endif
1718 cim.reserved_amount = htonl (got_reserv); 1700 cim.reserved_amount = htonl (got_reserv);
1719 cim.reserve_delay = GNUNET_TIME_relative_hton (rdelay); 1701 cim.reserve_delay = GNUNET_TIME_relative_hton (rdelay);
@@ -1737,8 +1719,8 @@ handle_client_request_info (void *cls,
1737 cim.peer = rcm->peer; 1719 cim.peer = rcm->peer;
1738 cim.rim_id = rcm->rim_id; 1720 cim.rim_id = rcm->rim_id;
1739#if DEBUG_CORE_CLIENT 1721#if DEBUG_CORE_CLIENT
1740 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1722 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message to client.\n",
1741 "Sending `%s' message to client.\n", "CONFIGURATION_INFO"); 1723 "CONFIGURATION_INFO");
1742#endif 1724#endif
1743 send_to_client (pos, &cim.header, GNUNET_NO); 1725 send_to_client (pos, &cim.header, GNUNET_NO);
1744 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1726 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -1808,8 +1790,7 @@ free_neighbour (struct Neighbour *n)
1808 if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) 1790 if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
1809 GNUNET_SCHEDULER_cancel (n->keep_alive_task); 1791 GNUNET_SCHEDULER_cancel (n->keep_alive_task);
1810 if (n->status == PEER_STATE_KEY_CONFIRMED) 1792 if (n->status == PEER_STATE_KEY_CONFIRMED)
1811 GNUNET_STATISTICS_update (stats, 1793 GNUNET_STATISTICS_update (stats, gettext_noop ("# established sessions"),
1812 gettext_noop ("# established sessions"),
1813 -1, GNUNET_NO); 1794 -1, GNUNET_NO);
1814 GNUNET_array_grow (n->ats, n->ats_count, 0); 1795 GNUNET_array_grow (n->ats, n->ats_count, 0);
1815 GNUNET_free_non_null (n->public_key); 1796 GNUNET_free_non_null (n->public_key);
@@ -1851,18 +1832,17 @@ do_encrypt (struct Neighbour *n,
1851 return GNUNET_NO; 1832 return GNUNET_NO;
1852 } 1833 }
1853 GNUNET_assert (size == 1834 GNUNET_assert (size ==
1854 GNUNET_CRYPTO_aes_encrypt (in, 1835 GNUNET_CRYPTO_aes_encrypt (in, (uint16_t) size,
1855 (uint16_t) size,
1856 &n->encrypt_key, iv, out)); 1836 &n->encrypt_key, iv, out));
1857 GNUNET_STATISTICS_update (stats, gettext_noop ("# bytes encrypted"), size, 1837 GNUNET_STATISTICS_update (stats, gettext_noop ("# bytes encrypted"), size,
1858 GNUNET_NO); 1838 GNUNET_NO);
1859#if DEBUG_CORE > 2 1839#if DEBUG_CORE > 2
1860 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1840 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1861 "Encrypted %u bytes for `%4s' using key %u, IV %u\n", 1841 "Encrypted %u bytes for `%4s' using key %u, IV %u\n",
1862 (unsigned int) size, 1842 (unsigned int) size, GNUNET_i2s (&n->peer),
1863 GNUNET_i2s (&n->peer), 1843 (unsigned int) n->encrypt_key.crc32, GNUNET_CRYPTO_crc32_n (iv,
1864 (unsigned int) n->encrypt_key.crc32, 1844 sizeof
1865 GNUNET_CRYPTO_crc32_n (iv, sizeof (iv))); 1845 (iv)));
1866#endif 1846#endif
1867 return GNUNET_OK; 1847 return GNUNET_OK;
1868} 1848}
@@ -1902,38 +1882,36 @@ send_keep_alive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1902 me->deadline = GNUNET_TIME_relative_to_absolute (MAX_PING_DELAY); 1882 me->deadline = GNUNET_TIME_relative_to_absolute (MAX_PING_DELAY);
1903 me->priority = PING_PRIORITY; 1883 me->priority = PING_PRIORITY;
1904 me->size = sizeof (struct PingMessage); 1884 me->size = sizeof (struct PingMessage);
1905 GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, 1885 GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, n->encrypted_tail,
1906 n->encrypted_tail, n->encrypted_tail, me); 1886 n->encrypted_tail, me);
1907 pm = (struct PingMessage *) &me[1]; 1887 pm = (struct PingMessage *) &me[1];
1908 pm->header.size = htons (sizeof (struct PingMessage)); 1888 pm->header.size = htons (sizeof (struct PingMessage));
1909 pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); 1889 pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING);
1910 pm->iv_seed = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 1890 pm->iv_seed =
1911 UINT32_MAX); 1891 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
1912 derive_iv (&iv, &n->encrypt_key, pm->iv_seed, &n->peer); 1892 derive_iv (&iv, &n->encrypt_key, pm->iv_seed, &n->peer);
1913 pp.challenge = n->ping_challenge; 1893 pp.challenge = n->ping_challenge;
1914 pp.target = n->peer; 1894 pp.target = n->peer;
1915#if DEBUG_HANDSHAKE 1895#if DEBUG_HANDSHAKE
1916 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1896 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1917 "Encrypting `%s' message with challenge %u for `%4s' using key %u, IV %u (salt %u).\n", 1897 "Encrypting `%s' message with challenge %u for `%4s' using key %u, IV %u (salt %u).\n",
1918 "PING", 1898 "PING", (unsigned int) n->ping_challenge, GNUNET_i2s (&n->peer),
1919 (unsigned int) n->ping_challenge, 1899 (unsigned int) n->encrypt_key.crc32, GNUNET_CRYPTO_crc32_n (&iv,
1920 GNUNET_i2s (&n->peer), 1900 sizeof
1921 (unsigned int) n->encrypt_key.crc32, 1901 (iv)),
1922 GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), pm->iv_seed); 1902 pm->iv_seed);
1923#endif 1903#endif
1924 do_encrypt (n, 1904 do_encrypt (n, &iv, &pp.target, &pm->target,
1925 &iv, 1905 sizeof (struct PingMessage) - ((void *) &pm->target -
1926 &pp.target, 1906 (void *) pm));
1927 &pm->target,
1928 sizeof (struct PingMessage) -
1929 ((void *) &pm->target - (void *) pm));
1930 process_encrypted_neighbour_queue (n); 1907 process_encrypted_neighbour_queue (n);
1931 /* reschedule PING job */ 1908 /* reschedule PING job */
1932 left = GNUNET_TIME_absolute_get_remaining (get_neighbour_timeout (n)); 1909 left = GNUNET_TIME_absolute_get_remaining (get_neighbour_timeout (n));
1933 retry = GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2), 1910 retry =
1934 MIN_PING_FREQUENCY); 1911 GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2),
1935 n->keep_alive_task 1912 MIN_PING_FREQUENCY);
1936 = GNUNET_SCHEDULER_add_delayed (retry, &send_keep_alive, n); 1913 n->keep_alive_task =
1914 GNUNET_SCHEDULER_add_delayed (retry, &send_keep_alive, n);
1937 1915
1938} 1916}
1939 1917
@@ -1973,16 +1951,15 @@ consider_free_neighbour (struct Neighbour *n)
1973 { 1951 {
1974 if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK) 1952 if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK)
1975 GNUNET_SCHEDULER_cancel (n->dead_clean_task); 1953 GNUNET_SCHEDULER_cancel (n->dead_clean_task);
1976 n->dead_clean_task = GNUNET_SCHEDULER_add_delayed (left, 1954 n->dead_clean_task =
1977 &consider_free_task, n); 1955 GNUNET_SCHEDULER_add_delayed (left, &consider_free_task, n);
1978 return; 1956 return;
1979 } 1957 }
1980 /* actually free the neighbour... */ 1958 /* actually free the neighbour... */
1981 GNUNET_assert (GNUNET_YES == 1959 GNUNET_assert (GNUNET_YES ==
1982 GNUNET_CONTAINER_multihashmap_remove (neighbours, 1960 GNUNET_CONTAINER_multihashmap_remove (neighbours,
1983 &n->peer.hashPubKey, n)); 1961 &n->peer.hashPubKey, n));
1984 GNUNET_STATISTICS_set (stats, 1962 GNUNET_STATISTICS_set (stats, gettext_noop ("# neighbour entries allocated"),
1985 gettext_noop ("# neighbour entries allocated"),
1986 GNUNET_CONTAINER_multihashmap_size (neighbours), 1963 GNUNET_CONTAINER_multihashmap_size (neighbours),
1987 GNUNET_NO); 1964 GNUNET_NO);
1988 free_neighbour (n); 1965 free_neighbour (n);
@@ -2029,9 +2006,9 @@ notify_encrypted_transmit_ready (void *cls, size_t size, void *buf)
2029#if DEBUG_CORE 2006#if DEBUG_CORE
2030 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2007 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2031 "Copied message of type %u and size %u into transport buffer for `%4s'\n", 2008 "Copied message of type %u and size %u into transport buffer for `%4s'\n",
2032 (unsigned int) 2009 (unsigned int) ntohs (((struct GNUNET_MessageHeader *) &m[1])->
2033 ntohs (((struct GNUNET_MessageHeader *) &m[1])->type), 2010 type), (unsigned int) ret,
2034 (unsigned int) ret, GNUNET_i2s (&n->peer)); 2011 GNUNET_i2s (&n->peer));
2035#endif 2012#endif
2036 process_encrypted_neighbour_queue (n); 2013 process_encrypted_neighbour_queue (n);
2037 } 2014 }
@@ -2040,9 +2017,8 @@ notify_encrypted_transmit_ready (void *cls, size_t size, void *buf)
2040#if DEBUG_CORE 2017#if DEBUG_CORE
2041 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2018 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2042 "Transmission of message of type %u and size %u failed\n", 2019 "Transmission of message of type %u and size %u failed\n",
2043 (unsigned int) 2020 (unsigned int) ntohs (((struct GNUNET_MessageHeader *) &m[1])->
2044 ntohs (((struct GNUNET_MessageHeader *) &m[1])->type), 2021 type), (unsigned int) m->size);
2045 (unsigned int) m->size);
2046#endif 2022#endif
2047 } 2023 }
2048 GNUNET_free (m); 2024 GNUNET_free (m);
@@ -2094,14 +2070,13 @@ process_encrypted_neighbour_queue (struct Neighbour *n)
2094#if DEBUG_CORE > 1 2070#if DEBUG_CORE > 1
2095 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2071 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2096 "Asking transport for transmission of %u bytes to `%4s' in next %llu ms\n", 2072 "Asking transport for transmission of %u bytes to `%4s' in next %llu ms\n",
2097 (unsigned int) m->size, 2073 (unsigned int) m->size, GNUNET_i2s (&n->peer),
2098 GNUNET_i2s (&n->peer), 2074 (unsigned long long) GNUNET_TIME_absolute_get_remaining (m->
2099 (unsigned long long) 2075 deadline).
2100 GNUNET_TIME_absolute_get_remaining (m->deadline).rel_value); 2076 rel_value);
2101#endif 2077#endif
2102 n->th = 2078 n->th =
2103 GNUNET_TRANSPORT_notify_transmit_ready (transport, &n->peer, 2079 GNUNET_TRANSPORT_notify_transmit_ready (transport, &n->peer, m->size,
2104 m->size,
2105 m->priority, 2080 m->priority,
2106 GNUNET_TIME_absolute_get_remaining 2081 GNUNET_TIME_absolute_get_remaining
2107 (m->deadline), 2082 (m->deadline),
@@ -2153,16 +2128,15 @@ do_decrypt (struct Neighbour *n,
2153 GNUNET_break (0); 2128 GNUNET_break (0);
2154 return GNUNET_SYSERR; 2129 return GNUNET_SYSERR;
2155 } 2130 }
2156 GNUNET_STATISTICS_update (stats, 2131 GNUNET_STATISTICS_update (stats, gettext_noop ("# bytes decrypted"), size,
2157 gettext_noop ("# bytes decrypted"), 2132 GNUNET_NO);
2158 size, GNUNET_NO);
2159#if DEBUG_CORE > 1 2133#if DEBUG_CORE > 1
2160 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2134 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2161 "Decrypted %u bytes from `%4s' using key %u, IV %u\n", 2135 "Decrypted %u bytes from `%4s' using key %u, IV %u\n",
2162 (unsigned int) size, 2136 (unsigned int) size, GNUNET_i2s (&n->peer),
2163 GNUNET_i2s (&n->peer), 2137 (unsigned int) n->decrypt_key.crc32, GNUNET_CRYPTO_crc32_n (iv,
2164 (unsigned int) n->decrypt_key.crc32, 2138 sizeof
2165 GNUNET_CRYPTO_crc32_n (iv, sizeof (*iv))); 2139 (*iv)));
2166#endif 2140#endif
2167 return GNUNET_OK; 2141 return GNUNET_OK;
2168} 2142}
@@ -2186,8 +2160,8 @@ do_decrypt (struct Neighbour *n,
2186 * defer scheduling overall; in that case, retry_time is set. 2160 * defer scheduling overall; in that case, retry_time is set.
2187 */ 2161 */
2188static size_t 2162static size_t
2189select_messages (struct Neighbour *n, 2163select_messages (struct Neighbour *n, size_t size,
2190 size_t size, struct GNUNET_TIME_Relative *retry_time) 2164 struct GNUNET_TIME_Relative *retry_time)
2191{ 2165{
2192 struct MessageEntry *pos; 2166 struct MessageEntry *pos;
2193 struct MessageEntry *min; 2167 struct MessageEntry *min;
@@ -2253,8 +2227,8 @@ select_messages (struct Neighbour *n,
2253 { 2227 {
2254 // FIXME: HUH? Check! 2228 // FIXME: HUH? Check!
2255 t = pos->deadline; 2229 t = pos->deadline;
2256 avail += GNUNET_BANDWIDTH_value_get_available_until (n->bw_out, 2230 avail +=
2257 delta); 2231 GNUNET_BANDWIDTH_value_get_available_until (n->bw_out, delta);
2258 } 2232 }
2259 if (avail < pos->size) 2233 if (avail < pos->size)
2260 { 2234 {
@@ -2267,9 +2241,10 @@ select_messages (struct Neighbour *n,
2267 /* update slack, considering both its absolute deadline 2241 /* update slack, considering both its absolute deadline
2268 * and relative deadlines caused by other messages 2242 * and relative deadlines caused by other messages
2269 * with their respective load */ 2243 * with their respective load */
2270 slack = GNUNET_TIME_relative_min (slack, 2244 slack =
2271 GNUNET_BANDWIDTH_value_get_delay_for 2245 GNUNET_TIME_relative_min (slack,
2272 (n->bw_out, avail)); 2246 GNUNET_BANDWIDTH_value_get_delay_for
2247 (n->bw_out, avail));
2273 if (pos->deadline.abs_value <= now.abs_value) 2248 if (pos->deadline.abs_value <= now.abs_value)
2274 { 2249 {
2275 /* now or never */ 2250 /* now or never */
@@ -2278,9 +2253,10 @@ select_messages (struct Neighbour *n,
2278 else if (GNUNET_YES == pos->got_slack) 2253 else if (GNUNET_YES == pos->got_slack)
2279 { 2254 {
2280 /* should be soon now! */ 2255 /* should be soon now! */
2281 slack = GNUNET_TIME_relative_min (slack, 2256 slack =
2282 GNUNET_TIME_absolute_get_remaining 2257 GNUNET_TIME_relative_min (slack,
2283 (pos->slack_deadline)); 2258 GNUNET_TIME_absolute_get_remaining
2259 (pos->slack_deadline));
2284 } 2260 }
2285 else 2261 else
2286 { 2262 {
@@ -2289,9 +2265,10 @@ select_messages (struct Neighbour *n,
2289 GNUNET_TIME_absolute_get_difference 2265 GNUNET_TIME_absolute_get_difference
2290 (now, pos->deadline)); 2266 (now, pos->deadline));
2291 pos->got_slack = GNUNET_YES; 2267 pos->got_slack = GNUNET_YES;
2292 pos->slack_deadline = GNUNET_TIME_absolute_min (pos->deadline, 2268 pos->slack_deadline =
2293 GNUNET_TIME_relative_to_absolute 2269 GNUNET_TIME_absolute_min (pos->deadline,
2294 (GNUNET_CONSTANTS_MAX_CORK_DELAY)); 2270 GNUNET_TIME_relative_to_absolute
2271 (GNUNET_CONSTANTS_MAX_CORK_DELAY));
2295 } 2272 }
2296 } 2273 }
2297 } 2274 }
@@ -2336,8 +2313,8 @@ select_messages (struct Neighbour *n,
2336#if DEBUG_CORE 2313#if DEBUG_CORE
2337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2338 "Deferring transmission for %llums due to underfull message buffer size (%u/%u)\n", 2315 "Deferring transmission for %llums due to underfull message buffer size (%u/%u)\n",
2339 (unsigned long long) retry_time->rel_value, 2316 (unsigned long long) retry_time->rel_value, (unsigned int) off,
2340 (unsigned int) off, (unsigned int) size); 2317 (unsigned int) size);
2341#endif 2318#endif
2342 return 0; 2319 return 0;
2343 } 2320 }
@@ -2371,9 +2348,8 @@ select_messages (struct Neighbour *n,
2371#if DEBUG_CORE 2348#if DEBUG_CORE
2372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2349 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2373 "Selected %llu/%llu bytes of %u/%u plaintext messages for transmission to `%4s'.\n", 2350 "Selected %llu/%llu bytes of %u/%u plaintext messages for transmission to `%4s'.\n",
2374 (unsigned long long) off, (unsigned long long) tsize, 2351 (unsigned long long) off, (unsigned long long) tsize, queue_size,
2375 queue_size, (unsigned int) MAX_PEER_QUEUE_SIZE, 2352 (unsigned int) MAX_PEER_QUEUE_SIZE, GNUNET_i2s (&n->peer));
2376 GNUNET_i2s (&n->peer));
2377#endif 2353#endif
2378 return off; 2354 return off;
2379} 2355}
@@ -2392,9 +2368,7 @@ select_messages (struct Neighbour *n,
2392 * @return number of bytes written to buf (can be zero) 2368 * @return number of bytes written to buf (can be zero)
2393 */ 2369 */
2394static size_t 2370static size_t
2395batch_message (struct Neighbour *n, 2371batch_message (struct Neighbour *n, char *buf, size_t size,
2396 char *buf,
2397 size_t size,
2398 struct GNUNET_TIME_Absolute *deadline, 2372 struct GNUNET_TIME_Absolute *deadline,
2399 struct GNUNET_TIME_Relative *retry_time, unsigned int *priority) 2373 struct GNUNET_TIME_Relative *retry_time, unsigned int *priority)
2400{ 2374{
@@ -2439,10 +2413,11 @@ batch_message (struct Neighbour *n,
2439 GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct NotifyTrafficMessage)) 2413 GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct NotifyTrafficMessage))
2440 { 2414 {
2441 memcpy (&ntm[1], &pos[1], pos->size); 2415 memcpy (&ntm[1], &pos[1], pos->size);
2442 ntm->header.size = htons (sizeof (struct NotifyTrafficMessage) + 2416 ntm->header.size =
2443 sizeof (struct GNUNET_MessageHeader)); 2417 htons (sizeof (struct NotifyTrafficMessage) +
2444 send_to_all_clients (&ntm->header, 2418 sizeof (struct GNUNET_MessageHeader));
2445 GNUNET_YES, GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND); 2419 send_to_all_clients (&ntm->header, GNUNET_YES,
2420 GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND);
2446 } 2421 }
2447 else 2422 else
2448 { 2423 {
@@ -2450,10 +2425,10 @@ batch_message (struct Neighbour *n,
2450 * least the 'hdr' type */ 2425 * least the 'hdr' type */
2451 memcpy (&ntm[1], &pos[1], sizeof (struct GNUNET_MessageHeader)); 2426 memcpy (&ntm[1], &pos[1], sizeof (struct GNUNET_MessageHeader));
2452 } 2427 }
2453 ntm->header.size = htons (sizeof (struct NotifyTrafficMessage) + 2428 ntm->header.size =
2454 pos->size); 2429 htons (sizeof (struct NotifyTrafficMessage) + pos->size);
2455 send_to_all_clients (&ntm->header, 2430 send_to_all_clients (&ntm->header, GNUNET_YES,
2456 GNUNET_YES, GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND); 2431 GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND);
2457#if DEBUG_HANDSHAKE 2432#if DEBUG_HANDSHAKE
2458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2433 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2459 "Encrypting %u bytes with message of type %u and size %u\n", 2434 "Encrypting %u bytes with message of type %u and size %u\n",
@@ -2461,8 +2436,8 @@ batch_message (struct Neighbour *n,
2461 (unsigned int) 2436 (unsigned int)
2462 ntohs (((const struct GNUNET_MessageHeader *) &pos[1])->type), 2437 ntohs (((const struct GNUNET_MessageHeader *) &pos[1])->type),
2463 (unsigned int) 2438 (unsigned int)
2464 ntohs (((const struct GNUNET_MessageHeader *) 2439 ntohs (((const struct GNUNET_MessageHeader *) &pos[1])->
2465 &pos[1])->size)); 2440 size));
2466#endif 2441#endif
2467 /* copy for encrypted transmission */ 2442 /* copy for encrypted transmission */
2468 memcpy (&buf[ret], &pos[1], pos->size); 2443 memcpy (&buf[ret], &pos[1], pos->size);
@@ -2473,8 +2448,9 @@ batch_message (struct Neighbour *n,
2473 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2448 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2474 "Adding plaintext message of size %u with deadline %llu ms to batch\n", 2449 "Adding plaintext message of size %u with deadline %llu ms to batch\n",
2475 (unsigned int) pos->size, 2450 (unsigned int) pos->size,
2476 (unsigned long long) 2451 (unsigned long long) GNUNET_TIME_absolute_get_remaining (pos->
2477 GNUNET_TIME_absolute_get_remaining (pos->deadline).rel_value); 2452 deadline).
2453 rel_value);
2478#endif 2454#endif
2479 deadline->abs_value = 2455 deadline->abs_value =
2480 GNUNET_MIN (deadline->abs_value, pos->deadline.abs_value); 2456 GNUNET_MIN (deadline->abs_value, pos->deadline.abs_value);
@@ -2584,8 +2560,8 @@ set_key_retry_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2584 struct Neighbour *n = cls; 2560 struct Neighbour *n = cls;
2585 2561
2586#if DEBUG_CORE 2562#if DEBUG_CORE
2587 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2563 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Retrying key transmission to `%4s'\n",
2588 "Retrying key transmission to `%4s'\n", GNUNET_i2s (&n->peer)); 2564 GNUNET_i2s (&n->peer));
2589#endif 2565#endif
2590 n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; 2566 n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
2591 n->set_key_retry_frequency = 2567 n->set_key_retry_frequency =
@@ -2632,9 +2608,9 @@ process_plaintext_neighbour_queue (struct Neighbour *n)
2632 return; 2608 return;
2633 case PEER_STATE_KEY_SENT: 2609 case PEER_STATE_KEY_SENT:
2634 if (n->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK) 2610 if (n->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK)
2635 n->retry_set_key_task 2611 n->retry_set_key_task =
2636 = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency, 2612 GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency,
2637 &set_key_retry_task, n); 2613 &set_key_retry_task, n);
2638#if DEBUG_CORE 2614#if DEBUG_CORE
2639 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2615 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2640 "Not yet connected to `%4s', deferring processing of plaintext messages.\n", 2616 "Not yet connected to `%4s', deferring processing of plaintext messages.\n",
@@ -2643,9 +2619,9 @@ process_plaintext_neighbour_queue (struct Neighbour *n)
2643 return; 2619 return;
2644 case PEER_STATE_KEY_RECEIVED: 2620 case PEER_STATE_KEY_RECEIVED:
2645 if (n->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK) 2621 if (n->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK)
2646 n->retry_set_key_task 2622 n->retry_set_key_task =
2647 = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency, 2623 GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency,
2648 &set_key_retry_task, n); 2624 &set_key_retry_task, n);
2649#if DEBUG_CORE 2625#if DEBUG_CORE
2650 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2626 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2651 "Not yet connected to `%4s', deferring processing of plaintext messages.\n", 2627 "Not yet connected to `%4s', deferring processing of plaintext messages.\n",
@@ -2680,10 +2656,10 @@ process_plaintext_neighbour_queue (struct Neighbour *n)
2680 deadline = GNUNET_TIME_UNIT_FOREVER_ABS; 2656 deadline = GNUNET_TIME_UNIT_FOREVER_ABS;
2681 priority = 0; 2657 priority = 0;
2682 used = sizeof (struct EncryptedMessage); 2658 used = sizeof (struct EncryptedMessage);
2683 used += batch_message (n, 2659 used +=
2684 &pbuf[used], 2660 batch_message (n, &pbuf[used],
2685 GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE, 2661 GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE, &deadline,
2686 &deadline, &retry_time, &priority); 2662 &retry_time, &priority);
2687 if (used == sizeof (struct EncryptedMessage)) 2663 if (used == sizeof (struct EncryptedMessage))
2688 { 2664 {
2689#if DEBUG_CORE > 1 2665#if DEBUG_CORE > 1
@@ -2693,8 +2669,8 @@ process_plaintext_neighbour_queue (struct Neighbour *n)
2693#endif 2669#endif
2694 /* no messages selected for sending, try again later... */ 2670 /* no messages selected for sending, try again later... */
2695 n->retry_plaintext_task = 2671 n->retry_plaintext_task =
2696 GNUNET_SCHEDULER_add_delayed (retry_time, 2672 GNUNET_SCHEDULER_add_delayed (retry_time, &retry_plaintext_processing,
2697 &retry_plaintext_processing, n); 2673 n);
2698 return; 2674 return;
2699 } 2675 }
2700#if DEBUG_CORE_QUOTA 2676#if DEBUG_CORE_QUOTA
@@ -2729,10 +2705,7 @@ process_plaintext_neighbour_queue (struct Neighbour *n)
2729 GNUNET_TIME_absolute_get_remaining (deadline).rel_value); 2705 GNUNET_TIME_absolute_get_remaining (deadline).rel_value);
2730#endif 2706#endif
2731 GNUNET_assert (GNUNET_OK == 2707 GNUNET_assert (GNUNET_OK ==
2732 do_encrypt (n, 2708 do_encrypt (n, &iv, &ph->sequence_number, &em->sequence_number,
2733 &iv,
2734 &ph->sequence_number,
2735 &em->sequence_number,
2736 used - ENCRYPTED_HEADER_SIZE)); 2709 used - ENCRYPTED_HEADER_SIZE));
2737 derive_auth_key (&auth_key, &n->encrypt_key, ph->iv_seed, 2710 derive_auth_key (&auth_key, &n->encrypt_key, ph->iv_seed,
2738 n->encrypt_key_created); 2711 n->encrypt_key_created);
@@ -2747,8 +2720,8 @@ process_plaintext_neighbour_queue (struct Neighbour *n)
2747 GNUNET_h2s (&em->hmac)); 2720 GNUNET_h2s (&em->hmac));
2748#endif 2721#endif
2749 /* append to transmission list */ 2722 /* append to transmission list */
2750 GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, 2723 GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, n->encrypted_tail,
2751 n->encrypted_tail, n->encrypted_tail, me); 2724 n->encrypted_tail, me);
2752 process_encrypted_neighbour_queue (n); 2725 process_encrypted_neighbour_queue (n);
2753 schedule_peer_messages (n); 2726 schedule_peer_messages (n);
2754} 2727}
@@ -2761,9 +2734,9 @@ process_plaintext_neighbour_queue (struct Neighbour *n)
2761 * @param cls neighbour for the quota update 2734 * @param cls neighbour for the quota update
2762 * @param tc context 2735 * @param tc context
2763 */ 2736 */
2764static void 2737static void neighbour_quota_update (void *cls,
2765neighbour_quota_update (void *cls, 2738 const struct GNUNET_SCHEDULER_TaskContext
2766 const struct GNUNET_SCHEDULER_TaskContext *tc); 2739 *tc);
2767 2740
2768 2741
2769/** 2742/**
@@ -2775,9 +2748,9 @@ static void
2775schedule_quota_update (struct Neighbour *n) 2748schedule_quota_update (struct Neighbour *n)
2776{ 2749{
2777 GNUNET_assert (n->quota_update_task == GNUNET_SCHEDULER_NO_TASK); 2750 GNUNET_assert (n->quota_update_task == GNUNET_SCHEDULER_NO_TASK);
2778 n->quota_update_task 2751 n->quota_update_task =
2779 = GNUNET_SCHEDULER_add_delayed (QUOTA_UPDATE_FREQUENCY, 2752 GNUNET_SCHEDULER_add_delayed (QUOTA_UPDATE_FREQUENCY,
2780 &neighbour_quota_update, n); 2753 &neighbour_quota_update, n);
2781} 2754}
2782 2755
2783 2756
@@ -2808,12 +2781,11 @@ create_neighbour (const struct GNUNET_PeerIdentity *pid)
2808 n->bw_out = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; 2781 n->bw_out = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT;
2809 n->bw_out_internal_limit = GNUNET_BANDWIDTH_value_init (UINT32_MAX); 2782 n->bw_out_internal_limit = GNUNET_BANDWIDTH_value_init (UINT32_MAX);
2810 n->bw_out_external_limit = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; 2783 n->bw_out_external_limit = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT;
2811 n->ping_challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 2784 n->ping_challenge =
2812 UINT32_MAX); 2785 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
2813 GNUNET_assert (GNUNET_OK == 2786 GNUNET_assert (GNUNET_OK ==
2814 GNUNET_CONTAINER_multihashmap_put (neighbours, 2787 GNUNET_CONTAINER_multihashmap_put (neighbours,
2815 &n->peer.hashPubKey, 2788 &n->peer.hashPubKey, n,
2816 n,
2817 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 2789 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
2818 GNUNET_STATISTICS_set (stats, gettext_noop ("# neighbour entries allocated"), 2790 GNUNET_STATISTICS_set (stats, gettext_noop ("# neighbour entries allocated"),
2819 GNUNET_CONTAINER_multihashmap_size (neighbours), 2791 GNUNET_CONTAINER_multihashmap_size (neighbours),
@@ -2832,8 +2804,7 @@ create_neighbour (const struct GNUNET_PeerIdentity *pid)
2832 * @param message the "struct SendMessage" 2804 * @param message the "struct SendMessage"
2833 */ 2805 */
2834static void 2806static void
2835handle_client_send (void *cls, 2807handle_client_send (void *cls, struct GNUNET_SERVER_Client *client,
2836 struct GNUNET_SERVER_Client *client,
2837 const struct GNUNET_MessageHeader *message) 2808 const struct GNUNET_MessageHeader *message)
2838{ 2809{
2839 const struct SendMessage *sm; 2810 const struct SendMessage *sm;
@@ -2852,8 +2823,7 @@ handle_client_send (void *cls,
2852 sizeof (struct SendMessage) + sizeof (struct GNUNET_MessageHeader)) 2823 sizeof (struct SendMessage) + sizeof (struct GNUNET_MessageHeader))
2853 { 2824 {
2854 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2825 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2855 "msize is %u, should be at least %u (in %s:%d)\n", 2826 "msize is %u, should be at least %u (in %s:%d)\n", msize,
2856 msize,
2857 sizeof (struct SendMessage) + 2827 sizeof (struct SendMessage) +
2858 sizeof (struct GNUNET_MessageHeader), __FILE__, __LINE__); 2828 sizeof (struct GNUNET_MessageHeader), __FILE__, __LINE__);
2859 GNUNET_break (0); 2829 GNUNET_break (0);
@@ -2867,17 +2837,14 @@ handle_client_send (void *cls,
2867 memcmp (&sm->peer, &my_identity, sizeof (struct GNUNET_PeerIdentity))) 2837 memcmp (&sm->peer, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
2868 { 2838 {
2869 /* loopback */ 2839 /* loopback */
2870 GNUNET_SERVER_mst_receive (mst, 2840 GNUNET_SERVER_mst_receive (mst, &self, (const char *) &sm[1], msize,
2871 &self, 2841 GNUNET_YES, GNUNET_NO);
2872 (const char *) &sm[1],
2873 msize, GNUNET_YES, GNUNET_NO);
2874 if (client != NULL) 2842 if (client != NULL)
2875 GNUNET_SERVER_receive_done (client, GNUNET_OK); 2843 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2876 return; 2844 return;
2877 } 2845 }
2878 n = find_neighbour (&sm->peer); 2846 n = find_neighbour (&sm->peer);
2879 if ((n == NULL) || 2847 if ((n == NULL) || (GNUNET_YES != n->is_connected) ||
2880 (GNUNET_YES != n->is_connected) ||
2881 (n->status != PEER_STATE_KEY_CONFIRMED)) 2848 (n->status != PEER_STATE_KEY_CONFIRMED))
2882 { 2849 {
2883 /* attempt to send message to peer that is not connected anymore 2850 /* attempt to send message to peer that is not connected anymore
@@ -2932,8 +2899,7 @@ handle_client_send (void *cls,
2932#if DEBUG_CORE 2899#if DEBUG_CORE
2933 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2900 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2934 "Queue full (%u/%u), discarding new request (%u bytes of type %u)\n", 2901 "Queue full (%u/%u), discarding new request (%u bytes of type %u)\n",
2935 queue_size, 2902 queue_size, (unsigned int) MAX_PEER_QUEUE_SIZE,
2936 (unsigned int) MAX_PEER_QUEUE_SIZE,
2937 (unsigned int) msize, (unsigned int) ntohs (message->type)); 2903 (unsigned int) msize, (unsigned int) ntohs (message->type));
2938#endif 2904#endif
2939 GNUNET_STATISTICS_update (stats, 2905 GNUNET_STATISTICS_update (stats,
@@ -3004,15 +2970,14 @@ handle_client_send (void *cls,
3004 * @param message the "struct ConnectMessage" 2970 * @param message the "struct ConnectMessage"
3005 */ 2971 */
3006static void 2972static void
3007handle_client_request_connect (void *cls, 2973handle_client_request_connect (void *cls, struct GNUNET_SERVER_Client *client,
3008 struct GNUNET_SERVER_Client *client,
3009 const struct GNUNET_MessageHeader *message) 2974 const struct GNUNET_MessageHeader *message)
3010{ 2975{
3011 const struct ConnectMessage *cm = (const struct ConnectMessage *) message; 2976 const struct ConnectMessage *cm = (const struct ConnectMessage *) message;
3012 struct Neighbour *n; 2977 struct Neighbour *n;
3013 2978
3014 if (0 == memcmp (&cm->peer, 2979 if (0 ==
3015 &my_identity, sizeof (struct GNUNET_PeerIdentity))) 2980 memcmp (&cm->peer, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
3016 { 2981 {
3017 /* In this case a client has asked us to connect to ourselves, not really an error! */ 2982 /* In this case a client has asked us to connect to ourselves, not really an error! */
3018 GNUNET_SERVER_receive_done (client, GNUNET_OK); 2983 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -3025,8 +2990,8 @@ handle_client_request_connect (void *cls,
3025 "REQUEST_CONNECT", GNUNET_i2s (&cm->peer)); 2990 "REQUEST_CONNECT", GNUNET_i2s (&cm->peer));
3026#endif 2991#endif
3027 GNUNET_STATISTICS_update (stats, 2992 GNUNET_STATISTICS_update (stats,
3028 gettext_noop ("# connection requests received"), 2993 gettext_noop ("# connection requests received"), 1,
3029 1, GNUNET_NO); 2994 GNUNET_NO);
3030 GNUNET_SERVER_receive_done (client, GNUNET_OK); 2995 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3031 n = find_neighbour (&cm->peer); 2996 n = find_neighbour (&cm->peer);
3032 if ((n == NULL) || (GNUNET_YES != n->is_connected)) 2997 if ((n == NULL) || (GNUNET_YES != n->is_connected))
@@ -3054,8 +3019,7 @@ handle_client_request_connect (void *cls,
3054 * @param err_msg NULL if successful, otherwise contains error message 3019 * @param err_msg NULL if successful, otherwise contains error message
3055 */ 3020 */
3056static void 3021static void
3057process_hello_retry_send_key (void *cls, 3022process_hello_retry_send_key (void *cls, const struct GNUNET_PeerIdentity *peer,
3058 const struct GNUNET_PeerIdentity *peer,
3059 const struct GNUNET_HELLO_Message *hello, 3023 const struct GNUNET_HELLO_Message *hello,
3060 const char *err_msg) 3024 const char *err_msg)
3061{ 3025{
@@ -3071,8 +3035,7 @@ process_hello_retry_send_key (void *cls,
3071 if (peer == NULL) 3035 if (peer == NULL)
3072 { 3036 {
3073#if DEBUG_CORE 3037#if DEBUG_CORE
3074 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3038 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Entered `%s' and `%s' is NULL!\n",
3075 "Entered `%s' and `%s' is NULL!\n",
3076 "process_hello_retry_send_key", "peer"); 3039 "process_hello_retry_send_key", "peer");
3077#endif 3040#endif
3078 n->pitr = NULL; 3041 n->pitr = NULL;
@@ -3101,16 +3064,15 @@ process_hello_retry_send_key (void *cls,
3101 ("# Delayed connecting due to lack of public key"), 3064 ("# Delayed connecting due to lack of public key"),
3102 1, GNUNET_NO); 3065 1, GNUNET_NO);
3103 if (GNUNET_SCHEDULER_NO_TASK == n->retry_set_key_task) 3066 if (GNUNET_SCHEDULER_NO_TASK == n->retry_set_key_task)
3104 n->retry_set_key_task 3067 n->retry_set_key_task =
3105 = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency, 3068 GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency,
3106 &set_key_retry_task, n); 3069 &set_key_retry_task, n);
3107 } 3070 }
3108 return; 3071 return;
3109 } 3072 }
3110 3073
3111#if DEBUG_CORE 3074#if DEBUG_CORE
3112 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3075 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Entered `%s' for peer `%4s'\n",
3113 "Entered `%s' for peer `%4s'\n",
3114 "process_hello_retry_send_key", GNUNET_i2s (peer)); 3076 "process_hello_retry_send_key", GNUNET_i2s (peer));
3115#endif 3077#endif
3116 if (n->public_key != NULL) 3078 if (n->public_key != NULL)
@@ -3196,11 +3158,11 @@ send_key (struct Neighbour *n)
3196 GNUNET_i2s (&n->peer)); 3158 GNUNET_i2s (&n->peer));
3197#endif 3159#endif
3198 GNUNET_assert (n->pitr == NULL); 3160 GNUNET_assert (n->pitr == NULL);
3199 n->pitr = GNUNET_PEERINFO_iterate (peerinfo, 3161 n->pitr =
3200 &n->peer, 3162 GNUNET_PEERINFO_iterate (peerinfo, &n->peer,
3201 GNUNET_TIME_relative_multiply 3163 GNUNET_TIME_relative_multiply
3202 (GNUNET_TIME_UNIT_SECONDS, 20), 3164 (GNUNET_TIME_UNIT_SECONDS, 20),
3203 &process_hello_retry_send_key, n); 3165 &process_hello_retry_send_key, n);
3204 return; 3166 return;
3205 } 3167 }
3206 pos = n->encrypted_head; 3168 pos = n->encrypted_head;
@@ -3212,8 +3174,8 @@ send_key (struct Neighbour *n)
3212 { 3174 {
3213#if DEBUG_CORE 3175#if DEBUG_CORE
3214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3215 "`%s' message for `%4s' queued already\n", 3177 "`%s' message for `%4s' queued already\n", "SET_KEY",
3216 "SET_KEY", GNUNET_i2s (&n->peer)); 3178 GNUNET_i2s (&n->peer));
3217#endif 3179#endif
3218 goto trigger_processing; 3180 goto trigger_processing;
3219 } 3181 }
@@ -3257,13 +3219,15 @@ send_key (struct Neighbour *n)
3257 me->is_setkey = GNUNET_YES; 3219 me->is_setkey = GNUNET_YES;
3258 me->got_slack = GNUNET_YES; /* do not defer this one! */ 3220 me->got_slack = GNUNET_YES; /* do not defer this one! */
3259 me->sender_status = n->status; 3221 me->sender_status = n->status;
3260 GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, 3222 GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, n->encrypted_tail,
3261 n->encrypted_tail, n->encrypted_tail, me); 3223 n->encrypted_tail, me);
3262 sm = (struct SetKeyMessage *) &me[1]; 3224 sm = (struct SetKeyMessage *) &me[1];
3263 sm->header.size = htons (sizeof (struct SetKeyMessage)); 3225 sm->header.size = htons (sizeof (struct SetKeyMessage));
3264 sm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SET_KEY); 3226 sm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SET_KEY);
3265 sm->sender_status = htonl ((int32_t) ((n->status == PEER_STATE_DOWN) ? 3227 sm->sender_status =
3266 PEER_STATE_KEY_SENT : n->status)); 3228 htonl ((int32_t)
3229 ((n->status ==
3230 PEER_STATE_DOWN) ? PEER_STATE_KEY_SENT : n->status));
3267 sm->purpose.size = 3231 sm->purpose.size =
3268 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + 3232 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
3269 sizeof (struct GNUNET_TIME_AbsoluteNBO) + 3233 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
@@ -3291,18 +3255,13 @@ send_key (struct Neighbour *n)
3291#if DEBUG_HANDSHAKE 3255#if DEBUG_HANDSHAKE
3292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3293 "Encrypting `%s' and `%s' messages with challenge %u for `%4s' using key %u, IV %u (salt %u).\n", 3257 "Encrypting `%s' and `%s' messages with challenge %u for `%4s' using key %u, IV %u (salt %u).\n",
3294 "SET_KEY", "PING", 3258 "SET_KEY", "PING", (unsigned int) n->ping_challenge,
3295 (unsigned int) n->ping_challenge, 3259 GNUNET_i2s (&n->peer), (unsigned int) n->encrypt_key.crc32,
3296 GNUNET_i2s (&n->peer),
3297 (unsigned int) n->encrypt_key.crc32,
3298 GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), pm->iv_seed); 3260 GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), pm->iv_seed);
3299#endif 3261#endif
3300 do_encrypt (n, 3262 do_encrypt (n, &iv, &pp.target, &pm->target,
3301 &iv, 3263 sizeof (struct PingMessage) - ((void *) &pm->target -
3302 &pp.target, 3264 (void *) pm));
3303 &pm->target,
3304 sizeof (struct PingMessage) -
3305 ((void *) &pm->target - (void *) pm));
3306 GNUNET_STATISTICS_update (stats, 3265 GNUNET_STATISTICS_update (stats,
3307 gettext_noop 3266 gettext_noop
3308 ("# SET_KEY and PING messages created"), 1, 3267 ("# SET_KEY and PING messages created"), 1,
@@ -3310,18 +3269,18 @@ send_key (struct Neighbour *n)
3310#if DEBUG_CORE 3269#if DEBUG_CORE
3311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3312 "Have %llu ms left for `%s' transmission.\n", 3271 "Have %llu ms left for `%s' transmission.\n",
3313 (unsigned long long) 3272 (unsigned long long) GNUNET_TIME_absolute_get_remaining (me->
3314 GNUNET_TIME_absolute_get_remaining (me->deadline).rel_value, 3273 deadline).
3315 "SET_KEY"); 3274 rel_value, "SET_KEY");
3316#endif 3275#endif
3317trigger_processing: 3276trigger_processing:
3318 /* trigger queue processing */ 3277 /* trigger queue processing */
3319 process_encrypted_neighbour_queue (n); 3278 process_encrypted_neighbour_queue (n);
3320 if ((n->status != PEER_STATE_KEY_CONFIRMED) && 3279 if ((n->status != PEER_STATE_KEY_CONFIRMED) &&
3321 (GNUNET_SCHEDULER_NO_TASK == n->retry_set_key_task)) 3280 (GNUNET_SCHEDULER_NO_TASK == n->retry_set_key_task))
3322 n->retry_set_key_task 3281 n->retry_set_key_task =
3323 = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency, 3282 GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency,
3324 &set_key_retry_task, n); 3283 &set_key_retry_task, n);
3325} 3284}
3326 3285
3327 3286
@@ -3334,11 +3293,9 @@ trigger_processing:
3334 * @param ats performance data 3293 * @param ats performance data
3335 * @param ats_count number of entries in ats (excluding 0-termination) 3294 * @param ats_count number of entries in ats (excluding 0-termination)
3336 */ 3295 */
3337static void 3296static void handle_set_key (struct Neighbour *n, const struct SetKeyMessage *m,
3338handle_set_key (struct Neighbour *n, 3297 const struct GNUNET_TRANSPORT_ATS_Information *ats,
3339 const struct SetKeyMessage *m, 3298 uint32_t ats_count);
3340 const struct GNUNET_TRANSPORT_ATS_Information *ats,
3341 uint32_t ats_count);
3342 3299
3343 3300
3344 3301
@@ -3450,8 +3407,7 @@ update_neighbour_performance (struct Neighbour *n,
3450 * @param ats_count number of entries in ats (excluding 0-termination) 3407 * @param ats_count number of entries in ats (excluding 0-termination)
3451 */ 3408 */
3452static void 3409static void
3453handle_ping (struct Neighbour *n, 3410handle_ping (struct Neighbour *n, const struct PingMessage *m,
3454 const struct PingMessage *m,
3455 const struct GNUNET_TRANSPORT_ATS_Information *ats, 3411 const struct GNUNET_TRANSPORT_ATS_Information *ats,
3456 uint32_t ats_count) 3412 uint32_t ats_count)
3457{ 3413{
@@ -3463,32 +3419,28 @@ handle_ping (struct Neighbour *n,
3463 3419
3464#if DEBUG_CORE 3420#if DEBUG_CORE
3465 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3421 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3466 "Core service receives `%s' request from `%4s'.\n", 3422 "Core service receives `%s' request from `%4s'.\n", "PING",
3467 "PING", GNUNET_i2s (&n->peer)); 3423 GNUNET_i2s (&n->peer));
3468#endif 3424#endif
3469 derive_iv (&iv, &n->decrypt_key, m->iv_seed, &my_identity); 3425 derive_iv (&iv, &n->decrypt_key, m->iv_seed, &my_identity);
3470 if (GNUNET_OK != 3426 if (GNUNET_OK !=
3471 do_decrypt (n, 3427 do_decrypt (n, &iv, &m->target, &t.target,
3472 &iv, 3428 sizeof (struct PingMessage) - ((void *) &m->target -
3473 &m->target, 3429 (void *) m)))
3474 &t.target,
3475 sizeof (struct PingMessage) -
3476 ((void *) &m->target - (void *) m)))
3477 return; 3430 return;
3478#if DEBUG_HANDSHAKE 3431#if DEBUG_HANDSHAKE
3479 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3432 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3480 "Decrypted `%s' to `%4s' with challenge %u decrypted using key %u, IV %u (salt %u)\n", 3433 "Decrypted `%s' to `%4s' with challenge %u decrypted using key %u, IV %u (salt %u)\n",
3481 "PING", 3434 "PING", GNUNET_i2s (&t.target), (unsigned int) t.challenge,
3482 GNUNET_i2s (&t.target), 3435 (unsigned int) n->decrypt_key.crc32, GNUNET_CRYPTO_crc32_n (&iv,
3483 (unsigned int) t.challenge, 3436 sizeof
3484 (unsigned int) n->decrypt_key.crc32, 3437 (iv)),
3485 GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), m->iv_seed); 3438 m->iv_seed);
3486#endif 3439#endif
3487 GNUNET_STATISTICS_update (stats, 3440 GNUNET_STATISTICS_update (stats, gettext_noop ("# PING messages decrypted"),
3488 gettext_noop ("# PING messages decrypted"),
3489 1, GNUNET_NO); 3441 1, GNUNET_NO);
3490 if (0 != memcmp (&t.target, 3442 if (0 !=
3491 &my_identity, sizeof (struct GNUNET_PeerIdentity))) 3443 memcmp (&t.target, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
3492 { 3444 {
3493 char sender[9]; 3445 char sender[9];
3494 char peer[9]; 3446 char peer[9];
@@ -3505,8 +3457,8 @@ handle_ping (struct Neighbour *n,
3505 update_neighbour_performance (n, ats, ats_count); 3457 update_neighbour_performance (n, ats, ats_count);
3506 me = GNUNET_malloc (sizeof (struct MessageEntry) + 3458 me = GNUNET_malloc (sizeof (struct MessageEntry) +
3507 sizeof (struct PongMessage)); 3459 sizeof (struct PongMessage));
3508 GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, 3460 GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, n->encrypted_tail,
3509 n->encrypted_tail, n->encrypted_tail, me); 3461 n->encrypted_tail, me);
3510 me->deadline = GNUNET_TIME_relative_to_absolute (MAX_PONG_DELAY); 3462 me->deadline = GNUNET_TIME_relative_to_absolute (MAX_PONG_DELAY);
3511 me->priority = PONG_PRIORITY; 3463 me->priority = PONG_PRIORITY;
3512 me->size = sizeof (struct PongMessage); 3464 me->size = sizeof (struct PongMessage);
@@ -3519,22 +3471,19 @@ handle_ping (struct Neighbour *n,
3519 tp->iv_seed = 3471 tp->iv_seed =
3520 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); 3472 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
3521 derive_pong_iv (&iv, &n->encrypt_key, tp->iv_seed, t.challenge, &n->peer); 3473 derive_pong_iv (&iv, &n->encrypt_key, tp->iv_seed, t.challenge, &n->peer);
3522 do_encrypt (n, 3474 do_encrypt (n, &iv, &tx.challenge, &tp->challenge,
3523 &iv, 3475 sizeof (struct PongMessage) - ((void *) &tp->challenge -
3524 &tx.challenge, 3476 (void *) tp));
3525 &tp->challenge, 3477 GNUNET_STATISTICS_update (stats, gettext_noop ("# PONG messages created"), 1,
3526 sizeof (struct PongMessage) - 3478 GNUNET_NO);
3527 ((void *) &tp->challenge - (void *) tp));
3528 GNUNET_STATISTICS_update (stats,
3529 gettext_noop ("# PONG messages created"),
3530 1, GNUNET_NO);
3531#if DEBUG_HANDSHAKE 3479#if DEBUG_HANDSHAKE
3532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3480 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3533 "Encrypting `%s' with challenge %u using key %u, IV %u (salt %u)\n", 3481 "Encrypting `%s' with challenge %u using key %u, IV %u (salt %u)\n",
3534 "PONG", 3482 "PONG", (unsigned int) t.challenge,
3535 (unsigned int) t.challenge, 3483 (unsigned int) n->encrypt_key.crc32, GNUNET_CRYPTO_crc32_n (&iv,
3536 (unsigned int) n->encrypt_key.crc32, 3484 sizeof
3537 GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), tp->iv_seed); 3485 (iv)),
3486 tp->iv_seed);
3538#endif 3487#endif
3539 /* trigger queue processing */ 3488 /* trigger queue processing */
3540 process_encrypted_neighbour_queue (n); 3489 process_encrypted_neighbour_queue (n);
@@ -3550,8 +3499,7 @@ handle_ping (struct Neighbour *n,
3550 * @param ats_count number of entries in ats (excluding 0-termination) 3499 * @param ats_count number of entries in ats (excluding 0-termination)
3551 */ 3500 */
3552static void 3501static void
3553handle_pong (struct Neighbour *n, 3502handle_pong (struct Neighbour *n, const struct PongMessage *m,
3554 const struct PongMessage *m,
3555 const struct GNUNET_TRANSPORT_ATS_Information *ats, 3503 const struct GNUNET_TRANSPORT_ATS_Information *ats,
3556 uint32_t ats_count) 3504 uint32_t ats_count)
3557{ 3505{
@@ -3564,47 +3512,41 @@ handle_pong (struct Neighbour *n,
3564 3512
3565#if DEBUG_HANDSHAKE 3513#if DEBUG_HANDSHAKE
3566 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3514 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3567 "Core service receives `%s' response from `%4s'.\n", 3515 "Core service receives `%s' response from `%4s'.\n", "PONG",
3568 "PONG", GNUNET_i2s (&n->peer)); 3516 GNUNET_i2s (&n->peer));
3569#endif 3517#endif
3570 /* mark as garbage, just to be sure */ 3518 /* mark as garbage, just to be sure */
3571 memset (&t, 255, sizeof (t)); 3519 memset (&t, 255, sizeof (t));
3572 derive_pong_iv (&iv, &n->decrypt_key, m->iv_seed, n->ping_challenge, 3520 derive_pong_iv (&iv, &n->decrypt_key, m->iv_seed, n->ping_challenge,
3573 &my_identity); 3521 &my_identity);
3574 if (GNUNET_OK != 3522 if (GNUNET_OK !=
3575 do_decrypt (n, 3523 do_decrypt (n, &iv, &m->challenge, &t.challenge,
3576 &iv, 3524 sizeof (struct PongMessage) - ((void *) &m->challenge -
3577 &m->challenge, 3525 (void *) m)))
3578 &t.challenge,
3579 sizeof (struct PongMessage) -
3580 ((void *) &m->challenge - (void *) m)))
3581 { 3526 {
3582 GNUNET_break_op (0); 3527 GNUNET_break_op (0);
3583 return; 3528 return;
3584 } 3529 }
3585 GNUNET_STATISTICS_update (stats, 3530 GNUNET_STATISTICS_update (stats, gettext_noop ("# PONG messages decrypted"),
3586 gettext_noop ("# PONG messages decrypted"),
3587 1, GNUNET_NO); 3531 1, GNUNET_NO);
3588#if DEBUG_HANDSHAKE 3532#if DEBUG_HANDSHAKE
3589 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3533 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3590 "Decrypted `%s' from `%4s' with challenge %u using key %u, IV %u (salt %u)\n", 3534 "Decrypted `%s' from `%4s' with challenge %u using key %u, IV %u (salt %u)\n",
3591 "PONG", 3535 "PONG", GNUNET_i2s (&t.target), (unsigned int) t.challenge,
3592 GNUNET_i2s (&t.target), 3536 (unsigned int) n->decrypt_key.crc32, GNUNET_CRYPTO_crc32_n (&iv,
3593 (unsigned int) t.challenge, 3537 sizeof
3594 (unsigned int) n->decrypt_key.crc32, 3538 (iv)),
3595 GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), m->iv_seed); 3539 m->iv_seed);
3596#endif 3540#endif
3597 if ((0 != memcmp (&t.target, 3541 if ((0 != memcmp (&t.target, &n->peer, sizeof (struct GNUNET_PeerIdentity)))
3598 &n->peer, 3542 || (n->ping_challenge != t.challenge))
3599 sizeof (struct GNUNET_PeerIdentity))) ||
3600 (n->ping_challenge != t.challenge))
3601 { 3543 {
3602 /* PONG malformed */ 3544 /* PONG malformed */
3603#if DEBUG_CORE 3545#if DEBUG_CORE
3604 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3546 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3605 "Received malformed `%s' wanted sender `%4s' with challenge %u\n", 3547 "Received malformed `%s' wanted sender `%4s' with challenge %u\n",
3606 "PONG", 3548 "PONG", GNUNET_i2s (&n->peer),
3607 GNUNET_i2s (&n->peer), (unsigned int) n->ping_challenge); 3549 (unsigned int) n->ping_challenge);
3608 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3609 "Received malformed `%s' received from `%4s' with challenge %u\n", 3551 "Received malformed `%s' received from `%4s' with challenge %u\n",
3610 "PONG", GNUNET_i2s (&t.target), (unsigned int) t.challenge); 3552 "PONG", GNUNET_i2s (&t.target), (unsigned int) t.challenge);
@@ -3636,16 +3578,17 @@ handle_pong (struct Neighbour *n,
3636 if (n->bw_out_external_limit.value__ != t.inbound_bw_limit.value__) 3578 if (n->bw_out_external_limit.value__ != t.inbound_bw_limit.value__)
3637 { 3579 {
3638 n->bw_out_external_limit = t.inbound_bw_limit; 3580 n->bw_out_external_limit = t.inbound_bw_limit;
3639 n->bw_out = GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit, 3581 n->bw_out =
3640 n->bw_out_internal_limit); 3582 GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit,
3583 n->bw_out_internal_limit);
3641 GNUNET_BANDWIDTH_tracker_update_quota (&n->available_send_window, 3584 GNUNET_BANDWIDTH_tracker_update_quota (&n->available_send_window,
3642 n->bw_out); 3585 n->bw_out);
3643 GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out); 3586 GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out);
3644 } 3587 }
3645#if DEBUG_CORE 3588#if DEBUG_CORE
3646 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3589 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3647 "Confirmed key via `%s' message for peer `%4s'\n", 3590 "Confirmed key via `%s' message for peer `%4s'\n", "PONG",
3648 "PONG", GNUNET_i2s (&n->peer)); 3591 GNUNET_i2s (&n->peer));
3649#endif 3592#endif
3650 if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) 3593 if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK)
3651 { 3594 {
@@ -3653,14 +3596,16 @@ handle_pong (struct Neighbour *n,
3653 n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; 3596 n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
3654 } 3597 }
3655 update_neighbour_performance (n, ats, ats_count); 3598 update_neighbour_performance (n, ats, ats_count);
3656 size = sizeof (struct ConnectNotifyMessage) + 3599 size =
3600 sizeof (struct ConnectNotifyMessage) +
3657 (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); 3601 (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
3658 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 3602 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
3659 { 3603 {
3660 GNUNET_break (0); 3604 GNUNET_break (0);
3661 /* recovery strategy: throw away performance data */ 3605 /* recovery strategy: throw away performance data */
3662 GNUNET_array_grow (n->ats, n->ats_count, 0); 3606 GNUNET_array_grow (n->ats, n->ats_count, 0);
3663 size = sizeof (struct PeerStatusNotifyMessage) + 3607 size =
3608 sizeof (struct PeerStatusNotifyMessage) +
3664 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); 3609 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
3665 } 3610 }
3666 cnm = (struct ConnectNotifyMessage *) buf; 3611 cnm = (struct ConnectNotifyMessage *) buf;
@@ -3669,21 +3614,19 @@ handle_pong (struct Neighbour *n,
3669 cnm->ats_count = htonl (n->ats_count); 3614 cnm->ats_count = htonl (n->ats_count);
3670 cnm->peer = n->peer; 3615 cnm->peer = n->peer;
3671 mats = &cnm->ats; 3616 mats = &cnm->ats;
3672 memcpy (mats, 3617 memcpy (mats, n->ats,
3673 n->ats,
3674 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); 3618 n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
3675 mats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 3619 mats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
3676 mats[n->ats_count].value = htonl (0); 3620 mats[n->ats_count].value = htonl (0);
3677 send_to_all_clients (&cnm->header, 3621 send_to_all_clients (&cnm->header, GNUNET_NO,
3678 GNUNET_NO, GNUNET_CORE_OPTION_SEND_CONNECT); 3622 GNUNET_CORE_OPTION_SEND_CONNECT);
3679 process_encrypted_neighbour_queue (n); 3623 process_encrypted_neighbour_queue (n);
3680 /* fall-through! */ 3624 /* fall-through! */
3681 case PEER_STATE_KEY_CONFIRMED: 3625 case PEER_STATE_KEY_CONFIRMED:
3682 n->last_activity = GNUNET_TIME_absolute_get (); 3626 n->last_activity = GNUNET_TIME_absolute_get ();
3683 if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) 3627 if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
3684 GNUNET_SCHEDULER_cancel (n->keep_alive_task); 3628 GNUNET_SCHEDULER_cancel (n->keep_alive_task);
3685 n->keep_alive_task 3629 n->keep_alive_task =
3686 =
3687 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide 3630 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
3688 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 3631 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
3689 2), &send_keep_alive, n); 3632 2), &send_keep_alive, n);
@@ -3706,8 +3649,7 @@ handle_pong (struct Neighbour *n,
3706 * @param ats_count number of entries in ats (excluding 0-termination) 3649 * @param ats_count number of entries in ats (excluding 0-termination)
3707 */ 3650 */
3708static void 3651static void
3709handle_set_key (struct Neighbour *n, 3652handle_set_key (struct Neighbour *n, const struct SetKeyMessage *m,
3710 const struct SetKeyMessage *m,
3711 const struct GNUNET_TRANSPORT_ATS_Information *ats, 3653 const struct GNUNET_TRANSPORT_ATS_Information *ats,
3712 uint32_t ats_count) 3654 uint32_t ats_count)
3713{ 3655{
@@ -3720,8 +3662,8 @@ handle_set_key (struct Neighbour *n,
3720 3662
3721#if DEBUG_CORE 3663#if DEBUG_CORE
3722 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3664 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3723 "Core service receives `%s' request from `%4s'.\n", 3665 "Core service receives `%s' request from `%4s'.\n", "SET_KEY",
3724 "SET_KEY", GNUNET_i2s (&n->peer)); 3666 GNUNET_i2s (&n->peer));
3725#endif 3667#endif
3726 if (n->public_key == NULL) 3668 if (n->public_key == NULL)
3727 { 3669 {
@@ -3743,18 +3685,17 @@ handle_set_key (struct Neighbour *n,
3743 /* lookup n's public key, then try again */ 3685 /* lookup n's public key, then try again */
3744 GNUNET_assert (n->skm == NULL); 3686 GNUNET_assert (n->skm == NULL);
3745 n->skm = m_cpy; 3687 n->skm = m_cpy;
3746 n->pitr = GNUNET_PEERINFO_iterate (peerinfo, 3688 n->pitr =
3747 &n->peer, 3689 GNUNET_PEERINFO_iterate (peerinfo, &n->peer, GNUNET_TIME_UNIT_MINUTES,
3748 GNUNET_TIME_UNIT_MINUTES, 3690 &process_hello_retry_handle_set_key, n);
3749 &process_hello_retry_handle_set_key, n);
3750 GNUNET_STATISTICS_update (stats, 3691 GNUNET_STATISTICS_update (stats,
3751 gettext_noop 3692 gettext_noop
3752 ("# SET_KEY messages deferred (need public key)"), 3693 ("# SET_KEY messages deferred (need public key)"),
3753 1, GNUNET_NO); 3694 1, GNUNET_NO);
3754 return; 3695 return;
3755 } 3696 }
3756 if (0 != memcmp (&m->target, 3697 if (0 !=
3757 &my_identity, sizeof (struct GNUNET_PeerIdentity))) 3698 memcmp (&m->target, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
3758 { 3699 {
3759 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3700 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3760 _ 3701 _
@@ -3768,8 +3709,8 @@ handle_set_key (struct Neighbour *n,
3768 sizeof (struct GNUNET_CRYPTO_RsaEncryptedData) + 3709 sizeof (struct GNUNET_CRYPTO_RsaEncryptedData) +
3769 sizeof (struct GNUNET_PeerIdentity)) || 3710 sizeof (struct GNUNET_PeerIdentity)) ||
3770 (GNUNET_OK != 3711 (GNUNET_OK !=
3771 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_SET_KEY, 3712 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_SET_KEY, &m->purpose,
3772 &m->purpose, &m->signature, n->public_key))) 3713 &m->signature, n->public_key)))
3773 { 3714 {
3774 /* invalid signature */ 3715 /* invalid signature */
3775 GNUNET_break_op (0); 3716 GNUNET_break_op (0);
@@ -3789,11 +3730,10 @@ handle_set_key (struct Neighbour *n,
3789#if DEBUG_CORE 3730#if DEBUG_CORE
3790 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting key material.\n"); 3731 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting key material.\n");
3791#endif 3732#endif
3792 if ((GNUNET_CRYPTO_rsa_decrypt (my_private_key, 3733 if ((GNUNET_CRYPTO_rsa_decrypt
3793 &m->encrypted_key, 3734 (my_private_key, &m->encrypted_key, &k,
3794 &k, 3735 sizeof (struct GNUNET_CRYPTO_AesSessionKey)) !=
3795 sizeof (struct GNUNET_CRYPTO_AesSessionKey)) 3736 sizeof (struct GNUNET_CRYPTO_AesSessionKey)) ||
3796 != sizeof (struct GNUNET_CRYPTO_AesSessionKey)) ||
3797 (GNUNET_OK != GNUNET_CRYPTO_aes_check_session_key (&k))) 3737 (GNUNET_OK != GNUNET_CRYPTO_aes_check_session_key (&k)))
3798 { 3738 {
3799 /* failed to decrypt !? */ 3739 /* failed to decrypt !? */
@@ -3801,8 +3741,8 @@ handle_set_key (struct Neighbour *n,
3801 return; 3741 return;
3802 } 3742 }
3803 GNUNET_STATISTICS_update (stats, 3743 GNUNET_STATISTICS_update (stats,
3804 gettext_noop ("# SET_KEY messages decrypted"), 3744 gettext_noop ("# SET_KEY messages decrypted"), 1,
3805 1, GNUNET_NO); 3745 GNUNET_NO);
3806 n->decrypt_key = k; 3746 n->decrypt_key = k;
3807 if (n->decrypt_key_created.abs_value != t.abs_value) 3747 if (n->decrypt_key_created.abs_value != t.abs_value)
3808 { 3748 {
@@ -3879,10 +3819,11 @@ handle_set_key (struct Neighbour *n,
3879 * @param msize number of bytes in buf to transmit 3819 * @param msize number of bytes in buf to transmit
3880 */ 3820 */
3881static void 3821static void
3882send_p2p_message_to_client (struct Neighbour *sender, 3822send_p2p_message_to_client (struct Neighbour *sender, struct Client *client,
3883 struct Client *client, const void *m, size_t msize) 3823 const void *m, size_t msize)
3884{ 3824{
3885 size_t size = msize + sizeof (struct NotifyTrafficMessage) + 3825 size_t size =
3826 msize + sizeof (struct NotifyTrafficMessage) +
3886 (sender->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); 3827 (sender->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
3887 char buf[size]; 3828 char buf[size];
3888 struct NotifyTrafficMessage *ntm; 3829 struct NotifyTrafficMessage *ntm;
@@ -3894,15 +3835,16 @@ send_p2p_message_to_client (struct Neighbour *sender,
3894 GNUNET_break (0); 3835 GNUNET_break (0);
3895 /* recovery strategy: throw performance data away... */ 3836 /* recovery strategy: throw performance data away... */
3896 GNUNET_array_grow (sender->ats, sender->ats_count, 0); 3837 GNUNET_array_grow (sender->ats, sender->ats_count, 0);
3897 size = msize + sizeof (struct NotifyTrafficMessage) + 3838 size =
3839 msize + sizeof (struct NotifyTrafficMessage) +
3898 (sender->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); 3840 (sender->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
3899 } 3841 }
3900#if DEBUG_CORE 3842#if DEBUG_CORE
3901 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3843 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3902 "Core service passes message from `%4s' of type %u to client.\n", 3844 "Core service passes message from `%4s' of type %u to client.\n",
3903 GNUNET_i2s (&sender->peer), 3845 GNUNET_i2s (&sender->peer),
3904 (unsigned int) 3846 (unsigned int) ntohs (((const struct GNUNET_MessageHeader *) m)->
3905 ntohs (((const struct GNUNET_MessageHeader *) m)->type)); 3847 type));
3906#endif 3848#endif
3907 ntm = (struct NotifyTrafficMessage *) buf; 3849 ntm = (struct NotifyTrafficMessage *) buf;
3908 ntm->header.size = htons (size); 3850 ntm->header.size = htons (size);
@@ -3910,8 +3852,7 @@ send_p2p_message_to_client (struct Neighbour *sender,
3910 ntm->ats_count = htonl (sender->ats_count); 3852 ntm->ats_count = htonl (sender->ats_count);
3911 ntm->peer = sender->peer; 3853 ntm->peer = sender->peer;
3912 ats = &ntm->ats; 3854 ats = &ntm->ats;
3913 memcpy (ats, 3855 memcpy (ats, sender->ats,
3914 sender->ats,
3915 sizeof (struct GNUNET_TRANSPORT_ATS_Information) * sender->ats_count); 3856 sizeof (struct GNUNET_TRANSPORT_ATS_Information) * sender->ats_count);
3916 ats[sender->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 3857 ats[sender->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
3917 ats[sender->ats_count].value = htonl (0); 3858 ats[sender->ats_count].value = htonl (0);
@@ -3945,8 +3886,7 @@ deliver_message (void *cls, void *client, const struct GNUNET_MessageHeader *m)
3945 "Received encapsulated message of type %u and size %u from `%4s'\n", 3886 "Received encapsulated message of type %u and size %u from `%4s'\n",
3946 (unsigned int) type, ntohs (m->size), GNUNET_i2s (&sender->peer)); 3887 (unsigned int) type, ntohs (m->size), GNUNET_i2s (&sender->peer));
3947#endif 3888#endif
3948 GNUNET_snprintf (buf, 3889 GNUNET_snprintf (buf, sizeof (buf),
3949 sizeof (buf),
3950 gettext_noop ("# bytes of messages of type %u received"), 3890 gettext_noop ("# bytes of messages of type %u received"),
3951 (unsigned int) type); 3891 (unsigned int) type);
3952 GNUNET_STATISTICS_update (stats, buf, msize, GNUNET_NO); 3892 GNUNET_STATISTICS_update (stats, buf, msize, GNUNET_NO);
@@ -4010,8 +3950,7 @@ deliver_message (void *cls, void *client, const struct GNUNET_MessageHeader *m)
4010 * @param ats_count number of entries in ats (excluding 0-termination) 3950 * @param ats_count number of entries in ats (excluding 0-termination)
4011 */ 3951 */
4012static void 3952static void
4013handle_encrypted_message (struct Neighbour *n, 3953handle_encrypted_message (struct Neighbour *n, const struct EncryptedMessage *m,
4014 const struct EncryptedMessage *m,
4015 const struct GNUNET_TRANSPORT_ATS_Information *ats, 3954 const struct GNUNET_TRANSPORT_ATS_Information *ats,
4016 uint32_t ats_count) 3955 uint32_t ats_count)
4017{ 3956{
@@ -4030,10 +3969,10 @@ handle_encrypted_message (struct Neighbour *n,
4030 "ENCRYPTED_MESSAGE", GNUNET_i2s (&n->peer)); 3969 "ENCRYPTED_MESSAGE", GNUNET_i2s (&n->peer));
4031#endif 3970#endif
4032 /* validate hash */ 3971 /* validate hash */
4033 derive_auth_key (&auth_key, 3972 derive_auth_key (&auth_key, &n->decrypt_key, m->iv_seed,
4034 &n->decrypt_key, m->iv_seed, n->decrypt_key_created); 3973 n->decrypt_key_created);
4035 GNUNET_CRYPTO_hmac (&auth_key, 3974 GNUNET_CRYPTO_hmac (&auth_key, &m->sequence_number,
4036 &m->sequence_number, size - ENCRYPTED_HEADER_SIZE, &ph); 3975 size - ENCRYPTED_HEADER_SIZE, &ph);
4037#if DEBUG_HANDSHAKE 3976#if DEBUG_HANDSHAKE
4038 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3977 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4039 "Re-Authenticated %u bytes of ciphertext (`%u'): `%s'\n", 3978 "Re-Authenticated %u bytes of ciphertext (`%u'): `%s'\n",
@@ -4052,10 +3991,8 @@ handle_encrypted_message (struct Neighbour *n,
4052 derive_iv (&iv, &n->decrypt_key, m->iv_seed, &my_identity); 3991 derive_iv (&iv, &n->decrypt_key, m->iv_seed, &my_identity);
4053 /* decrypt */ 3992 /* decrypt */
4054 if (GNUNET_OK != 3993 if (GNUNET_OK !=
4055 do_decrypt (n, 3994 do_decrypt (n, &iv, &m->sequence_number, &buf[ENCRYPTED_HEADER_SIZE],
4056 &iv, 3995 size - ENCRYPTED_HEADER_SIZE))
4057 &m->sequence_number,
4058 &buf[ENCRYPTED_HEADER_SIZE], size - ENCRYPTED_HEADER_SIZE))
4059 return; 3996 return;
4060 pt = (struct EncryptedMessage *) buf; 3997 pt = (struct EncryptedMessage *) buf;
4061 3998
@@ -4116,8 +4053,7 @@ handle_encrypted_message (struct Neighbour *n,
4116 MAX_MESSAGE_AGE.rel_value) 4053 MAX_MESSAGE_AGE.rel_value)
4117 { 4054 {
4118 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 4055 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
4119 _ 4056 _("Message received far too old (%llu ms). Content ignored.\n"),
4120 ("Message received far too old (%llu ms). Content ignored.\n"),
4121 GNUNET_TIME_absolute_get_duration (t).rel_value); 4057 GNUNET_TIME_absolute_get_duration (t).rel_value);
4122 GNUNET_STATISTICS_update (stats, 4058 GNUNET_STATISTICS_update (stats,
4123 gettext_noop 4059 gettext_noop
@@ -4136,8 +4072,9 @@ handle_encrypted_message (struct Neighbour *n,
4136 GNUNET_i2s (&n->peer)); 4072 GNUNET_i2s (&n->peer));
4137#endif 4073#endif
4138 n->bw_out_external_limit = pt->inbound_bw_limit; 4074 n->bw_out_external_limit = pt->inbound_bw_limit;
4139 n->bw_out = GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit, 4075 n->bw_out =
4140 n->bw_out_internal_limit); 4076 GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit,
4077 n->bw_out_internal_limit);
4141 GNUNET_BANDWIDTH_tracker_update_quota (&n->available_send_window, 4078 GNUNET_BANDWIDTH_tracker_update_quota (&n->available_send_window,
4142 n->bw_out); 4079 n->bw_out);
4143 GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out); 4080 GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out);
@@ -4145,8 +4082,7 @@ handle_encrypted_message (struct Neighbour *n,
4145 n->last_activity = GNUNET_TIME_absolute_get (); 4082 n->last_activity = GNUNET_TIME_absolute_get ();
4146 if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) 4083 if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
4147 GNUNET_SCHEDULER_cancel (n->keep_alive_task); 4084 GNUNET_SCHEDULER_cancel (n->keep_alive_task);
4148 n->keep_alive_task 4085 n->keep_alive_task =
4149 =
4150 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide 4086 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
4151 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 4087 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
4152 2), &send_keep_alive, n); 4088 2), &send_keep_alive, n);
@@ -4155,13 +4091,10 @@ handle_encrypted_message (struct Neighbour *n,
4155 size - sizeof (struct EncryptedMessage), GNUNET_NO); 4091 size - sizeof (struct EncryptedMessage), GNUNET_NO);
4156 handle_peer_status_change (n); 4092 handle_peer_status_change (n);
4157 update_neighbour_performance (n, ats, ats_count); 4093 update_neighbour_performance (n, ats, ats_count);
4158 if (GNUNET_OK != GNUNET_SERVER_mst_receive (mst, 4094 if (GNUNET_OK !=
4159 n, 4095 GNUNET_SERVER_mst_receive (mst, n, &buf[sizeof (struct EncryptedMessage)],
4160 &buf[sizeof 4096 size - sizeof (struct EncryptedMessage),
4161 (struct EncryptedMessage)], 4097 GNUNET_YES, GNUNET_NO))
4162 size -
4163 sizeof (struct EncryptedMessage),
4164 GNUNET_YES, GNUNET_NO))
4165 GNUNET_break_op (0); 4098 GNUNET_break_op (0);
4166} 4099}
4167 4100
@@ -4176,8 +4109,7 @@ handle_encrypted_message (struct Neighbour *n,
4176 * @param ats_count number of entries in ats (excluding 0-termination) 4109 * @param ats_count number of entries in ats (excluding 0-termination)
4177 */ 4110 */
4178static void 4111static void
4179handle_transport_receive (void *cls, 4112handle_transport_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
4180 const struct GNUNET_PeerIdentity *peer,
4181 const struct GNUNET_MessageHeader *message, 4113 const struct GNUNET_MessageHeader *message,
4182 const struct GNUNET_TRANSPORT_ATS_Information *ats, 4114 const struct GNUNET_TRANSPORT_ATS_Information *ats,
4183 uint32_t ats_count) 4115 uint32_t ats_count)
@@ -4218,14 +4150,13 @@ handle_transport_receive (void *cls,
4218 GNUNET_break_op (0); 4150 GNUNET_break_op (0);
4219 return; 4151 return;
4220 } 4152 }
4221 GNUNET_STATISTICS_update (stats, 4153 GNUNET_STATISTICS_update (stats, gettext_noop ("# session keys received"),
4222 gettext_noop ("# session keys received"),
4223 1, GNUNET_NO); 4154 1, GNUNET_NO);
4224 handle_set_key (n, (const struct SetKeyMessage *) message, ats, ats_count); 4155 handle_set_key (n, (const struct SetKeyMessage *) message, ats, ats_count);
4225 break; 4156 break;
4226 case GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE: 4157 case GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE:
4227 if (size < sizeof (struct EncryptedMessage) + 4158 if (size <
4228 sizeof (struct GNUNET_MessageHeader)) 4159 sizeof (struct EncryptedMessage) + sizeof (struct GNUNET_MessageHeader))
4229 { 4160 {
4230 GNUNET_break_op (0); 4161 GNUNET_break_op (0);
4231 return; 4162 return;
@@ -4240,9 +4171,8 @@ handle_transport_receive (void *cls,
4240 send_key (n); 4171 send_key (n);
4241 return; 4172 return;
4242 } 4173 }
4243 handle_encrypted_message (n, 4174 handle_encrypted_message (n, (const struct EncryptedMessage *) message, ats,
4244 (const struct EncryptedMessage *) message, 4175 ats_count);
4245 ats, ats_count);
4246 break; 4176 break;
4247 case GNUNET_MESSAGE_TYPE_CORE_PING: 4177 case GNUNET_MESSAGE_TYPE_CORE_PING:
4248 if (size != sizeof (struct PingMessage)) 4178 if (size != sizeof (struct PingMessage))
@@ -4303,15 +4233,13 @@ handle_transport_receive (void *cls,
4303 changed = GNUNET_YES; 4233 changed = GNUNET_YES;
4304 if (!up) 4234 if (!up)
4305 { 4235 {
4306 GNUNET_STATISTICS_update (stats, 4236 GNUNET_STATISTICS_update (stats, gettext_noop ("# established sessions"),
4307 gettext_noop ("# established sessions"),
4308 1, GNUNET_NO); 4237 1, GNUNET_NO);
4309 n->time_established = now; 4238 n->time_established = now;
4310 } 4239 }
4311 if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) 4240 if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
4312 GNUNET_SCHEDULER_cancel (n->keep_alive_task); 4241 GNUNET_SCHEDULER_cancel (n->keep_alive_task);
4313 n->keep_alive_task 4242 n->keep_alive_task =
4314 =
4315 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide 4243 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
4316 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 4244 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
4317 2), &send_keep_alive, n); 4245 2), &send_keep_alive, n);
@@ -4411,10 +4339,8 @@ neighbour_quota_update (void *cls,
4411#if DEBUG_CORE_QUOTA 4339#if DEBUG_CORE_QUOTA
4412 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4413 "Current quota for `%4s' is %u/%llu b/s in (old: %u b/s) / %u out (%u internal)\n", 4341 "Current quota for `%4s' is %u/%llu b/s in (old: %u b/s) / %u out (%u internal)\n",
4414 GNUNET_i2s (&n->peer), 4342 GNUNET_i2s (&n->peer), (unsigned int) ntohl (q_in.value__),
4415 (unsigned int) ntohl (q_in.value__), 4343 bandwidth_target_out_bps, (unsigned int) ntohl (n->bw_in.value__),
4416 bandwidth_target_out_bps,
4417 (unsigned int) ntohl (n->bw_in.value__),
4418 (unsigned int) ntohl (n->bw_out.value__), 4344 (unsigned int) ntohl (n->bw_out.value__),
4419 (unsigned int) ntohl (n->bw_out_internal_limit.value__)); 4345 (unsigned int) ntohl (n->bw_out_internal_limit.value__));
4420#endif 4346#endif
@@ -4470,17 +4396,17 @@ handle_transport_notify_connect (void *cls,
4470 n = create_neighbour (peer); 4396 n = create_neighbour (peer);
4471 } 4397 }
4472 GNUNET_STATISTICS_update (stats, 4398 GNUNET_STATISTICS_update (stats,
4473 gettext_noop ("# peers connected (transport)"), 4399 gettext_noop ("# peers connected (transport)"), 1,
4474 1, GNUNET_NO); 4400 GNUNET_NO);
4475 n->is_connected = GNUNET_YES; 4401 n->is_connected = GNUNET_YES;
4476 update_neighbour_performance (n, ats, ats_count); 4402 update_neighbour_performance (n, ats, ats_count);
4477 GNUNET_BANDWIDTH_tracker_init (&n->available_send_window, 4403 GNUNET_BANDWIDTH_tracker_init (&n->available_send_window, n->bw_out,
4478 n->bw_out, MAX_WINDOW_TIME_S); 4404 MAX_WINDOW_TIME_S);
4479 GNUNET_BANDWIDTH_tracker_init (&n->available_recv_window, 4405 GNUNET_BANDWIDTH_tracker_init (&n->available_recv_window, n->bw_in,
4480 n->bw_in, MAX_WINDOW_TIME_S); 4406 MAX_WINDOW_TIME_S);
4481#if DEBUG_CORE 4407#if DEBUG_CORE
4482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4408 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received connection from `%4s'.\n",
4483 "Received connection from `%4s'.\n", GNUNET_i2s (&n->peer)); 4409 GNUNET_i2s (&n->peer));
4484#endif 4410#endif
4485 GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out); 4411 GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out);
4486 send_key (n); 4412 send_key (n);
@@ -4552,8 +4478,8 @@ handle_transport_notify_disconnect (void *cls,
4552 } 4478 }
4553 4479
4554 GNUNET_STATISTICS_update (stats, 4480 GNUNET_STATISTICS_update (stats,
4555 gettext_noop ("# peers connected (transport)"), 4481 gettext_noop ("# peers connected (transport)"), -1,
4556 -1, GNUNET_NO); 4482 GNUNET_NO);
4557 if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK) 4483 if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK)
4558 GNUNET_SCHEDULER_cancel (n->dead_clean_task); 4484 GNUNET_SCHEDULER_cancel (n->dead_clean_task);
4559 left = 4485 left =
@@ -4595,8 +4521,8 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
4595 GNUNET_assert (transport != NULL); 4521 GNUNET_assert (transport != NULL);
4596 GNUNET_TRANSPORT_disconnect (transport); 4522 GNUNET_TRANSPORT_disconnect (transport);
4597 transport = NULL; 4523 transport = NULL;
4598 GNUNET_CONTAINER_multihashmap_iterate (neighbours, 4524 GNUNET_CONTAINER_multihashmap_iterate (neighbours, &free_neighbour_helper,
4599 &free_neighbour_helper, NULL); 4525 NULL);
4600 GNUNET_CONTAINER_multihashmap_destroy (neighbours); 4526 GNUNET_CONTAINER_multihashmap_destroy (neighbours);
4601 neighbours = NULL; 4527 neighbours = NULL;
4602 GNUNET_STATISTICS_set (stats, gettext_noop ("# neighbour entries allocated"), 4528 GNUNET_STATISTICS_set (stats, gettext_noop ("# neighbour entries allocated"),
@@ -4624,8 +4550,7 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
4624 * @param c configuration to use 4550 * @param c configuration to use
4625 */ 4551 */
4626static void 4552static void
4627run (void *cls, 4553run (void *cls, struct GNUNET_SERVER_Handle *server,
4628 struct GNUNET_SERVER_Handle *server,
4629 const struct GNUNET_CONFIGURATION_Handle *c) 4554 const struct GNUNET_CONFIGURATION_Handle *c)
4630{ 4555{
4631 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 4556 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
@@ -4656,19 +4581,14 @@ run (void *cls,
4656 cfg = c; 4581 cfg = c;
4657 /* parse configuration */ 4582 /* parse configuration */
4658 if ((GNUNET_OK != 4583 if ((GNUNET_OK !=
4659 GNUNET_CONFIGURATION_get_value_number (c, 4584 GNUNET_CONFIGURATION_get_value_number (c, "CORE", "TOTAL_QUOTA_IN",
4660 "CORE",
4661 "TOTAL_QUOTA_IN",
4662 &bandwidth_target_in_bps)) || 4585 &bandwidth_target_in_bps)) ||
4663 (GNUNET_OK != 4586 (GNUNET_OK !=
4664 GNUNET_CONFIGURATION_get_value_number (c, 4587 GNUNET_CONFIGURATION_get_value_number (c, "CORE", "TOTAL_QUOTA_OUT",
4665 "CORE",
4666 "TOTAL_QUOTA_OUT",
4667 &bandwidth_target_out_bps)) || 4588 &bandwidth_target_out_bps)) ||
4668 (GNUNET_OK != 4589 (GNUNET_OK !=
4669 GNUNET_CONFIGURATION_get_value_filename (c, 4590 GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY",
4670 "GNUNETD", 4591 &keyfile)))
4671 "HOSTKEY", &keyfile)))
4672 { 4592 {
4673 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 4593 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
4674 _ 4594 _
@@ -4697,29 +4617,27 @@ run (void *cls,
4697 } 4617 }
4698 neighbours = GNUNET_CONTAINER_multihashmap_create (128); 4618 neighbours = GNUNET_CONTAINER_multihashmap_create (128);
4699 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); 4619 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
4700 GNUNET_CRYPTO_hash (&my_public_key, 4620 GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key),
4701 sizeof (my_public_key), &my_identity.hashPubKey); 4621 &my_identity.hashPubKey);
4702 self.public_key = &my_public_key; 4622 self.public_key = &my_public_key;
4703 self.peer = my_identity; 4623 self.peer = my_identity;
4704 self.last_activity = GNUNET_TIME_UNIT_FOREVER_ABS; 4624 self.last_activity = GNUNET_TIME_UNIT_FOREVER_ABS;
4705 self.status = PEER_STATE_KEY_CONFIRMED; 4625 self.status = PEER_STATE_KEY_CONFIRMED;
4706 self.is_connected = GNUNET_YES; 4626 self.is_connected = GNUNET_YES;
4707 /* setup notification */ 4627 /* setup notification */
4708 notifier = GNUNET_SERVER_notification_context_create (server, 4628 notifier =
4709 MAX_NOTIFY_QUEUE); 4629 GNUNET_SERVER_notification_context_create (server, MAX_NOTIFY_QUEUE);
4710 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); 4630 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
4711 /* setup transport connection */ 4631 /* setup transport connection */
4712 transport = GNUNET_TRANSPORT_connect (cfg, 4632 transport =
4713 &my_identity, 4633 GNUNET_TRANSPORT_connect (cfg, &my_identity, NULL,
4714 NULL, 4634 &handle_transport_receive,
4715 &handle_transport_receive, 4635 &handle_transport_notify_connect,
4716 &handle_transport_notify_connect, 4636 &handle_transport_notify_disconnect);
4717 &handle_transport_notify_disconnect);
4718 GNUNET_assert (NULL != transport); 4637 GNUNET_assert (NULL != transport);
4719 stats = GNUNET_STATISTICS_create ("core", cfg); 4638 stats = GNUNET_STATISTICS_create ("core", cfg);
4720 4639
4721 GNUNET_STATISTICS_set (stats, 4640 GNUNET_STATISTICS_set (stats, gettext_noop ("# discarded CORE_SEND requests"),
4722 gettext_noop ("# discarded CORE_SEND requests"),
4723 0, GNUNET_NO); 4641 0, GNUNET_NO);
4724 GNUNET_STATISTICS_set (stats, 4642 GNUNET_STATISTICS_set (stats,
4725 gettext_noop 4643 gettext_noop
@@ -4727,12 +4645,12 @@ run (void *cls,
4727 GNUNET_NO); 4645 GNUNET_NO);
4728 4646
4729 mst = GNUNET_SERVER_mst_create (&deliver_message, NULL); 4647 mst = GNUNET_SERVER_mst_create (&deliver_message, NULL);
4730 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 4648 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task,
4731 &cleaning_task, NULL); 4649 NULL);
4732 /* process client requests */ 4650 /* process client requests */
4733 GNUNET_SERVER_add_handlers (server, handlers); 4651 GNUNET_SERVER_add_handlers (server, handlers);
4734 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 4652 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Core service of `%4s' ready.\n"),
4735 _("Core service of `%4s' ready.\n"), GNUNET_i2s (&my_identity)); 4653 GNUNET_i2s (&my_identity));
4736} 4654}
4737 4655
4738 4656
@@ -4748,10 +4666,8 @@ int
4748main (int argc, char *const *argv) 4666main (int argc, char *const *argv)
4749{ 4667{
4750 return (GNUNET_OK == 4668 return (GNUNET_OK ==
4751 GNUNET_SERVICE_run (argc, 4669 GNUNET_SERVICE_run (argc, argv, "core", GNUNET_SERVICE_OPTION_NONE,
4752 argv, 4670 &run, NULL)) ? 0 : 1;
4753 "core",
4754 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
4755} 4671}
4756 4672
4757/* end of gnunet-service-core.c */ 4673/* end of gnunet-service-core.c */
diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c
index b5e93a8a2..28805a372 100644
--- a/src/core/test_core_api.c
+++ b/src/core/test_core_api.c
@@ -150,8 +150,7 @@ transmit_ready (void *cls, size_t size, void *buf)
150 150
151 151
152static void 152static void
153connect_notify (void *cls, 153connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
154 const struct GNUNET_PeerIdentity *peer,
155 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 154 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
156{ 155{
157 struct PeerContext *pc = cls; 156 struct PeerContext *pc = cls;
@@ -173,15 +172,13 @@ connect_notify (void *cls,
173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
174 "Asking core (1) for transmission to peer `%4s'\n", 173 "Asking core (1) for transmission to peer `%4s'\n",
175 GNUNET_i2s (&p2.id)); 174 GNUNET_i2s (&p2.id));
176 if (NULL == GNUNET_CORE_notify_transmit_ready (p1.ch, 175 if (NULL ==
177 GNUNET_YES, 176 GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_YES, 0,
178 0, 177 GNUNET_TIME_relative_multiply
179 GNUNET_TIME_relative_multiply 178 (GNUNET_TIME_UNIT_SECONDS, 45),
180 (GNUNET_TIME_UNIT_SECONDS, 179 &p2.id,
181 45), &p2.id, 180 sizeof (struct GNUNET_MessageHeader),
182 sizeof (struct 181 &transmit_ready, &p1))
183 GNUNET_MessageHeader),
184 &transmit_ready, &p1))
185 { 182 {
186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
187 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", 184 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
@@ -199,14 +196,13 @@ disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
199 if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) 196 if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
200 return; 197 return;
201 pc->connect_status = 0; 198 pc->connect_status = 0;
202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted connection to `%4s' cut\n",
203 "Encrypted connection to `%4s' cut\n", GNUNET_i2s (peer)); 200 GNUNET_i2s (peer));
204} 201}
205 202
206 203
207static int 204static int
208inbound_notify (void *cls, 205inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
209 const struct GNUNET_PeerIdentity *other,
210 const struct GNUNET_MessageHeader *message, 206 const struct GNUNET_MessageHeader *message,
211 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 207 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
212{ 208{
@@ -217,8 +213,7 @@ inbound_notify (void *cls,
217 213
218 214
219static int 215static int
220outbound_notify (void *cls, 216outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
221 const struct GNUNET_PeerIdentity *other,
222 const struct GNUNET_MessageHeader *message, 217 const struct GNUNET_MessageHeader *message,
223 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 218 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
224{ 219{
@@ -231,13 +226,12 @@ outbound_notify (void *cls,
231 226
232 227
233static int 228static int
234process_mtype (void *cls, 229process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
235 const struct GNUNET_PeerIdentity *peer,
236 const struct GNUNET_MessageHeader *message, 230 const struct GNUNET_MessageHeader *message,
237 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 231 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
238{ 232{
239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving message from `%4s'.\n",
240 "Receiving message from `%4s'.\n", GNUNET_i2s (peer)); 234 GNUNET_i2s (peer));
241 GNUNET_assert (ok == 5); 235 GNUNET_assert (ok == 5);
242 OKPP; 236 OKPP;
243 GNUNET_SCHEDULER_cancel (err_task); 237 GNUNET_SCHEDULER_cancel (err_task);
@@ -260,8 +254,9 @@ connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
260 con_task = GNUNET_SCHEDULER_NO_TASK; 254 con_task = GNUNET_SCHEDULER_NO_TASK;
261 return; 255 return;
262 } 256 }
263 con_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 257 con_task =
264 &connect_task, NULL); 258 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &connect_task,
259 NULL);
265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
266 "Asking core (1) to connect to peer `%4s'\n", 261 "Asking core (1) to connect to peer `%4s'\n",
267 GNUNET_i2s (&p2.id)); 262 GNUNET_i2s (&p2.id));
@@ -269,15 +264,13 @@ connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
269} 264}
270 265
271static void 266static void
272init_notify (void *cls, 267init_notify (void *cls, struct GNUNET_CORE_Handle *server,
273 struct GNUNET_CORE_Handle *server,
274 const struct GNUNET_PeerIdentity *my_identity, 268 const struct GNUNET_PeerIdentity *my_identity,
275 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) 269 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
276{ 270{
277 struct PeerContext *p = cls; 271 struct PeerContext *p = cls;
278 272
279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core connection to `%4s' established\n",
280 "Core connection to `%4s' established\n",
281 GNUNET_i2s (my_identity)); 274 GNUNET_i2s (my_identity));
282 GNUNET_assert (server != NULL); 275 GNUNET_assert (server != NULL);
283 p->id = *my_identity; 276 p->id = *my_identity;
@@ -287,15 +280,11 @@ init_notify (void *cls,
287 GNUNET_assert (ok == 2); 280 GNUNET_assert (ok == 2);
288 OKPP; 281 OKPP;
289 /* connect p2 */ 282 /* connect p2 */
290 p2.ch = GNUNET_CORE_connect (p2.cfg, 1, 283 p2.ch =
291 &p2, 284 GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify,
292 &init_notify, 285 &disconnect_notify, NULL, &inbound_notify,
293 &connect_notify, 286 GNUNET_YES, &outbound_notify, GNUNET_YES,
294 &disconnect_notify, 287 handlers);
295 NULL,
296 &inbound_notify,
297 GNUNET_YES,
298 &outbound_notify, GNUNET_YES, handlers);
299 } 288 }
300 else 289 else
301 { 290 {
@@ -312,12 +301,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
312{ 301{
313 p->cfg = GNUNET_CONFIGURATION_create (); 302 p->cfg = GNUNET_CONFIGURATION_create ();
314#if START_ARM 303#if START_ARM
315 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 304 p->arm_proc =
316 "gnunet-service-arm", 305 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
306 "gnunet-service-arm",
317#if VERBOSE 307#if VERBOSE
318 "-L", "DEBUG", 308 "-L", "DEBUG",
319#endif 309#endif
320 "-c", cfgname, NULL); 310 "-c", cfgname, NULL);
321#endif 311#endif
322 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 312 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
323 p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); 313 p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL);
@@ -327,9 +317,8 @@ setup_peer (struct PeerContext *p, const char *cfgname)
327 317
328 318
329static void 319static void
330run (void *cls, 320run (void *cls, char *const *args, const char *cfgfile,
331 char *const *args, 321 const struct GNUNET_CONFIGURATION_Handle *cfg)
332 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
333{ 322{
334 GNUNET_assert (ok == 1); 323 GNUNET_assert (ok == 1);
335 OKPP; 324 OKPP;
@@ -353,8 +342,7 @@ stop_arm (struct PeerContext *p)
353 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 342 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
354 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 343 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
355 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 344 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
356 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
357 "ARM process %u stopped\n",
358 GNUNET_OS_process_get_pid (p->arm_proc)); 346 GNUNET_OS_process_get_pid (p->arm_proc));
359 GNUNET_OS_process_close (p->arm_proc); 347 GNUNET_OS_process_close (p->arm_proc);
360 p->arm_proc = NULL; 348 p->arm_proc = NULL;
@@ -377,8 +365,8 @@ check ()
377 GNUNET_GETOPT_OPTION_END 365 GNUNET_GETOPT_OPTION_END
378 }; 366 };
379 ok = 1; 367 ok = 1;
380 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 368 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
381 argv, "test-core-api", "nohelp", options, &run, &ok); 369 "test-core-api", "nohelp", options, &run, &ok);
382 stop_arm (&p1); 370 stop_arm (&p1);
383 stop_arm (&p2); 371 stop_arm (&p2);
384 return ok; 372 return ok;
diff --git a/src/core/test_core_api_preferences.c b/src/core/test_core_api_preferences.c
index 200ae4176..e5d5deb1b 100644
--- a/src/core/test_core_api_preferences.c
+++ b/src/core/test_core_api_preferences.c
@@ -151,13 +151,11 @@ transmit_ready (void *cls, size_t size, void *buf)
151 return sizeof (struct GNUNET_MessageHeader); 151 return sizeof (struct GNUNET_MessageHeader);
152} 152}
153 153
154static void 154static void preference_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
155preference_cb (void *cls, 155 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
156 const struct 156 int32_t amount,
157 GNUNET_PeerIdentity *peer, 157 struct GNUNET_TIME_Relative res_delay,
158 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 158 uint64_t preference);
159 int32_t amount,
160 struct GNUNET_TIME_Relative res_delay, uint64_t preference);
161 159
162static void 160static void
163do_reserve (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 161do_reserve (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -173,20 +171,17 @@ do_reserve (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
173 } 171 }
174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
175 "Requesting reservatin of 32k from core in 1s!\n"); 173 "Requesting reservatin of 32k from core in 1s!\n");
176 irc = GNUNET_CORE_peer_change_preference (p1.ch, 174 irc =
177 &p2.id, 175 GNUNET_CORE_peer_change_preference (p1.ch, &p2.id,
178 GNUNET_TIME_UNIT_SECONDS, 176 GNUNET_TIME_UNIT_SECONDS,
179 GNUNET_BANDWIDTH_VALUE_MAX, 177 GNUNET_BANDWIDTH_VALUE_MAX,
180 1000000 /* bandwidth for 1s */ , 178 1000000 /* bandwidth for 1s */ ,
181 0, &preference_cb, pc); 179 0, &preference_cb, pc);
182} 180}
183 181
184static void 182static void
185preference_cb (void *cls, 183preference_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
186 const struct 184 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, int32_t amount,
187 GNUNET_PeerIdentity *peer,
188 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
189 int32_t amount,
190 struct GNUNET_TIME_Relative res_delay, uint64_t preference) 185 struct GNUNET_TIME_Relative res_delay, uint64_t preference)
191{ 186{
192 struct PeerContext *pc = cls; 187 struct PeerContext *pc = cls;
@@ -212,15 +207,14 @@ preference_cb (void *cls,
212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
213 "Asking core (1) for transmission to peer `%4s'\n", 208 "Asking core (1) for transmission to peer `%4s'\n",
214 GNUNET_i2s (&p2.id)); 209 GNUNET_i2s (&p2.id));
215 if (NULL == (th = GNUNET_CORE_notify_transmit_ready (p1.ch, 210 if (NULL ==
216 GNUNET_YES, 211 (th =
217 0, 212 GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_YES, 0,
218 GNUNET_TIME_relative_multiply 213 GNUNET_TIME_relative_multiply
219 (GNUNET_TIME_UNIT_SECONDS, 214 (GNUNET_TIME_UNIT_SECONDS, 45),
220 45), &p2.id, 215 &p2.id,
221 sizeof (struct 216 sizeof (struct GNUNET_MessageHeader),
222 GNUNET_MessageHeader), 217 &transmit_ready, &p1)))
223 &transmit_ready, &p1)))
224 { 218 {
225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
226 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", 220 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
@@ -230,8 +224,7 @@ preference_cb (void *cls,
230 224
231 225
232static void 226static void
233connect_notify (void *cls, 227connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
234 const struct GNUNET_PeerIdentity *peer,
235 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 228 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
236{ 229{
237 struct PeerContext *pc = cls; 230 struct PeerContext *pc = cls;
@@ -286,14 +279,13 @@ disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
286 th = NULL; 279 th = NULL;
287 } 280 }
288 } 281 }
289 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 282 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted connection to `%4s' cut\n",
290 "Encrypted connection to `%4s' cut\n", GNUNET_i2s (peer)); 283 GNUNET_i2s (peer));
291} 284}
292 285
293 286
294static int 287static int
295inbound_notify (void *cls, 288inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
296 const struct GNUNET_PeerIdentity *other,
297 const struct GNUNET_MessageHeader *message, 289 const struct GNUNET_MessageHeader *message,
298 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 290 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
299{ 291{
@@ -304,8 +296,7 @@ inbound_notify (void *cls,
304 296
305 297
306static int 298static int
307outbound_notify (void *cls, 299outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
308 const struct GNUNET_PeerIdentity *other,
309 const struct GNUNET_MessageHeader *message, 300 const struct GNUNET_MessageHeader *message,
310 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 301 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
311{ 302{
@@ -318,13 +309,12 @@ outbound_notify (void *cls,
318 309
319 310
320static int 311static int
321process_mtype (void *cls, 312process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
322 const struct GNUNET_PeerIdentity *peer,
323 const struct GNUNET_MessageHeader *message, 313 const struct GNUNET_MessageHeader *message,
324 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 314 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
325{ 315{
326 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 316 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving message from `%4s'.\n",
327 "Receiving message from `%4s'.\n", GNUNET_i2s (peer)); 317 GNUNET_i2s (peer));
328 GNUNET_assert (ok == 5); 318 GNUNET_assert (ok == 5);
329 OKPP; 319 OKPP;
330 GNUNET_SCHEDULER_cancel (err_task); 320 GNUNET_SCHEDULER_cancel (err_task);
@@ -345,8 +335,8 @@ static void
345ask_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 335ask_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
346{ 336{
347 ask_task = 337 ask_task =
348 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 338 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &ask_connect_task,
349 &ask_connect_task, NULL); 339 NULL);
350 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
351 "Asking core (1) AGAIN to connect to peer `%4s'\n", 341 "Asking core (1) AGAIN to connect to peer `%4s'\n",
352 GNUNET_i2s (&p2.id)); 342 GNUNET_i2s (&p2.id));
@@ -355,15 +345,13 @@ ask_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
355 345
356 346
357static void 347static void
358init_notify (void *cls, 348init_notify (void *cls, struct GNUNET_CORE_Handle *server,
359 struct GNUNET_CORE_Handle *server,
360 const struct GNUNET_PeerIdentity *my_identity, 349 const struct GNUNET_PeerIdentity *my_identity,
361 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) 350 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
362{ 351{
363 struct PeerContext *p = cls; 352 struct PeerContext *p = cls;
364 353
365 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 354 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core connection to `%4s' established\n",
366 "Core connection to `%4s' established\n",
367 GNUNET_i2s (my_identity)); 355 GNUNET_i2s (my_identity));
368 GNUNET_assert (server != NULL); 356 GNUNET_assert (server != NULL);
369 p->id = *my_identity; 357 p->id = *my_identity;
@@ -373,14 +361,9 @@ init_notify (void *cls,
373 GNUNET_assert (ok == 2); 361 GNUNET_assert (ok == 2);
374 OKPP; 362 OKPP;
375 /* connect p2 */ 363 /* connect p2 */
376 GNUNET_CORE_connect (p2.cfg, 1, 364 GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify,
377 &p2, 365 &disconnect_notify, NULL, &inbound_notify, GNUNET_YES,
378 &init_notify, 366 &outbound_notify, GNUNET_YES, handlers);
379 &connect_notify,
380 &disconnect_notify,
381 NULL,
382 &inbound_notify,
383 GNUNET_YES, &outbound_notify, GNUNET_YES, handlers);
384 } 367 }
385 else 368 else
386 { 369 {
@@ -432,12 +415,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
432{ 415{
433 p->cfg = GNUNET_CONFIGURATION_create (); 416 p->cfg = GNUNET_CONFIGURATION_create ();
434#if START_ARM 417#if START_ARM
435 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 418 p->arm_proc =
436 "gnunet-service-arm", 419 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
420 "gnunet-service-arm",
437#if VERBOSE 421#if VERBOSE
438 "-L", "DEBUG", 422 "-L", "DEBUG",
439#endif 423#endif
440 "-c", cfgname, NULL); 424 "-c", cfgname, NULL);
441#endif 425#endif
442 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 426 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
443 p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); 427 p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL);
@@ -447,22 +431,16 @@ setup_peer (struct PeerContext *p, const char *cfgname)
447 431
448 432
449static void 433static void
450run (void *cls, 434run (void *cls, char *const *args, const char *cfgfile,
451 char *const *args, 435 const struct GNUNET_CONFIGURATION_Handle *cfg)
452 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
453{ 436{
454 GNUNET_assert (ok == 1); 437 GNUNET_assert (ok == 1);
455 OKPP; 438 OKPP;
456 setup_peer (&p1, "test_core_quota_asymmetric_recv_limited_peer1.conf"); 439 setup_peer (&p1, "test_core_quota_asymmetric_recv_limited_peer1.conf");
457 setup_peer (&p2, "test_core_quota_asymmetric_recv_limited_peer2.conf"); 440 setup_peer (&p2, "test_core_quota_asymmetric_recv_limited_peer2.conf");
458 GNUNET_CORE_connect (p1.cfg, 1, 441 GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify,
459 &p1, 442 &disconnect_notify, NULL, &inbound_notify, GNUNET_YES,
460 &init_notify, 443 &outbound_notify, GNUNET_YES, handlers);
461 &connect_notify,
462 &disconnect_notify,
463 NULL,
464 &inbound_notify,
465 GNUNET_YES, &outbound_notify, GNUNET_YES, handlers);
466} 444}
467 445
468static void 446static void
@@ -473,8 +451,7 @@ stop_arm (struct PeerContext *p)
473 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 451 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
474 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 452 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
475 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 453 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
476 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 454 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
477 "ARM process %u stopped\n",
478 GNUNET_OS_process_get_pid (p->arm_proc)); 455 GNUNET_OS_process_get_pid (p->arm_proc));
479 GNUNET_OS_process_close (p->arm_proc); 456 GNUNET_OS_process_close (p->arm_proc);
480 p->arm_proc = NULL; 457 p->arm_proc = NULL;
@@ -497,9 +474,9 @@ check ()
497 GNUNET_GETOPT_OPTION_END 474 GNUNET_GETOPT_OPTION_END
498 }; 475 };
499 ok = 1; 476 ok = 1;
500 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 477 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
501 argv, "test-core-api-preferences", "nohelp", options, 478 "test-core-api-preferences", "nohelp", options, &run,
502 &run, &ok); 479 &ok);
503 stop_arm (&p1); 480 stop_arm (&p1);
504 stop_arm (&p2); 481 stop_arm (&p2);
505 return ok; 482 return ok;
diff --git a/src/core/test_core_api_reliability.c b/src/core/test_core_api_reliability.c
index 1f82a0058..afe6ad269 100644
--- a/src/core/test_core_api_reliability.c
+++ b/src/core/test_core_api_reliability.c
@@ -132,8 +132,8 @@ terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
132 GNUNET_TRANSPORT_disconnect (p2.th); 132 GNUNET_TRANSPORT_disconnect (p2.th);
133 p2.th = NULL; 133 p2.th = NULL;
134 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; 134 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value;
135 fprintf (stderr, 135 fprintf (stderr, "\nThroughput was %llu kb/s\n",
136 "\nThroughput was %llu kb/s\n", total_bytes * 1000 / 1024 / delta); 136 total_bytes * 1000 / 1024 / delta);
137 GAUGER ("CORE", "Core throughput/s", total_bytes * 1000 / 1024 / delta, 137 GAUGER ("CORE", "Core throughput/s", total_bytes * 1000 / 1024 / delta,
138 "kb/s"); 138 "kb/s");
139 ok = 0; 139 ok = 0;
@@ -183,11 +183,8 @@ transmit_ready (void *cls, size_t size, void *buf)
183 { 183 {
184 if (p1.ch != NULL) 184 if (p1.ch != NULL)
185 GNUNET_break (NULL != 185 GNUNET_break (NULL !=
186 GNUNET_CORE_notify_transmit_ready (p1.ch, 186 GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0,
187 GNUNET_NO, 187 FAST_TIMEOUT, &p2.id,
188 0,
189 FAST_TIMEOUT,
190 &p2.id,
191 get_size (tr_n), 188 get_size (tr_n),
192 &transmit_ready, &p1)); 189 &transmit_ready, &p1));
193 return 0; 190 return 0;
@@ -229,8 +226,7 @@ transmit_ready (void *cls, size_t size, void *buf)
229 226
230 227
231static void 228static void
232connect_notify (void *cls, 229connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
233 const struct GNUNET_PeerIdentity *peer,
234 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 230 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
235{ 231{
236 struct PeerContext *pc = cls; 232 struct PeerContext *pc = cls;
@@ -252,11 +248,8 @@ connect_notify (void *cls,
252 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL); 248 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL);
253 start_time = GNUNET_TIME_absolute_get (); 249 start_time = GNUNET_TIME_absolute_get ();
254 GNUNET_break (NULL != 250 GNUNET_break (NULL !=
255 GNUNET_CORE_notify_transmit_ready (p1.ch, 251 GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0,
256 GNUNET_NO, 252 TIMEOUT, &p2.id,
257 0,
258 TIMEOUT,
259 &p2.id,
260 get_size (0), 253 get_size (0),
261 &transmit_ready, &p1)); 254 &transmit_ready, &p1));
262 } 255 }
@@ -271,14 +264,13 @@ disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
271 if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) 264 if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
272 return; 265 return;
273 pc->connect_status = 0; 266 pc->connect_status = 0;
274 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 267 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted connection to `%4s' cut\n",
275 "Encrypted connection to `%4s' cut\n", GNUNET_i2s (peer)); 268 GNUNET_i2s (peer));
276} 269}
277 270
278 271
279static int 272static int
280inbound_notify (void *cls, 273inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
281 const struct GNUNET_PeerIdentity *other,
282 const struct GNUNET_MessageHeader *message, 274 const struct GNUNET_MessageHeader *message,
283 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 275 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
284{ 276{
@@ -291,8 +283,7 @@ inbound_notify (void *cls,
291 283
292 284
293static int 285static int
294outbound_notify (void *cls, 286outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
295 const struct GNUNET_PeerIdentity *other,
296 const struct GNUNET_MessageHeader *message, 287 const struct GNUNET_MessageHeader *message,
297 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 288 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
298{ 289{
@@ -308,8 +299,7 @@ outbound_notify (void *cls,
308static size_t transmit_ready (void *cls, size_t size, void *buf); 299static size_t transmit_ready (void *cls, size_t size, void *buf);
309 300
310static int 301static int
311process_mtype (void *cls, 302process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
312 const struct GNUNET_PeerIdentity *peer,
313 const struct GNUNET_MessageHeader *message, 303 const struct GNUNET_MessageHeader *message,
314 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 304 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
315{ 305{
@@ -340,8 +330,7 @@ process_mtype (void *cls,
340 return GNUNET_SYSERR; 330 return GNUNET_SYSERR;
341 } 331 }
342#if VERBOSE 332#if VERBOSE
343 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 333 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got message %u of size %u\n",
344 "Got message %u of size %u\n",
345 ntohl (hdr->num), ntohs (message->size)); 334 ntohl (hdr->num), ntohs (message->size));
346#endif 335#endif
347 n++; 336 n++;
@@ -356,11 +345,8 @@ process_mtype (void *cls,
356 { 345 {
357 if (n == tr_n) 346 if (n == tr_n)
358 GNUNET_break (NULL != 347 GNUNET_break (NULL !=
359 GNUNET_CORE_notify_transmit_ready (p1.ch, 348 GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0,
360 GNUNET_NO, 349 FAST_TIMEOUT, &p2.id,
361 0,
362 FAST_TIMEOUT,
363 &p2.id,
364 get_size (tr_n), 350 get_size (tr_n),
365 &transmit_ready, &p1)); 351 &transmit_ready, &p1));
366 } 352 }
@@ -376,8 +362,7 @@ static struct GNUNET_CORE_MessageHandler handlers[] = {
376 362
377 363
378static void 364static void
379init_notify (void *cls, 365init_notify (void *cls, struct GNUNET_CORE_Handle *server,
380 struct GNUNET_CORE_Handle *server,
381 const struct GNUNET_PeerIdentity *my_identity, 366 const struct GNUNET_PeerIdentity *my_identity,
382 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) 367 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
383{ 368{
@@ -394,14 +379,9 @@ init_notify (void *cls,
394 GNUNET_assert (ok == 2); 379 GNUNET_assert (ok == 2);
395 OKPP; 380 OKPP;
396 /* connect p2 */ 381 /* connect p2 */
397 GNUNET_CORE_connect (p2.cfg, 1, 382 GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify,
398 &p2, 383 &disconnect_notify, NULL, &inbound_notify, GNUNET_YES,
399 &init_notify, 384 &outbound_notify, GNUNET_YES, handlers);
400 &connect_notify,
401 &disconnect_notify,
402 NULL,
403 &inbound_notify,
404 GNUNET_YES, &outbound_notify, GNUNET_YES, handlers);
405 } 385 }
406 else 386 else
407 { 387 {
@@ -444,12 +424,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
444{ 424{
445 p->cfg = GNUNET_CONFIGURATION_create (); 425 p->cfg = GNUNET_CONFIGURATION_create ();
446#if START_ARM 426#if START_ARM
447 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 427 p->arm_proc =
448 "gnunet-service-arm", 428 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
429 "gnunet-service-arm",
449#if VERBOSE 430#if VERBOSE
450 "-L", "DEBUG", 431 "-L", "DEBUG",
451#endif 432#endif
452 "-c", cfgname, NULL); 433 "-c", cfgname, NULL);
453#endif 434#endif
454 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 435 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
455 p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); 436 p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL);
@@ -459,9 +440,8 @@ setup_peer (struct PeerContext *p, const char *cfgname)
459 440
460 441
461static void 442static void
462run (void *cls, 443run (void *cls, char *const *args, const char *cfgfile,
463 char *const *args, 444 const struct GNUNET_CONFIGURATION_Handle *cfg)
464 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
465{ 445{
466 GNUNET_assert (ok == 1); 446 GNUNET_assert (ok == 1);
467 OKPP; 447 OKPP;
@@ -469,14 +449,9 @@ run (void *cls,
469 setup_peer (&p2, "test_core_api_peer2.conf"); 449 setup_peer (&p2, "test_core_api_peer2.conf");
470 err_task = 450 err_task =
471 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL); 451 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL);
472 GNUNET_CORE_connect (p1.cfg, 1, 452 GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify,
473 &p1, 453 &disconnect_notify, NULL, &inbound_notify, GNUNET_YES,
474 &init_notify, 454 &outbound_notify, GNUNET_YES, handlers);
475 &connect_notify,
476 &disconnect_notify,
477 NULL,
478 &inbound_notify,
479 GNUNET_YES, &outbound_notify, GNUNET_YES, handlers);
480} 455}
481 456
482 457
@@ -488,8 +463,7 @@ stop_arm (struct PeerContext *p)
488 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 463 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
489 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 464 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
490 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 465 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
491 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 466 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
492 "ARM process %u stopped\n",
493 GNUNET_OS_process_get_pid (p->arm_proc)); 467 GNUNET_OS_process_get_pid (p->arm_proc));
494 GNUNET_OS_process_close (p->arm_proc); 468 GNUNET_OS_process_close (p->arm_proc);
495 p->arm_proc = NULL; 469 p->arm_proc = NULL;
@@ -512,9 +486,9 @@ check ()
512 GNUNET_GETOPT_OPTION_END 486 GNUNET_GETOPT_OPTION_END
513 }; 487 };
514 ok = 1; 488 ok = 1;
515 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 489 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
516 argv, "test-core-api-reliability", "nohelp", options, 490 "test-core-api-reliability", "nohelp", options, &run,
517 &run, &ok); 491 &ok);
518 stop_arm (&p1); 492 stop_arm (&p1);
519 stop_arm (&p2); 493 stop_arm (&p2);
520 return ok; 494 return ok;
diff --git a/src/core/test_core_api_send_to_self.c b/src/core/test_core_api_send_to_self.c
index 09d6edacc..808447fa1 100644
--- a/src/core/test_core_api_send_to_self.c
+++ b/src/core/test_core_api_send_to_self.c
@@ -79,8 +79,8 @@ cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tskctx)
79 if (GNUNET_OS_process_wait (arm_proc) != GNUNET_OK) 79 if (GNUNET_OS_process_wait (arm_proc) != GNUNET_OK)
80 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 80 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
81 81
82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
83 "ARM process %u stopped\n", GNUNET_OS_process_get_pid (arm_proc)); 83 GNUNET_OS_process_get_pid (arm_proc));
84 GNUNET_OS_process_close (arm_proc); 84 GNUNET_OS_process_close (arm_proc);
85 arm_proc = NULL; 85 arm_proc = NULL;
86 86
@@ -143,10 +143,8 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
143 { 143 {
144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
145 "Connected to myself; sending message!\n"); 145 "Connected to myself; sending message!\n");
146 GNUNET_CORE_notify_transmit_ready (core, 146 GNUNET_CORE_notify_transmit_ready (core, GNUNET_YES, 0,
147 GNUNET_YES, 147 GNUNET_TIME_UNIT_FOREVER_REL, peer,
148 0, GNUNET_TIME_UNIT_FOREVER_REL,
149 peer,
150 sizeof (struct GNUNET_MessageHeader), 148 sizeof (struct GNUNET_MessageHeader),
151 send_message, NULL); 149 send_message, NULL);
152 } 150 }
@@ -162,9 +160,8 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
162 * @param cfg configuration 160 * @param cfg configuration
163 */ 161 */
164static void 162static void
165run (void *cls, 163run (void *cls, char *const *args, const char *cfgfile,
166 char *const *args, 164 const struct GNUNET_CONFIGURATION_Handle *cfg)
167 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
168{ 165{
169 const static struct GNUNET_CORE_MessageHandler handlers[] = { 166 const static struct GNUNET_CORE_MessageHandler handlers[] = {
170 {&receive, GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP, 0}, 167 {&receive, GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP, 0},
@@ -173,23 +170,21 @@ run (void *cls,
173 170
174 core_cfg = GNUNET_CONFIGURATION_create (); 171 core_cfg = GNUNET_CONFIGURATION_create ();
175 172
176 arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 173 arm_proc =
177 "gnunet-service-arm", 174 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
175 "gnunet-service-arm",
178#if VERBOSE 176#if VERBOSE
179 "-L", "DEBUG", 177 "-L", "DEBUG",
180#endif 178#endif
181 "-c", "test_core_api_peer1.conf", NULL); 179 "-c", "test_core_api_peer1.conf", NULL);
182 180
183 GNUNET_assert (GNUNET_OK == 181 GNUNET_assert (GNUNET_OK ==
184 GNUNET_CONFIGURATION_load (core_cfg, 182 GNUNET_CONFIGURATION_load (core_cfg,
185 "test_core_api_peer1.conf")); 183 "test_core_api_peer1.conf"));
186 184
187 core = GNUNET_CORE_connect (core_cfg, 185 core =
188 42, 186 GNUNET_CORE_connect (core_cfg, 42, NULL, &init, &connect_cb, NULL, NULL,
189 NULL, 187 NULL, 0, NULL, 0, handlers);
190 &init,
191 &connect_cb,
192 NULL, NULL, NULL, 0, NULL, 0, handlers);
193 188
194 die_task = 189 die_task =
195 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 190 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
@@ -217,11 +212,10 @@ check ()
217 ret = 1; 212 ret = 1;
218 213
219 return (GNUNET_OK == 214 return (GNUNET_OK ==
220 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 215 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
221 argv,
222 "test_core_api_send_to_self", 216 "test_core_api_send_to_self",
223 gettext_noop ("help text"), 217 gettext_noop ("help text"), options, &run,
224 options, &run, NULL)) ? ret : 1; 218 NULL)) ? ret : 1;
225} 219}
226 220
227/** 221/**
diff --git a/src/core/test_core_api_start_only.c b/src/core/test_core_api_start_only.c
index 36d964796..ca301f51e 100644
--- a/src/core/test_core_api_start_only.c
+++ b/src/core/test_core_api_start_only.c
@@ -66,8 +66,7 @@ static int ok;
66 66
67 67
68static void 68static void
69connect_notify (void *cls, 69connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
70 const struct GNUNET_PeerIdentity *peer,
71 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 70 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
72{ 71{
73} 72}
@@ -80,8 +79,7 @@ disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
80 79
81 80
82static int 81static int
83inbound_notify (void *cls, 82inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
84 const struct GNUNET_PeerIdentity *other,
85 const struct GNUNET_MessageHeader *message, 83 const struct GNUNET_MessageHeader *message,
86 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 84 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
87{ 85{
@@ -90,8 +88,7 @@ inbound_notify (void *cls,
90 88
91 89
92static int 90static int
93outbound_notify (void *cls, 91outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
94 const struct GNUNET_PeerIdentity *other,
95 const struct GNUNET_MessageHeader *message, 92 const struct GNUNET_MessageHeader *message,
96 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 93 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
97{ 94{
@@ -118,8 +115,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
118 115
119 116
120static void 117static void
121init_notify (void *cls, 118init_notify (void *cls, struct GNUNET_CORE_Handle *server,
122 struct GNUNET_CORE_Handle *server,
123 const struct GNUNET_PeerIdentity *my_identity, 119 const struct GNUNET_PeerIdentity *my_identity,
124 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) 120 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
125{ 121{
@@ -130,15 +126,11 @@ init_notify (void *cls,
130 if (cls == &p1) 126 if (cls == &p1)
131 { 127 {
132 /* connect p2 */ 128 /* connect p2 */
133 p2.ch = GNUNET_CORE_connect (p2.cfg, 1, 129 p2.ch =
134 &p2, 130 GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify,
135 &init_notify, 131 &disconnect_notify, NULL, &inbound_notify,
136 &connect_notify, 132 GNUNET_YES, &outbound_notify, GNUNET_YES,
137 &disconnect_notify, 133 handlers);
138 NULL,
139 &inbound_notify,
140 GNUNET_YES,
141 &outbound_notify, GNUNET_YES, handlers);
142 } 134 }
143 else 135 else
144 { 136 {
@@ -154,12 +146,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
154{ 146{
155 p->cfg = GNUNET_CONFIGURATION_create (); 147 p->cfg = GNUNET_CONFIGURATION_create ();
156#if START_ARM 148#if START_ARM
157 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 149 p->arm_proc =
158 "gnunet-service-arm", 150 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
151 "gnunet-service-arm",
159#if VERBOSE 152#if VERBOSE
160 "-L", "DEBUG", 153 "-L", "DEBUG",
161#endif 154#endif
162 "-c", cfgname, NULL); 155 "-c", cfgname, NULL);
163#endif 156#endif
164 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 157 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
165} 158}
@@ -185,9 +178,8 @@ timeout_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
185 178
186 179
187static void 180static void
188run (void *cls, 181run (void *cls, char *const *args, const char *cfgfile,
189 char *const *args, 182 const struct GNUNET_CONFIGURATION_Handle *cfg)
190 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
191{ 183{
192 GNUNET_assert (ok == 1); 184 GNUNET_assert (ok == 1);
193 OKPP; 185 OKPP;
@@ -213,8 +205,7 @@ stop_arm (struct PeerContext *p)
213 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 205 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
214 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 206 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
215 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 207 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
217 "ARM process %u stopped\n",
218 GNUNET_OS_process_get_pid (p->arm_proc)); 209 GNUNET_OS_process_get_pid (p->arm_proc));
219 GNUNET_OS_process_close (p->arm_proc); 210 GNUNET_OS_process_close (p->arm_proc);
220 p->arm_proc = NULL; 211 p->arm_proc = NULL;
@@ -241,9 +232,8 @@ check ()
241 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2"); 232 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2");
242 233
243 ok = 1; 234 ok = 1;
244 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 235 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
245 argv, "test-core-api-start-only", "nohelp", options, &run, 236 "test-core-api-start-only", "nohelp", options, &run, &ok);
246 &ok);
247 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test finished\n"); 237 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test finished\n");
248 stop_arm (&p1); 238 stop_arm (&p1);
249 stop_arm (&p2); 239 stop_arm (&p2);
diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c
index 5dcc20597..88ba2c0f2 100644
--- a/src/core/test_core_quota_compliance.c
+++ b/src/core/test_core_quota_compliance.c
@@ -173,16 +173,15 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
173 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration 173 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
174 */ 174 */
175static int 175static int
176print_stat (void *cls, 176print_stat (void *cls, const char *subsystem, const char *name, uint64_t value,
177 const char *subsystem, 177 int is_persistent)
178 const char *name, uint64_t value, int is_persistent)
179{ 178{
180 if (cls == &p1) 179 if (cls == &p1)
181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer1 %50s = %12llu\n", name,
182 "Peer1 %50s = %12llu\n", name, (unsigned long long) value); 181 (unsigned long long) value);
183 if (cls == &p2) 182 if (cls == &p2)
184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer2 %50s = %12llu\n", name,
185 "Peer2 %50s = %12llu\n", name, (unsigned long long) value); 184 (unsigned long long) value);
186 return GNUNET_OK; 185 return GNUNET_OK;
187} 186}
188 187
@@ -225,38 +224,28 @@ measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
225 else 224 else
226 ok = 0; 225 ok = 0;
227 226
228 GNUNET_STATISTICS_get (p1.stats, 227 GNUNET_STATISTICS_get (p1.stats, "core", "# discarded CORE_SEND requests",
229 "core",
230 "# discarded CORE_SEND requests",
231 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1); 228 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1);
232 229
233 GNUNET_STATISTICS_get (p1.stats, 230 GNUNET_STATISTICS_get (p1.stats, "core",
234 "core",
235 "# discarded CORE_SEND request bytes", 231 "# discarded CORE_SEND request bytes",
236 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1); 232 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1);
237 GNUNET_STATISTICS_get (p1.stats, 233 GNUNET_STATISTICS_get (p1.stats, "core",
238 "core",
239 "# discarded lower priority CORE_SEND requests", 234 "# discarded lower priority CORE_SEND requests",
240 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, NULL); 235 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, NULL);
241 GNUNET_STATISTICS_get (p1.stats, 236 GNUNET_STATISTICS_get (p1.stats, "core",
242 "core",
243 "# discarded lower priority CORE_SEND request bytes", 237 "# discarded lower priority CORE_SEND request bytes",
244 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1); 238 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1);
245 GNUNET_STATISTICS_get (p2.stats, 239 GNUNET_STATISTICS_get (p2.stats, "core", "# discarded CORE_SEND requests",
246 "core",
247 "# discarded CORE_SEND requests",
248 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2); 240 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);
249 241
250 GNUNET_STATISTICS_get (p2.stats, 242 GNUNET_STATISTICS_get (p2.stats, "core",
251 "core",
252 "# discarded CORE_SEND request bytes", 243 "# discarded CORE_SEND request bytes",
253 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2); 244 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);
254 GNUNET_STATISTICS_get (p2.stats, 245 GNUNET_STATISTICS_get (p2.stats, "core",
255 "core",
256 "# discarded lower priority CORE_SEND requests", 246 "# discarded lower priority CORE_SEND requests",
257 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2); 247 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);
258 GNUNET_STATISTICS_get (p2.stats, 248 GNUNET_STATISTICS_get (p2.stats, "core",
259 "core",
260 "# discarded lower priority CORE_SEND request bytes", 249 "# discarded lower priority CORE_SEND request bytes",
261 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2); 250 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);
262 251
@@ -312,11 +301,8 @@ transmit_ready (void *cls, size_t size, void *buf)
312 { 301 {
313 if ((p1.ch != NULL) && (p1.connect_status == 1)) 302 if ((p1.ch != NULL) && (p1.connect_status == 1))
314 GNUNET_break (NULL != 303 GNUNET_break (NULL !=
315 GNUNET_CORE_notify_transmit_ready (p1.ch, 304 GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0,
316 GNUNET_NO, 305 FAST_TIMEOUT, &p2.id,
317 0,
318 FAST_TIMEOUT,
319 &p2.id,
320 MESSAGESIZE, 306 MESSAGESIZE,
321 &transmit_ready, &p1)); 307 &transmit_ready, &p1));
322 return 0; 308 return 0;
@@ -330,8 +316,8 @@ transmit_ready (void *cls, size_t size, void *buf)
330 { 316 {
331#if DEBUG_TRANSMISSION 317#if DEBUG_TRANSMISSION
332 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 318 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
333 "Sending message %u of size %u at offset %u\n", 319 "Sending message %u of size %u at offset %u\n", tr_n,
334 tr_n, MESSAGESIZE, ret); 320 MESSAGESIZE, ret);
335#endif 321#endif
336 hdr.header.size = htons (MESSAGESIZE); 322 hdr.header.size = htons (MESSAGESIZE);
337 hdr.header.type = htons (MTYPE); 323 hdr.header.type = htons (MTYPE);
@@ -346,8 +332,8 @@ transmit_ready (void *cls, size_t size, void *buf)
346 } 332 }
347 while (size - ret >= MESSAGESIZE); 333 while (size - ret >= MESSAGESIZE);
348 GNUNET_SCHEDULER_cancel (err_task); 334 GNUNET_SCHEDULER_cancel (err_task);
349 err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 335 err_task =
350 &terminate_task_error, NULL); 336 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL);
351 337
352 total_bytes_sent += ret; 338 total_bytes_sent += ret;
353 return ret; 339 return ret;
@@ -356,8 +342,7 @@ transmit_ready (void *cls, size_t size, void *buf)
356 342
357 343
358static void 344static void
359connect_notify (void *cls, 345connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
360 const struct GNUNET_PeerIdentity *peer,
361 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 346 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
362{ 347{
363 struct PeerContext *pc = cls; 348 struct PeerContext *pc = cls;
@@ -378,22 +363,19 @@ connect_notify (void *cls,
378#endif 363#endif
379 if (err_task != GNUNET_SCHEDULER_NO_TASK) 364 if (err_task != GNUNET_SCHEDULER_NO_TASK)
380 GNUNET_SCHEDULER_cancel (err_task); 365 GNUNET_SCHEDULER_cancel (err_task);
381 err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 366 err_task =
382 &terminate_task_error, NULL); 367 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL);
383 start_time = GNUNET_TIME_absolute_get (); 368 start_time = GNUNET_TIME_absolute_get ();
384 running = GNUNET_YES; 369 running = GNUNET_YES;
385 measure_task = 370 measure_task =
386 GNUNET_SCHEDULER_add_delayed (MEASUREMENT_LENGTH, &measurement_stop, 371 GNUNET_SCHEDULER_add_delayed (MEASUREMENT_LENGTH, &measurement_stop,
387 NULL); 372 NULL);
388 373
389 GNUNET_break (NULL != GNUNET_CORE_notify_transmit_ready (p1.ch, 374 GNUNET_break (NULL !=
390 GNUNET_NO, 375 GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0,
391 0, 376 TIMEOUT, &p2.id,
392 TIMEOUT, 377 MESSAGESIZE,
393 &p2.id, 378 &transmit_ready, &p1));
394 MESSAGESIZE,
395 &transmit_ready,
396 &p1));
397 } 379 }
398} 380}
399 381
@@ -407,15 +389,14 @@ disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
407 return; 389 return;
408 pc->connect_status = 0; 390 pc->connect_status = 0;
409#if DEBUG_TRANSMISSION 391#if DEBUG_TRANSMISSION
410 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted connection to `%4s' cut\n",
411 "Encrypted connection to `%4s' cut\n", GNUNET_i2s (peer)); 393 GNUNET_i2s (peer));
412#endif 394#endif
413} 395}
414 396
415 397
416static int 398static int
417inbound_notify (void *cls, 399inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
418 const struct GNUNET_PeerIdentity *other,
419 const struct GNUNET_MessageHeader *message, 400 const struct GNUNET_MessageHeader *message,
420 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 401 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
421{ 402{
@@ -430,8 +411,7 @@ inbound_notify (void *cls,
430 411
431 412
432static int 413static int
433outbound_notify (void *cls, 414outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
434 const struct GNUNET_PeerIdentity *other,
435 const struct GNUNET_MessageHeader *message, 415 const struct GNUNET_MessageHeader *message,
436 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 416 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
437{ 417{
@@ -447,8 +427,7 @@ outbound_notify (void *cls,
447static size_t transmit_ready (void *cls, size_t size, void *buf); 427static size_t transmit_ready (void *cls, size_t size, void *buf);
448 428
449static int 429static int
450process_mtype (void *cls, 430process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
451 const struct GNUNET_PeerIdentity *peer,
452 const struct GNUNET_MessageHeader *message, 431 const struct GNUNET_MessageHeader *message,
453 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 432 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
454{ 433{
@@ -477,8 +456,7 @@ process_mtype (void *cls,
477 return GNUNET_SYSERR; 456 return GNUNET_SYSERR;
478 } 457 }
479#if DEBUG_TRANSMISSION 458#if DEBUG_TRANSMISSION
480 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 459 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got message %u of size %u\n",
481 "Got message %u of size %u\n",
482 ntohl (hdr->num), ntohs (message->size)); 460 ntohl (hdr->num), ntohs (message->size));
483#endif 461#endif
484 n++; 462 n++;
@@ -488,11 +466,8 @@ process_mtype (void *cls,
488 466
489 if (running == GNUNET_YES) 467 if (running == GNUNET_YES)
490 GNUNET_break (NULL != 468 GNUNET_break (NULL !=
491 GNUNET_CORE_notify_transmit_ready (p1.ch, 469 GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0,
492 GNUNET_NO, 470 FAST_TIMEOUT, &p2.id,
493 0,
494 FAST_TIMEOUT,
495 &p2.id,
496 MESSAGESIZE, 471 MESSAGESIZE,
497 &transmit_ready, &p1)); 472 &transmit_ready, &p1));
498 return GNUNET_OK; 473 return GNUNET_OK;
@@ -507,8 +482,7 @@ static struct GNUNET_CORE_MessageHandler handlers[] = {
507 482
508 483
509static void 484static void
510init_notify (void *cls, 485init_notify (void *cls, struct GNUNET_CORE_Handle *server,
511 struct GNUNET_CORE_Handle *server,
512 const struct GNUNET_PeerIdentity *my_identity, 486 const struct GNUNET_PeerIdentity *my_identity,
513 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) 487 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
514{ 488{
@@ -525,14 +499,9 @@ init_notify (void *cls,
525 GNUNET_assert (ok == 2); 499 GNUNET_assert (ok == 2);
526 OKPP; 500 OKPP;
527 /* connect p2 */ 501 /* connect p2 */
528 GNUNET_CORE_connect (p2.cfg, 1, 502 GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify,
529 &p2, 503 &disconnect_notify, NULL, &inbound_notify, GNUNET_YES,
530 &init_notify, 504 &outbound_notify, GNUNET_YES, handlers);
531 &connect_notify,
532 &disconnect_notify,
533 NULL,
534 &inbound_notify,
535 GNUNET_YES, &outbound_notify, GNUNET_YES, handlers);
536 } 505 }
537 else 506 else
538 { 507 {
@@ -580,12 +549,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
580{ 549{
581 p->cfg = GNUNET_CONFIGURATION_create (); 550 p->cfg = GNUNET_CONFIGURATION_create ();
582#if START_ARM 551#if START_ARM
583 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 552 p->arm_proc =
584 "gnunet-service-arm", 553 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
554 "gnunet-service-arm",
585#if VERBOSE 555#if VERBOSE
586 "-L", "DEBUG", 556 "-L", "DEBUG",
587#endif 557#endif
588 "-c", cfgname, NULL); 558 "-c", cfgname, NULL);
589#endif 559#endif
590 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 560 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
591 p->stats = GNUNET_STATISTICS_create ("core", p->cfg); 561 p->stats = GNUNET_STATISTICS_create ("core", p->cfg);
@@ -597,14 +567,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
597 567
598 568
599static void 569static void
600run (void *cls, 570run (void *cls, char *const *args, const char *cfgfile,
601 char *const *args, 571 const struct GNUNET_CONFIGURATION_Handle *cfg)
602 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
603{ 572{
604 GNUNET_assert (ok == 1); 573 GNUNET_assert (ok == 1);
605 OKPP; 574 OKPP;
606 err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 575 err_task =
607 &terminate_task_error, NULL); 576 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL);
608 if (test == SYMMETRIC) 577 if (test == SYMMETRIC)
609 { 578 {
610 setup_peer (&p1, "test_core_quota_peer1.conf"); 579 setup_peer (&p1, "test_core_quota_peer1.conf");
@@ -622,31 +591,26 @@ run (void *cls,
622 } 591 }
623 592
624 GNUNET_assert (test != -1); 593 GNUNET_assert (test != -1);
625 GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p1.cfg, 594 GNUNET_assert (GNUNET_SYSERR !=
626 "CORE", 595 GNUNET_CONFIGURATION_get_value_number (p1.cfg, "CORE",
627 "TOTAL_QUOTA_IN", 596 "TOTAL_QUOTA_IN",
628 &current_quota_p1_in)); 597 &current_quota_p1_in));
629 GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p2.cfg, 598 GNUNET_assert (GNUNET_SYSERR !=
630 "CORE", 599 GNUNET_CONFIGURATION_get_value_number (p2.cfg, "CORE",
631 "TOTAL_QUOTA_IN", 600 "TOTAL_QUOTA_IN",
632 &current_quota_p2_in)); 601 &current_quota_p2_in));
633 GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p1.cfg, 602 GNUNET_assert (GNUNET_SYSERR !=
634 "CORE", 603 GNUNET_CONFIGURATION_get_value_number (p1.cfg, "CORE",
635 "TOTAL_QUOTA_OUT", 604 "TOTAL_QUOTA_OUT",
636 &current_quota_p1_out)); 605 &current_quota_p1_out));
637 GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p2.cfg, 606 GNUNET_assert (GNUNET_SYSERR !=
638 "CORE", 607 GNUNET_CONFIGURATION_get_value_number (p2.cfg, "CORE",
639 "TOTAL_QUOTA_OUT", 608 "TOTAL_QUOTA_OUT",
640 &current_quota_p2_out)); 609 &current_quota_p2_out));
641 610
642 GNUNET_CORE_connect (p1.cfg, 1, 611 GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify,
643 &p1, 612 &disconnect_notify, NULL, &inbound_notify, GNUNET_YES,
644 &init_notify, 613 &outbound_notify, GNUNET_YES, handlers);
645 &connect_notify,
646 &disconnect_notify,
647 NULL,
648 &inbound_notify,
649 GNUNET_YES, &outbound_notify, GNUNET_YES, handlers);
650} 614}
651 615
652 616
@@ -658,8 +622,7 @@ stop_arm (struct PeerContext *p)
658 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 622 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
659 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 623 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
660 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 624 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
661 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 625 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
662 "ARM process %u stopped\n",
663 GNUNET_OS_process_get_pid (p->arm_proc)); 626 GNUNET_OS_process_get_pid (p->arm_proc));
664 GNUNET_OS_process_close (p->arm_proc); 627 GNUNET_OS_process_close (p->arm_proc);
665 p->arm_proc = NULL; 628 p->arm_proc = NULL;
@@ -684,9 +647,9 @@ check ()
684 GNUNET_GETOPT_OPTION_END 647 GNUNET_GETOPT_OPTION_END
685 }; 648 };
686 ok = 1; 649 ok = 1;
687 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 650 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
688 argv, "test-core-quota-compliance", "nohelp", options, 651 "test-core-quota-compliance", "nohelp", options, &run,
689 &run, &ok); 652 &ok);
690 stop_arm (&p1); 653 stop_arm (&p1);
691 stop_arm (&p2); 654 stop_arm (&p2);
692 return ok; 655 return ok;
diff --git a/src/datacache/datacache.c b/src/datacache/datacache.c
index a17eb9628..9d12fbc3e 100644
--- a/src/datacache/datacache.c
+++ b/src/datacache/datacache.c
@@ -105,8 +105,8 @@ env_delete_notify (void *cls, const GNUNET_HashCode * key, size_t size)
105 GNUNET_assert (h->utilization >= size); 105 GNUNET_assert (h->utilization >= size);
106 h->utilization -= size; 106 h->utilization -= size;
107 GNUNET_CONTAINER_bloomfilter_remove (h->filter, key); 107 GNUNET_CONTAINER_bloomfilter_remove (h->filter, key);
108 GNUNET_STATISTICS_update (h->stats, 108 GNUNET_STATISTICS_update (h->stats, gettext_noop ("# bytes stored"), -size,
109 gettext_noop ("# bytes stored"), -size, GNUNET_NO); 109 GNUNET_NO);
110} 110}
111 111
112 112
@@ -131,16 +131,16 @@ GNUNET_DATACACHE_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
131 GNUNET_CONFIGURATION_get_value_number (cfg, section, "QUOTA", &quota)) 131 GNUNET_CONFIGURATION_get_value_number (cfg, section, "QUOTA", &quota))
132 { 132 {
133 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 133 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
134 _("No `%s' specified for `%s' in configuration!\n"), 134 _("No `%s' specified for `%s' in configuration!\n"), "QUOTA",
135 "QUOTA", section); 135 section);
136 return NULL; 136 return NULL;
137 } 137 }
138 if (GNUNET_OK != 138 if (GNUNET_OK !=
139 GNUNET_CONFIGURATION_get_value_string (cfg, section, "DATABASE", &name)) 139 GNUNET_CONFIGURATION_get_value_string (cfg, section, "DATABASE", &name))
140 { 140 {
141 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 141 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
142 _("No `%s' specified for `%s' in configuration!\n"), 142 _("No `%s' specified for `%s' in configuration!\n"), "DATABASE",
143 "DATABASE", section); 143 section);
144 return NULL; 144 return NULL;
145 } 145 }
146 bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */ 146 bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */
@@ -164,8 +164,8 @@ GNUNET_DATACACHE_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
164 ret->env.cls = ret; 164 ret->env.cls = ret;
165 ret->env.delete_notify = &env_delete_notify; 165 ret->env.delete_notify = &env_delete_notify;
166 ret->env.quota = quota; 166 ret->env.quota = quota;
167 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 167 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' datacache plugin\n"),
168 _("Loading `%s' datacache plugin\n"), name); 168 name);
169 GNUNET_asprintf (&libname, "libgnunet_plugin_datacache_%s", name); 169 GNUNET_asprintf (&libname, "libgnunet_plugin_datacache_%s", name);
170 ret->short_name = name; 170 ret->short_name = name;
171 ret->lib_name = libname; 171 ret->lib_name = libname;
@@ -199,8 +199,8 @@ GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h)
199 if (h->bloom_name != NULL) 199 if (h->bloom_name != NULL)
200 { 200 {
201 if (0 != UNLINK (h->bloom_name)) 201 if (0 != UNLINK (h->bloom_name))
202 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 202 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink",
203 "unlink", h->bloom_name); 203 h->bloom_name);
204 GNUNET_free (h->bloom_name); 204 GNUNET_free (h->bloom_name);
205 } 205 }
206 GNUNET_STATISTICS_destroy (h->stats, GNUNET_NO); 206 GNUNET_STATISTICS_destroy (h->stats, GNUNET_NO);
@@ -221,10 +221,8 @@ GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h)
221 */ 221 */
222int 222int
223GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h, 223GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
224 const GNUNET_HashCode * key, 224 const GNUNET_HashCode * key, size_t size,
225 size_t size, 225 const char *data, enum GNUNET_BLOCK_Type type,
226 const char *data,
227 enum GNUNET_BLOCK_Type type,
228 struct GNUNET_TIME_Absolute discard_time) 226 struct GNUNET_TIME_Absolute discard_time)
229{ 227{
230 uint32_t used; 228 uint32_t used;
@@ -235,8 +233,8 @@ GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
235 GNUNET_break (0); 233 GNUNET_break (0);
236 return GNUNET_SYSERR; 234 return GNUNET_SYSERR;
237 } 235 }
238 GNUNET_STATISTICS_update (h->stats, 236 GNUNET_STATISTICS_update (h->stats, gettext_noop ("# bytes stored"), size,
239 gettext_noop ("# bytes stored"), size, GNUNET_NO); 237 GNUNET_NO);
240 GNUNET_CONTAINER_bloomfilter_add (h->filter, key); 238 GNUNET_CONTAINER_bloomfilter_add (h->filter, key);
241 while (h->utilization + used > h->env.quota) 239 while (h->utilization + used > h->env.quota)
242 GNUNET_assert (GNUNET_OK == h->api->del (h->api->cls)); 240 GNUNET_assert (GNUNET_OK == h->api->del (h->api->cls));
@@ -258,12 +256,11 @@ GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
258 */ 256 */
259unsigned int 257unsigned int
260GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h, 258GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h,
261 const GNUNET_HashCode * key, 259 const GNUNET_HashCode * key, enum GNUNET_BLOCK_Type type,
262 enum GNUNET_BLOCK_Type type,
263 GNUNET_DATACACHE_Iterator iter, void *iter_cls) 260 GNUNET_DATACACHE_Iterator iter, void *iter_cls)
264{ 261{
265 GNUNET_STATISTICS_update (h->stats, 262 GNUNET_STATISTICS_update (h->stats, gettext_noop ("# requests received"), 1,
266 gettext_noop ("# requests received"), 1, GNUNET_NO); 263 GNUNET_NO);
267 if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_test (h->filter, key)) 264 if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_test (h->filter, key))
268 { 265 {
269 GNUNET_STATISTICS_update (h->stats, 266 GNUNET_STATISTICS_update (h->stats,
diff --git a/src/datacache/perf_datacache.c b/src/datacache/perf_datacache.c
index 3af76dbb6..a5dc02362 100644
--- a/src/datacache/perf_datacache.c
+++ b/src/datacache/perf_datacache.c
@@ -44,10 +44,9 @@ static const char *plugin_name;
44 44
45 45
46static int 46static int
47checkIt (void *cls, 47checkIt (void *cls, struct GNUNET_TIME_Absolute exp,
48 struct GNUNET_TIME_Absolute exp, 48 const GNUNET_HashCode * key, size_t size, const char *data,
49 const GNUNET_HashCode * key, 49 enum GNUNET_BLOCK_Type type)
50 size_t size, const char *data, enum GNUNET_BLOCK_Type type)
51{ 50{
52 if ((size == sizeof (GNUNET_HashCode)) && (0 == memcmp (data, cls, size))) 51 if ((size == sizeof (GNUNET_HashCode)) && (0 == memcmp (data, cls, size)))
53 found++; 52 found++;
@@ -56,9 +55,8 @@ checkIt (void *cls,
56 55
57 56
58static void 57static void
59run (void *cls, 58run (void *cls, char *const *args, const char *cfgfile,
60 char *const *args, 59 const struct GNUNET_CONFIGURATION_Handle *cfg)
61 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
62{ 60{
63 struct GNUNET_DATACACHE_Handle *h; 61 struct GNUNET_DATACACHE_Handle *h;
64 GNUNET_HashCode k; 62 GNUNET_HashCode k;
@@ -86,21 +84,17 @@ run (void *cls,
86 if (0 == i % (ITERATIONS / 80)) 84 if (0 == i % (ITERATIONS / 80))
87 fprintf (stderr, "."); 85 fprintf (stderr, ".");
88 GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n); 86 GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
89 ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h, 87 ASSERT (GNUNET_OK ==
90 &k, 88 GNUNET_DATACACHE_put (h, &k, sizeof (GNUNET_HashCode),
91 sizeof (GNUNET_HashCode), 89 (const char *) &n, 1 + i % 16, exp));
92 (const char *) &n,
93 1 + i % 16, exp));
94 k = n; 90 k = n;
95 } 91 }
96 fprintf (stderr, "\n"); 92 fprintf (stderr, "\n");
97 fprintf (stdout, "Stored %u items in %llums\n", 93 fprintf (stdout, "Stored %u items in %llums\n", ITERATIONS,
98 ITERATIONS, 94 (unsigned long long) GNUNET_TIME_absolute_get_duration (start).
99 (unsigned long long) 95 rel_value);
100 GNUNET_TIME_absolute_get_duration (start).rel_value);
101 GNUNET_snprintf (gstr, sizeof (gstr), "DATACACHE-%s", plugin_name); 96 GNUNET_snprintf (gstr, sizeof (gstr), "DATACACHE-%s", plugin_name);
102 GAUGER (gstr, 97 GAUGER (gstr, "Time to PUT item in datacache",
103 "Time to PUT item in datacache",
104 GNUNET_TIME_absolute_get_duration (start).rel_value / ITERATIONS, 98 GNUNET_TIME_absolute_get_duration (start).rel_value / ITERATIONS,
105 "ms/item"); 99 "ms/item");
106 start = GNUNET_TIME_absolute_get (); 100 start = GNUNET_TIME_absolute_get ();
@@ -117,12 +111,10 @@ run (void *cls,
117 fprintf (stdout, 111 fprintf (stdout,
118 "Found %u/%u items in %llums (%u were deleted during storage processing)\n", 112 "Found %u/%u items in %llums (%u were deleted during storage processing)\n",
119 found, ITERATIONS, 113 found, ITERATIONS,
120 (unsigned long long) 114 (unsigned long long) GNUNET_TIME_absolute_get_duration (start).
121 GNUNET_TIME_absolute_get_duration (start).rel_value, 115 rel_value, ITERATIONS - found);
122 ITERATIONS - found);
123 if (found > 0) 116 if (found > 0)
124 GAUGER (gstr, 117 GAUGER (gstr, "Time to GET item from datacache",
125 "Time to GET item from datacache",
126 GNUNET_TIME_absolute_get_duration (start).rel_value / found, 118 GNUNET_TIME_absolute_get_duration (start).rel_value / found,
127 "ms/item"); 119 "ms/item");
128 GNUNET_DATACACHE_destroy (h); 120 GNUNET_DATACACHE_destroy (h);
@@ -170,13 +162,12 @@ main (int argc, char *argv[])
170 else 162 else
171 pos = (char *) plugin_name; 163 pos = (char *) plugin_name;
172 164
173 GNUNET_snprintf (cfg_name, 165 GNUNET_snprintf (cfg_name, sizeof (cfg_name), "perf_datacache_data_%s.conf",
174 sizeof (cfg_name), 166 plugin_name);
175 "perf_datacache_data_%s.conf", plugin_name);
176 if (pos != plugin_name) 167 if (pos != plugin_name)
177 pos[0] = '.'; 168 pos[0] = '.';
178 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, 169 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv,
179 xargv, "perf-datacache", "nohelp", options, &run, NULL); 170 "perf-datacache", "nohelp", options, &run, NULL);
180 if (ok != 0) 171 if (ok != 0)
181 fprintf (stderr, "Missed some perfcases: %d\n", ok); 172 fprintf (stderr, "Missed some perfcases: %d\n", ok);
182 return ok; 173 return ok;
diff --git a/src/datacache/plugin_datacache_mysql.c b/src/datacache/plugin_datacache_mysql.c
index f4530ccef..62787eea6 100644
--- a/src/datacache/plugin_datacache_mysql.c
+++ b/src/datacache/plugin_datacache_mysql.c
@@ -222,8 +222,8 @@ get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg)
222#endif 222#endif
223 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 223 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
224 _("Trying to use file `%s' for MySQL configuration.\n"), cnffile); 224 _("Trying to use file `%s' for MySQL configuration.\n"), cnffile);
225 if ((0 != STAT (cnffile, &st)) || 225 if ((0 != STAT (cnffile, &st)) || (0 != ACCESS (cnffile, R_OK)) ||
226 (0 != ACCESS (cnffile, R_OK)) || (!S_ISREG (st.st_mode))) 226 (!S_ISREG (st.st_mode)))
227 { 227 {
228 if (configured == GNUNET_YES) 228 if (configured == GNUNET_YES)
229 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 229 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -303,9 +303,9 @@ iopen (struct Plugin *ret)
303 mysql_options (ret->dbf, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout); 303 mysql_options (ret->dbf, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout);
304 mysql_options (ret->dbf, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout); 304 mysql_options (ret->dbf, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout);
305 mysql_dbname = NULL; 305 mysql_dbname = NULL;
306 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg, 306 if (GNUNET_YES ==
307 "datacache-mysql", 307 GNUNET_CONFIGURATION_have_value (ret->env->cfg, "datacache-mysql",
308 "DATABASE")) 308 "DATABASE"))
309 GNUNET_assert (GNUNET_OK == 309 GNUNET_assert (GNUNET_OK ==
310 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg, 310 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg,
311 "datacache-mysql", 311 "datacache-mysql",
@@ -314,8 +314,9 @@ iopen (struct Plugin *ret)
314 else 314 else
315 mysql_dbname = GNUNET_strdup ("gnunet"); 315 mysql_dbname = GNUNET_strdup ("gnunet");
316 mysql_user = NULL; 316 mysql_user = NULL;
317 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg, 317 if (GNUNET_YES ==
318 "datacache-mysql", "USER")) 318 GNUNET_CONFIGURATION_have_value (ret->env->cfg, "datacache-mysql",
319 "USER"))
319 { 320 {
320 GNUNET_assert (GNUNET_OK == 321 GNUNET_assert (GNUNET_OK ==
321 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg, 322 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg,
@@ -323,9 +324,9 @@ iopen (struct Plugin *ret)
323 "USER", &mysql_user)); 324 "USER", &mysql_user));
324 } 325 }
325 mysql_password = NULL; 326 mysql_password = NULL;
326 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg, 327 if (GNUNET_YES ==
327 "datacache-mysql", 328 GNUNET_CONFIGURATION_have_value (ret->env->cfg, "datacache-mysql",
328 "PASSWORD")) 329 "PASSWORD"))
329 { 330 {
330 GNUNET_assert (GNUNET_OK == 331 GNUNET_assert (GNUNET_OK ==
331 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg, 332 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg,
@@ -334,8 +335,9 @@ iopen (struct Plugin *ret)
334 &mysql_password)); 335 &mysql_password));
335 } 336 }
336 mysql_server = NULL; 337 mysql_server = NULL;
337 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg, 338 if (GNUNET_YES ==
338 "datacache-mysql", "HOST")) 339 GNUNET_CONFIGURATION_have_value (ret->env->cfg, "datacache-mysql",
340 "HOST"))
339 { 341 {
340 GNUNET_assert (GNUNET_OK == 342 GNUNET_assert (GNUNET_OK ==
341 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg, 343 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg,
@@ -344,8 +346,9 @@ iopen (struct Plugin *ret)
344 &mysql_server)); 346 &mysql_server));
345 } 347 }
346 mysql_port = 0; 348 mysql_port = 0;
347 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg, 349 if (GNUNET_YES ==
348 "datacache-mysql", "PORT")) 350 GNUNET_CONFIGURATION_have_value (ret->env->cfg, "datacache-mysql",
351 "PORT"))
349 { 352 {
350 GNUNET_assert (GNUNET_OK == 353 GNUNET_assert (GNUNET_OK ==
351 GNUNET_CONFIGURATION_get_value_number (ret->env->cfg, 354 GNUNET_CONFIGURATION_get_value_number (ret->env->cfg,
@@ -450,8 +453,8 @@ prepare_statement (struct Plugin *plugin,
450 * @return GNUNET_SYSERR on error, GNUNET_OK on success 453 * @return GNUNET_SYSERR on error, GNUNET_OK on success
451 */ 454 */
452static int 455static int
453init_params (struct Plugin *plugin, 456init_params (struct Plugin *plugin, struct GNUNET_MysqlStatementHandle *s,
454 struct GNUNET_MysqlStatementHandle *s, va_list ap) 457 va_list ap)
455{ 458{
456 MYSQL_BIND qbind[MAX_PARAM]; 459 MYSQL_BIND qbind[MAX_PARAM];
457 unsigned int pc; 460 unsigned int pc;
@@ -512,8 +515,8 @@ init_params (struct Plugin *plugin,
512 { 515 {
513 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 516 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
514 _("`%s' failed at %s:%d with error: %s\n"), 517 _("`%s' failed at %s:%d with error: %s\n"),
515 "mysql_stmt_bind_param", 518 "mysql_stmt_bind_param", __FILE__, __LINE__,
516 __FILE__, __LINE__, mysql_stmt_error (s->statement)); 519 mysql_stmt_error (s->statement));
517 iclose (plugin); 520 iclose (plugin);
518 return GNUNET_SYSERR; 521 return GNUNET_SYSERR;
519 } 522 }
@@ -521,8 +524,8 @@ init_params (struct Plugin *plugin,
521 { 524 {
522 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 525 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
523 _("`%s' failed at %s:%d with error: %s\n"), 526 _("`%s' failed at %s:%d with error: %s\n"),
524 "mysql_stmt_execute", 527 "mysql_stmt_execute", __FILE__, __LINE__,
525 __FILE__, __LINE__, mysql_stmt_error (s->statement)); 528 mysql_stmt_error (s->statement));
526 iclose (plugin); 529 iclose (plugin);
527 return GNUNET_SYSERR; 530 return GNUNET_SYSERR;
528 } 531 }
@@ -538,8 +541,7 @@ init_params (struct Plugin *plugin,
538 * @param values values returned by MySQL 541 * @param values values returned by MySQL
539 * @return GNUNET_OK to continue iterating, GNUNET_SYSERR to abort 542 * @return GNUNET_OK to continue iterating, GNUNET_SYSERR to abort
540 */ 543 */
541typedef int (*GNUNET_MysqlDataProcessor) (void *cls, 544typedef int (*GNUNET_MysqlDataProcessor) (void *cls, unsigned int num_values,
542 unsigned int num_values,
543 MYSQL_BIND * values); 545 MYSQL_BIND * values);
544 546
545 547
@@ -561,12 +563,10 @@ typedef int (*GNUNET_MysqlDataProcessor) (void *cls,
561 */ 563 */
562static int 564static int
563prepared_statement_run_select (struct Plugin *plugin, 565prepared_statement_run_select (struct Plugin *plugin,
564 struct GNUNET_MysqlStatementHandle 566 struct GNUNET_MysqlStatementHandle *s,
565 *s, 567 unsigned int result_size, MYSQL_BIND * results,
566 unsigned int result_size, 568 GNUNET_MysqlDataProcessor processor,
567 MYSQL_BIND * results, 569 void *processor_cls, ...)
568 GNUNET_MysqlDataProcessor
569 processor, void *processor_cls, ...)
570{ 570{
571 va_list ap; 571 va_list ap;
572 int ret; 572 int ret;
@@ -596,8 +596,8 @@ prepared_statement_run_select (struct Plugin *plugin,
596 { 596 {
597 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 597 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
598 _("`%s' failed at %s:%d with error: %s\n"), 598 _("`%s' failed at %s:%d with error: %s\n"),
599 "mysql_stmt_bind_result", 599 "mysql_stmt_bind_result", __FILE__, __LINE__,
600 __FILE__, __LINE__, mysql_stmt_error (s->statement)); 600 mysql_stmt_error (s->statement));
601 iclose (plugin); 601 iclose (plugin);
602 return GNUNET_SYSERR; 602 return GNUNET_SYSERR;
603 } 603 }
@@ -612,8 +612,8 @@ prepared_statement_run_select (struct Plugin *plugin,
612 { 612 {
613 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 613 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
614 _("`%s' failed at %s:%d with error: %s\n"), 614 _("`%s' failed at %s:%d with error: %s\n"),
615 "mysql_stmt_fetch", 615 "mysql_stmt_fetch", __FILE__, __LINE__,
616 __FILE__, __LINE__, mysql_stmt_error (s->statement)); 616 mysql_stmt_error (s->statement));
617 iclose (plugin); 617 iclose (plugin);
618 return GNUNET_SYSERR; 618 return GNUNET_SYSERR;
619 } 619 }
@@ -676,17 +676,17 @@ static int
676itable (struct Plugin *plugin) 676itable (struct Plugin *plugin)
677{ 677{
678#define MRUNS(a) (GNUNET_OK != run_statement (plugin, a) ) 678#define MRUNS(a) (GNUNET_OK != run_statement (plugin, a) )
679 if (MRUNS ("CREATE TEMPORARY TABLE gn080dstore (" 679 if (MRUNS
680 " type INT(11) UNSIGNED NOT NULL DEFAULT 0," 680 ("CREATE TEMPORARY TABLE gn080dstore ("
681 " puttime BIGINT UNSIGNED NOT NULL DEFAULT 0," 681 " type INT(11) UNSIGNED NOT NULL DEFAULT 0,"
682 " expire BIGINT UNSIGNED NOT NULL DEFAULT 0," 682 " puttime BIGINT UNSIGNED NOT NULL DEFAULT 0,"
683 " hash BINARY(64) NOT NULL DEFAULT ''," 683 " expire BIGINT UNSIGNED NOT NULL DEFAULT 0,"
684 " vhash BINARY(64) NOT NULL DEFAULT ''," 684 " hash BINARY(64) NOT NULL DEFAULT '',"
685 " value BLOB NOT NULL DEFAULT ''," 685 " vhash BINARY(64) NOT NULL DEFAULT '',"
686 " INDEX hashidx (hash(64),type,expire)," 686 " value BLOB NOT NULL DEFAULT '',"
687 " INDEX allidx (hash(64),vhash(64),type)," 687 " INDEX hashidx (hash(64),type,expire),"
688 " INDEX expireidx (puttime)" ") ENGINE=InnoDB") || 688 " INDEX allidx (hash(64),vhash(64),type)," " INDEX expireidx (puttime)"
689 MRUNS ("SET AUTOCOMMIT = 1")) 689 ") ENGINE=InnoDB") || MRUNS ("SET AUTOCOMMIT = 1"))
690 return GNUNET_SYSERR; 690 return GNUNET_SYSERR;
691#undef MRUNS 691#undef MRUNS
692#define PINIT(a,b) (NULL == (a = prepared_statement_create(plugin, b))) 692#define PINIT(a,b) (NULL == (a = prepared_statement_create(plugin, b)))
@@ -714,11 +714,8 @@ itable (struct Plugin *plugin)
714 * @return 0 on error, number of bytes used otherwise 714 * @return 0 on error, number of bytes used otherwise
715 */ 715 */
716static size_t 716static size_t
717mysql_plugin_put (void *cls, 717mysql_plugin_put (void *cls, const GNUNET_HashCode * key, size_t size,
718 const GNUNET_HashCode * key, 718 const char *data, enum GNUNET_BLOCK_Type type,
719 size_t size,
720 const char *data,
721 enum GNUNET_BLOCK_Type type,
722 struct GNUNET_TIME_Absolute discard_time) 719 struct GNUNET_TIME_Absolute discard_time)
723{ 720{
724 struct Plugin *plugin = cls; 721 struct Plugin *plugin = cls;
@@ -745,23 +742,12 @@ mysql_plugin_put (void *cls,
745 v_now = (unsigned long long) now.abs_value; 742 v_now = (unsigned long long) now.abs_value;
746 v_discard_time = (unsigned long long) discard_time.abs_value; 743 v_discard_time = (unsigned long long) discard_time.abs_value;
747 if (GNUNET_OK == 744 if (GNUNET_OK ==
748 prepared_statement_run (plugin, 745 prepared_statement_run (plugin, plugin->update_value, NULL,
749 plugin->update_value, 746 MYSQL_TYPE_LONGLONG, &v_now, GNUNET_YES,
750 NULL, 747 MYSQL_TYPE_LONGLONG, &v_discard_time, GNUNET_YES,
751 MYSQL_TYPE_LONGLONG, 748 MYSQL_TYPE_BLOB, key, sizeof (GNUNET_HashCode),
752 &v_now, 749 &k_length, MYSQL_TYPE_BLOB, &vhash,
753 GNUNET_YES, 750 sizeof (GNUNET_HashCode), &h_length,
754 MYSQL_TYPE_LONGLONG,
755 &v_discard_time,
756 GNUNET_YES,
757 MYSQL_TYPE_BLOB,
758 key,
759 sizeof (GNUNET_HashCode),
760 &k_length,
761 MYSQL_TYPE_BLOB,
762 &vhash,
763 sizeof (GNUNET_HashCode),
764 &h_length,
765 MYSQL_TYPE_LONG, &v_type, GNUNET_YES, -1)) 751 MYSQL_TYPE_LONG, &v_type, GNUNET_YES, -1))
766 return GNUNET_OK; 752 return GNUNET_OK;
767 753
@@ -770,29 +756,16 @@ mysql_plugin_put (void *cls,
770 k_length = sizeof (GNUNET_HashCode); 756 k_length = sizeof (GNUNET_HashCode);
771 v_length = size; 757 v_length = size;
772 if (GNUNET_OK != 758 if (GNUNET_OK !=
773 (ret = prepared_statement_run (plugin, 759 (ret =
774 plugin->insert_value, 760 prepared_statement_run (plugin, plugin->insert_value, NULL,
775 NULL, 761 MYSQL_TYPE_LONG, &type, GNUNET_YES,
776 MYSQL_TYPE_LONG, 762 MYSQL_TYPE_LONGLONG, &v_now, GNUNET_YES,
777 &type, 763 MYSQL_TYPE_LONGLONG, &v_discard_time, GNUNET_YES,
778 GNUNET_YES, 764 MYSQL_TYPE_BLOB, key, sizeof (GNUNET_HashCode),
779 MYSQL_TYPE_LONGLONG, 765 &k_length, MYSQL_TYPE_BLOB, &vhash,
780 &v_now, 766 sizeof (GNUNET_HashCode), &h_length,
781 GNUNET_YES, 767 MYSQL_TYPE_BLOB, data, (unsigned long) size,
782 MYSQL_TYPE_LONGLONG, 768 &v_length, -1)))
783 &v_discard_time,
784 GNUNET_YES,
785 MYSQL_TYPE_BLOB,
786 key,
787 sizeof (GNUNET_HashCode),
788 &k_length,
789 MYSQL_TYPE_BLOB,
790 &vhash,
791 sizeof (GNUNET_HashCode),
792 &h_length,
793 MYSQL_TYPE_BLOB,
794 data,
795 (unsigned long) size, &v_length, -1)))
796 { 769 {
797 if (ret == GNUNET_SYSERR) 770 if (ret == GNUNET_SYSERR)
798 itable (plugin); 771 itable (plugin);
@@ -821,10 +794,9 @@ return_ok (void *cls, unsigned int num_values, MYSQL_BIND * values)
821 * @return the number of results found 794 * @return the number of results found
822 */ 795 */
823static unsigned int 796static unsigned int
824mysql_plugin_get (void *cls, 797mysql_plugin_get (void *cls, const GNUNET_HashCode * key,
825 const GNUNET_HashCode * key, 798 enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter,
826 enum GNUNET_BLOCK_Type type, 799 void *iter_cls)
827 GNUNET_DATACACHE_Iterator iter, void *iter_cls)
828{ 800{
829 struct Plugin *plugin = cls; 801 struct Plugin *plugin = cls;
830 MYSQL_BIND rbind[3]; 802 MYSQL_BIND rbind[3];
@@ -852,22 +824,13 @@ mysql_plugin_get (void *cls,
852 v_type = type; 824 v_type = type;
853 v_now = (unsigned long long) now.abs_value; 825 v_now = (unsigned long long) now.abs_value;
854 if ((GNUNET_OK != 826 if ((GNUNET_OK !=
855 (ret = prepared_statement_run_select (plugin, 827 (ret =
856 plugin->count_value, 828 prepared_statement_run_select (plugin, plugin->count_value, 1, rbind,
857 1, 829 return_ok, NULL, MYSQL_TYPE_BLOB, key,
858 rbind, 830 sizeof (GNUNET_HashCode), &h_length,
859 return_ok, 831 MYSQL_TYPE_LONG, &v_type, GNUNET_YES,
860 NULL, 832 MYSQL_TYPE_LONGLONG, &v_now, GNUNET_YES,
861 MYSQL_TYPE_BLOB, 833 -1))) || (-1 == total))
862 key,
863 sizeof
864 (GNUNET_HashCode),
865 &h_length,
866 MYSQL_TYPE_LONG,
867 &v_type, GNUNET_YES,
868 MYSQL_TYPE_LONGLONG,
869 &v_now, GNUNET_YES,
870 -1))) || (-1 == total))
871 { 834 {
872 if (ret == GNUNET_SYSERR) 835 if (ret == GNUNET_SYSERR)
873 itable (plugin); 836 itable (plugin);
@@ -890,25 +853,13 @@ mysql_plugin_get (void *cls,
890 rbind[1].buffer = &v_expire; 853 rbind[1].buffer = &v_expire;
891 off = (off + 1) % total; 854 off = (off + 1) % total;
892 if (GNUNET_OK != 855 if (GNUNET_OK !=
893 (ret = prepared_statement_run_select (plugin, 856 (ret =
894 plugin->select_value, 857 prepared_statement_run_select (plugin, plugin->select_value, 2, rbind,
895 2, 858 return_ok, NULL, MYSQL_TYPE_BLOB, key,
896 rbind, 859 sizeof (GNUNET_HashCode), &h_length,
897 return_ok, 860 MYSQL_TYPE_LONG, &v_type, GNUNET_YES,
898 NULL, 861 MYSQL_TYPE_LONGLONG, &v_now, GNUNET_YES,
899 MYSQL_TYPE_BLOB, 862 MYSQL_TYPE_LONG, &off, GNUNET_YES, -1)))
900 key,
901 sizeof
902 (GNUNET_HashCode),
903 &h_length,
904 MYSQL_TYPE_LONG,
905 &v_type,
906 GNUNET_YES,
907 MYSQL_TYPE_LONGLONG,
908 &v_now,
909 GNUNET_YES,
910 MYSQL_TYPE_LONG,
911 &off, GNUNET_YES, -1)))
912 { 863 {
913 if (ret == GNUNET_SYSERR) 864 if (ret == GNUNET_SYSERR)
914 itable (plugin); 865 itable (plugin);
@@ -965,32 +916,20 @@ mysql_plugin_del (void *cls)
965 rbind[3].length = &v_length; 916 rbind[3].length = &v_length;
966 rbind[3].buffer = buffer; 917 rbind[3].buffer = buffer;
967 if ((GNUNET_OK != 918 if ((GNUNET_OK !=
968 (ret = prepared_statement_run_select (plugin, 919 (ret =
969 plugin->select_old_value, 920 prepared_statement_run_select (plugin, plugin->select_old_value, 4,
970 4, 921 rbind, return_ok, NULL, -1))) ||
971 rbind,
972 return_ok,
973 NULL,
974 -1))) ||
975 (GNUNET_OK != 922 (GNUNET_OK !=
976 (ret = prepared_statement_run (plugin, 923 (ret =
977 plugin->delete_value, 924 prepared_statement_run (plugin, plugin->delete_value, NULL,
978 NULL, 925 MYSQL_TYPE_BLOB, &v_key,
979 MYSQL_TYPE_BLOB, 926 sizeof (GNUNET_HashCode), &k_length,
980 &v_key, 927 MYSQL_TYPE_BLOB, &vhash,
981 sizeof (GNUNET_HashCode), 928 sizeof (GNUNET_HashCode), &h_length,
982 &k_length, 929 MYSQL_TYPE_LONG, &v_type, GNUNET_YES,
983 MYSQL_TYPE_BLOB, 930 MYSQL_TYPE_BLOB, buffer,
984 &vhash, 931 (unsigned long) sizeof (buffer), &v_length,
985 sizeof (GNUNET_HashCode), 932 -1))))
986 &h_length,
987 MYSQL_TYPE_LONG,
988 &v_type,
989 GNUNET_YES,
990 MYSQL_TYPE_BLOB,
991 buffer,
992 (unsigned long)
993 sizeof (buffer), &v_length, -1))))
994 { 933 {
995 if (ret == GNUNET_SYSERR) 934 if (ret == GNUNET_SYSERR)
996 itable (plugin); 935 itable (plugin);
@@ -1036,8 +975,8 @@ libgnunet_plugin_datacache_mysql_init (void *cls)
1036 api->get = &mysql_plugin_get; 975 api->get = &mysql_plugin_get;
1037 api->put = &mysql_plugin_put; 976 api->put = &mysql_plugin_put;
1038 api->del = &mysql_plugin_del; 977 api->del = &mysql_plugin_del;
1039 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, 978 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "mysql",
1040 "mysql", _("MySQL datacache running\n")); 979 _("MySQL datacache running\n"));
1041 return api; 980 return api;
1042} 981}
1043 982
diff --git a/src/datacache/plugin_datacache_postgres.c b/src/datacache/plugin_datacache_postgres.c
index fdc377b8f..c5730078a 100644
--- a/src/datacache/plugin_datacache_postgres.c
+++ b/src/datacache/plugin_datacache_postgres.c
@@ -61,9 +61,7 @@ struct Plugin
61 * @return GNUNET_OK if the result is acceptable 61 * @return GNUNET_OK if the result is acceptable
62 */ 62 */
63static int 63static int
64check_result (struct Plugin *plugin, 64check_result (struct Plugin *plugin, PGresult * ret, int expected_status,
65 PGresult * ret,
66 int expected_status,
67 const char *command, const char *args, int line) 65 const char *command, const char *args, int line)
68{ 66{
69 if (ret == NULL) 67 if (ret == NULL)
@@ -78,9 +76,8 @@ check_result (struct Plugin *plugin,
78 { 76 {
79 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 77 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
80 "datastore-postgres", 78 "datastore-postgres",
81 _("`%s:%s' failed at %s:%d with error: %s"), 79 _("`%s:%s' failed at %s:%d with error: %s"), command, args,
82 command, args, __FILE__, line, 80 __FILE__, line, PQerrorMessage (plugin->dbh));
83 PQerrorMessage (plugin->dbh));
84 PQclear (ret); 81 PQclear (ret);
85 return GNUNET_SYSERR; 82 return GNUNET_SYSERR;
86 } 83 }
@@ -97,8 +94,8 @@ pq_exec (struct Plugin *plugin, const char *sql, int line)
97 PGresult *ret; 94 PGresult *ret;
98 95
99 ret = PQexec (plugin->dbh, sql); 96 ret = PQexec (plugin->dbh, sql);
100 if (GNUNET_OK != check_result (plugin, 97 if (GNUNET_OK !=
101 ret, PGRES_COMMAND_OK, "PQexec", sql, line)) 98 check_result (plugin, ret, PGRES_COMMAND_OK, "PQexec", sql, line))
102 return GNUNET_SYSERR; 99 return GNUNET_SYSERR;
103 PQclear (ret); 100 PQclear (ret);
104 return GNUNET_OK; 101 return GNUNET_OK;
@@ -109,8 +106,8 @@ pq_exec (struct Plugin *plugin, const char *sql, int line)
109 * Prepare SQL statement. 106 * Prepare SQL statement.
110 */ 107 */
111static int 108static int
112pq_prepare (struct Plugin *plugin, 109pq_prepare (struct Plugin *plugin, const char *name, const char *sql,
113 const char *name, const char *sql, int nparms, int line) 110 int nparms, int line)
114{ 111{
115 PGresult *ret; 112 PGresult *ret;
116 113
@@ -136,8 +133,8 @@ init_connection (struct Plugin *plugin)
136 /* Open database and precompile statements */ 133 /* Open database and precompile statements */
137 if (GNUNET_OK != 134 if (GNUNET_OK !=
138 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, 135 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
139 "datacache-postgres", 136 "datacache-postgres", "CONFIG",
140 "CONFIG", &conninfo)) 137 &conninfo))
141 conninfo = NULL; 138 conninfo = NULL;
142 plugin->dbh = PQconnectdb (conninfo == NULL ? "" : conninfo); 139 plugin->dbh = PQconnectdb (conninfo == NULL ? "" : conninfo);
143 GNUNET_free_non_null (conninfo); 140 GNUNET_free_non_null (conninfo);
@@ -148,28 +145,27 @@ init_connection (struct Plugin *plugin)
148 } 145 }
149 if (PQstatus (plugin->dbh) != CONNECTION_OK) 146 if (PQstatus (plugin->dbh) != CONNECTION_OK)
150 { 147 {
151 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 148 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "datacache-postgres",
152 "datacache-postgres",
153 _("Unable to initialize Postgres: %s"), 149 _("Unable to initialize Postgres: %s"),
154 PQerrorMessage (plugin->dbh)); 150 PQerrorMessage (plugin->dbh));
155 PQfinish (plugin->dbh); 151 PQfinish (plugin->dbh);
156 plugin->dbh = NULL; 152 plugin->dbh = NULL;
157 return GNUNET_SYSERR; 153 return GNUNET_SYSERR;
158 } 154 }
159 ret = PQexec (plugin->dbh, 155 ret =
160 "CREATE TEMPORARY TABLE gn090dc (" 156 PQexec (plugin->dbh,
161 " type INTEGER NOT NULL DEFAULT 0," 157 "CREATE TEMPORARY TABLE gn090dc ("
162 " discard_time BIGINT NOT NULL DEFAULT 0," 158 " type INTEGER NOT NULL DEFAULT 0,"
163 " key BYTEA NOT NULL DEFAULT ''," 159 " discard_time BIGINT NOT NULL DEFAULT 0,"
164 " value BYTEA NOT NULL DEFAULT '')" "WITH OIDS"); 160 " key BYTEA NOT NULL DEFAULT '',"
161 " value BYTEA NOT NULL DEFAULT '')" "WITH OIDS");
165 if ((ret == NULL) || ((PQresultStatus (ret) != PGRES_COMMAND_OK) && (0 != strcmp ("42P07", /* duplicate table */ 162 if ((ret == NULL) || ((PQresultStatus (ret) != PGRES_COMMAND_OK) && (0 != strcmp ("42P07", /* duplicate table */
166 PQresultErrorField 163 PQresultErrorField
167 (ret, 164 (ret,
168 PG_DIAG_SQLSTATE))))) 165 PG_DIAG_SQLSTATE)))))
169 { 166 {
170 (void) check_result (plugin, 167 (void) check_result (plugin, ret, PGRES_COMMAND_OK, "CREATE TABLE",
171 ret, PGRES_COMMAND_OK, "CREATE TABLE", "gn090dc", 168 "gn090dc", __LINE__);
172 __LINE__);
173 PQfinish (plugin->dbh); 169 PQfinish (plugin->dbh);
174 plugin->dbh = NULL; 170 plugin->dbh = NULL;
175 return GNUNET_SYSERR; 171 return GNUNET_SYSERR;
@@ -190,11 +186,12 @@ init_connection (struct Plugin *plugin)
190 } 186 }
191 PQclear (ret); 187 PQclear (ret);
192#if 1 188#if 1
193 ret = PQexec (plugin->dbh, 189 ret =
194 "ALTER TABLE gn090dc ALTER value SET STORAGE EXTERNAL"); 190 PQexec (plugin->dbh,
191 "ALTER TABLE gn090dc ALTER value SET STORAGE EXTERNAL");
195 if (GNUNET_OK != 192 if (GNUNET_OK !=
196 check_result (plugin, 193 check_result (plugin, ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090dc",
197 ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090dc", __LINE__)) 194 __LINE__))
198 { 195 {
199 PQfinish (plugin->dbh); 196 PQfinish (plugin->dbh);
200 plugin->dbh = NULL; 197 plugin->dbh = NULL;
@@ -203,8 +200,8 @@ init_connection (struct Plugin *plugin)
203 PQclear (ret); 200 PQclear (ret);
204 ret = PQexec (plugin->dbh, "ALTER TABLE gn090dc ALTER key SET STORAGE PLAIN"); 201 ret = PQexec (plugin->dbh, "ALTER TABLE gn090dc ALTER key SET STORAGE PLAIN");
205 if (GNUNET_OK != 202 if (GNUNET_OK !=
206 check_result (plugin, 203 check_result (plugin, ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090dc",
207 ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090dc", __LINE__)) 204 __LINE__))
208 { 205 {
209 PQfinish (plugin->dbh); 206 PQfinish (plugin->dbh);
210 plugin->dbh = NULL; 207 plugin->dbh = NULL;
@@ -213,35 +210,22 @@ init_connection (struct Plugin *plugin)
213 PQclear (ret); 210 PQclear (ret);
214#endif 211#endif
215 if ((GNUNET_OK != 212 if ((GNUNET_OK !=
216 pq_prepare (plugin, 213 pq_prepare (plugin, "getkt",
217 "getkt",
218 "SELECT discard_time,type,value FROM gn090dc " 214 "SELECT discard_time,type,value FROM gn090dc "
219 "WHERE key=$1 AND type=$2 ", 215 "WHERE key=$1 AND type=$2 ", 2, __LINE__)) ||
220 2,
221 __LINE__)) ||
222 (GNUNET_OK != 216 (GNUNET_OK !=
223 pq_prepare (plugin, 217 pq_prepare (plugin, "getk",
224 "getk",
225 "SELECT discard_time,type,value FROM gn090dc " 218 "SELECT discard_time,type,value FROM gn090dc "
226 "WHERE key=$1", 219 "WHERE key=$1", 1, __LINE__)) ||
227 1,
228 __LINE__)) ||
229 (GNUNET_OK != 220 (GNUNET_OK !=
230 pq_prepare (plugin, 221 pq_prepare (plugin, "getm",
231 "getm",
232 "SELECT length(value),oid,key FROM gn090dc " 222 "SELECT length(value),oid,key FROM gn090dc "
233 "ORDER BY discard_time ASC LIMIT 1", 223 "ORDER BY discard_time ASC LIMIT 1", 0, __LINE__)) ||
234 0,
235 __LINE__)) ||
236 (GNUNET_OK != 224 (GNUNET_OK !=
237 pq_prepare (plugin, 225 pq_prepare (plugin, "delrow", "DELETE FROM gn090dc WHERE oid=$1", 1,
238 "delrow",
239 "DELETE FROM gn090dc WHERE oid=$1",
240 1,
241 __LINE__)) || 226 __LINE__)) ||
242 (GNUNET_OK != 227 (GNUNET_OK !=
243 pq_prepare (plugin, 228 pq_prepare (plugin, "put",
244 "put",
245 "INSERT INTO gn090dc (type, discard_time, key, value) " 229 "INSERT INTO gn090dc (type, discard_time, key, value) "
246 "VALUES ($1, $2, $3, $4)", 4, __LINE__))) 230 "VALUES ($1, $2, $3, $4)", 4, __LINE__)))
247 { 231 {
@@ -268,12 +252,11 @@ delete_by_rowid (struct Plugin *plugin, uint32_t rowid)
268 const int paramFormats[] = { 1 }; 252 const int paramFormats[] = { 1 };
269 PGresult *ret; 253 PGresult *ret;
270 254
271 ret = PQexecPrepared (plugin->dbh, 255 ret =
272 "delrow", 256 PQexecPrepared (plugin->dbh, "delrow", 1, paramValues, paramLengths,
273 1, paramValues, paramLengths, paramFormats, 1); 257 paramFormats, 1);
274 if (GNUNET_OK != 258 if (GNUNET_OK !=
275 check_result (plugin, 259 check_result (plugin, ret, PGRES_COMMAND_OK, "PQexecPrepared", "delrow",
276 ret, PGRES_COMMAND_OK, "PQexecPrepared", "delrow",
277 __LINE__)) 260 __LINE__))
278 { 261 {
279 return GNUNET_SYSERR; 262 return GNUNET_SYSERR;
@@ -295,11 +278,8 @@ delete_by_rowid (struct Plugin *plugin, uint32_t rowid)
295 * @return 0 on error, number of bytes used otherwise 278 * @return 0 on error, number of bytes used otherwise
296 */ 279 */
297static size_t 280static size_t
298postgres_plugin_put (void *cls, 281postgres_plugin_put (void *cls, const GNUNET_HashCode * key, size_t size,
299 const GNUNET_HashCode * key, 282 const char *data, enum GNUNET_BLOCK_Type type,
300 size_t size,
301 const char *data,
302 enum GNUNET_BLOCK_Type type,
303 struct GNUNET_TIME_Absolute discard_time) 283 struct GNUNET_TIME_Absolute discard_time)
304{ 284{
305 struct Plugin *plugin = cls; 285 struct Plugin *plugin = cls;
@@ -321,11 +301,12 @@ postgres_plugin_put (void *cls,
321 }; 301 };
322 const int paramFormats[] = { 1, 1, 1, 1 }; 302 const int paramFormats[] = { 1, 1, 1, 1 };
323 303
324 ret = PQexecPrepared (plugin->dbh, 304 ret =
325 "put", 4, paramValues, paramLengths, paramFormats, 1); 305 PQexecPrepared (plugin->dbh, "put", 4, paramValues, paramLengths,
326 if (GNUNET_OK != check_result (plugin, ret, 306 paramFormats, 1);
327 PGRES_COMMAND_OK, 307 if (GNUNET_OK !=
328 "PQexecPrepared", "put", __LINE__)) 308 check_result (plugin, ret, PGRES_COMMAND_OK, "PQexecPrepared", "put",
309 __LINE__))
329 return GNUNET_SYSERR; 310 return GNUNET_SYSERR;
330 PQclear (ret); 311 PQclear (ret);
331 return size + OVERHEAD; 312 return size + OVERHEAD;
@@ -344,8 +325,7 @@ postgres_plugin_put (void *cls,
344 * @return the number of results found 325 * @return the number of results found
345 */ 326 */
346static unsigned int 327static unsigned int
347postgres_plugin_get (void *cls, 328postgres_plugin_get (void *cls, const GNUNET_HashCode * key,
348 const GNUNET_HashCode * key,
349 enum GNUNET_BLOCK_Type type, 329 enum GNUNET_BLOCK_Type type,
350 GNUNET_DATACACHE_Iterator iter, void *iter_cls) 330 GNUNET_DATACACHE_Iterator iter, void *iter_cls)
351{ 331{
@@ -368,19 +348,16 @@ postgres_plugin_get (void *cls,
368 PGresult *res; 348 PGresult *res;
369 349
370 cnt = 0; 350 cnt = 0;
371 res = PQexecPrepared (plugin->dbh, 351 res =
372 (type == 0) ? "getk" : "getkt", 352 PQexecPrepared (plugin->dbh, (type == 0) ? "getk" : "getkt",
373 (type == 0) ? 1 : 2, 353 (type == 0) ? 1 : 2, paramValues, paramLengths,
374 paramValues, paramLengths, paramFormats, 1); 354 paramFormats, 1);
375 if (GNUNET_OK != check_result (plugin, 355 if (GNUNET_OK !=
376 res, 356 check_result (plugin, res, PGRES_TUPLES_OK, "PQexecPrepared",
377 PGRES_TUPLES_OK, 357 (type == 0) ? "getk" : "getkt", __LINE__))
378 "PQexecPrepared",
379 (type == 0) ? "getk" : "getkt", __LINE__))
380 { 358 {
381#if DEBUG_POSTGRES 359#if DEBUG_POSTGRES
382 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 360 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datacache-postgres",
383 "datacache-postgres",
384 "Ending iteration (postgres error)\n"); 361 "Ending iteration (postgres error)\n");
385#endif 362#endif
386 return 0; 363 return 0;
@@ -390,8 +367,7 @@ postgres_plugin_get (void *cls,
390 { 367 {
391 /* no result */ 368 /* no result */
392#if DEBUG_POSTGRES 369#if DEBUG_POSTGRES
393 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 370 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datacache-postgres",
394 "datacache-postgres",
395 "Ending iteration (no more results)\n"); 371 "Ending iteration (no more results)\n");
396#endif 372#endif
397 PQclear (res); 373 PQclear (res);
@@ -402,8 +378,7 @@ postgres_plugin_get (void *cls,
402 PQclear (res); 378 PQclear (res);
403 return cnt; 379 return cnt;
404 } 380 }
405 if ((3 != PQnfields (res)) || 381 if ((3 != PQnfields (res)) || (sizeof (uint64_t) != PQfsize (res, 0)) ||
406 (sizeof (uint64_t) != PQfsize (res, 0)) ||
407 (sizeof (uint32_t) != PQfsize (res, 1))) 382 (sizeof (uint32_t) != PQfsize (res, 1)))
408 { 383 {
409 GNUNET_break (0); 384 GNUNET_break (0);
@@ -417,19 +392,16 @@ postgres_plugin_get (void *cls,
417 type = ntohl (*(uint32_t *) PQgetvalue (res, i, 1)); 392 type = ntohl (*(uint32_t *) PQgetvalue (res, i, 1));
418 size = PQgetlength (res, i, 2); 393 size = PQgetlength (res, i, 2);
419#if DEBUG_POSTGRES 394#if DEBUG_POSTGRES
420 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 395 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datacache-postgres",
421 "datacache-postgres",
422 "Found result of size %u bytes and type %u in database\n", 396 "Found result of size %u bytes and type %u in database\n",
423 (unsigned int) size, (unsigned int) type); 397 (unsigned int) size, (unsigned int) type);
424#endif 398#endif
425 if (GNUNET_SYSERR == 399 if (GNUNET_SYSERR ==
426 iter (iter_cls, 400 iter (iter_cls, expiration_time, key, size, PQgetvalue (res, i, 2),
427 expiration_time, 401 (enum GNUNET_BLOCK_Type) type))
428 key, size, PQgetvalue (res, i, 2), (enum GNUNET_BLOCK_Type) type))
429 { 402 {
430#if DEBUG_POSTGRES 403#if DEBUG_POSTGRES
431 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 404 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datacache-postgres",
432 "datacache-postgres",
433 "Ending iteration (client error)\n"); 405 "Ending iteration (client error)\n");
434#endif 406#endif
435 PQclear (res); 407 PQclear (res);
@@ -458,14 +430,12 @@ postgres_plugin_del (void *cls)
458 PGresult *res; 430 PGresult *res;
459 431
460 res = PQexecPrepared (plugin->dbh, "getm", 0, NULL, NULL, NULL, 1); 432 res = PQexecPrepared (plugin->dbh, "getm", 0, NULL, NULL, NULL, 1);
461 if (GNUNET_OK != check_result (plugin, 433 if (GNUNET_OK !=
462 res, 434 check_result (plugin, res, PGRES_TUPLES_OK, "PQexecPrepared", "getm",
463 PGRES_TUPLES_OK, 435 __LINE__))
464 "PQexecPrepared", "getm", __LINE__))
465 { 436 {
466#if DEBUG_POSTGRES 437#if DEBUG_POSTGRES
467 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 438 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datacache-postgres",
468 "datacache-postgres",
469 "Ending iteration (postgres error)\n"); 439 "Ending iteration (postgres error)\n");
470#endif 440#endif
471 return 0; 441 return 0;
@@ -474,15 +444,13 @@ postgres_plugin_del (void *cls)
474 { 444 {
475 /* no result */ 445 /* no result */
476#if DEBUG_POSTGRES 446#if DEBUG_POSTGRES
477 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 447 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datacache-postgres",
478 "datacache-postgres",
479 "Ending iteration (no more results)\n"); 448 "Ending iteration (no more results)\n");
480#endif 449#endif
481 PQclear (res); 450 PQclear (res);
482 return GNUNET_SYSERR; 451 return GNUNET_SYSERR;
483 } 452 }
484 if ((3 != PQnfields (res)) || 453 if ((3 != PQnfields (res)) || (sizeof (size) != PQfsize (res, 0)) ||
485 (sizeof (size) != PQfsize (res, 0)) ||
486 (sizeof (oid) != PQfsize (res, 1)) || 454 (sizeof (oid) != PQfsize (res, 1)) ||
487 (sizeof (GNUNET_HashCode) != PQgetlength (res, 0, 2))) 455 (sizeof (GNUNET_HashCode) != PQgetlength (res, 0, 2)))
488 { 456 {
@@ -528,8 +496,8 @@ libgnunet_plugin_datacache_postgres_init (void *cls)
528 api->get = &postgres_plugin_get; 496 api->get = &postgres_plugin_get;
529 api->put = &postgres_plugin_put; 497 api->put = &postgres_plugin_put;
530 api->del = &postgres_plugin_del; 498 api->del = &postgres_plugin_del;
531 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, 499 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "datacache-postgres",
532 "datacache-postgres", _("Postgres datacache running\n")); 500 _("Postgres datacache running\n"));
533 return api; 501 return api;
534} 502}
535 503
diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c
index 5f534227f..3d67ffc22 100644
--- a/src/datacache/plugin_datacache_sqlite.c
+++ b/src/datacache/plugin_datacache_sqlite.c
@@ -78,8 +78,8 @@ sq_prepare (sqlite3 * dbh, const char *zSql, /* SQL statement, UTF-8 encoded
78{ /* OUT: Statement handle */ 78{ /* OUT: Statement handle */
79 char *dummy; 79 char *dummy;
80 80
81 return sqlite3_prepare (dbh, 81 return sqlite3_prepare (dbh, zSql, strlen (zSql), ppStmt,
82 zSql, strlen (zSql), ppStmt, (const char **) &dummy); 82 (const char **) &dummy);
83} 83}
84 84
85 85
@@ -95,11 +95,8 @@ sq_prepare (sqlite3 * dbh, const char *zSql, /* SQL statement, UTF-8 encoded
95 * @return 0 on error, number of bytes used otherwise 95 * @return 0 on error, number of bytes used otherwise
96 */ 96 */
97static size_t 97static size_t
98sqlite_plugin_put (void *cls, 98sqlite_plugin_put (void *cls, const GNUNET_HashCode * key, size_t size,
99 const GNUNET_HashCode * key, 99 const char *data, enum GNUNET_BLOCK_Type type,
100 size_t size,
101 const char *data,
102 enum GNUNET_BLOCK_Type type,
103 struct GNUNET_TIME_Absolute discard_time) 100 struct GNUNET_TIME_Absolute discard_time)
104{ 101{
105 struct Plugin *plugin = cls; 102 struct Plugin *plugin = cls;
@@ -109,48 +106,44 @@ sqlite_plugin_put (void *cls,
109#if DEBUG_DATACACHE_SQLITE 106#if DEBUG_DATACACHE_SQLITE
110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
111 "Processing `%s' of %u bytes with key `%4s' and expiration %llums\n", 108 "Processing `%s' of %u bytes with key `%4s' and expiration %llums\n",
112 "PUT", 109 "PUT", (unsigned int) size, GNUNET_h2s (key),
113 (unsigned int) size,
114 GNUNET_h2s (key),
115 (unsigned long long) 110 (unsigned long long)
116 GNUNET_TIME_absolute_get_remaining (discard_time).rel_value); 111 GNUNET_TIME_absolute_get_remaining (discard_time).rel_value);
117#endif 112#endif
118 dval = (int64_t) discard_time.abs_value; 113 dval = (int64_t) discard_time.abs_value;
119 if (dval < 0) 114 if (dval < 0)
120 dval = INT64_MAX; 115 dval = INT64_MAX;
121 if (sq_prepare (plugin->dbh, 116 if (sq_prepare
122 "INSERT INTO ds090 " 117 (plugin->dbh,
123 "(type, expire, key, value) " 118 "INSERT INTO ds090 " "(type, expire, key, value) " "VALUES (?, ?, ?, ?)",
124 "VALUES (?, ?, ?, ?)", &stmt) != SQLITE_OK) 119 &stmt) != SQLITE_OK)
125 { 120 {
126 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 121 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
127 _("`%s' failed at %s:%d with error: %s\n"), 122 _("`%s' failed at %s:%d with error: %s\n"), "sq_prepare",
128 "sq_prepare", __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); 123 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh));
129 return 0; 124 return 0;
130 } 125 }
131 if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) || 126 if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) ||
132 (SQLITE_OK != sqlite3_bind_int64 (stmt, 2, dval)) || 127 (SQLITE_OK != sqlite3_bind_int64 (stmt, 2, dval)) ||
133 (SQLITE_OK != sqlite3_bind_blob (stmt, 3, key, sizeof (GNUNET_HashCode), 128 (SQLITE_OK !=
134 SQLITE_TRANSIENT)) || 129 sqlite3_bind_blob (stmt, 3, key, sizeof (GNUNET_HashCode),
130 SQLITE_TRANSIENT)) ||
135 (SQLITE_OK != sqlite3_bind_blob (stmt, 4, data, size, SQLITE_TRANSIENT))) 131 (SQLITE_OK != sqlite3_bind_blob (stmt, 4, data, size, SQLITE_TRANSIENT)))
136 { 132 {
137 LOG_SQLITE (plugin->dbh, 133 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
138 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
139 "sqlite3_bind_xxx"); 134 "sqlite3_bind_xxx");
140 sqlite3_finalize (stmt); 135 sqlite3_finalize (stmt);
141 return 0; 136 return 0;
142 } 137 }
143 if (SQLITE_DONE != sqlite3_step (stmt)) 138 if (SQLITE_DONE != sqlite3_step (stmt))
144 { 139 {
145 LOG_SQLITE (plugin->dbh, 140 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
146 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
147 "sqlite3_step"); 141 "sqlite3_step");
148 sqlite3_finalize (stmt); 142 sqlite3_finalize (stmt);
149 return 0; 143 return 0;
150 } 144 }
151 if (SQLITE_OK != sqlite3_finalize (stmt)) 145 if (SQLITE_OK != sqlite3_finalize (stmt))
152 LOG_SQLITE (plugin->dbh, 146 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
153 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
154 "sqlite3_finalize"); 147 "sqlite3_finalize");
155 return size + OVERHEAD; 148 return size + OVERHEAD;
156} 149}
@@ -168,10 +161,9 @@ sqlite_plugin_put (void *cls,
168 * @return the number of results found 161 * @return the number of results found
169 */ 162 */
170static unsigned int 163static unsigned int
171sqlite_plugin_get (void *cls, 164sqlite_plugin_get (void *cls, const GNUNET_HashCode * key,
172 const GNUNET_HashCode * key, 165 enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter,
173 enum GNUNET_BLOCK_Type type, 166 void *iter_cls)
174 GNUNET_DATACACHE_Iterator iter, void *iter_cls)
175{ 167{
176 struct Plugin *plugin = cls; 168 struct Plugin *plugin = cls;
177 sqlite3_stmt *stmt; 169 sqlite3_stmt *stmt;
@@ -187,16 +179,17 @@ sqlite_plugin_get (void *cls,
187 179
188 now = GNUNET_TIME_absolute_get (); 180 now = GNUNET_TIME_absolute_get ();
189#if DEBUG_DATACACHE_SQLITE 181#if DEBUG_DATACACHE_SQLITE
190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 182 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s' for key `%4s'\n", "GET",
191 "Processing `%s' for key `%4s'\n", "GET", GNUNET_h2s (key)); 183 GNUNET_h2s (key));
192#endif 184#endif
193 if (sq_prepare (plugin->dbh, 185 if (sq_prepare
194 "SELECT count(*) FROM ds090 WHERE key=? AND type=? AND expire >= ?", 186 (plugin->dbh,
195 &stmt) != SQLITE_OK) 187 "SELECT count(*) FROM ds090 WHERE key=? AND type=? AND expire >= ?",
188 &stmt) != SQLITE_OK)
196 { 189 {
197 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 190 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
198 _("`%s' failed at %s:%d with error: %s\n"), 191 _("`%s' failed at %s:%d with error: %s\n"), "sq_prepare",
199 "sq_prepare", __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); 192 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh));
200 return 0; 193 return 0;
201 } 194 }
202 ntime = (int64_t) now.abs_value; 195 ntime = (int64_t) now.abs_value;
@@ -204,12 +197,10 @@ sqlite_plugin_get (void *cls,
204 if ((SQLITE_OK != 197 if ((SQLITE_OK !=
205 sqlite3_bind_blob (stmt, 1, key, sizeof (GNUNET_HashCode), 198 sqlite3_bind_blob (stmt, 1, key, sizeof (GNUNET_HashCode),
206 SQLITE_TRANSIENT)) || 199 SQLITE_TRANSIENT)) ||
207 (SQLITE_OK != 200 (SQLITE_OK != sqlite3_bind_int (stmt, 2, type)) ||
208 sqlite3_bind_int (stmt, 2, type)) ||
209 (SQLITE_OK != sqlite3_bind_int64 (stmt, 3, now.abs_value))) 201 (SQLITE_OK != sqlite3_bind_int64 (stmt, 3, now.abs_value)))
210 { 202 {
211 LOG_SQLITE (plugin->dbh, 203 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
212 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
213 "sqlite3_bind_xxx"); 204 "sqlite3_bind_xxx");
214 sqlite3_finalize (stmt); 205 sqlite3_finalize (stmt);
215 return 0; 206 return 0;
@@ -217,8 +208,7 @@ sqlite_plugin_get (void *cls,
217 208
218 if (SQLITE_ROW != sqlite3_step (stmt)) 209 if (SQLITE_ROW != sqlite3_step (stmt))
219 { 210 {
220 LOG_SQLITE (plugin->dbh, 211 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
221 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
222 "sqlite_step"); 212 "sqlite_step");
223 sqlite3_finalize (stmt); 213 sqlite3_finalize (stmt);
224 return 0; 214 return 0;
@@ -233,27 +223,23 @@ sqlite_plugin_get (void *cls,
233 while (cnt < total) 223 while (cnt < total)
234 { 224 {
235 off = (off + 1) % total; 225 off = (off + 1) % total;
236 GNUNET_snprintf (scratch, 226 GNUNET_snprintf (scratch, sizeof (scratch),
237 sizeof (scratch),
238 "SELECT value,expire FROM ds090 WHERE key=? AND type=? AND expire >= ? LIMIT 1 OFFSET %u", 227 "SELECT value,expire FROM ds090 WHERE key=? AND type=? AND expire >= ? LIMIT 1 OFFSET %u",
239 off); 228 off);
240 if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK) 229 if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK)
241 { 230 {
242 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 231 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
243 _("`%s' failed at %s:%d with error: %s\n"), 232 _("`%s' failed at %s:%d with error: %s\n"), "sq_prepare",
244 "sq_prepare", __FILE__, __LINE__, 233 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh));
245 sqlite3_errmsg (plugin->dbh));
246 return cnt; 234 return cnt;
247 } 235 }
248 if ((SQLITE_OK != 236 if ((SQLITE_OK !=
249 sqlite3_bind_blob (stmt, 1, key, sizeof (GNUNET_HashCode), 237 sqlite3_bind_blob (stmt, 1, key, sizeof (GNUNET_HashCode),
250 SQLITE_TRANSIENT)) || 238 SQLITE_TRANSIENT)) ||
251 (SQLITE_OK != 239 (SQLITE_OK != sqlite3_bind_int (stmt, 2, type)) ||
252 sqlite3_bind_int (stmt, 2, type)) ||
253 (SQLITE_OK != sqlite3_bind_int64 (stmt, 3, now.abs_value))) 240 (SQLITE_OK != sqlite3_bind_int64 (stmt, 3, now.abs_value)))
254 { 241 {
255 LOG_SQLITE (plugin->dbh, 242 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
256 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
257 "sqlite3_bind_xxx"); 243 "sqlite3_bind_xxx");
258 sqlite3_finalize (stmt); 244 sqlite3_finalize (stmt);
259 return cnt; 245 return cnt;
@@ -301,13 +287,14 @@ sqlite_plugin_del (void *cls)
301#endif 287#endif
302 stmt = NULL; 288 stmt = NULL;
303 dstmt = NULL; 289 dstmt = NULL;
304 if (sq_prepare (plugin->dbh, 290 if (sq_prepare
305 "SELECT type, key, value FROM ds090 ORDER BY expire ASC LIMIT 1", 291 (plugin->dbh,
306 &stmt) != SQLITE_OK) 292 "SELECT type, key, value FROM ds090 ORDER BY expire ASC LIMIT 1",
293 &stmt) != SQLITE_OK)
307 { 294 {
308 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 295 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
309 _("`%s' failed at %s:%d with error: %s\n"), 296 _("`%s' failed at %s:%d with error: %s\n"), "sq_prepare",
310 "sq_prepare", __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); 297 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh));
311 if (stmt != NULL) 298 if (stmt != NULL)
312 (void) sqlite3_finalize (stmt); 299 (void) sqlite3_finalize (stmt);
313 return GNUNET_SYSERR; 300 return GNUNET_SYSERR;
@@ -315,9 +302,8 @@ sqlite_plugin_del (void *cls)
315 if (SQLITE_ROW != sqlite3_step (stmt)) 302 if (SQLITE_ROW != sqlite3_step (stmt))
316 { 303 {
317 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 304 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
318 _("`%s' failed at %s:%d with error: %s\n"), 305 _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_step",
319 "sqlite3_step", __FILE__, __LINE__, 306 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh));
320 sqlite3_errmsg (plugin->dbh));
321 (void) sqlite3_finalize (stmt); 307 (void) sqlite3_finalize (stmt);
322 return GNUNET_SYSERR; 308 return GNUNET_SYSERR;
323 } 309 }
@@ -329,54 +315,44 @@ sqlite_plugin_del (void *cls)
329 memcpy (&hc, sqlite3_column_blob (stmt, 1), sizeof (GNUNET_HashCode)); 315 memcpy (&hc, sqlite3_column_blob (stmt, 1), sizeof (GNUNET_HashCode));
330 if (SQLITE_OK != sqlite3_finalize (stmt)) 316 if (SQLITE_OK != sqlite3_finalize (stmt))
331 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 317 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
332 _("`%s' failed at %s:%d with error: %s\n"), 318 _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_step",
333 "sqlite3_step", __FILE__, __LINE__, 319 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh));
334 sqlite3_errmsg (plugin->dbh)); 320 if (sq_prepare
335 if (sq_prepare (plugin->dbh, 321 (plugin->dbh, "DELETE FROM ds090 " "WHERE key=? AND value=? AND type=?",
336 "DELETE FROM ds090 " 322 &dstmt) != SQLITE_OK)
337 "WHERE key=? AND value=? AND type=?", &dstmt) != SQLITE_OK)
338 { 323 {
339 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 324 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
340 _("`%s' failed at %s:%d with error: %s\n"), 325 _("`%s' failed at %s:%d with error: %s\n"), "sq_prepare",
341 "sq_prepare", __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); 326 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh));
342 if (stmt != NULL) 327 if (stmt != NULL)
343 (void) sqlite3_finalize (stmt); 328 (void) sqlite3_finalize (stmt);
344 return GNUNET_SYSERR; 329 return GNUNET_SYSERR;
345 } 330 }
346 if ((SQLITE_OK != 331 if ((SQLITE_OK !=
347 sqlite3_bind_blob (dstmt, 332 sqlite3_bind_blob (dstmt, 1, &hc, sizeof (GNUNET_HashCode),
348 1, &hc,
349 sizeof (GNUNET_HashCode),
350 SQLITE_TRANSIENT)) ||
351 (SQLITE_OK !=
352 sqlite3_bind_blob (dstmt,
353 2, blob,
354 dsize,
355 SQLITE_TRANSIENT)) || 333 SQLITE_TRANSIENT)) ||
356 (SQLITE_OK != sqlite3_bind_int (dstmt, 3, dtype))) 334 (SQLITE_OK != sqlite3_bind_blob (dstmt, 2, blob, dsize, SQLITE_TRANSIENT))
335 || (SQLITE_OK != sqlite3_bind_int (dstmt, 3, dtype)))
357 { 336 {
358 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 337 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
359 _("`%s' failed at %s:%d with error: %s\n"), 338 _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_bind",
360 "sqlite3_bind", __FILE__, __LINE__, 339 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh));
361 sqlite3_errmsg (plugin->dbh));
362 (void) sqlite3_finalize (dstmt); 340 (void) sqlite3_finalize (dstmt);
363 return GNUNET_SYSERR; 341 return GNUNET_SYSERR;
364 } 342 }
365 if (sqlite3_step (dstmt) != SQLITE_DONE) 343 if (sqlite3_step (dstmt) != SQLITE_DONE)
366 { 344 {
367 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 345 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
368 _("`%s' failed at %s:%d with error: %s\n"), 346 _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_step",
369 "sqlite3_step", __FILE__, __LINE__, 347 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh));
370 sqlite3_errmsg (plugin->dbh));
371 (void) sqlite3_finalize (dstmt); 348 (void) sqlite3_finalize (dstmt);
372 return GNUNET_SYSERR; 349 return GNUNET_SYSERR;
373 } 350 }
374 plugin->env->delete_notify (plugin->env->cls, &hc, dsize + OVERHEAD); 351 plugin->env->delete_notify (plugin->env->cls, &hc, dsize + OVERHEAD);
375 if (SQLITE_OK != sqlite3_finalize (dstmt)) 352 if (SQLITE_OK != sqlite3_finalize (dstmt))
376 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 353 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
377 _("`%s' failed at %s:%d with error: %s\n"), 354 _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_finalize",
378 "sqlite3_finalize", __FILE__, __LINE__, 355 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh));
379 sqlite3_errmsg (plugin->dbh));
380 return GNUNET_OK; 356 return GNUNET_OK;
381} 357}
382 358
@@ -425,8 +401,7 @@ libgnunet_plugin_datacache_sqlite_init (void *cls)
425 SQLITE3_EXEC (dbh, "PRAGMA count_changes=OFF"); 401 SQLITE3_EXEC (dbh, "PRAGMA count_changes=OFF");
426 SQLITE3_EXEC (dbh, "PRAGMA page_size=4092"); 402 SQLITE3_EXEC (dbh, "PRAGMA page_size=4092");
427 SQLITE3_EXEC (dbh, 403 SQLITE3_EXEC (dbh,
428 "CREATE TABLE ds090 (" 404 "CREATE TABLE ds090 (" " type INTEGER NOT NULL DEFAULT 0,"
429 " type INTEGER NOT NULL DEFAULT 0,"
430 " expire INTEGER NOT NULL DEFAULT 0," 405 " expire INTEGER NOT NULL DEFAULT 0,"
431 " key BLOB NOT NULL DEFAULT ''," 406 " key BLOB NOT NULL DEFAULT '',"
432 " value BLOB NOT NULL DEFAULT '')"); 407 " value BLOB NOT NULL DEFAULT '')");
@@ -440,8 +415,8 @@ libgnunet_plugin_datacache_sqlite_init (void *cls)
440 api->get = &sqlite_plugin_get; 415 api->get = &sqlite_plugin_get;
441 api->put = &sqlite_plugin_put; 416 api->put = &sqlite_plugin_put;
442 api->del = &sqlite_plugin_del; 417 api->del = &sqlite_plugin_del;
443 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, 418 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "sqlite",
444 "sqlite", _("Sqlite datacache running\n")); 419 _("Sqlite datacache running\n"));
445 return api; 420 return api;
446} 421}
447 422
@@ -474,22 +449,20 @@ libgnunet_plugin_datacache_sqlite_done (void *cls)
474#if SQLITE_VERSION_NUMBER >= 3007000 449#if SQLITE_VERSION_NUMBER >= 3007000
475 if (result == SQLITE_BUSY) 450 if (result == SQLITE_BUSY)
476 { 451 {
477 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, 452 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "sqlite",
478 "sqlite",
479 _ 453 _
480 ("Tried to close sqlite without finalizing all prepared statements.\n")); 454 ("Tried to close sqlite without finalizing all prepared statements.\n"));
481 stmt = sqlite3_next_stmt (plugin->dbh, NULL); 455 stmt = sqlite3_next_stmt (plugin->dbh, NULL);
482 while (stmt != NULL) 456 while (stmt != NULL)
483 { 457 {
484#if DEBUG_SQLITE 458#if DEBUG_SQLITE
485 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 459 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
486 "sqlite", "Closing statement %p\n", stmt); 460 "Closing statement %p\n", stmt);
487#endif 461#endif
488 result = sqlite3_finalize (stmt); 462 result = sqlite3_finalize (stmt);
489#if DEBUG_SQLITE 463#if DEBUG_SQLITE
490 if (result != SQLITE_OK) 464 if (result != SQLITE_OK)
491 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 465 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
492 "sqlite",
493 "Failed to close statement %p: %d\n", stmt, result); 466 "Failed to close statement %p: %d\n", stmt, result);
494#endif 467#endif
495 stmt = sqlite3_next_stmt (plugin->dbh, NULL); 468 stmt = sqlite3_next_stmt (plugin->dbh, NULL);
diff --git a/src/datacache/plugin_datacache_template.c b/src/datacache/plugin_datacache_template.c
index 865f431d7..046c603ad 100644
--- a/src/datacache/plugin_datacache_template.c
+++ b/src/datacache/plugin_datacache_template.c
@@ -52,11 +52,8 @@ struct Plugin
52 * @return 0 on error, number of bytes used otherwise 52 * @return 0 on error, number of bytes used otherwise
53 */ 53 */
54static size_t 54static size_t
55template_plugin_put (void *cls, 55template_plugin_put (void *cls, const GNUNET_HashCode * key, size_t size,
56 const GNUNET_HashCode * key, 56 const char *data, enum GNUNET_BLOCK_Type type,
57 size_t size,
58 const char *data,
59 enum GNUNET_BLOCK_Type type,
60 struct GNUNET_TIME_Absolute discard_time) 57 struct GNUNET_TIME_Absolute discard_time)
61{ 58{
62 GNUNET_break (0); 59 GNUNET_break (0);
@@ -76,8 +73,7 @@ template_plugin_put (void *cls,
76 * @return the number of results found 73 * @return the number of results found
77 */ 74 */
78static unsigned int 75static unsigned int
79template_plugin_get (void *cls, 76template_plugin_get (void *cls, const GNUNET_HashCode * key,
80 const GNUNET_HashCode * key,
81 enum GNUNET_BLOCK_Type type, 77 enum GNUNET_BLOCK_Type type,
82 GNUNET_DATACACHE_Iterator iter, void *iter_cls) 78 GNUNET_DATACACHE_Iterator iter, void *iter_cls)
83{ 79{
@@ -121,8 +117,8 @@ libgnunet_plugin_datacache_template_init (void *cls)
121 api->get = &template_plugin_get; 117 api->get = &template_plugin_get;
122 api->put = &template_plugin_put; 118 api->put = &template_plugin_put;
123 api->del = &template_plugin_del; 119 api->del = &template_plugin_del;
124 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, 120 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "template",
125 "template", _("Template datacache running\n")); 121 _("Template datacache running\n"));
126 return api; 122 return api;
127} 123}
128 124
diff --git a/src/datacache/test_datacache.c b/src/datacache/test_datacache.c
index c04facc15..abf0209d8 100644
--- a/src/datacache/test_datacache.c
+++ b/src/datacache/test_datacache.c
@@ -39,10 +39,9 @@ static const char *plugin_name;
39 39
40 40
41static int 41static int
42checkIt (void *cls, 42checkIt (void *cls, struct GNUNET_TIME_Absolute exp,
43 struct GNUNET_TIME_Absolute exp, 43 const GNUNET_HashCode * key, size_t size, const char *data,
44 const GNUNET_HashCode * key, 44 enum GNUNET_BLOCK_Type type)
45 size_t size, const char *data, enum GNUNET_BLOCK_Type type)
46{ 45{
47 if (size != sizeof (GNUNET_HashCode)) 46 if (size != sizeof (GNUNET_HashCode))
48 { 47 {
@@ -59,9 +58,8 @@ checkIt (void *cls,
59 58
60 59
61static void 60static void
62run (void *cls, 61run (void *cls, char *const *args, const char *cfgfile,
63 char *const *args, 62 const struct GNUNET_CONFIGURATION_Handle *cfg)
64 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
65{ 63{
66 struct GNUNET_DATACACHE_Handle *h; 64 struct GNUNET_DATACACHE_Handle *h;
67 GNUNET_HashCode k; 65 GNUNET_HashCode k;
@@ -83,11 +81,9 @@ run (void *cls,
83 for (i = 0; i < 100; i++) 81 for (i = 0; i < 100; i++)
84 { 82 {
85 GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n); 83 GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
86 ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h, 84 ASSERT (GNUNET_OK ==
87 &k, 85 GNUNET_DATACACHE_put (h, &k, sizeof (GNUNET_HashCode),
88 sizeof (GNUNET_HashCode), 86 (const char *) &n, 1 + i % 16, exp));
89 (const char *) &n,
90 1 + i % 16, exp));
91 k = n; 87 k = n;
92 } 88 }
93 memset (&k, 0, sizeof (GNUNET_HashCode)); 89 memset (&k, 0, sizeof (GNUNET_HashCode));
@@ -100,12 +96,10 @@ run (void *cls,
100 96
101 memset (&k, 42, sizeof (GNUNET_HashCode)); 97 memset (&k, 42, sizeof (GNUNET_HashCode));
102 GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n); 98 GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
103 ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h, 99 ASSERT (GNUNET_OK ==
104 &k, 100 GNUNET_DATACACHE_put (h, &k, sizeof (GNUNET_HashCode),
105 sizeof (GNUNET_HashCode), 101 (const char *) &n, 792,
106 (const char *) &n, 102 GNUNET_TIME_UNIT_FOREVER_ABS));
107 792,
108 GNUNET_TIME_UNIT_FOREVER_ABS));
109 ASSERT (0 != GNUNET_DATACACHE_get (h, &k, 792, &checkIt, &n)); 103 ASSERT (0 != GNUNET_DATACACHE_get (h, &k, 792, &checkIt, &n));
110 104
111 GNUNET_DATACACHE_destroy (h); 105 GNUNET_DATACACHE_destroy (h);
@@ -153,13 +147,12 @@ main (int argc, char *argv[])
153 else 147 else
154 pos = (char *) plugin_name; 148 pos = (char *) plugin_name;
155 149
156 GNUNET_snprintf (cfg_name, 150 GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_datacache_data_%s.conf",
157 sizeof (cfg_name), 151 plugin_name);
158 "test_datacache_data_%s.conf", plugin_name);
159 if (pos != plugin_name) 152 if (pos != plugin_name)
160 pos[0] = '.'; 153 pos[0] = '.';
161 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, 154 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv,
162 xargv, "test-datacache", "nohelp", options, &run, NULL); 155 "test-datacache", "nohelp", options, &run, NULL);
163 if (ok != 0) 156 if (ok != 0)
164 fprintf (stderr, "Missed some testcases: %d\n", ok); 157 fprintf (stderr, "Missed some testcases: %d\n", ok);
165 return ok; 158 return ok;
diff --git a/src/datacache/test_datacache_quota.c b/src/datacache/test_datacache_quota.c
index f943844a4..ad8681cec 100644
--- a/src/datacache/test_datacache_quota.c
+++ b/src/datacache/test_datacache_quota.c
@@ -44,9 +44,8 @@ static const char *plugin_name;
44 * some of the data from the last iteration is still there. 44 * some of the data from the last iteration is still there.
45 */ 45 */
46static void 46static void
47run (void *cls, 47run (void *cls, char *const *args, const char *cfgfile,
48 char *const *args, 48 const struct GNUNET_CONFIGURATION_Handle *cfg)
49 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
50{ 49{
51 struct GNUNET_DATACACHE_Handle *h; 50 struct GNUNET_DATACACHE_Handle *h;
52 GNUNET_HashCode k; 51 GNUNET_HashCode k;
@@ -140,14 +139,12 @@ main (int argc, char *argv[])
140 else 139 else
141 pos = (char *) plugin_name; 140 pos = (char *) plugin_name;
142 141
143 GNUNET_snprintf (cfg_name, 142 GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_datacache_data_%s.conf",
144 sizeof (cfg_name), 143 plugin_name);
145 "test_datacache_data_%s.conf", plugin_name);
146 if (pos != plugin_name) 144 if (pos != plugin_name)
147 pos[0] = '.'; 145 pos[0] = '.';
148 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, 146 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv,
149 xargv, "test-datacache-quota", "nohelp", 147 "test-datacache-quota", "nohelp", options, &run, NULL);
150 options, &run, NULL);
151 if (ok != 0) 148 if (ok != 0)
152 fprintf (stderr, "Missed some testcases: %d\n", ok); 149 fprintf (stderr, "Missed some testcases: %d\n", ok);
153 return ok; 150 return ok;
diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c
index 85e402a4d..ff49c106e 100644
--- a/src/datastore/datastore_api.c
+++ b/src/datastore/datastore_api.c
@@ -367,8 +367,8 @@ timeout_queue_entry (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
367 struct GNUNET_DATASTORE_QueueEntry *qe = cls; 367 struct GNUNET_DATASTORE_QueueEntry *qe = cls;
368 368
369 GNUNET_STATISTICS_update (qe->h->stats, 369 GNUNET_STATISTICS_update (qe->h->stats,
370 gettext_noop ("# queue entry timeouts"), 370 gettext_noop ("# queue entry timeouts"), 1,
371 1, GNUNET_NO); 371 GNUNET_NO);
372 qe->task = GNUNET_SCHEDULER_NO_TASK; 372 qe->task = GNUNET_SCHEDULER_NO_TASK;
373 GNUNET_assert (qe->was_transmitted == GNUNET_NO); 373 GNUNET_assert (qe->was_transmitted == GNUNET_NO);
374#if DEBUG_DATASTORE 374#if DEBUG_DATASTORE
@@ -394,10 +394,8 @@ timeout_queue_entry (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
394 * @return NULL if the queue is full 394 * @return NULL if the queue is full
395 */ 395 */
396static struct GNUNET_DATASTORE_QueueEntry * 396static struct GNUNET_DATASTORE_QueueEntry *
397make_queue_entry (struct GNUNET_DATASTORE_Handle *h, 397make_queue_entry (struct GNUNET_DATASTORE_Handle *h, size_t msize,
398 size_t msize, 398 unsigned int queue_priority, unsigned int max_queue_size,
399 unsigned int queue_priority,
400 unsigned int max_queue_size,
401 struct GNUNET_TIME_Relative timeout, 399 struct GNUNET_TIME_Relative timeout,
402 GNUNET_CLIENT_MessageHandler response_proc, 400 GNUNET_CLIENT_MessageHandler response_proc,
403 const union QueueContext *qc) 401 const union QueueContext *qc)
@@ -408,16 +406,16 @@ make_queue_entry (struct GNUNET_DATASTORE_Handle *h,
408 406
409 c = 0; 407 c = 0;
410 pos = h->queue_head; 408 pos = h->queue_head;
411 while ((pos != NULL) && 409 while ((pos != NULL) && (c < max_queue_size) &&
412 (c < max_queue_size) && (pos->priority >= queue_priority)) 410 (pos->priority >= queue_priority))
413 { 411 {
414 c++; 412 c++;
415 pos = pos->next; 413 pos = pos->next;
416 } 414 }
417 if (c >= max_queue_size) 415 if (c >= max_queue_size)
418 { 416 {
419 GNUNET_STATISTICS_update (h->stats, 417 GNUNET_STATISTICS_update (h->stats, gettext_noop ("# queue overflows"), 1,
420 gettext_noop ("# queue overflows"), 1, GNUNET_NO); 418 GNUNET_NO);
421 return NULL; 419 return NULL;
422 } 420 }
423 ret = GNUNET_malloc (sizeof (struct GNUNET_DATASTORE_QueueEntry) + msize); 421 ret = GNUNET_malloc (sizeof (struct GNUNET_DATASTORE_QueueEntry) + msize);
@@ -443,8 +441,7 @@ make_queue_entry (struct GNUNET_DATASTORE_Handle *h,
443 pos = h->queue_head; 441 pos = h->queue_head;
444 } 442 }
445 c++; 443 c++;
446 GNUNET_STATISTICS_update (h->stats, 444 GNUNET_STATISTICS_update (h->stats, gettext_noop ("# queue entries created"),
447 gettext_noop ("# queue entries created"),
448 1, GNUNET_NO); 445 1, GNUNET_NO);
449 GNUNET_CONTAINER_DLL_insert_after (h->queue_head, h->queue_tail, pos, ret); 446 GNUNET_CONTAINER_DLL_insert_after (h->queue_head, h->queue_tail, pos, ret);
450 h->queue_size++; 447 h->queue_size++;
@@ -540,15 +537,14 @@ do_disconnect (struct GNUNET_DATASTORE_Handle *h)
540 return; 537 return;
541 } 538 }
542#if 0 539#if 0
543 GNUNET_STATISTICS_update (stats, 540 GNUNET_STATISTICS_update (stats, gettext_noop ("# reconnected to DATASTORE"),
544 gettext_noop ("# reconnected to DATASTORE"),
545 1, GNUNET_NO); 541 1, GNUNET_NO);
546#endif 542#endif
547 GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); 543 GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
548 h->skip_next_messages = 0; 544 h->skip_next_messages = 0;
549 h->client = NULL; 545 h->client = NULL;
550 h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->retry_time, 546 h->reconnect_task =
551 &try_reconnect, h); 547 GNUNET_SCHEDULER_add_delayed (h->retry_time, &try_reconnect, h);
552} 548}
553 549
554 550
@@ -628,12 +624,11 @@ transmit_request (void *cls, size_t size, void *buf)
628 qe->task = GNUNET_SCHEDULER_NO_TASK; 624 qe->task = GNUNET_SCHEDULER_NO_TASK;
629 GNUNET_assert (GNUNET_NO == h->in_receive); 625 GNUNET_assert (GNUNET_NO == h->in_receive);
630 h->in_receive = GNUNET_YES; 626 h->in_receive = GNUNET_YES;
631 GNUNET_CLIENT_receive (h->client, 627 GNUNET_CLIENT_receive (h->client, &receive_cb, h,
632 &receive_cb, 628 GNUNET_TIME_absolute_get_remaining (qe->timeout));
633 h, GNUNET_TIME_absolute_get_remaining (qe->timeout));
634 GNUNET_STATISTICS_update (h->stats, 629 GNUNET_STATISTICS_update (h->stats,
635 gettext_noop ("# bytes sent to datastore"), 630 gettext_noop ("# bytes sent to datastore"), 1,
636 1, GNUNET_NO); 631 GNUNET_NO);
637 return msize; 632 return msize;
638} 633}
639 634
@@ -686,11 +681,11 @@ process_queue (struct GNUNET_DATASTORE_Handle *h)
686 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 681 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
687 "Queueing %u byte request to DATASTORE\n", qe->message_size); 682 "Queueing %u byte request to DATASTORE\n", qe->message_size);
688#endif 683#endif
689 h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, 684 h->th =
690 qe->message_size, 685 GNUNET_CLIENT_notify_transmit_ready (h->client, qe->message_size,
691 GNUNET_TIME_absolute_get_remaining 686 GNUNET_TIME_absolute_get_remaining
692 (qe->timeout), GNUNET_YES, 687 (qe->timeout), GNUNET_YES,
693 &transmit_request, h); 688 &transmit_request, h);
694 GNUNET_assert (GNUNET_NO == h->in_receive); 689 GNUNET_assert (GNUNET_NO == h->in_receive);
695 GNUNET_break (NULL != h->th); 690 GNUNET_break (NULL != h->th);
696} 691}
@@ -768,8 +763,7 @@ process_status_message (void *cls, const struct GNUNET_MessageHeader *msg)
768 else 763 else
769 process_queue (h); 764 process_queue (h);
770 if (rc.cont != NULL) 765 if (rc.cont != NULL)
771 rc.cont (rc.cont_cls, 766 rc.cont (rc.cont_cls, GNUNET_SYSERR,
772 GNUNET_SYSERR,
773 _("Failed to receive status response from database.")); 767 _("Failed to receive status response from database."));
774 return; 768 return;
775 } 769 }
@@ -782,8 +776,7 @@ process_status_message (void *cls, const struct GNUNET_MessageHeader *msg)
782 h->retry_time = GNUNET_TIME_UNIT_ZERO; 776 h->retry_time = GNUNET_TIME_UNIT_ZERO;
783 do_disconnect (h); 777 do_disconnect (h);
784 if (rc.cont != NULL) 778 if (rc.cont != NULL)
785 rc.cont (rc.cont_cls, 779 rc.cont (rc.cont_cls, GNUNET_SYSERR,
786 GNUNET_SYSERR,
787 _("Error reading response from datastore service")); 780 _("Error reading response from datastore service"));
788 return; 781 return;
789 } 782 }
@@ -805,12 +798,12 @@ process_status_message (void *cls, const struct GNUNET_MessageHeader *msg)
805 emsg = _("Invalid error message received from datastore service"); 798 emsg = _("Invalid error message received from datastore service");
806 } 799 }
807#if DEBUG_DATASTORE 800#if DEBUG_DATASTORE
808 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 801 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received status %d/%s\n", (int) status,
809 "Received status %d/%s\n", (int) status, emsg); 802 emsg);
810#endif 803#endif
811 GNUNET_STATISTICS_update (h->stats, 804 GNUNET_STATISTICS_update (h->stats,
812 gettext_noop ("# status messages received"), 805 gettext_noop ("# status messages received"), 1,
813 1, GNUNET_NO); 806 GNUNET_NO);
814 h->retry_time.rel_value = 0; 807 h->retry_time.rel_value = 0;
815 process_queue (h); 808 process_queue (h);
816 if (rc.cont != NULL) 809 if (rc.cont != NULL)
@@ -845,18 +838,13 @@ process_status_message (void *cls, const struct GNUNET_MessageHeader *msg)
845 * (or rather, will already have been invoked) 838 * (or rather, will already have been invoked)
846 */ 839 */
847struct GNUNET_DATASTORE_QueueEntry * 840struct GNUNET_DATASTORE_QueueEntry *
848GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h, 841GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h, uint32_t rid,
849 uint32_t rid, 842 const GNUNET_HashCode * key, size_t size,
850 const GNUNET_HashCode * key, 843 const void *data, enum GNUNET_BLOCK_Type type,
851 size_t size, 844 uint32_t priority, uint32_t anonymity,
852 const void *data,
853 enum GNUNET_BLOCK_Type type,
854 uint32_t priority,
855 uint32_t anonymity,
856 uint32_t replication, 845 uint32_t replication,
857 struct GNUNET_TIME_Absolute expiration, 846 struct GNUNET_TIME_Absolute expiration,
858 unsigned int queue_priority, 847 unsigned int queue_priority, unsigned int max_queue_size,
859 unsigned int max_queue_size,
860 struct GNUNET_TIME_Relative timeout, 848 struct GNUNET_TIME_Relative timeout,
861 GNUNET_DATASTORE_ContinuationWithStatus cont, 849 GNUNET_DATASTORE_ContinuationWithStatus cont,
862 void *cont_cls) 850 void *cont_cls)
@@ -869,16 +857,14 @@ GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
869#if DEBUG_DATASTORE 857#if DEBUG_DATASTORE
870 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 858 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
871 "Asked to put %u bytes of data under key `%s' for %llu ms\n", 859 "Asked to put %u bytes of data under key `%s' for %llu ms\n",
872 size, 860 size, GNUNET_h2s (key),
873 GNUNET_h2s (key),
874 GNUNET_TIME_absolute_get_remaining (expiration).rel_value); 861 GNUNET_TIME_absolute_get_remaining (expiration).rel_value);
875#endif 862#endif
876 msize = sizeof (struct DataMessage) + size; 863 msize = sizeof (struct DataMessage) + size;
877 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); 864 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
878 qc.sc.cont = cont; 865 qc.sc.cont = cont;
879 qc.sc.cont_cls = cont_cls; 866 qc.sc.cont_cls = cont_cls;
880 qe = make_queue_entry (h, msize, 867 qe = make_queue_entry (h, msize, queue_priority, max_queue_size, timeout,
881 queue_priority, max_queue_size, timeout,
882 &process_status_message, &qc); 868 &process_status_message, &qc);
883 if (qe == NULL) 869 if (qe == NULL)
884 { 870 {
@@ -888,8 +874,7 @@ GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
888#endif 874#endif
889 return NULL; 875 return NULL;
890 } 876 }
891 GNUNET_STATISTICS_update (h->stats, 877 GNUNET_STATISTICS_update (h->stats, gettext_noop ("# PUT requests executed"),
892 gettext_noop ("# PUT requests executed"),
893 1, GNUNET_NO); 878 1, GNUNET_NO);
894 dm = (struct DataMessage *) &qe[1]; 879 dm = (struct DataMessage *) &qe[1];
895 dm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_PUT); 880 dm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_PUT);
@@ -930,10 +915,8 @@ GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
930 * (or rather, will already have been invoked) 915 * (or rather, will already have been invoked)
931 */ 916 */
932struct GNUNET_DATASTORE_QueueEntry * 917struct GNUNET_DATASTORE_QueueEntry *
933GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h, 918GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h, uint64_t amount,
934 uint64_t amount, 919 uint32_t entries, unsigned int queue_priority,
935 uint32_t entries,
936 unsigned int queue_priority,
937 unsigned int max_queue_size, 920 unsigned int max_queue_size,
938 struct GNUNET_TIME_Relative timeout, 921 struct GNUNET_TIME_Relative timeout,
939 GNUNET_DATASTORE_ContinuationWithStatus cont, 922 GNUNET_DATASTORE_ContinuationWithStatus cont,
@@ -952,9 +935,8 @@ GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
952#endif 935#endif
953 qc.sc.cont = cont; 936 qc.sc.cont = cont;
954 qc.sc.cont_cls = cont_cls; 937 qc.sc.cont_cls = cont_cls;
955 qe = make_queue_entry (h, sizeof (struct ReserveMessage), 938 qe = make_queue_entry (h, sizeof (struct ReserveMessage), queue_priority,
956 queue_priority, max_queue_size, timeout, 939 max_queue_size, timeout, &process_status_message, &qc);
957 &process_status_message, &qc);
958 if (qe == NULL) 940 if (qe == NULL)
959 { 941 {
960#if DEBUG_DATASTORE 942#if DEBUG_DATASTORE
@@ -964,8 +946,8 @@ GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
964 return NULL; 946 return NULL;
965 } 947 }
966 GNUNET_STATISTICS_update (h->stats, 948 GNUNET_STATISTICS_update (h->stats,
967 gettext_noop ("# RESERVE requests executed"), 949 gettext_noop ("# RESERVE requests executed"), 1,
968 1, GNUNET_NO); 950 GNUNET_NO);
969 rm = (struct ReserveMessage *) &qe[1]; 951 rm = (struct ReserveMessage *) &qe[1];
970 rm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE); 952 rm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE);
971 rm->header.size = htons (sizeof (struct ReserveMessage)); 953 rm->header.size = htons (sizeof (struct ReserveMessage));
@@ -999,8 +981,7 @@ GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
999 */ 981 */
1000struct GNUNET_DATASTORE_QueueEntry * 982struct GNUNET_DATASTORE_QueueEntry *
1001GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h, 983GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
1002 uint32_t rid, 984 uint32_t rid, unsigned int queue_priority,
1003 unsigned int queue_priority,
1004 unsigned int max_queue_size, 985 unsigned int max_queue_size,
1005 struct GNUNET_TIME_Relative timeout, 986 struct GNUNET_TIME_Relative timeout,
1006 GNUNET_DATASTORE_ContinuationWithStatus cont, 987 GNUNET_DATASTORE_ContinuationWithStatus cont,
@@ -1059,8 +1040,7 @@ GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
1059 * (or rather, will already have been invoked) 1040 * (or rather, will already have been invoked)
1060 */ 1041 */
1061struct GNUNET_DATASTORE_QueueEntry * 1042struct GNUNET_DATASTORE_QueueEntry *
1062GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h, 1043GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h, uint64_t uid,
1063 uint64_t uid,
1064 uint32_t priority, 1044 uint32_t priority,
1065 struct GNUNET_TIME_Absolute expiration, 1045 struct GNUNET_TIME_Absolute expiration,
1066 unsigned int queue_priority, 1046 unsigned int queue_priority,
@@ -1078,15 +1058,13 @@ GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
1078#if DEBUG_DATASTORE 1058#if DEBUG_DATASTORE
1079 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1059 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1080 "Asked to update entry %llu raising priority by %u and expiration to %llu\n", 1060 "Asked to update entry %llu raising priority by %u and expiration to %llu\n",
1081 uid, 1061 uid, (unsigned int) priority,
1082 (unsigned int) priority,
1083 (unsigned long long) expiration.abs_value); 1062 (unsigned long long) expiration.abs_value);
1084#endif 1063#endif
1085 qc.sc.cont = cont; 1064 qc.sc.cont = cont;
1086 qc.sc.cont_cls = cont_cls; 1065 qc.sc.cont_cls = cont_cls;
1087 qe = make_queue_entry (h, sizeof (struct UpdateMessage), 1066 qe = make_queue_entry (h, sizeof (struct UpdateMessage), queue_priority,
1088 queue_priority, max_queue_size, timeout, 1067 max_queue_size, timeout, &process_status_message, &qc);
1089 &process_status_message, &qc);
1090 if (qe == NULL) 1068 if (qe == NULL)
1091 { 1069 {
1092#if DEBUG_DATASTORE 1070#if DEBUG_DATASTORE
@@ -1096,8 +1074,8 @@ GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
1096 return NULL; 1074 return NULL;
1097 } 1075 }
1098 GNUNET_STATISTICS_update (h->stats, 1076 GNUNET_STATISTICS_update (h->stats,
1099 gettext_noop ("# UPDATE requests executed"), 1077 gettext_noop ("# UPDATE requests executed"), 1,
1100 1, GNUNET_NO); 1078 GNUNET_NO);
1101 um = (struct UpdateMessage *) &qe[1]; 1079 um = (struct UpdateMessage *) &qe[1];
1102 um->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_UPDATE); 1080 um->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_UPDATE);
1103 um->header.size = htons (sizeof (struct UpdateMessage)); 1081 um->header.size = htons (sizeof (struct UpdateMessage));
@@ -1132,10 +1110,8 @@ GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
1132 */ 1110 */
1133struct GNUNET_DATASTORE_QueueEntry * 1111struct GNUNET_DATASTORE_QueueEntry *
1134GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h, 1112GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
1135 const GNUNET_HashCode * key, 1113 const GNUNET_HashCode * key, size_t size,
1136 size_t size, 1114 const void *data, unsigned int queue_priority,
1137 const void *data,
1138 unsigned int queue_priority,
1139 unsigned int max_queue_size, 1115 unsigned int max_queue_size,
1140 struct GNUNET_TIME_Relative timeout, 1116 struct GNUNET_TIME_Relative timeout,
1141 GNUNET_DATASTORE_ContinuationWithStatus cont, 1117 GNUNET_DATASTORE_ContinuationWithStatus cont,
@@ -1150,15 +1126,14 @@ GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
1150 cont = &drop_status_cont; 1126 cont = &drop_status_cont;
1151#if DEBUG_DATASTORE 1127#if DEBUG_DATASTORE
1152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1153 "Asked to remove %u bytes under key `%s'\n", 1129 "Asked to remove %u bytes under key `%s'\n", size,
1154 size, GNUNET_h2s (key)); 1130 GNUNET_h2s (key));
1155#endif 1131#endif
1156 qc.sc.cont = cont; 1132 qc.sc.cont = cont;
1157 qc.sc.cont_cls = cont_cls; 1133 qc.sc.cont_cls = cont_cls;
1158 msize = sizeof (struct DataMessage) + size; 1134 msize = sizeof (struct DataMessage) + size;
1159 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); 1135 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
1160 qe = make_queue_entry (h, msize, 1136 qe = make_queue_entry (h, msize, queue_priority, max_queue_size, timeout,
1161 queue_priority, max_queue_size, timeout,
1162 &process_status_message, &qc); 1137 &process_status_message, &qc);
1163 if (qe == NULL) 1138 if (qe == NULL)
1164 { 1139 {
@@ -1169,8 +1144,8 @@ GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
1169 return NULL; 1144 return NULL;
1170 } 1145 }
1171 GNUNET_STATISTICS_update (h->stats, 1146 GNUNET_STATISTICS_update (h->stats,
1172 gettext_noop ("# REMOVE requests executed"), 1147 gettext_noop ("# REMOVE requests executed"), 1,
1173 1, GNUNET_NO); 1148 GNUNET_NO);
1174 dm = (struct DataMessage *) &qe[1]; 1149 dm = (struct DataMessage *) &qe[1];
1175 dm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE); 1150 dm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE);
1176 dm->header.size = htons (msize); 1151 dm->header.size = htons (msize);
@@ -1222,8 +1197,8 @@ process_result_message (void *cls, const struct GNUNET_MessageHeader *msg)
1222 process_queue (h); 1197 process_queue (h);
1223 } 1198 }
1224 if (rc.proc != NULL) 1199 if (rc.proc != NULL)
1225 rc.proc (rc.proc_cls, 1200 rc.proc (rc.proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS,
1226 NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 1201 0);
1227 return; 1202 return;
1228 } 1203 }
1229 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END) 1204 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END)
@@ -1239,8 +1214,8 @@ process_result_message (void *cls, const struct GNUNET_MessageHeader *msg)
1239 h->queue_size); 1214 h->queue_size);
1240#endif 1215#endif
1241 if (rc.proc != NULL) 1216 if (rc.proc != NULL)
1242 rc.proc (rc.proc_cls, 1217 rc.proc (rc.proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS,
1243 NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 1218 0);
1244 h->retry_time.rel_value = 0; 1219 h->retry_time.rel_value = 0;
1245 h->result_count = 0; 1220 h->result_count = 0;
1246 process_queue (h); 1221 process_queue (h);
@@ -1256,8 +1231,8 @@ process_result_message (void *cls, const struct GNUNET_MessageHeader *msg)
1256 h->retry_time = GNUNET_TIME_UNIT_ZERO; 1231 h->retry_time = GNUNET_TIME_UNIT_ZERO;
1257 do_disconnect (h); 1232 do_disconnect (h);
1258 if (rc.proc != NULL) 1233 if (rc.proc != NULL)
1259 rc.proc (rc.proc_cls, 1234 rc.proc (rc.proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS,
1260 NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 1235 0);
1261 return; 1236 return;
1262 } 1237 }
1263 if ((ntohs (msg->size) < sizeof (struct DataMessage)) || 1238 if ((ntohs (msg->size) < sizeof (struct DataMessage)) ||
@@ -1271,30 +1246,25 @@ process_result_message (void *cls, const struct GNUNET_MessageHeader *msg)
1271 h->retry_time = GNUNET_TIME_UNIT_ZERO; 1246 h->retry_time = GNUNET_TIME_UNIT_ZERO;
1272 do_disconnect (h); 1247 do_disconnect (h);
1273 if (rc.proc != NULL) 1248 if (rc.proc != NULL)
1274 rc.proc (rc.proc_cls, 1249 rc.proc (rc.proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS,
1275 NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 1250 0);
1276 return; 1251 return;
1277 } 1252 }
1278 GNUNET_STATISTICS_update (h->stats, 1253 GNUNET_STATISTICS_update (h->stats, gettext_noop ("# Results received"), 1,
1279 gettext_noop ("# Results received"), 1, GNUNET_NO); 1254 GNUNET_NO);
1280 dm = (const struct DataMessage *) msg; 1255 dm = (const struct DataMessage *) msg;
1281#if DEBUG_DATASTORE 1256#if DEBUG_DATASTORE
1282 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1283 "Received result %llu with type %u and size %u with key %s\n", 1258 "Received result %llu with type %u and size %u with key %s\n",
1284 (unsigned long long) GNUNET_ntohll (dm->uid), 1259 (unsigned long long) GNUNET_ntohll (dm->uid), ntohl (dm->type),
1285 ntohl (dm->type), ntohl (dm->size), GNUNET_h2s (&dm->key)); 1260 ntohl (dm->size), GNUNET_h2s (&dm->key));
1286#endif 1261#endif
1287 free_queue_entry (qe); 1262 free_queue_entry (qe);
1288 h->retry_time.rel_value = 0; 1263 h->retry_time.rel_value = 0;
1289 process_queue (h); 1264 process_queue (h);
1290 if (rc.proc != NULL) 1265 if (rc.proc != NULL)
1291 rc.proc (rc.proc_cls, 1266 rc.proc (rc.proc_cls, &dm->key, ntohl (dm->size), &dm[1], ntohl (dm->type),
1292 &dm->key, 1267 ntohl (dm->priority), ntohl (dm->anonymity),
1293 ntohl (dm->size),
1294 &dm[1],
1295 ntohl (dm->type),
1296 ntohl (dm->priority),
1297 ntohl (dm->anonymity),
1298 GNUNET_TIME_absolute_ntoh (dm->expiration), 1268 GNUNET_TIME_absolute_ntoh (dm->expiration),
1299 GNUNET_ntohll (dm->uid)); 1269 GNUNET_ntohll (dm->uid));
1300} 1270}
@@ -1401,8 +1371,8 @@ GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
1401#if DEBUG_DATASTORE 1371#if DEBUG_DATASTORE
1402 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1403 "Asked to get %llu-th zero-anonymity entry of type %d in %llu ms\n", 1373 "Asked to get %llu-th zero-anonymity entry of type %d in %llu ms\n",
1404 (unsigned long long) offset, 1374 (unsigned long long) offset, type,
1405 type, (unsigned long long) timeout.rel_value); 1375 (unsigned long long) timeout.rel_value);
1406#endif 1376#endif
1407 qc.rc.proc = proc; 1377 qc.rc.proc = proc;
1408 qc.rc.proc_cls = proc_cls; 1378 qc.rc.proc_cls = proc_cls;
@@ -1453,8 +1423,7 @@ GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
1453 * cancel 1423 * cancel
1454 */ 1424 */
1455struct GNUNET_DATASTORE_QueueEntry * 1425struct GNUNET_DATASTORE_QueueEntry *
1456GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h, 1426GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h, uint64_t offset,
1457 uint64_t offset,
1458 const GNUNET_HashCode * key, 1427 const GNUNET_HashCode * key,
1459 enum GNUNET_BLOCK_Type type, 1428 enum GNUNET_BLOCK_Type type,
1460 unsigned int queue_priority, 1429 unsigned int queue_priority,
@@ -1474,19 +1443,17 @@ GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h,
1474#endif 1443#endif
1475 qc.rc.proc = proc; 1444 qc.rc.proc = proc;
1476 qc.rc.proc_cls = proc_cls; 1445 qc.rc.proc_cls = proc_cls;
1477 qe = make_queue_entry (h, sizeof (struct GetMessage), 1446 qe = make_queue_entry (h, sizeof (struct GetMessage), queue_priority,
1478 queue_priority, max_queue_size, timeout, 1447 max_queue_size, timeout, &process_result_message, &qc);
1479 &process_result_message, &qc);
1480 if (qe == NULL) 1448 if (qe == NULL)
1481 { 1449 {
1482#if DEBUG_DATASTORE 1450#if DEBUG_DATASTORE
1483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1451 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could not queue request for `%s'\n",
1484 "Could not queue request for `%s'\n", GNUNET_h2s (key)); 1452 GNUNET_h2s (key));
1485#endif 1453#endif
1486 return NULL; 1454 return NULL;
1487 } 1455 }
1488 GNUNET_STATISTICS_update (h->stats, 1456 GNUNET_STATISTICS_update (h->stats, gettext_noop ("# GET requests executed"),
1489 gettext_noop ("# GET requests executed"),
1490 1, GNUNET_NO); 1457 1, GNUNET_NO);
1491 gm = (struct GetMessage *) &qe[1]; 1458 gm = (struct GetMessage *) &qe[1];
1492 gm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_GET); 1459 gm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_GET);
@@ -1522,8 +1489,8 @@ GNUNET_DATASTORE_cancel (struct GNUNET_DATASTORE_QueueEntry *qe)
1522 h = qe->h; 1489 h = qe->h;
1523#if DEBUG_DATASTORE 1490#if DEBUG_DATASTORE
1524 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1491 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1525 "Pending DATASTORE request %p cancelled (%d, %d)\n", 1492 "Pending DATASTORE request %p cancelled (%d, %d)\n", qe,
1526 qe, qe->was_transmitted, h->queue_head == qe); 1493 qe->was_transmitted, h->queue_head == qe);
1527#endif 1494#endif
1528 if (GNUNET_YES == qe->was_transmitted) 1495 if (GNUNET_YES == qe->was_transmitted)
1529 { 1496 {
diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c
index c01de5891..8efb706c1 100644
--- a/src/datastore/gnunet-service-datastore.c
+++ b/src/datastore/gnunet-service-datastore.c
@@ -276,8 +276,8 @@ static struct GNUNET_STATISTICS_GetHandle *stat_get;
276 * @param cls not used 276 * @param cls not used
277 * @param tc task context 277 * @param tc task context
278 */ 278 */
279static void 279static void delete_expired (void *cls,
280delete_expired (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 280 const struct GNUNET_SCHEDULER_TaskContext *tc);
281 281
282 282
283/** 283/**
@@ -301,45 +301,38 @@ delete_expired (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
301 * GNUNET_NO to delete the item and continue (if supported) 301 * GNUNET_NO to delete the item and continue (if supported)
302 */ 302 */
303static int 303static int
304expired_processor (void *cls, 304expired_processor (void *cls, const GNUNET_HashCode * key, uint32_t size,
305 const GNUNET_HashCode * key, 305 const void *data, enum GNUNET_BLOCK_Type type,
306 uint32_t size, 306 uint32_t priority, uint32_t anonymity,
307 const void *data,
308 enum GNUNET_BLOCK_Type type,
309 uint32_t priority,
310 uint32_t anonymity,
311 struct GNUNET_TIME_Absolute expiration, uint64_t uid) 307 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
312{ 308{
313 struct GNUNET_TIME_Absolute now; 309 struct GNUNET_TIME_Absolute now;
314 310
315 if (key == NULL) 311 if (key == NULL)
316 { 312 {
317 expired_kill_task 313 expired_kill_task =
318 = GNUNET_SCHEDULER_add_delayed (MAX_EXPIRE_DELAY, 314 GNUNET_SCHEDULER_add_delayed (MAX_EXPIRE_DELAY, &delete_expired, NULL);
319 &delete_expired, NULL);
320 return GNUNET_SYSERR; 315 return GNUNET_SYSERR;
321 } 316 }
322 now = GNUNET_TIME_absolute_get (); 317 now = GNUNET_TIME_absolute_get ();
323 if (expiration.abs_value > now.abs_value) 318 if (expiration.abs_value > now.abs_value)
324 { 319 {
325 /* finished processing */ 320 /* finished processing */
326 expired_kill_task 321 expired_kill_task =
327 = GNUNET_SCHEDULER_add_delayed (MAX_EXPIRE_DELAY, 322 GNUNET_SCHEDULER_add_delayed (MAX_EXPIRE_DELAY, &delete_expired, NULL);
328 &delete_expired, NULL);
329 return GNUNET_SYSERR; 323 return GNUNET_SYSERR;
330 } 324 }
331#if DEBUG_DATASTORE 325#if DEBUG_DATASTORE
332 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 326 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
333 "Deleting content `%s' of type %u that expired %llu ms ago\n", 327 "Deleting content `%s' of type %u that expired %llu ms ago\n",
334 GNUNET_h2s (key), 328 GNUNET_h2s (key), type,
335 type,
336 (unsigned long long) (now.abs_value - expiration.abs_value)); 329 (unsigned long long) (now.abs_value - expiration.abs_value));
337#endif 330#endif
338 GNUNET_STATISTICS_update (stats, 331 GNUNET_STATISTICS_update (stats, gettext_noop ("# bytes expired"), size,
339 gettext_noop ("# bytes expired"), size, GNUNET_YES); 332 GNUNET_YES);
340 GNUNET_CONTAINER_bloomfilter_remove (filter, key); 333 GNUNET_CONTAINER_bloomfilter_remove (filter, key);
341 expired_kill_task 334 expired_kill_task =
342 = GNUNET_SCHEDULER_add_delayed (MIN_EXPIRE_DELAY, &delete_expired, NULL); 335 GNUNET_SCHEDULER_add_delayed (MIN_EXPIRE_DELAY, &delete_expired, NULL);
343 return GNUNET_NO; 336 return GNUNET_NO;
344} 337}
345 338
@@ -381,13 +374,9 @@ delete_expired (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
381 * GNUNET_NO to delete the item and continue (if supported) 374 * GNUNET_NO to delete the item and continue (if supported)
382 */ 375 */
383static int 376static int
384quota_processor (void *cls, 377quota_processor (void *cls, const GNUNET_HashCode * key, uint32_t size,
385 const GNUNET_HashCode * key, 378 const void *data, enum GNUNET_BLOCK_Type type,
386 uint32_t size, 379 uint32_t priority, uint32_t anonymity,
387 const void *data,
388 enum GNUNET_BLOCK_Type type,
389 uint32_t priority,
390 uint32_t anonymity,
391 struct GNUNET_TIME_Absolute expiration, uint64_t uid) 380 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
392{ 381{
393 unsigned long long *need = cls; 382 unsigned long long *need = cls;
@@ -507,10 +496,10 @@ transmit (struct GNUNET_SERVER_Client *client, struct GNUNET_MessageHeader *msg)
507 tcc->msg = msg; 496 tcc->msg = msg;
508 tcc->client = client; 497 tcc->client = client;
509 if (NULL == 498 if (NULL ==
510 (tcc->th = GNUNET_SERVER_notify_transmit_ready (client, 499 (tcc->th =
511 ntohs (msg->size), 500 GNUNET_SERVER_notify_transmit_ready (client, ntohs (msg->size),
512 GNUNET_TIME_UNIT_FOREVER_REL, 501 GNUNET_TIME_UNIT_FOREVER_REL,
513 &transmit_callback, tcc))) 502 &transmit_callback, tcc)))
514 { 503 {
515 GNUNET_break (0); 504 GNUNET_break (0);
516 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 505 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -572,14 +561,10 @@ transmit_status (struct GNUNET_SERVER_Client *client, int code, const char *msg)
572 * GNUNET_NO to delete the item and continue (if supported) 561 * GNUNET_NO to delete the item and continue (if supported)
573 */ 562 */
574static int 563static int
575transmit_item (void *cls, 564transmit_item (void *cls, const GNUNET_HashCode * key, uint32_t size,
576 const GNUNET_HashCode * key, 565 const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority,
577 uint32_t size, 566 uint32_t anonymity, struct GNUNET_TIME_Absolute expiration,
578 const void *data, 567 uint64_t uid)
579 enum GNUNET_BLOCK_Type type,
580 uint32_t priority,
581 uint32_t anonymity,
582 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
583{ 568{
584 struct GNUNET_SERVER_Client *client = cls; 569 struct GNUNET_SERVER_Client *client = cls;
585 struct GNUNET_MessageHeader *end; 570 struct GNUNET_MessageHeader *end;
@@ -589,8 +574,8 @@ transmit_item (void *cls,
589 { 574 {
590 /* transmit 'DATA_END' */ 575 /* transmit 'DATA_END' */
591#if DEBUG_DATASTORE 576#if DEBUG_DATASTORE
592 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' message\n",
593 "Transmitting `%s' message\n", "DATA_END"); 578 "DATA_END");
594#endif 579#endif
595 end = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader)); 580 end = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader));
596 end->size = htons (sizeof (struct GNUNET_MessageHeader)); 581 end->size = htons (sizeof (struct GNUNET_MessageHeader));
@@ -618,14 +603,12 @@ transmit_item (void *cls,
618#if DEBUG_DATASTORE 603#if DEBUG_DATASTORE
619 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 604 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
620 "Transmitting `%s' message for `%s' of type %u with expiration %llu (now: %llu)\n", 605 "Transmitting `%s' message for `%s' of type %u with expiration %llu (now: %llu)\n",
621 "DATA", 606 "DATA", GNUNET_h2s (key), type,
622 GNUNET_h2s (key),
623 type,
624 (unsigned long long) expiration.abs_value, 607 (unsigned long long) expiration.abs_value,
625 (unsigned long long) GNUNET_TIME_absolute_get ().abs_value); 608 (unsigned long long) GNUNET_TIME_absolute_get ().abs_value);
626#endif 609#endif
627 GNUNET_STATISTICS_update (stats, 610 GNUNET_STATISTICS_update (stats, gettext_noop ("# results found"), 1,
628 gettext_noop ("# results found"), 1, GNUNET_NO); 611 GNUNET_NO);
629 transmit (client, &dm->header); 612 transmit (client, &dm->header);
630 GNUNET_SERVER_client_drop (client); 613 GNUNET_SERVER_client_drop (client);
631 return GNUNET_OK; 614 return GNUNET_OK;
@@ -640,8 +623,7 @@ transmit_item (void *cls,
640 * @param message the actual message 623 * @param message the actual message
641 */ 624 */
642static void 625static void
643handle_reserve (void *cls, 626handle_reserve (void *cls, struct GNUNET_SERVER_Client *client,
644 struct GNUNET_SERVER_Client *client,
645 const struct GNUNET_MessageHeader *message) 627 const struct GNUNET_MessageHeader *message)
646{ 628{
647 /** 629 /**
@@ -696,8 +678,8 @@ handle_reserve (void *cls,
696 return; 678 return;
697 } 679 }
698 reserved += req; 680 reserved += req;
699 GNUNET_STATISTICS_set (stats, 681 GNUNET_STATISTICS_set (stats, gettext_noop ("# reserved"), reserved,
700 gettext_noop ("# reserved"), reserved, GNUNET_NO); 682 GNUNET_NO);
701 e = GNUNET_malloc (sizeof (struct ReservationList)); 683 e = GNUNET_malloc (sizeof (struct ReservationList));
702 e->next = reservations; 684 e->next = reservations;
703 reservations = e; 685 reservations = e;
@@ -719,8 +701,7 @@ handle_reserve (void *cls,
719 * @param message the actual message 701 * @param message the actual message
720 */ 702 */
721static void 703static void
722handle_release_reserve (void *cls, 704handle_release_reserve (void *cls, struct GNUNET_SERVER_Client *client,
723 struct GNUNET_SERVER_Client *client,
724 const struct GNUNET_MessageHeader *message) 705 const struct GNUNET_MessageHeader *message)
725{ 706{
726 const struct ReleaseReserveMessage *msg = 707 const struct ReleaseReserveMessage *msg =
@@ -732,8 +713,8 @@ handle_release_reserve (void *cls,
732 unsigned long long rem; 713 unsigned long long rem;
733 714
734#if DEBUG_DATASTORE 715#if DEBUG_DATASTORE
735 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 716 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s' request\n",
736 "Processing `%s' request\n", "RELEASE_RESERVE"); 717 "RELEASE_RESERVE");
737#endif 718#endif
738 next = reservations; 719 next = reservations;
739 prev = NULL; 720 prev = NULL;
@@ -751,8 +732,8 @@ handle_release_reserve (void *cls,
751 ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * pos->entries; 732 ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * pos->entries;
752 GNUNET_assert (reserved >= rem); 733 GNUNET_assert (reserved >= rem);
753 reserved -= rem; 734 reserved -= rem;
754 GNUNET_STATISTICS_set (stats, 735 GNUNET_STATISTICS_set (stats, gettext_noop ("# reserved"), reserved,
755 gettext_noop ("# reserved"), reserved, GNUNET_NO); 736 GNUNET_NO);
756#if DEBUG_DATASTORE 737#if DEBUG_DATASTORE
757 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 738 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
758 "Returning %llu remaining reserved bytes to storage pool\n", 739 "Returning %llu remaining reserved bytes to storage pool\n",
@@ -830,20 +811,15 @@ execute_put (struct GNUNET_SERVER_Client *client, const struct DataMessage *dm)
830 811
831 size = ntohl (dm->size); 812 size = ntohl (dm->size);
832 msg = NULL; 813 msg = NULL;
833 ret = plugin->api->put (plugin->api->cls, 814 ret =
834 &dm->key, 815 plugin->api->put (plugin->api->cls, &dm->key, size, &dm[1],
835 size, 816 ntohl (dm->type), ntohl (dm->priority),
836 &dm[1], 817 ntohl (dm->anonymity), ntohl (dm->replication),
837 ntohl (dm->type), 818 GNUNET_TIME_absolute_ntoh (dm->expiration), &msg);
838 ntohl (dm->priority),
839 ntohl (dm->anonymity),
840 ntohl (dm->replication),
841 GNUNET_TIME_absolute_ntoh (dm->expiration), &msg);
842 if (GNUNET_OK == ret) 819 if (GNUNET_OK == ret)
843 { 820 {
844 GNUNET_STATISTICS_update (stats, 821 GNUNET_STATISTICS_update (stats, gettext_noop ("# bytes stored"), size,
845 gettext_noop ("# bytes stored"), 822 GNUNET_YES);
846 size, GNUNET_YES);
847 GNUNET_CONTAINER_bloomfilter_add (filter, &dm->key); 823 GNUNET_CONTAINER_bloomfilter_add (filter, &dm->key);
848#if DEBUG_DATASTORE 824#if DEBUG_DATASTORE
849 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 825 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -884,14 +860,10 @@ execute_put (struct GNUNET_SERVER_Client *client, const struct DataMessage *dm)
884 * GNUNET_NO to delete the item 860 * GNUNET_NO to delete the item
885 */ 861 */
886static int 862static int
887check_present (void *cls, 863check_present (void *cls, const GNUNET_HashCode * key, uint32_t size,
888 const GNUNET_HashCode * key, 864 const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority,
889 uint32_t size, 865 uint32_t anonymity, struct GNUNET_TIME_Absolute expiration,
890 const void *data, 866 uint64_t uid)
891 enum GNUNET_BLOCK_Type type,
892 uint32_t priority,
893 uint32_t anonymity,
894 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
895{ 867{
896 struct PutContext *pc = cls; 868 struct PutContext *pc = cls;
897 const struct DataMessage *dm; 869 const struct DataMessage *dm;
@@ -905,8 +877,9 @@ check_present (void *cls,
905 return GNUNET_OK; 877 return GNUNET_OK;
906 } 878 }
907 if ((GNUNET_BLOCK_TYPE_FS_DBLOCK == type) || 879 if ((GNUNET_BLOCK_TYPE_FS_DBLOCK == type) ||
908 (GNUNET_BLOCK_TYPE_FS_IBLOCK == type) || 880 (GNUNET_BLOCK_TYPE_FS_IBLOCK == type) || ((size == ntohl (dm->size)) &&
909 ((size == ntohl (dm->size)) && (0 == memcmp (&dm[1], data, size)))) 881 (0 ==
882 memcmp (&dm[1], data, size))))
910 { 883 {
911#if DEBUG_MYSQL 884#if DEBUG_MYSQL
912 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 885 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -916,8 +889,7 @@ check_present (void *cls,
916 if ((ntohl (dm->priority) > 0) || 889 if ((ntohl (dm->priority) > 0) ||
917 (GNUNET_TIME_absolute_ntoh (dm->expiration).abs_value > 890 (GNUNET_TIME_absolute_ntoh (dm->expiration).abs_value >
918 expiration.abs_value)) 891 expiration.abs_value))
919 plugin->api->update (plugin->api->cls, 892 plugin->api->update (plugin->api->cls, uid,
920 uid,
921 (int32_t) ntohl (dm->priority), 893 (int32_t) ntohl (dm->priority),
922 GNUNET_TIME_absolute_ntoh (dm->expiration), NULL); 894 GNUNET_TIME_absolute_ntoh (dm->expiration), NULL);
923 transmit_status (pc->client, GNUNET_NO, NULL); 895 transmit_status (pc->client, GNUNET_NO, NULL);
@@ -942,8 +914,7 @@ check_present (void *cls,
942 * @param message the actual message 914 * @param message the actual message
943 */ 915 */
944static void 916static void
945handle_put (void *cls, 917handle_put (void *cls, struct GNUNET_SERVER_Client *client,
946 struct GNUNET_SERVER_Client *client,
947 const struct GNUNET_MessageHeader *message) 918 const struct GNUNET_MessageHeader *message)
948{ 919{
949 const struct DataMessage *dm = check_data (message); 920 const struct DataMessage *dm = check_data (message);
@@ -961,8 +932,8 @@ handle_put (void *cls,
961 } 932 }
962#if DEBUG_DATASTORE 933#if DEBUG_DATASTORE
963 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 934 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
964 "Processing `%s' request for `%s' of type %u\n", 935 "Processing `%s' request for `%s' of type %u\n", "PUT",
965 "PUT", GNUNET_h2s (&dm->key), ntohl (dm->type)); 936 GNUNET_h2s (&dm->key), ntohl (dm->type));
966#endif 937#endif
967 rid = ntohl (dm->rid); 938 rid = ntohl (dm->rid);
968 size = ntohl (dm->size); 939 size = ntohl (dm->size);
@@ -979,8 +950,8 @@ handle_put (void *cls,
979 pos->entries--; 950 pos->entries--;
980 pos->amount -= size; 951 pos->amount -= size;
981 reserved -= (size + GNUNET_DATASTORE_ENTRY_OVERHEAD); 952 reserved -= (size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
982 GNUNET_STATISTICS_set (stats, 953 GNUNET_STATISTICS_set (stats, gettext_noop ("# reserved"), reserved,
983 gettext_noop ("# reserved"), reserved, GNUNET_NO); 954 GNUNET_NO);
984 } 955 }
985 } 956 }
986 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (filter, &dm->key)) 957 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (filter, &dm->key))
@@ -991,10 +962,8 @@ handle_put (void *cls,
991 pc->client = client; 962 pc->client = client;
992 GNUNET_SERVER_client_keep (client); 963 GNUNET_SERVER_client_keep (client);
993 memcpy (&pc[1], dm, size + sizeof (struct DataMessage)); 964 memcpy (&pc[1], dm, size + sizeof (struct DataMessage));
994 plugin->api->get_key (plugin->api->cls, 965 plugin->api->get_key (plugin->api->cls, 0, &dm->key, &vhash,
995 0, 966 ntohl (dm->type), &check_present, pc);
996 &dm->key,
997 &vhash, ntohl (dm->type), &check_present, pc);
998 return; 967 return;
999 } 968 }
1000 execute_put (client, dm); 969 execute_put (client, dm);
@@ -1009,8 +978,7 @@ handle_put (void *cls,
1009 * @param message the actual message 978 * @param message the actual message
1010 */ 979 */
1011static void 980static void
1012handle_get (void *cls, 981handle_get (void *cls, struct GNUNET_SERVER_Client *client,
1013 struct GNUNET_SERVER_Client *client,
1014 const struct GNUNET_MessageHeader *message) 982 const struct GNUNET_MessageHeader *message)
1015{ 983{
1016 const struct GetMessage *msg; 984 const struct GetMessage *msg;
@@ -1027,12 +995,11 @@ handle_get (void *cls,
1027 msg = (const struct GetMessage *) message; 995 msg = (const struct GetMessage *) message;
1028#if DEBUG_DATASTORE 996#if DEBUG_DATASTORE
1029 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 997 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1030 "Processing `%s' request for `%s' of type %u\n", 998 "Processing `%s' request for `%s' of type %u\n", "GET",
1031 "GET", GNUNET_h2s (&msg->key), ntohl (msg->type)); 999 GNUNET_h2s (&msg->key), ntohl (msg->type));
1032#endif 1000#endif
1033 GNUNET_STATISTICS_update (stats, 1001 GNUNET_STATISTICS_update (stats, gettext_noop ("# GET requests received"), 1,
1034 gettext_noop ("# GET requests received"), 1002 GNUNET_NO);
1035 1, GNUNET_NO);
1036 GNUNET_SERVER_client_keep (client); 1003 GNUNET_SERVER_client_keep (client);
1037 if ((size == sizeof (struct GetMessage)) && 1004 if ((size == sizeof (struct GetMessage)) &&
1038 (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (filter, &msg->key))) 1005 (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (filter, &msg->key)))
@@ -1051,8 +1018,7 @@ handle_get (void *cls,
1051 0); 1018 0);
1052 return; 1019 return;
1053 } 1020 }
1054 plugin->api->get_key (plugin->api->cls, 1021 plugin->api->get_key (plugin->api->cls, GNUNET_ntohll (msg->offset),
1055 GNUNET_ntohll (msg->offset),
1056 ((size == 1022 ((size ==
1057 sizeof (struct GetMessage)) ? &msg->key : NULL), NULL, 1023 sizeof (struct GetMessage)) ? &msg->key : NULL), NULL,
1058 ntohl (msg->type), &transmit_item, client); 1024 ntohl (msg->type), &transmit_item, client);
@@ -1067,29 +1033,25 @@ handle_get (void *cls,
1067 * @param message the actual message 1033 * @param message the actual message
1068 */ 1034 */
1069static void 1035static void
1070handle_update (void *cls, 1036handle_update (void *cls, struct GNUNET_SERVER_Client *client,
1071 struct GNUNET_SERVER_Client *client,
1072 const struct GNUNET_MessageHeader *message) 1037 const struct GNUNET_MessageHeader *message)
1073{ 1038{
1074 const struct UpdateMessage *msg; 1039 const struct UpdateMessage *msg;
1075 int ret; 1040 int ret;
1076 char *emsg; 1041 char *emsg;
1077 1042
1078 GNUNET_STATISTICS_update (stats, 1043 GNUNET_STATISTICS_update (stats, gettext_noop ("# UPDATE requests received"),
1079 gettext_noop ("# UPDATE requests received"),
1080 1, GNUNET_NO); 1044 1, GNUNET_NO);
1081 msg = (const struct UpdateMessage *) message; 1045 msg = (const struct UpdateMessage *) message;
1082 emsg = NULL; 1046 emsg = NULL;
1083#if DEBUG_DATASTORE 1047#if DEBUG_DATASTORE
1084 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1048 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s' request for %llu\n",
1085 "Processing `%s' request for %llu\n",
1086 "UPDATE", (unsigned long long) GNUNET_ntohll (msg->uid)); 1049 "UPDATE", (unsigned long long) GNUNET_ntohll (msg->uid));
1087#endif 1050#endif
1088 ret = plugin->api->update (plugin->api->cls, 1051 ret =
1089 GNUNET_ntohll (msg->uid), 1052 plugin->api->update (plugin->api->cls, GNUNET_ntohll (msg->uid),
1090 (int32_t) ntohl (msg->priority), 1053 (int32_t) ntohl (msg->priority),
1091 GNUNET_TIME_absolute_ntoh (msg->expiration), 1054 GNUNET_TIME_absolute_ntoh (msg->expiration), &emsg);
1092 &emsg);
1093 transmit_status (client, ret, emsg); 1055 transmit_status (client, ret, emsg);
1094 GNUNET_free_non_null (emsg); 1056 GNUNET_free_non_null (emsg);
1095} 1057}
@@ -1103,13 +1065,12 @@ handle_update (void *cls,
1103 * @param message the actual message 1065 * @param message the actual message
1104 */ 1066 */
1105static void 1067static void
1106handle_get_replication (void *cls, 1068handle_get_replication (void *cls, struct GNUNET_SERVER_Client *client,
1107 struct GNUNET_SERVER_Client *client,
1108 const struct GNUNET_MessageHeader *message) 1069 const struct GNUNET_MessageHeader *message)
1109{ 1070{
1110#if DEBUG_DATASTORE 1071#if DEBUG_DATASTORE
1111 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1072 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s' request\n",
1112 "Processing `%s' request\n", "GET_REPLICATION"); 1073 "GET_REPLICATION");
1113#endif 1074#endif
1114 GNUNET_STATISTICS_update (stats, 1075 GNUNET_STATISTICS_update (stats,
1115 gettext_noop 1076 gettext_noop
@@ -1128,8 +1089,7 @@ handle_get_replication (void *cls,
1128 * @param message the actual message 1089 * @param message the actual message
1129 */ 1090 */
1130static void 1091static void
1131handle_get_zero_anonymity (void *cls, 1092handle_get_zero_anonymity (void *cls, struct GNUNET_SERVER_Client *client,
1132 struct GNUNET_SERVER_Client *client,
1133 const struct GNUNET_MessageHeader *message) 1093 const struct GNUNET_MessageHeader *message)
1134{ 1094{
1135 const struct GetZeroAnonymityMessage *msg = 1095 const struct GetZeroAnonymityMessage *msg =
@@ -1144,8 +1104,8 @@ handle_get_zero_anonymity (void *cls,
1144 return; 1104 return;
1145 } 1105 }
1146#if DEBUG_DATASTORE 1106#if DEBUG_DATASTORE
1147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s' request\n",
1148 "Processing `%s' request\n", "GET_ZERO_ANONYMITY"); 1108 "GET_ZERO_ANONYMITY");
1149#endif 1109#endif
1150 GNUNET_STATISTICS_update (stats, 1110 GNUNET_STATISTICS_update (stats,
1151 gettext_noop 1111 gettext_noop
@@ -1153,8 +1113,8 @@ handle_get_zero_anonymity (void *cls,
1153 GNUNET_NO); 1113 GNUNET_NO);
1154 GNUNET_SERVER_client_keep (client); 1114 GNUNET_SERVER_client_keep (client);
1155 plugin->api->get_zero_anonymity (plugin->api->cls, 1115 plugin->api->get_zero_anonymity (plugin->api->cls,
1156 GNUNET_ntohll (msg->offset), 1116 GNUNET_ntohll (msg->offset), type,
1157 type, &transmit_item, client); 1117 &transmit_item, client);
1158} 1118}
1159 1119
1160 1120
@@ -1163,13 +1123,9 @@ handle_get_zero_anonymity (void *cls,
1163 * in to be deleted (by returning GNUNET_NO). 1123 * in to be deleted (by returning GNUNET_NO).
1164 */ 1124 */
1165static int 1125static int
1166remove_callback (void *cls, 1126remove_callback (void *cls, const GNUNET_HashCode * key, uint32_t size,
1167 const GNUNET_HashCode * key, 1127 const void *data, enum GNUNET_BLOCK_Type type,
1168 uint32_t size, 1128 uint32_t priority, uint32_t anonymity,
1169 const void *data,
1170 enum GNUNET_BLOCK_Type type,
1171 uint32_t priority,
1172 uint32_t anonymity,
1173 struct GNUNET_TIME_Absolute expiration, uint64_t uid) 1129 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
1174{ 1130{
1175 struct GNUNET_SERVER_Client *client = cls; 1131 struct GNUNET_SERVER_Client *client = cls;
@@ -1207,8 +1163,7 @@ remove_callback (void *cls,
1207 * @param message the actual message 1163 * @param message the actual message
1208 */ 1164 */
1209static void 1165static void
1210handle_remove (void *cls, 1166handle_remove (void *cls, struct GNUNET_SERVER_Client *client,
1211 struct GNUNET_SERVER_Client *client,
1212 const struct GNUNET_MessageHeader *message) 1167 const struct GNUNET_MessageHeader *message)
1213{ 1168{
1214 const struct DataMessage *dm = check_data (message); 1169 const struct DataMessage *dm = check_data (message);
@@ -1222,18 +1177,14 @@ handle_remove (void *cls,
1222 } 1177 }
1223#if DEBUG_DATASTORE 1178#if DEBUG_DATASTORE
1224 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1225 "Processing `%s' request for `%s' of type %u\n", 1180 "Processing `%s' request for `%s' of type %u\n", "REMOVE",
1226 "REMOVE", GNUNET_h2s (&dm->key), ntohl (dm->type)); 1181 GNUNET_h2s (&dm->key), ntohl (dm->type));
1227#endif 1182#endif
1228 GNUNET_STATISTICS_update (stats, 1183 GNUNET_STATISTICS_update (stats, gettext_noop ("# REMOVE requests received"),
1229 gettext_noop ("# REMOVE requests received"),
1230 1, GNUNET_NO); 1184 1, GNUNET_NO);
1231 GNUNET_SERVER_client_keep (client); 1185 GNUNET_SERVER_client_keep (client);
1232 GNUNET_CRYPTO_hash (&dm[1], ntohl (dm->size), &vhash); 1186 GNUNET_CRYPTO_hash (&dm[1], ntohl (dm->size), &vhash);
1233 plugin->api->get_key (plugin->api->cls, 1187 plugin->api->get_key (plugin->api->cls, 0, &dm->key, &vhash,
1234 0,
1235 &dm->key,
1236 &vhash,
1237 (enum GNUNET_BLOCK_Type) ntohl (dm->type), 1188 (enum GNUNET_BLOCK_Type) ntohl (dm->type),
1238 &remove_callback, client); 1189 &remove_callback, client);
1239} 1190}
@@ -1247,8 +1198,7 @@ handle_remove (void *cls,
1247 * @param message the actual message 1198 * @param message the actual message
1248 */ 1199 */
1249static void 1200static void
1250handle_drop (void *cls, 1201handle_drop (void *cls, struct GNUNET_SERVER_Client *client,
1251 struct GNUNET_SERVER_Client *client,
1252 const struct GNUNET_MessageHeader *message) 1202 const struct GNUNET_MessageHeader *message)
1253{ 1203{
1254#if DEBUG_DATASTORE 1204#if DEBUG_DATASTORE
@@ -1298,9 +1248,8 @@ disk_utilization_change_cb (void *cls, int delta)
1298 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration 1248 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
1299 */ 1249 */
1300static int 1250static int
1301process_stat_in (void *cls, 1251process_stat_in (void *cls, const char *subsystem, const char *name,
1302 const char *subsystem, 1252 uint64_t value, int is_persistent)
1303 const char *name, uint64_t value, int is_persistent)
1304{ 1253{
1305 GNUNET_assert (stats_worked == GNUNET_NO); 1254 GNUNET_assert (stats_worked == GNUNET_NO);
1306 stats_worked = GNUNET_YES; 1255 stats_worked = GNUNET_YES;
@@ -1336,20 +1285,20 @@ load_plugin ()
1336 char *name; 1285 char *name;
1337 1286
1338 if (GNUNET_OK != 1287 if (GNUNET_OK !=
1339 GNUNET_CONFIGURATION_get_value_string (cfg, 1288 GNUNET_CONFIGURATION_get_value_string (cfg, "DATASTORE", "DATABASE",
1340 "DATASTORE", "DATABASE", &name)) 1289 &name))
1341 { 1290 {
1342 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1291 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1343 _("No `%s' specified for `%s' in configuration!\n"), 1292 _("No `%s' specified for `%s' in configuration!\n"), "DATABASE",
1344 "DATABASE", "DATASTORE"); 1293 "DATASTORE");
1345 return NULL; 1294 return NULL;
1346 } 1295 }
1347 ret = GNUNET_malloc (sizeof (struct DatastorePlugin)); 1296 ret = GNUNET_malloc (sizeof (struct DatastorePlugin));
1348 ret->env.cfg = cfg; 1297 ret->env.cfg = cfg;
1349 ret->env.duc = &disk_utilization_change_cb; 1298 ret->env.duc = &disk_utilization_change_cb;
1350 ret->env.cls = NULL; 1299 ret->env.cls = NULL;
1351 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1300 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' datastore plugin\n"),
1352 _("Loading `%s' datastore plugin\n"), name); 1301 name);
1353 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); 1302 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
1354 ret->short_name = name; 1303 ret->short_name = name;
1355 ret->lib_name = libname; 1304 ret->lib_name = libname;
@@ -1444,8 +1393,8 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1444 GNUNET_SCHEDULER_cancel (expired_kill_task); 1393 GNUNET_SCHEDULER_cancel (expired_kill_task);
1445 expired_kill_task = GNUNET_SCHEDULER_NO_TASK; 1394 expired_kill_task = GNUNET_SCHEDULER_NO_TASK;
1446 } 1395 }
1447 GNUNET_SCHEDULER_add_continuation (&unload_task, 1396 GNUNET_SCHEDULER_add_continuation (&unload_task, NULL,
1448 NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 1397 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1449} 1398}
1450 1399
1451 1400
@@ -1486,8 +1435,8 @@ cleanup_reservations (void *cls, struct GNUNET_SERVER_Client *client)
1486 } 1435 }
1487 pos = next; 1436 pos = next;
1488 } 1437 }
1489 GNUNET_STATISTICS_set (stats, 1438 GNUNET_STATISTICS_set (stats, gettext_noop ("# reserved"), reserved,
1490 gettext_noop ("# reserved"), reserved, GNUNET_NO); 1439 GNUNET_NO);
1491} 1440}
1492 1441
1493 1442
@@ -1499,8 +1448,7 @@ cleanup_reservations (void *cls, struct GNUNET_SERVER_Client *client)
1499 * @param c configuration to use 1448 * @param c configuration to use
1500 */ 1449 */
1501static void 1450static void
1502run (void *cls, 1451run (void *cls, struct GNUNET_SERVER_Handle *server,
1503 struct GNUNET_SERVER_Handle *server,
1504 const struct GNUNET_CONFIGURATION_Handle *c) 1452 const struct GNUNET_CONFIGURATION_Handle *c)
1505{ 1453{
1506 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 1454 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
@@ -1532,21 +1480,19 @@ run (void *cls,
1532 GNUNET_CONFIGURATION_get_value_number (cfg, "DATASTORE", "QUOTA", &quota)) 1480 GNUNET_CONFIGURATION_get_value_number (cfg, "DATASTORE", "QUOTA", &quota))
1533 { 1481 {
1534 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1482 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1535 _("No `%s' specified for `%s' in configuration!\n"), 1483 _("No `%s' specified for `%s' in configuration!\n"), "QUOTA",
1536 "QUOTA", "DATASTORE"); 1484 "DATASTORE");
1537 return; 1485 return;
1538 } 1486 }
1539 stats = GNUNET_STATISTICS_create ("datastore", cfg); 1487 stats = GNUNET_STATISTICS_create ("datastore", cfg);
1540 GNUNET_STATISTICS_set (stats, gettext_noop ("# quota"), quota, GNUNET_NO); 1488 GNUNET_STATISTICS_set (stats, gettext_noop ("# quota"), quota, GNUNET_NO);
1541 cache_size = quota / 8; /* Or should we make this an option? */ 1489 cache_size = quota / 8; /* Or should we make this an option? */
1542 GNUNET_STATISTICS_set (stats, 1490 GNUNET_STATISTICS_set (stats, gettext_noop ("# cache size"), cache_size,
1543 gettext_noop ("# cache size"), cache_size, GNUNET_NO); 1491 GNUNET_NO);
1544 bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */ 1492 bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */
1545 fn = NULL; 1493 fn = NULL;
1546 if ((GNUNET_OK != 1494 if ((GNUNET_OK !=
1547 GNUNET_CONFIGURATION_get_value_filename (cfg, 1495 GNUNET_CONFIGURATION_get_value_filename (cfg, "DATASTORE", "BLOOMFILTER",
1548 "DATASTORE",
1549 "BLOOMFILTER",
1550 &fn)) || 1496 &fn)) ||
1551 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn))) 1497 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)))
1552 { 1498 {
@@ -1584,19 +1530,17 @@ run (void *cls,
1584 } 1530 }
1585 return; 1531 return;
1586 } 1532 }
1587 stat_get = GNUNET_STATISTICS_get (stats, 1533 stat_get =
1588 "datastore", 1534 GNUNET_STATISTICS_get (stats, "datastore", QUOTA_STAT_NAME,
1589 QUOTA_STAT_NAME, 1535 GNUNET_TIME_UNIT_SECONDS, &process_stat_done,
1590 GNUNET_TIME_UNIT_SECONDS, 1536 &process_stat_in, plugin);
1591 &process_stat_done,
1592 &process_stat_in, plugin);
1593 GNUNET_SERVER_disconnect_notify (server, &cleanup_reservations, NULL); 1537 GNUNET_SERVER_disconnect_notify (server, &cleanup_reservations, NULL);
1594 GNUNET_SERVER_add_handlers (server, handlers); 1538 GNUNET_SERVER_add_handlers (server, handlers);
1595 expired_kill_task 1539 expired_kill_task =
1596 = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, 1540 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
1597 &delete_expired, NULL); 1541 &delete_expired, NULL);
1598 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 1542 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task,
1599 &cleaning_task, NULL); 1543 NULL);
1600} 1544}
1601 1545
1602 1546
@@ -1612,11 +1556,10 @@ main (int argc, char *const *argv)
1612{ 1556{
1613 int ret; 1557 int ret;
1614 1558
1615 ret = (GNUNET_OK == 1559 ret =
1616 GNUNET_SERVICE_run (argc, 1560 (GNUNET_OK ==
1617 argv, 1561 GNUNET_SERVICE_run (argc, argv, "datastore", GNUNET_SERVICE_OPTION_NONE,
1618 "datastore", 1562 &run, NULL)) ? 0 : 1;
1619 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
1620 return ret; 1563 return ret;
1621} 1564}
1622 1565
diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c
index 9d567aacd..cf9911329 100644
--- a/src/datastore/perf_datastore_api.c
+++ b/src/datastore/perf_datastore_api.c
@@ -104,8 +104,8 @@ struct CpsRunContext
104 104
105 105
106 106
107static void 107static void run_continuation (void *cls,
108run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 108 const struct GNUNET_SCHEDULER_TaskContext *tc);
109 109
110 110
111 111
@@ -138,8 +138,8 @@ check_success (void *cls, int success, const char *msg)
138 else 138 else
139 crc->phase = RP_CUT; 139 crc->phase = RP_CUT;
140 } 140 }
141 GNUNET_SCHEDULER_add_continuation (&run_continuation, 141 GNUNET_SCHEDULER_add_continuation (&run_continuation, crc,
142 crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 142 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
143} 143}
144 144
145 145
@@ -172,14 +172,10 @@ remove_next (void *cls, int success, const char *msg)
172 172
173 173
174static void 174static void
175delete_value (void *cls, 175delete_value (void *cls, const GNUNET_HashCode * key, size_t size,
176 const GNUNET_HashCode * key, 176 const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority,
177 size_t size, 177 uint32_t anonymity, struct GNUNET_TIME_Absolute expiration,
178 const void *data, 178 uint64_t uid)
179 enum GNUNET_BLOCK_Type type,
180 uint32_t priority,
181 uint32_t anonymity,
182 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
183{ 179{
184 struct CpsRunContext *crc = cls; 180 struct CpsRunContext *crc = cls;
185 181
@@ -191,11 +187,8 @@ delete_value (void *cls,
191 if (stored_bytes < MAX_SIZE) 187 if (stored_bytes < MAX_SIZE)
192 crc->phase = RP_PUT; 188 crc->phase = RP_PUT;
193 GNUNET_assert (NULL != 189 GNUNET_assert (NULL !=
194 GNUNET_DATASTORE_remove (datastore, 190 GNUNET_DATASTORE_remove (datastore, key, size, data, 1, 1,
195 key, 191 TIMEOUT, &remove_next, crc));
196 size,
197 data,
198 1, 1, TIMEOUT, &remove_next, crc));
199} 192}
200 193
201 194
@@ -228,12 +221,7 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
228 memset (data, i - 255, size / 2); 221 memset (data, i - 255, size / 2);
229 data[0] = k; 222 data[0] = k;
230 GNUNET_assert (NULL != 223 GNUNET_assert (NULL !=
231 GNUNET_DATASTORE_put (datastore, 224 GNUNET_DATASTORE_put (datastore, 0, &key, size, data, i + 1,
232 0,
233 &key,
234 size,
235 data,
236 i + 1,
237 GNUNET_CRYPTO_random_u32 225 GNUNET_CRYPTO_random_u32
238 (GNUNET_CRYPTO_QUALITY_WEAK, 100), i, 226 (GNUNET_CRYPTO_QUALITY_WEAK, 100), i,
239 0, 227 0,
@@ -247,9 +235,9 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
247 case RP_CUT: 235 case RP_CUT:
248 /* trim down below MAX_SIZE again */ 236 /* trim down below MAX_SIZE again */
249 GNUNET_assert (NULL != 237 GNUNET_assert (NULL !=
250 GNUNET_DATASTORE_get_for_replication (datastore, 238 GNUNET_DATASTORE_get_for_replication (datastore, 1, 1,
251 1, 1, TIMEOUT, 239 TIMEOUT, &delete_value,
252 &delete_value, crc)); 240 crc));
253 break; 241 break;
254 case RP_REPORT: 242 case RP_REPORT:
255 printf ( 243 printf (
@@ -263,15 +251,13 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
263 (start_time).rel_value)); 251 (start_time).rel_value));
264 crc->phase = RP_PUT; 252 crc->phase = RP_PUT;
265 crc->j = 0; 253 crc->j = 0;
266 GNUNET_SCHEDULER_add_continuation (&run_continuation, 254 GNUNET_SCHEDULER_add_continuation (&run_continuation, crc,
267 crc,
268 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 255 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
269 break; 256 break;
270 case RP_DONE: 257 case RP_DONE:
271 GNUNET_snprintf (gstr, sizeof (gstr), "DATASTORE-%s", plugin_name); 258 GNUNET_snprintf (gstr, sizeof (gstr), "DATASTORE-%s", plugin_name);
272 if ((crc->i == ITERATIONS) && (stored_ops > 0)) 259 if ((crc->i == ITERATIONS) && (stored_ops > 0))
273 GAUGER (gstr, 260 GAUGER (gstr, "PUT operation duration",
274 "PUT operation duration",
275 GNUNET_TIME_absolute_get_duration (start_time).rel_value / 261 GNUNET_TIME_absolute_get_duration (start_time).rel_value /
276 stored_ops, "ms/operation"); 262 stored_ops, "ms/operation");
277 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); 263 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
@@ -302,15 +288,14 @@ run_tests (void *cls, int success, const char *msg)
302 GNUNET_free (crc); 288 GNUNET_free (crc);
303 return; 289 return;
304 } 290 }
305 GNUNET_SCHEDULER_add_continuation (&run_continuation, 291 GNUNET_SCHEDULER_add_continuation (&run_continuation, crc,
306 crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 292 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
307} 293}
308 294
309 295
310static void 296static void
311run (void *cls, 297run (void *cls, char *const *args, const char *cfgfile,
312 char *const *args, 298 const struct GNUNET_CONFIGURATION_Handle *cfg)
313 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
314{ 299{
315 struct CpsRunContext *crc; 300 struct CpsRunContext *crc;
316 static GNUNET_HashCode zkey; 301 static GNUNET_HashCode zkey;
@@ -321,10 +306,8 @@ run (void *cls,
321 crc->cfg = cfg; 306 crc->cfg = cfg;
322 crc->phase = RP_PUT; 307 crc->phase = RP_PUT;
323 if (NULL == 308 if (NULL ==
324 GNUNET_DATASTORE_put (datastore, 0, 309 GNUNET_DATASTORE_put (datastore, 0, &zkey, 4, "TEST",
325 &zkey, 4, "TEST", 310 GNUNET_BLOCK_TYPE_TEST, 0, 0, 0,
326 GNUNET_BLOCK_TYPE_TEST,
327 0, 0, 0,
328 GNUNET_TIME_relative_to_absolute 311 GNUNET_TIME_relative_to_absolute
329 (GNUNET_TIME_UNIT_SECONDS), 0, 1, 312 (GNUNET_TIME_UNIT_SECONDS), 0, 1,
330 GNUNET_TIME_UNIT_MINUTES, &run_tests, crc)) 313 GNUNET_TIME_UNIT_MINUTES, &run_tests, crc))
@@ -355,19 +338,18 @@ check ()
355 GNUNET_GETOPT_OPTION_END 338 GNUNET_GETOPT_OPTION_END
356 }; 339 };
357 340
358 GNUNET_snprintf (cfg_name, 341 GNUNET_snprintf (cfg_name, sizeof (cfg_name),
359 sizeof (cfg_name),
360 "test_datastore_api_data_%s.conf", plugin_name); 342 "test_datastore_api_data_%s.conf", plugin_name);
361 proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 343 proc =
362 "gnunet-service-arm", 344 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
345 "gnunet-service-arm",
363#if VERBOSE 346#if VERBOSE
364 "-L", "DEBUG", 347 "-L", "DEBUG",
365#endif 348#endif
366 "-c", cfg_name, NULL); 349 "-c", cfg_name, NULL);
367 GNUNET_assert (NULL != proc); 350 GNUNET_assert (NULL != proc);
368 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 351 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
369 argv, "perf-datastore-api", "nohelp", 352 "perf-datastore-api", "nohelp", options, &run, NULL);
370 options, &run, NULL);
371 sleep (1); /* give datastore chance to process 'DROP' */ 353 sleep (1); /* give datastore chance to process 'DROP' */
372 if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) 354 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
373 { 355 {
@@ -398,9 +380,8 @@ main (int argc, char *argv[])
398 else 380 else
399 pos = (char *) plugin_name; 381 pos = (char *) plugin_name;
400 382
401 GNUNET_snprintf (dir_name, 383 GNUNET_snprintf (dir_name, sizeof (dir_name), "/tmp/test-gnunet-datastore-%s",
402 sizeof (dir_name), 384 plugin_name);
403 "/tmp/test-gnunet-datastore-%s", plugin_name);
404 GNUNET_DISK_directory_remove (dir_name); 385 GNUNET_DISK_directory_remove (dir_name);
405 GNUNET_log_setup ("perf-datastore-api", 386 GNUNET_log_setup ("perf-datastore-api",
406#if VERBOSE 387#if VERBOSE
diff --git a/src/datastore/perf_plugin_datastore.c b/src/datastore/perf_plugin_datastore.c
index f8a3705e4..1e2a29f14 100644
--- a/src/datastore/perf_plugin_datastore.c
+++ b/src/datastore/perf_plugin_datastore.c
@@ -149,14 +149,10 @@ static void test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
149 149
150 150
151static int 151static int
152iterate_zeros (void *cls, 152iterate_zeros (void *cls, const GNUNET_HashCode * key, uint32_t size,
153 const GNUNET_HashCode * key, 153 const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority,
154 uint32_t size, 154 uint32_t anonymity, struct GNUNET_TIME_Absolute expiration,
155 const void *data, 155 uint64_t uid)
156 enum GNUNET_BLOCK_Type type,
157 uint32_t priority,
158 uint32_t anonymity,
159 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
160{ 156{
161 struct CpsRunContext *crc = cls; 157 struct CpsRunContext *crc = cls;
162 int i; 158 int i;
@@ -187,8 +183,7 @@ iterate_zeros (void *cls,
187 (unsigned long long) (crc->end.abs_value - crc->start.abs_value), 183 (unsigned long long) (crc->end.abs_value - crc->start.abs_value),
188 bc, crc->cnt); 184 bc, crc->cnt);
189 if (crc->cnt > 0) 185 if (crc->cnt > 0)
190 GAUGER (category, 186 GAUGER (category, "Select random zero-anonymity item",
191 "Select random zero-anonymity item",
192 (crc->end.abs_value - crc->start.abs_value) / crc->cnt, 187 (crc->end.abs_value - crc->start.abs_value) / crc->cnt,
193 "ms/item"); 188 "ms/item");
194 memset (hits, 0, sizeof (hits)); 189 memset (hits, 0, sizeof (hits));
@@ -202,13 +197,9 @@ iterate_zeros (void *cls,
202 197
203 198
204static int 199static int
205expiration_get (void *cls, 200expiration_get (void *cls, const GNUNET_HashCode * key, uint32_t size,
206 const GNUNET_HashCode * key, 201 const void *data, enum GNUNET_BLOCK_Type type,
207 uint32_t size, 202 uint32_t priority, uint32_t anonymity,
208 const void *data,
209 enum GNUNET_BLOCK_Type type,
210 uint32_t priority,
211 uint32_t anonymity,
212 struct GNUNET_TIME_Absolute expiration, uint64_t uid) 203 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
213{ 204{
214 struct CpsRunContext *crc = cls; 205 struct CpsRunContext *crc = cls;
@@ -234,8 +225,7 @@ expiration_get (void *cls,
234 (unsigned long long) (crc->end.abs_value - crc->start.abs_value), 225 (unsigned long long) (crc->end.abs_value - crc->start.abs_value),
235 bc, (unsigned int) PUT_10); 226 bc, (unsigned int) PUT_10);
236 if (crc->cnt > 0) 227 if (crc->cnt > 0)
237 GAUGER (category, 228 GAUGER (category, "Selecting and deleting by expiration",
238 "Selecting and deleting by expiration",
239 (crc->end.abs_value - crc->start.abs_value) / crc->cnt, 229 (crc->end.abs_value - crc->start.abs_value) / crc->cnt,
240 "ms/item"); 230 "ms/item");
241 memset (hits, 0, sizeof (hits)); 231 memset (hits, 0, sizeof (hits));
@@ -252,13 +242,9 @@ expiration_get (void *cls,
252 242
253 243
254static int 244static int
255replication_get (void *cls, 245replication_get (void *cls, const GNUNET_HashCode * key, uint32_t size,
256 const GNUNET_HashCode * key, 246 const void *data, enum GNUNET_BLOCK_Type type,
257 uint32_t size, 247 uint32_t priority, uint32_t anonymity,
258 const void *data,
259 enum GNUNET_BLOCK_Type type,
260 uint32_t priority,
261 uint32_t anonymity,
262 struct GNUNET_TIME_Absolute expiration, uint64_t uid) 248 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
263{ 249{
264 struct CpsRunContext *crc = cls; 250 struct CpsRunContext *crc = cls;
@@ -285,8 +271,7 @@ replication_get (void *cls,
285 (unsigned long long) (crc->end.abs_value - crc->start.abs_value), 271 (unsigned long long) (crc->end.abs_value - crc->start.abs_value),
286 bc, (unsigned int) PUT_10); 272 bc, (unsigned int) PUT_10);
287 if (crc->cnt > 0) 273 if (crc->cnt > 0)
288 GAUGER (category, 274 GAUGER (category, "Selecting random item for replication",
289 "Selecting random item for replication",
290 (crc->end.abs_value - crc->start.abs_value) / crc->cnt, 275 (crc->end.abs_value - crc->start.abs_value) / crc->cnt,
291 "ms/item"); 276 "ms/item");
292 memset (hits, 0, sizeof (hits)); 277 memset (hits, 0, sizeof (hits));
@@ -316,12 +301,12 @@ unload_plugin (struct GNUNET_DATASTORE_PluginFunctions *api,
316 char *libname; 301 char *libname;
317 302
318 if (GNUNET_OK != 303 if (GNUNET_OK !=
319 GNUNET_CONFIGURATION_get_value_string (cfg, 304 GNUNET_CONFIGURATION_get_value_string (cfg, "DATASTORE", "DATABASE",
320 "DATASTORE", "DATABASE", &name)) 305 &name))
321 { 306 {
322 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 307 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
323 _("No `%s' specified for `%s' in configuration!\n"), 308 _("No `%s' specified for `%s' in configuration!\n"), "DATABASE",
324 "DATABASE", "DATASTORE"); 309 "DATASTORE");
325 return; 310 return;
326 } 311 }
327 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); 312 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
@@ -375,13 +360,11 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
375 putValue (crc->api, j, crc->i); 360 putValue (crc->api, j, crc->i);
376 crc->end = GNUNET_TIME_absolute_get (); 361 crc->end = GNUNET_TIME_absolute_get ();
377 { 362 {
378 printf ("%s took %llu ms for %llu items\n", 363 printf ("%s took %llu ms for %llu items\n", "Storing an item",
379 "Storing an item",
380 (unsigned long long) (crc->end.abs_value - crc->start.abs_value), 364 (unsigned long long) (crc->end.abs_value - crc->start.abs_value),
381 PUT_10); 365 PUT_10);
382 if (PUT_10 > 0) 366 if (PUT_10 > 0)
383 GAUGER (category, 367 GAUGER (category, "Storing an item",
384 "Storing an item",
385 (crc->end.abs_value - crc->start.abs_value) / PUT_10, 368 (crc->end.abs_value - crc->start.abs_value) / PUT_10,
386 "ms/item"); 369 "ms/item");
387 } 370 }
@@ -394,8 +377,8 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
394 crc->api->get_replication (crc->api->cls, &replication_get, crc); 377 crc->api->get_replication (crc->api->cls, &replication_get, crc);
395 break; 378 break;
396 case RP_ZA_GET: 379 case RP_ZA_GET:
397 crc->api->get_zero_anonymity (crc->api->cls, 380 crc->api->get_zero_anonymity (crc->api->cls, crc->offset++, 1,
398 crc->offset++, 1, &iterate_zeros, crc); 381 &iterate_zeros, crc);
399 break; 382 break;
400 case RP_EXP_GET: 383 case RP_EXP_GET:
401 crc->api->get_expiration (crc->api->cls, &expiration_get, crc); 384 crc->api->get_expiration (crc->api->cls, &expiration_get, crc);
@@ -422,19 +405,19 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
422 char *libname; 405 char *libname;
423 406
424 if (GNUNET_OK != 407 if (GNUNET_OK !=
425 GNUNET_CONFIGURATION_get_value_string (cfg, 408 GNUNET_CONFIGURATION_get_value_string (cfg, "DATASTORE", "DATABASE",
426 "DATASTORE", "DATABASE", &name)) 409 &name))
427 { 410 {
428 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 411 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
429 _("No `%s' specified for `%s' in configuration!\n"), 412 _("No `%s' specified for `%s' in configuration!\n"), "DATABASE",
430 "DATABASE", "DATASTORE"); 413 "DATASTORE");
431 return NULL; 414 return NULL;
432 } 415 }
433 env.cfg = cfg; 416 env.cfg = cfg;
434 env.duc = &disk_utilization_change_cb; 417 env.duc = &disk_utilization_change_cb;
435 env.cls = NULL; 418 env.cls = NULL;
436 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 419 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' datastore plugin\n"),
437 _("Loading `%s' datastore plugin\n"), name); 420 name);
438 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); 421 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
439 if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env))) 422 if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env)))
440 { 423 {
@@ -448,9 +431,8 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
448 431
449 432
450static void 433static void
451run (void *cls, 434run (void *cls, char *const *args, const char *cfgfile,
452 char *const *args, 435 const struct GNUNET_CONFIGURATION_Handle *c)
453 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
454{ 436{
455 struct GNUNET_DATASTORE_PluginFunctions *api; 437 struct GNUNET_DATASTORE_PluginFunctions *api;
456 struct CpsRunContext *crc; 438 struct CpsRunContext *crc;
@@ -490,12 +472,10 @@ check ()
490 }; 472 };
491 473
492 GNUNET_snprintf (category, sizeof (category), "DATASTORE-%s", plugin_name); 474 GNUNET_snprintf (category, sizeof (category), "DATASTORE-%s", plugin_name);
493 GNUNET_snprintf (cfg_name, 475 GNUNET_snprintf (cfg_name, sizeof (cfg_name),
494 sizeof (cfg_name),
495 "perf_plugin_datastore_data_%s.conf", plugin_name); 476 "perf_plugin_datastore_data_%s.conf", plugin_name);
496 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 477 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
497 argv, "perf-plugin-datastore", "nohelp", 478 "perf-plugin-datastore", "nohelp", options, &run, NULL);
498 options, &run, NULL);
499 if (ok != 0) 479 if (ok != 0)
500 fprintf (stderr, "Missed some testcases: %u\n", ok); 480 fprintf (stderr, "Missed some testcases: %u\n", ok);
501 return ok; 481 return ok;
@@ -519,9 +499,8 @@ main (int argc, char *argv[])
519 else 499 else
520 pos = (char *) plugin_name; 500 pos = (char *) plugin_name;
521 501
522 GNUNET_snprintf (dir_name, 502 GNUNET_snprintf (dir_name, sizeof (dir_name), "/tmp/perf-gnunet-datastore-%s",
523 sizeof (dir_name), 503 plugin_name);
524 "/tmp/perf-gnunet-datastore-%s", plugin_name);
525 GNUNET_DISK_directory_remove (dir_name); 504 GNUNET_DISK_directory_remove (dir_name);
526 GNUNET_log_setup ("perf-plugin-datastore", 505 GNUNET_log_setup ("perf-plugin-datastore",
527#if VERBOSE 506#if VERBOSE
diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c
index a9b039981..63b065b0c 100644
--- a/src/datastore/plugin_datastore_mysql.c
+++ b/src/datastore/plugin_datastore_mysql.c
@@ -314,8 +314,8 @@ get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg)
314 314
315 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 315 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
316 _("Trying to use file `%s' for MySQL configuration.\n"), cnffile); 316 _("Trying to use file `%s' for MySQL configuration.\n"), cnffile);
317 if ((0 != STAT (cnffile, &st)) || 317 if ((0 != STAT (cnffile, &st)) || (0 != ACCESS (cnffile, R_OK)) ||
318 (0 != ACCESS (cnffile, R_OK)) || (!S_ISREG (st.st_mode))) 318 (!S_ISREG (st.st_mode)))
319 { 319 {
320 if (configured == GNUNET_YES) 320 if (configured == GNUNET_YES)
321 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 321 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -383,16 +383,16 @@ iopen (struct Plugin *plugin)
383 reconnect = 0; 383 reconnect = 0;
384 mysql_options (plugin->dbf, MYSQL_OPT_RECONNECT, &reconnect); 384 mysql_options (plugin->dbf, MYSQL_OPT_RECONNECT, &reconnect);
385 timeout = 120; /* in seconds */ 385 timeout = 120; /* in seconds */
386 mysql_options (plugin->dbf, 386 mysql_options (plugin->dbf, MYSQL_OPT_CONNECT_TIMEOUT,
387 MYSQL_OPT_CONNECT_TIMEOUT, (const void *) &timeout); 387 (const void *) &timeout);
388 mysql_options (plugin->dbf, MYSQL_SET_CHARSET_NAME, "UTF8"); 388 mysql_options (plugin->dbf, MYSQL_SET_CHARSET_NAME, "UTF8");
389 timeout = 60; /* in seconds */ 389 timeout = 60; /* in seconds */
390 mysql_options (plugin->dbf, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout); 390 mysql_options (plugin->dbf, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout);
391 mysql_options (plugin->dbf, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout); 391 mysql_options (plugin->dbf, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout);
392 mysql_dbname = NULL; 392 mysql_dbname = NULL;
393 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg, 393 if (GNUNET_YES ==
394 "datastore-mysql", 394 GNUNET_CONFIGURATION_have_value (plugin->env->cfg, "datastore-mysql",
395 "DATABASE")) 395 "DATABASE"))
396 GNUNET_assert (GNUNET_OK == 396 GNUNET_assert (GNUNET_OK ==
397 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, 397 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
398 "datastore-mysql", 398 "datastore-mysql",
@@ -401,8 +401,9 @@ iopen (struct Plugin *plugin)
401 else 401 else
402 mysql_dbname = GNUNET_strdup ("gnunet"); 402 mysql_dbname = GNUNET_strdup ("gnunet");
403 mysql_user = NULL; 403 mysql_user = NULL;
404 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg, 404 if (GNUNET_YES ==
405 "datastore-mysql", "USER")) 405 GNUNET_CONFIGURATION_have_value (plugin->env->cfg, "datastore-mysql",
406 "USER"))
406 { 407 {
407 GNUNET_assert (GNUNET_OK == 408 GNUNET_assert (GNUNET_OK ==
408 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, 409 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
@@ -410,9 +411,9 @@ iopen (struct Plugin *plugin)
410 "USER", &mysql_user)); 411 "USER", &mysql_user));
411 } 412 }
412 mysql_password = NULL; 413 mysql_password = NULL;
413 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg, 414 if (GNUNET_YES ==
414 "datastore-mysql", 415 GNUNET_CONFIGURATION_have_value (plugin->env->cfg, "datastore-mysql",
415 "PASSWORD")) 416 "PASSWORD"))
416 { 417 {
417 GNUNET_assert (GNUNET_OK == 418 GNUNET_assert (GNUNET_OK ==
418 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, 419 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
@@ -421,8 +422,9 @@ iopen (struct Plugin *plugin)
421 &mysql_password)); 422 &mysql_password));
422 } 423 }
423 mysql_server = NULL; 424 mysql_server = NULL;
424 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg, 425 if (GNUNET_YES ==
425 "datastore-mysql", "HOST")) 426 GNUNET_CONFIGURATION_have_value (plugin->env->cfg, "datastore-mysql",
427 "HOST"))
426 { 428 {
427 GNUNET_assert (GNUNET_OK == 429 GNUNET_assert (GNUNET_OK ==
428 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, 430 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
@@ -431,8 +433,9 @@ iopen (struct Plugin *plugin)
431 &mysql_server)); 433 &mysql_server));
432 } 434 }
433 mysql_port = 0; 435 mysql_port = 0;
434 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg, 436 if (GNUNET_YES ==
435 "datastore-mysql", "PORT")) 437 GNUNET_CONFIGURATION_have_value (plugin->env->cfg, "datastore-mysql",
438 "PORT"))
436 { 439 {
437 GNUNET_assert (GNUNET_OK == 440 GNUNET_assert (GNUNET_OK ==
438 GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, 441 GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg,
@@ -441,11 +444,9 @@ iopen (struct Plugin *plugin)
441 } 444 }
442 445
443 GNUNET_assert (mysql_dbname != NULL); 446 GNUNET_assert (mysql_dbname != NULL);
444 mysql_real_connect (plugin->dbf, 447 mysql_real_connect (plugin->dbf, mysql_server, mysql_user, mysql_password,
445 mysql_server, 448 mysql_dbname, (unsigned int) mysql_port, NULL,
446 mysql_user, mysql_password, 449 CLIENT_IGNORE_SIGPIPE);
447 mysql_dbname,
448 (unsigned int) mysql_port, NULL, CLIENT_IGNORE_SIGPIPE);
449 GNUNET_free_non_null (mysql_server); 450 GNUNET_free_non_null (mysql_server);
450 GNUNET_free_non_null (mysql_user); 451 GNUNET_free_non_null (mysql_user);
451 GNUNET_free_non_null (mysql_password); 452 GNUNET_free_non_null (mysql_password);
@@ -524,8 +525,7 @@ prepare_statement (struct Plugin *plugin,
524 } 525 }
525 if (mysql_stmt_prepare (ret->statement, ret->query, strlen (ret->query))) 526 if (mysql_stmt_prepare (ret->statement, ret->query, strlen (ret->query)))
526 { 527 {
527 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 528 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql",
528 "mysql",
529 _("Failed to prepare statement `%s'\n"), ret->query); 529 _("Failed to prepare statement `%s'\n"), ret->query);
530 LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_stmt_prepare", plugin); 530 LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_stmt_prepare", plugin);
531 mysql_stmt_close (ret->statement); 531 mysql_stmt_close (ret->statement);
@@ -549,8 +549,8 @@ prepare_statement (struct Plugin *plugin,
549 * @return GNUNET_SYSERR on error, GNUNET_OK on success 549 * @return GNUNET_SYSERR on error, GNUNET_OK on success
550 */ 550 */
551static int 551static int
552init_params (struct Plugin *plugin, 552init_params (struct Plugin *plugin, struct GNUNET_MysqlStatementHandle *s,
553 struct GNUNET_MysqlStatementHandle *s, va_list ap) 553 va_list ap)
554{ 554{
555 MYSQL_BIND qbind[MAX_PARAM]; 555 MYSQL_BIND qbind[MAX_PARAM];
556 unsigned int pc; 556 unsigned int pc;
@@ -611,8 +611,8 @@ init_params (struct Plugin *plugin,
611 { 611 {
612 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 612 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
613 _("`%s' failed at %s:%d with error: %s\n"), 613 _("`%s' failed at %s:%d with error: %s\n"),
614 "mysql_stmt_bind_param", 614 "mysql_stmt_bind_param", __FILE__, __LINE__,
615 __FILE__, __LINE__, mysql_stmt_error (s->statement)); 615 mysql_stmt_error (s->statement));
616 iclose (plugin); 616 iclose (plugin);
617 return GNUNET_SYSERR; 617 return GNUNET_SYSERR;
618 } 618 }
@@ -620,8 +620,8 @@ init_params (struct Plugin *plugin,
620 { 620 {
621 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 621 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
622 _("`%s' for `%s' failed at %s:%d with error: %s\n"), 622 _("`%s' for `%s' failed at %s:%d with error: %s\n"),
623 "mysql_stmt_execute", 623 "mysql_stmt_execute", s->query, __FILE__, __LINE__,
624 s->query, __FILE__, __LINE__, mysql_stmt_error (s->statement)); 624 mysql_stmt_error (s->statement));
625 iclose (plugin); 625 iclose (plugin);
626 return GNUNET_SYSERR; 626 return GNUNET_SYSERR;
627 } 627 }
@@ -671,8 +671,8 @@ prepared_statement_run_select_va (struct Plugin *plugin,
671 { 671 {
672 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 672 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
673 _("`%s' failed at %s:%d with error: %s\n"), 673 _("`%s' failed at %s:%d with error: %s\n"),
674 "mysql_stmt_bind_result", 674 "mysql_stmt_bind_result", __FILE__, __LINE__,
675 __FILE__, __LINE__, mysql_stmt_error (s->statement)); 675 mysql_stmt_error (s->statement));
676 iclose (plugin); 676 iclose (plugin);
677 return GNUNET_SYSERR; 677 return GNUNET_SYSERR;
678 } 678 }
@@ -682,8 +682,7 @@ prepared_statement_run_select_va (struct Plugin *plugin,
682 if (ret != 0) 682 if (ret != 0)
683 { 683 {
684 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 684 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
685 _("`%s' failed at %s:%d with error: %s\n"), 685 _("`%s' failed at %s:%d with error: %s\n"), "mysql_stmt_fetch",
686 "mysql_stmt_fetch",
687 __FILE__, __LINE__, mysql_stmt_error (s->statement)); 686 __FILE__, __LINE__, mysql_stmt_error (s->statement));
688 iclose (plugin); 687 iclose (plugin);
689 return GNUNET_SYSERR; 688 return GNUNET_SYSERR;
@@ -710,8 +709,8 @@ prepared_statement_run_select_va (struct Plugin *plugin,
710static int 709static int
711prepared_statement_run_select (struct Plugin *plugin, 710prepared_statement_run_select (struct Plugin *plugin,
712 struct GNUNET_MysqlStatementHandle *s, 711 struct GNUNET_MysqlStatementHandle *s,
713 unsigned int result_size, 712 unsigned int result_size, MYSQL_BIND * results,
714 MYSQL_BIND * results, ...) 713 ...)
715{ 714{
716 va_list ap; 715 va_list ap;
717 int ret; 716 int ret;
@@ -774,13 +773,12 @@ do_delete_entry (struct Plugin *plugin, unsigned long long uid)
774 int ret; 773 int ret;
775 774
776#if DEBUG_MYSQL 775#if DEBUG_MYSQL
777 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 776 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting value %llu from gn090 table\n",
778 "Deleting value %llu from gn090 table\n", uid); 777 uid);
779#endif 778#endif
780 ret = prepared_statement_run (plugin, 779 ret =
781 plugin->delete_entry_by_uid, 780 prepared_statement_run (plugin, plugin->delete_entry_by_uid, NULL,
782 NULL, 781 MYSQL_TYPE_LONGLONG, &uid, GNUNET_YES, -1);
783 MYSQL_TYPE_LONGLONG, &uid, GNUNET_YES, -1);
784 if (ret >= 0) 782 if (ret >= 0)
785 return GNUNET_OK; 783 return GNUNET_OK;
786 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 784 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -831,14 +829,9 @@ mysql_plugin_estimate_size (void *cls)
831 * @return GNUNET_OK on success 829 * @return GNUNET_OK on success
832 */ 830 */
833static int 831static int
834mysql_plugin_put (void *cls, 832mysql_plugin_put (void *cls, const GNUNET_HashCode * key, uint32_t size,
835 const GNUNET_HashCode * key, 833 const void *data, enum GNUNET_BLOCK_Type type,
836 uint32_t size, 834 uint32_t priority, uint32_t anonymity, uint32_t replication,
837 const void *data,
838 enum GNUNET_BLOCK_Type type,
839 uint32_t priority,
840 uint32_t anonymity,
841 uint32_t replication,
842 struct GNUNET_TIME_Absolute expiration, char **msg) 835 struct GNUNET_TIME_Absolute expiration, char **msg)
843{ 836{
844 struct Plugin *plugin = cls; 837 struct Plugin *plugin = cls;
@@ -864,9 +857,7 @@ mysql_plugin_put (void *cls,
864 lsize = size; 857 lsize = size;
865 GNUNET_CRYPTO_hash (data, size, &vhash); 858 GNUNET_CRYPTO_hash (data, size, &vhash);
866 if (GNUNET_OK != 859 if (GNUNET_OK !=
867 prepared_statement_run (plugin, 860 prepared_statement_run (plugin, plugin->insert_entry, NULL,
868 plugin->insert_entry,
869 NULL,
870 MYSQL_TYPE_LONG, &irepl, GNUNET_YES, 861 MYSQL_TYPE_LONG, &irepl, GNUNET_YES,
871 MYSQL_TYPE_LONG, &type, GNUNET_YES, 862 MYSQL_TYPE_LONG, &type, GNUNET_YES,
872 MYSQL_TYPE_LONG, &ipriority, GNUNET_YES, 863 MYSQL_TYPE_LONG, &ipriority, GNUNET_YES,
@@ -912,9 +903,8 @@ mysql_plugin_put (void *cls,
912 * @return GNUNET_OK on success 903 * @return GNUNET_OK on success
913 */ 904 */
914static int 905static int
915mysql_plugin_update (void *cls, 906mysql_plugin_update (void *cls, uint64_t uid, int delta,
916 uint64_t uid, 907 struct GNUNET_TIME_Absolute expire, char **msg)
917 int delta, struct GNUNET_TIME_Absolute expire, char **msg)
918{ 908{
919 struct Plugin *plugin = cls; 909 struct Plugin *plugin = cls;
920 unsigned long long vkey = uid; 910 unsigned long long vkey = uid;
@@ -926,17 +916,16 @@ mysql_plugin_update (void *cls,
926 "Updating value %llu adding %d to priority and maxing exp at %llu\n", 916 "Updating value %llu adding %d to priority and maxing exp at %llu\n",
927 vkey, delta, lexpire); 917 vkey, delta, lexpire);
928#endif 918#endif
929 ret = prepared_statement_run (plugin, 919 ret =
930 plugin->update_entry, 920 prepared_statement_run (plugin, plugin->update_entry, NULL,
931 NULL, 921 MYSQL_TYPE_LONG, &delta, GNUNET_NO,
932 MYSQL_TYPE_LONG, &delta, GNUNET_NO, 922 MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES,
933 MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES, 923 MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES,
934 MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES, 924 MYSQL_TYPE_LONGLONG, &vkey, GNUNET_YES, -1);
935 MYSQL_TYPE_LONGLONG, &vkey, GNUNET_YES, -1);
936 if (ret != GNUNET_OK) 925 if (ret != GNUNET_OK)
937 { 926 {
938 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 927 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to update value %llu\n",
939 "Failed to update value %llu\n", vkey); 928 vkey);
940 } 929 }
941 return ret; 930 return ret;
942} 931}
@@ -953,8 +942,7 @@ mysql_plugin_update (void *cls,
953 * @param ... arguments to initialize stmt 942 * @param ... arguments to initialize stmt
954 */ 943 */
955static void 944static void
956execute_select (struct Plugin *plugin, 945execute_select (struct Plugin *plugin, struct GNUNET_MysqlStatementHandle *stmt,
957 struct GNUNET_MysqlStatementHandle *stmt,
958 PluginDatumProcessor proc, void *proc_cls, ...) 946 PluginDatumProcessor proc, void *proc_cls, ...)
959{ 947{
960 va_list ap; 948 va_list ap;
@@ -1020,8 +1008,9 @@ execute_select (struct Plugin *plugin,
1020#endif 1008#endif
1021 GNUNET_assert (size < MAX_DATUM_SIZE); 1009 GNUNET_assert (size < MAX_DATUM_SIZE);
1022 expiration.abs_value = exp; 1010 expiration.abs_value = exp;
1023 ret = proc (proc_cls, 1011 ret =
1024 &key, size, value, type, priority, anonymity, expiration, uid); 1012 proc (proc_cls, &key, size, value, type, priority, anonymity, expiration,
1013 uid);
1025 if (ret == GNUNET_NO) 1014 if (ret == GNUNET_NO)
1026 { 1015 {
1027 do_delete_entry (plugin, uid); 1016 do_delete_entry (plugin, uid);
@@ -1051,12 +1040,10 @@ execute_select (struct Plugin *plugin,
1051 * @param proc_cls closure for proc 1040 * @param proc_cls closure for proc
1052 */ 1041 */
1053static void 1042static void
1054mysql_plugin_get_key (void *cls, 1043mysql_plugin_get_key (void *cls, uint64_t offset, const GNUNET_HashCode * key,
1055 uint64_t offset,
1056 const GNUNET_HashCode * key,
1057 const GNUNET_HashCode * vhash, 1044 const GNUNET_HashCode * vhash,
1058 enum GNUNET_BLOCK_Type type, 1045 enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc,
1059 PluginDatumProcessor proc, void *proc_cls) 1046 void *proc_cls)
1060{ 1047{
1061 struct Plugin *plugin = cls; 1048 struct Plugin *plugin = cls;
1062 int ret; 1049 int ret;
@@ -1081,22 +1068,21 @@ mysql_plugin_get_key (void *cls,
1081 { 1068 {
1082 ret = 1069 ret =
1083 prepared_statement_run_select (plugin, 1070 prepared_statement_run_select (plugin,
1084 plugin-> 1071 plugin->count_entry_by_hash_vhash_and_type,
1085 count_entry_by_hash_vhash_and_type, 1, 1072 1, cbind, MYSQL_TYPE_BLOB, key,
1086 cbind, MYSQL_TYPE_BLOB, key, hashSize, 1073 hashSize, &hashSize, MYSQL_TYPE_BLOB,
1087 &hashSize, MYSQL_TYPE_BLOB, vhash, 1074 vhash, hashSize2, &hashSize2,
1088 hashSize2, &hashSize2, MYSQL_TYPE_LONG, 1075 MYSQL_TYPE_LONG, &type, GNUNET_YES,
1089 &type, GNUNET_YES, -1); 1076 -1);
1090 } 1077 }
1091 else 1078 else
1092 { 1079 {
1093 ret = 1080 ret =
1094 prepared_statement_run_select (plugin, 1081 prepared_statement_run_select (plugin,
1095 plugin->count_entry_by_hash_and_type, 1082 plugin->count_entry_by_hash_and_type,
1096 1, cbind, 1083 1, cbind, MYSQL_TYPE_BLOB, key,
1097 MYSQL_TYPE_BLOB, key, hashSize, 1084 hashSize, &hashSize, MYSQL_TYPE_LONG,
1098 &hashSize, MYSQL_TYPE_LONG, &type, 1085 &type, GNUNET_YES, -1);
1099 GNUNET_YES, -1);
1100 } 1086 }
1101 } 1087 }
1102 else 1088 else
@@ -1106,19 +1092,16 @@ mysql_plugin_get_key (void *cls,
1106 ret = 1092 ret =
1107 prepared_statement_run_select (plugin, 1093 prepared_statement_run_select (plugin,
1108 plugin->count_entry_by_hash_and_vhash, 1094 plugin->count_entry_by_hash_and_vhash,
1109 1, cbind, 1095 1, cbind, MYSQL_TYPE_BLOB, key,
1110 MYSQL_TYPE_BLOB, key, hashSize, 1096 hashSize, &hashSize, MYSQL_TYPE_BLOB,
1111 &hashSize, MYSQL_TYPE_BLOB, vhash, 1097 vhash, hashSize2, &hashSize2, -1);
1112 hashSize2, &hashSize2, -1);
1113 1098
1114 } 1099 }
1115 else 1100 else
1116 { 1101 {
1117 ret = 1102 ret =
1118 prepared_statement_run_select (plugin, 1103 prepared_statement_run_select (plugin, plugin->count_entry_by_hash, 1,
1119 plugin->count_entry_by_hash, 1104 cbind, MYSQL_TYPE_BLOB, key, hashSize,
1120 1, cbind,
1121 MYSQL_TYPE_BLOB, key, hashSize,
1122 &hashSize, -1); 1105 &hashSize, -1);
1123 } 1106 }
1124 } 1107 }
@@ -1131,48 +1114,40 @@ mysql_plugin_get_key (void *cls,
1131 off = (unsigned long long) offset; 1114 off = (unsigned long long) offset;
1132#if DEBUG_MYSQL 1115#if DEBUG_MYSQL
1133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1134 "Obtaining %llu/%lld result for GET `%s'\n", 1117 "Obtaining %llu/%lld result for GET `%s'\n", off, total,
1135 off, total, GNUNET_h2s (key)); 1118 GNUNET_h2s (key));
1136#endif 1119#endif
1137 1120
1138 if (type != GNUNET_BLOCK_TYPE_ANY) 1121 if (type != GNUNET_BLOCK_TYPE_ANY)
1139 { 1122 {
1140 if (NULL != vhash) 1123 if (NULL != vhash)
1141 { 1124 {
1142 execute_select (plugin, 1125 execute_select (plugin, plugin->select_entry_by_hash_vhash_and_type, proc,
1143 plugin->select_entry_by_hash_vhash_and_type, 1126 proc_cls, MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
1144 proc, proc_cls,
1145 MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
1146 MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize, 1127 MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize,
1147 MYSQL_TYPE_LONG, &type, GNUNET_YES, 1128 MYSQL_TYPE_LONG, &type, GNUNET_YES, MYSQL_TYPE_LONGLONG,
1148 MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1); 1129 &off, GNUNET_YES, -1);
1149 } 1130 }
1150 else 1131 else
1151 { 1132 {
1152 execute_select (plugin, 1133 execute_select (plugin, plugin->select_entry_by_hash_and_type, proc,
1153 plugin->select_entry_by_hash_and_type, 1134 proc_cls, MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
1154 proc, proc_cls, 1135 MYSQL_TYPE_LONG, &type, GNUNET_YES, MYSQL_TYPE_LONGLONG,
1155 MYSQL_TYPE_BLOB, key, hashSize, &hashSize, 1136 &off, GNUNET_YES, -1);
1156 MYSQL_TYPE_LONG, &type, GNUNET_YES,
1157 MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1);
1158 } 1137 }
1159 } 1138 }
1160 else 1139 else
1161 { 1140 {
1162 if (NULL != vhash) 1141 if (NULL != vhash)
1163 { 1142 {
1164 execute_select (plugin, 1143 execute_select (plugin, plugin->select_entry_by_hash_and_vhash, proc,
1165 plugin->select_entry_by_hash_and_vhash, 1144 proc_cls, MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
1166 proc, proc_cls,
1167 MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
1168 MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize, 1145 MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize,
1169 MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1); 1146 MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1);
1170 } 1147 }
1171 else 1148 else
1172 { 1149 {
1173 execute_select (plugin, 1150 execute_select (plugin, plugin->select_entry_by_hash, proc, proc_cls,
1174 plugin->select_entry_by_hash,
1175 proc, proc_cls,
1176 MYSQL_TYPE_BLOB, key, hashSize, &hashSize, 1151 MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
1177 MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1); 1152 MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1);
1178 } 1153 }
@@ -1191,8 +1166,7 @@ mysql_plugin_get_key (void *cls,
1191 * @param proc_cls closure for iter 1166 * @param proc_cls closure for iter
1192 */ 1167 */
1193static void 1168static void
1194mysql_plugin_get_zero_anonymity (void *cls, 1169mysql_plugin_get_zero_anonymity (void *cls, uint64_t offset,
1195 uint64_t offset,
1196 enum GNUNET_BLOCK_Type type, 1170 enum GNUNET_BLOCK_Type type,
1197 PluginDatumProcessor proc, void *proc_cls) 1171 PluginDatumProcessor proc, void *proc_cls)
1198{ 1172{
@@ -1201,13 +1175,10 @@ mysql_plugin_get_zero_anonymity (void *cls,
1201 (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 1175 (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
1202 UINT64_MAX); 1176 UINT64_MAX);
1203 1177
1204 execute_select (plugin, 1178 execute_select (plugin, plugin->zero_iter, proc, proc_cls, MYSQL_TYPE_LONG,
1205 plugin->zero_iter, 1179 &type, GNUNET_YES, MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES,
1206 proc, proc_cls, 1180 MYSQL_TYPE_LONG, &type, GNUNET_YES, MYSQL_TYPE_LONGLONG,
1207 MYSQL_TYPE_LONG, &type, GNUNET_YES, 1181 &rvalue, GNUNET_YES, -1);
1208 MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES,
1209 MYSQL_TYPE_LONG, &type, GNUNET_YES,
1210 MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES, -1);
1211} 1182}
1212 1183
1213 1184
@@ -1255,14 +1226,10 @@ struct ReplCtx
1255 * GNUNET_NO to delete the item and continue (if supported) 1226 * GNUNET_NO to delete the item and continue (if supported)
1256 */ 1227 */
1257static int 1228static int
1258repl_proc (void *cls, 1229repl_proc (void *cls, const GNUNET_HashCode * key, uint32_t size,
1259 const GNUNET_HashCode * key, 1230 const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority,
1260 uint32_t size, 1231 uint32_t anonymity, struct GNUNET_TIME_Absolute expiration,
1261 const void *data, 1232 uint64_t uid)
1262 enum GNUNET_BLOCK_Type type,
1263 uint32_t priority,
1264 uint32_t anonymity,
1265 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
1266{ 1233{
1267 struct ReplCtx *rc = cls; 1234 struct ReplCtx *rc = cls;
1268 struct Plugin *plugin = rc->plugin; 1235 struct Plugin *plugin = rc->plugin;
@@ -1270,15 +1237,15 @@ repl_proc (void *cls,
1270 int ret; 1237 int ret;
1271 int iret; 1238 int iret;
1272 1239
1273 ret = rc->proc (rc->proc_cls, 1240 ret =
1274 key, size, data, type, priority, anonymity, expiration, uid); 1241 rc->proc (rc->proc_cls, key, size, data, type, priority, anonymity,
1242 expiration, uid);
1275 if (NULL != key) 1243 if (NULL != key)
1276 { 1244 {
1277 oid = (unsigned long long) uid; 1245 oid = (unsigned long long) uid;
1278 iret = prepared_statement_run (plugin, 1246 iret =
1279 plugin->dec_repl, 1247 prepared_statement_run (plugin, plugin->dec_repl, NULL,
1280 NULL, 1248 MYSQL_TYPE_LONGLONG, &oid, GNUNET_YES, -1);
1281 MYSQL_TYPE_LONGLONG, &oid, GNUNET_YES, -1);
1282 if (iret == GNUNET_SYSERR) 1249 if (iret == GNUNET_SYSERR)
1283 { 1250 {
1284 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1251 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -1302,8 +1269,8 @@ repl_proc (void *cls,
1302 * @param proc_cls closure for proc 1269 * @param proc_cls closure for proc
1303 */ 1270 */
1304static void 1271static void
1305mysql_plugin_get_replication (void *cls, 1272mysql_plugin_get_replication (void *cls, PluginDatumProcessor proc,
1306 PluginDatumProcessor proc, void *proc_cls) 1273 void *proc_cls)
1307{ 1274{
1308 struct Plugin *plugin = cls; 1275 struct Plugin *plugin = cls;
1309 struct ReplCtx rc; 1276 struct ReplCtx rc;
@@ -1382,26 +1349,22 @@ struct ExpiCtx
1382 * GNUNET_NO to delete the item and continue (if supported) 1349 * GNUNET_NO to delete the item and continue (if supported)
1383 */ 1350 */
1384static int 1351static int
1385expi_proc (void *cls, 1352expi_proc (void *cls, const GNUNET_HashCode * key, uint32_t size,
1386 const GNUNET_HashCode * key, 1353 const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority,
1387 uint32_t size, 1354 uint32_t anonymity, struct GNUNET_TIME_Absolute expiration,
1388 const void *data, 1355 uint64_t uid)
1389 enum GNUNET_BLOCK_Type type,
1390 uint32_t priority,
1391 uint32_t anonymity,
1392 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
1393{ 1356{
1394 struct ExpiCtx *rc = cls; 1357 struct ExpiCtx *rc = cls;
1395 struct Plugin *plugin = rc->plugin; 1358 struct Plugin *plugin = rc->plugin;
1396 1359
1397 if (NULL == key) 1360 if (NULL == key)
1398 { 1361 {
1399 execute_select (plugin, 1362 execute_select (plugin, plugin->select_priority, rc->proc, rc->proc_cls,
1400 plugin->select_priority, rc->proc, rc->proc_cls, -1); 1363 -1);
1401 return GNUNET_SYSERR; 1364 return GNUNET_SYSERR;
1402 } 1365 }
1403 return rc->proc (rc->proc_cls, 1366 return rc->proc (rc->proc_cls, key, size, data, type, priority, anonymity,
1404 key, size, data, type, priority, anonymity, expiration, uid); 1367 expiration, uid);
1405} 1368}
1406 1369
1407 1370
@@ -1414,8 +1377,8 @@ expi_proc (void *cls,
1414 * @param proc_cls closure for proc 1377 * @param proc_cls closure for proc
1415 */ 1378 */
1416static void 1379static void
1417mysql_plugin_get_expiration (void *cls, 1380mysql_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
1418 PluginDatumProcessor proc, void *proc_cls) 1381 void *proc_cls)
1419{ 1382{
1420 struct Plugin *plugin = cls; 1383 struct Plugin *plugin = cls;
1421 long long nt; 1384 long long nt;
@@ -1425,9 +1388,8 @@ mysql_plugin_get_expiration (void *cls,
1425 rc.proc = proc; 1388 rc.proc = proc;
1426 rc.proc_cls = proc_cls; 1389 rc.proc_cls = proc_cls;
1427 nt = (long long) GNUNET_TIME_absolute_get ().abs_value; 1390 nt = (long long) GNUNET_TIME_absolute_get ().abs_value;
1428 execute_select (plugin, 1391 execute_select (plugin, plugin->select_expiration, expi_proc, &rc,
1429 plugin->select_expiration, 1392 MYSQL_TYPE_LONGLONG, &nt, GNUNET_YES, -1);
1430 expi_proc, &rc, MYSQL_TYPE_LONGLONG, &nt, GNUNET_YES, -1);
1431 1393
1432} 1394}
1433 1395
@@ -1473,28 +1435,25 @@ libgnunet_plugin_datastore_mysql_init (void *cls)
1473 } 1435 }
1474#define MRUNS(a) (GNUNET_OK != run_statement (plugin, a) ) 1436#define MRUNS(a) (GNUNET_OK != run_statement (plugin, a) )
1475#define PINIT(a,b) (NULL == (a = prepared_statement_create(plugin, b))) 1437#define PINIT(a,b) (NULL == (a = prepared_statement_create(plugin, b)))
1476 if (MRUNS ("CREATE TABLE IF NOT EXISTS gn090 (" 1438 if (MRUNS
1477 " repl INT(11) UNSIGNED NOT NULL DEFAULT 0," 1439 ("CREATE TABLE IF NOT EXISTS gn090 ("
1478 " type INT(11) UNSIGNED NOT NULL DEFAULT 0," 1440 " repl INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1479 " prio INT(11) UNSIGNED NOT NULL DEFAULT 0," 1441 " type INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1480 " anonLevel INT(11) UNSIGNED NOT NULL DEFAULT 0," 1442 " prio INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1481 " expire BIGINT UNSIGNED NOT NULL DEFAULT 0," 1443 " anonLevel INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1482 " rvalue BIGINT UNSIGNED NOT NULL," 1444 " expire BIGINT UNSIGNED NOT NULL DEFAULT 0,"
1483 " hash BINARY(64) NOT NULL DEFAULT ''," 1445 " rvalue BIGINT UNSIGNED NOT NULL,"
1484 " vhash BINARY(64) NOT NULL DEFAULT ''," 1446 " hash BINARY(64) NOT NULL DEFAULT '',"
1485 " value BLOB NOT NULL DEFAULT ''," 1447 " vhash BINARY(64) NOT NULL DEFAULT '',"
1486 " uid BIGINT NOT NULL AUTO_INCREMENT," 1448 " value BLOB NOT NULL DEFAULT ''," " uid BIGINT NOT NULL AUTO_INCREMENT,"
1487 " PRIMARY KEY (uid)," 1449 " PRIMARY KEY (uid)," " INDEX idx_hash (hash(64)),"
1488 " INDEX idx_hash (hash(64))," 1450 " INDEX idx_hash_uid (hash(64),uid),"
1489 " INDEX idx_hash_uid (hash(64),uid)," 1451 " INDEX idx_hash_vhash (hash(64),vhash(64)),"
1490 " INDEX idx_hash_vhash (hash(64),vhash(64))," 1452 " INDEX idx_hash_type_uid (hash(64),type,rvalue),"
1491 " INDEX idx_hash_type_uid (hash(64),type,rvalue)," 1453 " INDEX idx_prio (prio)," " INDEX idx_repl_rvalue (repl,rvalue),"
1492 " INDEX idx_prio (prio)," 1454 " INDEX idx_expire (expire),"
1493 " INDEX idx_repl_rvalue (repl,rvalue)," 1455 " INDEX idx_anonLevel_type_rvalue (anonLevel,type,rvalue)"
1494 " INDEX idx_expire (expire)," 1456 ") ENGINE=InnoDB") || MRUNS ("SET AUTOCOMMIT = 1") ||
1495 " INDEX idx_anonLevel_type_rvalue (anonLevel,type,rvalue)"
1496 ") ENGINE=InnoDB") ||
1497 MRUNS ("SET AUTOCOMMIT = 1") ||
1498 PINIT (plugin->insert_entry, INSERT_ENTRY) || 1457 PINIT (plugin->insert_entry, INSERT_ENTRY) ||
1499 PINIT (plugin->delete_entry_by_uid, DELETE_ENTRY_BY_UID) || 1458 PINIT (plugin->delete_entry_by_uid, DELETE_ENTRY_BY_UID) ||
1500 PINIT (plugin->select_entry_by_hash, SELECT_ENTRY_BY_HASH) || 1459 PINIT (plugin->select_entry_by_hash, SELECT_ENTRY_BY_HASH) ||
@@ -1537,8 +1496,8 @@ libgnunet_plugin_datastore_mysql_init (void *cls)
1537 api->get_expiration = &mysql_plugin_get_expiration; 1496 api->get_expiration = &mysql_plugin_get_expiration;
1538 api->get_zero_anonymity = &mysql_plugin_get_zero_anonymity; 1497 api->get_zero_anonymity = &mysql_plugin_get_zero_anonymity;
1539 api->drop = &mysql_plugin_drop; 1498 api->drop = &mysql_plugin_drop;
1540 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, 1499 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "mysql",
1541 "mysql", _("Mysql database running\n")); 1500 _("Mysql database running\n"));
1542 return api; 1501 return api;
1543} 1502}
1544 1503
diff --git a/src/datastore/plugin_datastore_postgres.c b/src/datastore/plugin_datastore_postgres.c
index b79178dac..d71d5e0ef 100644
--- a/src/datastore/plugin_datastore_postgres.c
+++ b/src/datastore/plugin_datastore_postgres.c
@@ -75,9 +75,7 @@ struct Plugin
75 * @return GNUNET_OK if the result is acceptable 75 * @return GNUNET_OK if the result is acceptable
76 */ 76 */
77static int 77static int
78check_result (struct Plugin *plugin, 78check_result (struct Plugin *plugin, PGresult * ret, int expected_status,
79 PGresult * ret,
80 int expected_status,
81 const char *command, const char *args, int line) 79 const char *command, const char *args, int line)
82{ 80{
83 if (ret == NULL) 81 if (ret == NULL)
@@ -92,9 +90,8 @@ check_result (struct Plugin *plugin,
92 { 90 {
93 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 91 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
94 "datastore-postgres", 92 "datastore-postgres",
95 _("`%s:%s' failed at %s:%d with error: %s"), 93 _("`%s:%s' failed at %s:%d with error: %s"), command, args,
96 command, args, __FILE__, line, 94 __FILE__, line, PQerrorMessage (plugin->dbh));
97 PQerrorMessage (plugin->dbh));
98 PQclear (ret); 95 PQclear (ret);
99 return GNUNET_SYSERR; 96 return GNUNET_SYSERR;
100 } 97 }
@@ -114,8 +111,8 @@ pq_exec (struct Plugin *plugin, const char *sql, int line)
114 PGresult *ret; 111 PGresult *ret;
115 112
116 ret = PQexec (plugin->dbh, sql); 113 ret = PQexec (plugin->dbh, sql);
117 if (GNUNET_OK != check_result (plugin, 114 if (GNUNET_OK !=
118 ret, PGRES_COMMAND_OK, "PQexec", sql, line)) 115 check_result (plugin, ret, PGRES_COMMAND_OK, "PQexec", sql, line))
119 return GNUNET_SYSERR; 116 return GNUNET_SYSERR;
120 PQclear (ret); 117 PQclear (ret);
121 return GNUNET_OK; 118 return GNUNET_OK;
@@ -132,8 +129,8 @@ pq_exec (struct Plugin *plugin, const char *sql, int line)
132 * @return GNUNET_OK on success 129 * @return GNUNET_OK on success
133 */ 130 */
134static int 131static int
135pq_prepare (struct Plugin *plugin, 132pq_prepare (struct Plugin *plugin, const char *name, const char *sql,
136 const char *name, const char *sql, int nparams, int line) 133 int nparams, int line)
137{ 134{
138 PGresult *ret; 135 PGresult *ret;
139 136
@@ -160,8 +157,8 @@ init_connection (struct Plugin *plugin)
160 /* Open database and precompile statements */ 157 /* Open database and precompile statements */
161 conninfo = NULL; 158 conninfo = NULL;
162 (void) GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, 159 (void) GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
163 "datastore-postgres", 160 "datastore-postgres", "CONFIG",
164 "CONFIG", &conninfo); 161 &conninfo);
165 plugin->dbh = PQconnectdb (conninfo == NULL ? "" : conninfo); 162 plugin->dbh = PQconnectdb (conninfo == NULL ? "" : conninfo);
166 if (NULL == plugin->dbh) 163 if (NULL == plugin->dbh)
167 { 164 {
@@ -171,8 +168,7 @@ init_connection (struct Plugin *plugin)
171 } 168 }
172 if (PQstatus (plugin->dbh) != CONNECTION_OK) 169 if (PQstatus (plugin->dbh) != CONNECTION_OK)
173 { 170 {
174 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 171 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "datastore-postgres",
175 "datastore-postgres",
176 _ 172 _
177 ("Unable to initialize Postgres with configuration `%s': %s"), 173 ("Unable to initialize Postgres with configuration `%s': %s"),
178 conninfo, PQerrorMessage (plugin->dbh)); 174 conninfo, PQerrorMessage (plugin->dbh));
@@ -182,24 +178,23 @@ init_connection (struct Plugin *plugin)
182 return GNUNET_SYSERR; 178 return GNUNET_SYSERR;
183 } 179 }
184 GNUNET_free_non_null (conninfo); 180 GNUNET_free_non_null (conninfo);
185 ret = PQexec (plugin->dbh, 181 ret =
186 "CREATE TABLE gn090 (" 182 PQexec (plugin->dbh,
187 " repl INTEGER NOT NULL DEFAULT 0," 183 "CREATE TABLE gn090 (" " repl INTEGER NOT NULL DEFAULT 0,"
188 " type INTEGER NOT NULL DEFAULT 0," 184 " type INTEGER NOT NULL DEFAULT 0,"
189 " prio INTEGER NOT NULL DEFAULT 0," 185 " prio INTEGER NOT NULL DEFAULT 0,"
190 " anonLevel INTEGER NOT NULL DEFAULT 0," 186 " anonLevel INTEGER NOT NULL DEFAULT 0,"
191 " expire BIGINT NOT NULL DEFAULT 0," 187 " expire BIGINT NOT NULL DEFAULT 0,"
192 " rvalue BIGINT NOT NULL DEFAULT 0," 188 " rvalue BIGINT NOT NULL DEFAULT 0,"
193 " hash BYTEA NOT NULL DEFAULT ''," 189 " hash BYTEA NOT NULL DEFAULT '',"
194 " vhash BYTEA NOT NULL DEFAULT ''," 190 " vhash BYTEA NOT NULL DEFAULT '',"
195 " value BYTEA NOT NULL DEFAULT '')" "WITH OIDS"); 191 " value BYTEA NOT NULL DEFAULT '')" "WITH OIDS");
196 if ((ret == NULL) || ((PQresultStatus (ret) != PGRES_COMMAND_OK) && (0 != strcmp ("42P07", /* duplicate table */ 192 if ((ret == NULL) || ((PQresultStatus (ret) != PGRES_COMMAND_OK) && (0 != strcmp ("42P07", /* duplicate table */
197 PQresultErrorField 193 PQresultErrorField
198 (ret, 194 (ret,
199 PG_DIAG_SQLSTATE))))) 195 PG_DIAG_SQLSTATE)))))
200 { 196 {
201 (void) check_result (plugin, 197 (void) check_result (plugin, ret, PGRES_COMMAND_OK, "CREATE TABLE", "gn090",
202 ret, PGRES_COMMAND_OK, "CREATE TABLE", "gn090",
203 __LINE__); 198 __LINE__);
204 PQfinish (plugin->dbh); 199 PQfinish (plugin->dbh);
205 plugin->dbh = NULL; 200 plugin->dbh = NULL;
@@ -211,12 +206,12 @@ init_connection (struct Plugin *plugin)
211 pq_exec (plugin, "CREATE INDEX idx_hash ON gn090 (hash)", __LINE__)) || 206 pq_exec (plugin, "CREATE INDEX idx_hash ON gn090 (hash)", __LINE__)) ||
212 (GNUNET_OK != 207 (GNUNET_OK !=
213 pq_exec (plugin, "CREATE INDEX idx_hash_vhash ON gn090 (hash,vhash)", 208 pq_exec (plugin, "CREATE INDEX idx_hash_vhash ON gn090 (hash,vhash)",
214 __LINE__)) 209 __LINE__)) ||
215 || (GNUNET_OK != 210 (GNUNET_OK !=
216 pq_exec (plugin, "CREATE INDEX idx_prio ON gn090 (prio)", __LINE__)) 211 pq_exec (plugin, "CREATE INDEX idx_prio ON gn090 (prio)", __LINE__)) ||
217 || (GNUNET_OK != 212 (GNUNET_OK !=
218 pq_exec (plugin, "CREATE INDEX idx_expire ON gn090 (expire)", 213 pq_exec (plugin, "CREATE INDEX idx_expire ON gn090 (expire)",
219 __LINE__)) || 214 __LINE__)) ||
220 (GNUNET_OK != 215 (GNUNET_OK !=
221 pq_exec (plugin, 216 pq_exec (plugin,
222 "CREATE INDEX idx_prio_anon ON gn090 (prio,anonLevel)", 217 "CREATE INDEX idx_prio_anon ON gn090 (prio,anonLevel)",
@@ -239,11 +234,12 @@ init_connection (struct Plugin *plugin)
239 } 234 }
240 } 235 }
241 PQclear (ret); 236 PQclear (ret);
242 ret = PQexec (plugin->dbh, 237 ret =
243 "ALTER TABLE gn090 ALTER value SET STORAGE EXTERNAL"); 238 PQexec (plugin->dbh,
239 "ALTER TABLE gn090 ALTER value SET STORAGE EXTERNAL");
244 if (GNUNET_OK != 240 if (GNUNET_OK !=
245 check_result (plugin, 241 check_result (plugin, ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090",
246 ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090", __LINE__)) 242 __LINE__))
247 { 243 {
248 PQfinish (plugin->dbh); 244 PQfinish (plugin->dbh);
249 plugin->dbh = NULL; 245 plugin->dbh = NULL;
@@ -252,8 +248,8 @@ init_connection (struct Plugin *plugin)
252 PQclear (ret); 248 PQclear (ret);
253 ret = PQexec (plugin->dbh, "ALTER TABLE gn090 ALTER hash SET STORAGE PLAIN"); 249 ret = PQexec (plugin->dbh, "ALTER TABLE gn090 ALTER hash SET STORAGE PLAIN");
254 if (GNUNET_OK != 250 if (GNUNET_OK !=
255 check_result (plugin, 251 check_result (plugin, ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090",
256 ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090", __LINE__)) 252 __LINE__))
257 { 253 {
258 PQfinish (plugin->dbh); 254 PQfinish (plugin->dbh);
259 plugin->dbh = NULL; 255 plugin->dbh = NULL;
@@ -262,8 +258,8 @@ init_connection (struct Plugin *plugin)
262 PQclear (ret); 258 PQclear (ret);
263 ret = PQexec (plugin->dbh, "ALTER TABLE gn090 ALTER vhash SET STORAGE PLAIN"); 259 ret = PQexec (plugin->dbh, "ALTER TABLE gn090 ALTER vhash SET STORAGE PLAIN");
264 if (GNUNET_OK != 260 if (GNUNET_OK !=
265 check_result (plugin, 261 check_result (plugin, ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090",
266 ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090", __LINE__)) 262 __LINE__))
267 { 263 {
268 PQfinish (plugin->dbh); 264 PQfinish (plugin->dbh);
269 plugin->dbh = NULL; 265 plugin->dbh = NULL;
@@ -271,86 +267,57 @@ init_connection (struct Plugin *plugin)
271 } 267 }
272 PQclear (ret); 268 PQclear (ret);
273 if ((GNUNET_OK != 269 if ((GNUNET_OK !=
274 pq_prepare (plugin, 270 pq_prepare (plugin, "getvt",
275 "getvt",
276 "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 " 271 "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 "
277 "WHERE hash=$1 AND vhash=$2 AND type=$3 " 272 "WHERE hash=$1 AND vhash=$2 AND type=$3 "
278 "ORDER BY oid ASC LIMIT 1 OFFSET $4", 273 "ORDER BY oid ASC LIMIT 1 OFFSET $4", 4, __LINE__)) ||
279 4,
280 __LINE__)) ||
281 (GNUNET_OK != 274 (GNUNET_OK !=
282 pq_prepare (plugin, 275 pq_prepare (plugin, "gett",
283 "gett",
284 "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 " 276 "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 "
285 "WHERE hash=$1 AND type=$2 " 277 "WHERE hash=$1 AND type=$2 "
286 "ORDER BY oid ASC LIMIT 1 OFFSET $3", 278 "ORDER BY oid ASC LIMIT 1 OFFSET $3", 3, __LINE__)) ||
287 3,
288 __LINE__)) ||
289 (GNUNET_OK != 279 (GNUNET_OK !=
290 pq_prepare (plugin, 280 pq_prepare (plugin, "getv",
291 "getv",
292 "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 " 281 "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 "
293 "WHERE hash=$1 AND vhash=$2 " 282 "WHERE hash=$1 AND vhash=$2 "
294 "ORDER BY oid ASC LIMIT 1 OFFSET $3", 283 "ORDER BY oid ASC LIMIT 1 OFFSET $3", 3, __LINE__)) ||
295 3,
296 __LINE__)) ||
297 (GNUNET_OK != 284 (GNUNET_OK !=
298 pq_prepare (plugin, 285 pq_prepare (plugin, "get",
299 "get",
300 "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 " 286 "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 "
301 "WHERE hash=$1 " 287 "WHERE hash=$1 " "ORDER BY oid ASC LIMIT 1 OFFSET $2", 2,
302 "ORDER BY oid ASC LIMIT 1 OFFSET $2",
303 2,
304 __LINE__)) || 288 __LINE__)) ||
305 (GNUNET_OK != 289 (GNUNET_OK !=
306 pq_prepare (plugin, 290 pq_prepare (plugin, "put",
307 "put",
308 "INSERT INTO gn090 (repl, type, prio, anonLevel, expire, rvalue, hash, vhash, value) " 291 "INSERT INTO gn090 (repl, type, prio, anonLevel, expire, rvalue, hash, vhash, value) "
309 "VALUES ($1, $2, $3, $4, $5, RANDOM(), $6, $7, $8)", 292 "VALUES ($1, $2, $3, $4, $5, RANDOM(), $6, $7, $8)", 9,
310 9,
311 __LINE__)) || 293 __LINE__)) ||
312 (GNUNET_OK != 294 (GNUNET_OK !=
313 pq_prepare (plugin, 295 pq_prepare (plugin, "update",
314 "update",
315 "UPDATE gn090 SET prio = prio + $1, expire = CASE WHEN expire < $2 THEN $2 ELSE expire END " 296 "UPDATE gn090 SET prio = prio + $1, expire = CASE WHEN expire < $2 THEN $2 ELSE expire END "
316 "WHERE oid = $3", 297 "WHERE oid = $3", 3, __LINE__)) ||
317 3,
318 __LINE__)) ||
319 (GNUNET_OK != 298 (GNUNET_OK !=
320 pq_prepare (plugin, 299 pq_prepare (plugin, "decrepl",
321 "decrepl",
322 "UPDATE gn090 SET repl = GREATEST (repl - 1, 0) " 300 "UPDATE gn090 SET repl = GREATEST (repl - 1, 0) "
323 "WHERE oid = $1", 301 "WHERE oid = $1", 1, __LINE__)) ||
324 1,
325 __LINE__)) ||
326 (GNUNET_OK != 302 (GNUNET_OK !=
327 pq_prepare (plugin, 303 pq_prepare (plugin, "select_non_anonymous",
328 "select_non_anonymous",
329 "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 " 304 "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 "
330 "WHERE anonLevel = 0 AND type = $1 ORDER BY oid DESC LIMIT 1 OFFSET $2", 305 "WHERE anonLevel = 0 AND type = $1 ORDER BY oid DESC LIMIT 1 OFFSET $2",
331 1, 306 1, __LINE__)) ||
332 __LINE__)) ||
333 (GNUNET_OK != 307 (GNUNET_OK !=
334 pq_prepare (plugin, 308 pq_prepare (plugin, "select_expiration_order",
335 "select_expiration_order",
336 "(SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 " 309 "(SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 "
337 "WHERE expire < $1 ORDER BY prio ASC LIMIT 1) " 310 "WHERE expire < $1 ORDER BY prio ASC LIMIT 1) " "UNION "
338 "UNION "
339 "(SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 " 311 "(SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 "
340 "ORDER BY prio ASC LIMIT 1) " 312 "ORDER BY prio ASC LIMIT 1) " "ORDER BY expire ASC LIMIT 1",
341 "ORDER BY expire ASC LIMIT 1", 313 1, __LINE__)) ||
342 1,
343 __LINE__)) ||
344 (GNUNET_OK != 314 (GNUNET_OK !=
345 pq_prepare (plugin, 315 pq_prepare (plugin, "select_replication_order",
346 "select_replication_order",
347 "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 " 316 "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 "
348 "ORDER BY repl DESC,RANDOM() LIMIT 1", 317 "ORDER BY repl DESC,RANDOM() LIMIT 1", 0, __LINE__)) ||
349 0,
350 __LINE__)) ||
351 (GNUNET_OK != 318 (GNUNET_OK !=
352 pq_prepare (plugin, 319 pq_prepare (plugin, "delrow", "DELETE FROM gn090 " "WHERE oid=$1", 1,
353 "delrow", "DELETE FROM gn090 " "WHERE oid=$1", 1, __LINE__))) 320 __LINE__)))
354 { 321 {
355 PQfinish (plugin->dbh); 322 PQfinish (plugin->dbh);
356 plugin->dbh = NULL; 323 plugin->dbh = NULL;
@@ -378,12 +345,11 @@ delete_by_rowid (struct Plugin *plugin, unsigned int rowid)
378 PGresult *ret; 345 PGresult *ret;
379 346
380 browid = htonl (rowid); 347 browid = htonl (rowid);
381 ret = PQexecPrepared (plugin->dbh, 348 ret =
382 "delrow", 349 PQexecPrepared (plugin->dbh, "delrow", 1, paramValues, paramLengths,
383 1, paramValues, paramLengths, paramFormats, 1); 350 paramFormats, 1);
384 if (GNUNET_OK != 351 if (GNUNET_OK !=
385 check_result (plugin, 352 check_result (plugin, ret, PGRES_COMMAND_OK, "PQexecPrepared", "delrow",
386 ret, PGRES_COMMAND_OK, "PQexecPrepared", "delrow",
387 __LINE__)) 353 __LINE__))
388 { 354 {
389 return GNUNET_SYSERR; 355 return GNUNET_SYSERR;
@@ -407,18 +373,17 @@ postgres_plugin_estimate_size (void *cls)
407 unsigned long long total; 373 unsigned long long total;
408 PGresult *ret; 374 PGresult *ret;
409 375
410 ret = PQexecParams (plugin->dbh, 376 ret =
411 "SELECT SUM(LENGTH(value))+256*COUNT(*) FROM gn090", 377 PQexecParams (plugin->dbh,
412 0, NULL, NULL, NULL, NULL, 1); 378 "SELECT SUM(LENGTH(value))+256*COUNT(*) FROM gn090", 0,
413 if (GNUNET_OK != check_result (plugin, 379 NULL, NULL, NULL, NULL, 1);
414 ret, 380 if (GNUNET_OK !=
415 PGRES_TUPLES_OK, 381 check_result (plugin, ret, PGRES_TUPLES_OK, "PQexecParams", "get_size",
416 "PQexecParams", "get_size", __LINE__)) 382 __LINE__))
417 { 383 {
418 return 0; 384 return 0;
419 } 385 }
420 if ((PQntuples (ret) != 1) || 386 if ((PQntuples (ret) != 1) || (PQnfields (ret) != 1) ||
421 (PQnfields (ret) != 1) ||
422 (PQgetlength (ret, 0, 0) != sizeof (unsigned long long))) 387 (PQgetlength (ret, 0, 0) != sizeof (unsigned long long)))
423 { 388 {
424 GNUNET_break (0); 389 GNUNET_break (0);
@@ -447,13 +412,9 @@ postgres_plugin_estimate_size (void *cls)
447 * @return GNUNET_OK on success 412 * @return GNUNET_OK on success
448 */ 413 */
449static int 414static int
450postgres_plugin_put (void *cls, 415postgres_plugin_put (void *cls, const GNUNET_HashCode * key, uint32_t size,
451 const GNUNET_HashCode * key, 416 const void *data, enum GNUNET_BLOCK_Type type,
452 uint32_t size, 417 uint32_t priority, uint32_t anonymity,
453 const void *data,
454 enum GNUNET_BLOCK_Type type,
455 uint32_t priority,
456 uint32_t anonymity,
457 uint32_t replication, 418 uint32_t replication,
458 struct GNUNET_TIME_Absolute expiration, char **msg) 419 struct GNUNET_TIME_Absolute expiration, char **msg)
459{ 420{
@@ -489,17 +450,17 @@ postgres_plugin_put (void *cls,
489 const int paramFormats[] = { 1, 1, 1, 1, 1, 1, 1, 1 }; 450 const int paramFormats[] = { 1, 1, 1, 1, 1, 1, 1, 1 };
490 451
491 GNUNET_CRYPTO_hash (data, size, &vhash); 452 GNUNET_CRYPTO_hash (data, size, &vhash);
492 ret = PQexecPrepared (plugin->dbh, 453 ret =
493 "put", 8, paramValues, paramLengths, paramFormats, 1); 454 PQexecPrepared (plugin->dbh, "put", 8, paramValues, paramLengths,
494 if (GNUNET_OK != check_result (plugin, ret, 455 paramFormats, 1);
495 PGRES_COMMAND_OK, 456 if (GNUNET_OK !=
496 "PQexecPrepared", "put", __LINE__)) 457 check_result (plugin, ret, PGRES_COMMAND_OK, "PQexecPrepared", "put",
458 __LINE__))
497 return GNUNET_SYSERR; 459 return GNUNET_SYSERR;
498 PQclear (ret); 460 PQclear (ret);
499 plugin->env->duc (plugin->env->cls, size + GNUNET_DATASTORE_ENTRY_OVERHEAD); 461 plugin->env->duc (plugin->env->cls, size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
500#if DEBUG_POSTGRES 462#if DEBUG_POSTGRES
501 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 463 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datastore-postgres",
502 "datastore-postgres",
503 "Stored %u bytes in database\n", (unsigned int) size); 464 "Stored %u bytes in database\n", (unsigned int) size);
504#endif 465#endif
505 return GNUNET_OK; 466 return GNUNET_OK;
@@ -517,9 +478,8 @@ postgres_plugin_put (void *cls,
517 * @param line line number for error messages 478 * @param line line number for error messages
518 */ 479 */
519static void 480static void
520process_result (struct Plugin *plugin, 481process_result (struct Plugin *plugin, PluginDatumProcessor proc,
521 PluginDatumProcessor proc, void *proc_cls, 482 void *proc_cls, PGresult * res, int line)
522 PGresult * res, int line)
523{ 483{
524 int iret; 484 int iret;
525 enum GNUNET_BLOCK_Type type; 485 enum GNUNET_BLOCK_Type type;
@@ -530,14 +490,12 @@ process_result (struct Plugin *plugin,
530 struct GNUNET_TIME_Absolute expiration_time; 490 struct GNUNET_TIME_Absolute expiration_time;
531 GNUNET_HashCode key; 491 GNUNET_HashCode key;
532 492
533 if (GNUNET_OK != check_result (plugin, 493 if (GNUNET_OK !=
534 res, 494 check_result (plugin, res, PGRES_TUPLES_OK, "PQexecPrepared", "select",
535 PGRES_TUPLES_OK, 495 line))
536 "PQexecPrepared", "select", line))
537 { 496 {
538#if DEBUG_POSTGRES 497#if DEBUG_POSTGRES
539 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 498 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datastore-postgres",
540 "datastore-postgres",
541 "Ending iteration (postgres error)\n"); 499 "Ending iteration (postgres error)\n");
542#endif 500#endif
543 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 501 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
@@ -548,16 +506,14 @@ process_result (struct Plugin *plugin,
548 { 506 {
549 /* no result */ 507 /* no result */
550#if DEBUG_POSTGRES 508#if DEBUG_POSTGRES
551 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 509 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datastore-postgres",
552 "datastore-postgres",
553 "Ending iteration (no more results)\n"); 510 "Ending iteration (no more results)\n");
554#endif 511#endif
555 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 512 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
556 PQclear (res); 513 PQclear (res);
557 return; 514 return;
558 } 515 }
559 if ((1 != PQntuples (res)) || 516 if ((1 != PQntuples (res)) || (7 != PQnfields (res)) ||
560 (7 != PQnfields (res)) ||
561 (sizeof (uint32_t) != PQfsize (res, 0)) || 517 (sizeof (uint32_t) != PQfsize (res, 0)) ||
562 (sizeof (uint32_t) != PQfsize (res, 6))) 518 (sizeof (uint32_t) != PQfsize (res, 6)))
563 { 519 {
@@ -588,17 +544,14 @@ process_result (struct Plugin *plugin,
588 memcpy (&key, PQgetvalue (res, 0, 4), sizeof (GNUNET_HashCode)); 544 memcpy (&key, PQgetvalue (res, 0, 4), sizeof (GNUNET_HashCode));
589 size = PQgetlength (res, 0, 5); 545 size = PQgetlength (res, 0, 5);
590#if DEBUG_POSTGRES 546#if DEBUG_POSTGRES
591 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 547 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datastore-postgres",
592 "datastore-postgres",
593 "Found result of size %u bytes and type %u in database\n", 548 "Found result of size %u bytes and type %u in database\n",
594 (unsigned int) size, (unsigned int) type); 549 (unsigned int) size, (unsigned int) type);
595#endif 550#endif
596 iret = proc (proc_cls, 551 iret =
597 &key, 552 proc (proc_cls, &key, size, PQgetvalue (res, 0, 5),
598 size, 553 (enum GNUNET_BLOCK_Type) type, priority, anonymity, expiration_time,
599 PQgetvalue (res, 0, 5), 554 rowid);
600 (enum GNUNET_BLOCK_Type) type,
601 priority, anonymity, expiration_time, rowid);
602 PQclear (res); 555 PQclear (res);
603 if (iret == GNUNET_NO) 556 if (iret == GNUNET_NO)
604 { 557 {
@@ -609,16 +562,14 @@ process_result (struct Plugin *plugin,
609 if (GNUNET_OK == delete_by_rowid (plugin, rowid)) 562 if (GNUNET_OK == delete_by_rowid (plugin, rowid))
610 { 563 {
611#if DEBUG_POSTGRES 564#if DEBUG_POSTGRES
612 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 565 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datastore-postgres",
613 "datastore-postgres",
614 "Deleting %u bytes from database\n", 566 "Deleting %u bytes from database\n",
615 (unsigned int) size); 567 (unsigned int) size);
616#endif 568#endif
617 plugin->env->duc (plugin->env->cls, 569 plugin->env->duc (plugin->env->cls,
618 -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); 570 -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
619#if DEBUG_POSTGRES 571#if DEBUG_POSTGRES
620 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 572 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datastore-postgres",
621 "datastore-postgres",
622 "Deleted %u bytes from database\n", (unsigned int) size); 573 "Deleted %u bytes from database\n", (unsigned int) size);
623#endif 574#endif
624 } 575 }
@@ -646,12 +597,11 @@ process_result (struct Plugin *plugin,
646 * @param proc_cls closure for iter 597 * @param proc_cls closure for iter
647 */ 598 */
648static void 599static void
649postgres_plugin_get_key (void *cls, 600postgres_plugin_get_key (void *cls, uint64_t offset,
650 uint64_t offset,
651 const GNUNET_HashCode * key, 601 const GNUNET_HashCode * key,
652 const GNUNET_HashCode * vhash, 602 const GNUNET_HashCode * vhash,
653 enum GNUNET_BLOCK_Type type, 603 enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc,
654 PluginDatumProcessor proc, void *proc_cls) 604 void *proc_cls)
655{ 605{
656 struct Plugin *plugin = cls; 606 struct Plugin *plugin = cls;
657 const int paramFormats[] = { 1, 1, 1, 1, 1 }; 607 const int paramFormats[] = { 1, 1, 1, 1, 1 };
@@ -680,9 +630,10 @@ postgres_plugin_get_key (void *cls,
680 paramLengths[3] = sizeof (blimit_off); 630 paramLengths[3] = sizeof (blimit_off);
681 nparams = 4; 631 nparams = 4;
682 pname = "getvt"; 632 pname = "getvt";
683 ret = PQexecParams (plugin->dbh, 633 ret =
684 "SELECT count(*) FROM gn090 WHERE hash=$1 AND vhash=$2 AND type=$3", 634 PQexecParams (plugin->dbh,
685 3, NULL, paramValues, paramLengths, paramFormats, 1); 635 "SELECT count(*) FROM gn090 WHERE hash=$1 AND vhash=$2 AND type=$3",
636 3, NULL, paramValues, paramLengths, paramFormats, 1);
686 } 637 }
687 else 638 else
688 { 639 {
@@ -692,9 +643,10 @@ postgres_plugin_get_key (void *cls,
692 paramLengths[2] = sizeof (blimit_off); 643 paramLengths[2] = sizeof (blimit_off);
693 nparams = 3; 644 nparams = 3;
694 pname = "gett"; 645 pname = "gett";
695 ret = PQexecParams (plugin->dbh, 646 ret =
696 "SELECT count(*) FROM gn090 WHERE hash=$1 AND type=$2", 647 PQexecParams (plugin->dbh,
697 2, NULL, paramValues, paramLengths, paramFormats, 1); 648 "SELECT count(*) FROM gn090 WHERE hash=$1 AND type=$2",
649 2, NULL, paramValues, paramLengths, paramFormats, 1);
698 } 650 }
699 } 651 }
700 else 652 else
@@ -707,9 +659,10 @@ postgres_plugin_get_key (void *cls,
707 paramLengths[2] = sizeof (blimit_off); 659 paramLengths[2] = sizeof (blimit_off);
708 nparams = 3; 660 nparams = 3;
709 pname = "getv"; 661 pname = "getv";
710 ret = PQexecParams (plugin->dbh, 662 ret =
711 "SELECT count(*) FROM gn090 WHERE hash=$1 AND vhash=$2", 663 PQexecParams (plugin->dbh,
712 2, NULL, paramValues, paramLengths, paramFormats, 1); 664 "SELECT count(*) FROM gn090 WHERE hash=$1 AND vhash=$2",
665 2, NULL, paramValues, paramLengths, paramFormats, 1);
713 } 666 }
714 else 667 else
715 { 668 {
@@ -717,21 +670,19 @@ postgres_plugin_get_key (void *cls,
717 paramLengths[1] = sizeof (blimit_off); 670 paramLengths[1] = sizeof (blimit_off);
718 nparams = 2; 671 nparams = 2;
719 pname = "get"; 672 pname = "get";
720 ret = PQexecParams (plugin->dbh, 673 ret =
721 "SELECT count(*) FROM gn090 WHERE hash=$1", 674 PQexecParams (plugin->dbh, "SELECT count(*) FROM gn090 WHERE hash=$1",
722 1, NULL, paramValues, paramLengths, paramFormats, 1); 675 1, NULL, paramValues, paramLengths, paramFormats, 1);
723 } 676 }
724 } 677 }
725 if (GNUNET_OK != check_result (plugin, 678 if (GNUNET_OK !=
726 ret, 679 check_result (plugin, ret, PGRES_TUPLES_OK, "PQexecParams", pname,
727 PGRES_TUPLES_OK, 680 __LINE__))
728 "PQexecParams", pname, __LINE__))
729 { 681 {
730 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 682 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
731 return; 683 return;
732 } 684 }
733 if ((PQntuples (ret) != 1) || 685 if ((PQntuples (ret) != 1) || (PQnfields (ret) != 1) ||
734 (PQnfields (ret) != 1) ||
735 (PQgetlength (ret, 0, 0) != sizeof (unsigned long long))) 686 (PQgetlength (ret, 0, 0) != sizeof (unsigned long long)))
736 { 687 {
737 GNUNET_break (0); 688 GNUNET_break (0);
@@ -747,9 +698,9 @@ postgres_plugin_get_key (void *cls,
747 return; 698 return;
748 } 699 }
749 blimit_off = GNUNET_htonll (offset % total); 700 blimit_off = GNUNET_htonll (offset % total);
750 ret = PQexecPrepared (plugin->dbh, 701 ret =
751 pname, 702 PQexecPrepared (plugin->dbh, pname, nparams, paramValues, paramLengths,
752 nparams, paramValues, paramLengths, paramFormats, 1); 703 paramFormats, 1);
753 process_result (plugin, proc, proc_cls, ret, __LINE__); 704 process_result (plugin, proc, proc_cls, ret, __LINE__);
754} 705}
755 706
@@ -766,8 +717,7 @@ postgres_plugin_get_key (void *cls,
766 * @param proc_cls closure for proc 717 * @param proc_cls closure for proc
767 */ 718 */
768static void 719static void
769postgres_plugin_get_zero_anonymity (void *cls, 720postgres_plugin_get_zero_anonymity (void *cls, uint64_t offset,
770 uint64_t offset,
771 enum GNUNET_BLOCK_Type type, 721 enum GNUNET_BLOCK_Type type,
772 PluginDatumProcessor proc, void *proc_cls) 722 PluginDatumProcessor proc, void *proc_cls)
773{ 723{
@@ -781,9 +731,9 @@ postgres_plugin_get_zero_anonymity (void *cls,
781 731
782 btype = htonl ((uint32_t) type); 732 btype = htonl ((uint32_t) type);
783 boff = GNUNET_htonll (offset); 733 boff = GNUNET_htonll (offset);
784 ret = PQexecPrepared (plugin->dbh, 734 ret =
785 "select_non_anonymous", 735 PQexecPrepared (plugin->dbh, "select_non_anonymous", 2, paramValues,
786 2, paramValues, paramLengths, paramFormats, 1); 736 paramLengths, paramFormats, 1);
787 process_result (plugin, proc, proc_cls, ret, __LINE__); 737 process_result (plugin, proc, proc_cls, ret, __LINE__);
788} 738}
789 739
@@ -833,14 +783,10 @@ struct ReplCtx
833 * GNUNET_NO to delete the item and continue (if supported) 783 * GNUNET_NO to delete the item and continue (if supported)
834 */ 784 */
835static int 785static int
836repl_proc (void *cls, 786repl_proc (void *cls, const GNUNET_HashCode * key, uint32_t size,
837 const GNUNET_HashCode * key, 787 const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority,
838 uint32_t size, 788 uint32_t anonymity, struct GNUNET_TIME_Absolute expiration,
839 const void *data, 789 uint64_t uid)
840 enum GNUNET_BLOCK_Type type,
841 uint32_t priority,
842 uint32_t anonymity,
843 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
844{ 790{
845 struct ReplCtx *rc = cls; 791 struct ReplCtx *rc = cls;
846 struct Plugin *plugin = rc->plugin; 792 struct Plugin *plugin = rc->plugin;
@@ -848,8 +794,9 @@ repl_proc (void *cls,
848 PGresult *qret; 794 PGresult *qret;
849 uint32_t boid; 795 uint32_t boid;
850 796
851 ret = rc->proc (rc->proc_cls, 797 ret =
852 key, size, data, type, priority, anonymity, expiration, uid); 798 rc->proc (rc->proc_cls, key, size, data, type, priority, anonymity,
799 expiration, uid);
853 if (NULL != key) 800 if (NULL != key)
854 { 801 {
855 boid = htonl ((uint32_t) uid); 802 boid = htonl ((uint32_t) uid);
@@ -860,13 +807,12 @@ repl_proc (void *cls,
860 sizeof (boid), 807 sizeof (boid),
861 }; 808 };
862 const int paramFormats[] = { 1 }; 809 const int paramFormats[] = { 1 };
863 qret = PQexecPrepared (plugin->dbh, 810 qret =
864 "decrepl", 811 PQexecPrepared (plugin->dbh, "decrepl", 1, paramValues, paramLengths,
865 1, paramValues, paramLengths, paramFormats, 1); 812 paramFormats, 1);
866 if (GNUNET_OK != check_result (plugin, 813 if (GNUNET_OK !=
867 qret, 814 check_result (plugin, qret, PGRES_COMMAND_OK, "PQexecPrepared",
868 PGRES_COMMAND_OK, 815 "decrepl", __LINE__))
869 "PQexecPrepared", "decrepl", __LINE__))
870 return GNUNET_SYSERR; 816 return GNUNET_SYSERR;
871 PQclear (qret); 817 PQclear (qret);
872 } 818 }
@@ -885,8 +831,8 @@ repl_proc (void *cls,
885 * @param proc_cls closure for proc 831 * @param proc_cls closure for proc
886 */ 832 */
887static void 833static void
888postgres_plugin_get_replication (void *cls, 834postgres_plugin_get_replication (void *cls, PluginDatumProcessor proc,
889 PluginDatumProcessor proc, void *proc_cls) 835 void *proc_cls)
890{ 836{
891 struct Plugin *plugin = cls; 837 struct Plugin *plugin = cls;
892 struct ReplCtx rc; 838 struct ReplCtx rc;
@@ -895,8 +841,9 @@ postgres_plugin_get_replication (void *cls,
895 rc.plugin = plugin; 841 rc.plugin = plugin;
896 rc.proc = proc; 842 rc.proc = proc;
897 rc.proc_cls = proc_cls; 843 rc.proc_cls = proc_cls;
898 ret = PQexecPrepared (plugin->dbh, 844 ret =
899 "select_replication_order", 0, NULL, NULL, NULL, 1); 845 PQexecPrepared (plugin->dbh, "select_replication_order", 0, NULL, NULL,
846 NULL, 1);
900 process_result (plugin, &repl_proc, &rc, ret, __LINE__); 847 process_result (plugin, &repl_proc, &rc, ret, __LINE__);
901} 848}
902 849
@@ -910,8 +857,8 @@ postgres_plugin_get_replication (void *cls,
910 * @param proc_cls closure for proc 857 * @param proc_cls closure for proc
911 */ 858 */
912static void 859static void
913postgres_plugin_get_expiration (void *cls, 860postgres_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
914 PluginDatumProcessor proc, void *proc_cls) 861 void *proc_cls)
915{ 862{
916 struct Plugin *plugin = cls; 863 struct Plugin *plugin = cls;
917 uint64_t btime; 864 uint64_t btime;
@@ -921,9 +868,9 @@ postgres_plugin_get_expiration (void *cls,
921 PGresult *ret; 868 PGresult *ret;
922 869
923 btime = GNUNET_htonll (GNUNET_TIME_absolute_get ().abs_value); 870 btime = GNUNET_htonll (GNUNET_TIME_absolute_get ().abs_value);
924 ret = PQexecPrepared (plugin->dbh, 871 ret =
925 "select_expiration_order", 872 PQexecPrepared (plugin->dbh, "select_expiration_order", 1, paramValues,
926 1, paramValues, paramLengths, paramFormats, 1); 873 paramLengths, paramFormats, 1);
927 process_result (plugin, proc, proc_cls, ret, __LINE__); 874 process_result (plugin, proc, proc_cls, ret, __LINE__);
928} 875}
929 876
@@ -952,10 +899,8 @@ postgres_plugin_get_expiration (void *cls,
952 * @return GNUNET_OK on success 899 * @return GNUNET_OK on success
953 */ 900 */
954static int 901static int
955postgres_plugin_update (void *cls, 902postgres_plugin_update (void *cls, uint64_t uid, int delta,
956 uint64_t uid, 903 struct GNUNET_TIME_Absolute expire, char **msg)
957 int delta, struct GNUNET_TIME_Absolute expire,
958 char **msg)
959{ 904{
960 struct Plugin *plugin = cls; 905 struct Plugin *plugin = cls;
961 PGresult *ret; 906 PGresult *ret;
@@ -975,13 +920,12 @@ postgres_plugin_update (void *cls,
975 }; 920 };
976 const int paramFormats[] = { 1, 1, 1 }; 921 const int paramFormats[] = { 1, 1, 1 };
977 922
978 ret = PQexecPrepared (plugin->dbh, 923 ret =
979 "update", 924 PQexecPrepared (plugin->dbh, "update", 3, paramValues, paramLengths,
980 3, paramValues, paramLengths, paramFormats, 1); 925 paramFormats, 1);
981 if (GNUNET_OK != check_result (plugin, 926 if (GNUNET_OK !=
982 ret, 927 check_result (plugin, ret, PGRES_COMMAND_OK, "PQexecPrepared", "update",
983 PGRES_COMMAND_OK, 928 __LINE__))
984 "PQexecPrepared", "update", __LINE__))
985 return GNUNET_SYSERR; 929 return GNUNET_SYSERR;
986 PQclear (ret); 930 PQclear (ret);
987 return GNUNET_OK; 931 return GNUNET_OK;
@@ -1030,8 +974,8 @@ libgnunet_plugin_datastore_postgres_init (void *cls)
1030 api->get_expiration = &postgres_plugin_get_expiration; 974 api->get_expiration = &postgres_plugin_get_expiration;
1031 api->get_zero_anonymity = &postgres_plugin_get_zero_anonymity; 975 api->get_zero_anonymity = &postgres_plugin_get_zero_anonymity;
1032 api->drop = &postgres_plugin_drop; 976 api->drop = &postgres_plugin_drop;
1033 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, 977 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "datastore-postgres",
1034 "datastore-postgres", _("Postgres database running\n")); 978 _("Postgres database running\n"));
1035 return api; 979 return api;
1036} 980}
1037 981
diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c
index 075d31623..46486d933 100644
--- a/src/datastore/plugin_datastore_sqlite.c
+++ b/src/datastore/plugin_datastore_sqlite.c
@@ -144,12 +144,12 @@ sq_prepare (sqlite3 * dbh, const char *zSql, sqlite3_stmt ** ppStmt)
144 char *dummy; 144 char *dummy;
145 int result; 145 int result;
146 146
147 result = sqlite3_prepare_v2 (dbh, 147 result =
148 zSql, 148 sqlite3_prepare_v2 (dbh, zSql, strlen (zSql), ppStmt,
149 strlen (zSql), ppStmt, (const char **) &dummy); 149 (const char **) &dummy);
150#if DEBUG_SQLITE && 0 150#if DEBUG_SQLITE && 0
151 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 151 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
152 "sqlite", "Prepared `%s' / %p: %d\n", zSql, *ppStmt, result); 152 "Prepared `%s' / %p: %d\n", zSql, *ppStmt, result);
153#endif 153#endif
154 return result; 154 return result;
155} 155}
@@ -165,8 +165,7 @@ create_indices (sqlite3 * dbh)
165{ 165{
166 /* create indices */ 166 /* create indices */
167 if ((SQLITE_OK != 167 if ((SQLITE_OK !=
168 sqlite3_exec (dbh, 168 sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS idx_hash ON gn090 (hash)",
169 "CREATE INDEX IF NOT EXISTS idx_hash ON gn090 (hash)",
170 NULL, NULL, NULL)) || 169 NULL, NULL, NULL)) ||
171 (SQLITE_OK != 170 (SQLITE_OK !=
172 sqlite3_exec (dbh, 171 sqlite3_exec (dbh,
@@ -232,12 +231,10 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
232#endif 231#endif
233 232
234 if (GNUNET_OK != 233 if (GNUNET_OK !=
235 GNUNET_CONFIGURATION_get_value_filename (cfg, 234 GNUNET_CONFIGURATION_get_value_filename (cfg, "datastore-sqlite",
236 "datastore-sqlite",
237 "FILENAME", &afsdir)) 235 "FILENAME", &afsdir))
238 { 236 {
239 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 237 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "sqlite",
240 "sqlite",
241 _ 238 _
242 ("Option `%s' in section `%s' missing in configuration!\n"), 239 ("Option `%s' in section `%s' missing in configuration!\n"),
243 "FILENAME", "datastore-sqlite"); 240 "FILENAME", "datastore-sqlite");
@@ -255,8 +252,8 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
255 plugin->env->duc (plugin->env->cls, 0); 252 plugin->env->duc (plugin->env->cls, 0);
256 } 253 }
257#ifdef ENABLE_NLS 254#ifdef ENABLE_NLS
258 plugin->fn = GNUNET_STRINGS_to_utf8 (afsdir, strlen (afsdir), 255 plugin->fn =
259 nl_langinfo (CODESET)); 256 GNUNET_STRINGS_to_utf8 (afsdir, strlen (afsdir), nl_langinfo (CODESET));
260#else 257#else
261 plugin->fn = GNUNET_STRINGS_to_utf8 (afsdir, strlen (afsdir), "UTF-8"); /* good luck */ 258 plugin->fn = GNUNET_STRINGS_to_utf8 (afsdir, strlen (afsdir), "UTF-8"); /* good luck */
262#endif 259#endif
@@ -265,33 +262,32 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
265 /* Open database and precompile statements */ 262 /* Open database and precompile statements */
266 if (sqlite3_open (plugin->fn, &plugin->dbh) != SQLITE_OK) 263 if (sqlite3_open (plugin->fn, &plugin->dbh) != SQLITE_OK)
267 { 264 {
268 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 265 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "sqlite",
269 "sqlite",
270 _("Unable to initialize SQLite: %s.\n"), 266 _("Unable to initialize SQLite: %s.\n"),
271 sqlite3_errmsg (plugin->dbh)); 267 sqlite3_errmsg (plugin->dbh));
272 return GNUNET_SYSERR; 268 return GNUNET_SYSERR;
273 } 269 }
274 CHECK (SQLITE_OK == 270 CHECK (SQLITE_OK ==
275 sqlite3_exec (plugin->dbh, 271 sqlite3_exec (plugin->dbh, "PRAGMA temp_store=MEMORY", NULL, NULL,
276 "PRAGMA temp_store=MEMORY", NULL, NULL, ENULL)); 272 ENULL));
277 CHECK (SQLITE_OK == 273 CHECK (SQLITE_OK ==
278 sqlite3_exec (plugin->dbh, 274 sqlite3_exec (plugin->dbh, "PRAGMA synchronous=OFF", NULL, NULL,
279 "PRAGMA synchronous=OFF", NULL, NULL, ENULL)); 275 ENULL));
280 CHECK (SQLITE_OK == 276 CHECK (SQLITE_OK ==
281 sqlite3_exec (plugin->dbh, 277 sqlite3_exec (plugin->dbh, "PRAGMA legacy_file_format=OFF", NULL, NULL,
282 "PRAGMA legacy_file_format=OFF", NULL, NULL, ENULL)); 278 ENULL));
283 CHECK (SQLITE_OK == 279 CHECK (SQLITE_OK ==
284 sqlite3_exec (plugin->dbh, 280 sqlite3_exec (plugin->dbh, "PRAGMA auto_vacuum=INCREMENTAL", NULL,
285 "PRAGMA auto_vacuum=INCREMENTAL", NULL, NULL, ENULL)); 281 NULL, ENULL));
286 CHECK (SQLITE_OK == 282 CHECK (SQLITE_OK ==
287 sqlite3_exec (plugin->dbh, 283 sqlite3_exec (plugin->dbh, "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL,
288 "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, ENULL)); 284 ENULL));
289 CHECK (SQLITE_OK == 285 CHECK (SQLITE_OK ==
290 sqlite3_exec (plugin->dbh, 286 sqlite3_exec (plugin->dbh, "PRAGMA count_changes=OFF", NULL, NULL,
291 "PRAGMA count_changes=OFF", NULL, NULL, ENULL)); 287 ENULL));
292 CHECK (SQLITE_OK == 288 CHECK (SQLITE_OK ==
293 sqlite3_exec (plugin->dbh, 289 sqlite3_exec (plugin->dbh, "PRAGMA page_size=4092", NULL, NULL,
294 "PRAGMA page_size=4092", NULL, NULL, ENULL)); 290 ENULL));
295 291
296 CHECK (SQLITE_OK == sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS)); 292 CHECK (SQLITE_OK == sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS));
297 293
@@ -302,18 +298,14 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
302 "SELECT 1 FROM sqlite_master WHERE tbl_name = 'gn090'", 298 "SELECT 1 FROM sqlite_master WHERE tbl_name = 'gn090'",
303 &stmt)); 299 &stmt));
304 if ((sqlite3_step (stmt) == SQLITE_DONE) && 300 if ((sqlite3_step (stmt) == SQLITE_DONE) &&
305 (sqlite3_exec (plugin->dbh, 301 (sqlite3_exec
306 "CREATE TABLE gn090 (" 302 (plugin->dbh,
307 " repl INT4 NOT NULL DEFAULT 0," 303 "CREATE TABLE gn090 (" " repl INT4 NOT NULL DEFAULT 0,"
308 " type INT4 NOT NULL DEFAULT 0," 304 " type INT4 NOT NULL DEFAULT 0," " prio INT4 NOT NULL DEFAULT 0,"
309 " prio INT4 NOT NULL DEFAULT 0," 305 " anonLevel INT4 NOT NULL DEFAULT 0,"
310 " anonLevel INT4 NOT NULL DEFAULT 0," 306 " expire INT8 NOT NULL DEFAULT 0," " rvalue INT8 NOT NULL,"
311 " expire INT8 NOT NULL DEFAULT 0," 307 " hash TEXT NOT NULL DEFAULT ''," " vhash TEXT NOT NULL DEFAULT '',"
312 " rvalue INT8 NOT NULL," 308 " value BLOB NOT NULL DEFAULT '')", NULL, NULL, NULL) != SQLITE_OK))
313 " hash TEXT NOT NULL DEFAULT '',"
314 " vhash TEXT NOT NULL DEFAULT '',"
315 " value BLOB NOT NULL DEFAULT '')", NULL, NULL,
316 NULL) != SQLITE_OK))
317 { 309 {
318 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec"); 310 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec");
319 sqlite3_finalize (stmt); 311 sqlite3_finalize (stmt);
@@ -322,47 +314,49 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
322 sqlite3_finalize (stmt); 314 sqlite3_finalize (stmt);
323 create_indices (plugin->dbh); 315 create_indices (plugin->dbh);
324 316
325 if ((sq_prepare (plugin->dbh, 317 if ((sq_prepare
326 "UPDATE gn090 " 318 (plugin->dbh,
327 "SET prio = prio + ?, expire = MAX(expire,?) WHERE _ROWID_ = ?", 319 "UPDATE gn090 "
328 &plugin->updPrio) != SQLITE_OK) || 320 "SET prio = prio + ?, expire = MAX(expire,?) WHERE _ROWID_ = ?",
329 (sq_prepare (plugin->dbh, 321 &plugin->updPrio) != SQLITE_OK) ||
330 "UPDATE gn090 " 322 (sq_prepare
331 "SET repl = MAX (0, repl - 1) WHERE _ROWID_ = ?", 323 (plugin->dbh,
332 &plugin->updRepl) != SQLITE_OK) || 324 "UPDATE gn090 " "SET repl = MAX (0, repl - 1) WHERE _ROWID_ = ?",
333 (sq_prepare (plugin->dbh, 325 &plugin->updRepl) != SQLITE_OK) ||
334 "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " 326 (sq_prepare
335 "FROM gn090 INDEXED BY idx_repl_rvalue " 327 (plugin->dbh,
336 "WHERE repl=?2 AND" 328 "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ "
337 " (rvalue>=?1 OR" 329 "FROM gn090 INDEXED BY idx_repl_rvalue " "WHERE repl=?2 AND"
338 " NOT EXISTS (SELECT 1 FROM gn090 INDEXED BY idx_repl_rvalue WHERE repl=?2 AND rvalue>=?1 LIMIT 1))" 330 " (rvalue>=?1 OR"
339 " ORDER BY rvalue ASC" 331 " NOT EXISTS (SELECT 1 FROM gn090 INDEXED BY idx_repl_rvalue WHERE repl=?2 AND rvalue>=?1 LIMIT 1))"
340 " LIMIT 1", 332 " ORDER BY rvalue ASC" " LIMIT 1",
341 &plugin->selRepl) != SQLITE_OK) || 333 &plugin->selRepl) != SQLITE_OK) ||
342 (sq_prepare (plugin->dbh, 334 (sq_prepare
343 "SELECT MAX(repl) " 335 (plugin->dbh,
344 "FROM gn090 INDEXED BY idx_repl_rvalue", 336 "SELECT MAX(repl) " "FROM gn090 INDEXED BY idx_repl_rvalue",
345 &plugin->maxRepl) != SQLITE_OK) || 337 &plugin->maxRepl) != SQLITE_OK) ||
346 (sq_prepare (plugin->dbh, 338 (sq_prepare
347 "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " 339 (plugin->dbh,
348 "FROM gn090 INDEXED BY idx_expire" 340 "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ "
349 " WHERE NOT EXISTS (SELECT 1 FROM gn090 WHERE expire < ?1 LIMIT 1) OR (expire < ?1) " 341 "FROM gn090 INDEXED BY idx_expire"
350 " ORDER BY expire ASC LIMIT 1", 342 " WHERE NOT EXISTS (SELECT 1 FROM gn090 WHERE expire < ?1 LIMIT 1) OR (expire < ?1) "
351 &plugin->selExpi) != SQLITE_OK) || 343 " ORDER BY expire ASC LIMIT 1", &plugin->selExpi) != SQLITE_OK) ||
352 (sq_prepare (plugin->dbh, 344 (sq_prepare
353 "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " 345 (plugin->dbh,
354 "FROM gn090 INDEXED BY idx_anon_type_hash " 346 "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ "
355 "WHERE (anonLevel = 0 AND type=?1) " 347 "FROM gn090 INDEXED BY idx_anon_type_hash "
356 "ORDER BY hash DESC LIMIT 1 OFFSET ?2", 348 "WHERE (anonLevel = 0 AND type=?1) "
357 &plugin->selZeroAnon) != SQLITE_OK) || 349 "ORDER BY hash DESC LIMIT 1 OFFSET ?2",
358 (sq_prepare (plugin->dbh, 350 &plugin->selZeroAnon) != SQLITE_OK) ||
359 "INSERT INTO gn090 (repl, type, prio, " 351 (sq_prepare
360 "anonLevel, expire, rvalue, hash, vhash, value) " 352 (plugin->dbh,
361 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", 353 "INSERT INTO gn090 (repl, type, prio, "
362 &plugin->insertContent) != SQLITE_OK) || 354 "anonLevel, expire, rvalue, hash, vhash, value) "
363 (sq_prepare (plugin->dbh, 355 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
364 "DELETE FROM gn090 WHERE _ROWID_ = ?", 356 &plugin->insertContent) != SQLITE_OK) ||
365 &plugin->delRow) != SQLITE_OK)) 357 (sq_prepare
358 (plugin->dbh, "DELETE FROM gn090 WHERE _ROWID_ = ?",
359 &plugin->delRow) != SQLITE_OK))
366 { 360 {
367 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR, "precompiling"); 361 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR, "precompiling");
368 return GNUNET_SYSERR; 362 return GNUNET_SYSERR;
@@ -406,22 +400,20 @@ database_shutdown (struct Plugin *plugin)
406#if SQLITE_VERSION_NUMBER >= 3007000 400#if SQLITE_VERSION_NUMBER >= 3007000
407 if (result == SQLITE_BUSY) 401 if (result == SQLITE_BUSY)
408 { 402 {
409 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, 403 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "sqlite",
410 "sqlite",
411 _ 404 _
412 ("Tried to close sqlite without finalizing all prepared statements.\n")); 405 ("Tried to close sqlite without finalizing all prepared statements.\n"));
413 stmt = sqlite3_next_stmt (plugin->dbh, NULL); 406 stmt = sqlite3_next_stmt (plugin->dbh, NULL);
414 while (stmt != NULL) 407 while (stmt != NULL)
415 { 408 {
416#if DEBUG_SQLITE 409#if DEBUG_SQLITE
417 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 410 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
418 "sqlite", "Closing statement %p\n", stmt); 411 "Closing statement %p\n", stmt);
419#endif 412#endif
420 result = sqlite3_finalize (stmt); 413 result = sqlite3_finalize (stmt);
421#if DEBUG_SQLITE 414#if DEBUG_SQLITE
422 if (result != SQLITE_OK) 415 if (result != SQLITE_OK)
423 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 416 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
424 "sqlite",
425 "Failed to close statement %p: %d\n", stmt, result); 417 "Failed to close statement %p: %d\n", stmt, result);
426#endif 418#endif
427 stmt = sqlite3_next_stmt (plugin->dbh, NULL); 419 stmt = sqlite3_next_stmt (plugin->dbh, NULL);
@@ -448,8 +440,7 @@ delete_by_rowid (struct Plugin *plugin, unsigned long long rid)
448{ 440{
449 if (SQLITE_OK != sqlite3_bind_int64 (plugin->delRow, 1, rid)) 441 if (SQLITE_OK != sqlite3_bind_int64 (plugin->delRow, 1, rid))
450 { 442 {
451 LOG_SQLITE (plugin, NULL, 443 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
452 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
453 "sqlite3_bind_XXXX"); 444 "sqlite3_bind_XXXX");
454 if (SQLITE_OK != sqlite3_reset (plugin->delRow)) 445 if (SQLITE_OK != sqlite3_reset (plugin->delRow))
455 LOG_SQLITE (plugin, NULL, 446 LOG_SQLITE (plugin, NULL,
@@ -459,19 +450,17 @@ delete_by_rowid (struct Plugin *plugin, unsigned long long rid)
459 } 450 }
460 if (SQLITE_DONE != sqlite3_step (plugin->delRow)) 451 if (SQLITE_DONE != sqlite3_step (plugin->delRow))
461 { 452 {
462 LOG_SQLITE (plugin, NULL, 453 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
463 GNUNET_ERROR_TYPE_ERROR | 454 "sqlite3_step");
464 GNUNET_ERROR_TYPE_BULK, "sqlite3_step");
465 if (SQLITE_OK != sqlite3_reset (plugin->delRow)) 455 if (SQLITE_OK != sqlite3_reset (plugin->delRow))
466 LOG_SQLITE (plugin, NULL, 456 LOG_SQLITE (plugin, NULL,
467 GNUNET_ERROR_TYPE_ERROR | 457 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
468 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); 458 "sqlite3_reset");
469 return GNUNET_SYSERR; 459 return GNUNET_SYSERR;
470 } 460 }
471 if (SQLITE_OK != sqlite3_reset (plugin->delRow)) 461 if (SQLITE_OK != sqlite3_reset (plugin->delRow))
472 LOG_SQLITE (plugin, NULL, 462 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
473 GNUNET_ERROR_TYPE_ERROR | 463 "sqlite3_reset");
474 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
475 return GNUNET_OK; 464 return GNUNET_OK;
476} 465}
477 466
@@ -492,14 +481,9 @@ delete_by_rowid (struct Plugin *plugin, unsigned long long rid)
492 * @return GNUNET_OK on success 481 * @return GNUNET_OK on success
493 */ 482 */
494static int 483static int
495sqlite_plugin_put (void *cls, 484sqlite_plugin_put (void *cls, const GNUNET_HashCode * key, uint32_t size,
496 const GNUNET_HashCode * key, 485 const void *data, enum GNUNET_BLOCK_Type type,
497 uint32_t size, 486 uint32_t priority, uint32_t anonymity, uint32_t replication,
498 const void *data,
499 enum GNUNET_BLOCK_Type type,
500 uint32_t priority,
501 uint32_t anonymity,
502 uint32_t replication,
503 struct GNUNET_TIME_Absolute expiration, char **msg) 487 struct GNUNET_TIME_Absolute expiration, char **msg)
504{ 488{
505 struct Plugin *plugin = cls; 489 struct Plugin *plugin = cls;
@@ -512,12 +496,9 @@ sqlite_plugin_put (void *cls,
512 if (size > MAX_ITEM_SIZE) 496 if (size > MAX_ITEM_SIZE)
513 return GNUNET_SYSERR; 497 return GNUNET_SYSERR;
514#if DEBUG_SQLITE 498#if DEBUG_SQLITE
515 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 499 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
516 "sqlite",
517 "Storing in database block with type %u/key `%s'/priority %u/expiration in %llu ms (%lld).\n", 500 "Storing in database block with type %u/key `%s'/priority %u/expiration in %llu ms (%lld).\n",
518 type, 501 type, GNUNET_h2s (key), priority,
519 GNUNET_h2s (key),
520 priority,
521 (unsigned long long) 502 (unsigned long long)
522 GNUNET_TIME_absolute_get_remaining (expiration).rel_value, 503 GNUNET_TIME_absolute_get_remaining (expiration).rel_value,
523 (long long) expiration.abs_value); 504 (long long) expiration.abs_value);
@@ -536,13 +517,10 @@ sqlite_plugin_put (void *cls,
536 SQLITE_TRANSIENT)) || 517 SQLITE_TRANSIENT)) ||
537 (SQLITE_OK != 518 (SQLITE_OK !=
538 sqlite3_bind_blob (stmt, 8, &vhash, sizeof (GNUNET_HashCode), 519 sqlite3_bind_blob (stmt, 8, &vhash, sizeof (GNUNET_HashCode),
539 SQLITE_TRANSIENT)) 520 SQLITE_TRANSIENT)) ||
540 || (SQLITE_OK != 521 (SQLITE_OK != sqlite3_bind_blob (stmt, 9, data, size, SQLITE_TRANSIENT)))
541 sqlite3_bind_blob (stmt, 9, data, size, SQLITE_TRANSIENT)))
542 { 522 {
543 LOG_SQLITE (plugin, 523 LOG_SQLITE (plugin, msg, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
544 msg,
545 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
546 "sqlite3_bind_XXXX"); 524 "sqlite3_bind_XXXX");
547 if (SQLITE_OK != sqlite3_reset (stmt)) 525 if (SQLITE_OK != sqlite3_reset (stmt))
548 LOG_SQLITE (plugin, NULL, 526 LOG_SQLITE (plugin, NULL,
@@ -556,8 +534,7 @@ sqlite_plugin_put (void *cls,
556 case SQLITE_DONE: 534 case SQLITE_DONE:
557 plugin->env->duc (plugin->env->cls, size + GNUNET_DATASTORE_ENTRY_OVERHEAD); 535 plugin->env->duc (plugin->env->cls, size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
558#if DEBUG_SQLITE 536#if DEBUG_SQLITE
559 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 537 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
560 "sqlite",
561 "Stored new entry (%u bytes)\n", 538 "Stored new entry (%u bytes)\n",
562 size + GNUNET_DATASTORE_ENTRY_OVERHEAD); 539 size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
563#endif 540#endif
@@ -565,27 +542,24 @@ sqlite_plugin_put (void *cls,
565 break; 542 break;
566 case SQLITE_BUSY: 543 case SQLITE_BUSY:
567 GNUNET_break (0); 544 GNUNET_break (0);
568 LOG_SQLITE (plugin, msg, 545 LOG_SQLITE (plugin, msg, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
569 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
570 "sqlite3_step"); 546 "sqlite3_step");
571 ret = GNUNET_SYSERR; 547 ret = GNUNET_SYSERR;
572 break; 548 break;
573 default: 549 default:
574 LOG_SQLITE (plugin, msg, 550 LOG_SQLITE (plugin, msg, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
575 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
576 "sqlite3_step"); 551 "sqlite3_step");
577 if (SQLITE_OK != sqlite3_reset (stmt)) 552 if (SQLITE_OK != sqlite3_reset (stmt))
578 LOG_SQLITE (plugin, NULL, 553 LOG_SQLITE (plugin, NULL,
579 GNUNET_ERROR_TYPE_ERROR | 554 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
580 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); 555 "sqlite3_reset");
581 database_shutdown (plugin); 556 database_shutdown (plugin);
582 database_setup (plugin->env->cfg, plugin); 557 database_setup (plugin->env->cfg, plugin);
583 return GNUNET_SYSERR; 558 return GNUNET_SYSERR;
584 } 559 }
585 if (SQLITE_OK != sqlite3_reset (stmt)) 560 if (SQLITE_OK != sqlite3_reset (stmt))
586 LOG_SQLITE (plugin, NULL, 561 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
587 GNUNET_ERROR_TYPE_ERROR | 562 "sqlite3_reset");
588 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
589 return ret; 563 return ret;
590} 564}
591 565
@@ -614,21 +588,17 @@ sqlite_plugin_put (void *cls,
614 * @return GNUNET_OK on success 588 * @return GNUNET_OK on success
615 */ 589 */
616static int 590static int
617sqlite_plugin_update (void *cls, 591sqlite_plugin_update (void *cls, uint64_t uid, int delta,
618 uint64_t uid, 592 struct GNUNET_TIME_Absolute expire, char **msg)
619 int delta, struct GNUNET_TIME_Absolute expire, char **msg)
620{ 593{
621 struct Plugin *plugin = cls; 594 struct Plugin *plugin = cls;
622 int n; 595 int n;
623 596
624 if ((SQLITE_OK != 597 if ((SQLITE_OK != sqlite3_bind_int (plugin->updPrio, 1, delta)) ||
625 sqlite3_bind_int (plugin->updPrio, 1, delta)) || 598 (SQLITE_OK != sqlite3_bind_int64 (plugin->updPrio, 2, expire.abs_value))
626 (SQLITE_OK != 599 || (SQLITE_OK != sqlite3_bind_int64 (plugin->updPrio, 3, uid)))
627 sqlite3_bind_int64 (plugin->updPrio, 2, expire.abs_value)) ||
628 (SQLITE_OK != sqlite3_bind_int64 (plugin->updPrio, 3, uid)))
629 { 600 {
630 LOG_SQLITE (plugin, msg, 601 LOG_SQLITE (plugin, msg, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
631 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
632 "sqlite3_bind_XXXX"); 602 "sqlite3_bind_XXXX");
633 if (SQLITE_OK != sqlite3_reset (plugin->updPrio)) 603 if (SQLITE_OK != sqlite3_reset (plugin->updPrio))
634 LOG_SQLITE (plugin, NULL, 604 LOG_SQLITE (plugin, NULL,
@@ -639,8 +609,7 @@ sqlite_plugin_update (void *cls,
639 } 609 }
640 n = sqlite3_step (plugin->updPrio); 610 n = sqlite3_step (plugin->updPrio);
641 if (SQLITE_OK != sqlite3_reset (plugin->updPrio)) 611 if (SQLITE_OK != sqlite3_reset (plugin->updPrio))
642 LOG_SQLITE (plugin, NULL, 612 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
643 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
644 "sqlite3_reset"); 613 "sqlite3_reset");
645 switch (n) 614 switch (n)
646 { 615 {
@@ -650,13 +619,11 @@ sqlite_plugin_update (void *cls,
650#endif 619#endif
651 return GNUNET_OK; 620 return GNUNET_OK;
652 case SQLITE_BUSY: 621 case SQLITE_BUSY:
653 LOG_SQLITE (plugin, msg, 622 LOG_SQLITE (plugin, msg, GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
654 GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
655 "sqlite3_step"); 623 "sqlite3_step");
656 return GNUNET_NO; 624 return GNUNET_NO;
657 default: 625 default:
658 LOG_SQLITE (plugin, msg, 626 LOG_SQLITE (plugin, msg, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
659 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
660 "sqlite3_step"); 627 "sqlite3_step");
661 return GNUNET_SYSERR; 628 return GNUNET_SYSERR;
662 } 629 }
@@ -673,8 +640,8 @@ sqlite_plugin_update (void *cls,
673 * @param proc_cls closure for 'proc' 640 * @param proc_cls closure for 'proc'
674 */ 641 */
675static void 642static void
676execute_get (struct Plugin *plugin, 643execute_get (struct Plugin *plugin, sqlite3_stmt * stmt,
677 sqlite3_stmt * stmt, PluginDatumProcessor proc, void *proc_cls) 644 PluginDatumProcessor proc, void *proc_cls)
678{ 645{
679 int n; 646 int n;
680 struct GNUNET_TIME_Absolute expiration; 647 struct GNUNET_TIME_Absolute expiration;
@@ -690,14 +657,13 @@ execute_get (struct Plugin *plugin,
690 rowid = sqlite3_column_int64 (stmt, 6); 657 rowid = sqlite3_column_int64 (stmt, 6);
691 if (sqlite3_column_bytes (stmt, 4) != sizeof (GNUNET_HashCode)) 658 if (sqlite3_column_bytes (stmt, 4) != sizeof (GNUNET_HashCode))
692 { 659 {
693 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, 660 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "sqlite",
694 "sqlite",
695 _ 661 _
696 ("Invalid data in database. Trying to fix (by deletion).\n")); 662 ("Invalid data in database. Trying to fix (by deletion).\n"));
697 if (SQLITE_OK != sqlite3_reset (stmt)) 663 if (SQLITE_OK != sqlite3_reset (stmt))
698 LOG_SQLITE (plugin, NULL, 664 LOG_SQLITE (plugin, NULL,
699 GNUNET_ERROR_TYPE_ERROR | 665 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
700 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); 666 "sqlite3_reset");
701 if (GNUNET_OK == delete_by_rowid (plugin, rowid)) 667 if (GNUNET_OK == delete_by_rowid (plugin, rowid))
702 plugin->env->duc (plugin->env->cls, 668 plugin->env->duc (plugin->env->cls,
703 -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); 669 -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
@@ -705,8 +671,7 @@ execute_get (struct Plugin *plugin,
705 } 671 }
706 expiration.abs_value = sqlite3_column_int64 (stmt, 3); 672 expiration.abs_value = sqlite3_column_int64 (stmt, 3);
707#if DEBUG_SQLITE 673#if DEBUG_SQLITE
708 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 674 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
709 "sqlite",
710 "Found reply in database with expiration %llu\n", 675 "Found reply in database with expiration %llu\n",
711 (unsigned long long) expiration.abs_value); 676 (unsigned long long) expiration.abs_value);
712#endif 677#endif
@@ -718,8 +683,8 @@ execute_get (struct Plugin *plugin,
718 expiration, rowid); 683 expiration, rowid);
719 if (SQLITE_OK != sqlite3_reset (stmt)) 684 if (SQLITE_OK != sqlite3_reset (stmt))
720 LOG_SQLITE (plugin, NULL, 685 LOG_SQLITE (plugin, NULL,
721 GNUNET_ERROR_TYPE_ERROR | 686 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
722 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); 687 "sqlite3_reset");
723 if ((GNUNET_NO == ret) && (GNUNET_OK == delete_by_rowid (plugin, rowid))) 688 if ((GNUNET_NO == ret) && (GNUNET_OK == delete_by_rowid (plugin, rowid)))
724 plugin->env->duc (plugin->env->cls, 689 plugin->env->duc (plugin->env->cls,
725 -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); 690 -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
@@ -728,29 +693,27 @@ execute_get (struct Plugin *plugin,
728 /* database must be empty */ 693 /* database must be empty */
729 if (SQLITE_OK != sqlite3_reset (stmt)) 694 if (SQLITE_OK != sqlite3_reset (stmt))
730 LOG_SQLITE (plugin, NULL, 695 LOG_SQLITE (plugin, NULL,
731 GNUNET_ERROR_TYPE_ERROR | 696 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
732 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); 697 "sqlite3_reset");
733 break; 698 break;
734 case SQLITE_BUSY: 699 case SQLITE_BUSY:
735 case SQLITE_ERROR: 700 case SQLITE_ERROR:
736 case SQLITE_MISUSE: 701 case SQLITE_MISUSE:
737 default: 702 default:
738 LOG_SQLITE (plugin, NULL, 703 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
739 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
740 "sqlite3_step"); 704 "sqlite3_step");
741 if (SQLITE_OK != sqlite3_reset (stmt)) 705 if (SQLITE_OK != sqlite3_reset (stmt))
742 LOG_SQLITE (plugin, NULL, 706 LOG_SQLITE (plugin, NULL,
743 GNUNET_ERROR_TYPE_ERROR | 707 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
744 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); 708 "sqlite3_reset");
745 GNUNET_break (0); 709 GNUNET_break (0);
746 database_shutdown (plugin); 710 database_shutdown (plugin);
747 database_setup (plugin->env->cfg, plugin); 711 database_setup (plugin->env->cfg, plugin);
748 break; 712 break;
749 } 713 }
750 if (SQLITE_OK != sqlite3_reset (stmt)) 714 if (SQLITE_OK != sqlite3_reset (stmt))
751 LOG_SQLITE (plugin, NULL, 715 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
752 GNUNET_ERROR_TYPE_ERROR | 716 "sqlite3_reset");
753 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
754 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 717 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
755} 718}
756 719
@@ -770,8 +733,7 @@ execute_get (struct Plugin *plugin,
770 * @param proc_cls closure for proc 733 * @param proc_cls closure for proc
771 */ 734 */
772static void 735static void
773sqlite_plugin_get_zero_anonymity (void *cls, 736sqlite_plugin_get_zero_anonymity (void *cls, uint64_t offset,
774 uint64_t offset,
775 enum GNUNET_BLOCK_Type type, 737 enum GNUNET_BLOCK_Type type,
776 PluginDatumProcessor proc, void *proc_cls) 738 PluginDatumProcessor proc, void *proc_cls)
777{ 739{
@@ -783,13 +745,12 @@ sqlite_plugin_get_zero_anonymity (void *cls,
783 if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) || 745 if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) ||
784 (SQLITE_OK != sqlite3_bind_int64 (stmt, 2, offset))) 746 (SQLITE_OK != sqlite3_bind_int64 (stmt, 2, offset)))
785 { 747 {
786 LOG_SQLITE (plugin, NULL, 748 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
787 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
788 "sqlite3_bind_XXXX"); 749 "sqlite3_bind_XXXX");
789 if (SQLITE_OK != sqlite3_reset (stmt)) 750 if (SQLITE_OK != sqlite3_reset (stmt))
790 LOG_SQLITE (plugin, NULL, 751 LOG_SQLITE (plugin, NULL,
791 GNUNET_ERROR_TYPE_ERROR | 752 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
792 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); 753 "sqlite3_reset");
793 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 754 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
794 return; 755 return;
795 } 756 }
@@ -816,12 +777,10 @@ sqlite_plugin_get_zero_anonymity (void *cls,
816 * @param proc_cls closure for proc 777 * @param proc_cls closure for proc
817 */ 778 */
818static void 779static void
819sqlite_plugin_get_key (void *cls, 780sqlite_plugin_get_key (void *cls, uint64_t offset, const GNUNET_HashCode * key,
820 uint64_t offset,
821 const GNUNET_HashCode * key,
822 const GNUNET_HashCode * vhash, 781 const GNUNET_HashCode * vhash,
823 enum GNUNET_BLOCK_Type type, 782 enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc,
824 PluginDatumProcessor proc, void *proc_cls) 783 void *proc_cls)
825{ 784{
826 struct Plugin *plugin = cls; 785 struct Plugin *plugin = cls;
827 int ret; 786 int ret;
@@ -839,18 +798,19 @@ sqlite_plugin_get_key (void *cls,
839 type == 0 ? "" : " AND type=?"); 798 type == 0 ? "" : " AND type=?");
840 if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK) 799 if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK)
841 { 800 {
842 LOG_SQLITE (plugin, NULL, 801 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
843 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
844 "sqlite_prepare"); 802 "sqlite_prepare");
845 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 803 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
846 return; 804 return;
847 } 805 }
848 sqoff = 1; 806 sqoff = 1;
849 ret = sqlite3_bind_blob (stmt, sqoff++, 807 ret =
850 key, sizeof (GNUNET_HashCode), SQLITE_TRANSIENT); 808 sqlite3_bind_blob (stmt, sqoff++, key, sizeof (GNUNET_HashCode),
809 SQLITE_TRANSIENT);
851 if ((vhash != NULL) && (ret == SQLITE_OK)) 810 if ((vhash != NULL) && (ret == SQLITE_OK))
852 ret = sqlite3_bind_blob (stmt, sqoff++, 811 ret =
853 vhash, sizeof (GNUNET_HashCode), SQLITE_TRANSIENT); 812 sqlite3_bind_blob (stmt, sqoff++, vhash, sizeof (GNUNET_HashCode),
813 SQLITE_TRANSIENT);
854 if ((type != 0) && (ret == SQLITE_OK)) 814 if ((type != 0) && (ret == SQLITE_OK))
855 ret = sqlite3_bind_int (stmt, sqoff++, type); 815 ret = sqlite3_bind_int (stmt, sqoff++, type);
856 if (SQLITE_OK != ret) 816 if (SQLITE_OK != ret)
@@ -863,8 +823,7 @@ sqlite_plugin_get_key (void *cls,
863 ret = sqlite3_step (stmt); 823 ret = sqlite3_step (stmt);
864 if (ret != SQLITE_ROW) 824 if (ret != SQLITE_ROW)
865 { 825 {
866 LOG_SQLITE (plugin, NULL, 826 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
867 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
868 "sqlite_step"); 827 "sqlite_step");
869 sqlite3_finalize (stmt); 828 sqlite3_finalize (stmt);
870 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 829 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
@@ -888,29 +847,27 @@ sqlite_plugin_get_key (void *cls,
888 type == 0 ? "" : " AND type=?"); 847 type == 0 ? "" : " AND type=?");
889 if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK) 848 if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK)
890 { 849 {
891 LOG_SQLITE (plugin, NULL, 850 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
892 GNUNET_ERROR_TYPE_ERROR | 851 "sqlite_prepare");
893 GNUNET_ERROR_TYPE_BULK, "sqlite_prepare");
894 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 852 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
895 return; 853 return;
896 } 854 }
897 sqoff = 1; 855 sqoff = 1;
898 ret = sqlite3_bind_blob (stmt, 856 ret =
899 sqoff++, 857 sqlite3_bind_blob (stmt, sqoff++, key, sizeof (GNUNET_HashCode),
900 key, sizeof (GNUNET_HashCode), SQLITE_TRANSIENT); 858 SQLITE_TRANSIENT);
901 if ((vhash != NULL) && (ret == SQLITE_OK)) 859 if ((vhash != NULL) && (ret == SQLITE_OK))
902 ret = sqlite3_bind_blob (stmt, 860 ret =
903 sqoff++, 861 sqlite3_bind_blob (stmt, sqoff++, vhash, sizeof (GNUNET_HashCode),
904 vhash, sizeof (GNUNET_HashCode), SQLITE_TRANSIENT); 862 SQLITE_TRANSIENT);
905 if ((type != 0) && (ret == SQLITE_OK)) 863 if ((type != 0) && (ret == SQLITE_OK))
906 ret = sqlite3_bind_int (stmt, sqoff++, type); 864 ret = sqlite3_bind_int (stmt, sqoff++, type);
907 if (ret == SQLITE_OK) 865 if (ret == SQLITE_OK)
908 ret = sqlite3_bind_int64 (stmt, sqoff++, limit_off); 866 ret = sqlite3_bind_int64 (stmt, sqoff++, limit_off);
909 if (ret != SQLITE_OK) 867 if (ret != SQLITE_OK)
910 { 868 {
911 LOG_SQLITE (plugin, NULL, 869 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
912 GNUNET_ERROR_TYPE_ERROR | 870 "sqlite_bind");
913 GNUNET_ERROR_TYPE_BULK, "sqlite_bind");
914 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 871 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
915 return; 872 return;
916 } 873 }
@@ -968,20 +925,17 @@ struct ReplCtx
968 * GNUNET_NO to delete the item 925 * GNUNET_NO to delete the item
969 */ 926 */
970static int 927static int
971repl_proc (void *cls, 928repl_proc (void *cls, const GNUNET_HashCode * key, uint32_t size,
972 const GNUNET_HashCode * key, 929 const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority,
973 uint32_t size, 930 uint32_t anonymity, struct GNUNET_TIME_Absolute expiration,
974 const void *data, 931 uint64_t uid)
975 enum GNUNET_BLOCK_Type type,
976 uint32_t priority,
977 uint32_t anonymity,
978 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
979{ 932{
980 struct ReplCtx *rc = cls; 933 struct ReplCtx *rc = cls;
981 int ret; 934 int ret;
982 935
983 ret = rc->proc (rc->proc_cls, 936 ret =
984 key, size, data, type, priority, anonymity, expiration, uid); 937 rc->proc (rc->proc_cls, key, size, data, type, priority, anonymity,
938 expiration, uid);
985 if (key != NULL) 939 if (key != NULL)
986 { 940 {
987 rc->uid = uid; 941 rc->uid = uid;
@@ -1002,8 +956,8 @@ repl_proc (void *cls,
1002 * @param proc_cls closure for proc 956 * @param proc_cls closure for proc
1003 */ 957 */
1004static void 958static void
1005sqlite_plugin_get_replication (void *cls, 959sqlite_plugin_get_replication (void *cls, PluginDatumProcessor proc,
1006 PluginDatumProcessor proc, void *proc_cls) 960 void *proc_cls)
1007{ 961{
1008 struct Plugin *plugin = cls; 962 struct Plugin *plugin = cls;
1009 struct ReplCtx rc; 963 struct ReplCtx rc;
@@ -1012,8 +966,7 @@ sqlite_plugin_get_replication (void *cls,
1012 sqlite3_stmt *stmt; 966 sqlite3_stmt *stmt;
1013 967
1014#if DEBUG_SQLITE 968#if DEBUG_SQLITE
1015 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 969 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
1016 "sqlite",
1017 "Getting random block based on replication order.\n"); 970 "Getting random block based on replication order.\n");
1018#endif 971#endif
1019 rc.have_uid = GNUNET_NO; 972 rc.have_uid = GNUNET_NO;
@@ -1024,23 +977,21 @@ sqlite_plugin_get_replication (void *cls,
1024 { 977 {
1025 if (SQLITE_OK != sqlite3_reset (stmt)) 978 if (SQLITE_OK != sqlite3_reset (stmt))
1026 LOG_SQLITE (plugin, NULL, 979 LOG_SQLITE (plugin, NULL,
1027 GNUNET_ERROR_TYPE_ERROR | 980 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1028 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); 981 "sqlite3_reset");
1029 /* DB empty */ 982 /* DB empty */
1030 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 983 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1031 return; 984 return;
1032 } 985 }
1033 repl = sqlite3_column_int (stmt, 0); 986 repl = sqlite3_column_int (stmt, 0);
1034 if (SQLITE_OK != sqlite3_reset (stmt)) 987 if (SQLITE_OK != sqlite3_reset (stmt))
1035 LOG_SQLITE (plugin, NULL, 988 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1036 GNUNET_ERROR_TYPE_ERROR | 989 "sqlite3_reset");
1037 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
1038 stmt = plugin->selRepl; 990 stmt = plugin->selRepl;
1039 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); 991 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
1040 if (SQLITE_OK != sqlite3_bind_int64 (stmt, 1, rvalue)) 992 if (SQLITE_OK != sqlite3_bind_int64 (stmt, 1, rvalue))
1041 { 993 {
1042 LOG_SQLITE (plugin, NULL, 994 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1043 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1044 "sqlite3_bind_XXXX"); 995 "sqlite3_bind_XXXX");
1045 if (SQLITE_OK != sqlite3_reset (stmt)) 996 if (SQLITE_OK != sqlite3_reset (stmt))
1046 LOG_SQLITE (plugin, NULL, 997 LOG_SQLITE (plugin, NULL,
@@ -1051,8 +1002,7 @@ sqlite_plugin_get_replication (void *cls,
1051 } 1002 }
1052 if (SQLITE_OK != sqlite3_bind_int (stmt, 2, repl)) 1003 if (SQLITE_OK != sqlite3_bind_int (stmt, 2, repl))
1053 { 1004 {
1054 LOG_SQLITE (plugin, NULL, 1005 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1055 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1056 "sqlite3_bind_XXXX"); 1006 "sqlite3_bind_XXXX");
1057 if (SQLITE_OK != sqlite3_reset (stmt)) 1007 if (SQLITE_OK != sqlite3_reset (stmt))
1058 LOG_SQLITE (plugin, NULL, 1008 LOG_SQLITE (plugin, NULL,
@@ -1071,18 +1021,18 @@ sqlite_plugin_get_replication (void *cls,
1071 "sqlite3_bind_XXXX"); 1021 "sqlite3_bind_XXXX");
1072 if (SQLITE_OK != sqlite3_reset (plugin->updRepl)) 1022 if (SQLITE_OK != sqlite3_reset (plugin->updRepl))
1073 LOG_SQLITE (plugin, NULL, 1023 LOG_SQLITE (plugin, NULL,
1074 GNUNET_ERROR_TYPE_ERROR | 1024 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1075 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); 1025 "sqlite3_reset");
1076 return; 1026 return;
1077 } 1027 }
1078 if (SQLITE_DONE != sqlite3_step (plugin->updRepl)) 1028 if (SQLITE_DONE != sqlite3_step (plugin->updRepl))
1079 LOG_SQLITE (plugin, NULL, 1029 LOG_SQLITE (plugin, NULL,
1080 GNUNET_ERROR_TYPE_ERROR | 1030 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1081 GNUNET_ERROR_TYPE_BULK, "sqlite3_step"); 1031 "sqlite3_step");
1082 if (SQLITE_OK != sqlite3_reset (plugin->updRepl)) 1032 if (SQLITE_OK != sqlite3_reset (plugin->updRepl))
1083 LOG_SQLITE (plugin, NULL, 1033 LOG_SQLITE (plugin, NULL,
1084 GNUNET_ERROR_TYPE_ERROR | 1034 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1085 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); 1035 "sqlite3_reset");
1086 } 1036 }
1087} 1037}
1088 1038
@@ -1097,24 +1047,22 @@ sqlite_plugin_get_replication (void *cls,
1097 * @param proc_cls closure for proc 1047 * @param proc_cls closure for proc
1098 */ 1048 */
1099static void 1049static void
1100sqlite_plugin_get_expiration (void *cls, 1050sqlite_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
1101 PluginDatumProcessor proc, void *proc_cls) 1051 void *proc_cls)
1102{ 1052{
1103 struct Plugin *plugin = cls; 1053 struct Plugin *plugin = cls;
1104 sqlite3_stmt *stmt; 1054 sqlite3_stmt *stmt;
1105 struct GNUNET_TIME_Absolute now; 1055 struct GNUNET_TIME_Absolute now;
1106 1056
1107#if DEBUG_SQLITE 1057#if DEBUG_SQLITE
1108 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1058 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
1109 "sqlite",
1110 "Getting random block based on expiration and priority order.\n"); 1059 "Getting random block based on expiration and priority order.\n");
1111#endif 1060#endif
1112 now = GNUNET_TIME_absolute_get (); 1061 now = GNUNET_TIME_absolute_get ();
1113 stmt = plugin->selExpi; 1062 stmt = plugin->selExpi;
1114 if (SQLITE_OK != sqlite3_bind_int64 (stmt, 1, now.abs_value)) 1063 if (SQLITE_OK != sqlite3_bind_int64 (stmt, 1, now.abs_value))
1115 { 1064 {
1116 LOG_SQLITE (plugin, NULL, 1065 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1117 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1118 "sqlite3_bind_XXXX"); 1066 "sqlite3_bind_XXXX");
1119 if (SQLITE_OK != sqlite3_reset (stmt)) 1067 if (SQLITE_OK != sqlite3_reset (stmt))
1120 LOG_SQLITE (plugin, NULL, 1068 LOG_SQLITE (plugin, NULL,
@@ -1162,16 +1110,15 @@ sqlite_plugin_estimate_size (void *cls)
1162 1110
1163 if (SQLITE_VERSION_NUMBER < 3006000) 1111 if (SQLITE_VERSION_NUMBER < 3006000)
1164 { 1112 {
1165 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, 1113 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "datastore-sqlite",
1166 "datastore-sqlite",
1167 _ 1114 _
1168 ("sqlite version to old to determine size, assuming zero\n")); 1115 ("sqlite version to old to determine size, assuming zero\n"));
1169 return 0; 1116 return 0;
1170 } 1117 }
1171 CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh, "VACUUM", NULL, NULL, ENULL)); 1118 CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh, "VACUUM", NULL, NULL, ENULL));
1172 CHECK (SQLITE_OK == 1119 CHECK (SQLITE_OK ==
1173 sqlite3_exec (plugin->dbh, 1120 sqlite3_exec (plugin->dbh, "PRAGMA auto_vacuum=INCREMENTAL", NULL,
1174 "PRAGMA auto_vacuum=INCREMENTAL", NULL, NULL, ENULL)); 1121 NULL, ENULL));
1175 CHECK (SQLITE_OK == sq_prepare (plugin->dbh, "PRAGMA page_count", &stmt)); 1122 CHECK (SQLITE_OK == sq_prepare (plugin->dbh, "PRAGMA page_count", &stmt));
1176 if (SQLITE_ROW == sqlite3_step (stmt)) 1123 if (SQLITE_ROW == sqlite3_step (stmt))
1177 pages = sqlite3_column_int64 (stmt, 0); 1124 pages = sqlite3_column_int64 (stmt, 0);
@@ -1222,8 +1169,8 @@ libgnunet_plugin_datastore_sqlite_init (void *cls)
1222 api->get_expiration = &sqlite_plugin_get_expiration; 1169 api->get_expiration = &sqlite_plugin_get_expiration;
1223 api->get_zero_anonymity = &sqlite_plugin_get_zero_anonymity; 1170 api->get_zero_anonymity = &sqlite_plugin_get_zero_anonymity;
1224 api->drop = &sqlite_plugin_drop; 1171 api->drop = &sqlite_plugin_drop;
1225 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, 1172 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "sqlite",
1226 "sqlite", _("Sqlite database running\n")); 1173 _("Sqlite database running\n"));
1227 return api; 1174 return api;
1228} 1175}
1229 1176
@@ -1242,16 +1189,16 @@ libgnunet_plugin_datastore_sqlite_done (void *cls)
1242 struct Plugin *plugin = api->cls; 1189 struct Plugin *plugin = api->cls;
1243 1190
1244#if DEBUG_SQLITE 1191#if DEBUG_SQLITE
1245 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1192 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
1246 "sqlite", "sqlite plugin is done\n"); 1193 "sqlite plugin is done\n");
1247#endif 1194#endif
1248 1195
1249 fn = NULL; 1196 fn = NULL;
1250 if (plugin->drop_on_shutdown) 1197 if (plugin->drop_on_shutdown)
1251 fn = GNUNET_strdup (plugin->fn); 1198 fn = GNUNET_strdup (plugin->fn);
1252#if DEBUG_SQLITE 1199#if DEBUG_SQLITE
1253 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1200 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
1254 "sqlite", "Shutting down database\n"); 1201 "Shutting down database\n");
1255#endif 1202#endif
1256 database_shutdown (plugin); 1203 database_shutdown (plugin);
1257 plugin->env = NULL; 1204 plugin->env = NULL;
@@ -1263,8 +1210,8 @@ libgnunet_plugin_datastore_sqlite_done (void *cls)
1263 GNUNET_free (fn); 1210 GNUNET_free (fn);
1264 } 1211 }
1265#if DEBUG_SQLITE 1212#if DEBUG_SQLITE
1266 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1213 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
1267 "sqlite", "sqlite plugin is finished\n"); 1214 "sqlite plugin is finished\n");
1268#endif 1215#endif
1269 return NULL; 1216 return NULL;
1270} 1217}
diff --git a/src/datastore/plugin_datastore_template.c b/src/datastore/plugin_datastore_template.c
index 7ab469140..566155fb5 100644
--- a/src/datastore/plugin_datastore_template.c
+++ b/src/datastore/plugin_datastore_template.c
@@ -71,13 +71,9 @@ template_plugin_estimate_size (void *cls)
71 * @return GNUNET_OK on success 71 * @return GNUNET_OK on success
72 */ 72 */
73static int 73static int
74template_plugin_put (void *cls, 74template_plugin_put (void *cls, const GNUNET_HashCode * key, uint32_t size,
75 const GNUNET_HashCode * key, 75 const void *data, enum GNUNET_BLOCK_Type type,
76 uint32_t size, 76 uint32_t priority, uint32_t anonymity,
77 const void *data,
78 enum GNUNET_BLOCK_Type type,
79 uint32_t priority,
80 uint32_t anonymity,
81 uint32_t replication, 77 uint32_t replication,
82 struct GNUNET_TIME_Absolute expiration, char **msg) 78 struct GNUNET_TIME_Absolute expiration, char **msg)
83{ 79{
@@ -106,12 +102,11 @@ template_plugin_put (void *cls,
106 * @param proc_cls closure for proc 102 * @param proc_cls closure for proc
107 */ 103 */
108static void 104static void
109template_plugin_get_key (void *cls, 105template_plugin_get_key (void *cls, uint64_t offset,
110 uint64_t offset,
111 const GNUNET_HashCode * key, 106 const GNUNET_HashCode * key,
112 const GNUNET_HashCode * vhash, 107 const GNUNET_HashCode * vhash,
113 enum GNUNET_BLOCK_Type type, 108 enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc,
114 PluginDatumProcessor proc, void *proc_cls) 109 void *proc_cls)
115{ 110{
116 GNUNET_break (0); 111 GNUNET_break (0);
117} 112}
@@ -130,8 +125,8 @@ template_plugin_get_key (void *cls,
130 * @param proc_cls closure for proc 125 * @param proc_cls closure for proc
131 */ 126 */
132static void 127static void
133template_plugin_get_replication (void *cls, 128template_plugin_get_replication (void *cls, PluginDatumProcessor proc,
134 PluginDatumProcessor proc, void *proc_cls) 129 void *proc_cls)
135{ 130{
136 GNUNET_break (0); 131 GNUNET_break (0);
137} 132}
@@ -146,8 +141,8 @@ template_plugin_get_replication (void *cls,
146 * @param proc_cls closure for proc 141 * @param proc_cls closure for proc
147 */ 142 */
148static void 143static void
149template_plugin_get_expiration (void *cls, 144template_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
150 PluginDatumProcessor proc, void *proc_cls) 145 void *proc_cls)
151{ 146{
152 GNUNET_break (0); 147 GNUNET_break (0);
153} 148}
@@ -177,9 +172,7 @@ template_plugin_get_expiration (void *cls,
177 * @return GNUNET_OK on success 172 * @return GNUNET_OK on success
178 */ 173 */
179static int 174static int
180template_plugin_update (void *cls, 175template_plugin_update (void *cls, uint64_t uid, int delta,
181 uint64_t uid,
182 int delta,
183 struct GNUNET_TIME_Absolute expire, char **msg) 176 struct GNUNET_TIME_Absolute expire, char **msg)
184{ 177{
185 GNUNET_break (0); 178 GNUNET_break (0);
@@ -201,8 +194,7 @@ template_plugin_update (void *cls,
201 * @param proc_cls closure for proc 194 * @param proc_cls closure for proc
202 */ 195 */
203static void 196static void
204template_plugin_get_zero_anonymity (void *cls, 197template_plugin_get_zero_anonymity (void *cls, uint64_t offset,
205 uint64_t offset,
206 enum GNUNET_BLOCK_Type type, 198 enum GNUNET_BLOCK_Type type,
207 PluginDatumProcessor proc, void *proc_cls) 199 PluginDatumProcessor proc, void *proc_cls)
208{ 200{
@@ -245,8 +237,8 @@ libgnunet_plugin_datastore_template_init (void *cls)
245 api->get_expiration = &template_plugin_get_expiration; 237 api->get_expiration = &template_plugin_get_expiration;
246 api->get_zero_anonymity = &template_plugin_get_zero_anonymity; 238 api->get_zero_anonymity = &template_plugin_get_zero_anonymity;
247 api->drop = &template_plugin_drop; 239 api->drop = &template_plugin_drop;
248 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, 240 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "template",
249 "template", _("Template database running\n")); 241 _("Template database running\n"));
250 return api; 242 return api;
251} 243}
252 244
diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c
index 39b7a1ae2..3dff4a588 100644
--- a/src/datastore/test_datastore_api.c
+++ b/src/datastore/test_datastore_api.c
@@ -134,8 +134,8 @@ struct CpsRunContext
134}; 134};
135 135
136 136
137static void 137static void run_continuation (void *cls,
138run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 138 const struct GNUNET_SCHEDULER_TaskContext *tc);
139 139
140 140
141static void 141static void
@@ -146,14 +146,14 @@ check_success (void *cls, int success, const char *msg)
146 if (GNUNET_OK != success) 146 if (GNUNET_OK != success)
147 { 147 {
148 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 148 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
149 "Operation %d/%d not successfull: `%s'\n", 149 "Operation %d/%d not successfull: `%s'\n", crc->phase, crc->i,
150 crc->phase, crc->i, msg); 150 msg);
151 crc->phase = RP_ERROR; 151 crc->phase = RP_ERROR;
152 } 152 }
153 GNUNET_free_non_null (crc->data); 153 GNUNET_free_non_null (crc->data);
154 crc->data = NULL; 154 crc->data = NULL;
155 GNUNET_SCHEDULER_add_continuation (&run_continuation, 155 GNUNET_SCHEDULER_add_continuation (&run_continuation, crc,
156 crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 156 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
157} 157}
158 158
159 159
@@ -163,40 +163,33 @@ get_reserved (void *cls, int success, const char *msg)
163 struct CpsRunContext *crc = cls; 163 struct CpsRunContext *crc = cls;
164 164
165 if (0 >= success) 165 if (0 >= success)
166 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 166 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error obtaining reservation: `%s'\n",
167 "Error obtaining reservation: `%s'\n", msg); 167 msg);
168 GNUNET_assert (0 < success); 168 GNUNET_assert (0 < success);
169 crc->rid = success; 169 crc->rid = success;
170 GNUNET_SCHEDULER_add_continuation (&run_continuation, 170 GNUNET_SCHEDULER_add_continuation (&run_continuation, crc,
171 crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 171 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
172} 172}
173 173
174 174
175static void 175static void
176check_value (void *cls, 176check_value (void *cls, const GNUNET_HashCode * key, size_t size,
177 const GNUNET_HashCode * key, 177 const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority,
178 size_t size, 178 uint32_t anonymity, struct GNUNET_TIME_Absolute expiration,
179 const void *data, 179 uint64_t uid)
180 enum GNUNET_BLOCK_Type type,
181 uint32_t priority,
182 uint32_t anonymity,
183 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
184{ 180{
185 struct CpsRunContext *crc = cls; 181 struct CpsRunContext *crc = cls;
186 int i; 182 int i;
187 183
188 i = crc->i; 184 i = crc->i;
189#if 0 185#if 0
186 fprintf (stderr, "Check value got `%s' of size %u, type %d, expire %llu\n",
187 GNUNET_h2s (key), (unsigned int) size, type,
188 (unsigned long long) expiration.abs_value);
190 fprintf (stderr, 189 fprintf (stderr,
191 "Check value got `%s' of size %u, type %d, expire %llu\n", 190 "Check value iteration %d wants size %u, type %d, expire %llu\n", i,
192 GNUNET_h2s (key), 191 (unsigned int) get_size (i), get_type (i),
193 (unsigned int) size, 192 (unsigned long long) get_expiration (i).abs_value);
194 type, (unsigned long long) expiration.abs_value);
195 fprintf (stderr,
196 "Check value iteration %d wants size %u, type %d, expire %llu\n",
197 i,
198 (unsigned int) get_size (i),
199 get_type (i), (unsigned long long) get_expiration (i).abs_value);
200#endif 193#endif
201 GNUNET_assert (size == get_size (i)); 194 GNUNET_assert (size == get_size (i));
202 GNUNET_assert (0 == memcmp (data, get_data (i), size)); 195 GNUNET_assert (0 == memcmp (data, get_data (i), size));
@@ -210,20 +203,16 @@ check_value (void *cls,
210 crc->phase = RP_DEL; 203 crc->phase = RP_DEL;
211 crc->i = ITERATIONS; 204 crc->i = ITERATIONS;
212 } 205 }
213 GNUNET_SCHEDULER_add_continuation (&run_continuation, 206 GNUNET_SCHEDULER_add_continuation (&run_continuation, crc,
214 crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 207 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
215} 208}
216 209
217 210
218static void 211static void
219delete_value (void *cls, 212delete_value (void *cls, const GNUNET_HashCode * key, size_t size,
220 const GNUNET_HashCode * key, 213 const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority,
221 size_t size, 214 uint32_t anonymity, struct GNUNET_TIME_Absolute expiration,
222 const void *data, 215 uint64_t uid)
223 enum GNUNET_BLOCK_Type type,
224 uint32_t priority,
225 uint32_t anonymity,
226 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
227{ 216{
228 struct CpsRunContext *crc = cls; 217 struct CpsRunContext *crc = cls;
229 218
@@ -234,39 +223,31 @@ delete_value (void *cls,
234 crc->data = GNUNET_malloc (size); 223 crc->data = GNUNET_malloc (size);
235 memcpy (crc->data, data, size); 224 memcpy (crc->data, data, size);
236 crc->phase = RP_DO_DEL; 225 crc->phase = RP_DO_DEL;
237 GNUNET_SCHEDULER_add_continuation (&run_continuation, 226 GNUNET_SCHEDULER_add_continuation (&run_continuation, crc,
238 crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 227 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
239} 228}
240 229
241 230
242static void 231static void
243check_nothing (void *cls, 232check_nothing (void *cls, const GNUNET_HashCode * key, size_t size,
244 const GNUNET_HashCode * key, 233 const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority,
245 size_t size, 234 uint32_t anonymity, struct GNUNET_TIME_Absolute expiration,
246 const void *data, 235 uint64_t uid)
247 enum GNUNET_BLOCK_Type type,
248 uint32_t priority,
249 uint32_t anonymity,
250 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
251{ 236{
252 struct CpsRunContext *crc = cls; 237 struct CpsRunContext *crc = cls;
253 238
254 GNUNET_assert (key == NULL); 239 GNUNET_assert (key == NULL);
255 if (crc->i == 0) 240 if (crc->i == 0)
256 crc->phase = RP_RESERVE; 241 crc->phase = RP_RESERVE;
257 GNUNET_SCHEDULER_add_continuation (&run_continuation, 242 GNUNET_SCHEDULER_add_continuation (&run_continuation, crc,
258 crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 243 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
259} 244}
260 245
261 246
262static void 247static void
263check_multiple (void *cls, 248check_multiple (void *cls, const GNUNET_HashCode * key, size_t size,
264 const GNUNET_HashCode * key, 249 const void *data, enum GNUNET_BLOCK_Type type,
265 size_t size, 250 uint32_t priority, uint32_t anonymity,
266 const void *data,
267 enum GNUNET_BLOCK_Type type,
268 uint32_t priority,
269 uint32_t anonymity,
270 struct GNUNET_TIME_Absolute expiration, uint64_t uid) 251 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
271{ 252{
272 struct CpsRunContext *crc = cls; 253 struct CpsRunContext *crc = cls;
@@ -290,34 +271,30 @@ check_multiple (void *cls,
290 } 271 }
291 if (priority == get_priority (42)) 272 if (priority == get_priority (42))
292 crc->uid = uid; 273 crc->uid = uid;
293 GNUNET_SCHEDULER_add_continuation (&run_continuation, 274 GNUNET_SCHEDULER_add_continuation (&run_continuation, crc,
294 crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 275 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
295} 276}
296 277
297 278
298static void 279static void
299check_update (void *cls, 280check_update (void *cls, const GNUNET_HashCode * key, size_t size,
300 const GNUNET_HashCode * key, 281 const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority,
301 size_t size, 282 uint32_t anonymity, struct GNUNET_TIME_Absolute expiration,
302 const void *data, 283 uint64_t uid)
303 enum GNUNET_BLOCK_Type type,
304 uint32_t priority,
305 uint32_t anonymity,
306 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
307{ 284{
308 struct CpsRunContext *crc = cls; 285 struct CpsRunContext *crc = cls;
309 286
310 GNUNET_assert (key != NULL); 287 GNUNET_assert (key != NULL);
311 if ((anonymity == get_anonymity (42)) && 288 if ((anonymity == get_anonymity (42)) && (size == get_size (42)) &&
312 (size == get_size (42)) && (priority == get_priority (42) + 100)) 289 (priority == get_priority (42) + 100))
313 crc->phase = RP_DONE; 290 crc->phase = RP_DONE;
314 else 291 else
315 { 292 {
316 GNUNET_assert (size == get_size (43)); 293 GNUNET_assert (size == get_size (43));
317 crc->offset++; 294 crc->offset++;
318 } 295 }
319 GNUNET_SCHEDULER_add_continuation (&run_continuation, 296 GNUNET_SCHEDULER_add_continuation (&run_continuation, crc,
320 crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 297 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
321} 298}
322 299
323 300
@@ -334,21 +311,15 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
334 { 311 {
335 case RP_PUT: 312 case RP_PUT:
336#if VERBOSE 313#if VERBOSE
337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "PUT",
338 "Executing `%s' number %u\n", "PUT", crc->i); 315 crc->i);
339#endif 316#endif
340 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); 317 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
341 GNUNET_DATASTORE_put (datastore, 318 GNUNET_DATASTORE_put (datastore, 0, &crc->key, get_size (crc->i),
342 0, 319 get_data (crc->i), get_type (crc->i),
343 &crc->key, 320 get_priority (crc->i), get_anonymity (crc->i), 0,
344 get_size (crc->i), 321 get_expiration (crc->i), 1, 1, TIMEOUT,
345 get_data (crc->i), 322 &check_success, crc);
346 get_type (crc->i),
347 get_priority (crc->i),
348 get_anonymity (crc->i),
349 0,
350 get_expiration (crc->i),
351 1, 1, TIMEOUT, &check_success, crc);
352 crc->i++; 323 crc->i++;
353 if (crc->i == ITERATIONS) 324 if (crc->i == ITERATIONS)
354 crc->phase = RP_GET; 325 crc->phase = RP_GET;
@@ -356,36 +327,31 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
356 case RP_GET: 327 case RP_GET:
357 crc->i--; 328 crc->i--;
358#if VERBOSE 329#if VERBOSE
359 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 330 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "GET",
360 "Executing `%s' number %u\n", "GET", crc->i); 331 crc->i);
361#endif 332#endif
362 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); 333 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
363 GNUNET_DATASTORE_get_key (datastore, 334 GNUNET_DATASTORE_get_key (datastore, crc->offset, &crc->key,
364 crc->offset, 335 get_type (crc->i), 1, 1, TIMEOUT, &check_value,
365 &crc->key, 336 crc);
366 get_type (crc->i),
367 1, 1, TIMEOUT, &check_value, crc);
368 break; 337 break;
369 case RP_DEL: 338 case RP_DEL:
370 crc->i--; 339 crc->i--;
371#if VERBOSE 340#if VERBOSE
372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 341 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "DEL",
373 "Executing `%s' number %u\n", "DEL", crc->i); 342 crc->i);
374#endif 343#endif
375 crc->data = NULL; 344 crc->data = NULL;
376 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); 345 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
377 GNUNET_assert (NULL != 346 GNUNET_assert (NULL !=
378 GNUNET_DATASTORE_get_key (datastore, 347 GNUNET_DATASTORE_get_key (datastore, crc->offset, &crc->key,
379 crc->offset, 348 get_type (crc->i), 1, 1, TIMEOUT,
380 &crc->key,
381 get_type (crc->i),
382 1, 1, TIMEOUT,
383 &delete_value, crc)); 349 &delete_value, crc));
384 break; 350 break;
385 case RP_DO_DEL: 351 case RP_DO_DEL:
386#if VERBOSE 352#if VERBOSE
387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 353 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "DO_DEL",
388 "Executing `%s' number %u\n", "DO_DEL", crc->i); 354 crc->i);
389#endif 355#endif
390 if (crc->i == 0) 356 if (crc->i == 0)
391 { 357 {
@@ -397,95 +363,63 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
397 crc->phase = RP_DEL; 363 crc->phase = RP_DEL;
398 } 364 }
399 GNUNET_assert (NULL != 365 GNUNET_assert (NULL !=
400 GNUNET_DATASTORE_remove (datastore, 366 GNUNET_DATASTORE_remove (datastore, &crc->key, crc->size,
401 &crc->key, 367 crc->data, 1, 1, TIMEOUT,
402 crc->size,
403 crc->data,
404 1, 1, TIMEOUT,
405 &check_success, crc)); 368 &check_success, crc));
406 break; 369 break;
407 case RP_DELVALIDATE: 370 case RP_DELVALIDATE:
408 crc->i--; 371 crc->i--;
409#if VERBOSE 372#if VERBOSE
410 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 373 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n",
411 "Executing `%s' number %u\n", "DEL-VALIDATE", crc->i); 374 "DEL-VALIDATE", crc->i);
412#endif 375#endif
413 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); 376 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
414 GNUNET_assert (NULL != 377 GNUNET_assert (NULL !=
415 GNUNET_DATASTORE_get_key (datastore, 378 GNUNET_DATASTORE_get_key (datastore, crc->offset, &crc->key,
416 crc->offset, 379 get_type (crc->i), 1, 1, TIMEOUT,
417 &crc->key,
418 get_type (crc->i),
419 1, 1, TIMEOUT,
420 &check_nothing, crc)); 380 &check_nothing, crc));
421 break; 381 break;
422 case RP_RESERVE: 382 case RP_RESERVE:
423 crc->phase = RP_PUT_MULTIPLE; 383 crc->phase = RP_PUT_MULTIPLE;
424 GNUNET_DATASTORE_reserve (datastore, 384 GNUNET_DATASTORE_reserve (datastore, 128 * 1024, 2, 1, 1, TIMEOUT,
425 128 * 1024, 2, 1, 1, TIMEOUT, &get_reserved, crc); 385 &get_reserved, crc);
426 break; 386 break;
427 case RP_PUT_MULTIPLE: 387 case RP_PUT_MULTIPLE:
428 crc->phase = RP_PUT_MULTIPLE_NEXT; 388 crc->phase = RP_PUT_MULTIPLE_NEXT;
429 GNUNET_DATASTORE_put (datastore, 389 GNUNET_DATASTORE_put (datastore, crc->rid, &crc->key, get_size (42),
430 crc->rid, 390 get_data (42), get_type (42), get_priority (42),
431 &crc->key, 391 get_anonymity (42), 0, get_expiration (42), 1, 1,
432 get_size (42), 392 TIMEOUT, &check_success, crc);
433 get_data (42),
434 get_type (42),
435 get_priority (42),
436 get_anonymity (42),
437 0,
438 get_expiration (42),
439 1, 1, TIMEOUT, &check_success, crc);
440 break; 393 break;
441 case RP_PUT_MULTIPLE_NEXT: 394 case RP_PUT_MULTIPLE_NEXT:
442 crc->phase = RP_GET_MULTIPLE; 395 crc->phase = RP_GET_MULTIPLE;
443 GNUNET_DATASTORE_put (datastore, 396 GNUNET_DATASTORE_put (datastore, crc->rid, &crc->key, get_size (43),
444 crc->rid, 397 get_data (43), get_type (42), get_priority (43),
445 &crc->key, 398 get_anonymity (43), 0, get_expiration (43), 1, 1,
446 get_size (43), 399 TIMEOUT, &check_success, crc);
447 get_data (43),
448 get_type (42),
449 get_priority (43),
450 get_anonymity (43),
451 0,
452 get_expiration (43),
453 1, 1, TIMEOUT, &check_success, crc);
454 break; 400 break;
455 case RP_GET_MULTIPLE: 401 case RP_GET_MULTIPLE:
456 GNUNET_assert (NULL != 402 GNUNET_assert (NULL !=
457 GNUNET_DATASTORE_get_key (datastore, 403 GNUNET_DATASTORE_get_key (datastore, crc->offset, &crc->key,
458 crc->offset, 404 get_type (42), 1, 1, TIMEOUT,
459 &crc->key,
460 get_type (42),
461 1, 1, TIMEOUT,
462 &check_multiple, crc)); 405 &check_multiple, crc));
463 break; 406 break;
464 case RP_GET_MULTIPLE_NEXT: 407 case RP_GET_MULTIPLE_NEXT:
465 GNUNET_assert (NULL != 408 GNUNET_assert (NULL !=
466 GNUNET_DATASTORE_get_key (datastore, 409 GNUNET_DATASTORE_get_key (datastore, crc->offset, &crc->key,
467 crc->offset, 410 get_type (42), 1, 1, TIMEOUT,
468 &crc->key,
469 get_type (42),
470 1, 1, TIMEOUT,
471 &check_multiple, crc)); 411 &check_multiple, crc));
472 break; 412 break;
473 case RP_UPDATE: 413 case RP_UPDATE:
474 GNUNET_assert (crc->uid > 0); 414 GNUNET_assert (crc->uid > 0);
475 crc->phase = RP_UPDATE_VALIDATE; 415 crc->phase = RP_UPDATE_VALIDATE;
476 GNUNET_DATASTORE_update (datastore, 416 GNUNET_DATASTORE_update (datastore, crc->uid, 100, get_expiration (42), 1,
477 crc->uid, 417 1, TIMEOUT, &check_success, crc);
478 100,
479 get_expiration (42),
480 1, 1, TIMEOUT, &check_success, crc);
481 break; 418 break;
482 case RP_UPDATE_VALIDATE: 419 case RP_UPDATE_VALIDATE:
483 GNUNET_assert (NULL != 420 GNUNET_assert (NULL !=
484 GNUNET_DATASTORE_get_key (datastore, 421 GNUNET_DATASTORE_get_key (datastore, crc->offset, &crc->key,
485 crc->offset, 422 get_type (42), 1, 1, TIMEOUT,
486 &crc->key,
487 get_type (42),
488 1, 1, TIMEOUT,
489 &check_update, crc)); 423 &check_update, crc));
490 break; 424 break;
491 case RP_DONE: 425 case RP_DONE:
@@ -513,8 +447,7 @@ run_tests (void *cls, int32_t success, const char *msg)
513 switch (success) 447 switch (success)
514 { 448 {
515 case GNUNET_YES: 449 case GNUNET_YES:
516 GNUNET_SCHEDULER_add_continuation (&run_continuation, 450 GNUNET_SCHEDULER_add_continuation (&run_continuation, crc,
517 crc,
518 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 451 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
519 return; 452 return;
520 case GNUNET_NO: 453 case GNUNET_NO:
@@ -534,9 +467,8 @@ run_tests (void *cls, int32_t success, const char *msg)
534 467
535 468
536static void 469static void
537run (void *cls, 470run (void *cls, char *const *args, const char *cfgfile,
538 char *const *args, 471 const struct GNUNET_CONFIGURATION_Handle *cfg)
539 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
540{ 472{
541 struct CpsRunContext *crc; 473 struct CpsRunContext *crc;
542 static GNUNET_HashCode zkey; 474 static GNUNET_HashCode zkey;
@@ -547,10 +479,8 @@ run (void *cls,
547 now = GNUNET_TIME_absolute_get (); 479 now = GNUNET_TIME_absolute_get ();
548 datastore = GNUNET_DATASTORE_connect (cfg); 480 datastore = GNUNET_DATASTORE_connect (cfg);
549 if (NULL == 481 if (NULL ==
550 GNUNET_DATASTORE_put (datastore, 0, 482 GNUNET_DATASTORE_put (datastore, 0, &zkey, 4, "TEST",
551 &zkey, 4, "TEST", 483 GNUNET_BLOCK_TYPE_TEST, 0, 0, 0,
552 GNUNET_BLOCK_TYPE_TEST,
553 0, 0, 0,
554 GNUNET_TIME_relative_to_absolute 484 GNUNET_TIME_relative_to_absolute
555 (GNUNET_TIME_UNIT_SECONDS), 0, 1, 485 (GNUNET_TIME_UNIT_SECONDS), 0, 1,
556 GNUNET_TIME_UNIT_MINUTES, &run_tests, crc)) 486 GNUNET_TIME_UNIT_MINUTES, &run_tests, crc))
@@ -582,21 +512,20 @@ check ()
582 struct GNUNET_GETOPT_CommandLineOption options[] = { 512 struct GNUNET_GETOPT_CommandLineOption options[] = {
583 GNUNET_GETOPT_OPTION_END 513 GNUNET_GETOPT_OPTION_END
584 }; 514 };
585 GNUNET_snprintf (cfg_name, 515 GNUNET_snprintf (cfg_name, sizeof (cfg_name),
586 sizeof (cfg_name),
587 "test_datastore_api_data_%s.conf", plugin_name); 516 "test_datastore_api_data_%s.conf", plugin_name);
588#if START_DATASTORE 517#if START_DATASTORE
589 proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 518 proc =
590 "gnunet-service-arm", 519 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
520 "gnunet-service-arm",
591#if VERBOSE 521#if VERBOSE
592 "-L", "DEBUG", 522 "-L", "DEBUG",
593#endif 523#endif
594 "-c", cfg_name, NULL); 524 "-c", cfg_name, NULL);
595#endif 525#endif
596 GNUNET_assert (NULL != proc); 526 GNUNET_assert (NULL != proc);
597 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 527 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
598 argv, "test-datastore-api", "nohelp", 528 "test-datastore-api", "nohelp", options, &run, NULL);
599 options, &run, NULL);
600#if START_DATASTORE 529#if START_DATASTORE
601 sleep (1); /* give datastore chance to receive 'DROP' request */ 530 sleep (1); /* give datastore chance to receive 'DROP' request */
602 if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) 531 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
@@ -630,9 +559,8 @@ main (int argc, char *argv[])
630 else 559 else
631 pos = (char *) plugin_name; 560 pos = (char *) plugin_name;
632 561
633 GNUNET_snprintf (dir_name, 562 GNUNET_snprintf (dir_name, sizeof (dir_name), "/tmp/test-gnunet-datastore-%s",
634 sizeof (dir_name), 563 plugin_name);
635 "/tmp/test-gnunet-datastore-%s", plugin_name);
636 GNUNET_DISK_directory_remove (dir_name); 564 GNUNET_DISK_directory_remove (dir_name);
637 GNUNET_log_setup ("test-datastore-api", 565 GNUNET_log_setup ("test-datastore-api",
638#if VERBOSE 566#if VERBOSE
diff --git a/src/datastore/test_datastore_api_management.c b/src/datastore/test_datastore_api_management.c
index b2146a915..230b7eb67 100644
--- a/src/datastore/test_datastore_api_management.c
+++ b/src/datastore/test_datastore_api_management.c
@@ -117,8 +117,8 @@ struct CpsRunContext
117}; 117};
118 118
119 119
120static void 120static void run_continuation (void *cls,
121run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 121 const struct GNUNET_SCHEDULER_TaskContext *tc);
122 122
123 123
124static void 124static void
@@ -131,20 +131,16 @@ check_success (void *cls, int success, const char *msg)
131 GNUNET_assert (GNUNET_OK == success); 131 GNUNET_assert (GNUNET_OK == success);
132 GNUNET_free_non_null (crc->data); 132 GNUNET_free_non_null (crc->data);
133 crc->data = NULL; 133 crc->data = NULL;
134 GNUNET_SCHEDULER_add_continuation (&run_continuation, 134 GNUNET_SCHEDULER_add_continuation (&run_continuation, crc,
135 crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 135 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
136} 136}
137 137
138 138
139static void 139static void
140check_value (void *cls, 140check_value (void *cls, const GNUNET_HashCode * key, size_t size,
141 const GNUNET_HashCode * key, 141 const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority,
142 size_t size, 142 uint32_t anonymity, struct GNUNET_TIME_Absolute expiration,
143 const void *data, 143 uint64_t uid)
144 enum GNUNET_BLOCK_Type type,
145 uint32_t priority,
146 uint32_t anonymity,
147 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
148{ 144{
149 struct CpsRunContext *crc = cls; 145 struct CpsRunContext *crc = cls;
150 int i; 146 int i;
@@ -152,8 +148,7 @@ check_value (void *cls,
152 if (NULL == key) 148 if (NULL == key)
153 { 149 {
154 crc->phase = RP_GET_FAIL; 150 crc->phase = RP_GET_FAIL;
155 GNUNET_SCHEDULER_add_continuation (&run_continuation, 151 GNUNET_SCHEDULER_add_continuation (&run_continuation, crc,
156 crc,
157 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 152 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
158 return; 153 return;
159 } 154 }
@@ -168,28 +163,24 @@ check_value (void *cls,
168 crc->i--; 163 crc->i--;
169 if (crc->i == 0) 164 if (crc->i == 0)
170 crc->phase = RP_DONE; 165 crc->phase = RP_DONE;
171 GNUNET_SCHEDULER_add_continuation (&run_continuation, 166 GNUNET_SCHEDULER_add_continuation (&run_continuation, crc,
172 crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 167 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
173} 168}
174 169
175 170
176static void 171static void
177check_nothing (void *cls, 172check_nothing (void *cls, const GNUNET_HashCode * key, size_t size,
178 const GNUNET_HashCode * key, 173 const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority,
179 size_t size, 174 uint32_t anonymity, struct GNUNET_TIME_Absolute expiration,
180 const void *data, 175 uint64_t uid)
181 enum GNUNET_BLOCK_Type type,
182 uint32_t priority,
183 uint32_t anonymity,
184 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
185{ 176{
186 struct CpsRunContext *crc = cls; 177 struct CpsRunContext *crc = cls;
187 178
188 GNUNET_assert (key == NULL); 179 GNUNET_assert (key == NULL);
189 if (0 == --crc->i) 180 if (0 == --crc->i)
190 crc->phase = RP_DONE; 181 crc->phase = RP_DONE;
191 GNUNET_SCHEDULER_add_continuation (&run_continuation, 182 GNUNET_SCHEDULER_add_continuation (&run_continuation, crc,
192 crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 183 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
193} 184}
194 185
195 186
@@ -203,21 +194,15 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
203 { 194 {
204 case RP_PUT: 195 case RP_PUT:
205#if VERBOSE 196#if VERBOSE
206 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "PUT",
207 "Executing `%s' number %u\n", "PUT", crc->i); 198 crc->i);
208#endif 199#endif
209 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); 200 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
210 GNUNET_DATASTORE_put (datastore, 201 GNUNET_DATASTORE_put (datastore, 0, &crc->key, get_size (crc->i),
211 0, 202 get_data (crc->i), get_type (crc->i),
212 &crc->key, 203 get_priority (crc->i), get_anonymity (crc->i), 0,
213 get_size (crc->i), 204 get_expiration (crc->i), 1, 1, TIMEOUT,
214 get_data (crc->i), 205 &check_success, crc);
215 get_type (crc->i),
216 get_priority (crc->i),
217 get_anonymity (crc->i),
218 0,
219 get_expiration (crc->i),
220 1, 1, TIMEOUT, &check_success, crc);
221 crc->i++; 206 crc->i++;
222 if (crc->i == ITERATIONS) 207 if (crc->i == ITERATIONS)
223 { 208 {
@@ -230,27 +215,23 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
230 break; 215 break;
231 case RP_GET: 216 case RP_GET:
232#if VERBOSE 217#if VERBOSE
233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "GET",
234 "Executing `%s' number %u\n", "GET", crc->i); 219 crc->i);
235#endif 220#endif
236 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); 221 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
237 GNUNET_DATASTORE_get_key (datastore, 222 GNUNET_DATASTORE_get_key (datastore, crc->offset++, &crc->key,
238 crc->offset++, 223 get_type (crc->i), 1, 1, TIMEOUT, &check_value,
239 &crc->key, 224 crc);
240 get_type (crc->i),
241 1, 1, TIMEOUT, &check_value, crc);
242 break; 225 break;
243 case RP_GET_FAIL: 226 case RP_GET_FAIL:
244#if VERBOSE 227#if VERBOSE
245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 228 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "GET(f)",
246 "Executing `%s' number %u\n", "GET(f)", crc->i); 229 crc->i);
247#endif 230#endif
248 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); 231 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
249 GNUNET_DATASTORE_get_key (datastore, 232 GNUNET_DATASTORE_get_key (datastore, crc->offset++, &crc->key,
250 crc->offset++, 233 get_type (crc->i), 1, 1, TIMEOUT, &check_nothing,
251 &crc->key, 234 crc);
252 get_type (crc->i),
253 1, 1, TIMEOUT, &check_nothing, crc);
254 break; 235 break;
255 case RP_DONE: 236 case RP_DONE:
256 GNUNET_assert (0 == crc->i); 237 GNUNET_assert (0 == crc->i);
@@ -277,15 +258,14 @@ run_tests (void *cls, int success, const char *msg)
277 GNUNET_free (crc); 258 GNUNET_free (crc);
278 return; 259 return;
279 } 260 }
280 GNUNET_SCHEDULER_add_continuation (&run_continuation, 261 GNUNET_SCHEDULER_add_continuation (&run_continuation, crc,
281 crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 262 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
282} 263}
283 264
284 265
285static void 266static void
286run (void *cls, 267run (void *cls, char *const *args, const char *cfgfile,
287 char *const *args, 268 const struct GNUNET_CONFIGURATION_Handle *cfg)
288 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
289{ 269{
290 struct CpsRunContext *crc; 270 struct CpsRunContext *crc;
291 static GNUNET_HashCode zkey; 271 static GNUNET_HashCode zkey;
@@ -296,10 +276,8 @@ run (void *cls,
296 now = GNUNET_TIME_absolute_get (); 276 now = GNUNET_TIME_absolute_get ();
297 datastore = GNUNET_DATASTORE_connect (cfg); 277 datastore = GNUNET_DATASTORE_connect (cfg);
298 if (NULL == 278 if (NULL ==
299 GNUNET_DATASTORE_put (datastore, 0, 279 GNUNET_DATASTORE_put (datastore, 0, &zkey, 4, "TEST",
300 &zkey, 4, "TEST", 280 GNUNET_BLOCK_TYPE_TEST, 0, 0, 0,
301 GNUNET_BLOCK_TYPE_TEST,
302 0, 0, 0,
303 GNUNET_TIME_relative_to_absolute 281 GNUNET_TIME_relative_to_absolute
304 (GNUNET_TIME_UNIT_SECONDS), 0, 1, 282 (GNUNET_TIME_UNIT_SECONDS), 0, 1,
305 GNUNET_TIME_UNIT_MINUTES, &run_tests, crc)) 283 GNUNET_TIME_UNIT_MINUTES, &run_tests, crc))
@@ -330,19 +308,19 @@ check ()
330 struct GNUNET_GETOPT_CommandLineOption options[] = { 308 struct GNUNET_GETOPT_CommandLineOption options[] = {
331 GNUNET_GETOPT_OPTION_END 309 GNUNET_GETOPT_OPTION_END
332 }; 310 };
333 GNUNET_snprintf (cfg_name, 311 GNUNET_snprintf (cfg_name, sizeof (cfg_name),
334 sizeof (cfg_name),
335 "test_datastore_api_data_%s.conf", plugin_name); 312 "test_datastore_api_data_%s.conf", plugin_name);
336 proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 313 proc =
337 "gnunet-service-arm", 314 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
315 "gnunet-service-arm",
338#if VERBOSE 316#if VERBOSE
339 "-L", "DEBUG", 317 "-L", "DEBUG",
340#endif 318#endif
341 "-c", cfg_name, NULL); 319 "-c", cfg_name, NULL);
342 GNUNET_assert (NULL != proc); 320 GNUNET_assert (NULL != proc);
343 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 321 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
344 argv, "test-datastore-api-management", "nohelp", 322 "test-datastore-api-management", "nohelp", options, &run,
345 options, &run, NULL); 323 NULL);
346 sleep (1); /* give datastore chance to process 'DROP' request */ 324 sleep (1); /* give datastore chance to process 'DROP' request */
347 if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) 325 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
348 { 326 {
@@ -375,9 +353,8 @@ main (int argc, char *argv[])
375 else 353 else
376 pos = (char *) plugin_name; 354 pos = (char *) plugin_name;
377 355
378 GNUNET_snprintf (dir_name, 356 GNUNET_snprintf (dir_name, sizeof (dir_name), "/tmp/test-gnunet-datastore-%s",
379 sizeof (dir_name), 357 plugin_name);
380 "/tmp/test-gnunet-datastore-%s", plugin_name);
381 GNUNET_DISK_directory_remove (dir_name); 358 GNUNET_DISK_directory_remove (dir_name);
382 GNUNET_log_setup ("test-datastore-api-management", 359 GNUNET_log_setup ("test-datastore-api-management",
383#if VERBOSE 360#if VERBOSE
diff --git a/src/datastore/test_plugin_datastore.c b/src/datastore/test_plugin_datastore.c
index 15cca61f1..a34c4e38a 100644
--- a/src/datastore/test_plugin_datastore.c
+++ b/src/datastore/test_plugin_datastore.c
@@ -118,9 +118,8 @@ put_value (struct GNUNET_DATASTORE_PluginFunctions *api, int i, int k)
118 msg = NULL; 118 msg = NULL;
119 prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100); 119 prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
120#if VERBOSE 120#if VERBOSE
121 fprintf (stderr, 121 fprintf (stderr, "putting type %u, anon %u under key %s\n", i + 1, i,
122 "putting type %u, anon %u under key %s\n", 122 GNUNET_h2s (&key));
123 i + 1, i, GNUNET_h2s (&key));
124#endif 123#endif
125 if (GNUNET_OK != api->put (api->cls, &key, size, value, i + 1 /* type */ , 124 if (GNUNET_OK != api->put (api->cls, &key, size, value, i + 1 /* type */ ,
126 prio, i /* anonymity */ , 125 prio, i /* anonymity */ ,
@@ -149,13 +148,9 @@ static uint64_t guid;
149 148
150 149
151static int 150static int
152iterate_one_shot (void *cls, 151iterate_one_shot (void *cls, const GNUNET_HashCode * key, uint32_t size,
153 const GNUNET_HashCode * key, 152 const void *data, enum GNUNET_BLOCK_Type type,
154 uint32_t size, 153 uint32_t priority, uint32_t anonymity,
155 const void *data,
156 enum GNUNET_BLOCK_Type type,
157 uint32_t priority,
158 uint32_t anonymity,
159 struct GNUNET_TIME_Absolute expiration, uint64_t uid) 154 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
160{ 155{
161 struct CpsRunContext *crc = cls; 156 struct CpsRunContext *crc = cls;
@@ -166,8 +161,8 @@ iterate_one_shot (void *cls,
166#if VERBOSE 161#if VERBOSE
167 fprintf (stderr, 162 fprintf (stderr,
168 "Found result type=%u, priority=%u, size=%u, expire=%llu, key %s\n", 163 "Found result type=%u, priority=%u, size=%u, expire=%llu, key %s\n",
169 type, priority, size, 164 type, priority, size, (unsigned long long) expiration.abs_value,
170 (unsigned long long) expiration.abs_value, GNUNET_h2s (key)); 165 GNUNET_h2s (key));
171#endif 166#endif
172 GNUNET_SCHEDULER_add_now (&test, crc); 167 GNUNET_SCHEDULER_add_now (&test, crc);
173 return GNUNET_OK; 168 return GNUNET_OK;
@@ -189,12 +184,12 @@ unload_plugin (struct GNUNET_DATASTORE_PluginFunctions *api,
189 char *libname; 184 char *libname;
190 185
191 if (GNUNET_OK != 186 if (GNUNET_OK !=
192 GNUNET_CONFIGURATION_get_value_string (cfg, 187 GNUNET_CONFIGURATION_get_value_string (cfg, "DATASTORE", "DATABASE",
193 "DATASTORE", "DATABASE", &name)) 188 &name))
194 { 189 {
195 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 190 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
196 _("No `%s' specified for `%s' in configuration!\n"), 191 _("No `%s' specified for `%s' in configuration!\n"), "DATABASE",
197 "DATABASE", "DATASTORE"); 192 "DATASTORE");
198 return; 193 return;
199 } 194 }
200 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); 195 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
@@ -265,15 +260,13 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
265 break; 260 break;
266 } 261 }
267 gen_key (5, &key); 262 gen_key (5, &key);
268 crc->api->get_key (crc->api->cls, 263 crc->api->get_key (crc->api->cls, crc->offset++, &key, NULL,
269 crc->offset++,
270 &key, NULL,
271 GNUNET_BLOCK_TYPE_ANY, &iterate_one_shot, crc); 264 GNUNET_BLOCK_TYPE_ANY, &iterate_one_shot, crc);
272 break; 265 break;
273 case RP_UPDATE: 266 case RP_UPDATE:
274 GNUNET_assert (GNUNET_OK == 267 GNUNET_assert (GNUNET_OK ==
275 crc->api->update (crc->api->cls, 268 crc->api->update (crc->api->cls, guid, 1,
276 guid, 1, GNUNET_TIME_UNIT_ZERO_ABS, NULL)); 269 GNUNET_TIME_UNIT_ZERO_ABS, NULL));
277 crc->phase++; 270 crc->phase++;
278 GNUNET_SCHEDULER_add_now (&test, crc); 271 GNUNET_SCHEDULER_add_now (&test, crc);
279 break; 272 break;
@@ -314,19 +307,19 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
314 char *libname; 307 char *libname;
315 308
316 if (GNUNET_OK != 309 if (GNUNET_OK !=
317 GNUNET_CONFIGURATION_get_value_string (cfg, 310 GNUNET_CONFIGURATION_get_value_string (cfg, "DATASTORE", "DATABASE",
318 "DATASTORE", "DATABASE", &name)) 311 &name))
319 { 312 {
320 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 313 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
321 _("No `%s' specified for `%s' in configuration!\n"), 314 _("No `%s' specified for `%s' in configuration!\n"), "DATABASE",
322 "DATABASE", "DATASTORE"); 315 "DATASTORE");
323 return NULL; 316 return NULL;
324 } 317 }
325 env.cfg = cfg; 318 env.cfg = cfg;
326 env.duc = &disk_utilization_change_cb; 319 env.duc = &disk_utilization_change_cb;
327 env.cls = NULL; 320 env.cls = NULL;
328 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 321 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' datastore plugin\n"),
329 _("Loading `%s' datastore plugin\n"), name); 322 name);
330 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); 323 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
331 if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env))) 324 if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env)))
332 { 325 {
@@ -340,9 +333,8 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
340 333
341 334
342static void 335static void
343run (void *cls, 336run (void *cls, char *const *args, const char *cfgfile,
344 char *const *args, 337 const struct GNUNET_CONFIGURATION_Handle *c)
345 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
346{ 338{
347 struct GNUNET_DATASTORE_PluginFunctions *api; 339 struct GNUNET_DATASTORE_PluginFunctions *api;
348 struct CpsRunContext *crc; 340 struct CpsRunContext *crc;
@@ -380,12 +372,10 @@ check ()
380 GNUNET_GETOPT_OPTION_END 372 GNUNET_GETOPT_OPTION_END
381 }; 373 };
382 374
383 GNUNET_snprintf (cfg_name, 375 GNUNET_snprintf (cfg_name, sizeof (cfg_name),
384 sizeof (cfg_name),
385 "test_plugin_datastore_data_%s.conf", plugin_name); 376 "test_plugin_datastore_data_%s.conf", plugin_name);
386 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 377 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
387 argv, "test-plugin-datastore", "nohelp", 378 "test-plugin-datastore", "nohelp", options, &run, NULL);
388 options, &run, NULL);
389 if (ok != 0) 379 if (ok != 0)
390 fprintf (stderr, "Missed some testcases: %u\n", ok); 380 fprintf (stderr, "Missed some testcases: %u\n", ok);
391 return ok; 381 return ok;
@@ -409,8 +399,7 @@ main (int argc, char *argv[])
409 else 399 else
410 pos = (char *) plugin_name; 400 pos = (char *) plugin_name;
411 401
412 GNUNET_snprintf (dir_name, 402 GNUNET_snprintf (dir_name, sizeof (dir_name),
413 sizeof (dir_name),
414 "/tmp/test-gnunet-datastore-plugin-%s", plugin_name); 403 "/tmp/test-gnunet-datastore-plugin-%s", plugin_name);
415 GNUNET_DISK_directory_remove (dir_name); 404 GNUNET_DISK_directory_remove (dir_name);
416 GNUNET_log_setup ("test-plugin-datastore", 405 GNUNET_log_setup ("test-plugin-datastore",
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c
index 101751487..eded50efc 100644
--- a/src/dht/dht_api.c
+++ b/src/dht/dht_api.c
@@ -211,8 +211,8 @@ static size_t transmit_pending (void *cls, size_t size, void *buf);
211 * a demultiplexer which handles numerous message types 211 * a demultiplexer which handles numerous message types
212 * 212 *
213 */ 213 */
214static void 214static void service_message_handler (void *cls,
215service_message_handler (void *cls, const struct GNUNET_MessageHeader *msg); 215 const struct GNUNET_MessageHeader *msg);
216 216
217 217
218 218
@@ -238,9 +238,8 @@ try_connect (struct GNUNET_DHT_Handle *handle)
238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
239 "Starting to process replies from DHT\n"); 239 "Starting to process replies from DHT\n");
240#endif 240#endif
241 GNUNET_CLIENT_receive (handle->client, 241 GNUNET_CLIENT_receive (handle->client, &service_message_handler, handle,
242 &service_message_handler, 242 GNUNET_TIME_UNIT_FOREVER_REL);
243 handle, GNUNET_TIME_UNIT_FOREVER_REL);
244 return GNUNET_YES; 243 return GNUNET_YES;
245} 244}
246 245
@@ -262,8 +261,8 @@ add_request_to_pending (void *cls, const GNUNET_HashCode * key, void *value)
262 261
263 if (GNUNET_NO == rh->message->in_pending_queue) 262 if (GNUNET_NO == rh->message->in_pending_queue)
264 { 263 {
265 GNUNET_CONTAINER_DLL_insert (handle->pending_head, 264 GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail,
266 handle->pending_tail, rh->message); 265 rh->message);
267 rh->message->in_pending_queue = GNUNET_YES; 266 rh->message->in_pending_queue = GNUNET_YES;
268 } 267 }
269 return GNUNET_YES; 268 return GNUNET_YES;
@@ -321,9 +320,8 @@ do_disconnect (struct GNUNET_DHT_Handle *handle)
321 GNUNET_assert (handle->reconnect_task == GNUNET_SCHEDULER_NO_TASK); 320 GNUNET_assert (handle->reconnect_task == GNUNET_SCHEDULER_NO_TASK);
322 GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO); 321 GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO);
323 handle->client = NULL; 322 handle->client = NULL;
324 handle->reconnect_task = GNUNET_SCHEDULER_add_delayed (handle->retry_time, 323 handle->reconnect_task =
325 &try_reconnect, 324 GNUNET_SCHEDULER_add_delayed (handle->retry_time, &try_reconnect, handle);
326 handle);
327} 325}
328 326
329 327
@@ -344,11 +342,12 @@ process_pending_messages (struct GNUNET_DHT_Handle *handle)
344 return; 342 return;
345 if (NULL == (head = handle->pending_head)) 343 if (NULL == (head = handle->pending_head))
346 return; 344 return;
347 handle->th = GNUNET_CLIENT_notify_transmit_ready (handle->client, 345 handle->th =
348 ntohs (head->msg->size), 346 GNUNET_CLIENT_notify_transmit_ready (handle->client,
349 GNUNET_TIME_UNIT_FOREVER_REL, 347 ntohs (head->msg->size),
350 GNUNET_YES, 348 GNUNET_TIME_UNIT_FOREVER_REL,
351 &transmit_pending, handle); 349 GNUNET_YES, &transmit_pending,
350 handle);
352 if (NULL == handle->th) 351 if (NULL == handle->th)
353 { 352 {
354 do_disconnect (handle); 353 do_disconnect (handle);
@@ -385,8 +384,8 @@ transmit_pending (void *cls, size_t size, void *buf)
385 return 0; 384 return 0;
386 } 385 }
387 memcpy (buf, head->msg, tsize); 386 memcpy (buf, head->msg, tsize);
388 GNUNET_CONTAINER_DLL_remove (handle->pending_head, 387 GNUNET_CONTAINER_DLL_remove (handle->pending_head, handle->pending_tail,
389 handle->pending_tail, head); 388 head);
390 if (head->timeout_task != GNUNET_SCHEDULER_NO_TASK) 389 if (head->timeout_task != GNUNET_SCHEDULER_NO_TASK)
391 { 390 {
392 GNUNET_SCHEDULER_cancel (head->timeout_task); 391 GNUNET_SCHEDULER_cancel (head->timeout_task);
@@ -394,8 +393,7 @@ transmit_pending (void *cls, size_t size, void *buf)
394 } 393 }
395 if (NULL != head->cont) 394 if (NULL != head->cont)
396 { 395 {
397 GNUNET_SCHEDULER_add_continuation (head->cont, 396 GNUNET_SCHEDULER_add_continuation (head->cont, head->cont_cls,
398 head->cont_cls,
399 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 397 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
400 head->cont = NULL; 398 head->cont = NULL;
401 head->cont_cls = NULL; 399 head->cont_cls = NULL;
@@ -514,13 +512,12 @@ service_message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
514 GNUNET_h2s (&dht_msg->key), 512 GNUNET_h2s (&dht_msg->key),
515 GNUNET_CONTAINER_multihashmap_size (handle->active_requests)); 513 GNUNET_CONTAINER_multihashmap_size (handle->active_requests));
516 GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_requests, 514 GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_requests,
517 &dht_msg->key, 515 &dht_msg->key, &process_reply,
518 &process_reply, (void *) dht_msg); 516 (void *) dht_msg);
519 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 517 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
520 "Continuing to process replies from DHT\n"); 518 "Continuing to process replies from DHT\n");
521 GNUNET_CLIENT_receive (handle->client, 519 GNUNET_CLIENT_receive (handle->client, &service_message_handler, handle,
522 &service_message_handler, 520 GNUNET_TIME_UNIT_FOREVER_REL);
523 handle, GNUNET_TIME_UNIT_FOREVER_REL);
524 521
525} 522}
526 523
@@ -574,14 +571,13 @@ GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle)
574 } 571 }
575 while (NULL != (pm = handle->pending_head)) 572 while (NULL != (pm = handle->pending_head))
576 { 573 {
577 GNUNET_CONTAINER_DLL_remove (handle->pending_head, 574 GNUNET_CONTAINER_DLL_remove (handle->pending_head, handle->pending_tail,
578 handle->pending_tail, pm); 575 pm);
579 GNUNET_assert (GNUNET_YES == pm->free_on_send); 576 GNUNET_assert (GNUNET_YES == pm->free_on_send);
580 if (GNUNET_SCHEDULER_NO_TASK != pm->timeout_task) 577 if (GNUNET_SCHEDULER_NO_TASK != pm->timeout_task)
581 GNUNET_SCHEDULER_cancel (pm->timeout_task); 578 GNUNET_SCHEDULER_cancel (pm->timeout_task);
582 if (NULL != pm->cont) 579 if (NULL != pm->cont)
583 GNUNET_SCHEDULER_add_continuation (pm->cont, 580 GNUNET_SCHEDULER_add_continuation (pm->cont, pm->cont_cls,
584 pm->cont_cls,
585 GNUNET_SCHEDULER_REASON_TIMEOUT); 581 GNUNET_SCHEDULER_REASON_TIMEOUT);
586 pm->in_pending_queue = GNUNET_NO; 582 pm->in_pending_queue = GNUNET_NO;
587 GNUNET_free (pm); 583 GNUNET_free (pm);
@@ -622,8 +618,8 @@ timeout_route_request (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
622 return; 618 return;
623 } 619 }
624 handle = pending->handle; 620 handle = pending->handle;
625 GNUNET_CONTAINER_DLL_remove (handle->pending_head, 621 GNUNET_CONTAINER_DLL_remove (handle->pending_head, handle->pending_tail,
626 handle->pending_tail, pending); 622 pending);
627 if (pending->cont != NULL) 623 if (pending->cont != NULL)
628 pending->cont (pending->cont_cls, tc); 624 pending->cont (pending->cont_cls, tc);
629 GNUNET_free (pending); 625 GNUNET_free (pending);
@@ -658,8 +654,7 @@ GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle,
658 enum GNUNET_DHT_RouteOption options, 654 enum GNUNET_DHT_RouteOption options,
659 const struct GNUNET_MessageHeader *enc, 655 const struct GNUNET_MessageHeader *enc,
660 struct GNUNET_TIME_Relative timeout, 656 struct GNUNET_TIME_Relative timeout,
661 GNUNET_DHT_ReplyProcessor iter, 657 GNUNET_DHT_ReplyProcessor iter, void *iter_cls,
662 void *iter_cls,
663 GNUNET_SCHEDULER_Task cont, void *cont_cls) 658 GNUNET_SCHEDULER_Task cont, void *cont_cls)
664{ 659{
665 struct PendingMessage *pending; 660 struct PendingMessage *pending;
@@ -702,8 +697,7 @@ GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle,
702 route_handle->dht_handle = handle; 697 route_handle->dht_handle = handle;
703 route_handle->uid = handle->uid_gen; 698 route_handle->uid = handle->uid_gen;
704 route_handle->message = pending; 699 route_handle->message = pending;
705 GNUNET_CONTAINER_multihashmap_put (handle->active_requests, 700 GNUNET_CONTAINER_multihashmap_put (handle->active_requests, key,
706 key,
707 route_handle, 701 route_handle,
708 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 702 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
709 } 703 }
@@ -711,12 +705,11 @@ GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle,
711 { 705 {
712 route_handle = NULL; 706 route_handle = NULL;
713 pending->free_on_send = GNUNET_YES; 707 pending->free_on_send = GNUNET_YES;
714 pending->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, 708 pending->timeout_task =
715 &timeout_route_request, 709 GNUNET_SCHEDULER_add_delayed (timeout, &timeout_route_request, pending);
716 pending);
717 } 710 }
718 GNUNET_CONTAINER_DLL_insert (handle->pending_head, 711 GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail,
719 handle->pending_tail, pending); 712 pending);
720 pending->in_pending_queue = GNUNET_YES; 713 pending->in_pending_queue = GNUNET_YES;
721 process_pending_messages (handle); 714 process_pending_messages (handle);
722 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 715 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -755,21 +748,23 @@ GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *route_handle)
755 pending->handle = handle; 748 pending->handle = handle;
756 pending->free_on_send = GNUNET_YES; 749 pending->free_on_send = GNUNET_YES;
757 pending->in_pending_queue = GNUNET_YES; 750 pending->in_pending_queue = GNUNET_YES;
758 GNUNET_CONTAINER_DLL_insert (handle->pending_head, 751 GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail,
759 handle->pending_tail, pending); 752 pending);
760 process_pending_messages (handle); 753 process_pending_messages (handle);
761 } 754 }
762 else 755 else
763 { 756 {
764 /* simply remove pending request from message queue before 757 /* simply remove pending request from message queue before
765 * transmission, no need to transmit STOP request! */ 758 * transmission, no need to transmit STOP request! */
766 GNUNET_CONTAINER_DLL_remove (handle->pending_head, 759 GNUNET_CONTAINER_DLL_remove (handle->pending_head, handle->pending_tail,
767 handle->pending_tail, route_handle->message); 760 route_handle->message);
768 } 761 }
769 GNUNET_assert (GNUNET_YES == 762 GNUNET_assert (GNUNET_YES ==
770 GNUNET_CONTAINER_multihashmap_remove 763 GNUNET_CONTAINER_multihashmap_remove (route_handle->
771 (route_handle->dht_handle->active_requests, &route_handle->key, 764 dht_handle->
772 route_handle)); 765 active_requests,
766 &route_handle->key,
767 route_handle));
773 GNUNET_free (route_handle->message); 768 GNUNET_free (route_handle->message);
774 GNUNET_free (route_handle); 769 GNUNET_free (route_handle);
775 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DHT route stop request processed\n"); 770 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DHT route stop request processed\n");
@@ -790,16 +785,16 @@ GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *route_handle)
790 * @param cont_cls closure for cont 785 * @param cont_cls closure for cont
791 */ 786 */
792static void 787static void
793send_control_message (struct GNUNET_DHT_Handle *handle, 788send_control_message (struct GNUNET_DHT_Handle *handle, uint16_t command,
794 uint16_t command, 789 uint16_t variable, GNUNET_SCHEDULER_Task cont,
795 uint16_t variable, 790 void *cont_cls)
796 GNUNET_SCHEDULER_Task cont, void *cont_cls)
797{ 791{
798 struct GNUNET_DHT_ControlMessage *msg; 792 struct GNUNET_DHT_ControlMessage *msg;
799 struct PendingMessage *pending; 793 struct PendingMessage *pending;
800 794
801 pending = GNUNET_malloc (sizeof (struct PendingMessage) + 795 pending =
802 sizeof (struct GNUNET_DHT_ControlMessage)); 796 GNUNET_malloc (sizeof (struct PendingMessage) +
797 sizeof (struct GNUNET_DHT_ControlMessage));
803 msg = (struct GNUNET_DHT_ControlMessage *) &pending[1]; 798 msg = (struct GNUNET_DHT_ControlMessage *) &pending[1];
804 pending->msg = &msg->header; 799 pending->msg = &msg->header;
805 msg->header.size = htons (sizeof (struct GNUNET_DHT_ControlMessage)); 800 msg->header.size = htons (sizeof (struct GNUNET_DHT_ControlMessage));
@@ -810,8 +805,8 @@ send_control_message (struct GNUNET_DHT_Handle *handle,
810 pending->cont = cont; 805 pending->cont = cont;
811 pending->cont_cls = cont_cls; 806 pending->cont_cls = cont_cls;
812 pending->in_pending_queue = GNUNET_YES; 807 pending->in_pending_queue = GNUNET_YES;
813 GNUNET_CONTAINER_DLL_insert (handle->pending_head, 808 GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail,
814 handle->pending_tail, pending); 809 pending);
815 process_pending_messages (handle); 810 process_pending_messages (handle);
816} 811}
817 812
@@ -831,8 +826,8 @@ void
831GNUNET_DHT_find_peers (struct GNUNET_DHT_Handle *handle, 826GNUNET_DHT_find_peers (struct GNUNET_DHT_Handle *handle,
832 GNUNET_SCHEDULER_Task cont, void *cont_cls) 827 GNUNET_SCHEDULER_Task cont, void *cont_cls)
833{ 828{
834 send_control_message (handle, 829 send_control_message (handle, GNUNET_MESSAGE_TYPE_DHT_FIND_PEER, 0, cont,
835 GNUNET_MESSAGE_TYPE_DHT_FIND_PEER, 0, cont, cont_cls); 830 cont_cls);
836} 831}
837 832
838 833
@@ -858,8 +853,7 @@ GNUNET_DHT_set_malicious_getter (struct GNUNET_DHT_Handle *handle,
858 GNUNET_break (0); 853 GNUNET_break (0);
859 return; 854 return;
860 } 855 }
861 send_control_message (handle, 856 send_control_message (handle, GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET,
862 GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET,
863 frequency.rel_value, cont, cont_cls); 857 frequency.rel_value, cont, cont_cls);
864} 858}
865 859
@@ -883,8 +877,7 @@ GNUNET_DHT_set_malicious_putter (struct GNUNET_DHT_Handle *handle,
883 return; 877 return;
884 } 878 }
885 879
886 send_control_message (handle, 880 send_control_message (handle, GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT,
887 GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT,
888 frequency.rel_value, cont, cont_cls); 881 frequency.rel_value, cont, cont_cls);
889} 882}
890 883
@@ -902,9 +895,8 @@ void
902GNUNET_DHT_set_malicious_dropper (struct GNUNET_DHT_Handle *handle, 895GNUNET_DHT_set_malicious_dropper (struct GNUNET_DHT_Handle *handle,
903 GNUNET_SCHEDULER_Task cont, void *cont_cls) 896 GNUNET_SCHEDULER_Task cont, void *cont_cls)
904{ 897{
905 send_control_message (handle, 898 send_control_message (handle, GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP, 0, cont,
906 GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP, 0, 899 cont_cls);
907 cont, cont_cls);
908} 900}
909 901
910#endif 902#endif
diff --git a/src/dht/dht_api_find_peer.c b/src/dht/dht_api_find_peer.c
index bcf1b50b7..a9ecc7b59 100644
--- a/src/dht/dht_api_find_peer.c
+++ b/src/dht/dht_api_find_peer.c
@@ -71,8 +71,7 @@ struct GNUNET_DHT_FindPeerHandle
71 * @param reply response 71 * @param reply response
72 */ 72 */
73static void 73static void
74find_peer_reply_iterator (void *cls, 74find_peer_reply_iterator (void *cls, const GNUNET_HashCode * key,
75 const GNUNET_HashCode * key,
76 const struct GNUNET_PeerIdentity *const 75 const struct GNUNET_PeerIdentity *const
77 *outgoing_path, 76 *outgoing_path,
78 const struct GNUNET_MessageHeader *reply) 77 const struct GNUNET_MessageHeader *reply)
@@ -127,12 +126,9 @@ GNUNET_DHT_find_peer_start (struct GNUNET_DHT_Handle *handle,
127 htons (sizeof (struct GNUNET_DHT_FindPeerMessage)); 126 htons (sizeof (struct GNUNET_DHT_FindPeerMessage));
128 find_peer_msg.header.type = htons (GNUNET_MESSAGE_TYPE_DHT_FIND_PEER); 127 find_peer_msg.header.type = htons (GNUNET_MESSAGE_TYPE_DHT_FIND_PEER);
129 find_peer_handle->route_handle = 128 find_peer_handle->route_handle =
130 GNUNET_DHT_route_start (handle, key, 129 GNUNET_DHT_route_start (handle, key, 0, options, &find_peer_msg.header,
131 0, options, 130 timeout, &find_peer_reply_iterator,
132 &find_peer_msg.header, 131 find_peer_handle, NULL, NULL);
133 timeout,
134 &find_peer_reply_iterator, find_peer_handle,
135 NULL, NULL);
136 GNUNET_break (find_peer_handle->route_handle != NULL); 132 GNUNET_break (find_peer_handle->route_handle != NULL);
137 return find_peer_handle; 133 return find_peer_handle;
138} 134}
diff --git a/src/dht/dht_api_get_put.c b/src/dht/dht_api_get_put.c
index 30b73e1f1..6b0bf1e26 100644
--- a/src/dht/dht_api_get_put.c
+++ b/src/dht/dht_api_get_put.c
@@ -52,16 +52,13 @@
52 * @return GNUNET_YES if put message is queued for transmission 52 * @return GNUNET_YES if put message is queued for transmission
53 */ 53 */
54void 54void
55GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, 55GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, const GNUNET_HashCode * key,
56 const GNUNET_HashCode * key,
57 uint32_t desired_replication_level, 56 uint32_t desired_replication_level,
58 enum GNUNET_DHT_RouteOption options, 57 enum GNUNET_DHT_RouteOption options,
59 enum GNUNET_BLOCK_Type type, 58 enum GNUNET_BLOCK_Type type, size_t size, const char *data,
60 size_t size,
61 const char *data,
62 struct GNUNET_TIME_Absolute exp, 59 struct GNUNET_TIME_Absolute exp,
63 struct GNUNET_TIME_Relative timeout, 60 struct GNUNET_TIME_Relative timeout, GNUNET_SCHEDULER_Task cont,
64 GNUNET_SCHEDULER_Task cont, void *cont_cls) 61 void *cont_cls)
65{ 62{
66 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE]; 63 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE];
67 struct GNUNET_DHT_PutMessage *put_msg; 64 struct GNUNET_DHT_PutMessage *put_msg;
@@ -82,11 +79,9 @@ GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
82 (unsigned int) (sizeof (struct GNUNET_DHT_PutMessage) + size), 79 (unsigned int) (sizeof (struct GNUNET_DHT_PutMessage) + size),
83 "PUT", type); 80 "PUT", type);
84 GNUNET_break (NULL == 81 GNUNET_break (NULL ==
85 GNUNET_DHT_route_start (handle, 82 GNUNET_DHT_route_start (handle, key, desired_replication_level,
86 key, 83 options, &put_msg->header, timeout,
87 desired_replication_level, options, 84 NULL, NULL, cont, cont_cls));
88 &put_msg->header,
89 timeout, NULL, NULL, cont, cont_cls));
90} 85}
91 86
92 87
@@ -126,8 +121,7 @@ struct GNUNET_DHT_GetHandle
126 * @param reply response 121 * @param reply response
127 */ 122 */
128static void 123static void
129get_reply_iterator (void *cls, 124get_reply_iterator (void *cls, const GNUNET_HashCode * key,
130 const GNUNET_HashCode * key,
131 const struct GNUNET_PeerIdentity *const *outgoing_path, 125 const struct GNUNET_PeerIdentity *const *outgoing_path,
132 const struct GNUNET_MessageHeader *reply) 126 const struct GNUNET_MessageHeader *reply)
133{ 127{
@@ -177,10 +171,9 @@ get_reply_iterator (void *cls,
177 171
178 payload = ntohs (reply->size) - sizeof (struct GNUNET_DHT_GetResultMessage); 172 payload = ntohs (reply->size) - sizeof (struct GNUNET_DHT_GetResultMessage);
179 get_handle->iter (get_handle->iter_cls, 173 get_handle->iter (get_handle->iter_cls,
180 GNUNET_TIME_absolute_ntoh (result->expiration), 174 GNUNET_TIME_absolute_ntoh (result->expiration), key,
181 key, 175 outgoing_path, put_path, ntohs (result->type), payload,
182 outgoing_path, 176 &result[1]);
183 put_path, ntohs (result->type), payload, &result[1]);
184 GNUNET_free_non_null (put_path); 177 GNUNET_free_non_null (put_path);
185} 178}
186 179
@@ -209,15 +202,13 @@ get_reply_iterator (void *cls,
209struct GNUNET_DHT_GetHandle * 202struct GNUNET_DHT_GetHandle *
210GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, 203GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle,
211 struct GNUNET_TIME_Relative timeout, 204 struct GNUNET_TIME_Relative timeout,
212 enum GNUNET_BLOCK_Type type, 205 enum GNUNET_BLOCK_Type type, const GNUNET_HashCode * key,
213 const GNUNET_HashCode * key,
214 uint32_t desired_replication_level, 206 uint32_t desired_replication_level,
215 enum GNUNET_DHT_RouteOption options, 207 enum GNUNET_DHT_RouteOption options,
216 const struct GNUNET_CONTAINER_BloomFilter *bf, 208 const struct GNUNET_CONTAINER_BloomFilter *bf,
217 int32_t bf_mutator, 209 int32_t bf_mutator, const void *xquery,
218 const void *xquery, 210 size_t xquery_size, GNUNET_DHT_GetIterator iter,
219 size_t xquery_size, 211 void *iter_cls)
220 GNUNET_DHT_GetIterator iter, void *iter_cls)
221{ 212{
222 struct GNUNET_DHT_GetHandle *get_handle; 213 struct GNUNET_DHT_GetHandle *get_handle;
223 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; 214 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
@@ -237,8 +228,8 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle,
237 get_handle->iter_cls = iter_cls; 228 get_handle->iter_cls = iter_cls;
238 get_msg = (struct GNUNET_DHT_GetMessage *) buf; 229 get_msg = (struct GNUNET_DHT_GetMessage *) buf;
239 get_msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_GET); 230 get_msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_GET);
240 get_msg->header.size = htons (sizeof (struct GNUNET_DHT_GetMessage) + 231 get_msg->header.size =
241 xquery_size + bf_size); 232 htons (sizeof (struct GNUNET_DHT_GetMessage) + xquery_size + bf_size);
242 get_msg->type = htonl ((uint32_t) type); 233 get_msg->type = htonl ((uint32_t) type);
243 get_msg->bf_mutator = bf_mutator; 234 get_msg->bf_mutator = bf_mutator;
244 get_msg->xquery_size = htons ((uint16_t) xquery_size); 235 get_msg->xquery_size = htons ((uint16_t) xquery_size);
diff --git a/src/dht/dhtlog.c b/src/dht/dhtlog.c
index 7b9c05268..d56ba6469 100644
--- a/src/dht/dhtlog.c
+++ b/src/dht/dhtlog.c
@@ -50,11 +50,11 @@ GNUNET_DHTLOG_connect (const struct GNUNET_CONFIGURATION_Handle *c)
50 plugin = GNUNET_malloc (sizeof (struct GNUNET_DHTLOG_Plugin)); 50 plugin = GNUNET_malloc (sizeof (struct GNUNET_DHTLOG_Plugin));
51 plugin->cfg = c; 51 plugin->cfg = c;
52 if (GNUNET_OK == 52 if (GNUNET_OK ==
53 GNUNET_CONFIGURATION_get_value_string (c, 53 GNUNET_CONFIGURATION_get_value_string (c, "DHTLOG", "PLUGIN",
54 "DHTLOG", "PLUGIN", &plugin_name)) 54 &plugin_name))
55 { 55 {
56 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 56 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' dhtlog plugin\n"),
57 _("Loading `%s' dhtlog plugin\n"), plugin_name); 57 plugin_name);
58 GNUNET_asprintf (&libname, "libgnunet_plugin_dhtlog_%s", plugin_name); 58 GNUNET_asprintf (&libname, "libgnunet_plugin_dhtlog_%s", plugin_name);
59 GNUNET_PLUGIN_load (libname, plugin); 59 GNUNET_PLUGIN_load (libname, plugin);
60 } 60 }
diff --git a/src/dht/gnunet-dht-driver.c b/src/dht/gnunet-dht-driver.c
index a5158fba5..d58e49e3b 100644
--- a/src/dht/gnunet-dht-driver.c
+++ b/src/dht/gnunet-dht-driver.c
@@ -850,8 +850,8 @@ update_meter (struct ProgressMeter *meter)
850 fprintf (stdout, "%sProgress: [0%%", meter->startup_string); 850 fprintf (stdout, "%sProgress: [0%%", meter->startup_string);
851 } 851 }
852 else 852 else
853 fprintf (stdout, "%d%%", (int) (((float) meter->completed 853 fprintf (stdout, "%d%%",
854 / meter->total) * 100)); 854 (int) (((float) meter->completed / meter->total) * 100));
855 } 855 }
856 else if (meter->completed % meter->dotnum == 0) 856 else if (meter->completed % meter->dotnum == 0)
857 fprintf (stdout, "."); 857 fprintf (stdout, ".");
@@ -922,10 +922,10 @@ put_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
922 GNUNET_DHT_disconnect (test_put->dht_handle); 922 GNUNET_DHT_disconnect (test_put->dht_handle);
923 test_put->dht_handle = NULL; 923 test_put->dht_handle = NULL;
924 if (replicate_same == GNUNET_NO) 924 if (replicate_same == GNUNET_NO)
925 test_put->daemon 925 test_put->daemon =
926 = GNUNET_TESTING_daemon_get (pg, 926 GNUNET_TESTING_daemon_get (pg,
927 GNUNET_CRYPTO_random_u32 927 GNUNET_CRYPTO_random_u32
928 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers)); 928 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers));
929} 929}
930 930
931/** 931/**
@@ -1010,11 +1010,10 @@ log_topology_cb (void *cls, const struct GNUNET_PeerIdentity *first,
1010 1010
1011 if ((first != NULL) && (second != NULL)) 1011 if ((first != NULL) && (second != NULL))
1012 { 1012 {
1013 if ((topo_ctx->peers_seen != NULL) && (GNUNET_NO 1013 if ((topo_ctx->peers_seen != NULL) &&
1014 == 1014 (GNUNET_NO ==
1015 GNUNET_CONTAINER_multihashmap_contains 1015 GNUNET_CONTAINER_multihashmap_contains (topo_ctx->peers_seen,
1016 (topo_ctx->peers_seen, 1016 &first->hashPubKey)))
1017 &first->hashPubKey)))
1018 { 1017 {
1019 GNUNET_CONTAINER_multihashmap_put (topo_ctx->peers_seen, 1018 GNUNET_CONTAINER_multihashmap_put (topo_ctx->peers_seen,
1020 &first->hashPubKey, NULL, 1019 &first->hashPubKey, NULL,
@@ -1109,15 +1108,14 @@ stats_handle (void *cls, const struct GNUNET_PeerIdentity *peer,
1109 dhtlog_handle->add_generic_stat (peer, name, subsystem, value); 1108 dhtlog_handle->add_generic_stat (peer, name, subsystem, value);
1110 if (GNUNET_CONTAINER_multihashmap_contains (stats_map, &peer->hashPubKey)) 1109 if (GNUNET_CONTAINER_multihashmap_contains (stats_map, &peer->hashPubKey))
1111 { 1110 {
1112 stats_ctx = GNUNET_CONTAINER_multihashmap_get (stats_map, 1111 stats_ctx =
1113 &peer->hashPubKey); 1112 GNUNET_CONTAINER_multihashmap_get (stats_map, &peer->hashPubKey);
1114 } 1113 }
1115 else 1114 else
1116 { 1115 {
1117 stats_ctx = GNUNET_malloc (sizeof (struct StatisticsIteratorContext)); 1116 stats_ctx = GNUNET_malloc (sizeof (struct StatisticsIteratorContext));
1118 stats_ctx->peer = peer; 1117 stats_ctx->peer = peer;
1119 GNUNET_CONTAINER_multihashmap_put (stats_map, &peer->hashPubKey, 1118 GNUNET_CONTAINER_multihashmap_put (stats_map, &peer->hashPubKey, stats_ctx,
1120 stats_ctx,
1121 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 1119 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1122 } 1120 }
1123 GNUNET_assert (stats_ctx != NULL); 1121 GNUNET_assert (stats_ctx != NULL);
@@ -1329,8 +1327,8 @@ send_find_peer_request (void *cls,
1329{ 1327{
1330 struct TestFindPeer *test_find_peer = cls; 1328 struct TestFindPeer *test_find_peer = cls;
1331 1329
1332 if (test_find_peer->find_peer_context->outstanding 1330 if (test_find_peer->find_peer_context->outstanding >
1333 > max_outstanding_find_peers) 1331 max_outstanding_find_peers)
1334 { 1332 {
1335 GNUNET_SCHEDULER_add_delayed (find_peer_offset, &send_find_peer_request, 1333 GNUNET_SCHEDULER_add_delayed (find_peer_offset, &send_find_peer_request,
1336 test_find_peer); 1334 test_find_peer);
@@ -1345,8 +1343,8 @@ send_find_peer_request (void *cls,
1345 return; 1343 return;
1346 } 1344 }
1347 1345
1348 test_find_peer->dht_handle = GNUNET_DHT_connect (test_find_peer->daemon->cfg, 1346 test_find_peer->dht_handle =
1349 1); 1347 GNUNET_DHT_connect (test_find_peer->daemon->cfg, 1);
1350 GNUNET_assert (test_find_peer->dht_handle != NULL); 1348 GNUNET_assert (test_find_peer->dht_handle != NULL);
1351 GNUNET_DHT_find_peers (test_find_peer->dht_handle, &handle_find_peer_sent, 1349 GNUNET_DHT_find_peers (test_find_peer->dht_handle, &handle_find_peer_sent,
1352 test_find_peer); 1350 test_find_peer);
@@ -1365,12 +1363,12 @@ add_new_connection (struct FindPeerContext *find_peer_context,
1365 struct PeerCount *first_count; 1363 struct PeerCount *first_count;
1366 struct PeerCount *second_count; 1364 struct PeerCount *second_count;
1367 1365
1368 if (GNUNET_CONTAINER_multihashmap_contains (find_peer_context->peer_hash, 1366 if (GNUNET_CONTAINER_multihashmap_contains
1369 &first->hashPubKey)) 1367 (find_peer_context->peer_hash, &first->hashPubKey))
1370 { 1368 {
1371 first_count 1369 first_count =
1372 = GNUNET_CONTAINER_multihashmap_get (find_peer_context->peer_hash, 1370 GNUNET_CONTAINER_multihashmap_get (find_peer_context->peer_hash,
1373 &first->hashPubKey); 1371 &first->hashPubKey);
1374 GNUNET_assert (first_count != NULL); 1372 GNUNET_assert (first_count != NULL);
1375 first_count->count++; 1373 first_count->count++;
1376 GNUNET_CONTAINER_heap_update_cost (find_peer_context->peer_min_heap, 1374 GNUNET_CONTAINER_heap_update_cost (find_peer_context->peer_min_heap,
@@ -1382,20 +1380,20 @@ add_new_connection (struct FindPeerContext *find_peer_context,
1382 first_count = GNUNET_malloc (sizeof (struct PeerCount)); 1380 first_count = GNUNET_malloc (sizeof (struct PeerCount));
1383 first_count->count = 1; 1381 first_count->count = 1;
1384 memcpy (&first_count->peer_id, first, sizeof (struct GNUNET_PeerIdentity)); 1382 memcpy (&first_count->peer_id, first, sizeof (struct GNUNET_PeerIdentity));
1385 first_count->heap_node 1383 first_count->heap_node =
1386 = GNUNET_CONTAINER_heap_insert (find_peer_context->peer_min_heap, 1384 GNUNET_CONTAINER_heap_insert (find_peer_context->peer_min_heap,
1387 first_count, first_count->count); 1385 first_count, first_count->count);
1388 GNUNET_CONTAINER_multihashmap_put (find_peer_context->peer_hash, 1386 GNUNET_CONTAINER_multihashmap_put (find_peer_context->peer_hash,
1389 &first->hashPubKey, first_count, 1387 &first->hashPubKey, first_count,
1390 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 1388 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1391 } 1389 }
1392 1390
1393 if (GNUNET_CONTAINER_multihashmap_contains (find_peer_context->peer_hash, 1391 if (GNUNET_CONTAINER_multihashmap_contains
1394 &second->hashPubKey)) 1392 (find_peer_context->peer_hash, &second->hashPubKey))
1395 { 1393 {
1396 second_count 1394 second_count =
1397 = GNUNET_CONTAINER_multihashmap_get (find_peer_context->peer_hash, 1395 GNUNET_CONTAINER_multihashmap_get (find_peer_context->peer_hash,
1398 &second->hashPubKey); 1396 &second->hashPubKey);
1399 GNUNET_assert (second_count != NULL); 1397 GNUNET_assert (second_count != NULL);
1400 second_count->count++; 1398 second_count->count++;
1401 GNUNET_CONTAINER_heap_update_cost (find_peer_context->peer_min_heap, 1399 GNUNET_CONTAINER_heap_update_cost (find_peer_context->peer_min_heap,
@@ -1408,9 +1406,9 @@ add_new_connection (struct FindPeerContext *find_peer_context,
1408 second_count->count = 1; 1406 second_count->count = 1;
1409 memcpy (&second_count->peer_id, second, 1407 memcpy (&second_count->peer_id, second,
1410 sizeof (struct GNUNET_PeerIdentity)); 1408 sizeof (struct GNUNET_PeerIdentity));
1411 second_count->heap_node 1409 second_count->heap_node =
1412 = GNUNET_CONTAINER_heap_insert (find_peer_context->peer_min_heap, 1410 GNUNET_CONTAINER_heap_insert (find_peer_context->peer_min_heap,
1413 second_count, second_count->count); 1411 second_count, second_count->count);
1414 GNUNET_CONTAINER_multihashmap_put (find_peer_context->peer_hash, 1412 GNUNET_CONTAINER_multihashmap_put (find_peer_context->peer_hash,
1415 &second->hashPubKey, second_count, 1413 &second->hashPubKey, second_count,
1416 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 1414 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
@@ -1456,19 +1454,19 @@ iterate_min_heap_peers (void *cls, struct GNUNET_CONTAINER_HeapNode *node,
1456 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1454 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1457 "Peer %s has 0 connections. Trying to connect to %s...\n", 1455 "Peer %s has 0 connections. Trying to connect to %s...\n",
1458 GNUNET_i2s (&peer_count->peer_id), d2->shortname); 1456 GNUNET_i2s (&peer_count->peer_id), d2->shortname);
1459 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1457 timeout =
1460 DEFAULT_CONNECT_TIMEOUT); 1458 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
1461 if (GNUNET_TIME_relative_to_absolute (timeout).abs_value 1459 DEFAULT_CONNECT_TIMEOUT);
1462 > find_peer_context->endtime.abs_value) 1460 if (GNUNET_TIME_relative_to_absolute (timeout).abs_value >
1461 find_peer_context->endtime.abs_value)
1463 { 1462 {
1464 timeout = GNUNET_TIME_absolute_get_remaining (find_peer_context->endtime); 1463 timeout = GNUNET_TIME_absolute_get_remaining (find_peer_context->endtime);
1465 } 1464 }
1466 GNUNET_TESTING_daemons_connect (d1, d2, timeout, 1465 GNUNET_TESTING_daemons_connect (d1, d2, timeout, DEFAULT_RECONNECT_ATTEMPTS,
1467 DEFAULT_RECONNECT_ATTEMPTS, GNUNET_YES, 1466 GNUNET_YES, NULL, NULL);
1468 NULL, NULL);
1469 } 1467 }
1470 if (GNUNET_TIME_absolute_get_remaining (find_peer_context->endtime).rel_value 1468 if (GNUNET_TIME_absolute_get_remaining (find_peer_context->endtime).
1471 > 0) 1469 rel_value > 0)
1472 return GNUNET_YES; 1470 return GNUNET_YES;
1473 else 1471 else
1474 return GNUNET_NO; 1472 return GNUNET_NO;
@@ -1477,10 +1475,10 @@ iterate_min_heap_peers (void *cls, struct GNUNET_CONTAINER_HeapNode *node,
1477/** 1475/**
1478 * Forward declaration. 1476 * Forward declaration.
1479 */ 1477 */
1480static void 1478static void schedule_churn_find_peer_requests (void *cls,
1481schedule_churn_find_peer_requests (void *cls, 1479 const struct
1482 const struct GNUNET_SCHEDULER_TaskContext 1480 GNUNET_SCHEDULER_TaskContext
1483 *tc); 1481 *tc);
1484 1482
1485/** 1483/**
1486 * Callback for iterating over all the peer connections of a peer group. 1484 * Callback for iterating over all the peer connections of a peer group.
@@ -1557,11 +1555,12 @@ count_peers_churn_cb (void *cls, const struct GNUNET_PeerIdentity *first,
1557 */ 1555 */
1558 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1556 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1559 "Out of %u peers, fewest connections is %d\n", 1557 "Out of %u peers, fewest connections is %d\n",
1560 GNUNET_CONTAINER_heap_get_size 1558 GNUNET_CONTAINER_heap_get_size (find_peer_context->
1561 (find_peer_context->peer_min_heap), peer_count->count); 1559 peer_min_heap),
1560 peer_count->count);
1562 if ((peer_count->count == 0) && 1561 if ((peer_count->count == 0) &&
1563 (GNUNET_TIME_absolute_get_remaining 1562 (GNUNET_TIME_absolute_get_remaining (find_peer_context->endtime).
1564 (find_peer_context->endtime).rel_value > 0)) 1563 rel_value > 0))
1565 { 1564 {
1566 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1565 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1567 "Found peer with no connections, will choose some peer(s) at random to connect to!\n"); 1566 "Found peer with no connections, will choose some peer(s) at random to connect to!\n");
@@ -1571,9 +1570,8 @@ count_peers_churn_cb (void *cls, const struct GNUNET_PeerIdentity *first,
1571 GNUNET_SCHEDULER_add_now (&schedule_churn_find_peer_requests, 1570 GNUNET_SCHEDULER_add_now (&schedule_churn_find_peer_requests,
1572 find_peer_context); 1571 find_peer_context);
1573 } 1572 }
1574 else if ((GNUNET_TIME_absolute_get_remaining 1573 else if ((GNUNET_TIME_absolute_get_remaining (find_peer_context->endtime).
1575 (find_peer_context->endtime).rel_value > 0) && 1574 rel_value > 0) && (find_peer_context->last_sent != 0))
1576 (find_peer_context->last_sent != 0))
1577 { 1575 {
1578 GNUNET_SCHEDULER_add_now (&schedule_churn_find_peer_requests, 1576 GNUNET_SCHEDULER_add_now (&schedule_churn_find_peer_requests,
1579 find_peer_context); 1577 find_peer_context);
@@ -1596,8 +1594,7 @@ count_peers_churn_cb (void *cls, const struct GNUNET_PeerIdentity *first,
1596 topo_ctx->cls = all_gets; 1594 topo_ctx->cls = all_gets;
1597 topo_ctx->timeout = DEFAULT_GET_TIMEOUT; 1595 topo_ctx->timeout = DEFAULT_GET_TIMEOUT;
1598 topo_ctx->peers_seen = GNUNET_CONTAINER_multihashmap_create (num_peers); 1596 topo_ctx->peers_seen = GNUNET_CONTAINER_multihashmap_create (num_peers);
1599 die_task 1597 die_task =
1600 =
1601 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add 1598 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add
1602 (GNUNET_TIME_relative_add 1599 (GNUNET_TIME_relative_add
1603 (DEFAULT_GET_TIMEOUT, 1600 (DEFAULT_GET_TIMEOUT,
@@ -1609,8 +1606,7 @@ count_peers_churn_cb (void *cls, const struct GNUNET_PeerIdentity *first,
1609 } 1606 }
1610 else 1607 else
1611 { 1608 {
1612 die_task 1609 die_task =
1613 =
1614 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add 1610 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add
1615 (GNUNET_TIME_relative_add 1611 (GNUNET_TIME_relative_add
1616 (DEFAULT_GET_TIMEOUT, 1612 (DEFAULT_GET_TIMEOUT,
@@ -1641,12 +1637,12 @@ schedule_churn_find_peer_requests (void *cls,
1641 1637
1642 if (find_peer_ctx->previous_peers == 0) /* First time, go slowly */ 1638 if (find_peer_ctx->previous_peers == 0) /* First time, go slowly */
1643 find_peer_ctx->total = 1; 1639 find_peer_ctx->total = 1;
1644 else if (find_peer_ctx->current_peers - find_peer_ctx->previous_peers 1640 else if (find_peer_ctx->current_peers - find_peer_ctx->previous_peers <
1645 < MIN_FIND_PEER_CUTOFF) 1641 MIN_FIND_PEER_CUTOFF)
1646 find_peer_ctx->total = find_peer_ctx->total / 2; 1642 find_peer_ctx->total = find_peer_ctx->total / 2;
1647 else if (find_peer_ctx->current_peers - find_peer_ctx->previous_peers > MAX_FIND_PEER_CUTOFF) /* Found LOTS of peers, still go slowly */ 1643 else if (find_peer_ctx->current_peers - find_peer_ctx->previous_peers > MAX_FIND_PEER_CUTOFF) /* Found LOTS of peers, still go slowly */
1648 find_peer_ctx->total = find_peer_ctx->last_sent - (find_peer_ctx->last_sent 1644 find_peer_ctx->total =
1649 / 4); 1645 find_peer_ctx->last_sent - (find_peer_ctx->last_sent / 4);
1650 else 1646 else
1651 find_peer_ctx->total = find_peer_ctx->last_sent * 4; 1647 find_peer_ctx->total = find_peer_ctx->last_sent * 4;
1652 1648
@@ -1659,8 +1655,8 @@ schedule_churn_find_peer_requests (void *cls,
1659 find_peer_ctx->total); 1655 find_peer_ctx->total);
1660 1656
1661 if (find_peer_ctx->total > 0) 1657 if (find_peer_ctx->total > 0)
1662 find_peer_offset = GNUNET_TIME_relative_divide (find_peer_delay, 1658 find_peer_offset =
1663 find_peer_ctx->total); 1659 GNUNET_TIME_relative_divide (find_peer_delay, find_peer_ctx->total);
1664 else 1660 else
1665 { 1661 {
1666 find_peer_ctx->previous_peers = find_peer_ctx->current_peers; 1662 find_peer_ctx->previous_peers = find_peer_ctx->current_peers;
@@ -1672,8 +1668,8 @@ schedule_churn_find_peer_requests (void *cls,
1672 { 1668 {
1673 test_find_peer = GNUNET_malloc (sizeof (struct TestFindPeer)); 1669 test_find_peer = GNUNET_malloc (sizeof (struct TestFindPeer));
1674 /* If we have sent requests, choose peers with a low number of connections to send requests from */ 1670 /* If we have sent requests, choose peers with a low number of connections to send requests from */
1675 peer_count 1671 peer_count =
1676 = GNUNET_CONTAINER_heap_remove_root (find_peer_ctx->peer_min_heap); 1672 GNUNET_CONTAINER_heap_remove_root (find_peer_ctx->peer_min_heap);
1677 GNUNET_assert (peer_count != NULL); 1673 GNUNET_assert (peer_count != NULL);
1678 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1674 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1679 "Sending find peer request from peer with %u connections\n", 1675 "Sending find peer request from peer with %u connections\n",
@@ -1681,8 +1677,8 @@ schedule_churn_find_peer_requests (void *cls,
1681 GNUNET_CONTAINER_multihashmap_remove (find_peer_ctx->peer_hash, 1677 GNUNET_CONTAINER_multihashmap_remove (find_peer_ctx->peer_hash,
1682 &peer_count->peer_id.hashPubKey, 1678 &peer_count->peer_id.hashPubKey,
1683 peer_count); 1679 peer_count);
1684 test_find_peer->daemon 1680 test_find_peer->daemon =
1685 = GNUNET_TESTING_daemon_get_by_id (pg, &peer_count->peer_id); 1681 GNUNET_TESTING_daemon_get_by_id (pg, &peer_count->peer_id);
1686 GNUNET_assert (test_find_peer->daemon != NULL); 1682 GNUNET_assert (test_find_peer->daemon != NULL);
1687 test_find_peer->find_peer_context = find_peer_ctx; 1683 test_find_peer->find_peer_context = find_peer_ctx;
1688 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 1684 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
@@ -1690,12 +1686,12 @@ schedule_churn_find_peer_requests (void *cls,
1690 &send_find_peer_request, test_find_peer); 1686 &send_find_peer_request, test_find_peer);
1691 } 1687 }
1692 1688
1693 if ((find_peer_ctx->peer_hash == NULL) && (find_peer_ctx->peer_min_heap 1689 if ((find_peer_ctx->peer_hash == NULL) &&
1694 == NULL)) 1690 (find_peer_ctx->peer_min_heap == NULL))
1695 { 1691 {
1696 find_peer_ctx->peer_hash = GNUNET_CONTAINER_multihashmap_create (num_peers); 1692 find_peer_ctx->peer_hash = GNUNET_CONTAINER_multihashmap_create (num_peers);
1697 find_peer_ctx->peer_min_heap 1693 find_peer_ctx->peer_min_heap =
1698 = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 1694 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
1699 } 1695 }
1700 else 1696 else
1701 { 1697 {
@@ -1764,9 +1760,9 @@ churn_complete (void *cls, const char *emsg)
1764 memcpy (&peer_count->peer_id, &temp_daemon->id, 1760 memcpy (&peer_count->peer_id, &temp_daemon->id,
1765 sizeof (struct GNUNET_PeerIdentity)); 1761 sizeof (struct GNUNET_PeerIdentity));
1766 GNUNET_assert (peer_count->count == 0); 1762 GNUNET_assert (peer_count->count == 0);
1767 peer_count->heap_node 1763 peer_count->heap_node =
1768 = GNUNET_CONTAINER_heap_insert (find_peer_context->peer_min_heap, 1764 GNUNET_CONTAINER_heap_insert (find_peer_context->peer_min_heap,
1769 peer_count, peer_count->count); 1765 peer_count, peer_count->count);
1770 GNUNET_CONTAINER_multihashmap_put (find_peer_context->peer_hash, 1766 GNUNET_CONTAINER_multihashmap_put (find_peer_context->peer_hash,
1771 &temp_daemon->id.hashPubKey, 1767 &temp_daemon->id.hashPubKey,
1772 peer_count, 1768 peer_count,
@@ -1775,10 +1771,9 @@ churn_complete (void *cls, const char *emsg)
1775 } 1771 }
1776 } 1772 }
1777 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1773 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1778 "Added %d peers to heap, total size %d\n", 1774 "Added %d peers to heap, total size %d\n", count_added,
1779 count_added, 1775 GNUNET_CONTAINER_heap_get_size (find_peer_context->
1780 GNUNET_CONTAINER_heap_get_size 1776 peer_min_heap));
1781 (find_peer_context->peer_min_heap));
1782 GNUNET_SCHEDULER_add_delayed (DEFAULT_PEER_DISCONNECT_TIMEOUT, 1777 GNUNET_SCHEDULER_add_delayed (DEFAULT_PEER_DISCONNECT_TIMEOUT,
1783 &schedule_churn_get_topology, 1778 &schedule_churn_get_topology,
1784 find_peer_context); 1779 find_peer_context);
@@ -1794,33 +1789,33 @@ churn_complete (void *cls, const char *emsg)
1794 topo_ctx->cls = all_gets; 1789 topo_ctx->cls = all_gets;
1795 topo_ctx->timeout = DEFAULT_GET_TIMEOUT; 1790 topo_ctx->timeout = DEFAULT_GET_TIMEOUT;
1796 topo_ctx->peers_seen = GNUNET_CONTAINER_multihashmap_create (num_peers); 1791 topo_ctx->peers_seen = GNUNET_CONTAINER_multihashmap_create (num_peers);
1797 calc_timeout = GNUNET_TIME_relative_add (DEFAULT_GET_TIMEOUT, 1792 calc_timeout =
1798 all_get_timeout); 1793 GNUNET_TIME_relative_add (DEFAULT_GET_TIMEOUT, all_get_timeout);
1799 calc_timeout 1794 calc_timeout =
1800 = GNUNET_TIME_relative_add (calc_timeout, 1795 GNUNET_TIME_relative_add (calc_timeout,
1801 DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT); 1796 DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT);
1802 calc_timeout 1797 calc_timeout =
1803 = GNUNET_TIME_relative_add (calc_timeout, 1798 GNUNET_TIME_relative_add (calc_timeout,
1804 DEFAULT_PEER_DISCONNECT_TIMEOUT); 1799 DEFAULT_PEER_DISCONNECT_TIMEOUT);
1805 die_task 1800 die_task =
1806 = GNUNET_SCHEDULER_add_delayed (calc_timeout, &end_badly, 1801 GNUNET_SCHEDULER_add_delayed (calc_timeout, &end_badly,
1807 "from do gets (churn_complete)"); 1802 "from do gets (churn_complete)");
1808 GNUNET_SCHEDULER_add_delayed (DEFAULT_PEER_DISCONNECT_TIMEOUT, 1803 GNUNET_SCHEDULER_add_delayed (DEFAULT_PEER_DISCONNECT_TIMEOUT,
1809 &capture_current_topology, topo_ctx); 1804 &capture_current_topology, topo_ctx);
1810 dhtlog_handle->insert_round (DHT_ROUND_GET, rounds_finished); 1805 dhtlog_handle->insert_round (DHT_ROUND_GET, rounds_finished);
1811 } 1806 }
1812 else 1807 else
1813 { 1808 {
1814 calc_timeout = GNUNET_TIME_relative_add (DEFAULT_GET_TIMEOUT, 1809 calc_timeout =
1815 all_get_timeout); 1810 GNUNET_TIME_relative_add (DEFAULT_GET_TIMEOUT, all_get_timeout);
1816 calc_timeout 1811 calc_timeout =
1817 = GNUNET_TIME_relative_add (calc_timeout, 1812 GNUNET_TIME_relative_add (calc_timeout,
1818 DEFAULT_PEER_DISCONNECT_TIMEOUT); 1813 DEFAULT_PEER_DISCONNECT_TIMEOUT);
1819 die_task 1814 die_task =
1820 = GNUNET_SCHEDULER_add_delayed (calc_timeout, &end_badly, 1815 GNUNET_SCHEDULER_add_delayed (calc_timeout, &end_badly,
1821 "from do gets (churn_complete)"); 1816 "from do gets (churn_complete)");
1822 GNUNET_SCHEDULER_add_delayed (DEFAULT_PEER_DISCONNECT_TIMEOUT, 1817 GNUNET_SCHEDULER_add_delayed (DEFAULT_PEER_DISCONNECT_TIMEOUT, &do_get,
1823 &do_get, all_gets); 1818 all_gets);
1824 } 1819 }
1825 } 1820 }
1826} 1821}
@@ -1880,10 +1875,10 @@ churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1880 find_peer_context->previous_peers = 0; 1875 find_peer_context->previous_peers = 0;
1881 find_peer_context->current_peers = 0; 1876 find_peer_context->current_peers = 0;
1882 find_peer_context->endtime = GNUNET_TIME_relative_to_absolute (timeout); 1877 find_peer_context->endtime = GNUNET_TIME_relative_to_absolute (timeout);
1883 find_peer_context->peer_hash 1878 find_peer_context->peer_hash =
1884 = GNUNET_CONTAINER_multihashmap_create (num_peers); 1879 GNUNET_CONTAINER_multihashmap_create (num_peers);
1885 find_peer_context->peer_min_heap 1880 find_peer_context->peer_min_heap =
1886 = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 1881 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
1887 } 1882 }
1888 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1883 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1889 "churn_peers: want %u total, %u running, starting %u, stopping %u\n", 1884 "churn_peers: want %u total, %u running, starting %u, stopping %u\n",
@@ -1914,12 +1909,12 @@ get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1914 /* Reset the uid (which item to search for) and the daemon (which peer to search from) for later get request iterations */ 1909 /* Reset the uid (which item to search for) and the daemon (which peer to search from) for later get request iterations */
1915 if (get_from_same == GNUNET_NO) 1910 if (get_from_same == GNUNET_NO)
1916 { 1911 {
1917 test_get->uid = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1912 test_get->uid =
1918 num_puts); 1913 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_puts);
1919 test_get->daemon 1914 test_get->daemon =
1920 = GNUNET_TESTING_daemon_get (pg, 1915 GNUNET_TESTING_daemon_get (pg,
1921 GNUNET_CRYPTO_random_u32 1916 GNUNET_CRYPTO_random_u32
1922 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers)); 1917 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers));
1923 } 1918 }
1924 1919
1925#if VERBOSE > 1 1920#if VERBOSE > 1
@@ -1986,8 +1981,7 @@ get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1986 if (dhtlog_handle != NULL) 1981 if (dhtlog_handle != NULL)
1987 dhtlog_handle->insert_round (DHT_ROUND_GET, rounds_finished); 1982 dhtlog_handle->insert_round (DHT_ROUND_GET, rounds_finished);
1988 1983
1989 die_task 1984 die_task =
1990 =
1991 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add 1985 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add
1992 (GNUNET_TIME_relative_add 1986 (GNUNET_TIME_relative_add
1993 (GNUNET_TIME_relative_multiply 1987 (GNUNET_TIME_relative_multiply
@@ -2004,8 +1998,7 @@ get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2004 { 1998 {
2005 if (dhtlog_handle != NULL) 1999 if (dhtlog_handle != NULL)
2006 dhtlog_handle->insert_round (DHT_ROUND_NORMAL, rounds_finished); 2000 dhtlog_handle->insert_round (DHT_ROUND_NORMAL, rounds_finished);
2007 die_task 2001 die_task =
2008 =
2009 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add 2002 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add
2010 (GNUNET_TIME_relative_multiply 2003 (GNUNET_TIME_relative_multiply
2011 (GNUNET_TIME_UNIT_SECONDS, 2004 (GNUNET_TIME_UNIT_SECONDS,
@@ -2133,21 +2126,18 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2133 2126
2134 cumulative_num_gets++; 2127 cumulative_num_gets++;
2135 /* Insert the data at the first peer */ 2128 /* Insert the data at the first peer */
2136 test_get->get_handle = GNUNET_DHT_get_start (test_get->dht_handle, get_delay, 2129 test_get->get_handle =
2137 GNUNET_BLOCK_TYPE_TEST, 2130 GNUNET_DHT_get_start (test_get->dht_handle, get_delay,
2138 &known_keys[test_get->uid], 2131 GNUNET_BLOCK_TYPE_TEST, &known_keys[test_get->uid],
2139 get_replication, 2132 get_replication, GNUNET_DHT_RO_NONE, NULL, 0, NULL,
2140 GNUNET_DHT_RO_NONE, NULL, 0, 2133 0, &get_result_iterator, test_get);
2141 NULL, 0, &get_result_iterator,
2142 test_get);
2143 2134
2144#if VERBOSE > 1 2135#if VERBOSE > 1
2145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting get for uid %u from peer %s\n", 2136 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting get for uid %u from peer %s\n",
2146 test_get->uid, test_get->daemon->shortname); 2137 test_get->uid, test_get->daemon->shortname);
2147#endif 2138#endif
2148 test_get->disconnect_task = GNUNET_SCHEDULER_add_delayed (get_timeout, 2139 test_get->disconnect_task =
2149 &get_stop_task, 2140 GNUNET_SCHEDULER_add_delayed (get_timeout, &get_stop_task, test_get);
2150 test_get);
2151 2141
2152 /* Schedule the next request in the linked list of get requests */ 2142 /* Schedule the next request in the linked list of get requests */
2153 GNUNET_SCHEDULER_add_now (&do_get, test_get->next); 2143 GNUNET_SCHEDULER_add_now (&do_get, test_get->next);
@@ -2171,14 +2161,14 @@ put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2171 2161
2172 /* Reset the daemon (which peer to insert at) for later put request iterations */ 2162 /* Reset the daemon (which peer to insert at) for later put request iterations */
2173 if (replicate_same == GNUNET_NO) 2163 if (replicate_same == GNUNET_NO)
2174 test_put->daemon 2164 test_put->daemon =
2175 = GNUNET_TESTING_daemon_get (pg, 2165 GNUNET_TESTING_daemon_get (pg,
2176 GNUNET_CRYPTO_random_u32 2166 GNUNET_CRYPTO_random_u32
2177 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers)); 2167 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers));
2178 2168
2179 GNUNET_SCHEDULER_cancel (test_put->disconnect_task); 2169 GNUNET_SCHEDULER_cancel (test_put->disconnect_task);
2180 test_put->disconnect_task = GNUNET_SCHEDULER_add_now (&put_disconnect_task, 2170 test_put->disconnect_task =
2181 test_put); 2171 GNUNET_SCHEDULER_add_now (&put_disconnect_task, test_put);
2182 if (GNUNET_YES == update_meter (put_meter)) 2172 if (GNUNET_YES == update_meter (put_meter))
2183 { 2173 {
2184 GNUNET_assert (outstanding_puts == 0); 2174 GNUNET_assert (outstanding_puts == 0);
@@ -2190,8 +2180,7 @@ put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2190 topo_ctx->cls = all_gets; 2180 topo_ctx->cls = all_gets;
2191 topo_ctx->timeout = DEFAULT_GET_TIMEOUT; 2181 topo_ctx->timeout = DEFAULT_GET_TIMEOUT;
2192 topo_ctx->peers_seen = GNUNET_CONTAINER_multihashmap_create (num_peers); 2182 topo_ctx->peers_seen = GNUNET_CONTAINER_multihashmap_create (num_peers);
2193 die_task 2183 die_task =
2194 =
2195 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add 2184 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add
2196 (GNUNET_TIME_relative_add 2185 (GNUNET_TIME_relative_add
2197 (DEFAULT_GET_TIMEOUT, all_get_timeout), 2186 (DEFAULT_GET_TIMEOUT, all_get_timeout),
@@ -2203,8 +2192,7 @@ put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2203 else 2192 else
2204 { 2193 {
2205 fprintf (stderr, "Scheduling die task (put finished)\n"); 2194 fprintf (stderr, "Scheduling die task (put finished)\n");
2206 die_task 2195 die_task =
2207 =
2208 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add 2196 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add
2209 (DEFAULT_GET_TIMEOUT, all_get_timeout), 2197 (DEFAULT_GET_TIMEOUT, all_get_timeout),
2210 &end_badly, 2198 &end_badly,
@@ -2240,8 +2228,9 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2240 2228
2241 for (i = 0; i < sizeof (data); i++) 2229 for (i = 0; i < sizeof (data); i++)
2242 { 2230 {
2243 memset (&data[i], GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2231 memset (&data[i],
2244 UINT32_MAX), 1); 2232 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX),
2233 1);
2245 } 2234 }
2246 2235
2247 if (outstanding_puts > max_outstanding_puts) 2236 if (outstanding_puts > max_outstanding_puts)
@@ -2264,23 +2253,23 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2264 put_replication, GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST, 2253 put_replication, GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST,
2265 sizeof (data), data, GNUNET_TIME_UNIT_FOREVER_ABS, put_delay, 2254 sizeof (data), data, GNUNET_TIME_UNIT_FOREVER_ABS, put_delay,
2266 &put_finished, test_put); 2255 &put_finished, test_put);
2267 test_put->disconnect_task 2256 test_put->disconnect_task =
2268 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_get_forever (), 2257 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_get_forever (),
2269 &put_disconnect_task, test_put); 2258 &put_disconnect_task, test_put);
2270 rand = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2); 2259 rand = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2);
2271 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 2260 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2272 (GNUNET_TIME_UNIT_SECONDS, rand), &do_put, 2261 (GNUNET_TIME_UNIT_SECONDS, rand), &do_put,
2273 test_put->next); 2262 test_put->next);
2274} 2263}
2275 2264
2276static void 2265static void schedule_find_peer_requests (void *cls,
2277schedule_find_peer_requests (void *cls, 2266 const struct
2278 const struct GNUNET_SCHEDULER_TaskContext *tc); 2267 GNUNET_SCHEDULER_TaskContext *tc);
2279 2268
2280#if HAVE_MALICIOUS 2269#if HAVE_MALICIOUS
2281static void 2270static void setup_malicious_peers (void *cls,
2282setup_malicious_peers (void *cls, 2271 const struct GNUNET_SCHEDULER_TaskContext
2283 const struct GNUNET_SCHEDULER_TaskContext *tc); 2272 *tc);
2284#endif 2273#endif
2285 2274
2286/** 2275/**
@@ -2325,18 +2314,17 @@ count_peers_cb (void *cls, const struct GNUNET_PeerIdentity *first,
2325 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2314 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2326 "Peer count finished (%u connections), %u new peers, connection estimate %u (target %u)\n", 2315 "Peer count finished (%u connections), %u new peers, connection estimate %u (target %u)\n",
2327 find_peer_context->current_peers, 2316 find_peer_context->current_peers,
2328 find_peer_context->current_peers 2317 find_peer_context->current_peers -
2329 - find_peer_context->previous_peers, 2318 find_peer_context->previous_peers,
2330 connection_estimate (num_peers, DEFAULT_BUCKET_SIZE), 2319 connection_estimate (num_peers, DEFAULT_BUCKET_SIZE),
2331 target_total_connections); 2320 target_total_connections);
2332 2321
2333 if ((find_peer_context->last_sent < 8) 2322 if ((find_peer_context->last_sent < 8) ||
2334 || ((find_peer_context->current_peers < 2 2323 ((find_peer_context->current_peers <
2335 * connection_estimate (num_peers, DEFAULT_BUCKET_SIZE)) 2324 2 * connection_estimate (num_peers, DEFAULT_BUCKET_SIZE)) &&
2336 && 2325 (GNUNET_TIME_absolute_get_remaining (find_peer_context->endtime).
2337 (GNUNET_TIME_absolute_get_remaining 2326 rel_value > 0) &&
2338 (find_peer_context->endtime).rel_value > 0) && 2327 (find_peer_context->current_peers < target_total_connections)))
2339 (find_peer_context->current_peers < target_total_connections)))
2340 { 2328 {
2341 GNUNET_SCHEDULER_add_now (&schedule_find_peer_requests, 2329 GNUNET_SCHEDULER_add_now (&schedule_find_peer_requests,
2342 find_peer_context); 2330 find_peer_context);
@@ -2381,8 +2369,8 @@ schedule_find_peer_requests (void *cls,
2381 if (find_peer_ctx->previous_peers == 0) /* First time, go slowly */ 2369 if (find_peer_ctx->previous_peers == 0) /* First time, go slowly */
2382 find_peer_ctx->total = 1; 2370 find_peer_ctx->total = 1;
2383 else if (find_peer_ctx->current_peers - find_peer_ctx->previous_peers > MAX_FIND_PEER_CUTOFF) /* Found LOTS of peers, still go slowly */ 2371 else if (find_peer_ctx->current_peers - find_peer_ctx->previous_peers > MAX_FIND_PEER_CUTOFF) /* Found LOTS of peers, still go slowly */
2384 find_peer_ctx->total = find_peer_ctx->last_sent - (find_peer_ctx->last_sent 2372 find_peer_ctx->total =
2385 / 8); 2373 find_peer_ctx->last_sent - (find_peer_ctx->last_sent / 8);
2386 else 2374 else
2387 find_peer_ctx->total = find_peer_ctx->last_sent * 2; 2375 find_peer_ctx->total = find_peer_ctx->last_sent * 2;
2388 2376
@@ -2397,8 +2385,8 @@ schedule_find_peer_requests (void *cls,
2397 "Sending %u find peer messages (goal at least %u connections)\n", 2385 "Sending %u find peer messages (goal at least %u connections)\n",
2398 find_peer_ctx->total, target_total_connections); 2386 find_peer_ctx->total, target_total_connections);
2399 2387
2400 find_peer_offset = GNUNET_TIME_relative_divide (find_peer_delay, 2388 find_peer_offset =
2401 find_peer_ctx->total); 2389 GNUNET_TIME_relative_divide (find_peer_delay, find_peer_ctx->total);
2402 for (i = 0; i < find_peer_ctx->total; i++) 2390 for (i = 0; i < find_peer_ctx->total; i++)
2403 { 2391 {
2404 test_find_peer = GNUNET_malloc (sizeof (struct TestFindPeer)); 2392 test_find_peer = GNUNET_malloc (sizeof (struct TestFindPeer));
@@ -2418,9 +2406,10 @@ schedule_find_peer_requests (void *cls,
2418 * will be between 0 - 10, second between 10 - 20, etc. 2406 * will be between 0 - 10, second between 10 - 20, etc.
2419 */ 2407 */
2420 random = (num_peers / find_peer_ctx->total) * i; 2408 random = (num_peers / find_peer_ctx->total) * i;
2421 random = random 2409 random =
2422 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2410 random + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
2423 (num_peers / find_peer_ctx->total)); 2411 (num_peers /
2412 find_peer_ctx->total));
2424 if (random >= num_peers) 2413 if (random >= num_peers)
2425 { 2414 {
2426 random = random - num_peers; 2415 random = random - num_peers;
@@ -2432,12 +2421,14 @@ schedule_find_peer_requests (void *cls,
2432 } 2421 }
2433 else /* If we have sent requests, choose peers with a low number of connections to send requests from */ 2422 else /* If we have sent requests, choose peers with a low number of connections to send requests from */
2434 { 2423 {
2435 peer_count 2424 peer_count =
2436 = GNUNET_CONTAINER_heap_remove_root (find_peer_ctx->peer_min_heap); 2425 GNUNET_CONTAINER_heap_remove_root (find_peer_ctx->peer_min_heap);
2437 GNUNET_assert (GNUNET_YES == 2426 GNUNET_assert (GNUNET_YES ==
2438 GNUNET_CONTAINER_multihashmap_remove 2427 GNUNET_CONTAINER_multihashmap_remove (find_peer_ctx->
2439 (find_peer_ctx->peer_hash, &peer_count->peer_id.hashPubKey, 2428 peer_hash,
2440 peer_count)); 2429 &peer_count->peer_id.
2430 hashPubKey,
2431 peer_count));
2441 test_find_peer->daemon = 2432 test_find_peer->daemon =
2442 GNUNET_TESTING_daemon_get_by_id (pg, &peer_count->peer_id); 2433 GNUNET_TESTING_daemon_get_by_id (pg, &peer_count->peer_id);
2443 GNUNET_assert (test_find_peer->daemon != NULL); 2434 GNUNET_assert (test_find_peer->daemon != NULL);
@@ -2449,12 +2440,12 @@ schedule_find_peer_requests (void *cls,
2449 &send_find_peer_request, test_find_peer); 2440 &send_find_peer_request, test_find_peer);
2450 } 2441 }
2451 2442
2452 if ((find_peer_ctx->peer_hash == NULL) && (find_peer_ctx->peer_min_heap 2443 if ((find_peer_ctx->peer_hash == NULL) &&
2453 == NULL)) 2444 (find_peer_ctx->peer_min_heap == NULL))
2454 { 2445 {
2455 find_peer_ctx->peer_hash = GNUNET_CONTAINER_multihashmap_create (num_peers); 2446 find_peer_ctx->peer_hash = GNUNET_CONTAINER_multihashmap_create (num_peers);
2456 find_peer_ctx->peer_min_heap 2447 find_peer_ctx->peer_min_heap =
2457 = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 2448 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
2458 } 2449 }
2459 else 2450 else
2460 { 2451 {
@@ -2521,20 +2512,20 @@ setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2521 GNUNET_CRYPTO_hash_matching_bits (&known_keys[i], 2512 GNUNET_CRYPTO_hash_matching_bits (&known_keys[i],
2522 &sybil_target)); 2513 &sybil_target));
2523 } 2514 }
2524 temp_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2515 temp_peer =
2525 num_peers); 2516 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
2526 test_put->daemon = GNUNET_TESTING_daemon_get (pg, temp_peer); 2517 test_put->daemon = GNUNET_TESTING_daemon_get (pg, temp_peer);
2527 /* Don't start PUTs at malicious peers! */ 2518 /* Don't start PUTs at malicious peers! */
2528 if (malicious_bloom != NULL) 2519 if (malicious_bloom != NULL)
2529 { 2520 {
2530 count = 0; 2521 count = 0;
2531 hash_from_uid (temp_peer, &uid_hash); 2522 hash_from_uid (temp_peer, &uid_hash);
2532 while ((GNUNET_YES 2523 while ((GNUNET_YES ==
2533 == GNUNET_CONTAINER_bloomfilter_test (malicious_bloom, &uid_hash)) 2524 GNUNET_CONTAINER_bloomfilter_test (malicious_bloom, &uid_hash)) &&
2534 && (count < num_peers)) 2525 (count < num_peers))
2535 { 2526 {
2536 temp_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2527 temp_peer =
2537 num_peers); 2528 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
2538 hash_from_uid (temp_peer, &uid_hash); 2529 hash_from_uid (temp_peer, &uid_hash);
2539 test_put->daemon = GNUNET_TESTING_daemon_get (pg, temp_peer); 2530 test_put->daemon = GNUNET_TESTING_daemon_get (pg, temp_peer);
2540 count++; 2531 count++;
@@ -2551,28 +2542,28 @@ setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2551 for (i = 0; i < num_gets; i++) 2542 for (i = 0; i < num_gets; i++)
2552 { 2543 {
2553 test_get = GNUNET_malloc (sizeof (struct TestGetContext)); 2544 test_get = GNUNET_malloc (sizeof (struct TestGetContext));
2554 test_get->uid = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2545 test_get->uid =
2555 num_puts); 2546 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_puts);
2556#if REMEMBER 2547#if REMEMBER
2557 while (remember[test_get->uid][temp_daemon] == 1) 2548 while (remember[test_get->uid][temp_daemon] == 1)
2558 temp_daemon = 2549 temp_daemon =
2559 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers); 2550 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
2560 remember[test_get->uid][temp_daemon] = 1; 2551 remember[test_get->uid][temp_daemon] = 1;
2561#endif 2552#endif
2562 temp_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2553 temp_peer =
2563 num_peers); 2554 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
2564 test_get->daemon = GNUNET_TESTING_daemon_get (pg, temp_peer); 2555 test_get->daemon = GNUNET_TESTING_daemon_get (pg, temp_peer);
2565 /* Don't start GETs at malicious peers! */ 2556 /* Don't start GETs at malicious peers! */
2566 if (malicious_bloom != NULL) 2557 if (malicious_bloom != NULL)
2567 { 2558 {
2568 hash_from_uid (temp_peer, &uid_hash); 2559 hash_from_uid (temp_peer, &uid_hash);
2569 count = 0; 2560 count = 0;
2570 while ((GNUNET_YES 2561 while ((GNUNET_YES ==
2571 == GNUNET_CONTAINER_bloomfilter_test (malicious_bloom, &uid_hash)) 2562 GNUNET_CONTAINER_bloomfilter_test (malicious_bloom, &uid_hash)) &&
2572 && (count < num_peers)) 2563 (count < num_peers))
2573 { 2564 {
2574 temp_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2565 temp_peer =
2575 num_peers); 2566 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
2576 hash_from_uid (temp_peer, &uid_hash); 2567 hash_from_uid (temp_peer, &uid_hash);
2577 test_get->daemon = GNUNET_TESTING_daemon_get (pg, temp_peer); 2568 test_get->daemon = GNUNET_TESTING_daemon_get (pg, temp_peer);
2578 count++; 2569 count++;
@@ -2586,8 +2577,7 @@ setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2586 } 2577 }
2587 2578
2588 /*GNUNET_SCHEDULER_cancel (die_task); */ 2579 /*GNUNET_SCHEDULER_cancel (die_task); */
2589 die_task 2580 die_task =
2590 =
2591 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 2581 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2592 (GNUNET_TIME_UNIT_SECONDS, num_puts * 2), 2582 (GNUNET_TIME_UNIT_SECONDS, num_puts * 2),
2593 &end_badly, "from do puts"); 2583 &end_badly, "from do puts");
@@ -2660,8 +2650,7 @@ continue_puts_and_gets (void *cls,
2660 "Scheduling find peer requests during \"settle\" time.\n"); 2650 "Scheduling find peer requests during \"settle\" time.\n");
2661 find_peer_context = GNUNET_malloc (sizeof (struct FindPeerContext)); 2651 find_peer_context = GNUNET_malloc (sizeof (struct FindPeerContext));
2662 find_peer_context->count_peers_cb = &count_peers_cb; 2652 find_peer_context->count_peers_cb = &count_peers_cb;
2663 find_peer_context->endtime 2653 find_peer_context->endtime =
2664 =
2665 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply 2654 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
2666 (GNUNET_TIME_UNIT_SECONDS, 2655 (GNUNET_TIME_UNIT_SECONDS,
2667 settle_time)); 2656 settle_time));
@@ -2690,8 +2679,8 @@ malicious_disconnect_task (void *cls,
2690 ctx->dht_handle = NULL; 2679 ctx->dht_handle = NULL;
2691 GNUNET_free (ctx); 2680 GNUNET_free (ctx);
2692 2681
2693 if (malicious_completed == malicious_getters + malicious_putters 2682 if (malicious_completed ==
2694 + malicious_droppers) 2683 malicious_getters + malicious_putters + malicious_droppers)
2695 { 2684 {
2696 fprintf (stderr, "Finished setting all malicious peers up!\n"); 2685 fprintf (stderr, "Finished setting all malicious peers up!\n");
2697 } 2686 }
@@ -2757,9 +2746,9 @@ set_malicious (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2757 break; 2746 break;
2758 } 2747 }
2759 2748
2760 ctx->disconnect_task 2749 ctx->disconnect_task =
2761 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 2750 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
2762 &malicious_disconnect_task, ctx); 2751 &malicious_disconnect_task, ctx);
2763} 2752}
2764 2753
2765/** 2754/**
@@ -2890,16 +2879,17 @@ setup_malicious_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2890 2879
2891#if ONLY_TESTING 2880#if ONLY_TESTING
2892/* Forward declaration */ 2881/* Forward declaration */
2893static void 2882static void topology_callback (void *cls,
2894topology_callback (void *cls, 2883 const struct GNUNET_PeerIdentity *first,
2895 const struct GNUNET_PeerIdentity *first, 2884 const struct GNUNET_PeerIdentity *second,
2896 const struct GNUNET_PeerIdentity *second, 2885 uint32_t distance,
2897 uint32_t distance, 2886 const struct GNUNET_CONFIGURATION_Handle
2898 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 2887 *first_cfg,
2899 const struct GNUNET_CONFIGURATION_Handle *second_cfg, 2888 const struct GNUNET_CONFIGURATION_Handle
2900 struct GNUNET_TESTING_Daemon *first_daemon, 2889 *second_cfg,
2901 struct GNUNET_TESTING_Daemon *second_daemon, 2890 struct GNUNET_TESTING_Daemon *first_daemon,
2902 const char *emsg); 2891 struct GNUNET_TESTING_Daemon *second_daemon,
2892 const char *emsg);
2903 2893
2904/** 2894/**
2905 * Retry connecting two specific peers until they connect, 2895 * Retry connecting two specific peers until they connect,
@@ -2920,8 +2910,7 @@ repeat_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2920 repeat_connect_peer2->cfgfile); 2910 repeat_connect_peer2->cfgfile);
2921 2911
2922 repeat_connect_task = GNUNET_SCHEDULER_NO_TASK; 2912 repeat_connect_task = GNUNET_SCHEDULER_NO_TASK;
2923 GNUNET_TESTING_daemons_connect (repeat_connect_peer1, 2913 GNUNET_TESTING_daemons_connect (repeat_connect_peer1, repeat_connect_peer2,
2924 repeat_connect_peer2,
2925 GNUNET_TIME_relative_multiply 2914 GNUNET_TIME_relative_multiply
2926 (GNUNET_TIME_UNIT_SECONDS, 60), 2, 2915 (GNUNET_TIME_UNIT_SECONDS, 60), 2,
2927 &topology_callback, NULL); 2916 &topology_callback, NULL);
@@ -2989,9 +2978,9 @@ topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
2989 } 2978 }
2990#endif 2979#endif
2991 2980
2992 if (GNUNET_TIME_absolute_get_difference (connect_last_time, 2981 if (GNUNET_TIME_absolute_get_difference
2993 GNUNET_TIME_absolute_get 2982 (connect_last_time,
2994 ()).rel_value > 2983 GNUNET_TIME_absolute_get ()).rel_value >
2995 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2984 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
2996 CONN_UPDATE_DURATION).rel_value) 2985 CONN_UPDATE_DURATION).rel_value)
2997 { 2986 {
@@ -3002,19 +2991,19 @@ topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
3002 new_failed_connections = failed_connections - previous_failed_connections; 2991 new_failed_connections = failed_connections - previous_failed_connections;
3003 2992
3004 /* Get duration in seconds */ 2993 /* Get duration in seconds */
3005 duration 2994 duration =
3006 = GNUNET_TIME_absolute_get_difference (connect_last_time, 2995 GNUNET_TIME_absolute_get_difference (connect_last_time,
3007 GNUNET_TIME_absolute_get 2996 GNUNET_TIME_absolute_get ()).
3008 ()).rel_value / 1000; 2997 rel_value / 1000;
3009 total_duration = 2998 total_duration =
3010 GNUNET_TIME_absolute_get_difference (connect_start_time, 2999 GNUNET_TIME_absolute_get_difference (connect_start_time,
3011 GNUNET_TIME_absolute_get 3000 GNUNET_TIME_absolute_get ()).
3012 ()).rel_value / 1000; 3001 rel_value / 1000;
3013 3002
3014 failed_conns_per_sec_recent = (double) new_failed_connections 3003 failed_conns_per_sec_recent =
3015 / (double) duration; 3004 (double) new_failed_connections / (double) duration;
3016 failed_conns_per_sec_total = (double) failed_connections 3005 failed_conns_per_sec_total =
3017 / (double) total_duration; 3006 (double) failed_connections / (double) total_duration;
3018 conns_per_sec_recent = (double) new_connections / (double) duration; 3007 conns_per_sec_recent = (double) new_connections / (double) duration;
3019 conns_per_sec_total = (double) total_connections / (double) total_duration; 3008 conns_per_sec_total = (double) total_connections / (double) total_duration;
3020 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3009 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -3025,14 +3014,13 @@ topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
3025 previous_connections = total_connections; 3014 previous_connections = total_connections;
3026 previous_failed_connections = failed_connections; 3015 previous_failed_connections = failed_connections;
3027 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3016 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3028 "have %llu total_connections, %llu failed\n", 3017 "have %llu total_connections, %llu failed\n", total_connections,
3029 total_connections, failed_connections); 3018 failed_connections);
3030#if ONLY_TESTING 3019#if ONLY_TESTING
3031 /* These conditions likely mean we've entered the death spiral of doom */ 3020 /* These conditions likely mean we've entered the death spiral of doom */
3032 if ((total_connections > 20000) && 3021 if ((total_connections > 20000) && (conns_per_sec_recent < 5.0) &&
3033 (conns_per_sec_recent < 5.0) && 3022 (conns_per_sec_total > 10.0) && (emsg != NULL) &&
3034 (conns_per_sec_total > 10.0) && 3023 (repeat_connect_mode == GNUNET_NO))
3035 (emsg != NULL) && (repeat_connect_mode == GNUNET_NO))
3036 { 3024 {
3037 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3025 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3038 "Entering repeat connection attempt mode!\n"); 3026 "Entering repeat connection attempt mode!\n");
@@ -3096,10 +3084,10 @@ topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
3096 dhtlog_handle->insert_topology (expected_connections); 3084 dhtlog_handle->insert_topology (expected_connections);
3097 } 3085 }
3098 3086
3099 total_duration 3087 total_duration =
3100 = GNUNET_TIME_absolute_get_difference (connect_start_time, 3088 GNUNET_TIME_absolute_get_difference (connect_start_time,
3101 GNUNET_TIME_absolute_get 3089 GNUNET_TIME_absolute_get ()).
3102 ()).rel_value / 1000; 3090 rel_value / 1000;
3103 failed_conns_per_sec_total = 3091 failed_conns_per_sec_total =
3104 (long double) failed_connections / total_duration; 3092 (long double) failed_connections / total_duration;
3105 conns_per_sec_total = (long double) total_connections / total_duration; 3093 conns_per_sec_total = (long double) total_connections / total_duration;
@@ -3162,9 +3150,9 @@ topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
3162 else if (total_connections + failed_connections == expected_connections) 3150 else if (total_connections + failed_connections == expected_connections)
3163 { 3151 {
3164 GNUNET_SCHEDULER_cancel (die_task); 3152 GNUNET_SCHEDULER_cancel (die_task);
3165 die_task 3153 die_task =
3166 = GNUNET_SCHEDULER_add_now (&end_badly, 3154 GNUNET_SCHEDULER_add_now (&end_badly,
3167 "from topology_callback (too many failed connections)"); 3155 "from topology_callback (too many failed connections)");
3168 } 3156 }
3169} 3157}
3170 3158
@@ -3200,8 +3188,7 @@ peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
3200 3188
3201 GNUNET_asprintf (&revision_str, "%llu", revision); 3189 GNUNET_asprintf (&revision_str, "%llu", revision);
3202 if (GNUNET_YES == insert_gauger_data) 3190 if (GNUNET_YES == insert_gauger_data)
3203 GAUGER_ID ("DHT_TESTING", 3191 GAUGER_ID ("DHT_TESTING", "peer_startup_time",
3204 "peer_startup_time",
3205 GNUNET_TIME_absolute_get_duration (peer_start_time).rel_value / 3192 GNUNET_TIME_absolute_get_duration (peer_start_time).rel_value /
3206 (double) num_peers, "ms/peer", revision_str); 3193 (double) num_peers, "ms/peer", revision_str);
3207 GNUNET_free (revision_str); 3194 GNUNET_free (revision_str);
@@ -3210,28 +3197,26 @@ peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
3210 if ((pg != NULL) && (peers_left == 0)) 3197 if ((pg != NULL) && (peers_left == 0))
3211 { 3198 {
3212 connect_start_time = GNUNET_TIME_absolute_get (); 3199 connect_start_time = GNUNET_TIME_absolute_get ();
3213 expected_connections 3200 expected_connections =
3214 = GNUNET_TESTING_connect_topology (pg, 3201 GNUNET_TESTING_connect_topology (pg, connect_topology,
3215 connect_topology, 3202 connect_topology_option,
3216 connect_topology_option, 3203 connect_topology_option_modifier,
3217 connect_topology_option_modifier, 3204 connect_timeout, connect_attempts,
3218 connect_timeout, 3205 NULL, NULL);
3219 connect_attempts, NULL, NULL); 3206
3220 3207 peer_connect_meter =
3221 peer_connect_meter = create_meter (expected_connections, 3208 create_meter (expected_connections, "Peer connection ", GNUNET_YES);
3222 "Peer connection ", GNUNET_YES);
3223 fprintf (stderr, "Have %d expected connections\n", expected_connections); 3209 fprintf (stderr, "Have %d expected connections\n", expected_connections);
3224 } 3210 }
3225 3211
3226 if (expected_connections == 0) 3212 if (expected_connections == 0)
3227 { 3213 {
3228 die_task 3214 die_task =
3229 = GNUNET_SCHEDULER_add_now (&end_badly, 3215 GNUNET_SCHEDULER_add_now (&end_badly,
3230 "from connect topology (bad return)"); 3216 "from connect topology (bad return)");
3231 } 3217 }
3232 3218
3233 die_task 3219 die_task =
3234 =
3235 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 3220 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
3236 (GNUNET_TIME_UNIT_SECONDS, 3221 (GNUNET_TIME_UNIT_SECONDS,
3237 DEFAULT_CONNECT_TIMEOUT * 3222 DEFAULT_CONNECT_TIMEOUT *
@@ -3248,9 +3233,9 @@ create_topology ()
3248 unsigned int create_expected_connections; 3233 unsigned int create_expected_connections;
3249 3234
3250 peers_left = num_peers; /* Reset counter */ 3235 peers_left = num_peers; /* Reset counter */
3251 create_expected_connections 3236 create_expected_connections =
3252 = GNUNET_TESTING_create_topology (pg, topology, blacklist_topology, 3237 GNUNET_TESTING_create_topology (pg, topology, blacklist_topology,
3253 blacklist_transports); 3238 blacklist_transports);
3254 if (create_expected_connections > 0) 3239 if (create_expected_connections > 0)
3255 { 3240 {
3256 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3241 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -3262,13 +3247,13 @@ create_topology ()
3262 else 3247 else
3263 { 3248 {
3264 GNUNET_SCHEDULER_cancel (die_task); 3249 GNUNET_SCHEDULER_cancel (die_task);
3265 die_task = GNUNET_SCHEDULER_add_now (&end_badly, 3250 die_task =
3266 "from create topology (bad return)"); 3251 GNUNET_SCHEDULER_add_now (&end_badly,
3252 "from create topology (bad return)");
3267 } 3253 }
3268 GNUNET_free_non_null (blacklist_transports); 3254 GNUNET_free_non_null (blacklist_transports);
3269 GNUNET_SCHEDULER_cancel (die_task); 3255 GNUNET_SCHEDULER_cancel (die_task);
3270 die_task 3256 die_task =
3271 =
3272 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 3257 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
3273 (seconds_per_peer_start, num_peers), 3258 (seconds_per_peer_start, num_peers),
3274 &end_badly, 3259 &end_badly,
@@ -3297,8 +3282,8 @@ hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id,
3297 3282
3298#if VERBOSE > 1 3283#if VERBOSE > 1
3299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3284 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3300 "Hostkey (%d/%d) created for peer `%s'\n", 3285 "Hostkey (%d/%d) created for peer `%s'\n", num_peers - peers_left,
3301 num_peers - peers_left, num_peers, GNUNET_i2s (id)); 3286 num_peers, GNUNET_i2s (id));
3302#endif 3287#endif
3303 3288
3304 peers_left--; 3289 peers_left--;
@@ -3310,22 +3295,18 @@ hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id,
3310 GNUNET_asprintf (&revision_str, "%llu", revision); 3295 GNUNET_asprintf (&revision_str, "%llu", revision);
3311 if (GNUNET_YES == insert_gauger_data) 3296 if (GNUNET_YES == insert_gauger_data)
3312 { 3297 {
3313 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (config, "TESTING", 3298 if (GNUNET_YES ==
3314 "HOSTKEYSFILE")) 3299 GNUNET_CONFIGURATION_have_value (config, "TESTING", "HOSTKEYSFILE"))
3315 { 3300 {
3316 GAUGER_ID ("DHT_TESTING", 3301 GAUGER_ID ("DHT_TESTING", "HOSTKEY_GENERATION",
3317 "HOSTKEY_GENERATION", 3302 GNUNET_TIME_absolute_get_duration (hostkey_start_time).
3318 GNUNET_TIME_absolute_get_duration 3303 rel_value / (double) num_peers, "ms/hostkey", revision_str);
3319 (hostkey_start_time).rel_value / (double) num_peers,
3320 "ms/hostkey", revision_str);
3321 } 3304 }
3322 else 3305 else
3323 { 3306 {
3324 GAUGER_ID ("DHT_TESTING", 3307 GAUGER_ID ("DHT_TESTING", "HOSTKEY_GENERATION_REAL",
3325 "HOSTKEY_GENERATION_REAL", 3308 GNUNET_TIME_absolute_get_duration (hostkey_start_time).
3326 GNUNET_TIME_absolute_get_duration 3309 rel_value / (double) num_peers, "ms/hostkey", revision_str);
3327 (hostkey_start_time).rel_value / (double) num_peers,
3328 "ms/hostkey", revision_str);
3329 } 3310 }
3330 } 3311 }
3331 3312
@@ -3334,9 +3315,9 @@ hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id,
3334 GNUNET_SCHEDULER_cancel (die_task); 3315 GNUNET_SCHEDULER_cancel (die_task);
3335 /* Set up task in case topology creation doesn't finish 3316 /* Set up task in case topology creation doesn't finish
3336 * within a reasonable amount of time */ 3317 * within a reasonable amount of time */
3337 die_task = GNUNET_SCHEDULER_add_delayed (DEFAULT_TOPOLOGY_TIMEOUT, 3318 die_task =
3338 &end_badly, 3319 GNUNET_SCHEDULER_add_delayed (DEFAULT_TOPOLOGY_TIMEOUT, &end_badly,
3339 "from create_topology"); 3320 "from create_topology");
3340 GNUNET_SCHEDULER_add_now (&create_topology, NULL); 3321 GNUNET_SCHEDULER_add_now (&create_topology, NULL);
3341 ok = 0; 3322 ok = 0;
3342 } 3323 }
@@ -3379,18 +3360,18 @@ run (void *cls, char *const *args, const char *cfgfile,
3379 rounds_finished = 0; 3360 rounds_finished = 0;
3380 memset (&trial_info, 0, sizeof (struct GNUNET_DHTLOG_TrialInfo)); 3361 memset (&trial_info, 0, sizeof (struct GNUNET_DHTLOG_TrialInfo));
3381 /* Get path from configuration file */ 3362 /* Get path from configuration file */
3382 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "paths", 3363 if (GNUNET_YES !=
3383 "servicehome", 3364 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
3384 &test_directory)) 3365 &test_directory))
3385 { 3366 {
3386 ok = 404; 3367 ok = 404;
3387 return; 3368 return;
3388 } 3369 }
3389 3370
3390 /* Get number of peers to start from configuration */ 3371 /* Get number of peers to start from configuration */
3391 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, "testing", 3372 if (GNUNET_SYSERR ==
3392 "num_peers", 3373 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
3393 &num_peers)) 3374 &num_peers))
3394 { 3375 {
3395 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3376 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3396 "Number of peers must be specified in section %s option %s\n", 3377 "Number of peers must be specified in section %s option %s\n",
@@ -3398,11 +3379,12 @@ run (void *cls, char *const *args, const char *cfgfile,
3398 } 3379 }
3399 GNUNET_assert (num_peers > 0 && num_peers < ULONG_MAX); 3380 GNUNET_assert (num_peers > 0 && num_peers < ULONG_MAX);
3400 3381
3401 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "testing", 3382 if (GNUNET_OK ==
3402 "connect_timeout", 3383 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_timeout",
3403 &temp_config_number)) 3384 &temp_config_number))
3404 connect_timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3385 connect_timeout =
3405 temp_config_number); 3386 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
3387 temp_config_number);
3406 else 3388 else
3407 { 3389 {
3408 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", 3390 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
@@ -3410,28 +3392,29 @@ run (void *cls, char *const *args, const char *cfgfile,
3410 return; 3392 return;
3411 } 3393 }
3412 3394
3413 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "testing", 3395 if (GNUNET_OK !=
3414 "connect_attempts", 3396 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_attempts",
3415 &connect_attempts)) 3397 &connect_attempts))
3416 { 3398 {
3417 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", 3399 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
3418 "testing", "connect_attempts"); 3400 "testing", "connect_attempts");
3419 return; 3401 return;
3420 } 3402 }
3421 3403
3422 if (GNUNET_OK 3404 if (GNUNET_OK !=
3423 != GNUNET_CONFIGURATION_get_value_number (cfg, "testing", 3405 GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
3424 "max_outstanding_connections", 3406 "max_outstanding_connections",
3425 &max_outstanding_connections)) 3407 &max_outstanding_connections))
3426 { 3408 {
3427 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", 3409 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
3428 "testing", "max_outstanding_connections"); 3410 "testing", "max_outstanding_connections");
3429 return; 3411 return;
3430 } 3412 }
3431 3413
3432 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "testing", 3414 if (GNUNET_OK !=
3433 "max_concurrent_ssh", 3415 GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
3434 &max_concurrent_ssh)) 3416 "max_concurrent_ssh",
3417 &max_concurrent_ssh))
3435 { 3418 {
3436 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", 3419 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
3437 "testing", "max_concurrent_ssh"); 3420 "testing", "max_concurrent_ssh");
@@ -3441,18 +3424,19 @@ run (void *cls, char *const *args, const char *cfgfile,
3441 /** 3424 /**
3442 * Get DHT specific testing options. 3425 * Get DHT specific testing options.
3443 */ 3426 */
3444 if ((GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht_testing", 3427 if ((GNUNET_YES ==
3445 "mysql_logging")) 3428 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht_testing",
3446 || (GNUNET_YES 3429 "mysql_logging")) ||
3447 == GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht_testing", 3430 (GNUNET_YES ==
3448 "mysql_logging_extended")) 3431 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht_testing",
3449 || (GNUNET_YES 3432 "mysql_logging_extended")) ||
3450 == GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht_testing", 3433 (GNUNET_YES ==
3451 "mysql_logging_minimal"))) 3434 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht_testing",
3435 "mysql_logging_minimal")))
3452 { 3436 {
3453 if (GNUNET_YES 3437 if (GNUNET_YES ==
3454 == GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht_testing", 3438 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht_testing",
3455 "mysql_logging_minimal")) 3439 "mysql_logging_minimal"))
3456 dhtlog_minimal = GNUNET_YES; 3440 dhtlog_minimal = GNUNET_YES;
3457 3441
3458 dhtlog_handle = GNUNET_DHTLOG_connect (cfg); 3442 dhtlog_handle = GNUNET_DHTLOG_connect (cfg);
@@ -3465,8 +3449,8 @@ run (void *cls, char *const *args, const char *cfgfile,
3465 } 3449 }
3466 } 3450 }
3467 3451
3468 stop_closest = GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", 3452 stop_closest =
3469 "stop_on_closest"); 3453 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "stop_on_closest");
3470 if (stop_closest == GNUNET_SYSERR) 3454 if (stop_closest == GNUNET_SYSERR)
3471 stop_closest = GNUNET_NO; 3455 stop_closest = GNUNET_NO;
3472 3456
@@ -3474,21 +3458,21 @@ run (void *cls, char *const *args, const char *cfgfile,
3474 if (stop_found == GNUNET_SYSERR) 3458 if (stop_found == GNUNET_SYSERR)
3475 stop_found = GNUNET_NO; 3459 stop_found = GNUNET_NO;
3476 3460
3477 strict_kademlia = GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", 3461 strict_kademlia =
3478 "strict_kademlia"); 3462 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "strict_kademlia");
3479 if (strict_kademlia == GNUNET_SYSERR) 3463 if (strict_kademlia == GNUNET_SYSERR)
3480 strict_kademlia = GNUNET_NO; 3464 strict_kademlia = GNUNET_NO;
3481 3465
3482 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "dht_testing", 3466 if (GNUNET_OK !=
3483 "comment", 3467 GNUNET_CONFIGURATION_get_value_string (cfg, "dht_testing", "comment",
3484 &trialmessage)) 3468 &trialmessage))
3485 trialmessage = NULL; 3469 trialmessage = NULL;
3486 3470
3487 churn_data = NULL; 3471 churn_data = NULL;
3488 /** Check for a churn file to do churny simulation */ 3472 /** Check for a churn file to do churny simulation */
3489 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, "dht_testing", 3473 if (GNUNET_OK ==
3490 "churn_file", 3474 GNUNET_CONFIGURATION_get_value_string (cfg, "dht_testing", "churn_file",
3491 &churn_filename)) 3475 &churn_filename))
3492 { 3476 {
3493 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Reading churn data from %s\n", 3477 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Reading churn data from %s\n",
3494 churn_filename); 3478 churn_filename);
@@ -3511,8 +3495,8 @@ run (void *cls, char *const *args, const char *cfgfile,
3511 3495
3512 churn_data = GNUNET_malloc_large (frstat.st_size); 3496 churn_data = GNUNET_malloc_large (frstat.st_size);
3513 GNUNET_assert (churn_data != NULL); 3497 GNUNET_assert (churn_data != NULL);
3514 if (frstat.st_size != GNUNET_DISK_fn_read (churn_filename, churn_data, 3498 if (frstat.st_size !=
3515 frstat.st_size)) 3499 GNUNET_DISK_fn_read (churn_filename, churn_data, frstat.st_size))
3516 { 3500 {
3517 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 3501 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3518 "Could not read file %s specified for churn, ending test!", 3502 "Could not read file %s specified for churn, ending test!",
@@ -3551,10 +3535,10 @@ run (void *cls, char *const *args, const char *cfgfile,
3551 } 3535 }
3552 } 3536 }
3553 3537
3554 if (GNUNET_OK 3538 if (GNUNET_OK !=
3555 != GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", 3539 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing",
3556 "churns_per_round", 3540 "churns_per_round",
3557 &churns_per_round)) 3541 &churns_per_round))
3558 { 3542 {
3559 churns_per_round = (unsigned long long) churn_rounds; 3543 churns_per_round = (unsigned long long) churn_rounds;
3560 } 3544 }
@@ -3570,8 +3554,7 @@ run (void *cls, char *const *args, const char *cfgfile,
3570 ret = sscanf (buf, "%u", &churn_array[line_number]); 3554 ret = sscanf (buf, "%u", &churn_array[line_number]);
3571 if (1 == ret) 3555 if (1 == ret)
3572 { 3556 {
3573 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3557 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Read %u peers in round %u\n",
3574 "Read %u peers in round %u\n",
3575 churn_array[line_number], line_number); 3558 churn_array[line_number], line_number);
3576 line_number++; 3559 line_number++;
3577 } 3560 }
@@ -3591,9 +3574,9 @@ run (void *cls, char *const *args, const char *cfgfile,
3591 GNUNET_free_non_null (churn_data); 3574 GNUNET_free_non_null (churn_data);
3592 3575
3593 /* Check for a hostfile containing user@host:port triples */ 3576 /* Check for a hostfile containing user@host:port triples */
3594 if (GNUNET_OK 3577 if (GNUNET_OK !=
3595 != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "hostfile", 3578 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "hostfile",
3596 &hostfile)) 3579 &hostfile))
3597 hostfile = NULL; 3580 hostfile = NULL;
3598 3581
3599 hosts = NULL; 3582 hosts = NULL;
@@ -3602,8 +3585,9 @@ run (void *cls, char *const *args, const char *cfgfile,
3602 if (hostfile != NULL) 3585 if (hostfile != NULL)
3603 { 3586 {
3604 if (GNUNET_OK != GNUNET_DISK_file_test (hostfile)) 3587 if (GNUNET_OK != GNUNET_DISK_file_test (hostfile))
3605 GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ 3588 GNUNET_DISK_fn_write (hostfile, NULL, 0,
3606 | GNUNET_DISK_PERM_USER_WRITE); 3589 GNUNET_DISK_PERM_USER_READ |
3590 GNUNET_DISK_PERM_USER_WRITE);
3607 if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0)) 3591 if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0))
3608 { 3592 {
3609 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 3593 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -3638,9 +3622,9 @@ run (void *cls, char *const *args, const char *cfgfile,
3638 { 3622 {
3639 data[count] = '\0'; 3623 data[count] = '\0';
3640 temphost = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Host)); 3624 temphost = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Host));
3641 ret = sscanf (buf, "%a[a-zA-Z0-9_]@%a[a-zA-Z0-9.]:%hd", 3625 ret =
3642 &temphost->username, &temphost->hostname, 3626 sscanf (buf, "%a[a-zA-Z0-9_]@%a[a-zA-Z0-9.]:%hd",
3643 &temphost->port); 3627 &temphost->username, &temphost->hostname, &temphost->port);
3644 if (3 == ret) 3628 if (3 == ret)
3645 { 3629 {
3646 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -3664,124 +3648,134 @@ run (void *cls, char *const *args, const char *cfgfile,
3664 } 3648 }
3665 } 3649 }
3666 GNUNET_free_non_null (data); 3650 GNUNET_free_non_null (data);
3667 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", 3651 if (GNUNET_OK !=
3668 "malicious_getters", 3652 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing",
3669 &malicious_getters)) 3653 "malicious_getters",
3654 &malicious_getters))
3670 malicious_getters = 0; 3655 malicious_getters = 0;
3671 3656
3672 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", 3657 if (GNUNET_OK !=
3673 "malicious_putters", 3658 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing",
3674 &malicious_putters)) 3659 "malicious_putters",
3660 &malicious_putters))
3675 malicious_putters = 0; 3661 malicious_putters = 0;
3676 3662
3677 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", 3663 if (GNUNET_OK !=
3678 "malicious_droppers", 3664 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing",
3679 &malicious_droppers)) 3665 "malicious_droppers",
3666 &malicious_droppers))
3680 malicious_droppers = 0; 3667 malicious_droppers = 0;
3681 3668
3682 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", 3669 if (GNUNET_OK !=
3683 "settle_time", 3670 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "settle_time",
3684 &settle_time)) 3671 &settle_time))
3685 settle_time = 0; 3672 settle_time = 0;
3686 3673
3687 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, 3674 if (GNUNET_SYSERR ==
3688 "dht_testing", 3675 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "num_puts",
3689 "num_puts", 3676 &num_puts))
3690 &num_puts))
3691 num_puts = num_peers; 3677 num_puts = num_peers;
3692 3678
3693 if (GNUNET_SYSERR 3679 if (GNUNET_SYSERR ==
3694 == GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", 3680 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing",
3695 "put_replication", 3681 "put_replication",
3696 &put_replication)) 3682 &put_replication))
3697 put_replication = DEFAULT_PUT_REPLICATION; 3683 put_replication = DEFAULT_PUT_REPLICATION;
3698 3684
3699 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, 3685 if (GNUNET_SYSERR ==
3700 "dht_testing", 3686 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "num_gets",
3701 "num_gets", 3687 &num_gets))
3702 &num_gets))
3703 num_gets = num_peers; 3688 num_gets = num_peers;
3704 3689
3705 if (GNUNET_SYSERR 3690 if (GNUNET_SYSERR ==
3706 == GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", 3691 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing",
3707 "get_replication", 3692 "get_replication",
3708 &get_replication)) 3693 &get_replication))
3709 get_replication = DEFAULT_GET_REPLICATION; 3694 get_replication = DEFAULT_GET_REPLICATION;
3710 3695
3711 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", 3696 if (GNUNET_OK ==
3712 "find_peer_delay", 3697 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing",
3713 &temp_config_number)) 3698 "find_peer_delay",
3714 find_peer_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3699 &temp_config_number))
3715 temp_config_number); 3700 find_peer_delay =
3701 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
3702 temp_config_number);
3716 else 3703 else
3717 find_peer_delay = DEFAULT_FIND_PEER_DELAY; 3704 find_peer_delay = DEFAULT_FIND_PEER_DELAY;
3718 3705
3719 if (GNUNET_OK 3706 if (GNUNET_OK ==
3720 == GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", 3707 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing",
3721 "concurrent_find_peers", 3708 "concurrent_find_peers",
3722 &temp_config_number)) 3709 &temp_config_number))
3723 max_outstanding_find_peers = temp_config_number; 3710 max_outstanding_find_peers = temp_config_number;
3724 else 3711 else
3725 max_outstanding_find_peers = DEFAULT_MAX_OUTSTANDING_FIND_PEERS; 3712 max_outstanding_find_peers = DEFAULT_MAX_OUTSTANDING_FIND_PEERS;
3726 3713
3727 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", 3714 if (GNUNET_OK ==
3728 "get_timeout", 3715 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "get_timeout",
3729 &temp_config_number)) 3716 &temp_config_number))
3730 get_timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3717 get_timeout =
3731 temp_config_number); 3718 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
3719 temp_config_number);
3732 else 3720 else
3733 get_timeout = DEFAULT_GET_TIMEOUT; 3721 get_timeout = DEFAULT_GET_TIMEOUT;
3734 3722
3735 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", 3723 if (GNUNET_OK ==
3736 "concurrent_puts", 3724 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing",
3737 &temp_config_number)) 3725 "concurrent_puts",
3726 &temp_config_number))
3738 max_outstanding_puts = temp_config_number; 3727 max_outstanding_puts = temp_config_number;
3739 else 3728 else
3740 max_outstanding_puts = DEFAULT_MAX_OUTSTANDING_PUTS; 3729 max_outstanding_puts = DEFAULT_MAX_OUTSTANDING_PUTS;
3741 3730
3742 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", 3731 if (GNUNET_OK ==
3743 "concurrent_gets", 3732 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing",
3744 &temp_config_number)) 3733 "concurrent_gets",
3734 &temp_config_number))
3745 max_outstanding_gets = temp_config_number; 3735 max_outstanding_gets = temp_config_number;
3746 else 3736 else
3747 max_outstanding_gets = DEFAULT_MAX_OUTSTANDING_GETS; 3737 max_outstanding_gets = DEFAULT_MAX_OUTSTANDING_GETS;
3748 3738
3749 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", 3739 if (GNUNET_OK ==
3750 "timeout", 3740 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "timeout",
3751 &temp_config_number)) 3741 &temp_config_number))
3752 all_get_timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3742 all_get_timeout =
3753 temp_config_number); 3743 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
3744 temp_config_number);
3754 else 3745 else
3755 all_get_timeout.rel_value = get_timeout.rel_value * num_gets; 3746 all_get_timeout.rel_value = get_timeout.rel_value * num_gets;
3756 3747
3757 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", 3748 if (GNUNET_OK ==
3758 "get_delay", 3749 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "get_delay",
3759 &temp_config_number)) 3750 &temp_config_number))
3760 get_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3751 get_delay =
3761 temp_config_number); 3752 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
3753 temp_config_number);
3762 else 3754 else
3763 get_delay = DEFAULT_GET_DELAY; 3755 get_delay = DEFAULT_GET_DELAY;
3764 3756
3765 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", 3757 if (GNUNET_OK ==
3766 "put_delay", 3758 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "put_delay",
3767 &temp_config_number)) 3759 &temp_config_number))
3768 put_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3760 put_delay =
3769 temp_config_number); 3761 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
3762 temp_config_number);
3770 else 3763 else
3771 put_delay = DEFAULT_PUT_DELAY; 3764 put_delay = DEFAULT_PUT_DELAY;
3772 3765
3773 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", 3766 if (GNUNET_OK ==
3774 "peer_start_timeout", 3767 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing",
3775 &temp_config_number)) 3768 "peer_start_timeout",
3776 seconds_per_peer_start 3769 &temp_config_number))
3777 = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3770 seconds_per_peer_start =
3778 temp_config_number); 3771 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
3772 temp_config_number);
3779 else 3773 else
3780 seconds_per_peer_start = DEFAULT_SECONDS_PER_PEER_START; 3774 seconds_per_peer_start = DEFAULT_SECONDS_PER_PEER_START;
3781 3775
3782 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", 3776 if (GNUNET_OK ==
3783 "data_size", 3777 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "data_size",
3784 &temp_config_number)) 3778 &temp_config_number))
3785 test_data_size = temp_config_number; 3779 test_data_size = temp_config_number;
3786 else 3780 else
3787 test_data_size = DEFAULT_TEST_DATA_SIZE; 3781 test_data_size = DEFAULT_TEST_DATA_SIZE;
@@ -3789,39 +3783,42 @@ run (void *cls, char *const *args, const char *cfgfile,
3789 /** 3783 /**
3790 * Get DHT testing related options. 3784 * Get DHT testing related options.
3791 */ 3785 */
3792 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg, "DHT_TESTING", 3786 if (GNUNET_YES ==
3793 "REPLICATE_SAME")) 3787 GNUNET_CONFIGURATION_get_value_yesno (cfg, "DHT_TESTING",
3788 "REPLICATE_SAME"))
3794 replicate_same = GNUNET_YES; 3789 replicate_same = GNUNET_YES;
3795 3790
3796 if (GNUNET_SYSERR 3791 if (GNUNET_SYSERR ==
3797 == GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", 3792 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing",
3798 "target_completions", 3793 "target_completions",
3799 &target_completions)) 3794 &target_completions))
3800 target_completions = 0; /* Not required, on stack */ 3795 target_completions = 0; /* Not required, on stack */
3801 3796
3802 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg, "DHT_TESTING", 3797 if (GNUNET_YES ==
3803 "GET_FROM_SAME")) 3798 GNUNET_CONFIGURATION_get_value_yesno (cfg, "DHT_TESTING",
3799 "GET_FROM_SAME"))
3804 get_from_same = GNUNET_YES; 3800 get_from_same = GNUNET_YES;
3805 3801
3806 if (GNUNET_NO 3802 if (GNUNET_NO ==
3807 == GNUNET_CONFIGURATION_get_value_time (cfg, "DHT_TESTING", 3803 GNUNET_CONFIGURATION_get_value_time (cfg, "DHT_TESTING",
3808 "MALICIOUS_GET_FREQUENCY", 3804 "MALICIOUS_GET_FREQUENCY",
3809 &malicious_get_frequency)) 3805 &malicious_get_frequency))
3810 malicious_get_frequency = DEFAULT_MALICIOUS_GET_FREQUENCY; 3806 malicious_get_frequency = DEFAULT_MALICIOUS_GET_FREQUENCY;
3811 3807
3812 if (GNUNET_NO 3808 if (GNUNET_NO ==
3813 == GNUNET_CONFIGURATION_get_value_time (cfg, "DHT_TESTING", 3809 GNUNET_CONFIGURATION_get_value_time (cfg, "DHT_TESTING",
3814 "MALICIOUS_PUT_FREQUENCY", 3810 "MALICIOUS_PUT_FREQUENCY",
3815 &malicious_put_frequency)) 3811 &malicious_put_frequency))
3816 malicious_put_frequency = DEFAULT_MALICIOUS_PUT_FREQUENCY; 3812 malicious_put_frequency = DEFAULT_MALICIOUS_PUT_FREQUENCY;
3817 3813
3818 if (GNUNET_YES 3814 if (GNUNET_YES ==
3819 == GNUNET_CONFIGURATION_get_value_yesno (cfg, "DHT_TESTING", 3815 GNUNET_CONFIGURATION_get_value_yesno (cfg, "DHT_TESTING",
3820 "MALICIOUS_AFTER_SETTLE")) 3816 "MALICIOUS_AFTER_SETTLE"))
3821 malicious_after_settle = GNUNET_YES; 3817 malicious_after_settle = GNUNET_YES;
3822 3818
3823 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg, "DHT_TESTING", 3819 if (GNUNET_YES ==
3824 "MALICIOUS_SYBIL")) 3820 GNUNET_CONFIGURATION_get_value_yesno (cfg, "DHT_TESTING",
3821 "MALICIOUS_SYBIL"))
3825 { 3822 {
3826 /* Set up the malicious target at random for this round */ 3823 /* Set up the malicious target at random for this round */
3827 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, 3824 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
@@ -3836,81 +3833,83 @@ run (void *cls, char *const *args, const char *cfgfile,
3836 while (1 << k < malicious_droppers) 3833 while (1 << k < malicious_droppers)
3837 k++; 3834 k++;
3838 if (malicious_droppers > 0) 3835 if (malicious_droppers > 0)
3839 malicious_bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, 1 << k, 3836 malicious_bloom =
3840 DHT_BLOOM_K); 3837 GNUNET_CONTAINER_bloomfilter_init (NULL, 1 << k, DHT_BLOOM_K);
3841 3838
3842 /* The normal behavior of the DHT is to do find peer requests 3839 /* The normal behavior of the DHT is to do find peer requests
3843 * on its own. Only if this is explicitly turned off should 3840 * on its own. Only if this is explicitly turned off should
3844 * the testing driver issue find peer requests (even though 3841 * the testing driver issue find peer requests (even though
3845 * this is likely the default when testing). 3842 * this is likely the default when testing).
3846 */ 3843 */
3847 if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", 3844 if (GNUNET_NO ==
3848 "do_find_peer")) 3845 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "do_find_peer"))
3849 do_find_peer = GNUNET_YES; 3846 do_find_peer = GNUNET_YES;
3850 3847
3851 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht_testing", 3848 if (GNUNET_YES ==
3852 "insert_gauger_data")) 3849 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht_testing",
3850 "insert_gauger_data"))
3853 insert_gauger_data = GNUNET_YES; 3851 insert_gauger_data = GNUNET_YES;
3854 3852
3855 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", 3853 if (GNUNET_YES ==
3856 "republish")) 3854 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "republish"))
3857 in_dht_replication = GNUNET_YES; 3855 in_dht_replication = GNUNET_YES;
3858 3856
3859 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_number (cfg, "DHT_TESTING", 3857 if (GNUNET_YES !=
3860 "TRIAL_TO_RUN", 3858 GNUNET_CONFIGURATION_get_value_number (cfg, "DHT_TESTING", "TRIAL_TO_RUN",
3861 &trial_to_run)) 3859 &trial_to_run))
3862 trial_to_run = 0; 3860 trial_to_run = 0;
3863 3861
3864 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_number (cfg, "DHT_TESTING", 3862 if (GNUNET_YES !=
3865 "REVISION", 3863 GNUNET_CONFIGURATION_get_value_number (cfg, "DHT_TESTING", "REVISION",
3866 &revision)) 3864 &revision))
3867 revision = 0; 3865 revision = 0;
3868 3866
3869 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT_TESTING", 3867 if (GNUNET_YES ==
3870 "FIND_PEER_DELAY", 3868 GNUNET_CONFIGURATION_get_value_number (cfg, "DHT_TESTING",
3871 &temp_config_number)) 3869 "FIND_PEER_DELAY",
3872 find_peer_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3870 &temp_config_number))
3873 temp_config_number); 3871 find_peer_delay =
3872 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
3873 temp_config_number);
3874 else 3874 else
3875 find_peer_delay = DEFAULT_FIND_PEER_DELAY; 3875 find_peer_delay = DEFAULT_FIND_PEER_DELAY;
3876 3876
3877 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_number (cfg, "DHT_TESTING", 3877 if (GNUNET_YES !=
3878 "ROUND_DELAY", 3878 GNUNET_CONFIGURATION_get_value_number (cfg, "DHT_TESTING", "ROUND_DELAY",
3879 &round_delay)) 3879 &round_delay))
3880 round_delay = 0; 3880 round_delay = 0;
3881 3881
3882 if (GNUNET_NO 3882 if (GNUNET_NO ==
3883 == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT_TESTING", 3883 GNUNET_CONFIGURATION_get_value_number (cfg, "DHT_TESTING",
3884 "OUTSTANDING_FIND_PEERS", 3884 "OUTSTANDING_FIND_PEERS",
3885 &max_outstanding_find_peers)) 3885 &max_outstanding_find_peers))
3886 max_outstanding_find_peers = DEFAULT_MAX_OUTSTANDING_FIND_PEERS; 3886 max_outstanding_find_peers = DEFAULT_MAX_OUTSTANDING_FIND_PEERS;
3887 3887
3888 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", 3888 if (GNUNET_YES ==
3889 "strict_kademlia")) 3889 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "strict_kademlia"))
3890 max_outstanding_find_peers = max_outstanding_find_peers * 1; 3890 max_outstanding_find_peers = max_outstanding_find_peers * 1;
3891 3891
3892 find_peer_offset = GNUNET_TIME_relative_divide (find_peer_delay, 3892 find_peer_offset =
3893 max_outstanding_find_peers); 3893 GNUNET_TIME_relative_divide (find_peer_delay, max_outstanding_find_peers);
3894 3894
3895 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, 3895 if (GNUNET_SYSERR ==
3896 "dht_testing", 3896 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "num_rounds",
3897 "num_rounds", 3897 &total_rounds))
3898 &total_rounds))
3899 total_rounds = 1; 3898 total_rounds = 1;
3900 3899
3901 if ((GNUNET_SYSERR 3900 if ((GNUNET_SYSERR ==
3902 == GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", 3901 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing",
3903 "target_total_connections", 3902 "target_total_connections",
3904 &target_total_connections)) 3903 &target_total_connections)) ||
3905 || (target_total_connections == 0)) 3904 (target_total_connections == 0))
3906 target_total_connections = connection_estimate (num_peers, 3905 target_total_connections =
3907 DEFAULT_BUCKET_SIZE); 3906 connection_estimate (num_peers, DEFAULT_BUCKET_SIZE);
3908 3907
3909 topology_str = NULL; 3908 topology_str = NULL;
3910 if ((GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg, "testing", 3909 if ((GNUNET_YES ==
3911 "topology", 3910 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology",
3912 &topology_str)) 3911 &topology_str)) &&
3913 && (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str))) 3912 (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str)))
3914 { 3913 {
3915 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3914 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3916 "Invalid topology `%s' given for section %s option %s\n", 3915 "Invalid topology `%s' given for section %s option %s\n",
@@ -3918,9 +3917,9 @@ run (void *cls, char *const *args, const char *cfgfile,
3918 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */ 3917 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
3919 } 3918 }
3920 3919
3921 if (GNUNET_OK 3920 if (GNUNET_OK !=
3922 != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "percentage", 3921 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "percentage",
3923 &topology_percentage_str)) 3922 &topology_percentage_str))
3924 topology_percentage = 0.5; 3923 topology_percentage = 0.5;
3925 else 3924 else
3926 { 3925 {
@@ -3928,9 +3927,9 @@ run (void *cls, char *const *args, const char *cfgfile,
3928 GNUNET_free (topology_percentage_str); 3927 GNUNET_free (topology_percentage_str);
3929 } 3928 }
3930 3929
3931 if (GNUNET_OK 3930 if (GNUNET_OK !=
3932 != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "probability", 3931 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "probability",
3933 &topology_probability_str)) 3932 &topology_probability_str))
3934 topology_probability = 0.5; 3933 topology_probability = 0.5;
3935 else 3934 else
3936 { 3935 {
@@ -3938,12 +3937,12 @@ run (void *cls, char *const *args, const char *cfgfile,
3938 GNUNET_free (topology_probability_str); 3937 GNUNET_free (topology_probability_str);
3939 } 3938 }
3940 3939
3941 if ((GNUNET_YES 3940 if ((GNUNET_YES ==
3942 == GNUNET_CONFIGURATION_get_value_string (cfg, "testing", 3941 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
3943 "connect_topology", 3942 "connect_topology",
3944 &connect_topology_str)) 3943 &connect_topology_str)) &&
3945 && (GNUNET_NO == GNUNET_TESTING_topology_get (&connect_topology, 3944 (GNUNET_NO ==
3946 connect_topology_str))) 3945 GNUNET_TESTING_topology_get (&connect_topology, connect_topology_str)))
3947 { 3946 {
3948 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3947 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3949 "Invalid connect topology `%s' given for section %s option %s\n", 3948 "Invalid connect topology `%s' given for section %s option %s\n",
@@ -3951,13 +3950,13 @@ run (void *cls, char *const *args, const char *cfgfile,
3951 } 3950 }
3952 GNUNET_free_non_null (connect_topology_str); 3951 GNUNET_free_non_null (connect_topology_str);
3953 3952
3954 if ((GNUNET_YES 3953 if ((GNUNET_YES ==
3955 == GNUNET_CONFIGURATION_get_value_string (cfg, "testing", 3954 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
3956 "connect_topology_option", 3955 "connect_topology_option",
3957 &connect_topology_option_str)) 3956 &connect_topology_option_str)) &&
3958 && (GNUNET_NO 3957 (GNUNET_NO ==
3959 == GNUNET_TESTING_topology_option_get (&connect_topology_option, 3958 GNUNET_TESTING_topology_option_get (&connect_topology_option,
3960 connect_topology_option_str))) 3959 connect_topology_option_str)))
3961 { 3960 {
3962 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3961 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3963 "Invalid connect topology option `%s' given for section %s option %s\n", 3962 "Invalid connect topology option `%s' given for section %s option %s\n",
@@ -3967,14 +3966,14 @@ run (void *cls, char *const *args, const char *cfgfile,
3967 } 3966 }
3968 GNUNET_free_non_null (connect_topology_option_str); 3967 GNUNET_free_non_null (connect_topology_option_str);
3969 3968
3970 if (GNUNET_YES 3969 if (GNUNET_YES ==
3971 == GNUNET_CONFIGURATION_get_value_string (cfg, 3970 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
3972 "testing", 3971 "connect_topology_option_modifier",
3973 "connect_topology_option_modifier", 3972 &connect_topology_option_modifier_string))
3974 &connect_topology_option_modifier_string))
3975 { 3973 {
3976 if (sscanf (connect_topology_option_modifier_string, "%lf", 3974 if (sscanf
3977 &connect_topology_option_modifier) != 1) 3975 (connect_topology_option_modifier_string, "%lf",
3976 &connect_topology_option_modifier) != 1)
3978 { 3977 {
3979 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3978 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3980 _ 3979 _
@@ -3985,18 +3984,19 @@ run (void *cls, char *const *args, const char *cfgfile,
3985 GNUNET_free (connect_topology_option_modifier_string); 3984 GNUNET_free (connect_topology_option_modifier_string);
3986 } 3985 }
3987 3986
3988 if (GNUNET_YES 3987 if (GNUNET_YES !=
3989 != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", 3988 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
3990 "blacklist_transports", 3989 "blacklist_transports",
3991 &blacklist_transports)) 3990 &blacklist_transports))
3992 blacklist_transports = NULL; 3991 blacklist_transports = NULL;
3993 3992
3994 if ((GNUNET_YES 3993 if ((GNUNET_YES ==
3995 == GNUNET_CONFIGURATION_get_value_string (cfg, "testing", 3994 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
3996 "blacklist_topology", 3995 "blacklist_topology",
3997 &blacklist_topology_str)) 3996 &blacklist_topology_str)) &&
3998 && (GNUNET_NO == GNUNET_TESTING_topology_get (&blacklist_topology, 3997 (GNUNET_NO ==
3999 blacklist_topology_str))) 3998 GNUNET_TESTING_topology_get (&blacklist_topology,
3999 blacklist_topology_str)))
4000 { 4000 {
4001 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 4001 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
4002 "Invalid topology `%s' given for section %s option %s\n", 4002 "Invalid topology `%s' given for section %s option %s\n",
@@ -4009,8 +4009,7 @@ run (void *cls, char *const *args, const char *cfgfile,
4009 peers_left = num_peers; 4009 peers_left = num_peers;
4010 4010
4011 /* Set up a task to end testing if peer start fails */ 4011 /* Set up a task to end testing if peer start fails */
4012 die_task 4012 die_task =
4013 =
4014 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 4013 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
4015 (seconds_per_peer_start, num_peers), 4014 (seconds_per_peer_start, num_peers),
4016 &end_badly, 4015 &end_badly,
@@ -4025,8 +4024,8 @@ run (void *cls, char *const *args, const char *cfgfile,
4025 trial_info.blacklist_topology = blacklist_topology; 4024 trial_info.blacklist_topology = blacklist_topology;
4026 trial_info.connect_topology = connect_topology; 4025 trial_info.connect_topology = connect_topology;
4027 trial_info.connect_topology_option = connect_topology_option; 4026 trial_info.connect_topology_option = connect_topology_option;
4028 trial_info.connect_topology_option_modifier 4027 trial_info.connect_topology_option_modifier =
4029 = connect_topology_option_modifier; 4028 connect_topology_option_modifier;
4030 trial_info.topology_percentage = topology_percentage; 4029 trial_info.topology_percentage = topology_percentage;
4031 trial_info.topology_probability = topology_probability; 4030 trial_info.topology_probability = topology_probability;
4032 trial_info.puts = num_puts; 4031 trial_info.puts = num_puts;
@@ -4059,8 +4058,7 @@ run (void *cls, char *const *args, const char *cfgfile,
4059 put_meter = create_meter (num_puts, "Puts completed ", GNUNET_YES); 4058 put_meter = create_meter (num_puts, "Puts completed ", GNUNET_YES);
4060 get_meter = create_meter (num_gets, "Gets completed ", GNUNET_YES); 4059 get_meter = create_meter (num_gets, "Gets completed ", GNUNET_YES);
4061 hostkey_start_time = GNUNET_TIME_absolute_get (); 4060 hostkey_start_time = GNUNET_TIME_absolute_get ();
4062 pg = GNUNET_TESTING_daemons_start (cfg, 4061 pg = GNUNET_TESTING_daemons_start (cfg, peers_left,
4063 peers_left,
4064 max_outstanding_connections, 4062 max_outstanding_connections,
4065 max_concurrent_ssh, 4063 max_concurrent_ssh,
4066 GNUNET_TIME_relative_multiply 4064 GNUNET_TIME_relative_multiply
@@ -4088,8 +4086,9 @@ main (int argc, char *argv[])
4088 GNUNET_GETOPT_OPTION_END 4086 GNUNET_GETOPT_OPTION_END
4089 }; 4087 };
4090 4088
4091 ret = GNUNET_PROGRAM_run (argc, argv, "gnunet-dht-driver", "nohelp", options, 4089 ret =
4092 &run, &ok); 4090 GNUNET_PROGRAM_run (argc, argv, "gnunet-dht-driver", "nohelp", options,
4091 &run, &ok);
4093 4092
4094 if (malicious_bloom != NULL) 4093 if (malicious_bloom != NULL)
4095 GNUNET_CONTAINER_bloomfilter_free (malicious_bloom); 4094 GNUNET_CONTAINER_bloomfilter_free (malicious_bloom);
diff --git a/src/dht/gnunet-dht-get-peer.c b/src/dht/gnunet-dht-get-peer.c
index 6ca88d232..2de7e93be 100644
--- a/src/dht/gnunet-dht-get-peer.c
+++ b/src/dht/gnunet-dht-get-peer.c
@@ -126,9 +126,8 @@ find_peer_processor (void *cls, const struct GNUNET_HELLO_Message *hello)
126 * @param c configuration 126 * @param c configuration
127 */ 127 */
128static void 128static void
129run (void *cls, 129run (void *cls, char *const *args, const char *cfgfile,
130 char *const *args, 130 const struct GNUNET_CONFIGURATION_Handle *c)
131 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
132{ 131{
133 struct GNUNET_TIME_Relative timeout; 132 struct GNUNET_TIME_Relative timeout;
134 GNUNET_HashCode key; 133 GNUNET_HashCode key;
@@ -164,11 +163,9 @@ run (void *cls,
164 if (verbose) 163 if (verbose)
165 fprintf (stderr, "Issuing FIND PEER request for %s!\n", query_key); 164 fprintf (stderr, "Issuing FIND PEER request for %s!\n", query_key);
166 165
167 find_peer_handle = GNUNET_DHT_find_peer_start (dht_handle, 166 find_peer_handle =
168 timeout, 167 GNUNET_DHT_find_peer_start (dht_handle, timeout, &key, GNUNET_DHT_RO_NONE,
169 &key, 168 &find_peer_processor, NULL);
170 GNUNET_DHT_RO_NONE,
171 &find_peer_processor, NULL);
172 if (NULL == find_peer_handle) 169 if (NULL == find_peer_handle)
173 { 170 {
174 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 171 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
@@ -207,9 +204,7 @@ int
207main (int argc, char *const *argv) 204main (int argc, char *const *argv)
208{ 205{
209 return (GNUNET_OK == 206 return (GNUNET_OK ==
210 GNUNET_PROGRAM_run (argc, 207 GNUNET_PROGRAM_run (argc, argv, "gnunet-dht-get-peer",
211 argv,
212 "gnunet-dht-get-peer",
213 gettext_noop 208 gettext_noop
214 ("Issue a GET PEER request to the GNUnet DHT, print results."), 209 ("Issue a GET PEER request to the GNUnet DHT, print results."),
215 options, &run, NULL)) ? ret : 1; 210 options, &run, NULL)) ? ret : 1;
diff --git a/src/dht/gnunet-dht-get.c b/src/dht/gnunet-dht-get.c
index b807a798f..161f0f41b 100644
--- a/src/dht/gnunet-dht-get.c
+++ b/src/dht/gnunet-dht-get.c
@@ -117,15 +117,14 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
117 * @param data pointer to the result data 117 * @param data pointer to the result data
118 */ 118 */
119void 119void
120get_result_iterator (void *cls, 120get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
121 struct GNUNET_TIME_Absolute exp,
122 const GNUNET_HashCode * key, 121 const GNUNET_HashCode * key,
123 const struct GNUNET_PeerIdentity *const *get_path, 122 const struct GNUNET_PeerIdentity *const *get_path,
124 const struct GNUNET_PeerIdentity *const *put_path, 123 const struct GNUNET_PeerIdentity *const *put_path,
125 enum GNUNET_BLOCK_Type type, size_t size, const void *data) 124 enum GNUNET_BLOCK_Type type, size_t size, const void *data)
126{ 125{
127 fprintf (stdout, "Result %d, type %d:\n%.*s\n", 126 fprintf (stdout, "Result %d, type %d:\n%.*s\n", result_count, type,
128 result_count, type, (unsigned int) size, (char *) data); 127 (unsigned int) size, (char *) data);
129 result_count++; 128 result_count++;
130} 129}
131 130
@@ -139,9 +138,8 @@ get_result_iterator (void *cls,
139 * @param c configuration 138 * @param c configuration
140 */ 139 */
141static void 140static void
142run (void *cls, 141run (void *cls, char *const *args, const char *cfgfile,
143 char *const *args, 142 const struct GNUNET_CONFIGURATION_Handle *c)
144 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
145{ 143{
146 struct GNUNET_TIME_Relative timeout; 144 struct GNUNET_TIME_Relative timeout;
147 GNUNET_HashCode key; 145 GNUNET_HashCode key;
@@ -181,14 +179,10 @@ run (void *cls,
181 fprintf (stderr, "Issuing GET request for %s!\n", query_key); 179 fprintf (stderr, "Issuing GET request for %s!\n", query_key);
182 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining 180 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
183 (absolute_timeout), &cleanup_task, NULL); 181 (absolute_timeout), &cleanup_task, NULL);
184 get_handle = GNUNET_DHT_get_start (dht_handle, 182 get_handle =
185 timeout, 183 GNUNET_DHT_get_start (dht_handle, timeout, query_type, &key,
186 query_type, 184 DEFAULT_GET_REPLICATION, GNUNET_DHT_RO_NONE, NULL,
187 &key, 185 0, NULL, 0, &get_result_iterator, NULL);
188 DEFAULT_GET_REPLICATION,
189 GNUNET_DHT_RO_NONE,
190 NULL, 0,
191 NULL, 0, &get_result_iterator, NULL);
192 186
193} 187}
194 188
@@ -224,9 +218,7 @@ int
224main (int argc, char *const *argv) 218main (int argc, char *const *argv)
225{ 219{
226 return (GNUNET_OK == 220 return (GNUNET_OK ==
227 GNUNET_PROGRAM_run (argc, 221 GNUNET_PROGRAM_run (argc, argv, "gnunet-dht-get",
228 argv,
229 "gnunet-dht-get",
230 gettext_noop 222 gettext_noop
231 ("Issue a GET request to the GNUnet DHT, prints results."), 223 ("Issue a GET request to the GNUnet DHT, prints results."),
232 options, &run, NULL)) ? ret : 1; 224 options, &run, NULL)) ? ret : 1;
diff --git a/src/dht/gnunet-dht-put.c b/src/dht/gnunet-dht-put.c
index b76b92c2b..4a752ea24 100644
--- a/src/dht/gnunet-dht-put.c
+++ b/src/dht/gnunet-dht-put.c
@@ -105,9 +105,8 @@ message_sent_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
105 * @param c configuration 105 * @param c configuration
106 */ 106 */
107static void 107static void
108run (void *cls, 108run (void *cls, char *const *args, const char *cfgfile,
109 char *const *args, 109 const struct GNUNET_CONFIGURATION_Handle *c)
110 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
111{ 110{
112 struct GNUNET_TIME_Relative timeout; 111 struct GNUNET_TIME_Relative timeout;
113 struct GNUNET_TIME_Absolute expiration; 112 struct GNUNET_TIME_Absolute expiration;
@@ -147,9 +146,9 @@ run (void *cls,
147 if (verbose) 146 if (verbose)
148 fprintf (stderr, _("Issuing put request for `%s' with data `%s'!\n"), 147 fprintf (stderr, _("Issuing put request for `%s' with data `%s'!\n"),
149 query_key, data); 148 query_key, data);
150 GNUNET_DHT_put (dht_handle, &key, DEFAULT_PUT_REPLICATION, 149 GNUNET_DHT_put (dht_handle, &key, DEFAULT_PUT_REPLICATION, GNUNET_DHT_RO_NONE,
151 GNUNET_DHT_RO_NONE, query_type, strlen (data), data, 150 query_type, strlen (data), data, expiration, timeout,
152 expiration, timeout, &message_sent_cont, NULL); 151 &message_sent_cont, NULL);
153 152
154} 153}
155 154
@@ -191,9 +190,7 @@ int
191main (int argc, char *const *argv) 190main (int argc, char *const *argv)
192{ 191{
193 return (GNUNET_OK == 192 return (GNUNET_OK ==
194 GNUNET_PROGRAM_run (argc, 193 GNUNET_PROGRAM_run (argc, argv, "gnunet-dht-put",
195 argv,
196 "gnunet-dht-put",
197 gettext_noop 194 gettext_noop
198 ("Issue a PUT request to the GNUnet DHT insert DATA under KEY."), 195 ("Issue a PUT request to the GNUnet DHT insert DATA under KEY."),
199 options, &run, NULL)) ? ret : 1; 196 options, &run, NULL)) ? ret : 1;
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c
index 19250d07b..1721e73af 100644
--- a/src/dht/gnunet-service-dht.c
+++ b/src/dht/gnunet-service-dht.c
@@ -984,9 +984,8 @@ get_average_send_delay ()
984 } 984 }
985 985
986 average_time = GNUNET_TIME_relative_divide (average_time, divisor); 986 average_time = GNUNET_TIME_relative_divide (average_time, divisor);
987 fprintf (stderr, 987 fprintf (stderr, "Avg send delay: %u sends is %llu\n", divisor,
988 "Avg send delay: %u sends is %llu\n", 988 (unsigned long long) average_time.abs_value);
989 divisor, (unsigned long long) average_time.abs_value);
990 return average_time; 989 return average_time;
991} 990}
992#endif 991#endif
@@ -1088,8 +1087,7 @@ try_core_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1088 if (reply_counter >= MAX_REPLY_TIMES) 1087 if (reply_counter >= MAX_REPLY_TIMES)
1089 reply_counter = 0; 1088 reply_counter = 0;
1090 peer->th = 1089 peer->th =
1091 GNUNET_CORE_notify_transmit_ready (coreAPI, 1090 GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES,
1092 GNUNET_YES,
1093 pending->importance, 1091 pending->importance,
1094 pending->timeout, &peer->id, ssize, 1092 pending->timeout, &peer->id, ssize,
1095 &core_transmit_notify, peer); 1093 &core_transmit_notify, peer);
@@ -1162,8 +1160,7 @@ forward_result_message (const struct GNUNET_MessageHeader *msg,
1162 result_message->hop_count = htonl (msg_ctx->hop_count + 1); 1160 result_message->hop_count = htonl (msg_ctx->hop_count + 1);
1163 GNUNET_assert (GNUNET_OK == 1161 GNUNET_assert (GNUNET_OK ==
1164 GNUNET_CONTAINER_bloomfilter_get_raw_data (msg_ctx->bloom, 1162 GNUNET_CONTAINER_bloomfilter_get_raw_data (msg_ctx->bloom,
1165 result_message-> 1163 result_message->bloomfilter,
1166 bloomfilter,
1167 DHT_BLOOM_SIZE)); 1164 DHT_BLOOM_SIZE));
1168 result_message->unique_id = GNUNET_htonll (msg_ctx->unique_id); 1165 result_message->unique_id = GNUNET_htonll (msg_ctx->unique_id);
1169 memcpy (&result_message->key, &msg_ctx->key, sizeof (GNUNET_HashCode)); 1166 memcpy (&result_message->key, &msg_ctx->key, sizeof (GNUNET_HashCode));
@@ -1177,8 +1174,8 @@ forward_result_message (const struct GNUNET_MessageHeader *msg,
1177 msg_ctx->path_history_len * (sizeof (struct GNUNET_PeerIdentity))); 1174 msg_ctx->path_history_len * (sizeof (struct GNUNET_PeerIdentity)));
1178#if DEBUG_DHT > 1 1175#if DEBUG_DHT > 1
1179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1180 "%s:%s Adding pending message size %d for peer %s\n", 1177 "%s:%s Adding pending message size %d for peer %s\n", my_short_id,
1181 my_short_id, "DHT", msize, GNUNET_i2s (&peer->id)); 1178 "DHT", msize, GNUNET_i2s (&peer->id));
1182#endif 1179#endif
1183 peer->pending_count++; 1180 peer->pending_count++;
1184 increment_stats ("# pending messages scheduled"); 1181 increment_stats ("# pending messages scheduled");
@@ -1477,9 +1474,9 @@ find_peer_by_id (const struct GNUNET_PeerIdentity *peer)
1477} 1474}
1478 1475
1479/* Forward declaration */ 1476/* Forward declaration */
1480static void 1477static void update_core_preference (void *cls,
1481update_core_preference (void *cls, 1478 const struct GNUNET_SCHEDULER_TaskContext
1482 const struct GNUNET_SCHEDULER_TaskContext *tc); 1479 *tc);
1483/** 1480/**
1484 * Function called with statistics about the given peer. 1481 * Function called with statistics about the given peer.
1485 * 1482 *
@@ -1532,14 +1529,12 @@ update_core_preference (void *cls,
1532 matching = 63; 1529 matching = 63;
1533 } 1530 }
1534 preference = 1LL << matching; 1531 preference = 1LL << matching;
1535 peer->info_ctx = GNUNET_CORE_peer_change_preference (coreAPI, 1532 peer->info_ctx =
1536 &peer->id, 1533 GNUNET_CORE_peer_change_preference (coreAPI, &peer->id,
1537 GNUNET_TIME_UNIT_FOREVER_REL, 1534 GNUNET_TIME_UNIT_FOREVER_REL,
1538 GNUNET_BANDWIDTH_VALUE_MAX, 1535 GNUNET_BANDWIDTH_VALUE_MAX, 0,
1539 0, 1536 preference,
1540 preference, 1537 &update_core_preference_finish, peer);
1541 &update_core_preference_finish,
1542 peer);
1543} 1538}
1544 1539
1545 1540
@@ -1557,12 +1552,12 @@ static void
1557remove_peer (struct PeerInfo *peer, unsigned int bucket) 1552remove_peer (struct PeerInfo *peer, unsigned int bucket)
1558{ 1553{
1559 GNUNET_assert (k_buckets[bucket].peers_size > 0); 1554 GNUNET_assert (k_buckets[bucket].peers_size > 0);
1560 GNUNET_CONTAINER_DLL_remove (k_buckets[bucket].head, 1555 GNUNET_CONTAINER_DLL_remove (k_buckets[bucket].head, k_buckets[bucket].tail,
1561 k_buckets[bucket].tail, peer); 1556 peer);
1562 k_buckets[bucket].peers_size--; 1557 k_buckets[bucket].peers_size--;
1563#if CHANGE_LOWEST 1558#if CHANGE_LOWEST
1564 if ((bucket == lowest_bucket) && (k_buckets[lowest_bucket].peers_size == 0) 1559 if ((bucket == lowest_bucket) && (k_buckets[lowest_bucket].peers_size == 0) &&
1565 && (lowest_bucket < MAX_BUCKETS - 1)) 1560 (lowest_bucket < MAX_BUCKETS - 1))
1566 lowest_bucket++; 1561 lowest_bucket++;
1567#endif 1562#endif
1568} 1563}
@@ -1589,8 +1584,8 @@ delete_peer (struct PeerInfo *peer, unsigned int bucket)
1589 if (peer_pos == NULL) 1584 if (peer_pos == NULL)
1590 { 1585 {
1591 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1586 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1592 "%s:%s: Expected peer `%s' in bucket %d\n", my_short_id, 1587 "%s:%s: Expected peer `%s' in bucket %d\n", my_short_id, "DHT",
1593 "DHT", GNUNET_i2s (&peer->id), bucket); 1588 GNUNET_i2s (&peer->id), bucket);
1594 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1589 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1595 "%s:%s: Lowest bucket: %d, find_current_bucket: %d, peer resides in bucket: %d\n", 1590 "%s:%s: Lowest bucket: %d, find_current_bucket: %d, peer resides in bucket: %d\n",
1596 my_short_id, "DHT", lowest_bucket, 1591 my_short_id, "DHT", lowest_bucket,
@@ -1677,8 +1672,7 @@ enable_next_bucket ()
1677 while (pos != NULL) 1672 while (pos != NULL)
1678 { 1673 {
1679 if (find_bucket (&pos->id.hashPubKey) < lowest_bucket) 1674 if (find_bucket (&pos->id.hashPubKey) < lowest_bucket)
1680 GNUNET_CONTAINER_multihashmap_put (to_remove, &pos->id.hashPubKey, 1675 GNUNET_CONTAINER_multihashmap_put (to_remove, &pos->id.hashPubKey, pos,
1681 pos,
1682 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 1676 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1683 pos = pos->next; 1677 pos = pos->next;
1684 } 1678 }
@@ -1747,8 +1741,8 @@ find_closest_peer (const GNUNET_HashCode * hc)
1747 * @param msg_ctx the context of the message (hop count, bloom, etc.) 1741 * @param msg_ctx the context of the message (hop count, bloom, etc.)
1748 */ 1742 */
1749static void 1743static void
1750forward_message (const struct GNUNET_MessageHeader *msg, 1744forward_message (const struct GNUNET_MessageHeader *msg, struct PeerInfo *peer,
1751 struct PeerInfo *peer, struct DHT_MessageContext *msg_ctx) 1745 struct DHT_MessageContext *msg_ctx)
1752{ 1746{
1753 struct GNUNET_DHT_P2PRouteMessage *route_message; 1747 struct GNUNET_DHT_P2PRouteMessage *route_message;
1754 struct P2PPendingMessage *pending; 1748 struct P2PPendingMessage *pending;
@@ -1758,8 +1752,8 @@ forward_message (const struct GNUNET_MessageHeader *msg,
1758 1752
1759 increment_stats (STAT_ROUTE_FORWARDS); 1753 increment_stats (STAT_ROUTE_FORWARDS);
1760 GNUNET_assert (peer != NULL); 1754 GNUNET_assert (peer != NULL);
1761 if ((msg_ctx->closest != GNUNET_YES) 1755 if ((msg_ctx->closest != GNUNET_YES) &&
1762 && (peer == find_closest_peer (&msg_ctx->key))) 1756 (peer == find_closest_peer (&msg_ctx->key)))
1763 increment_stats (STAT_ROUTE_FORWARDS_CLOSEST); 1757 increment_stats (STAT_ROUTE_FORWARDS_CLOSEST);
1764 1758
1765 msize = 1759 msize =
@@ -1782,8 +1776,7 @@ forward_message (const struct GNUNET_MessageHeader *msg,
1782 if (msg_ctx->bloom != NULL) 1776 if (msg_ctx->bloom != NULL)
1783 GNUNET_assert (GNUNET_OK == 1777 GNUNET_assert (GNUNET_OK ==
1784 GNUNET_CONTAINER_bloomfilter_get_raw_data (msg_ctx->bloom, 1778 GNUNET_CONTAINER_bloomfilter_get_raw_data (msg_ctx->bloom,
1785 route_message-> 1779 route_message->bloomfilter,
1786 bloomfilter,
1787 DHT_BLOOM_SIZE)); 1780 DHT_BLOOM_SIZE));
1788 memcpy (&route_message->key, &msg_ctx->key, sizeof (GNUNET_HashCode)); 1781 memcpy (&route_message->key, &msg_ctx->key, sizeof (GNUNET_HashCode));
1789 memcpy (&route_message[1], msg, ntohs (msg->size)); 1782 memcpy (&route_message[1], msg, ntohs (msg->size));
@@ -1801,8 +1794,8 @@ forward_message (const struct GNUNET_MessageHeader *msg,
1801 } 1794 }
1802#if DEBUG_DHT > 1 1795#if DEBUG_DHT > 1
1803 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1796 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1804 "%s:%s Adding pending message size %d for peer %s\n", 1797 "%s:%s Adding pending message size %d for peer %s\n", my_short_id,
1805 my_short_id, "DHT", msize, GNUNET_i2s (&peer->id)); 1798 "DHT", msize, GNUNET_i2s (&peer->id));
1806#endif 1799#endif
1807 peer->pending_count++; 1800 peer->pending_count++;
1808 increment_stats ("# pending messages scheduled"); 1801 increment_stats ("# pending messages scheduled");
@@ -1835,9 +1828,8 @@ periodic_ping_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1835 1828
1836 memset (&msg_ctx, 0, sizeof (struct DHT_MessageContext)); 1829 memset (&msg_ctx, 0, sizeof (struct DHT_MessageContext));
1837#if DEBUG_PING 1830#if DEBUG_PING
1838 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1831 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s:%s Sending periodic ping to %s\n",
1839 "%s:%s Sending periodic ping to %s\n", my_short_id, "DHT", 1832 my_short_id, "DHT", GNUNET_i2s (&peer->id));
1840 GNUNET_i2s (&peer->id));
1841#endif 1833#endif
1842 forward_message (&ping_message, peer, &msg_ctx); 1834 forward_message (&ping_message, peer, &msg_ctx);
1843 peer->ping_task = 1835 peer->ping_task =
@@ -1864,8 +1856,8 @@ schedule_ping_messages ()
1864 { 1856 {
1865 if ((count < bucket_size) && (pos->ping_task == GNUNET_SCHEDULER_NO_TASK)) 1857 if ((count < bucket_size) && (pos->ping_task == GNUNET_SCHEDULER_NO_TASK))
1866 GNUNET_SCHEDULER_add_now (&periodic_ping_task, pos); 1858 GNUNET_SCHEDULER_add_now (&periodic_ping_task, pos);
1867 else if ((count >= bucket_size) 1859 else if ((count >= bucket_size) &&
1868 && (pos->ping_task != GNUNET_SCHEDULER_NO_TASK)) 1860 (pos->ping_task != GNUNET_SCHEDULER_NO_TASK))
1869 { 1861 {
1870 GNUNET_SCHEDULER_cancel (pos->ping_task); 1862 GNUNET_SCHEDULER_cancel (pos->ping_task);
1871 pos->ping_task = GNUNET_SCHEDULER_NO_TASK; 1863 pos->ping_task = GNUNET_SCHEDULER_NO_TASK;
@@ -1893,8 +1885,8 @@ process_pending_messages (struct ClientList *client)
1893 1885
1894 client->transmit_handle = 1886 client->transmit_handle =
1895 GNUNET_SERVER_notify_transmit_ready (client->client_handle, 1887 GNUNET_SERVER_notify_transmit_ready (client->client_handle,
1896 ntohs (client->pending_head-> 1888 ntohs (client->pending_head->msg->
1897 msg->size), 1889 size),
1898 GNUNET_TIME_UNIT_FOREVER_REL, 1890 GNUNET_TIME_UNIT_FOREVER_REL,
1899 &send_generic_reply, client); 1891 &send_generic_reply, client);
1900} 1892}
@@ -1930,8 +1922,8 @@ send_generic_reply (void *cls, size_t size, void *buf)
1930 while ((NULL != (reply = client->pending_head)) && 1922 while ((NULL != (reply = client->pending_head)) &&
1931 (size >= off + (msize = ntohs (reply->msg->size)))) 1923 (size >= off + (msize = ntohs (reply->msg->size))))
1932 { 1924 {
1933 GNUNET_CONTAINER_DLL_remove (client->pending_head, 1925 GNUNET_CONTAINER_DLL_remove (client->pending_head, client->pending_tail,
1934 client->pending_tail, reply); 1926 reply);
1935 memcpy (&cbuf[off], reply->msg, msize); 1927 memcpy (&cbuf[off], reply->msg, msize);
1936 GNUNET_free (reply); 1928 GNUNET_free (reply);
1937 off += msize; 1929 off += msize;
@@ -1956,8 +1948,7 @@ static void
1956add_pending_message (struct ClientList *client, 1948add_pending_message (struct ClientList *client,
1957 struct PendingMessage *pending_message) 1949 struct PendingMessage *pending_message)
1958{ 1950{
1959 GNUNET_CONTAINER_DLL_insert_after (client->pending_head, 1951 GNUNET_CONTAINER_DLL_insert_after (client->pending_head, client->pending_tail,
1960 client->pending_tail,
1961 client->pending_tail, pending_message); 1952 client->pending_tail, pending_message);
1962 process_pending_messages (client); 1953 process_pending_messages (client);
1963} 1954}
@@ -1987,8 +1978,8 @@ send_reply_to_client (struct ClientList *client,
1987 unsigned int i; 1978 unsigned int i;
1988#endif 1979#endif
1989#if DEBUG_DHT 1980#if DEBUG_DHT
1990 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1981 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s:%s': Sending reply to client.\n",
1991 "`%s:%s': Sending reply to client.\n", my_short_id, "DHT"); 1982 my_short_id, "DHT");
1992#endif 1983#endif
1993 msize = ntohs (message->size); 1984 msize = ntohs (message->size);
1994 tsize = 1985 tsize =
@@ -2049,14 +2040,13 @@ consider_peer (struct GNUNET_PeerIdentity *peer)
2049 2040
2050 if ((GNUNET_YES == 2041 if ((GNUNET_YES ==
2051 GNUNET_CONTAINER_multihashmap_contains (all_known_peers, 2042 GNUNET_CONTAINER_multihashmap_contains (all_known_peers,
2052 &peer->hashPubKey)) 2043 &peer->hashPubKey)) ||
2053 || (0 == 2044 (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))))
2054 memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))))
2055 return GNUNET_NO; /* We already know this peer (are connected even!) */ 2045 return GNUNET_NO; /* We already know this peer (are connected even!) */
2056 bucket = find_current_bucket (&peer->hashPubKey); 2046 bucket = find_current_bucket (&peer->hashPubKey);
2057 2047
2058 if ((k_buckets[bucket].peers_size < bucket_size) 2048 if ((k_buckets[bucket].peers_size < bucket_size) ||
2059 || ((bucket == lowest_bucket) && (lowest_bucket > 0))) 2049 ((bucket == lowest_bucket) && (lowest_bucket > 0)))
2060 return GNUNET_YES; 2050 return GNUNET_YES;
2061 2051
2062 return GNUNET_NO; 2052 return GNUNET_NO;
@@ -2083,8 +2073,8 @@ remove_forward_entry (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2083 if (record->head == NULL) /* No more entries in DLL */ 2073 if (record->head == NULL) /* No more entries in DLL */
2084 { 2074 {
2085 GNUNET_assert (GNUNET_YES == 2075 GNUNET_assert (GNUNET_YES ==
2086 GNUNET_CONTAINER_multihashmap_remove 2076 GNUNET_CONTAINER_multihashmap_remove (forward_list.hashmap,
2087 (forward_list.hashmap, &record->key, record)); 2077 &record->key, record));
2088 GNUNET_free (record); 2078 GNUNET_free (record);
2089 } 2079 }
2090 if (source_info->find_peers_responded != NULL) 2080 if (source_info->find_peers_responded != NULL)
@@ -2127,10 +2117,10 @@ route_result_message (struct GNUNET_MessageHeader *msg,
2127 GNUNET_break_op (0); 2117 GNUNET_break_op (0);
2128 2118
2129 hello_msg = &msg[1]; 2119 hello_msg = &msg[1];
2130 if ((ntohs (hello_msg->type) != GNUNET_MESSAGE_TYPE_HELLO) 2120 if ((ntohs (hello_msg->type) != GNUNET_MESSAGE_TYPE_HELLO) ||
2131 || (GNUNET_SYSERR == 2121 (GNUNET_SYSERR ==
2132 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) 2122 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hello_msg,
2133 hello_msg, &new_peer))) 2123 &new_peer)))
2134 { 2124 {
2135 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2125 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2136 "%s:%s Received non-HELLO message type in find peer result message!\n", 2126 "%s:%s Received non-HELLO message type in find peer result message!\n",
@@ -2168,13 +2158,10 @@ route_result_message (struct GNUNET_MessageHeader *msg,
2168#if DEBUG_DHT_ROUTING 2158#if DEBUG_DHT_ROUTING
2169 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 2159 if ((debug_routes_extended) && (dhtlog_handle != NULL))
2170 { 2160 {
2171 dhtlog_handle->insert_route (NULL, 2161 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_RESULT,
2172 msg_ctx->unique_id, 2162 msg_ctx->hop_count, GNUNET_SYSERR,
2173 DHTLOG_RESULT, 2163 &my_identity, &msg_ctx->key, msg_ctx->peer,
2174 msg_ctx->hop_count, 2164 NULL);
2175 GNUNET_SYSERR,
2176 &my_identity,
2177 &msg_ctx->key, msg_ctx->peer, NULL);
2178 } 2165 }
2179#endif 2166#endif
2180 if (msg_ctx->bloom != NULL) 2167 if (msg_ctx->bloom != NULL)
@@ -2216,10 +2203,10 @@ route_result_message (struct GNUNET_MessageHeader *msg,
2216#if DEBUG_DHT_ROUTING 2203#if DEBUG_DHT_ROUTING
2217 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 2204 if ((debug_routes_extended) && (dhtlog_handle != NULL))
2218 { 2205 {
2219 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, 2206 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_RESULT,
2220 DHTLOG_RESULT, msg_ctx->hop_count, 2207 msg_ctx->hop_count, GNUNET_YES,
2221 GNUNET_YES, &my_identity, 2208 &my_identity, &msg_ctx->key, msg_ctx->peer,
2222 &msg_ctx->key, msg_ctx->peer, NULL); 2209 NULL);
2223 } 2210 }
2224#endif 2211#endif
2225 increment_stats (STAT_RESULTS_TO_CLIENT); 2212 increment_stats (STAT_RESULTS_TO_CLIENT);
@@ -2268,12 +2255,10 @@ route_result_message (struct GNUNET_MessageHeader *msg,
2268#if DEBUG_DHT_ROUTING 2255#if DEBUG_DHT_ROUTING
2269 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 2256 if ((debug_routes_extended) && (dhtlog_handle != NULL))
2270 { 2257 {
2271 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, 2258 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_RESULT,
2272 DHTLOG_RESULT, 2259 msg_ctx->hop_count, GNUNET_NO,
2273 msg_ctx->hop_count, 2260 &my_identity, &msg_ctx->key,
2274 GNUNET_NO, &my_identity, 2261 msg_ctx->peer, &pos->source);
2275 &msg_ctx->key, msg_ctx->peer,
2276 &pos->source);
2277 } 2262 }
2278#endif 2263#endif
2279 forward_result_message (msg, peer_info, msg_ctx); 2264 forward_result_message (msg, peer_info, msg_ctx);
@@ -2320,11 +2305,9 @@ route_result_message (struct GNUNET_MessageHeader *msg,
2320 * to stop iteration. 2305 * to stop iteration.
2321 */ 2306 */
2322static int 2307static int
2323datacache_get_iterator (void *cls, 2308datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
2324 struct GNUNET_TIME_Absolute exp, 2309 const GNUNET_HashCode * key, size_t size,
2325 const GNUNET_HashCode * key, 2310 const char *data, enum GNUNET_BLOCK_Type type)
2326 size_t size, const char *data,
2327 enum GNUNET_BLOCK_Type type)
2328{ 2311{
2329 struct DHT_MessageContext *msg_ctx = cls; 2312 struct DHT_MessageContext *msg_ctx = cls;
2330 struct DHT_MessageContext *new_msg_ctx; 2313 struct DHT_MessageContext *new_msg_ctx;
@@ -2346,29 +2329,25 @@ datacache_get_iterator (void *cls,
2346 2329
2347 put_entry = (const struct DHTPutEntry *) data; 2330 put_entry = (const struct DHTPutEntry *) data;
2348 2331
2349 if (size != sizeof (struct DHTPutEntry) + 2332 if (size !=
2350 put_entry->data_size + 2333 sizeof (struct DHTPutEntry) + put_entry->data_size +
2351 (put_entry->path_length * sizeof (struct GNUNET_PeerIdentity))) 2334 (put_entry->path_length * sizeof (struct GNUNET_PeerIdentity)))
2352 { 2335 {
2353 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2336 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2354 "Path + data size doesn't add up for data inserted into datacache!\nData size %d, path length %d, expected %d, got %d\n", 2337 "Path + data size doesn't add up for data inserted into datacache!\nData size %d, path length %d, expected %d, got %d\n",
2355 put_entry->data_size, put_entry->path_length, 2338 put_entry->data_size, put_entry->path_length,
2356 sizeof (struct DHTPutEntry) + put_entry->data_size 2339 sizeof (struct DHTPutEntry) + put_entry->data_size +
2357 +
2358 (put_entry->path_length * sizeof (struct GNUNET_PeerIdentity)), 2340 (put_entry->path_length * sizeof (struct GNUNET_PeerIdentity)),
2359 size); 2341 size);
2360 msg_ctx->do_forward = GNUNET_NO; 2342 msg_ctx->do_forward = GNUNET_NO;
2361 return GNUNET_OK; 2343 return GNUNET_OK;
2362 } 2344 }
2363 2345
2364 eval = GNUNET_BLOCK_evaluate (block_context, 2346 eval =
2365 type, 2347 GNUNET_BLOCK_evaluate (block_context, type, key, &msg_ctx->reply_bf,
2366 key, 2348 msg_ctx->reply_bf_mutator, msg_ctx->xquery,
2367 &msg_ctx->reply_bf, 2349 msg_ctx->xquery_size, &put_entry[1],
2368 msg_ctx->reply_bf_mutator, 2350 put_entry->data_size);
2369 msg_ctx->xquery,
2370 msg_ctx->xquery_size, &put_entry[1],
2371 put_entry->data_size);
2372 2351
2373 switch (eval) 2352 switch (eval)
2374 { 2353 {
@@ -2437,14 +2416,14 @@ datacache_get_iterator (void *cls,
2437 break; 2416 break;
2438 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: 2417 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
2439#if DEBUG_DHT 2418#if DEBUG_DHT
2440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2419 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s:%s': Duplicate block error\n",
2441 "`%s:%s': Duplicate block error\n", my_short_id, "DHT"); 2420 my_short_id, "DHT");
2442#endif 2421#endif
2443 break; 2422 break;
2444 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: 2423 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
2445#if DEBUG_DHT 2424#if DEBUG_DHT
2446 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2425 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "`%s:%s': Invalid request error\n",
2447 "`%s:%s': Invalid request error\n", my_short_id, "DHT"); 2426 my_short_id, "DHT");
2448#endif 2427#endif
2449 break; 2428 break;
2450 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: 2429 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
@@ -2478,9 +2457,8 @@ datacache_get_iterator (void *cls,
2478 * @param msg the message to be routed 2457 * @param msg the message to be routed
2479 * @param msg_ctx the context containing all pertinent information about the message 2458 * @param msg_ctx the context containing all pertinent information about the message
2480 */ 2459 */
2481static void 2460static void route_message (const struct GNUNET_MessageHeader *msg,
2482route_message (const struct GNUNET_MessageHeader *msg, 2461 struct DHT_MessageContext *msg_ctx);
2483 struct DHT_MessageContext *msg_ctx);
2484 2462
2485 2463
2486/** 2464/**
@@ -2535,17 +2513,16 @@ handle_dht_get (const struct GNUNET_MessageHeader *msg,
2535 } 2513 }
2536 else 2514 else
2537 { 2515 {
2538 msg_ctx->reply_bf = GNUNET_CONTAINER_bloomfilter_init (end, 2516 msg_ctx->reply_bf =
2539 bf_size, 2517 GNUNET_CONTAINER_bloomfilter_init (end, bf_size,
2540 GNUNET_DHT_GET_BLOOMFILTER_K); 2518 GNUNET_DHT_GET_BLOOMFILTER_K);
2541 } 2519 }
2542 type = (enum GNUNET_BLOCK_Type) ntohl (get_msg->type); 2520 type = (enum GNUNET_BLOCK_Type) ntohl (get_msg->type);
2543#if DEBUG_DHT 2521#if DEBUG_DHT
2544 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2522 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2545 "`%s:%s': Received `%s' request, message type %u, key %s, uid %llu\n", 2523 "`%s:%s': Received `%s' request, message type %u, key %s, uid %llu\n",
2546 my_short_id, 2524 my_short_id, "DHT", "GET", type, GNUNET_h2s (&msg_ctx->key),
2547 "DHT", "GET", 2525 msg_ctx->unique_id);
2548 type, GNUNET_h2s (&msg_ctx->key), msg_ctx->unique_id);
2549#endif 2526#endif
2550 increment_stats (STAT_GETS); 2527 increment_stats (STAT_GETS);
2551 results = 0; 2528 results = 0;
@@ -2558,10 +2535,9 @@ handle_dht_get (const struct GNUNET_MessageHeader *msg,
2558#endif 2535#endif
2559 msg_ctx->do_forward = GNUNET_YES; 2536 msg_ctx->do_forward = GNUNET_YES;
2560 if (datacache != NULL) 2537 if (datacache != NULL)
2561 results 2538 results =
2562 = GNUNET_DATACACHE_get (datacache, 2539 GNUNET_DATACACHE_get (datacache, &msg_ctx->key, type,
2563 &msg_ctx->key, type, 2540 &datacache_get_iterator, msg_ctx);
2564 &datacache_get_iterator, msg_ctx);
2565#if DEBUG_DHT 2541#if DEBUG_DHT
2566 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2542 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2567 "`%s:%s': Found %d results for `%s' request uid %llu\n", 2543 "`%s:%s': Found %d results for `%s' request uid %llu\n",
@@ -2573,30 +2549,25 @@ handle_dht_get (const struct GNUNET_MessageHeader *msg,
2573 if ((debug_routes) && (dhtlog_handle != NULL)) 2549 if ((debug_routes) && (dhtlog_handle != NULL))
2574 { 2550 {
2575 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_GET, 2551 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_GET,
2576 msg_ctx->hop_count, GNUNET_YES, 2552 msg_ctx->hop_count, GNUNET_YES, &my_identity,
2577 &my_identity, &msg_ctx->key); 2553 &msg_ctx->key);
2578 } 2554 }
2579 2555
2580 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 2556 if ((debug_routes_extended) && (dhtlog_handle != NULL))
2581 { 2557 {
2582 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE, 2558 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
2583 msg_ctx->hop_count, GNUNET_YES, 2559 msg_ctx->hop_count, GNUNET_YES, &my_identity,
2584 &my_identity, &msg_ctx->key, 2560 &msg_ctx->key, msg_ctx->peer, NULL);
2585 msg_ctx->peer, NULL);
2586 } 2561 }
2587#endif 2562#endif
2588 } 2563 }
2589 else 2564 else
2590 { 2565 {
2591 /* check query valid */ 2566 /* check query valid */
2592 if (GNUNET_BLOCK_EVALUATION_REQUEST_INVALID 2567 if (GNUNET_BLOCK_EVALUATION_REQUEST_INVALID ==
2593 == GNUNET_BLOCK_evaluate (block_context, 2568 GNUNET_BLOCK_evaluate (block_context, type, &msg_ctx->key,
2594 type, 2569 &msg_ctx->reply_bf, msg_ctx->reply_bf_mutator,
2595 &msg_ctx->key, 2570 msg_ctx->xquery, msg_ctx->xquery_size, NULL, 0))
2596 &msg_ctx->reply_bf,
2597 msg_ctx->reply_bf_mutator,
2598 msg_ctx->xquery,
2599 msg_ctx->xquery_size, NULL, 0))
2600 { 2571 {
2601 GNUNET_break_op (0); 2572 GNUNET_break_op (0);
2602 msg_ctx->do_forward = GNUNET_NO; 2573 msg_ctx->do_forward = GNUNET_NO;
@@ -2609,8 +2580,8 @@ handle_dht_get (const struct GNUNET_MessageHeader *msg,
2609 if ((debug_routes) && (dhtlog_handle != NULL)) 2580 if ((debug_routes) && (dhtlog_handle != NULL))
2610 { 2581 {
2611 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_GET, 2582 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_GET,
2612 msg_ctx->hop_count, GNUNET_NO, 2583 msg_ctx->hop_count, GNUNET_NO, &my_identity,
2613 &my_identity, &msg_ctx->key); 2584 &msg_ctx->key);
2614 } 2585 }
2615#endif 2586#endif
2616 } 2587 }
@@ -2667,11 +2638,10 @@ handle_dht_find_peer (const struct GNUNET_MessageHeader *find_msg,
2667 ntohs (find_msg->size) - sizeof (struct GNUNET_DHT_FindPeerMessage); 2638 ntohs (find_msg->size) - sizeof (struct GNUNET_DHT_FindPeerMessage);
2668 other_hello = GNUNET_malloc (other_hello_size); 2639 other_hello = GNUNET_malloc (other_hello_size);
2669 memcpy (other_hello, &find_peer_message[1], other_hello_size); 2640 memcpy (other_hello, &find_peer_message[1], other_hello_size);
2670 if ((GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) other_hello) == 2641 if ((GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) other_hello) == 0)
2671 0)
2672 || (GNUNET_OK != 2642 || (GNUNET_OK !=
2673 GNUNET_HELLO_get_id ((struct GNUNET_HELLO_Message *) 2643 GNUNET_HELLO_get_id ((struct GNUNET_HELLO_Message *) other_hello,
2674 other_hello, &peer_id))) 2644 &peer_id)))
2675 { 2645 {
2676 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2646 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2677 "Received invalid HELLO message in find peer request!\n"); 2647 "Received invalid HELLO message in find peer request!\n");
@@ -2802,8 +2772,8 @@ handle_dht_find_peer (const struct GNUNET_MessageHeader *find_msg,
2802 memcpy (&find_peer_result[1], my_hello, hello_size); 2772 memcpy (&find_peer_result[1], my_hello, hello_size);
2803#if DEBUG_DHT 2773#if DEBUG_DHT
2804 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2774 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2805 "`%s': Sending hello size %d to requesting peer.\n", 2775 "`%s': Sending hello size %d to requesting peer.\n", "DHT",
2806 "DHT", hello_size); 2776 hello_size);
2807#endif 2777#endif
2808 2778
2809 new_msg_ctx = GNUNET_malloc (sizeof (struct DHT_MessageContext)); 2779 new_msg_ctx = GNUNET_malloc (sizeof (struct DHT_MessageContext));
@@ -2829,8 +2799,8 @@ handle_dht_find_peer (const struct GNUNET_MessageHeader *find_msg,
2829 if ((debug_routes) && (dhtlog_handle != NULL)) 2799 if ((debug_routes) && (dhtlog_handle != NULL))
2830 { 2800 {
2831 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_FIND_PEER, 2801 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_FIND_PEER,
2832 msg_ctx->hop_count, GNUNET_YES, 2802 msg_ctx->hop_count, GNUNET_YES, &my_identity,
2833 &my_identity, &msg_ctx->key); 2803 &msg_ctx->key);
2834 } 2804 }
2835#endif 2805#endif
2836 GNUNET_free_non_null (other_hello); 2806 GNUNET_free_non_null (other_hello);
@@ -2845,8 +2815,8 @@ handle_dht_find_peer (const struct GNUNET_MessageHeader *find_msg,
2845 * @param cls closure (a struct RepublishContext) 2815 * @param cls closure (a struct RepublishContext)
2846 * @param tc runtime context for this task 2816 * @param tc runtime context for this task
2847 */ 2817 */
2848static void 2818static void republish_content (void *cls,
2849republish_content (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 2819 const struct GNUNET_SCHEDULER_TaskContext *tc);
2850 2820
2851/** 2821/**
2852 * Server handler for initiating local dht put requests 2822 * Server handler for initiating local dht put requests
@@ -2881,8 +2851,8 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg,
2881 /** Log routes that die due to high load! */ 2851 /** Log routes that die due to high load! */
2882 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE, 2852 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
2883 msg_ctx->hop_count, GNUNET_SYSERR, 2853 msg_ctx->hop_count, GNUNET_SYSERR,
2884 &my_identity, &msg_ctx->key, 2854 &my_identity, &msg_ctx->key, msg_ctx->peer,
2885 msg_ctx->peer, NULL); 2855 NULL);
2886 } 2856 }
2887#endif 2857#endif
2888 return; 2858 return;
@@ -2900,8 +2870,8 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg,
2900 { 2870 {
2901 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE, 2871 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
2902 msg_ctx->hop_count, GNUNET_SYSERR, 2872 msg_ctx->hop_count, GNUNET_SYSERR,
2903 &my_identity, &msg_ctx->key, 2873 &my_identity, &msg_ctx->key, msg_ctx->peer,
2904 msg_ctx->peer, NULL); 2874 NULL);
2905 } 2875 }
2906#endif 2876#endif
2907 /* invalid reply */ 2877 /* invalid reply */
@@ -2916,8 +2886,8 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg,
2916 { 2886 {
2917 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE, 2887 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
2918 msg_ctx->hop_count, GNUNET_SYSERR, 2888 msg_ctx->hop_count, GNUNET_SYSERR,
2919 &my_identity, &msg_ctx->key, 2889 &my_identity, &msg_ctx->key, msg_ctx->peer,
2920 msg_ctx->peer, NULL); 2890 NULL);
2921 } 2891 }
2922#endif 2892#endif
2923 /* invalid wrapper: key mismatch! */ 2893 /* invalid wrapper: key mismatch! */
@@ -2938,8 +2908,8 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg,
2938 if ((debug_routes) && (dhtlog_handle != NULL)) 2908 if ((debug_routes) && (dhtlog_handle != NULL))
2939 { 2909 {
2940 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_PUT, 2910 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_PUT,
2941 msg_ctx->hop_count, GNUNET_NO, 2911 msg_ctx->hop_count, GNUNET_NO, &my_identity,
2942 &my_identity, &msg_ctx->key); 2912 &msg_ctx->key);
2943 } 2913 }
2944 } 2914 }
2945#endif 2915#endif
@@ -2961,16 +2931,15 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg,
2961 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 2931 if ((debug_routes_extended) && (dhtlog_handle != NULL))
2962 { 2932 {
2963 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE, 2933 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
2964 msg_ctx->hop_count, GNUNET_YES, 2934 msg_ctx->hop_count, GNUNET_YES, &my_identity,
2965 &my_identity, &msg_ctx->key, msg_ctx->peer, 2935 &msg_ctx->key, msg_ctx->peer, NULL);
2966 NULL);
2967 } 2936 }
2968 2937
2969 if ((debug_routes) && (dhtlog_handle != NULL)) 2938 if ((debug_routes) && (dhtlog_handle != NULL))
2970 { 2939 {
2971 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_PUT, 2940 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_PUT,
2972 msg_ctx->hop_count, GNUNET_YES, 2941 msg_ctx->hop_count, GNUNET_YES, &my_identity,
2973 &my_identity, &msg_ctx->key); 2942 &msg_ctx->key);
2974 } 2943 }
2975#endif 2944#endif
2976 2945
@@ -2995,10 +2964,10 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg,
2995 msg_ctx->path_history_len * sizeof (struct GNUNET_PeerIdentity)); 2964 msg_ctx->path_history_len * sizeof (struct GNUNET_PeerIdentity));
2996 } 2965 }
2997 2966
2998 ret = GNUNET_DATACACHE_put (datacache, &msg_ctx->key, put_size, 2967 ret =
2999 (const char *) put_entry, put_type, 2968 GNUNET_DATACACHE_put (datacache, &msg_ctx->key, put_size,
3000 GNUNET_TIME_absolute_ntoh 2969 (const char *) put_entry, put_type,
3001 (put_msg->expiration)); 2970 GNUNET_TIME_absolute_ntoh (put_msg->expiration));
3002 GNUNET_free (put_entry); 2971 GNUNET_free (put_entry);
3003 2972
3004 if ((ret == GNUNET_YES) && (do_republish == GNUNET_YES)) 2973 if ((ret == GNUNET_YES) && (do_republish == GNUNET_YES))
@@ -3006,8 +2975,8 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg,
3006 put_context = GNUNET_malloc (sizeof (struct RepublishContext)); 2975 put_context = GNUNET_malloc (sizeof (struct RepublishContext));
3007 memcpy (&put_context->key, &msg_ctx->key, sizeof (GNUNET_HashCode)); 2976 memcpy (&put_context->key, &msg_ctx->key, sizeof (GNUNET_HashCode));
3008 put_context->type = put_type; 2977 put_context->type = put_type;
3009 GNUNET_SCHEDULER_add_delayed (dht_republish_frequency, 2978 GNUNET_SCHEDULER_add_delayed (dht_republish_frequency, &republish_content,
3010 &republish_content, put_context); 2979 put_context);
3011 } 2980 }
3012 } 2981 }
3013 else 2982 else
@@ -3102,17 +3071,16 @@ get_forward_count (unsigned int hop_count, size_t target_replication)
3102 if (GNUNET_YES == paper_forwarding) 3071 if (GNUNET_YES == paper_forwarding)
3103 { 3072 {
3104 /* FIXME: re-run replication trials with this formula */ 3073 /* FIXME: re-run replication trials with this formula */
3105 target_value = 1 + (target_replication - 1.0) / (diameter 3074 target_value =
3106 + 3075 1 + (target_replication - 1.0) / (diameter +
3107 ((float) 3076 ((float) (target_replication - 1.0) *
3108 (target_replication - 3077 hop_count));
3109 1.0) * hop_count));
3110 /* Set forward count to floor of target_value */ 3078 /* Set forward count to floor of target_value */
3111 forward_count = (unsigned int) target_value; 3079 forward_count = (unsigned int) target_value;
3112 /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */ 3080 /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */
3113 target_value = target_value - forward_count; 3081 target_value = target_value - forward_count;
3114 random_value = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 3082 random_value =
3115 UINT32_MAX); 3083 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, UINT32_MAX);
3116 3084
3117 if (random_value < (target_value * UINT32_MAX)) 3085 if (random_value < (target_value * UINT32_MAX))
3118 forward_count += 1; 3086 forward_count += 1;
@@ -3121,10 +3089,9 @@ get_forward_count (unsigned int hop_count, size_t target_replication)
3121 { 3089 {
3122 random_value = 0; 3090 random_value = 0;
3123 forward_count = 1; 3091 forward_count = 1;
3124 target_value = target_replication / (diameter 3092 target_value =
3125 + 3093 target_replication / (diameter +
3126 ((float) target_replication * 3094 ((float) target_replication * hop_count));
3127 hop_count));
3128 if (target_value > 1) 3095 if (target_value > 1)
3129 { 3096 {
3130 /* Set forward count to floor of target_value */ 3097 /* Set forward count to floor of target_value */
@@ -3133,8 +3100,8 @@ get_forward_count (unsigned int hop_count, size_t target_replication)
3133 target_value = target_value - forward_count; 3100 target_value = target_value - forward_count;
3134 } 3101 }
3135 else 3102 else
3136 random_value = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 3103 random_value =
3137 UINT32_MAX); 3104 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, UINT32_MAX);
3138 3105
3139 if (random_value < (target_value * UINT32_MAX)) 3106 if (random_value < (target_value * UINT32_MAX))
3140 forward_count += 1; 3107 forward_count += 1;
@@ -3176,9 +3143,9 @@ am_closest_peer (const GNUNET_HashCode * target,
3176 count = 0; 3143 count = 0;
3177 while ((pos != NULL) && (count < bucket_size)) 3144 while ((pos != NULL) && (count < bucket_size))
3178 { 3145 {
3179 if ((bloom != NULL) 3146 if ((bloom != NULL) &&
3180 && (GNUNET_YES == 3147 (GNUNET_YES ==
3181 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))) 3148 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)))
3182 { 3149 {
3183 pos = pos->next; 3150 pos = pos->next;
3184 continue; /* Skip already checked entries */ 3151 continue; /* Skip already checked entries */
@@ -3216,8 +3183,8 @@ am_closest_peer (const GNUNET_HashCode * target,
3216 * 3183 *
3217 */ 3184 */
3218static unsigned long long 3185static unsigned long long
3219converge_distance (const GNUNET_HashCode * target, 3186converge_distance (const GNUNET_HashCode * target, struct PeerInfo *peer,
3220 struct PeerInfo *peer, unsigned int hops) 3187 unsigned int hops)
3221{ 3188{
3222 unsigned long long ret; 3189 unsigned long long ret;
3223 unsigned int other_matching_bits; 3190 unsigned int other_matching_bits;
@@ -3298,8 +3265,8 @@ converge_distance (const GNUNET_HashCode * target,
3298 errno = 0; 3265 errno = 0;
3299 feclearexcept (FE_ALL_EXCEPT); 3266 feclearexcept (FE_ALL_EXCEPT);
3300 ret = (unsigned long long) pow (other_matching_bits, calc_value); 3267 ret = (unsigned long long) pow (other_matching_bits, calc_value);
3301 if ((errno != 0) || fetestexcept (FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | 3268 if ((errno != 0) ||
3302 FE_UNDERFLOW)) 3269 fetestexcept (FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW))
3303 { 3270 {
3304 if (0 != fetestexcept (FE_OVERFLOW)) 3271 if (0 != fetestexcept (FE_OVERFLOW))
3305 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "FE_OVERFLOW\n"); 3272 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "FE_OVERFLOW\n");
@@ -3542,10 +3509,10 @@ select_peer (const GNUNET_HashCode * target,
3542 break; /* overflow case */ 3509 break; /* overflow case */
3543 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3510 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3544 "Choose %d matching bits (%d bits match me) (%.2f percent) converge ret %llu\n", 3511 "Choose %d matching bits (%d bits match me) (%.2f percent) converge ret %llu\n",
3545 GNUNET_CRYPTO_hash_matching_bits (&sorted_closest[i]->id. 3512 GNUNET_CRYPTO_hash_matching_bits (&sorted_closest[i]->
3546 hashPubKey, target), 3513 id.hashPubKey, target),
3547 GNUNET_CRYPTO_hash_matching_bits (&sorted_closest[i]->id. 3514 GNUNET_CRYPTO_hash_matching_bits (&sorted_closest[i]->
3548 hashPubKey, 3515 id.hashPubKey,
3549 &my_identity.hashPubKey), 3516 &my_identity.hashPubKey),
3550 (temp_converge_distance / (double) total_distance) * 100, 3517 (temp_converge_distance / (double) total_distance) * 100,
3551 temp_converge_distance); 3518 temp_converge_distance);
@@ -3576,8 +3543,8 @@ select_peer (const GNUNET_HashCode * target,
3576 target), 3543 target),
3577 GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey, 3544 GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey,
3578 &my_identity.hashPubKey), 3545 &my_identity.hashPubKey),
3579 (temp_converge_distance / (double) total_distance) * 3546 (temp_converge_distance / (double) total_distance) * 100,
3580 100, temp_converge_distance); 3547 temp_converge_distance);
3581 pos = pos->next; 3548 pos = pos->next;
3582 count++; 3549 count++;
3583 } 3550 }
@@ -3608,8 +3575,8 @@ select_peer (const GNUNET_HashCode * target,
3608 target), 3575 target),
3609 GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey, 3576 GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey,
3610 &my_identity.hashPubKey), 3577 &my_identity.hashPubKey),
3611 (temp_converge_distance / (double) total_distance) * 3578 (temp_converge_distance / (double) total_distance) * 100,
3612 100, temp_converge_distance); 3579 temp_converge_distance);
3613 pos = pos->next; 3580 pos = pos->next;
3614 count++; 3581 count++;
3615 } 3582 }
@@ -3750,8 +3717,9 @@ cache_response (struct DHT_MessageContext *msg_ctx)
3750 if (record->head == NULL) /* No more entries in DLL */ 3717 if (record->head == NULL) /* No more entries in DLL */
3751 { 3718 {
3752 GNUNET_assert (GNUNET_YES == 3719 GNUNET_assert (GNUNET_YES ==
3753 GNUNET_CONTAINER_multihashmap_remove 3720 GNUNET_CONTAINER_multihashmap_remove (forward_list.hashmap,
3754 (forward_list.hashmap, &record->key, record)); 3721 &record->key,
3722 record));
3755 GNUNET_free (record); 3723 GNUNET_free (record);
3756 } 3724 }
3757 if (source_info->delete_task != GNUNET_SCHEDULER_NO_TASK) 3725 if (source_info->delete_task != GNUNET_SCHEDULER_NO_TASK)
@@ -3864,8 +3832,8 @@ route_message (const struct GNUNET_MessageHeader *msg,
3864 { 3832 {
3865 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE, 3833 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
3866 msg_ctx->hop_count, GNUNET_SYSERR, 3834 msg_ctx->hop_count, GNUNET_SYSERR,
3867 &my_identity, &msg_ctx->key, 3835 &my_identity, &msg_ctx->key, msg_ctx->peer,
3868 msg_ctx->peer, NULL); 3836 NULL);
3869 } 3837 }
3870#endif 3838#endif
3871 if (msg_ctx->bloom != NULL) 3839 if (msg_ctx->bloom != NULL)
@@ -3887,8 +3855,8 @@ route_message (const struct GNUNET_MessageHeader *msg,
3887 msg_ctx->bloom = 3855 msg_ctx->bloom =
3888 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); 3856 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
3889 3857
3890 if ((stop_on_closest == GNUNET_YES) && (msg_ctx->closest == GNUNET_YES) 3858 if ((stop_on_closest == GNUNET_YES) && (msg_ctx->closest == GNUNET_YES) &&
3891 && (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_DHT_PUT)) 3859 (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_DHT_PUT))
3892 target_forward_count = 0; 3860 target_forward_count = 0;
3893 3861
3894 /** 3862 /**
@@ -3906,9 +3874,9 @@ route_message (const struct GNUNET_MessageHeader *msg,
3906 * testing driver) we will ignore this restriction for FIND_PEER messages so that 3874 * testing driver) we will ignore this restriction for FIND_PEER messages so that
3907 * routing tables still get constructed. 3875 * routing tables still get constructed.
3908 */ 3876 */
3909 if ((GNUNET_YES == strict_kademlia) && (msg_ctx->closest == GNUNET_YES) 3877 if ((GNUNET_YES == strict_kademlia) && (msg_ctx->closest == GNUNET_YES) &&
3910 && (msg_ctx->hop_count > 0) 3878 (msg_ctx->hop_count > 0) &&
3911 && (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_DHT_FIND_PEER)) 3879 (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_DHT_FIND_PEER))
3912 target_forward_count = 0; 3880 target_forward_count = 0;
3913 3881
3914 3882
@@ -3942,8 +3910,7 @@ route_message (const struct GNUNET_MessageHeader *msg,
3942 GNUNET_TIME_absolute_get ().abs_value); 3910 GNUNET_TIME_absolute_get ().abs_value);
3943 recent_req->bloom = 3911 recent_req->bloom =
3944 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); 3912 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
3945 GNUNET_CONTAINER_multihashmap_put (recent.hashmap, &unique_hash, 3913 GNUNET_CONTAINER_multihashmap_put (recent.hashmap, &unique_hash, recent_req,
3946 recent_req,
3947 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 3914 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
3948 } 3915 }
3949 3916
@@ -3988,8 +3955,7 @@ route_message (const struct GNUNET_MessageHeader *msg,
3988 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3955 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3989 "`%s:%s': Forwarding request key %s uid %llu to peer %s (closest %s, bits %d, distance %u)\n", 3956 "`%s:%s': Forwarding request key %s uid %llu to peer %s (closest %s, bits %d, distance %u)\n",
3990 my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key), 3957 my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key),
3991 msg_ctx->unique_id, GNUNET_i2s (&selected->id), 3958 msg_ctx->unique_id, GNUNET_i2s (&selected->id), nearest_buf,
3992 nearest_buf,
3993 GNUNET_CRYPTO_hash_matching_bits (&nearest->id.hashPubKey, 3959 GNUNET_CRYPTO_hash_matching_bits (&nearest->id.hashPubKey,
3994 msg_ctx->key), 3960 msg_ctx->key),
3995 distance (&nearest->id.hashPubKey, msg_ctx->key)); 3961 distance (&nearest->id.hashPubKey, msg_ctx->key));
@@ -3998,10 +3964,9 @@ route_message (const struct GNUNET_MessageHeader *msg,
3998#if DEBUG_DHT_ROUTING 3964#if DEBUG_DHT_ROUTING
3999 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 3965 if ((debug_routes_extended) && (dhtlog_handle != NULL))
4000 { 3966 {
4001 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, 3967 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
4002 DHTLOG_ROUTE, msg_ctx->hop_count, 3968 msg_ctx->hop_count, GNUNET_NO,
4003 GNUNET_NO, &my_identity, 3969 &my_identity, &msg_ctx->key, msg_ctx->peer,
4004 &msg_ctx->key, msg_ctx->peer,
4005 &selected->id); 3970 &selected->id);
4006 } 3971 }
4007#endif 3972#endif
@@ -4026,9 +3991,8 @@ route_message (const struct GNUNET_MessageHeader *msg,
4026 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 3991 if ((debug_routes_extended) && (dhtlog_handle != NULL))
4027 { 3992 {
4028 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE, 3993 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
4029 msg_ctx->hop_count, ret, 3994 msg_ctx->hop_count, ret, &my_identity,
4030 &my_identity, &msg_ctx->key, msg_ctx->peer, 3995 &msg_ctx->key, msg_ctx->peer, NULL);
4031 NULL);
4032 } 3996 }
4033#endif 3997#endif
4034} 3998}
@@ -4061,15 +4025,15 @@ demultiplex_message (const struct GNUNET_MessageHeader *msg,
4061 break; 4025 break;
4062 case GNUNET_MESSAGE_TYPE_DHT_FIND_PEER: /* Check if closest and not started by us, check options, add to requests seen */ 4026 case GNUNET_MESSAGE_TYPE_DHT_FIND_PEER: /* Check if closest and not started by us, check options, add to requests seen */
4063 increment_stats (STAT_FIND_PEER); 4027 increment_stats (STAT_FIND_PEER);
4064 if (((msg_ctx->hop_count > 0) 4028 if (((msg_ctx->hop_count > 0) &&
4065 && (0 != 4029 (0 !=
4066 memcmp (msg_ctx->peer, &my_identity, 4030 memcmp (msg_ctx->peer, &my_identity,
4067 sizeof (struct GNUNET_PeerIdentity)))) 4031 sizeof (struct GNUNET_PeerIdentity)))) ||
4068 || (msg_ctx->client != NULL)) 4032 (msg_ctx->client != NULL))
4069 { 4033 {
4070 cache_response (msg_ctx); 4034 cache_response (msg_ctx);
4071 if ((msg_ctx->closest == GNUNET_YES) 4035 if ((msg_ctx->closest == GNUNET_YES) ||
4072 || (msg_ctx->msg_options == GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) 4036 (msg_ctx->msg_options == GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE))
4073 handle_dht_find_peer (msg, msg_ctx); 4037 handle_dht_find_peer (msg, msg_ctx);
4074 } 4038 }
4075 else 4039 else
@@ -4080,8 +4044,7 @@ demultiplex_message (const struct GNUNET_MessageHeader *msg,
4080 if ((debug_routes) && (dhtlog_handle != NULL)) 4044 if ((debug_routes) && (dhtlog_handle != NULL))
4081 { 4045 {
4082 dhtlog_handle->insert_dhtkey (NULL, &msg_ctx->key); 4046 dhtlog_handle->insert_dhtkey (NULL, &msg_ctx->key);
4083 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, 4047 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_FIND_PEER,
4084 DHTLOG_FIND_PEER,
4085 msg_ctx->hop_count, GNUNET_NO, 4048 msg_ctx->hop_count, GNUNET_NO,
4086 &my_identity, &msg_ctx->key); 4049 &my_identity, &msg_ctx->key);
4087 } 4050 }
@@ -4113,10 +4076,9 @@ demultiplex_message (const struct GNUNET_MessageHeader *msg,
4113 * to stop iteration. 4076 * to stop iteration.
4114 */ 4077 */
4115static int 4078static int
4116republish_content_iterator (void *cls, 4079republish_content_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
4117 struct GNUNET_TIME_Absolute exp, 4080 const GNUNET_HashCode * key, size_t size,
4118 const GNUNET_HashCode * key, 4081 const char *data, uint32_t type)
4119 size_t size, const char *data, uint32_t type)
4120{ 4082{
4121 4083
4122 struct DHT_MessageContext *new_msg_ctx; 4084 struct DHT_MessageContext *new_msg_ctx;
@@ -4227,8 +4189,8 @@ find_client_records (void *cls, const GNUNET_HashCode * key, void *value)
4227 if (record->head == NULL) /* No more entries in DLL */ 4189 if (record->head == NULL) /* No more entries in DLL */
4228 { 4190 {
4229 GNUNET_assert (GNUNET_YES == 4191 GNUNET_assert (GNUNET_YES ==
4230 GNUNET_CONTAINER_multihashmap_remove 4192 GNUNET_CONTAINER_multihashmap_remove (forward_list.hashmap,
4231 (forward_list.hashmap, &record->key, record)); 4193 &record->key, record));
4232 GNUNET_free (record); 4194 GNUNET_free (record);
4233 } 4195 }
4234 return GNUNET_YES; 4196 return GNUNET_YES;
@@ -4274,8 +4236,8 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
4274 4236
4275 while (NULL != (reply = found->pending_head)) 4237 while (NULL != (reply = found->pending_head))
4276 { 4238 {
4277 GNUNET_CONTAINER_DLL_remove (found->pending_head, 4239 GNUNET_CONTAINER_DLL_remove (found->pending_head, found->pending_tail,
4278 found->pending_tail, reply); 4240 reply);
4279 GNUNET_free (reply); 4241 GNUNET_free (reply);
4280 } 4242 }
4281 GNUNET_CONTAINER_multihashmap_iterate (forward_list.hashmap, 4243 GNUNET_CONTAINER_multihashmap_iterate (forward_list.hashmap,
@@ -4354,13 +4316,13 @@ malicious_put_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
4354#endif 4316#endif
4355 increment_stats (STAT_PUT_START); 4317 increment_stats (STAT_PUT_START);
4356 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4318 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4357 "%s:%s Sending malicious PUT message with hash %s\n", 4319 "%s:%s Sending malicious PUT message with hash %s\n", my_short_id,
4358 my_short_id, "DHT", GNUNET_h2s (&key)); 4320 "DHT", GNUNET_h2s (&key));
4359 demultiplex_message (&put_message.header, &msg_ctx); 4321 demultiplex_message (&put_message.header, &msg_ctx);
4360 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 4322 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
4361 (GNUNET_TIME_UNIT_MILLISECONDS, 4323 (GNUNET_TIME_UNIT_MILLISECONDS,
4362 malicious_put_frequency), 4324 malicious_put_frequency), &malicious_put_task,
4363 &malicious_put_task, NULL); 4325 NULL);
4364} 4326}
4365 4327
4366 4328
@@ -4404,13 +4366,13 @@ malicious_get_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
4404#endif 4366#endif
4405 increment_stats (STAT_GET_START); 4367 increment_stats (STAT_GET_START);
4406 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4368 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4407 "%s:%s Sending malicious GET message with hash %s\n", 4369 "%s:%s Sending malicious GET message with hash %s\n", my_short_id,
4408 my_short_id, "DHT", GNUNET_h2s (&key)); 4370 "DHT", GNUNET_h2s (&key));
4409 demultiplex_message (&get_message.header, &msg_ctx); 4371 demultiplex_message (&get_message.header, &msg_ctx);
4410 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 4372 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
4411 (GNUNET_TIME_UNIT_MILLISECONDS, 4373 (GNUNET_TIME_UNIT_MILLISECONDS,
4412 malicious_get_frequency), 4374 malicious_get_frequency), &malicious_get_task,
4413 &malicious_get_task, NULL); 4375 NULL);
4414} 4376}
4415#endif 4377#endif
4416 4378
@@ -4511,8 +4473,7 @@ send_find_peer_message (void *cls,
4511 temp_bloom); 4473 temp_bloom);
4512 GNUNET_assert (GNUNET_OK == 4474 GNUNET_assert (GNUNET_OK ==
4513 GNUNET_CONTAINER_bloomfilter_get_raw_data (temp_bloom, 4475 GNUNET_CONTAINER_bloomfilter_get_raw_data (temp_bloom,
4514 find_peer_msg-> 4476 find_peer_msg->bloomfilter,
4515 bloomfilter,
4516 DHT_BLOOM_SIZE)); 4477 DHT_BLOOM_SIZE));
4517 GNUNET_CONTAINER_bloomfilter_free (temp_bloom); 4478 GNUNET_CONTAINER_bloomfilter_free (temp_bloom);
4518 memset (&msg_ctx, 0, sizeof (struct DHT_MessageContext)); 4479 memset (&msg_ctx, 0, sizeof (struct DHT_MessageContext));
@@ -4541,7 +4502,8 @@ send_find_peer_message (void *cls,
4541 } 4502 }
4542 else 4503 else
4543 { 4504 {
4544 next_send_time.rel_value = DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value + 4505 next_send_time.rel_value =
4506 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value +
4545 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, 4507 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
4546 DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value - 4508 DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value -
4547 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value); 4509 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value);
@@ -4553,8 +4515,8 @@ send_find_peer_message (void *cls,
4553 find_peer_context.start = GNUNET_TIME_absolute_get (); 4515 find_peer_context.start = GNUNET_TIME_absolute_get ();
4554 if (GNUNET_YES == do_find_peer) 4516 if (GNUNET_YES == do_find_peer)
4555 { 4517 {
4556 GNUNET_SCHEDULER_add_delayed (next_send_time, 4518 GNUNET_SCHEDULER_add_delayed (next_send_time, &send_find_peer_message,
4557 &send_find_peer_message, NULL); 4519 NULL);
4558 } 4520 }
4559} 4521}
4560 4522
@@ -4568,8 +4530,7 @@ send_find_peer_message (void *cls,
4568 * @param message the actual message received 4530 * @param message the actual message received
4569 */ 4531 */
4570static void 4532static void
4571handle_dht_local_route_request (void *cls, 4533handle_dht_local_route_request (void *cls, struct GNUNET_SERVER_Client *client,
4572 struct GNUNET_SERVER_Client *client,
4573 const struct GNUNET_MessageHeader *message) 4534 const struct GNUNET_MessageHeader *message)
4574{ 4535{
4575 const struct GNUNET_DHT_RouteMessage *dht_msg = 4536 const struct GNUNET_DHT_RouteMessage *dht_msg =
@@ -4581,10 +4542,7 @@ handle_dht_local_route_request (void *cls,
4581#if DEBUG_DHT 4542#if DEBUG_DHT
4582 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4543 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4583 "`%s:%s': Received `%s' request from client, message type %d, key %s, uid %llu\n", 4544 "`%s:%s': Received `%s' request from client, message type %d, key %s, uid %llu\n",
4584 my_short_id, 4545 my_short_id, "DHT", "GENERIC", ntohs (message->type),
4585 "DHT",
4586 "GENERIC",
4587 ntohs (message->type),
4588 GNUNET_h2s (&dht_msg->key), GNUNET_ntohll (dht_msg->unique_id)); 4546 GNUNET_h2s (&dht_msg->key), GNUNET_ntohll (dht_msg->unique_id));
4589#endif 4547#endif
4590#if DEBUG_DHT_ROUTING 4548#if DEBUG_DHT_ROUTING
@@ -4625,9 +4583,9 @@ handle_dht_local_route_request (void *cls,
4625#if DEBUG_DHT_ROUTING 4583#if DEBUG_DHT_ROUTING
4626 if ((debug_routes) && (dhtlog_handle != NULL)) 4584 if ((debug_routes) && (dhtlog_handle != NULL))
4627 { 4585 {
4628 dhtlog_handle->insert_query (NULL, msg_ctx.unique_id, 4586 dhtlog_handle->insert_query (NULL, msg_ctx.unique_id, DHTLOG_GET,
4629 DHTLOG_GET, msg_ctx.hop_count, 4587 msg_ctx.hop_count, GNUNET_NO, &my_identity,
4630 GNUNET_NO, &my_identity, &msg_ctx.key); 4588 &msg_ctx.key);
4631 } 4589 }
4632#endif 4590#endif
4633 } 4591 }
@@ -4636,9 +4594,9 @@ handle_dht_local_route_request (void *cls,
4636#if DEBUG_DHT_ROUTING 4594#if DEBUG_DHT_ROUTING
4637 if ((debug_routes) && (dhtlog_handle != NULL)) 4595 if ((debug_routes) && (dhtlog_handle != NULL))
4638 { 4596 {
4639 dhtlog_handle->insert_query (NULL, msg_ctx.unique_id, 4597 dhtlog_handle->insert_query (NULL, msg_ctx.unique_id, DHTLOG_PUT,
4640 DHTLOG_PUT, msg_ctx.hop_count, 4598 msg_ctx.hop_count, GNUNET_NO, &my_identity,
4641 GNUNET_NO, &my_identity, &msg_ctx.key); 4599 &msg_ctx.key);
4642 } 4600 }
4643#endif 4601#endif
4644 } 4602 }
@@ -4719,8 +4677,8 @@ handle_dht_control_message (void *cls, struct GNUNET_SERVER_Client *client,
4719#endif 4677#endif
4720 default: 4678 default:
4721 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 4679 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
4722 "%s:%s Unknown control command type `%d'!\n", 4680 "%s:%s Unknown control command type `%d'!\n", my_short_id,
4723 my_short_id, "DHT", ntohs (dht_control_msg->command)); 4681 "DHT", ntohs (dht_control_msg->command));
4724 break; 4682 break;
4725 } 4683 }
4726 4684
@@ -4787,8 +4745,7 @@ handle_dht_local_route_stop (void *cls, struct GNUNET_SERVER_Client *client,
4787 * 4745 *
4788 */ 4746 */
4789static int 4747static int
4790handle_dht_p2p_route_request (void *cls, 4748handle_dht_p2p_route_request (void *cls, const struct GNUNET_PeerIdentity *peer,
4791 const struct GNUNET_PeerIdentity *peer,
4792 const struct GNUNET_MessageHeader *message, 4749 const struct GNUNET_MessageHeader *message,
4793 const struct GNUNET_TRANSPORT_ATS_Information 4750 const struct GNUNET_TRANSPORT_ATS_Information
4794 *atsi) 4751 *atsi)
@@ -4809,8 +4766,8 @@ handle_dht_p2p_route_request (void *cls,
4809 if (ntohs (enc_msg->type) == GNUNET_MESSAGE_TYPE_DHT_P2P_PING) /* Throw these away. FIXME: Don't throw these away? (reply) */ 4766 if (ntohs (enc_msg->type) == GNUNET_MESSAGE_TYPE_DHT_P2P_PING) /* Throw these away. FIXME: Don't throw these away? (reply) */
4810 { 4767 {
4811#if DEBUG_PING 4768#if DEBUG_PING
4812 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4769 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s:%s Received P2P Ping message.\n",
4813 "%s:%s Received P2P Ping message.\n", my_short_id, "DHT"); 4770 my_short_id, "DHT");
4814#endif 4771#endif
4815 return GNUNET_YES; 4772 return GNUNET_YES;
4816 } 4773 }
@@ -4827,12 +4784,10 @@ handle_dht_p2p_route_request (void *cls,
4827 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 4784 if ((debug_routes_extended) && (dhtlog_handle != NULL))
4828 { 4785 {
4829 /** Log routes that die due to high load! */ 4786 /** Log routes that die due to high load! */
4830 dhtlog_handle->insert_route (NULL, 4787 dhtlog_handle->insert_route (NULL, GNUNET_ntohll (incoming->unique_id),
4831 GNUNET_ntohll (incoming->unique_id), 4788 DHTLOG_ROUTE, ntohl (incoming->hop_count),
4832 DHTLOG_ROUTE, 4789 GNUNET_SYSERR, &my_identity, &incoming->key,
4833 ntohl (incoming->hop_count), 4790 peer, NULL);
4834 GNUNET_SYSERR, &my_identity,
4835 &incoming->key, peer, NULL);
4836 } 4791 }
4837#endif 4792#endif
4838 return GNUNET_YES; 4793 return GNUNET_YES;
@@ -4848,12 +4803,10 @@ handle_dht_p2p_route_request (void *cls,
4848 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 4803 if ((debug_routes_extended) && (dhtlog_handle != NULL))
4849 { 4804 {
4850 /** Log routes that die due to high load! */ 4805 /** Log routes that die due to high load! */
4851 dhtlog_handle->insert_route (NULL, 4806 dhtlog_handle->insert_route (NULL, GNUNET_ntohll (incoming->unique_id),
4852 GNUNET_ntohll (incoming->unique_id), 4807 DHTLOG_ROUTE, ntohl (incoming->hop_count),
4853 DHTLOG_ROUTE, 4808 GNUNET_SYSERR, &my_identity, &incoming->key,
4854 ntohl (incoming->hop_count), 4809 peer, NULL);
4855 GNUNET_SYSERR, &my_identity,
4856 &incoming->key, peer, NULL);
4857 } 4810 }
4858#endif 4811#endif
4859 return GNUNET_YES; 4812 return GNUNET_YES;
@@ -4911,8 +4864,7 @@ handle_dht_p2p_route_request (void *cls,
4911 * 4864 *
4912 */ 4865 */
4913static int 4866static int
4914handle_dht_p2p_route_result (void *cls, 4867handle_dht_p2p_route_result (void *cls, const struct GNUNET_PeerIdentity *peer,
4915 const struct GNUNET_PeerIdentity *peer,
4916 const struct GNUNET_MessageHeader *message, 4868 const struct GNUNET_MessageHeader *message,
4917 const struct GNUNET_TRANSPORT_ATS_Information 4869 const struct GNUNET_TRANSPORT_ATS_Information
4918 *atsi) 4870 *atsi)
@@ -4944,12 +4896,10 @@ handle_dht_p2p_route_result (void *cls,
4944 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 4896 if ((debug_routes_extended) && (dhtlog_handle != NULL))
4945 { 4897 {
4946 /** Log routes that die due to high load! */ 4898 /** Log routes that die due to high load! */
4947 dhtlog_handle->insert_route (NULL, 4899 dhtlog_handle->insert_route (NULL, GNUNET_ntohll (incoming->unique_id),
4948 GNUNET_ntohll (incoming->unique_id), 4900 DHTLOG_ROUTE, ntohl (incoming->hop_count),
4949 DHTLOG_ROUTE, 4901 GNUNET_SYSERR, &my_identity, &incoming->key,
4950 ntohl (incoming->hop_count), 4902 peer, NULL);
4951 GNUNET_SYSERR, &my_identity,
4952 &incoming->key, peer, NULL);
4953 } 4903 }
4954#endif 4904#endif
4955 return GNUNET_YES; 4905 return GNUNET_YES;
@@ -4977,8 +4927,7 @@ handle_dht_p2p_route_result (void *cls,
4977#if DEBUG_DHT 4927#if DEBUG_DHT
4978 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4928 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4979 "Return message indicated a path was included, but sizes are wrong: Total size %d, enc size %d, left %d, expected %d\n", 4929 "Return message indicated a path was included, but sizes are wrong: Total size %d, enc size %d, left %d, expected %d\n",
4980 ntohs (message->size), 4930 ntohs (message->size), ntohs (enc_msg->size),
4981 ntohs (enc_msg->size),
4982 ntohs (message->size) - 4931 ntohs (message->size) -
4983 sizeof (struct GNUNET_DHT_P2PRouteResultMessage) - 4932 sizeof (struct GNUNET_DHT_P2PRouteResultMessage) -
4984 ntohs (enc_msg->size), 4933 ntohs (enc_msg->size),
@@ -5055,8 +5004,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
5055 if (coreAPI != NULL) 5004 if (coreAPI != NULL)
5056 { 5005 {
5057#if DEBUG_DHT 5006#if DEBUG_DHT
5058 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5007 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s:%s Disconnecting core!\n",
5059 "%s:%s Disconnecting core!\n", my_short_id, "DHT"); 5008 my_short_id, "DHT");
5060#endif 5009#endif
5061 GNUNET_CORE_disconnect (coreAPI); 5010 GNUNET_CORE_disconnect (coreAPI);
5062 coreAPI = NULL; 5011 coreAPI = NULL;
@@ -5077,8 +5026,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
5077 if (datacache != NULL) 5026 if (datacache != NULL)
5078 { 5027 {
5079#if DEBUG_DHT 5028#if DEBUG_DHT
5080 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5029 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s:%s Destroying datacache!\n",
5081 "%s:%s Destroying datacache!\n", my_short_id, "DHT"); 5030 my_short_id, "DHT");
5082#endif 5031#endif
5083 GNUNET_DATACACHE_destroy (datacache); 5032 GNUNET_DATACACHE_destroy (datacache);
5084 datacache = NULL; 5033 datacache = NULL;
@@ -5112,8 +5061,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
5112 * @param publicKey the public key of this peer 5061 * @param publicKey the public key of this peer
5113 */ 5062 */
5114void 5063void
5115core_init (void *cls, 5064core_init (void *cls, struct GNUNET_CORE_Handle *server,
5116 struct GNUNET_CORE_Handle *server,
5117 const struct GNUNET_PeerIdentity *identity, 5065 const struct GNUNET_PeerIdentity *identity,
5118 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) 5066 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
5119{ 5067{
@@ -5121,9 +5069,8 @@ core_init (void *cls,
5121 if (server == NULL) 5069 if (server == NULL)
5122 { 5070 {
5123#if DEBUG_DHT 5071#if DEBUG_DHT
5124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5072 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s: Connection to core FAILED!\n",
5125 "%s: Connection to core FAILED!\n", "dht", 5073 "dht", GNUNET_i2s (identity));
5126 GNUNET_i2s (identity));
5127#endif 5074#endif
5128 GNUNET_SCHEDULER_cancel (cleanup_task); 5075 GNUNET_SCHEDULER_cancel (cleanup_task);
5129 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 5076 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
@@ -5175,8 +5122,7 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = {
5175 * @param atsi performance data 5122 * @param atsi performance data
5176 */ 5123 */
5177static void 5124static void
5178handle_core_connect (void *cls, 5125handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
5179 const struct GNUNET_PeerIdentity *peer,
5180 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 5126 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
5181{ 5127{
5182 struct PeerInfo *ret; 5128 struct PeerInfo *ret;
@@ -5242,8 +5188,8 @@ handle_core_connect (void *cls,
5242 if ((GNUNET_CRYPTO_hash_matching_bits 5188 if ((GNUNET_CRYPTO_hash_matching_bits
5243 (&my_identity.hashPubKey, &peer->hashPubKey) > 0) && 5189 (&my_identity.hashPubKey, &peer->hashPubKey) > 0) &&
5244 (k_buckets[peer_bucket].peers_size <= bucket_size)) 5190 (k_buckets[peer_bucket].peers_size <= bucket_size))
5245 ret->preference_task = GNUNET_SCHEDULER_add_now (&update_core_preference, 5191 ret->preference_task =
5246 ret); 5192 GNUNET_SCHEDULER_add_now (&update_core_preference, ret);
5247#endif 5193#endif
5248 if ((k_buckets[lowest_bucket].peers_size) >= bucket_size) 5194 if ((k_buckets[lowest_bucket].peers_size) >= bucket_size)
5249 enable_next_bucket (); 5195 enable_next_bucket ();
@@ -5251,8 +5197,7 @@ handle_core_connect (void *cls,
5251 schedule_ping_messages (); 5197 schedule_ping_messages ();
5252#endif 5198#endif
5253 newly_found_peers++; 5199 newly_found_peers++;
5254 GNUNET_CONTAINER_multihashmap_put (all_known_peers, &peer->hashPubKey, 5200 GNUNET_CONTAINER_multihashmap_put (all_known_peers, &peer->hashPubKey, ret,
5255 ret,
5256 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 5201 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
5257 increment_stats (STAT_PEERS_KNOWN); 5202 increment_stats (STAT_PEERS_KNOWN);
5258 5203
@@ -5324,8 +5269,7 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
5324 * @param c configuration to use 5269 * @param c configuration to use
5325 */ 5270 */
5326static void 5271static void
5327run (void *cls, 5272run (void *cls, struct GNUNET_SERVER_Handle *server,
5328 struct GNUNET_SERVER_Handle *server,
5329 const struct GNUNET_CONFIGURATION_Handle *c) 5273 const struct GNUNET_CONFIGURATION_Handle *c)
5330{ 5274{
5331 struct GNUNET_TIME_Relative next_send_time; 5275 struct GNUNET_TIME_Relative next_send_time;
@@ -5351,8 +5295,8 @@ run (void *cls,
5351 5295
5352 if (coreAPI == NULL) 5296 if (coreAPI == NULL)
5353 return; 5297 return;
5354 transport_handle = GNUNET_TRANSPORT_connect (cfg, 5298 transport_handle =
5355 NULL, NULL, NULL, NULL, NULL); 5299 GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL, NULL, NULL);
5356 if (transport_handle != NULL) 5300 if (transport_handle != NULL)
5357 GNUNET_TRANSPORT_get_hello (transport_handle, &process_hello, NULL); 5301 GNUNET_TRANSPORT_get_hello (transport_handle, &process_hello, NULL);
5358 else 5302 else
@@ -5397,21 +5341,21 @@ run (void *cls,
5397 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "malicious_getter")) 5341 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "malicious_getter"))
5398 { 5342 {
5399 malicious_getter = GNUNET_YES; 5343 malicious_getter = GNUNET_YES;
5400 if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT", 5344 if (GNUNET_NO ==
5401 "MALICIOUS_GET_FREQUENCY", 5345 GNUNET_CONFIGURATION_get_value_number (cfg, "DHT",
5402 &malicious_get_frequency)) 5346 "MALICIOUS_GET_FREQUENCY",
5347 &malicious_get_frequency))
5403 malicious_get_frequency = DEFAULT_MALICIOUS_GET_FREQUENCY; 5348 malicious_get_frequency = DEFAULT_MALICIOUS_GET_FREQUENCY;
5404 } 5349 }
5405 5350
5406 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_number (cfg, "DHT", 5351 if (GNUNET_YES !=
5407 "MAX_HOPS", 5352 GNUNET_CONFIGURATION_get_value_number (cfg, "DHT", "MAX_HOPS", &max_hops))
5408 &max_hops))
5409 { 5353 {
5410 max_hops = DEFAULT_MAX_HOPS; 5354 max_hops = DEFAULT_MAX_HOPS;
5411 } 5355 }
5412 5356
5413 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg, "DHT", 5357 if (GNUNET_YES ==
5414 "USE_MAX_HOPS")) 5358 GNUNET_CONFIGURATION_get_value_yesno (cfg, "DHT", "USE_MAX_HOPS"))
5415 { 5359 {
5416 use_max_hops = GNUNET_YES; 5360 use_max_hops = GNUNET_YES;
5417 } 5361 }
@@ -5420,9 +5364,10 @@ run (void *cls,
5420 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "malicious_putter")) 5364 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "malicious_putter"))
5421 { 5365 {
5422 malicious_putter = GNUNET_YES; 5366 malicious_putter = GNUNET_YES;
5423 if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT", 5367 if (GNUNET_NO ==
5424 "MALICIOUS_PUT_FREQUENCY", 5368 GNUNET_CONFIGURATION_get_value_number (cfg, "DHT",
5425 &malicious_put_frequency)) 5369 "MALICIOUS_PUT_FREQUENCY",
5370 &malicious_put_frequency))
5426 malicious_put_frequency = DEFAULT_MALICIOUS_PUT_FREQUENCY; 5371 malicious_put_frequency = DEFAULT_MALICIOUS_PUT_FREQUENCY;
5427 } 5372 }
5428 5373
@@ -5570,19 +5515,21 @@ run (void *cls,
5570 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 5515 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
5571 if (GNUNET_YES == do_find_peer) 5516 if (GNUNET_YES == do_find_peer)
5572 { 5517 {
5573 next_send_time.rel_value = DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value + 5518 next_send_time.rel_value =
5519 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value +
5574 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, 5520 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
5575 (DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value / 5521 (DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value /
5576 2) - 5522 2) -
5577 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value); 5523 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value);
5578 find_peer_context.start = GNUNET_TIME_absolute_get (); 5524 find_peer_context.start = GNUNET_TIME_absolute_get ();
5579 GNUNET_SCHEDULER_add_delayed (next_send_time, 5525 GNUNET_SCHEDULER_add_delayed (next_send_time, &send_find_peer_message,
5580 &send_find_peer_message, &find_peer_context); 5526 &find_peer_context);
5581 } 5527 }
5582 5528
5583 /* Scheduled the task to clean up when shutdown is called */ 5529 /* Scheduled the task to clean up when shutdown is called */
5584 cleanup_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 5530 cleanup_task =
5585 &shutdown_task, NULL); 5531 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
5532 &shutdown_task, NULL);
5586} 5533}
5587 5534
5588/** 5535/**
@@ -5597,11 +5544,10 @@ main (int argc, char *const *argv)
5597{ 5544{
5598 int ret; 5545 int ret;
5599 5546
5600 ret = (GNUNET_OK == 5547 ret =
5601 GNUNET_SERVICE_run (argc, 5548 (GNUNET_OK ==
5602 argv, 5549 GNUNET_SERVICE_run (argc, argv, "dht", GNUNET_SERVICE_OPTION_NONE, &run,
5603 "dht", 5550 NULL)) ? 0 : 1;
5604 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
5605 if (NULL != recent.hashmap) 5551 if (NULL != recent.hashmap)
5606 { 5552 {
5607 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (recent.hashmap)); 5553 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (recent.hashmap));
diff --git a/src/dht/plugin_dhtlog_dummy.c b/src/dht/plugin_dhtlog_dummy.c
index 2250c0330..a411c5934 100644
--- a/src/dht/plugin_dhtlog_dummy.c
+++ b/src/dht/plugin_dhtlog_dummy.c
@@ -135,8 +135,8 @@ update_trials (unsigned int gets_succeeded)
135 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 135 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
136 */ 136 */
137int 137int
138add_generic_stat (const struct GNUNET_PeerIdentity *peer, 138add_generic_stat (const struct GNUNET_PeerIdentity *peer, const char *name,
139 const char *name, const char *section, uint64_t value) 139 const char *section, uint64_t value)
140{ 140{
141 return GNUNET_OK; 141 return GNUNET_OK;
142} 142}
@@ -193,9 +193,8 @@ add_query (unsigned long long *sqlqueryuid, unsigned long long queryid,
193 */ 193 */
194int 194int
195add_route (unsigned long long *sqlqueryuid, unsigned long long queryid, 195add_route (unsigned long long *sqlqueryuid, unsigned long long queryid,
196 unsigned int type, unsigned int hops, 196 unsigned int type, unsigned int hops, int succeeded,
197 int succeeded, const struct GNUNET_PeerIdentity *node, 197 const struct GNUNET_PeerIdentity *node, const GNUNET_HashCode * key,
198 const GNUNET_HashCode * key,
199 const struct GNUNET_PeerIdentity *from_node, 198 const struct GNUNET_PeerIdentity *from_node,
200 const struct GNUNET_PeerIdentity *to_node) 199 const struct GNUNET_PeerIdentity *to_node)
201{ 200{
@@ -282,16 +281,18 @@ set_malicious (struct GNUNET_PeerIdentity *peer)
282 * 281 *
283 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 282 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
284 */ 283 */
285int insert_stat 284int insert_stat (const struct GNUNET_PeerIdentity *peer,
286 (const struct GNUNET_PeerIdentity *peer, unsigned int route_requests, 285 unsigned int route_requests, unsigned int route_forwards,
287 unsigned int route_forwards, unsigned int result_requests, 286 unsigned int result_requests, unsigned int client_requests,
288 unsigned int client_requests, unsigned int result_forwards, 287 unsigned int result_forwards, unsigned int gets,
289 unsigned int gets, unsigned int puts, 288 unsigned int puts, unsigned int data_inserts,
290 unsigned int data_inserts, unsigned int find_peer_requests, 289 unsigned int find_peer_requests,
291 unsigned int find_peers_started, unsigned int gets_started, 290 unsigned int find_peers_started, unsigned int gets_started,
292 unsigned int puts_started, unsigned int find_peer_responses_received, 291 unsigned int puts_started,
293 unsigned int get_responses_received, unsigned int find_peer_responses_sent, 292 unsigned int find_peer_responses_received,
294 unsigned int get_responses_sent) 293 unsigned int get_responses_received,
294 unsigned int find_peer_responses_sent,
295 unsigned int get_responses_sent)
295{ 296{
296 return GNUNET_OK; 297 return GNUNET_OK;
297} 298}
diff --git a/src/dht/plugin_dhtlog_mysql.c b/src/dht/plugin_dhtlog_mysql.c
index c653f912a..33028fb09 100644
--- a/src/dht/plugin_dhtlog_mysql.c
+++ b/src/dht/plugin_dhtlog_mysql.c
@@ -73,8 +73,7 @@ struct StatementHandle
73 * @param values values returned by MySQL 73 * @param values values returned by MySQL
74 * @return GNUNET_OK to continue iterating, GNUNET_SYSERR to abort 74 * @return GNUNET_OK to continue iterating, GNUNET_SYSERR to abort
75 */ 75 */
76typedef int (*GNUNET_MysqlDataProcessor) (void *cls, 76typedef int (*GNUNET_MysqlDataProcessor) (void *cls, unsigned int num_values,
77 unsigned int num_values,
78 MYSQL_BIND * values); 77 MYSQL_BIND * values);
79 78
80static unsigned long max_varchar_len; 79static unsigned long max_varchar_len;
@@ -203,128 +202,121 @@ itable ()
203{ 202{
204#define MRUNS(a) (GNUNET_OK != run_statement (a) ) 203#define MRUNS(a) (GNUNET_OK != run_statement (a) )
205 204
206 if (MRUNS ("CREATE TABLE IF NOT EXISTS `dhtkeys` (" 205 if (MRUNS
207 "dhtkeyuid int(10) unsigned NOT NULL auto_increment COMMENT 'Unique Key given to each query'," 206 ("CREATE TABLE IF NOT EXISTS `dhtkeys` ("
208 "`dhtkey` varchar(255) NOT NULL COMMENT 'The ASCII value of the key being searched for'," 207 "dhtkeyuid int(10) unsigned NOT NULL auto_increment COMMENT 'Unique Key given to each query',"
209 "trialuid int(10) unsigned NOT NULL," 208 "`dhtkey` varchar(255) NOT NULL COMMENT 'The ASCII value of the key being searched for',"
210 "keybits blob NOT NULL," 209 "trialuid int(10) unsigned NOT NULL," "keybits blob NOT NULL,"
211 "UNIQUE KEY `dhtkeyuid` (`dhtkeyuid`)" 210 "UNIQUE KEY `dhtkeyuid` (`dhtkeyuid`)"
212 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1")) 211 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"))
213 return GNUNET_SYSERR; 212 return GNUNET_SYSERR;
214 213
215 if (MRUNS ("CREATE TABLE IF NOT EXISTS `nodes` (" 214 if (MRUNS
216 "`nodeuid` int(10) unsigned NOT NULL auto_increment," 215 ("CREATE TABLE IF NOT EXISTS `nodes` ("
217 "`trialuid` int(10) unsigned NOT NULL," 216 "`nodeuid` int(10) unsigned NOT NULL auto_increment,"
218 "`nodeid` varchar(255) NOT NULL," 217 "`trialuid` int(10) unsigned NOT NULL," "`nodeid` varchar(255) NOT NULL,"
219 "`nodebits` blob NOT NULL," 218 "`nodebits` blob NOT NULL," "PRIMARY KEY (`nodeuid`)"
220 "PRIMARY KEY (`nodeuid`)" 219 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"))
221 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"))
222 return GNUNET_SYSERR; 220 return GNUNET_SYSERR;
223 221
224 if (MRUNS ("CREATE TABLE IF NOT EXISTS `queries` (" 222 if (MRUNS
225 "`trialuid` int(10) unsigned NOT NULL," 223 ("CREATE TABLE IF NOT EXISTS `queries` ("
226 "`queryuid` int(10) unsigned NOT NULL auto_increment," 224 "`trialuid` int(10) unsigned NOT NULL,"
227 "`dhtqueryid` bigint(20) NOT NULL," 225 "`queryuid` int(10) unsigned NOT NULL auto_increment,"
228 "`querytype` enum('1','2','3','4','5') NOT NULL," 226 "`dhtqueryid` bigint(20) NOT NULL,"
229 "`hops` int(10) unsigned NOT NULL," 227 "`querytype` enum('1','2','3','4','5') NOT NULL,"
230 "`succeeded` tinyint NOT NULL," 228 "`hops` int(10) unsigned NOT NULL," "`succeeded` tinyint NOT NULL,"
231 "`nodeuid` int(10) unsigned NOT NULL," 229 "`nodeuid` int(10) unsigned NOT NULL,"
232 "`time` timestamp NOT NULL default CURRENT_TIMESTAMP," 230 "`time` timestamp NOT NULL default CURRENT_TIMESTAMP,"
233 "`dhtkeyuid` int(10) unsigned NOT NULL," 231 "`dhtkeyuid` int(10) unsigned NOT NULL," "PRIMARY KEY (`queryuid`)"
234 "PRIMARY KEY (`queryuid`)" 232 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"))
235 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"))
236 return GNUNET_SYSERR; 233 return GNUNET_SYSERR;
237 234
238 if (MRUNS ("CREATE TABLE IF NOT EXISTS `routes` (" 235 if (MRUNS
239 "`trialuid` int(10) unsigned NOT NULL," 236 ("CREATE TABLE IF NOT EXISTS `routes` ("
240 "`queryuid` int(10) unsigned NOT NULL auto_increment," 237 "`trialuid` int(10) unsigned NOT NULL,"
241 "`dhtqueryid` bigint(20) NOT NULL," 238 "`queryuid` int(10) unsigned NOT NULL auto_increment,"
242 "`querytype` enum('1','2','3','4','5') NOT NULL," 239 "`dhtqueryid` bigint(20) NOT NULL,"
243 "`hops` int(10) unsigned NOT NULL," 240 "`querytype` enum('1','2','3','4','5') NOT NULL,"
244 "`succeeded` tinyint NOT NULL," 241 "`hops` int(10) unsigned NOT NULL," "`succeeded` tinyint NOT NULL,"
245 "`nodeuid` int(10) unsigned NOT NULL," 242 "`nodeuid` int(10) unsigned NOT NULL,"
246 "`time` timestamp NOT NULL default CURRENT_TIMESTAMP," 243 "`time` timestamp NOT NULL default CURRENT_TIMESTAMP,"
247 "`dhtkeyuid` int(10) unsigned NOT NULL," 244 "`dhtkeyuid` int(10) unsigned NOT NULL,"
248 "`from_node` int(10) unsigned NOT NULL," 245 "`from_node` int(10) unsigned NOT NULL,"
249 "`to_node` int(10) unsigned NOT NULL," 246 "`to_node` int(10) unsigned NOT NULL," "PRIMARY KEY (`queryuid`)"
250 "PRIMARY KEY (`queryuid`)" 247 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"))
251 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"))
252 return GNUNET_SYSERR; 248 return GNUNET_SYSERR;
253 249
254 if (MRUNS ("CREATE TABLE IF NOT EXISTS `trials` (" 250 if (MRUNS
255 "`trialuid` int(10) unsigned NOT NULL auto_increment," 251 ("CREATE TABLE IF NOT EXISTS `trials` ("
256 "`other_trial_identifier` int(10) unsigned NOT NULL default '0'," 252 "`trialuid` int(10) unsigned NOT NULL auto_increment,"
257 "`numnodes` int(10) unsigned NOT NULL," 253 "`other_trial_identifier` int(10) unsigned NOT NULL default '0',"
258 "`topology` int(10) NOT NULL," 254 "`numnodes` int(10) unsigned NOT NULL," "`topology` int(10) NOT NULL,"
259 "`blacklist_topology` int(11) NOT NULL," 255 "`blacklist_topology` int(11) NOT NULL,"
260 "`connect_topology` int(11) NOT NULL," 256 "`connect_topology` int(11) NOT NULL,"
261 "`connect_topology_option` int(11) NOT NULL," 257 "`connect_topology_option` int(11) NOT NULL,"
262 "`topology_percentage` float NOT NULL," 258 "`topology_percentage` float NOT NULL,"
263 "`topology_probability` float NOT NULL," 259 "`topology_probability` float NOT NULL,"
264 "`connect_topology_option_modifier` float NOT NULL," 260 "`connect_topology_option_modifier` float NOT NULL,"
265 "`starttime` datetime NOT NULL," 261 "`starttime` datetime NOT NULL," "`endtime` datetime NOT NULL,"
266 "`endtime` datetime NOT NULL," 262 "`puts` int(10) unsigned NOT NULL," "`gets` int(10) unsigned NOT NULL,"
267 "`puts` int(10) unsigned NOT NULL," 263 "`concurrent` int(10) unsigned NOT NULL,"
268 "`gets` int(10) unsigned NOT NULL," 264 "`settle_time` int(10) unsigned NOT NULL,"
269 "`concurrent` int(10) unsigned NOT NULL," 265 "`totalConnections` int(10) unsigned NOT NULL,"
270 "`settle_time` int(10) unsigned NOT NULL," 266 "`message` text NOT NULL," "`num_rounds` int(10) unsigned NOT NULL,"
271 "`totalConnections` int(10) unsigned NOT NULL," 267 "`malicious_getters` int(10) unsigned NOT NULL,"
272 "`message` text NOT NULL," 268 "`malicious_putters` int(10) unsigned NOT NULL,"
273 "`num_rounds` int(10) unsigned NOT NULL," 269 "`malicious_droppers` int(10) unsigned NOT NULL,"
274 "`malicious_getters` int(10) unsigned NOT NULL," 270 "`topology_modifier` double NOT NULL,"
275 "`malicious_putters` int(10) unsigned NOT NULL," 271 "`malicious_get_frequency` int(10) unsigned NOT NULL,"
276 "`malicious_droppers` int(10) unsigned NOT NULL," 272 "`malicious_put_frequency` int(10) unsigned NOT NULL,"
277 "`topology_modifier` double NOT NULL," 273 "`stop_closest` int(10) unsigned NOT NULL,"
278 "`malicious_get_frequency` int(10) unsigned NOT NULL," 274 "`stop_found` int(10) unsigned NOT NULL,"
279 "`malicious_put_frequency` int(10) unsigned NOT NULL," 275 "`strict_kademlia` int(10) unsigned NOT NULL,"
280 "`stop_closest` int(10) unsigned NOT NULL," 276 "`gets_succeeded` int(10) unsigned NOT NULL,"
281 "`stop_found` int(10) unsigned NOT NULL," 277 "PRIMARY KEY (`trialuid`)," "UNIQUE KEY `trialuid` (`trialuid`)"
282 "`strict_kademlia` int(10) unsigned NOT NULL," 278 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"))
283 "`gets_succeeded` int(10) unsigned NOT NULL,"
284 "PRIMARY KEY (`trialuid`),"
285 "UNIQUE KEY `trialuid` (`trialuid`)"
286 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"))
287 return GNUNET_SYSERR; 279 return GNUNET_SYSERR;
288 280
289 if (MRUNS ("CREATE TABLE IF NOT EXISTS `topology` (" 281 if (MRUNS
290 "`topology_uid` int(10) unsigned NOT NULL AUTO_INCREMENT," 282 ("CREATE TABLE IF NOT EXISTS `topology` ("
291 "`trialuid` int(10) unsigned NOT NULL," 283 "`topology_uid` int(10) unsigned NOT NULL AUTO_INCREMENT,"
292 "`date` datetime NOT NULL," 284 "`trialuid` int(10) unsigned NOT NULL," "`date` datetime NOT NULL,"
293 "`connections` int(10) unsigned NOT NULL," 285 "`connections` int(10) unsigned NOT NULL,"
294 "PRIMARY KEY (`topology_uid`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1")) 286 "PRIMARY KEY (`topology_uid`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"))
295 return GNUNET_SYSERR; 287 return GNUNET_SYSERR;
296 288
297 if (MRUNS ("CREATE TABLE IF NOT EXISTS `extended_topology` (" 289 if (MRUNS
298 "`extended_uid` int(10) unsigned NOT NULL AUTO_INCREMENT," 290 ("CREATE TABLE IF NOT EXISTS `extended_topology` ("
299 "`topology_uid` int(10) unsigned NOT NULL," 291 "`extended_uid` int(10) unsigned NOT NULL AUTO_INCREMENT,"
300 "`uid_first` int(10) unsigned NOT NULL," 292 "`topology_uid` int(10) unsigned NOT NULL,"
301 "`uid_second` int(10) unsigned NOT NULL," 293 "`uid_first` int(10) unsigned NOT NULL,"
302 "PRIMARY KEY (`extended_uid`)" 294 "`uid_second` int(10) unsigned NOT NULL," "PRIMARY KEY (`extended_uid`)"
303 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1")) 295 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"))
304 return GNUNET_SYSERR; 296 return GNUNET_SYSERR;
305 297
306 if (MRUNS ("CREATE TABLE IF NOT EXISTS `node_statistics` (" 298 if (MRUNS
307 "`stat_uid` int(10) unsigned NOT NULL AUTO_INCREMENT," 299 ("CREATE TABLE IF NOT EXISTS `node_statistics` ("
308 "`trialuid` int(10) unsigned NOT NULL," 300 "`stat_uid` int(10) unsigned NOT NULL AUTO_INCREMENT,"
309 "`nodeuid` int(10) unsigned NOT NULL," 301 "`trialuid` int(10) unsigned NOT NULL,"
310 "`route_requests` int(10) unsigned NOT NULL," 302 "`nodeuid` int(10) unsigned NOT NULL,"
311 "`route_forwards` int(10) unsigned NOT NULL," 303 "`route_requests` int(10) unsigned NOT NULL,"
312 "`result_requests` int(10) unsigned NOT NULL," 304 "`route_forwards` int(10) unsigned NOT NULL,"
313 "`client_results` int(10) unsigned NOT NULL," 305 "`result_requests` int(10) unsigned NOT NULL,"
314 "`result_forwards` int(10) unsigned NOT NULL," 306 "`client_results` int(10) unsigned NOT NULL,"
315 "`gets` int(10) unsigned NOT NULL," 307 "`result_forwards` int(10) unsigned NOT NULL,"
316 "`puts` int(10) unsigned NOT NULL," 308 "`gets` int(10) unsigned NOT NULL," "`puts` int(10) unsigned NOT NULL,"
317 "`data_inserts` int(10) unsigned NOT NULL," 309 "`data_inserts` int(10) unsigned NOT NULL,"
318 "`find_peer_requests` int(10) unsigned NOT NULL," 310 "`find_peer_requests` int(10) unsigned NOT NULL,"
319 "`find_peers_started` int(10) unsigned NOT NULL," 311 "`find_peers_started` int(10) unsigned NOT NULL,"
320 "`gets_started` int(10) unsigned NOT NULL," 312 "`gets_started` int(10) unsigned NOT NULL,"
321 "`puts_started` int(10) unsigned NOT NULL," 313 "`puts_started` int(10) unsigned NOT NULL,"
322 "`find_peer_responses_received` int(10) unsigned NOT NULL," 314 "`find_peer_responses_received` int(10) unsigned NOT NULL,"
323 "`get_responses_received` int(10) unsigned NOT NULL," 315 "`get_responses_received` int(10) unsigned NOT NULL,"
324 "`find_peer_responses_sent` int(10) unsigned NOT NULL," 316 "`find_peer_responses_sent` int(10) unsigned NOT NULL,"
325 "`get_responses_sent` int(10) unsigned NOT NULL," 317 "`get_responses_sent` int(10) unsigned NOT NULL,"
326 "PRIMARY KEY (`stat_uid`)" 318 "PRIMARY KEY (`stat_uid`)"
327 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;")) 319 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"))
328 return GNUNET_SYSERR; 320 return GNUNET_SYSERR;
329 321
330 if (MRUNS ("SET AUTOCOMMIT = 1")) 322 if (MRUNS ("SET AUTOCOMMIT = 1"))
@@ -388,37 +380,37 @@ iopen (struct GNUNET_DHTLOG_Plugin *plugin)
388 if (conn == NULL) 380 if (conn == NULL)
389 return GNUNET_SYSERR; 381 return GNUNET_SYSERR;
390 382
391 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg, 383 if (GNUNET_OK !=
392 "MYSQL", "DATABASE", 384 GNUNET_CONFIGURATION_get_value_string (plugin->cfg, "MYSQL", "DATABASE",
393 &database)) 385 &database))
394 { 386 {
395 database = GNUNET_strdup ("gnunet"); 387 database = GNUNET_strdup ("gnunet");
396 } 388 }
397 389
398 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg, 390 if (GNUNET_OK !=
399 "MYSQL", "USER", 391 GNUNET_CONFIGURATION_get_value_string (plugin->cfg, "MYSQL", "USER",
400 &user)) 392 &user))
401 { 393 {
402 user = GNUNET_strdup ("dht"); 394 user = GNUNET_strdup ("dht");
403 } 395 }
404 396
405 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg, 397 if (GNUNET_OK !=
406 "MYSQL", "PASSWORD", 398 GNUNET_CONFIGURATION_get_value_string (plugin->cfg, "MYSQL", "PASSWORD",
407 &password)) 399 &password))
408 { 400 {
409 password = GNUNET_strdup ("dhttest**"); 401 password = GNUNET_strdup ("dhttest**");
410 } 402 }
411 403
412 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg, 404 if (GNUNET_OK !=
413 "MYSQL", "SERVER", 405 GNUNET_CONFIGURATION_get_value_string (plugin->cfg, "MYSQL", "SERVER",
414 &server)) 406 &server))
415 { 407 {
416 server = GNUNET_strdup ("localhost"); 408 server = GNUNET_strdup ("localhost");
417 } 409 }
418 410
419 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (plugin->cfg, 411 if (GNUNET_OK !=
420 "MYSQL", "MYSQL_PORT", 412 GNUNET_CONFIGURATION_get_value_number (plugin->cfg, "MYSQL", "MYSQL_PORT",
421 &port)) 413 &port))
422 { 414 {
423 port = 0; 415 port = 0;
424 } 416 }
@@ -434,9 +426,8 @@ iopen (struct GNUNET_DHTLOG_Plugin *plugin)
434 mysql_options (conn, MYSQL_SET_CHARSET_NAME, "UTF8"); 426 mysql_options (conn, MYSQL_SET_CHARSET_NAME, "UTF8");
435 mysql_options (conn, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout); 427 mysql_options (conn, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout);
436 mysql_options (conn, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout); 428 mysql_options (conn, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout);
437 mysql_real_connect (conn, server, user, password, 429 mysql_real_connect (conn, server, user, password, database,
438 database, (unsigned int) port, NULL, 430 (unsigned int) port, NULL, CLIENT_IGNORE_SIGPIPE);
439 CLIENT_IGNORE_SIGPIPE);
440 431
441 GNUNET_free_non_null (server); 432 GNUNET_free_non_null (server);
442 GNUNET_free_non_null (password); 433 GNUNET_free_non_null (password);
@@ -508,8 +499,8 @@ prepare_statement (struct StatementHandle *ret)
508 499
509 if (mysql_stmt_prepare (ret->statement, ret->query, strlen (ret->query))) 500 if (mysql_stmt_prepare (ret->statement, ret->query, strlen (ret->query)))
510 { 501 {
511 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 502 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "mysql_stmt_prepare `%s', %s",
512 "mysql_stmt_prepare `%s', %s", ret->query, mysql_error (conn)); 503 ret->query, mysql_error (conn));
513 mysql_stmt_close (ret->statement); 504 mysql_stmt_close (ret->statement);
514 ret->statement = NULL; 505 ret->statement = NULL;
515 return GNUNET_SYSERR; 506 return GNUNET_SYSERR;
@@ -588,8 +579,8 @@ init_params (struct StatementHandle *s, va_list ap)
588 { 579 {
589 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 580 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
590 _("`%s' failed at %s:%d with error: %s\n"), 581 _("`%s' failed at %s:%d with error: %s\n"),
591 "mysql_stmt_bind_param", 582 "mysql_stmt_bind_param", __FILE__, __LINE__,
592 __FILE__, __LINE__, mysql_stmt_error (s->statement)); 583 mysql_stmt_error (s->statement));
593 return GNUNET_SYSERR; 584 return GNUNET_SYSERR;
594 } 585 }
595 586
@@ -597,8 +588,8 @@ init_params (struct StatementHandle *s, va_list ap)
597 { 588 {
598 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 589 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
599 _("`%s' failed at %s:%d with error: %s\n"), 590 _("`%s' failed at %s:%d with error: %s\n"),
600 "mysql_stmt_execute", 591 "mysql_stmt_execute", __FILE__, __LINE__,
601 __FILE__, __LINE__, mysql_stmt_error (s->statement)); 592 mysql_stmt_error (s->statement));
602 return GNUNET_SYSERR; 593 return GNUNET_SYSERR;
603 } 594 }
604 595
@@ -623,10 +614,9 @@ init_params (struct StatementHandle *s, va_list ap)
623 */ 614 */
624int 615int
625prepared_statement_run_select (struct StatementHandle *s, 616prepared_statement_run_select (struct StatementHandle *s,
626 unsigned int result_size, 617 unsigned int result_size, MYSQL_BIND * results,
627 MYSQL_BIND * results, 618 GNUNET_MysqlDataProcessor processor,
628 GNUNET_MysqlDataProcessor 619 void *processor_cls, ...)
629 processor, void *processor_cls, ...)
630{ 620{
631 va_list ap; 621 va_list ap;
632 int ret; 622 int ret;
@@ -656,8 +646,8 @@ prepared_statement_run_select (struct StatementHandle *s,
656 { 646 {
657 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 647 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
658 _("`%s' failed at %s:%d with error: %s\n"), 648 _("`%s' failed at %s:%d with error: %s\n"),
659 "mysql_stmt_bind_result", 649 "mysql_stmt_bind_result", __FILE__, __LINE__,
660 __FILE__, __LINE__, mysql_stmt_error (s->statement)); 650 mysql_stmt_error (s->statement));
661 return GNUNET_SYSERR; 651 return GNUNET_SYSERR;
662 } 652 }
663 653
@@ -671,8 +661,8 @@ prepared_statement_run_select (struct StatementHandle *s,
671 { 661 {
672 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 662 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
673 _("`%s' failed at %s:%d with error: %s\n"), 663 _("`%s' failed at %s:%d with error: %s\n"),
674 "mysql_stmt_fetch", 664 "mysql_stmt_fetch", __FILE__, __LINE__,
675 __FILE__, __LINE__, mysql_stmt_error (s->statement)); 665 mysql_stmt_error (s->statement));
676 return GNUNET_SYSERR; 666 return GNUNET_SYSERR;
677 } 667 }
678 if (processor != NULL) 668 if (processor != NULL)
@@ -700,17 +690,11 @@ get_node_uid (unsigned long long *nodeuid, const GNUNET_HashCode * peerHash)
700 GNUNET_CRYPTO_hash_to_enc (peerHash, &encPeer); 690 GNUNET_CRYPTO_hash_to_enc (peerHash, &encPeer);
701 p_len = strlen ((char *) &encPeer); 691 p_len = strlen ((char *) &encPeer);
702 692
703 if (1 != prepared_statement_run_select (get_nodeuid, 693 if (1 !=
704 1, 694 prepared_statement_run_select (get_nodeuid, 1, rbind, return_ok, NULL,
705 rbind, 695 MYSQL_TYPE_LONGLONG, &current_trial,
706 return_ok, 696 GNUNET_YES, MYSQL_TYPE_VAR_STRING,
707 NULL, 697 &encPeer, max_varchar_len, &p_len, -1))
708 MYSQL_TYPE_LONGLONG,
709 &current_trial,
710 GNUNET_YES,
711 MYSQL_TYPE_VAR_STRING,
712 &encPeer,
713 max_varchar_len, &p_len, -1))
714 { 698 {
715#if DEBUG_DHTLOG 699#if DEBUG_DHTLOG
716 fprintf (stderr, "FAILED\n"); 700 fprintf (stderr, "FAILED\n");
@@ -731,8 +715,8 @@ get_current_trial (unsigned long long *trialuid)
731 rbind[0].buffer = trialuid; 715 rbind[0].buffer = trialuid;
732 716
733 if ((GNUNET_OK != 717 if ((GNUNET_OK !=
734 prepared_statement_run_select (get_trial, 718 prepared_statement_run_select (get_trial, 1, rbind, return_ok, NULL,
735 1, rbind, return_ok, NULL, -1))) 719 -1)))
736 { 720 {
737 return GNUNET_SYSERR; 721 return GNUNET_SYSERR;
738 } 722 }
@@ -751,8 +735,8 @@ get_current_topology (unsigned long long *topologyuid)
751 rbind[0].buffer = topologyuid; 735 rbind[0].buffer = topologyuid;
752 736
753 if ((GNUNET_OK != 737 if ((GNUNET_OK !=
754 prepared_statement_run_select (get_topology, 738 prepared_statement_run_select (get_topology, 1, rbind, return_ok, NULL,
755 1, rbind, return_ok, NULL, -1))) 739 -1)))
756 { 740 {
757 return GNUNET_SYSERR; 741 return GNUNET_SYSERR;
758 } 742 }
@@ -779,16 +763,11 @@ get_dhtkey_uid (unsigned long long *dhtkeyuid, const GNUNET_HashCode * key)
779 current_trial); 763 current_trial);
780#endif 764#endif
781 if ((GNUNET_OK != 765 if ((GNUNET_OK !=
782 prepared_statement_run_select (get_dhtkeyuid, 766 prepared_statement_run_select (get_dhtkeyuid, 1, rbind, return_ok, NULL,
783 1, 767 MYSQL_TYPE_VAR_STRING, &encKey,
784 rbind, 768 max_varchar_len, &k_len,
785 return_ok, NULL, 769 MYSQL_TYPE_LONGLONG, &current_trial,
786 MYSQL_TYPE_VAR_STRING, 770 GNUNET_YES, -1)))
787 &encKey,
788 max_varchar_len,
789 &k_len,
790 MYSQL_TYPE_LONGLONG,
791 &current_trial, GNUNET_YES, -1)))
792 { 771 {
793 return GNUNET_SYSERR; 772 return GNUNET_SYSERR;
794 } 773 }
@@ -860,51 +839,46 @@ add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info)
860 839
861 stmt = mysql_stmt_init (conn); 840 stmt = mysql_stmt_init (conn);
862 if (GNUNET_OK != 841 if (GNUNET_OK !=
863 (ret = prepared_statement_run (insert_trial, &current_trial, 842 (ret =
864 MYSQL_TYPE_LONG, 843 prepared_statement_run (insert_trial, &current_trial, MYSQL_TYPE_LONG,
865 &trial_info->other_identifier, GNUNET_YES, 844 &trial_info->other_identifier, GNUNET_YES,
866 MYSQL_TYPE_LONG, &trial_info->num_nodes, 845 MYSQL_TYPE_LONG, &trial_info->num_nodes,
867 GNUNET_YES, MYSQL_TYPE_LONG, 846 GNUNET_YES, MYSQL_TYPE_LONG,
868 &trial_info->topology, GNUNET_YES, 847 &trial_info->topology, GNUNET_YES,
869 MYSQL_TYPE_FLOAT, 848 MYSQL_TYPE_FLOAT,
870 &trial_info->topology_percentage, 849 &trial_info->topology_percentage,
871 MYSQL_TYPE_FLOAT, 850 MYSQL_TYPE_FLOAT,
872 &trial_info->topology_probability, 851 &trial_info->topology_probability,
873 MYSQL_TYPE_LONG, 852 MYSQL_TYPE_LONG, &trial_info->blacklist_topology,
874 &trial_info->blacklist_topology, 853 GNUNET_YES, MYSQL_TYPE_LONG,
875 GNUNET_YES, MYSQL_TYPE_LONG, 854 &trial_info->connect_topology, GNUNET_YES,
876 &trial_info->connect_topology, GNUNET_YES, 855 MYSQL_TYPE_LONG,
877 MYSQL_TYPE_LONG, 856 &trial_info->connect_topology_option, GNUNET_YES,
878 &trial_info->connect_topology_option, 857 MYSQL_TYPE_FLOAT,
879 GNUNET_YES, MYSQL_TYPE_FLOAT, 858 &trial_info->connect_topology_option_modifier,
880 &trial_info->connect_topology_option_modifier, 859 MYSQL_TYPE_LONG, &trial_info->puts, GNUNET_YES,
881 MYSQL_TYPE_LONG, &trial_info->puts, 860 MYSQL_TYPE_LONG, &trial_info->gets, GNUNET_YES,
882 GNUNET_YES, MYSQL_TYPE_LONG, 861 MYSQL_TYPE_LONG, &trial_info->concurrent,
883 &trial_info->gets, GNUNET_YES, 862 GNUNET_YES, MYSQL_TYPE_LONG,
884 MYSQL_TYPE_LONG, &trial_info->concurrent, 863 &trial_info->settle_time, GNUNET_YES,
885 GNUNET_YES, MYSQL_TYPE_LONG, 864 MYSQL_TYPE_LONG, &trial_info->num_rounds,
886 &trial_info->settle_time, GNUNET_YES, 865 GNUNET_YES, MYSQL_TYPE_LONG,
887 MYSQL_TYPE_LONG, &trial_info->num_rounds, 866 &trial_info->malicious_getters, GNUNET_YES,
888 GNUNET_YES, MYSQL_TYPE_LONG, 867 MYSQL_TYPE_LONG, &trial_info->malicious_putters,
889 &trial_info->malicious_getters, GNUNET_YES, 868 GNUNET_YES, MYSQL_TYPE_LONG,
890 MYSQL_TYPE_LONG, 869 &trial_info->malicious_droppers, GNUNET_YES,
891 &trial_info->malicious_putters, GNUNET_YES, 870 MYSQL_TYPE_LONG,
892 MYSQL_TYPE_LONG, 871 &trial_info->malicious_get_frequency, GNUNET_YES,
893 &trial_info->malicious_droppers, 872 MYSQL_TYPE_LONG,
894 GNUNET_YES, MYSQL_TYPE_LONG, 873 &trial_info->malicious_put_frequency, GNUNET_YES,
895 &trial_info->malicious_get_frequency, 874 MYSQL_TYPE_LONG, &trial_info->stop_closest,
896 GNUNET_YES, MYSQL_TYPE_LONG, 875 GNUNET_YES, MYSQL_TYPE_LONG,
897 &trial_info->malicious_put_frequency, 876 &trial_info->stop_found, GNUNET_YES,
898 GNUNET_YES, MYSQL_TYPE_LONG, 877 MYSQL_TYPE_LONG, &trial_info->strict_kademlia,
899 &trial_info->stop_closest, GNUNET_YES, 878 GNUNET_YES, MYSQL_TYPE_LONG,
900 MYSQL_TYPE_LONG, &trial_info->stop_found, 879 &trial_info->gets_succeeded, GNUNET_YES,
901 GNUNET_YES, MYSQL_TYPE_LONG, 880 MYSQL_TYPE_BLOB, trial_info->message,
902 &trial_info->strict_kademlia, GNUNET_YES, 881 max_varchar_len + max_varchar_len, &m_len, -1)))
903 MYSQL_TYPE_LONG,
904 &trial_info->gets_succeeded, GNUNET_YES,
905 MYSQL_TYPE_BLOB, trial_info->message,
906 max_varchar_len + max_varchar_len, &m_len,
907 -1)))
908 { 882 {
909 if (ret == GNUNET_SYSERR) 883 if (ret == GNUNET_SYSERR)
910 { 884 {
@@ -935,11 +909,11 @@ add_round (unsigned int round_type, unsigned int round_count)
935 int ret; 909 int ret;
936 910
937 stmt = mysql_stmt_init (conn); 911 stmt = mysql_stmt_init (conn);
938 ret = prepared_statement_run (insert_round, 912 ret =
939 NULL, 913 prepared_statement_run (insert_round, NULL, MYSQL_TYPE_LONGLONG,
940 MYSQL_TYPE_LONGLONG, &current_trial, GNUNET_YES, 914 &current_trial, GNUNET_YES, MYSQL_TYPE_LONG,
941 MYSQL_TYPE_LONG, &round_type, GNUNET_YES, 915 &round_type, GNUNET_YES, MYSQL_TYPE_LONG,
942 MYSQL_TYPE_LONG, &round_count, GNUNET_YES, -1); 916 &round_count, GNUNET_YES, -1);
943 mysql_stmt_close (stmt); 917 mysql_stmt_close (stmt);
944 if (ret != GNUNET_OK) 918 if (ret != GNUNET_OK)
945 return GNUNET_SYSERR; 919 return GNUNET_SYSERR;
@@ -966,14 +940,13 @@ add_round_details (unsigned int round_type, unsigned int round_count,
966 int ret; 940 int ret;
967 941
968 stmt = mysql_stmt_init (conn); 942 stmt = mysql_stmt_init (conn);
969 ret = prepared_statement_run (insert_round_details, 943 ret =
970 NULL, 944 prepared_statement_run (insert_round_details, NULL, MYSQL_TYPE_LONGLONG,
971 MYSQL_TYPE_LONGLONG, &current_trial, GNUNET_YES, 945 &current_trial, GNUNET_YES, MYSQL_TYPE_LONG,
972 MYSQL_TYPE_LONG, &round_type, GNUNET_YES, 946 &round_type, GNUNET_YES, MYSQL_TYPE_LONG,
973 MYSQL_TYPE_LONG, &round_count, GNUNET_YES, 947 &round_count, GNUNET_YES, MYSQL_TYPE_LONG,
974 MYSQL_TYPE_LONG, &num_messages, GNUNET_YES, 948 &num_messages, GNUNET_YES, MYSQL_TYPE_LONG,
975 MYSQL_TYPE_LONG, &num_messages_succeeded, 949 &num_messages_succeeded, GNUNET_YES, -1);
976 GNUNET_YES, -1);
977 mysql_stmt_close (stmt); 950 mysql_stmt_close (stmt);
978 if (ret != GNUNET_OK) 951 if (ret != GNUNET_OK)
979 return GNUNET_SYSERR; 952 return GNUNET_SYSERR;
@@ -1007,10 +980,10 @@ int
1007add_stat (const struct GNUNET_PeerIdentity *peer, unsigned int route_requests, 980add_stat (const struct GNUNET_PeerIdentity *peer, unsigned int route_requests,
1008 unsigned int route_forwards, unsigned int result_requests, 981 unsigned int route_forwards, unsigned int result_requests,
1009 unsigned int client_requests, unsigned int result_forwards, 982 unsigned int client_requests, unsigned int result_forwards,
1010 unsigned int gets, unsigned int puts, 983 unsigned int gets, unsigned int puts, unsigned int data_inserts,
1011 unsigned int data_inserts, unsigned int find_peer_requests, 984 unsigned int find_peer_requests, unsigned int find_peers_started,
1012 unsigned int find_peers_started, unsigned int gets_started, 985 unsigned int gets_started, unsigned int puts_started,
1013 unsigned int puts_started, unsigned int find_peer_responses_received, 986 unsigned int find_peer_responses_received,
1014 unsigned int get_responses_received, 987 unsigned int get_responses_received,
1015 unsigned int find_peer_responses_sent, 988 unsigned int find_peer_responses_sent,
1016 unsigned int get_responses_sent) 989 unsigned int get_responses_sent)
@@ -1030,33 +1003,28 @@ add_stat (const struct GNUNET_PeerIdentity *peer, unsigned int route_requests,
1030 1003
1031 stmt = mysql_stmt_init (conn); 1004 stmt = mysql_stmt_init (conn);
1032 if (GNUNET_OK != 1005 if (GNUNET_OK !=
1033 (ret = prepared_statement_run (insert_stat, 1006 (ret =
1034 &return_uid, 1007 prepared_statement_run (insert_stat, &return_uid, MYSQL_TYPE_LONGLONG,
1035 MYSQL_TYPE_LONGLONG, &current_trial, 1008 &current_trial, GNUNET_YES, MYSQL_TYPE_LONGLONG,
1036 GNUNET_YES, MYSQL_TYPE_LONGLONG, &peer_uid, 1009 &peer_uid, GNUNET_YES, MYSQL_TYPE_LONG,
1037 GNUNET_YES, MYSQL_TYPE_LONG, 1010 &route_requests, GNUNET_YES, MYSQL_TYPE_LONG,
1038 &route_requests, GNUNET_YES, 1011 &route_forwards, GNUNET_YES, MYSQL_TYPE_LONG,
1039 MYSQL_TYPE_LONG, &route_forwards, 1012 &result_requests, GNUNET_YES, MYSQL_TYPE_LONG,
1040 GNUNET_YES, MYSQL_TYPE_LONG, 1013 &client_requests, GNUNET_YES, MYSQL_TYPE_LONG,
1041 &result_requests, GNUNET_YES, 1014 &result_forwards, GNUNET_YES, MYSQL_TYPE_LONG,
1042 MYSQL_TYPE_LONG, &client_requests, 1015 &gets, GNUNET_YES, MYSQL_TYPE_LONG, &puts,
1043 GNUNET_YES, MYSQL_TYPE_LONG, 1016 GNUNET_YES, MYSQL_TYPE_LONG, &data_inserts,
1044 &result_forwards, GNUNET_YES, 1017 GNUNET_YES, MYSQL_TYPE_LONG, &find_peer_requests,
1045 MYSQL_TYPE_LONG, &gets, GNUNET_YES, 1018 GNUNET_YES, MYSQL_TYPE_LONG, &find_peers_started,
1046 MYSQL_TYPE_LONG, &puts, GNUNET_YES, 1019 GNUNET_YES, MYSQL_TYPE_LONG, &gets_started,
1047 MYSQL_TYPE_LONG, &data_inserts, GNUNET_YES, 1020 GNUNET_YES, MYSQL_TYPE_LONG, &puts_started,
1048 MYSQL_TYPE_LONG, &find_peer_requests, 1021 GNUNET_YES, MYSQL_TYPE_LONG,
1049 GNUNET_YES, MYSQL_TYPE_LONG, 1022 &find_peer_responses_received, GNUNET_YES,
1050 &find_peers_started, GNUNET_YES, 1023 MYSQL_TYPE_LONG, &get_responses_received,
1051 MYSQL_TYPE_LONG, &gets_started, GNUNET_YES, 1024 GNUNET_YES, MYSQL_TYPE_LONG,
1052 MYSQL_TYPE_LONG, &puts_started, GNUNET_YES, 1025 &find_peer_responses_sent, GNUNET_YES,
1053 MYSQL_TYPE_LONG, 1026 MYSQL_TYPE_LONG, &get_responses_sent, GNUNET_YES,
1054 &find_peer_responses_received, GNUNET_YES, 1027 -1)))
1055 MYSQL_TYPE_LONG, &get_responses_received,
1056 GNUNET_YES, MYSQL_TYPE_LONG,
1057 &find_peer_responses_sent, GNUNET_YES,
1058 MYSQL_TYPE_LONG, &get_responses_sent,
1059 GNUNET_YES, -1)))
1060 { 1028 {
1061 if (ret == GNUNET_SYSERR) 1029 if (ret == GNUNET_SYSERR)
1062 { 1030 {
@@ -1080,8 +1048,8 @@ add_stat (const struct GNUNET_PeerIdentity *peer, unsigned int route_requests,
1080 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 1048 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
1081 */ 1049 */
1082int 1050int
1083add_generic_stat (const struct GNUNET_PeerIdentity *peer, 1051add_generic_stat (const struct GNUNET_PeerIdentity *peer, const char *name,
1084 const char *name, const char *section, uint64_t value) 1052 const char *section, uint64_t value)
1085{ 1053{
1086 unsigned long long peer_uid; 1054 unsigned long long peer_uid;
1087 unsigned long long section_len; 1055 unsigned long long section_len;
@@ -1100,16 +1068,14 @@ add_generic_stat (const struct GNUNET_PeerIdentity *peer,
1100 name_len = strlen (name); 1068 name_len = strlen (name);
1101 1069
1102 if (GNUNET_OK != 1070 if (GNUNET_OK !=
1103 (ret = prepared_statement_run (insert_generic_stat, 1071 (ret =
1104 NULL, 1072 prepared_statement_run (insert_generic_stat, NULL, MYSQL_TYPE_LONGLONG,
1105 MYSQL_TYPE_LONGLONG, &current_trial, 1073 &current_trial, GNUNET_YES, MYSQL_TYPE_LONGLONG,
1106 GNUNET_YES, MYSQL_TYPE_LONGLONG, &peer_uid, 1074 &peer_uid, GNUNET_YES, MYSQL_TYPE_VAR_STRING,
1107 GNUNET_YES, MYSQL_TYPE_VAR_STRING, 1075 &section, max_varchar_len, &section_len,
1108 &section, max_varchar_len, &section_len, 1076 MYSQL_TYPE_VAR_STRING, &name, max_varchar_len,
1109 MYSQL_TYPE_VAR_STRING, &name, 1077 &name_len, MYSQL_TYPE_LONGLONG, &value,
1110 max_varchar_len, &name_len, 1078 GNUNET_YES, -1)))
1111 MYSQL_TYPE_LONGLONG, &value, GNUNET_YES,
1112 -1)))
1113 { 1079 {
1114 if (ret == GNUNET_SYSERR) 1080 if (ret == GNUNET_SYSERR)
1115 { 1081 {
@@ -1157,18 +1123,12 @@ add_dhtkey (unsigned long long *dhtkeyuid, const GNUNET_HashCode * dhtkey)
1157 } 1123 }
1158 1124
1159 if (GNUNET_OK != 1125 if (GNUNET_OK !=
1160 (ret = prepared_statement_run (insert_dhtkey, 1126 (ret =
1161 dhtkeyuid, 1127 prepared_statement_run (insert_dhtkey, dhtkeyuid, MYSQL_TYPE_VAR_STRING,
1162 MYSQL_TYPE_VAR_STRING, 1128 &encKey, max_varchar_len, &k_len,
1163 &encKey, 1129 MYSQL_TYPE_LONG, &current_trial, GNUNET_YES,
1164 max_varchar_len, 1130 MYSQL_TYPE_BLOB, dhtkey,
1165 &k_len, 1131 sizeof (GNUNET_HashCode), &h_len, -1)))
1166 MYSQL_TYPE_LONG,
1167 &current_trial,
1168 GNUNET_YES,
1169 MYSQL_TYPE_BLOB,
1170 dhtkey,
1171 sizeof (GNUNET_HashCode), &h_len, -1)))
1172 { 1132 {
1173 if (ret == GNUNET_SYSERR) 1133 if (ret == GNUNET_SYSERR)
1174 { 1134 {
@@ -1204,13 +1164,12 @@ add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity *node)
1204 p_len = (unsigned long) strlen ((char *) &encPeer); 1164 p_len = (unsigned long) strlen ((char *) &encPeer);
1205 h_len = sizeof (GNUNET_HashCode); 1165 h_len = sizeof (GNUNET_HashCode);
1206 if (GNUNET_OK != 1166 if (GNUNET_OK !=
1207 (ret = prepared_statement_run (insert_node, 1167 (ret =
1208 nodeuid, 1168 prepared_statement_run (insert_node, nodeuid, MYSQL_TYPE_LONGLONG,
1209 MYSQL_TYPE_LONGLONG, &current_trial, 1169 &current_trial, GNUNET_YES,
1210 GNUNET_YES, MYSQL_TYPE_VAR_STRING, 1170 MYSQL_TYPE_VAR_STRING, &encPeer, max_varchar_len,
1211 &encPeer, max_varchar_len, &p_len, 1171 &p_len, MYSQL_TYPE_BLOB, &node->hashPubKey,
1212 MYSQL_TYPE_BLOB, &node->hashPubKey, 1172 sizeof (GNUNET_HashCode), &h_len, -1)))
1213 sizeof (GNUNET_HashCode), &h_len, -1)))
1214 { 1173 {
1215 if (ret == GNUNET_SYSERR) 1174 if (ret == GNUNET_SYSERR)
1216 { 1175 {
@@ -1233,11 +1192,10 @@ update_trials (unsigned int gets_succeeded)
1233 int ret; 1192 int ret;
1234 1193
1235 if (GNUNET_OK != 1194 if (GNUNET_OK !=
1236 (ret = prepared_statement_run (update_trial, 1195 (ret =
1237 NULL, 1196 prepared_statement_run (update_trial, NULL, MYSQL_TYPE_LONG,
1238 MYSQL_TYPE_LONG, &gets_succeeded, 1197 &gets_succeeded, GNUNET_YES, MYSQL_TYPE_LONGLONG,
1239 GNUNET_YES, MYSQL_TYPE_LONGLONG, 1198 &current_trial, GNUNET_YES, -1)))
1240 &current_trial, GNUNET_YES, -1)))
1241 { 1199 {
1242 if (ret == GNUNET_SYSERR) 1200 if (ret == GNUNET_SYSERR)
1243 { 1201 {
@@ -1270,11 +1228,11 @@ set_malicious (struct GNUNET_PeerIdentity *peer)
1270 p_len = strlen (temp_str); 1228 p_len = strlen (temp_str);
1271 1229
1272 if (GNUNET_OK != 1230 if (GNUNET_OK !=
1273 (ret = prepared_statement_run (update_node_malicious, 1231 (ret =
1274 NULL, 1232 prepared_statement_run (update_node_malicious, NULL, MYSQL_TYPE_LONGLONG,
1275 MYSQL_TYPE_LONGLONG, &current_trial, 1233 &current_trial, GNUNET_YES,
1276 GNUNET_YES, MYSQL_TYPE_VAR_STRING, 1234 MYSQL_TYPE_VAR_STRING, temp_str, max_varchar_len,
1277 temp_str, max_varchar_len, &p_len, -1))) 1235 &p_len, -1)))
1278 { 1236 {
1279 if (ret == GNUNET_SYSERR) 1237 if (ret == GNUNET_SYSERR)
1280 { 1238 {
@@ -1298,13 +1256,11 @@ add_connections (unsigned int totalConnections)
1298 int ret; 1256 int ret;
1299 1257
1300 if (GNUNET_OK != 1258 if (GNUNET_OK !=
1301 (ret = prepared_statement_run (update_connection, 1259 (ret =
1302 NULL, 1260 prepared_statement_run (update_connection, NULL, MYSQL_TYPE_LONG,
1303 MYSQL_TYPE_LONG, 1261 &totalConnections, GNUNET_YES,
1304 &totalConnections, 1262 MYSQL_TYPE_LONGLONG, &current_trial, GNUNET_YES,
1305 GNUNET_YES, 1263 -1)))
1306 MYSQL_TYPE_LONGLONG,
1307 &current_trial, GNUNET_YES, -1)))
1308 { 1264 {
1309 if (ret == GNUNET_SYSERR) 1265 if (ret == GNUNET_SYSERR)
1310 { 1266 {
@@ -1341,8 +1297,8 @@ add_query (unsigned long long *sqlqueryuid, unsigned long long queryid,
1341 peer_uid = 0; 1297 peer_uid = 0;
1342 key_uid = 0; 1298 key_uid = 0;
1343 1299
1344 if ((node != NULL) 1300 if ((node != NULL) &&
1345 && (GNUNET_OK == get_node_uid (&peer_uid, &node->hashPubKey))) 1301 (GNUNET_OK == get_node_uid (&peer_uid, &node->hashPubKey)))
1346 { 1302 {
1347 1303
1348 } 1304 }
@@ -1365,28 +1321,15 @@ add_query (unsigned long long *sqlqueryuid, unsigned long long queryid,
1365 } 1321 }
1366 1322
1367 if (GNUNET_OK != 1323 if (GNUNET_OK !=
1368 (ret = prepared_statement_run (insert_query, 1324 (ret =
1369 sqlqueryuid, 1325 prepared_statement_run (insert_query, sqlqueryuid, MYSQL_TYPE_LONGLONG,
1370 MYSQL_TYPE_LONGLONG, 1326 &current_trial, GNUNET_YES, MYSQL_TYPE_LONG,
1371 &current_trial, 1327 &type, GNUNET_NO, MYSQL_TYPE_LONG, &hops,
1372 GNUNET_YES, 1328 GNUNET_YES, MYSQL_TYPE_LONGLONG, &key_uid,
1373 MYSQL_TYPE_LONG, 1329 GNUNET_YES, MYSQL_TYPE_LONGLONG, &queryid,
1374 &type, 1330 GNUNET_YES, MYSQL_TYPE_LONG, &succeeded,
1375 GNUNET_NO, 1331 GNUNET_NO, MYSQL_TYPE_LONGLONG, &peer_uid,
1376 MYSQL_TYPE_LONG, 1332 GNUNET_YES, -1)))
1377 &hops,
1378 GNUNET_YES,
1379 MYSQL_TYPE_LONGLONG,
1380 &key_uid,
1381 GNUNET_YES,
1382 MYSQL_TYPE_LONGLONG,
1383 &queryid,
1384 GNUNET_YES,
1385 MYSQL_TYPE_LONG,
1386 &succeeded,
1387 GNUNET_NO,
1388 MYSQL_TYPE_LONGLONG,
1389 &peer_uid, GNUNET_YES, -1)))
1390 { 1333 {
1391 if (ret == GNUNET_SYSERR) 1334 if (ret == GNUNET_SYSERR)
1392 { 1335 {
@@ -1416,9 +1359,8 @@ add_query (unsigned long long *sqlqueryuid, unsigned long long queryid,
1416 */ 1359 */
1417int 1360int
1418add_route (unsigned long long *sqlqueryuid, unsigned long long queryid, 1361add_route (unsigned long long *sqlqueryuid, unsigned long long queryid,
1419 unsigned int type, unsigned int hops, 1362 unsigned int type, unsigned int hops, int succeeded,
1420 int succeeded, const struct GNUNET_PeerIdentity *node, 1363 const struct GNUNET_PeerIdentity *node, const GNUNET_HashCode * key,
1421 const GNUNET_HashCode * key,
1422 const struct GNUNET_PeerIdentity *from_node, 1364 const struct GNUNET_PeerIdentity *from_node,
1423 const struct GNUNET_PeerIdentity *to_node) 1365 const struct GNUNET_PeerIdentity *to_node)
1424{ 1366{
@@ -1457,34 +1399,17 @@ add_route (unsigned long long *sqlqueryuid, unsigned long long queryid,
1457 return GNUNET_SYSERR; 1399 return GNUNET_SYSERR;
1458 1400
1459 if (GNUNET_OK != 1401 if (GNUNET_OK !=
1460 (ret = prepared_statement_run (insert_route, 1402 (ret =
1461 sqlqueryuid, 1403 prepared_statement_run (insert_route, sqlqueryuid, MYSQL_TYPE_LONGLONG,
1462 MYSQL_TYPE_LONGLONG, 1404 &current_trial, GNUNET_YES, MYSQL_TYPE_LONG,
1463 &current_trial, 1405 &type, GNUNET_NO, MYSQL_TYPE_LONG, &hops,
1464 GNUNET_YES, 1406 GNUNET_YES, MYSQL_TYPE_LONGLONG, &key_uid,
1465 MYSQL_TYPE_LONG, 1407 GNUNET_YES, MYSQL_TYPE_LONGLONG, &queryid,
1466 &type, 1408 GNUNET_YES, MYSQL_TYPE_LONG, &succeeded,
1467 GNUNET_NO, 1409 GNUNET_NO, MYSQL_TYPE_LONGLONG, &peer_uid,
1468 MYSQL_TYPE_LONG, 1410 GNUNET_YES, MYSQL_TYPE_LONGLONG, &from_uid,
1469 &hops, 1411 GNUNET_YES, MYSQL_TYPE_LONGLONG, &to_uid,
1470 GNUNET_YES, 1412 GNUNET_YES, -1)))
1471 MYSQL_TYPE_LONGLONG,
1472 &key_uid,
1473 GNUNET_YES,
1474 MYSQL_TYPE_LONGLONG,
1475 &queryid,
1476 GNUNET_YES,
1477 MYSQL_TYPE_LONG,
1478 &succeeded,
1479 GNUNET_NO,
1480 MYSQL_TYPE_LONGLONG,
1481 &peer_uid,
1482 GNUNET_YES,
1483 MYSQL_TYPE_LONGLONG,
1484 &from_uid,
1485 GNUNET_YES,
1486 MYSQL_TYPE_LONGLONG,
1487 &to_uid, GNUNET_YES, -1)))
1488 { 1413 {
1489 if (ret == GNUNET_SYSERR) 1414 if (ret == GNUNET_SYSERR)
1490 { 1415 {
@@ -1513,13 +1438,10 @@ update_current_topology (unsigned int connections)
1513 get_current_topology (&topologyuid); 1438 get_current_topology (&topologyuid);
1514 1439
1515 if (GNUNET_OK != 1440 if (GNUNET_OK !=
1516 (ret = prepared_statement_run (update_topology, 1441 (ret =
1517 NULL, 1442 prepared_statement_run (update_topology, NULL, MYSQL_TYPE_LONG,
1518 MYSQL_TYPE_LONG, 1443 &connections, GNUNET_YES, MYSQL_TYPE_LONGLONG,
1519 &connections, 1444 &topologyuid, GNUNET_YES, -1)))
1520 GNUNET_YES,
1521 MYSQL_TYPE_LONGLONG,
1522 &topologyuid, GNUNET_YES, -1)))
1523 { 1445 {
1524 if (ret == GNUNET_SYSERR) 1446 if (ret == GNUNET_SYSERR)
1525 { 1447 {
@@ -1545,11 +1467,10 @@ add_topology (int num_connections)
1545 int ret; 1467 int ret;
1546 1468
1547 if (GNUNET_OK != 1469 if (GNUNET_OK !=
1548 (ret = prepared_statement_run (insert_topology, 1470 (ret =
1549 NULL, 1471 prepared_statement_run (insert_topology, NULL, MYSQL_TYPE_LONGLONG,
1550 MYSQL_TYPE_LONGLONG, &current_trial, 1472 &current_trial, GNUNET_YES, MYSQL_TYPE_LONG,
1551 GNUNET_YES, MYSQL_TYPE_LONG, 1473 &num_connections, GNUNET_YES, -1)))
1552 &num_connections, GNUNET_YES, -1)))
1553 { 1474 {
1554 if (ret == GNUNET_SYSERR) 1475 if (ret == GNUNET_SYSERR)
1555 { 1476 {
@@ -1586,16 +1507,11 @@ add_extended_topology (const struct GNUNET_PeerIdentity *first,
1586 return GNUNET_SYSERR; 1507 return GNUNET_SYSERR;
1587 1508
1588 if (GNUNET_OK != 1509 if (GNUNET_OK !=
1589 (ret = prepared_statement_run (extend_topology, 1510 (ret =
1590 NULL, 1511 prepared_statement_run (extend_topology, NULL, MYSQL_TYPE_LONGLONG,
1591 MYSQL_TYPE_LONGLONG, 1512 &topologyuid, GNUNET_YES, MYSQL_TYPE_LONGLONG,
1592 &topologyuid, 1513 &first_uid, GNUNET_YES, MYSQL_TYPE_LONGLONG,
1593 GNUNET_YES, 1514 &second_uid, GNUNET_YES, -1)))
1594 MYSQL_TYPE_LONGLONG,
1595 &first_uid,
1596 GNUNET_YES,
1597 MYSQL_TYPE_LONGLONG,
1598 &second_uid, GNUNET_YES, -1)))
1599 { 1515 {
1600 if (ret == GNUNET_SYSERR) 1516 if (ret == GNUNET_SYSERR)
1601 { 1517 {
diff --git a/src/dht/plugin_dhtlog_mysql_dump.c b/src/dht/plugin_dhtlog_mysql_dump.c
index 25958044c..bbb1da0c9 100644
--- a/src/dht/plugin_dhtlog_mysql_dump.c
+++ b/src/dht/plugin_dhtlog_mysql_dump.c
@@ -162,24 +162,16 @@ static int
162iopen () 162iopen ()
163{ 163{
164#define PINIT(a) (GNUNET_OK != (prepared_statement_create(a))) 164#define PINIT(a) (GNUNET_OK != (prepared_statement_create(a)))
165 if (PINIT (INSERT_QUERIES_STMT) || 165 if (PINIT (INSERT_QUERIES_STMT) || PINIT (INSERT_ROUTES_STMT) ||
166 PINIT (INSERT_ROUTES_STMT) || 166 PINIT (INSERT_ROUND_STMT) || PINIT (INSERT_ROUND_DETAILS_STMT) ||
167 PINIT (INSERT_ROUND_STMT) || 167 PINIT (INSERT_TRIALS_STMT) || PINIT (SET_MALICIOUS_STMT) ||
168 PINIT (INSERT_ROUND_DETAILS_STMT) || 168 PINIT (INSERT_GENERIC_STAT_STMT) || PINIT (INSERT_STAT_STMT) ||
169 PINIT (INSERT_TRIALS_STMT) || 169 PINIT (INSERT_NODES_STMT) || PINIT (INSERT_DHTKEY_STMT) ||
170 PINIT (SET_MALICIOUS_STMT) || 170 PINIT (UPDATE_TRIALS_STMT) || PINIT (GET_DHTKEYUID_STMT) ||
171 PINIT (INSERT_GENERIC_STAT_STMT) || 171 PINIT (GET_NODEUID_STMT) || PINIT (UPDATE_CONNECTIONS_STMT) ||
172 PINIT (INSERT_STAT_STMT) || 172 PINIT (INSERT_TOPOLOGY_STMT) || PINIT (EXTEND_TOPOLOGY_STMT) ||
173 PINIT (INSERT_NODES_STMT) || 173 PINIT (UPDATE_TOPOLOGY_STMT) || PINIT (GET_TRIAL_STMT) ||
174 PINIT (INSERT_DHTKEY_STMT) || 174 PINIT (GET_TOPOLOGY_STMT))
175 PINIT (UPDATE_TRIALS_STMT) ||
176 PINIT (GET_DHTKEYUID_STMT) ||
177 PINIT (GET_NODEUID_STMT) ||
178 PINIT (UPDATE_CONNECTIONS_STMT) ||
179 PINIT (INSERT_TOPOLOGY_STMT) ||
180 PINIT (EXTEND_TOPOLOGY_STMT) ||
181 PINIT (UPDATE_TOPOLOGY_STMT) ||
182 PINIT (GET_TRIAL_STMT) || PINIT (GET_TOPOLOGY_STMT))
183 { 175 {
184 return GNUNET_SYSERR; 176 return GNUNET_SYSERR;
185 } 177 }
@@ -325,8 +317,10 @@ add_extended_topology (const struct GNUNET_PeerIdentity *first,
325 if (ret < 0) 317 if (ret < 0)
326 return GNUNET_SYSERR; 318 return GNUNET_SYSERR;
327 319
328 ret = fprintf (outfile, "execute extend_topology using " 320 ret =
329 "@temp_first_node, @temp_second_node;\n"); 321 fprintf (outfile,
322 "execute extend_topology using "
323 "@temp_first_node, @temp_second_node;\n");
330 324
331 if (ret >= 0) 325 if (ret >= 0)
332 return GNUNET_OK; 326 return GNUNET_OK;
@@ -376,13 +370,13 @@ add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info)
376 370
377 if (ret < 0) 371 if (ret < 0)
378 return GNUNET_SYSERR; 372 return GNUNET_SYSERR;
379 ret = fprintf (outfile, "execute insert_trial using " 373 ret =
380 "@date, @oid, @num, @topology, @t_p, @t_pr," 374 fprintf (outfile,
381 " @bl, @connect, @c_t_o," 375 "execute insert_trial using "
382 "@c_t_o_m, @puts, @gets," 376 "@date, @oid, @num, @topology, @t_p, @t_pr,"
383 "@concurrent, @settle, @rounds," 377 " @bl, @connect, @c_t_o," "@c_t_o_m, @puts, @gets,"
384 "@m_gets, @m_puts, @m_drops," 378 "@concurrent, @settle, @rounds," "@m_gets, @m_puts, @m_drops,"
385 "@m_g_f, @m_p_f, @s_c, @s_f," "@s_k, @g_s, @message;\n"); 379 "@m_g_f, @m_p_f, @s_c, @s_f," "@s_k, @g_s, @message;\n");
386 if (ret < 0) 380 if (ret < 0)
387 return GNUNET_SYSERR; 381 return GNUNET_SYSERR;
388 ret = fprintf (outfile, "execute select_trial;\n"); 382 ret = fprintf (outfile, "execute select_trial;\n");
@@ -404,8 +398,8 @@ add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info)
404 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 398 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
405 */ 399 */
406int 400int
407add_generic_stat (const struct GNUNET_PeerIdentity *peer, 401add_generic_stat (const struct GNUNET_PeerIdentity *peer, const char *name,
408 const char *name, const char *section, uint64_t value) 402 const char *section, uint64_t value)
409{ 403{
410 int ret; 404 int ret;
411 405
@@ -466,10 +460,10 @@ int
466add_stat (const struct GNUNET_PeerIdentity *peer, unsigned int route_requests, 460add_stat (const struct GNUNET_PeerIdentity *peer, unsigned int route_requests,
467 unsigned int route_forwards, unsigned int result_requests, 461 unsigned int route_forwards, unsigned int result_requests,
468 unsigned int client_requests, unsigned int result_forwards, 462 unsigned int client_requests, unsigned int result_forwards,
469 unsigned int gets, unsigned int puts, 463 unsigned int gets, unsigned int puts, unsigned int data_inserts,
470 unsigned int data_inserts, unsigned int find_peer_requests, 464 unsigned int find_peer_requests, unsigned int find_peers_started,
471 unsigned int find_peers_started, unsigned int gets_started, 465 unsigned int gets_started, unsigned int puts_started,
472 unsigned int puts_started, unsigned int find_peer_responses_received, 466 unsigned int find_peer_responses_received,
473 unsigned int get_responses_received, 467 unsigned int get_responses_received,
474 unsigned int find_peer_responses_sent, 468 unsigned int find_peer_responses_sent,
475 unsigned int get_responses_sent) 469 unsigned int get_responses_sent)
@@ -489,25 +483,27 @@ add_stat (const struct GNUNET_PeerIdentity *peer, unsigned int route_requests,
489 if (ret < 0) 483 if (ret < 0)
490 return GNUNET_SYSERR; 484 return GNUNET_SYSERR;
491 485
492 ret = fprintf (outfile, "set @r_r = %u, @r_f = %u, @res_r = %u, @c_r = %u, " 486 ret =
493 "@res_f = %u, @gets = %u, @puts = %u, @d_i = %u, " 487 fprintf (outfile,
494 "@f_p_r = %u, @f_p_s = %u, @g_s = %u, @p_s = %u, " 488 "set @r_r = %u, @r_f = %u, @res_r = %u, @c_r = %u, "
495 "@f_p_r_r = %u, @g_r_r = %u, @f_p_r_s = %u, @g_r_s = %u;\n", 489 "@res_f = %u, @gets = %u, @puts = %u, @d_i = %u, "
496 route_requests, route_forwards, result_requests, 490 "@f_p_r = %u, @f_p_s = %u, @g_s = %u, @p_s = %u, "
497 client_requests, result_forwards, gets, puts, 491 "@f_p_r_r = %u, @g_r_r = %u, @f_p_r_s = %u, @g_r_s = %u;\n",
498 data_inserts, find_peer_requests, find_peers_started, 492 route_requests, route_forwards, result_requests, client_requests,
499 gets_started, puts_started, find_peer_responses_received, 493 result_forwards, gets, puts, data_inserts, find_peer_requests,
500 get_responses_received, find_peer_responses_sent, 494 find_peers_started, gets_started, puts_started,
501 get_responses_sent); 495 find_peer_responses_received, get_responses_received,
496 find_peer_responses_sent, get_responses_sent);
502 497
503 if (ret < 0) 498 if (ret < 0)
504 return GNUNET_SYSERR; 499 return GNUNET_SYSERR;
505 500
506 ret = fprintf (outfile, "execute insert_stat using " 501 ret =
507 "@temp_trial, @temp_node, @r_r, @r_f, @res_r, @c_r, " 502 fprintf (outfile,
508 "@res_f, @gets, @puts, @d_i, " 503 "execute insert_stat using "
509 "@f_p_r, @f_p_s, @g_s, @p_s, " 504 "@temp_trial, @temp_node, @r_r, @r_f, @res_r, @c_r, "
510 "@f_p_r_r, @g_r_r, @f_p_r_s, @g_r_s;\n"); 505 "@res_f, @gets, @puts, @d_i, " "@f_p_r, @f_p_s, @g_s, @p_s, "
506 "@f_p_r_r, @g_r_r, @f_p_r_s, @g_r_s;\n");
511 if (ret < 0) 507 if (ret < 0)
512 return GNUNET_SYSERR; 508 return GNUNET_SYSERR;
513 return GNUNET_OK; 509 return GNUNET_OK;
@@ -784,9 +780,8 @@ add_query (unsigned long long *sqlqueryuid, unsigned long long queryid,
784 */ 780 */
785int 781int
786add_route (unsigned long long *sqlqueryuid, unsigned long long queryid, 782add_route (unsigned long long *sqlqueryuid, unsigned long long queryid,
787 unsigned int type, unsigned int hops, 783 unsigned int type, unsigned int hops, int succeeded,
788 int succeeded, const struct GNUNET_PeerIdentity *node, 784 const struct GNUNET_PeerIdentity *node, const GNUNET_HashCode * key,
789 const GNUNET_HashCode * key,
790 const struct GNUNET_PeerIdentity *from_node, 785 const struct GNUNET_PeerIdentity *from_node,
791 const struct GNUNET_PeerIdentity *to_node) 786 const struct GNUNET_PeerIdentity *to_node)
792{ 787{
@@ -882,15 +877,15 @@ libgnunet_plugin_dhtlog_mysql_dump_init (void *cls)
882 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 877 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
883 "MySQL (DUMP) DHT Logger: initializing\n"); 878 "MySQL (DUMP) DHT Logger: initializing\n");
884 879
885 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg, 880 if (GNUNET_OK !=
886 "MYSQLDUMP", "PATH", 881 GNUNET_CONFIGURATION_get_value_string (plugin->cfg, "MYSQLDUMP", "PATH",
887 &outfile_path)) 882 &outfile_path))
888 { 883 {
889 outfile_path = GNUNET_strdup (""); 884 outfile_path = GNUNET_strdup ("");
890 } 885 }
891 886
892 GNUNET_asprintf (&outfile_name, 887 GNUNET_asprintf (&outfile_name, "%s%s-%d", outfile_path, "mysqldump",
893 "%s%s-%d", outfile_path, "mysqldump", getpid ()); 888 getpid ());
894 889
895 fn = GNUNET_STRINGS_filename_expand (outfile_name); 890 fn = GNUNET_STRINGS_filename_expand (outfile_name);
896 891
diff --git a/src/dht/plugin_dhtlog_mysql_dump_load.c b/src/dht/plugin_dhtlog_mysql_dump_load.c
index 7c3f67942..fada2029e 100644
--- a/src/dht/plugin_dhtlog_mysql_dump_load.c
+++ b/src/dht/plugin_dhtlog_mysql_dump_load.c
@@ -222,31 +222,33 @@ add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info)
222 if (outfile == NULL) 222 if (outfile == NULL)
223 return GNUNET_SYSERR; 223 return GNUNET_SYSERR;
224 224
225 ret = fprintf (outfile, "INSERT INTO trials " 225 ret =
226 "(starttime, other_trial_identifier, numnodes, topology," 226 fprintf (outfile,
227 "blacklist_topology, connect_topology, connect_topology_option," 227 "INSERT INTO trials "
228 "connect_topology_option_modifier, topology_percentage, topology_probability," 228 "(starttime, other_trial_identifier, numnodes, topology,"
229 "puts, gets, " 229 "blacklist_topology, connect_topology, connect_topology_option,"
230 "concurrent, settle_time, num_rounds, malicious_getters," 230 "connect_topology_option_modifier, topology_percentage, topology_probability,"
231 "malicious_putters, malicious_droppers, malicious_get_frequency," 231 "puts, gets, "
232 "malicious_put_frequency, stop_closest, stop_found, strict_kademlia, " 232 "concurrent, settle_time, num_rounds, malicious_getters,"
233 "gets_succeeded, message) " 233 "malicious_putters, malicious_droppers, malicious_get_frequency,"
234 "VALUES (\"%s\", %u, %u, %u, %u, %u, %u, %f, %f, %f, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, \"%s\");\n", 234 "malicious_put_frequency, stop_closest, stop_found, strict_kademlia, "
235 get_sql_time (), trial_info->other_identifier, 235 "gets_succeeded, message) "
236 trial_info->num_nodes, trial_info->topology, 236 "VALUES (\"%s\", %u, %u, %u, %u, %u, %u, %f, %f, %f, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, \"%s\");\n",
237 trial_info->blacklist_topology, trial_info->connect_topology, 237 get_sql_time (), trial_info->other_identifier,
238 trial_info->connect_topology_option, 238 trial_info->num_nodes, trial_info->topology,
239 trial_info->connect_topology_option_modifier, 239 trial_info->blacklist_topology, trial_info->connect_topology,
240 trial_info->topology_percentage, 240 trial_info->connect_topology_option,
241 trial_info->topology_probability, trial_info->puts, 241 trial_info->connect_topology_option_modifier,
242 trial_info->gets, trial_info->concurrent, 242 trial_info->topology_percentage,
243 trial_info->settle_time, trial_info->num_rounds, 243 trial_info->topology_probability, trial_info->puts,
244 trial_info->malicious_getters, trial_info->malicious_putters, 244 trial_info->gets, trial_info->concurrent,
245 trial_info->malicious_droppers, 245 trial_info->settle_time, trial_info->num_rounds,
246 trial_info->malicious_get_frequency, 246 trial_info->malicious_getters, trial_info->malicious_putters,
247 trial_info->malicious_put_frequency, trial_info->stop_closest, 247 trial_info->malicious_droppers,
248 trial_info->stop_found, trial_info->strict_kademlia, 248 trial_info->malicious_get_frequency,
249 trial_info->gets_succeeded, trial_info->message); 249 trial_info->malicious_put_frequency, trial_info->stop_closest,
250 trial_info->stop_found, trial_info->strict_kademlia,
251 trial_info->gets_succeeded, trial_info->message);
250 252
251 if (ret < 0) 253 if (ret < 0)
252 return GNUNET_SYSERR; 254 return GNUNET_SYSERR;
@@ -273,8 +275,8 @@ add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info)
273 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 275 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
274 */ 276 */
275int 277int
276add_generic_stat (const struct GNUNET_PeerIdentity *peer, 278add_generic_stat (const struct GNUNET_PeerIdentity *peer, const char *name,
277 const char *name, const char *section, uint64_t value) 279 const char *section, uint64_t value)
278{ 280{
279 if (outfile == NULL) 281 if (outfile == NULL)
280 return GNUNET_SYSERR; 282 return GNUNET_SYSERR;
@@ -315,10 +317,10 @@ int
315add_stat (const struct GNUNET_PeerIdentity *peer, unsigned int route_requests, 317add_stat (const struct GNUNET_PeerIdentity *peer, unsigned int route_requests,
316 unsigned int route_forwards, unsigned int result_requests, 318 unsigned int route_forwards, unsigned int result_requests,
317 unsigned int client_requests, unsigned int result_forwards, 319 unsigned int client_requests, unsigned int result_forwards,
318 unsigned int gets, unsigned int puts, 320 unsigned int gets, unsigned int puts, unsigned int data_inserts,
319 unsigned int data_inserts, unsigned int find_peer_requests, 321 unsigned int find_peer_requests, unsigned int find_peers_started,
320 unsigned int find_peers_started, unsigned int gets_started, 322 unsigned int gets_started, unsigned int puts_started,
321 unsigned int puts_started, unsigned int find_peer_responses_received, 323 unsigned int find_peer_responses_received,
322 unsigned int get_responses_received, 324 unsigned int get_responses_received,
323 unsigned int find_peer_responses_sent, 325 unsigned int find_peer_responses_sent,
324 unsigned int get_responses_sent) 326 unsigned int get_responses_sent)
@@ -568,9 +570,8 @@ add_query (unsigned long long *sqlqueryuid, unsigned long long queryid,
568 */ 570 */
569int 571int
570add_route (unsigned long long *sqlqueryuid, unsigned long long queryid, 572add_route (unsigned long long *sqlqueryuid, unsigned long long queryid,
571 unsigned int type, unsigned int hops, 573 unsigned int type, unsigned int hops, int succeeded,
572 int succeeded, const struct GNUNET_PeerIdentity *node, 574 const struct GNUNET_PeerIdentity *node, const GNUNET_HashCode * key,
573 const GNUNET_HashCode * key,
574 const struct GNUNET_PeerIdentity *from_node, 575 const struct GNUNET_PeerIdentity *from_node,
575 const struct GNUNET_PeerIdentity *to_node) 576 const struct GNUNET_PeerIdentity *to_node)
576{ 577{
@@ -636,15 +637,15 @@ libgnunet_plugin_dhtlog_mysql_dump_load_init (void *cls)
636 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 637 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
637 "MySQL (DUMP) DHT Logger: initializing\n"); 638 "MySQL (DUMP) DHT Logger: initializing\n");
638 639
639 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg, 640 if (GNUNET_OK !=
640 "MYSQLDUMP", "PATH", 641 GNUNET_CONFIGURATION_get_value_string (plugin->cfg, "MYSQLDUMP", "PATH",
641 &outfile_path)) 642 &outfile_path))
642 { 643 {
643 outfile_path = GNUNET_strdup (""); 644 outfile_path = GNUNET_strdup ("");
644 } 645 }
645 646
646 GNUNET_asprintf (&outfile_name, 647 GNUNET_asprintf (&outfile_name, "%s%s-%d", outfile_path, "mysqldump",
647 "%s%s-%d", outfile_path, "mysqldump", getpid ()); 648 getpid ());
648 649
649 fn = GNUNET_STRINGS_filename_expand (outfile_name); 650 fn = GNUNET_STRINGS_filename_expand (outfile_name);
650 651
@@ -674,8 +675,8 @@ libgnunet_plugin_dhtlog_mysql_dump_load_init (void *cls)
674 } 675 }
675 676
676 GNUNET_free (outfile_name); 677 GNUNET_free (outfile_name);
677 GNUNET_asprintf (&outfile_name, 678 GNUNET_asprintf (&outfile_name, "%s%s-%d", outfile_path, "mysqldump_nodes",
678 "%s%s-%d", outfile_path, "mysqldump_nodes", getpid ()); 679 getpid ());
679 GNUNET_free (fn); 680 GNUNET_free (fn);
680 fn = GNUNET_STRINGS_filename_expand (outfile_name); 681 fn = GNUNET_STRINGS_filename_expand (outfile_name);
681 682
@@ -705,8 +706,8 @@ libgnunet_plugin_dhtlog_mysql_dump_load_init (void *cls)
705 } 706 }
706 707
707 GNUNET_free (outfile_name); 708 GNUNET_free (outfile_name);
708 GNUNET_asprintf (&outfile_name, 709 GNUNET_asprintf (&outfile_name, "%s%s-%d", outfile_path, "mysqldump_routes",
709 "%s%s-%d", outfile_path, "mysqldump_routes", getpid ()); 710 getpid ());
710 711
711 GNUNET_free (fn); 712 GNUNET_free (fn);
712 fn = GNUNET_STRINGS_filename_expand (outfile_name); 713 fn = GNUNET_STRINGS_filename_expand (outfile_name);
@@ -737,8 +738,8 @@ libgnunet_plugin_dhtlog_mysql_dump_load_init (void *cls)
737 } 738 }
738 739
739 GNUNET_free (outfile_name); 740 GNUNET_free (outfile_name);
740 GNUNET_asprintf (&outfile_name, 741 GNUNET_asprintf (&outfile_name, "%s%s-%d", outfile_path, "mysqldump_queries",
741 "%s%s-%d", outfile_path, "mysqldump_queries", getpid ()); 742 getpid ());
742 743
743 GNUNET_free (fn); 744 GNUNET_free (fn);
744 fn = GNUNET_STRINGS_filename_expand (outfile_name); 745 fn = GNUNET_STRINGS_filename_expand (outfile_name);
@@ -769,8 +770,8 @@ libgnunet_plugin_dhtlog_mysql_dump_load_init (void *cls)
769 } 770 }
770 771
771 GNUNET_free (outfile_name); 772 GNUNET_free (outfile_name);
772 GNUNET_asprintf (&outfile_name, 773 GNUNET_asprintf (&outfile_name, "%s%s-%d", outfile_path, "mysqldump_stats",
773 "%s%s-%d", outfile_path, "mysqldump_stats", getpid ()); 774 getpid ());
774 775
775 GNUNET_free (fn); 776 GNUNET_free (fn);
776 fn = GNUNET_STRINGS_filename_expand (outfile_name); 777 fn = GNUNET_STRINGS_filename_expand (outfile_name);
@@ -801,9 +802,8 @@ libgnunet_plugin_dhtlog_mysql_dump_load_init (void *cls)
801 } 802 }
802 803
803 GNUNET_free (outfile_name); 804 GNUNET_free (outfile_name);
804 GNUNET_asprintf (&outfile_name, 805 GNUNET_asprintf (&outfile_name, "%s%s-%d", outfile_path,
805 "%s%s-%d", 806 "mysqldump_generic_stats", getpid ());
806 outfile_path, "mysqldump_generic_stats", getpid ());
807 GNUNET_free (fn); 807 GNUNET_free (fn);
808 fn = GNUNET_STRINGS_filename_expand (outfile_name); 808 fn = GNUNET_STRINGS_filename_expand (outfile_name);
809 809
@@ -833,8 +833,8 @@ libgnunet_plugin_dhtlog_mysql_dump_load_init (void *cls)
833 } 833 }
834 834
835 GNUNET_free (outfile_name); 835 GNUNET_free (outfile_name);
836 GNUNET_asprintf (&outfile_name, 836 GNUNET_asprintf (&outfile_name, "%s%s-%d", outfile_path, "mysqldump_dhtkey",
837 "%s%s-%d", outfile_path, "mysqldump_dhtkey", getpid ()); 837 getpid ());
838 GNUNET_free (fn); 838 GNUNET_free (fn);
839 fn = GNUNET_STRINGS_filename_expand (outfile_name); 839 fn = GNUNET_STRINGS_filename_expand (outfile_name);
840 840
@@ -864,9 +864,8 @@ libgnunet_plugin_dhtlog_mysql_dump_load_init (void *cls)
864 } 864 }
865 865
866 GNUNET_free (outfile_name); 866 GNUNET_free (outfile_name);
867 GNUNET_asprintf (&outfile_name, 867 GNUNET_asprintf (&outfile_name, "%s%s-%d", outfile_path,
868 "%s%s-%d", 868 "mysqldump_extended_topology", getpid ());
869 outfile_path, "mysqldump_extended_topology", getpid ());
870 GNUNET_free (fn); 869 GNUNET_free (fn);
871 fn = GNUNET_STRINGS_filename_expand (outfile_name); 870 fn = GNUNET_STRINGS_filename_expand (outfile_name);
872 871
diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c
index 407e2279b..9fc5c2d7a 100644
--- a/src/dht/test_dht_api.c
+++ b/src/dht/test_dht_api.c
@@ -237,8 +237,8 @@ test_find_peer_processor (void *cls, const struct GNUNET_HELLO_Message *hello)
237 * @param cls closure 237 * @param cls closure
238 * @param tc context information (why was this task triggered now?) 238 * @param tc context information (why was this task triggered now?)
239 */ 239 */
240void 240void retry_find_peer_stop (void *cls,
241retry_find_peer_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 241 const struct GNUNET_SCHEDULER_TaskContext *tc);
242 242
243/** 243/**
244 * Retry the find_peer task on timeout. 244 * Retry the find_peer task on timeout.
@@ -330,8 +330,7 @@ test_find_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
330 retry_context.next_timeout = BASE_TIMEOUT; 330 retry_context.next_timeout = BASE_TIMEOUT;
331 retry_context.peer_ctx = peer; 331 retry_context.peer_ctx = peer;
332 332
333 peer->find_peer_handle 333 peer->find_peer_handle =
334 =
335 GNUNET_DHT_find_peer_start (peer->dht_handle, retry_context.next_timeout, 334 GNUNET_DHT_find_peer_start (peer->dht_handle, retry_context.next_timeout,
336 &hash, GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 335 &hash, GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
337 &test_find_peer_processor, &retry_context); 336 &test_find_peer_processor, &retry_context);
@@ -374,8 +373,7 @@ test_get_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
374} 373}
375 374
376void 375void
377test_get_iterator (void *cls, 376test_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
378 struct GNUNET_TIME_Absolute exp,
379 const GNUNET_HashCode * key, 377 const GNUNET_HashCode * key,
380 const struct GNUNET_PeerIdentity *const *get_path, 378 const struct GNUNET_PeerIdentity *const *get_path,
381 const struct GNUNET_PeerIdentity *const *put_path, 379 const struct GNUNET_PeerIdentity *const *put_path,
@@ -409,13 +407,10 @@ test_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
409 retry_context.next_timeout = BASE_TIMEOUT; 407 retry_context.next_timeout = BASE_TIMEOUT;
410 408
411 peer->get_handle = 409 peer->get_handle =
412 GNUNET_DHT_get_start (peer->dht_handle, 410 GNUNET_DHT_get_start (peer->dht_handle, TOTAL_TIMEOUT,
413 TOTAL_TIMEOUT, 411 GNUNET_BLOCK_TYPE_TEST, &hash,
414 GNUNET_BLOCK_TYPE_TEST, 412 DEFAULT_GET_REPLICATION, GNUNET_DHT_RO_NONE, NULL,
415 &hash, 413 0, NULL, 0, &test_get_iterator, NULL);
416 DEFAULT_GET_REPLICATION,
417 GNUNET_DHT_RO_NONE,
418 NULL, 0, NULL, 0, &test_get_iterator, NULL);
419 414
420 if (peer->get_handle == NULL) 415 if (peer->get_handle == NULL)
421 { 416 {
@@ -450,11 +445,8 @@ test_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
450 445
451 GNUNET_assert (peer->dht_handle != NULL); 446 GNUNET_assert (peer->dht_handle != NULL);
452 447
453 GNUNET_DHT_put (peer->dht_handle, &hash, 448 GNUNET_DHT_put (peer->dht_handle, &hash, DEFAULT_PUT_REPLICATION,
454 DEFAULT_PUT_REPLICATION, 449 GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST, data_size, data,
455 GNUNET_DHT_RO_NONE,
456 GNUNET_BLOCK_TYPE_TEST,
457 data_size, data,
458 GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT), 450 GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT),
459 TOTAL_TIMEOUT, &test_get, &p1); 451 TOTAL_TIMEOUT, &test_get, &p1);
460 GNUNET_free (data); 452 GNUNET_free (data);
@@ -465,28 +457,29 @@ setup_peer (struct PeerContext *p, const char *cfgname)
465{ 457{
466 p->cfg = GNUNET_CONFIGURATION_create (); 458 p->cfg = GNUNET_CONFIGURATION_create ();
467#if START_ARM 459#if START_ARM
468 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 460 p->arm_proc =
469 "gnunet-service-arm", 461 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
462 "gnunet-service-arm",
470#if VERBOSE_ARM 463#if VERBOSE_ARM
471 "-L", "DEBUG", 464 "-L", "DEBUG",
472#endif 465#endif
473 "-c", cfgname, NULL); 466 "-c", cfgname, NULL);
474#endif 467#endif
475 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 468 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
476 469
477} 470}
478 471
479static void 472static void
480run (void *cls, 473run (void *cls, char *const *args, const char *cfgfile,
481 char *const *args, 474 const struct GNUNET_CONFIGURATION_Handle *cfg)
482 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
483{ 475{
484 GNUNET_assert (ok == 1); 476 GNUNET_assert (ok == 1);
485 OKPP; 477 OKPP;
486 478
487 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 479 die_task =
488 (GNUNET_TIME_UNIT_MINUTES, 1), 480 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
489 &end_badly, NULL); 481 (GNUNET_TIME_UNIT_MINUTES, 1), &end_badly,
482 NULL);
490 483
491 setup_peer (&p1, "test_dht_api_peer1.conf"); 484 setup_peer (&p1, "test_dht_api_peer1.conf");
492 485
@@ -512,8 +505,8 @@ check ()
512 }; 505 };
513 506
514 ok = 1; 507 ok = 1;
515 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 508 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
516 argv, "test-dht-api", "nohelp", options, &run, &ok); 509 "test-dht-api", "nohelp", options, &run, &ok);
517 stop_arm (&p1); 510 stop_arm (&p1);
518 return ok; 511 return ok;
519} 512}
diff --git a/src/dht/test_dht_multipeer.c b/src/dht/test_dht_multipeer.c
index 3bbf44be1..779aff88d 100644
--- a/src/dht/test_dht_multipeer.c
+++ b/src/dht/test_dht_multipeer.c
@@ -394,8 +394,7 @@ get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
394 * @param data pointer to the result data 394 * @param data pointer to the result data
395 */ 395 */
396void 396void
397get_result_iterator (void *cls, 397get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
398 struct GNUNET_TIME_Absolute exp,
399 const GNUNET_HashCode * key, 398 const GNUNET_HashCode * key,
400 const struct GNUNET_PeerIdentity *const *get_path, 399 const struct GNUNET_PeerIdentity *const *get_path,
401 const struct GNUNET_PeerIdentity *const *put_path, 400 const struct GNUNET_PeerIdentity *const *put_path,
@@ -473,15 +472,11 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
473 /* Insert the data at the first peer */ 472 /* Insert the data at the first peer */
474 GNUNET_assert (test_get->dht_handle != NULL); 473 GNUNET_assert (test_get->dht_handle != NULL);
475 outstanding_gets++; 474 outstanding_gets++;
476 test_get->get_handle = GNUNET_DHT_get_start (test_get->dht_handle, 475 test_get->get_handle =
477 GNUNET_TIME_UNIT_FOREVER_REL, 476 GNUNET_DHT_get_start (test_get->dht_handle, GNUNET_TIME_UNIT_FOREVER_REL,
478 GNUNET_BLOCK_TYPE_TEST, 477 GNUNET_BLOCK_TYPE_TEST, &key,
479 &key, 478 DEFAULT_GET_REPLICATION, route_option, NULL, 0,
480 DEFAULT_GET_REPLICATION, 479 NULL, 0, &get_result_iterator, test_get);
481 route_option,
482 NULL, 0,
483 NULL, 0,
484 &get_result_iterator, test_get);
485#if VERBOSE 480#if VERBOSE
486 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting get for uid %u from peer %s\n", 481 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting get for uid %u from peer %s\n",
487 test_get->uid, test_get->daemon->shortname); 482 test_get->uid, test_get->daemon->shortname);
@@ -546,14 +541,10 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
546 541
547 GNUNET_assert (test_put->dht_handle != NULL); 542 GNUNET_assert (test_put->dht_handle != NULL);
548 outstanding_puts++; 543 outstanding_puts++;
549 GNUNET_DHT_put (test_put->dht_handle, 544 GNUNET_DHT_put (test_put->dht_handle, &key, DEFAULT_PUT_REPLICATION,
550 &key, 545 route_option, GNUNET_BLOCK_TYPE_TEST, sizeof (data), data,
551 DEFAULT_PUT_REPLICATION, 546 GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL,
552 route_option, 547 &put_finished, test_put);
553 GNUNET_BLOCK_TYPE_TEST,
554 sizeof (data), data,
555 GNUNET_TIME_UNIT_FOREVER_ABS,
556 GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, test_put);
557 test_put->disconnect_task = 548 test_put->disconnect_task =
558 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_get_forever (), 549 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_get_forever (),
559 &put_disconnect_task, test_put); 550 &put_disconnect_task, test_put);
@@ -616,10 +607,8 @@ setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
616 * failure (peers failed to connect). 607 * failure (peers failed to connect).
617 */ 608 */
618void 609void
619topology_callback (void *cls, 610topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
620 const struct GNUNET_PeerIdentity *first, 611 const struct GNUNET_PeerIdentity *second, uint32_t distance,
621 const struct GNUNET_PeerIdentity *second,
622 uint32_t distance,
623 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 612 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
624 const struct GNUNET_CONFIGURATION_Handle *second_cfg, 613 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
625 struct GNUNET_TESTING_Daemon *first_daemon, 614 struct GNUNET_TESTING_Daemon *first_daemon,
@@ -653,9 +642,9 @@ topology_callback (void *cls,
653 total_connections); 642 total_connections);
654#endif 643#endif
655 GNUNET_SCHEDULER_cancel (die_task); 644 GNUNET_SCHEDULER_cancel (die_task);
656 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 645 die_task =
657 &end_badly, 646 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
658 "from setup puts/gets"); 647 "from setup puts/gets");
659 648
660 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 649 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
661 (GNUNET_TIME_UNIT_SECONDS, 2), 650 (GNUNET_TIME_UNIT_SECONDS, 2),
@@ -671,8 +660,7 @@ topology_callback (void *cls,
671} 660}
672 661
673static void 662static void
674peers_started_callback (void *cls, 663peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
675 const struct GNUNET_PeerIdentity *id,
676 const struct GNUNET_CONFIGURATION_Handle *cfg, 664 const struct GNUNET_CONFIGURATION_Handle *cfg,
677 struct GNUNET_TESTING_Daemon *d, const char *emsg) 665 struct GNUNET_TESTING_Daemon *d, const char *emsg)
678{ 666{
@@ -702,16 +690,14 @@ peers_started_callback (void *cls,
702 expected_connections = -1; 690 expected_connections = -1;
703 if ((pg != NULL) && (peers_left == 0)) 691 if ((pg != NULL) && (peers_left == 0))
704 { 692 {
705 expected_connections = GNUNET_TESTING_connect_topology (pg, 693 expected_connections =
706 connection_topology, 694 GNUNET_TESTING_connect_topology (pg, connection_topology,
707 connect_topology_option, 695 connect_topology_option,
708 connect_topology_option_modifier, 696 connect_topology_option_modifier,
709 TIMEOUT, 697 TIMEOUT, num_peers, NULL, NULL);
710 num_peers,
711 NULL, NULL);
712#if VERBOSE 698#if VERBOSE
713 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 699 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Have %d expected connections\n",
714 "Have %d expected connections\n", expected_connections); 700 expected_connections);
715#endif 701#endif
716 } 702 }
717 703
@@ -722,9 +708,9 @@ peers_started_callback (void *cls,
722 "from connect topology (bad return)"); 708 "from connect topology (bad return)");
723 } 709 }
724 710
725 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 711 die_task =
726 &end_badly, 712 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
727 "from connect topology (timeout)"); 713 "from connect topology (timeout)");
728 714
729 ok = 0; 715 ok = 0;
730 } 716 }
@@ -751,9 +737,9 @@ create_topology ()
751 "from create topology (bad return)"); 737 "from create topology (bad return)");
752 } 738 }
753 GNUNET_SCHEDULER_cancel (die_task); 739 GNUNET_SCHEDULER_cancel (die_task);
754 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 740 die_task =
755 &end_badly, 741 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
756 "from continue startup (timeout)"); 742 "from continue startup (timeout)");
757} 743}
758 744
759/** 745/**
@@ -765,8 +751,7 @@ create_topology ()
765 * @param emsg non-null on failure 751 * @param emsg non-null on failure
766 */ 752 */
767void 753void
768hostkey_callback (void *cls, 754hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id,
769 const struct GNUNET_PeerIdentity *id,
770 struct GNUNET_TESTING_Daemon *d, const char *emsg) 755 struct GNUNET_TESTING_Daemon *d, const char *emsg)
771{ 756{
772 if (emsg != NULL) 757 if (emsg != NULL)
@@ -777,8 +762,8 @@ hostkey_callback (void *cls,
777 762
778#if VERBOSE > 1 763#if VERBOSE > 1
779 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 764 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
780 "Hostkey (%d/%d) created for peer `%s'\n", 765 "Hostkey (%d/%d) created for peer `%s'\n", num_peers - peers_left,
781 num_peers - peers_left, num_peers, GNUNET_i2s (id)); 766 num_peers, GNUNET_i2s (id));
782#endif 767#endif
783 768
784 769
@@ -792,9 +777,9 @@ hostkey_callback (void *cls,
792 GNUNET_SCHEDULER_cancel (die_task); 777 GNUNET_SCHEDULER_cancel (die_task);
793 /* Set up task in case topology creation doesn't finish 778 /* Set up task in case topology creation doesn't finish
794 * within a reasonable amount of time */ 779 * within a reasonable amount of time */
795 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 780 die_task =
796 &end_badly, 781 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
797 "from create_topology"); 782 "from create_topology");
798 GNUNET_SCHEDULER_add_now (&create_topology, NULL); 783 GNUNET_SCHEDULER_add_now (&create_topology, NULL);
799 ok = 0; 784 ok = 0;
800 } 785 }
@@ -802,9 +787,8 @@ hostkey_callback (void *cls,
802 787
803 788
804static void 789static void
805run (void *cls, 790run (void *cls, char *const *args, const char *cfgfile,
806 char *const *args, 791 const struct GNUNET_CONFIGURATION_Handle *cfg)
807 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
808{ 792{
809 char *topology_str; 793 char *topology_str;
810 char *connect_topology_str; 794 char *connect_topology_str;
@@ -962,9 +946,9 @@ check ()
962 GNUNET_GETOPT_OPTION_END 946 GNUNET_GETOPT_OPTION_END
963 }; 947 };
964 /* Run the run function as a new program */ 948 /* Run the run function as a new program */
965 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 949 ret =
966 argv, "test-dht-multipeer", "nohelp", 950 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
967 options, &run, &ok); 951 "test-dht-multipeer", "nohelp", options, &run, &ok);
968 if (ret != GNUNET_OK) 952 if (ret != GNUNET_OK)
969 { 953 {
970 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 954 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
diff --git a/src/dht/test_dht_twopeer.c b/src/dht/test_dht_twopeer.c
index 6ba3799dc..50a27a093 100644
--- a/src/dht/test_dht_twopeer.c
+++ b/src/dht/test_dht_twopeer.c
@@ -155,8 +155,7 @@ static void do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
155 * @param data pointer to the result data 155 * @param data pointer to the result data
156 */ 156 */
157void 157void
158get_result_iterator (void *cls, 158get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
159 struct GNUNET_TIME_Absolute exp,
160 const GNUNET_HashCode * key, 159 const GNUNET_HashCode * key,
161 const struct GNUNET_PeerIdentity *const *get_path, 160 const struct GNUNET_PeerIdentity *const *get_path,
162 const struct GNUNET_PeerIdentity *const *put_path, 161 const struct GNUNET_PeerIdentity *const *put_path,
@@ -200,8 +199,8 @@ get_result_iterator (void *cls,
200 199
201} 200}
202 201
203static void 202static void stop_retry_get (void *cls,
204stop_retry_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 203 const struct GNUNET_SCHEDULER_TaskContext *tc);
205 204
206static void 205static void
207get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 206get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -260,24 +259,20 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
260 (GNUNET_TIME_UNIT_SECONDS, 10), 259 (GNUNET_TIME_UNIT_SECONDS, 10),
261 &stop_retry_get, get_context); 260 &stop_retry_get, get_context);
262 261
263 get_context->get_handle = GNUNET_DHT_get_start (get_context->dht_handle, 262 get_context->get_handle =
264 GNUNET_TIME_relative_multiply 263 GNUNET_DHT_get_start (get_context->dht_handle,
265 (GNUNET_TIME_UNIT_SECONDS, 5), 264 GNUNET_TIME_relative_multiply
266 GNUNET_BLOCK_TYPE_DHT_HELLO, 265 (GNUNET_TIME_UNIT_SECONDS, 5),
267 &get_context-> 266 GNUNET_BLOCK_TYPE_DHT_HELLO,
268 peer->hashPubKey, 267 &get_context->peer->hashPubKey,
269 DEFAULT_GET_REPLICATION, 268 DEFAULT_GET_REPLICATION, GNUNET_DHT_RO_NONE, NULL,
270 GNUNET_DHT_RO_NONE, NULL, 0, 269 0, NULL, 0, &get_result_iterator, get_context);
271 NULL, 0, &get_result_iterator,
272 get_context);
273} 270}
274 271
275 272
276void 273void
277topology_callback (void *cls, 274topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
278 const struct GNUNET_PeerIdentity *first, 275 const struct GNUNET_PeerIdentity *second, uint32_t distance,
279 const struct GNUNET_PeerIdentity *second,
280 uint32_t distance,
281 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 276 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
282 const struct GNUNET_CONFIGURATION_Handle *second_cfg, 277 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
283 struct GNUNET_TESTING_Daemon *first_daemon, 278 struct GNUNET_TESTING_Daemon *first_daemon,
@@ -311,8 +306,8 @@ topology_callback (void *cls,
311 total_connections); 306 total_connections);
312#endif 307#endif
313 GNUNET_SCHEDULER_cancel (die_task); 308 GNUNET_SCHEDULER_cancel (die_task);
314 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 309 die_task =
315 &end_badly, "from test gets"); 310 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, "from test gets");
316 311
317 curr_get_ctx.dht_handle = peer1dht; 312 curr_get_ctx.dht_handle = peer1dht;
318 curr_get_ctx.peer = &peer2id; 313 curr_get_ctx.peer = &peer2id;
@@ -334,12 +329,10 @@ connect_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
334{ 329{
335 expected_connections = -1; 330 expected_connections = -1;
336 if ((pg != NULL) && (peers_left == 0)) 331 if ((pg != NULL) && (peers_left == 0))
337 expected_connections = GNUNET_TESTING_connect_topology (pg, 332 expected_connections =
338 GNUNET_TESTING_TOPOLOGY_CLIQUE, 333 GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_CLIQUE,
339 GNUNET_TESTING_TOPOLOGY_OPTION_ALL, 334 GNUNET_TESTING_TOPOLOGY_OPTION_ALL,
340 0.0, 335 0.0, TIMEOUT, 12, NULL, NULL);
341 TIMEOUT, 12, NULL,
342 NULL);
343 336
344 GNUNET_SCHEDULER_cancel (die_task); 337 GNUNET_SCHEDULER_cancel (die_task);
345 if (expected_connections == GNUNET_SYSERR) 338 if (expected_connections == GNUNET_SYSERR)
@@ -348,14 +341,13 @@ connect_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
348 "from connect topology (bad return)"); 341 "from connect topology (bad return)");
349 342
350 343
351 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 344 die_task =
352 &end_badly, 345 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
353 "from connect topology (timeout)"); 346 "from connect topology (timeout)");
354} 347}
355 348
356static void 349static void
357peers_started_callback (void *cls, 350peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
358 const struct GNUNET_PeerIdentity *id,
359 const struct GNUNET_CONFIGURATION_Handle *cfg, 351 const struct GNUNET_CONFIGURATION_Handle *cfg,
360 struct GNUNET_TESTING_Daemon *d, const char *emsg) 352 struct GNUNET_TESTING_Daemon *d, const char *emsg)
361{ 353{
@@ -399,9 +391,9 @@ peers_started_callback (void *cls,
399 GNUNET_SCHEDULER_cancel (die_task); 391 GNUNET_SCHEDULER_cancel (die_task);
400 /* Set up task in case topology creation doesn't finish 392 /* Set up task in case topology creation doesn't finish
401 * within a reasonable amount of time */ 393 * within a reasonable amount of time */
402 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 394 die_task =
403 &end_badly, 395 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
404 "from peers_started_callback"); 396 "from peers_started_callback");
405 397
406 GNUNET_SCHEDULER_add_now (&connect_topology, NULL); 398 GNUNET_SCHEDULER_add_now (&connect_topology, NULL);
407 ok = 0; 399 ok = 0;
@@ -409,9 +401,8 @@ peers_started_callback (void *cls,
409} 401}
410 402
411static void 403static void
412run (void *cls, 404run (void *cls, char *const *args, const char *cfgfile,
413 char *const *args, 405 const struct GNUNET_CONFIGURATION_Handle *cfg)
414 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
415{ 406{
416 407
417 if (GNUNET_YES != 408 if (GNUNET_YES !=
@@ -431,18 +422,13 @@ run (void *cls,
431 total_gets = num_peers; 422 total_gets = num_peers;
432 gets_succeeded = 0; 423 gets_succeeded = 0;
433 /* Set up a task to end testing if peer start fails */ 424 /* Set up a task to end testing if peer start fails */
434 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 425 die_task =
435 &end_badly, 426 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
436 "didn't start all daemons in reasonable amount of time!!!"); 427 "didn't start all daemons in reasonable amount of time!!!");
437 428
438 pg = GNUNET_TESTING_daemons_start (cfg, 429 pg = GNUNET_TESTING_daemons_start (cfg, num_peers, 10, num_peers, TIMEOUT,
439 num_peers, 430 NULL, NULL, &peers_started_callback, NULL,
440 10, 431 &topology_callback, NULL, NULL);
441 num_peers,
442 TIMEOUT,
443 NULL, NULL,
444 &peers_started_callback,
445 NULL, &topology_callback, NULL, NULL);
446 432
447} 433}
448 434
@@ -462,9 +448,9 @@ check ()
462 struct GNUNET_GETOPT_CommandLineOption options[] = { 448 struct GNUNET_GETOPT_CommandLineOption options[] = {
463 GNUNET_GETOPT_OPTION_END 449 GNUNET_GETOPT_OPTION_END
464 }; 450 };
465 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 451 ret =
466 argv, "test-dht-twopeer", "nohelp", 452 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
467 options, &run, &ok); 453 "test-dht-twopeer", "nohelp", options, &run, &ok);
468 if (ret != GNUNET_OK) 454 if (ret != GNUNET_OK)
469 { 455 {
470 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 456 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
diff --git a/src/dht/test_dht_twopeer_path_tracking.c b/src/dht/test_dht_twopeer_path_tracking.c
index ab0b1edd2..9985939ae 100644
--- a/src/dht/test_dht_twopeer_path_tracking.c
+++ b/src/dht/test_dht_twopeer_path_tracking.c
@@ -188,8 +188,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
188 * @param data pointer to the result data 188 * @param data pointer to the result data
189 */ 189 */
190void 190void
191get_result_iterator (void *cls, 191get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
192 struct GNUNET_TIME_Absolute exp,
193 const GNUNET_HashCode * key, 192 const GNUNET_HashCode * key,
194 const struct GNUNET_PeerIdentity *const *get_path, 193 const struct GNUNET_PeerIdentity *const *get_path,
195 const struct GNUNET_PeerIdentity *const *put_path, 194 const struct GNUNET_PeerIdentity *const *put_path,
@@ -262,9 +261,9 @@ static void
262put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 261put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
263{ 262{
264 GNUNET_SCHEDULER_cancel (die_task); 263 GNUNET_SCHEDULER_cancel (die_task);
265 die_task = GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, 264 die_task =
266 &end_badly, 265 GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &end_badly,
267 "waiting for get response (data not found)"); 266 "waiting for get response (data not found)");
268 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 267 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
269 (GNUNET_TIME_UNIT_SECONDS, 10), &do_get, NULL); 268 (GNUNET_TIME_UNIT_SECONDS, 10), &do_get, NULL);
270} 269}
@@ -282,13 +281,9 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
282 memset (data, 43, sizeof (data)); 281 memset (data, 43, sizeof (data));
283 282
284 /* Insert the data at the first peer */ 283 /* Insert the data at the first peer */
285 GNUNET_DHT_put (peer1dht, 284 GNUNET_DHT_put (peer1dht, &key, DEFAULT_PUT_REPLICATION,
286 &key, 285 GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_BLOCK_TYPE_TEST,
287 DEFAULT_PUT_REPLICATION, 286 sizeof (data), data, GNUNET_TIME_UNIT_FOREVER_ABS,
288 GNUNET_DHT_RO_RECORD_ROUTE,
289 GNUNET_BLOCK_TYPE_TEST,
290 sizeof (data), data,
291 GNUNET_TIME_UNIT_FOREVER_ABS,
292 GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, NULL); 287 GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, NULL);
293} 288}
294 289
@@ -302,10 +297,8 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
302 * failure (peers failed to connect). 297 * failure (peers failed to connect).
303 */ 298 */
304void 299void
305topology_callback (void *cls, 300topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
306 const struct GNUNET_PeerIdentity *first, 301 const struct GNUNET_PeerIdentity *second, uint32_t distance,
307 const struct GNUNET_PeerIdentity *second,
308 uint32_t distance,
309 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 302 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
310 const struct GNUNET_CONFIGURATION_Handle *second_cfg, 303 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
311 struct GNUNET_TESTING_Daemon *first_daemon, 304 struct GNUNET_TESTING_Daemon *first_daemon,
@@ -339,8 +332,8 @@ topology_callback (void *cls,
339 total_connections); 332 total_connections);
340#endif 333#endif
341 GNUNET_SCHEDULER_cancel (die_task); 334 GNUNET_SCHEDULER_cancel (die_task);
342 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 335 die_task =
343 &end_badly, "from test gets"); 336 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, "from test gets");
344 337
345 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 338 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
346 (GNUNET_TIME_UNIT_SECONDS, 2), &do_put, NULL); 339 (GNUNET_TIME_UNIT_SECONDS, 2), &do_put, NULL);
@@ -367,8 +360,7 @@ topology_callback (void *cls,
367 * @param emsg NULL if peer started, non-NULL on error 360 * @param emsg NULL if peer started, non-NULL on error
368 */ 361 */
369static void 362static void
370peers_started_callback (void *cls, 363peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
371 const struct GNUNET_PeerIdentity *id,
372 const struct GNUNET_CONFIGURATION_Handle *cfg, 364 const struct GNUNET_CONFIGURATION_Handle *cfg,
373 struct GNUNET_TESTING_Daemon *d, const char *emsg) 365 struct GNUNET_TESTING_Daemon *d, const char *emsg)
374{ 366{
@@ -415,12 +407,10 @@ peers_started_callback (void *cls,
415 if ((pg != NULL)) /* Sanity check */ 407 if ((pg != NULL)) /* Sanity check */
416 { 408 {
417 /* Connect peers in a "straight line" topology, return the number of expected connections */ 409 /* Connect peers in a "straight line" topology, return the number of expected connections */
418 expected_connections = GNUNET_TESTING_connect_topology (pg, 410 expected_connections =
419 GNUNET_TESTING_TOPOLOGY_LINE, 411 GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_LINE,
420 GNUNET_TESTING_TOPOLOGY_OPTION_ALL, 412 GNUNET_TESTING_TOPOLOGY_OPTION_ALL,
421 0.0, 413 0.0, TIMEOUT, 2, NULL, NULL);
422 TIMEOUT,
423 2, NULL, NULL);
424 } 414 }
425 415
426 /* Cancel current timeout fail task */ 416 /* Cancel current timeout fail task */
@@ -431,17 +421,16 @@ peers_started_callback (void *cls,
431 "from connect topology (bad return)"); 421 "from connect topology (bad return)");
432 422
433 /* Schedule timeout on failure task */ 423 /* Schedule timeout on failure task */
434 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 424 die_task =
435 &end_badly, 425 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
436 "from connect topology (timeout)"); 426 "from connect topology (timeout)");
437 ok = 0; 427 ok = 0;
438 } 428 }
439} 429}
440 430
441static void 431static void
442run (void *cls, 432run (void *cls, char *const *args, const char *cfgfile,
443 char *const *args, 433 const struct GNUNET_CONFIGURATION_Handle *cfg)
444 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
445{ 434{
446 435
447 /* Get path from configuration file */ 436 /* Get path from configuration file */
@@ -463,20 +452,18 @@ run (void *cls,
463 peers_left = num_peers; 452 peers_left = num_peers;
464 453
465 /* Set up a task to end testing if peer start fails */ 454 /* Set up a task to end testing if peer start fails */
466 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 455 die_task =
467 &end_badly, 456 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
468 "didn't start all daemons in reasonable amount of time!!!"); 457 "didn't start all daemons in reasonable amount of time!!!");
469 458
470 /* Start num_peers peers, call peers_started_callback on peer start, topology_callback on peer connect */ 459 /* Start num_peers peers, call peers_started_callback on peer start, topology_callback on peer connect */
471 /* Read the API documentation for other parameters! */ 460 /* Read the API documentation for other parameters! */
472 pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of peers */ 461 pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of peers */
473 peers_left, /* Number of outstanding connections */ 462 peers_left, /* Number of outstanding connections */
474 peers_left, /* Number of parallel ssh connections, or peers being started at once */ 463 peers_left, /* Number of parallel ssh connections, or peers being started at once */
475 TIMEOUT, 464 TIMEOUT, NULL, NULL,
476 NULL, 465 &peers_started_callback, NULL,
477 NULL, 466 &topology_callback, NULL, NULL);
478 &peers_started_callback,
479 NULL, &topology_callback, NULL, NULL);
480 467
481} 468}
482 469
@@ -498,9 +485,10 @@ check ()
498 GNUNET_GETOPT_OPTION_END 485 GNUNET_GETOPT_OPTION_END
499 }; 486 };
500 /* Run the run function as a new program */ 487 /* Run the run function as a new program */
501 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 488 ret =
502 argv, "test-dht-twopeer-put-get", "nohelp", 489 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
503 options, &run, &ok); 490 "test-dht-twopeer-put-get", "nohelp", options, &run,
491 &ok);
504 if (ret != GNUNET_OK) 492 if (ret != GNUNET_OK)
505 { 493 {
506 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 494 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
diff --git a/src/dht/test_dht_twopeer_put_get.c b/src/dht/test_dht_twopeer_put_get.c
index 9db0ca385..8e77837b2 100644
--- a/src/dht/test_dht_twopeer_put_get.c
+++ b/src/dht/test_dht_twopeer_put_get.c
@@ -210,13 +210,12 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
210 * @param data pointer to the result data 210 * @param data pointer to the result data
211 */ 211 */
212void 212void
213get_result_iterator (void *cls, 213get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
214 struct GNUNET_TIME_Absolute exp,
215 const GNUNET_HashCode * key, 214 const GNUNET_HashCode * key,
216 const struct GNUNET_PeerIdentity *const *get_path, 215 const struct GNUNET_PeerIdentity *const *get_path,
217 const struct GNUNET_PeerIdentity *const *put_path, 216 const struct GNUNET_PeerIdentity *const *put_path,
218 enum GNUNET_BLOCK_Type type, 217 enum GNUNET_BLOCK_Type type, size_t size,
219 size_t size, const void *result_data) 218 const void *result_data)
220{ 219{
221 GNUNET_HashCode original_key; /* Key data was stored data under */ 220 GNUNET_HashCode original_key; /* Key data was stored data under */
222 char original_data[4]; /* Made up data that was stored */ 221 char original_data[4]; /* Made up data that was stored */
@@ -273,9 +272,7 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
273#else 272#else
274 GNUNET_BLOCK_TYPE_TEST, 273 GNUNET_BLOCK_TYPE_TEST,
275#endif 274#endif
276 &key, 275 &key, DEFAULT_GET_REPLICATION, GNUNET_DHT_RO_NONE,
277 DEFAULT_GET_REPLICATION,
278 GNUNET_DHT_RO_NONE,
279 NULL, 0, NULL, 0, &get_result_iterator, NULL); 276 NULL, 0, NULL, 0, &get_result_iterator, NULL);
280} 277}
281 278
@@ -287,9 +284,9 @@ static void
287put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 284put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
288{ 285{
289 GNUNET_SCHEDULER_cancel (die_task); 286 GNUNET_SCHEDULER_cancel (die_task);
290 die_task = GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, 287 die_task =
291 &end_badly, 288 GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &end_badly,
292 "waiting for get response (data not found)"); 289 "waiting for get response (data not found)");
293 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 290 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
294 (GNUNET_TIME_UNIT_SECONDS, 10), &do_get, NULL); 291 (GNUNET_TIME_UNIT_SECONDS, 10), &do_get, NULL);
295} 292}
@@ -309,14 +306,10 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
309 memset (data, 43, sizeof (data)); 306 memset (data, 43, sizeof (data));
310 307
311 /* Insert the data at the first peer */ 308 /* Insert the data at the first peer */
312 GNUNET_DHT_put (peer1dht, 309 GNUNET_DHT_put (peer1dht, &key, DEFAULT_PUT_REPLICATION, GNUNET_DHT_RO_NONE,
313 &key, 310 GNUNET_BLOCK_TYPE_TEST, sizeof (data), data,
314 DEFAULT_PUT_REPLICATION, 311 GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL,
315 GNUNET_DHT_RO_NONE, 312 &put_finished, NULL);
316 GNUNET_BLOCK_TYPE_TEST,
317 sizeof (data), data,
318 GNUNET_TIME_UNIT_FOREVER_ABS,
319 GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, NULL);
320} 313}
321#else 314#else
322 315
@@ -353,24 +346,19 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
353 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS); 346 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS);
354 347
355 /* Sign the block */ 348 /* Sign the block */
356 if (GNUNET_OK != GNUNET_CRYPTO_rsa_sign (my_private_key, 349 if (GNUNET_OK !=
357 &data.purpose, &data.signature)) 350 GNUNET_CRYPTO_rsa_sign (my_private_key, &data.purpose, &data.signature))
358 { 351 {
359 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not sign DNS_Record\n"); 352 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not sign DNS_Record\n");
360 return; 353 return;
361 } 354 }
362 GNUNET_CRYPTO_rsa_key_free (my_private_key); 355 GNUNET_CRYPTO_rsa_key_free (my_private_key);
363 356
364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 357 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting with key %08x\n",
365 "Putting with key %08x\n",
366 *((unsigned int *) &data.service_descriptor)); 358 *((unsigned int *) &data.service_descriptor));
367 359
368 GNUNET_DHT_put (peer1dht, 360 GNUNET_DHT_put (peer1dht, &data.service_descriptor, DEFAULT_PUT_REPLICATION,
369 &data.service_descriptor, 361 GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_DNS, size,
370 DEFAULT_PUT_REPLICATION,
371 GNUNET_DHT_RO_NONE,
372 GNUNET_BLOCK_TYPE_DNS,
373 size,
374 (char *) &data, 362 (char *) &data,
375 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS), 363 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS),
376 GNUNET_TIME_UNIT_MINUTES, &put_finished, NULL); 364 GNUNET_TIME_UNIT_MINUTES, &put_finished, NULL);
@@ -387,10 +375,8 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
387 * failure (peers failed to connect). 375 * failure (peers failed to connect).
388 */ 376 */
389void 377void
390topology_callback (void *cls, 378topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
391 const struct GNUNET_PeerIdentity *first, 379 const struct GNUNET_PeerIdentity *second, uint32_t distance,
392 const struct GNUNET_PeerIdentity *second,
393 uint32_t distance,
394 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 380 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
395 const struct GNUNET_CONFIGURATION_Handle *second_cfg, 381 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
396 struct GNUNET_TESTING_Daemon *first_daemon, 382 struct GNUNET_TESTING_Daemon *first_daemon,
@@ -424,8 +410,8 @@ topology_callback (void *cls,
424 total_connections); 410 total_connections);
425#endif 411#endif
426 GNUNET_SCHEDULER_cancel (die_task); 412 GNUNET_SCHEDULER_cancel (die_task);
427 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 413 die_task =
428 &end_badly, "from test gets"); 414 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, "from test gets");
429 415
430 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 416 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
431 (GNUNET_TIME_UNIT_SECONDS, 2), &do_put, NULL); 417 (GNUNET_TIME_UNIT_SECONDS, 2), &do_put, NULL);
@@ -452,8 +438,7 @@ topology_callback (void *cls,
452 * @param emsg NULL if peer started, non-NULL on error 438 * @param emsg NULL if peer started, non-NULL on error
453 */ 439 */
454static void 440static void
455peers_started_callback (void *cls, 441peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
456 const struct GNUNET_PeerIdentity *id,
457 const struct GNUNET_CONFIGURATION_Handle *cfg, 442 const struct GNUNET_CONFIGURATION_Handle *cfg,
458 struct GNUNET_TESTING_Daemon *d, const char *emsg) 443 struct GNUNET_TESTING_Daemon *d, const char *emsg)
459{ 444{
@@ -500,12 +485,10 @@ peers_started_callback (void *cls,
500 if ((pg != NULL)) /* Sanity check */ 485 if ((pg != NULL)) /* Sanity check */
501 { 486 {
502 /* Connect peers in a "straight line" topology, return the number of expected connections */ 487 /* Connect peers in a "straight line" topology, return the number of expected connections */
503 expected_connections = GNUNET_TESTING_connect_topology (pg, 488 expected_connections =
504 GNUNET_TESTING_TOPOLOGY_LINE, 489 GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_LINE,
505 GNUNET_TESTING_TOPOLOGY_OPTION_ALL, 490 GNUNET_TESTING_TOPOLOGY_OPTION_ALL,
506 0.0, 491 0.0, TIMEOUT, 12, NULL, NULL);
507 TIMEOUT,
508 12, NULL, NULL);
509 } 492 }
510 493
511 /* Cancel current timeout fail task */ 494 /* Cancel current timeout fail task */
@@ -516,17 +499,16 @@ peers_started_callback (void *cls,
516 "from connect topology (bad return)"); 499 "from connect topology (bad return)");
517 500
518 /* Schedule timeout on failure task */ 501 /* Schedule timeout on failure task */
519 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 502 die_task =
520 &end_badly, 503 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
521 "from connect topology (timeout)"); 504 "from connect topology (timeout)");
522 ok = 0; 505 ok = 0;
523 } 506 }
524} 507}
525 508
526static void 509static void
527run (void *cls, 510run (void *cls, char *const *args, const char *cfgfile,
528 char *const *args, 511 const struct GNUNET_CONFIGURATION_Handle *cfg)
529 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
530{ 512{
531 513
532 /* Get path from configuration file */ 514 /* Get path from configuration file */
@@ -548,21 +530,15 @@ run (void *cls,
548 peers_left = num_peers; 530 peers_left = num_peers;
549 531
550 /* Set up a task to end testing if peer start fails */ 532 /* Set up a task to end testing if peer start fails */
551 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 533 die_task =
552 &end_badly, 534 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
553 "didn't start all daemons in reasonable amount of time!!!"); 535 "didn't start all daemons in reasonable amount of time!!!");
554 536
555 /* Start num_peers peers, call peers_started_callback on peer start, topology_callback on peer connect */ 537 /* Start num_peers peers, call peers_started_callback on peer start, topology_callback on peer connect */
556 /* Read the API documentation for other parameters! */ 538 /* Read the API documentation for other parameters! */
557 pg = GNUNET_TESTING_daemons_start (cfg, 539 pg = GNUNET_TESTING_daemons_start (cfg, num_peers, 2, 2, TIMEOUT, NULL, NULL,
558 num_peers, 540 &peers_started_callback, NULL,
559 2, 541 &topology_callback, NULL, NULL);
560 2,
561 TIMEOUT,
562 NULL,
563 NULL,
564 &peers_started_callback,
565 NULL, &topology_callback, NULL, NULL);
566 542
567} 543}
568 544
@@ -584,9 +560,10 @@ check ()
584 GNUNET_GETOPT_OPTION_END 560 GNUNET_GETOPT_OPTION_END
585 }; 561 };
586 /* Run the run function as a new program */ 562 /* Run the run function as a new program */
587 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 563 ret =
588 argv, "test-dht-twopeer-put-get", "nohelp", 564 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
589 options, &run, &ok); 565 "test-dht-twopeer-put-get", "nohelp", options, &run,
566 &ok);
590 if (ret != GNUNET_OK) 567 if (ret != GNUNET_OK)
591 { 568 {
592 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 569 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
diff --git a/src/dht/test_dhtlog.c b/src/dht/test_dhtlog.c
index 4021f5db5..89ec97d6c 100644
--- a/src/dht/test_dhtlog.c
+++ b/src/dht/test_dhtlog.c
@@ -195,9 +195,8 @@ test (struct GNUNET_DHTLOG_Handle *api)
195 195
196 196
197static void 197static void
198run (void *cls, 198run (void *cls, char *const *args, const char *cfgfile,
199 char *const *args, 199 const struct GNUNET_CONFIGURATION_Handle *cfg)
200 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
201{ 200{
202 struct GNUNET_DHTLOG_Handle *api; 201 struct GNUNET_DHTLOG_Handle *api;
203 202
@@ -229,8 +228,8 @@ check ()
229 struct GNUNET_GETOPT_CommandLineOption options[] = { 228 struct GNUNET_GETOPT_CommandLineOption options[] = {
230 GNUNET_GETOPT_OPTION_END 229 GNUNET_GETOPT_OPTION_END
231 }; 230 };
232 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 231 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
233 argv, "test-dhtlog-api", "nohelp", options, &run, NULL); 232 "test-dhtlog-api", "nohelp", options, &run, NULL);
234 if (ok != 0) 233 if (ok != 0)
235 fprintf (stderr, "Test failed with error code: %d\n", ok); 234 fprintf (stderr, "Test failed with error code: %d\n", ok);
236 return ok; 235 return ok;
diff --git a/src/dv/dv_api.c b/src/dv/dv_api.c
index 7a250b5a6..3450e5844 100644
--- a/src/dv/dv_api.c
+++ b/src/dv/dv_api.c
@@ -282,15 +282,13 @@ process_pending_message (struct GNUNET_DV_Handle *handle)
282 handle->current->next = NULL; 282 handle->current->next = NULL;
283 283
284 if (NULL == 284 if (NULL ==
285 (handle->th = GNUNET_CLIENT_notify_transmit_ready (handle->client, 285 (handle->th =
286 ntohs 286 GNUNET_CLIENT_notify_transmit_ready (handle->client,
287 (handle->current-> 287 ntohs (handle->current->msg->header.
288 msg->header.size), 288 size),
289 handle->current-> 289 handle->current->msg->timeout,
290 msg->timeout, 290 GNUNET_YES, &transmit_pending,
291 GNUNET_YES, 291 handle)))
292 &transmit_pending,
293 handle)))
294 { 292 {
295#if DEBUG_DV 293#if DEBUG_DV
296 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 294 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -397,12 +395,10 @@ handle_message_receipt (void *cls, const struct GNUNET_MessageHeader *msg)
397 ntohl (received_msg->distance)); 395 ntohl (received_msg->distance));
398#endif 396#endif
399 397
400 handle->receive_handler (handle->receive_cls, 398 handle->receive_handler (handle->receive_cls, &received_msg->sender,
401 &received_msg->sender, 399 packed_msg, packed_msg_len,
402 packed_msg, 400 ntohl (received_msg->distance), sender_address,
403 packed_msg_len, 401 sender_address_len);
404 ntohl (received_msg->distance),
405 sender_address, sender_address_len);
406 402
407 GNUNET_free (sender_address); 403 GNUNET_free (sender_address);
408 break; 404 break;
@@ -431,9 +427,8 @@ handle_message_receipt (void *cls, const struct GNUNET_MessageHeader *msg)
431 default: 427 default:
432 break; 428 break;
433 } 429 }
434 GNUNET_CLIENT_receive (handle->client, 430 GNUNET_CLIENT_receive (handle->client, &handle_message_receipt, handle,
435 &handle_message_receipt, 431 GNUNET_TIME_UNIT_FOREVER_REL);
436 handle, GNUNET_TIME_UNIT_FOREVER_REL);
437} 432}
438 433
439/** 434/**
@@ -454,14 +449,11 @@ handle_message_receipt (void *cls, const struct GNUNET_MessageHeader *msg)
454 */ 449 */
455int 450int
456GNUNET_DV_send (struct GNUNET_DV_Handle *dv_handle, 451GNUNET_DV_send (struct GNUNET_DV_Handle *dv_handle,
457 const struct GNUNET_PeerIdentity *target, 452 const struct GNUNET_PeerIdentity *target, const char *msgbuf,
458 const char *msgbuf, 453 size_t msgbuf_size, unsigned int priority,
459 size_t msgbuf_size, 454 struct GNUNET_TIME_Relative timeout, const void *addr,
460 unsigned int priority, 455 size_t addrlen, GNUNET_TRANSPORT_TransmitContinuation cont,
461 struct GNUNET_TIME_Relative timeout, 456 void *cont_cls)
462 const void *addr,
463 size_t addrlen,
464 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
465{ 457{
466 struct GNUNET_DV_SendMessage *msg; 458 struct GNUNET_DV_SendMessage *msg;
467 struct SendCallbackContext *send_ctx; 459 struct SendCallbackContext *send_ctx;
@@ -537,9 +529,8 @@ transmit_start (void *cls, size_t size, void *buf)
537 memcpy (buf, start_context->message, tsize); 529 memcpy (buf, start_context->message, tsize);
538 GNUNET_free (start_context->message); 530 GNUNET_free (start_context->message);
539 GNUNET_free (start_context); 531 GNUNET_free (start_context);
540 GNUNET_CLIENT_receive (handle->client, 532 GNUNET_CLIENT_receive (handle->client, &handle_message_receipt, handle,
541 &handle_message_receipt, 533 GNUNET_TIME_UNIT_FOREVER_REL);
542 handle, GNUNET_TIME_UNIT_FOREVER_REL);
543 534
544 535
545 return tsize; 536 return tsize;
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c
index 4b68f69b1..876d056ac 100644
--- a/src/dv/gnunet-service-dv.c
+++ b/src/dv/gnunet-service-dv.c
@@ -662,8 +662,7 @@ static unsigned long long max_table_size;
662 * respective neighbor. 662 * respective neighbor.
663 */ 663 */
664static int 664static int
665find_destination (void *cls, 665find_destination (void *cls, struct GNUNET_CONTAINER_HeapNode *node,
666 struct GNUNET_CONTAINER_HeapNode *node,
667 void *element, GNUNET_CONTAINER_HeapCostType cost) 666 void *element, GNUNET_CONTAINER_HeapCostType cost)
668{ 667{
669 struct FindDestinationContext *fdc = cls; 668 struct FindDestinationContext *fdc = cls;
@@ -752,21 +751,20 @@ transmit_to_plugin (void *cls, size_t size, void *buf)
752 while ((NULL != (reply = plugin_pending_head)) && 751 while ((NULL != (reply = plugin_pending_head)) &&
753 (size >= off + (msize = ntohs (reply->msg->size)))) 752 (size >= off + (msize = ntohs (reply->msg->size))))
754 { 753 {
755 GNUNET_CONTAINER_DLL_remove (plugin_pending_head, 754 GNUNET_CONTAINER_DLL_remove (plugin_pending_head, plugin_pending_tail,
756 plugin_pending_tail, reply); 755 reply);
757 memcpy (&cbuf[off], reply->msg, msize); 756 memcpy (&cbuf[off], reply->msg, msize);
758 GNUNET_free (reply); 757 GNUNET_free (reply);
759 off += msize; 758 off += msize;
760 } 759 }
761 760
762 if (plugin_pending_head != NULL) 761 if (plugin_pending_head != NULL)
763 plugin_transmit_handle = GNUNET_SERVER_notify_transmit_ready (client_handle, 762 plugin_transmit_handle =
764 ntohs 763 GNUNET_SERVER_notify_transmit_ready (client_handle,
765 (plugin_pending_head->msg-> 764 ntohs (plugin_pending_head->
766 size), 765 msg->size),
767 GNUNET_TIME_UNIT_FOREVER_REL, 766 GNUNET_TIME_UNIT_FOREVER_REL,
768 &transmit_to_plugin, 767 &transmit_to_plugin, NULL);
769 NULL);
770 768
771 return off; 769 return off;
772} 770}
@@ -783,8 +781,7 @@ transmit_to_plugin (void *cls, size_t size, void *buf)
783 */ 781 */
784void 782void
785send_to_plugin (const struct GNUNET_PeerIdentity *sender, 783send_to_plugin (const struct GNUNET_PeerIdentity *sender,
786 const struct GNUNET_MessageHeader *message, 784 const struct GNUNET_MessageHeader *message, size_t message_size,
787 size_t message_size,
788 struct GNUNET_PeerIdentity *distant_neighbor, size_t cost) 785 struct GNUNET_PeerIdentity *distant_neighbor, size_t cost)
789{ 786{
790 struct GNUNET_DV_MessageReceived *received_msg; 787 struct GNUNET_DV_MessageReceived *received_msg;
@@ -877,14 +874,13 @@ try_core_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
877 return; /* Message send already in progress */ 874 return; /* Message send already in progress */
878 875
879 if ((pending != NULL) && (coreAPI != NULL)) 876 if ((pending != NULL) && (coreAPI != NULL))
880 core_transmit_handle = GNUNET_CORE_notify_transmit_ready (coreAPI, 877 core_transmit_handle =
881 GNUNET_YES, 878 GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES,
882 pending->importance, 879 pending->importance,
883 pending->timeout, 880 pending->timeout,
884 &pending->recipient, 881 &pending->recipient,
885 pending->msg_size, 882 pending->msg_size,
886 &core_transmit_notify, 883 &core_transmit_notify, NULL);
887 NULL);
888} 884}
889 885
890 886
@@ -1003,9 +999,9 @@ send_message_via (const struct GNUNET_PeerIdentity *sender,
1003 find_context.via = recipient; 999 find_context.via = recipient;
1004 find_context.tid = 0; 1000 find_context.tid = 0;
1005 GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors, 1001 GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors,
1006 &send_context-> 1002 &send_context->distant_peer->
1007 distant_peer->hashPubKey, 1003 hashPubKey, &find_specific_id,
1008 &find_specific_id, &find_context); 1004 &find_context);
1009 1005
1010 if (find_context.tid == 0) 1006 if (find_context.tid == 0)
1011 { 1007 {
@@ -1019,8 +1015,9 @@ send_message_via (const struct GNUNET_PeerIdentity *sender,
1019 if (0 == (memcmp (&my_identity, sender, sizeof (struct GNUNET_PeerIdentity)))) 1015 if (0 == (memcmp (&my_identity, sender, sizeof (struct GNUNET_PeerIdentity))))
1020 { 1016 {
1021 sender_id = 0; 1017 sender_id = 0;
1022 source = GNUNET_CONTAINER_multihashmap_get (extended_neighbors, 1018 source =
1023 &sender->hashPubKey); 1019 GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
1020 &sender->hashPubKey);
1024 if (source != NULL) 1021 if (source != NULL)
1025 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1022 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1026 "%s: send_message_via found %s, myself in extended peer list???\n", 1023 "%s: send_message_via found %s, myself in extended peer list???\n",
@@ -1028,8 +1025,9 @@ send_message_via (const struct GNUNET_PeerIdentity *sender,
1028 } 1025 }
1029 else 1026 else
1030 { 1027 {
1031 source = GNUNET_CONTAINER_multihashmap_get (extended_neighbors, 1028 source =
1032 &sender->hashPubKey); 1029 GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
1030 &sender->hashPubKey);
1033 if (source == NULL) 1031 if (source == NULL)
1034 { 1032 {
1035 /* sender unknown to us, drop! */ 1033 /* sender unknown to us, drop! */
@@ -1067,8 +1065,7 @@ send_message_via (const struct GNUNET_PeerIdentity *sender,
1067 "DV", &shortname, GNUNET_i2s (recipient), msg_size); 1065 "DV", &shortname, GNUNET_i2s (recipient), msg_size);
1068#endif 1066#endif
1069 1067
1070 GNUNET_CONTAINER_DLL_insert_after (core_pending_head, 1068 GNUNET_CONTAINER_DLL_insert_after (core_pending_head, core_pending_tail,
1071 core_pending_tail,
1072 core_pending_tail, pending_message); 1069 core_pending_tail, pending_message);
1073 1070
1074 GNUNET_SCHEDULER_add_now (try_core_send, NULL); 1071 GNUNET_SCHEDULER_add_now (try_core_send, NULL);
@@ -1117,10 +1114,9 @@ static int
1117send_message (const struct GNUNET_PeerIdentity *recipient, 1114send_message (const struct GNUNET_PeerIdentity *recipient,
1118 const struct GNUNET_PeerIdentity *sender, 1115 const struct GNUNET_PeerIdentity *sender,
1119 const struct DistantNeighbor *specific_neighbor, 1116 const struct DistantNeighbor *specific_neighbor,
1120 const struct GNUNET_MessageHeader *message, 1117 const struct GNUNET_MessageHeader *message, size_t message_size,
1121 size_t message_size, 1118 unsigned int importance, unsigned int uid,
1122 unsigned int importance, 1119 struct GNUNET_TIME_Relative timeout)
1123 unsigned int uid, struct GNUNET_TIME_Relative timeout)
1124{ 1120{
1125 p2p_dv_MESSAGE_Data *toSend; 1121 p2p_dv_MESSAGE_Data *toSend;
1126 unsigned int msg_size; 1122 unsigned int msg_size;
@@ -1160,12 +1156,13 @@ send_message (const struct GNUNET_PeerIdentity *recipient,
1160 } 1156 }
1161 recipient_id = target->referrer_id; 1157 recipient_id = target->referrer_id;
1162 1158
1163 source = GNUNET_CONTAINER_multihashmap_get (extended_neighbors, 1159 source =
1164 &sender->hashPubKey); 1160 GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
1161 &sender->hashPubKey);
1165 if (source == NULL) 1162 if (source == NULL)
1166 { 1163 {
1167 if (0 != (memcmp (&my_identity, 1164 if (0 !=
1168 sender, sizeof (struct GNUNET_PeerIdentity)))) 1165 (memcmp (&my_identity, sender, sizeof (struct GNUNET_PeerIdentity))))
1169 { 1166 {
1170 /* sender unknown to us, drop! */ 1167 /* sender unknown to us, drop! */
1171 return GNUNET_SYSERR; 1168 return GNUNET_SYSERR;
@@ -1229,8 +1226,7 @@ send_message (const struct GNUNET_PeerIdentity *recipient,
1229 "%s: Sending message, but anticipate recipient will not know sender!!!\n\n\n", 1226 "%s: Sending message, but anticipate recipient will not know sender!!!\n\n\n",
1230 my_short_id); 1227 my_short_id);
1231 } 1228 }
1232 GNUNET_CONTAINER_DLL_insert_after (core_pending_head, 1229 GNUNET_CONTAINER_DLL_insert_after (core_pending_head, core_pending_tail,
1233 core_pending_tail,
1234 core_pending_tail, pending_message); 1230 core_pending_tail, pending_message);
1235#if DEBUG_DV 1231#if DEBUG_DV
1236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1292,8 +1288,7 @@ checkPeerID (void *cls, const GNUNET_HashCode * key, void *value)
1292 * @param message the actual message 1288 * @param message the actual message
1293 */ 1289 */
1294void 1290void
1295tokenized_message_handler (void *cls, 1291tokenized_message_handler (void *cls, void *client,
1296 void *client,
1297 const struct GNUNET_MessageHeader *message) 1292 const struct GNUNET_MessageHeader *message)
1298{ 1293{
1299 struct TokenizedMessageContext *ctx = client; 1294 struct TokenizedMessageContext *ctx = client;
@@ -1335,13 +1330,9 @@ send_message_delayed (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1335 1330
1336 if (msg_ctx != NULL) 1331 if (msg_ctx != NULL)
1337 { 1332 {
1338 send_message (&msg_ctx->dest, 1333 send_message (&msg_ctx->dest, &msg_ctx->sender, NULL, msg_ctx->message,
1339 &msg_ctx->sender, 1334 msg_ctx->message_size, default_dv_priority, msg_ctx->uid,
1340 NULL, 1335 GNUNET_TIME_relative_get_forever ());
1341 msg_ctx->message,
1342 msg_ctx->message_size,
1343 default_dv_priority,
1344 msg_ctx->uid, GNUNET_TIME_relative_get_forever ());
1345 GNUNET_free (msg_ctx->message); 1336 GNUNET_free (msg_ctx->message);
1346 GNUNET_free (msg_ctx); 1337 GNUNET_free (msg_ctx);
1347 } 1338 }
@@ -1404,8 +1395,7 @@ get_atsi_latency (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1404 * @param atsi transport ATS information (latency, distance, etc.) 1395 * @param atsi transport ATS information (latency, distance, etc.)
1405 */ 1396 */
1406static int 1397static int
1407handle_dv_data_message (void *cls, 1398handle_dv_data_message (void *cls, const struct GNUNET_PeerIdentity *peer,
1408 const struct GNUNET_PeerIdentity *peer,
1409 const struct GNUNET_MessageHeader *message, 1399 const struct GNUNET_MessageHeader *message,
1410 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 1400 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1411{ 1401{
@@ -1478,8 +1468,9 @@ handle_dv_data_message (void *cls,
1478 } 1468 }
1479 else 1469 else
1480 { 1470 {
1481 pos = GNUNET_CONTAINER_multihashmap_get (extended_neighbors, 1471 pos =
1482 &peer->hashPubKey); 1472 GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
1473 &peer->hashPubKey);
1483 } 1474 }
1484#else 1475#else
1485 pos = dn->referee_head; 1476 pos = dn->referee_head;
@@ -1547,11 +1538,9 @@ handle_dv_data_message (void *cls,
1547 tkm_ctx.peer = peer; 1538 tkm_ctx.peer = peer;
1548 tkm_ctx.distant = pos; 1539 tkm_ctx.distant = pos;
1549 tkm_ctx.uid = ntohl (incoming->uid); 1540 tkm_ctx.uid = ntohl (incoming->uid);
1550 if (GNUNET_OK != GNUNET_SERVER_mst_receive (coreMST, 1541 if (GNUNET_OK !=
1551 &tkm_ctx, 1542 GNUNET_SERVER_mst_receive (coreMST, &tkm_ctx, cbuf, packed_message_size,
1552 cbuf, 1543 GNUNET_NO, GNUNET_NO))
1553 packed_message_size,
1554 GNUNET_NO, GNUNET_NO))
1555 { 1544 {
1556 GNUNET_break_op (0); 1545 GNUNET_break_op (0);
1557 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1546 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -1634,14 +1623,11 @@ handle_dv_data_message (void *cls,
1634 else 1623 else
1635#endif 1624#endif
1636 { 1625 {
1637 ret = send_message (destination, 1626 ret =
1638 original_sender, 1627 send_message (destination, original_sender, NULL, packed_message,
1639 NULL, 1628 packed_message_size, default_dv_priority,
1640 packed_message, 1629 ntohl (incoming->uid),
1641 packed_message_size, 1630 GNUNET_TIME_relative_get_forever ());
1642 default_dv_priority,
1643 ntohl (incoming->uid),
1644 GNUNET_TIME_relative_get_forever ());
1645 } 1631 }
1646 if (ret != GNUNET_SYSERR) 1632 if (ret != GNUNET_SYSERR)
1647 return GNUNET_OK; 1633 return GNUNET_OK;
@@ -1756,17 +1742,17 @@ neighbor_send_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1756 (about->hidden == GNUNET_NO) && 1742 (about->hidden == GNUNET_NO) &&
1757#endif 1743#endif
1758 (to != NULL) && 1744 (to != NULL) &&
1759 (0 != memcmp (&about->identity, 1745 (0 !=
1760 &to->identity, sizeof (struct GNUNET_PeerIdentity))) && 1746 memcmp (&about->identity, &to->identity,
1761 (about->pkey != NULL)) 1747 sizeof (struct GNUNET_PeerIdentity))) && (about->pkey != NULL))
1762 { 1748 {
1763#if DEBUG_DV_GOSSIP_SEND 1749#if DEBUG_DV_GOSSIP_SEND
1764 encPeerAbout = GNUNET_strdup (GNUNET_i2s (&about->identity)); 1750 encPeerAbout = GNUNET_strdup (GNUNET_i2s (&about->identity));
1765 encPeerTo = GNUNET_strdup (GNUNET_i2s (&to->identity)); 1751 encPeerTo = GNUNET_strdup (GNUNET_i2s (&to->identity));
1766 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1752 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1767 "%s: Sending info about peer %s id %u to directly connected peer %s\n", 1753 "%s: Sending info about peer %s id %u to directly connected peer %s\n",
1768 GNUNET_i2s (&my_identity), 1754 GNUNET_i2s (&my_identity), encPeerAbout, about->our_id,
1769 encPeerAbout, about->our_id, encPeerTo); 1755 encPeerTo);
1770 GNUNET_free (encPeerAbout); 1756 GNUNET_free (encPeerAbout);
1771 GNUNET_free (encPeerTo); 1757 GNUNET_free (encPeerTo);
1772#endif 1758#endif
@@ -1791,8 +1777,7 @@ neighbor_send_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1791 memcpy (&message->neighbor, &about->identity, 1777 memcpy (&message->neighbor, &about->identity,
1792 sizeof (struct GNUNET_PeerIdentity)); 1778 sizeof (struct GNUNET_PeerIdentity));
1793 1779
1794 GNUNET_CONTAINER_DLL_insert_after (core_pending_head, 1780 GNUNET_CONTAINER_DLL_insert_after (core_pending_head, core_pending_tail,
1795 core_pending_tail,
1796 core_pending_tail, pending_message); 1781 core_pending_tail, pending_message);
1797 1782
1798 GNUNET_SCHEDULER_add_now (try_core_send, NULL); 1783 GNUNET_SCHEDULER_add_now (try_core_send, NULL);
@@ -1834,14 +1819,13 @@ neighbor_send_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1834 * @param message the actual message 1819 * @param message the actual message
1835 */ 1820 */
1836static void 1821static void
1837handle_start (void *cls, 1822handle_start (void *cls, struct GNUNET_SERVER_Client *client,
1838 struct GNUNET_SERVER_Client *client,
1839 const struct GNUNET_MessageHeader *message) 1823 const struct GNUNET_MessageHeader *message)
1840{ 1824{
1841 1825
1842#if DEBUG_DV 1826#if DEBUG_DV
1843 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1827 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' request from client\n",
1844 "Received `%s' request from client\n", "START"); 1828 "START");
1845#endif 1829#endif
1846 1830
1847 client_handle = client; 1831 client_handle = client;
@@ -1886,8 +1870,7 @@ send_iterator (void *cls, const GNUNET_HashCode * key, void *abs_value)
1886 * @param message the actual message 1870 * @param message the actual message
1887 */ 1871 */
1888void 1872void
1889handle_dv_send_message (void *cls, 1873handle_dv_send_message (void *cls, struct GNUNET_SERVER_Client *client,
1890 struct GNUNET_SERVER_Client *client,
1891 const struct GNUNET_MessageHeader *message) 1874 const struct GNUNET_MessageHeader *message)
1892{ 1875{
1893 struct GNUNET_DV_SendMessage *send_msg; 1876 struct GNUNET_DV_SendMessage *send_msg;
@@ -2139,8 +2122,8 @@ distant_neighbor_free (struct DistantNeighbor *referee)
2139 referrer = referee->referrer; 2122 referrer = referee->referrer;
2140 if (referrer != NULL) 2123 if (referrer != NULL)
2141 { 2124 {
2142 GNUNET_CONTAINER_DLL_remove (referrer->referee_head, 2125 GNUNET_CONTAINER_DLL_remove (referrer->referee_head, referrer->referee_tail,
2143 referrer->referee_tail, referee); 2126 referee);
2144 } 2127 }
2145 GNUNET_CONTAINER_heap_remove_node (referee->max_loc); 2128 GNUNET_CONTAINER_heap_remove_node (referee->max_loc);
2146 GNUNET_CONTAINER_heap_remove_node (referee->min_loc); 2129 GNUNET_CONTAINER_heap_remove_node (referee->min_loc);
@@ -2191,8 +2174,8 @@ direct_neighbor_free (struct DirectNeighbor *direct)
2191 * @return GNUNET_YES to continue iteration, GNUNET_NO to stop 2174 * @return GNUNET_YES to continue iteration, GNUNET_NO to stop
2192 */ 2175 */
2193static int 2176static int
2194schedule_disconnect_messages (void *cls, 2177schedule_disconnect_messages (void *cls, const GNUNET_HashCode * key,
2195 const GNUNET_HashCode * key, void *value) 2178 void *value)
2196{ 2179{
2197 struct DisconnectContext *disconnect_context = cls; 2180 struct DisconnectContext *disconnect_context = cls;
2198 struct DirectNeighbor *disconnected = disconnect_context->direct; 2181 struct DirectNeighbor *disconnected = disconnect_context->direct;
@@ -2219,8 +2202,7 @@ schedule_disconnect_messages (void *cls,
2219 disconnect_message->header.type = htons (GNUNET_MESSAGE_TYPE_DV_DISCONNECT); 2202 disconnect_message->header.type = htons (GNUNET_MESSAGE_TYPE_DV_DISCONNECT);
2220 disconnect_message->peer_id = htonl (disconnect_context->distant->our_id); 2203 disconnect_message->peer_id = htonl (disconnect_context->distant->our_id);
2221 2204
2222 GNUNET_CONTAINER_DLL_insert_after (core_pending_head, 2205 GNUNET_CONTAINER_DLL_insert_after (core_pending_head, core_pending_tail,
2223 core_pending_tail,
2224 core_pending_tail, pending_message); 2206 core_pending_tail, pending_message);
2225 2207
2226 GNUNET_SCHEDULER_add_now (try_core_send, NULL); 2208 GNUNET_SCHEDULER_add_now (try_core_send, NULL);
@@ -2305,8 +2287,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2305 * To be called on core init/fail. 2287 * To be called on core init/fail.
2306 */ 2288 */
2307void 2289void
2308core_init (void *cls, 2290core_init (void *cls, struct GNUNET_CORE_Handle *server,
2309 struct GNUNET_CORE_Handle *server,
2310 const struct GNUNET_PeerIdentity *identity, 2291 const struct GNUNET_PeerIdentity *identity,
2311 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) 2292 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
2312{ 2293{
@@ -2404,8 +2385,8 @@ update_matching_neighbors (void *cls, const GNUNET_HashCode * key, void *value)
2404 * @return GNUNET_YES to continue iteration, GNUNET_NO otherwise 2385 * @return GNUNET_YES to continue iteration, GNUNET_NO otherwise
2405 */ 2386 */
2406static int 2387static int
2407add_distant_all_direct_neighbors (void *cls, 2388add_distant_all_direct_neighbors (void *cls, const GNUNET_HashCode * key,
2408 const GNUNET_HashCode * key, void *value) 2389 void *value)
2409{ 2390{
2410 struct DirectNeighbor *direct = (struct DirectNeighbor *) value; 2391 struct DirectNeighbor *direct = (struct DirectNeighbor *) value;
2411 struct DistantNeighbor *distant = (struct DistantNeighbor *) cls; 2392 struct DistantNeighbor *distant = (struct DistantNeighbor *) cls;
@@ -2541,13 +2522,13 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity *peer,
2541#if DEBUG_DV_PEER_NUMBERS 2522#if DEBUG_DV_PEER_NUMBERS
2542 char *encAbout; 2523 char *encAbout;
2543 2524
2544 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2525 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s Received sender id (%u)!\n",
2545 "%s Received sender id (%u)!\n", "DV SERVICE", referrer_peer_id); 2526 "DV SERVICE", referrer_peer_id);
2546#endif 2527#endif
2547 2528
2548 now = GNUNET_TIME_absolute_get (); 2529 now = GNUNET_TIME_absolute_get ();
2549 neighbor = GNUNET_CONTAINER_multihashmap_get (extended_neighbors, 2530 neighbor =
2550 &peer->hashPubKey); 2531 GNUNET_CONTAINER_multihashmap_get (extended_neighbors, &peer->hashPubKey);
2551 neighbor_update = GNUNET_malloc (sizeof (struct NeighborUpdateInfo)); 2532 neighbor_update = GNUNET_malloc (sizeof (struct NeighborUpdateInfo));
2552 neighbor_update->neighbor = neighbor; 2533 neighbor_update->neighbor = neighbor;
2553 neighbor_update->cost = cost; 2534 neighbor_update->cost = cost;
@@ -2576,11 +2557,9 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity *peer,
2576 2557
2577 /* Either we do not know this peer, or we already do but via a different immediate peer */ 2558 /* Either we do not know this peer, or we already do but via a different immediate peer */
2578 if ((neighbor == NULL) || 2559 if ((neighbor == NULL) ||
2579 (GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors, 2560 (GNUNET_CONTAINER_multihashmap_get_multiple
2580 &peer->hashPubKey, 2561 (extended_neighbors, &peer->hashPubKey, &update_matching_neighbors,
2581 &update_matching_neighbors, 2562 neighbor_update) != GNUNET_SYSERR))
2582 neighbor_update) !=
2583 GNUNET_SYSERR))
2584 { 2563 {
2585#if AT_MOST_ONE 2564#if AT_MOST_ONE
2586 if ((neighbor != NULL) && (cost < neighbor->cost)) /* New cost is less than old, remove old */ 2565 if ((neighbor != NULL) && (cost < neighbor->cost)) /* New cost is less than old, remove old */
@@ -2630,12 +2609,12 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity *peer,
2630 } 2609 }
2631 2610
2632 neighbor = GNUNET_malloc (sizeof (struct DistantNeighbor)); 2611 neighbor = GNUNET_malloc (sizeof (struct DistantNeighbor));
2633 GNUNET_CONTAINER_DLL_insert (referrer->referee_head, 2612 GNUNET_CONTAINER_DLL_insert (referrer->referee_head, referrer->referee_tail,
2634 referrer->referee_tail, neighbor); 2613 neighbor);
2635 neighbor->max_loc = GNUNET_CONTAINER_heap_insert (neighbor_max_heap, 2614 neighbor->max_loc =
2636 neighbor, cost); 2615 GNUNET_CONTAINER_heap_insert (neighbor_max_heap, neighbor, cost);
2637 neighbor->min_loc = GNUNET_CONTAINER_heap_insert (neighbor_min_heap, 2616 neighbor->min_loc =
2638 neighbor, cost); 2617 GNUNET_CONTAINER_heap_insert (neighbor_min_heap, neighbor, cost);
2639 neighbor->referrer = referrer; 2618 neighbor->referrer = referrer;
2640 memcpy (&neighbor->identity, peer, sizeof (struct GNUNET_PeerIdentity)); 2619 memcpy (&neighbor->identity, peer, sizeof (struct GNUNET_PeerIdentity));
2641 if (pkey != NULL) /* pkey will be null on direct neighbor addition */ 2620 if (pkey != NULL) /* pkey will be null on direct neighbor addition */
@@ -2679,12 +2658,11 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity *peer,
2679 atsi[0].value = htonl (referrer->pending_messages[i].distance); 2658 atsi[0].value = htonl (referrer->pending_messages[i].distance);
2680 atsi[1].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY); 2659 atsi[1].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
2681 atsi[1].value = 2660 atsi[1].value =
2682 htonl ((uint32_t) referrer->pending_messages[i]. 2661 htonl ((uint32_t) referrer->pending_messages[i].latency.
2683 latency.rel_value); 2662 rel_value);
2684 atsi[2].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 2663 atsi[2].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
2685 atsi[2].value = htonl (0); 2664 atsi[2].value = htonl (0);
2686 handle_dv_data_message (NULL, 2665 handle_dv_data_message (NULL, &referrer->pending_messages[i].sender,
2687 &referrer->pending_messages[i].sender,
2688 referrer->pending_messages[i].message, 2666 referrer->pending_messages[i].message,
2689 (const struct GNUNET_TRANSPORT_ATS_Information 2667 (const struct GNUNET_TRANSPORT_ATS_Information
2690 *) &atsi); 2668 *) &atsi);
@@ -2733,9 +2711,8 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity *peer,
2733#endif 2711#endif
2734 } 2712 }
2735#if DEBUG_DV 2713#if DEBUG_DV
2736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2714 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s: Size of extended_neighbors is %d\n",
2737 "%s: Size of extended_neighbors is %d\n", "dv", 2715 "dv", GNUNET_CONTAINER_multihashmap_size (extended_neighbors));
2738 GNUNET_CONTAINER_multihashmap_size (extended_neighbors));
2739#endif 2716#endif
2740 2717
2741 GNUNET_free (neighbor_update); 2718 GNUNET_free (neighbor_update);
@@ -2756,8 +2733,7 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity *peer,
2756 * @param atsi performance data 2733 * @param atsi performance data
2757 */ 2734 */
2758static int 2735static int
2759handle_dv_disconnect_message (void *cls, 2736handle_dv_disconnect_message (void *cls, const struct GNUNET_PeerIdentity *peer,
2760 const struct GNUNET_PeerIdentity *peer,
2761 const struct GNUNET_MessageHeader *message, 2737 const struct GNUNET_MessageHeader *message,
2762 const struct GNUNET_TRANSPORT_ATS_Information 2738 const struct GNUNET_TRANSPORT_ATS_Information
2763 *atsi) 2739 *atsi)
@@ -2772,8 +2748,8 @@ handle_dv_disconnect_message (void *cls,
2772 return GNUNET_SYSERR; /* invalid message */ 2748 return GNUNET_SYSERR; /* invalid message */
2773 } 2749 }
2774 2750
2775 referrer = GNUNET_CONTAINER_multihashmap_get (direct_neighbors, 2751 referrer =
2776 &peer->hashPubKey); 2752 GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey);
2777 if (referrer == NULL) 2753 if (referrer == NULL)
2778 return GNUNET_OK; 2754 return GNUNET_OK;
2779 2755
@@ -2806,8 +2782,7 @@ handle_dv_disconnect_message (void *cls,
2806 * @param atsi performance data 2782 * @param atsi performance data
2807 */ 2783 */
2808static int 2784static int
2809handle_dv_gossip_message (void *cls, 2785handle_dv_gossip_message (void *cls, const struct GNUNET_PeerIdentity *peer,
2810 const struct GNUNET_PeerIdentity *peer,
2811 const struct GNUNET_MessageHeader *message, 2786 const struct GNUNET_MessageHeader *message,
2812 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 2787 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
2813{ 2788{
@@ -2834,14 +2809,14 @@ handle_dv_gossip_message (void *cls,
2834 GNUNET_free (encPeerFrom); 2809 GNUNET_free (encPeerFrom);
2835#endif 2810#endif
2836 2811
2837 referrer = GNUNET_CONTAINER_multihashmap_get (direct_neighbors, 2812 referrer =
2838 &peer->hashPubKey); 2813 GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey);
2839 if (referrer == NULL) 2814 if (referrer == NULL)
2840 return GNUNET_OK; 2815 return GNUNET_OK;
2841 2816
2842 addUpdateNeighbor (&enc_message->neighbor, &enc_message->pkey, 2817 addUpdateNeighbor (&enc_message->neighbor, &enc_message->pkey,
2843 ntohl (enc_message->neighbor_id), 2818 ntohl (enc_message->neighbor_id), referrer,
2844 referrer, ntohl (enc_message->cost) + 1); 2819 ntohl (enc_message->cost) + 1);
2845 2820
2846 return GNUNET_OK; 2821 return GNUNET_OK;
2847} 2822}
@@ -2897,8 +2872,8 @@ add_all_extended_peers (void *cls, const GNUNET_HashCode * key, void *value)
2897 * GNUNET_NO if not. 2872 * GNUNET_NO if not.
2898 */ 2873 */
2899static int 2874static int
2900gossip_all_to_all_iterator (void *cls, 2875gossip_all_to_all_iterator (void *cls, const GNUNET_HashCode * key,
2901 const GNUNET_HashCode * key, void *abs_value) 2876 void *abs_value)
2902{ 2877{
2903 struct DirectNeighbor *direct = abs_value; 2878 struct DirectNeighbor *direct = abs_value;
2904 2879
@@ -3007,8 +2982,7 @@ add_all_direct_neighbors (void *cls, const GNUNET_HashCode * key, void *value)
3007 * @param err_msg NULL if successful, otherwise contains error message 2982 * @param err_msg NULL if successful, otherwise contains error message
3008 */ 2983 */
3009static void 2984static void
3010process_peerinfo (void *cls, 2985process_peerinfo (void *cls, const struct GNUNET_PeerIdentity *peer,
3011 const struct GNUNET_PeerIdentity *peer,
3012 const struct GNUNET_HELLO_Message *hello, const char *err_msg) 2986 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
3013{ 2987{
3014 struct PeerIteratorContext *peerinfo_iterator = cls; 2988 struct PeerIteratorContext *peerinfo_iterator = cls;
@@ -3034,13 +3008,12 @@ process_peerinfo (void *cls,
3034 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3008 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3035 "Failed to get peerinfo information for this peer, retrying!\n"); 3009 "Failed to get peerinfo information for this peer, retrying!\n");
3036#endif 3010#endif
3037 peerinfo_iterator->ic = GNUNET_PEERINFO_iterate (peerinfo_handle, 3011 peerinfo_iterator->ic =
3038 &peerinfo_iterator->neighbor-> 3012 GNUNET_PEERINFO_iterate (peerinfo_handle,
3039 identity, 3013 &peerinfo_iterator->neighbor->identity,
3040 GNUNET_TIME_relative_multiply 3014 GNUNET_TIME_relative_multiply
3041 (GNUNET_TIME_UNIT_SECONDS, 3015 (GNUNET_TIME_UNIT_SECONDS, 3),
3042 3), &process_peerinfo, 3016 &process_peerinfo, peerinfo_iterator);
3043 peerinfo_iterator);
3044 } 3017 }
3045 else 3018 else
3046 { 3019 {
@@ -3111,8 +3084,7 @@ process_peerinfo (void *cls,
3111 * @param atsi performance data 3084 * @param atsi performance data
3112 */ 3085 */
3113static void 3086static void
3114handle_core_connect (void *cls, 3087handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
3115 const struct GNUNET_PeerIdentity *peer,
3116 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 3088 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
3117{ 3089{
3118 struct DirectNeighbor *neighbor; 3090 struct DirectNeighbor *neighbor;
@@ -3146,12 +3118,11 @@ handle_core_connect (void *cls,
3146 about = addUpdateNeighbor (peer, NULL, 0, neighbor, DIRECT_NEIGHBOR_COST); 3118 about = addUpdateNeighbor (peer, NULL, 0, neighbor, DIRECT_NEIGHBOR_COST);
3147 peerinfo_iterator->distant = about; 3119 peerinfo_iterator->distant = about;
3148 peerinfo_iterator->neighbor = neighbor; 3120 peerinfo_iterator->neighbor = neighbor;
3149 peerinfo_iterator->ic = GNUNET_PEERINFO_iterate (peerinfo_handle, 3121 peerinfo_iterator->ic =
3150 peer, 3122 GNUNET_PEERINFO_iterate (peerinfo_handle, peer,
3151 GNUNET_TIME_relative_multiply 3123 GNUNET_TIME_relative_multiply
3152 (GNUNET_TIME_UNIT_SECONDS, 3124 (GNUNET_TIME_UNIT_SECONDS, 3),
3153 3), &process_peerinfo, 3125 &process_peerinfo, peerinfo_iterator);
3154 peerinfo_iterator);
3155 3126
3156 if ((about != NULL) && (about->pkey == NULL)) 3127 if ((about != NULL) && (about->pkey == NULL))
3157 { 3128 {
@@ -3257,9 +3228,9 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
3257 } 3228 }
3258 3229
3259 GNUNET_assert (neighbor->referee_tail == NULL); 3230 GNUNET_assert (neighbor->referee_tail == NULL);
3260 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_remove (direct_neighbors, 3231 if (GNUNET_NO ==
3261 &peer->hashPubKey, 3232 GNUNET_CONTAINER_multihashmap_remove (direct_neighbors, &peer->hashPubKey,
3262 neighbor)) 3233 neighbor))
3263 { 3234 {
3264 GNUNET_break (0); 3235 GNUNET_break (0);
3265 } 3236 }
@@ -3278,8 +3249,7 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
3278 * @param c configuration to use 3249 * @param c configuration to use
3279 */ 3250 */
3280static void 3251static void
3281run (void *cls, 3252run (void *cls, struct GNUNET_SERVER_Handle *server,
3282 struct GNUNET_SERVER_Handle *server,
3283 const struct GNUNET_CONFIGURATION_Handle *c) 3253 const struct GNUNET_CONFIGURATION_Handle *c)
3284{ 3254{
3285 unsigned long long max_hosts; 3255 unsigned long long max_hosts;
@@ -3321,12 +3291,9 @@ run (void *cls,
3321 3291
3322 GNUNET_SERVER_add_handlers (server, plugin_handlers); 3292 GNUNET_SERVER_add_handlers (server, plugin_handlers);
3323 coreAPI = GNUNET_CORE_connect (cfg, 1, NULL, /* FIXME: anything we want to pass around? */ 3293 coreAPI = GNUNET_CORE_connect (cfg, 1, NULL, /* FIXME: anything we want to pass around? */
3324 &core_init, 3294 &core_init, &handle_core_connect,
3325 &handle_core_connect, 3295 &handle_core_disconnect, NULL, NULL, GNUNET_NO,
3326 &handle_core_disconnect, 3296 NULL, GNUNET_NO, core_handlers);
3327 NULL,
3328 NULL,
3329 GNUNET_NO, NULL, GNUNET_NO, core_handlers);
3330 3297
3331 if (coreAPI == NULL) 3298 if (coreAPI == NULL)
3332 return; 3299 return;
@@ -3342,8 +3309,9 @@ run (void *cls,
3342 } 3309 }
3343 3310
3344 /* Scheduled the task to clean up when shutdown is called */ 3311 /* Scheduled the task to clean up when shutdown is called */
3345 cleanup_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 3312 cleanup_task =
3346 &shutdown_task, NULL); 3313 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
3314 &shutdown_task, NULL);
3347} 3315}
3348 3316
3349 3317
@@ -3358,8 +3326,6 @@ int
3358main (int argc, char *const *argv) 3326main (int argc, char *const *argv)
3359{ 3327{
3360 return (GNUNET_OK == 3328 return (GNUNET_OK ==
3361 GNUNET_SERVICE_run (argc, 3329 GNUNET_SERVICE_run (argc, argv, "dv", GNUNET_SERVICE_OPTION_NONE,
3362 argv, 3330 &run, NULL)) ? 0 : 1;
3363 "dv",
3364 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
3365} 3331}
diff --git a/src/dv/plugin_transport_dv.c b/src/dv/plugin_transport_dv.c
index 2803e347e..bd73e7e20 100644
--- a/src/dv/plugin_transport_dv.c
+++ b/src/dv/plugin_transport_dv.c
@@ -145,11 +145,8 @@ struct Plugin
145 * Handler for messages received from the DV service. 145 * Handler for messages received from the DV service.
146 */ 146 */
147void 147void
148handle_dv_message_received (void *cls, 148handle_dv_message_received (void *cls, struct GNUNET_PeerIdentity *sender,
149 struct GNUNET_PeerIdentity *sender, 149 char *msg, size_t msg_len, uint32_t distance,
150 char *msg,
151 size_t msg_len,
152 uint32_t distance,
153 char *sender_address, size_t sender_address_len) 150 char *sender_address, size_t sender_address_len)
154{ 151{
155 struct Plugin *plugin = cls; 152 struct Plugin *plugin = cls;
@@ -158,8 +155,7 @@ handle_dv_message_received (void *cls,
158 char *my_id; 155 char *my_id;
159 156
160 my_id = GNUNET_strdup (GNUNET_i2s (plugin->env->my_identity)); 157 my_id = GNUNET_strdup (GNUNET_i2s (plugin->env->my_identity));
161 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 158 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "plugin_transport_dv",
162 "plugin_transport_dv",
163 _("%s Received message from %s of type %d, distance %u!\n"), 159 _("%s Received message from %s of type %d, distance %u!\n"),
164 my_id, GNUNET_i2s (sender), 160 my_id, GNUNET_i2s (sender),
165 ntohs (((struct GNUNET_MessageHeader *) msg)->type), 161 ntohs (((struct GNUNET_MessageHeader *) msg)->type),
@@ -173,8 +169,7 @@ handle_dv_message_received (void *cls,
173 ats[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 169 ats[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
174 ats[1].value = htonl (0); 170 ats[1].value = htonl (0);
175 171
176 plugin->env->receive (plugin->env->cls, 172 plugin->env->receive (plugin->env->cls, sender,
177 sender,
178 (struct GNUNET_MessageHeader *) msg, 173 (struct GNUNET_MessageHeader *) msg,
179 (const struct GNUNET_TRANSPORT_ATS_Information *) &ats, 174 (const struct GNUNET_TRANSPORT_ATS_Information *) &ats,
180 2, NULL, sender_address, sender_address_len); 175 2, NULL, sender_address, sender_address_len);
@@ -214,26 +209,18 @@ handle_dv_message_received (void *cls,
214 * and does NOT mean that the message was not transmitted (DV) 209 * and does NOT mean that the message was not transmitted (DV)
215 */ 210 */
216static ssize_t 211static ssize_t
217dv_plugin_send (void *cls, 212dv_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
218 const struct GNUNET_PeerIdentity *target, 213 const char *msgbuf, size_t msgbuf_size, unsigned int priority,
219 const char *msgbuf, 214 struct GNUNET_TIME_Relative timeout, struct Session *session,
220 size_t msgbuf_size, 215 const void *addr, size_t addrlen, int force_address,
221 unsigned int priority,
222 struct GNUNET_TIME_Relative timeout,
223 struct Session *session,
224 const void *addr,
225 size_t addrlen,
226 int force_address,
227 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) 216 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
228{ 217{
229 int ret = 0; 218 int ret = 0;
230 struct Plugin *plugin = cls; 219 struct Plugin *plugin = cls;
231 220
232 ret = GNUNET_DV_send (plugin->dv_handle, 221 ret =
233 target, 222 GNUNET_DV_send (plugin->dv_handle, target, msgbuf, msgbuf_size, priority,
234 msgbuf, 223 timeout, addr, addrlen, cont, cont_cls);
235 msgbuf_size,
236 priority, timeout, addr, addrlen, cont, cont_cls);
237 return ret; 224 return ret;
238} 225}
239 226
@@ -270,14 +257,11 @@ dv_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
270 * @param asc_cls closure for asc 257 * @param asc_cls closure for asc
271 */ 258 */
272static void 259static void
273dv_plugin_address_pretty_printer (void *cls, 260dv_plugin_address_pretty_printer (void *cls, const char *type, const void *addr,
274 const char *type, 261 size_t addrlen, int numeric,
275 const void *addr,
276 size_t addrlen,
277 int numeric,
278 struct GNUNET_TIME_Relative timeout, 262 struct GNUNET_TIME_Relative timeout,
279 GNUNET_TRANSPORT_AddressStringCallback 263 GNUNET_TRANSPORT_AddressStringCallback asc,
280 asc, void *asc_cls) 264 void *asc_cls)
281{ 265{
282 char *dest_peer; 266 char *dest_peer;
283 char *via_peer; 267 char *via_peer;
@@ -337,8 +321,8 @@ address_to_string (void *cls, const void *addr, size_t addrlen)
337 peer_hash.encoding[4] = '\0'; 321 peer_hash.encoding[4] = '\0';
338 GNUNET_CRYPTO_hash_to_enc (&via->hashPubKey, &via_hash); 322 GNUNET_CRYPTO_hash_to_enc (&via->hashPubKey, &via_hash);
339 via_hash.encoding[4] = '\0'; 323 via_hash.encoding[4] = '\0';
340 GNUNET_snprintf (return_buffer, 324 GNUNET_snprintf (return_buffer, sizeof (return_buffer), "%s:%s", &peer_hash,
341 sizeof (return_buffer), "%s:%s", &peer_hash, &via_hash); 325 &via_hash);
342 } 326 }
343 else 327 else
344 return NULL; 328 return NULL;
diff --git a/src/dv/test_transport_api_dv.c b/src/dv/test_transport_api_dv.c
index 5d9d367e1..fee8eea81 100644
--- a/src/dv/test_transport_api_dv.c
+++ b/src/dv/test_transport_api_dv.c
@@ -285,15 +285,13 @@ disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
285 285
286 /* Disconnect from the respective cores */ 286 /* Disconnect from the respective cores */
287#if VERBOSE 287#if VERBOSE
288 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 288 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from peer 1 `%4s'\n",
289 "Disconnecting from peer 1 `%4s'\n",
290 GNUNET_i2s (&pos->peer1->id)); 289 GNUNET_i2s (&pos->peer1->id));
291#endif 290#endif
292 if (pos->peer1handle != NULL) 291 if (pos->peer1handle != NULL)
293 GNUNET_CORE_disconnect (pos->peer1handle); 292 GNUNET_CORE_disconnect (pos->peer1handle);
294#if VERBOSE 293#if VERBOSE
295 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 294 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from peer 2 `%4s'\n",
296 "Disconnecting from peer 2 `%4s'\n",
297 GNUNET_i2s (&pos->peer2->id)); 295 GNUNET_i2s (&pos->peer2->id));
298#endif 296#endif
299 if (pos->peer2handle != NULL) 297 if (pos->peer2handle != NULL)
@@ -384,8 +382,8 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
384 } 382 }
385} 383}
386 384
387static void 385static void send_other_messages (void *cls,
388send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 386 const struct GNUNET_SCHEDULER_TaskContext *tc);
389 387
390/** 388/**
391 * Get distance information from 'atsi'. 389 * Get distance information from 'atsi'.
@@ -409,8 +407,7 @@ get_atsi_distance (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
409} 407}
410 408
411static int 409static int
412process_mtype (void *cls, 410process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
413 const struct GNUNET_PeerIdentity *peer,
414 const struct GNUNET_MessageHeader *message, 411 const struct GNUNET_MessageHeader *message,
415 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 412 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
416{ 413{
@@ -460,9 +457,9 @@ process_mtype (void *cls,
460 (total_other_messages == 0)) 457 (total_other_messages == 0))
461 { 458 {
462 GNUNET_SCHEDULER_cancel (die_task); 459 GNUNET_SCHEDULER_cancel (die_task);
463 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, 460 die_task =
464 &end_badly, 461 GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &end_badly,
465 "waiting for DV peers to connect!"); 462 "waiting for DV peers to connect!");
466 /* 463 /*
467 * if ((num_peers == 3) && (total_other_expected_messages == 2)) 464 * if ((num_peers == 3) && (total_other_expected_messages == 2))
468 * { 465 * {
@@ -527,9 +524,7 @@ static struct GNUNET_CORE_MessageHandler handlers[] = {
527 * @param atsi performance data for the connection 524 * @param atsi performance data for the connection
528 */ 525 */
529static void 526static void
530connect_notify_peer2 (void *cls, 527connect_notify_peer2 (void *cls, const struct GNUNET_PeerIdentity *peer,
531 const struct
532 GNUNET_PeerIdentity *peer,
533 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 528 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
534{ 529{
535 struct TestMessageContext *pos = cls; 530 struct TestMessageContext *pos = cls;
@@ -541,14 +536,11 @@ connect_notify_peer2 (void *cls,
541 "Core connection from `%s' to `%4s' verfied, sending message!\n", 536 "Core connection from `%s' to `%4s' verfied, sending message!\n",
542 GNUNET_i2s (&pos->peer2->id), GNUNET_h2s (&peer->hashPubKey)); 537 GNUNET_i2s (&pos->peer2->id), GNUNET_h2s (&peer->hashPubKey));
543#endif 538#endif
544 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle, 539 if (NULL ==
545 GNUNET_YES, 540 GNUNET_CORE_notify_transmit_ready (pos->peer1handle, GNUNET_YES, 0,
546 0, 541 TIMEOUT, &pos->peer2->id,
547 TIMEOUT, 542 sizeof (struct GNUNET_TestMessage),
548 &pos->peer2->id, 543 &transmit_ready, pos))
549 sizeof (struct
550 GNUNET_TestMessage),
551 &transmit_ready, pos))
552 { 544 {
553 /* This probably shouldn't happen, but it does (timing issue?) */ 545 /* This probably shouldn't happen, but it does (timing issue?) */
554 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 546 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -565,8 +557,7 @@ connect_notify_peer2 (void *cls,
565} 557}
566 558
567static void 559static void
568init_notify_peer2 (void *cls, 560init_notify_peer2 (void *cls, struct GNUNET_CORE_Handle *server,
569 struct GNUNET_CORE_Handle *server,
570 const struct GNUNET_PeerIdentity *my_identity, 561 const struct GNUNET_PeerIdentity *my_identity,
571 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded 562 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
572 *publicKey) 563 *publicKey)
@@ -588,9 +579,7 @@ init_notify_peer2 (void *cls,
588 * @param atsi performance data for the connection 579 * @param atsi performance data for the connection
589 */ 580 */
590static void 581static void
591connect_notify_peer1 (void *cls, 582connect_notify_peer1 (void *cls, const struct GNUNET_PeerIdentity *peer,
592 const struct
593 GNUNET_PeerIdentity *peer,
594 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 583 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
595{ 584{
596 struct TestMessageContext *pos = cls; 585 struct TestMessageContext *pos = cls;
@@ -605,21 +594,15 @@ connect_notify_peer1 (void *cls,
605 /* 594 /*
606 * Connect to the receiving peer 595 * Connect to the receiving peer
607 */ 596 */
608 pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg, 597 pos->peer2handle =
609 1, 598 GNUNET_CORE_connect (pos->peer2->cfg, 1, pos, &init_notify_peer2,
610 pos, 599 &connect_notify_peer2, NULL, NULL, NULL,
611 &init_notify_peer2, 600 GNUNET_YES, NULL, GNUNET_YES, handlers);
612 &connect_notify_peer2,
613 NULL,
614 NULL, NULL,
615 GNUNET_YES, NULL, GNUNET_YES,
616 handlers);
617 } 601 }
618} 602}
619 603
620static void 604static void
621init_notify_peer1 (void *cls, 605init_notify_peer1 (void *cls, struct GNUNET_CORE_Handle *server,
622 struct GNUNET_CORE_Handle *server,
623 const struct GNUNET_PeerIdentity *my_identity, 606 const struct GNUNET_PeerIdentity *my_identity,
624 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded 607 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
625 *publicKey) 608 *publicKey)
@@ -643,9 +626,9 @@ send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
643 626
644 if (die_task == GNUNET_SCHEDULER_NO_TASK) 627 if (die_task == GNUNET_SCHEDULER_NO_TASK)
645 { 628 {
646 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, 629 die_task =
647 &end_badly, 630 GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &end_badly,
648 "from create topology (timeout)"); 631 "from create topology (timeout)");
649 } 632 }
650 633
651 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS) 634 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
@@ -663,16 +646,10 @@ send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
663 /* 646 /*
664 * Connect to the sending peer 647 * Connect to the sending peer
665 */ 648 */
666 pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg, 649 pos->peer1handle =
667 1, 650 GNUNET_CORE_connect (pos->peer1->cfg, 1, pos, &init_notify_peer1,
668 pos, 651 &connect_notify_peer1, NULL, NULL, NULL, GNUNET_NO,
669 &init_notify_peer1, 652 NULL, GNUNET_NO, no_handlers);
670 &connect_notify_peer1,
671 NULL,
672 NULL,
673 NULL,
674 GNUNET_NO, NULL, GNUNET_NO,
675 no_handlers);
676 653
677 GNUNET_assert (pos->peer1handle != NULL); 654 GNUNET_assert (pos->peer1handle != NULL);
678 655
@@ -773,10 +750,8 @@ send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
773} 750}
774 751
775static void 752static void
776topology_callback (void *cls, 753topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
777 const struct GNUNET_PeerIdentity *first, 754 const struct GNUNET_PeerIdentity *second, uint32_t distance,
778 const struct GNUNET_PeerIdentity *second,
779 uint32_t distance,
780 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 755 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
781 const struct GNUNET_CONFIGURATION_Handle *second_cfg, 756 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
782 struct GNUNET_TESTING_Daemon *first_daemon, 757 struct GNUNET_TESTING_Daemon *first_daemon,
@@ -859,15 +834,14 @@ connect_topology ()
859 expected_connections = -1; 834 expected_connections = -1;
860 if ((pg != NULL) && (peers_left == 0)) 835 if ((pg != NULL) && (peers_left == 0))
861 { 836 {
862 expected_connections = GNUNET_TESTING_connect_topology (pg, 837 expected_connections =
863 connection_topology, 838 GNUNET_TESTING_connect_topology (pg, connection_topology,
864 connect_topology_option, 839 connect_topology_option,
865 connect_topology_option_modifier, 840 connect_topology_option_modifier,
866 TIMEOUT, 841 TIMEOUT, 12, NULL, NULL);
867 12, NULL, NULL);
868#if VERBOSE 842#if VERBOSE
869 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 843 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Have %d expected connections\n",
870 "Have %d expected connections\n", expected_connections); 844 expected_connections);
871#endif 845#endif
872 } 846 }
873 847
@@ -879,9 +853,9 @@ connect_topology ()
879 "from connect topology (bad return)"); 853 "from connect topology (bad return)");
880 } 854 }
881 855
882 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, 856 die_task =
883 &end_badly, 857 GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &end_badly,
884 "from connect topology (timeout)"); 858 "from connect topology (timeout)");
885} 859}
886 860
887static void 861static void
@@ -905,9 +879,9 @@ create_topology ()
905 "from create topology (bad return)"); 879 "from create topology (bad return)");
906 } 880 }
907 GNUNET_SCHEDULER_cancel (die_task); 881 GNUNET_SCHEDULER_cancel (die_task);
908 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, 882 die_task =
909 &end_badly, 883 GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &end_badly,
910 "from continue startup (timeout)"); 884 "from continue startup (timeout)");
911} 885}
912 886
913/** 887/**
@@ -919,9 +893,7 @@ create_topology ()
919 * @param distance reported distance (DV) to 'other' 893 * @param distance reported distance (DV) to 'other'
920 */ 894 */
921static void 895static void
922all_connect_handler (void *cls, 896all_connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
923 const struct
924 GNUNET_PeerIdentity *peer,
925 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 897 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
926{ 898{
927 struct GNUNET_TESTING_Daemon *d = cls; 899 struct GNUNET_TESTING_Daemon *d = cls;
@@ -940,8 +912,8 @@ all_connect_handler (void *cls,
940 912
941#if VERBOSE 913#if VERBOSE
942 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
943 "connected peer %s to peer %s, distance %u\n", 915 "connected peer %s to peer %s, distance %u\n", d->shortname,
944 d->shortname, second_shortname, distance); 916 second_shortname, distance);
945#endif 917#endif
946 918
947 second_daemon = 919 second_daemon =
@@ -993,8 +965,7 @@ all_connect_handler (void *cls,
993} 965}
994 966
995static void 967static void
996peers_started_callback (void *cls, 968peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
997 const struct GNUNET_PeerIdentity *id,
998 const struct GNUNET_CONFIGURATION_Handle *cfg, 969 const struct GNUNET_CONFIGURATION_Handle *cfg,
999 struct GNUNET_TESTING_Daemon *d, const char *emsg) 970 struct GNUNET_TESTING_Daemon *d, const char *emsg)
1000{ 971{
@@ -1017,13 +988,9 @@ peers_started_callback (void *cls,
1017 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 988 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1018 989
1019 new_peer = GNUNET_malloc (sizeof (struct PeerContext)); 990 new_peer = GNUNET_malloc (sizeof (struct PeerContext));
1020 new_peer->peer_handle = GNUNET_CORE_connect (cfg, 991 new_peer->peer_handle =
1021 1, 992 GNUNET_CORE_connect (cfg, 1, d, NULL, &all_connect_handler, NULL, NULL,
1022 d, NULL, 993 NULL, GNUNET_NO, NULL, GNUNET_NO, no_handlers);
1023 &all_connect_handler,
1024 NULL, NULL, NULL,
1025 GNUNET_NO, NULL, GNUNET_NO,
1026 no_handlers);
1027 new_peer->daemon = d; 994 new_peer->daemon = d;
1028 new_peer->next = all_peers; 995 new_peer->next = all_peers;
1029 all_peers = new_peer; 996 all_peers = new_peer;
@@ -1038,10 +1005,10 @@ peers_started_callback (void *cls,
1038 GNUNET_SCHEDULER_cancel (die_task); 1005 GNUNET_SCHEDULER_cancel (die_task);
1039 /* Set up task in case topology creation doesn't finish 1006 /* Set up task in case topology creation doesn't finish
1040 * within a reasonable amount of time */ 1007 * within a reasonable amount of time */
1041 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 1008 die_task =
1042 (GNUNET_TIME_UNIT_MINUTES, 5), 1009 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1043 &end_badly, 1010 (GNUNET_TIME_UNIT_MINUTES, 5), &end_badly,
1044 "from peers_started_callback"); 1011 "from peers_started_callback");
1045 1012
1046 connect_topology (); 1013 connect_topology ();
1047 ok = 0; 1014 ok = 0;
@@ -1057,8 +1024,7 @@ peers_started_callback (void *cls,
1057 * @param emsg non-null on failure 1024 * @param emsg non-null on failure
1058 */ 1025 */
1059static void 1026static void
1060hostkey_callback (void *cls, 1027hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id,
1061 const struct GNUNET_PeerIdentity *id,
1062 struct GNUNET_TESTING_Daemon *d, const char *emsg) 1028 struct GNUNET_TESTING_Daemon *d, const char *emsg)
1063{ 1029{
1064 if (emsg != NULL) 1030 if (emsg != NULL)
@@ -1068,8 +1034,8 @@ hostkey_callback (void *cls,
1068 } 1034 }
1069 1035
1070#if VERBOSE 1036#if VERBOSE
1071 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1037 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostkey created for peer `%s'\n",
1072 "Hostkey created for peer `%s'\n", GNUNET_i2s (id)); 1038 GNUNET_i2s (id));
1073#endif 1039#endif
1074 peers_left--; 1040 peers_left--;
1075 if (peers_left == 0) 1041 if (peers_left == 0)
@@ -1081,19 +1047,18 @@ hostkey_callback (void *cls,
1081 GNUNET_SCHEDULER_cancel (die_task); 1047 GNUNET_SCHEDULER_cancel (die_task);
1082 /* Set up task in case topology creation doesn't finish 1048 /* Set up task in case topology creation doesn't finish
1083 * within a reasonable amount of time */ 1049 * within a reasonable amount of time */
1084 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 1050 die_task =
1085 (GNUNET_TIME_UNIT_MINUTES, 5), 1051 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1086 &end_badly, 1052 (GNUNET_TIME_UNIT_MINUTES, 5), &end_badly,
1087 "from hostkey_callback"); 1053 "from hostkey_callback");
1088 GNUNET_SCHEDULER_add_now (&create_topology, NULL); 1054 GNUNET_SCHEDULER_add_now (&create_topology, NULL);
1089 ok = 0; 1055 ok = 0;
1090 } 1056 }
1091} 1057}
1092 1058
1093static void 1059static void
1094run (void *cls, 1060run (void *cls, char *const *args, const char *cfgfile,
1095 char *const *args, 1061 const struct GNUNET_CONFIGURATION_Handle *cfg)
1096 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
1097{ 1062{
1098 char *topology_str; 1063 char *topology_str;
1099 char *connect_topology_str; 1064 char *connect_topology_str;
@@ -1216,20 +1181,18 @@ run (void *cls,
1216 peers_left = num_peers; 1181 peers_left = num_peers;
1217 1182
1218 /* Set up a task to end testing if peer start fails */ 1183 /* Set up a task to end testing if peer start fails */
1219 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 1184 die_task =
1220 (GNUNET_TIME_UNIT_MINUTES, 5), 1185 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1221 &end_badly, 1186 (GNUNET_TIME_UNIT_MINUTES, 5), &end_badly,
1222 "didn't start all daemons in reasonable amount of time!!!"); 1187 "didn't start all daemons in reasonable amount of time!!!");
1223 1188
1224 peer_daemon_hash = GNUNET_CONTAINER_multihashmap_create (peers_left); 1189 peer_daemon_hash = GNUNET_CONTAINER_multihashmap_create (peers_left);
1225 pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of peers */ 1190 pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of peers */
1226 peers_left, /* Number of outstanding connections */ 1191 peers_left, /* Number of outstanding connections */
1227 peers_left, /* Number of parallel ssh connections, or peers being started at once */ 1192 peers_left, /* Number of parallel ssh connections, or peers being started at once */
1228 TIMEOUT, 1193 TIMEOUT, &hostkey_callback, NULL,
1229 &hostkey_callback, 1194 &peers_started_callback, NULL,
1230 NULL, 1195 &topology_callback, NULL, NULL);
1231 &peers_started_callback,
1232 NULL, &topology_callback, NULL, NULL);
1233 1196
1234} 1197}
1235 1198
@@ -1249,9 +1212,9 @@ check ()
1249 struct GNUNET_GETOPT_CommandLineOption options[] = { 1212 struct GNUNET_GETOPT_CommandLineOption options[] = {
1250 GNUNET_GETOPT_OPTION_END 1213 GNUNET_GETOPT_OPTION_END
1251 }; 1214 };
1252 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 1215 ret =
1253 argv, "test-transport-dv", "nohelp", 1216 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
1254 options, &run, &ok); 1217 "test-transport-dv", "nohelp", options, &run, &ok);
1255 if (ret != GNUNET_OK) 1218 if (ret != GNUNET_OK)
1256 { 1219 {
1257 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1220 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
diff --git a/src/fragmentation/defragmentation.c b/src/fragmentation/defragmentation.c
index 35d59854f..bd4dfba5a 100644
--- a/src/fragmentation/defragmentation.c
+++ b/src/fragmentation/defragmentation.c
@@ -203,8 +203,7 @@ struct GNUNET_DEFRAGMENT_Context
203 */ 203 */
204struct GNUNET_DEFRAGMENT_Context * 204struct GNUNET_DEFRAGMENT_Context *
205GNUNET_DEFRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats, 205GNUNET_DEFRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
206 uint16_t mtu, 206 uint16_t mtu, unsigned int num_msgs,
207 unsigned int num_msgs,
208 void *cls, 207 void *cls,
209 GNUNET_FRAGMENT_MessageProcessor proc, 208 GNUNET_FRAGMENT_MessageProcessor proc,
210 GNUNET_DEFRAGMENT_AckProcessor ackp) 209 GNUNET_DEFRAGMENT_AckProcessor ackp)
@@ -268,8 +267,8 @@ send_ack (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
268 fa.fragment_id = htonl (mc->fragment_id); 267 fa.fragment_id = htonl (mc->fragment_id);
269 fa.bits = GNUNET_htonll (mc->bits); 268 fa.bits = GNUNET_htonll (mc->bits);
270 GNUNET_STATISTICS_update (mc->dc->stats, 269 GNUNET_STATISTICS_update (mc->dc->stats,
271 _("# acknowledgements sent for fragment"), 270 _("# acknowledgements sent for fragment"), 1,
272 1, GNUNET_NO); 271 GNUNET_NO);
273 dc->ackp (dc->cls, mc->fragment_id, &fa.header); 272 dc->ackp (dc->cls, mc->fragment_id, &fa.header);
274} 273}
275 274
@@ -279,9 +278,9 @@ send_ack (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
279 * (C) 2000 Brian Gough 278 * (C) 2000 Brian Gough
280 */ 279 */
281static void 280static void
282gsl_fit_mul (const double *x, const size_t xstride, 281gsl_fit_mul (const double *x, const size_t xstride, const double *y,
283 const double *y, const size_t ystride, 282 const size_t ystride, const size_t n, double *c1, double *cov_11,
284 const size_t n, double *c1, double *cov_11, double *sumsq) 283 double *sumsq)
285{ 284{
286 double m_x = 0, m_y = 0, m_dx2 = 0, m_dxdy = 0; 285 double m_x = 0, m_y = 0, m_dx2 = 0, m_dxdy = 0;
287 286
@@ -457,8 +456,8 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc,
457 while ((NULL != mc) && (fid != mc->fragment_id)) 456 while ((NULL != mc) && (fid != mc->fragment_id))
458 mc = mc->next; 457 mc = mc->next;
459 bit = foff / (dc->mtu - sizeof (struct FragmentHeader)); 458 bit = foff / (dc->mtu - sizeof (struct FragmentHeader));
460 if (bit * (dc->mtu - sizeof (struct FragmentHeader)) + ntohs (msg->size) 459 if (bit * (dc->mtu - sizeof (struct FragmentHeader)) + ntohs (msg->size) -
461 - sizeof (struct FragmentHeader) > msize) 460 sizeof (struct FragmentHeader) > msize)
462 { 461 {
463 /* payload extends past total message size */ 462 /* payload extends past total message size */
464 GNUNET_break_op (0); 463 GNUNET_break_op (0);
@@ -497,8 +496,8 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc,
497 { 496 {
498 mc->bits -= 1LL << bit; 497 mc->bits -= 1LL << bit;
499 mbuf = (char *) &mc[1]; 498 mbuf = (char *) &mc[1];
500 memcpy (&mbuf[bit * (dc->mtu - sizeof (struct FragmentHeader))], 499 memcpy (&mbuf[bit * (dc->mtu - sizeof (struct FragmentHeader))], &fh[1],
501 &fh[1], ntohs (msg->size) - sizeof (struct FragmentHeader)); 500 ntohs (msg->size) - sizeof (struct FragmentHeader));
502 mc->last_update = now; 501 mc->last_update = now;
503 if (bit < mc->last_bit) 502 if (bit < mc->last_bit)
504 mc->frag_times_start_offset = mc->frag_times_write_offset; 503 mc->frag_times_start_offset = mc->frag_times_write_offset;
@@ -511,9 +510,8 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc,
511 else 510 else
512 { 511 {
513 duplicate = GNUNET_YES; 512 duplicate = GNUNET_YES;
514 GNUNET_STATISTICS_update (dc->stats, 513 GNUNET_STATISTICS_update (dc->stats, _("# duplicate fragments received"), 1,
515 _("# duplicate fragments received"), 514 GNUNET_NO);
516 1, GNUNET_NO);
517 } 515 }
518 516
519 /* count number of missing fragments */ 517 /* count number of missing fragments */
@@ -531,8 +529,8 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc,
531 mc->ack_task = GNUNET_SCHEDULER_add_delayed (delay, &send_ack, mc); 529 mc->ack_task = GNUNET_SCHEDULER_add_delayed (delay, &send_ack, mc);
532 if ((duplicate == GNUNET_NO) && (0 == mc->bits)) 530 if ((duplicate == GNUNET_NO) && (0 == mc->bits))
533 { 531 {
534 GNUNET_STATISTICS_update (dc->stats, 532 GNUNET_STATISTICS_update (dc->stats, _("# messages defragmented"), 1,
535 _("# messages defragmented"), 1, GNUNET_NO); 533 GNUNET_NO);
536 /* message complete, notify! */ 534 /* message complete, notify! */
537 dc->proc (dc->cls, mc->msg); 535 dc->proc (dc->cls, mc->msg);
538 } 536 }
diff --git a/src/fragmentation/fragmentation.c b/src/fragmentation/fragmentation.c
index d3483fc8d..cea33b652 100644
--- a/src/fragmentation/fragmentation.c
+++ b/src/fragmentation/fragmentation.c
@@ -176,16 +176,15 @@ transmit_next (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
176 fh->fragment_id = htonl (fc->fragment_id); 176 fh->fragment_id = htonl (fc->fragment_id);
177 fh->total_size = fc->msg->size; /* already in big-endian */ 177 fh->total_size = fc->msg->size; /* already in big-endian */
178 fh->offset = htons ((fc->mtu - sizeof (struct FragmentHeader)) * bit); 178 fh->offset = htons ((fc->mtu - sizeof (struct FragmentHeader)) * bit);
179 memcpy (&fh[1], 179 memcpy (&fh[1], &mbuf[bit * (fc->mtu - sizeof (struct FragmentHeader))],
180 &mbuf[bit * (fc->mtu - sizeof (struct FragmentHeader))],
181 fsize - sizeof (struct FragmentHeader)); 180 fsize - sizeof (struct FragmentHeader));
182 if (NULL != fc->tracker) 181 if (NULL != fc->tracker)
183 GNUNET_BANDWIDTH_tracker_consume (fc->tracker, fsize); 182 GNUNET_BANDWIDTH_tracker_consume (fc->tracker, fsize);
184 GNUNET_STATISTICS_update (fc->stats, 183 GNUNET_STATISTICS_update (fc->stats, _("# fragments transmitted"), 1,
185 _("# fragments transmitted"), 1, GNUNET_NO); 184 GNUNET_NO);
186 if (0 != fc->last_round.abs_value) 185 if (0 != fc->last_round.abs_value)
187 GNUNET_STATISTICS_update (fc->stats, 186 GNUNET_STATISTICS_update (fc->stats, _("# fragments retransmitted"), 1,
188 _("# fragments retransmitted"), 1, GNUNET_NO); 187 GNUNET_NO);
189 188
190 /* select next message to calculate delay */ 189 /* select next message to calculate delay */
191 bit = fc->next_transmission; 190 bit = fc->next_transmission;
@@ -201,8 +200,9 @@ transmit_next (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
201 if (wrap) 200 if (wrap)
202 { 201 {
203 /* full round transmitted wait 2x delay for ACK before going again */ 202 /* full round transmitted wait 2x delay for ACK before going again */
204 delay = GNUNET_TIME_relative_max (GNUNET_TIME_relative_multiply (delay, 2), 203 delay =
205 fc->delay); 204 GNUNET_TIME_relative_max (GNUNET_TIME_relative_multiply (delay, 2),
205 fc->delay);
206 /* never use zero, need some time for ACK always */ 206 /* never use zero, need some time for ACK always */
207 delay = GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS, delay); 207 delay = GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS, delay);
208 fc->last_round = GNUNET_TIME_absolute_get (); 208 fc->last_round = GNUNET_TIME_absolute_get ();
@@ -248,8 +248,7 @@ GNUNET_FRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
248 GNUNET_STATISTICS_update (stats, _("# messages fragmented"), 1, GNUNET_NO); 248 GNUNET_STATISTICS_update (stats, _("# messages fragmented"), 1, GNUNET_NO);
249 GNUNET_assert (mtu >= 1024 + sizeof (struct FragmentHeader)); 249 GNUNET_assert (mtu >= 1024 + sizeof (struct FragmentHeader));
250 size = ntohs (msg->size); 250 size = ntohs (msg->size);
251 GNUNET_STATISTICS_update (stats, 251 GNUNET_STATISTICS_update (stats, _("# total size of fragmented messages"),
252 _("# total size of fragmented messages"),
253 size, GNUNET_NO); 252 size, GNUNET_NO);
254 GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); 253 GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
255 fc = GNUNET_malloc (sizeof (struct GNUNET_FRAGMENT_Context) + size); 254 fc = GNUNET_malloc (sizeof (struct GNUNET_FRAGMENT_Context) + size);
@@ -260,8 +259,8 @@ GNUNET_FRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
260 fc->msg = (const struct GNUNET_MessageHeader *) &fc[1]; 259 fc->msg = (const struct GNUNET_MessageHeader *) &fc[1];
261 fc->proc = proc; 260 fc->proc = proc;
262 fc->proc_cls = proc_cls; 261 fc->proc_cls = proc_cls;
263 fc->fragment_id = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 262 fc->fragment_id =
264 UINT32_MAX); 263 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
265 memcpy (&fc[1], msg, size); 264 memcpy (&fc[1], msg, size);
266 bits = 265 bits =
267 (size + mtu - sizeof (struct FragmentHeader) - 1) / (mtu - 266 (size + mtu - sizeof (struct FragmentHeader) - 1) / (mtu -
@@ -333,14 +332,14 @@ GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc,
333 fc->delay.rel_value = (ndelay.rel_value + 3 * fc->delay.rel_value) / 4; 332 fc->delay.rel_value = (ndelay.rel_value + 3 * fc->delay.rel_value) / 4;
334 } 333 }
335 GNUNET_STATISTICS_update (fc->stats, 334 GNUNET_STATISTICS_update (fc->stats,
336 _("# fragment acknowledgements received"), 335 _("# fragment acknowledgements received"), 1,
337 1, GNUNET_NO); 336 GNUNET_NO);
338 if (abits != (fc->acks & abits)) 337 if (abits != (fc->acks & abits))
339 { 338 {
340 /* ID collission or message reordering, count! This should be rare! */ 339 /* ID collission or message reordering, count! This should be rare! */
341 GNUNET_STATISTICS_update (fc->stats, 340 GNUNET_STATISTICS_update (fc->stats,
342 _("# bits removed from fragmentation ACKs"), 341 _("# bits removed from fragmentation ACKs"), 1,
343 1, GNUNET_NO); 342 GNUNET_NO);
344 } 343 }
345 fc->acks = abits & fc->acks_mask; 344 fc->acks = abits & fc->acks_mask;
346 if (0 != fc->acks) 345 if (0 != fc->acks)
@@ -363,8 +362,8 @@ GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc,
363 362
364 /* all done */ 363 /* all done */
365 GNUNET_STATISTICS_update (fc->stats, 364 GNUNET_STATISTICS_update (fc->stats,
366 _("# fragmentation transmissions completed"), 365 _("# fragmentation transmissions completed"), 1,
367 1, GNUNET_NO); 366 GNUNET_NO);
368 if (fc->task != GNUNET_SCHEDULER_NO_TASK) 367 if (fc->task != GNUNET_SCHEDULER_NO_TASK)
369 { 368 {
370 GNUNET_SCHEDULER_cancel (fc->task); 369 GNUNET_SCHEDULER_cancel (fc->task);
diff --git a/src/fragmentation/test_fragmentation.c b/src/fragmentation/test_fragmentation.c
index b534a134e..b04b28385 100644
--- a/src/fragmentation/test_fragmentation.c
+++ b/src/fragmentation/test_fragmentation.c
@@ -183,9 +183,8 @@ proc_frac (void *cls, const struct GNUNET_MessageHeader *hdr)
183 * Main function run with scheduler. 183 * Main function run with scheduler.
184 */ 184 */
185static void 185static void
186run (void *cls, 186run (void *cls, char *const *args, const char *cfgfile,
187 char *const *args, 187 const struct GNUNET_CONFIGURATION_Handle *cfg)
188 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
189{ 188{
190 unsigned int i; 189 unsigned int i;
191 struct GNUNET_MessageHeader *msg; 190 struct GNUNET_MessageHeader *msg;
@@ -202,10 +201,9 @@ run (void *cls,
202 msg->size = 201 msg->size =
203 htons (sizeof (struct GNUNET_MessageHeader) + (17 * i) % (32 * 1024)); 202 htons (sizeof (struct GNUNET_MessageHeader) + (17 * i) % (32 * 1024));
204 frags[i] = GNUNET_FRAGMENT_context_create (NULL /* no stats */ , 203 frags[i] = GNUNET_FRAGMENT_context_create (NULL /* no stats */ ,
205 MTU, 204 MTU, &trackers[i],
206 &trackers[i], 205 GNUNET_TIME_UNIT_SECONDS, msg,
207 GNUNET_TIME_UNIT_SECONDS, 206 &proc_frac, &frags[i]);
208 msg, &proc_frac, &frags[i]);
209 } 207 }
210} 208}
211 209
diff --git a/src/fs/fs.c b/src/fs/fs.c
index 318b7088e..e26a01996 100644
--- a/src/fs/fs.c
+++ b/src/fs/fs.c
@@ -52,8 +52,7 @@ start_job (struct GNUNET_FS_QueueEntry *qe)
52 qe->h->active_blocks += qe->blocks; 52 qe->h->active_blocks += qe->blocks;
53 qe->start_time = GNUNET_TIME_absolute_get (); 53 qe->start_time = GNUNET_TIME_absolute_get ();
54 GNUNET_CONTAINER_DLL_remove (qe->h->pending_head, qe->h->pending_tail, qe); 54 GNUNET_CONTAINER_DLL_remove (qe->h->pending_head, qe->h->pending_tail, qe);
55 GNUNET_CONTAINER_DLL_insert_after (qe->h->running_head, 55 GNUNET_CONTAINER_DLL_insert_after (qe->h->running_head, qe->h->running_tail,
56 qe->h->running_tail,
57 qe->h->running_tail, qe); 56 qe->h->running_tail, qe);
58} 57}
59 58
@@ -71,12 +70,12 @@ stop_job (struct GNUNET_FS_QueueEntry *qe)
71 qe->stop (qe->cls); 70 qe->stop (qe->cls);
72 qe->h->active_downloads--; 71 qe->h->active_downloads--;
73 qe->h->active_blocks -= qe->blocks; 72 qe->h->active_blocks -= qe->blocks;
74 qe->run_time = GNUNET_TIME_relative_add (qe->run_time, 73 qe->run_time =
75 GNUNET_TIME_absolute_get_duration 74 GNUNET_TIME_relative_add (qe->run_time,
76 (qe->start_time)); 75 GNUNET_TIME_absolute_get_duration (qe->
76 start_time));
77 GNUNET_CONTAINER_DLL_remove (qe->h->running_head, qe->h->running_tail, qe); 77 GNUNET_CONTAINER_DLL_remove (qe->h->running_head, qe->h->running_tail, qe);
78 GNUNET_CONTAINER_DLL_insert_after (qe->h->pending_head, 78 GNUNET_CONTAINER_DLL_insert_after (qe->h->pending_head, qe->h->pending_tail,
79 qe->h->pending_tail,
80 qe->h->pending_tail, qe); 79 qe->h->pending_tail, qe);
81} 80}
82 81
@@ -123,8 +122,9 @@ process_job_queue (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
123 while (NULL != (qe = next)) 122 while (NULL != (qe = next))
124 { 123 {
125 next = qe->next; 124 next = qe->next;
126 run_time = GNUNET_TIME_relative_multiply (h->avg_block_latency, 125 run_time =
127 qe->blocks * qe->start_times); 126 GNUNET_TIME_relative_multiply (h->avg_block_latency,
127 qe->blocks * qe->start_times);
128 end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time); 128 end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time);
129 rst = GNUNET_TIME_absolute_get_remaining (end_time); 129 rst = GNUNET_TIME_absolute_get_remaining (end_time);
130 restart_at = GNUNET_TIME_relative_min (rst, restart_at); 130 restart_at = GNUNET_TIME_relative_min (rst, restart_at);
@@ -132,8 +132,8 @@ process_job_queue (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
132 continue; 132 continue;
133 stop_job (qe); 133 stop_job (qe);
134 } 134 }
135 h->queue_job = GNUNET_SCHEDULER_add_delayed (restart_at, 135 h->queue_job =
136 &process_job_queue, h); 136 GNUNET_SCHEDULER_add_delayed (restart_at, &process_job_queue, h);
137} 137}
138 138
139 139
@@ -148,8 +148,7 @@ process_job_queue (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
148 * @return queue handle 148 * @return queue handle
149 */ 149 */
150struct GNUNET_FS_QueueEntry * 150struct GNUNET_FS_QueueEntry *
151GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, 151GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, GNUNET_FS_QueueStart start,
152 GNUNET_FS_QueueStart start,
153 GNUNET_FS_QueueStop stop, void *cls, unsigned int blocks) 152 GNUNET_FS_QueueStop stop, void *cls, unsigned int blocks)
154{ 153{
155 struct GNUNET_FS_QueueEntry *qe; 154 struct GNUNET_FS_QueueEntry *qe;
@@ -161,8 +160,8 @@ GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h,
161 qe->cls = cls; 160 qe->cls = cls;
162 qe->queue_time = GNUNET_TIME_absolute_get (); 161 qe->queue_time = GNUNET_TIME_absolute_get ();
163 qe->blocks = blocks; 162 qe->blocks = blocks;
164 GNUNET_CONTAINER_DLL_insert_after (h->pending_head, 163 GNUNET_CONTAINER_DLL_insert_after (h->pending_head, h->pending_tail,
165 h->pending_tail, h->pending_tail, qe); 164 h->pending_tail, qe);
166 if (h->queue_job != GNUNET_SCHEDULER_NO_TASK) 165 if (h->queue_job != GNUNET_SCHEDULER_NO_TASK)
167 GNUNET_SCHEDULER_cancel (h->queue_job); 166 GNUNET_SCHEDULER_cancel (h->queue_job);
168 h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h); 167 h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h);
@@ -199,8 +198,8 @@ GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qh)
199 * @return fresh top-level activity handle 198 * @return fresh top-level activity handle
200 */ 199 */
201struct TopLevelActivity * 200struct TopLevelActivity *
202GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, 201GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, SuspendSignalFunction ssf,
203 SuspendSignalFunction ssf, void *ssf_cls) 202 void *ssf_cls)
204{ 203{
205 struct TopLevelActivity *ret; 204 struct TopLevelActivity *ret;
206 205
@@ -261,9 +260,8 @@ struct FileInfo
261 * @return number of bytes written, usually "max", 0 on error 260 * @return number of bytes written, usually "max", 0 on error
262 */ 261 */
263size_t 262size_t
264GNUNET_FS_data_reader_file_ (void *cls, 263GNUNET_FS_data_reader_file_ (void *cls, uint64_t offset, size_t max, void *buf,
265 uint64_t offset, 264 char **emsg)
266 size_t max, void *buf, char **emsg)
267{ 265{
268 struct FileInfo *fi = cls; 266 struct FileInfo *fi = cls;
269 ssize_t ret; 267 ssize_t ret;
@@ -278,14 +276,13 @@ GNUNET_FS_data_reader_file_ (void *cls,
278 } 276 }
279 if (fi->fd == NULL) 277 if (fi->fd == NULL)
280 { 278 {
281 fi->fd = GNUNET_DISK_file_open (fi->filename, 279 fi->fd =
282 GNUNET_DISK_OPEN_READ, 280 GNUNET_DISK_file_open (fi->filename, GNUNET_DISK_OPEN_READ,
283 GNUNET_DISK_PERM_NONE); 281 GNUNET_DISK_PERM_NONE);
284 if (fi->fd == NULL) 282 if (fi->fd == NULL)
285 { 283 {
286 GNUNET_asprintf (emsg, 284 GNUNET_asprintf (emsg, _("Could not open file `%s': %s"), fi->filename,
287 _("Could not open file `%s': %s"), 285 STRERROR (errno));
288 fi->filename, STRERROR (errno));
289 return 0; 286 return 0;
290 } 287 }
291 } 288 }
@@ -293,15 +290,14 @@ GNUNET_FS_data_reader_file_ (void *cls,
293 ret = GNUNET_DISK_file_read (fi->fd, buf, max); 290 ret = GNUNET_DISK_file_read (fi->fd, buf, max);
294 if (ret == -1) 291 if (ret == -1)
295 { 292 {
296 GNUNET_asprintf (emsg, 293 GNUNET_asprintf (emsg, _("Could not read file `%s': %s"), fi->filename,
297 _("Could not read file `%s': %s"), 294 STRERROR (errno));
298 fi->filename, STRERROR (errno));
299 return 0; 295 return 0;
300 } 296 }
301 if (ret != max) 297 if (ret != max)
302 { 298 {
303 GNUNET_asprintf (emsg, 299 GNUNET_asprintf (emsg, _("Short read reading from file `%s'!"),
304 _("Short read reading from file `%s'!"), fi->filename); 300 fi->filename);
305 return 0; 301 return 0;
306 } 302 }
307 return max; 303 return max;
@@ -347,9 +343,8 @@ GNUNET_FS_make_file_reader_context_ (const char *filename)
347 * @return number of bytes written, usually "max", 0 on error 343 * @return number of bytes written, usually "max", 0 on error
348 */ 344 */
349size_t 345size_t
350GNUNET_FS_data_reader_copy_ (void *cls, 346GNUNET_FS_data_reader_copy_ (void *cls, uint64_t offset, size_t max, void *buf,
351 uint64_t offset, 347 char **emsg)
352 size_t max, void *buf, char **emsg)
353{ 348{
354 char *data = cls; 349 char *data = cls;
355 350
@@ -373,8 +368,8 @@ GNUNET_FS_data_reader_copy_ (void *cls,
373 * @return NULL on error 368 * @return NULL on error
374 */ 369 */
375static char * 370static char *
376get_serialization_file_name (struct GNUNET_FS_Handle *h, 371get_serialization_file_name (struct GNUNET_FS_Handle *h, const char *ext,
377 const char *ext, const char *ent) 372 const char *ent)
378{ 373{
379 char *basename; 374 char *basename;
380 char *ret; 375 char *ret;
@@ -382,15 +377,12 @@ get_serialization_file_name (struct GNUNET_FS_Handle *h,
382 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) 377 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
383 return NULL; /* persistence not requested */ 378 return NULL; /* persistence not requested */
384 if (GNUNET_OK != 379 if (GNUNET_OK !=
385 GNUNET_CONFIGURATION_get_value_filename (h->cfg, 380 GNUNET_CONFIGURATION_get_value_filename (h->cfg, "fs", "STATE_DIR",
386 "fs", "STATE_DIR", &basename)) 381 &basename))
387 return NULL; 382 return NULL;
388 GNUNET_asprintf (&ret, 383 GNUNET_asprintf (&ret, "%s%s%s%s%s%s%s", basename, DIR_SEPARATOR_STR,
389 "%s%s%s%s%s%s%s", 384 h->client_name, DIR_SEPARATOR_STR, ext, DIR_SEPARATOR_STR,
390 basename, 385 ent);
391 DIR_SEPARATOR_STR,
392 h->client_name,
393 DIR_SEPARATOR_STR, ext, DIR_SEPARATOR_STR, ent);
394 GNUNET_free (basename); 386 GNUNET_free (basename);
395 return ret; 387 return ret;
396} 388}
@@ -408,8 +400,7 @@ get_serialization_file_name (struct GNUNET_FS_Handle *h,
408 * @return NULL on error 400 * @return NULL on error
409 */ 401 */
410static char * 402static char *
411get_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, 403get_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, const char *ext,
412 const char *ext,
413 const char *uni, const char *ent) 404 const char *uni, const char *ent)
414{ 405{
415 char *basename; 406 char *basename;
@@ -418,16 +409,12 @@ get_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h,
418 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) 409 if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
419 return NULL; /* persistence not requested */ 410 return NULL; /* persistence not requested */
420 if (GNUNET_OK != 411 if (GNUNET_OK !=
421 GNUNET_CONFIGURATION_get_value_filename (h->cfg, 412 GNUNET_CONFIGURATION_get_value_filename (h->cfg, "fs", "STATE_DIR",
422 "fs", "STATE_DIR", &basename)) 413 &basename))
423 return NULL; 414 return NULL;
424 GNUNET_asprintf (&ret, 415 GNUNET_asprintf (&ret, "%s%s%s%s%s%s%s.dir%s%s", basename, DIR_SEPARATOR_STR,
425 "%s%s%s%s%s%s%s.dir%s%s", 416 h->client_name, DIR_SEPARATOR_STR, ext, DIR_SEPARATOR_STR,
426 basename, 417 uni, DIR_SEPARATOR_STR, ent);
427 DIR_SEPARATOR_STR,
428 h->client_name,
429 DIR_SEPARATOR_STR,
430 ext, DIR_SEPARATOR_STR, uni, DIR_SEPARATOR_STR, ent);
431 GNUNET_free (basename); 418 GNUNET_free (basename);
432 return ret; 419 return ret;
433} 420}
@@ -493,8 +480,8 @@ get_write_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
493 * @return NULL on error 480 * @return NULL on error
494 */ 481 */
495static struct GNUNET_BIO_WriteHandle * 482static struct GNUNET_BIO_WriteHandle *
496get_write_handle_in_dir (struct GNUNET_FS_Handle *h, 483get_write_handle_in_dir (struct GNUNET_FS_Handle *h, const char *ext,
497 const char *ext, const char *uni, const char *ent) 484 const char *uni, const char *ent)
498{ 485{
499 char *fn; 486 char *fn;
500 struct GNUNET_BIO_WriteHandle *ret; 487 struct GNUNET_BIO_WriteHandle *ret;
@@ -516,8 +503,8 @@ get_write_handle_in_dir (struct GNUNET_FS_Handle *h,
516 * @param ent entity identifier 503 * @param ent entity identifier
517 */ 504 */
518void 505void
519GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, 506GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, const char *ext,
520 const char *ext, const char *ent) 507 const char *ent)
521{ 508{
522 char *filename; 509 char *filename;
523 510
@@ -545,8 +532,8 @@ GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
545 * @param ent entity identifier 532 * @param ent entity identifier
546 */ 533 */
547static void 534static void
548remove_sync_file_in_dir (struct GNUNET_FS_Handle *h, 535remove_sync_file_in_dir (struct GNUNET_FS_Handle *h, const char *ext,
549 const char *ext, const char *uni, const char *ent) 536 const char *uni, const char *ent)
550{ 537{
551 char *filename; 538 char *filename;
552 539
@@ -573,8 +560,8 @@ remove_sync_file_in_dir (struct GNUNET_FS_Handle *h,
573 * @param uni unique name of parent 560 * @param uni unique name of parent
574 */ 561 */
575void 562void
576GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h, 563GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h, const char *ext,
577 const char *ext, const char *uni) 564 const char *uni)
578{ 565{
579 char *dn; 566 char *dn;
580 567
@@ -670,8 +657,8 @@ static struct GNUNET_FS_FileInformation *deserialize_file_information (struct
670 * @return NULL on error 657 * @return NULL on error
671 */ 658 */
672static struct GNUNET_FS_FileInformation * 659static struct GNUNET_FS_FileInformation *
673deserialize_fi_node (struct GNUNET_FS_Handle *h, 660deserialize_fi_node (struct GNUNET_FS_Handle *h, const char *fn,
674 const char *fn, struct GNUNET_BIO_ReadHandle *rh) 661 struct GNUNET_BIO_ReadHandle *rh)
675{ 662{
676 struct GNUNET_FS_FileInformation *ret; 663 struct GNUNET_FS_FileInformation *ret;
677 struct GNUNET_FS_FileInformation *nxt; 664 struct GNUNET_FS_FileInformation *nxt;
@@ -691,34 +678,23 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h,
691 ksks = NULL; 678 ksks = NULL;
692 chks = NULL; 679 chks = NULL;
693 filename = NULL; 680 filename = NULL;
694 if ((GNUNET_OK != 681 if ((GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) ||
695 GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) || 682 (GNUNET_OK != GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32 * 1024)) ||
696 (GNUNET_OK !=
697 GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32 * 1024)) ||
698 ((ksks != NULL) && 683 ((ksks != NULL) &&
699 (NULL == 684 (NULL == (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL)))) ||
700 (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL)))) || 685 (GNUNET_YES != GNUNET_FS_uri_test_ksk (ret->keywords)) ||
701 (GNUNET_YES != 686 (GNUNET_OK != GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) ||
702 GNUNET_FS_uri_test_ksk (ret->keywords)) ||
703 (GNUNET_OK !=
704 GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) ||
705 ((chks != NULL) && 687 ((chks != NULL) &&
706 ((NULL == 688 ((NULL == (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) ||
707 (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) || 689 (GNUNET_YES != GNUNET_FS_uri_test_chk (ret->chk_uri)))) ||
708 (GNUNET_YES != 690 (GNUNET_OK != read_start_time (rh, &ret->start_time)) ||
709 GNUNET_FS_uri_test_chk (ret->chk_uri)))) || 691 (GNUNET_OK != GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16 * 1024))
710 (GNUNET_OK != 692 || (GNUNET_OK !=
711 read_start_time (rh, &ret->start_time)) || 693 GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) ||
712 (GNUNET_OK !=
713 GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16 * 1024)) ||
714 (GNUNET_OK !=
715 GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) ||
716 (GNUNET_OK != 694 (GNUNET_OK !=
717 GNUNET_BIO_read_int64 (rh, &ret->bo.expiration_time.abs_value)) || 695 GNUNET_BIO_read_int64 (rh, &ret->bo.expiration_time.abs_value)) ||
718 (GNUNET_OK != 696 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.anonymity_level)) ||
719 GNUNET_BIO_read_int32 (rh, &ret->bo.anonymity_level)) || 697 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.content_priority)) ||
720 (GNUNET_OK !=
721 GNUNET_BIO_read_int32 (rh, &ret->bo.content_priority)) ||
722 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.replication_level))) 698 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.replication_level)))
723 { 699 {
724 GNUNET_break (0); 700 GNUNET_break (0);
@@ -786,8 +762,7 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h,
786 GNUNET_break (0); 762 GNUNET_break (0);
787 goto cleanup; 763 goto cleanup;
788 } 764 }
789 if ((GNUNET_OK != 765 if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
790 GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
791 (GNUNET_OK != 766 (GNUNET_OK !=
792 GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id, 767 GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id,
793 sizeof (GNUNET_HashCode)))) 768 sizeof (GNUNET_HashCode))))
@@ -809,8 +784,7 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h,
809 GNUNET_break (0); 784 GNUNET_break (0);
810 goto cleanup; 785 goto cleanup;
811 } 786 }
812 if ((GNUNET_OK != 787 if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
813 GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
814 (GNUNET_OK != 788 (GNUNET_OK !=
815 GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id, 789 GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id,
816 sizeof (GNUNET_HashCode)))) 790 sizeof (GNUNET_HashCode))))
@@ -828,8 +802,7 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h,
828 break; 802 break;
829 case 4: /* directory */ 803 case 4: /* directory */
830 ret->is_directory = GNUNET_YES; 804 ret->is_directory = GNUNET_YES;
831 if ((GNUNET_OK != 805 if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dsize)) ||
832 GNUNET_BIO_read_int32 (rh, &dsize)) ||
833 (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) || 806 (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) ||
834 (GNUNET_OK != 807 (GNUNET_OK !=
835 GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) || 808 GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) ||
@@ -1046,8 +1019,8 @@ copy_from_reader (struct GNUNET_BIO_WriteHandle *wh,
1046 while (off < fi->data.file.file_size) 1019 while (off < fi->data.file.file_size)
1047 { 1020 {
1048 left = GNUNET_MIN (sizeof (buf), fi->data.file.file_size - off); 1021 left = GNUNET_MIN (sizeof (buf), fi->data.file.file_size - off);
1049 ret = fi->data.file.reader (fi->data.file.reader_cls, 1022 ret =
1050 off, left, buf, &emsg); 1023 fi->data.file.reader (fi->data.file.reader_cls, off, left, buf, &emsg);
1051 if (ret == 0) 1024 if (ret == 0)
1052 { 1025 {
1053 GNUNET_free (emsg); 1026 GNUNET_free (emsg);
@@ -1107,26 +1080,17 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi)
1107 chks = GNUNET_FS_uri_to_string (fi->chk_uri); 1080 chks = GNUNET_FS_uri_to_string (fi->chk_uri);
1108 else 1081 else
1109 chks = NULL; 1082 chks = NULL;
1110 if ((GNUNET_OK != 1083 if ((GNUNET_OK != GNUNET_BIO_write (wh, &b, sizeof (b))) ||
1111 GNUNET_BIO_write (wh, &b, sizeof (b))) || 1084 (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, fi->meta)) ||
1112 (GNUNET_OK != 1085 (GNUNET_OK != GNUNET_BIO_write_string (wh, ksks)) ||
1113 GNUNET_BIO_write_meta_data (wh, fi->meta)) || 1086 (GNUNET_OK != GNUNET_BIO_write_string (wh, chks)) ||
1114 (GNUNET_OK != 1087 (GNUNET_OK != write_start_time (wh, fi->start_time)) ||
1115 GNUNET_BIO_write_string (wh, ksks)) || 1088 (GNUNET_OK != GNUNET_BIO_write_string (wh, fi->emsg)) ||
1116 (GNUNET_OK != 1089 (GNUNET_OK != GNUNET_BIO_write_string (wh, fi->filename)) ||
1117 GNUNET_BIO_write_string (wh, chks)) ||
1118 (GNUNET_OK !=
1119 write_start_time (wh, fi->start_time)) ||
1120 (GNUNET_OK !=
1121 GNUNET_BIO_write_string (wh, fi->emsg)) ||
1122 (GNUNET_OK !=
1123 GNUNET_BIO_write_string (wh, fi->filename)) ||
1124 (GNUNET_OK != 1090 (GNUNET_OK !=
1125 GNUNET_BIO_write_int64 (wh, fi->bo.expiration_time.abs_value)) || 1091 GNUNET_BIO_write_int64 (wh, fi->bo.expiration_time.abs_value)) ||
1126 (GNUNET_OK != 1092 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->bo.anonymity_level)) ||
1127 GNUNET_BIO_write_int32 (wh, fi->bo.anonymity_level)) || 1093 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->bo.content_priority)) ||
1128 (GNUNET_OK !=
1129 GNUNET_BIO_write_int32 (wh, fi->bo.content_priority)) ||
1130 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->bo.replication_level))) 1094 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->bo.replication_level)))
1131 { 1095 {
1132 GNUNET_break (0); 1096 GNUNET_break (0);
@@ -1171,8 +1135,7 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi)
1171 GNUNET_break (0); 1135 GNUNET_break (0);
1172 goto cleanup; 1136 goto cleanup;
1173 } 1137 }
1174 if ((GNUNET_OK != 1138 if ((GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) ||
1175 GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) ||
1176 (GNUNET_OK != 1139 (GNUNET_OK !=
1177 GNUNET_BIO_write (wh, &fi->data.file.file_id, 1140 GNUNET_BIO_write (wh, &fi->data.file.file_id,
1178 sizeof (GNUNET_HashCode)))) 1141 sizeof (GNUNET_HashCode))))
@@ -1182,16 +1145,15 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi)
1182 } 1145 }
1183 break; 1146 break;
1184 case 4: /* directory */ 1147 case 4: /* directory */
1185 if ((GNUNET_OK != 1148 if ((GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) ||
1186 GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) ||
1187 (GNUNET_OK != 1149 (GNUNET_OK !=
1188 GNUNET_BIO_write (wh, fi->data.dir.dir_data, 1150 GNUNET_BIO_write (wh, fi->data.dir.dir_data,
1189 (uint32_t) fi->data.dir.dir_size)) || 1151 (uint32_t) fi->data.dir.dir_size)) ||
1190 (GNUNET_OK != 1152 (GNUNET_OK !=
1191 GNUNET_BIO_write_string (wh, 1153 GNUNET_BIO_write_string (wh,
1192 (fi->data.dir.entries == 1154 (fi->data.dir.entries ==
1193 NULL) ? NULL : fi->data.dir. 1155 NULL) ? NULL : fi->data.dir.entries->
1194 entries->serialization))) 1156 serialization)))
1195 { 1157 {
1196 GNUNET_break (0); 1158 GNUNET_break (0);
1197 goto cleanup; 1159 goto cleanup;
@@ -1279,13 +1241,11 @@ find_file_position (struct GNUNET_FS_FileInformation *pos, const char *srch)
1279 * @return GNUNET_OK to continue (always) 1241 * @return GNUNET_OK to continue (always)
1280 */ 1242 */
1281static int 1243static int
1282fip_signal_resume (void *cls, 1244fip_signal_resume (void *cls, struct GNUNET_FS_FileInformation *fi,
1283 struct GNUNET_FS_FileInformation *fi, 1245 uint64_t length, struct GNUNET_CONTAINER_MetaData *meta,
1284 uint64_t length,
1285 struct GNUNET_CONTAINER_MetaData *meta,
1286 struct GNUNET_FS_Uri **uri, 1246 struct GNUNET_FS_Uri **uri,
1287 struct GNUNET_FS_BlockOptions *bo, 1247 struct GNUNET_FS_BlockOptions *bo, int *do_index,
1288 int *do_index, void **client_info) 1248 void **client_info)
1289{ 1249{
1290 struct GNUNET_FS_PublishContext *sc = cls; 1250 struct GNUNET_FS_PublishContext *sc = cls;
1291 struct GNUNET_FS_ProgressInfo pi; 1251 struct GNUNET_FS_ProgressInfo pi;
@@ -1331,19 +1291,15 @@ deserialize_publish_file (void *cls, const char *filename)
1331 GNUNET_break (0); 1291 GNUNET_break (0);
1332 goto cleanup; 1292 goto cleanup;
1333 } 1293 }
1334 if ((GNUNET_OK != 1294 if ((GNUNET_OK != GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024))
1335 GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) || 1295 || (GNUNET_OK !=
1336 (GNUNET_OK != 1296 GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) ||
1337 GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) || 1297 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) ||
1338 (GNUNET_OK != 1298 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &all_done)) ||
1339 GNUNET_BIO_read_int32 (rh, &options)) ||
1340 (GNUNET_OK !=
1341 GNUNET_BIO_read_int32 (rh, &all_done)) ||
1342 (GNUNET_OK != 1299 (GNUNET_OK !=
1343 GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) || 1300 GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) ||
1344 (GNUNET_OK != 1301 (GNUNET_OK != GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128))
1345 GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) || 1302 || (GNUNET_OK != GNUNET_BIO_read_string (rh, "publish-ns", &ns, 1024)))
1346 (GNUNET_OK != GNUNET_BIO_read_string (rh, "publish-ns", &ns, 1024)))
1347 { 1303 {
1348 GNUNET_break (0); 1304 GNUNET_break (0);
1349 goto cleanup; 1305 goto cleanup;
@@ -1402,8 +1358,7 @@ deserialize_publish_file (void *cls, const char *filename)
1402 if (pc->all_done != GNUNET_YES) 1358 if (pc->all_done != GNUNET_YES)
1403 { 1359 {
1404 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); 1360 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
1405 pc->upload_task 1361 pc->upload_task =
1406 =
1407 GNUNET_SCHEDULER_add_with_priority 1362 GNUNET_SCHEDULER_add_with_priority
1408 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc); 1363 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc);
1409 } 1364 }
@@ -1426,8 +1381,8 @@ cleanup:
1426 if ((rh != NULL) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))) 1381 if ((rh != NULL) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)))
1427 { 1382 {
1428 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1383 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1429 _("Failed to resume publishing operation `%s': %s\n"), 1384 _("Failed to resume publishing operation `%s': %s\n"), filename,
1430 filename, emsg); 1385 emsg);
1431 GNUNET_free (emsg); 1386 GNUNET_free (emsg);
1432 } 1387 }
1433 if (pc->fi != NULL) 1388 if (pc->fi != NULL)
@@ -1454,8 +1409,9 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc)
1454 struct GNUNET_BIO_WriteHandle *wh; 1409 struct GNUNET_BIO_WriteHandle *wh;
1455 1410
1456 if (NULL == pc->serialization) 1411 if (NULL == pc->serialization)
1457 pc->serialization = make_serialization_file_name (pc->h, 1412 pc->serialization =
1458 GNUNET_FS_SYNC_PATH_MASTER_PUBLISH); 1413 make_serialization_file_name (pc->h,
1414 GNUNET_FS_SYNC_PATH_MASTER_PUBLISH);
1459 if (NULL == pc->serialization) 1415 if (NULL == pc->serialization)
1460 return; 1416 return;
1461 if (NULL == pc->fi) 1417 if (NULL == pc->fi)
@@ -1472,16 +1428,11 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc)
1472 GNUNET_break (0); 1428 GNUNET_break (0);
1473 goto cleanup; 1429 goto cleanup;
1474 } 1430 }
1475 if ((GNUNET_OK != 1431 if ((GNUNET_OK != GNUNET_BIO_write_string (wh, pc->nid)) ||
1476 GNUNET_BIO_write_string (wh, pc->nid)) || 1432 (GNUNET_OK != GNUNET_BIO_write_string (wh, pc->nuid)) ||
1477 (GNUNET_OK != 1433 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pc->options)) ||
1478 GNUNET_BIO_write_string (wh, pc->nuid)) || 1434 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pc->all_done)) ||
1479 (GNUNET_OK != 1435 (GNUNET_OK != GNUNET_BIO_write_string (wh, pc->fi->serialization)) ||
1480 GNUNET_BIO_write_int32 (wh, pc->options)) ||
1481 (GNUNET_OK !=
1482 GNUNET_BIO_write_int32 (wh, pc->all_done)) ||
1483 (GNUNET_OK !=
1484 GNUNET_BIO_write_string (wh, pc->fi->serialization)) ||
1485 (GNUNET_OK != 1436 (GNUNET_OK !=
1486 GNUNET_BIO_write_string (wh, 1437 GNUNET_BIO_write_string (wh,
1487 (pc->fi_pos == 1438 (pc->fi_pos ==
@@ -1525,8 +1476,9 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc)
1525 struct GNUNET_BIO_WriteHandle *wh; 1476 struct GNUNET_BIO_WriteHandle *wh;
1526 1477
1527 if (NULL == uc->serialization) 1478 if (NULL == uc->serialization)
1528 uc->serialization = make_serialization_file_name (uc->h, 1479 uc->serialization =
1529 GNUNET_FS_SYNC_PATH_MASTER_UNINDEX); 1480 make_serialization_file_name (uc->h,
1481 GNUNET_FS_SYNC_PATH_MASTER_UNINDEX);
1530 if (NULL == uc->serialization) 1482 if (NULL == uc->serialization)
1531 return; 1483 return;
1532 wh = get_write_handle (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, 1484 wh = get_write_handle (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
@@ -1536,14 +1488,10 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc)
1536 GNUNET_break (0); 1488 GNUNET_break (0);
1537 goto cleanup; 1489 goto cleanup;
1538 } 1490 }
1539 if ((GNUNET_OK != 1491 if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uc->filename)) ||
1540 GNUNET_BIO_write_string (wh, uc->filename)) || 1492 (GNUNET_OK != GNUNET_BIO_write_int64 (wh, uc->file_size)) ||
1541 (GNUNET_OK != 1493 (GNUNET_OK != write_start_time (wh, uc->start_time)) ||
1542 GNUNET_BIO_write_int64 (wh, uc->file_size)) || 1494 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) uc->state)) ||
1543 (GNUNET_OK !=
1544 write_start_time (wh, uc->start_time)) ||
1545 (GNUNET_OK !=
1546 GNUNET_BIO_write_int32 (wh, (uint32_t) uc->state)) ||
1547 ((uc->state == UNINDEX_STATE_FS_NOTIFY) && 1495 ((uc->state == UNINDEX_STATE_FS_NOTIFY) &&
1548 (GNUNET_OK != 1496 (GNUNET_OK !=
1549 GNUNET_BIO_write (wh, &uc->file_id, sizeof (GNUNET_HashCode)))) || 1497 GNUNET_BIO_write (wh, &uc->file_id, sizeof (GNUNET_HashCode)))) ||
@@ -1583,12 +1531,9 @@ write_download_request (struct GNUNET_BIO_WriteHandle *wh,
1583{ 1531{
1584 unsigned int i; 1532 unsigned int i;
1585 1533
1586 if ((GNUNET_OK != 1534 if ((GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->state)) ||
1587 GNUNET_BIO_write_int32 (wh, dr->state)) || 1535 (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dr->offset)) ||
1588 (GNUNET_OK != 1536 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->num_children)) ||
1589 GNUNET_BIO_write_int64 (wh, dr->offset)) ||
1590 (GNUNET_OK !=
1591 GNUNET_BIO_write_int32 (wh, dr->num_children)) ||
1592 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->depth))) 1537 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->depth)))
1593 return GNUNET_NO; 1538 return GNUNET_NO;
1594 if ((dr->state == BRS_CHK_SET) && 1539 if ((dr->state == BRS_CHK_SET) &&
@@ -1616,16 +1561,14 @@ read_download_request (struct GNUNET_BIO_ReadHandle *rh)
1616 1561
1617 dr = GNUNET_malloc (sizeof (struct DownloadRequest)); 1562 dr = GNUNET_malloc (sizeof (struct DownloadRequest));
1618 1563
1619 if ((GNUNET_OK != 1564 if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->state)) ||
1620 GNUNET_BIO_read_int32 (rh, &dr->state)) || 1565 (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dr->offset)) ||
1621 (GNUNET_OK != 1566 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->num_children)) ||
1622 GNUNET_BIO_read_int64 (rh, &dr->offset)) ||
1623 (GNUNET_OK !=
1624 GNUNET_BIO_read_int32 (rh, &dr->num_children)) ||
1625 (dr->num_children > CHK_PER_INODE) || 1567 (dr->num_children > CHK_PER_INODE) ||
1626 (GNUNET_OK != 1568 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->depth)) || ((dr->depth == 0)
1627 GNUNET_BIO_read_int32 (rh, &dr->depth)) || 1569 && (dr->
1628 ((dr->depth == 0) && (dr->num_children > 0)) || 1570 num_children
1571 > 0)) ||
1629 ((dr->depth > 0) && (dr->num_children == 0))) 1572 ((dr->depth > 0) && (dr->num_children == 0)))
1630 { 1573 {
1631 GNUNET_break (0); 1574 GNUNET_break (0);
@@ -1633,8 +1576,8 @@ read_download_request (struct GNUNET_BIO_ReadHandle *rh)
1633 goto cleanup; 1576 goto cleanup;
1634 } 1577 }
1635 if (dr->num_children > 0) 1578 if (dr->num_children > 0)
1636 dr->children = GNUNET_malloc (dr->num_children * 1579 dr->children =
1637 sizeof (struct ContentHashKey)); 1580 GNUNET_malloc (dr->num_children * sizeof (struct ContentHashKey));
1638 switch (dr->state) 1581 switch (dr->state)
1639 { 1582 {
1640 case BRS_INIT: 1583 case BRS_INIT:
@@ -1686,7 +1629,8 @@ get_download_sync_filename (struct GNUNET_FS_DownloadContext *dc,
1686 1629
1687 if (dc->parent == NULL) 1630 if (dc->parent == NULL)
1688 return get_serialization_file_name (dc->h, 1631 return get_serialization_file_name (dc->h,
1689 (dc->search != NULL) ? 1632 (dc->search !=
1633 NULL) ?
1690 GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD : 1634 GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD :
1691 GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, 1635 GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
1692 uni); 1636 uni);
@@ -1755,30 +1699,18 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc)
1755 GNUNET_assert ((GNUNET_YES == GNUNET_FS_uri_test_chk (dc->uri)) || 1699 GNUNET_assert ((GNUNET_YES == GNUNET_FS_uri_test_chk (dc->uri)) ||
1756 (GNUNET_YES == GNUNET_FS_uri_test_loc (dc->uri))); 1700 (GNUNET_YES == GNUNET_FS_uri_test_loc (dc->uri)));
1757 uris = GNUNET_FS_uri_to_string (dc->uri); 1701 uris = GNUNET_FS_uri_to_string (dc->uri);
1758 if ((GNUNET_OK != 1702 if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) ||
1759 GNUNET_BIO_write_string (wh, uris)) || 1703 (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, dc->meta)) ||
1760 (GNUNET_OK != 1704 (GNUNET_OK != GNUNET_BIO_write_string (wh, dc->emsg)) ||
1761 GNUNET_BIO_write_meta_data (wh, dc->meta)) || 1705 (GNUNET_OK != GNUNET_BIO_write_string (wh, dc->filename)) ||
1762 (GNUNET_OK != 1706 (GNUNET_OK != GNUNET_BIO_write_string (wh, dc->temp_filename)) ||
1763 GNUNET_BIO_write_string (wh, dc->emsg)) || 1707 (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->old_file_size)) ||
1764 (GNUNET_OK != 1708 (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->offset)) ||
1765 GNUNET_BIO_write_string (wh, dc->filename)) || 1709 (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->length)) ||
1766 (GNUNET_OK != 1710 (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->completed)) ||
1767 GNUNET_BIO_write_string (wh, dc->temp_filename)) || 1711 (GNUNET_OK != write_start_time (wh, dc->start_time)) ||
1768 (GNUNET_OK != 1712 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dc->anonymity)) ||
1769 GNUNET_BIO_write_int64 (wh, dc->old_file_size)) || 1713 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) dc->options)) ||
1770 (GNUNET_OK !=
1771 GNUNET_BIO_write_int64 (wh, dc->offset)) ||
1772 (GNUNET_OK !=
1773 GNUNET_BIO_write_int64 (wh, dc->length)) ||
1774 (GNUNET_OK !=
1775 GNUNET_BIO_write_int64 (wh, dc->completed)) ||
1776 (GNUNET_OK !=
1777 write_start_time (wh, dc->start_time)) ||
1778 (GNUNET_OK !=
1779 GNUNET_BIO_write_int32 (wh, dc->anonymity)) ||
1780 (GNUNET_OK !=
1781 GNUNET_BIO_write_int32 (wh, (uint32_t) dc->options)) ||
1782 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) dc->has_finished))) 1714 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) dc->has_finished)))
1783 { 1715 {
1784 GNUNET_break (0); 1716 GNUNET_break (0);
@@ -1831,22 +1763,19 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr)
1831 1763
1832 uris = NULL; 1764 uris = NULL;
1833 if (NULL == sr->serialization) 1765 if (NULL == sr->serialization)
1834 sr->serialization = make_serialization_file_name_in_dir (sr->sc->h, 1766 sr->serialization =
1835 (sr-> 1767 make_serialization_file_name_in_dir (sr->sc->h,
1836 sc->psearch_result 1768 (sr->sc->psearch_result ==
1837 == 1769 NULL) ?
1838 NULL) ? 1770 GNUNET_FS_SYNC_PATH_MASTER_SEARCH :
1839 GNUNET_FS_SYNC_PATH_MASTER_SEARCH 1771 GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
1840 : 1772 sr->sc->serialization);
1841 GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
1842 sr->
1843 sc->serialization);
1844 if (NULL == sr->serialization) 1773 if (NULL == sr->serialization)
1845 return; 1774 return;
1846 wh = get_write_handle_in_dir (sr->sc->h, 1775 wh = get_write_handle_in_dir (sr->sc->h,
1847 (sr->sc->psearch_result == NULL) 1776 (sr->sc->psearch_result ==
1848 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH 1777 NULL) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH :
1849 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 1778 GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
1850 sr->sc->serialization, sr->serialization); 1779 sr->sc->serialization, sr->serialization);
1851 if (wh == NULL) 1780 if (wh == NULL)
1852 { 1781 {
@@ -1854,8 +1783,7 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr)
1854 goto cleanup; 1783 goto cleanup;
1855 } 1784 }
1856 uris = GNUNET_FS_uri_to_string (sr->uri); 1785 uris = GNUNET_FS_uri_to_string (sr->uri);
1857 if ((GNUNET_OK != 1786 if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) ||
1858 GNUNET_BIO_write_string (wh, uris)) ||
1859 (GNUNET_OK != 1787 (GNUNET_OK !=
1860 GNUNET_BIO_write_string (wh, 1788 GNUNET_BIO_write_string (wh,
1861 sr->download != 1789 sr->download !=
@@ -1887,9 +1815,9 @@ cleanup:
1887 if (wh != NULL) 1815 if (wh != NULL)
1888 (void) GNUNET_BIO_write_close (wh); 1816 (void) GNUNET_BIO_write_close (wh);
1889 remove_sync_file_in_dir (sr->sc->h, 1817 remove_sync_file_in_dir (sr->sc->h,
1890 (sr->sc->psearch_result == NULL) 1818 (sr->sc->psearch_result ==
1891 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH 1819 NULL) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH :
1892 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 1820 GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
1893 sr->sc->serialization, sr->serialization); 1821 sr->sc->serialization, sr->serialization);
1894 GNUNET_free (sr->serialization); 1822 GNUNET_free (sr->serialization);
1895 sr->serialization = NULL; 1823 sr->serialization = NULL;
@@ -1912,8 +1840,10 @@ GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc)
1912 char in_pause; 1840 char in_pause;
1913 const char *category; 1841 const char *category;
1914 1842
1915 category = (sc->psearch_result == NULL) 1843 category =
1916 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH : GNUNET_FS_SYNC_PATH_CHILD_SEARCH; 1844 (sc->psearch_result ==
1845 NULL) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH :
1846 GNUNET_FS_SYNC_PATH_CHILD_SEARCH;
1917 if (NULL == sc->serialization) 1847 if (NULL == sc->serialization)
1918 sc->serialization = make_serialization_file_name (sc->h, category); 1848 sc->serialization = make_serialization_file_name (sc->h, category);
1919 if (NULL == sc->serialization) 1849 if (NULL == sc->serialization)
@@ -1929,16 +1859,11 @@ GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc)
1929 (GNUNET_YES == GNUNET_FS_uri_test_sks (sc->uri))); 1859 (GNUNET_YES == GNUNET_FS_uri_test_sks (sc->uri)));
1930 uris = GNUNET_FS_uri_to_string (sc->uri); 1860 uris = GNUNET_FS_uri_to_string (sc->uri);
1931 in_pause = (sc->task != GNUNET_SCHEDULER_NO_TASK) ? 'r' : '\0'; 1861 in_pause = (sc->task != GNUNET_SCHEDULER_NO_TASK) ? 'r' : '\0';
1932 if ((GNUNET_OK != 1862 if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) ||
1933 GNUNET_BIO_write_string (wh, uris)) || 1863 (GNUNET_OK != write_start_time (wh, sc->start_time)) ||
1934 (GNUNET_OK != 1864 (GNUNET_OK != GNUNET_BIO_write_string (wh, sc->emsg)) ||
1935 write_start_time (wh, sc->start_time)) || 1865 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) sc->options)) ||
1936 (GNUNET_OK != 1866 (GNUNET_OK != GNUNET_BIO_write (wh, &in_pause, sizeof (in_pause))) ||
1937 GNUNET_BIO_write_string (wh, sc->emsg)) ||
1938 (GNUNET_OK !=
1939 GNUNET_BIO_write_int32 (wh, (uint32_t) sc->options)) ||
1940 (GNUNET_OK !=
1941 GNUNET_BIO_write (wh, &in_pause, sizeof (in_pause))) ||
1942 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sc->anonymity))) 1867 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sc->anonymity)))
1943 { 1868 {
1944 GNUNET_break (0); 1869 GNUNET_break (0);
@@ -1992,10 +1917,8 @@ deserialize_unindex_file (void *cls, const char *filename)
1992 } 1917 }
1993 if ((GNUNET_OK != 1918 if ((GNUNET_OK !=
1994 GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10 * 1024)) || 1919 GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10 * 1024)) ||
1995 (GNUNET_OK != 1920 (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &uc->file_size)) ||
1996 GNUNET_BIO_read_int64 (rh, &uc->file_size)) || 1921 (GNUNET_OK != read_start_time (rh, &uc->start_time)) ||
1997 (GNUNET_OK !=
1998 read_start_time (rh, &uc->start_time)) ||
1999 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &state))) 1922 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &state)))
2000 { 1923 {
2001 GNUNET_break (0); 1924 GNUNET_break (0);
@@ -2034,17 +1957,16 @@ deserialize_unindex_file (void *cls, const char *filename)
2034 uc->top = GNUNET_FS_make_top (h, &GNUNET_FS_unindex_signal_suspend_, uc); 1957 uc->top = GNUNET_FS_make_top (h, &GNUNET_FS_unindex_signal_suspend_, uc);
2035 pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME; 1958 pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME;
2036 pi.value.unindex.specifics.resume.message = uc->emsg; 1959 pi.value.unindex.specifics.resume.message = uc->emsg;
2037 GNUNET_FS_unindex_make_status_ (&pi, 1960 GNUNET_FS_unindex_make_status_ (&pi, uc,
2038 uc, 1961 (uc->state ==
2039 (uc->state == UNINDEX_STATE_COMPLETE) 1962 UNINDEX_STATE_COMPLETE) ? uc->file_size : 0);
2040 ? uc->file_size : 0);
2041 switch (uc->state) 1963 switch (uc->state)
2042 { 1964 {
2043 case UNINDEX_STATE_HASHING: 1965 case UNINDEX_STATE_HASHING:
2044 uc->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, 1966 uc->fhc =
2045 uc->filename, 1967 GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, uc->filename,
2046 HASHING_BLOCKSIZE, 1968 HASHING_BLOCKSIZE,
2047 &GNUNET_FS_unindex_process_hash_, uc); 1969 &GNUNET_FS_unindex_process_hash_, uc);
2048 break; 1970 break;
2049 case UNINDEX_STATE_FS_NOTIFY: 1971 case UNINDEX_STATE_FS_NOTIFY:
2050 uc->state = UNINDEX_STATE_HASHING; 1972 uc->state = UNINDEX_STATE_HASHING;
@@ -2073,8 +1995,8 @@ cleanup:
2073 if ((rh != NULL) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))) 1995 if ((rh != NULL) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)))
2074 { 1996 {
2075 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1997 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2076 _("Failed to resume unindexing operation `%s': %s\n"), 1998 _("Failed to resume unindexing operation `%s': %s\n"), filename,
2077 filename, emsg); 1999 emsg);
2078 GNUNET_free (emsg); 2000 GNUNET_free (emsg);
2079 } 2001 }
2080 if (uc->serialization != NULL) 2002 if (uc->serialization != NULL)
@@ -2095,12 +2017,11 @@ cleanup:
2095 * @param search associated search 2017 * @param search associated search
2096 * @param serialization name under which the search was serialized 2018 * @param serialization name under which the search was serialized
2097 */ 2019 */
2098static void 2020static void deserialize_download (struct GNUNET_FS_Handle *h,
2099deserialize_download (struct GNUNET_FS_Handle *h, 2021 struct GNUNET_BIO_ReadHandle *rh,
2100 struct GNUNET_BIO_ReadHandle *rh, 2022 struct GNUNET_FS_DownloadContext *parent,
2101 struct GNUNET_FS_DownloadContext *parent, 2023 struct GNUNET_FS_SearchResult *search,
2102 struct GNUNET_FS_SearchResult *search, 2024 const char *serialization);
2103 const char *serialization);
2104 2025
2105 2026
2106/** 2027/**
@@ -2151,9 +2072,9 @@ deserialize_search_result (void *cls, const char *filename)
2151 if (ser != NULL) 2072 if (ser != NULL)
2152 { 2073 {
2153 remove_sync_file_in_dir (sc->h, 2074 remove_sync_file_in_dir (sc->h,
2154 (sc->psearch_result == NULL) 2075 (sc->psearch_result ==
2155 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH 2076 NULL) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH :
2156 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 2077 GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2157 sc->serialization, ser); 2078 sc->serialization, ser);
2158 GNUNET_free (ser); 2079 GNUNET_free (ser);
2159 } 2080 }
@@ -2165,15 +2086,12 @@ deserialize_search_result (void *cls, const char *filename)
2165 update_srch = NULL; 2086 update_srch = NULL;
2166 sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult)); 2087 sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult));
2167 sr->serialization = ser; 2088 sr->serialization = ser;
2168 if ((GNUNET_OK != 2089 if ((GNUNET_OK != GNUNET_BIO_read_string (rh, "result-uri", &uris, 10 * 1024))
2169 GNUNET_BIO_read_string (rh, "result-uri", &uris, 10 * 1024)) || 2090 || (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2170 (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) || 2091 (GNUNET_OK != GNUNET_BIO_read_string (rh, "download-lnk", &download, 16))
2171 (GNUNET_OK != 2092 || (GNUNET_OK !=
2172 GNUNET_BIO_read_string (rh, "download-lnk", &download, 16)) || 2093 GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) ||
2173 (GNUNET_OK != 2094 (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "result-meta", &sr->meta)) ||
2174 GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) ||
2175 (GNUNET_OK !=
2176 GNUNET_BIO_read_meta_data (rh, "result-meta", &sr->meta)) ||
2177 (GNUNET_OK != 2095 (GNUNET_OK !=
2178 GNUNET_BIO_read (rh, "result-key", &sr->key, sizeof (GNUNET_HashCode))) 2096 GNUNET_BIO_read (rh, "result-key", &sr->key, sizeof (GNUNET_HashCode)))
2179 || (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) || 2097 || (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) ||
@@ -2194,8 +2112,8 @@ deserialize_search_result (void *cls, const char *filename)
2194 if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg)) 2112 if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg))
2195 { 2113 {
2196 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2114 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2197 _("Failed to resume sub-download `%s': %s\n"), 2115 _("Failed to resume sub-download `%s': %s\n"), download,
2198 download, emsg); 2116 emsg);
2199 GNUNET_free (emsg); 2117 GNUNET_free (emsg);
2200 } 2118 }
2201 } 2119 }
@@ -2203,24 +2121,22 @@ deserialize_search_result (void *cls, const char *filename)
2203 } 2121 }
2204 if (update_srch != NULL) 2122 if (update_srch != NULL)
2205 { 2123 {
2206 drh = get_read_handle (sc->h, 2124 drh =
2207 GNUNET_FS_SYNC_PATH_CHILD_SEARCH, update_srch); 2125 get_read_handle (sc->h, GNUNET_FS_SYNC_PATH_CHILD_SEARCH, update_srch);
2208 if (drh != NULL) 2126 if (drh != NULL)
2209 { 2127 {
2210 deserialize_search (sc->h, drh, sr, update_srch); 2128 deserialize_search (sc->h, drh, sr, update_srch);
2211 if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg)) 2129 if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg))
2212 { 2130 {
2213 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2131 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2214 _("Failed to resume sub-search `%s': %s\n"), 2132 _("Failed to resume sub-search `%s': %s\n"), update_srch,
2215 update_srch, emsg); 2133 emsg);
2216 GNUNET_free (emsg); 2134 GNUNET_free (emsg);
2217 } 2135 }
2218 } 2136 }
2219 GNUNET_free (update_srch); 2137 GNUNET_free (update_srch);
2220 } 2138 }
2221 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, 2139 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, &sr->key, sr,
2222 &sr->key,
2223 sr,
2224 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 2140 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2225 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) 2141 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
2226 { 2142 {
@@ -2378,14 +2294,14 @@ free_search_context (struct GNUNET_FS_SearchContext *sc)
2378 if (sc->serialization != NULL) 2294 if (sc->serialization != NULL)
2379 { 2295 {
2380 GNUNET_FS_remove_sync_file_ (sc->h, 2296 GNUNET_FS_remove_sync_file_ (sc->h,
2381 (sc->psearch_result == NULL) 2297 (sc->psearch_result ==
2382 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH 2298 NULL) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH :
2383 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 2299 GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2384 sc->serialization); 2300 sc->serialization);
2385 GNUNET_FS_remove_sync_dir_ (sc->h, 2301 GNUNET_FS_remove_sync_dir_ (sc->h,
2386 (sc->psearch_result == NULL) 2302 (sc->psearch_result ==
2387 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH 2303 NULL) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH :
2388 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 2304 GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2389 sc->serialization); 2305 sc->serialization);
2390 } 2306 }
2391 GNUNET_free_non_null (sc->serialization); 2307 GNUNET_free_non_null (sc->serialization);
@@ -2394,8 +2310,8 @@ free_search_context (struct GNUNET_FS_SearchContext *sc)
2394 GNUNET_FS_uri_destroy (sc->uri); 2310 GNUNET_FS_uri_destroy (sc->uri);
2395 if (sc->master_result_map != NULL) 2311 if (sc->master_result_map != NULL)
2396 { 2312 {
2397 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, 2313 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, &free_result,
2398 &free_result, sc); 2314 sc);
2399 GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); 2315 GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
2400 } 2316 }
2401 GNUNET_free (sc); 2317 GNUNET_free (sc);
@@ -2507,10 +2423,9 @@ deserialize_download (struct GNUNET_FS_Handle *h,
2507 (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) || 2423 (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2508 ((GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) && 2424 ((GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) &&
2509 (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri))) || 2425 (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri))) ||
2510 (GNUNET_OK != 2426 (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta))
2511 GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta)) || 2427 || (GNUNET_OK !=
2512 (GNUNET_OK != 2428 GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10 * 1024)) ||
2513 GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10 * 1024)) ||
2514 (GNUNET_OK != 2429 (GNUNET_OK !=
2515 GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10 * 1024)) || 2430 GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10 * 1024)) ||
2516 (GNUNET_OK != 2431 (GNUNET_OK !=
@@ -2565,8 +2480,8 @@ deserialize_download (struct GNUNET_FS_Handle *h,
2565 } 2480 }
2566 if ((parent == NULL) && (search == NULL)) 2481 if ((parent == NULL) && (search == NULL))
2567 { 2482 {
2568 dc->top = GNUNET_FS_make_top (dc->h, 2483 dc->top =
2569 &GNUNET_FS_download_signal_suspend_, dc); 2484 GNUNET_FS_make_top (dc->h, &GNUNET_FS_download_signal_suspend_, dc);
2570 signal_download_resume (dc); 2485 signal_download_resume (dc);
2571 } 2486 }
2572 GNUNET_free (uris); 2487 GNUNET_free (uris);
@@ -2637,17 +2552,14 @@ deserialize_search (struct GNUNET_FS_Handle *h,
2637 } 2552 }
2638 sc->h = h; 2553 sc->h = h;
2639 sc->serialization = GNUNET_strdup (serialization); 2554 sc->serialization = GNUNET_strdup (serialization);
2640 if ((GNUNET_OK != 2555 if ((GNUNET_OK != GNUNET_BIO_read_string (rh, "search-uri", &uris, 10 * 1024))
2641 GNUNET_BIO_read_string (rh, "search-uri", &uris, 10 * 1024)) || 2556 || (NULL == (sc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2642 (NULL == (sc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
2643 ((GNUNET_YES != GNUNET_FS_uri_test_ksk (sc->uri)) && 2557 ((GNUNET_YES != GNUNET_FS_uri_test_ksk (sc->uri)) &&
2644 (GNUNET_YES != GNUNET_FS_uri_test_sks (sc->uri))) || 2558 (GNUNET_YES != GNUNET_FS_uri_test_sks (sc->uri))) ||
2645 (GNUNET_OK != 2559 (GNUNET_OK != read_start_time (rh, &sc->start_time)) ||
2646 read_start_time (rh, &sc->start_time)) ||
2647 (GNUNET_OK != 2560 (GNUNET_OK !=
2648 GNUNET_BIO_read_string (rh, "search-emsg", &sc->emsg, 10 * 1024)) || 2561 GNUNET_BIO_read_string (rh, "search-emsg", &sc->emsg, 10 * 1024)) ||
2649 (GNUNET_OK != 2562 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) ||
2650 GNUNET_BIO_read_int32 (rh, &options)) ||
2651 (GNUNET_OK != 2563 (GNUNET_OK !=
2652 GNUNET_BIO_read (rh, "search-pause", &in_pause, sizeof (in_pause))) || 2564 GNUNET_BIO_read (rh, "search-pause", &in_pause, sizeof (in_pause))) ||
2653 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sc->anonymity))) 2565 (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sc->anonymity)))
@@ -2658,9 +2570,10 @@ deserialize_search (struct GNUNET_FS_Handle *h,
2658 sc->options = (enum GNUNET_FS_SearchOptions) options; 2570 sc->options = (enum GNUNET_FS_SearchOptions) options;
2659 sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16); 2571 sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16);
2660 dn = get_serialization_file_name_in_dir (h, 2572 dn = get_serialization_file_name_in_dir (h,
2661 (sc->psearch_result == NULL) 2573 (sc->psearch_result ==
2662 ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH 2574 NULL) ?
2663 : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, 2575 GNUNET_FS_SYNC_PATH_MASTER_SEARCH :
2576 GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
2664 sc->serialization, ""); 2577 sc->serialization, "");
2665 if (dn != NULL) 2578 if (dn != NULL)
2666 { 2579 {
@@ -2775,8 +2688,7 @@ deserialize_download_file (void *cls, const char *filename)
2775 * @param h the 'struct GNUNET_FS_Handle*' 2688 * @param h the 'struct GNUNET_FS_Handle*'
2776 */ 2689 */
2777static void 2690static void
2778deserialization_master (const char *master_path, 2691deserialization_master (const char *master_path, GNUNET_FileNameCallback proc,
2779 GNUNET_FileNameCallback proc,
2780 struct GNUNET_FS_Handle *h) 2692 struct GNUNET_FS_Handle *h)
2781{ 2693{
2782 char *dn; 2694 char *dn;
@@ -2803,8 +2715,7 @@ deserialization_master (const char *master_path,
2803 */ 2715 */
2804struct GNUNET_FS_Handle * 2716struct GNUNET_FS_Handle *
2805GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg, 2717GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
2806 const char *client_name, 2718 const char *client_name, GNUNET_FS_ProgressCallback upcb,
2807 GNUNET_FS_ProgressCallback upcb,
2808 void *upcb_cls, enum GNUNET_FS_Flags flags, ...) 2719 void *upcb_cls, enum GNUNET_FS_Flags flags, ...)
2809{ 2720{
2810 struct GNUNET_FS_Handle *ret; 2721 struct GNUNET_FS_Handle *ret;
diff --git a/src/fs/fs_directory.c b/src/fs/fs_directory.c
index f22480d5f..61ed1586f 100644
--- a/src/fs/fs_directory.c
+++ b/src/fs/fs_directory.c
@@ -88,11 +88,9 @@ GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md)
88 GNUNET_free (mime); 88 GNUNET_free (mime);
89 return; 89 return;
90 } 90 }
91 GNUNET_CONTAINER_meta_data_insert (md, 91 GNUNET_CONTAINER_meta_data_insert (md, "<gnunet>",
92 "<gnunet>",
93 EXTRACTOR_METATYPE_MIMETYPE, 92 EXTRACTOR_METATYPE_MIMETYPE,
94 EXTRACTOR_METAFORMAT_UTF8, 93 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
95 "text/plain",
96 GNUNET_FS_DIRECTORY_MIME, 94 GNUNET_FS_DIRECTORY_MIME,
97 strlen (GNUNET_FS_DIRECTORY_MIME) + 1); 95 strlen (GNUNET_FS_DIRECTORY_MIME) + 1);
98} 96}
@@ -134,10 +132,8 @@ struct GetFullDataClosure
134 * @return 0 to continue extracting, 1 to abort 132 * @return 0 to continue extracting, 1 to abort
135 */ 133 */
136static int 134static int
137find_full_data (void *cls, 135find_full_data (void *cls, const char *plugin_name,
138 const char *plugin_name, 136 enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format,
139 enum EXTRACTOR_MetaType type,
140 enum EXTRACTOR_MetaFormat format,
141 const char *data_mime_type, const char *data, size_t data_len) 137 const char *data_mime_type, const char *data, size_t data_len)
142{ 138{
143 struct GetFullDataClosure *gfdc = cls; 139 struct GetFullDataClosure *gfdc = cls;
@@ -182,8 +178,7 @@ find_full_data (void *cls,
182 * GNUNET_SYSERR if 'data' does not represent a directory 178 * GNUNET_SYSERR if 'data' does not represent a directory
183 */ 179 */
184int 180int
185GNUNET_FS_directory_list_contents (size_t size, 181GNUNET_FS_directory_list_contents (size_t size, const void *data,
186 const void *data,
187 uint64_t offset, 182 uint64_t offset,
188 GNUNET_FS_DirectoryEntryProcessor dep, 183 GNUNET_FS_DirectoryEntryProcessor dep,
189 void *dep_cls) 184 void *dep_cls)
@@ -219,8 +214,7 @@ GNUNET_FS_directory_list_contents (size_t size,
219 _("MAGIC mismatch. This is not a GNUnet directory.\n")); 214 _("MAGIC mismatch. This is not a GNUnet directory.\n"));
220 return GNUNET_SYSERR; 215 return GNUNET_SYSERR;
221 } 216 }
222 md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[8 + 217 md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[8 + sizeof (uint32_t)],
223 sizeof (uint32_t)],
224 mdSize); 218 mdSize);
225 if (md == NULL) 219 if (md == NULL)
226 { 220 {
@@ -289,8 +283,9 @@ GNUNET_FS_directory_list_contents (size_t size,
289 return GNUNET_NO; /* malformed ! */ 283 return GNUNET_NO; /* malformed ! */
290 } 284 }
291 pos += mdSize; 285 pos += mdSize;
292 filename = GNUNET_CONTAINER_meta_data_get_by_type (md, 286 filename =
293 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); 287 GNUNET_CONTAINER_meta_data_get_by_type (md,
288 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
294 full_data.size = 0; 289 full_data.size = 0;
295 full_data.data = NULL; 290 full_data.data = NULL;
296 GNUNET_CONTAINER_meta_data_iterate (md, &find_full_data, &full_data); 291 GNUNET_CONTAINER_meta_data_iterate (md, &find_full_data, &full_data);
@@ -425,11 +420,10 @@ GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
425 if (fsize > 0) 420 if (fsize > 0)
426 { 421 {
427 meta = GNUNET_CONTAINER_meta_data_duplicate (md); 422 meta = GNUNET_CONTAINER_meta_data_duplicate (md);
428 GNUNET_CONTAINER_meta_data_insert (meta, 423 GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet>",
429 "<gnunet>",
430 EXTRACTOR_METATYPE_GNUNET_FULL_DATA, 424 EXTRACTOR_METATYPE_GNUNET_FULL_DATA,
431 EXTRACTOR_METAFORMAT_BINARY, 425 EXTRACTOR_METAFORMAT_BINARY, NULL, data,
432 NULL, data, fsize); 426 fsize);
433 mdxs = GNUNET_CONTAINER_meta_data_get_serialized_size (meta); 427 mdxs = GNUNET_CONTAINER_meta_data_get_serialized_size (meta);
434 if ((slen + sizeof (uint32_t) + mdxs - 1) / DBLOCK_SIZE == 428 if ((slen + sizeof (uint32_t) + mdxs - 1) / DBLOCK_SIZE ==
435 (slen + sizeof (uint32_t) + mds - 1) / DBLOCK_SIZE) 429 (slen + sizeof (uint32_t) + mds - 1) / DBLOCK_SIZE)
@@ -443,16 +437,15 @@ GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
443 437
444 if (mds > GNUNET_MAX_MALLOC_CHECKED / 2) 438 if (mds > GNUNET_MAX_MALLOC_CHECKED / 2)
445 mds = GNUNET_MAX_MALLOC_CHECKED / 2; 439 mds = GNUNET_MAX_MALLOC_CHECKED / 2;
446 e = GNUNET_malloc (sizeof (struct BuilderEntry) + 440 e = GNUNET_malloc (sizeof (struct BuilderEntry) + slen + mds +
447 slen + mds + sizeof (uint32_t)); 441 sizeof (uint32_t));
448 ser = (char *) &e[1]; 442 ser = (char *) &e[1];
449 memcpy (ser, uris, slen); 443 memcpy (ser, uris, slen);
450 GNUNET_free (uris); 444 GNUNET_free (uris);
451 sptr = &ser[slen + sizeof (uint32_t)]; 445 sptr = &ser[slen + sizeof (uint32_t)];
452 ret = GNUNET_CONTAINER_meta_data_serialize (meta_use, 446 ret =
453 &sptr, 447 GNUNET_CONTAINER_meta_data_serialize (meta_use, &sptr, mds,
454 mds, 448 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
455 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
456 if (NULL != meta) 449 if (NULL != meta)
457 GNUNET_CONTAINER_meta_data_destroy (meta); 450 GNUNET_CONTAINER_meta_data_destroy (meta);
458 if (ret == -1) 451 if (ret == -1)
@@ -495,8 +488,8 @@ do_align (size_t start_position, size_t end_position)
495 * @param perm the permutation of the blocks (updated) 488 * @param perm the permutation of the blocks (updated)
496 */ 489 */
497static void 490static void
498block_align (size_t start, 491block_align (size_t start, unsigned int count, const size_t * sizes,
499 unsigned int count, const size_t * sizes, unsigned int *perm) 492 unsigned int *perm)
500{ 493{
501 unsigned int i; 494 unsigned int i;
502 unsigned int j; 495 unsigned int j;
@@ -625,10 +618,10 @@ GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
625 off = strlen (GNUNET_DIRECTORY_MAGIC); 618 off = strlen (GNUNET_DIRECTORY_MAGIC);
626 619
627 sptr = &data[off + sizeof (uint32_t)]; 620 sptr = &data[off + sizeof (uint32_t)];
628 ret = GNUNET_CONTAINER_meta_data_serialize (bld->meta, 621 ret =
629 &sptr, 622 GNUNET_CONTAINER_meta_data_serialize (bld->meta, &sptr,
630 size - off - sizeof (uint32_t), 623 size - off - sizeof (uint32_t),
631 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL); 624 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL);
632 GNUNET_assert (ret != -1); 625 GNUNET_assert (ret != -1);
633 big = htonl (ret); 626 big = htonl (ret);
634 memcpy (&data[off], &big, sizeof (uint32_t)); 627 memcpy (&data[off], &big, sizeof (uint32_t));
diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c
index 6b72b4e56..a3c5b9b62 100644
--- a/src/fs/fs_download.c
+++ b/src/fs/fs_download.c
@@ -111,19 +111,19 @@ GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
111{ 111{
112 pi->value.download.dc = dc; 112 pi->value.download.dc = dc;
113 pi->value.download.cctx = dc->client_info; 113 pi->value.download.cctx = dc->client_info;
114 pi->value.download.pctx 114 pi->value.download.pctx =
115 = (dc->parent == NULL) ? NULL : dc->parent->client_info; 115 (dc->parent == NULL) ? NULL : dc->parent->client_info;
116 pi->value.download.sctx 116 pi->value.download.sctx =
117 = (dc->search == NULL) ? NULL : dc->search->client_info; 117 (dc->search == NULL) ? NULL : dc->search->client_info;
118 pi->value.download.uri = dc->uri; 118 pi->value.download.uri = dc->uri;
119 pi->value.download.filename = dc->filename; 119 pi->value.download.filename = dc->filename;
120 pi->value.download.size = dc->length; 120 pi->value.download.size = dc->length;
121 pi->value.download.duration 121 pi->value.download.duration =
122 = GNUNET_TIME_absolute_get_duration (dc->start_time); 122 GNUNET_TIME_absolute_get_duration (dc->start_time);
123 pi->value.download.completed = dc->completed; 123 pi->value.download.completed = dc->completed;
124 pi->value.download.anonymity = dc->anonymity; 124 pi->value.download.anonymity = dc->anonymity;
125 pi->value.download.eta 125 pi->value.download.eta =
126 = GNUNET_TIME_calculate_eta (dc->start_time, dc->completed, dc->length); 126 GNUNET_TIME_calculate_eta (dc->start_time, dc->completed, dc->length);
127 pi->value.download.is_active = (dc->client == NULL) ? GNUNET_NO : GNUNET_YES; 127 pi->value.download.is_active = (dc->client == NULL) ? GNUNET_NO : GNUNET_YES;
128 if (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) 128 if (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE))
129 dc->client_info = dc->h->upcb (dc->h->upcb_cls, pi); 129 dc->client_info = dc->h->upcb (dc->h->upcb_cls, pi);
@@ -194,9 +194,8 @@ struct ProcessResultClosure
194 * @param value value in the hash map (a 'struct DownloadRequest') 194 * @param value value in the hash map (a 'struct DownloadRequest')
195 * @return GNUNET_YES (we should continue to iterate); unless serious error 195 * @return GNUNET_YES (we should continue to iterate); unless serious error
196 */ 196 */
197static int 197static int process_result_with_request (void *cls, const GNUNET_HashCode * key,
198process_result_with_request (void *cls, 198 void *value);
199 const GNUNET_HashCode * key, void *value);
200 199
201 200
202/** 201/**
@@ -215,8 +214,8 @@ process_result_with_request (void *cls,
215static int 214static int
216encrypt_existing_match (struct GNUNET_FS_DownloadContext *dc, 215encrypt_existing_match (struct GNUNET_FS_DownloadContext *dc,
217 const struct ContentHashKey *chk, 216 const struct ContentHashKey *chk,
218 struct DownloadRequest *dr, 217 struct DownloadRequest *dr, const char *block,
219 const char *block, size_t len, int do_store) 218 size_t len, int do_store)
220{ 219{
221 struct ProcessResultClosure prc; 220 struct ProcessResultClosure prc;
222 char enc[len]; 221 char enc[len];
@@ -245,8 +244,9 @@ encrypt_existing_match (struct GNUNET_FS_DownloadContext *dc,
245 prc.dc = dc; 244 prc.dc = dc;
246 prc.data = enc; 245 prc.data = enc;
247 prc.size = len; 246 prc.size = len;
248 prc.type = (0 == dr->depth) 247 prc.type =
249 ? GNUNET_BLOCK_TYPE_FS_DBLOCK : GNUNET_BLOCK_TYPE_FS_IBLOCK; 248 (0 ==
249 dr->depth) ? GNUNET_BLOCK_TYPE_FS_DBLOCK : GNUNET_BLOCK_TYPE_FS_IBLOCK;
250 prc.query = chk->query; 250 prc.query = chk->query;
251 prc.do_store = do_store; 251 prc.do_store = do_store;
252 process_result_with_request (&prc, &chk->key, dr); 252 process_result_with_request (&prc, &chk->key, dr);
@@ -275,12 +275,10 @@ static void try_reconnect (struct GNUNET_FS_DownloadContext *dc);
275 * @param length number of bytes in data 275 * @param length number of bytes in data
276 * @param data contents of the file (or NULL if they were not inlined) 276 * @param data contents of the file (or NULL if they were not inlined)
277 */ 277 */
278static void 278static void trigger_recursive_download (void *cls, const char *filename,
279trigger_recursive_download (void *cls, 279 const struct GNUNET_FS_Uri *uri,
280 const char *filename, 280 const struct GNUNET_CONTAINER_MetaData
281 const struct GNUNET_FS_Uri *uri, 281 *meta, size_t length, const void *data);
282 const struct GNUNET_CONTAINER_MetaData *meta,
283 size_t length, const void *data);
284 282
285 283
286/** 284/**
@@ -309,14 +307,14 @@ full_recursive_download (struct GNUNET_FS_DownloadContext *dc)
309 } 307 }
310 if (dc->filename != NULL) 308 if (dc->filename != NULL)
311 { 309 {
312 h = GNUNET_DISK_file_open (dc->filename, 310 h = GNUNET_DISK_file_open (dc->filename, GNUNET_DISK_OPEN_READ,
313 GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE); 311 GNUNET_DISK_PERM_NONE);
314 } 312 }
315 else 313 else
316 { 314 {
317 GNUNET_assert (dc->temp_filename != NULL); 315 GNUNET_assert (dc->temp_filename != NULL);
318 h = GNUNET_DISK_file_open (dc->temp_filename, 316 h = GNUNET_DISK_file_open (dc->temp_filename, GNUNET_DISK_OPEN_READ,
319 GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE); 317 GNUNET_DISK_PERM_NONE);
320 } 318 }
321 if (h == NULL) 319 if (h == NULL)
322 return; /* oops */ 320 return; /* oops */
@@ -328,17 +326,16 @@ full_recursive_download (struct GNUNET_FS_DownloadContext *dc)
328 } 326 }
329 else 327 else
330 { 328 {
331 GNUNET_FS_directory_list_contents (size, 329 GNUNET_FS_directory_list_contents (size, data, 0,
332 data, 330 &trigger_recursive_download, dc);
333 0, &trigger_recursive_download, dc);
334 GNUNET_DISK_file_unmap (m); 331 GNUNET_DISK_file_unmap (m);
335 } 332 }
336 GNUNET_DISK_file_close (h); 333 GNUNET_DISK_file_close (h);
337 if (dc->filename == NULL) 334 if (dc->filename == NULL)
338 { 335 {
339 if (0 != UNLINK (dc->temp_filename)) 336 if (0 != UNLINK (dc->temp_filename))
340 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 337 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink",
341 "unlink", dc->temp_filename); 338 dc->temp_filename);
342 GNUNET_free (dc->temp_filename); 339 GNUNET_free (dc->temp_filename);
343 dc->temp_filename = NULL; 340 dc->temp_filename = NULL;
344 } 341 }
@@ -483,8 +480,8 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc,
483 if (fh == NULL) 480 if (fh == NULL)
484 { 481 {
485 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", fn); 482 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", fn);
486 GNUNET_asprintf (&dc->emsg, 483 GNUNET_asprintf (&dc->emsg, _("Failed to open file `%s' for writing"),
487 _("Failed to open file `%s' for writing"), fn); 484 fn);
488 GNUNET_DISK_file_close (fh); 485 GNUNET_DISK_file_close (fh);
489 dr->state = BRS_ERROR; 486 dr->state = BRS_ERROR;
490 pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; 487 pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR;
@@ -495,8 +492,8 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc,
495 if (data_len != GNUNET_DISK_file_write (fh, odata, odata_len)) 492 if (data_len != GNUNET_DISK_file_write (fh, odata, odata_len))
496 { 493 {
497 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn); 494 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn);
498 GNUNET_asprintf (&dc->emsg, 495 GNUNET_asprintf (&dc->emsg, _("Failed to open file `%s' for writing"),
499 _("Failed to open file `%s' for writing"), fn); 496 fn);
500 GNUNET_DISK_file_close (fh); 497 GNUNET_DISK_file_close (fh);
501 dr->state = BRS_ERROR; 498 dr->state = BRS_ERROR;
502 pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; 499 pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR;
@@ -516,10 +513,11 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc,
516 pi.value.download.specifics.progress.depth = 0; 513 pi.value.download.specifics.progress.depth = 0;
517 GNUNET_FS_download_make_status_ (&pi, dc); 514 GNUNET_FS_download_make_status_ (&pi, dc);
518 if ((NULL != dc->filename) && 515 if ((NULL != dc->filename) &&
519 (0 != truncate (dc->filename, 516 (0 !=
520 GNUNET_ntohll (dc->uri->data.chk.file_length)))) 517 truncate (dc->filename,
521 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 518 GNUNET_ntohll (dc->uri->data.chk.file_length))))
522 "truncate", dc->filename); 519 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "truncate",
520 dc->filename);
523 check_completed (dc); 521 check_completed (dc);
524 break; 522 break;
525 default: 523 default:
@@ -549,10 +547,8 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc,
549 * @return 0 to continue extracting, 1 to abort 547 * @return 0 to continue extracting, 1 to abort
550 */ 548 */
551static int 549static int
552match_full_data (void *cls, 550match_full_data (void *cls, const char *plugin_name,
553 const char *plugin_name, 551 enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format,
554 enum EXTRACTOR_MetaType type,
555 enum EXTRACTOR_MetaFormat format,
556 const char *data_mime_type, const char *data, size_t data_len) 552 const char *data_mime_type, const char *data, size_t data_len)
557{ 553{
558 struct GNUNET_FS_DownloadContext *dc = cls; 554 struct GNUNET_FS_DownloadContext *dc = cls;
@@ -560,8 +556,8 @@ match_full_data (void *cls,
560 if (type != EXTRACTOR_METATYPE_GNUNET_FULL_DATA) 556 if (type != EXTRACTOR_METATYPE_GNUNET_FULL_DATA)
561 return 0; 557 return 0;
562#if DEBUG_DOWNLOAD 558#if DEBUG_DOWNLOAD
563 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 559 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u bytes of FD!\n",
564 "Found %u bytes of FD!\n", (unsigned int) data_len); 560 (unsigned int) data_len);
565#endif 561#endif
566 if (GNUNET_FS_uri_chk_get_file_size (dc->uri) != data_len) 562 if (GNUNET_FS_uri_chk_get_file_size (dc->uri) != data_len)
567 { 563 {
@@ -729,28 +725,26 @@ schedule_block_download (struct GNUNET_FS_DownloadContext *dc,
729#if DEBUG_DOWNLOAD 725#if DEBUG_DOWNLOAD
730 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 726 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
731 "Scheduling download at offset %llu and depth %u for `%s'\n", 727 "Scheduling download at offset %llu and depth %u for `%s'\n",
732 (unsigned long long) dr->offset, 728 (unsigned long long) dr->offset, dr->depth,
733 dr->depth, GNUNET_h2s (&dr->chk.query)); 729 GNUNET_h2s (&dr->chk.query));
734#endif 730#endif
735 if (GNUNET_NO != 731 if (GNUNET_NO !=
736 GNUNET_CONTAINER_multihashmap_contains_value (dc->active, 732 GNUNET_CONTAINER_multihashmap_contains_value (dc->active, &dr->chk.query,
737 &dr->chk.query, dr)) 733 dr))
738 return; /* already active */ 734 return; /* already active */
739 GNUNET_CONTAINER_multihashmap_put (dc->active, 735 GNUNET_CONTAINER_multihashmap_put (dc->active, &dr->chk.query, dr,
740 &dr->chk.query,
741 dr,
742 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 736 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
743 if (dc->client == NULL) 737 if (dc->client == NULL)
744 return; /* download not active */ 738 return; /* download not active */
745 GNUNET_CONTAINER_DLL_insert (dc->pending_head, dc->pending_tail, dr); 739 GNUNET_CONTAINER_DLL_insert (dc->pending_head, dc->pending_tail, dr);
746 dr->is_pending = GNUNET_YES; 740 dr->is_pending = GNUNET_YES;
747 if (NULL == dc->th) 741 if (NULL == dc->th)
748 dc->th = GNUNET_CLIENT_notify_transmit_ready (dc->client, 742 dc->th =
749 sizeof (struct SearchMessage), 743 GNUNET_CLIENT_notify_transmit_ready (dc->client,
750 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 744 sizeof (struct SearchMessage),
751 GNUNET_NO, 745 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
752 &transmit_download_request, 746 GNUNET_NO,
753 dc); 747 &transmit_download_request, dc);
754} 748}
755 749
756 750
@@ -768,8 +762,7 @@ schedule_block_download (struct GNUNET_FS_DownloadContext *dc,
768 * @param data contents of the file (or NULL if they were not inlined) 762 * @param data contents of the file (or NULL if they were not inlined)
769 */ 763 */
770static void 764static void
771trigger_recursive_download (void *cls, 765trigger_recursive_download (void *cls, const char *filename,
772 const char *filename,
773 const struct GNUNET_FS_Uri *uri, 766 const struct GNUNET_FS_Uri *uri,
774 const struct GNUNET_CONTAINER_MetaData *meta, 767 const struct GNUNET_CONTAINER_MetaData *meta,
775 size_t length, const void *data) 768 size_t length, const void *data)
@@ -790,8 +783,7 @@ trigger_recursive_download (void *cls,
790 cpos = dc->child_head; 783 cpos = dc->child_head;
791 while (cpos != NULL) 784 while (cpos != NULL)
792 { 785 {
793 if ((GNUNET_FS_uri_test_equal (uri, 786 if ((GNUNET_FS_uri_test_equal (uri, cpos->uri)) ||
794 cpos->uri)) ||
795 ((filename != NULL) && (0 == strcmp (cpos->filename, filename)))) 787 ((filename != NULL) && (0 == strcmp (cpos->filename, filename))))
796 break; 788 break;
797 cpos = cpos->next; 789 cpos = cpos->next;
@@ -812,8 +804,8 @@ trigger_recursive_download (void *cls,
812 { 804 {
813 ext = fn; 805 ext = fn;
814 us = GNUNET_FS_uri_to_string (uri); 806 us = GNUNET_FS_uri_to_string (uri);
815 GNUNET_asprintf (&fn, 807 GNUNET_asprintf (&fn, "%s%s", &us[strlen (GNUNET_FS_URI_CHK_PREFIX)],
816 "%s%s", &us[strlen (GNUNET_FS_URI_CHK_PREFIX)], ext); 808 ext);
817 GNUNET_free (ext); 809 GNUNET_free (ext);
818 GNUNET_free (us); 810 GNUNET_free (us);
819 } 811 }
@@ -858,9 +850,8 @@ trigger_recursive_download (void *cls,
858 strstr (filename + strlen (filename) - 850 strstr (filename + strlen (filename) -
859 strlen (GNUNET_FS_DIRECTORY_EXT), GNUNET_FS_DIRECTORY_EXT)))) 851 strlen (GNUNET_FS_DIRECTORY_EXT), GNUNET_FS_DIRECTORY_EXT))))
860 { 852 {
861 GNUNET_asprintf (&full_name, 853 GNUNET_asprintf (&full_name, "%s%s%s%s", dn, DIR_SEPARATOR_STR, sfn,
862 "%s%s%s%s", 854 GNUNET_FS_DIRECTORY_EXT);
863 dn, DIR_SEPARATOR_STR, sfn, GNUNET_FS_DIRECTORY_EXT);
864 } 855 }
865 else 856 else
866 { 857 {
@@ -889,11 +880,7 @@ trigger_recursive_download (void *cls,
889 (unsigned int) 880 (unsigned int)
890 GNUNET_CONTAINER_meta_data_get_serialized_size (meta)); 881 GNUNET_CONTAINER_meta_data_get_serialized_size (meta));
891#endif 882#endif
892 GNUNET_FS_download_start (dc->h, 883 GNUNET_FS_download_start (dc->h, uri, meta, full_name, temp_name, 0,
893 uri,
894 meta,
895 full_name, temp_name,
896 0,
897 GNUNET_FS_uri_chk_get_file_size (uri), 884 GNUNET_FS_uri_chk_get_file_size (uri),
898 dc->anonymity, dc->options, NULL, dc); 885 dc->anonymity, dc->options, NULL, dc);
899 GNUNET_free_non_null (full_name); 886 GNUNET_free_non_null (full_name);
@@ -931,8 +918,8 @@ GNUNET_FS_free_download_request_ (struct DownloadRequest *dr)
931 * @return GNUNET_YES (we should continue to iterate); unless serious error 918 * @return GNUNET_YES (we should continue to iterate); unless serious error
932 */ 919 */
933static int 920static int
934process_result_with_request (void *cls, 921process_result_with_request (void *cls, const GNUNET_HashCode * key,
935 const GNUNET_HashCode * key, void *value) 922 void *value)
936{ 923{
937 struct ProcessResultClosure *prc = cls; 924 struct ProcessResultClosure *prc = cls;
938 struct DownloadRequest *dr = value; 925 struct DownloadRequest *dr = value;
@@ -952,11 +939,9 @@ process_result_with_request (void *cls,
952#if DEBUG_DOWNLOAD 939#if DEBUG_DOWNLOAD
953 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 940 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
954 "Received block `%s' matching pending request at depth %u and offset %llu/%llu\n", 941 "Received block `%s' matching pending request at depth %u and offset %llu/%llu\n",
955 GNUNET_h2s (key), 942 GNUNET_h2s (key), dr->depth, (unsigned long long) dr->offset,
956 dr->depth, 943 (unsigned long long) GNUNET_ntohll (dc->uri->data.chk.
957 (unsigned long long) dr->offset, 944 file_length));
958 (unsigned long long) GNUNET_ntohll (dc->uri->data.
959 chk.file_length));
960 945
961#endif 946#endif
962 bs = GNUNET_FS_tree_calculate_block_size (GNUNET_ntohll 947 bs = GNUNET_FS_tree_calculate_block_size (GNUNET_ntohll
@@ -968,8 +953,8 @@ process_result_with_request (void *cls,
968 _ 953 _
969 ("Internal error or bogus download URI (expected %u bytes at depth %u and offset %llu/%llu, got %u bytes)\n"), 954 ("Internal error or bogus download URI (expected %u bytes at depth %u and offset %llu/%llu, got %u bytes)\n"),
970 bs, dr->depth, (unsigned long long) dr->offset, 955 bs, dr->depth, (unsigned long long) dr->offset,
971 (unsigned long long) GNUNET_ntohll (dc->uri->data. 956 (unsigned long long) GNUNET_ntohll (dc->uri->data.chk.
972 chk.file_length), 957 file_length),
973 prc->size); 958 prc->size);
974 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s", dc->emsg); 959 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s", dc->emsg);
975 while (dr->parent != NULL) 960 while (dr->parent != NULL)
@@ -996,18 +981,17 @@ process_result_with_request (void *cls,
996 dc->emsg = GNUNET_strdup (_("internal error decrypting content")); 981 dc->emsg = GNUNET_strdup (_("internal error decrypting content"));
997 goto signal_error; 982 goto signal_error;
998 } 983 }
999 off = compute_disk_offset (GNUNET_ntohll (dc->uri->data.chk.file_length), 984 off =
1000 dr->offset, dr->depth); 985 compute_disk_offset (GNUNET_ntohll (dc->uri->data.chk.file_length),
986 dr->offset, dr->depth);
1001 /* save to disk */ 987 /* save to disk */
1002 if ((GNUNET_YES == prc->do_store) && 988 if ((GNUNET_YES == prc->do_store) &&
1003 ((dc->filename != NULL) || 989 ((dc->filename != NULL) || (is_recursive_download (dc))) &&
1004 (is_recursive_download (dc))) &&
1005 ((dr->depth == dc->treedepth) || 990 ((dr->depth == dc->treedepth) ||
1006 (0 == (dc->options & GNUNET_FS_DOWNLOAD_NO_TEMPORARIES)))) 991 (0 == (dc->options & GNUNET_FS_DOWNLOAD_NO_TEMPORARIES))))
1007 { 992 {
1008 fh = GNUNET_DISK_file_open (dc->filename != NULL 993 fh = GNUNET_DISK_file_open (dc->filename !=
1009 ? dc->filename 994 NULL ? dc->filename : dc->temp_filename,
1010 : dc->temp_filename,
1011 GNUNET_DISK_OPEN_READWRITE | 995 GNUNET_DISK_OPEN_READWRITE |
1012 GNUNET_DISK_OPEN_CREATE, 996 GNUNET_DISK_OPEN_CREATE,
1013 GNUNET_DISK_PERM_USER_READ | 997 GNUNET_DISK_PERM_USER_READ |
@@ -1030,8 +1014,8 @@ process_result_with_request (void *cls,
1030 { 1014 {
1031 GNUNET_asprintf (&dc->emsg, 1015 GNUNET_asprintf (&dc->emsg,
1032 _("Failed to seek to offset %llu in file `%s': %s\n"), 1016 _("Failed to seek to offset %llu in file `%s': %s\n"),
1033 (unsigned long long) off, 1017 (unsigned long long) off, dc->filename,
1034 dc->filename, STRERROR (errno)); 1018 STRERROR (errno));
1035 goto signal_error; 1019 goto signal_error;
1036 } 1020 }
1037 if (prc->size != GNUNET_DISK_file_write (fh, pt, prc->size)) 1021 if (prc->size != GNUNET_DISK_file_write (fh, pt, prc->size))
@@ -1072,9 +1056,8 @@ process_result_with_request (void *cls,
1072 * says it is a directory or if no meta data is given AND filename 1056 * says it is a directory or if no meta data is given AND filename
1073 * ends in '.gnd' (top-level case) */ 1057 * ends in '.gnd' (top-level case) */
1074 if (is_recursive_download (dc)) 1058 if (is_recursive_download (dc))
1075 GNUNET_FS_directory_list_contents (prc->size, 1059 GNUNET_FS_directory_list_contents (prc->size, pt, off,
1076 pt, 1060 &trigger_recursive_download, dc);
1077 off, &trigger_recursive_download, dc);
1078 1061
1079 } 1062 }
1080 dr->state = BRS_DOWNLOAD_DOWN; 1063 dr->state = BRS_DOWNLOAD_DOWN;
@@ -1094,16 +1077,17 @@ process_result_with_request (void *cls,
1094#if DEBUG_DOWNLOAD 1077#if DEBUG_DOWNLOAD
1095 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1078 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1096 "Download completed, truncating file to desired length %llu\n", 1079 "Download completed, truncating file to desired length %llu\n",
1097 (unsigned long long) GNUNET_ntohll (dc->uri->data. 1080 (unsigned long long) GNUNET_ntohll (dc->uri->data.chk.
1098 chk.file_length)); 1081 file_length));
1099#endif 1082#endif
1100 /* truncate file to size (since we store IBlocks at the end) */ 1083 /* truncate file to size (since we store IBlocks at the end) */
1101 if (dc->filename != NULL) 1084 if (dc->filename != NULL)
1102 { 1085 {
1103 if (0 != truncate (dc->filename, 1086 if (0 !=
1104 GNUNET_ntohll (dc->uri->data.chk.file_length))) 1087 truncate (dc->filename,
1105 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 1088 GNUNET_ntohll (dc->uri->data.chk.file_length)))
1106 "truncate", dc->filename); 1089 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "truncate",
1090 dc->filename);
1107 } 1091 }
1108 GNUNET_assert (dr->depth == 0); 1092 GNUNET_assert (dr->depth == 0);
1109 check_completed (dc); 1093 check_completed (dc);
@@ -1212,8 +1196,7 @@ process_result (struct GNUNET_FS_DownloadContext *dc,
1212 "Received result for query `%s' from `%s'-service\n", 1196 "Received result for query `%s' from `%s'-service\n",
1213 GNUNET_h2s (&prc.query), "FS"); 1197 GNUNET_h2s (&prc.query), "FS");
1214#endif 1198#endif
1215 GNUNET_CONTAINER_multihashmap_get_multiple (dc->active, 1199 GNUNET_CONTAINER_multihashmap_get_multiple (dc->active, &prc.query,
1216 &prc.query,
1217 &process_result_with_request, 1200 &process_result_with_request,
1218 &prc); 1201 &prc);
1219} 1202}
@@ -1233,8 +1216,7 @@ receive_results (void *cls, const struct GNUNET_MessageHeader *msg)
1233 const struct PutMessage *cm; 1216 const struct PutMessage *cm;
1234 uint16_t msize; 1217 uint16_t msize;
1235 1218
1236 if ((NULL == msg) || 1219 if ((NULL == msg) || (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_PUT) ||
1237 (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_PUT) ||
1238 (sizeof (struct PutMessage) > ntohs (msg->size))) 1220 (sizeof (struct PutMessage) > ntohs (msg->size)))
1239 { 1221 {
1240 GNUNET_break (msg == NULL); 1222 GNUNET_break (msg == NULL);
@@ -1243,13 +1225,13 @@ receive_results (void *cls, const struct GNUNET_MessageHeader *msg)
1243 } 1225 }
1244 msize = ntohs (msg->size); 1226 msize = ntohs (msg->size);
1245 cm = (const struct PutMessage *) msg; 1227 cm = (const struct PutMessage *) msg;
1246 process_result (dc, 1228 process_result (dc, ntohl (cm->type), &cm[1],
1247 ntohl (cm->type), &cm[1], msize - sizeof (struct PutMessage)); 1229 msize - sizeof (struct PutMessage));
1248 if (dc->client == NULL) 1230 if (dc->client == NULL)
1249 return; /* fatal error */ 1231 return; /* fatal error */
1250 /* continue receiving */ 1232 /* continue receiving */
1251 GNUNET_CLIENT_receive (dc->client, 1233 GNUNET_CLIENT_receive (dc->client, &receive_results, dc,
1252 &receive_results, dc, GNUNET_TIME_UNIT_FOREVER_REL); 1234 GNUNET_TIME_UNIT_FOREVER_REL);
1253} 1235}
1254 1236
1255 1237
@@ -1315,19 +1297,19 @@ transmit_download_request (void *cls, size_t size, void *buf)
1315 } 1297 }
1316 if (dc->pending_head != NULL) 1298 if (dc->pending_head != NULL)
1317 { 1299 {
1318 dc->th = GNUNET_CLIENT_notify_transmit_ready (dc->client, 1300 dc->th =
1319 sizeof (struct SearchMessage), 1301 GNUNET_CLIENT_notify_transmit_ready (dc->client,
1320 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 1302 sizeof (struct SearchMessage),
1321 GNUNET_NO, 1303 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1322 &transmit_download_request, 1304 GNUNET_NO,
1323 dc); 1305 &transmit_download_request, dc);
1324 GNUNET_assert (dc->th != NULL); 1306 GNUNET_assert (dc->th != NULL);
1325 } 1307 }
1326 if (GNUNET_NO == dc->in_receive) 1308 if (GNUNET_NO == dc->in_receive)
1327 { 1309 {
1328 dc->in_receive = GNUNET_YES; 1310 dc->in_receive = GNUNET_YES;
1329 GNUNET_CLIENT_receive (dc->client, 1311 GNUNET_CLIENT_receive (dc->client, &receive_results, dc,
1330 &receive_results, dc, GNUNET_TIME_UNIT_FOREVER_REL); 1312 GNUNET_TIME_UNIT_FOREVER_REL);
1331 } 1313 }
1332 return msize; 1314 return msize;
1333} 1315}
@@ -1357,12 +1339,12 @@ do_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1357 dc->client = client; 1339 dc->client = client;
1358 if (dc->pending_head != NULL) 1340 if (dc->pending_head != NULL)
1359 { 1341 {
1360 dc->th = GNUNET_CLIENT_notify_transmit_ready (client, 1342 dc->th =
1361 sizeof (struct SearchMessage), 1343 GNUNET_CLIENT_notify_transmit_ready (client,
1362 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 1344 sizeof (struct SearchMessage),
1363 GNUNET_NO, 1345 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1364 &transmit_download_request, 1346 GNUNET_NO,
1365 dc); 1347 &transmit_download_request, dc);
1366 GNUNET_assert (dc->th != NULL); 1348 GNUNET_assert (dc->th != NULL);
1367 } 1349 }
1368} 1350}
@@ -1423,9 +1405,9 @@ try_reconnect (struct GNUNET_FS_DownloadContext *dc)
1423#if DEBUG_DOWNLOAD 1405#if DEBUG_DOWNLOAD
1424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Will try to reconnect in 1s\n"); 1406 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Will try to reconnect in 1s\n");
1425#endif 1407#endif
1426 dc->task 1408 dc->task =
1427 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 1409 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_reconnect,
1428 &do_reconnect, dc); 1410 dc);
1429} 1411}
1430 1412
1431 1413
@@ -1459,12 +1441,12 @@ activate_fs_download (void *cls, struct GNUNET_CLIENT_Connection *client)
1459#endif 1441#endif
1460 if (dc->pending_head != NULL) 1442 if (dc->pending_head != NULL)
1461 { 1443 {
1462 dc->th = GNUNET_CLIENT_notify_transmit_ready (dc->client, 1444 dc->th =
1463 sizeof (struct SearchMessage), 1445 GNUNET_CLIENT_notify_transmit_ready (dc->client,
1464 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 1446 sizeof (struct SearchMessage),
1465 GNUNET_NO, 1447 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1466 &transmit_download_request, 1448 GNUNET_NO,
1467 dc); 1449 &transmit_download_request, dc);
1468 GNUNET_assert (dc->th != NULL); 1450 GNUNET_assert (dc->th != NULL);
1469 } 1451 }
1470} 1452}
@@ -1521,10 +1503,9 @@ deactivate_fs_download (void *cls)
1521 * the specified depth 1503 * the specified depth
1522 */ 1504 */
1523static struct DownloadRequest * 1505static struct DownloadRequest *
1524create_download_request (struct DownloadRequest *parent, 1506create_download_request (struct DownloadRequest *parent, unsigned int depth,
1525 unsigned int depth, 1507 uint64_t dr_offset, uint64_t file_start_offset,
1526 uint64_t dr_offset, 1508 uint64_t desired_length)
1527 uint64_t file_start_offset, uint64_t desired_length)
1528{ 1509{
1529 struct DownloadRequest *dr; 1510 struct DownloadRequest *dr;
1530 unsigned int i; 1511 unsigned int i;
@@ -1561,15 +1542,13 @@ create_download_request (struct DownloadRequest *parent,
1561 /* why else would we have gotten here to begin with? (that'd be a bad logic error) */ 1542 /* why else would we have gotten here to begin with? (that'd be a bad logic error) */
1562 GNUNET_assert (dr->num_children > 0); 1543 GNUNET_assert (dr->num_children > 0);
1563 1544
1564 dr->children = GNUNET_malloc (dr->num_children * 1545 dr->children =
1565 sizeof (struct DownloadRequest *)); 1546 GNUNET_malloc (dr->num_children * sizeof (struct DownloadRequest *));
1566 for (i = 0; i < dr->num_children; i++) 1547 for (i = 0; i < dr->num_children; i++)
1567 dr->children[i] = create_download_request (dr, 1548 dr->children[i] =
1568 depth - 1, 1549 create_download_request (dr, depth - 1,
1569 dr_offset + 1550 dr_offset + i * child_block_size,
1570 i * child_block_size, 1551 file_start_offset, desired_length);
1571 file_start_offset,
1572 desired_length);
1573 } 1552 }
1574 return dr; 1553 return dr;
1575} 1554}
@@ -1643,11 +1622,8 @@ get_next_block (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1643 * @param block_size size of block (in bytes) 1622 * @param block_size size of block (in bytes)
1644 */ 1623 */
1645static void 1624static void
1646reconstruct_cb (void *cls, 1625reconstruct_cb (void *cls, const struct ContentHashKey *chk, uint64_t offset,
1647 const struct ContentHashKey *chk, 1626 unsigned int depth, enum GNUNET_BLOCK_Type type,
1648 uint64_t offset,
1649 unsigned int depth,
1650 enum GNUNET_BLOCK_Type type,
1651 const void *block, uint16_t block_size) 1627 const void *block, uint16_t block_size)
1652{ 1628{
1653 struct GNUNET_FS_DownloadContext *dc = cls; 1629 struct GNUNET_FS_DownloadContext *dc = cls;
@@ -1781,7 +1757,8 @@ GNUNET_FS_download_start_task_ (void *cls,
1781 GNUNET_DISK_OPEN_READWRITE | 1757 GNUNET_DISK_OPEN_READWRITE |
1782 GNUNET_DISK_OPEN_CREATE | 1758 GNUNET_DISK_OPEN_CREATE |
1783 ((0 == 1759 ((0 ==
1784 GNUNET_FS_uri_chk_get_file_size (dc->uri)) ? 1760 GNUNET_FS_uri_chk_get_file_size (dc->
1761 uri)) ?
1785 GNUNET_DISK_OPEN_TRUNCATE : 0), 1762 GNUNET_DISK_OPEN_TRUNCATE : 0),
1786 GNUNET_DISK_PERM_USER_READ | 1763 GNUNET_DISK_PERM_USER_READ |
1787 GNUNET_DISK_PERM_USER_WRITE | 1764 GNUNET_DISK_PERM_USER_WRITE |
@@ -1797,11 +1774,13 @@ GNUNET_FS_download_start_task_ (void *cls,
1797 return; 1774 return;
1798 if (dc->top_request == NULL) 1775 if (dc->top_request == NULL)
1799 { 1776 {
1800 dc->top_request = create_download_request (NULL, dc->treedepth - 1, 0, 1777 dc->top_request =
1801 dc->offset, dc->length); 1778 create_download_request (NULL, dc->treedepth - 1, 0, dc->offset,
1779 dc->length);
1802 dc->top_request->state = BRS_CHK_SET; 1780 dc->top_request->state = BRS_CHK_SET;
1803 dc->top_request->chk = (dc->uri->type == chk) 1781 dc->top_request->chk =
1804 ? dc->uri->data.chk.chk : dc->uri->data.loc.fi.chk; 1782 (dc->uri->type ==
1783 chk) ? dc->uri->data.chk.chk : dc->uri->data.loc.fi.chk;
1805 /* signal start */ 1784 /* signal start */
1806 GNUNET_FS_download_sync_ (dc); 1785 GNUNET_FS_download_sync_ (dc);
1807 pi.status = GNUNET_FS_STATUS_DOWNLOAD_START; 1786 pi.status = GNUNET_FS_STATUS_DOWNLOAD_START;
@@ -1811,9 +1790,9 @@ GNUNET_FS_download_start_task_ (void *cls,
1811 GNUNET_FS_download_start_downloading_ (dc); 1790 GNUNET_FS_download_start_downloading_ (dc);
1812 /* attempt reconstruction from disk */ 1791 /* attempt reconstruction from disk */
1813 if (GNUNET_YES == GNUNET_DISK_file_test (dc->filename)) 1792 if (GNUNET_YES == GNUNET_DISK_file_test (dc->filename))
1814 dc->rfh = GNUNET_DISK_file_open (dc->filename, 1793 dc->rfh =
1815 GNUNET_DISK_OPEN_READ, 1794 GNUNET_DISK_file_open (dc->filename, GNUNET_DISK_OPEN_READ,
1816 GNUNET_DISK_PERM_NONE); 1795 GNUNET_DISK_PERM_NONE);
1817 if (dc->top_request->state == BRS_CHK_SET) 1796 if (dc->top_request->state == BRS_CHK_SET)
1818 { 1797 {
1819 if (dc->rfh != NULL) 1798 if (dc->rfh != NULL)
@@ -1884,12 +1863,10 @@ GNUNET_FS_download_start_task_ (void *cls,
1884 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1863 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1885 "Trying bottom-up reconstruction of file `%s'\n", dc->filename); 1864 "Trying bottom-up reconstruction of file `%s'\n", dc->filename);
1886#endif 1865#endif
1887 dc->te = GNUNET_FS_tree_encoder_create (dc->h, 1866 dc->te =
1888 dc->old_file_size, 1867 GNUNET_FS_tree_encoder_create (dc->h, dc->old_file_size, dc, &fh_reader,
1889 dc, 1868 &reconstruct_cb, NULL,
1890 &fh_reader, 1869 &reconstruct_cont);
1891 &reconstruct_cb,
1892 NULL, &reconstruct_cont);
1893 dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc); 1870 dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc);
1894 } 1871 }
1895 else 1872 else
@@ -1929,8 +1906,8 @@ GNUNET_FS_download_signal_suspend_ (void *cls)
1929 dc->job_queue = NULL; 1906 dc->job_queue = NULL;
1930 } 1907 }
1931 if (dc->parent != NULL) 1908 if (dc->parent != NULL)
1932 GNUNET_CONTAINER_DLL_remove (dc->parent->child_head, 1909 GNUNET_CONTAINER_DLL_remove (dc->parent->child_head, dc->parent->child_tail,
1933 dc->parent->child_tail, dc); 1910 dc);
1934 if (dc->task != GNUNET_SCHEDULER_NO_TASK) 1911 if (dc->task != GNUNET_SCHEDULER_NO_TASK)
1935 { 1912 {
1936 GNUNET_SCHEDULER_cancel (dc->task); 1913 GNUNET_SCHEDULER_cancel (dc->task);
@@ -1997,13 +1974,10 @@ struct GNUNET_FS_DownloadContext *
1997GNUNET_FS_download_start (struct GNUNET_FS_Handle *h, 1974GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
1998 const struct GNUNET_FS_Uri *uri, 1975 const struct GNUNET_FS_Uri *uri,
1999 const struct GNUNET_CONTAINER_MetaData *meta, 1976 const struct GNUNET_CONTAINER_MetaData *meta,
2000 const char *filename, 1977 const char *filename, const char *tempname,
2001 const char *tempname, 1978 uint64_t offset, uint64_t length, uint32_t anonymity,
2002 uint64_t offset, 1979 enum GNUNET_FS_DownloadOptions options, void *cctx,
2003 uint64_t length, 1980 struct GNUNET_FS_DownloadContext *parent)
2004 uint32_t anonymity,
2005 enum GNUNET_FS_DownloadOptions options,
2006 void *cctx, struct GNUNET_FS_DownloadContext *parent)
2007{ 1981{
2008 struct GNUNET_FS_DownloadContext *dc; 1982 struct GNUNET_FS_DownloadContext *dc;
2009 1983
@@ -2016,8 +1990,7 @@ GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2016 return NULL; 1990 return NULL;
2017 } 1991 }
2018#if DEBUG_DOWNLOAD 1992#if DEBUG_DOWNLOAD
2019 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1993 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting download `%s' of %llu bytes\n",
2020 "Starting download `%s' of %llu bytes\n",
2021 filename, (unsigned long long) length); 1994 filename, (unsigned long long) length);
2022#endif 1995#endif
2023 dc = GNUNET_malloc (sizeof (struct GNUNET_FS_DownloadContext)); 1996 dc = GNUNET_malloc (sizeof (struct GNUNET_FS_DownloadContext));
@@ -2057,13 +2030,13 @@ GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2057 } 2030 }
2058 2031
2059#if DEBUG_DOWNLOAD 2032#if DEBUG_DOWNLOAD
2060 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2033 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download tree has depth %u\n",
2061 "Download tree has depth %u\n", dc->treedepth); 2034 dc->treedepth);
2062#endif 2035#endif
2063 if (parent == NULL) 2036 if (parent == NULL)
2064 { 2037 {
2065 dc->top = GNUNET_FS_make_top (dc->h, 2038 dc->top =
2066 &GNUNET_FS_download_signal_suspend_, dc); 2039 GNUNET_FS_make_top (dc->h, &GNUNET_FS_download_signal_suspend_, dc);
2067 } 2040 }
2068 dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc); 2041 dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc);
2069 return dc; 2042 return dc;
@@ -2108,10 +2081,8 @@ struct GNUNET_FS_DownloadContext *
2108GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h, 2081GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h,
2109 struct GNUNET_FS_SearchResult *sr, 2082 struct GNUNET_FS_SearchResult *sr,
2110 const char *filename, 2083 const char *filename,
2111 const char *tempname, 2084 const char *tempname, uint64_t offset,
2112 uint64_t offset, 2085 uint64_t length, uint32_t anonymity,
2113 uint64_t length,
2114 uint32_t anonymity,
2115 enum GNUNET_FS_DownloadOptions options, 2086 enum GNUNET_FS_DownloadOptions options,
2116 void *cctx) 2087 void *cctx)
2117{ 2088{
@@ -2131,8 +2102,7 @@ GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h,
2131 return NULL; 2102 return NULL;
2132 } 2103 }
2133#if DEBUG_DOWNLOAD 2104#if DEBUG_DOWNLOAD
2134 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2105 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting download `%s' of %llu bytes\n",
2135 "Starting download `%s' of %llu bytes\n",
2136 filename, (unsigned long long) length); 2106 filename, (unsigned long long) length);
2137#endif 2107#endif
2138 dc = GNUNET_malloc (sizeof (struct GNUNET_FS_DownloadContext)); 2108 dc = GNUNET_malloc (sizeof (struct GNUNET_FS_DownloadContext));
@@ -2174,8 +2144,8 @@ GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h,
2174 } 2144 }
2175 2145
2176#if DEBUG_DOWNLOAD 2146#if DEBUG_DOWNLOAD
2177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download tree has depth %u\n",
2178 "Download tree has depth %u\n", dc->treedepth); 2148 dc->treedepth);
2179#endif 2149#endif
2180 dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc); 2150 dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc);
2181 return dc; 2151 return dc;
@@ -2193,12 +2163,9 @@ GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc)
2193 if (dc->completed == dc->length) 2163 if (dc->completed == dc->length)
2194 return; 2164 return;
2195 GNUNET_assert (dc->job_queue == NULL); 2165 GNUNET_assert (dc->job_queue == NULL);
2196 dc->job_queue = GNUNET_FS_queue_ (dc->h, 2166 dc->job_queue =
2197 &activate_fs_download, 2167 GNUNET_FS_queue_ (dc->h, &activate_fs_download, &deactivate_fs_download,
2198 &deactivate_fs_download, 2168 dc, (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE);
2199 dc,
2200 (dc->length + DBLOCK_SIZE -
2201 1) / DBLOCK_SIZE);
2202} 2169}
2203 2170
2204 2171
@@ -2242,19 +2209,20 @@ GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete)
2242 while (NULL != dc->child_head) 2209 while (NULL != dc->child_head)
2243 GNUNET_FS_download_stop (dc->child_head, do_delete); 2210 GNUNET_FS_download_stop (dc->child_head, do_delete);
2244 if (dc->parent != NULL) 2211 if (dc->parent != NULL)
2245 GNUNET_CONTAINER_DLL_remove (dc->parent->child_head, 2212 GNUNET_CONTAINER_DLL_remove (dc->parent->child_head, dc->parent->child_tail,
2246 dc->parent->child_tail, dc); 2213 dc);
2247 if (dc->serialization != NULL) 2214 if (dc->serialization != NULL)
2248 GNUNET_FS_remove_sync_file_ (dc->h, 2215 GNUNET_FS_remove_sync_file_ (dc->h,
2249 ((dc->parent != NULL) || (dc->search != NULL)) 2216 ((dc->parent != NULL) ||
2250 ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD 2217 (dc->search !=
2251 : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, 2218 NULL)) ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD :
2219 GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
2252 dc->serialization); 2220 dc->serialization);
2253 if ((GNUNET_YES == have_children) && (dc->parent == NULL)) 2221 if ((GNUNET_YES == have_children) && (dc->parent == NULL))
2254 GNUNET_FS_remove_sync_dir_ (dc->h, 2222 GNUNET_FS_remove_sync_dir_ (dc->h,
2255 (dc->search != NULL) 2223 (dc->search !=
2256 ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD 2224 NULL) ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD :
2257 : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, 2225 GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
2258 dc->serialization); 2226 dc->serialization);
2259 pi.status = GNUNET_FS_STATUS_DOWNLOAD_STOPPED; 2227 pi.status = GNUNET_FS_STATUS_DOWNLOAD_STOPPED;
2260 GNUNET_FS_download_make_status_ (&pi, dc); 2228 GNUNET_FS_download_make_status_ (&pi, dc);
@@ -2270,8 +2238,8 @@ GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete)
2270 if ((dc->completed != dc->length) && (GNUNET_YES == do_delete)) 2238 if ((dc->completed != dc->length) && (GNUNET_YES == do_delete))
2271 { 2239 {
2272 if (0 != UNLINK (dc->filename)) 2240 if (0 != UNLINK (dc->filename))
2273 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 2241 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink",
2274 "unlink", dc->filename); 2242 dc->filename);
2275 } 2243 }
2276 GNUNET_free (dc->filename); 2244 GNUNET_free (dc->filename);
2277 } 2245 }
@@ -2280,8 +2248,8 @@ GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete)
2280 if (NULL != dc->temp_filename) 2248 if (NULL != dc->temp_filename)
2281 { 2249 {
2282 if (0 != UNLINK (dc->temp_filename)) 2250 if (0 != UNLINK (dc->temp_filename))
2283 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 2251 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "unlink",
2284 "unlink", dc->temp_filename); 2252 dc->temp_filename);
2285 GNUNET_free (dc->temp_filename); 2253 GNUNET_free (dc->temp_filename);
2286 } 2254 }
2287 GNUNET_free_non_null (dc->serialization); 2255 GNUNET_free_non_null (dc->serialization);
diff --git a/src/fs/fs_file_information.c b/src/fs/fs_file_information.c
index bb323bbbc..6809e3055 100644
--- a/src/fs/fs_file_information.c
+++ b/src/fs/fs_file_information.c
@@ -52,18 +52,13 @@
52 * @return always 0 to continue extracting 52 * @return always 0 to continue extracting
53 */ 53 */
54static int 54static int
55add_to_md (void *cls, 55add_to_md (void *cls, const char *plugin_name, enum EXTRACTOR_MetaType type,
56 const char *plugin_name, 56 enum EXTRACTOR_MetaFormat format, const char *data_mime_type,
57 enum EXTRACTOR_MetaType type, 57 const char *data, size_t data_len)
58 enum EXTRACTOR_MetaFormat format,
59 const char *data_mime_type, const char *data, size_t data_len)
60{ 58{
61 struct GNUNET_CONTAINER_MetaData *md = cls; 59 struct GNUNET_CONTAINER_MetaData *md = cls;
62 60
63 (void) GNUNET_CONTAINER_meta_data_insert (md, 61 (void) GNUNET_CONTAINER_meta_data_insert (md, plugin_name, type, format,
64 plugin_name,
65 type,
66 format,
67 data_mime_type, data, data_len); 62 data_mime_type, data, data_len);
68 return 0; 63 return 0;
69} 64}
@@ -76,8 +71,8 @@ add_to_md (void *cls,
76 * of meta-data items obtained 71 * of meta-data items obtained
77 */ 72 */
78int 73int
79GNUNET_FS_meta_data_extract_from_file (struct GNUNET_CONTAINER_MetaData 74GNUNET_FS_meta_data_extract_from_file (struct GNUNET_CONTAINER_MetaData *md,
80 *md, const char *filename, 75 const char *filename,
81 struct EXTRACTOR_PluginList *extractors) 76 struct EXTRACTOR_PluginList *extractors)
82{ 77{
83 int old; 78 int old;
@@ -160,13 +155,12 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
160 GNUNET_break (0); 155 GNUNET_break (0);
161 return NULL; 156 return NULL;
162 } 157 }
163 ret = GNUNET_FS_file_information_create_from_reader (h, 158 ret =
164 client_info, 159 GNUNET_FS_file_information_create_from_reader (h, client_info,
165 sbuf.st_size, 160 sbuf.st_size,
166 &GNUNET_FS_data_reader_file_, 161 &GNUNET_FS_data_reader_file_,
167 fi, 162 fi, keywords, meta,
168 keywords, 163 do_index, bo);
169 meta, do_index, bo);
170 if (ret == NULL) 164 if (ret == NULL)
171 return NULL; 165 return NULL;
172 ret->h = h; 166 ret->h = h;
@@ -179,8 +173,7 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
179#endif 173#endif
180 while (NULL != (ss = strstr (fn, DIR_SEPARATOR_STR))) 174 while (NULL != (ss = strstr (fn, DIR_SEPARATOR_STR)))
181 fn = ss + 1; 175 fn = ss + 1;
182 GNUNET_CONTAINER_meta_data_insert (ret->meta, 176 GNUNET_CONTAINER_meta_data_insert (ret->meta, "<gnunet>",
183 "<gnunet>",
184 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, 177 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
185 EXTRACTOR_METAFORMAT_C_STRING, 178 EXTRACTOR_METAFORMAT_C_STRING,
186 "text/plain", fn, strlen (fn) + 1); 179 "text/plain", fn, strlen (fn) + 1);
@@ -206,8 +199,7 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
206 */ 199 */
207struct GNUNET_FS_FileInformation * 200struct GNUNET_FS_FileInformation *
208GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h, 201GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
209 void *client_info, 202 void *client_info, uint64_t length,
210 uint64_t length,
211 void *data, 203 void *data,
212 const struct GNUNET_FS_Uri 204 const struct GNUNET_FS_Uri
213 *keywords, 205 *keywords,
@@ -222,13 +214,10 @@ GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
222 GNUNET_break (0); 214 GNUNET_break (0);
223 return NULL; 215 return NULL;
224 } 216 }
225 return GNUNET_FS_file_information_create_from_reader (h, 217 return GNUNET_FS_file_information_create_from_reader (h, client_info, length,
226 client_info,
227 length,
228 &GNUNET_FS_data_reader_copy_, 218 &GNUNET_FS_data_reader_copy_,
229 data, 219 data, keywords, meta,
230 keywords, 220 do_index, bo);
231 meta, do_index, bo);
232} 221}
233 222
234 223
@@ -357,15 +346,13 @@ dir_scan_cb (void *cls, const char *filename)
357 346
358 if (0 != STAT (filename, &sbuf)) 347 if (0 != STAT (filename, &sbuf))
359 { 348 {
360 GNUNET_asprintf (&dsc->emsg, 349 GNUNET_asprintf (&dsc->emsg, _("`%s' failed on file `%s': %s"), "stat",
361 _("`%s' failed on file `%s': %s"), 350 filename, STRERROR (errno));
362 "stat", filename, STRERROR (errno));
363 return GNUNET_SYSERR; 351 return GNUNET_SYSERR;
364 } 352 }
365 if (S_ISDIR (sbuf.st_mode)) 353 if (S_ISDIR (sbuf.st_mode))
366 { 354 {
367 fi = GNUNET_FS_file_information_create_from_directory (dsc->h, 355 fi = GNUNET_FS_file_information_create_from_directory (dsc->h, NULL,
368 NULL,
369 filename, 356 filename,
370 dsc->scanner, 357 dsc->scanner,
371 dsc->scanner_cls, 358 dsc->scanner_cls,
@@ -383,11 +370,8 @@ dir_scan_cb (void *cls, const char *filename)
383 GNUNET_FS_meta_data_extract_from_file (meta, filename, dsc->extractors); 370 GNUNET_FS_meta_data_extract_from_file (meta, filename, dsc->extractors);
384 keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta); 371 keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta);
385 ksk_uri = GNUNET_FS_uri_ksk_canonicalize (keywords); 372 ksk_uri = GNUNET_FS_uri_ksk_canonicalize (keywords);
386 fi = GNUNET_FS_file_information_create_from_file (dsc->h, 373 fi = GNUNET_FS_file_information_create_from_file (dsc->h, NULL, filename,
387 NULL, 374 ksk_uri, meta,
388 filename,
389 ksk_uri,
390 meta,
391 dsc->do_index, dsc->bo); 375 dsc->do_index, dsc->bo);
392 GNUNET_CONTAINER_meta_data_destroy (meta); 376 GNUNET_CONTAINER_meta_data_destroy (meta);
393 GNUNET_FS_uri_destroy (keywords); 377 GNUNET_FS_uri_destroy (keywords);
@@ -420,10 +404,8 @@ dir_scan_cb (void *cls, const char *filename)
420 * @return GNUNET_OK on success 404 * @return GNUNET_OK on success
421 */ 405 */
422int 406int
423GNUNET_FS_directory_scanner_default (void *cls, 407GNUNET_FS_directory_scanner_default (void *cls, struct GNUNET_FS_Handle *h,
424 struct GNUNET_FS_Handle *h, 408 const char *dirname, int do_index,
425 const char *dirname,
426 int do_index,
427 const struct GNUNET_FS_BlockOptions *bo, 409 const struct GNUNET_FS_BlockOptions *bo,
428 GNUNET_FS_FileProcessor proc, 410 GNUNET_FS_FileProcessor proc,
429 void *proc_cls, char **emsg) 411 void *proc_cls, char **emsg)
@@ -527,9 +509,9 @@ GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h,
527 scanner (scanner_cls, h, filename, do_index, bo, &dirproc, &dc, emsg); 509 scanner (scanner_cls, h, filename, do_index, bo, &dirproc, &dc, emsg);
528 ksk = NULL; // FIXME... 510 ksk = NULL; // FIXME...
529 // FIXME: create meta! 511 // FIXME: create meta!
530 ret = GNUNET_FS_file_information_create_empty_directory (h, 512 ret =
531 client_info, 513 GNUNET_FS_file_information_create_empty_directory (h, client_info, ksk,
532 ksk, meta, bo); 514 meta, bo);
533 GNUNET_CONTAINER_meta_data_destroy (meta); 515 GNUNET_CONTAINER_meta_data_destroy (meta);
534 ret->data.dir.entries = dc.entries; 516 ret->data.dir.entries = dc.entries;
535 while (dc.entries != NULL) 517 while (dc.entries != NULL)
@@ -541,8 +523,7 @@ GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h,
541 while ((NULL != (ss = strstr (fn, DIR_SEPARATOR_STR))) && (strlen (ss) > 1)) 523 while ((NULL != (ss = strstr (fn, DIR_SEPARATOR_STR))) && (strlen (ss) > 1))
542 fn = ss + 1; 524 fn = ss + 1;
543 GNUNET_asprintf (&dn, "%s/", fn); 525 GNUNET_asprintf (&dn, "%s/", fn);
544 GNUNET_CONTAINER_meta_data_insert (ret->meta, 526 GNUNET_CONTAINER_meta_data_insert (ret->meta, "<gnunet>",
545 "<gnunet>",
546 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, 527 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
547 EXTRACTOR_METAFORMAT_C_STRING, 528 EXTRACTOR_METAFORMAT_C_STRING,
548 "text/plain", dn, strlen (dn) + 1); 529 "text/plain", dn, strlen (dn) + 1);
@@ -656,10 +637,9 @@ GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
656 637
657 no = GNUNET_NO; 638 no = GNUNET_NO;
658 if (GNUNET_OK != 639 if (GNUNET_OK !=
659 proc (proc_cls, 640 proc (proc_cls, dir,
660 dir, 641 (dir->is_directory) ? dir->data.dir.dir_size : dir->data.file.
661 (dir->is_directory) ? dir->data.dir.dir_size : dir->data. 642 file_size, dir->meta, &dir->keywords, &dir->bo,
662 file.file_size, dir->meta, &dir->keywords, &dir->bo,
663 (dir->is_directory) ? &no : &dir->data.file.do_index, 643 (dir->is_directory) ? &no : &dir->data.file.do_index,
664 &dir->client_info)) 644 &dir->client_info))
665 return; 645 return;
@@ -670,10 +650,9 @@ GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
670 { 650 {
671 no = GNUNET_NO; 651 no = GNUNET_NO;
672 if (GNUNET_OK != 652 if (GNUNET_OK !=
673 proc (proc_cls, 653 proc (proc_cls, pos,
674 pos, 654 (pos->is_directory) ? pos->data.dir.dir_size : pos->data.file.
675 (pos->is_directory) ? pos->data.dir.dir_size : pos->data. 655 file_size, pos->meta, &pos->keywords, &pos->bo,
676 file.file_size, pos->meta, &pos->keywords, &pos->bo,
677 (dir->is_directory) ? &no : &dir->data.file.do_index, 656 (dir->is_directory) ? &no : &dir->data.file.do_index,
678 &pos->client_info)) 657 &pos->client_info))
679 break; 658 break;
@@ -711,10 +690,8 @@ GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
711 } 690 }
712 /* clean up client-info */ 691 /* clean up client-info */
713 if (NULL != cleaner) 692 if (NULL != cleaner)
714 cleaner (cleaner_cls, 693 cleaner (cleaner_cls, fi, fi->data.dir.dir_size, fi->meta, &fi->keywords,
715 fi, 694 &fi->bo, &no, &fi->client_info);
716 fi->data.dir.dir_size,
717 fi->meta, &fi->keywords, &fi->bo, &no, &fi->client_info);
718 GNUNET_free_non_null (fi->data.dir.dir_data); 695 GNUNET_free_non_null (fi->data.dir.dir_data);
719 } 696 }
720 else 697 else
@@ -724,20 +701,17 @@ GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
724 fi->data.file.reader (fi->data.file.reader_cls, 0, 0, NULL, NULL); 701 fi->data.file.reader (fi->data.file.reader_cls, 0, 0, NULL, NULL);
725 /* clean up client-info */ 702 /* clean up client-info */
726 if (NULL != cleaner) 703 if (NULL != cleaner)
727 cleaner (cleaner_cls, 704 cleaner (cleaner_cls, fi, fi->data.file.file_size, fi->meta,
728 fi, 705 &fi->keywords, &fi->bo, &fi->data.file.do_index,
729 fi->data.file.file_size, 706 &fi->client_info);
730 fi->meta,
731 &fi->keywords,
732 &fi->bo, &fi->data.file.do_index, &fi->client_info);
733 } 707 }
734 GNUNET_free_non_null (fi->filename); 708 GNUNET_free_non_null (fi->filename);
735 GNUNET_free_non_null (fi->emsg); 709 GNUNET_free_non_null (fi->emsg);
736 GNUNET_free_non_null (fi->chk_uri); 710 GNUNET_free_non_null (fi->chk_uri);
737 /* clean up serialization */ 711 /* clean up serialization */
738 if ((NULL != fi->serialization) && (0 != UNLINK (fi->serialization))) 712 if ((NULL != fi->serialization) && (0 != UNLINK (fi->serialization)))
739 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 713 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink",
740 "unlink", fi->serialization); 714 fi->serialization);
741 if (NULL != fi->keywords) 715 if (NULL != fi->keywords)
742 GNUNET_FS_uri_destroy (fi->keywords); 716 GNUNET_FS_uri_destroy (fi->keywords);
743 if (NULL != fi->meta) 717 if (NULL != fi->meta)
diff --git a/src/fs/fs_getopt.c b/src/fs/fs_getopt.c
index 6c54fd69b..b50d0624b 100644
--- a/src/fs/fs_getopt.c
+++ b/src/fs/fs_getopt.c
@@ -154,9 +154,7 @@ GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext
154 (tmp[strlen (typename)] == ':') && 154 (tmp[strlen (typename)] == ':') &&
155 (0 == strncmp (typename, tmp, strlen (typename)))) 155 (0 == strncmp (typename, tmp, strlen (typename))))
156 { 156 {
157 GNUNET_CONTAINER_meta_data_insert (meta, 157 GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet>", type,
158 "<gnunet>",
159 type,
160 EXTRACTOR_METAFORMAT_UTF8, 158 EXTRACTOR_METAFORMAT_UTF8,
161 "text/plain", 159 "text/plain",
162 &tmp[strlen (typename) + 1], 160 &tmp[strlen (typename) + 1],
@@ -170,9 +168,7 @@ GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext
170 (tmp[strlen (typename_i18n)] == ':') && 168 (tmp[strlen (typename_i18n)] == ':') &&
171 (0 == strncmp (typename_i18n, tmp, strlen (typename_i18n)))) 169 (0 == strncmp (typename_i18n, tmp, strlen (typename_i18n))))
172 { 170 {
173 GNUNET_CONTAINER_meta_data_insert (meta, 171 GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet>", type,
174 "<gnunet>",
175 type,
176 EXTRACTOR_METAFORMAT_UTF8, 172 EXTRACTOR_METAFORMAT_UTF8,
177 "text/plain", 173 "text/plain",
178 &tmp[strlen (typename_i18n) + 1], 174 &tmp[strlen (typename_i18n) + 1],
@@ -186,11 +182,10 @@ GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext
186 } 182 }
187 if (tmp != NULL) 183 if (tmp != NULL)
188 { 184 {
189 GNUNET_CONTAINER_meta_data_insert (meta, 185 GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet>",
190 "<gnunet>",
191 EXTRACTOR_METATYPE_UNKNOWN, 186 EXTRACTOR_METATYPE_UNKNOWN,
192 EXTRACTOR_METAFORMAT_UTF8, 187 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
193 "text/plain", tmp, strlen (tmp) + 1); 188 tmp, strlen (tmp) + 1);
194 GNUNET_free (tmp); 189 GNUNET_free (tmp);
195 printf (_ 190 printf (_
196 ("Unknown metadata type in metadata option `%s'. Using metadata type `unknown' instead.\n"), 191 ("Unknown metadata type in metadata option `%s'. Using metadata type `unknown' instead.\n"),
diff --git a/src/fs/fs_list_indexed.c b/src/fs/fs_list_indexed.c
index 1eb290f11..85e12db32 100644
--- a/src/fs/fs_list_indexed.c
+++ b/src/fs/fs_list_indexed.c
@@ -98,8 +98,7 @@ handle_index_info (void *cls, const struct GNUNET_MessageHeader *msg)
98 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END) 98 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END)
99 { 99 {
100 /* normal end-of-list */ 100 /* normal end-of-list */
101 GNUNET_SCHEDULER_add_continuation (gic->cont, 101 GNUNET_SCHEDULER_add_continuation (gic->cont, gic->cont_cls,
102 gic->cont_cls,
103 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 102 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
104 GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO); 103 GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
105 GNUNET_free (gic); 104 GNUNET_free (gic);
@@ -125,17 +124,15 @@ handle_index_info (void *cls, const struct GNUNET_MessageHeader *msg)
125 } 124 }
126 if (GNUNET_OK != gic->iterator (gic->iterator_cls, filename, &iim->file_id)) 125 if (GNUNET_OK != gic->iterator (gic->iterator_cls, filename, &iim->file_id))
127 { 126 {
128 GNUNET_SCHEDULER_add_continuation (gic->cont, 127 GNUNET_SCHEDULER_add_continuation (gic->cont, gic->cont_cls,
129 gic->cont_cls,
130 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 128 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
131 GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO); 129 GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
132 GNUNET_free (gic); 130 GNUNET_free (gic);
133 return; 131 return;
134 } 132 }
135 /* get more */ 133 /* get more */
136 GNUNET_CLIENT_receive (gic->client, 134 GNUNET_CLIENT_receive (gic->client, &handle_index_info, gic,
137 &handle_index_info, 135 GNUNET_CONSTANTS_SERVICE_TIMEOUT);
138 gic, GNUNET_CONSTANTS_SERVICE_TIMEOUT);
139} 136}
140 137
141 138
@@ -153,8 +150,8 @@ handle_index_info (void *cls, const struct GNUNET_MessageHeader *msg)
153void 150void
154GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h, 151GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
155 GNUNET_FS_IndexedFileProcessor iterator, 152 GNUNET_FS_IndexedFileProcessor iterator,
156 void *iterator_cls, 153 void *iterator_cls, GNUNET_SCHEDULER_Task cont,
157 GNUNET_SCHEDULER_Task cont, void *cont_cls) 154 void *cont_cls)
158{ 155{
159 struct GNUNET_CLIENT_Connection *client; 156 struct GNUNET_CLIENT_Connection *client;
160 struct GetIndexedContext *gic; 157 struct GetIndexedContext *gic;
@@ -165,8 +162,7 @@ GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
165 { 162 {
166 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 163 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
167 _("Failed to not connect to `%s' service.\n"), "fs"); 164 _("Failed to not connect to `%s' service.\n"), "fs");
168 GNUNET_SCHEDULER_add_continuation (cont, 165 GNUNET_SCHEDULER_add_continuation (cont, cont_cls,
169 cont_cls,
170 GNUNET_SCHEDULER_REASON_TIMEOUT); 166 GNUNET_SCHEDULER_REASON_TIMEOUT);
171 return; 167 return;
172 } 168 }
@@ -181,8 +177,7 @@ GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
181 msg.size = htons (sizeof (struct GNUNET_MessageHeader)); 177 msg.size = htons (sizeof (struct GNUNET_MessageHeader));
182 msg.type = htons (GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET); 178 msg.type = htons (GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET);
183 GNUNET_assert (GNUNET_OK == 179 GNUNET_assert (GNUNET_OK ==
184 GNUNET_CLIENT_transmit_and_get_response (client, 180 GNUNET_CLIENT_transmit_and_get_response (client, &msg,
185 &msg,
186 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 181 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
187 GNUNET_YES, 182 GNUNET_YES,
188 &handle_index_info, 183 &handle_index_info,
diff --git a/src/fs/fs_misc.c b/src/fs/fs_misc.c
index 9fa86a5c4..3a8260d05 100644
--- a/src/fs/fs_misc.c
+++ b/src/fs/fs_misc.c
@@ -108,44 +108,45 @@ GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData
108 char *base; 108 char *base;
109 const char *ext; 109 const char *ext;
110 110
111 ret = GNUNET_CONTAINER_meta_data_get_by_type (md, 111 ret =
112 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); 112 GNUNET_CONTAINER_meta_data_get_by_type (md,
113 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
113 if (ret != NULL) 114 if (ret != NULL)
114 return ret; 115 return ret;
115 ext = NULL; 116 ext = NULL;
116 mime = GNUNET_CONTAINER_meta_data_get_by_type (md, 117 mime =
117 EXTRACTOR_METATYPE_MIMETYPE); 118 GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_METATYPE_MIMETYPE);
118 if (mime != NULL) 119 if (mime != NULL)
119 { 120 {
120 i = 0; 121 i = 0;
121 while ((mimeMap[i][0] != NULL) && (0 != strcmp (mime, mimeMap[i][0]))) 122 while ((mimeMap[i][0] != NULL) && (0 != strcmp (mime, mimeMap[i][0])))
122 i++; 123 i++;
123 if (mimeMap[i][1] == NULL) 124 if (mimeMap[i][1] == NULL)
124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | 125 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
125 GNUNET_ERROR_TYPE_BULK,
126 _("Did not find mime type `%s' in extension list.\n"), mime); 126 _("Did not find mime type `%s' in extension list.\n"), mime);
127 else 127 else
128 ext = mimeMap[i][1]; 128 ext = mimeMap[i][1];
129 GNUNET_free (mime); 129 GNUNET_free (mime);
130 } 130 }
131 base = GNUNET_CONTAINER_meta_data_get_first_by_types (md, 131 base =
132 EXTRACTOR_METATYPE_TITLE, 132 GNUNET_CONTAINER_meta_data_get_first_by_types (md,
133 EXTRACTOR_METATYPE_BOOK_TITLE, 133 EXTRACTOR_METATYPE_TITLE,
134 EXTRACTOR_METATYPE_ORIGINAL_TITLE, 134 EXTRACTOR_METATYPE_BOOK_TITLE,
135 EXTRACTOR_METATYPE_PACKAGE_NAME, 135 EXTRACTOR_METATYPE_ORIGINAL_TITLE,
136 EXTRACTOR_METATYPE_URL, 136 EXTRACTOR_METATYPE_PACKAGE_NAME,
137 EXTRACTOR_METATYPE_URI, 137 EXTRACTOR_METATYPE_URL,
138 EXTRACTOR_METATYPE_DESCRIPTION, 138 EXTRACTOR_METATYPE_URI,
139 EXTRACTOR_METATYPE_ISRC, 139 EXTRACTOR_METATYPE_DESCRIPTION,
140 EXTRACTOR_METATYPE_JOURNAL_NAME, 140 EXTRACTOR_METATYPE_ISRC,
141 EXTRACTOR_METATYPE_AUTHOR_NAME, 141 EXTRACTOR_METATYPE_JOURNAL_NAME,
142 EXTRACTOR_METATYPE_SUBJECT, 142 EXTRACTOR_METATYPE_AUTHOR_NAME,
143 EXTRACTOR_METATYPE_ALBUM, 143 EXTRACTOR_METATYPE_SUBJECT,
144 EXTRACTOR_METATYPE_ARTIST, 144 EXTRACTOR_METATYPE_ALBUM,
145 EXTRACTOR_METATYPE_KEYWORDS, 145 EXTRACTOR_METATYPE_ARTIST,
146 EXTRACTOR_METATYPE_COMMENT, 146 EXTRACTOR_METATYPE_KEYWORDS,
147 EXTRACTOR_METATYPE_UNKNOWN, 147 EXTRACTOR_METATYPE_COMMENT,
148 -1); 148 EXTRACTOR_METATYPE_UNKNOWN,
149 -1);
149 if ((base == NULL) && (ext == NULL)) 150 if ((base == NULL) && (ext == NULL))
150 return NULL; 151 return NULL;
151 if (base == NULL) 152 if (base == NULL)
diff --git a/src/fs/fs_namespace.c b/src/fs/fs_namespace.c
index e8dd56ef4..236e8d59b 100644
--- a/src/fs/fs_namespace.c
+++ b/src/fs/fs_namespace.c
@@ -45,8 +45,8 @@ get_namespace_directory (struct GNUNET_FS_Handle *h)
45 char *dn; 45 char *dn;
46 46
47 if (GNUNET_OK != 47 if (GNUNET_OK !=
48 GNUNET_CONFIGURATION_get_value_filename (h->cfg, 48 GNUNET_CONFIGURATION_get_value_filename (h->cfg, "FS", "IDENTITY_DIR",
49 "FS", "IDENTITY_DIR", &dn)) 49 &dn))
50 { 50 {
51 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 51 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
52 _("Configuration fails to specify `%s' in section `%s'\n"), 52 _("Configuration fails to specify `%s' in section `%s'\n"),
@@ -71,8 +71,8 @@ get_update_information_directory (struct GNUNET_FS_Namespace *ns)
71 char *ret; 71 char *ret;
72 72
73 if (GNUNET_OK != 73 if (GNUNET_OK !=
74 GNUNET_CONFIGURATION_get_value_filename (ns->h->cfg, 74 GNUNET_CONFIGURATION_get_value_filename (ns->h->cfg, "FS", "UPDATE_DIR",
75 "FS", "UPDATE_DIR", &dn)) 75 &dn))
76 { 76 {
77 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 77 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
78 _("Configuration fails to specify `%s' in section `%s'\n"), 78 _("Configuration fails to specify `%s' in section `%s'\n"),
@@ -114,12 +114,9 @@ write_update_information_graph (struct GNUNET_FS_Namespace *ns)
114 { 114 {
115 n = ns->update_nodes[i]; 115 n = ns->update_nodes[i];
116 uris = GNUNET_FS_uri_to_string (n->uri); 116 uris = GNUNET_FS_uri_to_string (n->uri);
117 if ((GNUNET_OK != 117 if ((GNUNET_OK != GNUNET_BIO_write_string (wh, n->id)) ||
118 GNUNET_BIO_write_string (wh, n->id)) || 118 (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, n->md)) ||
119 (GNUNET_OK != 119 (GNUNET_OK != GNUNET_BIO_write_string (wh, n->update)) ||
120 GNUNET_BIO_write_meta_data (wh, n->md)) ||
121 (GNUNET_OK !=
122 GNUNET_BIO_write_string (wh, n->update)) ||
123 (GNUNET_OK != GNUNET_BIO_write_string (wh, uris))) 120 (GNUNET_OK != GNUNET_BIO_write_string (wh, uris)))
124 { 121 {
125 GNUNET_free (uris); 122 GNUNET_free (uris);
@@ -129,8 +126,8 @@ write_update_information_graph (struct GNUNET_FS_Namespace *ns)
129 } 126 }
130END: 127END:
131 if (GNUNET_OK != GNUNET_BIO_write_close (wh)) 128 if (GNUNET_OK != GNUNET_BIO_write_close (wh))
132 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 129 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to write `%s': %s\n"),
133 _("Failed to write `%s': %s\n"), STRERROR (errno)); 130 STRERROR (errno));
134 GNUNET_free (fn); 131 GNUNET_free (fn);
135} 132}
136 133
@@ -185,10 +182,8 @@ read_update_information_graph (struct GNUNET_FS_Namespace *ns)
185 for (i = 0; i < count; i++) 182 for (i = 0; i < count; i++)
186 { 183 {
187 n = GNUNET_malloc (sizeof (struct NamespaceUpdateNode)); 184 n = GNUNET_malloc (sizeof (struct NamespaceUpdateNode));
188 if ((GNUNET_OK != 185 if ((GNUNET_OK != GNUNET_BIO_read_string (rh, "identifier", &n->id, 1024))
189 GNUNET_BIO_read_string (rh, "identifier", &n->id, 1024)) || 186 || (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "meta", &n->md)) ||
190 (GNUNET_OK !=
191 GNUNET_BIO_read_meta_data (rh, "meta", &n->md)) ||
192 (GNUNET_OK != 187 (GNUNET_OK !=
193 GNUNET_BIO_read_string (rh, "update-id", &n->update, 1024)) || 188 GNUNET_BIO_read_string (rh, "update-id", &n->update, 1024)) ||
194 (GNUNET_OK != GNUNET_BIO_read_string (rh, "uri", &uris, 1024 * 2))) 189 (GNUNET_OK != GNUNET_BIO_read_string (rh, "uri", &uris, 1024 * 2)))
@@ -320,8 +315,7 @@ advertisement_cont (void *cls, int success, const char *msg)
320 if (GNUNET_OK != success) 315 if (GNUNET_OK != success)
321 { 316 {
322 /* error! */ 317 /* error! */
323 GNUNET_SCHEDULER_add_continuation (&do_disconnect, 318 GNUNET_SCHEDULER_add_continuation (&do_disconnect, ac->dsh,
324 ac->dsh,
325 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 319 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
326 if (msg == NULL) 320 if (msg == NULL)
327 { 321 {
@@ -340,8 +334,7 @@ advertisement_cont (void *cls, int success, const char *msg)
340 if (ac->pos == ac->ksk_uri->data.ksk.keywordCount) 334 if (ac->pos == ac->ksk_uri->data.ksk.keywordCount)
341 { 335 {
342 /* done! */ 336 /* done! */
343 GNUNET_SCHEDULER_add_continuation (&do_disconnect, 337 GNUNET_SCHEDULER_add_continuation (&do_disconnect, ac->dsh,
344 ac->dsh,
345 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 338 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
346 if (ac->cont != NULL) 339 if (ac->cont != NULL)
347 ac->cont (ac->cont_cls, ac->ksk_uri, NULL); 340 ac->cont (ac->cont_cls, ac->ksk_uri, NULL);
@@ -359,8 +352,7 @@ advertisement_cont (void *cls, int success, const char *msg)
359 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv); 352 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv);
360 GNUNET_CRYPTO_aes_encrypt (ac->pt, ac->pt_size, &skey, &iv, &ac->nb[1]); 353 GNUNET_CRYPTO_aes_encrypt (ac->pt, ac->pt_size, &skey, &iv, &ac->nb[1]);
361 GNUNET_break (GNUNET_OK == 354 GNUNET_break (GNUNET_OK ==
362 GNUNET_CRYPTO_rsa_sign (ac->ns->key, 355 GNUNET_CRYPTO_rsa_sign (ac->ns->key, &ac->nb->ns_purpose,
363 &ac->nb->ns_purpose,
364 &ac->nb->ns_signature)); 356 &ac->nb->ns_signature));
365 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&key); 357 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&key);
366 GNUNET_assert (pk != NULL); 358 GNUNET_assert (pk != NULL);
@@ -369,22 +361,16 @@ advertisement_cont (void *cls, int success, const char *msg)
369 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 361 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
370 &query); 362 &query);
371 GNUNET_break (GNUNET_OK == 363 GNUNET_break (GNUNET_OK ==
372 GNUNET_CRYPTO_rsa_sign (pk, 364 GNUNET_CRYPTO_rsa_sign (pk, &ac->nb->ksk_purpose,
373 &ac->nb->ksk_purpose,
374 &ac->nb->ksk_signature)); 365 &ac->nb->ksk_signature));
375 GNUNET_CRYPTO_rsa_key_free (pk); 366 GNUNET_CRYPTO_rsa_key_free (pk);
376 GNUNET_DATASTORE_put (ac->dsh, 0 /* no reservation */ , 367 GNUNET_DATASTORE_put (ac->dsh, 0 /* no reservation */ ,
377 &query, 368 &query, ac->pt_size + sizeof (struct NBlock), ac->nb,
378 ac->pt_size + sizeof (struct NBlock), 369 GNUNET_BLOCK_TYPE_FS_NBLOCK, ac->bo.content_priority,
379 ac->nb, 370 ac->bo.anonymity_level, ac->bo.replication_level,
380 GNUNET_BLOCK_TYPE_FS_NBLOCK, 371 ac->bo.expiration_time, -2, 1,
381 ac->bo.content_priority, 372 GNUNET_CONSTANTS_SERVICE_TIMEOUT, &advertisement_cont,
382 ac->bo.anonymity_level, 373 ac);
383 ac->bo.replication_level,
384 ac->bo.expiration_time,
385 -2, 1,
386 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
387 &advertisement_cont, ac);
388} 374}
389 375
390 376
@@ -437,10 +423,9 @@ GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
437 pt = GNUNET_malloc (mdsize + reslen); 423 pt = GNUNET_malloc (mdsize + reslen);
438 memcpy (pt, rootEntry, reslen); 424 memcpy (pt, rootEntry, reslen);
439 mdst = &pt[reslen]; 425 mdst = &pt[reslen];
440 mdsize = GNUNET_CONTAINER_meta_data_serialize (meta, 426 mdsize =
441 &mdst, 427 GNUNET_CONTAINER_meta_data_serialize (meta, &mdst, mdsize,
442 mdsize, 428 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
443 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
444 if (mdsize == -1) 429 if (mdsize == -1)
445 { 430 {
446 GNUNET_break (0); 431 GNUNET_break (0);
@@ -451,11 +436,10 @@ GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
451 size = mdsize + sizeof (struct NBlock) + reslen; 436 size = mdsize + sizeof (struct NBlock) + reslen;
452 nb = GNUNET_malloc (size); 437 nb = GNUNET_malloc (size);
453 GNUNET_CRYPTO_rsa_key_get_public (namespace->key, &nb->subspace); 438 GNUNET_CRYPTO_rsa_key_get_public (namespace->key, &nb->subspace);
454 nb->ns_purpose.size = htonl (mdsize + reslen + 439 nb->ns_purpose.size =
455 sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) 440 htonl (mdsize + reslen +
456 + 441 sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
457 sizeof (struct 442 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
458 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
459 nb->ns_purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK); 443 nb->ns_purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK);
460 nb->ksk_purpose.size = 444 nb->ksk_purpose.size =
461 htonl (size - sizeof (struct GNUNET_CRYPTO_RsaSignature)); 445 htonl (size - sizeof (struct GNUNET_CRYPTO_RsaSignature));
@@ -541,8 +525,8 @@ GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace, int freeze)
541 if (freeze) 525 if (freeze)
542 { 526 {
543 if (0 != UNLINK (namespace->filename)) 527 if (0 != UNLINK (namespace->filename))
544 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 528 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "unlink",
545 "unlink", namespace->filename); 529 namespace->filename);
546 } 530 }
547 if (0 == namespace->rc) 531 if (0 == namespace->rc)
548 { 532 {
@@ -558,8 +542,8 @@ GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace, int freeze)
558 GNUNET_free (nsn->update); 542 GNUNET_free (nsn->update);
559 GNUNET_free (nsn); 543 GNUNET_free (nsn);
560 } 544 }
561 GNUNET_array_grow (namespace->update_nodes, 545 GNUNET_array_grow (namespace->update_nodes, namespace->update_node_count,
562 namespace->update_node_count, 0); 546 0);
563 if (namespace->update_map != NULL) 547 if (namespace->update_map != NULL)
564 GNUNET_CONTAINER_multihashmap_destroy (namespace->update_map); 548 GNUNET_CONTAINER_multihashmap_destroy (namespace->update_map);
565 GNUNET_free (namespace); 549 GNUNET_free (namespace);
@@ -733,8 +717,7 @@ sb_put_cont (void *cls, int success, const char *msg)
733 if (psc->namespace->update_map != NULL) 717 if (psc->namespace->update_map != NULL)
734 { 718 {
735 GNUNET_CRYPTO_hash (psc->nsn->id, strlen (psc->nsn->id), &hc); 719 GNUNET_CRYPTO_hash (psc->nsn->id, strlen (psc->nsn->id), &hc);
736 GNUNET_CONTAINER_multihashmap_put (psc->namespace->update_map, 720 GNUNET_CONTAINER_multihashmap_put (psc->namespace->update_map, &hc,
737 &hc,
738 psc->nsn, 721 psc->nsn,
739 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 722 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
740 } 723 }
@@ -775,8 +758,7 @@ sb_put_cont (void *cls, int success, const char *msg)
775void 758void
776GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, 759GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
777 struct GNUNET_FS_Namespace *namespace, 760 struct GNUNET_FS_Namespace *namespace,
778 const char *identifier, 761 const char *identifier, const char *update,
779 const char *update,
780 const struct GNUNET_CONTAINER_MetaData *meta, 762 const struct GNUNET_CONTAINER_MetaData *meta,
781 const struct GNUNET_FS_Uri *uri, 763 const struct GNUNET_FS_Uri *uri,
782 const struct GNUNET_FS_BlockOptions *bo, 764 const struct GNUNET_FS_BlockOptions *bo,
@@ -829,10 +811,9 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
829 memcpy (dest, uris, slen); 811 memcpy (dest, uris, slen);
830 GNUNET_free (uris); 812 GNUNET_free (uris);
831 dest += slen; 813 dest += slen;
832 mdsize = GNUNET_CONTAINER_meta_data_serialize (mmeta, 814 mdsize =
833 &dest, 815 GNUNET_CONTAINER_meta_data_serialize (mmeta, &dest, mdsize,
834 mdsize, 816 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
835 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
836 GNUNET_CONTAINER_meta_data_destroy (mmeta); 817 GNUNET_CONTAINER_meta_data_destroy (mmeta);
837 if (mdsize == -1) 818 if (mdsize == -1)
838 { 819 {
@@ -852,19 +833,18 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
852 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 833 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
853 &sks_uri->data.sks.namespace); 834 &sks_uri->data.sks.namespace);
854 sks_uri->data.sks.identifier = GNUNET_strdup (identifier); 835 sks_uri->data.sks.identifier = GNUNET_strdup (identifier);
855 GNUNET_CRYPTO_hash_xor (&id, 836 GNUNET_CRYPTO_hash_xor (&id, &sks_uri->data.sks.namespace,
856 &sks_uri->data.sks.namespace, &sb_enc->identifier); 837 &sb_enc->identifier);
857 GNUNET_CRYPTO_hash_to_aes_key (&key, &sk, &iv); 838 GNUNET_CRYPTO_hash_to_aes_key (&key, &sk, &iv);
858 GNUNET_CRYPTO_aes_encrypt (&sb[1], 839 GNUNET_CRYPTO_aes_encrypt (&sb[1], size - sizeof (struct SBlock), &sk, &iv,
859 size - sizeof (struct SBlock), 840 &sb_enc[1]);
860 &sk, &iv, &sb_enc[1]);
861 sb_enc->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK); 841 sb_enc->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK);
862 sb_enc->purpose.size = htonl (slen + mdsize + nidlen 842 sb_enc->purpose.size =
863 + sizeof (struct SBlock) 843 htonl (slen + mdsize + nidlen + sizeof (struct SBlock) -
864 - sizeof (struct GNUNET_CRYPTO_RsaSignature)); 844 sizeof (struct GNUNET_CRYPTO_RsaSignature));
865 GNUNET_assert (GNUNET_OK == 845 GNUNET_assert (GNUNET_OK ==
866 GNUNET_CRYPTO_rsa_sign (namespace->key, 846 GNUNET_CRYPTO_rsa_sign (namespace->key, &sb_enc->purpose,
867 &sb_enc->purpose, &sb_enc->signature)); 847 &sb_enc->signature));
868 psc = GNUNET_malloc (sizeof (struct PublishSksContext)); 848 psc = GNUNET_malloc (sizeof (struct PublishSksContext));
869 psc->uri = sks_uri; 849 psc->uri = sks_uri;
870 psc->cont = cont; 850 psc->cont = cont;
@@ -895,17 +875,10 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
895 psc->nsn->md = GNUNET_CONTAINER_meta_data_duplicate (meta); 875 psc->nsn->md = GNUNET_CONTAINER_meta_data_duplicate (meta);
896 psc->nsn->uri = GNUNET_FS_uri_dup (uri); 876 psc->nsn->uri = GNUNET_FS_uri_dup (uri);
897 } 877 }
898 GNUNET_DATASTORE_put (psc->dsh, 878 GNUNET_DATASTORE_put (psc->dsh, 0, &sb_enc->identifier, size, sb_enc,
899 0, 879 GNUNET_BLOCK_TYPE_FS_SBLOCK, bo->content_priority,
900 &sb_enc->identifier, 880 bo->anonymity_level, bo->replication_level,
901 size, 881 bo->expiration_time, -2, 1,
902 sb_enc,
903 GNUNET_BLOCK_TYPE_FS_SBLOCK,
904 bo->content_priority,
905 bo->anonymity_level,
906 bo->replication_level,
907 bo->expiration_time,
908 -2, 1,
909 GNUNET_CONSTANTS_SERVICE_TIMEOUT, &sb_put_cont, psc); 882 GNUNET_CONSTANTS_SERVICE_TIMEOUT, &sb_put_cont, psc);
910 GNUNET_free (sb); 883 GNUNET_free (sb);
911 GNUNET_free (sb_enc); 884 GNUNET_free (sb_enc);
@@ -1030,8 +1003,8 @@ find_trees (void *cls, const GNUNET_HashCode * key, void *value)
1030 nsn->tree_id = UINT_MAX; /* mark as undef */ 1003 nsn->tree_id = UINT_MAX; /* mark as undef */
1031 /* trace */ 1004 /* trace */
1032 GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc); 1005 GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc);
1033 GNUNET_CONTAINER_multihashmap_get_multiple (fc->namespace->update_map, 1006 GNUNET_CONTAINER_multihashmap_get_multiple (fc->namespace->update_map, &hc,
1034 &hc, &find_trees, fc); 1007 &find_trees, fc);
1035 } 1008 }
1036 return GNUNET_YES; 1009 return GNUNET_YES;
1037} 1010}
@@ -1093,9 +1066,7 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
1093 { 1066 {
1094 nsn = namespace->update_nodes[i]; 1067 nsn = namespace->update_nodes[i];
1095 GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc); 1068 GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc);
1096 GNUNET_CONTAINER_multihashmap_put (namespace->update_map, 1069 GNUNET_CONTAINER_multihashmap_put (namespace->update_map, &hc, nsn,
1097 &hc,
1098 nsn,
1099 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1070 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1100 } 1071 }
1101 } 1072 }
@@ -1104,8 +1075,8 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
1104 GNUNET_CRYPTO_hash (next_id, strlen (next_id), &hc); 1075 GNUNET_CRYPTO_hash (next_id, strlen (next_id), &hc);
1105 pc.ip = ip; 1076 pc.ip = ip;
1106 pc.ip_cls = ip_cls; 1077 pc.ip_cls = ip_cls;
1107 GNUNET_CONTAINER_multihashmap_get_multiple (namespace->update_map, 1078 GNUNET_CONTAINER_multihashmap_get_multiple (namespace->update_map, &hc,
1108 &hc, &process_update_node, &pc); 1079 &process_update_node, &pc);
1109 return; 1080 return;
1110 } 1081 }
1111#if DEBUG_NAMESPACE 1082#if DEBUG_NAMESPACE
@@ -1123,8 +1094,8 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
1123 if (nsn->nug == nug) 1094 if (nsn->nug == nug)
1124 { 1095 {
1125#if DEBUG_NAMESPACE 1096#if DEBUG_NAMESPACE
1126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1097 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TREE of node `%s' is %u\n", nsn->id,
1127 "TREE of node `%s' is %u\n", nsn->id, nsn->nug); 1098 nsn->nug);
1128#endif 1099#endif
1129 continue; /* already placed in TREE */ 1100 continue; /* already placed in TREE */
1130 } 1101 }
@@ -1133,8 +1104,8 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
1133 fc.id = UINT_MAX; 1104 fc.id = UINT_MAX;
1134 fc.nug = nug; 1105 fc.nug = nug;
1135 fc.namespace = namespace; 1106 fc.namespace = namespace;
1136 GNUNET_CONTAINER_multihashmap_get_multiple (namespace->update_map, 1107 GNUNET_CONTAINER_multihashmap_get_multiple (namespace->update_map, &hc,
1137 &hc, &find_trees, &fc); 1108 &find_trees, &fc);
1138 if (fc.id == UINT_MAX) 1109 if (fc.id == UINT_MAX)
1139 { 1110 {
1140 /* start new TREE */ 1111 /* start new TREE */
@@ -1154,16 +1125,16 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
1154 } 1125 }
1155#if DEBUG_NAMESPACE 1126#if DEBUG_NAMESPACE
1156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1127 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1157 "Starting new TREE %u with node `%s'\n", 1128 "Starting new TREE %u with node `%s'\n", nsn->tree_id,
1158 nsn->tree_id, nsn->id); 1129 nsn->id);
1159#endif 1130#endif
1160 /* put all nodes with same identifier into this TREE */ 1131 /* put all nodes with same identifier into this TREE */
1161 GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc); 1132 GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc);
1162 fc.id = nsn->tree_id; 1133 fc.id = nsn->tree_id;
1163 fc.nug = nug; 1134 fc.nug = nug;
1164 fc.namespace = namespace; 1135 fc.namespace = namespace;
1165 GNUNET_CONTAINER_multihashmap_get_multiple (namespace->update_map, 1136 GNUNET_CONTAINER_multihashmap_get_multiple (namespace->update_map, &hc,
1166 &hc, &find_trees, &fc); 1137 &find_trees, &fc);
1167 } 1138 }
1168 else 1139 else
1169 { 1140 {
@@ -1172,8 +1143,8 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
1172 nsn->tree_id = fc.id; 1143 nsn->tree_id = fc.id;
1173 } 1144 }
1174#if DEBUG_NAMESPACE 1145#if DEBUG_NAMESPACE
1175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TREE of node `%s' is %u\n", nsn->id,
1176 "TREE of node `%s' is %u\n", nsn->id, fc.id); 1147 fc.id);
1177#endif 1148#endif
1178 } 1149 }
1179 for (i = 0; i < fc.tree_array_size; i++) 1150 for (i = 0; i < fc.tree_array_size; i++)
@@ -1182,8 +1153,8 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
1182 if (NULL != nsn) 1153 if (NULL != nsn)
1183 { 1154 {
1184#if DEBUG_NAMESPACE 1155#if DEBUG_NAMESPACE
1185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Root of TREE %u is node `%s'\n", i,
1186 "Root of TREE %u is node `%s'\n", i, nsn->id); 1157 nsn->id);
1187#endif 1158#endif
1188 1159
1189 ip (ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update); 1160 ip (ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update);
diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c
index 87161501b..746f4f099 100644
--- a/src/fs/fs_publish.c
+++ b/src/fs/fs_publish.c
@@ -58,11 +58,10 @@ GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
58 pi->value.publish.cctx = p->client_info; 58 pi->value.publish.cctx = p->client_info;
59 pi->value.publish.pctx = (NULL == p->dir) ? NULL : p->dir->client_info; 59 pi->value.publish.pctx = (NULL == p->dir) ? NULL : p->dir->client_info;
60 pi->value.publish.filename = p->filename; 60 pi->value.publish.filename = p->filename;
61 pi->value.publish.size 61 pi->value.publish.size =
62 = (p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size; 62 (p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size;
63 pi->value.publish.eta 63 pi->value.publish.eta =
64 = GNUNET_TIME_calculate_eta (p->start_time, 64 GNUNET_TIME_calculate_eta (p->start_time, offset, pi->value.publish.size);
65 offset, pi->value.publish.size);
66 pi->value.publish.completed = offset; 65 pi->value.publish.completed = offset;
67 pi->value.publish.duration = 66 pi->value.publish.duration =
68 GNUNET_TIME_absolute_get_duration (p->start_time); 67 GNUNET_TIME_absolute_get_duration (p->start_time);
@@ -132,8 +131,8 @@ ds_put_cont (void *cls, int success, const char *msg)
132 if (GNUNET_SYSERR == pc->in_network_wait) 131 if (GNUNET_SYSERR == pc->in_network_wait)
133 { 132 {
134 /* we were aborted in the meantime, finish shutdown! */ 133 /* we were aborted in the meantime, finish shutdown! */
135 GNUNET_SCHEDULER_add_continuation (&publish_cleanup, 134 GNUNET_SCHEDULER_add_continuation (&publish_cleanup, pc,
136 pc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 135 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
137 return; 136 return;
138 } 137 }
139 GNUNET_assert (GNUNET_YES == pc->in_network_wait); 138 GNUNET_assert (GNUNET_YES == pc->in_network_wait);
@@ -155,8 +154,7 @@ ds_put_cont (void *cls, int success, const char *msg)
155 } 154 }
156 } 155 }
157 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); 156 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
158 pc->upload_task 157 pc->upload_task =
159 =
160 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, 158 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
161 &GNUNET_FS_publish_main_, pc); 159 &GNUNET_FS_publish_main_, pc);
162} 160}
@@ -179,10 +177,10 @@ signal_publish_completion (struct GNUNET_FS_FileInformation *p,
179 pi.status = GNUNET_FS_STATUS_PUBLISH_COMPLETED; 177 pi.status = GNUNET_FS_STATUS_PUBLISH_COMPLETED;
180 pi.value.publish.eta = GNUNET_TIME_UNIT_ZERO; 178 pi.value.publish.eta = GNUNET_TIME_UNIT_ZERO;
181 pi.value.publish.specifics.completed.chk_uri = p->chk_uri; 179 pi.value.publish.specifics.completed.chk_uri = p->chk_uri;
182 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 180 p->client_info =
183 GNUNET_ntohll (p-> 181 GNUNET_FS_publish_make_status_ (&pi, pc, p,
184 chk_uri->data. 182 GNUNET_ntohll (p->chk_uri->data.chk.
185 chk.file_length)); 183 file_length));
186} 184}
187 185
188 186
@@ -206,8 +204,8 @@ signal_publish_error (struct GNUNET_FS_FileInformation *p,
206 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; 204 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
207 pi.value.publish.specifics.error.message = emsg; 205 pi.value.publish.specifics.error.message = emsg;
208 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0); 206 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
209 if ((p->is_directory == GNUNET_NO) && 207 if ((p->is_directory == GNUNET_NO) && (p->filename != NULL) &&
210 (p->filename != NULL) && (p->data.file.do_index == GNUNET_YES)) 208 (p->data.file.do_index == GNUNET_YES))
211 { 209 {
212 /* run unindex to clean up */ 210 /* run unindex to clean up */
213 GNUNET_FS_unindex_start (pc->h, p->filename, NULL); 211 GNUNET_FS_unindex_start (pc->h, p->filename, NULL);
@@ -247,8 +245,8 @@ finish_release_reserve (void *cls, int success, const char *msg)
247 * @param emsg NULL on success, otherwise error message 245 * @param emsg NULL on success, otherwise error message
248 */ 246 */
249static void 247static void
250publish_sblocks_cont (void *cls, 248publish_sblocks_cont (void *cls, const struct GNUNET_FS_Uri *uri,
251 const struct GNUNET_FS_Uri *uri, const char *emsg) 249 const char *emsg)
252{ 250{
253 struct GNUNET_FS_PublishContext *pc = cls; 251 struct GNUNET_FS_PublishContext *pc = cls;
254 252
@@ -261,12 +259,10 @@ publish_sblocks_cont (void *cls,
261 GNUNET_assert (pc->qre == NULL); 259 GNUNET_assert (pc->qre == NULL);
262 if ((pc->dsh != NULL) && (pc->rid != 0)) 260 if ((pc->dsh != NULL) && (pc->rid != 0))
263 { 261 {
264 pc->qre = GNUNET_DATASTORE_release_reserve (pc->dsh, 262 pc->qre =
265 pc->rid, 263 GNUNET_DATASTORE_release_reserve (pc->dsh, pc->rid, UINT_MAX, UINT_MAX,
266 UINT_MAX, 264 GNUNET_TIME_UNIT_FOREVER_REL,
267 UINT_MAX, 265 &finish_release_reserve, pc);
268 GNUNET_TIME_UNIT_FOREVER_REL,
269 &finish_release_reserve, pc);
270 } 266 }
271 else 267 else
272 { 268 {
@@ -285,13 +281,9 @@ static void
285publish_sblock (struct GNUNET_FS_PublishContext *pc) 281publish_sblock (struct GNUNET_FS_PublishContext *pc)
286{ 282{
287 if (NULL != pc->namespace) 283 if (NULL != pc->namespace)
288 GNUNET_FS_publish_sks (pc->h, 284 GNUNET_FS_publish_sks (pc->h, pc->namespace, pc->nid, pc->nuid,
289 pc->namespace, 285 pc->fi->meta, pc->fi->chk_uri, &pc->fi->bo,
290 pc->nid, 286 pc->options, &publish_sblocks_cont, pc);
291 pc->nuid,
292 pc->fi->meta,
293 pc->fi->chk_uri,
294 &pc->fi->bo, pc->options, &publish_sblocks_cont, pc);
295 else 287 else
296 publish_sblocks_cont (pc, NULL, NULL); 288 publish_sblocks_cont (pc, NULL, NULL);
297} 289}
@@ -307,8 +299,8 @@ publish_sblock (struct GNUNET_FS_PublishContext *pc)
307 * @param emsg NULL on success, otherwise error message 299 * @param emsg NULL on success, otherwise error message
308 */ 300 */
309static void 301static void
310publish_kblocks_cont (void *cls, 302publish_kblocks_cont (void *cls, const struct GNUNET_FS_Uri *uri,
311 const struct GNUNET_FS_Uri *uri, const char *emsg) 303 const char *emsg)
312{ 304{
313 struct GNUNET_FS_PublishContext *pc = cls; 305 struct GNUNET_FS_PublishContext *pc = cls;
314 struct GNUNET_FS_FileInformation *p = pc->fi_pos; 306 struct GNUNET_FS_FileInformation *p = pc->fi_pos;
@@ -316,15 +308,14 @@ publish_kblocks_cont (void *cls,
316 if (NULL != emsg) 308 if (NULL != emsg)
317 { 309 {
318#if DEBUG_PUBLISH 310#if DEBUG_PUBLISH
319 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error uploading KSK blocks: %s\n",
320 "Error uploading KSK blocks: %s\n", emsg); 312 emsg);
321#endif 313#endif
322 signal_publish_error (p, pc, emsg); 314 signal_publish_error (p, pc, emsg);
323 GNUNET_FS_file_information_sync_ (p); 315 GNUNET_FS_file_information_sync_ (p);
324 GNUNET_FS_publish_sync_ (pc); 316 GNUNET_FS_publish_sync_ (pc);
325 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); 317 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
326 pc->upload_task 318 pc->upload_task =
327 =
328 GNUNET_SCHEDULER_add_with_priority 319 GNUNET_SCHEDULER_add_with_priority
329 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc); 320 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc);
330 return; 321 return;
@@ -342,8 +333,7 @@ publish_kblocks_cont (void *cls,
342 pc->fi_pos = p->dir; 333 pc->fi_pos = p->dir;
343 GNUNET_FS_publish_sync_ (pc); 334 GNUNET_FS_publish_sync_ (pc);
344 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); 335 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
345 pc->upload_task 336 pc->upload_task =
346 =
347 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, 337 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
348 &GNUNET_FS_publish_main_, pc); 338 &GNUNET_FS_publish_main_, pc);
349} 339}
@@ -384,8 +374,8 @@ block_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
384 return 0; /* calling reader with pt_size==0 374 return 0; /* calling reader with pt_size==0
385 * might free buf, so don't! */ 375 * might free buf, so don't! */
386 if (pt_size != 376 if (pt_size !=
387 p->data.file.reader (p->data.file.reader_cls, 377 p->data.file.reader (p->data.file.reader_cls, offset, pt_size, buf,
388 offset, pt_size, buf, emsg)) 378 emsg))
389 return 0; 379 return 0;
390 } 380 }
391 return pt_size; 381 return pt_size;
@@ -438,8 +428,7 @@ encode_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
438 428
439 /* continue with main */ 429 /* continue with main */
440 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); 430 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
441 pc->upload_task 431 pc->upload_task =
442 =
443 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, 432 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
444 &GNUNET_FS_publish_main_, pc); 433 &GNUNET_FS_publish_main_, pc);
445} 434}
@@ -460,11 +449,9 @@ encode_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
460 * @param block_size size of block (in bytes) 449 * @param block_size size of block (in bytes)
461 */ 450 */
462static void 451static void
463block_proc (void *cls, 452block_proc (void *cls, const struct ContentHashKey *chk, uint64_t offset,
464 const struct ContentHashKey *chk, 453 unsigned int depth, enum GNUNET_BLOCK_Type type, const void *block,
465 uint64_t offset, 454 uint16_t block_size)
466 unsigned int depth,
467 enum GNUNET_BLOCK_Type type, const void *block, uint16_t block_size)
468{ 455{
469 struct GNUNET_FS_PublishContext *pc = cls; 456 struct GNUNET_FS_PublishContext *pc = cls;
470 struct GNUNET_FS_FileInformation *p; 457 struct GNUNET_FS_FileInformation *p;
@@ -477,8 +464,7 @@ block_proc (void *cls,
477 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Waiting for datastore connection\n"); 464 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Waiting for datastore connection\n");
478#endif 465#endif
479 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); 466 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
480 pc->upload_task 467 pc->upload_task =
481 =
482 GNUNET_SCHEDULER_add_with_priority 468 GNUNET_SCHEDULER_add_with_priority
483 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc); 469 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc);
484 return; 470 return;
@@ -486,54 +472,42 @@ block_proc (void *cls,
486 472
487 GNUNET_assert (GNUNET_NO == pc->in_network_wait); 473 GNUNET_assert (GNUNET_NO == pc->in_network_wait);
488 pc->in_network_wait = GNUNET_YES; 474 pc->in_network_wait = GNUNET_YES;
489 if ((!p->is_directory) && 475 if ((!p->is_directory) && (GNUNET_YES == p->data.file.do_index) &&
490 (GNUNET_YES == p->data.file.do_index) &&
491 (type == GNUNET_BLOCK_TYPE_FS_DBLOCK)) 476 (type == GNUNET_BLOCK_TYPE_FS_DBLOCK))
492 { 477 {
493#if DEBUG_PUBLISH 478#if DEBUG_PUBLISH
494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 479 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
495 "Indexing block `%s' for offset %llu with index size %u\n", 480 "Indexing block `%s' for offset %llu with index size %u\n",
496 GNUNET_h2s (&chk->query), 481 GNUNET_h2s (&chk->query), (unsigned long long) offset,
497 (unsigned long long) offset, sizeof (struct OnDemandBlock)); 482 sizeof (struct OnDemandBlock));
498#endif 483#endif
499 odb.offset = GNUNET_htonll (offset); 484 odb.offset = GNUNET_htonll (offset);
500 odb.file_id = p->data.file.file_id; 485 odb.file_id = p->data.file.file_id;
501 GNUNET_assert (pc->qre == NULL); 486 GNUNET_assert (pc->qre == NULL);
502 pc->qre = GNUNET_DATASTORE_put (pc->dsh, 487 pc->qre =
503 (p->is_directory) ? 0 : pc->rid, 488 GNUNET_DATASTORE_put (pc->dsh, (p->is_directory) ? 0 : pc->rid,
504 &chk->query, 489 &chk->query, sizeof (struct OnDemandBlock), &odb,
505 sizeof (struct OnDemandBlock), 490 GNUNET_BLOCK_TYPE_FS_ONDEMAND,
506 &odb, 491 p->bo.content_priority, p->bo.anonymity_level,
507 GNUNET_BLOCK_TYPE_FS_ONDEMAND, 492 p->bo.replication_level, p->bo.expiration_time,
508 p->bo.content_priority, 493 -2, 1, GNUNET_CONSTANTS_SERVICE_TIMEOUT,
509 p->bo.anonymity_level, 494 &ds_put_cont, pc);
510 p->bo.replication_level,
511 p->bo.expiration_time,
512 -2, 1,
513 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
514 &ds_put_cont, pc);
515 return; 495 return;
516 } 496 }
517#if DEBUG_PUBLISH 497#if DEBUG_PUBLISH
518 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 498 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
519 "Publishing block `%s' for offset %llu with size %u\n", 499 "Publishing block `%s' for offset %llu with size %u\n",
520 GNUNET_h2s (&chk->query), 500 GNUNET_h2s (&chk->query), (unsigned long long) offset,
521 (unsigned long long) offset, (unsigned int) block_size); 501 (unsigned int) block_size);
522#endif 502#endif
523 GNUNET_assert (pc->qre == NULL); 503 GNUNET_assert (pc->qre == NULL);
524 pc->qre = GNUNET_DATASTORE_put (pc->dsh, 504 pc->qre =
525 (p->is_directory) ? 0 : pc->rid, 505 GNUNET_DATASTORE_put (pc->dsh, (p->is_directory) ? 0 : pc->rid,
526 &chk->query, 506 &chk->query, block_size, block, type,
527 block_size, 507 p->bo.content_priority, p->bo.anonymity_level,
528 block, 508 p->bo.replication_level, p->bo.expiration_time, -2,
529 type, 509 1, GNUNET_CONSTANTS_SERVICE_TIMEOUT, &ds_put_cont,
530 p->bo.content_priority, 510 pc);
531 p->bo.anonymity_level,
532 p->bo.replication_level,
533 p->bo.expiration_time,
534 -2, 1,
535 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
536 &ds_put_cont, pc);
537} 511}
538 512
539 513
@@ -548,9 +522,8 @@ block_proc (void *cls,
548 * @param depth depth of the block in the tree, 0 for DBLOCK 522 * @param depth depth of the block in the tree, 0 for DBLOCK
549 */ 523 */
550static void 524static void
551progress_proc (void *cls, 525progress_proc (void *cls, uint64_t offset, const void *pt_block, size_t pt_size,
552 uint64_t offset, 526 unsigned int depth)
553 const void *pt_block, size_t pt_size, unsigned int depth)
554{ 527{
555 struct GNUNET_FS_PublishContext *pc = cls; 528 struct GNUNET_FS_PublishContext *pc = cls;
556 struct GNUNET_FS_FileInformation *p; 529 struct GNUNET_FS_FileInformation *p;
@@ -610,10 +583,9 @@ publish_content (struct GNUNET_FS_PublishContext *pc)
610 raw_data = GNUNET_malloc (dirpos->data.file.file_size); 583 raw_data = GNUNET_malloc (dirpos->data.file.file_size);
611 emsg = NULL; 584 emsg = NULL;
612 if (dirpos->data.file.file_size != 585 if (dirpos->data.file.file_size !=
613 dirpos->data.file.reader (dirpos->data.file.reader_cls, 586 dirpos->data.file.reader (dirpos->data.file.reader_cls, 0,
614 0, 587 dirpos->data.file.file_size, raw_data,
615 dirpos->data.file.file_size, 588 &emsg))
616 raw_data, &emsg))
617 { 589 {
618 GNUNET_free_non_null (emsg); 590 GNUNET_free_non_null (emsg);
619 GNUNET_free (raw_data); 591 GNUNET_free (raw_data);
@@ -621,17 +593,15 @@ publish_content (struct GNUNET_FS_PublishContext *pc)
621 } 593 }
622 } 594 }
623 } 595 }
624 GNUNET_FS_directory_builder_add (db, 596 GNUNET_FS_directory_builder_add (db, dirpos->chk_uri, dirpos->meta,
625 dirpos->chk_uri, 597 raw_data);
626 dirpos->meta, raw_data);
627 GNUNET_free_non_null (raw_data); 598 GNUNET_free_non_null (raw_data);
628 dirpos = dirpos->next; 599 dirpos = dirpos->next;
629 } 600 }
630 GNUNET_free_non_null (p->data.dir.dir_data); 601 GNUNET_free_non_null (p->data.dir.dir_data);
631 p->data.dir.dir_data = NULL; 602 p->data.dir.dir_data = NULL;
632 p->data.dir.dir_size = 0; 603 p->data.dir.dir_size = 0;
633 GNUNET_FS_directory_builder_finish (db, 604 GNUNET_FS_directory_builder_finish (db, &p->data.dir.dir_size,
634 &p->data.dir.dir_size,
635 &p->data.dir.dir_data); 605 &p->data.dir.dir_data);
636 GNUNET_FS_file_information_sync_ (p); 606 GNUNET_FS_file_information_sync_ (p);
637 } 607 }
@@ -639,12 +609,10 @@ publish_content (struct GNUNET_FS_PublishContext *pc)
639#if DEBUG_PUBLISH 609#if DEBUG_PUBLISH
640 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating tree encoder\n"); 610 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating tree encoder\n");
641#endif 611#endif
642 p->te = GNUNET_FS_tree_encoder_create (pc->h, 612 p->te =
643 size, 613 GNUNET_FS_tree_encoder_create (pc->h, size, pc, &block_reader,
644 pc, 614 &block_proc, &progress_proc,
645 &block_reader, 615 &encode_cont);
646 &block_proc,
647 &progress_proc, &encode_cont);
648 616
649 } 617 }
650#if DEBUG_PUBLISH 618#if DEBUG_PUBLISH
@@ -761,8 +729,7 @@ hash_for_index_cb (void *cls, const GNUNET_HashCode * res)
761 return; 729 return;
762 } 730 }
763#if DEBUG_PUBLISH 731#if DEBUG_PUBLISH
764 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 732 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hash of indexed file `%s' is `%s'\n",
765 "Hash of indexed file `%s' is `%s'\n",
766 p->filename, GNUNET_h2s (res)); 733 p->filename, GNUNET_h2s (res));
767#endif 734#endif
768 if (0 != (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) 735 if (0 != (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
@@ -813,8 +780,7 @@ hash_for_index_cb (void *cls, const GNUNET_HashCode * res)
813 GNUNET_free (fn); 780 GNUNET_free (fn);
814 pc->client = client; 781 pc->client = client;
815 GNUNET_break (GNUNET_YES == 782 GNUNET_break (GNUNET_YES ==
816 GNUNET_CLIENT_transmit_and_get_response (client, 783 GNUNET_CLIENT_transmit_and_get_response (client, &ism->header,
817 &ism->header,
818 GNUNET_TIME_UNIT_FOREVER_REL, 784 GNUNET_TIME_UNIT_FOREVER_REL,
819 GNUNET_YES, 785 GNUNET_YES,
820 &process_index_start_response, 786 &process_index_start_response,
@@ -854,9 +820,8 @@ GNUNET_FS_publish_main_ (void *cls,
854 return; 820 return;
855 } 821 }
856 /* find starting position */ 822 /* find starting position */
857 while ((p->is_directory) && 823 while ((p->is_directory) && (NULL != p->data.dir.entries) && (NULL == p->emsg)
858 (NULL != p->data.dir.entries) && 824 && (NULL == p->data.dir.entries->chk_uri))
859 (NULL == p->emsg) && (NULL == p->data.dir.entries->chk_uri))
860 { 825 {
861 p = p->data.dir.entries; 826 p = p->data.dir.entries;
862 pc->fi_pos = p; 827 pc->fi_pos = p;
@@ -877,8 +842,8 @@ GNUNET_FS_publish_main_ (void *cls,
877 p = p->dir; 842 p = p->dir;
878 if (fn != NULL) 843 if (fn != NULL)
879 { 844 {
880 GNUNET_asprintf (&p->emsg, 845 GNUNET_asprintf (&p->emsg, _("Recursive upload failed at `%s': %s"), fn,
881 _("Recursive upload failed at `%s': %s"), fn, p->emsg); 846 p->emsg);
882 GNUNET_free (fn); 847 GNUNET_free (fn);
883 } 848 }
884 else 849 else
@@ -904,8 +869,9 @@ GNUNET_FS_publish_main_ (void *cls,
904 if (0 == p->bo.anonymity_level) 869 if (0 == p->bo.anonymity_level)
905 { 870 {
906 /* zero anonymity, box CHK URI in LOC URI */ 871 /* zero anonymity, box CHK URI in LOC URI */
907 loc = GNUNET_FS_uri_loc_create (p->chk_uri, 872 loc =
908 pc->h->cfg, p->bo.expiration_time); 873 GNUNET_FS_uri_loc_create (p->chk_uri, pc->h->cfg,
874 p->bo.expiration_time);
909 GNUNET_FS_uri_destroy (p->chk_uri); 875 GNUNET_FS_uri_destroy (p->chk_uri);
910 p->chk_uri = loc; 876 p->chk_uri = loc;
911 } 877 }
@@ -913,11 +879,8 @@ GNUNET_FS_publish_main_ (void *cls,
913 /* upload of "p" complete, publish KBlocks! */ 879 /* upload of "p" complete, publish KBlocks! */
914 if (p->keywords != NULL) 880 if (p->keywords != NULL)
915 { 881 {
916 GNUNET_FS_publish_ksk (pc->h, 882 GNUNET_FS_publish_ksk (pc->h, p->keywords, p->meta, p->chk_uri, &p->bo,
917 p->keywords, 883 pc->options, &publish_kblocks_cont, pc);
918 p->meta,
919 p->chk_uri,
920 &p->bo, pc->options, &publish_kblocks_cont, pc);
921 } 884 }
922 else 885 else
923 { 886 {
@@ -945,10 +908,9 @@ GNUNET_FS_publish_main_ (void *cls,
945 else 908 else
946 { 909 {
947 p->start_time = GNUNET_TIME_absolute_get (); 910 p->start_time = GNUNET_TIME_absolute_get ();
948 pc->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, 911 pc->fhc =
949 p->filename, 912 GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, p->filename,
950 HASHING_BLOCKSIZE, 913 HASHING_BLOCKSIZE, &hash_for_index_cb, pc);
951 &hash_for_index_cb, pc);
952 } 914 }
953 return; 915 return;
954 } 916 }
@@ -971,12 +933,9 @@ GNUNET_FS_publish_main_ (void *cls,
971 * @return GNUNET_OK to continue (always) 933 * @return GNUNET_OK to continue (always)
972 */ 934 */
973static int 935static int
974fip_signal_start (void *cls, 936fip_signal_start (void *cls, struct GNUNET_FS_FileInformation *fi,
975 struct GNUNET_FS_FileInformation *fi, 937 uint64_t length, struct GNUNET_CONTAINER_MetaData *meta,
976 uint64_t length, 938 struct GNUNET_FS_Uri **uri, struct GNUNET_FS_BlockOptions *bo,
977 struct GNUNET_CONTAINER_MetaData *meta,
978 struct GNUNET_FS_Uri **uri,
979 struct GNUNET_FS_BlockOptions *bo,
980 int *do_index, void **client_info) 939 int *do_index, void **client_info)
981{ 940{
982 struct GNUNET_FS_PublishContext *pc = cls; 941 struct GNUNET_FS_PublishContext *pc = cls;
@@ -1040,13 +999,11 @@ fip_signal_start (void *cls,
1040 * @return GNUNET_OK to continue (always) 999 * @return GNUNET_OK to continue (always)
1041 */ 1000 */
1042static int 1001static int
1043fip_signal_suspend (void *cls, 1002fip_signal_suspend (void *cls, struct GNUNET_FS_FileInformation *fi,
1044 struct GNUNET_FS_FileInformation *fi, 1003 uint64_t length, struct GNUNET_CONTAINER_MetaData *meta,
1045 uint64_t length,
1046 struct GNUNET_CONTAINER_MetaData *meta,
1047 struct GNUNET_FS_Uri **uri, 1004 struct GNUNET_FS_Uri **uri,
1048 struct GNUNET_FS_BlockOptions *bo, 1005 struct GNUNET_FS_BlockOptions *bo, int *do_index,
1049 int *do_index, void **client_info) 1006 void **client_info)
1050{ 1007{
1051 struct GNUNET_FS_PublishContext *pc = cls; 1008 struct GNUNET_FS_PublishContext *pc = cls;
1052 struct GNUNET_FS_ProgressInfo pi; 1009 struct GNUNET_FS_ProgressInfo pi;
@@ -1118,15 +1075,14 @@ finish_reserve (void *cls, int success, const char *msg)
1118#endif 1075#endif
1119 if ((msg != NULL) || (success <= 0)) 1076 if ((msg != NULL) || (success <= 0))
1120 { 1077 {
1121 GNUNET_asprintf (&pc->fi->emsg, 1078 GNUNET_asprintf (&pc->fi->emsg, _("Insufficient space for publishing: %s"),
1122 _("Insufficient space for publishing: %s"), msg); 1079 msg);
1123 signal_publish_error (pc->fi, pc, pc->fi->emsg); 1080 signal_publish_error (pc->fi, pc, pc->fi->emsg);
1124 return; 1081 return;
1125 } 1082 }
1126 pc->rid = success; 1083 pc->rid = success;
1127 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); 1084 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
1128 pc->upload_task 1085 pc->upload_task =
1129 =
1130 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, 1086 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
1131 &GNUNET_FS_publish_main_, pc); 1087 &GNUNET_FS_publish_main_, pc);
1132} 1088}
@@ -1148,8 +1104,7 @@ finish_reserve (void *cls, int success, const char *msg)
1148struct GNUNET_FS_PublishContext * 1104struct GNUNET_FS_PublishContext *
1149GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h, 1105GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1150 struct GNUNET_FS_FileInformation *fi, 1106 struct GNUNET_FS_FileInformation *fi,
1151 struct GNUNET_FS_Namespace *namespace, 1107 struct GNUNET_FS_Namespace *namespace, const char *nid,
1152 const char *nid,
1153 const char *nuid, 1108 const char *nuid,
1154 enum GNUNET_FS_PublishOptions options) 1109 enum GNUNET_FS_PublishOptions options)
1155{ 1110{
@@ -1203,8 +1158,7 @@ GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1203 else 1158 else
1204 { 1159 {
1205 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == ret->upload_task); 1160 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == ret->upload_task);
1206 ret->upload_task 1161 ret->upload_task =
1207 =
1208 GNUNET_SCHEDULER_add_with_priority 1162 GNUNET_SCHEDULER_add_with_priority
1209 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, ret); 1163 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, ret);
1210 } 1164 }
@@ -1227,12 +1181,9 @@ GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1227 * @return GNUNET_OK to continue (always) 1181 * @return GNUNET_OK to continue (always)
1228 */ 1182 */
1229static int 1183static int
1230fip_signal_stop (void *cls, 1184fip_signal_stop (void *cls, struct GNUNET_FS_FileInformation *fi,
1231 struct GNUNET_FS_FileInformation *fi, 1185 uint64_t length, struct GNUNET_CONTAINER_MetaData *meta,
1232 uint64_t length, 1186 struct GNUNET_FS_Uri **uri, struct GNUNET_FS_BlockOptions *bo,
1233 struct GNUNET_CONTAINER_MetaData *meta,
1234 struct GNUNET_FS_Uri **uri,
1235 struct GNUNET_FS_BlockOptions *bo,
1236 int *do_index, void **client_info) 1187 int *do_index, void **client_info)
1237{ 1188{
1238 struct GNUNET_FS_PublishContext *pc = cls; 1189 struct GNUNET_FS_PublishContext *pc = cls;
@@ -1241,8 +1192,7 @@ fip_signal_stop (void *cls,
1241 1192
1242 if (fi->serialization != NULL) 1193 if (fi->serialization != NULL)
1243 { 1194 {
1244 GNUNET_FS_remove_sync_file_ (pc->h, 1195 GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_FILE_INFO,
1245 GNUNET_FS_SYNC_PATH_FILE_INFO,
1246 fi->serialization); 1196 fi->serialization);
1247 GNUNET_free (fi->serialization); 1197 GNUNET_free (fi->serialization);
1248 fi->serialization = NULL; 1198 fi->serialization = NULL;
@@ -1383,8 +1333,8 @@ struct PublishKskContext
1383 * @param cls closure of type "struct PublishKskContext*" 1333 * @param cls closure of type "struct PublishKskContext*"
1384 * @param tc unused 1334 * @param tc unused
1385 */ 1335 */
1386static void 1336static void publish_ksk_cont (void *cls,
1387publish_ksk_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 1337 const struct GNUNET_SCHEDULER_TaskContext *tc);
1388 1338
1389 1339
1390/** 1340/**
@@ -1418,8 +1368,8 @@ kb_put_cont (void *cls, int success, const char *msg)
1418 GNUNET_free (pkc); 1368 GNUNET_free (pkc);
1419 return; 1369 return;
1420 } 1370 }
1421 GNUNET_SCHEDULER_add_continuation (&publish_ksk_cont, 1371 GNUNET_SCHEDULER_add_continuation (&publish_ksk_cont, pkc,
1422 pkc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 1372 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1423} 1373}
1424 1374
1425 1375
@@ -1461,15 +1411,15 @@ publish_ksk_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1461 } 1411 }
1462 keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++]; 1412 keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++];
1463#if DEBUG_PUBLISH 1413#if DEBUG_PUBLISH
1464 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1414 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing under keyword `%s'\n",
1465 "Publishing under keyword `%s'\n", keyword); 1415 keyword);
1466#endif 1416#endif
1467 /* first character of keyword indicates if it is 1417 /* first character of keyword indicates if it is
1468 * mandatory or not -- ignore for hashing */ 1418 * mandatory or not -- ignore for hashing */
1469 GNUNET_CRYPTO_hash (&keyword[1], strlen (&keyword[1]), &key); 1419 GNUNET_CRYPTO_hash (&keyword[1], strlen (&keyword[1]), &key);
1470 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv); 1420 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv);
1471 GNUNET_CRYPTO_aes_encrypt (&pkc->kb[1], 1421 GNUNET_CRYPTO_aes_encrypt (&pkc->kb[1], pkc->slen + pkc->mdsize, &skey, &iv,
1472 pkc->slen + pkc->mdsize, &skey, &iv, &pkc->cpy[1]); 1422 &pkc->cpy[1]);
1473 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&key); 1423 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&key);
1474 GNUNET_assert (NULL != pk); 1424 GNUNET_assert (NULL != pk);
1475 GNUNET_CRYPTO_rsa_key_get_public (pk, &pkc->cpy->keyspace); 1425 GNUNET_CRYPTO_rsa_key_get_public (pk, &pkc->cpy->keyspace);
@@ -1477,25 +1427,17 @@ publish_ksk_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1477 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 1427 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1478 &query); 1428 &query);
1479 GNUNET_assert (GNUNET_OK == 1429 GNUNET_assert (GNUNET_OK ==
1480 GNUNET_CRYPTO_rsa_sign (pk, 1430 GNUNET_CRYPTO_rsa_sign (pk, &pkc->cpy->purpose,
1481 &pkc->cpy->purpose,
1482 &pkc->cpy->signature)); 1431 &pkc->cpy->signature));
1483 GNUNET_CRYPTO_rsa_key_free (pk); 1432 GNUNET_CRYPTO_rsa_key_free (pk);
1484 pkc->qre = GNUNET_DATASTORE_put (pkc->dsh, 1433 pkc->qre =
1485 0, 1434 GNUNET_DATASTORE_put (pkc->dsh, 0, &query,
1486 &query, 1435 pkc->mdsize + sizeof (struct KBlock) + pkc->slen,
1487 pkc->mdsize + 1436 pkc->cpy, GNUNET_BLOCK_TYPE_FS_KBLOCK,
1488 sizeof (struct KBlock) + 1437 pkc->bo.content_priority, pkc->bo.anonymity_level,
1489 pkc->slen, 1438 pkc->bo.replication_level, pkc->bo.expiration_time,
1490 pkc->cpy, 1439 -2, 1, GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1491 GNUNET_BLOCK_TYPE_FS_KBLOCK, 1440 &kb_put_cont, pkc);
1492 pkc->bo.content_priority,
1493 pkc->bo.anonymity_level,
1494 pkc->bo.replication_level,
1495 pkc->bo.expiration_time,
1496 -2, 1,
1497 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1498 &kb_put_cont, pkc);
1499} 1441}
1500 1442
1501 1443
@@ -1561,10 +1503,9 @@ GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
1561 GNUNET_free (uris); 1503 GNUNET_free (uris);
1562 sptr = &kbe[pkc->slen]; 1504 sptr = &kbe[pkc->slen];
1563 if (meta != NULL) 1505 if (meta != NULL)
1564 pkc->mdsize = GNUNET_CONTAINER_meta_data_serialize (meta, 1506 pkc->mdsize =
1565 &sptr, 1507 GNUNET_CONTAINER_meta_data_serialize (meta, &sptr, pkc->mdsize,
1566 pkc->mdsize, 1508 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
1567 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
1568 if (pkc->mdsize == -1) 1509 if (pkc->mdsize == -1)
1569 { 1510 {
1570 GNUNET_break (0); 1511 GNUNET_break (0);
@@ -1587,8 +1528,8 @@ GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
1587 pkc->mdsize + pkc->slen); 1528 pkc->mdsize + pkc->slen);
1588 pkc->cpy->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK); 1529 pkc->cpy->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK);
1589 pkc->ksk_uri = GNUNET_FS_uri_dup (ksk_uri); 1530 pkc->ksk_uri = GNUNET_FS_uri_dup (ksk_uri);
1590 GNUNET_SCHEDULER_add_continuation (&publish_ksk_cont, 1531 GNUNET_SCHEDULER_add_continuation (&publish_ksk_cont, pkc,
1591 pkc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 1532 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1592} 1533}
1593 1534
1594 1535
diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c
index 60b7a1cc8..89a8c5582 100644
--- a/src/fs/fs_search.c
+++ b/src/fs/fs_search.c
@@ -48,8 +48,8 @@ GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
48 48
49 pi->value.search.sc = sc; 49 pi->value.search.sc = sc;
50 pi->value.search.cctx = sc->client_info; 50 pi->value.search.cctx = sc->client_info;
51 pi->value.search.pctx 51 pi->value.search.pctx =
52 = (sc->psearch_result == NULL) ? NULL : sc->psearch_result->client_info; 52 (sc->psearch_result == NULL) ? NULL : sc->psearch_result->client_info;
53 pi->value.search.query = sc->uri; 53 pi->value.search.query = sc->uri;
54 pi->value.search.duration = 54 pi->value.search.duration =
55 GNUNET_TIME_absolute_get_duration (sc->start_time); 55 GNUNET_TIME_absolute_get_duration (sc->start_time);
@@ -121,10 +121,10 @@ notify_client_chk_update (struct GNUNET_FS_SearchContext *sc,
121 pi.value.search.specifics.update.cctx = sr->client_info; 121 pi.value.search.specifics.update.cctx = sr->client_info;
122 pi.value.search.specifics.update.meta = sr->meta; 122 pi.value.search.specifics.update.meta = sr->meta;
123 pi.value.search.specifics.update.uri = sr->uri; 123 pi.value.search.specifics.update.uri = sr->uri;
124 pi.value.search.specifics.update.availability_rank 124 pi.value.search.specifics.update.availability_rank =
125 = 2 * sr->availability_success - sr->availability_trials; 125 2 * sr->availability_success - sr->availability_trials;
126 pi.value.search.specifics.update.availability_certainty 126 pi.value.search.specifics.update.availability_certainty =
127 = sr->availability_trials; 127 sr->availability_trials;
128 pi.value.search.specifics.update.applicability_rank = sr->optional_support; 128 pi.value.search.specifics.update.applicability_rank = sr->optional_support;
129 sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc); 129 sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
130} 130}
@@ -386,16 +386,15 @@ process_ksk_result (struct GNUNET_FS_SearchContext *sc,
386 /* check if new */ 386 /* check if new */
387 GNUNET_FS_uri_to_key (uri, &key); 387 GNUNET_FS_uri_to_key (uri, &key);
388 if (GNUNET_SYSERR == 388 if (GNUNET_SYSERR ==
389 GNUNET_CONTAINER_multihashmap_get_multiple (ent->results, 389 GNUNET_CONTAINER_multihashmap_get_multiple (ent->results, &key,
390 &key,
391 &test_result_present, 390 &test_result_present,
392 (void *) uri)) 391 (void *) uri))
393 return; /* duplicate result */ 392 return; /* duplicate result */
394 /* try to find search result in master map */ 393 /* try to find search result in master map */
395 grc.sr = NULL; 394 grc.sr = NULL;
396 grc.uri = uri; 395 grc.uri = uri;
397 GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map, 396 GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map, &key,
398 &key, &get_result_present, &grc); 397 &get_result_present, &grc);
399 sr = grc.sr; 398 sr = grc.sr;
400 is_new = (NULL == sr) || (sr->mandatory_missing > 0); 399 is_new = (NULL == sr) || (sr->mandatory_missing > 0);
401 if (NULL == sr) 400 if (NULL == sr)
@@ -406,9 +405,7 @@ process_ksk_result (struct GNUNET_FS_SearchContext *sc,
406 sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); 405 sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
407 sr->mandatory_missing = sc->mandatory_count; 406 sr->mandatory_missing = sc->mandatory_count;
408 sr->key = key; 407 sr->key = key;
409 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, 408 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, &key, sr,
410 &key,
411 sr,
412 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 409 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
413 } 410 }
414 else 411 else
@@ -464,8 +461,7 @@ static struct GNUNET_FS_SearchContext *search_start (struct GNUNET_FS_Handle *h,
464 * @param meta metadata associated with the URI 461 * @param meta metadata associated with the URI
465 */ 462 */
466static void 463static void
467process_sks_result (struct GNUNET_FS_SearchContext *sc, 464process_sks_result (struct GNUNET_FS_SearchContext *sc, const char *id_update,
468 const char *id_update,
469 const struct GNUNET_FS_Uri *uri, 465 const struct GNUNET_FS_Uri *uri,
470 const struct GNUNET_CONTAINER_MetaData *meta) 466 const struct GNUNET_CONTAINER_MetaData *meta)
471{ 467{
@@ -475,11 +471,10 @@ process_sks_result (struct GNUNET_FS_SearchContext *sc,
475 471
476 /* check if new */ 472 /* check if new */
477 GNUNET_FS_uri_to_key (uri, &key); 473 GNUNET_FS_uri_to_key (uri, &key);
478 GNUNET_CRYPTO_hash_xor (&uri->data.chk.chk.key, 474 GNUNET_CRYPTO_hash_xor (&uri->data.chk.chk.key, &uri->data.chk.chk.query,
479 &uri->data.chk.chk.query, &key); 475 &key);
480 if (GNUNET_SYSERR == 476 if (GNUNET_SYSERR ==
481 GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map, 477 GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map, &key,
482 &key,
483 &test_result_present, 478 &test_result_present,
484 (void *) uri)) 479 (void *) uri))
485 return; /* duplicate result */ 480 return; /* duplicate result */
@@ -488,9 +483,7 @@ process_sks_result (struct GNUNET_FS_SearchContext *sc,
488 sr->uri = GNUNET_FS_uri_dup (uri); 483 sr->uri = GNUNET_FS_uri_dup (uri);
489 sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); 484 sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
490 sr->key = key; 485 sr->key = key;
491 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, 486 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, &key, sr,
492 &key,
493 sr,
494 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 487 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
495 GNUNET_FS_search_result_sync_ (sr); 488 GNUNET_FS_search_result_sync_ (sr);
496 GNUNET_FS_search_start_probe_ (sr); 489 GNUNET_FS_search_start_probe_ (sr);
@@ -515,8 +508,8 @@ process_sks_result (struct GNUNET_FS_SearchContext *sc,
515 * @param size size of kb 508 * @param size size of kb
516 */ 509 */
517static void 510static void
518process_kblock (struct GNUNET_FS_SearchContext *sc, 511process_kblock (struct GNUNET_FS_SearchContext *sc, const struct KBlock *kb,
519 const struct KBlock *kb, size_t size) 512 size_t size)
520{ 513{
521 unsigned int i; 514 unsigned int i;
522 size_t j; 515 size_t j;
@@ -544,9 +537,9 @@ process_kblock (struct GNUNET_FS_SearchContext *sc,
544 } 537 }
545 /* decrypt */ 538 /* decrypt */
546 GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].key, &skey, &iv); 539 GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].key, &skey, &iv);
547 if (-1 == GNUNET_CRYPTO_aes_decrypt (&kb[1], 540 if (-1 ==
548 size - sizeof (struct KBlock), 541 GNUNET_CRYPTO_aes_decrypt (&kb[1], size - sizeof (struct KBlock), &skey,
549 &skey, &iv, pt)) 542 &iv, pt))
550 { 543 {
551 GNUNET_break (0); 544 GNUNET_break (0);
552 return; 545 return;
@@ -593,8 +586,8 @@ process_kblock (struct GNUNET_FS_SearchContext *sc,
593 * @param size size of nb 586 * @param size size of nb
594 */ 587 */
595static void 588static void
596process_nblock (struct GNUNET_FS_SearchContext *sc, 589process_nblock (struct GNUNET_FS_SearchContext *sc, const struct NBlock *nb,
597 const struct NBlock *nb, size_t size) 590 size_t size)
598{ 591{
599 unsigned int i; 592 unsigned int i;
600 size_t j; 593 size_t j;
@@ -622,9 +615,9 @@ process_nblock (struct GNUNET_FS_SearchContext *sc,
622 } 615 }
623 /* decrypt */ 616 /* decrypt */
624 GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].key, &skey, &iv); 617 GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].key, &skey, &iv);
625 if (-1 == GNUNET_CRYPTO_aes_decrypt (&nb[1], 618 if (-1 ==
626 size - sizeof (struct NBlock), 619 GNUNET_CRYPTO_aes_decrypt (&nb[1], size - sizeof (struct NBlock), &skey,
627 &skey, &iv, pt)) 620 &iv, pt))
628 { 621 {
629 GNUNET_break (0); 622 GNUNET_break (0);
630 return; 623 return;
@@ -654,11 +647,9 @@ process_nblock (struct GNUNET_FS_SearchContext *sc,
654 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 647 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
655 &uri->data.sks.namespace); 648 &uri->data.sks.namespace);
656 uris = GNUNET_FS_uri_to_string (uri); 649 uris = GNUNET_FS_uri_to_string (uri);
657 GNUNET_CONTAINER_meta_data_insert (meta, 650 GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet>", EXTRACTOR_METATYPE_URI,
658 "<gnunet>", 651 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
659 EXTRACTOR_METATYPE_URI, 652 uris, strlen (uris) + 1);
660 EXTRACTOR_METAFORMAT_UTF8,
661 "text/plain", uris, strlen (uris) + 1);
662 GNUNET_free (uris); 653 GNUNET_free (uris);
663 GNUNET_PSEUDONYM_add (sc->h->cfg, &uri->data.sks.namespace, meta); 654 GNUNET_PSEUDONYM_add (sc->h->cfg, &uri->data.sks.namespace, meta);
664 /* process */ 655 /* process */
@@ -678,8 +669,8 @@ process_nblock (struct GNUNET_FS_SearchContext *sc,
678 * @param size size of sb 669 * @param size size of sb
679 */ 670 */
680static void 671static void
681process_sblock (struct GNUNET_FS_SearchContext *sc, 672process_sblock (struct GNUNET_FS_SearchContext *sc, const struct SBlock *sb,
682 const struct SBlock *sb, size_t size) 673 size_t size)
683{ 674{
684 size_t len = size - sizeof (struct SBlock); 675 size_t len = size - sizeof (struct SBlock);
685 char pt[len]; 676 char pt[len];
@@ -719,8 +710,8 @@ process_sblock (struct GNUNET_FS_SearchContext *sc,
719 uri = GNUNET_FS_uri_parse (uris, &emsg); 710 uri = GNUNET_FS_uri_parse (uris, &emsg);
720 if (uri == NULL) 711 if (uri == NULL)
721 { 712 {
722 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 713 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to parse URI `%s': %s\n", uris,
723 "Failed to parse URI `%s': %s\n", uris, emsg); 714 emsg);
724 GNUNET_break_op (0); /* sblock malformed */ 715 GNUNET_break_op (0); /* sblock malformed */
725 GNUNET_free_non_null (emsg); 716 GNUNET_free_non_null (emsg);
726 GNUNET_CONTAINER_meta_data_destroy (meta); 717 GNUNET_CONTAINER_meta_data_destroy (meta);
@@ -744,10 +735,9 @@ process_sblock (struct GNUNET_FS_SearchContext *sc,
744 * @param size size of data 735 * @param size size of data
745 */ 736 */
746static void 737static void
747process_result (struct GNUNET_FS_SearchContext *sc, 738process_result (struct GNUNET_FS_SearchContext *sc, enum GNUNET_BLOCK_Type type,
748 enum GNUNET_BLOCK_Type type, 739 struct GNUNET_TIME_Absolute expiration, const void *data,
749 struct GNUNET_TIME_Absolute expiration, 740 size_t size)
750 const void *data, size_t size)
751{ 741{
752 if (GNUNET_TIME_absolute_get_duration (expiration).rel_value > 0) 742 if (GNUNET_TIME_absolute_get_duration (expiration).rel_value > 0)
753 { 743 {
@@ -840,8 +830,7 @@ receive_results (void *cls, const struct GNUNET_MessageHeader *msg)
840 const struct PutMessage *cm; 830 const struct PutMessage *cm;
841 uint16_t msize; 831 uint16_t msize;
842 832
843 if ((NULL == msg) || 833 if ((NULL == msg) || (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_PUT) ||
844 (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_PUT) ||
845 (ntohs (msg->size) <= sizeof (struct PutMessage))) 834 (ntohs (msg->size) <= sizeof (struct PutMessage)))
846 { 835 {
847 try_reconnect (sc); 836 try_reconnect (sc);
@@ -851,13 +840,12 @@ receive_results (void *cls, const struct GNUNET_MessageHeader *msg)
851 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 840 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
852 "Receiving %u bytes of result from fs service\n", msize); 841 "Receiving %u bytes of result from fs service\n", msize);
853 cm = (const struct PutMessage *) msg; 842 cm = (const struct PutMessage *) msg;
854 process_result (sc, 843 process_result (sc, ntohl (cm->type),
855 ntohl (cm->type), 844 GNUNET_TIME_absolute_ntoh (cm->expiration), &cm[1],
856 GNUNET_TIME_absolute_ntoh (cm->expiration), 845 msize - sizeof (struct PutMessage));
857 &cm[1], msize - sizeof (struct PutMessage));
858 /* continue receiving */ 846 /* continue receiving */
859 GNUNET_CLIENT_receive (sc->client, 847 GNUNET_CLIENT_receive (sc->client, &receive_results, sc,
860 &receive_results, sc, GNUNET_TIME_UNIT_FOREVER_REL); 848 GNUNET_TIME_UNIT_FOREVER_REL);
861} 849}
862 850
863 851
@@ -867,8 +855,8 @@ receive_results (void *cls, const struct GNUNET_MessageHeader *msg)
867 * 855 *
868 * @param sc context for the search 856 * @param sc context for the search
869 */ 857 */
870static void 858static void schedule_transmit_search_request (struct GNUNET_FS_SearchContext
871schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc); 859 *sc);
872 860
873 861
874/** 862/**
@@ -1064,8 +1052,8 @@ transmit_search_request (void *cls, size_t size, void *buf)
1064 return msize; 1052 return msize;
1065 } 1053 }
1066 } 1054 }
1067 GNUNET_CLIENT_receive (sc->client, 1055 GNUNET_CLIENT_receive (sc->client, &receive_results, sc,
1068 &receive_results, sc, GNUNET_TIME_UNIT_FOREVER_REL); 1056 GNUNET_TIME_UNIT_FOREVER_REL);
1069 return msize; 1057 return msize;
1070} 1058}
1071 1059
@@ -1090,8 +1078,7 @@ schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc)
1090 fit = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - size) / sizeof (GNUNET_HashCode); 1078 fit = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - size) / sizeof (GNUNET_HashCode);
1091 fit = GNUNET_MIN (fit, sqms); 1079 fit = GNUNET_MIN (fit, sqms);
1092 size += sizeof (GNUNET_HashCode) * fit; 1080 size += sizeof (GNUNET_HashCode) * fit;
1093 GNUNET_CLIENT_notify_transmit_ready (sc->client, 1081 GNUNET_CLIENT_notify_transmit_ready (sc->client, size,
1094 size,
1095 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 1082 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1096 GNUNET_NO, &transmit_search_request, sc); 1083 GNUNET_NO, &transmit_search_request, sc);
1097 1084
@@ -1140,9 +1127,9 @@ try_reconnect (struct GNUNET_FS_SearchContext *sc)
1140 GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO); 1127 GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO);
1141 sc->client = NULL; 1128 sc->client = NULL;
1142 } 1129 }
1143 sc->task 1130 sc->task =
1144 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 1131 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_reconnect,
1145 &do_reconnect, sc); 1132 sc);
1146} 1133}
1147 1134
1148 1135
@@ -1159,10 +1146,8 @@ try_reconnect (struct GNUNET_FS_SearchContext *sc)
1159 * @return context that can be used to control the search 1146 * @return context that can be used to control the search
1160 */ 1147 */
1161static struct GNUNET_FS_SearchContext * 1148static struct GNUNET_FS_SearchContext *
1162search_start (struct GNUNET_FS_Handle *h, 1149search_start (struct GNUNET_FS_Handle *h, const struct GNUNET_FS_Uri *uri,
1163 const struct GNUNET_FS_Uri *uri, 1150 uint32_t anonymity, enum GNUNET_FS_SearchOptions options,
1164 uint32_t anonymity,
1165 enum GNUNET_FS_SearchOptions options,
1166 void *cctx, struct GNUNET_FS_SearchResult *psearch) 1151 void *cctx, struct GNUNET_FS_SearchResult *psearch)
1167{ 1152{
1168 struct GNUNET_FS_SearchContext *sc; 1153 struct GNUNET_FS_SearchContext *sc;
@@ -1215,8 +1200,9 @@ GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc)
1215 if (GNUNET_FS_uri_test_ksk (sc->uri)) 1200 if (GNUNET_FS_uri_test_ksk (sc->uri))
1216 { 1201 {
1217 GNUNET_assert (0 != sc->uri->data.ksk.keywordCount); 1202 GNUNET_assert (0 != sc->uri->data.ksk.keywordCount);
1218 sc->requests = GNUNET_malloc (sizeof (struct SearchRequestEntry) * 1203 sc->requests =
1219 sc->uri->data.ksk.keywordCount); 1204 GNUNET_malloc (sizeof (struct SearchRequestEntry) *
1205 sc->uri->data.ksk.keywordCount);
1220 for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) 1206 for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
1221 { 1207 {
1222 keyword = &sc->uri->data.ksk.keywords[i][1]; 1208 keyword = &sc->uri->data.ksk.keywords[i][1];
@@ -1253,8 +1239,8 @@ GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc)
1253 * @return GNUNET_OK 1239 * @return GNUNET_OK
1254 */ 1240 */
1255static int 1241static int
1256search_result_freeze_probes (void *cls, 1242search_result_freeze_probes (void *cls, const GNUNET_HashCode * key,
1257 const GNUNET_HashCode * key, void *value) 1243 void *value)
1258{ 1244{
1259 struct GNUNET_FS_SearchResult *sr = value; 1245 struct GNUNET_FS_SearchResult *sr = value;
1260 1246
@@ -1283,8 +1269,8 @@ search_result_freeze_probes (void *cls,
1283 * @return GNUNET_OK 1269 * @return GNUNET_OK
1284 */ 1270 */
1285static int 1271static int
1286search_result_resume_probes (void *cls, 1272search_result_resume_probes (void *cls, const GNUNET_HashCode * key,
1287 const GNUNET_HashCode * key, void *value) 1273 void *value)
1288{ 1274{
1289 struct GNUNET_FS_SearchResult *sr = value; 1275 struct GNUNET_FS_SearchResult *sr = value;
1290 1276
@@ -1383,8 +1369,7 @@ GNUNET_FS_search_signal_suspend_ (void *cls)
1383 */ 1369 */
1384struct GNUNET_FS_SearchContext * 1370struct GNUNET_FS_SearchContext *
1385GNUNET_FS_search_start (struct GNUNET_FS_Handle *h, 1371GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
1386 const struct GNUNET_FS_Uri *uri, 1372 const struct GNUNET_FS_Uri *uri, uint32_t anonymity,
1387 uint32_t anonymity,
1388 enum GNUNET_FS_SearchOptions options, void *cctx) 1373 enum GNUNET_FS_SearchOptions options, void *cctx)
1389{ 1374{
1390 struct GNUNET_FS_SearchContext *ret; 1375 struct GNUNET_FS_SearchContext *ret;
@@ -1460,13 +1445,12 @@ search_result_free (void *cls, const GNUNET_HashCode * key, void *value)
1460 if (NULL != sr->download) 1445 if (NULL != sr->download)
1461 { 1446 {
1462 sr->download->search = NULL; 1447 sr->download->search = NULL;
1463 sr->download->top = GNUNET_FS_make_top (sr->download->h, 1448 sr->download->top =
1464 &GNUNET_FS_download_signal_suspend_, 1449 GNUNET_FS_make_top (sr->download->h,
1465 sr->download); 1450 &GNUNET_FS_download_signal_suspend_, sr->download);
1466 if (NULL != sr->download->serialization) 1451 if (NULL != sr->download->serialization)
1467 { 1452 {
1468 GNUNET_FS_remove_sync_file_ (sc->h, 1453 GNUNET_FS_remove_sync_file_ (sc->h, GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD,
1469 GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD,
1470 sr->download->serialization); 1454 sr->download->serialization);
1471 GNUNET_free (sr->download->serialization); 1455 GNUNET_free (sr->download->serialization);
1472 sr->download->serialization = NULL; 1456 sr->download->serialization = NULL;
@@ -1519,14 +1503,14 @@ GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc)
1519 if (sc->serialization != NULL) 1503 if (sc->serialization != NULL)
1520 { 1504 {
1521 GNUNET_FS_remove_sync_file_ (sc->h, 1505 GNUNET_FS_remove_sync_file_ (sc->h,
1522 (sc->psearch_result != NULL) 1506 (sc->psearch_result !=
1523 ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH 1507 NULL) ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH :
1524 : GNUNET_FS_SYNC_PATH_MASTER_SEARCH, 1508 GNUNET_FS_SYNC_PATH_MASTER_SEARCH,
1525 sc->serialization); 1509 sc->serialization);
1526 GNUNET_FS_remove_sync_dir_ (sc->h, 1510 GNUNET_FS_remove_sync_dir_ (sc->h,
1527 (sc->psearch_result != NULL) 1511 (sc->psearch_result !=
1528 ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH 1512 NULL) ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH :
1529 : GNUNET_FS_SYNC_PATH_MASTER_SEARCH, 1513 GNUNET_FS_SYNC_PATH_MASTER_SEARCH,
1530 sc->serialization); 1514 sc->serialization);
1531 GNUNET_free (sc->serialization); 1515 GNUNET_free (sc->serialization);
1532 } 1516 }
diff --git a/src/fs/fs_test_lib.c b/src/fs/fs_test_lib.c
index 334432232..17291d1bd 100644
--- a/src/fs/fs_test_lib.c
+++ b/src/fs/fs_test_lib.c
@@ -151,8 +151,8 @@ shutdown_callback (void *cls, const char *emsg)
151 151
152 if (emsg != NULL) 152 if (emsg != NULL)
153 { 153 {
154 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 154 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Shutdown of peers failed: %s\n",
155 "Shutdown of peers failed: %s\n", emsg); 155 emsg);
156 } 156 }
157 else 157 else
158 { 158 {
@@ -213,23 +213,20 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
213 break; 213 break;
214 case GNUNET_FS_STATUS_PUBLISH_PROGRESS: 214 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
215 if (daemon->verbose) 215 if (daemon->verbose)
216 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 216 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Publishing at %llu/%llu bytes\n",
217 "Publishing at %llu/%llu bytes\n",
218 (unsigned long long) info->value.publish.completed, 217 (unsigned long long) info->value.publish.completed,
219 (unsigned long long) info->value.publish.size); 218 (unsigned long long) info->value.publish.size);
220 break; 219 break;
221 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: 220 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
222 if (daemon->verbose) 221 if (daemon->verbose)
223 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 222 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Download at %llu/%llu bytes\n",
224 "Download at %llu/%llu bytes\n",
225 (unsigned long long) info->value.download.completed, 223 (unsigned long long) info->value.download.completed,
226 (unsigned long long) info->value.download.size); 224 (unsigned long long) info->value.download.size);
227 break; 225 break;
228 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: 226 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
229 GNUNET_SCHEDULER_cancel (daemon->download_timeout_task); 227 GNUNET_SCHEDULER_cancel (daemon->download_timeout_task);
230 daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK; 228 daemon->download_timeout_task = GNUNET_SCHEDULER_NO_TASK;
231 GNUNET_SCHEDULER_add_continuation (&report_success, 229 GNUNET_SCHEDULER_add_continuation (&report_success, daemon,
232 daemon,
233 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 230 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
234 break; 231 break;
235 case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: 232 case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
@@ -260,8 +257,7 @@ struct StartContext
260 257
261 258
262static void 259static void
263notify_running (void *cls, 260notify_running (void *cls, const struct GNUNET_PeerIdentity *id,
264 const struct GNUNET_PeerIdentity *id,
265 const struct GNUNET_CONFIGURATION_Handle *cfg, 261 const struct GNUNET_CONFIGURATION_Handle *cfg,
266 struct GNUNET_TESTING_Daemon *d, const char *emsg) 262 struct GNUNET_TESTING_Daemon *d, const char *emsg)
267{ 263{
@@ -270,8 +266,8 @@ notify_running (void *cls,
270 266
271 if (emsg != NULL) 267 if (emsg != NULL)
272 { 268 {
273 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 269 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to start daemon: %s\n"),
274 _("Failed to start daemon: %s\n"), emsg); 270 emsg);
275 return; 271 return;
276 } 272 }
277 i = 0; 273 i = 0;
@@ -291,19 +287,16 @@ notify_running (void *cls,
291 sctx->have++; 287 sctx->have++;
292 if (sctx->have == sctx->total) 288 if (sctx->have == sctx->total)
293 { 289 {
294 GNUNET_SCHEDULER_add_continuation (sctx->cont, 290 GNUNET_SCHEDULER_add_continuation (sctx->cont, sctx->cont_cls,
295 sctx->cont_cls,
296 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 291 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
297 sctx->daemons[0]->gcfg = sctx->cfg; 292 sctx->daemons[0]->gcfg = sctx->cfg;
298 GNUNET_SCHEDULER_cancel (sctx->timeout_task); 293 GNUNET_SCHEDULER_cancel (sctx->timeout_task);
299 for (i = 0; i < sctx->total; i++) 294 for (i = 0; i < sctx->total; i++)
300 { 295 {
301 sctx->daemons[i]->fs = GNUNET_FS_start (sctx->daemons[i]->cfg, 296 sctx->daemons[i]->fs =
302 "<tester>", 297 GNUNET_FS_start (sctx->daemons[i]->cfg, "<tester>", &progress_cb,
303 &progress_cb, 298 sctx->daemons[i], GNUNET_FS_FLAGS_NONE,
304 sctx->daemons[i], 299 GNUNET_FS_OPTIONS_END);
305 GNUNET_FS_FLAGS_NONE,
306 GNUNET_FS_OPTIONS_END);
307 } 300 }
308 GNUNET_free (sctx); 301 GNUNET_free (sctx);
309 } 302 }
@@ -330,8 +323,7 @@ start_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
330 sctx->daemons[i] = NULL; 323 sctx->daemons[i] = NULL;
331 } 324 }
332 GNUNET_CONFIGURATION_destroy (sctx->cfg); 325 GNUNET_CONFIGURATION_destroy (sctx->cfg);
333 GNUNET_SCHEDULER_add_continuation (sctx->cont, 326 GNUNET_SCHEDULER_add_continuation (sctx->cont, sctx->cont_cls,
334 sctx->cont_cls,
335 GNUNET_SCHEDULER_REASON_TIMEOUT); 327 GNUNET_SCHEDULER_REASON_TIMEOUT);
336 GNUNET_free (sctx); 328 GNUNET_free (sctx);
337} 329}
@@ -371,8 +363,7 @@ GNUNET_FS_TEST_daemons_start (const char *template_cfg_file,
371 GNUNET_break (0); 363 GNUNET_break (0);
372 GNUNET_CONFIGURATION_destroy (sctx->cfg); 364 GNUNET_CONFIGURATION_destroy (sctx->cfg);
373 GNUNET_free (sctx); 365 GNUNET_free (sctx);
374 GNUNET_SCHEDULER_add_continuation (cont, 366 GNUNET_SCHEDULER_add_continuation (cont, cont_cls,
375 cont_cls,
376 GNUNET_SCHEDULER_REASON_TIMEOUT); 367 GNUNET_SCHEDULER_REASON_TIMEOUT);
377 return; 368 return;
378 } 369 }
@@ -380,13 +371,11 @@ GNUNET_FS_TEST_daemons_start (const char *template_cfg_file,
380 daemons[i] = GNUNET_malloc (sizeof (struct GNUNET_FS_TestDaemon)); 371 daemons[i] = GNUNET_malloc (sizeof (struct GNUNET_FS_TestDaemon));
381 sctx->group = GNUNET_TESTING_daemons_start (sctx->cfg, total, total, /* Outstanding connections */ 372 sctx->group = GNUNET_TESTING_daemons_start (sctx->cfg, total, total, /* Outstanding connections */
382 total, /* Outstanding ssh connections */ 373 total, /* Outstanding ssh connections */
383 timeout, 374 timeout, NULL, NULL,
384 NULL, 375 &notify_running, sctx, NULL, NULL,
385 NULL, 376 NULL);
386 &notify_running, 377 sctx->timeout_task =
387 sctx, NULL, NULL, NULL); 378 GNUNET_SCHEDULER_add_delayed (timeout, &start_timeout, sctx);
388 sctx->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
389 &start_timeout, sctx);
390} 379}
391 380
392 381
@@ -412,10 +401,8 @@ struct ConnectContext
412 * @param emsg error message (NULL on success) 401 * @param emsg error message (NULL on success)
413 */ 402 */
414static void 403static void
415notify_connection (void *cls, 404notify_connection (void *cls, const struct GNUNET_PeerIdentity *first,
416 const struct GNUNET_PeerIdentity *first, 405 const struct GNUNET_PeerIdentity *second, uint32_t distance,
417 const struct GNUNET_PeerIdentity *second,
418 uint32_t distance,
419 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 406 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
420 const struct GNUNET_CONFIGURATION_Handle *second_cfg, 407 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
421 struct GNUNET_TESTING_Daemon *first_daemon, 408 struct GNUNET_TESTING_Daemon *first_daemon,
@@ -425,13 +412,12 @@ notify_connection (void *cls,
425 struct ConnectContext *cc = cls; 412 struct ConnectContext *cc = cls;
426 413
427 if (emsg != NULL) 414 if (emsg != NULL)
428 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 415 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to connect peers: %s\n",
429 "Failed to connect peers: %s\n", emsg); 416 emsg);
430 GNUNET_SCHEDULER_add_continuation (cc->cont, 417 GNUNET_SCHEDULER_add_continuation (cc->cont, cc->cont_cls,
431 cc->cont_cls, 418 (emsg !=
432 (emsg != NULL) 419 NULL) ? GNUNET_SCHEDULER_REASON_TIMEOUT :
433 ? GNUNET_SCHEDULER_REASON_TIMEOUT 420 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
434 : GNUNET_SCHEDULER_REASON_PREREQ_DONE);
435 GNUNET_free (cc); 421 GNUNET_free (cc);
436} 422}
437 423
@@ -457,11 +443,9 @@ GNUNET_FS_TEST_daemons_connect (struct GNUNET_FS_TestDaemon *daemon1,
457 ncc = GNUNET_malloc (sizeof (struct ConnectContext)); 443 ncc = GNUNET_malloc (sizeof (struct ConnectContext));
458 ncc->cont = cont; 444 ncc->cont = cont;
459 ncc->cont_cls = cont_cls; 445 ncc->cont_cls = cont_cls;
460 GNUNET_TESTING_daemons_connect (daemon1->daemon, 446 GNUNET_TESTING_daemons_connect (daemon1->daemon, daemon2->daemon, timeout,
461 daemon2->daemon, 447 CONNECT_ATTEMPTS, GNUNET_YES,
462 timeout, 448 &notify_connection, ncc);
463 CONNECT_ATTEMPTS,
464 GNUNET_YES, &notify_connection, ncc);
465} 449}
466 450
467 451
@@ -610,11 +594,8 @@ file_generator (void *cls, uint64_t offset, size_t max, void *buf, char **emsg)
610 */ 594 */
611void 595void
612GNUNET_FS_TEST_publish (struct GNUNET_FS_TestDaemon *daemon, 596GNUNET_FS_TEST_publish (struct GNUNET_FS_TestDaemon *daemon,
613 struct GNUNET_TIME_Relative timeout, 597 struct GNUNET_TIME_Relative timeout, uint32_t anonymity,
614 uint32_t anonymity, 598 int do_index, uint64_t size, uint32_t seed,
615 int do_index,
616 uint64_t size,
617 uint32_t seed,
618 unsigned int verbose, 599 unsigned int verbose,
619 GNUNET_FS_TEST_UriContinuation cont, void *cont_cls) 600 GNUNET_FS_TEST_UriContinuation cont, void *cont_cls)
620{ 601{
@@ -657,29 +638,23 @@ GNUNET_FS_TEST_publish (struct GNUNET_FS_TestDaemon *daemon,
657 off += bsize; 638 off += bsize;
658 } 639 }
659 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); 640 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
660 fi = GNUNET_FS_file_information_create_from_file (daemon->fs, 641 fi = GNUNET_FS_file_information_create_from_file (daemon->fs, daemon,
661 daemon,
662 daemon->publish_tmp_file, 642 daemon->publish_tmp_file,
663 NULL, NULL, 643 NULL, NULL, do_index,
664 do_index, &bo); 644 &bo);
665 } 645 }
666 else 646 else
667 { 647 {
668 fi = GNUNET_FS_file_information_create_from_reader (daemon->fs, 648 fi = GNUNET_FS_file_information_create_from_reader (daemon->fs, daemon,
669 daemon, 649 size, &file_generator,
670 size, 650 daemon, NULL, NULL,
671 &file_generator, 651 do_index, &bo);
672 daemon,
673 NULL,
674 NULL, do_index, &bo);
675 } 652 }
676 daemon->publish_context = GNUNET_FS_publish_start (daemon->fs, 653 daemon->publish_context =
677 fi, 654 GNUNET_FS_publish_start (daemon->fs, fi, NULL, NULL, NULL,
678 NULL, NULL, NULL, 655 GNUNET_FS_PUBLISH_OPTION_NONE);
679 GNUNET_FS_PUBLISH_OPTION_NONE); 656 daemon->publish_timeout_task =
680 daemon->publish_timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, 657 GNUNET_SCHEDULER_add_delayed (timeout, &publish_timeout, daemon);
681 &publish_timeout,
682 daemon);
683} 658}
684 659
685 660
@@ -716,10 +691,8 @@ download_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
716void 691void
717GNUNET_FS_TEST_download (struct GNUNET_FS_TestDaemon *daemon, 692GNUNET_FS_TEST_download (struct GNUNET_FS_TestDaemon *daemon,
718 struct GNUNET_TIME_Relative timeout, 693 struct GNUNET_TIME_Relative timeout,
719 uint32_t anonymity, 694 uint32_t anonymity, uint32_t seed,
720 uint32_t seed, 695 const struct GNUNET_FS_Uri *uri, unsigned int verbose,
721 const struct GNUNET_FS_Uri *uri,
722 unsigned int verbose,
723 GNUNET_SCHEDULER_Task cont, void *cont_cls) 696 GNUNET_SCHEDULER_Task cont, void *cont_cls)
724{ 697{
725 uint64_t size; 698 uint64_t size;
@@ -730,18 +703,12 @@ GNUNET_FS_TEST_download (struct GNUNET_FS_TestDaemon *daemon,
730 daemon->download_cont = cont; 703 daemon->download_cont = cont;
731 daemon->download_cont_cls = cont_cls; 704 daemon->download_cont_cls = cont_cls;
732 daemon->download_seed = seed; 705 daemon->download_seed = seed;
733 daemon->download_context = GNUNET_FS_download_start (daemon->fs, 706 daemon->download_context =
734 uri, 707 GNUNET_FS_download_start (daemon->fs, uri, NULL, NULL, NULL, 0, size,
735 NULL, NULL, 708 anonymity, GNUNET_FS_DOWNLOAD_OPTION_NONE, NULL,
736 NULL, 709 NULL);
737 0, 710 daemon->download_timeout_task =
738 size, 711 GNUNET_SCHEDULER_add_delayed (timeout, &download_timeout, daemon);
739 anonymity,
740 GNUNET_FS_DOWNLOAD_OPTION_NONE,
741 NULL, NULL);
742 daemon->download_timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
743 &download_timeout,
744 daemon);
745} 712}
746 713
747/* end of test_fs_lib.c */ 714/* end of test_fs_lib.c */
diff --git a/src/fs/fs_tree.c b/src/fs/fs_tree.c
index 5584ad868..0a0db7a10 100644
--- a/src/fs/fs_tree.c
+++ b/src/fs/fs_tree.c
@@ -221,8 +221,8 @@ GNUNET_FS_tree_compute_iblock_size (unsigned int depth, uint64_t end_offset)
221 * @return number of bytes stored in this node 221 * @return number of bytes stored in this node
222 */ 222 */
223size_t 223size_t
224GNUNET_FS_tree_calculate_block_size (uint64_t fsize, 224GNUNET_FS_tree_calculate_block_size (uint64_t fsize, uint64_t offset,
225 uint64_t offset, unsigned int depth) 225 unsigned int depth)
226{ 226{
227 size_t ret; 227 size_t ret;
228 uint64_t rsize; 228 uint64_t rsize;
@@ -268,10 +268,8 @@ GNUNET_FS_tree_calculate_block_size (uint64_t fsize,
268 * @param cont function to call when done 268 * @param cont function to call when done
269 */ 269 */
270struct GNUNET_FS_TreeEncoder * 270struct GNUNET_FS_TreeEncoder *
271GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h, 271GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h, uint64_t size,
272 uint64_t size, 272 void *cls, GNUNET_FS_DataReader reader,
273 void *cls,
274 GNUNET_FS_DataReader reader,
275 GNUNET_FS_TreeBlockProcessor proc, 273 GNUNET_FS_TreeBlockProcessor proc,
276 GNUNET_FS_TreeProgressCallback progress, 274 GNUNET_FS_TreeProgressCallback progress,
277 GNUNET_SCHEDULER_Task cont) 275 GNUNET_SCHEDULER_Task cont)
@@ -287,8 +285,9 @@ GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h,
287 te->progress = progress; 285 te->progress = progress;
288 te->cont = cont; 286 te->cont = cont;
289 te->chk_tree_depth = GNUNET_FS_compute_depth (size); 287 te->chk_tree_depth = GNUNET_FS_compute_depth (size);
290 te->chk_tree = GNUNET_malloc (te->chk_tree_depth * 288 te->chk_tree =
291 CHK_PER_INODE * sizeof (struct ContentHashKey)); 289 GNUNET_malloc (te->chk_tree_depth * CHK_PER_INODE *
290 sizeof (struct ContentHashKey));
292 return te; 291 return te;
293} 292}
294 293
@@ -343,8 +342,7 @@ GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder *te)
343 { 342 {
344 off = CHK_PER_INODE * (te->chk_tree_depth - 1); 343 off = CHK_PER_INODE * (te->chk_tree_depth - 1);
345#if DEBUG_TREE 344#if DEBUG_TREE
346 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TE done, reading CHK `%s' from %u\n",
347 "TE done, reading CHK `%s' from %u\n",
348 GNUNET_h2s (&te->chk_tree[off].query), off); 346 GNUNET_h2s (&te->chk_tree[off].query), off);
349#endif 347#endif
350 te->uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); 348 te->uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
@@ -362,8 +360,7 @@ GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder *te)
362 if (pt_size != 360 if (pt_size !=
363 te->reader (te->cls, te->publish_offset, pt_size, iob, &te->emsg)) 361 te->reader (te->cls, te->publish_offset, pt_size, iob, &te->emsg))
364 { 362 {
365 GNUNET_SCHEDULER_add_continuation (te->cont, 363 GNUNET_SCHEDULER_add_continuation (te->cont, te->cls,
366 te->cls,
367 GNUNET_SCHEDULER_REASON_TIMEOUT); 364 GNUNET_SCHEDULER_REASON_TIMEOUT);
368 te->in_next = GNUNET_NO; 365 te->in_next = GNUNET_NO;
369 return; 366 return;
@@ -372,16 +369,17 @@ GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder *te)
372 } 369 }
373 else 370 else
374 { 371 {
375 pt_size = GNUNET_FS_tree_compute_iblock_size (te->current_depth, 372 pt_size =
376 te->publish_offset); 373 GNUNET_FS_tree_compute_iblock_size (te->current_depth,
374 te->publish_offset);
377 pt_block = &te->chk_tree[(te->current_depth - 1) * CHK_PER_INODE]; 375 pt_block = &te->chk_tree[(te->current_depth - 1) * CHK_PER_INODE];
378 } 376 }
379 off = compute_chk_offset (te->current_depth, te->publish_offset); 377 off = compute_chk_offset (te->current_depth, te->publish_offset);
380#if DEBUG_TREE 378#if DEBUG_TREE
381 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 379 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
382 "TE is at offset %llu and depth %u with block size %u and target-CHK-offset %u\n", 380 "TE is at offset %llu and depth %u with block size %u and target-CHK-offset %u\n",
383 (unsigned long long) te->publish_offset, 381 (unsigned long long) te->publish_offset, te->current_depth,
384 te->current_depth, (unsigned int) pt_size, (unsigned int) off); 382 (unsigned int) pt_size, (unsigned int) off);
385#endif 383#endif
386 mychk = &te->chk_tree[te->current_depth * CHK_PER_INODE + off]; 384 mychk = &te->chk_tree[te->current_depth * CHK_PER_INODE + off];
387 GNUNET_CRYPTO_hash (pt_block, pt_size, &mychk->key); 385 GNUNET_CRYPTO_hash (pt_block, pt_size, &mychk->key);
@@ -395,16 +393,14 @@ GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder *te)
395 te->current_depth * CHK_PER_INODE + off); 393 te->current_depth * CHK_PER_INODE + off);
396#endif 394#endif
397 if (NULL != te->proc) 395 if (NULL != te->proc)
398 te->proc (te->cls, 396 te->proc (te->cls, mychk, te->publish_offset, te->current_depth,
399 mychk, 397 (0 ==
400 te->publish_offset, 398 te->
401 te->current_depth, 399 current_depth) ? GNUNET_BLOCK_TYPE_FS_DBLOCK :
402 (0 == te->current_depth) 400 GNUNET_BLOCK_TYPE_FS_IBLOCK, enc, pt_size);
403 ? GNUNET_BLOCK_TYPE_FS_DBLOCK
404 : GNUNET_BLOCK_TYPE_FS_IBLOCK, enc, pt_size);
405 if (NULL != te->progress) 401 if (NULL != te->progress)
406 te->progress (te->cls, 402 te->progress (te->cls, te->publish_offset, pt_block, pt_size,
407 te->publish_offset, pt_block, pt_size, te->current_depth); 403 te->current_depth);
408 if (0 == te->current_depth) 404 if (0 == te->current_depth)
409 { 405 {
410 te->publish_offset += pt_size; 406 te->publish_offset += pt_size;
diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c
index 130b2eae2..a992c5ff6 100644
--- a/src/fs/fs_unindex.c
+++ b/src/fs/fs_unindex.c
@@ -84,8 +84,8 @@ GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
84 pi->value.unindex.cctx = uc->client_info; 84 pi->value.unindex.cctx = uc->client_info;
85 pi->value.unindex.filename = uc->filename; 85 pi->value.unindex.filename = uc->filename;
86 pi->value.unindex.size = uc->file_size; 86 pi->value.unindex.size = uc->file_size;
87 pi->value.unindex.eta 87 pi->value.unindex.eta =
88 = GNUNET_TIME_calculate_eta (uc->start_time, offset, uc->file_size); 88 GNUNET_TIME_calculate_eta (uc->start_time, offset, uc->file_size);
89 pi->value.unindex.duration = 89 pi->value.unindex.duration =
90 GNUNET_TIME_absolute_get_duration (uc->start_time); 90 GNUNET_TIME_absolute_get_duration (uc->start_time);
91 pi->value.unindex.completed = offset; 91 pi->value.unindex.completed = offset;
@@ -105,9 +105,8 @@ GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
105 * @param depth depth of the block in the tree, 0 for DBLOCK 105 * @param depth depth of the block in the tree, 0 for DBLOCK
106 */ 106 */
107static void 107static void
108unindex_progress (void *cls, 108unindex_progress (void *cls, uint64_t offset, const void *pt_block,
109 uint64_t offset, 109 size_t pt_size, unsigned int depth)
110 const void *pt_block, size_t pt_size, unsigned int depth)
111{ 110{
112 struct GNUNET_FS_UnindexContext *uc = cls; 111 struct GNUNET_FS_UnindexContext *uc = cls;
113 struct GNUNET_FS_ProgressInfo pi; 112 struct GNUNET_FS_ProgressInfo pi;
@@ -181,11 +180,8 @@ process_cont (void *cls, int success, const char *msg)
181 * @param block_size size of block (in bytes) 180 * @param block_size size of block (in bytes)
182 */ 181 */
183static void 182static void
184unindex_process (void *cls, 183unindex_process (void *cls, const struct ContentHashKey *chk, uint64_t offset,
185 const struct ContentHashKey *chk, 184 unsigned int depth, enum GNUNET_BLOCK_Type type,
186 uint64_t offset,
187 unsigned int depth,
188 enum GNUNET_BLOCK_Type type,
189 const void *block, uint16_t block_size) 185 const void *block, uint16_t block_size)
190{ 186{
191 struct GNUNET_FS_UnindexContext *uc = cls; 187 struct GNUNET_FS_UnindexContext *uc = cls;
@@ -209,11 +205,7 @@ unindex_process (void *cls,
209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 205 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
210 "Sending REMOVE request to DATASTORE service\n"); 206 "Sending REMOVE request to DATASTORE service\n");
211#endif 207#endif
212 GNUNET_DATASTORE_remove (uc->dsh, 208 GNUNET_DATASTORE_remove (uc->dsh, &chk->query, size, data, -2, 1,
213 &chk->query,
214 size,
215 data,
216 -2, 1,
217 GNUNET_CONSTANTS_SERVICE_TIMEOUT, &process_cont, uc); 209 GNUNET_CONSTANTS_SERVICE_TIMEOUT, &process_cont, uc);
218} 210}
219 211
@@ -341,8 +333,9 @@ GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc)
341 signal_unindex_error (uc); 333 signal_unindex_error (uc);
342 return; 334 return;
343 } 335 }
344 uc->fh = GNUNET_DISK_file_open (uc->filename, 336 uc->fh =
345 GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE); 337 GNUNET_DISK_file_open (uc->filename, GNUNET_DISK_OPEN_READ,
338 GNUNET_DISK_PERM_NONE);
346 if (NULL == uc->fh) 339 if (NULL == uc->fh)
347 { 340 {
348 GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); 341 GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO);
@@ -353,12 +346,10 @@ GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc)
353 signal_unindex_error (uc); 346 signal_unindex_error (uc);
354 return; 347 return;
355 } 348 }
356 uc->tc = GNUNET_FS_tree_encoder_create (uc->h, 349 uc->tc =
357 uc->file_size, 350 GNUNET_FS_tree_encoder_create (uc->h, uc->file_size, uc, &unindex_reader,
358 uc, 351 &unindex_process, &unindex_progress,
359 &unindex_reader, 352 &unindex_finish);
360 &unindex_process,
361 &unindex_progress, &unindex_finish);
362 GNUNET_FS_tree_encoder_next (uc->tc); 353 GNUNET_FS_tree_encoder_next (uc->tc);
363} 354}
364 355
@@ -436,8 +427,8 @@ GNUNET_FS_unindex_signal_suspend_ (void *cls)
436 GNUNET_FS_end_top (uc->h, uc->top); 427 GNUNET_FS_end_top (uc->h, uc->top);
437 pi.status = GNUNET_FS_STATUS_UNINDEX_SUSPEND; 428 pi.status = GNUNET_FS_STATUS_UNINDEX_SUSPEND;
438 GNUNET_FS_unindex_make_status_ (&pi, uc, 429 GNUNET_FS_unindex_make_status_ (&pi, uc,
439 (uc->state == UNINDEX_STATE_COMPLETE) 430 (uc->state ==
440 ? uc->file_size : 0); 431 UNINDEX_STATE_COMPLETE) ? uc->file_size : 0);
441 GNUNET_break (NULL == uc->client_info); 432 GNUNET_break (NULL == uc->client_info);
442 GNUNET_free (uc->filename); 433 GNUNET_free (uc->filename);
443 GNUNET_free_non_null (uc->serialization); 434 GNUNET_free_non_null (uc->serialization);
@@ -455,8 +446,8 @@ GNUNET_FS_unindex_signal_suspend_ (void *cls)
455 * @return NULL on error, otherwise handle 446 * @return NULL on error, otherwise handle
456 */ 447 */
457struct GNUNET_FS_UnindexContext * 448struct GNUNET_FS_UnindexContext *
458GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, 449GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, const char *filename,
459 const char *filename, void *cctx) 450 void *cctx)
460{ 451{
461 struct GNUNET_FS_UnindexContext *ret; 452 struct GNUNET_FS_UnindexContext *ret;
462 struct GNUNET_FS_ProgressInfo pi; 453 struct GNUNET_FS_ProgressInfo pi;
@@ -474,10 +465,10 @@ GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h,
474 pi.status = GNUNET_FS_STATUS_UNINDEX_START; 465 pi.status = GNUNET_FS_STATUS_UNINDEX_START;
475 pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL; 466 pi.value.unindex.eta = GNUNET_TIME_UNIT_FOREVER_REL;
476 GNUNET_FS_unindex_make_status_ (&pi, ret, 0); 467 GNUNET_FS_unindex_make_status_ (&pi, ret, 0);
477 ret->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, 468 ret->fhc =
478 filename, 469 GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, filename,
479 HASHING_BLOCKSIZE, 470 HASHING_BLOCKSIZE,
480 &GNUNET_FS_unindex_process_hash_, ret); 471 &GNUNET_FS_unindex_process_hash_, ret);
481 ret->top = GNUNET_FS_make_top (h, &GNUNET_FS_unindex_signal_suspend_, ret); 472 ret->top = GNUNET_FS_make_top (h, &GNUNET_FS_unindex_signal_suspend_, ret);
482 return ret; 473 return ret;
483} 474}
@@ -529,8 +520,8 @@ GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc)
529 pi.status = GNUNET_FS_STATUS_UNINDEX_STOPPED; 520 pi.status = GNUNET_FS_STATUS_UNINDEX_STOPPED;
530 pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO; 521 pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO;
531 GNUNET_FS_unindex_make_status_ (&pi, uc, 522 GNUNET_FS_unindex_make_status_ (&pi, uc,
532 (uc->state == UNINDEX_STATE_COMPLETE) 523 (uc->state ==
533 ? uc->file_size : 0); 524 UNINDEX_STATE_COMPLETE) ? uc->file_size : 0);
534 GNUNET_break (NULL == uc->client_info); 525 GNUNET_break (NULL == uc->client_info);
535 GNUNET_free (uc->filename); 526 GNUNET_free (uc->filename);
536 GNUNET_free (uc); 527 GNUNET_free (uc);
diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c
index 5d5d24ca8..22dab4955 100644
--- a/src/fs/fs_uri.c
+++ b/src/fs/fs_uri.c
@@ -419,15 +419,12 @@ uri_chk_parse (const char *s, char **emsg)
419 } 419 }
420 memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); 420 memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
421 h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; 421 h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
422 memcpy (h2, 422 memcpy (h2, &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)],
423 &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)],
424 sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); 423 sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
425 h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; 424 h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
426 425
427 if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, 426 if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &fi.chk.key)) ||
428 &fi.chk.key)) || 427 (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &fi.chk.query)) ||
429 (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2,
430 &fi.chk.query)) ||
431 (1 != 428 (1 !=
432 SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], 429 SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2],
433 "%llu", &flen))) 430 "%llu", &flen)))
@@ -567,15 +564,12 @@ uri_loc_parse (const char *s, char **emsg)
567 } 564 }
568 memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); 565 memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
569 h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; 566 h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
570 memcpy (h2, 567 memcpy (h2, &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)],
571 &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)],
572 sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); 568 sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
573 h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; 569 h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
574 570
575 if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, 571 if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &ass.fi.chk.key)) ||
576 &ass.fi.chk.key)) || 572 (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &ass.fi.chk.query)) ||
577 (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2,
578 &ass.fi.chk.query)) ||
579 (1 != 573 (1 !=
580 SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], 574 SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2],
581 "%llu", &flen))) 575 "%llu", &flen)))
@@ -594,9 +588,9 @@ uri_loc_parse (const char *s, char **emsg)
594 goto ERR; 588 goto ERR;
595 } 589 }
596 npos++; 590 npos++;
597 ret = enc2bin (&s[npos], 591 ret =
598 &ass.peer, 592 enc2bin (&s[npos], &ass.peer,
599 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 593 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
600 if (ret == -1) 594 if (ret == -1)
601 { 595 {
602 *emsg = 596 *emsg =
@@ -769,8 +763,8 @@ GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
769 * @param is_mandatory is this keyword mandatory? 763 * @param is_mandatory is this keyword mandatory?
770 */ 764 */
771void 765void
772GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri, 766GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri, const char *keyword,
773 const char *keyword, int is_mandatory) 767 int is_mandatory)
774{ 768{
775 unsigned int i; 769 unsigned int i;
776 const char *old; 770 const char *old;
@@ -896,8 +890,8 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
896 if (baseUri->type != chk) 890 if (baseUri->type != chk)
897 return NULL; 891 return NULL;
898 if (GNUNET_OK != 892 if (GNUNET_OK !=
899 GNUNET_CONFIGURATION_get_value_filename (cfg, 893 GNUNET_CONFIGURATION_get_value_filename (cfg, "GNUNETD", "HOSTKEY",
900 "GNUNETD", "HOSTKEY", &keyfile)) 894 &keyfile))
901 { 895 {
902 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 896 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
903 _("Lacking key configuration settings.\n")); 897 _("Lacking key configuration settings.\n"));
@@ -924,8 +918,7 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
924 uri->data.loc.expirationTime = expiration_time; 918 uri->data.loc.expirationTime = expiration_time;
925 uri->data.loc.peer = my_public_key; 919 uri->data.loc.peer = my_public_key;
926 GNUNET_assert (GNUNET_OK == 920 GNUNET_assert (GNUNET_OK ==
927 GNUNET_CRYPTO_rsa_sign (my_private_key, 921 GNUNET_CRYPTO_rsa_sign (my_private_key, &ass.purpose,
928 &ass.purpose,
929 &uri->data.loc.contentSignature)); 922 &uri->data.loc.contentSignature));
930 GNUNET_CRYPTO_rsa_key_free (my_private_key); 923 GNUNET_CRYPTO_rsa_key_free (my_private_key);
931 return uri; 924 return uri;
@@ -941,8 +934,8 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
941 * @return an FS URI for the given namespace and identifier 934 * @return an FS URI for the given namespace and identifier
942 */ 935 */
943struct GNUNET_FS_Uri * 936struct GNUNET_FS_Uri *
944GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns, 937GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns, const char *id,
945 const char *id, char **emsg) 938 char **emsg)
946{ 939{
947 struct GNUNET_FS_Uri *ns_uri; 940 struct GNUNET_FS_Uri *ns_uri;
948 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pk; 941 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pk;
@@ -1166,8 +1159,8 @@ GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri)
1166 } 1159 }
1167 if (ret->data.ksk.keywordCount > 0) 1160 if (ret->data.ksk.keywordCount > 0)
1168 { 1161 {
1169 ret->data.ksk.keywords 1162 ret->data.ksk.keywords =
1170 = GNUNET_malloc (ret->data.ksk.keywordCount * sizeof (char *)); 1163 GNUNET_malloc (ret->data.ksk.keywordCount * sizeof (char *));
1171 for (i = 0; i < ret->data.ksk.keywordCount; i++) 1164 for (i = 0; i < ret->data.ksk.keywordCount; i++)
1172 ret->data.ksk.keywords[i] = GNUNET_strdup (uri->data.ksk.keywords[i]); 1165 ret->data.ksk.keywords[i] = GNUNET_strdup (uri->data.ksk.keywords[i]);
1173 } 1166 }
@@ -1315,8 +1308,7 @@ GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv)
1315 /* allow URI to be given as one and only keyword and 1308 /* allow URI to be given as one and only keyword and
1316 * handle accordingly */ 1309 * handle accordingly */
1317 emsg = NULL; 1310 emsg = NULL;
1318 if ((argc == 1) && 1311 if ((argc == 1) && (strlen (argv[0]) > strlen (GNUNET_FS_URI_PREFIX)) &&
1319 (strlen (argv[0]) > strlen (GNUNET_FS_URI_PREFIX)) &&
1320 (0 == 1312 (0 ==
1321 strncmp (argv[0], GNUNET_FS_URI_PREFIX, strlen (GNUNET_FS_URI_PREFIX))) 1313 strncmp (argv[0], GNUNET_FS_URI_PREFIX, strlen (GNUNET_FS_URI_PREFIX)))
1322 && (NULL != (uri = GNUNET_FS_uri_parse (argv[0], &emsg)))) 1314 && (NULL != (uri = GNUNET_FS_uri_parse (argv[0], &emsg))))
@@ -1371,14 +1363,14 @@ GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
1371 switch (u1->type) 1363 switch (u1->type)
1372 { 1364 {
1373 case chk: 1365 case chk:
1374 if (0 == memcmp (&u1->data.chk, 1366 if (0 ==
1375 &u2->data.chk, sizeof (struct FileIdentifier))) 1367 memcmp (&u1->data.chk, &u2->data.chk, sizeof (struct FileIdentifier)))
1376 return GNUNET_YES; 1368 return GNUNET_YES;
1377 return GNUNET_NO; 1369 return GNUNET_NO;
1378 case sks: 1370 case sks:
1379 if ((0 == memcmp (&u1->data.sks.namespace, 1371 if ((0 ==
1380 &u2->data.sks.namespace, 1372 memcmp (&u1->data.sks.namespace, &u2->data.sks.namespace,
1381 sizeof (GNUNET_HashCode))) && 1373 sizeof (GNUNET_HashCode))) &&
1382 (0 == strcmp (u1->data.sks.identifier, u2->data.sks.identifier))) 1374 (0 == strcmp (u1->data.sks.identifier, u2->data.sks.identifier)))
1383 1375
1384 return GNUNET_YES; 1376 return GNUNET_YES;
@@ -1402,12 +1394,12 @@ GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
1402 } 1394 }
1403 return GNUNET_YES; 1395 return GNUNET_YES;
1404 case loc: 1396 case loc:
1405 if (memcmp (&u1->data.loc, 1397 if (memcmp
1406 &u2->data.loc, 1398 (&u1->data.loc, &u2->data.loc,
1407 sizeof (struct FileIdentifier) + 1399 sizeof (struct FileIdentifier) +
1408 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + 1400 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
1409 sizeof (struct GNUNET_TIME_Absolute) + 1401 sizeof (struct GNUNET_TIME_Absolute) + sizeof (unsigned short) +
1410 sizeof (unsigned short) + sizeof (unsigned short)) != 0) 1402 sizeof (unsigned short)) != 0)
1411 return GNUNET_NO; 1403 return GNUNET_NO;
1412 return GNUNET_YES; 1404 return GNUNET_YES;
1413 default: 1405 default:
@@ -1584,10 +1576,8 @@ GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri)
1584 * @return 0 (always) 1576 * @return 0 (always)
1585 */ 1577 */
1586static int 1578static int
1587gather_uri_data (void *cls, 1579gather_uri_data (void *cls, const char *plugin_name,
1588 const char *plugin_name, 1580 enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format,
1589 enum EXTRACTOR_MetaType type,
1590 enum EXTRACTOR_MetaFormat format,
1591 const char *data_mime_type, const char *data, size_t data_len) 1581 const char *data_mime_type, const char *data, size_t data_len)
1592{ 1582{
1593 struct GNUNET_FS_Uri *uri = cls; 1583 struct GNUNET_FS_Uri *uri = cls;
@@ -1643,8 +1633,9 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
1643static int 1633static int
1644needs_percent (char c) 1634needs_percent (char c)
1645{ 1635{
1646 return (!((isalnum ((unsigned char) c)) || 1636 return (!
1647 (c == '-') || (c == '_') || (c == '.') || (c == '~'))); 1637 ((isalnum ((unsigned char) c)) || (c == '-') || (c == '_') ||
1638 (c == '.') || (c == '~')));
1648} 1639}
1649 1640
1650 1641
@@ -1737,9 +1728,7 @@ uri_sks_to_string (const struct GNUNET_FS_Uri *uri)
1737 namespace = &uri->data.sks.namespace; 1728 namespace = &uri->data.sks.namespace;
1738 identifier = uri->data.sks.identifier; 1729 identifier = uri->data.sks.identifier;
1739 GNUNET_CRYPTO_hash_to_enc (namespace, &ns); 1730 GNUNET_CRYPTO_hash_to_enc (namespace, &ns);
1740 GNUNET_asprintf (&ret, 1731 GNUNET_asprintf (&ret, "%s%s%s/%s", GNUNET_FS_URI_PREFIX,
1741 "%s%s%s/%s",
1742 GNUNET_FS_URI_PREFIX,
1743 GNUNET_FS_URI_SKS_INFIX, (const char *) &ns, identifier); 1732 GNUNET_FS_URI_SKS_INFIX, (const char *) &ns, identifier);
1744 return ret; 1733 return ret;
1745} 1734}
@@ -1765,11 +1754,8 @@ uri_chk_to_string (const struct GNUNET_FS_Uri *uri)
1765 GNUNET_CRYPTO_hash_to_enc (&fi->chk.key, &keyhash); 1754 GNUNET_CRYPTO_hash_to_enc (&fi->chk.key, &keyhash);
1766 GNUNET_CRYPTO_hash_to_enc (&fi->chk.query, &queryhash); 1755 GNUNET_CRYPTO_hash_to_enc (&fi->chk.query, &queryhash);
1767 1756
1768 GNUNET_asprintf (&ret, 1757 GNUNET_asprintf (&ret, "%s%s%s.%s.%llu", GNUNET_FS_URI_PREFIX,
1769 "%s%s%s.%s.%llu", 1758 GNUNET_FS_URI_CHK_INFIX, (const char *) &keyhash,
1770 GNUNET_FS_URI_PREFIX,
1771 GNUNET_FS_URI_CHK_INFIX,
1772 (const char *) &keyhash,
1773 (const char *) &queryhash, GNUNET_ntohll (fi->file_length)); 1759 (const char *) &queryhash, GNUNET_ntohll (fi->file_length));
1774 return ret; 1760 return ret;
1775} 1761}
@@ -1839,18 +1825,17 @@ uri_loc_to_string (const struct GNUNET_FS_Uri *uri)
1839 1825
1840 GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.key, &keyhash); 1826 GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.key, &keyhash);
1841 GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.query, &queryhash); 1827 GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.query, &queryhash);
1842 peerId = bin2enc (&uri->data.loc.peer, 1828 peerId =
1843 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 1829 bin2enc (&uri->data.loc.peer,
1844 peerSig = bin2enc (&uri->data.loc.contentSignature, 1830 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
1845 sizeof (struct GNUNET_CRYPTO_RsaSignature)); 1831 peerSig =
1846 GNUNET_asprintf (&ret, 1832 bin2enc (&uri->data.loc.contentSignature,
1847 "%s%s%s.%s.%llu.%s.%s.%llu", 1833 sizeof (struct GNUNET_CRYPTO_RsaSignature));
1848 GNUNET_FS_URI_PREFIX, 1834 GNUNET_asprintf (&ret, "%s%s%s.%s.%llu.%s.%s.%llu", GNUNET_FS_URI_PREFIX,
1849 GNUNET_FS_URI_LOC_INFIX, 1835 GNUNET_FS_URI_LOC_INFIX, (const char *) &keyhash,
1850 (const char *) &keyhash,
1851 (const char *) &queryhash, 1836 (const char *) &queryhash,
1852 (unsigned long long) GNUNET_ntohll (uri->data.loc. 1837 (unsigned long long) GNUNET_ntohll (uri->data.loc.fi.
1853 fi.file_length), peerId, 1838 file_length), peerId,
1854 peerSig, 1839 peerSig,
1855 (unsigned long long) uri->data.loc.expirationTime.abs_value); 1840 (unsigned long long) uri->data.loc.expirationTime.abs_value);
1856 GNUNET_free (peerSig); 1841 GNUNET_free (peerSig);
diff --git a/src/fs/gnunet-directory.c b/src/fs/gnunet-directory.c
index a6fa42664..f2b99f48d 100644
--- a/src/fs/gnunet-directory.c
+++ b/src/fs/gnunet-directory.c
@@ -40,11 +40,9 @@ static int ret;
40 * @return always 0 (to continue iterating) 40 * @return always 0 (to continue iterating)
41 */ 41 */
42static int 42static int
43item_printer (void *cls, 43item_printer (void *cls, const char *plugin_name, enum EXTRACTOR_MetaType type,
44 const char *plugin_name, 44 enum EXTRACTOR_MetaFormat format, const char *data_mime_type,
45 enum EXTRACTOR_MetaType type, 45 const char *data, size_t data_size)
46 enum EXTRACTOR_MetaFormat format,
47 const char *data_mime_type, const char *data, size_t data_size)
48{ 46{
49 if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA) 47 if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA)
50 { 48 {
@@ -81,17 +79,16 @@ item_printer (void *cls,
81 * @param data data available for the file (length bytes) 79 * @param data data available for the file (length bytes)
82 */ 80 */
83static void 81static void
84print_entry (void *cls, 82print_entry (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri,
85 const char *filename, 83 const struct GNUNET_CONTAINER_MetaData *meta, size_t length,
86 const struct GNUNET_FS_Uri *uri, 84 const void *data)
87 const struct GNUNET_CONTAINER_MetaData *meta,
88 size_t length, const void *data)
89{ 85{
90 char *string; 86 char *string;
91 char *name; 87 char *name;
92 88
93 name = GNUNET_CONTAINER_meta_data_get_by_type (meta, 89 name =
94 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); 90 GNUNET_CONTAINER_meta_data_get_by_type (meta,
91 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
95 if (uri == NULL) 92 if (uri == NULL)
96 { 93 {
97 printf (_("Directory `%s' meta data:\n"), name); 94 printf (_("Directory `%s' meta data:\n"), name);
@@ -119,9 +116,8 @@ print_entry (void *cls,
119 * @param cfg configuration 116 * @param cfg configuration
120 */ 117 */
121static void 118static void
122run (void *cls, 119run (void *cls, char *const *args, const char *cfgfile,
123 char *const *args, 120 const struct GNUNET_CONFIGURATION_Handle *cfg)
124 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
125{ 121{
126 struct GNUNET_DISK_MapHandle *map; 122 struct GNUNET_DISK_MapHandle *map;
127 struct GNUNET_DISK_FileHandle *h; 123 struct GNUNET_DISK_FileHandle *h;
@@ -140,16 +136,14 @@ run (void *cls,
140 i = 0; 136 i = 0;
141 while (NULL != (filename = args[i++])) 137 while (NULL != (filename = args[i++]))
142 { 138 {
143 if ((GNUNET_OK != 139 if ((GNUNET_OK != GNUNET_DISK_file_size (filename, &size, GNUNET_YES)) ||
144 GNUNET_DISK_file_size (filename, 140 (NULL ==
145 &size, 141 (h =
146 GNUNET_YES)) || 142 GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ,
147 (NULL == (h = GNUNET_DISK_file_open (filename, 143 GNUNET_DISK_PERM_NONE))))
148 GNUNET_DISK_OPEN_READ,
149 GNUNET_DISK_PERM_NONE))))
150 { 144 {
151 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 145 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to read directory `%s'\n"),
152 _("Failed to read directory `%s'\n"), filename); 146 filename);
153 ret = 1; 147 ret = 1;
154 continue; 148 continue;
155 } 149 }
@@ -177,9 +171,7 @@ main (int argc, char *const *argv)
177 GNUNET_GETOPT_OPTION_END 171 GNUNET_GETOPT_OPTION_END
178 }; 172 };
179 return (GNUNET_OK == 173 return (GNUNET_OK ==
180 GNUNET_PROGRAM_run (argc, 174 GNUNET_PROGRAM_run (argc, argv, "gnunet-directory [OPTIONS] FILENAME",
181 argv,
182 "gnunet-directory [OPTIONS] FILENAME",
183 gettext_noop 175 gettext_noop
184 ("Display contents of a GNUnet directory"), 176 ("Display contents of a GNUnet directory"),
185 options, &run, NULL)) ? ret : 1; 177 options, &run, NULL)) ? ret : 1;
diff --git a/src/fs/gnunet-download.c b/src/fs/gnunet-download.c
index fc0b768d9..9f18cb99c 100644
--- a/src/fs/gnunet-download.c
+++ b/src/fs/gnunet-download.c
@@ -97,8 +97,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
97 { 97 {
98 case GNUNET_FS_STATUS_DOWNLOAD_START: 98 case GNUNET_FS_STATUS_DOWNLOAD_START:
99 if (verbose > 1) 99 if (verbose > 1)
100 fprintf (stderr, 100 fprintf (stderr, _("Starting download `%s'.\n"),
101 _("Starting download `%s'.\n"), info->value.download.filename); 101 info->value.download.filename);
102 break; 102 break;
103 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: 103 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
104 if (verbose) 104 if (verbose)
@@ -106,8 +106,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
106 s = GNUNET_STRINGS_relative_time_to_string (info->value.download.eta); 106 s = GNUNET_STRINGS_relative_time_to_string (info->value.download.eta);
107 t = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed * 107 t = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed *
108 1000LL / 108 1000LL /
109 (info->value.download. 109 (info->value.download.duration.
110 duration.rel_value + 1)); 110 rel_value + 1));
111 fprintf (stdout, 111 fprintf (stdout,
112 _("Downloading `%s' at %llu/%llu (%s remaining, %s/s)\n"), 112 _("Downloading `%s' at %llu/%llu (%s remaining, %s/s)\n"),
113 info->value.download.filename, 113 info->value.download.filename,
@@ -118,15 +118,14 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
118 } 118 }
119 break; 119 break;
120 case GNUNET_FS_STATUS_DOWNLOAD_ERROR: 120 case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
121 fprintf (stderr, 121 fprintf (stderr, _("Error downloading: %s.\n"),
122 _("Error downloading: %s.\n"),
123 info->value.download.specifics.error.message); 122 info->value.download.specifics.error.message);
124 GNUNET_SCHEDULER_shutdown (); 123 GNUNET_SCHEDULER_shutdown ();
125 break; 124 break;
126 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: 125 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
127 s = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed * 1000 / 126 s = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed * 1000 /
128 (info->value.download. 127 (info->value.download.duration.
129 duration.rel_value + 1)); 128 rel_value + 1));
130 fprintf (stdout, _("Downloading `%s' done (%s/s).\n"), 129 fprintf (stdout, _("Downloading `%s' done (%s/s).\n"),
131 info->value.download.filename, s); 130 info->value.download.filename, s);
132 GNUNET_free (s); 131 GNUNET_free (s);
@@ -135,8 +134,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
135 break; 134 break;
136 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: 135 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
137 if (info->value.download.dc == dc) 136 if (info->value.download.dc == dc)
138 GNUNET_SCHEDULER_add_continuation (&cleanup_task, 137 GNUNET_SCHEDULER_add_continuation (&cleanup_task, NULL,
139 NULL,
140 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 138 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
141 break; 139 break;
142 case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: 140 case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
@@ -159,9 +157,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
159 * @param c configuration 157 * @param c configuration
160 */ 158 */
161static void 159static void
162run (void *cls, 160run (void *cls, char *const *args, const char *cfgfile,
163 char *const *args, 161 const struct GNUNET_CONFIGURATION_Handle *c)
164 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
165{ 162{
166 struct GNUNET_FS_Uri *uri; 163 struct GNUNET_FS_Uri *uri;
167 char *emsg; 164 char *emsg;
@@ -195,15 +192,12 @@ run (void *cls,
195 return; 192 return;
196 } 193 }
197 cfg = c; 194 cfg = c;
198 ctx = GNUNET_FS_start (cfg, 195 ctx =
199 "gnunet-download", 196 GNUNET_FS_start (cfg, "gnunet-download", &progress_cb, NULL,
200 &progress_cb, 197 GNUNET_FS_FLAGS_NONE,
201 NULL, 198 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, parallelism,
202 GNUNET_FS_FLAGS_NONE, 199 GNUNET_FS_OPTIONS_REQUEST_PARALLELISM,
203 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, 200 request_parallelism, GNUNET_FS_OPTIONS_END);
204 parallelism,
205 GNUNET_FS_OPTIONS_REQUEST_PARALLELISM,
206 request_parallelism, GNUNET_FS_OPTIONS_END);
207 if (NULL == ctx) 201 if (NULL == ctx)
208 { 202 {
209 fprintf (stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); 203 fprintf (stderr, _("Could not initialize `%s' subsystem.\n"), "FS");
@@ -216,11 +210,7 @@ run (void *cls,
216 options |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE; 210 options |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE;
217 if (local_only) 211 if (local_only)
218 options |= GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY; 212 options |= GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY;
219 dc = GNUNET_FS_download_start (ctx, 213 dc = GNUNET_FS_download_start (ctx, uri, NULL, filename, NULL, 0,
220 uri,
221 NULL,
222 filename, NULL,
223 0,
224 GNUNET_FS_uri_chk_get_file_size (uri), 214 GNUNET_FS_uri_chk_get_file_size (uri),
225 anonymity, options, NULL, NULL); 215 anonymity, options, NULL, NULL);
226 GNUNET_FS_uri_destroy (uri); 216 GNUNET_FS_uri_destroy (uri);
@@ -230,8 +220,8 @@ run (void *cls,
230 ctx = NULL; 220 ctx = NULL;
231 return; 221 return;
232 } 222 }
233 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 223 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
234 &shutdown_task, NULL); 224 NULL);
235} 225}
236 226
237 227
@@ -275,9 +265,7 @@ main (int argc, char *const *argv)
275 GNUNET_GETOPT_OPTION_END 265 GNUNET_GETOPT_OPTION_END
276 }; 266 };
277 return (GNUNET_OK == 267 return (GNUNET_OK ==
278 GNUNET_PROGRAM_run (argc, 268 GNUNET_PROGRAM_run (argc, argv, "gnunet-download [OPTIONS] URI",
279 argv,
280 "gnunet-download [OPTIONS] URI",
281 gettext_noop 269 gettext_noop
282 ("Download files from GNUnet using a GNUnet CHK or LOC URI (gnunet://fs/chk/...)"), 270 ("Download files from GNUnet using a GNUnet CHK or LOC URI (gnunet://fs/chk/...)"),
283 options, &run, NULL)) ? ret : 1; 271 options, &run, NULL)) ? ret : 1;
diff --git a/src/fs/gnunet-pseudonym.c b/src/fs/gnunet-pseudonym.c
index 742111c4e..ce0d24506 100644
--- a/src/fs/gnunet-pseudonym.c
+++ b/src/fs/gnunet-pseudonym.c
@@ -105,9 +105,7 @@ ns_printer (void *cls, const char *name, const GNUNET_HashCode * id)
105 105
106 106
107static int 107static int
108pseudo_printer (void *cls, 108pseudo_printer (void *cls, const GNUNET_HashCode * pseudonym,
109 const GNUNET_HashCode *
110 pseudonym,
111 const struct GNUNET_CONTAINER_MetaData *md, int rating) 109 const struct GNUNET_CONTAINER_MetaData *md, int rating)
112{ 110{
113 char *id; 111 char *id;
@@ -150,8 +148,8 @@ post_advertising (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
150 set++; 148 set++;
151 if (*set != ':') 149 if (*set != ':')
152 { 150 {
153 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 151 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Invalid argument `%s'\n"),
154 _("Invalid argument `%s'\n"), rating_change); 152 rating_change);
155 } 153 }
156 else 154 else
157 { 155 {
@@ -164,8 +162,8 @@ post_advertising (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
164 } 162 }
165 else 163 else
166 { 164 {
167 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 165 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Namespace `%s' unknown.\n"),
168 _("Namespace `%s' unknown.\n"), rating_change); 166 rating_change);
169 } 167 }
170 } 168 }
171 GNUNET_free (rating_change); 169 GNUNET_free (rating_change);
@@ -192,17 +190,14 @@ post_advertising (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
192 * @param c configuration 190 * @param c configuration
193 */ 191 */
194static void 192static void
195run (void *cls, 193run (void *cls, char *const *args, const char *cfgfile,
196 char *const *args, 194 const struct GNUNET_CONFIGURATION_Handle *c)
197 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
198{ 195{
199 char *emsg; 196 char *emsg;
200 197
201 cfg = c; 198 cfg = c;
202 h = GNUNET_FS_start (cfg, 199 h = GNUNET_FS_start (cfg, "gnunet-pseudonym", &progress_cb, NULL,
203 "gnunet-pseudonym", 200 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
204 &progress_cb,
205 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
206 if (NULL != delete_ns) 201 if (NULL != delete_ns)
207 { 202 {
208 ns = GNUNET_FS_namespace_create (h, delete_ns); 203 ns = GNUNET_FS_namespace_create (h, delete_ns);
@@ -234,13 +229,9 @@ run (void *cls,
234 ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/namespace", &emsg); 229 ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/namespace", &emsg);
235 GNUNET_assert (NULL == emsg); 230 GNUNET_assert (NULL == emsg);
236 } 231 }
237 GNUNET_FS_namespace_advertise (h, 232 GNUNET_FS_namespace_advertise (h, ksk_uri, ns, adv_metadata, &bo,
238 ksk_uri, 233 root_identifier, &post_advertising,
239 ns, 234 NULL);
240 adv_metadata,
241 &bo,
242 root_identifier,
243 &post_advertising, NULL);
244 return; 235 return;
245 } 236 }
246 else 237 else
@@ -284,9 +275,8 @@ main (int argc, char *const *argv)
284 gettext_noop ("delete namespace NAME "), 275 gettext_noop ("delete namespace NAME "),
285 1, &GNUNET_GETOPT_set_string, &delete_ns}, 276 1, &GNUNET_GETOPT_set_string, &delete_ns},
286 {'k', "keyword", "VALUE", 277 {'k', "keyword", "VALUE",
287 gettext_noop 278 gettext_noop ("add an additional keyword for the advertisment"
288 ("add an additional keyword for the advertisment" 279 " (this option can be specified multiple times)"),
289 " (this option can be specified multiple times)"),
290 1, &GNUNET_FS_getopt_set_keywords, &ksk_uri}, 280 1, &GNUNET_FS_getopt_set_keywords, &ksk_uri},
291 {'m', "meta", "TYPE:VALUE", 281 {'m', "meta", "TYPE:VALUE",
292 gettext_noop ("set the meta-data for the given TYPE to the given VALUE"), 282 gettext_noop ("set the meta-data for the given TYPE to the given VALUE"),
diff --git a/src/fs/gnunet-publish.c b/src/fs/gnunet-publish.c
index 326fed3c6..a67886f7d 100644
--- a/src/fs/gnunet-publish.c
+++ b/src/fs/gnunet-publish.c
@@ -112,8 +112,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
112 if (verbose) 112 if (verbose)
113 { 113 {
114 s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.eta); 114 s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.eta);
115 fprintf (stdout, 115 fprintf (stdout, _("Publishing `%s' at %llu/%llu (%s remaining)\n"),
116 _("Publishing `%s' at %llu/%llu (%s remaining)\n"),
117 info->value.publish.filename, 116 info->value.publish.filename,
118 (unsigned long long) info->value.publish.completed, 117 (unsigned long long) info->value.publish.completed,
119 (unsigned long long) info->value.publish.size, s); 118 (unsigned long long) info->value.publish.size, s);
@@ -121,23 +120,21 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
121 } 120 }
122 break; 121 break;
123 case GNUNET_FS_STATUS_PUBLISH_ERROR: 122 case GNUNET_FS_STATUS_PUBLISH_ERROR:
124 fprintf (stderr, 123 fprintf (stderr, _("Error publishing: %s.\n"),
125 _("Error publishing: %s.\n"),
126 info->value.publish.specifics.error.message); 124 info->value.publish.specifics.error.message);
127 if (kill_task != GNUNET_SCHEDULER_NO_TASK) 125 if (kill_task != GNUNET_SCHEDULER_NO_TASK)
128 { 126 {
129 GNUNET_SCHEDULER_cancel (kill_task); 127 GNUNET_SCHEDULER_cancel (kill_task);
130 kill_task = GNUNET_SCHEDULER_NO_TASK; 128 kill_task = GNUNET_SCHEDULER_NO_TASK;
131 } 129 }
132 GNUNET_SCHEDULER_add_continuation (&do_stop_task, 130 GNUNET_SCHEDULER_add_continuation (&do_stop_task, NULL,
133 NULL,
134 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 131 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
135 break; 132 break;
136 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 133 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
137 fprintf (stdout, 134 fprintf (stdout, _("Publishing `%s' done.\n"),
138 _("Publishing `%s' done.\n"), info->value.publish.filename); 135 info->value.publish.filename);
139 s = GNUNET_FS_uri_to_string (info->value.publish.specifics. 136 s = GNUNET_FS_uri_to_string (info->value.publish.specifics.completed.
140 completed.chk_uri); 137 chk_uri);
141 fprintf (stdout, _("URI is `%s'.\n"), s); 138 fprintf (stdout, _("URI is `%s'.\n"), s);
142 GNUNET_free (s); 139 GNUNET_free (s);
143 if (info->value.publish.pctx == NULL) 140 if (info->value.publish.pctx == NULL)
@@ -147,8 +144,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
147 GNUNET_SCHEDULER_cancel (kill_task); 144 GNUNET_SCHEDULER_cancel (kill_task);
148 kill_task = GNUNET_SCHEDULER_NO_TASK; 145 kill_task = GNUNET_SCHEDULER_NO_TASK;
149 } 146 }
150 GNUNET_SCHEDULER_add_continuation (&do_stop_task, 147 GNUNET_SCHEDULER_add_continuation (&do_stop_task, NULL,
151 NULL,
152 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 148 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
153 } 149 }
154 break; 150 break;
@@ -177,11 +173,9 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
177 * @return always 0 173 * @return always 0
178 */ 174 */
179static int 175static int
180meta_printer (void *cls, 176meta_printer (void *cls, const char *plugin_name, enum EXTRACTOR_MetaType type,
181 const char *plugin_name, 177 enum EXTRACTOR_MetaFormat format, const char *data_mime_type,
182 enum EXTRACTOR_MetaType type, 178 const char *data, size_t data_size)
183 enum EXTRACTOR_MetaFormat format,
184 const char *data_mime_type, const char *data, size_t data_size)
185{ 179{
186 if ((format != EXTRACTOR_METAFORMAT_UTF8) && 180 if ((format != EXTRACTOR_METAFORMAT_UTF8) &&
187 (format != EXTRACTOR_METAFORMAT_C_STRING)) 181 (format != EXTRACTOR_METAFORMAT_C_STRING))
@@ -228,13 +222,11 @@ keyword_printer (void *cls, const char *keyword, int is_mandatory)
228 * to abort the iteration 222 * to abort the iteration
229 */ 223 */
230static int 224static int
231publish_inspector (void *cls, 225publish_inspector (void *cls, struct GNUNET_FS_FileInformation *fi,
232 struct GNUNET_FS_FileInformation *fi, 226 uint64_t length, struct GNUNET_CONTAINER_MetaData *m,
233 uint64_t length,
234 struct GNUNET_CONTAINER_MetaData *m,
235 struct GNUNET_FS_Uri **uri, 227 struct GNUNET_FS_Uri **uri,
236 struct GNUNET_FS_BlockOptions *bo, 228 struct GNUNET_FS_BlockOptions *bo, int *do_index,
237 int *do_index, void **client_info) 229 void **client_info)
238{ 230{
239 char *fn; 231 char *fn;
240 char *fs; 232 char *fs;
@@ -286,8 +278,8 @@ publish_inspector (void *cls,
286 278
287 279
288static void 280static void
289uri_sks_continuation (void *cls, 281uri_sks_continuation (void *cls, const struct GNUNET_FS_Uri *ksk_uri,
290 const struct GNUNET_FS_Uri *ksk_uri, const char *emsg) 282 const char *emsg)
291{ 283{
292 if (emsg != NULL) 284 if (emsg != NULL)
293 { 285 {
@@ -302,8 +294,8 @@ uri_sks_continuation (void *cls,
302 294
303 295
304static void 296static void
305uri_ksk_continuation (void *cls, 297uri_ksk_continuation (void *cls, const struct GNUNET_FS_Uri *ksk_uri,
306 const struct GNUNET_FS_Uri *ksk_uri, const char *emsg) 298 const char *emsg)
307{ 299{
308 struct GNUNET_FS_Namespace *ns; 300 struct GNUNET_FS_Namespace *ns;
309 301
@@ -322,13 +314,7 @@ uri_ksk_continuation (void *cls,
322 } 314 }
323 else 315 else
324 { 316 {
325 GNUNET_FS_publish_sks (ctx, 317 GNUNET_FS_publish_sks (ctx, ns, this_id, next_id, meta, uri, &bo,
326 ns,
327 this_id,
328 next_id,
329 meta,
330 uri,
331 &bo,
332 GNUNET_FS_PUBLISH_OPTION_NONE, 318 GNUNET_FS_PUBLISH_OPTION_NONE,
333 uri_sks_continuation, NULL); 319 uri_sks_continuation, NULL);
334 GNUNET_assert (GNUNET_OK == GNUNET_FS_namespace_delete (ns, GNUNET_NO)); 320 GNUNET_assert (GNUNET_OK == GNUNET_FS_namespace_delete (ns, GNUNET_NO));
@@ -351,9 +337,8 @@ uri_ksk_continuation (void *cls,
351 * @param c configuration 337 * @param c configuration
352 */ 338 */
353static void 339static void
354run (void *cls, 340run (void *cls, char *const *args, const char *cfgfile,
355 char *const *args, 341 const struct GNUNET_CONFIGURATION_Handle *c)
356 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
357{ 342{
358 struct GNUNET_FS_FileInformation *fi; 343 struct GNUNET_FS_FileInformation *fi;
359 struct GNUNET_FS_Namespace *namespace; 344 struct GNUNET_FS_Namespace *namespace;
@@ -370,8 +355,8 @@ run (void *cls,
370 ret = -1; 355 ret = -1;
371 return; 356 return;
372 } 357 }
373 if (((uri_string == NULL) || (extract_only)) 358 if (((uri_string == NULL) || (extract_only)) &&
374 && ((args[0] == NULL) || (args[1] != NULL))) 359 ((args[0] == NULL) || (args[1] != NULL)))
375 { 360 {
376 printf (_("You must specify one and only one filename for insertion.\n")); 361 printf (_("You must specify one and only one filename for insertion.\n"));
377 ret = -1; 362 ret = -1;
@@ -387,8 +372,7 @@ run (void *cls,
387 { 372 {
388 if (NULL == this_id) 373 if (NULL == this_id)
389 { 374 {
390 fprintf (stderr, 375 fprintf (stderr, _("Option `%s' is required when using option `%s'.\n"),
391 _("Option `%s' is required when using option `%s'.\n"),
392 "-t", "-P"); 376 "-t", "-P");
393 ret = -1; 377 ret = -1;
394 return; 378 return;
@@ -398,26 +382,23 @@ run (void *cls,
398 { /* ordinary insertion checks */ 382 { /* ordinary insertion checks */
399 if (NULL != next_id) 383 if (NULL != next_id)
400 { 384 {
401 fprintf (stderr, 385 fprintf (stderr, _("Option `%s' makes no sense without option `%s'.\n"),
402 _("Option `%s' makes no sense without option `%s'.\n"),
403 "-N", "-P"); 386 "-N", "-P");
404 ret = -1; 387 ret = -1;
405 return; 388 return;
406 } 389 }
407 if (NULL != this_id) 390 if (NULL != this_id)
408 { 391 {
409 fprintf (stderr, 392 fprintf (stderr, _("Option `%s' makes no sense without option `%s'.\n"),
410 _("Option `%s' makes no sense without option `%s'.\n"),
411 "-t", "-P"); 393 "-t", "-P");
412 ret = -1; 394 ret = -1;
413 return; 395 return;
414 } 396 }
415 } 397 }
416 cfg = c; 398 cfg = c;
417 ctx = GNUNET_FS_start (cfg, 399 ctx =
418 "gnunet-publish", 400 GNUNET_FS_start (cfg, "gnunet-publish", &progress_cb, NULL,
419 &progress_cb, 401 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
420 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
421 if (NULL == ctx) 402 if (NULL == ctx)
422 { 403 {
423 fprintf (stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); 404 fprintf (stderr, _("Could not initialize `%s' subsystem.\n"), "FS");
@@ -450,13 +431,9 @@ run (void *cls,
450 ret = 1; 431 ret = 1;
451 return; 432 return;
452 } 433 }
453 GNUNET_FS_publish_ksk (ctx, 434 GNUNET_FS_publish_ksk (ctx, topKeywords, meta, uri, &bo,
454 topKeywords, 435 GNUNET_FS_PUBLISH_OPTION_NONE, &uri_ksk_continuation,
455 meta, 436 NULL);
456 uri,
457 &bo,
458 GNUNET_FS_PUBLISH_OPTION_NONE,
459 &uri_ksk_continuation, NULL);
460 if (namespace != NULL) 437 if (namespace != NULL)
461 GNUNET_FS_namespace_delete (namespace, GNUNET_NO); 438 GNUNET_FS_namespace_delete (namespace, GNUNET_NO);
462 return; 439 return;
@@ -484,12 +461,9 @@ run (void *cls,
484 } 461 }
485 else if (S_ISDIR (sbuf.st_mode)) 462 else if (S_ISDIR (sbuf.st_mode))
486 { 463 {
487 fi = GNUNET_FS_file_information_create_from_directory (ctx, 464 fi = GNUNET_FS_file_information_create_from_directory (ctx, NULL, args[0],
488 NULL,
489 args[0],
490 &GNUNET_FS_directory_scanner_default, 465 &GNUNET_FS_directory_scanner_default,
491 plugins, 466 plugins, !do_insert,
492 !do_insert,
493 &bo, &emsg); 467 &bo, &emsg);
494 } 468 }
495 else 469 else
@@ -498,11 +472,9 @@ run (void *cls,
498 meta = GNUNET_CONTAINER_meta_data_create (); 472 meta = GNUNET_CONTAINER_meta_data_create ();
499 GNUNET_FS_meta_data_extract_from_file (meta, args[0], plugins); 473 GNUNET_FS_meta_data_extract_from_file (meta, args[0], plugins);
500 keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta); 474 keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta);
501 fi = GNUNET_FS_file_information_create_from_file (ctx, 475 fi = GNUNET_FS_file_information_create_from_file (ctx, NULL, args[0],
502 NULL, 476 keywords, NULL,
503 args[0], 477 !do_insert, &bo);
504 keywords,
505 NULL, !do_insert, &bo);
506 GNUNET_break (fi != NULL); 478 GNUNET_break (fi != NULL);
507 GNUNET_FS_uri_destroy (keywords); 479 GNUNET_FS_uri_destroy (keywords);
508 } 480 }
@@ -526,14 +498,10 @@ run (void *cls,
526 GNUNET_FS_stop (ctx); 498 GNUNET_FS_stop (ctx);
527 return; 499 return;
528 } 500 }
529 pc = GNUNET_FS_publish_start (ctx, 501 pc = GNUNET_FS_publish_start (ctx, fi, namespace, this_id, next_id,
530 fi, 502 (do_simulate) ?
531 namespace, 503 GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY :
532 this_id, 504 GNUNET_FS_PUBLISH_OPTION_NONE);
533 next_id,
534 (do_simulate)
535 ? GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY
536 : GNUNET_FS_PUBLISH_OPTION_NONE);
537 if (NULL == pc) 505 if (NULL == pc)
538 { 506 {
539 fprintf (stderr, _("Could not start publishing.\n")); 507 fprintf (stderr, _("Could not start publishing.\n"));
@@ -541,8 +509,9 @@ run (void *cls,
541 ret = 1; 509 ret = 1;
542 return; 510 return;
543 } 511 }
544 kill_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 512 kill_task =
545 &do_stop_task, NULL); 513 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_stop_task,
514 NULL);
546} 515}
547 516
548 517
diff --git a/src/fs/gnunet-search.c b/src/fs/gnunet-search.c
index 8a3e2ed6a..c82a0794c 100644
--- a/src/fs/gnunet-search.c
+++ b/src/fs/gnunet-search.c
@@ -70,11 +70,9 @@ static int local_only;
70 * @return 0 to continue extracting, 1 to abort 70 * @return 0 to continue extracting, 1 to abort
71 */ 71 */
72static int 72static int
73item_printer (void *cls, 73item_printer (void *cls, const char *plugin_name, enum EXTRACTOR_MetaType type,
74 const char *plugin_name, 74 enum EXTRACTOR_MetaFormat format, const char *data_mime_type,
75 enum EXTRACTOR_MetaType type, 75 const char *data, size_t data_size)
76 enum EXTRACTOR_MetaFormat format,
77 const char *data_mime_type, const char *data, size_t data_size)
78{ 76{
79 if ((format != EXTRACTOR_METAFORMAT_UTF8) && 77 if ((format != EXTRACTOR_METAFORMAT_UTF8) &&
80 (format != EXTRACTOR_METAFORMAT_C_STRING)) 78 (format != EXTRACTOR_METAFORMAT_C_STRING))
@@ -105,9 +103,7 @@ clean_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
105 return; 103 return;
106 } 104 }
107 if (dsize != 105 if (dsize !=
108 GNUNET_DISK_fn_write (output_filename, 106 GNUNET_DISK_fn_write (output_filename, ddata, dsize,
109 ddata,
110 dsize,
111 GNUNET_DISK_PERM_USER_READ | 107 GNUNET_DISK_PERM_USER_READ |
112 GNUNET_DISK_PERM_USER_WRITE)) 108 GNUNET_DISK_PERM_USER_WRITE))
113 { 109 {
@@ -154,8 +150,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
154 uri = GNUNET_FS_uri_to_string (info->value.search.specifics.result.uri); 150 uri = GNUNET_FS_uri_to_string (info->value.search.specifics.result.uri);
155 printf ("#%u:\n", cnt++); 151 printf ("#%u:\n", cnt++);
156 filename = 152 filename =
157 GNUNET_CONTAINER_meta_data_get_by_type (info->value.search. 153 GNUNET_CONTAINER_meta_data_get_by_type (info->value.search.specifics.
158 specifics.result.meta, 154 result.meta,
159 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); 155 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
160 if (filename != NULL) 156 if (filename != NULL)
161 { 157 {
@@ -166,8 +162,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
166 else 162 else
167 printf ("gnunet-download %s\n", uri); 163 printf ("gnunet-download %s\n", uri);
168 if (verbose) 164 if (verbose)
169 GNUNET_CONTAINER_meta_data_iterate (info->value.search.specifics. 165 GNUNET_CONTAINER_meta_data_iterate (info->value.search.specifics.result.
170 result.meta, &item_printer, NULL); 166 meta, &item_printer, NULL);
171 printf ("\n"); 167 printf ("\n");
172 fflush (stdout); 168 fflush (stdout);
173 GNUNET_free_non_null (filename); 169 GNUNET_free_non_null (filename);
@@ -182,14 +178,12 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
182 /* ignore */ 178 /* ignore */
183 break; 179 break;
184 case GNUNET_FS_STATUS_SEARCH_ERROR: 180 case GNUNET_FS_STATUS_SEARCH_ERROR:
185 fprintf (stderr, 181 fprintf (stderr, _("Error searching: %s.\n"),
186 _("Error searching: %s.\n"),
187 info->value.search.specifics.error.message); 182 info->value.search.specifics.error.message);
188 GNUNET_SCHEDULER_shutdown (); 183 GNUNET_SCHEDULER_shutdown ();
189 break; 184 break;
190 case GNUNET_FS_STATUS_SEARCH_STOPPED: 185 case GNUNET_FS_STATUS_SEARCH_STOPPED:
191 GNUNET_SCHEDULER_add_continuation (&clean_task, 186 GNUNET_SCHEDULER_add_continuation (&clean_task, NULL,
192 NULL,
193 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 187 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
194 break; 188 break;
195 default: 189 default:
@@ -220,9 +214,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
220 * @param c configuration 214 * @param c configuration
221 */ 215 */
222static void 216static void
223run (void *cls, 217run (void *cls, char *const *args, const char *cfgfile,
224 char *const *args, 218 const struct GNUNET_CONFIGURATION_Handle *c)
225 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
226{ 219{
227 struct GNUNET_FS_Uri *uri; 220 struct GNUNET_FS_Uri *uri;
228 unsigned int argc; 221 unsigned int argc;
@@ -240,10 +233,9 @@ run (void *cls,
240 return; 233 return;
241 } 234 }
242 cfg = c; 235 cfg = c;
243 ctx = GNUNET_FS_start (cfg, 236 ctx =
244 "gnunet-search", 237 GNUNET_FS_start (cfg, "gnunet-search", &progress_cb, NULL,
245 &progress_cb, 238 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
246 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
247 if (NULL == ctx) 239 if (NULL == ctx)
248 { 240 {
249 fprintf (stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); 241 fprintf (stderr, _("Could not initialize `%s' subsystem.\n"), "FS");
@@ -272,8 +264,8 @@ run (void *cls,
272 } 264 }
273 else 265 else
274 { 266 {
275 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 267 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
276 &shutdown_task, NULL); 268 NULL);
277 } 269 }
278} 270}
279 271
@@ -311,9 +303,7 @@ main (int argc, char *const *argv)
311 GNUNET_GETOPT_OPTION_END 303 GNUNET_GETOPT_OPTION_END
312 }; 304 };
313 return (GNUNET_OK == 305 return (GNUNET_OK ==
314 GNUNET_PROGRAM_run (argc, 306 GNUNET_PROGRAM_run (argc, argv, "gnunet-search [OPTIONS] KEYWORD",
315 argv,
316 "gnunet-search [OPTIONS] KEYWORD",
317 gettext_noop 307 gettext_noop
318 ("Search GNUnet for files that were published on GNUnet"), 308 ("Search GNUnet for files that were published on GNUnet"),
319 options, &run, NULL)) ? ret : 1; 309 options, &run, NULL)) ? ret : 1;
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c
index 4d12b8bfd..0457607d5 100644
--- a/src/fs/gnunet-service-fs.c
+++ b/src/fs/gnunet-service-fs.c
@@ -166,8 +166,9 @@ age_cover_counters (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
166{ 166{
167 GSF_cover_content_count = (GSF_cover_content_count * 15) / 16; 167 GSF_cover_content_count = (GSF_cover_content_count * 15) / 16;
168 GSF_cover_query_count = (GSF_cover_query_count * 15) / 16; 168 GSF_cover_query_count = (GSF_cover_query_count * 15) / 16;
169 cover_age_task = GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, 169 cover_age_task =
170 &age_cover_counters, NULL); 170 GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, &age_cover_counters,
171 NULL);
171} 172}
172 173
173 174
@@ -223,8 +224,7 @@ GSF_test_get_load_too_high_ (uint32_t priority)
223 * GNUNET_SYSERR to close it (signal serious error) 224 * GNUNET_SYSERR to close it (signal serious error)
224 */ 225 */
225static int 226static int
226handle_p2p_put (void *cls, 227handle_p2p_put (void *cls, const struct GNUNET_PeerIdentity *other,
227 const struct GNUNET_PeerIdentity *other,
228 const struct GNUNET_MessageHeader *message, 228 const struct GNUNET_MessageHeader *message,
229 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 229 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
230{ 230{
@@ -273,8 +273,7 @@ consider_request_for_forwarding (void *cls,
273 * @param result final datastore lookup result 273 * @param result final datastore lookup result
274 */ 274 */
275static void 275static void
276consider_forwarding (void *cls, 276consider_forwarding (void *cls, struct GSF_PendingRequest *pr,
277 struct GSF_PendingRequest *pr,
278 enum GNUNET_BLOCK_EvaluationResult result) 277 enum GNUNET_BLOCK_EvaluationResult result)
279{ 278{
280 if (GNUNET_BLOCK_EVALUATION_OK_LAST == result) 279 if (GNUNET_BLOCK_EVALUATION_OK_LAST == result)
@@ -295,8 +294,7 @@ consider_forwarding (void *cls,
295 * GNUNET_SYSERR to close it (signal serious error) 294 * GNUNET_SYSERR to close it (signal serious error)
296 */ 295 */
297static int 296static int
298handle_p2p_get (void *cls, 297handle_p2p_get (void *cls, const struct GNUNET_PeerIdentity *other,
299 const struct GNUNET_PeerIdentity *other,
300 const struct GNUNET_MessageHeader *message, 298 const struct GNUNET_MessageHeader *message,
301 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 299 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
302{ 300{
@@ -321,8 +319,7 @@ handle_p2p_get (void *cls,
321 * @param result final datastore lookup result 319 * @param result final datastore lookup result
322 */ 320 */
323static void 321static void
324start_p2p_processing (void *cls, 322start_p2p_processing (void *cls, struct GSF_PendingRequest *pr,
325 struct GSF_PendingRequest *pr,
326 enum GNUNET_BLOCK_EvaluationResult result) 323 enum GNUNET_BLOCK_EvaluationResult result)
327{ 324{
328 struct GNUNET_SERVER_Client *client = cls; 325 struct GNUNET_SERVER_Client *client = cls;
@@ -355,8 +352,7 @@ start_p2p_processing (void *cls,
355 * @param message the actual message 352 * @param message the actual message
356 */ 353 */
357static void 354static void
358handle_start_search (void *cls, 355handle_start_search (void *cls, struct GNUNET_SERVER_Client *client,
359 struct GNUNET_SERVER_Client *client,
360 const struct GNUNET_MessageHeader *message) 356 const struct GNUNET_MessageHeader *message)
361{ 357{
362 struct GSF_PendingRequest *pr; 358 struct GSF_PendingRequest *pr;
@@ -424,8 +420,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
424 * @return GNUNET_YES to continue to iterate 420 * @return GNUNET_YES to continue to iterate
425 */ 421 */
426static int 422static int
427consider_peer_for_forwarding (void *cls, 423consider_peer_for_forwarding (void *cls, const GNUNET_HashCode * key,
428 const GNUNET_HashCode * key,
429 struct GSF_PendingRequest *pr) 424 struct GSF_PendingRequest *pr)
430{ 425{
431 struct GSF_ConnectedPeer *cp = cls; 426 struct GSF_ConnectedPeer *cp = cls;
@@ -443,8 +438,7 @@ consider_peer_for_forwarding (void *cls,
443 * @param atsi performance information 438 * @param atsi performance information
444 */ 439 */
445static void 440static void
446peer_connect_handler (void *cls, 441peer_connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
447 const struct GNUNET_PeerIdentity *peer,
448 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 442 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
449{ 443{
450 struct GSF_ConnectedPeer *cp; 444 struct GSF_ConnectedPeer *cp;
@@ -471,11 +465,10 @@ peer_connect_handler (void *cls,
471 * @param publicKey public key of this peer, NULL if we failed 465 * @param publicKey public key of this peer, NULL if we failed
472 */ 466 */
473static void 467static void
474peer_init_handler (void *cls, 468peer_init_handler (void *cls, struct GNUNET_CORE_Handle *server,
475 struct GNUNET_CORE_Handle *server,
476 const struct GNUNET_PeerIdentity *my_identity, 469 const struct GNUNET_PeerIdentity *my_identity,
477 const struct 470 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
478 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) 471 *publicKey)
479{ 472{
480 my_id = *my_identity; 473 my_id = *my_identity;
481} 474}
@@ -515,12 +508,10 @@ main_init (struct GNUNET_SERVER_Handle *server,
515 }; 508 };
516 509
517 GSF_core = GNUNET_CORE_connect (GSF_cfg, 2, /* larger? */ 510 GSF_core = GNUNET_CORE_connect (GSF_cfg, 2, /* larger? */
518 NULL, 511 NULL, &peer_init_handler,
519 &peer_init_handler,
520 &peer_connect_handler, 512 &peer_connect_handler,
521 &GSF_peer_disconnect_handler_, 513 &GSF_peer_disconnect_handler_,
522 &GSF_peer_status_handler_, 514 &GSF_peer_status_handler_, NULL, GNUNET_NO,
523 NULL, GNUNET_NO,
524 NULL, GNUNET_NO, p2p_handlers); 515 NULL, GNUNET_NO, p2p_handlers);
525 if (NULL == GSF_core) 516 if (NULL == GSF_core)
526 { 517 {
@@ -528,14 +519,15 @@ main_init (struct GNUNET_SERVER_Handle *server,
528 _("Failed to connect to `%s' service.\n"), "core"); 519 _("Failed to connect to `%s' service.\n"), "core");
529 return GNUNET_SYSERR; 520 return GNUNET_SYSERR;
530 } 521 }
531 GNUNET_SERVER_disconnect_notify (server, 522 GNUNET_SERVER_disconnect_notify (server, &GSF_client_disconnect_handler_,
532 &GSF_client_disconnect_handler_, NULL); 523 NULL);
533 GNUNET_SERVER_add_handlers (server, handlers); 524 GNUNET_SERVER_add_handlers (server, handlers);
534 cover_age_task = GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, 525 cover_age_task =
535 &age_cover_counters, NULL); 526 GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, &age_cover_counters,
527 NULL);
536 datastore_get_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE); 528 datastore_get_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE);
537 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 529 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
538 &shutdown_task, NULL); 530 NULL);
539 return GNUNET_OK; 531 return GNUNET_OK;
540} 532}
541 533
@@ -548,8 +540,7 @@ main_init (struct GNUNET_SERVER_Handle *server,
548 * @param cfg configuration to use 540 * @param cfg configuration to use
549 */ 541 */
550static void 542static void
551run (void *cls, 543run (void *cls, struct GNUNET_SERVER_Handle *server,
552 struct GNUNET_SERVER_Handle *server,
553 const struct GNUNET_CONFIGURATION_Handle *cfg) 544 const struct GNUNET_CONFIGURATION_Handle *cfg)
554{ 545{
555 GSF_cfg = cfg; 546 GSF_cfg = cfg;
@@ -594,10 +585,8 @@ int
594main (int argc, char *const *argv) 585main (int argc, char *const *argv)
595{ 586{
596 return (GNUNET_OK == 587 return (GNUNET_OK ==
597 GNUNET_SERVICE_run (argc, 588 GNUNET_SERVICE_run (argc, argv, "fs", GNUNET_SERVICE_OPTION_NONE,
598 argv, 589 &run, NULL)) ? 0 : 1;
599 "fs",
600 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
601} 590}
602 591
603/* end of gnunet-service-fs.c */ 592/* end of gnunet-service-fs.c */
diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c
index 4e57455b2..1e93a475e 100644
--- a/src/fs/gnunet-service-fs_cp.c
+++ b/src/fs/gnunet-service-fs_cp.c
@@ -400,13 +400,12 @@ static size_t peer_transmit_ready_cb (void *cls, size_t size, void *buf);
400 * long should the client wait until re-trying? 400 * long should the client wait until re-trying?
401 * @param preference current traffic preference for the given peer 401 * @param preference current traffic preference for the given peer
402 */ 402 */
403static void 403static void core_reserve_callback (void *cls,
404core_reserve_callback (void *cls, 404 const struct GNUNET_PeerIdentity *peer,
405 const struct GNUNET_PeerIdentity *peer, 405 struct GNUNET_BANDWIDTH_Value32NBO
406 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 406 bandwidth_out, int32_t amount,
407 int32_t amount, 407 struct GNUNET_TIME_Relative res_delay,
408 struct GNUNET_TIME_Relative res_delay, 408 uint64_t preference);
409 uint64_t preference);
410 409
411 410
412/** 411/**
@@ -437,23 +436,20 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth)
437 pth->was_reserved = GNUNET_YES; 436 pth->was_reserved = GNUNET_YES;
438 ip = cp->inc_preference; 437 ip = cp->inc_preference;
439 cp->inc_preference = 0; 438 cp->inc_preference = 0;
440 cp->irc = GNUNET_CORE_peer_change_preference (GSF_core, 439 cp->irc =
441 &target, 440 GNUNET_CORE_peer_change_preference (GSF_core, &target,
442 GNUNET_TIME_UNIT_FOREVER_REL, 441 GNUNET_TIME_UNIT_FOREVER_REL,
443 GNUNET_BANDWIDTH_VALUE_MAX, 442 GNUNET_BANDWIDTH_VALUE_MAX,
444 DBLOCK_SIZE, 443 DBLOCK_SIZE, ip,
445 ip, 444 &core_reserve_callback, cp);
446 &core_reserve_callback, cp);
447 } 445 }
448 GNUNET_assert (pth->cth == NULL); 446 GNUNET_assert (pth->cth == NULL);
449 pth->cth_in_progress++; 447 pth->cth_in_progress++;
450 pth->cth = GNUNET_CORE_notify_transmit_ready (GSF_core, 448 pth->cth =
451 GNUNET_YES, 449 GNUNET_CORE_notify_transmit_ready (GSF_core, GNUNET_YES, pth->priority,
452 pth->priority, 450 GNUNET_TIME_absolute_get_remaining
453 GNUNET_TIME_absolute_get_remaining 451 (pth->timeout), &target, pth->size,
454 (pth->timeout), &target, 452 &peer_transmit_ready_cb, pth);
455 pth->size,
456 &peer_transmit_ready_cb, pth);
457 GNUNET_assert (0 < pth->cth_in_progress--); 453 GNUNET_assert (0 < pth->cth_in_progress--);
458} 454}
459 455
@@ -495,8 +491,9 @@ peer_transmit_ready_cb (void *cls, size_t size, void *buf)
495 GNUNET_assert (0 < cp->ppd.pending_replies--); 491 GNUNET_assert (0 < cp->ppd.pending_replies--);
496 } 492 }
497 GNUNET_LOAD_update (cp->ppd.transmission_delay, 493 GNUNET_LOAD_update (cp->ppd.transmission_delay,
498 GNUNET_TIME_absolute_get_duration 494 GNUNET_TIME_absolute_get_duration (pth->
499 (pth->transmission_request_start_time).rel_value); 495 transmission_request_start_time).
496 rel_value);
500 ret = pth->gmc (pth->gmc_cls, size, buf); 497 ret = pth->gmc (pth->gmc_cls, size, buf);
501 GNUNET_assert (NULL == pth->cth); 498 GNUNET_assert (NULL == pth->cth);
502 for (pos = cp->pth_head; pos != NULL; pos = pos->next) 499 for (pos = cp->pth_head; pos != NULL; pos = pos->next)
@@ -528,12 +525,12 @@ retry_reservation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
528 cp->irc_delay_task = GNUNET_SCHEDULER_NO_TASK; 525 cp->irc_delay_task = GNUNET_SCHEDULER_NO_TASK;
529 ip = cp->inc_preference; 526 ip = cp->inc_preference;
530 cp->inc_preference = 0; 527 cp->inc_preference = 0;
531 cp->irc = GNUNET_CORE_peer_change_preference (GSF_core, 528 cp->irc =
532 &target, 529 GNUNET_CORE_peer_change_preference (GSF_core, &target,
533 GNUNET_TIME_UNIT_FOREVER_REL, 530 GNUNET_TIME_UNIT_FOREVER_REL,
534 GNUNET_BANDWIDTH_VALUE_MAX, 531 GNUNET_BANDWIDTH_VALUE_MAX,
535 DBLOCK_SIZE, 532 DBLOCK_SIZE, ip,
536 ip, &core_reserve_callback, cp); 533 &core_reserve_callback, cp);
537} 534}
538 535
539 536
@@ -550,11 +547,9 @@ retry_reservation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
550 * @param preference current traffic preference for the given peer 547 * @param preference current traffic preference for the given peer
551 */ 548 */
552static void 549static void
553core_reserve_callback (void *cls, 550core_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
554 const struct GNUNET_PeerIdentity *peer,
555 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 551 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
556 int32_t amount, 552 int32_t amount, struct GNUNET_TIME_Relative res_delay,
557 struct GNUNET_TIME_Relative res_delay,
558 uint64_t preference) 553 uint64_t preference)
559{ 554{
560 struct GSF_ConnectedPeer *cp = cls; 555 struct GSF_ConnectedPeer *cp = cls;
@@ -563,8 +558,8 @@ core_reserve_callback (void *cls,
563 cp->irc = NULL; 558 cp->irc = NULL;
564 if (0 == amount) 559 if (0 == amount)
565 { 560 {
566 cp->irc_delay_task = GNUNET_SCHEDULER_add_delayed (res_delay, 561 cp->irc_delay_task =
567 &retry_reservation, cp); 562 GNUNET_SCHEDULER_add_delayed (res_delay, &retry_reservation, cp);
568 return; 563 return;
569 } 564 }
570 cp->did_reserve = GNUNET_YES; 565 cp->did_reserve = GNUNET_YES;
@@ -573,13 +568,11 @@ core_reserve_callback (void *cls,
573 { 568 {
574 /* reservation success, try transmission now! */ 569 /* reservation success, try transmission now! */
575 pth->cth_in_progress++; 570 pth->cth_in_progress++;
576 pth->cth = GNUNET_CORE_notify_transmit_ready (GSF_core, 571 pth->cth =
577 GNUNET_YES, 572 GNUNET_CORE_notify_transmit_ready (GSF_core, GNUNET_YES, pth->priority,
578 pth->priority, 573 GNUNET_TIME_absolute_get_remaining
579 GNUNET_TIME_absolute_get_remaining 574 (pth->timeout), peer, pth->size,
580 (pth->timeout), peer, 575 &peer_transmit_ready_cb, pth);
581 pth->size,
582 &peer_transmit_ready_cb, pth);
583 GNUNET_assert (0 < pth->cth_in_progress--); 576 GNUNET_assert (0 < pth->cth_in_progress--);
584 } 577 }
585} 578}
@@ -604,12 +597,12 @@ GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
604 cp = GNUNET_malloc (sizeof (struct GSF_ConnectedPeer)); 597 cp = GNUNET_malloc (sizeof (struct GSF_ConnectedPeer));
605 cp->ppd.pid = GNUNET_PEER_intern (peer); 598 cp->ppd.pid = GNUNET_PEER_intern (peer);
606 cp->ppd.transmission_delay = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_ZERO); 599 cp->ppd.transmission_delay = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_ZERO);
607 cp->irc = GNUNET_CORE_peer_change_preference (GSF_core, 600 cp->irc =
608 peer, 601 GNUNET_CORE_peer_change_preference (GSF_core, peer,
609 GNUNET_TIME_UNIT_FOREVER_REL, 602 GNUNET_TIME_UNIT_FOREVER_REL,
610 GNUNET_BANDWIDTH_VALUE_MAX, 603 GNUNET_BANDWIDTH_VALUE_MAX,
611 DBLOCK_SIZE, 604 DBLOCK_SIZE, 0,
612 0, &core_reserve_callback, cp); 605 &core_reserve_callback, cp);
613 fn = get_trust_filename (peer); 606 fn = get_trust_filename (peer);
614 if ((GNUNET_DISK_file_test (fn) == GNUNET_YES) && 607 if ((GNUNET_DISK_file_test (fn) == GNUNET_YES) &&
615 (sizeof (trust) == GNUNET_DISK_fn_read (fn, &trust, sizeof (trust)))) 608 (sizeof (trust) == GNUNET_DISK_fn_read (fn, &trust, sizeof (trust))))
@@ -617,8 +610,7 @@ GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
617 GNUNET_free (fn); 610 GNUNET_free (fn);
618 cp->request_map = GNUNET_CONTAINER_multihashmap_create (128); 611 cp->request_map = GNUNET_CONTAINER_multihashmap_create (128);
619 GNUNET_break (GNUNET_OK == 612 GNUNET_break (GNUNET_OK ==
620 GNUNET_CONTAINER_multihashmap_put (cp_map, 613 GNUNET_CONTAINER_multihashmap_put (cp_map, &peer->hashPubKey,
621 &peer->hashPubKey,
622 cp, 614 cp,
623 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 615 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
624 update_atsi (cp, atsi); 616 update_atsi (cp, atsi);
@@ -645,8 +637,8 @@ revive_migration (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
645 if (0 != bt.rel_value) 637 if (0 != bt.rel_value)
646 { 638 {
647 /* still time left... */ 639 /* still time left... */
648 cp->mig_revive_task 640 cp->mig_revive_task =
649 = GNUNET_SCHEDULER_add_delayed (bt, &revive_migration, cp); 641 GNUNET_SCHEDULER_add_delayed (bt, &revive_migration, cp);
650 return; 642 return;
651 } 643 }
652 GSF_push_start_ (cp); 644 GSF_push_start_ (cp);
@@ -705,8 +697,8 @@ GSF_handle_p2p_migration_stop_ (void *cls,
705 if (cp->mig_revive_task == GNUNET_SCHEDULER_NO_TASK) 697 if (cp->mig_revive_task == GNUNET_SCHEDULER_NO_TASK)
706 { 698 {
707 GSF_push_stop_ (cp); 699 GSF_push_stop_ (cp);
708 cp->mig_revive_task 700 cp->mig_revive_task =
709 = GNUNET_SCHEDULER_add_delayed (bt, &revive_migration, cp); 701 GNUNET_SCHEDULER_add_delayed (bt, &revive_migration, cp);
710 } 702 }
711 update_atsi (cp, atsi); 703 update_atsi (cp, atsi);
712 return GNUNET_OK; 704 return GNUNET_OK;
@@ -740,8 +732,8 @@ copy_reply (void *cls, size_t buf_size, void *buf)
740 else 732 else
741 { 733 {
742 size = 0; 734 size = 0;
743 GNUNET_STATISTICS_update (GSF_stats, 735 GNUNET_STATISTICS_update (GSF_stats, gettext_noop ("# replies dropped"), 1,
744 gettext_noop ("# replies dropped"), 1, GNUNET_NO); 736 GNUNET_NO);
745 } 737 }
746 GNUNET_free (pm); 738 GNUNET_free (pm);
747 return size; 739 return size;
@@ -769,8 +761,7 @@ cancel_pending_request (void *cls, const GNUNET_HashCode * query, void *value)
769 GNUNET_SCHEDULER_cancel (peerreq->kill_task); 761 GNUNET_SCHEDULER_cancel (peerreq->kill_task);
770 peerreq->kill_task = GNUNET_SCHEDULER_NO_TASK; 762 peerreq->kill_task = GNUNET_SCHEDULER_NO_TASK;
771 } 763 }
772 GNUNET_STATISTICS_update (GSF_stats, 764 GNUNET_STATISTICS_update (GSF_stats, gettext_noop ("# P2P searches active"),
773 gettext_noop ("# P2P searches active"),
774 -1, GNUNET_NO); 765 -1, GNUNET_NO);
775 prd = GSF_pending_request_get_data_ (pr); 766 prd = GSF_pending_request_get_data_ (pr);
776 GNUNET_break (GNUNET_YES == 767 GNUNET_break (GNUNET_YES ==
@@ -820,9 +811,8 @@ transmit_delayed_now (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
820 GNUNET_free (dh); 811 GNUNET_free (dh);
821 return; 812 return;
822 } 813 }
823 (void) GSF_peer_transmit_ (cp, GNUNET_NO, 814 (void) GSF_peer_transmit_ (cp, GNUNET_NO, UINT32_MAX, REPLY_TIMEOUT,
824 UINT32_MAX, 815 dh->msize, &copy_reply, dh->pm);
825 REPLY_TIMEOUT, dh->msize, &copy_reply, dh->pm);
826 GNUNET_free (dh); 816 GNUNET_free (dh);
827} 817}
828 818
@@ -838,9 +828,10 @@ get_randomized_delay ()
838 struct GNUNET_TIME_Relative ret; 828 struct GNUNET_TIME_Relative ret;
839 829
840 /* FIXME: replace 5000 with something relating to current observed P2P message latency */ 830 /* FIXME: replace 5000 with something relating to current observed P2P message latency */
841 ret = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 831 ret =
842 GNUNET_CRYPTO_random_u32 832 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
843 (GNUNET_CRYPTO_QUALITY_WEAK, 5000)); 833 GNUNET_CRYPTO_random_u32
834 (GNUNET_CRYPTO_QUALITY_WEAK, 5000));
844 GNUNET_STATISTICS_update (GSF_stats, 835 GNUNET_STATISTICS_update (GSF_stats,
845 gettext_noop 836 gettext_noop
846 ("# artificial delays introduced (ms)"), 837 ("# artificial delays introduced (ms)"),
@@ -868,13 +859,11 @@ get_randomized_delay ()
868 * @param data_len number of bytes in data 859 * @param data_len number of bytes in data
869 */ 860 */
870static void 861static void
871handle_p2p_reply (void *cls, 862handle_p2p_reply (void *cls, enum GNUNET_BLOCK_EvaluationResult eval,
872 enum GNUNET_BLOCK_EvaluationResult eval, 863 struct GSF_PendingRequest *pr, uint32_t reply_anonymity_level,
873 struct GSF_PendingRequest *pr,
874 uint32_t reply_anonymity_level,
875 struct GNUNET_TIME_Absolute expiration, 864 struct GNUNET_TIME_Absolute expiration,
876 enum GNUNET_BLOCK_Type type, 865 enum GNUNET_BLOCK_Type type, const void *data,
877 const void *data, size_t data_len) 866 size_t data_len)
878{ 867{
879 struct PeerRequest *peerreq = cls; 868 struct PeerRequest *peerreq = cls;
880 struct GSF_ConnectedPeer *cp = peerreq->cp; 869 struct GSF_ConnectedPeer *cp = peerreq->cp;
@@ -888,8 +877,7 @@ handle_p2p_reply (void *cls,
888 prd = GSF_pending_request_get_data_ (pr); 877 prd = GSF_pending_request_get_data_ (pr);
889 if (NULL == data) 878 if (NULL == data)
890 { 879 {
891 GNUNET_STATISTICS_update (GSF_stats, 880 GNUNET_STATISTICS_update (GSF_stats, gettext_noop ("# P2P searches active"),
892 gettext_noop ("# P2P searches active"),
893 -1, GNUNET_NO); 881 -1, GNUNET_NO);
894 GNUNET_break (GNUNET_YES == 882 GNUNET_break (GNUNET_YES ==
895 GNUNET_CONTAINER_multihashmap_remove (cp->request_map, 883 GNUNET_CONTAINER_multihashmap_remove (cp->request_map,
@@ -936,8 +924,7 @@ handle_p2p_reply (void *cls,
936 pm->type = htonl (type); 924 pm->type = htonl (type);
937 pm->expiration = GNUNET_TIME_absolute_hton (expiration); 925 pm->expiration = GNUNET_TIME_absolute_hton (expiration);
938 memcpy (&pm[1], data, data_len); 926 memcpy (&pm[1], data, data_len);
939 if ((reply_anonymity_level != UINT32_MAX) && 927 if ((reply_anonymity_level != UINT32_MAX) && (reply_anonymity_level != 0) &&
940 (reply_anonymity_level != 0) &&
941 (GSF_enable_randomized_delays == GNUNET_YES)) 928 (GSF_enable_randomized_delays == GNUNET_YES))
942 { 929 {
943 struct GSF_DelayedHandle *dh; 930 struct GSF_DelayedHandle *dh;
@@ -947,14 +934,14 @@ handle_p2p_reply (void *cls,
947 dh->pm = pm; 934 dh->pm = pm;
948 dh->msize = msize; 935 dh->msize = msize;
949 GNUNET_CONTAINER_DLL_insert (cp->delayed_head, cp->delayed_tail, dh); 936 GNUNET_CONTAINER_DLL_insert (cp->delayed_head, cp->delayed_tail, dh);
950 dh->delay_task = GNUNET_SCHEDULER_add_delayed (get_randomized_delay (), 937 dh->delay_task =
951 &transmit_delayed_now, dh); 938 GNUNET_SCHEDULER_add_delayed (get_randomized_delay (),
939 &transmit_delayed_now, dh);
952 } 940 }
953 else 941 else
954 { 942 {
955 (void) GSF_peer_transmit_ (cp, GNUNET_NO, 943 (void) GSF_peer_transmit_ (cp, GNUNET_NO, UINT32_MAX, REPLY_TIMEOUT, msize,
956 UINT32_MAX, 944 &copy_reply, pm);
957 REPLY_TIMEOUT, msize, &copy_reply, pm);
958 } 945 }
959 if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST) 946 if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST)
960 return; 947 return;
@@ -1220,8 +1207,8 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
1220#if DEBUG_FS 1207#if DEBUG_FS
1221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1222 "Received request for `%s' of type %u from peer `%4s' with flags %u\n", 1209 "Received request for `%s' of type %u from peer `%4s' with flags %u\n",
1223 GNUNET_h2s (&gm->query), 1210 GNUNET_h2s (&gm->query), (unsigned int) type, GNUNET_i2s (other),
1224 (unsigned int) type, GNUNET_i2s (other), (unsigned int) bm); 1211 (unsigned int) bm);
1225#endif 1212#endif
1226 namespace = (0 != (bm & GET_MESSAGE_BIT_SKS_NAMESPACE)) ? &opt[bits++] : NULL; 1213 namespace = (0 != (bm & GET_MESSAGE_BIT_SKS_NAMESPACE)) ? &opt[bits++] : NULL;
1227 if ((type == GNUNET_BLOCK_TYPE_FS_SBLOCK) && (namespace == NULL)) 1214 if ((type == GNUNET_BLOCK_TYPE_FS_SBLOCK) && (namespace == NULL))
@@ -1254,8 +1241,9 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
1254 } 1241 }
1255 ttl = bound_ttl (ntohl (gm->ttl), priority); 1242 ttl = bound_ttl (ntohl (gm->ttl), priority);
1256 /* decrement ttl (always) */ 1243 /* decrement ttl (always) */
1257 ttl_decrement = 2 * TTL_DECREMENT + 1244 ttl_decrement =
1258 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, TTL_DECREMENT); 1245 2 * TTL_DECREMENT + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1246 TTL_DECREMENT);
1259 if ((ttl < 0) && (((int32_t) (ttl - ttl_decrement)) > 0)) 1247 if ((ttl < 0) && (((int32_t) (ttl - ttl_decrement)) > 0))
1260 { 1248 {
1261#if DEBUG_FS 1249#if DEBUG_FS
@@ -1299,8 +1287,8 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
1299 } 1287 }
1300 /* existing request has lower TTL, drop old one! */ 1288 /* existing request has lower TTL, drop old one! */
1301 GNUNET_STATISTICS_update (GSF_stats, 1289 GNUNET_STATISTICS_update (GSF_stats,
1302 gettext_noop ("# P2P searches active"), 1290 gettext_noop ("# P2P searches active"), -1,
1303 -1, GNUNET_NO); 1291 GNUNET_NO);
1304 priority += prd->priority; 1292 priority += prd->priority;
1305 GSF_pending_request_cancel_ (pr, GNUNET_YES); 1293 GSF_pending_request_cancel_ (pr, GNUNET_YES);
1306 GNUNET_assert (GNUNET_YES == 1294 GNUNET_assert (GNUNET_YES ==
@@ -1318,10 +1306,7 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
1318 1306
1319 peerreq = GNUNET_malloc (sizeof (struct PeerRequest)); 1307 peerreq = GNUNET_malloc (sizeof (struct PeerRequest));
1320 peerreq->cp = cp; 1308 peerreq->cp = cp;
1321 pr = GSF_pending_request_create_ (options, 1309 pr = GSF_pending_request_create_ (options, type, &gm->query, namespace,
1322 type,
1323 &gm->query,
1324 namespace,
1325 target, 1310 target,
1326 (bfsize > 1311 (bfsize >
1327 0) ? (const char *) &opt[bits] : NULL, 1312 0) ? (const char *) &opt[bits] : NULL,
@@ -1332,8 +1317,7 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
1332 GNUNET_assert (NULL != pr); 1317 GNUNET_assert (NULL != pr);
1333 peerreq->pr = pr; 1318 peerreq->pr = pr;
1334 GNUNET_break (GNUNET_OK == 1319 GNUNET_break (GNUNET_OK ==
1335 GNUNET_CONTAINER_multihashmap_put (cp->request_map, 1320 GNUNET_CONTAINER_multihashmap_put (cp->request_map, &gm->query,
1336 &gm->query,
1337 peerreq, 1321 peerreq,
1338 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 1322 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
1339 GNUNET_STATISTICS_update (GSF_stats, 1323 GNUNET_STATISTICS_update (GSF_stats,
@@ -1397,10 +1381,8 @@ peer_transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1397 * @return handle to cancel request 1381 * @return handle to cancel request
1398 */ 1382 */
1399struct GSF_PeerTransmitHandle * 1383struct GSF_PeerTransmitHandle *
1400GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp, 1384GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp, int is_query,
1401 int is_query, 1385 uint32_t priority, struct GNUNET_TIME_Relative timeout,
1402 uint32_t priority,
1403 struct GNUNET_TIME_Relative timeout,
1404 size_t size, GSF_GetMessageCallback gmc, void *gmc_cls) 1386 size_t size, GSF_GetMessageCallback gmc, void *gmc_cls)
1405{ 1387{
1406 struct GSF_PeerTransmitHandle *pth; 1388 struct GSF_PeerTransmitHandle *pth;
@@ -1432,9 +1414,8 @@ GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp,
1432 cp->ppd.pending_queries++; 1414 cp->ppd.pending_queries++;
1433 else if (GNUNET_NO == is_query) 1415 else if (GNUNET_NO == is_query)
1434 cp->ppd.pending_replies++; 1416 cp->ppd.pending_replies++;
1435 pth->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, 1417 pth->timeout_task =
1436 &peer_transmit_timeout, 1418 GNUNET_SCHEDULER_add_delayed (timeout, &peer_transmit_timeout, pth);
1437 pth);
1438 schedule_transmission (pth); 1419 schedule_transmission (pth);
1439 return pth; 1420 return pth;
1440} 1421}
@@ -1544,8 +1525,7 @@ GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp,
1544 * @param atsi status information 1525 * @param atsi status information
1545 */ 1526 */
1546void 1527void
1547GSF_peer_status_handler_ (void *cls, 1528GSF_peer_status_handler_ (void *cls, const struct GNUNET_PeerIdentity *peer,
1548 const struct GNUNET_PeerIdentity *peer,
1549 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 1529 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1550 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 1530 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
1551 struct GNUNET_TIME_Absolute timeout, 1531 struct GNUNET_TIME_Absolute timeout,
@@ -1752,27 +1732,24 @@ GSF_block_peer_migration_ (struct GSF_ConnectedPeer *cp,
1752#if DEBUG_FS && 0 1732#if DEBUG_FS && 0
1753 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1733 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1754 "Migration already blocked for another %llu ms\n", 1734 "Migration already blocked for another %llu ms\n",
1755 (unsigned long long) 1735 (unsigned long long) GNUNET_TIME_absolute_get_remaining (cp->
1756 GNUNET_TIME_absolute_get_remaining 1736 last_migration_block).
1757 (cp->last_migration_block).rel_value); 1737 rel_value);
1758#endif 1738#endif
1759 return; /* already blocked */ 1739 return; /* already blocked */
1760 } 1740 }
1761#if DEBUG_FS && 0 1741#if DEBUG_FS && 0
1762 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1742 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking to stop migration for %llu ms\n",
1763 "Asking to stop migration for %llu ms\n",
1764 (unsigned long long) block_time.rel_value); 1743 (unsigned long long) block_time.rel_value);
1765#endif 1744#endif
1766 cp->last_migration_block = GNUNET_TIME_relative_to_absolute (block_time); 1745 cp->last_migration_block = GNUNET_TIME_relative_to_absolute (block_time);
1767 if (cp->migration_pth != NULL) 1746 if (cp->migration_pth != NULL)
1768 GSF_peer_transmit_cancel_ (cp->migration_pth); 1747 GSF_peer_transmit_cancel_ (cp->migration_pth);
1769 cp->migration_pth 1748 cp->migration_pth =
1770 = GSF_peer_transmit_ (cp, 1749 GSF_peer_transmit_ (cp, GNUNET_SYSERR, UINT32_MAX,
1771 GNUNET_SYSERR, 1750 GNUNET_TIME_UNIT_FOREVER_REL,
1772 UINT32_MAX, 1751 sizeof (struct MigrationStopMessage),
1773 GNUNET_TIME_UNIT_FOREVER_REL, 1752 &create_migration_stop_message, cp);
1774 sizeof (struct MigrationStopMessage),
1775 &create_migration_stop_message, cp);
1776} 1753}
1777 1754
1778 1755
@@ -1806,12 +1783,12 @@ flush_trust (void *cls, const GNUNET_HashCode * key, void *value)
1806 else 1783 else
1807 { 1784 {
1808 trust = htonl (cp->ppd.trust); 1785 trust = htonl (cp->ppd.trust);
1809 if (sizeof (uint32_t) == GNUNET_DISK_fn_write (fn, &trust, 1786 if (sizeof (uint32_t) ==
1810 sizeof (uint32_t), 1787 GNUNET_DISK_fn_write (fn, &trust, sizeof (uint32_t),
1811 GNUNET_DISK_PERM_USER_READ | 1788 GNUNET_DISK_PERM_USER_READ |
1812 GNUNET_DISK_PERM_USER_WRITE | 1789 GNUNET_DISK_PERM_USER_WRITE |
1813 GNUNET_DISK_PERM_GROUP_READ | 1790 GNUNET_DISK_PERM_GROUP_READ |
1814 GNUNET_DISK_PERM_OTHER_READ)) 1791 GNUNET_DISK_PERM_OTHER_READ))
1815 cp->disk_trust = cp->ppd.trust; 1792 cp->disk_trust = cp->ppd.trust;
1816 } 1793 }
1817 GNUNET_free (fn); 1794 GNUNET_free (fn);
@@ -1865,8 +1842,7 @@ GSF_connected_peer_init_ ()
1865{ 1842{
1866 cp_map = GNUNET_CONTAINER_multihashmap_create (128); 1843 cp_map = GNUNET_CONTAINER_multihashmap_create (128);
1867 GNUNET_assert (GNUNET_OK == 1844 GNUNET_assert (GNUNET_OK ==
1868 GNUNET_CONFIGURATION_get_value_filename (GSF_cfg, 1845 GNUNET_CONFIGURATION_get_value_filename (GSF_cfg, "fs",
1869 "fs",
1870 "TRUST", 1846 "TRUST",
1871 &trustDirectory)); 1847 &trustDirectory));
1872 GNUNET_DISK_directory_create (trustDirectory); 1848 GNUNET_DISK_directory_create (trustDirectory);
@@ -1939,8 +1915,8 @@ GSF_handle_local_client_disconnect_ (const struct GSF_LocalClient *lc)
1939{ 1915{
1940 if (NULL == cp_map) 1916 if (NULL == cp_map)
1941 return; /* already cleaned up */ 1917 return; /* already cleaned up */
1942 GNUNET_CONTAINER_multihashmap_iterate (cp_map, 1918 GNUNET_CONTAINER_multihashmap_iterate (cp_map, &clean_local_client,
1943 &clean_local_client, (void *) lc); 1919 (void *) lc);
1944} 1920}
1945 1921
1946 1922
diff --git a/src/fs/gnunet-service-fs_indexing.c b/src/fs/gnunet-service-fs_indexing.c
index 4bf02adb0..c7bff3a9d 100644
--- a/src/fs/gnunet-service-fs_indexing.c
+++ b/src/fs/gnunet-service-fs_indexing.c
@@ -126,9 +126,7 @@ write_index_list ()
126 while (pos != NULL) 126 while (pos != NULL)
127 { 127 {
128 if ((GNUNET_OK != 128 if ((GNUNET_OK !=
129 GNUNET_BIO_write (wh, 129 GNUNET_BIO_write (wh, &pos->file_id, sizeof (GNUNET_HashCode))) ||
130 &pos->file_id,
131 sizeof (GNUNET_HashCode))) ||
132 (GNUNET_OK != GNUNET_BIO_write_string (wh, pos->filename))) 130 (GNUNET_OK != GNUNET_BIO_write_string (wh, pos->filename)))
133 break; 131 break;
134 pos = pos->next; 132 pos = pos->next;
@@ -181,14 +179,11 @@ read_index_list ()
181 return; 179 return;
182 } 180 }
183 while ((GNUNET_OK == 181 while ((GNUNET_OK ==
184 GNUNET_BIO_read (rh, 182 GNUNET_BIO_read (rh, "Hash of indexed file", &hc,
185 "Hash of indexed file",
186 &hc,
187 sizeof (GNUNET_HashCode))) && 183 sizeof (GNUNET_HashCode))) &&
188 (GNUNET_OK == 184 (GNUNET_OK ==
189 GNUNET_BIO_read_string (rh, 185 GNUNET_BIO_read_string (rh, "Name of indexed file", &fname,
190 "Name of indexed file", 186 1024 * 16)) && (fname != NULL))
191 &fname, 1024 * 16)) && (fname != NULL))
192 { 187 {
193 slen = strlen (fname) + 1; 188 slen = strlen (fname) + 1;
194 pos = GNUNET_malloc (sizeof (struct IndexInfo) + slen); 189 pos = GNUNET_malloc (sizeof (struct IndexInfo) + slen);
@@ -196,9 +191,7 @@ read_index_list ()
196 pos->filename = (const char *) &pos[1]; 191 pos->filename = (const char *) &pos[1];
197 memcpy (&pos[1], fname, slen); 192 memcpy (&pos[1], fname, slen);
198 if (GNUNET_SYSERR == 193 if (GNUNET_SYSERR ==
199 GNUNET_CONTAINER_multihashmap_put (ifm, 194 GNUNET_CONTAINER_multihashmap_put (ifm, &hc, (void *) pos->filename,
200 &hc,
201 (void *) pos->filename,
202 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 195 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
203 { 196 {
204 GNUNET_free (pos); 197 GNUNET_free (pos);
@@ -226,8 +219,7 @@ static void
226signal_index_ok (struct IndexInfo *ii) 219signal_index_ok (struct IndexInfo *ii)
227{ 220{
228 if (GNUNET_SYSERR == 221 if (GNUNET_SYSERR ==
229 GNUNET_CONTAINER_multihashmap_put (ifm, 222 GNUNET_CONTAINER_multihashmap_put (ifm, &ii->file_id,
230 &ii->file_id,
231 (void *) ii->filename, 223 (void *) ii->filename,
232 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 224 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
233 { 225 {
@@ -236,7 +228,8 @@ signal_index_ok (struct IndexInfo *ii)
236 ("Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"), 228 ("Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"),
237 ii->filename, 229 ii->filename,
238 (const char *) GNUNET_CONTAINER_multihashmap_get (ifm, 230 (const char *) GNUNET_CONTAINER_multihashmap_get (ifm,
239 &ii->file_id)); 231 &ii->
232 file_id));
240 GNUNET_SERVER_transmit_context_append_data (ii->tc, NULL, 0, 233 GNUNET_SERVER_transmit_context_append_data (ii->tc, NULL, 0,
241 GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK); 234 GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
242 GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES); 235 GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES);
@@ -246,8 +239,7 @@ signal_index_ok (struct IndexInfo *ii)
246 ii->next = indexed_files; 239 ii->next = indexed_files;
247 indexed_files = ii; 240 indexed_files = ii;
248 write_index_list (); 241 write_index_list ();
249 GNUNET_SERVER_transmit_context_append_data (ii->tc, 242 GNUNET_SERVER_transmit_context_append_data (ii->tc, NULL, 0,
250 NULL, 0,
251 GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK); 243 GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
252 GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES); 244 GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES);
253 ii->tc = NULL; 245 ii->tc = NULL;
@@ -275,11 +267,10 @@ hash_for_index_val (void *cls, const GNUNET_HashCode * res)
275 ("Hash mismatch trying to index file `%s' which has hash `%s'\n"), 267 ("Hash mismatch trying to index file `%s' which has hash `%s'\n"),
276 ii->filename, GNUNET_h2s (res)); 268 ii->filename, GNUNET_h2s (res));
277#if DEBUG_FS 269#if DEBUG_FS
278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Wanted `%s'\n",
279 "Wanted `%s'\n", GNUNET_h2s (&ii->file_id)); 271 GNUNET_h2s (&ii->file_id));
280#endif 272#endif
281 GNUNET_SERVER_transmit_context_append_data (ii->tc, 273 GNUNET_SERVER_transmit_context_append_data (ii->tc, NULL, 0,
282 NULL, 0,
283 GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED); 274 GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED);
284 GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES); 275 GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES);
285 GNUNET_free (ii); 276 GNUNET_free (ii);
@@ -297,8 +288,7 @@ hash_for_index_val (void *cls, const GNUNET_HashCode * res)
297 * @param message the actual message 288 * @param message the actual message
298 */ 289 */
299void 290void
300GNUNET_FS_handle_index_start (void *cls, 291GNUNET_FS_handle_index_start (void *cls, struct GNUNET_SERVER_Client *client,
301 struct GNUNET_SERVER_Client *client,
302 const struct GNUNET_MessageHeader *message) 292 const struct GNUNET_MessageHeader *message)
303{ 293{
304 const struct IndexStartMessage *ism; 294 const struct IndexStartMessage *ism;
@@ -341,19 +331,15 @@ GNUNET_FS_handle_index_start (void *cls,
341 memcpy (&ii[1], fn, slen); 331 memcpy (&ii[1], fn, slen);
342 ii->file_id = ism->file_id; 332 ii->file_id = ism->file_id;
343#if DEBUG_FS 333#if DEBUG_FS
344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 334 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message for file `%s'\n",
345 "Received `%s' message for file `%s'\n",
346 "START_INDEX", ii->filename); 335 "START_INDEX", ii->filename);
347#endif 336#endif
348 337
349 ii->tc = GNUNET_SERVER_transmit_context_create (client); 338 ii->tc = GNUNET_SERVER_transmit_context_create (client);
350 mydev = 0; 339 mydev = 0;
351 myino = 0; 340 myino = 0;
352 if (((dev != 0) || 341 if (((dev != 0) || (ino != 0)) &&
353 (ino != 0)) && 342 (GNUNET_OK == GNUNET_DISK_file_get_identifiers (fn, &mydev, &myino)) &&
354 (GNUNET_OK == GNUNET_DISK_file_get_identifiers (fn,
355 &mydev,
356 &myino)) &&
357 ((dev == mydev) && (ino == myino))) 343 ((dev == mydev) && (ino == myino)))
358 { 344 {
359 /* fast validation OK! */ 345 /* fast validation OK! */
@@ -364,15 +350,13 @@ GNUNET_FS_handle_index_start (void *cls,
364#if DEBUG_FS 350#if DEBUG_FS
365 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 351 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
366 "Mismatch in file identifiers (%llu != %llu or %u != %u), need to hash.\n", 352 "Mismatch in file identifiers (%llu != %llu or %u != %u), need to hash.\n",
367 (unsigned long long) ino, 353 (unsigned long long) ino, (unsigned long long) myino,
368 (unsigned long long) myino,
369 (unsigned int) dev, (unsigned int) mydev); 354 (unsigned int) dev, (unsigned int) mydev);
370#endif 355#endif
371 /* slow validation, need to hash full file (again) */ 356 /* slow validation, need to hash full file (again) */
372 ii->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, 357 ii->fhc =
373 fn, 358 GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, fn,
374 HASHING_BLOCKSIZE, 359 HASHING_BLOCKSIZE, &hash_for_index_val, ii);
375 &hash_for_index_val, ii);
376 if (ii->fhc == NULL) 360 if (ii->fhc == NULL)
377 hash_for_index_val (ii, NULL); 361 hash_for_index_val (ii, NULL);
378 GNUNET_free (fn); 362 GNUNET_free (fn);
@@ -387,8 +371,7 @@ GNUNET_FS_handle_index_start (void *cls,
387 * @param message the actual message 371 * @param message the actual message
388 */ 372 */
389void 373void
390GNUNET_FS_handle_index_list_get (void *cls, 374GNUNET_FS_handle_index_list_get (void *cls, struct GNUNET_SERVER_Client *client,
391 struct GNUNET_SERVER_Client *client,
392 const struct GNUNET_MessageHeader *message) 375 const struct GNUNET_MessageHeader *message)
393{ 376{
394 struct GNUNET_SERVER_TransmitContext *tc; 377 struct GNUNET_SERVER_TransmitContext *tc;
@@ -419,8 +402,7 @@ GNUNET_FS_handle_index_list_get (void *cls,
419 GNUNET_SERVER_transmit_context_append_message (tc, &iim->header); 402 GNUNET_SERVER_transmit_context_append_message (tc, &iim->header);
420 pos = pos->next; 403 pos = pos->next;
421 } 404 }
422 GNUNET_SERVER_transmit_context_append_data (tc, 405 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
423 NULL, 0,
424 GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END); 406 GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END);
425 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_MINUTES); 407 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_MINUTES);
426} 408}
@@ -434,8 +416,7 @@ GNUNET_FS_handle_index_list_get (void *cls,
434 * @param message the actual message 416 * @param message the actual message
435 */ 417 */
436void 418void
437GNUNET_FS_handle_unindex (void *cls, 419GNUNET_FS_handle_unindex (void *cls, struct GNUNET_SERVER_Client *client,
438 struct GNUNET_SERVER_Client *client,
439 const struct GNUNET_MessageHeader *message) 420 const struct GNUNET_MessageHeader *message)
440{ 421{
441 const struct UnindexMessage *um; 422 const struct UnindexMessage *um;
@@ -465,10 +446,9 @@ GNUNET_FS_handle_unindex (void *cls,
465 else 446 else
466 prev->next = next; 447 prev->next = next;
467 GNUNET_break (GNUNET_OK == 448 GNUNET_break (GNUNET_OK ==
468 GNUNET_CONTAINER_multihashmap_remove (ifm, 449 GNUNET_CONTAINER_multihashmap_remove (ifm, &pos->file_id,
469 &pos->file_id, 450 (void *) pos->
470 (void *) 451 filename));
471 pos->filename));
472 GNUNET_free (pos); 452 GNUNET_free (pos);
473 found = GNUNET_YES; 453 found = GNUNET_YES;
474 } 454 }
@@ -486,8 +466,7 @@ GNUNET_FS_handle_unindex (void *cls,
486 if (GNUNET_YES == found) 466 if (GNUNET_YES == found)
487 write_index_list (); 467 write_index_list ();
488 tc = GNUNET_SERVER_transmit_context_create (client); 468 tc = GNUNET_SERVER_transmit_context_create (client);
489 GNUNET_SERVER_transmit_context_append_data (tc, 469 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
490 NULL, 0,
491 GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK); 470 GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK);
492 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_MINUTES); 471 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_MINUTES);
493} 472}
@@ -530,14 +509,11 @@ remove_cont (void *cls, int success, const char *msg)
530 * @return GNUNET_OK on success 509 * @return GNUNET_OK on success
531 */ 510 */
532int 511int
533GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key, 512GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key, uint32_t size,
534 uint32_t size, 513 const void *data, enum GNUNET_BLOCK_Type type,
535 const void *data, 514 uint32_t priority, uint32_t anonymity,
536 enum GNUNET_BLOCK_Type type, 515 struct GNUNET_TIME_Absolute expiration,
537 uint32_t priority, 516 uint64_t uid,
538 uint32_t anonymity,
539 struct GNUNET_TIME_Absolute
540 expiration, uint64_t uid,
541 GNUNET_DATASTORE_DatumProcessor cont, 517 GNUNET_DATASTORE_DatumProcessor cont,
542 void *cont_cls) 518 void *cont_cls)
543{ 519{
@@ -556,11 +532,7 @@ GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key,
556 if (size != sizeof (struct OnDemandBlock)) 532 if (size != sizeof (struct OnDemandBlock))
557 { 533 {
558 GNUNET_break (0); 534 GNUNET_break (0);
559 GNUNET_DATASTORE_remove (dsh, 535 GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1,
560 key,
561 size,
562 data,
563 -1, -1,
564 GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL); 536 GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL);
565 return GNUNET_SYSERR; 537 return GNUNET_SYSERR;
566 } 538 }
@@ -569,13 +541,11 @@ GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key,
569 fn = (const char *) GNUNET_CONTAINER_multihashmap_get (ifm, &odb->file_id); 541 fn = (const char *) GNUNET_CONTAINER_multihashmap_get (ifm, &odb->file_id);
570 fh = NULL; 542 fh = NULL;
571 if ((NULL == fn) || 543 if ((NULL == fn) ||
572 (NULL == (fh = GNUNET_DISK_file_open (fn, 544 (NULL ==
573 GNUNET_DISK_OPEN_READ, 545 (fh =
574 GNUNET_DISK_PERM_NONE))) || 546 GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ,
575 (off != 547 GNUNET_DISK_PERM_NONE))) ||
576 GNUNET_DISK_file_seek (fh, 548 (off != GNUNET_DISK_file_seek (fh, off, GNUNET_DISK_SEEK_SET)) ||
577 off,
578 GNUNET_DISK_SEEK_SET)) ||
579 (-1 == (nsize = GNUNET_DISK_file_read (fh, ndata, sizeof (ndata))))) 549 (-1 == (nsize = GNUNET_DISK_file_read (fh, ndata, sizeof (ndata)))))
580 { 550 {
581 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 551 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -585,11 +555,7 @@ GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key,
585 (fn == NULL) ? _("not indexed") : STRERROR (errno)); 555 (fn == NULL) ? _("not indexed") : STRERROR (errno));
586 if (fh != NULL) 556 if (fh != NULL)
587 GNUNET_DISK_file_close (fh); 557 GNUNET_DISK_file_close (fh);
588 GNUNET_DATASTORE_remove (dsh, 558 GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1,
589 key,
590 size,
591 data,
592 -1, -1,
593 GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL); 559 GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL);
594 return GNUNET_SYSERR; 560 return GNUNET_SYSERR;
595 } 561 }
@@ -601,13 +567,9 @@ GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key,
601 if (0 != memcmp (&query, key, sizeof (GNUNET_HashCode))) 567 if (0 != memcmp (&query, key, sizeof (GNUNET_HashCode)))
602 { 568 {
603 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 569 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
604 _("Indexed file `%s' changed at offset %llu\n"), 570 _("Indexed file `%s' changed at offset %llu\n"), fn,
605 fn, (unsigned long long) off); 571 (unsigned long long) off);
606 GNUNET_DATASTORE_remove (dsh, 572 GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1,
607 key,
608 size,
609 data,
610 -1, -1,
611 GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL); 573 GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL);
612 return GNUNET_SYSERR; 574 return GNUNET_SYSERR;
613 } 575 }
@@ -615,11 +577,8 @@ GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key,
615 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
616 "On-demand encoded block for query `%s'\n", GNUNET_h2s (key)); 578 "On-demand encoded block for query `%s'\n", GNUNET_h2s (key));
617#endif 579#endif
618 cont (cont_cls, 580 cont (cont_cls, key, nsize, edata, GNUNET_BLOCK_TYPE_FS_DBLOCK, priority,
619 key, 581 anonymity, expiration, uid);
620 nsize,
621 edata,
622 GNUNET_BLOCK_TYPE_FS_DBLOCK, priority, anonymity, expiration, uid);
623 return GNUNET_OK; 582 return GNUNET_OK;
624} 583}
625 584
diff --git a/src/fs/gnunet-service-fs_lc.c b/src/fs/gnunet-service-fs_lc.c
index aa6569387..6460d4f13 100644
--- a/src/fs/gnunet-service-fs_lc.c
+++ b/src/fs/gnunet-service-fs_lc.c
@@ -199,8 +199,8 @@ client_request_destroy (void *cls,
199 GNUNET_CONTAINER_DLL_remove (lc->cr_head, lc->cr_tail, cr); 199 GNUNET_CONTAINER_DLL_remove (lc->cr_head, lc->cr_tail, cr);
200 GSF_pending_request_cancel_ (cr->pr, GNUNET_NO); 200 GSF_pending_request_cancel_ (cr->pr, GNUNET_NO);
201 GNUNET_STATISTICS_update (GSF_stats, 201 GNUNET_STATISTICS_update (GSF_stats,
202 gettext_noop ("# client searches active"), 202 gettext_noop ("# client searches active"), -1,
203 -1, GNUNET_NO); 203 GNUNET_NO);
204 GNUNET_free (cr); 204 GNUNET_free (cr);
205} 205}
206 206
@@ -223,13 +223,12 @@ client_request_destroy (void *cls,
223 * @param data_len number of bytes in data 223 * @param data_len number of bytes in data
224 */ 224 */
225static void 225static void
226client_response_handler (void *cls, 226client_response_handler (void *cls, enum GNUNET_BLOCK_EvaluationResult eval,
227 enum GNUNET_BLOCK_EvaluationResult eval,
228 struct GSF_PendingRequest *pr, 227 struct GSF_PendingRequest *pr,
229 uint32_t reply_anonymity_level, 228 uint32_t reply_anonymity_level,
230 struct GNUNET_TIME_Absolute expiration, 229 struct GNUNET_TIME_Absolute expiration,
231 enum GNUNET_BLOCK_Type type, 230 enum GNUNET_BLOCK_Type type, const void *data,
232 const void *data, size_t data_len) 231 size_t data_len)
233{ 232{
234 struct ClientRequest *cr = cls; 233 struct ClientRequest *cr = cls;
235 struct GSF_LocalClient *lc; 234 struct GSF_LocalClient *lc;
@@ -310,8 +309,8 @@ GSF_local_client_start_search_handler_ (struct GNUNET_SERVER_Client *client,
310 return NULL; 309 return NULL;
311 } 310 }
312 GNUNET_STATISTICS_update (GSF_stats, 311 GNUNET_STATISTICS_update (GSF_stats,
313 gettext_noop ("# client searches received"), 312 gettext_noop ("# client searches received"), 1,
314 1, GNUNET_NO); 313 GNUNET_NO);
315 sc = (msize - sizeof (struct SearchMessage)) / sizeof (GNUNET_HashCode); 314 sc = (msize - sizeof (struct SearchMessage)) / sizeof (GNUNET_HashCode);
316 sm = (const struct SearchMessage *) message; 315 sm = (const struct SearchMessage *) message;
317 type = ntohl (sm->type); 316 type = ntohl (sm->type);
@@ -334,9 +333,8 @@ GSF_local_client_start_search_handler_ (struct GNUNET_SERVER_Client *client,
334 while (cr != NULL) 333 while (cr != NULL)
335 { 334 {
336 prd = GSF_pending_request_get_data_ (cr->pr); 335 prd = GSF_pending_request_get_data_ (cr->pr);
337 if ((0 != memcmp (&prd->query, 336 if ((0 != memcmp (&prd->query, &sm->query, sizeof (GNUNET_HashCode))) &&
338 &sm->query, 337 (prd->type == type))
339 sizeof (GNUNET_HashCode))) && (prd->type == type))
340 break; 338 break;
341 cr = cr->next; 339 cr = cr->next;
342 } 340 }
@@ -346,8 +344,8 @@ GSF_local_client_start_search_handler_ (struct GNUNET_SERVER_Client *client,
346 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
347 "Have existing request, merging content-seen lists.\n"); 345 "Have existing request, merging content-seen lists.\n");
348#endif 346#endif
349 GSF_pending_request_update_ (cr->pr, 347 GSF_pending_request_update_ (cr->pr, (const GNUNET_HashCode *) &sm[1],
350 (const GNUNET_HashCode *) &sm[1], sc); 348 sc);
351 GNUNET_STATISTICS_update (GSF_stats, 349 GNUNET_STATISTICS_update (GSF_stats,
352 gettext_noop 350 gettext_noop
353 ("# client searches updated (merged content seen list)"), 351 ("# client searches updated (merged content seen list)"),
@@ -358,8 +356,8 @@ GSF_local_client_start_search_handler_ (struct GNUNET_SERVER_Client *client,
358 } 356 }
359 357
360 GNUNET_STATISTICS_update (GSF_stats, 358 GNUNET_STATISTICS_update (GSF_stats,
361 gettext_noop ("# client searches active"), 359 gettext_noop ("# client searches active"), 1,
362 1, GNUNET_NO); 360 GNUNET_NO);
363 cr = GNUNET_malloc (sizeof (struct ClientRequest)); 361 cr = GNUNET_malloc (sizeof (struct ClientRequest));
364 cr->lc = lc; 362 cr->lc = lc;
365 GNUNET_CONTAINER_DLL_insert (lc->cr_head, lc->cr_tail, cr); 363 GNUNET_CONTAINER_DLL_insert (lc->cr_head, lc->cr_tail, cr);
@@ -368,9 +366,9 @@ GSF_local_client_start_search_handler_ (struct GNUNET_SERVER_Client *client,
368 options |= GSF_PRO_LOCAL_ONLY; 366 options |= GSF_PRO_LOCAL_ONLY;
369 cr->pr = GSF_pending_request_create_ (options, type, &sm->query, (type == GNUNET_BLOCK_TYPE_FS_SBLOCK) ? &sm->target /* namespace */ 367 cr->pr = GSF_pending_request_create_ (options, type, &sm->query, (type == GNUNET_BLOCK_TYPE_FS_SBLOCK) ? &sm->target /* namespace */
370 : NULL, 368 : NULL,
371 (0 != memcmp (&sm->target, 369 (0 !=
372 &all_zeros, 370 memcmp (&sm->target, &all_zeros,
373 sizeof (GNUNET_HashCode))) 371 sizeof (GNUNET_HashCode)))
374 ? (const struct GNUNET_PeerIdentity *) 372 ? (const struct GNUNET_PeerIdentity *)
375 &sm->target : NULL, NULL, 0, 373 &sm->target : NULL, NULL, 0,
376 0 /* bf */ , 374 0 /* bf */ ,
@@ -418,10 +416,10 @@ transmit_to_client (void *cls, size_t size, void *buf)
418 GNUNET_free (res); 416 GNUNET_free (res);
419 } 417 }
420 if (NULL != res) 418 if (NULL != res)
421 lc->th = GNUNET_SERVER_notify_transmit_ready (lc->client, 419 lc->th =
422 res->msize, 420 GNUNET_SERVER_notify_transmit_ready (lc->client, res->msize,
423 GNUNET_TIME_UNIT_FOREVER_REL, 421 GNUNET_TIME_UNIT_FOREVER_REL,
424 &transmit_to_client, lc); 422 &transmit_to_client, lc);
425 return msize; 423 return msize;
426} 424}
427 425
@@ -448,10 +446,10 @@ GSF_local_client_transmit_ (struct GSF_LocalClient *lc,
448 memcpy (&res[1], msg, msize); 446 memcpy (&res[1], msg, msize);
449 GNUNET_CONTAINER_DLL_insert_tail (lc->res_head, lc->res_tail, res); 447 GNUNET_CONTAINER_DLL_insert_tail (lc->res_head, lc->res_tail, res);
450 if (NULL == lc->th) 448 if (NULL == lc->th)
451 lc->th = GNUNET_SERVER_notify_transmit_ready (lc->client, 449 lc->th =
452 msize, 450 GNUNET_SERVER_notify_transmit_ready (lc->client, msize,
453 GNUNET_TIME_UNIT_FOREVER_REL, 451 GNUNET_TIME_UNIT_FOREVER_REL,
454 &transmit_to_client, lc); 452 &transmit_to_client, lc);
455} 453}
456 454
457 455
@@ -479,8 +477,8 @@ GSF_client_disconnect_handler_ (void *cls, struct GNUNET_SERVER_Client *client)
479 GNUNET_CONTAINER_DLL_remove (pos->cr_head, pos->cr_tail, cr); 477 GNUNET_CONTAINER_DLL_remove (pos->cr_head, pos->cr_tail, cr);
480 GSF_pending_request_cancel_ (cr->pr, GNUNET_NO); 478 GSF_pending_request_cancel_ (cr->pr, GNUNET_NO);
481 GNUNET_STATISTICS_update (GSF_stats, 479 GNUNET_STATISTICS_update (GSF_stats,
482 gettext_noop ("# client searches active"), 480 gettext_noop ("# client searches active"), -1,
483 -1, GNUNET_NO); 481 GNUNET_NO);
484 if (GNUNET_SCHEDULER_NO_TASK != cr->kill_task) 482 if (GNUNET_SCHEDULER_NO_TASK != cr->kill_task)
485 GNUNET_SCHEDULER_cancel (cr->kill_task); 483 GNUNET_SCHEDULER_cancel (cr->kill_task);
486 GNUNET_free (cr); 484 GNUNET_free (cr);
diff --git a/src/fs/gnunet-service-fs_pe.c b/src/fs/gnunet-service-fs_pe.c
index d3ab5026b..58fb11cee 100644
--- a/src/fs/gnunet-service-fs_pe.c
+++ b/src/fs/gnunet-service-fs_pe.c
@@ -207,9 +207,9 @@ static unsigned long long plan_count;
207 * @param cls the 'struct GSF_ConnectedPeer' for transmission 207 * @param cls the 'struct GSF_ConnectedPeer' for transmission
208 * @param tc scheduler context 208 * @param tc scheduler context
209 */ 209 */
210static void 210static void schedule_peer_transmission (void *cls,
211schedule_peer_transmission (void *cls, 211 const struct
212 const struct GNUNET_SCHEDULER_TaskContext *tc); 212 GNUNET_SCHEDULER_TaskContext *tc);
213 213
214 214
215/** 215/**
@@ -230,8 +230,9 @@ plan (struct PeerPlan *pp, struct GSF_RequestPlan *rp)
230 prd = GSF_pending_request_get_data_ (rp->prl_head->pr); 230 prd = GSF_pending_request_get_data_ (rp->prl_head->pr);
231 // FIXME: calculate 'rp->priority'! 231 // FIXME: calculate 'rp->priority'!
232 if (rp->transmission_counter < 32) 232 if (rp->transmission_counter < 32)
233 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 233 delay =
234 1LL << rp->transmission_counter); 234 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
235 1LL << rp->transmission_counter);
235 else 236 else
236 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, UINT_MAX); 237 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, UINT_MAX);
237 rp->earliest_transmission = GNUNET_TIME_relative_to_absolute (delay); 238 rp->earliest_transmission = GNUNET_TIME_relative_to_absolute (delay);
@@ -242,13 +243,13 @@ plan (struct PeerPlan *pp, struct GSF_RequestPlan *rp)
242#endif 243#endif
243 244
244 GNUNET_assert (rp->hn == NULL); 245 GNUNET_assert (rp->hn == NULL);
245 if (GNUNET_TIME_absolute_get_remaining (rp->earliest_transmission).rel_value 246 if (GNUNET_TIME_absolute_get_remaining (rp->earliest_transmission).
246 == 0) 247 rel_value == 0)
247 rp->hn = GNUNET_CONTAINER_heap_insert (pp->priority_heap, rp, rp->priority); 248 rp->hn = GNUNET_CONTAINER_heap_insert (pp->priority_heap, rp, rp->priority);
248 else 249 else
249 rp->hn = GNUNET_CONTAINER_heap_insert (pp->delay_heap, 250 rp->hn =
250 rp, 251 GNUNET_CONTAINER_heap_insert (pp->delay_heap, rp,
251 rp->earliest_transmission.abs_value); 252 rp->earliest_transmission.abs_value);
252 if (GNUNET_SCHEDULER_NO_TASK != pp->task) 253 if (GNUNET_SCHEDULER_NO_TASK != pp->task)
253 GNUNET_SCHEDULER_cancel (pp->task); 254 GNUNET_SCHEDULER_cancel (pp->task);
254 pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp); 255 pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp);
@@ -358,8 +359,8 @@ schedule_peer_transmission (void *cls,
358 } 359 }
359 /* move ready requests to priority queue */ 360 /* move ready requests to priority queue */
360 while ((NULL != (rp = GNUNET_CONTAINER_heap_peek (pp->delay_heap))) && 361 while ((NULL != (rp = GNUNET_CONTAINER_heap_peek (pp->delay_heap))) &&
361 (GNUNET_TIME_absolute_get_remaining 362 (GNUNET_TIME_absolute_get_remaining (rp->earliest_transmission).
362 (rp->earliest_transmission).rel_value == 0)) 363 rel_value == 0))
363 { 364 {
364 GNUNET_assert (rp == GNUNET_CONTAINER_heap_remove_root (pp->delay_heap)); 365 GNUNET_assert (rp == GNUNET_CONTAINER_heap_remove_root (pp->delay_heap));
365 rp->hn = GNUNET_CONTAINER_heap_insert (pp->priority_heap, rp, rp->priority); 366 rp->hn = GNUNET_CONTAINER_heap_insert (pp->priority_heap, rp, rp->priority);
@@ -371,17 +372,17 @@ schedule_peer_transmission (void *cls,
371 if (NULL == rp) 372 if (NULL == rp)
372 { 373 {
373#if DEBUG_FS 374#if DEBUG_FS
374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 375 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No active requests for plan %p.\n",
375 "No active requests for plan %p.\n", pp); 376 pp);
376#endif 377#endif
377 return; /* both queues empty */ 378 return; /* both queues empty */
378 } 379 }
379#if DEBUG_FS 380#if DEBUG_FS
380 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 381 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
381 "Sleeping for %llu ms before retrying requests on plan %p.\n", 382 "Sleeping for %llu ms before retrying requests on plan %p.\n",
382 (unsigned long long) 383 (unsigned long long) GNUNET_TIME_absolute_get_remaining (rp->
383 GNUNET_TIME_absolute_get_remaining 384 earliest_transmission).
384 (rp->earliest_transmission).rel_value, pp); 385 rel_value, pp);
385#endif 386#endif
386 pp->task = 387 pp->task =
387 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining 388 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
@@ -396,11 +397,10 @@ schedule_peer_transmission (void *cls,
396#endif 397#endif
397 GNUNET_assert (NULL != rp); 398 GNUNET_assert (NULL != rp);
398 msize = GSF_pending_request_get_message_ (get_latest (rp), 0, NULL); 399 msize = GSF_pending_request_get_message_ (get_latest (rp), 0, NULL);
399 pp->pth = GSF_peer_transmit_ (pp->cp, 400 pp->pth =
400 GNUNET_YES, 401 GSF_peer_transmit_ (pp->cp, GNUNET_YES, rp->priority,
401 rp->priority, 402 GNUNET_TIME_UNIT_FOREVER_REL, msize,
402 GNUNET_TIME_UNIT_FOREVER_REL, 403 &transmit_message_callback, pp);
403 msize, &transmit_message_callback, pp);
404 GNUNET_assert (NULL != pp->pth); 404 GNUNET_assert (NULL != pp->pth);
405} 405}
406 406
@@ -430,9 +430,8 @@ struct MergeContext
430 * GNUNET_NO if not (merge success) 430 * GNUNET_NO if not (merge success)
431 */ 431 */
432static int 432static int
433merge_pr (void *cls, 433merge_pr (void *cls, struct GNUNET_CONTAINER_HeapNode *node, void *element,
434 struct GNUNET_CONTAINER_HeapNode *node, 434 GNUNET_CONTAINER_HeapCostType cost)
435 void *element, GNUNET_CONTAINER_HeapCostType cost)
436{ 435{
437 struct MergeContext *mpr = cls; 436 struct MergeContext *mpr = cls;
438 struct GSF_RequestPlan *rp = element; 437 struct GSF_RequestPlan *rp = element;
@@ -455,14 +454,13 @@ merge_pr (void *cls,
455 GNUNET_CONTAINER_DLL_insert (prd->rpr_head, prd->rpr_tail, rpr); 454 GNUNET_CONTAINER_DLL_insert (prd->rpr_head, prd->rpr_tail, rpr);
456 GNUNET_CONTAINER_DLL_insert (rp->prl_head, rp->prl_tail, prl); 455 GNUNET_CONTAINER_DLL_insert (rp->prl_head, rp->prl_tail, prl);
457 mpr->merged = GNUNET_YES; 456 mpr->merged = GNUNET_YES;
458 GNUNET_STATISTICS_update (GSF_stats, 457 GNUNET_STATISTICS_update (GSF_stats, gettext_noop ("# requests merged"), 1,
459 gettext_noop ("# requests merged"), 1, GNUNET_NO); 458 GNUNET_NO);
460 latest = get_latest (rp); 459 latest = get_latest (rp);
461 if (GSF_pending_request_get_data_ (latest)->ttl.abs_value < 460 if (GSF_pending_request_get_data_ (latest)->ttl.abs_value <
462 prd->ttl.abs_value) 461 prd->ttl.abs_value)
463 { 462 {
464 GNUNET_STATISTICS_update (GSF_stats, 463 GNUNET_STATISTICS_update (GSF_stats, gettext_noop ("# requests refreshed"),
465 gettext_noop ("# requests refreshed"),
466 1, GNUNET_NO); 464 1, GNUNET_NO);
467 rp->transmission_counter = 0; /* reset */ 465 rp->transmission_counter = 0; /* reset */
468 } 466 }
@@ -498,9 +496,7 @@ GSF_plan_add_ (struct GSF_ConnectedPeer *cp, struct GSF_PendingRequest *pr)
498 pp->delay_heap = 496 pp->delay_heap =
499 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 497 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
500 pp->cp = cp; 498 pp->cp = cp;
501 GNUNET_CONTAINER_multihashmap_put (plans, 499 GNUNET_CONTAINER_multihashmap_put (plans, &id.hashPubKey, pp,
502 &id.hashPubKey,
503 pp,
504 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 500 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
505 } 501 }
506 mpc.merged = GNUNET_NO; 502 mpc.merged = GNUNET_NO;
@@ -512,9 +508,8 @@ GSF_plan_add_ (struct GSF_ConnectedPeer *cp, struct GSF_PendingRequest *pr)
512 if (mpc.merged != GNUNET_NO) 508 if (mpc.merged != GNUNET_NO)
513 return; 509 return;
514 plan_count++; 510 plan_count++;
515 GNUNET_STATISTICS_update (GSF_stats, 511 GNUNET_STATISTICS_update (GSF_stats, gettext_noop ("# query plan entries"), 1,
516 gettext_noop ("# query plan entries"), 512 GNUNET_NO);
517 1, GNUNET_NO);
518 prd = GSF_pending_request_get_data_ (pr); 513 prd = GSF_pending_request_get_data_ (pr);
519#if DEBUG_FS 514#if DEBUG_FS
520 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 515 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -554,8 +549,8 @@ GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp)
554 if (NULL == pp) 549 if (NULL == pp)
555 return; /* nothing was ever planned for this peer */ 550 return; /* nothing was ever planned for this peer */
556 GNUNET_assert (GNUNET_YES == 551 GNUNET_assert (GNUNET_YES ==
557 GNUNET_CONTAINER_multihashmap_remove (plans, 552 GNUNET_CONTAINER_multihashmap_remove (plans, &id.hashPubKey,
558 &id.hashPubKey, pp)); 553 pp));
559 if (NULL != pp->pth) 554 if (NULL != pp->pth)
560 GSF_peer_transmit_cancel_ (pp->pth); 555 GSF_peer_transmit_cancel_ (pp->pth);
561 if (GNUNET_SCHEDULER_NO_TASK != pp->task) 556 if (GNUNET_SCHEDULER_NO_TASK != pp->task)
@@ -588,8 +583,7 @@ GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp)
588 } 583 }
589 GNUNET_free (rp); 584 GNUNET_free (rp);
590 } 585 }
591 GNUNET_STATISTICS_set (GSF_stats, 586 GNUNET_STATISTICS_set (GSF_stats, gettext_noop ("# query plan entries"),
592 gettext_noop ("# query plan entries"),
593 plan_count, GNUNET_NO); 587 plan_count, GNUNET_NO);
594 588
595 GNUNET_CONTAINER_heap_destroy (pp->delay_heap); 589 GNUNET_CONTAINER_heap_destroy (pp->delay_heap);
@@ -625,8 +619,7 @@ GSF_plan_notify_request_done_ (struct GSF_PendingRequest *pr)
625 GNUNET_free (rp); 619 GNUNET_free (rp);
626 } 620 }
627 } 621 }
628 GNUNET_STATISTICS_set (GSF_stats, 622 GNUNET_STATISTICS_set (GSF_stats, gettext_noop ("# query plan entries"),
629 gettext_noop ("# query plan entries"),
630 plan_count, GNUNET_NO); 623 plan_count, GNUNET_NO);
631} 624}
632 625
diff --git a/src/fs/gnunet-service-fs_pr.c b/src/fs/gnunet-service-fs_pr.c
index e637be664..7b6290bbb 100644
--- a/src/fs/gnunet-service-fs_pr.c
+++ b/src/fs/gnunet-service-fs_pr.c
@@ -241,8 +241,8 @@ refresh_bloomfilter (struct GSF_PendingRequest *pr)
241 return GNUNET_NO; /* size not changed */ 241 return GNUNET_NO; /* size not changed */
242 if (pr->bf != NULL) 242 if (pr->bf != NULL)
243 GNUNET_CONTAINER_bloomfilter_free (pr->bf); 243 GNUNET_CONTAINER_bloomfilter_free (pr->bf);
244 pr->mingle = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 244 pr->mingle =
245 UINT32_MAX); 245 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
246 pr->bf = GNUNET_CONTAINER_bloomfilter_init (NULL, nsize, BLOOMFILTER_K); 246 pr->bf = GNUNET_CONTAINER_bloomfilter_init (NULL, nsize, BLOOMFILTER_K);
247 for (i = 0; i < pr->replies_seen_count; i++) 247 for (i = 0; i < pr->replies_seen_count; i++)
248 { 248 {
@@ -280,12 +280,9 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
280 const GNUNET_HashCode * query, 280 const GNUNET_HashCode * query,
281 const GNUNET_HashCode * namespace, 281 const GNUNET_HashCode * namespace,
282 const struct GNUNET_PeerIdentity *target, 282 const struct GNUNET_PeerIdentity *target,
283 const char *bf_data, 283 const char *bf_data, size_t bf_size,
284 size_t bf_size, 284 uint32_t mingle, uint32_t anonymity_level,
285 uint32_t mingle, 285 uint32_t priority, int32_t ttl,
286 uint32_t anonymity_level,
287 uint32_t priority,
288 int32_t ttl,
289 GNUNET_PEER_Id sender_pid, 286 GNUNET_PEER_Id sender_pid,
290 const GNUNET_HashCode * replies_seen, 287 const GNUNET_HashCode * replies_seen,
291 unsigned int replies_seen_count, 288 unsigned int replies_seen_count,
@@ -300,8 +297,8 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
300 GNUNET_h2s (query), type); 297 GNUNET_h2s (query), type);
301#endif 298#endif
302 GNUNET_STATISTICS_update (GSF_stats, 299 GNUNET_STATISTICS_update (GSF_stats,
303 gettext_noop ("# Pending requests created"), 300 gettext_noop ("# Pending requests created"), 1,
304 1, GNUNET_NO); 301 GNUNET_NO);
305 pr = GNUNET_malloc (sizeof (struct GSF_PendingRequest)); 302 pr = GNUNET_malloc (sizeof (struct GSF_PendingRequest));
306 pr->local_result_offset = 303 pr->local_result_offset =
307 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); 304 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
@@ -348,8 +345,8 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
348 } 345 }
349 if (NULL != bf_data) 346 if (NULL != bf_data)
350 { 347 {
351 pr->bf = GNUNET_CONTAINER_bloomfilter_init (bf_data, 348 pr->bf =
352 bf_size, BLOOMFILTER_K); 349 GNUNET_CONTAINER_bloomfilter_init (bf_data, bf_size, BLOOMFILTER_K);
353 pr->mingle = mingle; 350 pr->mingle = mingle;
354 } 351 }
355 else if ((replies_seen_count > 0) && 352 else if ((replies_seen_count > 0) &&
@@ -357,15 +354,13 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
357 { 354 {
358 GNUNET_assert (GNUNET_YES == refresh_bloomfilter (pr)); 355 GNUNET_assert (GNUNET_YES == refresh_bloomfilter (pr));
359 } 356 }
360 GNUNET_CONTAINER_multihashmap_put (pr_map, 357 GNUNET_CONTAINER_multihashmap_put (pr_map, query, pr,
361 query,
362 pr,
363 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 358 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
364 if (0 != (options & GSF_PRO_REQUEST_EXPIRES)) 359 if (0 != (options & GSF_PRO_REQUEST_EXPIRES))
365 { 360 {
366 pr->hnode = GNUNET_CONTAINER_heap_insert (requests_by_expiration_heap, 361 pr->hnode =
367 pr, 362 GNUNET_CONTAINER_heap_insert (requests_by_expiration_heap, pr,
368 pr->public_data.ttl.abs_value); 363 pr->public_data.ttl.abs_value);
369 /* make sure we don't track too many requests */ 364 /* make sure we don't track too many requests */
370 while (GNUNET_CONTAINER_heap_get_size (requests_by_expiration_heap) > 365 while (GNUNET_CONTAINER_heap_get_size (requests_by_expiration_heap) >
371 max_pending_requests) 366 max_pending_requests)
@@ -374,17 +369,15 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
374 GNUNET_assert (dpr != NULL); 369 GNUNET_assert (dpr != NULL);
375 if (pr == dpr) 370 if (pr == dpr)
376 break; /* let the request live briefly... */ 371 break; /* let the request live briefly... */
377 dpr->rh (dpr->rh_cls, 372 dpr->rh (dpr->rh_cls, GNUNET_BLOCK_EVALUATION_REQUEST_VALID, dpr,
378 GNUNET_BLOCK_EVALUATION_REQUEST_VALID, 373 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_BLOCK_TYPE_ANY,
379 dpr, 374 NULL, 0);
380 UINT32_MAX,
381 GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_BLOCK_TYPE_ANY, NULL, 0);
382 GSF_pending_request_cancel_ (dpr, GNUNET_YES); 375 GSF_pending_request_cancel_ (dpr, GNUNET_YES);
383 } 376 }
384 } 377 }
385 GNUNET_STATISTICS_update (GSF_stats, 378 GNUNET_STATISTICS_update (GSF_stats,
386 gettext_noop ("# Pending requests active"), 379 gettext_noop ("# Pending requests active"), 1,
387 1, GNUNET_NO); 380 GNUNET_NO);
388 return pr; 381 return pr;
389} 382}
390 383
@@ -416,12 +409,13 @@ GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra,
416 struct GSF_PendingRequest *prb) 409 struct GSF_PendingRequest *prb)
417{ 410{
418 if ((pra->public_data.type != prb->public_data.type) || 411 if ((pra->public_data.type != prb->public_data.type) ||
419 (0 != memcmp (&pra->public_data.query, 412 (0 !=
420 &prb->public_data.query, 413 memcmp (&pra->public_data.query, &prb->public_data.query,
421 sizeof (GNUNET_HashCode))) || 414 sizeof (GNUNET_HashCode))) ||
422 ((pra->public_data.type == GNUNET_BLOCK_TYPE_FS_SBLOCK) && 415 ((pra->public_data.type == GNUNET_BLOCK_TYPE_FS_SBLOCK) &&
423 (0 != memcmp (&pra->public_data.namespace, 416 (0 !=
424 &prb->public_data.namespace, sizeof (GNUNET_HashCode))))) 417 memcmp (&pra->public_data.namespace, &prb->public_data.namespace,
418 sizeof (GNUNET_HashCode)))))
425 return GNUNET_NO; 419 return GNUNET_NO;
426 return GNUNET_OK; 420 return GNUNET_OK;
427} 421}
@@ -450,11 +444,10 @@ GSF_pending_request_update_ (struct GSF_PendingRequest *pr,
450 { 444 {
451 /* we're responsible for the BF, full refresh */ 445 /* we're responsible for the BF, full refresh */
452 if (replies_seen_count + pr->replies_seen_count > pr->replies_seen_size) 446 if (replies_seen_count + pr->replies_seen_count > pr->replies_seen_size)
453 GNUNET_array_grow (pr->replies_seen, 447 GNUNET_array_grow (pr->replies_seen, pr->replies_seen_size,
454 pr->replies_seen_size,
455 replies_seen_count + pr->replies_seen_count); 448 replies_seen_count + pr->replies_seen_count);
456 memcpy (&pr->replies_seen[pr->replies_seen_count], 449 memcpy (&pr->replies_seen[pr->replies_seen_count], replies_seen,
457 replies_seen, sizeof (GNUNET_HashCode) * replies_seen_count); 450 sizeof (GNUNET_HashCode) * replies_seen_count);
458 pr->replies_seen_count += replies_seen_count; 451 pr->replies_seen_count += replies_seen_count;
459 if (GNUNET_NO == refresh_bloomfilter (pr)) 452 if (GNUNET_NO == refresh_bloomfilter (pr))
460 { 453 {
@@ -472,12 +465,13 @@ GSF_pending_request_update_ (struct GSF_PendingRequest *pr,
472 { 465 {
473 /* we're not the initiator, but the initiator did not give us 466 /* we're not the initiator, but the initiator did not give us
474 * any bloom-filter, so we need to create one on-the-fly */ 467 * any bloom-filter, so we need to create one on-the-fly */
475 pr->mingle = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 468 pr->mingle =
476 UINT32_MAX); 469 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
477 pr->bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 470 pr->bf =
478 compute_bloomfilter_size 471 GNUNET_CONTAINER_bloomfilter_init (NULL,
479 (replies_seen_count), 472 compute_bloomfilter_size
480 BLOOMFILTER_K); 473 (replies_seen_count),
474 BLOOMFILTER_K);
481 } 475 }
482 for (i = 0; i < pr->replies_seen_count; i++) 476 for (i = 0; i < pr->replies_seen_count; i++)
483 { 477 {
@@ -552,8 +546,9 @@ GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr,
552 gm->header.size = htons (msize); 546 gm->header.size = htons (msize);
553 gm->type = htonl (pr->public_data.type); 547 gm->type = htonl (pr->public_data.type);
554 if (do_route) 548 if (do_route)
555 prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 549 prio =
556 pr->public_data.priority + 1); 550 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
551 pr->public_data.priority + 1);
557 else 552 else
558 prio = 0; 553 prio = 0;
559 pr->public_data.priority -= prio; 554 pr->public_data.priority -= prio;
@@ -640,8 +635,8 @@ clean_request (void *cls, const GNUNET_HashCode * key, void *value)
640 &pr->public_data.query, 635 &pr->public_data.query,
641 pr)); 636 pr));
642 GNUNET_STATISTICS_update (GSF_stats, 637 GNUNET_STATISTICS_update (GSF_stats,
643 gettext_noop ("# Pending requests active"), 638 gettext_noop ("# Pending requests active"), -1,
644 -1, GNUNET_NO); 639 GNUNET_NO);
645 GNUNET_free (pr); 640 GNUNET_free (pr);
646 return GNUNET_YES; 641 return GNUNET_YES;
647} 642}
@@ -776,8 +771,8 @@ update_request_performance_data (struct ProcessReplyClosure *prq,
776{ 771{
777 if (prq->sender == NULL) 772 if (prq->sender == NULL)
778 return; 773 return;
779 GSF_peer_update_performance_ (prq->sender, 774 GSF_peer_update_performance_ (prq->sender, pr->public_data.start_time,
780 pr->public_data.start_time, prq->priority); 775 prq->priority);
781} 776}
782 777
783 778
@@ -804,18 +799,15 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value)
804 (unsigned int) prq->type, GNUNET_h2s (key)); 799 (unsigned int) prq->type, GNUNET_h2s (key));
805#endif 800#endif
806 GNUNET_STATISTICS_update (GSF_stats, 801 GNUNET_STATISTICS_update (GSF_stats,
807 gettext_noop ("# replies received and matched"), 802 gettext_noop ("# replies received and matched"), 1,
808 1, GNUNET_NO); 803 GNUNET_NO);
809 prq->eval = GNUNET_BLOCK_evaluate (GSF_block_ctx, 804 prq->eval =
810 prq->type, 805 GNUNET_BLOCK_evaluate (GSF_block_ctx, prq->type, key, &pr->bf, pr->mingle,
811 key, 806 &pr->public_data.namespace,
812 &pr->bf, 807 (prq->type ==
813 pr->mingle, 808 GNUNET_BLOCK_TYPE_FS_SBLOCK) ?
814 &pr->public_data.namespace, 809 sizeof (GNUNET_HashCode) : 0, prq->data,
815 (prq->type == 810 prq->size);
816 GNUNET_BLOCK_TYPE_FS_SBLOCK) ?
817 sizeof (GNUNET_HashCode) : 0, prq->data,
818 prq->size);
819 switch (prq->eval) 811 switch (prq->eval)
820 { 812 {
821 case GNUNET_BLOCK_EVALUATION_OK_MORE: 813 case GNUNET_BLOCK_EVALUATION_OK_MORE:
@@ -825,14 +817,12 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value)
825 /* short cut: stop processing early, no BF-update, etc. */ 817 /* short cut: stop processing early, no BF-update, etc. */
826 update_request_performance_data (prq, pr); 818 update_request_performance_data (prq, pr);
827 GNUNET_LOAD_update (GSF_rt_entry_lifetime, 819 GNUNET_LOAD_update (GSF_rt_entry_lifetime,
828 GNUNET_TIME_absolute_get_duration (pr-> 820 GNUNET_TIME_absolute_get_duration (pr->public_data.
829 public_data.start_time).rel_value); 821 start_time).
822 rel_value);
830 /* pass on to other peers / local clients */ 823 /* pass on to other peers / local clients */
831 pr->rh (pr->rh_cls, 824 pr->rh (pr->rh_cls, prq->eval, pr, prq->anonymity_level, prq->expiration,
832 prq->eval, 825 prq->type, prq->data, prq->size);
833 pr,
834 prq->anonymity_level,
835 prq->expiration, prq->type, prq->data, prq->size);
836 return GNUNET_YES; 826 return GNUNET_YES;
837 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: 827 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
838 GNUNET_STATISTICS_update (GSF_stats, 828 GNUNET_STATISTICS_update (GSF_stats,
@@ -853,8 +843,8 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value)
853 GNUNET_break (0); 843 GNUNET_break (0);
854 return GNUNET_YES; 844 return GNUNET_YES;
855 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: 845 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
856 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 846 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Unsupported block type %u\n"),
857 _("Unsupported block type %u\n"), prq->type); 847 prq->type);
858 return GNUNET_NO; 848 return GNUNET_NO;
859 } 849 }
860 /* update bloomfilter */ 850 /* update bloomfilter */
@@ -868,8 +858,8 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value)
868 GNUNET_h2s (key)); 858 GNUNET_h2s (key));
869#endif 859#endif
870 GNUNET_STATISTICS_update (GSF_stats, 860 GNUNET_STATISTICS_update (GSF_stats,
871 gettext_noop ("# results found locally"), 861 gettext_noop ("# results found locally"), 1,
872 1, GNUNET_NO); 862 GNUNET_NO);
873 } 863 }
874 else 864 else
875 { 865 {
@@ -881,11 +871,8 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value)
881 pr->public_data.results_found++; 871 pr->public_data.results_found++;
882 prq->request_found = GNUNET_YES; 872 prq->request_found = GNUNET_YES;
883 /* finally, pass on to other peer / local client */ 873 /* finally, pass on to other peer / local client */
884 pr->rh (pr->rh_cls, 874 pr->rh (pr->rh_cls, prq->eval, pr, prq->anonymity_level, prq->expiration,
885 prq->eval, 875 prq->type, prq->data, prq->size);
886 pr,
887 prq->anonymity_level,
888 prq->expiration, prq->type, prq->data, prq->size);
889 return GNUNET_YES; 876 return GNUNET_YES;
890} 877}
891 878
@@ -940,12 +927,11 @@ put_migration_continuation (void *cls, int success, const char *msg)
940 { 927 {
941 ppd = GSF_get_peer_performance_data_ (cp); 928 ppd = GSF_get_peer_performance_data_ (cp);
942 ppd->migration_duplication++; 929 ppd->migration_duplication++;
943 block_time = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 930 block_time =
944 5 * 931 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
945 ppd->migration_duplication + 932 5 * ppd->migration_duplication +
946 GNUNET_CRYPTO_random_u32 933 GNUNET_CRYPTO_random_u32
947 (GNUNET_CRYPTO_QUALITY_WEAK, 934 (GNUNET_CRYPTO_QUALITY_WEAK, 5));
948 5));
949 GSF_block_peer_migration_ (cp, block_time); 935 GSF_block_peer_migration_ (cp, block_time);
950 } 936 }
951 } 937 }
@@ -964,8 +950,8 @@ put_migration_continuation (void *cls, int success, const char *msg)
964 if (GNUNET_OK == success) 950 if (GNUNET_OK == success)
965 return; 951 return;
966 GNUNET_STATISTICS_update (GSF_stats, 952 GNUNET_STATISTICS_update (GSF_stats,
967 gettext_noop ("# Datastore `PUT' failures"), 953 gettext_noop ("# Datastore `PUT' failures"), 1,
968 1, GNUNET_NO); 954 GNUNET_NO);
969} 955}
970 956
971 957
@@ -1013,8 +999,7 @@ test_put_load_too_high (uint32_t priority)
1013 * @param data pointer to the result data 999 * @param data pointer to the result data
1014 */ 1000 */
1015static void 1001static void
1016handle_dht_reply (void *cls, 1002handle_dht_reply (void *cls, struct GNUNET_TIME_Absolute exp,
1017 struct GNUNET_TIME_Absolute exp,
1018 const GNUNET_HashCode * key, 1003 const GNUNET_HashCode * key,
1019 const struct GNUNET_PeerIdentity *const *get_path, 1004 const struct GNUNET_PeerIdentity *const *get_path,
1020 const struct GNUNET_PeerIdentity *const *put_path, 1005 const struct GNUNET_PeerIdentity *const *put_path,
@@ -1025,8 +1010,8 @@ handle_dht_reply (void *cls,
1025 struct PutMigrationContext *pmc; 1010 struct PutMigrationContext *pmc;
1026 1011
1027 GNUNET_STATISTICS_update (GSF_stats, 1012 GNUNET_STATISTICS_update (GSF_stats,
1028 gettext_noop ("# Replies received from DHT"), 1013 gettext_noop ("# Replies received from DHT"), 1,
1029 1, GNUNET_NO); 1014 GNUNET_NO);
1030 memset (&prq, 0, sizeof (prq)); 1015 memset (&prq, 0, sizeof (prq));
1031 prq.data = data; 1016 prq.data = data;
1032 prq.expiration = exp; 1017 prq.expiration = exp;
@@ -1045,12 +1030,10 @@ handle_dht_reply (void *cls,
1045 pmc->start = GNUNET_TIME_absolute_get (); 1030 pmc->start = GNUNET_TIME_absolute_get ();
1046 pmc->requested = GNUNET_YES; 1031 pmc->requested = GNUNET_YES;
1047 if (NULL == 1032 if (NULL ==
1048 GNUNET_DATASTORE_put (GSF_dsh, 1033 GNUNET_DATASTORE_put (GSF_dsh, 0, key, size, data, type, prq.priority,
1049 0, key, size, data, 1034 1 /* anonymity */ ,
1050 type, prq.priority, 1 /* anonymity */ ,
1051 0 /* replication */ , 1035 0 /* replication */ ,
1052 exp, 1036 exp, 1 + prq.priority, MAX_DATASTORE_QUEUE,
1053 1 + prq.priority, MAX_DATASTORE_QUEUE,
1054 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 1037 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1055 &put_migration_continuation, pmc)) 1038 &put_migration_continuation, pmc))
1056 { 1039 {
@@ -1095,15 +1078,13 @@ GSF_dht_lookup_ (struct GSF_PendingRequest *pr)
1095 memcpy (&buf[xquery_size], &pi, sizeof (struct GNUNET_PeerIdentity)); 1078 memcpy (&buf[xquery_size], &pi, sizeof (struct GNUNET_PeerIdentity));
1096 xquery_size += sizeof (struct GNUNET_PeerIdentity); 1079 xquery_size += sizeof (struct GNUNET_PeerIdentity);
1097 } 1080 }
1098 pr->gh = GNUNET_DHT_get_start (GSF_dht, 1081 pr->gh =
1099 GNUNET_TIME_UNIT_FOREVER_REL, 1082 GNUNET_DHT_get_start (GSF_dht, GNUNET_TIME_UNIT_FOREVER_REL,
1100 pr->public_data.type, 1083 pr->public_data.type, &pr->public_data.query,
1101 &pr->public_data.query, 1084 DEFAULT_GET_REPLICATION,
1102 DEFAULT_GET_REPLICATION, 1085 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, pr->bf,
1103 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 1086 pr->mingle, xquery, xquery_size, &handle_dht_reply,
1104 pr->bf, 1087 pr);
1105 pr->mingle,
1106 xquery, xquery_size, &handle_dht_reply, pr);
1107} 1088}
1108 1089
1109 1090
@@ -1120,8 +1101,9 @@ warn_delay_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1120 1101
1121 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1102 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1122 _("Datastore lookup already took %llu ms!\n"), 1103 _("Datastore lookup already took %llu ms!\n"),
1123 (unsigned long long) 1104 (unsigned long long) GNUNET_TIME_absolute_get_duration (pr->
1124 GNUNET_TIME_absolute_get_duration (pr->qe_start).rel_value); 1105 qe_start).
1106 rel_value);
1125 pr->warn_task = 1107 pr->warn_task =
1126 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &warn_delay_task, 1108 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &warn_delay_task,
1127 pr); 1109 pr);
@@ -1141,8 +1123,9 @@ odc_warn_delay_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1141 1123
1142 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1124 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1143 _("On-demand lookup already took %llu ms!\n"), 1125 _("On-demand lookup already took %llu ms!\n"),
1144 (unsigned long long) 1126 (unsigned long long) GNUNET_TIME_absolute_get_duration (pr->
1145 GNUNET_TIME_absolute_get_duration (pr->qe_start).rel_value); 1127 qe_start).
1128 rel_value);
1146 pr->warn_task = 1129 pr->warn_task =
1147 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 1130 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
1148 &odc_warn_delay_task, pr); 1131 &odc_warn_delay_task, pr);
@@ -1167,13 +1150,9 @@ odc_warn_delay_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1167 * maybe 0 if no unique identifier is available 1150 * maybe 0 if no unique identifier is available
1168 */ 1151 */
1169static void 1152static void
1170process_local_reply (void *cls, 1153process_local_reply (void *cls, const GNUNET_HashCode * key, size_t size,
1171 const GNUNET_HashCode * key, 1154 const void *data, enum GNUNET_BLOCK_Type type,
1172 size_t size, 1155 uint32_t priority, uint32_t anonymity,
1173 const void *data,
1174 enum GNUNET_BLOCK_Type type,
1175 uint32_t priority,
1176 uint32_t anonymity,
1177 struct GNUNET_TIME_Absolute expiration, uint64_t uid) 1156 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
1178{ 1157{
1179 struct GSF_PendingRequest *pr = cls; 1158 struct GSF_PendingRequest *pr = cls;
@@ -1250,8 +1229,9 @@ process_local_reply (void *cls,
1250 ("# on-demand blocks matched requests"), 1, 1229 ("# on-demand blocks matched requests"), 1,
1251 GNUNET_NO); 1230 GNUNET_NO);
1252 pr->qe_start = GNUNET_TIME_absolute_get (); 1231 pr->qe_start = GNUNET_TIME_absolute_get ();
1253 pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 1232 pr->warn_task =
1254 &odc_warn_delay_task, pr); 1233 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
1234 &odc_warn_delay_task, pr);
1255 if (GNUNET_OK == 1235 if (GNUNET_OK ==
1256 GNUNET_FS_handle_on_demand_block (key, size, data, type, priority, 1236 GNUNET_FS_handle_on_demand_block (key, size, data, type, priority,
1257 anonymity, expiration, uid, 1237 anonymity, expiration, uid,
@@ -1264,30 +1244,28 @@ process_local_reply (void *cls,
1264 return; /* we're done */ 1244 return; /* we're done */
1265 } 1245 }
1266 GNUNET_STATISTICS_update (GSF_stats, 1246 GNUNET_STATISTICS_update (GSF_stats,
1267 gettext_noop ("# on-demand lookups failed"), 1247 gettext_noop ("# on-demand lookups failed"), 1,
1268 1, GNUNET_NO); 1248 GNUNET_NO);
1269 GNUNET_SCHEDULER_cancel (pr->warn_task); 1249 GNUNET_SCHEDULER_cancel (pr->warn_task);
1270 pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 1250 pr->warn_task =
1271 &warn_delay_task, pr); 1251 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
1272 pr->qe = GNUNET_DATASTORE_get_key (GSF_dsh, 1252 &warn_delay_task, pr);
1273 pr->local_result_offset - 1, 1253 pr->qe =
1274 &pr->public_data.query, 1254 GNUNET_DATASTORE_get_key (GSF_dsh, pr->local_result_offset - 1,
1275 pr->public_data.type == 1255 &pr->public_data.query,
1276 GNUNET_BLOCK_TYPE_FS_DBLOCK ? 1256 pr->public_data.type ==
1277 GNUNET_BLOCK_TYPE_ANY : pr-> 1257 GNUNET_BLOCK_TYPE_FS_DBLOCK ?
1278 public_data.type, 1258 GNUNET_BLOCK_TYPE_ANY : pr->public_data.type,
1279 (0 != 1259 (0 !=
1280 (GSF_PRO_PRIORITY_UNLIMITED & 1260 (GSF_PRO_PRIORITY_UNLIMITED & pr->
1281 pr->public_data. 1261 public_data.options)) ? UINT_MAX : 1
1282 options)) ? UINT_MAX : 1 1262 /* queue priority */ ,
1283 /* queue priority */ , 1263 (0 !=
1284 (0 != 1264 (GSF_PRO_PRIORITY_UNLIMITED & pr->
1285 (GSF_PRO_PRIORITY_UNLIMITED & 1265 public_data.options)) ? UINT_MAX : 1
1286 pr->public_data.options)) ? UINT_MAX : 1266 /* max queue size */ ,
1287 1 1267 GNUNET_TIME_UNIT_FOREVER_REL,
1288 /* max queue size */ , 1268 &process_local_reply, pr);
1289 GNUNET_TIME_UNIT_FOREVER_REL,
1290 &process_local_reply, pr);
1291 if (NULL != pr->qe) 1269 if (NULL != pr->qe)
1292 { 1270 {
1293 GNUNET_STATISTICS_update (GSF_stats, 1271 GNUNET_STATISTICS_update (GSF_stats,
@@ -1307,32 +1285,28 @@ process_local_reply (void *cls,
1307 GNUNET_BLOCK_get_key (GSF_block_ctx, type, data, size, &query)) 1285 GNUNET_BLOCK_get_key (GSF_block_ctx, type, data, size, &query))
1308 { 1286 {
1309 GNUNET_break (0); 1287 GNUNET_break (0);
1310 GNUNET_DATASTORE_remove (GSF_dsh, 1288 GNUNET_DATASTORE_remove (GSF_dsh, key, size, data, -1, -1,
1311 key, 1289 GNUNET_TIME_UNIT_FOREVER_REL, NULL, NULL);
1312 size, data,
1313 -1, -1, GNUNET_TIME_UNIT_FOREVER_REL, NULL, NULL);
1314 pr->qe_start = GNUNET_TIME_absolute_get (); 1290 pr->qe_start = GNUNET_TIME_absolute_get ();
1315 pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 1291 pr->warn_task =
1316 &warn_delay_task, pr); 1292 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
1317 pr->qe = GNUNET_DATASTORE_get_key (GSF_dsh, 1293 &warn_delay_task, pr);
1318 pr->local_result_offset - 1, 1294 pr->qe =
1319 &pr->public_data.query, 1295 GNUNET_DATASTORE_get_key (GSF_dsh, pr->local_result_offset - 1,
1320 pr->public_data.type == 1296 &pr->public_data.query,
1321 GNUNET_BLOCK_TYPE_FS_DBLOCK ? 1297 pr->public_data.type ==
1322 GNUNET_BLOCK_TYPE_ANY : pr-> 1298 GNUNET_BLOCK_TYPE_FS_DBLOCK ?
1323 public_data.type, 1299 GNUNET_BLOCK_TYPE_ANY : pr->public_data.type,
1324 (0 != 1300 (0 !=
1325 (GSF_PRO_PRIORITY_UNLIMITED & 1301 (GSF_PRO_PRIORITY_UNLIMITED & pr->
1326 pr->public_data. 1302 public_data.options)) ? UINT_MAX : 1
1327 options)) ? UINT_MAX : 1 1303 /* queue priority */ ,
1328 /* queue priority */ , 1304 (0 !=
1329 (0 != 1305 (GSF_PRO_PRIORITY_UNLIMITED & pr->
1330 (GSF_PRO_PRIORITY_UNLIMITED & 1306 public_data.options)) ? UINT_MAX : 1
1331 pr->public_data.options)) ? UINT_MAX : 1307 /* max queue size */ ,
1332 1 1308 GNUNET_TIME_UNIT_FOREVER_REL,
1333 /* max queue size */ , 1309 &process_local_reply, pr);
1334 GNUNET_TIME_UNIT_FOREVER_REL,
1335 &process_local_reply, pr);
1336 if (pr->qe == NULL) 1310 if (pr->qe == NULL)
1337 { 1311 {
1338 GNUNET_STATISTICS_update (GSF_stats, 1312 GNUNET_STATISTICS_update (GSF_stats,
@@ -1373,25 +1347,25 @@ process_local_reply (void *cls,
1373 goto check_error_and_continue; 1347 goto check_error_and_continue;
1374 } 1348 }
1375 pr->qe_start = GNUNET_TIME_absolute_get (); 1349 pr->qe_start = GNUNET_TIME_absolute_get ();
1376 pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 1350 pr->warn_task =
1377 &warn_delay_task, pr); 1351 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &warn_delay_task,
1378 pr->qe = GNUNET_DATASTORE_get_key (GSF_dsh, 1352 pr);
1379 pr->local_result_offset++, 1353 pr->qe =
1380 &pr->public_data.query, 1354 GNUNET_DATASTORE_get_key (GSF_dsh, pr->local_result_offset++,
1381 pr->public_data.type == 1355 &pr->public_data.query,
1382 GNUNET_BLOCK_TYPE_FS_DBLOCK ? 1356 pr->public_data.type ==
1383 GNUNET_BLOCK_TYPE_ANY : pr-> 1357 GNUNET_BLOCK_TYPE_FS_DBLOCK ?
1384 public_data.type, 1358 GNUNET_BLOCK_TYPE_ANY : pr->public_data.type,
1385 (0 != 1359 (0 !=
1386 (GSF_PRO_PRIORITY_UNLIMITED & 1360 (GSF_PRO_PRIORITY_UNLIMITED & pr->public_data.
1387 pr->public_data.options)) ? UINT_MAX : 1 1361 options)) ? UINT_MAX : 1
1388 /* queue priority */ , 1362 /* queue priority */ ,
1389 (0 != 1363 (0 !=
1390 (GSF_PRO_PRIORITY_UNLIMITED & 1364 (GSF_PRO_PRIORITY_UNLIMITED & pr->public_data.
1391 pr->public_data.options)) ? UINT_MAX : 1 1365 options)) ? UINT_MAX : 1
1392 /* max queue size */ , 1366 /* max queue size */ ,
1393 GNUNET_TIME_UNIT_FOREVER_REL, 1367 GNUNET_TIME_UNIT_FOREVER_REL,
1394 &process_local_reply, pr); 1368 &process_local_reply, pr);
1395 /* check if we successfully queued another datastore request; 1369 /* check if we successfully queued another datastore request;
1396 * if so, return, otherwise call our continuation (if we have 1370 * if so, return, otherwise call our continuation (if we have
1397 * any) */ 1371 * any) */
@@ -1426,28 +1400,28 @@ GSF_local_lookup_ (struct GSF_PendingRequest *pr,
1426 pr->llc_cont = cont; 1400 pr->llc_cont = cont;
1427 pr->llc_cont_cls = cont_cls; 1401 pr->llc_cont_cls = cont_cls;
1428 pr->qe_start = GNUNET_TIME_absolute_get (); 1402 pr->qe_start = GNUNET_TIME_absolute_get ();
1429 pr->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 1403 pr->warn_task =
1430 &warn_delay_task, pr); 1404 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &warn_delay_task,
1405 pr);
1431 GNUNET_STATISTICS_update (GSF_stats, 1406 GNUNET_STATISTICS_update (GSF_stats,
1432 gettext_noop ("# Datastore lookups initiated"), 1407 gettext_noop ("# Datastore lookups initiated"), 1,
1433 1, GNUNET_NO); 1408 GNUNET_NO);
1434 pr->qe = GNUNET_DATASTORE_get_key (GSF_dsh, 1409 pr->qe =
1435 pr->local_result_offset++, 1410 GNUNET_DATASTORE_get_key (GSF_dsh, pr->local_result_offset++,
1436 &pr->public_data.query, 1411 &pr->public_data.query,
1437 pr->public_data.type == 1412 pr->public_data.type ==
1438 GNUNET_BLOCK_TYPE_FS_DBLOCK ? 1413 GNUNET_BLOCK_TYPE_FS_DBLOCK ?
1439 GNUNET_BLOCK_TYPE_ANY : pr-> 1414 GNUNET_BLOCK_TYPE_ANY : pr->public_data.type,
1440 public_data.type, 1415 (0 !=
1441 (0 != 1416 (GSF_PRO_PRIORITY_UNLIMITED & pr->public_data.
1442 (GSF_PRO_PRIORITY_UNLIMITED & 1417 options)) ? UINT_MAX : 1
1443 pr->public_data.options)) ? UINT_MAX : 1 1418 /* queue priority */ ,
1444 /* queue priority */ , 1419 (0 !=
1445 (0 != 1420 (GSF_PRO_PRIORITY_UNLIMITED & pr->public_data.
1446 (GSF_PRO_PRIORITY_UNLIMITED & 1421 options)) ? UINT_MAX : 1
1447 pr->public_data.options)) ? UINT_MAX : 1 1422 /* max queue size */ ,
1448 /* max queue size */ , 1423 GNUNET_TIME_UNIT_FOREVER_REL,
1449 GNUNET_TIME_UNIT_FOREVER_REL, 1424 &process_local_reply, pr);
1450 &process_local_reply, pr);
1451 if (NULL != pr->qe) 1425 if (NULL != pr->qe)
1452 { 1426 {
1453 GNUNET_STATISTICS_update (GSF_stats, 1427 GNUNET_STATISTICS_update (GSF_stats,
@@ -1513,8 +1487,8 @@ GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
1513 return GNUNET_SYSERR; 1487 return GNUNET_SYSERR;
1514 } 1488 }
1515 GNUNET_STATISTICS_update (GSF_stats, 1489 GNUNET_STATISTICS_update (GSF_stats,
1516 gettext_noop ("# GAP PUT messages received"), 1490 gettext_noop ("# GAP PUT messages received"), 1,
1517 1, GNUNET_NO); 1491 GNUNET_NO);
1518 /* now, lookup 'query' */ 1492 /* now, lookup 'query' */
1519 prq.data = (const void *) &put[1]; 1493 prq.data = (const void *) &put[1];
1520 if (NULL != cp) 1494 if (NULL != cp)
@@ -1527,8 +1501,8 @@ GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
1527 prq.priority = 0; 1501 prq.priority = 0;
1528 prq.anonymity_level = UINT32_MAX; 1502 prq.anonymity_level = UINT32_MAX;
1529 prq.request_found = GNUNET_NO; 1503 prq.request_found = GNUNET_NO;
1530 GNUNET_CONTAINER_multihashmap_get_multiple (pr_map, 1504 GNUNET_CONTAINER_multihashmap_get_multiple (pr_map, &query, &process_reply,
1531 &query, &process_reply, &prq); 1505 &prq);
1532 if (NULL != cp) 1506 if (NULL != cp)
1533 { 1507 {
1534 GSF_connected_peer_change_preference_ (cp, 1508 GSF_connected_peer_change_preference_ (cp,
@@ -1551,12 +1525,10 @@ GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
1551 GNUNET_PEER_resolve (GSF_get_peer_performance_data_ (cp)->pid, 1525 GNUNET_PEER_resolve (GSF_get_peer_performance_data_ (cp)->pid,
1552 &pmc->origin); 1526 &pmc->origin);
1553 if (NULL == 1527 if (NULL ==
1554 GNUNET_DATASTORE_put (GSF_dsh, 1528 GNUNET_DATASTORE_put (GSF_dsh, 0, &query, dsize, &put[1], type,
1555 0, &query, dsize, &put[1], 1529 prq.priority, 1 /* anonymity */ ,
1556 type, prq.priority, 1 /* anonymity */ ,
1557 0 /* replication */ , 1530 0 /* replication */ ,
1558 expiration, 1531 expiration, 1 + prq.priority, MAX_DATASTORE_QUEUE,
1559 1 + prq.priority, MAX_DATASTORE_QUEUE,
1560 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 1532 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1561 &put_migration_continuation, pmc)) 1533 &put_migration_continuation, pmc))
1562 { 1534 {
@@ -1568,24 +1540,23 @@ GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
1568#if DEBUG_FS 1540#if DEBUG_FS
1569 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1541 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1570 "Choosing not to keep content `%s' (%d/%d)\n", 1542 "Choosing not to keep content `%s' (%d/%d)\n",
1571 GNUNET_h2s (&query), 1543 GNUNET_h2s (&query), active_to_migration,
1572 active_to_migration, test_put_load_too_high (prq.priority)); 1544 test_put_load_too_high (prq.priority));
1573#endif 1545#endif
1574 } 1546 }
1575 putl = GNUNET_LOAD_get_load (datastore_put_load); 1547 putl = GNUNET_LOAD_get_load (datastore_put_load);
1576 if ((NULL != (cp = prq.sender)) && 1548 if ((NULL != (cp = prq.sender)) && (GNUNET_NO == prq.request_found) &&
1577 (GNUNET_NO == prq.request_found) &&
1578 ((GNUNET_YES != active_to_migration) || 1549 ((GNUNET_YES != active_to_migration) ||
1579 (putl > 2.5 * (1 + prq.priority)))) 1550 (putl > 2.5 * (1 + prq.priority))))
1580 { 1551 {
1581 if (GNUNET_YES != active_to_migration) 1552 if (GNUNET_YES != active_to_migration)
1582 putl = 1.0 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 5); 1553 putl = 1.0 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 5);
1583 block_time = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 1554 block_time =
1584 5000 + 1555 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
1585 GNUNET_CRYPTO_random_u32 1556 5000 +
1586 (GNUNET_CRYPTO_QUALITY_WEAK, 1557 GNUNET_CRYPTO_random_u32
1587 (unsigned int) (60000 * putl * 1558 (GNUNET_CRYPTO_QUALITY_WEAK,
1588 putl))); 1559 (unsigned int) (60000 * putl * putl)));
1589 GSF_block_peer_migration_ (cp, block_time); 1560 GSF_block_peer_migration_ (cp, block_time);
1590 } 1561 }
1591 return GNUNET_OK; 1562 return GNUNET_OK;
@@ -1599,8 +1570,7 @@ void
1599GSF_pending_request_init_ () 1570GSF_pending_request_init_ ()
1600{ 1571{
1601 if (GNUNET_OK != 1572 if (GNUNET_OK !=
1602 GNUNET_CONFIGURATION_get_value_number (GSF_cfg, 1573 GNUNET_CONFIGURATION_get_value_number (GSF_cfg, "fs",
1603 "fs",
1604 "MAX_PENDING_REQUESTS", 1574 "MAX_PENDING_REQUESTS",
1605 &max_pending_requests)) 1575 &max_pending_requests))
1606 { 1576 {
@@ -1609,9 +1579,8 @@ GSF_pending_request_init_ ()
1609 ("Configuration fails to specify `%s', assuming default value."), 1579 ("Configuration fails to specify `%s', assuming default value."),
1610 "MAX_PENDING_REQUESTS"); 1580 "MAX_PENDING_REQUESTS");
1611 } 1581 }
1612 active_to_migration = GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, 1582 active_to_migration =
1613 "FS", 1583 GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, "FS", "CONTENT_CACHING");
1614 "CONTENT_CACHING");
1615 datastore_put_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE); 1584 datastore_put_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE);
1616 pr_map = GNUNET_CONTAINER_multihashmap_create (32 * 1024); 1585 pr_map = GNUNET_CONTAINER_multihashmap_create (32 * 1024);
1617 requests_by_expiration_heap = 1586 requests_by_expiration_heap =
diff --git a/src/fs/gnunet-service-fs_push.c b/src/fs/gnunet-service-fs_push.c
index 108fce5fc..6d8c05999 100644
--- a/src/fs/gnunet-service-fs_push.c
+++ b/src/fs/gnunet-service-fs_push.c
@@ -227,8 +227,8 @@ transmit_message (void *cls, size_t buf_size, void *buf)
227 memcpy (buf, msg, msize); 227 memcpy (buf, msg, msize);
228 GNUNET_free (msg); 228 GNUNET_free (msg);
229#if DEBUG_FS_MIGRATION 229#if DEBUG_FS_MIGRATION
230 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 230 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Pushing %u bytes to another peer\n",
231 "Pushing %u bytes to another peer\n", msize); 231 msize);
232#endif 232#endif
233 find_content (peer); 233 find_content (peer);
234 return msize; 234 return msize;
@@ -285,8 +285,8 @@ transmit_content (struct MigrationReadyPeer *peer,
285 "Asking for transmission of %u bytes for migration\n", msize); 285 "Asking for transmission of %u bytes for migration\n", msize);
286#endif 286#endif
287 peer->th = GSF_peer_transmit_ (peer->peer, GNUNET_NO, 0 /* priority */ , 287 peer->th = GSF_peer_transmit_ (peer->peer, GNUNET_NO, 0 /* priority */ ,
288 GNUNET_TIME_UNIT_FOREVER_REL, 288 GNUNET_TIME_UNIT_FOREVER_REL, msize,
289 msize, &transmit_message, peer); 289 &transmit_message, peer);
290 return ret; 290 return ret;
291} 291}
292 292
@@ -421,9 +421,9 @@ find_content (struct MigrationReadyPeer *mrp)
421 * @param cls unused 421 * @param cls unused
422 * @param tc scheduler context (also unused) 422 * @param tc scheduler context (also unused)
423 */ 423 */
424static void 424static void gather_migration_blocks (void *cls,
425gather_migration_blocks (void *cls, 425 const struct GNUNET_SCHEDULER_TaskContext
426 const struct GNUNET_SCHEDULER_TaskContext *tc); 426 *tc);
427 427
428 428
429/** 429/**
@@ -450,8 +450,8 @@ consider_gathering ()
450 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 450 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
451 "Scheduling gathering task (queue size: %u)\n", mig_size); 451 "Scheduling gathering task (queue size: %u)\n", mig_size);
452#endif 452#endif
453 mig_task = GNUNET_SCHEDULER_add_delayed (delay, 453 mig_task =
454 &gather_migration_blocks, NULL); 454 GNUNET_SCHEDULER_add_delayed (delay, &gather_migration_blocks, NULL);
455} 455}
456 456
457 457
@@ -470,13 +470,9 @@ consider_gathering ()
470 * maybe 0 if no unique identifier is available 470 * maybe 0 if no unique identifier is available
471 */ 471 */
472static void 472static void
473process_migration_content (void *cls, 473process_migration_content (void *cls, const GNUNET_HashCode * key, size_t size,
474 const GNUNET_HashCode * key, 474 const void *data, enum GNUNET_BLOCK_Type type,
475 size_t size, 475 uint32_t priority, uint32_t anonymity,
476 const void *data,
477 enum GNUNET_BLOCK_Type type,
478 uint32_t priority,
479 uint32_t anonymity,
480 struct GNUNET_TIME_Absolute expiration, uint64_t uid) 476 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
481{ 477{
482 struct MigrationReadyBlock *mb; 478 struct MigrationReadyBlock *mb;
@@ -501,9 +497,8 @@ process_migration_content (void *cls,
501 if (type == GNUNET_BLOCK_TYPE_FS_ONDEMAND) 497 if (type == GNUNET_BLOCK_TYPE_FS_ONDEMAND)
502 { 498 {
503 if (GNUNET_OK != 499 if (GNUNET_OK !=
504 GNUNET_FS_handle_on_demand_block (key, size, data, 500 GNUNET_FS_handle_on_demand_block (key, size, data, type, priority,
505 type, priority, anonymity, 501 anonymity, expiration, uid,
506 expiration, uid,
507 &process_migration_content, NULL)) 502 &process_migration_content, NULL))
508 consider_gathering (); 503 consider_gathering ();
509 return; 504 return;
@@ -560,11 +555,10 @@ gather_migration_blocks (void *cls,
560 "Asking datastore for content for replication (queue size: %u)\n", 555 "Asking datastore for content for replication (queue size: %u)\n",
561 mig_size); 556 mig_size);
562#endif 557#endif
563 mig_qe = GNUNET_DATASTORE_get_for_replication (GSF_dsh, 558 mig_qe =
564 0, UINT_MAX, 559 GNUNET_DATASTORE_get_for_replication (GSF_dsh, 0, UINT_MAX,
565 GNUNET_TIME_UNIT_FOREVER_REL, 560 GNUNET_TIME_UNIT_FOREVER_REL,
566 &process_migration_content, 561 &process_migration_content, NULL);
567 NULL);
568 if (NULL == mig_qe) 562 if (NULL == mig_qe)
569 consider_gathering (); 563 consider_gathering ();
570 } 564 }
@@ -632,15 +626,13 @@ GSF_push_stop_ (struct GSF_ConnectedPeer *peer)
632void 626void
633GSF_push_init_ () 627GSF_push_init_ ()
634{ 628{
635 enabled = GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, 629 enabled =
636 "FS", "CONTENT_PUSHING"); 630 GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, "FS", "CONTENT_PUSHING");
637 if (GNUNET_YES != enabled) 631 if (GNUNET_YES != enabled)
638 return; 632 return;
639 633
640 if (GNUNET_OK != 634 if (GNUNET_OK !=
641 GNUNET_CONFIGURATION_get_value_time (GSF_cfg, 635 GNUNET_CONFIGURATION_get_value_time (GSF_cfg, "fs", "MIN_MIGRATION_DELAY",
642 "fs",
643 "MIN_MIGRATION_DELAY",
644 &min_migration_delay)) 636 &min_migration_delay))
645 { 637 {
646 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 638 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
diff --git a/src/fs/gnunet-service-fs_put.c b/src/fs/gnunet-service-fs_put.c
index e67bf0c04..ec2344b37 100644
--- a/src/fs/gnunet-service-fs_put.c
+++ b/src/fs/gnunet-service-fs_put.c
@@ -86,9 +86,9 @@ static struct PutOperator operators[] = {
86 * @param cls type of blocks to gather 86 * @param cls type of blocks to gather
87 * @param tc scheduler context (unused) 87 * @param tc scheduler context (unused)
88 */ 88 */
89static void 89static void gather_dht_put_blocks (void *cls,
90gather_dht_put_blocks (void *cls, 90 const struct GNUNET_SCHEDULER_TaskContext
91 const struct GNUNET_SCHEDULER_TaskContext *tc); 91 *tc);
92 92
93 93
94/** 94/**
@@ -108,8 +108,9 @@ delay_dht_put_blocks (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
108 return; 108 return;
109 if (po->zero_anonymity_count_estimate > 0) 109 if (po->zero_anonymity_count_estimate > 0)
110 { 110 {
111 delay = GNUNET_TIME_relative_divide (GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY, 111 delay =
112 po->zero_anonymity_count_estimate); 112 GNUNET_TIME_relative_divide (GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY,
113 po->zero_anonymity_count_estimate);
113 delay = GNUNET_TIME_relative_min (delay, MAX_DHT_PUT_FREQ); 114 delay = GNUNET_TIME_relative_min (delay, MAX_DHT_PUT_FREQ);
114 } 115 }
115 else 116 else
@@ -118,8 +119,8 @@ delay_dht_put_blocks (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
118 * (hopefully) appear */ 119 * (hopefully) appear */
119 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5); 120 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5);
120 } 121 }
121 po->dht_task = GNUNET_SCHEDULER_add_delayed (delay, 122 po->dht_task =
122 &gather_dht_put_blocks, po); 123 GNUNET_SCHEDULER_add_delayed (delay, &gather_dht_put_blocks, po);
123} 124}
124 125
125 126
@@ -138,13 +139,9 @@ delay_dht_put_blocks (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
138 * maybe 0 if no unique identifier is available 139 * maybe 0 if no unique identifier is available
139 */ 140 */
140static void 141static void
141process_dht_put_content (void *cls, 142process_dht_put_content (void *cls, const GNUNET_HashCode * key, size_t size,
142 const GNUNET_HashCode * key, 143 const void *data, enum GNUNET_BLOCK_Type type,
143 size_t size, 144 uint32_t priority, uint32_t anonymity,
144 const void *data,
145 enum GNUNET_BLOCK_Type type,
146 uint32_t priority,
147 uint32_t anonymity,
148 struct GNUNET_TIME_Absolute expiration, uint64_t uid) 145 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
149{ 146{
150 struct PutOperator *po = cls; 147 struct PutOperator *po = cls;
@@ -157,22 +154,16 @@ process_dht_put_content (void *cls,
157 po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_blocks, po); 154 po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_blocks, po);
158 return; 155 return;
159 } 156 }
160 po->zero_anonymity_count_estimate = GNUNET_MAX (po->current_offset, 157 po->zero_anonymity_count_estimate =
161 po->zero_anonymity_count_estimate); 158 GNUNET_MAX (po->current_offset, po->zero_anonymity_count_estimate);
162#if DEBUG_FS 159#if DEBUG_FS
163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 160 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
164 "Retrieved block `%s' of type %u for DHT PUT\n", 161 "Retrieved block `%s' of type %u for DHT PUT\n", GNUNET_h2s (key),
165 GNUNET_h2s (key), type); 162 type);
166#endif 163#endif
167 GNUNET_DHT_put (GSF_dht, 164 GNUNET_DHT_put (GSF_dht, key, DEFAULT_PUT_REPLICATION, GNUNET_DHT_RO_NONE,
168 key, 165 type, size, data, expiration, GNUNET_TIME_UNIT_FOREVER_REL,
169 DEFAULT_PUT_REPLICATION, 166 &delay_dht_put_blocks, po);
170 GNUNET_DHT_RO_NONE,
171 type,
172 size,
173 data,
174 expiration,
175 GNUNET_TIME_UNIT_FOREVER_REL, &delay_dht_put_blocks, po);
176} 167}
177 168
178 169
@@ -190,13 +181,12 @@ gather_dht_put_blocks (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
190 po->dht_task = GNUNET_SCHEDULER_NO_TASK; 181 po->dht_task = GNUNET_SCHEDULER_NO_TASK;
191 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 182 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
192 return; 183 return;
193 po->dht_qe = GNUNET_DATASTORE_get_zero_anonymity (GSF_dsh, 184 po->dht_qe =
194 po->current_offset++, 185 GNUNET_DATASTORE_get_zero_anonymity (GSF_dsh, po->current_offset++, 0,
195 0, UINT_MAX, 186 UINT_MAX,
196 GNUNET_TIME_UNIT_FOREVER_REL, 187 GNUNET_TIME_UNIT_FOREVER_REL,
197 po->dht_put_type, 188 po->dht_put_type,
198 &process_dht_put_content, 189 &process_dht_put_content, po);
199 po);
200 if (NULL == po->dht_qe) 190 if (NULL == po->dht_qe)
201 po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_blocks, po); 191 po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_blocks, po);
202} 192}
diff --git a/src/fs/gnunet-unindex.c b/src/fs/gnunet-unindex.c
index a4aad4568..d52956a75 100644
--- a/src/fs/gnunet-unindex.c
+++ b/src/fs/gnunet-unindex.c
@@ -86,16 +86,14 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
86 if (verbose) 86 if (verbose)
87 { 87 {
88 s = GNUNET_STRINGS_relative_time_to_string (info->value.unindex.eta); 88 s = GNUNET_STRINGS_relative_time_to_string (info->value.unindex.eta);
89 fprintf (stdout, 89 fprintf (stdout, _("Unindexing at %llu/%llu (%s remaining)\n"),
90 _("Unindexing at %llu/%llu (%s remaining)\n"),
91 (unsigned long long) info->value.unindex.completed, 90 (unsigned long long) info->value.unindex.completed,
92 (unsigned long long) info->value.unindex.size, s); 91 (unsigned long long) info->value.unindex.size, s);
93 GNUNET_free (s); 92 GNUNET_free (s);
94 } 93 }
95 break; 94 break;
96 case GNUNET_FS_STATUS_UNINDEX_ERROR: 95 case GNUNET_FS_STATUS_UNINDEX_ERROR:
97 fprintf (stderr, 96 fprintf (stderr, _("Error unindexing: %s.\n"),
98 _("Error unindexing: %s.\n"),
99 info->value.unindex.specifics.error.message); 97 info->value.unindex.specifics.error.message);
100 GNUNET_SCHEDULER_shutdown (); 98 GNUNET_SCHEDULER_shutdown ();
101 break; 99 break;
@@ -104,8 +102,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
104 GNUNET_SCHEDULER_shutdown (); 102 GNUNET_SCHEDULER_shutdown ();
105 break; 103 break;
106 case GNUNET_FS_STATUS_UNINDEX_STOPPED: 104 case GNUNET_FS_STATUS_UNINDEX_STOPPED:
107 GNUNET_SCHEDULER_add_continuation (&cleanup_task, 105 GNUNET_SCHEDULER_add_continuation (&cleanup_task, NULL,
108 NULL,
109 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 106 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
110 break; 107 break;
111 default: 108 default:
@@ -125,9 +122,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
125 * @param c configuration 122 * @param c configuration
126 */ 123 */
127static void 124static void
128run (void *cls, 125run (void *cls, char *const *args, const char *cfgfile,
129 char *const *args, 126 const struct GNUNET_CONFIGURATION_Handle *c)
130 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
131{ 127{
132 /* check arguments */ 128 /* check arguments */
133 if ((args[0] == NULL) || (args[1] != NULL)) 129 if ((args[0] == NULL) || (args[1] != NULL))
@@ -137,10 +133,9 @@ run (void *cls,
137 return; 133 return;
138 } 134 }
139 cfg = c; 135 cfg = c;
140 ctx = GNUNET_FS_start (cfg, 136 ctx =
141 "gnunet-unindex", 137 GNUNET_FS_start (cfg, "gnunet-unindex", &progress_cb, NULL,
142 &progress_cb, 138 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
143 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
144 if (NULL == ctx) 139 if (NULL == ctx)
145 { 140 {
146 fprintf (stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); 141 fprintf (stderr, _("Could not initialize `%s' subsystem.\n"), "FS");
@@ -154,8 +149,8 @@ run (void *cls,
154 GNUNET_FS_stop (ctx); 149 GNUNET_FS_stop (ctx);
155 return; 150 return;
156 } 151 }
157 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 152 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
158 &shutdown_task, NULL); 153 NULL);
159} 154}
160 155
161 156
@@ -176,9 +171,7 @@ main (int argc, char *const *argv)
176 GNUNET_GETOPT_OPTION_END 171 GNUNET_GETOPT_OPTION_END
177 }; 172 };
178 return (GNUNET_OK == 173 return (GNUNET_OK ==
179 GNUNET_PROGRAM_run (argc, 174 GNUNET_PROGRAM_run (argc, argv, "gnunet-unindex [OPTIONS] FILENAME",
180 argv,
181 "gnunet-unindex [OPTIONS] FILENAME",
182 gettext_noop 175 gettext_noop
183 ("Unindex a file that was previously indexed with gnunet-publish."), 176 ("Unindex a file that was previously indexed with gnunet-publish."),
184 options, &run, NULL)) ? ret : 1; 177 options, &run, NULL)) ? ret : 1;
diff --git a/src/fs/perf_gnunet_service_fs_p2p.c b/src/fs/perf_gnunet_service_fs_p2p.c
index 92441e901..0737ea949 100644
--- a/src/fs/perf_gnunet_service_fs_p2p.c
+++ b/src/fs/perf_gnunet_service_fs_p2p.c
@@ -115,15 +115,13 @@ static struct StatValues stats[] = {
115 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration 115 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
116 */ 116 */
117static int 117static int
118print_stat (void *cls, 118print_stat (void *cls, const char *subsystem, const char *name, uint64_t value,
119 const char *subsystem, 119 int is_persistent)
120 const char *name, uint64_t value, int is_persistent)
121{ 120{
122 struct StatMaster *sm = cls; 121 struct StatMaster *sm = cls;
123 122
124 fprintf (stderr, 123 fprintf (stderr, "Peer %2u: %12s/%50s = %12llu\n", sm->daemon, subsystem,
125 "Peer %2u: %12s/%50s = %12llu\n", 124 name, (unsigned long long) value);
126 sm->daemon, subsystem, name, (unsigned long long) value);
127 return GNUNET_OK; 125 return GNUNET_OK;
128} 126}
129 127
@@ -164,8 +162,8 @@ stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
164#else 162#else
165 stats[sm->value].subsystem, stats[sm->value].name, 163 stats[sm->value].subsystem, stats[sm->value].name,
166#endif 164#endif
167 GNUNET_TIME_UNIT_FOREVER_REL, 165 GNUNET_TIME_UNIT_FOREVER_REL, &get_done, &print_stat,
168 &get_done, &print_stat, sm); 166 sm);
169 return; 167 return;
170 } 168 }
171 GNUNET_STATISTICS_destroy (sm->stat, GNUNET_NO); 169 GNUNET_STATISTICS_destroy (sm->stat, GNUNET_NO);
@@ -177,9 +175,10 @@ stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
177 GNUNET_SCHEDULER_add_now (&do_stop, NULL); 175 GNUNET_SCHEDULER_add_now (&do_stop, NULL);
178 return; 176 return;
179 } 177 }
180 sm->stat = GNUNET_STATISTICS_create ("<driver>", 178 sm->stat =
181 GNUNET_FS_TEST_get_configuration 179 GNUNET_STATISTICS_create ("<driver>",
182 (daemons, sm->daemon)); 180 GNUNET_FS_TEST_get_configuration (daemons,
181 sm->daemon));
183 GNUNET_SCHEDULER_add_now (&stat_run, sm); 182 GNUNET_SCHEDULER_add_now (&stat_run, sm);
184} 183}
185 184
@@ -201,13 +200,14 @@ do_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
201 1000LL / del.rel_value); 200 1000LL / del.rel_value);
202 fprintf (stdout, "Download speed was %s/s\n", fancy); 201 fprintf (stdout, "Download speed was %s/s\n", fancy);
203 GNUNET_free (fancy); 202 GNUNET_free (fancy);
204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished download, shutting down\n",
205 "Finished download, shutting down\n",
206 (unsigned long long) FILESIZE); 204 (unsigned long long) FILESIZE);
207 sm = GNUNET_malloc (sizeof (struct StatMaster)); 205 sm = GNUNET_malloc (sizeof (struct StatMaster));
208 sm->stat = GNUNET_STATISTICS_create ("<driver>", 206 sm->stat =
209 GNUNET_FS_TEST_get_configuration 207 GNUNET_STATISTICS_create ("<driver>",
210 (daemons, sm->daemon)); 208 GNUNET_FS_TEST_get_configuration (daemons,
209 sm->
210 daemon));
211 GNUNET_SCHEDULER_add_now (&stat_run, sm); 211 GNUNET_SCHEDULER_add_now (&stat_run, sm);
212 } 212 }
213 else 213 else
@@ -233,16 +233,15 @@ do_download (void *cls, const struct GNUNET_FS_Uri *uri)
233 ok = 1; 233 ok = 1;
234 return; 234 return;
235 } 235 }
236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n",
237 "Downloading %llu bytes\n", (unsigned long long) FILESIZE); 237 (unsigned long long) FILESIZE);
238 start_time = GNUNET_TIME_absolute_get (); 238 start_time = GNUNET_TIME_absolute_get ();
239 if (NULL != strstr (progname, "dht")) 239 if (NULL != strstr (progname, "dht"))
240 anonymity = 0; 240 anonymity = 0;
241 else 241 else
242 anonymity = 1; 242 anonymity = 1;
243 GNUNET_FS_TEST_download (daemons[0], 243 GNUNET_FS_TEST_download (daemons[0], TIMEOUT, anonymity, SEED, uri, VERBOSE,
244 TIMEOUT, 244 &do_report, NULL);
245 anonymity, SEED, uri, VERBOSE, &do_report, NULL);
246} 245}
247 246
248 247
@@ -259,8 +258,8 @@ do_publish (void *cls, const char *emsg)
259 ok = 1; 258 ok = 1;
260 return; 259 return;
261 } 260 }
262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
263 "Publishing %llu bytes\n", (unsigned long long) FILESIZE); 262 (unsigned long long) FILESIZE);
264 if (NULL != strstr (progname, "index")) 263 if (NULL != strstr (progname, "index"))
265 do_index = GNUNET_YES; 264 do_index = GNUNET_YES;
266 else 265 else
@@ -270,11 +269,9 @@ do_publish (void *cls, const char *emsg)
270 else 269 else
271 anonymity = 1; 270 anonymity = 1;
272 271
273 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1], 272 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity,
274 TIMEOUT, 273 do_index, FILESIZE, SEED, VERBOSE, &do_download,
275 anonymity, 274 NULL);
276 do_index, FILESIZE, SEED,
277 VERBOSE, &do_download, NULL);
278} 275}
279 276
280 277
@@ -287,27 +284,22 @@ do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
287 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 284 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
288 "Daemons started, will now try to connect them\n"); 285 "Daemons started, will now try to connect them\n");
289 pg = GNUNET_FS_TEST_get_group (daemons); 286 pg = GNUNET_FS_TEST_get_group (daemons);
290 GNUNET_break ((NUM_DAEMONS - 1) * 2 287 GNUNET_break ((NUM_DAEMONS - 1) * 2 ==
291 == (GNUNET_TESTING_create_topology (pg, 288 (GNUNET_TESTING_create_topology
292 GNUNET_TESTING_TOPOLOGY_LINE, 289 (pg, GNUNET_TESTING_TOPOLOGY_LINE,
293 GNUNET_TESTING_TOPOLOGY_NONE, 290 GNUNET_TESTING_TOPOLOGY_NONE, NULL)));
294 NULL))); 291 GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_LINE,
295 GNUNET_TESTING_connect_topology (pg, 292 GNUNET_TESTING_TOPOLOGY_OPTION_NONE, 0.0,
296 GNUNET_TESTING_TOPOLOGY_LINE,
297 GNUNET_TESTING_TOPOLOGY_OPTION_NONE,
298 0.0,
299 TIMEOUT, NUM_DAEMONS, &do_publish, NULL); 293 TIMEOUT, NUM_DAEMONS, &do_publish, NULL);
300} 294}
301 295
302 296
303static void 297static void
304run (void *cls, 298run (void *cls, char *const *args, const char *cfgfile,
305 char *const *args, 299 const struct GNUNET_CONFIGURATION_Handle *cfg)
306 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
307{ 300{
308 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf", 301 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf", TIMEOUT, NUM_DAEMONS,
309 TIMEOUT, 302 daemons, &do_connect, NULL);
310 NUM_DAEMONS, daemons, &do_connect, NULL);
311} 303}
312 304
313 305
@@ -335,9 +327,9 @@ main (int argc, char *argv[])
335 "WARNING", 327 "WARNING",
336#endif 328#endif
337 NULL); 329 NULL);
338 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 330 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
339 argvx, "perf-gnunet-service-fs-p2p-index", 331 "perf-gnunet-service-fs-p2p-index", "nohelp", options,
340 "nohelp", options, &run, NULL); 332 &run, NULL);
341 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); 333 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
342 return ok; 334 return ok;
343} 335}
diff --git a/src/fs/perf_gnunet_service_fs_p2p_trust.c b/src/fs/perf_gnunet_service_fs_p2p_trust.c
index a78ff0571..5a8d4242a 100644
--- a/src/fs/perf_gnunet_service_fs_p2p_trust.c
+++ b/src/fs/perf_gnunet_service_fs_p2p_trust.c
@@ -148,15 +148,13 @@ static struct StatValues stats[] = {
148 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration 148 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
149 */ 149 */
150static int 150static int
151print_stat (void *cls, 151print_stat (void *cls, const char *subsystem, const char *name, uint64_t value,
152 const char *subsystem, 152 int is_persistent)
153 const char *name, uint64_t value, int is_persistent)
154{ 153{
155 struct StatMaster *sm = cls; 154 struct StatMaster *sm = cls;
156 155
157 fprintf (stderr, 156 fprintf (stderr, "Peer %2u: %12s/%50s = %12llu\n", sm->daemon, subsystem,
158 "Peer %2u: %12s/%50s = %12llu\n", 157 name, (unsigned long long) value);
159 sm->daemon, subsystem, name, (unsigned long long) value);
160 return GNUNET_OK; 158 return GNUNET_OK;
161} 159}
162 160
@@ -197,8 +195,8 @@ stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
197#else 195#else
198 stats[sm->value].subsystem, stats[sm->value].name, 196 stats[sm->value].subsystem, stats[sm->value].name,
199#endif 197#endif
200 GNUNET_TIME_UNIT_FOREVER_REL, 198 GNUNET_TIME_UNIT_FOREVER_REL, &get_done, &print_stat,
201 &get_done, &print_stat, sm); 199 sm);
202 return; 200 return;
203 } 201 }
204 GNUNET_STATISTICS_destroy (sm->stat, GNUNET_NO); 202 GNUNET_STATISTICS_destroy (sm->stat, GNUNET_NO);
@@ -210,9 +208,10 @@ stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
210 GNUNET_SCHEDULER_add_now (&do_stop, NULL); 208 GNUNET_SCHEDULER_add_now (&do_stop, NULL);
211 return; 209 return;
212 } 210 }
213 sm->stat = GNUNET_STATISTICS_create ("<driver>", 211 sm->stat =
214 GNUNET_FS_TEST_get_configuration 212 GNUNET_STATISTICS_create ("<driver>",
215 (daemons, sm->daemon)); 213 GNUNET_FS_TEST_get_configuration (daemons,
214 sm->daemon));
216 GNUNET_SCHEDULER_add_now (&stat_run, sm); 215 GNUNET_SCHEDULER_add_now (&stat_run, sm);
217} 216}
218 217
@@ -242,9 +241,11 @@ do_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
242 "Finished all downloads, shutting down\n", 241 "Finished all downloads, shutting down\n",
243 (unsigned long long) FILESIZE); 242 (unsigned long long) FILESIZE);
244 sm = GNUNET_malloc (sizeof (struct StatMaster)); 243 sm = GNUNET_malloc (sizeof (struct StatMaster));
245 sm->stat = GNUNET_STATISTICS_create ("<driver>", 244 sm->stat =
246 GNUNET_FS_TEST_get_configuration 245 GNUNET_STATISTICS_create ("<driver>",
247 (daemons, sm->daemon)); 246 GNUNET_FS_TEST_get_configuration (daemons,
247 sm->
248 daemon));
248 GNUNET_SCHEDULER_add_now (&stat_run, sm); 249 GNUNET_SCHEDULER_add_now (&stat_run, sm);
249 } 250 }
250 else 251 else
@@ -273,8 +274,8 @@ do_downloads (void *cls, const struct GNUNET_FS_Uri *u2)
273 return; 274 return;
274 } 275 }
275 uri2 = GNUNET_FS_uri_dup (u2); 276 uri2 = GNUNET_FS_uri_dup (u2);
276 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 277 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n",
277 "Downloading %llu bytes\n", (unsigned long long) FILESIZE); 278 (unsigned long long) FILESIZE);
278 start_time = GNUNET_TIME_absolute_get (); 279 start_time = GNUNET_TIME_absolute_get ();
279 if (NULL != strstr (progname, "dht")) 280 if (NULL != strstr (progname, "dht"))
280 anonymity = 0; 281 anonymity = 0;
@@ -284,21 +285,15 @@ do_downloads (void *cls, const struct GNUNET_FS_Uri *u2)
284 * these peers do participate in sharing, they just 285 * these peers do participate in sharing, they just
285 * don't have to offer anything *initially*. */ 286 * don't have to offer anything *initially*. */
286 for (i = 0; i < NUM_DAEMONS - 2; i++) 287 for (i = 0; i < NUM_DAEMONS - 2; i++)
287 GNUNET_FS_TEST_download (daemons[i], 288 GNUNET_FS_TEST_download (daemons[i], TIMEOUT, anonymity,
288 TIMEOUT,
289 anonymity,
290 0 == (i % 2) ? SEED1 : SEED2, 289 0 == (i % 2) ? SEED1 : SEED2,
291 0 == (i % 2) ? uri1 : uri2, 290 0 == (i % 2) ? uri1 : uri2, VERBOSE, &do_report,
292 VERBOSE, &do_report, "leach"); 291 "leach");
293 /* mutual downloads of (primary) sharing peers */ 292 /* mutual downloads of (primary) sharing peers */
294 GNUNET_FS_TEST_download (daemons[NUM_DAEMONS - 2], 293 GNUNET_FS_TEST_download (daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity, SEED1,
295 TIMEOUT, 294 uri1, VERBOSE, &do_report, "seeder 2");
296 anonymity, SEED1, uri1, 295 GNUNET_FS_TEST_download (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, SEED2,
297 VERBOSE, &do_report, "seeder 2"); 296 uri2, VERBOSE, &do_report, "seeder 1");
298 GNUNET_FS_TEST_download (daemons[NUM_DAEMONS - 1],
299 TIMEOUT,
300 anonymity, SEED2, uri2,
301 VERBOSE, &do_report, "seeder 1");
302} 297}
303 298
304 299
@@ -317,8 +312,8 @@ do_publish2 (void *cls, const struct GNUNET_FS_Uri *u1)
317 return; 312 return;
318 } 313 }
319 uri1 = GNUNET_FS_uri_dup (u1); 314 uri1 = GNUNET_FS_uri_dup (u1);
320 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 315 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
321 "Publishing %llu bytes\n", (unsigned long long) FILESIZE); 316 (unsigned long long) FILESIZE);
322 if (NULL != strstr (progname, "index")) 317 if (NULL != strstr (progname, "index"))
323 do_index = GNUNET_YES; 318 do_index = GNUNET_YES;
324 else 319 else
@@ -328,11 +323,9 @@ do_publish2 (void *cls, const struct GNUNET_FS_Uri *u1)
328 else 323 else
329 anonymity = 1; 324 anonymity = 1;
330 325
331 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 2], 326 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity,
332 TIMEOUT, 327 do_index, FILESIZE, SEED2, VERBOSE, &do_downloads,
333 anonymity, 328 NULL);
334 do_index, FILESIZE, SEED2,
335 VERBOSE, &do_downloads, NULL);
336} 329}
337 330
338static void 331static void
@@ -348,8 +341,8 @@ do_publish1 (void *cls, const char *emsg)
348 ok = 1; 341 ok = 1;
349 return; 342 return;
350 } 343 }
351 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
352 "Publishing %llu bytes\n", (unsigned long long) FILESIZE); 345 (unsigned long long) FILESIZE);
353 if (NULL != strstr (progname, "index")) 346 if (NULL != strstr (progname, "index"))
354 do_index = GNUNET_YES; 347 do_index = GNUNET_YES;
355 else 348 else
@@ -359,11 +352,9 @@ do_publish1 (void *cls, const char *emsg)
359 else 352 else
360 anonymity = 1; 353 anonymity = 1;
361 354
362 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1], 355 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity,
363 TIMEOUT, 356 do_index, FILESIZE, SEED1, VERBOSE, &do_publish2,
364 anonymity, 357 NULL);
365 do_index, FILESIZE, SEED1,
366 VERBOSE, &do_publish2, NULL);
367} 358}
368 359
369 360
@@ -376,25 +367,20 @@ do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
376 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
377 "Daemons started, will now try to connect them\n"); 368 "Daemons started, will now try to connect them\n");
378 pg = GNUNET_FS_TEST_get_group (daemons); 369 pg = GNUNET_FS_TEST_get_group (daemons);
379 GNUNET_TESTING_create_topology (pg, 370 GNUNET_TESTING_create_topology (pg, GNUNET_TESTING_TOPOLOGY_CLIQUE,
380 GNUNET_TESTING_TOPOLOGY_CLIQUE,
381 GNUNET_TESTING_TOPOLOGY_NONE, NULL); 371 GNUNET_TESTING_TOPOLOGY_NONE, NULL);
382 GNUNET_TESTING_connect_topology (pg, 372 GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_CLIQUE,
383 GNUNET_TESTING_TOPOLOGY_CLIQUE, 373 GNUNET_TESTING_TOPOLOGY_OPTION_NONE, 0.0,
384 GNUNET_TESTING_TOPOLOGY_OPTION_NONE,
385 0.0,
386 TIMEOUT, NUM_DAEMONS, &do_publish1, NULL); 374 TIMEOUT, NUM_DAEMONS, &do_publish1, NULL);
387} 375}
388 376
389 377
390static void 378static void
391run (void *cls, 379run (void *cls, char *const *args, const char *cfgfile,
392 char *const *args, 380 const struct GNUNET_CONFIGURATION_Handle *cfg)
393 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
394{ 381{
395 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf", 382 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf", TIMEOUT, NUM_DAEMONS,
396 TIMEOUT, 383 daemons, &do_connect, NULL);
397 NUM_DAEMONS, daemons, &do_connect, NULL);
398} 384}
399 385
400 386
@@ -422,9 +408,9 @@ main (int argc, char *argv[])
422 "WARNING", 408 "WARNING",
423#endif 409#endif
424 NULL); 410 NULL);
425 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 411 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
426 argvx, "perf-gnunet-service-fs-p2p-trust", 412 "perf-gnunet-service-fs-p2p-trust", "nohelp", options,
427 "nohelp", options, &run, NULL); 413 &run, NULL);
428 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); 414 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
429 return ok; 415 return ok;
430} 416}
diff --git a/src/fs/test_fs.c b/src/fs/test_fs.c
index b936c3199..9aee89e85 100644
--- a/src/fs/test_fs.c
+++ b/src/fs/test_fs.c
@@ -40,8 +40,8 @@ makeName (unsigned int i)
40 fn = GNUNET_malloc (strlen ("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") + 40 fn = GNUNET_malloc (strlen ("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") +
41 14); 41 14);
42 GNUNET_snprintf (fn, 42 GNUNET_snprintf (fn,
43 strlen ("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") + 43 strlen ("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") + 14,
44 14, "/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST%u", i); 44 "/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST%u", i);
45 GNUNET_disk_directory_create_for_file (NULL, fn); 45 GNUNET_disk_directory_create_for_file (NULL, fn);
46 return fn; 46 return fn;
47} 47}
@@ -143,9 +143,8 @@ main (int argc, char *argv[])
143 &eventCallback, NULL); 143 &eventCallback, NULL);
144 CHECK (ctx != NULL); 144 CHECK (ctx != NULL);
145 filename = makeName (42); 145 filename = makeName (42);
146 GNUNET_disk_file_write (NULL, 146 GNUNET_disk_file_write (NULL, filename, "foo bar test!",
147 filename, 147 strlen ("foo bar test!"), "600");
148 "foo bar test!", strlen ("foo bar test!"), "600");
149 meta = GNUNET_meta_data_create (); 148 meta = GNUNET_meta_data_create ();
150 kuri = 149 kuri =
151 GNUNET_ECRS_keyword_command_line_to_uri (NULL, 2, 150 GNUNET_ECRS_keyword_command_line_to_uri (NULL, 2,
@@ -153,11 +152,9 @@ main (int argc, char *argv[])
153 /* upload */ 152 /* upload */
154 upload = GNUNET_FSUI_upload_start (ctx, filename, (GNUNET_FSUI_DirectoryScanCallback) & GNUNET_disk_directory_scan, NULL, 0, /* anonymity */ 153 upload = GNUNET_FSUI_upload_start (ctx, filename, (GNUNET_FSUI_DirectoryScanCallback) & GNUNET_disk_directory_scan, NULL, 0, /* anonymity */
155 0, /* priority */ 154 0, /* priority */
156 GNUNET_YES, 155 GNUNET_YES, GNUNET_NO, GNUNET_NO,
157 GNUNET_NO, 156 GNUNET_get_time () + 5 * GNUNET_CRON_HOURS,
158 GNUNET_NO, 157 meta, kuri, kuri);
159 GNUNET_get_time () +
160 5 * GNUNET_CRON_HOURS, meta, kuri, kuri);
161 CHECK (upload != NULL); 158 CHECK (upload != NULL);
162 GNUNET_ECRS_uri_destroy (kuri); 159 GNUNET_ECRS_uri_destroy (kuri);
163 GNUNET_meta_data_destroy (meta); 160 GNUNET_meta_data_destroy (meta);
@@ -190,11 +187,9 @@ main (int argc, char *argv[])
190 187
191 /* download */ 188 /* download */
192 fn = makeName (43); 189 fn = makeName (43);
193 download = GNUNET_FSUI_download_start (ctx, 190 download =
194 0, 191 GNUNET_FSUI_download_start (ctx, 0, GNUNET_NO, search_uri, search_meta,
195 GNUNET_NO, 192 fn, NULL, NULL);
196 search_uri,
197 search_meta, fn, NULL, NULL);
198 GNUNET_free (fn); 193 GNUNET_free (fn);
199 prog = 0; 194 prog = 0;
200 while (lastEvent != GNUNET_FSUI_download_completed) 195 while (lastEvent != GNUNET_FSUI_download_completed)
diff --git a/src/fs/test_fs_directory.c b/src/fs/test_fs_directory.c
index d8a9c63b6..ac581bd6f 100644
--- a/src/fs/test_fs_directory.c
+++ b/src/fs/test_fs_directory.c
@@ -41,11 +41,9 @@ struct PCLS
41}; 41};
42 42
43static void 43static void
44processor (void *cls, 44processor (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri,
45 const char *filename, 45 const struct GNUNET_CONTAINER_MetaData *md, size_t length,
46 const struct GNUNET_FS_Uri *uri, 46 const void *data)
47 const struct GNUNET_CONTAINER_MetaData *md,
48 size_t length, const void *data)
49{ 47{
50 struct PCLS *p = cls; 48 struct PCLS *p = cls;
51 int i; 49 int i;
@@ -54,8 +52,7 @@ processor (void *cls,
54 return; /* ignore directory's meta data */ 52 return; /* ignore directory's meta data */
55 for (i = 0; i < p->max; i++) 53 for (i = 0; i < p->max; i++)
56 { 54 {
57 if (GNUNET_CONTAINER_meta_data_test_equal (p->md[i], 55 if (GNUNET_CONTAINER_meta_data_test_equal (p->md[i], md) &&
58 md) &&
59 GNUNET_FS_uri_test_equal (p->uri[i], uri)) 56 GNUNET_FS_uri_test_equal (p->uri[i], uri))
60 { 57 {
61 p->pos++; 58 p->pos++;
@@ -88,17 +85,12 @@ testDirectory (unsigned int i)
88 uris = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri *) * i); 85 uris = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri *) * i);
89 mds = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_MetaData *) * i); 86 mds = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_MetaData *) * i);
90 meta = GNUNET_CONTAINER_meta_data_create (); 87 meta = GNUNET_CONTAINER_meta_data_create ();
91 GNUNET_CONTAINER_meta_data_insert (meta, 88 GNUNET_CONTAINER_meta_data_insert (meta, "<test>", EXTRACTOR_METATYPE_TITLE,
92 "<test>", 89 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
93 EXTRACTOR_METATYPE_TITLE,
94 EXTRACTOR_METAFORMAT_UTF8,
95 "text/plain",
96 "A title", strlen ("A title") + 1); 90 "A title", strlen ("A title") + 1);
97 GNUNET_CONTAINER_meta_data_insert (meta, 91 GNUNET_CONTAINER_meta_data_insert (meta, "<test>",
98 "<test>",
99 EXTRACTOR_METATYPE_AUTHOR_NAME, 92 EXTRACTOR_METATYPE_AUTHOR_NAME,
100 EXTRACTOR_METAFORMAT_UTF8, 93 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
101 "text/plain",
102 "An author", strlen ("An author") + 1); 94 "An author", strlen ("An author") + 1);
103 for (p = 0; p < i; p++) 95 for (p = 0; p < i; p++)
104 { 96 {
@@ -106,14 +98,12 @@ testDirectory (unsigned int i)
106 for (q = 0; q <= p; q++) 98 for (q = 0; q <= p; q++)
107 { 99 {
108 GNUNET_snprintf (txt, sizeof (txt), "%u -- %u\n", p, q); 100 GNUNET_snprintf (txt, sizeof (txt), "%u -- %u\n", p, q);
109 GNUNET_CONTAINER_meta_data_insert (mds[p], 101 GNUNET_CONTAINER_meta_data_insert (mds[p], "<test>",
110 "<test>",
111 q % EXTRACTOR_metatype_get_max (), 102 q % EXTRACTOR_metatype_get_max (),
112 EXTRACTOR_METAFORMAT_UTF8, 103 EXTRACTOR_METAFORMAT_UTF8,
113 "text/plain", txt, strlen (txt) + 1); 104 "text/plain", txt, strlen (txt) + 1);
114 } 105 }
115 GNUNET_snprintf (uri, 106 GNUNET_snprintf (uri, sizeof (uri),
116 sizeof (uri),
117 "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u", 107 "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u",
118 p); 108 p);
119 emsg = NULL; 109 emsg = NULL;
diff --git a/src/fs/test_fs_download.c b/src/fs/test_fs_download.c
index d37b94c03..34625ff2e 100644
--- a/src/fs/test_fs_download.c
+++ b/src/fs/test_fs_download.c
@@ -140,42 +140,42 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
140 (unsigned long long) event->value.publish.completed, 140 (unsigned long long) event->value.publish.completed,
141 (unsigned long long) event->value.publish.size, 141 (unsigned long long) event->value.publish.size,
142 event->value.publish.specifics.progress.depth, 142 event->value.publish.specifics.progress.depth,
143 (unsigned long long) event->value.publish.specifics. 143 (unsigned long long) event->value.publish.specifics.progress.
144 progress.offset); 144 offset);
145#endif 145#endif
146 break; 146 break;
147 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 147 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
148 printf ("Publishing complete, %llu kb/s.\n", 148 printf ("Publishing complete, %llu kb/s.\n",
149 (unsigned long long) (FILESIZE * 1000LL / 149 (unsigned long long) (FILESIZE * 1000LL /
150 (1 + 150 (1 +
151 GNUNET_TIME_absolute_get_duration 151 GNUNET_TIME_absolute_get_duration (start).
152 (start).rel_value) / 1024LL)); 152 rel_value) / 1024LL));
153 GAUGER ("FS", "Publishing speed (insertion)", 153 GAUGER ("FS", "Publishing speed (insertion)",
154 (unsigned long long) (FILESIZE * 1000LL / 154 (unsigned long long) (FILESIZE * 1000LL /
155 (1 + 155 (1 +
156 GNUNET_TIME_absolute_get_duration 156 GNUNET_TIME_absolute_get_duration (start).
157 (start).rel_value) / 1024LL), "kb/s"); 157 rel_value) / 1024LL), "kb/s");
158 fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst"); 158 fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst");
159 start = GNUNET_TIME_absolute_get (); 159 start = GNUNET_TIME_absolute_get ();
160 download = GNUNET_FS_download_start (fs, 160 download =
161 event->value.publish. 161 GNUNET_FS_download_start (fs,
162 specifics.completed.chk_uri, NULL, fn, 162 event->value.publish.specifics.completed.
163 NULL, 0, FILESIZE, 1, 163 chk_uri, NULL, fn, NULL, 0, FILESIZE, 1,
164 GNUNET_FS_DOWNLOAD_OPTION_NONE, 164 GNUNET_FS_DOWNLOAD_OPTION_NONE, "download",
165 "download", NULL); 165 NULL);
166 GNUNET_assert (download != NULL); 166 GNUNET_assert (download != NULL);
167 break; 167 break;
168 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: 168 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
169 printf ("Download complete, %llu kb/s.\n", 169 printf ("Download complete, %llu kb/s.\n",
170 (unsigned long long) (FILESIZE * 1000LL / 170 (unsigned long long) (FILESIZE * 1000LL /
171 (1 + 171 (1 +
172 GNUNET_TIME_absolute_get_duration 172 GNUNET_TIME_absolute_get_duration (start).
173 (start).rel_value) / 1024LL)); 173 rel_value) / 1024LL));
174 GAUGER ("FS", "Local download speed (inserted)", 174 GAUGER ("FS", "Local download speed (inserted)",
175 (unsigned long long) (FILESIZE * 1000LL / 175 (unsigned long long) (FILESIZE * 1000LL /
176 (1 + 176 (1 +
177 GNUNET_TIME_absolute_get_duration 177 GNUNET_TIME_absolute_get_duration (start).
178 (start).rel_value) / 1024LL), "kb/s"); 178 rel_value) / 1024LL), "kb/s");
179 GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); 179 GNUNET_SCHEDULER_add_now (&abort_download_task, NULL);
180 break; 180 break;
181 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: 181 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
@@ -185,22 +185,19 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
185 (unsigned long long) event->value.download.completed, 185 (unsigned long long) event->value.download.completed,
186 (unsigned long long) event->value.download.size, 186 (unsigned long long) event->value.download.size,
187 event->value.download.specifics.progress.depth, 187 event->value.download.specifics.progress.depth,
188 (unsigned long long) event->value.download.specifics. 188 (unsigned long long) event->value.download.specifics.progress.
189 progress.offset); 189 offset);
190#endif 190#endif
191 break; 191 break;
192 case GNUNET_FS_STATUS_PUBLISH_ERROR: 192 case GNUNET_FS_STATUS_PUBLISH_ERROR:
193 fprintf (stderr, 193 fprintf (stderr, "Error publishing file: %s\n",
194 "Error publishing file: %s\n",
195 event->value.publish.specifics.error.message); 194 event->value.publish.specifics.error.message);
196 GNUNET_break (0); 195 GNUNET_break (0);
197 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 196 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL,
198 NULL,
199 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 197 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
200 break; 198 break;
201 case GNUNET_FS_STATUS_DOWNLOAD_ERROR: 199 case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
202 fprintf (stderr, 200 fprintf (stderr, "Error downloading file: %s\n",
203 "Error downloading file: %s\n",
204 event->value.download.specifics.error.message); 201 event->value.download.specifics.error.message);
205 GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); 202 GNUNET_SCHEDULER_add_now (&abort_download_task, NULL);
206 break; 203 break;
@@ -231,8 +228,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
231 break; 228 break;
232 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: 229 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
233 GNUNET_assert (download == event->value.download.dc); 230 GNUNET_assert (download == event->value.download.dc);
234 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 231 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL,
235 NULL,
236 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 232 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
237 break; 233 break;
238 default: 234 default:
@@ -248,12 +244,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
248{ 244{
249 p->cfg = GNUNET_CONFIGURATION_create (); 245 p->cfg = GNUNET_CONFIGURATION_create ();
250#if START_ARM 246#if START_ARM
251 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 247 p->arm_proc =
252 "gnunet-service-arm", 248 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
249 "gnunet-service-arm",
253#if VERBOSE 250#if VERBOSE
254 "-L", "DEBUG", 251 "-L", "DEBUG",
255#endif 252#endif
256 "-c", cfgname, NULL); 253 "-c", cfgname, NULL);
257#endif 254#endif
258 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 255 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
259} 256}
@@ -269,8 +266,7 @@ stop_arm (struct PeerContext *p)
269 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 266 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
270 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 267 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
271 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 268 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
273 "ARM process %u stopped\n",
274 GNUNET_OS_process_get_pid (p->arm_proc)); 270 GNUNET_OS_process_get_pid (p->arm_proc));
275 GNUNET_OS_process_close (p->arm_proc); 271 GNUNET_OS_process_close (p->arm_proc);
276 p->arm_proc = NULL; 272 p->arm_proc = NULL;
@@ -281,9 +277,8 @@ stop_arm (struct PeerContext *p)
281 277
282 278
283static void 279static void
284run (void *cls, 280run (void *cls, char *const *args, const char *cfgfile,
285 char *const *args, 281 const struct GNUNET_CONFIGURATION_Handle *cfg)
286 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
287{ 282{
288 const char *keywords[] = { 283 const char *keywords[] = {
289 "down_foo", 284 "down_foo",
@@ -297,10 +292,8 @@ run (void *cls,
297 struct GNUNET_FS_BlockOptions bo; 292 struct GNUNET_FS_BlockOptions bo;
298 293
299 setup_peer (&p1, "test_fs_download_data.conf"); 294 setup_peer (&p1, "test_fs_download_data.conf");
300 fs = GNUNET_FS_start (cfg, 295 fs = GNUNET_FS_start (cfg, "test-fs-download", &progress_cb, NULL,
301 "test-fs-download", 296 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
302 &progress_cb,
303 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
304 GNUNET_assert (NULL != fs); 297 GNUNET_assert (NULL != fs);
305 buf = GNUNET_malloc (FILESIZE); 298 buf = GNUNET_malloc (FILESIZE);
306 for (i = 0; i < FILESIZE; i++) 299 for (i = 0; i < FILESIZE; i++)
@@ -311,21 +304,18 @@ run (void *cls,
311 bo.anonymity_level = 1; 304 bo.anonymity_level = 1;
312 bo.replication_level = 0; 305 bo.replication_level = 0;
313 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 306 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
314 fi = GNUNET_FS_file_information_create_from_data (fs, 307 fi = GNUNET_FS_file_information_create_from_data (fs, "publish-context",
315 "publish-context", 308 FILESIZE, buf, kuri, meta,
316 FILESIZE, 309 GNUNET_NO, &bo);
317 buf,
318 kuri, meta, GNUNET_NO, &bo);
319 GNUNET_FS_uri_destroy (kuri); 310 GNUNET_FS_uri_destroy (kuri);
320 GNUNET_CONTAINER_meta_data_destroy (meta); 311 GNUNET_CONTAINER_meta_data_destroy (meta);
321 GNUNET_assert (NULL != fi); 312 GNUNET_assert (NULL != fi);
322 timeout_kill = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 313 timeout_kill =
323 &timeout_kill_task, NULL); 314 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_kill_task, NULL);
324 start = GNUNET_TIME_absolute_get (); 315 start = GNUNET_TIME_absolute_get ();
325 publish = GNUNET_FS_publish_start (fs, 316 publish =
326 fi, 317 GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL,
327 NULL, NULL, NULL, 318 GNUNET_FS_PUBLISH_OPTION_NONE);
328 GNUNET_FS_PUBLISH_OPTION_NONE);
329 GNUNET_assert (publish != NULL); 319 GNUNET_assert (publish != NULL);
330} 320}
331 321
@@ -353,8 +343,8 @@ main (int argc, char *argv[])
353 "WARNING", 343 "WARNING",
354#endif 344#endif
355 NULL); 345 NULL);
356 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 346 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
357 argvx, "test-fs-download", "nohelp", options, &run, NULL); 347 "test-fs-download", "nohelp", options, &run, NULL);
358 stop_arm (&p1); 348 stop_arm (&p1);
359 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/"); 349 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/");
360 return err; 350 return err;
diff --git a/src/fs/test_fs_download_indexed.c b/src/fs/test_fs_download_indexed.c
index 86933352a..5b1752e63 100644
--- a/src/fs/test_fs_download_indexed.c
+++ b/src/fs/test_fs_download_indexed.c
@@ -141,42 +141,42 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
141 (unsigned long long) event->value.publish.completed, 141 (unsigned long long) event->value.publish.completed,
142 (unsigned long long) event->value.publish.size, 142 (unsigned long long) event->value.publish.size,
143 event->value.publish.specifics.progress.depth, 143 event->value.publish.specifics.progress.depth,
144 (unsigned long long) event->value.publish.specifics. 144 (unsigned long long) event->value.publish.specifics.progress.
145 progress.offset); 145 offset);
146#endif 146#endif
147 break; 147 break;
148 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 148 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
149 printf ("Publishing complete, %llu kbps.\n", 149 printf ("Publishing complete, %llu kbps.\n",
150 (unsigned long long) (FILESIZE * 1000LL / 150 (unsigned long long) (FILESIZE * 1000LL /
151 (1 + 151 (1 +
152 GNUNET_TIME_absolute_get_duration 152 GNUNET_TIME_absolute_get_duration (start).
153 (start).rel_value) / 1024LL)); 153 rel_value) / 1024LL));
154 GAUGER ("FS", "Publishing speed (indexing)", 154 GAUGER ("FS", "Publishing speed (indexing)",
155 (unsigned long long) (FILESIZE * 1000LL / 155 (unsigned long long) (FILESIZE * 1000LL /
156 (1 + 156 (1 +
157 GNUNET_TIME_absolute_get_duration 157 GNUNET_TIME_absolute_get_duration (start).
158 (start).rel_value) / 1024LL), "kb/s"); 158 rel_value) / 1024LL), "kb/s");
159 fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst"); 159 fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst");
160 start = GNUNET_TIME_absolute_get (); 160 start = GNUNET_TIME_absolute_get ();
161 download = GNUNET_FS_download_start (fs, 161 download =
162 event->value.publish. 162 GNUNET_FS_download_start (fs,
163 specifics.completed.chk_uri, NULL, fn, 163 event->value.publish.specifics.completed.
164 NULL, 0, FILESIZE, 1, 164 chk_uri, NULL, fn, NULL, 0, FILESIZE, 1,
165 GNUNET_FS_DOWNLOAD_OPTION_NONE, 165 GNUNET_FS_DOWNLOAD_OPTION_NONE, "download",
166 "download", NULL); 166 NULL);
167 GNUNET_assert (download != NULL); 167 GNUNET_assert (download != NULL);
168 break; 168 break;
169 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: 169 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
170 printf ("Download complete, %llu kbps.\n", 170 printf ("Download complete, %llu kbps.\n",
171 (unsigned long long) (FILESIZE * 1000LL / 171 (unsigned long long) (FILESIZE * 1000LL /
172 (1 + 172 (1 +
173 GNUNET_TIME_absolute_get_duration 173 GNUNET_TIME_absolute_get_duration (start).
174 (start).rel_value) / 1024LL)); 174 rel_value) / 1024LL));
175 GAUGER ("FS", "Local download speed (indexed)", 175 GAUGER ("FS", "Local download speed (indexed)",
176 (unsigned long long) (FILESIZE * 1000LL / 176 (unsigned long long) (FILESIZE * 1000LL /
177 (1 + 177 (1 +
178 GNUNET_TIME_absolute_get_duration 178 GNUNET_TIME_absolute_get_duration (start).
179 (start).rel_value) / 1024LL), "kb/s"); 179 rel_value) / 1024LL), "kb/s");
180 GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); 180 GNUNET_SCHEDULER_add_now (&abort_download_task, NULL);
181 break; 181 break;
182 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: 182 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
@@ -186,22 +186,19 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
186 (unsigned long long) event->value.download.completed, 186 (unsigned long long) event->value.download.completed,
187 (unsigned long long) event->value.download.size, 187 (unsigned long long) event->value.download.size,
188 event->value.download.specifics.progress.depth, 188 event->value.download.specifics.progress.depth,
189 (unsigned long long) event->value.download.specifics. 189 (unsigned long long) event->value.download.specifics.progress.
190 progress.offset); 190 offset);
191#endif 191#endif
192 break; 192 break;
193 case GNUNET_FS_STATUS_PUBLISH_ERROR: 193 case GNUNET_FS_STATUS_PUBLISH_ERROR:
194 fprintf (stderr, 194 fprintf (stderr, "Error publishing file: %s\n",
195 "Error publishing file: %s\n",
196 event->value.publish.specifics.error.message); 195 event->value.publish.specifics.error.message);
197 GNUNET_break (0); 196 GNUNET_break (0);
198 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 197 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL,
199 NULL,
200 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 198 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
201 break; 199 break;
202 case GNUNET_FS_STATUS_DOWNLOAD_ERROR: 200 case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
203 fprintf (stderr, 201 fprintf (stderr, "Error downloading file: %s\n",
204 "Error downloading file: %s\n",
205 event->value.download.specifics.error.message); 202 event->value.download.specifics.error.message);
206 GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); 203 GNUNET_SCHEDULER_add_now (&abort_download_task, NULL);
207 break; 204 break;
@@ -232,8 +229,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
232 break; 229 break;
233 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: 230 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
234 GNUNET_assert (download == event->value.download.dc); 231 GNUNET_assert (download == event->value.download.dc);
235 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 232 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL,
236 NULL,
237 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 233 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
238 break; 234 break;
239 default: 235 default:
@@ -249,12 +245,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
249{ 245{
250 p->cfg = GNUNET_CONFIGURATION_create (); 246 p->cfg = GNUNET_CONFIGURATION_create ();
251#if START_ARM 247#if START_ARM
252 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 248 p->arm_proc =
253 "gnunet-service-arm", 249 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
250 "gnunet-service-arm",
254#if VERBOSE 251#if VERBOSE
255 "-L", "DEBUG", 252 "-L", "DEBUG",
256#endif 253#endif
257 "-c", cfgname, NULL); 254 "-c", cfgname, NULL);
258#endif 255#endif
259 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 256 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
260} 257}
@@ -270,8 +267,7 @@ stop_arm (struct PeerContext *p)
270 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 267 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
271 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 268 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
272 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 269 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
274 "ARM process %u stopped\n",
275 GNUNET_OS_process_get_pid (p->arm_proc)); 271 GNUNET_OS_process_get_pid (p->arm_proc));
276 GNUNET_OS_process_close (p->arm_proc); 272 GNUNET_OS_process_close (p->arm_proc);
277 p->arm_proc = NULL; 273 p->arm_proc = NULL;
@@ -282,9 +278,8 @@ stop_arm (struct PeerContext *p)
282 278
283 279
284static void 280static void
285run (void *cls, 281run (void *cls, char *const *args, const char *cfgfile,
286 char *const *args, 282 const struct GNUNET_CONFIGURATION_Handle *cfg)
287 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
288{ 283{
289 const char *keywords[] = { 284 const char *keywords[] = {
290 "down_foo", 285 "down_foo",
@@ -298,10 +293,8 @@ run (void *cls,
298 size_t i; 293 size_t i;
299 294
300 setup_peer (&p1, "test_fs_download_data.conf"); 295 setup_peer (&p1, "test_fs_download_data.conf");
301 fs = GNUNET_FS_start (cfg, 296 fs = GNUNET_FS_start (cfg, "test-fs-download-indexed", &progress_cb, NULL,
302 "test-fs-download-indexed", 297 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
303 &progress_cb,
304 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
305 GNUNET_assert (NULL != fs); 298 GNUNET_assert (NULL != fs);
306 299
307 fn1 = GNUNET_DISK_mktemp ("gnunet-download-indexed-test"); 300 fn1 = GNUNET_DISK_mktemp ("gnunet-download-indexed-test");
@@ -309,9 +302,7 @@ run (void *cls,
309 for (i = 0; i < FILESIZE; i++) 302 for (i = 0; i < FILESIZE; i++)
310 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 303 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
311 GNUNET_assert (FILESIZE == 304 GNUNET_assert (FILESIZE ==
312 GNUNET_DISK_fn_write (fn1, 305 GNUNET_DISK_fn_write (fn1, buf, FILESIZE,
313 buf,
314 FILESIZE,
315 GNUNET_DISK_PERM_USER_READ | 306 GNUNET_DISK_PERM_USER_READ |
316 GNUNET_DISK_PERM_USER_WRITE)); 307 GNUNET_DISK_PERM_USER_WRITE));
317 GNUNET_free (buf); 308 GNUNET_free (buf);
@@ -321,21 +312,18 @@ run (void *cls,
321 bo.anonymity_level = 1; 312 bo.anonymity_level = 1;
322 bo.replication_level = 0; 313 bo.replication_level = 0;
323 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 314 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
324 fi = GNUNET_FS_file_information_create_from_file (fs, 315 fi = GNUNET_FS_file_information_create_from_file (fs, "publish-context", fn1,
325 "publish-context", 316 kuri, meta, GNUNET_YES,
326 fn1, 317 &bo);
327 kuri,
328 meta, GNUNET_YES, &bo);
329 GNUNET_FS_uri_destroy (kuri); 318 GNUNET_FS_uri_destroy (kuri);
330 GNUNET_CONTAINER_meta_data_destroy (meta); 319 GNUNET_CONTAINER_meta_data_destroy (meta);
331 GNUNET_assert (NULL != fi); 320 GNUNET_assert (NULL != fi);
332 timeout_kill = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 321 timeout_kill =
333 &timeout_kill_task, NULL); 322 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_kill_task, NULL);
334 start = GNUNET_TIME_absolute_get (); 323 start = GNUNET_TIME_absolute_get ();
335 publish = GNUNET_FS_publish_start (fs, 324 publish =
336 fi, 325 GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL,
337 NULL, NULL, NULL, 326 GNUNET_FS_PUBLISH_OPTION_NONE);
338 GNUNET_FS_PUBLISH_OPTION_NONE);
339 GNUNET_assert (publish != NULL); 327 GNUNET_assert (publish != NULL);
340} 328}
341 329
@@ -363,9 +351,9 @@ main (int argc, char *argv[])
363 "WARNING", 351 "WARNING",
364#endif 352#endif
365 NULL); 353 NULL);
366 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 354 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
367 argvx, "test-fs-download-indexed", 355 "test-fs-download-indexed", "nohelp", options, &run,
368 "nohelp", options, &run, NULL); 356 NULL);
369 stop_arm (&p1); 357 stop_arm (&p1);
370 if (fn1 != NULL) 358 if (fn1 != NULL)
371 { 359 {
diff --git a/src/fs/test_fs_download_persistence.c b/src/fs/test_fs_download_persistence.c
index d484f9587..5b2a53f80 100644
--- a/src/fs/test_fs_download_persistence.c
+++ b/src/fs/test_fs_download_persistence.c
@@ -132,10 +132,7 @@ restart_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
132{ 132{
133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Restarting FS.\n"); 133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Restarting FS.\n");
134 GNUNET_FS_stop (fs); 134 GNUNET_FS_stop (fs);
135 fs = GNUNET_FS_start (cfg, 135 fs = GNUNET_FS_start (cfg, "test-fs-download-persistence", &progress_cb, NULL,
136 "test-fs-download-persistence",
137 &progress_cb,
138 NULL,
139 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); 136 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
140} 137}
141 138
@@ -174,26 +171,22 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
174 (unsigned long long) event->value.publish.completed, 171 (unsigned long long) event->value.publish.completed,
175 (unsigned long long) event->value.publish.size, 172 (unsigned long long) event->value.publish.size,
176 event->value.publish.specifics.progress.depth, 173 event->value.publish.specifics.progress.depth,
177 (unsigned long long) event->value.publish.specifics. 174 (unsigned long long) event->value.publish.specifics.progress.
178 progress.offset); 175 offset);
179#endif 176#endif
180 break; 177 break;
181 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 178 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
182 printf ("Publishing complete, %llu kbps.\n", 179 printf ("Publishing complete, %llu kbps.\n",
183 (unsigned long long) (FILESIZE * 1000LL / 180 (unsigned long long) (FILESIZE * 1000LL /
184 (1 + 181 (1 +
185 GNUNET_TIME_absolute_get_duration 182 GNUNET_TIME_absolute_get_duration (start).
186 (start).rel_value) / 1024LL)); 183 rel_value) / 1024LL));
187 fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst"); 184 fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst");
188 start = GNUNET_TIME_absolute_get (); 185 start = GNUNET_TIME_absolute_get ();
189 GNUNET_assert (download == NULL); 186 GNUNET_assert (download == NULL);
190 GNUNET_FS_download_start (fs, 187 GNUNET_FS_download_start (fs,
191 event->value.publish.specifics.completed.chk_uri, 188 event->value.publish.specifics.completed.chk_uri,
192 NULL, 189 NULL, fn, NULL, 0, FILESIZE, 1,
193 fn, NULL,
194 0,
195 FILESIZE,
196 1,
197 GNUNET_FS_DOWNLOAD_OPTION_NONE, "download", NULL); 190 GNUNET_FS_DOWNLOAD_OPTION_NONE, "download", NULL);
198 break; 191 break;
199 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: 192 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
@@ -201,8 +194,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
201 printf ("Download complete, %llu kbps.\n", 194 printf ("Download complete, %llu kbps.\n",
202 (unsigned long long) (FILESIZE * 1000LL / 195 (unsigned long long) (FILESIZE * 1000LL /
203 (1 + 196 (1 +
204 GNUNET_TIME_absolute_get_duration 197 GNUNET_TIME_absolute_get_duration (start).
205 (start).rel_value) / 1024LL)); 198 rel_value) / 1024LL));
206 GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); 199 GNUNET_SCHEDULER_add_now (&abort_download_task, NULL);
207 break; 200 break;
208 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: 201 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
@@ -213,22 +206,19 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
213 (unsigned long long) event->value.download.completed, 206 (unsigned long long) event->value.download.completed,
214 (unsigned long long) event->value.download.size, 207 (unsigned long long) event->value.download.size,
215 event->value.download.specifics.progress.depth, 208 event->value.download.specifics.progress.depth,
216 (unsigned long long) event->value.download.specifics. 209 (unsigned long long) event->value.download.specifics.progress.
217 progress.offset); 210 offset);
218#endif 211#endif
219 break; 212 break;
220 case GNUNET_FS_STATUS_PUBLISH_ERROR: 213 case GNUNET_FS_STATUS_PUBLISH_ERROR:
221 fprintf (stderr, 214 fprintf (stderr, "Error publishing file: %s\n",
222 "Error publishing file: %s\n",
223 event->value.publish.specifics.error.message); 215 event->value.publish.specifics.error.message);
224 GNUNET_break (0); 216 GNUNET_break (0);
225 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 217 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL,
226 NULL,
227 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 218 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
228 break; 219 break;
229 case GNUNET_FS_STATUS_DOWNLOAD_ERROR: 220 case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
230 fprintf (stderr, 221 fprintf (stderr, "Error downloading file: %s\n",
231 "Error downloading file: %s\n",
232 event->value.download.specifics.error.message); 222 event->value.download.specifics.error.message);
233 GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); 223 GNUNET_SCHEDULER_add_now (&abort_download_task, NULL);
234 break; 224 break;
@@ -287,8 +277,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
287 break; 277 break;
288 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: 278 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
289 GNUNET_assert (download == event->value.download.dc); 279 GNUNET_assert (download == event->value.download.dc);
290 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 280 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL,
291 NULL,
292 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 281 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
293 download = NULL; 282 download = NULL;
294 break; 283 break;
@@ -305,12 +294,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
305{ 294{
306 p->cfg = GNUNET_CONFIGURATION_create (); 295 p->cfg = GNUNET_CONFIGURATION_create ();
307#if START_ARM 296#if START_ARM
308 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 297 p->arm_proc =
309 "gnunet-service-arm", 298 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
299 "gnunet-service-arm",
310#if VERBOSE 300#if VERBOSE
311 "-L", "DEBUG", 301 "-L", "DEBUG",
312#endif 302#endif
313 "-c", cfgname, NULL); 303 "-c", cfgname, NULL);
314#endif 304#endif
315 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 305 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
316} 306}
@@ -326,8 +316,7 @@ stop_arm (struct PeerContext *p)
326 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 316 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
327 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 317 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
328 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 318 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
329 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 319 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
330 "ARM process %u stopped\n",
331 GNUNET_OS_process_get_pid (p->arm_proc)); 320 GNUNET_OS_process_get_pid (p->arm_proc));
332 GNUNET_OS_process_close (p->arm_proc); 321 GNUNET_OS_process_close (p->arm_proc);
333 p->arm_proc = NULL; 322 p->arm_proc = NULL;
@@ -338,9 +327,8 @@ stop_arm (struct PeerContext *p)
338 327
339 328
340static void 329static void
341run (void *cls, 330run (void *cls, char *const *args, const char *cfgfile,
342 char *const *args, 331 const struct GNUNET_CONFIGURATION_Handle *c)
343 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
344{ 332{
345 const char *keywords[] = { 333 const char *keywords[] = {
346 "down_foo", 334 "down_foo",
@@ -355,10 +343,7 @@ run (void *cls,
355 343
356 cfg = c; 344 cfg = c;
357 setup_peer (&p1, "test_fs_download_data.conf"); 345 setup_peer (&p1, "test_fs_download_data.conf");
358 fs = GNUNET_FS_start (cfg, 346 fs = GNUNET_FS_start (cfg, "test-fs-download-persistence", &progress_cb, NULL,
359 "test-fs-download-persistence",
360 &progress_cb,
361 NULL,
362 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); 347 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
363 GNUNET_assert (NULL != fs); 348 GNUNET_assert (NULL != fs);
364 buf = GNUNET_malloc (FILESIZE); 349 buf = GNUNET_malloc (FILESIZE);
@@ -370,21 +355,18 @@ run (void *cls,
370 bo.anonymity_level = 1; 355 bo.anonymity_level = 1;
371 bo.replication_level = 0; 356 bo.replication_level = 0;
372 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 357 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
373 fi = GNUNET_FS_file_information_create_from_data (fs, 358 fi = GNUNET_FS_file_information_create_from_data (fs, "publish-context",
374 "publish-context", 359 FILESIZE, buf, kuri, meta,
375 FILESIZE, 360 GNUNET_NO, &bo);
376 buf,
377 kuri, meta, GNUNET_NO, &bo);
378 GNUNET_FS_uri_destroy (kuri); 361 GNUNET_FS_uri_destroy (kuri);
379 GNUNET_CONTAINER_meta_data_destroy (meta); 362 GNUNET_CONTAINER_meta_data_destroy (meta);
380 GNUNET_assert (NULL != fi); 363 GNUNET_assert (NULL != fi);
381 timeout_kill = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 364 timeout_kill =
382 &timeout_kill_task, NULL); 365 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_kill_task, NULL);
383 start = GNUNET_TIME_absolute_get (); 366 start = GNUNET_TIME_absolute_get ();
384 publish = GNUNET_FS_publish_start (fs, 367 publish =
385 fi, 368 GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL,
386 NULL, NULL, NULL, 369 GNUNET_FS_PUBLISH_OPTION_NONE);
387 GNUNET_FS_PUBLISH_OPTION_NONE);
388 GNUNET_assert (publish != NULL); 370 GNUNET_assert (publish != NULL);
389} 371}
390 372
@@ -412,9 +394,9 @@ main (int argc, char *argv[])
412#endif 394#endif
413 NULL); 395 NULL);
414 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/"); 396 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/");
415 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 397 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
416 argvx, "test-fs-download-persistence", 398 "test-fs-download-persistence", "nohelp", options, &run,
417 "nohelp", options, &run, NULL); 399 NULL);
418 stop_arm (&p1); 400 stop_arm (&p1);
419 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/"); 401 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/");
420 return err; 402 return err;
diff --git a/src/fs/test_fs_download_recursive.c b/src/fs/test_fs_download_recursive.c
index c3e0ea440..d350dcae8 100644
--- a/src/fs/test_fs_download_recursive.c
+++ b/src/fs/test_fs_download_recursive.c
@@ -50,9 +50,9 @@ makeName (unsigned int i)
50 ("/tmp/gnunet-fsui-recursive_download_test/FSUITEST") + 50 ("/tmp/gnunet-fsui-recursive_download_test/FSUITEST") +
51 15); 51 15);
52 GNUNET_snprintf (fn, 52 GNUNET_snprintf (fn,
53 strlen 53 strlen ("/tmp/gnunet-fsui-recursive_download_test/FSUITEST")
54 ("/tmp/gnunet-fsui-recursive_download_test/FSUITEST") + 15, 54 + 15, "/tmp/gnunet-fsui-recursive_download_test/FSUITEST%u/",
55 "/tmp/gnunet-fsui-recursive_download_test/FSUITEST%u/", i); 55 i);
56 return fn; 56 return fn;
57} 57}
58 58
@@ -142,8 +142,9 @@ checkHierarchy (unsigned int i, const char *tree)
142 GNUNET_free (fn); 142 GNUNET_free (fn);
143 return GNUNET_SYSERR; 143 return GNUNET_SYSERR;
144 } 144 }
145 res = ((makeHierarchyHelper (fn, tree, 0, 1) == -1) ? 145 res =
146 GNUNET_SYSERR : GNUNET_OK); 146 ((makeHierarchyHelper (fn, tree, 0, 1) ==
147 -1) ? GNUNET_SYSERR : GNUNET_OK);
147 GNUNET_free (fn); 148 GNUNET_free (fn);
148 return res; 149 return res;
149} 150}
@@ -287,9 +288,9 @@ main (int argc, char *argv[])
287 GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to start */ 288 GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to start */
288 /* ACTUAL TEST CODE */ 289 /* ACTUAL TEST CODE */
289#endif 290#endif
290 ctx = GNUNET_FSUI_start (NULL, 291 ctx =
291 cfg, "fsuirecursive_download_test", 32, GNUNET_YES, 292 GNUNET_FSUI_start (NULL, cfg, "fsuirecursive_download_test", 32,
292 &eventCallback, NULL); 293 GNUNET_YES, &eventCallback, NULL);
293 CHECK (ctx != NULL); 294 CHECK (ctx != NULL);
294 fn = makeHierarchy (42, DIRECTORY_TREE_SPEC); 295 fn = makeHierarchy (42, DIRECTORY_TREE_SPEC);
295 meta = GNUNET_meta_data_create (); 296 meta = GNUNET_meta_data_create ();
@@ -298,13 +299,13 @@ main (int argc, char *argv[])
298 (const char **) keywords); 299 (const char **) keywords);
299 fprintf (stderr, "Uploading...\n"); 300 fprintf (stderr, "Uploading...\n");
300 waitForEvent = GNUNET_FSUI_upload_completed; 301 waitForEvent = GNUNET_FSUI_upload_completed;
301 upload = GNUNET_FSUI_upload_start (ctx, 302 upload =
302 fn, 303 GNUNET_FSUI_upload_start (ctx, fn,
303 (GNUNET_FSUI_DirectoryScanCallback) & 304 (GNUNET_FSUI_DirectoryScanCallback) &
304 GNUNET_disk_directory_scan, NULL, 0, 0, 305 GNUNET_disk_directory_scan, NULL, 0, 0,
305 GNUNET_YES, GNUNET_NO, GNUNET_NO, 306 GNUNET_YES, GNUNET_NO, GNUNET_NO,
306 GNUNET_get_time () + 307 GNUNET_get_time () + 5 * GNUNET_CRON_HOURS,
307 5 * GNUNET_CRON_HOURS, meta, kuri, kuri); 308 meta, kuri, kuri);
308 CHECK (upload != NULL); 309 CHECK (upload != NULL);
309 GNUNET_ECRS_uri_destroy (kuri); 310 GNUNET_ECRS_uri_destroy (kuri);
310 kuri = NULL; 311 kuri = NULL;
@@ -324,10 +325,9 @@ main (int argc, char *argv[])
324 fprintf (stderr, "Downloading...\n"); 325 fprintf (stderr, "Downloading...\n");
325 waitForEvent = GNUNET_FSUI_download_completed; 326 waitForEvent = GNUNET_FSUI_download_completed;
326 fn43 = makeName (43); 327 fn43 = makeName (43);
327 download = GNUNET_FSUI_download_start (ctx, 328 download =
328 0, 329 GNUNET_FSUI_download_start (ctx, 0, GNUNET_YES, upURI, meta, fn43, NULL,
329 GNUNET_YES, 330 NULL);
330 upURI, meta, fn43, NULL, NULL);
331 CHECK (download != NULL); 331 CHECK (download != NULL);
332 GNUNET_free (fn43); 332 GNUNET_free (fn43);
333 fn43 = NULL; 333 fn43 = NULL;
diff --git a/src/fs/test_fs_file_information.c b/src/fs/test_fs_file_information.c
index 97a63062e..db5a8448a 100644
--- a/src/fs/test_fs_file_information.c
+++ b/src/fs/test_fs_file_information.c
@@ -50,11 +50,8 @@
50 50
51 51
52static int 52static int
53mycleaner (void *cls, 53mycleaner (void *cls, struct GNUNET_FS_FileInformation *fi, uint64_t length,
54 struct GNUNET_FS_FileInformation *fi, 54 struct GNUNET_CONTAINER_MetaData *meta, struct GNUNET_FS_Uri **uri,
55 uint64_t length,
56 struct GNUNET_CONTAINER_MetaData *meta,
57 struct GNUNET_FS_Uri **uri,
58 struct GNUNET_FS_BlockOptions *bo, int *do_index, void **client_info) 55 struct GNUNET_FS_BlockOptions *bo, int *do_index, void **client_info)
59{ 56{
60 return GNUNET_OK; 57 return GNUNET_OK;
@@ -62,9 +59,8 @@ mycleaner (void *cls,
62 59
63 60
64static void 61static void
65run (void *cls, 62run (void *cls, char *const *args, const char *cfgfile,
66 char *const *args, 63 const struct GNUNET_CONFIGURATION_Handle *cfg)
67 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
68{ 64{
69 const char *keywords[] = { 65 const char *keywords[] = {
70 "down_foo", 66 "down_foo",
@@ -89,9 +85,7 @@ run (void *cls,
89 for (i = 0; i < FILESIZE; i++) 85 for (i = 0; i < FILESIZE; i++)
90 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 86 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
91 GNUNET_assert (FILESIZE == 87 GNUNET_assert (FILESIZE ==
92 GNUNET_DISK_fn_write (fn1, 88 GNUNET_DISK_fn_write (fn1, buf, FILESIZE,
93 buf,
94 FILESIZE,
95 GNUNET_DISK_PERM_USER_READ | 89 GNUNET_DISK_PERM_USER_READ |
96 GNUNET_DISK_PERM_USER_WRITE)); 90 GNUNET_DISK_PERM_USER_WRITE));
97 GNUNET_free (buf); 91 GNUNET_free (buf);
@@ -101,9 +95,7 @@ run (void *cls,
101 for (i = 0; i < FILESIZE; i++) 95 for (i = 0; i < FILESIZE; i++)
102 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 96 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
103 GNUNET_assert (FILESIZE == 97 GNUNET_assert (FILESIZE ==
104 GNUNET_DISK_fn_write (fn2, 98 GNUNET_DISK_fn_write (fn2, buf, FILESIZE,
105 buf,
106 FILESIZE,
107 GNUNET_DISK_PERM_USER_READ | 99 GNUNET_DISK_PERM_USER_READ |
108 GNUNET_DISK_PERM_USER_WRITE)); 100 GNUNET_DISK_PERM_USER_WRITE));
109 GNUNET_free (buf); 101 GNUNET_free (buf);
@@ -114,21 +106,22 @@ run (void *cls,
114 bo.anonymity_level = 1; 106 bo.anonymity_level = 1;
115 bo.replication_level = 0; 107 bo.replication_level = 0;
116 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 108 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
117 fi1 = GNUNET_FS_file_information_create_from_file (fs, 109 fi1 =
118 "file_information-context1", 110 GNUNET_FS_file_information_create_from_file (fs,
119 fn1, 111 "file_information-context1",
120 kuri, 112 fn1, kuri, meta, GNUNET_YES,
121 meta, GNUNET_YES, &bo); 113 &bo);
122 GNUNET_assert (fi1 != NULL); 114 GNUNET_assert (fi1 != NULL);
123 fi2 = GNUNET_FS_file_information_create_from_file (fs, 115 fi2 =
124 "file_information-context2", 116 GNUNET_FS_file_information_create_from_file (fs,
125 fn2, 117 "file_information-context2",
126 kuri, 118 fn2, kuri, meta, GNUNET_YES,
127 meta, GNUNET_YES, &bo); 119 &bo);
128 GNUNET_assert (fi2 != NULL); 120 GNUNET_assert (fi2 != NULL);
129 fidir = GNUNET_FS_file_information_create_empty_directory (fs, 121 fidir =
130 "file_information-context-dir", 122 GNUNET_FS_file_information_create_empty_directory (fs,
131 kuri, meta, &bo); 123 "file_information-context-dir",
124 kuri, meta, &bo);
132 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); 125 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
133 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); 126 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
134 GNUNET_FS_uri_destroy (kuri); 127 GNUNET_FS_uri_destroy (kuri);
@@ -165,9 +158,10 @@ testThumbnail ()
165 ex = EXTRACTOR_plugin_add_config (ex, "mime", 158 ex = EXTRACTOR_plugin_add_config (ex, "mime",
166 EXTRACTOR_OPTION_DEFAULT_POLICY); 159 EXTRACTOR_OPTION_DEFAULT_POLICY);
167 m = GNUNET_CONTAINER_meta_data_create (); 160 m = GNUNET_CONTAINER_meta_data_create ();
168 if (3 != GNUNET_FS_meta_data_extract_from_file (m, 161 if (3 !=
169 "test_fs_file_information_meta_data_image.jpg", 162 GNUNET_FS_meta_data_extract_from_file (m,
170 ex)) 163 "test_fs_file_information_meta_data_image.jpg",
164 ex))
171 { 165 {
172 GNUNET_break (0); 166 GNUNET_break (0);
173 EXTRACTOR_plugin_remove_all (ex); 167 EXTRACTOR_plugin_remove_all (ex);
@@ -187,8 +181,9 @@ testThumbnail ()
187 } 181 }
188 GNUNET_free (thumb); 182 GNUNET_free (thumb);
189 GNUNET_CONTAINER_meta_data_add_publication_date (d); 183 GNUNET_CONTAINER_meta_data_add_publication_date (d);
190 date = GNUNET_CONTAINER_meta_data_get_by_type (d, 184 date =
191 EXTRACTOR_METATYPE_PUBLICATION_DATE); 185 GNUNET_CONTAINER_meta_data_get_by_type (d,
186 EXTRACTOR_METATYPE_PUBLICATION_DATE);
192 if (date == NULL) 187 if (date == NULL)
193 { 188 {
194 GNUNET_break (0); 189 GNUNET_break (0);
@@ -227,9 +222,9 @@ main (int argc, char *argv[])
227 NULL); 222 NULL);
228 if (0 != testThumbnail ()) 223 if (0 != testThumbnail ())
229 return 1; 224 return 1;
230 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 225 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
231 argvx, "test-fs-file_information", 226 "test-fs-file_information", "nohelp", options, &run,
232 "nohelp", options, &run, NULL); 227 NULL);
233 return 0; 228 return 0;
234} 229}
235 230
diff --git a/src/fs/test_fs_list_indexed.c b/src/fs/test_fs_list_indexed.c
index e3330f3ba..87afa12e1 100644
--- a/src/fs/test_fs_list_indexed.c
+++ b/src/fs/test_fs_list_indexed.c
@@ -92,8 +92,8 @@ static void
92list_indexed_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 92list_indexed_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
93{ 93{
94 94
95 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 95 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL,
96 NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 96 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
97} 97}
98 98
99 99
@@ -110,11 +110,10 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
110 printf ("Publish complete, %llu kbps.\n", 110 printf ("Publish complete, %llu kbps.\n",
111 (unsigned long long) (FILESIZE * 1000 / 111 (unsigned long long) (FILESIZE * 1000 /
112 (1 + 112 (1 +
113 GNUNET_TIME_absolute_get_duration 113 GNUNET_TIME_absolute_get_duration (start).
114 (start).rel_value) / 1024)); 114 rel_value) / 1024));
115 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx)) 115 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx))
116 GNUNET_SCHEDULER_add_continuation (&list_indexed_task, 116 GNUNET_SCHEDULER_add_continuation (&list_indexed_task, NULL,
117 NULL,
118 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 117 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
119 118
120 break; 119 break;
@@ -126,41 +125,41 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
126 (unsigned long long) event->value.publish.completed, 125 (unsigned long long) event->value.publish.completed,
127 (unsigned long long) event->value.publish.size, 126 (unsigned long long) event->value.publish.size,
128 event->value.publish.specifics.progress.depth, 127 event->value.publish.specifics.progress.depth,
129 (unsigned long long) event->value.publish.specifics. 128 (unsigned long long) event->value.publish.specifics.progress.
130 progress.offset); 129 offset);
131#endif 130#endif
132 break; 131 break;
133 case GNUNET_FS_STATUS_PUBLISH_ERROR: 132 case GNUNET_FS_STATUS_PUBLISH_ERROR:
134 ret = event->value.publish.cctx; 133 ret = event->value.publish.cctx;
135 fprintf (stderr, 134 fprintf (stderr, "Error publishing file: %s\n",
136 "Error publishing file: %s\n",
137 event->value.publish.specifics.error.message); 135 event->value.publish.specifics.error.message);
138 err = 1; 136 err = 1;
139 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx)) 137 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx))
140 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 138 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL,
141 NULL,
142 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 139 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
143 break; 140 break;
144 case GNUNET_FS_STATUS_PUBLISH_START: 141 case GNUNET_FS_STATUS_PUBLISH_START:
145 ret = event->value.publish.cctx; 142 ret = event->value.publish.cctx;
146 if (0 == strcmp ("list_indexed-context1", event->value.publish.cctx)) 143 if (0 == strcmp ("list_indexed-context1", event->value.publish.cctx))
147 { 144 {
148 GNUNET_assert (0 == strcmp ("list_indexed-context-dir", 145 GNUNET_assert (0 ==
149 event->value.publish.pctx)); 146 strcmp ("list_indexed-context-dir",
147 event->value.publish.pctx));
150 GNUNET_assert (FILESIZE == event->value.publish.size); 148 GNUNET_assert (FILESIZE == event->value.publish.size);
151 GNUNET_assert (0 == event->value.publish.completed); 149 GNUNET_assert (0 == event->value.publish.completed);
152 GNUNET_assert (1 == event->value.publish.anonymity); 150 GNUNET_assert (1 == event->value.publish.anonymity);
153 } 151 }
154 else if (0 == strcmp ("list_indexed-context2", event->value.publish.cctx)) 152 else if (0 == strcmp ("list_indexed-context2", event->value.publish.cctx))
155 { 153 {
156 GNUNET_assert (0 == strcmp ("list_indexed-context-dir", 154 GNUNET_assert (0 ==
157 event->value.publish.pctx)); 155 strcmp ("list_indexed-context-dir",
156 event->value.publish.pctx));
158 GNUNET_assert (FILESIZE == event->value.publish.size); 157 GNUNET_assert (FILESIZE == event->value.publish.size);
159 GNUNET_assert (0 == event->value.publish.completed); 158 GNUNET_assert (0 == event->value.publish.completed);
160 GNUNET_assert (2 == event->value.publish.anonymity); 159 GNUNET_assert (2 == event->value.publish.anonymity);
161 } 160 }
162 else if (0 == strcmp ("list_indexed-context-dir", 161 else if (0 ==
163 event->value.publish.cctx)) 162 strcmp ("list_indexed-context-dir", event->value.publish.cctx))
164 { 163 {
165 GNUNET_assert (0 == event->value.publish.completed); 164 GNUNET_assert (0 == event->value.publish.completed);
166 GNUNET_assert (3 == event->value.publish.anonymity); 165 GNUNET_assert (3 == event->value.publish.anonymity);
@@ -188,12 +187,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
188{ 187{
189 p->cfg = GNUNET_CONFIGURATION_create (); 188 p->cfg = GNUNET_CONFIGURATION_create ();
190#if START_ARM 189#if START_ARM
191 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 190 p->arm_proc =
192 "gnunet-service-arm", 191 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
192 "gnunet-service-arm",
193#if VERBOSE 193#if VERBOSE
194 "-L", "DEBUG", 194 "-L", "DEBUG",
195#endif 195#endif
196 "-c", cfgname, NULL); 196 "-c", cfgname, NULL);
197#endif 197#endif
198 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 198 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
199} 199}
@@ -209,8 +209,7 @@ stop_arm (struct PeerContext *p)
209 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 209 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
210 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 210 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
211 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 211 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
213 "ARM process %u stopped\n",
214 GNUNET_OS_process_get_pid (p->arm_proc)); 213 GNUNET_OS_process_get_pid (p->arm_proc));
215 GNUNET_OS_process_close (p->arm_proc); 214 GNUNET_OS_process_close (p->arm_proc);
216 p->arm_proc = NULL; 215 p->arm_proc = NULL;
@@ -221,9 +220,8 @@ stop_arm (struct PeerContext *p)
221 220
222 221
223static void 222static void
224run (void *cls, 223run (void *cls, char *const *args, const char *cfgfile,
225 char *const *args, 224 const struct GNUNET_CONFIGURATION_Handle *cfg)
226 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
227{ 225{
228 const char *keywords[] = { 226 const char *keywords[] = {
229 "down_foo", 227 "down_foo",
@@ -239,19 +237,15 @@ run (void *cls,
239 struct GNUNET_FS_BlockOptions bo; 237 struct GNUNET_FS_BlockOptions bo;
240 238
241 setup_peer (&p1, "test_fs_list_indexed_data.conf"); 239 setup_peer (&p1, "test_fs_list_indexed_data.conf");
242 fs = GNUNET_FS_start (cfg, 240 fs = GNUNET_FS_start (cfg, "test-fs-list_indexed", &progress_cb, NULL,
243 "test-fs-list_indexed", 241 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
244 &progress_cb,
245 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
246 GNUNET_assert (NULL != fs); 242 GNUNET_assert (NULL != fs);
247 fn1 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst"); 243 fn1 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst");
248 buf = GNUNET_malloc (FILESIZE); 244 buf = GNUNET_malloc (FILESIZE);
249 for (i = 0; i < FILESIZE; i++) 245 for (i = 0; i < FILESIZE; i++)
250 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 246 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
251 GNUNET_assert (FILESIZE == 247 GNUNET_assert (FILESIZE ==
252 GNUNET_DISK_fn_write (fn1, 248 GNUNET_DISK_fn_write (fn1, buf, FILESIZE,
253 buf,
254 FILESIZE,
255 GNUNET_DISK_PERM_USER_READ | 249 GNUNET_DISK_PERM_USER_READ |
256 GNUNET_DISK_PERM_USER_WRITE)); 250 GNUNET_DISK_PERM_USER_WRITE));
257 GNUNET_free (buf); 251 GNUNET_free (buf);
@@ -261,9 +255,7 @@ run (void *cls,
261 for (i = 0; i < FILESIZE; i++) 255 for (i = 0; i < FILESIZE; i++)
262 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 256 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
263 GNUNET_assert (FILESIZE == 257 GNUNET_assert (FILESIZE ==
264 GNUNET_DISK_fn_write (fn2, 258 GNUNET_DISK_fn_write (fn2, buf, FILESIZE,
265 buf,
266 FILESIZE,
267 GNUNET_DISK_PERM_USER_READ | 259 GNUNET_DISK_PERM_USER_READ |
268 GNUNET_DISK_PERM_USER_WRITE)); 260 GNUNET_DISK_PERM_USER_WRITE));
269 GNUNET_free (buf); 261 GNUNET_free (buf);
@@ -274,33 +266,31 @@ run (void *cls,
274 bo.anonymity_level = 1; 266 bo.anonymity_level = 1;
275 bo.replication_level = 0; 267 bo.replication_level = 0;
276 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 268 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
277 fi1 = GNUNET_FS_file_information_create_from_file (fs, 269 fi1 =
278 "list_indexed-context1", 270 GNUNET_FS_file_information_create_from_file (fs, "list_indexed-context1",
279 fn1, 271 fn1, kuri, meta, GNUNET_YES,
280 kuri, 272 &bo);
281 meta, GNUNET_YES, &bo);
282 GNUNET_assert (NULL != fi1); 273 GNUNET_assert (NULL != fi1);
283 bo.anonymity_level = 2; 274 bo.anonymity_level = 2;
284 fi2 = GNUNET_FS_file_information_create_from_file (fs, 275 fi2 =
285 "list_indexed-context2", 276 GNUNET_FS_file_information_create_from_file (fs, "list_indexed-context2",
286 fn2, 277 fn2, kuri, meta, GNUNET_YES,
287 kuri, 278 &bo);
288 meta, GNUNET_YES, &bo);
289 GNUNET_assert (NULL != fi2); 279 GNUNET_assert (NULL != fi2);
290 bo.anonymity_level = 3; 280 bo.anonymity_level = 3;
291 fidir = GNUNET_FS_file_information_create_empty_directory (fs, 281 fidir =
292 "list_indexed-context-dir", 282 GNUNET_FS_file_information_create_empty_directory (fs,
293 kuri, meta, &bo); 283 "list_indexed-context-dir",
284 kuri, meta, &bo);
294 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); 285 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
295 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); 286 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
296 GNUNET_FS_uri_destroy (kuri); 287 GNUNET_FS_uri_destroy (kuri);
297 GNUNET_CONTAINER_meta_data_destroy (meta); 288 GNUNET_CONTAINER_meta_data_destroy (meta);
298 GNUNET_assert (NULL != fidir); 289 GNUNET_assert (NULL != fidir);
299 start = GNUNET_TIME_absolute_get (); 290 start = GNUNET_TIME_absolute_get ();
300 publish = GNUNET_FS_publish_start (fs, 291 publish =
301 fidir, 292 GNUNET_FS_publish_start (fs, fidir, NULL, NULL, NULL,
302 NULL, NULL, NULL, 293 GNUNET_FS_PUBLISH_OPTION_NONE);
303 GNUNET_FS_PUBLISH_OPTION_NONE);
304 GNUNET_assert (publish != NULL); 294 GNUNET_assert (publish != NULL);
305} 295}
306 296
@@ -328,9 +318,8 @@ main (int argc, char *argv[])
328 "WARNING", 318 "WARNING",
329#endif 319#endif
330 NULL); 320 NULL);
331 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 321 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
332 argvx, "test-fs-list_indexed", 322 "test-fs-list_indexed", "nohelp", options, &run, NULL);
333 "nohelp", options, &run, NULL);
334 stop_arm (&p1); 323 stop_arm (&p1);
335 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-list-indexed/"); 324 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-list-indexed/");
336 if (fn1 != NULL) 325 if (fn1 != NULL)
diff --git a/src/fs/test_fs_namespace.c b/src/fs/test_fs_namespace.c
index 96caa8dfa..ae2f77806 100644
--- a/src/fs/test_fs_namespace.c
+++ b/src/fs/test_fs_namespace.c
@@ -66,12 +66,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
66{ 66{
67 p->cfg = GNUNET_CONFIGURATION_create (); 67 p->cfg = GNUNET_CONFIGURATION_create ();
68#if START_ARM 68#if START_ARM
69 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 69 p->arm_proc =
70 "gnunet-service-arm", 70 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
71 "gnunet-service-arm",
71#if VERBOSE 72#if VERBOSE
72 "-L", "DEBUG", 73 "-L", "DEBUG",
73#endif 74#endif
74 "-c", cfgname, NULL); 75 "-c", cfgname, NULL);
75#endif 76#endif
76 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 77 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
77} 78}
@@ -87,8 +88,7 @@ stop_arm (struct PeerContext *p)
87 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 88 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
88 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 89 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
89 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 90 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
90 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 91 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
91 "ARM process %u stopped\n",
92 GNUNET_OS_process_get_pid (p->arm_proc)); 92 GNUNET_OS_process_get_pid (p->arm_proc));
93 GNUNET_OS_process_close (p->arm_proc); 93 GNUNET_OS_process_close (p->arm_proc);
94 p->arm_proc = NULL; 94 p->arm_proc = NULL;
@@ -155,8 +155,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
155 case GNUNET_FS_STATUS_SEARCH_RESULT: 155 case GNUNET_FS_STATUS_SEARCH_RESULT:
156 if (sks_search == event->value.search.sc) 156 if (sks_search == event->value.search.sc)
157 { 157 {
158 if (!GNUNET_FS_uri_test_equal (sks_expect_uri, 158 if (!GNUNET_FS_uri_test_equal
159 event->value.search.specifics.result.uri)) 159 (sks_expect_uri, event->value.search.specifics.result.uri))
160 { 160 {
161 fprintf (stderr, "Wrong result for sks search!\n"); 161 fprintf (stderr, "Wrong result for sks search!\n");
162 err = 1; 162 err = 1;
@@ -167,14 +167,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
167 } 167 }
168 else if (ksk_search == event->value.search.sc) 168 else if (ksk_search == event->value.search.sc)
169 { 169 {
170 if (!GNUNET_FS_uri_test_equal (ksk_expect_uri, 170 if (!GNUNET_FS_uri_test_equal
171 event->value.search.specifics.result.uri)) 171 (ksk_expect_uri, event->value.search.specifics.result.uri))
172 { 172 {
173 fprintf (stderr, "Wrong result for ksk search!\n"); 173 fprintf (stderr, "Wrong result for ksk search!\n");
174 err = 1; 174 err = 1;
175 } 175 }
176 GNUNET_SCHEDULER_add_continuation (&abort_ksk_search_task, 176 GNUNET_SCHEDULER_add_continuation (&abort_ksk_search_task, NULL,
177 NULL,
178 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 177 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
179 } 178 }
180 else 179 else
@@ -184,16 +183,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
184 } 183 }
185 break; 184 break;
186 case GNUNET_FS_STATUS_SEARCH_ERROR: 185 case GNUNET_FS_STATUS_SEARCH_ERROR:
187 fprintf (stderr, 186 fprintf (stderr, "Error searching file: %s\n",
188 "Error searching file: %s\n",
189 event->value.search.specifics.error.message); 187 event->value.search.specifics.error.message);
190 if (sks_search == event->value.search.sc) 188 if (sks_search == event->value.search.sc)
191 GNUNET_SCHEDULER_add_continuation (&abort_sks_search_task, 189 GNUNET_SCHEDULER_add_continuation (&abort_sks_search_task, NULL,
192 NULL,
193 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 190 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
194 else if (ksk_search == event->value.search.sc) 191 else if (ksk_search == event->value.search.sc)
195 GNUNET_SCHEDULER_add_continuation (&abort_ksk_search_task, 192 GNUNET_SCHEDULER_add_continuation (&abort_ksk_search_task, NULL,
196 NULL,
197 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 193 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
198 else 194 else
199 GNUNET_break (0); 195 GNUNET_break (0);
@@ -365,15 +361,12 @@ testNamespace ()
365 361
366 362
367static void 363static void
368run (void *cls, 364run (void *cls, char *const *args, const char *cfgfile,
369 char *const *args, 365 const struct GNUNET_CONFIGURATION_Handle *cfg)
370 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
371{ 366{
372 setup_peer (&p1, "test_fs_namespace_data.conf"); 367 setup_peer (&p1, "test_fs_namespace_data.conf");
373 fs = GNUNET_FS_start (cfg, 368 fs = GNUNET_FS_start (cfg, "test-fs-namespace", &progress_cb, NULL,
374 "test-fs-namespace", 369 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
375 &progress_cb,
376 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
377 testNamespace (); 370 testNamespace ();
378} 371}
379 372
@@ -401,9 +394,8 @@ main (int argc, char *argv[])
401 "WARNING", 394 "WARNING",
402#endif 395#endif
403 NULL); 396 NULL);
404 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 397 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
405 argvx, "test-fs-namespace", 398 "test-fs-namespace", "nohelp", options, &run, NULL);
406 "nohelp", options, &run, NULL);
407 stop_arm (&p1); 399 stop_arm (&p1);
408 if (GNUNET_YES != update_started) 400 if (GNUNET_YES != update_started)
409 { 401 {
diff --git a/src/fs/test_fs_namespace_list_updateable.c b/src/fs/test_fs_namespace_list_updateable.c
index dc8673e21..1ad2fb5ac 100644
--- a/src/fs/test_fs_namespace_list_updateable.c
+++ b/src/fs/test_fs_namespace_list_updateable.c
@@ -70,12 +70,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
70{ 70{
71 p->cfg = GNUNET_CONFIGURATION_create (); 71 p->cfg = GNUNET_CONFIGURATION_create ();
72#if START_ARM 72#if START_ARM
73 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 73 p->arm_proc =
74 "gnunet-service-arm", 74 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
75 "gnunet-service-arm",
75#if VERBOSE 76#if VERBOSE
76 "-L", "DEBUG", 77 "-L", "DEBUG",
77#endif 78#endif
78 "-c", cfgname, NULL); 79 "-c", cfgname, NULL);
79#endif 80#endif
80 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 81 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
81} 82}
@@ -91,8 +92,7 @@ stop_arm (struct PeerContext *p)
91 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 92 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
92 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 93 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
93 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 94 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
94 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 95 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
95 "ARM process %u stopped\n",
96 GNUNET_OS_process_get_pid (p->arm_proc)); 96 GNUNET_OS_process_get_pid (p->arm_proc));
97 GNUNET_OS_process_close (p->arm_proc); 97 GNUNET_OS_process_close (p->arm_proc);
98 p->arm_proc = NULL; 98 p->arm_proc = NULL;
@@ -112,8 +112,7 @@ stop_arm (struct PeerContext *p)
112 112
113 113
114static void 114static void
115check_next (void *cls, 115check_next (void *cls, const char *last_id,
116 const char *last_id,
117 const struct GNUNET_FS_Uri *last_uri, 116 const struct GNUNET_FS_Uri *last_uri,
118 const struct GNUNET_CONTAINER_MetaData *last_meta, 117 const struct GNUNET_CONTAINER_MetaData *last_meta,
119 const char *next_id) 118 const char *next_id)
@@ -125,8 +124,7 @@ check_next (void *cls,
125 124
126 125
127static void 126static void
128check_this_next (void *cls, 127check_this_next (void *cls, const char *last_id,
129 const char *last_id,
130 const struct GNUNET_FS_Uri *last_uri, 128 const struct GNUNET_FS_Uri *last_uri,
131 const struct GNUNET_CONTAINER_MetaData *last_meta, 129 const struct GNUNET_CONTAINER_MetaData *last_meta,
132 const char *next_id) 130 const char *next_id)
@@ -150,8 +148,7 @@ sks_cont_next (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
150 148
151 149
152static void 150static void
153check_this (void *cls, 151check_this (void *cls, const char *last_id,
154 const char *last_id,
155 const struct GNUNET_FS_Uri *last_uri, 152 const struct GNUNET_FS_Uri *last_uri,
156 const struct GNUNET_CONTAINER_MetaData *last_meta, 153 const struct GNUNET_CONTAINER_MetaData *last_meta,
157 const char *next_id) 154 const char *next_id)
@@ -169,13 +166,7 @@ sks_cont_this (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
169 GNUNET_assert (NULL == emsg); 166 GNUNET_assert (NULL == emsg);
170 err = 1; 167 err = 1;
171 GNUNET_FS_namespace_list_updateable (ns, NULL, &check_this, NULL); 168 GNUNET_FS_namespace_list_updateable (ns, NULL, &check_this, NULL);
172 GNUNET_FS_publish_sks (fs, 169 GNUNET_FS_publish_sks (fs, ns, "next", "future", meta, uri_next, &bo,
173 ns,
174 "next",
175 "future",
176 meta,
177 uri_next,
178 &bo,
179 GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_next, NULL); 170 GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_next, NULL);
180 171
181} 172}
@@ -209,15 +200,12 @@ testNamespace ()
209 200
210 201
211static void 202static void
212run (void *cls, 203run (void *cls, char *const *args, const char *cfgfile,
213 char *const *args, 204 const struct GNUNET_CONFIGURATION_Handle *cfg)
214 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
215{ 205{
216 setup_peer (&p1, "test_fs_namespace_data.conf"); 206 setup_peer (&p1, "test_fs_namespace_data.conf");
217 fs = GNUNET_FS_start (cfg, 207 fs = GNUNET_FS_start (cfg, "test-fs-namespace", &progress_cb, NULL,
218 "test-fs-namespace", 208 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
219 &progress_cb,
220 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
221 testNamespace (); 209 testNamespace ();
222} 210}
223 211
@@ -245,9 +233,8 @@ main (int argc, char *argv[])
245 "WARNING", 233 "WARNING",
246#endif 234#endif
247 NULL); 235 NULL);
248 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 236 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
249 argvx, "test-fs-namespace", 237 "test-fs-namespace", "nohelp", options, &run, NULL);
250 "nohelp", options, &run, NULL);
251 stop_arm (&p1); 238 stop_arm (&p1);
252 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-namespace/"); 239 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-namespace/");
253 return err; 240 return err;
diff --git a/src/fs/test_fs_publish.c b/src/fs/test_fs_publish.c
index d53b5b0ae..797c4c9a8 100644
--- a/src/fs/test_fs_publish.c
+++ b/src/fs/test_fs_publish.c
@@ -98,11 +98,10 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
98 printf ("Publish complete, %llu kbps.\n", 98 printf ("Publish complete, %llu kbps.\n",
99 (unsigned long long) (FILESIZE * 1000 / 99 (unsigned long long) (FILESIZE * 1000 /
100 (1 + 100 (1 +
101 GNUNET_TIME_absolute_get_duration 101 GNUNET_TIME_absolute_get_duration (start).
102 (start).rel_value) / 1024)); 102 rel_value) / 1024));
103 if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) 103 if (0 == strcmp ("publish-context-dir", event->value.publish.cctx))
104 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 104 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL,
105 NULL,
106 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 105 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
107 break; 106 break;
108 case GNUNET_FS_STATUS_PUBLISH_PROGRESS: 107 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
@@ -113,22 +112,20 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
113 (unsigned long long) event->value.publish.completed, 112 (unsigned long long) event->value.publish.completed,
114 (unsigned long long) event->value.publish.size, 113 (unsigned long long) event->value.publish.size,
115 event->value.publish.specifics.progress.depth, 114 event->value.publish.specifics.progress.depth,
116 (unsigned long long) event->value.publish.specifics. 115 (unsigned long long) event->value.publish.specifics.progress.
117 progress.offset); 116 offset);
118#endif 117#endif
119 break; 118 break;
120 case GNUNET_FS_STATUS_PUBLISH_ERROR: 119 case GNUNET_FS_STATUS_PUBLISH_ERROR:
121 ret = event->value.publish.cctx; 120 ret = event->value.publish.cctx;
122 fprintf (stderr, 121 fprintf (stderr, "Error publishing file: %s\n",
123 "Error publishing file: %s\n",
124 event->value.publish.specifics.error.message); 122 event->value.publish.specifics.error.message);
125 err = 1; 123 err = 1;
126 if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) 124 if (0 == strcmp ("publish-context-dir", event->value.publish.cctx))
127 { 125 {
128 fprintf (stderr, "Scheduling abort task for error on `%s'\n", 126 fprintf (stderr, "Scheduling abort task for error on `%s'\n",
129 (const char *) event->value.publish.cctx); 127 (const char *) event->value.publish.cctx);
130 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 128 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL,
131 NULL,
132 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 129 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
133 } 130 }
134 break; 131 break;
@@ -136,16 +133,16 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
136 ret = event->value.publish.cctx; 133 ret = event->value.publish.cctx;
137 if (0 == strcmp ("publish-context1", event->value.publish.cctx)) 134 if (0 == strcmp ("publish-context1", event->value.publish.cctx))
138 { 135 {
139 GNUNET_assert (0 == strcmp ("publish-context-dir", 136 GNUNET_assert (0 ==
140 event->value.publish.pctx)); 137 strcmp ("publish-context-dir", event->value.publish.pctx));
141 GNUNET_assert (FILESIZE == event->value.publish.size); 138 GNUNET_assert (FILESIZE == event->value.publish.size);
142 GNUNET_assert (0 == event->value.publish.completed); 139 GNUNET_assert (0 == event->value.publish.completed);
143 GNUNET_assert (1 == event->value.publish.anonymity); 140 GNUNET_assert (1 == event->value.publish.anonymity);
144 } 141 }
145 else if (0 == strcmp ("publish-context2", event->value.publish.cctx)) 142 else if (0 == strcmp ("publish-context2", event->value.publish.cctx))
146 { 143 {
147 GNUNET_assert (0 == strcmp ("publish-context-dir", 144 GNUNET_assert (0 ==
148 event->value.publish.pctx)); 145 strcmp ("publish-context-dir", event->value.publish.pctx));
149 GNUNET_assert (FILESIZE == event->value.publish.size); 146 GNUNET_assert (FILESIZE == event->value.publish.size);
150 GNUNET_assert (0 == event->value.publish.completed); 147 GNUNET_assert (0 == event->value.publish.completed);
151 GNUNET_assert (2 == event->value.publish.anonymity); 148 GNUNET_assert (2 == event->value.publish.anonymity);
@@ -175,12 +172,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
175{ 172{
176 p->cfg = GNUNET_CONFIGURATION_create (); 173 p->cfg = GNUNET_CONFIGURATION_create ();
177#if START_ARM 174#if START_ARM
178 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 175 p->arm_proc =
179 "gnunet-service-arm", 176 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
177 "gnunet-service-arm",
180#if VERBOSE 178#if VERBOSE
181 "-L", "DEBUG", 179 "-L", "DEBUG",
182#endif 180#endif
183 "-c", cfgname, NULL); 181 "-c", cfgname, NULL);
184#endif 182#endif
185 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 183 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
186} 184}
@@ -196,8 +194,7 @@ stop_arm (struct PeerContext *p)
196 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 194 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
197 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 195 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
198 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 196 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
200 "ARM process %u stopped\n",
201 GNUNET_OS_process_get_pid (p->arm_proc)); 198 GNUNET_OS_process_get_pid (p->arm_proc));
202 GNUNET_OS_process_close (p->arm_proc); 199 GNUNET_OS_process_close (p->arm_proc);
203 p->arm_proc = NULL; 200 p->arm_proc = NULL;
@@ -208,9 +205,8 @@ stop_arm (struct PeerContext *p)
208 205
209 206
210static void 207static void
211run (void *cls, 208run (void *cls, char *const *args, const char *cfgfile,
212 char *const *args, 209 const struct GNUNET_CONFIGURATION_Handle *cfg)
213 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
214{ 210{
215 const char *keywords[] = { 211 const char *keywords[] = {
216 "down_foo", 212 "down_foo",
@@ -226,19 +222,15 @@ run (void *cls,
226 struct GNUNET_FS_BlockOptions bo; 222 struct GNUNET_FS_BlockOptions bo;
227 223
228 setup_peer (&p1, "test_fs_publish_data.conf"); 224 setup_peer (&p1, "test_fs_publish_data.conf");
229 fs = GNUNET_FS_start (cfg, 225 fs = GNUNET_FS_start (cfg, "test-fs-publish", &progress_cb, NULL,
230 "test-fs-publish", 226 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
231 &progress_cb,
232 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
233 GNUNET_assert (NULL != fs); 227 GNUNET_assert (NULL != fs);
234 fn1 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst"); 228 fn1 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst");
235 buf = GNUNET_malloc (FILESIZE); 229 buf = GNUNET_malloc (FILESIZE);
236 for (i = 0; i < FILESIZE; i++) 230 for (i = 0; i < FILESIZE; i++)
237 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 231 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
238 GNUNET_assert (FILESIZE == 232 GNUNET_assert (FILESIZE ==
239 GNUNET_DISK_fn_write (fn1, 233 GNUNET_DISK_fn_write (fn1, buf, FILESIZE,
240 buf,
241 FILESIZE,
242 GNUNET_DISK_PERM_USER_READ | 234 GNUNET_DISK_PERM_USER_READ |
243 GNUNET_DISK_PERM_USER_WRITE)); 235 GNUNET_DISK_PERM_USER_WRITE));
244 GNUNET_free (buf); 236 GNUNET_free (buf);
@@ -248,9 +240,7 @@ run (void *cls,
248 for (i = 0; i < FILESIZE; i++) 240 for (i = 0; i < FILESIZE; i++)
249 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 241 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
250 GNUNET_assert (FILESIZE == 242 GNUNET_assert (FILESIZE ==
251 GNUNET_DISK_fn_write (fn2, 243 GNUNET_DISK_fn_write (fn2, buf, FILESIZE,
252 buf,
253 FILESIZE,
254 GNUNET_DISK_PERM_USER_READ | 244 GNUNET_DISK_PERM_USER_READ |
255 GNUNET_DISK_PERM_USER_WRITE)); 245 GNUNET_DISK_PERM_USER_WRITE));
256 GNUNET_free (buf); 246 GNUNET_free (buf);
@@ -262,34 +252,30 @@ run (void *cls,
262 bo.replication_level = 0; 252 bo.replication_level = 0;
263 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 253 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
264 254
265 fi1 = GNUNET_FS_file_information_create_from_file (fs, 255 fi1 =
266 "publish-context1", 256 GNUNET_FS_file_information_create_from_file (fs, "publish-context1", fn1,
267 fn1, 257 kuri, meta, GNUNET_YES, &bo);
268 kuri,
269 meta, GNUNET_YES, &bo);
270 258
271 GNUNET_assert (NULL != fi1); 259 GNUNET_assert (NULL != fi1);
272 bo.anonymity_level = 2; 260 bo.anonymity_level = 2;
273 fi2 = GNUNET_FS_file_information_create_from_file (fs, 261 fi2 =
274 "publish-context2", 262 GNUNET_FS_file_information_create_from_file (fs, "publish-context2", fn2,
275 fn2, 263 kuri, meta, GNUNET_YES, &bo);
276 kuri,
277 meta, GNUNET_YES, &bo);
278 GNUNET_assert (NULL != fi2); 264 GNUNET_assert (NULL != fi2);
279 bo.anonymity_level = 3; 265 bo.anonymity_level = 3;
280 fidir = GNUNET_FS_file_information_create_empty_directory (fs, 266 fidir =
281 "publish-context-dir", 267 GNUNET_FS_file_information_create_empty_directory (fs,
282 kuri, meta, &bo); 268 "publish-context-dir",
269 kuri, meta, &bo);
283 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); 270 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
284 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); 271 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
285 GNUNET_FS_uri_destroy (kuri); 272 GNUNET_FS_uri_destroy (kuri);
286 GNUNET_CONTAINER_meta_data_destroy (meta); 273 GNUNET_CONTAINER_meta_data_destroy (meta);
287 GNUNET_assert (NULL != fidir); 274 GNUNET_assert (NULL != fidir);
288 start = GNUNET_TIME_absolute_get (); 275 start = GNUNET_TIME_absolute_get ();
289 publish = GNUNET_FS_publish_start (fs, 276 publish =
290 fidir, 277 GNUNET_FS_publish_start (fs, fidir, NULL, NULL, NULL,
291 NULL, NULL, NULL, 278 GNUNET_FS_PUBLISH_OPTION_NONE);
292 GNUNET_FS_PUBLISH_OPTION_NONE);
293 GNUNET_assert (publish != NULL); 279 GNUNET_assert (publish != NULL);
294} 280}
295 281
@@ -317,8 +303,8 @@ main (int argc, char *argv[])
317 "WARNING", 303 "WARNING",
318#endif 304#endif
319 NULL); 305 NULL);
320 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 306 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
321 argvx, "test-fs-publish", "nohelp", options, &run, NULL); 307 "test-fs-publish", "nohelp", options, &run, NULL);
322 stop_arm (&p1); 308 stop_arm (&p1);
323 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-publish/"); 309 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-publish/");
324 if (fn1 != NULL) 310 if (fn1 != NULL)
diff --git a/src/fs/test_fs_publish_persistence.c b/src/fs/test_fs_publish_persistence.c
index 4dcf10965..f69ac5d9a 100644
--- a/src/fs/test_fs_publish_persistence.c
+++ b/src/fs/test_fs_publish_persistence.c
@@ -106,10 +106,7 @@ restart_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
106{ 106{
107 rtask = GNUNET_SCHEDULER_NO_TASK; 107 rtask = GNUNET_SCHEDULER_NO_TASK;
108 GNUNET_FS_stop (fs); 108 GNUNET_FS_stop (fs);
109 fs = GNUNET_FS_start (cfg, 109 fs = GNUNET_FS_start (cfg, "test-fs-publish-persistence", &progress_cb, NULL,
110 "test-fs-publish-persistence",
111 &progress_cb,
112 NULL,
113 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); 110 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
114} 111}
115 112
@@ -132,8 +129,9 @@ consider_restart (int ev)
132 if (prev[i] == ev) 129 if (prev[i] == ev)
133 return; 130 return;
134 prev[off++] = ev; 131 prev[off++] = ev;
135 rtask = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_URGENT, 132 rtask =
136 &restart_fs_task, NULL); 133 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_URGENT,
134 &restart_fs_task, NULL);
137} 135}
138 136
139 137
@@ -151,8 +149,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
151 printf ("Publish complete, %llu kbps.\n", 149 printf ("Publish complete, %llu kbps.\n",
152 (unsigned long long) (FILESIZE * 1000LL / 150 (unsigned long long) (FILESIZE * 1000LL /
153 (1 + 151 (1 +
154 GNUNET_TIME_absolute_get_duration 152 GNUNET_TIME_absolute_get_duration (start).
155 (start).rel_value) / 1024)); 153 rel_value) / 1024));
156 if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) 154 if (0 == strcmp ("publish-context-dir", event->value.publish.cctx))
157 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); 155 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
158 break; 156 break;
@@ -165,8 +163,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
165 (unsigned long long) event->value.publish.completed, 163 (unsigned long long) event->value.publish.completed,
166 (unsigned long long) event->value.publish.size, 164 (unsigned long long) event->value.publish.size,
167 event->value.publish.specifics.progress.depth, 165 event->value.publish.specifics.progress.depth,
168 (unsigned long long) event->value.publish.specifics. 166 (unsigned long long) event->value.publish.specifics.progress.
169 progress.offset); 167 offset);
170#endif 168#endif
171 break; 169 break;
172 case GNUNET_FS_STATUS_PUBLISH_SUSPEND: 170 case GNUNET_FS_STATUS_PUBLISH_SUSPEND:
@@ -177,17 +175,15 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
177 if (NULL == publish) 175 if (NULL == publish)
178 { 176 {
179 GNUNET_assert (GNUNET_YES == 177 GNUNET_assert (GNUNET_YES ==
180 GNUNET_FS_file_information_is_directory (event-> 178 GNUNET_FS_file_information_is_directory (event->value.
181 value.publish. 179 publish.fi));
182 fi));
183 publish = event->value.publish.pc; 180 publish = event->value.publish.pc;
184 return "publish-context-dir"; 181 return "publish-context-dir";
185 } 182 }
186 break; 183 break;
187 case GNUNET_FS_STATUS_PUBLISH_ERROR: 184 case GNUNET_FS_STATUS_PUBLISH_ERROR:
188 ret = event->value.publish.cctx; 185 ret = event->value.publish.cctx;
189 fprintf (stderr, 186 fprintf (stderr, "Error publishing file: %s\n",
190 "Error publishing file: %s\n",
191 event->value.publish.specifics.error.message); 187 event->value.publish.specifics.error.message);
192 err = 1; 188 err = 1;
193 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); 189 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
@@ -198,16 +194,16 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
198 ret = event->value.publish.cctx; 194 ret = event->value.publish.cctx;
199 if (0 == strcmp ("publish-context1", event->value.publish.cctx)) 195 if (0 == strcmp ("publish-context1", event->value.publish.cctx))
200 { 196 {
201 GNUNET_assert (0 == strcmp ("publish-context-dir", 197 GNUNET_assert (0 ==
202 event->value.publish.pctx)); 198 strcmp ("publish-context-dir", event->value.publish.pctx));
203 GNUNET_assert (FILESIZE == event->value.publish.size); 199 GNUNET_assert (FILESIZE == event->value.publish.size);
204 GNUNET_assert (0 == event->value.publish.completed); 200 GNUNET_assert (0 == event->value.publish.completed);
205 GNUNET_assert (1 == event->value.publish.anonymity); 201 GNUNET_assert (1 == event->value.publish.anonymity);
206 } 202 }
207 else if (0 == strcmp ("publish-context2", event->value.publish.cctx)) 203 else if (0 == strcmp ("publish-context2", event->value.publish.cctx))
208 { 204 {
209 GNUNET_assert (0 == strcmp ("publish-context-dir", 205 GNUNET_assert (0 ==
210 event->value.publish.pctx)); 206 strcmp ("publish-context-dir", event->value.publish.pctx));
211 GNUNET_assert (FILESIZE == event->value.publish.size); 207 GNUNET_assert (FILESIZE == event->value.publish.size);
212 GNUNET_assert (0 == event->value.publish.completed); 208 GNUNET_assert (0 == event->value.publish.completed);
213 GNUNET_assert (2 == event->value.publish.anonymity); 209 GNUNET_assert (2 == event->value.publish.anonymity);
@@ -238,12 +234,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
238{ 234{
239 p->cfg = GNUNET_CONFIGURATION_create (); 235 p->cfg = GNUNET_CONFIGURATION_create ();
240#if START_ARM 236#if START_ARM
241 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 237 p->arm_proc =
242 "gnunet-service-arm", 238 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
239 "gnunet-service-arm",
243#if VERBOSE 240#if VERBOSE
244 "-L", "DEBUG", 241 "-L", "DEBUG",
245#endif 242#endif
246 "-c", cfgname, NULL); 243 "-c", cfgname, NULL);
247#endif 244#endif
248 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 245 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
249} 246}
@@ -259,8 +256,7 @@ stop_arm (struct PeerContext *p)
259 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 256 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
260 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 257 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
261 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 258 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 259 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
263 "ARM process %u stopped\n",
264 GNUNET_OS_process_get_pid (p->arm_proc)); 260 GNUNET_OS_process_get_pid (p->arm_proc));
265 GNUNET_OS_process_close (p->arm_proc); 261 GNUNET_OS_process_close (p->arm_proc);
266 p->arm_proc = NULL; 262 p->arm_proc = NULL;
@@ -271,9 +267,8 @@ stop_arm (struct PeerContext *p)
271 267
272 268
273static void 269static void
274run (void *cls, 270run (void *cls, char *const *args, const char *cfgfile,
275 char *const *args, 271 const struct GNUNET_CONFIGURATION_Handle *c)
276 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
277{ 272{
278 const char *keywords[] = { 273 const char *keywords[] = {
279 "down_foo", 274 "down_foo",
@@ -290,10 +285,7 @@ run (void *cls,
290 285
291 cfg = c; 286 cfg = c;
292 setup_peer (&p1, "test_fs_publish_data.conf"); 287 setup_peer (&p1, "test_fs_publish_data.conf");
293 fs = GNUNET_FS_start (cfg, 288 fs = GNUNET_FS_start (cfg, "test-fs-publish-persistence", &progress_cb, NULL,
294 "test-fs-publish-persistence",
295 &progress_cb,
296 NULL,
297 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); 289 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
298 GNUNET_assert (NULL != fs); 290 GNUNET_assert (NULL != fs);
299 fn1 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst"); 291 fn1 = GNUNET_DISK_mktemp ("gnunet-publish-test-dst");
@@ -301,9 +293,7 @@ run (void *cls,
301 for (i = 0; i < FILESIZE; i++) 293 for (i = 0; i < FILESIZE; i++)
302 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 294 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
303 GNUNET_assert (FILESIZE == 295 GNUNET_assert (FILESIZE ==
304 GNUNET_DISK_fn_write (fn1, 296 GNUNET_DISK_fn_write (fn1, buf, FILESIZE,
305 buf,
306 FILESIZE,
307 GNUNET_DISK_PERM_USER_READ | 297 GNUNET_DISK_PERM_USER_READ |
308 GNUNET_DISK_PERM_USER_WRITE)); 298 GNUNET_DISK_PERM_USER_WRITE));
309 GNUNET_free (buf); 299 GNUNET_free (buf);
@@ -313,9 +303,7 @@ run (void *cls,
313 for (i = 0; i < FILESIZE; i++) 303 for (i = 0; i < FILESIZE; i++)
314 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 304 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
315 GNUNET_assert (FILESIZE == 305 GNUNET_assert (FILESIZE ==
316 GNUNET_DISK_fn_write (fn2, 306 GNUNET_DISK_fn_write (fn2, buf, FILESIZE,
317 buf,
318 FILESIZE,
319 GNUNET_DISK_PERM_USER_READ | 307 GNUNET_DISK_PERM_USER_READ |
320 GNUNET_DISK_PERM_USER_WRITE)); 308 GNUNET_DISK_PERM_USER_WRITE));
321 GNUNET_free (buf); 309 GNUNET_free (buf);
@@ -326,32 +314,28 @@ run (void *cls,
326 bo.anonymity_level = 1; 314 bo.anonymity_level = 1;
327 bo.replication_level = 0; 315 bo.replication_level = 0;
328 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 316 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
329 fi1 = GNUNET_FS_file_information_create_from_file (fs, 317 fi1 =
330 "publish-context1", 318 GNUNET_FS_file_information_create_from_file (fs, "publish-context1", fn1,
331 fn1, 319 kuri, meta, GNUNET_YES, &bo);
332 kuri,
333 meta, GNUNET_YES, &bo);
334 GNUNET_assert (NULL != fi1); 320 GNUNET_assert (NULL != fi1);
335 bo.anonymity_level = 2; 321 bo.anonymity_level = 2;
336 fi2 = GNUNET_FS_file_information_create_from_file (fs, 322 fi2 =
337 "publish-context2", 323 GNUNET_FS_file_information_create_from_file (fs, "publish-context2", fn2,
338 fn2, 324 kuri, meta, GNUNET_YES, &bo);
339 kuri,
340 meta, GNUNET_YES, &bo);
341 GNUNET_assert (NULL != fi2); 325 GNUNET_assert (NULL != fi2);
342 bo.anonymity_level = 3; 326 bo.anonymity_level = 3;
343 fidir = GNUNET_FS_file_information_create_empty_directory (fs, 327 fidir =
344 "publish-context-dir", 328 GNUNET_FS_file_information_create_empty_directory (fs,
345 kuri, meta, &bo); 329 "publish-context-dir",
330 kuri, meta, &bo);
346 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); 331 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1));
347 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); 332 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2));
348 GNUNET_FS_uri_destroy (kuri); 333 GNUNET_FS_uri_destroy (kuri);
349 GNUNET_CONTAINER_meta_data_destroy (meta); 334 GNUNET_CONTAINER_meta_data_destroy (meta);
350 GNUNET_assert (NULL != fidir); 335 GNUNET_assert (NULL != fidir);
351 start = GNUNET_TIME_absolute_get (); 336 start = GNUNET_TIME_absolute_get ();
352 GNUNET_FS_publish_start (fs, 337 GNUNET_FS_publish_start (fs, fidir, NULL, NULL, NULL,
353 fidir, 338 GNUNET_FS_PUBLISH_OPTION_NONE);
354 NULL, NULL, NULL, GNUNET_FS_PUBLISH_OPTION_NONE);
355 GNUNET_assert (publish != NULL); 339 GNUNET_assert (publish != NULL);
356} 340}
357 341
@@ -379,8 +363,8 @@ main (int argc, char *argv[])
379 "WARNING", 363 "WARNING",
380#endif 364#endif
381 NULL); 365 NULL);
382 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 366 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
383 argvx, "test-fs-publish", "nohelp", options, &run, NULL); 367 "test-fs-publish", "nohelp", options, &run, NULL);
384 stop_arm (&p1); 368 stop_arm (&p1);
385 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-publish/"); 369 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-publish/");
386 if (fn1 != NULL) 370 if (fn1 != NULL)
diff --git a/src/fs/test_fs_search.c b/src/fs/test_fs_search.c
index 878624c73..3961017cf 100644
--- a/src/fs/test_fs_search.c
+++ b/src/fs/test_fs_search.c
@@ -101,16 +101,16 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
101 (unsigned long long) event->value.publish.completed, 101 (unsigned long long) event->value.publish.completed,
102 (unsigned long long) event->value.publish.size, 102 (unsigned long long) event->value.publish.size,
103 event->value.publish.specifics.progress.depth, 103 event->value.publish.specifics.progress.depth,
104 (unsigned long long) event->value.publish.specifics. 104 (unsigned long long) event->value.publish.specifics.progress.
105 progress.offset); 105 offset);
106#endif 106#endif
107 break; 107 break;
108 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 108 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
109 kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords); 109 kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords);
110 start = GNUNET_TIME_absolute_get (); 110 start = GNUNET_TIME_absolute_get ();
111 search = GNUNET_FS_search_start (fs, 111 search =
112 kuri, 112 GNUNET_FS_search_start (fs, kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE,
113 1, GNUNET_FS_SEARCH_OPTION_NONE, "search"); 113 "search");
114 GNUNET_FS_uri_destroy (kuri); 114 GNUNET_FS_uri_destroy (kuri);
115 GNUNET_assert (search != NULL); 115 GNUNET_assert (search != NULL);
116 break; 116 break;
@@ -118,25 +118,20 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
118#if VERBOSE 118#if VERBOSE
119 printf ("Search complete.\n"); 119 printf ("Search complete.\n");
120#endif 120#endif
121 GNUNET_SCHEDULER_add_continuation (&abort_search_task, 121 GNUNET_SCHEDULER_add_continuation (&abort_search_task, NULL,
122 NULL,
123 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 122 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
124 break; 123 break;
125 case GNUNET_FS_STATUS_PUBLISH_ERROR: 124 case GNUNET_FS_STATUS_PUBLISH_ERROR:
126 fprintf (stderr, 125 fprintf (stderr, "Error publishing file: %s\n",
127 "Error publishing file: %s\n",
128 event->value.publish.specifics.error.message); 126 event->value.publish.specifics.error.message);
129 GNUNET_break (0); 127 GNUNET_break (0);
130 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 128 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL,
131 NULL,
132 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 129 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
133 break; 130 break;
134 case GNUNET_FS_STATUS_SEARCH_ERROR: 131 case GNUNET_FS_STATUS_SEARCH_ERROR:
135 fprintf (stderr, 132 fprintf (stderr, "Error searching file: %s\n",
136 "Error searching file: %s\n",
137 event->value.search.specifics.error.message); 133 event->value.search.specifics.error.message);
138 GNUNET_SCHEDULER_add_continuation (&abort_search_task, 134 GNUNET_SCHEDULER_add_continuation (&abort_search_task, NULL,
139 NULL,
140 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 135 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
141 break; 136 break;
142 case GNUNET_FS_STATUS_PUBLISH_START: 137 case GNUNET_FS_STATUS_PUBLISH_START:
@@ -162,8 +157,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
162 break; 157 break;
163 case GNUNET_FS_STATUS_SEARCH_STOPPED: 158 case GNUNET_FS_STATUS_SEARCH_STOPPED:
164 GNUNET_assert (search == event->value.search.sc); 159 GNUNET_assert (search == event->value.search.sc);
165 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 160 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL,
166 NULL,
167 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 161 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
168 break; 162 break;
169 default: 163 default:
@@ -179,12 +173,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
179{ 173{
180 p->cfg = GNUNET_CONFIGURATION_create (); 174 p->cfg = GNUNET_CONFIGURATION_create ();
181#if START_ARM 175#if START_ARM
182 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 176 p->arm_proc =
183 "gnunet-service-arm", 177 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
178 "gnunet-service-arm",
184#if VERBOSE 179#if VERBOSE
185 "-L", "DEBUG", 180 "-L", "DEBUG",
186#endif 181#endif
187 "-c", cfgname, NULL); 182 "-c", cfgname, NULL);
188#endif 183#endif
189 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 184 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
190} 185}
@@ -200,8 +195,7 @@ stop_arm (struct PeerContext *p)
200 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 195 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
201 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 196 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
202 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 197 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
204 "ARM process %u stopped\n",
205 GNUNET_OS_process_get_pid (p->arm_proc)); 199 GNUNET_OS_process_get_pid (p->arm_proc));
206 GNUNET_OS_process_close (p->arm_proc); 200 GNUNET_OS_process_close (p->arm_proc);
207 p->arm_proc = NULL; 201 p->arm_proc = NULL;
@@ -212,9 +206,8 @@ stop_arm (struct PeerContext *p)
212 206
213 207
214static void 208static void
215run (void *cls, 209run (void *cls, char *const *args, const char *cfgfile,
216 char *const *args, 210 const struct GNUNET_CONFIGURATION_Handle *cfg)
217 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
218{ 211{
219 const char *keywords[] = { 212 const char *keywords[] = {
220 "down_foo", 213 "down_foo",
@@ -228,10 +221,8 @@ run (void *cls,
228 size_t i; 221 size_t i;
229 222
230 setup_peer (&p1, "test_fs_search_data.conf"); 223 setup_peer (&p1, "test_fs_search_data.conf");
231 fs = GNUNET_FS_start (cfg, 224 fs = GNUNET_FS_start (cfg, "test-fs-search", &progress_cb, NULL,
232 "test-fs-search", 225 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
233 &progress_cb,
234 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
235 GNUNET_assert (NULL != fs); 226 GNUNET_assert (NULL != fs);
236 buf = GNUNET_malloc (FILESIZE); 227 buf = GNUNET_malloc (FILESIZE);
237 for (i = 0; i < FILESIZE; i++) 228 for (i = 0; i < FILESIZE; i++)
@@ -242,19 +233,16 @@ run (void *cls,
242 bo.anonymity_level = 1; 233 bo.anonymity_level = 1;
243 bo.replication_level = 0; 234 bo.replication_level = 0;
244 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 235 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
245 fi = GNUNET_FS_file_information_create_from_data (fs, 236 fi = GNUNET_FS_file_information_create_from_data (fs, "publish-context",
246 "publish-context", 237 FILESIZE, buf, kuri, meta,
247 FILESIZE, 238 GNUNET_NO, &bo);
248 buf,
249 kuri, meta, GNUNET_NO, &bo);
250 GNUNET_FS_uri_destroy (kuri); 239 GNUNET_FS_uri_destroy (kuri);
251 GNUNET_CONTAINER_meta_data_destroy (meta); 240 GNUNET_CONTAINER_meta_data_destroy (meta);
252 GNUNET_assert (NULL != fi); 241 GNUNET_assert (NULL != fi);
253 start = GNUNET_TIME_absolute_get (); 242 start = GNUNET_TIME_absolute_get ();
254 publish = GNUNET_FS_publish_start (fs, 243 publish =
255 fi, 244 GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL,
256 NULL, NULL, NULL, 245 GNUNET_FS_PUBLISH_OPTION_NONE);
257 GNUNET_FS_PUBLISH_OPTION_NONE);
258 GNUNET_assert (publish != NULL); 246 GNUNET_assert (publish != NULL);
259} 247}
260 248
@@ -282,8 +270,8 @@ main (int argc, char *argv[])
282 "WARNING", 270 "WARNING",
283#endif 271#endif
284 NULL); 272 NULL);
285 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 273 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
286 argvx, "test-fs-search", "nohelp", options, &run, NULL); 274 "test-fs-search", "nohelp", options, &run, NULL);
287 stop_arm (&p1); 275 stop_arm (&p1);
288 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-search/"); 276 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-search/");
289 return 0; 277 return 0;
diff --git a/src/fs/test_fs_search_persistence.c b/src/fs/test_fs_search_persistence.c
index eceb4d1d5..5c5a6f140 100644
--- a/src/fs/test_fs_search_persistence.c
+++ b/src/fs/test_fs_search_persistence.c
@@ -94,10 +94,7 @@ static void
94restart_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 94restart_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
95{ 95{
96 GNUNET_FS_stop (fs); 96 GNUNET_FS_stop (fs);
97 fs = GNUNET_FS_start (cfg, 97 fs = GNUNET_FS_start (cfg, "test-fs-search-persistence", &progress_cb, NULL,
98 "test-fs-search-persistence",
99 &progress_cb,
100 NULL,
101 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); 98 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
102} 99}
103 100
@@ -143,15 +140,15 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
143 (unsigned long long) event->value.publish.completed, 140 (unsigned long long) event->value.publish.completed,
144 (unsigned long long) event->value.publish.size, 141 (unsigned long long) event->value.publish.size,
145 event->value.publish.specifics.progress.depth, 142 event->value.publish.specifics.progress.depth,
146 (unsigned long long) event->value.publish.specifics. 143 (unsigned long long) event->value.publish.specifics.progress.
147 progress.offset); 144 offset);
148#endif 145#endif
149 break; 146 break;
150 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 147 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
151 kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords); 148 kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords);
152 start = GNUNET_TIME_absolute_get (); 149 start = GNUNET_TIME_absolute_get ();
153 GNUNET_FS_search_start (fs, 150 GNUNET_FS_search_start (fs, kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE,
154 kuri, 1, GNUNET_FS_SEARCH_OPTION_NONE, "search"); 151 "search");
155 GNUNET_FS_uri_destroy (kuri); 152 GNUNET_FS_uri_destroy (kuri);
156 GNUNET_assert (search != NULL); 153 GNUNET_assert (search != NULL);
157 break; 154 break;
@@ -169,25 +166,20 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
169#if VERBOSE 166#if VERBOSE
170 printf ("Search complete.\n"); 167 printf ("Search complete.\n");
171#endif 168#endif
172 GNUNET_SCHEDULER_add_continuation (&abort_search_task, 169 GNUNET_SCHEDULER_add_continuation (&abort_search_task, NULL,
173 NULL,
174 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 170 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
175 break; 171 break;
176 case GNUNET_FS_STATUS_PUBLISH_ERROR: 172 case GNUNET_FS_STATUS_PUBLISH_ERROR:
177 fprintf (stderr, 173 fprintf (stderr, "Error publishing file: %s\n",
178 "Error publishing file: %s\n",
179 event->value.publish.specifics.error.message); 174 event->value.publish.specifics.error.message);
180 GNUNET_break (0); 175 GNUNET_break (0);
181 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 176 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL,
182 NULL,
183 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 177 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
184 break; 178 break;
185 case GNUNET_FS_STATUS_SEARCH_ERROR: 179 case GNUNET_FS_STATUS_SEARCH_ERROR:
186 fprintf (stderr, 180 fprintf (stderr, "Error searching file: %s\n",
187 "Error searching file: %s\n",
188 event->value.search.specifics.error.message); 181 event->value.search.specifics.error.message);
189 GNUNET_SCHEDULER_add_continuation (&abort_search_task, 182 GNUNET_SCHEDULER_add_continuation (&abort_search_task, NULL,
190 NULL,
191 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 183 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
192 break; 184 break;
193 case GNUNET_FS_STATUS_SEARCH_SUSPEND: 185 case GNUNET_FS_STATUS_SEARCH_SUSPEND:
@@ -226,8 +218,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
226 break; 218 break;
227 case GNUNET_FS_STATUS_SEARCH_STOPPED: 219 case GNUNET_FS_STATUS_SEARCH_STOPPED:
228 GNUNET_assert (search == event->value.search.sc); 220 GNUNET_assert (search == event->value.search.sc);
229 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 221 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL,
230 NULL,
231 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 222 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
232 search = NULL; 223 search = NULL;
233 break; 224 break;
@@ -244,12 +235,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
244{ 235{
245 p->cfg = GNUNET_CONFIGURATION_create (); 236 p->cfg = GNUNET_CONFIGURATION_create ();
246#if START_ARM 237#if START_ARM
247 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 238 p->arm_proc =
248 "gnunet-service-arm", 239 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
240 "gnunet-service-arm",
249#if VERBOSE 241#if VERBOSE
250 "-L", "DEBUG", 242 "-L", "DEBUG",
251#endif 243#endif
252 "-c", cfgname, NULL); 244 "-c", cfgname, NULL);
253#endif 245#endif
254 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 246 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
255} 247}
@@ -265,8 +257,7 @@ stop_arm (struct PeerContext *p)
265 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 257 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
266 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 258 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
267 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 259 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
268 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
269 "ARM process %u stopped\n",
270 GNUNET_OS_process_get_pid (p->arm_proc)); 261 GNUNET_OS_process_get_pid (p->arm_proc));
271 GNUNET_OS_process_close (p->arm_proc); 262 GNUNET_OS_process_close (p->arm_proc);
272 p->arm_proc = NULL; 263 p->arm_proc = NULL;
@@ -277,9 +268,8 @@ stop_arm (struct PeerContext *p)
277 268
278 269
279static void 270static void
280run (void *cls, 271run (void *cls, char *const *args, const char *cfgfile,
281 char *const *args, 272 const struct GNUNET_CONFIGURATION_Handle *c)
282 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
283{ 273{
284 const char *keywords[] = { 274 const char *keywords[] = {
285 "down_foo", 275 "down_foo",
@@ -294,10 +284,7 @@ run (void *cls,
294 284
295 cfg = c; 285 cfg = c;
296 setup_peer (&p1, "test_fs_search_data.conf"); 286 setup_peer (&p1, "test_fs_search_data.conf");
297 fs = GNUNET_FS_start (cfg, 287 fs = GNUNET_FS_start (cfg, "test-fs-search-persistence", &progress_cb, NULL,
298 "test-fs-search-persistence",
299 &progress_cb,
300 NULL,
301 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); 288 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
302 GNUNET_assert (NULL != fs); 289 GNUNET_assert (NULL != fs);
303 buf = GNUNET_malloc (FILESIZE); 290 buf = GNUNET_malloc (FILESIZE);
@@ -309,19 +296,16 @@ run (void *cls,
309 bo.anonymity_level = 1; 296 bo.anonymity_level = 1;
310 bo.replication_level = 0; 297 bo.replication_level = 0;
311 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 298 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
312 fi = GNUNET_FS_file_information_create_from_data (fs, 299 fi = GNUNET_FS_file_information_create_from_data (fs, "publish-context",
313 "publish-context", 300 FILESIZE, buf, kuri, meta,
314 FILESIZE, 301 GNUNET_NO, &bo);
315 buf,
316 kuri, meta, GNUNET_NO, &bo);
317 GNUNET_FS_uri_destroy (kuri); 302 GNUNET_FS_uri_destroy (kuri);
318 GNUNET_CONTAINER_meta_data_destroy (meta); 303 GNUNET_CONTAINER_meta_data_destroy (meta);
319 GNUNET_assert (NULL != fi); 304 GNUNET_assert (NULL != fi);
320 start = GNUNET_TIME_absolute_get (); 305 start = GNUNET_TIME_absolute_get ();
321 publish = GNUNET_FS_publish_start (fs, 306 publish =
322 fi, 307 GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL,
323 NULL, NULL, NULL, 308 GNUNET_FS_PUBLISH_OPTION_NONE);
324 GNUNET_FS_PUBLISH_OPTION_NONE);
325 GNUNET_assert (publish != NULL); 309 GNUNET_assert (publish != NULL);
326} 310}
327 311
@@ -350,9 +334,9 @@ main (int argc, char *argv[])
350 "WARNING", 334 "WARNING",
351#endif 335#endif
352 NULL); 336 NULL);
353 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 337 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
354 argvx, "test-fs-search-persistence", 338 "test-fs-search-persistence", "nohelp", options, &run,
355 "nohelp", options, &run, NULL); 339 NULL);
356 stop_arm (&p1); 340 stop_arm (&p1);
357 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-search/"); 341 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-search/");
358 return 0; 342 return 0;
diff --git a/src/fs/test_fs_search_ranking.c b/src/fs/test_fs_search_ranking.c
index b19ff97bf..53522c6fe 100644
--- a/src/fs/test_fs_search_ranking.c
+++ b/src/fs/test_fs_search_ranking.c
@@ -38,8 +38,7 @@ makeName (unsigned int i)
38 char *fn; 38 char *fn;
39 39
40 fn = GNUNET_malloc (strlen ("/tmp/gnunet-fsui-searchranktest/FSUITEST") + 14); 40 fn = GNUNET_malloc (strlen ("/tmp/gnunet-fsui-searchranktest/FSUITEST") + 14);
41 GNUNET_snprintf (fn, 41 GNUNET_snprintf (fn, strlen ("/tmp/gnunet-fsui-searchranktest/FSUITEST") + 14,
42 strlen ("/tmp/gnunet-fsui-searchranktest/FSUITEST") + 14,
43 "/tmp/gnunet-fsui-searchranktest/FSUITEST%u", i); 42 "/tmp/gnunet-fsui-searchranktest/FSUITEST%u", i);
44 GNUNET_disk_directory_create_for_file (NULL, fn); 43 GNUNET_disk_directory_create_for_file (NULL, fn);
45 return fn; 44 return fn;
@@ -159,22 +158,21 @@ main (int argc, char *argv[])
159 GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to start */ 158 GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to start */
160 /* ACTUAL TEST CODE */ 159 /* ACTUAL TEST CODE */
161#endif 160#endif
162 ctx = GNUNET_FSUI_start (NULL, 161 ctx =
163 cfg, "fsuisearchranktest", 32, GNUNET_YES, 162 GNUNET_FSUI_start (NULL, cfg, "fsuisearchranktest", 32, GNUNET_YES,
164 &eventCallback, NULL); 163 &eventCallback, NULL);
165 CHECK (ctx != NULL); 164 CHECK (ctx != NULL);
166 /* upload */ 165 /* upload */
167 fn = makeName (42); 166 fn = makeName (42);
168 GNUNET_disk_file_write (NULL, 167 GNUNET_disk_file_write (NULL, fn, "foo bar test!", strlen ("foo bar test!"),
169 fn, "foo bar test!", strlen ("foo bar test!"), "600"); 168 "600");
170 meta = GNUNET_meta_data_create (); 169 meta = GNUNET_meta_data_create ();
171 kuri = 170 kuri =
172 GNUNET_ECRS_keyword_command_line_to_uri (NULL, 2, 171 GNUNET_ECRS_keyword_command_line_to_uri (NULL, 2,
173 (const char **) keywords); 172 (const char **) keywords);
174 waitForEvent = GNUNET_FSUI_upload_completed; 173 waitForEvent = GNUNET_FSUI_upload_completed;
175 upload = 174 upload =
176 GNUNET_FSUI_upload_start (ctx, 175 GNUNET_FSUI_upload_start (ctx, fn,
177 fn,
178 (GNUNET_FSUI_DirectoryScanCallback) & 176 (GNUNET_FSUI_DirectoryScanCallback) &
179 GNUNET_disk_directory_scan, NULL, 0, 0, 177 GNUNET_disk_directory_scan, NULL, 0, 0,
180 GNUNET_YES, GNUNET_NO, GNUNET_NO, 178 GNUNET_YES, GNUNET_NO, GNUNET_NO,
@@ -191,8 +189,8 @@ main (int argc, char *argv[])
191 prog++; 189 prog++;
192 if (prog == 10000) 190 if (prog == 10000)
193 { 191 {
194 fprintf (stderr, 192 fprintf (stderr, "Upload failed to complete -- last event: %u\n",
195 "Upload failed to complete -- last event: %u\n", lastEvent); 193 lastEvent);
196 } 194 }
197 CHECK (prog < 10000); 195 CHECK (prog < 10000);
198 GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); 196 GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
@@ -211,9 +209,8 @@ main (int argc, char *argv[])
211 CHECK (NULL != search); 209 CHECK (NULL != search);
212 GNUNET_FSUI_search_pause (search); 210 GNUNET_FSUI_search_pause (search);
213 GNUNET_FSUI_search_restart (search); 211 GNUNET_FSUI_search_restart (search);
214 while ((uri == NULL) && 212 while ((uri == NULL) && (availability < 3) && (rank != 2) &&
215 (availability < 3) && 213 (GNUNET_shutdown_test () != GNUNET_YES))
216 (rank != 2) && (GNUNET_shutdown_test () != GNUNET_YES))
217 { 214 {
218 prog++; 215 prog++;
219 CHECK (prog < 10000); 216 CHECK (prog < 10000);
diff --git a/src/fs/test_fs_start_stop.c b/src/fs/test_fs_start_stop.c
index e38a4b965..c65ad2fc1 100644
--- a/src/fs/test_fs_start_stop.c
+++ b/src/fs/test_fs_start_stop.c
@@ -56,12 +56,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
56{ 56{
57 p->cfg = GNUNET_CONFIGURATION_create (); 57 p->cfg = GNUNET_CONFIGURATION_create ();
58#if START_ARM 58#if START_ARM
59 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 59 p->arm_proc =
60 "gnunet-service-arm", 60 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
61 "gnunet-service-arm",
61#if VERBOSE 62#if VERBOSE
62 "-L", "DEBUG", 63 "-L", "DEBUG",
63#endif 64#endif
64 "-c", cfgname, NULL); 65 "-c", cfgname, NULL);
65#endif 66#endif
66 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 67 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
67} 68}
@@ -77,8 +78,7 @@ stop_arm (struct PeerContext *p)
77 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 78 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
78 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 79 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
79 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 80 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
80 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 81 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
81 "ARM process %u stopped\n",
82 GNUNET_OS_process_get_pid (p->arm_proc)); 82 GNUNET_OS_process_get_pid (p->arm_proc));
83 GNUNET_OS_process_close (p->arm_proc); 83 GNUNET_OS_process_close (p->arm_proc);
84 p->arm_proc = NULL; 84 p->arm_proc = NULL;
@@ -89,17 +89,14 @@ stop_arm (struct PeerContext *p)
89 89
90 90
91static void 91static void
92run (void *cls, 92run (void *cls, char *const *args, const char *cfgfile,
93 char *const *args, 93 const struct GNUNET_CONFIGURATION_Handle *cfg)
94 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
95{ 94{
96 struct GNUNET_FS_Handle *fs; 95 struct GNUNET_FS_Handle *fs;
97 96
98 setup_peer (&p1, "test_fs_data.conf"); 97 setup_peer (&p1, "test_fs_data.conf");
99 fs = GNUNET_FS_start (cfg, 98 fs = GNUNET_FS_start (cfg, "test-fs-start-stop", &progress_cb, NULL,
100 "test-fs-start-stop", 99 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
101 &progress_cb,
102 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
103 GNUNET_assert (NULL != fs); 100 GNUNET_assert (NULL != fs);
104 GNUNET_FS_stop (fs); 101 GNUNET_FS_stop (fs);
105} 102}
@@ -128,9 +125,8 @@ main (int argc, char *argv[])
128 "WARNING", 125 "WARNING",
129#endif 126#endif
130 NULL); 127 NULL);
131 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 128 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
132 argvx, "test-fs-start-stop", 129 "test-fs-start-stop", "nohelp", options, &run, NULL);
133 "nohelp", options, &run, NULL);
134 stop_arm (&p1); 130 stop_arm (&p1);
135 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs/"); 131 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs/");
136 return 0; 132 return 0;
diff --git a/src/fs/test_fs_test_lib.c b/src/fs/test_fs_test_lib.c
index 9aa7b2ee3..458d4606b 100644
--- a/src/fs/test_fs_test_lib.c
+++ b/src/fs/test_fs_test_lib.c
@@ -56,8 +56,7 @@ do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
56 } 56 }
57 else 57 else
58 { 58 {
59 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 59 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished download, shutting down\n",
60 "Finished download, shutting down\n",
61 (unsigned long long) FILESIZE); 60 (unsigned long long) FILESIZE);
62 } 61 }
63 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons); 62 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
@@ -74,10 +73,10 @@ do_download (void *cls, const struct GNUNET_FS_Uri *uri)
74 ret = 1; 73 ret = 1;
75 return; 74 return;
76 } 75 }
77 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 76 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n",
78 "Downloading %llu bytes\n", (unsigned long long) FILESIZE); 77 (unsigned long long) FILESIZE);
79 GNUNET_FS_TEST_download (daemons[0], 78 GNUNET_FS_TEST_download (daemons[0], TIMEOUT, 1, SEED, uri, VERBOSE, &do_stop,
80 TIMEOUT, 1, SEED, uri, VERBOSE, &do_stop, NULL); 79 NULL);
81} 80}
82 81
83 82
@@ -91,11 +90,9 @@ do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
91 GNUNET_SCHEDULER_add_now (&do_stop, NULL); 90 GNUNET_SCHEDULER_add_now (&do_stop, NULL);
92 return; 91 return;
93 } 92 }
94 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
95 "Publishing %llu bytes\n", (unsigned long long) FILESIZE); 94 (unsigned long long) FILESIZE);
96 GNUNET_FS_TEST_publish (daemons[0], 95 GNUNET_FS_TEST_publish (daemons[0], TIMEOUT, 1, GNUNET_NO, FILESIZE, SEED,
97 TIMEOUT,
98 1, GNUNET_NO, FILESIZE, SEED,
99 VERBOSE, &do_download, NULL); 96 VERBOSE, &do_download, NULL);
100} 97}
101 98
@@ -112,19 +109,17 @@ do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
112 } 109 }
113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
114 "Daemons started, will now try to connect them\n"); 111 "Daemons started, will now try to connect them\n");
115 GNUNET_FS_TEST_daemons_connect (daemons[0], 112 GNUNET_FS_TEST_daemons_connect (daemons[0], daemons[1], TIMEOUT, &do_publish,
116 daemons[1], TIMEOUT, &do_publish, NULL); 113 NULL);
117} 114}
118 115
119 116
120static void 117static void
121run (void *cls, 118run (void *cls, char *const *args, const char *cfgfile,
122 char *const *args, 119 const struct GNUNET_CONFIGURATION_Handle *cfg)
123 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
124{ 120{
125 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf", 121 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf", TIMEOUT, NUM_DAEMONS,
126 TIMEOUT, 122 daemons, &do_connect, NULL);
127 NUM_DAEMONS, daemons, &do_connect, NULL);
128} 123}
129 124
130 125
@@ -152,8 +147,8 @@ main (int argc, char *argv[])
152 "WARNING", 147 "WARNING",
153#endif 148#endif
154 NULL); 149 NULL);
155 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 150 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
156 argvx, "test-fs-test-lib", "nohelp", options, &run, NULL); 151 "test-fs-test-lib", "nohelp", options, &run, NULL);
157 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); 152 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
158 return ret; 153 return ret;
159} 154}
diff --git a/src/fs/test_fs_unindex.c b/src/fs/test_fs_unindex.c
index 70a9e0bcf..177b687ca 100644
--- a/src/fs/test_fs_unindex.c
+++ b/src/fs/test_fs_unindex.c
@@ -100,16 +100,16 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
100 (unsigned long long) event->value.publish.completed, 100 (unsigned long long) event->value.publish.completed,
101 (unsigned long long) event->value.publish.size, 101 (unsigned long long) event->value.publish.size,
102 event->value.publish.specifics.progress.depth, 102 event->value.publish.specifics.progress.depth,
103 (unsigned long long) event->value.publish.specifics. 103 (unsigned long long) event->value.publish.specifics.progress.
104 progress.offset); 104 offset);
105#endif 105#endif
106 break; 106 break;
107 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 107 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
108 printf ("Publishing complete, %llu kbps.\n", 108 printf ("Publishing complete, %llu kbps.\n",
109 (unsigned long long) (FILESIZE * 1000 / 109 (unsigned long long) (FILESIZE * 1000 /
110 (1 + 110 (1 +
111 GNUNET_TIME_absolute_get_duration 111 GNUNET_TIME_absolute_get_duration (start).
112 (start).rel_value) / 1024)); 112 rel_value) / 1024));
113 start = GNUNET_TIME_absolute_get (); 113 start = GNUNET_TIME_absolute_get ();
114 unindex = GNUNET_FS_unindex_start (fs, fn, "unindex"); 114 unindex = GNUNET_FS_unindex_start (fs, fn, "unindex");
115 GNUNET_assert (unindex != NULL); 115 GNUNET_assert (unindex != NULL);
@@ -118,8 +118,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
118 printf ("Unindex complete, %llu kbps.\n", 118 printf ("Unindex complete, %llu kbps.\n",
119 (unsigned long long) (FILESIZE * 1000 / 119 (unsigned long long) (FILESIZE * 1000 /
120 (1 + 120 (1 +
121 GNUNET_TIME_absolute_get_duration 121 GNUNET_TIME_absolute_get_duration (start).
122 (start).rel_value) / 1024)); 122 rel_value) / 1024));
123 GNUNET_SCHEDULER_add_continuation (&abort_unindex_task, NULL, 123 GNUNET_SCHEDULER_add_continuation (&abort_unindex_task, NULL,
124 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 124 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
125 break; 125 break;
@@ -130,25 +130,21 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
130 (unsigned long long) event->value.unindex.completed, 130 (unsigned long long) event->value.unindex.completed,
131 (unsigned long long) event->value.unindex.size, 131 (unsigned long long) event->value.unindex.size,
132 event->value.unindex.specifics.progress.depth, 132 event->value.unindex.specifics.progress.depth,
133 (unsigned long long) event->value.unindex.specifics. 133 (unsigned long long) event->value.unindex.specifics.progress.
134 progress.offset); 134 offset);
135#endif 135#endif
136 break; 136 break;
137 case GNUNET_FS_STATUS_PUBLISH_ERROR: 137 case GNUNET_FS_STATUS_PUBLISH_ERROR:
138 fprintf (stderr, 138 fprintf (stderr, "Error publishing file: %s\n",
139 "Error publishing file: %s\n",
140 event->value.publish.specifics.error.message); 139 event->value.publish.specifics.error.message);
141 GNUNET_break (0); 140 GNUNET_break (0);
142 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 141 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL,
143 NULL,
144 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 142 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
145 break; 143 break;
146 case GNUNET_FS_STATUS_UNINDEX_ERROR: 144 case GNUNET_FS_STATUS_UNINDEX_ERROR:
147 fprintf (stderr, 145 fprintf (stderr, "Error unindexing file: %s\n",
148 "Error unindexing file: %s\n",
149 event->value.unindex.specifics.error.message); 146 event->value.unindex.specifics.error.message);
150 GNUNET_SCHEDULER_add_continuation (&abort_unindex_task, 147 GNUNET_SCHEDULER_add_continuation (&abort_unindex_task, NULL,
151 NULL,
152 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 148 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
153 break; 149 break;
154 case GNUNET_FS_STATUS_PUBLISH_START: 150 case GNUNET_FS_STATUS_PUBLISH_START:
@@ -174,8 +170,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
174 break; 170 break;
175 case GNUNET_FS_STATUS_UNINDEX_STOPPED: 171 case GNUNET_FS_STATUS_UNINDEX_STOPPED:
176 GNUNET_assert (unindex == event->value.unindex.uc); 172 GNUNET_assert (unindex == event->value.unindex.uc);
177 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 173 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL,
178 NULL,
179 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 174 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
180 break; 175 break;
181 default: 176 default:
@@ -191,12 +186,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
191{ 186{
192 p->cfg = GNUNET_CONFIGURATION_create (); 187 p->cfg = GNUNET_CONFIGURATION_create ();
193#if START_ARM 188#if START_ARM
194 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 189 p->arm_proc =
195 "gnunet-service-arm", 190 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
191 "gnunet-service-arm",
196#if VERBOSE 192#if VERBOSE
197 "-L", "DEBUG", 193 "-L", "DEBUG",
198#endif 194#endif
199 "-c", cfgname, NULL); 195 "-c", cfgname, NULL);
200#endif 196#endif
201 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 197 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
202} 198}
@@ -212,8 +208,7 @@ stop_arm (struct PeerContext *p)
212 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 208 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
213 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 209 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
214 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 210 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
216 "ARM process %u stopped\n",
217 GNUNET_OS_process_get_pid (p->arm_proc)); 212 GNUNET_OS_process_get_pid (p->arm_proc));
218 GNUNET_OS_process_close (p->arm_proc); 213 GNUNET_OS_process_close (p->arm_proc);
219 p->arm_proc = NULL; 214 p->arm_proc = NULL;
@@ -224,9 +219,8 @@ stop_arm (struct PeerContext *p)
224 219
225 220
226static void 221static void
227run (void *cls, 222run (void *cls, char *const *args, const char *cfgfile,
228 char *const *args, 223 const struct GNUNET_CONFIGURATION_Handle *cfg)
229 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
230{ 224{
231 const char *keywords[] = { 225 const char *keywords[] = {
232 "down_foo", 226 "down_foo",
@@ -241,18 +235,14 @@ run (void *cls,
241 235
242 setup_peer (&p1, "test_fs_unindex_data.conf"); 236 setup_peer (&p1, "test_fs_unindex_data.conf");
243 fn = GNUNET_DISK_mktemp ("gnunet-unindex-test-dst"); 237 fn = GNUNET_DISK_mktemp ("gnunet-unindex-test-dst");
244 fs = GNUNET_FS_start (cfg, 238 fs = GNUNET_FS_start (cfg, "test-fs-unindex", &progress_cb, NULL,
245 "test-fs-unindex", 239 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
246 &progress_cb,
247 NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
248 GNUNET_assert (NULL != fs); 240 GNUNET_assert (NULL != fs);
249 buf = GNUNET_malloc (FILESIZE); 241 buf = GNUNET_malloc (FILESIZE);
250 for (i = 0; i < FILESIZE; i++) 242 for (i = 0; i < FILESIZE; i++)
251 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 243 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
252 GNUNET_assert (FILESIZE == 244 GNUNET_assert (FILESIZE ==
253 GNUNET_DISK_fn_write (fn, 245 GNUNET_DISK_fn_write (fn, buf, FILESIZE,
254 buf,
255 FILESIZE,
256 GNUNET_DISK_PERM_USER_READ | 246 GNUNET_DISK_PERM_USER_READ |
257 GNUNET_DISK_PERM_USER_WRITE)); 247 GNUNET_DISK_PERM_USER_WRITE));
258 GNUNET_free (buf); 248 GNUNET_free (buf);
@@ -262,19 +252,16 @@ run (void *cls,
262 bo.anonymity_level = 1; 252 bo.anonymity_level = 1;
263 bo.replication_level = 0; 253 bo.replication_level = 0;
264 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 254 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
265 fi = GNUNET_FS_file_information_create_from_file (fs, 255 fi = GNUNET_FS_file_information_create_from_file (fs, "publish-context", fn,
266 "publish-context", 256 kuri, meta, GNUNET_YES,
267 fn, 257 &bo);
268 kuri,
269 meta, GNUNET_YES, &bo);
270 GNUNET_FS_uri_destroy (kuri); 258 GNUNET_FS_uri_destroy (kuri);
271 GNUNET_CONTAINER_meta_data_destroy (meta); 259 GNUNET_CONTAINER_meta_data_destroy (meta);
272 GNUNET_assert (NULL != fi); 260 GNUNET_assert (NULL != fi);
273 start = GNUNET_TIME_absolute_get (); 261 start = GNUNET_TIME_absolute_get ();
274 publish = GNUNET_FS_publish_start (fs, 262 publish =
275 fi, 263 GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL,
276 NULL, NULL, NULL, 264 GNUNET_FS_PUBLISH_OPTION_NONE);
277 GNUNET_FS_PUBLISH_OPTION_NONE);
278 GNUNET_assert (publish != NULL); 265 GNUNET_assert (publish != NULL);
279} 266}
280 267
@@ -302,8 +289,8 @@ main (int argc, char *argv[])
302 "WARNING", 289 "WARNING",
303#endif 290#endif
304 NULL); 291 NULL);
305 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 292 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
306 argvx, "test-fs-unindex", "nohelp", options, &run, NULL); 293 "test-fs-unindex", "nohelp", options, &run, NULL);
307 stop_arm (&p1); 294 stop_arm (&p1);
308 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-unindex/"); 295 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-unindex/");
309 if (NULL != fn) 296 if (NULL != fn)
diff --git a/src/fs/test_fs_unindex_persistence.c b/src/fs/test_fs_unindex_persistence.c
index 191dec57d..4fcd1445f 100644
--- a/src/fs/test_fs_unindex_persistence.c
+++ b/src/fs/test_fs_unindex_persistence.c
@@ -102,10 +102,7 @@ static void
102restart_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 102restart_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
103{ 103{
104 GNUNET_FS_stop (fs); 104 GNUNET_FS_stop (fs);
105 fs = GNUNET_FS_start (cfg, 105 fs = GNUNET_FS_start (cfg, "test-fs-unindex-persistence", &progress_cb, NULL,
106 "test-fs-unindex-persistence",
107 &progress_cb,
108 NULL,
109 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); 106 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
110} 107}
111 108
@@ -144,16 +141,16 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
144 (unsigned long long) event->value.publish.completed, 141 (unsigned long long) event->value.publish.completed,
145 (unsigned long long) event->value.publish.size, 142 (unsigned long long) event->value.publish.size,
146 event->value.publish.specifics.progress.depth, 143 event->value.publish.specifics.progress.depth,
147 (unsigned long long) event->value.publish.specifics. 144 (unsigned long long) event->value.publish.specifics.progress.
148 progress.offset); 145 offset);
149#endif 146#endif
150 break; 147 break;
151 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 148 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
152 printf ("Publishing complete, %llu kbps.\n", 149 printf ("Publishing complete, %llu kbps.\n",
153 (unsigned long long) (FILESIZE * 1000 / 150 (unsigned long long) (FILESIZE * 1000 /
154 (1 + 151 (1 +
155 GNUNET_TIME_absolute_get_duration 152 GNUNET_TIME_absolute_get_duration (start).
156 (start).rel_value) / 1024)); 153 rel_value) / 1024));
157 start = GNUNET_TIME_absolute_get (); 154 start = GNUNET_TIME_absolute_get ();
158 unindex = GNUNET_FS_unindex_start (fs, fn, "unindex"); 155 unindex = GNUNET_FS_unindex_start (fs, fn, "unindex");
159 GNUNET_assert (unindex != NULL); 156 GNUNET_assert (unindex != NULL);
@@ -162,8 +159,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
162 printf ("Unindex complete, %llu kbps.\n", 159 printf ("Unindex complete, %llu kbps.\n",
163 (unsigned long long) (FILESIZE * 1000 / 160 (unsigned long long) (FILESIZE * 1000 /
164 (1 + 161 (1 +
165 GNUNET_TIME_absolute_get_duration 162 GNUNET_TIME_absolute_get_duration (start).
166 (start).rel_value) / 1024)); 163 rel_value) / 1024));
167 GNUNET_SCHEDULER_add_continuation (&abort_unindex_task, NULL, 164 GNUNET_SCHEDULER_add_continuation (&abort_unindex_task, NULL,
168 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 165 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
169 break; 166 break;
@@ -175,8 +172,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
175 (unsigned long long) event->value.unindex.completed, 172 (unsigned long long) event->value.unindex.completed,
176 (unsigned long long) event->value.unindex.size, 173 (unsigned long long) event->value.unindex.size,
177 event->value.unindex.specifics.progress.depth, 174 event->value.unindex.specifics.progress.depth,
178 (unsigned long long) event->value.unindex.specifics. 175 (unsigned long long) event->value.unindex.specifics.progress.
179 progress.offset); 176 offset);
180#endif 177#endif
181 break; 178 break;
182 case GNUNET_FS_STATUS_PUBLISH_SUSPEND: 179 case GNUNET_FS_STATUS_PUBLISH_SUSPEND:
@@ -199,20 +196,16 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
199 unindex = event->value.unindex.uc; 196 unindex = event->value.unindex.uc;
200 return "unindex"; 197 return "unindex";
201 case GNUNET_FS_STATUS_PUBLISH_ERROR: 198 case GNUNET_FS_STATUS_PUBLISH_ERROR:
202 fprintf (stderr, 199 fprintf (stderr, "Error publishing file: %s\n",
203 "Error publishing file: %s\n",
204 event->value.publish.specifics.error.message); 200 event->value.publish.specifics.error.message);
205 GNUNET_break (0); 201 GNUNET_break (0);
206 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 202 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL,
207 NULL,
208 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 203 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
209 break; 204 break;
210 case GNUNET_FS_STATUS_UNINDEX_ERROR: 205 case GNUNET_FS_STATUS_UNINDEX_ERROR:
211 fprintf (stderr, 206 fprintf (stderr, "Error unindexing file: %s\n",
212 "Error unindexing file: %s\n",
213 event->value.unindex.specifics.error.message); 207 event->value.unindex.specifics.error.message);
214 GNUNET_SCHEDULER_add_continuation (&abort_unindex_task, 208 GNUNET_SCHEDULER_add_continuation (&abort_unindex_task, NULL,
215 NULL,
216 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 209 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
217 break; 210 break;
218 case GNUNET_FS_STATUS_PUBLISH_START: 211 case GNUNET_FS_STATUS_PUBLISH_START:
@@ -239,8 +232,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
239 break; 232 break;
240 case GNUNET_FS_STATUS_UNINDEX_STOPPED: 233 case GNUNET_FS_STATUS_UNINDEX_STOPPED:
241 GNUNET_assert (unindex == event->value.unindex.uc); 234 GNUNET_assert (unindex == event->value.unindex.uc);
242 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, 235 GNUNET_SCHEDULER_add_continuation (&abort_publish_task, NULL,
243 NULL,
244 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 236 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
245 break; 237 break;
246 default: 238 default:
@@ -256,12 +248,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
256{ 248{
257 p->cfg = GNUNET_CONFIGURATION_create (); 249 p->cfg = GNUNET_CONFIGURATION_create ();
258#if START_ARM 250#if START_ARM
259 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 251 p->arm_proc =
260 "gnunet-service-arm", 252 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
253 "gnunet-service-arm",
261#if VERBOSE 254#if VERBOSE
262 "-L", "DEBUG", 255 "-L", "DEBUG",
263#endif 256#endif
264 "-c", cfgname, NULL); 257 "-c", cfgname, NULL);
265#endif 258#endif
266 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 259 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
267} 260}
@@ -277,8 +270,7 @@ stop_arm (struct PeerContext *p)
277 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 270 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
278 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 271 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
279 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 272 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
280 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
281 "ARM process %u stopped\n",
282 GNUNET_OS_process_get_pid (p->arm_proc)); 274 GNUNET_OS_process_get_pid (p->arm_proc));
283 GNUNET_OS_process_close (p->arm_proc); 275 GNUNET_OS_process_close (p->arm_proc);
284 p->arm_proc = NULL; 276 p->arm_proc = NULL;
@@ -289,9 +281,8 @@ stop_arm (struct PeerContext *p)
289 281
290 282
291static void 283static void
292run (void *cls, 284run (void *cls, char *const *args, const char *cfgfile,
293 char *const *args, 285 const struct GNUNET_CONFIGURATION_Handle *c)
294 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
295{ 286{
296 const char *keywords[] = { 287 const char *keywords[] = {
297 "down_foo", 288 "down_foo",
@@ -307,19 +298,14 @@ run (void *cls,
307 cfg = c; 298 cfg = c;
308 setup_peer (&p1, "test_fs_unindex_data.conf"); 299 setup_peer (&p1, "test_fs_unindex_data.conf");
309 fn = GNUNET_DISK_mktemp ("gnunet-unindex-test-dst"); 300 fn = GNUNET_DISK_mktemp ("gnunet-unindex-test-dst");
310 fs = GNUNET_FS_start (cfg, 301 fs = GNUNET_FS_start (cfg, "test-fs-unindex-persistence", &progress_cb, NULL,
311 "test-fs-unindex-persistence",
312 &progress_cb,
313 NULL,
314 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); 302 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
315 GNUNET_assert (NULL != fs); 303 GNUNET_assert (NULL != fs);
316 buf = GNUNET_malloc (FILESIZE); 304 buf = GNUNET_malloc (FILESIZE);
317 for (i = 0; i < FILESIZE; i++) 305 for (i = 0; i < FILESIZE; i++)
318 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 306 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
319 GNUNET_assert (FILESIZE == 307 GNUNET_assert (FILESIZE ==
320 GNUNET_DISK_fn_write (fn, 308 GNUNET_DISK_fn_write (fn, buf, FILESIZE,
321 buf,
322 FILESIZE,
323 GNUNET_DISK_PERM_USER_READ | 309 GNUNET_DISK_PERM_USER_READ |
324 GNUNET_DISK_PERM_USER_WRITE)); 310 GNUNET_DISK_PERM_USER_WRITE));
325 GNUNET_free (buf); 311 GNUNET_free (buf);
@@ -329,19 +315,16 @@ run (void *cls,
329 bo.anonymity_level = 1; 315 bo.anonymity_level = 1;
330 bo.replication_level = 0; 316 bo.replication_level = 0;
331 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 317 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME);
332 fi = GNUNET_FS_file_information_create_from_file (fs, 318 fi = GNUNET_FS_file_information_create_from_file (fs, "publish-context", fn,
333 "publish-context", 319 kuri, meta, GNUNET_YES,
334 fn, 320 &bo);
335 kuri,
336 meta, GNUNET_YES, &bo);
337 GNUNET_FS_uri_destroy (kuri); 321 GNUNET_FS_uri_destroy (kuri);
338 GNUNET_CONTAINER_meta_data_destroy (meta); 322 GNUNET_CONTAINER_meta_data_destroy (meta);
339 GNUNET_assert (NULL != fi); 323 GNUNET_assert (NULL != fi);
340 start = GNUNET_TIME_absolute_get (); 324 start = GNUNET_TIME_absolute_get ();
341 publish = GNUNET_FS_publish_start (fs, 325 publish =
342 fi, 326 GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL,
343 NULL, NULL, NULL, 327 GNUNET_FS_PUBLISH_OPTION_NONE);
344 GNUNET_FS_PUBLISH_OPTION_NONE);
345 GNUNET_assert (publish != NULL); 328 GNUNET_assert (publish != NULL);
346} 329}
347 330
@@ -369,8 +352,8 @@ main (int argc, char *argv[])
369 "WARNING", 352 "WARNING",
370#endif 353#endif
371 NULL); 354 NULL);
372 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 355 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
373 argvx, "test-fs-unindex", "nohelp", options, &run, NULL); 356 "test-fs-unindex", "nohelp", options, &run, NULL);
374 stop_arm (&p1); 357 stop_arm (&p1);
375 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-unindex/"); 358 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-unindex/");
376 if (NULL != fn) 359 if (NULL != fn)
diff --git a/src/fs/test_fs_uri.c b/src/fs/test_fs_uri.c
index e8f6ed70f..d226147f9 100644
--- a/src/fs/test_fs_uri.c
+++ b/src/fs/test_fs_uri.c
@@ -209,8 +209,9 @@ testNamespace (int i)
209 } 209 }
210 210
211 uri = GNUNET_FS_uri_to_string (ret); 211 uri = GNUNET_FS_uri_to_string (ret);
212 if (0 != strcmp (uri, 212 if (0 !=
213 "gnunet://fs/sks/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820/test")) 213 strcmp (uri,
214 "gnunet://fs/sks/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820/test"))
214 { 215 {
215 GNUNET_FS_uri_destroy (ret); 216 GNUNET_FS_uri_destroy (ret);
216 GNUNET_free (uri); 217 GNUNET_free (uri);
@@ -284,8 +285,9 @@ testFile (int i)
284 } 285 }
285 286
286 uri = GNUNET_FS_uri_to_string (ret); 287 uri = GNUNET_FS_uri_to_string (ret);
287 if (0 != strcmp (uri, 288 if (0 !=
288 "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42")) 289 strcmp (uri,
290 "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42"))
289 { 291 {
290 GNUNET_free (uri); 292 GNUNET_free (uri);
291 GNUNET_FS_uri_destroy (ret); 293 GNUNET_FS_uri_destroy (ret);
diff --git a/src/fs/test_gnunet_service_fs_migration.c b/src/fs/test_gnunet_service_fs_migration.c
index 9a209521f..a5570e1d4 100644
--- a/src/fs/test_gnunet_service_fs_migration.c
+++ b/src/fs/test_gnunet_service_fs_migration.c
@@ -69,8 +69,7 @@ do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
69 1000LL / del.rel_value); 69 1000LL / del.rel_value);
70 fprintf (stdout, "Download speed was %s/s\n", fancy); 70 fprintf (stdout, "Download speed was %s/s\n", fancy);
71 GNUNET_free (fancy); 71 GNUNET_free (fancy);
72 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 72 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished download, shutting down\n",
73 "Finished download, shutting down\n",
74 (unsigned long long) FILESIZE); 73 (unsigned long long) FILESIZE);
75 } 74 }
76 else 75 else
@@ -90,17 +89,17 @@ do_download (void *cls, const char *emsg)
90 if (emsg != NULL) 89 if (emsg != NULL)
91 { 90 {
92 GNUNET_FS_TEST_daemons_stop (2, daemons); 91 GNUNET_FS_TEST_daemons_stop (2, daemons);
93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 92 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to stop source daemon: %s\n",
94 "Failed to stop source daemon: %s\n", emsg); 93 emsg);
95 GNUNET_FS_uri_destroy (uri); 94 GNUNET_FS_uri_destroy (uri);
96 ok = 1; 95 ok = 1;
97 return; 96 return;
98 } 97 }
99 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 98 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n",
100 "Downloading %llu bytes\n", (unsigned long long) FILESIZE); 99 (unsigned long long) FILESIZE);
101 start_time = GNUNET_TIME_absolute_get (); 100 start_time = GNUNET_TIME_absolute_get ();
102 GNUNET_FS_TEST_download (daemons[0], 101 GNUNET_FS_TEST_download (daemons[0], TIMEOUT, 1, SEED, uri, VERBOSE, &do_stop,
103 TIMEOUT, 1, SEED, uri, VERBOSE, &do_stop, NULL); 102 NULL);
104 GNUNET_FS_uri_destroy (uri); 103 GNUNET_FS_uri_destroy (uri);
105} 104}
106 105
@@ -147,11 +146,9 @@ do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
147 ok = 1; 146 ok = 1;
148 return; 147 return;
149 } 148 }
150 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
151 "Publishing %llu bytes\n", (unsigned long long) FILESIZE); 150 (unsigned long long) FILESIZE);
152 GNUNET_FS_TEST_publish (daemons[1], 151 GNUNET_FS_TEST_publish (daemons[1], TIMEOUT, 1, GNUNET_NO, FILESIZE, SEED,
153 TIMEOUT,
154 1, GNUNET_NO, FILESIZE, SEED,
155 VERBOSE, &do_wait, NULL); 152 VERBOSE, &do_wait, NULL);
156} 153}
157 154
@@ -168,15 +165,14 @@ do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
168 } 165 }
169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
170 "Daemons started, will now try to connect them\n"); 167 "Daemons started, will now try to connect them\n");
171 GNUNET_FS_TEST_daemons_connect (daemons[0], 168 GNUNET_FS_TEST_daemons_connect (daemons[0], daemons[1], TIMEOUT, &do_publish,
172 daemons[1], TIMEOUT, &do_publish, NULL); 169 NULL);
173} 170}
174 171
175 172
176static void 173static void
177run (void *cls, 174run (void *cls, char *const *args, const char *cfgfile,
178 char *const *args, 175 const struct GNUNET_CONFIGURATION_Handle *cfg)
179 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
180{ 176{
181 GNUNET_FS_TEST_daemons_start ("test_gnunet_service_fs_migration_data.conf", 177 GNUNET_FS_TEST_daemons_start ("test_gnunet_service_fs_migration_data.conf",
182 TIMEOUT, 2, daemons, &do_connect, NULL); 178 TIMEOUT, 2, daemons, &do_connect, NULL);
@@ -207,9 +203,9 @@ main (int argc, char *argv[])
207 "WARNING", 203 "WARNING",
208#endif 204#endif
209 NULL); 205 NULL);
210 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 206 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
211 argvx, "test-gnunet-service-fs-migration", 207 "test-gnunet-service-fs-migration", "nohelp", options,
212 "nohelp", options, &run, NULL); 208 &run, NULL);
213 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/"); 209 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/");
214 return ok; 210 return ok;
215} 211}
diff --git a/src/fs/test_gnunet_service_fs_p2p.c b/src/fs/test_gnunet_service_fs_p2p.c
index c48f98666..aece0e80a 100644
--- a/src/fs/test_gnunet_service_fs_p2p.c
+++ b/src/fs/test_gnunet_service_fs_p2p.c
@@ -65,8 +65,7 @@ do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
65 1000LL / del.rel_value); 65 1000LL / del.rel_value);
66 fprintf (stdout, "Download speed was %s/s\n", fancy); 66 fprintf (stdout, "Download speed was %s/s\n", fancy);
67 GNUNET_free (fancy); 67 GNUNET_free (fancy);
68 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 68 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished download, shutting down\n",
69 "Finished download, shutting down\n",
70 (unsigned long long) FILESIZE); 69 (unsigned long long) FILESIZE);
71 } 70 }
72 else 71 else
@@ -89,11 +88,11 @@ do_download (void *cls, const struct GNUNET_FS_Uri *uri)
89 ok = 1; 88 ok = 1;
90 return; 89 return;
91 } 90 }
92 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 91 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n",
93 "Downloading %llu bytes\n", (unsigned long long) FILESIZE); 92 (unsigned long long) FILESIZE);
94 start_time = GNUNET_TIME_absolute_get (); 93 start_time = GNUNET_TIME_absolute_get ();
95 GNUNET_FS_TEST_download (daemons[0], 94 GNUNET_FS_TEST_download (daemons[0], TIMEOUT, 1, SEED, uri, VERBOSE, &do_stop,
96 TIMEOUT, 1, SEED, uri, VERBOSE, &do_stop, NULL); 95 NULL);
97} 96}
98 97
99 98
@@ -108,11 +107,9 @@ do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
108 ok = 1; 107 ok = 1;
109 return; 108 return;
110 } 109 }
111 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
112 "Publishing %llu bytes\n", (unsigned long long) FILESIZE); 111 (unsigned long long) FILESIZE);
113 GNUNET_FS_TEST_publish (daemons[1], 112 GNUNET_FS_TEST_publish (daemons[1], TIMEOUT, 1, GNUNET_NO, FILESIZE, SEED,
114 TIMEOUT,
115 1, GNUNET_NO, FILESIZE, SEED,
116 VERBOSE, &do_download, NULL); 113 VERBOSE, &do_download, NULL);
117} 114}
118 115
@@ -123,19 +120,17 @@ do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
123 GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)); 120 GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE));
124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
125 "Daemons started, will now try to connect them\n"); 122 "Daemons started, will now try to connect them\n");
126 GNUNET_FS_TEST_daemons_connect (daemons[0], 123 GNUNET_FS_TEST_daemons_connect (daemons[0], daemons[1], TIMEOUT, &do_publish,
127 daemons[1], TIMEOUT, &do_publish, NULL); 124 NULL);
128} 125}
129 126
130 127
131static void 128static void
132run (void *cls, 129run (void *cls, char *const *args, const char *cfgfile,
133 char *const *args, 130 const struct GNUNET_CONFIGURATION_Handle *cfg)
134 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
135{ 131{
136 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf", 132 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf", TIMEOUT, NUM_DAEMONS,
137 TIMEOUT, 133 daemons, &do_connect, NULL);
138 NUM_DAEMONS, daemons, &do_connect, NULL);
139} 134}
140 135
141 136
@@ -163,9 +158,9 @@ main (int argc, char *argv[])
163 "WARNING", 158 "WARNING",
164#endif 159#endif
165 NULL); 160 NULL);
166 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 161 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
167 argvx, "test-gnunet-service-fs-p2p", 162 "test-gnunet-service-fs-p2p", "nohelp", options, &run,
168 "nohelp", options, &run, NULL); 163 NULL);
169 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); 164 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
170 return ok; 165 return ok;
171} 166}
diff --git a/src/hello/hello.c b/src/hello/hello.c
index 0df888c21..5d64d8f5a 100644
--- a/src/hello/hello.c
+++ b/src/hello/hello.c
@@ -77,8 +77,8 @@ struct GNUNET_HELLO_Message
77size_t 77size_t
78GNUNET_HELLO_add_address (const char *tname, 78GNUNET_HELLO_add_address (const char *tname,
79 struct GNUNET_TIME_Absolute expiration, 79 struct GNUNET_TIME_Absolute expiration,
80 const void *addr, 80 const void *addr, uint16_t addr_len, char *target,
81 uint16_t addr_len, char *target, size_t max) 81 size_t max)
82{ 82{
83 uint16_t alen; 83 uint16_t alen;
84 size_t slen; 84 size_t slen;
@@ -245,9 +245,9 @@ GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg,
245 memcpy (&expire, 245 memcpy (&expire,
246 &inptr[esize - alen - sizeof (struct GNUNET_TIME_AbsoluteNBO)], 246 &inptr[esize - alen - sizeof (struct GNUNET_TIME_AbsoluteNBO)],
247 sizeof (struct GNUNET_TIME_AbsoluteNBO)); 247 sizeof (struct GNUNET_TIME_AbsoluteNBO));
248 iret = it (it_cls, 248 iret =
249 inptr, 249 it (it_cls, inptr, GNUNET_TIME_absolute_ntoh (expire),
250 GNUNET_TIME_absolute_ntoh (expire), &inptr[esize - alen], alen); 250 &inptr[esize - alen], alen);
251 if (iret == GNUNET_SYSERR) 251 if (iret == GNUNET_SYSERR)
252 { 252 {
253 if (ret != NULL) 253 if (ret != NULL)
@@ -280,15 +280,13 @@ struct ExpireContext
280 280
281 281
282static int 282static int
283get_match_exp (void *cls, 283get_match_exp (void *cls, const char *tname,
284 const char *tname, 284 struct GNUNET_TIME_Absolute expiration, const void *addr,
285 struct GNUNET_TIME_Absolute expiration, 285 uint16_t addrlen)
286 const void *addr, uint16_t addrlen)
287{ 286{
288 struct ExpireContext *ec = cls; 287 struct ExpireContext *ec = cls;
289 288
290 if ((addrlen == ec->addrlen) && 289 if ((addrlen == ec->addrlen) && (0 == memcmp (addr, ec->addr, addrlen)) &&
291 (0 == memcmp (addr, ec->addr, addrlen)) &&
292 (0 == strcmp (tname, ec->tname))) 290 (0 == strcmp (tname, ec->tname)))
293 { 291 {
294 ec->found = GNUNET_YES; 292 ec->found = GNUNET_YES;
@@ -313,10 +311,9 @@ struct MergeContext
313 311
314 312
315static int 313static int
316copy_latest (void *cls, 314copy_latest (void *cls, const char *tname,
317 const char *tname, 315 struct GNUNET_TIME_Absolute expiration, const void *addr,
318 struct GNUNET_TIME_Absolute expiration, 316 uint16_t addrlen)
319 const void *addr, uint16_t addrlen)
320{ 317{
321 struct MergeContext *mc = cls; 318 struct MergeContext *mc = cls;
322 struct ExpireContext ec; 319 struct ExpireContext ec;
@@ -331,11 +328,9 @@ copy_latest (void *cls,
331 ((ec.expiration.abs_value == expiration.abs_value) && 328 ((ec.expiration.abs_value == expiration.abs_value) &&
332 (mc->take_equal == GNUNET_YES))) 329 (mc->take_equal == GNUNET_YES)))
333 { 330 {
334 mc->ret += GNUNET_HELLO_add_address (tname, 331 mc->ret +=
335 expiration, 332 GNUNET_HELLO_add_address (tname, expiration, addr, addrlen,
336 addr, 333 &mc->buf[mc->ret], mc->max - mc->ret);
337 addrlen,
338 &mc->buf[mc->ret], mc->max - mc->ret);
339 } 334 }
340 return GNUNET_OK; 335 return GNUNET_OK;
341} 336}
@@ -394,10 +389,9 @@ struct DeltaContext
394 389
395 390
396static int 391static int
397delta_match (void *cls, 392delta_match (void *cls, const char *tname,
398 const char *tname, 393 struct GNUNET_TIME_Absolute expiration, const void *addr,
399 struct GNUNET_TIME_Absolute expiration, 394 uint16_t addrlen)
400 const void *addr, uint16_t addrlen)
401{ 395{
402 struct DeltaContext *dc = cls; 396 struct DeltaContext *dc = cls;
403 int ret; 397 int ret;
@@ -407,8 +401,8 @@ delta_match (void *cls,
407 ec.addrlen = addrlen; 401 ec.addrlen = addrlen;
408 ec.found = GNUNET_NO; 402 ec.found = GNUNET_NO;
409 ec.tname = tname; 403 ec.tname = tname;
410 GNUNET_HELLO_iterate_addresses (dc->old_hello, 404 GNUNET_HELLO_iterate_addresses (dc->old_hello, GNUNET_NO, &get_match_exp,
411 GNUNET_NO, &get_match_exp, &ec); 405 &ec);
412 if ((ec.found == GNUNET_YES) && 406 if ((ec.found == GNUNET_YES) &&
413 ((ec.expiration.abs_value > expiration.abs_value) || 407 ((ec.expiration.abs_value > expiration.abs_value) ||
414 (ec.expiration.abs_value >= dc->expiration_limit.abs_value))) 408 (ec.expiration.abs_value >= dc->expiration_limit.abs_value)))
@@ -553,18 +547,16 @@ struct EqualsContext
553 547
554 548
555static int 549static int
556find_other_matching (void *cls, 550find_other_matching (void *cls, const char *tname,
557 const char *tname, 551 struct GNUNET_TIME_Absolute expiration, const void *addr,
558 struct GNUNET_TIME_Absolute expiration, 552 uint16_t addrlen)
559 const void *addr, uint16_t addrlen)
560{ 553{
561 struct EqualsContext *ec = cls; 554 struct EqualsContext *ec = cls;
562 555
563 if (expiration.abs_value < ec->expiration_limit.abs_value) 556 if (expiration.abs_value < ec->expiration_limit.abs_value)
564 return GNUNET_YES; 557 return GNUNET_YES;
565 if ((addrlen == ec->addrlen) && 558 if ((addrlen == ec->addrlen) && (0 == strcmp (tname, ec->tname)) &&
566 (0 == strcmp (tname, 559 (0 == memcmp (addr, ec->addr, addrlen)))
567 ec->tname)) && (0 == memcmp (addr, ec->addr, addrlen)))
568 { 560 {
569 ec->found = GNUNET_YES; 561 ec->found = GNUNET_YES;
570 if (expiration.abs_value < ec->expiration.abs_value) 562 if (expiration.abs_value < ec->expiration.abs_value)
@@ -576,10 +568,9 @@ find_other_matching (void *cls,
576 568
577 569
578static int 570static int
579find_matching (void *cls, 571find_matching (void *cls, const char *tname,
580 const char *tname, 572 struct GNUNET_TIME_Absolute expiration, const void *addr,
581 struct GNUNET_TIME_Absolute expiration, 573 uint16_t addrlen)
582 const void *addr, uint16_t addrlen)
583{ 574{
584 struct EqualsContext *ec = cls; 575 struct EqualsContext *ec = cls;
585 576
@@ -616,16 +607,15 @@ find_matching (void *cls,
616 * do not match at all 607 * do not match at all
617 */ 608 */
618struct GNUNET_TIME_Absolute 609struct GNUNET_TIME_Absolute
619GNUNET_HELLO_equals (const struct 610GNUNET_HELLO_equals (const struct GNUNET_HELLO_Message *h1,
620 GNUNET_HELLO_Message *h1, 611 const struct GNUNET_HELLO_Message *h2,
621 const struct 612 struct GNUNET_TIME_Absolute now)
622 GNUNET_HELLO_Message *h2, struct GNUNET_TIME_Absolute now)
623{ 613{
624 struct EqualsContext ec; 614 struct EqualsContext ec;
625 615
626 if (0 != memcmp (&h1->publicKey, 616 if (0 !=
627 &h2->publicKey, 617 memcmp (&h1->publicKey, &h2->publicKey,
628 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))) 618 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
629 return GNUNET_TIME_UNIT_ZERO_ABS; 619 return GNUNET_TIME_UNIT_ZERO_ABS;
630 ec.expiration_limit = now; 620 ec.expiration_limit = now;
631 ec.result = GNUNET_TIME_UNIT_FOREVER_ABS; 621 ec.result = GNUNET_TIME_UNIT_FOREVER_ABS;
diff --git a/src/hello/test_hello.c b/src/hello/test_hello.c
index b6a9dc681..c9bf96791 100644
--- a/src/hello/test_hello.c
+++ b/src/hello/test_hello.c
@@ -41,19 +41,18 @@ my_addr_gen (void *cls, size_t max, void *buf)
41#endif 41#endif
42 if (0 == *i) 42 if (0 == *i)
43 return 0; 43 return 0;
44 ret = GNUNET_HELLO_add_address ("test", 44 ret =
45 GNUNET_TIME_absolute_get (), 45 GNUNET_HELLO_add_address ("test", GNUNET_TIME_absolute_get (),
46 "address_information", *i, buf, max); 46 "address_information", *i, buf, max);
47 (*i)--; 47 (*i)--;
48 return ret; 48 return ret;
49} 49}
50 50
51 51
52static int 52static int
53check_addr (void *cls, 53check_addr (void *cls, const char *tname,
54 const char *tname, 54 struct GNUNET_TIME_Absolute expiration, const void *addr,
55 struct GNUNET_TIME_Absolute expiration, 55 uint16_t addrlen)
56 const void *addr, uint16_t addrlen)
57{ 56{
58 unsigned int *i = cls; 57 unsigned int *i = cls;
59 58
@@ -71,10 +70,9 @@ check_addr (void *cls,
71 70
72 71
73static int 72static int
74remove_some (void *cls, 73remove_some (void *cls, const char *tname,
75 const char *tname, 74 struct GNUNET_TIME_Absolute expiration, const void *addr,
76 struct GNUNET_TIME_Absolute expiration, 75 uint16_t addrlen)
77 const void *addr, uint16_t addrlen)
78{ 76{
79 unsigned int *i = cls; 77 unsigned int *i = cls;
80 78
@@ -118,8 +116,8 @@ main (int argc, char *argv[])
118 fprintf (stderr, "Testing address iteration (empty set)...\n"); 116 fprintf (stderr, "Testing address iteration (empty set)...\n");
119#endif 117#endif
120 GNUNET_assert (NULL == 118 GNUNET_assert (NULL ==
121 GNUNET_HELLO_iterate_addresses (msg1, 119 GNUNET_HELLO_iterate_addresses (msg1, GNUNET_NO, &check_addr,
122 GNUNET_NO, &check_addr, &i)); 120 &i));
123 121
124#if VERBOSE 122#if VERBOSE
125 fprintf (stderr, "Testing HELLO creation (with one address)...\n"); 123 fprintf (stderr, "Testing HELLO creation (with one address)...\n");
@@ -134,8 +132,8 @@ main (int argc, char *argv[])
134#endif 132#endif
135 i = 1; 133 i = 1;
136 GNUNET_assert (NULL == 134 GNUNET_assert (NULL ==
137 GNUNET_HELLO_iterate_addresses (msg2, 135 GNUNET_HELLO_iterate_addresses (msg2, GNUNET_NO, &check_addr,
138 GNUNET_NO, &check_addr, &i)); 136 &i));
139 GNUNET_assert (i == 0); 137 GNUNET_assert (i == 0);
140 138
141#if VERBOSE 139#if VERBOSE
@@ -158,8 +156,8 @@ main (int argc, char *argv[])
158#endif 156#endif
159 i = 3; 157 i = 3;
160 GNUNET_assert (NULL == 158 GNUNET_assert (NULL ==
161 GNUNET_HELLO_iterate_addresses (msg3, 159 GNUNET_HELLO_iterate_addresses (msg3, GNUNET_NO, &check_addr,
162 GNUNET_NO, &check_addr, &i)); 160 &i));
163 GNUNET_assert (i == 0); 161 GNUNET_assert (i == 0);
164 162
165#if VERBOSE 163#if VERBOSE
@@ -170,8 +168,8 @@ main (int argc, char *argv[])
170 168
171 i = 3; 169 i = 3;
172 GNUNET_assert (NULL == 170 GNUNET_assert (NULL ==
173 GNUNET_HELLO_iterate_addresses (msg1, 171 GNUNET_HELLO_iterate_addresses (msg1, GNUNET_NO, &check_addr,
174 GNUNET_NO, &check_addr, &i)); 172 &i));
175 GNUNET_assert (i == 0); 173 GNUNET_assert (i == 0);
176 GNUNET_free (msg1); 174 GNUNET_free (msg1);
177 175
@@ -184,8 +182,8 @@ main (int argc, char *argv[])
184 GNUNET_assert (i == 0); 182 GNUNET_assert (i == 0);
185 i = 1; 183 i = 1;
186 GNUNET_assert (NULL == 184 GNUNET_assert (NULL ==
187 GNUNET_HELLO_iterate_addresses (msg1, 185 GNUNET_HELLO_iterate_addresses (msg1, GNUNET_NO, &check_addr,
188 GNUNET_NO, &check_addr, &i)); 186 &i));
189 GNUNET_assert (i == 0); 187 GNUNET_assert (i == 0);
190 GNUNET_free (msg1); 188 GNUNET_free (msg1);
191 189
@@ -193,8 +191,8 @@ main (int argc, char *argv[])
193 fprintf (stderr, "Testing delta address iteration...\n"); 191 fprintf (stderr, "Testing delta address iteration...\n");
194#endif 192#endif
195 i = 2; 193 i = 2;
196 GNUNET_HELLO_iterate_new_addresses (msg3, 194 GNUNET_HELLO_iterate_new_addresses (msg3, msg2, startup_time, &check_addr,
197 msg2, startup_time, &check_addr, &i); 195 &i);
198 GNUNET_assert (i == 0); 196 GNUNET_assert (i == 0);
199 GNUNET_free (msg2); 197 GNUNET_free (msg2);
200 GNUNET_free (msg3); 198 GNUNET_free (msg3);
diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c
index c49aec765..9d47dfa9c 100644
--- a/src/hostlist/gnunet-daemon-hostlist.c
+++ b/src/hostlist/gnunet-daemon-hostlist.c
@@ -128,8 +128,7 @@ struct GNUNET_HOSTLIST_ADV_Message
128static struct GNUNET_PeerIdentity me; 128static struct GNUNET_PeerIdentity me;
129 129
130static void 130static void
131core_init (void *cls, 131core_init (void *cls, struct GNUNET_CORE_Handle *server,
132 struct GNUNET_CORE_Handle *server,
133 const struct GNUNET_PeerIdentity *my_identity, 132 const struct GNUNET_PeerIdentity *my_identity,
134 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) 133 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
135{ 134{
@@ -140,8 +139,7 @@ core_init (void *cls,
140 * Core handler for p2p hostlist advertisements 139 * Core handler for p2p hostlist advertisements
141 */ 140 */
142static int 141static int
143advertisement_handler (void *cls, 142advertisement_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
144 const struct GNUNET_PeerIdentity *peer,
145 const struct GNUNET_MessageHeader *message, 143 const struct GNUNET_MessageHeader *message,
146 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 144 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
147{ 145{
@@ -158,9 +156,7 @@ advertisement_handler (void *cls,
158 * @param atsi performance data 156 * @param atsi performance data
159 */ 157 */
160static void 158static void
161connect_handler (void *cls, 159connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
162 const struct
163 GNUNET_PeerIdentity *peer,
164 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 160 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
165{ 161{
166 if (0 == memcmp (&me, peer, sizeof (struct GNUNET_PeerIdentity))) 162 if (0 == memcmp (&me, peer, sizeof (struct GNUNET_PeerIdentity)))
@@ -236,9 +232,8 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
236 * @param cfg configuration 232 * @param cfg configuration
237 */ 233 */
238static void 234static void
239run (void *cls, 235run (void *cls, char *const *args, const char *cfgfile,
240 char *const *args, 236 const struct GNUNET_CONFIGURATION_Handle *cfg)
241 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
242{ 237{
243 static const struct GNUNET_CORE_MessageHandler learn_handlers[] = { 238 static const struct GNUNET_CORE_MessageHandler learn_handlers[] = {
244 {&advertisement_handler, GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, 0}, 239 {&advertisement_handler, GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, 0},
@@ -263,20 +258,16 @@ run (void *cls,
263 258
264 stats = GNUNET_STATISTICS_create ("hostlist", cfg); 259 stats = GNUNET_STATISTICS_create ("hostlist", cfg);
265 260
266 core = GNUNET_CORE_connect (cfg, 261 core =
267 1, 262 GNUNET_CORE_connect (cfg, 1, NULL, &core_init, &connect_handler,
268 NULL, 263 &disconnect_handler, NULL, NULL, GNUNET_NO, NULL,
269 &core_init, 264 GNUNET_NO,
270 &connect_handler, &disconnect_handler, NULL, 265 learning ? learn_handlers : no_learn_handlers);
271 NULL, GNUNET_NO,
272 NULL, GNUNET_NO,
273 learning ? learn_handlers : no_learn_handlers);
274 266
275 if (bootstrapping) 267 if (bootstrapping)
276 { 268 {
277 GNUNET_HOSTLIST_client_start (cfg, stats, 269 GNUNET_HOSTLIST_client_start (cfg, stats, &client_ch, &client_dh,
278 &client_ch, &client_dh, &client_adv_handler, 270 &client_adv_handler, learning);
279 learning);
280 } 271 }
281 272
282#if HAVE_MHD 273#if HAVE_MHD
@@ -286,8 +277,8 @@ run (void *cls,
286 advertising); 277 advertising);
287 } 278 }
288#endif 279#endif
289 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 280 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task,
290 &cleaning_task, NULL); 281 NULL);
291 282
292 if (NULL == core) 283 if (NULL == core)
293 { 284 {
@@ -333,12 +324,11 @@ main (int argc, char *const *argv)
333 int ret; 324 int ret;
334 325
335 GNUNET_log_setup ("hostlist", "WARNING", NULL); 326 GNUNET_log_setup ("hostlist", "WARNING", NULL);
336 ret = (GNUNET_OK == 327 ret =
337 GNUNET_PROGRAM_run (argc, 328 (GNUNET_OK ==
338 argv, 329 GNUNET_PROGRAM_run (argc, argv, "hostlist",
339 "hostlist", 330 _("GNUnet hostlist server and client"), options,
340 _("GNUnet hostlist server and client"), 331 &run, NULL)) ? 0 : 1;
341 options, &run, NULL)) ? 0 : 1;
342 332
343 return ret; 333 return ret;
344} 334}
diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c
index 422855f0e..c049dceea 100644
--- a/src/hostlist/hostlist-client.c
+++ b/src/hostlist/hostlist-client.c
@@ -366,8 +366,8 @@ get_bootstrap_server ()
366 size_t pos; 366 size_t pos;
367 367
368 if (GNUNET_OK != 368 if (GNUNET_OK !=
369 GNUNET_CONFIGURATION_get_value_string (cfg, 369 GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST", "SERVERS",
370 "HOSTLIST", "SERVERS", &servers)) 370 &servers))
371 { 371 {
372 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 372 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
373 _ 373 _
@@ -453,8 +453,8 @@ download_get_url ()
453 current_hostlist = NULL; 453 current_hostlist = NULL;
454 return get_bootstrap_server (); 454 return get_bootstrap_server ();
455 } 455 }
456 index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 456 index =
457 linked_list_size); 457 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, linked_list_size);
458 counter = 0; 458 counter = 0;
459 pos = linked_list_head; 459 pos = linked_list_head;
460 while (counter < index) 460 while (counter < index)
@@ -462,8 +462,8 @@ download_get_url ()
462 pos = pos->next; 462 pos = pos->next;
463 counter++; 463 counter++;
464 } 464 }
465 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 465 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using learned hostlist `%s'\n",
466 "Using learned hostlist `%s'\n", pos->hostlist_uri); 466 pos->hostlist_uri);
467 current_hostlist = pos; 467 current_hostlist = pos;
468 return strdup (pos->hostlist_uri); 468 return strdup (pos->hostlist_uri);
469} 469}
@@ -585,11 +585,10 @@ insert_hostlist ()
585 linked_list_size--; 585 linked_list_size--;
586 GNUNET_free (lowest_quality); 586 GNUNET_free (lowest_quality);
587 } 587 }
588 GNUNET_CONTAINER_DLL_insert (linked_list_head, 588 GNUNET_CONTAINER_DLL_insert (linked_list_head, linked_list_tail,
589 linked_list_tail, hostlist_to_test); 589 hostlist_to_test);
590 linked_list_size++; 590 linked_list_size++;
591 GNUNET_STATISTICS_set (stats, 591 GNUNET_STATISTICS_set (stats, gettext_noop ("# advertised hostlist URIs"),
592 gettext_noop ("# advertised hostlist URIs"),
593 linked_list_size, GNUNET_NO); 592 linked_list_size, GNUNET_NO);
594 stat_testing_hostlist = GNUNET_NO; 593 stat_testing_hostlist = GNUNET_NO;
595} 594}
@@ -679,15 +678,13 @@ clean_up ()
679 mret = curl_multi_remove_handle (multi, curl); 678 mret = curl_multi_remove_handle (multi, curl);
680 if (mret != CURLM_OK) 679 if (mret != CURLM_OK)
681 { 680 {
682 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 681 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
683 _("%s failed at %s:%d: `%s'\n"),
684 "curl_multi_remove_handle", __FILE__, __LINE__, 682 "curl_multi_remove_handle", __FILE__, __LINE__,
685 curl_multi_strerror (mret)); 683 curl_multi_strerror (mret));
686 } 684 }
687 mret = curl_multi_cleanup (multi); 685 mret = curl_multi_cleanup (multi);
688 if (mret != CURLM_OK) 686 if (mret != CURLM_OK)
689 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 687 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
690 _("%s failed at %s:%d: `%s'\n"),
691 "curl_multi_cleanup", __FILE__, __LINE__, 688 "curl_multi_cleanup", __FILE__, __LINE__,
692 curl_multi_strerror (mret)); 689 curl_multi_strerror (mret));
693 multi = NULL; 690 multi = NULL;
@@ -711,8 +708,8 @@ clean_up ()
711 * @param cls closure, unused 708 * @param cls closure, unused
712 * @param tc task context, unused 709 * @param tc task context, unused
713 */ 710 */
714static void 711static void task_download (void *cls,
715task_download (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 712 const struct GNUNET_SCHEDULER_TaskContext *tc);
716 713
717 714
718/** 715/**
@@ -739,8 +736,7 @@ download_prepare ()
739 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); 736 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
740 if (mret != CURLM_OK) 737 if (mret != CURLM_OK)
741 { 738 {
742 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 739 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
743 _("%s failed at %s:%d: `%s'\n"),
744 "curl_multi_fdset", __FILE__, __LINE__, 740 "curl_multi_fdset", __FILE__, __LINE__,
745 curl_multi_strerror (mret)); 741 curl_multi_strerror (mret));
746 clean_up (); 742 clean_up ();
@@ -749,8 +745,7 @@ download_prepare ()
749 mret = curl_multi_timeout (multi, &timeout); 745 mret = curl_multi_timeout (multi, &timeout);
750 if (mret != CURLM_OK) 746 if (mret != CURLM_OK)
751 { 747 {
752 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 748 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
753 _("%s failed at %s:%d: `%s'\n"),
754 "curl_multi_timeout", __FILE__, __LINE__, 749 "curl_multi_timeout", __FILE__, __LINE__,
755 curl_multi_strerror (mret)); 750 curl_multi_strerror (mret));
756 clean_up (); 751 clean_up ();
@@ -768,10 +763,10 @@ download_prepare ()
768 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 763 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
769 "Scheduling task for hostlist download using cURL\n"); 764 "Scheduling task for hostlist download using cURL\n");
770#endif 765#endif
771 ti_download 766 ti_download =
772 = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 767 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
773 GNUNET_SCHEDULER_NO_TASK, 768 GNUNET_SCHEDULER_NO_TASK, rtime, grs, gws,
774 rtime, grs, gws, &task_download, multi); 769 &task_download, multi);
775 GNUNET_NETWORK_fdset_destroy (gws); 770 GNUNET_NETWORK_fdset_destroy (gws);
776 GNUNET_NETWORK_fdset_destroy (grs); 771 GNUNET_NETWORK_fdset_destroy (grs);
777} 772}
@@ -844,10 +839,8 @@ task_download (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
844 (msg->data.result != CURLE_GOT_NOTHING)) 839 (msg->data.result != CURLE_GOT_NOTHING))
845 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 840 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
846 _("%s failed for `%s' at %s:%d: `%s'\n"), 841 _("%s failed for `%s' at %s:%d: `%s'\n"),
847 "curl_multi_perform", 842 "curl_multi_perform", current_url, __FILE__, __LINE__,
848 current_url, 843 curl_easy_strerror (msg->data.result));
849 __FILE__,
850 __LINE__, curl_easy_strerror (msg->data.result));
851 else 844 else
852 { 845 {
853 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 846 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -880,8 +873,7 @@ task_download (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
880 873
881 if (mret != CURLM_OK) 874 if (mret != CURLM_OK)
882 { 875 {
883 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 876 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("%s failed at %s:%d: `%s'\n"),
884 _("%s failed at %s:%d: `%s'\n"),
885 "curl_multi_perform", __FILE__, __LINE__, 877 "curl_multi_perform", __FILE__, __LINE__,
886 curl_multi_strerror (mret)); 878 curl_multi_strerror (mret));
887 clean_up (); 879 clean_up ();
@@ -921,8 +913,8 @@ download_hostlist ()
921 stat_bytes_downloaded = 0; 913 stat_bytes_downloaded = 0;
922 914
923 GNUNET_STATISTICS_update (stats, 915 GNUNET_STATISTICS_update (stats,
924 gettext_noop ("# hostlist downloads initiated"), 916 gettext_noop ("# hostlist downloads initiated"), 1,
925 1, GNUNET_NO); 917 GNUNET_NO);
926 if (proxy != NULL) 918 if (proxy != NULL)
927 CURL_EASY_SETOPT (curl, CURLOPT_PROXY, proxy); 919 CURL_EASY_SETOPT (curl, CURLOPT_PROXY, proxy);
928 download_pos = 0; 920 download_pos = 0;
@@ -971,14 +963,12 @@ download_hostlist ()
971 mret = curl_multi_add_handle (multi, curl); 963 mret = curl_multi_add_handle (multi, curl);
972 if (mret != CURLM_OK) 964 if (mret != CURLM_OK)
973 { 965 {
974 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 966 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
975 _("%s failed at %s:%d: `%s'\n"),
976 "curl_multi_add_handle", __FILE__, __LINE__, 967 "curl_multi_add_handle", __FILE__, __LINE__,
977 curl_multi_strerror (mret)); 968 curl_multi_strerror (mret));
978 mret = curl_multi_cleanup (multi); 969 mret = curl_multi_cleanup (multi);
979 if (mret != CURLM_OK) 970 if (mret != CURLM_OK)
980 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 971 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
981 _("%s failed at %s:%d: `%s'\n"),
982 "curl_multi_cleanup", __FILE__, __LINE__, 972 "curl_multi_cleanup", __FILE__, __LINE__,
983 curl_multi_strerror (mret)); 973 curl_multi_strerror (mret));
984 multi = NULL; 974 multi = NULL;
@@ -1104,8 +1094,9 @@ task_hostlist_saving (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1104 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1094 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1105 _("Hostlists will be saved to file again in %llums\n"), 1095 _("Hostlists will be saved to file again in %llums\n"),
1106 (unsigned long long) SAVING_INTERVALL.rel_value); 1096 (unsigned long long) SAVING_INTERVALL.rel_value);
1107 ti_saving_task = GNUNET_SCHEDULER_add_delayed (SAVING_INTERVALL, 1097 ti_saving_task =
1108 &task_hostlist_saving, NULL); 1098 GNUNET_SCHEDULER_add_delayed (SAVING_INTERVALL, &task_hostlist_saving,
1099 NULL);
1109} 1100}
1110 1101
1111 1102
@@ -1117,16 +1108,13 @@ task_hostlist_saving (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1117 * @param atsi performance data 1108 * @param atsi performance data
1118 */ 1109 */
1119static void 1110static void
1120handler_connect (void *cls, 1111handler_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
1121 const struct
1122 GNUNET_PeerIdentity *peer,
1123 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 1112 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1124{ 1113{
1125 GNUNET_assert (stat_connection_count < UINT_MAX); 1114 GNUNET_assert (stat_connection_count < UINT_MAX);
1126 stat_connection_count++; 1115 stat_connection_count++;
1127 GNUNET_STATISTICS_update (stats, 1116 GNUNET_STATISTICS_update (stats, gettext_noop ("# active connections"), 1,
1128 gettext_noop ("# active connections"), 1117 GNUNET_NO);
1129 1, GNUNET_NO);
1130} 1118}
1131 1119
1132 1120
@@ -1141,9 +1129,8 @@ handler_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
1141{ 1129{
1142 GNUNET_assert (stat_connection_count > 0); 1130 GNUNET_assert (stat_connection_count > 0);
1143 stat_connection_count--; 1131 stat_connection_count--;
1144 GNUNET_STATISTICS_update (stats, 1132 GNUNET_STATISTICS_update (stats, gettext_noop ("# active connections"), -1,
1145 gettext_noop ("# active connections"), 1133 GNUNET_NO);
1146 -1, GNUNET_NO);
1147} 1134}
1148 1135
1149 1136
@@ -1158,8 +1145,7 @@ handler_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
1158 * GNUNET_SYSERR to close it (signal serious error) 1145 * GNUNET_SYSERR to close it (signal serious error)
1159 */ 1146 */
1160static int 1147static int
1161handler_advertisement (void *cls, 1148handler_advertisement (void *cls, const struct GNUNET_PeerIdentity *peer,
1162 const struct GNUNET_PeerIdentity *peer,
1163 const struct GNUNET_MessageHeader *message, 1149 const struct GNUNET_MessageHeader *message,
1164 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 1150 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1165{ 1151{
@@ -1217,9 +1203,9 @@ handler_advertisement (void *cls,
1217 1203
1218 stat_testing_hostlist = GNUNET_YES; 1204 stat_testing_hostlist = GNUNET_YES;
1219 stat_testing_allowed = GNUNET_NO; 1205 stat_testing_allowed = GNUNET_NO;
1220 ti_testing_intervall_task = GNUNET_SCHEDULER_add_delayed (TESTING_INTERVAL, 1206 ti_testing_intervall_task =
1221 &task_testing_intervall_reset, 1207 GNUNET_SCHEDULER_add_delayed (TESTING_INTERVAL,
1222 NULL); 1208 &task_testing_intervall_reset, NULL);
1223 1209
1224 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1225 "Testing new hostlist advertisements is locked for the next %u ms\n", 1211 "Testing new hostlist advertisements is locked for the next %u ms\n",
@@ -1255,9 +1241,8 @@ primary_task (void *cls, int success)
1255 1241
1256 1242
1257static int 1243static int
1258process_stat (void *cls, 1244process_stat (void *cls, const char *subsystem, const char *name,
1259 const char *subsystem, 1245 uint64_t value, int is_persistent)
1260 const char *name, uint64_t value, int is_persistent)
1261{ 1246{
1262 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1247 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1263 _("Initial time between hostlist downloads is %llums\n"), 1248 _("Initial time between hostlist downloads is %llums\n"),
@@ -1286,9 +1271,8 @@ load_hostlist_file ()
1286 uint32_t counter; 1271 uint32_t counter;
1287 1272
1288 if (GNUNET_OK != 1273 if (GNUNET_OK !=
1289 GNUNET_CONFIGURATION_get_value_filename (cfg, 1274 GNUNET_CONFIGURATION_get_value_filename (cfg, "HOSTLIST", "HOSTLISTFILE",
1290 "HOSTLIST", 1275 &filename))
1291 "HOSTLISTFILE", &filename))
1292 { 1276 {
1293 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1277 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1294 _ 1278 _
@@ -1321,9 +1305,8 @@ load_hostlist_file ()
1321 1305
1322 counter = 0; 1306 counter = 0;
1323 while ((GNUNET_OK == GNUNET_BIO_read_string (rh, "url", &uri, MAX_URL_LEN)) && 1307 while ((GNUNET_OK == GNUNET_BIO_read_string (rh, "url", &uri, MAX_URL_LEN)) &&
1324 (NULL != uri) && 1308 (NULL != uri) && (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &times_used))
1325 (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &times_used)) && 1309 && (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &quality)) &&
1326 (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &quality)) &&
1327 (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &last_used)) && 1310 (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &last_used)) &&
1328 (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &created)) && 1311 (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &created)) &&
1329 (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &hellos_returned))) 1312 (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &hellos_returned)))
@@ -1347,13 +1330,11 @@ load_hostlist_file ()
1347 break; 1330 break;
1348 } 1331 }
1349 1332
1350 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1333 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("%u hostlist URIs loaded from file\n"),
1351 _("%u hostlist URIs loaded from file\n"), counter); 1334 counter);
1352 GNUNET_STATISTICS_set (stats, 1335 GNUNET_STATISTICS_set (stats, gettext_noop ("# hostlist URIs read from file"),
1353 gettext_noop ("# hostlist URIs read from file"),
1354 counter, GNUNET_YES); 1336 counter, GNUNET_YES);
1355 GNUNET_STATISTICS_set (stats, 1337 GNUNET_STATISTICS_set (stats, gettext_noop ("# advertised hostlist URIs"),
1356 gettext_noop ("# advertised hostlist URIs"),
1357 linked_list_size, GNUNET_NO); 1338 linked_list_size, GNUNET_NO);
1358 1339
1359 GNUNET_free_non_null (uri); 1340 GNUNET_free_non_null (uri);
@@ -1379,9 +1360,8 @@ save_hostlist_file (int shutdown)
1379 uint32_t counter; 1360 uint32_t counter;
1380 1361
1381 if (GNUNET_OK != 1362 if (GNUNET_OK !=
1382 GNUNET_CONFIGURATION_get_value_filename (cfg, 1363 GNUNET_CONFIGURATION_get_value_filename (cfg, "HOSTLIST", "HOSTLISTFILE",
1383 "HOSTLIST", 1364 &filename))
1384 "HOSTLISTFILE", &filename))
1385 { 1365 {
1386 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1366 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1387 _ 1367 _
@@ -1404,8 +1384,7 @@ save_hostlist_file (int shutdown)
1404 GNUNET_free (filename); 1384 GNUNET_free (filename);
1405 return; 1385 return;
1406 } 1386 }
1407 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1387 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Writing %u hostlist URIs to `%s'\n"),
1408 _("Writing %u hostlist URIs to `%s'\n"),
1409 linked_list_size, filename); 1388 linked_list_size, filename);
1410 /* add code to write hostlists to file using bio */ 1389 /* add code to write hostlists to file using bio */
1411 ok = GNUNET_YES; 1390 ok = GNUNET_YES;
@@ -1419,12 +1398,9 @@ save_hostlist_file (int shutdown)
1419 } 1398 }
1420 if (GNUNET_YES == ok) 1399 if (GNUNET_YES == ok)
1421 { 1400 {
1422 if ((GNUNET_OK != 1401 if ((GNUNET_OK != GNUNET_BIO_write_string (wh, pos->hostlist_uri)) ||
1423 GNUNET_BIO_write_string (wh, pos->hostlist_uri)) || 1402 (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pos->times_used)) ||
1424 (GNUNET_OK != 1403 (GNUNET_OK != GNUNET_BIO_write_int64 (wh, pos->quality)) ||
1425 GNUNET_BIO_write_int32 (wh, pos->times_used)) ||
1426 (GNUNET_OK !=
1427 GNUNET_BIO_write_int64 (wh, pos->quality)) ||
1428 (GNUNET_OK != 1404 (GNUNET_OK !=
1429 GNUNET_BIO_write_int64 (wh, pos->time_last_usage.abs_value)) || 1405 GNUNET_BIO_write_int64 (wh, pos->time_last_usage.abs_value)) ||
1430 (GNUNET_OK != 1406 (GNUNET_OK !=
@@ -1480,8 +1456,8 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
1480 cfg = c; 1456 cfg = c;
1481 stats = st; 1457 stats = st;
1482 if (GNUNET_OK != 1458 if (GNUNET_OK !=
1483 GNUNET_CONFIGURATION_get_value_string (cfg, 1459 GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST", "HTTP-PROXY",
1484 "HOSTLIST", "HTTP-PROXY", &proxy)) 1460 &proxy))
1485 proxy = NULL; 1461 proxy = NULL;
1486 stat_learning = learn; 1462 stat_learning = learn;
1487 *ch = &handler_connect; 1463 *ch = &handler_connect;
@@ -1501,18 +1477,18 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
1501 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1477 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1502 _("Hostlists will be saved to file again in %llums\n"), 1478 _("Hostlists will be saved to file again in %llums\n"),
1503 (unsigned long long) SAVING_INTERVALL.rel_value); 1479 (unsigned long long) SAVING_INTERVALL.rel_value);
1504 ti_saving_task = GNUNET_SCHEDULER_add_delayed (SAVING_INTERVALL, 1480 ti_saving_task =
1505 &task_hostlist_saving, NULL); 1481 GNUNET_SCHEDULER_add_delayed (SAVING_INTERVALL, &task_hostlist_saving,
1482 NULL);
1506 } 1483 }
1507 else 1484 else
1508 { 1485 {
1509 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1486 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1510 _("Learning is not enabled on this peer\n")); 1487 _("Learning is not enabled on this peer\n"));
1511 *msgh = NULL; 1488 *msgh = NULL;
1512 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, 1489 if (GNUNET_OK ==
1513 "HOSTLIST", 1490 GNUNET_CONFIGURATION_get_value_filename (cfg, "HOSTLIST",
1514 "HOSTLISTFILE", 1491 "HOSTLISTFILE", &filename))
1515 &filename))
1516 { 1492 {
1517 if (GNUNET_YES == GNUNET_DISK_file_test (filename)) 1493 if (GNUNET_YES == GNUNET_DISK_file_test (filename))
1518 { 1494 {
@@ -1529,8 +1505,7 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
1529 } 1505 }
1530 GNUNET_free (filename); 1506 GNUNET_free (filename);
1531 } 1507 }
1532 GNUNET_STATISTICS_get (stats, 1508 GNUNET_STATISTICS_get (stats, "hostlist",
1533 "hostlist",
1534 gettext_noop 1509 gettext_noop
1535 ("# milliseconds between hostlist downloads"), 1510 ("# milliseconds between hostlist downloads"),
1536 GNUNET_TIME_UNIT_MINUTES, &primary_task, &process_stat, 1511 GNUNET_TIME_UNIT_MINUTES, &primary_task, &process_stat,
diff --git a/src/hostlist/hostlist-server.c b/src/hostlist/hostlist-server.c
index e30b3c1e0..e48b6a4ac 100644
--- a/src/hostlist/hostlist-server.c
+++ b/src/hostlist/hostlist-server.c
@@ -123,15 +123,15 @@ finish_response (struct HostSet *results)
123 "Creating hostlist response with %u bytes\n", 123 "Creating hostlist response with %u bytes\n",
124 (unsigned int) results->size); 124 (unsigned int) results->size);
125#endif 125#endif
126 response = MHD_create_response_from_data (results->size, 126 response =
127 results->data, MHD_YES, MHD_NO); 127 MHD_create_response_from_data (results->size, results->data, MHD_YES,
128 MHD_NO);
128 if ((daemon_handle_v4 == NULL) && (daemon_handle_v6 == NULL)) 129 if ((daemon_handle_v4 == NULL) && (daemon_handle_v6 == NULL))
129 { 130 {
130 MHD_destroy_response (response); 131 MHD_destroy_response (response);
131 response = NULL; 132 response = NULL;
132 } 133 }
133 GNUNET_STATISTICS_set (stats, 134 GNUNET_STATISTICS_set (stats, gettext_noop ("bytes in hostlist"),
134 gettext_noop ("bytes in hostlist"),
135 results->size, GNUNET_YES); 135 results->size, GNUNET_YES);
136 GNUNET_free (results); 136 GNUNET_free (results);
137} 137}
@@ -148,18 +148,17 @@ finish_response (struct HostSet *results)
148 * @return GNUNET_SYSERR to stop iterating (unless expiration has occured) 148 * @return GNUNET_SYSERR to stop iterating (unless expiration has occured)
149 */ 149 */
150static int 150static int
151check_has_addr (void *cls, 151check_has_addr (void *cls, const char *tname,
152 const char *tname, 152 struct GNUNET_TIME_Absolute expiration, const void *addr,
153 struct GNUNET_TIME_Absolute expiration, 153 uint16_t addrlen)
154 const void *addr, uint16_t addrlen)
155{ 154{
156 int *arg = cls; 155 int *arg = cls;
157 156
158 if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0) 157 if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0)
159 { 158 {
160 GNUNET_STATISTICS_update (stats, 159 GNUNET_STATISTICS_update (stats,
161 gettext_noop ("expired addresses encountered"), 160 gettext_noop ("expired addresses encountered"), 1,
162 1, GNUNET_YES); 161 GNUNET_YES);
163 return GNUNET_YES; /* ignore this address */ 162 return GNUNET_YES; /* ignore this address */
164 } 163 }
165 *arg = GNUNET_YES; 164 *arg = GNUNET_YES;
@@ -172,8 +171,7 @@ check_has_addr (void *cls,
172 * hostlist response construction. 171 * hostlist response construction.
173 */ 172 */
174static void 173static void
175host_processor (void *cls, 174host_processor (void *cls, const struct GNUNET_PeerIdentity *peer,
176 const struct GNUNET_PeerIdentity *peer,
177 const struct GNUNET_HELLO_Message *hello, const char *err_msg) 175 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
178{ 176{
179 struct HostSet *results = cls; 177 struct HostSet *results = cls;
@@ -229,8 +227,8 @@ host_processor (void *cls,
229 } 227 }
230#if DEBUG_HOSTLIST_SERVER 228#if DEBUG_HOSTLIST_SERVER
231 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 229 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
232 "Adding peer `%s' to hostlist (%u bytes)\n", 230 "Adding peer `%s' to hostlist (%u bytes)\n", GNUNET_i2s (peer),
233 GNUNET_i2s (peer), (unsigned int) s); 231 (unsigned int) s);
234#endif 232#endif
235 GNUNET_array_grow (results->data, results->size, old + s); 233 GNUNET_array_grow (results->data, results->size, old + s);
236 memcpy (&results->data[old], hello, s); 234 memcpy (&results->data[old], hello, s);
@@ -242,8 +240,8 @@ host_processor (void *cls,
242 * Hostlist access policy (very permissive, allows everything). 240 * Hostlist access policy (very permissive, allows everything).
243 */ 241 */
244static int 242static int
245accept_policy_callback (void *cls, 243accept_policy_callback (void *cls, const struct sockaddr *addr,
246 const struct sockaddr *addr, socklen_t addrlen) 244 socklen_t addrlen)
247{ 245{
248 if (NULL == response) 246 if (NULL == response)
249 { 247 {
@@ -261,12 +259,9 @@ accept_policy_callback (void *cls,
261 * Main request handler. 259 * Main request handler.
262 */ 260 */
263static int 261static int
264access_handler_callback (void *cls, 262access_handler_callback (void *cls, struct MHD_Connection *connection,
265 struct MHD_Connection *connection, 263 const char *url, const char *method,
266 const char *url, 264 const char *version, const char *upload_data,
267 const char *method,
268 const char *version,
269 const char *upload_data,
270 size_t * upload_data_size, void **con_cls) 265 size_t * upload_data_size, void **con_cls)
271{ 266{
272 static int dummy; 267 static int dummy;
@@ -312,8 +307,7 @@ access_handler_callback (void *cls,
312 return MHD_NO; /* internal error, no response yet */ 307 return MHD_NO; /* internal error, no response yet */
313 } 308 }
314 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received request for our hostlist\n")); 309 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received request for our hostlist\n"));
315 GNUNET_STATISTICS_update (stats, 310 GNUNET_STATISTICS_update (stats, gettext_noop ("hostlist requests processed"),
316 gettext_noop ("hostlist requests processed"),
317 1, GNUNET_YES); 311 1, GNUNET_YES);
318 return MHD_queue_response (connection, MHD_HTTP_OK, response); 312 return MHD_queue_response (connection, MHD_HTTP_OK, response);
319} 313}
@@ -353,11 +347,11 @@ adv_transmit_ready (void *cls, size_t size, void *buf)
353 "Sent advertisement message: Copied %u bytes into buffer!\n", 347 "Sent advertisement message: Copied %u bytes into buffer!\n",
354 (unsigned int) transmission_size); 348 (unsigned int) transmission_size);
355 hostlist_adv_count++; 349 hostlist_adv_count++;
356 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 350 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " # Sent advertisement message: %u\n",
357 " # Sent advertisement message: %u\n", hostlist_adv_count); 351 hostlist_adv_count);
358 GNUNET_STATISTICS_update (stats, 352 GNUNET_STATISTICS_update (stats,
359 gettext_noop ("# hostlist advertisements send"), 353 gettext_noop ("# hostlist advertisements send"), 1,
360 1, GNUNET_NO); 354 GNUNET_NO);
361 return transmission_size; 355 return transmission_size;
362} 356}
363 357
@@ -370,9 +364,7 @@ adv_transmit_ready (void *cls, size_t size, void *buf)
370 * @param atsi performance data 364 * @param atsi performance data
371 */ 365 */
372static void 366static void
373connect_handler (void *cls, 367connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
374 const struct
375 GNUNET_PeerIdentity *peer,
376 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 368 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
377{ 369{
378 size_t size; 370 size_t size;
@@ -397,13 +389,10 @@ connect_handler (void *cls,
397 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 389 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
398 "Asked core to transmit advertisement message with a size of %u bytes to peer `%s'\n", 390 "Asked core to transmit advertisement message with a size of %u bytes to peer `%s'\n",
399 size, GNUNET_i2s (peer)); 391 size, GNUNET_i2s (peer));
400 if (NULL == GNUNET_CORE_notify_transmit_ready (core, 392 if (NULL ==
401 GNUNET_YES, 393 GNUNET_CORE_notify_transmit_ready (core, GNUNET_YES, 0,
402 0, 394 GNUNET_ADV_TIMEOUT, peer, size,
403 GNUNET_ADV_TIMEOUT, 395 &adv_transmit_ready, NULL))
404 peer,
405 size,
406 &adv_transmit_ready, NULL))
407 { 396 {
408 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 397 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
409 _("Advertisement message could not be queued by core\n")); 398 _("Advertisement message could not be queued by core\n"));
@@ -433,8 +422,7 @@ disconnect_handler (void *cls, const struct GNUNET_PeerIdentity *peer)
433 * @param err_msg NULL if successful, otherwise contains error message 422 * @param err_msg NULL if successful, otherwise contains error message
434 */ 423 */
435static void 424static void
436process_notify (void *cls, 425process_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
437 const struct GNUNET_PeerIdentity *peer,
438 const struct GNUNET_HELLO_Message *hello, const char *err_msg) 426 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
439{ 427{
440 struct HostSet *results; 428 struct HostSet *results;
@@ -451,18 +439,17 @@ process_notify (void *cls,
451 } 439 }
452 results = GNUNET_malloc (sizeof (struct HostSet)); 440 results = GNUNET_malloc (sizeof (struct HostSet));
453 GNUNET_assert (peerinfo != NULL); 441 GNUNET_assert (peerinfo != NULL);
454 pitr = GNUNET_PEERINFO_iterate (peerinfo, 442 pitr =
455 NULL, 443 GNUNET_PEERINFO_iterate (peerinfo, NULL, GNUNET_TIME_UNIT_MINUTES,
456 GNUNET_TIME_UNIT_MINUTES, 444 &host_processor, results);
457 &host_processor, results);
458} 445}
459 446
460/** 447/**
461 * Function that queries MHD's select sets and 448 * Function that queries MHD's select sets and
462 * starts the task waiting for them. 449 * starts the task waiting for them.
463 */ 450 */
464static GNUNET_SCHEDULER_TaskIdentifier 451static GNUNET_SCHEDULER_TaskIdentifier prepare_daemon (struct MHD_Daemon
465prepare_daemon (struct MHD_Daemon *daemon_handle); 452 *daemon_handle);
466 453
467 454
468/** 455/**
@@ -524,9 +511,10 @@ prepare_daemon (struct MHD_Daemon *daemon_handle)
524 GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1); 511 GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1);
525 GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1); 512 GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1);
526 GNUNET_NETWORK_fdset_copy_native (wes, &es, max + 1); 513 GNUNET_NETWORK_fdset_copy_native (wes, &es, max + 1);
527 ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, 514 ret =
528 GNUNET_SCHEDULER_NO_TASK, 515 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
529 tv, wrs, wws, &run_daemon, daemon_handle); 516 GNUNET_SCHEDULER_NO_TASK, tv, wrs, wws,
517 &run_daemon, daemon_handle);
530 GNUNET_NETWORK_fdset_destroy (wrs); 518 GNUNET_NETWORK_fdset_destroy (wrs);
531 GNUNET_NETWORK_fdset_destroy (wws); 519 GNUNET_NETWORK_fdset_destroy (wws);
532 GNUNET_NETWORK_fdset_destroy (wes); 520 GNUNET_NETWORK_fdset_destroy (wes);
@@ -568,9 +556,9 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
568 _("Could not access PEERINFO service. Exiting.\n")); 556 _("Could not access PEERINFO service. Exiting.\n"));
569 return GNUNET_SYSERR; 557 return GNUNET_SYSERR;
570 } 558 }
571 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, 559 if (GNUNET_OK !=
572 "HOSTLIST", 560 GNUNET_CONFIGURATION_get_value_number (cfg, "HOSTLIST", "HTTPPORT",
573 "HTTPPORT", &port)) 561 &port))
574 return GNUNET_SYSERR; 562 return GNUNET_SYSERR;
575 if ((port == 0) || (port > UINT16_MAX)) 563 if ((port == 0) || (port > UINT16_MAX))
576 { 564 {
@@ -579,14 +567,13 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
579 return GNUNET_SYSERR; 567 return GNUNET_SYSERR;
580 } 568 }
581 569
582 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, 570 if (GNUNET_SYSERR ==
583 "HOSTLIST", 571 GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST",
584 "EXTERNAL_DNS_NAME", 572 "EXTERNAL_DNS_NAME", &hostname))
585 &hostname))
586 hostname = GNUNET_RESOLVER_local_fqdn_get (); 573 hostname = GNUNET_RESOLVER_local_fqdn_get ();
587 574
588 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 575 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Hostlist service starts on %s:%llu\n"),
589 _("Hostlist service starts on %s:%llu\n"), hostname, port); 576 hostname, port);
590 if (NULL != hostname) 577 if (NULL != hostname)
591 { 578 {
592 size = strlen (hostname); 579 size = strlen (hostname);
@@ -596,8 +583,8 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
596 } 583 }
597 else 584 else
598 { 585 {
599 GNUNET_asprintf (&hostlist_uri, 586 GNUNET_asprintf (&hostlist_uri, "http://%s:%u/", hostname,
600 "http://%s:%u/", hostname, (unsigned int) port); 587 (unsigned int) port);
601 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 588 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
602 _("Address to obtain hostlist: `%s'\n"), hostlist_uri); 589 _("Address to obtain hostlist: `%s'\n"), hostlist_uri);
603 } 590 }
@@ -607,12 +594,9 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
607#if DEBUG_HOSTLIST_SERVER 594#if DEBUG_HOSTLIST_SERVER
608 | MHD_USE_DEBUG 595 | MHD_USE_DEBUG
609#endif 596#endif
610 , 597 , (unsigned short) port,
611 (unsigned short) port, 598 &accept_policy_callback, NULL,
612 &accept_policy_callback, 599 &access_handler_callback, NULL,
613 NULL,
614 &access_handler_callback,
615 NULL,
616 MHD_OPTION_CONNECTION_LIMIT, 600 MHD_OPTION_CONNECTION_LIMIT,
617 (unsigned int) 16, 601 (unsigned int) 16,
618 MHD_OPTION_PER_IP_CONNECTION_LIMIT, 602 MHD_OPTION_PER_IP_CONNECTION_LIMIT,
@@ -625,12 +609,9 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
625#if DEBUG_HOSTLIST_SERVER 609#if DEBUG_HOSTLIST_SERVER
626 | MHD_USE_DEBUG 610 | MHD_USE_DEBUG
627#endif 611#endif
628 , 612 , (unsigned short) port,
629 (unsigned short) port, 613 &accept_policy_callback, NULL,
630 &accept_policy_callback, 614 &access_handler_callback, NULL,
631 NULL,
632 &access_handler_callback,
633 NULL,
634 MHD_OPTION_CONNECTION_LIMIT, 615 MHD_OPTION_CONNECTION_LIMIT,
635 (unsigned int) 16, 616 (unsigned int) 16,
636 MHD_OPTION_PER_IP_CONNECTION_LIMIT, 617 MHD_OPTION_PER_IP_CONNECTION_LIMIT,
diff --git a/src/hostlist/test_gnunet_daemon_hostlist.c b/src/hostlist/test_gnunet_daemon_hostlist.c
index 5cca8becd..909b946e7 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist.c
+++ b/src/hostlist/test_gnunet_daemon_hostlist.c
@@ -95,8 +95,7 @@ timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
95 * @param distance in overlay hops, as given by transport plugin 95 * @param distance in overlay hops, as given by transport plugin
96 */ 96 */
97static void 97static void
98notify_connect (void *cls, 98notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
99 const struct GNUNET_PeerIdentity *peer,
100 const struct GNUNET_TRANSPORT_ATS_Information *ats, 99 const struct GNUNET_TRANSPORT_ATS_Information *ats,
101 uint32_t ats_count) 100 uint32_t ats_count)
102{ 101{
@@ -129,16 +128,17 @@ setup_peer (struct PeerContext *p, const char *cfgname)
129{ 128{
130 p->cfg = GNUNET_CONFIGURATION_create (); 129 p->cfg = GNUNET_CONFIGURATION_create ();
131#if START_ARM 130#if START_ARM
132 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 131 p->arm_proc =
133 "gnunet-service-arm", 132 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
133 "gnunet-service-arm",
134#if VERBOSE 134#if VERBOSE
135 "-L", "DEBUG", 135 "-L", "DEBUG",
136#endif 136#endif
137 "-c", cfgname, NULL); 137 "-c", cfgname, NULL);
138#endif 138#endif
139 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 139 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
140 p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, 140 p->th =
141 &notify_connect, NULL); 141 GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, &notify_connect, NULL);
142 GNUNET_assert (p->th != NULL); 142 GNUNET_assert (p->th != NULL);
143 GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p); 143 GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p);
144} 144}
@@ -155,8 +155,7 @@ waitpid_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
155 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 155 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
156 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 156 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
157 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 157 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
158 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 158 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
159 "ARM process %u stopped\n",
160 GNUNET_OS_process_get_pid (p->arm_proc)); 159 GNUNET_OS_process_get_pid (p->arm_proc));
161 GNUNET_OS_process_close (p->arm_proc); 160 GNUNET_OS_process_close (p->arm_proc);
162 p->arm_proc = NULL; 161 p->arm_proc = NULL;
@@ -185,15 +184,14 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
185 184
186 185
187static void 186static void
188run (void *cls, 187run (void *cls, char *const *args, const char *cfgfile,
189 char *const *args, 188 const struct GNUNET_CONFIGURATION_Handle *cfg)
190 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
191{ 189{
192 GNUNET_assert (ok == 1); 190 GNUNET_assert (ok == 1);
193 ok++; 191 ok++;
194 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL); 192 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL);
195 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 193 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
196 &shutdown_task, NULL); 194 NULL);
197 setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf"); 195 setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf");
198 setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf"); 196 setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf");
199} 197}
@@ -213,9 +211,9 @@ check ()
213 GNUNET_GETOPT_OPTION_END 211 GNUNET_GETOPT_OPTION_END
214 }; 212 };
215 ok = 1; 213 ok = 1;
216 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 214 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
217 argv, "test-gnunet-daemon-hostlist", 215 "test-gnunet-daemon-hostlist", "nohelp", options, &run,
218 "nohelp", options, &run, &ok); 216 &ok);
219 return ok; 217 return ok;
220} 218}
221 219
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_learning.c b/src/hostlist/test_gnunet_daemon_hostlist_learning.c
index 7ecca8a85..2538e42fb 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist_learning.c
+++ b/src/hostlist/test_gnunet_daemon_hostlist_learning.c
@@ -182,9 +182,8 @@ process_downloads_done (void *cls, int success)
182 182
183 183
184static int 184static int
185process_downloads (void *cls, 185process_downloads (void *cls, const char *subsystem, const char *name,
186 const char *subsystem, 186 uint64_t value, int is_persistent)
187 const char *name, uint64_t value, int is_persistent)
188{ 187{
189 if ((value >= 2) && (learned_hostlist_downloaded == GNUNET_NO)) 188 if ((value >= 2) && (learned_hostlist_downloaded == GNUNET_NO))
190 { 189 {
@@ -206,12 +205,11 @@ process_uris_recv_done (void *cls, int success)
206 205
207 206
208static int 207static int
209process_uris_recv (void *cls, 208process_uris_recv (void *cls, const char *subsystem, const char *name,
210 const char *subsystem, 209 uint64_t value, int is_persistent)
211 const char *name, uint64_t value, int is_persistent)
212{ 210{
213 if (((struct PeerContext *) cls == &learn_peer) && 211 if (((struct PeerContext *) cls == &learn_peer) && (value == 1) &&
214 (value == 1) && (learned_hostlist_saved == GNUNET_NO)) 212 (learned_hostlist_saved == GNUNET_NO))
215 { 213 {
216 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 214 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
217 "Peer has successfully saved advertised URI\n"); 215 "Peer has successfully saved advertised URI\n");
@@ -231,9 +229,8 @@ process_adv_sent_done (void *cls, int success)
231 229
232 230
233static int 231static int
234process_adv_sent (void *cls, 232process_adv_sent (void *cls, const char *subsystem, const char *name,
235 const char *subsystem, 233 uint64_t value, int is_persistent)
236 const char *name, uint64_t value, int is_persistent)
237{ 234{
238 if ((value >= 1) && (adv_sent == GNUNET_NO)) 235 if ((value >= 1) && (adv_sent == GNUNET_NO))
239 { 236 {
@@ -259,44 +256,39 @@ check_statistics (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
259 check_task = GNUNET_SCHEDULER_NO_TASK; 256 check_task = GNUNET_SCHEDULER_NO_TASK;
260 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 257 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
261 return; 258 return;
262 GNUNET_asprintf (&stat, 259 GNUNET_asprintf (&stat, gettext_noop ("# advertised URI `%s' downloaded"),
263 gettext_noop ("# advertised URI `%s' downloaded"),
264 current_adv_uri); 260 current_adv_uri);
265 if (NULL != learn_peer.stats) 261 if (NULL != learn_peer.stats)
266 { 262 {
267 if (NULL != download_stats) 263 if (NULL != download_stats)
268 GNUNET_STATISTICS_get_cancel (download_stats); 264 GNUNET_STATISTICS_get_cancel (download_stats);
269 download_stats = GNUNET_STATISTICS_get (learn_peer.stats, 265 download_stats =
270 "hostlist", 266 GNUNET_STATISTICS_get (learn_peer.stats, "hostlist", stat,
271 stat, 267 GNUNET_TIME_UNIT_MINUTES,
272 GNUNET_TIME_UNIT_MINUTES, 268 &process_downloads_done, &process_downloads,
273 &process_downloads_done, 269 &learn_peer);
274 &process_downloads, &learn_peer);
275 if (NULL != urisrecv_stat) 270 if (NULL != urisrecv_stat)
276 GNUNET_STATISTICS_get_cancel (urisrecv_stat); 271 GNUNET_STATISTICS_get_cancel (urisrecv_stat);
277 urisrecv_stat = GNUNET_STATISTICS_get (learn_peer.stats, 272 urisrecv_stat =
278 "hostlist", 273 GNUNET_STATISTICS_get (learn_peer.stats, "hostlist",
279 gettext_noop 274 gettext_noop ("# advertised hostlist URIs"),
280 ("# advertised hostlist URIs"), 275 GNUNET_TIME_UNIT_MINUTES,
281 GNUNET_TIME_UNIT_MINUTES, 276 &process_uris_recv_done, &process_uris_recv,
282 &process_uris_recv_done, 277 &learn_peer);
283 &process_uris_recv, &learn_peer);
284 } 278 }
285 GNUNET_free (stat); 279 GNUNET_free (stat);
286 if (NULL != adv_peer.stats) 280 if (NULL != adv_peer.stats)
287 { 281 {
288 if (NULL != advsent_stat) 282 if (NULL != advsent_stat)
289 GNUNET_STATISTICS_get_cancel (advsent_stat); 283 GNUNET_STATISTICS_get_cancel (advsent_stat);
290 advsent_stat = GNUNET_STATISTICS_get (adv_peer.stats, 284 advsent_stat =
291 "hostlist", 285 GNUNET_STATISTICS_get (adv_peer.stats, "hostlist",
292 gettext_noop 286 gettext_noop ("# hostlist advertisements send"),
293 ("# hostlist advertisements send"), 287 GNUNET_TIME_UNIT_MINUTES, &process_adv_sent_done,
294 GNUNET_TIME_UNIT_MINUTES, 288 &process_adv_sent, NULL);
295 &process_adv_sent_done,
296 &process_adv_sent, NULL);
297 } 289 }
298 check_task = GNUNET_SCHEDULER_add_delayed (CHECK_INTERVALL, 290 check_task =
299 &check_statistics, NULL); 291 GNUNET_SCHEDULER_add_delayed (CHECK_INTERVALL, &check_statistics, NULL);
300} 292}
301 293
302 294
@@ -304,8 +296,7 @@ check_statistics (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
304 * Core handler for p2p hostlist advertisements 296 * Core handler for p2p hostlist advertisements
305 */ 297 */
306static int 298static int
307ad_arrive_handler (void *cls, 299ad_arrive_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
308 const struct GNUNET_PeerIdentity *peer,
309 const struct GNUNET_MessageHeader *message, 300 const struct GNUNET_MessageHeader *message,
310 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 301 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
311{ 302{
@@ -315,22 +306,20 @@ ad_arrive_handler (void *cls,
315 const struct GNUNET_MessageHeader *incoming; 306 const struct GNUNET_MessageHeader *incoming;
316 const char *end; 307 const char *end;
317 308
318 if (-1 == GNUNET_CONFIGURATION_get_value_number (adv_peer.cfg, 309 if (-1 ==
319 "HOSTLIST", 310 GNUNET_CONFIGURATION_get_value_number (adv_peer.cfg, "HOSTLIST",
320 "HTTPPORT", &port)) 311 "HTTPPORT", &port))
321 { 312 {
322 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 313 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
323 "Could not read advertising server's configuration\n"); 314 "Could not read advertising server's configuration\n");
324 return GNUNET_SYSERR; 315 return GNUNET_SYSERR;
325 } 316 }
326 317
327 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (adv_peer.cfg, 318 if (GNUNET_SYSERR ==
328 "HOSTLIST", 319 GNUNET_CONFIGURATION_get_value_string (adv_peer.cfg, "HOSTLIST",
329 "EXTERNAL_DNS_NAME", 320 "EXTERNAL_DNS_NAME", &hostname))
330 &hostname))
331 hostname = GNUNET_RESOLVER_local_fqdn_get (); 321 hostname = GNUNET_RESOLVER_local_fqdn_get ();
332 GNUNET_asprintf (&expected_uri, 322 GNUNET_asprintf (&expected_uri, "http://%s:%u/",
333 "http://%s:%u/",
334 hostname != NULL ? hostname : "localhost", 323 hostname != NULL ? hostname : "localhost",
335 (unsigned int) port); 324 (unsigned int) port);
336 incoming = (const struct GNUNET_MessageHeader *) message; 325 incoming = (const struct GNUNET_MessageHeader *) message;
@@ -379,18 +368,18 @@ setup_learn_peer (struct PeerContext *p, const char *cfgname)
379 368
380 p->cfg = GNUNET_CONFIGURATION_create (); 369 p->cfg = GNUNET_CONFIGURATION_create ();
381#if START_ARM 370#if START_ARM
382 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 371 p->arm_proc =
383 "gnunet-service-arm", 372 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
373 "gnunet-service-arm",
384#if VERBOSE 374#if VERBOSE
385 "-L", "DEBUG", 375 "-L", "DEBUG",
386#endif 376#endif
387 "-c", cfgname, NULL); 377 "-c", cfgname, NULL);
388#endif 378#endif
389 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 379 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
390 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (p->cfg, 380 if (GNUNET_OK ==
391 "HOSTLIST", 381 GNUNET_CONFIGURATION_get_value_string (p->cfg, "HOSTLIST", "HOSTLISTFILE",
392 "HOSTLISTFILE", 382 &filename))
393 &filename))
394 { 383 {
395 if (GNUNET_YES == GNUNET_DISK_file_test (filename)) 384 if (GNUNET_YES == GNUNET_DISK_file_test (filename))
396 { 385 {
@@ -401,13 +390,9 @@ setup_learn_peer (struct PeerContext *p, const char *cfgname)
401 } 390 }
402 GNUNET_free (filename); 391 GNUNET_free (filename);
403 } 392 }
404 p->core = GNUNET_CORE_connect (p->cfg, 393 p->core =
405 1, 394 GNUNET_CORE_connect (p->cfg, 1, NULL, NULL, NULL, NULL, NULL, NULL,
406 NULL, 395 GNUNET_NO, NULL, GNUNET_NO, learn_handlers);
407 NULL,
408 NULL, NULL, NULL,
409 NULL, GNUNET_NO,
410 NULL, GNUNET_NO, learn_handlers);
411 GNUNET_assert (NULL != p->core); 396 GNUNET_assert (NULL != p->core);
412 p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg); 397 p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg);
413 GNUNET_assert (NULL != p->stats); 398 GNUNET_assert (NULL != p->stats);
@@ -419,12 +404,13 @@ setup_adv_peer (struct PeerContext *p, const char *cfgname)
419{ 404{
420 p->cfg = GNUNET_CONFIGURATION_create (); 405 p->cfg = GNUNET_CONFIGURATION_create ();
421#if START_ARM 406#if START_ARM
422 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 407 p->arm_proc =
423 "gnunet-service-arm", 408 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
409 "gnunet-service-arm",
424#if VERBOSE 410#if VERBOSE
425 "-L", "DEBUG", 411 "-L", "DEBUG",
426#endif 412#endif
427 "-c", cfgname, NULL); 413 "-c", cfgname, NULL);
428#endif 414#endif
429 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 415 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
430 p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg); 416 p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg);
@@ -433,9 +419,8 @@ setup_adv_peer (struct PeerContext *p, const char *cfgname)
433 419
434 420
435static void 421static void
436run (void *cls, 422run (void *cls, char *const *args, const char *cfgfile,
437 char *const *args, 423 const struct GNUNET_CONFIGURATION_Handle *c)
438 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
439{ 424{
440 timeout = GNUNET_NO; 425 timeout = GNUNET_NO;
441 adv_sent = GNUNET_NO; 426 adv_sent = GNUNET_NO;
@@ -450,8 +435,8 @@ run (void *cls,
450 setup_learn_peer (&learn_peer, "test_learning_learn_peer.conf"); 435 setup_learn_peer (&learn_peer, "test_learning_learn_peer.conf");
451 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL); 436 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL);
452 437
453 check_task = GNUNET_SCHEDULER_add_delayed (CHECK_INTERVALL, 438 check_task =
454 &check_statistics, NULL); 439 GNUNET_SCHEDULER_add_delayed (CHECK_INTERVALL, &check_statistics, NULL);
455} 440}
456 441
457 442
@@ -472,9 +457,9 @@ check ()
472 GNUNET_GETOPT_OPTION_END 457 GNUNET_GETOPT_OPTION_END
473 }; 458 };
474 459
475 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 460 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
476 argv, "test-gnunet-daemon-hostlist-learning", 461 "test-gnunet-daemon-hostlist-learning", "nohelp", options,
477 "nohelp", options, &run, NULL); 462 &run, NULL);
478 failed = GNUNET_NO; 463 failed = GNUNET_NO;
479 if (timeout == GNUNET_YES) 464 if (timeout == GNUNET_YES)
480 { 465 {
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
index d1227da4c..ff625cf8e 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
+++ b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
@@ -96,8 +96,7 @@ timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
96 * @param distance in overlay hops, as given by transport plugin 96 * @param distance in overlay hops, as given by transport plugin
97 */ 97 */
98static void 98static void
99notify_connect (void *cls, 99notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
100 const struct GNUNET_PeerIdentity *peer,
101 const struct GNUNET_TRANSPORT_ATS_Information *ats, 100 const struct GNUNET_TRANSPORT_ATS_Information *ats,
102 uint32_t ats_count) 101 uint32_t ats_count)
103{ 102{
@@ -133,16 +132,17 @@ setup_peer (struct PeerContext *p, const char *cfgname)
133{ 132{
134 p->cfg = GNUNET_CONFIGURATION_create (); 133 p->cfg = GNUNET_CONFIGURATION_create ();
135#if START_ARM 134#if START_ARM
136 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 135 p->arm_proc =
137 "gnunet-service-arm", 136 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
137 "gnunet-service-arm",
138#if VERBOSE 138#if VERBOSE
139 "-L", "DEBUG", 139 "-L", "DEBUG",
140#endif 140#endif
141 "-c", cfgname, NULL); 141 "-c", cfgname, NULL);
142#endif 142#endif
143 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 143 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
144 p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, 144 p->th =
145 &notify_connect, NULL); 145 GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, &notify_connect, NULL);
146 GNUNET_assert (p->th != NULL); 146 GNUNET_assert (p->th != NULL);
147 GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p); 147 GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p);
148} 148}
@@ -159,8 +159,7 @@ waitpid_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
159 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 159 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
160 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 160 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
161 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 161 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
163 "ARM process %u stopped\n",
164 GNUNET_OS_process_get_pid (p->arm_proc)); 163 GNUNET_OS_process_get_pid (p->arm_proc));
165 GNUNET_OS_process_close (p->arm_proc); 164 GNUNET_OS_process_close (p->arm_proc);
166 p->arm_proc = NULL; 165 p->arm_proc = NULL;
@@ -189,15 +188,14 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
189 188
190 189
191static void 190static void
192run (void *cls, 191run (void *cls, char *const *args, const char *cfgfile,
193 char *const *args, 192 const struct GNUNET_CONFIGURATION_Handle *cfg)
194 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
195{ 193{
196 GNUNET_assert (ok == 1); 194 GNUNET_assert (ok == 1);
197 ok++; 195 ok++;
198 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL); 196 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL);
199 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 197 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
200 &shutdown_task, NULL); 198 NULL);
201 setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf"); 199 setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf");
202 setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf"); 200 setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf");
203} 201}
@@ -217,9 +215,9 @@ check ()
217 GNUNET_GETOPT_OPTION_END 215 GNUNET_GETOPT_OPTION_END
218 }; 216 };
219 ok = 1; 217 ok = 1;
220 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 218 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
221 argv, "test-gnunet-daemon-hostlist", 219 "test-gnunet-daemon-hostlist", "nohelp", options, &run,
222 "nohelp", options, &run, &ok); 220 &ok);
223 return ok; 221 return ok;
224} 222}
225 223
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index de1daecb0..338def09a 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -480,11 +480,9 @@ get_peer_info (const struct GNUNET_PeerIdentity *peer)
480 peer_info = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); 480 peer_info = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
481 if (NULL == peer_info) 481 if (NULL == peer_info)
482 { 482 {
483 peer_info = (struct MeshPeerInfo *) 483 peer_info =
484 GNUNET_malloc (sizeof (struct MeshPeerInfo)); 484 (struct MeshPeerInfo *) GNUNET_malloc (sizeof (struct MeshPeerInfo));
485 GNUNET_CONTAINER_multihashmap_put (peers, 485 GNUNET_CONTAINER_multihashmap_put (peers, &peer->hashPubKey, peer_info,
486 &peer->hashPubKey,
487 peer_info,
488 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 486 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
489 peer_info->id = GNUNET_PEER_intern (peer); 487 peer_info->id = GNUNET_PEER_intern (peer);
490 peer_info->state = MESH_PEER_SEARCHING; 488 peer_info->state = MESH_PEER_SEARCHING;
@@ -591,8 +589,8 @@ add_path_to_peer (struct MeshPeerInfo *peer_info, struct MeshPath *path)
591 if (best_cost < new_cost) 589 if (best_cost < new_cost)
592 { 590 {
593 path->in_use = 0; 591 path->in_use = 0;
594 GNUNET_CONTAINER_DLL_insert_tail (peer_info->path, 592 GNUNET_CONTAINER_DLL_insert_tail (peer_info->path, peer_info->path_tail,
595 peer_info->path_tail, path); 593 path);
596 } 594 }
597 else 595 else
598 { 596 {
@@ -820,16 +818,12 @@ announce_applications (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
820 GNUNET_PEER_resolve (myid, &id); 818 GNUNET_PEER_resolve (myid, &id);
821 for (i = 0; i < n_applications; i++) 819 for (i = 0; i < n_applications; i++)
822 { 820 {
823 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 821 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting PUT for app %d\n",
824 "Starting PUT for app %d\n", applications[i]); 822 applications[i]);
825 *p = htonl (applications[i]); 823 *p = htonl (applications[i]);
826 GNUNET_CRYPTO_hash (buffer, 12, &hash); 824 GNUNET_CRYPTO_hash (buffer, 12, &hash);
827 GNUNET_DHT_put (dht_handle, 825 GNUNET_DHT_put (dht_handle, &hash, 10U, GNUNET_DHT_RO_RECORD_ROUTE,
828 &hash, 826 GNUNET_BLOCK_TYPE_ANY, sizeof (struct GNUNET_PeerIdentity),
829 10U,
830 GNUNET_DHT_RO_RECORD_ROUTE,
831 GNUNET_BLOCK_TYPE_ANY,
832 sizeof (struct GNUNET_PeerIdentity),
833 (const char *) &id, 827 (const char *) &id,
834 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), 828 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
835 APP_ANNOUNCE_TIME), 829 APP_ANNOUNCE_TIME),
@@ -840,9 +834,9 @@ announce_applications (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
840 NULL, NULL); 834 NULL, NULL);
841#endif 835#endif
842 } 836 }
843 announce_applications_task = GNUNET_SCHEDULER_add_delayed (APP_ANNOUNCE_TIME, 837 announce_applications_task =
844 &announce_applications, 838 GNUNET_SCHEDULER_add_delayed (APP_ANNOUNCE_TIME, &announce_applications,
845 cls); 839 cls);
846 return; 840 return;
847} 841}
848 842
@@ -883,8 +877,8 @@ announce_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
883 NULL, /* Continuation */ 877 NULL, /* Continuation */
884 NULL); /* Continuation closure */ 878 NULL); /* Continuation closure */
885#endif 879#endif
886 announce_id_task = GNUNET_SCHEDULER_add_delayed (ID_ANNOUNCE_TIME, 880 announce_id_task =
887 &announce_id, cls); 881 GNUNET_SCHEDULER_add_delayed (ID_ANNOUNCE_TIME, &announce_id, cls);
888} 882}
889 883
890/******************************************************************************/ 884/******************************************************************************/
@@ -917,11 +911,8 @@ send_core_create_path_for_peer (void *cls, size_t size, void *buf)
917 { 911 {
918 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Retransmitting create path\n"); 912 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Retransmitting create path\n");
919 GNUNET_PEER_resolve (get_first_hop (peer_info->path), &id); 913 GNUNET_PEER_resolve (get_first_hop (peer_info->path), &id);
920 GNUNET_CORE_notify_transmit_ready (core_handle, 914 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
921 0, 915 GNUNET_TIME_UNIT_FOREVER_REL, &id,
922 0,
923 GNUNET_TIME_UNIT_FOREVER_REL,
924 &id,
925 sizeof (struct 916 sizeof (struct
926 GNUNET_MESH_ManipulatePath) + 917 GNUNET_MESH_ManipulatePath) +
927 (peer_info->path->length * 918 (peer_info->path->length *
@@ -942,8 +933,9 @@ send_core_create_path_for_peer (void *cls, size_t size, void *buf)
942 if (p == NULL) 933 if (p == NULL)
943 return 0; // TODO Notify ERROR Path not found 934 return 0; // TODO Notify ERROR Path not found
944 935
945 size_needed = sizeof (struct GNUNET_MESH_ManipulatePath) 936 size_needed =
946 + p->length * sizeof (struct GNUNET_PeerIdentity); 937 sizeof (struct GNUNET_MESH_ManipulatePath) +
938 p->length * sizeof (struct GNUNET_PeerIdentity);
947 if (size < size_needed) 939 if (size < size_needed)
948 { 940 {
949 // TODO retry? cancel? 941 // TODO retry? cancel?
@@ -1194,8 +1186,8 @@ send_p2p_tunnel_destroy (void *cls, size_t size, void *buf)
1194 c = t->client; 1186 c = t->client;
1195 msg = buf; 1187 msg = buf;
1196 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); 1188 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY);
1197 /*FIXME*/ 1189 /*FIXME*/ msg->header.size =
1198 msg->header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); 1190 htons (sizeof (struct GNUNET_MESH_TunnelMessage));
1199 msg->tunnel_id = htonl (t->id.tid); 1191 msg->tunnel_id = htonl (t->id.tid);
1200 1192
1201 destroy_tunnel (c, t); 1193 destroy_tunnel (c, t);
@@ -1223,8 +1215,8 @@ send_subscribed_clients (struct GNUNET_MessageHeader *msg)
1223 if (is_client_subscribed (type, c)) 1215 if (is_client_subscribed (type, c))
1224 { 1216 {
1225 count++; 1217 count++;
1226 GNUNET_SERVER_notification_context_unicast (nc, 1218 GNUNET_SERVER_notification_context_unicast (nc, c->handle, msg,
1227 c->handle, msg, GNUNET_YES); 1219 GNUNET_YES);
1228 } 1220 }
1229 } 1221 }
1230 return count; 1222 return count;
@@ -1284,8 +1276,7 @@ iterate_collect_neighbors (void *cls, const GNUNET_HashCode * key, void *value)
1284 * 1276 *
1285 */ 1277 */
1286static int 1278static int
1287handle_mesh_path_create (void *cls, 1279handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
1288 const struct GNUNET_PeerIdentity *peer,
1289 const struct GNUNET_MessageHeader *message, 1280 const struct GNUNET_MessageHeader *message,
1290 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 1281 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1291{ 1282{
@@ -1341,9 +1332,7 @@ handle_mesh_path_create (void *cls,
1341 1332
1342 GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); 1333 GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash);
1343 if (GNUNET_OK != 1334 if (GNUNET_OK !=
1344 GNUNET_CONTAINER_multihashmap_put (tunnels, 1335 GNUNET_CONTAINER_multihashmap_put (tunnels, &hash, t,
1345 &hash,
1346 t,
1347 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 1336 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1348 { 1337 {
1349 GNUNET_break (0); 1338 GNUNET_break (0);
@@ -1351,15 +1340,14 @@ handle_mesh_path_create (void *cls,
1351 } 1340 }
1352 1341
1353 } 1342 }
1354 dest_peer_info = GNUNET_CONTAINER_multihashmap_get (peers, 1343 dest_peer_info =
1355 &pi[size - 1].hashPubKey); 1344 GNUNET_CONTAINER_multihashmap_get (peers, &pi[size - 1].hashPubKey);
1356 if (NULL == dest_peer_info) 1345 if (NULL == dest_peer_info)
1357 { 1346 {
1358 dest_peer_info = GNUNET_malloc (sizeof (struct MeshPeerInfo)); 1347 dest_peer_info = GNUNET_malloc (sizeof (struct MeshPeerInfo));
1359 dest_peer_info->id = GNUNET_PEER_intern (&pi[size - 1]); 1348 dest_peer_info->id = GNUNET_PEER_intern (&pi[size - 1]);
1360 dest_peer_info->state = MESH_PEER_WAITING; 1349 dest_peer_info->state = MESH_PEER_WAITING;
1361 GNUNET_CONTAINER_multihashmap_put (peers, 1350 GNUNET_CONTAINER_multihashmap_put (peers, &pi[size - 1].hashPubKey,
1362 &pi[size - 1].hashPubKey,
1363 dest_peer_info, 1351 dest_peer_info,
1364 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 1352 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1365 } 1353 }
@@ -1369,9 +1357,7 @@ handle_mesh_path_create (void *cls,
1369 orig_peer_info = GNUNET_malloc (sizeof (struct MeshPeerInfo)); 1357 orig_peer_info = GNUNET_malloc (sizeof (struct MeshPeerInfo));
1370 orig_peer_info->id = GNUNET_PEER_intern (pi); 1358 orig_peer_info->id = GNUNET_PEER_intern (pi);
1371 orig_peer_info->state = MESH_PEER_WAITING; 1359 orig_peer_info->state = MESH_PEER_WAITING;
1372 GNUNET_CONTAINER_multihashmap_put (peers, 1360 GNUNET_CONTAINER_multihashmap_put (peers, &pi->hashPubKey, orig_peer_info,
1373 &pi->hashPubKey,
1374 orig_peer_info,
1375 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 1361 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1376 } 1362 }
1377 1363
@@ -1424,11 +1410,8 @@ handle_mesh_path_create (void *cls,
1424 { 1410 {
1425 add_path_to_peer (dest_peer_info, path); 1411 add_path_to_peer (dest_peer_info, path);
1426 GNUNET_PEER_resolve (get_first_hop (path), &id); 1412 GNUNET_PEER_resolve (get_first_hop (path), &id);
1427 GNUNET_CORE_notify_transmit_ready (core_handle, 1413 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
1428 0, 1414 GNUNET_TIME_UNIT_FOREVER_REL, &id,
1429 0,
1430 GNUNET_TIME_UNIT_FOREVER_REL,
1431 &id,
1432 sizeof (struct GNUNET_MessageHeader), 1415 sizeof (struct GNUNET_MessageHeader),
1433 &send_core_create_path_for_peer, 1416 &send_core_create_path_for_peer,
1434 dest_peer_info); 1417 dest_peer_info);
@@ -1448,8 +1431,7 @@ handle_mesh_path_create (void *cls,
1448 * GNUNET_SYSERR to close it (signal serious error) 1431 * GNUNET_SYSERR to close it (signal serious error)
1449 */ 1432 */
1450static int 1433static int
1451handle_mesh_data_unicast (void *cls, 1434handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
1452 const struct GNUNET_PeerIdentity *peer,
1453 const struct GNUNET_MessageHeader *message, 1435 const struct GNUNET_MessageHeader *message,
1454 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 1436 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1455{ 1437{
@@ -1460,8 +1442,9 @@ handle_mesh_data_unicast (void *cls,
1460 size_t size; 1442 size_t size;
1461 1443
1462 size = ntohs (message->size); 1444 size = ntohs (message->size);
1463 if (size < sizeof (struct GNUNET_MESH_Unicast) 1445 if (size <
1464 + sizeof (struct GNUNET_MessageHeader)) 1446 sizeof (struct GNUNET_MESH_Unicast) +
1447 sizeof (struct GNUNET_MessageHeader))
1465 { 1448 {
1466 GNUNET_break (0); 1449 GNUNET_break (0);
1467 return GNUNET_OK; 1450 return GNUNET_OK;
@@ -1488,11 +1471,9 @@ handle_mesh_data_unicast (void *cls,
1488 GNUNET_PEER_resolve (get_first_hop (pi->path), &id); 1471 GNUNET_PEER_resolve (get_first_hop (pi->path), &id);
1489 msg = GNUNET_malloc (size); 1472 msg = GNUNET_malloc (size);
1490 memcpy (msg, message, size); 1473 memcpy (msg, message, size);
1491 GNUNET_CORE_notify_transmit_ready (core_handle, 1474 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
1492 0, 1475 GNUNET_TIME_UNIT_FOREVER_REL, &id, size,
1493 0, 1476 &send_core_data_raw, msg);
1494 GNUNET_TIME_UNIT_FOREVER_REL,
1495 &id, size, &send_core_data_raw, msg);
1496 return GNUNET_OK; 1477 return GNUNET_OK;
1497} 1478}
1498 1479
@@ -1508,8 +1489,7 @@ handle_mesh_data_unicast (void *cls,
1508 * GNUNET_SYSERR to close it (signal serious error) 1489 * GNUNET_SYSERR to close it (signal serious error)
1509 */ 1490 */
1510static int 1491static int
1511handle_mesh_data_multicast (void *cls, 1492handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer,
1512 const struct GNUNET_PeerIdentity *peer,
1513 const struct GNUNET_MessageHeader *message, 1493 const struct GNUNET_MessageHeader *message,
1514 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 1494 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1515{ 1495{
@@ -1524,8 +1504,9 @@ handle_mesh_data_multicast (void *cls,
1524 1504
1525 1505
1526 size = ntohs (message->size); 1506 size = ntohs (message->size);
1527 if (size < sizeof (struct GNUNET_MESH_Multicast) 1507 if (size <
1528 + sizeof (struct GNUNET_MessageHeader)) 1508 sizeof (struct GNUNET_MESH_Multicast) +
1509 sizeof (struct GNUNET_MessageHeader))
1529 { 1510 {
1530 GNUNET_break_op (0); 1511 GNUNET_break_op (0);
1531 return GNUNET_OK; 1512 return GNUNET_OK;
@@ -1549,8 +1530,7 @@ handle_mesh_data_multicast (void *cls,
1549 /* Retransmit to other peers */ 1530 /* Retransmit to other peers */
1550 neighbors = GNUNET_malloc (sizeof (GNUNET_PEER_Id)); 1531 neighbors = GNUNET_malloc (sizeof (GNUNET_PEER_Id));
1551 neighbors[0] = 0; 1532 neighbors[0] = 0;
1552 GNUNET_CONTAINER_multihashmap_iterate (t->peers, 1533 GNUNET_CONTAINER_multihashmap_iterate (t->peers, &iterate_collect_neighbors,
1553 &iterate_collect_neighbors,
1554 &neighbors); 1534 &neighbors);
1555 if (!neighbors[0]) 1535 if (!neighbors[0])
1556 { 1536 {
@@ -1598,8 +1578,7 @@ handle_mesh_data_multicast (void *cls,
1598 * GNUNET_SYSERR to close it (signal serious error) 1578 * GNUNET_SYSERR to close it (signal serious error)
1599 */ 1579 */
1600static int 1580static int
1601handle_mesh_data_to_orig (void *cls, 1581handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer,
1602 const struct GNUNET_PeerIdentity *peer,
1603 const struct GNUNET_MessageHeader *message, 1582 const struct GNUNET_MessageHeader *message,
1604 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 1583 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1605{ 1584{
@@ -1610,8 +1589,9 @@ handle_mesh_data_to_orig (void *cls,
1610 size_t size; 1589 size_t size;
1611 1590
1612 size = ntohs (message->size); 1591 size = ntohs (message->size);
1613 if (size < sizeof (struct GNUNET_MESH_ToOrigin) 1592 if (size <
1614 + sizeof (struct GNUNET_MessageHeader)) 1593 sizeof (struct GNUNET_MESH_ToOrigin) +
1594 sizeof (struct GNUNET_MessageHeader))
1615 { 1595 {
1616 GNUNET_break_op (0); 1596 GNUNET_break_op (0);
1617 return GNUNET_OK; 1597 return GNUNET_OK;
@@ -1633,9 +1613,8 @@ handle_mesh_data_to_orig (void *cls,
1633 GNUNET_break_op (0); 1613 GNUNET_break_op (0);
1634 return GNUNET_OK; 1614 return GNUNET_OK;
1635 } 1615 }
1636 GNUNET_SERVER_notification_context_unicast (nc, 1616 GNUNET_SERVER_notification_context_unicast (nc, t->client->handle, message,
1637 t->client->handle, 1617 GNUNET_YES);
1638 message, GNUNET_YES);
1639 return GNUNET_OK; 1618 return GNUNET_OK;
1640 } 1619 }
1641 peer_info = get_peer_info (&msg->oid); 1620 peer_info = get_peer_info (&msg->oid);
@@ -1648,11 +1627,9 @@ handle_mesh_data_to_orig (void *cls,
1648 GNUNET_PEER_resolve (get_first_hop (peer_info->path), &id); 1627 GNUNET_PEER_resolve (get_first_hop (peer_info->path), &id);
1649 msg = GNUNET_malloc (size); 1628 msg = GNUNET_malloc (size);
1650 memcpy (msg, message, size); 1629 memcpy (msg, message, size);
1651 GNUNET_CORE_notify_transmit_ready (core_handle, 1630 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
1652 0, 1631 GNUNET_TIME_UNIT_FOREVER_REL, &id, size,
1653 0, 1632 &send_core_data_raw, msg);
1654 GNUNET_TIME_UNIT_FOREVER_REL,
1655 &id, size, &send_core_data_raw, msg);
1656 1633
1657 return GNUNET_OK; 1634 return GNUNET_OK;
1658} 1635}
@@ -1669,8 +1646,7 @@ handle_mesh_data_to_orig (void *cls,
1669 * GNUNET_SYSERR to close it (signal serious error) 1646 * GNUNET_SYSERR to close it (signal serious error)
1670 */ 1647 */
1671static int 1648static int
1672handle_mesh_path_ack (void *cls, 1649handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
1673 const struct GNUNET_PeerIdentity *peer,
1674 const struct GNUNET_MessageHeader *message, 1650 const struct GNUNET_MessageHeader *message,
1675 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 1651 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1676{ 1652{
@@ -1708,8 +1684,7 @@ handle_mesh_path_ack (void *cls,
1708 pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); 1684 pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
1709 pc.tunnel_id = htonl (t->local_tid); 1685 pc.tunnel_id = htonl (t->local_tid);
1710 GNUNET_PEER_resolve (peer_info->id, &pc.peer); 1686 GNUNET_PEER_resolve (peer_info->id, &pc.peer);
1711 GNUNET_SERVER_notification_context_unicast (nc, 1687 GNUNET_SERVER_notification_context_unicast (nc, t->client->handle,
1712 t->client->handle,
1713 &pc.header, GNUNET_NO); 1688 &pc.header, GNUNET_NO);
1714 return GNUNET_OK; 1689 return GNUNET_OK;
1715 } 1690 }
@@ -1724,11 +1699,8 @@ handle_mesh_path_ack (void *cls,
1724 GNUNET_PEER_resolve (get_first_hop (peer_info->path), &id); 1699 GNUNET_PEER_resolve (get_first_hop (peer_info->path), &id);
1725 msg = GNUNET_malloc (sizeof (struct GNUNET_MESH_PathACK)); 1700 msg = GNUNET_malloc (sizeof (struct GNUNET_MESH_PathACK));
1726 memcpy (msg, message, sizeof (struct GNUNET_MESH_PathACK)); 1701 memcpy (msg, message, sizeof (struct GNUNET_MESH_PathACK));
1727 GNUNET_CORE_notify_transmit_ready (core_handle, 1702 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
1728 0, 1703 GNUNET_TIME_UNIT_FOREVER_REL, &id,
1729 0,
1730 GNUNET_TIME_UNIT_FOREVER_REL,
1731 &id,
1732 sizeof (struct GNUNET_MESH_PathACK), 1704 sizeof (struct GNUNET_MESH_PathACK),
1733 &send_core_data_raw, msg); 1705 &send_core_data_raw, msg);
1734 return GNUNET_OK; 1706 return GNUNET_OK;
@@ -1826,14 +1798,12 @@ path_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1826 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) 1798 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
1827 return; 1799 return;
1828 GNUNET_PEER_resolve (get_first_hop (peer_info->path), &id); 1800 GNUNET_PEER_resolve (get_first_hop (peer_info->path), &id);
1829 GNUNET_CORE_notify_transmit_ready (core_handle, 1801 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
1830 0, 1802 GNUNET_TIME_UNIT_FOREVER_REL, &id,
1831 0,
1832 GNUNET_TIME_UNIT_FOREVER_REL,
1833 &id,
1834 sizeof (struct GNUNET_MESH_ManipulatePath) 1803 sizeof (struct GNUNET_MESH_ManipulatePath)
1835 + (peer_info->path->length 1804 +
1836 * sizeof (struct GNUNET_PeerIdentity)), 1805 (peer_info->path->length *
1806 sizeof (struct GNUNET_PeerIdentity)),
1837 &send_core_create_path_for_peer, 1807 &send_core_create_path_for_peer,
1838 peer_info); 1808 peer_info);
1839 peer_info->path_refresh_task = 1809 peer_info->path_refresh_task =
@@ -1860,8 +1830,7 @@ path_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1860 * @param data pointer to the result data 1830 * @param data pointer to the result data
1861 */ 1831 */
1862static void 1832static void
1863dht_get_id_handler (void *cls, 1833dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
1864 struct GNUNET_TIME_Absolute exp,
1865 const GNUNET_HashCode * key, 1834 const GNUNET_HashCode * key,
1866 const struct GNUNET_PeerIdentity *const *get_path, 1835 const struct GNUNET_PeerIdentity *const *get_path,
1867 const struct GNUNET_PeerIdentity *const *put_path, 1836 const struct GNUNET_PeerIdentity *const *put_path,
@@ -1890,28 +1859,26 @@ dht_get_id_handler (void *cls,
1890 for (i = 0; get_path[i] != NULL; i++) ; 1859 for (i = 0; get_path[i] != NULL; i++) ;
1891 for (i--; i >= 0; i--) 1860 for (i--; i >= 0; i--)
1892 { 1861 {
1893 p->peers = GNUNET_realloc (p->peers, 1862 p->peers =
1894 sizeof (GNUNET_PEER_Id) * (p->length + 1)); 1863 GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * (p->length + 1));
1895 p->peers[p->length] = GNUNET_PEER_intern (get_path[i]); 1864 p->peers[p->length] = GNUNET_PEER_intern (get_path[i]);
1896 p->length++; 1865 p->length++;
1897 } 1866 }
1898 for (i = 0; put_path[i] != NULL; i++) ; 1867 for (i = 0; put_path[i] != NULL; i++) ;
1899 for (i--; i >= 0; i--) 1868 for (i--; i >= 0; i--)
1900 { 1869 {
1901 p->peers = GNUNET_realloc (p->peers, 1870 p->peers =
1902 sizeof (GNUNET_PEER_Id) * (p->length + 1)); 1871 GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * (p->length + 1));
1903 p->peers[p->length] = GNUNET_PEER_intern (put_path[i]); 1872 p->peers[p->length] = GNUNET_PEER_intern (put_path[i]);
1904 p->length++; 1873 p->length++;
1905 } 1874 }
1906 add_path_to_peer (peer_info, p); 1875 add_path_to_peer (peer_info, p);
1907 GNUNET_CORE_notify_transmit_ready (core_handle, 1876 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
1908 0, 1877 GNUNET_TIME_UNIT_FOREVER_REL, get_path[1],
1909 0,
1910 GNUNET_TIME_UNIT_FOREVER_REL,
1911 get_path[1],
1912 sizeof (struct GNUNET_MESH_ManipulatePath) 1878 sizeof (struct GNUNET_MESH_ManipulatePath)
1913 + (p->length 1879 +
1914 * sizeof (struct GNUNET_PeerIdentity)), 1880 (p->length *
1881 sizeof (struct GNUNET_PeerIdentity)),
1915 &send_core_create_path_for_peer, 1882 &send_core_create_path_for_peer,
1916 peer_info); 1883 peer_info);
1917 if (0 == peer_info->path_refresh_task) 1884 if (0 == peer_info->path_refresh_task)
@@ -1941,13 +1908,12 @@ dht_get_id_handler (void *cls,
1941 * @param data pointer to the result data 1908 * @param data pointer to the result data
1942 */ 1909 */
1943static void 1910static void
1944dht_get_type_handler (void *cls, 1911dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp,
1945 struct GNUNET_TIME_Absolute exp,
1946 const GNUNET_HashCode * key, 1912 const GNUNET_HashCode * key,
1947 const struct GNUNET_PeerIdentity *const *get_path, 1913 const struct GNUNET_PeerIdentity *const *get_path,
1948 const struct GNUNET_PeerIdentity *const *put_path, 1914 const struct GNUNET_PeerIdentity *const *put_path,
1949 enum GNUNET_BLOCK_Type type, 1915 enum GNUNET_BLOCK_Type type, size_t size,
1950 size_t size, const void *data) 1916 const void *data)
1951{ 1917{
1952 const struct GNUNET_PeerIdentity *pi = data; 1918 const struct GNUNET_PeerIdentity *pi = data;
1953 struct MeshTunnel *t = cls; 1919 struct MeshTunnel *t = cls;
@@ -1962,9 +1928,7 @@ dht_get_type_handler (void *cls,
1962 return; 1928 return;
1963 } 1929 }
1964 peer_info = get_peer_info (pi); 1930 peer_info = get_peer_info (pi);
1965 GNUNET_CONTAINER_multihashmap_put (t->peers, 1931 GNUNET_CONTAINER_multihashmap_put (t->peers, &pi->hashPubKey, peer_info,
1966 &pi->hashPubKey,
1967 peer_info,
1968 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 1932 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1969 if ((NULL == get_path || NULL == put_path) && NULL == peer_info->path) 1933 if ((NULL == get_path || NULL == put_path) && NULL == peer_info->path)
1970 { 1934 {
@@ -1984,28 +1948,26 @@ dht_get_type_handler (void *cls,
1984 for (i = 0; get_path[i] != NULL; i++) ; 1948 for (i = 0; get_path[i] != NULL; i++) ;
1985 for (i--; i >= 0; i--) 1949 for (i--; i >= 0; i--)
1986 { 1950 {
1987 p->peers = GNUNET_realloc (p->peers, 1951 p->peers =
1988 sizeof (GNUNET_PEER_Id) * (p->length + 1)); 1952 GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * (p->length + 1));
1989 p->peers[p->length] = GNUNET_PEER_intern (get_path[i]); 1953 p->peers[p->length] = GNUNET_PEER_intern (get_path[i]);
1990 p->length++; 1954 p->length++;
1991 } 1955 }
1992 for (i = 0; put_path[i] != NULL; i++) ; 1956 for (i = 0; put_path[i] != NULL; i++) ;
1993 for (i--; i >= 0; i--) 1957 for (i--; i >= 0; i--)
1994 { 1958 {
1995 p->peers = GNUNET_realloc (p->peers, 1959 p->peers =
1996 sizeof (GNUNET_PEER_Id) * (p->length + 1)); 1960 GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * (p->length + 1));
1997 p->peers[p->length] = GNUNET_PEER_intern (put_path[i]); 1961 p->peers[p->length] = GNUNET_PEER_intern (put_path[i]);
1998 p->length++; 1962 p->length++;
1999 } 1963 }
2000 add_path_to_peer (peer_info, p); 1964 add_path_to_peer (peer_info, p);
2001 GNUNET_CORE_notify_transmit_ready (core_handle, 1965 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
2002 0, 1966 GNUNET_TIME_UNIT_FOREVER_REL, get_path[1],
2003 0,
2004 GNUNET_TIME_UNIT_FOREVER_REL,
2005 get_path[1],
2006 sizeof (struct GNUNET_MESH_ManipulatePath) 1967 sizeof (struct GNUNET_MESH_ManipulatePath)
2007 + (p->length 1968 +
2008 * sizeof (struct GNUNET_PeerIdentity)), 1969 (p->length *
1970 sizeof (struct GNUNET_PeerIdentity)),
2009 &send_core_create_path_for_peer, 1971 &send_core_create_path_for_peer,
2010 peer_info); 1972 peer_info);
2011 1973
@@ -2039,8 +2001,8 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
2039 { 2001 {
2040 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2002 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2041 " matching client found, cleaning\n"); 2003 " matching client found, cleaning\n");
2042 GNUNET_CONTAINER_multihashmap_iterate (c->tunnels, 2004 GNUNET_CONTAINER_multihashmap_iterate (c->tunnels, &delete_tunnel_entry,
2043 &delete_tunnel_entry, c); 2005 c);
2044 GNUNET_CONTAINER_multihashmap_destroy (c->tunnels); 2006 GNUNET_CONTAINER_multihashmap_destroy (c->tunnels);
2045 if (0 != c->app_counter) 2007 if (0 != c->app_counter)
2046 { /* deregister clients applications */ 2008 { /* deregister clients applications */
@@ -2055,10 +2017,10 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
2055 applications[j] = applications[n_applications - 1]; 2017 applications[j] = applications[n_applications - 1];
2056 applications_rc[j] = applications_rc[n_applications - 1]; 2018 applications_rc[j] = applications_rc[n_applications - 1];
2057 n_applications--; 2019 n_applications--;
2058 applications = GNUNET_realloc (applications, 2020 applications =
2059 n_applications * 2021 GNUNET_realloc (applications,
2060 sizeof 2022 n_applications *
2061 (GNUNET_MESH_ApplicationType)); 2023 sizeof (GNUNET_MESH_ApplicationType));
2062 applications_rc = 2024 applications_rc =
2063 GNUNET_realloc (applications_rc, 2025 GNUNET_realloc (applications_rc,
2064 n_applications * sizeof (unsigned int)); 2026 n_applications * sizeof (unsigned int));
@@ -2100,8 +2062,7 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
2100 * @param message the actual message, which includes messages the client wants 2062 * @param message the actual message, which includes messages the client wants
2101 */ 2063 */
2102static void 2064static void
2103handle_local_new_client (void *cls, 2065handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client,
2104 struct GNUNET_SERVER_Client *client,
2105 const struct GNUNET_MessageHeader *message) 2066 const struct GNUNET_MessageHeader *message)
2106{ 2067{
2107 struct GNUNET_MESH_ClientConnect *cc_msg; 2068 struct GNUNET_MESH_ClientConnect *cc_msg;
@@ -2140,8 +2101,7 @@ handle_local_new_client (void *cls,
2140 { 2101 {
2141 c->app_counter = apps; 2102 c->app_counter = apps;
2142 c->apps = GNUNET_malloc (apps * sizeof (GNUNET_MESH_ApplicationType)); 2103 c->apps = GNUNET_malloc (apps * sizeof (GNUNET_MESH_ApplicationType));
2143 memcpy (c->apps, 2104 memcpy (c->apps, &message[1] + types * sizeof (uint16_t),
2144 &message[1] + types * sizeof (uint16_t),
2145 apps * sizeof (GNUNET_MESH_ApplicationType)); 2105 apps * sizeof (GNUNET_MESH_ApplicationType));
2146 } 2106 }
2147 for (i = 0; i < apps; i++) 2107 for (i = 0; i < apps; i++)
@@ -2159,11 +2119,13 @@ handle_local_new_client (void *cls,
2159 if (!known) 2119 if (!known)
2160 { /* Register previously unknown application */ 2120 { /* Register previously unknown application */
2161 n_applications++; 2121 n_applications++;
2162 applications = GNUNET_realloc (applications, 2122 applications =
2163 n_applications * 2123 GNUNET_realloc (applications,
2164 sizeof (GNUNET_MESH_ApplicationType)); 2124 n_applications *
2165 applications_rc = GNUNET_realloc (applications_rc, 2125 sizeof (GNUNET_MESH_ApplicationType));
2166 n_applications * sizeof (unsigned int)); 2126 applications_rc =
2127 GNUNET_realloc (applications_rc,
2128 n_applications * sizeof (unsigned int));
2167 applications[n_applications - 1] = c->apps[i]; 2129 applications[n_applications - 1] = c->apps[i];
2168 applications_rc[n_applications - 1] = 1; 2130 applications_rc[n_applications - 1] = 1;
2169 if (0 == announce_applications_task) 2131 if (0 == announce_applications_task)
@@ -2174,8 +2136,7 @@ handle_local_new_client (void *cls,
2174 } 2136 }
2175 } 2137 }
2176 } 2138 }
2177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client has %u+%u subscriptions\n",
2178 " client has %u+%u subscriptions\n",
2179 c->type_counter, c->app_counter); 2140 c->type_counter, c->app_counter);
2180 2141
2181 GNUNET_CONTAINER_DLL_insert (clients, clients_tail, c); 2142 GNUNET_CONTAINER_DLL_insert (clients, clients_tail, c);
@@ -2195,8 +2156,7 @@ handle_local_new_client (void *cls,
2195 * @param message the actual message 2156 * @param message the actual message
2196 */ 2157 */
2197static void 2158static void
2198handle_local_tunnel_create (void *cls, 2159handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client,
2199 struct GNUNET_SERVER_Client *client,
2200 const struct GNUNET_MessageHeader *message) 2160 const struct GNUNET_MessageHeader *message)
2201{ 2161{
2202 struct GNUNET_MESH_TunnelMessage *t_msg; 2162 struct GNUNET_MESH_TunnelMessage *t_msg;
@@ -2278,8 +2238,7 @@ handle_local_tunnel_create (void *cls,
2278 * @param message the actual message 2238 * @param message the actual message
2279 */ 2239 */
2280static void 2240static void
2281handle_local_tunnel_destroy (void *cls, 2241handle_local_tunnel_destroy (void *cls, struct GNUNET_SERVER_Client *client,
2282 struct GNUNET_SERVER_Client *client,
2283 const struct GNUNET_MessageHeader *message) 2242 const struct GNUNET_MessageHeader *message)
2284{ 2243{
2285 struct GNUNET_MESH_TunnelMessage *tunnel_msg; 2244 struct GNUNET_MESH_TunnelMessage *tunnel_msg;
@@ -2332,8 +2291,7 @@ handle_local_tunnel_destroy (void *cls,
2332 * @param message the actual message (PeerControl) 2291 * @param message the actual message (PeerControl)
2333 */ 2292 */
2334static void 2293static void
2335handle_local_connect_add (void *cls, 2294handle_local_connect_add (void *cls, struct GNUNET_SERVER_Client *client,
2336 struct GNUNET_SERVER_Client *client,
2337 const struct GNUNET_MessageHeader *message) 2295 const struct GNUNET_MessageHeader *message)
2338{ 2296{
2339 struct GNUNET_MESH_PeerControl *peer_msg; 2297 struct GNUNET_MESH_PeerControl *peer_msg;
@@ -2406,8 +2364,7 @@ handle_local_connect_add (void *cls,
2406 * @param message the actual message (PeerControl) 2364 * @param message the actual message (PeerControl)
2407 */ 2365 */
2408static void 2366static void
2409handle_local_connect_del (void *cls, 2367handle_local_connect_del (void *cls, struct GNUNET_SERVER_Client *client,
2410 struct GNUNET_SERVER_Client *client,
2411 const struct GNUNET_MessageHeader *message) 2368 const struct GNUNET_MessageHeader *message)
2412{ 2369{
2413 struct GNUNET_MESH_PeerControl *peer_msg; 2370 struct GNUNET_MESH_PeerControl *peer_msg;
@@ -2466,8 +2423,7 @@ handle_local_connect_del (void *cls,
2466 * @param message the actual message (ConnectPeerByType) 2423 * @param message the actual message (ConnectPeerByType)
2467 */ 2424 */
2468static void 2425static void
2469handle_local_connect_by_type (void *cls, 2426handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client,
2470 struct GNUNET_SERVER_Client *client,
2471 const struct GNUNET_MessageHeader *message) 2427 const struct GNUNET_MessageHeader *message)
2472{ 2428{
2473 struct GNUNET_MESH_ConnectPeerByType *connect_msg; 2429 struct GNUNET_MESH_ConnectPeerByType *connect_msg;
@@ -2528,8 +2484,7 @@ handle_local_connect_by_type (void *cls,
2528 struct GNUNET_MESH_PeerControl pc; 2484 struct GNUNET_MESH_PeerControl pc;
2529 2485
2530 GNUNET_PEER_resolve (myid, &pc.peer); 2486 GNUNET_PEER_resolve (myid, &pc.peer);
2531 GNUNET_CONTAINER_multihashmap_put (t->peers, 2487 GNUNET_CONTAINER_multihashmap_put (t->peers, &pc.peer.hashPubKey,
2532 &pc.peer.hashPubKey,
2533 get_peer_info (&pc.peer), 2488 get_peer_info (&pc.peer),
2534 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 2489 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
2535 pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); 2490 pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
@@ -2546,14 +2501,11 @@ handle_local_connect_by_type (void *cls,
2546 { 2501 {
2547 GNUNET_DHT_get_stop (c->dht_get_type); 2502 GNUNET_DHT_get_stop (c->dht_get_type);
2548 } 2503 }
2549 c->dht_get_type = GNUNET_DHT_get_start (dht_handle, 2504 c->dht_get_type =
2550 GNUNET_TIME_UNIT_FOREVER_REL, 2505 GNUNET_DHT_get_start (dht_handle, GNUNET_TIME_UNIT_FOREVER_REL,
2551 GNUNET_BLOCK_TYPE_ANY, 2506 GNUNET_BLOCK_TYPE_ANY, &hash, 10U,
2552 &hash, 2507 GNUNET_DHT_RO_RECORD_ROUTE, NULL, 0, NULL, 0,
2553 10U, 2508 &dht_get_type_handler, t);
2554 GNUNET_DHT_RO_RECORD_ROUTE,
2555 NULL,
2556 0, NULL, 0, &dht_get_type_handler, t);
2557 2509
2558 GNUNET_SERVER_receive_done (client, GNUNET_OK); 2510 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2559 return; 2511 return;
@@ -2568,8 +2520,7 @@ handle_local_connect_by_type (void *cls,
2568 * @param message the actual message 2520 * @param message the actual message
2569 */ 2521 */
2570static void 2522static void
2571handle_local_unicast (void *cls, 2523handle_local_unicast (void *cls, struct GNUNET_SERVER_Client *client,
2572 struct GNUNET_SERVER_Client *client,
2573 const struct GNUNET_MessageHeader *message) 2524 const struct GNUNET_MessageHeader *message)
2574{ 2525{
2575 struct MeshClient *c; 2526 struct MeshClient *c;
@@ -2590,8 +2541,8 @@ handle_local_unicast (void *cls,
2590 } 2541 }
2591 data_msg = (struct GNUNET_MESH_Unicast *) message; 2542 data_msg = (struct GNUNET_MESH_Unicast *) message;
2592 /* Sanity check for message size */ 2543 /* Sanity check for message size */
2593 if (sizeof (struct GNUNET_MESH_Unicast) + sizeof (struct GNUNET_MessageHeader) 2544 if (sizeof (struct GNUNET_MESH_Unicast) +
2594 > ntohs (data_msg->header.size)) 2545 sizeof (struct GNUNET_MessageHeader) > ntohs (data_msg->header.size))
2595 { 2546 {
2596 GNUNET_break (0); 2547 GNUNET_break (0);
2597 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 2548 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -2645,9 +2596,8 @@ handle_local_unicast (void *cls,
2645 info->origin = &t->id; 2596 info->origin = &t->id;
2646 info->size = data_size; 2597 info->size = data_size;
2647 info->client = client; 2598 info->client = client;
2648 GNUNET_CORE_notify_transmit_ready (core_handle, 2599 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
2649 0, 2600 GNUNET_TIME_UNIT_FOREVER_REL, &next_hop,
2650 0, GNUNET_TIME_UNIT_FOREVER_REL, &next_hop,
2651 /* FIXME re-check types */ 2601 /* FIXME re-check types */
2652 data_size + 2602 data_size +
2653 sizeof (struct GNUNET_MESH_Unicast), 2603 sizeof (struct GNUNET_MESH_Unicast),
@@ -2663,8 +2613,7 @@ handle_local_unicast (void *cls,
2663 * @param message the actual message 2613 * @param message the actual message
2664 */ 2614 */
2665static void 2615static void
2666handle_local_multicast (void *cls, 2616handle_local_multicast (void *cls, struct GNUNET_SERVER_Client *client,
2667 struct GNUNET_SERVER_Client *client,
2668 const struct GNUNET_MessageHeader *message) 2617 const struct GNUNET_MessageHeader *message)
2669{ 2618{
2670 struct MeshClient *c; 2619 struct MeshClient *c;
@@ -2751,8 +2700,7 @@ static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = {
2751 * @param publicKey the public key of this peer 2700 * @param publicKey the public key of this peer
2752 */ 2701 */
2753static void 2702static void
2754core_init (void *cls, 2703core_init (void *cls, struct GNUNET_CORE_Handle *server,
2755 struct GNUNET_CORE_Handle *server,
2756 const struct GNUNET_PeerIdentity *identity, 2704 const struct GNUNET_PeerIdentity *identity,
2757 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) 2705 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
2758{ 2706{
@@ -2771,8 +2719,7 @@ core_init (void *cls,
2771 * @param atsi performance data for the connection 2719 * @param atsi performance data for the connection
2772 */ 2720 */
2773static void 2721static void
2774core_connect (void *cls, 2722core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
2775 const struct GNUNET_PeerIdentity *peer,
2776 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 2723 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
2777{ 2724{
2778// GNUNET_PEER_Id pid; 2725// GNUNET_PEER_Id pid;
@@ -2870,8 +2817,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2870 * @param c configuration to use 2817 * @param c configuration to use
2871 */ 2818 */
2872static void 2819static void
2873run (void *cls, 2820run (void *cls, struct GNUNET_SERVER_Handle *server,
2874 struct GNUNET_SERVER_Handle *server,
2875 const struct GNUNET_CONFIGURATION_Handle *c) 2821 const struct GNUNET_CONFIGURATION_Handle *c)
2876{ 2822{
2877 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting to run\n"); 2823 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting to run\n");
@@ -2919,8 +2865,8 @@ run (void *cls,
2919 announce_applications_task = 0; 2865 announce_applications_task = 0;
2920 2866
2921 /* Scheduled the task to clean up when shutdown is called */ 2867 /* Scheduled the task to clean up when shutdown is called */
2922 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 2868 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
2923 &shutdown_task, NULL); 2869 NULL);
2924 2870
2925 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "end of run()\n"); 2871 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "end of run()\n");
2926} 2872}
@@ -2937,11 +2883,10 @@ main (int argc, char *const *argv)
2937{ 2883{
2938 int ret; 2884 int ret;
2939 2885
2940 ret = (GNUNET_OK == 2886 ret =
2941 GNUNET_SERVICE_run (argc, 2887 (GNUNET_OK ==
2942 argv, 2888 GNUNET_SERVICE_run (argc, argv, "mesh", GNUNET_SERVICE_OPTION_NONE, &run,
2943 "mesh", 2889 NULL)) ? 0 : 1;
2944 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
2945 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "end of main()\n"); 2890 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "end of main()\n");
2946 return ret; 2891 return ret;
2947} 2892}
diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c
index 1ccd31dfe..3a50e44ee 100644
--- a/src/mesh/mesh_api.c
+++ b/src/mesh/mesh_api.c
@@ -171,8 +171,8 @@ call_connect_handler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
171} 171}
172 172
173static void 173static void
174core_startup (void *cls, 174core_startup (void *cls, struct GNUNET_CORE_Handle *core
175 struct GNUNET_CORE_Handle *core __attribute__ ((unused)), 175 __attribute__ ((unused)),
176 const struct GNUNET_PeerIdentity *my_identity, 176 const struct GNUNET_PeerIdentity *my_identity,
177 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey 177 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey
178 __attribute__ ((unused))) 178 __attribute__ ((unused)))
@@ -215,8 +215,7 @@ send_hello_message (void *cls, size_t size, void *buf)
215 * 215 *
216 */ 216 */
217static void 217static void
218core_connect (void *cls, 218core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
219 const struct GNUNET_PeerIdentity *peer,
220 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 219 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
221{ 220{
222 struct GNUNET_MESH_Handle *handle = cls; 221 struct GNUNET_MESH_Handle *handle = cls;
@@ -225,11 +224,8 @@ core_connect (void *cls,
225 "Core tells us we are connected to peer %s\n", GNUNET_i2s (peer)); 224 "Core tells us we are connected to peer %s\n", GNUNET_i2s (peer));
226 225
227 /* Send a hello to this peer */ 226 /* Send a hello to this peer */
228 GNUNET_CORE_notify_transmit_ready (handle->core, 227 GNUNET_CORE_notify_transmit_ready (handle->core, GNUNET_NO, 42,
229 GNUNET_NO, 228 GNUNET_TIME_UNIT_SECONDS, peer,
230 42,
231 GNUNET_TIME_UNIT_SECONDS,
232 peer,
233 sizeof (struct GNUNET_MessageHeader) + 229 sizeof (struct GNUNET_MessageHeader) +
234 handle->hello_message_size, 230 handle->hello_message_size,
235 &send_hello_message, cls); 231 &send_hello_message, cls);
@@ -347,8 +343,7 @@ core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
347 * This is a hello-message, containing the application-types the other peer can receive 343 * This is a hello-message, containing the application-types the other peer can receive
348 */ 344 */
349static int 345static int
350receive_hello (void *cls, 346receive_hello (void *cls, const struct GNUNET_PeerIdentity *other,
351 const struct GNUNET_PeerIdentity *other,
352 const struct GNUNET_MessageHeader *message, 347 const struct GNUNET_MessageHeader *message,
353 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 348 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
354{ 349{
@@ -434,8 +429,7 @@ receive_hello (void *cls,
434 * Receive a message from core. 429 * Receive a message from core.
435 */ 430 */
436static int 431static int
437core_receive (void *cls, 432core_receive (void *cls, const struct GNUNET_PeerIdentity *other,
438 const struct GNUNET_PeerIdentity *other,
439 const struct GNUNET_MessageHeader *message, 433 const struct GNUNET_MessageHeader *message,
440 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 434 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
441{ 435{
@@ -448,9 +442,9 @@ core_receive (void *cls,
448 442
449 for (handler = handle->handlers; handler->callback != NULL; handler++) 443 for (handler = handle->handlers; handler->callback != NULL; handler++)
450 { 444 {
451 if ((ntohs (rmessage->type) == handler->type) 445 if ((ntohs (rmessage->type) == handler->type) &&
452 && ((handler->expected_size == 0) 446 ((handler->expected_size == 0) ||
453 || (handler->expected_size == ntohs (rmessage->size)))) 447 (handler->expected_size == ntohs (rmessage->size))))
454 { 448 {
455 break; 449 break;
456 } 450 }
@@ -474,10 +468,10 @@ core_receive (void *cls,
474 if (tunnel->tunnel.id.id == tmessage->id.id && 468 if (tunnel->tunnel.id.id == tmessage->id.id &&
475 (0 == 469 (0 ==
476 memcmp (&tmessage->id.initiator, &tunnel->tunnel.id.initiator, 470 memcmp (&tmessage->id.initiator, &tunnel->tunnel.id.initiator,
477 sizeof (struct GNUNET_PeerIdentity))) 471 sizeof (struct GNUNET_PeerIdentity))) &&
478 && (0 == 472 (0 ==
479 memcmp (&tmessage->id.target, &tunnel->tunnel.id.target, 473 memcmp (&tmessage->id.target, &tunnel->tunnel.id.target,
480 sizeof (struct GNUNET_PeerIdentity)))) 474 sizeof (struct GNUNET_PeerIdentity))))
481 break; 475 break;
482 tunnel = tunnel->next; 476 tunnel = tunnel->next;
483 } 477 }
@@ -507,8 +501,8 @@ core_receive (void *cls,
507 "Inbound message from peer %s; type %d.\n", GNUNET_i2s (other), 501 "Inbound message from peer %s; type %d.\n", GNUNET_i2s (other),
508 ntohs (rmessage->type)); 502 ntohs (rmessage->type));
509 503
510 return handler->callback (handle->cls, &tunnel->tunnel, 504 return handler->callback (handle->cls, &tunnel->tunnel, &tunnel->tunnel.ctx,
511 &tunnel->tunnel.ctx, other, rmessage, atsi); 505 other, rmessage, atsi);
512} 506}
513 507
514struct GNUNET_MESH_Tunnel * 508struct GNUNET_MESH_Tunnel *
@@ -691,19 +685,13 @@ core_notify (void *cls, size_t size, void *buf)
691 * memory); if NULL is returned, "notify" will NOT be called. 685 * memory); if NULL is returned, "notify" will NOT be called.
692 */ 686 */
693struct GNUNET_MESH_TransmitHandle * 687struct GNUNET_MESH_TransmitHandle *
694GNUNET_MESH_notify_transmit_ready (struct 688GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork,
695 GNUNET_MESH_Tunnel
696 *tunnel,
697 int cork,
698 uint32_t priority, 689 uint32_t priority,
699 struct 690 struct GNUNET_TIME_Relative maxdelay,
700 GNUNET_TIME_Relative
701 maxdelay,
702 const struct GNUNET_PeerIdentity *target 691 const struct GNUNET_PeerIdentity *target
703 __attribute__ ((unused)), 692 __attribute__ ((unused)), size_t notify_size,
704 size_t notify_size, 693 GNUNET_CONNECTION_TransmitReadyNotify notify,
705 GNUNET_CONNECTION_TransmitReadyNotify 694 void *notify_cls)
706 notify, void *notify_cls)
707{ 695{
708 if (NULL != tunnel->notify_handle) 696 if (NULL != tunnel->notify_handle)
709 { 697 {
@@ -718,7 +706,8 @@ GNUNET_MESH_notify_transmit_ready (struct
718 cls->notify = notify; 706 cls->notify = notify;
719 cls->tunnel = tunnel; 707 cls->tunnel = tunnel;
720 708
721 tunnel->notify_handle = (struct GNUNET_MESH_TransmitHandle *) 709 tunnel->notify_handle =
710 (struct GNUNET_MESH_TransmitHandle *)
722 GNUNET_CORE_notify_transmit_ready (tunnel->handle->core, cork, priority, 711 GNUNET_CORE_notify_transmit_ready (tunnel->handle->core, cork, priority,
723 maxdelay, &tunnel->peer, 712 maxdelay, &tunnel->peer,
724 notify_size + 713 notify_size +
@@ -806,11 +795,8 @@ build_hello_message (struct GNUNET_MESH_Handle *handle,
806 795
807 796
808struct GNUNET_MESH_Handle * 797struct GNUNET_MESH_Handle *
809GNUNET_MESH_connect (const struct 798GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls,
810 GNUNET_CONFIGURATION_Handle 799 GNUNET_MESH_TunnelEndHandler cleaner,
811 *cfg, void *cls,
812 GNUNET_MESH_TunnelEndHandler
813 cleaner,
814 const struct GNUNET_MESH_MessageHandler *handlers, 800 const struct GNUNET_MESH_MessageHandler *handlers,
815 const GNUNET_MESH_ApplicationType *stypes) 801 const GNUNET_MESH_ApplicationType *stypes)
816{ 802{
@@ -845,15 +831,10 @@ GNUNET_MESH_connect (const struct
845 {NULL, 0, 0} 831 {NULL, 0, 0}
846 }; 832 };
847 833
848 ret->core = GNUNET_CORE_connect (cfg, 834 ret->core =
849 42, 835 GNUNET_CORE_connect (cfg, 42, ret, &core_startup, &core_connect,
850 ret, 836 &core_disconnect, NULL, NULL, GNUNET_NO, NULL,
851 &core_startup, 837 GNUNET_NO, core_handlers);
852 &core_connect,
853 &core_disconnect,
854 NULL,
855 NULL,
856 GNUNET_NO, NULL, GNUNET_NO, core_handlers);
857 return ret; 838 return ret;
858} 839}
859 840
diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c
index 83ac2a818..f765aca1c 100644
--- a/src/mesh/mesh_api_new.c
+++ b/src/mesh/mesh_api_new.c
@@ -239,18 +239,20 @@ send_connect_packet (void *cls, size_t size, void *buf)
239 239
240 for (napps = 0, apps = NULL; napps < h->n_applications; napps++) 240 for (napps = 0, apps = NULL; napps < h->n_applications; napps++)
241 { 241 {
242 apps = GNUNET_realloc (apps, 242 apps =
243 sizeof (GNUNET_MESH_ApplicationType) * (napps + 1)); 243 GNUNET_realloc (apps,
244 sizeof (GNUNET_MESH_ApplicationType) * (napps + 1));
244 apps[napps] = h->applications[napps]; 245 apps[napps] = h->applications[napps];
245 } 246 }
246 247
247 msg->header.size = htons (sizeof (struct GNUNET_MESH_ClientConnect) + 248 msg->header.size =
248 sizeof (uint16_t) * ntypes + 249 htons (sizeof (struct GNUNET_MESH_ClientConnect) +
249 sizeof (GNUNET_MESH_ApplicationType) * napps); 250 sizeof (uint16_t) * ntypes +
251 sizeof (GNUNET_MESH_ApplicationType) * napps);
250 252
251 memcpy (&msg[1], types, sizeof (uint16_t) * ntypes); 253 memcpy (&msg[1], types, sizeof (uint16_t) * ntypes);
252 memcpy (&msg[1] + sizeof (uint16_t) * ntypes, 254 memcpy (&msg[1] + sizeof (uint16_t) * ntypes, apps,
253 apps, sizeof (GNUNET_MESH_ApplicationType) * napps); 255 sizeof (GNUNET_MESH_ApplicationType) * napps);
254 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
255 "Sent %lu bytes long message %d types and %d apps\n", 257 "Sent %lu bytes long message %d types and %d apps\n",
256 ntohs (msg->header.size), ntypes, napps); 258 ntohs (msg->header.size), ntypes, napps);
@@ -303,8 +305,8 @@ send_tunnel_create_packet (void *cls, size_t size, void *buf)
303 msg->header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); 305 msg->header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
304 msg->tunnel_id = htonl (t->tid); 306 msg->tunnel_id = htonl (t->tid);
305 307
306 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 308 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent %lu bytes long message\n",
307 "Sent %lu bytes long message\n", ntohs (msg->header.size)); 309 ntohs (msg->header.size));
308 310
309 return ntohs (msg->header.size); 311 return ntohs (msg->header.size);
310} 312}
@@ -502,8 +504,8 @@ msg_received (void *cls, const struct GNUNET_MessageHeader *msg)
502 } 504 }
503 505
504 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "received a message from mesh\n"); 506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "received a message from mesh\n");
505 GNUNET_CLIENT_receive (h->client, 507 GNUNET_CLIENT_receive (h->client, &msg_received, h,
506 &msg_received, h, GNUNET_TIME_UNIT_FOREVER_REL); 508 GNUNET_TIME_UNIT_FOREVER_REL);
507 return; 509 return;
508} 510}
509 511
@@ -527,8 +529,7 @@ msg_received (void *cls, const struct GNUNET_MessageHeader *msg)
527 * NULL on error (in this case, init is never called) 529 * NULL on error (in this case, init is never called)
528 */ 530 */
529struct GNUNET_MESH_Handle * 531struct GNUNET_MESH_Handle *
530GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 532GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls,
531 void *cls,
532 GNUNET_MESH_TunnelEndHandler cleaner, 533 GNUNET_MESH_TunnelEndHandler cleaner,
533 const struct GNUNET_MESH_MessageHandler *handlers, 534 const struct GNUNET_MESH_MessageHandler *handlers,
534 const GNUNET_MESH_ApplicationType *stypes) 535 const GNUNET_MESH_ApplicationType *stypes)
@@ -540,8 +541,8 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
540 541
541 h->cleaner = cleaner; 542 h->cleaner = cleaner;
542 h->client = GNUNET_CLIENT_connect ("mesh", cfg); 543 h->client = GNUNET_CLIENT_connect ("mesh", cfg);
543 GNUNET_CLIENT_receive (h->client, 544 GNUNET_CLIENT_receive (h->client, &msg_received, h,
544 &msg_received, h, GNUNET_TIME_UNIT_FOREVER_REL); 545 GNUNET_TIME_UNIT_FOREVER_REL);
545 if (h->client == NULL) 546 if (h->client == NULL)
546 { 547 {
547 GNUNET_free (h); 548 GNUNET_free (h);
@@ -560,12 +561,11 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
560 size += h->n_handlers * sizeof (uint16_t); 561 size += h->n_handlers * sizeof (uint16_t);
561 size += h->n_applications * sizeof (GNUNET_MESH_ApplicationType); 562 size += h->n_applications * sizeof (GNUNET_MESH_ApplicationType);
562 563
563 h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, 564 h->th =
564 size, 565 GNUNET_CLIENT_notify_transmit_ready (h->client, size,
565 GNUNET_TIME_UNIT_FOREVER_REL, 566 GNUNET_TIME_UNIT_FOREVER_REL,
566 GNUNET_YES, 567 GNUNET_YES, &send_connect_packet,
567 &send_connect_packet, 568 (void *) h);
568 (void *) h);
569 569
570 return h; 570 return h;
571} 571}
@@ -602,8 +602,7 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
602 */ 602 */
603struct GNUNET_MESH_Tunnel * 603struct GNUNET_MESH_Tunnel *
604GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, 604GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h,
605 GNUNET_MESH_TunnelConnectHandler 605 GNUNET_MESH_TunnelConnectHandler connect_handler,
606 connect_handler,
607 GNUNET_MESH_TunnelDisconnectHandler 606 GNUNET_MESH_TunnelDisconnectHandler
608 disconnect_handler, void *handler_cls) 607 disconnect_handler, void *handler_cls)
609{ 608{
@@ -619,13 +618,14 @@ GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h,
619 tunnel->tid = h->next_tid++; 618 tunnel->tid = h->next_tid++;
620 h->next_tid |= GNUNET_MESH_LOCAL_TUNNEL_ID_MARK; // keep in range 619 h->next_tid |= GNUNET_MESH_LOCAL_TUNNEL_ID_MARK; // keep in range
621 620
622 h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, 621 h->th =
623 sizeof (struct 622 GNUNET_CLIENT_notify_transmit_ready (h->client,
624 GNUNET_MESH_TunnelMessage), 623 sizeof (struct
625 GNUNET_TIME_UNIT_FOREVER_REL, 624 GNUNET_MESH_TunnelMessage),
626 GNUNET_YES, 625 GNUNET_TIME_UNIT_FOREVER_REL,
627 &send_tunnel_create_packet, 626 GNUNET_YES,
628 (void *) tunnel); 627 &send_tunnel_create_packet,
628 (void *) tunnel);
629 629
630 return tunnel; 630 return tunnel;
631} 631}
@@ -714,14 +714,13 @@ GNUNET_MESH_peer_request_connect_by_type (struct GNUNET_MESH_Tunnel *tunnel,
714 * memory); if NULL is returned, "notify" will NOT be called. 714 * memory); if NULL is returned, "notify" will NOT be called.
715 */ 715 */
716struct GNUNET_MESH_TransmitHandle * 716struct GNUNET_MESH_TransmitHandle *
717GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, 717GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork,
718 int cork,
719 uint32_t priority, 718 uint32_t priority,
720 struct GNUNET_TIME_Relative maxdelay, 719 struct GNUNET_TIME_Relative maxdelay,
721 const struct GNUNET_PeerIdentity *target, 720 const struct GNUNET_PeerIdentity *target,
722 size_t notify_size, 721 size_t notify_size,
723 GNUNET_CONNECTION_TransmitReadyNotify 722 GNUNET_CONNECTION_TransmitReadyNotify notify,
724 notify, void *notify_cls) 723 void *notify_cls)
725{ 724{
726 struct GNUNET_MESH_TransmitHandle *handle; 725 struct GNUNET_MESH_TransmitHandle *handle;
727 726
diff --git a/src/mesh/test_mesh_api.c b/src/mesh/test_mesh_api.c
index 9828ee8d9..c5f0e9f0f 100644
--- a/src/mesh/test_mesh_api.c
+++ b/src/mesh/test_mesh_api.c
@@ -51,9 +51,7 @@ GNUNET_SCHEDULER_TaskIdentifier test_task;
51 * GNUNET_SYSERR to close it (signal serious error) 51 * GNUNET_SYSERR to close it (signal serious error)
52 */ 52 */
53static int 53static int
54callback (void *cls, 54callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx,
55 struct GNUNET_MESH_Tunnel *tunnel,
56 void **tunnel_ctx,
57 const struct GNUNET_PeerIdentity *sender, 55 const struct GNUNET_PeerIdentity *sender,
58 const struct GNUNET_MessageHeader *message, 56 const struct GNUNET_MessageHeader *message,
59 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 57 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
@@ -125,16 +123,16 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
125 123
126 124
127static void 125static void
128run (void *cls, 126run (void *cls, char *const *args, const char *cfgfile,
129 char *const *args, 127 const struct GNUNET_CONFIGURATION_Handle *cfg)
130 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
131{ 128{
132 arm_pid = GNUNET_OS_start_process (NULL, NULL, 129 arm_pid =
133 "gnunet-service-arm", "gnunet-service-arm", 130 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
131 "gnunet-service-arm",
134#if VERBOSE_ARM 132#if VERBOSE_ARM
135 "-L", "DEBUG", 133 "-L", "DEBUG",
136#endif 134#endif
137 "-c", "test_mesh.conf", NULL); 135 "-c", "test_mesh.conf", NULL);
138 136
139 abort_task = 137 abort_task =
140 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 138 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
@@ -170,14 +168,14 @@ main (int argc, char *argv[])
170 "WARNING", 168 "WARNING",
171#endif 169#endif
172 NULL); 170 NULL);
173 ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, 171 ret =
174 argv2, "test-mesh-api", "nohelp", 172 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
175 options, &run, NULL); 173 "test-mesh-api", "nohelp", options, &run, NULL);
176 174
177 if (GNUNET_OK != ret) 175 if (GNUNET_OK != ret)
178 { 176 {
179 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 177 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "run failed with error code %d\n",
180 "run failed with error code %d\n", ret); 178 ret);
181 return 1; 179 return 1;
182 } 180 }
183 if (GNUNET_SYSERR == result) 181 if (GNUNET_SYSERR == result)
diff --git a/src/mesh/test_mesh_small.c b/src/mesh/test_mesh_small.c
index d0d394177..fe0ca631d 100644
--- a/src/mesh/test_mesh_small.c
+++ b/src/mesh/test_mesh_small.c
@@ -213,8 +213,8 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
213} 213}
214 214
215 215
216static void 216static void churn_peers (void *cls,
217churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 217 const struct GNUNET_SCHEDULER_TaskContext *tc);
218 218
219 219
220/** 220/**
@@ -235,9 +235,9 @@ stats_finished_callback (void *cls, int success)
235 { 235 {
236 /* Stats lookup successful, write out data */ 236 /* Stats lookup successful, write out data */
237 buf = NULL; 237 buf = NULL;
238 buf_len = GNUNET_asprintf (&buf, 238 buf_len =
239 "TOTAL_MESH_BYTES: %u\n", 239 GNUNET_asprintf (&buf, "TOTAL_MESH_BYTES: %u\n",
240 stats_context->total_mesh_bytes); 240 stats_context->total_mesh_bytes);
241 if (buf_len > 0) 241 if (buf_len > 0)
242 { 242 {
243 GNUNET_DISK_file_write (data_file, buf, buf_len); 243 GNUNET_DISK_file_write (data_file, buf, buf_len);
@@ -263,10 +263,9 @@ stats_finished_callback (void *cls, int success)
263 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration 263 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
264 */ 264 */
265static int 265static int
266statistics_iterator (void *cls, 266statistics_iterator (void *cls, const struct GNUNET_PeerIdentity *peer,
267 const struct GNUNET_PeerIdentity *peer, 267 const char *subsystem, const char *name, uint64_t value,
268 const char *subsystem, 268 int is_persistent)
269 const char *name, uint64_t value, int is_persistent)
270{ 269{
271 struct StatsContext *stats_context = cls; 270 struct StatsContext *stats_context = cls;
272 271
@@ -300,10 +299,9 @@ disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
300// } 299// }
301 300
302 GNUNET_asprintf (&buf, "round%llu", current_round); 301 GNUNET_asprintf (&buf, "round%llu", current_round);
303 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (testing_cfg, 302 if (GNUNET_OK ==
304 "test_mesh_small", 303 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small",
305 buf, 304 buf, &peers_next_round))
306 &peers_next_round))
307 { 305 {
308 current_round++; 306 current_round++;
309 GNUNET_assert (churn_task == GNUNET_SCHEDULER_NO_TASK); 307 GNUNET_assert (churn_task == GNUNET_SCHEDULER_NO_TASK);
@@ -314,8 +312,7 @@ disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
314 stats_context = GNUNET_malloc (sizeof (struct StatsContext)); 312 stats_context = GNUNET_malloc (sizeof (struct StatsContext));
315 GNUNET_SCHEDULER_cancel (shutdown_handle); 313 GNUNET_SCHEDULER_cancel (shutdown_handle);
316 shutdown_handle = GNUNET_SCHEDULER_NO_TASK; 314 shutdown_handle = GNUNET_SCHEDULER_NO_TASK;
317 GNUNET_TESTING_get_statistics (pg, 315 GNUNET_TESTING_get_statistics (pg, &stats_finished_callback,
318 &stats_finished_callback,
319 &statistics_iterator, stats_context); 316 &statistics_iterator, stats_context);
320 } 317 }
321 GNUNET_free (buf); 318 GNUNET_free (buf);
@@ -331,8 +328,8 @@ disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
331static void 328static void
332topology_output_callback (void *cls, const char *emsg) 329topology_output_callback (void *cls, const char *emsg)
333{ 330{
334 disconnect_task = GNUNET_SCHEDULER_add_delayed (wait_time, 331 disconnect_task =
335 &disconnect_mesh_peers, NULL); 332 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL);
336 GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL); 333 GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL);
337} 334}
338 335
@@ -354,19 +351,18 @@ churn_callback (void *cls, const char *emsg)
354 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 351 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
355 "Round %llu, churn finished successfully.\n", current_round); 352 "Round %llu, churn finished successfully.\n", current_round);
356 GNUNET_assert (disconnect_task == GNUNET_SCHEDULER_NO_TASK); 353 GNUNET_assert (disconnect_task == GNUNET_SCHEDULER_NO_TASK);
357 GNUNET_asprintf (&temp_output_file, 354 GNUNET_asprintf (&temp_output_file, "%s_%llu.dot", topology_file,
358 "%s_%llu.dot", topology_file, current_round); 355 current_round);
359 GNUNET_TESTING_peergroup_topology_to_file (pg, 356 GNUNET_TESTING_peergroup_topology_to_file (pg, temp_output_file,
360 temp_output_file,
361 &topology_output_callback, NULL); 357 &topology_output_callback, NULL);
362 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 358 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Writing topology to file %s\n",
363 "Writing topology to file %s\n", temp_output_file); 359 temp_output_file);
364 GNUNET_free (temp_output_file); 360 GNUNET_free (temp_output_file);
365 } 361 }
366 else 362 else
367 { 363 {
368 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 364 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Round %llu, churn FAILED!!\n",
369 "Round %llu, churn FAILED!!\n", current_round); 365 current_round);
370 GNUNET_SCHEDULER_cancel (shutdown_handle); 366 GNUNET_SCHEDULER_cancel (shutdown_handle);
371 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 367 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
372 } 368 }
@@ -383,9 +379,8 @@ churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
383 /* Nothing to do... */ 379 /* Nothing to do... */
384 GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL); 380 GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL);
385 GNUNET_assert (disconnect_task == GNUNET_SCHEDULER_NO_TASK); 381 GNUNET_assert (disconnect_task == GNUNET_SCHEDULER_NO_TASK);
386 disconnect_task = GNUNET_SCHEDULER_add_delayed (wait_time, 382 disconnect_task =
387 &disconnect_mesh_peers, 383 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL);
388 NULL);
389 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Round %lu, doing nothing!\n", 384 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Round %lu, doing nothing!\n",
390 current_round); 385 current_round);
391 } 386 }
@@ -401,18 +396,18 @@ churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
401 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 396 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
402 "Round %llu, turning off %llu peers, turning on %llu peers!\n", 397 "Round %llu, turning off %llu peers, turning on %llu peers!\n",
403 current_round, 398 current_round,
404 (peers_running > peers_next_round) 399 (peers_running >
405 ? peers_running - peers_next_round 400 peers_next_round) ? peers_running - peers_next_round : 0,
406 : 0, 401 (peers_next_round >
407 (peers_next_round > peers_running) 402 peers_running) ? peers_next_round - peers_running : 0);
408 ? peers_next_round - peers_running : 0);
409 GNUNET_TESTING_daemons_churn (pg, "nse", 403 GNUNET_TESTING_daemons_churn (pg, "nse",
410 (peers_running > peers_next_round) 404 (peers_running >
411 ? peers_running - peers_next_round 405 peers_next_round) ? peers_running -
412 : 0, 406 peers_next_round : 0,
413 (peers_next_round > peers_running) 407 (peers_next_round >
414 ? peers_next_round - peers_running 408 peers_running) ? peers_next_round -
415 : 0, wait_time, &churn_callback, NULL); 409 peers_running : 0, wait_time, &churn_callback,
410 NULL);
416 } 411 }
417} 412}
418 413
@@ -435,8 +430,8 @@ my_cb (void *cls, const char *emsg)
435#if VERBOSE 430#if VERBOSE
436 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer Group started successfully!\n"); 431 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer Group started successfully!\n");
437#endif 432#endif
438 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 433 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Have %u connections\n",
439 "Have %u connections\n", total_connections); 434 total_connections);
440 if (data_file != NULL) 435 if (data_file != NULL)
441 { 436 {
442 buf = NULL; 437 buf = NULL;
@@ -469,10 +464,8 @@ my_cb (void *cls, const char *emsg)
469 * @param emsg error message (NULL on success) 464 * @param emsg error message (NULL on success)
470 */ 465 */
471static void 466static void
472connect_cb (void *cls, 467connect_cb (void *cls, const struct GNUNET_PeerIdentity *first,
473 const struct GNUNET_PeerIdentity *first, 468 const struct GNUNET_PeerIdentity *second, uint32_t distance,
474 const struct GNUNET_PeerIdentity *second,
475 uint32_t distance,
476 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 469 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
477 const struct GNUNET_CONFIGURATION_Handle *second_cfg, 470 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
478 struct GNUNET_TESTING_Daemon *first_daemon, 471 struct GNUNET_TESTING_Daemon *first_daemon,
@@ -484,9 +477,8 @@ connect_cb (void *cls,
484 477
485 478
486static void 479static void
487run (void *cls, 480run (void *cls, char *const *args, const char *cfgfile,
488 char *const *args, 481 const struct GNUNET_CONFIGURATION_Handle *cfg)
489 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
490{ 482{
491 char *temp_str; 483 char *temp_str;
492 unsigned long long temp_wait; 484 unsigned long long temp_wait;
@@ -496,82 +488,80 @@ run (void *cls,
496 testing_cfg = (struct GNUNET_CONFIGURATION_Handle *) cfg; // GNUNET_CONFIGURATION_create(); 488 testing_cfg = (struct GNUNET_CONFIGURATION_Handle *) cfg; // GNUNET_CONFIGURATION_create();
497#if VERBOSE 489#if VERBOSE
498 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n"); 490 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n");
499 GNUNET_CONFIGURATION_set_value_string (testing_cfg, 491 GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing",
500 "testing", "use_progressbars", "YES"); 492 "use_progressbars", "YES");
501#endif 493#endif
502 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg, 494 if (GNUNET_OK !=
503 "testing", 495 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing",
504 "num_peers", 496 "num_peers", &num_peers))
505 &num_peers))
506 { 497 {
507 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 498 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
508 "Option TESTING:NUM_PEERS is required!\n"); 499 "Option TESTING:NUM_PEERS is required!\n");
509 return; 500 return;
510 } 501 }
511 502
512 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg, 503 if (GNUNET_OK !=
513 "test_mesh_small", 504 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small",
514 "wait_time", 505 "wait_time", &temp_wait))
515 &temp_wait))
516 { 506 {
517 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 507 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
518 "Option nsetest_mesh_small:wait_time is required!\n"); 508 "Option nsetest_mesh_small:wait_time is required!\n");
519 return; 509 return;
520 } 510 }
521 511
522 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (testing_cfg, 512 if (GNUNET_OK !=
523 "testing", 513 GNUNET_CONFIGURATION_get_value_string (testing_cfg, "testing",
524 "topology_output_file", 514 "topology_output_file",
525 &topology_file)) 515 &topology_file))
526 { 516 {
527 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 517 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
528 "Option test_mesh_small:topology_output_file is required!\n"); 518 "Option test_mesh_small:topology_output_file is required!\n");
529 return; 519 return;
530 } 520 }
531 521
532 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (testing_cfg, 522 if (GNUNET_OK !=
533 "test_mesh_small", 523 GNUNET_CONFIGURATION_get_value_string (testing_cfg, "test_mesh_small",
534 "data_output_file", 524 "data_output_file",
535 &data_filename)) 525 &data_filename))
536 { 526 {
537 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 527 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
538 "Option test_mesh_small:data_output_file is required!\n"); 528 "Option test_mesh_small:data_output_file is required!\n");
539 return; 529 return;
540 } 530 }
541 531
542 data_file = GNUNET_DISK_file_open (data_filename, 532 data_file =
543 GNUNET_DISK_OPEN_READWRITE 533 GNUNET_DISK_file_open (data_filename,
544 | GNUNET_DISK_OPEN_CREATE, 534 GNUNET_DISK_OPEN_READWRITE |
545 GNUNET_DISK_PERM_USER_READ | 535 GNUNET_DISK_OPEN_CREATE,
546 GNUNET_DISK_PERM_USER_WRITE); 536 GNUNET_DISK_PERM_USER_READ |
537 GNUNET_DISK_PERM_USER_WRITE);
547 if (data_file == NULL) 538 if (data_file == NULL)
548 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 539 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
549 "Failed to open %s for output!\n", data_filename); 540 data_filename);
550 GNUNET_free (data_filename); 541 GNUNET_free (data_filename);
551 542
552 wait_time = 543 wait_time =
553 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_wait); 544 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_wait);
554 545
555 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg, 546 if (GNUNET_YES ==
556 "test_mesh_small", 547 GNUNET_CONFIGURATION_get_value_string (cfg, "test_mesh_small",
557 "output_file", 548 "output_file", &temp_str))
558 &temp_str))
559 { 549 {
560 output_file = GNUNET_DISK_file_open (temp_str, GNUNET_DISK_OPEN_READWRITE 550 output_file =
561 | GNUNET_DISK_OPEN_CREATE, 551 GNUNET_DISK_file_open (temp_str,
562 GNUNET_DISK_PERM_USER_READ | 552 GNUNET_DISK_OPEN_READWRITE |
563 GNUNET_DISK_PERM_USER_WRITE); 553 GNUNET_DISK_OPEN_CREATE,
554 GNUNET_DISK_PERM_USER_READ |
555 GNUNET_DISK_PERM_USER_WRITE);
564 if (output_file == NULL) 556 if (output_file == NULL)
565 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 557 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
566 "Failed to open %s for output!\n", temp_str); 558 temp_str);
567 } 559 }
568 GNUNET_free_non_null (temp_str); 560 GNUNET_free_non_null (temp_str);
569 561
570 hosts = GNUNET_TESTING_hosts_load (testing_cfg); 562 hosts = GNUNET_TESTING_hosts_load (testing_cfg);
571 563
572 pg = GNUNET_TESTING_peergroup_start (testing_cfg, 564 pg = GNUNET_TESTING_peergroup_start (testing_cfg, num_peers, TIMEOUT,
573 num_peers,
574 TIMEOUT,
575 &connect_cb, &my_cb, NULL, hosts); 565 &connect_cb, &my_cb, NULL, hosts);
576 GNUNET_assert (pg != NULL); 566 GNUNET_assert (pg != NULL);
577 shutdown_handle = 567 shutdown_handle =
@@ -602,10 +592,9 @@ main (int argc, char *argv[])
602 "WARNING", 592 "WARNING",
603#endif 593#endif
604 NULL); 594 NULL);
605 GNUNET_PROGRAM_run (argc, 595 GNUNET_PROGRAM_run (argc, argv, "test_mesh_small",
606 argv, "test_mesh_small", 596 gettext_noop ("Test mesh in a small network."), options,
607 gettext_noop ("Test mesh in a small network."), 597 &run, NULL);
608 options, &run, NULL);
609#if REMOVE_DIR 598#if REMOVE_DIR
610 GNUNET_DISK_directory_remove ("/tmp/test_mesh_small"); 599 GNUNET_DISK_directory_remove ("/tmp/test_mesh_small");
611#endif 600#endif
diff --git a/src/nat/gnunet-helper-nat-client-windows.c b/src/nat/gnunet-helper-nat-client-windows.c
index 0fa62ff7c..864c911b0 100644
--- a/src/nat/gnunet-helper-nat-client-windows.c
+++ b/src/nat/gnunet-helper-nat-client-windows.c
@@ -258,8 +258,8 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other)
258 ip_pkt.checksum = 0; 258 ip_pkt.checksum = 0;
259 ip_pkt.src_ip = my_ip->s_addr; 259 ip_pkt.src_ip = my_ip->s_addr;
260 ip_pkt.dst_ip = other->s_addr; 260 ip_pkt.dst_ip = other->s_addr;
261 ip_pkt.checksum = htons (calc_checksum ((uint16_t *) & ip_pkt, 261 ip_pkt.checksum =
262 sizeof (struct ip_header))); 262 htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header)));
263 memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); 263 memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
264 off += sizeof (struct ip_header); 264 off += sizeof (struct ip_header);
265 265
@@ -273,8 +273,8 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other)
273 /* ip header of the presumably 'lost' udp packet */ 273 /* ip header of the presumably 'lost' udp packet */
274 ip_pkt.vers_ihl = 0x45; 274 ip_pkt.vers_ihl = 0x45;
275 ip_pkt.tos = 0; 275 ip_pkt.tos = 0;
276 ip_pkt.pkt_len = htons (sizeof (struct ip_header) + 276 ip_pkt.pkt_len =
277 sizeof (struct udp_header)); 277 htons (sizeof (struct ip_header) + sizeof (struct udp_header));
278 ip_pkt.id = htons (0); 278 ip_pkt.id = htons (0);
279 ip_pkt.flags_frag_offset = 0; 279 ip_pkt.flags_frag_offset = 0;
280 ip_pkt.ttl = 128; 280 ip_pkt.ttl = 128;
@@ -282,8 +282,8 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other)
282 ip_pkt.checksum = 0; 282 ip_pkt.checksum = 0;
283 ip_pkt.src_ip = other->s_addr; 283 ip_pkt.src_ip = other->s_addr;
284 ip_pkt.dst_ip = dummy.s_addr; 284 ip_pkt.dst_ip = dummy.s_addr;
285 ip_pkt.checksum = htons (calc_checksum ((uint16_t *) & ip_pkt, 285 ip_pkt.checksum =
286 sizeof (struct ip_header))); 286 htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header)));
287 memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); 287 memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
288 off += sizeof (struct ip_header); 288 off += sizeof (struct ip_header);
289 289
@@ -296,20 +296,20 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other)
296 off += sizeof (struct udp_header); 296 off += sizeof (struct udp_header);
297 297
298 /* no go back to calculate ICMP packet checksum */ 298 /* no go back to calculate ICMP packet checksum */
299 icmp_pkt.checksum = htons (calc_checksum ((uint16_t *) & packet[off], 299 icmp_pkt.checksum =
300 sizeof (struct 300 htons (calc_checksum
301 icmp_ttl_exceeded_header) + 301 ((uint16_t *) & packet[off],
302 sizeof (struct ip_header) + 302 sizeof (struct icmp_ttl_exceeded_header) +
303 sizeof (struct udp_header))); 303 sizeof (struct ip_header) + sizeof (struct udp_header)));
304 memcpy (&packet[sizeof (struct ip_header)], &icmp_pkt, 304 memcpy (&packet[sizeof (struct ip_header)], &icmp_pkt,
305 sizeof (struct icmp_ttl_exceeded_header)); 305 sizeof (struct icmp_ttl_exceeded_header));
306 306
307 memset (&dst, 0, sizeof (dst)); 307 memset (&dst, 0, sizeof (dst));
308 dst.sin_family = AF_INET; 308 dst.sin_family = AF_INET;
309 dst.sin_addr = *other; 309 dst.sin_addr = *other;
310 err = sendto (rawsock, 310 err =
311 packet, 311 sendto (rawsock, packet, sizeof (packet), 0, (struct sockaddr *) &dst,
312 sizeof (packet), 0, (struct sockaddr *) &dst, sizeof (dst)); 312 sizeof (dst));
313 if (err < 0) 313 if (err < 0)
314 { 314 {
315 fprintf (stderr, "sendto failed: %s\n", strerror (errno)); 315 fprintf (stderr, "sendto failed: %s\n", strerror (errno));
@@ -352,8 +352,8 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other)
352 ip_pkt.checksum = 0; 352 ip_pkt.checksum = 0;
353 ip_pkt.src_ip = my_ip->s_addr; 353 ip_pkt.src_ip = my_ip->s_addr;
354 ip_pkt.dst_ip = other->s_addr; 354 ip_pkt.dst_ip = other->s_addr;
355 ip_pkt.checksum = htons (calc_checksum ((uint16_t *) & ip_pkt, 355 ip_pkt.checksum =
356 sizeof (struct ip_header))); 356 htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header)));
357 memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); 357 memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
358 off += sizeof (ip_pkt); 358 off += sizeof (ip_pkt);
359 359
@@ -377,8 +377,8 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other)
377 ip_pkt.src_ip = other->s_addr; 377 ip_pkt.src_ip = other->s_addr;
378 ip_pkt.dst_ip = dummy.s_addr; 378 ip_pkt.dst_ip = dummy.s_addr;
379 ip_pkt.checksum = 0; 379 ip_pkt.checksum = 0;
380 ip_pkt.checksum = htons (calc_checksum ((uint16_t *) & ip_pkt, 380 ip_pkt.checksum =
381 sizeof (struct ip_header))); 381 htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header)));
382 memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); 382 memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
383 off += sizeof (struct ip_header); 383 off += sizeof (struct ip_header);
384 384
@@ -386,26 +386,27 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other)
386 icmp_echo.code = 0; 386 icmp_echo.code = 0;
387 icmp_echo.reserved = htonl (port); 387 icmp_echo.reserved = htonl (port);
388 icmp_echo.checksum = 0; 388 icmp_echo.checksum = 0;
389 icmp_echo.checksum = htons (calc_checksum ((uint16_t *) & icmp_echo, 389 icmp_echo.checksum =
390 sizeof (struct icmp_echo_header))); 390 htons (calc_checksum
391 ((uint16_t *) & icmp_echo, sizeof (struct icmp_echo_header)));
391 memcpy (&packet[off], &icmp_echo, sizeof (struct icmp_echo_header)); 392 memcpy (&packet[off], &icmp_echo, sizeof (struct icmp_echo_header));
392 393
393 /* no go back to calculate ICMP packet checksum */ 394 /* no go back to calculate ICMP packet checksum */
394 off = sizeof (struct ip_header); 395 off = sizeof (struct ip_header);
395 icmp_ttl.checksum = htons (calc_checksum ((uint16_t *) & packet[off], 396 icmp_ttl.checksum =
396 sizeof (struct 397 htons (calc_checksum
397 icmp_ttl_exceeded_header) + 398 ((uint16_t *) & packet[off],
398 sizeof (struct ip_header) + 399 sizeof (struct icmp_ttl_exceeded_header) +
399 sizeof (struct icmp_echo_header))); 400 sizeof (struct ip_header) + sizeof (struct icmp_echo_header)));
400 memcpy (&packet[off], &icmp_ttl, sizeof (struct icmp_ttl_exceeded_header)); 401 memcpy (&packet[off], &icmp_ttl, sizeof (struct icmp_ttl_exceeded_header));
401 402
402 memset (&dst, 0, sizeof (dst)); 403 memset (&dst, 0, sizeof (dst));
403 dst.sin_family = AF_INET; 404 dst.sin_family = AF_INET;
404 dst.sin_addr = *other; 405 dst.sin_addr = *other;
405 406
406 err = sendto (rawsock, 407 err =
407 packet, 408 sendto (rawsock, packet, sizeof (packet), 0, (struct sockaddr *) &dst,
408 sizeof (packet), 0, (struct sockaddr *) &dst, sizeof (dst)); 409 sizeof (dst));
409 410
410 if (err < 0) 411 if (err < 0)
411 { 412 {
@@ -439,8 +440,8 @@ make_raw_socket ()
439 if (0 != 440 if (0 !=
440 setsockopt (ret, SOL_SOCKET, SO_BROADCAST, (char *) &bOptVal, bOptLen)) 441 setsockopt (ret, SOL_SOCKET, SO_BROADCAST, (char *) &bOptVal, bOptLen))
441 { 442 {
442 fprintf (stderr, 443 fprintf (stderr, "Error setting SO_BROADCAST to ON: %s\n",
443 "Error setting SO_BROADCAST to ON: %s\n", strerror (errno)); 444 strerror (errno));
444 closesocket (rawsock); 445 closesocket (rawsock);
445 return INVALID_SOCKET; 446 return INVALID_SOCKET;
446 } 447 }
diff --git a/src/nat/gnunet-helper-nat-client.c b/src/nat/gnunet-helper-nat-client.c
index 76f405bf1..fbebdbc0f 100644
--- a/src/nat/gnunet-helper-nat-client.c
+++ b/src/nat/gnunet-helper-nat-client.c
@@ -235,8 +235,8 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other)
235 ip_pkt.checksum = 0; 235 ip_pkt.checksum = 0;
236 ip_pkt.src_ip = my_ip->s_addr; 236 ip_pkt.src_ip = my_ip->s_addr;
237 ip_pkt.dst_ip = other->s_addr; 237 ip_pkt.dst_ip = other->s_addr;
238 ip_pkt.checksum = htons (calc_checksum ((uint16_t *) & ip_pkt, 238 ip_pkt.checksum =
239 sizeof (struct ip_header))); 239 htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header)));
240 memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); 240 memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
241 off += sizeof (struct ip_header); 241 off += sizeof (struct ip_header);
242 242
@@ -250,8 +250,8 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other)
250 /* ip header of the presumably 'lost' udp packet */ 250 /* ip header of the presumably 'lost' udp packet */
251 ip_pkt.vers_ihl = 0x45; 251 ip_pkt.vers_ihl = 0x45;
252 ip_pkt.tos = 0; 252 ip_pkt.tos = 0;
253 ip_pkt.pkt_len = htons (sizeof (struct ip_header) + 253 ip_pkt.pkt_len =
254 sizeof (struct udp_header)); 254 htons (sizeof (struct ip_header) + sizeof (struct udp_header));
255 ip_pkt.id = htons (0); 255 ip_pkt.id = htons (0);
256 ip_pkt.flags_frag_offset = 0; 256 ip_pkt.flags_frag_offset = 0;
257 ip_pkt.ttl = 128; 257 ip_pkt.ttl = 128;
@@ -259,8 +259,8 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other)
259 ip_pkt.checksum = 0; 259 ip_pkt.checksum = 0;
260 ip_pkt.src_ip = other->s_addr; 260 ip_pkt.src_ip = other->s_addr;
261 ip_pkt.dst_ip = dummy.s_addr; 261 ip_pkt.dst_ip = dummy.s_addr;
262 ip_pkt.checksum = htons (calc_checksum ((uint16_t *) & ip_pkt, 262 ip_pkt.checksum =
263 sizeof (struct ip_header))); 263 htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header)));
264 memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); 264 memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
265 off += sizeof (struct ip_header); 265 off += sizeof (struct ip_header);
266 266
@@ -287,9 +287,9 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other)
287 dst.sin_len = sizeof (struct sockaddr_in); 287 dst.sin_len = sizeof (struct sockaddr_in);
288#endif 288#endif
289 dst.sin_addr = *other; 289 dst.sin_addr = *other;
290 err = sendto (rawsock, 290 err =
291 packet, 291 sendto (rawsock, packet, sizeof (packet), 0, (struct sockaddr *) &dst,
292 sizeof (packet), 0, (struct sockaddr *) &dst, sizeof (dst)); 292 sizeof (dst));
293 if (err < 0) 293 if (err < 0)
294 { 294 {
295 fprintf (stderr, "sendto failed: %s\n", strerror (errno)); 295 fprintf (stderr, "sendto failed: %s\n", strerror (errno));
@@ -332,8 +332,8 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other)
332 ip_pkt.checksum = 0; 332 ip_pkt.checksum = 0;
333 ip_pkt.src_ip = my_ip->s_addr; 333 ip_pkt.src_ip = my_ip->s_addr;
334 ip_pkt.dst_ip = other->s_addr; 334 ip_pkt.dst_ip = other->s_addr;
335 ip_pkt.checksum = htons (calc_checksum ((uint16_t *) & ip_pkt, 335 ip_pkt.checksum =
336 sizeof (struct ip_header))); 336 htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header)));
337 memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); 337 memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
338 off = sizeof (ip_pkt); 338 off = sizeof (ip_pkt);
339 339
@@ -357,8 +357,8 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other)
357 ip_pkt.src_ip = other->s_addr; 357 ip_pkt.src_ip = other->s_addr;
358 ip_pkt.dst_ip = dummy.s_addr; 358 ip_pkt.dst_ip = dummy.s_addr;
359 ip_pkt.checksum = 0; 359 ip_pkt.checksum = 0;
360 ip_pkt.checksum = htons (calc_checksum ((uint16_t *) & ip_pkt, 360 ip_pkt.checksum =
361 sizeof (struct ip_header))); 361 htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header)));
362 memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); 362 memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
363 off += sizeof (struct ip_header); 363 off += sizeof (struct ip_header);
364 364
@@ -366,17 +366,18 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other)
366 icmp_echo.code = 0; 366 icmp_echo.code = 0;
367 icmp_echo.reserved = htonl (port); 367 icmp_echo.reserved = htonl (port);
368 icmp_echo.checksum = 0; 368 icmp_echo.checksum = 0;
369 icmp_echo.checksum = htons (calc_checksum ((uint16_t *) & icmp_echo, 369 icmp_echo.checksum =
370 sizeof (struct icmp_echo_header))); 370 htons (calc_checksum
371 ((uint16_t *) & icmp_echo, sizeof (struct icmp_echo_header)));
371 memcpy (&packet[off], &icmp_echo, sizeof (struct icmp_echo_header)); 372 memcpy (&packet[off], &icmp_echo, sizeof (struct icmp_echo_header));
372 373
373 /* no go back to calculate ICMP packet checksum */ 374 /* no go back to calculate ICMP packet checksum */
374 off = sizeof (struct ip_header); 375 off = sizeof (struct ip_header);
375 icmp_ttl.checksum = htons (calc_checksum ((uint16_t *) & packet[off], 376 icmp_ttl.checksum =
376 sizeof (struct 377 htons (calc_checksum
377 icmp_ttl_exceeded_header) + 378 ((uint16_t *) & packet[off],
378 sizeof (struct ip_header) + 379 sizeof (struct icmp_ttl_exceeded_header) +
379 sizeof (struct icmp_echo_header))); 380 sizeof (struct ip_header) + sizeof (struct icmp_echo_header)));
380 memcpy (&packet[off], &icmp_ttl, sizeof (struct icmp_ttl_exceeded_header)); 381 memcpy (&packet[off], &icmp_ttl, sizeof (struct icmp_ttl_exceeded_header));
381 382
382 /* prepare for transmission */ 383 /* prepare for transmission */
@@ -386,9 +387,9 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other)
386 dst.sin_len = sizeof (struct sockaddr_in); 387 dst.sin_len = sizeof (struct sockaddr_in);
387#endif 388#endif
388 dst.sin_addr = *other; 389 dst.sin_addr = *other;
389 err = sendto (rawsock, 390 err =
390 packet, 391 sendto (rawsock, packet, sizeof (packet), 0, (struct sockaddr *) &dst,
391 sizeof (packet), 0, (struct sockaddr *) &dst, sizeof (dst)); 392 sizeof (dst));
392 if (err < 0) 393 if (err < 0)
393 { 394 {
394 fprintf (stderr, "sendto failed: %s\n", strerror (errno)); 395 fprintf (stderr, "sendto failed: %s\n", strerror (errno));
@@ -417,15 +418,15 @@ make_raw_socket ()
417 fprintf (stderr, "Error opening RAW socket: %s\n", strerror (errno)); 418 fprintf (stderr, "Error opening RAW socket: %s\n", strerror (errno));
418 return -1; 419 return -1;
419 } 420 }
420 if (0 != setsockopt (ret, SOL_SOCKET, SO_BROADCAST, 421 if (0 !=
421 (char *) &one, sizeof (one))) 422 setsockopt (ret, SOL_SOCKET, SO_BROADCAST, (char *) &one, sizeof (one)))
422 { 423 {
423 fprintf (stderr, "setsockopt failed: %s\n", strerror (errno)); 424 fprintf (stderr, "setsockopt failed: %s\n", strerror (errno));
424 close (ret); 425 close (ret);
425 return -1; 426 return -1;
426 } 427 }
427 if (0 != setsockopt (ret, IPPROTO_IP, IP_HDRINCL, 428 if (0 !=
428 (char *) &one, sizeof (one))) 429 setsockopt (ret, IPPROTO_IP, IP_HDRINCL, (char *) &one, sizeof (one)))
429 { 430 {
430 fprintf (stderr, "setsockopt failed: %s\n", strerror (errno)); 431 fprintf (stderr, "setsockopt failed: %s\n", strerror (errno));
431 close (ret); 432 close (ret);
diff --git a/src/nat/gnunet-helper-nat-server-windows.c b/src/nat/gnunet-helper-nat-server-windows.c
index 727a7be67..8386a15b1 100644
--- a/src/nat/gnunet-helper-nat-server-windows.c
+++ b/src/nat/gnunet-helper-nat-server-windows.c
@@ -272,8 +272,8 @@ send_icmp_echo (const struct in_addr *my_ip)
272 ip_pkt.checksum = 0; 272 ip_pkt.checksum = 0;
273 ip_pkt.src_ip = my_ip->s_addr; 273 ip_pkt.src_ip = my_ip->s_addr;
274 ip_pkt.dst_ip = dummy.s_addr; 274 ip_pkt.dst_ip = dummy.s_addr;
275 ip_pkt.checksum = htons (calc_checksum ((uint16_t *) & ip_pkt, 275 ip_pkt.checksum =
276 sizeof (struct ip_header))); 276 htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header)));
277 memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); 277 memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
278 off += sizeof (struct ip_header); 278 off += sizeof (struct ip_header);
279 279
@@ -281,16 +281,17 @@ send_icmp_echo (const struct in_addr *my_ip)
281 icmp_echo.code = 0; 281 icmp_echo.code = 0;
282 icmp_echo.reserved = 0; 282 icmp_echo.reserved = 0;
283 icmp_echo.checksum = 0; 283 icmp_echo.checksum = 0;
284 icmp_echo.checksum = htons (calc_checksum ((uint16_t *) & icmp_echo, 284 icmp_echo.checksum =
285 sizeof (struct icmp_echo_header))); 285 htons (calc_checksum
286 ((uint16_t *) & icmp_echo, sizeof (struct icmp_echo_header)));
286 memcpy (&packet[off], &icmp_echo, sizeof (struct icmp_echo_header)); 287 memcpy (&packet[off], &icmp_echo, sizeof (struct icmp_echo_header));
287 off += sizeof (struct icmp_echo_header); 288 off += sizeof (struct icmp_echo_header);
288 289
289 memset (&dst, 0, sizeof (dst)); 290 memset (&dst, 0, sizeof (dst));
290 dst.sin_family = AF_INET; 291 dst.sin_family = AF_INET;
291 dst.sin_addr = dummy; 292 dst.sin_addr = dummy;
292 err = sendto (rawsock, 293 err =
293 packet, off, 0, (struct sockaddr *) &dst, sizeof (dst)); 294 sendto (rawsock, packet, off, 0, (struct sockaddr *) &dst, sizeof (dst));
294 if (err < 0) 295 if (err < 0)
295 { 296 {
296#if VERBOSE 297#if VERBOSE
@@ -383,9 +384,10 @@ process_icmp_response ()
383 switch (ip_pkt.proto) 384 switch (ip_pkt.proto)
384 { 385 {
385 case IPPROTO_ICMP: 386 case IPPROTO_ICMP:
386 if (have != (sizeof (struct ip_header) * 2 + 387 if (have !=
387 sizeof (struct icmp_ttl_exceeded_header) + 388 (sizeof (struct ip_header) * 2 +
388 sizeof (struct icmp_echo_header))) 389 sizeof (struct icmp_ttl_exceeded_header) +
390 sizeof (struct icmp_echo_header)))
389 { 391 {
390 /* malformed */ 392 /* malformed */
391 return; 393 return;
@@ -395,9 +397,9 @@ process_icmp_response ()
395 port = (uint16_t) ntohl (icmp_echo.reserved); 397 port = (uint16_t) ntohl (icmp_echo.reserved);
396 break; 398 break;
397 case IPPROTO_UDP: 399 case IPPROTO_UDP:
398 if (have != (sizeof (struct ip_header) * 2 + 400 if (have !=
399 sizeof (struct icmp_ttl_exceeded_header) + 401 (sizeof (struct ip_header) * 2 +
400 sizeof (struct udp_header))) 402 sizeof (struct icmp_ttl_exceeded_header) + sizeof (struct udp_header)))
401 { 403 {
402 /* malformed */ 404 /* malformed */
403 return; 405 return;
@@ -412,8 +414,8 @@ process_icmp_response ()
412 } 414 }
413 415
414 ssize = sizeof (buf); 416 ssize = sizeof (buf);
415 WSAAddressToString ((LPSOCKADDR) & source_ip, 417 WSAAddressToString ((LPSOCKADDR) & source_ip, sizeof (source_ip), NULL, buf,
416 sizeof (source_ip), NULL, buf, &ssize); 418 &ssize);
417 if (port == 0) 419 if (port == 0)
418 fprintf (stdout, "%s\n", buf); 420 fprintf (stdout, "%s\n", buf);
419 else 421 else
@@ -460,16 +462,17 @@ make_raw_socket ()
460 return INVALID_SOCKET; 462 return INVALID_SOCKET;
461 } 463 }
462 464
463 if (0 != setsockopt (rawsock, 465 if (0 !=
464 SOL_SOCKET, SO_BROADCAST, (char *) &bOptVal, bOptLen)) 466 setsockopt (rawsock, SOL_SOCKET, SO_BROADCAST, (char *) &bOptVal,
467 bOptLen))
465 { 468 {
466 fprintf (stderr, 469 fprintf (stderr, "Error setting SO_BROADCAST to ON: %s\n",
467 "Error setting SO_BROADCAST to ON: %s\n", strerror (errno)); 470 strerror (errno));
468 closesocket (rawsock); 471 closesocket (rawsock);
469 return INVALID_SOCKET; 472 return INVALID_SOCKET;
470 } 473 }
471 if (0 != setsockopt (rawsock, 474 if (0 !=
472 IPPROTO_IP, IP_HDRINCL, (char *) &bOptVal, bOptLen)) 475 setsockopt (rawsock, IPPROTO_IP, IP_HDRINCL, (char *) &bOptVal, bOptLen))
473 { 476 {
474 fprintf (stderr, "Error setting IP_HDRINCL to ON: %s\n", strerror (errno)); 477 fprintf (stderr, "Error setting IP_HDRINCL to ON: %s\n", strerror (errno));
475 closesocket (rawsock); 478 closesocket (rawsock);
@@ -503,9 +506,8 @@ make_udp_socket (const struct in_addr *my_ip)
503 addr.sin_port = htons (NAT_TRAV_PORT); 506 addr.sin_port = htons (NAT_TRAV_PORT);
504 if (0 != bind (ret, (struct sockaddr *) &addr, sizeof (addr))) 507 if (0 != bind (ret, (struct sockaddr *) &addr, sizeof (addr)))
505 { 508 {
506 fprintf (stderr, 509 fprintf (stderr, "Error binding UDP socket to port %u: %s\n", NAT_TRAV_PORT,
507 "Error binding UDP socket to port %u: %s\n", 510 strerror (errno));
508 NAT_TRAV_PORT, strerror (errno));
509 /* likely problematic, but not certain, try to continue */ 511 /* likely problematic, but not certain, try to continue */
510 } 512 }
511 return ret; 513 return ret;
@@ -530,9 +532,8 @@ main (int argc, char *const *argv)
530 } 532 }
531 if (1 != inet_pton (AF_INET, argv[1], &external)) 533 if (1 != inet_pton (AF_INET, argv[1], &external))
532 { 534 {
533 fprintf (stderr, 535 fprintf (stderr, "Error parsing IPv4 address: %s, error %s\n", argv[1],
534 "Error parsing IPv4 address: %s, error %s\n", 536 strerror (errno));
535 argv[1], strerror (errno));
536 return 1; 537 return 1;
537 } 538 }
538 if (1 != inet_pton (AF_INET, DUMMY_IP, &dummy)) 539 if (1 != inet_pton (AF_INET, DUMMY_IP, &dummy))
diff --git a/src/nat/gnunet-helper-nat-server.c b/src/nat/gnunet-helper-nat-server.c
index 636ae6003..684fa9706 100644
--- a/src/nat/gnunet-helper-nat-server.c
+++ b/src/nat/gnunet-helper-nat-server.c
@@ -252,8 +252,8 @@ send_icmp_echo (const struct in_addr *my_ip)
252 ip_pkt.checksum = 0; 252 ip_pkt.checksum = 0;
253 ip_pkt.src_ip = my_ip->s_addr; 253 ip_pkt.src_ip = my_ip->s_addr;
254 ip_pkt.dst_ip = dummy.s_addr; 254 ip_pkt.dst_ip = dummy.s_addr;
255 ip_pkt.checksum = htons (calc_checksum ((uint16_t *) & ip_pkt, 255 ip_pkt.checksum =
256 sizeof (struct ip_header))); 256 htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header)));
257 memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); 257 memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
258 off += sizeof (struct ip_header); 258 off += sizeof (struct ip_header);
259 259
@@ -261,8 +261,9 @@ send_icmp_echo (const struct in_addr *my_ip)
261 icmp_echo.code = 0; 261 icmp_echo.code = 0;
262 icmp_echo.checksum = 0; 262 icmp_echo.checksum = 0;
263 icmp_echo.reserved = 0; 263 icmp_echo.reserved = 0;
264 icmp_echo.checksum = htons (calc_checksum ((uint16_t *) & icmp_echo, 264 icmp_echo.checksum =
265 sizeof (struct icmp_echo_header))); 265 htons (calc_checksum
266 ((uint16_t *) & icmp_echo, sizeof (struct icmp_echo_header)));
266 memcpy (&packet[off], &icmp_echo, sizeof (struct icmp_echo_header)); 267 memcpy (&packet[off], &icmp_echo, sizeof (struct icmp_echo_header));
267 off += sizeof (struct icmp_echo_header); 268 off += sizeof (struct icmp_echo_header);
268 269
@@ -272,8 +273,8 @@ send_icmp_echo (const struct in_addr *my_ip)
272 dst.sin_len = sizeof (struct sockaddr_in); 273 dst.sin_len = sizeof (struct sockaddr_in);
273#endif 274#endif
274 dst.sin_addr = dummy; 275 dst.sin_addr = dummy;
275 err = sendto (rawsock, 276 err =
276 packet, off, 0, (struct sockaddr *) &dst, sizeof (dst)); 277 sendto (rawsock, packet, off, 0, (struct sockaddr *) &dst, sizeof (dst));
277 if (err < 0) 278 if (err < 0)
278 { 279 {
279#if VERBOSE 280#if VERBOSE
@@ -368,9 +369,10 @@ process_icmp_response ()
368 switch (ip_pkt.proto) 369 switch (ip_pkt.proto)
369 { 370 {
370 case IPPROTO_ICMP: 371 case IPPROTO_ICMP:
371 if (have != (sizeof (struct ip_header) * 2 + 372 if (have !=
372 sizeof (struct icmp_ttl_exceeded_header) + 373 (sizeof (struct ip_header) * 2 +
373 sizeof (struct icmp_echo_header))) 374 sizeof (struct icmp_ttl_exceeded_header) +
375 sizeof (struct icmp_echo_header)))
374 { 376 {
375 /* malformed */ 377 /* malformed */
376 return; 378 return;
@@ -380,9 +382,9 @@ process_icmp_response ()
380 port = (uint16_t) ntohl (icmp_echo.reserved); 382 port = (uint16_t) ntohl (icmp_echo.reserved);
381 break; 383 break;
382 case IPPROTO_UDP: 384 case IPPROTO_UDP:
383 if (have != (sizeof (struct ip_header) * 2 + 385 if (have !=
384 sizeof (struct icmp_ttl_exceeded_header) + 386 (sizeof (struct ip_header) * 2 +
385 sizeof (struct udp_header))) 387 sizeof (struct icmp_ttl_exceeded_header) + sizeof (struct udp_header)))
386 { 388 {
387 /* malformed */ 389 /* malformed */
388 return; 390 return;
@@ -397,13 +399,12 @@ process_icmp_response ()
397 } 399 }
398 400
399 if (port == 0) 401 if (port == 0)
400 fprintf (stdout, 402 fprintf (stdout, "%s\n",
401 "%s\n", inet_ntop (AF_INET, &source_ip, buf, sizeof (buf))); 403 inet_ntop (AF_INET, &source_ip, buf, sizeof (buf)));
402 else 404 else
403 fprintf (stdout, 405 fprintf (stdout, "%s:%u\n",
404 "%s:%u\n", 406 inet_ntop (AF_INET, &source_ip, buf, sizeof (buf)),
405 inet_ntop (AF_INET, 407 (unsigned int) port);
406 &source_ip, buf, sizeof (buf)), (unsigned int) port);
407 fflush (stdout); 408 fflush (stdout);
408} 409}
409 410
@@ -426,9 +427,8 @@ make_icmp_socket ()
426 } 427 }
427 if (ret >= FD_SETSIZE) 428 if (ret >= FD_SETSIZE)
428 { 429 {
429 fprintf (stderr, 430 fprintf (stderr, "Socket number too large (%d > %u)\n", ret,
430 "Socket number too large (%d > %u)\n", 431 (unsigned int) FD_SETSIZE);
431 ret, (unsigned int) FD_SETSIZE);
432 close (ret); 432 close (ret);
433 return -1; 433 return -1;
434 } 434 }
@@ -453,15 +453,15 @@ make_raw_socket ()
453 fprintf (stderr, "Error opening RAW socket: %s\n", strerror (errno)); 453 fprintf (stderr, "Error opening RAW socket: %s\n", strerror (errno));
454 return -1; 454 return -1;
455 } 455 }
456 if (-1 == setsockopt (ret, 456 if (-1 ==
457 SOL_SOCKET, SO_BROADCAST, (char *) &one, sizeof (one))) 457 setsockopt (ret, SOL_SOCKET, SO_BROADCAST, (char *) &one, sizeof (one)))
458 { 458 {
459 fprintf (stderr, "setsockopt failed: %s\n", strerror (errno)); 459 fprintf (stderr, "setsockopt failed: %s\n", strerror (errno));
460 close (ret); 460 close (ret);
461 return -1; 461 return -1;
462 } 462 }
463 if (-1 == setsockopt (ret, 463 if (-1 ==
464 IPPROTO_IP, IP_HDRINCL, (char *) &one, sizeof (one))) 464 setsockopt (ret, IPPROTO_IP, IP_HDRINCL, (char *) &one, sizeof (one)))
465 { 465 {
466 fprintf (stderr, "setsockopt failed: %s\n", strerror (errno)); 466 fprintf (stderr, "setsockopt failed: %s\n", strerror (errno));
467 close (ret); 467 close (ret);
@@ -499,9 +499,8 @@ make_udp_socket (const struct in_addr *my_ip)
499 499
500 if (0 != bind (ret, &addr, sizeof (addr))) 500 if (0 != bind (ret, &addr, sizeof (addr)))
501 { 501 {
502 fprintf (stderr, 502 fprintf (stderr, "Error binding UDP socket to port %u: %s\n", NAT_TRAV_PORT,
503 "Error binding UDP socket to port %u: %s\n", 503 strerror (errno));
504 NAT_TRAV_PORT, strerror (errno));
505 /* likely problematic, but not certain, try to continue */ 504 /* likely problematic, but not certain, try to continue */
506 } 505 }
507 return ret; 506 return ret;
diff --git a/src/nat/gnunet-nat-server.c b/src/nat/gnunet-nat-server.c
index 3b4ec2293..988e9fbc9 100644
--- a/src/nat/gnunet-nat-server.c
+++ b/src/nat/gnunet-nat-server.c
@@ -148,13 +148,11 @@ try_send_tcp (uint32_t dst_ipv4, uint16_t dport, uint16_t data)
148 sa.sin_addr.s_addr = dst_ipv4; 148 sa.sin_addr.s_addr = dst_ipv4;
149 sa.sin_port = htons (dport); 149 sa.sin_port = htons (dport);
150#if DEBUG_NAT 150#if DEBUG_NAT
151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending TCP message to `%s'\n",
152 "Sending TCP message to `%s'\n",
153 GNUNET_a2s ((struct sockaddr *) &sa, sizeof (sa))); 152 GNUNET_a2s ((struct sockaddr *) &sa, sizeof (sa)));
154#endif 153#endif
155 if ((GNUNET_OK != 154 if ((GNUNET_OK !=
156 GNUNET_NETWORK_socket_connect (s, 155 GNUNET_NETWORK_socket_connect (s, (const struct sockaddr *) &sa,
157 (const struct sockaddr *) &sa,
158 sizeof (sa))) && (errno != EINPROGRESS)) 156 sizeof (sa))) && (errno != EINPROGRESS))
159 { 157 {
160 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "connect"); 158 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "connect");
@@ -196,14 +194,12 @@ try_send_udp (uint32_t dst_ipv4, uint16_t dport, uint16_t data)
196 sa.sin_addr.s_addr = dst_ipv4; 194 sa.sin_addr.s_addr = dst_ipv4;
197 sa.sin_port = htons (dport); 195 sa.sin_port = htons (dport);
198#if DEBUG_NAT 196#if DEBUG_NAT
199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending UDP packet to `%s'\n",
200 "Sending UDP packet to `%s'\n",
201 GNUNET_a2s ((struct sockaddr *) &sa, sizeof (sa))); 198 GNUNET_a2s ((struct sockaddr *) &sa, sizeof (sa)));
202#endif 199#endif
203 if (-1 == GNUNET_NETWORK_socket_sendto (s, 200 if (-1 ==
204 &data, sizeof (data), 201 GNUNET_NETWORK_socket_sendto (s, &data, sizeof (data),
205 (const struct sockaddr *) &sa, 202 (const struct sockaddr *) &sa, sizeof (sa)))
206 sizeof (sa)))
207 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "sendto"); 203 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "sendto");
208 GNUNET_NETWORK_socket_close (s); 204 GNUNET_NETWORK_socket_close (s);
209} 205}
@@ -218,8 +214,7 @@ try_send_udp (uint32_t dst_ipv4, uint16_t dport, uint16_t data)
218 * @param msg message with details about what to test 214 * @param msg message with details about what to test
219 */ 215 */
220static void 216static void
221test (void *cls, 217test (void *cls, struct GNUNET_SERVER_Client *client,
222 struct GNUNET_SERVER_Client *client,
223 const struct GNUNET_MessageHeader *msg) 218 const struct GNUNET_MessageHeader *msg)
224{ 219{
225 const struct GNUNET_NAT_TestMessage *tm; 220 const struct GNUNET_NAT_TestMessage *tm;
@@ -263,9 +258,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
263 * @param c configuration 258 * @param c configuration
264 */ 259 */
265static void 260static void
266run (void *cls, 261run (void *cls, char *const *args, const char *cfgfile,
267 char *const *args, 262 const struct GNUNET_CONFIGURATION_Handle *c)
268 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
269{ 263{
270 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 264 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
271 {&test, NULL, GNUNET_MESSAGE_TYPE_NAT_TEST, 265 {&test, NULL, GNUNET_MESSAGE_TYPE_NAT_TEST,
@@ -288,8 +282,8 @@ run (void *cls,
288 }; 282 };
289 283
290 cfg = c; 284 cfg = c;
291 if ((args[0] == NULL) || 285 if ((args[0] == NULL) || (1 != SSCANF (args[0], "%u", &port)) || (0 == port)
292 (1 != SSCANF (args[0], "%u", &port)) || (0 == port) || (65536 <= port)) 286 || (65536 <= port))
293 { 287 {
294 fprintf (stderr, 288 fprintf (stderr,
295 _ 289 _
@@ -307,12 +301,12 @@ run (void *cls,
307 in4.sin_len = sizeof (in4); 301 in4.sin_len = sizeof (in4);
308 in6.sin6_len = sizeof (in6); 302 in6.sin6_len = sizeof (in6);
309#endif 303#endif
310 server = GNUNET_SERVER_create (NULL, NULL, 304 server =
311 (struct sockaddr * const *) sa, 305 GNUNET_SERVER_create (NULL, NULL, (struct sockaddr * const *) sa, slen,
312 slen, GNUNET_TIME_UNIT_SECONDS, GNUNET_YES); 306 GNUNET_TIME_UNIT_SECONDS, GNUNET_YES);
313 GNUNET_SERVER_add_handlers (server, handlers); 307 GNUNET_SERVER_add_handlers (server, handlers);
314 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 308 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
315 &shutdown_task, NULL); 309 NULL);
316} 310}
317 311
318 312
@@ -331,10 +325,9 @@ main (int argc, char *const argv[])
331 }; 325 };
332 326
333 if (GNUNET_OK != 327 if (GNUNET_OK !=
334 GNUNET_PROGRAM_run (argc, argv, 328 GNUNET_PROGRAM_run (argc, argv, "gnunet-nat-server [options] PORT",
335 "gnunet-nat-server [options] PORT", 329 _("GNUnet NAT traversal test helper daemon"), options,
336 _("GNUnet NAT traversal test helper daemon"), 330 &run, NULL))
337 options, &run, NULL))
338 return 1; 331 return 1;
339 return 0; 332 return 0;
340} 333}
diff --git a/src/nat/nat.c b/src/nat/nat.c
index ed72be9f8..6069d40ad 100644
--- a/src/nat/nat.c
+++ b/src/nat/nat.c
@@ -386,8 +386,7 @@ remove_from_address_list_by_source (struct GNUNET_NAT_Handle *h,
386 continue; 386 continue;
387 GNUNET_CONTAINER_DLL_remove (h->lal_head, h->lal_tail, pos); 387 GNUNET_CONTAINER_DLL_remove (h->lal_head, h->lal_tail, pos);
388 if (NULL != h->address_callback) 388 if (NULL != h->address_callback)
389 h->address_callback (h->callback_cls, 389 h->address_callback (h->callback_cls, GNUNET_NO,
390 GNUNET_NO,
391 (const struct sockaddr *) &pos[1], pos->addrlen); 390 (const struct sockaddr *) &pos[1], pos->addrlen);
392 GNUNET_free (pos); 391 GNUNET_free (pos);
393 } 392 }
@@ -416,10 +415,10 @@ add_to_address_list_as_is (struct GNUNET_NAT_Handle *h,
416 lal->source = src; 415 lal->source = src;
417 GNUNET_CONTAINER_DLL_insert (h->lal_head, h->lal_tail, lal); 416 GNUNET_CONTAINER_DLL_insert (h->lal_head, h->lal_tail, lal);
418#if DEBUG_NAT 417#if DEBUG_NAT
419 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 418 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat",
420 "nat", 419 "Adding address `%s' from source %d\n", GNUNET_a2s (arg,
421 "Adding address `%s' from source %d\n", 420 arg_size),
422 GNUNET_a2s (arg, arg_size), src); 421 src);
423#endif 422#endif
424 if (NULL != h->address_callback) 423 if (NULL != h->address_callback)
425 h->address_callback (h->callback_cls, GNUNET_YES, arg, arg_size); 424 h->address_callback (h->callback_cls, GNUNET_YES, arg, arg_size);
@@ -438,8 +437,7 @@ add_to_address_list_as_is (struct GNUNET_NAT_Handle *h,
438 * @param arg_size number of bytes in arg 437 * @param arg_size number of bytes in arg
439 */ 438 */
440static void 439static void
441add_to_address_list (struct GNUNET_NAT_Handle *h, 440add_to_address_list (struct GNUNET_NAT_Handle *h, enum LocalAddressSource src,
442 enum LocalAddressSource src,
443 const struct sockaddr *arg, socklen_t arg_size) 441 const struct sockaddr *arg, socklen_t arg_size)
444{ 442{
445 struct sockaddr_in s4; 443 struct sockaddr_in s4;
@@ -452,17 +450,13 @@ add_to_address_list (struct GNUNET_NAT_Handle *h,
452 in4 = (const struct sockaddr_in *) arg; 450 in4 = (const struct sockaddr_in *) arg;
453 s4 = *in4; 451 s4 = *in4;
454 s4.sin_port = htons (h->adv_port); 452 s4.sin_port = htons (h->adv_port);
455 add_to_address_list_as_is (h, 453 add_to_address_list_as_is (h, src, (const struct sockaddr *) &s4,
456 src,
457 (const struct sockaddr *) &s4,
458 sizeof (struct sockaddr_in)); 454 sizeof (struct sockaddr_in));
459 if (GNUNET_YES == h->enable_nat_server) 455 if (GNUNET_YES == h->enable_nat_server)
460 { 456 {
461 /* also add with PORT = 0 to indicate NAT server is enabled */ 457 /* also add with PORT = 0 to indicate NAT server is enabled */
462 s4.sin_port = htons (0); 458 s4.sin_port = htons (0);
463 add_to_address_list_as_is (h, 459 add_to_address_list_as_is (h, src, (const struct sockaddr *) &s4,
464 src,
465 (const struct sockaddr *) &s4,
466 sizeof (struct sockaddr_in)); 460 sizeof (struct sockaddr_in));
467 } 461 }
468 } 462 }
@@ -473,9 +467,7 @@ add_to_address_list (struct GNUNET_NAT_Handle *h,
473 in6 = (const struct sockaddr_in6 *) arg; 467 in6 = (const struct sockaddr_in6 *) arg;
474 s6 = *in6; 468 s6 = *in6;
475 s6.sin6_port = htons (h->adv_port); 469 s6.sin6_port = htons (h->adv_port);
476 add_to_address_list_as_is (h, 470 add_to_address_list_as_is (h, src, (const struct sockaddr *) &s6,
477 src,
478 (const struct sockaddr *) &s6,
479 sizeof (struct sockaddr_in6)); 471 sizeof (struct sockaddr_in6));
480 } 472 }
481 } 473 }
@@ -497,8 +489,8 @@ add_to_address_list (struct GNUNET_NAT_Handle *h,
497 */ 489 */
498static void 490static void
499add_ip_to_address_list (struct GNUNET_NAT_Handle *h, 491add_ip_to_address_list (struct GNUNET_NAT_Handle *h,
500 enum LocalAddressSource src, 492 enum LocalAddressSource src, const void *addr,
501 const void *addr, socklen_t addrlen) 493 socklen_t addrlen)
502{ 494{
503 struct sockaddr_in s4; 495 struct sockaddr_in s4;
504 const struct in_addr *in4; 496 const struct in_addr *in4;
@@ -515,17 +507,13 @@ add_ip_to_address_list (struct GNUNET_NAT_Handle *h,
515 s4.sin_len = (u_char) sizeof (struct sockaddr_in); 507 s4.sin_len = (u_char) sizeof (struct sockaddr_in);
516#endif 508#endif
517 s4.sin_addr = *in4; 509 s4.sin_addr = *in4;
518 add_to_address_list (h, 510 add_to_address_list (h, src, (const struct sockaddr *) &s4,
519 src,
520 (const struct sockaddr *) &s4,
521 sizeof (struct sockaddr_in)); 511 sizeof (struct sockaddr_in));
522 if (GNUNET_YES == h->enable_nat_server) 512 if (GNUNET_YES == h->enable_nat_server)
523 { 513 {
524 /* also add with PORT = 0 to indicate NAT server is enabled */ 514 /* also add with PORT = 0 to indicate NAT server is enabled */
525 s4.sin_port = htons (0); 515 s4.sin_port = htons (0);
526 add_to_address_list (h, 516 add_to_address_list (h, src, (const struct sockaddr *) &s4,
527 src,
528 (const struct sockaddr *) &s4,
529 sizeof (struct sockaddr_in)); 517 sizeof (struct sockaddr_in));
530 518
531 } 519 }
@@ -542,9 +530,7 @@ add_ip_to_address_list (struct GNUNET_NAT_Handle *h,
542 s6.sin6_len = (u_char) sizeof (struct sockaddr_in6); 530 s6.sin6_len = (u_char) sizeof (struct sockaddr_in6);
543#endif 531#endif
544 s6.sin6_addr = *in6; 532 s6.sin6_addr = *in6;
545 add_to_address_list (h, 533 add_to_address_list (h, src, (const struct sockaddr *) &s6,
546 src,
547 (const struct sockaddr *) &s6,
548 sizeof (struct sockaddr_in6)); 534 sizeof (struct sockaddr_in6));
549 } 535 }
550 } 536 }
@@ -562,8 +548,8 @@ add_ip_to_address_list (struct GNUNET_NAT_Handle *h,
562 * @param cls the NAT handle 548 * @param cls the NAT handle
563 * @param tc scheduler context 549 * @param tc scheduler context
564 */ 550 */
565static void 551static void resolve_dns (void *cls,
566resolve_dns (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 552 const struct GNUNET_SCHEDULER_TaskContext *tc);
567 553
568 554
569/** 555/**
@@ -585,8 +571,8 @@ process_external_ip (void *cls, const struct sockaddr *addr, socklen_t addrlen)
585 h->ext_dns = NULL; 571 h->ext_dns = NULL;
586 if (1 == inet_pton (AF_INET, h->external_address, &dummy)) 572 if (1 == inet_pton (AF_INET, h->external_address, &dummy))
587 return; /* repated lookup pointless: was numeric! */ 573 return; /* repated lookup pointless: was numeric! */
588 h->dns_task = GNUNET_SCHEDULER_add_delayed (h->dyndns_frequency, 574 h->dns_task =
589 &resolve_dns, h); 575 GNUNET_SCHEDULER_add_delayed (h->dyndns_frequency, &resolve_dns, h);
590 return; 576 return;
591 } 577 }
592 add_to_address_list (h, LAL_EXTERNAL_IP, addr, addrlen); 578 add_to_address_list (h, LAL_EXTERNAL_IP, addr, addrlen);
@@ -599,8 +585,8 @@ process_external_ip (void *cls, const struct sockaddr *addr, socklen_t addrlen)
599 * @param cls the NAT handle 585 * @param cls the NAT handle
600 * @param tc scheduler context 586 * @param tc scheduler context
601 */ 587 */
602static void 588static void resolve_hostname (void *cls,
603resolve_hostname (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 589 const struct GNUNET_SCHEDULER_TaskContext *tc);
604 590
605 591
606/** 592/**
@@ -620,8 +606,9 @@ process_hostname_ip (void *cls, const struct sockaddr *addr, socklen_t addrlen)
620 if (addr == NULL) 606 if (addr == NULL)
621 { 607 {
622 h->hostname_dns = NULL; 608 h->hostname_dns = NULL;
623 h->hostname_task = GNUNET_SCHEDULER_add_delayed (h->hostname_dns_frequency, 609 h->hostname_task =
624 &resolve_hostname, h); 610 GNUNET_SCHEDULER_add_delayed (h->hostname_dns_frequency,
611 &resolve_hostname, h);
625 return; 612 return;
626 } 613 }
627 add_to_address_list (h, LAL_HOSTNAME_DNS, addr, addrlen); 614 add_to_address_list (h, LAL_HOSTNAME_DNS, addr, addrlen);
@@ -640,9 +627,7 @@ process_hostname_ip (void *cls, const struct sockaddr *addr, socklen_t addrlen)
640 * @return GNUNET_OK to continue iterating 627 * @return GNUNET_OK to continue iterating
641 */ 628 */
642static int 629static int
643process_interfaces (void *cls, 630process_interfaces (void *cls, const char *name, int isDefault,
644 const char *name,
645 int isDefault,
646 const struct sockaddr *addr, socklen_t addrlen) 631 const struct sockaddr *addr, socklen_t addrlen)
647{ 632{
648 struct GNUNET_NAT_Handle *h = cls; 633 struct GNUNET_NAT_Handle *h = cls;
@@ -657,9 +642,8 @@ process_interfaces (void *cls,
657 s4 = (struct sockaddr_in *) addr; 642 s4 = (struct sockaddr_in *) addr;
658 ip = &s4->sin_addr; 643 ip = &s4->sin_addr;
659 if (GNUNET_YES == h->use_localaddresses) 644 if (GNUNET_YES == h->use_localaddresses)
660 add_ip_to_address_list (h, 645 add_ip_to_address_list (h, LAL_INTERFACE_ADDRESS, &s4->sin_addr,
661 LAL_INTERFACE_ADDRESS, 646 sizeof (struct in_addr));
662 &s4->sin_addr, sizeof (struct in_addr));
663 break; 647 break;
664 case AF_INET6: 648 case AF_INET6:
665 s6 = (struct sockaddr_in6 *) addr; 649 s6 = (struct sockaddr_in6 *) addr;
@@ -670,24 +654,22 @@ process_interfaces (void *cls,
670 } 654 }
671 ip = &s6->sin6_addr; 655 ip = &s6->sin6_addr;
672 if (GNUNET_YES == h->use_localaddresses) 656 if (GNUNET_YES == h->use_localaddresses)
673 add_ip_to_address_list (h, 657 add_ip_to_address_list (h, LAL_INTERFACE_ADDRESS, &s6->sin6_addr,
674 LAL_INTERFACE_ADDRESS, 658 sizeof (struct in6_addr));
675 &s6->sin6_addr, sizeof (struct in6_addr));
676 break; 659 break;
677 default: 660 default:
678 GNUNET_break (0); 661 GNUNET_break (0);
679 return GNUNET_OK; 662 return GNUNET_OK;
680 } 663 }
681 if ((h->internal_address == NULL) && 664 if ((h->internal_address == NULL) && (h->server_proc == NULL) &&
682 (h->server_proc == NULL) &&
683 (h->server_read_task == GNUNET_SCHEDULER_NO_TASK) && 665 (h->server_read_task == GNUNET_SCHEDULER_NO_TASK) &&
684 (GNUNET_YES == isDefault) && 666 (GNUNET_YES == isDefault) && ((addr->sa_family == AF_INET) ||
685 ((addr->sa_family == AF_INET) || (addr->sa_family == AF_INET6))) 667 (addr->sa_family == AF_INET6)))
686 { 668 {
687 /* no internal address configured, but we found a "default" 669 /* no internal address configured, but we found a "default"
688 * interface, try using that as our 'internal' address */ 670 * interface, try using that as our 'internal' address */
689 h->internal_address = GNUNET_strdup (inet_ntop (addr->sa_family, 671 h->internal_address =
690 ip, buf, sizeof (buf))); 672 GNUNET_strdup (inet_ntop (addr->sa_family, ip, buf, sizeof (buf)));
691 start_gnunet_nat_server (h); 673 start_gnunet_nat_server (h);
692 } 674 }
693 return GNUNET_OK; 675 return GNUNET_OK;
@@ -736,13 +718,12 @@ nat_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
736 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 718 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
737 return; 719 return;
738 memset (mybuf, 0, sizeof (mybuf)); 720 memset (mybuf, 0, sizeof (mybuf));
739 bytes = GNUNET_DISK_file_read (h->server_stdout_handle, 721 bytes =
740 mybuf, sizeof (mybuf)); 722 GNUNET_DISK_file_read (h->server_stdout_handle, mybuf, sizeof (mybuf));
741 if (bytes < 1) 723 if (bytes < 1)
742 { 724 {
743#if DEBUG_NAT 725#if DEBUG_NAT
744 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 726 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat",
745 "nat",
746 "Finished reading from server stdout with code: %d\n", 727 "Finished reading from server stdout with code: %d\n",
747 bytes); 728 bytes);
748#endif 729#endif
@@ -787,13 +768,11 @@ nat_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
787#if HAVE_SOCKADDR_IN_SIN_LEN 768#if HAVE_SOCKADDR_IN_SIN_LEN
788 sin_addr.sin_len = sizeof (sin_addr); 769 sin_addr.sin_len = sizeof (sin_addr);
789#endif 770#endif
790 if ((NULL == port_start) || 771 if ((NULL == port_start) || (1 != sscanf (port_start, "%d", &port)) ||
791 (1 != sscanf (port_start, "%d", &port)) ||
792 (-1 == inet_pton (AF_INET, mybuf, &sin_addr.sin_addr))) 772 (-1 == inet_pton (AF_INET, mybuf, &sin_addr.sin_addr)))
793 { 773 {
794 /* should we restart gnunet-helper-nat-server? */ 774 /* should we restart gnunet-helper-nat-server? */
795 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, 775 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "nat",
796 "nat",
797 _ 776 _
798 ("gnunet-helper-nat-server generated malformed address `%s'\n"), 777 ("gnunet-helper-nat-server generated malformed address `%s'\n"),
799 mybuf); 778 mybuf);
@@ -805,16 +784,15 @@ nat_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
805 } 784 }
806 sin_addr.sin_port = htons ((uint16_t) port); 785 sin_addr.sin_port = htons ((uint16_t) port);
807#if DEBUG_NAT 786#if DEBUG_NAT
808 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 787 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat",
809 "nat",
810 "gnunet-helper-nat-server read: %s:%d\n", mybuf, port); 788 "gnunet-helper-nat-server read: %s:%d\n", mybuf, port);
811#endif 789#endif
812 h->reversal_callback (h->callback_cls, 790 h->reversal_callback (h->callback_cls, (const struct sockaddr *) &sin_addr,
813 (const struct sockaddr *) &sin_addr, sizeof (sin_addr)); 791 sizeof (sin_addr));
814 h->server_read_task = 792 h->server_read_task =
815 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 793 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
816 h->server_stdout_handle, 794 h->server_stdout_handle, &nat_server_read,
817 &nat_server_read, h); 795 h);
818} 796}
819 797
820 798
@@ -827,28 +805,25 @@ nat_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
827static void 805static void
828start_gnunet_nat_server (struct GNUNET_NAT_Handle *h) 806start_gnunet_nat_server (struct GNUNET_NAT_Handle *h)
829{ 807{
830 if ((h->behind_nat == GNUNET_YES) && 808 if ((h->behind_nat == GNUNET_YES) && (h->enable_nat_server == GNUNET_YES) &&
831 (h->enable_nat_server == GNUNET_YES) &&
832 (h->internal_address != NULL) && 809 (h->internal_address != NULL) &&
833 (NULL != (h->server_stdout = GNUNET_DISK_pipe (GNUNET_YES, 810 (NULL !=
834 GNUNET_NO, GNUNET_YES)))) 811 (h->server_stdout =
812 GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES))))
835 { 813 {
836#if DEBUG_NAT 814#if DEBUG_NAT
837 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 815 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat" "Starting %s at `%s'\n",
838 "nat"
839 "Starting %s at `%s'\n",
840 "gnunet-helper-nat-server", h->internal_address); 816 "gnunet-helper-nat-server", h->internal_address);
841#endif 817#endif
842 /* Start the server process */ 818 /* Start the server process */
843 h->server_proc = GNUNET_OS_start_process (NULL, 819 h->server_proc =
844 h->server_stdout, 820 GNUNET_OS_start_process (NULL, h->server_stdout,
845 "gnunet-helper-nat-server", 821 "gnunet-helper-nat-server",
846 "gnunet-helper-nat-server", 822 "gnunet-helper-nat-server",
847 h->internal_address, NULL); 823 h->internal_address, NULL);
848 if (h->server_proc == NULL) 824 if (h->server_proc == NULL)
849 { 825 {
850 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, 826 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "nat",
851 "nat",
852 _("Failed to start %s\n"), "gnunet-helper-nat-server"); 827 _("Failed to start %s\n"), "gnunet-helper-nat-server");
853 GNUNET_DISK_pipe_close (h->server_stdout); 828 GNUNET_DISK_pipe_close (h->server_stdout);
854 h->server_stdout = NULL; 829 h->server_stdout = NULL;
@@ -857,13 +832,12 @@ start_gnunet_nat_server (struct GNUNET_NAT_Handle *h)
857 { 832 {
858 /* Close the write end of the read pipe */ 833 /* Close the write end of the read pipe */
859 GNUNET_DISK_pipe_close_end (h->server_stdout, GNUNET_DISK_PIPE_END_WRITE); 834 GNUNET_DISK_pipe_close_end (h->server_stdout, GNUNET_DISK_PIPE_END_WRITE);
860 h->server_stdout_handle 835 h->server_stdout_handle =
861 = GNUNET_DISK_pipe_handle (h->server_stdout, 836 GNUNET_DISK_pipe_handle (h->server_stdout, GNUNET_DISK_PIPE_END_READ);
862 GNUNET_DISK_PIPE_END_READ); 837 h->server_read_task =
863 h->server_read_task 838 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
864 = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 839 h->server_stdout_handle,
865 h->server_stdout_handle, 840 &nat_server_read, h);
866 &nat_server_read, h);
867 } 841 }
868 } 842 }
869} 843}
@@ -883,8 +857,8 @@ list_interfaces (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
883 h->ifc_task = GNUNET_SCHEDULER_NO_TASK; 857 h->ifc_task = GNUNET_SCHEDULER_NO_TASK;
884 remove_from_address_list_by_source (h, LAL_INTERFACE_ADDRESS); 858 remove_from_address_list_by_source (h, LAL_INTERFACE_ADDRESS);
885 GNUNET_OS_network_interfaces_list (&process_interfaces, h); 859 GNUNET_OS_network_interfaces_list (&process_interfaces, h);
886 h->ifc_task = GNUNET_SCHEDULER_add_delayed (h->ifc_scan_frequency, 860 h->ifc_task =
887 &list_interfaces, h); 861 GNUNET_SCHEDULER_add_delayed (h->ifc_scan_frequency, &list_interfaces, h);
888} 862}
889 863
890 864
@@ -901,9 +875,9 @@ resolve_hostname (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
901 875
902 h->hostname_task = GNUNET_SCHEDULER_NO_TASK; 876 h->hostname_task = GNUNET_SCHEDULER_NO_TASK;
903 remove_from_address_list_by_source (h, LAL_HOSTNAME_DNS); 877 remove_from_address_list_by_source (h, LAL_HOSTNAME_DNS);
904 h->hostname_dns = GNUNET_RESOLVER_hostname_resolve (AF_UNSPEC, 878 h->hostname_dns =
905 HOSTNAME_RESOLVE_TIMEOUT, 879 GNUNET_RESOLVER_hostname_resolve (AF_UNSPEC, HOSTNAME_RESOLVE_TIMEOUT,
906 &process_hostname_ip, h); 880 &process_hostname_ip, h);
907} 881}
908 882
909 883
@@ -921,10 +895,10 @@ resolve_dns (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
921 895
922 h->dns_task = GNUNET_SCHEDULER_NO_TASK; 896 h->dns_task = GNUNET_SCHEDULER_NO_TASK;
923 remove_from_address_list_by_source (h, LAL_EXTERNAL_IP); 897 remove_from_address_list_by_source (h, LAL_EXTERNAL_IP);
924 h->ext_dns = GNUNET_RESOLVER_ip_get (h->external_address, 898 h->ext_dns =
925 AF_INET, 899 GNUNET_RESOLVER_ip_get (h->external_address, AF_INET,
926 GNUNET_TIME_UNIT_MINUTES, 900 GNUNET_TIME_UNIT_MINUTES, &process_external_ip,
927 &process_external_ip, h); 901 h);
928} 902}
929 903
930 904
@@ -938,8 +912,8 @@ resolve_dns (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
938 * @param addrlen actual lenght of the address 912 * @param addrlen actual lenght of the address
939 */ 913 */
940static void 914static void
941upnp_add (void *cls, 915upnp_add (void *cls, int add_remove, const struct sockaddr *addr,
942 int add_remove, const struct sockaddr *addr, socklen_t addrlen) 916 socklen_t addrlen)
943{ 917{
944 struct GNUNET_NAT_Handle *h = cls; 918 struct GNUNET_NAT_Handle *h = cls;
945 struct LocalAddressList *pos; 919 struct LocalAddressList *pos;
@@ -955,13 +929,12 @@ upnp_add (void *cls,
955 while (NULL != (pos = next)) 929 while (NULL != (pos = next))
956 { 930 {
957 next = pos->next; 931 next = pos->next;
958 if ((pos->source != LAL_UPNP) || 932 if ((pos->source != LAL_UPNP) || (pos->addrlen != addrlen) ||
959 (pos->addrlen != addrlen) || (0 != memcmp (&pos[1], addr, addrlen))) 933 (0 != memcmp (&pos[1], addr, addrlen)))
960 continue; 934 continue;
961 GNUNET_CONTAINER_DLL_remove (h->lal_head, h->lal_tail, pos); 935 GNUNET_CONTAINER_DLL_remove (h->lal_head, h->lal_tail, pos);
962 if (NULL != h->address_callback) 936 if (NULL != h->address_callback)
963 h->address_callback (h->callback_cls, 937 h->address_callback (h->callback_cls, GNUNET_NO,
964 GNUNET_NO,
965 (const struct sockaddr *) &pos[1], pos->addrlen); 938 (const struct sockaddr *) &pos[1], pos->addrlen);
966 GNUNET_free (pos); 939 GNUNET_free (pos);
967 return; /* only remove once */ 940 return; /* only remove once */
@@ -1036,8 +1009,9 @@ add_from_bind (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1036 GNUNET_break (0); 1009 GNUNET_break (0);
1037 break; 1010 break;
1038 } 1011 }
1039 if (0 != memcmp (&((const struct sockaddr_in6 *) sa)->sin6_addr, 1012 if (0 !=
1040 &any, sizeof (struct in6_addr))) 1013 memcmp (&((const struct sockaddr_in6 *) sa)->sin6_addr, &any,
1014 sizeof (struct in6_addr)))
1041 add_to_address_list (h, LAL_BINDTO_ADDRESS, sa, 1015 add_to_address_list (h, LAL_BINDTO_ADDRESS, sa,
1042 sizeof (struct sockaddr_in6)); 1016 sizeof (struct sockaddr_in6));
1043 break; 1017 break;
@@ -1068,12 +1042,9 @@ add_from_bind (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1068 * @return NULL on error, otherwise handle that can be used to unregister 1042 * @return NULL on error, otherwise handle that can be used to unregister
1069 */ 1043 */
1070struct GNUNET_NAT_Handle * 1044struct GNUNET_NAT_Handle *
1071GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, 1045GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, int is_tcp,
1072 int is_tcp, 1046 uint16_t adv_port, unsigned int num_addrs,
1073 uint16_t adv_port, 1047 const struct sockaddr **addrs, const socklen_t * addrlens,
1074 unsigned int num_addrs,
1075 const struct sockaddr **addrs,
1076 const socklen_t * addrlens,
1077 GNUNET_NAT_AddressCallback address_callback, 1048 GNUNET_NAT_AddressCallback address_callback,
1078 GNUNET_NAT_ReversalCallback reversal_callback, 1049 GNUNET_NAT_ReversalCallback reversal_callback,
1079 void *callback_cls) 1050 void *callback_cls)
@@ -1083,8 +1054,7 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
1083 unsigned int i; 1054 unsigned int i;
1084 1055
1085#if DEBUG_NAT 1056#if DEBUG_NAT
1086 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1057 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat",
1087 "nat",
1088 "Registered with NAT service at port %u with %u IP bound local addresses\n", 1058 "Registered with NAT service at port %u with %u IP bound local addresses\n",
1089 (unsigned int) adv_port, num_addrs); 1059 (unsigned int) adv_port, num_addrs);
1090#endif 1060#endif
@@ -1114,16 +1084,14 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
1114 if (GNUNET_OK == 1084 if (GNUNET_OK ==
1115 GNUNET_CONFIGURATION_have_value (cfg, "nat", "INTERNAL_ADDRESS")) 1085 GNUNET_CONFIGURATION_have_value (cfg, "nat", "INTERNAL_ADDRESS"))
1116 { 1086 {
1117 (void) GNUNET_CONFIGURATION_get_value_string (cfg, 1087 (void) GNUNET_CONFIGURATION_get_value_string (cfg, "nat",
1118 "nat",
1119 "INTERNAL_ADDRESS", 1088 "INTERNAL_ADDRESS",
1120 &h->internal_address); 1089 &h->internal_address);
1121 } 1090 }
1122 if ((h->internal_address != NULL) && 1091 if ((h->internal_address != NULL) &&
1123 (inet_pton (AF_INET, h->internal_address, &in_addr) != 1)) 1092 (inet_pton (AF_INET, h->internal_address, &in_addr) != 1))
1124 { 1093 {
1125 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, 1094 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "nat",
1126 "nat",
1127 _("Malformed %s `%s' given in configuration!\n"), 1095 _("Malformed %s `%s' given in configuration!\n"),
1128 "INTERNAL_ADDRESS", h->internal_address); 1096 "INTERNAL_ADDRESS", h->internal_address);
1129 GNUNET_free (h->internal_address); 1097 GNUNET_free (h->internal_address);
@@ -1133,57 +1101,45 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
1133 if (GNUNET_OK == 1101 if (GNUNET_OK ==
1134 GNUNET_CONFIGURATION_have_value (cfg, "nat", "EXTERNAL_ADDRESS")) 1102 GNUNET_CONFIGURATION_have_value (cfg, "nat", "EXTERNAL_ADDRESS"))
1135 { 1103 {
1136 (void) GNUNET_CONFIGURATION_get_value_string (cfg, 1104 (void) GNUNET_CONFIGURATION_get_value_string (cfg, "nat",
1137 "nat",
1138 "EXTERNAL_ADDRESS", 1105 "EXTERNAL_ADDRESS",
1139 &h->external_address); 1106 &h->external_address);
1140 } 1107 }
1141 if ((h->external_address != NULL) && 1108 if ((h->external_address != NULL) &&
1142 (inet_pton (AF_INET, h->external_address, &in_addr) != 1)) 1109 (inet_pton (AF_INET, h->external_address, &in_addr) != 1))
1143 { 1110 {
1144 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, 1111 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "nat",
1145 "nat",
1146 _("Malformed %s `%s' given in configuration!\n"), 1112 _("Malformed %s `%s' given in configuration!\n"),
1147 "EXTERNAL_ADDRESS", h->external_address); 1113 "EXTERNAL_ADDRESS", h->external_address);
1148 GNUNET_free (h->external_address); 1114 GNUNET_free (h->external_address);
1149 h->external_address = NULL; 1115 h->external_address = NULL;
1150 } 1116 }
1151 h->behind_nat = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1117 h->behind_nat =
1152 "nat", "BEHIND_NAT"); 1118 GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "BEHIND_NAT");
1153 h->nat_punched = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1119 h->nat_punched =
1154 "nat", "PUNCHED_NAT"); 1120 GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "PUNCHED_NAT");
1155 h->enable_nat_client = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1121 h->enable_nat_client =
1156 "nat", 1122 GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "ENABLE_NAT_CLIENT");
1157 "ENABLE_NAT_CLIENT"); 1123 h->enable_nat_server =
1158 h->enable_nat_server = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1124 GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "ENABLE_NAT_SERVER");
1159 "nat", 1125 h->enable_upnp =
1160 "ENABLE_NAT_SERVER"); 1126 GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "ENABLE_UPNP");
1161 h->enable_upnp = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1127 h->use_localaddresses =
1162 "nat", "ENABLE_UPNP"); 1128 GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "USE_LOCALADDR");
1163 h->use_localaddresses = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1129 h->use_hostname =
1164 "nat", 1130 GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "USE_HOSTNAME");
1165 "USE_LOCALADDR"); 1131 h->disable_ipv6 =
1166 h->use_hostname = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1132 GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "DISABLEV6");
1167 "nat",
1168 "USE_HOSTNAME");
1169 h->disable_ipv6 = GNUNET_CONFIGURATION_get_value_yesno (cfg,
1170 "nat", "DISABLEV6");
1171 if (GNUNET_OK != 1133 if (GNUNET_OK !=
1172 GNUNET_CONFIGURATION_get_value_time (cfg, 1134 GNUNET_CONFIGURATION_get_value_time (cfg, "nat", "DYNDNS_FREQUENCY",
1173 "nat",
1174 "DYNDNS_FREQUENCY",
1175 &h->dyndns_frequency)) 1135 &h->dyndns_frequency))
1176 h->dyndns_frequency = DYNDNS_FREQUENCY; 1136 h->dyndns_frequency = DYNDNS_FREQUENCY;
1177 if (GNUNET_OK != 1137 if (GNUNET_OK !=
1178 GNUNET_CONFIGURATION_get_value_time (cfg, 1138 GNUNET_CONFIGURATION_get_value_time (cfg, "nat", "IFC_SCAN_FREQUENCY",
1179 "nat",
1180 "IFC_SCAN_FREQUENCY",
1181 &h->ifc_scan_frequency)) 1139 &h->ifc_scan_frequency))
1182 h->ifc_scan_frequency = IFC_SCAN_FREQUENCY; 1140 h->ifc_scan_frequency = IFC_SCAN_FREQUENCY;
1183 if (GNUNET_OK != 1141 if (GNUNET_OK !=
1184 GNUNET_CONFIGURATION_get_value_time (cfg, 1142 GNUNET_CONFIGURATION_get_value_time (cfg, "nat", "HOSTNAME_DNS_FREQUENCY",
1185 "nat",
1186 "HOSTNAME_DNS_FREQUENCY",
1187 &h->hostname_dns_frequency)) 1143 &h->hostname_dns_frequency))
1188 h->hostname_dns_frequency = HOSTNAME_DNS_FREQUENCY; 1144 h->hostname_dns_frequency = HOSTNAME_DNS_FREQUENCY;
1189 1145
@@ -1191,8 +1147,8 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
1191 h->enable_nat_server = GNUNET_NO; 1147 h->enable_nat_server = GNUNET_NO;
1192 1148
1193 /* Check if NAT was hole-punched */ 1149 /* Check if NAT was hole-punched */
1194 if ((NULL != h->address_callback) && 1150 if ((NULL != h->address_callback) && (h->external_address != NULL) &&
1195 (h->external_address != NULL) && (h->nat_punched == GNUNET_YES)) 1151 (h->nat_punched == GNUNET_YES))
1196 { 1152 {
1197 h->dns_task = GNUNET_SCHEDULER_add_now (&resolve_dns, h); 1153 h->dns_task = GNUNET_SCHEDULER_add_now (&resolve_dns, h);
1198 h->enable_nat_server = GNUNET_NO; 1154 h->enable_nat_server = GNUNET_NO;
@@ -1200,8 +1156,7 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
1200 } 1156 }
1201 1157
1202 /* Test for SUID binaries */ 1158 /* Test for SUID binaries */
1203 if ((h->behind_nat == GNUNET_YES) && 1159 if ((h->behind_nat == GNUNET_YES) && (GNUNET_YES == h->enable_nat_server) &&
1204 (GNUNET_YES == h->enable_nat_server) &&
1205 (GNUNET_YES != 1160 (GNUNET_YES !=
1206 GNUNET_OS_check_helper_binary ("gnunet-helper-nat-server"))) 1161 GNUNET_OS_check_helper_binary ("gnunet-helper-nat-server")))
1207 { 1162 {
@@ -1313,8 +1268,7 @@ GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *h)
1313 { 1268 {
1314 GNUNET_CONTAINER_DLL_remove (h->lal_head, h->lal_tail, lal); 1269 GNUNET_CONTAINER_DLL_remove (h->lal_head, h->lal_tail, lal);
1315 if (NULL != h->address_callback) 1270 if (NULL != h->address_callback)
1316 h->address_callback (h->callback_cls, 1271 h->address_callback (h->callback_cls, GNUNET_NO,
1317 GNUNET_NO,
1318 (const struct sockaddr *) &lal[1], lal->addrlen); 1272 (const struct sockaddr *) &lal[1], lal->addrlen);
1319 GNUNET_free (lal); 1273 GNUNET_free (lal);
1320 } 1274 }
@@ -1349,8 +1303,7 @@ GNUNET_NAT_run_client (struct GNUNET_NAT_Handle *h,
1349 1303
1350 if (h->internal_address == NULL) 1304 if (h->internal_address == NULL)
1351 { 1305 {
1352 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, 1306 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "nat",
1353 "nat",
1354 _ 1307 _
1355 ("Internal IP address not known, cannot use ICMP NAT traversal method\n")); 1308 ("Internal IP address not known, cannot use ICMP NAT traversal method\n"));
1356 return; 1309 return;
@@ -1363,17 +1316,14 @@ GNUNET_NAT_run_client (struct GNUNET_NAT_Handle *h,
1363 } 1316 }
1364 GNUNET_snprintf (port_as_string, sizeof (port_as_string), "%d", h->adv_port); 1317 GNUNET_snprintf (port_as_string, sizeof (port_as_string), "%d", h->adv_port);
1365#if DEBUG_NAT 1318#if DEBUG_NAT
1366 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1319 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat",
1367 "nat",
1368 _("Running gnunet-helper-nat-client %s %s %u\n"), 1320 _("Running gnunet-helper-nat-client %s %s %u\n"),
1369 h->internal_address, inet4, (unsigned int) h->adv_port); 1321 h->internal_address, inet4, (unsigned int) h->adv_port);
1370#endif 1322#endif
1371 proc = GNUNET_OS_start_process (NULL, 1323 proc =
1372 NULL, 1324 GNUNET_OS_start_process (NULL, NULL, "gnunet-helper-nat-client",
1373 "gnunet-helper-nat-client", 1325 "gnunet-helper-nat-client", h->internal_address,
1374 "gnunet-helper-nat-client", 1326 inet4, port_as_string, NULL);
1375 h->internal_address,
1376 inet4, port_as_string, NULL);
1377 if (NULL == proc) 1327 if (NULL == proc)
1378 return; 1328 return;
1379 /* we know that the gnunet-helper-nat-client will terminate virtually 1329 /* we know that the gnunet-helper-nat-client will terminate virtually
@@ -1394,8 +1344,8 @@ GNUNET_NAT_run_client (struct GNUNET_NAT_Handle *h,
1394 * GNUNET_SYSERR if the address is malformed 1344 * GNUNET_SYSERR if the address is malformed
1395 */ 1345 */
1396int 1346int
1397GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *h, 1347GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *h, const void *addr,
1398 const void *addr, socklen_t addrlen) 1348 socklen_t addrlen)
1399{ 1349{
1400 struct LocalAddressList *pos; 1350 struct LocalAddressList *pos;
1401 const struct sockaddr_in *in4; 1351 const struct sockaddr_in *in4;
diff --git a/src/nat/nat_mini.c b/src/nat/nat_mini.c
index c40231067..e88c9ca55 100644
--- a/src/nat/nat_mini.c
+++ b/src/nat/nat_mini.c
@@ -118,8 +118,9 @@ read_external_ipv4 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
118 118
119 eh->task = GNUNET_SCHEDULER_NO_TASK; 119 eh->task = GNUNET_SCHEDULER_NO_TASK;
120 if (GNUNET_YES == GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, eh->r)) 120 if (GNUNET_YES == GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, eh->r))
121 ret = GNUNET_DISK_file_read (eh->r, 121 ret =
122 &eh->buf[eh->off], sizeof (eh->buf) - eh->off); 122 GNUNET_DISK_file_read (eh->r, &eh->buf[eh->off],
123 sizeof (eh->buf) - eh->off);
123 else 124 else
124 ret = -1; /* error reading, timeout, etc. */ 125 ret = -1; /* error reading, timeout, etc. */
125 if (ret > 0) 126 if (ret > 0)
@@ -172,9 +173,9 @@ GNUNET_NAT_mini_get_external_ipv4 (struct GNUNET_TIME_Relative timeout,
172 GNUNET_free (eh); 173 GNUNET_free (eh);
173 return NULL; 174 return NULL;
174 } 175 }
175 eh->eip = GNUNET_OS_start_process (NULL, 176 eh->eip =
176 eh->opipe, 177 GNUNET_OS_start_process (NULL, eh->opipe, "external-ip", "external-ip",
177 "external-ip", "external-ip", NULL); 178 NULL);
178 if (NULL == eh->eip) 179 if (NULL == eh->eip)
179 { 180 {
180 GNUNET_DISK_pipe_close (eh->opipe); 181 GNUNET_DISK_pipe_close (eh->opipe);
@@ -184,8 +185,8 @@ GNUNET_NAT_mini_get_external_ipv4 (struct GNUNET_TIME_Relative timeout,
184 GNUNET_DISK_pipe_close_end (eh->opipe, GNUNET_DISK_PIPE_END_WRITE); 185 GNUNET_DISK_pipe_close_end (eh->opipe, GNUNET_DISK_PIPE_END_WRITE);
185 eh->timeout = GNUNET_TIME_relative_to_absolute (timeout); 186 eh->timeout = GNUNET_TIME_relative_to_absolute (timeout);
186 eh->r = GNUNET_DISK_pipe_handle (eh->opipe, GNUNET_DISK_PIPE_END_READ); 187 eh->r = GNUNET_DISK_pipe_handle (eh->opipe, GNUNET_DISK_PIPE_END_READ);
187 eh->task = GNUNET_SCHEDULER_add_read_file (timeout, 188 eh->task =
188 eh->r, &read_external_ipv4, eh); 189 GNUNET_SCHEDULER_add_read_file (timeout, eh->r, &read_external_ipv4, eh);
189 return eh; 190 return eh;
190} 191}
191 192
@@ -278,8 +279,8 @@ struct GNUNET_NAT_MiniHandle
278 * @param cls the 'struct GNUNET_NAT_MiniHandle' 279 * @param cls the 'struct GNUNET_NAT_MiniHandle'
279 * @param tc scheduler context 280 * @param tc scheduler context
280 */ 281 */
281static void 282static void do_refresh (void *cls,
282do_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 283 const struct GNUNET_SCHEDULER_TaskContext *tc);
283 284
284 285
285/** 286/**
@@ -322,19 +323,15 @@ process_refresh_output (void *cls, const char *line)
322 mini->did_map = GNUNET_NO; 323 mini->did_map = GNUNET_NO;
323 } 324 }
324 GNUNET_snprintf (pstr, sizeof (pstr), "%u", (unsigned int) mini->port); 325 GNUNET_snprintf (pstr, sizeof (pstr), "%u", (unsigned int) mini->port);
325 mini->map_cmd = GNUNET_OS_command_run (&process_map_output, 326 mini->map_cmd =
326 mini, 327 GNUNET_OS_command_run (&process_map_output, mini, MAP_TIMEOUT,
327 MAP_TIMEOUT, 328 "upnpc", "upnpc", "-r", pstr,
328 "upnpc", 329 mini->is_tcp ? "tcp" : "udp", NULL);
329 "upnpc",
330 "-r", pstr,
331 mini->is_tcp ? "tcp" : "udp",
332 NULL);
333 if (NULL != mini->map_cmd) 330 if (NULL != mini->map_cmd)
334 return; 331 return;
335 } 332 }
336 mini->refresh_task = GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ, 333 mini->refresh_task =
337 &do_refresh, mini); 334 GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ, &do_refresh, mini);
338 return; 335 return;
339 } 336 }
340 if (!mini->did_map) 337 if (!mini->did_map)
@@ -377,10 +374,11 @@ process_refresh_output (void *cls, const char *line)
377 return; /* skip */ 374 return; /* skip */
378 if (NULL == strstr (s, pstr)) 375 if (NULL == strstr (s, pstr))
379 return; /* skip */ 376 return; /* skip */
380 if (1 != sscanf (line, 377 if (1 !=
381 (mini->is_tcp) 378 sscanf (line,
382 ? "%*u TCP %u->%*s:%*u %*s" 379 (mini->
383 : "%*u UDP %u->%*s:%*u %*s", &nport)) 380 is_tcp) ? "%*u TCP %u->%*s:%*u %*s" :
381 "%*u UDP %u->%*s:%*u %*s", &nport))
384 return; /* skip */ 382 return; /* skip */
385 mini->found = GNUNET_YES; 383 mini->found = GNUNET_YES;
386 if (nport == ntohs (mini->current_addr.sin_port)) 384 if (nport == ntohs (mini->current_addr.sin_port))
@@ -410,10 +408,9 @@ do_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
410 408
411 mini->refresh_task = GNUNET_SCHEDULER_NO_TASK; 409 mini->refresh_task = GNUNET_SCHEDULER_NO_TASK;
412 mini->found = GNUNET_NO; 410 mini->found = GNUNET_NO;
413 mini->refresh_cmd = GNUNET_OS_command_run (&process_refresh_output, 411 mini->refresh_cmd =
414 mini, 412 GNUNET_OS_command_run (&process_refresh_output, mini, MAP_TIMEOUT,
415 MAP_TIMEOUT, 413 "upnpc", "upnpc", "-l", NULL);
416 "upnpc", "upnpc", "-l", NULL);
417} 414}
418 415
419 416
@@ -436,8 +433,8 @@ process_map_output (void *cls, const char *line)
436 { 433 {
437 GNUNET_OS_command_stop (mini->map_cmd); 434 GNUNET_OS_command_stop (mini->map_cmd);
438 mini->map_cmd = NULL; 435 mini->map_cmd = NULL;
439 mini->refresh_task = GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ, 436 mini->refresh_task =
440 &do_refresh, mini); 437 GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ, &do_refresh, mini);
441 return; 438 return;
442 } 439 }
443 /* 440 /*
@@ -486,8 +483,7 @@ process_map_output (void *cls, const char *line)
486 * @return NULL on error (no 'upnpc' installed) 483 * @return NULL on error (no 'upnpc' installed)
487 */ 484 */
488struct GNUNET_NAT_MiniHandle * 485struct GNUNET_NAT_MiniHandle *
489GNUNET_NAT_mini_map_start (uint16_t port, 486GNUNET_NAT_mini_map_start (uint16_t port, int is_tcp,
490 int is_tcp,
491 GNUNET_NAT_AddressCallback ac, void *ac_cls) 487 GNUNET_NAT_AddressCallback ac, void *ac_cls)
492{ 488{
493 struct GNUNET_NAT_MiniHandle *ret; 489 struct GNUNET_NAT_MiniHandle *ret;
@@ -501,17 +497,13 @@ GNUNET_NAT_mini_map_start (uint16_t port,
501 ret->is_tcp = is_tcp; 497 ret->is_tcp = is_tcp;
502 ret->port = port; 498 ret->port = port;
503 GNUNET_snprintf (pstr, sizeof (pstr), "%u", (unsigned int) port); 499 GNUNET_snprintf (pstr, sizeof (pstr), "%u", (unsigned int) port);
504 ret->map_cmd = GNUNET_OS_command_run (&process_map_output, 500 ret->map_cmd =
505 ret, 501 GNUNET_OS_command_run (&process_map_output, ret, MAP_TIMEOUT, "upnpc",
506 MAP_TIMEOUT, 502 "upnpc", "-r", pstr, is_tcp ? "tcp" : "udp", NULL);
507 "upnpc",
508 "upnpc",
509 "-r", pstr,
510 is_tcp ? "tcp" : "udp", NULL);
511 if (NULL != ret->map_cmd) 503 if (NULL != ret->map_cmd)
512 return ret; 504 return ret;
513 ret->refresh_task = GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ, 505 ret->refresh_task =
514 &do_refresh, ret); 506 GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ, &do_refresh, ret);
515 507
516 return ret; 508 return ret;
517} 509}
@@ -581,21 +573,17 @@ GNUNET_NAT_mini_map_stop (struct GNUNET_NAT_MiniHandle *mini)
581 /* Note: oddly enough, deletion uses the external port whereas 573 /* Note: oddly enough, deletion uses the external port whereas
582 * addition uses the internal port; this rarely matters since they 574 * addition uses the internal port; this rarely matters since they
583 * often are the same, but it might... */ 575 * often are the same, but it might... */
584 GNUNET_snprintf (pstr, sizeof (pstr), 576 GNUNET_snprintf (pstr, sizeof (pstr), "%u",
585 "%u", (unsigned int) ntohs (mini->current_addr.sin_port)); 577 (unsigned int) ntohs (mini->current_addr.sin_port));
586#if DEBUG_NAT 578#if DEBUG_NAT
587 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 579 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat",
588 "nat",
589 "Unmapping port %u with UPnP\n", 580 "Unmapping port %u with UPnP\n",
590 ntohs (mini->current_addr.sin_port)); 581 ntohs (mini->current_addr.sin_port));
591#endif 582#endif
592 mini->unmap_cmd = GNUNET_OS_command_run (&process_unmap_output, 583 mini->unmap_cmd =
593 mini, 584 GNUNET_OS_command_run (&process_unmap_output, mini, UNMAP_TIMEOUT,
594 UNMAP_TIMEOUT, 585 "upnpc", "upnpc", "-d", pstr,
595 "upnpc", 586 mini->is_tcp ? "tcp" : "udp", NULL);
596 "upnpc",
597 "-d", pstr,
598 mini->is_tcp ? "tcp" : "udp", NULL);
599} 587}
600 588
601 589
diff --git a/src/nat/nat_test.c b/src/nat/nat_test.c
index 30db00803..74bb758dd 100644
--- a/src/nat/nat_test.c
+++ b/src/nat/nat_test.c
@@ -178,8 +178,7 @@ reversal_cb (void *cls, const struct sockaddr *addr, socklen_t addrlen)
178 if (h->data != sa->sin_port) 178 if (h->data != sa->sin_port)
179 { 179 {
180#if DEBUG_NAT 180#if DEBUG_NAT
181 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 181 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat",
182 "nat",
183 "Received connection reversal request for wrong port\n"); 182 "Received connection reversal request for wrong port\n");
184#endif 183#endif
185 return; /* wrong port */ 184 return; /* wrong port */
@@ -202,11 +201,11 @@ do_udp_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
202 struct GNUNET_NAT_Test *tst = cls; 201 struct GNUNET_NAT_Test *tst = cls;
203 uint16_t data; 202 uint16_t data;
204 203
205 tst->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 204 tst->ltask =
206 tst->lsock, &do_udp_read, tst); 205 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, tst->lsock,
206 &do_udp_read, tst);
207 if ((NULL != tc->write_ready) && 207 if ((NULL != tc->write_ready) &&
208 (GNUNET_NETWORK_fdset_isset (tc->read_ready, 208 (GNUNET_NETWORK_fdset_isset (tc->read_ready, tst->lsock)) &&
209 tst->lsock)) &&
210 (sizeof (data) == 209 (sizeof (data) ==
211 GNUNET_NETWORK_socket_recv (tst->lsock, &data, sizeof (data)))) 210 GNUNET_NETWORK_socket_recv (tst->lsock, &data, sizeof (data))))
212 { 211 {
@@ -214,14 +213,14 @@ do_udp_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
214 tst->report (tst->report_cls, GNUNET_OK); 213 tst->report (tst->report_cls, GNUNET_OK);
215#if DEBUG_NAT 214#if DEBUG_NAT
216 else 215 else
217 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 216 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat",
218 "nat", "Received data mismatches expected value\n"); 217 "Received data mismatches expected value\n");
219#endif 218#endif
220 } 219 }
221#if DEBUG_NAT 220#if DEBUG_NAT
222 else 221 else
223 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 222 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat",
224 "nat", "Failed to receive data from inbound connection\n"); 223 "Failed to receive data from inbound connection\n");
225#endif 224#endif
226} 225}
227 226
@@ -244,8 +243,7 @@ do_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
244 tst = na->h; 243 tst = na->h;
245 GNUNET_CONTAINER_DLL_remove (tst->na_head, tst->na_tail, na); 244 GNUNET_CONTAINER_DLL_remove (tst->na_head, tst->na_tail, na);
246 if ((NULL != tc->write_ready) && 245 if ((NULL != tc->write_ready) &&
247 (GNUNET_NETWORK_fdset_isset (tc->read_ready, 246 (GNUNET_NETWORK_fdset_isset (tc->read_ready, na->sock)) &&
248 na->sock)) &&
249 (sizeof (data) == 247 (sizeof (data) ==
250 GNUNET_NETWORK_socket_recv (na->sock, &data, sizeof (data)))) 248 GNUNET_NETWORK_socket_recv (na->sock, &data, sizeof (data))))
251 { 249 {
@@ -259,8 +257,8 @@ do_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
259 } 257 }
260#if DEBUG_NAT 258#if DEBUG_NAT
261 else 259 else
262 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 260 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat",
263 "nat", "Failed to receive data from inbound connection\n"); 261 "Failed to receive data from inbound connection\n");
264#endif 262#endif
265 GNUNET_NETWORK_socket_close (na->sock); 263 GNUNET_NETWORK_socket_close (na->sock);
266 GNUNET_free (na); 264 GNUNET_free (na);
@@ -284,8 +282,9 @@ do_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
284 tst->ltask = GNUNET_SCHEDULER_NO_TASK; 282 tst->ltask = GNUNET_SCHEDULER_NO_TASK;
285 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 283 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
286 return; 284 return;
287 tst->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 285 tst->ltask =
288 tst->lsock, &do_accept, tst); 286 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, tst->lsock,
287 &do_accept, tst);
289 s = GNUNET_NETWORK_socket_accept (tst->lsock, NULL, NULL); 288 s = GNUNET_NETWORK_socket_accept (tst->lsock, NULL, NULL);
290 if (NULL == s) 289 if (NULL == s)
291 { 290 {
@@ -293,14 +292,15 @@ do_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
293 return; /* odd error */ 292 return; /* odd error */
294 } 293 }
295#if DEBUG_NAT 294#if DEBUG_NAT
296 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 295 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat",
297 "nat", "Got an inbound connection, waiting for data\n"); 296 "Got an inbound connection, waiting for data\n");
298#endif 297#endif
299 wl = GNUNET_malloc (sizeof (struct NatActivity)); 298 wl = GNUNET_malloc (sizeof (struct NatActivity));
300 wl->sock = s; 299 wl->sock = s;
301 wl->h = tst; 300 wl->h = tst;
302 wl->rtask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 301 wl->rtask =
303 wl->sock, &do_read, wl); 302 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, wl->sock,
303 &do_read, wl);
304 GNUNET_CONTAINER_DLL_insert (tst->na_head, tst->na_tail, wl); 304 GNUNET_CONTAINER_DLL_insert (tst->na_head, tst->na_tail, wl);
305} 305}
306 306
@@ -315,8 +315,8 @@ do_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
315 * @param addrlen actual lenght of the address 315 * @param addrlen actual lenght of the address
316 */ 316 */
317static void 317static void
318addr_cb (void *cls, 318addr_cb (void *cls, int add_remove, const struct sockaddr *addr,
319 int add_remove, const struct sockaddr *addr, socklen_t addrlen) 319 socklen_t addrlen)
320{ 320{
321 struct GNUNET_NAT_Test *h = cls; 321 struct GNUNET_NAT_Test *h = cls;
322 struct ClientActivity *ca; 322 struct ClientActivity *ca;
@@ -329,8 +329,7 @@ addr_cb (void *cls,
329 if (addrlen != sizeof (struct sockaddr_in)) 329 if (addrlen != sizeof (struct sockaddr_in))
330 return; /* ignore IPv6 here */ 330 return; /* ignore IPv6 here */
331#if DEBUG_NAT 331#if DEBUG_NAT
332 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 332 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat",
333 "nat",
334 "Asking gnunet-nat-server to connect to `%s'\n", 333 "Asking gnunet-nat-server to connect to `%s'\n",
335 GNUNET_a2s (addr, addrlen)); 334 GNUNET_a2s (addr, addrlen));
336#endif 335#endif
@@ -353,11 +352,10 @@ addr_cb (void *cls,
353 ca->client = client; 352 ca->client = client;
354 GNUNET_CONTAINER_DLL_insert (h->ca_head, h->ca_tail, ca); 353 GNUNET_CONTAINER_DLL_insert (h->ca_head, h->ca_tail, ca);
355 GNUNET_break (GNUNET_OK == 354 GNUNET_break (GNUNET_OK ==
356 GNUNET_CLIENT_transmit_and_get_response (client, 355 GNUNET_CLIENT_transmit_and_get_response (client, &msg.header,
357 &msg.header,
358 GNUNET_TIME_UNIT_SECONDS, 356 GNUNET_TIME_UNIT_SECONDS,
359 GNUNET_YES, 357 GNUNET_YES, NULL,
360 NULL, NULL)); 358 NULL));
361} 359}
362 360
363 361
@@ -375,9 +373,7 @@ addr_cb (void *cls,
375 */ 373 */
376struct GNUNET_NAT_Test * 374struct GNUNET_NAT_Test *
377GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, 375GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
378 int is_tcp, 376 int is_tcp, uint16_t bnd_port, uint16_t adv_port,
379 uint16_t bnd_port,
380 uint16_t adv_port,
381 GNUNET_NAT_TestCallback report, void *report_cls) 377 GNUNET_NAT_TestCallback report, void *report_cls)
382{ 378{
383 struct GNUNET_NAT_Test *ret; 379 struct GNUNET_NAT_Test *ret;
@@ -401,19 +397,21 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
401 ret->report_cls = report_cls; 397 ret->report_cls = report_cls;
402 if (bnd_port == 0) 398 if (bnd_port == 0)
403 { 399 {
404 ret->nat = GNUNET_NAT_register (cfg, is_tcp, 400 ret->nat =
405 0, 401 GNUNET_NAT_register (cfg, is_tcp, 0, 0, NULL, NULL, &addr_cb,
406 0, NULL, NULL, &addr_cb, &reversal_cb, ret); 402 &reversal_cb, ret);
407 } 403 }
408 else 404 else
409 { 405 {
410 ret->lsock = GNUNET_NETWORK_socket_create (AF_INET, 406 ret->lsock =
411 (is_tcp == GNUNET_YES) 407 GNUNET_NETWORK_socket_create (AF_INET,
412 ? SOCK_STREAM : SOCK_DGRAM, 0); 408 (is_tcp ==
409 GNUNET_YES) ? SOCK_STREAM : SOCK_DGRAM,
410 0);
413 if ((ret->lsock == NULL) || 411 if ((ret->lsock == NULL) ||
414 (GNUNET_OK != GNUNET_NETWORK_socket_bind (ret->lsock, 412 (GNUNET_OK !=
415 (const struct sockaddr *) &sa, 413 GNUNET_NETWORK_socket_bind (ret->lsock, (const struct sockaddr *) &sa,
416 sizeof (sa)))) 414 sizeof (sa))))
417 { 415 {
418 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 416 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
419 _ 417 _
@@ -428,18 +426,19 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
428 if (GNUNET_YES == is_tcp) 426 if (GNUNET_YES == is_tcp)
429 { 427 {
430 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_listen (ret->lsock, 5)); 428 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_listen (ret->lsock, 5));
431 ret->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 429 ret->ltask =
432 ret->lsock, &do_accept, ret); 430 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
431 ret->lsock, &do_accept, ret);
433 } 432 }
434 else 433 else
435 { 434 {
436 ret->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 435 ret->ltask =
437 ret->lsock, 436 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
438 &do_udp_read, ret); 437 ret->lsock, &do_udp_read, ret);
439 } 438 }
440 ret->nat = GNUNET_NAT_register (cfg, is_tcp, 439 ret->nat =
441 adv_port, 440 GNUNET_NAT_register (cfg, is_tcp, adv_port, 1, addrs, addrlens,
442 1, addrs, addrlens, &addr_cb, NULL, ret); 441 &addr_cb, NULL, ret);
443 } 442 }
444 return ret; 443 return ret;
445} 444}
diff --git a/src/nat/test_nat.c b/src/nat/test_nat.c
index 12ff30cac..6a533798e 100644
--- a/src/nat/test_nat.c
+++ b/src/nat/test_nat.c
@@ -55,13 +55,13 @@
55 * believes to be valid for the transport. 55 * believes to be valid for the transport.
56 */ 56 */
57static void 57static void
58addr_callback (void *cls, int add_remove, 58addr_callback (void *cls, int add_remove, const struct sockaddr *addr,
59 const struct sockaddr *addr, socklen_t addrlen) 59 socklen_t addrlen)
60{ 60{
61 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 61 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Address changed: %s `%s' (%u bytes)\n",
62 "Address changed: %s `%s' (%u bytes)\n", 62 add_remove == GNUNET_YES ? "added" : "removed", GNUNET_a2s (addr,
63 add_remove == GNUNET_YES ? "added" : "removed", 63 addrlen),
64 GNUNET_a2s (addr, addrlen), (unsigned int) addrlen); 64 (unsigned int) addrlen);
65} 65}
66 66
67 67
@@ -97,9 +97,8 @@ struct addr_cls
97 * @return GNUNET_OK to continue iterating 97 * @return GNUNET_OK to continue iterating
98 */ 98 */
99static int 99static int
100process_if (void *cls, 100process_if (void *cls, const char *name, int isDefault,
101 const char *name, 101 const struct sockaddr *addr, socklen_t addrlen)
102 int isDefault, const struct sockaddr *addr, socklen_t addrlen)
103{ 102{
104 struct addr_cls *data = cls; 103 struct addr_cls *data = cls;
105 104
@@ -119,9 +118,8 @@ process_if (void *cls,
119 * Main function run with scheduler. 118 * Main function run with scheduler.
120 */ 119 */
121static void 120static void
122run (void *cls, 121run (void *cls, char *const *args, const char *cfgfile,
123 char *const *args, 122 const struct GNUNET_CONFIGURATION_Handle *cfg)
124 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
125{ 123{
126 struct GNUNET_NAT_Handle *nat; 124 struct GNUNET_NAT_Handle *nat;
127 struct addr_cls data; 125 struct addr_cls data;
@@ -147,9 +145,7 @@ run (void *cls,
147 GNUNET_a2s (addr, data.addrlen)); 145 GNUNET_a2s (addr, data.addrlen));
148 146
149 nat = GNUNET_NAT_register (cfg, GNUNET_YES /* tcp */ , 147 nat = GNUNET_NAT_register (cfg, GNUNET_YES /* tcp */ ,
150 2086, 148 2086, 1, (const struct sockaddr **) &addr,
151 1,
152 (const struct sockaddr **) &addr,
153 &data.addrlen, &addr_callback, NULL, NULL); 149 &data.addrlen, &addr_callback, NULL, NULL);
154 GNUNET_free (addr); 150 GNUNET_free (addr);
155 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &stop, nat); 151 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &stop, nat);
diff --git a/src/nat/test_nat_mini.c b/src/nat/test_nat_mini.c
index 8f689d6bc..4aac3d17f 100644
--- a/src/nat/test_nat_mini.c
+++ b/src/nat/test_nat_mini.c
@@ -46,13 +46,13 @@
46 * believes to be valid for the transport. 46 * believes to be valid for the transport.
47 */ 47 */
48static void 48static void
49addr_callback (void *cls, int add_remove, 49addr_callback (void *cls, int add_remove, const struct sockaddr *addr,
50 const struct sockaddr *addr, socklen_t addrlen) 50 socklen_t addrlen)
51{ 51{
52 fprintf (stderr, 52 fprintf (stderr, "Address changed: %s `%s' (%u bytes)\n",
53 "Address changed: %s `%s' (%u bytes)\n", 53 add_remove == GNUNET_YES ? "added" : "removed", GNUNET_a2s (addr,
54 add_remove == GNUNET_YES ? "added" : "removed", 54 addrlen),
55 GNUNET_a2s (addr, addrlen), (unsigned int) addrlen); 55 (unsigned int) addrlen);
56} 56}
57 57
58 58
@@ -74,9 +74,8 @@ stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
74 * Main function run with scheduler. 74 * Main function run with scheduler.
75 */ 75 */
76static void 76static void
77run (void *cls, 77run (void *cls, char *const *args, const char *cfgfile,
78 char *const *args, 78 const struct GNUNET_CONFIGURATION_Handle *cfg)
79 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
80{ 79{
81 struct GNUNET_NAT_MiniHandle *mini; 80 struct GNUNET_NAT_MiniHandle *mini;
82 81
diff --git a/src/nat/test_nat_test.c b/src/nat/test_nat_test.c
index 520d82d92..b1e6235f9 100644
--- a/src/nat/test_nat_test.c
+++ b/src/nat/test_nat_test.c
@@ -65,12 +65,12 @@ report_success (void *cls, int success)
65 * Main function run with scheduler. 65 * Main function run with scheduler.
66 */ 66 */
67static void 67static void
68run (void *cls, 68run (void *cls, char *const *args, const char *cfgfile,
69 char *const *args, 69 const struct GNUNET_CONFIGURATION_Handle *cfg)
70 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
71{ 70{
72 tst = GNUNET_NAT_test_start (cfg, GNUNET_YES, 71 tst =
73 1285, 1285, &report_success, NULL); 72 GNUNET_NAT_test_start (cfg, GNUNET_YES, 1285, 1285, &report_success,
73 NULL);
74 if (NULL == tst) 74 if (NULL == tst)
75 return; 75 return;
76 end = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL); 76 end = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL);
@@ -105,16 +105,16 @@ main (int argc, char *const argv[])
105 "WARNING", 105 "WARNING",
106#endif 106#endif
107 NULL); 107 NULL);
108 gns = GNUNET_OS_start_process (NULL, NULL, 108 gns =
109 "gnunet-nat-server", "gnunet-nat-server", 109 GNUNET_OS_start_process (NULL, NULL, "gnunet-nat-server",
110 "gnunet-nat-server",
110#if VERBOSE 111#if VERBOSE
111 "-L", "DEBUG", 112 "-L", "DEBUG",
112#endif 113#endif
113 "-c", "test_nat_test_data.conf", 114 "-c", "test_nat_test_data.conf", "12345", NULL);
114 "12345", NULL);
115 GNUNET_assert (NULL != gns); 115 GNUNET_assert (NULL != gns);
116 GNUNET_PROGRAM_run (5, argv_prog, 116 GNUNET_PROGRAM_run (5, argv_prog, "test-nat-test", "nohelp", options, &run,
117 "test-nat-test", "nohelp", options, &run, NULL); 117 NULL);
118 GNUNET_break (0 == GNUNET_OS_process_kill (gns, SIGTERM)); 118 GNUNET_break (0 == GNUNET_OS_process_kill (gns, SIGTERM));
119 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (gns)); 119 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (gns));
120 GNUNET_OS_process_close (gns); 120 GNUNET_OS_process_close (gns);
diff --git a/src/nse/gnunet-nse-profiler.c b/src/nse/gnunet-nse-profiler.c
index b88dbc3fc..df26280c4 100644
--- a/src/nse/gnunet-nse-profiler.c
+++ b/src/nse/gnunet-nse-profiler.c
@@ -213,13 +213,12 @@ handle_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp,
213 213
214 if (output_file != NULL) 214 if (output_file != NULL)
215 { 215 {
216 size = GNUNET_asprintf (&output_buffer, 216 size =
217 "%s %llu %llu %f %f %f\n", 217 GNUNET_asprintf (&output_buffer, "%s %llu %llu %f %f %f\n",
218 GNUNET_i2s (&peer->daemon->id), 218 GNUNET_i2s (&peer->daemon->id), peers_running,
219 peers_running, 219 timestamp.abs_value,
220 timestamp.abs_value, 220 GNUNET_NSE_log_estimate_to_n (estimate), estimate,
221 GNUNET_NSE_log_estimate_to_n (estimate), 221 std_dev);
222 estimate, std_dev);
223 if (size != GNUNET_DISK_file_write (output_file, output_buffer, size)) 222 if (size != GNUNET_DISK_file_write (output_file, output_buffer, size))
224 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n"); 223 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
225 GNUNET_free (output_buffer); 224 GNUNET_free (output_buffer);
@@ -254,9 +253,9 @@ connect_nse_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
254 if (GNUNET_YES == 253 if (GNUNET_YES ==
255 GNUNET_TESTING_daemon_running (GNUNET_TESTING_daemon_get (pg, i))) 254 GNUNET_TESTING_daemon_running (GNUNET_TESTING_daemon_get (pg, i)))
256 { 255 {
257 current_peer->nse_handle = GNUNET_NSE_connect (current_peer->daemon->cfg, 256 current_peer->nse_handle =
258 &handle_estimate, 257 GNUNET_NSE_connect (current_peer->daemon->cfg, &handle_estimate,
259 current_peer); 258 current_peer);
260 GNUNET_assert (current_peer->nse_handle != NULL); 259 GNUNET_assert (current_peer->nse_handle != NULL);
261 } 260 }
262 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer); 261 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer);
@@ -264,8 +263,8 @@ connect_nse_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
264} 263}
265 264
266 265
267static void 266static void churn_peers (void *cls,
268churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 267 const struct GNUNET_SCHEDULER_TaskContext *tc);
269 268
270 269
271/** 270/**
@@ -286,9 +285,9 @@ stats_finished_callback (void *cls, int success)
286 { 285 {
287 /* Stats lookup successful, write out data */ 286 /* Stats lookup successful, write out data */
288 buf = NULL; 287 buf = NULL;
289 buf_len = GNUNET_asprintf (&buf, 288 buf_len =
290 "TOTAL_NSE_BYTES: %u\n", 289 GNUNET_asprintf (&buf, "TOTAL_NSE_BYTES: %u\n",
291 stats_context->total_nse_bytes); 290 stats_context->total_nse_bytes);
292 if (buf_len > 0) 291 if (buf_len > 0)
293 { 292 {
294 GNUNET_DISK_file_write (data_file, buf, buf_len); 293 GNUNET_DISK_file_write (data_file, buf, buf_len);
@@ -314,10 +313,9 @@ stats_finished_callback (void *cls, int success)
314 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration 313 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
315 */ 314 */
316static int 315static int
317statistics_iterator (void *cls, 316statistics_iterator (void *cls, const struct GNUNET_PeerIdentity *peer,
318 const struct GNUNET_PeerIdentity *peer, 317 const char *subsystem, const char *name, uint64_t value,
319 const char *subsystem, 318 int is_persistent)
320 const char *name, uint64_t value, int is_persistent)
321{ 319{
322 struct StatsContext *stats_context = cls; 320 struct StatsContext *stats_context = cls;
323 321
@@ -350,10 +348,9 @@ disconnect_nse_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
350 } 348 }
351 349
352 GNUNET_asprintf (&buf, "round%llu", current_round); 350 GNUNET_asprintf (&buf, "round%llu", current_round);
353 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (testing_cfg, 351 if (GNUNET_OK ==
354 "nse-profiler", 352 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "nse-profiler", buf,
355 buf, 353 &peers_next_round))
356 &peers_next_round))
357 { 354 {
358 current_round++; 355 current_round++;
359 GNUNET_assert (churn_task == GNUNET_SCHEDULER_NO_TASK); 356 GNUNET_assert (churn_task == GNUNET_SCHEDULER_NO_TASK);
@@ -364,8 +361,7 @@ disconnect_nse_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
364 stats_context = GNUNET_malloc (sizeof (struct StatsContext)); 361 stats_context = GNUNET_malloc (sizeof (struct StatsContext));
365 GNUNET_SCHEDULER_cancel (shutdown_handle); 362 GNUNET_SCHEDULER_cancel (shutdown_handle);
366 shutdown_handle = GNUNET_SCHEDULER_NO_TASK; 363 shutdown_handle = GNUNET_SCHEDULER_NO_TASK;
367 GNUNET_TESTING_get_statistics (pg, 364 GNUNET_TESTING_get_statistics (pg, &stats_finished_callback,
368 &stats_finished_callback,
369 &statistics_iterator, stats_context); 365 &statistics_iterator, stats_context);
370 } 366 }
371 GNUNET_free (buf); 367 GNUNET_free (buf);
@@ -381,8 +377,8 @@ disconnect_nse_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
381static void 377static void
382topology_output_callback (void *cls, const char *emsg) 378topology_output_callback (void *cls, const char *emsg)
383{ 379{
384 disconnect_task = GNUNET_SCHEDULER_add_delayed (wait_time, 380 disconnect_task =
385 &disconnect_nse_peers, NULL); 381 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_nse_peers, NULL);
386 GNUNET_SCHEDULER_add_now (&connect_nse_service, NULL); 382 GNUNET_SCHEDULER_add_now (&connect_nse_service, NULL);
387} 383}
388 384
@@ -404,19 +400,18 @@ churn_callback (void *cls, const char *emsg)
404 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 400 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
405 "Round %llu, churn finished successfully.\n", current_round); 401 "Round %llu, churn finished successfully.\n", current_round);
406 GNUNET_assert (disconnect_task == GNUNET_SCHEDULER_NO_TASK); 402 GNUNET_assert (disconnect_task == GNUNET_SCHEDULER_NO_TASK);
407 GNUNET_asprintf (&temp_output_file, 403 GNUNET_asprintf (&temp_output_file, "%s_%llu.dot", topology_file,
408 "%s_%llu.dot", topology_file, current_round); 404 current_round);
409 GNUNET_TESTING_peergroup_topology_to_file (pg, 405 GNUNET_TESTING_peergroup_topology_to_file (pg, temp_output_file,
410 temp_output_file,
411 &topology_output_callback, NULL); 406 &topology_output_callback, NULL);
412 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 407 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Writing topology to file %s\n",
413 "Writing topology to file %s\n", temp_output_file); 408 temp_output_file);
414 GNUNET_free (temp_output_file); 409 GNUNET_free (temp_output_file);
415 } 410 }
416 else 411 else
417 { 412 {
418 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 413 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Round %llu, churn FAILED!!\n",
419 "Round %llu, churn FAILED!!\n", current_round); 414 current_round);
420 GNUNET_SCHEDULER_cancel (shutdown_handle); 415 GNUNET_SCHEDULER_cancel (shutdown_handle);
421 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 416 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
422 } 417 }
@@ -433,9 +428,8 @@ churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
433 /* Nothing to do... */ 428 /* Nothing to do... */
434 GNUNET_SCHEDULER_add_now (&connect_nse_service, NULL); 429 GNUNET_SCHEDULER_add_now (&connect_nse_service, NULL);
435 GNUNET_assert (disconnect_task == GNUNET_SCHEDULER_NO_TASK); 430 GNUNET_assert (disconnect_task == GNUNET_SCHEDULER_NO_TASK);
436 disconnect_task = GNUNET_SCHEDULER_add_delayed (wait_time, 431 disconnect_task =
437 &disconnect_nse_peers, 432 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_nse_peers, NULL);
438 NULL);
439 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Round %lu, doing nothing!\n", 433 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Round %lu, doing nothing!\n",
440 current_round); 434 current_round);
441 } 435 }
@@ -451,18 +445,18 @@ churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
451 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 445 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
452 "Round %llu, turning off %llu peers, turning on %llu peers!\n", 446 "Round %llu, turning off %llu peers, turning on %llu peers!\n",
453 current_round, 447 current_round,
454 (peers_running > peers_next_round) 448 (peers_running >
455 ? peers_running - peers_next_round 449 peers_next_round) ? peers_running - peers_next_round : 0,
456 : 0, 450 (peers_next_round >
457 (peers_next_round > peers_running) 451 peers_running) ? peers_next_round - peers_running : 0);
458 ? peers_next_round - peers_running : 0);
459 GNUNET_TESTING_daemons_churn (pg, "nse", 452 GNUNET_TESTING_daemons_churn (pg, "nse",
460 (peers_running > peers_next_round) 453 (peers_running >
461 ? peers_running - peers_next_round 454 peers_next_round) ? peers_running -
462 : 0, 455 peers_next_round : 0,
463 (peers_next_round > peers_running) 456 (peers_next_round >
464 ? peers_next_round - peers_running 457 peers_running) ? peers_next_round -
465 : 0, wait_time, &churn_callback, NULL); 458 peers_running : 0, wait_time, &churn_callback,
459 NULL);
466 } 460 }
467} 461}
468 462
@@ -495,8 +489,8 @@ my_cb (void *cls, const char *emsg)
495 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
496 "Peer Group started successfully, connecting to NSE service for each peer!\n"); 490 "Peer Group started successfully, connecting to NSE service for each peer!\n");
497#endif 491#endif
498 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 492 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Have %u connections\n",
499 "Have %u connections\n", total_connections); 493 total_connections);
500 if (data_file != NULL) 494 if (data_file != NULL)
501 { 495 {
502 buf = NULL; 496 buf = NULL;
@@ -506,9 +500,8 @@ my_cb (void *cls, const char *emsg)
506 GNUNET_free (buf); 500 GNUNET_free (buf);
507 } 501 }
508 peers_running = GNUNET_TESTING_daemons_running (pg); 502 peers_running = GNUNET_TESTING_daemons_running (pg);
509 GNUNET_TESTING_daemons_start_service (pg, 503 GNUNET_TESTING_daemons_start_service (pg, "nse", wait_time, &nse_started_cb,
510 "nse", 504 NULL);
511 wait_time, &nse_started_cb, NULL);
512 505
513} 506}
514 507
@@ -528,10 +521,8 @@ my_cb (void *cls, const char *emsg)
528 * @param emsg error message (NULL on success) 521 * @param emsg error message (NULL on success)
529 */ 522 */
530static void 523static void
531connect_cb (void *cls, 524connect_cb (void *cls, const struct GNUNET_PeerIdentity *first,
532 const struct GNUNET_PeerIdentity *first, 525 const struct GNUNET_PeerIdentity *second, uint32_t distance,
533 const struct GNUNET_PeerIdentity *second,
534 uint32_t distance,
535 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 526 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
536 const struct GNUNET_CONFIGURATION_Handle *second_cfg, 527 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
537 struct GNUNET_TESTING_Daemon *first_daemon, 528 struct GNUNET_TESTING_Daemon *first_daemon,
@@ -543,9 +534,8 @@ connect_cb (void *cls,
543 534
544 535
545static void 536static void
546run (void *cls, 537run (void *cls, char *const *args, const char *cfgfile,
547 char *const *args, 538 const struct GNUNET_CONFIGURATION_Handle *cfg)
548 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
549{ 539{
550 char *temp_str; 540 char *temp_str;
551 unsigned long long temp_wait; 541 unsigned long long temp_wait;
@@ -555,100 +545,99 @@ run (void *cls,
555 testing_cfg = GNUNET_CONFIGURATION_create (); 545 testing_cfg = GNUNET_CONFIGURATION_create ();
556#if VERBOSE 546#if VERBOSE
557 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n"); 547 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n");
558 GNUNET_CONFIGURATION_set_value_string (testing_cfg, 548 GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing",
559 "testing", "use_progressbars", "YES"); 549 "use_progressbars", "YES");
560#endif 550#endif
561 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg, 551 if (GNUNET_OK !=
562 "testing", 552 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing",
563 "num_peers", 553 "num_peers", &num_peers))
564 &num_peers))
565 { 554 {
566 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 555 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
567 "Option TESTING:NUM_PEERS is required!\n"); 556 "Option TESTING:NUM_PEERS is required!\n");
568 return; 557 return;
569 } 558 }
570 559
571 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg, 560 if (GNUNET_OK !=
572 "nse-profiler", 561 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "nse-profiler",
573 "wait_time", 562 "wait_time", &temp_wait))
574 &temp_wait))
575 { 563 {
576 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 564 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
577 "Option nse-profiler:wait_time is required!\n"); 565 "Option nse-profiler:wait_time is required!\n");
578 return; 566 return;
579 } 567 }
580 568
581 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg, 569 if (GNUNET_OK !=
582 "nse-profiler", 570 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "nse-profiler",
583 "connection_limit", 571 "connection_limit",
584 &connection_limit)) 572 &connection_limit))
585 { 573 {
586 connection_limit = 0; 574 connection_limit = 0;
587 } 575 }
588 576
589 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (testing_cfg, 577 if (GNUNET_OK !=
590 "nse-profiler", 578 GNUNET_CONFIGURATION_get_value_string (testing_cfg, "nse-profiler",
591 "topology_output_file", 579 "topology_output_file",
592 &topology_file)) 580 &topology_file))
593 { 581 {
594 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 582 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
595 "Option nse-profiler:topology_output_file is required!\n"); 583 "Option nse-profiler:topology_output_file is required!\n");
596 return; 584 return;
597 } 585 }
598 586
599 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (testing_cfg, 587 if (GNUNET_OK !=
600 "nse-profiler", 588 GNUNET_CONFIGURATION_get_value_string (testing_cfg, "nse-profiler",
601 "data_output_file", 589 "data_output_file",
602 &data_filename)) 590 &data_filename))
603 { 591 {
604 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 592 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
605 "Option nse-profiler:data_output_file is required!\n"); 593 "Option nse-profiler:data_output_file is required!\n");
606 return; 594 return;
607 } 595 }
608 596
609 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (testing_cfg, 597 if (GNUNET_YES ==
610 "nse-profiler", 598 GNUNET_CONFIGURATION_get_value_yesno (testing_cfg, "nse-profiler",
611 "skew_clock")) 599 "skew_clock"))
612 { 600 {
613 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Setting our clock as skewed...\n"); 601 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Setting our clock as skewed...\n");
614 clock_skew = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 602 clock_skew =
615 GNUNET_TIME_UNIT_MINUTES.rel_value); 603 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
604 GNUNET_TIME_UNIT_MINUTES.rel_value);
616 } 605 }
617 606
618 607
619 data_file = GNUNET_DISK_file_open (data_filename, 608 data_file =
620 GNUNET_DISK_OPEN_READWRITE 609 GNUNET_DISK_file_open (data_filename,
621 | GNUNET_DISK_OPEN_CREATE, 610 GNUNET_DISK_OPEN_READWRITE |
622 GNUNET_DISK_PERM_USER_READ | 611 GNUNET_DISK_OPEN_CREATE,
623 GNUNET_DISK_PERM_USER_WRITE); 612 GNUNET_DISK_PERM_USER_READ |
613 GNUNET_DISK_PERM_USER_WRITE);
624 if (data_file == NULL) 614 if (data_file == NULL)
625 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 615 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
626 "Failed to open %s for output!\n", data_filename); 616 data_filename);
627 GNUNET_free (data_filename); 617 GNUNET_free (data_filename);
628 618
629 wait_time = 619 wait_time =
630 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_wait); 620 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_wait);
631 621
632 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg, 622 if (GNUNET_YES ==
633 "nse-profiler", 623 GNUNET_CONFIGURATION_get_value_string (cfg, "nse-profiler", "output_file",
634 "output_file", 624 &temp_str))
635 &temp_str))
636 { 625 {
637 output_file = GNUNET_DISK_file_open (temp_str, GNUNET_DISK_OPEN_READWRITE 626 output_file =
638 | GNUNET_DISK_OPEN_CREATE, 627 GNUNET_DISK_file_open (temp_str,
639 GNUNET_DISK_PERM_USER_READ | 628 GNUNET_DISK_OPEN_READWRITE |
640 GNUNET_DISK_PERM_USER_WRITE); 629 GNUNET_DISK_OPEN_CREATE,
630 GNUNET_DISK_PERM_USER_READ |
631 GNUNET_DISK_PERM_USER_WRITE);
641 if (output_file == NULL) 632 if (output_file == NULL)
642 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 633 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
643 "Failed to open %s for output!\n", temp_str); 634 temp_str);
644 } 635 }
645 GNUNET_free_non_null (temp_str); 636 GNUNET_free_non_null (temp_str);
646 637
647 hosts = GNUNET_TESTING_hosts_load (testing_cfg); 638 hosts = GNUNET_TESTING_hosts_load (testing_cfg);
648 639
649 pg = GNUNET_TESTING_peergroup_start (testing_cfg, 640 pg = GNUNET_TESTING_peergroup_start (testing_cfg, num_peers, TIMEOUT,
650 num_peers,
651 TIMEOUT,
652 &connect_cb, &my_cb, NULL, hosts); 641 &connect_cb, &my_cb, NULL, hosts);
653 GNUNET_assert (pg != NULL); 642 GNUNET_assert (pg != NULL);
654 shutdown_handle = 643 shutdown_handle =
@@ -679,8 +668,7 @@ main (int argc, char *argv[])
679 "WARNING", 668 "WARNING",
680#endif 669#endif
681 NULL); 670 NULL);
682 GNUNET_PROGRAM_run (argc, 671 GNUNET_PROGRAM_run (argc, argv, "nse-profiler",
683 argv, "nse-profiler",
684 gettext_noop 672 gettext_noop
685 ("Measure quality and performance of the NSE service."), 673 ("Measure quality and performance of the NSE service."),
686 options, &run, NULL); 674 options, &run, NULL);
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c
index 9da9abba2..5f880088f 100644
--- a/src/nse/gnunet-service-nse.c
+++ b/src/nse/gnunet-service-nse.c
@@ -315,8 +315,10 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em)
315 sumweight = 0.0; 315 sumweight = 0.0;
316 for (i = 0; i < estimate_count; i++) 316 for (i = 0; i < estimate_count; i++)
317 { 317 {
318 val = htonl (size_estimate_messages[(estimate_index - i + HISTORY_SIZE) 318 val =
319 % HISTORY_SIZE].matching_bits); 319 htonl (size_estimate_messages
320 [(estimate_index - i +
321 HISTORY_SIZE) % HISTORY_SIZE].matching_bits);
320 weight = 1; /* was: estimate_count + 1 - i; */ 322 weight = 1; /* was: estimate_count + 1 - i; */
321 323
322 temp = weight + sumweight; 324 temp = weight + sumweight;
@@ -338,8 +340,7 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em)
338 em->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); 340 em->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
339 em->size_estimate = mean - 1.0 / 3.0; 341 em->size_estimate = mean - 1.0 / 3.0;
340 em->std_deviation = std_dev; 342 em->std_deviation = std_dev;
341 GNUNET_STATISTICS_set (stats, 343 GNUNET_STATISTICS_set (stats, "# nodes in the network (estimate)",
342 "# nodes in the network (estimate)",
343 (uint64_t) pow (2, mean - 1.0 / 3.0), GNUNET_NO); 344 (uint64_t) pow (2, mean - 1.0 / 3.0), GNUNET_NO);
344} 345}
345 346
@@ -385,8 +386,7 @@ get_matching_bits_delay (uint32_t matching_bits)
385 // f is frequency (gnunet_nse_interval) 386 // f is frequency (gnunet_nse_interval)
386 // x is matching_bits 387 // x is matching_bits
387 // p' is current_size_estimate 388 // p' is current_size_estimate
388 return ((double) gnunet_nse_interval.rel_value / (double) 2.0) 389 return ((double) gnunet_nse_interval.rel_value / (double) 2.0) -
389 -
390 ((gnunet_nse_interval.rel_value / M_PI) * 390 ((gnunet_nse_interval.rel_value / M_PI) *
391 atan (matching_bits - current_size_estimate)); 391 atan (matching_bits - current_size_estimate));
392} 392}
@@ -406,12 +406,12 @@ get_delay_randomization (uint32_t matching_bits)
406 406
407 if (matching_bits == 0) 407 if (matching_bits == 0)
408 return GNUNET_TIME_UNIT_ZERO; 408 return GNUNET_TIME_UNIT_ZERO;
409 ret.rel_value = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 409 ret.rel_value =
410 (uint32_t) (get_matching_bits_delay 410 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
411 (matching_bits - 411 (uint32_t) (get_matching_bits_delay
412 1) / 412 (matching_bits -
413 (double) (hop_count_max 413 1) / (double) (hop_count_max +
414 + 1))); 414 1)));
415 return ret; 415 return ret;
416#else 416#else
417 return GNUNET_TIME_UNIT_ZERO; 417 return GNUNET_TIME_UNIT_ZERO;
@@ -432,8 +432,8 @@ get_matching_bits (struct GNUNET_TIME_Absolute timestamp,
432{ 432{
433 GNUNET_HashCode timestamp_hash; 433 GNUNET_HashCode timestamp_hash;
434 434
435 GNUNET_CRYPTO_hash (&timestamp.abs_value, 435 GNUNET_CRYPTO_hash (&timestamp.abs_value, sizeof (timestamp.abs_value),
436 sizeof (timestamp.abs_value), &timestamp_hash); 436 &timestamp_hash);
437 return GNUNET_CRYPTO_hash_matching_bits (&timestamp_hash, &id->hashPubKey); 437 return GNUNET_CRYPTO_hash_matching_bits (&timestamp_hash, &id->hashPubKey);
438} 438}
439 439
@@ -498,8 +498,8 @@ get_transmit_delay (int round_offset)
498 * @param cls the 'struct NSEPeerEntry' 498 * @param cls the 'struct NSEPeerEntry'
499 * @param tc scheduler context 499 * @param tc scheduler context
500 */ 500 */
501static void 501static void transmit_task (void *cls,
502transmit_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 502 const struct GNUNET_SCHEDULER_TaskContext *tc);
503 503
504 504
505/** 505/**
@@ -545,17 +545,15 @@ transmit_ready (void *cls, size_t size, void *buf)
545 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 545 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
546 "In round %llu, sending to `%s' estimate with %u bits\n", 546 "In round %llu, sending to `%s' estimate with %u bits\n",
547 (unsigned long long) 547 (unsigned long long)
548 GNUNET_TIME_absolute_ntoh (size_estimate_messages[idx]. 548 GNUNET_TIME_absolute_ntoh (size_estimate_messages[idx].timestamp).
549 timestamp).abs_value, 549 abs_value, GNUNET_i2s (&peer_entry->id),
550 GNUNET_i2s (&peer_entry->id),
551 (unsigned int) ntohl (size_estimate_messages[idx].matching_bits)); 550 (unsigned int) ntohl (size_estimate_messages[idx].matching_bits));
552#endif 551#endif
553 if (ntohl (size_estimate_messages[idx].hop_count) == 0) 552 if (ntohl (size_estimate_messages[idx].hop_count) == 0)
554 GNUNET_STATISTICS_update (stats, "# flood messages started", 1, GNUNET_NO); 553 GNUNET_STATISTICS_update (stats, "# flood messages started", 1, GNUNET_NO);
555 GNUNET_STATISTICS_update (stats, 554 GNUNET_STATISTICS_update (stats, "# flood messages transmitted", 1,
556 "# flood messages transmitted", 1, GNUNET_NO); 555 GNUNET_NO);
557 memcpy (buf, 556 memcpy (buf, &size_estimate_messages[idx],
558 &size_estimate_messages[idx],
559 sizeof (struct GNUNET_NSE_FloodMessage)); 557 sizeof (struct GNUNET_NSE_FloodMessage));
560 GNUNET_STATISTICS_update (stats, "# flood messages sent", 1, GNUNET_NO); 558 GNUNET_STATISTICS_update (stats, "# flood messages sent", 1, GNUNET_NO);
561 return sizeof (struct GNUNET_NSE_FloodMessage); 559 return sizeof (struct GNUNET_NSE_FloodMessage);
@@ -575,15 +573,13 @@ transmit_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
575 573
576 peer_entry->transmit_task = GNUNET_SCHEDULER_NO_TASK; 574 peer_entry->transmit_task = GNUNET_SCHEDULER_NO_TASK;
577 GNUNET_assert (NULL == peer_entry->th); 575 GNUNET_assert (NULL == peer_entry->th);
578 peer_entry->th 576 peer_entry->th =
579 = GNUNET_CORE_notify_transmit_ready (coreAPI, 577 GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_NO, NSE_PRIORITY,
580 GNUNET_NO, 578 GNUNET_TIME_UNIT_FOREVER_REL,
581 NSE_PRIORITY, 579 &peer_entry->id,
582 GNUNET_TIME_UNIT_FOREVER_REL, 580 sizeof (struct
583 &peer_entry->id, 581 GNUNET_NSE_FloodMessage),
584 sizeof (struct 582 &transmit_ready, peer_entry);
585 GNUNET_NSE_FloodMessage),
586 &transmit_ready, peer_entry);
587} 583}
588 584
589 585
@@ -622,10 +618,10 @@ setup_flood_message (unsigned int slot, struct GNUNET_TIME_Absolute ts)
622 fm->header.type = htons (GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD); 618 fm->header.type = htons (GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD);
623 fm->hop_count = htonl (0); 619 fm->hop_count = htonl (0);
624 fm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_NSE_SEND); 620 fm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_NSE_SEND);
625 fm->purpose.size = htonl (sizeof (struct GNUNET_NSE_FloodMessage) 621 fm->purpose.size =
626 - sizeof (struct GNUNET_MessageHeader) 622 htonl (sizeof (struct GNUNET_NSE_FloodMessage) -
627 - sizeof (uint32_t) 623 sizeof (struct GNUNET_MessageHeader) - sizeof (uint32_t) -
628 - sizeof (struct GNUNET_CRYPTO_RsaSignature)); 624 sizeof (struct GNUNET_CRYPTO_RsaSignature));
629 fm->matching_bits = htonl (matching_bits); 625 fm->matching_bits = htonl (matching_bits);
630 fm->timestamp = GNUNET_TIME_absolute_hton (ts); 626 fm->timestamp = GNUNET_TIME_absolute_hton (ts);
631 fm->pkey = my_public_key; 627 fm->pkey = my_public_key;
@@ -684,13 +680,13 @@ update_flood_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
684 if (0 != offset.rel_value) 680 if (0 != offset.rel_value)
685 { 681 {
686 /* somehow run early, delay more */ 682 /* somehow run early, delay more */
687 flood_task 683 flood_task =
688 = GNUNET_SCHEDULER_add_delayed (offset, &update_flood_message, NULL); 684 GNUNET_SCHEDULER_add_delayed (offset, &update_flood_message, NULL);
689 return; 685 return;
690 } 686 }
691 current_timestamp = next_timestamp; 687 current_timestamp = next_timestamp;
692 next_timestamp = GNUNET_TIME_absolute_add (current_timestamp, 688 next_timestamp =
693 gnunet_nse_interval); 689 GNUNET_TIME_absolute_add (current_timestamp, gnunet_nse_interval);
694 estimate_index = (estimate_index + 1) % HISTORY_SIZE; 690 estimate_index = (estimate_index + 1) % HISTORY_SIZE;
695 if (estimate_count < HISTORY_SIZE) 691 if (estimate_count < HISTORY_SIZE)
696 estimate_count++; 692 estimate_count++;
@@ -699,16 +695,16 @@ update_flood_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
699 { 695 {
700 /* we received a message for this round way early, use it! */ 696 /* we received a message for this round way early, use it! */
701 size_estimate_messages[estimate_index] = next_message; 697 size_estimate_messages[estimate_index] = next_message;
702 size_estimate_messages[estimate_index].hop_count 698 size_estimate_messages[estimate_index].hop_count =
703 = htonl (1 + ntohl (next_message.hop_count)); 699 htonl (1 + ntohl (next_message.hop_count));
704 } 700 }
705 else 701 else
706 setup_flood_message (estimate_index, current_timestamp); 702 setup_flood_message (estimate_index, current_timestamp);
707 next_message.matching_bits = htonl (0); /* reset for 'next' round */ 703 next_message.matching_bits = htonl (0); /* reset for 'next' round */
708 hop_count_max = 0; 704 hop_count_max = 0;
709 for (i = 0; i < HISTORY_SIZE; i++) 705 for (i = 0; i < HISTORY_SIZE; i++)
710 hop_count_max = GNUNET_MAX (ntohl (size_estimate_messages[i].hop_count), 706 hop_count_max =
711 hop_count_max); 707 GNUNET_MAX (ntohl (size_estimate_messages[i].hop_count), hop_count_max);
712 GNUNET_CONTAINER_multihashmap_iterate (peers, &schedule_current_round, NULL); 708 GNUNET_CONTAINER_multihashmap_iterate (peers, &schedule_current_round, NULL);
713 flood_task = 709 flood_task =
714 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining 710 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
@@ -753,8 +749,8 @@ check_proof_of_work (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey,
753 GNUNET_HashCode result; 749 GNUNET_HashCode result;
754 750
755 memcpy (buf, &val, sizeof (val)); 751 memcpy (buf, &val, sizeof (val));
756 memcpy (&buf[sizeof (val)], 752 memcpy (&buf[sizeof (val)], pkey,
757 pkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 753 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
758 GNUNET_CRYPTO_hash (buf, sizeof (buf), &result); 754 GNUNET_CRYPTO_hash (buf, sizeof (buf), &result);
759 return (count_leading_zeroes (&result) >= 755 return (count_leading_zeroes (&result) >=
760 nse_work_required) ? GNUNET_YES : GNUNET_NO; 756 nse_work_required) ? GNUNET_YES : GNUNET_NO;
@@ -773,9 +769,7 @@ write_proof ()
773 GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE", &proof)) 769 GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE", &proof))
774 return; 770 return;
775 if (sizeof (my_proof) != 771 if (sizeof (my_proof) !=
776 GNUNET_DISK_fn_write (proof, 772 GNUNET_DISK_fn_write (proof, &my_proof, sizeof (my_proof),
777 &my_proof,
778 sizeof (my_proof),
779 GNUNET_DISK_PERM_USER_READ | 773 GNUNET_DISK_PERM_USER_READ |
780 GNUNET_DISK_PERM_USER_WRITE)) 774 GNUNET_DISK_PERM_USER_WRITE))
781 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", proof); 775 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", proof);
@@ -801,8 +795,7 @@ find_proof (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
801 unsigned int i; 795 unsigned int i;
802 796
803 proof_task = GNUNET_SCHEDULER_NO_TASK; 797 proof_task = GNUNET_SCHEDULER_NO_TASK;
804 memcpy (&buf[sizeof (uint64_t)], 798 memcpy (&buf[sizeof (uint64_t)], &my_public_key,
805 &my_public_key,
806 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 799 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
807 i = 0; 800 i = 0;
808 counter = my_proof; 801 counter = my_proof;
@@ -814,8 +807,7 @@ find_proof (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
814 { 807 {
815 my_proof = counter; 808 my_proof = counter;
816#if DEBUG_NSE 809#if DEBUG_NSE
817 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 810 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Proof of work found: %llu!\n",
818 "Proof of work found: %llu!\n",
819 (unsigned long long) GNUNET_ntohll (counter)); 811 (unsigned long long) GNUNET_ntohll (counter));
820#endif 812#endif
821 for (i = 0; i < HISTORY_SIZE; i++) 813 for (i = 0; i < HISTORY_SIZE; i++)
@@ -835,8 +827,7 @@ find_proof (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
835 if (my_proof / (100 * ROUND_SIZE) < counter / (100 * ROUND_SIZE)) 827 if (my_proof / (100 * ROUND_SIZE) < counter / (100 * ROUND_SIZE))
836 { 828 {
837#if DEBUG_NSE 829#if DEBUG_NSE
838 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 830 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing proofs currently at %llu\n",
839 "Testing proofs currently at %llu\n",
840 (unsigned long long) counter); 831 (unsigned long long) counter);
841#endif 832#endif
842 /* remember progress every 100 rounds */ 833 /* remember progress every 100 rounds */
@@ -847,8 +838,8 @@ find_proof (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
847 { 838 {
848 my_proof = counter; 839 my_proof = counter;
849 } 840 }
850 proof_task = GNUNET_SCHEDULER_add_delayed (proof_find_delay, 841 proof_task =
851 &find_proof, NULL); 842 GNUNET_SCHEDULER_add_delayed (proof_find_delay, &find_proof, NULL);
852} 843}
853 844
854 845
@@ -869,10 +860,9 @@ verify_message_crypto (const struct GNUNET_NSE_FloodMessage *incoming_flood)
869 check_proof_of_work (&incoming_flood->pkey, 860 check_proof_of_work (&incoming_flood->pkey,
870 incoming_flood->proof_of_work)) 861 incoming_flood->proof_of_work))
871 { 862 {
872 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 863 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Proof of work invalid: %llu!\n"),
873 _("Proof of work invalid: %llu!\n"), 864 (unsigned long long) GNUNET_ntohll (incoming_flood->
874 (unsigned long long) 865 proof_of_work));
875 GNUNET_ntohll (incoming_flood->proof_of_work));
876 GNUNET_break_op (0); 866 GNUNET_break_op (0);
877 return GNUNET_NO; 867 return GNUNET_NO;
878 } 868 }
@@ -923,9 +913,8 @@ update_flood_times (void *cls, const GNUNET_HashCode * key, void *value)
923 peer_entry->transmit_task = GNUNET_SCHEDULER_NO_TASK; 913 peer_entry->transmit_task = GNUNET_SCHEDULER_NO_TASK;
924 } 914 }
925 delay = get_transmit_delay (0); 915 delay = get_transmit_delay (0);
926 peer_entry->transmit_task = GNUNET_SCHEDULER_add_delayed (delay, 916 peer_entry->transmit_task =
927 &transmit_task, 917 GNUNET_SCHEDULER_add_delayed (delay, &transmit_task, peer_entry);
928 peer_entry);
929 return GNUNET_OK; 918 return GNUNET_OK;
930} 919}
931 920
@@ -940,8 +929,7 @@ update_flood_times (void *cls, const GNUNET_HashCode * key, void *value)
940 * 929 *
941 */ 930 */
942static int 931static int
943handle_p2p_size_estimate (void *cls, 932handle_p2p_size_estimate (void *cls, const struct GNUNET_PeerIdentity *peer,
944 const struct GNUNET_PeerIdentity *peer,
945 const struct GNUNET_MessageHeader *message, 933 const struct GNUNET_MessageHeader *message,
946 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 934 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
947{ 935{
@@ -971,9 +959,9 @@ handle_p2p_size_estimate (void *cls,
971 GNUNET_snprintf (pred, sizeof (pred), "%s", GNUNET_i2s (peer)); 959 GNUNET_snprintf (pred, sizeof (pred), "%s", GNUNET_i2s (peer));
972 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 960 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
973 "Flood at %llu from `%s' via `%s' at `%s' with bits %u\n", 961 "Flood at %llu from `%s' via `%s' at `%s' with bits %u\n",
974 (unsigned long long) 962 (unsigned long long) GNUNET_TIME_absolute_ntoh (incoming_flood->
975 GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp).abs_value, 963 timestamp).
976 origin, pred, GNUNET_i2s (&my_identity), 964 abs_value, origin, pred, GNUNET_i2s (&my_identity),
977 (unsigned int) matching_bits); 965 (unsigned int) matching_bits);
978 } 966 }
979#endif 967#endif
@@ -1015,8 +1003,8 @@ handle_p2p_size_estimate (void *cls,
1015 if (0 == (memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity)))) 1003 if (0 == (memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity))))
1016 { 1004 {
1017 /* send to self, update our own estimate IF this also comes from us! */ 1005 /* send to self, update our own estimate IF this also comes from us! */
1018 if (0 == memcmp (&incoming_flood->pkey, 1006 if (0 ==
1019 &my_public_key, sizeof (my_public_key))) 1007 memcmp (&incoming_flood->pkey, &my_public_key, sizeof (my_public_key)))
1020 update_network_size_estimate (); 1008 update_network_size_estimate ();
1021 return GNUNET_OK; 1009 return GNUNET_OK;
1022 } 1010 }
@@ -1057,8 +1045,8 @@ handle_p2p_size_estimate (void *cls,
1057 { 1045 {
1058 if (peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK) 1046 if (peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK)
1059 GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); 1047 GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
1060 peer_entry->transmit_task = GNUNET_SCHEDULER_add_now (&transmit_task, 1048 peer_entry->transmit_task =
1061 peer_entry); 1049 GNUNET_SCHEDULER_add_now (&transmit_task, peer_entry);
1062 } 1050 }
1063 /* Not closer than our most recent message, no need to do work here */ 1051 /* Not closer than our most recent message, no need to do work here */
1064 GNUNET_STATISTICS_update (stats, 1052 GNUNET_STATISTICS_update (stats,
@@ -1081,8 +1069,8 @@ handle_p2p_size_estimate (void *cls,
1081 update_network_size_estimate (); 1069 update_network_size_estimate ();
1082 1070
1083 /* flood to rest */ 1071 /* flood to rest */
1084 GNUNET_CONTAINER_multihashmap_iterate (peers, 1072 GNUNET_CONTAINER_multihashmap_iterate (peers, &update_flood_times,
1085 &update_flood_times, peer_entry); 1073 peer_entry);
1086 return GNUNET_OK; 1074 return GNUNET_OK;
1087} 1075}
1088 1076
@@ -1102,14 +1090,12 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
1102 struct NSEPeerEntry *peer_entry; 1090 struct NSEPeerEntry *peer_entry;
1103 1091
1104#if DEBUG_NSE 1092#if DEBUG_NSE
1105 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1093 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' connected to us\n",
1106 "Peer `%s' connected to us\n", GNUNET_i2s (peer)); 1094 GNUNET_i2s (peer));
1107#endif 1095#endif
1108 peer_entry = GNUNET_malloc (sizeof (struct NSEPeerEntry)); 1096 peer_entry = GNUNET_malloc (sizeof (struct NSEPeerEntry));
1109 peer_entry->id = *peer; 1097 peer_entry->id = *peer;
1110 GNUNET_CONTAINER_multihashmap_put (peers, 1098 GNUNET_CONTAINER_multihashmap_put (peers, &peer->hashPubKey, peer_entry,
1111 &peer->hashPubKey,
1112 peer_entry,
1113 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 1099 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1114 peer_entry->transmit_task = 1100 peer_entry->transmit_task =
1115 GNUNET_SCHEDULER_add_delayed (get_transmit_delay (-1), &transmit_task, 1101 GNUNET_SCHEDULER_add_delayed (get_transmit_delay (-1), &transmit_task,
@@ -1129,8 +1115,8 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
1129 struct NSEPeerEntry *pos; 1115 struct NSEPeerEntry *pos;
1130 1116
1131#if DEBUG_NSE 1117#if DEBUG_NSE
1132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' disconnected from us\n",
1133 "Peer `%s' disconnected from us\n", GNUNET_i2s (peer)); 1119 GNUNET_i2s (peer));
1134#endif 1120#endif
1135 pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); 1121 pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
1136 if (NULL == pos) 1122 if (NULL == pos)
@@ -1139,8 +1125,8 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
1139 return; 1125 return;
1140 } 1126 }
1141 GNUNET_assert (GNUNET_YES == 1127 GNUNET_assert (GNUNET_YES ==
1142 GNUNET_CONTAINER_multihashmap_remove (peers, 1128 GNUNET_CONTAINER_multihashmap_remove (peers, &peer->hashPubKey,
1143 &peer->hashPubKey, pos)); 1129 pos));
1144 if (pos->transmit_task != GNUNET_SCHEDULER_NO_TASK) 1130 if (pos->transmit_task != GNUNET_SCHEDULER_NO_TASK)
1145 GNUNET_SCHEDULER_cancel (pos->transmit_task); 1131 GNUNET_SCHEDULER_cancel (pos->transmit_task);
1146 if (pos->th != NULL) 1132 if (pos->th != NULL)
@@ -1251,8 +1237,7 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server,
1251 } 1237 }
1252 estimate_index = HISTORY_SIZE - 1; 1238 estimate_index = HISTORY_SIZE - 1;
1253 estimate_count = 2; 1239 estimate_count = 2;
1254 flood_task 1240 flood_task =
1255 =
1256 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining 1241 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
1257 (next_timestamp), &update_flood_message, 1242 (next_timestamp), &update_flood_message,
1258 NULL); 1243 NULL);
@@ -1286,16 +1271,13 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1286 cfg = c; 1271 cfg = c;
1287 1272
1288 if ((GNUNET_OK != 1273 if ((GNUNET_OK !=
1289 GNUNET_CONFIGURATION_get_value_time (cfg, 1274 GNUNET_CONFIGURATION_get_value_time (cfg, "NSE", "INTERVAL",
1290 "NSE", "INTERVAL",
1291 &gnunet_nse_interval)) || 1275 &gnunet_nse_interval)) ||
1292 (GNUNET_OK != 1276 (GNUNET_OK !=
1293 GNUNET_CONFIGURATION_get_value_time (cfg, 1277 GNUNET_CONFIGURATION_get_value_time (cfg, "NSE", "WORKDELAY",
1294 "NSE", "WORKDELAY",
1295 &proof_find_delay)) || 1278 &proof_find_delay)) ||
1296 (GNUNET_OK != 1279 (GNUNET_OK !=
1297 GNUNET_CONFIGURATION_get_value_number (cfg, 1280 GNUNET_CONFIGURATION_get_value_number (cfg, "NSE", "WORKBITS",
1298 "NSE", "WORKBITS",
1299 &nse_work_required))) 1281 &nse_work_required)))
1300 { 1282 {
1301 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1283 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -1314,8 +1296,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1314 1296
1315 1297
1316 if (GNUNET_OK != 1298 if (GNUNET_OK !=
1317 GNUNET_CONFIGURATION_get_value_filename (cfg, 1299 GNUNET_CONFIGURATION_get_value_filename (cfg, "GNUNETD", "HOSTKEY",
1318 "GNUNETD", "HOSTKEY", &keyfile)) 1300 &keyfile))
1319 { 1301 {
1320 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1302 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1321 _ 1303 _
@@ -1374,8 +1356,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1374 NULL, /* Don't want notified about all outbound messages */ 1356 NULL, /* Don't want notified about all outbound messages */
1375 GNUNET_NO, /* For header only outbound notification */ 1357 GNUNET_NO, /* For header only outbound notification */
1376 core_handlers); /* Register these handlers */ 1358 core_handlers); /* Register these handlers */
1377 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 1359 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
1378 &shutdown_task, NULL); 1360 NULL);
1379#if ENABLE_HISTOGRAM 1361#if ENABLE_HISTOGRAM
1380 if (GNUNET_OK == 1362 if (GNUNET_OK ==
1381 GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "HISTOGRAM", &proof)) 1363 GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "HISTOGRAM", &proof))
@@ -1403,10 +1385,9 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1403int 1385int
1404main (int argc, char *const *argv) 1386main (int argc, char *const *argv)
1405{ 1387{
1406 return (GNUNET_OK == GNUNET_SERVICE_run (argc, argv, 1388 return (GNUNET_OK ==
1407 "nse", 1389 GNUNET_SERVICE_run (argc, argv, "nse", GNUNET_SERVICE_OPTION_NONE,
1408 GNUNET_SERVICE_OPTION_NONE, &run, 1390 &run, NULL)) ? 0 : 1;
1409 NULL)) ? 0 : 1;
1410} 1391}
1411 1392
1412/* end of gnunet-service-nse.c */ 1393/* end of gnunet-service-nse.c */
diff --git a/src/nse/nse_api.c b/src/nse/nse_api.c
index 62c58ca77..8ff0256b9 100644
--- a/src/nse/nse_api.c
+++ b/src/nse/nse_api.c
@@ -85,8 +85,8 @@ struct GNUNET_NSE_Handle
85 * @param cls the handle to the transport service 85 * @param cls the handle to the transport service
86 * @param tc scheduler context 86 * @param tc scheduler context
87 */ 87 */
88static void 88static void reconnect (void *cls,
89reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 89 const struct GNUNET_SCHEDULER_TaskContext *tc);
90 90
91 91
92/** 92/**
@@ -107,8 +107,8 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
107 /* Error, timeout, death */ 107 /* Error, timeout, death */
108 GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); 108 GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
109 h->client = NULL; 109 h->client = NULL;
110 h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, 110 h->reconnect_task =
111 &reconnect, h); 111 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
112 return; 112 return;
113 } 113 }
114 if ((ntohs (msg->size) != sizeof (struct GNUNET_NSE_ClientMessage)) || 114 if ((ntohs (msg->size) != sizeof (struct GNUNET_NSE_ClientMessage)) ||
@@ -118,11 +118,10 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
118 return; 118 return;
119 } 119 }
120 client_msg = (const struct GNUNET_NSE_ClientMessage *) msg; 120 client_msg = (const struct GNUNET_NSE_ClientMessage *) msg;
121 h->recv_cb (h->recv_cb_cls, 121 h->recv_cb (h->recv_cb_cls, GNUNET_TIME_absolute_ntoh (client_msg->timestamp),
122 GNUNET_TIME_absolute_ntoh (client_msg->timestamp),
123 client_msg->size_estimate, client_msg->std_deviation); 122 client_msg->size_estimate, client_msg->std_deviation);
124 GNUNET_CLIENT_receive (h->client, 123 GNUNET_CLIENT_receive (h->client, &message_handler, h,
125 &message_handler, h, GNUNET_TIME_UNIT_FOREVER_REL); 124 GNUNET_TIME_UNIT_FOREVER_REL);
126} 125}
127 126
128 127
@@ -153,8 +152,8 @@ reschedule_connect (struct GNUNET_NSE_Handle *h)
153 "Scheduling task to reconnect to nse service in %llu ms.\n", 152 "Scheduling task to reconnect to nse service in %llu ms.\n",
154 h->reconnect_delay.rel_value); 153 h->reconnect_delay.rel_value);
155#endif 154#endif
156 h->reconnect_task 155 h->reconnect_task =
157 = GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); 156 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
158 if (h->reconnect_delay.rel_value == 0) 157 if (h->reconnect_delay.rel_value == 0)
159 { 158 {
160 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS; 159 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
@@ -162,8 +161,8 @@ reschedule_connect (struct GNUNET_NSE_Handle *h)
162 else 161 else
163 { 162 {
164 h->reconnect_delay = GNUNET_TIME_relative_multiply (h->reconnect_delay, 2); 163 h->reconnect_delay = GNUNET_TIME_relative_multiply (h->reconnect_delay, 2);
165 h->reconnect_delay = GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, 164 h->reconnect_delay =
166 h->reconnect_delay); 165 GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, h->reconnect_delay);
167 } 166 }
168} 167}
169 168
@@ -201,8 +200,8 @@ send_start (void *cls, size_t size, void *buf)
201 msg = (struct GNUNET_MessageHeader *) buf; 200 msg = (struct GNUNET_MessageHeader *) buf;
202 msg->size = htons (sizeof (struct GNUNET_MessageHeader)); 201 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
203 msg->type = htons (GNUNET_MESSAGE_TYPE_NSE_START); 202 msg->type = htons (GNUNET_MESSAGE_TYPE_NSE_START);
204 GNUNET_CLIENT_receive (h->client, 203 GNUNET_CLIENT_receive (h->client, &message_handler, h,
205 &message_handler, h, GNUNET_TIME_UNIT_FOREVER_REL); 204 GNUNET_TIME_UNIT_FOREVER_REL);
206 return sizeof (struct GNUNET_MessageHeader); 205 return sizeof (struct GNUNET_MessageHeader);
207} 206}
208 207
diff --git a/src/nse/test_nse_api.c b/src/nse/test_nse_api.c
index c06b2be8b..e4d2ba409 100644
--- a/src/nse/test_nse_api.c
+++ b/src/nse/test_nse_api.c
@@ -88,8 +88,7 @@ end_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
88 * 88 *
89 */ 89 */
90static void 90static void
91check_nse_message (void *cls, 91check_nse_message (void *cls, struct GNUNET_TIME_Absolute timestamp,
92 struct GNUNET_TIME_Absolute timestamp,
93 double estimate, double std_dev) 92 double estimate, double std_dev)
94{ 93{
95 int *ok = cls; 94 int *ok = cls;
@@ -110,13 +109,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
110{ 109{
111 p->cfg = GNUNET_CONFIGURATION_create (); 110 p->cfg = GNUNET_CONFIGURATION_create ();
112#if START_ARM 111#if START_ARM
113 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, 112 p->arm_proc =
114 "gnunet-service-arm", 113 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
115 "gnunet-service-arm", 114 "gnunet-service-arm",
116#if VERBOSE_ARM 115#if VERBOSE_ARM
117 "-L", "DEBUG", 116 "-L", "DEBUG",
118#endif 117#endif
119 "-c", cfgname, NULL); 118 "-c", cfgname, NULL);
120#endif 119#endif
121 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 120 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
122 121
@@ -125,13 +124,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
125 124
126 125
127static void 126static void
128run (void *cls, 127run (void *cls, char *const *args, const char *cfgfile,
129 char *const *args, 128 const struct GNUNET_CONFIGURATION_Handle *cfg)
130 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
131{ 129{
132 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 130 die_task =
133 (GNUNET_TIME_UNIT_MINUTES, 1), 131 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
134 &end_test, NULL); 132 (GNUNET_TIME_UNIT_MINUTES, 1), &end_test,
133 NULL);
135 134
136 setup_peer (&p1, cfgfile); 135 setup_peer (&p1, cfgfile);
137 h = GNUNET_NSE_connect (cfg, &check_nse_message, cls); 136 h = GNUNET_NSE_connect (cfg, &check_nse_message, cls);
diff --git a/src/nse/test_nse_multipeer.c b/src/nse/test_nse_multipeer.c
index 29e5cd6cc..1db00415f 100644
--- a/src/nse/test_nse_multipeer.c
+++ b/src/nse/test_nse_multipeer.c
@@ -72,8 +72,8 @@ shutdown_callback (void *cls, const char *emsg)
72 if (emsg != NULL) 72 if (emsg != NULL)
73 { 73 {
74#if VERBOSE 74#if VERBOSE
75 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 75 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed: %s!\n",
76 "Shutdown of peers failed: %s!\n", emsg); 76 emsg);
77#endif 77#endif
78 if (ok == 0) 78 if (ok == 0)
79 ok = 666; 79 ok = 666;
@@ -117,17 +117,15 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
117 * 117 *
118 */ 118 */
119static void 119static void
120handle_estimate (void *cls, 120handle_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp,
121 struct GNUNET_TIME_Absolute timestamp,
122 double estimate, double std_dev) 121 double estimate, double std_dev)
123{ 122{
124 struct NSEPeer *peer = cls; 123 struct NSEPeer *peer = cls;
125 124
126 fprintf (stderr, 125 fprintf (stderr,
127 "Received network size estimate from peer %s. logSize: %f std.dev. %f (%f/%u)\n", 126 "Received network size estimate from peer %s. logSize: %f std.dev. %f (%f/%u)\n",
128 GNUNET_i2s (&peer->daemon->id), 127 GNUNET_i2s (&peer->daemon->id), estimate, std_dev,
129 estimate, 128 GNUNET_NSE_log_estimate_to_n (estimate), num_peers);
130 std_dev, GNUNET_NSE_log_estimate_to_n (estimate), num_peers);
131} 129}
132 130
133 131
@@ -144,9 +142,9 @@ connect_nse_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
144 { 142 {
145 current_peer = GNUNET_malloc (sizeof (struct NSEPeer)); 143 current_peer = GNUNET_malloc (sizeof (struct NSEPeer));
146 current_peer->daemon = GNUNET_TESTING_daemon_get (pg, i); 144 current_peer->daemon = GNUNET_TESTING_daemon_get (pg, i);
147 current_peer->nse_handle = GNUNET_NSE_connect (current_peer->daemon->cfg, 145 current_peer->nse_handle =
148 &handle_estimate, 146 GNUNET_NSE_connect (current_peer->daemon->cfg, &handle_estimate,
149 current_peer); 147 current_peer);
150 GNUNET_assert (current_peer->nse_handle != NULL); 148 GNUNET_assert (current_peer->nse_handle != NULL);
151 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer); 149 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer);
152 } 150 }
@@ -169,8 +167,8 @@ my_cb (void *cls, const char *emsg)
169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 167 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
170 "Peer Group started successfully, connecting to NSE service for each peer!\n"); 168 "Peer Group started successfully, connecting to NSE service for each peer!\n");
171#endif 169#endif
172 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 170 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Have %u connections\n",
173 "Have %u connections\n", total_connections); 171 total_connections);
174 172
175 GNUNET_SCHEDULER_add_now (&connect_nse_service, NULL); 173 GNUNET_SCHEDULER_add_now (&connect_nse_service, NULL);
176} 174}
@@ -191,10 +189,8 @@ my_cb (void *cls, const char *emsg)
191 * @param emsg error message (NULL on success) 189 * @param emsg error message (NULL on success)
192 */ 190 */
193static void 191static void
194connect_cb (void *cls, 192connect_cb (void *cls, const struct GNUNET_PeerIdentity *first,
195 const struct GNUNET_PeerIdentity *first, 193 const struct GNUNET_PeerIdentity *second, uint32_t distance,
196 const struct GNUNET_PeerIdentity *second,
197 uint32_t distance,
198 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 194 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
199 const struct GNUNET_CONFIGURATION_Handle *second_cfg, 195 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
200 struct GNUNET_TESTING_Daemon *first_daemon, 196 struct GNUNET_TESTING_Daemon *first_daemon,
@@ -210,9 +206,8 @@ connect_cb (void *cls,
210 206
211 207
212static void 208static void
213run (void *cls, 209run (void *cls, char *const *args, const char *cfgfile,
214 char *const *args, 210 const struct GNUNET_CONFIGURATION_Handle *cfg)
215 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
216{ 211{
217 struct GNUNET_CONFIGURATION_Handle *testing_cfg; 212 struct GNUNET_CONFIGURATION_Handle *testing_cfg;
218 unsigned long long total_peers; 213 unsigned long long total_peers;
@@ -223,20 +218,17 @@ run (void *cls,
223 218
224#if VERBOSE 219#if VERBOSE
225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n"); 220 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n");
226 GNUNET_CONFIGURATION_set_value_string (testing_cfg, 221 GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing",
227 "testing", "use_progressbars", "YES"); 222 "use_progressbars", "YES");
228#endif 223#endif
229 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg, 224 if (GNUNET_OK !=
230 "testing", 225 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing",
231 "num_peers", 226 "num_peers", &total_peers))
232 &total_peers))
233 total_peers = NUM_PEERS; 227 total_peers = NUM_PEERS;
234 228
235 peers_left = total_peers; 229 peers_left = total_peers;
236 num_peers = peers_left; 230 num_peers = peers_left;
237 pg = GNUNET_TESTING_peergroup_start (testing_cfg, 231 pg = GNUNET_TESTING_peergroup_start (testing_cfg, peers_left, TIMEOUT,
238 peers_left,
239 TIMEOUT,
240 &connect_cb, &my_cb, NULL, NULL); 232 &connect_cb, &my_cb, NULL, NULL);
241 GNUNET_assert (pg != NULL); 233 GNUNET_assert (pg != NULL);
242 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &shutdown_task, NULL); 234 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &shutdown_task, NULL);
@@ -257,8 +249,8 @@ check ()
257 struct GNUNET_GETOPT_CommandLineOption options[] = { 249 struct GNUNET_GETOPT_CommandLineOption options[] = {
258 GNUNET_GETOPT_OPTION_END 250 GNUNET_GETOPT_OPTION_END
259 }; 251 };
260 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 252 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
261 argv, "test-nse-multipeer", "nohelp", options, &run, &ok); 253 "test-nse-multipeer", "nohelp", options, &run, &ok);
262 return ok; 254 return ok;
263} 255}
264 256
diff --git a/src/peerinfo-tool/gnunet-peerinfo.c b/src/peerinfo-tool/gnunet-peerinfo.c
index 951eecce8..c61b6abbf 100644
--- a/src/peerinfo-tool/gnunet-peerinfo.c
+++ b/src/peerinfo-tool/gnunet-peerinfo.c
@@ -87,8 +87,8 @@ process_resolved_address (void *cls, const char *address)
87 dump_pc (pc); 87 dump_pc (pc);
88 return; 88 return;
89 } 89 }
90 GNUNET_array_append (pc->address_list, 90 GNUNET_array_append (pc->address_list, pc->num_addresses,
91 pc->num_addresses, GNUNET_strdup (address)); 91 GNUNET_strdup (address));
92} 92}
93 93
94 94
@@ -103,10 +103,9 @@ process_resolved_address (void *cls, const char *address)
103 * @return GNUNET_OK to keep the address and continue 103 * @return GNUNET_OK to keep the address and continue
104 */ 104 */
105static int 105static int
106count_address (void *cls, 106count_address (void *cls, const char *tname,
107 const char *tname, 107 struct GNUNET_TIME_Absolute expiration, const void *addr,
108 struct GNUNET_TIME_Absolute expiration, 108 uint16_t addrlen)
109 const void *addr, uint16_t addrlen)
110{ 109{
111 struct PrintContext *pc = cls; 110 struct PrintContext *pc = cls;
112 111
@@ -126,18 +125,13 @@ count_address (void *cls,
126 * @return GNUNET_OK to keep the address and continue 125 * @return GNUNET_OK to keep the address and continue
127 */ 126 */
128static int 127static int
129print_address (void *cls, 128print_address (void *cls, const char *tname,
130 const char *tname, 129 struct GNUNET_TIME_Absolute expiration, const void *addr,
131 struct GNUNET_TIME_Absolute expiration, 130 uint16_t addrlen)
132 const void *addr, uint16_t addrlen)
133{ 131{
134 struct PrintContext *pc = cls; 132 struct PrintContext *pc = cls;
135 133
136 GNUNET_TRANSPORT_address_lookup (cfg, 134 GNUNET_TRANSPORT_address_lookup (cfg, addr, addrlen, no_resolve, tname,
137 addr,
138 addrlen,
139 no_resolve,
140 tname,
141 GNUNET_TIME_relative_multiply 135 GNUNET_TIME_relative_multiply
142 (GNUNET_TIME_UNIT_SECONDS, 10), 136 (GNUNET_TIME_UNIT_SECONDS, 10),
143 &process_resolved_address, pc); 137 &process_resolved_address, pc);
@@ -151,8 +145,7 @@ print_address (void *cls,
151 * Could of course do more (e.g. resolve via DNS). 145 * Could of course do more (e.g. resolve via DNS).
152 */ 146 */
153static void 147static void
154print_peer_info (void *cls, 148print_peer_info (void *cls, const struct GNUNET_PeerIdentity *peer,
155 const struct GNUNET_PeerIdentity *peer,
156 const struct GNUNET_HELLO_Message *hello, const char *err_msg) 149 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
157{ 150{
158 struct GNUNET_CRYPTO_HashAsciiEncoded enc; 151 struct GNUNET_CRYPTO_HashAsciiEncoded enc;
@@ -192,9 +185,8 @@ print_peer_info (void *cls,
192 * @param c configuration 185 * @param c configuration
193 */ 186 */
194static void 187static void
195run (void *cls, 188run (void *cls, char *const *args, const char *cfgfile,
196 char *const *args, 189 const struct GNUNET_CONFIGURATION_Handle *c)
197 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
198{ 190{
199 struct GNUNET_CRYPTO_RsaPrivateKey *priv; 191 struct GNUNET_CRYPTO_RsaPrivateKey *priv;
200 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; 192 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub;
@@ -216,20 +208,18 @@ run (void *cls,
216 fprintf (stderr, _("Could not access PEERINFO service. Exiting.\n")); 208 fprintf (stderr, _("Could not access PEERINFO service. Exiting.\n"));
217 return; 209 return;
218 } 210 }
219 GNUNET_PEERINFO_iterate (peerinfo, 211 GNUNET_PEERINFO_iterate (peerinfo, NULL,
220 NULL,
221 GNUNET_TIME_relative_multiply 212 GNUNET_TIME_relative_multiply
222 (GNUNET_TIME_UNIT_SECONDS, 5), 213 (GNUNET_TIME_UNIT_SECONDS, 5), &print_peer_info,
223 &print_peer_info, NULL); 214 NULL);
224 } 215 }
225 else 216 else
226 { 217 {
227 if (GNUNET_OK != 218 if (GNUNET_OK !=
228 GNUNET_CONFIGURATION_get_value_filename (cfg, 219 GNUNET_CONFIGURATION_get_value_filename (cfg, "GNUNETD", "HOSTKEY",
229 "GNUNETD", "HOSTKEY", &fn)) 220 &fn))
230 { 221 {
231 fprintf (stderr, 222 fprintf (stderr, _("Could not find option `%s:%s' in configuration.\n"),
232 _("Could not find option `%s:%s' in configuration.\n"),
233 "GNUNETD", "HOSTKEYFILE"); 223 "GNUNETD", "HOSTKEYFILE");
234 return; 224 return;
235 } 225 }
@@ -276,9 +266,7 @@ main (int argc, char *const *argv)
276 GNUNET_GETOPT_OPTION_END 266 GNUNET_GETOPT_OPTION_END
277 }; 267 };
278 return (GNUNET_OK == 268 return (GNUNET_OK ==
279 GNUNET_PROGRAM_run (argc, 269 GNUNET_PROGRAM_run (argc, argv, "gnunet-peerinfo",
280 argv,
281 "gnunet-peerinfo",
282 gettext_noop ("Print information about peers."), 270 gettext_noop ("Print information about peers."),
283 options, &run, NULL)) ? 0 : 1; 271 options, &run, NULL)) ? 0 : 1;
284} 272}
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c
index 160993649..26fec5289 100644
--- a/src/peerinfo/gnunet-service-peerinfo.c
+++ b/src/peerinfo/gnunet-service-peerinfo.c
@@ -124,10 +124,9 @@ make_info_message (const struct HostEntry *he)
124 * @return GNUNET_NO if expiration smaller than the current time 124 * @return GNUNET_NO if expiration smaller than the current time
125 */ 125 */
126static int 126static int
127discard_expired (void *cls, 127discard_expired (void *cls, const char *tname,
128 const char *tname, 128 struct GNUNET_TIME_Absolute expiration, const void *addr,
129 struct GNUNET_TIME_Absolute expiration, 129 uint16_t addrlen)
130 const void *addr, uint16_t addrlen)
131{ 130{
132 const struct GNUNET_TIME_Absolute *now = cls; 131 const struct GNUNET_TIME_Absolute *now = cls;
133 132
@@ -170,8 +169,8 @@ notify_all (struct HostEntry *entry)
170 struct InfoMessage *msg; 169 struct InfoMessage *msg;
171 170
172 msg = make_info_message (entry); 171 msg = make_info_message (entry);
173 GNUNET_SERVER_notification_context_broadcast (notify_list, 172 GNUNET_SERVER_notification_context_broadcast (notify_list, &msg->header,
174 &msg->header, GNUNET_NO); 173 GNUNET_NO);
175 GNUNET_free (msg); 174 GNUNET_free (msg);
176} 175}
177 176
@@ -195,8 +194,8 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity)
195 entry = GNUNET_CONTAINER_multihashmap_get (hostmap, &identity->hashPubKey); 194 entry = GNUNET_CONTAINER_multihashmap_get (hostmap, &identity->hashPubKey);
196 if (entry != NULL) 195 if (entry != NULL)
197 return; 196 return;
198 GNUNET_STATISTICS_update (stats, 197 GNUNET_STATISTICS_update (stats, gettext_noop ("# peers known"), 1,
199 gettext_noop ("# peers known"), 1, GNUNET_NO); 198 GNUNET_NO);
200 entry = GNUNET_malloc (sizeof (struct HostEntry)); 199 entry = GNUNET_malloc (sizeof (struct HostEntry));
201 entry->identity = *identity; 200 entry->identity = *identity;
202 201
@@ -216,16 +215,14 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity)
216 else 215 else
217 { 216 {
218 now = GNUNET_TIME_absolute_get (); 217 now = GNUNET_TIME_absolute_get ();
219 hello_clean = GNUNET_HELLO_iterate_addresses (hello, 218 hello_clean =
220 GNUNET_YES, 219 GNUNET_HELLO_iterate_addresses (hello, GNUNET_YES, &discard_expired,
221 &discard_expired, &now); 220 &now);
222 entry->hello = hello_clean; 221 entry->hello = hello_clean;
223 } 222 }
224 } 223 }
225 GNUNET_free (fn); 224 GNUNET_free (fn);
226 GNUNET_CONTAINER_multihashmap_put (hostmap, 225 GNUNET_CONTAINER_multihashmap_put (hostmap, &identity->hashPubKey, entry,
227 &identity->hashPubKey,
228 entry,
229 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 226 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
230 notify_all (entry); 227 notify_all (entry);
231} 228}
@@ -244,8 +241,8 @@ remove_garbage (const char *fullname)
244 ("File `%s' in directory `%s' does not match naming convention. " 241 ("File `%s' in directory `%s' does not match naming convention. "
245 "Removed.\n"), fullname, networkIdDirectory); 242 "Removed.\n"), fullname, networkIdDirectory);
246 else 243 else
247 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR | 244 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
248 GNUNET_ERROR_TYPE_BULK, "unlink", fullname); 245 "unlink", fullname);
249} 246}
250 247
251 248
@@ -271,8 +268,8 @@ hosts_directory_scan_callback (void *cls, const char *fullname)
271 remove_garbage (fullname); 268 remove_garbage (fullname);
272 return GNUNET_OK; 269 return GNUNET_OK;
273 } 270 }
274 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (filename, 271 if (GNUNET_OK !=
275 &identity.hashPubKey)) 272 GNUNET_CRYPTO_hash_from_string (filename, &identity.hashPubKey))
276 { 273 {
277 remove_garbage (fullname); 274 remove_garbage (fullname);
278 return GNUNET_OK; 275 return GNUNET_OK;
@@ -305,11 +302,10 @@ cron_scan_directory_data_hosts (void *cls,
305 GNUNET_DISK_directory_scan (networkIdDirectory, 302 GNUNET_DISK_directory_scan (networkIdDirectory,
306 &hosts_directory_scan_callback, &count); 303 &hosts_directory_scan_callback, &count);
307 if ((0 == count) && (0 == (++retries & 31))) 304 if ((0 == count) && (0 == (++retries & 31)))
308 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | 305 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
309 GNUNET_ERROR_TYPE_BULK,
310 _("Still no peers found in `%s'!\n"), networkIdDirectory); 306 _("Still no peers found in `%s'!\n"), networkIdDirectory);
311 GNUNET_SCHEDULER_add_delayed (DATA_HOST_FREQ, 307 GNUNET_SCHEDULER_add_delayed (DATA_HOST_FREQ, &cron_scan_directory_data_hosts,
312 &cron_scan_directory_data_hosts, NULL); 308 NULL);
313} 309}
314 310
315 311
@@ -352,9 +348,7 @@ bind_address (const struct GNUNET_PeerIdentity *peer,
352 if (GNUNET_OK == GNUNET_DISK_directory_create_for_file (fn)) 348 if (GNUNET_OK == GNUNET_DISK_directory_create_for_file (fn))
353 { 349 {
354 if (GNUNET_SYSERR == 350 if (GNUNET_SYSERR ==
355 GNUNET_DISK_fn_write (fn, 351 GNUNET_DISK_fn_write (fn, host->hello, GNUNET_HELLO_size (host->hello),
356 host->hello,
357 GNUNET_HELLO_size (host->hello),
358 GNUNET_DISK_PERM_USER_READ | 352 GNUNET_DISK_PERM_USER_READ |
359 GNUNET_DISK_PERM_USER_WRITE | 353 GNUNET_DISK_PERM_USER_WRITE |
360 GNUNET_DISK_PERM_GROUP_READ | 354 GNUNET_DISK_PERM_GROUP_READ |
@@ -425,14 +419,11 @@ discard_hosts_helper (void *cls, const char *fn)
425 return GNUNET_OK; 419 return GNUNET_OK;
426 } 420 }
427 hello = (const struct GNUNET_HELLO_Message *) buffer; 421 hello = (const struct GNUNET_HELLO_Message *) buffer;
428 new_hello = GNUNET_HELLO_iterate_addresses (hello, 422 new_hello =
429 GNUNET_YES, 423 GNUNET_HELLO_iterate_addresses (hello, GNUNET_YES, &discard_expired, now);
430 &discard_expired, now);
431 if (new_hello != NULL) 424 if (new_hello != NULL)
432 { 425 {
433 GNUNET_DISK_fn_write (fn, 426 GNUNET_DISK_fn_write (fn, new_hello, GNUNET_HELLO_size (new_hello),
434 new_hello,
435 GNUNET_HELLO_size (new_hello),
436 GNUNET_DISK_PERM_USER_READ | 427 GNUNET_DISK_PERM_USER_READ |
437 GNUNET_DISK_PERM_USER_WRITE | 428 GNUNET_DISK_PERM_USER_WRITE |
438 GNUNET_DISK_PERM_GROUP_READ | 429 GNUNET_DISK_PERM_GROUP_READ |
@@ -461,8 +452,8 @@ cron_clean_data_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
461 return; 452 return;
462 now = GNUNET_TIME_absolute_get (); 453 now = GNUNET_TIME_absolute_get ();
463 GNUNET_DISK_directory_scan (networkIdDirectory, &discard_hosts_helper, &now); 454 GNUNET_DISK_directory_scan (networkIdDirectory, &discard_hosts_helper, &now);
464 GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ, 455 GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ, &cron_clean_data_hosts,
465 &cron_clean_data_hosts, NULL); 456 NULL);
466} 457}
467 458
468 459
@@ -474,8 +465,7 @@ cron_clean_data_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
474 * @param message the actual message 465 * @param message the actual message
475 */ 466 */
476static void 467static void
477handle_hello (void *cls, 468handle_hello (void *cls, struct GNUNET_SERVER_Client *client,
478 struct GNUNET_SERVER_Client *client,
479 const struct GNUNET_MessageHeader *message) 469 const struct GNUNET_MessageHeader *message)
480{ 470{
481 const struct GNUNET_HELLO_Message *hello; 471 const struct GNUNET_HELLO_Message *hello;
@@ -489,8 +479,7 @@ handle_hello (void *cls,
489 return; 479 return;
490 } 480 }
491#if DEBUG_PEERINFO 481#if DEBUG_PEERINFO
492 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received for peer `%4s'\n",
493 "`%s' message received for peer `%4s'\n",
494 "HELLO", GNUNET_i2s (&pid)); 483 "HELLO", GNUNET_i2s (&pid));
495#endif 484#endif
496 bind_address (&pid, hello); 485 bind_address (&pid, hello);
@@ -506,8 +495,7 @@ handle_hello (void *cls,
506 * @param message the actual message 495 * @param message the actual message
507 */ 496 */
508static void 497static void
509handle_get (void *cls, 498handle_get (void *cls, struct GNUNET_SERVER_Client *client,
510 struct GNUNET_SERVER_Client *client,
511 const struct GNUNET_MessageHeader *message) 499 const struct GNUNET_MessageHeader *message)
512{ 500{
513 const struct ListPeerMessage *lpm; 501 const struct ListPeerMessage *lpm;
@@ -516,13 +504,11 @@ handle_get (void *cls,
516 lpm = (const struct ListPeerMessage *) message; 504 lpm = (const struct ListPeerMessage *) message;
517 GNUNET_break (0 == ntohl (lpm->reserved)); 505 GNUNET_break (0 == ntohl (lpm->reserved));
518#if DEBUG_PEERINFO 506#if DEBUG_PEERINFO
519 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 507 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received for peer `%4s'\n",
520 "`%s' message received for peer `%4s'\n",
521 "GET", GNUNET_i2s (&lpm->peer)); 508 "GET", GNUNET_i2s (&lpm->peer));
522#endif 509#endif
523 tc = GNUNET_SERVER_transmit_context_create (client); 510 tc = GNUNET_SERVER_transmit_context_create (client);
524 GNUNET_CONTAINER_multihashmap_get_multiple (hostmap, 511 GNUNET_CONTAINER_multihashmap_get_multiple (hostmap, &lpm->peer.hashPubKey,
525 &lpm->peer.hashPubKey,
526 &add_to_tc, tc); 512 &add_to_tc, tc);
527 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 513 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
528 GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); 514 GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
@@ -538,8 +524,7 @@ handle_get (void *cls,
538 * @param message the actual message 524 * @param message the actual message
539 */ 525 */
540static void 526static void
541handle_get_all (void *cls, 527handle_get_all (void *cls, struct GNUNET_SERVER_Client *client,
542 struct GNUNET_SERVER_Client *client,
543 const struct GNUNET_MessageHeader *message) 528 const struct GNUNET_MessageHeader *message)
544{ 529{
545 struct GNUNET_SERVER_TransmitContext *tc; 530 struct GNUNET_SERVER_TransmitContext *tc;
@@ -563,8 +548,8 @@ do_notify_entry (void *cls, const GNUNET_HashCode * key, void *value)
563 struct InfoMessage *msg; 548 struct InfoMessage *msg;
564 549
565 msg = make_info_message (he); 550 msg = make_info_message (he);
566 GNUNET_SERVER_notification_context_unicast (notify_list, 551 GNUNET_SERVER_notification_context_unicast (notify_list, client, &msg->header,
567 client, &msg->header, GNUNET_NO); 552 GNUNET_NO);
568 GNUNET_free (msg); 553 GNUNET_free (msg);
569 return GNUNET_YES; 554 return GNUNET_YES;
570} 555}
@@ -578,8 +563,7 @@ do_notify_entry (void *cls, const GNUNET_HashCode * key, void *value)
578 * @param message the actual message 563 * @param message the actual message
579 */ 564 */
580static void 565static void
581handle_notify (void *cls, 566handle_notify (void *cls, struct GNUNET_SERVER_Client *client,
582 struct GNUNET_SERVER_Client *client,
583 const struct GNUNET_MessageHeader *message) 567 const struct GNUNET_MessageHeader *message)
584{ 568{
585#if DEBUG_PEERINFO 569#if DEBUG_PEERINFO
@@ -630,8 +614,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
630 * @param cfg configuration to use 614 * @param cfg configuration to use
631 */ 615 */
632static void 616static void
633run (void *cls, 617run (void *cls, struct GNUNET_SERVER_Handle *server,
634 struct GNUNET_SERVER_Handle *server,
635 const struct GNUNET_CONFIGURATION_Handle *cfg) 618 const struct GNUNET_CONFIGURATION_Handle *cfg)
636{ 619{
637 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 620 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
@@ -649,8 +632,7 @@ run (void *cls,
649 stats = GNUNET_STATISTICS_create ("peerinfo", cfg); 632 stats = GNUNET_STATISTICS_create ("peerinfo", cfg);
650 notify_list = GNUNET_SERVER_notification_context_create (server, 0); 633 notify_list = GNUNET_SERVER_notification_context_create (server, 0);
651 GNUNET_assert (GNUNET_OK == 634 GNUNET_assert (GNUNET_OK ==
652 GNUNET_CONFIGURATION_get_value_filename (cfg, 635 GNUNET_CONFIGURATION_get_value_filename (cfg, "peerinfo",
653 "peerinfo",
654 "HOSTS", 636 "HOSTS",
655 &networkIdDirectory)); 637 &networkIdDirectory));
656 GNUNET_DISK_directory_create (networkIdDirectory); 638 GNUNET_DISK_directory_create (networkIdDirectory);
@@ -658,8 +640,8 @@ run (void *cls,
658 &cron_scan_directory_data_hosts, NULL); 640 &cron_scan_directory_data_hosts, NULL);
659 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, 641 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
660 &cron_clean_data_hosts, NULL); 642 &cron_clean_data_hosts, NULL);
661 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 643 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
662 &shutdown_task, NULL); 644 NULL);
663 GNUNET_SERVER_add_handlers (server, handlers); 645 GNUNET_SERVER_add_handlers (server, handlers);
664} 646}
665 647
@@ -676,11 +658,10 @@ main (int argc, char *const *argv)
676{ 658{
677 int ret; 659 int ret;
678 660
679 ret = (GNUNET_OK == 661 ret =
680 GNUNET_SERVICE_run (argc, 662 (GNUNET_OK ==
681 argv, 663 GNUNET_SERVICE_run (argc, argv, "peerinfo", GNUNET_SERVICE_OPTION_NONE,
682 "peerinfo", 664 &run, NULL)) ? 0 : 1;
683 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
684 GNUNET_free_non_null (networkIdDirectory); 665 GNUNET_free_non_null (networkIdDirectory);
685 return ret; 666 return ret;
686} 667}
diff --git a/src/peerinfo/peerinfo_api.c b/src/peerinfo/peerinfo_api.c
index 444ae98e2..4febf2eeb 100644
--- a/src/peerinfo/peerinfo_api.c
+++ b/src/peerinfo/peerinfo_api.c
@@ -240,8 +240,9 @@ reconnect (struct GNUNET_PEERINFO_Handle *h)
240 h->client = GNUNET_CLIENT_connect ("peerinfo", h->cfg); 240 h->client = GNUNET_CLIENT_connect ("peerinfo", h->cfg);
241 if (NULL == h->client) 241 if (NULL == h->client)
242 { 242 {
243 h->r_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 243 h->r_task =
244 &reconnect_task, h); 244 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect_task,
245 h);
245 return; 246 return;
246 } 247 }
247 trigger_transmit (h); 248 trigger_transmit (h);
@@ -283,8 +284,8 @@ do_transmit (void *cls, size_t size, void *buf)
283 memcpy (buf, &tqe[1], ret); 284 memcpy (buf, &tqe[1], ret);
284#if DEBUG_PEERINFO 285#if DEBUG_PEERINFO
285 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 286 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
286 "Transmitting request of size %u to `%s' service.\n", 287 "Transmitting request of size %u to `%s' service.\n", ret,
287 ret, "PEERINFO"); 288 "PEERINFO");
288#endif 289#endif
289 GNUNET_CONTAINER_DLL_remove (h->tq_head, h->tq_tail, tqe); 290 GNUNET_CONTAINER_DLL_remove (h->tq_head, h->tq_tail, tqe);
290 if (tqe->cont != NULL) 291 if (tqe->cont != NULL)
@@ -318,11 +319,11 @@ trigger_transmit (struct GNUNET_PEERINFO_Handle *h)
318 reconnect (h); 319 reconnect (h);
319 return; 320 return;
320 } 321 }
321 h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, 322 h->th =
322 tqe->size, 323 GNUNET_CLIENT_notify_transmit_ready (h->client, tqe->size,
323 GNUNET_TIME_absolute_get_remaining 324 GNUNET_TIME_absolute_get_remaining
324 (tqe->timeout), GNUNET_YES, 325 (tqe->timeout), GNUNET_YES,
325 &do_transmit, h); 326 &do_transmit, h);
326} 327}
327 328
328 329
@@ -487,9 +488,8 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg)
487 ic->h->in_receive = GNUNET_YES; 488 ic->h->in_receive = GNUNET_YES;
488 if (ic->callback != NULL) 489 if (ic->callback != NULL)
489 ic->callback (ic->callback_cls, &im->peer, hello, NULL); 490 ic->callback (ic->callback_cls, &im->peer, hello, NULL);
490 GNUNET_CLIENT_receive (ic->h->client, 491 GNUNET_CLIENT_receive (ic->h->client, &peerinfo_handler, ic,
491 &peerinfo_handler, 492 GNUNET_TIME_absolute_get_remaining (ic->timeout));
492 ic, GNUNET_TIME_absolute_get_remaining (ic->timeout));
493} 493}
494 494
495 495
@@ -527,9 +527,8 @@ iterator_start_receive (void *cls, int transmit_success)
527 ic->h->in_receive = GNUNET_YES; 527 ic->h->in_receive = GNUNET_YES;
528 ic->in_receive = GNUNET_YES; 528 ic->in_receive = GNUNET_YES;
529 ic->tqe = NULL; 529 ic->tqe = NULL;
530 GNUNET_CLIENT_receive (ic->h->client, 530 GNUNET_CLIENT_receive (ic->h->client, &peerinfo_handler, ic,
531 &peerinfo_handler, 531 GNUNET_TIME_absolute_get_remaining (ic->timeout));
532 ic, GNUNET_TIME_absolute_get_remaining (ic->timeout));
533} 532}
534 533
535 534
@@ -549,8 +548,7 @@ signal_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
549 GNUNET_CONTAINER_DLL_remove (ic->h->tq_head, ic->h->tq_tail, ic->tqe); 548 GNUNET_CONTAINER_DLL_remove (ic->h->tq_head, ic->h->tq_tail, ic->tqe);
550 else 549 else
551 reconnect (ic->h); 550 reconnect (ic->h);
552 ic->callback (ic->callback_cls, 551 ic->callback (ic->callback_cls, NULL, NULL,
553 NULL, NULL,
554 _ 552 _
555 ("Timeout transmitting iteration request to `PEERINFO' service.\n")); 553 ("Timeout transmitting iteration request to `PEERINFO' service.\n"));
556 ic->callback = NULL; 554 ic->callback = NULL;
@@ -592,8 +590,9 @@ GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h,
592 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 590 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
593 "Requesting list of peers from PEERINFO service\n"); 591 "Requesting list of peers from PEERINFO service\n");
594#endif 592#endif
595 tqe = GNUNET_malloc (sizeof (struct TransmissionQueueEntry) + 593 tqe =
596 sizeof (struct GNUNET_MessageHeader)); 594 GNUNET_malloc (sizeof (struct TransmissionQueueEntry) +
595 sizeof (struct GNUNET_MessageHeader));
597 tqe->size = sizeof (struct GNUNET_MessageHeader); 596 tqe->size = sizeof (struct GNUNET_MessageHeader);
598 lapm = (struct GNUNET_MessageHeader *) &tqe[1]; 597 lapm = (struct GNUNET_MessageHeader *) &tqe[1];
599 lapm->size = htons (sizeof (struct GNUNET_MessageHeader)); 598 lapm->size = htons (sizeof (struct GNUNET_MessageHeader));
@@ -606,8 +605,9 @@ GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h,
606 "Requesting information on peer `%4s' from PEERINFO service\n", 605 "Requesting information on peer `%4s' from PEERINFO service\n",
607 GNUNET_i2s (peer)); 606 GNUNET_i2s (peer));
608#endif 607#endif
609 tqe = GNUNET_malloc (sizeof (struct TransmissionQueueEntry) + 608 tqe =
610 sizeof (struct ListPeerMessage)); 609 GNUNET_malloc (sizeof (struct TransmissionQueueEntry) +
610 sizeof (struct ListPeerMessage));
611 tqe->size = sizeof (struct ListPeerMessage); 611 tqe->size = sizeof (struct ListPeerMessage);
612 lpm = (struct ListPeerMessage *) &tqe[1]; 612 lpm = (struct ListPeerMessage *) &tqe[1];
613 lpm->header.size = htons (sizeof (struct ListPeerMessage)); 613 lpm->header.size = htons (sizeof (struct ListPeerMessage));
@@ -620,8 +620,8 @@ GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h,
620 ic->callback = callback; 620 ic->callback = callback;
621 ic->callback_cls = callback_cls; 621 ic->callback_cls = callback_cls;
622 ic->timeout = GNUNET_TIME_relative_to_absolute (timeout); 622 ic->timeout = GNUNET_TIME_relative_to_absolute (timeout);
623 ic->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, 623 ic->timeout_task =
624 &signal_timeout, ic); 624 GNUNET_SCHEDULER_add_delayed (timeout, &signal_timeout, ic);
625 tqe->timeout = ic->timeout; 625 tqe->timeout = ic->timeout;
626 tqe->cont = &iterator_start_receive; 626 tqe->cont = &iterator_start_receive;
627 tqe->cont_cls = ic; 627 tqe->cont_cls = ic;
diff --git a/src/peerinfo/peerinfo_api_notify.c b/src/peerinfo/peerinfo_api_notify.c
index 0c7474f4a..4ec7b2192 100644
--- a/src/peerinfo/peerinfo_api_notify.c
+++ b/src/peerinfo/peerinfo_api_notify.c
@@ -104,8 +104,8 @@ reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
104 if (NULL == nc->client) 104 if (NULL == nc->client)
105 { 105 {
106 /* ugh */ 106 /* ugh */
107 nc->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 107 nc->task =
108 &reconnect, nc); 108 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect, nc);
109 return; 109 return;
110 } 110 }
111 request_notifications (nc); 111 request_notifications (nc);
@@ -176,9 +176,8 @@ process_notification (void *cls, const struct GNUNET_MessageHeader *msg)
176static void 176static void
177receive_notifications (struct GNUNET_PEERINFO_NotifyContext *nc) 177receive_notifications (struct GNUNET_PEERINFO_NotifyContext *nc)
178{ 178{
179 GNUNET_CLIENT_receive (nc->client, 179 GNUNET_CLIENT_receive (nc->client, &process_notification, nc,
180 &process_notification, 180 GNUNET_TIME_UNIT_FOREVER_REL);
181 nc, GNUNET_TIME_UNIT_FOREVER_REL);
182} 181}
183 182
184 183
@@ -223,12 +222,12 @@ static void
223request_notifications (struct GNUNET_PEERINFO_NotifyContext *nc) 222request_notifications (struct GNUNET_PEERINFO_NotifyContext *nc)
224{ 223{
225 GNUNET_assert (NULL == nc->init); 224 GNUNET_assert (NULL == nc->init);
226 nc->init = GNUNET_CLIENT_notify_transmit_ready (nc->client, 225 nc->init =
227 sizeof (struct 226 GNUNET_CLIENT_notify_transmit_ready (nc->client,
228 GNUNET_MessageHeader), 227 sizeof (struct GNUNET_MessageHeader),
229 GNUNET_TIME_UNIT_FOREVER_REL, 228 GNUNET_TIME_UNIT_FOREVER_REL,
230 GNUNET_YES, 229 GNUNET_YES, &transmit_notify_request,
231 &transmit_notify_request, nc); 230 nc);
232} 231}
233 232
234 233
diff --git a/src/peerinfo/perf_peerinfo_api.c b/src/peerinfo/perf_peerinfo_api.c
index d0eadaf94..d9107c8fe 100755
--- a/src/peerinfo/perf_peerinfo_api.c
+++ b/src/peerinfo/perf_peerinfo_api.c
@@ -47,9 +47,7 @@ static struct GNUNET_PEERINFO_Handle *h;
47static unsigned int numpeers; 47static unsigned int numpeers;
48 48
49static int 49static int
50check_it (void *cls, 50check_it (void *cls, const char *tname, struct GNUNET_TIME_Absolute expiration,
51 const char *tname,
52 struct GNUNET_TIME_Absolute expiration,
53 const void *addr, uint16_t addrlen) 51 const void *addr, uint16_t addrlen)
54{ 52{
55#if DEBUG 53#if DEBUG
@@ -74,10 +72,11 @@ address_generator (void *cls, size_t max, void *buf)
74 72
75 GNUNET_asprintf (&address, "Address%d", *agc); 73 GNUNET_asprintf (&address, "Address%d", *agc);
76 74
77 ret = GNUNET_HELLO_add_address ("peerinfotest", 75 ret =
78 GNUNET_TIME_relative_to_absolute 76 GNUNET_HELLO_add_address ("peerinfotest",
79 (GNUNET_TIME_UNIT_HOURS), 77 GNUNET_TIME_relative_to_absolute
80 address, strlen (address) + 1, buf, max); 78 (GNUNET_TIME_UNIT_HOURS), address,
79 strlen (address) + 1, buf, max);
81 GNUNET_free (address); 80 GNUNET_free (address);
82 *agc = 0; 81 *agc = 0;
83 return ret; 82 return ret;
@@ -100,8 +99,7 @@ add_peer (size_t i)
100 99
101 100
102static void 101static void
103process (void *cls, 102process (void *cls, const struct GNUNET_PeerIdentity *peer,
104 const struct GNUNET_PeerIdentity *peer,
105 const struct GNUNET_HELLO_Message *hello, const char *err_msg) 103 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
106{ 104{
107 if (peer == NULL) 105 if (peer == NULL)
@@ -124,9 +122,8 @@ process (void *cls,
124 122
125 123
126static void 124static void
127run (void *cls, 125run (void *cls, char *const *args, const char *cfgfile,
128 char *const *args, 126 const struct GNUNET_CONFIGURATION_Handle *c)
129 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
130{ 127{
131 size_t i; 128 size_t i;
132 129
@@ -136,11 +133,10 @@ run (void *cls,
136 for (i = 0; i < NUM_REQUESTS; i++) 133 for (i = 0; i < NUM_REQUESTS; i++)
137 { 134 {
138 add_peer (i); 135 add_peer (i);
139 ic[i] = GNUNET_PEERINFO_iterate (h, 136 ic[i] =
140 NULL, 137 GNUNET_PEERINFO_iterate (h, NULL,
141 GNUNET_TIME_relative_multiply 138 GNUNET_TIME_relative_multiply
142 (GNUNET_TIME_UNIT_SECONDS, 30), 139 (GNUNET_TIME_UNIT_SECONDS, 30), &process, cls);
143 &process, cls);
144 } 140 }
145} 141}
146 142
@@ -165,21 +161,21 @@ check ()
165 struct GNUNET_GETOPT_CommandLineOption options[] = { 161 struct GNUNET_GETOPT_CommandLineOption options[] = {
166 GNUNET_GETOPT_OPTION_END 162 GNUNET_GETOPT_OPTION_END
167 }; 163 };
168 proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-peerinfo", 164 proc =
169 "gnunet-service-peerinfo", 165 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-peerinfo",
166 "gnunet-service-peerinfo",
170#if DEBUG_PEERINFO 167#if DEBUG_PEERINFO
171 "-L", "DEBUG", 168 "-L", "DEBUG",
172#else 169#else
173 "-L", "ERROR", 170 "-L", "ERROR",
174#endif 171#endif
175 "-c", "test_peerinfo_api_data.conf", NULL); 172 "-c", "test_peerinfo_api_data.conf", NULL);
176#endif 173#endif
177 GNUNET_assert (NULL != proc); 174 GNUNET_assert (NULL != proc);
178 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 175 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
179 argv, "perf-peerinfo-api", "nohelp", options, &run, &ok); 176 "perf-peerinfo-api", "nohelp", options, &run, &ok);
180 fprintf (stderr, 177 fprintf (stderr, "Received %u/%u calls before timeout\n", numpeers,
181 "Received %u/%u calls before timeout\n", 178 NUM_REQUESTS * NUM_REQUESTS / 2);
182 numpeers, NUM_REQUESTS * NUM_REQUESTS / 2);
183 GAUGER ("PEERINFO", "Peerinfo lookups", numpeers / 30, "peers/s"); 179 GAUGER ("PEERINFO", "Peerinfo lookups", numpeers / 30, "peers/s");
184#if START_SERVICE 180#if START_SERVICE
185 if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) 181 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
diff --git a/src/peerinfo/test_peerinfo_api.c b/src/peerinfo/test_peerinfo_api.c
index e740f1fc9..bbdc591f4 100644
--- a/src/peerinfo/test_peerinfo_api.c
+++ b/src/peerinfo/test_peerinfo_api.c
@@ -45,9 +45,7 @@ static struct GNUNET_PEERINFO_Handle *h;
45static unsigned int retries; 45static unsigned int retries;
46 46
47static int 47static int
48check_it (void *cls, 48check_it (void *cls, const char *tname, struct GNUNET_TIME_Absolute expiration,
49 const char *tname,
50 struct GNUNET_TIME_Absolute expiration,
51 const void *addr, uint16_t addrlen) 49 const void *addr, uint16_t addrlen)
52{ 50{
53 unsigned int *agc = cls; 51 unsigned int *agc = cls;
@@ -70,10 +68,11 @@ address_generator (void *cls, size_t max, void *buf)
70 68
71 if (0 == *agc) 69 if (0 == *agc)
72 return 0; 70 return 0;
73 ret = GNUNET_HELLO_add_address ("peerinfotest", 71 ret =
74 GNUNET_TIME_relative_to_absolute 72 GNUNET_HELLO_add_address ("peerinfotest",
75 (GNUNET_TIME_UNIT_HOURS), "Address", *agc, 73 GNUNET_TIME_relative_to_absolute
76 buf, max); 74 (GNUNET_TIME_UNIT_HOURS), "Address", *agc, buf,
75 max);
77 (*agc)--; 76 (*agc)--;
78 return ret; 77 return ret;
79} 78}
@@ -98,8 +97,7 @@ add_peer ()
98 97
99 98
100static void 99static void
101process (void *cls, 100process (void *cls, const struct GNUNET_PeerIdentity *peer,
102 const struct GNUNET_PeerIdentity *peer,
103 const struct GNUNET_HELLO_Message *hello, const char *err_msg) 101 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
104{ 102{
105 int *ok = cls; 103 int *ok = cls;
@@ -119,11 +117,10 @@ process (void *cls,
119 /* try again */ 117 /* try again */
120 retries++; 118 retries++;
121 add_peer (); 119 add_peer ();
122 ic = GNUNET_PEERINFO_iterate (h, 120 ic = GNUNET_PEERINFO_iterate (h, NULL,
123 NULL,
124 GNUNET_TIME_relative_multiply 121 GNUNET_TIME_relative_multiply
125 (GNUNET_TIME_UNIT_SECONDS, 15), 122 (GNUNET_TIME_UNIT_SECONDS, 15), &process,
126 &process, cls); 123 cls);
127 return; 124 return;
128 } 125 }
129 GNUNET_assert (peer == NULL); 126 GNUNET_assert (peer == NULL);
@@ -145,16 +142,14 @@ process (void *cls,
145 142
146 143
147static void 144static void
148run (void *cls, 145run (void *cls, char *const *args, const char *cfgfile,
149 char *const *args, 146 const struct GNUNET_CONFIGURATION_Handle *c)
150 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
151{ 147{
152 cfg = c; 148 cfg = c;
153 h = GNUNET_PEERINFO_connect (cfg); 149 h = GNUNET_PEERINFO_connect (cfg);
154 GNUNET_assert (h != NULL); 150 GNUNET_assert (h != NULL);
155 add_peer (); 151 add_peer ();
156 ic = GNUNET_PEERINFO_iterate (h, 152 ic = GNUNET_PEERINFO_iterate (h, NULL,
157 NULL,
158 GNUNET_TIME_relative_multiply 153 GNUNET_TIME_relative_multiply
159 (GNUNET_TIME_UNIT_SECONDS, 15), &process, cls); 154 (GNUNET_TIME_UNIT_SECONDS, 15), &process, cls);
160} 155}
@@ -177,15 +172,16 @@ check ()
177 struct GNUNET_GETOPT_CommandLineOption options[] = { 172 struct GNUNET_GETOPT_CommandLineOption options[] = {
178 GNUNET_GETOPT_OPTION_END 173 GNUNET_GETOPT_OPTION_END
179 }; 174 };
180 proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-peerinfo", 175 proc =
181 "gnunet-service-peerinfo", 176 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-peerinfo",
177 "gnunet-service-peerinfo",
182#if DEBUG_PEERINFO 178#if DEBUG_PEERINFO
183 "-L", "DEBUG", 179 "-L", "DEBUG",
184#endif 180#endif
185 "-c", "test_peerinfo_api_data.conf", NULL); 181 "-c", "test_peerinfo_api_data.conf", NULL);
186 GNUNET_assert (NULL != proc); 182 GNUNET_assert (NULL != proc);
187 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 183 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
188 argv, "test-peerinfo-api", "nohelp", options, &run, &ok); 184 "test-peerinfo-api", "nohelp", options, &run, &ok);
189 if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) 185 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
190 { 186 {
191 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 187 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
diff --git a/src/statistics/gnunet-service-statistics.c b/src/statistics/gnunet-service-statistics.c
index 5e0be1183..3305dc6f4 100644
--- a/src/statistics/gnunet-service-statistics.c
+++ b/src/statistics/gnunet-service-statistics.c
@@ -181,8 +181,8 @@ load (struct GNUNET_SERVER_Handle *server)
181 char *buf; 181 char *buf;
182 struct GNUNET_SERVER_MessageStreamTokenizer *mst; 182 struct GNUNET_SERVER_MessageStreamTokenizer *mst;
183 183
184 fn = GNUNET_DISK_get_home_filename (cfg, 184 fn = GNUNET_DISK_get_home_filename (cfg, "statistics", "statistics.data",
185 "statistics", "statistics.data", NULL); 185 NULL);
186 if (fn == NULL) 186 if (fn == NULL)
187 return; 187 return;
188 if ((0 != stat (fn, &sb)) || (sb.st_size == 0)) 188 if ((0 != stat (fn, &sb)) || (sb.st_size == 0))
@@ -209,10 +209,8 @@ load (struct GNUNET_SERVER_Handle *server)
209 (unsigned long long) sb.st_size, fn); 209 (unsigned long long) sb.st_size, fn);
210 mst = GNUNET_SERVER_mst_create (&inject_message, server); 210 mst = GNUNET_SERVER_mst_create (&inject_message, server);
211 GNUNET_break (GNUNET_OK == 211 GNUNET_break (GNUNET_OK ==
212 GNUNET_SERVER_mst_receive (mst, 212 GNUNET_SERVER_mst_receive (mst, NULL, buf, sb.st_size,
213 NULL, 213 GNUNET_YES, GNUNET_NO));
214 buf,
215 sb.st_size, GNUNET_YES, GNUNET_NO));
216 GNUNET_SERVER_mst_destroy (mst); 214 GNUNET_SERVER_mst_destroy (mst);
217 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_unmap (mh)); 215 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_unmap (mh));
218 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh)); 216 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh));
@@ -232,12 +230,12 @@ save ()
232 unsigned long long total; 230 unsigned long long total;
233 231
234 fh = NULL; 232 fh = NULL;
235 fn = GNUNET_DISK_get_home_filename (cfg, 233 fn = GNUNET_DISK_get_home_filename (cfg, "statistics", "statistics.data",
236 "statistics", "statistics.data", NULL); 234 NULL);
237 if (fn != NULL) 235 if (fn != NULL)
238 fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_WRITE 236 fh = GNUNET_DISK_file_open (fn,
239 | GNUNET_DISK_OPEN_CREATE | 237 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE
240 GNUNET_DISK_OPEN_TRUNCATE, 238 | GNUNET_DISK_OPEN_TRUNCATE,
241 GNUNET_DISK_PERM_USER_READ | 239 GNUNET_DISK_PERM_USER_READ |
242 GNUNET_DISK_PERM_USER_WRITE); 240 GNUNET_DISK_PERM_USER_WRITE);
243 total = 0; 241 total = 0;
@@ -292,13 +290,13 @@ transmit (struct GNUNET_SERVER_Client *client, const struct StatsEntry *e)
292 m->uid |= htonl (GNUNET_STATISTICS_PERSIST_BIT); 290 m->uid |= htonl (GNUNET_STATISTICS_PERSIST_BIT);
293 m->value = GNUNET_htonll (e->value); 291 m->value = GNUNET_htonll (e->value);
294 size -= sizeof (struct GNUNET_STATISTICS_ReplyMessage); 292 size -= sizeof (struct GNUNET_STATISTICS_ReplyMessage);
295 GNUNET_assert (size == GNUNET_STRINGS_buffer_fill ((char *) &m[1], 293 GNUNET_assert (size ==
296 size, 294 GNUNET_STRINGS_buffer_fill ((char *) &m[1], size, 2,
297 2, e->service, e->name)); 295 e->service, e->name));
298#if DEBUG_STATISTICS 296#if DEBUG_STATISTICS
299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 297 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
300 "Transmitting value for `%s:%s' (%d): %llu\n", 298 "Transmitting value for `%s:%s' (%d): %llu\n", e->service,
301 e->service, e->name, e->persistent, e->value); 299 e->name, e->persistent, e->value);
302#endif 300#endif
303 GNUNET_SERVER_notification_context_unicast (nc, client, &m->header, 301 GNUNET_SERVER_notification_context_unicast (nc, client, &m->header,
304 GNUNET_NO); 302 GNUNET_NO);
@@ -312,9 +310,8 @@ transmit (struct GNUNET_SERVER_Client *client, const struct StatsEntry *e)
312static int 310static int
313matches (const struct StatsEntry *e, const char *service, const char *name) 311matches (const struct StatsEntry *e, const char *service, const char *name)
314{ 312{
315 return ((0 == strlen (service)) || 313 return ((0 == strlen (service)) || (0 == strcmp (service, e->service))) &&
316 (0 == strcmp (service, e->service))) 314 ((0 == strlen (name)) || (0 == strcmp (name, e->name)));
317 && ((0 == strlen (name)) || (0 == strcmp (name, e->name)));
318} 315}
319 316
320 317
@@ -350,8 +347,7 @@ make_client_entry (struct GNUNET_SERVER_Client *client)
350 * GNUNET_SYSERR to close it (signal serious error) 347 * GNUNET_SYSERR to close it (signal serious error)
351 */ 348 */
352static void 349static void
353handle_get (void *cls, 350handle_get (void *cls, struct GNUNET_SERVER_Client *client,
354 struct GNUNET_SERVER_Client *client,
355 const struct GNUNET_MessageHeader *message) 351 const struct GNUNET_MessageHeader *message)
356{ 352{
357 struct GNUNET_MessageHeader end; 353 struct GNUNET_MessageHeader end;
@@ -363,8 +359,9 @@ handle_get (void *cls,
363 if (client != NULL) 359 if (client != NULL)
364 make_client_entry (client); 360 make_client_entry (client);
365 size = ntohs (message->size) - sizeof (struct GNUNET_MessageHeader); 361 size = ntohs (message->size) - sizeof (struct GNUNET_MessageHeader);
366 if (size != GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1], 362 if (size !=
367 size, 2, &service, &name)) 363 GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1], size, 2,
364 &service, &name))
368 { 365 {
369 GNUNET_break (0); 366 GNUNET_break (0);
370 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 367 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -407,9 +404,8 @@ notify_change (struct StatsEntry *se)
407 wvm.wid = htonl (pos->wid); 404 wvm.wid = htonl (pos->wid);
408 wvm.reserved = htonl (0); 405 wvm.reserved = htonl (0);
409 wvm.value = GNUNET_htonll (se->value); 406 wvm.value = GNUNET_htonll (se->value);
410 GNUNET_SERVER_notification_context_unicast (nc, 407 GNUNET_SERVER_notification_context_unicast (nc, pos->client, &wvm.header,
411 pos->client, 408 GNUNET_NO);
412 &wvm.header, GNUNET_NO);
413 pos->last_value = se->value; 409 pos->last_value = se->value;
414 } 410 }
415 pos = pos->next; 411 pos = pos->next;
@@ -424,8 +420,7 @@ notify_change (struct StatsEntry *se)
424 * @param message the actual message 420 * @param message the actual message
425 */ 421 */
426static void 422static void
427handle_set (void *cls, 423handle_set (void *cls, struct GNUNET_SERVER_Client *client,
428 struct GNUNET_SERVER_Client *client,
429 const struct GNUNET_MessageHeader *message) 424 const struct GNUNET_MessageHeader *message)
430{ 425{
431 char *service; 426 char *service;
@@ -452,8 +447,9 @@ handle_set (void *cls,
452 size = msize - sizeof (struct GNUNET_STATISTICS_SetMessage); 447 size = msize - sizeof (struct GNUNET_STATISTICS_SetMessage);
453 msg = (const struct GNUNET_STATISTICS_SetMessage *) message; 448 msg = (const struct GNUNET_STATISTICS_SetMessage *) message;
454 449
455 if (size != GNUNET_STRINGS_buffer_tokenize ((const char *) &msg[1], 450 if (size !=
456 size, 2, &service, &name)) 451 GNUNET_STRINGS_buffer_tokenize ((const char *) &msg[1], size, 2, &service,
452 &name))
457 { 453 {
458 GNUNET_break (0); 454 GNUNET_break (0);
459 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 455 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -504,8 +500,8 @@ handle_set (void *cls,
504 } 500 }
505#if DEBUG_STATISTICS 501#if DEBUG_STATISTICS
506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 502 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
507 "Statistic `%s:%s' updated to value %llu.\n", 503 "Statistic `%s:%s' updated to value %llu.\n", service, name,
508 service, name, pos->value); 504 pos->value);
509#endif 505#endif
510 if (changed) 506 if (changed)
511 notify_change (pos); 507 notify_change (pos);
@@ -530,8 +526,8 @@ handle_set (void *cls,
530 start = pos; 526 start = pos;
531#if DEBUG_STATISTICS 527#if DEBUG_STATISTICS
532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 528 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
533 "New statistic on `%s:%s' with value %llu created.\n", 529 "New statistic on `%s:%s' with value %llu created.\n", service,
534 service, name, pos->value); 530 name, pos->value);
535#endif 531#endif
536 GNUNET_SERVER_receive_done (client, GNUNET_OK); 532 GNUNET_SERVER_receive_done (client, GNUNET_OK);
537} 533}
@@ -545,8 +541,7 @@ handle_set (void *cls,
545 * @param message the actual message 541 * @param message the actual message
546 */ 542 */
547static void 543static void
548handle_watch (void *cls, 544handle_watch (void *cls, struct GNUNET_SERVER_Client *client,
549 struct GNUNET_SERVER_Client *client,
550 const struct GNUNET_MessageHeader *message) 545 const struct GNUNET_MessageHeader *message)
551{ 546{
552 char *service; 547 char *service;
@@ -567,8 +562,9 @@ handle_watch (void *cls,
567 return; 562 return;
568 } 563 }
569 size = msize - sizeof (struct GNUNET_MessageHeader); 564 size = msize - sizeof (struct GNUNET_MessageHeader);
570 if (size != GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1], 565 if (size !=
571 size, 2, &service, &name)) 566 GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1], size, 2,
567 &service, &name))
572 { 568 {
573 GNUNET_break (0); 569 GNUNET_break (0);
574 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 570 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -576,8 +572,8 @@ handle_watch (void *cls,
576 } 572 }
577#if DEBUG_STATISTICS 573#if DEBUG_STATISTICS
578 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
579 "Received request to watch statistic on `%s:%s'\n", 575 "Received request to watch statistic on `%s:%s'\n", service,
580 service, name); 576 name);
581#endif 577#endif
582 pos = start; 578 pos = start;
583 while (pos != NULL) 579 while (pos != NULL)
@@ -588,8 +584,9 @@ handle_watch (void *cls,
588 } 584 }
589 if (pos == NULL) 585 if (pos == NULL)
590 { 586 {
591 pos = GNUNET_malloc (sizeof (struct StatsEntry) + 587 pos =
592 sizeof (struct GNUNET_STATISTICS_SetMessage) + size); 588 GNUNET_malloc (sizeof (struct StatsEntry) +
589 sizeof (struct GNUNET_STATISTICS_SetMessage) + size);
593 pos->next = start; 590 pos->next = start;
594 pos->uid = uidgen++; 591 pos->uid = uidgen++;
595 pos->msg = (void *) &pos[1]; 592 pos->msg = (void *) &pos[1];
@@ -702,8 +699,7 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
702 * @param c configuration to use 699 * @param c configuration to use
703 */ 700 */
704static void 701static void
705run (void *cls, 702run (void *cls, struct GNUNET_SERVER_Handle *server,
706 struct GNUNET_SERVER_Handle *server,
707 const struct GNUNET_CONFIGURATION_Handle *c) 703 const struct GNUNET_CONFIGURATION_Handle *c)
708{ 704{
709 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 705 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
@@ -717,8 +713,8 @@ run (void *cls,
717 nc = GNUNET_SERVER_notification_context_create (server, 16); 713 nc = GNUNET_SERVER_notification_context_create (server, 16);
718 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); 714 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
719 load (server); 715 load (server);
720 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 716 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
721 &shutdown_task, NULL); 717 NULL);
722} 718}
723 719
724 720
@@ -733,9 +729,7 @@ int
733main (int argc, char *const *argv) 729main (int argc, char *const *argv)
734{ 730{
735 return (GNUNET_OK == 731 return (GNUNET_OK ==
736 GNUNET_SERVICE_run (argc, 732 GNUNET_SERVICE_run (argc, argv, "statistics",
737 argv,
738 "statistics",
739 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; 733 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
740} 734}
741 735
diff --git a/src/statistics/gnunet-statistics.c b/src/statistics/gnunet-statistics.c
index 5267e38cf..80488958f 100644
--- a/src/statistics/gnunet-statistics.c
+++ b/src/statistics/gnunet-statistics.c
@@ -63,14 +63,11 @@ static int persistent;
63 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration 63 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
64 */ 64 */
65static int 65static int
66printer (void *cls, 66printer (void *cls, const char *subsystem, const char *name, uint64_t value,
67 const char *subsystem, 67 int is_persistent)
68 const char *name, uint64_t value, int is_persistent)
69{ 68{
70 FPRINTF (stdout, 69 FPRINTF (stdout, "%s%-12s %-50s: %16llu\n", is_persistent ? "!" : " ",
71 "%s%-12s %-50s: %16llu\n", 70 subsystem, _(name), (unsigned long long) value);
72 is_persistent ? "!" : " ", subsystem, _(name),
73 (unsigned long long) value);
74 return GNUNET_OK; 71 return GNUNET_OK;
75} 72}
76 73
@@ -106,17 +103,16 @@ cleanup (void *cls, int success)
106 * @param cfg configuration 103 * @param cfg configuration
107 */ 104 */
108static void 105static void
109run (void *cls, 106run (void *cls, char *const *args, const char *cfgfile,
110 char *const *args, 107 const struct GNUNET_CONFIGURATION_Handle *cfg)
111 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
112{ 108{
113 struct GNUNET_STATISTICS_Handle *h; 109 struct GNUNET_STATISTICS_Handle *h;
114 unsigned long long val; 110 unsigned long long val;
115 111
116 if (args[0] != NULL) 112 if (args[0] != NULL)
117 { 113 {
118 if ((1 != SSCANF (args[0], "%llu", &val)) || 114 if ((1 != SSCANF (args[0], "%llu", &val)) || (subsystem == NULL) ||
119 (subsystem == NULL) || (name == NULL)) 115 (name == NULL))
120 { 116 {
121 FPRINTF (stderr, _("Invalid argument `%s'\n"), args[0]); 117 FPRINTF (stderr, _("Invalid argument `%s'\n"), args[0]);
122 ret = 1; 118 ret = 1;
@@ -138,9 +134,9 @@ run (void *cls,
138 ret = 1; 134 ret = 1;
139 return; 135 return;
140 } 136 }
141 if (NULL == GNUNET_STATISTICS_get (h, 137 if (NULL ==
142 subsystem, name, GET_TIMEOUT, &cleanup, 138 GNUNET_STATISTICS_get (h, subsystem, name, GET_TIMEOUT, &cleanup,
143 &printer, h)) 139 &printer, h))
144 cleanup (h, GNUNET_SYSERR); 140 cleanup (h, GNUNET_SYSERR);
145} 141}
146 142
@@ -167,9 +163,7 @@ main (int argc, char *const *argv)
167 GNUNET_GETOPT_OPTION_END 163 GNUNET_GETOPT_OPTION_END
168 }; 164 };
169 return (GNUNET_OK == 165 return (GNUNET_OK ==
170 GNUNET_PROGRAM_run (argc, 166 GNUNET_PROGRAM_run (argc, argv, "gnunet-statistics [options [value]]",
171 argv,
172 "gnunet-statistics [options [value]]",
173 gettext_noop 167 gettext_noop
174 ("Print statistics about GNUnet operations."), 168 ("Print statistics about GNUnet operations."),
175 options, &run, NULL)) ? ret : 1; 169 options, &run, NULL)) ? ret : 1;
diff --git a/src/statistics/statistics_api.c b/src/statistics/statistics_api.c
index a76f83db1..f4a71cc21 100644
--- a/src/statistics/statistics_api.c
+++ b/src/statistics/statistics_api.c
@@ -256,8 +256,8 @@ static void
256insert_ai (struct GNUNET_STATISTICS_Handle *h, 256insert_ai (struct GNUNET_STATISTICS_Handle *h,
257 struct GNUNET_STATISTICS_GetHandle *ai) 257 struct GNUNET_STATISTICS_GetHandle *ai)
258{ 258{
259 GNUNET_CONTAINER_DLL_insert_after (h->action_head, 259 GNUNET_CONTAINER_DLL_insert_after (h->action_head, h->action_tail,
260 h->action_tail, h->action_tail, ai); 260 h->action_tail, ai);
261 if (h->action_head == ai) 261 if (h->action_head == ai)
262 schedule_action (h); 262 schedule_action (h);
263} 263}
@@ -388,21 +388,20 @@ process_message (struct GNUNET_STATISTICS_Handle *h,
388 } 388 }
389 smsg = (const struct GNUNET_STATISTICS_ReplyMessage *) msg; 389 smsg = (const struct GNUNET_STATISTICS_ReplyMessage *) msg;
390 size -= sizeof (struct GNUNET_STATISTICS_ReplyMessage); 390 size -= sizeof (struct GNUNET_STATISTICS_ReplyMessage);
391 if (size != GNUNET_STRINGS_buffer_tokenize ((const char *) &smsg[1], 391 if (size !=
392 size, 2, &service, &name)) 392 GNUNET_STRINGS_buffer_tokenize ((const char *) &smsg[1], size, 2,
393 &service, &name))
393 { 394 {
394 GNUNET_break (0); 395 GNUNET_break (0);
395 return GNUNET_SYSERR; 396 return GNUNET_SYSERR;
396 } 397 }
397#if DEBUG_STATISTICS 398#if DEBUG_STATISTICS
398 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
399 "Received valid statistic on `%s:%s': %llu\n", 400 "Received valid statistic on `%s:%s': %llu\n", service, name,
400 service, name, GNUNET_ntohll (smsg->value)); 401 GNUNET_ntohll (smsg->value));
401#endif 402#endif
402 if (GNUNET_OK != 403 if (GNUNET_OK !=
403 h->current->proc (h->current->cls, 404 h->current->proc (h->current->cls, service, name,
404 service,
405 name,
406 GNUNET_ntohll (smsg->value), 405 GNUNET_ntohll (smsg->value),
407 0 != 406 0 !=
408 (ntohl (smsg->uid) & GNUNET_STATISTICS_PERSIST_BIT))) 407 (ntohl (smsg->uid) & GNUNET_STATISTICS_PERSIST_BIT)))
@@ -442,9 +441,7 @@ process_watch_value (struct GNUNET_STATISTICS_Handle *h,
442 return GNUNET_SYSERR; 441 return GNUNET_SYSERR;
443 } 442 }
444 w = h->watches[wid]; 443 w = h->watches[wid];
445 (void) w->proc (w->proc_cls, 444 (void) w->proc (w->proc_cls, w->subsystem, w->name,
446 w->subsystem,
447 w->name,
448 GNUNET_ntohll (wvm->value), 445 GNUNET_ntohll (wvm->value),
449 0 != (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT)); 446 0 != (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT));
450 return GNUNET_OK; 447 return GNUNET_OK;
@@ -485,8 +482,8 @@ receive_stats (void *cls, const struct GNUNET_MessageHeader *msg)
485 h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; 482 h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
486 if (h->watches_size > 0) 483 if (h->watches_size > 0)
487 { 484 {
488 GNUNET_CLIENT_receive (h->client, 485 GNUNET_CLIENT_receive (h->client, &receive_stats, h,
489 &receive_stats, h, GNUNET_TIME_UNIT_FOREVER_REL); 486 GNUNET_TIME_UNIT_FOREVER_REL);
490 } 487 }
491 else 488 else
492 { 489 {
@@ -502,11 +499,9 @@ receive_stats (void *cls, const struct GNUNET_MessageHeader *msg)
502 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 499 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
503 "Processing VALUE done, now reading more\n"); 500 "Processing VALUE done, now reading more\n");
504#endif 501#endif
505 GNUNET_CLIENT_receive (h->client, 502 GNUNET_CLIENT_receive (h->client, &receive_stats, h,
506 &receive_stats, 503 GNUNET_TIME_absolute_get_remaining (h->current->
507 h, 504 timeout));
508 GNUNET_TIME_absolute_get_remaining
509 (h->current->timeout));
510 h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; 505 h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
511 return; 506 return;
512 } 507 }
@@ -517,8 +512,8 @@ receive_stats (void *cls, const struct GNUNET_MessageHeader *msg)
517 { 512 {
518 h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; 513 h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
519 GNUNET_assert (h->watches_size > 0); 514 GNUNET_assert (h->watches_size > 0);
520 GNUNET_CLIENT_receive (h->client, 515 GNUNET_CLIENT_receive (h->client, &receive_stats, h,
521 &receive_stats, h, GNUNET_TIME_UNIT_FOREVER_REL); 516 GNUNET_TIME_UNIT_FOREVER_REL);
522 return; 517 return;
523 } 518 }
524 GNUNET_break (0); 519 GNUNET_break (0);
@@ -566,9 +561,7 @@ transmit_get (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf)
566 hdr->size = htons (msize); 561 hdr->size = htons (msize);
567 hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_GET); 562 hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_GET);
568 GNUNET_assert (slen1 + slen2 == 563 GNUNET_assert (slen1 + slen2 ==
569 GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], 564 GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], slen1 + slen2, 2,
570 slen1 + slen2,
571 2,
572 handle->current->subsystem, 565 handle->current->subsystem,
573 handle->current->name)); 566 handle->current->name));
574 if (!handle->receiving) 567 if (!handle->receiving)
@@ -578,11 +571,9 @@ transmit_get (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf)
578 "Transmission of GET done, now reading response\n"); 571 "Transmission of GET done, now reading response\n");
579#endif 572#endif
580 handle->receiving = GNUNET_YES; 573 handle->receiving = GNUNET_YES;
581 GNUNET_CLIENT_receive (handle->client, 574 GNUNET_CLIENT_receive (handle->client, &receive_stats, handle,
582 &receive_stats, 575 GNUNET_TIME_absolute_get_remaining (handle->current->
583 handle, 576 timeout));
584 GNUNET_TIME_absolute_get_remaining (handle->
585 current->timeout));
586 } 577 }
587 return msize; 578 return msize;
588} 579}
@@ -611,8 +602,8 @@ transmit_watch (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf)
611 return 0; 602 return 0;
612 } 603 }
613#if DEBUG_STATISTICS 604#if DEBUG_STATISTICS
614 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 605 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting watch request for `%s'\n",
615 "Transmitting watch request for `%s'\n", handle->current->name); 606 handle->current->name);
616#endif 607#endif
617 slen1 = strlen (handle->current->subsystem) + 1; 608 slen1 = strlen (handle->current->subsystem) + 1;
618 slen2 = strlen (handle->current->name) + 1; 609 slen2 = strlen (handle->current->name) + 1;
@@ -622,17 +613,14 @@ transmit_watch (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf)
622 hdr->size = htons (msize); 613 hdr->size = htons (msize);
623 hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_WATCH); 614 hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_WATCH);
624 GNUNET_assert (slen1 + slen2 == 615 GNUNET_assert (slen1 + slen2 ==
625 GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], 616 GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], slen1 + slen2, 2,
626 slen1 + slen2,
627 2,
628 handle->current->subsystem, 617 handle->current->subsystem,
629 handle->current->name)); 618 handle->current->name));
630 if (GNUNET_YES != handle->receiving) 619 if (GNUNET_YES != handle->receiving)
631 { 620 {
632 handle->receiving = GNUNET_YES; 621 handle->receiving = GNUNET_YES;
633 GNUNET_CLIENT_receive (handle->client, 622 GNUNET_CLIENT_receive (handle->client, &receive_stats, handle,
634 &receive_stats, 623 GNUNET_TIME_UNIT_FOREVER_REL);
635 handle, GNUNET_TIME_UNIT_FOREVER_REL);
636 } 624 }
637 finish (handle, GNUNET_OK); 625 finish (handle, GNUNET_OK);
638 return msize; 626 return msize;
@@ -675,9 +663,7 @@ transmit_set (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf)
675 if (handle->current->type == ACTION_UPDATE) 663 if (handle->current->type == ACTION_UPDATE)
676 r->flags |= htonl (GNUNET_STATISTICS_SETFLAG_RELATIVE); 664 r->flags |= htonl (GNUNET_STATISTICS_SETFLAG_RELATIVE);
677 GNUNET_assert (slen + nlen == 665 GNUNET_assert (slen + nlen ==
678 GNUNET_STRINGS_buffer_fill ((char *) &r[1], 666 GNUNET_STRINGS_buffer_fill ((char *) &r[1], slen + nlen, 2,
679 slen + nlen,
680 2,
681 handle->current->subsystem, 667 handle->current->subsystem,
682 handle->current->name)); 668 handle->current->name));
683 finish (handle, GNUNET_OK); 669 finish (handle, GNUNET_OK);
@@ -809,11 +795,10 @@ GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, int sync_first)
809 if ((h->current != NULL) && (h->th == NULL)) 795 if ((h->current != NULL) && (h->th == NULL))
810 { 796 {
811 timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout); 797 timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout);
812 h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, 798 h->th =
813 h->current->msize, 799 GNUNET_CLIENT_notify_transmit_ready (h->client, h->current->msize,
814 timeout, 800 timeout, GNUNET_YES,
815 GNUNET_YES, 801 &transmit_action, h);
816 &transmit_action, h);
817 GNUNET_assert (NULL != h->th); 802 GNUNET_assert (NULL != h->th);
818 } 803 }
819 if (h->th != NULL) 804 if (h->th != NULL)
@@ -870,11 +855,11 @@ schedule_action (struct GNUNET_STATISTICS_Handle *h)
870 return; /* action already pending */ 855 return; /* action already pending */
871 if (GNUNET_YES != try_connect (h)) 856 if (GNUNET_YES != try_connect (h))
872 { 857 {
873 h->backoff_task = GNUNET_SCHEDULER_add_delayed (h->backoff, 858 h->backoff_task =
874 &finish_task, h); 859 GNUNET_SCHEDULER_add_delayed (h->backoff, &finish_task, h);
875 h->backoff = GNUNET_TIME_relative_multiply (h->backoff, 2); 860 h->backoff = GNUNET_TIME_relative_multiply (h->backoff, 2);
876 h->backoff = GNUNET_TIME_relative_min (h->backoff, 861 h->backoff =
877 GNUNET_CONSTANTS_SERVICE_TIMEOUT); 862 GNUNET_TIME_relative_min (h->backoff, GNUNET_CONSTANTS_SERVICE_TIMEOUT);
878 return; 863 return;
879 } 864 }
880 865
@@ -892,11 +877,10 @@ schedule_action (struct GNUNET_STATISTICS_Handle *h)
892 GNUNET_CONTAINER_DLL_remove (h->action_head, h->action_tail, h->current); 877 GNUNET_CONTAINER_DLL_remove (h->action_head, h->action_tail, h->current);
893 timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout); 878 timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout);
894 if (NULL == 879 if (NULL ==
895 (h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, 880 (h->th =
896 h->current->msize, 881 GNUNET_CLIENT_notify_transmit_ready (h->client, h->current->msize,
897 timeout, 882 timeout, GNUNET_YES,
898 GNUNET_YES, 883 &transmit_action, h)))
899 &transmit_action, h)))
900 { 884 {
901#if DEBUG_STATISTICS 885#if DEBUG_STATISTICS
902 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 886 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -922,8 +906,7 @@ schedule_action (struct GNUNET_STATISTICS_Handle *h)
922 */ 906 */
923struct GNUNET_STATISTICS_GetHandle * 907struct GNUNET_STATISTICS_GetHandle *
924GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, 908GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle,
925 const char *subsystem, 909 const char *subsystem, const char *name,
926 const char *name,
927 struct GNUNET_TIME_Relative timeout, 910 struct GNUNET_TIME_Relative timeout,
928 GNUNET_STATISTICS_Callback cont, 911 GNUNET_STATISTICS_Callback cont,
929 GNUNET_STATISTICS_Iterator proc, void *cls) 912 GNUNET_STATISTICS_Iterator proc, void *cls)
@@ -1005,8 +988,7 @@ GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh)
1005 */ 988 */
1006int 989int
1007GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle, 990GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle,
1008 const char *subsystem, 991 const char *subsystem, const char *name,
1009 const char *name,
1010 GNUNET_STATISTICS_Iterator proc, void *proc_cls) 992 GNUNET_STATISTICS_Iterator proc, void *proc_cls)
1011{ 993{
1012 struct GNUNET_STATISTICS_WatchEntry *w; 994 struct GNUNET_STATISTICS_WatchEntry *w;
@@ -1025,8 +1007,7 @@ GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle,
1025 1007
1026 1008
1027static void 1009static void
1028add_setter_action (struct GNUNET_STATISTICS_Handle *h, 1010add_setter_action (struct GNUNET_STATISTICS_Handle *h, const char *name,
1029 const char *name,
1030 int make_persistent, uint64_t value, enum ActionType type) 1011 int make_persistent, uint64_t value, enum ActionType type)
1031{ 1012{
1032 struct GNUNET_STATISTICS_GetHandle *ai; 1013 struct GNUNET_STATISTICS_GetHandle *ai;
@@ -1051,8 +1032,8 @@ add_setter_action (struct GNUNET_STATISTICS_Handle *h,
1051 while (ai != NULL) 1032 while (ai != NULL)
1052 { 1033 {
1053 if ((0 == strcmp (ai->subsystem, h->subsystem)) && 1034 if ((0 == strcmp (ai->subsystem, h->subsystem)) &&
1054 (0 == strcmp (ai->name, name)) && 1035 (0 == strcmp (ai->name, name)) && ((ai->type == ACTION_UPDATE) ||
1055 ((ai->type == ACTION_UPDATE) || (ai->type == ACTION_SET))) 1036 (ai->type == ACTION_SET)))
1056 { 1037 {
1057 if (ai->type == ACTION_SET) 1038 if (ai->type == ACTION_SET)
1058 { 1039 {
@@ -1146,8 +1127,8 @@ GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle,
1146 if (delta == 0) 1127 if (delta == 0)
1147 return; 1128 return;
1148 GNUNET_assert (GNUNET_NO == handle->do_destroy); 1129 GNUNET_assert (GNUNET_NO == handle->do_destroy);
1149 add_setter_action (handle, name, make_persistent, 1130 add_setter_action (handle, name, make_persistent, (uint64_t) delta,
1150 (uint64_t) delta, ACTION_UPDATE); 1131 ACTION_UPDATE);
1151} 1132}
1152 1133
1153 1134
diff --git a/src/statistics/test_statistics_api.c b/src/statistics/test_statistics_api.c
index de05d6c69..39a71a79e 100644
--- a/src/statistics/test_statistics_api.c
+++ b/src/statistics/test_statistics_api.c
@@ -34,12 +34,10 @@
34#define START_SERVICE GNUNET_YES 34#define START_SERVICE GNUNET_YES
35 35
36static int 36static int
37check_1 (void *cls, 37check_1 (void *cls, const char *subsystem, const char *name, uint64_t value,
38 const char *subsystem, 38 int is_persistent)
39 const char *name, uint64_t value, int is_persistent)
40{ 39{
41 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 40 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received value %llu for `%s:%s\n",
42 "Received value %llu for `%s:%s\n",
43 (unsigned long long) value, subsystem, name); 41 (unsigned long long) value, subsystem, name);
44 GNUNET_assert (0 == strcmp (name, "test-1")); 42 GNUNET_assert (0 == strcmp (name, "test-1"));
45 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api")); 43 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
@@ -49,12 +47,10 @@ check_1 (void *cls,
49} 47}
50 48
51static int 49static int
52check_2 (void *cls, 50check_2 (void *cls, const char *subsystem, const char *name, uint64_t value,
53 const char *subsystem, 51 int is_persistent)
54 const char *name, uint64_t value, int is_persistent)
55{ 52{
56 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 53 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received value %llu for `%s:%s\n",
57 "Received value %llu for `%s:%s\n",
58 (unsigned long long) value, subsystem, name); 54 (unsigned long long) value, subsystem, name);
59 GNUNET_assert (0 == strcmp (name, "test-2")); 55 GNUNET_assert (0 == strcmp (name, "test-2"));
60 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api")); 56 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
@@ -64,12 +60,10 @@ check_2 (void *cls,
64} 60}
65 61
66static int 62static int
67check_3 (void *cls, 63check_3 (void *cls, const char *subsystem, const char *name, uint64_t value,
68 const char *subsystem, 64 int is_persistent)
69 const char *name, uint64_t value, int is_persistent)
70{ 65{
71 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 66 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received value %llu for `%s:%s\n",
72 "Received value %llu for `%s:%s\n",
73 (unsigned long long) value, subsystem, name); 67 (unsigned long long) value, subsystem, name);
74 GNUNET_assert (0 == strcmp (name, "test-3")); 68 GNUNET_assert (0 == strcmp (name, "test-3"));
75 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api")); 69 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
@@ -102,9 +96,8 @@ next (void *cls, int success)
102} 96}
103 97
104static void 98static void
105run (void *cls, 99run (void *cls, char *const *args, const char *cfgfile,
106 char *const *args, 100 const struct GNUNET_CONFIGURATION_Handle *cfg)
107 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
108{ 101{
109 h = GNUNET_STATISTICS_create ("test-statistics-api", cfg); 102 h = GNUNET_STATISTICS_create ("test-statistics-api", cfg);
110 GNUNET_STATISTICS_set (h, "test-1", 1, GNUNET_NO); 103 GNUNET_STATISTICS_set (h, "test-1", 1, GNUNET_NO);
@@ -119,9 +112,8 @@ run (void *cls,
119} 112}
120 113
121static void 114static void
122run_more (void *cls, 115run_more (void *cls, char *const *args, const char *cfgfile,
123 char *const *args, 116 const struct GNUNET_CONFIGURATION_Handle *cfg)
124 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
125{ 117{
126 h = GNUNET_STATISTICS_create ("test-statistics-api", cfg); 118 h = GNUNET_STATISTICS_create ("test-statistics-api", cfg);
127 GNUNET_break (NULL != 119 GNUNET_break (NULL !=
@@ -151,16 +143,17 @@ check ()
151#if START_SERVICE 143#if START_SERVICE
152 struct GNUNET_OS_Process *proc; 144 struct GNUNET_OS_Process *proc;
153 145
154 proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics", 146 proc =
155 "gnunet-service-statistics", 147 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics",
148 "gnunet-service-statistics",
156#if DEBUG_STATISTICS 149#if DEBUG_STATISTICS
157 "-L", "DEBUG", 150 "-L", "DEBUG",
158#endif 151#endif
159 "-c", "test_statistics_api_data.conf", NULL); 152 "-c", "test_statistics_api_data.conf", NULL);
160#endif 153#endif
161 GNUNET_assert (NULL != proc); 154 GNUNET_assert (NULL != proc);
162 GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp", 155 GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp", options, &run,
163 options, &run, &ok); 156 &ok);
164#if START_SERVICE 157#if START_SERVICE
165 if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) 158 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
166 { 159 {
@@ -176,15 +169,16 @@ check ()
176 ok = 1; 169 ok = 1;
177#if START_SERVICE 170#if START_SERVICE
178 /* restart to check persistence! */ 171 /* restart to check persistence! */
179 proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics", 172 proc =
180 "gnunet-service-statistics", 173 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics",
174 "gnunet-service-statistics",
181#if DEBUG_STATISTICS 175#if DEBUG_STATISTICS
182 "-L", "DEBUG", 176 "-L", "DEBUG",
183#endif 177#endif
184 "-c", "test_statistics_api_data.conf", NULL); 178 "-c", "test_statistics_api_data.conf", NULL);
185#endif 179#endif
186 GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp", 180 GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp", options,
187 options, &run_more, &ok); 181 &run_more, &ok);
188#if START_SERVICE 182#if START_SERVICE
189 if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) 183 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
190 { 184 {
diff --git a/src/statistics/test_statistics_api_loop.c b/src/statistics/test_statistics_api_loop.c
index 87190a99a..eb739b752 100644
--- a/src/statistics/test_statistics_api_loop.c
+++ b/src/statistics/test_statistics_api_loop.c
@@ -36,9 +36,8 @@
36#define ROUNDS (1024 * 1024) 36#define ROUNDS (1024 * 1024)
37 37
38static int 38static int
39check_1 (void *cls, 39check_1 (void *cls, const char *subsystem, const char *name, uint64_t value,
40 const char *subsystem, 40 int is_persistent)
41 const char *name, uint64_t value, int is_persistent)
42{ 41{
43 GNUNET_assert (0 == strcmp (name, "test-0")); 42 GNUNET_assert (0 == strcmp (name, "test-0"));
44 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api-loop")); 43 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api-loop"));
@@ -59,9 +58,8 @@ next (void *cls, int success)
59} 58}
60 59
61static void 60static void
62run (void *cls, 61run (void *cls, char *const *args, const char *cfgfile,
63 char *const *args, 62 const struct GNUNET_CONFIGURATION_Handle *cfg)
64 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
65{ 63{
66 int i; 64 int i;
67 char name[128]; 65 char name[128];
@@ -98,16 +96,17 @@ check ()
98#if START_SERVICE 96#if START_SERVICE
99 struct GNUNET_OS_Process *proc; 97 struct GNUNET_OS_Process *proc;
100 98
101 proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics", 99 proc =
102 "gnunet-service-statistics", 100 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics",
101 "gnunet-service-statistics",
103#if DEBUG_STATISTICS 102#if DEBUG_STATISTICS
104 "-L", "DEBUG", 103 "-L", "DEBUG",
105#endif 104#endif
106 "-c", "test_statistics_api_data.conf", NULL); 105 "-c", "test_statistics_api_data.conf", NULL);
107#endif 106#endif
108 GNUNET_assert (NULL != proc); 107 GNUNET_assert (NULL != proc);
109 GNUNET_PROGRAM_run (3, argv, "test-statistics-api", "nohelp", 108 GNUNET_PROGRAM_run (3, argv, "test-statistics-api", "nohelp", options, &run,
110 options, &run, &ok); 109 &ok);
111#if START_SERVICE 110#if START_SERVICE
112 if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) 111 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
113 { 112 {
diff --git a/src/statistics/test_statistics_api_watch.c b/src/statistics/test_statistics_api_watch.c
index 72cb27ecf..cea495836 100644
--- a/src/statistics/test_statistics_api_watch.c
+++ b/src/statistics/test_statistics_api_watch.c
@@ -63,9 +63,8 @@ normal_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
63 63
64 64
65static int 65static int
66watch_1 (void *cls, 66watch_1 (void *cls, const char *subsystem, const char *name, uint64_t value,
67 const char *subsystem, 67 int is_persistent)
68 const char *name, uint64_t value, int is_persistent)
69{ 68{
70 GNUNET_assert (value == 42); 69 GNUNET_assert (value == 42);
71 GNUNET_assert (0 == strcmp (name, "test-1")); 70 GNUNET_assert (0 == strcmp (name, "test-1"));
@@ -80,9 +79,8 @@ watch_1 (void *cls,
80 79
81 80
82static int 81static int
83watch_2 (void *cls, 82watch_2 (void *cls, const char *subsystem, const char *name, uint64_t value,
84 const char *subsystem, 83 int is_persistent)
85 const char *name, uint64_t value, int is_persistent)
86{ 84{
87 GNUNET_assert (value == 43); 85 GNUNET_assert (value == 43);
88 GNUNET_assert (0 == strcmp (name, "test-2")); 86 GNUNET_assert (0 == strcmp (name, "test-2"));
@@ -97,24 +95,22 @@ watch_2 (void *cls,
97 95
98 96
99static void 97static void
100run (void *cls, 98run (void *cls, char *const *args, const char *cfgfile,
101 char *const *args, 99 const struct GNUNET_CONFIGURATION_Handle *cfg)
102 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
103{ 100{
104 h = GNUNET_STATISTICS_create ("dummy", cfg); 101 h = GNUNET_STATISTICS_create ("dummy", cfg);
105 GNUNET_assert (GNUNET_OK == 102 GNUNET_assert (GNUNET_OK ==
106 GNUNET_STATISTICS_watch (h, 103 GNUNET_STATISTICS_watch (h, "test-statistics-api-watch",
107 "test-statistics-api-watch",
108 "test-1", &watch_1, NULL)); 104 "test-1", &watch_1, NULL));
109 GNUNET_assert (GNUNET_OK == 105 GNUNET_assert (GNUNET_OK ==
110 GNUNET_STATISTICS_watch (h, 106 GNUNET_STATISTICS_watch (h, "test-statistics-api-watch",
111 "test-statistics-api-watch",
112 "test-2", &watch_2, NULL)); 107 "test-2", &watch_2, NULL));
113 h2 = GNUNET_STATISTICS_create ("test-statistics-api-watch", cfg); 108 h2 = GNUNET_STATISTICS_create ("test-statistics-api-watch", cfg);
114 GNUNET_STATISTICS_set (h2, "test-1", 42, GNUNET_NO); 109 GNUNET_STATISTICS_set (h2, "test-1", 42, GNUNET_NO);
115 GNUNET_STATISTICS_set (h2, "test-2", 43, GNUNET_NO); 110 GNUNET_STATISTICS_set (h2, "test-2", 43, GNUNET_NO);
116 shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 111 shutdown_task =
117 &force_shutdown, NULL); 112 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &force_shutdown,
113 NULL);
118} 114}
119 115
120 116
@@ -132,17 +128,18 @@ check ()
132#if START_SERVICE 128#if START_SERVICE
133 struct GNUNET_OS_Process *proc; 129 struct GNUNET_OS_Process *proc;
134 130
135 proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics", 131 proc =
136 "gnunet-service-statistics", 132 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics",
133 "gnunet-service-statistics",
137#if VERBOSE 134#if VERBOSE
138 "-L", "DEBUG", 135 "-L", "DEBUG",
139#endif 136#endif
140 "-c", "test_statistics_api_data.conf", NULL); 137 "-c", "test_statistics_api_data.conf", NULL);
141#endif 138#endif
142 GNUNET_assert (NULL != proc); 139 GNUNET_assert (NULL != proc);
143 ok = 3; 140 ok = 3;
144 GNUNET_PROGRAM_run (3, argv, "test-statistics-api", "nohelp", 141 GNUNET_PROGRAM_run (3, argv, "test-statistics-api", "nohelp", options, &run,
145 options, &run, NULL); 142 NULL);
146#if START_SERVICE 143#if START_SERVICE
147 if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) 144 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
148 { 145 {
diff --git a/src/template/gnunet-service-template.c b/src/template/gnunet-service-template.c
index 8ee88c961..54b7ecc94 100644
--- a/src/template/gnunet-service-template.c
+++ b/src/template/gnunet-service-template.c
@@ -49,8 +49,7 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
49 * @param cfg configuration to use 49 * @param cfg configuration to use
50 */ 50 */
51static void 51static void
52run (void *cls, 52run (void *cls, struct GNUNET_SERVER_Handle *server,
53 struct GNUNET_SERVER_Handle *server,
54 const struct GNUNET_CONFIGURATION_Handle *cfg) 53 const struct GNUNET_CONFIGURATION_Handle *cfg)
55{ 54{
56 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 55 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
@@ -59,8 +58,8 @@ run (void *cls,
59 }; 58 };
60 /* FIXME: do setup here */ 59 /* FIXME: do setup here */
61 GNUNET_SERVER_add_handlers (server, handlers); 60 GNUNET_SERVER_add_handlers (server, handlers);
62 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 61 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
63 &cleanup_task, NULL); 62 NULL);
64} 63}
65 64
66 65
@@ -75,9 +74,7 @@ int
75main (int argc, char *const *argv) 74main (int argc, char *const *argv)
76{ 75{
77 return (GNUNET_OK == 76 return (GNUNET_OK ==
78 GNUNET_SERVICE_run (argc, 77 GNUNET_SERVICE_run (argc, argv, "template",
79 argv,
80 "template",
81 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; 78 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
82} 79}
83 80
diff --git a/src/template/gnunet-template.c b/src/template/gnunet-template.c
index 657b3d4ce..7b1d9dfff 100644
--- a/src/template/gnunet-template.c
+++ b/src/template/gnunet-template.c
@@ -42,9 +42,8 @@ static int ret;
42 * @param cfg configuration 42 * @param cfg configuration
43 */ 43 */
44static void 44static void
45run (void *cls, 45run (void *cls, char *const *args, const char *cfgfile,
46 char *const *args, 46 const struct GNUNET_CONFIGURATION_Handle *cfg)
47 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
48{ 47{
49 /* main code here */ 48 /* main code here */
50} 49}
@@ -65,11 +64,9 @@ main (int argc, char *const *argv)
65 GNUNET_GETOPT_OPTION_END 64 GNUNET_GETOPT_OPTION_END
66 }; 65 };
67 return (GNUNET_OK == 66 return (GNUNET_OK ==
68 GNUNET_PROGRAM_run (argc, 67 GNUNET_PROGRAM_run (argc, argv, "gnunet-template",
69 argv, 68 gettext_noop ("help text"), options, &run,
70 "gnunet-template", 69 NULL)) ? ret : 1;
71 gettext_noop ("help text"),
72 options, &run, NULL)) ? ret : 1;
73} 70}
74 71
75/* end of gnunet-template.c */ 72/* end of gnunet-template.c */
diff --git a/src/testing/test_testing.c b/src/testing/test_testing.c
index 88861a156..3e2cd65ee 100644
--- a/src/testing/test_testing.c
+++ b/src/testing/test_testing.c
@@ -59,8 +59,7 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
59 59
60 60
61static void 61static void
62my_cb (void *cls, 62my_cb (void *cls, const struct GNUNET_PeerIdentity *id,
63 const struct GNUNET_PeerIdentity *id,
64 const struct GNUNET_CONFIGURATION_Handle *cfg, 63 const struct GNUNET_CONFIGURATION_Handle *cfg,
65 struct GNUNET_TESTING_Daemon *d, const char *emsg) 64 struct GNUNET_TESTING_Daemon *d, const char *emsg)
66{ 65{
@@ -74,9 +73,8 @@ my_cb (void *cls,
74 73
75 74
76static void 75static void
77run (void *cls, 76run (void *cls, char *const *args, const char *cfgfile,
78 char *const *args, 77 const struct GNUNET_CONFIGURATION_Handle *cfg)
79 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
80{ 78{
81 struct GNUNET_TESTING_Daemon *d; 79 struct GNUNET_TESTING_Daemon *d;
82 80
@@ -103,8 +101,8 @@ check ()
103 struct GNUNET_GETOPT_CommandLineOption options[] = { 101 struct GNUNET_GETOPT_CommandLineOption options[] = {
104 GNUNET_GETOPT_OPTION_END 102 GNUNET_GETOPT_OPTION_END
105 }; 103 };
106 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 104 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
107 argv, "test-testing", "nohelp", options, &run, &ok); 105 "test-testing", "nohelp", options, &run, &ok);
108 return ok; 106 return ok;
109} 107}
110 108
diff --git a/src/testing/test_testing_connect.c b/src/testing/test_testing_connect.c
index 19e3bb1c0..4fe3a1dd6 100644
--- a/src/testing/test_testing_connect.c
+++ b/src/testing/test_testing_connect.c
@@ -90,8 +90,7 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
90} 90}
91 91
92static void 92static void
93my_connect_complete (void *cls, 93my_connect_complete (void *cls, const struct GNUNET_PeerIdentity *first,
94 const struct GNUNET_PeerIdentity *first,
95 const struct GNUNET_PeerIdentity *second, 94 const struct GNUNET_PeerIdentity *second,
96 unsigned int distance, 95 unsigned int distance,
97 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 96 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
@@ -105,32 +104,29 @@ my_connect_complete (void *cls,
105 104
106 105
107static void 106static void
108my_cb2 (void *cls, 107my_cb2 (void *cls, const struct GNUNET_PeerIdentity *id,
109 const struct GNUNET_PeerIdentity *id,
110 const struct GNUNET_CONFIGURATION_Handle *cfg, 108 const struct GNUNET_CONFIGURATION_Handle *cfg,
111 struct GNUNET_TESTING_Daemon *d, const char *emsg) 109 struct GNUNET_TESTING_Daemon *d, const char *emsg)
112{ 110{
113 GNUNET_assert (id != NULL); 111 GNUNET_assert (id != NULL);
114#if VERBOSE 112#if VERBOSE
115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Daemon `%s' started.\n",
116 "Daemon `%s' started.\n", GNUNET_i2s (id)); 114 GNUNET_i2s (id));
117#endif 115#endif
118 GNUNET_TESTING_daemons_connect (d1, d2, 116 GNUNET_TESTING_daemons_connect (d1, d2, TIMEOUT, CONNECT_ATTEMPTS, GNUNET_YES,
119 TIMEOUT, CONNECT_ATTEMPTS, 117 &my_connect_complete, NULL);
120 GNUNET_YES, &my_connect_complete, NULL);
121} 118}
122 119
123 120
124static void 121static void
125my_cb1 (void *cls, 122my_cb1 (void *cls, const struct GNUNET_PeerIdentity *id,
126 const struct GNUNET_PeerIdentity *id,
127 const struct GNUNET_CONFIGURATION_Handle *cfg, 123 const struct GNUNET_CONFIGURATION_Handle *cfg,
128 struct GNUNET_TESTING_Daemon *d, const char *emsg) 124 struct GNUNET_TESTING_Daemon *d, const char *emsg)
129{ 125{
130 GNUNET_assert (id != NULL); 126 GNUNET_assert (id != NULL);
131#if VERBOSE 127#if VERBOSE
132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Daemon `%s' started.\n",
133 "Daemon `%s' started.\n", GNUNET_i2s (id)); 129 GNUNET_i2s (id));
134#endif 130#endif
135 d2 = GNUNET_TESTING_daemon_start (c2, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL, 131 d2 = GNUNET_TESTING_daemon_start (c2, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL,
136 NULL, NULL, &my_cb2, NULL); 132 NULL, NULL, &my_cb2, NULL);
@@ -140,9 +136,8 @@ my_cb1 (void *cls,
140 136
141 137
142static void 138static void
143run (void *cls, 139run (void *cls, char *const *args, const char *cfgfile,
144 char *const *args, 140 const struct GNUNET_CONFIGURATION_Handle *cfg)
145 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
146{ 141{
147 ok = 1; 142 ok = 1;
148#if VERBOSE 143#if VERBOSE
@@ -171,9 +166,8 @@ check ()
171 struct GNUNET_GETOPT_CommandLineOption options[] = { 166 struct GNUNET_GETOPT_CommandLineOption options[] = {
172 GNUNET_GETOPT_OPTION_END 167 GNUNET_GETOPT_OPTION_END
173 }; 168 };
174 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 169 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
175 argv, "test-testing-connect", "nohelp", 170 "test-testing-connect", "nohelp", options, &run, &ok);
176 options, &run, &ok);
177 return ok; 171 return ok;
178} 172}
179 173
diff --git a/src/testing/test_testing_group.c b/src/testing/test_testing_group.c
index 88893f45d..f5df45b19 100644
--- a/src/testing/test_testing_group.c
+++ b/src/testing/test_testing_group.c
@@ -65,8 +65,7 @@ shutdown_callback (void *cls, const char *emsg)
65 65
66 66
67static void 67static void
68my_cb (void *cls, 68my_cb (void *cls, const struct GNUNET_PeerIdentity *id,
69 const struct GNUNET_PeerIdentity *id,
70 const struct GNUNET_CONFIGURATION_Handle *cfg, 69 const struct GNUNET_CONFIGURATION_Handle *cfg,
71 struct GNUNET_TESTING_Daemon *d, const char *emsg) 70 struct GNUNET_TESTING_Daemon *d, const char *emsg)
72{ 71{
@@ -105,9 +104,8 @@ my_cb (void *cls,
105 104
106 105
107static void 106static void
108run (void *cls, 107run (void *cls, char *const *args, const char *cfgfile,
109 char *const *args, 108 const struct GNUNET_CONFIGURATION_Handle *cfg)
110 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
111{ 109{
112 ok = 1; 110 ok = 1;
113#if VERBOSE 111#if VERBOSE
@@ -117,9 +115,8 @@ run (void *cls,
117 pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of peers */ 115 pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of peers */
118 peers_left, /* Number of outstanding connections */ 116 peers_left, /* Number of outstanding connections */
119 peers_left, /* Number of parallel ssh connections, or peers being started at once */ 117 peers_left, /* Number of parallel ssh connections, or peers being started at once */
120 TIMEOUT, 118 TIMEOUT, NULL, NULL, &my_cb, NULL, NULL,
121 NULL, NULL, 119 NULL, NULL);
122 &my_cb, NULL, NULL, NULL, NULL);
123 GNUNET_assert (pg != NULL); 120 GNUNET_assert (pg != NULL);
124} 121}
125 122
@@ -137,8 +134,8 @@ check ()
137 struct GNUNET_GETOPT_CommandLineOption options[] = { 134 struct GNUNET_GETOPT_CommandLineOption options[] = {
138 GNUNET_GETOPT_OPTION_END 135 GNUNET_GETOPT_OPTION_END
139 }; 136 };
140 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 137 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
141 argv, "test-testing-group", "nohelp", options, &run, &ok); 138 "test-testing-group", "nohelp", options, &run, &ok);
142 return ok; 139 return ok;
143} 140}
144 141
diff --git a/src/testing/test_testing_group_remote.c b/src/testing/test_testing_group_remote.c
index d43e7ed57..e300f95e3 100644
--- a/src/testing/test_testing_group_remote.c
+++ b/src/testing/test_testing_group_remote.c
@@ -72,8 +72,7 @@ shutdown_callback (void *cls, const char *emsg)
72 72
73 73
74static void 74static void
75my_cb (void *cls, 75my_cb (void *cls, const struct GNUNET_PeerIdentity *id,
76 const struct GNUNET_PeerIdentity *id,
77 const struct GNUNET_CONFIGURATION_Handle *cfg, 76 const struct GNUNET_CONFIGURATION_Handle *cfg,
78 struct GNUNET_TESTING_Daemon *d, const char *emsg) 77 struct GNUNET_TESTING_Daemon *d, const char *emsg)
79{ 78{
@@ -98,9 +97,8 @@ my_cb (void *cls,
98 97
99 98
100static void 99static void
101run (void *cls, 100run (void *cls, char *const *args, const char *cfgfile,
102 char *const *args, 101 const struct GNUNET_CONFIGURATION_Handle *cfg)
103 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
104{ 102{
105 struct GNUNET_TESTING_Host *hosts; 103 struct GNUNET_TESTING_Host *hosts;
106 struct GNUNET_TESTING_Host *hostpos; 104 struct GNUNET_TESTING_Host *hostpos;
@@ -133,8 +131,9 @@ run (void *cls,
133 if (hostfile != NULL) 131 if (hostfile != NULL)
134 { 132 {
135 if (GNUNET_OK != GNUNET_DISK_file_test (hostfile)) 133 if (GNUNET_OK != GNUNET_DISK_file_test (hostfile))
136 GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ 134 GNUNET_DISK_fn_write (hostfile, NULL, 0,
137 | GNUNET_DISK_PERM_USER_WRITE); 135 GNUNET_DISK_PERM_USER_READ |
136 GNUNET_DISK_PERM_USER_WRITE);
138 if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0)) 137 if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0))
139 { 138 {
140 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 139 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -202,9 +201,8 @@ run (void *cls,
202 pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of peers */ 201 pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of peers */
203 peers_left, /* Number of outstanding connections */ 202 peers_left, /* Number of outstanding connections */
204 peers_left, /* Number of parallel ssh connections, or peers being started at once */ 203 peers_left, /* Number of parallel ssh connections, or peers being started at once */
205 TIMEOUT, 204 TIMEOUT, NULL, NULL, &my_cb, NULL, NULL,
206 NULL, 205 NULL, hosts);
207 NULL, &my_cb, NULL, NULL, NULL, hosts);
208 hostpos = hosts; 206 hostpos = hosts;
209 while (hostpos != NULL) 207 while (hostpos != NULL)
210 { 208 {
@@ -233,8 +231,8 @@ check ()
233 struct GNUNET_GETOPT_CommandLineOption options[] = { 231 struct GNUNET_GETOPT_CommandLineOption options[] = {
234 GNUNET_GETOPT_OPTION_END 232 GNUNET_GETOPT_OPTION_END
235 }; 233 };
236 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 234 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
237 argv, "test-testing-group", "nohelp", options, &run, &ok); 235 "test-testing-group", "nohelp", options, &run, &ok);
238 return ok; 236 return ok;
239} 237}
240 238
diff --git a/src/testing/test_testing_large_topology.c b/src/testing/test_testing_large_topology.c
index 62922e9e8..9581dc9b2 100644
--- a/src/testing/test_testing_large_topology.c
+++ b/src/testing/test_testing_large_topology.c
@@ -185,9 +185,9 @@ gather_log_data ()
185 185
186 GNUNET_asprintf (&peer_number, "%llu", num_peers); 186 GNUNET_asprintf (&peer_number, "%llu", num_peers);
187 GNUNET_asprintf (&connect_number, "%llu", expected_connections); 187 GNUNET_asprintf (&connect_number, "%llu", expected_connections);
188 mem_process = GNUNET_OS_start_process (NULL, NULL, "./memsize.pl", 188 mem_process =
189 "memsize.pl", "totals.txt", 189 GNUNET_OS_start_process (NULL, NULL, "./memsize.pl", "memsize.pl",
190 peer_number, connect_number, NULL); 190 "totals.txt", peer_number, connect_number, NULL);
191 GNUNET_OS_process_wait (mem_process); 191 GNUNET_OS_process_wait (mem_process);
192 GNUNET_OS_process_close (mem_process); 192 GNUNET_OS_process_close (mem_process);
193 mem_process = NULL; 193 mem_process = NULL;
@@ -257,15 +257,13 @@ disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
257 257
258 /* Disconnect from the respective cores */ 258 /* Disconnect from the respective cores */
259#if VERBOSE > 1 259#if VERBOSE > 1
260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from peer 1 `%4s'\n",
261 "Disconnecting from peer 1 `%4s'\n",
262 GNUNET_i2s (&pos->peer1->id)); 261 GNUNET_i2s (&pos->peer1->id));
263#endif 262#endif
264 if (pos->peer1handle != NULL) 263 if (pos->peer1handle != NULL)
265 GNUNET_CORE_disconnect (pos->peer1handle); 264 GNUNET_CORE_disconnect (pos->peer1handle);
266#if VERBOSE > 1 265#if VERBOSE > 1
267 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 266 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from peer 2 `%4s'\n",
268 "Disconnecting from peer 2 `%4s'\n",
269 GNUNET_i2s (&pos->peer2->id)); 267 GNUNET_i2s (&pos->peer2->id));
270#endif 268#endif
271 if (pos->peer2handle != NULL) 269 if (pos->peer2handle != NULL)
@@ -280,8 +278,7 @@ disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
280 278
281 279
282static void 280static void
283topology_cb (void *cls, 281topology_cb (void *cls, const struct GNUNET_PeerIdentity *first,
284 const struct GNUNET_PeerIdentity *first,
285 const struct GNUNET_PeerIdentity *second, const char *emsg) 282 const struct GNUNET_PeerIdentity *second, const char *emsg)
286{ 283{
287 FILE *outfile = cls; 284 FILE *outfile = cls;
@@ -310,8 +307,7 @@ topology_cb (void *cls,
310} 307}
311 308
312static int 309static int
313process_mtype (void *cls, 310process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
314 const struct GNUNET_PeerIdentity *peer,
315 const struct GNUNET_MessageHeader *message, 311 const struct GNUNET_MessageHeader *message,
316 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 312 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
317{ 313{
@@ -330,8 +326,8 @@ process_mtype (void *cls,
330 fprintf (stdout, "0%%"); 326 fprintf (stdout, "0%%");
331 else 327 else
332 fprintf (stdout, "%d%%", 328 fprintf (stdout, "%d%%",
333 (int) (((float) total_messages_received / 329 (int) (((float) total_messages_received / expected_messages) *
334 expected_messages) * 100)); 330 100));
335 331
336 } 332 }
337 else if (total_messages_received % dotnum == 0) 333 else if (total_messages_received % dotnum == 0)
@@ -462,8 +458,7 @@ static struct GNUNET_CORE_MessageHandler handlers[] = {
462}; 458};
463 459
464static void 460static void
465init_notify_peer2 (void *cls, 461init_notify_peer2 (void *cls, struct GNUNET_CORE_Handle *server,
466 struct GNUNET_CORE_Handle *server,
467 const struct GNUNET_PeerIdentity *my_identity, 462 const struct GNUNET_PeerIdentity *my_identity,
468 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded 463 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
469 *publicKey) 464 *publicKey)
@@ -481,13 +476,11 @@ init_notify_peer2 (void *cls,
481 GNUNET_i2s (my_identity), 476 GNUNET_i2s (my_identity),
482 GNUNET_h2s (&pos->peer1->id.hashPubKey)); 477 GNUNET_h2s (&pos->peer1->id.hashPubKey));
483#endif 478#endif
484 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle, 479 if (NULL ==
485 0, 480 GNUNET_CORE_notify_transmit_ready (pos->peer1handle, 0, timeout,
486 timeout, 481 &pos->peer2->id,
487 &pos->peer2->id, 482 sizeof (struct GNUNET_TestMessage),
488 sizeof (struct 483 &transmit_ready, pos))
489 GNUNET_TestMessage),
490 &transmit_ready, pos))
491 { 484 {
492 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 485 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
493 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", 486 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
@@ -509,9 +502,7 @@ init_notify_peer2 (void *cls,
509 * @param atsi performance data for the connection 502 * @param atsi performance data for the connection
510 */ 503 */
511static void 504static void
512connect_notify_peers (void *cls, 505connect_notify_peers (void *cls, const struct GNUNET_PeerIdentity *peer,
513 const struct
514 GNUNET_PeerIdentity *peer,
515 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 506 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
516{ 507{
517 struct TestMessageContext *pos = cls; 508 struct TestMessageContext *pos = cls;
@@ -536,13 +527,11 @@ connect_notify_peers (void *cls,
536 GNUNET_i2s (&pos->peer2->id), 527 GNUNET_i2s (&pos->peer2->id),
537 GNUNET_h2s (&pos->peer1->id.hashPubKey)); 528 GNUNET_h2s (&pos->peer1->id.hashPubKey));
538#endif 529#endif
539 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle, 530 if (NULL ==
540 0, 531 GNUNET_CORE_notify_transmit_ready (pos->peer1handle, 0, timeout,
541 timeout, 532 &pos->peer2->id,
542 &pos->peer2->id, 533 sizeof (struct GNUNET_TestMessage),
543 sizeof (struct 534 &transmit_ready, pos))
544 GNUNET_TestMessage),
545 &transmit_ready, pos))
546 { 535 {
547 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 536 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
548 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", 537 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
@@ -557,8 +546,7 @@ connect_notify_peers (void *cls,
557} 546}
558 547
559static void 548static void
560init_notify_peer1 (void *cls, 549init_notify_peer1 (void *cls, struct GNUNET_CORE_Handle *server,
561 struct GNUNET_CORE_Handle *server,
562 const struct GNUNET_PeerIdentity *my_identity, 550 const struct GNUNET_PeerIdentity *my_identity,
563 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded 551 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
564 *publicKey) 552 *publicKey)
@@ -576,15 +564,10 @@ init_notify_peer1 (void *cls,
576 /* 564 /*
577 * Connect to the receiving peer 565 * Connect to the receiving peer
578 */ 566 */
579 pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg, 567 pos->peer2handle =
580 1, 568 GNUNET_CORE_connect (pos->peer2->cfg, 1, pos, &init_notify_peer2, NULL,
581 pos, 569 NULL, NULL, NULL, GNUNET_YES, NULL, GNUNET_YES,
582 &init_notify_peer2, 570 handlers);
583 NULL,
584 NULL,
585 NULL, NULL,
586 GNUNET_YES, NULL, GNUNET_YES,
587 handlers);
588 571
589} 572}
590 573
@@ -604,9 +587,9 @@ send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
604 587
605 if (die_task == GNUNET_SCHEDULER_NO_TASK) 588 if (die_task == GNUNET_SCHEDULER_NO_TASK)
606 { 589 {
607 die_task = GNUNET_SCHEDULER_add_delayed (test_timeout, 590 die_task =
608 &end_badly, 591 GNUNET_SCHEDULER_add_delayed (test_timeout, &end_badly,
609 "from send test messages (timeout)"); 592 "from send test messages (timeout)");
610 } 593 }
611 594
612 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS) 595 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
@@ -620,15 +603,10 @@ send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
620 /* 603 /*
621 * Connect to the sending peer 604 * Connect to the sending peer
622 */ 605 */
623 pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg, 606 pos->peer1handle =
624 1, 607 GNUNET_CORE_connect (pos->peer1->cfg, 1, pos, &init_notify_peer1,
625 pos, 608 &connect_notify_peers, NULL, NULL, NULL, GNUNET_NO,
626 &init_notify_peer1, 609 NULL, GNUNET_NO, no_handlers);
627 &connect_notify_peers, NULL,
628 NULL,
629 NULL,
630 GNUNET_NO, NULL, GNUNET_NO,
631 no_handlers);
632 610
633 GNUNET_assert (pos->peer1handle != NULL); 611 GNUNET_assert (pos->peer1handle != NULL);
634 612
@@ -646,10 +624,8 @@ send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
646 624
647 625
648void 626void
649topology_callback (void *cls, 627topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
650 const struct GNUNET_PeerIdentity *first, 628 const struct GNUNET_PeerIdentity *second, uint32_t distance,
651 const struct GNUNET_PeerIdentity *second,
652 uint32_t distance,
653 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 629 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
654 const struct GNUNET_CONFIGURATION_Handle *second_cfg, 630 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
655 struct GNUNET_TESTING_Daemon *first_daemon, 631 struct GNUNET_TESTING_Daemon *first_daemon,
@@ -667,8 +643,8 @@ topology_callback (void *cls,
667 fprintf (stdout, "0%%"); 643 fprintf (stdout, "0%%");
668 else 644 else
669 fprintf (stdout, "%d%%", 645 fprintf (stdout, "%d%%",
670 (int) (((float) total_connections / 646 (int) (((float) total_connections / expected_connections) *
671 expected_connections) * 100)); 647 100));
672 648
673 } 649 }
674 else if (total_connections % dotnum == 0) 650 else if (total_connections % dotnum == 0)
@@ -787,12 +763,11 @@ connect_topology ()
787 GNUNET_TESTING_connect_topology (pg, connection_topology, 763 GNUNET_TESTING_connect_topology (pg, connection_topology,
788 connect_topology_option, 764 connect_topology_option,
789 connect_topology_option_modifier, 765 connect_topology_option_modifier,
790 connect_timeout, 766 connect_timeout, connect_attempts,
791 connect_attempts,
792 &topology_creation_finished, NULL); 767 &topology_creation_finished, NULL);
793#if VERBOSE > 1 768#if VERBOSE > 1
794 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 769 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Have %d expected connections\n",
795 "Have %d expected connections\n", expected_connections); 770 expected_connections);
796#endif 771#endif
797 } 772 }
798 773
@@ -804,9 +779,9 @@ connect_topology ()
804 "from connect topology (bad return)"); 779 "from connect topology (bad return)");
805 } 780 }
806 781
807 die_task = GNUNET_SCHEDULER_add_delayed (test_timeout, 782 die_task =
808 &end_badly, 783 GNUNET_SCHEDULER_add_delayed (test_timeout, &end_badly,
809 "from connect topology (timeout)"); 784 "from connect topology (timeout)");
810 modnum = expected_connections / 4; 785 modnum = expected_connections / 4;
811 dotnum = (expected_connections / 50) + 1; 786 dotnum = (expected_connections / 50) + 1;
812#if VERBOSE 787#if VERBOSE
@@ -836,15 +811,14 @@ create_topology ()
836 "from create topology (bad return)"); 811 "from create topology (bad return)");
837 } 812 }
838 GNUNET_SCHEDULER_cancel (die_task); 813 GNUNET_SCHEDULER_cancel (die_task);
839 die_task = GNUNET_SCHEDULER_add_delayed (test_timeout, 814 die_task =
840 &end_badly, 815 GNUNET_SCHEDULER_add_delayed (test_timeout, &end_badly,
841 "from continue startup (timeout)"); 816 "from continue startup (timeout)");
842} 817}
843 818
844 819
845static void 820static void
846peers_started_callback (void *cls, 821peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
847 const struct GNUNET_PeerIdentity *id,
848 const struct GNUNET_CONFIGURATION_Handle *cfg, 822 const struct GNUNET_CONFIGURATION_Handle *cfg,
849 struct GNUNET_TESTING_Daemon *d, const char *emsg) 823 struct GNUNET_TESTING_Daemon *d, const char *emsg)
850{ 824{
@@ -888,9 +862,9 @@ peers_started_callback (void *cls,
888 GNUNET_SCHEDULER_cancel (die_task); 862 GNUNET_SCHEDULER_cancel (die_task);
889 /* Set up task in case topology creation doesn't finish 863 /* Set up task in case topology creation doesn't finish
890 * within a reasonable amount of time */ 864 * within a reasonable amount of time */
891 die_task = GNUNET_SCHEDULER_add_delayed (timeout, 865 die_task =
892 &end_badly, 866 GNUNET_SCHEDULER_add_delayed (timeout, &end_badly,
893 "from peers_started_callback"); 867 "from peers_started_callback");
894#if DELAY_FOR_LOGGING 868#if DELAY_FOR_LOGGING
895 fprintf (stdout, "Connecting topology in 10 seconds\n"); 869 fprintf (stdout, "Connecting topology in 10 seconds\n");
896 gather_log_data (); 870 gather_log_data ();
@@ -913,8 +887,7 @@ peers_started_callback (void *cls,
913 * @param emsg non-null on failure 887 * @param emsg non-null on failure
914 */ 888 */
915void 889void
916hostkey_callback (void *cls, 890hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id,
917 const struct GNUNET_PeerIdentity *id,
918 struct GNUNET_TESTING_Daemon *d, const char *emsg) 891 struct GNUNET_TESTING_Daemon *d, const char *emsg)
919{ 892{
920 if (emsg != NULL) 893 if (emsg != NULL)
@@ -925,8 +898,8 @@ hostkey_callback (void *cls,
925 898
926#if VERBOSE > 1 899#if VERBOSE > 1
927 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 900 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
928 "Hostkey (%d/%d) created for peer `%s'\n", 901 "Hostkey (%d/%d) created for peer `%s'\n", num_peers - peers_left,
929 num_peers - peers_left, num_peers, GNUNET_i2s (id)); 902 num_peers, GNUNET_i2s (id));
930#endif 903#endif
931 904
932#if VERBOSE 905#if VERBOSE
@@ -956,18 +929,17 @@ hostkey_callback (void *cls,
956 GNUNET_SCHEDULER_cancel (die_task); 929 GNUNET_SCHEDULER_cancel (die_task);
957 /* Set up task in case topology creation doesn't finish 930 /* Set up task in case topology creation doesn't finish
958 * within a reasonable amount of time */ 931 * within a reasonable amount of time */
959 die_task = GNUNET_SCHEDULER_add_delayed (test_timeout, 932 die_task =
960 &end_badly, 933 GNUNET_SCHEDULER_add_delayed (test_timeout, &end_badly,
961 "from create_topology"); 934 "from create_topology");
962 GNUNET_SCHEDULER_add_now (&create_topology, NULL); 935 GNUNET_SCHEDULER_add_now (&create_topology, NULL);
963 ok = 0; 936 ok = 0;
964 } 937 }
965} 938}
966 939
967static void 940static void
968run (void *cls, 941run (void *cls, char *const *args, const char *cfgfile,
969 char *const *args, 942 const struct GNUNET_CONFIGURATION_Handle *cfg)
970 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
971{ 943{
972 char *topology_str; 944 char *topology_str;
973 char *connect_topology_str; 945 char *connect_topology_str;
@@ -999,8 +971,8 @@ run (void *cls,
999 971
1000 if ((GNUNET_YES == 972 if ((GNUNET_YES ==
1001 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology", 973 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology",
1002 &topology_str)) 974 &topology_str)) &&
1003 && (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str))) 975 (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str)))
1004 { 976 {
1005 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 977 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1006 "Invalid topology `%s' given for section %s option %s\n", 978 "Invalid topology `%s' given for section %s option %s\n",
@@ -1011,10 +983,10 @@ run (void *cls,
1011 if ((GNUNET_YES == 983 if ((GNUNET_YES ==
1012 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", 984 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1013 "connect_topology", 985 "connect_topology",
1014 &connect_topology_str)) 986 &connect_topology_str)) &&
1015 && (GNUNET_NO == 987 (GNUNET_NO ==
1016 GNUNET_TESTING_topology_get (&connection_topology, 988 GNUNET_TESTING_topology_get (&connection_topology,
1017 connect_topology_str))) 989 connect_topology_str)))
1018 { 990 {
1019 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 991 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1020 "Invalid connect topology `%s' given for section %s option %s\n", 992 "Invalid connect topology `%s' given for section %s option %s\n",
@@ -1024,10 +996,10 @@ run (void *cls,
1024 if ((GNUNET_YES == 996 if ((GNUNET_YES ==
1025 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", 997 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1026 "connect_topology_option", 998 "connect_topology_option",
1027 &connect_topology_option_str)) 999 &connect_topology_option_str)) &&
1028 && (GNUNET_NO == 1000 (GNUNET_NO ==
1029 GNUNET_TESTING_topology_option_get (&connect_topology_option, 1001 GNUNET_TESTING_topology_option_get (&connect_topology_option,
1030 connect_topology_option_str))) 1002 connect_topology_option_str)))
1031 { 1003 {
1032 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1004 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1033 "Invalid connect topology option `%s' given for section %s option %s\n", 1005 "Invalid connect topology option `%s' given for section %s option %s\n",
@@ -1063,10 +1035,10 @@ run (void *cls,
1063 if ((GNUNET_YES == 1035 if ((GNUNET_YES ==
1064 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", 1036 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1065 "blacklist_topology", 1037 "blacklist_topology",
1066 &blacklist_topology_str)) 1038 &blacklist_topology_str)) &&
1067 && (GNUNET_NO == 1039 (GNUNET_NO ==
1068 GNUNET_TESTING_topology_get (&blacklist_topology, 1040 GNUNET_TESTING_topology_get (&blacklist_topology,
1069 blacklist_topology_str))) 1041 blacklist_topology_str)))
1070 { 1042 {
1071 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1043 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1072 "Invalid topology `%s' given for section %s option %s\n", 1044 "Invalid topology `%s' given for section %s option %s\n",
@@ -1135,18 +1107,13 @@ run (void *cls,
1135#endif 1107#endif
1136 /* Set up a task to end testing if peer start fails */ 1108 /* Set up a task to end testing if peer start fails */
1137 die_task = 1109 die_task =
1138 GNUNET_SCHEDULER_add_delayed (timeout, 1110 GNUNET_SCHEDULER_add_delayed (timeout, &end_badly,
1139 &end_badly,
1140 "didn't generate all hostkeys within a reasonable amount of time!!!"); 1111 "didn't generate all hostkeys within a reasonable amount of time!!!");
1141 1112
1142 GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1); 1113 GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1);
1143 pg = GNUNET_TESTING_daemons_start (cfg, 1114 pg = GNUNET_TESTING_daemons_start (cfg, peers_left, peers_left / 2,
1144 peers_left, 1115 peers_left, timeout, &hostkey_callback,
1145 peers_left / 2, 1116 NULL, &peers_started_callback, NULL,
1146 peers_left,
1147 timeout,
1148 &hostkey_callback, NULL,
1149 &peers_started_callback, NULL,
1150 &topology_callback, NULL, NULL); 1117 &topology_callback, NULL, NULL);
1151 1118
1152} 1119}
@@ -1173,8 +1140,9 @@ check ()
1173 struct GNUNET_GETOPT_CommandLineOption options[] = { 1140 struct GNUNET_GETOPT_CommandLineOption options[] = {
1174 GNUNET_GETOPT_OPTION_END 1141 GNUNET_GETOPT_OPTION_END
1175 }; 1142 };
1176 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 1143 ret =
1177 argv, binary_name, "nohelp", options, &run, &ok); 1144 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
1145 binary_name, "nohelp", options, &run, &ok);
1178 if (ret != GNUNET_OK) 1146 if (ret != GNUNET_OK)
1179 { 1147 {
1180 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1148 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
diff --git a/src/testing/test_testing_peergroup.c b/src/testing/test_testing_peergroup.c
index f06864036..061a0ca75 100644
--- a/src/testing/test_testing_peergroup.c
+++ b/src/testing/test_testing_peergroup.c
@@ -99,9 +99,8 @@ my_cb (void *cls, const char *emsg)
99 99
100 100
101static void 101static void
102run (void *cls, 102run (void *cls, char *const *args, const char *cfgfile,
103 char *const *args, 103 const struct GNUNET_CONFIGURATION_Handle *cfg)
104 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
105{ 104{
106 struct GNUNET_CONFIGURATION_Handle *testing_cfg; 105 struct GNUNET_CONFIGURATION_Handle *testing_cfg;
107 106
@@ -114,9 +113,8 @@ run (void *cls,
114 "use_progressbars", "YES"); 113 "use_progressbars", "YES");
115#endif 114#endif
116 peers_left = NUM_PEERS; 115 peers_left = NUM_PEERS;
117 pg = GNUNET_TESTING_peergroup_start (testing_cfg, 116 pg = GNUNET_TESTING_peergroup_start (testing_cfg, peers_left, TIMEOUT, NULL,
118 peers_left, 117 &my_cb, NULL, NULL);
119 TIMEOUT, NULL, &my_cb, NULL, NULL);
120 GNUNET_assert (pg != NULL); 118 GNUNET_assert (pg != NULL);
121} 119}
122 120
@@ -134,9 +132,8 @@ check ()
134 struct GNUNET_GETOPT_CommandLineOption options[] = { 132 struct GNUNET_GETOPT_CommandLineOption options[] = {
135 GNUNET_GETOPT_OPTION_END 133 GNUNET_GETOPT_OPTION_END
136 }; 134 };
137 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 135 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
138 argv, "test-testing-peergroup", "nohelp", 136 "test-testing-peergroup", "nohelp", options, &run, &ok);
139 options, &run, &ok);
140 return ok; 137 return ok;
141} 138}
142 139
diff --git a/src/testing/test_testing_reconnect.c b/src/testing/test_testing_reconnect.c
index 1e028779f..480bafdc6 100644
--- a/src/testing/test_testing_reconnect.c
+++ b/src/testing/test_testing_reconnect.c
@@ -113,8 +113,7 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
113 113
114 114
115static void 115static void
116my_connect_complete (void *cls, 116my_connect_complete (void *cls, const struct GNUNET_PeerIdentity *first,
117 const struct GNUNET_PeerIdentity *first,
118 const struct GNUNET_PeerIdentity *second, 117 const struct GNUNET_PeerIdentity *second,
119 unsigned int distance, 118 unsigned int distance,
120 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 119 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
@@ -134,32 +133,29 @@ my_connect_complete (void *cls,
134 133
135 134
136static void 135static void
137my_cb2 (void *cls, 136my_cb2 (void *cls, const struct GNUNET_PeerIdentity *id,
138 const struct GNUNET_PeerIdentity *id,
139 const struct GNUNET_CONFIGURATION_Handle *cfg, 137 const struct GNUNET_CONFIGURATION_Handle *cfg,
140 struct GNUNET_TESTING_Daemon *d, const char *emsg) 138 struct GNUNET_TESTING_Daemon *d, const char *emsg)
141{ 139{
142 GNUNET_assert (id != NULL); 140 GNUNET_assert (id != NULL);
143#if VERBOSE 141#if VERBOSE
144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 142 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Daemon `%s' started.\n",
145 "Daemon `%s' started.\n", GNUNET_i2s (id)); 143 GNUNET_i2s (id));
146#endif 144#endif
147 GNUNET_TESTING_daemons_connect (d1, d2, 145 GNUNET_TESTING_daemons_connect (d1, d2, TIMEOUT, CONNECT_ATTEMPTS, GNUNET_YES,
148 TIMEOUT, CONNECT_ATTEMPTS, 146 &my_connect_complete, NULL);
149 GNUNET_YES, &my_connect_complete, NULL);
150} 147}
151 148
152 149
153static void 150static void
154my_cb1 (void *cls, 151my_cb1 (void *cls, const struct GNUNET_PeerIdentity *id,
155 const struct GNUNET_PeerIdentity *id,
156 const struct GNUNET_CONFIGURATION_Handle *cfg, 152 const struct GNUNET_CONFIGURATION_Handle *cfg,
157 struct GNUNET_TESTING_Daemon *d, const char *emsg) 153 struct GNUNET_TESTING_Daemon *d, const char *emsg)
158{ 154{
159 GNUNET_assert (id != NULL); 155 GNUNET_assert (id != NULL);
160#if VERBOSE 156#if VERBOSE
161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Daemon `%s' started.\n",
162 "Daemon `%s' started.\n", GNUNET_i2s (id)); 158 GNUNET_i2s (id));
163#endif 159#endif
164 d2 = GNUNET_TESTING_daemon_start (c2, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL, 160 d2 = GNUNET_TESTING_daemon_start (c2, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL,
165 NULL, NULL, &my_cb2, NULL); 161 NULL, NULL, &my_cb2, NULL);
@@ -168,9 +164,8 @@ my_cb1 (void *cls,
168 164
169 165
170static void 166static void
171run (void *cls, 167run (void *cls, char *const *args, const char *cfgfile,
172 char *const *args, 168 const struct GNUNET_CONFIGURATION_Handle *cfg)
173 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
174{ 169{
175 ok = 1; 170 ok = 1;
176#if VERBOSE 171#if VERBOSE
@@ -206,9 +201,8 @@ check ()
206 struct GNUNET_GETOPT_CommandLineOption options[] = { 201 struct GNUNET_GETOPT_CommandLineOption options[] = {
207 GNUNET_GETOPT_OPTION_END 202 GNUNET_GETOPT_OPTION_END
208 }; 203 };
209 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 204 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
210 argv, "test-testing-reconnect", "nohelp", 205 "test-testing-reconnect", "nohelp", options, &run, &ok);
211 options, &run, &ok);
212 return ok; 206 return ok;
213} 207}
214 208
diff --git a/src/testing/test_testing_topology.c b/src/testing/test_testing_topology.c
index 73b49e469..27ad0a24c 100644
--- a/src/testing/test_testing_topology.c
+++ b/src/testing/test_testing_topology.c
@@ -193,9 +193,9 @@ gather_log_data ()
193 193
194 GNUNET_asprintf (&peer_number, "%llu", num_peers); 194 GNUNET_asprintf (&peer_number, "%llu", num_peers);
195 GNUNET_asprintf (&connect_number, "%llu", expected_connections); 195 GNUNET_asprintf (&connect_number, "%llu", expected_connections);
196 mem_process = GNUNET_OS_start_process (NULL, NULL, "./memsize.pl", 196 mem_process =
197 "memsize.pl", "totals.txt", 197 GNUNET_OS_start_process (NULL, NULL, "./memsize.pl", "memsize.pl",
198 peer_number, connect_number, NULL); 198 "totals.txt", peer_number, connect_number, NULL);
199 GNUNET_OS_process_wait (mem_process); 199 GNUNET_OS_process_wait (mem_process);
200 GNUNET_OS_process_close (mem_process); 200 GNUNET_OS_process_close (mem_process);
201 mem_process = NULL; 201 mem_process = NULL;
@@ -265,15 +265,13 @@ disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
265 265
266 /* Disconnect from the respective cores */ 266 /* Disconnect from the respective cores */
267#if VERBOSE > 1 267#if VERBOSE > 1
268 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 268 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from peer 1 `%4s'\n",
269 "Disconnecting from peer 1 `%4s'\n",
270 GNUNET_i2s (&pos->peer1->id)); 269 GNUNET_i2s (&pos->peer1->id));
271#endif 270#endif
272 if (pos->peer1handle != NULL) 271 if (pos->peer1handle != NULL)
273 GNUNET_CORE_disconnect (pos->peer1handle); 272 GNUNET_CORE_disconnect (pos->peer1handle);
274#if VERBOSE > 1 273#if VERBOSE > 1
275 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 274 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from peer 2 `%4s'\n",
276 "Disconnecting from peer 2 `%4s'\n",
277 GNUNET_i2s (&pos->peer2->id)); 275 GNUNET_i2s (&pos->peer2->id));
278#endif 276#endif
279 if (pos->peer2handle != NULL) 277 if (pos->peer2handle != NULL)
@@ -305,20 +303,18 @@ stats_finished (void *cls, int result)
305 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration 303 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
306 */ 304 */
307static int 305static int
308stats_print (void *cls, 306stats_print (void *cls, const struct GNUNET_PeerIdentity *peer,
309 const struct GNUNET_PeerIdentity *peer, 307 const char *subsystem, const char *name, uint64_t value,
310 const char *subsystem, 308 int is_persistent)
311 const char *name, uint64_t value, int is_persistent)
312{ 309{
313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s:%s:%s -- %llu\n", 310 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s:%s:%s -- %llu\n", GNUNET_i2s (peer),
314 GNUNET_i2s (peer), subsystem, name, value); 311 subsystem, name, value);
315 return GNUNET_OK; 312 return GNUNET_OK;
316} 313}
317#endif 314#endif
318 315
319static void 316static void
320topology_cb (void *cls, 317topology_cb (void *cls, const struct GNUNET_PeerIdentity *first,
321 const struct GNUNET_PeerIdentity *first,
322 const struct GNUNET_PeerIdentity *second, const char *emsg) 318 const struct GNUNET_PeerIdentity *second, const char *emsg)
323{ 319{
324 FILE *outfile = cls; 320 FILE *outfile = cls;
@@ -350,8 +346,7 @@ topology_cb (void *cls,
350} 346}
351 347
352static int 348static int
353process_mtype (void *cls, 349process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
354 const struct GNUNET_PeerIdentity *peer,
355 const struct GNUNET_MessageHeader *message, 350 const struct GNUNET_MessageHeader *message,
356 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 351 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
357{ 352{
@@ -370,8 +365,8 @@ process_mtype (void *cls,
370 fprintf (stdout, "0%%"); 365 fprintf (stdout, "0%%");
371 else 366 else
372 fprintf (stdout, "%d%%", 367 fprintf (stdout, "%d%%",
373 (int) (((float) total_messages_received / 368 (int) (((float) total_messages_received / expected_messages) *
374 expected_messages) * 100)); 369 100));
375 370
376 } 371 }
377 else if (total_messages_received % dotnum == 0) 372 else if (total_messages_received % dotnum == 0)
@@ -502,8 +497,7 @@ static struct GNUNET_CORE_MessageHandler handlers[] = {
502}; 497};
503 498
504static void 499static void
505init_notify_peer2 (void *cls, 500init_notify_peer2 (void *cls, struct GNUNET_CORE_Handle *server,
506 struct GNUNET_CORE_Handle *server,
507 const struct GNUNET_PeerIdentity *my_identity, 501 const struct GNUNET_PeerIdentity *my_identity,
508 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded 502 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
509 *publicKey) 503 *publicKey)
@@ -521,14 +515,11 @@ init_notify_peer2 (void *cls,
521 GNUNET_i2s (my_identity), 515 GNUNET_i2s (my_identity),
522 GNUNET_h2s (&pos->peer1->id.hashPubKey)); 516 GNUNET_h2s (&pos->peer1->id.hashPubKey));
523#endif 517#endif
524 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle, 518 if (NULL ==
525 GNUNET_YES, 519 GNUNET_CORE_notify_transmit_ready (pos->peer1handle, GNUNET_YES, 0,
526 0, 520 TIMEOUT, &pos->peer2->id,
527 TIMEOUT, 521 sizeof (struct GNUNET_TestMessage),
528 &pos->peer2->id, 522 &transmit_ready, pos))
529 sizeof (struct
530 GNUNET_TestMessage),
531 &transmit_ready, pos))
532 { 523 {
533 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 524 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
534 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", 525 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
@@ -550,9 +541,7 @@ init_notify_peer2 (void *cls,
550 * @param atsi performance data for the connection 541 * @param atsi performance data for the connection
551 */ 542 */
552static void 543static void
553connect_notify_peers (void *cls, 544connect_notify_peers (void *cls, const struct GNUNET_PeerIdentity *peer,
554 const struct
555 GNUNET_PeerIdentity *peer,
556 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 545 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
557{ 546{
558 struct TestMessageContext *pos = cls; 547 struct TestMessageContext *pos = cls;
@@ -577,14 +566,11 @@ connect_notify_peers (void *cls,
577 GNUNET_i2s (&pos->peer2->id), 566 GNUNET_i2s (&pos->peer2->id),
578 GNUNET_h2s (&pos->peer1->id.hashPubKey)); 567 GNUNET_h2s (&pos->peer1->id.hashPubKey));
579#endif 568#endif
580 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle, 569 if (NULL ==
581 GNUNET_YES, 570 GNUNET_CORE_notify_transmit_ready (pos->peer1handle, GNUNET_YES, 0,
582 0, 571 TIMEOUT, &pos->peer2->id,
583 TIMEOUT, 572 sizeof (struct GNUNET_TestMessage),
584 &pos->peer2->id, 573 &transmit_ready, pos))
585 sizeof (struct
586 GNUNET_TestMessage),
587 &transmit_ready, pos))
588 { 574 {
589 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 575 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
590 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", 576 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
@@ -599,8 +585,7 @@ connect_notify_peers (void *cls,
599} 585}
600 586
601static void 587static void
602init_notify_peer1 (void *cls, 588init_notify_peer1 (void *cls, struct GNUNET_CORE_Handle *server,
603 struct GNUNET_CORE_Handle *server,
604 const struct GNUNET_PeerIdentity *my_identity, 589 const struct GNUNET_PeerIdentity *my_identity,
605 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded 590 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
606 *publicKey) 591 *publicKey)
@@ -618,15 +603,10 @@ init_notify_peer1 (void *cls,
618 /* 603 /*
619 * Connect to the receiving peer 604 * Connect to the receiving peer
620 */ 605 */
621 pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg, 606 pos->peer2handle =
622 1, 607 GNUNET_CORE_connect (pos->peer2->cfg, 1, pos, &init_notify_peer2, NULL,
623 pos, 608 NULL, NULL, NULL, GNUNET_YES, NULL, GNUNET_YES,
624 &init_notify_peer2, 609 handlers);
625 NULL,
626 NULL,
627 NULL, NULL,
628 GNUNET_YES, NULL, GNUNET_YES,
629 handlers);
630 610
631} 611}
632 612
@@ -646,9 +626,9 @@ send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
646 626
647 if (die_task == GNUNET_SCHEDULER_NO_TASK) 627 if (die_task == GNUNET_SCHEDULER_NO_TASK)
648 { 628 {
649 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, 629 die_task =
650 &end_badly, 630 GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &end_badly,
651 "from send test messages (timeout)"); 631 "from send test messages (timeout)");
652 } 632 }
653 633
654 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS) 634 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
@@ -662,15 +642,10 @@ send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
662 /* 642 /*
663 * Connect to the sending peer 643 * Connect to the sending peer
664 */ 644 */
665 pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg, 645 pos->peer1handle =
666 1, 646 GNUNET_CORE_connect (pos->peer1->cfg, 1, pos, &init_notify_peer1,
667 pos, 647 &connect_notify_peers, NULL, NULL, NULL, GNUNET_NO,
668 &init_notify_peer1, 648 NULL, GNUNET_NO, no_handlers);
669 &connect_notify_peers, NULL,
670 NULL,
671 NULL,
672 GNUNET_NO, NULL, GNUNET_NO,
673 no_handlers);
674 649
675 GNUNET_assert (pos->peer1handle != NULL); 650 GNUNET_assert (pos->peer1handle != NULL);
676 651
@@ -688,10 +663,8 @@ send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
688 663
689 664
690void 665void
691topology_callback (void *cls, 666topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
692 const struct GNUNET_PeerIdentity *first, 667 const struct GNUNET_PeerIdentity *second, uint32_t distance,
693 const struct GNUNET_PeerIdentity *second,
694 uint32_t distance,
695 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 668 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
696 const struct GNUNET_CONFIGURATION_Handle *second_cfg, 669 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
697 struct GNUNET_TESTING_Daemon *first_daemon, 670 struct GNUNET_TESTING_Daemon *first_daemon,
@@ -709,8 +682,8 @@ topology_callback (void *cls,
709 fprintf (stdout, "0%%"); 682 fprintf (stdout, "0%%");
710 else 683 else
711 fprintf (stdout, "%d%%", 684 fprintf (stdout, "%d%%",
712 (int) (((float) total_connections / 685 (int) (((float) total_connections / expected_connections) *
713 expected_connections) * 100)); 686 100));
714 687
715 } 688 }
716 else if (total_connections % dotnum == 0) 689 else if (total_connections % dotnum == 0)
@@ -833,12 +806,11 @@ connect_topology ()
833 GNUNET_TESTING_connect_topology (pg, connection_topology, 806 GNUNET_TESTING_connect_topology (pg, connection_topology,
834 connect_topology_option, 807 connect_topology_option,
835 connect_topology_option_modifier, 808 connect_topology_option_modifier,
836 connect_timeout, 809 connect_timeout, connect_attempts,
837 connect_attempts,
838 &topology_creation_finished, NULL); 810 &topology_creation_finished, NULL);
839#if PROGRESS_BARS 811#if PROGRESS_BARS
840 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 812 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Have %d expected connections\n",
841 "Have %d expected connections\n", expected_connections); 813 expected_connections);
842#endif 814#endif
843 } 815 }
844 816
@@ -851,11 +823,12 @@ connect_topology ()
851 return; 823 return;
852 } 824 }
853 825
854 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 826 die_task =
855 (GNUNET_TIME_UNIT_SECONDS, 827 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
856 SECONDS_PER_PEER_START * num_peers), 828 (GNUNET_TIME_UNIT_SECONDS,
857 &end_badly, 829 SECONDS_PER_PEER_START * num_peers),
858 "from connect topology (timeout)"); 830 &end_badly,
831 "from connect topology (timeout)");
859 modnum = expected_connections / 4; 832 modnum = expected_connections / 4;
860 dotnum = (expected_connections / 50) + 1; 833 dotnum = (expected_connections / 50) + 1;
861 if (modnum == 0) 834 if (modnum == 0)
@@ -889,17 +862,17 @@ create_topology ()
889 "from create topology (bad return)"); 862 "from create topology (bad return)");
890 } 863 }
891 GNUNET_SCHEDULER_cancel (die_task); 864 GNUNET_SCHEDULER_cancel (die_task);
892 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 865 die_task =
893 (GNUNET_TIME_UNIT_SECONDS, 866 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
894 SECONDS_PER_PEER_START * num_peers), 867 (GNUNET_TIME_UNIT_SECONDS,
895 &end_badly, 868 SECONDS_PER_PEER_START * num_peers),
896 "from continue startup (timeout)"); 869 &end_badly,
870 "from continue startup (timeout)");
897} 871}
898 872
899 873
900static void 874static void
901peers_started_callback (void *cls, 875peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
902 const struct GNUNET_PeerIdentity *id,
903 const struct GNUNET_CONFIGURATION_Handle *cfg, 876 const struct GNUNET_CONFIGURATION_Handle *cfg,
904 struct GNUNET_TESTING_Daemon *d, const char *emsg) 877 struct GNUNET_TESTING_Daemon *d, const char *emsg)
905{ 878{
@@ -943,10 +916,10 @@ peers_started_callback (void *cls,
943 GNUNET_SCHEDULER_cancel (die_task); 916 GNUNET_SCHEDULER_cancel (die_task);
944 /* Set up task in case topology creation doesn't finish 917 /* Set up task in case topology creation doesn't finish
945 * within a reasonable amount of time */ 918 * within a reasonable amount of time */
946 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 919 die_task =
947 (GNUNET_TIME_UNIT_MINUTES, 8), 920 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
948 &end_badly, 921 (GNUNET_TIME_UNIT_MINUTES, 8), &end_badly,
949 "from peers_started_callback"); 922 "from peers_started_callback");
950#if DELAY_FOR_LOGGING 923#if DELAY_FOR_LOGGING
951 fprintf (stdout, "Connecting topology in 10 seconds\n"); 924 fprintf (stdout, "Connecting topology in 10 seconds\n");
952 gather_log_data (); 925 gather_log_data ();
@@ -969,8 +942,7 @@ peers_started_callback (void *cls,
969 * @param emsg non-null on failure 942 * @param emsg non-null on failure
970 */ 943 */
971void 944void
972hostkey_callback (void *cls, 945hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id,
973 const struct GNUNET_PeerIdentity *id,
974 struct GNUNET_TESTING_Daemon *d, const char *emsg) 946 struct GNUNET_TESTING_Daemon *d, const char *emsg)
975{ 947{
976 if (emsg != NULL) 948 if (emsg != NULL)
@@ -981,8 +953,8 @@ hostkey_callback (void *cls,
981 953
982#if VERBOSE > 1 954#if VERBOSE > 1
983 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 955 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
984 "Hostkey (%d/%d) created for peer `%s'\n", 956 "Hostkey (%d/%d) created for peer `%s'\n", num_peers - peers_left,
985 num_peers - peers_left, num_peers, GNUNET_i2s (id)); 957 num_peers, GNUNET_i2s (id));
986#endif 958#endif
987 959
988#if PROGRESS_BARS 960#if PROGRESS_BARS
@@ -1012,18 +984,17 @@ hostkey_callback (void *cls,
1012 GNUNET_SCHEDULER_cancel (die_task); 984 GNUNET_SCHEDULER_cancel (die_task);
1013 /* Set up task in case topology creation doesn't finish 985 /* Set up task in case topology creation doesn't finish
1014 * within a reasonable amount of time */ 986 * within a reasonable amount of time */
1015 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 987 die_task =
1016 &end_badly, 988 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
1017 "from create_topology"); 989 "from create_topology");
1018 GNUNET_SCHEDULER_add_now (&create_topology, NULL); 990 GNUNET_SCHEDULER_add_now (&create_topology, NULL);
1019 ok = 0; 991 ok = 0;
1020 } 992 }
1021} 993}
1022 994
1023static void 995static void
1024run (void *cls, 996run (void *cls, char *const *args, const char *cfgfile,
1025 char *const *args, 997 const struct GNUNET_CONFIGURATION_Handle *cfg)
1026 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
1027{ 998{
1028 char *topology_str; 999 char *topology_str;
1029 char *connect_topology_str; 1000 char *connect_topology_str;
@@ -1056,8 +1027,8 @@ run (void *cls,
1056 1027
1057 if ((GNUNET_YES == 1028 if ((GNUNET_YES ==
1058 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology", 1029 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology",
1059 &topology_str)) 1030 &topology_str)) &&
1060 && (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str))) 1031 (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str)))
1061 { 1032 {
1062 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1033 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1063 "Invalid topology `%s' given for section %s option %s\n", 1034 "Invalid topology `%s' given for section %s option %s\n",
@@ -1068,10 +1039,10 @@ run (void *cls,
1068 if ((GNUNET_YES == 1039 if ((GNUNET_YES ==
1069 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", 1040 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1070 "connect_topology", 1041 "connect_topology",
1071 &connect_topology_str)) 1042 &connect_topology_str)) &&
1072 && (GNUNET_NO == 1043 (GNUNET_NO ==
1073 GNUNET_TESTING_topology_get (&connection_topology, 1044 GNUNET_TESTING_topology_get (&connection_topology,
1074 connect_topology_str))) 1045 connect_topology_str)))
1075 { 1046 {
1076 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1047 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1077 "Invalid connect topology `%s' given for section %s option %s\n", 1048 "Invalid connect topology `%s' given for section %s option %s\n",
@@ -1081,10 +1052,10 @@ run (void *cls,
1081 if ((GNUNET_YES == 1052 if ((GNUNET_YES ==
1082 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", 1053 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1083 "connect_topology_option", 1054 "connect_topology_option",
1084 &connect_topology_option_str)) 1055 &connect_topology_option_str)) &&
1085 && (GNUNET_NO == 1056 (GNUNET_NO ==
1086 GNUNET_TESTING_topology_option_get (&connect_topology_option, 1057 GNUNET_TESTING_topology_option_get (&connect_topology_option,
1087 connect_topology_option_str))) 1058 connect_topology_option_str)))
1088 { 1059 {
1089 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1060 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1090 "Invalid connect topology option `%s' given for section %s option %s\n", 1061 "Invalid connect topology option `%s' given for section %s option %s\n",
@@ -1120,10 +1091,10 @@ run (void *cls,
1120 if ((GNUNET_YES == 1091 if ((GNUNET_YES ==
1121 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", 1092 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1122 "blacklist_topology", 1093 "blacklist_topology",
1123 &blacklist_topology_str)) 1094 &blacklist_topology_str)) &&
1124 && (GNUNET_NO == 1095 (GNUNET_NO ==
1125 GNUNET_TESTING_topology_get (&blacklist_topology, 1096 GNUNET_TESTING_topology_get (&blacklist_topology,
1126 blacklist_topology_str))) 1097 blacklist_topology_str)))
1127 { 1098 {
1128 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1099 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1129 "Invalid topology `%s' given for section %s option %s\n", 1100 "Invalid topology `%s' given for section %s option %s\n",
@@ -1196,10 +1167,8 @@ run (void *cls,
1196 "didn't generate all hostkeys within a reasonable amount of time!!!"); 1167 "didn't generate all hostkeys within a reasonable amount of time!!!");
1197 1168
1198 GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1); 1169 GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1);
1199 pg = GNUNET_TESTING_daemons_start (cfg, 1170 pg = GNUNET_TESTING_daemons_start (cfg, peers_left,
1200 peers_left, 1171 max_outstanding_connections, peers_left,
1201 max_outstanding_connections,
1202 peers_left,
1203 GNUNET_TIME_relative_multiply 1172 GNUNET_TIME_relative_multiply
1204 (GNUNET_TIME_UNIT_SECONDS, 1173 (GNUNET_TIME_UNIT_SECONDS,
1205 SECONDS_PER_PEER_START * num_peers), 1174 SECONDS_PER_PEER_START * num_peers),
@@ -1231,8 +1200,9 @@ check ()
1231 struct GNUNET_GETOPT_CommandLineOption options[] = { 1200 struct GNUNET_GETOPT_CommandLineOption options[] = {
1232 GNUNET_GETOPT_OPTION_END 1201 GNUNET_GETOPT_OPTION_END
1233 }; 1202 };
1234 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 1203 ret =
1235 argv, binary_name, "nohelp", options, &run, &ok); 1204 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
1205 binary_name, "nohelp", options, &run, &ok);
1236 if (ret != GNUNET_OK) 1206 if (ret != GNUNET_OK)
1237 { 1207 {
1238 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1208 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
diff --git a/src/testing/test_testing_topology_blacklist.c b/src/testing/test_testing_topology_blacklist.c
index f9185b6fc..d60e3a8fb 100644
--- a/src/testing/test_testing_topology_blacklist.c
+++ b/src/testing/test_testing_topology_blacklist.c
@@ -173,10 +173,8 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
173 173
174 174
175void 175void
176topology_callback (void *cls, 176topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
177 const struct GNUNET_PeerIdentity *first, 177 const struct GNUNET_PeerIdentity *second, uint32_t distance,
178 const struct GNUNET_PeerIdentity *second,
179 uint32_t distance,
180 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 178 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
181 const struct GNUNET_CONFIGURATION_Handle *second_cfg, 179 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
182 struct GNUNET_TESTING_Daemon *first_daemon, 180 struct GNUNET_TESTING_Daemon *first_daemon,
@@ -222,9 +220,9 @@ topology_callback (void *cls,
222 } 220 }
223 else if (total_connections + failed_connections == expected_connections) 221 else if (total_connections + failed_connections == expected_connections)
224 { 222 {
225 if ((failed_connections == expected_failed_connections) 223 if ((failed_connections == expected_failed_connections) &&
226 && (total_connections == 224 (total_connections ==
227 expected_connections - expected_failed_connections)) 225 expected_connections - expected_failed_connections))
228 { 226 {
229 GNUNET_SCHEDULER_cancel (die_task); 227 GNUNET_SCHEDULER_cancel (die_task);
230 die_task = GNUNET_SCHEDULER_NO_TASK; 228 die_task = GNUNET_SCHEDULER_NO_TASK;
@@ -260,11 +258,11 @@ connect_topology ()
260 GNUNET_TESTING_connect_topology (pg, connection_topology, 258 GNUNET_TESTING_connect_topology (pg, connection_topology,
261 connect_topology_option, 259 connect_topology_option,
262 connect_topology_option_modifier, 260 connect_topology_option_modifier,
263 connect_timeout, 261 connect_timeout, connect_attempts,
264 connect_attempts, NULL, NULL); 262 NULL, NULL);
265#if VERBOSE 263#if VERBOSE
266 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Have %d expected connections\n",
267 "Have %d expected connections\n", expected_connections); 265 expected_connections);
268#endif 266#endif
269 } 267 }
270 268
@@ -276,9 +274,9 @@ connect_topology ()
276 "from connect topology (bad return)"); 274 "from connect topology (bad return)");
277 } 275 }
278 276
279 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, 277 die_task =
280 &end_badly, 278 GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &end_badly,
281 "from connect topology (timeout)"); 279 "from connect topology (timeout)");
282} 280}
283 281
284static void 282static void
@@ -302,15 +300,14 @@ create_topology ()
302 "from create topology (bad return)"); 300 "from create topology (bad return)");
303 } 301 }
304 GNUNET_SCHEDULER_cancel (die_task); 302 GNUNET_SCHEDULER_cancel (die_task);
305 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, 303 die_task =
306 &end_badly, 304 GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &end_badly,
307 "from continue startup (timeout)"); 305 "from continue startup (timeout)");
308} 306}
309 307
310 308
311static void 309static void
312peers_started_callback (void *cls, 310peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
313 const struct GNUNET_PeerIdentity *id,
314 const struct GNUNET_CONFIGURATION_Handle *cfg, 311 const struct GNUNET_CONFIGURATION_Handle *cfg,
315 struct GNUNET_TESTING_Daemon *d, const char *emsg) 312 struct GNUNET_TESTING_Daemon *d, const char *emsg)
316{ 313{
@@ -335,10 +332,10 @@ peers_started_callback (void *cls,
335 GNUNET_SCHEDULER_cancel (die_task); 332 GNUNET_SCHEDULER_cancel (die_task);
336 /* Set up task in case topology creation doesn't finish 333 /* Set up task in case topology creation doesn't finish
337 * within a reasonable amount of time */ 334 * within a reasonable amount of time */
338 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 335 die_task =
339 (GNUNET_TIME_UNIT_MINUTES, 5), 336 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
340 &end_badly, 337 (GNUNET_TIME_UNIT_MINUTES, 5), &end_badly,
341 "from peers_started_callback"); 338 "from peers_started_callback");
342 connect_topology (); 339 connect_topology ();
343 ok = 0; 340 ok = 0;
344 } 341 }
@@ -353,8 +350,7 @@ peers_started_callback (void *cls,
353 * @param emsg non-null on failure 350 * @param emsg non-null on failure
354 */ 351 */
355void 352void
356hostkey_callback (void *cls, 353hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id,
357 const struct GNUNET_PeerIdentity *id,
358 struct GNUNET_TESTING_Daemon *d, const char *emsg) 354 struct GNUNET_TESTING_Daemon *d, const char *emsg)
359{ 355{
360 if (emsg != NULL) 356 if (emsg != NULL)
@@ -364,8 +360,8 @@ hostkey_callback (void *cls,
364 } 360 }
365 361
366#if VERBOSE 362#if VERBOSE
367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 363 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostkey created for peer `%s'\n",
368 "Hostkey created for peer `%s'\n", GNUNET_i2s (id)); 364 GNUNET_i2s (id));
369#endif 365#endif
370 peers_left--; 366 peers_left--;
371 if (peers_left == 0) 367 if (peers_left == 0)
@@ -377,19 +373,18 @@ hostkey_callback (void *cls,
377 GNUNET_SCHEDULER_cancel (die_task); 373 GNUNET_SCHEDULER_cancel (die_task);
378 /* Set up task in case topology creation doesn't finish 374 /* Set up task in case topology creation doesn't finish
379 * within a reasonable amount of time */ 375 * within a reasonable amount of time */
380 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 376 die_task =
381 (GNUNET_TIME_UNIT_MINUTES, 5), 377 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
382 &end_badly, 378 (GNUNET_TIME_UNIT_MINUTES, 5), &end_badly,
383 "from hostkey_callback"); 379 "from hostkey_callback");
384 GNUNET_SCHEDULER_add_now (&create_topology, NULL); 380 GNUNET_SCHEDULER_add_now (&create_topology, NULL);
385 ok = 0; 381 ok = 0;
386 } 382 }
387} 383}
388 384
389static void 385static void
390run (void *cls, 386run (void *cls, char *const *args, const char *cfgfile,
391 char *const *args, 387 const struct GNUNET_CONFIGURATION_Handle *cfg)
392 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
393{ 388{
394 unsigned long long topology_num; 389 unsigned long long topology_num;
395 unsigned long long connect_topology_num; 390 unsigned long long connect_topology_num;
@@ -429,8 +424,7 @@ run (void *cls,
429 topology = topology_num; 424 topology = topology_num;
430 425
431 if (GNUNET_YES == 426 if (GNUNET_YES ==
432 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", 427 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_topology",
433 "connect_topology",
434 &connect_topology_num)) 428 &connect_topology_num))
435 connection_topology = connect_topology_num; 429 connection_topology = connect_topology_num;
436 430
@@ -528,15 +522,14 @@ run (void *cls,
528 522
529 523
530 /* Set up a task to end testing if peer start fails */ 524 /* Set up a task to end testing if peer start fails */
531 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 525 die_task =
532 (GNUNET_TIME_UNIT_MINUTES, 5), 526 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
533 &end_badly, 527 (GNUNET_TIME_UNIT_MINUTES, 5), &end_badly,
534 "didn't start all daemons in reasonable amount of time!!!"); 528 "didn't start all daemons in reasonable amount of time!!!");
535 529
536 pg = GNUNET_TESTING_daemons_start (cfg, 530 pg = GNUNET_TESTING_daemons_start (cfg, peers_left, peers_left, peers_left,
537 peers_left, peers_left, peers_left, 531 TIMEOUT, &hostkey_callback, NULL,
538 TIMEOUT, &hostkey_callback, 532 &peers_started_callback, NULL,
539 NULL, &peers_started_callback, NULL,
540 &topology_callback, NULL, NULL); 533 &topology_callback, NULL, NULL);
541 534
542} 535}
@@ -557,9 +550,10 @@ check ()
557 struct GNUNET_GETOPT_CommandLineOption options[] = { 550 struct GNUNET_GETOPT_CommandLineOption options[] = {
558 GNUNET_GETOPT_OPTION_END 551 GNUNET_GETOPT_OPTION_END
559 }; 552 };
560 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 553 ret =
561 argv, "test-testing-topology-blacklist", "nohelp", 554 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
562 options, &run, &ok); 555 "test-testing-topology-blacklist", "nohelp", options,
556 &run, &ok);
563 if (ret != GNUNET_OK) 557 if (ret != GNUNET_OK)
564 { 558 {
565 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 559 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
diff --git a/src/testing/test_testing_topology_churn.c b/src/testing/test_testing_topology_churn.c
index ee800c52c..5a348642c 100644
--- a/src/testing/test_testing_topology_churn.c
+++ b/src/testing/test_testing_topology_churn.c
@@ -198,8 +198,7 @@ churn_peers_off ()
198} 198}
199 199
200static void 200static void
201peers_started_callback (void *cls, 201peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
202 const struct GNUNET_PeerIdentity *id,
203 const struct GNUNET_CONFIGURATION_Handle *cfg, 202 const struct GNUNET_CONFIGURATION_Handle *cfg,
204 struct GNUNET_TESTING_Daemon *d, const char *emsg) 203 struct GNUNET_TESTING_Daemon *d, const char *emsg)
205{ 204{
@@ -224,10 +223,10 @@ peers_started_callback (void *cls,
224 GNUNET_SCHEDULER_cancel (die_task); 223 GNUNET_SCHEDULER_cancel (die_task);
225 /* Set up task in case topology creation doesn't finish 224 /* Set up task in case topology creation doesn't finish
226 * within a reasonable amount of time */ 225 * within a reasonable amount of time */
227 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 226 die_task =
228 (GNUNET_TIME_UNIT_MINUTES, 5), 227 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
229 &end_badly, 228 (GNUNET_TIME_UNIT_MINUTES, 5), &end_badly,
230 "from peers_started_callback"); 229 "from peers_started_callback");
231 churn_peers_off (); 230 churn_peers_off ();
232 ok = 0; 231 ok = 0;
233 } 232 }
@@ -235,9 +234,8 @@ peers_started_callback (void *cls,
235 234
236 235
237static void 236static void
238run (void *cls, 237run (void *cls, char *const *args, const char *cfgfile,
239 char *const *args, 238 const struct GNUNET_CONFIGURATION_Handle *cfg)
240 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
241{ 239{
242 ok = 1; 240 ok = 1;
243 241
@@ -274,18 +272,15 @@ run (void *cls,
274 272
275 273
276 /* Set up a task to end testing if peer start fails */ 274 /* Set up a task to end testing if peer start fails */
277 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 275 die_task =
278 (GNUNET_TIME_UNIT_MINUTES, 5), 276 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
279 &end_badly, 277 (GNUNET_TIME_UNIT_MINUTES, 5), &end_badly,
280 "didn't start all daemons in reasonable amount of time!!!"); 278 "didn't start all daemons in reasonable amount of time!!!");
281 279
282 pg = GNUNET_TESTING_daemons_start (cfg, 280 pg = GNUNET_TESTING_daemons_start (cfg, peers_left, peers_left, peers_left,
283 peers_left,
284 peers_left,
285 peers_left,
286 TIMEOUT, NULL, NULL, 281 TIMEOUT, NULL, NULL,
287 &peers_started_callback, NULL, NULL, 282 &peers_started_callback, NULL, NULL, NULL,
288 NULL, NULL); 283 NULL);
289 284
290} 285}
291 286
@@ -305,9 +300,10 @@ check ()
305 struct GNUNET_GETOPT_CommandLineOption options[] = { 300 struct GNUNET_GETOPT_CommandLineOption options[] = {
306 GNUNET_GETOPT_OPTION_END 301 GNUNET_GETOPT_OPTION_END
307 }; 302 };
308 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 303 ret =
309 argv, "test-testing-topology-churn", "nohelp", 304 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
310 options, &run, &ok); 305 "test-testing-topology-churn", "nohelp", options,
306 &run, &ok);
311 if (ret != GNUNET_OK) 307 if (ret != GNUNET_OK)
312 { 308 {
313 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 309 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
diff --git a/src/testing/testing.c b/src/testing/testing.c
index c21166775..c107ec593 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -67,10 +67,9 @@ static struct GNUNET_CORE_MessageHandler no_handlers[] = { {NULL, 0, 0} };
67 67
68#if EMPTY_HACK 68#if EMPTY_HACK
69static int 69static int
70test_address (void *cls, 70test_address (void *cls, const char *tname,
71 const char *tname, 71 struct GNUNET_TIME_Absolute expiration, const void *addr,
72 struct GNUNET_TIME_Absolute expiration, 72 uint16_t addrlen)
73 const void *addr, uint16_t addrlen)
74{ 73{
75 int *empty = cls; 74 int *empty = cls;
76 75
@@ -144,8 +143,8 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message)
144 } 143 }
145#if DEBUG_TESTING 144#if DEBUG_TESTING
146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
147 "Received `%s' from transport service of `%4s'\n", 146 "Received `%s' from transport service of `%4s'\n", "HELLO",
148 "HELLO", GNUNET_i2s (&daemon->id)); 147 GNUNET_i2s (&daemon->id));
149#endif 148#endif
150 149
151 GNUNET_free_non_null (daemon->hello); 150 GNUNET_free_non_null (daemon->hello);
@@ -165,8 +164,8 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message)
165#endif 164#endif
166} 165}
167 166
168static void 167static void start_fsm (void *cls,
169start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 168 const struct GNUNET_SCHEDULER_TaskContext *tc);
170 169
171#if WAIT_FOR_HELLO 170#if WAIT_FOR_HELLO
172/** 171/**
@@ -182,8 +181,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
182 * @param publicKey public key of this peer, NULL if we failed 181 * @param publicKey public key of this peer, NULL if we failed
183 */ 182 */
184static void 183static void
185testing_init (void *cls, 184testing_init (void *cls, struct GNUNET_CORE_Handle *server,
186 struct GNUNET_CORE_Handle *server,
187 const struct GNUNET_PeerIdentity *my_identity, 185 const struct GNUNET_PeerIdentity *my_identity,
188 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) 186 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
189{ 187{
@@ -197,17 +195,18 @@ testing_init (void *cls,
197 d->server = NULL; 195 d->server = NULL;
198 if (GNUNET_YES == d->dead) 196 if (GNUNET_YES == d->dead)
199 GNUNET_TESTING_daemon_stop (d, 197 GNUNET_TESTING_daemon_stop (d,
200 GNUNET_TIME_absolute_get_remaining 198 GNUNET_TIME_absolute_get_remaining (d->
201 (d->max_timeout), d->dead_cb, 199 max_timeout),
202 d->dead_cb_cls, GNUNET_YES, GNUNET_NO); 200 d->dead_cb, d->dead_cb_cls, GNUNET_YES,
201 GNUNET_NO);
203 else if (NULL != d->cb) 202 else if (NULL != d->cb)
204 d->cb (d->cb_cls, NULL, d->cfg, d, 203 d->cb (d->cb_cls, NULL, d->cfg, d,
205 _("Failed to connect to core service\n")); 204 _("Failed to connect to core service\n"));
206 return; 205 return;
207 } 206 }
208#if DEBUG_TESTING 207#if DEBUG_TESTING
209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully started peer `%4s'.\n",
210 "Successfully started peer `%4s'.\n", GNUNET_i2s (my_identity)); 209 GNUNET_i2s (my_identity));
211#endif 210#endif
212 d->id = *my_identity; /* FIXME: shouldn't we already have this from reading the hostkey file? */ 211 d->id = *my_identity; /* FIXME: shouldn't we already have this from reading the hostkey file? */
213 if (d->shortname == NULL) 212 if (d->shortname == NULL)
@@ -234,9 +233,10 @@ testing_init (void *cls,
234 { 233 {
235 if (GNUNET_YES == d->dead) 234 if (GNUNET_YES == d->dead)
236 GNUNET_TESTING_daemon_stop (d, 235 GNUNET_TESTING_daemon_stop (d,
237 GNUNET_TIME_absolute_get_remaining 236 GNUNET_TIME_absolute_get_remaining (d->
238 (d->max_timeout), d->dead_cb, 237 max_timeout),
239 d->dead_cb_cls, GNUNET_YES, GNUNET_NO); 238 d->dead_cb, d->dead_cb_cls, GNUNET_YES,
239 GNUNET_NO);
240 else if (NULL != d->cb) 240 else if (NULL != d->cb)
241 d->cb (d->cb_cls, &d->id, d->cfg, d, 241 d->cb (d->cb_cls, &d->id, d->cfg, d,
242 _("Failed to connect to transport service!\n")); 242 _("Failed to connect to transport service!\n"));
@@ -252,9 +252,8 @@ testing_init (void *cls,
252 /* wait some more */ 252 /* wait some more */
253 if (d->task != GNUNET_SCHEDULER_NO_TASK) 253 if (d->task != GNUNET_SCHEDULER_NO_TASK)
254 GNUNET_SCHEDULER_cancel (d->task); 254 GNUNET_SCHEDULER_cancel (d->task);
255 d->task 255 d->task =
256 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, 256 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm, d);
257 &start_fsm, d);
258} 257}
259#endif 258#endif
260 259
@@ -312,17 +311,15 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
312 cb = d->cb; 311 cb = d->cb;
313 d->cb = NULL; 312 d->cb = NULL;
314 if (NULL != cb) 313 if (NULL != cb)
315 cb (d->cb_cls, 314 cb (d->cb_cls, NULL, d->cfg, d,
316 NULL,
317 d->cfg, d,
318 _ 315 _
319 ("`scp' does not seem to terminate (timeout copying config).\n")); 316 ("`scp' does not seem to terminate (timeout copying config).\n"));
320 return; 317 return;
321 } 318 }
322 /* wait some more */ 319 /* wait some more */
323 d->task 320 d->task =
324 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, 321 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm,
325 &start_fsm, d); 322 d);
326 return; 323 return;
327 } 324 }
328 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) 325 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
@@ -350,13 +347,12 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
350 cb = d->cb; 347 cb = d->cb;
351 d->cb = NULL; 348 d->cb = NULL;
352 if (NULL != cb) 349 if (NULL != cb)
353 cb (d->cb_cls, 350 cb (d->cb_cls, NULL, d->cfg, d,
354 NULL, 351 (NULL ==
355 d->cfg, 352 d->
356 d, 353 hostname) ?
357 (NULL == d->hostname) 354 _("Failed to create pipe for `gnunet-peerinfo' process.\n") :
358 ? _("Failed to create pipe for `gnunet-peerinfo' process.\n") 355 _("Failed to create pipe for `ssh' process.\n"));
359 : _("Failed to create pipe for `ssh' process.\n"));
360 return; 356 return;
361 } 357 }
362 if (NULL == d->hostname) 358 if (NULL == d->hostname)
@@ -369,8 +365,8 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
369#endif 365#endif
370 d->proc = 366 d->proc =
371 GNUNET_OS_start_process (NULL, d->pipe_stdout, "gnunet-peerinfo", 367 GNUNET_OS_start_process (NULL, d->pipe_stdout, "gnunet-peerinfo",
372 "gnunet-peerinfo", "-c", d->cfgfile, 368 "gnunet-peerinfo", "-c", d->cfgfile, "-sq",
373 "-sq", NULL); 369 NULL);
374 GNUNET_DISK_pipe_close_end (d->pipe_stdout, GNUNET_DISK_PIPE_END_WRITE); 370 GNUNET_DISK_pipe_close_end (d->pipe_stdout, GNUNET_DISK_PIPE_END_WRITE);
375 } 371 }
376 else 372 else
@@ -392,20 +388,19 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
392#if !DEBUG_TESTING 388#if !DEBUG_TESTING
393 "-q", 389 "-q",
394#endif 390#endif
395 dst, 391 dst, "gnunet-peerinfo", "-c",
396 "gnunet-peerinfo", 392 d->cfgfile, "-sq", NULL);
397 "-c", d->cfgfile, "-sq", NULL);
398 } 393 }
399 else 394 else
400 { 395 {
401 d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", 396 d->proc =
402 "ssh", "-p", d->ssh_port_str, 397 GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", "ssh", "-p",
398 d->ssh_port_str,
403#if !DEBUG_TESTING 399#if !DEBUG_TESTING
404 "-q", 400 "-q",
405#endif 401#endif
406 dst, 402 dst, "gnunet-peerinfo", "-c", d->cfgfile,
407 "gnunet-peerinfo", 403 "-sq", NULL);
408 "-c", d->cfgfile, "-sq", NULL);
409 } 404 }
410 GNUNET_DISK_pipe_close_end (d->pipe_stdout, GNUNET_DISK_PIPE_END_WRITE); 405 GNUNET_DISK_pipe_close_end (d->pipe_stdout, GNUNET_DISK_PIPE_END_WRITE);
411 GNUNET_free (dst); 406 GNUNET_free (dst);
@@ -418,13 +413,11 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
418 cb = d->cb; 413 cb = d->cb;
419 d->cb = NULL; 414 d->cb = NULL;
420 if (NULL != cb) 415 if (NULL != cb)
421 cb (d->cb_cls, 416 cb (d->cb_cls, NULL, d->cfg, d,
422 NULL, 417 (NULL ==
423 d->cfg, 418 d->
424 d, 419 hostname) ? _("Failed to start `gnunet-peerinfo' process.\n") :
425 (NULL == d->hostname) 420 _("Failed to start `ssh' process.\n"));
426 ? _("Failed to start `gnunet-peerinfo' process.\n")
427 : _("Failed to start `ssh' process.\n"));
428 GNUNET_DISK_pipe_close (d->pipe_stdout); 421 GNUNET_DISK_pipe_close (d->pipe_stdout);
429 return; 422 return;
430 } 423 }
@@ -433,13 +426,12 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
433 "Started `%s', waiting for hostkey.\n", "gnunet-peerinfo"); 426 "Started `%s', waiting for hostkey.\n", "gnunet-peerinfo");
434#endif 427#endif
435 d->phase = SP_HOSTKEY_CREATE; 428 d->phase = SP_HOSTKEY_CREATE;
436 d->task 429 d->task =
437 =
438 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining 430 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining
439 (d->max_timeout), 431 (d->max_timeout),
440 GNUNET_DISK_pipe_handle 432 GNUNET_DISK_pipe_handle (d->
441 (d->pipe_stdout, 433 pipe_stdout,
442 GNUNET_DISK_PIPE_END_READ), 434 GNUNET_DISK_PIPE_END_READ),
443 &start_fsm, d); 435 &start_fsm, d);
444 } 436 }
445 else /* Already have a hostkey! */ 437 else /* Already have a hostkey! */
@@ -469,21 +461,20 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
469 if ((d->hostkeybufpos < 104) && (bytes_read > 0)) 461 if ((d->hostkeybufpos < 104) && (bytes_read > 0))
470 { 462 {
471 /* keep reading */ 463 /* keep reading */
472 d->task 464 d->task =
473 =
474 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining 465 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining
475 (d->max_timeout), 466 (d->max_timeout),
476 GNUNET_DISK_pipe_handle 467 GNUNET_DISK_pipe_handle (d->
477 (d->pipe_stdout, 468 pipe_stdout,
478 GNUNET_DISK_PIPE_END_READ), 469 GNUNET_DISK_PIPE_END_READ),
479 &start_fsm, d); 470 &start_fsm, d);
480 return; 471 return;
481 } 472 }
482 d->hostkeybuf[103] = '\0'; 473 d->hostkeybuf[103] = '\0';
483 474
484 if ((bytes_read < 0) || 475 if ((bytes_read < 0) ||
485 (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (d->hostkeybuf, 476 (GNUNET_OK !=
486 &d->id.hashPubKey))) 477 GNUNET_CRYPTO_hash_from_string (d->hostkeybuf, &d->id.hashPubKey)))
487 { 478 {
488 /* error */ 479 /* error */
489 if (bytes_read < 0) 480 if (bytes_read < 0)
@@ -529,20 +520,20 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
529 /* Fall through */ 520 /* Fall through */
530 case SP_HOSTKEY_CREATED: 521 case SP_HOSTKEY_CREATED:
531 /* wait for topology finished */ 522 /* wait for topology finished */
532 if ((GNUNET_YES == d->dead) 523 if ((GNUNET_YES == d->dead) ||
533 || (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0)) 524 (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0))
534 { 525 {
535 cb = d->cb; 526 cb = d->cb;
536 d->cb = NULL; 527 d->cb = NULL;
537 if (NULL != cb) 528 if (NULL != cb)
538 cb (d->cb_cls, 529 cb (d->cb_cls, NULL, d->cfg, d,
539 NULL, d->cfg, d, _("`Failed while waiting for topology setup!\n")); 530 _("`Failed while waiting for topology setup!\n"));
540 return; 531 return;
541 } 532 }
542 533
543 d->task 534 d->task =
544 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, 535 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm,
545 &start_fsm, d); 536 d);
546 break; 537 break;
547 case SP_TOPOLOGY_SETUP: /* Indicates topology setup has completed! */ 538 case SP_TOPOLOGY_SETUP: /* Indicates topology setup has completed! */
548 /* start GNUnet on remote host */ 539 /* start GNUnet on remote host */
@@ -551,18 +542,19 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
551#if DEBUG_TESTING 542#if DEBUG_TESTING
552 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 543 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
553 "Starting `%s', with command `%s %s %s %s %s %s'.\n", 544 "Starting `%s', with command `%s %s %s %s %s %s'.\n",
554 "gnunet-arm", "gnunet-arm", "-c", d->cfgfile, 545 "gnunet-arm", "gnunet-arm", "-c", d->cfgfile, "-L", "DEBUG",
555 "-L", "DEBUG", "-s"); 546 "-s");
556#endif 547#endif
557 d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", 548 d->proc =
558 "gnunet-arm", "-c", d->cfgfile, 549 GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm", "-c",
550 d->cfgfile,
559#if DEBUG_TESTING 551#if DEBUG_TESTING
560 "-L", "DEBUG", 552 "-L", "DEBUG",
561#endif 553#endif
562 "-s", "-q", "-T", 554 "-s", "-q", "-T",
563 GNUNET_TIME_relative_to_string 555 GNUNET_TIME_relative_to_string
564 (GNUNET_TIME_absolute_get_remaining 556 (GNUNET_TIME_absolute_get_remaining
565 (d->max_timeout)), NULL); 557 (d->max_timeout)), NULL);
566 } 558 }
567 else 559 else
568 { 560 {
@@ -574,8 +566,8 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
574#if DEBUG_TESTING 566#if DEBUG_TESTING
575 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 567 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
576 "Starting `%s', with command `%s %s %s %s %s %s %s %s'.\n", 568 "Starting `%s', with command `%s %s %s %s %s %s %s %s'.\n",
577 "gnunet-arm", "ssh", dst, "gnunet-arm", "-c", 569 "gnunet-arm", "ssh", dst, "gnunet-arm", "-c", d->cfgfile,
578 d->cfgfile, "-L", "DEBUG", "-s", "-q"); 570 "-L", "DEBUG", "-s", "-q");
579#endif 571#endif
580 if (d->ssh_port_str == NULL) 572 if (d->ssh_port_str == NULL)
581 { 573 {
@@ -587,8 +579,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
587#if DEBUG_TESTING 579#if DEBUG_TESTING
588 "-L", "DEBUG", 580 "-L", "DEBUG",
589#endif 581#endif
590 "-c", d->cfgfile, "-s", "-q", 582 "-c", d->cfgfile, "-s", "-q", "-T",
591 "-T",
592 GNUNET_TIME_relative_to_string 583 GNUNET_TIME_relative_to_string
593 (GNUNET_TIME_absolute_get_remaining 584 (GNUNET_TIME_absolute_get_remaining
594 (d->max_timeout)), NULL); 585 (d->max_timeout)), NULL);
@@ -596,20 +587,20 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
596 else 587 else
597 { 588 {
598 589
599 d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", 590 d->proc =
600 "ssh", "-p", d->ssh_port_str, 591 GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", "-p",
592 d->ssh_port_str,
601#if !DEBUG_TESTING 593#if !DEBUG_TESTING
602 "-q", 594 "-q",
603#endif 595#endif
604 dst, "gnunet-arm", 596 dst, "gnunet-arm",
605#if DEBUG_TESTING 597#if DEBUG_TESTING
606 "-L", "DEBUG", 598 "-L", "DEBUG",
607#endif 599#endif
608 "-c", d->cfgfile, "-s", "-q", 600 "-c", d->cfgfile, "-s", "-q", "-T",
609 "-T", 601 GNUNET_TIME_relative_to_string
610 GNUNET_TIME_relative_to_string 602 (GNUNET_TIME_absolute_get_remaining
611 (GNUNET_TIME_absolute_get_remaining 603 (d->max_timeout)), NULL);
612 (d->max_timeout)), NULL);
613 } 604 }
614 GNUNET_free (dst); 605 GNUNET_free (dst);
615 } 606 }
@@ -621,24 +612,22 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
621 cb = d->cb; 612 cb = d->cb;
622 d->cb = NULL; 613 d->cb = NULL;
623 if (NULL != cb) 614 if (NULL != cb)
624 cb (d->cb_cls, 615 cb (d->cb_cls, NULL, d->cfg, d,
625 NULL, 616 (NULL ==
626 d->cfg, 617 d->
627 d, 618 hostname) ? _("Failed to start `gnunet-arm' process.\n") :
628 (NULL == d->hostname) 619 _("Failed to start `ssh' process.\n"));
629 ? _("Failed to start `gnunet-arm' process.\n")
630 : _("Failed to start `ssh' process.\n"));
631 return; 620 return;
632 } 621 }
633#if DEBUG_TESTING 622#if DEBUG_TESTING
634 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 623 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
635 "Started `%s', waiting for `%s' to be up.\n", 624 "Started `%s', waiting for `%s' to be up.\n", "gnunet-arm",
636 "gnunet-arm", "gnunet-service-core"); 625 "gnunet-service-core");
637#endif 626#endif
638 d->phase = SP_START_ARMING; 627 d->phase = SP_START_ARMING;
639 d->task 628 d->task =
640 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, 629 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm,
641 &start_fsm, d); 630 d);
642 break; 631 break;
643 case SP_START_ARMING: 632 case SP_START_ARMING:
644 if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) 633 if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code))
@@ -648,13 +637,11 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
648 cb = d->cb; 637 cb = d->cb;
649 d->cb = NULL; 638 d->cb = NULL;
650 if (NULL != cb) 639 if (NULL != cb)
651 cb (d->cb_cls, 640 cb (d->cb_cls, NULL, d->cfg, d,
652 NULL, 641 (NULL ==
653 d->cfg, 642 d->
654 d, 643 hostname) ? _("`gnunet-arm' does not seem to terminate.\n") :
655 (NULL == d->hostname) 644 _("`ssh' does not seem to terminate.\n"));
656 ? _("`gnunet-arm' does not seem to terminate.\n")
657 : _("`ssh' does not seem to terminate.\n"));
658 GNUNET_CONFIGURATION_destroy (d->cfg); 645 GNUNET_CONFIGURATION_destroy (d->cfg);
659 GNUNET_free (d->cfgfile); 646 GNUNET_free (d->cfgfile);
660 GNUNET_free_non_null (d->hostname); 647 GNUNET_free_non_null (d->hostname);
@@ -664,14 +651,14 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
664 return; 651 return;
665 } 652 }
666 /* wait some more */ 653 /* wait some more */
667 d->task 654 d->task =
668 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, 655 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm,
669 &start_fsm, d); 656 d);
670 return; 657 return;
671 } 658 }
672#if DEBUG_TESTING 659#if DEBUG_TESTING
673 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 660 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Successfully started `%s'.\n",
674 "Successfully started `%s'.\n", "gnunet-arm"); 661 "gnunet-arm");
675#endif 662#endif
676 GNUNET_free (d->proc); 663 GNUNET_free (d->proc);
677 d->phase = SP_START_CORE; 664 d->phase = SP_START_CORE;
@@ -689,9 +676,8 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
689 cb = d->cb; 676 cb = d->cb;
690 d->cb = NULL; 677 d->cb = NULL;
691 if (NULL != cb) 678 if (NULL != cb)
692 cb (d->cb_cls, 679 cb (d->cb_cls, NULL, d->cfg, d,
693 NULL, 680 _("Unable to connect to CORE service for peer!\n"));
694 d->cfg, d, _("Unable to connect to CORE service for peer!\n"));
695 GNUNET_CONFIGURATION_destroy (d->cfg); 681 GNUNET_CONFIGURATION_destroy (d->cfg);
696 GNUNET_free (d->cfgfile); 682 GNUNET_free (d->cfgfile);
697 GNUNET_free_non_null (d->hostname); 683 GNUNET_free_non_null (d->hostname);
@@ -699,14 +685,10 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
699 GNUNET_free (d); 685 GNUNET_free (d);
700 return; 686 return;
701 } 687 }
702 d->server = GNUNET_CORE_connect (d->cfg, 1, 688 d->server =
703 d, 689 GNUNET_CORE_connect (d->cfg, 1, d, &testing_init, NULL, NULL, NULL,
704 &testing_init, 690 NULL, GNUNET_NO, NULL, GNUNET_NO, no_handlers);
705 NULL, NULL, NULL, 691 d->task =
706 NULL, GNUNET_NO,
707 NULL, GNUNET_NO, no_handlers);
708 d->task
709 =
710 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 692 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
711 (GNUNET_CONSTANTS_SERVICE_RETRY, 2), 693 (GNUNET_CONSTANTS_SERVICE_RETRY, 2),
712 &start_fsm, d); 694 &start_fsm, d);
@@ -716,9 +698,10 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
716 { 698 {
717 if (GNUNET_YES == d->dead) 699 if (GNUNET_YES == d->dead)
718 GNUNET_TESTING_daemon_stop (d, 700 GNUNET_TESTING_daemon_stop (d,
719 GNUNET_TIME_absolute_get_remaining 701 GNUNET_TIME_absolute_get_remaining (d->
720 (d->max_timeout), d->dead_cb, 702 max_timeout),
721 d->dead_cb_cls, GNUNET_YES, GNUNET_NO); 703 d->dead_cb, d->dead_cb_cls, GNUNET_YES,
704 GNUNET_NO);
722 else if (NULL != d->cb) 705 else if (NULL != d->cb)
723 d->cb (d->cb_cls, &d->id, d->cfg, d, 706 d->cb (d->cb_cls, &d->id, d->cfg, d,
724 _("Failed to connect to transport service!\n")); 707 _("Failed to connect to transport service!\n"));
@@ -761,8 +744,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
761 if (d->hello != NULL) 744 if (d->hello != NULL)
762 return; 745 return;
763 GNUNET_assert (d->task == GNUNET_SCHEDULER_NO_TASK); 746 GNUNET_assert (d->task == GNUNET_SCHEDULER_NO_TASK);
764 d->task 747 d->task =
765 =
766 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 748 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
767 (GNUNET_CONSTANTS_SERVICE_RETRY, 2), 749 (GNUNET_CONSTANTS_SERVICE_RETRY, 2),
768 &start_fsm, d); 750 &start_fsm, d);
@@ -779,19 +761,17 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
779 cb = d->cb; 761 cb = d->cb;
780 d->cb = NULL; 762 d->cb = NULL;
781 if (NULL != cb) 763 if (NULL != cb)
782 cb (d->cb_cls, 764 cb (d->cb_cls, NULL, d->cfg, d,
783 NULL, 765 (NULL ==
784 d->cfg, 766 d->
785 d, 767 hostname) ? _("`gnunet-arm' does not seem to terminate.\n") :
786 (NULL == d->hostname) 768 _("`ssh' does not seem to terminate.\n"));
787 ? _("`gnunet-arm' does not seem to terminate.\n")
788 : _("`ssh' does not seem to terminate.\n"));
789 return; 769 return;
790 } 770 }
791 /* wait some more */ 771 /* wait some more */
792 d->task 772 d->task =
793 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, 773 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm,
794 &start_fsm, d); 774 d);
795 return; 775 return;
796 } 776 }
797#if EXTRA_CHECKS 777#if EXTRA_CHECKS
@@ -800,12 +780,10 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
800 cb = d->cb; 780 cb = d->cb;
801 d->cb = NULL; 781 d->cb = NULL;
802 if (NULL != cb) 782 if (NULL != cb)
803 cb (d->cb_cls, 783 cb (d->cb_cls, NULL, d->cfg, d,
804 NULL, 784 (NULL ==
805 d->cfg, 785 d->
806 d, 786 hostname) ?
807 (NULL == d->hostname)
808 ?
809 _ 787 _
810 ("`gnunet-arm' terminated with non-zero exit status (or timed out)!\n") 788 ("`gnunet-arm' terminated with non-zero exit status (or timed out)!\n")
811 : _("`ssh' does not seem to terminate.\n")); 789 : _("`ssh' does not seem to terminate.\n"));
@@ -834,9 +812,9 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
834 return; 812 return;
835 } 813 }
836 /* wait some more */ 814 /* wait some more */
837 d->task 815 d->task =
838 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, 816 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm,
839 &start_fsm, d); 817 d);
840 return; 818 return;
841 } 819 }
842#if EXTRA_CHECKS 820#if EXTRA_CHECKS
@@ -883,9 +861,9 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
883 return; 861 return;
884 } 862 }
885 /* wait some more */ 863 /* wait some more */
886 d->task 864 d->task =
887 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, 865 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm,
888 &start_fsm, d); 866 d);
889 return; 867 return;
890 } 868 }
891 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) 869 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
@@ -963,14 +941,14 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
963 cb = d->cb; 941 cb = d->cb;
964 d->cb = NULL; 942 d->cb = NULL;
965 if (NULL != cb) 943 if (NULL != cb)
966 cb (d->cb_cls, 944 cb (d->cb_cls, NULL, d->cfg, d,
967 NULL, d->cfg, d, _("`scp' does not seem to terminate.\n")); 945 _("`scp' does not seem to terminate.\n"));
968 return; 946 return;
969 } 947 }
970 /* wait some more */ 948 /* wait some more */
971 d->task 949 d->task =
972 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, 950 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm,
973 &start_fsm, d); 951 d);
974 return; 952 return;
975 } 953 }
976 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) 954 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
@@ -1231,8 +1209,7 @@ GNUNET_TESTING_daemon_start_stopped (struct GNUNET_TESTING_Daemon *daemon,
1231 daemon->phase = SP_TOPOLOGY_SETUP; 1209 daemon->phase = SP_TOPOLOGY_SETUP;
1232 daemon->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); 1210 daemon->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1233 1211
1234 GNUNET_SCHEDULER_add_continuation (&start_fsm, 1212 GNUNET_SCHEDULER_add_continuation (&start_fsm, daemon,
1235 daemon,
1236 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 1213 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1237} 1214}
1238 1215
@@ -1261,12 +1238,9 @@ GNUNET_TESTING_daemon_start_stopped (struct GNUNET_TESTING_Daemon *daemon,
1261 */ 1238 */
1262struct GNUNET_TESTING_Daemon * 1239struct GNUNET_TESTING_Daemon *
1263GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, 1240GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
1264 struct GNUNET_TIME_Relative timeout, 1241 struct GNUNET_TIME_Relative timeout, int pretend,
1265 int pretend, 1242 const char *hostname, const char *ssh_username,
1266 const char *hostname, 1243 uint16_t sshport, const char *hostkey,
1267 const char *ssh_username,
1268 uint16_t sshport,
1269 const char *hostkey,
1270 GNUNET_TESTING_NotifyHostkeyCreated 1244 GNUNET_TESTING_NotifyHostkeyCreated
1271 hostkey_callback, void *hostkey_cls, 1245 hostkey_callback, void *hostkey_cls,
1272 GNUNET_TESTING_NotifyDaemonRunning cb, 1246 GNUNET_TESTING_NotifyDaemonRunning cb,
@@ -1295,8 +1269,7 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
1295 1269
1296 /* Find service home and base service home directories, create it if it doesn't exist */ 1270 /* Find service home and base service home directories, create it if it doesn't exist */
1297 GNUNET_assert (GNUNET_OK == 1271 GNUNET_assert (GNUNET_OK ==
1298 GNUNET_CONFIGURATION_get_value_string (cfg, 1272 GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS",
1299 "PATHS",
1300 "SERVICEHOME", 1273 "SERVICEHOME",
1301 &servicehome)); 1274 &servicehome));
1302 1275
@@ -1321,9 +1294,8 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
1321 ret->cb_cls = cb_cls; 1294 ret->cb_cls = cb_cls;
1322 ret->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); 1295 ret->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1323 ret->cfg = GNUNET_CONFIGURATION_dup (cfg); 1296 ret->cfg = GNUNET_CONFIGURATION_dup (cfg);
1324 GNUNET_CONFIGURATION_set_value_string (ret->cfg, 1297 GNUNET_CONFIGURATION_set_value_string (ret->cfg, "PATHS", "DEFAULTCONFIG",
1325 "PATHS", 1298 ret->cfgfile);
1326 "DEFAULTCONFIG", ret->cfgfile);
1327 1299
1328 if (hostkey != NULL) /* Get the peer identity from the hostkey */ 1300 if (hostkey != NULL) /* Get the peer identity from the hostkey */
1329 { 1301 {
@@ -1344,8 +1316,8 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
1344 { 1316 {
1345 GNUNET_asprintf (&hostkeyfile, "%s/.hostkey", servicehome); 1317 GNUNET_asprintf (&hostkeyfile, "%s/.hostkey", servicehome);
1346 fn = GNUNET_DISK_file_open (hostkeyfile, 1318 fn = GNUNET_DISK_file_open (hostkeyfile,
1347 GNUNET_DISK_OPEN_READWRITE 1319 GNUNET_DISK_OPEN_READWRITE |
1348 | GNUNET_DISK_OPEN_CREATE, 1320 GNUNET_DISK_OPEN_CREATE,
1349 GNUNET_DISK_PERM_USER_READ | 1321 GNUNET_DISK_PERM_USER_READ |
1350 GNUNET_DISK_PERM_USER_WRITE); 1322 GNUNET_DISK_PERM_USER_WRITE);
1351 GNUNET_assert (fn != NULL); 1323 GNUNET_assert (fn != NULL);
@@ -1358,8 +1330,8 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
1358 if (GNUNET_OK != GNUNET_CONFIGURATION_write (ret->cfg, ret->cfgfile)) 1330 if (GNUNET_OK != GNUNET_CONFIGURATION_write (ret->cfg, ret->cfgfile))
1359 { 1331 {
1360 if (0 != UNLINK (ret->cfgfile)) 1332 if (0 != UNLINK (ret->cfgfile))
1361 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 1333 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink",
1362 "unlink", ret->cfgfile); 1334 ret->cfgfile);
1363 GNUNET_CONFIGURATION_destroy (ret->cfg); 1335 GNUNET_CONFIGURATION_destroy (ret->cfg);
1364 GNUNET_free_non_null (ret->hostname); 1336 GNUNET_free_non_null (ret->hostname);
1365 GNUNET_free (ret->cfgfile); 1337 GNUNET_free (ret->cfgfile);
@@ -1368,11 +1340,10 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
1368 } 1340 }
1369 if (ssh_username != NULL) 1341 if (ssh_username != NULL)
1370 username = GNUNET_strdup (ssh_username); 1342 username = GNUNET_strdup (ssh_username);
1371 if ((ssh_username == NULL) && (GNUNET_OK != 1343 if ((ssh_username == NULL) &&
1372 GNUNET_CONFIGURATION_get_value_string (cfg, 1344 (GNUNET_OK !=
1373 "TESTING", 1345 GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", "USERNAME",
1374 "USERNAME", 1346 &username)))
1375 &username)))
1376 { 1347 {
1377 if (NULL != getenv ("USER")) 1348 if (NULL != getenv ("USER"))
1378 username = GNUNET_strdup (getenv ("USER")); 1349 username = GNUNET_strdup (getenv ("USER"));
@@ -1420,13 +1391,13 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
1420 } 1391 }
1421 else 1392 else
1422 { 1393 {
1423 ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", 1394 ret->proc =
1424 "scp", "-r", "-P", 1395 GNUNET_OS_start_process (NULL, NULL, "scp", "scp", "-r", "-P",
1425 ret->ssh_port_str, 1396 ret->ssh_port_str,
1426#if !DEBUG_TESTING 1397#if !DEBUG_TESTING
1427 "-q", 1398 "-q",
1428#endif 1399#endif
1429 servicehome, arg, NULL); 1400 servicehome, arg, NULL);
1430 } 1401 }
1431 GNUNET_free (arg); 1402 GNUNET_free (arg);
1432 if (NULL == ret->proc) 1403 if (NULL == ret->proc)
@@ -1436,25 +1407,25 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
1436 ("Could not start `%s' process to copy configuration directory.\n"), 1407 ("Could not start `%s' process to copy configuration directory.\n"),
1437 "scp"); 1408 "scp");
1438 if (0 != UNLINK (ret->cfgfile)) 1409 if (0 != UNLINK (ret->cfgfile))
1439 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 1410 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink",
1440 "unlink", ret->cfgfile); 1411 ret->cfgfile);
1441 GNUNET_CONFIGURATION_destroy (ret->cfg); 1412 GNUNET_CONFIGURATION_destroy (ret->cfg);
1442 GNUNET_free_non_null (ret->hostname); 1413 GNUNET_free_non_null (ret->hostname);
1443 GNUNET_free_non_null (ret->username); 1414 GNUNET_free_non_null (ret->username);
1444 GNUNET_free (ret->cfgfile); 1415 GNUNET_free (ret->cfgfile);
1445 GNUNET_free (ret); 1416 GNUNET_free (ret);
1446 if ((hostkey != NULL) && (0 != UNLINK (hostkeyfile))) 1417 if ((hostkey != NULL) && (0 != UNLINK (hostkeyfile)))
1447 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 1418 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink",
1448 "unlink", hostkeyfile); 1419 hostkeyfile);
1449 GNUNET_free_non_null (hostkeyfile); 1420 GNUNET_free_non_null (hostkeyfile);
1450 GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (servicehome)); 1421 GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (servicehome));
1451 GNUNET_free (servicehome); 1422 GNUNET_free (servicehome);
1452 return NULL; 1423 return NULL;
1453 } 1424 }
1454 1425
1455 ret->task 1426 ret->task =
1456 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, 1427 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm,
1457 &start_fsm, ret); 1428 ret);
1458 GNUNET_free_non_null (hostkeyfile); 1429 GNUNET_free_non_null (hostkeyfile);
1459 GNUNET_free (servicehome); 1430 GNUNET_free (servicehome);
1460 return ret; 1431 return ret;
@@ -1464,8 +1435,7 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
1464 "No need to copy configuration file since we are running locally.\n"); 1435 "No need to copy configuration file since we are running locally.\n");
1465#endif 1436#endif
1466 ret->phase = SP_COPIED; 1437 ret->phase = SP_COPIED;
1467 GNUNET_SCHEDULER_add_continuation (&start_fsm, 1438 GNUNET_SCHEDULER_add_continuation (&start_fsm, ret,
1468 ret,
1469 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 1439 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1470 } 1440 }
1471 GNUNET_free_non_null (hostkeyfile); 1441 GNUNET_free_non_null (hostkeyfile);
@@ -1520,8 +1490,8 @@ GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d,
1520 GNUNET_free_non_null (d->hello); 1490 GNUNET_free_non_null (d->hello);
1521 1491
1522#if DEBUG_TESTING 1492#if DEBUG_TESTING
1523 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1493 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Terminating peer `%4s'\n"),
1524 _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id)); 1494 GNUNET_i2s (&d->id));
1525#endif 1495#endif
1526 1496
1527 d->phase = SP_START_ARMING; 1497 d->phase = SP_START_ARMING;
@@ -1567,9 +1537,8 @@ GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d,
1567 } 1537 }
1568 1538
1569 GNUNET_free_non_null (del_arg); 1539 GNUNET_free_non_null (del_arg);
1570 d->task 1540 d->task =
1571 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, 1541 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm, d);
1572 &start_fsm, d);
1573 1542
1574} 1543}
1575 1544
@@ -1608,8 +1577,8 @@ GNUNET_TESTING_daemon_stop_service (struct GNUNET_TESTING_Daemon *d,
1608 } 1577 }
1609 1578
1610#if DEBUG_TESTING 1579#if DEBUG_TESTING
1611 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1580 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Terminating peer `%4s'\n"),
1612 _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id)); 1581 GNUNET_i2s (&d->id));
1613#endif 1582#endif
1614 if (d->churned_services != NULL) 1583 if (d->churned_services != NULL)
1615 { 1584 {
@@ -1698,8 +1667,8 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
1698 if (NULL != d->cb) 1667 if (NULL != d->cb)
1699 { 1668 {
1700#if DEBUG_TESTING 1669#if DEBUG_TESTING
1701 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1670 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Setting d->dead on peer `%4s'\n"),
1702 _("Setting d->dead on peer `%4s'\n"), GNUNET_i2s (&d->id)); 1671 GNUNET_i2s (&d->id));
1703#endif 1672#endif
1704 d->dead = GNUNET_YES; 1673 d->dead = GNUNET_YES;
1705 return; 1674 return;
@@ -1746,8 +1715,8 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
1746 */ 1715 */
1747 /* shutdown ARM process (will terminate others) */ 1716 /* shutdown ARM process (will terminate others) */
1748#if DEBUG_TESTING 1717#if DEBUG_TESTING
1749 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1718 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Terminating peer `%4s'\n"),
1750 _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id)); 1719 GNUNET_i2s (&d->id));
1751#endif 1720#endif
1752 d->phase = SP_SHUTDOWN_START; 1721 d->phase = SP_SHUTDOWN_START;
1753 d->running = GNUNET_NO; 1722 d->running = GNUNET_NO;
@@ -1781,8 +1750,7 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
1781#if DEBUG_TESTING 1750#if DEBUG_TESTING
1782 "-L", "DEBUG", 1751 "-L", "DEBUG",
1783#endif 1752#endif
1784 "-c", d->cfgfile, "-e", "-q", 1753 "-c", d->cfgfile, "-e", "-q", "-T",
1785 "-T",
1786 GNUNET_TIME_relative_to_string (timeout), 1754 GNUNET_TIME_relative_to_string (timeout),
1787 del_arg, NULL); 1755 del_arg, NULL);
1788 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1756 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1801,8 +1769,7 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
1801#if DEBUG_TESTING 1769#if DEBUG_TESTING
1802 "-L", "DEBUG", 1770 "-L", "DEBUG",
1803#endif 1771#endif
1804 "-c", d->cfgfile, "-e", "-q", 1772 "-c", d->cfgfile, "-e", "-q", "-T",
1805 "-T",
1806 GNUNET_TIME_relative_to_string (timeout), 1773 GNUNET_TIME_relative_to_string (timeout),
1807 del_arg, NULL); 1774 del_arg, NULL);
1808 } 1775 }
@@ -1873,8 +1840,7 @@ GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d,
1873 if (NULL == d->proc) 1840 if (NULL == d->proc)
1874 { 1841 {
1875 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1842 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1876 _ 1843 _("Could not start `%s' process to copy configuration file.\n"),
1877 ("Could not start `%s' process to copy configuration file.\n"),
1878 "scp"); 1844 "scp");
1879 if (NULL != cb) 1845 if (NULL != cb)
1880 cb (cb_cls, _("Failed to copy new configuration to remote machine.")); 1846 cb (cb_cls, _("Failed to copy new configuration to remote machine."));
@@ -1883,9 +1849,8 @@ GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d,
1883 } 1849 }
1884 d->update_cb = cb; 1850 d->update_cb = cb;
1885 d->update_cb_cls = cb_cls; 1851 d->update_cb_cls = cb_cls;
1886 d->task 1852 d->task =
1887 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, 1853 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm, d);
1888 &start_fsm, d);
1889} 1854}
1890 1855
1891 1856
@@ -1981,9 +1946,9 @@ struct ConnectContext
1981 1946
1982 1947
1983/** Forward declaration **/ 1948/** Forward declaration **/
1984static void 1949static void reattempt_daemons_connect (void *cls,
1985reattempt_daemons_connect (void *cls, 1950 const struct GNUNET_SCHEDULER_TaskContext
1986 const struct GNUNET_SCHEDULER_TaskContext *tc); 1951 *tc);
1987 1952
1988 1953
1989/** 1954/**
@@ -2039,10 +2004,7 @@ notify_connect_result (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2039 { 2004 {
2040 if (ctx->cb != NULL) 2005 if (ctx->cb != NULL)
2041 { 2006 {
2042 ctx->cb (ctx->cb_cls, 2007 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->distance,
2043 &ctx->d1->id,
2044 &ctx->d2->id,
2045 ctx->distance,
2046 ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, NULL); 2008 ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, NULL);
2047 } 2009 }
2048 } 2010 }
@@ -2081,15 +2043,13 @@ notify_connect_result (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2081 * 2043 *
2082 */ 2044 */
2083static void 2045static void
2084connect_notify (void *cls, 2046connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
2085 const struct GNUNET_PeerIdentity *peer,
2086 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 2047 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
2087{ 2048{
2088 struct ConnectContext *ctx = cls; 2049 struct ConnectContext *ctx = cls;
2089 2050
2090#if DEBUG_TESTING 2051#if DEBUG_TESTING
2091 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2052 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Connected peer %s to peer %s\n",
2092 "Connected peer %s to peer %s\n",
2093 ctx->d1->shortname, GNUNET_i2s (peer)); 2053 ctx->d1->shortname, GNUNET_i2s (peer));
2094#endif 2054#endif
2095 2055
@@ -2118,8 +2078,7 @@ connect_notify (void *cls,
2118 * 2078 *
2119 */ 2079 */
2120static void 2080static void
2121connect_notify_core2 (void *cls, 2081connect_notify_core2 (void *cls, const struct GNUNET_PeerIdentity *peer,
2122 const struct GNUNET_PeerIdentity *peer,
2123 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 2082 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
2124{ 2083{
2125 struct ConnectContext *ctx = cls; 2084 struct ConnectContext *ctx = cls;
@@ -2158,9 +2117,9 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2158 ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK; 2117 ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK;
2159 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 2118 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
2160 return; 2119 return;
2161 if ((ctx->d1core_ready == GNUNET_YES) && (ctx->d2->hello != NULL) 2120 if ((ctx->d1core_ready == GNUNET_YES) && (ctx->d2->hello != NULL) &&
2162 && (NULL != GNUNET_HELLO_get_header (ctx->d2->hello)) 2121 (NULL != GNUNET_HELLO_get_header (ctx->d2->hello)) &&
2163 && (ctx->d1->phase == SP_START_DONE) && (ctx->d2->phase == SP_START_DONE)) 2122 (ctx->d1->phase == SP_START_DONE) && (ctx->d2->phase == SP_START_DONE))
2164 { 2123 {
2165 hello = GNUNET_HELLO_get_header (ctx->d2->hello); 2124 hello = GNUNET_HELLO_get_header (ctx->d2->hello);
2166 GNUNET_assert (hello != NULL); 2125 GNUNET_assert (hello != NULL);
@@ -2171,8 +2130,7 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2171 GNUNET_TRANSPORT_offer_hello (ctx->d1th, hello, NULL, NULL); 2130 GNUNET_TRANSPORT_offer_hello (ctx->d1th, hello, NULL, NULL);
2172 GNUNET_assert (ctx->d1core != NULL); 2131 GNUNET_assert (ctx->d1core != NULL);
2173 ctx->connect_request_handle = 2132 ctx->connect_request_handle =
2174 GNUNET_CORE_peer_request_connect (ctx->d1core, 2133 GNUNET_CORE_peer_request_connect (ctx->d1core, &ctx->d2->id,
2175 &ctx->d2->id,
2176 &core_connect_request_cont, ctx); 2134 &core_connect_request_cont, ctx);
2177 2135
2178#if DEBUG_TESTING 2136#if DEBUG_TESTING
@@ -2186,8 +2144,8 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2186 GNUNET_TIME_relative_multiply 2144 GNUNET_TIME_relative_multiply
2187 (GNUNET_TIME_UNIT_MILLISECONDS, 500)); 2145 (GNUNET_TIME_UNIT_MILLISECONDS, 500));
2188 } 2146 }
2189 ctx->hello_send_task = GNUNET_SCHEDULER_add_delayed (ctx->timeout_hello, 2147 ctx->hello_send_task =
2190 &send_hello, ctx); 2148 GNUNET_SCHEDULER_add_delayed (ctx->timeout_hello, &send_hello, ctx);
2191} 2149}
2192 2150
2193/** 2151/**
@@ -2199,11 +2157,10 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2199 * @param publicKey the public key of the peer 2157 * @param publicKey the public key of the peer
2200 */ 2158 */
2201void 2159void
2202core_init_notify (void *cls, 2160core_init_notify (void *cls, struct GNUNET_CORE_Handle *server,
2203 struct GNUNET_CORE_Handle *server,
2204 const struct GNUNET_PeerIdentity *my_identity, 2161 const struct GNUNET_PeerIdentity *my_identity,
2205 const struct 2162 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
2206 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) 2163 *publicKey)
2207{ 2164{
2208 struct ConnectContext *connect_ctx = cls; 2165 struct ConnectContext *connect_ctx = cls;
2209 2166
@@ -2246,12 +2203,10 @@ reattempt_daemons_connect (void *cls,
2246 ctx->connect_attempts--; 2203 ctx->connect_attempts--;
2247 GNUNET_assert (ctx->d1core == NULL); 2204 GNUNET_assert (ctx->d1core == NULL);
2248 ctx->d1core_ready = GNUNET_NO; 2205 ctx->d1core_ready = GNUNET_NO;
2249 ctx->d1core = GNUNET_CORE_connect (ctx->d1->cfg, 1, 2206 ctx->d1core =
2250 ctx, 2207 GNUNET_CORE_connect (ctx->d1->cfg, 1, ctx, &core_init_notify,
2251 &core_init_notify, 2208 &connect_notify, NULL, NULL, NULL, GNUNET_NO, NULL,
2252 &connect_notify, NULL, NULL, 2209 GNUNET_NO, no_handlers);
2253 NULL, GNUNET_NO,
2254 NULL, GNUNET_NO, no_handlers);
2255 if (ctx->d1core == NULL) 2210 if (ctx->d1core == NULL)
2256 { 2211 {
2257 if (NULL != ctx->cb) 2212 if (NULL != ctx->cb)
@@ -2299,9 +2254,9 @@ reattempt_daemons_connect (void *cls,
2299 2254
2300 if (ctx->send_hello == GNUNET_YES) 2255 if (ctx->send_hello == GNUNET_YES)
2301 { 2256 {
2302 ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg, 2257 ctx->d1th =
2303 &ctx->d1->id, 2258 GNUNET_TRANSPORT_connect (ctx->d1->cfg, &ctx->d1->id, ctx->d1, NULL,
2304 ctx->d1, NULL, NULL, NULL); 2259 NULL, NULL);
2305 if (ctx->d1th == NULL) 2260 if (ctx->d1th == NULL)
2306 { 2261 {
2307 GNUNET_CORE_disconnect (ctx->d1core); 2262 GNUNET_CORE_disconnect (ctx->d1core);
@@ -2317,8 +2272,7 @@ reattempt_daemons_connect (void *cls,
2317 else 2272 else
2318 { 2273 {
2319 ctx->connect_request_handle = 2274 ctx->connect_request_handle =
2320 GNUNET_CORE_peer_request_connect (ctx->d1core, 2275 GNUNET_CORE_peer_request_connect (ctx->d1core, &ctx->d2->id,
2321 &ctx->d2->id,
2322 &core_connect_request_cont, ctx); 2276 &core_connect_request_cont, ctx);
2323 } 2277 }
2324 ctx->timeout_task = 2278 ctx->timeout_task =
@@ -2338,8 +2292,7 @@ reattempt_daemons_connect (void *cls,
2338 * 2292 *
2339 */ 2293 */
2340static void 2294static void
2341core_initial_iteration (void *cls, 2295core_initial_iteration (void *cls, const struct GNUNET_PeerIdentity *peer,
2342 const struct GNUNET_PeerIdentity *peer,
2343 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 2296 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
2344{ 2297{
2345 struct ConnectContext *ctx = cls; 2298 struct ConnectContext *ctx = cls;
@@ -2355,8 +2308,8 @@ core_initial_iteration (void *cls,
2355 { 2308 {
2356 if (ctx->connected == GNUNET_YES) 2309 if (ctx->connected == GNUNET_YES)
2357 { 2310 {
2358 ctx->timeout_task = GNUNET_SCHEDULER_add_now (&notify_connect_result, 2311 ctx->timeout_task =
2359 ctx); 2312 GNUNET_SCHEDULER_add_now (&notify_connect_result, ctx);
2360 return; 2313 return;
2361 } 2314 }
2362 2315
@@ -2367,12 +2320,10 @@ core_initial_iteration (void *cls,
2367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2320 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2368 "Peers are NOT connected, connecting to core!\n"); 2321 "Peers are NOT connected, connecting to core!\n");
2369#endif 2322#endif
2370 ctx->d1core = GNUNET_CORE_connect (ctx->d1->cfg, 1, 2323 ctx->d1core =
2371 ctx, 2324 GNUNET_CORE_connect (ctx->d1->cfg, 1, ctx, &core_init_notify,
2372 &core_init_notify, 2325 &connect_notify, NULL, NULL, NULL, GNUNET_NO,
2373 &connect_notify, NULL, NULL, 2326 NULL, GNUNET_NO, no_handlers);
2374 NULL, GNUNET_NO,
2375 NULL, GNUNET_NO, no_handlers);
2376 } 2327 }
2377 2328
2378 if (ctx->d1core == NULL) 2329 if (ctx->d1core == NULL)
@@ -2405,9 +2356,9 @@ core_initial_iteration (void *cls,
2405 2356
2406 if (ctx->send_hello == GNUNET_YES) 2357 if (ctx->send_hello == GNUNET_YES)
2407 { 2358 {
2408 ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg, 2359 ctx->d1th =
2409 &ctx->d1->id, ctx->d1, NULL, NULL, 2360 GNUNET_TRANSPORT_connect (ctx->d1->cfg, &ctx->d1->id, ctx->d1, NULL,
2410 NULL); 2361 NULL, NULL);
2411 if (ctx->d1th == NULL) 2362 if (ctx->d1th == NULL)
2412 { 2363 {
2413 GNUNET_CORE_disconnect (ctx->d1core); 2364 GNUNET_CORE_disconnect (ctx->d1core);
@@ -2475,8 +2426,7 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
2475 ctx->connected = GNUNET_NO; 2426 ctx->connected = GNUNET_NO;
2476 ctx->send_hello = send_hello; 2427 ctx->send_hello = send_hello;
2477#if DEBUG_TESTING 2428#if DEBUG_TESTING
2478 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2429 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asked to connect peer %s to peer %s\n",
2479 "Asked to connect peer %s to peer %s\n",
2480 d1->shortname, d2->shortname); 2430 d1->shortname, d2->shortname);
2481#endif 2431#endif
2482 2432
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c
index 723afd456..d03cb307b 100644
--- a/src/testing/testing_group.c
+++ b/src/testing/testing_group.c
@@ -87,12 +87,13 @@ enum PeerLists
87 * Prototype of a function called whenever two peers would be connected 87 * Prototype of a function called whenever two peers would be connected
88 * in a certain topology. 88 * in a certain topology.
89 */ 89 */
90typedef unsigned int 90typedef unsigned int (*GNUNET_TESTING_ConnectionProcessor) (struct
91 (*GNUNET_TESTING_ConnectionProcessor) (struct GNUNET_TESTING_PeerGroup * pg, 91 GNUNET_TESTING_PeerGroup
92 unsigned int first, 92 * pg,
93 unsigned int second, 93 unsigned int first,
94 enum PeerLists list, 94 unsigned int second,
95 unsigned int check); 95 enum PeerLists list,
96 unsigned int check);
96 97
97/** 98/**
98 * Context for handling churning a peer group 99 * Context for handling churning a peer group
@@ -1091,8 +1092,8 @@ update_meter (struct ProgressMeter *meter)
1091 fprintf (stdout, "%sProgress: [0%%", meter->startup_string); 1092 fprintf (stdout, "%sProgress: [0%%", meter->startup_string);
1092 } 1093 }
1093 else 1094 else
1094 fprintf (stdout, "%d%%", (int) (((float) meter->completed 1095 fprintf (stdout, "%d%%",
1095 / meter->total) * 100)); 1096 (int) (((float) meter->completed / meter->total) * 100));
1096 } 1097 }
1097 else if (meter->completed % meter->dotnum == 0) 1098 else if (meter->completed % meter->dotnum == 0)
1098 fprintf (stdout, "."); 1099 fprintf (stdout, ".");
@@ -1332,24 +1333,24 @@ update_config (void *cls, const char *section, const char *option,
1332 1333
1333 if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival))) 1334 if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival)))
1334 { 1335 {
1335 if ((ival != 0) && (GNUNET_YES 1336 if ((ival != 0) &&
1336 != GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, 1337 (GNUNET_YES !=
1337 "testing", 1338 GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, "testing",
1338 single_variable))) 1339 single_variable)))
1339 { 1340 {
1340 GNUNET_snprintf (cval, sizeof (cval), "%u", ctx->nport++); 1341 GNUNET_snprintf (cval, sizeof (cval), "%u", ctx->nport++);
1341 value = cval; 1342 value = cval;
1342 } 1343 }
1343 else if ((ival != 0) && (GNUNET_YES 1344 else if ((ival != 0) &&
1344 == GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, 1345 (GNUNET_YES ==
1345 "testing", 1346 GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, "testing",
1346 single_variable)) 1347 single_variable)) &&
1347 && GNUNET_CONFIGURATION_get_value_number (ctx->orig, "testing", 1348 GNUNET_CONFIGURATION_get_value_number (ctx->orig, "testing",
1348 per_host_variable, 1349 per_host_variable,
1349 &num_per_host)) 1350 &num_per_host))
1350 { 1351 {
1351 GNUNET_snprintf (cval, sizeof (cval), "%u", ival + ctx->fdnum 1352 GNUNET_snprintf (cval, sizeof (cval), "%u",
1352 % num_per_host); 1353 ival + ctx->fdnum % num_per_host);
1353 value = cval; 1354 value = cval;
1354 } 1355 }
1355 1356
@@ -1361,23 +1362,23 @@ update_config (void *cls, const char *section, const char *option,
1361 1362
1362 if (0 == strcmp (option, "UNIXPATH")) 1363 if (0 == strcmp (option, "UNIXPATH"))
1363 { 1364 {
1364 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, 1365 if (GNUNET_YES !=
1365 "testing", 1366 GNUNET_CONFIGURATION_get_value_yesno (ctx->orig, "testing",
1366 single_variable)) 1367 single_variable))
1367 { 1368 {
1368 GNUNET_snprintf (uval, sizeof (uval), "/tmp/test-service-%s-%u", 1369 GNUNET_snprintf (uval, sizeof (uval), "/tmp/test-service-%s-%u", section,
1369 section, ctx->upnum++); 1370 ctx->upnum++);
1370 value = uval; 1371 value = uval;
1371 } 1372 }
1372 else if ((GNUNET_YES 1373 else if ((GNUNET_YES ==
1373 == GNUNET_CONFIGURATION_get_value_number (ctx->orig, "testing", 1374 GNUNET_CONFIGURATION_get_value_number (ctx->orig, "testing",
1374 per_host_variable, 1375 per_host_variable,
1375 &num_per_host)) 1376 &num_per_host)) &&
1376 && (num_per_host > 0)) 1377 (num_per_host > 0))
1377 1378
1378 { 1379 {
1379 GNUNET_snprintf (uval, sizeof (uval), "/tmp/test-service-%s-%u", 1380 GNUNET_snprintf (uval, sizeof (uval), "/tmp/test-service-%s-%u", section,
1380 section, ctx->fdnum % num_per_host); 1381 ctx->fdnum % num_per_host);
1381 value = uval; 1382 value = uval;
1382 } 1383 }
1383 } 1384 }
@@ -1437,10 +1438,10 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off,
1437 return NULL; 1438 return NULL;
1438 } 1439 }
1439 1440
1440 if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "testing", 1441 if ((GNUNET_OK ==
1441 "skew_variance", 1442 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "skew_variance",
1442 &skew_variance)) 1443 &skew_variance)) &&
1443 && (skew_variance > 0)) 1444 (skew_variance > 0))
1444 { 1445 {
1445 skew_offset = 1446 skew_offset =
1446 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 1447 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
@@ -1454,8 +1455,8 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off,
1454 skew_offset); 1455 skew_offset);
1455 } 1456 }
1456 1457
1457 if (GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "control_host", 1458 if (GNUNET_CONFIGURATION_get_value_string
1458 &control_host) == GNUNET_OK) 1459 (cfg, "testing", "control_host", &control_host) == GNUNET_OK)
1459 { 1460 {
1460 if (hostname != NULL) 1461 if (hostname != NULL)
1461 GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1; %s;", control_host, 1462 GNUNET_asprintf (&allowed_hosts, "%s; 127.0.0.1; %s;", control_host,
@@ -1469,12 +1470,12 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off,
1469 GNUNET_CONFIGURATION_set_value_string (uc.ret, "nse", "ACCEPT_FROM", 1470 GNUNET_CONFIGURATION_set_value_string (uc.ret, "nse", "ACCEPT_FROM",
1470 allowed_hosts); 1471 allowed_hosts);
1471 1472
1472 GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport", 1473 GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport", "ACCEPT_FROM",
1473 "ACCEPT_FROM", allowed_hosts); 1474 allowed_hosts);
1474 GNUNET_CONFIGURATION_set_value_string (uc.ret, "dht", "ACCEPT_FROM", 1475 GNUNET_CONFIGURATION_set_value_string (uc.ret, "dht", "ACCEPT_FROM",
1475 allowed_hosts); 1476 allowed_hosts);
1476 GNUNET_CONFIGURATION_set_value_string (uc.ret, "statistics", 1477 GNUNET_CONFIGURATION_set_value_string (uc.ret, "statistics", "ACCEPT_FROM",
1477 "ACCEPT_FROM", allowed_hosts); 1478 allowed_hosts);
1478 1479
1479 GNUNET_CONFIGURATION_set_value_string (uc.ret, "core", "UNIXPATH", ""); 1480 GNUNET_CONFIGURATION_set_value_string (uc.ret, "core", "UNIXPATH", "");
1480 GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport", "UNIXPATH", ""); 1481 GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport", "UNIXPATH", "");
@@ -1629,23 +1630,19 @@ remove_connections (struct GNUNET_TESTING_PeerGroup *pg, unsigned int first,
1629 } 1630 }
1630#else 1631#else
1631 if (GNUNET_YES == 1632 if (GNUNET_YES ==
1632 GNUNET_CONTAINER_multihashmap_contains (pg-> 1633 GNUNET_CONTAINER_multihashmap_contains (pg->peers[first].
1633 peers[first].blacklisted_peers, 1634 blacklisted_peers, &hash_second))
1634 &hash_second))
1635 { 1635 {
1636 GNUNET_CONTAINER_multihashmap_remove_all (pg-> 1636 GNUNET_CONTAINER_multihashmap_remove_all (pg->peers[first].
1637 peers[first].blacklisted_peers, 1637 blacklisted_peers, &hash_second);
1638 &hash_second);
1639 } 1638 }
1640 1639
1641 if (GNUNET_YES == 1640 if (GNUNET_YES ==
1642 GNUNET_CONTAINER_multihashmap_contains (pg-> 1641 GNUNET_CONTAINER_multihashmap_contains (pg->peers[second].
1643 peers[second].blacklisted_peers, 1642 blacklisted_peers, &hash_first))
1644 &hash_first))
1645 { 1643 {
1646 GNUNET_CONTAINER_multihashmap_remove_all (pg-> 1644 GNUNET_CONTAINER_multihashmap_remove_all (pg->peers[second].
1647 peers[second].blacklisted_peers, 1645 blacklisted_peers, &hash_first);
1648 &hash_first);
1649 } 1646 }
1650#endif 1647#endif
1651 1648
@@ -1801,22 +1798,22 @@ create_scale_free (struct GNUNET_TESTING_PeerGroup *pg,
1801 previous_total_connections = total_connections; 1798 previous_total_connections = total_connections;
1802 for (i = 0; i < outer_count; i++) 1799 for (i = 0; i < outer_count; i++)
1803 { 1800 {
1804 probability = pg->peers[i].num_connections 1801 probability =
1805 / (double) previous_total_connections; 1802 pg->peers[i].num_connections / (double) previous_total_connections;
1806 random 1803 random =
1807 = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 1804 ((double)
1808 UINT64_MAX)) 1805 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
1809 / ((double) UINT64_MAX); 1806 UINT64_MAX)) / ((double) UINT64_MAX);
1810#if VERBOSE_TESTING 1807#if VERBOSE_TESTING
1811 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1808 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1812 "Considering connecting peer %d to peer %d\n", 1809 "Considering connecting peer %d to peer %d\n", outer_count,
1813 outer_count, i); 1810 i);
1814#endif 1811#endif
1815 if (random < probability) 1812 if (random < probability)
1816 { 1813 {
1817#if VERBOSE_TESTING 1814#if VERBOSE_TESTING
1818 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1815 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %d to peer %d\n",
1819 "Connecting peer %d to peer %d\n", outer_count, i); 1816 outer_count, i);
1820#endif 1817#endif
1821 total_connections += proc (pg, outer_count, i, list, GNUNET_YES); 1818 total_connections += proc (pg, outer_count, i, list, GNUNET_YES);
1822 } 1819 }
@@ -1872,9 +1869,9 @@ create_small_world_ring (struct GNUNET_TESTING_PeerGroup *pg,
1872 int connect_attempts; 1869 int connect_attempts;
1873 1870
1874 logNModifier = 0.5; /* FIXME: default value? */ 1871 logNModifier = 0.5; /* FIXME: default value? */
1875 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", 1872 if (GNUNET_OK ==
1876 "PERCENTAGE", 1873 GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", "PERCENTAGE",
1877 &p_string)) 1874 &p_string))
1878 { 1875 {
1879 if (sscanf (p_string, "%lf", &logNModifier) != 1) 1876 if (sscanf (p_string, "%lf", &logNModifier) != 1)
1880 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1877 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -1884,9 +1881,9 @@ create_small_world_ring (struct GNUNET_TESTING_PeerGroup *pg,
1884 GNUNET_free (p_string); 1881 GNUNET_free (p_string);
1885 } 1882 }
1886 probability = 0.5; /* FIXME: default percentage? */ 1883 probability = 0.5; /* FIXME: default percentage? */
1887 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", 1884 if (GNUNET_OK ==
1888 "PROBABILITY", 1885 GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", "PROBABILITY",
1889 &p_string)) 1886 &p_string))
1890 { 1887 {
1891 if (sscanf (p_string, "%lf", &probability) != 1) 1888 if (sscanf (p_string, "%lf", &probability) != 1)
1892 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1889 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -1926,22 +1923,20 @@ create_small_world_ring (struct GNUNET_TESTING_PeerGroup *pg,
1926 1923
1927 for (j = 0; j < connsPerPeer / 2; j++) 1924 for (j = 0; j < connsPerPeer / 2; j++)
1928 { 1925 {
1929 random 1926 random =
1930 = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 1927 ((double)
1931 UINT64_MAX) 1928 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
1932 / ((double) UINT64_MAX)); 1929 UINT64_MAX) / ((double) UINT64_MAX));
1933 if (random < probability) 1930 if (random < probability)
1934 { 1931 {
1935 /* Connect to uniformly selected random peer */ 1932 /* Connect to uniformly selected random peer */
1936 randomPeer 1933 randomPeer =
1937 = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, pg->total); 1934 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, pg->total);
1938 while ((((randomPeer < max) && (randomPeer > min)) && (useAnd 1935 while ((((randomPeer < max) && (randomPeer > min)) && (useAnd == 0)) ||
1939 == 0)) ||
1940 (((randomPeer > min) || (randomPeer < max)) && (useAnd == 1))) 1936 (((randomPeer > min) || (randomPeer < max)) && (useAnd == 1)))
1941 { 1937 {
1942 randomPeer 1938 randomPeer =
1943 = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1939 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, pg->total);
1944 pg->total);
1945 } 1940 }
1946 smallWorldConnections += proc (pg, i, randomPeer, list, GNUNET_YES); 1941 smallWorldConnections += proc (pg, i, randomPeer, list, GNUNET_YES);
1947 } 1942 }
@@ -1987,9 +1982,9 @@ create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg,
1987 char *p_string; 1982 char *p_string;
1988 1983
1989 nat_percentage = 0.6; /* FIXME: default percentage? */ 1984 nat_percentage = 0.6; /* FIXME: default percentage? */
1990 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", 1985 if (GNUNET_OK ==
1991 "PERCENTAGE", 1986 GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", "PERCENTAGE",
1992 &p_string)) 1987 &p_string))
1993 { 1988 {
1994 if (sscanf (p_string, "%lf", &nat_percentage) != 1) 1989 if (sscanf (p_string, "%lf", &nat_percentage) != 1)
1995 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1990 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -2008,12 +2003,11 @@ create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg,
2008 if ((outer_count > cutoff) || (inner_count > cutoff)) 2003 if ((outer_count > cutoff) || (inner_count > cutoff))
2009 { 2004 {
2010#if VERBOSE_TESTING 2005#if VERBOSE_TESTING
2011 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2006 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %d to peer %d\n",
2012 "Connecting peer %d to peer %d\n",
2013 outer_count, inner_count); 2007 outer_count, inner_count);
2014#endif 2008#endif
2015 connect_attempts += proc (pg, outer_count, inner_count, list, 2009 connect_attempts +=
2016 GNUNET_YES); 2010 proc (pg, outer_count, inner_count, list, GNUNET_YES);
2017 } 2011 }
2018 } 2012 }
2019 } 2013 }
@@ -2047,9 +2041,9 @@ create_nated_internet_copy (struct GNUNET_TESTING_PeerGroup *pg,
2047 struct ProgressMeter *conn_meter; 2041 struct ProgressMeter *conn_meter;
2048 2042
2049 nat_percentage = 0.6; /* FIXME: default percentage? */ 2043 nat_percentage = 0.6; /* FIXME: default percentage? */
2050 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", 2044 if (GNUNET_OK ==
2051 "PERCENTAGE", 2045 GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", "PERCENTAGE",
2052 &p_string)) 2046 &p_string))
2053 { 2047 {
2054 if (sscanf (p_string, "%lf", &nat_percentage) != 1) 2048 if (sscanf (p_string, "%lf", &nat_percentage) != 1)
2055 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2049 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -2080,12 +2074,11 @@ create_nated_internet_copy (struct GNUNET_TESTING_PeerGroup *pg,
2080 if ((outer_count > cutoff) || (inner_count > cutoff)) 2074 if ((outer_count > cutoff) || (inner_count > cutoff))
2081 { 2075 {
2082#if VERBOSE_TESTING 2076#if VERBOSE_TESTING
2083 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2077 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %d to peer %d\n",
2084 "Connecting peer %d to peer %d\n",
2085 outer_count, inner_count); 2078 outer_count, inner_count);
2086#endif 2079#endif
2087 connect_attempts += proc (pg, outer_count, inner_count, list, 2080 connect_attempts +=
2088 GNUNET_YES); 2081 proc (pg, outer_count, inner_count, list, GNUNET_YES);
2089 add_connections (pg, outer_count, inner_count, ALLOWED, GNUNET_NO); 2082 add_connections (pg, outer_count, inner_count, ALLOWED, GNUNET_NO);
2090 update_meter (conn_meter); 2083 update_meter (conn_meter);
2091 } 2084 }
@@ -2137,9 +2130,9 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg,
2137 cols = square; 2130 cols = square;
2138 2131
2139 percentage = 0.5; /* FIXME: default percentage? */ 2132 percentage = 0.5; /* FIXME: default percentage? */
2140 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", 2133 if (GNUNET_OK ==
2141 "PERCENTAGE", 2134 GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", "PERCENTAGE",
2142 &p_string)) 2135 &p_string))
2143 { 2136 {
2144 if (sscanf (p_string, "%lf", &percentage) != 1) 2137 if (sscanf (p_string, "%lf", &percentage) != 1)
2145 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2138 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -2157,9 +2150,9 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg,
2157 percentage = 0.5; 2150 percentage = 0.5;
2158 } 2151 }
2159 probability = 0.5; /* FIXME: default percentage? */ 2152 probability = 0.5; /* FIXME: default percentage? */
2160 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", 2153 if (GNUNET_OK ==
2161 "PROBABILITY", 2154 GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", "PROBABILITY",
2162 &p_string)) 2155 &p_string))
2163 { 2156 {
2164 if (sscanf (p_string, "%lf", &probability) != 1) 2157 if (sscanf (p_string, "%lf", &probability) != 1)
2165 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2158 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -2182,8 +2175,7 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg,
2182 } 2175 }
2183#if VERBOSE_TESTING 2176#if VERBOSE_TESTING
2184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2185 _ 2178 _("Connecting nodes in 2d torus topology: %u rows %u columns\n"),
2186 ("Connecting nodes in 2d torus topology: %u rows %u columns\n"),
2187 rows, cols); 2179 rows, cols);
2188#endif 2180#endif
2189 2181
@@ -2220,8 +2212,8 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg,
2220 natLog = log (pg->total); 2212 natLog = log (pg->total);
2221#if VERBOSE_TESTING > 2 2213#if VERBOSE_TESTING > 2
2222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2223 _("natural log of %d is %d, will run %d iterations\n"), 2215 _("natural log of %d is %d, will run %d iterations\n"), pg->total,
2224 pg->total, natLog, (int) (natLog * percentage)); 2216 natLog, (int) (natLog * percentage));
2225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2217 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2226 _("Total connections added thus far: %u!\n"), connect_attempts); 2218 _("Total connections added thus far: %u!\n"), connect_attempts);
2227#endif 2219#endif
@@ -2249,10 +2241,10 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg,
2249 /* Calculate probability as 1 over the square of the distance */ 2241 /* Calculate probability as 1 over the square of the distance */
2250 probability = 1.0 / (distance * distance); 2242 probability = 1.0 / (distance * distance);
2251 /* Choose a random value between 0 and 1 */ 2243 /* Choose a random value between 0 and 1 */
2252 random 2244 random =
2253 = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 2245 ((double)
2254 UINT64_MAX)) 2246 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
2255 / ((double) UINT64_MAX); 2247 UINT64_MAX)) / ((double) UINT64_MAX);
2256 /* If random < probability, then connect the two nodes */ 2248 /* If random < probability, then connect the two nodes */
2257 if (random < probability) 2249 if (random < probability)
2258 smallWorldConnections += proc (pg, j, k, list, GNUNET_YES); 2250 smallWorldConnections += proc (pg, j, k, list, GNUNET_YES);
@@ -2295,9 +2287,9 @@ create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg,
2295 char *p_string; 2287 char *p_string;
2296 2288
2297 probability = 0.5; /* FIXME: default percentage? */ 2289 probability = 0.5; /* FIXME: default percentage? */
2298 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", 2290 if (GNUNET_OK ==
2299 "PROBABILITY", 2291 GNUNET_CONFIGURATION_get_value_string (pg->cfg, "TESTING", "PROBABILITY",
2300 &p_string)) 2292 &p_string))
2301 { 2293 {
2302 if (sscanf (p_string, "%lf", &probability) != 1) 2294 if (sscanf (p_string, "%lf", &probability) != 1)
2303 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2295 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -2311,18 +2303,18 @@ create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg,
2311 { 2303 {
2312 for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) 2304 for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++)
2313 { 2305 {
2314 temp_rand 2306 temp_rand =
2315 = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 2307 ((double)
2316 UINT64_MAX)) 2308 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
2317 / ((double) UINT64_MAX); 2309 UINT64_MAX)) / ((double) UINT64_MAX);
2318#if VERBOSE_TESTING 2310#if VERBOSE_TESTING
2319 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("rand is %f probability is %f\n"),
2320 _("rand is %f probability is %f\n"), temp_rand, probability); 2312 temp_rand, probability);
2321#endif 2313#endif
2322 if (temp_rand < probability) 2314 if (temp_rand < probability)
2323 { 2315 {
2324 connect_attempts += proc (pg, outer_count, inner_count, list, 2316 connect_attempts +=
2325 GNUNET_YES); 2317 proc (pg, outer_count, inner_count, list, GNUNET_YES);
2326 } 2318 }
2327 } 2319 }
2328 } 2320 }
@@ -2376,8 +2368,7 @@ create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg,
2376 } 2368 }
2377#if VERBOSE_TESTING 2369#if VERBOSE_TESTING
2378 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2370 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2379 _ 2371 _("Connecting nodes in 2d torus topology: %u rows %u columns\n"),
2380 ("Connecting nodes in 2d torus topology: %u rows %u columns\n"),
2381 rows, cols); 2372 rows, cols);
2382#endif 2373#endif
2383 /* Rows and columns are all sorted out, now iterate over all nodes and connect each 2374 /* Rows and columns are all sorted out, now iterate over all nodes and connect each
@@ -2395,8 +2386,8 @@ create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg,
2395 else 2386 else
2396 nodeToConnect = i - cols + 1; 2387 nodeToConnect = i - cols + 1;
2397#if VERBOSE_TESTING 2388#if VERBOSE_TESTING
2398 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2389 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %d to peer %d\n", i,
2399 "Connecting peer %d to peer %d\n", i, nodeToConnect); 2390 nodeToConnect);
2400#endif 2391#endif
2401 connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES); 2392 connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES);
2402 2393
@@ -2413,8 +2404,8 @@ create_2d_torus (struct GNUNET_TESTING_PeerGroup *pg,
2413 if (nodeToConnect < pg->total) 2404 if (nodeToConnect < pg->total)
2414 { 2405 {
2415#if VERBOSE_TESTING 2406#if VERBOSE_TESTING
2416 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %d to peer %d\n", i,
2417 "Connecting peer %d to peer %d\n", i, nodeToConnect); 2408 nodeToConnect);
2418#endif 2409#endif
2419 connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES); 2410 connect_attempts += proc (pg, i, nodeToConnect, list, GNUNET_YES);
2420 } 2411 }
@@ -2450,15 +2441,16 @@ create_clique (struct GNUNET_TESTING_PeerGroup *pg,
2450 2441
2451 connect_attempts = 0; 2442 connect_attempts = 0;
2452 2443
2453 conn_meter = create_meter ((((pg->total * pg->total) + pg->total) / 2) 2444 conn_meter =
2454 - pg->total, "Create Clique ", GNUNET_NO); 2445 create_meter ((((pg->total * pg->total) + pg->total) / 2) - pg->total,
2446 "Create Clique ", GNUNET_NO);
2455 for (outer_count = 0; outer_count < pg->total - 1; outer_count++) 2447 for (outer_count = 0; outer_count < pg->total - 1; outer_count++)
2456 { 2448 {
2457 for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++) 2449 for (inner_count = outer_count + 1; inner_count < pg->total; inner_count++)
2458 { 2450 {
2459#if VERBOSE_TESTING 2451#if VERBOSE_TESTING
2460 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2452 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %d to peer %d\n",
2461 "Connecting peer %d to peer %d\n", outer_count, inner_count); 2453 outer_count, inner_count);
2462#endif 2454#endif
2463 connect_attempts += proc (pg, outer_count, inner_count, list, check); 2455 connect_attempts += proc (pg, outer_count, inner_count, list, check);
2464 update_meter (conn_meter); 2456 update_meter (conn_meter);
@@ -2568,8 +2560,8 @@ create_line (struct GNUNET_TESTING_PeerGroup *pg,
2568 for (count = 0; count < pg->total - 1; count++) 2560 for (count = 0; count < pg->total - 1; count++)
2569 { 2561 {
2570#if VERBOSE_TESTING 2562#if VERBOSE_TESTING
2571 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2563 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %d to peer %d\n",
2572 "Connecting peer %d to peer %d\n", count, count + 1); 2564 count, count + 1);
2573#endif 2565#endif
2574 connect_attempts += proc (pg, count, count + 1, list, GNUNET_YES); 2566 connect_attempts += proc (pg, count, count + 1, list, GNUNET_YES);
2575 } 2567 }
@@ -2691,12 +2683,11 @@ create_from_file (struct GNUNET_TESTING_PeerGroup *pg, char *filename,
2691 return connect_attempts; 2683 return connect_attempts;
2692 } 2684 }
2693 /* Assume file is written with first peer 1, but array index is 0 */ 2685 /* Assume file is written with first peer 1, but array index is 0 */
2694 connect_attempts += proc (pg, first_peer_index - 1, second_peer_index 2686 connect_attempts +=
2695 - 1, list, GNUNET_YES); 2687 proc (pg, first_peer_index - 1, second_peer_index - 1, list,
2696 while ((buf[count] != '\n') && (buf[count] != ',') && (count 2688 GNUNET_YES);
2697 < 2689 while ((buf[count] != '\n') && (buf[count] != ',') &&
2698 frstat.st_size - 2690 (count < frstat.st_size - 1))
2699 1))
2700 count++; 2691 count++;
2701 if (buf[count] == '\n') 2692 if (buf[count] == '\n')
2702 { 2693 {
@@ -2746,8 +2737,8 @@ create_ring (struct GNUNET_TESTING_PeerGroup *pg,
2746 for (count = 0; count < pg->total - 1; count++) 2737 for (count = 0; count < pg->total - 1; count++)
2747 { 2738 {
2748#if VERBOSE_TESTING 2739#if VERBOSE_TESTING
2749 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2740 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %d to peer %d\n",
2750 "Connecting peer %d to peer %d\n", count, count + 1); 2741 count, count + 1);
2751#endif 2742#endif
2752 connect_attempts += proc (pg, count, count + 1, list, GNUNET_YES); 2743 connect_attempts += proc (pg, count, count + 1, list, GNUNET_YES);
2753 } 2744 }
@@ -2873,8 +2864,8 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg)
2873 conn_iter = pg->peers[pg_iter].allowed_peers_head; 2864 conn_iter = pg->peers[pg_iter].allowed_peers_head;
2874 while (conn_iter != NULL) 2865 while (conn_iter != NULL)
2875 { 2866 {
2876 GNUNET_CRYPTO_hash_to_enc (&pg->peers[conn_iter->index].daemon-> 2867 GNUNET_CRYPTO_hash_to_enc (&pg->peers[conn_iter->index].daemon->id.
2877 id.hashPubKey, &peer_enc); 2868 hashPubKey, &peer_enc);
2878 fprintf (temp_friend_handle, "%s\n", (char *) &peer_enc); 2869 fprintf (temp_friend_handle, "%s\n", (char *) &peer_enc);
2879 conn_iter = conn_iter->next; 2870 conn_iter = conn_iter->next;
2880 } 2871 }
@@ -2885,8 +2876,7 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg)
2885#endif 2876#endif
2886 fclose (temp_friend_handle); 2877 fclose (temp_friend_handle);
2887 2878
2888 if (GNUNET_OK 2879 if (GNUNET_OK !=
2889 !=
2890 GNUNET_CONFIGURATION_get_value_string (pg->peers[pg_iter].daemon->cfg, 2880 GNUNET_CONFIGURATION_get_value_string (pg->peers[pg_iter].daemon->cfg,
2891 "PATHS", "SERVICEHOME", 2881 "PATHS", "SERVICEHOME",
2892 &temp_service_path)) 2882 &temp_service_path))
@@ -2904,8 +2894,8 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg)
2904 if (pg->peers[pg_iter].daemon->hostname == NULL) /* Local, just copy the file */ 2894 if (pg->peers[pg_iter].daemon->hostname == NULL) /* Local, just copy the file */
2905 { 2895 {
2906 GNUNET_asprintf (&arg, "%s/friends", temp_service_path); 2896 GNUNET_asprintf (&arg, "%s/friends", temp_service_path);
2907 procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", "mv", 2897 procarr[pg_iter] =
2908 mytemp, arg, NULL); 2898 GNUNET_OS_start_process (NULL, NULL, "mv", "mv", mytemp, arg, NULL);
2909 GNUNET_assert (procarr[pg_iter] != NULL); 2899 GNUNET_assert (procarr[pg_iter] != NULL);
2910#if VERBOSE_TESTING 2900#if VERBOSE_TESTING
2911 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2901 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -2926,8 +2916,8 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg)
2926 GNUNET_asprintf (&arg, "%s:%s/friends", 2916 GNUNET_asprintf (&arg, "%s:%s/friends",
2927 pg->peers[pg_iter].daemon->hostname, 2917 pg->peers[pg_iter].daemon->hostname,
2928 temp_service_path); 2918 temp_service_path);
2929 procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", 2919 procarr[pg_iter] =
2930 mytemp, arg, NULL); 2920 GNUNET_OS_start_process (NULL, NULL, "scp", "scp", mytemp, arg, NULL);
2931 GNUNET_assert (procarr[pg_iter] != NULL); 2921 GNUNET_assert (procarr[pg_iter] != NULL);
2932 ret = GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: schedule this, throttle! */ 2922 ret = GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: schedule this, throttle! */
2933 GNUNET_OS_process_close (procarr[pg_iter]); 2923 GNUNET_OS_process_close (procarr[pg_iter]);
@@ -2960,13 +2950,13 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg)
2960 for (pg_iter = 0; pg_iter < pg->total; pg_iter++) 2950 for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
2961 { 2951 {
2962#if VERBOSE_TESTING 2952#if VERBOSE_TESTING
2963 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2953 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking copy status of file %d\n",
2964 "Checking copy status of file %d\n", pg_iter); 2954 pg_iter);
2965#endif 2955#endif
2966 if (procarr[pg_iter] != NULL) /* Check for already completed! */ 2956 if (procarr[pg_iter] != NULL) /* Check for already completed! */
2967 { 2957 {
2968 if (GNUNET_OS_process_status 2958 if (GNUNET_OS_process_status (procarr[pg_iter], &type, &return_code) !=
2969 (procarr[pg_iter], &type, &return_code) != GNUNET_OK) 2959 GNUNET_OK)
2970 { 2960 {
2971 ret = GNUNET_SYSERR; 2961 ret = GNUNET_SYSERR;
2972 } 2962 }
@@ -3061,15 +3051,15 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg,
3061 conn_iter = pg->peers[pg_iter].blacklisted_peers_head; 3051 conn_iter = pg->peers[pg_iter].blacklisted_peers_head;
3062 while (conn_iter != NULL) 3052 while (conn_iter != NULL)
3063 { 3053 {
3064 GNUNET_CRYPTO_hash_to_enc (&pg->peers[conn_iter->index].daemon-> 3054 GNUNET_CRYPTO_hash_to_enc (&pg->peers[conn_iter->index].daemon->id.
3065 id.hashPubKey, &peer_enc); 3055 hashPubKey, &peer_enc);
3066 fprintf (temp_file_handle, "%s:%s\n", pos, (char *) &peer_enc); 3056 fprintf (temp_file_handle, "%s:%s\n", pos, (char *) &peer_enc);
3067 conn_iter = conn_iter->next; 3057 conn_iter = conn_iter->next;
3068 } 3058 }
3069#else 3059#else
3070 blacklist_ctx.transport = pos; 3060 blacklist_ctx.transport = pos;
3071 (void) GNUNET_CONTAINER_multihashmap_iterate (pg->peers 3061 (void) GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].
3072 [pg_iter].blacklisted_peers, 3062 blacklisted_peers,
3073 &blacklist_file_iterator, 3063 &blacklist_file_iterator,
3074 &blacklist_ctx); 3064 &blacklist_ctx);
3075#endif 3065#endif
@@ -3084,8 +3074,7 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg,
3084 GNUNET_free (temp_transports); 3074 GNUNET_free (temp_transports);
3085 fclose (temp_file_handle); 3075 fclose (temp_file_handle);
3086 3076
3087 if (GNUNET_OK 3077 if (GNUNET_OK !=
3088 !=
3089 GNUNET_CONFIGURATION_get_value_string (pg->peers[pg_iter].daemon->cfg, 3078 GNUNET_CONFIGURATION_get_value_string (pg->peers[pg_iter].daemon->cfg,
3090 "PATHS", "SERVICEHOME", 3079 "PATHS", "SERVICEHOME",
3091 &temp_service_path)) 3080 &temp_service_path))
@@ -3103,8 +3092,8 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg,
3103 if (pg->peers[pg_iter].daemon->hostname == NULL) /* Local, just copy the file */ 3092 if (pg->peers[pg_iter].daemon->hostname == NULL) /* Local, just copy the file */
3104 { 3093 {
3105 GNUNET_asprintf (&arg, "%s/blacklist", temp_service_path); 3094 GNUNET_asprintf (&arg, "%s/blacklist", temp_service_path);
3106 procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", "mv", 3095 procarr[pg_iter] =
3107 mytemp, arg, NULL); 3096 GNUNET_OS_start_process (NULL, NULL, "mv", "mv", mytemp, arg, NULL);
3108#if VERBOSE_TESTING 3097#if VERBOSE_TESTING
3109 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3098 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3110 _("Copying file with command cp %s %s\n"), mytemp, arg); 3099 _("Copying file with command cp %s %s\n"), mytemp, arg);
@@ -3123,8 +3112,8 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg,
3123 GNUNET_asprintf (&arg, "%s:%s/blacklist", 3112 GNUNET_asprintf (&arg, "%s:%s/blacklist",
3124 pg->peers[pg_iter].daemon->hostname, 3113 pg->peers[pg_iter].daemon->hostname,
3125 temp_service_path); 3114 temp_service_path);
3126 procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", 3115 procarr[pg_iter] =
3127 mytemp, arg, NULL); 3116 GNUNET_OS_start_process (NULL, NULL, "scp", "scp", mytemp, arg, NULL);
3128 GNUNET_assert (procarr[pg_iter] != NULL); 3117 GNUNET_assert (procarr[pg_iter] != NULL);
3129 GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: add scheduled blacklist file copy that parallelizes file copying! */ 3118 GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: add scheduled blacklist file copy that parallelizes file copying! */
3130 3119
@@ -3151,8 +3140,8 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg,
3151#endif 3140#endif
3152 if (procarr[pg_iter] != NULL) /* Check for already completed! */ 3141 if (procarr[pg_iter] != NULL) /* Check for already completed! */
3153 { 3142 {
3154 if (GNUNET_OS_process_status (procarr[pg_iter], &type, 3143 if (GNUNET_OS_process_status (procarr[pg_iter], &type, &return_code) !=
3155 &return_code) != GNUNET_OK) 3144 GNUNET_OK)
3156 { 3145 {
3157 ret = GNUNET_SYSERR; 3146 ret = GNUNET_SYSERR;
3158 } 3147 }
@@ -3187,8 +3176,8 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg,
3187} 3176}
3188 3177
3189/* Forward Declaration */ 3178/* Forward Declaration */
3190static void 3179static void schedule_connect (void *cls,
3191schedule_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 3180 const struct GNUNET_SCHEDULER_TaskContext *tc);
3192 3181
3193/** 3182/**
3194 * Choose a random peer's next connection to create, and 3183 * Choose a random peer's next connection to create, and
@@ -3206,11 +3195,11 @@ preschedule_connect (struct GNUNET_TESTING_PeerGroup *pg)
3206 3195
3207 if (ct_ctx->remaining_connections == 0) 3196 if (ct_ctx->remaining_connections == 0)
3208 return; 3197 return;
3209 random_peer 3198 random_peer =
3210 = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, pg->total); 3199 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, pg->total);
3211 while (pg->peers[random_peer].connect_peers_head == NULL) 3200 while (pg->peers[random_peer].connect_peers_head == NULL)
3212 random_peer = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 3201 random_peer =
3213 pg->total); 3202 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, pg->total);
3214 3203
3215 connection_iter = pg->peers[random_peer].connect_peers_head; 3204 connection_iter = pg->peers[random_peer].connect_peers_head;
3216 connect_context = GNUNET_malloc (sizeof (struct ConnectContext)); 3205 connect_context = GNUNET_malloc (sizeof (struct ConnectContext));
@@ -3330,19 +3319,19 @@ send_core_connect_requests (void *cls,
3330 conn = send_hello_context->peer->connect_peers_head; 3319 conn = send_hello_context->peer->connect_peers_head;
3331 while (conn != NULL) 3320 while (conn != NULL)
3332 { 3321 {
3333 GNUNET_CORE_peer_request_connect (send_hello_context->peer-> 3322 GNUNET_CORE_peer_request_connect (send_hello_context->peer->daemon->
3334 daemon->server, 3323 server,
3335 &send_hello_context->pg-> 3324 &send_hello_context->pg->peers[conn->
3336 peers[conn->index].daemon->id, NULL, 3325 index].
3337 NULL); 3326 daemon->id, NULL, NULL);
3338 conn = conn->next; 3327 conn = conn->next;
3339 } 3328 }
3340 send_hello_context->core_connect_task = 3329 send_hello_context->core_connect_task =
3341 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide 3330 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
3342 (send_hello_context->pg-> 3331 (send_hello_context->pg->ct_ctx.
3343 ct_ctx.connect_timeout, 3332 connect_timeout,
3344 send_hello_context->pg-> 3333 send_hello_context->pg->ct_ctx.
3345 ct_ctx.connect_attempts), 3334 connect_attempts),
3346 &send_core_connect_requests, 3335 &send_core_connect_requests,
3347 send_hello_context); 3336 send_hello_context);
3348 } 3337 }
@@ -3368,8 +3357,7 @@ send_core_connect_requests (void *cls,
3368 * doesn't take too long! 3357 * doesn't take too long!
3369 */ 3358 */
3370static void 3359static void
3371core_connect_notify (void *cls, 3360core_connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
3372 const struct GNUNET_PeerIdentity *peer,
3373 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 3361 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
3374{ 3362{
3375 struct SendHelloContext *send_hello_context = cls; 3363 struct SendHelloContext *send_hello_context = cls;
@@ -3380,8 +3368,7 @@ core_connect_notify (void *cls,
3380 struct PeerData *other_peer; 3368 struct PeerData *other_peer;
3381#endif 3369#endif
3382#if DEBUG_TESTING 3370#if DEBUG_TESTING
3383 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3371 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Connected peer %s to peer %s\n",
3384 "Connected peer %s to peer %s\n",
3385 ctx->d1->shortname, GNUNET_i2s (peer)); 3372 ctx->d1->shortname, GNUNET_i2s (peer));
3386#endif 3373#endif
3387 3374
@@ -3474,8 +3461,7 @@ core_connect_notify (void *cls,
3474 * @param publicKey the public key of the peer 3461 * @param publicKey the public key of the peer
3475 */ 3462 */
3476void 3463void
3477core_init (void *cls, 3464core_init (void *cls, struct GNUNET_CORE_Handle *server,
3478 struct GNUNET_CORE_Handle *server,
3479 const struct GNUNET_PeerIdentity *my_identity, 3465 const struct GNUNET_PeerIdentity *my_identity,
3480 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) 3466 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
3481{ 3467{
@@ -3536,10 +3522,10 @@ hello_sent_callback (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3536 3522
3537 send_hello_context->core_connect_task = 3523 send_hello_context->core_connect_task =
3538 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide 3524 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
3539 (send_hello_context->pg-> 3525 (send_hello_context->pg->ct_ctx.
3540 ct_ctx.connect_timeout, 3526 connect_timeout,
3541 send_hello_context->pg-> 3527 send_hello_context->pg->ct_ctx.
3542 ct_ctx.connect_attempts), 3528 connect_attempts),
3543 &send_core_connect_requests, 3529 &send_core_connect_requests,
3544 send_hello_context); 3530 send_hello_context);
3545 } 3531 }
@@ -3590,22 +3576,22 @@ schedule_send_hellos (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3590 if (send_hello_context->peer->daemon->th == NULL) 3576 if (send_hello_context->peer->daemon->th == NULL)
3591 { 3577 {
3592 pg->outstanding_connects++; /* Actual TRANSPORT, CORE connections! */ 3578 pg->outstanding_connects++; /* Actual TRANSPORT, CORE connections! */
3593 send_hello_context->peer->daemon->th 3579 send_hello_context->peer->daemon->th =
3594 = GNUNET_TRANSPORT_connect (send_hello_context->peer->cfg, NULL, 3580 GNUNET_TRANSPORT_connect (send_hello_context->peer->cfg, NULL,
3595 send_hello_context, NULL, NULL, NULL); 3581 send_hello_context, NULL, NULL, NULL);
3596 } 3582 }
3597#if DEBUG_TESTING 3583#if DEBUG_TESTING
3598 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3584 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3599 _("Offering Hello of peer %s to peer %s\n"), 3585 _("Offering Hello of peer %s to peer %s\n"),
3600 send_hello_context->peer->daemon->shortname, 3586 send_hello_context->peer->daemon->shortname,
3601 pg->peers[send_hello_context->peer_pos->index]. 3587 pg->peers[send_hello_context->peer_pos->index].daemon->
3602 daemon->shortname); 3588 shortname);
3603#endif 3589#endif
3604 GNUNET_TRANSPORT_offer_hello (send_hello_context->peer->daemon->th, 3590 GNUNET_TRANSPORT_offer_hello (send_hello_context->peer->daemon->th,
3605 (const struct GNUNET_MessageHeader *) 3591 (const struct GNUNET_MessageHeader *) pg->
3606 pg->peers[send_hello_context->peer_pos-> 3592 peers[send_hello_context->peer_pos->index].
3607 index].daemon->hello, 3593 daemon->hello, &hello_sent_callback,
3608 &hello_sent_callback, send_hello_context); 3594 send_hello_context);
3609 send_hello_context->peer_pos = send_hello_context->peer_pos->next; 3595 send_hello_context->peer_pos = send_hello_context->peer_pos->next;
3610 GNUNET_assert (send_hello_context->peer->daemon->th != NULL); 3596 GNUNET_assert (send_hello_context->peer->daemon->th != NULL);
3611 } 3597 }
@@ -3644,12 +3630,10 @@ internal_connect_notify (void *cls, const struct GNUNET_PeerIdentity *first,
3644 other_peer = NULL; 3630 other_peer = NULL;
3645#endif 3631#endif
3646 3632
3647 while ((connection != NULL) && (0 3633 while ((connection != NULL) &&
3648 != memcmp (first, 3634 (0 !=
3649 &pg->peers[connection-> 3635 memcmp (first, &pg->peers[connection->index].daemon->id,
3650 index].daemon->id, 3636 sizeof (struct GNUNET_PeerIdentity))))
3651 sizeof (struct
3652 GNUNET_PeerIdentity))))
3653 { 3637 {
3654 connection = connection->next; 3638 connection = connection->next;
3655 } 3639 }
@@ -3659,16 +3643,14 @@ internal_connect_notify (void *cls, const struct GNUNET_PeerIdentity *first,
3659 GNUNET_assert (0 < ct_ctx->remaining_connections); 3643 GNUNET_assert (0 < ct_ctx->remaining_connections);
3660 ct_ctx->remaining_connections--; 3644 ct_ctx->remaining_connections--;
3661 if (pg->notify_connection != NULL) /* Notify of reverse connection */ 3645 if (pg->notify_connection != NULL) /* Notify of reverse connection */
3662 pg->notify_connection (pg->notify_connection_cls, second, first, 3646 pg->notify_connection (pg->notify_connection_cls, second, first, distance,
3663 distance, second_cfg, first_cfg, second_daemon, 3647 second_cfg, first_cfg, second_daemon, first_daemon,
3664 first_daemon, emsg); 3648 emsg);
3665 3649
3666 GNUNET_CONTAINER_DLL_remove (pg-> 3650 GNUNET_CONTAINER_DLL_remove (pg->peers[connect_ctx->second_index].
3667 peers[connect_ctx-> 3651 connect_peers_head,
3668 second_index].connect_peers_head, 3652 pg->peers[connect_ctx->second_index].
3669 pg->peers[connect_ctx-> 3653 connect_peers_tail, connection);
3670 second_index].connect_peers_tail,
3671 connection);
3672 GNUNET_free (connection); 3654 GNUNET_free (connection);
3673 } 3655 }
3674 3656
@@ -3707,8 +3689,8 @@ schedule_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3707 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 3689 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
3708 return; 3690 return;
3709 3691
3710 if ((pg->outstanding_connects > pg->max_outstanding_connections) 3692 if ((pg->outstanding_connects > pg->max_outstanding_connections) ||
3711 || (pg->stop_connects == GNUNET_YES)) 3693 (pg->stop_connects == GNUNET_YES))
3712 { 3694 {
3713#if VERBOSE_TESTING 3695#if VERBOSE_TESTING
3714 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3696 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -3729,10 +3711,10 @@ schedule_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3729#endif 3711#endif
3730 pg->outstanding_connects++; 3712 pg->outstanding_connects++;
3731 pg->total_connects_scheduled++; 3713 pg->total_connects_scheduled++;
3732 GNUNET_TESTING_daemons_connect (pg-> 3714 GNUNET_TESTING_daemons_connect (pg->peers[connect_context->first_index].
3733 peers[connect_context->first_index].daemon, 3715 daemon,
3734 pg->peers[connect_context-> 3716 pg->peers[connect_context->second_index].
3735 second_index].daemon, 3717 daemon,
3736 connect_context->ct_ctx->connect_timeout, 3718 connect_context->ct_ctx->connect_timeout,
3737 connect_context->ct_ctx->connect_attempts, 3719 connect_context->ct_ctx->connect_attempts,
3738#if USE_SEND_HELLOS 3720#if USE_SEND_HELLOS
@@ -4032,11 +4014,11 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
4032#if VERBOSE_TESTING 4014#if VERBOSE_TESTING
4033 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating topology from file!\n")); 4015 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Creating topology from file!\n"));
4034#endif 4016#endif
4035 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, "testing", 4017 if (GNUNET_OK ==
4036 "topology_file", 4018 GNUNET_CONFIGURATION_get_value_string (pg->cfg, "testing",
4037 &filename)) 4019 "topology_file", &filename))
4038 num_connections = create_from_file (pg, filename, &add_connections, 4020 num_connections =
4039 ALLOWED); 4021 create_from_file (pg, filename, &add_connections, ALLOWED);
4040 else 4022 else
4041 { 4023 {
4042 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 4024 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -4057,8 +4039,8 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
4057 break; 4039 break;
4058 } 4040 }
4059 4041
4060 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "TESTING", 4042 if (GNUNET_YES ==
4061 "F2F")) 4043 GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "TESTING", "F2F"))
4062 { 4044 {
4063 ret = create_and_copy_friend_files (pg); 4045 ret = create_and_copy_friend_files (pg);
4064 if (ret != GNUNET_OK) 4046 if (ret != GNUNET_OK)
@@ -4079,9 +4061,8 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
4079 } 4061 }
4080 4062
4081 /* Use the create clique method to initially set all connections as blacklisted. */ 4063 /* Use the create clique method to initially set all connections as blacklisted. */
4082 if ((restrict_topology != GNUNET_TESTING_TOPOLOGY_NONE) && (restrict_topology 4064 if ((restrict_topology != GNUNET_TESTING_TOPOLOGY_NONE) &&
4083 != 4065 (restrict_topology != GNUNET_TESTING_TOPOLOGY_FROM_FILE))
4084 GNUNET_TESTING_TOPOLOGY_FROM_FILE))
4085 create_clique (pg, &add_connections, BLACKLIST, GNUNET_NO); 4066 create_clique (pg, &add_connections, BLACKLIST, GNUNET_NO);
4086 else 4067 else
4087 return num_connections; 4068 return num_connections;
@@ -4095,49 +4076,48 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
4095 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4076 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4096 _("Blacklisting all but clique topology\n")); 4077 _("Blacklisting all but clique topology\n"));
4097#endif 4078#endif
4098 unblacklisted_connections = create_clique (pg, &remove_connections, 4079 unblacklisted_connections =
4099 BLACKLIST, GNUNET_NO); 4080 create_clique (pg, &remove_connections, BLACKLIST, GNUNET_NO);
4100 break; 4081 break;
4101 case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: 4082 case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING:
4102#if VERBOSE_TESTING 4083#if VERBOSE_TESTING
4103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4084 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4104 _("Blacklisting all but small world (ring) topology\n")); 4085 _("Blacklisting all but small world (ring) topology\n"));
4105#endif 4086#endif
4106 unblacklisted_connections = create_small_world_ring (pg, 4087 unblacklisted_connections =
4107 &remove_connections, 4088 create_small_world_ring (pg, &remove_connections, BLACKLIST);
4108 BLACKLIST);
4109 break; 4089 break;
4110 case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: 4090 case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD:
4111#if VERBOSE_TESTING 4091#if VERBOSE_TESTING
4112 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4092 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4113 _("Blacklisting all but small world (2d-torus) topology\n")); 4093 _("Blacklisting all but small world (2d-torus) topology\n"));
4114#endif 4094#endif
4115 unblacklisted_connections = create_small_world (pg, &remove_connections, 4095 unblacklisted_connections =
4116 BLACKLIST); 4096 create_small_world (pg, &remove_connections, BLACKLIST);
4117 break; 4097 break;
4118 case GNUNET_TESTING_TOPOLOGY_RING: 4098 case GNUNET_TESTING_TOPOLOGY_RING:
4119#if VERBOSE_TESTING 4099#if VERBOSE_TESTING
4120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4100 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4121 _("Blacklisting all but ring topology\n")); 4101 _("Blacklisting all but ring topology\n"));
4122#endif 4102#endif
4123 unblacklisted_connections 4103 unblacklisted_connections =
4124 = create_ring (pg, &remove_connections, BLACKLIST); 4104 create_ring (pg, &remove_connections, BLACKLIST);
4125 break; 4105 break;
4126 case GNUNET_TESTING_TOPOLOGY_2D_TORUS: 4106 case GNUNET_TESTING_TOPOLOGY_2D_TORUS:
4127#if VERBOSE_TESTING 4107#if VERBOSE_TESTING
4128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4108 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4129 _("Blacklisting all but 2d torus topology\n")); 4109 _("Blacklisting all but 2d torus topology\n"));
4130#endif 4110#endif
4131 unblacklisted_connections = create_2d_torus (pg, &remove_connections, 4111 unblacklisted_connections =
4132 BLACKLIST); 4112 create_2d_torus (pg, &remove_connections, BLACKLIST);
4133 break; 4113 break;
4134 case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: 4114 case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI:
4135#if VERBOSE_TESTING 4115#if VERBOSE_TESTING
4136 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4137 _("Blacklisting all but Erdos-Renyi topology\n")); 4117 _("Blacklisting all but Erdos-Renyi topology\n"));
4138#endif 4118#endif
4139 unblacklisted_connections = create_erdos_renyi (pg, &remove_connections, 4119 unblacklisted_connections =
4140 BLACKLIST); 4120 create_erdos_renyi (pg, &remove_connections, BLACKLIST);
4141 break; 4121 break;
4142 case GNUNET_TESTING_TOPOLOGY_INTERNAT: 4122 case GNUNET_TESTING_TOPOLOGY_INTERNAT:
4143#if VERBOSE_TESTING 4123#if VERBOSE_TESTING
@@ -4168,8 +4148,8 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
4168 pg->peers[off].connect_peers_head = NULL; 4148 pg->peers[off].connect_peers_head = NULL;
4169 pg->peers[off].connect_peers_tail = NULL; 4149 pg->peers[off].connect_peers_tail = NULL;
4170 } 4150 }
4171 unblacklisted_connections 4151 unblacklisted_connections =
4172 = create_nated_internet_copy (pg, &remove_connections, BLACKLIST); 4152 create_nated_internet_copy (pg, &remove_connections, BLACKLIST);
4173#else 4153#else
4174 unblacklisted_connections = 4154 unblacklisted_connections =
4175 create_nated_internet (pg, &remove_connections, BLACKLIST); 4155 create_nated_internet (pg, &remove_connections, BLACKLIST);
@@ -4181,16 +4161,16 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
4181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4182 _("Blacklisting all but Scale Free topology\n")); 4162 _("Blacklisting all but Scale Free topology\n"));
4183#endif 4163#endif
4184 unblacklisted_connections = create_scale_free (pg, &remove_connections, 4164 unblacklisted_connections =
4185 BLACKLIST); 4165 create_scale_free (pg, &remove_connections, BLACKLIST);
4186 break; 4166 break;
4187 case GNUNET_TESTING_TOPOLOGY_LINE: 4167 case GNUNET_TESTING_TOPOLOGY_LINE:
4188#if VERBOSE_TESTING 4168#if VERBOSE_TESTING
4189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4190 _("Blacklisting all but straight line topology\n")); 4170 _("Blacklisting all but straight line topology\n"));
4191#endif 4171#endif
4192 unblacklisted_connections 4172 unblacklisted_connections =
4193 = create_line (pg, &remove_connections, BLACKLIST); 4173 create_line (pg, &remove_connections, BLACKLIST);
4194 default: 4174 default:
4195 break; 4175 break;
4196 } 4176 }
@@ -4244,8 +4224,8 @@ random_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value)
4244 if (random_number < random_ctx->percentage) 4224 if (random_number < random_ctx->percentage)
4245 { 4225 {
4246 GNUNET_assert (GNUNET_OK == 4226 GNUNET_assert (GNUNET_OK ==
4247 GNUNET_CONTAINER_multihashmap_put (random_ctx-> 4227 GNUNET_CONTAINER_multihashmap_put (random_ctx->first->
4248 first->connect_peers_working_set, 4228 connect_peers_working_set,
4249 key, value, 4229 key, value,
4250 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 4230 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
4251 } 4231 }
@@ -4255,11 +4235,12 @@ random_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value)
4255 hash_from_uid (random_ctx->first_uid, &first_hash); 4235 hash_from_uid (random_ctx->first_uid, &first_hash);
4256 GNUNET_assert (random_ctx->pg->total > second_pos); 4236 GNUNET_assert (random_ctx->pg->total > second_pos);
4257 GNUNET_assert (GNUNET_YES == 4237 GNUNET_assert (GNUNET_YES ==
4258 GNUNET_CONTAINER_multihashmap_remove (random_ctx->pg->peers 4238 GNUNET_CONTAINER_multihashmap_remove (random_ctx->pg->
4259 [second_pos].connect_peers, 4239 peers[second_pos].
4240 connect_peers,
4260 &first_hash, 4241 &first_hash,
4261 random_ctx-> 4242 random_ctx->first->
4262 first->daemon)); 4243 daemon));
4263 4244
4264 return GNUNET_YES; 4245 return GNUNET_YES;
4265} 4246}
@@ -4289,25 +4270,29 @@ minimum_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value)
4289 if (min_ctx->pg_array[i] == min_ctx->current) 4270 if (min_ctx->pg_array[i] == min_ctx->current)
4290 { 4271 {
4291 GNUNET_assert (GNUNET_OK == 4272 GNUNET_assert (GNUNET_OK ==
4292 GNUNET_CONTAINER_multihashmap_put 4273 GNUNET_CONTAINER_multihashmap_put (min_ctx->first->
4293 (min_ctx->first->connect_peers_working_set, key, 4274 connect_peers_working_set,
4294 value, 4275 key, value,
4295 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 4276 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
4296 uid_from_hash (key, &second_pos); 4277 uid_from_hash (key, &second_pos);
4297 hash_from_uid (min_ctx->first_uid, &first_hash); 4278 hash_from_uid (min_ctx->first_uid, &first_hash);
4298 GNUNET_assert (min_ctx->pg->total > second_pos); 4279 GNUNET_assert (min_ctx->pg->total > second_pos);
4299 GNUNET_assert (GNUNET_OK == 4280 GNUNET_assert (GNUNET_OK ==
4300 GNUNET_CONTAINER_multihashmap_put (min_ctx->pg->peers 4281 GNUNET_CONTAINER_multihashmap_put (min_ctx->pg->
4301 [second_pos].connect_peers_working_set, 4282 peers[second_pos].
4283 connect_peers_working_set,
4302 &first_hash, 4284 &first_hash,
4303 min_ctx->first-> 4285 min_ctx->
4304 daemon, 4286 first->daemon,
4305 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 4287 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
4306 /* Now we have added this particular connection, remove it from the second peer's map so it's not double counted */ 4288 /* Now we have added this particular connection, remove it from the second peer's map so it's not double counted */
4307 GNUNET_assert (GNUNET_YES == 4289 GNUNET_assert (GNUNET_YES ==
4308 GNUNET_CONTAINER_multihashmap_remove 4290 GNUNET_CONTAINER_multihashmap_remove (min_ctx->pg->
4309 (min_ctx->pg->peers[second_pos].connect_peers, 4291 peers[second_pos].
4310 &first_hash, min_ctx->first->daemon)); 4292 connect_peers,
4293 &first_hash,
4294 min_ctx->first->
4295 daemon));
4311 } 4296 }
4312 } 4297 }
4313 min_ctx->current++; 4298 min_ctx->current++;
@@ -4336,26 +4321,28 @@ dfs_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value)
4336 if (dfs_ctx->current == dfs_ctx->chosen) 4321 if (dfs_ctx->current == dfs_ctx->chosen)
4337 { 4322 {
4338 GNUNET_assert (GNUNET_OK == 4323 GNUNET_assert (GNUNET_OK ==
4339 GNUNET_CONTAINER_multihashmap_put (dfs_ctx-> 4324 GNUNET_CONTAINER_multihashmap_put (dfs_ctx->first->
4340 first->connect_peers_working_set, 4325 connect_peers_working_set,
4341 key, value, 4326 key, value,
4342 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 4327 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
4343 uid_from_hash (key, &dfs_ctx->second_uid); 4328 uid_from_hash (key, &dfs_ctx->second_uid);
4344 hash_from_uid (dfs_ctx->first_uid, &first_hash); 4329 hash_from_uid (dfs_ctx->first_uid, &first_hash);
4345 GNUNET_assert (GNUNET_OK == 4330 GNUNET_assert (GNUNET_OK ==
4346 GNUNET_CONTAINER_multihashmap_put (dfs_ctx->pg->peers 4331 GNUNET_CONTAINER_multihashmap_put (dfs_ctx->pg->
4347 [dfs_ctx-> 4332 peers
4348 second_uid].connect_peers_working_set, 4333 [dfs_ctx->second_uid].
4334 connect_peers_working_set,
4349 &first_hash, 4335 &first_hash,
4350 dfs_ctx->first->daemon, 4336 dfs_ctx->first->daemon,
4351 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 4337 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
4352 GNUNET_assert (GNUNET_YES == 4338 GNUNET_assert (GNUNET_YES ==
4353 GNUNET_CONTAINER_multihashmap_remove (dfs_ctx-> 4339 GNUNET_CONTAINER_multihashmap_remove (dfs_ctx->pg->
4354 pg->peers 4340 peers[dfs_ctx->
4355 [dfs_ctx->second_uid].connect_peers, 4341 second_uid].
4342 connect_peers,
4356 &first_hash, 4343 &first_hash,
4357 dfs_ctx-> 4344 dfs_ctx->first->
4358 first->daemon)); 4345 daemon));
4359 /* Can't remove second from first yet because we are currently iterating, hence the return value in the DFSContext! */ 4346 /* Can't remove second from first yet because we are currently iterating, hence the return value in the DFSContext! */
4360 return GNUNET_NO; /* We have found our peer, don't iterate more */ 4347 return GNUNET_NO; /* We have found our peer, don't iterate more */
4361 } 4348 }
@@ -4391,10 +4378,10 @@ choose_random_connections (struct GNUNET_TESTING_PeerGroup *pg,
4391 conn_iter = pg->peers[pg_iter].connect_peers_head; 4378 conn_iter = pg->peers[pg_iter].connect_peers_head;
4392 while (conn_iter != NULL) 4379 while (conn_iter != NULL)
4393 { 4380 {
4394 random_number 4381 random_number =
4395 = ((double) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 4382 ((double)
4396 UINT64_MAX)) 4383 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
4397 / ((double) UINT64_MAX); 4384 UINT64_MAX)) / ((double) UINT64_MAX);
4398 if (random_number < percentage) 4385 if (random_number < percentage)
4399 { 4386 {
4400 add_connections (pg, pg_iter, conn_iter->index, WORKING_SET, 4387 add_connections (pg, pg_iter, conn_iter->index, WORKING_SET,
@@ -4407,16 +4394,16 @@ choose_random_connections (struct GNUNET_TESTING_PeerGroup *pg,
4407 random_ctx.first = &pg->peers[pg_iter]; 4394 random_ctx.first = &pg->peers[pg_iter];
4408 random_ctx.percentage = percentage; 4395 random_ctx.percentage = percentage;
4409 random_ctx.pg = pg; 4396 random_ctx.pg = pg;
4410 pg->peers[pg_iter].connect_peers_working_set 4397 pg->peers[pg_iter].connect_peers_working_set =
4411 = GNUNET_CONTAINER_multihashmap_create (pg->total); 4398 GNUNET_CONTAINER_multihashmap_create (pg->total);
4412 GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].connect_peers, 4399 GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].connect_peers,
4413 &random_connect_iterator, 4400 &random_connect_iterator,
4414 &random_ctx); 4401 &random_ctx);
4415 /* Now remove the old connections */ 4402 /* Now remove the old connections */
4416 GNUNET_CONTAINER_multihashmap_destroy (pg->peers[pg_iter].connect_peers); 4403 GNUNET_CONTAINER_multihashmap_destroy (pg->peers[pg_iter].connect_peers);
4417 /* And replace with the random set */ 4404 /* And replace with the random set */
4418 pg->peers[pg_iter].connect_peers 4405 pg->peers[pg_iter].connect_peers =
4419 = pg->peers[pg_iter].connect_peers_working_set; 4406 pg->peers[pg_iter].connect_peers_working_set;
4420#endif 4407#endif
4421 } 4408 }
4422 4409
@@ -4425,13 +4412,13 @@ choose_random_connections (struct GNUNET_TESTING_PeerGroup *pg,
4425 conn_iter = pg->peers[pg_iter].connect_peers_head; 4412 conn_iter = pg->peers[pg_iter].connect_peers_head;
4426 while (pg->peers[pg_iter].connect_peers_head != NULL) 4413 while (pg->peers[pg_iter].connect_peers_head != NULL)
4427 remove_connections (pg, pg_iter, 4414 remove_connections (pg, pg_iter,
4428 pg->peers[pg_iter].connect_peers_head->index, 4415 pg->peers[pg_iter].connect_peers_head->index, CONNECT,
4429 CONNECT, GNUNET_YES); 4416 GNUNET_YES);
4430 4417
4431 pg->peers[pg_iter].connect_peers_head 4418 pg->peers[pg_iter].connect_peers_head =
4432 = pg->peers[pg_iter].connect_peers_working_set_head; 4419 pg->peers[pg_iter].connect_peers_working_set_head;
4433 pg->peers[pg_iter].connect_peers_tail 4420 pg->peers[pg_iter].connect_peers_tail =
4434 = pg->peers[pg_iter].connect_peers_working_set_tail; 4421 pg->peers[pg_iter].connect_peers_working_set_tail;
4435 pg->peers[pg_iter].connect_peers_working_set_head = NULL; 4422 pg->peers[pg_iter].connect_peers_working_set_head = NULL;
4436 pg->peers[pg_iter].connect_peers_working_set_tail = NULL; 4423 pg->peers[pg_iter].connect_peers_working_set_tail = NULL;
4437 } 4424 }
@@ -4482,8 +4469,8 @@ count_workingset_connections (struct GNUNET_TESTING_PeerGroup *pg)
4482 } 4469 }
4483#else 4470#else
4484 count += 4471 count +=
4485 GNUNET_CONTAINER_multihashmap_size (pg->peers 4472 GNUNET_CONTAINER_multihashmap_size (pg->peers[pg_iter].
4486 [pg_iter].connect_peers_working_set); 4473 connect_peers_working_set);
4487#endif 4474#endif
4488 } 4475 }
4489 4476
@@ -4546,14 +4533,14 @@ choose_minimum (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num)
4546 temp_list_size = count_connections (pg->peers[pg_iter].connect_peers_head); 4533 temp_list_size = count_connections (pg->peers[pg_iter].connect_peers_head);
4547 if (temp_list_size == 0) 4534 if (temp_list_size == 0)
4548 { 4535 {
4549 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 4536 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Peer %d has 0 connections!?!?\n",
4550 "Peer %d has 0 connections!?!?\n", pg_iter); 4537 pg_iter);
4551 break; 4538 break;
4552 } 4539 }
4553 for (i = 0; i < num; i++) 4540 for (i = 0; i < num; i++)
4554 { 4541 {
4555 random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 4542 random =
4556 temp_list_size); 4543 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, temp_list_size);
4557 conn_iter = pg->peers[pg_iter].connect_peers_head; 4544 conn_iter = pg->peers[pg_iter].connect_peers_head;
4558 for (count = 0; count < random; count++) 4545 for (count = 0; count < random; count++)
4559 conn_iter = conn_iter->next; 4546 conn_iter = conn_iter->next;
@@ -4574,8 +4561,10 @@ choose_minimum (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num)
4574 minimum_ctx.first_uid = pg_iter; 4561 minimum_ctx.first_uid = pg_iter;
4575 minimum_ctx.pg_array = 4562 minimum_ctx.pg_array =
4576 GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, 4563 GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK,
4577 GNUNET_CONTAINER_multihashmap_size 4564 GNUNET_CONTAINER_multihashmap_size (pg->
4578 (pg->peers[pg_iter].connect_peers)); 4565 peers
4566 [pg_iter].
4567 connect_peers));
4579 minimum_ctx.first = &pg->peers[pg_iter]; 4568 minimum_ctx.first = &pg->peers[pg_iter];
4580 minimum_ctx.pg = pg; 4569 minimum_ctx.pg = pg;
4581 minimum_ctx.num_to_add = num; 4570 minimum_ctx.num_to_add = num;
@@ -4606,10 +4595,10 @@ choose_minimum (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num)
4606 /*remove_connections(pg, pg_iter, pg->peers[pg_iter].connect_peers_head->index, CONNECT, GNUNET_YES); */ 4595 /*remove_connections(pg, pg_iter, pg->peers[pg_iter].connect_peers_head->index, CONNECT, GNUNET_YES); */
4607 } 4596 }
4608 4597
4609 pg->peers[pg_iter].connect_peers_head 4598 pg->peers[pg_iter].connect_peers_head =
4610 = pg->peers[pg_iter].connect_peers_working_set_head; 4599 pg->peers[pg_iter].connect_peers_working_set_head;
4611 pg->peers[pg_iter].connect_peers_tail 4600 pg->peers[pg_iter].connect_peers_tail =
4612 = pg->peers[pg_iter].connect_peers_working_set_tail; 4601 pg->peers[pg_iter].connect_peers_working_set_tail;
4613 pg->peers[pg_iter].connect_peers_working_set_head = NULL; 4602 pg->peers[pg_iter].connect_peers_working_set_head = NULL;
4614 pg->peers[pg_iter].connect_peers_working_set_tail = NULL; 4603 pg->peers[pg_iter].connect_peers_working_set_tail = NULL;
4615 } 4604 }
@@ -4663,16 +4652,15 @@ find_closest_peers (void *cls, const GNUNET_HashCode * key, void *value)
4663 (GNUNET_CRYPTO_hash_matching_bits 4652 (GNUNET_CRYPTO_hash_matching_bits
4664 (&daemon->id.hashPubKey, 4653 (&daemon->id.hashPubKey,
4665 &closest_ctx->curr_peer->daemon->id.hashPubKey) > 4654 &closest_ctx->curr_peer->daemon->id.hashPubKey) >
4666 closest_ctx->closest_dist)) 4655 closest_ctx->closest_dist)) &&
4667 && (GNUNET_YES != 4656 (GNUNET_YES !=
4668 GNUNET_CONTAINER_multihashmap_contains (closest_ctx-> 4657 GNUNET_CONTAINER_multihashmap_contains (closest_ctx->curr_peer->
4669 curr_peer->connect_peers, 4658 connect_peers, key)))
4670 key)))
4671 { 4659 {
4672 closest_ctx->closest_dist = 4660 closest_ctx->closest_dist =
4673 GNUNET_CRYPTO_hash_matching_bits (&daemon->id.hashPubKey, 4661 GNUNET_CRYPTO_hash_matching_bits (&daemon->id.hashPubKey,
4674 &closest_ctx->curr_peer->daemon-> 4662 &closest_ctx->curr_peer->daemon->id.
4675 id.hashPubKey); 4663 hashPubKey);
4676 closest_ctx->closest = daemon; 4664 closest_ctx->closest = daemon;
4677 uid_from_hash (key, &closest_ctx->closest_num); 4665 uid_from_hash (key, &closest_ctx->closest_num);
4678 } 4666 }
@@ -4750,18 +4738,17 @@ perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num)
4750#if OLD 4738#if OLD
4751 starting_peer = 0; 4739 starting_peer = 0;
4752 dfs_count = 0; 4740 dfs_count = 0;
4753 while ((count_workingset_connections (pg) < num * pg->total) 4741 while ((count_workingset_connections (pg) < num * pg->total) &&
4754 && (count_allowed_connections (pg) > 0)) 4742 (count_allowed_connections (pg) > 0))
4755 { 4743 {
4756 if (dfs_count % pg->total == 0) /* Restart the DFS at some weakly connected peer */ 4744 if (dfs_count % pg->total == 0) /* Restart the DFS at some weakly connected peer */
4757 { 4745 {
4758 least_connections = -1; /* Set to very high number */ 4746 least_connections = -1; /* Set to very high number */
4759 for (pg_iter = 0; pg_iter < pg->total; pg_iter++) 4747 for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
4760 { 4748 {
4761 temp_count 4749 temp_count =
4762 = 4750 count_connections (pg->peers[pg_iter].
4763 count_connections (pg-> 4751 connect_peers_working_set_head);
4764 peers[pg_iter].connect_peers_working_set_head);
4765 if (temp_count < least_connections) 4752 if (temp_count < least_connections)
4766 { 4753 {
4767 starting_peer = pg_iter; 4754 starting_peer = pg_iter;
@@ -4770,13 +4757,13 @@ perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num)
4770 } 4757 }
4771 } 4758 }
4772 4759
4773 temp_count 4760 temp_count =
4774 = count_connections (pg->peers[starting_peer].connect_peers_head); 4761 count_connections (pg->peers[starting_peer].connect_peers_head);
4775 if (temp_count == 0) 4762 if (temp_count == 0)
4776 continue; /* FIXME: infinite loop? */ 4763 continue; /* FIXME: infinite loop? */
4777 4764
4778 random_connection = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 4765 random_connection =
4779 temp_count); 4766 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, temp_count);
4780 temp_count = 0; 4767 temp_count = 0;
4781 peer_iter = pg->peers[starting_peer].connect_peers_head; 4768 peer_iter = pg->peers[starting_peer].connect_peers_head;
4782 while (temp_count < random_connection) 4769 while (temp_count < random_connection)
@@ -4802,8 +4789,8 @@ perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num)
4802 4789
4803 starting_peer = 0; 4790 starting_peer = 0;
4804 dfs_count = 0; 4791 dfs_count = 0;
4805 while ((count_workingset_connections (pg) < num * pg->total) 4792 while ((count_workingset_connections (pg) < num * pg->total) &&
4806 && (count_allowed_connections (pg) > 0)) 4793 (count_allowed_connections (pg) > 0))
4807 { 4794 {
4808 if (dfs_count % pg->total == 0) /* Restart the DFS at some weakly connected peer */ 4795 if (dfs_count % pg->total == 0) /* Restart the DFS at some weakly connected peer */
4809 { 4796 {
@@ -4815,8 +4802,8 @@ perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num)
4815 { 4802 {
4816 starting_peer = pg_iter; 4803 starting_peer = pg_iter;
4817 least_connections = 4804 least_connections =
4818 GNUNET_CONTAINER_multihashmap_size (pg->peers 4805 GNUNET_CONTAINER_multihashmap_size (pg->peers[pg_iter].
4819 [pg_iter].connect_peers_working_set); 4806 connect_peers_working_set);
4820 } 4807 }
4821 } 4808 }
4822 } 4809 }
@@ -4830,25 +4817,28 @@ perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num)
4830 /* Choose a random peer from the chosen peers set of connections to add */ 4817 /* Choose a random peer from the chosen peers set of connections to add */
4831 dfs_ctx.chosen = 4818 dfs_ctx.chosen =
4832 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 4819 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
4833 GNUNET_CONTAINER_multihashmap_size 4820 GNUNET_CONTAINER_multihashmap_size (pg->
4834 (pg->peers[starting_peer].connect_peers)); 4821 peers
4822 [starting_peer].
4823 connect_peers));
4835 dfs_ctx.first_uid = starting_peer; 4824 dfs_ctx.first_uid = starting_peer;
4836 dfs_ctx.first = &pg->peers[starting_peer]; 4825 dfs_ctx.first = &pg->peers[starting_peer];
4837 dfs_ctx.pg = pg; 4826 dfs_ctx.pg = pg;
4838 dfs_ctx.current = 0; 4827 dfs_ctx.current = 0;
4839 4828
4840 GNUNET_CONTAINER_multihashmap_iterate (pg->peers 4829 GNUNET_CONTAINER_multihashmap_iterate (pg->peers[starting_peer].
4841 [starting_peer].connect_peers, 4830 connect_peers, &dfs_connect_iterator,
4842 &dfs_connect_iterator, &dfs_ctx); 4831 &dfs_ctx);
4843 /* Remove the second from the first, since we will be continuing the search and may encounter the first peer again! */ 4832 /* Remove the second from the first, since we will be continuing the search and may encounter the first peer again! */
4844 hash_from_uid (dfs_ctx.second_uid, &second_hash); 4833 hash_from_uid (dfs_ctx.second_uid, &second_hash);
4845 GNUNET_assert (GNUNET_YES == 4834 GNUNET_assert (GNUNET_YES ==
4846 GNUNET_CONTAINER_multihashmap_remove (pg->peers 4835 GNUNET_CONTAINER_multihashmap_remove (pg->
4847 [starting_peer].connect_peers, 4836 peers[starting_peer].
4837 connect_peers,
4848 &second_hash, 4838 &second_hash,
4849 pg-> 4839 pg->peers[dfs_ctx.
4850 peers 4840 second_uid].
4851 [dfs_ctx.second_uid].daemon)); 4841 daemon));
4852 starting_peer = dfs_ctx.second_uid; 4842 starting_peer = dfs_ctx.second_uid;
4853 } 4843 }
4854 4844
@@ -4906,8 +4896,8 @@ schedule_get_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
4906 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 4896 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
4907 return; 4897 return;
4908 4898
4909 if (topology_context->connected 4899 if (topology_context->connected >
4910 > topology_context->pg->max_outstanding_connections) 4900 topology_context->pg->max_outstanding_connections)
4911 { 4901 {
4912#if VERBOSE_TESTING > 2 4902#if VERBOSE_TESTING > 2
4913 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4903 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -4927,9 +4917,9 @@ schedule_get_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
4927#endif 4917#endif
4928 topology_context->connected++; 4918 topology_context->connected++;
4929 4919
4930 if (GNUNET_OK != GNUNET_CORE_iterate_peers (core_context->daemon->cfg, 4920 if (GNUNET_OK !=
4931 &internal_topology_callback, 4921 GNUNET_CORE_iterate_peers (core_context->daemon->cfg,
4932 core_context)) 4922 &internal_topology_callback, core_context))
4933 { 4923 {
4934 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Topology iteration failed.\n"); 4924 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Topology iteration failed.\n");
4935 internal_topology_callback (core_context, NULL, NULL); 4925 internal_topology_callback (core_context, NULL, NULL);
@@ -5068,19 +5058,19 @@ schedule_get_statistics (void *cls,
5068#endif 5058#endif
5069 5059
5070 stats_context->connected++; 5060 stats_context->connected++;
5071 core_context->stats_handle 5061 core_context->stats_handle =
5072 = GNUNET_STATISTICS_create ("testing", core_context->daemon->cfg); 5062 GNUNET_STATISTICS_create ("testing", core_context->daemon->cfg);
5073 if (core_context->stats_handle == NULL) 5063 if (core_context->stats_handle == NULL)
5074 { 5064 {
5075 internal_stats_cont (core_context, GNUNET_NO); 5065 internal_stats_cont (core_context, GNUNET_NO);
5076 return; 5066 return;
5077 } 5067 }
5078 5068
5079 core_context->stats_get_handle 5069 core_context->stats_get_handle =
5080 = GNUNET_STATISTICS_get (core_context->stats_handle, NULL, NULL, 5070 GNUNET_STATISTICS_get (core_context->stats_handle, NULL, NULL,
5081 GNUNET_TIME_relative_get_forever (), 5071 GNUNET_TIME_relative_get_forever (),
5082 &internal_stats_cont, 5072 &internal_stats_cont, &internal_stats_callback,
5083 &internal_stats_callback, core_context); 5073 core_context);
5084 if (core_context->stats_get_handle == NULL) 5074 if (core_context->stats_get_handle == NULL)
5085 internal_stats_cont (core_context, GNUNET_NO); 5075 internal_stats_cont (core_context, GNUNET_NO);
5086 5076
@@ -5121,21 +5111,20 @@ stats_check_existing (struct GNUNET_TESTING_PeerGroup *pg,
5121 unsigned long long port; 5111 unsigned long long port;
5122 char *to_match; 5112 char *to_match;
5123 5113
5124 if (GNUNET_YES 5114 if (GNUNET_YES !=
5125 != GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "testing", 5115 GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "testing",
5126 "single_statistics_per_host")) 5116 "single_statistics_per_host"))
5127 return GNUNET_NO; /* Each peer has its own statistics instance, do nothing! */ 5117 return GNUNET_NO; /* Each peer has its own statistics instance, do nothing! */
5128 5118
5129 pos = *stats_list; 5119 pos = *stats_list;
5130 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (specific_peer->cfg, 5120 if (GNUNET_OK !=
5131 "statistics", 5121 GNUNET_CONFIGURATION_get_value_string (specific_peer->cfg, "statistics",
5132 "unixpath", 5122 "unixpath", &unix_domain_socket))
5133 &unix_domain_socket))
5134 return GNUNET_NO; 5123 return GNUNET_NO;
5135 5124
5136 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (specific_peer->cfg, 5125 if (GNUNET_OK !=
5137 "statistics", "port", 5126 GNUNET_CONFIGURATION_get_value_number (specific_peer->cfg, "statistics",
5138 &port)) 5127 "port", &port))
5139 { 5128 {
5140 GNUNET_free (unix_domain_socket); 5129 GNUNET_free (unix_domain_socket);
5141 return GNUNET_NO; 5130 return GNUNET_NO;
@@ -5200,11 +5189,8 @@ GNUNET_TESTING_get_statistics (struct GNUNET_TESTING_PeerGroup *pg,
5200 5189
5201 for (i = 0; i < pg->total; i++) 5190 for (i = 0; i < pg->total; i++)
5202 { 5191 {
5203 if ((pg->peers[i].daemon->running == GNUNET_YES) && (GNUNET_NO 5192 if ((pg->peers[i].daemon->running == GNUNET_YES) &&
5204 == 5193 (GNUNET_NO == stats_check_existing (pg, &pg->peers[i], &stats_list)))
5205 stats_check_existing
5206 (pg, &pg->peers[i],
5207 &stats_list)))
5208 { 5194 {
5209 /* Allocate one core context per core we need to connect to */ 5195 /* Allocate one core context per core we need to connect to */
5210 core_ctx = GNUNET_malloc (sizeof (struct StatsCoreContext)); 5196 core_ctx = GNUNET_malloc (sizeof (struct StatsCoreContext));
@@ -5358,8 +5344,8 @@ GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg,
5358 copy_allowed_topology (pg); 5344 copy_allowed_topology (pg);
5359 break; 5345 break;
5360 default: 5346 default:
5361 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ 5347 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
5362 ("Unknown topology specification, can't connect peers!\n")); 5348 _("Unknown topology specification, can't connect peers!\n"));
5363 return GNUNET_SYSERR; 5349 return GNUNET_SYSERR;
5364 } 5350 }
5365 5351
@@ -5367,7 +5353,8 @@ GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg,
5367 { 5353 {
5368 case GNUNET_TESTING_TOPOLOGY_OPTION_RANDOM: 5354 case GNUNET_TESTING_TOPOLOGY_OPTION_RANDOM:
5369#if VERBOSE_TOPOLOGY 5355#if VERBOSE_TOPOLOGY
5370 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ 5356 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5357 _
5371 ("Connecting random subset (%'.2f percent) of possible peers\n"), 5358 ("Connecting random subset (%'.2f percent) of possible peers\n"),
5372 100 * option_modifier); 5359 100 * option_modifier);
5373#endif 5360#endif
@@ -5383,7 +5370,8 @@ GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg,
5383 break; 5370 break;
5384 case GNUNET_TESTING_TOPOLOGY_OPTION_DFS: 5371 case GNUNET_TESTING_TOPOLOGY_OPTION_DFS:
5385#if VERBOSE_TOPOLOGY 5372#if VERBOSE_TOPOLOGY
5386 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ 5373 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5374 _
5387 ("Using DFS to connect a minimum of %u peers each (if possible)\n"), 5375 ("Using DFS to connect a minimum of %u peers each (if possible)\n"),
5388 (unsigned int) option_modifier); 5376 (unsigned int) option_modifier);
5389#endif 5377#endif
@@ -5393,8 +5381,8 @@ GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg,
5393 break; 5381 break;
5394 case GNUNET_TESTING_TOPOLOGY_OPTION_ADD_CLOSEST: 5382 case GNUNET_TESTING_TOPOLOGY_OPTION_ADD_CLOSEST:
5395#if VERBOSE_TOPOLOGY 5383#if VERBOSE_TOPOLOGY
5396 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ 5384 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
5397 ("Finding additional %u closest peers each (if possible)\n"), 5385 _("Finding additional %u closest peers each (if possible)\n"),
5398 (unsigned int) option_modifier); 5386 (unsigned int) option_modifier);
5399#endif 5387#endif
5400#if FIXME 5388#if FIXME
@@ -5498,8 +5486,8 @@ internal_hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id,
5498 if (internal_context->hostkey_callback != NULL) 5486 if (internal_context->hostkey_callback != NULL)
5499 internal_context->hostkey_callback (internal_context->hostkey_cls, id, d, 5487 internal_context->hostkey_callback (internal_context->hostkey_cls, id, d,
5500 emsg); 5488 emsg);
5501 else if (internal_context->peer->pg->started 5489 else if (internal_context->peer->pg->started ==
5502 == internal_context->peer->pg->total) 5490 internal_context->peer->pg->total)
5503 { 5491 {
5504 internal_context->peer->pg->started = 0; /* Internal startup may use this counter! */ 5492 internal_context->peer->pg->started = 0; /* Internal startup may use this counter! */
5505 GNUNET_TESTING_daemons_continue_startup (internal_context->peer->pg); 5493 GNUNET_TESTING_daemons_continue_startup (internal_context->peer->pg);
@@ -5544,12 +5532,13 @@ internal_continue_startup (void *cls,
5544 return; 5532 return;
5545 } 5533 }
5546 5534
5547 if ((internal_context->peer->pg->starting 5535 if ((internal_context->peer->pg->starting <
5548 < internal_context->peer->pg->max_concurrent_ssh) 5536 internal_context->peer->pg->max_concurrent_ssh) ||
5549 || ((internal_context->hostname != NULL) 5537 ((internal_context->hostname != NULL) &&
5550 && (count_outstanding_at_host (internal_context->hostname, 5538 (count_outstanding_at_host
5551 internal_context->peer->pg) 5539 (internal_context->hostname,
5552 < internal_context->peer->pg->max_concurrent_ssh))) 5540 internal_context->peer->pg) <
5541 internal_context->peer->pg->max_concurrent_ssh)))
5553 { 5542 {
5554 if (internal_context->hostname != NULL) 5543 if (internal_context->hostname != NULL)
5555 increment_outstanding_at_host (internal_context->hostname, 5544 increment_outstanding_at_host (internal_context->hostname,
@@ -5599,8 +5588,9 @@ churn_start_callback (void *cls, const struct GNUNET_PeerIdentity *id,
5599 churn_ctx->num_to_start--; 5588 churn_ctx->num_to_start--;
5600 } 5589 }
5601 5590
5602 total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) 5591 total_left =
5603 + (churn_ctx->num_to_start - churn_ctx->num_failed_start); 5592 (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) +
5593 (churn_ctx->num_to_start - churn_ctx->num_failed_start);
5604 5594
5605 if (total_left == 0) 5595 if (total_left == 0)
5606 { 5596 {
@@ -5630,8 +5620,8 @@ schedule_churn_restart (void *cls,
5630 { 5620 {
5631 if (startup_ctx->churn_ctx->service != NULL) 5621 if (startup_ctx->churn_ctx->service != NULL)
5632 GNUNET_TESTING_daemon_start_stopped_service (peer_restart_ctx->daemon, 5622 GNUNET_TESTING_daemon_start_stopped_service (peer_restart_ctx->daemon,
5633 startup_ctx-> 5623 startup_ctx->churn_ctx->
5634 churn_ctx->service, 5624 service,
5635 startup_ctx->timeout, 5625 startup_ctx->timeout,
5636 &churn_start_callback, 5626 &churn_start_callback,
5637 startup_ctx); 5627 startup_ctx);
@@ -5655,8 +5645,7 @@ schedule_churn_restart (void *cls,
5655 * 5645 *
5656 */ 5646 */
5657void 5647void
5658service_start_callback (void *cls, 5648service_start_callback (void *cls, const struct GNUNET_PeerIdentity *id,
5659 const struct GNUNET_PeerIdentity *id,
5660 const struct GNUNET_CONFIGURATION_Handle *cfg, 5649 const struct GNUNET_CONFIGURATION_Handle *cfg,
5661 struct GNUNET_TESTING_Daemon *d, const char *emsg) 5650 struct GNUNET_TESTING_Daemon *d, const char *emsg)
5662{ 5651{
@@ -5693,8 +5682,7 @@ schedule_service_start (void *cls,
5693 else 5682 else
5694 { 5683 {
5695 5684
5696 GNUNET_TESTING_daemon_start_service (peer_ctx->daemon, 5685 GNUNET_TESTING_daemon_start_service (peer_ctx->daemon, startup_ctx->service,
5697 startup_ctx->service,
5698 startup_ctx->timeout, 5686 startup_ctx->timeout,
5699 &service_start_callback, startup_ctx); 5687 &service_start_callback, startup_ctx);
5700 GNUNET_free (peer_ctx); 5688 GNUNET_free (peer_ctx);
@@ -5712,29 +5700,29 @@ internal_start (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
5712 return; 5700 return;
5713 } 5701 }
5714 5702
5715 if ((internal_context->peer->pg->starting 5703 if ((internal_context->peer->pg->starting <
5716 < internal_context->peer->pg->max_concurrent_ssh) 5704 internal_context->peer->pg->max_concurrent_ssh) ||
5717 || ((internal_context->hostname != NULL) 5705 ((internal_context->hostname != NULL) &&
5718 && (count_outstanding_at_host (internal_context->hostname, 5706 (count_outstanding_at_host
5719 internal_context->peer->pg) 5707 (internal_context->hostname,
5720 < internal_context->peer->pg->max_concurrent_ssh))) 5708 internal_context->peer->pg) <
5709 internal_context->peer->pg->max_concurrent_ssh)))
5721 { 5710 {
5722 if (internal_context->hostname != NULL) 5711 if (internal_context->hostname != NULL)
5723 increment_outstanding_at_host (internal_context->hostname, 5712 increment_outstanding_at_host (internal_context->hostname,
5724 internal_context->peer->pg); 5713 internal_context->peer->pg);
5725 internal_context->peer->pg->starting++; 5714 internal_context->peer->pg->starting++;
5726 internal_context->peer->daemon 5715 internal_context->peer->daemon =
5727 = GNUNET_TESTING_daemon_start (internal_context->peer->cfg, 5716 GNUNET_TESTING_daemon_start (internal_context->peer->cfg,
5728 internal_context->timeout, 5717 internal_context->timeout, GNUNET_NO,
5729 GNUNET_NO, 5718 internal_context->hostname,
5730 internal_context->hostname, 5719 internal_context->username,
5731 internal_context->username, 5720 internal_context->sshport,
5732 internal_context->sshport, 5721 internal_context->hostkey,
5733 internal_context->hostkey, 5722 &internal_hostkey_callback,
5734 &internal_hostkey_callback, 5723 internal_context,
5735 internal_context, 5724 &internal_startup_callback,
5736 &internal_startup_callback, 5725 internal_context);
5737 internal_context);
5738 } 5726 }
5739 else 5727 else
5740 { 5728 {
@@ -5822,8 +5810,9 @@ start_peer_helper (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
5822 GNUNET_asprintf (&arg, "%s", helper->host->hostname); 5810 GNUNET_asprintf (&arg, "%s", helper->host->hostname);
5823 5811
5824 /* FIXME: Doesn't support ssh_port option! */ 5812 /* FIXME: Doesn't support ssh_port option! */
5825 helper->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", arg, 5813 helper->proc =
5826 "peerStartHelper.pl", tempdir, NULL); 5814 GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", arg,
5815 "peerStartHelper.pl", tempdir, NULL);
5827 GNUNET_assert (helper->proc != NULL); 5816 GNUNET_assert (helper->proc != NULL);
5828 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 5817 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
5829 "starting peers with cmd ssh %s %s %s\n", arg, 5818 "starting peers with cmd ssh %s %s %s\n", arg,
@@ -5891,9 +5880,9 @@ call_hostkey_callbacks (void *cls,
5891 for (i = 0; i < pg->total; i++) 5880 for (i = 0; i < pg->total; i++)
5892 { 5881 {
5893 if (pg->peers[i].internal_context.hostkey_callback != NULL) 5882 if (pg->peers[i].internal_context.hostkey_callback != NULL)
5894 pg->peers[i].internal_context.hostkey_callback (pg->peers 5883 pg->peers[i].internal_context.hostkey_callback (pg->
5895 [i]. 5884 peers[i].internal_context.
5896 internal_context.hostkey_cls, 5885 hostkey_cls,
5897 &pg->peers[i].daemon->id, 5886 &pg->peers[i].daemon->id,
5898 pg->peers[i].daemon, 5887 pg->peers[i].daemon,
5899 NULL); 5888 NULL);
@@ -6044,16 +6033,17 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
6044 if (pg->hosts[i].sshport != 0) 6033 if (pg->hosts[i].sshport != 0)
6045 { 6034 {
6046 GNUNET_asprintf (&ssh_port_str, "%d", pg->hosts[i].sshport); 6035 GNUNET_asprintf (&ssh_port_str, "%d", pg->hosts[i].sshport);
6047 proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", "-P", 6036 proc =
6048 ssh_port_str, 6037 GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", "-P", ssh_port_str,
6049#if !DEBUG_TESTING 6038#if !DEBUG_TESTING
6050 "-q", 6039 "-q",
6051#endif 6040#endif
6052 arg, "mkdir -p", tmpdir, NULL); 6041 arg, "mkdir -p", tmpdir, NULL);
6053 } 6042 }
6054 else 6043 else
6055 proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", arg, 6044 proc =
6056 "mkdir -p", tmpdir, NULL); 6045 GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", arg, "mkdir -p",
6046 tmpdir, NULL);
6057 GNUNET_assert (proc != NULL); 6047 GNUNET_assert (proc != NULL);
6058 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6048 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6059 "Creating remote dir with command ssh %s %s %s\n", arg, 6049 "Creating remote dir with command ssh %s %s %s\n", arg,
@@ -6066,9 +6056,9 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
6066 GNUNET_free (baseservicehome); 6056 GNUNET_free (baseservicehome);
6067 baseservicehome = NULL; 6057 baseservicehome = NULL;
6068 6058
6069 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", 6059 if (GNUNET_YES ==
6070 "HOSTKEYSFILE", 6060 GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", "HOSTKEYSFILE",
6071 &hostkeys_file)) 6061 &hostkeys_file))
6072 { 6062 {
6073 if (GNUNET_YES != GNUNET_DISK_file_test (hostkeys_file)) 6063 if (GNUNET_YES != GNUNET_DISK_file_test (hostkeys_file))
6074 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 6064 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -6076,12 +6066,12 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
6076 else 6066 else
6077 { 6067 {
6078 /* Check hostkey file size, read entire thing into memory */ 6068 /* Check hostkey file size, read entire thing into memory */
6079 fd = GNUNET_DISK_file_open (hostkeys_file, 6069 fd = GNUNET_DISK_file_open (hostkeys_file, GNUNET_DISK_OPEN_READ,
6080 GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE); 6070 GNUNET_DISK_PERM_NONE);
6081 if (NULL == fd) 6071 if (NULL == fd)
6082 { 6072 {
6083 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 6073 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open",
6084 "open", hostkeys_file); 6074 hostkeys_file);
6085 GNUNET_free (hostkeys_file); 6075 GNUNET_free (hostkeys_file);
6086 for (i = 0; i < pg->num_hosts; i++) 6076 for (i = 0; i < pg->num_hosts; i++)
6087 { 6077 {
@@ -6126,8 +6116,9 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
6126 hostname = pg->hosts[off % hostcnt].hostname; 6116 hostname = pg->hosts[off % hostcnt].hostname;
6127 username = pg->hosts[off % hostcnt].username; 6117 username = pg->hosts[off % hostcnt].username;
6128 sshport = pg->hosts[off % hostcnt].sshport; 6118 sshport = pg->hosts[off % hostcnt].sshport;
6129 pcfg = make_config (cfg, off, &pg->hosts[off % hostcnt].minport, 6119 pcfg =
6130 &upnum, hostname, &fdnum); 6120 make_config (cfg, off, &pg->hosts[off % hostcnt].minport, &upnum,
6121 hostname, &fdnum);
6131 } 6122 }
6132 else 6123 else
6133 { 6124 {
@@ -6146,10 +6137,9 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
6146 continue; 6137 continue;
6147 } 6138 }
6148 6139
6149 if (GNUNET_YES 6140 if (GNUNET_YES ==
6150 == GNUNET_CONFIGURATION_get_value_string (pcfg, "PATHS", 6141 GNUNET_CONFIGURATION_get_value_string (pcfg, "PATHS", "SERVICEHOME",
6151 "SERVICEHOME", 6142 &baseservicehome))
6152 &baseservicehome))
6153 { 6143 {
6154 if (hostname != NULL) 6144 if (hostname != NULL)
6155 GNUNET_asprintf (&newservicehome, "%s/%s/%d/", baseservicehome, 6145 GNUNET_asprintf (&newservicehome, "%s/%s/%d/", baseservicehome,
@@ -6181,9 +6171,8 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
6181 pg->peers[off].internal_context.username = username; 6171 pg->peers[off].internal_context.username = username;
6182 pg->peers[off].internal_context.sshport = sshport; 6172 pg->peers[off].internal_context.sshport = sshport;
6183 if (pg->hostkey_data != NULL) 6173 if (pg->hostkey_data != NULL)
6184 pg->peers[off].internal_context.hostkey = &pg->hostkey_data[off 6174 pg->peers[off].internal_context.hostkey =
6185 * 6175 &pg->hostkey_data[off * HOSTKEYFILESIZE];
6186 HOSTKEYFILESIZE];
6187 pg->peers[off].internal_context.hostkey_callback = hostkey_callback; 6176 pg->peers[off].internal_context.hostkey_callback = hostkey_callback;
6188 pg->peers[off].internal_context.hostkey_cls = hostkey_cls; 6177 pg->peers[off].internal_context.hostkey_cls = hostkey_cls;
6189 pg->peers[off].internal_context.start_cb = cb; 6178 pg->peers[off].internal_context.start_cb = cb;
@@ -6194,19 +6183,14 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
6194#else 6183#else
6195 if ((pg->hostkey_data != NULL) && (hostcnt > 0)) 6184 if ((pg->hostkey_data != NULL) && (hostcnt > 0))
6196 { 6185 {
6197 pg->peers[off].daemon 6186 pg->peers[off].daemon =
6198 = GNUNET_TESTING_daemon_start (pcfg, 6187 GNUNET_TESTING_daemon_start (pcfg, timeout, GNUNET_YES, hostname,
6199 timeout, 6188 username, sshport,
6200 GNUNET_YES, 6189 pg->peers[off].internal_context.hostkey,
6201 hostname, 6190 &internal_hostkey_callback,
6202 username, 6191 &pg->peers[off].internal_context,
6203 sshport, 6192 &internal_startup_callback,
6204 pg->peers[off]. 6193 &pg->peers[off].internal_context);
6205 internal_context.hostkey,
6206 &internal_hostkey_callback,
6207 &pg->peers[off].internal_context,
6208 &internal_startup_callback,
6209 &pg->peers[off].internal_context);
6210 /** 6194 /**
6211 * At this point, given that we had a hostkeyfile, 6195 * At this point, given that we had a hostkeyfile,
6212 * we can call the hostkey callback! 6196 * we can call the hostkey callback!
@@ -6245,10 +6229,9 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
6245 sshport = 0; 6229 sshport = 0;
6246 } 6230 }
6247 6231
6248 if (GNUNET_YES 6232 if (GNUNET_YES ==
6249 == GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", 6233 GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME",
6250 "SERVICEHOME", 6234 &baseservicehome))
6251 &baseservicehome))
6252 { 6235 {
6253 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "baseservice home is %s\n", 6236 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "baseservice home is %s\n",
6254 baseservicehome); 6237 baseservicehome);
@@ -6273,17 +6256,16 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
6273 } 6256 }
6274 6257
6275 if (NULL != username) 6258 if (NULL != username)
6276 GNUNET_asprintf (&arg, 6259 GNUNET_asprintf (&arg, "%s@%s:%s", username, pg->hosts[off].hostname,
6277 "%s@%s:%s", 6260 newservicehome);
6278 username, pg->hosts[off].hostname, newservicehome);
6279 else 6261 else
6280 GNUNET_asprintf (&arg, 6262 GNUNET_asprintf (&arg, "%s:%s", pg->hosts[off].hostname,
6281 "%s:%s", pg->hosts[off].hostname, newservicehome); 6263 newservicehome);
6282 6264
6283 /* FIXME: Doesn't support ssh_port option! */ 6265 /* FIXME: Doesn't support ssh_port option! */
6284 proc = GNUNET_OS_start_process (NULL, NULL, 6266 proc =
6285 "rsync", 6267 GNUNET_OS_start_process (NULL, NULL, "rsync", "rsync", "-r",
6286 "rsync", "-r", newservicehome, arg, NULL); 6268 newservicehome, arg, NULL);
6287 6269
6288 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 6270 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
6289 "copying directory with command rsync -r %s %s\n", 6271 "copying directory with command rsync -r %s %s\n",
@@ -6338,8 +6320,9 @@ GNUNET_TESTING_daemon_get_by_id (struct GNUNET_TESTING_PeerGroup *pg,
6338 6320
6339 for (i = 0; i < pg->total; i++) 6321 for (i = 0; i < pg->total; i++)
6340 { 6322 {
6341 if (0 == memcmp (&pg->peers[i].daemon->id, peer_id, 6323 if (0 ==
6342 sizeof (struct GNUNET_PeerIdentity))) 6324 memcmp (&pg->peers[i].daemon->id, peer_id,
6325 sizeof (struct GNUNET_PeerIdentity)))
6343 return pg->peers[i].daemon; 6326 return pg->peers[i].daemon;
6344 } 6327 }
6345 return NULL; 6328 return NULL;
@@ -6376,8 +6359,8 @@ restart_callback (void *cls, const struct GNUNET_PeerIdentity *id,
6376 restart_context->callback (restart_context->callback_cls, NULL); 6359 restart_context->callback (restart_context->callback_cls, NULL);
6377 GNUNET_free (restart_context); 6360 GNUNET_free (restart_context);
6378 } 6361 }
6379 else if (restart_context->peers_restart_failed 6362 else if (restart_context->peers_restart_failed +
6380 + restart_context->peers_restarted == 6363 restart_context->peers_restarted ==
6381 restart_context->peer_group->total) 6364 restart_context->peer_group->total)
6382 { 6365 {
6383 restart_context->callback (restart_context->callback_cls, 6366 restart_context->callback (restart_context->callback_cls,
@@ -6417,8 +6400,9 @@ churn_stop_callback (void *cls, const char *emsg)
6417 churn_ctx->num_to_stop--; 6400 churn_ctx->num_to_stop--;
6418 } 6401 }
6419 6402
6420 total_left = (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) 6403 total_left =
6421 + (churn_ctx->num_to_start - churn_ctx->num_failed_start); 6404 (churn_ctx->num_to_stop - churn_ctx->num_failed_stop) +
6405 (churn_ctx->num_to_start - churn_ctx->num_failed_start);
6422 6406
6423 if (total_left == 0) 6407 if (total_left == 0)
6424 { 6408 {
@@ -6523,8 +6507,8 @@ schedule_churn_shutdown_task (void *cls,
6523 */ 6507 */
6524void 6508void
6525GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg, 6509GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg,
6526 char *service, 6510 char *service, unsigned int voff,
6527 unsigned int voff, unsigned int von, 6511 unsigned int von,
6528 struct GNUNET_TIME_Relative timeout, 6512 struct GNUNET_TIME_Relative timeout,
6529 GNUNET_TESTING_NotifyCompletion cb, void *cb_cls) 6513 GNUNET_TESTING_NotifyCompletion cb, void *cb_cls)
6530{ 6514{
@@ -6634,11 +6618,11 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg,
6634 stopped_permute = NULL; 6618 stopped_permute = NULL;
6635 6619
6636 if (running > 0) 6620 if (running > 0)
6637 running_permute = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, 6621 running_permute =
6638 running); 6622 GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, running);
6639 if (stopped > 0) 6623 if (stopped > 0)
6640 stopped_permute = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, 6624 stopped_permute =
6641 stopped); 6625 GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, stopped);
6642 6626
6643 total_running = running; 6627 total_running = running;
6644 total_stopped = stopped; 6628 total_stopped = stopped;
@@ -6707,8 +6691,8 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg,
6707#endif 6691#endif
6708 GNUNET_assert (running_arr != NULL); 6692 GNUNET_assert (running_arr != NULL);
6709 peer_shutdown_ctx = GNUNET_malloc (sizeof (struct PeerShutdownContext)); 6693 peer_shutdown_ctx = GNUNET_malloc (sizeof (struct PeerShutdownContext));
6710 peer_shutdown_ctx->daemon 6694 peer_shutdown_ctx->daemon =
6711 = pg->peers[running_arr[running_permute[i]]].daemon; 6695 pg->peers[running_arr[running_permute[i]]].daemon;
6712 peer_shutdown_ctx->shutdown_ctx = shutdown_ctx; 6696 peer_shutdown_ctx->shutdown_ctx = shutdown_ctx;
6713 GNUNET_SCHEDULER_add_now (&schedule_churn_shutdown_task, peer_shutdown_ctx); 6697 GNUNET_SCHEDULER_add_now (&schedule_churn_shutdown_task, peer_shutdown_ctx);
6714 } 6698 }
@@ -6730,8 +6714,8 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg,
6730 GNUNET_assert (stopped_arr != NULL); 6714 GNUNET_assert (stopped_arr != NULL);
6731 peer_restart_ctx = GNUNET_malloc (sizeof (struct PeerRestartContext)); 6715 peer_restart_ctx = GNUNET_malloc (sizeof (struct PeerRestartContext));
6732 peer_restart_ctx->churn_restart_ctx = churn_startup_ctx; 6716 peer_restart_ctx->churn_restart_ctx = churn_startup_ctx;
6733 peer_restart_ctx->daemon 6717 peer_restart_ctx->daemon =
6734 = pg->peers[stopped_arr[stopped_permute[i]]].daemon; 6718 pg->peers[stopped_arr[stopped_permute[i]]].daemon;
6735 GNUNET_SCHEDULER_add_now (&schedule_churn_restart, peer_restart_ctx); 6719 GNUNET_SCHEDULER_add_now (&schedule_churn_restart, peer_restart_ctx);
6736 } 6720 }
6737 6721
@@ -6812,8 +6796,8 @@ GNUNET_TESTING_daemons_restart (struct GNUNET_TESTING_PeerGroup *pg,
6812 6796
6813 for (off = 0; off < pg->total; off++) 6797 for (off = 0; off < pg->total; off++)
6814 { 6798 {
6815 GNUNET_TESTING_daemon_restart (pg->peers[off].daemon, 6799 GNUNET_TESTING_daemon_restart (pg->peers[off].daemon, &restart_callback,
6816 &restart_callback, restart_context); 6800 restart_context);
6817 } 6801 }
6818 } 6802 }
6819} 6803}
@@ -6851,8 +6835,8 @@ GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg,
6851 churn_ctx->cb_cls = cb_cls; 6835 churn_ctx->cb_cls = cb_cls;
6852 shutdown_ctx->cb_cls = churn_ctx; 6836 shutdown_ctx->cb_cls = churn_ctx;
6853 GNUNET_TESTING_daemon_stop (pg->peers[offset].daemon, timeout, 6837 GNUNET_TESTING_daemon_stop (pg->peers[offset].daemon, timeout,
6854 &churn_stop_callback, shutdown_ctx, 6838 &churn_stop_callback, shutdown_ctx, GNUNET_NO,
6855 GNUNET_NO, GNUNET_YES); 6839 GNUNET_YES);
6856 } 6840 }
6857 } 6841 }
6858 else if (GNUNET_YES == desired_status) 6842 else if (GNUNET_YES == desired_status)
@@ -6866,9 +6850,8 @@ GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg,
6866 churn_ctx->cb = cb; 6850 churn_ctx->cb = cb;
6867 churn_ctx->cb_cls = cb_cls; 6851 churn_ctx->cb_cls = cb_cls;
6868 startup_ctx->churn_ctx = churn_ctx; 6852 startup_ctx->churn_ctx = churn_ctx;
6869 GNUNET_TESTING_daemon_start_stopped (pg->peers[offset].daemon, 6853 GNUNET_TESTING_daemon_start_stopped (pg->peers[offset].daemon, timeout,
6870 timeout, &churn_start_callback, 6854 &churn_start_callback, startup_ctx);
6871 startup_ctx);
6872 } 6855 }
6873 } 6856 }
6874 else 6857 else
@@ -6908,9 +6891,9 @@ internal_shutdown_callback (void *cls, const char *emsg)
6908 shutdown_ctx->peers_failed++; 6891 shutdown_ctx->peers_failed++;
6909 } 6892 }
6910 6893
6911 if ((shutdown_ctx->cb != NULL) && (shutdown_ctx->peers_down 6894 if ((shutdown_ctx->cb != NULL) &&
6912 + shutdown_ctx->peers_failed == 6895 (shutdown_ctx->peers_down + shutdown_ctx->peers_failed ==
6913 shutdown_ctx->total_peers)) 6896 shutdown_ctx->total_peers))
6914 { 6897 {
6915 if (shutdown_ctx->peers_failed > 0) 6898 if (shutdown_ctx->peers_failed > 0)
6916 shutdown_ctx->cb (shutdown_ctx->cb_cls, 6899 shutdown_ctx->cb (shutdown_ctx->cb_cls,
@@ -6957,11 +6940,11 @@ schedule_shutdown_task (void *cls,
6957 shutdown_ctx = peer_shutdown_ctx->shutdown_ctx; 6940 shutdown_ctx = peer_shutdown_ctx->shutdown_ctx;
6958 GNUNET_assert (shutdown_ctx != NULL); 6941 GNUNET_assert (shutdown_ctx != NULL);
6959 6942
6960 if ((shutdown_ctx->outstanding < shutdown_ctx->pg->max_concurrent_ssh) 6943 if ((shutdown_ctx->outstanding < shutdown_ctx->pg->max_concurrent_ssh) ||
6961 || ((peer_shutdown_ctx->daemon->hostname != NULL) 6944 ((peer_shutdown_ctx->daemon->hostname != NULL) &&
6962 && (count_outstanding_at_host (peer_shutdown_ctx->daemon->hostname, 6945 (count_outstanding_at_host
6963 shutdown_ctx->pg) 6946 (peer_shutdown_ctx->daemon->hostname,
6964 < shutdown_ctx->pg->max_concurrent_ssh))) 6947 shutdown_ctx->pg) < shutdown_ctx->pg->max_concurrent_ssh)))
6965 { 6948 {
6966 if (peer_shutdown_ctx->daemon->hostname != NULL) 6949 if (peer_shutdown_ctx->daemon->hostname != NULL)
6967 increment_outstanding_at_host (peer_shutdown_ctx->daemon->hostname, 6950 increment_outstanding_at_host (peer_shutdown_ctx->daemon->hostname,
@@ -7001,9 +6984,9 @@ GNUNET_TESTING_hosts_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
7001 int ret; 6984 int ret;
7002 6985
7003 /* Check for a hostfile containing user@host:port triples */ 6986 /* Check for a hostfile containing user@host:port triples */
7004 if (GNUNET_OK 6987 if (GNUNET_OK !=
7005 != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "hostfile", 6988 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "hostfile",
7006 &hostfile)) 6989 &hostfile))
7007 return NULL; 6990 return NULL;
7008 6991
7009 hosts = NULL; 6992 hosts = NULL;
@@ -7012,8 +6995,9 @@ GNUNET_TESTING_hosts_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
7012 if (hostfile != NULL) 6995 if (hostfile != NULL)
7013 { 6996 {
7014 if (GNUNET_OK != GNUNET_DISK_file_test (hostfile)) 6997 if (GNUNET_OK != GNUNET_DISK_file_test (hostfile))
7015 GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ 6998 GNUNET_DISK_fn_write (hostfile, NULL, 0,
7016 | GNUNET_DISK_PERM_USER_WRITE); 6999 GNUNET_DISK_PERM_USER_READ |
7000 GNUNET_DISK_PERM_USER_WRITE);
7017 if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0)) 7001 if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0))
7018 { 7002 {
7019 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 7003 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -7045,9 +7029,9 @@ GNUNET_TESTING_hosts_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
7045 { 7029 {
7046 data[count] = '\0'; 7030 data[count] = '\0';
7047 temphost = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Host)); 7031 temphost = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Host));
7048 ret = sscanf (buf, "%a[a-zA-Z0-9_]@%a[a-zA-Z0-9.]:%hd", 7032 ret =
7049 &temphost->username, &temphost->hostname, 7033 sscanf (buf, "%a[a-zA-Z0-9_]@%a[a-zA-Z0-9.]:%hd",
7050 &temphost->port); 7034 &temphost->username, &temphost->hostname, &temphost->port);
7051 if (3 == ret) 7035 if (3 == ret)
7052 { 7036 {
7053 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 7037 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -7100,9 +7084,8 @@ GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg,
7100 GNUNET_assert (pg->total > 0); 7084 GNUNET_assert (pg->total > 0);
7101 7085
7102 shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext)); 7086 shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext));
7103 shutdown_ctx->delete_files = GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, 7087 shutdown_ctx->delete_files =
7104 "TESTING", 7088 GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "TESTING", "DELETE_FILES");
7105 "DELETE_FILES");
7106 shutdown_ctx->cb = cb; 7089 shutdown_ctx->cb = cb;
7107 shutdown_ctx->cb_cls = cb_cls; 7090 shutdown_ctx->cb_cls = cb_cls;
7108 shutdown_ctx->total_peers = pg->total; 7091 shutdown_ctx->total_peers = pg->total;
diff --git a/src/testing/testing_peergroup.c b/src/testing/testing_peergroup.c
index e81e9fad8..a76c7cc26 100644
--- a/src/testing/testing_peergroup.c
+++ b/src/testing/testing_peergroup.c
@@ -203,8 +203,8 @@ update_meter (struct ProgressMeter *meter)
203 fprintf (stdout, "%sProgress: [0%%", meter->startup_string); 203 fprintf (stdout, "%sProgress: [0%%", meter->startup_string);
204 } 204 }
205 else 205 else
206 fprintf (stdout, "%d%%", (int) (((float) meter->completed 206 fprintf (stdout, "%d%%",
207 / meter->total) * 100)); 207 (int) (((float) meter->completed / meter->total) * 100));
208 } 208 }
209 else if (meter->completed % meter->dotnum == 0) 209 else if (meter->completed % meter->dotnum == 0)
210 fprintf (stdout, "."); 210 fprintf (stdout, ".");
@@ -304,8 +304,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
304 * failure (peers failed to connect). 304 * failure (peers failed to connect).
305 */ 305 */
306static void 306static void
307internal_topology_callback (void *cls, 307internal_topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
308 const struct GNUNET_PeerIdentity *first,
309 const struct GNUNET_PeerIdentity *second, 308 const struct GNUNET_PeerIdentity *second,
310 uint32_t distance, 309 uint32_t distance,
311 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 310 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
@@ -332,9 +331,9 @@ internal_topology_callback (void *cls,
332#endif 331#endif
333 332
334#if TIMING 333#if TIMING
335 if (GNUNET_TIME_absolute_get_difference (connect_last_time, 334 if (GNUNET_TIME_absolute_get_difference
336 GNUNET_TIME_absolute_get 335 (connect_last_time,
337 ()).rel_value > 336 GNUNET_TIME_absolute_get ()).rel_value >
338 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 337 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
339 CONN_UPDATE_DURATION).rel_value) 338 CONN_UPDATE_DURATION).rel_value)
340 { 339 {
@@ -345,14 +344,14 @@ internal_topology_callback (void *cls,
345 new_failed_connections = failed_connections - previous_failed_connections; 344 new_failed_connections = failed_connections - previous_failed_connections;
346 345
347 /* Get duration in seconds */ 346 /* Get duration in seconds */
348 duration 347 duration =
349 = GNUNET_TIME_absolute_get_difference (connect_last_time, 348 GNUNET_TIME_absolute_get_difference (connect_last_time,
350 GNUNET_TIME_absolute_get 349 GNUNET_TIME_absolute_get ()).
351 ()).rel_value / 1000; 350 rel_value / 1000;
352 total_duration = 351 total_duration =
353 GNUNET_TIME_absolute_get_difference (connect_start_time, 352 GNUNET_TIME_absolute_get_difference (connect_start_time,
354 GNUNET_TIME_absolute_get 353 GNUNET_TIME_absolute_get ()).
355 ()).rel_value / 1000; 354 rel_value / 1000;
356 355
357 failed_conns_per_sec_recent = (double) new_failed_connections / duration; 356 failed_conns_per_sec_recent = (double) new_failed_connections / duration;
358 failed_conns_per_sec_total = (double) failed_connections / total_duration; 357 failed_conns_per_sec_total = (double) failed_connections / total_duration;
@@ -360,9 +359,8 @@ internal_topology_callback (void *cls,
360 conns_per_sec_total = (double) total_connections / total_duration; 359 conns_per_sec_total = (double) total_connections / total_duration;
361 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 360 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
362 "Recent: %.2f/s, Total: %.2f/s, Recent failed: %.2f/s, total failed %.2f/s\n", 361 "Recent: %.2f/s, Total: %.2f/s, Recent failed: %.2f/s, total failed %.2f/s\n",
363 conns_per_sec_recent, CONN_UPDATE_DURATION, 362 conns_per_sec_recent, CONN_UPDATE_DURATION, conns_per_sec_total,
364 conns_per_sec_total, failed_conns_per_sec_recent, 363 failed_conns_per_sec_recent, failed_conns_per_sec_total);
365 failed_conns_per_sec_total);
366 connect_last_time = GNUNET_TIME_absolute_get (); 364 connect_last_time = GNUNET_TIME_absolute_get ();
367 previous_connections = total_connections; 365 previous_connections = total_connections;
368 previous_failed_connections = failed_connections; 366 previous_failed_connections = failed_connections;
@@ -410,11 +408,9 @@ internal_topology_callback (void *cls,
410 408
411 GNUNET_assert (pg_start_ctx->connect_meter != NULL); 409 GNUNET_assert (pg_start_ctx->connect_meter != NULL);
412 if (pg_start_ctx->connect_cb != NULL) 410 if (pg_start_ctx->connect_cb != NULL)
413 pg_start_ctx->connect_cb (pg_start_ctx->cls, first, 411 pg_start_ctx->connect_cb (pg_start_ctx->cls, first, second, distance,
414 second, 412 first_cfg, second_cfg, first_daemon,
415 distance, 413 second_daemon, emsg);
416 first_cfg,
417 second_cfg, first_daemon, second_daemon, emsg);
418 if (GNUNET_YES == update_meter (pg_start_ctx->connect_meter)) 414 if (GNUNET_YES == update_meter (pg_start_ctx->connect_meter))
419 { 415 {
420#if VERBOSE 416#if VERBOSE
@@ -424,10 +420,10 @@ internal_topology_callback (void *cls,
424#endif 420#endif
425 421
426#if TIMING 422#if TIMING
427 total_duration 423 total_duration =
428 = GNUNET_TIME_absolute_get_difference (connect_start_time, 424 GNUNET_TIME_absolute_get_difference (connect_start_time,
429 GNUNET_TIME_absolute_get 425 GNUNET_TIME_absolute_get ()).
430 ()).rel_value / 1000; 426 rel_value / 1000;
431 failed_conns_per_sec_total = (double) failed_connections / total_duration; 427 failed_conns_per_sec_total = (double) failed_connections / total_duration;
432 conns_per_sec_total = (double) total_connections / total_duration; 428 conns_per_sec_total = (double) total_connections / total_duration;
433 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 429 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -494,20 +490,21 @@ internal_peers_started_callback (void *cls,
494 if ((pg_start_ctx->pg != NULL) && (pg_start_ctx->peers_left == 0)) 490 if ((pg_start_ctx->pg != NULL) && (pg_start_ctx->peers_left == 0))
495 { 491 {
496 pg_start_ctx->connect_start_time = GNUNET_TIME_absolute_get (); 492 pg_start_ctx->connect_start_time = GNUNET_TIME_absolute_get ();
497 pg_start_ctx->expected_connections 493 pg_start_ctx->expected_connections =
498 = GNUNET_TESTING_connect_topology (pg_start_ctx->pg, 494 GNUNET_TESTING_connect_topology (pg_start_ctx->pg,
499 pg_start_ctx->connect_topology, 495 pg_start_ctx->connect_topology,
500 pg_start_ctx->connect_topology_option, 496 pg_start_ctx->
501 pg_start_ctx->connect_topology_option_modifier, 497 connect_topology_option,
502 DEFAULT_CONNECT_TIMEOUT, 498 pg_start_ctx->
503 pg_start_ctx->connect_attempts, 499 connect_topology_option_modifier,
504 NULL, NULL); 500 DEFAULT_CONNECT_TIMEOUT,
505 501 pg_start_ctx->connect_attempts, NULL,
506 pg_start_ctx->connect_meter 502 NULL);
507 = create_meter (pg_start_ctx->expected_connections, 503
508 "Peer connection ", pg_start_ctx->verbose); 504 pg_start_ctx->connect_meter =
509 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 505 create_meter (pg_start_ctx->expected_connections, "Peer connection ",
510 "Have %d expected connections\n", 506 pg_start_ctx->verbose);
507 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Have %d expected connections\n",
511 pg_start_ctx->expected_connections); 508 pg_start_ctx->expected_connections);
512 } 509 }
513 510
@@ -553,8 +550,8 @@ internal_hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id,
553 550
554#if VERBOSE > 1 551#if VERBOSE > 1
555 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 552 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
556 "Hostkey (%d/%d) created for peer `%s'\n", 553 "Hostkey (%d/%d) created for peer `%s'\n", num_peers - peers_left,
557 num_peers - peers_left, num_peers, GNUNET_i2s (id)); 554 num_peers, GNUNET_i2s (id));
558#endif 555#endif
559 556
560 pg_start_ctx->peers_left--; 557 pg_start_ctx->peers_left--;
@@ -583,13 +580,13 @@ internal_hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id,
583 else 580 else
584 { 581 {
585 GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task); 582 GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task);
586 pg_start_ctx->die_task = GNUNET_SCHEDULER_add_now (&end_badly, 583 pg_start_ctx->die_task =
587 "from create topology (bad return)"); 584 GNUNET_SCHEDULER_add_now (&end_badly,
585 "from create topology (bad return)");
588 } 586 }
589 587
590 GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task); 588 GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task);
591 pg_start_ctx->die_task 589 pg_start_ctx->die_task =
592 =
593 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining 590 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
594 (pg_start_ctx->timeout), &end_badly, 591 (pg_start_ctx->timeout), &end_badly,
595 "from continue startup (timeout)"); 592 "from continue startup (timeout)");
@@ -608,8 +605,7 @@ internal_hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id,
608 * @param emsg error message (NULL on success) 605 * @param emsg error message (NULL on success)
609 */ 606 */
610void 607void
611write_topology_cb (void *cls, 608write_topology_cb (void *cls, const struct GNUNET_PeerIdentity *first,
612 const struct GNUNET_PeerIdentity *first,
613 const struct GNUNET_PeerIdentity *second, const char *emsg) 609 const struct GNUNET_PeerIdentity *second, const char *emsg)
614{ 610{
615 struct TopologyOutputContext *topo_ctx; 611 struct TopologyOutputContext *topo_ctx;
@@ -727,9 +723,9 @@ GNUNET_TESTING_peergroup_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
727 723
728 pg_start_ctx = GNUNET_malloc (sizeof (struct PeerGroupStartupContext)); 724 pg_start_ctx = GNUNET_malloc (sizeof (struct PeerGroupStartupContext));
729 725
730 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "testing", 726 if (GNUNET_OK !=
731 "connect_attempts", 727 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_attempts",
732 &pg_start_ctx->connect_attempts)) 728 &pg_start_ctx->connect_attempts))
733 { 729 {
734 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", 730 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
735 "testing", "connect_attempts"); 731 "testing", "connect_attempts");
@@ -737,10 +733,11 @@ GNUNET_TESTING_peergroup_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
737 return NULL; 733 return NULL;
738 } 734 }
739 735
740 if (GNUNET_OK 736 if (GNUNET_OK !=
741 != GNUNET_CONFIGURATION_get_value_number (cfg, "testing", 737 GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
742 "max_outstanding_connections", 738 "max_outstanding_connections",
743 &pg_start_ctx->max_concurrent_connections)) 739 &pg_start_ctx->
740 max_concurrent_connections))
744 { 741 {
745 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", 742 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
746 "testing", "max_outstanding_connections"); 743 "testing", "max_outstanding_connections");
@@ -748,9 +745,10 @@ GNUNET_TESTING_peergroup_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
748 return NULL; 745 return NULL;
749 } 746 }
750 747
751 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "testing", 748 if (GNUNET_OK !=
752 "max_concurrent_ssh", 749 GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
753 &pg_start_ctx->max_concurrent_ssh)) 750 "max_concurrent_ssh",
751 &pg_start_ctx->max_concurrent_ssh))
754 { 752 {
755 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", 753 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
756 "testing", "max_concurrent_ssh"); 754 "testing", "max_concurrent_ssh");
@@ -769,9 +767,10 @@ GNUNET_TESTING_peergroup_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
769 return NULL; 767 return NULL;
770 } 768 }
771 769
772 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "testing", 770 if (GNUNET_OK ==
773 "peergroup_timeout", 771 GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
774 &temp_config_number)) 772 "peergroup_timeout",
773 &temp_config_number))
775 pg_start_ctx->timeout = 774 pg_start_ctx->timeout =
776 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply 775 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
777 (GNUNET_TIME_UNIT_SECONDS, 776 (GNUNET_TIME_UNIT_SECONDS,
@@ -787,11 +786,11 @@ GNUNET_TESTING_peergroup_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
787 786
788 /* Read topology related options from the configuration file */ 787 /* Read topology related options from the configuration file */
789 temp_str = NULL; 788 temp_str = NULL;
790 if ((GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg, "testing", 789 if ((GNUNET_YES ==
791 "topology", 790 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology",
792 &temp_str)) 791 &temp_str)) &&
793 && (GNUNET_NO == 792 (GNUNET_NO ==
794 GNUNET_TESTING_topology_get (&pg_start_ctx->topology, temp_str))) 793 GNUNET_TESTING_topology_get (&pg_start_ctx->topology, temp_str)))
795 { 794 {
796 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 795 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
797 "Invalid topology `%s' given for section %s option %s\n", 796 "Invalid topology `%s' given for section %s option %s\n",
@@ -821,9 +820,9 @@ GNUNET_TESTING_peergroup_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
821 GNUNET_free (temp_str); 820 GNUNET_free (temp_str);
822 } 821 }
823 822
824 if (GNUNET_OK 823 if (GNUNET_OK !=
825 != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "percentage", 824 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "percentage",
826 &temp_str)) 825 &temp_str))
827 pg_start_ctx->topology_percentage = 0.5; 826 pg_start_ctx->topology_percentage = 0.5;
828 else 827 else
829 { 828 {
@@ -831,9 +830,9 @@ GNUNET_TESTING_peergroup_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
831 GNUNET_free (temp_str); 830 GNUNET_free (temp_str);
832 } 831 }
833 832
834 if (GNUNET_OK 833 if (GNUNET_OK !=
835 != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "probability", 834 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "probability",
836 &temp_str)) 835 &temp_str))
837 pg_start_ctx->topology_probability = 0.5; 836 pg_start_ctx->topology_probability = 0.5;
838 else 837 else
839 { 838 {
@@ -841,13 +840,11 @@ GNUNET_TESTING_peergroup_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
841 GNUNET_free (temp_str); 840 GNUNET_free (temp_str);
842 } 841 }
843 842
844 if ((GNUNET_YES 843 if ((GNUNET_YES ==
845 == GNUNET_CONFIGURATION_get_value_string (cfg, "testing", 844 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
846 "connect_topology", 845 "connect_topology", &temp_str)) &&
847 &temp_str)) 846 (GNUNET_NO ==
848 && (GNUNET_NO == 847 GNUNET_TESTING_topology_get (&pg_start_ctx->connect_topology, temp_str)))
849 GNUNET_TESTING_topology_get (&pg_start_ctx->connect_topology,
850 temp_str)))
851 { 848 {
852 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 849 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
853 "Invalid connect topology `%s' given for section %s option %s\n", 850 "Invalid connect topology `%s' given for section %s option %s\n",
@@ -855,14 +852,13 @@ GNUNET_TESTING_peergroup_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
855 } 852 }
856 GNUNET_free_non_null (temp_str); 853 GNUNET_free_non_null (temp_str);
857 854
858 if ((GNUNET_YES 855 if ((GNUNET_YES ==
859 == GNUNET_CONFIGURATION_get_value_string (cfg, "testing", 856 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
860 "connect_topology_option", 857 "connect_topology_option",
861 &temp_str)) 858 &temp_str)) &&
862 && (GNUNET_NO 859 (GNUNET_NO ==
863 == 860 GNUNET_TESTING_topology_option_get (&pg_start_ctx->
864 GNUNET_TESTING_topology_option_get 861 connect_topology_option, temp_str)))
865 (&pg_start_ctx->connect_topology_option, temp_str)))
866 { 862 {
867 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 863 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
868 "Invalid connect topology option `%s' given for section %s option %s\n", 864 "Invalid connect topology option `%s' given for section %s option %s\n",
@@ -871,14 +867,13 @@ GNUNET_TESTING_peergroup_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
871 } 867 }
872 GNUNET_free_non_null (temp_str); 868 GNUNET_free_non_null (temp_str);
873 869
874 if (GNUNET_YES 870 if (GNUNET_YES ==
875 == GNUNET_CONFIGURATION_get_value_string (cfg, 871 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
876 "testing", 872 "connect_topology_option_modifier",
877 "connect_topology_option_modifier", 873 &temp_str))
878 &temp_str))
879 { 874 {
880 if (sscanf (temp_str, "%lf", 875 if (sscanf
881 &pg_start_ctx->connect_topology_option_modifier) != 1) 876 (temp_str, "%lf", &pg_start_ctx->connect_topology_option_modifier) != 1)
882 { 877 {
883 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 878 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
884 _ 879 _
@@ -891,17 +886,17 @@ GNUNET_TESTING_peergroup_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
891 GNUNET_free (temp_str); 886 GNUNET_free (temp_str);
892 } 887 }
893 888
894 if (GNUNET_YES 889 if (GNUNET_YES !=
895 != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", 890 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
896 "blacklist_transports", 891 "blacklist_transports",
897 &pg_start_ctx->restrict_transports)) 892 &pg_start_ctx->
893 restrict_transports))
898 pg_start_ctx->restrict_transports = NULL; 894 pg_start_ctx->restrict_transports = NULL;
899 895
900 pg_start_ctx->restrict_topology = GNUNET_TESTING_TOPOLOGY_NONE; 896 pg_start_ctx->restrict_topology = GNUNET_TESTING_TOPOLOGY_NONE;
901 if ((GNUNET_YES 897 if ((GNUNET_YES ==
902 == GNUNET_CONFIGURATION_get_value_string (cfg, "testing", 898 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
903 "blacklist_topology", 899 "blacklist_topology", &temp_str))
904 &temp_str))
905 && (GNUNET_NO == 900 && (GNUNET_NO ==
906 GNUNET_TESTING_topology_get (&pg_start_ctx->restrict_topology, 901 GNUNET_TESTING_topology_get (&pg_start_ctx->restrict_topology,
907 temp_str))) 902 temp_str)))
@@ -928,23 +923,21 @@ GNUNET_TESTING_peergroup_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
928 pg_start_ctx->verbose); 923 pg_start_ctx->verbose);
929 /* Make compilers happy */ 924 /* Make compilers happy */
930 reset_meter (pg_start_ctx->peer_start_meter); 925 reset_meter (pg_start_ctx->peer_start_meter);
931 pg_start_ctx->die_task 926 pg_start_ctx->die_task =
932 =
933 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining 927 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
934 (pg_start_ctx->timeout), &end_badly, 928 (pg_start_ctx->timeout), &end_badly,
935 "didn't generate all hostkeys within allowed startup time!"); 929 "didn't generate all hostkeys within allowed startup time!");
936 930
937 pg_start_ctx->pg 931 pg_start_ctx->pg =
938 = GNUNET_TESTING_daemons_start (pg_start_ctx->cfg, 932 GNUNET_TESTING_daemons_start (pg_start_ctx->cfg, pg_start_ctx->peers_left,
939 pg_start_ctx->peers_left, 933 pg_start_ctx->max_concurrent_connections,
940 pg_start_ctx->max_concurrent_connections, 934 pg_start_ctx->max_concurrent_ssh,
941 pg_start_ctx->max_concurrent_ssh, 935 GNUNET_TIME_absolute_get_remaining
942 GNUNET_TIME_absolute_get_remaining 936 (pg_start_ctx->timeout),
943 (pg_start_ctx->timeout), 937 &internal_hostkey_callback, pg_start_ctx,
944 &internal_hostkey_callback, pg_start_ctx, 938 &internal_peers_started_callback,
945 &internal_peers_started_callback, 939 pg_start_ctx, &internal_topology_callback,
946 pg_start_ctx, &internal_topology_callback, 940 pg_start_ctx, pg_start_ctx->hostnames);
947 pg_start_ctx, pg_start_ctx->hostnames);
948 941
949 return pg_start_ctx->pg; 942 return pg_start_ctx->pg;
950} 943}
diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c
index 91d0ed12d..8f86619fd 100644
--- a/src/topology/gnunet-daemon-topology.c
+++ b/src/topology/gnunet-daemon-topology.c
@@ -247,8 +247,8 @@ blacklist_check (void *cls, const struct GNUNET_PeerIdentity *pid)
247 pos = GNUNET_CONTAINER_multihashmap_get (peers, &pid->hashPubKey); 247 pos = GNUNET_CONTAINER_multihashmap_get (peers, &pid->hashPubKey);
248 if ((pos != NULL) && (pos->is_friend == GNUNET_YES)) 248 if ((pos != NULL) && (pos->is_friend == GNUNET_YES))
249 return GNUNET_OK; 249 return GNUNET_OK;
250 GNUNET_STATISTICS_update (stats, 250 GNUNET_STATISTICS_update (stats, gettext_noop ("# peers blacklisted"), 1,
251 gettext_noop ("# peers blacklisted"), 1, GNUNET_NO); 251 GNUNET_NO);
252 return GNUNET_SYSERR; 252 return GNUNET_SYSERR;
253} 253}
254 254
@@ -292,8 +292,8 @@ connect_completed_callback (void *cls, int success)
292static int 292static int
293is_connection_allowed (struct Peer *peer) 293is_connection_allowed (struct Peer *peer)
294{ 294{
295 if (0 == memcmp (&my_identity, 295 if (0 ==
296 &peer->pid, sizeof (struct GNUNET_PeerIdentity))) 296 memcmp (&my_identity, &peer->pid, sizeof (struct GNUNET_PeerIdentity)))
297 return GNUNET_SYSERR; /* disallow connections to self */ 297 return GNUNET_SYSERR; /* disallow connections to self */
298 if (peer->is_friend) 298 if (peer->is_friend)
299 return GNUNET_OK; 299 return GNUNET_OK;
@@ -355,8 +355,9 @@ free_peer (void *cls, const GNUNET_HashCode * pid, void *value)
355 * @param cls 'struct Peer' to greylist 355 * @param cls 'struct Peer' to greylist
356 * @param tc scheduler context 356 * @param tc scheduler context
357 */ 357 */
358static void 358static void remove_from_greylist (void *cls,
359remove_from_greylist (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 359 const struct GNUNET_SCHEDULER_TaskContext
360 *tc);
360 361
361 362
362/** 363/**
@@ -392,19 +393,18 @@ attempt_connect (struct Peer *pos)
392 pos->greylisted_until = GNUNET_TIME_relative_to_absolute (rem); 393 pos->greylisted_until = GNUNET_TIME_relative_to_absolute (rem);
393 if (pos->greylist_clean_task != GNUNET_SCHEDULER_NO_TASK) 394 if (pos->greylist_clean_task != GNUNET_SCHEDULER_NO_TASK)
394 GNUNET_SCHEDULER_cancel (pos->greylist_clean_task); 395 GNUNET_SCHEDULER_cancel (pos->greylist_clean_task);
395 pos->greylist_clean_task 396 pos->greylist_clean_task =
396 = GNUNET_SCHEDULER_add_delayed (rem, &remove_from_greylist, pos); 397 GNUNET_SCHEDULER_add_delayed (rem, &remove_from_greylist, pos);
397#if DEBUG_TOPOLOGY 398#if DEBUG_TOPOLOGY
398 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking to connect to `%s'\n",
399 "Asking to connect to `%s'\n", GNUNET_i2s (&pos->pid)); 400 GNUNET_i2s (&pos->pid));
400#endif 401#endif
401 GNUNET_STATISTICS_update (stats, 402 GNUNET_STATISTICS_update (stats,
402 gettext_noop ("# connect requests issued to core"), 403 gettext_noop ("# connect requests issued to core"),
403 1, GNUNET_NO); 404 1, GNUNET_NO);
404 pos->connect_req = GNUNET_CORE_peer_request_connect (handle, 405 pos->connect_req =
405 &pos->pid, 406 GNUNET_CORE_peer_request_connect (handle, &pos->pid,
406 &connect_completed_callback, 407 &connect_completed_callback, pos);
407 pos);
408} 408}
409 409
410 410
@@ -429,11 +429,11 @@ remove_from_greylist (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
429 } 429 }
430 else 430 else
431 { 431 {
432 pos->greylist_clean_task 432 pos->greylist_clean_task =
433 = GNUNET_SCHEDULER_add_delayed (rem, &remove_from_greylist, pos); 433 GNUNET_SCHEDULER_add_delayed (rem, &remove_from_greylist, pos);
434 } 434 }
435 if ((GNUNET_NO == pos->is_friend) && 435 if ((GNUNET_NO == pos->is_friend) && (GNUNET_NO == pos->is_connected) &&
436 (GNUNET_NO == pos->is_connected) && (NULL == pos->hello)) 436 (NULL == pos->hello))
437 { 437 {
438 free_peer (NULL, &pos->pid.hashPubKey, pos); 438 free_peer (NULL, &pos->pid.hashPubKey, pos);
439 return; 439 return;
@@ -450,8 +450,7 @@ remove_from_greylist (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
450 * @return the new entry 450 * @return the new entry
451 */ 451 */
452static struct Peer * 452static struct Peer *
453make_peer (const struct 453make_peer (const struct GNUNET_PeerIdentity *peer,
454 GNUNET_PeerIdentity *peer,
455 const struct GNUNET_HELLO_Message *hello, int is_friend) 454 const struct GNUNET_HELLO_Message *hello, int is_friend)
456{ 455{
457 struct Peer *ret; 456 struct Peer *ret;
@@ -465,8 +464,7 @@ make_peer (const struct
465 memcpy (ret->hello, hello, GNUNET_HELLO_size (hello)); 464 memcpy (ret->hello, hello, GNUNET_HELLO_size (hello));
466 } 465 }
467 GNUNET_break (GNUNET_OK == 466 GNUNET_break (GNUNET_OK ==
468 GNUNET_CONTAINER_multihashmap_put (peers, 467 GNUNET_CONTAINER_multihashmap_put (peers, &peer->hashPubKey,
469 &peer->hashPubKey,
470 ret, 468 ret,
471 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 469 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
472 return ret; 470 return ret;
@@ -599,8 +597,8 @@ schedule_next_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
599 fah.max_size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1; 597 fah.max_size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1;
600 fah.next_adv = GNUNET_TIME_UNIT_FOREVER_REL; 598 fah.next_adv = GNUNET_TIME_UNIT_FOREVER_REL;
601 GNUNET_CONTAINER_multihashmap_iterate (peers, &find_advertisable_hello, &fah); 599 GNUNET_CONTAINER_multihashmap_iterate (peers, &find_advertisable_hello, &fah);
602 pl->hello_delay_task 600 pl->hello_delay_task =
603 = GNUNET_SCHEDULER_add_delayed (fah.next_adv, &schedule_next_hello, pl); 601 GNUNET_SCHEDULER_add_delayed (fah.next_adv, &schedule_next_hello, pl);
604 if (fah.result == NULL) 602 if (fah.result == NULL)
605 return; 603 return;
606 next_want = GNUNET_HELLO_size (fah.result->hello); 604 next_want = GNUNET_HELLO_size (fah.result->hello);
@@ -608,14 +606,11 @@ schedule_next_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
608 if (delay.rel_value == 0) 606 if (delay.rel_value == 0)
609 { 607 {
610 /* now! */ 608 /* now! */
611 pl->hello_req = GNUNET_CORE_notify_transmit_ready (handle, 609 pl->hello_req =
612 GNUNET_YES, 610 GNUNET_CORE_notify_transmit_ready (handle, GNUNET_YES, 0,
613 0, 611 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
614 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 612 &pl->pid, next_want,
615 &pl->pid, 613 &hello_advertising_ready, pl);
616 next_want,
617 &hello_advertising_ready,
618 pl);
619 } 614 }
620} 615}
621 616
@@ -650,8 +645,8 @@ reschedule_hellos (void *cls, const GNUNET_HashCode * pid, void *value)
650 GNUNET_SCHEDULER_cancel (peer->hello_delay_task); 645 GNUNET_SCHEDULER_cancel (peer->hello_delay_task);
651 peer->hello_delay_task = GNUNET_SCHEDULER_NO_TASK; 646 peer->hello_delay_task = GNUNET_SCHEDULER_NO_TASK;
652 } 647 }
653 peer->hello_delay_task 648 peer->hello_delay_task =
654 = GNUNET_SCHEDULER_add_now (&schedule_next_hello, peer); 649 GNUNET_SCHEDULER_add_now (&schedule_next_hello, peer);
655 return GNUNET_YES; 650 return GNUNET_YES;
656} 651}
657 652
@@ -664,9 +659,7 @@ reschedule_hellos (void *cls, const GNUNET_HashCode * pid, void *value)
664 * @param atsi performance data 659 * @param atsi performance data
665 */ 660 */
666static void 661static void
667connect_notify (void *cls, 662connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
668 const struct
669 GNUNET_PeerIdentity *peer,
670 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 663 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
671{ 664{
672 struct Peer *pos; 665 struct Peer *pos;
@@ -680,8 +673,7 @@ connect_notify (void *cls,
680 return; 673 return;
681 674
682 connection_count++; 675 connection_count++;
683 GNUNET_STATISTICS_set (stats, 676 GNUNET_STATISTICS_set (stats, gettext_noop ("# peers connected"),
684 gettext_noop ("# peers connected"),
685 connection_count, GNUNET_NO); 677 connection_count, GNUNET_NO);
686 pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); 678 pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
687 if (pos == NULL) 679 if (pos == NULL)
@@ -702,8 +694,7 @@ connect_notify (void *cls,
702 (GNUNET_YES != friends_only)) 694 (GNUNET_YES != friends_only))
703 whitelist_peers (); 695 whitelist_peers ();
704 friend_count++; 696 friend_count++;
705 GNUNET_STATISTICS_set (stats, 697 GNUNET_STATISTICS_set (stats, gettext_noop ("# friends connected"),
706 gettext_noop ("# friends connected"),
707 friend_count, GNUNET_NO); 698 friend_count, GNUNET_NO);
708 } 699 }
709 reschedule_hellos (NULL, &peer->hashPubKey, pos); 700 reschedule_hellos (NULL, &peer->hashPubKey, pos);
@@ -784,14 +775,12 @@ disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
784 GNUNET_SCHEDULER_cancel (pos->hello_delay_task); 775 GNUNET_SCHEDULER_cancel (pos->hello_delay_task);
785 pos->hello_delay_task = GNUNET_SCHEDULER_NO_TASK; 776 pos->hello_delay_task = GNUNET_SCHEDULER_NO_TASK;
786 } 777 }
787 GNUNET_STATISTICS_set (stats, 778 GNUNET_STATISTICS_set (stats, gettext_noop ("# peers connected"),
788 gettext_noop ("# peers connected"),
789 connection_count, GNUNET_NO); 779 connection_count, GNUNET_NO);
790 if (pos->is_friend) 780 if (pos->is_friend)
791 { 781 {
792 friend_count--; 782 friend_count--;
793 GNUNET_STATISTICS_set (stats, 783 GNUNET_STATISTICS_set (stats, gettext_noop ("# friends connected"),
794 gettext_noop ("# friends connected"),
795 friend_count, GNUNET_NO); 784 friend_count, GNUNET_NO);
796 } 785 }
797 if (((connection_count < target_connection_count) || 786 if (((connection_count < target_connection_count) ||
@@ -814,10 +803,9 @@ disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
814 * @return GNUNET_SYSERR always, to terminate iteration 803 * @return GNUNET_SYSERR always, to terminate iteration
815 */ 804 */
816static int 805static int
817address_iterator (void *cls, 806address_iterator (void *cls, const char *tname,
818 const char *tname, 807 struct GNUNET_TIME_Absolute expiration, const void *addr,
819 struct GNUNET_TIME_Absolute expiration, 808 uint16_t addrlen)
820 const void *addr, uint16_t addrlen)
821{ 809{
822 int *flag = cls; 810 int *flag = cls;
823 811
@@ -850,8 +838,8 @@ consider_for_advertising (const struct GNUNET_HELLO_Message *hello)
850 if (0 == memcmp (&pid, &my_identity, sizeof (struct GNUNET_PeerIdentity))) 838 if (0 == memcmp (&pid, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
851 return; /* that's me! */ 839 return; /* that's me! */
852 have_address = GNUNET_NO; 840 have_address = GNUNET_NO;
853 GNUNET_HELLO_iterate_addresses (hello, 841 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &address_iterator,
854 GNUNET_NO, &address_iterator, &have_address); 842 &have_address);
855 if (GNUNET_NO == have_address) 843 if (GNUNET_NO == have_address)
856 return; /* no point in advertising this one... */ 844 return; /* no point in advertising this one... */
857 peer = GNUNET_CONTAINER_multihashmap_get (peers, &pid.hashPubKey); 845 peer = GNUNET_CONTAINER_multihashmap_get (peers, &pid.hashPubKey);
@@ -867,8 +855,8 @@ consider_for_advertising (const struct GNUNET_HELLO_Message *hello)
867 } 855 }
868#if DEBUG_TOPOLOGY 856#if DEBUG_TOPOLOGY
869 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 857 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
870 "Found `%s' from peer `%s' for advertising\n", 858 "Found `%s' from peer `%s' for advertising\n", "HELLO",
871 "HELLO", GNUNET_i2s (&pid)); 859 GNUNET_i2s (&pid));
872#endif 860#endif
873 if (peer->hello != NULL) 861 if (peer->hello != NULL)
874 { 862 {
@@ -901,8 +889,7 @@ consider_for_advertising (const struct GNUNET_HELLO_Message *hello)
901 * @param err_msg NULL if successful, otherwise contains error message 889 * @param err_msg NULL if successful, otherwise contains error message
902 */ 890 */
903static void 891static void
904process_peer (void *cls, 892process_peer (void *cls, const struct GNUNET_PeerIdentity *peer,
905 const struct GNUNET_PeerIdentity *peer,
906 const struct GNUNET_HELLO_Message *hello, const char *err_msg) 893 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
907{ 894{
908 struct Peer *pos; 895 struct Peer *pos;
@@ -932,11 +919,10 @@ process_peer (void *cls,
932 GNUNET_CONTAINER_bloomfilter_free (pos->filter); 919 GNUNET_CONTAINER_bloomfilter_free (pos->filter);
933 pos->filter = NULL; 920 pos->filter = NULL;
934 } 921 }
935 if ((!pos->is_connected) && 922 if ((!pos->is_connected) && (!pos->is_friend) &&
936 (!pos->is_friend) &&
937 (0 == 923 (0 ==
938 GNUNET_TIME_absolute_get_remaining (pos-> 924 GNUNET_TIME_absolute_get_remaining (pos->greylisted_until).
939 greylisted_until).rel_value)) 925 rel_value))
940 free_peer (NULL, &pos->pid.hashPubKey, pos); 926 free_peer (NULL, &pos->pid.hashPubKey, pos);
941 } 927 }
942 return; 928 return;
@@ -949,22 +935,22 @@ process_peer (void *cls,
949 if (GNUNET_YES == pos->is_connected) 935 if (GNUNET_YES == pos->is_connected)
950 { 936 {
951#if DEBUG_TOPOLOGY 937#if DEBUG_TOPOLOGY
952 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 938 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Already connected to peer `%s'\n",
953 "Already connected to peer `%s'\n", GNUNET_i2s (peer)); 939 GNUNET_i2s (peer));
954#endif 940#endif
955 return; 941 return;
956 } 942 }
957 if (GNUNET_TIME_absolute_get_remaining (pos->greylisted_until).rel_value > 0) 943 if (GNUNET_TIME_absolute_get_remaining (pos->greylisted_until).rel_value > 0)
958 { 944 {
959#if DEBUG_TOPOLOGY 945#if DEBUG_TOPOLOGY
960 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 946 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Already tried peer `%s' recently\n",
961 "Already tried peer `%s' recently\n", GNUNET_i2s (peer)); 947 GNUNET_i2s (peer));
962#endif 948#endif
963 return; /* peer still greylisted */ 949 return; /* peer still greylisted */
964 } 950 }
965#if DEBUG_TOPOLOGY 951#if DEBUG_TOPOLOGY
966 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 952 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Considering connecting to peer `%s'\n",
967 "Considering connecting to peer `%s'\n", GNUNET_i2s (peer)); 953 GNUNET_i2s (peer));
968#endif 954#endif
969 attempt_connect (pos); 955 attempt_connect (pos);
970} 956}
@@ -980,8 +966,7 @@ process_peer (void *cls,
980 * @param publicKey public key of this peer, NULL if we failed 966 * @param publicKey public key of this peer, NULL if we failed
981 */ 967 */
982static void 968static void
983core_init (void *cls, 969core_init (void *cls, struct GNUNET_CORE_Handle *server,
984 struct GNUNET_CORE_Handle *server,
985 const struct GNUNET_PeerIdentity *my_id, 970 const struct GNUNET_PeerIdentity *my_id,
986 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) 971 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
987{ 972{
@@ -1021,14 +1006,14 @@ read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg)
1021 GNUNET_CONFIGURATION_get_value_filename (cfg, "TOPOLOGY", "FRIENDS", &fn)) 1006 GNUNET_CONFIGURATION_get_value_filename (cfg, "TOPOLOGY", "FRIENDS", &fn))
1022 { 1007 {
1023 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1008 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1024 _("Option `%s' in section `%s' not specified!\n"), 1009 _("Option `%s' in section `%s' not specified!\n"), "FRIENDS",
1025 "FRIENDS", "TOPOLOGY"); 1010 "TOPOLOGY");
1026 return; 1011 return;
1027 } 1012 }
1028 if (GNUNET_OK != GNUNET_DISK_file_test (fn)) 1013 if (GNUNET_OK != GNUNET_DISK_file_test (fn))
1029 GNUNET_DISK_fn_write (fn, NULL, 0, 1014 GNUNET_DISK_fn_write (fn, NULL, 0,
1030 GNUNET_DISK_PERM_USER_READ 1015 GNUNET_DISK_PERM_USER_READ |
1031 | GNUNET_DISK_PERM_USER_WRITE); 1016 GNUNET_DISK_PERM_USER_WRITE);
1032 if (0 != STAT (fn, &frstat)) 1017 if (0 != STAT (fn, &frstat))
1033 { 1018 {
1034 if ((friends_only) || (minimum_friend_count > 0)) 1019 if ((friends_only) || (minimum_friend_count > 0))
@@ -1039,8 +1024,8 @@ read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg)
1039 } 1024 }
1040 if (frstat.st_size == 0) 1025 if (frstat.st_size == 0)
1041 { 1026 {
1042 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1027 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Friends file `%s' is empty.\n"),
1043 _("Friends file `%s' is empty.\n"), fn); 1028 fn);
1044 GNUNET_free (fn); 1029 GNUNET_free (fn);
1045 return; 1030 return;
1046 } 1031 }
@@ -1071,8 +1056,8 @@ read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg)
1071 { 1056 {
1072 memcpy (&enc, &data[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); 1057 memcpy (&enc, &data[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
1073 if (!isspace 1058 if (!isspace
1074 ((unsigned char) 1059 ((unsigned char) enc.
1075 enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1])) 1060 encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1]))
1076 { 1061 {
1077 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1062 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1078 _ 1063 _
@@ -1115,8 +1100,7 @@ read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg)
1115 } 1100 }
1116 GNUNET_free (data); 1101 GNUNET_free (data);
1117 GNUNET_free (fn); 1102 GNUNET_free (fn);
1118 GNUNET_STATISTICS_update (stats, 1103 GNUNET_STATISTICS_update (stats, gettext_noop ("# friends in configuration"),
1119 gettext_noop ("# friends in configuration"),
1120 entries_found, GNUNET_NO); 1104 entries_found, GNUNET_NO);
1121 if ((minimum_friend_count > entries_found) && (friends_only == GNUNET_NO)) 1105 if ((minimum_friend_count > entries_found) && (friends_only == GNUNET_NO))
1122 { 1106 {
@@ -1147,8 +1131,7 @@ read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg)
1147 * GNUNET_SYSERR to close it (signal serious error) 1131 * GNUNET_SYSERR to close it (signal serious error)
1148 */ 1132 */
1149static int 1133static int
1150handle_encrypted_hello (void *cls, 1134handle_encrypted_hello (void *cls, const struct GNUNET_PeerIdentity *other,
1151 const struct GNUNET_PeerIdentity *other,
1152 const struct GNUNET_MessageHeader *message, 1135 const struct GNUNET_MessageHeader *message,
1153 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 1136 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1154{ 1137{
@@ -1156,8 +1139,7 @@ handle_encrypted_hello (void *cls,
1156 struct GNUNET_PeerIdentity pid; 1139 struct GNUNET_PeerIdentity pid;
1157 1140
1158#if DEBUG_TOPOLOGY 1141#if DEBUG_TOPOLOGY
1159 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1142 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received encrypted `%s' from peer `%s'",
1160 "Received encrypted `%s' from peer `%s'",
1161 "HELLO", GNUNET_i2s (other)); 1143 "HELLO", GNUNET_i2s (other));
1162#endif 1144#endif
1163 if (GNUNET_OK != 1145 if (GNUNET_OK !=
@@ -1166,8 +1148,7 @@ handle_encrypted_hello (void *cls,
1166 GNUNET_break_op (0); 1148 GNUNET_break_op (0);
1167 return GNUNET_SYSERR; 1149 return GNUNET_SYSERR;
1168 } 1150 }
1169 GNUNET_STATISTICS_update (stats, 1151 GNUNET_STATISTICS_update (stats, gettext_noop ("# HELLO messages received"),
1170 gettext_noop ("# HELLO messages received"),
1171 1, GNUNET_NO); 1152 1, GNUNET_NO);
1172 peer = GNUNET_CONTAINER_multihashmap_get (peers, &pid.hashPubKey); 1153 peer = GNUNET_CONTAINER_multihashmap_get (peers, &pid.hashPubKey);
1173 if (peer == NULL) 1154 if (peer == NULL)
@@ -1220,12 +1201,12 @@ hello_advertising_ready (void *cls, size_t size, void *buf)
1220 memcpy (buf, fah.result->hello, want); 1201 memcpy (buf, fah.result->hello, want);
1221 GNUNET_CONTAINER_bloomfilter_add (fah.result->filter, &pl->pid.hashPubKey); 1202 GNUNET_CONTAINER_bloomfilter_add (fah.result->filter, &pl->pid.hashPubKey);
1222#if DEBUG_TOPOLOGY 1203#if DEBUG_TOPOLOGY
1223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' with %u bytes", "HELLO",
1224 "Sending `%s' with %u bytes", "HELLO", (unsigned int) want); 1205 (unsigned int) want);
1225#endif 1206#endif
1226 GNUNET_STATISTICS_update (stats, 1207 GNUNET_STATISTICS_update (stats,
1227 gettext_noop ("# HELLO messages gossipped"), 1208 gettext_noop ("# HELLO messages gossipped"), 1,
1228 1, GNUNET_NO); 1209 GNUNET_NO);
1229 } 1210 }
1230 1211
1231 if (pl->hello_delay_task != GNUNET_SCHEDULER_NO_TASK) 1212 if (pl->hello_delay_task != GNUNET_SCHEDULER_NO_TASK)
@@ -1284,9 +1265,8 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1284 * @param c configuration 1265 * @param c configuration
1285 */ 1266 */
1286static void 1267static void
1287run (void *cls, 1268run (void *cls, char *const *args, const char *cfgfile,
1288 char *const *args, 1269 const struct GNUNET_CONFIGURATION_Handle *c)
1289 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
1290{ 1270{
1291 static struct GNUNET_CORE_MessageHandler handlers[] = { 1271 static struct GNUNET_CORE_MessageHandler handlers[] = {
1292 {&handle_encrypted_hello, GNUNET_MESSAGE_TYPE_HELLO, 0}, 1272 {&handle_encrypted_hello, GNUNET_MESSAGE_TYPE_HELLO, 0},
@@ -1296,21 +1276,17 @@ run (void *cls,
1296 1276
1297 cfg = c; 1277 cfg = c;
1298 stats = GNUNET_STATISTICS_create ("topology", cfg); 1278 stats = GNUNET_STATISTICS_create ("topology", cfg);
1299 autoconnect = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1279 autoconnect =
1300 "TOPOLOGY", 1280 GNUNET_CONFIGURATION_get_value_yesno (cfg, "TOPOLOGY", "AUTOCONNECT");
1301 "AUTOCONNECT"); 1281 friends_only =
1302 friends_only = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1282 GNUNET_CONFIGURATION_get_value_yesno (cfg, "TOPOLOGY", "FRIENDS-ONLY");
1303 "TOPOLOGY",
1304 "FRIENDS-ONLY");
1305 if (GNUNET_OK != 1283 if (GNUNET_OK !=
1306 GNUNET_CONFIGURATION_get_value_number (cfg, 1284 GNUNET_CONFIGURATION_get_value_number (cfg, "TOPOLOGY", "MINIMUM-FRIENDS",
1307 "TOPOLOGY", 1285 &opt))
1308 "MINIMUM-FRIENDS", &opt))
1309 opt = 0; 1286 opt = 0;
1310 minimum_friend_count = (unsigned int) opt; 1287 minimum_friend_count = (unsigned int) opt;
1311 if (GNUNET_OK != 1288 if (GNUNET_OK !=
1312 GNUNET_CONFIGURATION_get_value_number (cfg, 1289 GNUNET_CONFIGURATION_get_value_number (cfg, "TOPOLOGY",
1313 "TOPOLOGY",
1314 "TARGET-CONNECTION-COUNT", &opt)) 1290 "TARGET-CONNECTION-COUNT", &opt))
1315 opt = 16; 1291 opt = 16;
1316 target_connection_count = (unsigned int) opt; 1292 target_connection_count = (unsigned int) opt;
@@ -1321,23 +1297,18 @@ run (void *cls,
1321#if DEBUG_TOPOLOGY 1297#if DEBUG_TOPOLOGY
1322 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1323 "Topology would like %u connections with at least %u friends (%s)\n", 1299 "Topology would like %u connections with at least %u friends (%s)\n",
1324 target_connection_count, 1300 target_connection_count, minimum_friend_count,
1325 minimum_friend_count,
1326 autoconnect ? "autoconnect enabled" : "autoconnect disabled"); 1301 autoconnect ? "autoconnect enabled" : "autoconnect disabled");
1327#endif 1302#endif
1328 if ((friend_count < minimum_friend_count) && (blacklist == NULL)) 1303 if ((friend_count < minimum_friend_count) && (blacklist == NULL))
1329 blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_check, NULL); 1304 blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_check, NULL);
1330 transport = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL, NULL, NULL); 1305 transport = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL, NULL, NULL);
1331 handle = GNUNET_CORE_connect (cfg, 1306 handle =
1332 1, 1307 GNUNET_CORE_connect (cfg, 1, NULL, &core_init, &connect_notify,
1333 NULL, 1308 &disconnect_notify, NULL, NULL, GNUNET_NO, NULL,
1334 &core_init, 1309 GNUNET_NO, handlers);
1335 &connect_notify, 1310 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task,
1336 &disconnect_notify, 1311 NULL);
1337 NULL,
1338 NULL, GNUNET_NO, NULL, GNUNET_NO, handlers);
1339 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
1340 &cleaning_task, NULL);
1341 if (NULL == transport) 1312 if (NULL == transport)
1342 { 1313 {
1343 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1314 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -1370,13 +1341,12 @@ main (int argc, char *const *argv)
1370 }; 1341 };
1371 int ret; 1342 int ret;
1372 1343
1373 ret = (GNUNET_OK == 1344 ret =
1374 GNUNET_PROGRAM_run (argc, 1345 (GNUNET_OK ==
1375 argv, 1346 GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-topology",
1376 "gnunet-daemon-topology", 1347 _
1377 _ 1348 ("GNUnet topology control (maintaining P2P mesh and F2F constraints)"),
1378 ("GNUnet topology control (maintaining P2P mesh and F2F constraints)"), 1349 options, &run, NULL)) ? 0 : 1;
1379 options, &run, NULL)) ? 0 : 1;
1380 return ret; 1350 return ret;
1381} 1351}
1382 1352
diff --git a/src/topology/test_gnunet_daemon_topology.c b/src/topology/test_gnunet_daemon_topology.c
index 9d0c055cb..c9a43ecd7 100644
--- a/src/topology/test_gnunet_daemon_topology.c
+++ b/src/topology/test_gnunet_daemon_topology.c
@@ -80,8 +80,7 @@ clean_up_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
80 80
81 81
82static void 82static void
83notify_connect_complete (void *cls, 83notify_connect_complete (void *cls, const struct GNUNET_PeerIdentity *first,
84 const struct GNUNET_PeerIdentity *first,
85 const struct GNUNET_PeerIdentity *second, 84 const struct GNUNET_PeerIdentity *second,
86 unsigned int distance, 85 unsigned int distance,
87 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 86 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
@@ -108,8 +107,7 @@ notify_connect_complete (void *cls,
108 107
109 108
110static void 109static void
111my_cb (void *cls, 110my_cb (void *cls, const struct GNUNET_PeerIdentity *id,
112 const struct GNUNET_PeerIdentity *id,
113 const struct GNUNET_CONFIGURATION_Handle *cfg, 111 const struct GNUNET_CONFIGURATION_Handle *cfg,
114 struct GNUNET_TESTING_Daemon *d, const char *emsg) 112 struct GNUNET_TESTING_Daemon *d, const char *emsg)
115{ 113{
@@ -134,22 +132,17 @@ my_cb (void *cls,
134 132
135 133
136static void 134static void
137run (void *cls, 135run (void *cls, char *const *args, const char *cfgfile,
138 char *const *args, 136 const struct GNUNET_CONFIGURATION_Handle *cfg)
139 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
140{ 137{
141 ok = 1; 138 ok = 1;
142#if VERBOSE 139#if VERBOSE
143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n"); 140 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n");
144#endif 141#endif
145 peers_left = NUM_PEERS; 142 peers_left = NUM_PEERS;
146 pg = GNUNET_TESTING_daemons_start (cfg, 143 pg = GNUNET_TESTING_daemons_start (cfg, peers_left, peers_left, peers_left,
147 peers_left, 144 TIMEOUT, NULL, NULL, &my_cb, NULL, NULL,
148 peers_left, 145 NULL, NULL);
149 peers_left,
150 TIMEOUT,
151 NULL, NULL,
152 &my_cb, NULL, NULL, NULL, NULL);
153 GNUNET_assert (pg != NULL); 146 GNUNET_assert (pg != NULL);
154} 147}
155 148
@@ -169,9 +162,9 @@ check ()
169 struct GNUNET_GETOPT_CommandLineOption options[] = { 162 struct GNUNET_GETOPT_CommandLineOption options[] = {
170 GNUNET_GETOPT_OPTION_END 163 GNUNET_GETOPT_OPTION_END
171 }; 164 };
172 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 165 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
173 argv, "test-gnunet-daemon-topology", "nohelp", 166 "test-gnunet-daemon-topology", "nohelp", options, &run,
174 options, &run, &ok); 167 &ok);
175 return ok; 168 return ok;
176} 169}
177 170
diff --git a/src/transport/gnunet-service-transport-new.c b/src/transport/gnunet-service-transport-new.c
index 8ceffd86c..6c2b396dc 100644
--- a/src/transport/gnunet-service-transport-new.c
+++ b/src/transport/gnunet-service-transport-new.c
@@ -85,16 +85,13 @@ struct GNUNET_ATS_Handle *GST_ats;
85 * @param ats_count number of records in ats (unused) 85 * @param ats_count number of records in ats (unused)
86 */ 86 */
87static void 87static void
88transmit_our_hello (void *cls, 88transmit_our_hello (void *cls, const struct GNUNET_PeerIdentity *target,
89 const struct GNUNET_PeerIdentity *target,
90 const struct GNUNET_TRANSPORT_ATS_Information *ats, 89 const struct GNUNET_TRANSPORT_ATS_Information *ats,
91 uint32_t ats_count) 90 uint32_t ats_count)
92{ 91{
93 const struct GNUNET_MessageHeader *hello = cls; 92 const struct GNUNET_MessageHeader *hello = cls;
94 93
95 GST_neighbours_send (target, 94 GST_neighbours_send (target, (const char *) hello, ntohs (hello->size),
96 (const char *) hello,
97 ntohs (hello->size),
98 GST_HELLO_ADDRESS_EXPIRATION, NULL, NULL); 95 GST_HELLO_ADDRESS_EXPIRATION, NULL, NULL);
99} 96}
100 97
@@ -123,8 +120,8 @@ process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello)
123 * GNUNET_NO if not 120 * GNUNET_NO if not
124 */ 121 */
125static void 122static void
126try_connect_if_allowed (void *cls, 123try_connect_if_allowed (void *cls, const struct GNUNET_PeerIdentity *peer,
127 const struct GNUNET_PeerIdentity *peer, int result) 124 int result)
128{ 125{
129 if (GNUNET_OK != result) 126 if (GNUNET_OK != result)
130 return; /* not allowed */ 127 return; /* not allowed */
@@ -156,8 +153,7 @@ try_connect_if_allowed (void *cls,
156 * (plugins that do not support this, can ignore the return value) 153 * (plugins that do not support this, can ignore the return value)
157 */ 154 */
158static struct GNUNET_TIME_Relative 155static struct GNUNET_TIME_Relative
159plugin_env_receive_callback (void *cls, 156plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
160 const struct GNUNET_PeerIdentity *peer,
161 const struct GNUNET_MessageHeader *message, 157 const struct GNUNET_MessageHeader *message,
162 const struct GNUNET_TRANSPORT_ATS_Information *ats, 158 const struct GNUNET_TRANSPORT_ATS_Information *ats,
163 uint32_t ats_count, struct Session *session, 159 uint32_t ats_count, struct Session *session,
@@ -182,33 +178,29 @@ plugin_env_receive_callback (void *cls,
182 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING: 178 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
183#if DEBUG_TRANSPORT 179#if DEBUG_TRANSPORT
184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
185 "Processing `%s' from `%s'\n", 181 "Processing `%s' from `%s'\n", "PING",
186 "PING", 182 (sender_address != NULL) ? GST_plugins_a2s (plugin_name,
187 (sender_address != NULL) 183 sender_address,
188 ? GST_plugins_a2s (plugin_name, 184 sender_address_len)
189 sender_address, 185 : "<inbound>");
190 sender_address_len) : "<inbound>");
191#endif 186#endif
192 GST_validation_handle_ping (peer, 187 GST_validation_handle_ping (peer, message, plugin_name, session,
193 message, 188 sender_address, sender_address_len);
194 plugin_name,
195 session, sender_address, sender_address_len);
196 break; 189 break;
197 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: 190 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG:
198#if DEBUG_TRANSPORT 191#if DEBUG_TRANSPORT
199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 192 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
200 "Processing `%s' from `%s'\n", 193 "Processing `%s' from `%s'\n", "PONG",
201 "PONG", 194 (sender_address != NULL) ? GST_plugins_a2s (plugin_name,
202 (sender_address != NULL) 195 sender_address,
203 ? GST_plugins_a2s (plugin_name, 196 sender_address_len)
204 sender_address, 197 : "<inbound>");
205 sender_address_len) : "<inbound>");
206#endif 198#endif
207 GST_validation_handle_pong (peer, message); 199 GST_validation_handle_pong (peer, message);
208 break; 200 break;
209 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT: 201 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT:
210 (void) GST_blacklist_test_allowed (peer, 202 (void) GST_blacklist_test_allowed (peer, NULL, &try_connect_if_allowed,
211 NULL, &try_connect_if_allowed, NULL); 203 NULL);
212 /* TODO: if 'session != NULL', maybe notify ATS that this is now the preferred 204 /* TODO: if 'session != NULL', maybe notify ATS that this is now the preferred
213 * way to communicate with this peer (other peer switched transport) */ 205 * way to communicate with this peer (other peer switched transport) */
214 break; 206 break;
@@ -223,20 +215,19 @@ plugin_env_receive_callback (void *cls,
223 default: 215 default:
224 /* should be payload */ 216 /* should be payload */
225 do_forward = GNUNET_SYSERR; 217 do_forward = GNUNET_SYSERR;
226 ret = GST_neighbours_calculate_receive_delay (peer, 218 ret =
227 (message == NULL) 219 GST_neighbours_calculate_receive_delay (peer,
228 ? 0 220 (message ==
229 : ntohs (message->size), 221 NULL) ? 0 : ntohs (message->
230 &do_forward); 222 size),
223 &do_forward);
231 if (do_forward == GNUNET_YES) 224 if (do_forward == GNUNET_YES)
232 GST_clients_broadcast (message, GNUNET_YES); 225 GST_clients_broadcast (message, GNUNET_YES);
233 break; 226 break;
234 } 227 }
235 } 228 }
236 GNUNET_ATS_address_update (GST_ats, peer, GNUNET_TIME_absolute_get (), /* valid at least until right now... */ 229 GNUNET_ATS_address_update (GST_ats, peer, GNUNET_TIME_absolute_get (), /* valid at least until right now... */
237 plugin_name, 230 plugin_name, session, sender_address,
238 session,
239 sender_address,
240 sender_address_len, ats, ats_count); 231 sender_address_len, ats, ats_count);
241 232
242 return ret; 233 return ret;
@@ -255,8 +246,7 @@ plugin_env_receive_callback (void *cls,
255 * @param addrlen length of the address 246 * @param addrlen length of the address
256 */ 247 */
257static void 248static void
258plugin_env_address_change_notification (void *cls, 249plugin_env_address_change_notification (void *cls, int add_remove,
259 int add_remove,
260 const void *addr, size_t addrlen) 250 const void *addr, size_t addrlen)
261{ 251{
262 const char *plugin_name = cls; 252 const char *plugin_name = cls;
@@ -279,8 +269,7 @@ plugin_env_address_change_notification (void *cls,
279 * @param session which session is being destoyed 269 * @param session which session is being destoyed
280 */ 270 */
281static void 271static void
282plugin_env_session_end (void *cls, 272plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
283 const struct GNUNET_PeerIdentity *peer,
284 struct Session *session) 273 struct Session *session)
285{ 274{
286 GST_neighbours_session_terminated (peer, session); 275 GST_neighbours_session_terminated (peer, session);
@@ -303,17 +292,12 @@ plugin_env_session_end (void *cls,
303 * @param bandwidth assigned outbound bandwidth for the connection 292 * @param bandwidth assigned outbound bandwidth for the connection
304 */ 293 */
305static void 294static void
306ats_request_address_change (void *cls, 295ats_request_address_change (void *cls, const struct GNUNET_PeerIdentity *peer,
307 const struct GNUNET_PeerIdentity *peer, 296 const char *plugin_name, struct Session *session,
308 const char *plugin_name, 297 const void *plugin_addr, size_t plugin_addr_len,
309 struct Session *session,
310 const void *plugin_addr,
311 size_t plugin_addr_len,
312 struct GNUNET_BANDWIDTH_Value32NBO bandwidth) 298 struct GNUNET_BANDWIDTH_Value32NBO bandwidth)
313{ 299{
314 GST_neighbours_switch_to_address (peer, 300 GST_neighbours_switch_to_address (peer, plugin_name, plugin_addr,
315 plugin_name,
316 plugin_addr,
317 plugin_addr_len, session, NULL, 0); 301 plugin_addr_len, session, NULL, 0);
318 GST_neighbours_set_incoming_quota (peer, bandwidth); 302 GST_neighbours_set_incoming_quota (peer, bandwidth);
319} 303}
@@ -417,8 +401,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
417 * @param c configuration to use 401 * @param c configuration to use
418 */ 402 */
419static void 403static void
420run (void *cls, 404run (void *cls, struct GNUNET_SERVER_Handle *server,
421 struct GNUNET_SERVER_Handle *server,
422 const struct GNUNET_CONFIGURATION_Handle *c) 405 const struct GNUNET_CONFIGURATION_Handle *c)
423{ 406{
424 char *keyfile; 407 char *keyfile;
@@ -426,8 +409,8 @@ run (void *cls,
426 /* setup globals */ 409 /* setup globals */
427 GST_cfg = c; 410 GST_cfg = c;
428 if (GNUNET_OK != 411 if (GNUNET_OK !=
429 GNUNET_CONFIGURATION_get_value_filename (c, 412 GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY",
430 "GNUNETD", "HOSTKEY", &keyfile)) 413 &keyfile))
431 { 414 {
432 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 415 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
433 _ 416 _
@@ -447,10 +430,10 @@ run (void *cls,
447 GST_stats = GNUNET_STATISTICS_create ("transport", c); 430 GST_stats = GNUNET_STATISTICS_create ("transport", c);
448 GST_peerinfo = GNUNET_PEERINFO_connect (c); 431 GST_peerinfo = GNUNET_PEERINFO_connect (c);
449 GNUNET_CRYPTO_rsa_key_get_public (GST_my_private_key, &GST_my_public_key); 432 GNUNET_CRYPTO_rsa_key_get_public (GST_my_private_key, &GST_my_public_key);
450 GNUNET_CRYPTO_hash (&GST_my_public_key, 433 GNUNET_CRYPTO_hash (&GST_my_public_key, sizeof (GST_my_public_key),
451 sizeof (GST_my_public_key), &GST_my_identity.hashPubKey); 434 &GST_my_identity.hashPubKey);
452 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 435 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
453 &shutdown_task, NULL); 436 NULL);
454 if (GST_peerinfo == NULL) 437 if (GST_peerinfo == NULL)
455 { 438 {
456 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 439 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -466,8 +449,7 @@ run (void *cls,
466 &plugin_env_address_change_notification, 449 &plugin_env_address_change_notification,
467 &plugin_env_session_end); 450 &plugin_env_session_end);
468 GST_ats = GNUNET_ATS_init (GST_cfg, &ats_request_address_change, NULL); 451 GST_ats = GNUNET_ATS_init (GST_cfg, &ats_request_address_change, NULL);
469 GST_neighbours_start (NULL, 452 GST_neighbours_start (NULL, &neighbours_connect_notification,
470 &neighbours_connect_notification,
471 &neighbours_disconnect_notification); 453 &neighbours_disconnect_notification);
472 GST_clients_start (server); 454 GST_clients_start (server);
473 GST_validation_start (); 455 GST_validation_start ();
@@ -485,9 +467,7 @@ int
485main (int argc, char *const *argv) 467main (int argc, char *const *argv)
486{ 468{
487 return (GNUNET_OK == 469 return (GNUNET_OK ==
488 GNUNET_SERVICE_run (argc, 470 GNUNET_SERVICE_run (argc, argv, "transport",
489 argv,
490 "transport",
491 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; 471 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
492} 472}
493 473
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index 4f962d117..5b0a58fac 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -1065,8 +1065,7 @@ is_blacklisted (const struct GNUNET_PeerIdentity *peer,
1065 (plugin->blacklist, &peer->hashPubKey) == GNUNET_YES) 1065 (plugin->blacklist, &peer->hashPubKey) == GNUNET_YES)
1066 { 1066 {
1067#if DEBUG_BLACKLIST 1067#if DEBUG_BLACKLIST
1068 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1068 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s:%s' is blacklisted!\n",
1069 "Peer `%s:%s' is blacklisted!\n",
1070 plugin->short_name, GNUNET_i2s (peer)); 1069 plugin->short_name, GNUNET_i2s (peer));
1071#endif 1070#endif
1072 if (stats != NULL) 1071 if (stats != NULL)
@@ -1097,8 +1096,7 @@ add_peer_to_blacklist (struct GNUNET_PeerIdentity *peer, char *transport_name)
1097 plugin->blacklist = 1096 plugin->blacklist =
1098 GNUNET_CONTAINER_multihashmap_create (TRANSPORT_BLACKLIST_HT_SIZE); 1097 GNUNET_CONTAINER_multihashmap_create (TRANSPORT_BLACKLIST_HT_SIZE);
1099 GNUNET_assert (plugin->blacklist != NULL); 1098 GNUNET_assert (plugin->blacklist != NULL);
1100 GNUNET_CONTAINER_multihashmap_put (plugin->blacklist, &peer->hashPubKey, 1099 GNUNET_CONTAINER_multihashmap_put (plugin->blacklist, &peer->hashPubKey, NULL,
1101 NULL,
1102 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); 1100 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
1103} 1101}
1104 1102
@@ -1124,8 +1122,7 @@ read_blacklist_file (const struct GNUNET_CONFIGURATION_Handle *cfg)
1124 char *transport_name; 1122 char *transport_name;
1125 1123
1126 if (GNUNET_OK != 1124 if (GNUNET_OK !=
1127 GNUNET_CONFIGURATION_get_value_filename (cfg, 1125 GNUNET_CONFIGURATION_get_value_filename (cfg, "TRANSPORT",
1128 "TRANSPORT",
1129 "BLACKLIST_FILE", &fn)) 1126 "BLACKLIST_FILE", &fn))
1130 { 1127 {
1131#if DEBUG_TRANSPORT 1128#if DEBUG_TRANSPORT
@@ -1136,8 +1133,9 @@ read_blacklist_file (const struct GNUNET_CONFIGURATION_Handle *cfg)
1136 return; 1133 return;
1137 } 1134 }
1138 if (GNUNET_OK != GNUNET_DISK_file_test (fn)) 1135 if (GNUNET_OK != GNUNET_DISK_file_test (fn))
1139 GNUNET_DISK_fn_write (fn, NULL, 0, GNUNET_DISK_PERM_USER_READ 1136 GNUNET_DISK_fn_write (fn, NULL, 0,
1140 | GNUNET_DISK_PERM_USER_WRITE); 1137 GNUNET_DISK_PERM_USER_READ |
1138 GNUNET_DISK_PERM_USER_WRITE);
1141 if (0 != STAT (fn, &frstat)) 1139 if (0 != STAT (fn, &frstat))
1142 { 1140 {
1143 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1141 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -1148,8 +1146,8 @@ read_blacklist_file (const struct GNUNET_CONFIGURATION_Handle *cfg)
1148 if (frstat.st_size == 0) 1146 if (frstat.st_size == 0)
1149 { 1147 {
1150#if DEBUG_TRANSPORT 1148#if DEBUG_TRANSPORT
1151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Blacklist file `%s' is empty.\n"),
1152 _("Blacklist file `%s' is empty.\n"), fn); 1150 fn);
1153#endif 1151#endif
1154 GNUNET_free (fn); 1152 GNUNET_free (fn);
1155 return; 1153 return;
@@ -1225,8 +1223,8 @@ read_blacklist_file (const struct GNUNET_CONFIGURATION_Handle *cfg)
1225#endif 1223#endif
1226 memcpy (&enc, &data[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); 1224 memcpy (&enc, &data[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
1227 if (!isspace 1225 if (!isspace
1228 ((unsigned char) 1226 ((unsigned char) enc.
1229 enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1])) 1227 encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1]))
1230 { 1228 {
1231 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1229 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1232 _ 1230 _
@@ -1338,11 +1336,11 @@ transmit_to_client_callback (void *cls, size_t size, void *buf)
1338 if (NULL != q) 1336 if (NULL != q)
1339 { 1337 {
1340 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader)); 1338 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
1341 client->th = GNUNET_SERVER_notify_transmit_ready (client->client, 1339 client->th =
1342 msize, 1340 GNUNET_SERVER_notify_transmit_ready (client->client, msize,
1343 GNUNET_TIME_UNIT_FOREVER_REL, 1341 GNUNET_TIME_UNIT_FOREVER_REL,
1344 &transmit_to_client_callback, 1342 &transmit_to_client_callback,
1345 client); 1343 client);
1346 GNUNET_assert (client->th != NULL); 1344 GNUNET_assert (client->th != NULL);
1347 } 1345 }
1348 return tsize; 1346 return tsize;
@@ -1419,11 +1417,10 @@ timeout_hello_validation (void *cls,
1419 1417
1420 va->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1418 va->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1421 GNUNET_STATISTICS_update (stats, 1419 GNUNET_STATISTICS_update (stats,
1422 gettext_noop ("# address validation timeouts"), 1420 gettext_noop ("# address validation timeouts"), 1,
1423 1, GNUNET_NO); 1421 GNUNET_NO);
1424 GNUNET_CRYPTO_hash (&va->publicKey, 1422 GNUNET_CRYPTO_hash (&va->publicKey,
1425 sizeof (struct 1423 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1426 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1427 &pid.hashPubKey); 1424 &pid.hashPubKey);
1428 GNUNET_break (GNUNET_OK == 1425 GNUNET_break (GNUNET_OK ==
1429 GNUNET_CONTAINER_multihashmap_remove (validation_map, 1426 GNUNET_CONTAINER_multihashmap_remove (validation_map,
@@ -1464,8 +1461,8 @@ transmit_to_client (struct TransportClient *client,
1464 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1461 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1465 _ 1462 _
1466 ("Dropping message of type %u and size %u, have %u messages pending (%u is the soft limit)\n"), 1463 ("Dropping message of type %u and size %u, have %u messages pending (%u is the soft limit)\n"),
1467 ntohs (msg->type), 1464 ntohs (msg->type), ntohs (msg->size), client->message_count,
1468 ntohs (msg->size), client->message_count, MAX_PENDING); 1465 MAX_PENDING);
1469 GNUNET_STATISTICS_update (stats, 1466 GNUNET_STATISTICS_update (stats,
1470 gettext_noop 1467 gettext_noop
1471 ("# messages dropped due to slow client"), 1, 1468 ("# messages dropped due to slow client"), 1,
@@ -1481,11 +1478,11 @@ transmit_to_client (struct TransportClient *client,
1481 client->message_count++; 1478 client->message_count++;
1482 if (client->th == NULL) 1479 if (client->th == NULL)
1483 { 1480 {
1484 client->th = GNUNET_SERVER_notify_transmit_ready (client->client, 1481 client->th =
1485 msize, 1482 GNUNET_SERVER_notify_transmit_ready (client->client, msize,
1486 GNUNET_TIME_UNIT_FOREVER_REL, 1483 GNUNET_TIME_UNIT_FOREVER_REL,
1487 &transmit_to_client_callback, 1484 &transmit_to_client_callback,
1488 client); 1485 client);
1489 GNUNET_assert (client->th != NULL); 1486 GNUNET_assert (client->th != NULL);
1490 } 1487 }
1491} 1488}
@@ -1501,8 +1498,7 @@ transmit_to_client (struct TransportClient *client,
1501 * @param result status code for the transmission request 1498 * @param result status code for the transmission request
1502 */ 1499 */
1503static void 1500static void
1504transmit_send_ok (struct TransportClient *client, 1501transmit_send_ok (struct TransportClient *client, struct NeighbourMapEntry *n,
1505 struct NeighbourMapEntry *n,
1506 const struct GNUNET_PeerIdentity *target, int result) 1502 const struct GNUNET_PeerIdentity *target, int result)
1507{ 1503{
1508 struct SendOkMessage send_ok_msg; 1504 struct SendOkMessage send_ok_msg;
@@ -1561,8 +1557,7 @@ retry_transmission_task (void *cls,
1561 * more messages 1557 * more messages
1562 */ 1558 */
1563static void 1559static void
1564transmit_send_continuation (void *cls, 1560transmit_send_continuation (void *cls, const struct GNUNET_PeerIdentity *target,
1565 const struct GNUNET_PeerIdentity *target,
1566 int result) 1561 int result)
1567{ 1562{
1568 struct MessageQueue *mq = cls; 1563 struct MessageQueue *mq = cls;
@@ -1606,8 +1601,7 @@ transmit_send_continuation (void *cls,
1606 mq->specific_address->addr, 1601 mq->specific_address->addr,
1607 mq->specific_address->addrlen)); 1602 mq->specific_address->addrlen));
1608#endif 1603#endif
1609 GNUNET_STATISTICS_update (stats, 1604 GNUNET_STATISTICS_update (stats, gettext_noop ("# connected addresses"),
1610 gettext_noop ("# connected addresses"),
1611 -1, GNUNET_NO); 1605 -1, GNUNET_NO);
1612 mq->specific_address->connected = GNUNET_NO; 1606 mq->specific_address->connected = GNUNET_NO;
1613 } 1607 }
@@ -1698,13 +1692,13 @@ try_transmission_to_peer (struct NeighbourMapEntry *n)
1698 GNUNET_NO); 1692 GNUNET_NO);
1699 if (n->retry_task != GNUNET_SCHEDULER_NO_TASK) 1693 if (n->retry_task != GNUNET_SCHEDULER_NO_TASK)
1700 GNUNET_SCHEDULER_cancel (n->retry_task); 1694 GNUNET_SCHEDULER_cancel (n->retry_task);
1701 n->retry_task = GNUNET_SCHEDULER_add_delayed (timeout, 1695 n->retry_task =
1702 &retry_transmission_task, n); 1696 GNUNET_SCHEDULER_add_delayed (timeout, &retry_transmission_task, n);
1703#if DEBUG_TRANSPORT 1697#if DEBUG_TRANSPORT
1704 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1698 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1705 "No validated destination address available to transmit message of size %u to peer `%4s', will wait %llums to find an address.\n", 1699 "No validated destination address available to transmit message of size %u to peer `%4s', will wait %llums to find an address.\n",
1706 mq->message_buf_size, 1700 mq->message_buf_size, GNUNET_i2s (&mq->neighbour_id),
1707 GNUNET_i2s (&mq->neighbour_id), timeout.rel_value); 1701 timeout.rel_value);
1708#endif 1702#endif
1709 /* FIXME: might want to trigger peerinfo lookup here 1703 /* FIXME: might want to trigger peerinfo lookup here
1710 * (unless that's already pending...) */ 1704 * (unless that's already pending...) */
@@ -1720,13 +1714,11 @@ try_transmission_to_peer (struct NeighbourMapEntry *n)
1720#if DEBUG_TRANSPORT 1714#if DEBUG_TRANSPORT
1721 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1715 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1722 "Sending message of size %u for `%4s' to `%s' via plugin `%s'\n", 1716 "Sending message of size %u for `%4s' to `%s' via plugin `%s'\n",
1723 mq->message_buf_size, 1717 mq->message_buf_size, GNUNET_i2s (&n->id),
1724 GNUNET_i2s (&n->id), 1718 (mq->specific_address->addr !=
1725 (mq->specific_address->addr != NULL) 1719 NULL) ? a2s (mq->plugin->short_name, mq->specific_address->addr,
1726 ? a2s (mq->plugin->short_name, 1720 mq->specific_address->addrlen) : "<inbound>",
1727 mq->specific_address->addr, 1721 rl->plugin->short_name);
1728 mq->specific_address->addrlen)
1729 : "<inbound>", rl->plugin->short_name);
1730#endif 1722#endif
1731 GNUNET_STATISTICS_update (stats, 1723 GNUNET_STATISTICS_update (stats,
1732 gettext_noop 1724 gettext_noop
@@ -1738,16 +1730,15 @@ try_transmission_to_peer (struct NeighbourMapEntry *n)
1738 1730
1739 GNUNET_CONTAINER_DLL_insert (n->cont_head, n->cont_tail, mq); 1731 GNUNET_CONTAINER_DLL_insert (n->cont_head, n->cont_tail, mq);
1740 1732
1741 ret = rl->plugin->api->send (rl->plugin->api->cls, 1733 ret =
1742 &mq->neighbour_id, 1734 rl->plugin->api->send (rl->plugin->api->cls, &mq->neighbour_id,
1743 mq->message_buf, 1735 mq->message_buf, mq->message_buf_size,
1744 mq->message_buf_size, 1736 mq->priority,
1745 mq->priority, 1737 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1746 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1738 mq->specific_address->session,
1747 mq->specific_address->session, 1739 mq->specific_address->addr,
1748 mq->specific_address->addr, 1740 mq->specific_address->addrlen, force_address,
1749 mq->specific_address->addrlen, 1741 &transmit_send_continuation, mq);
1750 force_address, &transmit_send_continuation, mq);
1751 if (ret == -1) 1742 if (ret == -1)
1752 { 1743 {
1753 /* failure, but 'send' would not call continuation in this case, 1744 /* failure, but 'send' would not call continuation in this case,
@@ -1773,10 +1764,8 @@ try_transmission_to_peer (struct NeighbourMapEntry *n)
1773static void 1764static void
1774transmit_to_peer (struct TransportClient *client, 1765transmit_to_peer (struct TransportClient *client,
1775 struct ForeignAddressList *peer_address, 1766 struct ForeignAddressList *peer_address,
1776 unsigned int priority, 1767 unsigned int priority, struct GNUNET_TIME_Relative timeout,
1777 struct GNUNET_TIME_Relative timeout, 1768 const char *message_buf, size_t message_buf_size,
1778 const char *message_buf,
1779 size_t message_buf_size,
1780 int is_internal, struct NeighbourMapEntry *neighbour) 1769 int is_internal, struct NeighbourMapEntry *neighbour)
1781{ 1770{
1782 struct MessageQueue *mq; 1771 struct MessageQueue *mq;
@@ -1865,12 +1854,11 @@ transmit_plain_ping (struct NeighbourMapEntry *n)
1865 continue; 1854 continue;
1866 ve = GNUNET_malloc (sizeof (struct ValidationEntry)); 1855 ve = GNUNET_malloc (sizeof (struct ValidationEntry));
1867 ve->transport_name = GNUNET_strdup (plugin->short_name); 1856 ve->transport_name = GNUNET_strdup (plugin->short_name);
1868 ve->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 1857 ve->challenge =
1869 UINT_MAX); 1858 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT_MAX);
1870 ve->send_time = GNUNET_TIME_absolute_get (); 1859 ve->send_time = GNUNET_TIME_absolute_get ();
1871 ve->session = fal->session; 1860 ve->session = fal->session;
1872 memcpy (&ve->publicKey, 1861 memcpy (&ve->publicKey, &n->publicKey,
1873 &n->publicKey,
1874 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 1862 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
1875 ve->timeout_task = 1863 ve->timeout_task =
1876 GNUNET_SCHEDULER_add_delayed (HELLO_VERIFICATION_TIMEOUT, 1864 GNUNET_SCHEDULER_add_delayed (HELLO_VERIFICATION_TIMEOUT,
@@ -1919,8 +1907,8 @@ mark_address_connected (struct ForeignAddressList *fal)
1919 while (pos != NULL) 1907 while (pos != NULL)
1920 { 1908 {
1921 /* Already have inbound address, and this is also an inbound address, don't switch!! */ 1909 /* Already have inbound address, and this is also an inbound address, don't switch!! */
1922 if ((GNUNET_YES == pos->connected) && 1910 if ((GNUNET_YES == pos->connected) && (0 == pos->addrlen) &&
1923 (0 == pos->addrlen) && (0 == fal->addrlen)) 1911 (0 == fal->addrlen))
1924 return; 1912 return;
1925 if ((0 == pos->addrlen) && (GNUNET_YES == pos->connected)) 1913 if ((0 == pos->addrlen) && (GNUNET_YES == pos->connected))
1926 inbound = pos; 1914 inbound = pos;
@@ -1931,8 +1919,8 @@ mark_address_connected (struct ForeignAddressList *fal)
1931 while (pos != NULL) 1919 while (pos != NULL)
1932 { 1920 {
1933 /* Already have outbound address, and this is also an outbound address, don't switch!! */ 1921 /* Already have outbound address, and this is also an outbound address, don't switch!! */
1934 if ((GNUNET_YES == pos->connected) && 1922 if ((GNUNET_YES == pos->connected) && (0 < pos->addrlen) &&
1935 (0 < pos->addrlen) && (0 < fal->addrlen)) 1923 (0 < fal->addrlen))
1936 return; 1924 return;
1937 if ((0 < pos->addrlen) && (GNUNET_YES == pos->connected)) 1925 if ((0 < pos->addrlen) && (GNUNET_YES == pos->connected))
1938 outbound = pos; 1926 outbound = pos;
@@ -1949,14 +1937,11 @@ mark_address_connected (struct ForeignAddressList *fal)
1949#endif 1937#endif
1950 1938
1951 /* Have an inbound connection to this peer which is valid; our id is lower, ignore outbound connection! */ 1939 /* Have an inbound connection to this peer which is valid; our id is lower, ignore outbound connection! */
1952 if ((inbound != NULL) && (0 != fal->addrlen) && (1 1940 if ((inbound != NULL) && (0 != fal->addrlen) &&
1953 == 1941 (1 ==
1954 GNUNET_CRYPTO_hash_xorcmp 1942 GNUNET_CRYPTO_hash_xorcmp (&inbound->ready_list->neighbour->
1955 (&inbound-> 1943 id.hashPubKey, &my_identity.hashPubKey,
1956 ready_list->neighbour->id. 1944 &null_hash)))
1957 hashPubKey,
1958 &my_identity.hashPubKey,
1959 &null_hash)))
1960 { 1945 {
1961#if DEBUG_INBOUND 1946#if DEBUG_INBOUND
1962 fprintf (stderr, "Peer: %s, had inbound connection, ignoring outbound!\n", 1947 fprintf (stderr, "Peer: %s, had inbound connection, ignoring outbound!\n",
@@ -1964,13 +1949,11 @@ mark_address_connected (struct ForeignAddressList *fal)
1964#endif 1949#endif
1965 return; 1950 return;
1966 } 1951 }
1967 else if ((outbound != NULL) && (0 == fal->addrlen) && ((-1 1952 else if ((outbound != NULL) && (0 == fal->addrlen) &&
1968 == 1953 ((-1 ==
1969 GNUNET_CRYPTO_hash_xorcmp 1954 GNUNET_CRYPTO_hash_xorcmp (&outbound->ready_list->neighbour->id.
1970 (&outbound->ready_list->neighbour-> 1955 hashPubKey, &my_identity.hashPubKey,
1971 id.hashPubKey, 1956 &null_hash))))
1972 &my_identity.hashPubKey,
1973 &null_hash))))
1974 { 1957 {
1975#if DEBUG_INBOUND 1958#if DEBUG_INBOUND
1976 fprintf (stderr, "Peer: %s, have outbound connection, ignoring inbound!\n", 1959 fprintf (stderr, "Peer: %s, have outbound connection, ignoring inbound!\n",
@@ -1991,22 +1974,20 @@ mark_address_connected (struct ForeignAddressList *fal)
1991 pos->addrlen)); 1974 pos->addrlen));
1992#endif 1975#endif
1993#if DEBUG_INBOUND 1976#if DEBUG_INBOUND
1994 fprintf (stderr, 1977 fprintf (stderr, "Peer: %s, setting %s connection to disconnected.\n",
1995 "Peer: %s, setting %s connection to disconnected.\n",
1996 GNUNET_i2s (&my_identity), 1978 GNUNET_i2s (&my_identity),
1997 (0 == pos->addrlen) ? "INBOUND" : "OUTBOUND"); 1979 (0 == pos->addrlen) ? "INBOUND" : "OUTBOUND");
1998#endif 1980#endif
1999 pos->connected = GNUNET_NO; 1981 pos->connected = GNUNET_NO;
2000 GNUNET_STATISTICS_update (stats, 1982 GNUNET_STATISTICS_update (stats, gettext_noop ("# connected addresses"),
2001 gettext_noop ("# connected addresses"), -1, 1983 -1, GNUNET_NO);
2002 GNUNET_NO);
2003 } 1984 }
2004 pos = pos->next; 1985 pos = pos->next;
2005 } 1986 }
2006 GNUNET_assert (GNUNET_NO == fal->connected); 1987 GNUNET_assert (GNUNET_NO == fal->connected);
2007 fal->connected = GNUNET_YES; 1988 fal->connected = GNUNET_YES;
2008 GNUNET_STATISTICS_update (stats, gettext_noop ("# connected addresses"), 1989 GNUNET_STATISTICS_update (stats, gettext_noop ("# connected addresses"), 1,
2009 1, GNUNET_NO); 1990 GNUNET_NO);
2010} 1991}
2011 1992
2012 1993
@@ -2044,8 +2025,7 @@ find_ready_address (struct NeighbourMapEntry *neighbour)
2044 "Marking long-time inactive connection to `%4s' as down.\n", 2025 "Marking long-time inactive connection to `%4s' as down.\n",
2045 GNUNET_i2s (&neighbour->id)); 2026 GNUNET_i2s (&neighbour->id));
2046#endif 2027#endif
2047 GNUNET_STATISTICS_update (stats, 2028 GNUNET_STATISTICS_update (stats, gettext_noop ("# connected addresses"),
2048 gettext_noop ("# connected addresses"),
2049 -1, GNUNET_NO); 2029 -1, GNUNET_NO);
2050 addresses->connected = GNUNET_NO; 2030 addresses->connected = GNUNET_NO;
2051 } 2031 }
@@ -2059,14 +2039,10 @@ find_ready_address (struct NeighbourMapEntry *neighbour)
2059 if (addresses->addr != NULL) 2039 if (addresses->addr != NULL)
2060 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2040 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2061 "Have address `%s' for peer `%4s' (status: %d, %d, %d, %u, %llums, %u)\n", 2041 "Have address `%s' for peer `%4s' (status: %d, %d, %d, %u, %llums, %u)\n",
2062 a2s (head->plugin->short_name, 2042 a2s (head->plugin->short_name, addresses->addr,
2063 addresses->addr, 2043 addresses->addrlen), GNUNET_i2s (&neighbour->id),
2064 addresses->addrlen), 2044 addresses->connected, addresses->in_transmit,
2065 GNUNET_i2s (&neighbour->id), 2045 addresses->validated, addresses->connect_attempts,
2066 addresses->connected,
2067 addresses->in_transmit,
2068 addresses->validated,
2069 addresses->connect_attempts,
2070 (unsigned long long) addresses->timeout.abs_value, 2046 (unsigned long long) addresses->timeout.abs_value,
2071 (unsigned int) addresses->distance); 2047 (unsigned int) addresses->distance);
2072#endif 2048#endif
@@ -2077,12 +2053,13 @@ find_ready_address (struct NeighbourMapEntry *neighbour)
2077 (addresses->latency.rel_value < unix_address->latency.rel_value))) 2053 (addresses->latency.rel_value < unix_address->latency.rel_value)))
2078 unix_address = addresses; 2054 unix_address = addresses;
2079 } 2055 }
2080 if (((best_address == NULL) || 2056 if (((best_address == NULL) || (addresses->connected == GNUNET_YES) ||
2081 (addresses->connected == GNUNET_YES) ||
2082 (best_address->connected == GNUNET_NO)) && 2057 (best_address->connected == GNUNET_NO)) &&
2083 (addresses->in_transmit == GNUNET_NO) && 2058 (addresses->in_transmit == GNUNET_NO) && ((best_address == NULL) ||
2084 ((best_address == NULL) || 2059 (addresses->latency.
2085 (addresses->latency.rel_value < best_address->latency.rel_value))) 2060 rel_value <
2061 best_address->latency.
2062 rel_value)))
2086 best_address = addresses; 2063 best_address = addresses;
2087 /* FIXME: also give lower-latency addresses that are not 2064 /* FIXME: also give lower-latency addresses that are not
2088 * connected a chance some times... */ 2065 * connected a chance some times... */
@@ -2105,11 +2082,11 @@ find_ready_address (struct NeighbourMapEntry *neighbour)
2105#if DEBUG_TRANSPORT 2082#if DEBUG_TRANSPORT
2106 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2083 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2107 "Best address found (`%s') has latency of %llu ms.\n", 2084 "Best address found (`%s') has latency of %llu ms.\n",
2108 (best_address->addrlen > 0) 2085 (best_address->addrlen >
2109 ? a2s (best_address->ready_list->plugin->short_name, 2086 0) ? a2s (best_address->ready_list->plugin->short_name,
2110 best_address->addr, 2087 best_address->addr,
2111 best_address->addrlen) 2088 best_address->addrlen) : "<inbound>",
2112 : "<inbound>", best_address->latency.rel_value); 2089 best_address->latency.rel_value);
2113#endif 2090#endif
2114 } 2091 }
2115 else 2092 else
@@ -2154,10 +2131,10 @@ address_generator (void *cls, size_t max, void *buf)
2154 2131
2155 return 0; 2132 return 0;
2156 } 2133 }
2157 ret = GNUNET_HELLO_add_address (gc->plug_pos->short_name, 2134 ret =
2158 gc->expiration, 2135 GNUNET_HELLO_add_address (gc->plug_pos->short_name, gc->expiration,
2159 &gc->addr_pos[1], 2136 &gc->addr_pos[1], gc->addr_pos->addrlen, buf,
2160 gc->addr_pos->addrlen, buf, max); 2137 max);
2161 gc->addr_pos = gc->addr_pos->next; 2138 gc->addr_pos = gc->addr_pos->next;
2162 return ret; 2139 return ret;
2163} 2140}
@@ -2173,8 +2150,8 @@ transmit_our_hello_if_pong (void *cls, const GNUNET_HashCode * key, void *value)
2173 return GNUNET_OK; 2150 return GNUNET_OK;
2174#if DEBUG_TRANSPORT 2151#if DEBUG_TRANSPORT
2175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 2152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
2176 "Transmitting updated `%s' to neighbour `%4s'\n", 2153 "Transmitting updated `%s' to neighbour `%4s'\n", "HELLO",
2177 "HELLO", GNUNET_i2s (&npos->id)); 2154 GNUNET_i2s (&npos->id));
2178#endif 2155#endif
2179 GNUNET_STATISTICS_update (stats, 2156 GNUNET_STATISTICS_update (stats,
2180 gettext_noop 2157 gettext_noop
@@ -2211,15 +2188,14 @@ refresh_hello_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2211 "Refreshed my `%s', new size is %d\n", "HELLO", 2188 "Refreshed my `%s', new size is %d\n", "HELLO",
2212 GNUNET_HELLO_size (hello)); 2189 GNUNET_HELLO_size (hello));
2213#endif 2190#endif
2214 GNUNET_STATISTICS_update (stats, 2191 GNUNET_STATISTICS_update (stats, gettext_noop ("# refreshed my HELLO"), 1,
2215 gettext_noop ("# refreshed my HELLO"), 2192 GNUNET_NO);
2216 1, GNUNET_NO);
2217 cpos = clients; 2193 cpos = clients;
2218 while (cpos != NULL) 2194 while (cpos != NULL)
2219 { 2195 {
2220 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting my HELLO to client!\n"); 2196 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting my HELLO to client!\n");
2221 transmit_to_client (cpos, 2197 transmit_to_client (cpos, (const struct GNUNET_MessageHeader *) hello,
2222 (const struct GNUNET_MessageHeader *) hello, GNUNET_NO); 2198 GNUNET_NO);
2223 cpos = cpos->next; 2199 cpos = cpos->next;
2224 } 2200 }
2225 2201
@@ -2320,9 +2296,8 @@ try_fast_reconnect (struct TransportPlugin *p, struct NeighbourMapEntry *nl)
2320 /* No reconnect, signal disconnect instead! */ 2296 /* No reconnect, signal disconnect instead! */
2321#if DEBUG_TRANSPORT 2297#if DEBUG_TRANSPORT
2322#endif 2298#endif
2323 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s', %s\n",
2324 "Disconnecting peer `%4s', %s\n", GNUNET_i2s (&nl->id), 2300 GNUNET_i2s (&nl->id), "try_fast_reconnect");
2325 "try_fast_reconnect");
2326 2301
2327 GNUNET_STATISTICS_update (stats, 2302 GNUNET_STATISTICS_update (stats,
2328 gettext_noop 2303 gettext_noop
@@ -2346,8 +2321,7 @@ try_fast_reconnect (struct TransportPlugin *p, struct NeighbourMapEntry *nl)
2346 * @param session which session is being destoyed 2321 * @param session which session is being destoyed
2347 */ 2322 */
2348static void 2323static void
2349plugin_env_session_end (void *cls, 2324plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
2350 const struct GNUNET_PeerIdentity *peer,
2351 struct Session *session) 2325 struct Session *session)
2352{ 2326{
2353 struct TransportPlugin *p = cls; 2327 struct TransportPlugin *p = cls;
@@ -2357,8 +2331,7 @@ plugin_env_session_end (void *cls,
2357 struct ForeignAddressList *prev; 2331 struct ForeignAddressList *prev;
2358 2332
2359#if DEBUG_TRANSPORT 2333#if DEBUG_TRANSPORT
2360 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2334 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Session ended with peer `%4s', %s\n",
2361 "Session ended with peer `%4s', %s\n",
2362 GNUNET_i2s (peer), "plugin_env_session_end"); 2335 GNUNET_i2s (peer), "plugin_env_session_end");
2363#endif 2336#endif
2364 GNUNET_CONTAINER_multihashmap_iterate (validation_map, 2337 GNUNET_CONTAINER_multihashmap_iterate (validation_map,
@@ -2435,9 +2408,8 @@ plugin_env_session_end (void *cls,
2435 if (GNUNET_YES == pos->connected) 2408 if (GNUNET_YES == pos->connected)
2436 { 2409 {
2437 pos->connected = GNUNET_NO; 2410 pos->connected = GNUNET_NO;
2438 GNUNET_STATISTICS_update (stats, 2411 GNUNET_STATISTICS_update (stats, gettext_noop ("# connected addresses"), -1,
2439 gettext_noop ("# connected addresses"), 2412 GNUNET_NO);
2440 -1, GNUNET_NO);
2441 } 2413 }
2442 if (GNUNET_SCHEDULER_NO_TASK != pos->revalidate_task) 2414 if (GNUNET_SCHEDULER_NO_TASK != pos->revalidate_task)
2443 { 2415 {
@@ -2491,16 +2463,15 @@ plugin_env_session_end (void *cls,
2491 return; 2463 return;
2492 } 2464 }
2493 pos->connected = GNUNET_NO; 2465 pos->connected = GNUNET_NO;
2494 GNUNET_STATISTICS_update (stats, 2466 GNUNET_STATISTICS_update (stats, gettext_noop ("# connected addresses"), -1,
2495 gettext_noop ("# connected addresses"), 2467 GNUNET_NO);
2496 -1, GNUNET_NO);
2497 GNUNET_free (pos); 2468 GNUNET_free (pos);
2498 2469
2499 if (nl->received_pong == GNUNET_NO) 2470 if (nl->received_pong == GNUNET_NO)
2500 { 2471 {
2501 GNUNET_STATISTICS_update (stats, 2472 GNUNET_STATISTICS_update (stats,
2502 gettext_noop ("# disconnects due to NO pong"), 2473 gettext_noop ("# disconnects due to NO pong"), 1,
2503 1, GNUNET_NO); 2474 GNUNET_NO);
2504 disconnect_neighbour (nl, GNUNET_YES); 2475 disconnect_neighbour (nl, GNUNET_YES);
2505 return; /* nothing to do, never connected... */ 2476 return; /* nothing to do, never connected... */
2506 } 2477 }
@@ -2522,8 +2493,7 @@ plugin_env_session_end (void *cls,
2522 /* no valid addresses left, signal disconnect! */ 2493 /* no valid addresses left, signal disconnect! */
2523 2494
2524#if DEBUG_TRANSPORT 2495#if DEBUG_TRANSPORT
2525 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2496 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s', %s\n",
2526 "Disconnecting peer `%4s', %s\n",
2527 GNUNET_i2s (peer), "plugin_env_session_end"); 2497 GNUNET_i2s (peer), "plugin_env_session_end");
2528#endif 2498#endif
2529 /* FIXME: This doesn't mean there are no addresses left for this PEER, 2499 /* FIXME: This doesn't mean there are no addresses left for this PEER,
@@ -2553,8 +2523,8 @@ plugin_env_session_end (void *cls,
2553 * @param addrlen length of the address 2523 * @param addrlen length of the address
2554 */ 2524 */
2555static void 2525static void
2556plugin_env_notify_address (void *cls, 2526plugin_env_notify_address (void *cls, int add_remove, const void *addr,
2557 int add_remove, const void *addr, size_t addrlen) 2527 size_t addrlen)
2558{ 2528{
2559 struct TransportPlugin *p = cls; 2529 struct TransportPlugin *p = cls;
2560 struct OwnAddressList *al; 2530 struct OwnAddressList *al;
@@ -2563,9 +2533,9 @@ plugin_env_notify_address (void *cls,
2563 GNUNET_assert (p->api != NULL); 2533 GNUNET_assert (p->api != NULL);
2564#if DEBUG_TRANSPORT 2534#if DEBUG_TRANSPORT
2565 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2535 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2566 (add_remove == GNUNET_YES) 2536 (add_remove ==
2567 ? "Adding `%s':%s to the set of our addresses\n" 2537 GNUNET_YES) ? "Adding `%s':%s to the set of our addresses\n" :
2568 : "Removing `%s':%s from the set of our addresses\n", 2538 "Removing `%s':%s from the set of our addresses\n",
2569 a2s (p->short_name, addr, addrlen), p->short_name); 2539 a2s (p->short_name, addr, addrlen), p->short_name);
2570#endif 2540#endif
2571 GNUNET_assert (addr != NULL); 2541 GNUNET_assert (addr != NULL);
@@ -2622,8 +2592,8 @@ notify_clients_connect (const struct GNUNET_PeerIdentity *peer,
2622 "Notifying clients about connection with `%s'\n", 2592 "Notifying clients about connection with `%s'\n",
2623 GNUNET_i2s (peer)); 2593 GNUNET_i2s (peer));
2624#endif 2594#endif
2625 GNUNET_STATISTICS_update (stats, 2595 GNUNET_STATISTICS_update (stats, gettext_noop ("# peers connected"), 1,
2626 gettext_noop ("# peers connected"), 1, GNUNET_NO); 2596 GNUNET_NO);
2627 2597
2628 ats_count = 2; 2598 ats_count = 2;
2629 size = 2599 size =
@@ -2679,8 +2649,8 @@ notify_clients_disconnect (const struct GNUNET_PeerIdentity *peer)
2679 "Notifying clients about lost connection to `%s'\n", 2649 "Notifying clients about lost connection to `%s'\n",
2680 GNUNET_i2s (peer)); 2650 GNUNET_i2s (peer));
2681#endif 2651#endif
2682 GNUNET_STATISTICS_update (stats, 2652 GNUNET_STATISTICS_update (stats, gettext_noop ("# peers connected"), -1,
2683 gettext_noop ("# peers connected"), -1, GNUNET_NO); 2653 GNUNET_NO);
2684 dim.header.size = htons (sizeof (struct DisconnectInfoMessage)); 2654 dim.header.size = htons (sizeof (struct DisconnectInfoMessage));
2685 dim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); 2655 dim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
2686 dim.reserved = htonl (0); 2656 dim.reserved = htonl (0);
@@ -2718,8 +2688,7 @@ notify_clients_disconnect (const struct GNUNET_PeerIdentity *peer)
2718 * @return NULL if no such entry exists 2688 * @return NULL if no such entry exists
2719 */ 2689 */
2720static struct ForeignAddressList * 2690static struct ForeignAddressList *
2721find_peer_address (struct NeighbourMapEntry *neighbour, 2691find_peer_address (struct NeighbourMapEntry *neighbour, const char *tname,
2722 const char *tname,
2723 struct Session *session, const char *addr, uint16_t addrlen) 2692 struct Session *session, const char *addr, uint16_t addrlen)
2724{ 2693{
2725 struct ReadyList *head; 2694 struct ReadyList *head;
@@ -2761,8 +2730,7 @@ find_peer_address (struct NeighbourMapEntry *neighbour,
2761 * @return NULL if we do not have a transport plugin for 'tname' 2730 * @return NULL if we do not have a transport plugin for 'tname'
2762 */ 2731 */
2763static struct ForeignAddressList * 2732static struct ForeignAddressList *
2764add_peer_address (struct NeighbourMapEntry *neighbour, 2733add_peer_address (struct NeighbourMapEntry *neighbour, const char *tname,
2765 const char *tname,
2766 struct Session *session, const char *addr, uint16_t addrlen) 2734 struct Session *session, const char *addr, uint16_t addrlen)
2767{ 2735{
2768 struct ReadyList *head; 2736 struct ReadyList *head;
@@ -2841,11 +2809,13 @@ add_peer_address (struct NeighbourMapEntry *neighbour,
2841 GNUNET_malloc (available_quality_metrics * 2809 GNUNET_malloc (available_quality_metrics *
2842 sizeof (struct ATS_quality_entry)); 2810 sizeof (struct ATS_quality_entry));
2843 ret->addrlen = addrlen; 2811 ret->addrlen = addrlen;
2844 ret->expires = GNUNET_TIME_relative_to_absolute 2812 ret->expires =
2813 GNUNET_TIME_relative_to_absolute
2845 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 2814 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
2846 ret->latency = GNUNET_TIME_relative_get_forever (); 2815 ret->latency = GNUNET_TIME_relative_get_forever ();
2847 ret->distance = -1; 2816 ret->distance = -1;
2848 ret->timeout = GNUNET_TIME_relative_to_absolute 2817 ret->timeout =
2818 GNUNET_TIME_relative_to_absolute
2849 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 2819 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
2850 ret->ready_list = head; 2820 ret->ready_list = head;
2851 ret->next = head->addresses; 2821 ret->next = head->addresses;
@@ -2950,8 +2920,7 @@ check_address_exists (void *cls, const GNUNET_HashCode * key, void *value)
2950 struct CheckAddressExistsClosure *caec = cls; 2920 struct CheckAddressExistsClosure *caec = cls;
2951 struct ValidationEntry *ve = value; 2921 struct ValidationEntry *ve = value;
2952 2922
2953 if ((0 == strcmp (caec->tname, 2923 if ((0 == strcmp (caec->tname, ve->transport_name)) &&
2954 ve->transport_name)) &&
2955 (caec->addrlen == ve->addrlen) && 2924 (caec->addrlen == ve->addrlen) &&
2956 (0 == memcmp (caec->addr, ve->addr, caec->addrlen))) 2925 (0 == memcmp (caec->addr, ve->addr, caec->addrlen)))
2957 { 2926 {
@@ -2978,8 +2947,8 @@ neighbour_timeout_task (void *cls,
2978 "Neighbour `%4s' has timed out!\n", GNUNET_i2s (&n->id)); 2947 "Neighbour `%4s' has timed out!\n", GNUNET_i2s (&n->id));
2979#endif 2948#endif
2980 GNUNET_STATISTICS_update (stats, 2949 GNUNET_STATISTICS_update (stats,
2981 gettext_noop ("# disconnects due to timeout"), 2950 gettext_noop ("# disconnects due to timeout"), 1,
2982 1, GNUNET_NO); 2951 GNUNET_NO);
2983 n->timeout_task = GNUNET_SCHEDULER_NO_TASK; 2952 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2984 disconnect_neighbour (n, GNUNET_NO); 2953 disconnect_neighbour (n, GNUNET_NO);
2985} 2954}
@@ -3006,8 +2975,7 @@ static void schedule_next_ping (struct ForeignAddressList *fal);
3006 * @return GNUNET_OK (always) 2975 * @return GNUNET_OK (always)
3007 */ 2976 */
3008static int 2977static int
3009add_to_foreign_address_list (void *cls, 2978add_to_foreign_address_list (void *cls, const char *tname,
3010 const char *tname,
3011 struct GNUNET_TIME_Absolute expiration, 2979 struct GNUNET_TIME_Absolute expiration,
3012 const void *addr, uint16_t addrlen) 2980 const void *addr, uint16_t addrlen)
3013{ 2981{
@@ -3026,8 +2994,8 @@ add_to_foreign_address_list (void *cls,
3026#if DEBUG_TRANSPORT_HELLO 2994#if DEBUG_TRANSPORT_HELLO
3027 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2995 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3028 "Adding address `%s' (%s) for peer `%4s' due to PEERINFO data for %llums.\n", 2996 "Adding address `%s' (%s) for peer `%4s' due to PEERINFO data for %llums.\n",
3029 a2s (tname, addr, addrlen), 2997 a2s (tname, addr, addrlen), tname, GNUNET_i2s (&n->id),
3030 tname, GNUNET_i2s (&n->id), expiration.abs_value); 2998 expiration.abs_value);
3031#endif 2999#endif
3032 fal = add_peer_address (n, tname, NULL, addr, addrlen); 3000 fal = add_peer_address (n, tname, NULL, addr, addrlen);
3033 if (fal == NULL) 3001 if (fal == NULL)
@@ -3086,8 +3054,7 @@ add_to_foreign_address_list (void *cls,
3086 * @param err_msg NULL if successful, otherwise contains error message 3054 * @param err_msg NULL if successful, otherwise contains error message
3087 */ 3055 */
3088static void 3056static void
3089add_hello_for_peer (void *cls, 3057add_hello_for_peer (void *cls, const struct GNUNET_PeerIdentity *peer,
3090 const struct GNUNET_PeerIdentity *peer,
3091 const struct GNUNET_HELLO_Message *h, const char *err_msg) 3058 const struct GNUNET_HELLO_Message *h, const char *err_msg)
3092{ 3059{
3093 struct NeighbourMapEntry *n = cls; 3060 struct NeighbourMapEntry *n = cls;
@@ -3122,8 +3089,8 @@ add_hello_for_peer (void *cls,
3122 GNUNET_HELLO_get_key (h, &n->publicKey); 3089 GNUNET_HELLO_get_key (h, &n->publicKey);
3123 n->public_key_valid = GNUNET_YES; 3090 n->public_key_valid = GNUNET_YES;
3124 } 3091 }
3125 GNUNET_HELLO_iterate_addresses (h, 3092 GNUNET_HELLO_iterate_addresses (h, GNUNET_NO, &add_to_foreign_address_list,
3126 GNUNET_NO, &add_to_foreign_address_list, n); 3093 n);
3127} 3094}
3128 3095
3129 3096
@@ -3143,15 +3110,15 @@ setup_new_neighbour (const struct GNUNET_PeerIdentity *peer, int do_hello)
3143 struct TransportPlugin *tp; 3110 struct TransportPlugin *tp;
3144 struct ReadyList *rl; 3111 struct ReadyList *rl;
3145 3112
3146 GNUNET_assert (0 != memcmp (peer, 3113 GNUNET_assert (0 !=
3147 &my_identity, 3114 memcmp (peer, &my_identity,
3148 sizeof (struct GNUNET_PeerIdentity))); 3115 sizeof (struct GNUNET_PeerIdentity)));
3149#if DEBUG_TRANSPORT 3116#if DEBUG_TRANSPORT
3150 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3117 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up state for neighbour `%4s'\n",
3151 "Setting up state for neighbour `%4s'\n", GNUNET_i2s (peer)); 3118 GNUNET_i2s (peer));
3152#endif 3119#endif
3153 GNUNET_STATISTICS_update (stats, 3120 GNUNET_STATISTICS_update (stats, gettext_noop ("# active neighbours"), 1,
3154 gettext_noop ("# active neighbours"), 1, GNUNET_NO); 3121 GNUNET_NO);
3155 n = GNUNET_malloc (sizeof (struct NeighbourMapEntry)); 3122 n = GNUNET_malloc (sizeof (struct NeighbourMapEntry));
3156 n->id = *peer; 3123 n->id = *peer;
3157 n->peer_timeout = 3124 n->peer_timeout =
@@ -3199,8 +3166,7 @@ setup_new_neighbour (const struct GNUNET_PeerIdentity *peer, int do_hello)
3199 gettext_noop ("# HELLO's sent to new neighbors"), 3166 gettext_noop ("# HELLO's sent to new neighbors"),
3200 1, GNUNET_NO); 3167 1, GNUNET_NO);
3201 if (NULL != our_hello) 3168 if (NULL != our_hello)
3202 transmit_to_peer (NULL, NULL, 0, 3169 transmit_to_peer (NULL, NULL, 0, HELLO_ADDRESS_EXPIRATION,
3203 HELLO_ADDRESS_EXPIRATION,
3204 (const char *) our_hello, GNUNET_HELLO_size (our_hello), 3170 (const char *) our_hello, GNUNET_HELLO_size (our_hello),
3205 GNUNET_NO, n); 3171 GNUNET_NO, n);
3206 } 3172 }
@@ -3329,8 +3295,8 @@ static struct BlacklistCheck *bc_tail;
3329 * @param cls the 'struct BlacklistCheck*' 3295 * @param cls the 'struct BlacklistCheck*'
3330 * @param tc unused 3296 * @param tc unused
3331 */ 3297 */
3332static void 3298static void do_blacklist_check (void *cls,
3333do_blacklist_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 3299 const struct GNUNET_SCHEDULER_TaskContext *tc);
3334 3300
3335/** 3301/**
3336 * Transmit blacklist query to the client. 3302 * Transmit blacklist query to the client.
@@ -3401,12 +3367,11 @@ do_blacklist_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3401 if (bl->bc == NULL) 3367 if (bl->bc == NULL)
3402 { 3368 {
3403 bl->bc = bc; 3369 bl->bc = bc;
3404 bc->th = GNUNET_SERVER_notify_transmit_ready (bl->client, 3370 bc->th =
3405 sizeof (struct 3371 GNUNET_SERVER_notify_transmit_ready (bl->client,
3406 BlacklistMessage), 3372 sizeof (struct BlacklistMessage),
3407 GNUNET_TIME_UNIT_FOREVER_REL, 3373 GNUNET_TIME_UNIT_FOREVER_REL,
3408 &transmit_blacklist_message, 3374 &transmit_blacklist_message, bc);
3409 bc);
3410 } 3375 }
3411} 3376}
3412 3377
@@ -3425,8 +3390,8 @@ do_blacklist_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3425 */ 3390 */
3426static void 3391static void
3427setup_peer_check_blacklist (const struct GNUNET_PeerIdentity *peer, 3392setup_peer_check_blacklist (const struct GNUNET_PeerIdentity *peer,
3428 int do_hello, 3393 int do_hello, SetupContinuation cont,
3429 SetupContinuation cont, void *cont_cls) 3394 void *cont_cls)
3430{ 3395{
3431 struct NeighbourMapEntry *n; 3396 struct NeighbourMapEntry *n;
3432 struct BlacklistCheck *bc; 3397 struct BlacklistCheck *bc;
@@ -3476,9 +3441,8 @@ confirm_or_drop_neighbour (void *cls, struct NeighbourMapEntry *n)
3476 if (n == NULL) 3441 if (n == NULL)
3477 { 3442 {
3478#if DEBUG_TRANSPORT 3443#if DEBUG_TRANSPORT
3479 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3444 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s', %s\n",
3480 "Disconnecting peer `%4s', %s\n", GNUNET_i2s (&orig->id), 3445 GNUNET_i2s (&orig->id), "confirm_or_drop_neighboUr");
3481 "confirm_or_drop_neighboUr");
3482#endif 3446#endif
3483 GNUNET_STATISTICS_update (stats, 3447 GNUNET_STATISTICS_update (stats,
3484 gettext_noop ("# disconnects due to blacklist"), 3448 gettext_noop ("# disconnects due to blacklist"),
@@ -3530,8 +3494,7 @@ test_connection_ok (void *cls, const GNUNET_HashCode * key, void *value)
3530 * @param message the actual message 3494 * @param message the actual message
3531 */ 3495 */
3532static void 3496static void
3533handle_blacklist_init (void *cls, 3497handle_blacklist_init (void *cls, struct GNUNET_SERVER_Client *client,
3534 struct GNUNET_SERVER_Client *client,
3535 const struct GNUNET_MessageHeader *message) 3498 const struct GNUNET_MessageHeader *message)
3536{ 3499{
3537 struct Blacklisters *bl; 3500 struct Blacklisters *bl;
@@ -3567,8 +3530,7 @@ handle_blacklist_init (void *cls,
3567 * @param message the actual message 3530 * @param message the actual message
3568 */ 3531 */
3569static void 3532static void
3570handle_blacklist_reply (void *cls, 3533handle_blacklist_reply (void *cls, struct GNUNET_SERVER_Client *client,
3571 struct GNUNET_SERVER_Client *client,
3572 const struct GNUNET_MessageHeader *message) 3534 const struct GNUNET_MessageHeader *message)
3573{ 3535{
3574 const struct BlacklistMessage *msg = 3536 const struct BlacklistMessage *msg =
@@ -3658,8 +3620,8 @@ send_periodic_ping (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3658 caec.session = peer_address->session; 3620 caec.session = peer_address->session;
3659 caec.exists = GNUNET_NO; 3621 caec.exists = GNUNET_NO;
3660 3622
3661 GNUNET_CONTAINER_multihashmap_iterate (validation_map, 3623 GNUNET_CONTAINER_multihashmap_iterate (validation_map, &check_address_exists,
3662 &check_address_exists, &caec); 3624 &caec);
3663 if (caec.exists == GNUNET_YES) 3625 if (caec.exists == GNUNET_YES)
3664 { 3626 {
3665 /* During validation attempts we will likely trigger the other 3627 /* During validation attempts we will likely trigger the other
@@ -3669,19 +3631,19 @@ send_periodic_ping (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3669#if DEBUG_TRANSPORT > 1 3631#if DEBUG_TRANSPORT > 1
3670 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3632 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3671 "Some validation of address `%s' via `%s' for peer `%4s' already in progress.\n", 3633 "Some validation of address `%s' via `%s' for peer `%4s' already in progress.\n",
3672 (peer_address->addr != NULL) 3634 (peer_address->addr != NULL) ? a2s (tp->short_name,
3673 ? a2s (tp->short_name, 3635 peer_address->addr,
3674 peer_address->addr, 3636 peer_address->
3675 peer_address->addrlen) 3637 addrlen) : "<inbound>",
3676 : "<inbound>", tp->short_name, GNUNET_i2s (&neighbour->id)); 3638 tp->short_name, GNUNET_i2s (&neighbour->id));
3677#endif 3639#endif
3678 schedule_next_ping (peer_address); 3640 schedule_next_ping (peer_address);
3679 return; 3641 return;
3680 } 3642 }
3681 va = GNUNET_malloc (sizeof (struct ValidationEntry) + peer_address->addrlen); 3643 va = GNUNET_malloc (sizeof (struct ValidationEntry) + peer_address->addrlen);
3682 va->transport_name = GNUNET_strdup (tp->short_name); 3644 va->transport_name = GNUNET_strdup (tp->short_name);
3683 va->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 3645 va->challenge =
3684 UINT_MAX); 3646 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT_MAX);
3685 va->send_time = GNUNET_TIME_absolute_get (); 3647 va->send_time = GNUNET_TIME_absolute_get ();
3686 va->session = peer_address->session; 3648 va->session = peer_address->session;
3687 if (peer_address->addr != NULL) 3649 if (peer_address->addr != NULL)
@@ -3690,15 +3652,13 @@ send_periodic_ping (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3690 memcpy (&va[1], peer_address->addr, peer_address->addrlen); 3652 memcpy (&va[1], peer_address->addr, peer_address->addrlen);
3691 va->addrlen = peer_address->addrlen; 3653 va->addrlen = peer_address->addrlen;
3692 } 3654 }
3693 memcpy (&va->publicKey, 3655 memcpy (&va->publicKey, &neighbour->publicKey,
3694 &neighbour->publicKey,
3695 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 3656 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
3696 3657
3697 va->timeout_task = GNUNET_SCHEDULER_add_delayed (HELLO_VERIFICATION_TIMEOUT, 3658 va->timeout_task =
3698 &timeout_hello_validation, 3659 GNUNET_SCHEDULER_add_delayed (HELLO_VERIFICATION_TIMEOUT,
3699 va); 3660 &timeout_hello_validation, va);
3700 GNUNET_CONTAINER_multihashmap_put (validation_map, 3661 GNUNET_CONTAINER_multihashmap_put (validation_map, &neighbour->id.hashPubKey,
3701 &neighbour->id.hashPubKey,
3702 va, 3662 va,
3703 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 3663 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
3704 3664
@@ -3729,8 +3689,9 @@ send_periodic_ping (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3729 3689
3730 if (peer_address->addr != NULL) 3690 if (peer_address->addr != NULL)
3731 { 3691 {
3732 ping.header.size = htons (sizeof (struct TransportPingMessage) + 3692 ping.header.size =
3733 peer_address->addrlen + slen); 3693 htons (sizeof (struct TransportPingMessage) + peer_address->addrlen +
3694 slen);
3734 memcpy (&message_buf[hello_size + sizeof (struct TransportPingMessage)], 3695 memcpy (&message_buf[hello_size + sizeof (struct TransportPingMessage)],
3735 tp->short_name, slen); 3696 tp->short_name, slen);
3736 memcpy (&message_buf 3697 memcpy (&message_buf
@@ -3742,19 +3703,18 @@ send_periodic_ping (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3742 ping.header.size = htons (sizeof (struct TransportPingMessage)); 3703 ping.header.size = htons (sizeof (struct TransportPingMessage));
3743 } 3704 }
3744 3705
3745 memcpy (&message_buf[hello_size], 3706 memcpy (&message_buf[hello_size], &ping,
3746 &ping, sizeof (struct TransportPingMessage)); 3707 sizeof (struct TransportPingMessage));
3747 3708
3748#if DEBUG_TRANSPORT_REVALIDATION 3709#if DEBUG_TRANSPORT_REVALIDATION
3749 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3710 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3750 "Performing re-validation of address `%s' via `%s' for peer `%4s' sending `%s' (%u bytes) and `%s'\n", 3711 "Performing re-validation of address `%s' via `%s' for peer `%4s' sending `%s' (%u bytes) and `%s'\n",
3751 (peer_address->addr != NULL) 3712 (peer_address->addr !=
3752 ? a2s (peer_address->plugin->short_name, 3713 NULL) ? a2s (peer_address->plugin->short_name,
3753 peer_address->addr, 3714 peer_address->addr,
3754 peer_address->addrlen) 3715 peer_address->addrlen) : "<inbound>",
3755 : "<inbound>", 3716 tp->short_name, GNUNET_i2s (&neighbour->id), "HELLO", hello_size,
3756 tp->short_name, 3717 "PING");
3757 GNUNET_i2s (&neighbour->id), "HELLO", hello_size, "PING");
3758#endif 3718#endif
3759 if (peer_address->validated != GNUNET_YES) 3719 if (peer_address->validated != GNUNET_YES)
3760 GNUNET_STATISTICS_update (stats, 3720 GNUNET_STATISTICS_update (stats,
@@ -3804,8 +3764,9 @@ schedule_next_ping (struct ForeignAddressList *fal)
3804 3764
3805 if (GNUNET_YES == fal->connected) 3765 if (GNUNET_YES == fal->connected)
3806 { 3766 {
3807 delay = GNUNET_TIME_relative_min (delay, 3767 delay =
3808 CONNECTED_LATENCY_EVALUATION_MAX_DELAY); 3768 GNUNET_TIME_relative_min (delay,
3769 CONNECTED_LATENCY_EVALUATION_MAX_DELAY);
3809 } 3770 }
3810 /* FIXME: also adjust delay based on how close the last 3771 /* FIXME: also adjust delay based on how close the last
3811 * observed latency is to the latency of the best alternative */ 3772 * observed latency is to the latency of the best alternative */
@@ -3816,9 +3777,8 @@ schedule_next_ping (struct ForeignAddressList *fal)
3816 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000); 3777 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000);
3817 3778
3818 GNUNET_assert (fal->revalidate_task == GNUNET_SCHEDULER_NO_TASK); 3779 GNUNET_assert (fal->revalidate_task == GNUNET_SCHEDULER_NO_TASK);
3819 fal->revalidate_task = GNUNET_SCHEDULER_add_delayed (delay, 3780 fal->revalidate_task =
3820 &send_periodic_ping, 3781 GNUNET_SCHEDULER_add_delayed (delay, &send_periodic_ping, fal);
3821 fal);
3822} 3782}
3823 3783
3824 3784
@@ -3845,8 +3805,8 @@ handle_payload_message (const struct GNUNET_MessageHeader *message,
3845#if DEBUG_TRANSPORT 3805#if DEBUG_TRANSPORT
3846 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3806 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3847 "Received message of type %u and size %u from `%4s', but no pong yet!\n", 3807 "Received message of type %u and size %u from `%4s', but no pong yet!\n",
3848 ntohs (message->type), 3808 ntohs (message->type), ntohs (message->size),
3849 ntohs (message->size), GNUNET_i2s (&n->id)); 3809 GNUNET_i2s (&n->id));
3850#endif 3810#endif
3851 GNUNET_free_non_null (n->pre_connect_message_buffer); 3811 GNUNET_free_non_null (n->pre_connect_message_buffer);
3852 n->pre_connect_message_buffer = GNUNET_malloc (msize); 3812 n->pre_connect_message_buffer = GNUNET_malloc (msize);
@@ -3857,11 +3817,11 @@ handle_payload_message (const struct GNUNET_MessageHeader *message,
3857#if DEBUG_TRANSPORT 3817#if DEBUG_TRANSPORT
3858 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3818 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3859 "Received message of type %u and size %u from `%4s', sending to all clients.\n", 3819 "Received message of type %u and size %u from `%4s', sending to all clients.\n",
3860 ntohs (message->type), 3820 ntohs (message->type), ntohs (message->size),
3861 ntohs (message->size), GNUNET_i2s (&n->id)); 3821 GNUNET_i2s (&n->id));
3862#endif 3822#endif
3863 if (GNUNET_YES == GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, 3823 if (GNUNET_YES ==
3864 (ssize_t) msize)) 3824 GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, (ssize_t) msize))
3865 { 3825 {
3866 n->quota_violation_count++; 3826 n->quota_violation_count++;
3867#if DEBUG_TRANSPORT 3827#if DEBUG_TRANSPORT
@@ -3956,12 +3916,10 @@ check_pending_validation (void *cls, const GNUNET_HashCode * key, void *value)
3956 addr = (const char *) &pong[1]; 3916 addr = (const char *) &pong[1];
3957 slen = strlen (ve->transport_name) + 1; 3917 slen = strlen (ve->transport_name) + 1;
3958 if ((ps - sizeof (struct TransportPongMessage) < slen) || 3918 if ((ps - sizeof (struct TransportPongMessage) < slen) ||
3959 (ve->challenge != challenge) || 3919 (ve->challenge != challenge) || (addr[slen - 1] != '\0') ||
3960 (addr[slen - 1] != '\0') ||
3961 (0 != strcmp (addr, ve->transport_name)) || 3920 (0 != strcmp (addr, ve->transport_name)) ||
3962 (ntohl (pong->purpose.size) 3921 (ntohl (pong->purpose.size) !=
3963 != sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + 3922 sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + sizeof (uint32_t) +
3964 sizeof (uint32_t) +
3965 sizeof (struct GNUNET_TIME_AbsoluteNBO) + 3923 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
3966 sizeof (struct GNUNET_PeerIdentity) + ps - 3924 sizeof (struct GNUNET_PeerIdentity) + ps -
3967 sizeof (struct TransportPongMessage))) 3925 sizeof (struct TransportPongMessage)))
@@ -3985,8 +3943,8 @@ check_pending_validation (void *cls, const GNUNET_HashCode * key, void *value)
3985 } 3943 }
3986 if (GNUNET_OK != 3944 if (GNUNET_OK !=
3987 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, 3945 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
3988 &pong->purpose, 3946 &pong->purpose, &pong->signature,
3989 &pong->signature, &ve->publicKey)) 3947 &ve->publicKey))
3990 { 3948 {
3991 GNUNET_break_op (0); 3949 GNUNET_break_op (0);
3992 return GNUNET_NO; 3950 return GNUNET_NO;
@@ -3995,15 +3953,14 @@ check_pending_validation (void *cls, const GNUNET_HashCode * key, void *value)
3995#if DEBUG_TRANSPORT 3953#if DEBUG_TRANSPORT
3996 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3954 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3997 "Confirmed validity of address, peer `%4s' has address `%s' (%s).\n", 3955 "Confirmed validity of address, peer `%4s' has address `%s' (%s).\n",
3998 GNUNET_h2s (key), 3956 GNUNET_h2s (key), a2s (ve->transport_name,
3999 a2s (ve->transport_name, 3957 (const struct sockaddr *) ve->addr,
4000 (const struct sockaddr *) ve->addr, 3958 ve->addrlen), ve->transport_name);
4001 ve->addrlen), ve->transport_name);
4002#endif 3959#endif
4003 break; 3960 break;
4004 case GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING: 3961 case GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING:
4005 if (0 != memcmp (&pong->pid, 3962 if (0 !=
4006 &my_identity, sizeof (struct GNUNET_PeerIdentity))) 3963 memcmp (&pong->pid, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
4007 { 3964 {
4008 char *peer; 3965 char *peer;
4009 3966
@@ -4050,8 +4007,8 @@ check_pending_validation (void *cls, const GNUNET_HashCode * key, void *value)
4050 } 4007 }
4051 if (GNUNET_OK != 4008 if (GNUNET_OK !=
4052 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING, 4009 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING,
4053 &pong->purpose, 4010 &pong->purpose, &pong->signature,
4054 &pong->signature, &ve->publicKey)) 4011 &ve->publicKey))
4055 { 4012 {
4056 GNUNET_break_op (0); 4013 GNUNET_break_op (0);
4057 return GNUNET_NO; 4014 return GNUNET_NO;
@@ -4060,9 +4017,8 @@ check_pending_validation (void *cls, const GNUNET_HashCode * key, void *value)
4060#if DEBUG_TRANSPORT 4017#if DEBUG_TRANSPORT
4061 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4018 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4062 "Confirmed that peer `%4s' is talking to us using address `%s' (%s) for us.\n", 4019 "Confirmed that peer `%4s' is talking to us using address `%s' (%s) for us.\n",
4063 GNUNET_h2s (key), 4020 GNUNET_h2s (key), a2s (ve->transport_name, &addr[slen], alen),
4064 a2s (ve->transport_name, 4021 ve->transport_name);
4065 &addr[slen], alen), ve->transport_name);
4066#endif 4022#endif
4067 break; 4023 break;
4068 default: 4024 default:
@@ -4077,8 +4033,8 @@ check_pending_validation (void *cls, const GNUNET_HashCode * key, void *value)
4077 return GNUNET_NO; 4033 return GNUNET_NO;
4078 } 4034 }
4079 GNUNET_STATISTICS_update (stats, 4035 GNUNET_STATISTICS_update (stats,
4080 gettext_noop ("# address validation successes"), 4036 gettext_noop ("# address validation successes"), 1,
4081 1, GNUNET_NO); 4037 GNUNET_NO);
4082 /* create the updated HELLO */ 4038 /* create the updated HELLO */
4083 GNUNET_CRYPTO_hash (&ve->publicKey, 4039 GNUNET_CRYPTO_hash (&ve->publicKey,
4084 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 4040 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
@@ -4096,9 +4052,9 @@ check_pending_validation (void *cls, const GNUNET_HashCode * key, void *value)
4096 { 4052 {
4097 n->publicKey = ve->publicKey; 4053 n->publicKey = ve->publicKey;
4098 n->public_key_valid = GNUNET_YES; 4054 n->public_key_valid = GNUNET_YES;
4099 fal = add_peer_address (n, 4055 fal =
4100 ve->transport_name, 4056 add_peer_address (n, ve->transport_name, ve->session, ve->addr,
4101 ve->session, ve->addr, ve->addrlen); 4057 ve->addrlen);
4102 GNUNET_assert (fal != NULL); 4058 GNUNET_assert (fal != NULL);
4103 fal->expires = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION); 4059 fal->expires = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION);
4104 fal->validated = GNUNET_YES; 4060 fal->validated = GNUNET_YES;
@@ -4109,9 +4065,8 @@ check_pending_validation (void *cls, const GNUNET_HashCode * key, void *value)
4109 GNUNET_NO); 4065 GNUNET_NO);
4110 fal->latency = GNUNET_TIME_absolute_get_duration (ve->send_time); 4066 fal->latency = GNUNET_TIME_absolute_get_duration (ve->send_time);
4111 update_addr_value (fal, 4067 update_addr_value (fal,
4112 GNUNET_TIME_absolute_get_duration (ve-> 4068 GNUNET_TIME_absolute_get_duration (ve->send_time).
4113 send_time).rel_value, 4069 rel_value, GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
4114 GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
4115 4070
4116 schedule_next_ping (fal); 4071 schedule_next_ping (fal);
4117 if (n->latency.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value) 4072 if (n->latency.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
@@ -4142,8 +4097,8 @@ check_pending_validation (void *cls, const GNUNET_HashCode * key, void *value)
4142 4097
4143 /* clean up validation entry */ 4098 /* clean up validation entry */
4144 GNUNET_assert (GNUNET_YES == 4099 GNUNET_assert (GNUNET_YES ==
4145 GNUNET_CONTAINER_multihashmap_remove (validation_map, 4100 GNUNET_CONTAINER_multihashmap_remove (validation_map, key,
4146 key, ve)); 4101 ve));
4147 abort_validation (NULL, NULL, ve); 4102 abort_validation (NULL, NULL, ve);
4148 return GNUNET_NO; 4103 return GNUNET_NO;
4149} 4104}
@@ -4166,26 +4121,24 @@ check_pending_validation (void *cls, const GNUNET_HashCode * key, void *value)
4166 */ 4121 */
4167static void 4122static void
4168handle_pong (void *cls, const struct GNUNET_MessageHeader *message, 4123handle_pong (void *cls, const struct GNUNET_MessageHeader *message,
4169 const struct GNUNET_PeerIdentity *peer, 4124 const struct GNUNET_PeerIdentity *peer, const char *sender_address,
4170 const char *sender_address, size_t sender_address_len) 4125 size_t sender_address_len)
4171{ 4126{
4172 if (0 == memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity))) 4127 if (0 == memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
4173 { 4128 {
4174 /* PONG send to self, ignore */ 4129 /* PONG send to self, ignore */
4175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4130 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving `%s' message from myself\n",
4176 "Receiving `%s' message from myself\n", "PONG"); 4131 "PONG");
4177 return; 4132 return;
4178 } 4133 }
4179#if DEBUG_TRANSPORT > 1 4134#if DEBUG_TRANSPORT > 1
4180 /* we get tons of these that just get discarded, only log 4135 /* we get tons of these that just get discarded, only log
4181 * if we are quite verbose */ 4136 * if we are quite verbose */
4182 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4137 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving `%s' message from `%4s'.\n",
4183 "Receiving `%s' message from `%4s'.\n", "PONG", 4138 "PONG", GNUNET_i2s (peer));
4184 GNUNET_i2s (peer));
4185#endif 4139#endif
4186 GNUNET_STATISTICS_update (stats, 4140 GNUNET_STATISTICS_update (stats, gettext_noop ("# PONG messages received"), 1,
4187 gettext_noop ("# PONG messages received"), 4141 GNUNET_NO);
4188 1, GNUNET_NO);
4189 if (GNUNET_SYSERR != 4142 if (GNUNET_SYSERR !=
4190 GNUNET_CONTAINER_multihashmap_get_multiple (validation_map, 4143 GNUNET_CONTAINER_multihashmap_get_multiple (validation_map,
4191 &peer->hashPubKey, 4144 &peer->hashPubKey,
@@ -4241,9 +4194,9 @@ transmit_hello_and_ping (void *cls, struct NeighbourMapEntry *neighbour)
4241 } 4194 }
4242 neighbour->publicKey = va->publicKey; 4195 neighbour->publicKey = va->publicKey;
4243 neighbour->public_key_valid = GNUNET_YES; 4196 neighbour->public_key_valid = GNUNET_YES;
4244 peer_address = add_peer_address (neighbour, 4197 peer_address =
4245 va->transport_name, NULL, 4198 add_peer_address (neighbour, va->transport_name, NULL,
4246 (const void *) &va[1], va->addrlen); 4199 (const void *) &va[1], va->addrlen);
4247 if (peer_address == NULL) 4200 if (peer_address == NULL)
4248 { 4201 {
4249 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 4202 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -4268,8 +4221,8 @@ transmit_hello_and_ping (void *cls, struct NeighbourMapEntry *neighbour)
4268 ping.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PING); 4221 ping.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
4269 memcpy (&ping.target, &neighbour->id, sizeof (struct GNUNET_PeerIdentity)); 4222 memcpy (&ping.target, &neighbour->id, sizeof (struct GNUNET_PeerIdentity));
4270 memcpy (message_buf, our_hello, hello_size); 4223 memcpy (message_buf, our_hello, hello_size);
4271 memcpy (&message_buf[hello_size], 4224 memcpy (&message_buf[hello_size], &ping,
4272 &ping, sizeof (struct TransportPingMessage)); 4225 sizeof (struct TransportPingMessage));
4273 memcpy (&message_buf[hello_size + sizeof (struct TransportPingMessage)], 4226 memcpy (&message_buf[hello_size + sizeof (struct TransportPingMessage)],
4274 va->transport_name, slen); 4227 va->transport_name, slen);
4275 memcpy (&message_buf 4228 memcpy (&message_buf
@@ -4278,14 +4231,11 @@ transmit_hello_and_ping (void *cls, struct NeighbourMapEntry *neighbour)
4278#if DEBUG_TRANSPORT 4231#if DEBUG_TRANSPORT
4279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4280 "Performing validation of address `%s' via `%s' for peer `%4s' sending `%s' (%u bytes) and `%s' (%u bytes)\n", 4233 "Performing validation of address `%s' via `%s' for peer `%4s' sending `%s' (%u bytes) and `%s' (%u bytes)\n",
4281 (va->addrlen == 0) 4234 (va->addrlen == 0) ? "<inbound>" : a2s (va->transport_name,
4282 ? "<inbound>" 4235 (const void *) &va[1],
4283 : a2s (va->transport_name, 4236 va->addrlen),
4284 (const void *) &va[1], va->addrlen), 4237 va->transport_name, GNUNET_i2s (&neighbour->id), "HELLO",
4285 va->transport_name, 4238 hello_size, "PING",
4286 GNUNET_i2s (&neighbour->id),
4287 "HELLO", hello_size,
4288 "PING",
4289 sizeof (struct TransportPingMessage) + va->addrlen + slen); 4239 sizeof (struct TransportPingMessage) + va->addrlen + slen);
4290#endif 4240#endif
4291 4241
@@ -4313,10 +4263,9 @@ transmit_hello_and_ping (void *cls, struct NeighbourMapEntry *neighbour)
4313 * @return GNUNET_OK (always) 4263 * @return GNUNET_OK (always)
4314 */ 4264 */
4315static int 4265static int
4316run_validation (void *cls, 4266run_validation (void *cls, const char *tname,
4317 const char *tname, 4267 struct GNUNET_TIME_Absolute expiration, const void *addr,
4318 struct GNUNET_TIME_Absolute expiration, 4268 uint16_t addrlen)
4319 const void *addr, uint16_t addrlen)
4320{ 4269{
4321 struct CheckHelloValidatedContext *chvc = cls; 4270 struct CheckHelloValidatedContext *chvc = cls;
4322 struct GNUNET_PeerIdentity id; 4271 struct GNUNET_PeerIdentity id;
@@ -4335,8 +4284,7 @@ run_validation (void *cls,
4335 tp = find_transport (tname); 4284 tp = find_transport (tname);
4336 if (tp == NULL) 4285 if (tp == NULL)
4337 { 4286 {
4338 GNUNET_log (GNUNET_ERROR_TYPE_INFO | 4287 GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
4339 GNUNET_ERROR_TYPE_BULK,
4340 _ 4288 _
4341 ("Transport `%s' not loaded, will not try to validate peer address using this transport.\n"), 4289 ("Transport `%s' not loaded, will not try to validate peer address using this transport.\n"),
4342 tname); 4290 tname);
@@ -4363,8 +4311,7 @@ run_validation (void *cls,
4363 } 4311 }
4364 GNUNET_HELLO_get_key (chvc->hello, &pk); 4312 GNUNET_HELLO_get_key (chvc->hello, &pk);
4365 GNUNET_CRYPTO_hash (&pk, 4313 GNUNET_CRYPTO_hash (&pk,
4366 sizeof (struct 4314 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
4367 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
4368 &id.hashPubKey); 4315 &id.hashPubKey);
4369 4316
4370 if (is_blacklisted (&id, tp)) 4317 if (is_blacklisted (&id, tp))
@@ -4382,8 +4329,8 @@ run_validation (void *cls,
4382 caec.session = NULL; 4329 caec.session = NULL;
4383 caec.tname = tname; 4330 caec.tname = tname;
4384 caec.exists = GNUNET_NO; 4331 caec.exists = GNUNET_NO;
4385 GNUNET_CONTAINER_multihashmap_iterate (validation_map, 4332 GNUNET_CONTAINER_multihashmap_iterate (validation_map, &check_address_exists,
4386 &check_address_exists, &caec); 4333 &caec);
4387 if (caec.exists == GNUNET_YES) 4334 if (caec.exists == GNUNET_YES)
4388 { 4335 {
4389 /* During validation attempts we will likely trigger the other 4336 /* During validation attempts we will likely trigger the other
@@ -4405,19 +4352,17 @@ run_validation (void *cls,
4405 va->chvc = chvc; 4352 va->chvc = chvc;
4406 chvc->ve_count++; 4353 chvc->ve_count++;
4407 va->transport_name = GNUNET_strdup (tname); 4354 va->transport_name = GNUNET_strdup (tname);
4408 va->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 4355 va->challenge =
4409 UINT_MAX); 4356 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT_MAX);
4410 va->send_time = GNUNET_TIME_absolute_get (); 4357 va->send_time = GNUNET_TIME_absolute_get ();
4411 va->addr = (const void *) &va[1]; 4358 va->addr = (const void *) &va[1];
4412 memcpy (&va[1], addr, addrlen); 4359 memcpy (&va[1], addr, addrlen);
4413 va->addrlen = addrlen; 4360 va->addrlen = addrlen;
4414 GNUNET_HELLO_get_key (chvc->hello, &va->publicKey); 4361 GNUNET_HELLO_get_key (chvc->hello, &va->publicKey);
4415 va->timeout_task = GNUNET_SCHEDULER_add_delayed (HELLO_VERIFICATION_TIMEOUT, 4362 va->timeout_task =
4416 &timeout_hello_validation, 4363 GNUNET_SCHEDULER_add_delayed (HELLO_VERIFICATION_TIMEOUT,
4417 va); 4364 &timeout_hello_validation, va);
4418 GNUNET_CONTAINER_multihashmap_put (validation_map, 4365 GNUNET_CONTAINER_multihashmap_put (validation_map, &id.hashPubKey, va,
4419 &id.hashPubKey,
4420 va,
4421 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 4366 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
4422 setup_peer_check_blacklist (&id, GNUNET_NO, &transmit_hello_and_ping, va); 4367 setup_peer_check_blacklist (&id, GNUNET_NO, &transmit_hello_and_ping, va);
4423 return GNUNET_OK; 4368 return GNUNET_OK;
@@ -4434,8 +4379,7 @@ run_validation (void *cls,
4434 * @param err_msg NULL if successful, otherwise contains error message 4379 * @param err_msg NULL if successful, otherwise contains error message
4435 */ 4380 */
4436static void 4381static void
4437check_hello_validated (void *cls, 4382check_hello_validated (void *cls, const struct GNUNET_PeerIdentity *peer,
4438 const struct GNUNET_PeerIdentity *peer,
4439 const struct GNUNET_HELLO_Message *h, 4383 const struct GNUNET_HELLO_Message *h,
4440 const char *err_msg) 4384 const char *err_msg)
4441{ 4385{
@@ -4515,8 +4459,8 @@ check_hello_validated (void *cls,
4515 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4459 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4516 "Calling hello_iterate_addresses for %s!\n", GNUNET_i2s (peer)); 4460 "Calling hello_iterate_addresses for %s!\n", GNUNET_i2s (peer));
4517#endif 4461#endif
4518 GNUNET_HELLO_iterate_addresses (h, 4462 GNUNET_HELLO_iterate_addresses (h, GNUNET_NO, &add_to_foreign_address_list,
4519 GNUNET_NO, &add_to_foreign_address_list, n); 4463 n);
4520 try_transmission_to_peer (n); 4464 try_transmission_to_peer (n);
4521 } 4465 }
4522 else 4466 else
@@ -4533,8 +4477,7 @@ check_hello_validated (void *cls,
4533 GNUNET_STATISTICS_update (stats, 4477 GNUNET_STATISTICS_update (stats,
4534 gettext_noop ("# HELLO validations (update case)"), 4478 gettext_noop ("# HELLO validations (update case)"),
4535 1, GNUNET_NO); 4479 1, GNUNET_NO);
4536 GNUNET_HELLO_iterate_new_addresses (chvc->hello, 4480 GNUNET_HELLO_iterate_new_addresses (chvc->hello, h,
4537 h,
4538 GNUNET_TIME_relative_to_absolute 4481 GNUNET_TIME_relative_to_absolute
4539 (HELLO_REVALIDATION_START_TIME), 4482 (HELLO_REVALIDATION_START_TIME),
4540 &run_validation, chvc); 4483 &run_validation, chvc);
@@ -4579,8 +4522,8 @@ process_hello (struct TransportPlugin *plugin,
4579 { 4522 {
4580#if DEBUG_TRANSPORT_HELLO 4523#if DEBUG_TRANSPORT_HELLO
4581 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4524 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4582 "Unable to get public key from `%s' for `%4s'!\n", 4525 "Unable to get public key from `%s' for `%4s'!\n", "HELLO",
4583 "HELLO", GNUNET_i2s (&target)); 4526 GNUNET_i2s (&target));
4584#endif 4527#endif
4585 GNUNET_break_op (0); 4528 GNUNET_break_op (0);
4586 return GNUNET_SYSERR; 4529 return GNUNET_SYSERR;
@@ -4590,8 +4533,7 @@ process_hello (struct TransportPlugin *plugin,
4590 &target.hashPubKey); 4533 &target.hashPubKey);
4591 4534
4592#if DEBUG_TRANSPORT_HELLO 4535#if DEBUG_TRANSPORT_HELLO
4593 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4536 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message for `%4s'\n",
4594 "Received `%s' message for `%4s'\n",
4595 "HELLO", GNUNET_i2s (&target)); 4537 "HELLO", GNUNET_i2s (&target));
4596#endif 4538#endif
4597 if (0 == memcmp (&my_identity, &target, sizeof (struct GNUNET_PeerIdentity))) 4539 if (0 == memcmp (&my_identity, &target, sizeof (struct GNUNET_PeerIdentity)))
@@ -4619,8 +4561,8 @@ process_hello (struct TransportPlugin *plugin,
4619 GNUNET_NO); 4561 GNUNET_NO);
4620#if DEBUG_TRANSPORT_HELLO 4562#if DEBUG_TRANSPORT_HELLO
4621 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4563 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4622 "Ignoring `%s' for `%4s', load too high.\n", 4564 "Ignoring `%s' for `%4s', load too high.\n", "HELLO",
4623 "HELLO", GNUNET_i2s (&target)); 4565 GNUNET_i2s (&target));
4624#endif 4566#endif
4625 return GNUNET_OK; 4567 return GNUNET_OK;
4626 } 4568 }
@@ -4629,9 +4571,8 @@ process_hello (struct TransportPlugin *plugin,
4629 chvc = chvc_head; 4571 chvc = chvc_head;
4630 while (NULL != chvc) 4572 while (NULL != chvc)
4631 { 4573 {
4632 if (GNUNET_HELLO_equals (hello, 4574 if (GNUNET_HELLO_equals (hello, chvc->hello, GNUNET_TIME_absolute_get ()).
4633 chvc->hello, 4575 abs_value > 0)
4634 GNUNET_TIME_absolute_get ()).abs_value > 0)
4635 { 4576 {
4636#if DEBUG_TRANSPORT_HELLO > 2 4577#if DEBUG_TRANSPORT_HELLO > 2
4637 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4578 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -4641,8 +4582,8 @@ process_hello (struct TransportPlugin *plugin,
4641 return GNUNET_OK; /* validation already pending */ 4582 return GNUNET_OK; /* validation already pending */
4642 } 4583 }
4643 if (GNUNET_HELLO_size (hello) == GNUNET_HELLO_size (chvc->hello)) 4584 if (GNUNET_HELLO_size (hello) == GNUNET_HELLO_size (chvc->hello))
4644 GNUNET_break (0 != memcmp (hello, chvc->hello, 4585 GNUNET_break (0 !=
4645 GNUNET_HELLO_size (hello))); 4586 memcmp (hello, chvc->hello, GNUNET_HELLO_size (hello)));
4646 chvc = chvc->next; 4587 chvc = chvc->next;
4647 } 4588 }
4648 4589
@@ -4663,10 +4604,8 @@ process_hello (struct TransportPlugin *plugin,
4663 my_id = GNUNET_strdup (GNUNET_i2s (plugin->env.my_identity)); 4604 my_id = GNUNET_strdup (GNUNET_i2s (plugin->env.my_identity));
4664 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4605 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4665 "%s: Starting validation of `%s' message for `%4s' via '%s' of size %u\n", 4606 "%s: Starting validation of `%s' message for `%4s' via '%s' of size %u\n",
4666 my_id, 4607 my_id, "HELLO", GNUNET_i2s (&target), plugin->short_name,
4667 "HELLO", 4608 GNUNET_HELLO_size (hello));
4668 GNUNET_i2s (&target),
4669 plugin->short_name, GNUNET_HELLO_size (hello));
4670 GNUNET_free (my_id); 4609 GNUNET_free (my_id);
4671#endif 4610#endif
4672 } 4611 }
@@ -4768,8 +4707,7 @@ disconnect_neighbour (struct NeighbourMapEntry *n, int check)
4768 rpos->addresses = peer_pos->next; 4707 rpos->addresses = peer_pos->next;
4769 if (peer_pos->connected == GNUNET_YES) 4708 if (peer_pos->connected == GNUNET_YES)
4770 { 4709 {
4771 GNUNET_STATISTICS_update (stats, 4710 GNUNET_STATISTICS_update (stats, gettext_noop ("# connected addresses"),
4772 gettext_noop ("# connected addresses"),
4773 -1, GNUNET_NO); 4711 -1, GNUNET_NO);
4774 peer_pos->connected = GNUNET_NO; 4712 peer_pos->connected = GNUNET_NO;
4775 } 4713 }
@@ -4804,8 +4742,9 @@ disconnect_neighbour (struct NeighbourMapEntry *n, int check)
4804 ("# bytes discarded due to disconnect"), 4742 ("# bytes discarded due to disconnect"),
4805 mq->message_buf_size, GNUNET_NO); 4743 mq->message_buf_size, GNUNET_NO);
4806 GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq); 4744 GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq);
4807 GNUNET_assert (0 == memcmp (&mq->neighbour_id, 4745 GNUNET_assert (0 ==
4808 &n->id, sizeof (struct GNUNET_PeerIdentity))); 4746 memcmp (&mq->neighbour_id, &n->id,
4747 sizeof (struct GNUNET_PeerIdentity)));
4809 GNUNET_free (mq); 4748 GNUNET_free (mq);
4810 } 4749 }
4811 4750
@@ -4813,8 +4752,9 @@ disconnect_neighbour (struct NeighbourMapEntry *n, int check)
4813 { 4752 {
4814 4753
4815 GNUNET_CONTAINER_DLL_remove (n->cont_head, n->cont_tail, mq); 4754 GNUNET_CONTAINER_DLL_remove (n->cont_head, n->cont_tail, mq);
4816 GNUNET_assert (0 == memcmp (&mq->neighbour_id, 4755 GNUNET_assert (0 ==
4817 &n->id, sizeof (struct GNUNET_PeerIdentity))); 4756 memcmp (&mq->neighbour_id, &n->id,
4757 sizeof (struct GNUNET_PeerIdentity)));
4818 GNUNET_free (mq); 4758 GNUNET_free (mq);
4819 } 4759 }
4820 4760
@@ -4842,9 +4782,8 @@ disconnect_neighbour (struct NeighbourMapEntry *n, int check)
4842 GNUNET_CONTAINER_multihashmap_remove (neighbours, 4782 GNUNET_CONTAINER_multihashmap_remove (neighbours,
4843 &n->id.hashPubKey, n)); 4783 &n->id.hashPubKey, n));
4844 /* finally, free n itself */ 4784 /* finally, free n itself */
4845 GNUNET_STATISTICS_update (stats, 4785 GNUNET_STATISTICS_update (stats, gettext_noop ("# active neighbours"), -1,
4846 gettext_noop ("# active neighbours"), 4786 GNUNET_NO);
4847 -1, GNUNET_NO);
4848 GNUNET_free_non_null (n->pre_connect_message_buffer); 4787 GNUNET_free_non_null (n->pre_connect_message_buffer);
4849 GNUNET_free (n); 4788 GNUNET_free (n);
4850} 4789}
@@ -4856,8 +4795,7 @@ disconnect_neighbour (struct NeighbourMapEntry *n, int check)
4856 */ 4795 */
4857static int 4796static int
4858handle_ping (void *cls, const struct GNUNET_MessageHeader *message, 4797handle_ping (void *cls, const struct GNUNET_MessageHeader *message,
4859 const struct GNUNET_PeerIdentity *peer, 4798 const struct GNUNET_PeerIdentity *peer, struct Session *session,
4860 struct Session *session,
4861 const char *sender_address, uint16_t sender_address_len) 4799 const char *sender_address, uint16_t sender_address_len)
4862{ 4800{
4863 struct TransportPlugin *plugin = cls; 4801 struct TransportPlugin *plugin = cls;
@@ -4880,9 +4818,9 @@ handle_ping (void *cls, const struct GNUNET_MessageHeader *message,
4880 } 4818 }
4881 4819
4882 ping = (struct TransportPingMessage *) message; 4820 ping = (struct TransportPingMessage *) message;
4883 if (0 != memcmp (&ping->target, 4821 if (0 !=
4884 plugin->env.my_identity, 4822 memcmp (&ping->target, plugin->env.my_identity,
4885 sizeof (struct GNUNET_PeerIdentity))) 4823 sizeof (struct GNUNET_PeerIdentity)))
4886 { 4824 {
4887#if DEBUG_TRANSPORT 4825#if DEBUG_TRANSPORT
4888 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4826 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -4898,16 +4836,15 @@ handle_ping (void *cls, const struct GNUNET_MessageHeader *message,
4898 } 4836 }
4899#if DEBUG_PING_PONG 4837#if DEBUG_PING_PONG
4900 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 4838 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
4901 "Processing `%s' from `%s'\n", 4839 "Processing `%s' from `%s'\n", "PING",
4902 "PING", 4840 (sender_address != NULL) ? a2s (plugin->short_name,
4903 (sender_address != NULL) 4841 (const struct sockaddr *)
4904 ? a2s (plugin->short_name, 4842 sender_address,
4905 (const struct sockaddr *) sender_address, 4843 sender_address_len) :
4906 sender_address_len) : "<inbound>"); 4844 "<inbound>");
4907#endif 4845#endif
4908 GNUNET_STATISTICS_update (stats, 4846 GNUNET_STATISTICS_update (stats, gettext_noop ("# PING messages received"), 1,
4909 gettext_noop ("# PING messages received"), 4847 GNUNET_NO);
4910 1, GNUNET_NO);
4911 addr = (const char *) &ping[1]; 4848 addr = (const char *) &ping[1];
4912 alen = ntohs (message->size) - sizeof (struct TransportPingMessage); 4849 alen = ntohs (message->size) - sizeof (struct TransportPingMessage);
4913 slen = strlen (plugin->short_name) + 1; 4850 slen = strlen (plugin->short_name) + 1;
@@ -4930,8 +4867,8 @@ handle_ping (void *cls, const struct GNUNET_MessageHeader *message,
4930 */ 4867 */
4931 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4868 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4932 "Creating PONG indicating that we received a connection at our address `%s' from `%s'.\n", 4869 "Creating PONG indicating that we received a connection at our address `%s' from `%s'.\n",
4933 a2s (plugin->short_name, 4870 a2s (plugin->short_name, sender_address, sender_address_len),
4934 sender_address, sender_address_len), GNUNET_i2s (peer)); 4871 GNUNET_i2s (peer));
4935 4872
4936 pong = 4873 pong =
4937 GNUNET_malloc (sizeof (struct TransportPongMessage) + 4874 GNUNET_malloc (sizeof (struct TransportPongMessage) +
@@ -4942,8 +4879,7 @@ handle_ping (void *cls, const struct GNUNET_MessageHeader *message,
4942 pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG); 4879 pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG);
4943 pong->purpose.size = 4880 pong->purpose.size =
4944 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + 4881 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
4945 sizeof (uint32_t) + 4882 sizeof (uint32_t) + sizeof (struct GNUNET_TIME_AbsoluteNBO) +
4946 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
4947 sizeof (struct GNUNET_PeerIdentity) + sender_address_len + slen); 4883 sizeof (struct GNUNET_PeerIdentity) + sender_address_len + slen);
4948 pong->purpose.purpose = 4884 pong->purpose.purpose =
4949 htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING); 4885 htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING);
@@ -4953,9 +4889,8 @@ handle_ping (void *cls, const struct GNUNET_MessageHeader *message,
4953 memcpy (&pong[1], plugin->short_name, slen); 4889 memcpy (&pong[1], plugin->short_name, slen);
4954 if ((sender_address != NULL) && (sender_address_len > 0)) 4890 if ((sender_address != NULL) && (sender_address_len > 0))
4955 memcpy (&((char *) &pong[1])[slen], sender_address, sender_address_len); 4891 memcpy (&((char *) &pong[1])[slen], sender_address, sender_address_len);
4956 if (GNUNET_TIME_absolute_get_remaining 4892 if (GNUNET_TIME_absolute_get_remaining (session_header->pong_sig_expires).
4957 (session_header->pong_sig_expires).rel_value < 4893 rel_value < PONG_SIGNATURE_LIFETIME.rel_value / 4)
4958 PONG_SIGNATURE_LIFETIME.rel_value / 4)
4959 { 4894 {
4960 /* create / update cached sig */ 4895 /* create / update cached sig */
4961#if DEBUG_TRANSPORT 4896#if DEBUG_TRANSPORT
@@ -4975,8 +4910,7 @@ handle_ping (void *cls, const struct GNUNET_MessageHeader *message,
4975 pong->expiration = 4910 pong->expiration =
4976 GNUNET_TIME_absolute_hton (session_header->pong_sig_expires); 4911 GNUNET_TIME_absolute_hton (session_header->pong_sig_expires);
4977 } 4912 }
4978 memcpy (&pong->signature, 4913 memcpy (&pong->signature, &session_header->pong_signature,
4979 &session_header->pong_signature,
4980 sizeof (struct GNUNET_CRYPTO_RsaSignature)); 4914 sizeof (struct GNUNET_CRYPTO_RsaSignature));
4981 4915
4982 4916
@@ -5007,8 +4941,7 @@ handle_ping (void *cls, const struct GNUNET_MessageHeader *message,
5007 pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG); 4941 pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG);
5008 pong->purpose.size = 4942 pong->purpose.size =
5009 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + 4943 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
5010 sizeof (uint32_t) + 4944 sizeof (uint32_t) + sizeof (struct GNUNET_TIME_AbsoluteNBO) +
5011 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
5012 sizeof (struct GNUNET_PeerIdentity) + alen + slen); 4945 sizeof (struct GNUNET_PeerIdentity) + alen + slen);
5013 pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN); 4946 pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN);
5014 pong->challenge = ping->challenge; 4947 pong->challenge = ping->challenge;
@@ -5029,11 +4962,10 @@ handle_ping (void *cls, const struct GNUNET_MessageHeader *message,
5029 GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME); 4962 GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME);
5030 pong->expiration = GNUNET_TIME_absolute_hton (oal->pong_sig_expires); 4963 pong->expiration = GNUNET_TIME_absolute_hton (oal->pong_sig_expires);
5031 GNUNET_assert (GNUNET_OK == 4964 GNUNET_assert (GNUNET_OK ==
5032 GNUNET_CRYPTO_rsa_sign (my_private_key, 4965 GNUNET_CRYPTO_rsa_sign (my_private_key, &pong->purpose,
5033 &pong->purpose,
5034 &oal->pong_signature)); 4966 &oal->pong_signature));
5035 memcpy (&pong->signature, 4967 memcpy (&pong->signature, &oal->pong_signature,
5036 &oal->pong_signature, sizeof (struct GNUNET_CRYPTO_RsaSignature)); 4968 sizeof (struct GNUNET_CRYPTO_RsaSignature));
5037 } 4969 }
5038 else if (oal == NULL) 4970 else if (oal == NULL)
5039 { 4971 {
@@ -5049,8 +4981,8 @@ handle_ping (void *cls, const struct GNUNET_MessageHeader *message,
5049 { 4981 {
5050 /* can used cached version */ 4982 /* can used cached version */
5051 pong->expiration = GNUNET_TIME_absolute_hton (oal->pong_sig_expires); 4983 pong->expiration = GNUNET_TIME_absolute_hton (oal->pong_sig_expires);
5052 memcpy (&pong->signature, 4984 memcpy (&pong->signature, &oal->pong_signature,
5053 &oal->pong_signature, sizeof (struct GNUNET_CRYPTO_RsaSignature)); 4985 sizeof (struct GNUNET_CRYPTO_RsaSignature));
5054 } 4986 }
5055 } 4987 }
5056 n = find_neighbour (peer); 4988 n = find_neighbour (peer);
@@ -5063,15 +4995,13 @@ handle_ping (void *cls, const struct GNUNET_MessageHeader *message,
5063 fal = rl->addresses; 4995 fal = rl->addresses;
5064 while (fal != NULL) 4996 while (fal != NULL)
5065 { 4997 {
5066 if (-1 != rl->plugin->api->send (rl->plugin->api->cls, 4998 if (-1 !=
5067 peer, 4999 rl->plugin->api->send (rl->plugin->api->cls, peer,
5068 (const char *) pong, 5000 (const char *) pong, ntohs (pong->header.size),
5069 ntohs (pong->header.size), 5001 TRANSPORT_PONG_PRIORITY,
5070 TRANSPORT_PONG_PRIORITY, 5002 HELLO_VERIFICATION_TIMEOUT, fal->session,
5071 HELLO_VERIFICATION_TIMEOUT, 5003 fal->addr, fal->addrlen, GNUNET_SYSERR, NULL,
5072 fal->session, 5004 NULL))
5073 fal->addr,
5074 fal->addrlen, GNUNET_SYSERR, NULL, NULL))
5075 { 5005 {
5076 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5006 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5077 "Transmitted PONG to `%s' via reliable mechanism\n", 5007 "Transmitted PONG to `%s' via reliable mechanism\n",
@@ -5102,13 +5032,11 @@ handle_ping (void *cls, const struct GNUNET_MessageHeader *message,
5102 { 5032 {
5103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5033 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5104 "Transmitting PONG to `%s' via unreliable mechanism `%s':%s\n", 5034 "Transmitting PONG to `%s' via unreliable mechanism `%s':%s\n",
5105 GNUNET_i2s (peer), 5035 GNUNET_i2s (peer), a2s (rl->plugin->short_name, fal->addr,
5106 a2s (rl->plugin->short_name, 5036 fal->addrlen),
5107 fal->addr, fal->addrlen), rl->plugin->short_name); 5037 rl->plugin->short_name);
5108 transmit_to_peer (NULL, fal, 5038 transmit_to_peer (NULL, fal, TRANSPORT_PONG_PRIORITY,
5109 TRANSPORT_PONG_PRIORITY, 5039 HELLO_VERIFICATION_TIMEOUT, (const char *) pong,
5110 HELLO_VERIFICATION_TIMEOUT,
5111 (const char *) pong,
5112 ntohs (pong->header.size), GNUNET_YES, n); 5040 ntohs (pong->header.size), GNUNET_YES, n);
5113 did_pong = GNUNET_YES; 5041 did_pong = GNUNET_YES;
5114 fal = fal->next; 5042 fal = fal->next;
@@ -5146,8 +5074,7 @@ static struct GNUNET_TIME_Relative
5146plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 5074plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
5147 const struct GNUNET_MessageHeader *message, 5075 const struct GNUNET_MessageHeader *message,
5148 const struct GNUNET_TRANSPORT_ATS_Information *ats_data, 5076 const struct GNUNET_TRANSPORT_ATS_Information *ats_data,
5149 uint32_t ats_count, 5077 uint32_t ats_count, struct Session *session,
5150 struct Session *session,
5151 const char *sender_address, uint16_t sender_address_len) 5078 const char *sender_address, uint16_t sender_address_len)
5152{ 5079{
5153 struct TransportPlugin *plugin = cls; 5080 struct TransportPlugin *plugin = cls;
@@ -5185,10 +5112,9 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
5185 if (message != NULL) 5112 if (message != NULL)
5186 { 5113 {
5187 if ((session != NULL) || (sender_address != NULL)) 5114 if ((session != NULL) || (sender_address != NULL))
5188 peer_address = add_peer_address (n, 5115 peer_address =
5189 plugin->short_name, 5116 add_peer_address (n, plugin->short_name, session, sender_address,
5190 session, 5117 sender_address_len);
5191 sender_address, sender_address_len);
5192 if (peer_address != NULL) 5118 if (peer_address != NULL)
5193 { 5119 {
5194 update_addr_ats (peer_address, ats_data, ats_count); 5120 update_addr_ats (peer_address, ats_data, ats_count);
@@ -5216,8 +5142,7 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
5216 GNUNET_SCHEDULER_add_now (&send_periodic_ping, peer_address); 5142 GNUNET_SCHEDULER_add_now (&send_periodic_ping, peer_address);
5217 5143
5218 } 5144 }
5219 peer_address->timeout 5145 peer_address->timeout =
5220 =
5221 GNUNET_TIME_relative_to_absolute 5146 GNUNET_TIME_relative_to_absolute
5222 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 5147 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
5223 } 5148 }
@@ -5239,8 +5164,7 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
5239 if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD) 5164 if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD)
5240 { 5165 {
5241 /* dropping message due to frequent inbound volume violations! */ 5166 /* dropping message due to frequent inbound volume violations! */
5242 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | 5167 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
5243 GNUNET_ERROR_TYPE_BULK,
5244 _ 5168 _
5245 ("Dropping incoming message due to repeated bandwidth quota (%u b/s) violations (total of %u).\n"), 5169 ("Dropping incoming message due to repeated bandwidth quota (%u b/s) violations (total of %u).\n"),
5246 n->in_tracker.available_bytes_per_s__, 5170 n->in_tracker.available_bytes_per_s__,
@@ -5277,8 +5201,8 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
5277#if DEBUG_PING_PONG 5201#if DEBUG_PING_PONG
5278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5279 "Received message of type %u and size %u from `%4s', sending to all clients.\n", 5203 "Received message of type %u and size %u from `%4s', sending to all clients.\n",
5280 ntohs (message->type), 5204 ntohs (message->type), ntohs (message->size),
5281 ntohs (message->size), GNUNET_i2s (peer)); 5205 GNUNET_i2s (peer));
5282#endif 5206#endif
5283 switch (ntohs (message->type)) 5207 switch (ntohs (message->type))
5284 { 5208 {
@@ -5311,13 +5235,12 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
5311#if DEBUG_TRANSPORT 5235#if DEBUG_TRANSPORT
5312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5313 "Throttling read (%llu bytes excess at %u b/s), waiting %llu ms before reading more.\n", 5237 "Throttling read (%llu bytes excess at %u b/s), waiting %llu ms before reading more.\n",
5314 (unsigned long long) n-> 5238 (unsigned long long) n->in_tracker.
5315 in_tracker.consumption_since_last_update__, 5239 consumption_since_last_update__,
5316 (unsigned int) n->in_tracker.available_bytes_per_s__, 5240 (unsigned int) n->in_tracker.available_bytes_per_s__,
5317 (unsigned long long) ret.rel_value); 5241 (unsigned long long) ret.rel_value);
5318#endif 5242#endif
5319 GNUNET_STATISTICS_update (stats, 5243 GNUNET_STATISTICS_update (stats, gettext_noop ("# ms throttling suggested"),
5320 gettext_noop ("# ms throttling suggested"),
5321 (int64_t) ret.rel_value, GNUNET_NO); 5244 (int64_t) ret.rel_value, GNUNET_NO);
5322 } 5245 }
5323 return ret; 5246 return ret;
@@ -5325,8 +5248,8 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
5325 5248
5326 5249
5327static int 5250static int
5328notify_client_about_neighbour (void *cls, 5251notify_client_about_neighbour (void *cls, const GNUNET_HashCode * key,
5329 const GNUNET_HashCode * key, void *value) 5252 void *value)
5330{ 5253{
5331 struct TransportClient *c = cls; 5254 struct TransportClient *c = cls;
5332 struct NeighbourMapEntry *n = value; 5255 struct NeighbourMapEntry *n = value;
@@ -5371,8 +5294,7 @@ notify_client_about_neighbour (void *cls,
5371 * @param message the actual message 5294 * @param message the actual message
5372 */ 5295 */
5373static void 5296static void
5374handle_start (void *cls, 5297handle_start (void *cls, struct GNUNET_SERVER_Client *client,
5375 struct GNUNET_SERVER_Client *client,
5376 const struct GNUNET_MessageHeader *message) 5298 const struct GNUNET_MessageHeader *message)
5377{ 5299{
5378 const struct StartMessage *start; 5300 const struct StartMessage *start;
@@ -5380,8 +5302,8 @@ handle_start (void *cls,
5380 5302
5381 start = (const struct StartMessage *) message; 5303 start = (const struct StartMessage *) message;
5382#if DEBUG_TRANSPORT 5304#if DEBUG_TRANSPORT
5383 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' request from client\n",
5384 "Received `%s' request from client\n", "START"); 5306 "START");
5385#endif 5307#endif
5386 c = clients; 5308 c = clients;
5387 while (c != NULL) 5309 while (c != NULL)
@@ -5396,8 +5318,9 @@ handle_start (void *cls,
5396 c = c->next; 5318 c = c->next;
5397 } 5319 }
5398 if ((GNUNET_NO != ntohl (start->do_check)) && 5320 if ((GNUNET_NO != ntohl (start->do_check)) &&
5399 (0 != memcmp (&start->self, 5321 (0 !=
5400 &my_identity, sizeof (struct GNUNET_PeerIdentity)))) 5322 memcmp (&start->self, &my_identity,
5323 sizeof (struct GNUNET_PeerIdentity))))
5401 { 5324 {
5402 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 5325 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
5403 _ 5326 _
@@ -5413,11 +5336,10 @@ handle_start (void *cls,
5413 if (our_hello != NULL) 5336 if (our_hello != NULL)
5414 { 5337 {
5415#if DEBUG_TRANSPORT 5338#if DEBUG_TRANSPORT
5416 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5339 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending our own `%s' to new client\n",
5417 "Sending our own `%s' to new client\n", "HELLO"); 5340 "HELLO");
5418#endif 5341#endif
5419 transmit_to_client (c, 5342 transmit_to_client (c, (const struct GNUNET_MessageHeader *) our_hello,
5420 (const struct GNUNET_MessageHeader *) our_hello,
5421 GNUNET_NO); 5343 GNUNET_NO);
5422 /* tell new client about all existing connections */ 5344 /* tell new client about all existing connections */
5423 GNUNET_CONTAINER_multihashmap_iterate (neighbours, 5345 GNUNET_CONTAINER_multihashmap_iterate (neighbours,
@@ -5443,15 +5365,14 @@ handle_start (void *cls,
5443 * @param message the actual message 5365 * @param message the actual message
5444 */ 5366 */
5445static void 5367static void
5446handle_hello (void *cls, 5368handle_hello (void *cls, struct GNUNET_SERVER_Client *client,
5447 struct GNUNET_SERVER_Client *client,
5448 const struct GNUNET_MessageHeader *message) 5369 const struct GNUNET_MessageHeader *message)
5449{ 5370{
5450 int ret; 5371 int ret;
5451 5372
5452 GNUNET_STATISTICS_update (stats, 5373 GNUNET_STATISTICS_update (stats,
5453 gettext_noop ("# HELLOs received from clients"), 5374 gettext_noop ("# HELLOs received from clients"), 1,
5454 1, GNUNET_NO); 5375 GNUNET_NO);
5455 ret = process_hello (NULL, message); 5376 ret = process_hello (NULL, message);
5456 GNUNET_SERVER_receive_done (client, ret); 5377 GNUNET_SERVER_receive_done (client, ret);
5457} 5378}
@@ -5521,8 +5442,7 @@ transmit_client_message (void *cls, struct NeighbourMapEntry *n)
5521 * @param message the actual message 5442 * @param message the actual message
5522 */ 5443 */
5523static void 5444static void
5524handle_send (void *cls, 5445handle_send (void *cls, struct GNUNET_SERVER_Client *client,
5525 struct GNUNET_SERVER_Client *client,
5526 const struct GNUNET_MessageHeader *message) 5446 const struct GNUNET_MessageHeader *message)
5527{ 5447{
5528 const struct OutboundMessage *obm; 5448 const struct OutboundMessage *obm;
@@ -5560,8 +5480,8 @@ handle_send (void *cls,
5560 /* FIXME: this memcpy can be up to 7% of our total runtime */ 5480 /* FIXME: this memcpy can be up to 7% of our total runtime */
5561 memcpy (&tcmc[1], obmm, msize); 5481 memcpy (&tcmc[1], obmm, msize);
5562 GNUNET_SERVER_client_keep (client); 5482 GNUNET_SERVER_client_keep (client);
5563 setup_peer_check_blacklist (&obm->peer, GNUNET_YES, 5483 setup_peer_check_blacklist (&obm->peer, GNUNET_YES, &transmit_client_message,
5564 &transmit_client_message, tcmc); 5484 tcmc);
5565} 5485}
5566 5486
5567 5487
@@ -5573,8 +5493,7 @@ handle_send (void *cls,
5573 * @param message the actual message 5493 * @param message the actual message
5574 */ 5494 */
5575static void 5495static void
5576handle_request_connect (void *cls, 5496handle_request_connect (void *cls, struct GNUNET_SERVER_Client *client,
5577 struct GNUNET_SERVER_Client *client,
5578 const struct GNUNET_MessageHeader *message) 5497 const struct GNUNET_MessageHeader *message)
5579{ 5498{
5580 const struct TransportRequestConnectMessage *trcm = 5499 const struct TransportRequestConnectMessage *trcm =
@@ -5602,16 +5521,15 @@ handle_request_connect (void *cls,
5602 * @param message the actual message 5521 * @param message the actual message
5603 */ 5522 */
5604static void 5523static void
5605handle_set_quota (void *cls, 5524handle_set_quota (void *cls, struct GNUNET_SERVER_Client *client,
5606 struct GNUNET_SERVER_Client *client,
5607 const struct GNUNET_MessageHeader *message) 5525 const struct GNUNET_MessageHeader *message)
5608{ 5526{
5609 const struct QuotaSetMessage *qsm = (const struct QuotaSetMessage *) message; 5527 const struct QuotaSetMessage *qsm = (const struct QuotaSetMessage *) message;
5610 struct NeighbourMapEntry *n; 5528 struct NeighbourMapEntry *n;
5611 5529
5612 GNUNET_STATISTICS_update (stats, 5530 GNUNET_STATISTICS_update (stats,
5613 gettext_noop ("# SET QUOTA messages received"), 5531 gettext_noop ("# SET QUOTA messages received"), 1,
5614 1, GNUNET_NO); 5532 GNUNET_NO);
5615 n = find_neighbour (&qsm->peer); 5533 n = find_neighbour (&qsm->peer);
5616 if (n == NULL) 5534 if (n == NULL)
5617 { 5535 {
@@ -5625,8 +5543,7 @@ handle_set_quota (void *cls,
5625#if DEBUG_TRANSPORT 5543#if DEBUG_TRANSPORT
5626 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5544 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5627 "Received `%s' request (new quota %u, old quota %u) from client for peer `%4s'\n", 5545 "Received `%s' request (new quota %u, old quota %u) from client for peer `%4s'\n",
5628 "SET_QUOTA", 5546 "SET_QUOTA", (unsigned int) ntohl (qsm->quota.value__),
5629 (unsigned int) ntohl (qsm->quota.value__),
5630 (unsigned int) n->in_tracker.available_bytes_per_s__, 5547 (unsigned int) n->in_tracker.available_bytes_per_s__,
5631 GNUNET_i2s (&qsm->peer)); 5548 GNUNET_i2s (&qsm->peer));
5632#endif 5549#endif
@@ -5634,9 +5551,8 @@ handle_set_quota (void *cls,
5634 if (0 == ntohl (qsm->quota.value__)) 5551 if (0 == ntohl (qsm->quota.value__))
5635 { 5552 {
5636#if DEBUG_TRANSPORT 5553#if DEBUG_TRANSPORT
5637 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5554 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s', %s\n",
5638 "Disconnecting peer `%4s', %s\n", GNUNET_i2s (&n->id), 5555 GNUNET_i2s (&n->id), "SET_QUOTA");
5639 "SET_QUOTA");
5640#endif 5556#endif
5641 GNUNET_STATISTICS_update (stats, 5557 GNUNET_STATISTICS_update (stats,
5642 gettext_noop ("# disconnects due to quota of 0"), 5558 gettext_noop ("# disconnects due to quota of 0"),
@@ -5683,8 +5599,7 @@ transmit_address_to_client (void *cls, const char *address)
5683 * @param message the actual message 5599 * @param message the actual message
5684 */ 5600 */
5685static void 5601static void
5686handle_address_lookup (void *cls, 5602handle_address_lookup (void *cls, struct GNUNET_SERVER_Client *client,
5687 struct GNUNET_SERVER_Client *client,
5688 const struct GNUNET_MessageHeader *message) 5603 const struct GNUNET_MessageHeader *message)
5689{ 5604{
5690 const struct AddressLookupMessage *alum; 5605 const struct AddressLookupMessage *alum;
@@ -5734,11 +5649,8 @@ handle_address_lookup (void *cls,
5734 } 5649 }
5735 GNUNET_SERVER_disable_receive_done_warning (client); 5650 GNUNET_SERVER_disable_receive_done_warning (client);
5736 tc = GNUNET_SERVER_transmit_context_create (client); 5651 tc = GNUNET_SERVER_transmit_context_create (client);
5737 lsPlugin->api->address_pretty_printer (lsPlugin->api->cls, 5652 lsPlugin->api->address_pretty_printer (lsPlugin->api->cls, nameTransport,
5738 nameTransport, 5653 address, addressLen, numeric, rtimeout,
5739 address, addressLen,
5740 numeric,
5741 rtimeout,
5742 &transmit_address_to_client, tc); 5654 &transmit_address_to_client, tc);
5743} 5655}
5744 5656
@@ -5750,8 +5662,7 @@ handle_address_lookup (void *cls,
5750 * @param message the actual message 5662 * @param message the actual message
5751 */ 5663 */
5752static void 5664static void
5753handle_peer_address_lookup (void *cls, 5665handle_peer_address_lookup (void *cls, struct GNUNET_SERVER_Client *client,
5754 struct GNUNET_SERVER_Client *client,
5755 const struct GNUNET_MessageHeader *message) 5666 const struct GNUNET_MessageHeader *message)
5756{ 5667{
5757 const struct PeerAddressLookupMessage *peer_address_lookup; 5668 const struct PeerAddressLookupMessage *peer_address_lookup;
@@ -5804,22 +5715,20 @@ handle_peer_address_lookup (void *cls,
5804 a2s (transport_plugin->short_name, 5715 a2s (transport_plugin->short_name,
5805 foreign_address_iterator->addr, 5716 foreign_address_iterator->addr,
5806 foreign_address_iterator->addrlen), 5717 foreign_address_iterator->addrlen),
5807 (foreign_address_iterator->connected 5718 (foreign_address_iterator->connected ==
5808 == GNUNET_YES) ? "CONNECTED" 5719 GNUNET_YES) ? "CONNECTED" : "DISCONNECTED",
5809 : "DISCONNECTED", 5720 (foreign_address_iterator->validated ==
5810 (foreign_address_iterator->validated 5721 GNUNET_YES) ? "VALIDATED" : "UNVALIDATED");
5811 == GNUNET_YES) ? "VALIDATED" : "UNVALIDATED");
5812 transmit_address_to_client (tc, addr_buf); 5722 transmit_address_to_client (tc, addr_buf);
5813 GNUNET_free (addr_buf); 5723 GNUNET_free (addr_buf);
5814 } 5724 }
5815 else if (foreign_address_iterator->addrlen == 0) 5725 else if (foreign_address_iterator->addrlen == 0)
5816 { 5726 {
5817 GNUNET_asprintf (&addr_buf, "%s --- %s, %s", "<inbound>", 5727 GNUNET_asprintf (&addr_buf, "%s --- %s, %s", "<inbound>",
5818 (foreign_address_iterator->connected 5728 (foreign_address_iterator->connected ==
5819 == GNUNET_YES) ? "CONNECTED" 5729 GNUNET_YES) ? "CONNECTED" : "DISCONNECTED",
5820 : "DISCONNECTED", 5730 (foreign_address_iterator->validated ==
5821 (foreign_address_iterator->validated 5731 GNUNET_YES) ? "VALIDATED" : "UNVALIDATED");
5822 == GNUNET_YES) ? "VALIDATED" : "UNVALIDATED");
5823 transmit_address_to_client (tc, addr_buf); 5732 transmit_address_to_client (tc, addr_buf);
5824 GNUNET_free (addr_buf); 5733 GNUNET_free (addr_buf);
5825 } 5734 }
@@ -5859,24 +5768,21 @@ output_addresses (void *cls, const GNUNET_HashCode * key, void *value)
5859 a2s (transport_plugin->short_name, 5768 a2s (transport_plugin->short_name,
5860 foreign_address_iterator->addr, 5769 foreign_address_iterator->addr,
5861 foreign_address_iterator->addrlen), 5770 foreign_address_iterator->addrlen),
5862 (foreign_address_iterator->connected 5771 (foreign_address_iterator->connected ==
5863 == GNUNET_YES) ? "CONNECTED" 5772 GNUNET_YES) ? "CONNECTED" : "DISCONNECTED",
5864 : "DISCONNECTED", 5773 (foreign_address_iterator->validated ==
5865 (foreign_address_iterator->validated 5774 GNUNET_YES) ? "VALIDATED" : "UNVALIDATED");
5866 == GNUNET_YES) ? "VALIDATED" : "UNVALIDATED");
5867 transmit_address_to_client (tc, addr_buf); 5775 transmit_address_to_client (tc, addr_buf);
5868 GNUNET_free (addr_buf); 5776 GNUNET_free (addr_buf);
5869 } 5777 }
5870 else if (foreign_address_iterator->addrlen == 0) 5778 else if (foreign_address_iterator->addrlen == 0)
5871 { 5779 {
5872 GNUNET_asprintf (&addr_buf, "%s:%s --- %s, %s", 5780 GNUNET_asprintf (&addr_buf, "%s:%s --- %s, %s",
5873 GNUNET_i2s (&neighbor_iterator->id), 5781 GNUNET_i2s (&neighbor_iterator->id), "<inbound>",
5874 "<inbound>", 5782 (foreign_address_iterator->connected ==
5875 (foreign_address_iterator->connected 5783 GNUNET_YES) ? "CONNECTED" : "DISCONNECTED",
5876 == GNUNET_YES) ? "CONNECTED" 5784 (foreign_address_iterator->validated ==
5877 : "DISCONNECTED", 5785 GNUNET_YES) ? "VALIDATED" : "UNVALIDATED");
5878 (foreign_address_iterator->validated
5879 == GNUNET_YES) ? "VALIDATED" : "UNVALIDATED");
5880 transmit_address_to_client (tc, addr_buf); 5786 transmit_address_to_client (tc, addr_buf);
5881 GNUNET_free (addr_buf); 5787 GNUNET_free (addr_buf);
5882 } 5788 }
@@ -5897,8 +5803,7 @@ output_addresses (void *cls, const GNUNET_HashCode * key, void *value)
5897 * @param message the actual message 5803 * @param message the actual message
5898 */ 5804 */
5899static void 5805static void
5900handle_address_iterate (void *cls, 5806handle_address_iterate (void *cls, struct GNUNET_SERVER_Client *client,
5901 struct GNUNET_SERVER_Client *client,
5902 const struct GNUNET_MessageHeader *message) 5807 const struct GNUNET_MessageHeader *message)
5903{ 5808{
5904 struct GNUNET_SERVER_TransmitContext *tc; 5809 struct GNUNET_SERVER_TransmitContext *tc;
@@ -5954,8 +5859,8 @@ start_transport (struct GNUNET_SERVER_Handle *server, const char *name)
5954 struct TransportPlugin *plug; 5859 struct TransportPlugin *plug;
5955 char *libname; 5860 char *libname;
5956 5861
5957 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 5862 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' transport plugin\n"),
5958 _("Loading `%s' transport plugin\n"), name); 5863 name);
5959 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", name); 5864 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", name);
5960 plug = GNUNET_malloc (sizeof (struct TransportPlugin)); 5865 plug = GNUNET_malloc (sizeof (struct TransportPlugin));
5961 create_environment (plug); 5866 create_environment (plug);
@@ -6062,8 +5967,8 @@ client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
6062 GNUNET_free (mqe); 5967 GNUNET_free (mqe);
6063 } 5968 }
6064 if (NULL != neighbours) 5969 if (NULL != neighbours)
6065 GNUNET_CONTAINER_multihashmap_iterate (neighbours, 5970 GNUNET_CONTAINER_multihashmap_iterate (neighbours, &null_mq_client_pointers,
6066 &null_mq_client_pointers, pos); 5971 pos);
6067 if (prev == NULL) 5972 if (prev == NULL)
6068 clients = pos->next; 5973 clients = pos->next;
6069 else 5974 else
@@ -6089,8 +5994,7 @@ disconnect_all_neighbours (void *cls, const GNUNET_HashCode * key, void *value)
6089 struct NeighbourMapEntry *n = value; 5994 struct NeighbourMapEntry *n = value;
6090 5995
6091#if DEBUG_TRANSPORT 5996#if DEBUG_TRANSPORT
6092 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5997 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s', %s\n",
6093 "Disconnecting peer `%4s', %s\n",
6094 GNUNET_i2s (&n->id), "SHUTDOWN_TASK"); 5998 GNUNET_i2s (&n->id), "SHUTDOWN_TASK");
6095#endif 5999#endif
6096 disconnect_neighbour (n, GNUNET_NO); 6000 disconnect_neighbour (n, GNUNET_NO);
@@ -6113,8 +6017,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
6113 struct CheckHelloValidatedContext *chvc; 6017 struct CheckHelloValidatedContext *chvc;
6114 6018
6115 shutdown_in_progress = GNUNET_YES; 6019 shutdown_in_progress = GNUNET_YES;
6116 GNUNET_CONTAINER_multihashmap_iterate (neighbours, 6020 GNUNET_CONTAINER_multihashmap_iterate (neighbours, &disconnect_all_neighbours,
6117 &disconnect_all_neighbours, NULL); 6021 NULL);
6118#if DEBUG_TRANSPORT 6022#if DEBUG_TRANSPORT
6119 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6023 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6120 "Transport service is unloading plugins...\n"); 6024 "Transport service is unloading plugins...\n");
@@ -6141,8 +6045,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
6141 GNUNET_CRYPTO_rsa_key_free (my_private_key); 6045 GNUNET_CRYPTO_rsa_key_free (my_private_key);
6142 GNUNET_free_non_null (our_hello); 6046 GNUNET_free_non_null (our_hello);
6143 6047
6144 GNUNET_CONTAINER_multihashmap_iterate (validation_map, 6048 GNUNET_CONTAINER_multihashmap_iterate (validation_map, &abort_validation,
6145 &abort_validation, NULL); 6049 NULL);
6146 GNUNET_CONTAINER_multihashmap_destroy (validation_map); 6050 GNUNET_CONTAINER_multihashmap_destroy (validation_map);
6147 validation_map = NULL; 6051 validation_map = NULL;
6148 6052
@@ -6290,8 +6194,8 @@ setup_ats_problem (void *cls, const GNUNET_HashCode * key, void *value)
6290 6194
6291 6195
6292static void 6196static void
6293create_ats_information (struct ATS_peer **p, 6197create_ats_information (struct ATS_peer **p, int *c_p, struct ATS_mechanism **m,
6294 int *c_p, struct ATS_mechanism **m, int *c_m) 6198 int *c_m)
6295{ 6199{
6296 struct AtsBuildContext abc; 6200 struct AtsBuildContext abc;
6297 6201
@@ -6301,8 +6205,8 @@ create_ats_information (struct ATS_peer **p,
6301#endif 6205#endif
6302 abc.c_peers = 0; 6206 abc.c_peers = 0;
6303 abc.c_mechs = 0; 6207 abc.c_mechs = 0;
6304 GNUNET_CONTAINER_multihashmap_iterate (neighbours, 6208 GNUNET_CONTAINER_multihashmap_iterate (neighbours, &find_and_count_addresses,
6305 &find_and_count_addresses, &abc); 6209 &abc);
6306#if VERBOSE_ATS 6210#if VERBOSE_ATS
6307 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 6211 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
6308 "Found %u peers with % u transport mechanisms\n", c_peers, 6212 "Found %u peers with % u transport mechanisms\n", c_peers,
@@ -6369,8 +6273,8 @@ schedule_ats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
6369#endif 6273#endif
6370 last_ats_execution = GNUNET_TIME_absolute_get (); 6274 last_ats_execution = GNUNET_TIME_absolute_get ();
6371 6275
6372 ats_task = GNUNET_SCHEDULER_add_delayed (ats_regular_interval, 6276 ats_task =
6373 &schedule_ats, ats); 6277 GNUNET_SCHEDULER_add_delayed (ats_regular_interval, &schedule_ats, ats);
6374} 6278}
6375#endif 6279#endif
6376 6280
@@ -6390,8 +6294,7 @@ get_preferred_ats_address (struct NeighbourMapEntry *n)
6390 * @param c configuration to use 6294 * @param c configuration to use
6391 */ 6295 */
6392static void 6296static void
6393run (void *cls, 6297run (void *cls, struct GNUNET_SERVER_Handle *server,
6394 struct GNUNET_SERVER_Handle *server,
6395 const struct GNUNET_CONFIGURATION_Handle *c) 6298 const struct GNUNET_CONFIGURATION_Handle *c)
6396{ 6299{
6397 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 6300 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
@@ -6436,14 +6339,11 @@ run (void *cls,
6436 neighbours = GNUNET_CONTAINER_multihashmap_create (256); 6339 neighbours = GNUNET_CONTAINER_multihashmap_create (256);
6437 /* parse configuration */ 6340 /* parse configuration */
6438 if ((GNUNET_OK != 6341 if ((GNUNET_OK !=
6439 GNUNET_CONFIGURATION_get_value_number (c, 6342 GNUNET_CONFIGURATION_get_value_number (c, "TRANSPORT", "NEIGHBOUR_LIMIT",
6440 "TRANSPORT",
6441 "NEIGHBOUR_LIMIT",
6442 &tneigh)) || 6343 &tneigh)) ||
6443 (GNUNET_OK != 6344 (GNUNET_OK !=
6444 GNUNET_CONFIGURATION_get_value_filename (c, 6345 GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY",
6445 "GNUNETD", 6346 &keyfile)))
6446 "HOSTKEY", &keyfile)))
6447 { 6347 {
6448 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 6348 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
6449 _ 6349 _
@@ -6499,18 +6399,18 @@ run (void *cls,
6499 return; 6399 return;
6500 } 6400 }
6501 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); 6401 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
6502 GNUNET_CRYPTO_hash (&my_public_key, 6402 GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key),
6503 sizeof (my_public_key), &my_identity.hashPubKey); 6403 &my_identity.hashPubKey);
6504 /* setup notification */ 6404 /* setup notification */
6505 GNUNET_SERVER_disconnect_notify (server, 6405 GNUNET_SERVER_disconnect_notify (server, &client_disconnect_notification,
6506 &client_disconnect_notification, NULL); 6406 NULL);
6507 /* load plugins... */ 6407 /* load plugins... */
6508 no_transports = 1; 6408 no_transports = 1;
6509 if (GNUNET_OK == 6409 if (GNUNET_OK ==
6510 GNUNET_CONFIGURATION_get_value_string (c, "TRANSPORT", "PLUGINS", &plugs)) 6410 GNUNET_CONFIGURATION_get_value_string (c, "TRANSPORT", "PLUGINS", &plugs))
6511 { 6411 {
6512 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 6412 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Starting transport plugins `%s'\n"),
6513 _("Starting transport plugins `%s'\n"), plugs); 6413 plugs);
6514 pos = strtok (plugs, " "); 6414 pos = strtok (plugs, " ");
6515 while (pos != NULL) 6415 while (pos != NULL)
6516 { 6416 {
@@ -6520,8 +6420,8 @@ run (void *cls,
6520 } 6420 }
6521 GNUNET_free (plugs); 6421 GNUNET_free (plugs);
6522 } 6422 }
6523 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 6423 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
6524 &shutdown_task, NULL); 6424 NULL);
6525 if (no_transports) 6425 if (no_transports)
6526 refresh_hello (); 6426 refresh_hello ();
6527 6427
@@ -6547,9 +6447,9 @@ run (void *cls,
6547 GNUNET_asprintf (&section, "%s_UP", ressources[co].cfg_param); 6447 GNUNET_asprintf (&section, "%s_UP", ressources[co].cfg_param);
6548 if (GNUNET_CONFIGURATION_have_value (cfg, "transport", section)) 6448 if (GNUNET_CONFIGURATION_have_value (cfg, "transport", section))
6549 { 6449 {
6550 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, 6450 if (GNUNET_OK ==
6551 "transport", 6451 GNUNET_CONFIGURATION_get_value_number (cfg, "transport", section,
6552 section, &value)) 6452 &value))
6553 { 6453 {
6554#if DEBUG_ATS 6454#if DEBUG_ATS
6555 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 6455 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -6562,9 +6462,9 @@ run (void *cls,
6562 GNUNET_asprintf (&section, "%s_DOWN", ressources[co].cfg_param); 6462 GNUNET_asprintf (&section, "%s_DOWN", ressources[co].cfg_param);
6563 if (GNUNET_CONFIGURATION_have_value (cfg, "transport", section)) 6463 if (GNUNET_CONFIGURATION_have_value (cfg, "transport", section))
6564 { 6464 {
6565 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, 6465 if (GNUNET_OK ==
6566 "transport", 6466 GNUNET_CONFIGURATION_get_value_number (cfg, "transport", section,
6567 section, &value)) 6467 &value))
6568 { 6468 {
6569#if DEBUG_ATS 6469#if DEBUG_ATS
6570 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 6470 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -6576,18 +6476,16 @@ run (void *cls,
6576 GNUNET_free (section); 6476 GNUNET_free (section);
6577 } 6477 }
6578#if HAVE_LIBGLPK 6478#if HAVE_LIBGLPK
6579 ats = ats_init (D, U, R, v_b_min, v_n_min, 6479 ats =
6580 ATS_MAX_ITERATIONS, ATS_MAX_EXEC_DURATION, 6480 ats_init (D, U, R, v_b_min, v_n_min, ATS_MAX_ITERATIONS,
6581 &create_ats_information, ats_result_cb); 6481 ATS_MAX_EXEC_DURATION, &create_ats_information, ats_result_cb);
6582 ats_set_logging_options (ats, stats, cfg); 6482 ats_set_logging_options (ats, stats, cfg);
6583 GNUNET_break (GNUNET_OK == 6483 GNUNET_break (GNUNET_OK ==
6584 GNUNET_CONFIGURATION_get_value_time (cfg, 6484 GNUNET_CONFIGURATION_get_value_time (cfg, "transport",
6585 "transport",
6586 "ATS_EXEC_INTERVAL", 6485 "ATS_EXEC_INTERVAL",
6587 &ats_regular_interval)); 6486 &ats_regular_interval));
6588 GNUNET_break (GNUNET_OK == 6487 GNUNET_break (GNUNET_OK ==
6589 GNUNET_CONFIGURATION_get_value_time (cfg, 6488 GNUNET_CONFIGURATION_get_value_time (cfg, "transport",
6590 "transport",
6591 "ATS_MIN_INTERVAL", 6489 "ATS_MIN_INTERVAL",
6592 &ats_minimum_interval)); 6490 &ats_minimum_interval));
6593 if (ats != NULL) 6491 if (ats != NULL)
@@ -6617,9 +6515,7 @@ main (int argc, char *const *argv)
6617{ 6515{
6618 a2s (NULL, NULL, 0); /* make compiler happy */ 6516 a2s (NULL, NULL, 0); /* make compiler happy */
6619 return (GNUNET_OK == 6517 return (GNUNET_OK ==
6620 GNUNET_SERVICE_run (argc, 6518 GNUNET_SERVICE_run (argc, argv, "transport",
6621 argv,
6622 "transport",
6623 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; 6519 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
6624} 6520}
6625 6521
diff --git a/src/transport/gnunet-service-transport_ats.c b/src/transport/gnunet-service-transport_ats.c
index 34d1791b9..2e859f1db 100644
--- a/src/transport/gnunet-service-transport_ats.c
+++ b/src/transport/gnunet-service-transport_ats.c
@@ -317,8 +317,8 @@ _lp_simplex (glp_prob *P, void *parm)
317} 317}
318 318
319static void 319static void
320_lp_load_matrix (glp_prob *P, int ne, const int ia[], 320_lp_load_matrix (glp_prob *P, int ne, const int ia[], const int ja[],
321 const int ja[], const double ar[]) 321 const double ar[])
322{ 322{
323#if HAVE_LIBGLPK 323#if HAVE_LIBGLPK
324 glp_load_matrix (P, ne, ia, ja, ar); 324 glp_load_matrix (P, ne, ia, ja, ar);
@@ -510,13 +510,8 @@ _dummy2 ()
510 */ 510 */
511 511
512struct ATS_Handle * 512struct ATS_Handle *
513ats_init (double D, 513ats_init (double D, double U, double R, int v_b_min, int v_n_min,
514 double U, 514 int max_iterations, struct GNUNET_TIME_Relative max_duration,
515 double R,
516 int v_b_min,
517 int v_n_min,
518 int max_iterations,
519 struct GNUNET_TIME_Relative max_duration,
520 GNUNET_TRANSPORT_ATS_AddressNotification address_not, 515 GNUNET_TRANSPORT_ATS_AddressNotification address_not,
521 GNUNET_TRANSPORT_ATS_ResultCallback res_cb) 516 GNUNET_TRANSPORT_ATS_ResultCallback res_cb)
522{ 517{
@@ -561,10 +556,9 @@ ats_init (double D,
561 * @return GNUNET_SYSERR if glpk is not available, number of mechanisms used 556 * @return GNUNET_SYSERR if glpk is not available, number of mechanisms used
562 */ 557 */
563int 558int
564ats_create_problem (struct ATS_Handle *ats, 559ats_create_problem (struct ATS_Handle *ats, struct ATS_internals *stat,
565 struct ATS_internals *stat, 560 struct ATS_peer *peers, int c_p,
566 struct ATS_peer *peers, 561 struct ATS_mechanism *mechanisms, int c_m)
567 int c_p, struct ATS_mechanism *mechanisms, int c_m)
568{ 562{
569 if ((c_p == 0) || (c_m == 0)) 563 if ((c_p == 0) || (c_m == 0))
570 return GNUNET_SYSERR; 564 return GNUNET_SYSERR;
@@ -591,8 +585,9 @@ ats_create_problem (struct ATS_Handle *ats,
591 c_p, c_m, c_c_ressources, c_q_metrics); 585 c_p, c_m, c_c_ressources, c_q_metrics);
592#endif 586#endif
593 587
594 int size = 1 + 3 + 10 * c_m + c_p + 588 int size =
595 (c_q_metrics * c_m) + c_q_metrics + c_c_ressources * c_m; 589 1 + 3 + 10 * c_m + c_p + (c_q_metrics * c_m) + c_q_metrics +
590 c_c_ressources * c_m;
596 int row_index; 591 int row_index;
597 int array_index = 1; 592 int array_index = 1;
598 int *ia = GNUNET_malloc (size * sizeof (int)); 593 int *ia = GNUNET_malloc (size * sizeof (int));
@@ -609,8 +604,8 @@ ats_create_problem (struct ATS_Handle *ats,
609 /* adding b_t cols */ 604 /* adding b_t cols */
610 for (c = 1; c <= c_m; c++) 605 for (c = 1; c <= c_m; c++)
611 { 606 {
612 GNUNET_asprintf (&name, 607 GNUNET_asprintf (&name, "p_%s_b%i",
613 "p_%s_b%i", GNUNET_i2s (&(mechanisms[c].peer->peer)), c); 608 GNUNET_i2s (&(mechanisms[c].peer->peer)), c);
614 _lp_set_col_name (ats->prob, c, name); 609 _lp_set_col_name (ats->prob, c, name);
615 GNUNET_free (name); 610 GNUNET_free (name);
616 _lp_set_col_bnds (ats->prob, c, GLP_LO, 0.0, 0.0); 611 _lp_set_col_bnds (ats->prob, c, GLP_LO, 0.0, 0.0);
@@ -621,9 +616,8 @@ ats_create_problem (struct ATS_Handle *ats,
621 /* adding n_t cols */ 616 /* adding n_t cols */
622 for (c = c_m + 1; c <= 2 * c_m; c++) 617 for (c = c_m + 1; c <= 2 * c_m; c++)
623 { 618 {
624 GNUNET_asprintf (&name, 619 GNUNET_asprintf (&name, "p_%s_n%i",
625 "p_%s_n%i", GNUNET_i2s (&(mechanisms[c - c_m].peer->peer)), 620 GNUNET_i2s (&(mechanisms[c - c_m].peer->peer)), (c - c_m));
626 (c - c_m));
627 _lp_set_col_name (ats->prob, c, name); 621 _lp_set_col_name (ats->prob, c, name);
628 GNUNET_free (name); 622 GNUNET_free (name);
629 _lp_set_col_bnds (ats->prob, c, GLP_DB, 0.0, 1.0); 623 _lp_set_col_bnds (ats->prob, c, GLP_DB, 0.0, 1.0);
@@ -653,8 +647,8 @@ ats_create_problem (struct ATS_Handle *ats,
653 ar[array_index] = 1; 647 ar[array_index] = 1;
654#if VERBOSE_ATS 648#if VERBOSE_ATS
655 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 649 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
656 array_index, 650 array_index, ia[array_index], ja[array_index],
657 ia[array_index], ja[array_index], ar[array_index]); 651 ar[array_index]);
658#endif 652#endif
659 array_index++; 653 array_index++;
660 m = m->next; 654 m = m->next;
@@ -754,8 +748,8 @@ ats_create_problem (struct ATS_Handle *ats,
754 ar[array_index] = value; 748 ar[array_index] = value;
755#if VERBOSE_ATS 749#if VERBOSE_ATS
756 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 750 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
757 array_index, ia[array_index], 751 array_index, ia[array_index], ja[array_index],
758 ja[array_index], ar[array_index]); 752 ar[array_index]);
759#endif 753#endif
760 array_index++; 754 array_index++;
761 } 755 }
@@ -893,9 +887,8 @@ ats_create_problem (struct ATS_Handle *ats,
893 ar[array_index] = (mechanisms[c2].peer->f) * value; 887 ar[array_index] = (mechanisms[c2].peer->f) * value;
894#if VERBOSE_ATS 888#if VERBOSE_ATS
895 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: %s [%i,%i]=%f \n", 889 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: %s [%i,%i]=%f \n",
896 array_index, 890 array_index, qm[c - 1].name, ia[array_index], ja[array_index],
897 qm[c - 1].name, 891 ar[array_index]);
898 ia[array_index], ja[array_index], ar[array_index]);
899#endif 892#endif
900 array_index++; 893 array_index++;
901 } 894 }
@@ -970,8 +963,8 @@ ats_create_problem (struct ATS_Handle *ats,
970 ar[array_index] = 1 / mechanisms[c].peer->f; 963 ar[array_index] = 1 / mechanisms[c].peer->f;
971#if VERBOSE_ATS 964#if VERBOSE_ATS
972 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 965 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
973 array_index, 966 array_index, ia[array_index], ja[array_index],
974 ia[array_index], ja[array_index], ar[array_index]); 967 ar[array_index]);
975#endif 968#endif
976 array_index++; 969 array_index++;
977 m = m->next; 970 m = m->next;
@@ -1076,10 +1069,8 @@ ats_modify_problem_state (struct ATS_Handle *ats, enum ATS_problem_state s)
1076} 1069}
1077 1070
1078void 1071void
1079ats_solve_problem (struct ATS_Handle *ats, 1072ats_solve_problem (struct ATS_Handle *ats, unsigned int max_it,
1080 unsigned int max_it, 1073 unsigned int max_dur, unsigned int c_peers,
1081 unsigned int max_dur,
1082 unsigned int c_peers,
1083 unsigned int c_mechs, struct ATS_internals *stat) 1074 unsigned int c_mechs, struct ATS_internals *stat)
1084{ 1075{
1085 int result = GNUNET_SYSERR; 1076 int result = GNUNET_SYSERR;
@@ -1127,8 +1118,8 @@ ats_solve_problem (struct ATS_Handle *ats,
1127 lp_solution = _lp_get_status (ats->prob); 1118 lp_solution = _lp_get_status (ats->prob);
1128 1119
1129 // TODO: Remove if this does not appear until release 1120 // TODO: Remove if this does not appear until release
1130 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "" 1121 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1131 "EXECUTED SIMPLEX WITH PRESOLVER! %i \n", lp_solution); 1122 "" "EXECUTED SIMPLEX WITH PRESOLVER! %i \n", lp_solution);
1132 1123
1133 if (ats_evaluate_results (result, lp_solution, "LP") != GNUNET_YES) 1124 if (ats_evaluate_results (result, lp_solution, "LP") != GNUNET_YES)
1134 { 1125 {
@@ -1136,10 +1127,8 @@ ats_solve_problem (struct ATS_Handle *ats,
1136 "After execution simplex with presolver: STILL INVALID!\n"); 1127 "After execution simplex with presolver: STILL INVALID!\n");
1137 char *filename; 1128 char *filename;
1138 1129
1139 GNUNET_asprintf (&filename, 1130 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i_%llu.mlp",
1140 "ats_mlp_p%i_m%i_%llu.mlp", 1131 ats->internal.c_peers, ats->internal.c_mechs,
1141 ats->internal.c_peers,
1142 ats->internal.c_mechs,
1143 GNUNET_TIME_absolute_get ().abs_value); 1132 GNUNET_TIME_absolute_get ().abs_value);
1144 _lp_write_lp ((void *) ats->prob, NULL, filename); 1133 _lp_write_lp ((void *) ats->prob, NULL, filename);
1145 GNUNET_free (filename); 1134 GNUNET_free (filename);
@@ -1227,10 +1216,12 @@ ats_update_problem_qm (struct ATS_Handle *ats)
1227 int c, c2; 1216 int c, c2;
1228 int c_q_metrics = available_quality_metrics; 1217 int c_q_metrics = available_quality_metrics;
1229 1218
1230 int *ja = GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 + 1219 int *ja =
1231 available_quality_metrics) * sizeof (int)); 1220 GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 +
1232 double *ar = GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 + 1221 available_quality_metrics) * sizeof (int));
1233 available_quality_metrics) * sizeof (double)); 1222 double *ar =
1223 GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 +
1224 available_quality_metrics) * sizeof (double));
1234#if DEBUG_ATS 1225#if DEBUG_ATS
1235 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating problem quality metrics\n"); 1226 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating problem quality metrics\n");
1236#endif 1227#endif
@@ -1289,8 +1280,8 @@ ats_update_problem_qm (struct ATS_Handle *ats)
1289 ar[array_index] = (ats->mechanisms[c2].peer->f) * value; 1280 ar[array_index] = (ats->mechanisms[c2].peer->f) * value;
1290#if VERBOSE_ATS 1281#if VERBOSE_ATS
1291 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: %s [%i,%i]=%f \n", 1282 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: %s [%i,%i]=%f \n",
1292 array_index, 1283 array_index, qm[c - 1].name, row_index, ja[array_index],
1293 qm[c - 1].name, row_index, ja[array_index], ar[array_index]); 1284 ar[array_index]);
1294#endif 1285#endif
1295 array_index++; 1286 array_index++;
1296 } 1287 }
@@ -1332,8 +1323,8 @@ ats_calculate_bandwidth_distribution (struct ATS_Handle *ats)
1332 1323
1333 ats->internal.simplex_rerun_required = GNUNET_NO; 1324 ats->internal.simplex_rerun_required = GNUNET_NO;
1334 start = GNUNET_TIME_absolute_get (); 1325 start = GNUNET_TIME_absolute_get ();
1335 if ((ats->internal.recreate_problem == GNUNET_YES) || 1326 if ((ats->internal.recreate_problem == GNUNET_YES) || (ats->prob == NULL) ||
1336 (ats->prob == NULL) || (ats->internal.valid == GNUNET_NO)) 1327 (ats->internal.valid == GNUNET_NO))
1337 { 1328 {
1338 text = "new"; 1329 text = "new";
1339 ats->internal.recreate_problem = GNUNET_YES; 1330 ats->internal.recreate_problem = GNUNET_YES;
@@ -1381,10 +1372,8 @@ ats_calculate_bandwidth_distribution (struct ATS_Handle *ats)
1381 ats->internal.solution = GLP_UNDEF; 1372 ats->internal.solution = GLP_UNDEF;
1382 if (ats->internal.valid == GNUNET_YES) 1373 if (ats->internal.valid == GNUNET_YES)
1383 { 1374 {
1384 ats_solve_problem (ats, 1375 ats_solve_problem (ats, ats->max_iterations,
1385 ats->max_iterations, 1376 ats->max_exec_duration.rel_value, ats->internal.c_peers,
1386 ats->max_exec_duration.rel_value,
1387 ats->internal.c_peers,
1388 ats->internal.c_mechs, &ats->internal); 1377 ats->internal.c_mechs, &ats->internal);
1389 } 1378 }
1390 solving = 1379 solving =
@@ -1402,11 +1391,8 @@ ats_calculate_bandwidth_distribution (struct ATS_Handle *ats)
1402#endif 1391#endif
1403 GNUNET_log (msg_type, 1392 GNUNET_log (msg_type,
1404 "MLP %s: creation time: %llu, execution time: %llu, %i peers, %i mechanisms, simplex rerun: %s, solution %s\n", 1393 "MLP %s: creation time: %llu, execution time: %llu, %i peers, %i mechanisms, simplex rerun: %s, solution %s\n",
1405 text, 1394 text, creation.rel_value, solving.rel_value,
1406 creation.rel_value, 1395 ats->internal.c_peers, ats->internal.c_mechs,
1407 solving.rel_value,
1408 ats->internal.c_peers,
1409 ats->internal.c_mechs,
1410 (ats->internal.simplex_rerun_required == 1396 (ats->internal.simplex_rerun_required ==
1411 GNUNET_NO) ? "NO" : "YES", 1397 GNUNET_NO) ? "NO" : "YES",
1412 (ats->internal.solution == 5) ? "OPTIMAL" : "INVALID"); 1398 (ats->internal.solution == 5) ? "OPTIMAL" : "INVALID");
@@ -1449,9 +1435,8 @@ ats_calculate_bandwidth_distribution (struct ATS_Handle *ats)
1449 } 1435 }
1450 } 1436 }
1451 1437
1452 GNUNET_STATISTICS_set (ats->stats, 1438 GNUNET_STATISTICS_set (ats->stats, "ATS duration",
1453 "ATS duration", solving.rel_value + creation.rel_value, 1439 solving.rel_value + creation.rel_value, GNUNET_NO);
1454 GNUNET_NO);
1455 GNUNET_STATISTICS_set (ats->stats, "ATS mechanisms", ats->internal.c_mechs, 1440 GNUNET_STATISTICS_set (ats->stats, "ATS mechanisms", ats->internal.c_mechs,
1456 GNUNET_NO); 1441 GNUNET_NO);
1457 GNUNET_STATISTICS_set (ats->stats, "ATS peers", ats->internal.c_peers, 1442 GNUNET_STATISTICS_set (ats->stats, "ATS peers", ats->internal.c_peers,
@@ -1470,15 +1455,14 @@ ats_calculate_bandwidth_distribution (struct ATS_Handle *ats)
1470 if (ats->dump_overwrite == GNUNET_NO) 1455 if (ats->dump_overwrite == GNUNET_NO)
1471 { 1456 {
1472 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i_%s_%llu.mlp", 1457 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i_%s_%llu.mlp",
1473 ats->internal.c_peers, 1458 ats->internal.c_peers, ats->internal.c_mechs, text,
1474 ats->internal.c_mechs, 1459 GNUNET_TIME_absolute_get ().abs_value);
1475 text, GNUNET_TIME_absolute_get ().abs_value);
1476 _lp_write_lp ((void *) ats->prob, NULL, filename); 1460 _lp_write_lp ((void *) ats->prob, NULL, filename);
1477 } 1461 }
1478 else 1462 else
1479 { 1463 {
1480 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i.mlp", 1464 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i.mlp", ats->internal.c_peers,
1481 ats->internal.c_peers, ats->internal.c_mechs); 1465 ats->internal.c_mechs);
1482 _lp_write_lp ((void *) ats->prob, NULL, filename); 1466 _lp_write_lp ((void *) ats->prob, NULL, filename);
1483 } 1467 }
1484 GNUNET_free (filename); 1468 GNUNET_free (filename);
@@ -1492,15 +1476,14 @@ ats_calculate_bandwidth_distribution (struct ATS_Handle *ats)
1492 if (ats->dump_overwrite == GNUNET_NO) 1476 if (ats->dump_overwrite == GNUNET_NO)
1493 { 1477 {
1494 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i_%s_%llu.sol", 1478 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i_%s_%llu.sol",
1495 ats->internal.c_peers, 1479 ats->internal.c_peers, ats->internal.c_mechs, text,
1496 ats->internal.c_mechs, 1480 GNUNET_TIME_absolute_get ().abs_value);
1497 text, GNUNET_TIME_absolute_get ().abs_value);
1498 _lp_print_sol (ats->prob, filename); 1481 _lp_print_sol (ats->prob, filename);
1499 } 1482 }
1500 else 1483 else
1501 { 1484 {
1502 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i.sol", 1485 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i.sol", ats->internal.c_peers,
1503 ats->internal.c_peers, ats->internal.c_mechs); 1486 ats->internal.c_mechs);
1504 _lp_print_sol (ats->prob, filename); 1487 _lp_print_sol (ats->prob, filename);
1505 } 1488 }
1506 GNUNET_free (filename); 1489 GNUNET_free (filename);
@@ -1545,8 +1528,8 @@ ats_evaluate_results (int result, int solution, char *problem)
1545 break; 1528 break;
1546 case GLP_EITLIM: /* iteration limit exceeded */ 1529 case GLP_EITLIM: /* iteration limit exceeded */
1547#if DEBUG_ATS || VERBOSE_ATS 1530#if DEBUG_ATS || VERBOSE_ATS
1548 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1531 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s Iteration limit exceeded\n",
1549 "%s Iteration limit exceeded\n", problem); 1532 problem);
1550#endif 1533#endif
1551 break; 1534 break;
1552 case GLP_ETMLIM: /* time limit exceeded */ 1535 case GLP_ETMLIM: /* time limit exceeded */
@@ -1602,8 +1585,8 @@ ats_evaluate_results (int result, int solution, char *problem)
1602 break; 1585 break;
1603 case GLP_NOFEAS: 1586 case GLP_NOFEAS:
1604#if DEBUG_ATS || VERBOSE_ATS 1587#if DEBUG_ATS || VERBOSE_ATS
1605 GNUNET_log (error_kind, "%s problem has no %sfeasible solution\n", 1588 GNUNET_log (error_kind, "%s problem has no %sfeasible solution\n", problem,
1606 problem, (0 == strcmp (problem, "LP") ? "" : "integer ")); 1589 (0 == strcmp (problem, "LP") ? "" : "integer "));
1607#endif 1590#endif
1608 break; 1591 break;
1609 case GLP_INFEAS: 1592 case GLP_INFEAS:
@@ -1629,10 +1612,12 @@ ats_update_problem_cr (struct ATS_Handle *ats)
1629 int c, c2; 1612 int c, c2;
1630 double ct_max, ct_min; 1613 double ct_max, ct_min;
1631 1614
1632 int *ja = GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 + 1615 int *ja =
1633 available_quality_metrics) * sizeof (int)); 1616 GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 +
1634 double *ar = GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 + 1617 available_quality_metrics) * sizeof (int));
1635 available_quality_metrics) * sizeof (double)); 1618 double *ar =
1619 GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 +
1620 available_quality_metrics) * sizeof (double));
1636 1621
1637 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating problem quality metrics\n"); 1622 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating problem quality metrics\n");
1638 row_index = ats->internal.begin_cr; 1623 row_index = ats->internal.begin_cr;
@@ -1685,23 +1670,19 @@ ats_set_logging_options (struct ATS_Handle *ats,
1685 1670
1686 if (ats == NULL) 1671 if (ats == NULL)
1687 return; 1672 return;
1688 log_problem = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1673 log_problem =
1689 "transport", "DUMP_MLP"); 1674 GNUNET_CONFIGURATION_get_value_yesno (cfg, "transport", "DUMP_MLP");
1690 log_solution = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1675 log_solution =
1691 "transport", 1676 GNUNET_CONFIGURATION_get_value_yesno (cfg, "transport", "DUMP_SOLUTION");
1692 "DUMP_SOLUTION"); 1677 overwrite_dump =
1693 overwrite_dump = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1678 GNUNET_CONFIGURATION_get_value_yesno (cfg, "transport", "DUMP_OVERWRITE");
1694 "transport",
1695 "DUMP_OVERWRITE");
1696 if (GNUNET_OK == 1679 if (GNUNET_OK ==
1697 GNUNET_CONFIGURATION_get_value_number (cfg, 1680 GNUNET_CONFIGURATION_get_value_number (cfg, "transport", "DUMP_MIN_PEERS",
1698 "transport", 1681 &value))
1699 "DUMP_MIN_PEERS", &value))
1700 minimum_peers = (int) value; 1682 minimum_peers = (int) value;
1701 if (GNUNET_OK == 1683 if (GNUNET_OK ==
1702 GNUNET_CONFIGURATION_get_value_number (cfg, 1684 GNUNET_CONFIGURATION_get_value_number (cfg, "transport", "DUMP_MIN_ADDRS",
1703 "transport", 1685 &value))
1704 "DUMP_MIN_ADDRS", &value))
1705 minimum_addresses = (int) value; 1686 minimum_addresses = (int) value;
1706 1687
1707 1688
@@ -1725,10 +1706,12 @@ ats_update_problem_qm_TEST ()
1725 int old_ja[ats->internal.c_mechs + 2]; 1706 int old_ja[ats->internal.c_mechs + 2];
1726 double old_ar[ats->internal.c_mechs + 2]; 1707 double old_ar[ats->internal.c_mechs + 2];
1727 1708
1728 int *ja = GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 + 1709 int *ja =
1729 available_quality_metrics) * sizeof (int)); 1710 GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 +
1730 double *ar = GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 + 1711 available_quality_metrics) * sizeof (int));
1731 available_quality_metrics) * sizeof (double)); 1712 double *ar =
1713 GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 +
1714 available_quality_metrics) * sizeof (double));
1732#if DEBUG_ATS 1715#if DEBUG_ATS
1733 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1716 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1734 "Updating problem quality metrics TEST\n"); 1717 "Updating problem quality metrics TEST\n");
@@ -1753,8 +1736,7 @@ ats_update_problem_qm_TEST ()
1753 ar[c2] = old_ar[c2]; 1736 ar[c2] = old_ar[c2];
1754#if VERBOSE_ATS 1737#if VERBOSE_ATS
1755 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1738 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1756 "[index]=[%i]: old [%i,%i]=%f new [%i,%i]=%f\n", 1739 "[index]=[%i]: old [%i,%i]=%f new [%i,%i]=%f\n", c2,
1757 c2,
1758 row_index, old_ja[c2], old_ar[c2], row_index, ja[c2], ar[c2]); 1740 row_index, old_ja[c2], old_ar[c2], row_index, ja[c2], ar[c2]);
1759#endif 1741#endif
1760 } 1742 }
diff --git a/src/transport/gnunet-service-transport_blacklist.c b/src/transport/gnunet-service-transport_blacklist.c
index 7720e467f..abb536414 100644
--- a/src/transport/gnunet-service-transport_blacklist.c
+++ b/src/transport/gnunet-service-transport_blacklist.c
@@ -161,8 +161,8 @@ static struct GNUNET_CONTAINER_MultiHashMap *blacklist;
161 * @param cls the 'struct BlacklistCheck*' 161 * @param cls the 'struct BlacklistCheck*'
162 * @param tc unused 162 * @param tc unused
163 */ 163 */
164static void 164static void do_blacklist_check (void *cls,
165do_blacklist_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 165 const struct GNUNET_SCHEDULER_TaskContext *tc);
166 166
167 167
168/** 168/**
@@ -227,8 +227,7 @@ read_blacklist_file ()
227 char *transport_name; 227 char *transport_name;
228 228
229 if (GNUNET_OK != 229 if (GNUNET_OK !=
230 GNUNET_CONFIGURATION_get_value_filename (GST_cfg, 230 GNUNET_CONFIGURATION_get_value_filename (GST_cfg, "TRANSPORT",
231 "TRANSPORT",
232 "BLACKLIST_FILE", &fn)) 231 "BLACKLIST_FILE", &fn))
233 { 232 {
234#if DEBUG_TRANSPORT 233#if DEBUG_TRANSPORT
@@ -252,8 +251,8 @@ read_blacklist_file ()
252 if (frstat.st_size == 0) 251 if (frstat.st_size == 0)
253 { 252 {
254#if DEBUG_TRANSPORT 253#if DEBUG_TRANSPORT
255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 254 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Blacklist file `%s' is empty.\n"),
256 _("Blacklist file `%s' is empty.\n"), fn); 255 fn);
257#endif 256#endif
258 GNUNET_free (fn); 257 GNUNET_free (fn);
259 return; 258 return;
@@ -278,8 +277,7 @@ read_blacklist_file ()
278 frstat.st_size - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded))) 277 frstat.st_size - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)))
279 { 278 {
280 colon_pos = pos; 279 colon_pos = pos;
281 while ((colon_pos < frstat.st_size) && 280 while ((colon_pos < frstat.st_size) && (data[colon_pos] != ':') &&
282 (data[colon_pos] != ':') &&
283 (!isspace ((unsigned char) data[colon_pos]))) 281 (!isspace ((unsigned char) data[colon_pos])))
284 colon_pos++; 282 colon_pos++;
285 if (colon_pos >= frstat.st_size) 283 if (colon_pos >= frstat.st_size)
@@ -330,8 +328,8 @@ read_blacklist_file ()
330#endif 328#endif
331 memcpy (&enc, &data[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); 329 memcpy (&enc, &data[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
332 if (!isspace 330 if (!isspace
333 ((unsigned char) 331 ((unsigned char) enc.
334 enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1])) 332 encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1]))
335 { 333 {
336 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 334 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
337 _ 335 _
@@ -354,8 +352,8 @@ read_blacklist_file ()
354 } 352 }
355 else 353 else
356 { 354 {
357 if (0 != memcmp (&pid, 355 if (0 !=
358 &GST_my_identity, sizeof (struct GNUNET_PeerIdentity))) 356 memcmp (&pid, &GST_my_identity, sizeof (struct GNUNET_PeerIdentity)))
359 { 357 {
360 entries_found++; 358 entries_found++;
361 GST_blacklist_add_peer (&pid, transport_name); 359 GST_blacklist_add_peer (&pid, transport_name);
@@ -372,8 +370,7 @@ read_blacklist_file ()
372 while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos])) 370 while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos]))
373 pos++; 371 pos++;
374 } 372 }
375 GNUNET_STATISTICS_update (GST_stats, 373 GNUNET_STATISTICS_update (GST_stats, "# Transport entries blacklisted",
376 "# Transport entries blacklisted",
377 entries_found, GNUNET_NO); 374 entries_found, GNUNET_NO);
378 GNUNET_free (data); 375 GNUNET_free (data);
379 GNUNET_free (fn); 376 GNUNET_free (fn);
@@ -389,8 +386,8 @@ void
389GST_blacklist_start (struct GNUNET_SERVER_Handle *server) 386GST_blacklist_start (struct GNUNET_SERVER_Handle *server)
390{ 387{
391 read_blacklist_file (); 388 read_blacklist_file ();
392 GNUNET_SERVER_disconnect_notify (server, 389 GNUNET_SERVER_disconnect_notify (server, &client_disconnect_notification,
393 &client_disconnect_notification, NULL); 390 NULL);
394} 391}
395 392
396 393
@@ -420,8 +417,8 @@ GST_blacklist_stop ()
420{ 417{
421 if (NULL != blacklist) 418 if (NULL != blacklist)
422 { 419 {
423 GNUNET_CONTAINER_multihashmap_iterate (blacklist, 420 GNUNET_CONTAINER_multihashmap_iterate (blacklist, &free_blacklist_entry,
424 &free_blacklist_entry, NULL); 421 NULL);
425 GNUNET_CONTAINER_multihashmap_destroy (blacklist); 422 GNUNET_CONTAINER_multihashmap_destroy (blacklist);
426 blacklist = NULL; 423 blacklist = NULL;
427 } 424 }
@@ -498,12 +495,11 @@ do_blacklist_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
498 if ((bl->bc != NULL) || (bl->waiting_for_reply != GNUNET_NO)) 495 if ((bl->bc != NULL) || (bl->waiting_for_reply != GNUNET_NO))
499 return; /* someone else busy with this client */ 496 return; /* someone else busy with this client */
500 bl->bc = bc; 497 bl->bc = bc;
501 bc->th = GNUNET_SERVER_notify_transmit_ready (bl->client, 498 bc->th =
502 sizeof (struct 499 GNUNET_SERVER_notify_transmit_ready (bl->client,
503 BlacklistMessage), 500 sizeof (struct BlacklistMessage),
504 GNUNET_TIME_UNIT_FOREVER_REL, 501 GNUNET_TIME_UNIT_FOREVER_REL,
505 &transmit_blacklist_message, 502 &transmit_blacklist_message, bc);
506 bc);
507} 503}
508 504
509 505
@@ -517,14 +513,14 @@ do_blacklist_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
517 * GNUNET_NO if we must shutdown the connection 513 * GNUNET_NO if we must shutdown the connection
518 */ 514 */
519static void 515static void
520confirm_or_drop_neighbour (void *cls, 516confirm_or_drop_neighbour (void *cls, const struct GNUNET_PeerIdentity *peer,
521 const struct GNUNET_PeerIdentity *peer, int allowed) 517 int allowed)
522{ 518{
523 if (GNUNET_OK == allowed) 519 if (GNUNET_OK == allowed)
524 return; /* we're done */ 520 return; /* we're done */
525 GNUNET_STATISTICS_update (GST_stats, 521 GNUNET_STATISTICS_update (GST_stats,
526 gettext_noop ("# disconnects due to blacklist"), 522 gettext_noop ("# disconnects due to blacklist"), 1,
527 1, GNUNET_NO); 523 GNUNET_NO);
528 GST_neighbours_force_disconnect (peer); 524 GST_neighbours_force_disconnect (peer);
529} 525}
530 526
@@ -556,8 +552,7 @@ struct TestConnectionContext
556 * @param ats_count number of entries in ats (excluding 0-termination) 552 * @param ats_count number of entries in ats (excluding 0-termination)
557 */ 553 */
558static void 554static void
559test_connection_ok (void *cls, 555test_connection_ok (void *cls, const struct GNUNET_PeerIdentity *neighbour,
560 const struct GNUNET_PeerIdentity *neighbour,
561 const struct GNUNET_TRANSPORT_ATS_Information *ats, 556 const struct GNUNET_TRANSPORT_ATS_Information *ats,
562 uint32_t ats_count) 557 uint32_t ats_count)
563{ 558{
@@ -591,8 +586,7 @@ test_connection_ok (void *cls,
591 * @param message the blacklist-init message that was sent 586 * @param message the blacklist-init message that was sent
592 */ 587 */
593void 588void
594GST_blacklist_handle_init (void *cls, 589GST_blacklist_handle_init (void *cls, struct GNUNET_SERVER_Client *client,
595 struct GNUNET_SERVER_Client *client,
596 const struct GNUNET_MessageHeader *message) 590 const struct GNUNET_MessageHeader *message)
597{ 591{
598 struct Blacklisters *bl; 592 struct Blacklisters *bl;
@@ -629,8 +623,7 @@ GST_blacklist_handle_init (void *cls,
629 * @param message the blacklist-init message that was sent 623 * @param message the blacklist-init message that was sent
630 */ 624 */
631void 625void
632GST_blacklist_handle_reply (void *cls, 626GST_blacklist_handle_reply (void *cls, struct GNUNET_SERVER_Client *client,
633 struct GNUNET_SERVER_Client *client,
634 const struct GNUNET_MessageHeader *message) 627 const struct GNUNET_MessageHeader *message)
635{ 628{
636 const struct BlacklistMessage *msg = 629 const struct BlacklistMessage *msg =
@@ -752,8 +745,7 @@ GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
752 745
753 if ((blacklist != NULL) && 746 if ((blacklist != NULL) &&
754 (GNUNET_SYSERR == 747 (GNUNET_SYSERR ==
755 GNUNET_CONTAINER_multihashmap_get_multiple (blacklist, 748 GNUNET_CONTAINER_multihashmap_get_multiple (blacklist, &peer->hashPubKey,
756 &peer->hashPubKey,
757 &test_blacklisted, 749 &test_blacklisted,
758 (void *) transport_name))) 750 (void *) transport_name)))
759 { 751 {
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c
index 542e3e00b..3ad2149bb 100644
--- a/src/transport/gnunet-service-transport_clients.c
+++ b/src/transport/gnunet-service-transport_clients.c
@@ -205,8 +205,8 @@ transmit_to_client_callback (void *cls, size_t size, void *buf)
205 "Transmitting message of type %u to client.\n", 205 "Transmitting message of type %u to client.\n",
206 ntohs (msg->type)); 206 ntohs (msg->type));
207#endif 207#endif
208 GNUNET_CONTAINER_DLL_remove (tc->message_queue_head, 208 GNUNET_CONTAINER_DLL_remove (tc->message_queue_head, tc->message_queue_tail,
209 tc->message_queue_tail, q); 209 q);
210 tc->message_count--; 210 tc->message_count--;
211 memcpy (&cbuf[tsize], msg, msize); 211 memcpy (&cbuf[tsize], msg, msize);
212 GNUNET_free (q); 212 GNUNET_free (q);
@@ -215,11 +215,10 @@ transmit_to_client_callback (void *cls, size_t size, void *buf)
215 if (NULL != q) 215 if (NULL != q)
216 { 216 {
217 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader)); 217 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
218 tc->th = GNUNET_SERVER_notify_transmit_ready (tc->client, 218 tc->th =
219 msize, 219 GNUNET_SERVER_notify_transmit_ready (tc->client, msize,
220 GNUNET_TIME_UNIT_FOREVER_REL, 220 GNUNET_TIME_UNIT_FOREVER_REL,
221 &transmit_to_client_callback, 221 &transmit_to_client_callback, tc);
222 tc);
223 GNUNET_assert (tc->th != NULL); 222 GNUNET_assert (tc->th != NULL);
224 } 223 }
225 return tsize; 224 return tsize;
@@ -234,8 +233,8 @@ transmit_to_client_callback (void *cls, size_t size, void *buf)
234 * @param may_drop GNUNET_YES if the message can be dropped 233 * @param may_drop GNUNET_YES if the message can be dropped
235 */ 234 */
236static void 235static void
237unicast (struct TransportClient *tc, 236unicast (struct TransportClient *tc, const struct GNUNET_MessageHeader *msg,
238 const struct GNUNET_MessageHeader *msg, int may_drop) 237 int may_drop)
239{ 238{
240 struct ClientMessageQueueEntry *q; 239 struct ClientMessageQueueEntry *q;
241 uint16_t msize; 240 uint16_t msize;
@@ -262,11 +261,10 @@ unicast (struct TransportClient *tc,
262 tc->message_count++; 261 tc->message_count++;
263 if (tc->th != NULL) 262 if (tc->th != NULL)
264 return; 263 return;
265 tc->th = GNUNET_SERVER_notify_transmit_ready (tc->client, 264 tc->th =
266 msize, 265 GNUNET_SERVER_notify_transmit_ready (tc->client, msize,
267 GNUNET_TIME_UNIT_FOREVER_REL, 266 GNUNET_TIME_UNIT_FOREVER_REL,
268 &transmit_to_client_callback, 267 &transmit_to_client_callback, tc);
269 tc);
270 GNUNET_assert (tc->th != NULL); 268 GNUNET_assert (tc->th != NULL);
271} 269}
272 270
@@ -295,8 +293,8 @@ client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
295#endif 293#endif
296 while (NULL != (mqe = tc->message_queue_head)) 294 while (NULL != (mqe = tc->message_queue_head))
297 { 295 {
298 GNUNET_CONTAINER_DLL_remove (tc->message_queue_head, 296 GNUNET_CONTAINER_DLL_remove (tc->message_queue_head, tc->message_queue_tail,
299 tc->message_queue_tail, mqe); 297 mqe);
300 tc->message_count--; 298 tc->message_count--;
301 GNUNET_free (mqe); 299 GNUNET_free (mqe);
302 } 300 }
@@ -339,8 +337,8 @@ notify_client_about_neighbour (void *cls,
339 cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 337 cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
340 cim->ats_count = htonl (ats_count); 338 cim->ats_count = htonl (ats_count);
341 cim->id = *peer; 339 cim->id = *peer;
342 memcpy (&cim->ats, 340 memcpy (&cim->ats, ats,
343 ats, ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); 341 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
344 unicast (tc, &cim->header, GNUNET_NO); 342 unicast (tc, &cim->header, GNUNET_NO);
345 GNUNET_free (cim); 343 GNUNET_free (cim);
346} 344}
@@ -356,8 +354,7 @@ notify_client_about_neighbour (void *cls,
356 * @param message the start message that was sent 354 * @param message the start message that was sent
357 */ 355 */
358static void 356static void
359clients_handle_start (void *cls, 357clients_handle_start (void *cls, struct GNUNET_SERVER_Client *client,
360 struct GNUNET_SERVER_Client *client,
361 const struct GNUNET_MessageHeader *message) 358 const struct GNUNET_MessageHeader *message)
362{ 359{
363 const struct StartMessage *start; 360 const struct StartMessage *start;
@@ -373,8 +370,9 @@ clients_handle_start (void *cls,
373 } 370 }
374 start = (const struct StartMessage *) message; 371 start = (const struct StartMessage *) message;
375 if ((GNUNET_NO != ntohl (start->do_check)) && 372 if ((GNUNET_NO != ntohl (start->do_check)) &&
376 (0 != memcmp (&start->self, 373 (0 !=
377 &GST_my_identity, sizeof (struct GNUNET_PeerIdentity)))) 374 memcmp (&start->self, &GST_my_identity,
375 sizeof (struct GNUNET_PeerIdentity))))
378 { 376 {
379 /* client thinks this is a different peer, reject */ 377 /* client thinks this is a different peer, reject */
380 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 378 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -399,8 +397,7 @@ clients_handle_start (void *cls,
399 * @param message the HELLO message 397 * @param message the HELLO message
400 */ 398 */
401static void 399static void
402clients_handle_hello (void *cls, 400clients_handle_hello (void *cls, struct GNUNET_SERVER_Client *client,
403 struct GNUNET_SERVER_Client *client,
404 const struct GNUNET_MessageHeader *message) 401 const struct GNUNET_MessageHeader *message)
405{ 402{
406 GST_validation_handle_hello (message); 403 GST_validation_handle_hello (message);
@@ -458,8 +455,7 @@ handle_send_transmit_continuation (void *cls, int success)
458 * @param message the send message that was sent 455 * @param message the send message that was sent
459 */ 456 */
460static void 457static void
461clients_handle_send (void *cls, 458clients_handle_send (void *cls, struct GNUNET_SERVER_Client *client,
462 struct GNUNET_SERVER_Client *client,
463 const struct GNUNET_MessageHeader *message) 459 const struct GNUNET_MessageHeader *message)
464{ 460{
465 const struct OutboundMessage *obm; 461 const struct OutboundMessage *obm;
@@ -509,8 +505,7 @@ clients_handle_send (void *cls,
509 stcc->target = obm->peer; 505 stcc->target = obm->peer;
510 stcc->client = client; 506 stcc->client = client;
511 GNUNET_SERVER_client_keep (client); 507 GNUNET_SERVER_client_keep (client);
512 GST_neighbours_send (&obm->peer, 508 GST_neighbours_send (&obm->peer, obmm, msize,
513 obmm, msize,
514 GNUNET_TIME_relative_ntoh (obm->timeout), 509 GNUNET_TIME_relative_ntoh (obm->timeout),
515 &handle_send_transmit_continuation, stcc); 510 &handle_send_transmit_continuation, stcc);
516} 511}
@@ -526,8 +521,8 @@ clients_handle_send (void *cls,
526 * GNUNET_NO if not 521 * GNUNET_NO if not
527 */ 522 */
528static void 523static void
529try_connect_if_allowed (void *cls, 524try_connect_if_allowed (void *cls, const struct GNUNET_PeerIdentity *peer,
530 const struct GNUNET_PeerIdentity *peer, int result) 525 int result)
531{ 526{
532 if (GNUNET_OK != result) 527 if (GNUNET_OK != result)
533 return; /* not allowed */ 528 return; /* not allowed */
@@ -543,8 +538,7 @@ try_connect_if_allowed (void *cls,
543 * @param message the actual message 538 * @param message the actual message
544 */ 539 */
545static void 540static void
546clients_handle_request_connect (void *cls, 541clients_handle_request_connect (void *cls, struct GNUNET_SERVER_Client *client,
547 struct GNUNET_SERVER_Client *client,
548 const struct GNUNET_MessageHeader *message) 542 const struct GNUNET_MessageHeader *message)
549{ 543{
550 const struct TransportRequestConnectMessage *trcm = 544 const struct TransportRequestConnectMessage *trcm =
@@ -559,8 +553,8 @@ clients_handle_request_connect (void *cls,
559 "Received a request connect message for peer `%s'\n", 553 "Received a request connect message for peer `%s'\n",
560 GNUNET_i2s (&trcm->peer)); 554 GNUNET_i2s (&trcm->peer));
561#endif 555#endif
562 (void) GST_blacklist_test_allowed (&trcm->peer, NULL, 556 (void) GST_blacklist_test_allowed (&trcm->peer, NULL, &try_connect_if_allowed,
563 &try_connect_if_allowed, NULL); 557 NULL);
564 GNUNET_SERVER_receive_done (client, GNUNET_OK); 558 GNUNET_SERVER_receive_done (client, GNUNET_OK);
565} 559}
566 560
@@ -573,21 +567,19 @@ clients_handle_request_connect (void *cls,
573 * @param message the quota changing message 567 * @param message the quota changing message
574 */ 568 */
575static void 569static void
576clients_handle_set_quota (void *cls, 570clients_handle_set_quota (void *cls, struct GNUNET_SERVER_Client *client,
577 struct GNUNET_SERVER_Client *client,
578 const struct GNUNET_MessageHeader *message) 571 const struct GNUNET_MessageHeader *message)
579{ 572{
580 const struct QuotaSetMessage *qsm; 573 const struct QuotaSetMessage *qsm;
581 574
582 qsm = (const struct QuotaSetMessage *) message; 575 qsm = (const struct QuotaSetMessage *) message;
583 GNUNET_STATISTICS_update (GST_stats, 576 GNUNET_STATISTICS_update (GST_stats,
584 gettext_noop ("# SET QUOTA messages received"), 577 gettext_noop ("# SET QUOTA messages received"), 1,
585 1, GNUNET_NO); 578 GNUNET_NO);
586#if DEBUG_TRANSPORT 579#if DEBUG_TRANSPORT
587 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 580 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
588 "Received `%s' request (new quota %u) from client for peer `%4s'\n", 581 "Received `%s' request (new quota %u) from client for peer `%4s'\n",
589 "SET_QUOTA", 582 "SET_QUOTA", (unsigned int) ntohl (qsm->quota.value__),
590 (unsigned int) ntohl (qsm->quota.value__),
591 GNUNET_i2s (&qsm->peer)); 583 GNUNET_i2s (&qsm->peer));
592#endif 584#endif
593 GST_neighbours_set_incoming_quota (&qsm->peer, qsm->quota); 585 GST_neighbours_set_incoming_quota (&qsm->peer, qsm->quota);
@@ -614,8 +606,7 @@ transmit_address_to_client (void *cls, const char *address)
614 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); 606 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
615 return; 607 return;
616 } 608 }
617 GNUNET_SERVER_transmit_context_append_data (tc, 609 GNUNET_SERVER_transmit_context_append_data (tc, address, strlen (address) + 1,
618 address, strlen (address) + 1,
619 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); 610 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
620} 611}
621 612
@@ -628,8 +619,7 @@ transmit_address_to_client (void *cls, const char *address)
628 * @param message the resolution request 619 * @param message the resolution request
629 */ 620 */
630static void 621static void
631clients_handle_address_lookup (void *cls, 622clients_handle_address_lookup (void *cls, struct GNUNET_SERVER_Client *client,
632 struct GNUNET_SERVER_Client *client,
633 const struct GNUNET_MessageHeader *message) 623 const struct GNUNET_MessageHeader *message)
634{ 624{
635 const struct AddressLookupMessage *alum; 625 const struct AddressLookupMessage *alum;
@@ -659,8 +649,8 @@ clients_handle_address_lookup (void *cls,
659 } 649 }
660 address = (const char *) &alum[1]; 650 address = (const char *) &alum[1];
661 plugin_name = (const char *) &address[address_len]; 651 plugin_name = (const char *) &address[address_len];
662 if (plugin_name 652 if (plugin_name[size - sizeof (struct AddressLookupMessage) - address_len - 1]
663 [size - sizeof (struct AddressLookupMessage) - address_len - 1] != '\0') 653 != '\0')
664 { 654 {
665 GNUNET_break (0); 655 GNUNET_break (0);
666 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 656 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -678,11 +668,9 @@ clients_handle_address_lookup (void *cls,
678 return; 668 return;
679 } 669 }
680 GNUNET_SERVER_disable_receive_done_warning (client); 670 GNUNET_SERVER_disable_receive_done_warning (client);
681 papi->address_pretty_printer (papi->cls, 671 papi->address_pretty_printer (papi->cls, plugin_name, address, address_len,
682 plugin_name, 672 numeric, rtimeout, &transmit_address_to_client,
683 address, address_len, 673 tc);
684 numeric,
685 rtimeout, &transmit_address_to_client, tc);
686} 674}
687 675
688 676
@@ -714,12 +702,11 @@ send_address_to_client (void *cls,
714 702
715 /* FIXME: move to a binary format!!! */ 703 /* FIXME: move to a binary format!!! */
716 GNUNET_asprintf (&addr_buf, "%s --- %s, %s", 704 GNUNET_asprintf (&addr_buf, "%s --- %s, %s",
717 GST_plugins_a2s (plugin_name, 705 GST_plugins_a2s (plugin_name, plugin_address,
718 plugin_address,
719 plugin_address_len), 706 plugin_address_len),
720 (GNUNET_YES == GST_neighbours_test_connected (target)) 707 (GNUNET_YES ==
721 ? "CONNECTED" 708 GST_neighbours_test_connected (target)) ? "CONNECTED" :
722 : "DISCONNECTED", 709 "DISCONNECTED",
723 (GNUNET_TIME_absolute_get_remaining (valid_until).rel_value > 710 (GNUNET_TIME_absolute_get_remaining (valid_until).rel_value >
724 0) ? "VALIDATED" : "UNVALIDATED"); 711 0) ? "VALIDATED" : "UNVALIDATED");
725 transmit_address_to_client (tc, addr_buf); 712 transmit_address_to_client (tc, addr_buf);
@@ -749,8 +736,7 @@ clients_handle_peer_address_lookup (void *cls,
749 tc = GNUNET_SERVER_transmit_context_create (client); 736 tc = GNUNET_SERVER_transmit_context_create (client);
750 GST_validation_get_addresses (&peer_address_lookup->peer, 737 GST_validation_get_addresses (&peer_address_lookup->peer,
751 &send_address_to_client, tc); 738 &send_address_to_client, tc);
752 GNUNET_SERVER_transmit_context_append_data (tc, 739 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
753 NULL, 0,
754 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); 740 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
755 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); 741 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
756} 742}
@@ -765,8 +751,7 @@ clients_handle_peer_address_lookup (void *cls,
765 * @param ats_count number of entries in ats (excluding 0-termination) 751 * @param ats_count number of entries in ats (excluding 0-termination)
766 */ 752 */
767static void 753static void
768output_addresses (void *cls, 754output_addresses (void *cls, const struct GNUNET_PeerIdentity *neighbour,
769 const struct GNUNET_PeerIdentity *neighbour,
770 const struct GNUNET_TRANSPORT_ATS_Information *ats, 755 const struct GNUNET_TRANSPORT_ATS_Information *ats,
771 uint32_t ats_count) 756 uint32_t ats_count)
772{ 757{
@@ -774,9 +759,8 @@ output_addresses (void *cls,
774 char *addr_buf; 759 char *addr_buf;
775 760
776 /* FIXME: move to a binary format!!! */ 761 /* FIXME: move to a binary format!!! */
777 GNUNET_asprintf (&addr_buf, 762 GNUNET_asprintf (&addr_buf, "%s: %s", GNUNET_i2s (neighbour),
778 "%s: %s", 763 GST_plugins_a2s ("FIXME", NULL, 0));
779 GNUNET_i2s (neighbour), GST_plugins_a2s ("FIXME", NULL, 0));
780 transmit_address_to_client (tc, addr_buf); 764 transmit_address_to_client (tc, addr_buf);
781 GNUNET_free (addr_buf); 765 GNUNET_free (addr_buf);
782} 766}
@@ -791,8 +775,7 @@ output_addresses (void *cls,
791 * @param message the peer address information request 775 * @param message the peer address information request
792 */ 776 */
793static void 777static void
794clients_handle_address_iterate (void *cls, 778clients_handle_address_iterate (void *cls, struct GNUNET_SERVER_Client *client,
795 struct GNUNET_SERVER_Client *client,
796 const struct GNUNET_MessageHeader *message) 779 const struct GNUNET_MessageHeader *message)
797{ 780{
798 struct GNUNET_SERVER_TransmitContext *tc; 781 struct GNUNET_SERVER_TransmitContext *tc;
@@ -843,8 +826,8 @@ GST_clients_start (struct GNUNET_SERVER_Handle *server)
843 {NULL, NULL, 0, 0} 826 {NULL, NULL, 0, 0}
844 }; 827 };
845 GNUNET_SERVER_add_handlers (server, handlers); 828 GNUNET_SERVER_add_handlers (server, handlers);
846 GNUNET_SERVER_disconnect_notify (server, 829 GNUNET_SERVER_disconnect_notify (server, &client_disconnect_notification,
847 &client_disconnect_notification, NULL); 830 NULL);
848} 831}
849 832
850 833
diff --git a/src/transport/gnunet-service-transport_hello.c b/src/transport/gnunet-service-transport_hello.c
index a2d0d966c..3c51c5df2 100644
--- a/src/transport/gnunet-service-transport_hello.c
+++ b/src/transport/gnunet-service-transport_hello.c
@@ -141,10 +141,10 @@ address_generator (void *cls, size_t max, void *buf)
141 141
142 if (NULL == gc->addr_pos) 142 if (NULL == gc->addr_pos)
143 return 0; 143 return 0;
144 ret = GNUNET_HELLO_add_address (gc->addr_pos->plugin_name, 144 ret =
145 gc->expiration, 145 GNUNET_HELLO_add_address (gc->addr_pos->plugin_name, gc->expiration,
146 &gc->addr_pos[1], 146 &gc->addr_pos[1], gc->addr_pos->addrlen, buf,
147 gc->addr_pos->addrlen, buf, max); 147 max);
148 gc->addr_pos = gc->addr_pos->next; 148 gc->addr_pos = gc->addr_pos->next;
149 return ret; 149 return ret;
150} 150}
@@ -173,15 +173,14 @@ refresh_hello_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
173 "Refreshed my `%s', new size is %d\n", "HELLO", 173 "Refreshed my `%s', new size is %d\n", "HELLO",
174 GNUNET_HELLO_size (our_hello)); 174 GNUNET_HELLO_size (our_hello));
175#endif 175#endif
176 GNUNET_STATISTICS_update (GST_stats, 176 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# refreshed my HELLO"), 1,
177 gettext_noop ("# refreshed my HELLO"), 177 GNUNET_NO);
178 1, GNUNET_NO);
179 if (NULL != hello_cb) 178 if (NULL != hello_cb)
180 hello_cb (hello_cb_cls, GST_hello_get ()); 179 hello_cb (hello_cb_cls, GST_hello_get ());
181 GNUNET_PEERINFO_add_peer (GST_peerinfo, our_hello); 180 GNUNET_PEERINFO_add_peer (GST_peerinfo, our_hello);
182 hello_task 181 hello_task =
183 = GNUNET_SCHEDULER_add_delayed (HELLO_REFRESH_PERIOD, 182 GNUNET_SCHEDULER_add_delayed (HELLO_REFRESH_PERIOD, &refresh_hello_task,
184 &refresh_hello_task, NULL); 183 NULL);
185 184
186} 185}
187 186
@@ -257,8 +256,7 @@ GST_hello_get ()
257 * @param plugin_address_len number of bytes in plugin_address 256 * @param plugin_address_len number of bytes in plugin_address
258 */ 257 */
259void 258void
260GST_hello_modify_addresses (int addremove, 259GST_hello_modify_addresses (int addremove, const char *plugin_name,
261 const char *plugin_name,
262 const void *plugin_address, 260 const void *plugin_address,
263 size_t plugin_address_len) 261 size_t plugin_address_len)
264{ 262{
@@ -266,9 +264,9 @@ GST_hello_modify_addresses (int addremove,
266 264
267#if DEBUG_TRANSPORT 265#if DEBUG_TRANSPORT
268 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 266 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
269 (add_remove == GNUNET_YES) 267 (add_remove ==
270 ? "Adding `%s':%s to the set of our addresses\n" 268 GNUNET_YES) ? "Adding `%s':%s to the set of our addresses\n" :
271 : "Removing `%s':%s from the set of our addresses\n", 269 "Removing `%s':%s from the set of our addresses\n",
272 GST_plugins_a2s (plugin_name, addr, addrlen), p->short_name); 270 GST_plugins_a2s (plugin_name, addr, addrlen), p->short_name);
273#endif 271#endif
274 GNUNET_assert (plugin_address != NULL); 272 GNUNET_assert (plugin_address != NULL);
@@ -311,8 +309,7 @@ GST_hello_modify_addresses (int addremove,
311 * GNUNET_NO if not 309 * GNUNET_NO if not
312 */ 310 */
313int 311int
314GST_hello_test_address (const char *plugin_name, 312GST_hello_test_address (const char *plugin_name, const void *plugin_address,
315 const void *plugin_address,
316 size_t plugin_address_len, 313 size_t plugin_address_len,
317 struct GNUNET_CRYPTO_RsaSignature **sig, 314 struct GNUNET_CRYPTO_RsaSignature **sig,
318 struct GNUNET_TIME_Absolute **sig_expiration) 315 struct GNUNET_TIME_Absolute **sig_expiration)
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 386894d48..251b4c356 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -246,8 +246,8 @@ lookup_neighbour (const struct GNUNET_PeerIdentity *pid)
246 * @param cls the 'struct NeighbourMapEntry' 246 * @param cls the 'struct NeighbourMapEntry'
247 * @param tc scheduler context 247 * @param tc scheduler context
248 */ 248 */
249static void 249static void transmission_task (void *cls,
250transmission_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 250 const struct GNUNET_SCHEDULER_TaskContext *tc);
251 251
252 252
253/** 253/**
@@ -318,15 +318,11 @@ try_transmission_to_peer (struct NeighbourMapEntry *n)
318 GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq); 318 GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq);
319 n->is_active = mq; 319 n->is_active = mq;
320 mq->n = n; 320 mq->n = n;
321 ret = papi->send (papi->cls, 321 ret =
322 &n->id, 322 papi->send (papi->cls, &n->id, mq->message_buf, mq->message_buf_size,
323 mq->message_buf, 323 0 /* priority -- remove from plugin API? */ ,
324 mq->message_buf_size, 324 timeout, n->session, n->addr, n->addrlen, GNUNET_YES,
325 0 /* priority -- remove from plugin API? */ , 325 &transmit_send_continuation, mq);
326 timeout,
327 n->session,
328 n->addr,
329 n->addrlen, GNUNET_YES, &transmit_send_continuation, mq);
330 if (ret == -1) 326 if (ret == -1)
331 { 327 {
332 /* failure, but 'send' would not call continuation in this case, 328 /* failure, but 'send' would not call continuation in this case,
@@ -361,8 +357,7 @@ transmission_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
361 * @param disconnect_cb function to call if we disconnect from a peer 357 * @param disconnect_cb function to call if we disconnect from a peer
362 */ 358 */
363void 359void
364GST_neighbours_start (void *cls, 360GST_neighbours_start (void *cls, GNUNET_TRANSPORT_NotifyConnect connect_cb,
365 GNUNET_TRANSPORT_NotifyConnect connect_cb,
366 GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb) 361 GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb)
367{ 362{
368 callback_cls = cls; 363 callback_cls = cls;
@@ -466,8 +461,7 @@ disconnect_all_neighbours (void *cls, const GNUNET_HashCode * key, void *value)
466 struct NeighbourMapEntry *n = value; 461 struct NeighbourMapEntry *n = value;
467 462
468#if DEBUG_TRANSPORT 463#if DEBUG_TRANSPORT
469 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 464 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s', %s\n",
470 "Disconnecting peer `%4s', %s\n",
471 GNUNET_i2s (&n->id), "SHUTDOWN_TASK"); 465 GNUNET_i2s (&n->id), "SHUTDOWN_TASK");
472#endif 466#endif
473 disconnect_neighbour (n); 467 disconnect_neighbour (n);
@@ -481,8 +475,8 @@ disconnect_all_neighbours (void *cls, const GNUNET_HashCode * key, void *value)
481void 475void
482GST_neighbours_stop () 476GST_neighbours_stop ()
483{ 477{
484 GNUNET_CONTAINER_multihashmap_iterate (neighbours, 478 GNUNET_CONTAINER_multihashmap_iterate (neighbours, &disconnect_all_neighbours,
485 &disconnect_all_neighbours, NULL); 479 NULL);
486 GNUNET_CONTAINER_multihashmap_destroy (neighbours); 480 GNUNET_CONTAINER_multihashmap_destroy (neighbours);
487 neighbours = NULL; 481 neighbours = NULL;
488 callback_cls = NULL; 482 callback_cls = NULL;
@@ -506,10 +500,8 @@ GST_neighbours_stop ()
506 */ 500 */
507void 501void
508GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, 502GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
509 const char *plugin_name, 503 const char *plugin_name, const void *address,
510 const void *address, 504 size_t address_len, struct Session *session,
511 size_t address_len,
512 struct Session *session,
513 const struct GNUNET_TRANSPORT_ATS_Information 505 const struct GNUNET_TRANSPORT_ATS_Information
514 *ats, uint32_t ats_count) 506 *ats, uint32_t ats_count)
515{ 507{
@@ -528,8 +520,8 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
528 n->addrlen = address_len; 520 n->addrlen = address_len;
529 n->session = session; 521 n->session = session;
530 GNUNET_array_grow (n->ats, n->ats_count, ats_count); 522 GNUNET_array_grow (n->ats, n->ats_count, ats_count);
531 memcpy (n->ats, 523 memcpy (n->ats, ats,
532 ats, ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); 524 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
533 GNUNET_free_non_null (n->plugin_name); 525 GNUNET_free_non_null (n->plugin_name);
534 n->plugin_name = GNUNET_strdup (plugin_name); 526 n->plugin_name = GNUNET_strdup (plugin_name);
535 GNUNET_SCHEDULER_cancel (n->timeout_task); 527 GNUNET_SCHEDULER_cancel (n->timeout_task);
@@ -538,9 +530,7 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
538 &neighbour_timeout_task, n); 530 &neighbour_timeout_task, n);
539 connect_msg.size = htons (sizeof (struct GNUNET_MessageHeader)); 531 connect_msg.size = htons (sizeof (struct GNUNET_MessageHeader));
540 connect_msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 532 connect_msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
541 GST_neighbours_send (peer, 533 GST_neighbours_send (peer, &connect_msg, sizeof (connect_msg),
542 &connect_msg,
543 sizeof (connect_msg),
544 GNUNET_TIME_UNIT_FOREVER_REL, NULL, NULL); 534 GNUNET_TIME_UNIT_FOREVER_REL, NULL, NULL);
545} 535}
546 536
@@ -558,10 +548,8 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
558 * @param ats_count number of performance records in 'ats' 548 * @param ats_count number of performance records in 'ats'
559 */ 549 */
560static void 550static void
561try_connect_using_address (void *cls, 551try_connect_using_address (void *cls, const struct GNUNET_PeerIdentity *target,
562 const struct GNUNET_PeerIdentity *target, 552 const char *plugin_name, const void *plugin_address,
563 const char *plugin_name,
564 const void *plugin_address,
565 size_t plugin_address_len, 553 size_t plugin_address_len,
566 struct GNUNET_BANDWIDTH_Value32NBO bandwidth, 554 struct GNUNET_BANDWIDTH_Value32NBO bandwidth,
567 const struct GNUNET_TRANSPORT_ATS_Information *ats, 555 const struct GNUNET_TRANSPORT_ATS_Information *ats,
@@ -570,9 +558,7 @@ try_connect_using_address (void *cls,
570 struct NeighbourMapEntry *n = cls; 558 struct NeighbourMapEntry *n = cls;
571 559
572 n->asc = NULL; 560 n->asc = NULL;
573 GST_neighbours_switch_to_address (target, 561 GST_neighbours_switch_to_address (target, plugin_name, plugin_address,
574 plugin_name,
575 plugin_address,
576 plugin_address_len, NULL, ats, ats_count); 562 plugin_address_len, NULL, ats, ats_count);
577 if (GNUNET_YES == n->is_connected) 563 if (GNUNET_YES == n->is_connected)
578 return; 564 return;
@@ -591,9 +577,9 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
591{ 577{
592 struct NeighbourMapEntry *n; 578 struct NeighbourMapEntry *n;
593 579
594 GNUNET_assert (0 != memcmp (target, 580 GNUNET_assert (0 !=
595 &GST_my_identity, 581 memcmp (target, &GST_my_identity,
596 sizeof (struct GNUNET_PeerIdentity))); 582 sizeof (struct GNUNET_PeerIdentity)));
597 n = lookup_neighbour (target); 583 n = lookup_neighbour (target);
598 if ((NULL != n) && (GNUNET_YES == n->is_connected)) 584 if ((NULL != n) && (GNUNET_YES == n->is_connected))
599 return; /* already connected */ 585 return; /* already connected */
@@ -614,8 +600,9 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
614 } 600 }
615 if (n->asc != NULL) 601 if (n->asc != NULL)
616 return; /* already trying */ 602 return; /* already trying */
617 n->asc = GNUNET_ATS_suggest_address (GST_ats, 603 n->asc =
618 target, &try_connect_using_address, n); 604 GNUNET_ATS_suggest_address (GST_ats, target, &try_connect_using_address,
605 n);
619} 606}
620 607
621 608
@@ -684,10 +671,8 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
684 * @param cont_cls closure for 'cont' 671 * @param cont_cls closure for 'cont'
685 */ 672 */
686void 673void
687GST_neighbours_send (const struct GNUNET_PeerIdentity *target, 674GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg,
688 const void *msg, 675 size_t msg_size, struct GNUNET_TIME_Relative timeout,
689 size_t msg_size,
690 struct GNUNET_TIME_Relative timeout,
691 GST_NeighbourSendContinuation cont, void *cont_cls) 676 GST_NeighbourSendContinuation cont, void *cont_cls)
692{ 677{
693 struct NeighbourMapEntry *n; 678 struct NeighbourMapEntry *n;
@@ -785,8 +770,8 @@ GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity
785#if DEBUG_TRANSPORT 770#if DEBUG_TRANSPORT
786 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 771 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
787 "Throttling read (%llu bytes excess at %u b/s), waiting %llu ms before reading more.\n", 772 "Throttling read (%llu bytes excess at %u b/s), waiting %llu ms before reading more.\n",
788 (unsigned long long) n-> 773 (unsigned long long) n->in_tracker.
789 in_tracker.consumption_since_last_update__, 774 consumption_since_last_update__,
790 (unsigned int) n->in_tracker.available_bytes_per_s__, 775 (unsigned int) n->in_tracker.available_bytes_per_s__,
791 (unsigned long long) ret.rel_value); 776 (unsigned long long) ret.rel_value);
792#endif 777#endif
@@ -850,13 +835,12 @@ GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour,
850 if (0 != ntohl (quota.value__)) 835 if (0 != ntohl (quota.value__))
851 return; 836 return;
852#if DEBUG_TRANSPORT 837#if DEBUG_TRANSPORT
853 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 838 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s' due to `%s'\n",
854 "Disconnecting peer `%4s' due to `%s'\n",
855 GNUNET_i2s (&n->id), "SET_QUOTA"); 839 GNUNET_i2s (&n->id), "SET_QUOTA");
856#endif 840#endif
857 GNUNET_STATISTICS_update (GST_stats, 841 GNUNET_STATISTICS_update (GST_stats,
858 gettext_noop ("# disconnects due to quota of 0"), 842 gettext_noop ("# disconnects due to quota of 0"), 1,
859 1, GNUNET_NO); 843 GNUNET_NO);
860 disconnect_neighbour (n); 844 disconnect_neighbour (n);
861} 845}
862 846
@@ -939,13 +923,11 @@ GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target)
939 disconnect_msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 923 disconnect_msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
940 papi = GST_plugins_find (n->plugin_name); 924 papi = GST_plugins_find (n->plugin_name);
941 if (papi != NULL) 925 if (papi != NULL)
942 papi->send (papi->cls, 926 papi->send (papi->cls, target, (const void *) &disconnect_msg,
943 target,
944 (const void *) &disconnect_msg,
945 sizeof (struct GNUNET_MessageHeader), 927 sizeof (struct GNUNET_MessageHeader),
946 UINT32_MAX /* priority */ , 928 UINT32_MAX /* priority */ ,
947 GNUNET_TIME_UNIT_FOREVER_REL, 929 GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->addr, n->addrlen,
948 n->session, n->addr, n->addrlen, GNUNET_YES, NULL, NULL); 930 GNUNET_YES, NULL, NULL);
949 } 931 }
950 disconnect_neighbour (n); 932 disconnect_neighbour (n);
951} 933}
diff --git a/src/transport/gnunet-service-transport_plugins.c b/src/transport/gnunet-service-transport_plugins.c
index 87901d2cc..c32ac3acc 100644
--- a/src/transport/gnunet-service-transport_plugins.c
+++ b/src/transport/gnunet-service-transport_plugins.c
@@ -102,8 +102,7 @@ GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
102 char *pos; 102 char *pos;
103 103
104 if (GNUNET_OK != 104 if (GNUNET_OK !=
105 GNUNET_CONFIGURATION_get_value_number (GST_cfg, 105 GNUNET_CONFIGURATION_get_value_number (GST_cfg, "TRANSPORT",
106 "TRANSPORT",
107 "NEIGHBOUR_LIMIT", &tneigh)) 106 "NEIGHBOUR_LIMIT", &tneigh))
108 { 107 {
109 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 108 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -111,15 +110,15 @@ GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
111 return; 110 return;
112 } 111 }
113 if (GNUNET_OK != 112 if (GNUNET_OK !=
114 GNUNET_CONFIGURATION_get_value_string (GST_cfg, 113 GNUNET_CONFIGURATION_get_value_string (GST_cfg, "TRANSPORT", "PLUGINS",
115 "TRANSPORT", "PLUGINS", &plugs)) 114 &plugs))
116 return; 115 return;
117 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 116 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Starting transport plugins `%s'\n"),
118 _("Starting transport plugins `%s'\n"), plugs); 117 plugs);
119 for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " ")) 118 for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
120 { 119 {
121 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 120 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' transport plugin\n"),
122 _("Loading `%s' transport plugin\n"), pos); 121 pos);
123 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", pos); 122 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", pos);
124 plug = GNUNET_malloc (sizeof (struct TransportPlugin)); 123 plug = GNUNET_malloc (sizeof (struct TransportPlugin));
125 plug->short_name = GNUNET_strdup (pos); 124 plug->short_name = GNUNET_strdup (pos);
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c
index f618a2b1a..9a3914814 100644
--- a/src/transport/gnunet-service-transport_validation.c
+++ b/src/transport/gnunet-service-transport_validation.c
@@ -361,13 +361,11 @@ find_validation_entry (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
361 ve->addr = (void *) &ve[1]; 361 ve->addr = (void *) &ve[1];
362 ve->public_key = *public_key; 362 ve->public_key = *public_key;
363 ve->pid = *neighbour; 363 ve->pid = *neighbour;
364 ve->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 364 ve->challenge =
365 UINT32_MAX); 365 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
366 memcpy (&ve[1], addr, addrlen); 366 memcpy (&ve[1], addr, addrlen);
367 ve->addrlen = addrlen; 367 ve->addrlen = addrlen;
368 GNUNET_CONTAINER_multihashmap_put (validation_map, 368 GNUNET_CONTAINER_multihashmap_put (validation_map, &neighbour->hashPubKey, ve,
369 &neighbour->hashPubKey,
370 ve,
371 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 369 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
372 return ve; 370 return ve;
373} 371}
@@ -385,10 +383,9 @@ find_validation_entry (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
385 * @return GNUNET_OK (keep the address) 383 * @return GNUNET_OK (keep the address)
386 */ 384 */
387static int 385static int
388add_valid_address (void *cls, 386add_valid_address (void *cls, const char *tname,
389 const char *tname, 387 struct GNUNET_TIME_Absolute expiration, const void *addr,
390 struct GNUNET_TIME_Absolute expiration, 388 uint16_t addrlen)
391 const void *addr, uint16_t addrlen)
392{ 389{
393 const struct GNUNET_HELLO_Message *hello = cls; 390 const struct GNUNET_HELLO_Message *hello = cls;
394 struct ValidationEntry *ve; 391 struct ValidationEntry *ve;
@@ -397,8 +394,7 @@ add_valid_address (void *cls,
397 394
398 if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0) 395 if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0)
399 return GNUNET_OK; /* expired */ 396 return GNUNET_OK; /* expired */
400 if ((GNUNET_OK != 397 if ((GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) ||
401 GNUNET_HELLO_get_id (hello, &pid)) ||
402 (GNUNET_OK != GNUNET_HELLO_get_key (hello, &public_key))) 398 (GNUNET_OK != GNUNET_HELLO_get_key (hello, &public_key)))
403 { 399 {
404 GNUNET_break (0); 400 GNUNET_break (0);
@@ -406,10 +402,8 @@ add_valid_address (void *cls,
406 } 402 }
407 ve = find_validation_entry (&public_key, &pid, tname, addr, addrlen); 403 ve = find_validation_entry (&public_key, &pid, tname, addr, addrlen);
408 ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, expiration); 404 ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, expiration);
409 GNUNET_ATS_address_update (GST_ats, 405 GNUNET_ATS_address_update (GST_ats, &pid, ve->valid_until, tname, NULL, addr,
410 &pid, 406 addrlen, NULL, 0);
411 ve->valid_until,
412 tname, NULL, addr, addrlen, NULL, 0);
413 return GNUNET_OK; 407 return GNUNET_OK;
414} 408}
415 409
@@ -423,8 +417,7 @@ add_valid_address (void *cls,
423 * @param error message 417 * @param error message
424 */ 418 */
425static void 419static void
426process_peerinfo_hello (void *cls, 420process_peerinfo_hello (void *cls, const struct GNUNET_PeerIdentity *peer,
427 const struct GNUNET_PeerIdentity *peer,
428 const struct GNUNET_HELLO_Message *hello, 421 const struct GNUNET_HELLO_Message *hello,
429 const char *err_msg) 422 const char *err_msg)
430{ 423{
@@ -432,8 +425,7 @@ process_peerinfo_hello (void *cls,
432 if (NULL == hello) 425 if (NULL == hello)
433 return; 426 return;
434 GNUNET_assert (NULL == 427 GNUNET_assert (NULL ==
435 GNUNET_HELLO_iterate_addresses (hello, 428 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO,
436 GNUNET_NO,
437 &add_valid_address, 429 &add_valid_address,
438 (void *) hello)); 430 (void *) hello));
439} 431}
@@ -517,8 +509,8 @@ timeout_hello_validation (void *cls,
517 509
518 ve->timeout_task = GNUNET_SCHEDULER_NO_TASK; 510 ve->timeout_task = GNUNET_SCHEDULER_NO_TASK;
519 GNUNET_STATISTICS_update (GST_stats, 511 GNUNET_STATISTICS_update (GST_stats,
520 gettext_noop ("# address records discarded"), 512 gettext_noop ("# address records discarded"), 1,
521 1, GNUNET_NO); 513 GNUNET_NO);
522 cleanup_validation_entry (NULL, &ve->pid.hashPubKey, ve); 514 cleanup_validation_entry (NULL, &ve->pid.hashPubKey, ve);
523} 515}
524 516
@@ -553,14 +545,9 @@ multicast_pong (void *cls,
553 papi = GST_plugins_find (plugin_name); 545 papi = GST_plugins_find (plugin_name);
554 if (papi == NULL) 546 if (papi == NULL)
555 return; 547 return;
556 (void) papi->send (papi->cls, 548 (void) papi->send (papi->cls, target, (const char *) pong,
557 target, 549 ntohs (pong->header.size), PONG_PRIORITY,
558 (const char *) pong, 550 HELLO_REVALIDATION_START_TIME, NULL, plugin_address,
559 ntohs (pong->header.size),
560 PONG_PRIORITY,
561 HELLO_REVALIDATION_START_TIME,
562 NULL,
563 plugin_address,
564 plugin_address_len, GNUNET_YES, NULL, NULL); 551 plugin_address_len, GNUNET_YES, NULL, NULL);
565} 552}
566 553
@@ -579,8 +566,7 @@ multicast_pong (void *cls,
579void 566void
580GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, 567GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
581 const struct GNUNET_MessageHeader *hdr, 568 const struct GNUNET_MessageHeader *hdr,
582 const char *plugin_name, 569 const char *plugin_name, struct Session *session,
583 struct Session *session,
584 const void *sender_address, 570 const void *sender_address,
585 size_t sender_address_len) 571 size_t sender_address_len)
586{ 572{
@@ -601,15 +587,16 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
601 return; 587 return;
602 } 588 }
603 ping = (const struct TransportPingMessage *) hdr; 589 ping = (const struct TransportPingMessage *) hdr;
604 if (0 != memcmp (&ping->target, 590 if (0 !=
605 &GST_my_identity, sizeof (struct GNUNET_PeerIdentity))) 591 memcmp (&ping->target, &GST_my_identity,
592 sizeof (struct GNUNET_PeerIdentity)))
606 { 593 {
607 GNUNET_break_op (0); 594 GNUNET_break_op (0);
608 return; 595 return;
609 } 596 }
610 GNUNET_STATISTICS_update (GST_stats, 597 GNUNET_STATISTICS_update (GST_stats,
611 gettext_noop ("# PING messages received"), 598 gettext_noop ("# PING messages received"), 1,
612 1, GNUNET_NO); 599 GNUNET_NO);
613 addr = (const char *) &ping[1]; 600 addr = (const char *) &ping[1];
614 alen = ntohs (hdr->size) - sizeof (struct TransportPingMessage); 601 alen = ntohs (hdr->size) - sizeof (struct TransportPingMessage);
615 /* peer wants to confirm that this is one of our addresses, this is what is 602 /* peer wants to confirm that this is one of our addresses, this is what is
@@ -641,8 +628,8 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
641 pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG); 628 pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG);
642 pong->purpose.size = 629 pong->purpose.size =
643 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + 630 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
644 sizeof (uint32_t) + 631 sizeof (uint32_t) + sizeof (struct GNUNET_TIME_AbsoluteNBO) +
645 sizeof (struct GNUNET_TIME_AbsoluteNBO) + alen + slen); 632 alen + slen);
646 pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN); 633 pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN);
647 pong->challenge = ping->challenge; 634 pong->challenge = ping->challenge;
648 pong->addrlen = htonl (alen + slen); 635 pong->addrlen = htonl (alen + slen);
@@ -659,8 +646,8 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
659 *sig_cache_exp = GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME); 646 *sig_cache_exp = GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME);
660 pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp); 647 pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp);
661 GNUNET_assert (GNUNET_OK == 648 GNUNET_assert (GNUNET_OK ==
662 GNUNET_CRYPTO_rsa_sign (GST_my_private_key, 649 GNUNET_CRYPTO_rsa_sign (GST_my_private_key, &pong->purpose,
663 &pong->purpose, sig_cache)); 650 sig_cache));
664 } 651 }
665 else 652 else
666 { 653 {
@@ -674,15 +661,11 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
674 if (papi == NULL) 661 if (papi == NULL)
675 ret = -1; 662 ret = -1;
676 else 663 else
677 ret = papi->send (papi->cls, 664 ret =
678 sender, 665 papi->send (papi->cls, sender, (const char *) pong,
679 (const char *) pong, 666 ntohs (pong->header.size), PONG_PRIORITY,
680 ntohs (pong->header.size), 667 HELLO_REVALIDATION_START_TIME, session, sender_address,
681 PONG_PRIORITY, 668 sender_address_len, GNUNET_SYSERR, NULL, NULL);
682 HELLO_REVALIDATION_START_TIME,
683 session,
684 sender_address,
685 sender_address_len, GNUNET_SYSERR, NULL, NULL);
686 if (ret != -1) 669 if (ret != -1)
687 { 670 {
688 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 671 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -733,8 +716,8 @@ struct ValidateAddressContext
733 * @param result GNUNET_OK if the connection is allowed, GNUNET_NO if not 716 * @param result GNUNET_OK if the connection is allowed, GNUNET_NO if not
734 */ 717 */
735static void 718static void
736transmit_ping_if_allowed (void *cls, 719transmit_ping_if_allowed (void *cls, const struct GNUNET_PeerIdentity *pid,
737 const struct GNUNET_PeerIdentity *pid, int result) 720 int result)
738{ 721{
739 struct ValidationEntry *ve = cls; 722 struct ValidationEntry *ve = cls;
740 struct TransportPingMessage ping; 723 struct TransportPingMessage ping;
@@ -746,8 +729,8 @@ transmit_ping_if_allowed (void *cls,
746 uint16_t hsize; 729 uint16_t hsize;
747 730
748 ve->bc = NULL; 731 ve->bc = NULL;
749 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 732 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting plain PING to `%s'\n",
750 "Transmitting plain PING to `%s'\n", GNUNET_i2s (pid)); 733 GNUNET_i2s (pid));
751 ping.header.size = htons (sizeof (struct TransportPingMessage)); 734 ping.header.size = htons (sizeof (struct TransportPingMessage));
752 ping.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PING); 735 ping.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
753 ping.challenge = htonl (ve->challenge); 736 ping.challenge = htonl (ve->challenge);
@@ -780,13 +763,10 @@ transmit_ping_if_allowed (void *cls,
780 if (papi == NULL) 763 if (papi == NULL)
781 ret = -1; 764 ret = -1;
782 else 765 else
783 ret = papi->send (papi->cls, 766 ret =
784 pid, 767 papi->send (papi->cls, pid, message_buf, tsize, PING_PRIORITY,
785 message_buf, 768 HELLO_REVALIDATION_START_TIME, NULL /* no session */ ,
786 tsize, 769 ve->addr, ve->addrlen, GNUNET_YES, NULL, NULL);
787 PING_PRIORITY,
788 HELLO_REVALIDATION_START_TIME, NULL /* no session */ ,
789 ve->addr, ve->addrlen, GNUNET_YES, NULL, NULL);
790 } 770 }
791 if (-1 != ret) 771 if (-1 != ret)
792 { 772 {
@@ -811,10 +791,9 @@ transmit_ping_if_allowed (void *cls,
811 * @return GNUNET_OK (keep the address) 791 * @return GNUNET_OK (keep the address)
812 */ 792 */
813static int 793static int
814validate_address (void *cls, 794validate_address (void *cls, const char *tname,
815 const char *tname, 795 struct GNUNET_TIME_Absolute expiration, const void *addr,
816 struct GNUNET_TIME_Absolute expiration, 796 uint16_t addrlen)
817 const void *addr, uint16_t addrlen)
818{ 797{
819 const struct ValidateAddressContext *vac = cls; 798 const struct ValidateAddressContext *vac = cls;
820 const struct GNUNET_PeerIdentity *pid = &vac->pid; 799 const struct GNUNET_PeerIdentity *pid = &vac->pid;
@@ -861,18 +840,17 @@ revalidate_address (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
861 if (delay.rel_value > 0) 840 if (delay.rel_value > 0)
862 { 841 {
863 /* should wait a bit longer */ 842 /* should wait a bit longer */
864 ve->timeout_task = GNUNET_SCHEDULER_add_delayed (delay, 843 ve->timeout_task =
865 &revalidate_address, ve); 844 GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve);
866 return; 845 return;
867 } 846 }
868 GNUNET_STATISTICS_update (GST_stats, 847 GNUNET_STATISTICS_update (GST_stats,
869 gettext_noop ("# address revalidations started"), 848 gettext_noop ("# address revalidations started"), 1,
870 1, GNUNET_NO); 849 GNUNET_NO);
871 vac.pid = ve->pid; 850 vac.pid = ve->pid;
872 vac.public_key = ve->public_key; 851 vac.public_key = ve->public_key;
873 validate_address (&vac, 852 validate_address (&vac, ve->transport_name, ve->valid_until, ve->addr,
874 ve->transport_name, 853 (uint16_t) ve->addrlen);
875 ve->valid_until, ve->addr, (uint16_t) ve->addrlen);
876} 854}
877 855
878 856
@@ -888,8 +866,7 @@ add_valid_peer_address (void *cls, size_t max, void *buf)
888{ 866{
889 struct ValidationEntry *ve = cls; 867 struct ValidationEntry *ve = cls;
890 868
891 return GNUNET_HELLO_add_address (ve->transport_name, 869 return GNUNET_HELLO_add_address (ve->transport_name, ve->valid_until,
892 ve->valid_until,
893 ve->addr, ve->addrlen, buf, max); 870 ve->addr, ve->addrlen, buf, max);
894} 871}
895 872
@@ -921,8 +898,8 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
921 return; 898 return;
922 } 899 }
923 GNUNET_STATISTICS_update (GST_stats, 900 GNUNET_STATISTICS_update (GST_stats,
924 gettext_noop ("# PONG messages received"), 901 gettext_noop ("# PONG messages received"), 1,
925 1, GNUNET_NO); 902 GNUNET_NO);
926 pong = (const struct TransportPongMessage *) hdr; 903 pong = (const struct TransportPongMessage *) hdr;
927 addr = (const char *) &pong[1]; 904 addr = (const char *) &pong[1];
928 alen = ntohs (hdr->size) - sizeof (struct TransportPongMessage); 905 alen = ntohs (hdr->size) - sizeof (struct TransportPongMessage);
@@ -962,8 +939,8 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
962 } 939 }
963 if (GNUNET_OK != 940 if (GNUNET_OK !=
964 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, 941 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
965 &pong->purpose, 942 &pong->purpose, &pong->signature,
966 &pong->signature, &ve->public_key)) 943 &ve->public_key))
967 { 944 {
968 GNUNET_break_op (0); 945 GNUNET_break_op (0);
969 return; 946 return;
@@ -983,9 +960,10 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
983 960
984 /* randomly delay by up to 1h to avoid synchronous validations */ 961 /* randomly delay by up to 1h to avoid synchronous validations */
985 rdelay = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 60 * 60); 962 rdelay = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 60 * 60);
986 delay = GNUNET_TIME_relative_add (HELLO_REVALIDATION_START_TIME, 963 delay =
987 GNUNET_TIME_relative_multiply 964 GNUNET_TIME_relative_add (HELLO_REVALIDATION_START_TIME,
988 (GNUNET_TIME_UNIT_SECONDS, rdelay)); 965 GNUNET_TIME_relative_multiply
966 (GNUNET_TIME_UNIT_SECONDS, rdelay));
989 ve->timeout_task = 967 ve->timeout_task =
990 GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve); 968 GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve);
991} 969}
@@ -1004,8 +982,7 @@ GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello)
1004 (const struct GNUNET_HELLO_Message *) hello; 982 (const struct GNUNET_HELLO_Message *) hello;
1005 struct ValidateAddressContext vac; 983 struct ValidateAddressContext vac;
1006 984
1007 if ((GNUNET_OK != 985 if ((GNUNET_OK != GNUNET_HELLO_get_id (hm, &vac.pid)) ||
1008 GNUNET_HELLO_get_id (hm, &vac.pid)) ||
1009 (GNUNET_OK != GNUNET_HELLO_get_key (hm, &vac.public_key))) 986 (GNUNET_OK != GNUNET_HELLO_get_key (hm, &vac.public_key)))
1010 { 987 {
1011 /* malformed HELLO */ 988 /* malformed HELLO */
@@ -1013,8 +990,7 @@ GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello)
1013 return; 990 return;
1014 } 991 }
1015 GNUNET_assert (NULL == 992 GNUNET_assert (NULL ==
1016 GNUNET_HELLO_iterate_addresses (hm, 993 GNUNET_HELLO_iterate_addresses (hm, GNUNET_NO,
1017 GNUNET_NO,
1018 &validate_address, &vac)); 994 &validate_address, &vac));
1019} 995}
1020 996
@@ -1051,10 +1027,7 @@ iterate_addresses (void *cls, const GNUNET_HashCode * key, void *value)
1051 struct IteratorContext *ic = cls; 1027 struct IteratorContext *ic = cls;
1052 struct ValidationEntry *ve = value; 1028 struct ValidationEntry *ve = value;
1053 1029
1054 ic->cb (ic->cb_cls, 1030 ic->cb (ic->cb_cls, &ve->public_key, &ve->pid, ve->valid_until,
1055 &ve->public_key,
1056 &ve->pid,
1057 ve->valid_until,
1058 ve->validation_block, ve->transport_name, ve->addr, ve->addrlen); 1031 ve->validation_block, ve->transport_name, ve->addr, ve->addrlen);
1059 return GNUNET_OK; 1032 return GNUNET_OK;
1060} 1033}
diff --git a/src/transport/gnunet-transport-certificate-creation.c b/src/transport/gnunet-transport-certificate-creation.c
index a63c21c60..9fd62fc9f 100644
--- a/src/transport/gnunet-transport-certificate-creation.c
+++ b/src/transport/gnunet-transport-certificate-creation.c
@@ -56,10 +56,9 @@ main (int argc, char **argv)
56 close (2); /* eliminate stderr */ 56 close (2); /* eliminate stderr */
57 /* Create RSA Private Key */ 57 /* Create RSA Private Key */
58 /* openssl genrsa -out $1 1024 2> /dev/null */ 58 /* openssl genrsa -out $1 1024 2> /dev/null */
59 openssl = GNUNET_OS_start_process (NULL, NULL, 59 openssl =
60 "openssl", 60 GNUNET_OS_start_process (NULL, NULL, "openssl", "openssl", "genrsa",
61 "openssl", 61 "-out", argv[1], "1024", NULL);
62 "genrsa", "-out", argv[1], "1024", NULL);
63 if (openssl == NULL) 62 if (openssl == NULL)
64 return 2; 63 return 2;
65 GNUNET_assert (GNUNET_OS_process_wait (openssl) == GNUNET_OK); 64 GNUNET_assert (GNUNET_OS_process_wait (openssl) == GNUNET_OK);
@@ -67,12 +66,10 @@ main (int argc, char **argv)
67 66
68 /* Create a self-signed certificate in batch mode using rsa key */ 67 /* Create a self-signed certificate in batch mode using rsa key */
69 /* openssl req -batch -days 365 -out $2 -new -x509 -key $1 2> /dev/null */ 68 /* openssl req -batch -days 365 -out $2 -new -x509 -key $1 2> /dev/null */
70 openssl = GNUNET_OS_start_process (NULL, NULL, 69 openssl =
71 "openssl", 70 GNUNET_OS_start_process (NULL, NULL, "openssl", "openssl", "req",
72 "openssl", 71 "-batch", "-days", "365", "-out", argv[2],
73 "req", "-batch", "-days", "365", 72 "-new", "-x509", "-key", argv[1], NULL);
74 "-out", argv[2], "-new", "-x509", "-key",
75 argv[1], NULL);
76 if (openssl == NULL) 73 if (openssl == NULL)
77 return 3; 74 return 3;
78 GNUNET_assert (GNUNET_OS_process_wait (openssl) == GNUNET_OK); 75 GNUNET_assert (GNUNET_OS_process_wait (openssl) == GNUNET_OK);
diff --git a/src/transport/gnunet-transport-list-connections.c b/src/transport/gnunet-transport-list-connections.c
index d68d2fedf..d31d2febb 100644
--- a/src/transport/gnunet-transport-list-connections.c
+++ b/src/transport/gnunet-transport-list-connections.c
@@ -72,9 +72,8 @@ process_address (void *cls, const char *address)
72 * @param c configuration 72 * @param c configuration
73 */ 73 */
74static void 74static void
75run (void *cls, 75run (void *cls, char *const *args, const char *cfgfile,
76 char *const *args, 76 const struct GNUNET_CONFIGURATION_Handle *c)
77 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
78{ 77{
79 78
80 cfg = c; 79 cfg = c;
@@ -84,8 +83,7 @@ run (void *cls,
84 return; 83 return;
85 } 84 }
86 85
87 GNUNET_TRANSPORT_address_iterate (cfg, 86 GNUNET_TRANSPORT_address_iterate (cfg, GNUNET_TIME_UNIT_MINUTES,
88 GNUNET_TIME_UNIT_MINUTES,
89 &process_address, NULL); 87 &process_address, NULL);
90} 88}
91 89
@@ -107,9 +105,7 @@ main (int argc, char *const *argv)
107 GNUNET_GETOPT_OPTION_END 105 GNUNET_GETOPT_OPTION_END
108 }; 106 };
109 return (GNUNET_OK == 107 return (GNUNET_OK ==
110 GNUNET_PROGRAM_run (argc, 108 GNUNET_PROGRAM_run (argc, argv, "gnunet-list-connections",
111 argv,
112 "gnunet-list-connections",
113 gettext_noop 109 gettext_noop
114 ("Print information about connected peers."), 110 ("Print information about connected peers."),
115 options, &run, NULL)) ? 0 : 1; 111 options, &run, NULL)) ? 0 : 1;
diff --git a/src/transport/gnunet-transport-wlan-helper.c b/src/transport/gnunet-transport-wlan-helper.c
index 1cfcf2c4e..b3468791d 100644
--- a/src/transport/gnunet-transport-wlan-helper.c
+++ b/src/transport/gnunet-transport-wlan-helper.c
@@ -135,10 +135,8 @@ check_crc_buf_osdep (unsigned char *buf, int len)
135 135
136 crc = calc_crc_osdep (buf, len); 136 crc = calc_crc_osdep (buf, len);
137 buf += len; 137 buf += len;
138 return (((crc) & 0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] && ((crc 138 return (((crc) & 0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] &&
139 >> 16) 139 ((crc >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3]);
140 & 0xFF)
141 == buf[2] && ((crc >> 24) & 0xFF) == buf[3]);
142} 140}
143 141
144 142
@@ -387,8 +385,7 @@ openraw (struct Hardware_Infos *dev)
387 sll.sll_protocol = htons (ETH_P_ALL); 385 sll.sll_protocol = htons (ETH_P_ALL);
388 if (-1 == ioctl (dev->fd_raw, SIOCGIFHWADDR, &ifr)) 386 if (-1 == ioctl (dev->fd_raw, SIOCGIFHWADDR, &ifr))
389 { 387 {
390 fprintf (stderr, 388 fprintf (stderr, "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n",
391 "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n",
392 IFNAMSIZ, dev->iface, strerror (errno)); 389 IFNAMSIZ, dev->iface, strerror (errno));
393 return 1; 390 return 1;
394 } 391 }
@@ -408,8 +405,7 @@ openraw (struct Hardware_Infos *dev)
408 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL)) || 405 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL)) ||
409 (wrq.u.mode != IW_MODE_MONITOR)) 406 (wrq.u.mode != IW_MODE_MONITOR))
410 { 407 {
411 fprintf (stderr, 408 fprintf (stderr, "Error: interface `%.*s' is not in monitor mode\n",
412 "Error: interface `%.*s' is not in monitor mode\n",
413 IFNAMSIZ, dev->iface); 409 IFNAMSIZ, dev->iface);
414 return 1; 410 return 1;
415 } 411 }
@@ -432,9 +428,8 @@ openraw (struct Hardware_Infos *dev)
432 /* bind the raw socket to the interface */ 428 /* bind the raw socket to the interface */
433 if (-1 == bind (dev->fd_raw, (struct sockaddr *) &sll, sizeof (sll))) 429 if (-1 == bind (dev->fd_raw, (struct sockaddr *) &sll, sizeof (sll)))
434 { 430 {
435 fprintf (stderr, 431 fprintf (stderr, "Failed to bind interface `%.*s': %s\n", IFNAMSIZ,
436 "Failed to bind interface `%.*s': %s\n", 432 dev->iface, strerror (errno));
437 IFNAMSIZ, dev->iface, strerror (errno));
438 return 1; 433 return 1;
439 } 434 }
440 435
@@ -453,8 +448,7 @@ openraw (struct Hardware_Infos *dev)
453 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) && 448 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) &&
454 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL)) 449 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL))
455 { 450 {
456 fprintf (stderr, 451 fprintf (stderr, "Unsupported hardware link type %d on interface `%.*s'\n",
457 "Unsupported hardware link type %d on interface `%.*s'\n",
458 ifr.ifr_hwaddr.sa_family, IFNAMSIZ, dev->iface); 452 ifr.ifr_hwaddr.sa_family, IFNAMSIZ, dev->iface);
459 return 1; 453 return 1;
460 } 454 }
@@ -467,8 +461,7 @@ openraw (struct Hardware_Infos *dev)
467 setsockopt (dev->fd_raw, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mr, 461 setsockopt (dev->fd_raw, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mr,
468 sizeof (mr))) 462 sizeof (mr)))
469 { 463 {
470 fprintf (stderr, 464 fprintf (stderr, "Failed to enable promiscuous mode on interface `%.*s'\n",
471 "Failed to enable promiscuous mode on interface `%.*s'\n",
472 IFNAMSIZ, dev->iface); 465 IFNAMSIZ, dev->iface);
473 return 1; 466 return 1;
474 } 467 }
@@ -494,17 +487,16 @@ wlaninit (struct Hardware_Infos *dev, const char *iface)
494 } 487 }
495 if (dev->fd_raw >= FD_SETSIZE) 488 if (dev->fd_raw >= FD_SETSIZE)
496 { 489 {
497 fprintf (stderr, 490 fprintf (stderr, "File descriptor too large for select (%d > %d)\n",
498 "File descriptor too large for select (%d > %d)\n",
499 dev->fd_raw, FD_SETSIZE); 491 dev->fd_raw, FD_SETSIZE);
500 close (dev->fd_raw); 492 close (dev->fd_raw);
501 return 1; 493 return 1;
502 } 494 }
503 495
504 /* mac80211 stack detection */ 496 /* mac80211 stack detection */
505 ret = snprintf (strbuf, 497 ret =
506 sizeof (strbuf), 498 snprintf (strbuf, sizeof (strbuf), "/sys/class/net/%s/phy80211/subsystem",
507 "/sys/class/net/%s/phy80211/subsystem", iface); 499 iface);
508 if ((ret < 0) || (ret >= sizeof (strbuf)) || (0 != stat (strbuf, &sbuf))) 500 if ((ret < 0) || (ret >= sizeof (strbuf)) || (0 != stat (strbuf, &sbuf)))
509 { 501 {
510 fprintf (stderr, "Did not find 802.11 interface `%s'. Exiting.\n", iface); 502 fprintf (stderr, "Did not find 802.11 interface `%s'. Exiting.\n", iface);
@@ -634,8 +626,7 @@ maketest (unsigned char *buf, struct Hardware_Infos *dev)
634 static int first = 0; 626 static int first = 0;
635 627
636 const int rate = 11000000; 628 const int rate = 11000000;
637 static const char 629 static const char txt[] =
638 txt[] =
639 "Hallo1Hallo2 Hallo3 Hallo4...998877665544332211Hallo1Hallo2 Hallo3 Hallo4...998877665544332211"; 630 "Hallo1Hallo2 Hallo3 Hallo4...998877665544332211Hallo1Hallo2 Hallo3 Hallo4...998877665544332211";
640 631
641 unsigned char u8aRadiotap[] = { 0x00, 0x00, // <-- radiotap version 632 unsigned char u8aRadiotap[] = { 0x00, 0x00, // <-- radiotap version
@@ -686,14 +677,14 @@ maketest (unsigned char *buf, struct Hardware_Infos *dev)
686 } 677 }
687 678
688 tmp16 = (uint16_t *) u8aIeeeHeader.i_dur; 679 tmp16 = (uint16_t *) u8aIeeeHeader.i_dur;
689 *tmp16 680 *tmp16 =
690 =
691 (uint16_t) 681 (uint16_t)
692 htole16 ((sizeof (txt) + 682 htole16 ((sizeof (txt) +
693 sizeof (struct ieee80211_frame) * 1000000) / rate + 290); 683 sizeof (struct ieee80211_frame) * 1000000) / rate + 290);
694 tmp16 = (uint16_t *) u8aIeeeHeader.i_seq; 684 tmp16 = (uint16_t *) u8aIeeeHeader.i_seq;
695 *tmp16 = (*tmp16 & IEEE80211_SEQ_FRAG_MASK) | (htole16 (seqenz) 685 *tmp16 =
696 << IEEE80211_SEQ_SEQ_SHIFT); 686 (*tmp16 & IEEE80211_SEQ_FRAG_MASK) | (htole16 (seqenz) <<
687 IEEE80211_SEQ_SEQ_SHIFT);
697 seqenz++; 688 seqenz++;
698 689
699 memcpy (buf, u8aRadiotap, sizeof (u8aRadiotap)); 690 memcpy (buf, u8aRadiotap, sizeof (u8aRadiotap));
@@ -795,9 +786,9 @@ hardwaremode (int argc, char *argv[])
795 786
796 if (FD_ISSET (STDOUT_FILENO, &wfds)) 787 if (FD_ISSET (STDOUT_FILENO, &wfds))
797 { 788 {
798 ret = write (STDOUT_FILENO, 789 ret =
799 write_std.buf + write_std.pos, 790 write (STDOUT_FILENO, write_std.buf + write_std.pos,
800 write_std.size - write_std.pos); 791 write_std.size - write_std.pos);
801 if (0 > ret) 792 if (0 > ret)
802 { 793 {
803 fprintf (stderr, "Failed to write to STDOUT: %s\n", strerror (errno)); 794 fprintf (stderr, "Failed to write to STDOUT: %s\n", strerror (errno));
@@ -824,9 +815,8 @@ hardwaremode (int argc, char *argv[])
824 dev.write_pout.pos += ret; 815 dev.write_pout.pos += ret;
825 if ((dev.write_pout.pos != dev.write_pout.size) && (ret != 0)) 816 if ((dev.write_pout.pos != dev.write_pout.size) && (ret != 0))
826 { 817 {
827 fprintf (stderr, 818 fprintf (stderr, "Line %u: Write error, partial send: %u/%u\n",
828 "Line %u: Write error, partial send: %u/%u\n", __LINE__, 819 __LINE__, dev.write_pout.pos, dev.write_pout.size);
829 dev.write_pout.pos, dev.write_pout.size);
830 break; 820 break;
831 } 821 }
832 if (dev.write_pout.pos == dev.write_pout.size) 822 if (dev.write_pout.pos == dev.write_pout.size)
@@ -849,8 +839,8 @@ hardwaremode (int argc, char *argv[])
849 /* stop reading... */ 839 /* stop reading... */
850 stdin_open = 0; 840 stdin_open = 0;
851 } 841 }
852 GNUNET_SERVER_mst_receive (stdin_mst, NULL, 842 GNUNET_SERVER_mst_receive (stdin_mst, NULL, readbuf, ret, GNUNET_NO,
853 readbuf, ret, GNUNET_NO, GNUNET_NO); 843 GNUNET_NO);
854 } 844 }
855 845
856 if (FD_ISSET (dev.fd_raw, &rfds)) 846 if (FD_ISSET (dev.fd_raw, &rfds))
@@ -862,10 +852,10 @@ hardwaremode (int argc, char *argv[])
862 header = (struct GNUNET_MessageHeader *) write_std.buf; 852 header = (struct GNUNET_MessageHeader *) write_std.buf;
863 rxinfo = (struct Radiotap_rx *) &header[1]; 853 rxinfo = (struct Radiotap_rx *) &header[1];
864 datastart = (struct ieee80211_frame *) &rxinfo[1]; 854 datastart = (struct ieee80211_frame *) &rxinfo[1];
865 ret = linux_read (&dev, 855 ret =
866 (unsigned char *) datastart, 856 linux_read (&dev, (unsigned char *) datastart,
867 sizeof (write_std.buf) - sizeof (struct Radiotap_rx) - 857 sizeof (write_std.buf) - sizeof (struct Radiotap_rx) -
868 sizeof (struct GNUNET_MessageHeader), rxinfo); 858 sizeof (struct GNUNET_MessageHeader), rxinfo);
869 if (0 > ret) 859 if (0 > ret)
870 { 860 {
871 fprintf (stderr, "Read error from raw socket: %s\n", strerror (errno)); 861 fprintf (stderr, "Read error from raw socket: %s\n", strerror (errno));
diff --git a/src/transport/perf_transport_ats.c b/src/transport/perf_transport_ats.c
index df1ebe950..0be15d255 100644
--- a/src/transport/perf_transport_ats.c
+++ b/src/transport/perf_transport_ats.c
@@ -170,8 +170,8 @@ bench_simplex_no_optimization (char *file, int executions)
170 exec_time[c] = GNUNET_TIME_absolute_get_difference (start, end).rel_value; 170 exec_time[c] = GNUNET_TIME_absolute_get_difference (start, end).rel_value;
171 171
172 sim_no_opt_avg += exec_time[c]; 172 sim_no_opt_avg += exec_time[c];
173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Simplex iterations %i: %llu \n", c,
174 "Simplex iterations %i: %llu \n", c, exec_time[c]); 174 exec_time[c]);
175 } 175 }
176 176
177 glp_delete_prob (prob); 177 glp_delete_prob (prob);
@@ -328,8 +328,7 @@ main (int argc, char *argv[])
328 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 328 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
329 "MLP optimization average per address: %f\n", 329 "MLP optimization average per address: %f\n",
330 ((double) mlp_with_opt_avg / EXECS) / 400); 330 ((double) mlp_with_opt_avg / EXECS) / 400);
331 GAUGER ("TRANSPORT", 331 GAUGER ("TRANSPORT", "GLPK MLP 100 peers 400 addresses with optimization",
332 "GLPK MLP 100 peers 400 addresses with optimization",
333 ((double) mlp_with_opt_avg / EXECS) / 400, "ms/address"); 332 ((double) mlp_with_opt_avg / EXECS) / 400, "ms/address");
334 (void) CLOSE (nullfd); 333 (void) CLOSE (nullfd);
335 return ret; 334 return ret;
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index 0c856e4ab..a6b24e73e 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -547,8 +547,7 @@ struct PrettyPrinterContext
547 * @param addrlen length of the address 547 * @param addrlen length of the address
548 * @return string representing the same address 548 * @return string representing the same address
549 */ 549 */
550static const char *http_plugin_address_to_string (void *cls, 550static const char *http_plugin_address_to_string (void *cls, const void *addr,
551 const void *addr,
552 size_t addrlen); 551 size_t addrlen);
553 552
554 553
@@ -618,8 +617,7 @@ create_url (struct Plugin *plugin, const void *addr, size_t addrlen, size_t id)
618 char *addr_str = (char *) http_plugin_address_to_string (NULL, addr, addrlen); 617 char *addr_str = (char *) http_plugin_address_to_string (NULL, addr, addrlen);
619 618
620 GNUNET_assert ((addr != NULL) && (addrlen != 0)); 619 GNUNET_assert ((addr != NULL) && (addrlen != 0));
621 GNUNET_asprintf (&url, 620 GNUNET_asprintf (&url, "%s://%s/%s;%u", PROTOCOL_PREFIX, addr_str,
622 "%s://%s/%s;%u", PROTOCOL_PREFIX, addr_str,
623 (char *) (&plugin->my_ascii_hash_ident), id); 621 (char *) (&plugin->my_ascii_hash_ident), id);
624 return url; 622 return url;
625} 623}
@@ -634,8 +632,8 @@ create_url (struct Plugin *plugin, const void *addr, size_t addrlen, size_t id)
634static int 632static int
635remove_http_message (struct Session *ps, struct HTTP_Message *msg) 633remove_http_message (struct Session *ps, struct HTTP_Message *msg)
636{ 634{
637 GNUNET_CONTAINER_DLL_remove (ps->pending_msgs_head, 635 GNUNET_CONTAINER_DLL_remove (ps->pending_msgs_head, ps->pending_msgs_tail,
638 ps->pending_msgs_tail, msg); 636 msg);
639 GNUNET_free (msg); 637 GNUNET_free (msg);
640 return GNUNET_OK; 638 return GNUNET_OK;
641} 639}
@@ -648,8 +646,8 @@ remove_http_message (struct Session *ps, struct HTTP_Message *msg)
648 * @return GNUNET_YES on success 646 * @return GNUNET_YES on success
649 */ 647 */
650static int 648static int
651remove_peer_context_Iterator (void *cls, 649remove_peer_context_Iterator (void *cls, const GNUNET_HashCode * key,
652 const GNUNET_HashCode * key, void *value) 650 void *value)
653{ 651{
654 struct Plugin *plugin = cls; 652 struct Plugin *plugin = cls;
655 struct HTTP_PeerContext *pc = value; 653 struct HTTP_PeerContext *pc = value;
@@ -659,8 +657,8 @@ remove_peer_context_Iterator (void *cls,
659 struct HTTP_Message *msg_tmp = NULL; 657 struct HTTP_Message *msg_tmp = NULL;
660 658
661#if DEBUG_HTTP 659#if DEBUG_HTTP
662 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 660 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Freeing context for peer `%s'\n",
663 "Freeing context for peer `%s'\n", GNUNET_i2s (&pc->identity)); 661 GNUNET_i2s (&pc->identity));
664#endif 662#endif
665 GNUNET_assert (GNUNET_YES == 663 GNUNET_assert (GNUNET_YES ==
666 GNUNET_CONTAINER_multihashmap_remove (plugin->peers, 664 GNUNET_CONTAINER_multihashmap_remove (plugin->peers,
@@ -695,8 +693,8 @@ remove_peer_context_Iterator (void *cls,
695 } 693 }
696 GNUNET_free (pc); 694 GNUNET_free (pc);
697 GNUNET_STATISTICS_update (plugin->env->stats, 695 GNUNET_STATISTICS_update (plugin->env->stats,
698 gettext_noop ("# HTTP peers active"), 696 gettext_noop ("# HTTP peers active"), -1,
699 -1, GNUNET_NO); 697 GNUNET_NO);
700 return GNUNET_YES; 698 return GNUNET_YES;
701} 699}
702 700
@@ -710,18 +708,17 @@ remove_peer_context_Iterator (void *cls,
710 * @return GNUNET_SYSERR if msg not found, GNUNET_OK on success 708 * @return GNUNET_SYSERR if msg not found, GNUNET_OK on success
711 */ 709 */
712static int 710static int
713remove_session (struct HTTP_PeerContext *pc, 711remove_session (struct HTTP_PeerContext *pc, struct Session *ps,
714 struct Session *ps, int call_msg_cont, int call_msg_cont_result) 712 int call_msg_cont, int call_msg_cont_result)
715{ 713{
716 struct HTTP_Message *msg; 714 struct HTTP_Message *msg;
717 struct Plugin *plugin = ps->peercontext->plugin; 715 struct Plugin *plugin = ps->peercontext->plugin;
718 716
719#if DEBUG_CONNECTIONS 717#if DEBUG_CONNECTIONS
720 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 718 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
721 "Connection %X: removing %s session %X with id %u\n", 719 "Connection %X: removing %s session %X with id %u\n", ps,
722 ps, 720 (ps->direction == INBOUND) ? "inbound" : "outbound", ps,
723 (ps->direction == INBOUND) 721 ps->session_id);
724 ? "inbound" : "outbound", ps, ps->session_id);
725#endif 722#endif
726 plugin->env->session_end (plugin, &pc->identity, ps); 723 plugin->env->session_end (plugin, &pc->identity, ps);
727 GNUNET_free_non_null (ps->addr); 724 GNUNET_free_non_null (ps->addr);
@@ -746,11 +743,11 @@ remove_session (struct HTTP_PeerContext *pc,
746 { 743 {
747 if ((call_msg_cont == GNUNET_YES) && (msg->transmit_cont != NULL)) 744 if ((call_msg_cont == GNUNET_YES) && (msg->transmit_cont != NULL))
748 { 745 {
749 msg->transmit_cont (msg->transmit_cont_cls, 746 msg->transmit_cont (msg->transmit_cont_cls, &pc->identity,
750 &pc->identity, call_msg_cont_result); 747 call_msg_cont_result);
751 } 748 }
752 GNUNET_CONTAINER_DLL_remove (ps->pending_msgs_head, 749 GNUNET_CONTAINER_DLL_remove (ps->pending_msgs_head, ps->pending_msgs_head,
753 ps->pending_msgs_head, msg); 750 msg);
754 GNUNET_free (msg); 751 GNUNET_free (msg);
755 msg = ps->pending_msgs_head; 752 msg = ps->pending_msgs_head;
756 } 753 }
@@ -795,8 +792,8 @@ check_localaddress (const struct sockaddr *addr, socklen_t addrlen)
795 else 792 else
796 local = GNUNET_YES; 793 local = GNUNET_YES;
797#if DEBUG_HTTP 794#if DEBUG_HTTP
798 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking IPv4 address `%s': %s\n",
799 "Checking IPv4 address `%s': %s\n", GNUNET_a2s (addr, addrlen), 796 GNUNET_a2s (addr, addrlen),
800 (local == GNUNET_YES) ? "local" : "global"); 797 (local == GNUNET_YES) ? "local" : "global");
801#endif 798#endif
802 break; 799 break;
@@ -809,8 +806,8 @@ check_localaddress (const struct sockaddr *addr, socklen_t addrlen)
809 else 806 else
810 local = GNUNET_NO; 807 local = GNUNET_NO;
811#if DEBUG_HTTP 808#if DEBUG_HTTP
812 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 809 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking IPv6 address `%s' : %s\n",
813 "Checking IPv6 address `%s' : %s\n", GNUNET_a2s (addr, addrlen), 810 GNUNET_a2s (addr, addrlen),
814 (local == GNUNET_YES) ? "local" : "global"); 811 (local == GNUNET_YES) ? "local" : "global");
815#endif 812#endif
816 break; 813 break;
@@ -832,9 +829,7 @@ check_localaddress (const struct sockaddr *addr, socklen_t addrlen)
832 * @return GNUNET_OK to continue iterating 829 * @return GNUNET_OK to continue iterating
833 */ 830 */
834static int 831static int
835process_interfaces (void *cls, 832process_interfaces (void *cls, const char *name, int isDefault,
836 const char *name,
837 int isDefault,
838 const struct sockaddr *addr, socklen_t addrlen) 833 const struct sockaddr *addr, socklen_t addrlen)
839{ 834{
840 struct Plugin *plugin = cls; 835 struct Plugin *plugin = cls;
@@ -847,8 +842,7 @@ process_interfaces (void *cls,
847 if (GNUNET_YES == check_localaddress (addr, addrlen)) 842 if (GNUNET_YES == check_localaddress (addr, addrlen))
848 { 843 {
849#if DEBUG_HTTP 844#if DEBUG_HTTP
850 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 845 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PROTOCOL_PREFIX,
851 PROTOCOL_PREFIX,
852 "Not notifying transport of address `%s' (local address)\n", 846 "Not notifying transport of address `%s' (local address)\n",
853 GNUNET_a2s (addr, addrlen)); 847 GNUNET_a2s (addr, addrlen));
854#endif 848#endif
@@ -859,8 +853,8 @@ process_interfaces (void *cls,
859 853
860 GNUNET_assert (cls != NULL); 854 GNUNET_assert (cls != NULL);
861 af = addr->sa_family; 855 af = addr->sa_family;
862 if ((af == AF_INET) && 856 if ((af == AF_INET) && (plugin->use_ipv4 == GNUNET_YES) &&
863 (plugin->use_ipv4 == GNUNET_YES) && (plugin->bind6_address == NULL)) 857 (plugin->bind6_address == NULL))
864 { 858 {
865 859
866 struct in_addr bnd_cmp = ((struct sockaddr_in *) addr)->sin_addr; 860 struct in_addr bnd_cmp = ((struct sockaddr_in *) addr)->sin_addr;
@@ -879,9 +873,8 @@ process_interfaces (void *cls,
879 { 873 {
880 GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head, 874 GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head,
881 plugin->ipv4_addr_tail, t4); 875 plugin->ipv4_addr_tail, t4);
882 plugin->env->notify_address (plugin->env->cls, 876 plugin->env->notify_address (plugin->env->cls, GNUNET_YES, t4,
883 GNUNET_YES, 877 sizeof (struct IPv4HttpAddress));
884 t4, sizeof (struct IPv4HttpAddress));
885 return GNUNET_OK; 878 return GNUNET_OK;
886 } 879 }
887 GNUNET_free (t4); 880 GNUNET_free (t4);
@@ -891,14 +884,13 @@ process_interfaces (void *cls,
891 { 884 {
892 GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head, 885 GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head,
893 plugin->ipv4_addr_tail, t4); 886 plugin->ipv4_addr_tail, t4);
894 plugin->env->notify_address (plugin->env->cls, 887 plugin->env->notify_address (plugin->env->cls, GNUNET_YES, t4,
895 GNUNET_YES, 888 sizeof (struct IPv4HttpAddress));
896 t4, sizeof (struct IPv4HttpAddress));
897 return GNUNET_OK; 889 return GNUNET_OK;
898 } 890 }
899 } 891 }
900 if ((af == AF_INET6) && 892 if ((af == AF_INET6) && (plugin->use_ipv6 == GNUNET_YES) &&
901 (plugin->use_ipv6 == GNUNET_YES) && (plugin->bind4_address == NULL)) 893 (plugin->bind4_address == NULL))
902 { 894 {
903 895
904 struct in6_addr bnd_cmp6 = ((struct sockaddr_in6 *) addr)->sin6_addr; 896 struct in6_addr bnd_cmp6 = ((struct sockaddr_in6 *) addr)->sin6_addr;
@@ -908,16 +900,15 @@ process_interfaces (void *cls,
908 900
909 if (plugin->bind6_address != NULL) 901 if (plugin->bind6_address != NULL)
910 { 902 {
911 if (0 == memcmp (&plugin->bind6_address->sin6_addr, 903 if (0 ==
912 &bnd_cmp6, sizeof (struct in6_addr))) 904 memcmp (&plugin->bind6_address->sin6_addr, &bnd_cmp6,
905 sizeof (struct in6_addr)))
913 { 906 {
914 memcpy (&t6->ipv6_addr, 907 memcpy (&t6->ipv6_addr, &((struct sockaddr_in6 *) addr)->sin6_addr,
915 &((struct sockaddr_in6 *) addr)->sin6_addr,
916 sizeof (struct in6_addr)); 908 sizeof (struct in6_addr));
917 t6->port = htons (plugin->port_inbound); 909 t6->port = htons (plugin->port_inbound);
918 plugin->env->notify_address (plugin->env->cls, 910 plugin->env->notify_address (plugin->env->cls, GNUNET_YES, t6,
919 GNUNET_YES, 911 sizeof (struct IPv6HttpAddress));
920 t6, sizeof (struct IPv6HttpAddress));
921 GNUNET_CONTAINER_DLL_insert (plugin->ipv6_addr_head, 912 GNUNET_CONTAINER_DLL_insert (plugin->ipv6_addr_head,
922 plugin->ipv6_addr_tail, t6); 913 plugin->ipv6_addr_tail, t6);
923 return GNUNET_OK; 914 return GNUNET_OK;
@@ -925,16 +916,14 @@ process_interfaces (void *cls,
925 GNUNET_free (t6); 916 GNUNET_free (t6);
926 return GNUNET_OK; 917 return GNUNET_OK;
927 } 918 }
928 memcpy (&t6->ipv6_addr, 919 memcpy (&t6->ipv6_addr, &((struct sockaddr_in6 *) addr)->sin6_addr,
929 &((struct sockaddr_in6 *) addr)->sin6_addr,
930 sizeof (struct in6_addr)); 920 sizeof (struct in6_addr));
931 t6->port = htons (plugin->port_inbound); 921 t6->port = htons (plugin->port_inbound);
932 GNUNET_CONTAINER_DLL_insert (plugin->ipv6_addr_head, plugin->ipv6_addr_tail, 922 GNUNET_CONTAINER_DLL_insert (plugin->ipv6_addr_head, plugin->ipv6_addr_tail,
933 t6); 923 t6);
934 924
935 plugin->env->notify_address (plugin->env->cls, 925 plugin->env->notify_address (plugin->env->cls, GNUNET_YES, t6,
936 GNUNET_YES, 926 sizeof (struct IPv6HttpAddress));
937 t6, sizeof (struct IPv6HttpAddress));
938 } 927 }
939 return GNUNET_OK; 928 return GNUNET_OK;
940} 929}
@@ -958,8 +947,8 @@ mhd_logger (void *arg, const char *fmt, va_list ap)
958 947
959 948
960static void 949static void
961mhd_termination_cb (void *cls, 950mhd_termination_cb (void *cls, struct MHD_Connection *connection,
962 struct MHD_Connection *connection, void **httpSessionCache) 951 void **httpSessionCache)
963{ 952{
964 struct Session *ps = *httpSessionCache; 953 struct Session *ps = *httpSessionCache;
965 954
@@ -1013,8 +1002,8 @@ mhd_termination_cb (void *cls,
1013 * @param message the message to be forwarded to transport service 1002 * @param message the message to be forwarded to transport service
1014 */ 1003 */
1015static void 1004static void
1016mhd_write_mst_cb (void *cls, 1005mhd_write_mst_cb (void *cls, void *client,
1017 void *client, const struct GNUNET_MessageHeader *message) 1006 const struct GNUNET_MessageHeader *message)
1018{ 1007{
1019 struct Session *ps = cls; 1008 struct Session *ps = cls;
1020 struct HTTP_PeerContext *pc; 1009 struct HTTP_PeerContext *pc;
@@ -1026,9 +1015,7 @@ mhd_write_mst_cb (void *cls,
1026#if DEBUG_HTTP 1015#if DEBUG_HTTP
1027 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1016 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1028 "Connection %X: Forwarding message to transport service, type %u and size %u from `%s' (`%s')\n", 1017 "Connection %X: Forwarding message to transport service, type %u and size %u from `%s' (`%s')\n",
1029 ps, 1018 ps, ntohs (message->type), ntohs (message->size),
1030 ntohs (message->type),
1031 ntohs (message->size),
1032 GNUNET_i2s (&(ps->peercontext)->identity), 1019 GNUNET_i2s (&(ps->peercontext)->identity),
1033 http_plugin_address_to_string (NULL, ps->addr, ps->addrlen)); 1020 http_plugin_address_to_string (NULL, ps->addr, ps->addrlen));
1034#endif 1021#endif
@@ -1038,12 +1025,11 @@ mhd_write_mst_cb (void *cls,
1038 distance[0].value = htonl (1); 1025 distance[0].value = htonl (1);
1039 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 1026 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
1040 distance[1].value = htonl (0); 1027 distance[1].value = htonl (0);
1041 delay = pc->plugin->env->receive (ps->peercontext->plugin->env->cls, 1028 delay =
1042 &pc->identity, 1029 pc->plugin->env->receive (ps->peercontext->plugin->env->cls,
1043 message, 1030 &pc->identity, message,
1044 (const struct 1031 (const struct GNUNET_TRANSPORT_ATS_Information
1045 GNUNET_TRANSPORT_ATS_Information *) 1032 *) &distance, 2, ps, NULL, 0);
1046 &distance, 2, ps, NULL, 0);
1047 pc->delay = delay; 1033 pc->delay = delay;
1048 if (pc->reset_task != GNUNET_SCHEDULER_NO_TASK) 1034 if (pc->reset_task != GNUNET_SCHEDULER_NO_TASK)
1049 GNUNET_SCHEDULER_cancel (pc->reset_task); 1035 GNUNET_SCHEDULER_cancel (pc->reset_task);
@@ -1142,8 +1128,8 @@ mhd_send_callback (void *cls, uint64_t pos, char *buf, size_t max)
1142 } 1128 }
1143 } 1129 }
1144#if DEBUG_CONNECTIONS 1130#if DEBUG_CONNECTIONS
1145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connection %X: MHD has sent %u bytes\n",
1146 "Connection %X: MHD has sent %u bytes\n", ps, bytes_read); 1132 ps, bytes_read);
1147#endif 1133#endif
1148 return bytes_read; 1134 return bytes_read;
1149} 1135}
@@ -1157,13 +1143,10 @@ mhd_send_callback (void *cls, uint64_t pos, char *buf, size_t max)
1157 * already exists and create a new one if not. 1143 * already exists and create a new one if not.
1158 */ 1144 */
1159static int 1145static int
1160mhd_access_cb (void *cls, 1146mhd_access_cb (void *cls, struct MHD_Connection *mhd_connection,
1161 struct MHD_Connection *mhd_connection, 1147 const char *url, const char *method, const char *version,
1162 const char *url, 1148 const char *upload_data, size_t * upload_data_size,
1163 const char *method, 1149 void **httpSessionCache)
1164 const char *version,
1165 const char *upload_data,
1166 size_t * upload_data_size, void **httpSessionCache)
1167{ 1150{
1168 struct Plugin *plugin = cls; 1151 struct Plugin *plugin = cls;
1169 struct MHD_Response *response; 1152 struct MHD_Response *response;
@@ -1205,9 +1188,9 @@ mhd_access_cb (void *cls,
1205 GNUNET_free (peer); 1188 GNUNET_free (peer);
1206 if (GNUNET_SYSERR == res) 1189 if (GNUNET_SYSERR == res)
1207 { 1190 {
1208 response = MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE), 1191 response =
1209 HTTP_ERROR_RESPONSE, 1192 MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE),
1210 MHD_NO, MHD_NO); 1193 HTTP_ERROR_RESPONSE, MHD_NO, MHD_NO);
1211 res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response); 1194 res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response);
1212 MHD_destroy_response (response); 1195 MHD_destroy_response (response);
1213#if DEBUG_CONNECTIONS 1196#if DEBUG_CONNECTIONS
@@ -1240,12 +1223,11 @@ mhd_access_cb (void *cls,
1240 pc->last_session = NULL; 1223 pc->last_session = NULL;
1241 memcpy (&pc->identity, &pi_in, sizeof (struct GNUNET_PeerIdentity)); 1224 memcpy (&pc->identity, &pi_in, sizeof (struct GNUNET_PeerIdentity));
1242 GNUNET_CONTAINER_multihashmap_put (plugin->peers, 1225 GNUNET_CONTAINER_multihashmap_put (plugin->peers,
1243 &pc->identity.hashPubKey, 1226 &pc->identity.hashPubKey, pc,
1244 pc,
1245 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 1227 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1246 GNUNET_STATISTICS_update (plugin->env->stats, 1228 GNUNET_STATISTICS_update (plugin->env->stats,
1247 gettext_noop ("# HTTP peers active"), 1229 gettext_noop ("# HTTP peers active"), 1,
1248 1, GNUNET_NO); 1230 GNUNET_NO);
1249 } 1231 }
1250 1232
1251 conn_info = 1233 conn_info =
@@ -1329,9 +1311,7 @@ mhd_access_cb (void *cls,
1329#if DEBUG_HTTP 1311#if DEBUG_HTTP
1330 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1331 "Connection %X: HTTP Daemon has new an incoming `%s' request from peer `%s' (`%s')\n", 1313 "Connection %X: HTTP Daemon has new an incoming `%s' request from peer `%s' (`%s')\n",
1332 ps, 1314 ps, method, GNUNET_i2s (&pc->identity),
1333 method,
1334 GNUNET_i2s (&pc->identity),
1335 http_plugin_address_to_string (NULL, ps->addr, ps->addrlen)); 1315 http_plugin_address_to_string (NULL, ps->addr, ps->addrlen));
1336#endif 1316#endif
1337 } 1317 }
@@ -1365,9 +1345,9 @@ mhd_access_cb (void *cls,
1365 /* Transmission of all data complete */ 1345 /* Transmission of all data complete */
1366 if ((*upload_data_size == 0) && (ps->recv_active == GNUNET_YES)) 1346 if ((*upload_data_size == 0) && (ps->recv_active == GNUNET_YES))
1367 { 1347 {
1368 response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE), 1348 response =
1369 HTTP_PUT_RESPONSE, 1349 MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),
1370 MHD_NO, MHD_NO); 1350 HTTP_PUT_RESPONSE, MHD_NO, MHD_NO);
1371 res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); 1351 res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
1372#if DEBUG_CONNECTIONS 1352#if DEBUG_CONNECTIONS
1373 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1353 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1385,12 +1365,12 @@ mhd_access_cb (void *cls,
1385 { 1365 {
1386#if DEBUG_HTTP 1366#if DEBUG_HTTP
1387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1388 "Connection %X: PUT with %u bytes forwarded to MST\n", 1368 "Connection %X: PUT with %u bytes forwarded to MST\n", ps,
1389 ps, *upload_data_size); 1369 *upload_data_size);
1390#endif 1370#endif
1391 res = GNUNET_SERVER_mst_receive (ps->msgtok, ps, 1371 res =
1392 upload_data, *upload_data_size, 1372 GNUNET_SERVER_mst_receive (ps->msgtok, ps, upload_data,
1393 GNUNET_NO, GNUNET_NO); 1373 *upload_data_size, GNUNET_NO, GNUNET_NO);
1394 (*upload_data_size) = 0; 1374 (*upload_data_size) = 0;
1395 } 1375 }
1396 else 1376 else
@@ -1485,11 +1465,10 @@ http_server_daemon_prepare (struct Plugin *plugin,
1485 plugin->http_server_daemon_v4 = GNUNET_SCHEDULER_NO_TASK; 1465 plugin->http_server_daemon_v4 = GNUNET_SCHEDULER_NO_TASK;
1486 } 1466 }
1487 1467
1488 ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 1468 ret =
1489 GNUNET_SCHEDULER_NO_TASK, 1469 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1490 tv, 1470 GNUNET_SCHEDULER_NO_TASK, tv, wrs, wws,
1491 wrs, 1471 &http_server_daemon_v4_run, plugin);
1492 wws, &http_server_daemon_v4_run, plugin);
1493 } 1472 }
1494 if (daemon_handle == plugin->http_server_daemon_v6) 1473 if (daemon_handle == plugin->http_server_daemon_v6)
1495 { 1474 {
@@ -1499,11 +1478,10 @@ http_server_daemon_prepare (struct Plugin *plugin,
1499 plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK; 1478 plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK;
1500 } 1479 }
1501 1480
1502 ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 1481 ret =
1503 GNUNET_SCHEDULER_NO_TASK, 1482 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1504 tv, 1483 GNUNET_SCHEDULER_NO_TASK, tv, wrs, wws,
1505 wrs, 1484 &http_server_daemon_v6_run, plugin);
1506 wws, &http_server_daemon_v6_run, plugin);
1507 } 1485 }
1508 GNUNET_NETWORK_fdset_destroy (wrs); 1486 GNUNET_NETWORK_fdset_destroy (wrs);
1509 GNUNET_NETWORK_fdset_destroy (wws); 1487 GNUNET_NETWORK_fdset_destroy (wws);
@@ -1643,8 +1621,8 @@ curl_get_header_cb (void *ptr, size_t size, size_t nmemb, void *stream)
1643 if (tmp[len - 2] == 13) 1621 if (tmp[len - 2] == 13)
1644 tmp[len - 2] = '\0'; 1622 tmp[len - 2] = '\0';
1645 } 1623 }
1646 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1624 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connection %X: Header: %s\n", ps,
1647 "Connection %X: Header: %s\n", ps, tmp); 1625 tmp);
1648 } 1626 }
1649 GNUNET_free_non_null (tmp); 1627 GNUNET_free_non_null (tmp);
1650#endif 1628#endif
@@ -1791,8 +1769,8 @@ curl_send_cb (void *stream, size_t size, size_t nmemb, void *ptr)
1791 1769
1792 1770
1793static void 1771static void
1794curl_receive_mst_cb (void *cls, 1772curl_receive_mst_cb (void *cls, void *client,
1795 void *client, const struct GNUNET_MessageHeader *message) 1773 const struct GNUNET_MessageHeader *message)
1796{ 1774{
1797 struct Session *ps = cls; 1775 struct Session *ps = cls;
1798 struct GNUNET_TIME_Relative delay; 1776 struct GNUNET_TIME_Relative delay;
@@ -1805,11 +1783,12 @@ curl_receive_mst_cb (void *cls,
1805#if DEBUG_HTTP 1783#if DEBUG_HTTP
1806 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1784 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1807 "Connection %X: Forwarding message to transport service, type %u and size %u from `%s' (`%s')\n", 1785 "Connection %X: Forwarding message to transport service, type %u and size %u from `%s' (`%s')\n",
1808 ps, 1786 ps, ntohs (message->type), ntohs (message->size),
1809 ntohs (message->type), 1787 GNUNET_i2s (&(pc->identity)), http_plugin_address_to_string (NULL,
1810 ntohs (message->size), 1788 ps->
1811 GNUNET_i2s (&(pc->identity)), 1789 addr,
1812 http_plugin_address_to_string (NULL, ps->addr, ps->addrlen)); 1790 ps->
1791 addrlen));
1813#endif 1792#endif
1814 struct GNUNET_TRANSPORT_ATS_Information distance[2]; 1793 struct GNUNET_TRANSPORT_ATS_Information distance[2];
1815 1794
@@ -1818,12 +1797,10 @@ curl_receive_mst_cb (void *cls,
1818 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 1797 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
1819 distance[1].value = htonl (0); 1798 distance[1].value = htonl (0);
1820 1799
1821 delay = pc->plugin->env->receive (pc->plugin->env->cls, 1800 delay =
1822 &pc->identity, 1801 pc->plugin->env->receive (pc->plugin->env->cls, &pc->identity, message,
1823 message, 1802 (const struct GNUNET_TRANSPORT_ATS_Information
1824 (const struct 1803 *) &distance, 2, ps, ps->addr, ps->addrlen);
1825 GNUNET_TRANSPORT_ATS_Information *)
1826 &distance, 2, ps, ps->addr, ps->addrlen);
1827 pc->delay = delay; 1804 pc->delay = delay;
1828 if (pc->reset_task != GNUNET_SCHEDULER_NO_TASK) 1805 if (pc->reset_task != GNUNET_SCHEDULER_NO_TASK)
1829 GNUNET_SCHEDULER_cancel (pc->reset_task); 1806 GNUNET_SCHEDULER_cancel (pc->reset_task);
@@ -1865,11 +1842,11 @@ curl_receive_cb (void *stream, size_t size, size_t nmemb, void *ptr)
1865 return 0; 1842 return 0;
1866 } 1843 }
1867#if DEBUG_CONNECTIONS 1844#if DEBUG_CONNECTIONS
1868 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1845 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connection %X: %u bytes received\n", ps,
1869 "Connection %X: %u bytes received\n", ps, size * nmemb); 1846 size * nmemb);
1870#endif 1847#endif
1871 GNUNET_SERVER_mst_receive (ps->msgtok, ps, 1848 GNUNET_SERVER_mst_receive (ps->msgtok, ps, stream, size * nmemb, GNUNET_NO,
1872 stream, size * nmemb, GNUNET_NO, GNUNET_NO); 1849 GNUNET_NO);
1873 return (size * nmemb); 1850 return (size * nmemb);
1874} 1851}
1875 1852
@@ -1958,8 +1935,7 @@ curl_handle_finished (struct Plugin *plugin)
1958#if DEBUG_CONNECTIONS 1935#if DEBUG_CONNECTIONS
1959 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1936 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1960 "Connection %X: HTTP PUT connection to peer `%s' (`%s') was closed with HTTP code %u\n", 1937 "Connection %X: HTTP PUT connection to peer `%s' (`%s') was closed with HTTP code %u\n",
1961 ps, 1938 ps, GNUNET_i2s (&pc->identity),
1962 GNUNET_i2s (&pc->identity),
1963 http_plugin_address_to_string (NULL, ps->addr, 1939 http_plugin_address_to_string (NULL, ps->addr,
1964 ps->addrlen), http_result); 1940 ps->addrlen), http_result);
1965#endif 1941#endif
@@ -1995,8 +1971,7 @@ curl_handle_finished (struct Plugin *plugin)
1995#if DEBUG_CONNECTIONS 1971#if DEBUG_CONNECTIONS
1996 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1972 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1997 "Connection %X: HTTP GET connection to peer `%s' (`%s') was closed with HTTP code %u\n", 1973 "Connection %X: HTTP GET connection to peer `%s' (`%s') was closed with HTTP code %u\n",
1998 ps, 1974 ps, GNUNET_i2s (&pc->identity),
1999 GNUNET_i2s (&pc->identity),
2000 http_plugin_address_to_string (NULL, ps->addr, 1975 http_plugin_address_to_string (NULL, ps->addr,
2001 ps->addrlen), http_result); 1976 ps->addrlen), http_result);
2002#endif 1977#endif
@@ -2081,8 +2056,7 @@ curl_schedule (struct Plugin *plugin)
2081 mret = curl_multi_fdset (plugin->multi_handle, &rs, &ws, &es, &max); 2056 mret = curl_multi_fdset (plugin->multi_handle, &rs, &ws, &es, &max);
2082 if (mret != CURLM_OK) 2057 if (mret != CURLM_OK)
2083 { 2058 {
2084 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2059 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
2085 _("%s failed at %s:%d: `%s'\n"),
2086 "curl_multi_fdset", __FILE__, __LINE__, 2060 "curl_multi_fdset", __FILE__, __LINE__,
2087 curl_multi_strerror (mret)); 2061 curl_multi_strerror (mret));
2088 return GNUNET_SYSERR; 2062 return GNUNET_SYSERR;
@@ -2090,8 +2064,7 @@ curl_schedule (struct Plugin *plugin)
2090 mret = curl_multi_timeout (plugin->multi_handle, &to); 2064 mret = curl_multi_timeout (plugin->multi_handle, &to);
2091 if (mret != CURLM_OK) 2065 if (mret != CURLM_OK)
2092 { 2066 {
2093 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2067 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
2094 _("%s failed at %s:%d: `%s'\n"),
2095 "curl_multi_timeout", __FILE__, __LINE__, 2068 "curl_multi_timeout", __FILE__, __LINE__,
2096 curl_multi_strerror (mret)); 2069 curl_multi_strerror (mret));
2097 return GNUNET_SYSERR; 2070 return GNUNET_SYSERR;
@@ -2129,8 +2102,8 @@ curl_schedule (struct Plugin *plugin)
2129 * @return 0 2102 * @return 0
2130 */ 2103 */
2131static int 2104static int
2132curl_logger (CURL * curl, 2105curl_logger (CURL * curl, curl_infotype type, char *data, size_t size,
2133 curl_infotype type, char *data, size_t size, void *cls) 2106 void *cls)
2134{ 2107{
2135 if (type == CURLINFO_TEXT) 2108 if (type == CURLINFO_TEXT)
2136 { 2109 {
@@ -2217,8 +2190,7 @@ send_check_connections (struct Plugin *plugin, struct Session *ps)
2217 if (mret != CURLM_OK) 2190 if (mret != CURLM_OK)
2218 { 2191 {
2219 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2192 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2220 _("Connection: %X: %s failed at %s:%d: `%s'\n"), 2193 _("Connection: %X: %s failed at %s:%d: `%s'\n"), ps,
2221 ps,
2222 "curl_multi_add_handle", __FILE__, __LINE__, 2194 "curl_multi_add_handle", __FILE__, __LINE__,
2223 curl_multi_strerror (mret)); 2195 curl_multi_strerror (mret));
2224 return GNUNET_SYSERR; 2196 return GNUNET_SYSERR;
@@ -2330,8 +2302,7 @@ send_check_connections (struct Plugin *plugin, struct Session *ps)
2330 if (mret != CURLM_OK) 2302 if (mret != CURLM_OK)
2331 { 2303 {
2332 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2304 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2333 _("Connection: %X: %s failed at %s:%d: `%s'\n"), 2305 _("Connection: %X: %s failed at %s:%d: `%s'\n"), ps,
2334 ps,
2335 "curl_multi_add_handle", __FILE__, __LINE__, 2306 "curl_multi_add_handle", __FILE__, __LINE__,
2336 curl_multi_strerror (mret)); 2307 curl_multi_strerror (mret));
2337 return GNUNET_SYSERR; 2308 return GNUNET_SYSERR;
@@ -2371,9 +2342,8 @@ send_check_connections (struct Plugin *plugin, struct Session *ps)
2371 * 2342 *
2372 */ 2343 */
2373static struct Session * 2344static struct Session *
2374send_select_session (struct HTTP_PeerContext *pc, 2345send_select_session (struct HTTP_PeerContext *pc, const void *addr,
2375 const void *addr, size_t addrlen, 2346 size_t addrlen, int force_address, struct Session *session)
2376 int force_address, struct Session *session)
2377{ 2347{
2378 struct Session *tmp = NULL; 2348 struct Session *tmp = NULL;
2379 int addr_given = GNUNET_NO; 2349 int addr_given = GNUNET_NO;
@@ -2534,16 +2504,10 @@ send_select_session (struct HTTP_PeerContext *pc,
2534 * and does NOT mean that the message was not transmitted (DV) 2504 * and does NOT mean that the message was not transmitted (DV)
2535 */ 2505 */
2536static ssize_t 2506static ssize_t
2537http_plugin_send (void *cls, 2507http_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
2538 const struct GNUNET_PeerIdentity *target, 2508 const char *msgbuf, size_t msgbuf_size, unsigned int priority,
2539 const char *msgbuf, 2509 struct GNUNET_TIME_Relative to, struct Session *session,
2540 size_t msgbuf_size, 2510 const void *addr, size_t addrlen, int force_address,
2541 unsigned int priority,
2542 struct GNUNET_TIME_Relative to,
2543 struct Session *session,
2544 const void *addr,
2545 size_t addrlen,
2546 int force_address,
2547 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) 2511 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
2548{ 2512{
2549 struct Plugin *plugin = cls; 2513 struct Plugin *plugin = cls;
@@ -2566,9 +2530,7 @@ http_plugin_send (void *cls,
2566 GNUNET_assert (0); 2530 GNUNET_assert (0);
2567 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2531 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2568 "Transport tells me to send %u bytes to `%s' using %s (%s) and session: %X\n", 2532 "Transport tells me to send %u bytes to `%s' using %s (%s) and session: %X\n",
2569 msgbuf_size, 2533 msgbuf_size, GNUNET_i2s (target), force,
2570 GNUNET_i2s (target),
2571 force,
2572 http_plugin_address_to_string (NULL, addr, addrlen), session); 2534 http_plugin_address_to_string (NULL, addr, addrlen), session);
2573 GNUNET_free (force); 2535 GNUNET_free (force);
2574#endif 2536#endif
@@ -2582,13 +2544,12 @@ http_plugin_send (void *cls,
2582 pc->session_id_counter = 1; 2544 pc->session_id_counter = 1;
2583 pc->last_session = NULL; 2545 pc->last_session = NULL;
2584 memcpy (&pc->identity, target, sizeof (struct GNUNET_PeerIdentity)); 2546 memcpy (&pc->identity, target, sizeof (struct GNUNET_PeerIdentity));
2585 GNUNET_CONTAINER_multihashmap_put (plugin->peers, 2547 GNUNET_CONTAINER_multihashmap_put (plugin->peers, &pc->identity.hashPubKey,
2586 &pc->identity.hashPubKey,
2587 pc, 2548 pc,
2588 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 2549 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
2589 GNUNET_STATISTICS_update (plugin->env->stats, 2550 GNUNET_STATISTICS_update (plugin->env->stats,
2590 gettext_noop ("# HTTP peers active"), 2551 gettext_noop ("# HTTP peers active"), 1,
2591 1, GNUNET_NO); 2552 GNUNET_NO);
2592 } 2553 }
2593 ps = send_select_session (pc, addr, addrlen, force_address, session); 2554 ps = send_select_session (pc, addr, addrlen, force_address, session);
2594 /* session not existing, but address forced -> creating new session */ 2555 /* session not existing, but address forced -> creating new session */
@@ -2659,8 +2620,8 @@ http_plugin_send (void *cls,
2659 msg->transmit_cont = cont; 2620 msg->transmit_cont = cont;
2660 msg->transmit_cont_cls = cont_cls; 2621 msg->transmit_cont_cls = cont_cls;
2661 memcpy (msg->buf, msgbuf, msgbuf_size); 2622 memcpy (msg->buf, msgbuf, msgbuf_size);
2662 GNUNET_CONTAINER_DLL_insert (ps->pending_msgs_head, 2623 GNUNET_CONTAINER_DLL_insert (ps->pending_msgs_head, ps->pending_msgs_tail,
2663 ps->pending_msgs_tail, msg); 2624 msg);
2664 ps->queue_length_cur += msgbuf_size; 2625 ps->queue_length_cur += msgbuf_size;
2665 if (send_check_connections (plugin, ps) == GNUNET_SYSERR) 2626 if (send_check_connections (plugin, ps) == GNUNET_SYSERR)
2666 return GNUNET_SYSERR; 2627 return GNUNET_SYSERR;
@@ -2767,14 +2728,12 @@ append_port (void *cls, const char *hostname)
2767 * @param asc_cls closure for asc 2728 * @param asc_cls closure for asc
2768 */ 2729 */
2769static void 2730static void
2770http_plugin_address_pretty_printer (void *cls, 2731http_plugin_address_pretty_printer (void *cls, const char *type,
2771 const char *type, 2732 const void *addr, size_t addrlen,
2772 const void *addr,
2773 size_t addrlen,
2774 int numeric, 2733 int numeric,
2775 struct GNUNET_TIME_Relative timeout, 2734 struct GNUNET_TIME_Relative timeout,
2776 GNUNET_TRANSPORT_AddressStringCallback 2735 GNUNET_TRANSPORT_AddressStringCallback asc,
2777 asc, void *asc_cls) 2736 void *asc_cls)
2778{ 2737{
2779 struct PrettyPrinterContext *ppc; 2738 struct PrettyPrinterContext *ppc;
2780 const void *sb; 2739 const void *sb;
@@ -2963,16 +2922,15 @@ http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
2963 * @param addrlen number of bytes in addr 2922 * @param addrlen number of bytes in addr
2964 */ 2923 */
2965static void 2924static void
2966try_connection_reversal (void *cls, 2925try_connection_reversal (void *cls, const struct sockaddr *addr,
2967 const struct sockaddr *addr, socklen_t addrlen) 2926 socklen_t addrlen)
2968{ 2927{
2969 2928
2970} 2929}
2971 2930
2972static void 2931static void
2973tcp_nat_cb_add_addr (void *cls, 2932tcp_nat_cb_add_addr (void *cls, int add_remove, const struct sockaddr *addr,
2974 int add_remove, 2933 socklen_t addrlen)
2975 const struct sockaddr *addr, socklen_t addrlen)
2976{ 2934{
2977 struct Plugin *plugin = cls; 2935 struct Plugin *plugin = cls;
2978 struct IPv4HttpAddress *t4 = NULL; 2936 struct IPv4HttpAddress *t4 = NULL;
@@ -3000,8 +2958,7 @@ tcp_nat_cb_add_addr (void *cls,
3000 { 2958 {
3001 w_t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddressWrapper)); 2959 w_t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddressWrapper));
3002 t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddress)); 2960 t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddress));
3003 memcpy (&t4->ipv4_addr, 2961 memcpy (&t4->ipv4_addr, &((struct sockaddr_in *) addr)->sin_addr,
3004 &((struct sockaddr_in *) addr)->sin_addr,
3005 sizeof (struct in_addr)); 2962 sizeof (struct in_addr));
3006 t4->port = htons (plugin->port_inbound); 2963 t4->port = htons (plugin->port_inbound);
3007 2964
@@ -3010,9 +2967,8 @@ tcp_nat_cb_add_addr (void *cls,
3010 GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head, 2967 GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head,
3011 plugin->ipv4_addr_tail, w_t4); 2968 plugin->ipv4_addr_tail, w_t4);
3012 } 2969 }
3013 plugin->env->notify_address (plugin->env->cls, 2970 plugin->env->notify_address (plugin->env->cls, add_remove, w_t4->addr,
3014 add_remove, 2971 sizeof (struct IPv4HttpAddress));
3015 w_t4->addr, sizeof (struct IPv4HttpAddress));
3016 2972
3017 break; 2973 break;
3018 case AF_INET6: 2974 case AF_INET6:
@@ -3032,8 +2988,7 @@ tcp_nat_cb_add_addr (void *cls,
3032 w_t6 = GNUNET_malloc (sizeof (struct IPv6HttpAddressWrapper)); 2988 w_t6 = GNUNET_malloc (sizeof (struct IPv6HttpAddressWrapper));
3033 t6 = GNUNET_malloc (sizeof (struct IPv6HttpAddress)); 2989 t6 = GNUNET_malloc (sizeof (struct IPv6HttpAddress));
3034 2990
3035 memcpy (&t6->ipv6_addr, 2991 memcpy (&t6->ipv6_addr, &((struct sockaddr_in6 *) addr)->sin6_addr,
3036 &((struct sockaddr_in6 *) addr)->sin6_addr,
3037 sizeof (struct in6_addr)); 2992 sizeof (struct in6_addr));
3038 t6->port = htons (plugin->port_inbound); 2993 t6->port = htons (plugin->port_inbound);
3039 2994
@@ -3042,9 +2997,8 @@ tcp_nat_cb_add_addr (void *cls,
3042 GNUNET_CONTAINER_DLL_insert (plugin->ipv6_addr_head, 2997 GNUNET_CONTAINER_DLL_insert (plugin->ipv6_addr_head,
3043 plugin->ipv6_addr_tail, w_t6); 2998 plugin->ipv6_addr_tail, w_t6);
3044 } 2999 }
3045 plugin->env->notify_address (plugin->env->cls, 3000 plugin->env->notify_address (plugin->env->cls, add_remove, w_t6->addr,
3046 add_remove, 3001 sizeof (struct IPv6HttpAddress));
3047 w_t6->addr, sizeof (struct IPv6HttpAddress));
3048 break; 3002 break;
3049 default: 3003 default:
3050 return; 3004 return;
@@ -3053,9 +3007,8 @@ tcp_nat_cb_add_addr (void *cls,
3053} 3007}
3054 3008
3055static void 3009static void
3056tcp_nat_cb_remove_addr (void *cls, 3010tcp_nat_cb_remove_addr (void *cls, int add_remove, const struct sockaddr *addr,
3057 int add_remove, 3011 socklen_t addrlen)
3058 const struct sockaddr *addr, socklen_t addrlen)
3059{ 3012{
3060 struct Plugin *plugin = cls; 3013 struct Plugin *plugin = cls;
3061 struct IPv4HttpAddressWrapper *w_t4 = NULL; 3014 struct IPv4HttpAddressWrapper *w_t4 = NULL;
@@ -3079,12 +3032,11 @@ tcp_nat_cb_remove_addr (void *cls,
3079 } 3032 }
3080 if (w_t4 == NULL) 3033 if (w_t4 == NULL)
3081 return; 3034 return;
3082 plugin->env->notify_address (plugin->env->cls, 3035 plugin->env->notify_address (plugin->env->cls, add_remove, w_t4->addr,
3083 add_remove, 3036 sizeof (struct IPv4HttpAddress));
3084 w_t4->addr, sizeof (struct IPv4HttpAddress));
3085 3037
3086 GNUNET_CONTAINER_DLL_remove (plugin->ipv4_addr_head, 3038 GNUNET_CONTAINER_DLL_remove (plugin->ipv4_addr_head, plugin->ipv4_addr_tail,
3087 plugin->ipv4_addr_tail, w_t4); 3039 w_t4);
3088 GNUNET_free (w_t4->addr); 3040 GNUNET_free (w_t4->addr);
3089 GNUNET_free (w_t4); 3041 GNUNET_free (w_t4);
3090 break; 3042 break;
@@ -3102,12 +3054,11 @@ tcp_nat_cb_remove_addr (void *cls,
3102 } 3054 }
3103 if (w_t6 == NULL) 3055 if (w_t6 == NULL)
3104 return; 3056 return;
3105 plugin->env->notify_address (plugin->env->cls, 3057 plugin->env->notify_address (plugin->env->cls, add_remove, w_t6->addr,
3106 add_remove, 3058 sizeof (struct IPv6HttpAddress));
3107 w_t6->addr, sizeof (struct IPv6HttpAddress));
3108 3059
3109 GNUNET_CONTAINER_DLL_remove (plugin->ipv6_addr_head, 3060 GNUNET_CONTAINER_DLL_remove (plugin->ipv6_addr_head, plugin->ipv6_addr_tail,
3110 plugin->ipv6_addr_tail, w_t6); 3061 w_t6);
3111 GNUNET_free (w_t6->addr); 3062 GNUNET_free (w_t6->addr);
3112 GNUNET_free (w_t6); 3063 GNUNET_free (w_t6);
3113 break; 3064 break;
@@ -3127,14 +3078,12 @@ tcp_nat_cb_remove_addr (void *cls,
3127 * @param addrlen actual lenght of the address 3078 * @param addrlen actual lenght of the address
3128 */ 3079 */
3129static void 3080static void
3130tcp_nat_port_map_callback (void *cls, 3081tcp_nat_port_map_callback (void *cls, int add_remove,
3131 int add_remove,
3132 const struct sockaddr *addr, socklen_t addrlen) 3082 const struct sockaddr *addr, socklen_t addrlen)
3133{ 3083{
3134 GNUNET_assert (cls != NULL); 3084 GNUNET_assert (cls != NULL);
3135#if DEBUG_HTTP 3085#if DEBUG_HTTP
3136 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 3086 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "NPMC called to %s address `%s'\n",
3137 "NPMC called to %s address `%s'\n",
3138 (add_remove == GNUNET_YES) ? "remove" : "add", 3087 (add_remove == GNUNET_YES) ? "remove" : "add",
3139 GNUNET_a2s (addr, addrlen)); 3088 GNUNET_a2s (addr, addrlen));
3140#endif 3089#endif
@@ -3242,8 +3191,8 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
3242 GNUNET_free (plugin); 3191 GNUNET_free (plugin);
3243 GNUNET_free (api); 3192 GNUNET_free (api);
3244#if DEBUG_HTTP 3193#if DEBUG_HTTP
3245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unload %s plugin complete...\n",
3246 "Unload %s plugin complete...\n", PROTOCOL_PREFIX); 3195 PROTOCOL_PREFIX);
3247#endif 3196#endif
3248 return NULL; 3197 return NULL;
3249} 3198}
@@ -3304,8 +3253,8 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3304 3253
3305 GNUNET_assert (cls != NULL); 3254 GNUNET_assert (cls != NULL);
3306#if DEBUG_HTTP 3255#if DEBUG_HTTP
3307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting %s plugin...\n",
3308 "Starting %s plugin...\n", PROTOCOL_PREFIX); 3257 PROTOCOL_PREFIX);
3309#endif 3258#endif
3310 GNUNET_asprintf (&component_name, "transport-%s", PROTOCOL_PREFIX); 3259 GNUNET_asprintf (&component_name, "transport-%s", PROTOCOL_PREFIX);
3311 3260
@@ -3333,8 +3282,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3333 3282
3334 3283
3335 if (GNUNET_OK != 3284 if (GNUNET_OK !=
3336 GNUNET_CONFIGURATION_get_value_number (env->cfg, 3285 GNUNET_CONFIGURATION_get_value_number (env->cfg, component_name,
3337 component_name,
3338 "MAX_CONNECTIONS", &tneigh)) 3286 "MAX_CONNECTIONS", &tneigh))
3339 tneigh = 128; 3287 tneigh = 128;
3340 plugin->max_connect_per_transport = tneigh; 3288 plugin->max_connect_per_transport = tneigh;
@@ -3343,34 +3291,32 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3343 /* Use IPv6? */ 3291 /* Use IPv6? */
3344 if (GNUNET_CONFIGURATION_have_value (env->cfg, component_name, "USE_IPv6")) 3292 if (GNUNET_CONFIGURATION_have_value (env->cfg, component_name, "USE_IPv6"))
3345 { 3293 {
3346 plugin->use_ipv6 = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 3294 plugin->use_ipv6 =
3347 component_name, 3295 GNUNET_CONFIGURATION_get_value_yesno (env->cfg, component_name,
3348 "USE_IPv6"); 3296 "USE_IPv6");
3349 } 3297 }
3350 /* Use IPv4? */ 3298 /* Use IPv4? */
3351 if (GNUNET_CONFIGURATION_have_value (env->cfg, component_name, "USE_IPv4")) 3299 if (GNUNET_CONFIGURATION_have_value (env->cfg, component_name, "USE_IPv4"))
3352 { 3300 {
3353 plugin->use_ipv4 = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 3301 plugin->use_ipv4 =
3354 component_name, 3302 GNUNET_CONFIGURATION_get_value_yesno (env->cfg, component_name,
3355 "USE_IPv4"); 3303 "USE_IPv4");
3356 } 3304 }
3357 /* use local addresses? */ 3305 /* use local addresses? */
3358 3306
3359 if (GNUNET_CONFIGURATION_have_value (env->cfg, 3307 if (GNUNET_CONFIGURATION_have_value
3360 component_name, "USE_LOCALADDR")) 3308 (env->cfg, component_name, "USE_LOCALADDR"))
3361 { 3309 {
3362 plugin->use_localaddresses = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 3310 plugin->use_localaddresses =
3363 component_name, 3311 GNUNET_CONFIGURATION_get_value_yesno (env->cfg, component_name,
3364 "USE_LOCALADDR"); 3312 "USE_LOCALADDR");
3365 } 3313 }
3366 /* Reading port number from config file */ 3314 /* Reading port number from config file */
3367 if ((GNUNET_OK != 3315 if ((GNUNET_OK !=
3368 GNUNET_CONFIGURATION_get_value_number (env->cfg, 3316 GNUNET_CONFIGURATION_get_value_number (env->cfg, component_name, "PORT",
3369 component_name, 3317 &port)) || (port > 65535))
3370 "PORT", &port)) || (port > 65535))
3371 { 3318 {
3372 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 3319 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, component_name,
3373 component_name,
3374 _ 3320 _
3375 ("Require valid port number for transport plugin `%s' in configuration!\n"), 3321 ("Require valid port number for transport plugin `%s' in configuration!\n"),
3376 PROTOCOL_PREFIX); 3322 PROTOCOL_PREFIX);
@@ -3387,7 +3333,8 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3387 GNUNET_CONFIGURATION_get_value_string (env->cfg, 3333 GNUNET_CONFIGURATION_get_value_string (env->cfg,
3388 component_name, 3334 component_name,
3389 "BINDTO4", 3335 "BINDTO4",
3390 &plugin->bind_hostname)); 3336 &plugin->
3337 bind_hostname));
3391 plugin->bind4_address = GNUNET_malloc (sizeof (struct sockaddr_in)); 3338 plugin->bind4_address = GNUNET_malloc (sizeof (struct sockaddr_in));
3392 plugin->bind4_address->sin_family = AF_INET; 3339 plugin->bind4_address->sin_family = AF_INET;
3393 plugin->bind4_address->sin_port = htons (port); 3340 plugin->bind4_address->sin_port = htons (port);
@@ -3398,8 +3345,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3398 (AF_INET, plugin->bind_hostname, 3345 (AF_INET, plugin->bind_hostname,
3399 &plugin->bind4_address->sin_addr) <= 0) 3346 &plugin->bind4_address->sin_addr) <= 0)
3400 { 3347 {
3401 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 3348 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, component_name,
3402 component_name,
3403 _ 3349 _
3404 ("Misconfigured address to bind to in configuration!\n")); 3350 ("Misconfigured address to bind to in configuration!\n"));
3405 GNUNET_free (plugin->bind4_address); 3351 GNUNET_free (plugin->bind4_address);
@@ -3414,10 +3360,10 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3414 if ((plugin->use_ipv6 == GNUNET_YES) && 3360 if ((plugin->use_ipv6 == GNUNET_YES) &&
3415 (GNUNET_CONFIGURATION_have_value (env->cfg, component_name, "BINDTO6"))) 3361 (GNUNET_CONFIGURATION_have_value (env->cfg, component_name, "BINDTO6")))
3416 { 3362 {
3417 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, 3363 if (GNUNET_OK ==
3418 component_name, 3364 GNUNET_CONFIGURATION_get_value_string (env->cfg, component_name,
3419 "BINDTO6", 3365 "BINDTO6",
3420 &plugin->bind_hostname)) 3366 &plugin->bind_hostname))
3421 { 3367 {
3422 plugin->bind6_address = GNUNET_malloc (sizeof (struct sockaddr_in6)); 3368 plugin->bind6_address = GNUNET_malloc (sizeof (struct sockaddr_in6));
3423 plugin->bind6_address->sin6_family = AF_INET6; 3369 plugin->bind6_address->sin6_family = AF_INET6;
@@ -3428,8 +3374,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3428 (AF_INET6, plugin->bind_hostname, 3374 (AF_INET6, plugin->bind_hostname,
3429 &plugin->bind6_address->sin6_addr) <= 0) 3375 &plugin->bind6_address->sin6_addr) <= 0)
3430 { 3376 {
3431 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 3377 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, component_name,
3432 component_name,
3433 _ 3378 _
3434 ("Misconfigured address to bind to in configuration!\n")); 3379 ("Misconfigured address to bind to in configuration!\n"));
3435 GNUNET_free (plugin->bind6_address); 3380 GNUNET_free (plugin->bind6_address);
@@ -3445,22 +3390,17 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3445 /* Reading HTTPS crypto related configuration */ 3390 /* Reading HTTPS crypto related configuration */
3446 /* Get crypto init string from config */ 3391 /* Get crypto init string from config */
3447 if ((GNUNET_OK != 3392 if ((GNUNET_OK !=
3448 GNUNET_CONFIGURATION_get_value_string (env->cfg, 3393 GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-https",
3449 "transport-https",
3450 "CRYPTO_INIT", 3394 "CRYPTO_INIT",
3451 &plugin->crypto_init)) || 3395 &plugin->crypto_init)) ||
3452 (GNUNET_OK != 3396 (GNUNET_OK !=
3453 GNUNET_CONFIGURATION_get_value_filename (env->cfg, 3397 GNUNET_CONFIGURATION_get_value_filename (env->cfg, "transport-https",
3454 "transport-https", 3398 "KEY_FILE", &key_file)) ||
3455 "KEY_FILE",
3456 &key_file)) ||
3457 (GNUNET_OK != 3399 (GNUNET_OK !=
3458 GNUNET_CONFIGURATION_get_value_filename (env->cfg, 3400 GNUNET_CONFIGURATION_get_value_filename (env->cfg, "transport-https",
3459 "transport-https",
3460 "CERT_FILE", &cert_file))) 3401 "CERT_FILE", &cert_file)))
3461 { 3402 {
3462 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 3403 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "https",
3463 "https",
3464 _ 3404 _
3465 ("Required configuration options missing in section `%s'\n"), 3405 ("Required configuration options missing in section `%s'\n"),
3466 "transport-https"); 3406 "transport-https");
@@ -3472,8 +3412,8 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3472 } 3412 }
3473 3413
3474 /* read key & certificates from file */ 3414 /* read key & certificates from file */
3475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3415 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loading TLS certificate `%s' `%s'\n",
3476 "Loading TLS certificate `%s' `%s'\n", key_file, cert_file); 3416 key_file, cert_file);
3477 3417
3478 plugin->key = load_certificate (key_file); 3418 plugin->key = load_certificate (key_file);
3479 plugin->cert = load_certificate (cert_file); 3419 plugin->cert = load_certificate (cert_file);
@@ -3491,14 +3431,14 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3491 "No usable TLS certificate found, creating certificate\n"); 3431 "No usable TLS certificate found, creating certificate\n");
3492#endif 3432#endif
3493 errno = 0; 3433 errno = 0;
3494 certcreation = GNUNET_OS_start_process (NULL, NULL, 3434 certcreation =
3495 "gnunet-transport-certificate-creation", 3435 GNUNET_OS_start_process (NULL, NULL,
3496 "gnunet-transport-certificate-creation", 3436 "gnunet-transport-certificate-creation",
3497 key_file, cert_file, NULL); 3437 "gnunet-transport-certificate-creation",
3438 key_file, cert_file, NULL);
3498 if (certcreation == NULL) 3439 if (certcreation == NULL)
3499 { 3440 {
3500 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 3441 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "https",
3501 "https",
3502 _ 3442 _
3503 ("Could not create a new TLS certificate, program `gnunet-transport-certificate-creation' could not be started!\n")); 3443 ("Could not create a new TLS certificate, program `gnunet-transport-certificate-creation' could not be started!\n"));
3504 GNUNET_free (key_file); 3444 GNUNET_free (key_file);
@@ -3514,8 +3454,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3514 } 3454 }
3515 if ((plugin->key == NULL) || (plugin->cert == NULL)) 3455 if ((plugin->key == NULL) || (plugin->cert == NULL))
3516 { 3456 {
3517 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 3457 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "https",
3518 "https",
3519 _ 3458 _
3520 ("No usable TLS certificate found and creating one failed!\n"), 3459 ("No usable TLS certificate found and creating one failed!\n"),
3521 "transport-https"); 3460 "transport-https");
@@ -3549,15 +3488,14 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3549#if BUILD_HTTPS 3488#if BUILD_HTTPS
3550 MHD_USE_SSL | 3489 MHD_USE_SSL |
3551#endif 3490#endif
3552 MHD_USE_IPv6, 3491 MHD_USE_IPv6, port,
3553 port,
3554 &mhd_accept_cb, plugin, 3492 &mhd_accept_cb, plugin,
3555 &mhd_access_cb, plugin, 3493 &mhd_access_cb, plugin,
3556 MHD_OPTION_SOCK_ADDR, 3494 MHD_OPTION_SOCK_ADDR,
3557 tmp, 3495 tmp,
3558 MHD_OPTION_CONNECTION_LIMIT, 3496 MHD_OPTION_CONNECTION_LIMIT,
3559 (unsigned int) 3497 (unsigned int) plugin->
3560 plugin->max_connect_per_transport, 3498 max_connect_per_transport,
3561#if BUILD_HTTPS 3499#if BUILD_HTTPS
3562 MHD_OPTION_HTTPS_PRIORITIES, 3500 MHD_OPTION_HTTPS_PRIORITIES,
3563 plugin->crypto_init, 3501 plugin->crypto_init,
@@ -3589,16 +3527,15 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3589#if BUILD_HTTPS 3527#if BUILD_HTTPS
3590 MHD_USE_SSL | 3528 MHD_USE_SSL |
3591#endif 3529#endif
3592 MHD_NO_FLAG, 3530 MHD_NO_FLAG, port,
3593 port,
3594 &mhd_accept_cb, plugin, 3531 &mhd_accept_cb, plugin,
3595 &mhd_access_cb, plugin, 3532 &mhd_access_cb, plugin,
3596 MHD_OPTION_SOCK_ADDR, 3533 MHD_OPTION_SOCK_ADDR,
3597 (struct sockaddr_in *) 3534 (struct sockaddr_in *)
3598 plugin->bind4_address, 3535 plugin->bind4_address,
3599 MHD_OPTION_CONNECTION_LIMIT, 3536 MHD_OPTION_CONNECTION_LIMIT,
3600 (unsigned int) 3537 (unsigned int) plugin->
3601 plugin->max_connect_per_transport, 3538 max_connect_per_transport,
3602#if BUILD_HTTPS 3539#if BUILD_HTTPS
3603 MHD_OPTION_HTTPS_PRIORITIES, 3540 MHD_OPTION_HTTPS_PRIORITIES,
3604 plugin->crypto_init, 3541 plugin->crypto_init,
@@ -3685,8 +3622,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3685 3622
3686 if (NULL == plugin->multi_handle) 3623 if (NULL == plugin->multi_handle)
3687 { 3624 {
3688 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 3625 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, component_name,
3689 component_name,
3690 _ 3626 _
3691 ("Could not initialize curl multi handle, failed to start %s plugin!\n"), 3627 ("Could not initialize curl multi handle, failed to start %s plugin!\n"),
3692 PROTOCOL_PREFIX); 3628 PROTOCOL_PREFIX);
@@ -3695,19 +3631,17 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3695 return NULL; 3631 return NULL;
3696 } 3632 }
3697 3633
3698 ret = GNUNET_SERVICE_get_server_addresses (component_name, 3634 ret =
3699 env->cfg, &addrs, &addrlens); 3635 GNUNET_SERVICE_get_server_addresses (component_name, env->cfg, &addrs,
3636 &addrlens);
3700 3637
3701 if (ret != GNUNET_SYSERR) 3638 if (ret != GNUNET_SYSERR)
3702 { 3639 {
3703 plugin->nat = GNUNET_NAT_register (env->cfg, 3640 plugin->nat =
3704 GNUNET_YES, 3641 GNUNET_NAT_register (env->cfg, GNUNET_YES, port, (unsigned int) ret,
3705 port, 3642 (const struct sockaddr **) addrs, addrlens,
3706 (unsigned int) ret, 3643 &tcp_nat_port_map_callback,
3707 (const struct sockaddr **) addrs, 3644 &try_connection_reversal, plugin);
3708 addrlens,
3709 &tcp_nat_port_map_callback,
3710 &try_connection_reversal, plugin);
3711 while (ret > 0) 3645 while (ret > 0)
3712 { 3646 {
3713 ret--; 3647 ret--;
@@ -3719,11 +3653,9 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3719 } 3653 }
3720 else 3654 else
3721 { 3655 {
3722 plugin->nat = GNUNET_NAT_register (env->cfg, 3656 plugin->nat =
3723 GNUNET_YES, 3657 GNUNET_NAT_register (env->cfg, GNUNET_YES, 0, 0, NULL, NULL, NULL,
3724 0, 3658 &try_connection_reversal, plugin);
3725 0, NULL, NULL,
3726 NULL, &try_connection_reversal, plugin);
3727 } 3659 }
3728 3660
3729 plugin->peers = GNUNET_CONTAINER_multihashmap_create (10); 3661 plugin->peers = GNUNET_CONTAINER_multihashmap_create (10);
diff --git a/src/transport/plugin_transport_smtp.c b/src/transport/plugin_transport_smtp.c
index 074bc16fc..1b9f5fb72 100644
--- a/src/transport/plugin_transport_smtp.c
+++ b/src/transport/plugin_transport_smtp.c
@@ -145,8 +145,8 @@ static GNUNET_CronTime last_transmission;
145/** ******************** Base64 encoding ***********/ 145/** ******************** Base64 encoding ***********/
146 146
147#define FILLCHAR '=' 147#define FILLCHAR '='
148static char *cvt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 148static char *cvt =
149 "abcdefghijklmnopqrstuvwxyz" "0123456789+/"; 149 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789+/";
150 150
151/** 151/**
152 * Encode into Base64. 152 * Encode into Base64.
@@ -171,8 +171,10 @@ base64_encode (const char *data, unsigned int len, char **output)
171 (*output)[ret++] = '\n'; \ 171 (*output)[ret++] = '\n'; \
172 } 172 }
173 ret = 0; 173 ret = 0;
174 opt = GNUNET_malloc (2 + (((len * 4 / 3) + 8) * (MAX_CHAR_PER_LINE + 2)) / 174 opt =
175 MAX_CHAR_PER_LINE); 175 GNUNET_malloc (2 +
176 (((len * 4 / 3) + 8) * (MAX_CHAR_PER_LINE +
177 2)) / MAX_CHAR_PER_LINE);
176 /* message must start with \r\n for libesmtp */ 178 /* message must start with \r\n for libesmtp */
177 *output = opt; 179 *output = opt;
178 opt[0] = '\r'; 180 opt[0] = '\r';
@@ -361,17 +363,14 @@ listenAndDistribute (void *unused)
361 if (ntohs (mp->header.size) != size) 363 if (ntohs (mp->header.size) != size)
362 { 364 {
363 GNUNET_GE_LOG (ectx, 365 GNUNET_GE_LOG (ectx,
364 GNUNET_GE_WARNING | GNUNET_GE_BULK | 366 GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
365 GNUNET_GE_USER, 367 _("Received malformed message via %s. Ignored.\n"),
366 _
367 ("Received malformed message via %s. Ignored.\n"),
368 "SMTP"); 368 "SMTP");
369#if DEBUG_SMTP 369#if DEBUG_SMTP
370 GNUNET_GE_LOG (ectx, 370 GNUNET_GE_LOG (ectx,
371 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | 371 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
372 GNUNET_GE_USER, 372 "Size returned by base64=%d, in the msg=%d.\n", size,
373 "Size returned by base64=%d, in the msg=%d.\n", 373 ntohl (mp->size));
374 size, ntohl (mp->size));
375#endif 374#endif
376 GNUNET_free (out); 375 GNUNET_free (out);
377 goto END; 376 goto END;
@@ -384,8 +383,7 @@ listenAndDistribute (void *unused)
384 coreMP->tsession = NULL; 383 coreMP->tsession = NULL;
385 coreMP->sender = mp->sender; 384 coreMP->sender = mp->sender;
386#if DEBUG_SMTP 385#if DEBUG_SMTP
387 GNUNET_GE_LOG (ectx, 386 GNUNET_GE_LOG (ectx, GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
388 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
389 "SMTP message passed to the core.\n"); 387 "SMTP message passed to the core.\n");
390#endif 388#endif
391 389
@@ -393,8 +391,7 @@ listenAndDistribute (void *unused)
393 } 391 }
394END: 392END:
395#if DEBUG_SMTP 393#if DEBUG_SMTP
396 GNUNET_GE_LOG (ectx, 394 GNUNET_GE_LOG (ectx, GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
397 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
398 "SMTP message processed.\n"); 395 "SMTP message processed.\n");
399#endif 396#endif
400 if (fdes != NULL) 397 if (fdes != NULL)
@@ -423,8 +420,9 @@ api_verify_hello (const GNUNET_MessageHello * hello)
423 maddr = (const EmailAddress *) &hello[1]; 420 maddr = (const EmailAddress *) &hello[1];
424 if ((ntohs (hello->header.size) != 421 if ((ntohs (hello->header.size) !=
425 sizeof (GNUNET_MessageHello) + ntohs (hello->senderAddressSize)) || 422 sizeof (GNUNET_MessageHello) + ntohs (hello->senderAddressSize)) ||
426 (maddr->senderAddress[ntohs (hello->senderAddressSize) - 1 - 423 (maddr->
427 FILTER_STRING_SIZE] != '\0')) 424 senderAddress[ntohs (hello->senderAddressSize) - 1 -
425 FILTER_STRING_SIZE] != '\0'))
428 { 426 {
429 GNUNET_GE_BREAK (ectx, 0); 427 GNUNET_GE_BREAK (ectx, 0);
430 return GNUNET_SYSERR; /* obviously invalid */ 428 return GNUNET_SYSERR; /* obviously invalid */
@@ -449,13 +447,11 @@ api_create_hello ()
449 EmailAddress *haddr; 447 EmailAddress *haddr;
450 int i; 448 int i;
451 449
452 GNUNET_GC_get_configuration_value_string (coreAPI->cfg, 450 GNUNET_GC_get_configuration_value_string (coreAPI->cfg, "SMTP", "FILTER",
453 "SMTP", "FILTER",
454 "X-mailer: GNUnet", &filter); 451 "X-mailer: GNUnet", &filter);
455 if (NULL == strstr (filter, ": ")) 452 if (NULL == strstr (filter, ": "))
456 { 453 {
457 GNUNET_GE_LOG (ectx, 454 GNUNET_GE_LOG (ectx, GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
458 GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
459 _("SMTP filter string to invalid, lacks ': '\n")); 455 _("SMTP filter string to invalid, lacks ': '\n"));
460 GNUNET_free (filter); 456 GNUNET_free (filter);
461 return NULL; 457 return NULL;
@@ -464,8 +460,7 @@ api_create_hello ()
464 if (strlen (filter) > FILTER_STRING_SIZE) 460 if (strlen (filter) > FILTER_STRING_SIZE)
465 { 461 {
466 filter[FILTER_STRING_SIZE] = '\0'; 462 filter[FILTER_STRING_SIZE] = '\0';
467 GNUNET_GE_LOG (ectx, 463 GNUNET_GE_LOG (ectx, GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
468 GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
469 _("SMTP filter string to long, capped to `%s'\n"), filter); 464 _("SMTP filter string to long, capped to `%s'\n"), filter);
470 } 465 }
471 i = (strlen (email) + 8) & (~7); /* make multiple of 8 */ 466 i = (strlen (email) + 8) & (~7); /* make multiple of 8 */
@@ -521,8 +516,8 @@ get_message (void **buf, int *len, void *cls)
521 * @return GNUNET_SYSERR on error, GNUNET_OK on success 516 * @return GNUNET_SYSERR on error, GNUNET_OK on success
522 */ 517 */
523static int 518static int
524api_send (GNUNET_TSession * tsession, 519api_send (GNUNET_TSession * tsession, const void *msg, const unsigned int size,
525 const void *msg, const unsigned int size, int important) 520 int important)
526{ 521{
527 const GNUNET_MessageHello *hello; 522 const GNUNET_MessageHello *hello;
528 const EmailAddress *haddr; 523 const EmailAddress *haddr;
@@ -561,10 +556,9 @@ api_send (GNUNET_TSession * tsession,
561 { 556 {
562 GNUNET_GE_LOG (ectx, 557 GNUNET_GE_LOG (ectx,
563 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER | 558 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER |
564 GNUNET_GE_IMMEDIATE, 559 GNUNET_GE_IMMEDIATE, _("SMTP: `%s' failed: %s.\n"),
565 _("SMTP: `%s' failed: %s.\n"), 560 "smtp_create_session", smtp_strerror (smtp_errno (), ebuf,
566 "smtp_create_session", 561 EBUF_LEN));
567 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
568 GNUNET_mutex_unlock (lock); 562 GNUNET_mutex_unlock (lock);
569 return GNUNET_SYSERR; 563 return GNUNET_SYSERR;
570 } 564 }
@@ -572,10 +566,9 @@ api_send (GNUNET_TSession * tsession,
572 { 566 {
573 GNUNET_GE_LOG (ectx, 567 GNUNET_GE_LOG (ectx,
574 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER | 568 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER |
575 GNUNET_GE_IMMEDIATE, 569 GNUNET_GE_IMMEDIATE, _("SMTP: `%s' failed: %s.\n"),
576 _("SMTP: `%s' failed: %s.\n"), 570 "smtp_set_server", smtp_strerror (smtp_errno (), ebuf,
577 "smtp_set_server", 571 EBUF_LEN));
578 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
579 smtp_destroy_session (session); 572 smtp_destroy_session (session);
580 GNUNET_mutex_unlock (lock); 573 GNUNET_mutex_unlock (lock);
581 return GNUNET_SYSERR; 574 return GNUNET_SYSERR;
@@ -586,10 +579,9 @@ api_send (GNUNET_TSession * tsession,
586 { 579 {
587 GNUNET_GE_LOG (ectx, 580 GNUNET_GE_LOG (ectx,
588 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 581 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
589 GNUNET_GE_BULK, 582 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"),
590 _("SMTP: `%s' failed: %s.\n"), 583 "smtp_add_message", smtp_strerror (smtp_errno (), ebuf,
591 "smtp_add_message", 584 EBUF_LEN));
592 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
593 smtp_destroy_session (session); 585 smtp_destroy_session (session);
594 GNUNET_mutex_unlock (lock); 586 GNUNET_mutex_unlock (lock);
595 return GNUNET_SYSERR; 587 return GNUNET_SYSERR;
@@ -606,10 +598,9 @@ api_send (GNUNET_TSession * tsession,
606 { 598 {
607 GNUNET_GE_LOG (ectx, 599 GNUNET_GE_LOG (ectx,
608 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 600 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
609 GNUNET_GE_BULK, 601 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"),
610 _("SMTP: `%s' failed: %s.\n"), 602 "smtp_set_header", smtp_strerror (smtp_errno (), ebuf,
611 "smtp_set_header", 603 EBUF_LEN));
612 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
613 smtp_destroy_session (session); 604 smtp_destroy_session (session);
614 GNUNET_mutex_unlock (lock); 605 GNUNET_mutex_unlock (lock);
615 GNUNET_free (filter); 606 GNUNET_free (filter);
@@ -630,19 +621,17 @@ api_send (GNUNET_TSession * tsession,
630 { 621 {
631 GNUNET_GE_LOG (ectx, 622 GNUNET_GE_LOG (ectx,
632 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 623 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
633 GNUNET_GE_BULK, 624 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"),
634 _("SMTP: `%s' failed: %s.\n"), 625 "smtp_size_set_estimate", smtp_strerror (smtp_errno (), ebuf,
635 "smtp_size_set_estimate", 626 EBUF_LEN));
636 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
637 } 627 }
638 if (0 == smtp_set_messagecb (message, &get_message, &gm_cls)) 628 if (0 == smtp_set_messagecb (message, &get_message, &gm_cls))
639 { 629 {
640 GNUNET_GE_LOG (ectx, 630 GNUNET_GE_LOG (ectx,
641 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 631 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
642 GNUNET_GE_BULK, 632 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"),
643 _("SMTP: `%s' failed: %s.\n"), 633 "smtp_set_messagecb", smtp_strerror (smtp_errno (), ebuf,
644 "smtp_set_messagecb", 634 EBUF_LEN));
645 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
646 smtp_destroy_session (session); 635 smtp_destroy_session (session);
647 GNUNET_mutex_unlock (lock); 636 GNUNET_mutex_unlock (lock);
648 GNUNET_free (gm_cls.ebody); 637 GNUNET_free (gm_cls.ebody);
@@ -653,10 +642,9 @@ api_send (GNUNET_TSession * tsession,
653 { 642 {
654 GNUNET_GE_LOG (ectx, 643 GNUNET_GE_LOG (ectx,
655 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 644 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
656 GNUNET_GE_BULK, 645 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"),
657 _("SMTP: `%s' failed: %s.\n"), 646 "smtp_add_recipient", smtp_strerror (smtp_errno (), ebuf,
658 "smtp_add_recipient", 647 EBUF_LEN));
659 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
660 smtp_destroy_session (session); 648 smtp_destroy_session (session);
661 GNUNET_mutex_unlock (lock); 649 GNUNET_mutex_unlock (lock);
662 return GNUNET_SYSERR; 650 return GNUNET_SYSERR;
@@ -665,10 +653,9 @@ api_send (GNUNET_TSession * tsession,
665 { 653 {
666 GNUNET_GE_LOG (ectx, 654 GNUNET_GE_LOG (ectx,
667 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 655 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
668 GNUNET_GE_BULK, 656 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"),
669 _("SMTP: `%s' failed: %s.\n"), 657 "smtp_start_session", smtp_strerror (smtp_errno (), ebuf,
670 "smtp_start_session", 658 EBUF_LEN));
671 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
672 smtp_destroy_session (session); 659 smtp_destroy_session (session);
673 GNUNET_mutex_unlock (lock); 660 GNUNET_mutex_unlock (lock);
674 GNUNET_free (gm_cls.ebody); 661 GNUNET_free (gm_cls.ebody);
@@ -694,8 +681,8 @@ api_send (GNUNET_TSession * tsession,
694 * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed 681 * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed
695 */ 682 */
696static int 683static int
697api_connect (const GNUNET_MessageHello * hello, 684api_connect (const GNUNET_MessageHello * hello, GNUNET_TSession ** tsessionPtr,
698 GNUNET_TSession ** tsessionPtr, int may_reuse) 685 int may_reuse)
699{ 686{
700 GNUNET_TSession *tsession; 687 GNUNET_TSession *tsession;
701 688
@@ -739,8 +726,8 @@ api_start_transport_server ()
739 if (dispatchThread == NULL) 726 if (dispatchThread == NULL)
740 { 727 {
741 GNUNET_GE_DIE_STRERROR (ectx, 728 GNUNET_GE_DIE_STRERROR (ectx,
742 GNUNET_GE_ADMIN | GNUNET_GE_BULK | 729 GNUNET_GE_ADMIN | GNUNET_GE_BULK | GNUNET_GE_FATAL,
743 GNUNET_GE_FATAL, "pthread_create"); 730 "pthread_create");
744 return GNUNET_SYSERR; 731 return GNUNET_SYSERR;
745 } 732 }
746 return GNUNET_OK; 733 return GNUNET_OK;
@@ -765,8 +752,8 @@ api_stop_transport_server ()
765 * Convert SMTP hello to an IP address (always fails). 752 * Convert SMTP hello to an IP address (always fails).
766 */ 753 */
767static int 754static int
768api_hello_to_address (const GNUNET_MessageHello * hello, 755api_hello_to_address (const GNUNET_MessageHello * hello, void **sa,
769 void **sa, unsigned int *sa_len) 756 unsigned int *sa_len)
770{ 757{
771 return GNUNET_SYSERR; 758 return GNUNET_SYSERR;
772} 759}
@@ -807,42 +794,34 @@ inittransport_smtp (GNUNET_CoreAPIForTransport * core)
807 ectx = core->ectx; 794 ectx = core->ectx;
808 if (!GNUNET_GC_have_configuration_value (coreAPI->cfg, "SMTP", "EMAIL")) 795 if (!GNUNET_GC_have_configuration_value (coreAPI->cfg, "SMTP", "EMAIL"))
809 { 796 {
810 GNUNET_GE_LOG (ectx, 797 GNUNET_GE_LOG (ectx, GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER,
811 GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER,
812 _ 798 _
813 ("No email-address specified, can not start SMTP transport.\n")); 799 ("No email-address specified, can not start SMTP transport.\n"));
814 return NULL; 800 return NULL;
815 } 801 }
816 GNUNET_GC_get_configuration_value_number (coreAPI->cfg, 802 GNUNET_GC_get_configuration_value_number (coreAPI->cfg, "SMTP", "MTU", 1200,
817 "SMTP",
818 "MTU",
819 1200,
820 SMTP_MESSAGE_SIZE, 803 SMTP_MESSAGE_SIZE,
821 SMTP_MESSAGE_SIZE, &mtu); 804 SMTP_MESSAGE_SIZE, &mtu);
822 GNUNET_GC_get_configuration_value_number (coreAPI->cfg, 805 GNUNET_GC_get_configuration_value_number (coreAPI->cfg, "SMTP", "RATELIMIT",
823 "SMTP",
824 "RATELIMIT",
825 0, 0, 1024 * 1024, &rate_limit); 806 0, 0, 1024 * 1024, &rate_limit);
826 stats = coreAPI->service_request ("stats"); 807 stats = coreAPI->service_request ("stats");
827 if (stats != NULL) 808 if (stats != NULL)
828 { 809 {
829 stat_bytesReceived 810 stat_bytesReceived =
830 = stats->create (gettext_noop ("# bytes received via SMTP")); 811 stats->create (gettext_noop ("# bytes received via SMTP"));
831 stat_bytesSent = stats->create (gettext_noop ("# bytes sent via SMTP")); 812 stat_bytesSent = stats->create (gettext_noop ("# bytes sent via SMTP"));
832 stat_bytesDropped 813 stat_bytesDropped =
833 = stats->create (gettext_noop ("# bytes dropped by SMTP (outgoing)")); 814 stats->create (gettext_noop ("# bytes dropped by SMTP (outgoing)"));
834 } 815 }
835 GNUNET_GC_get_configuration_value_filename (coreAPI->cfg, 816 GNUNET_GC_get_configuration_value_filename (coreAPI->cfg, "SMTP", "PIPE",
836 "SMTP",
837 "PIPE",
838 GNUNET_DEFAULT_DAEMON_VAR_DIRECTORY 817 GNUNET_DEFAULT_DAEMON_VAR_DIRECTORY
839 "/smtp-pipe", &pipename); 818 "/smtp-pipe", &pipename);
840 UNLINK (pipename); 819 UNLINK (pipename);
841 if (0 != mkfifo (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH)) 820 if (0 != mkfifo (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH))
842 { 821 {
843 GNUNET_GE_LOG_STRERROR (ectx, 822 GNUNET_GE_LOG_STRERROR (ectx,
844 GNUNET_GE_ADMIN | GNUNET_GE_BULK | 823 GNUNET_GE_ADMIN | GNUNET_GE_BULK | GNUNET_GE_FATAL,
845 GNUNET_GE_FATAL, "mkfifo"); 824 "mkfifo");
846 GNUNET_free (pipename); 825 GNUNET_free (pipename);
847 coreAPI->service_release (stats); 826 coreAPI->service_release (stats);
848 stats = NULL; 827 stats = NULL;
@@ -854,12 +833,10 @@ inittransport_smtp (GNUNET_CoreAPIForTransport * core)
854 GNUNET_GE_LOG_STRERROR (ectx, 833 GNUNET_GE_LOG_STRERROR (ectx,
855 GNUNET_GE_ADMIN | GNUNET_GE_BULK | 834 GNUNET_GE_ADMIN | GNUNET_GE_BULK |
856 GNUNET_GE_WARNING, "chmod"); 835 GNUNET_GE_WARNING, "chmod");
857 GNUNET_GC_get_configuration_value_string (coreAPI->cfg, 836 GNUNET_GC_get_configuration_value_string (coreAPI->cfg, "SMTP", "EMAIL", NULL,
858 "SMTP", "EMAIL", NULL, &email); 837 &email);
859 lock = GNUNET_mutex_create (GNUNET_NO); 838 lock = GNUNET_mutex_create (GNUNET_NO);
860 GNUNET_GC_get_configuration_value_string (coreAPI->cfg, 839 GNUNET_GC_get_configuration_value_string (coreAPI->cfg, "SMTP", "SERVER",
861 "SMTP",
862 "SERVER",
863 "localhost:25", &smtp_server_name); 840 "localhost:25", &smtp_server_name);
864 sa.sa_handler = SIG_IGN; 841 sa.sa_handler = SIG_IGN;
865 sigemptyset (&sa.sa_mask); 842 sigemptyset (&sa.sa_mask);
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index bd2f4aa6a..331203471 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -419,8 +419,7 @@ plugin_tcp_access_check (void *cls,
419 * @param addrlen actual lenght of the address 419 * @param addrlen actual lenght of the address
420 */ 420 */
421static void 421static void
422tcp_nat_port_map_callback (void *cls, 422tcp_nat_port_map_callback (void *cls, int add_remove,
423 int add_remove,
424 const struct sockaddr *addr, socklen_t addrlen) 423 const struct sockaddr *addr, socklen_t addrlen)
425{ 424{
426 struct Plugin *plugin = cls; 425 struct Plugin *plugin = cls;
@@ -429,10 +428,9 @@ tcp_nat_port_map_callback (void *cls,
429 void *arg; 428 void *arg;
430 size_t args; 429 size_t args;
431 430
432 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 431 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
433 "tcp", 432 "NPMC called with %d for address `%s'\n", add_remove,
434 "NPMC called with %d for address `%s'\n", 433 GNUNET_a2s (addr, addrlen));
435 add_remove, GNUNET_a2s (addr, addrlen));
436 /* convert 'addr' to our internal format */ 434 /* convert 'addr' to our internal format */
437 switch (addr->sa_family) 435 switch (addr->sa_family)
438 { 436 {
@@ -445,8 +443,7 @@ tcp_nat_port_map_callback (void *cls,
445 break; 443 break;
446 case AF_INET6: 444 case AF_INET6:
447 GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); 445 GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
448 memcpy (&t6.ipv6_addr, 446 memcpy (&t6.ipv6_addr, &((struct sockaddr_in6 *) addr)->sin6_addr,
449 &((struct sockaddr_in6 *) addr)->sin6_addr,
450 sizeof (struct in6_addr)); 447 sizeof (struct in6_addr));
451 t6.t6_port = ((struct sockaddr_in6 *) addr)->sin6_port; 448 t6.t6_port = ((struct sockaddr_in6 *) addr)->sin6_port;
452 arg = &t6; 449 arg = &t6;
@@ -503,8 +500,7 @@ tcp_address_to_string (void *cls, const void *addr, size_t addrlen)
503 } 500 }
504 else 501 else
505 { 502 {
506 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 503 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "tcp",
507 "tcp",
508 _("Unexpected address length: %u bytes\n"), 504 _("Unexpected address length: %u bytes\n"),
509 (unsigned int) addrlen); 505 (unsigned int) addrlen);
510 GNUNET_break (0); 506 GNUNET_break (0);
@@ -515,9 +511,8 @@ tcp_address_to_string (void *cls, const void *addr, size_t addrlen)
515 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); 511 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
516 return NULL; 512 return NULL;
517 } 513 }
518 GNUNET_snprintf (rbuf, 514 GNUNET_snprintf (rbuf, sizeof (rbuf), (af == AF_INET6) ? "[%s]:%u" : "%s:%u",
519 sizeof (rbuf), 515 buf, port);
520 (af == AF_INET6) ? "[%s]:%u" : "%s:%u", buf, port);
521 return rbuf; 516 return rbuf;
522} 517}
523 518
@@ -554,8 +549,7 @@ find_session_by_client (struct Plugin *plugin,
554 * @return new session object 549 * @return new session object
555 */ 550 */
556static struct Session * 551static struct Session *
557create_session (struct Plugin *plugin, 552create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
558 const struct GNUNET_PeerIdentity *target,
559 struct GNUNET_SERVER_Client *client, int is_nat) 553 struct GNUNET_SERVER_Client *client, int is_nat)
560{ 554{
561 struct Session *ret; 555 struct Session *ret;
@@ -567,8 +561,7 @@ create_session (struct Plugin *plugin,
567 else 561 else
568 GNUNET_assert (client == NULL); 562 GNUNET_assert (client == NULL);
569#if DEBUG_TCP 563#if DEBUG_TCP
570 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 564 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
571 "tcp",
572 "Creating new session for peer `%4s'\n", 565 "Creating new session for peer `%4s'\n",
573 GNUNET_i2s (target)); 566 GNUNET_i2s (target));
574#endif 567#endif
@@ -600,8 +593,8 @@ create_session (struct Plugin *plugin,
600 ret->pending_messages_tail, pm); 593 ret->pending_messages_tail, pm);
601 if (is_nat != GNUNET_YES) 594 if (is_nat != GNUNET_YES)
602 GNUNET_STATISTICS_update (plugin->env->stats, 595 GNUNET_STATISTICS_update (plugin->env->stats,
603 gettext_noop ("# TCP sessions active"), 596 gettext_noop ("# TCP sessions active"), 1,
604 1, GNUNET_NO); 597 GNUNET_NO);
605 return ret; 598 return ret;
606} 599}
607 600
@@ -645,8 +638,7 @@ do_transmit (void *cls, size_t size, void *buf)
645 if (buf == NULL) 638 if (buf == NULL)
646 { 639 {
647#if DEBUG_TCP 640#if DEBUG_TCP
648 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 641 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
649 "tcp",
650 "Timeout trying to transmit to peer `%4s', discarding message queue.\n", 642 "Timeout trying to transmit to peer `%4s', discarding message queue.\n",
651 GNUNET_i2s (&session->target)); 643 GNUNET_i2s (&session->target));
652#endif 644#endif
@@ -661,8 +653,7 @@ do_transmit (void *cls, size_t size, void *buf)
661 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, 653 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
662 session->pending_messages_tail, pos); 654 session->pending_messages_tail, pos);
663#if DEBUG_TCP 655#if DEBUG_TCP
664 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 656 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
665 "tcp",
666 "Failed to transmit %u byte message to `%4s'.\n", 657 "Failed to transmit %u byte message to `%4s'.\n",
667 pos->message_size, GNUNET_i2s (&session->target)); 658 pos->message_size, GNUNET_i2s (&session->target));
668#endif 659#endif
@@ -729,15 +720,15 @@ do_transmit (void *cls, size_t size, void *buf)
729 GNUNET_assert (hd == NULL); 720 GNUNET_assert (hd == NULL);
730 GNUNET_assert (tl == NULL); 721 GNUNET_assert (tl == NULL);
731#if DEBUG_TCP > 1 722#if DEBUG_TCP > 1
732 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 723 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", "Transmitting %u bytes\n",
733 "tcp", "Transmitting %u bytes\n", ret); 724 ret);
734#endif 725#endif
735 GNUNET_STATISTICS_update (plugin->env->stats, 726 GNUNET_STATISTICS_update (plugin->env->stats,
736 gettext_noop ("# bytes currently in TCP buffers"), 727 gettext_noop ("# bytes currently in TCP buffers"),
737 -(int64_t) ret, GNUNET_NO); 728 -(int64_t) ret, GNUNET_NO);
738 GNUNET_STATISTICS_update (plugin->env->stats, 729 GNUNET_STATISTICS_update (plugin->env->stats,
739 gettext_noop ("# bytes transmitted via TCP"), 730 gettext_noop ("# bytes transmitted via TCP"), ret,
740 ret, GNUNET_NO); 731 GNUNET_NO);
741 return ret; 732 return ret;
742} 733}
743 734
@@ -759,12 +750,11 @@ process_pending_messages (struct Session *session)
759 if (NULL == (pm = session->pending_messages_head)) 750 if (NULL == (pm = session->pending_messages_head))
760 return; 751 return;
761 752
762 session->transmit_handle 753 session->transmit_handle =
763 = GNUNET_SERVER_notify_transmit_ready (session->client, 754 GNUNET_SERVER_notify_transmit_ready (session->client, pm->message_size,
764 pm->message_size, 755 GNUNET_TIME_absolute_get_remaining
765 GNUNET_TIME_absolute_get_remaining 756 (pm->timeout), &do_transmit,
766 (pm->timeout), 757 session);
767 &do_transmit, session);
768} 758}
769 759
770 760
@@ -783,14 +773,14 @@ disconnect_session (struct Session *session)
783 struct PendingMessage *pm; 773 struct PendingMessage *pm;
784 774
785#if DEBUG_TCP 775#if DEBUG_TCP
786 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 776 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
787 "tcp",
788 "Disconnecting from `%4s' at %s.\n", 777 "Disconnecting from `%4s' at %s.\n",
789 GNUNET_i2s (&session->target), 778 GNUNET_i2s (&session->target),
790 (session->connect_addr != NULL) ? 779 (session->connect_addr !=
791 tcp_address_to_string (session->plugin, 780 NULL) ? tcp_address_to_string (session->plugin,
792 session->connect_addr, 781 session->connect_addr,
793 session->connect_alen) : "*"); 782 session->
783 connect_alen) : "*");
794#endif 784#endif
795 /* remove from session list */ 785 /* remove from session list */
796 prev = NULL; 786 prev = NULL;
@@ -816,11 +806,10 @@ disconnect_session (struct Session *session)
816 while (NULL != (pm = session->pending_messages_head)) 806 while (NULL != (pm = session->pending_messages_head))
817 { 807 {
818#if DEBUG_TCP 808#if DEBUG_TCP
819 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 809 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
820 "tcp", 810 pm->transmit_cont !=
821 pm->transmit_cont != NULL 811 NULL ? "Could not deliver message to `%4s'.\n" :
822 ? "Could not deliver message to `%4s'.\n" 812 "Could not deliver message to `%4s', notifying.\n",
823 : "Could not deliver message to `%4s', notifying.\n",
824 GNUNET_i2s (&session->target)); 813 GNUNET_i2s (&session->target));
825#endif 814#endif
826 GNUNET_STATISTICS_update (session->plugin->env->stats, 815 GNUNET_STATISTICS_update (session->plugin->env->stats,
@@ -833,8 +822,8 @@ disconnect_session (struct Session *session)
833 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, 822 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
834 session->pending_messages_tail, pm); 823 session->pending_messages_tail, pm);
835 if (NULL != pm->transmit_cont) 824 if (NULL != pm->transmit_cont)
836 pm->transmit_cont (pm->transmit_cont_cls, 825 pm->transmit_cont (pm->transmit_cont_cls, &session->target,
837 &session->target, GNUNET_SYSERR); 826 GNUNET_SYSERR);
838 GNUNET_free (pm); 827 GNUNET_free (pm);
839 } 828 }
840 GNUNET_break (session->client != NULL); 829 GNUNET_break (session->client != NULL);
@@ -850,8 +839,8 @@ disconnect_session (struct Session *session)
850 session->client = NULL; 839 session->client = NULL;
851 } 840 }
852 GNUNET_STATISTICS_update (session->plugin->env->stats, 841 GNUNET_STATISTICS_update (session->plugin->env->stats,
853 gettext_noop ("# TCP sessions active"), 842 gettext_noop ("# TCP sessions active"), -1,
854 -1, GNUNET_NO); 843 GNUNET_NO);
855 GNUNET_free_non_null (session->connect_addr); 844 GNUNET_free_non_null (session->connect_addr);
856 GNUNET_assert (NULL == session->transmit_handle); 845 GNUNET_assert (NULL == session->transmit_handle);
857 GNUNET_free (session); 846 GNUNET_free (session);
@@ -928,16 +917,10 @@ select_better_session (struct Session *s1, struct Session *s2)
928 * and does NOT mean that the message was not transmitted (DV and NAT) 917 * and does NOT mean that the message was not transmitted (DV and NAT)
929 */ 918 */
930static ssize_t 919static ssize_t
931tcp_plugin_send (void *cls, 920tcp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
932 const struct GNUNET_PeerIdentity *target, 921 const char *msg, size_t msgbuf_size, uint32_t priority,
933 const char *msg, 922 struct GNUNET_TIME_Relative timeout, struct Session *session,
934 size_t msgbuf_size, 923 const void *addr, size_t addrlen, int force_address,
935 uint32_t priority,
936 struct GNUNET_TIME_Relative timeout,
937 struct Session *session,
938 const void *addr,
939 size_t addrlen,
940 int force_address,
941 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) 924 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
942{ 925{
943 struct Plugin *plugin = cls; 926 struct Plugin *plugin = cls;
@@ -969,8 +952,9 @@ tcp_plugin_send (void *cls,
969 { 952 {
970 next = session->next; 953 next = session->next;
971 GNUNET_assert (session->client != NULL); 954 GNUNET_assert (session->client != NULL);
972 if (0 != memcmp (target, 955 if (0 !=
973 &session->target, sizeof (struct GNUNET_PeerIdentity))) 956 memcmp (target, &session->target,
957 sizeof (struct GNUNET_PeerIdentity)))
974 continue; 958 continue;
975 if (((GNUNET_SYSERR == force_address) && 959 if (((GNUNET_SYSERR == force_address) &&
976 (session->expecting_welcome == GNUNET_NO)) || 960 (session->expecting_welcome == GNUNET_NO)) ||
@@ -989,8 +973,8 @@ tcp_plugin_send (void *cls,
989 } 973 }
990 if ((addrlen != session->connect_alen) && (session->is_nat == GNUNET_NO)) 974 if ((addrlen != session->connect_alen) && (session->is_nat == GNUNET_NO))
991 continue; 975 continue;
992 if ((0 != memcmp (session->connect_addr, 976 if ((0 != memcmp (session->connect_addr, addr, addrlen)) &&
993 addr, addrlen)) && (session->is_nat == GNUNET_NO)) 977 (session->is_nat == GNUNET_NO))
994 continue; 978 continue;
995 cand_session = select_better_session (cand_session, session); 979 cand_session = select_better_session (cand_session, session);
996 } 980 }
@@ -999,8 +983,7 @@ tcp_plugin_send (void *cls,
999 if ((session == NULL) && (addr == NULL)) 983 if ((session == NULL) && (addr == NULL))
1000 { 984 {
1001#if DEBUG_TCP 985#if DEBUG_TCP
1002 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 986 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
1003 "tcp",
1004 "Asked to transmit to `%4s' without address and I have no existing connection (failing).\n", 987 "Asked to transmit to `%4s' without address and I have no existing connection (failing).\n",
1005 GNUNET_i2s (target)); 988 GNUNET_i2s (target));
1006#endif 989#endif
@@ -1046,8 +1029,8 @@ tcp_plugin_send (void *cls,
1046 } 1029 }
1047 else 1030 else
1048 { 1031 {
1049 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 1032 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "tcp",
1050 "tcp", _("Address of unexpected length: %u\n"), addrlen); 1033 _("Address of unexpected length: %u\n"), addrlen);
1051 GNUNET_break (0); 1034 GNUNET_break (0);
1052 return -1; 1035 return -1;
1053 } 1036 }
@@ -1057,15 +1040,13 @@ tcp_plugin_send (void *cls,
1057 if (0 == plugin->max_connections) 1040 if (0 == plugin->max_connections)
1058 return -1; /* saturated */ 1041 return -1; /* saturated */
1059 1042
1060 if ((is_natd == GNUNET_YES) && 1043 if ((is_natd == GNUNET_YES) && (NULL != plugin->nat) &&
1061 (NULL != plugin->nat) &&
1062 (GNUNET_NO == 1044 (GNUNET_NO ==
1063 GNUNET_CONTAINER_multihashmap_contains (plugin->nat_wait_conns, 1045 GNUNET_CONTAINER_multihashmap_contains (plugin->nat_wait_conns,
1064 &target->hashPubKey))) 1046 &target->hashPubKey)))
1065 { 1047 {
1066#if DEBUG_TCP_NAT 1048#if DEBUG_TCP_NAT
1067 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1049 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
1068 "tcp",
1069 _("Found valid IPv4 NAT address (creating session)!\n")); 1050 _("Found valid IPv4 NAT address (creating session)!\n"));
1070#endif 1051#endif
1071 session = create_session (plugin, target, NULL, GNUNET_YES); 1052 session = create_session (plugin, target, NULL, GNUNET_YES);
@@ -1088,14 +1069,12 @@ tcp_plugin_send (void *cls,
1088 session->pending_messages_tail, 1069 session->pending_messages_tail,
1089 session->pending_messages_tail, pm); 1070 session->pending_messages_tail, pm);
1090 1071
1091 GNUNET_assert (GNUNET_CONTAINER_multihashmap_put (plugin->nat_wait_conns, 1072 GNUNET_assert (GNUNET_CONTAINER_multihashmap_put
1092 &target->hashPubKey, 1073 (plugin->nat_wait_conns, &target->hashPubKey, session,
1093 session, 1074 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) ==
1094 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) 1075 GNUNET_OK);
1095 == GNUNET_OK);
1096#if DEBUG_TCP_NAT 1076#if DEBUG_TCP_NAT
1097 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1077 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
1098 "tcp",
1099 "Created NAT WAIT connection to `%4s' at `%s'\n", 1078 "Created NAT WAIT connection to `%4s' at `%s'\n",
1100 GNUNET_i2s (target), GNUNET_a2s (sb, sbs)); 1079 GNUNET_i2s (target), GNUNET_a2s (sb, sbs));
1101#endif 1080#endif
@@ -1114,8 +1093,7 @@ tcp_plugin_send (void *cls,
1114 if (sa == NULL) 1093 if (sa == NULL)
1115 { 1094 {
1116#if DEBUG_TCP 1095#if DEBUG_TCP
1117 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1096 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
1118 "tcp",
1119 "Failed to create connection to `%4s' at `%s'\n", 1097 "Failed to create connection to `%4s' at `%s'\n",
1120 GNUNET_i2s (target), GNUNET_a2s (sb, sbs)); 1098 GNUNET_i2s (target), GNUNET_a2s (sb, sbs));
1121#endif 1099#endif
@@ -1128,15 +1106,14 @@ tcp_plugin_send (void *cls,
1128 GNUNET_assert (0 != plugin->max_connections); 1106 GNUNET_assert (0 != plugin->max_connections);
1129 plugin->max_connections--; 1107 plugin->max_connections--;
1130#if DEBUG_TCP_NAT 1108#if DEBUG_TCP_NAT
1131 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1109 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
1132 "tcp",
1133 "Asked to transmit to `%4s', creating fresh session using address `%s'.\n", 1110 "Asked to transmit to `%4s', creating fresh session using address `%s'.\n",
1134 GNUNET_i2s (target), GNUNET_a2s (sb, sbs)); 1111 GNUNET_i2s (target), GNUNET_a2s (sb, sbs));
1135#endif 1112#endif
1136 session = create_session (plugin, 1113 session =
1137 target, 1114 create_session (plugin, target,
1138 GNUNET_SERVER_connect_socket (plugin->server, 1115 GNUNET_SERVER_connect_socket (plugin->server, sa),
1139 sa), GNUNET_NO); 1116 GNUNET_NO);
1140 session->connect_addr = GNUNET_malloc (addrlen); 1117 session->connect_addr = GNUNET_malloc (addrlen);
1141 memcpy (session->connect_addr, addr, addrlen); 1118 memcpy (session->connect_addr, addr, addrlen);
1142 session->connect_alen = addrlen; 1119 session->connect_alen = addrlen;
@@ -1177,8 +1154,7 @@ tcp_plugin_send (void *cls,
1177 session->pending_messages_tail, 1154 session->pending_messages_tail,
1178 session->pending_messages_tail, pm); 1155 session->pending_messages_tail, pm);
1179#if DEBUG_TCP 1156#if DEBUG_TCP
1180 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1157 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
1181 "tcp",
1182 "Asked to transmit %u bytes to `%s', added message to list.\n", 1158 "Asked to transmit %u bytes to `%s', added message to list.\n",
1183 msgbuf_size, GNUNET_i2s (target)); 1159 msgbuf_size, GNUNET_i2s (target));
1184#endif 1160#endif
@@ -1212,16 +1188,15 @@ tcp_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
1212 struct PendingMessage *pm; 1188 struct PendingMessage *pm;
1213 1189
1214#if DEBUG_TCP 1190#if DEBUG_TCP
1215 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1191 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
1216 "tcp",
1217 "Asked to cancel session with `%4s'\n", GNUNET_i2s (target)); 1192 "Asked to cancel session with `%4s'\n", GNUNET_i2s (target));
1218#endif 1193#endif
1219 next = plugin->sessions; 1194 next = plugin->sessions;
1220 while (NULL != (session = next)) 1195 while (NULL != (session = next))
1221 { 1196 {
1222 next = session->next; 1197 next = session->next;
1223 if (0 != memcmp (target, 1198 if (0 !=
1224 &session->target, sizeof (struct GNUNET_PeerIdentity))) 1199 memcmp (target, &session->target, sizeof (struct GNUNET_PeerIdentity)))
1225 continue; 1200 continue;
1226 pm = session->pending_messages_head; 1201 pm = session->pending_messages_head;
1227 while (pm != NULL) 1202 while (pm != NULL)
@@ -1300,10 +1275,8 @@ append_port (void *cls, const char *hostname)
1300 * @param asc_cls closure for asc 1275 * @param asc_cls closure for asc
1301 */ 1276 */
1302static void 1277static void
1303tcp_plugin_address_pretty_printer (void *cls, 1278tcp_plugin_address_pretty_printer (void *cls, const char *type,
1304 const char *type, 1279 const void *addr, size_t addrlen,
1305 const void *addr,
1306 size_t addrlen,
1307 int numeric, 1280 int numeric,
1308 struct GNUNET_TIME_Relative timeout, 1281 struct GNUNET_TIME_Relative timeout,
1309 GNUNET_TRANSPORT_AddressStringCallback asc, 1282 GNUNET_TRANSPORT_AddressStringCallback asc,
@@ -1408,8 +1381,8 @@ tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen)
1408 if (GNUNET_OK != check_port (plugin, ntohs (v4->t4_port))) 1381 if (GNUNET_OK != check_port (plugin, ntohs (v4->t4_port)))
1409 return GNUNET_SYSERR; 1382 return GNUNET_SYSERR;
1410 if (GNUNET_OK != 1383 if (GNUNET_OK !=
1411 GNUNET_NAT_test_address (plugin->nat, 1384 GNUNET_NAT_test_address (plugin->nat, &v4->ipv4_addr,
1412 &v4->ipv4_addr, sizeof (struct in_addr))) 1385 sizeof (struct in_addr)))
1413 return GNUNET_SYSERR; 1386 return GNUNET_SYSERR;
1414 } 1387 }
1415 else 1388 else
@@ -1423,8 +1396,8 @@ tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen)
1423 if (GNUNET_OK != check_port (plugin, ntohs (v6->t6_port))) 1396 if (GNUNET_OK != check_port (plugin, ntohs (v6->t6_port)))
1424 return GNUNET_SYSERR; 1397 return GNUNET_SYSERR;
1425 if (GNUNET_OK != 1398 if (GNUNET_OK !=
1426 GNUNET_NAT_test_address (plugin->nat, 1399 GNUNET_NAT_test_address (plugin->nat, &v6->ipv6_addr,
1427 &v6->ipv6_addr, sizeof (struct in6_addr))) 1400 sizeof (struct in6_addr)))
1428 return GNUNET_SYSERR; 1401 return GNUNET_SYSERR;
1429 } 1402 }
1430 return GNUNET_OK; 1403 return GNUNET_OK;
@@ -1441,8 +1414,7 @@ tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen)
1441 * @param message the actual message 1414 * @param message the actual message
1442 */ 1415 */
1443static void 1416static void
1444handle_tcp_nat_probe (void *cls, 1417handle_tcp_nat_probe (void *cls, struct GNUNET_SERVER_Client *client,
1445 struct GNUNET_SERVER_Client *client,
1446 const struct GNUNET_MessageHeader *message) 1418 const struct GNUNET_MessageHeader *message)
1447{ 1419{
1448 struct Plugin *plugin = cls; 1420 struct Plugin *plugin = cls;
@@ -1472,34 +1444,36 @@ handle_tcp_nat_probe (void *cls,
1472 } 1444 }
1473 1445
1474 tcp_nat_probe = (const struct TCP_NAT_ProbeMessage *) message; 1446 tcp_nat_probe = (const struct TCP_NAT_ProbeMessage *) message;
1475 if (0 == memcmp (&tcp_nat_probe->clientIdentity, 1447 if (0 ==
1476 plugin->env->my_identity, 1448 memcmp (&tcp_nat_probe->clientIdentity, plugin->env->my_identity,
1477 sizeof (struct GNUNET_PeerIdentity))) 1449 sizeof (struct GNUNET_PeerIdentity)))
1478 { 1450 {
1479 /* refuse connections from ourselves */ 1451 /* refuse connections from ourselves */
1480 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1452 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1481 return; 1453 return;
1482 } 1454 }
1483 1455
1484 session = GNUNET_CONTAINER_multihashmap_get (plugin->nat_wait_conns, 1456 session =
1485 &tcp_nat_probe-> 1457 GNUNET_CONTAINER_multihashmap_get (plugin->nat_wait_conns,
1486 clientIdentity.hashPubKey); 1458 &tcp_nat_probe->clientIdentity.
1459 hashPubKey);
1487 if (session == NULL) 1460 if (session == NULL)
1488 { 1461 {
1489#if DEBUG_TCP_NAT 1462#if DEBUG_TCP_NAT
1490 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1463 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
1491 "tcp", "Did NOT find session for NAT probe!\n"); 1464 "Did NOT find session for NAT probe!\n");
1492#endif 1465#endif
1493 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1466 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1494 return; 1467 return;
1495 } 1468 }
1496#if DEBUG_TCP_NAT 1469#if DEBUG_TCP_NAT
1497 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1470 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
1498 "tcp", "Found session for NAT probe!\n"); 1471 "Found session for NAT probe!\n");
1499#endif 1472#endif
1500 GNUNET_assert (GNUNET_CONTAINER_multihashmap_remove (plugin->nat_wait_conns, 1473 GNUNET_assert (GNUNET_CONTAINER_multihashmap_remove
1501 &tcp_nat_probe->clientIdentity.hashPubKey, 1474 (plugin->nat_wait_conns,
1502 session) == GNUNET_YES); 1475 &tcp_nat_probe->clientIdentity.hashPubKey,
1476 session) == GNUNET_YES);
1503 if (GNUNET_OK != GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) 1477 if (GNUNET_OK != GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
1504 { 1478 {
1505 GNUNET_break (0); 1479 GNUNET_break (0);
@@ -1514,8 +1488,7 @@ handle_tcp_nat_probe (void *cls,
1514 session->inbound = GNUNET_NO; 1488 session->inbound = GNUNET_NO;
1515 1489
1516#if DEBUG_TCP_NAT 1490#if DEBUG_TCP_NAT
1517 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1491 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
1518 "tcp",
1519 "Found address `%s' for incoming connection\n", 1492 "Found address `%s' for incoming connection\n",
1520 GNUNET_a2s (vaddr, alen)); 1493 GNUNET_a2s (vaddr, alen));
1521#endif 1494#endif
@@ -1540,8 +1513,8 @@ handle_tcp_nat_probe (void *cls,
1540 default: 1513 default:
1541 GNUNET_break_op (0); 1514 GNUNET_break_op (0);
1542#if DEBUG_TCP_NAT 1515#if DEBUG_TCP_NAT
1543 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1516 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
1544 "tcp", "Bad address for incoming connection!\n"); 1517 "Bad address for incoming connection!\n");
1545#endif 1518#endif
1546 GNUNET_free (vaddr); 1519 GNUNET_free (vaddr);
1547 GNUNET_SERVER_client_drop (client); 1520 GNUNET_SERVER_client_drop (client);
@@ -1554,8 +1527,8 @@ handle_tcp_nat_probe (void *cls,
1554 session->next = plugin->sessions; 1527 session->next = plugin->sessions;
1555 plugin->sessions = session; 1528 plugin->sessions = session;
1556 GNUNET_STATISTICS_update (plugin->env->stats, 1529 GNUNET_STATISTICS_update (plugin->env->stats,
1557 gettext_noop ("# TCP sessions active"), 1530 gettext_noop ("# TCP sessions active"), 1,
1558 1, GNUNET_NO); 1531 GNUNET_NO);
1559 process_pending_messages (session); 1532 process_pending_messages (session);
1560 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1533 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1561} 1534}
@@ -1570,8 +1543,7 @@ handle_tcp_nat_probe (void *cls,
1570 * @param message the actual message 1543 * @param message the actual message
1571 */ 1544 */
1572static void 1545static void
1573handle_tcp_welcome (void *cls, 1546handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client,
1574 struct GNUNET_SERVER_Client *client,
1575 const struct GNUNET_MessageHeader *message) 1547 const struct GNUNET_MessageHeader *message)
1576{ 1548{
1577 struct Plugin *plugin = cls; 1549 struct Plugin *plugin = cls;
@@ -1584,30 +1556,28 @@ handle_tcp_welcome (void *cls,
1584 const struct sockaddr_in *s4; 1556 const struct sockaddr_in *s4;
1585 const struct sockaddr_in6 *s6; 1557 const struct sockaddr_in6 *s6;
1586 1558
1587 if (0 == memcmp (&wm->clientIdentity, 1559 if (0 ==
1588 plugin->env->my_identity, 1560 memcmp (&wm->clientIdentity, plugin->env->my_identity,
1589 sizeof (struct GNUNET_PeerIdentity))) 1561 sizeof (struct GNUNET_PeerIdentity)))
1590 { 1562 {
1591 /* refuse connections from ourselves */ 1563 /* refuse connections from ourselves */
1592 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1564 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1593 return; 1565 return;
1594 } 1566 }
1595#if DEBUG_TCP 1567#if DEBUG_TCP
1596 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1568 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
1597 "tcp", 1569 "Received %s message from `%4s'.\n", "WELCOME",
1598 "Received %s message from `%4s'.\n", 1570 GNUNET_i2s (&wm->clientIdentity));
1599 "WELCOME", GNUNET_i2s (&wm->clientIdentity));
1600#endif 1571#endif
1601 GNUNET_STATISTICS_update (plugin->env->stats, 1572 GNUNET_STATISTICS_update (plugin->env->stats,
1602 gettext_noop ("# TCP WELCOME messages received"), 1573 gettext_noop ("# TCP WELCOME messages received"), 1,
1603 1, GNUNET_NO); 1574 GNUNET_NO);
1604 session = find_session_by_client (plugin, client); 1575 session = find_session_by_client (plugin, client);
1605 1576
1606 if (session == NULL) 1577 if (session == NULL)
1607 { 1578 {
1608#if DEBUG_TCP_NAT 1579#if DEBUG_TCP_NAT
1609 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1580 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
1610 "tcp",
1611 "Received %s message from a `%4s', creating new session\n", 1581 "Received %s message from a `%4s', creating new session\n",
1612 "WELCOME", GNUNET_i2s (&wm->clientIdentity)); 1582 "WELCOME", GNUNET_i2s (&wm->clientIdentity));
1613#endif 1583#endif
@@ -1617,8 +1587,7 @@ handle_tcp_welcome (void *cls,
1617 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) 1587 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
1618 { 1588 {
1619#if DEBUG_TCP_NAT 1589#if DEBUG_TCP_NAT
1620 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1590 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
1621 "tcp",
1622 "Found address `%s' for incoming connection\n", 1591 "Found address `%s' for incoming connection\n",
1623 GNUNET_a2s (vaddr, alen)); 1592 GNUNET_a2s (vaddr, alen));
1624#endif 1593#endif
@@ -1646,8 +1615,7 @@ handle_tcp_welcome (void *cls,
1646 else 1615 else
1647 { 1616 {
1648#if DEBUG_TCP 1617#if DEBUG_TCP
1649 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1618 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
1650 "tcp",
1651 "Did not obtain TCP socket address for incoming connection\n"); 1619 "Did not obtain TCP socket address for incoming connection\n");
1652#endif 1620#endif
1653 } 1621 }
@@ -1658,8 +1626,7 @@ handle_tcp_welcome (void *cls,
1658#if DEBUG_TCP_NAT 1626#if DEBUG_TCP_NAT
1659 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) 1627 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
1660 { 1628 {
1661 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1629 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
1662 "tcp",
1663 "Found address `%s' (already have session)\n", 1630 "Found address `%s' (already have session)\n",
1664 GNUNET_a2s (vaddr, alen)); 1631 GNUNET_a2s (vaddr, alen));
1665 GNUNET_free (vaddr); 1632 GNUNET_free (vaddr);
@@ -1695,9 +1662,10 @@ delayed_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1695 struct GNUNET_TIME_Relative delay; 1662 struct GNUNET_TIME_Relative delay;
1696 1663
1697 session->receive_delay_task = GNUNET_SCHEDULER_NO_TASK; 1664 session->receive_delay_task = GNUNET_SCHEDULER_NO_TASK;
1698 delay = session->plugin->env->receive (session->plugin->env->cls, 1665 delay =
1699 &session->target, 1666 session->plugin->env->receive (session->plugin->env->cls,
1700 NULL, NULL, 0, session, NULL, 0); 1667 &session->target, NULL, NULL, 0, session,
1668 NULL, 0);
1701 if (delay.rel_value == 0) 1669 if (delay.rel_value == 0)
1702 GNUNET_SERVER_receive_done (session->client, GNUNET_OK); 1670 GNUNET_SERVER_receive_done (session->client, GNUNET_OK);
1703 else 1671 else
@@ -1715,8 +1683,7 @@ delayed_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1715 * @param message the actual message 1683 * @param message the actual message
1716 */ 1684 */
1717static void 1685static void
1718handle_tcp_data (void *cls, 1686handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client,
1719 struct GNUNET_SERVER_Client *client,
1720 const struct GNUNET_MessageHeader *message) 1687 const struct GNUNET_MessageHeader *message)
1721{ 1688{
1722 struct Plugin *plugin = cls; 1689 struct Plugin *plugin = cls;
@@ -1740,8 +1707,7 @@ handle_tcp_data (void *cls,
1740 } 1707 }
1741 session->last_activity = GNUNET_TIME_absolute_get (); 1708 session->last_activity = GNUNET_TIME_absolute_get ();
1742#if DEBUG_TCP > 1 1709#if DEBUG_TCP > 1
1743 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1710 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
1744 "tcp",
1745 "Passing %u bytes of type %u from `%4s' to transport service.\n", 1711 "Passing %u bytes of type %u from `%4s' to transport service.\n",
1746 (unsigned int) ntohs (message->size), 1712 (unsigned int) ntohs (message->size),
1747 (unsigned int) ntohs (message->type), 1713 (unsigned int) ntohs (message->type),
@@ -1756,14 +1722,14 @@ handle_tcp_data (void *cls,
1756 distance[0].value = htonl (1); 1722 distance[0].value = htonl (1);
1757 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 1723 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
1758 distance[1].value = htonl (0); 1724 distance[1].value = htonl (0);
1759 delay = plugin->env->receive (plugin->env->cls, &session->target, message, 1725 delay =
1760 (const struct GNUNET_TRANSPORT_ATS_Information 1726 plugin->env->receive (plugin->env->cls, &session->target, message,
1761 *) &distance, 2, session, 1727 (const struct GNUNET_TRANSPORT_ATS_Information *)
1762 (GNUNET_YES == 1728 &distance, 2, session,
1763 session-> 1729 (GNUNET_YES ==
1764 inbound) ? NULL : session->connect_addr, 1730 session->inbound) ? NULL : session->connect_addr,
1765 (GNUNET_YES == 1731 (GNUNET_YES ==
1766 session->inbound) ? 0 : session->connect_alen); 1732 session->inbound) ? 0 : session->connect_alen);
1767 if (delay.rel_value == 0) 1733 if (delay.rel_value == 0)
1768 { 1734 {
1769 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1735 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -1771,8 +1737,7 @@ handle_tcp_data (void *cls,
1771 else 1737 else
1772 { 1738 {
1773#if DEBUG_TCP 1739#if DEBUG_TCP
1774 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1740 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
1775 "tcp",
1776 "Throttling receiving from `%s' for %llu ms\n", 1741 "Throttling receiving from `%s' for %llu ms\n",
1777 GNUNET_i2s (&session->target), 1742 GNUNET_i2s (&session->target),
1778 (unsigned long long) delay.rel_value); 1743 (unsigned long long) delay.rel_value);
@@ -1804,14 +1769,14 @@ disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client)
1804 if (session == NULL) 1769 if (session == NULL)
1805 return; /* unknown, nothing to do */ 1770 return; /* unknown, nothing to do */
1806#if DEBUG_TCP 1771#if DEBUG_TCP
1807 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1772 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
1808 "tcp",
1809 "Destroying session of `%4s' with %s due to network-level disconnect.\n", 1773 "Destroying session of `%4s' with %s due to network-level disconnect.\n",
1810 GNUNET_i2s (&session->target), 1774 GNUNET_i2s (&session->target),
1811 (session->connect_addr != NULL) ? 1775 (session->connect_addr !=
1812 tcp_address_to_string (session->plugin, 1776 NULL) ? tcp_address_to_string (session->plugin,
1813 session->connect_addr, 1777 session->connect_addr,
1814 session->connect_alen) : "*"); 1778 session->
1779 connect_alen) : "*");
1815#endif 1780#endif
1816 GNUNET_STATISTICS_update (session->plugin->env->stats, 1781 GNUNET_STATISTICS_update (session->plugin->env->stats,
1817 gettext_noop 1782 gettext_noop
@@ -1837,8 +1802,8 @@ notify_send_probe (void *cls, size_t size, void *buf)
1837 size_t ret; 1802 size_t ret;
1838 1803
1839 tcp_probe_ctx->transmit_handle = NULL; 1804 tcp_probe_ctx->transmit_handle = NULL;
1840 GNUNET_CONTAINER_DLL_remove (plugin->probe_head, 1805 GNUNET_CONTAINER_DLL_remove (plugin->probe_head, plugin->probe_tail,
1841 plugin->probe_tail, tcp_probe_ctx); 1806 tcp_probe_ctx);
1842 if (buf == NULL) 1807 if (buf == NULL)
1843 { 1808 {
1844 GNUNET_CONNECTION_destroy (tcp_probe_ctx->sock, GNUNET_NO); 1809 GNUNET_CONNECTION_destroy (tcp_probe_ctx->sock, GNUNET_NO);
@@ -1865,8 +1830,8 @@ notify_send_probe (void *cls, size_t size, void *buf)
1865 * @param addrlen number of bytes in addr 1830 * @param addrlen number of bytes in addr
1866 */ 1831 */
1867static void 1832static void
1868try_connection_reversal (void *cls, 1833try_connection_reversal (void *cls, const struct sockaddr *addr,
1869 const struct sockaddr *addr, socklen_t addrlen) 1834 socklen_t addrlen)
1870{ 1835{
1871 struct Plugin *plugin = cls; 1836 struct Plugin *plugin = cls;
1872 struct GNUNET_CONNECTION_Handle *sock; 1837 struct GNUNET_CONNECTION_Handle *sock;
@@ -1886,23 +1851,23 @@ try_connection_reversal (void *cls,
1886 /* FIXME: do we need to track these probe context objects so that 1851 /* FIXME: do we need to track these probe context objects so that
1887 * we can clean them up on plugin unload? */ 1852 * we can clean them up on plugin unload? */
1888 tcp_probe_ctx = GNUNET_malloc (sizeof (struct TCPProbeContext)); 1853 tcp_probe_ctx = GNUNET_malloc (sizeof (struct TCPProbeContext));
1889 tcp_probe_ctx->message.header.size 1854 tcp_probe_ctx->message.header.size =
1890 = htons (sizeof (struct TCP_NAT_ProbeMessage)); 1855 htons (sizeof (struct TCP_NAT_ProbeMessage));
1891 tcp_probe_ctx->message.header.type 1856 tcp_probe_ctx->message.header.type =
1892 = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE); 1857 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE);
1893 memcpy (&tcp_probe_ctx->message.clientIdentity, 1858 memcpy (&tcp_probe_ctx->message.clientIdentity, plugin->env->my_identity,
1894 plugin->env->my_identity, sizeof (struct GNUNET_PeerIdentity)); 1859 sizeof (struct GNUNET_PeerIdentity));
1895 tcp_probe_ctx->plugin = plugin; 1860 tcp_probe_ctx->plugin = plugin;
1896 tcp_probe_ctx->sock = sock; 1861 tcp_probe_ctx->sock = sock;
1897 GNUNET_CONTAINER_DLL_insert (plugin->probe_head, 1862 GNUNET_CONTAINER_DLL_insert (plugin->probe_head, plugin->probe_tail,
1898 plugin->probe_tail, tcp_probe_ctx); 1863 tcp_probe_ctx);
1899 tcp_probe_ctx->transmit_handle 1864 tcp_probe_ctx->transmit_handle =
1900 = GNUNET_CONNECTION_notify_transmit_ready (sock, 1865 GNUNET_CONNECTION_notify_transmit_ready (sock,
1901 ntohs (tcp_probe_ctx-> 1866 ntohs (tcp_probe_ctx->message.
1902 message.header.size), 1867 header.size),
1903 GNUNET_TIME_UNIT_FOREVER_REL, 1868 GNUNET_TIME_UNIT_FOREVER_REL,
1904 &notify_send_probe, 1869 &notify_send_probe,
1905 tcp_probe_ctx); 1870 tcp_probe_ctx);
1906 1871
1907} 1872}
1908 1873
@@ -1938,27 +1903,21 @@ libgnunet_plugin_transport_tcp_init (void *cls)
1938 socklen_t *addrlens; 1903 socklen_t *addrlens;
1939 1904
1940 if (GNUNET_OK != 1905 if (GNUNET_OK !=
1941 GNUNET_CONFIGURATION_get_value_number (env->cfg, 1906 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp",
1942 "transport-tcp",
1943 "MAX_CONNECTIONS", 1907 "MAX_CONNECTIONS",
1944 &max_connections)) 1908 &max_connections))
1945 max_connections = 128; 1909 max_connections = 128;
1946 1910
1947 aport = 0; 1911 aport = 0;
1948 if ((GNUNET_OK != 1912 if ((GNUNET_OK !=
1949 GNUNET_CONFIGURATION_get_value_number (env->cfg, 1913 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp", "PORT",
1950 "transport-tcp", 1914 &bport)) || (bport > 65535) ||
1951 "PORT",
1952 &bport)) ||
1953 (bport > 65535) ||
1954 ((GNUNET_OK == 1915 ((GNUNET_OK ==
1955 GNUNET_CONFIGURATION_get_value_number (env->cfg, 1916 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp",
1956 "transport-tcp", 1917 "ADVERTISED-PORT", &aport)) &&
1957 "ADVERTISED-PORT", 1918 (aport > 65535)))
1958 &aport)) && (aport > 65535)))
1959 { 1919 {
1960 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 1920 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "tcp",
1961 "tcp",
1962 _ 1921 _
1963 ("Require valid port number for service `%s' in configuration!\n"), 1922 ("Require valid port number for service `%s' in configuration!\n"),
1964 "transport-tcp"); 1923 "transport-tcp");
@@ -1973,8 +1932,8 @@ libgnunet_plugin_transport_tcp_init (void *cls)
1973 service = GNUNET_SERVICE_start ("transport-tcp", env->cfg); 1932 service = GNUNET_SERVICE_start ("transport-tcp", env->cfg);
1974 if (service == NULL) 1933 if (service == NULL)
1975 { 1934 {
1976 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, 1935 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "tcp",
1977 "tcp", _("Failed to start service.\n")); 1936 _("Failed to start service.\n"));
1978 return NULL; 1937 return NULL;
1979 } 1938 }
1980 } 1939 }
@@ -1991,18 +1950,15 @@ libgnunet_plugin_transport_tcp_init (void *cls)
1991 plugin->lsock = NULL; 1950 plugin->lsock = NULL;
1992 if ((service != NULL) && 1951 if ((service != NULL) &&
1993 (GNUNET_SYSERR != 1952 (GNUNET_SYSERR !=
1994 (ret = GNUNET_SERVICE_get_server_addresses ("transport-tcp", 1953 (ret =
1995 env->cfg, 1954 GNUNET_SERVICE_get_server_addresses ("transport-tcp", env->cfg, &addrs,
1996 &addrs, &addrlens)))) 1955 &addrlens))))
1997 { 1956 {
1998 plugin->nat = GNUNET_NAT_register (env->cfg, 1957 plugin->nat =
1999 GNUNET_YES, 1958 GNUNET_NAT_register (env->cfg, GNUNET_YES, aport, (unsigned int) ret,
2000 aport, 1959 (const struct sockaddr **) addrs, addrlens,
2001 (unsigned int) ret, 1960 &tcp_nat_port_map_callback,
2002 (const struct sockaddr **) addrs, 1961 &try_connection_reversal, plugin);
2003 addrlens,
2004 &tcp_nat_port_map_callback,
2005 &try_connection_reversal, plugin);
2006 while (ret > 0) 1962 while (ret > 0)
2007 { 1963 {
2008 ret--; 1964 ret--;
@@ -2014,11 +1970,9 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2014 } 1970 }
2015 else 1971 else
2016 { 1972 {
2017 plugin->nat = GNUNET_NAT_register (env->cfg, 1973 plugin->nat =
2018 GNUNET_YES, 1974 GNUNET_NAT_register (env->cfg, GNUNET_YES, 0, 0, NULL, NULL, NULL,
2019 0, 1975 &try_connection_reversal, plugin);
2020 0, NULL, NULL,
2021 NULL, &try_connection_reversal, plugin);
2022 } 1976 }
2023 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); 1977 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
2024 api->cls = plugin; 1978 api->cls = plugin;
@@ -2035,12 +1989,10 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2035 else 1989 else
2036 { 1990 {
2037 if (GNUNET_OK != 1991 if (GNUNET_OK !=
2038 GNUNET_CONFIGURATION_get_value_time (env->cfg, 1992 GNUNET_CONFIGURATION_get_value_time (env->cfg, "transport-tcp",
2039 "transport-tcp",
2040 "TIMEOUT", &idle_timeout)) 1993 "TIMEOUT", &idle_timeout))
2041 { 1994 {
2042 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 1995 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "tcp",
2043 "tcp",
2044 _("Failed to find option %s in section %s!\n"), 1996 _("Failed to find option %s in section %s!\n"),
2045 "TIMEOUT", "transport-tcp"); 1997 "TIMEOUT", "transport-tcp");
2046 if (plugin->nat != NULL) 1998 if (plugin->nat != NULL)
@@ -2063,16 +2015,14 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2063 GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin); 2015 GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin);
2064 plugin->nat_wait_conns = GNUNET_CONTAINER_multihashmap_create (16); 2016 plugin->nat_wait_conns = GNUNET_CONTAINER_multihashmap_create (16);
2065 if (bport != 0) 2017 if (bport != 0)
2066 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, 2018 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "tcp",
2067 "tcp", _("TCP transport listening on port %llu\n"), bport); 2019 _("TCP transport listening on port %llu\n"), bport);
2068 else 2020 else
2069 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, 2021 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "tcp",
2070 "tcp",
2071 _ 2022 _
2072 ("TCP transport not listening on any port (client only)\n")); 2023 ("TCP transport not listening on any port (client only)\n"));
2073 if (aport != bport) 2024 if (aport != bport)
2074 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, 2025 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "tcp",
2075 "tcp",
2076 _ 2026 _
2077 ("TCP transport advertises itself as being on port %llu\n"), 2027 ("TCP transport advertises itself as being on port %llu\n"),
2078 aport); 2028 aport);
@@ -2102,8 +2052,8 @@ libgnunet_plugin_transport_tcp_done (void *cls)
2102 GNUNET_NAT_unregister (plugin->nat); 2052 GNUNET_NAT_unregister (plugin->nat);
2103 while (NULL != (tcp_probe = plugin->probe_head)) 2053 while (NULL != (tcp_probe = plugin->probe_head))
2104 { 2054 {
2105 GNUNET_CONTAINER_DLL_remove (plugin->probe_head, 2055 GNUNET_CONTAINER_DLL_remove (plugin->probe_head, plugin->probe_tail,
2106 plugin->probe_tail, tcp_probe); 2056 tcp_probe);
2107 GNUNET_CONNECTION_destroy (tcp_probe->sock, GNUNET_NO); 2057 GNUNET_CONNECTION_destroy (tcp_probe->sock, GNUNET_NO);
2108 GNUNET_free (tcp_probe); 2058 GNUNET_free (tcp_probe);
2109 } 2059 }
diff --git a/src/transport/plugin_transport_template.c b/src/transport/plugin_transport_template.c
index d83807a36..3ad8014c5 100644
--- a/src/transport/plugin_transport_template.c
+++ b/src/transport/plugin_transport_template.c
@@ -151,18 +151,14 @@ struct Plugin
151 * and does NOT mean that the message was not transmitted (DV) 151 * and does NOT mean that the message was not transmitted (DV)
152 */ 152 */
153static ssize_t 153static ssize_t
154template_plugin_send (void *cls, 154template_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
155 const struct GNUNET_PeerIdentity *target, 155 const char *msgbuf, size_t msgbuf_size,
156 const char *msgbuf,
157 size_t msgbuf_size,
158 unsigned int priority, 156 unsigned int priority,
159 struct GNUNET_TIME_Relative timeout, 157 struct GNUNET_TIME_Relative timeout,
160 struct Session *session, 158 struct Session *session, const void *addr, size_t addrlen,
161 const void *addr,
162 size_t addrlen,
163 int force_address, 159 int force_address,
164 GNUNET_TRANSPORT_TransmitContinuation 160 GNUNET_TRANSPORT_TransmitContinuation cont,
165 cont, void *cont_cls) 161 void *cont_cls)
166{ 162{
167 int bytes_sent = 0; 163 int bytes_sent = 0;
168 164
@@ -203,10 +199,8 @@ template_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
203 * @param asc_cls closure for asc 199 * @param asc_cls closure for asc
204 */ 200 */
205static void 201static void
206template_plugin_address_pretty_printer (void *cls, 202template_plugin_address_pretty_printer (void *cls, const char *type,
207 const char *type, 203 const void *addr, size_t addrlen,
208 const void *addr,
209 size_t addrlen,
210 int numeric, 204 int numeric,
211 struct GNUNET_TIME_Relative timeout, 205 struct GNUNET_TIME_Relative timeout,
212 GNUNET_TRANSPORT_AddressStringCallback 206 GNUNET_TRANSPORT_AddressStringCallback
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index df8447a12..f9310fb8f 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -350,8 +350,8 @@ udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
350 * @return the number of bytes written 350 * @return the number of bytes written
351 */ 351 */
352static ssize_t 352static ssize_t
353udp_send (struct Plugin *plugin, 353udp_send (struct Plugin *plugin, const struct sockaddr *sa,
354 const struct sockaddr *sa, const struct GNUNET_MessageHeader *msg) 354 const struct GNUNET_MessageHeader *msg)
355{ 355{
356 ssize_t sent; 356 ssize_t sent;
357 size_t slen; 357 size_t slen;
@@ -362,18 +362,14 @@ udp_send (struct Plugin *plugin,
362 if (NULL == plugin->sockv4) 362 if (NULL == plugin->sockv4)
363 return 0; 363 return 0;
364 sent = 364 sent =
365 GNUNET_NETWORK_socket_sendto (plugin->sockv4, 365 GNUNET_NETWORK_socket_sendto (plugin->sockv4, msg, ntohs (msg->size),
366 msg,
367 ntohs (msg->size),
368 sa, slen = sizeof (struct sockaddr_in)); 366 sa, slen = sizeof (struct sockaddr_in));
369 break; 367 break;
370 case AF_INET6: 368 case AF_INET6:
371 if (NULL == plugin->sockv6) 369 if (NULL == plugin->sockv6)
372 return 0; 370 return 0;
373 sent = 371 sent =
374 GNUNET_NETWORK_socket_sendto (plugin->sockv6, 372 GNUNET_NETWORK_socket_sendto (plugin->sockv6, msg, ntohs (msg->size),
375 msg,
376 ntohs (msg->size),
377 sa, slen = sizeof (struct sockaddr_in6)); 373 sa, slen = sizeof (struct sockaddr_in6));
378 break; 374 break;
379 default: 375 default:
@@ -385,8 +381,7 @@ udp_send (struct Plugin *plugin,
385#if DEBUG_UDP 381#if DEBUG_UDP
386 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 382 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
387 "UDP transmited %u-byte message to %s (%d: %s)\n", 383 "UDP transmited %u-byte message to %s (%d: %s)\n",
388 (unsigned int) ntohs (msg->size), 384 (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen),
389 GNUNET_a2s (sa, slen),
390 (int) sent, (sent < 0) ? STRERROR (errno) : "ok"); 385 (int) sent, (sent < 0) ? STRERROR (errno) : "ok");
391#endif 386#endif
392 return sent; 387 return sent;
@@ -437,16 +432,10 @@ send_fragment (void *cls, const struct GNUNET_MessageHeader *msg)
437 * still be transmitted later!) 432 * still be transmitted later!)
438 */ 433 */
439static ssize_t 434static ssize_t
440udp_plugin_send (void *cls, 435udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
441 const struct GNUNET_PeerIdentity *target, 436 const char *msgbuf, size_t msgbuf_size, unsigned int priority,
442 const char *msgbuf, 437 struct GNUNET_TIME_Relative timeout, struct Session *session,
443 size_t msgbuf_size, 438 const void *addr, size_t addrlen, int force_address,
444 unsigned int priority,
445 struct GNUNET_TIME_Relative timeout,
446 struct Session *session,
447 const void *addr,
448 size_t addrlen,
449 int force_address,
450 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) 439 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
451{ 440{
452 struct Plugin *plugin = cls; 441 struct Plugin *plugin = cls;
@@ -534,13 +523,12 @@ udp_plugin_send (void *cls,
534 &target->hashPubKey, 523 &target->hashPubKey,
535 peer_session, 524 peer_session,
536 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 525 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
537 peer_session->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats, 526 peer_session->frag =
538 UDP_MTU, 527 GNUNET_FRAGMENT_context_create (plugin->env->stats, UDP_MTU,
539 &plugin->tracker, 528 &plugin->tracker,
540 plugin->last_expected_delay, 529 plugin->last_expected_delay,
541 &udp->header, 530 &udp->header, &send_fragment,
542 &send_fragment, 531 peer_session);
543 peer_session);
544 } 532 }
545 return mlen; 533 return mlen;
546} 534}
@@ -577,8 +565,7 @@ struct SourceInformation
577 * @param hdr the actual message 565 * @param hdr the actual message
578 */ 566 */
579static void 567static void
580process_inbound_tokenized_messages (void *cls, 568process_inbound_tokenized_messages (void *cls, void *client,
581 void *client,
582 const struct GNUNET_MessageHeader *hdr) 569 const struct GNUNET_MessageHeader *hdr)
583{ 570{
584 struct Plugin *plugin = cls; 571 struct Plugin *plugin = cls;
@@ -591,8 +578,8 @@ process_inbound_tokenized_messages (void *cls,
591 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 578 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
592 distance[1].value = htonl (0); 579 distance[1].value = htonl (0);
593 580
594 plugin->env->receive (plugin->env->cls, 581 plugin->env->receive (plugin->env->cls, &si->sender, hdr, distance, 2, NULL,
595 &si->sender, hdr, distance, 2, NULL, si->arg, si->args); 582 si->arg, si->args);
596} 583}
597 584
598 585
@@ -605,8 +592,7 @@ process_inbound_tokenized_messages (void *cls,
605 * @param sender_addr_len number of bytes in sender_addr 592 * @param sender_addr_len number of bytes in sender_addr
606 */ 593 */
607static void 594static void
608process_udp_message (struct Plugin *plugin, 595process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg,
609 const struct UDPMessage *msg,
610 const struct sockaddr *sender_addr, 596 const struct sockaddr *sender_addr,
611 socklen_t sender_addr_len) 597 socklen_t sender_addr_len)
612{ 598{
@@ -650,21 +636,18 @@ process_udp_message (struct Plugin *plugin,
650 return; 636 return;
651 } 637 }
652#if DEBUG_UDP 638#if DEBUG_UDP
653 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 639 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp",
654 "udp",
655 "Received message with %u bytes from peer `%s' at `%s'\n", 640 "Received message with %u bytes from peer `%s' at `%s'\n",
656 (unsigned int) ntohs (msg->header.size), 641 (unsigned int) ntohs (msg->header.size),
657 GNUNET_i2s (&msg->sender), 642 GNUNET_i2s (&msg->sender), GNUNET_a2s (sender_addr,
658 GNUNET_a2s (sender_addr, sender_addr_len)); 643 sender_addr_len));
659#endif 644#endif
660 645
661 /* iterate over all embedded messages */ 646 /* iterate over all embedded messages */
662 si.sender = msg->sender; 647 si.sender = msg->sender;
663 si.arg = arg; 648 si.arg = arg;
664 si.args = args; 649 si.args = args;
665 GNUNET_SERVER_mst_receive (plugin->mst, 650 GNUNET_SERVER_mst_receive (plugin->mst, &si, (const char *) &msg[1],
666 &si,
667 (const char *) &msg[1],
668 ntohs (msg->header.size) - 651 ntohs (msg->header.size) -
669 sizeof (struct UDPMessage), GNUNET_YES, GNUNET_NO); 652 sizeof (struct UDPMessage), GNUNET_YES, GNUNET_NO);
670} 653}
@@ -691,8 +674,7 @@ fragment_msg_proc (void *cls, const struct GNUNET_MessageHeader *msg)
691 GNUNET_break (0); 674 GNUNET_break (0);
692 return; 675 return;
693 } 676 }
694 process_udp_message (rc->plugin, 677 process_udp_message (rc->plugin, (const struct UDPMessage *) msg,
695 (const struct UDPMessage *) msg,
696 rc->src_addr, rc->addr_len); 678 rc->src_addr, rc->addr_len);
697} 679}
698 680
@@ -713,13 +695,11 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
713 struct UDPMessage *udp; 695 struct UDPMessage *udp;
714 696
715#if DEBUG_UDP 697#if DEBUG_UDP
716 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 698 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", "Sending ACK to `%s'\n",
717 "udp",
718 "Sending ACK to `%s'\n",
719 GNUNET_a2s (rc->src_addr, 699 GNUNET_a2s (rc->src_addr,
720 (rc->src_addr->sa_family == AF_INET) 700 (rc->src_addr->sa_family ==
721 ? sizeof (struct sockaddr_in) 701 AF_INET) ? sizeof (struct sockaddr_in) :
722 : sizeof (struct sockaddr_in6))); 702 sizeof (struct sockaddr_in6)));
723#endif 703#endif
724 udp = (struct UDPMessage *) buf; 704 udp = (struct UDPMessage *) buf;
725 udp->header.size = htons ((uint16_t) msize); 705 udp->header.size = htons ((uint16_t) msize);
@@ -764,8 +744,7 @@ struct FindReceiveContext
764 * GNUNET_NO if not. 744 * GNUNET_NO if not.
765 */ 745 */
766static int 746static int
767find_receive_context (void *cls, 747find_receive_context (void *cls, struct GNUNET_CONTAINER_HeapNode *node,
768 struct GNUNET_CONTAINER_HeapNode *node,
769 void *element, GNUNET_CONTAINER_HeapCostType cost) 748 void *element, GNUNET_CONTAINER_HeapCostType cost)
770{ 749{
771 struct FindReceiveContext *frc = cls; 750 struct FindReceiveContext *frc = cls;
@@ -804,8 +783,9 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
804 783
805 fromlen = sizeof (addr); 784 fromlen = sizeof (addr);
806 memset (&addr, 0, sizeof (addr)); 785 memset (&addr, 0, sizeof (addr));
807 ret = GNUNET_NETWORK_socket_recvfrom (rsock, buf, sizeof (buf), 786 ret =
808 (struct sockaddr *) &addr, &fromlen); 787 GNUNET_NETWORK_socket_recvfrom (rsock, buf, sizeof (buf),
788 (struct sockaddr *) &addr, &fromlen);
809 if (ret < sizeof (struct GNUNET_MessageHeader)) 789 if (ret < sizeof (struct GNUNET_MessageHeader))
810 { 790 {
811 GNUNET_break_op (0); 791 GNUNET_break_op (0);
@@ -813,8 +793,7 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
813 } 793 }
814#if DEBUG_UDP 794#if DEBUG_UDP
815 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
816 "UDP received %u-byte message from `%s'\n", 796 "UDP received %u-byte message from `%s'\n", (unsigned int) ret,
817 (unsigned int) ret,
818 GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); 797 GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
819#endif 798#endif
820 msg = (const struct GNUNET_MessageHeader *) buf; 799 msg = (const struct GNUNET_MessageHeader *) buf;
@@ -831,8 +810,7 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
831 GNUNET_break_op (0); 810 GNUNET_break_op (0);
832 return; 811 return;
833 } 812 }
834 process_udp_message (plugin, 813 process_udp_message (plugin, (const struct UDPMessage *) msg,
835 (const struct UDPMessage *) msg,
836 (const struct sockaddr *) addr, fromlen); 814 (const struct sockaddr *) addr, fromlen);
837 return; 815 return;
838 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK: 816 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK:
@@ -857,8 +835,7 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
857#if DEBUG_UDP 835#if DEBUG_UDP
858 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 836 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
859 "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", 837 "UDP processes %u-byte acknowledgement from `%s' at `%s'\n",
860 (unsigned int) ntohs (msg->size), 838 (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp->sender),
861 GNUNET_i2s (&udp->sender),
862 GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); 839 GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
863#endif 840#endif
864 841
@@ -875,8 +852,8 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
875 return; 852 return;
876 GNUNET_assert (GNUNET_OK == 853 GNUNET_assert (GNUNET_OK ==
877 GNUNET_CONTAINER_multihashmap_remove (plugin->sessions, 854 GNUNET_CONTAINER_multihashmap_remove (plugin->sessions,
878 &udp-> 855 &udp->sender.
879 sender.hashPubKey, 856 hashPubKey,
880 peer_session)); 857 peer_session));
881 plugin->last_expected_delay = 858 plugin->last_expected_delay =
882 GNUNET_FRAGMENT_context_destroy (peer_session->frag); 859 GNUNET_FRAGMENT_context_destroy (peer_session->frag);
@@ -887,8 +864,8 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
887 frc.rc = NULL; 864 frc.rc = NULL;
888 frc.addr = (const struct sockaddr *) addr; 865 frc.addr = (const struct sockaddr *) addr;
889 frc.addr_len = fromlen; 866 frc.addr_len = fromlen;
890 GNUNET_CONTAINER_heap_iterate (plugin->defrags, 867 GNUNET_CONTAINER_heap_iterate (plugin->defrags, &find_receive_context,
891 &find_receive_context, &frc); 868 &frc);
892 now = GNUNET_TIME_absolute_get (); 869 now = GNUNET_TIME_absolute_get ();
893 rc = frc.rc; 870 rc = frc.rc;
894 if (rc == NULL) 871 if (rc == NULL)
@@ -899,16 +876,14 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
899 rc->src_addr = (const struct sockaddr *) &rc[1]; 876 rc->src_addr = (const struct sockaddr *) &rc[1];
900 rc->addr_len = fromlen; 877 rc->addr_len = fromlen;
901 rc->plugin = plugin; 878 rc->plugin = plugin;
902 rc->defrag = GNUNET_DEFRAGMENT_context_create (plugin->env->stats, 879 rc->defrag =
903 UDP_MTU, 880 GNUNET_DEFRAGMENT_context_create (plugin->env->stats, UDP_MTU,
904 UDP_MAX_MESSAGES_IN_DEFRAG, 881 UDP_MAX_MESSAGES_IN_DEFRAG, rc,
905 rc, 882 &fragment_msg_proc, &ack_proc);
906 &fragment_msg_proc, 883 rc->hnode =
907 &ack_proc); 884 GNUNET_CONTAINER_heap_insert (plugin->defrags, rc,
908 rc->hnode = GNUNET_CONTAINER_heap_insert (plugin->defrags, 885 (GNUNET_CONTAINER_HeapCostType) now.
909 rc, 886 abs_value);
910 (GNUNET_CONTAINER_HeapCostType)
911 now.abs_value);
912 } 887 }
913#if DEBUG_UDP 888#if DEBUG_UDP
914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -920,10 +895,9 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
920 if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (rc->defrag, msg)) 895 if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (rc->defrag, msg))
921 { 896 {
922 /* keep this 'rc' from expiring */ 897 /* keep this 'rc' from expiring */
923 GNUNET_CONTAINER_heap_update_cost (plugin->defrags, 898 GNUNET_CONTAINER_heap_update_cost (plugin->defrags, rc->hnode,
924 rc->hnode, 899 (GNUNET_CONTAINER_HeapCostType) now.
925 (GNUNET_CONTAINER_HeapCostType) 900 abs_value);
926 now.abs_value);
927 } 901 }
928 if (GNUNET_CONTAINER_heap_get_size (plugin->defrags) > 902 if (GNUNET_CONTAINER_heap_get_size (plugin->defrags) >
929 UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG) 903 UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG)
@@ -1026,8 +1000,8 @@ udp_plugin_check_address (void *cls, const void *addr, size_t addrlen)
1026 if (GNUNET_OK != check_port (plugin, ntohs (v4->u4_port))) 1000 if (GNUNET_OK != check_port (plugin, ntohs (v4->u4_port)))
1027 return GNUNET_SYSERR; 1001 return GNUNET_SYSERR;
1028 if (GNUNET_OK != 1002 if (GNUNET_OK !=
1029 GNUNET_NAT_test_address (plugin->nat, 1003 GNUNET_NAT_test_address (plugin->nat, &v4->ipv4_addr,
1030 &v4->ipv4_addr, sizeof (struct in_addr))) 1004 sizeof (struct in_addr)))
1031 return GNUNET_SYSERR; 1005 return GNUNET_SYSERR;
1032 } 1006 }
1033 else 1007 else
@@ -1041,8 +1015,8 @@ udp_plugin_check_address (void *cls, const void *addr, size_t addrlen)
1041 if (GNUNET_OK != check_port (plugin, ntohs (v6->u6_port))) 1015 if (GNUNET_OK != check_port (plugin, ntohs (v6->u6_port)))
1042 return GNUNET_SYSERR; 1016 return GNUNET_SYSERR;
1043 if (GNUNET_OK != 1017 if (GNUNET_OK !=
1044 GNUNET_NAT_test_address (plugin->nat, 1018 GNUNET_NAT_test_address (plugin->nat, &v6->ipv6_addr,
1045 &v6->ipv6_addr, sizeof (struct in6_addr))) 1019 sizeof (struct in6_addr)))
1046 return GNUNET_SYSERR; 1020 return GNUNET_SYSERR;
1047 } 1021 }
1048 return GNUNET_OK; 1022 return GNUNET_OK;
@@ -1161,10 +1135,8 @@ append_port (void *cls, const char *hostname)
1161 * @param asc_cls closure for asc 1135 * @param asc_cls closure for asc
1162 */ 1136 */
1163static void 1137static void
1164udp_plugin_address_pretty_printer (void *cls, 1138udp_plugin_address_pretty_printer (void *cls, const char *type,
1165 const char *type, 1139 const void *addr, size_t addrlen,
1166 const void *addr,
1167 size_t addrlen,
1168 int numeric, 1140 int numeric,
1169 struct GNUNET_TIME_Relative timeout, 1141 struct GNUNET_TIME_Relative timeout,
1170 GNUNET_TRANSPORT_AddressStringCallback asc, 1142 GNUNET_TRANSPORT_AddressStringCallback asc,
@@ -1232,8 +1204,7 @@ udp_plugin_address_pretty_printer (void *cls,
1232 * @param addrlen actual lenght of the address 1204 * @param addrlen actual lenght of the address
1233 */ 1205 */
1234static void 1206static void
1235udp_nat_port_map_callback (void *cls, 1207udp_nat_port_map_callback (void *cls, int add_remove,
1236 int add_remove,
1237 const struct sockaddr *addr, socklen_t addrlen) 1208 const struct sockaddr *addr, socklen_t addrlen)
1238{ 1209{
1239 struct Plugin *plugin = cls; 1210 struct Plugin *plugin = cls;
@@ -1254,8 +1225,7 @@ udp_nat_port_map_callback (void *cls,
1254 break; 1225 break;
1255 case AF_INET6: 1226 case AF_INET6:
1256 GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); 1227 GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
1257 memcpy (&u6.ipv6_addr, 1228 memcpy (&u6.ipv6_addr, &((struct sockaddr_in6 *) addr)->sin6_addr,
1258 &((struct sockaddr_in6 *) addr)->sin6_addr,
1259 sizeof (struct in6_addr)); 1229 sizeof (struct in6_addr));
1260 u6.u6_port = ((struct sockaddr_in6 *) addr)->sin6_port; 1230 u6.u6_port = ((struct sockaddr_in6 *) addr)->sin6_port;
1261 arg = &u6; 1231 arg = &u6;
@@ -1296,24 +1266,22 @@ libgnunet_plugin_transport_udp_init (void *cls)
1296 unsigned long long udp_max_bps; 1266 unsigned long long udp_max_bps;
1297 1267
1298 if (GNUNET_OK != 1268 if (GNUNET_OK !=
1299 GNUNET_CONFIGURATION_get_value_number (env->cfg, 1269 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", "PORT",
1300 "transport-udp", "PORT", &port)) 1270 &port))
1301 port = 2086; 1271 port = 2086;
1302 if (GNUNET_OK != 1272 if (GNUNET_OK !=
1303 GNUNET_CONFIGURATION_get_value_number (env->cfg, 1273 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp",
1304 "transport-udp",
1305 "MAX_BPS", &udp_max_bps)) 1274 "MAX_BPS", &udp_max_bps))
1306 udp_max_bps = 1024 * 1024 * 50; /* 50 MB/s == infinity for practical purposes */ 1275 udp_max_bps = 1024 * 1024 * 50; /* 50 MB/s == infinity for practical purposes */
1307 if (GNUNET_OK != 1276 if (GNUNET_OK !=
1308 GNUNET_CONFIGURATION_get_value_number (env->cfg, 1277 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp",
1309 "transport-udp",
1310 "ADVERTISED_PORT", &aport)) 1278 "ADVERTISED_PORT", &aport))
1311 aport = port; 1279 aport = port;
1312 if (port > 65535) 1280 if (port > 65535)
1313 { 1281 {
1314 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1282 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1315 _("Given `%s' option is out of range: %llu > %u\n"), 1283 _("Given `%s' option is out of range: %llu > %u\n"), "PORT",
1316 "PORT", port, 65535); 1284 port, 65535);
1317 return NULL; 1285 return NULL;
1318 } 1286 }
1319 memset (&serverAddrv6, 0, sizeof (serverAddrv6)); 1287 memset (&serverAddrv6, 0, sizeof (serverAddrv6));
@@ -1336,10 +1304,9 @@ libgnunet_plugin_transport_udp_init (void *cls)
1336 api->address_to_string = &udp_address_to_string; 1304 api->address_to_string = &udp_address_to_string;
1337 api->check_address = &udp_plugin_check_address; 1305 api->check_address = &udp_plugin_check_address;
1338 1306
1339 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (env->cfg, 1307 if (GNUNET_YES ==
1340 "transport-udp", 1308 GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp",
1341 "BINDTO", 1309 "BINDTO", &plugin->bind4_address))
1342 &plugin->bind4_address))
1343 { 1310 {
1344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1345 "Binding udp plugin to specific address: `%s'\n", 1312 "Binding udp plugin to specific address: `%s'\n",
@@ -1353,19 +1320,18 @@ libgnunet_plugin_transport_udp_init (void *cls)
1353 } 1320 }
1354 } 1321 }
1355 1322
1356 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (env->cfg, 1323 if (GNUNET_YES ==
1357 "transport-udp", 1324 GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp",
1358 "BINDTO6", 1325 "BINDTO6", &plugin->bind6_address))
1359 &plugin->bind6_address))
1360 { 1326 {
1361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1327 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1362 "Binding udp plugin to specific address: `%s'\n", 1328 "Binding udp plugin to specific address: `%s'\n",
1363 plugin->bind6_address); 1329 plugin->bind6_address);
1364 if (1 != inet_pton (AF_INET6, 1330 if (1 !=
1365 plugin->bind6_address, &serverAddrv6.sin6_addr)) 1331 inet_pton (AF_INET6, plugin->bind6_address, &serverAddrv6.sin6_addr))
1366 { 1332 {
1367 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1333 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Invalid IPv6 address: `%s'\n"),
1368 _("Invalid IPv6 address: `%s'\n"), plugin->bind6_address); 1334 plugin->bind6_address);
1369 GNUNET_free_non_null (plugin->bind4_address); 1335 GNUNET_free_non_null (plugin->bind4_address);
1370 GNUNET_free (plugin->bind6_address); 1336 GNUNET_free (plugin->bind6_address);
1371 GNUNET_free (plugin); 1337 GNUNET_free (plugin);
@@ -1381,8 +1347,8 @@ libgnunet_plugin_transport_udp_init (void *cls)
1381 * 2); 1347 * 2);
1382 sockets_created = 0; 1348 sockets_created = 0;
1383 if ((GNUNET_YES != 1349 if ((GNUNET_YES !=
1384 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, 1350 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, "nat",
1385 "nat", "DISABLEV6"))) 1351 "DISABLEV6")))
1386 { 1352 {
1387 plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0); 1353 plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0);
1388 if (NULL == plugin->sockv6) 1354 if (NULL == plugin->sockv6)
@@ -1400,12 +1366,12 @@ libgnunet_plugin_transport_udp_init (void *cls)
1400 addrlen = sizeof (serverAddrv6); 1366 addrlen = sizeof (serverAddrv6);
1401 serverAddr = (struct sockaddr *) &serverAddrv6; 1367 serverAddr = (struct sockaddr *) &serverAddrv6;
1402#if DEBUG_UDP 1368#if DEBUG_UDP
1403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1369 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv6 port %d\n",
1404 "Binding to IPv6 port %d\n", ntohs (serverAddrv6.sin6_port)); 1370 ntohs (serverAddrv6.sin6_port));
1405#endif 1371#endif
1406 tries = 0; 1372 tries = 0;
1407 while (GNUNET_NETWORK_socket_bind (plugin->sockv6, 1373 while (GNUNET_NETWORK_socket_bind (plugin->sockv6, serverAddr, addrlen) !=
1408 serverAddr, addrlen) != GNUNET_OK) 1374 GNUNET_OK)
1409 { 1375 {
1410 serverAddrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ 1376 serverAddrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */
1411#if DEBUG_UDP 1377#if DEBUG_UDP
@@ -1430,8 +1396,8 @@ libgnunet_plugin_transport_udp_init (void *cls)
1430 } 1396 }
1431 } 1397 }
1432 1398
1433 plugin->mst = GNUNET_SERVER_mst_create (&process_inbound_tokenized_messages, 1399 plugin->mst =
1434 plugin); 1400 GNUNET_SERVER_mst_create (&process_inbound_tokenized_messages, plugin);
1435 plugin->sockv4 = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0); 1401 plugin->sockv4 = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0);
1436 if (NULL == plugin->sockv4) 1402 if (NULL == plugin->sockv4)
1437 { 1403 {
@@ -1448,8 +1414,8 @@ libgnunet_plugin_transport_udp_init (void *cls)
1448 addrlen = sizeof (serverAddrv4); 1414 addrlen = sizeof (serverAddrv4);
1449 serverAddr = (struct sockaddr *) &serverAddrv4; 1415 serverAddr = (struct sockaddr *) &serverAddrv4;
1450#if DEBUG_UDP 1416#if DEBUG_UDP
1451 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1417 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv4 port %d\n",
1452 "Binding to IPv4 port %d\n", ntohs (serverAddrv4.sin_port)); 1418 ntohs (serverAddrv4.sin_port));
1453#endif 1419#endif
1454 tries = 0; 1420 tries = 0;
1455 while (GNUNET_NETWORK_socket_bind (plugin->sockv4, serverAddr, addrlen) != 1421 while (GNUNET_NETWORK_socket_bind (plugin->sockv4, serverAddr, addrlen) !=
@@ -1491,12 +1457,10 @@ libgnunet_plugin_transport_udp_init (void *cls)
1491 NULL, &udp_plugin_select, plugin); 1457 NULL, &udp_plugin_select, plugin);
1492 if (sockets_created == 0) 1458 if (sockets_created == 0)
1493 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to open UDP sockets\n")); 1459 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to open UDP sockets\n"));
1494 plugin->nat = GNUNET_NAT_register (env->cfg, 1460 plugin->nat =
1495 GNUNET_NO, 1461 GNUNET_NAT_register (env->cfg, GNUNET_NO, port, sockets_created,
1496 port, 1462 (const struct sockaddr **) addrs, addrlens,
1497 sockets_created, 1463 &udp_nat_port_map_callback, NULL, plugin);
1498 (const struct sockaddr **) addrs, addrlens,
1499 &udp_nat_port_map_callback, NULL, plugin);
1500 return api; 1464 return api;
1501} 1465}
1502 1466
@@ -1534,8 +1498,8 @@ libgnunet_plugin_transport_udp_done (void *cls)
1534 struct ReceiveContext *rc; 1498 struct ReceiveContext *rc;
1535 1499
1536 /* FIXME: clean up heap and hashmap */ 1500 /* FIXME: clean up heap and hashmap */
1537 GNUNET_CONTAINER_multihashmap_iterate (plugin->sessions, 1501 GNUNET_CONTAINER_multihashmap_iterate (plugin->sessions, &destroy_session,
1538 &destroy_session, NULL); 1502 NULL);
1539 GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions); 1503 GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions);
1540 plugin->sessions = NULL; 1504 plugin->sessions = NULL;
1541 while (NULL != (rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags))) 1505 while (NULL != (rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags)))
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c
index 22dda8e8b..7193e2e8b 100644
--- a/src/transport/plugin_transport_unix.c
+++ b/src/transport/plugin_transport_unix.c
@@ -419,18 +419,16 @@ find_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *peer)
419} 419}
420 420
421/* Forward Declaration */ 421/* Forward Declaration */
422static ssize_t 422static ssize_t unix_real_send (void *cls,
423unix_real_send (void *cls, 423 struct RetrySendContext *incoming_retry_context,
424 struct RetrySendContext *incoming_retry_context, 424 struct GNUNET_NETWORK_Handle *send_handle,
425 struct GNUNET_NETWORK_Handle *send_handle, 425 const struct GNUNET_PeerIdentity *target,
426 const struct GNUNET_PeerIdentity *target, 426 const char *msgbuf, size_t msgbuf_size,
427 const char *msgbuf, 427 unsigned int priority,
428 size_t msgbuf_size, 428 struct GNUNET_TIME_Relative timeout,
429 unsigned int priority, 429 const void *addr, size_t addrlen,
430 struct GNUNET_TIME_Relative timeout, 430 GNUNET_TRANSPORT_TransmitContinuation cont,
431 const void *addr, 431 void *cont_cls);
432 size_t addrlen,
433 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls);
434 432
435/** 433/**
436 * Retry sending a message. 434 * Retry sending a message.
@@ -451,16 +449,12 @@ retry_send_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
451 return; 449 return;
452 } 450 }
453 451
454 unix_real_send (retry_ctx->plugin, 452 unix_real_send (retry_ctx->plugin, retry_ctx, retry_ctx->send_handle,
455 retry_ctx, 453 &retry_ctx->target, retry_ctx->msg, retry_ctx->msg_size,
456 retry_ctx->send_handle,
457 &retry_ctx->target,
458 retry_ctx->msg,
459 retry_ctx->msg_size,
460 retry_ctx->priority, 454 retry_ctx->priority,
461 GNUNET_TIME_absolute_get_remaining (retry_ctx->timeout), 455 GNUNET_TIME_absolute_get_remaining (retry_ctx->timeout),
462 retry_ctx->addr, 456 retry_ctx->addr, retry_ctx->addrlen, retry_ctx->cont,
463 retry_ctx->addrlen, retry_ctx->cont, retry_ctx->cont_cls); 457 retry_ctx->cont_cls);
464 return; 458 return;
465} 459}
466 460
@@ -487,17 +481,13 @@ retry_send_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
487 * @return the number of bytes written, -1 on errors 481 * @return the number of bytes written, -1 on errors
488 */ 482 */
489static ssize_t 483static ssize_t
490unix_real_send (void *cls, 484unix_real_send (void *cls, struct RetrySendContext *incoming_retry_context,
491 struct RetrySendContext *incoming_retry_context,
492 struct GNUNET_NETWORK_Handle *send_handle, 485 struct GNUNET_NETWORK_Handle *send_handle,
493 const struct GNUNET_PeerIdentity *target, 486 const struct GNUNET_PeerIdentity *target, const char *msgbuf,
494 const char *msgbuf, 487 size_t msgbuf_size, unsigned int priority,
495 size_t msgbuf_size, 488 struct GNUNET_TIME_Relative timeout, const void *addr,
496 unsigned int priority, 489 size_t addrlen, GNUNET_TRANSPORT_TransmitContinuation cont,
497 struct GNUNET_TIME_Relative timeout, 490 void *cont_cls)
498 const void *addr,
499 size_t addrlen,
500 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
501{ 491{
502 struct Plugin *plugin = cls; 492 struct Plugin *plugin = cls;
503 struct UNIXMessage *message; 493 struct UNIXMessage *message;
@@ -635,9 +625,8 @@ unix_real_send (void *cls,
635#if DEBUG_UNIX 625#if DEBUG_UNIX
636 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 626 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
637 "UNIX transmit %u-byte message to %s (%d: %s)\n", 627 "UNIX transmit %u-byte message to %s (%d: %s)\n",
638 (unsigned int) ssize, 628 (unsigned int) ssize, GNUNET_a2s (sb, sbs), (int) sent,
639 GNUNET_a2s (sb, sbs), 629 (sent < 0) ? STRERROR (errno) : "ok");
640 (int) sent, (sent < 0) ? STRERROR (errno) : "ok");
641#endif 630#endif
642 if (cont != NULL) 631 if (cont != NULL)
643 { 632 {
@@ -689,16 +678,10 @@ unix_real_send (void *cls,
689 * still be transmitted later!) 678 * still be transmitted later!)
690 */ 679 */
691static ssize_t 680static ssize_t
692unix_plugin_send (void *cls, 681unix_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
693 const struct GNUNET_PeerIdentity *target, 682 const char *msgbuf, size_t msgbuf_size, unsigned int priority,
694 const char *msgbuf, 683 struct GNUNET_TIME_Relative timeout, struct Session *session,
695 size_t msgbuf_size, 684 const void *addr, size_t addrlen, int force_address,
696 unsigned int priority,
697 struct GNUNET_TIME_Relative timeout,
698 struct Session *session,
699 const void *addr,
700 size_t addrlen,
701 int force_address,
702 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) 685 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
703{ 686{
704 struct Plugin *plugin = cls; 687 struct Plugin *plugin = cls;
@@ -712,12 +695,10 @@ unix_plugin_send (void *cls,
712 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asked to send message to `%s'\n", 695 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asked to send message to `%s'\n",
713 (char *) addr); 696 (char *) addr);
714#endif 697#endif
715 sent = unix_real_send (cls, 698 sent =
716 NULL, 699 unix_real_send (cls, NULL, plugin->unix_sock.desc, target, msgbuf,
717 plugin->unix_sock.desc, 700 msgbuf_size, priority, timeout, addr, addrlen, cont,
718 target, 701 cont_cls);
719 msgbuf, msgbuf_size,
720 priority, timeout, addr, addrlen, cont, cont_cls);
721#if DEBUG_UNIX 702#if DEBUG_UNIX
722 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent %d bytes to `%s'\n", sent, 703 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent %d bytes to `%s'\n", sent,
723 (char *) addr); 704 (char *) addr);
@@ -738,8 +719,7 @@ unix_plugin_send (void *cls,
738 * @param fromlen the length of the address 719 * @param fromlen the length of the address
739 */ 720 */
740static void 721static void
741unix_demultiplexer (struct Plugin *plugin, 722unix_demultiplexer (struct Plugin *plugin, struct GNUNET_PeerIdentity *sender,
742 struct GNUNET_PeerIdentity *sender,
743 const struct GNUNET_MessageHeader *currhdr, 723 const struct GNUNET_MessageHeader *currhdr,
744 const struct sockaddr_un *un, size_t fromlen) 724 const struct sockaddr_un *un, size_t fromlen)
745{ 725{
@@ -909,8 +889,8 @@ unix_transport_server_start (void *cls)
909 return GNUNET_SYSERR; 889 return GNUNET_SYSERR;
910 } 890 }
911#if DEBUG_UNIX 891#if DEBUG_UNIX
912 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 892 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "unix", "Bound to `%s'\n",
913 "unix", "Bound to `%s'\n", &un.sun_path[0]); 893 &un.sun_path[0]);
914#endif 894#endif
915 plugin->rs = GNUNET_NETWORK_fdset_create (); 895 plugin->rs = GNUNET_NETWORK_fdset_create ();
916 GNUNET_NETWORK_fdset_zero (plugin->rs); 896 GNUNET_NETWORK_fdset_zero (plugin->rs);
@@ -990,10 +970,8 @@ append_port (void *cls, const char *hostname)
990 * @param asc_cls closure for asc 970 * @param asc_cls closure for asc
991 */ 971 */
992static void 972static void
993unix_plugin_address_pretty_printer (void *cls, 973unix_plugin_address_pretty_printer (void *cls, const char *type,
994 const char *type, 974 const void *addr, size_t addrlen,
995 const void *addr,
996 size_t addrlen,
997 int numeric, 975 int numeric,
998 struct GNUNET_TIME_Relative timeout, 976 struct GNUNET_TIME_Relative timeout,
999 GNUNET_TRANSPORT_AddressStringCallback asc, 977 GNUNET_TRANSPORT_AddressStringCallback asc,
@@ -1075,8 +1053,7 @@ address_notification (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1075{ 1053{
1076 struct Plugin *plugin = cls; 1054 struct Plugin *plugin = cls;
1077 1055
1078 plugin->env->notify_address (plugin->env->cls, 1056 plugin->env->notify_address (plugin->env->cls, GNUNET_YES,
1079 GNUNET_YES,
1080 plugin->unix_socket_path, 1057 plugin->unix_socket_path,
1081 strlen (plugin->unix_socket_path) + 1); 1058 strlen (plugin->unix_socket_path) + 1);
1082} 1059}
@@ -1095,14 +1072,14 @@ libgnunet_plugin_transport_unix_init (void *cls)
1095 int sockets_created; 1072 int sockets_created;
1096 1073
1097 if (GNUNET_OK != 1074 if (GNUNET_OK !=
1098 GNUNET_CONFIGURATION_get_value_number (env->cfg, 1075 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-unix", "PORT",
1099 "transport-unix", "PORT", &port)) 1076 &port))
1100 port = UNIX_NAT_DEFAULT_PORT; 1077 port = UNIX_NAT_DEFAULT_PORT;
1101 plugin = GNUNET_malloc (sizeof (struct Plugin)); 1078 plugin = GNUNET_malloc (sizeof (struct Plugin));
1102 plugin->port = port; 1079 plugin->port = port;
1103 plugin->env = env; 1080 plugin->env = env;
1104 GNUNET_asprintf (&plugin->unix_socket_path, 1081 GNUNET_asprintf (&plugin->unix_socket_path, "/tmp/unix-plugin-sock.%d",
1105 "/tmp/unix-plugin-sock.%d", plugin->port); 1082 plugin->port);
1106 1083
1107 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); 1084 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
1108 api->cls = plugin; 1085 api->cls = plugin;
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c
index 6ed367293..ad8d9a7a1 100644
--- a/src/transport/plugin_transport_wlan.c
+++ b/src/transport/plugin_transport_wlan.c
@@ -662,11 +662,10 @@ struct FragmentMessage
662 struct Radiotap_Send *radioHeader; 662 struct Radiotap_Send *radioHeader;
663}; 663};
664 664
665static void 665static void do_transmit (void *cls,
666do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 666 const struct GNUNET_SCHEDULER_TaskContext *tc);
667static void 667static void free_session (struct Plugin *plugin, struct Sessionqueue *queue,
668free_session (struct Plugin *plugin, struct Sessionqueue *queue, 668 int do_free_macendpoint);
669 int do_free_macendpoint);
670static struct MacEndpoint *create_macendpoint (struct Plugin *plugin, 669static struct MacEndpoint *create_macendpoint (struct Plugin *plugin,
671 const struct MacAddress *addr); 670 const struct MacAddress *addr);
672 671
@@ -773,8 +772,9 @@ search_session (struct Plugin *plugin, const struct MacEndpoint *endpoint,
773 while (queue != NULL) 772 while (queue != NULL)
774 { 773 {
775 GNUNET_assert (queue->content != NULL); 774 GNUNET_assert (queue->content != NULL);
776 if (memcmp (peer, &queue->content->target, 775 if (memcmp
777 sizeof (struct GNUNET_PeerIdentity)) == 0) 776 (peer, &queue->content->target,
777 sizeof (struct GNUNET_PeerIdentity)) == 0)
778 return queue->content; /* session found */ 778 return queue->content; /* session found */
779 queue = queue->next; 779 queue = queue->next;
780 } 780 }
@@ -974,27 +974,29 @@ set_next_beacon_time (struct Plugin *const plugin)
974 //under 10 known peers: once a second 974 //under 10 known peers: once a second
975 if (plugin->mac_count < 10) 975 if (plugin->mac_count < 10)
976 { 976 {
977 plugin->beacon_time = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), 977 plugin->beacon_time =
978 GNUNET_TIME_relative_multiply 978 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
979 (GNUNET_TIME_UNIT_SECONDS, 979 GNUNET_TIME_relative_multiply
980 HALLO_BEACON_SCALING_FACTOR)); 980 (GNUNET_TIME_UNIT_SECONDS,
981 HALLO_BEACON_SCALING_FACTOR));
981 } 982 }
982 //under 30 known peers: every 10 seconds 983 //under 30 known peers: every 10 seconds
983 else if (plugin->mac_count < 30) 984 else if (plugin->mac_count < 30)
984 { 985 {
985 plugin->beacon_time = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), 986 plugin->beacon_time =
986 GNUNET_TIME_relative_multiply 987 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
987 (GNUNET_TIME_UNIT_SECONDS, 988 GNUNET_TIME_relative_multiply
988 10 * 989 (GNUNET_TIME_UNIT_SECONDS,
989 HALLO_BEACON_SCALING_FACTOR)); 990 10 * HALLO_BEACON_SCALING_FACTOR));
990 } 991 }
991 //over 30 known peers: once a minute 992 //over 30 known peers: once a minute
992 else 993 else
993 { 994 {
994 plugin->beacon_time = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), 995 plugin->beacon_time =
995 GNUNET_TIME_relative_multiply 996 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
996 (GNUNET_TIME_UNIT_MINUTES, 997 GNUNET_TIME_relative_multiply
997 HALLO_BEACON_SCALING_FACTOR)); 998 (GNUNET_TIME_UNIT_MINUTES,
999 HALLO_BEACON_SCALING_FACTOR));
998 } 1000 }
999} 1001}
1000 1002
@@ -1094,10 +1096,10 @@ get_next_queue_session (struct Plugin *plugin)
1094 if (GNUNET_TIME_absolute_get_remaining (pm->timeout).rel_value > 0) 1096 if (GNUNET_TIME_absolute_get_remaining (pm->timeout).rel_value > 0)
1095 { 1097 {
1096 //check if session has no message in the fragment queue 1098 //check if session has no message in the fragment queue
1097 if ((session->mac->fragment_messages_out_count 1099 if ((session->mac->fragment_messages_out_count <
1098 < FRAGMENT_QUEUE_MESSAGES_OUT_PER_MACENDPOINT) 1100 FRAGMENT_QUEUE_MESSAGES_OUT_PER_MACENDPOINT) &&
1099 && (session->fragment_messages_out_count 1101 (session->fragment_messages_out_count <
1100 < FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION)) 1102 FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION))
1101 { 1103 {
1102 plugin->pendingsessions--; 1104 plugin->pendingsessions--;
1103 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head, 1105 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
@@ -1335,8 +1337,9 @@ add_message_for_send (void *cls, const struct GNUNET_MessageHeader *hdr)
1335 fm, fm->session, endpoint); 1337 fm, fm->session, endpoint);
1336#endif 1338#endif
1337 1339
1338 size = sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) 1340 size =
1339 + sizeof (struct ieee80211_frame) + ntohs (hdr->size); 1341 sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) +
1342 sizeof (struct ieee80211_frame) + ntohs (hdr->size);
1340 fm->frag = GNUNET_malloc (size); 1343 fm->frag = GNUNET_malloc (size);
1341 fm->size = size; 1344 fm->size = size;
1342 1345
@@ -1382,9 +1385,10 @@ send_hello_beacon (struct Plugin *plugin)
1382 hello = plugin->env->get_our_hello (); 1385 hello = plugin->env->get_our_hello ();
1383 hallo_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello); 1386 hallo_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
1384 GNUNET_assert (sizeof (struct WlanHeader) + hallo_size <= WLAN_MTU); 1387 GNUNET_assert (sizeof (struct WlanHeader) + hallo_size <= WLAN_MTU);
1385 size = sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) 1388 size =
1386 + sizeof (struct ieee80211_frame) + sizeof (struct GNUNET_MessageHeader) 1389 sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) +
1387 + hallo_size; 1390 sizeof (struct ieee80211_frame) + sizeof (struct GNUNET_MessageHeader) +
1391 hallo_size;
1388 1392
1389 msgheader = GNUNET_malloc (size); 1393 msgheader = GNUNET_malloc (size);
1390 msgheader->size = htons (size); 1394 msgheader->size = htons (size);
@@ -1443,16 +1447,18 @@ add_ack_for_send (void *cls, uint32_t msg_id,
1443 struct GNUNET_MessageHeader *msgheader2; 1447 struct GNUNET_MessageHeader *msgheader2;
1444 uint16_t size; 1448 uint16_t size;
1445 1449
1446 size = sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) 1450 size =
1447 + sizeof (struct ieee80211_frame) + ntohs (hdr->size) 1451 sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) +
1448 + sizeof (struct AckSendQueue); 1452 sizeof (struct ieee80211_frame) + ntohs (hdr->size) +
1453 sizeof (struct AckSendQueue);
1449 1454
1450 ack = GNUNET_malloc (size); 1455 ack = GNUNET_malloc (size);
1451 ack->message_id = msg_id; 1456 ack->message_id = msg_id;
1452 ack->endpoint = endpoint; 1457 ack->endpoint = endpoint;
1453 1458
1454 size = sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) 1459 size =
1455 + sizeof (struct ieee80211_frame) + ntohs (hdr->size); 1460 sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) +
1461 sizeof (struct ieee80211_frame) + ntohs (hdr->size);
1456 1462
1457 msgheader = (struct GNUNET_MessageHeader *) &ack[1]; 1463 msgheader = (struct GNUNET_MessageHeader *) &ack[1];
1458 ack->hdr = (struct GNUNET_MessageHeader *) &ack[1]; 1464 ack->hdr = (struct GNUNET_MessageHeader *) &ack[1];
@@ -1528,13 +1534,12 @@ check_fragment_queue (struct Plugin *plugin)
1528 fm->session = session; 1534 fm->session = session;
1529 fm->timeout.abs_value = pm->timeout.abs_value; 1535 fm->timeout.abs_value = pm->timeout.abs_value;
1530 fm->frag = NULL; 1536 fm->frag = NULL;
1531 fm->fragcontext = GNUNET_FRAGMENT_context_create (plugin->env->stats, 1537 fm->fragcontext =
1532 WLAN_MTU, 1538 GNUNET_FRAGMENT_context_create (plugin->env->stats, WLAN_MTU,
1533 &plugin->tracker, 1539 &plugin->tracker,
1534 GNUNET_TIME_UNIT_SECONDS, 1540 GNUNET_TIME_UNIT_SECONDS,
1535 &(pm->msg->header), 1541 &(pm->msg->header),
1536 &add_message_for_send, 1542 &add_message_for_send, fm);
1537 fm);
1538 fm->timeout_task = 1543 fm->timeout_task =
1539 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining 1544 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
1540 (fm->timeout), fragmentmessage_timeout, 1545 (fm->timeout), fragmentmessage_timeout,
@@ -1596,8 +1601,9 @@ send_ack (struct Plugin *plugin, struct AckSendQueue *ack)
1596 getWlanHeader (ack->ieeewlanheader, &ack->endpoint->addr, plugin, 1601 getWlanHeader (ack->ieeewlanheader, &ack->endpoint->addr, plugin,
1597 ntohs (ack->hdr->size)); 1602 ntohs (ack->hdr->size));
1598 1603
1599 bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle, ack->hdr, 1604 bytes =
1600 ntohs (ack->hdr->size)); 1605 GNUNET_DISK_file_write (plugin->server_stdin_handle, ack->hdr,
1606 ntohs (ack->hdr->size));
1601 if (bytes == GNUNET_SYSERR) 1607 if (bytes == GNUNET_SYSERR)
1602 { 1608 {
1603 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME, 1609 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
@@ -1632,8 +1638,9 @@ finish_sending (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1632 GNUNET_free (finish); 1638 GNUNET_free (finish);
1633 return; 1639 return;
1634 } 1640 }
1635 bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle, 1641 bytes =
1636 finish->msgheader, finish->size); 1642 GNUNET_DISK_file_write (plugin->server_stdin_handle, finish->msgheader,
1643 finish->size);
1637 GNUNET_assert (bytes != GNUNET_SYSERR); 1644 GNUNET_assert (bytes != GNUNET_SYSERR);
1638 1645
1639 if (bytes != finish->size) 1646 if (bytes != finish->size)
@@ -1713,8 +1720,9 @@ do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1713 getWlanHeader (fm->ieeewlanheader, &(fm->session->mac->addr), plugin, 1720 getWlanHeader (fm->ieeewlanheader, &(fm->session->mac->addr), plugin,
1714 fm->size); 1721 fm->size);
1715 1722
1716 bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle, fm->frag, 1723 bytes =
1717 fm->size); 1724 GNUNET_DISK_file_write (plugin->server_stdin_handle, fm->frag,
1725 fm->size);
1718 if (bytes == GNUNET_SYSERR) 1726 if (bytes == GNUNET_SYSERR)
1719 { 1727 {
1720 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME, 1728 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
@@ -1852,9 +1860,8 @@ wlan_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
1852 newmsg = session->pending_message_head; 1860 newmsg = session->pending_message_head;
1853 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME, 1861 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1854 "wlan_plugin_send: a pending message is already in the queue for this client\n remaining time to send this message is %u, queued fragment messages for this mac connection %u\n", 1862 "wlan_plugin_send: a pending message is already in the queue for this client\n remaining time to send this message is %u, queued fragment messages for this mac connection %u\n",
1855 GNUNET_TIME_absolute_get_remaining (newmsg-> 1863 GNUNET_TIME_absolute_get_remaining (newmsg->timeout).
1856 timeout).rel_value, 1864 rel_value, session->mac->fragment_messages_out_count);
1857 session->mac->fragment_messages_out_count);
1858 } 1865 }
1859 1866
1860 newmsg = GNUNET_malloc (sizeof (struct PendingMessage)); 1867 newmsg = GNUNET_malloc (sizeof (struct PendingMessage));
@@ -1992,8 +1999,8 @@ free_session (struct Plugin *plugin, struct Sessionqueue *queue,
1992 pm = queue->content->pending_message_head; 1999 pm = queue->content->pending_message_head;
1993 } 2000 }
1994 2001
1995 GNUNET_CONTAINER_DLL_remove (endpoint->sessions_head, 2002 GNUNET_CONTAINER_DLL_remove (endpoint->sessions_head, endpoint->sessions_tail,
1996 endpoint->sessions_tail, queue); 2003 queue);
1997 2004
1998 if (endpoint->sessions_head == NULL && do_free_macendpoint == GNUNET_YES) 2005 if (endpoint->sessions_head == NULL && do_free_macendpoint == GNUNET_YES)
1999 { 2006 {
@@ -2033,8 +2040,9 @@ wlan_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
2033 // content is never NULL 2040 // content is never NULL
2034 GNUNET_assert (queue->content != NULL); 2041 GNUNET_assert (queue->content != NULL);
2035 queue_next = queue->next; 2042 queue_next = queue->next;
2036 if (memcmp (target, &(queue->content->target), 2043 if (memcmp
2037 sizeof (struct GNUNET_PeerIdentity)) == 0) 2044 (target, &(queue->content->target),
2045 sizeof (struct GNUNET_PeerIdentity)) == 0)
2038 { 2046 {
2039 free_session (plugin, queue, GNUNET_YES); 2047 free_session (plugin, queue, GNUNET_YES);
2040 } 2048 }
@@ -2113,8 +2121,8 @@ wlan_data_message_handler (void *cls, const struct GNUNET_MessageHeader *hdr)
2113 ntohs (hdr->size)); 2121 ntohs (hdr->size));
2114#endif 2122#endif
2115 2123
2116 if (ntohs (hdr->size) < sizeof (struct WlanHeader) 2124 if (ntohs (hdr->size) <
2117 + sizeof (struct GNUNET_MessageHeader)) 2125 sizeof (struct WlanHeader) + sizeof (struct GNUNET_MessageHeader))
2118 { 2126 {
2119 //packet not big enought 2127 //packet not big enought
2120 return; 2128 return;
@@ -2149,13 +2157,14 @@ wlan_data_message_handler (void *cls, const struct GNUNET_MessageHeader *hdr)
2149 sizeof (struct WlanHeader)); 2157 sizeof (struct WlanHeader));
2150#endif 2158#endif
2151 //try if it is a hello message 2159 //try if it is a hello message
2152 if (ntohs (wlanheader->header.size) >= ntohs (temp_hdr->size) 2160 if (ntohs (wlanheader->header.size) >=
2153 + sizeof (struct WlanHeader)) 2161 ntohs (temp_hdr->size) + sizeof (struct WlanHeader))
2154 { 2162 {
2155 if (ntohs (temp_hdr->type) == GNUNET_MESSAGE_TYPE_HELLO) 2163 if (ntohs (temp_hdr->type) == GNUNET_MESSAGE_TYPE_HELLO)
2156 { 2164 {
2157 if (GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) 2165 if (GNUNET_HELLO_get_id
2158 temp_hdr, &tmpsource) == GNUNET_OK) 2166 ((const struct GNUNET_HELLO_Message *) temp_hdr,
2167 &tmpsource) == GNUNET_OK)
2159 { 2168 {
2160 session = create_session (plugin, endpoint, &tmpsource); 2169 session = create_session (plugin, endpoint, &tmpsource);
2161 } 2170 }
@@ -2186,8 +2195,9 @@ wlan_data_message_handler (void *cls, const struct GNUNET_MessageHeader *hdr)
2186 2195
2187 //"receive" the message 2196 //"receive" the message
2188 2197
2189 if (memcmp (&wlanheader->source, &session->target, 2198 if (memcmp
2190 sizeof (struct GNUNET_PeerIdentity)) != 0) 2199 (&wlanheader->source, &session->target,
2200 sizeof (struct GNUNET_PeerIdentity)) != 0)
2191 { 2201 {
2192 //wrong peer id 2202 //wrong peer id
2193#if DEBUG_wlan 2203#if DEBUG_wlan
@@ -2198,8 +2208,9 @@ wlan_data_message_handler (void *cls, const struct GNUNET_MessageHeader *hdr)
2198 return; 2208 return;
2199 } 2209 }
2200 2210
2201 if (memcmp (&wlanheader->target, plugin->env->my_identity, 2211 if (memcmp
2202 sizeof (struct GNUNET_PeerIdentity)) != 0) 2212 (&wlanheader->target, plugin->env->my_identity,
2213 sizeof (struct GNUNET_PeerIdentity)) != 0)
2203 { 2214 {
2204 //wrong peer id 2215 //wrong peer id
2205#if DEBUG_wlan 2216#if DEBUG_wlan
@@ -2252,8 +2263,8 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
2252 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2263 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2253 "Calling plugin->env->receive for session %p; %s; size: %u\n", 2264 "Calling plugin->env->receive for session %p; %s; size: %u\n",
2254 session, wlan_plugin_address_to_string (NULL, 2265 session, wlan_plugin_address_to_string (NULL,
2255 session->mac-> 2266 session->mac->addr.
2256 addr.mac, 6), 2267 mac, 6),
2257 htons (hdr->size)); 2268 htons (hdr->size));
2258#endif 2269#endif
2259 2270
@@ -2291,22 +2302,20 @@ wlan_data_helper (void *cls, struct Session_light *session_light,
2291#if DEBUG_wlan 2302#if DEBUG_wlan
2292 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2303 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2293 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT size: %u; %s\n", 2304 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT size: %u; %s\n",
2294 ntohs (hdr->size), 2305 ntohs (hdr->size), wlan_plugin_address_to_string (NULL,
2295 wlan_plugin_address_to_string (NULL, 2306 session_light->
2296 session_light->addr.mac, 2307 addr.mac,
2297 6)); 2308 6));
2298#endif 2309#endif
2299 2310
2300 if (session_light->macendpoint == NULL) 2311 if (session_light->macendpoint == NULL)
2301 { 2312 {
2302 session_light->macendpoint = get_macendpoint (plugin, 2313 session_light->macendpoint =
2303 &session_light->addr, 2314 get_macendpoint (plugin, &session_light->addr, GNUNET_NO);
2304 GNUNET_NO);
2305 } 2315 }
2306 GNUNET_assert (GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) 2316 GNUNET_assert (GNUNET_HELLO_get_id
2307 &hdr[1], 2317 ((const struct GNUNET_HELLO_Message *) &hdr[1],
2308 &(session_light->session->target)) != 2318 &(session_light->session->target)) != GNUNET_SYSERR);
2309 GNUNET_SYSERR);
2310 2319
2311 } 2320 }
2312 2321
@@ -2318,9 +2327,8 @@ wlan_data_helper (void *cls, struct Session_light *session_light,
2318 GNUNET_assert (session_light != NULL); 2327 GNUNET_assert (session_light != NULL);
2319 if (session_light->macendpoint == NULL) 2328 if (session_light->macendpoint == NULL)
2320 { 2329 {
2321 session_light->macendpoint = get_macendpoint (plugin, 2330 session_light->macendpoint =
2322 &session_light->addr, 2331 get_macendpoint (plugin, &session_light->addr, GNUNET_YES);
2323 GNUNET_YES);
2324 } 2332 }
2325 2333
2326#if DEBUG_wlan 2334#if DEBUG_wlan
@@ -2355,9 +2363,8 @@ wlan_data_helper (void *cls, struct Session_light *session_light,
2355 GNUNET_assert (session_light != NULL); 2363 GNUNET_assert (session_light != NULL);
2356 if (session_light->macendpoint == NULL) 2364 if (session_light->macendpoint == NULL)
2357 { 2365 {
2358 session_light->macendpoint = get_macendpoint (plugin, 2366 session_light->macendpoint =
2359 &session_light->addr, 2367 get_macendpoint (plugin, &session_light->addr, GNUNET_NO);
2360 GNUNET_NO);
2361 } 2368 }
2362 2369
2363 if (session_light->macendpoint == NULL) 2370 if (session_light->macendpoint == NULL)
@@ -2365,10 +2372,11 @@ wlan_data_helper (void *cls, struct Session_light *session_light,
2365#if DEBUG_wlan 2372#if DEBUG_wlan
2366 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2373 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2367 "Macendpoint does not exist for this GNUNET_MESSAGE_TYPE_FRAGMENT_ACK size: %u; %s\n", 2374 "Macendpoint does not exist for this GNUNET_MESSAGE_TYPE_FRAGMENT_ACK size: %u; %s\n",
2368 ntohs (hdr->size), 2375 ntohs (hdr->size), wlan_plugin_address_to_string (NULL,
2369 wlan_plugin_address_to_string (NULL, 2376 session_light->
2370 session_light->addr.mac, 2377 addr.
2371 6)); 2378 mac,
2379 6));
2372#endif 2380#endif
2373 return; 2381 return;
2374 } 2382 }
@@ -2469,16 +2477,16 @@ macendpoint_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2469 return; 2477 return;
2470 } 2478 }
2471 if (GNUNET_TIME_absolute_get_remaining 2479 if (GNUNET_TIME_absolute_get_remaining
2472 (GNUNET_TIME_absolute_add 2480 (GNUNET_TIME_absolute_add (endpoint->last_activity, MACENDPOINT_TIMEOUT)).
2473 (endpoint->last_activity, MACENDPOINT_TIMEOUT)).rel_value == 0) 2481 rel_value == 0)
2474 { 2482 {
2475 free_macendpoint (endpoint->plugin, endpoint); 2483 free_macendpoint (endpoint->plugin, endpoint);
2476 } 2484 }
2477 else 2485 else
2478 { 2486 {
2479 endpoint->timeout_task = GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT, 2487 endpoint->timeout_task =
2480 &macendpoint_timeout, 2488 GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT, &macendpoint_timeout,
2481 endpoint); 2489 endpoint);
2482 } 2490 }
2483} 2491}
2484 2492
@@ -2497,16 +2505,15 @@ create_macendpoint (struct Plugin *plugin, const struct MacAddress *addr)
2497 newend->plugin = plugin; 2505 newend->plugin = plugin;
2498 newend->addr = *addr; 2506 newend->addr = *addr;
2499 newend->fragment_messages_out_count = 0; 2507 newend->fragment_messages_out_count = 0;
2500 newend->defrag = GNUNET_DEFRAGMENT_context_create (plugin->env->stats, 2508 newend->defrag =
2501 WLAN_MTU, 2509 GNUNET_DEFRAGMENT_context_create (plugin->env->stats, WLAN_MTU,
2502 MESSAGES_IN_DEFRAG_QUEUE_PER_MAC, 2510 MESSAGES_IN_DEFRAG_QUEUE_PER_MAC,
2503 newend, 2511 newend, &wlan_data_message_handler,
2504 &wlan_data_message_handler, 2512 &add_ack_for_send);
2505 &add_ack_for_send);
2506 newend->last_activity = GNUNET_TIME_absolute_get (); 2513 newend->last_activity = GNUNET_TIME_absolute_get ();
2507 newend->timeout_task = GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT, 2514 newend->timeout_task =
2508 &macendpoint_timeout, 2515 GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT, &macendpoint_timeout,
2509 newend); 2516 newend);
2510 2517
2511 plugin->mac_count++; 2518 plugin->mac_count++;
2512 GNUNET_CONTAINER_DLL_insert_tail (plugin->mac_head, plugin->mac_tail, newend); 2519 GNUNET_CONTAINER_DLL_insert_tail (plugin->mac_head, plugin->mac_tail, newend);
@@ -2548,15 +2555,16 @@ wlan_process_helper (void *cls, void *client,
2548#endif 2555#endif
2549 2556
2550 //call wlan_process_helper with the message inside, later with wlan: analyze signal 2557 //call wlan_process_helper with the message inside, later with wlan: analyze signal
2551 if (ntohs (hdr->size) < sizeof (struct ieee80211_frame) 2558 if (ntohs (hdr->size) <
2552 + sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_rx)) 2559 sizeof (struct ieee80211_frame) + sizeof (struct GNUNET_MessageHeader) +
2560 sizeof (struct Radiotap_rx))
2553 { 2561 {
2554#if DEBUG_wlan 2562#if DEBUG_wlan
2555 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2563 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2556 "Size of packet is too small; size: %u min size: %u\n", 2564 "Size of packet is too small; size: %u min size: %u\n",
2557 ntohs (hdr->size), 2565 ntohs (hdr->size),
2558 sizeof (struct ieee80211_frame) 2566 sizeof (struct ieee80211_frame) +
2559 + sizeof (struct GNUNET_MessageHeader)); 2567 sizeof (struct GNUNET_MessageHeader));
2560#endif 2568#endif
2561 //GNUNET_break (0); 2569 //GNUNET_break (0);
2562 /* FIXME: restart SUID process */ 2570 /* FIXME: restart SUID process */
@@ -2568,12 +2576,14 @@ wlan_process_helper (void *cls, void *client,
2568 //process only if it is an broadcast or for this computer both with the gnunet bssid 2576 //process only if it is an broadcast or for this computer both with the gnunet bssid
2569 2577
2570 //check for bssid 2578 //check for bssid
2571 if (memcmp (&(wlanIeeeHeader->i_addr3), &mac_bssid, 2579 if (memcmp
2572 sizeof (struct MacAddress)) == 0) 2580 (&(wlanIeeeHeader->i_addr3), &mac_bssid,
2581 sizeof (struct MacAddress)) == 0)
2573 { 2582 {
2574 //check for broadcast or mac 2583 //check for broadcast or mac
2575 if (memcmp (&(wlanIeeeHeader->i_addr1), &bc_all_mac, 2584 if (memcmp
2576 sizeof (struct MacAddress) == 0) || 2585 (&(wlanIeeeHeader->i_addr1), &bc_all_mac,
2586 sizeof (struct MacAddress) == 0) ||
2577 memcmp (&(wlanIeeeHeader->i_addr1), &(plugin->mac_address), 2587 memcmp (&(wlanIeeeHeader->i_addr1), &(plugin->mac_address),
2578 sizeof (struct MacAddress)) == 0) 2588 sizeof (struct MacAddress)) == 0)
2579 { 2589 {
@@ -2581,9 +2591,9 @@ wlan_process_helper (void *cls, void *client,
2581 // process the inner data 2591 // process the inner data
2582 2592
2583 2593
2584 datasize = ntohs (hdr->size) - sizeof (struct ieee80211_frame) 2594 datasize =
2585 - sizeof (struct GNUNET_MessageHeader) 2595 ntohs (hdr->size) - sizeof (struct ieee80211_frame) -
2586 - sizeof (struct Radiotap_rx); 2596 sizeof (struct GNUNET_MessageHeader) - sizeof (struct Radiotap_rx);
2587 2597
2588 session_light = GNUNET_malloc (sizeof (struct Session_light)); 2598 session_light = GNUNET_malloc (sizeof (struct Session_light));
2589 memcpy (&session_light->addr, &(wlanIeeeHeader->i_addr2), 2599 memcpy (&session_light->addr, &(wlanIeeeHeader->i_addr2),
@@ -2670,8 +2680,9 @@ wlan_plugin_helper_read (void *cls,
2670 char mybuf[WLAN_MTU + sizeof (struct GNUNET_MessageHeader)]; 2680 char mybuf[WLAN_MTU + sizeof (struct GNUNET_MessageHeader)];
2671 ssize_t bytes; 2681 ssize_t bytes;
2672 2682
2673 bytes = GNUNET_DISK_file_read (plugin->server_stdout_handle, mybuf, 2683 bytes =
2674 sizeof (mybuf)); 2684 GNUNET_DISK_file_read (plugin->server_stdout_handle, mybuf,
2685 sizeof (mybuf));
2675 if (bytes <= 0) 2686 if (bytes <= 0)
2676 { 2687 {
2677#if DEBUG_wlan 2688#if DEBUG_wlan
@@ -2724,10 +2735,10 @@ wlan_transport_start_wlan_helper (struct Plugin *plugin, int testmode)
2724 filenamehw, plugin->interface, testmode); 2735 filenamehw, plugin->interface, testmode);
2725#endif 2736#endif
2726 2737
2727 plugin->server_proc = GNUNET_OS_start_process (plugin->server_stdin, 2738 plugin->server_proc =
2728 plugin->server_stdout, 2739 GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout,
2729 filenamehw, filenamehw, 2740 filenamehw, filenamehw, plugin->interface,
2730 plugin->interface, NULL); 2741 NULL);
2731 } 2742 }
2732 else if (testmode == 1) 2743 else if (testmode == 1)
2733 { 2744 {
@@ -2738,10 +2749,9 @@ wlan_transport_start_wlan_helper (struct Plugin *plugin, int testmode)
2738 filenameloopback, plugin->interface, testmode); 2749 filenameloopback, plugin->interface, testmode);
2739#endif 2750#endif
2740 2751
2741 plugin->server_proc = GNUNET_OS_start_process (plugin->server_stdin, 2752 plugin->server_proc =
2742 plugin->server_stdout, 2753 GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout,
2743 filenameloopback, 2754 filenameloopback, filenameloopback, "1", NULL);
2744 filenameloopback, "1", NULL);
2745 } 2755 }
2746 else if (testmode == 2) 2756 else if (testmode == 2)
2747 { 2757 {
@@ -2750,10 +2760,9 @@ wlan_transport_start_wlan_helper (struct Plugin *plugin, int testmode)
2750 "Starting gnunet-wlan-helper loopback 2 process cmd: %s %s %i\n", 2760 "Starting gnunet-wlan-helper loopback 2 process cmd: %s %s %i\n",
2751 filenameloopback, plugin->interface, testmode); 2761 filenameloopback, plugin->interface, testmode);
2752#endif 2762#endif
2753 plugin->server_proc = GNUNET_OS_start_process (plugin->server_stdin, 2763 plugin->server_proc =
2754 plugin->server_stdout, 2764 GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout,
2755 filenameloopback, 2765 filenameloopback, filenameloopback, "2", NULL);
2756 filenameloopback, "2", NULL);
2757 } 2766 }
2758 if (plugin->server_proc == NULL) 2767 if (plugin->server_proc == NULL)
2759 { 2768 {
@@ -2771,10 +2780,12 @@ wlan_transport_start_wlan_helper (struct Plugin *plugin, int testmode)
2771 /* Close the read end of the write pipe */ 2780 /* Close the read end of the write pipe */
2772 GNUNET_DISK_pipe_close_end (plugin->server_stdin, GNUNET_DISK_PIPE_END_READ); 2781 GNUNET_DISK_pipe_close_end (plugin->server_stdin, GNUNET_DISK_PIPE_END_READ);
2773 2782
2774 plugin->server_stdout_handle = GNUNET_DISK_pipe_handle (plugin->server_stdout, 2783 plugin->server_stdout_handle =
2775 GNUNET_DISK_PIPE_END_READ); 2784 GNUNET_DISK_pipe_handle (plugin->server_stdout,
2776 plugin->server_stdin_handle = GNUNET_DISK_pipe_handle (plugin->server_stdin, 2785 GNUNET_DISK_PIPE_END_READ);
2777 GNUNET_DISK_PIPE_END_WRITE); 2786 plugin->server_stdin_handle =
2787 GNUNET_DISK_pipe_handle (plugin->server_stdin,
2788 GNUNET_DISK_PIPE_END_WRITE);
2778 2789
2779 GNUNET_assert (plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK); 2790 GNUNET_assert (plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK);
2780 2791
@@ -2880,8 +2891,8 @@ libgnunet_plugin_transport_wlan_init (void *cls)
2880 GNUNET_BANDWIDTH_value_init (100 * 1024 * 2891 GNUNET_BANDWIDTH_value_init (100 * 1024 *
2881 1024 / 8), 100); 2892 1024 / 8), 100);
2882 2893
2883 plugin->suid_tokenizer = GNUNET_SERVER_mst_create (&wlan_process_helper, 2894 plugin->suid_tokenizer =
2884 plugin); 2895 GNUNET_SERVER_mst_create (&wlan_process_helper, plugin);
2885 2896
2886 plugin->data_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin); 2897 plugin->data_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
2887 2898
@@ -2899,19 +2910,17 @@ libgnunet_plugin_transport_wlan_init (void *cls)
2899 2910
2900 if (GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "TESTMODE")) 2911 if (GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "TESTMODE"))
2901 { 2912 {
2902 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (env->cfg, 2913 if (GNUNET_SYSERR ==
2903 "transport-wlan", 2914 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-wlan",
2904 "TESTMODE", 2915 "TESTMODE", &testmode))
2905 &testmode))
2906 testmode = 0; //default value 2916 testmode = 0; //default value
2907 } 2917 }
2908 2918
2909 if (GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "INTERFACE")) 2919 if (GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "INTERFACE"))
2910 { 2920 {
2911 if (GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-wlan", 2921 if (GNUNET_CONFIGURATION_get_value_string
2912 "INTERFACE", 2922 (env->cfg, "transport-wlan", "INTERFACE",
2913 &(plugin->interface)) != 2923 &(plugin->interface)) != GNUNET_YES)
2914 GNUNET_YES)
2915 { 2924 {
2916 libgnunet_plugin_transport_wlan_done (api); 2925 libgnunet_plugin_transport_wlan_done (api);
2917 return NULL; 2926 return NULL;
diff --git a/src/transport/test_plugin_transport.c b/src/transport/test_plugin_transport.c
index e66e04ead..6bb187b19 100644
--- a/src/transport/test_plugin_transport.c
+++ b/src/transport/test_plugin_transport.c
@@ -87,20 +87,16 @@ static int ok;
87/** 87/**
88 */ 88 */
89static void 89static void
90receive (void *cls, 90receive (void *cls, const struct GNUNET_PeerIdentity *peer,
91 const struct GNUNET_PeerIdentity 91 const struct GNUNET_MessageHeader *message, uint32_t distance,
92 *peer, const struct GNUNET_MessageHeader *message,
93 uint32_t distance,
94 const char *sender_address, size_t sender_address_len) 92 const char *sender_address, size_t sender_address_len)
95{ 93{
96 /* do nothing */ 94 /* do nothing */
97} 95}
98 96
99void 97void
100notify_address (void *cls, 98notify_address (void *cls, const char *name, const void *addr, size_t addrlen,
101 const char *name, 99 struct GNUNET_TIME_Relative expires)
102 const void *addr,
103 size_t addrlen, struct GNUNET_TIME_Relative expires)
104{ 100{
105} 101}
106 102
@@ -161,8 +157,7 @@ test_validation ()
161 GNUNET_assert (GNUNET_OK == 157 GNUNET_assert (GNUNET_OK ==
162 api->check_address (api->cls, &soaddr, sizeof (soaddr))); 158 api->check_address (api->cls, &soaddr, sizeof (soaddr)));
163 ok = 0; 159 ok = 0;
164 GNUNET_SCHEDULER_add_continuation (&unload_task, 160 GNUNET_SCHEDULER_add_continuation (&unload_task, (void *) cfg,
165 (void *) cfg,
166 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 161 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
167} 162}
168 163
@@ -186,9 +181,8 @@ setup_plugin_environment ()
186 * @param c configuration to use 181 * @param c configuration to use
187 */ 182 */
188static void 183static void
189run (void *cls, 184run (void *cls, char *const *args, const char *cfgfile,
190 char *const *args, 185 const struct GNUNET_CONFIGURATION_Handle *c)
191 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
192{ 186{
193 unsigned long long tneigh; 187 unsigned long long tneigh;
194 char *keyfile; 188 char *keyfile;
@@ -197,14 +191,11 @@ run (void *cls,
197 cfg = c; 191 cfg = c;
198 /* parse configuration */ 192 /* parse configuration */
199 if ((GNUNET_OK != 193 if ((GNUNET_OK !=
200 GNUNET_CONFIGURATION_get_value_number (c, 194 GNUNET_CONFIGURATION_get_value_number (c, "TRANSPORT", "NEIGHBOUR_LIMIT",
201 "TRANSPORT",
202 "NEIGHBOUR_LIMIT",
203 &tneigh)) || 195 &tneigh)) ||
204 (GNUNET_OK != 196 (GNUNET_OK !=
205 GNUNET_CONFIGURATION_get_value_filename (c, 197 GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY",
206 "GNUNETD", 198 &keyfile)))
207 "HOSTKEY", &keyfile)))
208 { 199 {
209 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 200 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
210 _ 201 _
@@ -223,8 +214,8 @@ run (void *cls,
223 return; 214 return;
224 } 215 }
225 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); 216 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
226 GNUNET_CRYPTO_hash (&my_public_key, 217 GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key),
227 sizeof (my_public_key), &my_identity.hashPubKey); 218 &my_identity.hashPubKey);
228 219
229 220
230 221
@@ -281,11 +272,10 @@ main (int argc, char *const *argv)
281#endif 272#endif
282 NULL); 273 NULL);
283 ok = 1; /* set to fail */ 274 ok = 1; /* set to fail */
284 ret = (GNUNET_OK == 275 ret =
285 GNUNET_PROGRAM_run (5, 276 (GNUNET_OK ==
286 argv_prog, 277 GNUNET_PROGRAM_run (5, argv_prog, "test-plugin-transport", "testcase",
287 "test-plugin-transport", 278 options, &run, NULL)) ? ok : 1;
288 "testcase", options, &run, NULL)) ? ok : 1;
289 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport"); 279 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport");
290 return ret; 280 return ret;
291} 281}
diff --git a/src/transport/test_plugin_transport_http.c b/src/transport/test_plugin_transport_http.c
index 921f9ec32..f59edfb26 100644
--- a/src/transport/test_plugin_transport_http.c
+++ b/src/transport/test_plugin_transport_http.c
@@ -399,8 +399,8 @@ shutdown_clean ()
399 399
400 /* Evaluate results */ 400 /* Evaluate results */
401 fail = 0; 401 fail = 0;
402 if ((fail_notify_address == GNUNET_YES) || 402 if ((fail_notify_address == GNUNET_YES) || (fail_pretty_printer == GNUNET_YES)
403 (fail_pretty_printer == GNUNET_YES) || (fail_addr_to_str == GNUNET_YES)) 403 || (fail_addr_to_str == GNUNET_YES))
404 { 404 {
405 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 405 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
406 "Phase 0: Test plugin functions failed\n"); 406 "Phase 0: Test plugin functions failed\n");
@@ -530,15 +530,14 @@ static void run_connection_tests (int phase, void *cls);
530static struct GNUNET_TIME_Relative 530static struct GNUNET_TIME_Relative
531receive (void *cls, const struct GNUNET_PeerIdentity *peer, 531receive (void *cls, const struct GNUNET_PeerIdentity *peer,
532 const struct GNUNET_MessageHeader *message, 532 const struct GNUNET_MessageHeader *message,
533 const struct GNUNET_TRANSPORT_ATS_Information *ats, 533 const struct GNUNET_TRANSPORT_ATS_Information *ats, uint32_t ats_count,
534 uint32_t ats_count, 534 struct Session *session, const char *sender_address,
535 struct Session *session, 535 uint16_t sender_address_len)
536 const char *sender_address, uint16_t sender_address_len)
537{ 536{
538 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 537 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
539 "Testcase recieved new message from peer `%s' with type %u and length %u, session %X\n", 538 "Testcase recieved new message from peer `%s' with type %u and length %u, session %X\n",
540 GNUNET_i2s (peer), 539 GNUNET_i2s (peer), ntohs (message->type), ntohs (message->size),
541 ntohs (message->type), ntohs (message->size), session); 540 session);
542 541
543 if ((ntohs (message->type) >= 10) && (ntohs (message->type) < 20)) 542 if ((ntohs (message->type) >= 10) && (ntohs (message->type) < 20))
544 { 543 {
@@ -689,9 +688,8 @@ send_execute (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
689 688
690 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 689 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
691 _("curl failed for `%s' at %s:%d: `%s'\n"), 690 _("curl failed for `%s' at %s:%d: `%s'\n"),
692 "curl_multi_perform", 691 "curl_multi_perform", __FILE__, __LINE__,
693 __FILE__, 692 curl_easy_strerror (msg->data.result));
694 __LINE__, curl_easy_strerror (msg->data.result));
695 /* sending msg failed */ 693 /* sending msg failed */
696 curl_easy_cleanup (curl_handle); 694 curl_easy_cleanup (curl_handle);
697 curl_handle = NULL; 695 curl_handle = NULL;
@@ -792,8 +790,7 @@ send_prepare (struct HTTP_Transfer *result)
792 mret = curl_multi_fdset (multi_handle, &rs, &ws, &es, &max); 790 mret = curl_multi_fdset (multi_handle, &rs, &ws, &es, &max);
793 if (mret != CURLM_OK) 791 if (mret != CURLM_OK)
794 { 792 {
795 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 793 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
796 _("%s failed at %s:%d: `%s'\n"),
797 "curl_multi_fdset", __FILE__, __LINE__, 794 "curl_multi_fdset", __FILE__, __LINE__,
798 curl_multi_strerror (mret)); 795 curl_multi_strerror (mret));
799 return -1; 796 return -1;
@@ -801,8 +798,7 @@ send_prepare (struct HTTP_Transfer *result)
801 mret = curl_multi_timeout (multi_handle, &to); 798 mret = curl_multi_timeout (multi_handle, &to);
802 if (mret != CURLM_OK) 799 if (mret != CURLM_OK)
803 { 800 {
804 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 801 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
805 _("%s failed at %s:%d: `%s'\n"),
806 "curl_multi_timeout", __FILE__, __LINE__, 802 "curl_multi_timeout", __FILE__, __LINE__,
807 curl_multi_strerror (mret)); 803 curl_multi_strerror (mret));
808 return -1; 804 return -1;
@@ -918,13 +914,12 @@ notify_address (void *cls, int add_remove, const void *addr, size_t addrlen)
918} 914}
919 915
920static void 916static void
921plugin_env_session_end (void *cls, 917plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
922 const struct GNUNET_PeerIdentity *peer,
923 struct Session *session) 918 struct Session *session)
924{ 919{
925 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 920 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
926 "Pluging tells me: session %X to peer `%s' ended\n", 921 "Pluging tells me: session %X to peer `%s' ended\n", session,
927 session, GNUNET_i2s (peer)); 922 GNUNET_i2s (peer));
928} 923}
929 924
930 925
@@ -967,8 +962,8 @@ pretty_printer_cb (void *cls, const char *address)
967{ 962{
968 if (NULL == address) 963 if (NULL == address)
969 return; 964 return;
970 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 965 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Plugin returned pretty address: `%s'\n",
971 "Plugin returned pretty address: `%s'\n", address); 966 address);
972 fail_pretty_printer_count++; 967 fail_pretty_printer_count++;
973} 968}
974 969
@@ -999,8 +994,8 @@ run_connection_tests (int phase, void *cls)
999 /* Connecting to peer without identification */ 994 /* Connecting to peer without identification */
1000 const char *ident = ""; 995 const char *ident = "";
1001 996
1002 GNUNET_asprintf (&host_str, 997 GNUNET_asprintf (&host_str, "%s://%s/%s", PROTOCOL_PREFIX, test_addr,
1003 "%s://%s/%s", PROTOCOL_PREFIX, test_addr, ident); 998 ident);
1004 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 999 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1005 _("Connecting to peer without any peer identification.\n")); 1000 _("Connecting to peer without any peer identification.\n"));
1006 test_no_ident.test_executed = GNUNET_YES; 1001 test_no_ident.test_executed = GNUNET_YES;
@@ -1013,8 +1008,8 @@ run_connection_tests (int phase, void *cls)
1013 const char *ident = "AAAAAAAAAA"; 1008 const char *ident = "AAAAAAAAAA";
1014 1009
1015 /* Connecting to peer with too short identification */ 1010 /* Connecting to peer with too short identification */
1016 GNUNET_asprintf (&host_str, 1011 GNUNET_asprintf (&host_str, "%s://%s/%s", PROTOCOL_PREFIX, test_addr,
1017 "%s://%s/%s", PROTOCOL_PREFIX, test_addr, ident); 1012 ident);
1018 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1013 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1019 _ 1014 _
1020 ("Connecting to peer with too short peer identification.\n")); 1015 ("Connecting to peer with too short peer identification.\n"));
@@ -1044,9 +1039,8 @@ run_connection_tests (int phase, void *cls)
1044 struct GNUNET_CRYPTO_HashAsciiEncoded ident; 1039 struct GNUNET_CRYPTO_HashAsciiEncoded ident;
1045 1040
1046 GNUNET_CRYPTO_hash_to_enc (&my_identity.hashPubKey, &ident); 1041 GNUNET_CRYPTO_hash_to_enc (&my_identity.hashPubKey, &ident);
1047 GNUNET_asprintf (&host_str, 1042 GNUNET_asprintf (&host_str, "%s://%s/%s%s", PROTOCOL_PREFIX, test_addr,
1048 "%s://%s/%s%s", 1043 (char *) &ident, ";0");
1049 PROTOCOL_PREFIX, test_addr, (char *) &ident, ";0");
1050 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1044 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1051 _("Connecting to peer with valid peer identification.\n")); 1045 _("Connecting to peer with valid peer identification.\n"));
1052 test_valid_ident.test_executed = GNUNET_YES; 1046 test_valid_ident.test_executed = GNUNET_YES;
@@ -1083,8 +1077,8 @@ run_connection_tests (int phase, void *cls)
1083 INET_ADDRSTRLEN); 1077 INET_ADDRSTRLEN);
1084 port = ntohs (((struct IPv4HttpAddress *) tmp_addr->addr)->u_port); 1078 port = ntohs (((struct IPv4HttpAddress *) tmp_addr->addr)->u_port);
1085 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1079 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1086 "Sending message to addres no. %u: `%s':%u\n", 1080 "Sending message to addres no. %u: `%s':%u\n", count,
1087 count, address, port); 1081 address, port);
1088 } 1082 }
1089 if (tmp_addr->addrlen == (sizeof (struct IPv6HttpAddress))) 1083 if (tmp_addr->addrlen == (sizeof (struct IPv6HttpAddress)))
1090 { 1084 {
@@ -1092,19 +1086,15 @@ run_connection_tests (int phase, void *cls)
1092 INET6_ADDRSTRLEN); 1086 INET6_ADDRSTRLEN);
1093 port = ntohs (((struct IPv6HttpAddress *) tmp_addr->addr)->u6_port); 1087 port = ntohs (((struct IPv6HttpAddress *) tmp_addr->addr)->u6_port);
1094 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1088 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1095 "Sending message to addres no. %u: `%s':%u\n", 1089 "Sending message to addres no. %u: `%s':%u\n", count,
1096 count, address, port); 1090 address, port);
1097 } 1091 }
1098 msg.type = htons (type); 1092 msg.type = htons (type);
1099 memcpy (tmp, &msg, sizeof (struct GNUNET_MessageHeader)); 1093 memcpy (tmp, &msg, sizeof (struct GNUNET_MessageHeader));
1100 api->send (api->cls, 1094 api->send (api->cls, &my_identity, tmp,
1101 &my_identity, 1095 sizeof (struct GNUNET_MessageHeader), 0, TIMEOUT, NULL,
1102 tmp, sizeof (struct GNUNET_MessageHeader), 1096 tmp_addr->addr, tmp_addr->addrlen, GNUNET_YES, &task_send_cont,
1103 0, TIMEOUT, 1097 &fail_msgs_transmited_to_local_addrs);
1104 NULL,
1105 tmp_addr->addr, tmp_addr->addrlen,
1106 GNUNET_YES,
1107 &task_send_cont, &fail_msgs_transmited_to_local_addrs);
1108 tmp_addr = tmp_addr->next; 1098 tmp_addr = tmp_addr->next;
1109 count++; 1099 count++;
1110 type++; 1100 type++;
@@ -1123,26 +1113,19 @@ run_connection_tests (int phase, void *cls)
1123 size = sizeof (struct GNUNET_MessageHeader); 1113 size = sizeof (struct GNUNET_MessageHeader);
1124 msg->size = htons (size); 1114 msg->size = htons (size);
1125 msg->type = htons (20); 1115 msg->type = htons (20);
1126 api->send (api->cls, 1116 api->send (api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT,
1127 &my_identity, 1117 NULL, NULL, 0, GNUNET_NO, &task_send_cont, NULL);
1128 (const char *) msg, size,
1129 0, TIMEOUT, NULL, NULL, 0, GNUNET_NO, &task_send_cont, NULL);
1130 1118
1131 msg->type = htons (21); 1119 msg->type = htons (21);
1132 api->send (api->cls, 1120 api->send (api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT,
1133 &my_identity, 1121 NULL, NULL, 0, GNUNET_SYSERR, &task_send_cont, NULL);
1134 (const char *) msg, size,
1135 0, TIMEOUT, NULL, NULL, 0, GNUNET_SYSERR, &task_send_cont, NULL);
1136 1122
1137 /* answer on session */ 1123 /* answer on session */
1138 size = sizeof (struct GNUNET_MessageHeader); 1124 size = sizeof (struct GNUNET_MessageHeader);
1139 msg->size = htons (size); 1125 msg->size = htons (size);
1140 msg->type = htons (22); 1126 msg->type = htons (22);
1141 api->send (api->cls, 1127 api->send (api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT,
1142 &my_identity, 1128 session, NULL, 0, GNUNET_SYSERR, &task_send_cont, NULL);
1143 (const char *) msg, size,
1144 0, TIMEOUT, session, NULL, 0, GNUNET_SYSERR,
1145 &task_send_cont, NULL);
1146 GNUNET_free (msg); 1129 GNUNET_free (msg);
1147 1130
1148 /* answer on session with big message not fitting in mhd send buffer */ 1131 /* answer on session with big message not fitting in mhd send buffer */
@@ -1150,10 +1133,8 @@ run_connection_tests (int phase, void *cls)
1150 msg = GNUNET_malloc (size); 1133 msg = GNUNET_malloc (size);
1151 msg->size = htons (size); 1134 msg->size = htons (size);
1152 msg->type = htons (23); 1135 msg->type = htons (23);
1153 api->send (api->cls, 1136 api->send (api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT,
1154 &my_identity, 1137 session, NULL, 0, GNUNET_NO, &task_send_cont, NULL);
1155 (const char *) msg, size,
1156 0, TIMEOUT, session, NULL, 0, GNUNET_NO, &task_send_cont, NULL);
1157 GNUNET_free (msg); 1138 GNUNET_free (msg);
1158 return; 1139 return;
1159 } 1140 }
@@ -1178,12 +1159,10 @@ run_connection_tests (int phase, void *cls)
1178 1159
1179 msg2->size = htons (2 * sizeof (struct GNUNET_MessageHeader)); 1160 msg2->size = htons (2 * sizeof (struct GNUNET_MessageHeader));
1180 msg2->type = htons (31); 1161 msg2->type = htons (31);
1181 api->send (api->cls, 1162 api->send (api->cls, &my_identity, (const char *) msg,
1182 &my_identity, 1163 4 * sizeof (struct GNUNET_MessageHeader), 0, TIMEOUT, NULL,
1183 (const char *) msg, 4 * sizeof (struct GNUNET_MessageHeader), 1164 addr_head->addr, addr_head->addrlen, GNUNET_NO, &task_send_cont,
1184 0, TIMEOUT, NULL, 1165 &fail_multiple_msgs_in_transmission);
1185 addr_head->addr, addr_head->addrlen,
1186 GNUNET_NO, &task_send_cont, &fail_multiple_msgs_in_transmission);
1187 GNUNET_free (msg); 1166 GNUNET_free (msg);
1188 /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1 */ 1167 /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1 */
1189 1168
@@ -1191,12 +1170,9 @@ run_connection_tests (int phase, void *cls)
1191 msg = GNUNET_malloc (size); 1170 msg = GNUNET_malloc (size);
1192 msg->size = htons (size); 1171 msg->size = htons (size);
1193 msg->type = htons (32); 1172 msg->type = htons (32);
1194 api->send (api->cls, 1173 api->send (api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT,
1195 &my_identity, 1174 NULL, addr_head->addr, addr_head->addrlen, GNUNET_NO,
1196 (const char *) msg, size, 1175 &task_send_cont, &fail_msg_transmited_max_size);
1197 0, TIMEOUT, NULL,
1198 addr_head->addr, addr_head->addrlen,
1199 GNUNET_NO, &task_send_cont, &fail_msg_transmited_max_size);
1200 GNUNET_free (msg); 1176 GNUNET_free (msg);
1201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more tests to run\n"); 1177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more tests to run\n");
1202 } 1178 }
@@ -1210,9 +1186,8 @@ run_connection_tests (int phase, void *cls)
1210 * @param c configuration to use 1186 * @param c configuration to use
1211 */ 1187 */
1212static void 1188static void
1213run (void *cls, 1189run (void *cls, char *const *args, const char *cfgfile,
1214 char *const *args, 1190 const struct GNUNET_CONFIGURATION_Handle *c)
1215 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
1216{ 1191{
1217 char *libname; 1192 char *libname;
1218 1193
@@ -1244,14 +1219,11 @@ run (void *cls,
1244 &servicehome); 1219 &servicehome);
1245 1220
1246 if ((GNUNET_OK != 1221 if ((GNUNET_OK !=
1247 GNUNET_CONFIGURATION_get_value_number (c, 1222 GNUNET_CONFIGURATION_get_value_number (c, "TRANSPORT", "NEIGHBOUR_LIMIT",
1248 "TRANSPORT",
1249 "NEIGHBOUR_LIMIT",
1250 &tneigh)) || 1223 &tneigh)) ||
1251 (GNUNET_OK != 1224 (GNUNET_OK !=
1252 GNUNET_CONFIGURATION_get_value_filename (c, 1225 GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY",
1253 "GNUNETD", 1226 &keyfile)))
1254 "HOSTKEY", &keyfile)))
1255 { 1227 {
1256 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1228 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1257 _ 1229 _
@@ -1262,14 +1234,11 @@ run (void *cls,
1262 } 1234 }
1263 1235
1264 if ((GNUNET_OK != 1236 if ((GNUNET_OK !=
1265 GNUNET_CONFIGURATION_get_value_number (cfg, 1237 GNUNET_CONFIGURATION_get_value_number (cfg, "transport-http", "PORT",
1266 "transport-http", 1238 &port)) || (port > 65535) ||
1267 "PORT", 1239 (port == 0))
1268 &port)) ||
1269 (port > 65535) || (port == 0))
1270 { 1240 {
1271 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 1241 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "http",
1272 "http",
1273 _ 1242 _
1274 ("Require valid port number for transport plugin `%s' in configuration!\n"), 1243 ("Require valid port number for transport plugin `%s' in configuration!\n"),
1275 "transport-http"); 1244 "transport-http");
@@ -1297,8 +1266,8 @@ run (void *cls,
1297 /* load plugins... */ 1266 /* load plugins... */
1298 setup_plugin_environment (); 1267 setup_plugin_environment ();
1299 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_http"); 1268 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_http");
1300 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1269 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading HTTP transport plugin `%s'\n"),
1301 _("Loading HTTP transport plugin `%s'\n"), libname); 1270 libname);
1302 api = GNUNET_PLUGIN_load (libname, &env); 1271 api = GNUNET_PLUGIN_load (libname, &env);
1303 GNUNET_free (libname); 1272 GNUNET_free (libname);
1304 if (api == NULL) 1273 if (api == NULL)
@@ -1322,9 +1291,9 @@ run (void *cls,
1322 cur = addr_head; 1291 cur = addr_head;
1323 while (cur != NULL) 1292 while (cur != NULL)
1324 { 1293 {
1325 api->address_pretty_printer (api->cls, "http", 1294 api->address_pretty_printer (api->cls, "http", cur->addr, cur->addrlen,
1326 cur->addr, cur->addrlen, GNUNET_NO, 1295 GNUNET_NO, TEST_TIMEOUT, &pretty_printer_cb,
1327 TEST_TIMEOUT, &pretty_printer_cb, NULL); 1296 NULL);
1328 addr_str = api->address_to_string (api->cls, cur->addr, cur->addrlen); 1297 addr_str = api->address_to_string (api->cls, cur->addr, cur->addrlen);
1329 suggest_res = api->check_address (api->cls, cur->addr, cur->addrlen); 1298 suggest_res = api->check_address (api->cls, cur->addr, cur->addrlen);
1330 1299
@@ -1444,12 +1413,11 @@ main (int argc, char *const *argv)
1444 GNUNET_DISK_directory_remove (servicehome); 1413 GNUNET_DISK_directory_remove (servicehome);
1445 GNUNET_CONFIGURATION_destroy (cfg); 1414 GNUNET_CONFIGURATION_destroy (cfg);
1446 1415
1447 ret = (GNUNET_OK == 1416 ret =
1448 GNUNET_PROGRAM_run (5, 1417 (GNUNET_OK ==
1449 argv_prog, 1418 GNUNET_PROGRAM_run (5, argv_prog, "test_gnunet_transport_plugin_http",
1450 "test_gnunet_transport_plugin_http", 1419 "testcase", options, &run,
1451 "testcase", options, &run, 1420 NULL)) ? GNUNET_NO : GNUNET_YES;
1452 NULL)) ? GNUNET_NO : GNUNET_YES;
1453 1421
1454 if (servicehome != NULL) 1422 if (servicehome != NULL)
1455 { 1423 {
diff --git a/src/transport/test_plugin_transport_https.c b/src/transport/test_plugin_transport_https.c
index e6e71c7f5..5b78f89b4 100644
--- a/src/transport/test_plugin_transport_https.c
+++ b/src/transport/test_plugin_transport_https.c
@@ -559,10 +559,9 @@ static void run_connection_tests (int phase, void *cls);
559static struct GNUNET_TIME_Relative 559static struct GNUNET_TIME_Relative
560receive (void *cls, const struct GNUNET_PeerIdentity *peer, 560receive (void *cls, const struct GNUNET_PeerIdentity *peer,
561 const struct GNUNET_MessageHeader *message, 561 const struct GNUNET_MessageHeader *message,
562 const struct GNUNET_TRANSPORT_ATS_Information *ats, 562 const struct GNUNET_TRANSPORT_ATS_Information *ats, uint32_t ats_count,
563 uint32_t ats_count, 563 struct Session *session, const char *sender_address,
564 struct Session *session, 564 uint16_t sender_address_len)
565 const char *sender_address, uint16_t sender_address_len)
566{ 565{
567 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 566 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
568 "Testcase recieved new message from peer `%s' with type %u and length %u, session %X\n", 567 "Testcase recieved new message from peer `%s' with type %u and length %u, session %X\n",
@@ -723,9 +722,8 @@ send_execute (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
723 722
724 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 723 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
725 _("curl failed for `%s' at %s:%d: `%s'\n"), 724 _("curl failed for `%s' at %s:%d: `%s'\n"),
726 "curl_multi_perform", 725 "curl_multi_perform", __FILE__, __LINE__,
727 __FILE__, 726 curl_easy_strerror (msg->data.result));
728 __LINE__, curl_easy_strerror (msg->data.result));
729 /* sending msg failed */ 727 /* sending msg failed */
730 curl_easy_cleanup (curl_handle); 728 curl_easy_cleanup (curl_handle);
731 curl_handle = NULL; 729 curl_handle = NULL;
@@ -826,8 +824,7 @@ send_prepare (struct HTTP_Transfer *result)
826 mret = curl_multi_fdset (multi_handle, &rs, &ws, &es, &max); 824 mret = curl_multi_fdset (multi_handle, &rs, &ws, &es, &max);
827 if (mret != CURLM_OK) 825 if (mret != CURLM_OK)
828 { 826 {
829 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 827 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
830 _("%s failed at %s:%d: `%s'\n"),
831 "curl_multi_fdset", __FILE__, __LINE__, 828 "curl_multi_fdset", __FILE__, __LINE__,
832 curl_multi_strerror (mret)); 829 curl_multi_strerror (mret));
833 return -1; 830 return -1;
@@ -835,8 +832,7 @@ send_prepare (struct HTTP_Transfer *result)
835 mret = curl_multi_timeout (multi_handle, &to); 832 mret = curl_multi_timeout (multi_handle, &to);
836 if (mret != CURLM_OK) 833 if (mret != CURLM_OK)
837 { 834 {
838 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 835 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
839 _("%s failed at %s:%d: `%s'\n"),
840 "curl_multi_timeout", __FILE__, __LINE__, 836 "curl_multi_timeout", __FILE__, __LINE__,
841 curl_multi_strerror (mret)); 837 curl_multi_strerror (mret));
842 return -1; 838 return -1;
@@ -955,8 +951,7 @@ notify_address (void *cls, int add_remove, const void *addr, size_t addrlen)
955} 951}
956 952
957static void 953static void
958plugin_env_session_end (void *cls, 954plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
959 const struct GNUNET_PeerIdentity *peer,
960 struct Session *session) 955 struct Session *session)
961{ 956{
962 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 957 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1230,9 +1225,8 @@ run_connection_tests (int phase, void *cls)
1230 * @param c configuration to use 1225 * @param c configuration to use
1231 */ 1226 */
1232static void 1227static void
1233run (void *cls, 1228run (void *cls, char *const *args, const char *cfgfile,
1234 char *const *args, 1229 const struct GNUNET_CONFIGURATION_Handle *c)
1235 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
1236{ 1230{
1237 char *libname; 1231 char *libname;
1238 1232
@@ -1264,14 +1258,11 @@ run (void *cls,
1264 1258
1265 1259
1266 if ((GNUNET_OK != 1260 if ((GNUNET_OK !=
1267 GNUNET_CONFIGURATION_get_value_number (c, 1261 GNUNET_CONFIGURATION_get_value_number (c, "TRANSPORT", "NEIGHBOUR_LIMIT",
1268 "TRANSPORT",
1269 "NEIGHBOUR_LIMIT",
1270 &tneigh)) || 1262 &tneigh)) ||
1271 (GNUNET_OK != 1263 (GNUNET_OK !=
1272 GNUNET_CONFIGURATION_get_value_filename (c, 1264 GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY",
1273 "GNUNETD", 1265 &keyfile)))
1274 "HOSTKEY", &keyfile)))
1275 { 1266 {
1276 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1267 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1277 _ 1268 _
@@ -1282,14 +1273,11 @@ run (void *cls,
1282 } 1273 }
1283 1274
1284 if ((GNUNET_OK != 1275 if ((GNUNET_OK !=
1285 GNUNET_CONFIGURATION_get_value_number (cfg, 1276 GNUNET_CONFIGURATION_get_value_number (cfg, "transport-https", "PORT",
1286 "transport-https", 1277 &port)) || (port > 65535) ||
1287 "PORT", 1278 (port == 0))
1288 &port)) ||
1289 (port > 65535) || (port == 0))
1290 { 1279 {
1291 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 1280 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "https",
1292 "https",
1293 _ 1281 _
1294 ("Require valid port number for transport plugin `%s' in configuration!\n"), 1282 ("Require valid port number for transport plugin `%s' in configuration!\n"),
1295 "transport-http"); 1283 "transport-http");
@@ -1298,9 +1286,8 @@ run (void *cls,
1298 /* Get private key file from config */ 1286 /* Get private key file from config */
1299 if (GNUNET_CONFIGURATION_have_value (cfg, "transport-https", "KEY_FILE")) 1287 if (GNUNET_CONFIGURATION_have_value (cfg, "transport-https", "KEY_FILE"))
1300 { 1288 {
1301 GNUNET_CONFIGURATION_get_value_string (cfg, 1289 GNUNET_CONFIGURATION_get_value_string (cfg, "transport-https", "KEY_FILE",
1302 "transport-https", 1290 &key_file);
1303 "KEY_FILE", &key_file);
1304 } 1291 }
1305 if (key_file == NULL) 1292 if (key_file == NULL)
1306 GNUNET_asprintf (&key_file, "https.key"); 1293 GNUNET_asprintf (&key_file, "https.key");
@@ -1319,9 +1306,8 @@ run (void *cls,
1319 /* Get private key file from config */ 1306 /* Get private key file from config */
1320 if (GNUNET_CONFIGURATION_have_value (cfg, "transport-https", "CERT_FILE")) 1307 if (GNUNET_CONFIGURATION_have_value (cfg, "transport-https", "CERT_FILE"))
1321 { 1308 {
1322 GNUNET_CONFIGURATION_get_value_string (cfg, 1309 GNUNET_CONFIGURATION_get_value_string (cfg, "transport-https", "CERT_FILE",
1323 "transport-https", 1310 &cert_file);
1324 "CERT_FILE", &cert_file);
1325 } 1311 }
1326 if (cert_file == NULL) 1312 if (cert_file == NULL)
1327 GNUNET_asprintf (&cert_file, "https.cert"); 1313 GNUNET_asprintf (&cert_file, "https.cert");
@@ -1511,12 +1497,11 @@ main (int argc, char *const *argv)
1511 GNUNET_DISK_directory_remove (servicehome); 1497 GNUNET_DISK_directory_remove (servicehome);
1512 GNUNET_CONFIGURATION_destroy (cfg); 1498 GNUNET_CONFIGURATION_destroy (cfg);
1513 1499
1514 ret = (GNUNET_OK == 1500 ret =
1515 GNUNET_PROGRAM_run (5, 1501 (GNUNET_OK ==
1516 argv_prog, 1502 GNUNET_PROGRAM_run (5, argv_prog, "test_gnunet_transport_plugin.https",
1517 "test_gnunet_transport_plugin.https", 1503 "testcase", options, &run,
1518 "testcase", options, &run, 1504 NULL)) ? GNUNET_NO : GNUNET_YES;
1519 NULL)) ? GNUNET_NO : GNUNET_YES;
1520 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("\ndelete\n\n")); 1505 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("\ndelete\n\n"));
1521 if (servicehome != NULL) 1506 if (servicehome != NULL)
1522 { 1507 {
diff --git a/src/transport/test_plugin_transport_udp.c b/src/transport/test_plugin_transport_udp.c
index b23d4eb67..8fbd2ab9c 100644
--- a/src/transport/test_plugin_transport_udp.c
+++ b/src/transport/test_plugin_transport_udp.c
@@ -89,20 +89,16 @@ static int ok;
89 * Initialize Environment for this plugin 89 * Initialize Environment for this plugin
90 */ 90 */
91static void 91static void
92receive (void *cls, 92receive (void *cls, const struct GNUNET_PeerIdentity *peer,
93 const struct GNUNET_PeerIdentity *peer, 93 const struct GNUNET_MessageHeader *message, uint32_t distance,
94 const struct GNUNET_MessageHeader *message,
95 uint32_t distance,
96 const char *sender_address, size_t sender_address_len) 94 const char *sender_address, size_t sender_address_len)
97{ 95{
98 /* do nothing */ 96 /* do nothing */
99} 97}
100 98
101void 99void
102notify_address (void *cls, 100notify_address (void *cls, const char *name, const void *addr, size_t addrlen,
103 const char *name, 101 struct GNUNET_TIME_Relative expires)
104 const void *addr,
105 size_t addrlen, struct GNUNET_TIME_Relative expires)
106{ 102{
107} 103}
108 104
@@ -168,9 +164,8 @@ setup_plugin_environment ()
168 * @param c configuration to use 164 * @param c configuration to use
169 */ 165 */
170static void 166static void
171run (void *cls, 167run (void *cls, char *const *args, const char *cfgfile,
172 char *const *args, 168 const struct GNUNET_CONFIGURATION_Handle *c)
173 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
174{ 169{
175 unsigned long long tneigh; 170 unsigned long long tneigh;
176 char *keyfile; 171 char *keyfile;
@@ -179,14 +174,11 @@ run (void *cls,
179 cfg = c; 174 cfg = c;
180 /* parse configuration */ 175 /* parse configuration */
181 if ((GNUNET_OK != 176 if ((GNUNET_OK !=
182 GNUNET_CONFIGURATION_get_value_number (c, 177 GNUNET_CONFIGURATION_get_value_number (c, "TRANSPORT", "NEIGHBOUR_LIMIT",
183 "TRANSPORT",
184 "NEIGHBOUR_LIMIT",
185 &tneigh)) || 178 &tneigh)) ||
186 (GNUNET_OK != 179 (GNUNET_OK !=
187 GNUNET_CONFIGURATION_get_value_filename (c, 180 GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY",
188 "GNUNETD", 181 &keyfile)))
189 "HOSTKEY", &keyfile)))
190 { 182 {
191 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 183 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
192 _ 184 _
@@ -205,8 +197,8 @@ run (void *cls,
205 return; 197 return;
206 } 198 }
207 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); 199 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
208 GNUNET_CRYPTO_hash (&my_public_key, 200 GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key),
209 sizeof (my_public_key), &my_identity.hashPubKey); 201 &my_identity.hashPubKey);
210 202
211 /* load plugins... */ 203 /* load plugins... */
212 setup_plugin_environment (); 204 setup_plugin_environment ();
@@ -261,11 +253,10 @@ main (int argc, char *const *argv)
261#endif 253#endif
262 NULL); 254 NULL);
263 ok = 1; /* set to fail */ 255 ok = 1; /* set to fail */
264 ret = (GNUNET_OK == 256 ret =
265 GNUNET_PROGRAM_run (5, 257 (GNUNET_OK ==
266 argv_prog, 258 GNUNET_PROGRAM_run (5, argv_prog, "test-plugin-transport", "testcase",
267 "test-plugin-transport", 259 options, &run, NULL)) ? ok : 1;
268 "testcase", options, &run, NULL)) ? ok : 1;
269 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport"); 260 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport");
270 return ret; 261 return ret;
271} 262}
diff --git a/src/transport/test_plugin_transport_wlan_dummy.c b/src/transport/test_plugin_transport_wlan_dummy.c
index eba4f9dbd..03dedbe4d 100644
--- a/src/transport/test_plugin_transport_wlan_dummy.c
+++ b/src/transport/test_plugin_transport_wlan_dummy.c
@@ -72,8 +72,9 @@ stdin_send (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
72 char *to_radiotap; 72 char *to_radiotap;
73 char *to_start; 73 char *to_start;
74 74
75 sendsize = ntohs (hdr->size) - sizeof (struct Radiotap_Send) 75 sendsize =
76 + sizeof (struct Radiotap_rx); 76 ntohs (hdr->size) - sizeof (struct Radiotap_Send) +
77 sizeof (struct Radiotap_rx);
77 78
78 if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs (hdr->type)) 79 if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs (hdr->type))
79 { 80 {
@@ -335,9 +336,9 @@ testmode (int argc, char *argv[])
335 336
336 if (FD_ISSET (STDOUT_FILENO, &wfds)) 337 if (FD_ISSET (STDOUT_FILENO, &wfds))
337 { 338 {
338 ret = write (STDOUT_FILENO, 339 ret =
339 write_std.buf + write_std.pos, 340 write (STDOUT_FILENO, write_std.buf + write_std.pos,
340 write_std.size - write_std.pos); 341 write_std.size - write_std.pos);
341 if (0 > ret) 342 if (0 > ret)
342 { 343 {
343 closeprog = 1; 344 closeprog = 1;
@@ -358,9 +359,9 @@ testmode (int argc, char *argv[])
358 359
359 if (FD_ISSET (fdpout, &wfds)) 360 if (FD_ISSET (fdpout, &wfds))
360 { 361 {
361 ret = write (fdpout, 362 ret =
362 write_pout.buf + write_pout.pos, 363 write (fdpout, write_pout.buf + write_pout.pos,
363 write_pout.size - write_pout.pos); 364 write_pout.size - write_pout.pos);
364 365
365 if (0 > ret) 366 if (0 > ret)
366 { 367 {
@@ -453,9 +454,8 @@ main (int argc, char *argv[])
453 fprintf (stderr, 454 fprintf (stderr,
454 "This program must be started with the operating mode as argument.\n"); 455 "This program must be started with the operating mode as argument.\n");
455 fprintf (stderr, 456 fprintf (stderr,
456 "Usage: options\n" 457 "Usage: options\n" "options:\n" "1 = first loopback file\n"
457 "options:\n" 458 "2 = second loopback file\n" "\n");
458 "1 = first loopback file\n" "2 = second loopback file\n" "\n");
459 return 1; 459 return 1;
460 } 460 }
461 if (strstr (argv[1], "1") || strstr (argv[1], "2")) 461 if (strstr (argv[1], "1") || strstr (argv[1], "2"))
diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c
index e4638e4fc..bc2aca31b 100644
--- a/src/transport/test_quota_compliance.c
+++ b/src/transport/test_quota_compliance.c
@@ -232,8 +232,7 @@ get_size ()
232} 232}
233 233
234static void 234static void
235notify_receive_new (void *cls, 235notify_receive_new (void *cls, const struct GNUNET_PeerIdentity *peer,
236 const struct GNUNET_PeerIdentity *peer,
237 const struct GNUNET_MessageHeader *message, 236 const struct GNUNET_MessageHeader *message,
238 const struct GNUNET_TRANSPORT_ATS_Information *ats, 237 const struct GNUNET_TRANSPORT_ATS_Information *ats,
239 uint32_t ats_count) 238 uint32_t ats_count)
@@ -250,8 +249,7 @@ notify_receive_new (void *cls,
250#if DEBUG_MEASUREMENT 249#if DEBUG_MEASUREMENT
251 if (ntohl (hdr->num) % 5000 == 0) 250 if (ntohl (hdr->num) % 5000 == 0)
252 { 251 {
253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 252 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got message %u of size %u\n",
254 "Got message %u of size %u\n",
255 ntohl (hdr->num), ntohs (message->size)); 253 ntohl (hdr->num), ntohs (message->size));
256 } 254 }
257#endif 255#endif
@@ -309,11 +307,9 @@ notify_ready (void *cls, size_t size, void *buf)
309 break; /* sometimes pack buffer full, sometimes not */ 307 break; /* sometimes pack buffer full, sometimes not */
310 } 308 }
311 while (size - ret >= s); 309 while (size - ret >= s);
312 transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th, 310 transmit_handle =
313 &p1.id, 311 GNUNET_TRANSPORT_notify_transmit_ready (p2.th, &p1.id, s, 0, SEND_TIMEOUT,
314 s, 0, SEND_TIMEOUT, 312 &notify_ready, NULL);
315 &notify_ready,
316 NULL);
317 total_bytes_sent += s; 313 total_bytes_sent += s;
318 return ret; 314 return ret;
319} 315}
@@ -348,9 +344,9 @@ measurement_end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
348 return; 344 return;
349 345
350 measurement_running = GNUNET_NO; 346 measurement_running = GNUNET_NO;
351 struct GNUNET_TIME_Relative duration 347 struct GNUNET_TIME_Relative duration =
352 = GNUNET_TIME_absolute_get_difference (start_time, 348 GNUNET_TIME_absolute_get_difference (start_time,
353 GNUNET_TIME_absolute_get ()); 349 GNUNET_TIME_absolute_get ());
354 350
355 351
356 if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK) 352 if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
@@ -435,10 +431,8 @@ measurement_end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
435 else 431 else
436 { 432 {
437 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 433 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
438 "\nQuota compliance ok: \n" 434 "\nQuota compliance ok: \n" "Quota allowed: %10llu kB/s\n"
439 "Quota allowed: %10llu kB/s\n" 435 "Throughput : %10llu kB/s\n", (quota_allowed / (1024)),
440 "Throughput : %10llu kB/s\n",
441 (quota_allowed / (1024)),
442 (total_bytes_sent / (duration.rel_value / 1000) / 1024)); 436 (total_bytes_sent / (duration.rel_value / 1000) / 1024));
443 if (failed_measurement_counter < 2) 437 if (failed_measurement_counter < 2)
444 failed_measurement_counter++; 438 failed_measurement_counter++;
@@ -509,12 +503,10 @@ measure (unsigned long long quota_p1, unsigned long long quota_p2)
509 current_quota_p2 / 1024); 503 current_quota_p2 / 1024);
510 504
511#endif 505#endif
512 GNUNET_TRANSPORT_set_quota (p1.th, 506 GNUNET_TRANSPORT_set_quota (p1.th, &p2.id,
513 &p2.id,
514 GNUNET_BANDWIDTH_value_init (current_quota_p1), 507 GNUNET_BANDWIDTH_value_init (current_quota_p1),
515 GNUNET_BANDWIDTH_value_init (current_quota_p1)); 508 GNUNET_BANDWIDTH_value_init (current_quota_p1));
516 GNUNET_TRANSPORT_set_quota (p2.th, 509 GNUNET_TRANSPORT_set_quota (p2.th, &p1.id,
517 &p1.id,
518 GNUNET_BANDWIDTH_value_init (current_quota_p2), 510 GNUNET_BANDWIDTH_value_init (current_quota_p2),
519 GNUNET_BANDWIDTH_value_init (current_quota_p2)); 511 GNUNET_BANDWIDTH_value_init (current_quota_p2));
520 GNUNET_SCHEDULER_cancel (die_task); 512 GNUNET_SCHEDULER_cancel (die_task);
@@ -535,12 +527,10 @@ measure (unsigned long long quota_p1, unsigned long long quota_p2)
535 527
536 if (transmit_handle != NULL) 528 if (transmit_handle != NULL)
537 GNUNET_TRANSPORT_notify_transmit_ready_cancel (transmit_handle); 529 GNUNET_TRANSPORT_notify_transmit_ready_cancel (transmit_handle);
538 transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th, 530 transmit_handle =
539 &p1.id, 531 GNUNET_TRANSPORT_notify_transmit_ready (p2.th, &p1.id, get_size (), 0,
540 get_size (), 0, 532 SEND_TIMEOUT, &notify_ready,
541 SEND_TIMEOUT, 533 NULL);
542 &notify_ready,
543 NULL);
544} 534}
545 535
546 536
@@ -584,8 +574,7 @@ exchange_hello (void *cls, const struct GNUNET_MessageHeader *message)
584 574
585 575
586static void 576static void
587notify_connect (void *cls, 577notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
588 const struct GNUNET_PeerIdentity *peer,
589 const struct GNUNET_TRANSPORT_ATS_Information *ats, 578 const struct GNUNET_TRANSPORT_ATS_Information *ats,
590 uint32_t ats_count) 579 uint32_t ats_count)
591{ 580{
@@ -593,15 +582,15 @@ notify_connect (void *cls,
593 if (cls == &p1) 582 if (cls == &p1)
594 { 583 {
595#if DEBUG_CONNECTIONS 584#if DEBUG_CONNECTIONS
596 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 585 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 1 `%4s' connected to us (%p)!\n",
597 "Peer 1 `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls); 586 GNUNET_i2s (peer), cls);
598#endif 587#endif
599 } 588 }
600 else 589 else
601 { 590 {
602#if DEBUG_CONNECTIONS 591#if DEBUG_CONNECTIONS
603 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 592 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 2 `%4s' connected to us (%p)!\n",
604 "Peer 2 `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls); 593 GNUNET_i2s (peer), cls);
605#endif 594#endif
606 } 595 }
607 if (connected == 2) 596 if (connected == 2)
@@ -636,8 +625,8 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
636 } 625 }
637 connected--; 626 connected--;
638#if DEBUG_CONNECTIONS 627#if DEBUG_CONNECTIONS
639 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 628 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' disconnected (%p)!\n",
640 "Peer `%4s' disconnected (%p)!\n", GNUNET_i2s (peer), cls); 629 GNUNET_i2s (peer), cls);
641#endif 630#endif
642} 631}
643 632
@@ -655,19 +644,18 @@ setup_peer (struct PeerContext *p, const char *cfgname)
655 } 644 }
656 645
657#if START_ARM 646#if START_ARM
658 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, 647 p->arm_proc =
659 "gnunet-service-arm", 648 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
660 "gnunet-service-arm", 649 "gnunet-service-arm",
661#if VERBOSE_ARM 650#if VERBOSE_ARM
662 "-L", "DEBUG", 651 "-L", "DEBUG",
663#endif 652#endif
664 "-c", cfgname, NULL); 653 "-c", cfgname, NULL);
665#endif 654#endif
666 655
667 p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, 656 p->th =
668 p, 657 GNUNET_TRANSPORT_connect (p->cfg, NULL, p, &notify_receive_new,
669 &notify_receive_new, 658 &notify_connect, &notify_disconnect);
670 &notify_connect, &notify_disconnect);
671 GNUNET_assert (p->th != NULL); 659 GNUNET_assert (p->th != NULL);
672} 660}
673 661
@@ -680,15 +668,15 @@ try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
680#endif 668#endif
681 GNUNET_TRANSPORT_try_connect (p2.th, &p1.id); 669 GNUNET_TRANSPORT_try_connect (p2.th, &p1.id);
682 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id); 670 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id);
683 tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 671 tct =
684 &try_connect, NULL); 672 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect,
673 NULL);
685} 674}
686 675
687 676
688static void 677static void
689run (void *cls, 678run (void *cls, char *const *args, const char *cfgfile,
690 char *const *args, 679 const struct GNUNET_CONFIGURATION_Handle *cfg)
691 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
692{ 680{
693 GNUNET_assert (ok == 1); 681 GNUNET_assert (ok == 1);
694 OKPP; 682 OKPP;
@@ -924,8 +912,8 @@ main (int argc, char *argv[])
924 GNUNET_GETOPT_OPTION_END 912 GNUNET_GETOPT_OPTION_END
925 }; 913 };
926 ok = 1; 914 ok = 1;
927 GNUNET_PROGRAM_run ((sizeof (argv1) / sizeof (char *)) - 1, 915 GNUNET_PROGRAM_run ((sizeof (argv1) / sizeof (char *)) - 1, argv1, logger,
928 argv1, logger, "nohelp", options, &run, &ok); 916 "nohelp", options, &run, &ok);
929 ret = ok; 917 ret = ok;
930 stop_arm (&p1); 918 stop_arm (&p1);
931 stop_arm (&p2); 919 stop_arm (&p2);
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c
index f9ac6a8e5..02d80d410 100644
--- a/src/transport/test_transport_api.c
+++ b/src/transport/test_transport_api.c
@@ -115,8 +115,7 @@ end_badly ()
115 115
116 116
117static void 117static void
118notify_receive (void *cls, 118notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
119 const struct GNUNET_PeerIdentity *peer,
120 const struct GNUNET_MessageHeader *message, 119 const struct GNUNET_MessageHeader *message,
121 const struct GNUNET_TRANSPORT_ATS_Information *ats, 120 const struct GNUNET_TRANSPORT_ATS_Information *ats,
122 uint32_t ats_count) 121 uint32_t ats_count)
@@ -164,30 +163,27 @@ notify_ready (void *cls, size_t size, void *buf)
164 163
165 164
166static void 165static void
167notify_connect (void *cls, 166notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
168 const struct GNUNET_PeerIdentity *peer,
169 const struct GNUNET_TRANSPORT_ATS_Information *ats, 167 const struct GNUNET_TRANSPORT_ATS_Information *ats,
170 uint32_t ats_count) 168 uint32_t ats_count)
171{ 169{
172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n",
173 "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls); 171 GNUNET_i2s (peer), cls);
174} 172}
175 173
176 174
177static void 175static void
178notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 176notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
179{ 177{
180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' disconnected (%p)!\n",
181 "Peer `%4s' disconnected (%p)!\n", GNUNET_i2s (peer), cls); 179 GNUNET_i2s (peer), cls);
182} 180}
183 181
184static void 182static void
185sendtask () 183sendtask ()
186{ 184{
187 th = GNUNET_TRANSPORT_notify_transmit_ready (p1->th, 185 th = GNUNET_TRANSPORT_notify_transmit_ready (p1->th, &p2->id, 256, 0, TIMEOUT,
188 &p2->id, 186 &notify_ready, &p1);
189 256, 0, TIMEOUT, &notify_ready,
190 &p1);
191} 187}
192 188
193static void 189static void
@@ -195,8 +191,8 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
195{ 191{
196 char *p1_c = strdup (GNUNET_i2s (&p1->id)); 192 char *p1_c = strdup (GNUNET_i2s (&p1->id));
197 193
198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n", 194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n", p1_c,
199 p1_c, GNUNET_i2s (&p2->id)); 195 GNUNET_i2s (&p2->id));
200 GNUNET_free (p1_c); 196 GNUNET_free (p1_c);
201 197
202 // FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG! 198 // FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG!
@@ -204,20 +200,17 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
204} 200}
205 201
206static void 202static void
207run (void *cls, 203run (void *cls, char *const *args, const char *cfgfile,
208 char *const *args, 204 const struct GNUNET_CONFIGURATION_Handle *cfg)
209 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
210{ 205{
211 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); 206 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
212 207
213 p1 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p1, 208 p1 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p1, &notify_receive,
214 &notify_receive, 209 &notify_connect, &notify_disconnect,
215 &notify_connect, 210 NULL);
216 &notify_disconnect, NULL); 211 p2 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p2, &notify_receive,
217 p2 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p2, 212 &notify_connect, &notify_disconnect,
218 &notify_receive, 213 NULL);
219 &notify_connect,
220 &notify_disconnect, NULL);
221 214
222 GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, NULL); 215 GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, NULL);
223} 216}
@@ -241,8 +234,8 @@ check ()
241 setTransportOptions ("test_transport_api_data.conf"); 234 setTransportOptions ("test_transport_api_data.conf");
242#endif 235#endif
243 ok = 1; 236 ok = 1;
244 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 237 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
245 argv, "test-transport-api", "nohelp", options, &run, &ok); 238 "test-transport-api", "nohelp", options, &run, &ok);
246 239
247 return ok; 240 return ok;
248} 241}
@@ -332,8 +325,8 @@ check_gnunet_nat_binary (char *binary)
332 } 325 }
333 if (0 != STAT (p, &statbuf)) 326 if (0 != STAT (p, &statbuf))
334 { 327 {
335 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 328 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("stat (%s) failed: %s\n"), p,
336 _("stat (%s) failed: %s\n"), p, STRERROR (errno)); 329 STRERROR (errno));
337 GNUNET_free (p); 330 GNUNET_free (p);
338 return GNUNET_SYSERR; 331 return GNUNET_SYSERR;
339 } 332 }
diff --git a/src/transport/test_transport_api_disconnect.c b/src/transport/test_transport_api_disconnect.c
index 08f57b670..daae553b7 100644
--- a/src/transport/test_transport_api_disconnect.c
+++ b/src/transport/test_transport_api_disconnect.c
@@ -185,8 +185,7 @@ end_badly ()
185 185
186 186
187static void 187static void
188notify_receive (void *cls, 188notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
189 const struct GNUNET_PeerIdentity *peer,
190 const struct GNUNET_MessageHeader *message, 189 const struct GNUNET_MessageHeader *message,
191 const struct GNUNET_TRANSPORT_ATS_Information *ats, 190 const struct GNUNET_TRANSPORT_ATS_Information *ats,
192 uint32_t ats_count) 191 uint32_t ats_count)
@@ -201,8 +200,8 @@ notify_receive (void *cls,
201 msgs_recv++; 200 msgs_recv++;
202} 201}
203 202
204static void 203static void peers_disconnect (void *cls,
205peers_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 204 const struct GNUNET_SCHEDULER_TaskContext *tc);
206 205
207static size_t 206static size_t
208notify_ready (void *cls, size_t size, void *buf) 207notify_ready (void *cls, size_t size, void *buf)
@@ -231,13 +230,12 @@ notify_ready (void *cls, size_t size, void *buf)
231 230
232 231
233static void 232static void
234notify_connect (void *cls, 233notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
235 const struct GNUNET_PeerIdentity *peer,
236 const struct GNUNET_TRANSPORT_ATS_Information *ats, 234 const struct GNUNET_TRANSPORT_ATS_Information *ats,
237 uint32_t ats_count) 235 uint32_t ats_count)
238{ 236{
239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 237 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n",
240 "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls); 238 GNUNET_i2s (peer), cls);
241 peers_connected++; 239 peers_connected++;
242 if (cls == &p1) 240 if (cls == &p1)
243 { 241 {
@@ -250,12 +248,10 @@ notify_connect (void *cls,
250 GNUNET_SCHEDULER_cancel (tct); 248 GNUNET_SCHEDULER_cancel (tct);
251 tct = GNUNET_SCHEDULER_NO_TASK; 249 tct = GNUNET_SCHEDULER_NO_TASK;
252 250
253 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_TRANSMIT, 251 die_task =
254 &end_badly, NULL); 252 GNUNET_SCHEDULER_add_delayed (TIMEOUT_TRANSMIT, &end_badly, NULL);
255 th = GNUNET_TRANSPORT_notify_transmit_ready (p1.th, 253 th = GNUNET_TRANSPORT_notify_transmit_ready (p1.th, &p2.id, 256, 0, TIMEOUT,
256 &p2.id, 254 &notify_ready, &p1);
257 256, 0, TIMEOUT, &notify_ready,
258 &p1);
259 } 255 }
260} 256}
261 257
@@ -263,8 +259,8 @@ notify_connect (void *cls,
263static void 259static void
264notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 260notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
265{ 261{
266 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' disconnected (%p)!\n",
267 "Peer `%4s' disconnected (%p)!\n", GNUNET_i2s (peer), cls); 263 GNUNET_i2s (peer), cls);
268 peers_connected--; 264 peers_connected--;
269} 265}
270 266
@@ -282,12 +278,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
282 GNUNET_DISK_directory_remove (p->servicehome); 278 GNUNET_DISK_directory_remove (p->servicehome);
283 279
284#if START_ARM 280#if START_ARM
285 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 281 p->arm_proc =
286 "gnunet-service-arm", 282 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
283 "gnunet-service-arm",
287#if VERBOSE_ARM 284#if VERBOSE_ARM
288 "-L", "DEBUG", 285 "-L", "DEBUG",
289#endif 286#endif
290 "-c", cfgname, NULL); 287 "-c", cfgname, NULL);
291#endif 288#endif
292 289
293} 290}
@@ -300,8 +297,9 @@ try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
300 /* FIXME: 'pX.id' may still be all-zeros here... */ 297 /* FIXME: 'pX.id' may still be all-zeros here... */
301 GNUNET_TRANSPORT_try_connect (p2.th, &p1.id); 298 GNUNET_TRANSPORT_try_connect (p2.th, &p1.id);
302 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id); 299 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id);
303 tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 300 tct =
304 &try_connect, NULL); 301 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect,
302 NULL);
305} 303}
306 304
307 305
@@ -340,16 +338,14 @@ peers_connect ()
340 ITERATIONS); 338 ITERATIONS);
341 339
342 GNUNET_assert (p1.th == NULL); 340 GNUNET_assert (p1.th == NULL);
343 p1.th = GNUNET_TRANSPORT_connect (p1.cfg, 341 p1.th =
344 NULL, &p1, 342 GNUNET_TRANSPORT_connect (p1.cfg, NULL, &p1, &notify_receive,
345 &notify_receive, 343 &notify_connect, &notify_disconnect);
346 &notify_connect, &notify_disconnect);
347 344
348 GNUNET_assert (p2.th == NULL); 345 GNUNET_assert (p2.th == NULL);
349 p2.th = GNUNET_TRANSPORT_connect (p2.cfg, 346 p2.th =
350 NULL, &p2, 347 GNUNET_TRANSPORT_connect (p2.cfg, NULL, &p2, &notify_receive,
351 &notify_receive, 348 &notify_connect, &notify_disconnect);
352 &notify_connect, &notify_disconnect);
353 349
354 GNUNET_assert (p1.th != NULL); 350 GNUNET_assert (p1.th != NULL);
355 GNUNET_assert (p2.th != NULL); 351 GNUNET_assert (p2.th != NULL);
@@ -360,9 +356,8 @@ peers_connect ()
360} 356}
361 357
362static void 358static void
363run (void *cls, 359run (void *cls, char *const *args, const char *cfgfile,
364 char *const *args, 360 const struct GNUNET_CONFIGURATION_Handle *cfg)
365 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
366{ 361{
367 GNUNET_assert (ok == 1); 362 GNUNET_assert (ok == 1);
368 OKPP; 363 OKPP;
@@ -393,8 +388,8 @@ check ()
393 setTransportOptions ("test_transport_api_data.conf"); 388 setTransportOptions ("test_transport_api_data.conf");
394#endif 389#endif
395 ok = 1; 390 ok = 1;
396 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 391 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
397 argv, "test-transport-api", "nohelp", options, &run, &ok); 392 "test-transport-api", "nohelp", options, &run, &ok);
398 stop_arm (&p1); 393 stop_arm (&p1);
399 stop_arm (&p2); 394 stop_arm (&p2);
400 395
diff --git a/src/transport/test_transport_api_multiaddress.c b/src/transport/test_transport_api_multiaddress.c
index 63ef28862..8748e5f6c 100644
--- a/src/transport/test_transport_api_multiaddress.c
+++ b/src/transport/test_transport_api_multiaddress.c
@@ -165,13 +165,12 @@ end_normally (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
165} 165}
166 166
167static void 167static void
168notify_connect (void *cls, 168notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
169 const struct GNUNET_PeerIdentity *peer,
170 const struct GNUNET_TRANSPORT_ATS_Information *ats, 169 const struct GNUNET_TRANSPORT_ATS_Information *ats,
171 uint32_t ats_count) 170 uint32_t ats_count)
172{ 171{
173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n",
174 "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls); 173 GNUNET_i2s (peer), cls);
175 if (cls == &p1) 174 if (cls == &p1)
176 { 175 {
177 GNUNET_assert (ok >= 2); 176 GNUNET_assert (ok >= 2);
@@ -182,8 +181,8 @@ notify_connect (void *cls,
182 if (GNUNET_SCHEDULER_NO_TASK != tct) 181 if (GNUNET_SCHEDULER_NO_TASK != tct)
183 GNUNET_SCHEDULER_cancel (tct); 182 GNUNET_SCHEDULER_cancel (tct);
184 tct = GNUNET_SCHEDULER_NO_TASK; 183 tct = GNUNET_SCHEDULER_NO_TASK;
185 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_TRANSMIT, 184 die_task =
186 &end_normally, NULL); 185 GNUNET_SCHEDULER_add_delayed (TIMEOUT_TRANSMIT, &end_normally, NULL);
187 } 186 }
188} 187}
189 188
@@ -196,8 +195,8 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
196 GNUNET_SCHEDULER_cancel (die_task); 195 GNUNET_SCHEDULER_cancel (die_task);
197 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); 196 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
198 } 197 }
199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' disconnected (%p)!\n",
200 "Peer `%4s' disconnected (%p)!\n", GNUNET_i2s (peer), cls); 199 GNUNET_i2s (peer), cls);
201} 200}
202 201
203 202
@@ -210,24 +209,24 @@ setup_peer (struct PeerContext *p, const char *cfgname)
210 if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME")) 209 if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME"))
211 { 210 {
212 GNUNET_assert (GNUNET_OK == 211 GNUNET_assert (GNUNET_OK ==
213 GNUNET_CONFIGURATION_get_value_string (p->cfg, 212 GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS",
214 "PATHS",
215 "SERVICEHOME", 213 "SERVICEHOME",
216 &p->servicehome)); 214 &p->servicehome));
217 GNUNET_DISK_directory_remove (p->servicehome); 215 GNUNET_DISK_directory_remove (p->servicehome);
218 } 216 }
219 217
220#if START_ARM 218#if START_ARM
221 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 219 p->arm_proc =
222 "gnunet-service-arm", 220 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
221 "gnunet-service-arm",
223#if VERBOSE_ARM 222#if VERBOSE_ARM
224 "-L", "DEBUG", 223 "-L", "DEBUG",
225#endif 224#endif
226 "-c", cfgname, NULL); 225 "-c", cfgname, NULL);
227#endif 226#endif
228 p->th = GNUNET_TRANSPORT_connect (p->cfg, 227 p->th =
229 NULL, p, 228 GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, &notify_connect,
230 NULL, &notify_connect, &notify_disconnect); 229 &notify_disconnect);
231 GNUNET_assert (p->th != NULL); 230 GNUNET_assert (p->th != NULL);
232} 231}
233 232
@@ -239,15 +238,15 @@ try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
239 /* FIXME: 'pX.id' may still be all-zeros here... */ 238 /* FIXME: 'pX.id' may still be all-zeros here... */
240 GNUNET_TRANSPORT_try_connect (p2.th, &p1.id); 239 GNUNET_TRANSPORT_try_connect (p2.th, &p1.id);
241 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id); 240 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id);
242 tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 241 tct =
243 &try_connect, NULL); 242 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect,
243 NULL);
244} 244}
245 245
246 246
247static void 247static void
248run (void *cls, 248run (void *cls, char *const *args, const char *cfgfile,
249 char *const *args, 249 const struct GNUNET_CONFIGURATION_Handle *cfg)
250 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
251{ 250{
252 GNUNET_assert (ok == 1); 251 GNUNET_assert (ok == 1);
253 OKPP; 252 OKPP;
@@ -284,8 +283,8 @@ check ()
284 setTransportOptions ("test_transport_api_data.conf"); 283 setTransportOptions ("test_transport_api_data.conf");
285#endif 284#endif
286 ok = 1; 285 ok = 1;
287 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 286 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
288 argv, "test-transport-api", "nohelp", options, &run, &ok); 287 "test-transport-api", "nohelp", options, &run, &ok);
289 stop_arm (&p1); 288 stop_arm (&p1);
290 stop_arm (&p2); 289 stop_arm (&p2);
291 290
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c
index 60191394d..008bb9019 100644
--- a/src/transport/test_transport_api_reliability.c
+++ b/src/transport/test_transport_api_reliability.c
@@ -114,8 +114,8 @@ end ()
114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); 114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n");
115 115
116 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; 116 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value;
117 fprintf (stderr, 117 fprintf (stderr, "\nThroughput was %llu kb/s\n",
118 "\nThroughput was %llu kb/s\n", total_bytes * 1000 / 1024 / delta); 118 total_bytes * 1000 / 1024 / delta);
119 //GNUNET_asprintf(&value_name, "reliable_%s", test_name); 119 //GNUNET_asprintf(&value_name, "reliable_%s", test_name);
120 //GAUGER ("TRANSPORT", value_name, (int)(total_bytes * 1000 / 1024 /delta), "kb/s"); 120 //GAUGER ("TRANSPORT", value_name, (int)(total_bytes * 1000 / 1024 /delta), "kb/s");
121 //GNUNET_free(value_name); 121 //GNUNET_free(value_name);
@@ -161,8 +161,7 @@ get_size (unsigned int iter)
161 161
162 162
163static void 163static void
164notify_receive (void *cls, 164notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
165 const struct GNUNET_PeerIdentity *peer,
166 const struct GNUNET_MessageHeader *message, 165 const struct GNUNET_MessageHeader *message,
167 const struct GNUNET_TRANSPORT_ATS_Information *ats, 166 const struct GNUNET_TRANSPORT_ATS_Information *ats,
168 uint32_t ats_count) 167 uint32_t ats_count)
@@ -204,8 +203,8 @@ notify_receive (void *cls,
204 if (0 != memcmp (cbuf, &hdr[1], s - sizeof (struct TestMessage))) 203 if (0 != memcmp (cbuf, &hdr[1], s - sizeof (struct TestMessage)))
205 { 204 {
206 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 205 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
207 "Expected message %u with bits %u, but body did not match\n", 206 "Expected message %u with bits %u, but body did not match\n", n,
208 n, (unsigned char) n); 207 (unsigned char) n);
209 if (die_task != GNUNET_SCHEDULER_NO_TASK) 208 if (die_task != GNUNET_SCHEDULER_NO_TASK)
210 GNUNET_SCHEDULER_cancel (die_task); 209 GNUNET_SCHEDULER_cancel (die_task);
211 test_failed = GNUNET_YES; 210 test_failed = GNUNET_YES;
@@ -215,8 +214,7 @@ notify_receive (void *cls,
215#if VERBOSE 214#if VERBOSE
216 if (ntohl (hdr->num) % 5000 == 0) 215 if (ntohl (hdr->num) % 5000 == 0)
217 { 216 {
218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 217 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got message %u of size %u\n",
219 "Got message %u of size %u\n",
220 ntohl (hdr->num), ntohs (message->size)); 218 ntohl (hdr->num), ntohs (message->size));
221 } 219 }
222#endif 220#endif
@@ -271,8 +269,8 @@ notify_ready (void *cls, size_t size, void *buf)
271#if VERBOSE 269#if VERBOSE
272 if (n % 5000 == 0) 270 if (n % 5000 == 0)
273 { 271 {
274 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message %u of size %u\n", n,
275 "Sending message %u of size %u\n", n, s); 273 s);
276 } 274 }
277#endif 275#endif
278 n++; 276 n++;
@@ -284,10 +282,9 @@ notify_ready (void *cls, size_t size, void *buf)
284 if (n < TOTAL_MSGS) 282 if (n < TOTAL_MSGS)
285 { 283 {
286 if (th == NULL) 284 if (th == NULL)
287 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, 285 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, s, 0,
288 &p1->id, 286 TIMEOUT, &notify_ready,
289 s, 0, TIMEOUT, 287 NULL);
290 &notify_ready, NULL);
291 msg_scheduled = n; 288 msg_scheduled = n;
292 } 289 }
293 if (n % 5000 == 0) 290 if (n % 5000 == 0)
@@ -305,19 +302,17 @@ notify_ready (void *cls, size_t size, void *buf)
305 302
306 303
307static void 304static void
308notify_connect (void *cls, 305notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
309 const struct GNUNET_PeerIdentity *peer,
310 const struct GNUNET_TRANSPORT_ATS_Information *ats, 306 const struct GNUNET_TRANSPORT_ATS_Information *ats,
311 uint32_t ats_count) 307 uint32_t ats_count)
312{ 308{
313 309
314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 310 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n",
315 "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls); 311 GNUNET_i2s (peer), cls);
316 312
317 if (cls == p1) 313 if (cls == p1)
318 { 314 {
319 GNUNET_TRANSPORT_set_quota (p1->th, 315 GNUNET_TRANSPORT_set_quota (p1->th, &p2->id,
320 &p2->id,
321 GNUNET_BANDWIDTH_value_init (1024 * 1024 * 316 GNUNET_BANDWIDTH_value_init (1024 * 1024 *
322 1024), 317 1024),
323 GNUNET_BANDWIDTH_value_init (1024 * 1024 * 318 GNUNET_BANDWIDTH_value_init (1024 * 1024 *
@@ -325,8 +320,7 @@ notify_connect (void *cls,
325 } 320 }
326 else if (cls == p2) 321 else if (cls == p2)
327 { 322 {
328 GNUNET_TRANSPORT_set_quota (p2->th, 323 GNUNET_TRANSPORT_set_quota (p2->th, &p1->id,
329 &p1->id,
330 GNUNET_BANDWIDTH_value_init (1024 * 1024 * 324 GNUNET_BANDWIDTH_value_init (1024 * 1024 *
331 1024), 325 1024),
332 GNUNET_BANDWIDTH_value_init (1024 * 1024 * 326 GNUNET_BANDWIDTH_value_init (1024 * 1024 *
@@ -338,18 +332,16 @@ notify_connect (void *cls,
338static void 332static void
339notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 333notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
340{ 334{
341 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 335 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' disconnected (%p)!\n",
342 "Peer `%4s' disconnected (%p)!\n", GNUNET_i2s (peer), cls); 336 GNUNET_i2s (peer), cls);
343} 337}
344 338
345static void 339static void
346sendtask () 340sendtask ()
347{ 341{
348 start_time = GNUNET_TIME_absolute_get (); 342 start_time = GNUNET_TIME_absolute_get ();
349 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, 343 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, get_size (0), 0,
350 &p1->id, 344 TIMEOUT, &notify_ready, NULL);
351 get_size (0), 0, TIMEOUT,
352 &notify_ready, NULL);
353} 345}
354 346
355static void 347static void
@@ -357,8 +349,8 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
357{ 349{
358 char *p1_c = strdup (GNUNET_i2s (&p1->id)); 350 char *p1_c = strdup (GNUNET_i2s (&p1->id));
359 351
360 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n", 352 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n", p1_c,
361 p1_c, GNUNET_i2s (&p2->id)); 353 GNUNET_i2s (&p2->id));
362 GNUNET_free (p1_c); 354 GNUNET_free (p1_c);
363 355
364 // FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG! 356 // FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG!
@@ -366,20 +358,17 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
366} 358}
367 359
368static void 360static void
369run (void *cls, 361run (void *cls, char *const *args, const char *cfgfile,
370 char *const *args, 362 const struct GNUNET_CONFIGURATION_Handle *cfg)
371 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
372{ 363{
373 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); 364 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
374 365
375 p1 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p1, 366 p1 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p1, &notify_receive,
376 &notify_receive, 367 &notify_connect, &notify_disconnect,
377 &notify_connect, 368 NULL);
378 &notify_disconnect, NULL); 369 p2 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p2, &notify_receive,
379 p2 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p2, 370 &notify_connect, &notify_disconnect,
380 &notify_receive, 371 NULL);
381 &notify_connect,
382 &notify_disconnect, NULL);
383 372
384 GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, NULL); 373 GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, NULL);
385} 374}
@@ -403,8 +392,8 @@ check ()
403 setTransportOptions ("test_transport_api_data.conf"); 392 setTransportOptions ("test_transport_api_data.conf");
404#endif 393#endif
405 ok = 1; 394 ok = 1;
406 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 395 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
407 argv, "test-transport-api", "nohelp", options, &run, &ok); 396 "test-transport-api", "nohelp", options, &run, &ok);
408 397
409 return ok; 398 return ok;
410} 399}
@@ -494,8 +483,8 @@ check_gnunet_nat_binary (char *binary)
494 } 483 }
495 if (0 != STAT (p, &statbuf)) 484 if (0 != STAT (p, &statbuf))
496 { 485 {
497 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 486 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("stat (%s) failed: %s\n"), p,
498 _("stat (%s) failed: %s\n"), p, STRERROR (errno)); 487 STRERROR (errno));
499 GNUNET_free (p); 488 GNUNET_free (p);
500 return GNUNET_SYSERR; 489 return GNUNET_SYSERR;
501 } 490 }
diff --git a/src/transport/test_transport_api_unreliability.c b/src/transport/test_transport_api_unreliability.c
index 88df23eb4..5eed408c0 100644
--- a/src/transport/test_transport_api_unreliability.c
+++ b/src/transport/test_transport_api_unreliability.c
@@ -193,8 +193,8 @@ end ()
193 GAUGER ("TRANSPORT", value_name, (int) (total_bytes * 1000 / 1024 / delta), 193 GAUGER ("TRANSPORT", value_name, (int) (total_bytes * 1000 / 1024 / delta),
194 "kb/s"); 194 "kb/s");
195 GNUNET_free (value_name); 195 GNUNET_free (value_name);
196 fprintf (stderr, 196 fprintf (stderr, "\nThroughput was %llu kb/s\n",
197 "\nThroughput was %llu kb/s\n", total_bytes * 1000 / 1024 / delta); 197 total_bytes * 1000 / 1024 / delta);
198 ok = result; 198 ok = result;
199 199
200} 200}
@@ -231,8 +231,8 @@ end_unreliably ()
231 "Transports disconnected, returning success!\n"); 231 "Transports disconnected, returning success!\n");
232#endif 232#endif
233 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; 233 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value;
234 fprintf (stderr, 234 fprintf (stderr, "\nThroughput was %llu kb/s\n",
235 "\nThroughput was %llu kb/s\n", total_bytes * 1000 / 1024 / delta); 235 total_bytes * 1000 / 1024 / delta);
236 GNUNET_asprintf (&value_name, "unreliable_%s", test_name); 236 GNUNET_asprintf (&value_name, "unreliable_%s", test_name);
237 GAUGER ("TRANSPORT", value_name, (int) (total_bytes * 1000 / 1024 / delta), 237 GAUGER ("TRANSPORT", value_name, (int) (total_bytes * 1000 / 1024 / delta),
238 "kb/s"); 238 "kb/s");
@@ -355,8 +355,7 @@ get_size (unsigned int iter)
355 355
356 356
357static void 357static void
358notify_receive (void *cls, 358notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
359 const struct GNUNET_PeerIdentity *peer,
360 const struct GNUNET_MessageHeader *message, 359 const struct GNUNET_MessageHeader *message,
361 const struct GNUNET_TRANSPORT_ATS_Information *ats, 360 const struct GNUNET_TRANSPORT_ATS_Information *ats,
362 uint32_t ats_count) 361 uint32_t ats_count)
@@ -401,8 +400,7 @@ notify_receive (void *cls,
401#if VERBOSE 400#if VERBOSE
402 if (ntohl (hdr->num) % 5 == 0) 401 if (ntohl (hdr->num) % 5 == 0)
403 { 402 {
404 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got message %u of size %u\n",
405 "Got message %u of size %u\n",
406 ntohl (hdr->num), ntohs (message->size)); 404 ntohl (hdr->num), ntohs (message->size));
407 } 405 }
408#endif 406#endif
@@ -456,8 +454,8 @@ notify_ready (void *cls, size_t size, void *buf)
456#if VERBOSE 454#if VERBOSE
457 if (n % 5000 == 0) 455 if (n % 5000 == 0)
458 { 456 {
459 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message %u of size %u\n", n,
460 "Sending message %u of size %u\n", n, s); 458 s);
461 } 459 }
462#endif 460#endif
463 n++; 461 n++;
@@ -468,10 +466,9 @@ notify_ready (void *cls, size_t size, void *buf)
468 while (size - ret >= s); 466 while (size - ret >= s);
469 if (n < TOTAL_MSGS) 467 if (n < TOTAL_MSGS)
470 { 468 {
471 th_p2 = GNUNET_TRANSPORT_notify_transmit_ready (p2.th, 469 th_p2 =
472 &p1.id, 470 GNUNET_TRANSPORT_notify_transmit_ready (p2.th, &p1.id, s, 0, TIMEOUT,
473 s, 0, TIMEOUT, 471 &notify_ready, NULL);
474 &notify_ready, NULL);
475 msg_scheduled = n; 472 msg_scheduled = n;
476 } 473 }
477 else 474 else
@@ -500,8 +497,8 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
500{ 497{
501 connected--; 498 connected--;
502#if VERBOSE 499#if VERBOSE
503 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 500 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' disconnected (%p)!\n",
504 "Peer `%4s' disconnected (%p)!\n", GNUNET_i2s (peer), cls); 501 GNUNET_i2s (peer), cls);
505#endif 502#endif
506 if (th_p2 != NULL) 503 if (th_p2 != NULL)
507 { 504 {
@@ -513,17 +510,15 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
513 510
514 511
515static void 512static void
516notify_connect (void *cls, 513notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
517 const struct GNUNET_PeerIdentity *peer,
518 const struct GNUNET_TRANSPORT_ATS_Information *ats, 514 const struct GNUNET_TRANSPORT_ATS_Information *ats,
519 uint32_t ats_count) 515 uint32_t ats_count)
520{ 516{
521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 517 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n",
522 "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls); 518 GNUNET_i2s (peer), cls);
523 if (cls == &p1) 519 if (cls == &p1)
524 { 520 {
525 GNUNET_TRANSPORT_set_quota (p1.th, 521 GNUNET_TRANSPORT_set_quota (p1.th, &p2.id,
526 &p2.id,
527 GNUNET_BANDWIDTH_value_init (1024 * 1024 * 522 GNUNET_BANDWIDTH_value_init (1024 * 1024 *
528 1024), 523 1024),
529 GNUNET_BANDWIDTH_value_init (1024 * 1024 * 524 GNUNET_BANDWIDTH_value_init (1024 * 1024 *
@@ -533,8 +528,7 @@ notify_connect (void *cls,
533 } 528 }
534 else 529 else
535 { 530 {
536 GNUNET_TRANSPORT_set_quota (p2.th, 531 GNUNET_TRANSPORT_set_quota (p2.th, &p1.id,
537 &p1.id,
538 GNUNET_BANDWIDTH_value_init (1024 * 1024 * 532 GNUNET_BANDWIDTH_value_init (1024 * 1024 *
539 1024), 533 1024),
540 GNUNET_BANDWIDTH_value_init (1024 * 1024 * 534 GNUNET_BANDWIDTH_value_init (1024 * 1024 *
@@ -564,10 +558,8 @@ notify_connect (void *cls,
564 } 558 }
565 559
566 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); 560 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
567 GNUNET_TRANSPORT_notify_transmit_ready (p2.th, 561 GNUNET_TRANSPORT_notify_transmit_ready (p2.th, &p1.id, get_size (0), 0,
568 &p1.id, 562 TIMEOUT, &notify_ready, NULL);
569 get_size (0), 0, TIMEOUT,
570 &notify_ready, NULL);
571 563
572 } 564 }
573} 565}
@@ -583,8 +575,7 @@ setup_peer (struct PeerContext *p, const char *cfgname)
583 if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME")) 575 if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME"))
584 { 576 {
585 GNUNET_assert (GNUNET_OK == 577 GNUNET_assert (GNUNET_OK ==
586 GNUNET_CONFIGURATION_get_value_string (p->cfg, 578 GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS",
587 "PATHS",
588 "SERVICEHOME", 579 "SERVICEHOME",
589 &p->servicehome)); 580 &p->servicehome));
590 GNUNET_DISK_directory_remove (p->servicehome); 581 GNUNET_DISK_directory_remove (p->servicehome);
@@ -592,19 +583,18 @@ setup_peer (struct PeerContext *p, const char *cfgname)
592 583
593 584
594#if START_ARM 585#if START_ARM
595 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, 586 p->arm_proc =
596 "gnunet-service-arm", 587 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
597 "gnunet-service-arm", 588 "gnunet-service-arm",
598#if VERBOSE_ARM 589#if VERBOSE_ARM
599 "-L", "DEBUG", 590 "-L", "DEBUG",
600#endif 591#endif
601 "-c", cfgname, NULL); 592 "-c", cfgname, NULL);
602#endif 593#endif
603 594
604 p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, 595 p->th =
605 p, 596 GNUNET_TRANSPORT_connect (p->cfg, NULL, p, &notify_receive,
606 &notify_receive, 597 &notify_connect, &notify_disconnect);
607 &notify_connect, &notify_disconnect);
608 GNUNET_assert (p->th != NULL); 598 GNUNET_assert (p->th != NULL);
609} 599}
610 600
@@ -694,8 +684,8 @@ check_gnunet_nat_binary (char *binary)
694 } 684 }
695 if (0 != STAT (p, &statbuf)) 685 if (0 != STAT (p, &statbuf))
696 { 686 {
697 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 687 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("stat (%s) failed: %s\n"), p,
698 _("stat (%s) failed: %s\n"), p, STRERROR (errno)); 688 STRERROR (errno));
699 GNUNET_free (p); 689 GNUNET_free (p);
700 return GNUNET_SYSERR; 690 return GNUNET_SYSERR;
701 } 691 }
@@ -727,16 +717,16 @@ try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
727 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking peers to connect...\n"); 717 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking peers to connect...\n");
728 GNUNET_TRANSPORT_try_connect (p2.th, &p1.id); 718 GNUNET_TRANSPORT_try_connect (p2.th, &p1.id);
729 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id); 719 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id);
730 tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 720 tct =
731 &try_connect, NULL); 721 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect,
722 NULL);
732} 723}
733 724
734 725
735 726
736static void 727static void
737run (void *cls, 728run (void *cls, char *const *args, const char *cfgfile,
738 char *const *args, 729 const struct GNUNET_CONFIGURATION_Handle *cfg)
739 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
740{ 730{
741 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); 731 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
742 if (is_tcp) 732 if (is_tcp)
@@ -814,9 +804,9 @@ check ()
814 return 0; 804 return 0;
815 } 805 }
816 806
817 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 807 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
818 argv, "test-transport-api-unreliability", "nohelp", 808 "test-transport-api-unreliability", "nohelp", options,
819 options, &run, &ok); 809 &run, &ok);
820 stop_arm (&p1); 810 stop_arm (&p1);
821 stop_arm (&p2); 811 stop_arm (&p2);
822 812
diff --git a/src/transport/test_transport_ats.c b/src/transport/test_transport_ats.c
index d9e4b23d5..0d16cd1b8 100644
--- a/src/transport/test_transport_ats.c
+++ b/src/transport/test_transport_ats.c
@@ -55,8 +55,8 @@ struct TransportConfiguration
55 55
56 56
57static void 57static void
58create_ats_information (struct ATS_peer **p, int *c_p, 58create_ats_information (struct ATS_peer **p, int *c_p, struct ATS_mechanism **m,
59 struct ATS_mechanism **m, int *c_m) 59 int *c_m)
60{ 60{
61 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS needs addresses\n"); 61 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS needs addresses\n");
62 62
@@ -73,8 +73,8 @@ run_ats ()
73 int ret = 0; 73 int ret = 0;
74 74
75 ats_calculate_bandwidth_distribution (ats); 75 ats_calculate_bandwidth_distribution (ats);
76 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 76 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Running ATS: %s \n",
77 "Running ATS: %s \n", (ret == 0) ? "SUCCESSFUL" : "FAILED"); 77 (ret == 0) ? "SUCCESSFUL" : "FAILED");
78 return ret; 78 return ret;
79} 79}
80 80
@@ -84,12 +84,13 @@ init_ats ()
84{ 84{
85 int ret = 0; 85 int ret = 0;
86 86
87 ats = ats_init (1.0, 1.0, 1.0, 50000, 5, 10, ATS_MAX_EXEC_DURATION, 87 ats =
88 create_ats_information, ats_result_cb); 88 ats_init (1.0, 1.0, 1.0, 50000, 5, 10, ATS_MAX_EXEC_DURATION,
89 create_ats_information, ats_result_cb);
89 //GNUNET_assert (ats != NULL); 90 //GNUNET_assert (ats != NULL);
90 91
91 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 92 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Initializing ATS: %s \n",
92 "Initializing ATS: %s \n", (ret == 0) ? "SUCCESSFUL" : "FAILED"); 93 (ret == 0) ? "SUCCESSFUL" : "FAILED");
93 return ret; 94 return ret;
94} 95}
95 96
@@ -101,8 +102,8 @@ shutdown_ats ()
101 102
102 ats_delete_problem (ats); 103 ats_delete_problem (ats);
103 ats_shutdown (ats); 104 ats_shutdown (ats);
104 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 105 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Shutdown ATS: %s \n",
105 "Shutdown ATS: %s \n", (ret == 0) ? "SUCCESSFUL" : "FAILED"); 106 (ret == 0) ? "SUCCESSFUL" : "FAILED");
106 return ret; 107 return ret;
107} 108}
108 109
@@ -123,16 +124,16 @@ dummy ()
123 124
124 125
125static void 126static void
126iterate_peer_values (void *cls, 127iterate_peer_values (void *cls, const char *section, const char *option,
127 const char *section, const char *option, const char *value) 128 const char *value)
128{ 129{
129 if (strcmp (option, "f") == 0) 130 if (strcmp (option, "f") == 0)
130 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t %s %s\n", option, value); 131 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t %s %s\n", option, value);
131} 132}
132 133
133static void 134static void
134iterate_mech_values (void *cls, 135iterate_mech_values (void *cls, const char *section, const char *option,
135 const char *section, const char *option, const char *value) 136 const char *value)
136{ 137{
137 if (strcmp (option, "f") == 0) 138 if (strcmp (option, "f") == 0)
138 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t %s %s\n", option, value); 139 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t %s %s\n", option, value);
diff --git a/src/transport/test_transport_ats_multiple_peers.c b/src/transport/test_transport_ats_multiple_peers.c
index d060a4d4b..fbc148e10 100644
--- a/src/transport/test_transport_ats_multiple_peers.c
+++ b/src/transport/test_transport_ats_multiple_peers.c
@@ -215,15 +215,15 @@ evaluate_measurements ()
215 stddev[0] = 0.0; 215 stddev[0] = 0.0;
216 for (c = 0; c < c_new; c++) 216 for (c = 0; c < c_new; c++)
217 { 217 {
218 stddev[0] += (results_new[c].duration - average[0]) * 218 stddev[0] +=
219 (results_new[c].duration - average[0]); 219 (results_new[c].duration - average[0]) * (results_new[c].duration -
220 average[0]);
220 } 221 }
221 stddev[0] /= c_new; 222 stddev[0] /= c_new;
222 stddev[0] = sqrt (stddev[0]); 223 stddev[0] = sqrt (stddev[0]);
223 if (!machine_parsable) 224 if (!machine_parsable)
224 fprintf (stderr, 225 fprintf (stderr, "new, %i measurements, average: %f stddev: %f\n", c_new,
225 "new, %i measurements, average: %f stddev: %f\n", 226 average[0], stddev[0]);
226 c_new, average[0], stddev[0]);
227 227
228 average[1] = 0.0; 228 average[1] = 0.0;
229 for (c = 0; c < c_modified; c++) 229 for (c = 0; c < c_modified; c++)
@@ -235,14 +235,14 @@ evaluate_measurements ()
235 stddev[1] = 0.0; 235 stddev[1] = 0.0;
236 for (c = 0; c < c_modified; c++) 236 for (c = 0; c < c_modified; c++)
237 { 237 {
238 stddev[1] += (results_modified[c].duration - average[1]) * 238 stddev[1] +=
239 (results_modified[c].duration - average[1]); 239 (results_modified[c].duration -
240 average[1]) * (results_modified[c].duration - average[1]);
240 } 241 }
241 stddev[1] /= c_modified; 242 stddev[1] /= c_modified;
242 stddev[1] = sqrt (stddev[1]); 243 stddev[1] = sqrt (stddev[1]);
243 if (!machine_parsable) 244 if (!machine_parsable)
244 fprintf (stderr, 245 fprintf (stderr, "modified, %i measurements, average: %f stddev: %f\n",
245 "modified, %i measurements, average: %f stddev: %f\n",
246 c_modified, average[1], stddev[1]); 246 c_modified, average[1], stddev[1]);
247 247
248 average[2] = 0.0; 248 average[2] = 0.0;
@@ -254,35 +254,31 @@ evaluate_measurements ()
254 stddev[2] = 0.0; 254 stddev[2] = 0.0;
255 for (c = 0; c < c_unmodified; c++) 255 for (c = 0; c < c_unmodified; c++)
256 { 256 {
257 stddev[2] += (results_unmodified[c].duration - average[2]) * 257 stddev[2] +=
258 (results_unmodified[c].duration - average[2]); 258 (results_unmodified[c].duration -
259 average[2]) * (results_unmodified[c].duration - average[2]);
259 } 260 }
260 stddev[2] /= c_unmodified; 261 stddev[2] /= c_unmodified;
261 stddev[2] = sqrt (stddev[2]); 262 stddev[2] = sqrt (stddev[2]);
262 263
263 if (!machine_parsable) 264 if (!machine_parsable)
264 fprintf (stderr, 265 fprintf (stderr, "unmodified, %i measurements, average: %f stddev: %f\n",
265 "unmodified, %i measurements, average: %f stddev: %f\n",
266 c_unmodified, average[2], stddev[2]); 266 c_unmodified, average[2], stddev[2]);
267 267
268 if (machine_parsable) 268 if (machine_parsable)
269 fprintf (stderr, 269 fprintf (stderr,
270 "peers,%i,mechs,%llu," 270 "peers,%i,mechs,%llu," "new,%i,%f,%f," "mod,%i,%f,%f,"
271 "new,%i,%f,%f," 271 "unmod,%i,%f,%f\n", peers - 1,
272 "mod,%i,%f,%f," 272 (unsigned long long) results_unmodified[0].mechs, c_new,
273 "unmod,%i,%f,%f\n", 273 average[0], stddev[0], c_modified, average[1], stddev[1],
274 peers - 1, (unsigned long long) results_unmodified[0].mechs,
275 c_new, average[0], stddev[0],
276 c_modified, average[1], stddev[1],
277 c_unmodified, average[2], stddev[2]); 274 c_unmodified, average[2], stddev[2]);
278 shutdown_peers (); 275 shutdown_peers ();
279} 276}
280 277
281 278
282static int 279static int
283stats_cb (void *cls, 280stats_cb (void *cls, const char *subsystem, const char *name, uint64_t value,
284 const char *subsystem, 281 int is_persistent)
285 const char *name, uint64_t value, int is_persistent)
286{ 282{
287 static int printed = GNUNET_NO; 283 static int printed = GNUNET_NO;
288 284
@@ -330,8 +326,8 @@ stats_cb (void *cls,
330 s_state = NULL; 326 s_state = NULL;
331 } 327 }
332 328
333 if ((measurement_started == GNUNET_NO) && 329 if ((measurement_started == GNUNET_NO) && (0 == strcmp (name, "ATS peers")) &&
334 (0 == strcmp (name, "ATS peers")) && (value == peers - 1)) 330 (value == peers - 1))
335 { 331 {
336 measurement_started = GNUNET_YES; 332 measurement_started = GNUNET_YES;
337 count = 1; 333 count = 1;
@@ -396,12 +392,11 @@ stats_cb (void *cls,
396 } 392 }
397 count++; 393 count++;
398#if VERBOSE 394#if VERBOSE
399 fprintf (stderr, 395 fprintf (stderr, "(new: %i / modified: %i / unmodified: %i) of %i \n",
400 "(new: %i / modified: %i / unmodified: %i) of %i \n",
401 c_new, c_modified, c_unmodified, MEASUREMENTS); 396 c_new, c_modified, c_unmodified, MEASUREMENTS);
402#endif 397#endif
403 if ((c_modified >= MEASUREMENTS) && 398 if ((c_modified >= MEASUREMENTS) && (c_new >= MEASUREMENTS) &&
404 (c_new >= MEASUREMENTS) && (c_unmodified >= MEASUREMENTS)) 399 (c_unmodified >= MEASUREMENTS))
405 { 400 {
406#if !VERBOSE 401#if !VERBOSE
407 if (!machine_parsable) 402 if (!machine_parsable)
@@ -430,32 +425,32 @@ stats_cb (void *cls,
430 { 425 {
431 current.solution = value; 426 current.solution = value;
432 if (printed == GNUNET_NO) 427 if (printed == GNUNET_NO)
433 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n", 428 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n", count, name,
434 count, name, value); 429 value);
435 } 430 }
436 431
437 if (0 == strcmp (name, "ATS peers")) 432 if (0 == strcmp (name, "ATS peers"))
438 { 433 {
439 current.peers = value; 434 current.peers = value;
440 if (printed == GNUNET_NO) 435 if (printed == GNUNET_NO)
441 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n", 436 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n", count, name,
442 count, name, value); 437 value);
443 } 438 }
444 439
445 if (0 == strcmp (name, "ATS mechanisms")) 440 if (0 == strcmp (name, "ATS mechanisms"))
446 { 441 {
447 current.mechs = value; 442 current.mechs = value;
448 if (printed == GNUNET_NO) 443 if (printed == GNUNET_NO)
449 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n", 444 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n", count, name,
450 count, name, value); 445 value);
451 } 446 }
452 447
453 if (0 == strcmp (name, "ATS duration")) 448 if (0 == strcmp (name, "ATS duration"))
454 { 449 {
455 current.duration = value; 450 current.duration = value;
456 if (printed == GNUNET_NO) 451 if (printed == GNUNET_NO)
457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n", 452 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n", count, name,
458 count, name, value); 453 value);
459 } 454 }
460 if (0 == strcmp (name, "ATS state")) 455 if (0 == strcmp (name, "ATS state"))
461 { 456 {
@@ -485,8 +480,8 @@ stats_cb (void *cls,
485 break; 480 break;
486 } 481 }
487 if (printed == GNUNET_NO) 482 if (printed == GNUNET_NO)
488 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] ATS state: %s\n", count,
489 "[%i] ATS state: %s\n", count, cont); 484 cont);
490 } 485 }
491 } 486 }
492 return GNUNET_OK; 487 return GNUNET_OK;
@@ -500,16 +495,21 @@ stats_get_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
500 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 495 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
501 return; 496 return;
502 497
503 s_time = GNUNET_STATISTICS_get (stats, "transport", "ATS timestamp", 498 s_time =
504 TIMEOUT, NULL, &stats_cb, NULL); 499 GNUNET_STATISTICS_get (stats, "transport", "ATS timestamp", TIMEOUT, NULL,
505 s_solution = GNUNET_STATISTICS_get (stats, "transport", "ATS solution", 500 &stats_cb, NULL);
506 TIMEOUT, NULL, &stats_cb, NULL); 501 s_solution =
507 s_duration = GNUNET_STATISTICS_get (stats, "transport", "ATS duration", 502 GNUNET_STATISTICS_get (stats, "transport", "ATS solution", TIMEOUT, NULL,
508 TIMEOUT, NULL, &stats_cb, NULL); 503 &stats_cb, NULL);
509 s_peers = GNUNET_STATISTICS_get (stats, "transport", "ATS peers", 504 s_duration =
510 TIMEOUT, NULL, &stats_cb, NULL); 505 GNUNET_STATISTICS_get (stats, "transport", "ATS duration", TIMEOUT, NULL,
511 s_mechs = GNUNET_STATISTICS_get (stats, "transport", "ATS mechanisms", 506 &stats_cb, NULL);
512 TIMEOUT, NULL, &stats_cb, NULL); 507 s_peers =
508 GNUNET_STATISTICS_get (stats, "transport", "ATS peers", TIMEOUT, NULL,
509 &stats_cb, NULL);
510 s_mechs =
511 GNUNET_STATISTICS_get (stats, "transport", "ATS mechanisms", TIMEOUT,
512 NULL, &stats_cb, NULL);
513 s_invalid = 513 s_invalid =
514 GNUNET_STATISTICS_get (stats, "transport", "ATS invalid solutions", 514 GNUNET_STATISTICS_get (stats, "transport", "ATS invalid solutions",
515 TIMEOUT, NULL, &stats_cb, NULL); 515 TIMEOUT, NULL, &stats_cb, NULL);
@@ -592,8 +592,7 @@ send_task_f (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
592 } 592 }
593 593
594 if (send_msg == GNUNET_YES) 594 if (send_msg == GNUNET_YES)
595 t = GNUNET_TRANSPORT_notify_transmit_ready (th, 595 t = GNUNET_TRANSPORT_notify_transmit_ready (th, &master_deamon->id,
596 &master_deamon->id,
597 sizeof (struct TestMessage), 0, 596 sizeof (struct TestMessage), 0,
598 SEND_TIMEOUT, 597 SEND_TIMEOUT,
599 &send_dummy_data_task, NULL); 598 &send_dummy_data_task, NULL);
@@ -605,8 +604,7 @@ send_task_f (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
605} 604}
606 605
607static void 606static void
608notify_connect (void *cls, 607notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
609 const struct GNUNET_PeerIdentity *peer,
610 const struct GNUNET_TRANSPORT_ATS_Information *ats, 608 const struct GNUNET_TRANSPORT_ATS_Information *ats,
611 uint32_t ats_count) 609 uint32_t ats_count)
612{ 610{
@@ -633,10 +631,8 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
633} 631}
634 632
635static void 633static void
636daemon_connect_cb (void *cls, 634daemon_connect_cb (void *cls, const struct GNUNET_PeerIdentity *first,
637 const struct GNUNET_PeerIdentity *first, 635 const struct GNUNET_PeerIdentity *second, uint32_t distance,
638 const struct GNUNET_PeerIdentity *second,
639 uint32_t distance,
640 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 636 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
641 const struct GNUNET_CONFIGURATION_Handle *second_cfg, 637 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
642 struct GNUNET_TESTING_Daemon *first_daemon, 638 struct GNUNET_TESTING_Daemon *first_daemon,
@@ -647,20 +643,16 @@ daemon_connect_cb (void *cls,
647 char *secondc = strdup (GNUNET_i2s (second)); 643 char *secondc = strdup (GNUNET_i2s (second));
648 644
649 connected++; 645 connected++;
650 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 646 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected peers `%s'<->`%s' (%i/%i)\n",
651 "Connected peers `%s'<->`%s' (%i/%i)\n",
652 firstc, secondc, connected, peers - 1); 647 firstc, secondc, connected, peers - 1);
653 GNUNET_free (firstc); 648 GNUNET_free (firstc);
654 GNUNET_free (secondc); 649 GNUNET_free (secondc);
655 650
656 if (((first_daemon == ping_deamon) || 651 if (((first_daemon == ping_deamon) || (second_daemon == ping_deamon)) &&
657 (second_daemon == ping_deamon)) &&
658 (master_deamon != NULL) && (ping_deamon != NULL)) 652 (master_deamon != NULL) && (ping_deamon != NULL))
659 { 653 {
660 th = GNUNET_TRANSPORT_connect (ping_deamon->cfg, 654 th = GNUNET_TRANSPORT_connect (ping_deamon->cfg, &ping_deamon->id, NULL,
661 &ping_deamon->id, 655 NULL, &notify_connect, &notify_disconnect);
662 NULL, NULL,
663 &notify_connect, &notify_disconnect);
664 force_q_updates = GNUNET_YES; 656 force_q_updates = GNUNET_YES;
665 send_msg = GNUNET_YES; 657 send_msg = GNUNET_YES;
666 } 658 }
@@ -669,8 +661,7 @@ daemon_connect_cb (void *cls,
669 661
670 662
671static void 663static void
672daemon_start_cb (void *cls, 664daemon_start_cb (void *cls, const struct GNUNET_PeerIdentity *id,
673 const struct GNUNET_PeerIdentity *id,
674 const struct GNUNET_CONFIGURATION_Handle *cfg, 665 const struct GNUNET_CONFIGURATION_Handle *cfg,
675 struct GNUNET_TESTING_Daemon *d, const char *emsg) 666 struct GNUNET_TESTING_Daemon *d, const char *emsg)
676{ 667{
@@ -693,8 +684,8 @@ daemon_start_cb (void *cls,
693 684
694 if (master_deamon == NULL) 685 if (master_deamon == NULL)
695 { 686 {
696 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Master peer `%s' '%s'\n",
697 "Master peer `%s' '%s'\n", GNUNET_i2s (id), d->cfgfile); 688 GNUNET_i2s (id), d->cfgfile);
698 master_deamon = d; 689 master_deamon = d;
699 stats = GNUNET_STATISTICS_create ("transport", master_deamon->cfg); 690 stats = GNUNET_STATISTICS_create ("transport", master_deamon->cfg);
700 GNUNET_assert (stats != NULL); 691 GNUNET_assert (stats != NULL);
@@ -702,13 +693,10 @@ daemon_start_cb (void *cls,
702 } 693 }
703 else 694 else
704 { 695 {
705 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 696 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer `%s'\n",
706 "Connecting peer `%s'\n",
707 GNUNET_i2s (id), GNUNET_i2s (&master_deamon->id)); 697 GNUNET_i2s (id), GNUNET_i2s (&master_deamon->id));
708 GNUNET_TESTING_daemons_connect (d, 698 GNUNET_TESTING_daemons_connect (d, master_deamon, TIMEOUT, 0, GNUNET_YES,
709 master_deamon, 699 &daemon_connect_cb, NULL);
710 TIMEOUT,
711 0, GNUNET_YES, &daemon_connect_cb, NULL);
712 } 700 }
713 701
714 if (peers_left == 0) 702 if (peers_left == 0)
@@ -716,8 +704,8 @@ daemon_start_cb (void *cls,
716 if (ping_deamon == NULL) 704 if (ping_deamon == NULL)
717 { 705 {
718 ping_deamon = d; 706 ping_deamon = d;
719 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 707 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ping peer `%s' '%s'\n",
720 "Ping peer `%s' '%s'\n", GNUNET_i2s (id), d->cfgfile); 708 GNUNET_i2s (id), d->cfgfile);
721 } 709 }
722 710
723 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers started successfully!\n"); 711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers started successfully!\n");
@@ -735,9 +723,8 @@ daemon_start_cb (void *cls,
735 723
736 724
737static void 725static void
738run (void *cls, 726run (void *cls, char *const *args, const char *cfgfile,
739 char *const *args, 727 const struct GNUNET_CONFIGURATION_Handle *cfg)
740 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
741{ 728{
742 ok = 1; 729 ok = 1;
743 measurement_started = GNUNET_NO; 730 measurement_started = GNUNET_NO;
@@ -748,9 +735,8 @@ run (void *cls,
748 pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of peers */ 735 pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of peers */
749 peers_left, /* Number of outstanding connections */ 736 peers_left, /* Number of outstanding connections */
750 peers_left, /* Number of parallel ssh connections, or peers being started at once */ 737 peers_left, /* Number of parallel ssh connections, or peers being started at once */
751 TIMEOUT, 738 TIMEOUT, NULL, NULL, &daemon_start_cb,
752 NULL, NULL, 739 NULL, NULL, NULL, NULL);
753 &daemon_start_cb, NULL, NULL, NULL, NULL);
754 GNUNET_assert (pg != NULL); 740 GNUNET_assert (pg != NULL);
755} 741}
756 742
@@ -769,9 +755,9 @@ check ()
769 struct GNUNET_GETOPT_CommandLineOption options[] = { 755 struct GNUNET_GETOPT_CommandLineOption options[] = {
770 GNUNET_GETOPT_OPTION_END 756 GNUNET_GETOPT_OPTION_END
771 }; 757 };
772 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 758 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
773 argv, "test_transport_ats_multiple_peers", "nohelp", 759 "test_transport_ats_multiple_peers", "nohelp", options,
774 options, &run, &ok); 760 &run, &ok);
775 return ok; 761 return ok;
776} 762}
777 763
diff --git a/src/transport/test_transport_testing.c b/src/transport/test_transport_testing.c
index cd5d7ed2c..85c05df4b 100644
--- a/src/transport/test_transport_testing.c
+++ b/src/transport/test_transport_testing.c
@@ -86,15 +86,14 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
86{ 86{
87 char *p1_c = strdup (GNUNET_i2s (&p1->id)); 87 char *p1_c = strdup (GNUNET_i2s (&p1->id));
88 88
89 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers connected: %s <-> %s\n", 89 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers connected: %s <-> %s\n", p1_c,
90 p1_c, GNUNET_i2s (&p2->id)); 90 GNUNET_i2s (&p2->id));
91 GNUNET_free (p1_c); 91 GNUNET_free (p1_c);
92 end (); 92 end ();
93} 93}
94 94
95static void 95static void
96notify_connect (void *cls, 96notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
97 const struct GNUNET_PeerIdentity *peer,
98 const struct GNUNET_TRANSPORT_ATS_Information *ats, 97 const struct GNUNET_TRANSPORT_ATS_Information *ats,
99 uint32_t ats_count) 98 uint32_t ats_count)
100{ 99{
@@ -111,8 +110,7 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
111} 110}
112 111
113static void 112static void
114notify_receive (void *cls, 113notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
115 const struct GNUNET_PeerIdentity *peer,
116 const struct GNUNET_MessageHeader *message, 114 const struct GNUNET_MessageHeader *message,
117 const struct GNUNET_TRANSPORT_ATS_Information *ats, 115 const struct GNUNET_TRANSPORT_ATS_Information *ats,
118 uint32_t ats_count) 116 uint32_t ats_count)
@@ -122,22 +120,19 @@ notify_receive (void *cls,
122 120
123 121
124static void 122static void
125run (void *cls, 123run (void *cls, char *const *args, const char *cfgfile,
126 char *const *args, 124 const struct GNUNET_CONFIGURATION_Handle *cfg)
127 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
128{ 125{
129 timeout_task = 126 timeout_task =
130 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &end_badly, NULL); 127 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &end_badly, NULL);
131 128
132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting peer\n"); 129 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting peer\n");
133 p1 = GNUNET_TRANSPORT_TESTING_start_peer ("test_transport_api_tcp_peer1.conf", 130 p1 = GNUNET_TRANSPORT_TESTING_start_peer ("test_transport_api_tcp_peer1.conf",
134 &notify_receive, 131 &notify_receive, &notify_connect,
135 &notify_connect,
136 &notify_disconnect, p1); 132 &notify_disconnect, p1);
137 133
138 p2 = GNUNET_TRANSPORT_TESTING_start_peer ("test_transport_api_tcp_peer2.conf", 134 p2 = GNUNET_TRANSPORT_TESTING_start_peer ("test_transport_api_tcp_peer2.conf",
139 &notify_receive, 135 &notify_receive, &notify_connect,
140 &notify_connect,
141 &notify_disconnect, p2); 136 &notify_disconnect, p2);
142 137
143 if (p1 != NULL) 138 if (p1 != NULL)
@@ -185,9 +180,8 @@ main (int argc, char *argv[])
185 GNUNET_GETOPT_OPTION_END 180 GNUNET_GETOPT_OPTION_END
186 }; 181 };
187 182
188 GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1, 183 GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1, argv_1,
189 argv_1, "test_transport_testing", "nohelp", 184 "test_transport_testing", "nohelp", options, &run, &ret);
190 options, &run, &ret);
191 185
192 return ret; 186 return ret;
193} 187}
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c
index e6fcabb48..62544584c 100644
--- a/src/transport/transport-testing.c
+++ b/src/transport/transport-testing.c
@@ -41,14 +41,13 @@ struct ConnectingContext
41 int p2_c; 41 int p2_c;
42}; 42};
43 43
44static void 44static void exchange_hello_last (void *cb_cls,
45exchange_hello_last (void *cb_cls, const struct GNUNET_MessageHeader *message); 45 const struct GNUNET_MessageHeader *message);
46static void 46static void exchange_hello (void *cb_cls,
47exchange_hello (void *cb_cls, const struct GNUNET_MessageHeader *message); 47 const struct GNUNET_MessageHeader *message);
48 48
49static void 49static void
50notify_connect_internal (void *cls, 50notify_connect_internal (void *cls, const struct GNUNET_PeerIdentity *peer,
51 const struct GNUNET_PeerIdentity *peer,
52 const struct GNUNET_TRANSPORT_ATS_Information *ats, 51 const struct GNUNET_TRANSPORT_ATS_Information *ats,
53 uint32_t ats_count) 52 uint32_t ats_count)
54{ 53{
@@ -93,8 +92,7 @@ notify_connect_internal (void *cls,
93} 92}
94 93
95static void 94static void
96notify_connect (void *cls, 95notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
97 const struct GNUNET_PeerIdentity *peer,
98 const struct GNUNET_TRANSPORT_ATS_Information *ats, 96 const struct GNUNET_TRANSPORT_ATS_Information *ats,
99 uint32_t ats_count) 97 uint32_t ats_count)
100{ 98{
@@ -118,8 +116,7 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
118} 116}
119 117
120static void 118static void
121notify_receive (void *cls, 119notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
122 const struct GNUNET_PeerIdentity *peer,
123 const struct GNUNET_MessageHeader *message, 120 const struct GNUNET_MessageHeader *message,
124 const struct GNUNET_TRANSPORT_ATS_Information *ats, 121 const struct GNUNET_TRANSPORT_ATS_Information *ats,
125 uint32_t ats_count) 122 uint32_t ats_count)
@@ -188,8 +185,8 @@ try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
188 GNUNET_TRANSPORT_try_connect (cc->th_p1, &p2->id); 185 GNUNET_TRANSPORT_try_connect (cc->th_p1, &p2->id);
189 GNUNET_TRANSPORT_try_connect (cc->th_p2, &p1->id); 186 GNUNET_TRANSPORT_try_connect (cc->th_p2, &p1->id);
190 187
191 cc->tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 188 cc->tct =
192 &try_connect, cc); 189 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect, cc);
193} 190}
194 191
195 192
@@ -218,14 +215,15 @@ GNUNET_TRANSPORT_TESTING_start_peer (const char *cfgname,
218 &p->servicehome); 215 &p->servicehome);
219 if (NULL != p->servicehome) 216 if (NULL != p->servicehome)
220 GNUNET_DISK_directory_remove (p->servicehome); 217 GNUNET_DISK_directory_remove (p->servicehome);
221 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 218 p->arm_proc =
222 "gnunet-service-arm", "-c", cfgname, 219 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
220 "gnunet-service-arm", "-c", cfgname,
223#if VERBOSE_PEERS 221#if VERBOSE_PEERS
224 "-L", "DEBUG", 222 "-L", "DEBUG",
225#else 223#else
226 "-L", "ERROR", 224 "-L", "ERROR",
227#endif 225#endif
228 NULL); 226 NULL);
229 p->nc = nc; 227 p->nc = nc;
230 p->nd = nd; 228 p->nd = nd;
231 p->rec = rec; 229 p->rec = rec;
@@ -234,10 +232,9 @@ GNUNET_TRANSPORT_TESTING_start_peer (const char *cfgname,
234 else 232 else
235 p->cb_cls = p; 233 p->cb_cls = p;
236 234
237 p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, 235 p->th =
238 p, 236 GNUNET_TRANSPORT_connect (p->cfg, NULL, p, &notify_receive,
239 &notify_receive, 237 &notify_connect, &notify_disconnect);
240 &notify_connect, &notify_disconnect);
241 GNUNET_assert (p->th != NULL); 238 GNUNET_assert (p->th != NULL);
242 return p; 239 return p;
243} 240}
@@ -296,13 +293,13 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct PeerContext *p1,
296 cc->cb = cb; 293 cc->cb = cb;
297 cc->cb_cls = cb_cls; 294 cc->cb_cls = cb_cls;
298 295
299 cc->th_p1 = GNUNET_TRANSPORT_connect (cc->p1->cfg, NULL, 296 cc->th_p1 =
300 cc, 297 GNUNET_TRANSPORT_connect (cc->p1->cfg, NULL, cc, NULL,
301 NULL, &notify_connect_internal, NULL); 298 &notify_connect_internal, NULL);
302 299
303 cc->th_p2 = GNUNET_TRANSPORT_connect (cc->p2->cfg, NULL, 300 cc->th_p2 =
304 cc, 301 GNUNET_TRANSPORT_connect (cc->p2->cfg, NULL, cc, NULL,
305 NULL, &notify_connect_internal, NULL); 302 &notify_connect_internal, NULL);
306 303
307 GNUNET_assert (cc->th_p1 != NULL); 304 GNUNET_assert (cc->th_p1 != NULL);
308 GNUNET_assert (cc->th_p2 != NULL); 305 GNUNET_assert (cc->th_p2 != NULL);
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c
index 2cdaacad6..b732871ca 100644
--- a/src/transport/transport_api.c
+++ b/src/transport/transport_api.c
@@ -304,8 +304,8 @@ static void schedule_transmission (struct GNUNET_TRANSPORT_Handle *h);
304 * 304 *
305 * @param h transport service to reconnect 305 * @param h transport service to reconnect
306 */ 306 */
307static void 307static void disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle
308disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h); 308 *h);
309 309
310 310
311/** 311/**
@@ -335,8 +335,8 @@ neighbour_add (struct GNUNET_TRANSPORT_Handle *h,
335 struct Neighbour *n; 335 struct Neighbour *n;
336 336
337#if DEBUG_TRANSPORT 337#if DEBUG_TRANSPORT
338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating entry for neighbour `%4s'.\n",
339 "Creating entry for neighbour `%4s'.\n", GNUNET_i2s (pid)); 339 GNUNET_i2s (pid));
340#endif 340#endif
341 n = GNUNET_malloc (sizeof (struct Neighbour)); 341 n = GNUNET_malloc (sizeof (struct Neighbour));
342 n->id = *pid; 342 n->id = *pid;
@@ -347,8 +347,7 @@ neighbour_add (struct GNUNET_TRANSPORT_Handle *h,
347 MAX_BANDWIDTH_CARRY_S); 347 MAX_BANDWIDTH_CARRY_S);
348 GNUNET_assert (GNUNET_OK == 348 GNUNET_assert (GNUNET_OK ==
349 GNUNET_CONTAINER_multihashmap_put (h->neighbours, 349 GNUNET_CONTAINER_multihashmap_put (h->neighbours,
350 &pid->hashPubKey, 350 &pid->hashPubKey, n,
351 n,
352 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 351 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
353 return n; 352 return n;
354} 353}
@@ -375,8 +374,8 @@ neighbour_delete (void *cls, const GNUNET_HashCode * key, void *value)
375 GNUNET_assert (NULL == n->th); 374 GNUNET_assert (NULL == n->th);
376 GNUNET_assert (NULL == n->hn); 375 GNUNET_assert (NULL == n->hn);
377 GNUNET_assert (GNUNET_YES == 376 GNUNET_assert (GNUNET_YES ==
378 GNUNET_CONTAINER_multihashmap_remove (handle->neighbours, 377 GNUNET_CONTAINER_multihashmap_remove (handle->neighbours, key,
379 key, n)); 378 n));
380 GNUNET_free (n); 379 GNUNET_free (n);
381 return GNUNET_YES; 380 return GNUNET_YES;
382} 381}
@@ -414,8 +413,8 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
414 disconnect_and_schedule_reconnect (h); 413 disconnect_and_schedule_reconnect (h);
415 return; 414 return;
416 } 415 }
417 GNUNET_CLIENT_receive (h->client, 416 GNUNET_CLIENT_receive (h->client, &demultiplexer, h,
418 &demultiplexer, h, GNUNET_TIME_UNIT_FOREVER_REL); 417 GNUNET_TIME_UNIT_FOREVER_REL);
419 size = ntohs (msg->size); 418 size = ntohs (msg->size);
420 switch (ntohs (msg->type)) 419 switch (ntohs (msg->type))
421 { 420 {
@@ -428,8 +427,8 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
428 } 427 }
429#if DEBUG_TRANSPORT 428#if DEBUG_TRANSPORT
430 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 429 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
431 "Receiving (my own) `%s' message, I am `%4s'.\n", 430 "Receiving (my own) `%s' message, I am `%4s'.\n", "HELLO",
432 "HELLO", GNUNET_i2s (&me)); 431 GNUNET_i2s (&me));
433#endif 432#endif
434 GNUNET_free_non_null (h->my_hello); 433 GNUNET_free_non_null (h->my_hello);
435 h->my_hello = NULL; 434 h->my_hello = NULL;
@@ -465,8 +464,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
465 break; 464 break;
466 } 465 }
467#if DEBUG_TRANSPORT 466#if DEBUG_TRANSPORT
468 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving `%s' message for `%4s'.\n",
469 "Receiving `%s' message for `%4s'.\n",
470 "CONNECT", GNUNET_i2s (&cim->id)); 468 "CONNECT", GNUNET_i2s (&cim->id));
471#endif 469#endif
472 n = neighbour_find (h, &cim->id); 470 n = neighbour_find (h, &cim->id);
@@ -488,8 +486,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
488 dim = (const struct DisconnectInfoMessage *) msg; 486 dim = (const struct DisconnectInfoMessage *) msg;
489 GNUNET_break (ntohl (dim->reserved) == 0); 487 GNUNET_break (ntohl (dim->reserved) == 0);
490#if DEBUG_TRANSPORT_DISCONNECT 488#if DEBUG_TRANSPORT_DISCONNECT
491 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving `%s' message for `%4s'.\n",
492 "Receiving `%s' message for `%4s'.\n",
493 "DISCONNECT", GNUNET_i2s (&dim->peer)); 490 "DISCONNECT", GNUNET_i2s (&dim->peer));
494#endif 491#endif
495 n = neighbour_find (h, &dim->peer); 492 n = neighbour_find (h, &dim->peer);
@@ -551,8 +548,8 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
551 } 548 }
552#if DEBUG_TRANSPORT 549#if DEBUG_TRANSPORT
553 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
554 "Received message of type %u from `%4s'.\n", 551 "Received message of type %u from `%4s'.\n", ntohs (imm->type),
555 ntohs (imm->type), GNUNET_i2s (&im->peer)); 552 GNUNET_i2s (&im->peer));
556#endif 553#endif
557 n = neighbour_find (h, &im->peer); 554 n = neighbour_find (h, &im->peer);
558 if (n == NULL) 555 if (n == NULL)
@@ -565,8 +562,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
565 break; 562 break;
566 default: 563 default:
567 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 564 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
568 _ 565 _("Received unexpected message of type %u in %s:%u\n"),
569 ("Received unexpected message of type %u in %s:%u\n"),
570 ntohs (msg->type), __FILE__, __LINE__); 566 ntohs (msg->type), __FILE__, __LINE__);
571 GNUNET_break (0); 567 GNUNET_break (0);
572 break; 568 break;
@@ -663,17 +659,17 @@ transport_notify_ready (void *cls, size_t size, void *buf)
663 th = n->th; 659 th = n->th;
664 if (th->notify_size + sizeof (struct OutboundMessage) > size) 660 if (th->notify_size + sizeof (struct OutboundMessage) > size)
665 break; /* does not fit */ 661 break; /* does not fit */
666 if (GNUNET_BANDWIDTH_tracker_get_delay 662 if (GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, th->notify_size).
667 (&n->out_tracker, th->notify_size).rel_value > 0) 663 rel_value > 0)
668 break; /* too early */ 664 break; /* too early */
669 GNUNET_assert (n == GNUNET_CONTAINER_heap_remove_root (h->ready_heap)); 665 GNUNET_assert (n == GNUNET_CONTAINER_heap_remove_root (h->ready_heap));
670 n->hn = NULL; 666 n->hn = NULL;
671 n->th = NULL; 667 n->th = NULL;
672 n->is_ready = GNUNET_NO; 668 n->is_ready = GNUNET_NO;
673 GNUNET_assert (size >= sizeof (struct OutboundMessage)); 669 GNUNET_assert (size >= sizeof (struct OutboundMessage));
674 mret = th->notify (th->notify_cls, 670 mret =
675 size - sizeof (struct OutboundMessage), 671 th->notify (th->notify_cls, size - sizeof (struct OutboundMessage),
676 &cbuf[ret + sizeof (struct OutboundMessage)]); 672 &cbuf[ret + sizeof (struct OutboundMessage)]);
677 GNUNET_assert (mret <= size - sizeof (struct OutboundMessage)); 673 GNUNET_assert (mret <= size - sizeof (struct OutboundMessage));
678 if (mret != 0) 674 if (mret != 0)
679 { 675 {
@@ -756,11 +752,10 @@ schedule_transmission_task (void *cls,
756 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling notify_transmit_ready\n"); 752 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling notify_transmit_ready\n");
757#endif 753#endif
758 h->cth = 754 h->cth =
759 GNUNET_CLIENT_notify_transmit_ready (h->client, 755 GNUNET_CLIENT_notify_transmit_ready (h->client, size,
760 size,
761 GNUNET_TIME_UNIT_FOREVER_REL, 756 GNUNET_TIME_UNIT_FOREVER_REL,
762 GNUNET_NO, 757 GNUNET_NO, &transport_notify_ready,
763 &transport_notify_ready, h); 758 h);
764 GNUNET_assert (NULL != h->cth); 759 GNUNET_assert (NULL != h->cth);
765} 760}
766 761
@@ -794,8 +789,8 @@ schedule_transmission (struct GNUNET_TRANSPORT_Handle *h)
794 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 789 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
795 "Scheduling next transmission to service in %llu ms\n", 790 "Scheduling next transmission to service in %llu ms\n",
796 (unsigned long long) delay.rel_value); 791 (unsigned long long) delay.rel_value);
797 h->quota_task = GNUNET_SCHEDULER_add_delayed (delay, 792 h->quota_task =
798 &schedule_transmission_task, h); 793 GNUNET_SCHEDULER_add_delayed (delay, &schedule_transmission_task, h);
799} 794}
800 795
801 796
@@ -809,8 +804,7 @@ schedule_transmission (struct GNUNET_TRANSPORT_Handle *h)
809 * @param notify_cls closure for notify 804 * @param notify_cls closure for notify
810 */ 805 */
811static void 806static void
812schedule_control_transmit (struct GNUNET_TRANSPORT_Handle *h, 807schedule_control_transmit (struct GNUNET_TRANSPORT_Handle *h, size_t size,
813 size_t size,
814 GNUNET_CONNECTION_TransmitReadyNotify notify, 808 GNUNET_CONNECTION_TransmitReadyNotify notify,
815 void *notify_cls) 809 void *notify_cls)
816{ 810{
@@ -861,8 +855,8 @@ send_start (void *cls, size_t size, void *buf)
861 s.do_check = htonl (h->check_self); 855 s.do_check = htonl (h->check_self);
862 s.self = h->self; 856 s.self = h->self;
863 memcpy (buf, &s, sizeof (struct StartMessage)); 857 memcpy (buf, &s, sizeof (struct StartMessage));
864 GNUNET_CLIENT_receive (h->client, 858 GNUNET_CLIENT_receive (h->client, &demultiplexer, h,
865 &demultiplexer, h, GNUNET_TIME_UNIT_FOREVER_REL); 859 GNUNET_TIME_UNIT_FOREVER_REL);
866 return sizeof (struct StartMessage); 860 return sizeof (struct StartMessage);
867} 861}
868 862
@@ -936,8 +930,8 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h)
936 "Scheduling task to reconnect to transport service in %llu ms.\n", 930 "Scheduling task to reconnect to transport service in %llu ms.\n",
937 h->reconnect_delay.rel_value); 931 h->reconnect_delay.rel_value);
938#endif 932#endif
939 h->reconnect_task 933 h->reconnect_task =
940 = GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); 934 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
941 if (h->reconnect_delay.rel_value == 0) 935 if (h->reconnect_delay.rel_value == 0)
942 { 936 {
943 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS; 937 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
@@ -945,8 +939,8 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h)
945 else 939 else
946 { 940 {
947 h->reconnect_delay = GNUNET_TIME_relative_multiply (h->reconnect_delay, 2); 941 h->reconnect_delay = GNUNET_TIME_relative_multiply (h->reconnect_delay, 2);
948 h->reconnect_delay = GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, 942 h->reconnect_delay =
949 h->reconnect_delay); 943 GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, h->reconnect_delay);
950 } 944 }
951} 945}
952 946
@@ -990,8 +984,8 @@ send_set_quota (void *cls, size_t size, void *buf)
990 } 984 }
991#if DEBUG_TRANSPORT 985#if DEBUG_TRANSPORT
992 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 986 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
993 "Transmitting `%s' request with respect to `%4s'.\n", 987 "Transmitting `%s' request with respect to `%4s'.\n", "SET_QUOTA",
994 "SET_QUOTA", GNUNET_i2s (&sqc->target)); 988 GNUNET_i2s (&sqc->target));
995#endif 989#endif
996 GNUNET_assert (size >= sizeof (struct QuotaSetMessage)); 990 GNUNET_assert (size >= sizeof (struct QuotaSetMessage));
997 msg.header.size = htons (sizeof (struct QuotaSetMessage)); 991 msg.header.size = htons (sizeof (struct QuotaSetMessage));
@@ -1038,8 +1032,7 @@ GNUNET_TRANSPORT_set_quota (struct GNUNET_TRANSPORT_Handle *handle,
1038 (unsigned int) n->out_tracker.available_bytes_per_s__, 1032 (unsigned int) n->out_tracker.available_bytes_per_s__,
1039 (unsigned int) ntohl (quota_out.value__), GNUNET_i2s (target)); 1033 (unsigned int) ntohl (quota_out.value__), GNUNET_i2s (target));
1040 else 1034 else
1041 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1035 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Quota remains at %u for peer `%s'\n",
1042 "Quota remains at %u for peer `%s'\n",
1043 (unsigned int) n->out_tracker.available_bytes_per_s__, 1036 (unsigned int) n->out_tracker.available_bytes_per_s__,
1044 GNUNET_i2s (target)); 1037 GNUNET_i2s (target));
1045#endif 1038#endif
@@ -1047,8 +1040,7 @@ GNUNET_TRANSPORT_set_quota (struct GNUNET_TRANSPORT_Handle *handle,
1047 sqc = GNUNET_malloc (sizeof (struct SetQuotaContext)); 1040 sqc = GNUNET_malloc (sizeof (struct SetQuotaContext));
1048 sqc->target = *target; 1041 sqc->target = *target;
1049 sqc->quota_in = quota_in; 1042 sqc->quota_in = quota_in;
1050 schedule_control_transmit (handle, 1043 schedule_control_transmit (handle, sizeof (struct QuotaSetMessage),
1051 sizeof (struct QuotaSetMessage),
1052 &send_set_quota, sqc); 1044 &send_set_quota, sqc);
1053} 1045}
1054 1046
@@ -1257,8 +1249,7 @@ GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_Handle *handle,
1257 */ 1249 */
1258struct GNUNET_TRANSPORT_Handle * 1250struct GNUNET_TRANSPORT_Handle *
1259GNUNET_TRANSPORT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 1251GNUNET_TRANSPORT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
1260 const struct GNUNET_PeerIdentity *self, 1252 const struct GNUNET_PeerIdentity *self, void *cls,
1261 void *cls,
1262 GNUNET_TRANSPORT_ReceiveCallback rec, 1253 GNUNET_TRANSPORT_ReceiveCallback rec,
1263 GNUNET_TRANSPORT_NotifyConnect nc, 1254 GNUNET_TRANSPORT_NotifyConnect nc,
1264 GNUNET_TRANSPORT_NotifyDisconnect nd) 1255 GNUNET_TRANSPORT_NotifyDisconnect nd)
diff --git a/src/transport/transport_api_address_iterate.c b/src/transport/transport_api_address_iterate.c
index 4f442fda0..833b82d7e 100644
--- a/src/transport/transport_api_address_iterate.c
+++ b/src/transport/transport_api_address_iterate.c
@@ -110,8 +110,7 @@ peer_address_response_processor (void *cls,
110 return; 110 return;
111 } 111 }
112 /* expect more replies */ 112 /* expect more replies */
113 GNUNET_CLIENT_receive (alucb->client, 113 GNUNET_CLIENT_receive (alucb->client, &peer_address_response_processor, alucb,
114 &peer_address_response_processor, alucb,
115 GNUNET_TIME_absolute_get_remaining (alucb->timeout)); 114 GNUNET_TIME_absolute_get_remaining (alucb->timeout));
116 alucb->cb (alucb->cb_cls, address); 115 alucb->cb (alucb->cb_cls, address);
117} 116}
@@ -154,10 +153,8 @@ GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
154 peer_address_lookup_cb->timeout = abs_timeout; 153 peer_address_lookup_cb->timeout = abs_timeout;
155 peer_address_lookup_cb->client = client; 154 peer_address_lookup_cb->client = client;
156 GNUNET_assert (GNUNET_OK == 155 GNUNET_assert (GNUNET_OK ==
157 GNUNET_CLIENT_transmit_and_get_response (client, 156 GNUNET_CLIENT_transmit_and_get_response (client, &msg.header,
158 &msg.header, 157 timeout, GNUNET_YES,
159 timeout,
160 GNUNET_YES,
161 &peer_address_response_processor, 158 &peer_address_response_processor,
162 peer_address_lookup_cb)); 159 peer_address_lookup_cb));
163} 160}
diff --git a/src/transport/transport_api_address_lookup.c b/src/transport/transport_api_address_lookup.c
index 4aadf10f4..1cbafdab0 100644
--- a/src/transport/transport_api_address_lookup.c
+++ b/src/transport/transport_api_address_lookup.c
@@ -97,8 +97,7 @@ address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
97 return; 97 return;
98 } 98 }
99 /* expect more replies */ 99 /* expect more replies */
100 GNUNET_CLIENT_receive (alucb->client, 100 GNUNET_CLIENT_receive (alucb->client, &address_response_processor, alucb,
101 &address_response_processor, alucb,
102 GNUNET_TIME_absolute_get_remaining (alucb->timeout)); 101 GNUNET_TIME_absolute_get_remaining (alucb->timeout));
103 alucb->cb (alucb->cb_cls, address); 102 alucb->cb (alucb->cb_cls, address);
104} 103}
@@ -119,10 +118,8 @@ address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
119 */ 118 */
120void 119void
121GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, 120GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
122 const char *address, 121 const char *address, size_t addressLen,
123 size_t addressLen, 122 int numeric, const char *nameTrans,
124 int numeric,
125 const char *nameTrans,
126 struct GNUNET_TIME_Relative timeout, 123 struct GNUNET_TIME_Relative timeout,
127 GNUNET_TRANSPORT_AddressLookUpCallback aluc, 124 GNUNET_TRANSPORT_AddressLookUpCallback aluc,
128 void *aluc_cls) 125 void *aluc_cls)
@@ -163,10 +160,8 @@ GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
163 aluCB->timeout = GNUNET_TIME_relative_to_absolute (timeout); 160 aluCB->timeout = GNUNET_TIME_relative_to_absolute (timeout);
164 aluCB->client = client; 161 aluCB->client = client;
165 GNUNET_assert (GNUNET_OK == 162 GNUNET_assert (GNUNET_OK ==
166 GNUNET_CLIENT_transmit_and_get_response (client, 163 GNUNET_CLIENT_transmit_and_get_response (client, &msg->header,
167 &msg->header, 164 timeout, GNUNET_YES,
168 timeout,
169 GNUNET_YES,
170 &address_response_processor, 165 &address_response_processor,
171 aluCB)); 166 aluCB));
172 GNUNET_free (msg); 167 GNUNET_free (msg);
diff --git a/src/transport/transport_api_blacklist.c b/src/transport/transport_api_blacklist.c
index f8f430995..f6852ff01 100644
--- a/src/transport/transport_api_blacklist.c
+++ b/src/transport/transport_api_blacklist.c
@@ -122,8 +122,8 @@ query_handler (void *cls, const struct GNUNET_MessageHeader *msg)
122static void 122static void
123receive (struct GNUNET_TRANSPORT_Blacklist *br) 123receive (struct GNUNET_TRANSPORT_Blacklist *br)
124{ 124{
125 GNUNET_CLIENT_receive (br->client, 125 GNUNET_CLIENT_receive (br->client, &query_handler, br,
126 &query_handler, br, GNUNET_TIME_UNIT_FOREVER_REL); 126 GNUNET_TIME_UNIT_FOREVER_REL);
127} 127}
128 128
129 129
@@ -166,12 +166,12 @@ reconnect (struct GNUNET_TRANSPORT_Blacklist *br)
166 GNUNET_CLIENT_disconnect (br->client, GNUNET_NO); 166 GNUNET_CLIENT_disconnect (br->client, GNUNET_NO);
167 br->client = GNUNET_CLIENT_connect ("transport", br->cfg); 167 br->client = GNUNET_CLIENT_connect ("transport", br->cfg);
168 GNUNET_assert (br->client != NULL); 168 GNUNET_assert (br->client != NULL);
169 br->th = GNUNET_CLIENT_notify_transmit_ready (br->client, 169 br->th =
170 sizeof (struct 170 GNUNET_CLIENT_notify_transmit_ready (br->client,
171 GNUNET_MessageHeader), 171 sizeof (struct GNUNET_MessageHeader),
172 GNUNET_TIME_UNIT_FOREVER_REL, 172 GNUNET_TIME_UNIT_FOREVER_REL,
173 GNUNET_YES, 173 GNUNET_YES, &transmit_blacklist_init,
174 &transmit_blacklist_init, br); 174 br);
175} 175}
176 176
177 177
@@ -212,12 +212,12 @@ transmit_blacklist_reply (void *cls, size_t size, void *buf)
212static void 212static void
213reply (struct GNUNET_TRANSPORT_Blacklist *br) 213reply (struct GNUNET_TRANSPORT_Blacklist *br)
214{ 214{
215 br->th = GNUNET_CLIENT_notify_transmit_ready (br->client, 215 br->th =
216 sizeof (struct 216 GNUNET_CLIENT_notify_transmit_ready (br->client,
217 BlacklistMessage), 217 sizeof (struct BlacklistMessage),
218 GNUNET_TIME_UNIT_FOREVER_REL, 218 GNUNET_TIME_UNIT_FOREVER_REL,
219 GNUNET_NO, 219 GNUNET_NO, &transmit_blacklist_reply,
220 &transmit_blacklist_reply, br); 220 br);
221 if (br->th == NULL) 221 if (br->th == NULL)
222 { 222 {
223 reconnect (br); 223 reconnect (br);
@@ -253,12 +253,12 @@ GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
253 ret = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_Blacklist)); 253 ret = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_Blacklist));
254 ret->client = client; 254 ret->client = client;
255 ret->cfg = cfg; 255 ret->cfg = cfg;
256 ret->th = GNUNET_CLIENT_notify_transmit_ready (client, 256 ret->th =
257 sizeof (struct 257 GNUNET_CLIENT_notify_transmit_ready (client,
258 GNUNET_MessageHeader), 258 sizeof (struct GNUNET_MessageHeader),
259 GNUNET_TIME_UNIT_FOREVER_REL, 259 GNUNET_TIME_UNIT_FOREVER_REL,
260 GNUNET_YES, 260 GNUNET_YES, &transmit_blacklist_init,
261 &transmit_blacklist_init, ret); 261 ret);
262 return ret; 262 return ret;
263} 263}
264 264
diff --git a/src/transport/transport_api_peer_address_lookup.c b/src/transport/transport_api_peer_address_lookup.c
index 50536b47d..c84874b4b 100644
--- a/src/transport/transport_api_peer_address_lookup.c
+++ b/src/transport/transport_api_peer_address_lookup.c
@@ -110,8 +110,7 @@ peer_address_response_processor (void *cls,
110 return; 110 return;
111 } 111 }
112 /* expect more replies */ 112 /* expect more replies */
113 GNUNET_CLIENT_receive (alucb->client, 113 GNUNET_CLIENT_receive (alucb->client, &peer_address_response_processor, alucb,
114 &peer_address_response_processor, alucb,
115 GNUNET_TIME_absolute_get_remaining (alucb->timeout)); 114 GNUNET_TIME_absolute_get_remaining (alucb->timeout));
116 alucb->cb (alucb->cb_cls, address); 115 alucb->cb (alucb->cb_cls, address);
117} 116}
@@ -155,10 +154,8 @@ GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle
155 peer_address_lookup_cb->timeout = GNUNET_TIME_relative_to_absolute (timeout); 154 peer_address_lookup_cb->timeout = GNUNET_TIME_relative_to_absolute (timeout);
156 peer_address_lookup_cb->client = client; 155 peer_address_lookup_cb->client = client;
157 GNUNET_assert (GNUNET_OK == 156 GNUNET_assert (GNUNET_OK ==
158 GNUNET_CLIENT_transmit_and_get_response (client, 157 GNUNET_CLIENT_transmit_and_get_response (client, &msg.header,
159 &msg.header, 158 timeout, GNUNET_YES,
160 timeout,
161 GNUNET_YES,
162 &peer_address_response_processor, 159 &peer_address_response_processor,
163 peer_address_lookup_cb)); 160 peer_address_lookup_cb));
164} 161}
diff --git a/src/transport/wlan/radiotap-parser.c b/src/transport/wlan/radiotap-parser.c
index 51dfd7107..ab75524f2 100644
--- a/src/transport/wlan/radiotap-parser.c
+++ b/src/transport/wlan/radiotap-parser.c
@@ -62,14 +62,14 @@ ieee80211_radiotap_iterator_init (struct ieee80211_radiotap_iterator *iterator,
62 iterator->max_length = le16_to_cpu (radiotap_header->it_len); 62 iterator->max_length = le16_to_cpu (radiotap_header->it_len);
63 iterator->arg_index = 0; 63 iterator->arg_index = 0;
64 iterator->bitmap_shifter = le32_to_cpu (radiotap_header->it_present); 64 iterator->bitmap_shifter = le32_to_cpu (radiotap_header->it_present);
65 iterator->arg = ((u8 *) radiotap_header) + 65 iterator->arg =
66 sizeof (struct ieee80211_radiotap_header); 66 ((u8 *) radiotap_header) + sizeof (struct ieee80211_radiotap_header);
67 iterator->this_arg = 0; 67 iterator->this_arg = 0;
68 68
69 /* find payload start allowing for extended bitmap(s) */ 69 /* find payload start allowing for extended bitmap(s) */
70 70
71 if (unlikely (iterator->bitmap_shifter & 71 if (unlikely
72 IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK)) 72 (iterator->bitmap_shifter & IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK))
73 { 73 {
74 while (le32_to_cpu (*((u32 *) iterator->arg)) & 74 while (le32_to_cpu (*((u32 *) iterator->arg)) &
75 IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK) 75 IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK)
@@ -190,13 +190,14 @@ ieee80211_radiotap_iterator_next (struct ieee80211_radiotap_iterator *iterator)
190 * kind of boundary. 190 * kind of boundary.
191 */ 191 */
192 192
193 if ((((void *) iterator->arg) - ((void *) iterator->rtheader)) & 193 if ((((void *) iterator->arg) -
194 ((rt_sizes[iterator->arg_index] >> 4) - 1)) 194 ((void *) iterator->
195 rtheader)) & ((rt_sizes[iterator->arg_index] >> 4) - 1))
195 iterator->arg_index += 196 iterator->arg_index +=
196 (rt_sizes[iterator->arg_index] >> 4) - 197 (rt_sizes[iterator->arg_index] >> 4) -
197 ((((void *) iterator->arg) - 198 ((((void *) iterator->arg) -
198 ((void *) iterator->rtheader)) & 199 ((void *) iterator->
199 ((rt_sizes[iterator->arg_index] >> 4) - 1)); 200 rtheader)) & ((rt_sizes[iterator->arg_index] >> 4) - 1));
200 201
201 /* 202 /*
202 * this is what we will return to user, but we need to 203 * this is what we will return to user, but we need to
diff --git a/src/util/bandwidth.c b/src/util/bandwidth.c
index d138ffba1..95ff4bfff 100644
--- a/src/util/bandwidth.c
+++ b/src/util/bandwidth.c
@@ -41,8 +41,7 @@ GNUNET_BANDWIDTH_value_init (uint32_t bytes_per_second)
41 struct GNUNET_BANDWIDTH_Value32NBO ret; 41 struct GNUNET_BANDWIDTH_Value32NBO ret;
42 42
43#if DEBUG_BANDWIDTH 43#if DEBUG_BANDWIDTH
44 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 44 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initializing bandwidth of %u Bps\n",
45 "Initializing bandwidth of %u Bps\n",
46 (unsigned int) bytes_per_second); 45 (unsigned int) bytes_per_second);
47#endif 46#endif
48 ret.value__ = htonl (bytes_per_second); 47 ret.value__ = htonl (bytes_per_second);
@@ -61,8 +60,9 @@ struct GNUNET_BANDWIDTH_Value32NBO
61GNUNET_BANDWIDTH_value_min (struct GNUNET_BANDWIDTH_Value32NBO b1, 60GNUNET_BANDWIDTH_value_min (struct GNUNET_BANDWIDTH_Value32NBO b1,
62 struct GNUNET_BANDWIDTH_Value32NBO b2) 61 struct GNUNET_BANDWIDTH_Value32NBO b2)
63{ 62{
64 return GNUNET_BANDWIDTH_value_init (GNUNET_MIN (ntohl (b1.value__), 63 return
65 ntohl (b2.value__))); 64 GNUNET_BANDWIDTH_value_init (GNUNET_MIN
65 (ntohl (b1.value__), ntohl (b2.value__)));
66} 66}
67 67
68 68
@@ -152,8 +152,7 @@ GNUNET_BANDWIDTH_tracker_init (struct GNUNET_BANDWIDTH_Tracker *av,
152 av->max_carry_s__ = max_carry_s; 152 av->max_carry_s__ = max_carry_s;
153#if DEBUG_BANDWIDTH 153#if DEBUG_BANDWIDTH
154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
155 "Tracker %p initialized with %u Bps and max carry %u\n", 155 "Tracker %p initialized with %u Bps and max carry %u\n", av,
156 av,
157 (unsigned int) av->available_bytes_per_s__, 156 (unsigned int) av->available_bytes_per_s__,
158 (unsigned int) max_carry_s); 157 (unsigned int) max_carry_s);
159#endif 158#endif
@@ -196,8 +195,7 @@ update_tracker (struct GNUNET_BANDWIDTH_Tracker *av)
196#if DEBUG_BANDWIDTH 195#if DEBUG_BANDWIDTH
197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 196 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
198 "Tracker %p updated, have %u Bps, last update was %llu ms ago\n", 197 "Tracker %p updated, have %u Bps, last update was %llu ms ago\n",
199 av, 198 av, (unsigned int) av->available_bytes_per_s__,
200 (unsigned int) av->available_bytes_per_s__,
201 (unsigned long long) delta_time); 199 (unsigned long long) delta_time);
202#endif 200#endif
203 201
@@ -222,8 +220,8 @@ GNUNET_BANDWIDTH_tracker_consume (struct GNUNET_BANDWIDTH_Tracker *av,
222 int64_t nc; 220 int64_t nc;
223 221
224#if DEBUG_BANDWIDTH 222#if DEBUG_BANDWIDTH
225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p consumes %d bytes\n", av,
226 "Tracker %p consumes %d bytes\n", av, (int) size); 224 (int) size);
227#endif 225#endif
228 if (size > 0) 226 if (size > 0)
229 { 227 {
@@ -239,8 +237,8 @@ GNUNET_BANDWIDTH_tracker_consume (struct GNUNET_BANDWIDTH_Tracker *av,
239 { 237 {
240#if DEBUG_BANDWIDTH 238#if DEBUG_BANDWIDTH
241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
242 "Tracker %p consumption %llu bytes above limit\n", 240 "Tracker %p consumption %llu bytes above limit\n", av,
243 av, (unsigned long long) av->consumption_since_last_update__); 241 (unsigned long long) av->consumption_since_last_update__);
244#endif 242#endif
245 return GNUNET_YES; 243 return GNUNET_YES;
246 } 244 }
@@ -282,8 +280,8 @@ GNUNET_BANDWIDTH_tracker_get_delay (struct GNUNET_BANDWIDTH_Tracker *av,
282 { 280 {
283#if DEBUG_BANDWIDTH 281#if DEBUG_BANDWIDTH
284 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 282 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
285 "Tracker %p delay for %u bytes is zero\n", 283 "Tracker %p delay for %u bytes is zero\n", av,
286 av, (unsigned int) size); 284 (unsigned int) size);
287#endif 285#endif
288 return GNUNET_TIME_UNIT_ZERO; 286 return GNUNET_TIME_UNIT_ZERO;
289 } 287 }
@@ -291,8 +289,8 @@ GNUNET_BANDWIDTH_tracker_get_delay (struct GNUNET_BANDWIDTH_Tracker *av,
291 1000LL * bytes_needed / (unsigned long long) av->available_bytes_per_s__; 289 1000LL * bytes_needed / (unsigned long long) av->available_bytes_per_s__;
292#if DEBUG_BANDWIDTH 290#if DEBUG_BANDWIDTH
293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
294 "Tracker %p delay for %u bytes is %llu ms\n", 292 "Tracker %p delay for %u bytes is %llu ms\n", av,
295 av, (unsigned int) size, (unsigned long long) ret.rel_value); 293 (unsigned int) size, (unsigned long long) ret.rel_value);
296#endif 294#endif
297 return ret; 295 return ret;
298} 296}
@@ -314,14 +312,15 @@ GNUNET_BANDWIDTH_tracker_get_available (struct GNUNET_BANDWIDTH_Tracker * av)
314 312
315 update_tracker (av); 313 update_tracker (av);
316 bps = GNUNET_BANDWIDTH_value_init (av->available_bytes_per_s__); 314 bps = GNUNET_BANDWIDTH_value_init (av->available_bytes_per_s__);
317 avail = GNUNET_BANDWIDTH_value_get_available_until (bps, 315 avail =
318 GNUNET_TIME_absolute_get_duration 316 GNUNET_BANDWIDTH_value_get_available_until (bps,
319 (av->last_update__)); 317 GNUNET_TIME_absolute_get_duration
318 (av->last_update__));
320 used = av->consumption_since_last_update__; 319 used = av->consumption_since_last_update__;
321#if DEBUG_BANDWIDTH 320#if DEBUG_BANDWIDTH
322 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 321 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
323 "Tracker %p available bandwidth is %lld bytes\n", 322 "Tracker %p available bandwidth is %lld bytes\n", av,
324 av, (long long) (int64_t) (avail - used)); 323 (long long) (int64_t) (avail - used));
325#endif 324#endif
326 return (int64_t) (avail - used); 325 return (int64_t) (avail - used);
327} 326}
@@ -344,8 +343,8 @@ GNUNET_BANDWIDTH_tracker_update_quota (struct GNUNET_BANDWIDTH_Tracker *av,
344 new_limit = ntohl (bytes_per_second_limit.value__); 343 new_limit = ntohl (bytes_per_second_limit.value__);
345#if DEBUG_BANDWIDTH 344#if DEBUG_BANDWIDTH
346 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
347 "Tracker %p bandwidth changed to %u Bps\n", 346 "Tracker %p bandwidth changed to %u Bps\n", av,
348 av, (unsigned int) new_limit); 347 (unsigned int) new_limit);
349#endif 348#endif
350 update_tracker (av); 349 update_tracker (av);
351 old_limit = av->available_bytes_per_s__; 350 old_limit = av->available_bytes_per_s__;
diff --git a/src/util/bio.c b/src/util/bio.c
index b29d75eb9..404b7aa3b 100644
--- a/src/util/bio.c
+++ b/src/util/bio.c
@@ -101,8 +101,8 @@ GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg)
101 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 101 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
102 */ 102 */
103int 103int
104GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, 104GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, const char *what,
105 const char *what, void *result, size_t len) 105 void *result, size_t len)
106{ 106{
107 char *dst = result; 107 char *dst = result;
108 size_t min; 108 size_t min;
@@ -131,14 +131,14 @@ GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
131 ret = GNUNET_DISK_file_read (h->fd, h->buffer, h->size); 131 ret = GNUNET_DISK_file_read (h->fd, h->buffer, h->size);
132 if (ret == -1) 132 if (ret == -1)
133 { 133 {
134 GNUNET_asprintf (&h->emsg, 134 GNUNET_asprintf (&h->emsg, _("Error reading `%s': %s"), what,
135 _("Error reading `%s': %s"), what, STRERROR (errno)); 135 STRERROR (errno));
136 return GNUNET_SYSERR; 136 return GNUNET_SYSERR;
137 } 137 }
138 if (ret == 0) 138 if (ret == 0)
139 { 139 {
140 GNUNET_asprintf (&h->emsg, 140 GNUNET_asprintf (&h->emsg, _("Error reading `%s': %s"), what,
141 _("Error reading `%s': %s"), what, _("End of file")); 141 _("End of file"));
142 return GNUNET_SYSERR; 142 return GNUNET_SYSERR;
143 } 143 }
144 h->pos = 0; 144 h->pos = 0;
@@ -160,8 +160,8 @@ GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
160 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 160 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
161 */ 161 */
162int 162int
163GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h, 163GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h, const char *file, int line,
164 const char *file, int line, void *result, size_t len) 164 void *result, size_t len)
165{ 165{
166 char what[1024]; 166 char what[1024];
167 167
@@ -181,8 +181,8 @@ GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h,
181 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 181 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
182 */ 182 */
183int 183int
184GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, 184GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, const char *what,
185 const char *what, char **result, size_t maxLen) 185 char **result, size_t maxLen)
186{ 186{
187 char *buf; 187 char *buf;
188 uint32_t big; 188 uint32_t big;
@@ -200,8 +200,7 @@ GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h,
200 } 200 }
201 if (big > maxLen) 201 if (big > maxLen)
202 { 202 {
203 GNUNET_asprintf (&h->emsg, 203 GNUNET_asprintf (&h->emsg, _("String `%s' longer than allowed (%u > %u)"),
204 _("String `%s' longer than allowed (%u > %u)"),
205 what, big, maxLen); 204 what, big, maxLen);
206 return GNUNET_SYSERR; 205 return GNUNET_SYSERR;
207 } 206 }
@@ -229,8 +228,7 @@ GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h,
229 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 228 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
230 */ 229 */
231int 230int
232GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, 231GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, const char *what,
233 const char *what,
234 struct GNUNET_CONTAINER_MetaData **result) 232 struct GNUNET_CONTAINER_MetaData **result)
235{ 233{
236 uint32_t size; 234 uint32_t size;
@@ -280,8 +278,8 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
280 * @return GNUNET_OK on success, GNUNET_SYSERR on error 278 * @return GNUNET_OK on success, GNUNET_SYSERR on error
281 */ 279 */
282int 280int
283GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, 281GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, const char *file,
284 const char *file, int line, int32_t * i) 282 int line, int32_t * i)
285{ 283{
286 int32_t big; 284 int32_t big;
287 285
@@ -302,8 +300,8 @@ GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h,
302 * @return GNUNET_OK on success, GNUNET_SYSERR on error 300 * @return GNUNET_OK on success, GNUNET_SYSERR on error
303 */ 301 */
304int 302int
305GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h, 303GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h, const char *file,
306 const char *file, int line, int64_t * i) 304 int line, int64_t * i)
307{ 305{
308 int64_t big; 306 int64_t big;
309 307
@@ -339,9 +337,8 @@ GNUNET_BIO_write_open (const char *fn)
339 struct GNUNET_BIO_WriteHandle *h; 337 struct GNUNET_BIO_WriteHandle *h;
340 338
341 fd = GNUNET_DISK_file_open (fn, 339 fd = GNUNET_DISK_file_open (fn,
342 GNUNET_DISK_OPEN_WRITE | 340 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE
343 GNUNET_DISK_OPEN_TRUNCATE | 341 | GNUNET_DISK_OPEN_CREATE,
344 GNUNET_DISK_OPEN_CREATE,
345 GNUNET_DISK_PERM_USER_READ | 342 GNUNET_DISK_PERM_USER_READ |
346 GNUNET_DISK_PERM_USER_WRITE); 343 GNUNET_DISK_PERM_USER_WRITE);
347 if (NULL == fd) 344 if (NULL == fd)
@@ -394,8 +391,8 @@ GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h)
394 * @return GNUNET_OK on success, GNUNET_SYSERR on error 391 * @return GNUNET_OK on success, GNUNET_SYSERR on error
395 */ 392 */
396int 393int
397GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, 394GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, const void *buffer,
398 const void *buffer, size_t n) 395 size_t n)
399{ 396{
400 const char *src = buffer; 397 const char *src = buffer;
401 size_t min; 398 size_t min;
@@ -470,10 +467,9 @@ GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
470 if (m == NULL) 467 if (m == NULL)
471 return GNUNET_BIO_write_int32 (h, 0); 468 return GNUNET_BIO_write_int32 (h, 0);
472 buf = NULL; 469 buf = NULL;
473 size = GNUNET_CONTAINER_meta_data_serialize (m, 470 size =
474 &buf, 471 GNUNET_CONTAINER_meta_data_serialize (m, &buf, MAX_META_DATA,
475 MAX_META_DATA, 472 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
476 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
477 if (size == -1) 473 if (size == -1)
478 { 474 {
479 GNUNET_free (buf); 475 GNUNET_free (buf);
diff --git a/src/util/client.c b/src/util/client.c
index 032a6c5e4..59cd26ad1 100644
--- a/src/util/client.c
+++ b/src/util/client.c
@@ -293,15 +293,11 @@ do_connect (const char *service_name,
293#endif 293#endif
294 294
295 if ((GNUNET_OK != 295 if ((GNUNET_OK !=
296 GNUNET_CONFIGURATION_get_value_number (cfg, 296 GNUNET_CONFIGURATION_get_value_number (cfg, service_name, "PORT", &port))
297 service_name, 297 || (port > 65535) ||
298 "PORT",
299 &port)) ||
300 (port > 65535) ||
301 (GNUNET_OK != 298 (GNUNET_OK !=
302 GNUNET_CONFIGURATION_get_value_string (cfg, 299 GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "HOSTNAME",
303 service_name, 300 &hostname)))
304 "HOSTNAME", &hostname)))
305 { 301 {
306 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 302 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
307 _ 303 _
@@ -325,13 +321,12 @@ do_connect (const char *service_name,
325 /* try UNIX */ 321 /* try UNIX */
326 unixpath = NULL; 322 unixpath = NULL;
327 if ((GNUNET_OK == 323 if ((GNUNET_OK ==
328 GNUNET_CONFIGURATION_get_value_string (cfg, 324 GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "UNIXPATH",
329 service_name, 325 &unixpath)) &&
330 "UNIXPATH", &unixpath)) &&
331 (0 < strlen (unixpath))) 326 (0 < strlen (unixpath)))
332 { 327 {
333 sock = GNUNET_CONNECTION_create_from_connect_to_unixpath (cfg, 328 sock =
334 unixpath); 329 GNUNET_CONNECTION_create_from_connect_to_unixpath (cfg, unixpath);
335 if (sock != NULL) 330 if (sock != NULL)
336 { 331 {
337 GNUNET_free (unixpath); 332 GNUNET_free (unixpath);
@@ -457,8 +452,8 @@ check_complete (struct GNUNET_CLIENT_Connection *conn)
457{ 452{
458 if ((conn->received_pos >= sizeof (struct GNUNET_MessageHeader)) && 453 if ((conn->received_pos >= sizeof (struct GNUNET_MessageHeader)) &&
459 (conn->received_pos >= 454 (conn->received_pos >=
460 ntohs (((const struct GNUNET_MessageHeader *) conn->received_buf)-> 455 ntohs (((const struct GNUNET_MessageHeader *) conn->
461 size))) 456 received_buf)->size)))
462 conn->msg_complete = GNUNET_YES; 457 conn->msg_complete = GNUNET_YES;
463} 458}
464 459
@@ -476,9 +471,7 @@ check_complete (struct GNUNET_CLIENT_Connection *conn)
476 * @param errCode value of errno (on errors receiving) 471 * @param errCode value of errno (on errors receiving)
477 */ 472 */
478static void 473static void
479receive_helper (void *cls, 474receive_helper (void *cls, const void *buf, size_t available,
480 const void *buf,
481 size_t available,
482 const struct sockaddr *addr, socklen_t addrlen, int errCode) 475 const struct sockaddr *addr, socklen_t addrlen, int errCode)
483{ 476{
484 struct GNUNET_CLIENT_Connection *conn = cls; 477 struct GNUNET_CLIENT_Connection *conn = cls;
@@ -512,8 +505,8 @@ receive_helper (void *cls,
512 505
513 /* slow path: append to array */ 506 /* slow path: append to array */
514 if (conn->received_size < conn->received_pos + available) 507 if (conn->received_size < conn->received_pos + available)
515 GNUNET_array_grow (conn->received_buf, 508 GNUNET_array_grow (conn->received_buf, conn->received_size,
516 conn->received_size, conn->received_pos + available); 509 conn->received_pos + available);
517 memcpy (&conn->received_buf[conn->received_pos], buf, available); 510 memcpy (&conn->received_buf[conn->received_pos], buf, available);
518 conn->received_pos += available; 511 conn->received_pos += available;
519 check_complete (conn); 512 check_complete (conn);
@@ -527,8 +520,7 @@ receive_helper (void *cls,
527 return; 520 return;
528 } 521 }
529 /* back to receive -- either for more data or to call callback! */ 522 /* back to receive -- either for more data or to call callback! */
530 GNUNET_CLIENT_receive (conn, 523 GNUNET_CLIENT_receive (conn, conn->receiver_handler,
531 conn->receiver_handler,
532 conn->receiver_handler_cls, remaining); 524 conn->receiver_handler_cls, remaining);
533} 525}
534 526
@@ -553,15 +545,15 @@ receive_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
553 545
554#if DEBUG_CLIENT 546#if DEBUG_CLIENT
555 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 547 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
556 "Received message of type %u and size %u\n", 548 "Received message of type %u and size %u\n", ntohs (cmsg->type),
557 ntohs (cmsg->type), msize); 549 msize);
558#endif 550#endif
559 sock->receive_task = GNUNET_SCHEDULER_NO_TASK; 551 sock->receive_task = GNUNET_SCHEDULER_NO_TASK;
560 GNUNET_assert (GNUNET_YES == sock->msg_complete); 552 GNUNET_assert (GNUNET_YES == sock->msg_complete);
561 GNUNET_assert (sock->received_pos >= msize); 553 GNUNET_assert (sock->received_pos >= msize);
562 memcpy (msg, cmsg, msize); 554 memcpy (msg, cmsg, msize);
563 memmove (sock->received_buf, 555 memmove (sock->received_buf, &sock->received_buf[msize],
564 &sock->received_buf[msize], sock->received_pos - msize); 556 sock->received_pos - msize);
565 sock->received_pos -= msize; 557 sock->received_pos -= msize;
566 sock->msg_complete = GNUNET_NO; 558 sock->msg_complete = GNUNET_NO;
567 sock->receiver_handler = NULL; 559 sock->receiver_handler = NULL;
@@ -581,8 +573,8 @@ receive_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
581 */ 573 */
582void 574void
583GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *sock, 575GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *sock,
584 GNUNET_CLIENT_MessageHandler handler, 576 GNUNET_CLIENT_MessageHandler handler, void *handler_cls,
585 void *handler_cls, struct GNUNET_TIME_Relative timeout) 577 struct GNUNET_TIME_Relative timeout)
586{ 578{
587 if (sock->sock == NULL) 579 if (sock->sock == NULL)
588 { 580 {
@@ -607,8 +599,7 @@ GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *sock,
607#if DEBUG_CLIENT 599#if DEBUG_CLIENT
608 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "calling GNUNET_CONNECTION_receive\n"); 600 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "calling GNUNET_CONNECTION_receive\n");
609#endif 601#endif
610 GNUNET_CONNECTION_receive (sock->sock, 602 GNUNET_CONNECTION_receive (sock->sock, GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
611 GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
612 timeout, &receive_helper, sock); 603 timeout, &receive_helper, sock);
613 } 604 }
614} 605}
@@ -620,8 +611,8 @@ GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *sock,
620static void 611static void
621service_test_error (GNUNET_SCHEDULER_Task task, void *task_cls) 612service_test_error (GNUNET_SCHEDULER_Task task, void *task_cls)
622{ 613{
623 GNUNET_SCHEDULER_add_continuation (task, 614 GNUNET_SCHEDULER_add_continuation (task, task_cls,
624 task_cls, GNUNET_SCHEDULER_REASON_TIMEOUT); 615 GNUNET_SCHEDULER_REASON_TIMEOUT);
625} 616}
626 617
627 618
@@ -645,8 +636,7 @@ confirm_handler (void *cls, const struct GNUNET_MessageHeader *msg)
645 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 636 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
646 "Received confirmation that service is running.\n"); 637 "Received confirmation that service is running.\n");
647#endif 638#endif
648 GNUNET_SCHEDULER_add_continuation (conn->test_cb, 639 GNUNET_SCHEDULER_add_continuation (conn->test_cb, conn->test_cb_cls,
649 conn->test_cb_cls,
650 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 640 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
651 } 641 }
652 else 642 else
@@ -688,11 +678,9 @@ write_test (void *cls, size_t size, void *buf)
688 msg = (struct GNUNET_MessageHeader *) buf; 678 msg = (struct GNUNET_MessageHeader *) buf;
689 msg->type = htons (GNUNET_MESSAGE_TYPE_TEST); 679 msg->type = htons (GNUNET_MESSAGE_TYPE_TEST);
690 msg->size = htons (sizeof (struct GNUNET_MessageHeader)); 680 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
691 GNUNET_CLIENT_receive (conn, 681 GNUNET_CLIENT_receive (conn, &confirm_handler, conn,
692 &confirm_handler, 682 GNUNET_TIME_absolute_get_remaining (conn->
693 conn, 683 test_deadline));
694 GNUNET_TIME_absolute_get_remaining
695 (conn->test_deadline));
696 return sizeof (struct GNUNET_MessageHeader); 684 return sizeof (struct GNUNET_MessageHeader);
697} 685}
698 686
@@ -722,8 +710,8 @@ GNUNET_CLIENT_service_test (const char *service,
722 struct GNUNET_CLIENT_Connection *conn; 710 struct GNUNET_CLIENT_Connection *conn;
723 711
724#if DEBUG_CLIENT 712#if DEBUG_CLIENT
725 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 713 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing if service `%s' is running.\n",
726 "Testing if service `%s' is running.\n", service); 714 service);
727#endif 715#endif
728#ifdef AF_UNIX 716#ifdef AF_UNIX
729 { 717 {
@@ -761,15 +749,13 @@ GNUNET_CLIENT_service_test (const char *service,
761 s_un.sun_len = (u_char) slen; 749 s_un.sun_len = (u_char) slen;
762#endif 750#endif
763 if (GNUNET_OK != 751 if (GNUNET_OK !=
764 GNUNET_NETWORK_socket_bind (sock, 752 GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_un,
765 (const struct sockaddr *) &s_un,
766 slen)) 753 slen))
767 { 754 {
768 /* failed to bind => service must be running */ 755 /* failed to bind => service must be running */
769 GNUNET_free (unixpath); 756 GNUNET_free (unixpath);
770 (void) GNUNET_NETWORK_socket_close (sock); 757 (void) GNUNET_NETWORK_socket_close (sock);
771 GNUNET_SCHEDULER_add_continuation (task, 758 GNUNET_SCHEDULER_add_continuation (task, task_cls,
772 task_cls,
773 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 759 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
774 return; 760 return;
775 } 761 }
@@ -784,14 +770,11 @@ GNUNET_CLIENT_service_test (const char *service,
784 770
785 hostname = NULL; 771 hostname = NULL;
786 if ((GNUNET_OK != 772 if ((GNUNET_OK !=
787 GNUNET_CONFIGURATION_get_value_number (cfg, 773 GNUNET_CONFIGURATION_get_value_number (cfg, service, "PORT", &port)) ||
788 service,
789 "PORT",
790 &port)) ||
791 (port > 65535) || 774 (port > 65535) ||
792 (GNUNET_OK != 775 (GNUNET_OK !=
793 GNUNET_CONFIGURATION_get_value_string (cfg, 776 GNUNET_CONFIGURATION_get_value_string (cfg, service, "HOSTNAME",
794 service, "HOSTNAME", &hostname))) 777 &hostname)))
795 { 778 {
796 /* UNIXPATH failed (if possible) AND IP failed => error */ 779 /* UNIXPATH failed (if possible) AND IP failed => error */
797 service_test_error (task, task_cls); 780 service_test_error (task, task_cls);
@@ -818,15 +801,13 @@ GNUNET_CLIENT_service_test (const char *service,
818 if (sock != NULL) 801 if (sock != NULL)
819 { 802 {
820 if (GNUNET_OK != 803 if (GNUNET_OK !=
821 GNUNET_NETWORK_socket_bind (sock, 804 GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_in,
822 (const struct sockaddr *) &s_in,
823 sizeof (s_in))) 805 sizeof (s_in)))
824 { 806 {
825 /* failed to bind => service must be running */ 807 /* failed to bind => service must be running */
826 GNUNET_free (hostname); 808 GNUNET_free (hostname);
827 (void) GNUNET_NETWORK_socket_close (sock); 809 (void) GNUNET_NETWORK_socket_close (sock);
828 GNUNET_SCHEDULER_add_continuation (task, 810 GNUNET_SCHEDULER_add_continuation (task, task_cls,
829 task_cls,
830 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 811 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
831 return; 812 return;
832 } 813 }
@@ -854,15 +835,13 @@ GNUNET_CLIENT_service_test (const char *service,
854 if (sock != NULL) 835 if (sock != NULL)
855 { 836 {
856 if (GNUNET_OK != 837 if (GNUNET_OK !=
857 GNUNET_NETWORK_socket_bind (sock, 838 GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_in6,
858 (const struct sockaddr *) &s_in6,
859 sizeof (s_in6))) 839 sizeof (s_in6)))
860 { 840 {
861 /* failed to bind => service must be running */ 841 /* failed to bind => service must be running */
862 GNUNET_free (hostname); 842 GNUNET_free (hostname);
863 (void) GNUNET_NETWORK_socket_close (sock); 843 (void) GNUNET_NETWORK_socket_close (sock);
864 GNUNET_SCHEDULER_add_continuation (task, 844 GNUNET_SCHEDULER_add_continuation (task, task_cls,
865 task_cls,
866 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 845 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
867 return; 846 return;
868 } 847 }
@@ -889,8 +868,7 @@ GNUNET_CLIENT_service_test (const char *service,
889 if (conn == NULL) 868 if (conn == NULL)
890 { 869 {
891 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 870 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
892 _ 871 _("Could not connect to service `%s', must not be running.\n"),
893 ("Could not connect to service `%s', must not be running.\n"),
894 service); 872 service);
895 service_test_error (task, task_cls); 873 service_test_error (task, task_cls);
896 return; 874 return;
@@ -899,11 +877,11 @@ GNUNET_CLIENT_service_test (const char *service,
899 conn->test_cb_cls = task_cls; 877 conn->test_cb_cls = task_cls;
900 conn->test_deadline = GNUNET_TIME_relative_to_absolute (timeout); 878 conn->test_deadline = GNUNET_TIME_relative_to_absolute (timeout);
901 879
902 if (NULL == GNUNET_CLIENT_notify_transmit_ready (conn, 880 if (NULL ==
903 sizeof (struct 881 GNUNET_CLIENT_notify_transmit_ready (conn,
904 GNUNET_MessageHeader), 882 sizeof (struct GNUNET_MessageHeader),
905 timeout, GNUNET_YES, 883 timeout, GNUNET_YES, &write_test,
906 &write_test, conn)) 884 conn))
907 { 885 {
908 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 886 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
909 _("Failure to transmit request to service `%s'\n"), service); 887 _("Failure to transmit request to service `%s'\n"), service);
@@ -952,8 +930,8 @@ client_delayed_retry (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
952 GNUNET_free (th); 930 GNUNET_free (th);
953 return; 931 return;
954 } 932 }
955 th->sock->sock = do_connect (th->sock->service_name, 933 th->sock->sock =
956 th->sock->cfg, th->sock->attempts++); 934 do_connect (th->sock->service_name, th->sock->cfg, th->sock->attempts++);
957 if (NULL == th->sock->sock) 935 if (NULL == th->sock->sock)
958 { 936 {
959 /* could happen if we're out of sockets */ 937 /* could happen if we're out of sockets */
@@ -970,17 +948,16 @@ client_delayed_retry (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
970 MAX_ATTEMPTS - th->attempts_left, 948 MAX_ATTEMPTS - th->attempts_left,
971 (unsigned long long) delay.rel_value); 949 (unsigned long long) delay.rel_value);
972#endif 950#endif
973 th->reconnect_task = GNUNET_SCHEDULER_add_delayed (delay, 951 th->reconnect_task =
974 &client_delayed_retry, 952 GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th);
975 th);
976 return; 953 return;
977 } 954 }
978 GNUNET_CONNECTION_ignore_shutdown (th->sock->sock, th->sock->ignore_shutdown); 955 GNUNET_CONNECTION_ignore_shutdown (th->sock->sock, th->sock->ignore_shutdown);
979 th->th = GNUNET_CONNECTION_notify_transmit_ready (th->sock->sock, 956 th->th =
980 th->size, 957 GNUNET_CONNECTION_notify_transmit_ready (th->sock->sock, th->size,
981 GNUNET_TIME_absolute_get_remaining 958 GNUNET_TIME_absolute_get_remaining
982 (th->timeout), 959 (th->timeout), &client_notify,
983 &client_notify, th); 960 th);
984 if (th->th == NULL) 961 if (th->th == NULL)
985 { 962 {
986 GNUNET_break (0); 963 GNUNET_break (0);
@@ -1037,8 +1014,7 @@ client_notify (void *cls, size_t size, void *buf)
1037 GNUNET_CONNECTION_destroy (th->sock->sock, GNUNET_NO); 1014 GNUNET_CONNECTION_destroy (th->sock->sock, GNUNET_NO);
1038 th->sock->sock = NULL; 1015 th->sock->sock = NULL;
1039 delay = GNUNET_TIME_relative_min (delay, th->sock->back_off); 1016 delay = GNUNET_TIME_relative_min (delay, th->sock->back_off);
1040 th->sock->back_off 1017 th->sock->back_off =
1041 =
1042 GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply 1018 GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply
1043 (th->sock->back_off, 2), 1019 (th->sock->back_off, 2),
1044 GNUNET_TIME_UNIT_SECONDS); 1020 GNUNET_TIME_UNIT_SECONDS);
@@ -1049,9 +1025,8 @@ client_notify (void *cls, size_t size, void *buf)
1049 (unsigned long long) delay.rel_value); 1025 (unsigned long long) delay.rel_value);
1050#endif 1026#endif
1051 th->sock->th = th; 1027 th->sock->th = th;
1052 th->reconnect_task = GNUNET_SCHEDULER_add_delayed (delay, 1028 th->reconnect_task =
1053 &client_delayed_retry, 1029 GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th);
1054 th);
1055 return 0; 1030 return 0;
1056 } 1031 }
1057 GNUNET_assert (size >= th->size); 1032 GNUNET_assert (size >= th->size);
@@ -1108,17 +1083,16 @@ GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *sock,
1108 sock->th = th; 1083 sock->th = th;
1109 if (sock->sock == NULL) 1084 if (sock->sock == NULL)
1110 { 1085 {
1111 th->reconnect_task = GNUNET_SCHEDULER_add_delayed (sock->back_off, 1086 th->reconnect_task =
1112 &client_delayed_retry, 1087 GNUNET_SCHEDULER_add_delayed (sock->back_off, &client_delayed_retry,
1113 th); 1088 th);
1114 1089
1115 } 1090 }
1116 else 1091 else
1117 { 1092 {
1118 th->th = GNUNET_CONNECTION_notify_transmit_ready (sock->sock, 1093 th->th =
1119 size, 1094 GNUNET_CONNECTION_notify_transmit_ready (sock->sock, size, timeout,
1120 timeout, 1095 &client_notify, th);
1121 &client_notify, th);
1122 if (NULL == th->th) 1096 if (NULL == th->th)
1123 { 1097 {
1124 GNUNET_break (0); 1098 GNUNET_break (0);
@@ -1137,8 +1111,8 @@ GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *sock,
1137 * @param th handle from the original request. 1111 * @param th handle from the original request.
1138 */ 1112 */
1139void 1113void
1140GNUNET_CLIENT_notify_transmit_ready_cancel (struct 1114GNUNET_CLIENT_notify_transmit_ready_cancel (struct GNUNET_CLIENT_TransmitHandle
1141 GNUNET_CLIENT_TransmitHandle *th) 1115 *th)
1142{ 1116{
1143 if (th->reconnect_task != GNUNET_SCHEDULER_NO_TASK) 1117 if (th->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
1144 { 1118 {
@@ -1189,9 +1163,7 @@ transmit_for_response (void *cls, size_t size, void *buf)
1189 } 1163 }
1190 GNUNET_assert (size >= msize); 1164 GNUNET_assert (size >= msize);
1191 memcpy (buf, tc->hdr, msize); 1165 memcpy (buf, tc->hdr, msize);
1192 GNUNET_CLIENT_receive (tc->sock, 1166 GNUNET_CLIENT_receive (tc->sock, tc->rn, tc->rn_cls,
1193 tc->rn,
1194 tc->rn_cls,
1195 GNUNET_TIME_absolute_get_remaining (tc->timeout)); 1167 GNUNET_TIME_absolute_get_remaining (tc->timeout));
1196 GNUNET_free (tc); 1168 GNUNET_free (tc);
1197 return msize; 1169 return msize;
@@ -1220,10 +1192,8 @@ transmit_for_response (void *cls, size_t size, void *buf)
1220 * is already pending 1192 * is already pending
1221 */ 1193 */
1222int 1194int
1223GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection 1195GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection *sock,
1224 *sock, 1196 const struct GNUNET_MessageHeader *hdr,
1225 const struct GNUNET_MessageHeader
1226 *hdr,
1227 struct GNUNET_TIME_Relative timeout, 1197 struct GNUNET_TIME_Relative timeout,
1228 int auto_retry, 1198 int auto_retry,
1229 GNUNET_CLIENT_MessageHandler rn, 1199 GNUNET_CLIENT_MessageHandler rn,
@@ -1243,11 +1213,9 @@ GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection
1243 tc->timeout = GNUNET_TIME_relative_to_absolute (timeout); 1213 tc->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1244 tc->rn = rn; 1214 tc->rn = rn;
1245 tc->rn_cls = rn_cls; 1215 tc->rn_cls = rn_cls;
1246 if (NULL == GNUNET_CLIENT_notify_transmit_ready (sock, 1216 if (NULL ==
1247 msize, 1217 GNUNET_CLIENT_notify_transmit_ready (sock, msize, timeout, auto_retry,
1248 timeout, 1218 &transmit_for_response, tc))
1249 auto_retry,
1250 &transmit_for_response, tc))
1251 { 1219 {
1252 GNUNET_break (0); 1220 GNUNET_break (0);
1253 GNUNET_free (tc); 1221 GNUNET_free (tc);
diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c
index 6f01e8230..71aa15add 100644
--- a/src/util/common_allocation.c
+++ b/src/util/common_allocation.c
@@ -255,9 +255,7 @@ GNUNET_xstrndup_ (const char *str, size_t len, const char *filename,
255 * @param linenumber where in the code was the call to GNUNET_array_grow 255 * @param linenumber where in the code was the call to GNUNET_array_grow
256 */ 256 */
257void 257void
258GNUNET_xgrow_ (void **old, 258GNUNET_xgrow_ (void **old, size_t elementSize, unsigned int *oldCount,
259 size_t elementSize,
260 unsigned int *oldCount,
261 unsigned int newCount, const char *filename, int linenumber) 259 unsigned int newCount, const char *filename, int linenumber)
262{ 260{
263 void *tmp; 261 void *tmp;
diff --git a/src/util/common_logging.c b/src/util/common_logging.c
index 37f630854..ff3ac12ee 100644
--- a/src/util/common_logging.c
+++ b/src/util/common_logging.c
@@ -279,8 +279,8 @@ GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls)
279 * @param msg the actual message 279 * @param msg the actual message
280 */ 280 */
281static void 281static void
282output_message (enum GNUNET_ErrorType kind, 282output_message (enum GNUNET_ErrorType kind, const char *comp,
283 const char *comp, const char *datestr, const char *msg) 283 const char *datestr, const char *msg)
284{ 284{
285 struct CustomLogger *pos; 285 struct CustomLogger *pos;
286 286
@@ -371,8 +371,8 @@ GNUNET_log_skip (unsigned int n, int check_reset)
371 * @param va arguments to the format string "message" 371 * @param va arguments to the format string "message"
372 */ 372 */
373static void 373static void
374mylog (enum GNUNET_ErrorType kind, 374mylog (enum GNUNET_ErrorType kind, const char *comp, const char *message,
375 const char *comp, const char *message, va_list va) 375 va_list va)
376{ 376{
377 char date[DATE_STR_SIZE]; 377 char date[DATE_STR_SIZE];
378 char date2[DATE_STR_SIZE]; 378 char date2[DATE_STR_SIZE];
@@ -419,9 +419,8 @@ mylog (enum GNUNET_ErrorType kind,
419 } 419 }
420 else 420 else
421 strcpy (date, "localtime error"); 421 strcpy (date, "localtime error");
422 if ((0 != (kind & GNUNET_ERROR_TYPE_BULK)) && 422 if ((0 != (kind & GNUNET_ERROR_TYPE_BULK)) && (last_bulk_time.abs_value != 0)
423 (last_bulk_time.abs_value != 0) && 423 && (0 == strncmp (buf, last_bulk, sizeof (last_bulk))))
424 (0 == strncmp (buf, last_bulk, sizeof (last_bulk))))
425 { 424 {
426 last_bulk_repeat++; 425 last_bulk_repeat++;
427 if ((GNUNET_TIME_absolute_get_duration (last_bulk_time).rel_value > 426 if ((GNUNET_TIME_absolute_get_duration (last_bulk_time).rel_value >
@@ -469,8 +468,8 @@ GNUNET_log (enum GNUNET_ErrorType kind, const char *message, ...)
469 * @param ... arguments for format string 468 * @param ... arguments for format string
470 */ 469 */
471void 470void
472GNUNET_log_from (enum GNUNET_ErrorType kind, 471GNUNET_log_from (enum GNUNET_ErrorType kind, const char *comp,
473 const char *comp, const char *message, ...) 472 const char *message, ...)
474{ 473{
475 va_list va; 474 va_list va;
476 char comp_w_pid[128]; 475 char comp_w_pid[128];
@@ -614,10 +613,7 @@ GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen)
614 off = 0; 613 off = 0;
615 if (un->sun_path[0] == '\0') 614 if (un->sun_path[0] == '\0')
616 off++; 615 off++;
617 snprintf (buf, 616 snprintf (buf, sizeof (buf), "%s%.*s", (off == 1) ? "@" : "",
618 sizeof (buf),
619 "%s%.*s",
620 (off == 1) ? "@" : "",
621 (int) (addrlen - sizeof (sa_family_t) - 1 - off), 617 (int) (addrlen - sizeof (sa_family_t) - 1 - off),
622 &un->sun_path[off]); 618 &un->sun_path[off]);
623 return buf; 619 return buf;
diff --git a/src/util/configuration.c b/src/util/configuration.c
index b3b9d5ea8..534949652 100644
--- a/src/util/configuration.c
+++ b/src/util/configuration.c
@@ -241,8 +241,7 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
241 { 241 {
242 /* parse error */ 242 /* parse error */
243 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 243 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
244 _ 244 _("Syntax error in configuration file `%s' at line %u.\n"),
245 ("Syntax error in configuration file `%s' at line %u.\n"),
246 filename, nr); 245 filename, nr);
247 ret = GNUNET_SYSERR; 246 ret = GNUNET_SYSERR;
248 break; 247 break;
@@ -499,8 +498,8 @@ GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
499 * @param value value to copy 498 * @param value value to copy
500 */ 499 */
501static void 500static void
502copy_entry (void *cls, 501copy_entry (void *cls, const char *section, const char *option,
503 const char *section, const char *option, const char *value) 502 const char *value)
504{ 503{
505 struct GNUNET_CONFIGURATION_Handle *dst = cls; 504 struct GNUNET_CONFIGURATION_Handle *dst = cls;
506 505
@@ -553,8 +552,8 @@ findSection (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
553 * @return matching entry, NULL if not found 552 * @return matching entry, NULL if not found
554 */ 553 */
555static struct ConfigEntry * 554static struct ConfigEntry *
556findEntry (const struct GNUNET_CONFIGURATION_Handle *cfg, 555findEntry (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section,
557 const char *section, const char *key) 556 const char *key)
558{ 557{
559 struct ConfigSection *sec; 558 struct ConfigSection *sec;
560 struct ConfigEntry *pos; 559 struct ConfigEntry *pos;
@@ -580,8 +579,8 @@ findEntry (const struct GNUNET_CONFIGURATION_Handle *cfg,
580 * @param value value to copy (of the default conf.) 579 * @param value value to copy (of the default conf.)
581 */ 580 */
582static void 581static void
583compareEntries (void *cls, 582compareEntries (void *cls, const char *section, const char *option,
584 const char *section, const char *option, const char *value) 583 const char *value)
585{ 584{
586 struct DiffHandle *dh = cls; 585 struct DiffHandle *dh = cls;
587 struct ConfigEntry *entNew; 586 struct ConfigEntry *entNew;
@@ -627,10 +626,9 @@ GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle
627 * @param value value to set 626 * @param value value to set
628 */ 627 */
629void 628void
630GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle 629GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
631 *cfg, 630 const char *section, const char *option,
632 const char *section, 631 const char *value)
633 const char *option, const char *value)
634{ 632{
635 struct ConfigSection *sec; 633 struct ConfigSection *sec;
636 struct ConfigEntry *e; 634 struct ConfigEntry *e;
@@ -667,9 +665,8 @@ GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle
667 * @param number value to set 665 * @param number value to set
668 */ 666 */
669void 667void
670GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle 668GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
671 *cfg, const char *section, 669 const char *section, const char *option,
672 const char *option,
673 unsigned long long number) 670 unsigned long long number)
674{ 671{
675 char s[64]; 672 char s[64];
@@ -689,9 +686,8 @@ GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle
689 * @return GNUNET_OK on success, GNUNET_SYSERR on error 686 * @return GNUNET_OK on success, GNUNET_SYSERR on error
690 */ 687 */
691int 688int
692GNUNET_CONFIGURATION_get_value_number (const struct 689GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle
693 GNUNET_CONFIGURATION_Handle *cfg, 690 *cfg, const char *section,
694 const char *section,
695 const char *option, 691 const char *option,
696 unsigned long long *number) 692 unsigned long long *number)
697{ 693{
@@ -751,9 +747,8 @@ GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle
751 * @return GNUNET_OK on success, GNUNET_SYSERR on error 747 * @return GNUNET_OK on success, GNUNET_SYSERR on error
752 */ 748 */
753int 749int
754GNUNET_CONFIGURATION_get_value_string (const struct 750GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle
755 GNUNET_CONFIGURATION_Handle *cfg, 751 *cfg, const char *section,
756 const char *section,
757 const char *option, char **value) 752 const char *option, char **value)
758{ 753{
759 struct ConfigEntry *e; 754 struct ConfigEntry *e;
@@ -782,11 +777,10 @@ GNUNET_CONFIGURATION_get_value_string (const struct
782 * @return GNUNET_OK on success, GNUNET_SYSERR on error 777 * @return GNUNET_OK on success, GNUNET_SYSERR on error
783 */ 778 */
784int 779int
785GNUNET_CONFIGURATION_get_value_choice (const struct 780GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle
786 GNUNET_CONFIGURATION_Handle *cfg, 781 *cfg, const char *section,
787 const char *section, 782 const char *option, const char **choices,
788 const char *option, 783 const char **value)
789 const char **choices, const char **value)
790{ 784{
791 struct ConfigEntry *e; 785 struct ConfigEntry *e;
792 int i; 786 int i;
@@ -805,8 +799,8 @@ GNUNET_CONFIGURATION_get_value_choice (const struct
805 { 799 {
806 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 800 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
807 _("Configuration value '%s' for '%s'" 801 _("Configuration value '%s' for '%s'"
808 " in section '%s' is not in set of legal choices\n"), 802 " in section '%s' is not in set of legal choices\n"), e->val,
809 e->val, option, section); 803 option, section);
810 return GNUNET_SYSERR; 804 return GNUNET_SYSERR;
811 } 805 }
812 *value = choices[i]; 806 *value = choices[i];
@@ -822,8 +816,8 @@ GNUNET_CONFIGURATION_get_value_choice (const struct
822 * @return GNUNET_YES if so, GNUNET_NO if not. 816 * @return GNUNET_YES if so, GNUNET_NO if not.
823 */ 817 */
824int 818int
825GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle 819GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
826 *cfg, const char *section, const char *option) 820 const char *section, const char *option)
827{ 821{
828 struct ConfigEntry *e; 822 struct ConfigEntry *e;
829 823
@@ -866,9 +860,8 @@ GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle
866 orig[i] = '\0'; 860 orig[i] = '\0';
867 post = &orig[i + 1]; 861 post = &orig[i + 1];
868 } 862 }
869 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, 863 if (GNUNET_OK !=
870 "PATHS", 864 GNUNET_CONFIGURATION_get_value_filename (cfg, "PATHS", &orig[1], &prefix))
871 &orig[1], &prefix))
872 { 865 {
873 if (NULL == (env = getenv (&orig[1]))) 866 if (NULL == (env = getenv (&orig[1])))
874 { 867 {
@@ -940,8 +933,8 @@ GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle
940 const char *val; 933 const char *val;
941 int ret; 934 int ret;
942 935
943 ret = GNUNET_CONFIGURATION_get_value_choice (cfg, 936 ret =
944 section, option, yesno, &val); 937 GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val);
945 if (ret == GNUNET_SYSERR) 938 if (ret == GNUNET_SYSERR)
946 return ret; 939 return ret;
947 if (val == yesno[0]) 940 if (val == yesno[0])
@@ -962,8 +955,8 @@ GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle
962 */ 955 */
963int 956int
964GNUNET_CONFIGURATION_iterate_value_filenames (const struct 957GNUNET_CONFIGURATION_iterate_value_filenames (const struct
965 GNUNET_CONFIGURATION_Handle 958 GNUNET_CONFIGURATION_Handle *cfg,
966 *cfg, const char *section, 959 const char *section,
967 const char *option, 960 const char *option,
968 GNUNET_FileNameCallback cb, 961 GNUNET_FileNameCallback cb,
969 void *cb_cls) 962 void *cb_cls)
@@ -1093,8 +1086,7 @@ test_match (void *cls, const char *fn)
1093 */ 1086 */
1094int 1087int
1095GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle 1088GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle
1096 *cfg, 1089 *cfg, const char *section,
1097 const char *section,
1098 const char *option, 1090 const char *option,
1099 const char *value) 1091 const char *value)
1100{ 1092{
@@ -1102,12 +1094,10 @@ GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle
1102 char *old; 1094 char *old;
1103 char *nw; 1095 char *nw;
1104 1096
1105 if (GNUNET_SYSERR 1097 if (GNUNET_SYSERR ==
1106 == GNUNET_CONFIGURATION_iterate_value_filenames (cfg, 1098 GNUNET_CONFIGURATION_iterate_value_filenames (cfg, section, option,
1107 section, 1099 &test_match,
1108 option, 1100 (void *) value))
1109 &test_match,
1110 (void *) value))
1111 return GNUNET_NO; /* already exists */ 1101 return GNUNET_NO; /* already exists */
1112 if (GNUNET_OK != 1102 if (GNUNET_OK !=
1113 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old)) 1103 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old))
@@ -1140,8 +1130,7 @@ GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle
1140 */ 1130 */
1141int 1131int
1142GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle 1132GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle
1143 *cfg, 1133 *cfg, const char *section,
1144 const char *section,
1145 const char *option, 1134 const char *option,
1146 const char *value) 1135 const char *value)
1147{ 1136{
@@ -1231,11 +1220,10 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
1231 if (ipath == NULL) 1220 if (ipath == NULL)
1232 return GNUNET_SYSERR; 1221 return GNUNET_SYSERR;
1233 baseconfig = NULL; 1222 baseconfig = NULL;
1234 GNUNET_asprintf (&baseconfig, 1223 GNUNET_asprintf (&baseconfig, "%s%s%s", ipath, DIR_SEPARATOR_STR,
1235 "%s%s%s", ipath, DIR_SEPARATOR_STR, "defaults.conf"); 1224 "defaults.conf");
1236 GNUNET_free (ipath); 1225 GNUNET_free (ipath);
1237 if ((GNUNET_OK != 1226 if ((GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, baseconfig)) ||
1238 GNUNET_CONFIGURATION_parse (cfg, baseconfig)) ||
1239 (!((filename == NULL) || 1227 (!((filename == NULL) ||
1240 (GNUNET_OK == GNUNET_CONFIGURATION_parse (cfg, filename))))) 1228 (GNUNET_OK == GNUNET_CONFIGURATION_parse (cfg, filename)))))
1241 { 1229 {
@@ -1243,18 +1231,15 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
1243 return (filename == NULL) ? GNUNET_OK : GNUNET_SYSERR; 1231 return (filename == NULL) ? GNUNET_OK : GNUNET_SYSERR;
1244 } 1232 }
1245 GNUNET_free (baseconfig); 1233 GNUNET_free (baseconfig);
1246 if (((GNUNET_YES != GNUNET_CONFIGURATION_have_value (cfg, 1234 if (((GNUNET_YES !=
1247 "PATHS", 1235 GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "DEFAULTCONFIG"))) &&
1248 "DEFAULTCONFIG"))) &&
1249 (filename != NULL)) 1236 (filename != NULL))
1250 GNUNET_CONFIGURATION_set_value_string (cfg, 1237 GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG",
1251 "PATHS", "DEFAULTCONFIG", filename); 1238 filename);
1252 if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (cfg, 1239 if ((GNUNET_YES ==
1253 "TESTING", 1240 GNUNET_CONFIGURATION_have_value (cfg, "TESTING", "WEAKRANDOM")) &&
1254 "WEAKRANDOM")) && 1241 (GNUNET_YES ==
1255 (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg, 1242 GNUNET_CONFIGURATION_get_value_yesno (cfg, "TESTING", "WEAKRANDOM")))
1256 "TESTING",
1257 "WEAKRANDOM")))
1258 GNUNET_CRYPTO_random_disable_entropy_gathering (); 1243 GNUNET_CRYPTO_random_disable_entropy_gathering ();
1259 return GNUNET_OK; 1244 return GNUNET_OK;
1260} 1245}
diff --git a/src/util/connection.c b/src/util/connection.c
index 1ac1b2304..39cb1dde2 100644
--- a/src/util/connection.c
+++ b/src/util/connection.c
@@ -425,9 +425,8 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access,
425 /* largely traditional GNU/Linux */ 425 /* largely traditional GNU/Linux */
426 olen = sizeof (uc); 426 olen = sizeof (uc);
427 if ((0 == 427 if ((0 ==
428 getsockopt (GNUNET_NETWORK_get_fd (sock), 428 getsockopt (GNUNET_NETWORK_get_fd (sock), SOL_SOCKET, SO_PEERCRED, &uc,
429 SOL_SOCKET, SO_PEERCRED, &uc, &olen)) && 429 &olen)) && (olen == sizeof (uc)))
430 (olen == sizeof (uc)))
431 { 430 {
432 gc.uid = uc.uid; 431 gc.uid = uc.uid;
433 gc.gid = uc.gid; 432 gc.gid = uc.gid;
@@ -455,8 +454,8 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access,
455 (GNUNET_YES != (aret = access (access_cls, gcp, uaddr, addrlen)))) 454 (GNUNET_YES != (aret = access (access_cls, gcp, uaddr, addrlen))))
456 { 455 {
457 if (aret == GNUNET_NO) 456 if (aret == GNUNET_NO)
458 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 457 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Access denied to `%s'\n"),
459 _("Access denied to `%s'\n"), GNUNET_a2s (uaddr, addrlen)); 458 GNUNET_a2s (uaddr, addrlen));
460 GNUNET_break (GNUNET_OK == 459 GNUNET_break (GNUNET_OK ==
461 GNUNET_NETWORK_socket_shutdown (sock, SHUT_RDWR)); 460 GNUNET_NETWORK_socket_shutdown (sock, SHUT_RDWR));
462 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); 461 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
@@ -470,8 +469,7 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access,
470 ret->addrlen = addrlen; 469 ret->addrlen = addrlen;
471 ret->sock = sock; 470 ret->sock = sock;
472#if DEBUG_CONNECTION 471#if DEBUG_CONNECTION
473 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 472 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Accepting connection from `%s': %p\n"),
474 _("Accepting connection from `%s': %p\n"),
475 GNUNET_a2s (uaddr, addrlen), ret); 473 GNUNET_a2s (uaddr, addrlen), ret);
476#endif 474#endif
477 return ret; 475 return ret;
@@ -508,8 +506,8 @@ GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *sock,
508 * @param cls our connection handle 506 * @param cls our connection handle
509 * @param tc task context describing why we are here 507 * @param tc task context describing why we are here
510 */ 508 */
511static void 509static void receive_again (void *cls,
512receive_again (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 510 const struct GNUNET_SCHEDULER_TaskContext *tc);
513 511
514 512
515/** 513/**
@@ -544,9 +542,9 @@ destroy_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
544 "Destroy waits for write_task to be done (%p)\n", sock); 542 "Destroy waits for write_task to be done (%p)\n", sock);
545#endif 543#endif
546 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); 544 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task);
547 sock->destroy_task 545 sock->destroy_task =
548 = GNUNET_SCHEDULER_add_after (sock->write_task, 546 GNUNET_SCHEDULER_add_after (sock->write_task, &destroy_continuation,
549 &destroy_continuation, sock); 547 sock);
550 return; 548 return;
551 } 549 }
552 if (0 != (sock->ccs & COCO_RECEIVE_AGAIN)) 550 if (0 != (sock->ccs & COCO_RECEIVE_AGAIN))
@@ -569,9 +567,9 @@ destroy_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
569 if (sock->read_task != GNUNET_SCHEDULER_NO_TASK) 567 if (sock->read_task != GNUNET_SCHEDULER_NO_TASK)
570 { 568 {
571 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); 569 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task);
572 sock->destroy_task 570 sock->destroy_task =
573 = GNUNET_SCHEDULER_add_after (sock->read_task, 571 GNUNET_SCHEDULER_add_after (sock->read_task, &destroy_continuation,
574 &destroy_continuation, sock); 572 sock);
575 return; 573 return;
576 } 574 }
577#if DEBUG_CONNECTION 575#if DEBUG_CONNECTION
@@ -604,8 +602,8 @@ destroy_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
604 GNUNET_free_non_null (sock->hostname); 602 GNUNET_free_non_null (sock->hostname);
605 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); 603 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task);
606#if DEBUG_CONNECTION 604#if DEBUG_CONNECTION
607 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 605 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Freeing memory of connection %p.\n",
608 "Freeing memory of connection %p.\n", sock); 606 sock);
609#endif 607#endif
610 GNUNET_free (sock->write_buffer); 608 GNUNET_free (sock->write_buffer);
611 GNUNET_free (sock); 609 GNUNET_free (sock);
@@ -621,8 +619,8 @@ destroy_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
621 * @param cls our connection handle 619 * @param cls our connection handle
622 * @param tc task context describing why we are here 620 * @param tc task context describing why we are here
623 */ 621 */
624static void 622static void transmit_ready (void *cls,
625transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 623 const struct GNUNET_SCHEDULER_TaskContext *tc);
626 624
627 625
628/** 626/**
@@ -634,11 +632,10 @@ static void
634connect_fail_continuation (struct GNUNET_CONNECTION_Handle *h) 632connect_fail_continuation (struct GNUNET_CONNECTION_Handle *h)
635{ 633{
636#if DEBUG_CONNECTION 634#if DEBUG_CONNECTION
637 GNUNET_log ((0 != strncmp (h->hostname, 635 GNUNET_log ((0 !=
638 "localhost:", 636 strncmp (h->hostname, "localhost:",
639 10)) 637 10)) ? GNUNET_ERROR_TYPE_INFO :
640 ? GNUNET_ERROR_TYPE_INFO 638 GNUNET_ERROR_TYPE_WARNING,
641 : GNUNET_ERROR_TYPE_WARNING,
642 _ 639 _
643 ("Failed to establish TCP connection to `%s:%u', no further addresses to try.\n"), 640 ("Failed to establish TCP connection to `%s:%u', no further addresses to try.\n"),
644 h->hostname, h->port); 641 h->hostname, h->port);
@@ -697,8 +694,7 @@ static void
697connect_success_continuation (struct GNUNET_CONNECTION_Handle *h) 694connect_success_continuation (struct GNUNET_CONNECTION_Handle *h)
698{ 695{
699#if DEBUG_CONNECTION 696#if DEBUG_CONNECTION
700 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 697 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connection to `%s' succeeded! (%p)\n",
701 "Connection to `%s' succeeded! (%p)\n",
702 GNUNET_a2s (h->addr, h->addrlen), h); 698 GNUNET_a2s (h->addr, h->addrlen), h);
703#endif 699#endif
704 /* trigger jobs that waited for the connection */ 700 /* trigger jobs that waited for the connection */
@@ -767,8 +763,8 @@ connect_probe_continuation (void *cls,
767 error = 0; 763 error = 0;
768 if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) || 764 if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) ||
769 (GNUNET_OK != 765 (GNUNET_OK !=
770 GNUNET_NETWORK_socket_getsockopt (ap->sock, SOL_SOCKET, SO_ERROR, 766 GNUNET_NETWORK_socket_getsockopt (ap->sock, SOL_SOCKET, SO_ERROR, &error,
771 &error, &len)) || (error != 0)) 767 &len)) || (error != 0))
772 { 768 {
773 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); 769 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock));
774 GNUNET_free (ap); 770 GNUNET_free (ap);
@@ -804,8 +800,8 @@ connect_probe_continuation (void *cls,
804 * @param addrlen length of addr 800 * @param addrlen length of addr
805 */ 801 */
806static void 802static void
807try_connect_using_address (void *cls, 803try_connect_using_address (void *cls, const struct sockaddr *addr,
808 const struct sockaddr *addr, socklen_t addrlen) 804 socklen_t addrlen)
809{ 805{
810 struct GNUNET_CONNECTION_Handle *h = cls; 806 struct GNUNET_CONNECTION_Handle *h = cls;
811 struct AddressProbe *ap; 807 struct AddressProbe *ap;
@@ -824,8 +820,8 @@ try_connect_using_address (void *cls,
824 /* try to connect */ 820 /* try to connect */
825#if DEBUG_CONNECTION 821#if DEBUG_CONNECTION
826 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 822 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
827 "Trying to connect using address `%s:%u/%s:%u'\n", 823 "Trying to connect using address `%s:%u/%s:%u'\n", h->hostname,
828 h->hostname, h->port, GNUNET_a2s (addr, addrlen), h->port); 824 h->port, GNUNET_a2s (addr, addrlen), h->port);
829#endif 825#endif
830 ap = GNUNET_malloc (sizeof (struct AddressProbe) + addrlen); 826 ap = GNUNET_malloc (sizeof (struct AddressProbe) + addrlen);
831 ap->addr = (const struct sockaddr *) &ap[1]; 827 ap->addr = (const struct sockaddr *) &ap[1];
@@ -853,13 +849,11 @@ try_connect_using_address (void *cls,
853 return; /* not supported by OS */ 849 return; /* not supported by OS */
854 } 850 }
855#if DEBUG_CONNECTION 851#if DEBUG_CONNECTION
856 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 852 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Trying to connect to `%s' (%p)\n"),
857 _("Trying to connect to `%s' (%p)\n"),
858 GNUNET_a2s (ap->addr, ap->addrlen), h); 853 GNUNET_a2s (ap->addr, ap->addrlen), h);
859#endif 854#endif
860 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (ap->sock, 855 if ((GNUNET_OK !=
861 ap->addr, 856 GNUNET_NETWORK_socket_connect (ap->sock, ap->addr, ap->addrlen)) &&
862 ap->addrlen)) &&
863 (errno != EINPROGRESS)) 857 (errno != EINPROGRESS))
864 { 858 {
865 /* maybe refused / unsupported address, try next */ 859 /* maybe refused / unsupported address, try next */
@@ -871,13 +865,15 @@ try_connect_using_address (void *cls,
871 GNUNET_CONTAINER_DLL_insert (h->ap_head, h->ap_tail, ap); 865 GNUNET_CONTAINER_DLL_insert (h->ap_head, h->ap_tail, ap);
872 delay = GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT; 866 delay = GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT;
873 if (h->nth.notify_ready != NULL) 867 if (h->nth.notify_ready != NULL)
874 delay = GNUNET_TIME_relative_min (delay, 868 delay =
875 GNUNET_TIME_absolute_get_remaining 869 GNUNET_TIME_relative_min (delay,
876 (h->nth.transmit_timeout)); 870 GNUNET_TIME_absolute_get_remaining (h->nth.
871 transmit_timeout));
877 if (h->receiver != NULL) 872 if (h->receiver != NULL)
878 delay = GNUNET_TIME_relative_min (delay, 873 delay =
879 GNUNET_TIME_absolute_get_remaining 874 GNUNET_TIME_relative_min (delay,
880 (h->receive_timeout)); 875 GNUNET_TIME_absolute_get_remaining (h->
876 receive_timeout));
881 ap->task = 877 ap->task =
882 GNUNET_SCHEDULER_add_write_net (delay, ap->sock, 878 GNUNET_SCHEDULER_add_write_net (delay, ap->sock,
883 &connect_probe_continuation, ap); 879 &connect_probe_continuation, ap);
@@ -895,9 +891,9 @@ try_connect_using_address (void *cls,
895 * @return the socket handle 891 * @return the socket handle
896 */ 892 */
897struct GNUNET_CONNECTION_Handle * 893struct GNUNET_CONNECTION_Handle *
898GNUNET_CONNECTION_create_from_connect (const struct 894GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle
899 GNUNET_CONFIGURATION_Handle *cfg, 895 *cfg, const char *hostname,
900 const char *hostname, uint16_t port) 896 uint16_t port)
901{ 897{
902 struct GNUNET_CONNECTION_Handle *ret; 898 struct GNUNET_CONNECTION_Handle *ret;
903 899
@@ -908,10 +904,10 @@ GNUNET_CONNECTION_create_from_connect (const struct
908 ret->write_buffer = GNUNET_malloc (ret->write_buffer_size); 904 ret->write_buffer = GNUNET_malloc (ret->write_buffer_size);
909 ret->port = port; 905 ret->port = port;
910 ret->hostname = GNUNET_strdup (hostname); 906 ret->hostname = GNUNET_strdup (hostname);
911 ret->dns_active = GNUNET_RESOLVER_ip_get (ret->hostname, 907 ret->dns_active =
912 AF_UNSPEC, 908 GNUNET_RESOLVER_ip_get (ret->hostname, AF_UNSPEC,
913 GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT, 909 GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT,
914 &try_connect_using_address, ret); 910 &try_connect_using_address, ret);
915 return ret; 911 return ret;
916} 912}
917 913
@@ -966,8 +962,8 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct
966 GNUNET_free (ret); 962 GNUNET_free (ret);
967 return NULL; 963 return NULL;
968 } 964 }
969 if (GNUNET_OK != GNUNET_NETWORK_socket_connect (ret->sock, 965 if (GNUNET_OK !=
970 ret->addr, ret->addrlen)) 966 GNUNET_NETWORK_socket_connect (ret->sock, ret->addr, ret->addrlen))
971 { 967 {
972 /* Just return; we expect everything to work eventually so don't fail HARD */ 968 /* Just return; we expect everything to work eventually so don't fail HARD */
973 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret->sock)); 969 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret->sock));
@@ -1004,18 +1000,18 @@ GNUNET_CONNECTION_create_from_sockaddr (int af_family,
1004 s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0); 1000 s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0);
1005 if (s == NULL) 1001 if (s == NULL)
1006 { 1002 {
1007 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING | 1003 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
1008 GNUNET_ERROR_TYPE_BULK, "socket"); 1004 "socket");
1009 return NULL; 1005 return NULL;
1010 } 1006 }
1011 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) 1007 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) &&
1012 && (errno != EINPROGRESS)) 1008 (errno != EINPROGRESS))
1013 { 1009 {
1014 /* maybe refused / unsupported address, try next */ 1010 /* maybe refused / unsupported address, try next */
1015 GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "connect"); 1011 GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "connect");
1016 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1012 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1017 _("Attempt to connect to `%s' failed\n"), 1013 _("Attempt to connect to `%s' failed\n"), GNUNET_a2s (serv_addr,
1018 GNUNET_a2s (serv_addr, addrlen)); 1014 addrlen));
1019 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); 1015 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s));
1020 return NULL; 1016 return NULL;
1021 } 1017 }
@@ -1024,8 +1020,7 @@ GNUNET_CONNECTION_create_from_sockaddr (int af_family,
1024 memcpy (ret->addr, serv_addr, addrlen); 1020 memcpy (ret->addr, serv_addr, addrlen);
1025 ret->addrlen = addrlen; 1021 ret->addrlen = addrlen;
1026#if DEBUG_CONNECTION 1022#if DEBUG_CONNECTION
1027 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1023 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Trying to connect to `%s' (%p)\n"),
1028 _("Trying to connect to `%s' (%p)\n"),
1029 GNUNET_a2s (serv_addr, addrlen), ret); 1024 GNUNET_a2s (serv_addr, addrlen), ret);
1030#endif 1025#endif
1031 return ret; 1026 return ret;
@@ -1157,8 +1152,9 @@ receive_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1158 "Receive from `%s' encounters error: time out by %llums... (%p)\n", 1153 "Receive from `%s' encounters error: time out by %llums... (%p)\n",
1159 GNUNET_a2s (sh->addr, sh->addrlen), 1154 GNUNET_a2s (sh->addr, sh->addrlen),
1160 GNUNET_TIME_absolute_get_duration (sh->receive_timeout). 1155 GNUNET_TIME_absolute_get_duration (sh->
1161 rel_value, sh); 1156 receive_timeout).rel_value,
1157 sh);
1162#endif 1158#endif
1163 signal_timeout (sh); 1159 signal_timeout (sh);
1164 return; 1160 return;
@@ -1181,8 +1177,8 @@ RETRY:
1181 if (errno == EINTR) 1177 if (errno == EINTR)
1182 goto RETRY; 1178 goto RETRY;
1183#if DEBUG_CONNECTION 1179#if DEBUG_CONNECTION
1184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error receiving: %s\n",
1185 "Error receiving: %s\n", STRERROR (errno)); 1181 STRERROR (errno));
1186#endif 1182#endif
1187 signal_error (sh, errno); 1183 signal_error (sh, errno);
1188 return; 1184 return;
@@ -1190,8 +1186,8 @@ RETRY:
1190#if DEBUG_CONNECTION 1186#if DEBUG_CONNECTION
1191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1187 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1192 "receive_ready read %u/%u bytes from `%s' (%p)!\n", 1188 "receive_ready read %u/%u bytes from `%s' (%p)!\n",
1193 (unsigned int) ret, 1189 (unsigned int) ret, sh->max, GNUNET_a2s (sh->addr, sh->addrlen),
1194 sh->max, GNUNET_a2s (sh->addr, sh->addrlen), sh); 1190 sh);
1195#endif 1191#endif
1196 GNUNET_assert (NULL != (receiver = sh->receiver)); 1192 GNUNET_assert (NULL != (receiver = sh->receiver));
1197 sh->receiver = NULL; 1193 sh->receiver = NULL;
@@ -1260,8 +1256,7 @@ receive_again (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1260 * @param receiver_cls closure for receiver 1256 * @param receiver_cls closure for receiver
1261 */ 1257 */
1262void 1258void
1263GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *sock, 1259GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *sock, size_t max,
1264 size_t max,
1265 struct GNUNET_TIME_Relative timeout, 1260 struct GNUNET_TIME_Relative timeout,
1266 GNUNET_CONNECTION_Receiver receiver, 1261 GNUNET_CONNECTION_Receiver receiver,
1267 void *receiver_cls) 1262 void *receiver_cls)
@@ -1358,15 +1353,16 @@ process_notify (struct GNUNET_CONNECTION_Handle *sock)
1358 if (sock->write_buffer_size - sock->write_buffer_off < size) 1353 if (sock->write_buffer_size - sock->write_buffer_off < size)
1359 { 1354 {
1360 /* need to compact */ 1355 /* need to compact */
1361 memmove (sock->write_buffer, 1356 memmove (sock->write_buffer, &sock->write_buffer[sock->write_buffer_pos],
1362 &sock->write_buffer[sock->write_buffer_pos], used); 1357 used);
1363 sock->write_buffer_off -= sock->write_buffer_pos; 1358 sock->write_buffer_off -= sock->write_buffer_pos;
1364 sock->write_buffer_pos = 0; 1359 sock->write_buffer_pos = 0;
1365 } 1360 }
1366 avail = sock->write_buffer_size - sock->write_buffer_off; 1361 avail = sock->write_buffer_size - sock->write_buffer_off;
1367 GNUNET_assert (avail >= size); 1362 GNUNET_assert (avail >= size);
1368 size = notify (sock->nth.notify_ready_cls, 1363 size =
1369 avail, &sock->write_buffer[sock->write_buffer_off]); 1364 notify (sock->nth.notify_ready_cls, avail,
1365 &sock->write_buffer[sock->write_buffer_off]);
1370 GNUNET_assert (size <= avail); 1366 GNUNET_assert (size <= avail);
1371 sock->write_buffer_off += size; 1367 sock->write_buffer_off += size;
1372 return GNUNET_YES; 1368 return GNUNET_YES;
@@ -1397,8 +1393,8 @@ transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1397#if DEBUG_CONNECTION 1393#if DEBUG_CONNECTION
1398 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1394 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1399 "Transmit to `%s:%u/%s' fails, time out reached (%p).\n", 1395 "Transmit to `%s:%u/%s' fails, time out reached (%p).\n",
1400 sock->hostname, 1396 sock->hostname, sock->port, GNUNET_a2s (sock->addr,
1401 sock->port, GNUNET_a2s (sock->addr, sock->addrlen), sock); 1397 sock->addrlen), sock);
1402#endif 1398#endif
1403 GNUNET_assert (0 != (sock->ccs & COCO_TRANSMIT_READY)); 1399 GNUNET_assert (0 != (sock->ccs & COCO_TRANSMIT_READY));
1404 sock->ccs -= COCO_TRANSMIT_READY; /* remove request */ 1400 sock->ccs -= COCO_TRANSMIT_READY; /* remove request */
@@ -1541,8 +1537,8 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1541 if ((sock->nth.notify_ready != NULL) && 1537 if ((sock->nth.notify_ready != NULL) &&
1542 (sock->write_buffer_size < sock->nth.notify_size)) 1538 (sock->write_buffer_size < sock->nth.notify_size))
1543 { 1539 {
1544 sock->write_buffer = GNUNET_realloc (sock->write_buffer, 1540 sock->write_buffer =
1545 sock->nth.notify_size); 1541 GNUNET_realloc (sock->write_buffer, sock->nth.notify_size);
1546 sock->write_buffer_size = sock->nth.notify_size; 1542 sock->write_buffer_size = sock->nth.notify_size;
1547 } 1543 }
1548 process_notify (sock); 1544 process_notify (sock);
@@ -1556,9 +1552,10 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1556 GNUNET_assert (have + sock->write_buffer_pos <= sock->write_buffer_size); 1552 GNUNET_assert (have + sock->write_buffer_pos <= sock->write_buffer_size);
1557 GNUNET_assert (sock->write_buffer_pos <= sock->write_buffer_size); 1553 GNUNET_assert (sock->write_buffer_pos <= sock->write_buffer_size);
1558RETRY: 1554RETRY:
1559 ret = GNUNET_NETWORK_socket_send (sock->sock, 1555 ret =
1560 &sock->write_buffer[sock->write_buffer_pos], 1556 GNUNET_NETWORK_socket_send (sock->sock,
1561 have); 1557 &sock->write_buffer[sock->write_buffer_pos],
1558 have);
1562 if (ret == -1) 1559 if (ret == -1)
1563 { 1560 {
1564 if (errno == EINTR) 1561 if (errno == EINTR)
@@ -1566,8 +1563,7 @@ RETRY:
1566#if 0 1563#if 0
1567 int en = errno; 1564 int en = errno;
1568 1565
1569 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1566 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to send to `%s': %s\n"),
1570 _("Failed to send to `%s': %s\n"),
1571 GNUNET_a2s (sock->addr, sock->addrlen), STRERROR (en)); 1567 GNUNET_a2s (sock->addr, sock->addrlen), STRERROR (en));
1572#endif 1568#endif
1573#if DEBUG_CONNECTION 1569#if DEBUG_CONNECTION
@@ -1579,8 +1575,8 @@ RETRY:
1579#if DEBUG_CONNECTION 1575#if DEBUG_CONNECTION
1580 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1576 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1581 "transmit_ready transmitted %u/%u bytes to `%s' (%p)\n", 1577 "transmit_ready transmitted %u/%u bytes to `%s' (%p)\n",
1582 (unsigned int) ret, 1578 (unsigned int) ret, have, GNUNET_a2s (sock->addr, sock->addrlen),
1583 have, GNUNET_a2s (sock->addr, sock->addrlen), sock); 1579 sock);
1584#endif 1580#endif
1585 sock->write_buffer_pos += ret; 1581 sock->write_buffer_pos += ret;
1586 if (sock->write_buffer_pos == sock->write_buffer_off) 1582 if (sock->write_buffer_pos == sock->write_buffer_off)
@@ -1601,9 +1597,8 @@ SCHEDULE_WRITE:
1601 GNUNET_assert ((sock->nth.notify_ready != NULL) || (have > 0)); 1597 GNUNET_assert ((sock->nth.notify_ready != NULL) || (have > 0));
1602 if (sock->write_task == GNUNET_SCHEDULER_NO_TASK) 1598 if (sock->write_task == GNUNET_SCHEDULER_NO_TASK)
1603 sock->write_task = 1599 sock->write_task =
1604 GNUNET_SCHEDULER_add_write_net ((sock->nth.notify_ready == NULL) 1600 GNUNET_SCHEDULER_add_write_net ((sock->nth.notify_ready ==
1605 ? GNUNET_TIME_UNIT_FOREVER_REL 1601 NULL) ? GNUNET_TIME_UNIT_FOREVER_REL :
1606 :
1607 GNUNET_TIME_absolute_get_remaining 1602 GNUNET_TIME_absolute_get_remaining
1608 (sock->nth.transmit_timeout), 1603 (sock->nth.transmit_timeout),
1609 sock->sock, &transmit_ready, sock); 1604 sock->sock, &transmit_ready, sock);
@@ -1625,8 +1620,8 @@ SCHEDULE_WRITE:
1625 * NULL if we are already going to notify someone else (busy) 1620 * NULL if we are already going to notify someone else (busy)
1626 */ 1621 */
1627struct GNUNET_CONNECTION_TransmitHandle * 1622struct GNUNET_CONNECTION_TransmitHandle *
1628GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle 1623GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *sock,
1629 *sock, size_t size, 1624 size_t size,
1630 struct GNUNET_TIME_Relative timeout, 1625 struct GNUNET_TIME_Relative timeout,
1631 GNUNET_CONNECTION_TransmitReadyNotify 1626 GNUNET_CONNECTION_TransmitReadyNotify
1632 notify, void *notify_cls) 1627 notify, void *notify_cls)
@@ -1647,8 +1642,8 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle
1647 sock->nth.notify_size = size; 1642 sock->nth.notify_size = size;
1648 sock->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute (timeout); 1643 sock->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1649 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->nth.timeout_task); 1644 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->nth.timeout_task);
1650 if ((sock->sock == NULL) && 1645 if ((sock->sock == NULL) && (sock->ap_head == NULL) &&
1651 (sock->ap_head == NULL) && (sock->dns_active == NULL)) 1646 (sock->dns_active == NULL))
1652 { 1647 {
1653 if (sock->write_task != GNUNET_SCHEDULER_NO_TASK) 1648 if (sock->write_task != GNUNET_SCHEDULER_NO_TASK)
1654 GNUNET_SCHEDULER_cancel (sock->write_task); 1649 GNUNET_SCHEDULER_cancel (sock->write_task);
@@ -1660,8 +1655,8 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle
1660 if (sock->sock != NULL) 1655 if (sock->sock != NULL)
1661 { 1656 {
1662#if DEBUG_CONNECTION 1657#if DEBUG_CONNECTION
1663 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1658 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scheduling transmit_ready (%p).\n",
1664 "Scheduling transmit_ready (%p).\n", sock); 1659 sock);
1665#endif 1660#endif
1666 sock->write_task = 1661 sock->write_task =
1667 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining 1662 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining
@@ -1676,9 +1671,8 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle
1676 sock); 1671 sock);
1677#endif 1672#endif
1678 sock->ccs |= COCO_TRANSMIT_READY; 1673 sock->ccs |= COCO_TRANSMIT_READY;
1679 sock->nth.timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, 1674 sock->nth.timeout_task =
1680 &transmit_timeout, 1675 GNUNET_SCHEDULER_add_delayed (timeout, &transmit_timeout, sock);
1681 sock);
1682 } 1676 }
1683 return &sock->nth; 1677 return &sock->nth;
1684} 1678}
diff --git a/src/util/container_bloomfilter.c b/src/util/container_bloomfilter.c
index a0749a18a..ebd056128 100644
--- a/src/util/container_bloomfilter.c
+++ b/src/util/container_bloomfilter.c
@@ -102,8 +102,7 @@ struct GNUNET_CONTAINER_BloomFilter *
102GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter 102GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter
103 *bf) 103 *bf)
104{ 104{
105 return GNUNET_CONTAINER_bloomfilter_init (bf->bitArray, 105 return GNUNET_CONTAINER_bloomfilter_init (bf->bitArray, bf->bitArraySize,
106 bf->bitArraySize,
107 bf->addressesPerElement); 106 bf->addressesPerElement);
108} 107}
109 108
@@ -209,9 +208,8 @@ incrementBit (char *bitArray, unsigned int bitIdx,
209 high++; 208 high++;
210 } 209 }
211 value = ((high << 4) | low); 210 value = ((high << 4) | low);
212 GNUNET_assert (fileSlot == GNUNET_DISK_file_seek (fh, 211 GNUNET_assert (fileSlot ==
213 fileSlot, 212 GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET));
214 GNUNET_DISK_SEEK_SET));
215 GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1)); 213 GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1));
216} 214}
217 215
@@ -348,8 +346,7 @@ iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf,
348 { 346 {
349 while (slot < (sizeof (GNUNET_HashCode) / sizeof (uint32_t))) 347 while (slot < (sizeof (GNUNET_HashCode) / sizeof (uint32_t)))
350 { 348 {
351 callback (arg, 349 callback (arg, bf,
352 bf,
353 (((uint32_t *) & tmp[round & 1])[slot]) & 350 (((uint32_t *) & tmp[round & 1])[slot]) &
354 ((bf->bitArraySize * 8) - 1)); 351 ((bf->bitArraySize * 8) - 1));
355 slot++; 352 slot++;
@@ -375,8 +372,7 @@ iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf,
375 * @param bit the bit to increment 372 * @param bit the bit to increment
376 */ 373 */
377static void 374static void
378incrementBitCallback (void *cls, 375incrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf,
379 const struct GNUNET_CONTAINER_BloomFilter *bf,
380 unsigned int bit) 376 unsigned int bit)
381{ 377{
382 struct GNUNET_CONTAINER_BloomFilter *b = cls; 378 struct GNUNET_CONTAINER_BloomFilter *b = cls;
@@ -392,8 +388,7 @@ incrementBitCallback (void *cls,
392 * @param bit the bit to decrement 388 * @param bit the bit to decrement
393 */ 389 */
394static void 390static void
395decrementBitCallback (void *cls, 391decrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf,
396 const struct GNUNET_CONTAINER_BloomFilter *bf,
397 unsigned int bit) 392 unsigned int bit)
398{ 393{
399 struct GNUNET_CONTAINER_BloomFilter *b = cls; 394 struct GNUNET_CONTAINER_BloomFilter *b = cls;
@@ -409,8 +404,7 @@ decrementBitCallback (void *cls,
409 * @param bit the bit to test 404 * @param bit the bit to test
410 */ 405 */
411static void 406static void
412testBitCallback (void *cls, 407testBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf,
413 const struct GNUNET_CONTAINER_BloomFilter *bf,
414 unsigned int bit) 408 unsigned int bit)
415{ 409{
416 int *arg = cls; 410 int *arg = cls;
@@ -432,8 +426,8 @@ testBitCallback (void *cls,
432 * @return the bloomfilter 426 * @return the bloomfilter
433 */ 427 */
434struct GNUNET_CONTAINER_BloomFilter * 428struct GNUNET_CONTAINER_BloomFilter *
435GNUNET_CONTAINER_bloomfilter_load (const char *filename, 429GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
436 size_t size, unsigned int k) 430 unsigned int k)
437{ 431{
438 struct GNUNET_CONTAINER_BloomFilter *bf; 432 struct GNUNET_CONTAINER_BloomFilter *bf;
439 char *rbuff; 433 char *rbuff;
@@ -453,10 +447,12 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename,
453 447
454 bf = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_BloomFilter)); 448 bf = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_BloomFilter));
455 /* Try to open a bloomfilter file */ 449 /* Try to open a bloomfilter file */
456 bf->fh = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READWRITE 450 bf->fh =
457 | GNUNET_DISK_OPEN_CREATE, 451 GNUNET_DISK_file_open (filename,
458 GNUNET_DISK_PERM_USER_READ | 452 GNUNET_DISK_OPEN_READWRITE |
459 GNUNET_DISK_PERM_USER_WRITE); 453 GNUNET_DISK_OPEN_CREATE,
454 GNUNET_DISK_PERM_USER_READ |
455 GNUNET_DISK_PERM_USER_WRITE);
460 if (NULL == bf->fh) 456 if (NULL == bf->fh)
461 { 457 {
462 GNUNET_free (bf); 458 GNUNET_free (bf);
@@ -487,8 +483,8 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename,
487 res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE); 483 res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE);
488 if (res == -1) 484 if (res == -1)
489 { 485 {
490 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 486 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "read",
491 "read", bf->filename); 487 bf->filename);
492 } 488 }
493 if (res == 0) 489 if (res == 0)
494 break; /* is ok! we just did not use that many bits yet */ 490 break; /* is ok! we just did not use that many bits yet */
@@ -522,8 +518,8 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename,
522 * @return the bloomfilter 518 * @return the bloomfilter
523 */ 519 */
524struct GNUNET_CONTAINER_BloomFilter * 520struct GNUNET_CONTAINER_BloomFilter *
525GNUNET_CONTAINER_bloomfilter_init (const char *data, 521GNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size,
526 size_t size, unsigned int k) 522 unsigned int k)
527{ 523{
528 struct GNUNET_CONTAINER_BloomFilter *bf; 524 struct GNUNET_CONTAINER_BloomFilter *bf;
529 size_t ui; 525 size_t ui;
@@ -752,8 +748,8 @@ GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf,
752void 748void
753GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf, 749GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf,
754 GNUNET_HashCodeIterator iterator, 750 GNUNET_HashCodeIterator iterator,
755 void *iterator_cls, 751 void *iterator_cls, size_t size,
756 size_t size, unsigned int k) 752 unsigned int k)
757{ 753{
758 GNUNET_HashCode hc; 754 GNUNET_HashCode hc;
759 unsigned int i; 755 unsigned int i;
diff --git a/src/util/container_heap.c b/src/util/container_heap.c
index c1d478e06..ef6bcc892 100644
--- a/src/util/container_heap.c
+++ b/src/util/container_heap.c
@@ -218,11 +218,11 @@ node_iterator (const struct GNUNET_CONTAINER_Heap *heap,
218{ 218{
219 if (node == NULL) 219 if (node == NULL)
220 return GNUNET_YES; 220 return GNUNET_YES;
221 if (GNUNET_YES != node_iterator (heap, 221 if (GNUNET_YES !=
222 node->left_child, iterator, iterator_cls)) 222 node_iterator (heap, node->left_child, iterator, iterator_cls))
223 return GNUNET_NO; 223 return GNUNET_NO;
224 if (GNUNET_YES != node_iterator (heap, 224 if (GNUNET_YES !=
225 node->right_child, iterator, iterator_cls)) 225 node_iterator (heap, node->right_child, iterator, iterator_cls))
226 return GNUNET_NO; 226 return GNUNET_NO;
227 return iterator (iterator_cls, node, node->element, node->cost); 227 return iterator (iterator_cls, node, node->element, node->cost);
228} 228}
@@ -267,9 +267,10 @@ GNUNET_CONTAINER_heap_walk_get_next (struct GNUNET_CONTAINER_Heap *heap)
267 if (pos == NULL) 267 if (pos == NULL)
268 pos = heap->root; 268 pos = heap->root;
269 element = pos->element; 269 element = pos->element;
270 heap->walk_pos 270 heap->walk_pos =
271 = (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2)) 271 (0 ==
272 ? pos->right_child : pos->left_child; 272 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
273 2)) ? pos->right_child : pos->left_child;
273 return element; 274 return element;
274} 275}
275 276
@@ -290,8 +291,12 @@ insert_node (struct GNUNET_CONTAINER_Heap *heap,
290 struct GNUNET_CONTAINER_HeapNode *parent; 291 struct GNUNET_CONTAINER_HeapNode *parent;
291 292
292 GNUNET_assert (node->parent == NULL); 293 GNUNET_assert (node->parent == NULL);
293 while ((heap->order == GNUNET_CONTAINER_HEAP_ORDER_MAX) 294 while ((heap->order == GNUNET_CONTAINER_HEAP_ORDER_MAX) ? (pos->cost >=
294 ? (pos->cost >= node->cost) : (pos->cost <= node->cost)) 295 node->
296 cost) : (pos->
297 cost <=
298 node->
299 cost))
295 { 300 {
296 /* node is descendent of pos */ 301 /* node is descendent of pos */
297 pos->tree_size += (1 + node->tree_size); 302 pos->tree_size += (1 + node->tree_size);
@@ -343,8 +348,8 @@ insert_node (struct GNUNET_CONTAINER_Heap *heap,
343 * @return node for the new element 348 * @return node for the new element
344 */ 349 */
345struct GNUNET_CONTAINER_HeapNode * 350struct GNUNET_CONTAINER_HeapNode *
346GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap, 351GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap, void *element,
347 void *element, GNUNET_CONTAINER_HeapCostType cost) 352 GNUNET_CONTAINER_HeapCostType cost)
348{ 353{
349 struct GNUNET_CONTAINER_HeapNode *node; 354 struct GNUNET_CONTAINER_HeapNode *node;
350 355
@@ -399,8 +404,7 @@ GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *heap)
399 } 404 }
400 GNUNET_free (root); 405 GNUNET_free (root);
401#if DEBUG 406#if DEBUG
402 GNUNET_assert (((heap->size == 0) && 407 GNUNET_assert (((heap->size == 0) && (heap->root == NULL)) ||
403 (heap->root == NULL)) ||
404 (heap->size == heap->root->tree_size + 1)); 408 (heap->size == heap->root->tree_size + 1));
405 CHECK (heap->root); 409 CHECK (heap->root);
406#endif 410#endif
@@ -502,8 +506,7 @@ GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_HeapNode *node)
502 GNUNET_free (node); 506 GNUNET_free (node);
503#if DEBUG 507#if DEBUG
504 CHECK (heap->root); 508 CHECK (heap->root);
505 GNUNET_assert (((heap->size == 0) && 509 GNUNET_assert (((heap->size == 0) && (heap->root == NULL)) ||
506 (heap->root == NULL)) ||
507 (heap->size == heap->root->tree_size + 1)); 510 (heap->size == heap->root->tree_size + 1));
508#endif 511#endif
509 return ret; 512 return ret;
@@ -523,16 +526,14 @@ GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap,
523 GNUNET_CONTAINER_HeapCostType new_cost) 526 GNUNET_CONTAINER_HeapCostType new_cost)
524{ 527{
525#if DEBUG 528#if DEBUG
526 GNUNET_assert (((heap->size == 0) && 529 GNUNET_assert (((heap->size == 0) && (heap->root == NULL)) ||
527 (heap->root == NULL)) ||
528 (heap->size == heap->root->tree_size + 1)); 530 (heap->size == heap->root->tree_size + 1));
529 CHECK (heap->root); 531 CHECK (heap->root);
530#endif 532#endif
531 remove_node (node); 533 remove_node (node);
532#if DEBUG 534#if DEBUG
533 CHECK (heap->root); 535 CHECK (heap->root);
534 GNUNET_assert (((heap->size == 1) && 536 GNUNET_assert (((heap->size == 1) && (heap->root == NULL)) ||
535 (heap->root == NULL)) ||
536 (heap->size == heap->root->tree_size + 2)); 537 (heap->size == heap->root->tree_size + 2));
537#endif 538#endif
538 node->cost = new_cost; 539 node->cost = new_cost;
@@ -542,8 +543,7 @@ GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap,
542 insert_node (heap, heap->root, node); 543 insert_node (heap, heap->root, node);
543#if DEBUG 544#if DEBUG
544 CHECK (heap->root); 545 CHECK (heap->root);
545 GNUNET_assert (((heap->size == 0) && 546 GNUNET_assert (((heap->size == 0) && (heap->root == NULL)) ||
546 (heap->root == NULL)) ||
547 (heap->size == heap->root->tree_size + 1)); 547 (heap->size == heap->root->tree_size + 1));
548#endif 548#endif
549} 549}
diff --git a/src/util/container_meta_data.c b/src/util/container_meta_data.c
index 64a58e133..c67e96dac 100644
--- a/src/util/container_meta_data.c
+++ b/src/util/container_meta_data.c
@@ -224,8 +224,7 @@ GNUNET_CONTAINER_meta_data_test_equal (const struct GNUNET_CONTAINER_MetaData
224 j = md2->items; 224 j = md2->items;
225 while (NULL != j) 225 while (NULL != j)
226 { 226 {
227 if ((i->type == j->type) && 227 if ((i->type == j->type) && (i->format == j->format) &&
228 (i->format == j->format) &&
229 (i->data_size == j->data_size) && 228 (i->data_size == j->data_size) &&
230 (0 == memcmp (i->data, j->data, i->data_size))) 229 (0 == memcmp (i->data, j->data, i->data_size)))
231 { 230 {
@@ -265,8 +264,8 @@ GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md,
265 const char *plugin_name, 264 const char *plugin_name,
266 enum EXTRACTOR_MetaType type, 265 enum EXTRACTOR_MetaType type,
267 enum EXTRACTOR_MetaFormat format, 266 enum EXTRACTOR_MetaFormat format,
268 const char *data_mime_type, 267 const char *data_mime_type, const char *data,
269 const char *data, size_t data_len) 268 size_t data_len)
270{ 269{
271 struct MetaItem *prev; 270 struct MetaItem *prev;
272 struct MetaItem *pos; 271 struct MetaItem *pos;
@@ -279,8 +278,7 @@ GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md,
279 { 278 {
280 if (pos->data_size < data_len) 279 if (pos->data_size < data_len)
281 break; 280 break;
282 if ((pos->type == type) && 281 if ((pos->type == type) && (pos->data_size == data_len) &&
283 (pos->data_size == data_len) &&
284 (0 == memcmp (pos->data, data, data_len))) 282 (0 == memcmp (pos->data, data, data_len)))
285 { 283 {
286 if ((pos->mime_type == NULL) && (data_mime_type != NULL)) 284 if ((pos->mime_type == NULL) && (data_mime_type != NULL))
@@ -349,16 +347,13 @@ GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md,
349 * @return 0 (to continue) 347 * @return 0 (to continue)
350 */ 348 */
351static int 349static int
352merge_helper (void *cls, 350merge_helper (void *cls, const char *plugin_name, enum EXTRACTOR_MetaType type,
353 const char *plugin_name, 351 enum EXTRACTOR_MetaFormat format, const char *data_mime_type,
354 enum EXTRACTOR_MetaType type, 352 const char *data, size_t data_len)
355 enum EXTRACTOR_MetaFormat format,
356 const char *data_mime_type, const char *data, size_t data_len)
357{ 353{
358 struct GNUNET_CONTAINER_MetaData *md = cls; 354 struct GNUNET_CONTAINER_MetaData *md = cls;
359 355
360 (void) GNUNET_CONTAINER_meta_data_insert (md, plugin_name, 356 (void) GNUNET_CONTAINER_meta_data_insert (md, plugin_name, type, format,
361 type, format,
362 data_mime_type, data, data_len); 357 data_mime_type, data, data_len);
363 return 0; 358 return 0;
364} 359}
@@ -436,15 +431,13 @@ GNUNET_CONTAINER_meta_data_add_publication_date (struct
436 struct GNUNET_TIME_Absolute t; 431 struct GNUNET_TIME_Absolute t;
437 432
438 t = GNUNET_TIME_absolute_get (); 433 t = GNUNET_TIME_absolute_get ();
439 GNUNET_CONTAINER_meta_data_delete (md, 434 GNUNET_CONTAINER_meta_data_delete (md, EXTRACTOR_METATYPE_PUBLICATION_DATE,
440 EXTRACTOR_METATYPE_PUBLICATION_DATE,
441 NULL, 0); 435 NULL, 0);
442 dat = GNUNET_STRINGS_absolute_time_to_string (t); 436 dat = GNUNET_STRINGS_absolute_time_to_string (t);
443 GNUNET_CONTAINER_meta_data_insert (md, 437 GNUNET_CONTAINER_meta_data_insert (md, "<gnunet>",
444 "<gnunet>",
445 EXTRACTOR_METATYPE_PUBLICATION_DATE, 438 EXTRACTOR_METATYPE_PUBLICATION_DATE,
446 EXTRACTOR_METAFORMAT_UTF8, 439 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
447 "text/plain", dat, strlen (dat) + 1); 440 dat, strlen (dat) + 1);
448 GNUNET_free (dat); 441 GNUNET_free (dat);
449} 442}
450 443
@@ -458,10 +451,9 @@ GNUNET_CONTAINER_meta_data_add_publication_date (struct
458 * @return number of entries 451 * @return number of entries
459 */ 452 */
460int 453int
461GNUNET_CONTAINER_meta_data_iterate (const struct 454GNUNET_CONTAINER_meta_data_iterate (const struct GNUNET_CONTAINER_MetaData *md,
462 GNUNET_CONTAINER_MetaData *md, 455 EXTRACTOR_MetaDataProcessor iter,
463 EXTRACTOR_MetaDataProcessor 456 void *iter_cls)
464 iter, void *iter_cls)
465{ 457{
466 struct MetaItem *pos; 458 struct MetaItem *pos;
467 459
@@ -472,10 +464,9 @@ GNUNET_CONTAINER_meta_data_iterate (const struct
472 pos = md->items; 464 pos = md->items;
473 while (NULL != pos) 465 while (NULL != pos)
474 { 466 {
475 if (0 != iter (iter_cls, 467 if (0 !=
476 pos->plugin_name, 468 iter (iter_cls, pos->plugin_name, pos->type, pos->format,
477 pos->type, 469 pos->mime_type, pos->data, pos->data_size))
478 pos->format, pos->mime_type, pos->data, pos->data_size))
479 return md->item_count; 470 return md->item_count;
480 pos = pos->next; 471 pos = pos->next;
481 } 472 }
@@ -562,9 +553,8 @@ GNUNET_CONTAINER_meta_data_get_first_by_types (const struct
562 * @return number of bytes in thumbnail, 0 if not available 553 * @return number of bytes in thumbnail, 0 if not available
563 */ 554 */
564size_t 555size_t
565GNUNET_CONTAINER_meta_data_get_thumbnail (const struct 556GNUNET_CONTAINER_meta_data_get_thumbnail (const struct GNUNET_CONTAINER_MetaData
566 GNUNET_CONTAINER_MetaData * md, 557 * md, unsigned char **thumb)
567 unsigned char **thumb)
568{ 558{
569 struct MetaItem *pos; 559 struct MetaItem *pos;
570 struct MetaItem *match; 560 struct MetaItem *match;
@@ -576,8 +566,7 @@ GNUNET_CONTAINER_meta_data_get_thumbnail (const struct
576 while (NULL != pos) 566 while (NULL != pos)
577 { 567 {
578 if ((NULL != pos->mime_type) && 568 if ((NULL != pos->mime_type) &&
579 (0 == strncasecmp ("image/", pos->mime_type, 569 (0 == strncasecmp ("image/", pos->mime_type, strlen ("image/"))) &&
580 strlen ("image/"))) &&
581 (pos->format == EXTRACTOR_METAFORMAT_BINARY)) 570 (pos->format == EXTRACTOR_METAFORMAT_BINARY))
582 { 571 {
583 if (match == NULL) 572 if (match == NULL)
@@ -615,12 +604,9 @@ GNUNET_CONTAINER_meta_data_duplicate (const struct GNUNET_CONTAINER_MetaData
615 pos = md->items; 604 pos = md->items;
616 while (NULL != pos) 605 while (NULL != pos)
617 { 606 {
618 GNUNET_CONTAINER_meta_data_insert (ret, 607 GNUNET_CONTAINER_meta_data_insert (ret, pos->plugin_name, pos->type,
619 pos->plugin_name, 608 pos->format, pos->mime_type, pos->data,
620 pos->type, 609 pos->data_size);
621 pos->format,
622 pos->mime_type,
623 pos->data, pos->data_size);
624 pos = pos->next; 610 pos = pos->next;
625 } 611 }
626 return ret; 612 return ret;
@@ -642,8 +628,8 @@ GNUNET_CONTAINER_meta_data_duplicate (const struct GNUNET_CONTAINER_MetaData
642 * GNUNET_NO if compression did not help 628 * GNUNET_NO if compression did not help
643 */ 629 */
644static int 630static int
645try_compression (const char *data, 631try_compression (const char *data, size_t oldSize, char **result,
646 size_t oldSize, char **result, size_t * newSize) 632 size_t * newSize)
647{ 633{
648 char *tmp; 634 char *tmp;
649 uLongf dlen; 635 uLongf dlen;
@@ -656,8 +642,8 @@ try_compression (const char *data,
656 * should be able to overshoot by more to be safe */ 642 * should be able to overshoot by more to be safe */
657#endif 643#endif
658 tmp = GNUNET_malloc (dlen); 644 tmp = GNUNET_malloc (dlen);
659 if (Z_OK == compress2 ((Bytef *) tmp, 645 if (Z_OK ==
660 &dlen, (const Bytef *) data, oldSize, 9)) 646 compress2 ((Bytef *) tmp, &dlen, (const Bytef *) data, oldSize, 9))
661 { 647 {
662 if (dlen < oldSize) 648 if (dlen < oldSize)
663 { 649 {
@@ -990,10 +976,9 @@ GNUNET_CONTAINER_meta_data_get_serialized_size (const struct
990 if (md->sbuf != NULL) 976 if (md->sbuf != NULL)
991 return md->sbuf_size; 977 return md->sbuf_size;
992 ptr = NULL; 978 ptr = NULL;
993 ret = GNUNET_CONTAINER_meta_data_serialize (md, 979 ret =
994 &ptr, 980 GNUNET_CONTAINER_meta_data_serialize (md, &ptr, GNUNET_MAX_MALLOC_CHECKED,
995 GNUNET_MAX_MALLOC_CHECKED, 981 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL);
996 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL);
997 if (ret != -1) 982 if (ret != -1)
998 GNUNET_free (ptr); 983 GNUNET_free (ptr);
999 return ret; 984 return ret;
@@ -1018,8 +1003,8 @@ decompress (const char *input, size_t inputSize, size_t outputSize)
1018 1003
1019 olen = outputSize; 1004 olen = outputSize;
1020 output = GNUNET_malloc (olen); 1005 output = GNUNET_malloc (olen);
1021 if (Z_OK == uncompress ((Bytef *) output, 1006 if (Z_OK ==
1022 &olen, (const Bytef *) input, inputSize)) 1007 uncompress ((Bytef *) output, &olen, (const Bytef *) input, inputSize))
1023 { 1008 {
1024 return output; 1009 return output;
1025 } 1010 }
@@ -1119,8 +1104,7 @@ GNUNET_CONTAINER_meta_data_deserialize (const char *input, size_t size)
1119 mdata = &cdata[ic * sizeof (struct MetaDataEntry)]; 1104 mdata = &cdata[ic * sizeof (struct MetaDataEntry)];
1120 for (i = 0; i < ic; i++) 1105 for (i = 0; i < ic; i++)
1121 { 1106 {
1122 memcpy (&ent, 1107 memcpy (&ent, &cdata[i * sizeof (struct MetaDataEntry)],
1123 &cdata[i * sizeof (struct MetaDataEntry)],
1124 sizeof (struct MetaDataEntry)); 1108 sizeof (struct MetaDataEntry));
1125 format = (enum EXTRACTOR_MetaFormat) ntohl (ent.format); 1109 format = (enum EXTRACTOR_MetaFormat) ntohl (ent.format);
1126 if ((format != EXTRACTOR_METAFORMAT_UTF8) && 1110 if ((format != EXTRACTOR_METAFORMAT_UTF8) &&
@@ -1180,11 +1164,10 @@ GNUNET_CONTAINER_meta_data_deserialize (const char *input, size_t size)
1180 mime_type = NULL; 1164 mime_type = NULL;
1181 else 1165 else
1182 mime_type = &mdata[left]; 1166 mime_type = &mdata[left];
1183 GNUNET_CONTAINER_meta_data_insert (md, 1167 GNUNET_CONTAINER_meta_data_insert (md, plugin_name,
1184 plugin_name, 1168 (enum EXTRACTOR_MetaType) ntohl (ent.
1185 (enum EXTRACTOR_MetaType) 1169 type),
1186 ntohl (ent.type), format, mime_type, 1170 format, mime_type, meta_data, dlen);
1187 meta_data, dlen);
1188 } 1171 }
1189 GNUNET_free_non_null (data); 1172 GNUNET_free_non_null (data);
1190 return md; 1173 return md;
diff --git a/src/util/container_multihashmap.c b/src/util/container_multihashmap.c
index 9635af17d..974d6c7f7 100644
--- a/src/util/container_multihashmap.c
+++ b/src/util/container_multihashmap.c
@@ -230,9 +230,8 @@ GNUNET_CONTAINER_multihashmap_iterate (const struct
230 * is not in the map 230 * is not in the map
231 */ 231 */
232int 232int
233GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap 233GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map,
234 *map, const GNUNET_HashCode * key, 234 const GNUNET_HashCode * key, void *value)
235 void *value)
236{ 235{
237 struct MapEntry *e; 236 struct MapEntry *e;
238 struct MapEntry *p; 237 struct MapEntry *p;
@@ -348,8 +347,7 @@ GNUNET_CONTAINER_multihashmap_contains (const struct
348int 347int
349GNUNET_CONTAINER_multihashmap_contains_value (const struct 348GNUNET_CONTAINER_multihashmap_contains_value (const struct
350 GNUNET_CONTAINER_MultiHashMap 349 GNUNET_CONTAINER_MultiHashMap
351 *map, 350 *map, const GNUNET_HashCode * key,
352 const GNUNET_HashCode * key,
353 const void *value) 351 const void *value)
354{ 352{
355 struct MapEntry *e; 353 struct MapEntry *e;
@@ -416,8 +414,7 @@ grow (struct GNUNET_CONTAINER_MultiHashMap *map)
416 */ 414 */
417int 415int
418GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map, 416GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map,
419 const GNUNET_HashCode * key, 417 const GNUNET_HashCode * key, void *value,
420 void *value,
421 enum GNUNET_CONTAINER_MultiHashMapOption opt) 418 enum GNUNET_CONTAINER_MultiHashMapOption opt)
422{ 419{
423 struct MapEntry *e; 420 struct MapEntry *e;
@@ -467,10 +464,10 @@ GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map,
467 */ 464 */
468int 465int
469GNUNET_CONTAINER_multihashmap_get_multiple (const struct 466GNUNET_CONTAINER_multihashmap_get_multiple (const struct
470 GNUNET_CONTAINER_MultiHashMap 467 GNUNET_CONTAINER_MultiHashMap *map,
471 *map, const GNUNET_HashCode * key, 468 const GNUNET_HashCode * key,
472 GNUNET_CONTAINER_HashMapIterator 469 GNUNET_CONTAINER_HashMapIterator it,
473 it, void *it_cls) 470 void *it_cls)
474{ 471{
475 int count; 472 int count;
476 struct MapEntry *e; 473 struct MapEntry *e;
diff --git a/src/util/container_slist.c b/src/util/container_slist.c
index c06d70e91..2d7c24c03 100644
--- a/src/util/container_slist.c
+++ b/src/util/container_slist.c
@@ -107,8 +107,8 @@ struct GNUNET_CONTAINER_SList_Iterator
107 * @return a new element 107 * @return a new element
108 */ 108 */
109static struct GNUNET_CONTAINER_SList_Elem * 109static struct GNUNET_CONTAINER_SList_Elem *
110create_elem (enum GNUNET_CONTAINER_SListDisposition disp, 110create_elem (enum GNUNET_CONTAINER_SListDisposition disp, const void *buf,
111 const void *buf, size_t len) 111 size_t len)
112{ 112{
113 struct GNUNET_CONTAINER_SList_Elem *e; 113 struct GNUNET_CONTAINER_SList_Elem *e;
114 114
@@ -186,8 +186,9 @@ GNUNET_CONTAINER_slist_append (struct GNUNET_CONTAINER_SList *dst,
186{ 186{
187 struct GNUNET_CONTAINER_SList_Iterator *i; 187 struct GNUNET_CONTAINER_SList_Iterator *i;
188 188
189 for (i = GNUNET_CONTAINER_slist_begin (src); GNUNET_CONTAINER_slist_end (i) != 189 for (i = GNUNET_CONTAINER_slist_begin (src);
190 GNUNET_YES; GNUNET_CONTAINER_slist_next (i)) 190 GNUNET_CONTAINER_slist_end (i) != GNUNET_YES;
191 GNUNET_CONTAINER_slist_next (i))
191 192
192 { 193 {
193 GNUNET_CONTAINER_slist_add (dst, 194 GNUNET_CONTAINER_slist_add (dst,
diff --git a/src/util/crypto_aes.c b/src/util/crypto_aes.c
index 200c367c1..a984e17fc 100644
--- a/src/util/crypto_aes.c
+++ b/src/util/crypto_aes.c
@@ -73,12 +73,11 @@ GNUNET_CRYPTO_aes_check_session_key (const struct GNUNET_CRYPTO_AesSessionKey
73 * @returns the size of the encrypted block, -1 for errors 73 * @returns the size of the encrypted block, -1 for errors
74 */ 74 */
75ssize_t 75ssize_t
76GNUNET_CRYPTO_aes_encrypt (const void *block, 76GNUNET_CRYPTO_aes_encrypt (const void *block, size_t len,
77 size_t len, 77 const struct GNUNET_CRYPTO_AesSessionKey *
78 const struct GNUNET_CRYPTO_AesSessionKey 78 sessionkey,
79 * sessionkey, 79 const struct GNUNET_CRYPTO_AesInitializationVector *
80 const struct GNUNET_CRYPTO_AesInitializationVector 80 iv, void *result)
81 * iv, void *result)
82{ 81{
83 gcry_cipher_hd_t handle; 82 gcry_cipher_hd_t handle;
84 int rc; 83 int rc;
@@ -89,9 +88,9 @@ GNUNET_CRYPTO_aes_encrypt (const void *block,
89 GNUNET_break (0); 88 GNUNET_break (0);
90 return -1; 89 return -1;
91 } 90 }
92 GNUNET_assert (0 == gcry_cipher_open (&handle, 91 GNUNET_assert (0 ==
93 GCRY_CIPHER_AES256, 92 gcry_cipher_open (&handle, GCRY_CIPHER_AES256,
94 GCRY_CIPHER_MODE_CFB, 0)); 93 GCRY_CIPHER_MODE_CFB, 0));
95 rc = gcry_cipher_setkey (handle, sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH); 94 rc = gcry_cipher_setkey (handle, sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH);
96 GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); 95 GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
97 rc = gcry_cipher_setiv (handle, iv, 96 rc = gcry_cipher_setiv (handle, iv,
@@ -115,12 +114,11 @@ GNUNET_CRYPTO_aes_encrypt (const void *block,
115 * @return -1 on failure, size of decrypted block on success 114 * @return -1 on failure, size of decrypted block on success
116 */ 115 */
117ssize_t 116ssize_t
118GNUNET_CRYPTO_aes_decrypt (const void *block, 117GNUNET_CRYPTO_aes_decrypt (const void *block, size_t size,
119 size_t size, 118 const struct GNUNET_CRYPTO_AesSessionKey *
120 const struct GNUNET_CRYPTO_AesSessionKey 119 sessionkey,
121 * sessionkey, 120 const struct GNUNET_CRYPTO_AesInitializationVector *
122 const struct GNUNET_CRYPTO_AesInitializationVector 121 iv, void *result)
123 * iv, void *result)
124{ 122{
125 gcry_cipher_hd_t handle; 123 gcry_cipher_hd_t handle;
126 int rc; 124 int rc;
@@ -131,9 +129,9 @@ GNUNET_CRYPTO_aes_decrypt (const void *block,
131 GNUNET_break (0); 129 GNUNET_break (0);
132 return -1; 130 return -1;
133 } 131 }
134 GNUNET_assert (0 == gcry_cipher_open (&handle, 132 GNUNET_assert (0 ==
135 GCRY_CIPHER_AES256, 133 gcry_cipher_open (&handle, GCRY_CIPHER_AES256,
136 GCRY_CIPHER_MODE_CFB, 0)); 134 GCRY_CIPHER_MODE_CFB, 0));
137 rc = gcry_cipher_setkey (handle, sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH); 135 rc = gcry_cipher_setkey (handle, sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH);
138 GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); 136 GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
139 rc = gcry_cipher_setiv (handle, iv, 137 rc = gcry_cipher_setiv (handle, iv,
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c
index c693ed081..6438784ba 100644
--- a/src/util/crypto_hash.c
+++ b/src/util/crypto_hash.c
@@ -175,8 +175,7 @@ file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
175 */ 175 */
176struct GNUNET_CRYPTO_FileHashContext * 176struct GNUNET_CRYPTO_FileHashContext *
177GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority, 177GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority,
178 const char *filename, 178 const char *filename, size_t blocksize,
179 size_t blocksize,
180 GNUNET_CRYPTO_HashCompletedCallback callback, 179 GNUNET_CRYPTO_HashCompletedCallback callback,
181 void *callback_cls) 180 void *callback_cls)
182{ 181{
@@ -202,17 +201,17 @@ GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority,
202 GNUNET_free (fhc); 201 GNUNET_free (fhc);
203 return NULL; 202 return NULL;
204 } 203 }
205 fhc->fh = GNUNET_DISK_file_open (filename, 204 fhc->fh =
206 GNUNET_DISK_OPEN_READ, 205 GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ,
207 GNUNET_DISK_PERM_NONE); 206 GNUNET_DISK_PERM_NONE);
208 if (!fhc->fh) 207 if (!fhc->fh)
209 { 208 {
210 GNUNET_free (fhc->filename); 209 GNUNET_free (fhc->filename);
211 GNUNET_free (fhc); 210 GNUNET_free (fhc);
212 return NULL; 211 return NULL;
213 } 212 }
214 fhc->task 213 fhc->task =
215 = GNUNET_SCHEDULER_add_with_priority (priority, &file_hash_task, fhc); 214 GNUNET_SCHEDULER_add_with_priority (priority, &file_hash_task, fhc);
216 return fhc; 215 return fhc;
217} 216}
218 217
@@ -390,8 +389,8 @@ GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a,
390 389
391 390
392void 391void
393GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, 392GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, const GNUNET_HashCode * b,
394 const GNUNET_HashCode * b, GNUNET_HashCode * result) 393 GNUNET_HashCode * result)
395{ 394{
396 int i; 395 int i;
397 396
@@ -542,12 +541,11 @@ GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key,
542void 541void
543GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key, 542GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key,
544 const struct GNUNET_CRYPTO_AesSessionKey *rkey, 543 const struct GNUNET_CRYPTO_AesSessionKey *rkey,
545 const void *salt, 544 const void *salt, size_t salt_len,
546 size_t salt_len, va_list argp) 545 va_list argp)
547{ 546{
548 GNUNET_CRYPTO_kdf_v (key->key, 547 GNUNET_CRYPTO_kdf_v (key->key, sizeof (key->key), salt, salt_len, rkey->key,
549 sizeof (key->key), 548 sizeof (rkey->key), argp);
550 salt, salt_len, rkey->key, sizeof (rkey->key), argp);
551} 549}
552 550
553 551
@@ -561,15 +559,14 @@ GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key,
561 */ 559 */
562void 560void
563GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key, 561GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
564 const void *plaintext, 562 const void *plaintext, size_t plaintext_len,
565 size_t plaintext_len, GNUNET_HashCode * hmac) 563 GNUNET_HashCode * hmac)
566{ 564{
567 gcry_md_hd_t md; 565 gcry_md_hd_t md;
568 const unsigned char *mc; 566 const unsigned char *mc;
569 567
570 GNUNET_assert (GPG_ERR_NO_ERROR == gcry_md_open (&md, 568 GNUNET_assert (GPG_ERR_NO_ERROR ==
571 GCRY_MD_SHA512, 569 gcry_md_open (&md, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC));
572 GCRY_MD_FLAG_HMAC));
573 gcry_md_setkey (md, key->key, sizeof (key->key)); 570 gcry_md_setkey (md, key->key, sizeof (key->key));
574 gcry_md_write (md, plaintext, plaintext_len); 571 gcry_md_write (md, plaintext, plaintext_len);
575 mc = gcry_md_read (md, GCRY_MD_SHA512); 572 mc = gcry_md_read (md, GCRY_MD_SHA512);
diff --git a/src/util/crypto_hkdf.c b/src/util/crypto_hkdf.c
index d97f516fe..0654b51f6 100644
--- a/src/util/crypto_hkdf.c
+++ b/src/util/crypto_hkdf.c
@@ -71,8 +71,8 @@
71 * @return HMAC, freed by caller via gcry_md_close/_reset 71 * @return HMAC, freed by caller via gcry_md_close/_reset
72 */ 72 */
73static const void * 73static const void *
74doHMAC (gcry_md_hd_t mac, 74doHMAC (gcry_md_hd_t mac, const void *key, size_t key_len, const void *buf,
75 const void *key, size_t key_len, const void *buf, size_t buf_len) 75 size_t buf_len)
76{ 76{
77 gcry_md_setkey (mac, key, key_len); 77 gcry_md_setkey (mac, key, key_len);
78 gcry_md_write (mac, buf, buf_len); 78 gcry_md_write (mac, buf, buf_len);
@@ -91,9 +91,8 @@ doHMAC (gcry_md_hd_t mac,
91 * @return GNUNET_YES on success 91 * @return GNUNET_YES on success
92 */ 92 */
93static int 93static int
94getPRK (gcry_md_hd_t mac, 94getPRK (gcry_md_hd_t mac, const void *xts, size_t xts_len, const void *skm,
95 const void *xts, size_t xts_len, 95 size_t skm_len, void *prk)
96 const void *skm, size_t skm_len, void *prk)
97{ 96{
98 const void *ret; 97 const void *ret;
99 98
@@ -136,10 +135,9 @@ dump (const char *src, const void *p, unsigned int l)
136 * @return GNUNET_YES on success 135 * @return GNUNET_YES on success
137 */ 136 */
138int 137int
139GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, 138GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, int prf_algo,
140 int xtr_algo, int prf_algo, 139 const void *xts, size_t xts_len, const void *skm,
141 const void *xts, size_t xts_len, 140 size_t skm_len, va_list argp)
142 const void *skm, size_t skm_len, va_list argp)
143{ 141{
144 const void *hc; 142 const void *hc;
145 unsigned long i, t, d; 143 unsigned long i, t, d;
@@ -280,17 +278,17 @@ hkdf_ok:
280 * @return GNUNET_YES on success 278 * @return GNUNET_YES on success
281 */ 279 */
282int 280int
283GNUNET_CRYPTO_hkdf (void *result, size_t out_len, 281GNUNET_CRYPTO_hkdf (void *result, size_t out_len, int xtr_algo, int prf_algo,
284 int xtr_algo, int prf_algo, 282 const void *xts, size_t xts_len, const void *skm,
285 const void *xts, size_t xts_len, 283 size_t skm_len, ...)
286 const void *skm, size_t skm_len, ...)
287{ 284{
288 va_list argp; 285 va_list argp;
289 int ret; 286 int ret;
290 287
291 va_start (argp, skm_len); 288 va_start (argp, skm_len);
292 ret = GNUNET_CRYPTO_hkdf_v (result, out_len, xtr_algo, prf_algo, xts, 289 ret =
293 xts_len, skm, skm_len, argp); 290 GNUNET_CRYPTO_hkdf_v (result, out_len, xtr_algo, prf_algo, xts, xts_len,
291 skm, skm_len, argp);
294 va_end (argp); 292 va_end (argp);
295 293
296 return ret; 294 return ret;
diff --git a/src/util/crypto_kdf.c b/src/util/crypto_kdf.c
index dc2e667af..cd665ad23 100644
--- a/src/util/crypto_kdf.c
+++ b/src/util/crypto_kdf.c
@@ -41,9 +41,9 @@
41 * @return GNUNET_YES on success 41 * @return GNUNET_YES on success
42 */ 42 */
43int 43int
44GNUNET_CRYPTO_kdf_v (void *result, size_t out_len, 44GNUNET_CRYPTO_kdf_v (void *result, size_t out_len, const void *xts,
45 const void *xts, size_t xts_len, const void *skm, 45 size_t xts_len, const void *skm, size_t skm_len,
46 size_t skm_len, va_list argp) 46 va_list argp)
47{ 47{
48 /* 48 /*
49 * "Finally, we point out to a particularly advantageous instantiation using 49 * "Finally, we point out to a particularly advantageous instantiation using
@@ -73,9 +73,8 @@ GNUNET_CRYPTO_kdf_v (void *result, size_t out_len,
73 * @return GNUNET_YES on success 73 * @return GNUNET_YES on success
74 */ 74 */
75int 75int
76GNUNET_CRYPTO_kdf (void *result, size_t out_len, 76GNUNET_CRYPTO_kdf (void *result, size_t out_len, const void *xts,
77 const void *xts, size_t xts_len, const void *skm, 77 size_t xts_len, const void *skm, size_t skm_len, ...)
78 size_t skm_len, ...)
79{ 78{
80 va_list argp; 79 va_list argp;
81 int ret; 80 int ret;
diff --git a/src/util/crypto_ksk.c b/src/util/crypto_ksk.c
index 7c23fc1e0..bec87c803 100644
--- a/src/util/crypto_ksk.c
+++ b/src/util/crypto_ksk.c
@@ -397,8 +397,8 @@ gen_prime (gcry_mpi_t * ptest, unsigned int nbits, GNUNET_HashCode * hc)
397 * @param hc the HC to use for PRNG (modified!) 397 * @param hc the HC to use for PRNG (modified!)
398 */ 398 */
399static void 399static void
400generate_kblock_key (KBlock_secret_key *sk, 400generate_kblock_key (KBlock_secret_key *sk, unsigned int nbits,
401 unsigned int nbits, GNUNET_HashCode * hc) 401 GNUNET_HashCode * hc)
402{ 402{
403 gcry_mpi_t t1, t2; 403 gcry_mpi_t t1, t2;
404 gcry_mpi_t phi; /* helper: (p-1)(q-1) */ 404 gcry_mpi_t phi; /* helper: (p-1)(q-1) */
@@ -569,10 +569,9 @@ ksk_decode_key (const struct KskRsaPrivateKeyBinaryEncoded *encoding)
569 569
570 pos = 0; 570 pos = 0;
571 size = ntohs (encoding->sizen); 571 size = ntohs (encoding->sizen);
572 rc = gcry_mpi_scan (&n, 572 rc = gcry_mpi_scan (&n, GCRYMPI_FMT_USG,
573 GCRYMPI_FMT_USG, 573 &((const unsigned char *) (&encoding[1]))[pos], size,
574 &((const unsigned char *) (&encoding[1]))[pos], 574 &size);
575 size, &size);
576 pos += ntohs (encoding->sizen); 575 pos += ntohs (encoding->sizen);
577 if (rc) 576 if (rc)
578 { 577 {
@@ -580,10 +579,9 @@ ksk_decode_key (const struct KskRsaPrivateKeyBinaryEncoded *encoding)
580 return NULL; 579 return NULL;
581 } 580 }
582 size = ntohs (encoding->sizee); 581 size = ntohs (encoding->sizee);
583 rc = gcry_mpi_scan (&e, 582 rc = gcry_mpi_scan (&e, GCRYMPI_FMT_USG,
584 GCRYMPI_FMT_USG, 583 &((const unsigned char *) (&encoding[1]))[pos], size,
585 &((const unsigned char *) (&encoding[1]))[pos], 584 &size);
586 size, &size);
587 pos += ntohs (encoding->sizee); 585 pos += ntohs (encoding->sizee);
588 if (rc) 586 if (rc)
589 { 587 {
@@ -592,10 +590,9 @@ ksk_decode_key (const struct KskRsaPrivateKeyBinaryEncoded *encoding)
592 return NULL; 590 return NULL;
593 } 591 }
594 size = ntohs (encoding->sized); 592 size = ntohs (encoding->sized);
595 rc = gcry_mpi_scan (&d, 593 rc = gcry_mpi_scan (&d, GCRYMPI_FMT_USG,
596 GCRYMPI_FMT_USG, 594 &((const unsigned char *) (&encoding[1]))[pos], size,
597 &((const unsigned char *) (&encoding[1]))[pos], 595 &size);
598 size, &size);
599 pos += ntohs (encoding->sized); 596 pos += ntohs (encoding->sized);
600 if (rc) 597 if (rc)
601 { 598 {
@@ -608,10 +605,9 @@ ksk_decode_key (const struct KskRsaPrivateKeyBinaryEncoded *encoding)
608 size = ntohs (encoding->sizep); 605 size = ntohs (encoding->sizep);
609 if (size > 0) 606 if (size > 0)
610 { 607 {
611 rc = gcry_mpi_scan (&q, 608 rc = gcry_mpi_scan (&q, GCRYMPI_FMT_USG,
612 GCRYMPI_FMT_USG, 609 &((const unsigned char *) (&encoding[1]))[pos], size,
613 &((const unsigned char *) (&encoding[1]))[pos], 610 &size);
614 size, &size);
615 pos += ntohs (encoding->sizep); 611 pos += ntohs (encoding->sizep);
616 if (rc) 612 if (rc)
617 { 613 {
@@ -627,10 +623,9 @@ ksk_decode_key (const struct KskRsaPrivateKeyBinaryEncoded *encoding)
627 size = ntohs (encoding->sizeq); 623 size = ntohs (encoding->sizeq);
628 if (size > 0) 624 if (size > 0)
629 { 625 {
630 rc = gcry_mpi_scan (&p, 626 rc = gcry_mpi_scan (&p, GCRYMPI_FMT_USG,
631 GCRYMPI_FMT_USG, 627 &((const unsigned char *) (&encoding[1]))[pos], size,
632 &((const unsigned char *) (&encoding[1]))[pos], 628 &size);
633 size, &size);
634 pos += ntohs (encoding->sizeq); 629 pos += ntohs (encoding->sizeq);
635 if (rc) 630 if (rc)
636 { 631 {
@@ -652,10 +647,9 @@ ksk_decode_key (const struct KskRsaPrivateKeyBinaryEncoded *encoding)
652 pos; 647 pos;
653 if (size > 0) 648 if (size > 0)
654 { 649 {
655 rc = gcry_mpi_scan (&u, 650 rc = gcry_mpi_scan (&u, GCRYMPI_FMT_USG,
656 GCRYMPI_FMT_USG, 651 &((const unsigned char *) (&encoding[1]))[pos], size,
657 &((const unsigned char *) (&encoding[1]))[pos], 652 &size);
658 size, &size);
659 if (rc) 653 if (rc)
660 { 654 {
661 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); 655 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c
index 03f6c0e98..bb105437d 100644
--- a/src/util/crypto_random.c
+++ b/src/util/crypto_random.c
@@ -71,8 +71,8 @@ GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i)
71 ul = UINT32_MAX - (UINT32_MAX % i); 71 ul = UINT32_MAX - (UINT32_MAX % i);
72 do 72 do
73 { 73 {
74 gcry_randomize ((unsigned char *) &ret, 74 gcry_randomize ((unsigned char *) &ret, sizeof (uint32_t),
75 sizeof (uint32_t), GCRY_STRONG_RANDOM); 75 GCRY_STRONG_RANDOM);
76 } 76 }
77 while (ret >= ul); 77 while (ret >= ul);
78 return ret % i; 78 return ret % i;
@@ -147,8 +147,8 @@ GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max)
147 ul = UINT64_MAX - (UINT64_MAX % max); 147 ul = UINT64_MAX - (UINT64_MAX % max);
148 do 148 do
149 { 149 {
150 gcry_randomize ((unsigned char *) &ret, 150 gcry_randomize ((unsigned char *) &ret, sizeof (uint64_t),
151 sizeof (uint64_t), GCRY_STRONG_RANDOM); 151 GCRY_STRONG_RANDOM);
152 } 152 }
153 while (ret >= ul); 153 while (ret >= ul);
154 return ret % max; 154 return ret % max;
@@ -195,8 +195,8 @@ static struct GNUNET_OS_Process *genproc;
195 * blocked gathering entropy. 195 * blocked gathering entropy.
196 */ 196 */
197static void 197static void
198entropy_generator (void *cls, 198entropy_generator (void *cls, const char *what, int printchar, int current,
199 const char *what, int printchar, int current, int total) 199 int total)
200{ 200{
201 unsigned long code; 201 unsigned long code;
202 enum GNUNET_OS_ProcessStatusType type; 202 enum GNUNET_OS_ProcessStatusType type;
@@ -234,11 +234,10 @@ entropy_generator (void *cls,
234 } 234 }
235 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 235 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
236 _("Starting `%s' process to generate entropy\n"), "find"); 236 _("Starting `%s' process to generate entropy\n"), "find");
237 genproc = GNUNET_OS_start_process (NULL, NULL, "sh", 237 genproc =
238 "sh", 238 GNUNET_OS_start_process (NULL, NULL, "sh", "sh", "-c",
239 "-c", 239 "exec find / -mount -type f -exec cp {} /dev/null \\; 2>/dev/null",
240 "exec find / -mount -type f -exec cp {} /dev/null \\; 2>/dev/null", 240 NULL);
241 NULL);
242} 241}
243 242
244 243
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c
index 6be2f53c0..3607998e4 100644
--- a/src/util/crypto_rsa.c
+++ b/src/util/crypto_rsa.c
@@ -108,10 +108,10 @@ GNUNET_CRYPTO_rsa_key_create ()
108 gcry_sexp_t s_key; 108 gcry_sexp_t s_key;
109 gcry_sexp_t s_keyparam; 109 gcry_sexp_t s_keyparam;
110 110
111 GNUNET_assert (0 == gcry_sexp_build (&s_keyparam, 111 GNUNET_assert (0 ==
112 NULL, 112 gcry_sexp_build (&s_keyparam, NULL,
113 "(genkey(rsa(nbits %d)(rsa-use-e 3:257)))", 113 "(genkey(rsa(nbits %d)(rsa-use-e 3:257)))",
114 HOSTKEY_LEN)); 114 HOSTKEY_LEN));
115 GNUNET_assert (0 == gcry_pk_genkey (&s_key, s_keyparam)); 115 GNUNET_assert (0 == gcry_pk_genkey (&s_key, s_keyparam));
116 gcry_sexp_release (s_keyparam); 116 gcry_sexp_release (s_keyparam);
117#if EXTRA_CHECKS 117#if EXTRA_CHECKS
@@ -133,8 +133,8 @@ GNUNET_CRYPTO_rsa_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey)
133} 133}
134 134
135static int 135static int
136key_from_sexp (gcry_mpi_t * array, 136key_from_sexp (gcry_mpi_t * array, gcry_sexp_t sexp, const char *topname,
137 gcry_sexp_t sexp, const char *topname, const char *elems) 137 const char *elems)
138{ 138{
139 gcry_sexp_t list, l2; 139 gcry_sexp_t list, l2;
140 const char *s; 140 const char *s;
@@ -192,8 +192,8 @@ key_from_sexp (gcry_mpi_t * array,
192void 192void
193GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey 193GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey
194 *priv, 194 *priv,
195 struct 195 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
196 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pub) 196 *pub)
197{ 197{
198 gcry_mpi_t skey[2]; 198 gcry_mpi_t skey[2];
199 size_t size; 199 size_t size;
@@ -211,14 +211,15 @@ GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey
211 pub->sizen = htons (GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH); 211 pub->sizen = htons (GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH);
212 pub->padding = 0; 212 pub->padding = 0;
213 size = GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH; 213 size = GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH;
214 GNUNET_assert (0 == gcry_mpi_print (GCRYMPI_FMT_USG, 214 GNUNET_assert (0 ==
215 &pub->key[0], size, &size, skey[0])); 215 gcry_mpi_print (GCRYMPI_FMT_USG, &pub->key[0], size, &size,
216 skey[0]));
216 adjust (&pub->key[0], size, GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH); 217 adjust (&pub->key[0], size, GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH);
217 size = GNUNET_CRYPTO_RSA_KEY_LENGTH - GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH; 218 size = GNUNET_CRYPTO_RSA_KEY_LENGTH - GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH;
218 GNUNET_assert (0 == 219 GNUNET_assert (0 ==
219 gcry_mpi_print (GCRYMPI_FMT_USG, 220 gcry_mpi_print (GCRYMPI_FMT_USG,
220 &pub->key 221 &pub->
221 [GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH], 222 key[GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH],
222 size, &size, skey[1])); 223 size, &size, skey[1]));
223 adjust (&pub->key[GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH], size, 224 adjust (&pub->key[GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH], size,
224 GNUNET_CRYPTO_RSA_KEY_LENGTH - 225 GNUNET_CRYPTO_RSA_KEY_LENGTH -
@@ -271,8 +272,8 @@ public2PrivateKey (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
271 gcry_mpi_release (n); 272 gcry_mpi_release (n);
272 return NULL; 273 return NULL;
273 } 274 }
274 rc = gcry_sexp_build (&result, 275 rc = gcry_sexp_build (&result, &erroff, "(public-key(rsa(n %m)(e %m)))", n,
275 &erroff, "(public-key(rsa(n %m)(e %m)))", n, e); 276 e);
276 gcry_mpi_release (n); 277 gcry_mpi_release (n);
277 gcry_mpi_release (e); 278 gcry_mpi_release (e);
278 if (rc) 279 if (rc)
@@ -329,9 +330,10 @@ rsa_encode_key (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey)
329 { 330 {
330 if (pkv[i] != NULL) 331 if (pkv[i] != NULL)
331 { 332 {
332 GNUNET_assert (0 == gcry_mpi_aprint (GCRYMPI_FMT_USG, 333 GNUNET_assert (0 ==
333 (unsigned char **) &pbu[i], 334 gcry_mpi_aprint (GCRYMPI_FMT_USG,
334 &sizes[i], pkv[i])); 335 (unsigned char **) &pbu[i], &sizes[i],
336 pkv[i]));
335 size += sizes[i]; 337 size += sizes[i];
336 } 338 }
337 else 339 else
@@ -399,10 +401,9 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len)
399 401
400 pos = 0; 402 pos = 0;
401 size = ntohs (encoding->sizen); 403 size = ntohs (encoding->sizen);
402 rc = gcry_mpi_scan (&n, 404 rc = gcry_mpi_scan (&n, GCRYMPI_FMT_USG,
403 GCRYMPI_FMT_USG, 405 &((const unsigned char *) (&encoding[1]))[pos], size,
404 &((const unsigned char *) (&encoding[1]))[pos], 406 &size);
405 size, &size);
406 pos += ntohs (encoding->sizen); 407 pos += ntohs (encoding->sizen);
407 if (rc) 408 if (rc)
408 { 409 {
@@ -410,10 +411,9 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len)
410 return NULL; 411 return NULL;
411 } 412 }
412 size = ntohs (encoding->sizee); 413 size = ntohs (encoding->sizee);
413 rc = gcry_mpi_scan (&e, 414 rc = gcry_mpi_scan (&e, GCRYMPI_FMT_USG,
414 GCRYMPI_FMT_USG, 415 &((const unsigned char *) (&encoding[1]))[pos], size,
415 &((const unsigned char *) (&encoding[1]))[pos], 416 &size);
416 size, &size);
417 pos += ntohs (encoding->sizee); 417 pos += ntohs (encoding->sizee);
418 if (rc) 418 if (rc)
419 { 419 {
@@ -422,10 +422,9 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len)
422 return NULL; 422 return NULL;
423 } 423 }
424 size = ntohs (encoding->sized); 424 size = ntohs (encoding->sized);
425 rc = gcry_mpi_scan (&d, 425 rc = gcry_mpi_scan (&d, GCRYMPI_FMT_USG,
426 GCRYMPI_FMT_USG, 426 &((const unsigned char *) (&encoding[1]))[pos], size,
427 &((const unsigned char *) (&encoding[1]))[pos], 427 &size);
428 size, &size);
429 pos += ntohs (encoding->sized); 428 pos += ntohs (encoding->sized);
430 if (rc) 429 if (rc)
431 { 430 {
@@ -438,10 +437,9 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len)
438 size = ntohs (encoding->sizep); 437 size = ntohs (encoding->sizep);
439 if (size > 0) 438 if (size > 0)
440 { 439 {
441 rc = gcry_mpi_scan (&q, 440 rc = gcry_mpi_scan (&q, GCRYMPI_FMT_USG,
442 GCRYMPI_FMT_USG, 441 &((const unsigned char *) (&encoding[1]))[pos], size,
443 &((const unsigned char *) (&encoding[1]))[pos], 442 &size);
444 size, &size);
445 pos += ntohs (encoding->sizep); 443 pos += ntohs (encoding->sizep);
446 if (rc) 444 if (rc)
447 { 445 {
@@ -457,10 +455,9 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len)
457 size = ntohs (encoding->sizeq); 455 size = ntohs (encoding->sizeq);
458 if (size > 0) 456 if (size > 0)
459 { 457 {
460 rc = gcry_mpi_scan (&p, 458 rc = gcry_mpi_scan (&p, GCRYMPI_FMT_USG,
461 GCRYMPI_FMT_USG, 459 &((const unsigned char *) (&encoding[1]))[pos], size,
462 &((const unsigned char *) (&encoding[1]))[pos], 460 &size);
463 size, &size);
464 pos += ntohs (encoding->sizeq); 461 pos += ntohs (encoding->sizeq);
465 if (rc) 462 if (rc)
466 { 463 {
@@ -481,10 +478,9 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len)
481 ntohs (encoding->len) - sizeof (struct RsaPrivateKeyBinaryEncoded) - pos; 478 ntohs (encoding->len) - sizeof (struct RsaPrivateKeyBinaryEncoded) - pos;
482 if (size > 0) 479 if (size > 0)
483 { 480 {
484 rc = gcry_mpi_scan (&u, 481 rc = gcry_mpi_scan (&u, GCRYMPI_FMT_USG,
485 GCRYMPI_FMT_USG, 482 &((const unsigned char *) (&encoding[1]))[pos], size,
486 &((const unsigned char *) (&encoding[1]))[pos], 483 &size);
487 size, &size);
488 if (rc) 484 if (rc)
489 { 485 {
490 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); 486 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
@@ -577,9 +573,8 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
577 while (GNUNET_YES != GNUNET_DISK_file_test (filename)) 573 while (GNUNET_YES != GNUNET_DISK_file_test (filename))
578 { 574 {
579 fd = GNUNET_DISK_file_open (filename, 575 fd = GNUNET_DISK_file_open (filename,
580 GNUNET_DISK_OPEN_WRITE | 576 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE
581 GNUNET_DISK_OPEN_CREATE | 577 | GNUNET_DISK_OPEN_FAILIFEXISTS,
582 GNUNET_DISK_OPEN_FAILIFEXISTS,
583 GNUNET_DISK_PERM_USER_READ | 578 GNUNET_DISK_PERM_USER_READ |
584 GNUNET_DISK_PERM_USER_WRITE); 579 GNUNET_DISK_PERM_USER_WRITE);
585 if (NULL == fd) 580 if (NULL == fd)
@@ -590,8 +585,8 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
590 { 585 {
591 /* must exist but not be accessible, fail for good! */ 586 /* must exist but not be accessible, fail for good! */
592 if (0 != ACCESS (filename, R_OK)) 587 if (0 != ACCESS (filename, R_OK))
593 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 588 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "access",
594 "access", filename); 589 filename);
595 else 590 else
596 GNUNET_break (0); /* what is going on!? */ 591 GNUNET_break (0); /* what is going on!? */
597 return NULL; 592 return NULL;
@@ -605,8 +600,7 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
605 600
606 while (GNUNET_YES != 601 while (GNUNET_YES !=
607 GNUNET_DISK_file_lock (fd, 0, 602 GNUNET_DISK_file_lock (fd, 0,
608 sizeof (struct 603 sizeof (struct RsaPrivateKeyBinaryEncoded),
609 RsaPrivateKeyBinaryEncoded),
610 GNUNET_YES)) 604 GNUNET_YES))
611 { 605 {
612 sleep (1); 606 sleep (1);
@@ -614,9 +608,8 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
614 { 608 {
615 ec = errno; 609 ec = errno;
616 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 610 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
617 _ 611 _("Could not aquire lock on file `%s': %s...\n"), filename,
618 ("Could not aquire lock on file `%s': %s...\n"), 612 STRERROR (ec));
619 filename, STRERROR (ec));
620 } 613 }
621 } 614 }
622 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 615 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -662,8 +655,8 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
662 { 655 {
663 ec = errno; 656 ec = errno;
664 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 657 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
665 _("Could not aquire lock on file `%s': %s...\n"), 658 _("Could not aquire lock on file `%s': %s...\n"), filename,
666 filename, STRERROR (ec)); 659 STRERROR (ec));
667 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 660 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
668 _ 661 _
669 ("This may be ok if someone is currently generating a hostkey.\n")); 662 ("This may be ok if someone is currently generating a hostkey.\n"));
@@ -754,10 +747,9 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
754 * @returns GNUNET_SYSERR on error, GNUNET_OK if ok 747 * @returns GNUNET_SYSERR on error, GNUNET_OK if ok
755 */ 748 */
756int 749int
757GNUNET_CRYPTO_rsa_encrypt (const void *block, 750GNUNET_CRYPTO_rsa_encrypt (const void *block, size_t size,
758 size_t size, 751 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
759 const struct 752 *publicKey,
760 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey,
761 struct GNUNET_CRYPTO_RsaEncryptedData *target) 753 struct GNUNET_CRYPTO_RsaEncryptedData *target)
762{ 754{
763 gcry_sexp_t result; 755 gcry_sexp_t result;
@@ -786,9 +778,9 @@ GNUNET_CRYPTO_rsa_encrypt (const void *block,
786 GNUNET_assert (0 == key_from_sexp (&rval, result, "rsa", "a")); 778 GNUNET_assert (0 == key_from_sexp (&rval, result, "rsa", "a"));
787 gcry_sexp_release (result); 779 gcry_sexp_release (result);
788 isize = sizeof (struct GNUNET_CRYPTO_RsaEncryptedData); 780 isize = sizeof (struct GNUNET_CRYPTO_RsaEncryptedData);
789 GNUNET_assert (0 == gcry_mpi_print (GCRYMPI_FMT_USG, 781 GNUNET_assert (0 ==
790 (unsigned char *) target, isize, &isize, 782 gcry_mpi_print (GCRYMPI_FMT_USG, (unsigned char *) target,
791 rval)); 783 isize, &isize, rval));
792 gcry_mpi_release (rval); 784 gcry_mpi_release (rval);
793 adjust (&target->encoding[0], isize, 785 adjust (&target->encoding[0], isize,
794 sizeof (struct GNUNET_CRYPTO_RsaEncryptedData)); 786 sizeof (struct GNUNET_CRYPTO_RsaEncryptedData));
@@ -807,8 +799,8 @@ GNUNET_CRYPTO_rsa_encrypt (const void *block,
807 */ 799 */
808ssize_t 800ssize_t
809GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey * key, 801GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey * key,
810 const struct GNUNET_CRYPTO_RsaEncryptedData * 802 const struct GNUNET_CRYPTO_RsaEncryptedData * block,
811 block, void *result, size_t max) 803 void *result, size_t max)
812{ 804{
813 gcry_sexp_t resultsexp; 805 gcry_sexp_t resultsexp;
814 gcry_sexp_t data; 806 gcry_sexp_t data;
@@ -822,12 +814,12 @@ GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey * key,
822 GNUNET_assert (0 == gcry_pk_testkey (key->sexp)); 814 GNUNET_assert (0 == gcry_pk_testkey (key->sexp));
823#endif 815#endif
824 size = sizeof (struct GNUNET_CRYPTO_RsaEncryptedData); 816 size = sizeof (struct GNUNET_CRYPTO_RsaEncryptedData);
825 GNUNET_assert (0 == gcry_mpi_scan (&val,
826 GCRYMPI_FMT_USG, &block->encoding[0],
827 size, &size));
828 GNUNET_assert (0 == 817 GNUNET_assert (0 ==
829 gcry_sexp_build (&data, &erroff, 818 gcry_mpi_scan (&val, GCRYMPI_FMT_USG, &block->encoding[0],
830 "(enc-val(flags)(rsa(a %m)))", val)); 819 size, &size));
820 GNUNET_assert (0 ==
821 gcry_sexp_build (&data, &erroff, "(enc-val(flags)(rsa(a %m)))",
822 val));
831 gcry_mpi_release (val); 823 gcry_mpi_release (val);
832 GNUNET_assert (0 == gcry_pk_decrypt (&resultsexp, data, key->sexp)); 824 GNUNET_assert (0 == gcry_pk_decrypt (&resultsexp, data, key->sexp));
833 gcry_sexp_release (data); 825 gcry_sexp_release (data);
@@ -858,8 +850,8 @@ GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey * key,
858 */ 850 */
859int 851int
860GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key, 852GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
861 const struct GNUNET_CRYPTO_RsaSignaturePurpose 853 const struct GNUNET_CRYPTO_RsaSignaturePurpose *purpose,
862 *purpose, struct GNUNET_CRYPTO_RsaSignature *sig) 854 struct GNUNET_CRYPTO_RsaSignature *sig)
863{ 855{
864 gcry_sexp_t result; 856 gcry_sexp_t result;
865 gcry_sexp_t data; 857 gcry_sexp_t data;
@@ -886,9 +878,9 @@ GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
886 GNUNET_assert (0 == key_from_sexp (&rval, result, "rsa", "s")); 878 GNUNET_assert (0 == key_from_sexp (&rval, result, "rsa", "s"));
887 gcry_sexp_release (result); 879 gcry_sexp_release (result);
888 ssize = sizeof (struct GNUNET_CRYPTO_RsaSignature); 880 ssize = sizeof (struct GNUNET_CRYPTO_RsaSignature);
889 GNUNET_assert (0 == gcry_mpi_print (GCRYMPI_FMT_USG, 881 GNUNET_assert (0 ==
890 (unsigned char *) sig, ssize, &ssize, 882 gcry_mpi_print (GCRYMPI_FMT_USG, (unsigned char *) sig, ssize,
891 rval)); 883 &ssize, rval));
892 gcry_mpi_release (rval); 884 gcry_mpi_release (rval);
893 adjust (sig->sig, ssize, sizeof (struct GNUNET_CRYPTO_RsaSignature)); 885 adjust (sig->sig, ssize, sizeof (struct GNUNET_CRYPTO_RsaSignature));
894 return GNUNET_OK; 886 return GNUNET_OK;
@@ -927,9 +919,9 @@ GNUNET_CRYPTO_rsa_verify (uint32_t purpose,
927 return GNUNET_SYSERR; /* purpose mismatch */ 919 return GNUNET_SYSERR; /* purpose mismatch */
928 GNUNET_CRYPTO_hash (validate, ntohl (validate->size), &hc); 920 GNUNET_CRYPTO_hash (validate, ntohl (validate->size), &hc);
929 size = sizeof (struct GNUNET_CRYPTO_RsaSignature); 921 size = sizeof (struct GNUNET_CRYPTO_RsaSignature);
930 GNUNET_assert (0 == gcry_mpi_scan (&val, 922 GNUNET_assert (0 ==
931 GCRYMPI_FMT_USG, 923 gcry_mpi_scan (&val, GCRYMPI_FMT_USG,
932 (const unsigned char *) sig, size, &size)); 924 (const unsigned char *) sig, size, &size));
933 GNUNET_assert (0 == 925 GNUNET_assert (0 ==
934 gcry_sexp_build (&sigdata, &erroff, "(sig-val(rsa(s %m)))", 926 gcry_sexp_build (&sigdata, &erroff, "(sig-val(rsa(s %m)))",
935 val)); 927 val));
@@ -937,9 +929,10 @@ GNUNET_CRYPTO_rsa_verify (uint32_t purpose,
937 bufSize = strlen (FORMATSTRING) + 1; 929 bufSize = strlen (FORMATSTRING) + 1;
938 buff = GNUNET_malloc (bufSize); 930 buff = GNUNET_malloc (bufSize);
939 memcpy (buff, FORMATSTRING, bufSize); 931 memcpy (buff, FORMATSTRING, bufSize);
940 memcpy (&buff[strlen (FORMATSTRING) - 932 memcpy (&buff
941 strlen 933 [strlen (FORMATSTRING) -
942 ("0123456789012345678901234567890123456789012345678901234567890123))")], 934 strlen
935 ("0123456789012345678901234567890123456789012345678901234567890123))")],
943 &hc, sizeof (GNUNET_HashCode)); 936 &hc, sizeof (GNUNET_HashCode));
944 GNUNET_assert (0 == gcry_sexp_new (&data, buff, bufSize, 0)); 937 GNUNET_assert (0 == gcry_sexp_new (&data, buff, bufSize, 0));
945 GNUNET_free (buff); 938 GNUNET_free (buff);
@@ -957,8 +950,8 @@ GNUNET_CRYPTO_rsa_verify (uint32_t purpose,
957 if (rc) 950 if (rc)
958 { 951 {
959 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 952 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
960 _("RSA signature verification failed at %s:%d: %s\n"), 953 _("RSA signature verification failed at %s:%d: %s\n"), __FILE__,
961 __FILE__, __LINE__, gcry_strerror (rc)); 954 __LINE__, gcry_strerror (rc));
962 return GNUNET_SYSERR; 955 return GNUNET_SYSERR;
963 } 956 }
964 return GNUNET_OK; 957 return GNUNET_OK;
diff --git a/src/util/disk.c b/src/util/disk.c
index dd7db7d73..6ba5db773 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -172,8 +172,7 @@ getSizeRec (void *cls, const char *fn)
172#endif 172#endif
173 if ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES)) 173 if ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES))
174 gfsd->total += buf.st_size; 174 gfsd->total += buf.st_size;
175 if ((S_ISDIR (buf.st_mode)) && 175 if ((S_ISDIR (buf.st_mode)) && (0 == ACCESS (fn, X_OK)) &&
176 (0 == ACCESS (fn, X_OK)) &&
177 ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES))) 176 ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES)))
178 { 177 {
179 if (GNUNET_SYSERR == GNUNET_DISK_directory_scan (fn, &getSizeRec, gfsd)) 178 if (GNUNET_SYSERR == GNUNET_DISK_directory_scan (fn, &getSizeRec, gfsd))
@@ -255,8 +254,8 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle * h, off_t offset,
255 * @return GNUNET_SYSERR on error, GNUNET_OK on success 254 * @return GNUNET_SYSERR on error, GNUNET_OK on success
256 */ 255 */
257int 256int
258GNUNET_DISK_file_size (const char *filename, 257GNUNET_DISK_file_size (const char *filename, uint64_t * size,
259 uint64_t * size, int includeSymLinks) 258 int includeSymLinks)
260{ 259{
261 struct GetFileSizeData gfsd; 260 struct GetFileSizeData gfsd;
262 int ret; 261 int ret;
@@ -286,8 +285,8 @@ GNUNET_DISK_file_size (const char *filename,
286 * @return GNUNET_OK on success 285 * @return GNUNET_OK on success
287 */ 286 */
288int 287int
289GNUNET_DISK_file_get_identifiers (const char *filename, 288GNUNET_DISK_file_get_identifiers (const char *filename, uint64_t * dev,
290 uint64_t * dev, uint64_t * ino) 289 uint64_t * ino)
291{ 290{
292#if LINUX 291#if LINUX
293 struct stat sbuf; 292 struct stat sbuf;
@@ -427,8 +426,8 @@ GNUNET_DISK_get_blocks_available (const char *part)
427 if (!GetDiskFreeSpace (szDrive, &dwDummy, &dwDummy, &dwBlocks, &dwDummy)) 426 if (!GetDiskFreeSpace (szDrive, &dwDummy, &dwDummy, &dwBlocks, &dwDummy))
428 { 427 {
429 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 428 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
430 _("`%s' failed for drive `%s': %u\n"), 429 _("`%s' failed for drive `%s': %u\n"), "GetDiskFreeSpace",
431 "GetDiskFreeSpace", szDrive, GetLastError ()); 430 szDrive, GetLastError ());
432 431
433 return -1; 432 return -1;
434 } 433 }
@@ -772,15 +771,14 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h,
772 * @return number of bytes written on success, GNUNET_SYSERR on error 771 * @return number of bytes written on success, GNUNET_SYSERR on error
773 */ 772 */
774ssize_t 773ssize_t
775GNUNET_DISK_fn_write (const char *fn, const void *buffer, 774GNUNET_DISK_fn_write (const char *fn, const void *buffer, size_t n,
776 size_t n, enum GNUNET_DISK_AccessPermissions mode) 775 enum GNUNET_DISK_AccessPermissions mode)
777{ 776{
778 struct GNUNET_DISK_FileHandle *fh; 777 struct GNUNET_DISK_FileHandle *fh;
779 ssize_t ret; 778 ssize_t ret;
780 779
781 fh = GNUNET_DISK_file_open (fn, 780 fh = GNUNET_DISK_file_open (fn,
782 GNUNET_DISK_OPEN_WRITE 781 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE
783 | GNUNET_DISK_OPEN_TRUNCATE
784 | GNUNET_DISK_OPEN_CREATE, mode); 782 | GNUNET_DISK_OPEN_CREATE, mode);
785 if (!fh) 783 if (!fh)
786 return GNUNET_SYSERR; 784 return GNUNET_SYSERR;
@@ -862,10 +860,7 @@ GNUNET_DISK_directory_scan (const char *dirName,
862 /* dname can end in "/" only if dname == "/"; 860 /* dname can end in "/" only if dname == "/";
863 * if dname does not end in "/", we need to add 861 * if dname does not end in "/", we need to add
864 * a "/" (otherwise, we must not!) */ 862 * a "/" (otherwise, we must not!) */
865 GNUNET_snprintf (name, 863 GNUNET_snprintf (name, n_size, "%s%s%s", dname,
866 n_size,
867 "%s%s%s",
868 dname,
869 (strcmp (dname, DIR_SEPARATOR_STR) == 864 (strcmp (dname, DIR_SEPARATOR_STR) ==
870 0) ? "" : DIR_SEPARATOR_STR, finfo->d_name); 865 0) ? "" : DIR_SEPARATOR_STR, finfo->d_name);
871 if (GNUNET_OK != callback (callback_cls, name)) 866 if (GNUNET_OK != callback (callback_cls, name))
@@ -954,8 +949,8 @@ directory_iterator_task (void *cls,
954 * GNUNET_SYSERR if abort was YES 949 * GNUNET_SYSERR if abort was YES
955 */ 950 */
956int 951int
957GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator 952GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator *iter,
958 *iter, int can) 953 int can)
959{ 954{
960 struct dirent *finfo; 955 struct dirent *finfo;
961 956
@@ -972,8 +967,8 @@ GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator
972 if ((0 == strcmp (finfo->d_name, ".")) || 967 if ((0 == strcmp (finfo->d_name, ".")) ||
973 (0 == strcmp (finfo->d_name, ".."))) 968 (0 == strcmp (finfo->d_name, "..")))
974 continue; 969 continue;
975 GNUNET_asprintf (&iter->next_name, 970 GNUNET_asprintf (&iter->next_name, "%s%s%s", iter->dirname,
976 "%s%s%s", iter->dirname, DIR_SEPARATOR_STR, finfo->d_name); 971 DIR_SEPARATOR_STR, finfo->d_name);
977 break; 972 break;
978 } 973 }
979 if (finfo == NULL) 974 if (finfo == NULL)
@@ -981,8 +976,8 @@ GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator
981 GNUNET_DISK_directory_iterator_next (iter, GNUNET_YES); 976 GNUNET_DISK_directory_iterator_next (iter, GNUNET_YES);
982 return GNUNET_NO; 977 return GNUNET_NO;
983 } 978 }
984 GNUNET_SCHEDULER_add_with_priority (iter->priority, 979 GNUNET_SCHEDULER_add_with_priority (iter->priority, &directory_iterator_task,
985 &directory_iterator_task, iter); 980 iter);
986 return GNUNET_YES; 981 return GNUNET_YES;
987} 982}
988 983
@@ -1101,13 +1096,14 @@ GNUNET_DISK_file_copy (const char *src, const char *dst)
1101 GNUNET_DISK_PERM_NONE); 1096 GNUNET_DISK_PERM_NONE);
1102 if (!in) 1097 if (!in)
1103 return GNUNET_SYSERR; 1098 return GNUNET_SYSERR;
1104 out = GNUNET_DISK_file_open (dst, GNUNET_DISK_OPEN_WRITE 1099 out =
1105 | GNUNET_DISK_OPEN_CREATE | 1100 GNUNET_DISK_file_open (dst,
1106 GNUNET_DISK_OPEN_FAILIFEXISTS, 1101 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE |
1107 GNUNET_DISK_PERM_USER_READ | 1102 GNUNET_DISK_OPEN_FAILIFEXISTS,
1108 GNUNET_DISK_PERM_USER_WRITE | 1103 GNUNET_DISK_PERM_USER_READ |
1109 GNUNET_DISK_PERM_GROUP_READ | 1104 GNUNET_DISK_PERM_USER_WRITE |
1110 GNUNET_DISK_PERM_GROUP_WRITE); 1105 GNUNET_DISK_PERM_GROUP_READ |
1106 GNUNET_DISK_PERM_GROUP_WRITE);
1111 if (!out) 1107 if (!out)
1112 { 1108 {
1113 GNUNET_DISK_file_close (in); 1109 GNUNET_DISK_file_close (in);
@@ -1152,8 +1148,8 @@ GNUNET_DISK_filename_canonicalize (char *fn)
1152 { 1148 {
1153 c = *idx; 1149 c = *idx;
1154 1150
1155 if (c == '/' || c == '\\' || c == ':' || c == '*' || c == '?' || 1151 if (c == '/' || c == '\\' || c == ':' || c == '*' || c == '?' || c == '"' ||
1156 c == '"' || c == '<' || c == '>' || c == '|') 1152 c == '<' || c == '>' || c == '|')
1157 { 1153 {
1158 *idx = '_'; 1154 *idx = '_';
1159 } 1155 }
@@ -1181,8 +1177,8 @@ GNUNET_DISK_file_change_owner (const char *filename, const char *user)
1181 if (pws == NULL) 1177 if (pws == NULL)
1182 { 1178 {
1183 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1179 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1184 _("Cannot obtain information about user `%s': %s\n"), 1180 _("Cannot obtain information about user `%s': %s\n"), user,
1185 user, STRERROR (errno)); 1181 STRERROR (errno));
1186 return GNUNET_SYSERR; 1182 return GNUNET_SYSERR;
1187 } 1183 }
1188 if (0 != chown (filename, pws->pw_uid, pws->pw_gid)) 1184 if (0 != chown (filename, pws->pw_uid, pws->pw_gid))
@@ -1226,8 +1222,9 @@ GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart,
1226 memset (&o, 0, sizeof (OVERLAPPED)); 1222 memset (&o, 0, sizeof (OVERLAPPED));
1227 o.Offset = lockStart; 1223 o.Offset = lockStart;
1228 1224
1229 if (!LockFileEx (fh->h, (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0) 1225 if (!LockFileEx
1230 | LOCKFILE_FAIL_IMMEDIATELY, 0, lockEnd - lockStart, 0, &o)) 1226 (fh->h, (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0) | LOCKFILE_FAIL_IMMEDIATELY,
1227 0, lockEnd - lockStart, 0, &o))
1231 { 1228 {
1232 SetErrnoFromWinError (GetLastError ()); 1229 SetErrnoFromWinError (GetLastError ());
1233 return GNUNET_SYSERR; 1230 return GNUNET_SYSERR;
@@ -1295,8 +1292,7 @@ GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, off_t unlockStart,
1295 * @return IO handle on success, NULL on error 1292 * @return IO handle on success, NULL on error
1296 */ 1293 */
1297struct GNUNET_DISK_FileHandle * 1294struct GNUNET_DISK_FileHandle *
1298GNUNET_DISK_file_open (const char *fn, 1295GNUNET_DISK_file_open (const char *fn, enum GNUNET_DISK_OpenFlags flags,
1299 enum GNUNET_DISK_OpenFlags flags,
1300 enum GNUNET_DISK_AccessPermissions perm) 1296 enum GNUNET_DISK_AccessPermissions perm)
1301{ 1297{
1302 char *expfn; 1298 char *expfn;
@@ -1385,8 +1381,9 @@ GNUNET_DISK_file_open (const char *fn,
1385 } 1381 }
1386 1382
1387 /* TODO: access priviledges? */ 1383 /* TODO: access priviledges? */
1388 h = CreateFile (expfn, access, FILE_SHARE_DELETE | FILE_SHARE_READ 1384 h = CreateFile (expfn, access,
1389 | FILE_SHARE_WRITE, NULL, disp, FILE_ATTRIBUTE_NORMAL, NULL); 1385 FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
1386 disp, FILE_ATTRIBUTE_NORMAL, NULL);
1390 if (h == INVALID_HANDLE_VALUE) 1387 if (h == INVALID_HANDLE_VALUE)
1391 { 1388 {
1392 SetErrnoFromWinError (GetLastError ()); 1389 SetErrnoFromWinError (GetLastError ());
@@ -1713,10 +1710,9 @@ GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h)
1713 Note that the return value is either NO_ERROR or GetLastError, 1710 Note that the return value is either NO_ERROR or GetLastError,
1714 unlike CreatePipe, which returns a bool for success or failure. */ 1711 unlike CreatePipe, which returns a bool for success or failure. */
1715static int 1712static int
1716create_selectable_pipe (PHANDLE read_pipe_ptr, 1713create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr,
1717 PHANDLE write_pipe_ptr, 1714 LPSECURITY_ATTRIBUTES sa_ptr, DWORD psize,
1718 LPSECURITY_ATTRIBUTES sa_ptr, 1715 DWORD dwReadMode, DWORD dwWriteMode)
1719 DWORD psize, DWORD dwReadMode, DWORD dwWriteMode)
1720{ 1716{
1721 /* Default to error. */ 1717 /* Default to error. */
1722 *read_pipe_ptr = *write_pipe_ptr = INVALID_HANDLE_VALUE; 1718 *read_pipe_ptr = *write_pipe_ptr = INVALID_HANDLE_VALUE;
@@ -1921,10 +1917,9 @@ GNUNET_DISK_pipe (int blocking, int inherit_read, int inherit_write)
1921 SetErrnoFromWinError (GetLastError ()); 1917 SetErrnoFromWinError (GetLastError ());
1922 return NULL; 1918 return NULL;
1923 } 1919 }
1924 if (!DuplicateHandle (GetCurrentProcess (), p->fd[0]->h, 1920 if (!DuplicateHandle
1925 GetCurrentProcess (), &tmp_handle, 0, 1921 (GetCurrentProcess (), p->fd[0]->h, GetCurrentProcess (), &tmp_handle, 0,
1926 inherit_read == GNUNET_YES ? TRUE : FALSE, 1922 inherit_read == GNUNET_YES ? TRUE : FALSE, DUPLICATE_SAME_ACCESS))
1927 DUPLICATE_SAME_ACCESS))
1928 { 1923 {
1929 SetErrnoFromWinError (GetLastError ()); 1924 SetErrnoFromWinError (GetLastError ());
1930 CloseHandle (p->fd[0]->h); 1925 CloseHandle (p->fd[0]->h);
@@ -1935,10 +1930,9 @@ GNUNET_DISK_pipe (int blocking, int inherit_read, int inherit_write)
1935 CloseHandle (p->fd[0]->h); 1930 CloseHandle (p->fd[0]->h);
1936 p->fd[0]->h = tmp_handle; 1931 p->fd[0]->h = tmp_handle;
1937 1932
1938 if (!DuplicateHandle (GetCurrentProcess (), p->fd[1]->h, 1933 if (!DuplicateHandle
1939 GetCurrentProcess (), &tmp_handle, 0, 1934 (GetCurrentProcess (), p->fd[1]->h, GetCurrentProcess (), &tmp_handle, 0,
1940 inherit_write == GNUNET_YES ? TRUE : FALSE, 1935 inherit_write == GNUNET_YES ? TRUE : FALSE, DUPLICATE_SAME_ACCESS))
1941 DUPLICATE_SAME_ACCESS))
1942 { 1936 {
1943 SetErrnoFromWinError (GetLastError ()); 1937 SetErrnoFromWinError (GetLastError ());
1944 CloseHandle (p->fd[0]->h); 1938 CloseHandle (p->fd[0]->h);
@@ -2093,8 +2087,7 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p)
2093 * @return pipe handle on success, NULL on error 2087 * @return pipe handle on success, NULL on error
2094 */ 2088 */
2095struct GNUNET_DISK_FileHandle * 2089struct GNUNET_DISK_FileHandle *
2096GNUNET_DISK_npipe_create (char **fn, 2090GNUNET_DISK_npipe_create (char **fn, enum GNUNET_DISK_OpenFlags flags,
2097 enum GNUNET_DISK_OpenFlags flags,
2098 enum GNUNET_DISK_AccessPermissions perm) 2091 enum GNUNET_DISK_AccessPermissions perm)
2099{ 2092{
2100#ifdef MINGW 2093#ifdef MINGW
@@ -2226,8 +2219,7 @@ GNUNET_DISK_npipe_create (char **fn,
2226 * @return pipe handle on success, NULL on error 2219 * @return pipe handle on success, NULL on error
2227 */ 2220 */
2228struct GNUNET_DISK_FileHandle * 2221struct GNUNET_DISK_FileHandle *
2229GNUNET_DISK_npipe_open (const char *fn, 2222GNUNET_DISK_npipe_open (const char *fn, enum GNUNET_DISK_OpenFlags flags,
2230 enum GNUNET_DISK_OpenFlags flags,
2231 enum GNUNET_DISK_AccessPermissions perm) 2223 enum GNUNET_DISK_AccessPermissions perm)
2232{ 2224{
2233#ifdef MINGW 2225#ifdef MINGW
diff --git a/src/util/getopt.c b/src/util/getopt.c
index 2a35ab278..db81d1c3d 100644
--- a/src/util/getopt.c
+++ b/src/util/getopt.c
@@ -410,8 +410,8 @@ _getopt_initialize (argc, argv, optstring)
410 { 410 {
411 if (nonoption_flags_max_len == 0) 411 if (nonoption_flags_max_len == 0)
412 { 412 {
413 if (__getopt_nonoption_flags == NULL 413 if (__getopt_nonoption_flags == NULL ||
414 || __getopt_nonoption_flags[0] == '\0') 414 __getopt_nonoption_flags[0] == '\0')
415 nonoption_flags_max_len = -1; 415 nonoption_flags_max_len = -1;
416 else 416 else
417 { 417 {
@@ -497,11 +497,9 @@ _getopt_initialize (argc, argv, optstring)
497 long-named options. */ 497 long-named options. */
498 498
499static int 499static int
500GN_getopt_internal (int argc, 500GN_getopt_internal (int argc, char *const *argv, const char *optstring,
501 char *const *argv, 501 const struct GNoption *longopts, int *longind,
502 const char *optstring, 502 int long_only)
503 const struct GNoption *longopts,
504 int *longind, int long_only)
505{ 503{
506 static int __getopt_initialized = 0; 504 static int __getopt_initialized = 0;
507 static int GNopterr = 1; 505 static int GNopterr = 1;
@@ -600,8 +598,8 @@ GN_getopt_internal (int argc,
600 /* We have found another option-ARGV-element. 598 /* We have found another option-ARGV-element.
601 * Skip the initial punctuation. */ 599 * Skip the initial punctuation. */
602 600
603 nextchar = (argv[GNoptind] + 1 601 nextchar =
604 + (longopts != NULL && argv[GNoptind][1] == '-')); 602 (argv[GNoptind] + 1 + (longopts != NULL && argv[GNoptind][1] == '-'));
605 } 603 }
606 604
607 /* Decode the current option-ARGV-element. */ 605 /* Decode the current option-ARGV-element. */
@@ -619,11 +617,10 @@ GN_getopt_internal (int argc,
619 * 617 *
620 * This distinction seems to be the most useful approach. */ 618 * This distinction seems to be the most useful approach. */
621 619
622 if (longopts != NULL 620 if (longopts != NULL &&
623 && (argv[GNoptind][1] == '-' 621 (argv[GNoptind][1] == '-' ||
624 || (long_only 622 (long_only &&
625 && (argv[GNoptind][2] 623 (argv[GNoptind][2] || !my_index (optstring, argv[GNoptind][1])))))
626 || !my_index (optstring, argv[GNoptind][1])))))
627 { 624 {
628 char *nameend; 625 char *nameend;
629 const struct GNoption *p; 626 const struct GNoption *p;
@@ -641,8 +638,8 @@ GN_getopt_internal (int argc,
641 for (p = longopts, option_index = 0; p->name; p++, option_index++) 638 for (p = longopts, option_index = 0; p->name; p++, option_index++)
642 if (!strncmp (p->name, nextchar, nameend - nextchar)) 639 if (!strncmp (p->name, nextchar, nameend - nextchar))
643 { 640 {
644 if ((unsigned int) (nameend - nextchar) 641 if ((unsigned int) (nameend - nextchar) ==
645 == (unsigned int) strlen (p->name)) 642 (unsigned int) strlen (p->name))
646 { 643 {
647 /* Exact match found. */ 644 /* Exact match found. */
648 pfound = p; 645 pfound = p;
@@ -664,8 +661,8 @@ GN_getopt_internal (int argc,
664 if (ambig && !exact) 661 if (ambig && !exact)
665 { 662 {
666 if (GNopterr) 663 if (GNopterr)
667 fprintf (stderr, _("%s: option `%s' is ambiguous\n"), 664 fprintf (stderr, _("%s: option `%s' is ambiguous\n"), argv[0],
668 argv[0], argv[GNoptind]); 665 argv[GNoptind]);
669 nextchar += strlen (nextchar); 666 nextchar += strlen (nextchar);
670 GNoptind++; 667 GNoptind++;
671 return '?'; 668 return '?';
@@ -688,14 +685,12 @@ GN_getopt_internal (int argc,
688 if (argv[GNoptind - 1][1] == '-') 685 if (argv[GNoptind - 1][1] == '-')
689 /* --option */ 686 /* --option */
690 fprintf (stderr, 687 fprintf (stderr,
691 _ 688 _("%s: option `--%s' does not allow an argument\n"),
692 ("%s: option `--%s' does not allow an argument\n"),
693 argv[0], pfound->name); 689 argv[0], pfound->name);
694 else 690 else
695 /* +option or -option */ 691 /* +option or -option */
696 fprintf (stderr, 692 fprintf (stderr,
697 _ 693 _("%s: option `%c%s' does not allow an argument\n"),
698 ("%s: option `%c%s' does not allow an argument\n"),
699 argv[0], argv[GNoptind - 1][0], pfound->name); 694 argv[0], argv[GNoptind - 1][0], pfound->name);
700 } 695 }
701 nextchar += strlen (nextchar); 696 nextchar += strlen (nextchar);
@@ -712,8 +707,7 @@ GN_getopt_internal (int argc,
712 { 707 {
713 if (GNopterr) 708 if (GNopterr)
714 { 709 {
715 fprintf (stderr, 710 fprintf (stderr, _("%s: option `%s' requires an argument\n"),
716 _("%s: option `%s' requires an argument\n"),
717 argv[0], argv[GNoptind - 1]); 711 argv[0], argv[GNoptind - 1]);
718 } 712 }
719 nextchar += strlen (nextchar); 713 nextchar += strlen (nextchar);
@@ -735,19 +729,19 @@ GN_getopt_internal (int argc,
735 * or the option starts with '--' or is not a valid short 729 * or the option starts with '--' or is not a valid short
736 * option, then it's an error. 730 * option, then it's an error.
737 * Otherwise interpret it as a short option. */ 731 * Otherwise interpret it as a short option. */
738 if (!long_only || argv[GNoptind][1] == '-' 732 if (!long_only || argv[GNoptind][1] == '-' ||
739 || my_index (optstring, *nextchar) == NULL) 733 my_index (optstring, *nextchar) == NULL)
740 { 734 {
741 if (GNopterr) 735 if (GNopterr)
742 { 736 {
743 if (argv[GNoptind][1] == '-') 737 if (argv[GNoptind][1] == '-')
744 /* --option */ 738 /* --option */
745 fprintf (stderr, _("%s: unrecognized option `--%s'\n"), 739 fprintf (stderr, _("%s: unrecognized option `--%s'\n"), argv[0],
746 argv[0], nextchar); 740 nextchar);
747 else 741 else
748 /* +option or -option */ 742 /* +option or -option */
749 fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), 743 fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), argv[0],
750 argv[0], argv[GNoptind][0], nextchar); 744 argv[GNoptind][0], nextchar);
751 } 745 }
752 nextchar = (char *) ""; 746 nextchar = (char *) "";
753 GNoptind++; 747 GNoptind++;
@@ -849,8 +843,8 @@ GN_getopt_internal (int argc,
849 if (ambig && !exact) 843 if (ambig && !exact)
850 { 844 {
851 if (GNopterr) 845 if (GNopterr)
852 fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), 846 fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), argv[0],
853 argv[0], argv[GNoptind]); 847 argv[GNoptind]);
854 nextchar += strlen (nextchar); 848 nextchar += strlen (nextchar);
855 GNoptind++; 849 GNoptind++;
856 return '?'; 850 return '?';
@@ -881,8 +875,7 @@ GN_getopt_internal (int argc,
881 else 875 else
882 { 876 {
883 if (GNopterr) 877 if (GNopterr)
884 fprintf (stderr, 878 fprintf (stderr, _("%s: option `%s' requires an argument\n"),
885 _("%s: option `%s' requires an argument\n"),
886 argv[0], argv[GNoptind - 1]); 879 argv[0], argv[GNoptind - 1]);
887 nextchar += strlen (nextchar); 880 nextchar += strlen (nextchar);
888 return optstring[0] == ':' ? ':' : '?'; 881 return optstring[0] == ':' ? ':' : '?';
@@ -930,8 +923,8 @@ GN_getopt_internal (int argc,
930 if (GNopterr) 923 if (GNopterr)
931 { 924 {
932 /* 1003.2 specifies the format of this message. */ 925 /* 1003.2 specifies the format of this message. */
933 fprintf (stderr, 926 fprintf (stderr, _("%s: option requires an argument -- %c\n"),
934 _("%s: option requires an argument -- %c\n"), argv[0], c); 927 argv[0], c);
935 } 928 }
936 if (optstring[0] == ':') 929 if (optstring[0] == ':')
937 c = ':'; 930 c = ':';
@@ -950,9 +943,7 @@ GN_getopt_internal (int argc,
950} 943}
951 944
952static int 945static int
953GNgetopt_long (int argc, 946GNgetopt_long (int argc, char *const *argv, const char *options,
954 char *const *argv,
955 const char *options,
956 const struct GNoption *long_options, int *opt_index) 947 const struct GNoption *long_options, int *opt_index)
957{ 948{
958 return GN_getopt_internal (argc, argv, options, long_options, opt_index, 0); 949 return GN_getopt_internal (argc, argv, options, long_options, opt_index, 0);
@@ -1028,9 +1019,9 @@ GNUNET_GETOPT_run (const char *binaryOptions,
1028 clpc.currentArgument = GNoptind - 1; 1019 clpc.currentArgument = GNoptind - 1;
1029 if ((char) c == allOptions[i].shortName) 1020 if ((char) c == allOptions[i].shortName)
1030 { 1021 {
1031 cont = allOptions[i].processor (&clpc, 1022 cont =
1032 allOptions[i].scls, 1023 allOptions[i].processor (&clpc, allOptions[i].scls,
1033 allOptions[i].name, GNoptarg); 1024 allOptions[i].name, GNoptarg);
1034 break; 1025 break;
1035 } 1026 }
1036 } 1027 }
diff --git a/src/util/getopt_helpers.c b/src/util/getopt_helpers.c
index aa85bf536..d0c8c0e6a 100644
--- a/src/util/getopt_helpers.c
+++ b/src/util/getopt_helpers.c
@@ -166,9 +166,8 @@ OUTER:
166 * @return GNUNET_OK 166 * @return GNUNET_OK
167 */ 167 */
168int 168int
169GNUNET_GETOPT_increment_value (struct 169GNUNET_GETOPT_increment_value (struct GNUNET_GETOPT_CommandLineProcessorContext
170 GNUNET_GETOPT_CommandLineProcessorContext *ctx, 170 *ctx, void *scls, const char *option,
171 void *scls, const char *option,
172 const char *value) 171 const char *value)
173{ 172{
174 int *val = scls; 173 int *val = scls;
@@ -218,9 +217,8 @@ GNUNET_GETOPT_set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
218 * @return GNUNET_OK 217 * @return GNUNET_OK
219 */ 218 */
220int 219int
221GNUNET_GETOPT_set_string (struct GNUNET_GETOPT_CommandLineProcessorContext 220GNUNET_GETOPT_set_string (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
222 *ctx, void *scls, const char *option, 221 void *scls, const char *option, const char *value)
223 const char *value)
224{ 222{
225 char **val = scls; 223 char **val = scls;
226 224
@@ -246,9 +244,8 @@ GNUNET_GETOPT_set_string (struct GNUNET_GETOPT_CommandLineProcessorContext
246 * @return GNUNET_OK if parsing the value worked 244 * @return GNUNET_OK if parsing the value worked
247 */ 245 */
248int 246int
249GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext 247GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
250 *ctx, void *scls, const char *option, 248 void *scls, const char *option, const char *value)
251 const char *value)
252{ 249{
253 unsigned long long *val = scls; 250 unsigned long long *val = scls;
254 251
diff --git a/src/util/gnunet-config-diff.c b/src/util/gnunet-config-diff.c
index 02ffa77a1..207b9518a 100644
--- a/src/util/gnunet-config-diff.c
+++ b/src/util/gnunet-config-diff.c
@@ -14,8 +14,7 @@ main (int argc, char **argv)
14 } 14 }
15 i1 = GNUNET_CONFIGURATION_create (); 15 i1 = GNUNET_CONFIGURATION_create ();
16 i2 = GNUNET_CONFIGURATION_create (); 16 i2 = GNUNET_CONFIGURATION_create ();
17 if ((GNUNET_OK != 17 if ((GNUNET_OK != GNUNET_CONFIGURATION_load (i1, argv[1])) ||
18 GNUNET_CONFIGURATION_load (i1, argv[1])) ||
19 (GNUNET_OK != GNUNET_CONFIGURATION_load (i2, argv[2]))) 18 (GNUNET_OK != GNUNET_CONFIGURATION_load (i2, argv[2])))
20 return 1; 19 return 1;
21 if (GNUNET_OK != GNUNET_CONFIGURATION_write_diffs (i1, i2, argv[2])) 20 if (GNUNET_OK != GNUNET_CONFIGURATION_write_diffs (i1, i2, argv[2]))
diff --git a/src/util/gnunet-resolver.c b/src/util/gnunet-resolver.c
index 125d6665f..131693dd1 100644
--- a/src/util/gnunet-resolver.c
+++ b/src/util/gnunet-resolver.c
@@ -50,9 +50,8 @@ printer (void *cls, const struct sockaddr *addr, socklen_t addrlen)
50 * @param cfg configuration 50 * @param cfg configuration
51 */ 51 */
52static void 52static void
53run (void *cls, 53run (void *cls, char *const *args, const char *cfgfile,
54 char *const *args, 54 const struct GNUNET_CONFIGURATION_Handle *cfg)
55 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
56{ 55{
57 if (args[0] == NULL) 56 if (args[0] == NULL)
58 return; 57 return;
@@ -73,11 +72,8 @@ main (int argc, char *const *argv)
73 GNUNET_GETOPT_OPTION_END 72 GNUNET_GETOPT_OPTION_END
74 }; 73 };
75 return (GNUNET_OK == 74 return (GNUNET_OK ==
76 GNUNET_PROGRAM_run (argc, 75 GNUNET_PROGRAM_run (argc, argv, "gnunet-resolver [hostname]",
77 argv, 76 gettext_noop ("Test GNUnet DNS resolver code."),
78 "gnunet-resolver [hostname]",
79 gettext_noop
80 ("Test GNUnet DNS resolver code."),
81 options, &run, NULL)) ? 0 : 1; 77 options, &run, NULL)) ? 0 : 1;
82} 78}
83 79
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c
index f49ec3882..5d4c5c224 100644
--- a/src/util/gnunet-service-resolver.c
+++ b/src/util/gnunet-service-resolver.c
@@ -87,8 +87,9 @@ getnameinfo_resolve (struct IPCache *cache)
87{ 87{
88 char hostname[256]; 88 char hostname[256];
89 89
90 if (0 == getnameinfo (cache->sa, 90 if (0 ==
91 cache->salen, hostname, sizeof (hostname), NULL, 0, 0)) 91 getnameinfo (cache->sa, cache->salen, hostname, sizeof (hostname), NULL,
92 0, 0))
92 cache->addr = GNUNET_strdup (hostname); 93 cache->addr = GNUNET_strdup (hostname);
93} 94}
94#endif 95#endif
@@ -108,12 +109,14 @@ gethostbyaddr_resolve (struct IPCache *cache)
108 switch (cache->sa->sa_family) 109 switch (cache->sa->sa_family)
109 { 110 {
110 case AF_INET: 111 case AF_INET:
111 ent = gethostbyaddr (&((struct sockaddr_in *) cache->sa)->sin_addr, 112 ent =
112 sizeof (struct in_addr), AF_INET); 113 gethostbyaddr (&((struct sockaddr_in *) cache->sa)->sin_addr,
114 sizeof (struct in_addr), AF_INET);
113 break; 115 break;
114 case AF_INET6: 116 case AF_INET6:
115 ent = gethostbyaddr (&((struct sockaddr_in6 *) cache->sa)->sin6_addr, 117 ent =
116 sizeof (struct in6_addr), AF_INET6); 118 gethostbyaddr (&((struct sockaddr_in6 *) cache->sa)->sin6_addr,
119 sizeof (struct in6_addr), AF_INET6);
117 break; 120 break;
118 default: 121 default:
119 ent = NULL; 122 ent = NULL;
@@ -225,8 +228,7 @@ get_ip_as_string (struct GNUNET_SERVER_Client *client,
225 } 228 }
226 tc = GNUNET_SERVER_transmit_context_create (client); 229 tc = GNUNET_SERVER_transmit_context_create (client);
227 if (cache->addr != NULL) 230 if (cache->addr != NULL)
228 GNUNET_SERVER_transmit_context_append_data (tc, 231 GNUNET_SERVER_transmit_context_append_data (tc, cache->addr,
229 cache->addr,
230 strlen (cache->addr) + 1, 232 strlen (cache->addr) + 1,
231 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 233 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
232 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 234 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
@@ -256,11 +258,10 @@ getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc,
256 258
257 if (0 != (s = getaddrinfo (hostname, NULL, &hints, &result))) 259 if (0 != (s = getaddrinfo (hostname, NULL, &hints, &result)))
258 { 260 {
259 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 261 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Could not resolve `%s' (%s): %s\n"),
260 _("Could not resolve `%s' (%s): %s\n"), hostname, 262 hostname,
261 (domain == 263 (domain ==
262 AF_INET) ? "IPv4" : ((domain == 264 AF_INET) ? "IPv4" : ((domain == AF_INET6) ? "IPv6" : "any"),
263 AF_INET6) ? "IPv6" : "any"),
264 gai_strerror (s)); 265 gai_strerror (s));
265 if ((s == EAI_BADFLAGS) || (s == EAI_MEMORY) 266 if ((s == EAI_BADFLAGS) || (s == EAI_MEMORY)
266#ifndef MINGW 267#ifndef MINGW
@@ -278,8 +279,7 @@ getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc,
278 pos = result; 279 pos = result;
279 while (pos != NULL) 280 while (pos != NULL)
280 { 281 {
281 GNUNET_SERVER_transmit_context_append_data (tc, 282 GNUNET_SERVER_transmit_context_append_data (tc, pos->ai_addr,
282 pos->ai_addr,
283 pos->ai_addrlen, 283 pos->ai_addrlen,
284 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 284 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
285 pos = pos->ai_next; 285 pos = pos->ai_next;
@@ -314,8 +314,8 @@ gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc,
314 if (hp == NULL) 314 if (hp == NULL)
315 { 315 {
316 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 316 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
317 _("Could not find IP of host `%s': %s\n"), 317 _("Could not find IP of host `%s': %s\n"), hostname,
318 hostname, hstrerror (h_errno)); 318 hstrerror (h_errno));
319 return GNUNET_SYSERR; 319 return GNUNET_SYSERR;
320 } 320 }
321 GNUNET_assert (hp->h_addrtype == domain); 321 GNUNET_assert (hp->h_addrtype == domain);
@@ -328,9 +328,7 @@ gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc,
328 a4.sin_len = (u_char) sizeof (struct sockaddr_in); 328 a4.sin_len = (u_char) sizeof (struct sockaddr_in);
329#endif 329#endif
330 memcpy (&a4.sin_addr, hp->h_addr_list[0], hp->h_length); 330 memcpy (&a4.sin_addr, hp->h_addr_list[0], hp->h_length);
331 GNUNET_SERVER_transmit_context_append_data (tc, 331 GNUNET_SERVER_transmit_context_append_data (tc, &a4, sizeof (a4),
332 &a4,
333 sizeof (a4),
334 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 332 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
335 } 333 }
336 else 334 else
@@ -342,9 +340,7 @@ gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc,
342 a6.sin6_len = (u_char) sizeof (struct sockaddr_in6); 340 a6.sin6_len = (u_char) sizeof (struct sockaddr_in6);
343#endif 341#endif
344 memcpy (&a6.sin6_addr, hp->h_addr_list[0], hp->h_length); 342 memcpy (&a6.sin6_addr, hp->h_addr_list[0], hp->h_length);
345 GNUNET_SERVER_transmit_context_append_data (tc, 343 GNUNET_SERVER_transmit_context_append_data (tc, &a6, sizeof (a6),
346 &a6,
347 sizeof (a6),
348 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 344 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
349 } 345 }
350 return GNUNET_OK; 346 return GNUNET_OK;
@@ -363,8 +359,8 @@ gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc,
363 if (hp == NULL) 359 if (hp == NULL)
364 { 360 {
365 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 361 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
366 _("Could not find IP of host `%s': %s\n"), 362 _("Could not find IP of host `%s': %s\n"), hostname,
367 hostname, hstrerror (h_errno)); 363 hstrerror (h_errno));
368 return GNUNET_SYSERR; 364 return GNUNET_SYSERR;
369 } 365 }
370 if (hp->h_addrtype != AF_INET) 366 if (hp->h_addrtype != AF_INET)
@@ -379,9 +375,7 @@ gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc,
379 addr.sin_len = (u_char) sizeof (struct sockaddr_in); 375 addr.sin_len = (u_char) sizeof (struct sockaddr_in);
380#endif 376#endif
381 memcpy (&addr.sin_addr, hp->h_addr_list[0], hp->h_length); 377 memcpy (&addr.sin_addr, hp->h_addr_list[0], hp->h_length);
382 GNUNET_SERVER_transmit_context_append_data (tc, 378 GNUNET_SERVER_transmit_context_append_data (tc, &addr, sizeof (addr),
383 &addr,
384 sizeof (addr),
385 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 379 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
386 return GNUNET_OK; 380 return GNUNET_OK;
387} 381}
@@ -396,8 +390,8 @@ gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc,
396 * @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any" 390 * @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any"
397 */ 391 */
398static void 392static void
399get_ip_from_hostname (struct GNUNET_SERVER_Client *client, 393get_ip_from_hostname (struct GNUNET_SERVER_Client *client, const char *hostname,
400 const char *hostname, int domain) 394 int domain)
401{ 395{
402 int ret; 396 int ret;
403 struct GNUNET_SERVER_TransmitContext *tc; 397 struct GNUNET_SERVER_TransmitContext *tc;
@@ -430,8 +424,7 @@ get_ip_from_hostname (struct GNUNET_SERVER_Client *client,
430 * @param message the actual message 424 * @param message the actual message
431 */ 425 */
432static void 426static void
433handle_get (void *cls, 427handle_get (void *cls, struct GNUNET_SERVER_Client *client,
434 struct GNUNET_SERVER_Client *client,
435 const struct GNUNET_MessageHeader *message) 428 const struct GNUNET_MessageHeader *message)
436{ 429{
437 uint16_t msize; 430 uint16_t msize;
@@ -464,8 +457,8 @@ handle_get (void *cls,
464 return; 457 return;
465 } 458 }
466#if DEBUG_RESOLVER 459#if DEBUG_RESOLVER
467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 460 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolver asked to look up `%s'.\n"),
468 _("Resolver asked to look up `%s'.\n"), hostname); 461 hostname);
469#endif 462#endif
470 get_ip_from_hostname (client, hostname, domain); 463 get_ip_from_hostname (client, hostname, domain);
471 } 464 }
@@ -527,8 +520,7 @@ handle_get (void *cls,
527 * @param cfg configuration to use 520 * @param cfg configuration to use
528 */ 521 */
529static void 522static void
530run (void *cls, 523run (void *cls, struct GNUNET_SERVER_Handle *server,
531 struct GNUNET_SERVER_Handle *server,
532 const struct GNUNET_CONFIGURATION_Handle *cfg) 524 const struct GNUNET_CONFIGURATION_Handle *cfg)
533{ 525{
534 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 526 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
@@ -552,11 +544,10 @@ main (int argc, char *const *argv)
552 int ret; 544 int ret;
553 struct IPCache *pos; 545 struct IPCache *pos;
554 546
555 ret = (GNUNET_OK == 547 ret =
556 GNUNET_SERVICE_run (argc, 548 (GNUNET_OK ==
557 argv, 549 GNUNET_SERVICE_run (argc, argv, "resolver", GNUNET_SERVICE_OPTION_NONE,
558 "resolver", GNUNET_SERVICE_OPTION_NONE, 550 &run, NULL)) ? 0 : 1;
559 &run, NULL)) ? 0 : 1;
560 551
561 while (head != NULL) 552 while (head != NULL)
562 { 553 {
diff --git a/src/util/network.c b/src/util/network.c
index b533ce183..e071b8b54 100644
--- a/src/util/network.c
+++ b/src/util/network.c
@@ -212,8 +212,7 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc,
212 int gsn = getsockname (desc->fd, &name, &namelen); 212 int gsn = getsockname (desc->fd, &name, &namelen);
213 213
214 if (gsn == 0) 214 if (gsn == 0)
215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Accepting connection on `%s'\n",
216 "Accepting connection on `%s'\n",
217 GNUNET_a2s (&name, namelen)); 216 GNUNET_a2s (&name, namelen));
218 } 217 }
219#endif 218#endif
@@ -357,8 +356,8 @@ GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc)
357 const struct sockaddr_un *un = (const struct sockaddr_un *) desc->addr; 356 const struct sockaddr_un *un = (const struct sockaddr_un *) desc->addr;
358 357
359 if (0 != unlink (un->sun_path)) 358 if (0 != unlink (un->sun_path))
360 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 359 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink",
361 "unlink", un->sun_path); 360 un->sun_path);
362 } 361 }
363#endif 362#endif
364#endif 363#endif
@@ -480,8 +479,8 @@ GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc,
480 * @param desc socket 479 * @param desc socket
481 */ 480 */
482ssize_t 481ssize_t
483GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle 482GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle *
484 * desc) 483 desc)
485{ 484{
486 int error; 485 int error;
487 486
@@ -645,9 +644,8 @@ GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc,
645 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise 644 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
646 */ 645 */
647int 646int
648GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd, 647GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd, int level,
649 int level, int option_name, 648 int option_name, const void *option_value,
650 const void *option_value,
651 socklen_t option_len) 649 socklen_t option_len)
652{ 650{
653 int ret; 651 int ret;
@@ -945,8 +943,8 @@ GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds,
945{ 943{
946#ifdef MINGW 944#ifdef MINGW
947 GNUNET_CONTAINER_slist_add (fds->handles, 945 GNUNET_CONTAINER_slist_add (fds->handles,
948 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, 946 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, h,
949 h, sizeof (struct GNUNET_DISK_FileHandle)); 947 sizeof (struct GNUNET_DISK_FileHandle));
950 948
951#else 949#else
952 int fd; 950 int fd;
@@ -1569,10 +1567,9 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
1569 "send to the socket %d returned %d (%u)\n", i, status, 1567 "send to the socket %d returned %d (%u)\n", i, status,
1570 error); 1568 error);
1571#endif 1569#endif
1572 if (status == 0 1570 if (status == 0 || (error != WSAEWOULDBLOCK && error != WSAENOTCONN) ||
1573 || (error != WSAEWOULDBLOCK && error != WSAENOTCONN) 1571 (status == -1 && gso_result == 0 && error == WSAENOTCONN &&
1574 || (status == -1 && gso_result == 0 && error == WSAENOTCONN && 1572 so_error == WSAECONNREFUSED))
1575 so_error == WSAECONNREFUSED))
1576 { 1573 {
1577 FD_SET (wfds->sds.fd_array[i], &awrite); 1574 FD_SET (wfds->sds.fd_array[i], &awrite);
1578 retcode += 1; 1575 retcode += 1;
diff --git a/src/util/os_installation.c b/src/util/os_installation.c
index 188401abb..00825f2b7 100644
--- a/src/util/os_installation.c
+++ b/src/util/os_installation.c
@@ -57,9 +57,9 @@ get_path_from_proc_maps ()
57 return NULL; 57 return NULL;
58 while (NULL != fgets (line, sizeof (line), f)) 58 while (NULL != fgets (line, sizeof (line), f))
59 { 59 {
60 if ((1 == sscanf (line, 60 if ((1 ==
61 "%*x-%*x %*c%*c%*c%*c %*x %*2u:%*2u %*u%*[ ]%s", 61 sscanf (line, "%*x-%*x %*c%*c%*c%*c %*x %*2u:%*2u %*u%*[ ]%s", dir)) &&
62 dir)) && (NULL != (lgu = strstr (dir, "libgnunetutil")))) 62 (NULL != (lgu = strstr (dir, "libgnunetutil"))))
63 { 63 {
64 lgu[0] = '\0'; 64 lgu[0] = '\0';
65 fclose (f); 65 fclose (f);
@@ -476,8 +476,8 @@ GNUNET_OS_check_helper_binary (const char *binary)
476 } 476 }
477 if (0 != STAT (p, &statbuf)) 477 if (0 != STAT (p, &statbuf))
478 { 478 {
479 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 479 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("stat (%s) failed: %s\n"), p,
480 _("stat (%s) failed: %s\n"), p, STRERROR (errno)); 480 STRERROR (errno));
481 GNUNET_free (p); 481 GNUNET_free (p);
482 return GNUNET_SYSERR; 482 return GNUNET_SYSERR;
483 } 483 }
diff --git a/src/util/os_network.c b/src/util/os_network.c
index af8046814..21376f94c 100644
--- a/src/util/os_network.c
+++ b/src/util/os_network.c
@@ -131,15 +131,12 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
131 131
132 /* Set entry */ 132 /* Set entry */
133 memset (bPhysAddr, 0, MAXLEN_PHYSADDR); 133 memset (bPhysAddr, 0, MAXLEN_PHYSADDR);
134 memcpy (bPhysAddr, 134 memcpy (bPhysAddr, pTable->table[dwIfIdx].bPhysAddr,
135 pTable->table[dwIfIdx].bPhysAddr,
136 pTable->table[dwIfIdx].dwPhysAddrLen); 135 pTable->table[dwIfIdx].dwPhysAddrLen);
137 136
138 snprintf (szEntry, 1000, "%s (%s - %I64u)", 137 snprintf (szEntry, 1000, "%s (%s - %I64u)",
139 pszIfName ? pszIfName : (char *) 138 pszIfName ? pszIfName : (char *) pTable->table[dwIfIdx].
140 pTable->table[dwIfIdx].bDescr, inet_ntop (AF_INET, 139 bDescr, inet_ntop (AF_INET, &dwIP, dst, INET_ADDRSTRLEN),
141 &dwIP, dst,
142 INET_ADDRSTRLEN),
143 *((unsigned long long *) bPhysAddr)); 140 *((unsigned long long *) bPhysAddr));
144 szEntry[1000] = 0; 141 szEntry[1000] = 0;
145 142
@@ -153,8 +150,7 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
153 sa.sin_addr.S_un.S_addr = dwIP; 150 sa.sin_addr.S_un.S_addr = dwIP;
154 151
155 if (GNUNET_OK != 152 if (GNUNET_OK !=
156 proc (proc_cls, 153 proc (proc_cls, szEntry,
157 szEntry,
158 pTable->table[dwIfIdx].dwIndex == dwExternalNIC, 154 pTable->table[dwIfIdx].dwIndex == dwExternalNIC,
159 (const struct sockaddr *) &sa, sizeof (sa))) 155 (const struct sockaddr *) &sa, sizeof (sa)))
160 break; 156 break;
@@ -176,8 +172,8 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
176 { 172 {
177 for (ifa_ptr = ifa_first; ifa_ptr != NULL; ifa_ptr = ifa_ptr->ifa_next) 173 for (ifa_ptr = ifa_first; ifa_ptr != NULL; ifa_ptr = ifa_ptr->ifa_next)
178 { 174 {
179 if (ifa_ptr->ifa_name != NULL && 175 if (ifa_ptr->ifa_name != NULL && ifa_ptr->ifa_addr != NULL &&
180 ifa_ptr->ifa_addr != NULL && (ifa_ptr->ifa_flags & IFF_UP) != 0) 176 (ifa_ptr->ifa_flags & IFF_UP) != 0)
181 { 177 {
182 if ((ifa_ptr->ifa_addr->sa_family != AF_INET) && 178 if ((ifa_ptr->ifa_addr->sa_family != AF_INET) &&
183 (ifa_ptr->ifa_addr->sa_family != AF_INET6)) 179 (ifa_ptr->ifa_addr->sa_family != AF_INET6))
@@ -186,11 +182,10 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
186 alen = sizeof (struct sockaddr_in); 182 alen = sizeof (struct sockaddr_in);
187 else 183 else
188 alen = sizeof (struct sockaddr_in6); 184 alen = sizeof (struct sockaddr_in6);
189 if (GNUNET_OK != proc (proc_cls, 185 if (GNUNET_OK !=
190 ifa_ptr->ifa_name, 186 proc (proc_cls, ifa_ptr->ifa_name,
191 0 == strcmp (ifa_ptr->ifa_name, 187 0 == strcmp (ifa_ptr->ifa_name, GNUNET_DEFAULT_INTERFACE),
192 GNUNET_DEFAULT_INTERFACE), 188 ifa_ptr->ifa_addr, alen))
193 ifa_ptr->ifa_addr, alen))
194 break; 189 break;
195 } 190 }
196 } 191 }
@@ -261,9 +256,7 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
261#endif 256#endif
262 a4.sin_addr = v4; 257 a4.sin_addr = v4;
263 if (GNUNET_OK != 258 if (GNUNET_OK !=
264 proc (proc_cls, 259 proc (proc_cls, ifc, 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE),
265 ifc,
266 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE),
267 (const struct sockaddr *) &a4, sizeof (a4))) 260 (const struct sockaddr *) &a4, sizeof (a4)))
268 break; 261 break;
269 continue; 262 continue;
@@ -278,9 +271,7 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
278#endif 271#endif
279 a6.sin6_addr = v6; 272 a6.sin6_addr = v6;
280 if (GNUNET_OK != 273 if (GNUNET_OK !=
281 proc (proc_cls, 274 proc (proc_cls, ifc, 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE),
282 ifc,
283 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE),
284 (const struct sockaddr *) &a6, sizeof (a6))) 275 (const struct sockaddr *) &a6, sizeof (a6)))
285 break; 276 break;
286 continue; 277 continue;
diff --git a/src/util/os_priority.c b/src/util/os_priority.c
index bccde8d46..d27642a58 100644
--- a/src/util/os_priority.c
+++ b/src/util/os_priority.c
@@ -60,19 +60,20 @@ parent_control_handler (void *cls,
60 int sig; 60 int sig;
61 61
62#if DEBUG_OS 62#if DEBUG_OS
63 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 63 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' invoked because of %d\n",
64 "`%s' invoked because of %d\n", __FUNCTION__, tc->reason); 64 __FUNCTION__, tc->reason);
65#endif 65#endif
66 if (tc->reason & (GNUNET_SCHEDULER_REASON_SHUTDOWN | 66 if (tc->
67 GNUNET_SCHEDULER_REASON_TIMEOUT | 67 reason & (GNUNET_SCHEDULER_REASON_SHUTDOWN |
68 GNUNET_SCHEDULER_REASON_PREREQ_DONE)) 68 GNUNET_SCHEDULER_REASON_TIMEOUT |
69 GNUNET_SCHEDULER_REASON_PREREQ_DONE))
69 { 70 {
70 GNUNET_DISK_npipe_close (control_pipe); 71 GNUNET_DISK_npipe_close (control_pipe);
71 } 72 }
72 else 73 else
73 { 74 {
74 if (GNUNET_DISK_file_read (control_pipe, 75 if (GNUNET_DISK_file_read (control_pipe, &sig, sizeof (sig)) !=
75 &sig, sizeof (sig)) != sizeof (sig)) 76 sizeof (sig))
76 { 77 {
77 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DISK_file_read"); 78 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DISK_file_read");
78 GNUNET_DISK_npipe_close (control_pipe); 79 GNUNET_DISK_npipe_close (control_pipe);
@@ -80,12 +81,12 @@ parent_control_handler (void *cls,
80 else 81 else
81 { 82 {
82#if DEBUG_OS 83#if DEBUG_OS
83 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 84 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got control code %d from parent\n",
84 "Got control code %d from parent\n", sig); 85 sig);
85#endif 86#endif
86 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 87 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
87 control_pipe, 88 control_pipe, &parent_control_handler,
88 &parent_control_handler, control_pipe); 89 control_pipe);
89 raise (sig); 90 raise (sig);
90 } 91 }
91 } 92 }
@@ -111,10 +112,10 @@ GNUNET_OS_install_parent_control_handler (void *cls,
111 GNUNET_OS_CONTROL_PIPE, env_buf); 112 GNUNET_OS_CONTROL_PIPE, env_buf);
112 return; 113 return;
113 } 114 }
114 control_pipe = GNUNET_DISK_npipe_open (env_buf, 115 control_pipe =
115 GNUNET_DISK_OPEN_READ, 116 GNUNET_DISK_npipe_open (env_buf, GNUNET_DISK_OPEN_READ,
116 GNUNET_DISK_PERM_USER_READ | 117 GNUNET_DISK_PERM_USER_READ |
117 GNUNET_DISK_PERM_USER_WRITE); 118 GNUNET_DISK_PERM_USER_WRITE);
118 if (control_pipe == NULL) 119 if (control_pipe == NULL)
119 { 120 {
120 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "open", env_buf); 121 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "open", env_buf);
@@ -125,8 +126,7 @@ GNUNET_OS_install_parent_control_handler (void *cls,
125 "Adding parent control handler pipe `%s' to the scheduler\n", 126 "Adding parent control handler pipe `%s' to the scheduler\n",
126 env_buf); 127 env_buf);
127#endif 128#endif
128 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 129 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, control_pipe,
129 control_pipe,
130 &parent_control_handler, control_pipe); 130 &parent_control_handler, control_pipe);
131} 131}
132 132
@@ -219,13 +219,14 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig)
219 */ 219 */
220 while (1) 220 while (1)
221 { 221 {
222 ret = GNUNET_NETWORK_socket_select (rfds, NULL, efds, 222 ret =
223 GNUNET_TIME_relative_multiply 223 GNUNET_NETWORK_socket_select (rfds, NULL, efds,
224 (GNUNET_TIME_relative_get_unit (), 224 GNUNET_TIME_relative_multiply
225 5000)); 225 (GNUNET_TIME_relative_get_unit (),
226 226 5000));
227 if (ret < 1 || GNUNET_NETWORK_fdset_handle_isset (efds, 227
228 proc->control_pipe)) 228 if (ret < 1 ||
229 GNUNET_NETWORK_fdset_handle_isset (efds, proc->control_pipe))
229 { 230 {
230 /* Just to be sure */ 231 /* Just to be sure */
231 PLIBC_KILL (proc->pid, sig); 232 PLIBC_KILL (proc->pid, sig);
@@ -234,8 +235,8 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig)
234 } 235 }
235 else 236 else
236 { 237 {
237 if (GNUNET_DISK_file_read (proc->control_pipe, &ret, 238 if (GNUNET_DISK_file_read (proc->control_pipe, &ret, sizeof (ret)) !=
238 sizeof (ret)) != GNUNET_OK) 239 GNUNET_OK)
239 res = PLIBC_KILL (proc->pid, sig); 240 res = PLIBC_KILL (proc->pid, sig);
240 241
241 /* Child signaled shutdown is in progress */ 242 /* Child signaled shutdown is in progress */
@@ -394,8 +395,8 @@ GNUNET_OS_set_process_priority (struct GNUNET_OS_Process *proc,
394 errno = 0; 395 errno = 0;
395 if ((delta != 0) && (rprio == nice (delta)) && (errno != 0)) 396 if ((delta != 0) && (rprio == nice (delta)) && (errno != 0))
396 { 397 {
397 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING | 398 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
398 GNUNET_ERROR_TYPE_BULK, "nice"); 399 "nice");
399 return GNUNET_SYSERR; 400 return GNUNET_SYSERR;
400 } 401 }
401 } 402 }
@@ -403,8 +404,8 @@ GNUNET_OS_set_process_priority (struct GNUNET_OS_Process *proc,
403 { 404 {
404 if (0 != setpriority (PRIO_PROCESS, pid, rprio)) 405 if (0 != setpriority (PRIO_PROCESS, pid, rprio))
405 { 406 {
406 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING | 407 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
407 GNUNET_ERROR_TYPE_BULK, "setpriority"); 408 "setpriority");
408 return GNUNET_SYSERR; 409 return GNUNET_SYSERR;
409 } 410 }
410 } 411 }
@@ -552,10 +553,10 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin,
552 int fd_stdin_write; 553 int fd_stdin_write;
553 554
554#if ENABLE_WINDOWS_WORKAROUNDS 555#if ENABLE_WINDOWS_WORKAROUNDS
555 control_pipe = GNUNET_DISK_npipe_create (&childpipename, 556 control_pipe =
556 GNUNET_DISK_OPEN_WRITE, 557 GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE,
557 GNUNET_DISK_PERM_USER_READ | 558 GNUNET_DISK_PERM_USER_READ |
558 GNUNET_DISK_PERM_USER_WRITE); 559 GNUNET_DISK_PERM_USER_WRITE);
559 if (control_pipe == NULL) 560 if (control_pipe == NULL)
560 return NULL; 561 return NULL;
561#endif 562#endif
@@ -776,10 +777,10 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin,
776 start.hStdOutput = stdout_handle; 777 start.hStdOutput = stdout_handle;
777 } 778 }
778 779
779 control_pipe = GNUNET_DISK_npipe_create (&childpipename, 780 control_pipe =
780 GNUNET_DISK_OPEN_WRITE, 781 GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE,
781 GNUNET_DISK_PERM_USER_READ | 782 GNUNET_DISK_PERM_USER_READ |
782 GNUNET_DISK_PERM_USER_WRITE); 783 GNUNET_DISK_PERM_USER_WRITE);
783 if (control_pipe == NULL) 784 if (control_pipe == NULL)
784 { 785 {
785 GNUNET_free (cmd); 786 GNUNET_free (cmd);
@@ -865,8 +866,8 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin,
865 * @return process ID of the new process, -1 on error 866 * @return process ID of the new process, -1 on error
866 */ 867 */
867struct GNUNET_OS_Process * 868struct GNUNET_OS_Process *
868GNUNET_OS_start_process_v (const int *lsocks, 869GNUNET_OS_start_process_v (const int *lsocks, const char *filename,
869 const char *filename, char *const argv[]) 870 char *const argv[])
870{ 871{
871#if ENABLE_WINDOWS_WORKAROUNDS 872#if ENABLE_WINDOWS_WORKAROUNDS
872 struct GNUNET_DISK_FileHandle *control_pipe = NULL; 873 struct GNUNET_DISK_FileHandle *control_pipe = NULL;
@@ -887,10 +888,10 @@ GNUNET_OS_start_process_v (const int *lsocks,
887 unsigned int ls; 888 unsigned int ls;
888 889
889#if ENABLE_WINDOWS_WORKAROUNDS 890#if ENABLE_WINDOWS_WORKAROUNDS
890 control_pipe = GNUNET_DISK_npipe_create (&childpipename, 891 control_pipe =
891 GNUNET_DISK_OPEN_WRITE, 892 GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE,
892 GNUNET_DISK_PERM_USER_READ | 893 GNUNET_DISK_PERM_USER_READ |
893 GNUNET_DISK_PERM_USER_WRITE); 894 GNUNET_DISK_PERM_USER_WRITE);
894 if (control_pipe == NULL) 895 if (control_pipe == NULL)
895 return NULL; 896 return NULL;
896#endif 897#endif
@@ -1121,10 +1122,10 @@ GNUNET_OS_start_process_v (const int *lsocks,
1121 memset (&start, 0, sizeof (start)); 1122 memset (&start, 0, sizeof (start));
1122 start.cb = sizeof (start); 1123 start.cb = sizeof (start);
1123 1124
1124 control_pipe = GNUNET_DISK_npipe_create (&childpipename, 1125 control_pipe =
1125 GNUNET_DISK_OPEN_WRITE, 1126 GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE,
1126 GNUNET_DISK_PERM_USER_READ | 1127 GNUNET_DISK_PERM_USER_READ |
1127 GNUNET_DISK_PERM_USER_WRITE); 1128 GNUNET_DISK_PERM_USER_WRITE);
1128 if (control_pipe == NULL) 1129 if (control_pipe == NULL)
1129 { 1130 {
1130 GNUNET_free (cmd); 1131 GNUNET_free (cmd);
@@ -1414,9 +1415,9 @@ cmd_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1414 proc (cmd->proc_cls, NULL); 1415 proc (cmd->proc_cls, NULL);
1415 return; 1416 return;
1416 } 1417 }
1417 ret = GNUNET_DISK_file_read (cmd->r, 1418 ret =
1418 &cmd->buf[cmd->off], 1419 GNUNET_DISK_file_read (cmd->r, &cmd->buf[cmd->off],
1419 sizeof (cmd->buf) - cmd->off); 1420 sizeof (cmd->buf) - cmd->off);
1420 if (ret <= 0) 1421 if (ret <= 0)
1421 { 1422 {
1422 if ((cmd->off > 0) && (cmd->off < sizeof (cmd->buf))) 1423 if ((cmd->off > 0) && (cmd->off < sizeof (cmd->buf)))
@@ -1457,10 +1458,9 @@ cmd_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1457 * @return NULL on error 1458 * @return NULL on error
1458 */ 1459 */
1459struct GNUNET_OS_CommandHandle * 1460struct GNUNET_OS_CommandHandle *
1460GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, 1461GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, void *proc_cls,
1461 void *proc_cls, 1462 struct GNUNET_TIME_Relative timeout, const char *binary,
1462 struct GNUNET_TIME_Relative timeout, 1463 ...)
1463 const char *binary, ...)
1464{ 1464{
1465 struct GNUNET_OS_CommandHandle *cmd; 1465 struct GNUNET_OS_CommandHandle *cmd;
1466 struct GNUNET_OS_Process *eip; 1466 struct GNUNET_OS_Process *eip;
diff --git a/src/util/peer.c b/src/util/peer.c
index 91a706040..62fa0e2f2 100644
--- a/src/util/peer.c
+++ b/src/util/peer.c
@@ -148,8 +148,7 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid)
148 table[ret].rc = 1; 148 table[ret].rc = 1;
149 table[ret].pid = ret; 149 table[ret].pid = ret;
150 GNUNET_break (GNUNET_OK == 150 GNUNET_break (GNUNET_OK ==
151 GNUNET_CONTAINER_multihashmap_put (map, 151 GNUNET_CONTAINER_multihashmap_put (map, &pid->hashPubKey,
152 &pid->hashPubKey,
153 (void *) (long) ret, 152 (void *) (long) ret,
154 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 153 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
155 return ret; 154 return ret;
@@ -182,8 +181,8 @@ GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id *ids, unsigned int count)
182 { 181 {
183 GNUNET_break (GNUNET_OK == 182 GNUNET_break (GNUNET_OK ==
184 GNUNET_CONTAINER_multihashmap_remove (map, 183 GNUNET_CONTAINER_multihashmap_remove (map,
185 &table[id]. 184 &table[id].id.
186 id.hashPubKey, 185 hashPubKey,
187 (void *) (long) id)); 186 (void *) (long) id));
188 table[id].pid = free_list_start; 187 table[id].pid = free_list_start;
189 free_list_start = id; 188 free_list_start = id;
@@ -211,8 +210,8 @@ GNUNET_PEER_change_rc (GNUNET_PEER_Id id, int delta)
211 { 210 {
212 GNUNET_break (GNUNET_OK == 211 GNUNET_break (GNUNET_OK ==
213 GNUNET_CONTAINER_multihashmap_remove (map, 212 GNUNET_CONTAINER_multihashmap_remove (map,
214 &table[id]. 213 &table[id].id.
215 id.hashPubKey, 214 hashPubKey,
216 (void *) (long) id)); 215 (void *) (long) id));
217 table[id].pid = free_list_start; 216 table[id].pid = free_list_start;
218 free_list_start = id; 217 free_list_start = id;
diff --git a/src/util/perf_crypto_hash.c b/src/util/perf_crypto_hash.c
index d883776b4..689781835 100644
--- a/src/util/perf_crypto_hash.c
+++ b/src/util/perf_crypto_hash.c
@@ -58,12 +58,12 @@ main (int argc, char *argv[])
58 start = GNUNET_TIME_absolute_get (); 58 start = GNUNET_TIME_absolute_get ();
59 perfHash (); 59 perfHash ();
60 printf ("Hash perf took %llu ms\n", 60 printf ("Hash perf took %llu ms\n",
61 (unsigned long long) 61 (unsigned long long) GNUNET_TIME_absolute_get_duration (start).
62 GNUNET_TIME_absolute_get_duration (start).rel_value); 62 rel_value);
63 GAUGER ("UTIL", "Cryptographic hashing", 63 GAUGER ("UTIL", "Cryptographic hashing",
64 1024 * 64 * 1024 / (1 + 64 1024 * 64 * 1024 / (1 +
65 GNUNET_TIME_absolute_get_duration 65 GNUNET_TIME_absolute_get_duration (start).
66 (start).rel_value), "kb/s"); 66 rel_value), "kb/s");
67 return 0; 67 return 0;
68} 68}
69 69
diff --git a/src/util/plugin.c b/src/util/plugin.c
index b1c979dff..08b32b295 100644
--- a/src/util/plugin.c
+++ b/src/util/plugin.c
@@ -84,8 +84,7 @@ plugin_init ()
84 err = lt_dlinit (); 84 err = lt_dlinit ();
85 if (err > 0) 85 if (err > 0)
86 { 86 {
87 fprintf (stderr, 87 fprintf (stderr, _("Initialization of plugin mechanism failed: %s!\n"),
88 _("Initialization of plugin mechanism failed: %s!\n"),
89 lt_dlerror ()); 88 lt_dlerror ());
90 return; 89 return;
91 } 90 }
diff --git a/src/util/program.c b/src/util/program.c
index cccb7db73..f1e95477d 100644
--- a/src/util/program.c
+++ b/src/util/program.c
@@ -124,9 +124,7 @@ cmd_sorter (__const void *a1, __const void *a2)
124 * @return GNUNET_SYSERR on error, GNUNET_OK on success 124 * @return GNUNET_SYSERR on error, GNUNET_OK on success
125 */ 125 */
126int 126int
127GNUNET_PROGRAM_run (int argc, 127GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName,
128 char *const *argv,
129 const char *binaryName,
130 const char *binaryHelp, 128 const char *binaryHelp,
131 const struct GNUNET_GETOPT_CommandLineOption *options, 129 const struct GNUNET_GETOPT_CommandLineOption *options,
132 GNUNET_PROGRAM_Main task, void *task_cls) 130 GNUNET_PROGRAM_Main task, void *task_cls)
@@ -217,13 +215,10 @@ GNUNET_PROGRAM_run (int argc,
217 lpfx = GNUNET_strdup (binaryName); 215 lpfx = GNUNET_strdup (binaryName);
218 if (NULL != (spc = strstr (lpfx, " "))) 216 if (NULL != (spc = strstr (lpfx, " ")))
219 *spc = '\0'; 217 *spc = '\0';
220 if ((-1 == (ret = GNUNET_GETOPT_run (binaryName, 218 if ((-1 ==
221 allopts, 219 (ret =
222 (unsigned int) argc, argv))) || 220 GNUNET_GETOPT_run (binaryName, allopts, (unsigned int) argc, argv))) ||
223 ((GNUNET_OK != 221 ((GNUNET_OK != GNUNET_log_setup (lpfx, loglev, logfile)) ||
224 GNUNET_log_setup (lpfx,
225 loglev,
226 logfile)) ||
227 (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cc.cfgfile)))) 222 (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cc.cfgfile))))
228 { 223 {
229 GNUNET_CONFIGURATION_destroy (cfg); 224 GNUNET_CONFIGURATION_destroy (cfg);
diff --git a/src/util/pseudonym.c b/src/util/pseudonym.c
index 254decb76..85a485098 100644
--- a/src/util/pseudonym.c
+++ b/src/util/pseudonym.c
@@ -99,8 +99,7 @@ internal_notify (const GNUNET_HashCode * id,
99 */ 99 */
100int 100int
101GNUNET_PSEUDONYM_discovery_callback_register (const struct 101GNUNET_PSEUDONYM_discovery_callback_register (const struct
102 GNUNET_CONFIGURATION_Handle 102 GNUNET_CONFIGURATION_Handle *cfg,
103 *cfg,
104 GNUNET_PSEUDONYM_Iterator 103 GNUNET_PSEUDONYM_Iterator
105 iterator, void *closure) 104 iterator, void *closure)
106{ 105{
@@ -155,16 +154,14 @@ GNUNET_PSEUDONYM_discovery_callback_unregister (GNUNET_PSEUDONYM_Iterator
155 * @return filename of the pseudonym (if psid != NULL) or directory with the data (if psid == NULL) 154 * @return filename of the pseudonym (if psid != NULL) or directory with the data (if psid == NULL)
156 */ 155 */
157static char * 156static char *
158get_data_filename (const struct GNUNET_CONFIGURATION_Handle 157get_data_filename (const struct GNUNET_CONFIGURATION_Handle *cfg,
159 *cfg, const char *prefix, const GNUNET_HashCode * psid) 158 const char *prefix, const GNUNET_HashCode * psid)
160{ 159{
161 struct GNUNET_CRYPTO_HashAsciiEncoded enc; 160 struct GNUNET_CRYPTO_HashAsciiEncoded enc;
162 161
163 if (psid != NULL) 162 if (psid != NULL)
164 GNUNET_CRYPTO_hash_to_enc (psid, &enc); 163 GNUNET_CRYPTO_hash_to_enc (psid, &enc);
165 return GNUNET_DISK_get_home_filename (cfg, 164 return GNUNET_DISK_get_home_filename (cfg, GNUNET_CLIENT_SERVICE_NAME, prefix,
166 GNUNET_CLIENT_SERVICE_NAME,
167 prefix,
168 (psid == 165 (psid ==
169 NULL) ? NULL : (const char *) &enc, 166 NULL) ? NULL : (const char *) &enc,
170 NULL); 167 NULL);
@@ -228,8 +225,8 @@ write_pseudonym_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
228static int 225static int
229read_info (const struct GNUNET_CONFIGURATION_Handle *cfg, 226read_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
230 const GNUNET_HashCode * nsid, 227 const GNUNET_HashCode * nsid,
231 struct GNUNET_CONTAINER_MetaData **meta, 228 struct GNUNET_CONTAINER_MetaData **meta, int32_t * ranking,
232 int32_t * ranking, char **ns_name) 229 char **ns_name)
233{ 230{
234 char *fn; 231 char *fn;
235 char *emsg; 232 char *emsg;
@@ -309,16 +306,17 @@ GNUNET_PSEUDONYM_id_to_name (const struct GNUNET_CONFIGURATION_Handle *cfg,
309 if (GNUNET_OK == read_info (cfg, nsid, &meta, rank, &name)) 306 if (GNUNET_OK == read_info (cfg, nsid, &meta, rank, &name))
310 { 307 {
311 if ((meta != NULL) && (name == NULL)) 308 if ((meta != NULL) && (name == NULL))
312 name = GNUNET_CONTAINER_meta_data_get_first_by_types (meta, 309 name =
313 EXTRACTOR_METATYPE_TITLE, 310 GNUNET_CONTAINER_meta_data_get_first_by_types (meta,
314 EXTRACTOR_METATYPE_FILENAME, 311 EXTRACTOR_METATYPE_TITLE,
315 EXTRACTOR_METATYPE_DESCRIPTION, 312 EXTRACTOR_METATYPE_FILENAME,
316 EXTRACTOR_METATYPE_SUBJECT, 313 EXTRACTOR_METATYPE_DESCRIPTION,
317 EXTRACTOR_METATYPE_PUBLISHER, 314 EXTRACTOR_METATYPE_SUBJECT,
318 EXTRACTOR_METATYPE_AUTHOR_NAME, 315 EXTRACTOR_METATYPE_PUBLISHER,
319 EXTRACTOR_METATYPE_COMMENT, 316 EXTRACTOR_METATYPE_AUTHOR_NAME,
320 EXTRACTOR_METATYPE_SUMMARY, 317 EXTRACTOR_METATYPE_COMMENT,
321 -1); 318 EXTRACTOR_METATYPE_SUMMARY,
319 -1);
322 if (meta != NULL) 320 if (meta != NULL)
323 { 321 {
324 GNUNET_CONTAINER_meta_data_destroy (meta); 322 GNUNET_CONTAINER_meta_data_destroy (meta);
@@ -334,15 +332,16 @@ GNUNET_PSEUDONYM_id_to_name (const struct GNUNET_CONFIGURATION_Handle *cfg,
334 len = 0; 332 len = 0;
335 if (0 == STAT (fn, &sbuf)) 333 if (0 == STAT (fn, &sbuf))
336 GNUNET_DISK_file_size (fn, &len, GNUNET_YES); 334 GNUNET_DISK_file_size (fn, &len, GNUNET_YES);
337 fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_CREATE 335 fh = GNUNET_DISK_file_open (fn,
338 | GNUNET_DISK_OPEN_READWRITE, 336 GNUNET_DISK_OPEN_CREATE |
337 GNUNET_DISK_OPEN_READWRITE,
339 GNUNET_DISK_PERM_USER_READ | 338 GNUNET_DISK_PERM_USER_READ |
340 GNUNET_DISK_PERM_USER_WRITE); 339 GNUNET_DISK_PERM_USER_WRITE);
341 i = 0; 340 i = 0;
342 idx = -1; 341 idx = -1;
343 while ((len >= sizeof (GNUNET_HashCode)) && 342 while ((len >= sizeof (GNUNET_HashCode)) &&
344 (sizeof (GNUNET_HashCode) 343 (sizeof (GNUNET_HashCode) ==
345 == GNUNET_DISK_file_read (fh, &nh, sizeof (GNUNET_HashCode)))) 344 GNUNET_DISK_file_read (fh, &nh, sizeof (GNUNET_HashCode))))
346 { 345 {
347 if (0 == memcmp (&nh, nsid, sizeof (GNUNET_HashCode))) 346 if (0 == memcmp (&nh, nsid, sizeof (GNUNET_HashCode)))
348 { 347 {
@@ -407,8 +406,9 @@ GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg,
407 GNUNET_free (fn); 406 GNUNET_free (fn);
408 return GNUNET_SYSERR; 407 return GNUNET_SYSERR;
409 } 408 }
410 fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_CREATE 409 fh = GNUNET_DISK_file_open (fn,
411 | GNUNET_DISK_OPEN_READWRITE, 410 GNUNET_DISK_OPEN_CREATE |
411 GNUNET_DISK_OPEN_READWRITE,
412 GNUNET_DISK_PERM_USER_READ | 412 GNUNET_DISK_PERM_USER_READ |
413 GNUNET_DISK_PERM_USER_WRITE); 413 GNUNET_DISK_PERM_USER_WRITE);
414 GNUNET_free (fn); 414 GNUNET_free (fn);
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c
index ef48faf59..3aa8bff9c 100644
--- a/src/util/resolver_api.c
+++ b/src/util/resolver_api.c
@@ -191,17 +191,16 @@ check_config (const struct GNUNET_CONFIGURATION_Handle *cfg)
191 v6.sin6_len = sizeof (v6); 191 v6.sin6_len = sizeof (v6);
192#endif 192#endif
193 if (GNUNET_OK != 193 if (GNUNET_OK !=
194 GNUNET_CONFIGURATION_get_value_string (cfg, 194 GNUNET_CONFIGURATION_get_value_string (cfg, "resolver", "HOSTNAME",
195 "resolver", "HOSTNAME", &hostname)) 195 &hostname))
196 { 196 {
197 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 197 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
198 _("Must specify `%s' for `%s' in configuration!\n"), 198 _("Must specify `%s' for `%s' in configuration!\n"), "HOSTNAME",
199 "HOSTNAME", "resolver"); 199 "resolver");
200 GNUNET_assert (0); 200 GNUNET_assert (0);
201 } 201 }
202 if ((1 != inet_pton (AF_INET, 202 if ((1 != inet_pton (AF_INET, hostname, &v4)) ||
203 hostname, 203 (1 != inet_pton (AF_INET6, hostname, &v6)))
204 &v4)) || (1 != inet_pton (AF_INET6, hostname, &v6)))
205 { 204 {
206 GNUNET_free (hostname); 205 GNUNET_free (hostname);
207 return; 206 return;
@@ -288,9 +287,8 @@ no_resolve (const struct sockaddr *sa, socklen_t salen)
288 if (salen != sizeof (struct sockaddr_in)) 287 if (salen != sizeof (struct sockaddr_in))
289 return NULL; 288 return NULL;
290 if (NULL == 289 if (NULL ==
291 inet_ntop (AF_INET, 290 inet_ntop (AF_INET, &((struct sockaddr_in *) sa)->sin_addr, inet4,
292 &((struct sockaddr_in *) sa)->sin_addr, 291 INET_ADDRSTRLEN))
293 inet4, INET_ADDRSTRLEN))
294 { 292 {
295 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); 293 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
296 return NULL; 294 return NULL;
@@ -301,9 +299,8 @@ no_resolve (const struct sockaddr *sa, socklen_t salen)
301 if (salen != sizeof (struct sockaddr_in6)) 299 if (salen != sizeof (struct sockaddr_in6))
302 return NULL; 300 return NULL;
303 if (NULL == 301 if (NULL ==
304 inet_ntop (AF_INET6, 302 inet_ntop (AF_INET6, &((struct sockaddr_in6 *) sa)->sin6_addr, inet6,
305 &((struct sockaddr_in6 *) sa)->sin6_addr, 303 INET6_ADDRSTRLEN))
306 inet6, INET6_ADDRSTRLEN))
307 { 304 {
308 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); 305 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
309 return NULL; 306 return NULL;
@@ -427,15 +424,13 @@ handle_response (void *cls, const struct GNUNET_MessageHeader *msg)
427 } 424 }
428#if DEBUG_RESOLVER 425#if DEBUG_RESOLVER
429 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
430 _("Resolver returns `%s' for IP `%s'.\n"), 427 _("Resolver returns `%s' for IP `%s'.\n"), hostname,
431 hostname, GNUNET_a2s ((const void *) &rh[1], rh->data_len)); 428 GNUNET_a2s ((const void *) &rh[1], rh->data_len));
432#endif 429#endif
433 if (rh->was_transmitted != GNUNET_SYSERR) 430 if (rh->was_transmitted != GNUNET_SYSERR)
434 rh->name_callback (rh->cls, hostname); 431 rh->name_callback (rh->cls, hostname);
435 rh->received_response = GNUNET_YES; 432 rh->received_response = GNUNET_YES;
436 GNUNET_CLIENT_receive (client, 433 GNUNET_CLIENT_receive (client, &handle_response, rh,
437 &handle_response,
438 rh,
439 GNUNET_TIME_absolute_get_remaining (rh->timeout)); 434 GNUNET_TIME_absolute_get_remaining (rh->timeout));
440 } 435 }
441 /* return lookup results to caller */ 436 /* return lookup results to caller */
@@ -459,16 +454,13 @@ handle_response (void *cls, const struct GNUNET_MessageHeader *msg)
459 { 454 {
460 char *ips = no_resolve (sa, salen); 455 char *ips = no_resolve (sa, salen);
461 456
462 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Resolver returns `%s' for `%s'.\n",
463 "Resolver returns `%s' for `%s'.\n",
464 ips, (const char *) &rh[1]); 458 ips, (const char *) &rh[1]);
465 GNUNET_free (ips); 459 GNUNET_free (ips);
466 } 460 }
467#endif 461#endif
468 rh->addr_callback (rh->cls, sa, salen); 462 rh->addr_callback (rh->cls, sa, salen);
469 GNUNET_CLIENT_receive (client, 463 GNUNET_CLIENT_receive (client, &handle_response, rh,
470 &handle_response,
471 rh,
472 GNUNET_TIME_absolute_get_remaining (rh->timeout)); 464 GNUNET_TIME_absolute_get_remaining (rh->timeout));
473 } 465 }
474} 466}
@@ -610,8 +602,9 @@ process_requests ()
610 { 602 {
611 /* nothing to do, release socket really soon if there is nothing 603 /* nothing to do, release socket really soon if there is nothing
612 * else happening... */ 604 * else happening... */
613 s_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, 605 s_task =
614 &shutdown_task, NULL); 606 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
607 &shutdown_task, NULL);
615 return; 608 return;
616 } 609 }
617 if (GNUNET_YES == rh->was_transmitted) 610 if (GNUNET_YES == rh->was_transmitted)
@@ -628,8 +621,7 @@ process_requests ()
628 "Transmitting DNS resolution request to DNS service\n"); 621 "Transmitting DNS resolution request to DNS service\n");
629#endif 622#endif
630 if (GNUNET_OK != 623 if (GNUNET_OK !=
631 GNUNET_CLIENT_transmit_and_get_response (client, 624 GNUNET_CLIENT_transmit_and_get_response (client, &msg->header,
632 &msg->header,
633 GNUNET_TIME_absolute_get_remaining 625 GNUNET_TIME_absolute_get_remaining
634 (rh->timeout), GNUNET_YES, 626 (rh->timeout), GNUNET_YES,
635 &handle_response, rh)) 627 &handle_response, rh))
@@ -726,8 +718,7 @@ reconnect ()
726 * @return handle that can be used to cancel the request, NULL on error 718 * @return handle that can be used to cancel the request, NULL on error
727 */ 719 */
728struct GNUNET_RESOLVER_RequestHandle * 720struct GNUNET_RESOLVER_RequestHandle *
729GNUNET_RESOLVER_ip_get (const char *hostname, 721GNUNET_RESOLVER_ip_get (const char *hostname, int domain,
730 int domain,
731 struct GNUNET_TIME_Relative timeout, 722 struct GNUNET_TIME_Relative timeout,
732 GNUNET_RESOLVER_AddressCallback callback, 723 GNUNET_RESOLVER_AddressCallback callback,
733 void *callback_cls) 724 void *callback_cls)
@@ -754,13 +745,9 @@ GNUNET_RESOLVER_ip_get (const char *hostname,
754 rh->timeout = GNUNET_TIME_relative_to_absolute (timeout); 745 rh->timeout = GNUNET_TIME_relative_to_absolute (timeout);
755 rh->direction = GNUNET_NO; 746 rh->direction = GNUNET_NO;
756 /* first, check if this is a numeric address */ 747 /* first, check if this is a numeric address */
757 if (((1 == inet_pton (AF_INET, 748 if (((1 == inet_pton (AF_INET, hostname, &v4)) &&
758 hostname,
759 &v4)) &&
760 ((domain == AF_INET) || (domain == AF_UNSPEC))) || 749 ((domain == AF_INET) || (domain == AF_UNSPEC))) ||
761 ((1 == inet_pton (AF_INET6, 750 ((1 == inet_pton (AF_INET6, hostname, &v6)) &&
762 hostname,
763 &v6)) &&
764 ((domain == AF_INET6) || (domain == AF_UNSPEC)))) 751 ((domain == AF_INET6) || (domain == AF_UNSPEC))))
765 { 752 {
766 rh->task = GNUNET_SCHEDULER_add_now (&numeric_resolution, rh); 753 rh->task = GNUNET_SCHEDULER_add_now (&numeric_resolution, rh);
@@ -826,8 +813,7 @@ numeric_reverse (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
826 * @return handle that can be used to cancel the request 813 * @return handle that can be used to cancel the request
827 */ 814 */
828struct GNUNET_RESOLVER_RequestHandle * 815struct GNUNET_RESOLVER_RequestHandle *
829GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa, 816GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa, socklen_t salen,
830 socklen_t salen,
831 int do_resolve, 817 int do_resolve,
832 struct GNUNET_TIME_Relative timeout, 818 struct GNUNET_TIME_Relative timeout,
833 GNUNET_RESOLVER_HostnameCallback callback, 819 GNUNET_RESOLVER_HostnameCallback callback,
@@ -881,19 +867,19 @@ GNUNET_RESOLVER_local_fqdn_get ()
881 867
882 if (0 != gethostname (hostname, sizeof (hostname) - 1)) 868 if (0 != gethostname (hostname, sizeof (hostname) - 1))
883 { 869 {
884 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | 870 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
885 GNUNET_ERROR_TYPE_BULK, "gethostname"); 871 "gethostname");
886 return NULL; 872 return NULL;
887 } 873 }
888#if DEBUG_RESOLVER 874#if DEBUG_RESOLVER
889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 875 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolving our FQDN `%s'\n"),
890 _("Resolving our FQDN `%s'\n"), hostname); 876 hostname);
891#endif 877#endif
892 host = gethostbyname (hostname); 878 host = gethostbyname (hostname);
893 if (NULL == host) 879 if (NULL == host)
894 { 880 {
895 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 881 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not resolve our FQDN : %s\n"),
896 _("Could not resolve our FQDN : %s\n"), hstrerror (h_errno)); 882 hstrerror (h_errno));
897 return NULL; 883 return NULL;
898 } 884 }
899 return GNUNET_strdup (host->h_name); 885 return GNUNET_strdup (host->h_name);
@@ -919,13 +905,13 @@ GNUNET_RESOLVER_hostname_resolve (int domain,
919 905
920 if (0 != gethostname (hostname, sizeof (hostname) - 1)) 906 if (0 != gethostname (hostname, sizeof (hostname) - 1))
921 { 907 {
922 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | 908 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
923 GNUNET_ERROR_TYPE_BULK, "gethostname"); 909 "gethostname");
924 return NULL; 910 return NULL;
925 } 911 }
926#if DEBUG_RESOLVER 912#if DEBUG_RESOLVER
927 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 913 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolving our hostname `%s'\n"),
928 _("Resolving our hostname `%s'\n"), hostname); 914 hostname);
929#endif 915#endif
930 return GNUNET_RESOLVER_ip_get (hostname, domain, timeout, callback, cls); 916 return GNUNET_RESOLVER_ip_get (hostname, domain, timeout, callback, cls);
931} 917}
diff --git a/src/util/scheduler.c b/src/util/scheduler.c
index 9412457f6..844531b37 100644
--- a/src/util/scheduler.c
+++ b/src/util/scheduler.c
@@ -349,8 +349,7 @@ is_pending (GNUNET_SCHEDULER_TaskIdentifier id)
349 * @param timeout next timeout (updated) 349 * @param timeout next timeout (updated)
350 */ 350 */
351static void 351static void
352update_sets (struct GNUNET_NETWORK_FDSet *rs, 352update_sets (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws,
353 struct GNUNET_NETWORK_FDSet *ws,
354 struct GNUNET_TIME_Relative *timeout) 353 struct GNUNET_TIME_Relative *timeout)
355{ 354{
356 struct Task *pos; 355 struct Task *pos;
@@ -434,8 +433,7 @@ set_overlaps (const struct GNUNET_NETWORK_FDSet *ready,
434 * @return GNUNET_YES if we can run it, GNUNET_NO if not. 433 * @return GNUNET_YES if we can run it, GNUNET_NO if not.
435 */ 434 */
436static int 435static int
437is_ready (struct Task *task, 436is_ready (struct Task *task, struct GNUNET_TIME_Absolute now,
438 struct GNUNET_TIME_Absolute now,
439 const struct GNUNET_NETWORK_FDSet *rs, 437 const struct GNUNET_NETWORK_FDSet *rs,
440 const struct GNUNET_NETWORK_FDSet *ws) 438 const struct GNUNET_NETWORK_FDSet *ws)
441{ 439{
@@ -525,8 +523,8 @@ check_ready (const struct GNUNET_NETWORK_FDSet *rs,
525 { 523 {
526#if DEBUG_TASKS 524#if DEBUG_TASKS
527 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 525 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
528 "Checking readiness of task: %llu / %p\n", 526 "Checking readiness of task: %llu / %p\n", pos->id,
529 pos->id, pos->callback_cls); 527 pos->callback_cls);
530#endif 528#endif
531 next = pos->next; 529 next = pos->next;
532 if (GNUNET_YES == is_ready (pos, now, rs, ws)) 530 if (GNUNET_YES == is_ready (pos, now, rs, ws))
@@ -657,11 +655,10 @@ run_ready (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws)
657 DELAY_THRESHOLD.rel_value) 655 DELAY_THRESHOLD.rel_value)
658 { 656 {
659 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 657 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
660 "Task %llu took %llums to be scheduled\n", 658 "Task %llu took %llums to be scheduled\n", pos->id,
661 pos->id, 659 (unsigned long long) GNUNET_TIME_absolute_get_duration (pos->
662 (unsigned long long) 660 start_time).
663 GNUNET_TIME_absolute_get_duration 661 rel_value);
664 (pos->start_time).rel_value);
665 } 662 }
666#endif 663#endif
667 tc.reason = pos->reason; 664 tc.reason = pos->reason;
@@ -678,17 +675,16 @@ run_ready (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws)
678 (!GNUNET_NETWORK_fdset_test_native (ws, pos->write_fd))) 675 (!GNUNET_NETWORK_fdset_test_native (ws, pos->write_fd)))
679 abort (); // added to ready in previous select loop! 676 abort (); // added to ready in previous select loop!
680#if DEBUG_TASKS 677#if DEBUG_TASKS
681 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 678 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running task: %llu / %p\n", pos->id,
682 "Running task: %llu / %p\n", pos->id, pos->callback_cls); 679 pos->callback_cls);
683#endif 680#endif
684 pos->callback (pos->callback_cls, &tc); 681 pos->callback (pos->callback_cls, &tc);
685#if EXECINFO 682#if EXECINFO
686 int i; 683 int i;
687 684
688 for (i = 0; i < pos->num_backtrace_strings; i++) 685 for (i = 0; i < pos->num_backtrace_strings; i++)
689 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 686 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Task %llu trace %d: %s\n", pos->id,
690 "Task %llu trace %d: %s\n", 687 i, pos->backtrace_strings[i]);
691 pos->id, i, pos->backtrace_strings[i]);
692#endif 688#endif
693 active_task = NULL; 689 active_task = NULL;
694 destroy_task (pos); 690 destroy_task (pos);
@@ -809,8 +805,8 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls)
809#endif 805#endif
810 current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT; 806 current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT;
811 current_lifeness = GNUNET_YES; 807 current_lifeness = GNUNET_YES;
812 GNUNET_SCHEDULER_add_continuation (task, 808 GNUNET_SCHEDULER_add_continuation (task, task_cls,
813 task_cls, GNUNET_SCHEDULER_REASON_STARTUP); 809 GNUNET_SCHEDULER_REASON_STARTUP);
814#if ENABLE_WINDOWS_WORKAROUNDS 810#if ENABLE_WINDOWS_WORKAROUNDS
815 active_task = (void *) (long) -1; /* force passing of sanity check */ 811 active_task = (void *) (long) -1; /* force passing of sanity check */
816 GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO, 812 GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO,
@@ -1031,8 +1027,8 @@ GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_TaskIdentifier task)
1031 } 1027 }
1032 ret = t->callback_cls; 1028 ret = t->callback_cls;
1033#if DEBUG_TASKS 1029#if DEBUG_TASKS
1034 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1030 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Canceling task: %llu / %p\n", task,
1035 "Canceling task: %llu / %p\n", task, t->callback_cls); 1031 t->callback_cls);
1036#endif 1032#endif
1037 destroy_task (t); 1033 destroy_task (t);
1038 return ret; 1034 return ret;
@@ -1049,8 +1045,7 @@ GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_TaskIdentifier task)
1049 * @param reason reason for task invocation 1045 * @param reason reason for task invocation
1050 */ 1046 */
1051void 1047void
1052GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, 1048GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls,
1053 void *task_cls,
1054 enum GNUNET_SCHEDULER_Reason reason) 1049 enum GNUNET_SCHEDULER_Reason reason)
1055{ 1050{
1056 struct Task *t; 1051 struct Task *t;
@@ -1080,8 +1075,8 @@ GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task,
1080 t->priority = current_priority; 1075 t->priority = current_priority;
1081 t->lifeness = current_lifeness; 1076 t->lifeness = current_lifeness;
1082#if DEBUG_TASKS 1077#if DEBUG_TASKS
1083 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1078 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding continuation task: %llu / %p\n",
1084 "Adding continuation task: %llu / %p\n", t->id, t->callback_cls); 1079 t->id, t->callback_cls);
1085#endif 1080#endif
1086 queue_ready_task (t); 1081 queue_ready_task (t);
1087} 1082}
@@ -1109,8 +1104,7 @@ GNUNET_SCHEDULER_add_after (GNUNET_SCHEDULER_TaskIdentifier prerequisite_task,
1109 GNUNET_SCHEDULER_Task task, void *task_cls) 1104 GNUNET_SCHEDULER_Task task, void *task_cls)
1110{ 1105{
1111 return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, 1106 return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP,
1112 prerequisite_task, 1107 prerequisite_task, GNUNET_TIME_UNIT_ZERO,
1113 GNUNET_TIME_UNIT_ZERO,
1114 NULL, NULL, task, task_cls); 1108 NULL, NULL, task, task_cls);
1115} 1109}
1116 1110
@@ -1128,10 +1122,9 @@ GNUNET_SCHEDULER_TaskIdentifier
1128GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio, 1122GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio,
1129 GNUNET_SCHEDULER_Task task, void *task_cls) 1123 GNUNET_SCHEDULER_Task task, void *task_cls)
1130{ 1124{
1131 return GNUNET_SCHEDULER_add_select (prio, 1125 return GNUNET_SCHEDULER_add_select (prio, GNUNET_SCHEDULER_NO_TASK,
1132 GNUNET_SCHEDULER_NO_TASK, 1126 GNUNET_TIME_UNIT_ZERO, NULL, NULL, task,
1133 GNUNET_TIME_UNIT_ZERO, 1127 task_cls);
1134 NULL, NULL, task, task_cls);
1135} 1128}
1136 1129
1137 1130
@@ -1212,23 +1205,23 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
1212 pending_timeout_last = t; 1205 pending_timeout_last = t;
1213 1206
1214#if DEBUG_TASKS 1207#if DEBUG_TASKS
1215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding task: %llu / %p\n", t->id,
1216 "Adding task: %llu / %p\n", t->id, t->callback_cls); 1209 t->callback_cls);
1217#endif 1210#endif
1218#if EXECINFO 1211#if EXECINFO
1219 int i; 1212 int i;
1220 1213
1221 for (i = 0; i < t->num_backtrace_strings; i++) 1214 for (i = 0; i < t->num_backtrace_strings; i++)
1222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Task %llu trace %d: %s\n", t->id, i,
1223 "Task %llu trace %d: %s\n", t->id, i, t->backtrace_strings[i]); 1216 t->backtrace_strings[i]);
1224#endif 1217#endif
1225 return t->id; 1218 return t->id;
1226 1219
1227#else 1220#else
1228 /* unoptimized version */ 1221 /* unoptimized version */
1229 return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, 1222 return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP,
1230 GNUNET_SCHEDULER_NO_TASK, delay, 1223 GNUNET_SCHEDULER_NO_TASK, delay, NULL,
1231 NULL, NULL, task, task_cls); 1224 NULL, task, task_cls);
1232#endif 1225#endif
1233} 1226}
1234 1227
@@ -1248,8 +1241,8 @@ GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_Task task, void *task_cls)
1248{ 1241{
1249 return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, 1242 return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP,
1250 GNUNET_SCHEDULER_NO_TASK, 1243 GNUNET_SCHEDULER_NO_TASK,
1251 GNUNET_TIME_UNIT_ZERO, 1244 GNUNET_TIME_UNIT_ZERO, NULL, NULL, task,
1252 NULL, NULL, task, task_cls); 1245 task_cls);
1253} 1246}
1254 1247
1255 1248
@@ -1274,10 +1267,11 @@ GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness,
1274{ 1267{
1275 GNUNET_SCHEDULER_TaskIdentifier ret; 1268 GNUNET_SCHEDULER_TaskIdentifier ret;
1276 1269
1277 ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, 1270 ret =
1278 GNUNET_SCHEDULER_NO_TASK, 1271 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP,
1279 GNUNET_TIME_UNIT_ZERO, 1272 GNUNET_SCHEDULER_NO_TASK,
1280 NULL, NULL, task, task_cls); 1273 GNUNET_TIME_UNIT_ZERO, NULL, NULL, task,
1274 task_cls);
1281 GNUNET_assert (pending->id == ret); 1275 GNUNET_assert (pending->id == ret);
1282 pending->lifeness = lifeness; 1276 pending->lifeness = lifeness;
1283 return ret; 1277 return ret;
@@ -1314,8 +1308,8 @@ GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness,
1314 */ 1308 */
1315#ifndef MINGW 1309#ifndef MINGW
1316GNUNET_SCHEDULER_TaskIdentifier 1310GNUNET_SCHEDULER_TaskIdentifier
1317add_without_sets (struct GNUNET_TIME_Relative delay, 1311add_without_sets (struct GNUNET_TIME_Relative delay, int rfd, int wfd,
1318 int rfd, int wfd, GNUNET_SCHEDULER_Task task, void *task_cls) 1312 GNUNET_SCHEDULER_Task task, void *task_cls)
1319{ 1313{
1320 struct Task *t; 1314 struct Task *t;
1321 1315
@@ -1346,8 +1340,8 @@ add_without_sets (struct GNUNET_TIME_Relative delay,
1346 int i; 1340 int i;
1347 1341
1348 for (i = 0; i < t->num_backtrace_strings; i++) 1342 for (i = 0; i < t->num_backtrace_strings; i++)
1349 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1343 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trace: %s\n",
1350 "Trace: %s\n", t->backtrace_strings[i]); 1344 t->backtrace_strings[i]);
1351#endif 1345#endif
1352 GNUNET_assert (0); 1346 GNUNET_assert (0);
1353 } 1347 }
@@ -1364,8 +1358,8 @@ add_without_sets (struct GNUNET_TIME_Relative delay,
1364 int i; 1358 int i;
1365 1359
1366 for (i = 0; i < t->num_backtrace_strings; i++) 1360 for (i = 0; i < t->num_backtrace_strings; i++)
1367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trace: %s\n",
1368 "Trace: %s\n", t->backtrace_strings[i]); 1362 t->backtrace_strings[i]);
1369#endif 1363#endif
1370 GNUNET_assert (0); 1364 GNUNET_assert (0);
1371 } 1365 }
@@ -1386,15 +1380,15 @@ add_without_sets (struct GNUNET_TIME_Relative delay,
1386 pending = t; 1380 pending = t;
1387 max_priority_added = GNUNET_MAX (max_priority_added, t->priority); 1381 max_priority_added = GNUNET_MAX (max_priority_added, t->priority);
1388#if DEBUG_TASKS 1382#if DEBUG_TASKS
1389 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1383 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding task: %llu / %p\n", t->id,
1390 "Adding task: %llu / %p\n", t->id, t->callback_cls); 1384 t->callback_cls);
1391#endif 1385#endif
1392#if EXECINFO 1386#if EXECINFO
1393 int i; 1387 int i;
1394 1388
1395 for (i = 0; i < t->num_backtrace_strings; i++) 1389 for (i = 0; i < t->num_backtrace_strings; i++)
1396 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1390 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Task %llu trace %d: %s\n", t->id, i,
1397 "Task %llu trace %d: %s\n", t->id, i, t->backtrace_strings[i]); 1391 t->backtrace_strings[i]);
1398#endif 1392#endif
1399 return t->id; 1393 return t->id;
1400} 1394}
@@ -1430,14 +1424,15 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay,
1430 GNUNET_assert (rfd != NULL); 1424 GNUNET_assert (rfd != NULL);
1431 rs = GNUNET_NETWORK_fdset_create (); 1425 rs = GNUNET_NETWORK_fdset_create ();
1432 GNUNET_NETWORK_fdset_set (rs, rfd); 1426 GNUNET_NETWORK_fdset_set (rs, rfd);
1433 ret = GNUNET_SCHEDULER_add_select (check_priority (current_priority), 1427 ret =
1434 GNUNET_SCHEDULER_NO_TASK, delay, 1428 GNUNET_SCHEDULER_add_select (check_priority (current_priority),
1435 rs, NULL, task, task_cls); 1429 GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL,
1430 task, task_cls);
1436 GNUNET_NETWORK_fdset_destroy (rs); 1431 GNUNET_NETWORK_fdset_destroy (rs);
1437 return ret; 1432 return ret;
1438#else 1433#else
1439 return add_without_sets (delay, 1434 return add_without_sets (delay, GNUNET_NETWORK_get_fd (rfd), -1, task,
1440 GNUNET_NETWORK_get_fd (rfd), -1, task, task_cls); 1435 task_cls);
1441#endif 1436#endif
1442} 1437}
1443 1438
@@ -1470,15 +1465,16 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay,
1470 GNUNET_assert (wfd != NULL); 1465 GNUNET_assert (wfd != NULL);
1471 ws = GNUNET_NETWORK_fdset_create (); 1466 ws = GNUNET_NETWORK_fdset_create ();
1472 GNUNET_NETWORK_fdset_set (ws, wfd); 1467 GNUNET_NETWORK_fdset_set (ws, wfd);
1473 ret = GNUNET_SCHEDULER_add_select (check_priority (current_priority), 1468 ret =
1474 GNUNET_SCHEDULER_NO_TASK, delay, 1469 GNUNET_SCHEDULER_add_select (check_priority (current_priority),
1475 NULL, ws, task, task_cls); 1470 GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws,
1471 task, task_cls);
1476 GNUNET_NETWORK_fdset_destroy (ws); 1472 GNUNET_NETWORK_fdset_destroy (ws);
1477 return ret; 1473 return ret;
1478#else 1474#else
1479 GNUNET_assert (GNUNET_NETWORK_get_fd (wfd) >= 0); 1475 GNUNET_assert (GNUNET_NETWORK_get_fd (wfd) >= 0);
1480 return add_without_sets (delay, 1476 return add_without_sets (delay, -1, GNUNET_NETWORK_get_fd (wfd), task,
1481 -1, GNUNET_NETWORK_get_fd (wfd), task, task_cls); 1477 task_cls);
1482#endif 1478#endif
1483} 1479}
1484 1480
@@ -1511,9 +1507,10 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay,
1511 GNUNET_assert (rfd != NULL); 1507 GNUNET_assert (rfd != NULL);
1512 rs = GNUNET_NETWORK_fdset_create (); 1508 rs = GNUNET_NETWORK_fdset_create ();
1513 GNUNET_NETWORK_fdset_handle_set (rs, rfd); 1509 GNUNET_NETWORK_fdset_handle_set (rs, rfd);
1514 ret = GNUNET_SCHEDULER_add_select (check_priority (current_priority), 1510 ret =
1515 GNUNET_SCHEDULER_NO_TASK, delay, 1511 GNUNET_SCHEDULER_add_select (check_priority (current_priority),
1516 rs, NULL, task, task_cls); 1512 GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL,
1513 task, task_cls);
1517 GNUNET_NETWORK_fdset_destroy (rs); 1514 GNUNET_NETWORK_fdset_destroy (rs);
1518 return ret; 1515 return ret;
1519#else 1516#else
@@ -1554,9 +1551,10 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay,
1554 GNUNET_assert (wfd != NULL); 1551 GNUNET_assert (wfd != NULL);
1555 ws = GNUNET_NETWORK_fdset_create (); 1552 ws = GNUNET_NETWORK_fdset_create ();
1556 GNUNET_NETWORK_fdset_handle_set (ws, wfd); 1553 GNUNET_NETWORK_fdset_handle_set (ws, wfd);
1557 ret = GNUNET_SCHEDULER_add_select (check_priority (current_priority), 1554 ret =
1558 GNUNET_SCHEDULER_NO_TASK, 1555 GNUNET_SCHEDULER_add_select (check_priority (current_priority),
1559 delay, NULL, ws, task, task_cls); 1556 GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws,
1557 task, task_cls);
1560 GNUNET_NETWORK_fdset_destroy (ws); 1558 GNUNET_NETWORK_fdset_destroy (ws);
1561 return ret; 1559 return ret;
1562#else 1560#else
@@ -1605,8 +1603,7 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay,
1605 */ 1603 */
1606GNUNET_SCHEDULER_TaskIdentifier 1604GNUNET_SCHEDULER_TaskIdentifier
1607GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, 1605GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio,
1608 GNUNET_SCHEDULER_TaskIdentifier 1606 GNUNET_SCHEDULER_TaskIdentifier prerequisite_task,
1609 prerequisite_task,
1610 struct GNUNET_TIME_Relative delay, 1607 struct GNUNET_TIME_Relative delay,
1611 const struct GNUNET_NETWORK_FDSet *rs, 1608 const struct GNUNET_NETWORK_FDSet *rs,
1612 const struct GNUNET_NETWORK_FDSet *ws, 1609 const struct GNUNET_NETWORK_FDSet *ws,
@@ -1648,22 +1645,22 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio,
1648 t->timeout = GNUNET_TIME_relative_to_absolute (delay); 1645 t->timeout = GNUNET_TIME_relative_to_absolute (delay);
1649 t->priority = 1646 t->priority =
1650 check_priority ((prio == 1647 check_priority ((prio ==
1651 GNUNET_SCHEDULER_PRIORITY_KEEP) ? current_priority 1648 GNUNET_SCHEDULER_PRIORITY_KEEP) ? current_priority :
1652 : prio); 1649 prio);
1653 t->lifeness = current_lifeness; 1650 t->lifeness = current_lifeness;
1654 t->next = pending; 1651 t->next = pending;
1655 pending = t; 1652 pending = t;
1656 max_priority_added = GNUNET_MAX (max_priority_added, t->priority); 1653 max_priority_added = GNUNET_MAX (max_priority_added, t->priority);
1657#if DEBUG_TASKS 1654#if DEBUG_TASKS
1658 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1655 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding task: %llu / %p\n", t->id,
1659 "Adding task: %llu / %p\n", t->id, t->callback_cls); 1656 t->callback_cls);
1660#endif 1657#endif
1661#if EXECINFO 1658#if EXECINFO
1662 int i; 1659 int i;
1663 1660
1664 for (i = 0; i < t->num_backtrace_strings; i++) 1661 for (i = 0; i < t->num_backtrace_strings; i++)
1665 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1662 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Task %llu trace %d: %s\n", t->id, i,
1666 "Task %llu trace %d: %s\n", t->id, i, t->backtrace_strings[i]); 1663 t->backtrace_strings[i]);
1667#endif 1664#endif
1668 return t->id; 1665 return t->id;
1669} 1666}
diff --git a/src/util/server.c b/src/util/server.c
index 935cf04f8..504391bc7 100644
--- a/src/util/server.c
+++ b/src/util/server.c
@@ -381,9 +381,7 @@ open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen)
381 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); 381 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
382 if (port != 0) 382 if (port != 0)
383 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 383 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
384 _ 384 _("`%s' failed for port %d (%s).\n"), "bind", port,
385 ("`%s' failed for port %d (%s).\n"),
386 "bind", port,
387 (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6"); 385 (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6");
388 eno = 0; 386 eno = 0;
389 } 387 }
@@ -391,15 +389,12 @@ open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen)
391 { 389 {
392 if (port != 0) 390 if (port != 0)
393 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 391 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
394 _ 392 _("`%s' failed for port %d (%s): address already in use\n"),
395 ("`%s' failed for port %d (%s): address already in use\n"),
396 "bind", port, 393 "bind", port,
397 (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6"); 394 (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6");
398 else if (serverAddr->sa_family == AF_UNIX) 395 else if (serverAddr->sa_family == AF_UNIX)
399 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 396 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
400 _ 397 _("`%s' failed for `%s': address already in use\n"), "bind",
401 ("`%s' failed for `%s': address already in use\n"),
402 "bind",
403 ((const struct sockaddr_un *) serverAddr)->sun_path); 398 ((const struct sockaddr_un *) serverAddr)->sun_path);
404 399
405 } 400 }
@@ -483,12 +478,11 @@ GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access,
483 * (typically, "port" already in use) 478 * (typically, "port" already in use)
484 */ 479 */
485struct GNUNET_SERVER_Handle * 480struct GNUNET_SERVER_Handle *
486GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access, 481GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access, void *access_cls,
487 void *access_cls,
488 struct sockaddr *const *serverAddr, 482 struct sockaddr *const *serverAddr,
489 const socklen_t * socklen, 483 const socklen_t * socklen,
490 struct GNUNET_TIME_Relative 484 struct GNUNET_TIME_Relative idle_timeout,
491 idle_timeout, int require_found) 485 int require_found)
492{ 486{
493 struct GNUNET_NETWORK_Handle **lsocks; 487 struct GNUNET_NETWORK_Handle **lsocks;
494 unsigned int i; 488 unsigned int i;
@@ -521,8 +515,7 @@ GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access,
521 { 515 {
522 lsocks = NULL; 516 lsocks = NULL;
523 } 517 }
524 return GNUNET_SERVER_create_with_sockets (access, access_cls, 518 return GNUNET_SERVER_create_with_sockets (access, access_cls, lsocks,
525 lsocks,
526 idle_timeout, require_found); 519 idle_timeout, require_found);
527} 520}
528 521
@@ -610,17 +603,17 @@ warn_no_receive_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
610{ 603{
611 struct GNUNET_SERVER_Client *client = cls; 604 struct GNUNET_SERVER_Client *client = cls;
612 605
613 client->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 606 client->warn_task =
614 &warn_no_receive_done, 607 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
615 client); 608 &warn_no_receive_done, client);
616 if (0 == (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) 609 if (0 == (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
617 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 610 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
618 _ 611 _
619 ("Processing code for message of type %u did not call GNUNET_SERVER_receive_done after %llums\n"), 612 ("Processing code for message of type %u did not call GNUNET_SERVER_receive_done after %llums\n"),
620 (unsigned int) client->warn_type, 613 (unsigned int) client->warn_type,
621 (unsigned long long) 614 (unsigned long long) GNUNET_TIME_absolute_get_duration (client->
622 GNUNET_TIME_absolute_get_duration 615 warn_start).
623 (client->warn_start).rel_value); 616 rel_value);
624} 617}
625 618
626 619
@@ -737,11 +730,9 @@ GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server,
737 * @param addrlen length of addr 730 * @param addrlen length of addr
738 * @param errCode code indicating errors receiving, 0 for success 731 * @param errCode code indicating errors receiving, 0 for success
739 */ 732 */
740static void 733static void process_incoming (void *cls, const void *buf, size_t available,
741process_incoming (void *cls, 734 const struct sockaddr *addr, socklen_t addrlen,
742 const void *buf, 735 int errCode);
743 size_t available,
744 const struct sockaddr *addr, socklen_t addrlen, int errCode);
745 736
746 737
747/** 738/**
@@ -760,8 +751,7 @@ process_incoming (void *cls,
760static void 751static void
761process_mst (struct GNUNET_SERVER_Client *client, int ret) 752process_mst (struct GNUNET_SERVER_Client *client, int ret)
762{ 753{
763 while ((ret != GNUNET_SYSERR) && 754 while ((ret != GNUNET_SYSERR) && (client->server != NULL) &&
764 (client->server != NULL) &&
765 (GNUNET_YES != client->shutdown_now) && (0 == client->suspended)) 755 (GNUNET_YES != client->shutdown_now) && (0 == client->suspended))
766 { 756 {
767 if (ret == GNUNET_OK) 757 if (ret == GNUNET_OK)
@@ -774,8 +764,8 @@ process_mst (struct GNUNET_SERVER_Client *client, int ret)
774#endif 764#endif
775 GNUNET_CONNECTION_receive (client->connection, 765 GNUNET_CONNECTION_receive (client->connection,
776 GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, 766 GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
777 client->idle_timeout, 767 client->idle_timeout, &process_incoming,
778 &process_incoming, client); 768 client);
779 break; 769 break;
780 } 770 }
781#if DEBUG_SERVER 771#if DEBUG_SERVER
@@ -817,9 +807,7 @@ process_mst (struct GNUNET_SERVER_Client *client, int ret)
817 * @param errCode code indicating errors receiving, 0 for success 807 * @param errCode code indicating errors receiving, 0 for success
818 */ 808 */
819static void 809static void
820process_incoming (void *cls, 810process_incoming (void *cls, const void *buf, size_t available,
821 const void *buf,
822 size_t available,
823 const struct sockaddr *addr, socklen_t addrlen, int errCode) 811 const struct sockaddr *addr, socklen_t addrlen, int errCode)
824{ 812{
825 struct GNUNET_SERVER_Client *client = cls; 813 struct GNUNET_SERVER_Client *client = cls;
@@ -834,8 +822,7 @@ process_incoming (void *cls,
834 end = GNUNET_TIME_absolute_add (client->last_activity, client->idle_timeout); 822 end = GNUNET_TIME_absolute_add (client->last_activity, client->idle_timeout);
835 823
836 if ((buf == NULL) && (available == 0) && (addr == NULL) && (errCode == 0) && 824 if ((buf == NULL) && (available == 0) && (addr == NULL) && (errCode == 0) &&
837 (client->shutdown_now != GNUNET_YES) && 825 (client->shutdown_now != GNUNET_YES) && (server != NULL) &&
838 (server != NULL) &&
839 (GNUNET_YES == GNUNET_CONNECTION_check (client->connection)) && 826 (GNUNET_YES == GNUNET_CONNECTION_check (client->connection)) &&
840 (end.abs_value > now.abs_value)) 827 (end.abs_value > now.abs_value))
841 { 828 {
@@ -852,10 +839,7 @@ process_incoming (void *cls,
852 &process_incoming, client); 839 &process_incoming, client);
853 return; 840 return;
854 } 841 }
855 if ((buf == NULL) || 842 if ((buf == NULL) || (available == 0) || (errCode != 0) || (server == NULL) ||
856 (available == 0) ||
857 (errCode != 0) ||
858 (server == NULL) ||
859 (client->shutdown_now == GNUNET_YES) || 843 (client->shutdown_now == GNUNET_YES) ||
860 (GNUNET_YES != GNUNET_CONNECTION_check (client->connection))) 844 (GNUNET_YES != GNUNET_CONNECTION_check (client->connection)))
861 { 845 {
@@ -864,8 +848,7 @@ process_incoming (void *cls,
864 return; 848 return;
865 } 849 }
866#if DEBUG_SERVER 850#if DEBUG_SERVER
867 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 851 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server receives %u bytes from `%s'.\n",
868 "Server receives %u bytes from `%s'.\n",
869 (unsigned int) available, GNUNET_a2s (addr, addrlen)); 852 (unsigned int) available, GNUNET_a2s (addr, addrlen));
870#endif 853#endif
871 GNUNET_SERVER_client_keep (client); 854 GNUNET_SERVER_client_keep (client);
@@ -928,8 +911,7 @@ restart_processing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
928 * @param message the actual message 911 * @param message the actual message
929 */ 912 */
930static void 913static void
931client_message_tokenizer_callback (void *cls, 914client_message_tokenizer_callback (void *cls, void *client,
932 void *client,
933 const struct GNUNET_MessageHeader *message) 915 const struct GNUNET_MessageHeader *message)
934{ 916{
935 struct GNUNET_SERVER_Handle *server = cls; 917 struct GNUNET_SERVER_Handle *server = cls;
@@ -963,17 +945,15 @@ client_message_tokenizer_callback (void *cls,
963 * "client_drop" on the return value eventually) 945 * "client_drop" on the return value eventually)
964 */ 946 */
965struct GNUNET_SERVER_Client * 947struct GNUNET_SERVER_Client *
966GNUNET_SERVER_connect_socket (struct 948GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server,
967 GNUNET_SERVER_Handle
968 *server,
969 struct GNUNET_CONNECTION_Handle *connection) 949 struct GNUNET_CONNECTION_Handle *connection)
970{ 950{
971 struct GNUNET_SERVER_Client *client; 951 struct GNUNET_SERVER_Client *client;
972 952
973 client = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Client)); 953 client = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Client));
974 client->connection = connection; 954 client->connection = connection;
975 client->mst = GNUNET_SERVER_mst_create (&client_message_tokenizer_callback, 955 client->mst =
976 server); 956 GNUNET_SERVER_mst_create (&client_message_tokenizer_callback, server);
977 client->reference_count = 1; 957 client->reference_count = 1;
978 client->server = server; 958 client->server = server;
979 client->last_activity = GNUNET_TIME_absolute_get (); 959 client->last_activity = GNUNET_TIME_absolute_get ();
@@ -1274,8 +1254,7 @@ GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client,
1274{ 1254{
1275 client->callback_cls = callback_cls; 1255 client->callback_cls = callback_cls;
1276 client->callback = callback; 1256 client->callback = callback;
1277 return GNUNET_CONNECTION_notify_transmit_ready (client->connection, 1257 return GNUNET_CONNECTION_notify_transmit_ready (client->connection, size,
1278 size,
1279 timeout, 1258 timeout,
1280 &transmit_ready_callback_wrapper, 1259 &transmit_ready_callback_wrapper,
1281 client); 1260 client);
diff --git a/src/util/server_mst.c b/src/util/server_mst.c
index f48ef5475..07a7b30b8 100644
--- a/src/util/server_mst.c
+++ b/src/util/server_mst.c
@@ -119,9 +119,8 @@ GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb,
119 */ 119 */
120int 120int
121GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst, 121GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
122 void *client_identity, 122 void *client_identity, const char *buf, size_t size,
123 const char *buf, 123 int purge, int one_shot)
124 size_t size, int purge, int one_shot)
125{ 124{
126 const struct GNUNET_MessageHeader *hdr; 125 const struct GNUNET_MessageHeader *hdr;
127 size_t delta; 126 size_t delta;
diff --git a/src/util/server_nc.c b/src/util/server_nc.c
index f8e300029..a1cb43f00 100644
--- a/src/util/server_nc.c
+++ b/src/util/server_nc.c
@@ -323,10 +323,10 @@ transmit_message (void *cls, size_t size, void *buf)
323 "Have %u messages left in NC queue, will try transmission again\n", 323 "Have %u messages left in NC queue, will try transmission again\n",
324 cl->num_pending); 324 cl->num_pending);
325#endif 325#endif
326 cl->th = GNUNET_SERVER_notify_transmit_ready (cl->client, 326 cl->th =
327 ntohs (pml->msg->size), 327 GNUNET_SERVER_notify_transmit_ready (cl->client, ntohs (pml->msg->size),
328 GNUNET_TIME_UNIT_FOREVER_REL, 328 GNUNET_TIME_UNIT_FOREVER_REL,
329 &transmit_message, cl); 329 &transmit_message, cl);
330 } 330 }
331 else 331 else
332 GNUNET_assert (cl->num_pending == 0); 332 GNUNET_assert (cl->num_pending == 0);
@@ -344,8 +344,8 @@ transmit_message (void *cls, size_t size, void *buf)
344 */ 344 */
345static void 345static void
346do_unicast (struct GNUNET_SERVER_NotificationContext *nc, 346do_unicast (struct GNUNET_SERVER_NotificationContext *nc,
347 struct ClientList *client, 347 struct ClientList *client, const struct GNUNET_MessageHeader *msg,
348 const struct GNUNET_MessageHeader *msg, int can_drop) 348 int can_drop)
349{ 349{
350 struct PendingMessageList *pml; 350 struct PendingMessageList *pml;
351 uint16_t size; 351 uint16_t size;
@@ -354,8 +354,8 @@ do_unicast (struct GNUNET_SERVER_NotificationContext *nc,
354 { 354 {
355 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 355 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
356 "Dropping message of type %u and size %u due to full queue (%u entries)\n", 356 "Dropping message of type %u and size %u due to full queue (%u entries)\n",
357 ntohs (msg->type), 357 ntohs (msg->type), ntohs (msg->size),
358 ntohs (msg->size), (unsigned int) nc->queue_length); 358 (unsigned int) nc->queue_length);
359 return; /* drop! */ 359 return; /* drop! */
360 } 360 }
361 if (client->num_pending > nc->queue_length) 361 if (client->num_pending > nc->queue_length)
@@ -371,21 +371,20 @@ do_unicast (struct GNUNET_SERVER_NotificationContext *nc,
371#if DEBUG_SERVER_NC 371#if DEBUG_SERVER_NC
372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
373 "Adding message of type %u and size %u to pending queue (which has %u entries)\n", 373 "Adding message of type %u and size %u to pending queue (which has %u entries)\n",
374 ntohs (msg->type), 374 ntohs (msg->type), ntohs (msg->size),
375 ntohs (msg->size), (unsigned int) nc->queue_length); 375 (unsigned int) nc->queue_length);
376#endif 376#endif
377 memcpy (&pml[1], msg, size); 377 memcpy (&pml[1], msg, size);
378 /* append */ 378 /* append */
379 GNUNET_CONTAINER_DLL_insert_tail (client->pending_head, 379 GNUNET_CONTAINER_DLL_insert_tail (client->pending_head, client->pending_tail,
380 client->pending_tail, pml); 380 pml);
381 if (client->th == NULL) 381 if (client->th == NULL)
382 client->th = GNUNET_SERVER_notify_transmit_ready (client->client, 382 client->th =
383 ntohs 383 GNUNET_SERVER_notify_transmit_ready (client->client,
384 (client->pending_head-> 384 ntohs (client->pending_head->msg->
385 msg->size), 385 size),
386 GNUNET_TIME_UNIT_FOREVER_REL, 386 GNUNET_TIME_UNIT_FOREVER_REL,
387 &transmit_message, 387 &transmit_message, client);
388 client);
389} 388}
390 389
391 390
diff --git a/src/util/server_tc.c b/src/util/server_tc.c
index eda82e50f..127131032 100644
--- a/src/util/server_tc.c
+++ b/src/util/server_tc.c
@@ -103,13 +103,13 @@ transmit_response (void *cls, size_t size, void *buf)
103 } 103 }
104 else 104 else
105 { 105 {
106 if (NULL == GNUNET_SERVER_notify_transmit_ready (tc->client, 106 if (NULL ==
107 GNUNET_MIN 107 GNUNET_SERVER_notify_transmit_ready (tc->client,
108 (MIN_BLOCK_SIZE, 108 GNUNET_MIN (MIN_BLOCK_SIZE,
109 tc->total - tc->off), 109 tc->total - tc->off),
110 GNUNET_TIME_absolute_get_remaining 110 GNUNET_TIME_absolute_get_remaining
111 (tc->timeout), 111 (tc->timeout), &transmit_response,
112 &transmit_response, tc)) 112 tc))
113 { 113 {
114 GNUNET_break (0); 114 GNUNET_break (0);
115 GNUNET_SERVER_receive_done (tc->client, GNUNET_SYSERR); 115 GNUNET_SERVER_receive_done (tc->client, GNUNET_SYSERR);
diff --git a/src/util/service.c b/src/util/service.c
index 308267bd6..9b60dc56b 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -99,12 +99,10 @@ parse_ipv4_specification (const char *routeList)
99 pos = 0; 99 pos = 0;
100 while (i < count) 100 while (i < count)
101 { 101 {
102 cnt = sscanf (&routeList[pos], 102 cnt =
103 "%u.%u.%u.%u/%u.%u.%u.%u;", 103 sscanf (&routeList[pos], "%u.%u.%u.%u/%u.%u.%u.%u;", &temps[0],
104 &temps[0], 104 &temps[1], &temps[2], &temps[3], &temps[4], &temps[5],
105 &temps[1], 105 &temps[6], &temps[7]);
106 &temps[2],
107 &temps[3], &temps[4], &temps[5], &temps[6], &temps[7]);
108 if (cnt == 8) 106 if (cnt == 8)
109 { 107 {
110 for (j = 0; j < 8; j++) 108 for (j = 0; j < 8; j++)
@@ -115,8 +113,7 @@ parse_ipv4_specification (const char *routeList)
115 GNUNET_free (result); 113 GNUNET_free (result);
116 return NULL; 114 return NULL;
117 } 115 }
118 result[i].network.s_addr 116 result[i].network.s_addr =
119 =
120 htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + 117 htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) +
121 temps[3]); 118 temps[3]);
122 result[i].netmask.s_addr = 119 result[i].netmask.s_addr =
@@ -129,9 +126,9 @@ parse_ipv4_specification (const char *routeList)
129 continue; 126 continue;
130 } 127 }
131 /* try second notation */ 128 /* try second notation */
132 cnt = sscanf (&routeList[pos], 129 cnt =
133 "%u.%u.%u.%u/%u;", 130 sscanf (&routeList[pos], "%u.%u.%u.%u/%u;", &temps[0], &temps[1],
134 &temps[0], &temps[1], &temps[2], &temps[3], &slash); 131 &temps[2], &temps[3], &slash);
135 if (cnt == 5) 132 if (cnt == 5)
136 { 133 {
137 for (j = 0; j < 4; j++) 134 for (j = 0; j < 4; j++)
@@ -142,8 +139,7 @@ parse_ipv4_specification (const char *routeList)
142 GNUNET_free (result); 139 GNUNET_free (result);
143 return NULL; 140 return NULL;
144 } 141 }
145 result[i].network.s_addr 142 result[i].network.s_addr =
146 =
147 htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + 143 htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) +
148 temps[3]); 144 temps[3]);
149 if ((slash <= 32) && (slash >= 0)) 145 if ((slash <= 32) && (slash >= 0))
@@ -151,8 +147,8 @@ parse_ipv4_specification (const char *routeList)
151 result[i].netmask.s_addr = 0; 147 result[i].netmask.s_addr = 0;
152 while (slash > 0) 148 while (slash > 0)
153 { 149 {
154 result[i].netmask.s_addr 150 result[i].netmask.s_addr =
155 = (result[i].netmask.s_addr >> 1) + 0x80000000; 151 (result[i].netmask.s_addr >> 1) + 0x80000000;
156 slash--; 152 slash--;
157 } 153 }
158 result[i].netmask.s_addr = htonl (result[i].netmask.s_addr); 154 result[i].netmask.s_addr = htonl (result[i].netmask.s_addr);
@@ -174,8 +170,9 @@ parse_ipv4_specification (const char *routeList)
174 } 170 }
175 /* try third notation */ 171 /* try third notation */
176 slash = 32; 172 slash = 32;
177 cnt = sscanf (&routeList[pos], 173 cnt =
178 "%u.%u.%u.%u;", &temps[0], &temps[1], &temps[2], &temps[3]); 174 sscanf (&routeList[pos], "%u.%u.%u.%u;", &temps[0], &temps[1],
175 &temps[2], &temps[3]);
179 if (cnt == 4) 176 if (cnt == 4)
180 { 177 {
181 for (j = 0; j < 4; j++) 178 for (j = 0; j < 4; j++)
@@ -186,8 +183,7 @@ parse_ipv4_specification (const char *routeList)
186 GNUNET_free (result); 183 GNUNET_free (result);
187 return NULL; 184 return NULL;
188 } 185 }
189 result[i].network.s_addr 186 result[i].network.s_addr =
190 =
191 htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + 187 htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) +
192 temps[3]); 188 temps[3]);
193 result[i].netmask.s_addr = 0; 189 result[i].netmask.s_addr = 0;
@@ -203,15 +199,15 @@ parse_ipv4_specification (const char *routeList)
203 i++; 199 i++;
204 continue; 200 continue;
205 } 201 }
206 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 202 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"),
207 _("Invalid format for IP: `%s'\n"), &routeList[pos]); 203 &routeList[pos]);
208 GNUNET_free (result); 204 GNUNET_free (result);
209 return NULL; /* error */ 205 return NULL; /* error */
210 } 206 }
211 if (pos < strlen (routeList)) 207 if (pos < strlen (routeList))
212 { 208 {
213 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 209 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"),
214 _("Invalid format for IP: `%s'\n"), &routeList[pos]); 210 &routeList[pos]);
215 GNUNET_free (result); 211 GNUNET_free (result);
216 return NULL; /* oops */ 212 return NULL; /* oops */
217 } 213 }
@@ -259,8 +255,7 @@ parse_ipv6_specification (const char *routeListX)
259 if (routeList[len - 1] != ';') 255 if (routeList[len - 1] != ';')
260 { 256 {
261 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 257 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
262 _ 258 _("Invalid network notation (does not end with ';': `%s')\n"),
263 ("Invalid network notation (does not end with ';': `%s')\n"),
264 routeList); 259 routeList);
265 GNUNET_free (routeList); 260 GNUNET_free (routeList);
266 return NULL; 261 return NULL;
@@ -313,8 +308,8 @@ parse_ipv6_specification (const char *routeListX)
313 } 308 }
314 while (bits > 0) 309 while (bits > 0)
315 { 310 {
316 result[i].netmask.s6_addr[off] 311 result[i].netmask.s6_addr[off] =
317 = (result[i].netmask.s6_addr[off] >> 1) + 0x80; 312 (result[i].netmask.s6_addr[off] >> 1) + 0x80;
318 bits--; 313 bits--;
319 } 314 }
320 } 315 }
@@ -550,16 +545,15 @@ write_test (void *cls, size_t size, void *buf)
550 * @param message the actual message 545 * @param message the actual message
551 */ 546 */
552static void 547static void
553handle_test (void *cls, 548handle_test (void *cls, struct GNUNET_SERVER_Client *client,
554 struct GNUNET_SERVER_Client *client,
555 const struct GNUNET_MessageHeader *message) 549 const struct GNUNET_MessageHeader *message)
556{ 550{
557 /* simply bounce message back to acknowledge */ 551 /* simply bounce message back to acknowledge */
558 if (NULL == GNUNET_SERVER_notify_transmit_ready (client, 552 if (NULL ==
559 sizeof (struct 553 GNUNET_SERVER_notify_transmit_ready (client,
560 GNUNET_MessageHeader), 554 sizeof (struct GNUNET_MessageHeader),
561 GNUNET_TIME_UNIT_FOREVER_REL, 555 GNUNET_TIME_UNIT_FOREVER_REL,
562 &write_test, client)) 556 &write_test, client))
563 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 557 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
564} 558}
565 559
@@ -591,8 +585,7 @@ static const struct GNUNET_SERVER_MessageHandler defhandlers[] = {
591 * for unknown address family (will be denied). 585 * for unknown address family (will be denied).
592 */ 586 */
593static int 587static int
594check_access (void *cls, 588check_access (void *cls, const struct GNUNET_CONNECTION_Credentials *uc,
595 const struct GNUNET_CONNECTION_Credentials *uc,
596 const struct sockaddr *addr, socklen_t addrlen) 589 const struct sockaddr *addr, socklen_t addrlen)
597{ 590{
598 struct GNUNET_SERVICE_Context *sctx = cls; 591 struct GNUNET_SERVICE_Context *sctx = cls;
@@ -606,19 +599,17 @@ check_access (void *cls,
606 GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); 599 GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
607 i4 = (const struct sockaddr_in *) addr; 600 i4 = (const struct sockaddr_in *) addr;
608 ret = ((sctx->v4_allowed == NULL) || 601 ret = ((sctx->v4_allowed == NULL) ||
609 (check_ipv4_listed (sctx->v4_allowed, 602 (check_ipv4_listed (sctx->v4_allowed, &i4->sin_addr))) &&
610 &i4->sin_addr))) 603 ((sctx->v4_denied == NULL) ||
611 && ((sctx->v4_denied == NULL) || 604 (!check_ipv4_listed (sctx->v4_denied, &i4->sin_addr)));
612 (!check_ipv4_listed (sctx->v4_denied, &i4->sin_addr)));
613 break; 605 break;
614 case AF_INET6: 606 case AF_INET6:
615 GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); 607 GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
616 i6 = (const struct sockaddr_in6 *) addr; 608 i6 = (const struct sockaddr_in6 *) addr;
617 ret = ((sctx->v6_allowed == NULL) || 609 ret = ((sctx->v6_allowed == NULL) ||
618 (check_ipv6_listed (sctx->v6_allowed, 610 (check_ipv6_listed (sctx->v6_allowed, &i6->sin6_addr))) &&
619 &i6->sin6_addr))) 611 ((sctx->v6_denied == NULL) ||
620 && ((sctx->v6_denied == NULL) || 612 (!check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr)));
621 (!check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr)));
622 break; 613 break;
623#ifndef WINDOWS 614#ifndef WINDOWS
624 case AF_UNIX: 615 case AF_UNIX:
@@ -626,11 +617,10 @@ check_access (void *cls,
626 if ((sctx->match_uid == GNUNET_YES) || (sctx->match_gid == GNUNET_YES)) 617 if ((sctx->match_uid == GNUNET_YES) || (sctx->match_gid == GNUNET_YES))
627 ret = GNUNET_NO; 618 ret = GNUNET_NO;
628 if ((uc != NULL) && 619 if ((uc != NULL) &&
629 ((sctx->match_uid != GNUNET_YES) || 620 ((sctx->match_uid != GNUNET_YES) || (uc->uid == geteuid ()) ||
630 (uc->uid == geteuid ()) || 621 (uc->uid == getuid ())) && ((sctx->match_gid != GNUNET_YES) ||
631 (uc->uid == getuid ())) && 622 (uc->gid == getegid ()) ||
632 ((sctx->match_gid != GNUNET_YES) || 623 (uc->gid == getgid ())))
633 (uc->gid == getegid ()) || (uc->gid == getgid ())))
634 ret = GNUNET_YES; 624 ret = GNUNET_YES;
635 else 625 else
636 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 626 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -639,8 +629,8 @@ check_access (void *cls,
639 break; 629 break;
640#endif 630#endif
641 default: 631 default:
642 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 632 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Unknown address family %d\n"),
643 _("Unknown address family %d\n"), addr->sa_family); 633 addr->sa_family);
644 return GNUNET_SYSERR; 634 return GNUNET_SYSERR;
645 } 635 }
646 if (ret != GNUNET_OK) 636 if (ret != GNUNET_OK)
@@ -664,8 +654,7 @@ get_pid_file_name (struct GNUNET_SERVICE_Context *sctx)
664 char *pif; 654 char *pif;
665 655
666 if (GNUNET_OK != 656 if (GNUNET_OK !=
667 GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, 657 GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, sctx->serviceName,
668 sctx->serviceName,
669 "PIDFILE", &pif)) 658 "PIDFILE", &pif))
670 return NULL; 659 return NULL;
671 return pif; 660 return pif;
@@ -676,8 +665,8 @@ get_pid_file_name (struct GNUNET_SERVICE_Context *sctx)
676 * Parse an IPv4 access control list. 665 * Parse an IPv4 access control list.
677 */ 666 */
678static int 667static int
679process_acl4 (struct IPv4NetworkSet **ret, 668process_acl4 (struct IPv4NetworkSet **ret, struct GNUNET_SERVICE_Context *sctx,
680 struct GNUNET_SERVICE_Context *sctx, const char *option) 669 const char *option)
681{ 670{
682 char *opt; 671 char *opt;
683 672
@@ -705,8 +694,8 @@ process_acl4 (struct IPv4NetworkSet **ret,
705 * Parse an IPv4 access control list. 694 * Parse an IPv4 access control list.
706 */ 695 */
707static int 696static int
708process_acl6 (struct IPv6NetworkSet **ret, 697process_acl6 (struct IPv6NetworkSet **ret, struct GNUNET_SERVICE_Context *sctx,
709 struct GNUNET_SERVICE_Context *sctx, const char *option) 698 const char *option)
710{ 699{
711 char *opt; 700 char *opt;
712 701
@@ -738,8 +727,8 @@ process_acl6 (struct IPv6NetworkSet **ret,
738 * @param unixpath path to add 727 * @param unixpath path to add
739 */ 728 */
740static void 729static void
741add_unixpath (struct sockaddr **saddrs, 730add_unixpath (struct sockaddr **saddrs, socklen_t * saddrlens,
742 socklen_t * saddrlens, const char *unixpath) 731 const char *unixpath)
743{ 732{
744#ifdef AF_UNIX 733#ifdef AF_UNIX
745 struct sockaddr_un *un; 734 struct sockaddr_un *un;
@@ -816,9 +805,8 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName,
816 if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "DISABLEV6")) 805 if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "DISABLEV6"))
817 { 806 {
818 if (GNUNET_SYSERR == 807 if (GNUNET_SYSERR ==
819 (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (cfg, 808 (disablev6 =
820 serviceName, 809 GNUNET_CONFIGURATION_get_value_yesno (cfg, serviceName, "DISABLEV6")))
821 "DISABLEV6")))
822 return GNUNET_SYSERR; 810 return GNUNET_SYSERR;
823 } 811 }
824 else 812 else
@@ -830,8 +818,8 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName,
830 desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0); 818 desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
831 if (NULL == desc) 819 if (NULL == desc)
832 { 820 {
833 if ((errno == ENOBUFS) || 821 if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) ||
834 (errno == ENOMEM) || (errno == ENFILE) || (errno == EACCES)) 822 (errno == EACCES))
835 { 823 {
836 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); 824 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
837 return GNUNET_SYSERR; 825 return GNUNET_SYSERR;
@@ -853,8 +841,7 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName,
853 if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "PORT")) 841 if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "PORT"))
854 { 842 {
855 GNUNET_break (GNUNET_OK == 843 GNUNET_break (GNUNET_OK ==
856 GNUNET_CONFIGURATION_get_value_number (cfg, 844 GNUNET_CONFIGURATION_get_value_number (cfg, serviceName,
857 serviceName,
858 "PORT", &port)); 845 "PORT", &port));
859 if (port > 65535) 846 if (port > 65535)
860 { 847 {
@@ -869,8 +856,7 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName,
869 if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "BINDTO")) 856 if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "BINDTO"))
870 { 857 {
871 GNUNET_break (GNUNET_OK == 858 GNUNET_break (GNUNET_OK ==
872 GNUNET_CONFIGURATION_get_value_string (cfg, 859 GNUNET_CONFIGURATION_get_value_string (cfg, serviceName,
873 serviceName,
874 "BINDTO", &hostname)); 860 "BINDTO", &hostname));
875 } 861 }
876 else 862 else
@@ -878,11 +864,11 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName,
878 864
879 unixpath = NULL; 865 unixpath = NULL;
880#ifdef AF_UNIX 866#ifdef AF_UNIX
881 if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (cfg, 867 if ((GNUNET_YES ==
882 serviceName, "UNIXPATH")) 868 GNUNET_CONFIGURATION_have_value (cfg, serviceName, "UNIXPATH")) &&
883 && (GNUNET_OK == 869 (GNUNET_OK ==
884 GNUNET_CONFIGURATION_get_value_string (cfg, serviceName, "UNIXPATH", 870 GNUNET_CONFIGURATION_get_value_string (cfg, serviceName, "UNIXPATH",
885 &unixpath)) && 871 &unixpath)) &&
886 (0 < strlen (unixpath))) 872 (0 < strlen (unixpath)))
887 { 873 {
888 /* probe UNIX support */ 874 /* probe UNIX support */
@@ -901,8 +887,8 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName,
901 desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); 887 desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
902 if (NULL == desc) 888 if (NULL == desc)
903 { 889 {
904 if ((errno == ENOBUFS) || 890 if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) ||
905 (errno == ENOMEM) || (errno == ENFILE) || (errno == EACCES)) 891 (errno == EACCES))
906 { 892 {
907 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); 893 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
908 GNUNET_free_non_null (hostname); 894 GNUNET_free_non_null (hostname);
@@ -955,11 +941,10 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName,
955 memset (&hints, 0, sizeof (struct addrinfo)); 941 memset (&hints, 0, sizeof (struct addrinfo));
956 if (disablev6) 942 if (disablev6)
957 hints.ai_family = AF_INET; 943 hints.ai_family = AF_INET;
958 if ((0 != (ret = getaddrinfo (hostname, 944 if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) ||
959 NULL, &hints, &res))) || (res == NULL)) 945 (res == NULL))
960 { 946 {
961 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 947 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to resolve `%s': %s\n"),
962 _("Failed to resolve `%s': %s\n"),
963 hostname, gai_strerror (ret)); 948 hostname, gai_strerror (ret));
964 GNUNET_free (hostname); 949 GNUNET_free (hostname);
965 GNUNET_free_non_null (unixpath); 950 GNUNET_free_non_null (unixpath);
@@ -1006,8 +991,7 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName,
1006 if ((pos->ai_socktype != SOCK_STREAM) && (pos->ai_socktype != 0)) 991 if ((pos->ai_socktype != SOCK_STREAM) && (pos->ai_socktype != 0))
1007 continue; /* huh? */ 992 continue; /* huh? */
1008#if DEBUG_SERVICE 993#if DEBUG_SERVICE
1009 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 994 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service `%s' will bind to `%s'\n",
1010 "Service `%s' will bind to `%s'\n",
1011 serviceName, GNUNET_a2s (pos->ai_addr, pos->ai_addrlen)); 995 serviceName, GNUNET_a2s (pos->ai_addr, pos->ai_addrlen));
1012#endif 996#endif
1013 if (pos->ai_family == AF_INET) 997 if (pos->ai_family == AF_INET)
@@ -1130,8 +1114,7 @@ setup_service (struct GNUNET_SERVICE_Context *sctx)
1130 if (GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->serviceName, "TIMEOUT")) 1114 if (GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->serviceName, "TIMEOUT"))
1131 { 1115 {
1132 if (GNUNET_OK != 1116 if (GNUNET_OK !=
1133 GNUNET_CONFIGURATION_get_value_time (sctx->cfg, 1117 GNUNET_CONFIGURATION_get_value_time (sctx->cfg, sctx->serviceName,
1134 sctx->serviceName,
1135 "TIMEOUT", &idleout)) 1118 "TIMEOUT", &idleout))
1136 { 1119 {
1137 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1120 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -1144,13 +1127,13 @@ setup_service (struct GNUNET_SERVICE_Context *sctx)
1144 else 1127 else
1145 sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; 1128 sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
1146 1129
1147 if (GNUNET_CONFIGURATION_have_value (sctx->cfg, 1130 if (GNUNET_CONFIGURATION_have_value
1148 sctx->serviceName, "TOLERANT")) 1131 (sctx->cfg, sctx->serviceName, "TOLERANT"))
1149 { 1132 {
1150 if (GNUNET_SYSERR == 1133 if (GNUNET_SYSERR ==
1151 (tolerant = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, 1134 (tolerant =
1152 sctx->serviceName, 1135 GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->serviceName,
1153 "TOLERANT"))) 1136 "TOLERANT")))
1154 { 1137 {
1155 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1138 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1156 _("Specified value for `%s' of service `%s' is invalid\n"), 1139 _("Specified value for `%s' of service `%s' is invalid\n"),
@@ -1164,19 +1147,17 @@ setup_service (struct GNUNET_SERVICE_Context *sctx)
1164#ifndef MINGW 1147#ifndef MINGW
1165 errno = 0; 1148 errno = 0;
1166 if ((NULL != (lpid = getenv ("LISTEN_PID"))) && 1149 if ((NULL != (lpid = getenv ("LISTEN_PID"))) &&
1167 (1 == sscanf (lpid, "%u", &pid)) && 1150 (1 == sscanf (lpid, "%u", &pid)) && (getpid () == (pid_t) pid) &&
1168 (getpid () == (pid_t) pid) &&
1169 (NULL != (nfds = getenv ("LISTEN_FDS"))) && 1151 (NULL != (nfds = getenv ("LISTEN_FDS"))) &&
1170 (1 == sscanf (nfds, "%u", &cnt)) && 1152 (1 == sscanf (nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) &&
1171 (cnt > 0) && (cnt < FD_SETSIZE) && (cnt + 4 < FD_SETSIZE)) 1153 (cnt + 4 < FD_SETSIZE))
1172 { 1154 {
1173 sctx->lsocks = 1155 sctx->lsocks =
1174 GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (cnt + 1)); 1156 GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (cnt + 1));
1175 while (0 < cnt--) 1157 while (0 < cnt--)
1176 { 1158 {
1177 flags = fcntl (3 + cnt, F_GETFD); 1159 flags = fcntl (3 + cnt, F_GETFD);
1178 if ((flags < 0) || 1160 if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) ||
1179 (0 != (flags & FD_CLOEXEC)) ||
1180 (NULL == 1161 (NULL ==
1181 (sctx->lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt)))) 1162 (sctx->lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt))))
1182 { 1163 {
@@ -1199,17 +1180,16 @@ setup_service (struct GNUNET_SERVICE_Context *sctx)
1199 1180
1200 if ((sctx->lsocks == NULL) && 1181 if ((sctx->lsocks == NULL) &&
1201 (GNUNET_SYSERR == 1182 (GNUNET_SYSERR ==
1202 GNUNET_SERVICE_get_server_addresses (sctx->serviceName, 1183 GNUNET_SERVICE_get_server_addresses (sctx->serviceName, sctx->cfg,
1203 sctx->cfg,
1204 &sctx->addrs, &sctx->addrlens))) 1184 &sctx->addrs, &sctx->addrlens)))
1205 return GNUNET_SYSERR; 1185 return GNUNET_SYSERR;
1206 sctx->require_found = tolerant ? GNUNET_NO : GNUNET_YES; 1186 sctx->require_found = tolerant ? GNUNET_NO : GNUNET_YES;
1207 sctx->match_uid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, 1187 sctx->match_uid =
1208 sctx->serviceName, 1188 GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->serviceName,
1209 "UNIX_MATCH_UID"); 1189 "UNIX_MATCH_UID");
1210 sctx->match_gid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, 1190 sctx->match_gid =
1211 sctx->serviceName, 1191 GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->serviceName,
1212 "UNIX_MATCH_GID"); 1192 "UNIX_MATCH_GID");
1213 process_acl4 (&sctx->v4_denied, sctx, "REJECT_FROM"); 1193 process_acl4 (&sctx->v4_denied, sctx, "REJECT_FROM");
1214 process_acl4 (&sctx->v4_allowed, sctx, "ACCEPT_FROM"); 1194 process_acl4 (&sctx->v4_allowed, sctx, "ACCEPT_FROM");
1215 process_acl6 (&sctx->v6_denied, sctx, "REJECT_FROM6"); 1195 process_acl6 (&sctx->v6_denied, sctx, "REJECT_FROM6");
@@ -1230,8 +1210,7 @@ get_user_name (struct GNUNET_SERVICE_Context *sctx)
1230 char *un; 1210 char *un;
1231 1211
1232 if (GNUNET_OK != 1212 if (GNUNET_OK !=
1233 GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, 1213 GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, sctx->serviceName,
1234 sctx->serviceName,
1235 "USERNAME", &un)) 1214 "USERNAME", &un))
1236 return NULL; 1215 return NULL;
1237 return un; 1216 return un;
@@ -1319,17 +1298,13 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1319 1298
1320 GNUNET_RESOLVER_connect (sctx->cfg); 1299 GNUNET_RESOLVER_connect (sctx->cfg);
1321 if (sctx->lsocks != NULL) 1300 if (sctx->lsocks != NULL)
1322 sctx->server = GNUNET_SERVER_create_with_sockets (&check_access, 1301 sctx->server =
1323 sctx, 1302 GNUNET_SERVER_create_with_sockets (&check_access, sctx, sctx->lsocks,
1324 sctx->lsocks, 1303 sctx->timeout, sctx->require_found);
1325 sctx->timeout,
1326 sctx->require_found);
1327 else 1304 else
1328 sctx->server = GNUNET_SERVER_create (&check_access, 1305 sctx->server =
1329 sctx, 1306 GNUNET_SERVER_create (&check_access, sctx, sctx->addrs, sctx->addrlens,
1330 sctx->addrs, 1307 sctx->timeout, sctx->require_found);
1331 sctx->addrlens,
1332 sctx->timeout, sctx->require_found);
1333 if (sctx->server == NULL) 1308 if (sctx->server == NULL)
1334 { 1309 {
1335 if (sctx->addrs != NULL) 1310 if (sctx->addrs != NULL)
@@ -1337,10 +1312,9 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1337 i = 0; 1312 i = 0;
1338 while (sctx->addrs[i] != NULL) 1313 while (sctx->addrs[i] != NULL)
1339 { 1314 {
1340 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1315 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Failed to start `%s' at `%s'\n"),
1341 _("Failed to start `%s' at `%s'\n"), 1316 sctx->serviceName, GNUNET_a2s (sctx->addrs[i],
1342 sctx->serviceName, 1317 sctx->addrlens[i]));
1343 GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
1344 i++; 1318 i++;
1345 } 1319 }
1346 } 1320 }
@@ -1351,8 +1325,8 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1351 { 1325 {
1352 /* install a task that will kill the server 1326 /* install a task that will kill the server
1353 * process if the scheduler ever gets a shutdown signal */ 1327 * process if the scheduler ever gets a shutdown signal */
1354 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 1328 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
1355 &shutdown_task, sctx->server); 1329 sctx->server);
1356 } 1330 }
1357 sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers)); 1331 sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers));
1358 memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers)); 1332 memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers));
@@ -1372,10 +1346,9 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1372 i = 0; 1346 i = 0;
1373 while (sctx->addrs[i] != NULL) 1347 while (sctx->addrs[i] != NULL)
1374 { 1348 {
1375 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1349 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Service `%s' runs at %s\n"),
1376 _("Service `%s' runs at %s\n"), 1350 sctx->serviceName, GNUNET_a2s (sctx->addrs[i],
1377 sctx->serviceName, 1351 sctx->addrlens[i]));
1378 GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
1379 i++; 1352 i++;
1380 } 1353 }
1381 } 1354 }
@@ -1480,8 +1453,8 @@ set_user_id (struct GNUNET_SERVICE_Context *sctx)
1480 if (pws == NULL) 1453 if (pws == NULL)
1481 { 1454 {
1482 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1455 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1483 _("Cannot obtain information about user `%s': %s\n"), 1456 _("Cannot obtain information about user `%s': %s\n"), user,
1484 user, errno == 0 ? _("No such user") : STRERROR (errno)); 1457 errno == 0 ? _("No such user") : STRERROR (errno));
1485 GNUNET_free (user); 1458 GNUNET_free (user);
1486 return GNUNET_SYSERR; 1459 return GNUNET_SYSERR;
1487 } 1460 }
@@ -1537,11 +1510,9 @@ pid_file_delete (struct GNUNET_SERVICE_Context *sctx)
1537 * if we shutdown nicely 1510 * if we shutdown nicely
1538 */ 1511 */
1539int 1512int
1540GNUNET_SERVICE_run (int argc, 1513GNUNET_SERVICE_run (int argc, char *const *argv, const char *serviceName,
1541 char *const *argv, 1514 enum GNUNET_SERVICE_Options opt, GNUNET_SERVICE_Main task,
1542 const char *serviceName, 1515 void *task_cls)
1543 enum GNUNET_SERVICE_Options opt,
1544 GNUNET_SERVICE_Main task, void *task_cls)
1545{ 1516{
1546#define HANDLE_ERROR do { err = 1; GNUNET_break (0); goto shutdown; } while (0) 1517#define HANDLE_ERROR do { err = 1; GNUNET_break (0); goto shutdown; } while (0)
1547 1518
@@ -1583,8 +1554,8 @@ GNUNET_SERVICE_run (int argc,
1583 sctx.serviceName = serviceName; 1554 sctx.serviceName = serviceName;
1584 sctx.cfg = cfg = GNUNET_CONFIGURATION_create (); 1555 sctx.cfg = cfg = GNUNET_CONFIGURATION_create ();
1585 /* setup subsystems */ 1556 /* setup subsystems */
1586 if (GNUNET_SYSERR == GNUNET_GETOPT_run (serviceName, service_options, argc, 1557 if (GNUNET_SYSERR ==
1587 argv)) 1558 GNUNET_GETOPT_run (serviceName, service_options, argc, argv))
1588 goto shutdown; 1559 goto shutdown;
1589 if (GNUNET_OK != GNUNET_log_setup (serviceName, loglev, logfile)) 1560 if (GNUNET_OK != GNUNET_log_setup (serviceName, loglev, logfile))
1590 HANDLE_ERROR; 1561 HANDLE_ERROR;
@@ -1598,8 +1569,8 @@ GNUNET_SERVICE_run (int argc,
1598 goto shutdown; 1569 goto shutdown;
1599#if DEBUG_SERVICE 1570#if DEBUG_SERVICE
1600 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1571 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1601 "Service `%s' runs with configuration from `%s'\n", 1572 "Service `%s' runs with configuration from `%s'\n", serviceName,
1602 serviceName, cfg_fn); 1573 cfg_fn);
1603#endif 1574#endif
1604 if (GNUNET_OK == 1575 if (GNUNET_OK ==
1605 GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "testing", "skew_offset", 1576 GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "testing", "skew_offset",
@@ -1679,17 +1650,13 @@ GNUNET_SERVICE_start (const char *serviceName,
1679 return NULL; 1650 return NULL;
1680 } 1651 }
1681 if (sctx->lsocks != NULL) 1652 if (sctx->lsocks != NULL)
1682 sctx->server = GNUNET_SERVER_create_with_sockets (&check_access, 1653 sctx->server =
1683 sctx, 1654 GNUNET_SERVER_create_with_sockets (&check_access, sctx, sctx->lsocks,
1684 sctx->lsocks, 1655 sctx->timeout, sctx->require_found);
1685 sctx->timeout,
1686 sctx->require_found);
1687 else 1656 else
1688 sctx->server = GNUNET_SERVER_create (&check_access, 1657 sctx->server =
1689 sctx, 1658 GNUNET_SERVER_create (&check_access, sctx, sctx->addrs, sctx->addrlens,
1690 sctx->addrs, 1659 sctx->timeout, sctx->require_found);
1691 sctx->addrlens,
1692 sctx->timeout, sctx->require_found);
1693 1660
1694 if (NULL == sctx->server) 1661 if (NULL == sctx->server)
1695 { 1662 {
diff --git a/src/util/strings.c b/src/util/strings.c
index a95981690..e2ca69e10 100644
--- a/src/util/strings.c
+++ b/src/util/strings.c
@@ -96,8 +96,8 @@ GNUNET_STRINGS_buffer_fill (char *buffer, size_t size, unsigned int count, ...)
96 * in the buffer, or 0 on error. 96 * in the buffer, or 0 on error.
97 */ 97 */
98unsigned int 98unsigned int
99GNUNET_STRINGS_buffer_tokenize (const char *buffer, 99GNUNET_STRINGS_buffer_tokenize (const char *buffer, size_t size,
100 size_t size, unsigned int count, ...) 100 unsigned int count, ...)
101{ 101{
102 unsigned int start; 102 unsigned int start;
103 unsigned int needed; 103 unsigned int needed;
@@ -314,8 +314,7 @@ GNUNET_STRINGS_filename_expand (const char *fil)
314 } 314 }
315 n = strlen (fm) + 1 + strlen (fil_ptr) + 1; 315 n = strlen (fm) + 1 + strlen (fil_ptr) + 1;
316 buffer = GNUNET_malloc (n); 316 buffer = GNUNET_malloc (n);
317 GNUNET_snprintf (buffer, n, "%s%s%s", 317 GNUNET_snprintf (buffer, n, "%s%s%s", fm,
318 fm,
319 (fm[strlen (fm) - 1] == 318 (fm[strlen (fm) - 1] ==
320 DIR_SEPARATOR) ? "" : DIR_SEPARATOR_STR, fil_ptr); 319 DIR_SEPARATOR) ? "" : DIR_SEPARATOR_STR, fil_ptr);
321 GNUNET_free (fm); 320 GNUNET_free (fm);
diff --git a/src/util/test_client.c b/src/util/test_client.c
index 9c2abb016..f9d961ab6 100644
--- a/src/util/test_client.c
+++ b/src/util/test_client.c
@@ -70,8 +70,7 @@ copy_msg (void *cls, size_t size, void *buf)
70 * Callback that just bounces the message back to the sender. 70 * Callback that just bounces the message back to the sender.
71 */ 71 */
72static void 72static void
73echo_cb (void *cls, 73echo_cb (void *cls, struct GNUNET_SERVER_Client *client,
74 struct GNUNET_SERVER_Client *client,
75 const struct GNUNET_MessageHeader *message) 74 const struct GNUNET_MessageHeader *message)
76{ 75{
77 struct CopyContext *cc; 76 struct CopyContext *cc;
@@ -148,13 +147,10 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
148#endif 147#endif
149 sa.sin_family = AF_INET; 148 sa.sin_family = AF_INET;
150 sa.sin_port = htons (PORT); 149 sa.sin_port = htons (PORT);
151 server = GNUNET_SERVER_create (NULL, 150 server =
152 NULL, 151 GNUNET_SERVER_create (NULL, NULL, sap, slens,
153 sap, 152 GNUNET_TIME_relative_multiply
154 slens, 153 (GNUNET_TIME_UNIT_MILLISECONDS, 10000), GNUNET_NO);
155 GNUNET_TIME_relative_multiply
156 (GNUNET_TIME_UNIT_MILLISECONDS, 10000),
157 GNUNET_NO);
158 GNUNET_assert (server != NULL); 154 GNUNET_assert (server != NULL);
159 handlers[0].callback_cls = cls; 155 handlers[0].callback_cls = cls;
160 handlers[1].callback_cls = cls; 156 handlers[1].callback_cls = cls;
@@ -166,8 +162,8 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
166 sizeof (struct 162 sizeof (struct
167 GNUNET_MessageHeader), 163 GNUNET_MessageHeader),
168 GNUNET_TIME_UNIT_SECONDS, 164 GNUNET_TIME_UNIT_SECONDS,
169 GNUNET_NO, 165 GNUNET_NO, &make_msg,
170 &make_msg, NULL)); 166 NULL));
171 GNUNET_CLIENT_receive (client, &recv_bounce, cls, 167 GNUNET_CLIENT_receive (client, &recv_bounce, cls,
172 GNUNET_TIME_relative_multiply 168 GNUNET_TIME_relative_multiply
173 (GNUNET_TIME_UNIT_MILLISECONDS, 10000)); 169 (GNUNET_TIME_UNIT_MILLISECONDS, 10000));
@@ -186,8 +182,8 @@ check ()
186 cfg = GNUNET_CONFIGURATION_create (); 182 cfg = GNUNET_CONFIGURATION_create ();
187 GNUNET_CONFIGURATION_set_value_number (cfg, MYNAME, "PORT", PORT); 183 GNUNET_CONFIGURATION_set_value_number (cfg, MYNAME, "PORT", PORT);
188 GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "HOSTNAME", "localhost"); 184 GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "HOSTNAME", "localhost");
189 GNUNET_CONFIGURATION_set_value_string (cfg, 185 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
190 "resolver", "HOSTNAME", "localhost"); 186 "localhost");
191 ok = 1; 187 ok = 1;
192 GNUNET_SCHEDULER_run (&task, &ok); 188 GNUNET_SCHEDULER_run (&task, &ok);
193 GNUNET_CONFIGURATION_destroy (cfg); 189 GNUNET_CONFIGURATION_destroy (cfg);
diff --git a/src/util/test_common_endian.c b/src/util/test_common_endian.c
index fb556c7f4..a709abec6 100644
--- a/src/util/test_common_endian.c
+++ b/src/util/test_common_endian.c
@@ -33,8 +33,8 @@ main (int argc, char *argv[])
33 CHECK (1); 33 CHECK (1);
34 CHECK (0x12345678); 34 CHECK (0x12345678);
35 CHECK (123456789012345LL); 35 CHECK (123456789012345LL);
36 if ((0x1234567890ABCDEFLL != 36 if ((0x1234567890ABCDEFLL != GNUNET_htonll (0xEFCDAB9078563412LL)) &&
37 GNUNET_htonll (0xEFCDAB9078563412LL)) && 42 != htonl (42)) 37 42 != htonl (42))
38 return 1; 38 return 1;
39 return 0; 39 return 0;
40} 40}
diff --git a/src/util/test_common_logging.c b/src/util/test_common_logging.c
index da200d62a..39ef58267 100644
--- a/src/util/test_common_logging.c
+++ b/src/util/test_common_logging.c
@@ -27,8 +27,8 @@
27#include "gnunet_common.h" 27#include "gnunet_common.h"
28 28
29static void 29static void
30my_log (void *ctx, enum GNUNET_ErrorType kind, 30my_log (void *ctx, enum GNUNET_ErrorType kind, const char *component,
31 const char *component, const char *date, const char *msg) 31 const char *date, const char *msg)
32{ 32{
33 unsigned int *c = ctx; 33 unsigned int *c = ctx;
34 34
diff --git a/src/util/test_configuration.c b/src/util/test_configuration.c
index 8bad5b5d4..2737cb4f7 100644
--- a/src/util/test_configuration.c
+++ b/src/util/test_configuration.c
@@ -75,8 +75,8 @@ initDiffsCBData (struct DiffsCBData *cbData)
75 * and comparing configuration 75 * and comparing configuration
76*/ 76*/
77static void 77static void
78diffsCallBack (void *cls, 78diffsCallBack (void *cls, const char *section, const char *option,
79 const char *section, const char *option, const char *value) 79 const char *value)
80{ 80{
81 struct DiffsCBData *cbData = cls; 81 struct DiffsCBData *cbData = cls;
82 int cbOption = cbData->callBackOption; 82 int cbOption = cbData->callBackOption;
@@ -90,15 +90,15 @@ diffsCallBack (void *cls,
90 { 90 {
91 GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, option, 91 GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, option,
92 "new-value"); 92 "new-value");
93 GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, 93 GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, option,
94 option, "new-value"); 94 "new-value");
95 } 95 }
96 break; 96 break;
97 case EDIT_ALL: 97 case EDIT_ALL:
98 GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, option, 98 GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, option,
99 "new-value"); 99 "new-value");
100 GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, 100 GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, option,
101 option, "new-value"); 101 "new-value");
102 break; 102 break;
103 case ADD_NEW_ENTRY: 103 case ADD_NEW_ENTRY:
104 { 104 {
@@ -107,8 +107,8 @@ diffsCallBack (void *cls,
107 if (hit == 0) 107 if (hit == 0)
108 { 108 {
109 hit = 1; 109 hit = 1;
110 GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, 110 GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, "new-key",
111 "new-key", "new-value"); 111 "new-value");
112 GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, 112 GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section,
113 "new-key", "new-value"); 113 "new-key", "new-value");
114 } 114 }
@@ -183,8 +183,8 @@ editConfiguration (struct GNUNET_CONFIGURATION_Handle *cfg, int option)
183 GNUNET_asprintf (&key, "key%d", i); 183 GNUNET_asprintf (&key, "key%d", i);
184 GNUNET_CONFIGURATION_set_value_string (cfg, "new-section", key, 184 GNUNET_CONFIGURATION_set_value_string (cfg, "new-section", key,
185 "new-value"); 185 "new-value");
186 GNUNET_CONFIGURATION_set_value_string (diffsCB.cfgDiffs, 186 GNUNET_CONFIGURATION_set_value_string (diffsCB.cfgDiffs, "new-section",
187 "new-section", key, "new-value"); 187 key, "new-value");
188 GNUNET_free (key); 188 GNUNET_free (key);
189 } 189 }
190 break; 190 break;
@@ -282,8 +282,8 @@ testConfig ()
282 return 2; 282 return 2;
283 } 283 }
284 GNUNET_free (c); 284 GNUNET_free (c);
285 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, 285 if (GNUNET_OK !=
286 "test", "five", &l)) 286 GNUNET_CONFIGURATION_get_value_number (cfg, "test", "five", &l))
287 { 287 {
288 GNUNET_break (0); 288 GNUNET_break (0);
289 return 3; 289 return 3;
@@ -364,9 +364,9 @@ testConfigFilenames ()
364 int idx; 364 int idx;
365 365
366 idx = 0; 366 idx = 0;
367 if (3 != GNUNET_CONFIGURATION_iterate_value_filenames (cfg, 367 if (3 !=
368 "FILENAMES", 368 GNUNET_CONFIGURATION_iterate_value_filenames (cfg, "FILENAMES", "test",
369 "test", &check, &idx)) 369 &check, &idx))
370 { 370 {
371 GNUNET_break (0); 371 GNUNET_break (0);
372 return 8; 372 return 8;
@@ -374,60 +374,54 @@ testConfigFilenames ()
374 if (idx != 3) 374 if (idx != 3)
375 return 16; 375 return 16;
376 if (GNUNET_OK != 376 if (GNUNET_OK !=
377 GNUNET_CONFIGURATION_remove_value_filename (cfg, 377 GNUNET_CONFIGURATION_remove_value_filename (cfg, "FILENAMES", "test",
378 "FILENAMES", 378 "/File Name"))
379 "test", "/File Name"))
380 { 379 {
381 GNUNET_break (0); 380 GNUNET_break (0);
382 return 24; 381 return 24;
383 } 382 }
384 383
385 if (GNUNET_NO != 384 if (GNUNET_NO !=
386 GNUNET_CONFIGURATION_remove_value_filename (cfg, 385 GNUNET_CONFIGURATION_remove_value_filename (cfg, "FILENAMES", "test",
387 "FILENAMES", 386 "/File Name"))
388 "test", "/File Name"))
389 { 387 {
390 GNUNET_break (0); 388 GNUNET_break (0);
391 return 32; 389 return 32;
392 } 390 }
393 if (GNUNET_NO != 391 if (GNUNET_NO !=
394 GNUNET_CONFIGURATION_remove_value_filename (cfg, 392 GNUNET_CONFIGURATION_remove_value_filename (cfg, "FILENAMES", "test",
395 "FILENAMES", "test", "Stuff")) 393 "Stuff"))
396 { 394 {
397 GNUNET_break (0); 395 GNUNET_break (0);
398 return 40; 396 return 40;
399 } 397 }
400 398
401 if (GNUNET_NO != 399 if (GNUNET_NO !=
402 GNUNET_CONFIGURATION_append_value_filename (cfg, 400 GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test",
403 "FILENAMES", 401 "/Hello"))
404 "test", "/Hello"))
405 { 402 {
406 GNUNET_break (0); 403 GNUNET_break (0);
407 return 48; 404 return 48;
408 } 405 }
409 if (GNUNET_NO != 406 if (GNUNET_NO !=
410 GNUNET_CONFIGURATION_append_value_filename (cfg, 407 GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test",
411 "FILENAMES", 408 "/World"))
412 "test", "/World"))
413 { 409 {
414 GNUNET_break (0); 410 GNUNET_break (0);
415 return 56; 411 return 56;
416 } 412 }
417 413
418 if (GNUNET_YES != 414 if (GNUNET_YES !=
419 GNUNET_CONFIGURATION_append_value_filename (cfg, 415 GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test",
420 "FILENAMES", 416 "/File 1"))
421 "test", "/File 1"))
422 { 417 {
423 GNUNET_break (0); 418 GNUNET_break (0);
424 return 64; 419 return 64;
425 } 420 }
426 421
427 if (GNUNET_YES != 422 if (GNUNET_YES !=
428 GNUNET_CONFIGURATION_append_value_filename (cfg, 423 GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test",
429 "FILENAMES", 424 "/File 2"))
430 "test", "/File 2"))
431 { 425 {
432 GNUNET_break (0); 426 GNUNET_break (0);
433 return 72; 427 return 72;
@@ -437,9 +431,9 @@ testConfigFilenames ()
437 want[1] = "/World"; 431 want[1] = "/World";
438 want[2] = "/File 1"; 432 want[2] = "/File 1";
439 want[3] = "/File 2"; 433 want[3] = "/File 2";
440 if (4 != GNUNET_CONFIGURATION_iterate_value_filenames (cfg, 434 if (4 !=
441 "FILENAMES", 435 GNUNET_CONFIGURATION_iterate_value_filenames (cfg, "FILENAMES", "test",
442 "test", &check, &idx)) 436 &check, &idx))
443 { 437 {
444 GNUNET_break (0); 438 GNUNET_break (0);
445 return 80; 439 return 80;
diff --git a/src/util/test_connection.c b/src/util/test_connection.c
index 3519522ef..cb69f4036 100644
--- a/src/util/test_connection.c
+++ b/src/util/test_connection.c
@@ -75,9 +75,7 @@ open_listen_socket ()
75} 75}
76 76
77static void 77static void
78receive_check (void *cls, 78receive_check (void *cls, const void *buf, size_t available,
79 const void *buf,
80 size_t available,
81 const struct sockaddr *addr, socklen_t addrlen, int errCode) 79 const struct sockaddr *addr, socklen_t addrlen, int errCode)
82{ 80{
83 int *ok = cls; 81 int *ok = cls;
@@ -93,11 +91,10 @@ receive_check (void *cls,
93#if VERBOSE 91#if VERBOSE
94 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receive needs more data\n"); 92 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receive needs more data\n");
95#endif 93#endif
96 GNUNET_CONNECTION_receive (asock, 94 GNUNET_CONNECTION_receive (asock, 1024,
97 1024,
98 GNUNET_TIME_relative_multiply 95 GNUNET_TIME_relative_multiply
99 (GNUNET_TIME_UNIT_SECONDS, 5), 96 (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check,
100 &receive_check, cls); 97 cls);
101 } 98 }
102 else 99 else
103 { 100 {
@@ -127,8 +124,7 @@ run_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
127 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
128 "Test asks to receive on accepted socket\n"); 125 "Test asks to receive on accepted socket\n");
129#endif 126#endif
130 GNUNET_CONNECTION_receive (asock, 127 GNUNET_CONNECTION_receive (asock, 1024,
131 1024,
132 GNUNET_TIME_relative_multiply 128 GNUNET_TIME_relative_multiply
133 (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, 129 (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check,
134 cls); 130 cls);
@@ -162,15 +158,14 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test asks for write notification\n"); 158 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test asks for write notification\n");
163#endif 159#endif
164 GNUNET_assert (NULL != 160 GNUNET_assert (NULL !=
165 GNUNET_CONNECTION_notify_transmit_ready (csock, 161 GNUNET_CONNECTION_notify_transmit_ready (csock, 12,
166 12,
167 GNUNET_TIME_UNIT_SECONDS, 162 GNUNET_TIME_UNIT_SECONDS,
168 &make_hello, NULL)); 163 &make_hello, NULL));
169#if VERBOSE 164#if VERBOSE
170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test prepares to accept\n"); 165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test prepares to accept\n");
171#endif 166#endif
172 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 167 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, ls, &run_accept,
173 ls, &run_accept, cls); 168 cls);
174} 169}
175 170
176 171
@@ -185,8 +180,8 @@ check ()
185 180
186 ok = 1; 181 ok = 1;
187 cfg = GNUNET_CONFIGURATION_create (); 182 cfg = GNUNET_CONFIGURATION_create ();
188 GNUNET_CONFIGURATION_set_value_string (cfg, 183 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
189 "resolver", "HOSTNAME", "localhost"); 184 "localhost");
190 GNUNET_SCHEDULER_run (&task, &ok); 185 GNUNET_SCHEDULER_run (&task, &ok);
191 GNUNET_CONFIGURATION_destroy (cfg); 186 GNUNET_CONFIGURATION_destroy (cfg);
192 return ok; 187 return ok;
diff --git a/src/util/test_connection_addressing.c b/src/util/test_connection_addressing.c
index 111894a36..2d08acc3c 100644
--- a/src/util/test_connection_addressing.c
+++ b/src/util/test_connection_addressing.c
@@ -67,9 +67,9 @@ open_listen_socket ()
67 if (GNUNET_NETWORK_socket_setsockopt 67 if (GNUNET_NETWORK_socket_setsockopt
68 (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) 68 (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)
69 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); 69 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt");
70 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (desc, 70 if (GNUNET_OK !=
71 (const struct sockaddr *) &sa, 71 GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) &sa,
72 sizeof (sa))) 72 sizeof (sa)))
73 { 73 {
74 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 74 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
75 "bind"); 75 "bind");
@@ -81,9 +81,7 @@ open_listen_socket ()
81 81
82 82
83static void 83static void
84receive_check (void *cls, 84receive_check (void *cls, const void *buf, size_t available,
85 const void *buf,
86 size_t available,
87 const struct sockaddr *addr, socklen_t addrlen, int errCode) 85 const struct sockaddr *addr, socklen_t addrlen, int errCode)
88{ 86{
89 int *ok = cls; 87 int *ok = cls;
@@ -93,11 +91,10 @@ receive_check (void *cls,
93 sofar += available; 91 sofar += available;
94 if (sofar < 12) 92 if (sofar < 12)
95 { 93 {
96 GNUNET_CONNECTION_receive (asock, 94 GNUNET_CONNECTION_receive (asock, 1024,
97 1024,
98 GNUNET_TIME_relative_multiply 95 GNUNET_TIME_relative_multiply
99 (GNUNET_TIME_UNIT_SECONDS, 5), 96 (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check,
100 &receive_check, cls); 97 cls);
101 } 98 }
102 else 99 else
103 { 100 {
@@ -132,8 +129,7 @@ run_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
132 GNUNET_assert (0 == memcmp (&expect, v4, alen)); 129 GNUNET_assert (0 == memcmp (&expect, v4, alen));
133 GNUNET_free (addr); 130 GNUNET_free (addr);
134 GNUNET_CONNECTION_destroy (lsock, GNUNET_YES); 131 GNUNET_CONNECTION_destroy (lsock, GNUNET_YES);
135 GNUNET_CONNECTION_receive (asock, 132 GNUNET_CONNECTION_receive (asock, 1024,
136 1024,
137 GNUNET_TIME_relative_multiply 133 GNUNET_TIME_relative_multiply
138 (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, 134 (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check,
139 cls); 135 cls);
@@ -162,18 +158,18 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
162 v4.sin_family = AF_INET; 158 v4.sin_family = AF_INET;
163 v4.sin_port = htons (PORT); 159 v4.sin_port = htons (PORT);
164 v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK); 160 v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
165 csock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, 161 csock =
166 (const struct sockaddr 162 GNUNET_CONNECTION_create_from_sockaddr (AF_INET,
167 *) &v4, sizeof (v4)); 163 (const struct sockaddr *) &v4,
164 sizeof (v4));
168 GNUNET_assert (csock != NULL); 165 GNUNET_assert (csock != NULL);
169 GNUNET_assert (NULL != 166 GNUNET_assert (NULL !=
170 GNUNET_CONNECTION_notify_transmit_ready (csock, 167 GNUNET_CONNECTION_notify_transmit_ready (csock, 12,
171 12,
172 GNUNET_TIME_UNIT_SECONDS, 168 GNUNET_TIME_UNIT_SECONDS,
173 &make_hello, NULL)); 169 &make_hello, NULL));
174 GNUNET_CONNECTION_destroy (csock, GNUNET_YES); 170 GNUNET_CONNECTION_destroy (csock, GNUNET_YES);
175 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 171 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, ls, &run_accept,
176 ls, &run_accept, cls); 172 cls);
177} 173}
178 174
179 175
diff --git a/src/util/test_connection_receive_cancel.c b/src/util/test_connection_receive_cancel.c
index d635f5742..aa1672455 100644
--- a/src/util/test_connection_receive_cancel.c
+++ b/src/util/test_connection_receive_cancel.c
@@ -76,9 +76,7 @@ open_listen_socket ()
76 76
77 77
78static void 78static void
79dead_receive (void *cls, 79dead_receive (void *cls, const void *buf, size_t available,
80 const void *buf,
81 size_t available,
82 const struct sockaddr *addr, socklen_t addrlen, int errCode) 80 const struct sockaddr *addr, socklen_t addrlen, int errCode)
83{ 81{
84 GNUNET_assert (0); 82 GNUNET_assert (0);
@@ -93,8 +91,7 @@ run_accept_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
93 GNUNET_assert (asock != NULL); 91 GNUNET_assert (asock != NULL);
94 GNUNET_assert (GNUNET_YES == GNUNET_CONNECTION_check (asock)); 92 GNUNET_assert (GNUNET_YES == GNUNET_CONNECTION_check (asock));
95 GNUNET_CONNECTION_destroy (lsock, GNUNET_YES); 93 GNUNET_CONNECTION_destroy (lsock, GNUNET_YES);
96 GNUNET_CONNECTION_receive (asock, 94 GNUNET_CONNECTION_receive (asock, 1024,
97 1024,
98 GNUNET_TIME_relative_multiply 95 GNUNET_TIME_relative_multiply
99 (GNUNET_TIME_UNIT_SECONDS, 5), &dead_receive, cls); 96 (GNUNET_TIME_UNIT_SECONDS, 5), &dead_receive, cls);
100} 97}
@@ -121,10 +118,10 @@ task_receive_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
121 GNUNET_assert (lsock != NULL); 118 GNUNET_assert (lsock != NULL);
122 csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT); 119 csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT);
123 GNUNET_assert (csock != NULL); 120 GNUNET_assert (csock != NULL);
124 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 121 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, ls,
125 ls, &run_accept_cancel, cls); 122 &run_accept_cancel, cls);
126 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 123 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &receive_cancel_task,
127 &receive_cancel_task, cls); 124 cls);
128} 125}
129 126
130 127
@@ -139,8 +136,8 @@ check_receive_cancel ()
139 136
140 ok = 1; 137 ok = 1;
141 cfg = GNUNET_CONFIGURATION_create (); 138 cfg = GNUNET_CONFIGURATION_create ();
142 GNUNET_CONFIGURATION_set_value_string (cfg, 139 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
143 "resolver", "HOSTNAME", "localhost"); 140 "localhost");
144 GNUNET_SCHEDULER_run (&task_receive_cancel, &ok); 141 GNUNET_SCHEDULER_run (&task_receive_cancel, &ok);
145 GNUNET_CONFIGURATION_destroy (cfg); 142 GNUNET_CONFIGURATION_destroy (cfg);
146 return ok; 143 return ok;
diff --git a/src/util/test_connection_timeout.c b/src/util/test_connection_timeout.c
index 3989d654a..2338665cb 100644
--- a/src/util/test_connection_timeout.c
+++ b/src/util/test_connection_timeout.c
@@ -94,8 +94,7 @@ send_kilo (void *cls, size_t size, void *buf)
94 memset (buf, 42, 1024); 94 memset (buf, 42, 1024);
95 95
96 GNUNET_assert (NULL != 96 GNUNET_assert (NULL !=
97 GNUNET_CONNECTION_notify_transmit_ready (csock, 97 GNUNET_CONNECTION_notify_transmit_ready (csock, 1024,
98 1024,
99 GNUNET_TIME_UNIT_SECONDS, 98 GNUNET_TIME_UNIT_SECONDS,
100 &send_kilo, cls)); 99 &send_kilo, cls));
101 return 1024; 100 return 1024;
@@ -112,8 +111,7 @@ task_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
112 csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT); 111 csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT);
113 GNUNET_assert (csock != NULL); 112 GNUNET_assert (csock != NULL);
114 GNUNET_assert (NULL != 113 GNUNET_assert (NULL !=
115 GNUNET_CONNECTION_notify_transmit_ready (csock, 114 GNUNET_CONNECTION_notify_transmit_ready (csock, 1024,
116 1024,
117 GNUNET_TIME_UNIT_SECONDS, 115 GNUNET_TIME_UNIT_SECONDS,
118 &send_kilo, cls)); 116 &send_kilo, cls));
119} 117}
@@ -130,8 +128,8 @@ check_timeout ()
130 128
131 ok = 1; 129 ok = 1;
132 cfg = GNUNET_CONFIGURATION_create (); 130 cfg = GNUNET_CONFIGURATION_create ();
133 GNUNET_CONFIGURATION_set_value_string (cfg, 131 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
134 "resolver", "HOSTNAME", "localhost"); 132 "localhost");
135 GNUNET_SCHEDULER_run (&task_timeout, &ok); 133 GNUNET_SCHEDULER_run (&task_timeout, &ok);
136 GNUNET_CONFIGURATION_destroy (cfg); 134 GNUNET_CONFIGURATION_destroy (cfg);
137 return ok; 135 return ok;
diff --git a/src/util/test_connection_timeout_no_connect.c b/src/util/test_connection_timeout_no_connect.c
index ea4a32412..2e8f9be2e 100644
--- a/src/util/test_connection_timeout_no_connect.c
+++ b/src/util/test_connection_timeout_no_connect.c
@@ -57,8 +57,7 @@ task_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
57 csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT); 57 csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT);
58 GNUNET_assert (csock != NULL); 58 GNUNET_assert (csock != NULL);
59 GNUNET_assert (NULL != 59 GNUNET_assert (NULL !=
60 GNUNET_CONNECTION_notify_transmit_ready (csock, 60 GNUNET_CONNECTION_notify_transmit_ready (csock, 1024,
61 1024,
62 GNUNET_TIME_UNIT_SECONDS, 61 GNUNET_TIME_UNIT_SECONDS,
63 &handle_timeout, 62 &handle_timeout,
64 cls)); 63 cls));
@@ -76,8 +75,8 @@ check_timeout ()
76 75
77 ok = 1; 76 ok = 1;
78 cfg = GNUNET_CONFIGURATION_create (); 77 cfg = GNUNET_CONFIGURATION_create ();
79 GNUNET_CONFIGURATION_set_value_string (cfg, 78 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
80 "resolver", "HOSTNAME", "localhost"); 79 "localhost");
81 GNUNET_SCHEDULER_run (&task_timeout, &ok); 80 GNUNET_SCHEDULER_run (&task_timeout, &ok);
82 GNUNET_CONFIGURATION_destroy (cfg); 81 GNUNET_CONFIGURATION_destroy (cfg);
83 return ok; 82 return ok;
diff --git a/src/util/test_connection_transmit_cancel.c b/src/util/test_connection_transmit_cancel.c
index 4280edf1d..d81c32a6c 100644
--- a/src/util/test_connection_transmit_cancel.c
+++ b/src/util/test_connection_transmit_cancel.c
@@ -51,8 +51,7 @@ task_transmit_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
51 51
52 csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT); 52 csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT);
53 GNUNET_assert (csock != NULL); 53 GNUNET_assert (csock != NULL);
54 th = GNUNET_CONNECTION_notify_transmit_ready (csock, 54 th = GNUNET_CONNECTION_notify_transmit_ready (csock, 12,
55 12,
56 GNUNET_TIME_UNIT_MINUTES, 55 GNUNET_TIME_UNIT_MINUTES,
57 &not_run, cls); 56 &not_run, cls);
58 GNUNET_assert (NULL != th); 57 GNUNET_assert (NULL != th);
@@ -74,8 +73,8 @@ check_transmit_cancel ()
74 73
75 ok = 1; 74 ok = 1;
76 cfg = GNUNET_CONFIGURATION_create (); 75 cfg = GNUNET_CONFIGURATION_create ();
77 GNUNET_CONFIGURATION_set_value_string (cfg, 76 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
78 "resolver", "HOSTNAME", "localhost"); 77 "localhost");
79 GNUNET_SCHEDULER_run (&task_transmit_cancel, &ok); 78 GNUNET_SCHEDULER_run (&task_transmit_cancel, &ok);
80 GNUNET_CONFIGURATION_destroy (cfg); 79 GNUNET_CONFIGURATION_destroy (cfg);
81 return ok; 80 return ok;
diff --git a/src/util/test_container_bloomfilter.c b/src/util/test_container_bloomfilter.c
index 49cddac7c..c14adb075 100644
--- a/src/util/test_container_bloomfilter.c
+++ b/src/util/test_container_bloomfilter.c
@@ -127,8 +127,8 @@ main (int argc, char *argv[])
127 127
128 if (ok2 != 200) 128 if (ok2 != 200)
129 { 129 {
130 printf ("Got %d elements out of 200 " 130 printf ("Got %d elements out of 200 " "expected after initialization.\n",
131 "expected after initialization.\n", ok2); 131 ok2);
132 GNUNET_CONTAINER_bloomfilter_free (bf); 132 GNUNET_CONTAINER_bloomfilter_free (bf);
133 GNUNET_CONTAINER_bloomfilter_free (bfi); 133 GNUNET_CONTAINER_bloomfilter_free (bfi);
134 return -1; 134 return -1;
diff --git a/src/util/test_container_heap.c b/src/util/test_container_heap.c
index 7b352241c..62d675bbb 100644
--- a/src/util/test_container_heap.c
+++ b/src/util/test_container_heap.c
@@ -29,8 +29,7 @@
29#include "gnunet_container_lib.h" 29#include "gnunet_container_lib.h"
30 30
31static int 31static int
32iterator_callback (void *cls, 32iterator_callback (void *cls, struct GNUNET_CONTAINER_HeapNode *node,
33 struct GNUNET_CONTAINER_HeapNode *node,
34 void *element, GNUNET_CONTAINER_HeapCostType cost) 33 void *element, GNUNET_CONTAINER_HeapCostType cost)
35{ 34{
36 return GNUNET_OK; 35 return GNUNET_OK;
diff --git a/src/util/test_container_meta_data.c b/src/util/test_container_meta_data.c
index cee550f96..fe1dd79c1 100644
--- a/src/util/test_container_meta_data.c
+++ b/src/util/test_container_meta_data.c
@@ -41,20 +41,17 @@ testMeta (int i)
41 41
42 m = GNUNET_CONTAINER_meta_data_create (); 42 m = GNUNET_CONTAINER_meta_data_create ();
43 if (GNUNET_OK != 43 if (GNUNET_OK !=
44 GNUNET_CONTAINER_meta_data_insert (m, 44 GNUNET_CONTAINER_meta_data_insert (m, "<test>", EXTRACTOR_METATYPE_TITLE,
45 "<test>",
46 EXTRACTOR_METATYPE_TITLE,
47 EXTRACTOR_METAFORMAT_UTF8, 45 EXTRACTOR_METAFORMAT_UTF8,
48 "text/plain", 46 "text/plain", "TestTitle",
49 "TestTitle", strlen ("TestTitle") + 1)) 47 strlen ("TestTitle") + 1))
50 ABORT (m); 48 ABORT (m);
51 if (GNUNET_OK != 49 if (GNUNET_OK !=
52 GNUNET_CONTAINER_meta_data_insert (m, 50 GNUNET_CONTAINER_meta_data_insert (m, "<test>",
53 "<test>",
54 EXTRACTOR_METATYPE_AUTHOR_NAME, 51 EXTRACTOR_METATYPE_AUTHOR_NAME,
55 EXTRACTOR_METAFORMAT_UTF8, 52 EXTRACTOR_METAFORMAT_UTF8,
56 "text/plain", 53 "text/plain", "TestTitle",
57 "TestTitle", strlen ("TestTitle") + 1)) 54 strlen ("TestTitle") + 1))
58 ABORT (m); 55 ABORT (m);
59 if (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (m, "<test>", EXTRACTOR_METATYPE_TITLE, EXTRACTOR_METAFORMAT_UTF8, "text/plain", "TestTitle", strlen ("TestTitle") + 1)) /* dup! */ 56 if (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (m, "<test>", EXTRACTOR_METATYPE_TITLE, EXTRACTOR_METAFORMAT_UTF8, "text/plain", "TestTitle", strlen ("TestTitle") + 1)) /* dup! */
60 ABORT (m); 57 ABORT (m);
@@ -63,8 +60,7 @@ testMeta (int i)
63 if (2 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL)) 60 if (2 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL))
64 ABORT (m); 61 ABORT (m);
65 if (GNUNET_OK != 62 if (GNUNET_OK !=
66 GNUNET_CONTAINER_meta_data_delete (m, 63 GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_AUTHOR_NAME,
67 EXTRACTOR_METATYPE_AUTHOR_NAME,
68 "TestTitle", strlen ("TestTitle") + 1)) 64 "TestTitle", strlen ("TestTitle") + 1))
69 ABORT (m); 65 ABORT (m);
70 if (GNUNET_OK == GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_AUTHOR_NAME, "TestTitle", strlen ("TestTitle") + 1)) /* already gone */ 66 if (GNUNET_OK == GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_AUTHOR_NAME, "TestTitle", strlen ("TestTitle") + 1)) /* already gone */
@@ -72,8 +68,7 @@ testMeta (int i)
72 if (1 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL)) 68 if (1 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL))
73 ABORT (m); 69 ABORT (m);
74 if (GNUNET_OK != 70 if (GNUNET_OK !=
75 GNUNET_CONTAINER_meta_data_delete (m, 71 GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_TITLE,
76 EXTRACTOR_METATYPE_TITLE,
77 "TestTitle", strlen ("TestTitle") + 1)) 72 "TestTitle", strlen ("TestTitle") + 1))
78 ABORT (m); 73 ABORT (m);
79 if (GNUNET_OK == GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_TITLE, "TestTitle", strlen ("TestTitle") + 1)) /* already gone */ 74 if (GNUNET_OK == GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_TITLE, "TestTitle", strlen ("TestTitle") + 1)) /* already gone */
@@ -82,12 +77,10 @@ testMeta (int i)
82 ABORT (m); 77 ABORT (m);
83 for (j = 0; j < i; j++) 78 for (j = 0; j < i; j++)
84 { 79 {
85 GNUNET_snprintf (val, 80 GNUNET_snprintf (val, sizeof (val), "%s.%d",
86 sizeof (val), 81 "A teststring that should compress well.", j);
87 "%s.%d", "A teststring that should compress well.", j);
88 if (GNUNET_OK != 82 if (GNUNET_OK !=
89 GNUNET_CONTAINER_meta_data_insert (m, 83 GNUNET_CONTAINER_meta_data_insert (m, "<test>",
90 "<test>",
91 EXTRACTOR_METATYPE_UNKNOWN, 84 EXTRACTOR_METATYPE_UNKNOWN,
92 EXTRACTOR_METAFORMAT_UTF8, 85 EXTRACTOR_METAFORMAT_UTF8,
93 "text/plain", val, strlen (val) + 1)) 86 "text/plain", val, strlen (val) + 1))
@@ -98,9 +91,9 @@ testMeta (int i)
98 91
99 size = GNUNET_CONTAINER_meta_data_get_serialized_size (m); 92 size = GNUNET_CONTAINER_meta_data_get_serialized_size (m);
100 sval = NULL; 93 sval = NULL;
101 if (size != GNUNET_CONTAINER_meta_data_serialize (m, 94 if (size !=
102 &sval, size, 95 GNUNET_CONTAINER_meta_data_serialize (m, &sval, size,
103 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL)) 96 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL))
104 { 97 {
105 GNUNET_free_non_null (sval); 98 GNUNET_free_non_null (sval);
106 ABORT (m); 99 ABORT (m);
@@ -112,13 +105,11 @@ testMeta (int i)
112 ABORT (m); 105 ABORT (m);
113 for (j = 0; j < i; j++) 106 for (j = 0; j < i; j++)
114 { 107 {
115 GNUNET_snprintf (val, 108 GNUNET_snprintf (val, sizeof (val), "%s.%d",
116 sizeof (val), "%s.%d",
117 "A teststring that should compress well.", j); 109 "A teststring that should compress well.", j);
118 if (GNUNET_OK != 110 if (GNUNET_OK !=
119 GNUNET_CONTAINER_meta_data_delete (m, 111 GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_UNKNOWN, val,
120 EXTRACTOR_METATYPE_UNKNOWN, 112 strlen (val) + 1))
121 val, strlen (val) + 1))
122 { 113 {
123 ABORT (m); 114 ABORT (m);
124 } 115 }
@@ -142,17 +133,16 @@ testMetaMore (int i)
142 for (q = 0; q <= i; q++) 133 for (q = 0; q <= i; q++)
143 { 134 {
144 GNUNET_snprintf (txt, 128, "%u -- %u\n", i, q); 135 GNUNET_snprintf (txt, 128, "%u -- %u\n", i, q);
145 GNUNET_CONTAINER_meta_data_insert (meta, 136 GNUNET_CONTAINER_meta_data_insert (meta, "<test>",
146 "<test>",
147 q % EXTRACTOR_metatype_get_max (), 137 q % EXTRACTOR_metatype_get_max (),
148 EXTRACTOR_METAFORMAT_UTF8, 138 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
149 "text/plain", txt, strlen (txt) + 1); 139 txt, strlen (txt) + 1);
150 } 140 }
151 size = GNUNET_CONTAINER_meta_data_get_serialized_size (meta); 141 size = GNUNET_CONTAINER_meta_data_get_serialized_size (meta);
152 data = GNUNET_malloc (size * 4); 142 data = GNUNET_malloc (size * 4);
153 if (size != GNUNET_CONTAINER_meta_data_serialize (meta, 143 if (size !=
154 &data, size * 4, 144 GNUNET_CONTAINER_meta_data_serialize (meta, &data, size * 4,
155 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL)) 145 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL))
156 { 146 {
157 GNUNET_free (data); 147 GNUNET_free (data);
158 ABORT (meta); 148 ABORT (meta);
@@ -171,25 +161,23 @@ testMetaLink ()
171 161
172 m = GNUNET_CONTAINER_meta_data_create (); 162 m = GNUNET_CONTAINER_meta_data_create ();
173 if (GNUNET_OK != 163 if (GNUNET_OK !=
174 GNUNET_CONTAINER_meta_data_insert (m, 164 GNUNET_CONTAINER_meta_data_insert (m, "<test>",
175 "<test>",
176 EXTRACTOR_METATYPE_UNKNOWN, 165 EXTRACTOR_METATYPE_UNKNOWN,
177 EXTRACTOR_METAFORMAT_UTF8, 166 EXTRACTOR_METAFORMAT_UTF8,
178 "text/plain", 167 "text/plain", "link",
179 "link", strlen ("link") + 1)) 168 strlen ("link") + 1))
180 ABORT (m); 169 ABORT (m);
181 if (GNUNET_OK != 170 if (GNUNET_OK !=
182 GNUNET_CONTAINER_meta_data_insert (m, 171 GNUNET_CONTAINER_meta_data_insert (m, "<test>",
183 "<test>",
184 EXTRACTOR_METATYPE_FILENAME, 172 EXTRACTOR_METATYPE_FILENAME,
185 EXTRACTOR_METAFORMAT_UTF8, 173 EXTRACTOR_METAFORMAT_UTF8,
186 "text/plain", 174 "text/plain", "lib-link.m4",
187 "lib-link.m4",
188 strlen ("lib-link.m4") + 1)) 175 strlen ("lib-link.m4") + 1))
189 ABORT (m); 176 ABORT (m);
190 val = NULL; 177 val = NULL;
191 size = GNUNET_CONTAINER_meta_data_serialize (m, &val, (size_t) - 1, 178 size =
192 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL); 179 GNUNET_CONTAINER_meta_data_serialize (m, &val, (size_t) - 1,
180 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL);
193 GNUNET_CONTAINER_meta_data_destroy (m); 181 GNUNET_CONTAINER_meta_data_destroy (m);
194 m = GNUNET_CONTAINER_meta_data_deserialize (val, size); 182 m = GNUNET_CONTAINER_meta_data_deserialize (val, size);
195 GNUNET_free (val); 183 GNUNET_free (val);
@@ -215,17 +203,13 @@ check ()
215 for (q = 0; q <= i; q++) 203 for (q = 0; q <= i; q++)
216 { 204 {
217 GNUNET_snprintf (txt, 128, "%u -- %u\n", i, q); 205 GNUNET_snprintf (txt, 128, "%u -- %u\n", i, q);
218 GNUNET_CONTAINER_meta_data_insert (meta, 206 GNUNET_CONTAINER_meta_data_insert (meta, "<test>",
219 "<test>",
220 EXTRACTOR_METATYPE_UNKNOWN, 207 EXTRACTOR_METATYPE_UNKNOWN,
221 EXTRACTOR_METAFORMAT_UTF8, 208 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
222 "text/plain",
223 "TestTitle", strlen ("TestTitle") + 1); 209 "TestTitle", strlen ("TestTitle") + 1);
224 GNUNET_CONTAINER_meta_data_insert (meta2, 210 GNUNET_CONTAINER_meta_data_insert (meta2, "<test>",
225 "<test>",
226 EXTRACTOR_METATYPE_UNKNOWN, 211 EXTRACTOR_METATYPE_UNKNOWN,
227 EXTRACTOR_METAFORMAT_UTF8, 212 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
228 "text/plain",
229 "TestTitle", strlen ("TestTitle") + 1); 213 "TestTitle", strlen ("TestTitle") + 1);
230 } 214 }
231 215
@@ -303,9 +287,10 @@ check ()
303 } 287 }
304 288
305 //check meta_data_get_first_by_types 289 //check meta_data_get_first_by_types
306 str = GNUNET_CONTAINER_meta_data_get_first_by_types (meta, 290 str =
307 EXTRACTOR_METATYPE_UNKNOWN, 291 GNUNET_CONTAINER_meta_data_get_first_by_types (meta,
308 -1); 292 EXTRACTOR_METATYPE_UNKNOWN,
293 -1);
309 GNUNET_assert (NULL != str); 294 GNUNET_assert (NULL != str);
310 if (str[0] != 'T') 295 if (str[0] != 'T')
311 { 296 {
diff --git a/src/util/test_container_multihashmap.c b/src/util/test_container_multihashmap.c
index c16b2df22..ba621c17e 100644
--- a/src/util/test_container_multihashmap.c
+++ b/src/util/test_container_multihashmap.c
@@ -54,27 +54,23 @@ testMap (int i)
54 CHECK (0 == GNUNET_CONTAINER_multihashmap_iterate (m, NULL, NULL)); 54 CHECK (0 == GNUNET_CONTAINER_multihashmap_iterate (m, NULL, NULL));
55 CHECK (0 == GNUNET_CONTAINER_multihashmap_get_multiple (m, &k1, NULL, NULL)); 55 CHECK (0 == GNUNET_CONTAINER_multihashmap_get_multiple (m, &k1, NULL, NULL));
56 56
57 CHECK (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (m, 57 CHECK (GNUNET_OK ==
58 &k1, 58 GNUNET_CONTAINER_multihashmap_put (m, &k1, "v1",
59 "v1", 59 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
60 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
61 CHECK (1 == GNUNET_CONTAINER_multihashmap_size (m)); 60 CHECK (1 == GNUNET_CONTAINER_multihashmap_size (m));
62 ret = GNUNET_CONTAINER_multihashmap_get (m, &k1); 61 ret = GNUNET_CONTAINER_multihashmap_get (m, &k1);
63 GNUNET_assert (ret != NULL); 62 GNUNET_assert (ret != NULL);
64 CHECK (0 == strcmp ("v1", ret)); 63 CHECK (0 == strcmp ("v1", ret));
65 CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap_put (m, 64 CHECK (GNUNET_NO ==
66 &k1, 65 GNUNET_CONTAINER_multihashmap_put (m, &k1, "v1",
67 "v1", 66 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
68 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
69 CHECK (1 == GNUNET_CONTAINER_multihashmap_size (m)); 67 CHECK (1 == GNUNET_CONTAINER_multihashmap_size (m));
70 CHECK (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (m, 68 CHECK (GNUNET_OK ==
71 &k1, 69 GNUNET_CONTAINER_multihashmap_put (m, &k1, "v2",
72 "v2", 70 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
73 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 71 CHECK (GNUNET_OK ==
74 CHECK (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (m, 72 GNUNET_CONTAINER_multihashmap_put (m, &k1, "v3",
75 &k1, 73 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
76 "v3",
77 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
78 CHECK (3 == GNUNET_CONTAINER_multihashmap_size (m)); 74 CHECK (3 == GNUNET_CONTAINER_multihashmap_size (m));
79 CHECK (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (m, &k1, "v3")); 75 CHECK (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (m, &k1, "v3"));
80 CHECK (2 == GNUNET_CONTAINER_multihashmap_size (m)); 76 CHECK (2 == GNUNET_CONTAINER_multihashmap_size (m));
@@ -85,10 +81,9 @@ testMap (int i)
85 CHECK (2 == GNUNET_CONTAINER_multihashmap_iterate (m, NULL, NULL)); 81 CHECK (2 == GNUNET_CONTAINER_multihashmap_iterate (m, NULL, NULL));
86 CHECK (2 == GNUNET_CONTAINER_multihashmap_remove_all (m, &k1)); 82 CHECK (2 == GNUNET_CONTAINER_multihashmap_remove_all (m, &k1));
87 for (j = 0; j < 1024; j++) 83 for (j = 0; j < 1024; j++)
88 CHECK (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (m, 84 CHECK (GNUNET_OK ==
89 &k1, 85 GNUNET_CONTAINER_multihashmap_put (m, &k1, "v2",
90 "v2", 86 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
91 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
92 GNUNET_CONTAINER_multihashmap_destroy (m); 87 GNUNET_CONTAINER_multihashmap_destroy (m);
93 return 0; 88 return 0;
94} 89}
diff --git a/src/util/test_container_slist.c b/src/util/test_container_slist.c
index 13c12bc5a..4a277dab5 100644
--- a/src/util/test_container_slist.c
+++ b/src/util/test_container_slist.c
@@ -46,8 +46,7 @@ main (int argc, char *argv[])
46 GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 0); 46 GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 0);
47 47
48 for (i = 0; i < 100; i++) 48 for (i = 0; i < 100; i++)
49 GNUNET_CONTAINER_slist_add (l, 49 GNUNET_CONTAINER_slist_add (l, GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
50 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
51 &i, sizeof (i)); 50 &i, sizeof (i));
52 GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 100); 51 GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 100);
53 52
@@ -105,8 +104,7 @@ main (int argc, char *argv[])
105 GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 0); 104 GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 0);
106 105
107 for (i = 0; i < 100; i++) 106 for (i = 0; i < 100; i++)
108 GNUNET_CONTAINER_slist_add (l, 107 GNUNET_CONTAINER_slist_add (l, GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
109 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
110 &i, sizeof (i)); 108 &i, sizeof (i));
111 /*check slist_append */ 109 /*check slist_append */
112 GNUNET_CONTAINER_slist_append (l, l); 110 GNUNET_CONTAINER_slist_append (l, l);
@@ -145,8 +143,7 @@ main (int argc, char *argv[])
145 { 143 {
146 ip = GNUNET_malloc (sizeof (int)); 144 ip = GNUNET_malloc (sizeof (int));
147 *ip = i; 145 *ip = i;
148 GNUNET_CONTAINER_slist_add (l, 146 GNUNET_CONTAINER_slist_add (l, GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC,
149 GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC,
150 ip, sizeof (int)); 147 ip, sizeof (int));
151 } 148 }
152 //creat_add 149 //creat_add
diff --git a/src/util/test_crypto_aes.c b/src/util/test_crypto_aes.c
index 968c7f40f..971e9afbe 100644
--- a/src/util/test_crypto_aes.c
+++ b/src/util/test_crypto_aes.c
@@ -39,22 +39,21 @@ testSymcipher ()
39 char res[100]; 39 char res[100];
40 40
41 GNUNET_CRYPTO_aes_create_session_key (&key); 41 GNUNET_CRYPTO_aes_create_session_key (&key);
42 size = GNUNET_CRYPTO_aes_encrypt (TESTSTRING, 42 size =
43 strlen (TESTSTRING) + 1, 43 GNUNET_CRYPTO_aes_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, &key,
44 &key, 44 (const struct
45 (const struct 45 GNUNET_CRYPTO_AesInitializationVector *)
46 GNUNET_CRYPTO_AesInitializationVector *) 46 INITVALUE, result);
47 INITVALUE, result);
48 if (size == -1) 47 if (size == -1)
49 { 48 {
50 printf ("symciphertest failed: encryptBlock returned %d\n", size); 49 printf ("symciphertest failed: encryptBlock returned %d\n", size);
51 return 1; 50 return 1;
52 } 51 }
53 size = GNUNET_CRYPTO_aes_decrypt (result, size, 52 size =
54 &key, 53 GNUNET_CRYPTO_aes_decrypt (result, size, &key,
55 (const struct 54 (const struct
56 GNUNET_CRYPTO_AesInitializationVector *) 55 GNUNET_CRYPTO_AesInitializationVector *)
57 INITVALUE, res); 56 INITVALUE, res);
58 if (strlen (TESTSTRING) + 1 != size) 57 if (strlen (TESTSTRING) + 1 != size)
59 { 58 {
60 printf ("symciphertest failed: decryptBlock returned %d\n", size); 59 printf ("symciphertest failed: decryptBlock returned %d\n", size);
@@ -101,17 +100,15 @@ verifyCrypto ()
101 100
102 if (ntohl (key.crc32) != (unsigned int) 38125195LL) 101 if (ntohl (key.crc32) != (unsigned int) 38125195LL)
103 { 102 {
104 printf ("Static key has different CRC: %u - %u\n", 103 printf ("Static key has different CRC: %u - %u\n", ntohl (key.crc32),
105 ntohl (key.crc32), key.crc32); 104 key.crc32);
106 105
107 ret = 1; 106 ret = 1;
108 goto error; 107 goto error;
109 } 108 }
110 109
111 if (GNUNET_CRYPTO_AES_KEY_LENGTH != 110 if (GNUNET_CRYPTO_AES_KEY_LENGTH !=
112 GNUNET_CRYPTO_aes_encrypt (plain, 111 GNUNET_CRYPTO_aes_encrypt (plain, GNUNET_CRYPTO_AES_KEY_LENGTH, &key,
113 GNUNET_CRYPTO_AES_KEY_LENGTH,
114 &key,
115 (const struct 112 (const struct
116 GNUNET_CRYPTO_AesInitializationVector *) 113 GNUNET_CRYPTO_AesInitializationVector *)
117 "testtesttesttest", result)) 114 "testtesttesttest", result))
@@ -131,9 +128,7 @@ verifyCrypto ()
131 res = GNUNET_malloc (GNUNET_CRYPTO_AES_KEY_LENGTH); 128 res = GNUNET_malloc (GNUNET_CRYPTO_AES_KEY_LENGTH);
132 129
133 if (GNUNET_CRYPTO_AES_KEY_LENGTH != 130 if (GNUNET_CRYPTO_AES_KEY_LENGTH !=
134 GNUNET_CRYPTO_aes_decrypt (result, 131 GNUNET_CRYPTO_aes_decrypt (result, GNUNET_CRYPTO_AES_KEY_LENGTH, &key,
135 GNUNET_CRYPTO_AES_KEY_LENGTH,
136 &key,
137 (const struct 132 (const struct
138 GNUNET_CRYPTO_AesInitializationVector *) 133 GNUNET_CRYPTO_AesInitializationVector *)
139 "testtesttesttest", res)) 134 "testtesttesttest", res))
diff --git a/src/util/test_crypto_aes_weak.c b/src/util/test_crypto_aes_weak.c
index f54835b3d..a0161b575 100644
--- a/src/util/test_crypto_aes_weak.c
+++ b/src/util/test_crypto_aes_weak.c
@@ -94,9 +94,10 @@ testWeakKey ()
94 weak_key.crc32 = 94 weak_key.crc32 =
95 htonl (GNUNET_CRYPTO_crc32_n (&weak_key, GNUNET_CRYPTO_AES_KEY_LENGTH)); 95 htonl (GNUNET_CRYPTO_crc32_n (&weak_key, GNUNET_CRYPTO_AES_KEY_LENGTH));
96 96
97 size = GNUNET_CRYPTO_aes_encrypt (WEAK_KEY_TESTSTRING, 97 size =
98 strlen (WEAK_KEY_TESTSTRING) + 1, 98 GNUNET_CRYPTO_aes_encrypt (WEAK_KEY_TESTSTRING,
99 &weak_key, &INITVALUE, result); 99 strlen (WEAK_KEY_TESTSTRING) + 1, &weak_key,
100 &INITVALUE, result);
100 101
101 if (size == -1) 102 if (size == -1)
102 { 103 {
@@ -139,8 +140,8 @@ getWeakKeys ()
139 /*printf("Got to run number %d.\n", number_of_runs); */ 140 /*printf("Got to run number %d.\n", number_of_runs); */
140 GNUNET_CRYPTO_aes_create_session_key (&sessionkey); 141 GNUNET_CRYPTO_aes_create_session_key (&sessionkey);
141 142
142 rc = gcry_cipher_open (&handle, 143 rc = gcry_cipher_open (&handle, GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CFB,
143 GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CFB, 0); 144 0);
144 145
145 if (rc) 146 if (rc)
146 { 147 {
@@ -188,8 +189,8 @@ main (int argc, char *argv[])
188 } 189 }
189 else 190 else
190 { 191 {
191 printf ("\n%d weak keys found in %d runs.\n", 192 printf ("\n%d weak keys found in %d runs.\n", weak_keys,
192 weak_keys, MAX_WEAK_KEY_TRIALS); 193 MAX_WEAK_KEY_TRIALS);
193 } 194 }
194 } 195 }
195 196
diff --git a/src/util/test_crypto_hkdf.c b/src/util/test_crypto_hkdf.c
index a9b742922..752116194 100644
--- a/src/util/test_crypto_hkdf.c
+++ b/src/util/test_crypto_hkdf.c
@@ -43,8 +43,8 @@ tc1 ()
43 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 43 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
44 0x0a, 0x0b, 0x0c 44 0x0a, 0x0b, 0x0c
45 }; 45 };
46 unsigned char 46 unsigned char info[10] =
47 info[10] = { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 }; 47 { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 };
48 unsigned char okm[42] = 48 unsigned char okm[42] =
49 { 0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a, 0x90, 0x43, 49 { 0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a, 0x90, 0x43,
50 0x4f, 0x64, 0xd0, 0x36, 0x2f, 0x2a, 0x2d, 0x2d, 0x0a, 0x90, 0xcf, 0x1a, 50 0x4f, 0x64, 0xd0, 0x36, 0x2f, 0x2a, 0x2d, 0x2d, 0x0a, 0x90, 0xcf, 0x1a,
@@ -149,8 +149,8 @@ tc4 ()
149 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 149 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
150 0x0a, 0x0b, 0x0c 150 0x0a, 0x0b, 0x0c
151 }; 151 };
152 unsigned char 152 unsigned char info[10] =
153 info[10] = { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 }; 153 { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 };
154 unsigned char okm[42] = 154 unsigned char okm[42] =
155 { 0x08, 0x5a, 0x01, 0xea, 0x1b, 0x10, 0xf3, 0x69, 0x33, 0x06, 155 { 0x08, 0x5a, 0x01, 0xea, 0x1b, 0x10, 0xf3, 0x69, 0x33, 0x06,
156 0x8b, 0x56, 0xef, 0xa5, 0xad, 0x81, 0xa4, 0xf1, 0x4b, 0x82, 0x2f, 0x5b, 156 0x8b, 0x56, 0xef, 0xa5, 0xad, 0x81, 0xa4, 0xf1, 0x4b, 0x82, 0x2f, 0x5b,
diff --git a/src/util/test_crypto_ksk.c b/src/util/test_crypto_ksk.c
index 184f9f137..d4340f3ea 100644
--- a/src/util/test_crypto_ksk.c
+++ b/src/util/test_crypto_ksk.c
@@ -66,9 +66,8 @@ testCorrectKey ()
66 snprintf (out, sizeof (out), "%02x", ((unsigned char *) &pkey)[i]); 66 snprintf (out, sizeof (out), "%02x", ((unsigned char *) &pkey)[i]);
67 if (0 != strncmp (out, &want[i * 2], 2)) 67 if (0 != strncmp (out, &want[i * 2], 2))
68 { 68 {
69 fprintf (stderr, 69 fprintf (stderr, " Failed! Wanted %.2s but got %2s at %d\n", &want[i * 2],
70 " Failed! Wanted %.2s but got %2s at %d\n", 70 out, i);
71 &want[i * 2], out, i);
72 return GNUNET_SYSERR; 71 return GNUNET_SYSERR;
73 } 72 }
74 } 73 }
@@ -144,17 +143,17 @@ testEncryptDecrypt (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey)
144 for (i = 0; i < ITER; i++) 143 for (i = 0; i < ITER; i++)
145 { 144 {
146 fprintf (stderr, "."); 145 fprintf (stderr, ".");
147 if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, 146 if (GNUNET_SYSERR ==
148 strlen (TESTSTRING) + 1, 147 GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, &pkey,
149 &pkey, &target)) 148 &target))
150 { 149 {
151 fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n"); 150 fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n");
152 ok++; 151 ok++;
153 continue; 152 continue;
154 } 153 }
155 if (-1 == GNUNET_CRYPTO_rsa_decrypt (hostkey, 154 if (-1 ==
156 &target, result, 155 GNUNET_CRYPTO_rsa_decrypt (hostkey, &target, result,
157 strlen (TESTSTRING) + 1)) 156 strlen (TESTSTRING) + 1))
158 { 157 {
159 fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n"); 158 fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n");
160 ok++; 159 ok++;
@@ -162,16 +161,15 @@ testEncryptDecrypt (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey)
162 } 161 }
163 if (strncmp (TESTSTRING, result, strlen (TESTSTRING)) != 0) 162 if (strncmp (TESTSTRING, result, strlen (TESTSTRING)) != 0)
164 { 163 {
165 printf ("%s != %.*s - testEncryptDecrypt failed!\n", 164 printf ("%s != %.*s - testEncryptDecrypt failed!\n", TESTSTRING,
166 TESTSTRING, MAX_TESTVAL, result); 165 MAX_TESTVAL, result);
167 ok++; 166 ok++;
168 continue; 167 continue;
169 } 168 }
170 } 169 }
171 printf ("%d RSA encrypt/decrypt operations %llums (%d failures)\n", 170 printf ("%d RSA encrypt/decrypt operations %llums (%d failures)\n", ITER,
172 ITER, 171 (unsigned long long) GNUNET_TIME_absolute_get_duration (start).
173 (unsigned long long) 172 rel_value, ok);
174 GNUNET_TIME_absolute_get_duration (start).rel_value, ok);
175 if (ok == 0) 173 if (ok == 0)
176 return GNUNET_OK; 174 return GNUNET_OK;
177 else 175 else
@@ -203,26 +201,25 @@ testSignVerify (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey)
203 continue; 201 continue;
204 } 202 }
205 if (GNUNET_SYSERR == 203 if (GNUNET_SYSERR ==
206 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TEST, 204 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TEST, &purp, &sig,
207 &purp, &sig, &pkey)) 205 &pkey))
208 { 206 {
209 printf ("GNUNET_CRYPTO_rsa_verify failed!\n"); 207 printf ("GNUNET_CRYPTO_rsa_verify failed!\n");
210 ok = GNUNET_SYSERR; 208 ok = GNUNET_SYSERR;
211 continue; 209 continue;
212 } 210 }
213 if (GNUNET_SYSERR != 211 if (GNUNET_SYSERR !=
214 GNUNET_CRYPTO_rsa_verify 212 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
215 (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, &purp, &sig, &pkey)) 213 &purp, &sig, &pkey))
216 { 214 {
217 printf ("GNUNET_CRYPTO_rsa_verify failed to fail!\n"); 215 printf ("GNUNET_CRYPTO_rsa_verify failed to fail!\n");
218 ok = GNUNET_SYSERR; 216 ok = GNUNET_SYSERR;
219 continue; 217 continue;
220 } 218 }
221 } 219 }
222 printf ("%d RSA sign/verify operations %llums\n", 220 printf ("%d RSA sign/verify operations %llums\n", ITER,
223 ITER, 221 (unsigned long long) GNUNET_TIME_absolute_get_duration (start).
224 (unsigned long long) 222 rel_value);
225 GNUNET_TIME_absolute_get_duration (start).rel_value);
226 return ok; 223 return ok;
227} 224}
228 225
diff --git a/src/util/test_crypto_rsa.c b/src/util/test_crypto_rsa.c
index d7c23731e..bf058d285 100644
--- a/src/util/test_crypto_rsa.c
+++ b/src/util/test_crypto_rsa.c
@@ -56,17 +56,17 @@ testEncryptDecrypt ()
56 for (i = 0; i < ITER; i++) 56 for (i = 0; i < ITER; i++)
57 { 57 {
58 fprintf (stderr, "."); 58 fprintf (stderr, ".");
59 if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, 59 if (GNUNET_SYSERR ==
60 strlen (TESTSTRING) + 1, 60 GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, &pkey,
61 &pkey, &target)) 61 &target))
62 { 62 {
63 fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n"); 63 fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n");
64 ok++; 64 ok++;
65 continue; 65 continue;
66 } 66 }
67 if (-1 == GNUNET_CRYPTO_rsa_decrypt (hostkey, 67 if (-1 ==
68 &target, result, 68 GNUNET_CRYPTO_rsa_decrypt (hostkey, &target, result,
69 strlen (TESTSTRING) + 1)) 69 strlen (TESTSTRING) + 1))
70 { 70 {
71 fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n"); 71 fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n");
72 ok++; 72 ok++;
@@ -75,16 +75,15 @@ testEncryptDecrypt ()
75 } 75 }
76 if (strncmp (TESTSTRING, result, strlen (TESTSTRING)) != 0) 76 if (strncmp (TESTSTRING, result, strlen (TESTSTRING)) != 0)
77 { 77 {
78 printf ("%s != %.*s - testEncryptDecrypt failed!\n", 78 printf ("%s != %.*s - testEncryptDecrypt failed!\n", TESTSTRING,
79 TESTSTRING, (int) MAX_TESTVAL, result); 79 (int) MAX_TESTVAL, result);
80 ok++; 80 ok++;
81 continue; 81 continue;
82 } 82 }
83 } 83 }
84 printf ("%d RSA encrypt/decrypt operations %llums (%d failures)\n", 84 printf ("%d RSA encrypt/decrypt operations %llums (%d failures)\n", ITER,
85 ITER, 85 (unsigned long long) GNUNET_TIME_absolute_get_duration (start).
86 (unsigned long long) 86 rel_value, ok);
87 GNUNET_TIME_absolute_get_duration (start).rel_value, ok);
88 GNUNET_CRYPTO_rsa_key_free (hostkey); 87 GNUNET_CRYPTO_rsa_key_free (hostkey);
89 if (ok == 0) 88 if (ok == 0)
90 return GNUNET_OK; 89 return GNUNET_OK;
@@ -112,19 +111,18 @@ testEncryptPerformance ()
112 for (i = 0; i < ITER; i++) 111 for (i = 0; i < ITER; i++)
113 { 112 {
114 fprintf (stderr, "."); 113 fprintf (stderr, ".");
115 if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, 114 if (GNUNET_SYSERR ==
116 strlen (TESTSTRING) + 1, 115 GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, &pkey,
117 &pkey, &target)) 116 &target))
118 { 117 {
119 fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n"); 118 fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n");
120 ok++; 119 ok++;
121 continue; 120 continue;
122 } 121 }
123 } 122 }
124 printf ("%d RSA encrypt operations %llu ms (%d failures)\n", 123 printf ("%d RSA encrypt operations %llu ms (%d failures)\n", ITER,
125 ITER, 124 (unsigned long long) GNUNET_TIME_absolute_get_duration (start).
126 (unsigned long long) 125 rel_value, ok);
127 GNUNET_TIME_absolute_get_duration (start).rel_value, ok);
128 GNUNET_CRYPTO_rsa_key_free (hostkey); 126 GNUNET_CRYPTO_rsa_key_free (hostkey);
129 if (ok != 0) 127 if (ok != 0)
130 return GNUNET_SYSERR; 128 return GNUNET_SYSERR;
@@ -154,19 +152,18 @@ testEncryptDecryptSK ()
154 { 152 {
155 fprintf (stderr, "."); 153 fprintf (stderr, ".");
156 GNUNET_CRYPTO_aes_create_session_key (&insk); 154 GNUNET_CRYPTO_aes_create_session_key (&insk);
157 if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_encrypt (&insk, 155 if (GNUNET_SYSERR ==
158 sizeof (struct 156 GNUNET_CRYPTO_rsa_encrypt (&insk,
159 GNUNET_CRYPTO_AesSessionKey), 157 sizeof (struct GNUNET_CRYPTO_AesSessionKey),
160 &pkey, &target)) 158 &pkey, &target))
161 { 159 {
162 fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n"); 160 fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n");
163 ok++; 161 ok++;
164 continue; 162 continue;
165 } 163 }
166 if (-1 == GNUNET_CRYPTO_rsa_decrypt (hostkey, 164 if (-1 ==
167 &target, &outsk, 165 GNUNET_CRYPTO_rsa_decrypt (hostkey, &target, &outsk,
168 sizeof (struct 166 sizeof (struct GNUNET_CRYPTO_AesSessionKey)))
169 GNUNET_CRYPTO_AesSessionKey)))
170 { 167 {
171 fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n"); 168 fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n");
172 ok++; 169 ok++;
@@ -180,10 +177,9 @@ testEncryptDecryptSK ()
180 continue; 177 continue;
181 } 178 }
182 } 179 }
183 printf ("%d RSA encrypt/decrypt SK operations %llums (%d failures)\n", 180 printf ("%d RSA encrypt/decrypt SK operations %llums (%d failures)\n", ITER,
184 ITER, 181 (unsigned long long) GNUNET_TIME_absolute_get_duration (start).
185 (unsigned long long) 182 rel_value, ok);
186 GNUNET_TIME_absolute_get_duration (start).rel_value, ok);
187 GNUNET_CRYPTO_rsa_key_free (hostkey); 183 GNUNET_CRYPTO_rsa_key_free (hostkey);
188 if (ok != 0) 184 if (ok != 0)
189 return GNUNET_SYSERR; 185 return GNUNET_SYSERR;
@@ -219,26 +215,25 @@ testSignVerify ()
219 continue; 215 continue;
220 } 216 }
221 if (GNUNET_SYSERR == 217 if (GNUNET_SYSERR ==
222 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TEST, 218 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TEST, &purp, &sig,
223 &purp, &sig, &pkey)) 219 &pkey))
224 { 220 {
225 printf ("GNUNET_CRYPTO_rsa_verify failed!\n"); 221 printf ("GNUNET_CRYPTO_rsa_verify failed!\n");
226 ok = GNUNET_SYSERR; 222 ok = GNUNET_SYSERR;
227 continue; 223 continue;
228 } 224 }
229 if (GNUNET_SYSERR != 225 if (GNUNET_SYSERR !=
230 GNUNET_CRYPTO_rsa_verify 226 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
231 (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, &purp, &sig, &pkey)) 227 &purp, &sig, &pkey))
232 { 228 {
233 printf ("GNUNET_CRYPTO_rsa_verify failed to fail!\n"); 229 printf ("GNUNET_CRYPTO_rsa_verify failed to fail!\n");
234 ok = GNUNET_SYSERR; 230 ok = GNUNET_SYSERR;
235 continue; 231 continue;
236 } 232 }
237 } 233 }
238 printf ("%d RSA sign/verify operations %llums\n", 234 printf ("%d RSA sign/verify operations %llums\n", ITER,
239 ITER, 235 (unsigned long long) GNUNET_TIME_absolute_get_duration (start).
240 (unsigned long long) 236 rel_value);
241 GNUNET_TIME_absolute_get_duration (start).rel_value);
242 GNUNET_CRYPTO_rsa_key_free (hostkey); 237 GNUNET_CRYPTO_rsa_key_free (hostkey);
243 return ok; 238 return ok;
244} 239}
@@ -273,8 +268,8 @@ testSignPerformance ()
273 } 268 }
274 } 269 }
275 printf ("%d RSA sign operations %llu ms\n", ITER, 270 printf ("%d RSA sign operations %llu ms\n", ITER,
276 (unsigned long long) 271 (unsigned long long) GNUNET_TIME_absolute_get_duration (start).
277 GNUNET_TIME_absolute_get_duration (start).rel_value); 272 rel_value);
278 GNUNET_CRYPTO_rsa_key_free (hostkey); 273 GNUNET_CRYPTO_rsa_key_free (hostkey);
279 return ok; 274 return ok;
280} 275}
diff --git a/src/util/test_disk.c b/src/util/test_disk.c
index d8d8021e5..91154a6f5 100644
--- a/src/util/test_disk.c
+++ b/src/util/test_disk.c
@@ -37,8 +37,7 @@ testReadWrite ()
37 int ret; 37 int ret;
38 38
39 if (strlen (TESTSTRING) != 39 if (strlen (TESTSTRING) !=
40 GNUNET_DISK_fn_write (".testfile", TESTSTRING, 40 GNUNET_DISK_fn_write (".testfile", TESTSTRING, strlen (TESTSTRING),
41 strlen (TESTSTRING),
42 GNUNET_DISK_PERM_USER_READ | 41 GNUNET_DISK_PERM_USER_READ |
43 GNUNET_DISK_PERM_USER_WRITE)) 42 GNUNET_DISK_PERM_USER_WRITE))
44 return 1; 43 return 1;
@@ -53,9 +52,8 @@ testReadWrite ()
53 tmp[ret] = '\0'; 52 tmp[ret] = '\0';
54 if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1)) 53 if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1))
55 { 54 {
56 fprintf (stderr, 55 fprintf (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", tmp,
57 "Error in testReadWrite: *%s* != *%s* for file %s\n", 56 TESTSTRING, ".testfile");
58 tmp, TESTSTRING, ".testfile");
59 return 1; 57 return 1;
60 } 58 }
61 GNUNET_DISK_file_copy (".testfile", ".testfile2"); 59 GNUNET_DISK_file_copy (".testfile", ".testfile2");
@@ -63,16 +61,15 @@ testReadWrite ()
63 ret = GNUNET_DISK_fn_read (".testfile2", tmp, sizeof (tmp) - 1); 61 ret = GNUNET_DISK_fn_read (".testfile2", tmp, sizeof (tmp) - 1);
64 if (ret < 0) 62 if (ret < 0)
65 { 63 {
66 fprintf (stderr, 64 fprintf (stderr, "Error reading file `%s' in testReadWrite\n",
67 "Error reading file `%s' in testReadWrite\n", ".testfile2"); 65 ".testfile2");
68 return 1; 66 return 1;
69 } 67 }
70 tmp[ret] = '\0'; 68 tmp[ret] = '\0';
71 if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1)) 69 if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1))
72 { 70 {
73 fprintf (stderr, 71 fprintf (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", tmp,
74 "Error in testReadWrite: *%s* != *%s* for file %s\n", 72 TESTSTRING, ".testfile2");
75 tmp, TESTSTRING, ".testfile2");
76 return 1; 73 return 1;
77 } 74 }
78 75
@@ -91,8 +88,9 @@ testOpenClose ()
91 uint64_t size; 88 uint64_t size;
92 long avail; 89 long avail;
93 90
94 fh = GNUNET_DISK_file_open (".testfile", GNUNET_DISK_OPEN_READWRITE 91 fh = GNUNET_DISK_file_open (".testfile",
95 | GNUNET_DISK_OPEN_CREATE, 92 GNUNET_DISK_OPEN_READWRITE |
93 GNUNET_DISK_OPEN_CREATE,
96 GNUNET_DISK_PERM_USER_READ | 94 GNUNET_DISK_PERM_USER_READ |
97 GNUNET_DISK_PERM_USER_WRITE); 95 GNUNET_DISK_PERM_USER_WRITE);
98 GNUNET_assert (GNUNET_NO == GNUNET_DISK_handle_invalid (fh)); 96 GNUNET_assert (GNUNET_NO == GNUNET_DISK_handle_invalid (fh));
@@ -108,8 +106,9 @@ testOpenClose ()
108 GNUNET_log_skip (1, GNUNET_NO); 106 GNUNET_log_skip (1, GNUNET_NO);
109 avail = GNUNET_DISK_get_blocks_available (".testfile"); 107 avail = GNUNET_DISK_get_blocks_available (".testfile");
110 GNUNET_log_skip (0, GNUNET_NO); 108 GNUNET_log_skip (0, GNUNET_NO);
111 fh = GNUNET_DISK_file_open (".testfile", GNUNET_DISK_OPEN_READWRITE 109 fh = GNUNET_DISK_file_open (".testfile",
112 | GNUNET_DISK_OPEN_CREATE, 110 GNUNET_DISK_OPEN_READWRITE |
111 GNUNET_DISK_OPEN_CREATE,
113 GNUNET_DISK_PERM_USER_WRITE | 112 GNUNET_DISK_PERM_USER_WRITE |
114 GNUNET_DISK_PERM_USER_READ); 113 GNUNET_DISK_PERM_USER_READ);
115 GNUNET_assert (GNUNET_NO == GNUNET_DISK_handle_invalid (fh)); 114 GNUNET_assert (GNUNET_NO == GNUNET_DISK_handle_invalid (fh));
@@ -156,8 +155,7 @@ testDirScan ()
156} 155}
157 156
158static void 157static void
159iter_callback (void *cls, 158iter_callback (void *cls, struct GNUNET_DISK_DirectoryIterator *di,
160 struct GNUNET_DISK_DirectoryIterator *di,
161 const char *filename, const char *dirname) 159 const char *filename, const char *dirname)
162{ 160{
163 int *i = cls; 161 int *i = cls;
diff --git a/src/util/test_os_network.c b/src/util/test_os_network.c
index e92eba2c9..583a5fb82 100644
--- a/src/util/test_os_network.c
+++ b/src/util/test_os_network.c
@@ -34,9 +34,8 @@
34 * (success). 34 * (success).
35 */ 35 */
36static int 36static int
37proc (void *cls, 37proc (void *cls, const char *name, int isDefault, const struct sockaddr *addr,
38 const char *name, 38 socklen_t addrlen)
39 int isDefault, const struct sockaddr *addr, socklen_t addrlen)
40{ 39{
41 int *ok = cls; 40 int *ok = cls;
42 char buf[INET6_ADDRSTRLEN]; 41 char buf[INET6_ADDRSTRLEN];
@@ -45,9 +44,9 @@ proc (void *cls,
45 return GNUNET_OK; 44 return GNUNET_OK;
46 45
47 inet_ntop (addr->sa_family, 46 inet_ntop (addr->sa_family,
48 (addr->sa_family == AF_INET) ? 47 (addr->sa_family ==
49 (void *) &((struct sockaddr_in *) addr)->sin_addr : 48 AF_INET) ? (void *) &((struct sockaddr_in *) addr)->
50 (void *) &((struct sockaddr_in6 *) addr)->sin6_addr, 49 sin_addr : (void *) &((struct sockaddr_in6 *) addr)->sin6_addr,
51 buf, sizeof (buf)); 50 buf, sizeof (buf));
52 if ((0 == strcmp ("::1", buf)) || (0 == strcmp ("127.0.0.1", buf))) 51 if ((0 == strcmp ("::1", buf)) || (0 == strcmp ("127.0.0.1", buf)))
53 *ok = 0; 52 *ok = 0;
diff --git a/src/util/test_os_start_process.c b/src/util/test_os_start_process.c
index 4137118fa..36dd42a23 100644
--- a/src/util/test_os_start_process.c
+++ b/src/util/test_os_start_process.c
@@ -125,8 +125,9 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
125 return; 125 return;
126 } 126 }
127 127
128 proc = GNUNET_OS_start_process (hello_pipe_stdin, hello_pipe_stdout, fn, 128 proc =
129 "test_gnunet_echo_hello", "-", NULL); 129 GNUNET_OS_start_process (hello_pipe_stdin, hello_pipe_stdout, fn,
130 "test_gnunet_echo_hello", "-", NULL);
130 GNUNET_free (fn); 131 GNUNET_free (fn);
131 132
132 /* Close the write end of the read pipe */ 133 /* Close the write end of the read pipe */
diff --git a/src/util/test_program.c b/src/util/test_program.c
index 9ea5b1510..faeb4e716 100644
--- a/src/util/test_program.c
+++ b/src/util/test_program.c
@@ -57,9 +57,8 @@ static struct GNUNET_GETOPT_CommandLineOption options4[] = {
57 */ 57 */
58 58
59static void 59static void
60runner (void *cls, 60runner (void *cls, char *const *args, const char *cfgfile,
61 char *const *args, 61 const struct GNUNET_CONFIGURATION_Handle *cfg)
62 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
63{ 62{
64 int *ok = cls; 63 int *ok = cls;
65 64
@@ -92,26 +91,18 @@ check ()
92 }; 91 };
93 92
94 GNUNET_assert (GNUNET_OK == 93 GNUNET_assert (GNUNET_OK ==
95 GNUNET_PROGRAM_run (7, 94 GNUNET_PROGRAM_run (7, argv, "test_program", "A test",
96 argv, 95 options1, &runner, &ok));
97 "test_program",
98 "A test", options1, &runner, &ok));
99 96
100 GNUNET_assert (GNUNET_OK == 97 GNUNET_assert (GNUNET_OK ==
101 GNUNET_PROGRAM_run (7, 98 GNUNET_PROGRAM_run (7, argv, "test_program", "A test",
102 argv, 99 options2, &runner, &ok));
103 "test_program",
104 "A test", options2, &runner, &ok));
105 GNUNET_assert (GNUNET_OK == 100 GNUNET_assert (GNUNET_OK ==
106 GNUNET_PROGRAM_run (7, 101 GNUNET_PROGRAM_run (7, argv, "test_program", "A test",
107 argv, 102 options3, &runner, &ok));
108 "test_program",
109 "A test", options3, &runner, &ok));
110 GNUNET_assert (GNUNET_OK == 103 GNUNET_assert (GNUNET_OK ==
111 GNUNET_PROGRAM_run (7, 104 GNUNET_PROGRAM_run (7, argv, "test_program", "A test",
112 argv, 105 options4, &runner, &ok));
113 "test_program",
114 "A test", options4, &runner, &ok));
115 106
116 return ok; 107 return ok;
117} 108}
diff --git a/src/util/test_pseudonym.c b/src/util/test_pseudonym.c
index dfdcbb1bb..20a3d3d96 100644
--- a/src/util/test_pseudonym.c
+++ b/src/util/test_pseudonym.c
@@ -38,15 +38,12 @@ static struct GNUNET_CONTAINER_MetaData *meta;
38static GNUNET_HashCode id1; 38static GNUNET_HashCode id1;
39 39
40static int 40static int
41iter (void *cls, 41iter (void *cls, const GNUNET_HashCode * pseudonym,
42 const GNUNET_HashCode * 42 const struct GNUNET_CONTAINER_MetaData *md, int rating)
43 pseudonym, const struct GNUNET_CONTAINER_MetaData *md, int rating)
44{ 43{
45 int *ok = cls; 44 int *ok = cls;
46 45
47 if ((0 == memcmp (pseudonym, 46 if ((0 == memcmp (pseudonym, &id1, sizeof (GNUNET_HashCode))) &&
48 &id1,
49 sizeof (GNUNET_HashCode))) &&
50 (!GNUNET_CONTAINER_meta_data_test_equal (md, meta))) 47 (!GNUNET_CONTAINER_meta_data_test_equal (md, meta)))
51 { 48 {
52 *ok = GNUNET_NO; 49 *ok = GNUNET_NO;
@@ -56,9 +53,7 @@ iter (void *cls,
56} 53}
57 54
58static int 55static int
59noti_callback (void *cls, 56noti_callback (void *cls, const GNUNET_HashCode * pseudonym,
60 const GNUNET_HashCode *
61 pseudonym,
62 const struct GNUNET_CONTAINER_MetaData *md, int rating) 57 const struct GNUNET_CONTAINER_MetaData *md, int rating)
63{ 58{
64 int *ret = cls; 59 int *ret = cls;
@@ -68,9 +63,7 @@ noti_callback (void *cls,
68} 63}
69 64
70static int 65static int
71fake_noti_callback (void *cls, 66fake_noti_callback (void *cls, const GNUNET_HashCode * pseudonym,
72 const GNUNET_HashCode *
73 pseudonym,
74 const struct GNUNET_CONTAINER_MetaData *md, int rating) 67 const struct GNUNET_CONTAINER_MetaData *md, int rating)
75{ 68{
76 int *ret = cls; 69 int *ret = cls;
@@ -80,8 +73,7 @@ fake_noti_callback (void *cls,
80} 73}
81 74
82static int 75static int
83false_callback (void *cls, 76false_callback (void *cls, const GNUNET_HashCode * pseudonym,
84 const GNUNET_HashCode * pseudonym,
85 const struct GNUNET_CONTAINER_MetaData *md, int rating) 77 const struct GNUNET_CONTAINER_MetaData *md, int rating)
86{ 78{
87 return GNUNET_OK; 79 return GNUNET_OK;
@@ -125,8 +117,7 @@ main (int argc, char *argv[])
125 notiCount = 0; 117 notiCount = 0;
126 fakenotiCount = 0; 118 fakenotiCount = 0;
127 count = 0; 119 count = 0;
128 GNUNET_PSEUDONYM_discovery_callback_register (cfg, 120 GNUNET_PSEUDONYM_discovery_callback_register (cfg, &fake_noti_callback,
129 &fake_noti_callback,
130 &fakenotiCount); 121 &fakenotiCount);
131 GNUNET_PSEUDONYM_discovery_callback_register (cfg, &noti_callback, 122 GNUNET_PSEUDONYM_discovery_callback_register (cfg, &noti_callback,
132 &notiCount); 123 &notiCount);
@@ -137,11 +128,9 @@ main (int argc, char *argv[])
137 /* ACTUAL TEST CODE */ 128 /* ACTUAL TEST CODE */
138 old = GNUNET_PSEUDONYM_list_all (cfg, NULL, NULL); 129 old = GNUNET_PSEUDONYM_list_all (cfg, NULL, NULL);
139 meta = GNUNET_CONTAINER_meta_data_create (); 130 meta = GNUNET_CONTAINER_meta_data_create ();
140 GNUNET_CONTAINER_meta_data_insert (meta, 131 GNUNET_CONTAINER_meta_data_insert (meta, "<test>", EXTRACTOR_METATYPE_TITLE,
141 "<test>", 132 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
142 EXTRACTOR_METATYPE_TITLE, 133 "test", strlen ("test") + 1);
143 EXTRACTOR_METAFORMAT_UTF8,
144 "text/plain", "test", strlen ("test") + 1);
145 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id1); 134 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id1);
146 GNUNET_PSEUDONYM_add (cfg, &id1, meta); 135 GNUNET_PSEUDONYM_add (cfg, &id1, meta);
147 CHECK (notiCount == 1); 136 CHECK (notiCount == 1);
@@ -155,14 +144,12 @@ main (int argc, char *argv[])
155 CHECK (notiCount == 3); 144 CHECK (notiCount == 3);
156 newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok); 145 newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok);
157 CHECK (old < newVal); 146 CHECK (old < newVal);
158 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (meta, 147 GNUNET_assert (GNUNET_OK ==
159 "<test>", 148 GNUNET_CONTAINER_meta_data_insert (meta, "<test>",
160 EXTRACTOR_METATYPE_COMMENT, 149 EXTRACTOR_METATYPE_COMMENT,
161 EXTRACTOR_METAFORMAT_UTF8, 150 EXTRACTOR_METAFORMAT_UTF8,
162 "text/plain", 151 "text/plain", m,
163 m, 152 strlen (m) + 1));
164 strlen (m) +
165 1));
166 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id3); 153 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id3);
167 GNUNET_PSEUDONYM_add (cfg, &id3, meta); 154 GNUNET_PSEUDONYM_add (cfg, &id3, meta);
168 name3 = GNUNET_PSEUDONYM_id_to_name (cfg, &id3); 155 name3 = GNUNET_PSEUDONYM_id_to_name (cfg, &id3);
diff --git a/src/util/test_resolver_api.c b/src/util/test_resolver_api.c
index 8058fa287..563f204eb 100644
--- a/src/util/test_resolver_api.c
+++ b/src/util/test_resolver_api.c
@@ -65,16 +65,16 @@ check_localhost_num (void *cls, const char *hostname)
65 if (0 == strcmp (hostname, "127.0.0.1")) 65 if (0 == strcmp (hostname, "127.0.0.1"))
66 { 66 {
67#if DEBUG_RESOLVER 67#if DEBUG_RESOLVER
68 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 68 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct hostname `%s'.\n",
69 "Received correct hostname `%s'.\n", hostname); 69 hostname);
70#endif 70#endif
71 (*ok) &= ~4; 71 (*ok) &= ~4;
72 } 72 }
73 else 73 else
74 { 74 {
75#if DEBUG_RESOLVER 75#if DEBUG_RESOLVER
76 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 76 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received invalid hostname `%s'.\n",
77 "Received invalid hostname `%s'.\n", hostname); 77 hostname);
78#endif 78#endif
79 GNUNET_break (0); 79 GNUNET_break (0);
80 } 80 }
@@ -91,8 +91,8 @@ check_localhost (void *cls, const char *hostname)
91 if (0 == strcmp (hostname, "localhost")) 91 if (0 == strcmp (hostname, "localhost"))
92 { 92 {
93#if DEBUG_RESOLVER 93#if DEBUG_RESOLVER
94 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 94 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct hostname `%s'.\n",
95 "Received correct hostname `%s'.\n", hostname); 95 hostname);
96#endif 96#endif
97 (*ok) &= ~2; 97 (*ok) &= ~2;
98 } 98 }
@@ -139,20 +139,20 @@ check_local_fqdn (void *cls, const char *gnunet_fqdn)
139 139
140 if (0 != gethostname (hostname, sizeof (hostname) - 1)) 140 if (0 != gethostname (hostname, sizeof (hostname) - 1))
141 { 141 {
142 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | 142 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
143 GNUNET_ERROR_TYPE_BULK, "gethostname"); 143 "gethostname");
144 return; 144 return;
145 } 145 }
146#if DEBUG_RESOLVER 146#if DEBUG_RESOLVER
147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolving our FQDN `%s'\n"),
148 _("Resolving our FQDN `%s'\n"), hostname); 148 hostname);
149#endif 149#endif
150 host = gethostbyname (hostname); 150 host = gethostbyname (hostname);
151 if (NULL == host) 151 if (NULL == host)
152 { 152 {
153 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 153 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
154 _("Could not resolve our FQDN : %s %u\n"), 154 _("Could not resolve our FQDN : %s %u\n"), hstrerror (h_errno),
155 hstrerror (h_errno), h_errno); 155 h_errno);
156 return; 156 return;
157 } 157 }
158 158
@@ -224,8 +224,8 @@ check_rootserver_name (void *cls, const char *hostname)
224} 224}
225 225
226static void 226static void
227run (void *cls, char *const *args, 227run (void *cls, char *const *args, const char *cfgfile,
228 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) 228 const struct GNUNET_CONFIGURATION_Handle *cfg)
229{ 229{
230 int *ok = cls; 230 int *ok = cls;
231 struct sockaddr_in sa; 231 struct sockaddr_in sa;
@@ -283,8 +283,9 @@ run (void *cls, char *const *args,
283 } 283 }
284 284
285 /* Comparing to resolved address to the address the root name server should have */ 285 /* Comparing to resolved address to the address the root name server should have */
286 if (strcmp (inet_ntoa (*(struct in_addr *) rootserver->h_addr_list[0]), 286 if (strcmp
287 ROOTSERVER_IP) != 0) 287 (inet_ntoa (*(struct in_addr *) rootserver->h_addr_list[0]),
288 ROOTSERVER_IP) != 0)
288 { 289 {
289#if DEBUG_RESOLVER 290#if DEBUG_RESOLVER
290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -318,8 +319,8 @@ run (void *cls, char *const *args,
318 GNUNET_break (0); 319 GNUNET_break (0);
319 } 320 }
320 321
321 rootserver 322 rootserver =
322 = gethostbyaddr (&rootserver_addr, sizeof (rootserver_addr), AF_INET); 323 gethostbyaddr (&rootserver_addr, sizeof (rootserver_addr), AF_INET);
323 if (rootserver == NULL) 324 if (rootserver == NULL)
324 { 325 {
325 /* Error: resolving IP addresses does not work */ 326 /* Error: resolving IP addresses does not work */
diff --git a/src/util/test_scheduler.c b/src/util/test_scheduler.c
index d5a701692..3d8ae979c 100644
--- a/src/util/test_scheduler.c
+++ b/src/util/test_scheduler.c
@@ -50,8 +50,8 @@ task2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
50 GNUNET_assert (2 == *ok); 50 GNUNET_assert (2 == *ok);
51 (*ok) = 3; 51 (*ok) = 3;
52 /* t3 will go before t4: higher priority */ 52 /* t3 will go before t4: higher priority */
53 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, 53 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, &task3,
54 &task3, cls); 54 cls);
55} 55}
56 56
57static void 57static void
@@ -106,8 +106,8 @@ taskRd (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
106 GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, fds[0])); 106 GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, fds[0]));
107 GNUNET_assert (1 == GNUNET_DISK_file_read (fds[0], &c, 1)); 107 GNUNET_assert (1 == GNUNET_DISK_file_read (fds[0], &c, 1));
108 (*ok) = 8; 108 (*ok) = 8;
109 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, 109 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, &taskLast,
110 &taskLast, cls); 110 cls);
111 GNUNET_SCHEDULER_shutdown (); 111 GNUNET_SCHEDULER_shutdown ();
112} 112}
113 113
@@ -123,10 +123,10 @@ task5 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
123 GNUNET_assert (NULL != p); 123 GNUNET_assert (NULL != p);
124 fds[0] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_READ); 124 fds[0] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_READ);
125 fds[1] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_WRITE); 125 fds[1] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_WRITE);
126 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 126 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, fds[0], &taskRd,
127 fds[0], &taskRd, cls); 127 cls);
128 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, 128 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, fds[1],
129 fds[1], &taskWrt, cls); 129 &taskWrt, cls);
130} 130}
131 131
132 132
@@ -225,8 +225,8 @@ taskCancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
225 225
226 GNUNET_assert (1 == *ok); 226 GNUNET_assert (1 == *ok);
227 *ok = 0; 227 *ok = 0;
228 GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_add_after (GNUNET_SCHEDULER_NO_TASK, 228 GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_add_after
229 &taskNeverRun, NULL)); 229 (GNUNET_SCHEDULER_NO_TASK, &taskNeverRun, NULL));
230} 230}
231 231
232 232
diff --git a/src/util/test_scheduler_delay.c b/src/util/test_scheduler_delay.c
index b98e76eeb..8bcfa096e 100644
--- a/src/util/test_scheduler_delay.c
+++ b/src/util/test_scheduler_delay.c
@@ -66,8 +66,8 @@ test_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
66 return; 66 return;
67 } 67 }
68 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 68 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
69 (GNUNET_TIME_UNIT_MILLISECONDS, i), 69 (GNUNET_TIME_UNIT_MILLISECONDS, i), &test_task,
70 &test_task, NULL); 70 NULL);
71 i += INCR; 71 i += INCR;
72} 72}
73 73
@@ -76,8 +76,8 @@ check ()
76{ 76{
77 target = GNUNET_TIME_absolute_get (); 77 target = GNUNET_TIME_absolute_get ();
78 GNUNET_SCHEDULER_run (&test_task, NULL); 78 GNUNET_SCHEDULER_run (&test_task, NULL);
79 FPRINTF (stdout, 79 FPRINTF (stdout, "Sleep precision: %llu ms. ",
80 "Sleep precision: %llu ms. ", cumDelta / 1000 / (MAXV / INCR)); 80 cumDelta / 1000 / (MAXV / INCR));
81 if (cumDelta <= 10 * MAXV / INCR) 81 if (cumDelta <= 10 * MAXV / INCR)
82 fprintf (stdout, "Timer precision is excellent.\n"); 82 fprintf (stdout, "Timer precision is excellent.\n");
83 else if (cumDelta <= 50 * MAXV / INCR) /* 50 ms average deviation */ 83 else if (cumDelta <= 50 * MAXV / INCR) /* 50 ms average deviation */
diff --git a/src/util/test_server.c b/src/util/test_server.c
index 577a841ff..59bf8a2f4 100644
--- a/src/util/test_server.c
+++ b/src/util/test_server.c
@@ -60,8 +60,7 @@ finish_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
60 60
61 61
62static void 62static void
63recv_fin_cb (void *cls, 63recv_fin_cb (void *cls, struct GNUNET_SERVER_Client *client,
64 struct GNUNET_SERVER_Client *client,
65 const struct GNUNET_MessageHeader *message) 64 const struct GNUNET_MessageHeader *message)
66{ 65{
67 GNUNET_assert (ok == 5); 66 GNUNET_assert (ok == 5);
@@ -98,8 +97,7 @@ reply_msg (void *cls, size_t size, void *buf)
98 97
99 98
100static void 99static void
101recv_cb (void *cls, 100recv_cb (void *cls, struct GNUNET_SERVER_Client *client,
102 struct GNUNET_SERVER_Client *client,
103 const struct GNUNET_MessageHeader *message) 101 const struct GNUNET_MessageHeader *message)
104{ 102{
105 GNUNET_assert (ok == 2); 103 GNUNET_assert (ok == 2);
@@ -111,8 +109,8 @@ recv_cb (void *cls,
111 GNUNET_assert (NULL != 109 GNUNET_assert (NULL !=
112 GNUNET_SERVER_notify_transmit_ready (client, 110 GNUNET_SERVER_notify_transmit_ready (client,
113 ntohs (message->size), 111 ntohs (message->size),
114 TIMEOUT, 112 TIMEOUT, &reply_msg,
115 &reply_msg, NULL)); 113 NULL));
116} 114}
117 115
118 116
diff --git a/src/util/test_server_disconnect.c b/src/util/test_server_disconnect.c
index 03d57a222..8010695e8 100644
--- a/src/util/test_server_disconnect.c
+++ b/src/util/test_server_disconnect.c
@@ -80,8 +80,7 @@ server_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
80 80
81 81
82static void 82static void
83recv_cb (void *cls, 83recv_cb (void *cls, struct GNUNET_SERVER_Client *client,
84 struct GNUNET_SERVER_Client *client,
85 const struct GNUNET_MessageHeader *message) 84 const struct GNUNET_MessageHeader *message)
86{ 85{
87 GNUNET_assert (ok == 2); 86 GNUNET_assert (ok == 2);
diff --git a/src/util/test_server_with_client.c b/src/util/test_server_with_client.c
index 4b9d84059..06a4b71d6 100644
--- a/src/util/test_server_with_client.c
+++ b/src/util/test_server_with_client.c
@@ -57,8 +57,7 @@ send_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
57 57
58 58
59static void 59static void
60recv_cb (void *cls, 60recv_cb (void *cls, struct GNUNET_SERVER_Client *argclient,
61 struct GNUNET_SERVER_Client *argclient,
62 const struct GNUNET_MessageHeader *message) 61 const struct GNUNET_MessageHeader *message)
63{ 62{
64 void *addr; 63 void *addr;
@@ -169,13 +168,10 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
169#endif 168#endif
170 sa.sin_family = AF_INET; 169 sa.sin_family = AF_INET;
171 sa.sin_port = htons (PORT); 170 sa.sin_port = htons (PORT);
172 server = GNUNET_SERVER_create (NULL, 171 server =
173 NULL, 172 GNUNET_SERVER_create (NULL, NULL, sap, slens,
174 sap, 173 GNUNET_TIME_relative_multiply
175 slens, 174 (GNUNET_TIME_UNIT_MILLISECONDS, 250), GNUNET_NO);
176 GNUNET_TIME_relative_multiply
177 (GNUNET_TIME_UNIT_MILLISECONDS, 250),
178 GNUNET_NO);
179 GNUNET_assert (server != NULL); 175 GNUNET_assert (server != NULL);
180 handlers[0].callback_cls = cls; 176 handlers[0].callback_cls = cls;
181 GNUNET_SERVER_add_handlers (server, handlers); 177 GNUNET_SERVER_add_handlers (server, handlers);
@@ -187,8 +183,7 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
187 "localhost"); 183 "localhost");
188 client = GNUNET_CLIENT_connect ("test", cfg); 184 client = GNUNET_CLIENT_connect ("test", cfg);
189 GNUNET_assert (client != NULL); 185 GNUNET_assert (client != NULL);
190 GNUNET_CLIENT_notify_transmit_ready (client, 186 GNUNET_CLIENT_notify_transmit_ready (client, 256,
191 256,
192 GNUNET_TIME_relative_multiply 187 GNUNET_TIME_relative_multiply
193 (GNUNET_TIME_UNIT_MILLISECONDS, 250), 188 (GNUNET_TIME_UNIT_MILLISECONDS, 250),
194 GNUNET_NO, &notify_ready, NULL); 189 GNUNET_NO, &notify_ready, NULL);
diff --git a/src/util/test_server_with_client_unix.c b/src/util/test_server_with_client_unix.c
index 00df21129..99af4e8c3 100644
--- a/src/util/test_server_with_client_unix.c
+++ b/src/util/test_server_with_client_unix.c
@@ -55,8 +55,7 @@ send_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
55 55
56 56
57static void 57static void
58recv_cb (void *cls, 58recv_cb (void *cls, struct GNUNET_SERVER_Client *argclient,
59 struct GNUNET_SERVER_Client *argclient,
60 const struct GNUNET_MessageHeader *message) 59 const struct GNUNET_MessageHeader *message)
61{ 60{
62 switch (ok) 61 switch (ok)
@@ -156,13 +155,10 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
156 slens[0] = sizeof (un); 155 slens[0] = sizeof (un);
157 sap[1] = NULL; 156 sap[1] = NULL;
158 slens[1] = 0; 157 slens[1] = 0;
159 server = GNUNET_SERVER_create (NULL, 158 server =
160 NULL, 159 GNUNET_SERVER_create (NULL, NULL, sap, slens,
161 sap, 160 GNUNET_TIME_relative_multiply
162 slens, 161 (GNUNET_TIME_UNIT_MILLISECONDS, 250), GNUNET_NO);
163 GNUNET_TIME_relative_multiply
164 (GNUNET_TIME_UNIT_MILLISECONDS, 250),
165 GNUNET_NO);
166 GNUNET_assert (server != NULL); 162 GNUNET_assert (server != NULL);
167 handlers[0].callback_cls = cls; 163 handlers[0].callback_cls = cls;
168 GNUNET_SERVER_add_handlers (server, handlers); 164 GNUNET_SERVER_add_handlers (server, handlers);
@@ -175,8 +171,7 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
175 171
176 client = GNUNET_CLIENT_connect ("test", cfg); 172 client = GNUNET_CLIENT_connect ("test", cfg);
177 GNUNET_assert (client != NULL); 173 GNUNET_assert (client != NULL);
178 GNUNET_CLIENT_notify_transmit_ready (client, 174 GNUNET_CLIENT_notify_transmit_ready (client, 256,
179 256,
180 GNUNET_TIME_relative_multiply 175 GNUNET_TIME_relative_multiply
181 (GNUNET_TIME_UNIT_MILLISECONDS, 250), 176 (GNUNET_TIME_UNIT_MILLISECONDS, 250),
182 GNUNET_NO, &notify_ready, NULL); 177 GNUNET_NO, &notify_ready, NULL);
diff --git a/src/util/test_service.c b/src/util/test_service.c
index daafa6cd3..4d1608191 100644
--- a/src/util/test_service.c
+++ b/src/util/test_service.c
@@ -71,8 +71,8 @@ ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
71 "Client connecting, waiting to transmit\n"); 71 "Client connecting, waiting to transmit\n");
72 GNUNET_CLIENT_notify_transmit_ready (client, 72 GNUNET_CLIENT_notify_transmit_ready (client,
73 sizeof (struct GNUNET_MessageHeader), 73 sizeof (struct GNUNET_MessageHeader),
74 GNUNET_TIME_UNIT_SECONDS, 74 GNUNET_TIME_UNIT_SECONDS, GNUNET_NO,
75 GNUNET_NO, &build_msg, client); 75 &build_msg, client);
76} 76}
77 77
78static void 78static void
@@ -83,8 +83,7 @@ do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
83 83
84 84
85static void 85static void
86recv_cb (void *cls, 86recv_cb (void *cls, struct GNUNET_SERVER_Client *client,
87 struct GNUNET_SERVER_Client *client,
88 const struct GNUNET_MessageHeader *message) 87 const struct GNUNET_MessageHeader *message)
89{ 88{
90 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving client message...\n"); 89 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving client message...\n");
@@ -105,15 +104,13 @@ static struct GNUNET_SERVER_MessageHandler myhandlers[] = {
105 104
106 105
107static void 106static void
108runner (void *cls, 107runner (void *cls, struct GNUNET_SERVER_Handle *server,
109 struct GNUNET_SERVER_Handle *server,
110 const struct GNUNET_CONFIGURATION_Handle *cfg) 108 const struct GNUNET_CONFIGURATION_Handle *cfg)
111{ 109{
112 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service initializing\n"); 110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service initializing\n");
113 GNUNET_SERVER_add_handlers (server, myhandlers); 111 GNUNET_SERVER_add_handlers (server, myhandlers);
114 GNUNET_CLIENT_service_test ("test_service", 112 GNUNET_CLIENT_service_test ("test_service", cfg, GNUNET_TIME_UNIT_SECONDS,
115 cfg, GNUNET_TIME_UNIT_SECONDS, &ready, 113 &ready, (void *) cfg);
116 (void *) cfg);
117} 114}
118 115
119 116
@@ -139,9 +136,7 @@ check ()
139 }; 136 };
140 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting service\n"); 137 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting service\n");
141 GNUNET_assert (GNUNET_OK == 138 GNUNET_assert (GNUNET_OK ==
142 GNUNET_SERVICE_run (5, 139 GNUNET_SERVICE_run (5, argv, "test_service",
143 argv,
144 "test_service",
145 GNUNET_SERVICE_OPTION_NONE, &runner, &ok)); 140 GNUNET_SERVICE_OPTION_NONE, &runner, &ok));
146 GNUNET_assert (0 == ok); 141 GNUNET_assert (0 == ok);
147 return ok; 142 return ok;
@@ -160,20 +155,18 @@ ready6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
160 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "V6 client connected\n"); 155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "V6 client connected\n");
161 GNUNET_CLIENT_notify_transmit_ready (client, 156 GNUNET_CLIENT_notify_transmit_ready (client,
162 sizeof (struct GNUNET_MessageHeader), 157 sizeof (struct GNUNET_MessageHeader),
163 GNUNET_TIME_UNIT_SECONDS, 158 GNUNET_TIME_UNIT_SECONDS, GNUNET_NO,
164 GNUNET_NO, &build_msg, client); 159 &build_msg, client);
165} 160}
166 161
167static void 162static void
168runner6 (void *cls, 163runner6 (void *cls, struct GNUNET_SERVER_Handle *server,
169 struct GNUNET_SERVER_Handle *server,
170 const struct GNUNET_CONFIGURATION_Handle *cfg) 164 const struct GNUNET_CONFIGURATION_Handle *cfg)
171{ 165{
172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initializing v6 service\n"); 166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initializing v6 service\n");
173 GNUNET_SERVER_add_handlers (server, myhandlers); 167 GNUNET_SERVER_add_handlers (server, myhandlers);
174 GNUNET_CLIENT_service_test ("test_service6", 168 GNUNET_CLIENT_service_test ("test_service6", cfg, GNUNET_TIME_UNIT_SECONDS,
175 cfg, GNUNET_TIME_UNIT_SECONDS, &ready6, 169 &ready6, (void *) cfg);
176 (void *) cfg);
177} 170}
178 171
179/** 172/**
@@ -197,11 +190,9 @@ check6 ()
197 }; 190 };
198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting v6 service\n"); 191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting v6 service\n");
199 GNUNET_assert (GNUNET_OK == 192 GNUNET_assert (GNUNET_OK ==
200 GNUNET_SERVICE_run (5, 193 GNUNET_SERVICE_run (5, argv, "test_service6",
201 argv, 194 GNUNET_SERVICE_OPTION_NONE, &runner6,
202 "test_service6", 195 &ok));
203 GNUNET_SERVICE_OPTION_NONE,
204 &runner6, &ok));
205 GNUNET_assert (0 == ok); 196 GNUNET_assert (0 == ok);
206 return ok; 197 return ok;
207} 198}
@@ -209,9 +200,7 @@ check6 ()
209 200
210 201
211static void 202static void
212start_stop_main (void *cls, 203start_stop_main (void *cls, char *const *args, const char *cfgfile,
213 char *const *args,
214 const char *cfgfile,
215 const struct GNUNET_CONFIGURATION_Handle *cfg) 204 const struct GNUNET_CONFIGURATION_Handle *cfg)
216{ 205{
217 int *ret = cls; 206 int *ret = cls;
@@ -245,10 +234,7 @@ check_start_stop ()
245 int ret = 1; 234 int ret = 1;
246 235
247 GNUNET_assert (GNUNET_OK == 236 GNUNET_assert (GNUNET_OK ==
248 GNUNET_PROGRAM_run (5, 237 GNUNET_PROGRAM_run (5, argv, "test-service-program", "no help",
249 argv,
250 "test-service-program",
251 "no help",
252 options, &start_stop_main, &ret)); 238 options, &start_stop_main, &ret));
253 239
254 GNUNET_break (0 == ret); 240 GNUNET_break (0 == ret);
@@ -278,8 +264,8 @@ main (int argc, char *argv[])
278#endif 264#endif
279 if (NULL == s) 265 if (NULL == s)
280 { 266 {
281 if ((errno == ENOBUFS) || 267 if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) ||
282 (errno == ENOMEM) || (errno == ENFILE) || (errno == EACCES)) 268 (errno == EACCES))
283 { 269 {
284 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); 270 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
285 return 1; 271 return 1;
diff --git a/src/util/test_time.c b/src/util/test_time.c
index 788884fcc..6a05b698c 100644
--- a/src/util/test_time.c
+++ b/src/util/test_time.c
@@ -108,8 +108,8 @@ check ()
108 GNUNET_assert (GNUNET_TIME_absolute_get_difference (future, now).rel_value == 108 GNUNET_assert (GNUNET_TIME_absolute_get_difference (future, now).rel_value ==
109 0); 109 0);
110 110
111 GNUNET_assert (GNUNET_TIME_absolute_get_difference (zero, forever).rel_value 111 GNUNET_assert (GNUNET_TIME_absolute_get_difference (zero, forever).
112 == forever.abs_value); 112 rel_value == forever.abs_value);
113 113
114 past.abs_value = now.abs_value - 1000000; 114 past.abs_value = now.abs_value - 1000000;
115 rel = GNUNET_TIME_absolute_get_duration (future); 115 rel = GNUNET_TIME_absolute_get_duration (future);
@@ -153,7 +153,8 @@ check ()
153 153
154 GNUNET_assert (forever.abs_value == 154 GNUNET_assert (forever.abs_value ==
155 GNUNET_TIME_absolute_subtract (forever, 155 GNUNET_TIME_absolute_subtract (forever,
156 GNUNET_TIME_UNIT_MINUTES).abs_value); 156 GNUNET_TIME_UNIT_MINUTES).
157 abs_value);
157 /*check absolute subtract */ 158 /*check absolute subtract */
158 now.abs_value = 50000; 159 now.abs_value = 50000;
159 rel.rel_value = 100000; 160 rel.rel_value = 100000;
diff --git a/src/util/time.c b/src/util/time.c
index f4d4c4070..34880b08b 100644
--- a/src/util/time.c
+++ b/src/util/time.c
@@ -145,9 +145,8 @@ GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel)
145 * @return timestamp that is smaller 145 * @return timestamp that is smaller
146 */ 146 */
147struct GNUNET_TIME_Relative 147struct GNUNET_TIME_Relative
148GNUNET_TIME_relative_min (struct 148GNUNET_TIME_relative_min (struct GNUNET_TIME_Relative t1,
149 GNUNET_TIME_Relative 149 struct GNUNET_TIME_Relative t2)
150 t1, struct GNUNET_TIME_Relative t2)
151{ 150{
152 return (t1.rel_value < t2.rel_value) ? t1 : t2; 151 return (t1.rel_value < t2.rel_value) ? t1 : t2;
153} 152}
@@ -161,9 +160,8 @@ GNUNET_TIME_relative_min (struct
161 * @return timestamp that is larger 160 * @return timestamp that is larger
162 */ 161 */
163struct GNUNET_TIME_Relative 162struct GNUNET_TIME_Relative
164GNUNET_TIME_relative_max (struct 163GNUNET_TIME_relative_max (struct GNUNET_TIME_Relative t1,
165 GNUNET_TIME_Relative 164 struct GNUNET_TIME_Relative t2)
166 t1, struct GNUNET_TIME_Relative t2)
167{ 165{
168 return (t1.rel_value > t2.rel_value) ? t1 : t2; 166 return (t1.rel_value > t2.rel_value) ? t1 : t2;
169} 167}
@@ -178,9 +176,8 @@ GNUNET_TIME_relative_max (struct
178 * @return timestamp that is smaller 176 * @return timestamp that is smaller
179 */ 177 */
180struct GNUNET_TIME_Absolute 178struct GNUNET_TIME_Absolute
181GNUNET_TIME_absolute_min (struct 179GNUNET_TIME_absolute_min (struct GNUNET_TIME_Absolute t1,
182 GNUNET_TIME_Absolute 180 struct GNUNET_TIME_Absolute t2)
183 t1, struct GNUNET_TIME_Absolute t2)
184{ 181{
185 return (t1.abs_value < t2.abs_value) ? t1 : t2; 182 return (t1.abs_value < t2.abs_value) ? t1 : t2;
186} 183}
@@ -194,9 +191,8 @@ GNUNET_TIME_absolute_min (struct
194 * @return timestamp that is smaller 191 * @return timestamp that is smaller
195 */ 192 */
196struct GNUNET_TIME_Absolute 193struct GNUNET_TIME_Absolute
197GNUNET_TIME_absolute_max (struct 194GNUNET_TIME_absolute_max (struct GNUNET_TIME_Absolute t1,
198 GNUNET_TIME_Absolute 195 struct GNUNET_TIME_Absolute t2)
199 t1, struct GNUNET_TIME_Absolute t2)
200{ 196{
201 return (t1.abs_value > t2.abs_value) ? t1 : t2; 197 return (t1.abs_value > t2.abs_value) ? t1 : t2;
202} 198}
@@ -298,9 +294,8 @@ GNUNET_TIME_absolute_add (struct GNUNET_TIME_Absolute start,
298 * @return ZERO if start <= duration, or FOREVER if start time is FOREVER; start-duration otherwise 294 * @return ZERO if start <= duration, or FOREVER if start time is FOREVER; start-duration otherwise
299 */ 295 */
300struct GNUNET_TIME_Absolute 296struct GNUNET_TIME_Absolute
301GNUNET_TIME_absolute_subtract (struct 297GNUNET_TIME_absolute_subtract (struct GNUNET_TIME_Absolute start,
302 GNUNET_TIME_Absolute 298 struct GNUNET_TIME_Relative duration)
303 start, struct GNUNET_TIME_Relative duration)
304{ 299{
305 struct GNUNET_TIME_Absolute ret; 300 struct GNUNET_TIME_Absolute ret;
306 301
@@ -368,8 +363,8 @@ GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel,
368 * assuming it continues at the same speed 363 * assuming it continues at the same speed
369 */ 364 */
370struct GNUNET_TIME_Relative 365struct GNUNET_TIME_Relative
371GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start, 366GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start, uint64_t finished,
372 uint64_t finished, uint64_t total) 367 uint64_t total)
373{ 368{
374 struct GNUNET_TIME_Relative dur; 369 struct GNUNET_TIME_Relative dur;
375 double exp; 370 double exp;
diff --git a/src/util/winproc.c b/src/util/winproc.c
index 4fa3ab484..9594c5d6f 100644
--- a/src/util/winproc.c
+++ b/src/util/winproc.c
@@ -100,8 +100,9 @@ GNInitWinEnv ()
100 /* Function to get CPU usage under Win NT */ 100 /* Function to get CPU usage under Win NT */
101 if (hNTDLL) 101 if (hNTDLL)
102 { 102 {
103 GNNtQuerySystemInformation = (TNtQuerySystemInformation) 103 GNNtQuerySystemInformation =
104 GetProcAddress (hNTDLL, "NtQuerySystemInformation"); 104 (TNtQuerySystemInformation) GetProcAddress (hNTDLL,
105 "NtQuerySystemInformation");
105 } 106 }
106 else 107 else
107 { 108 {
@@ -113,13 +114,13 @@ GNInitWinEnv ()
113 if (hIphlpapi) 114 if (hIphlpapi)
114 { 115 {
115 GNGetIfEntry = (TGetIfEntry) GetProcAddress (hIphlpapi, "GetIfEntry"); 116 GNGetIfEntry = (TGetIfEntry) GetProcAddress (hIphlpapi, "GetIfEntry");
116 GNGetIpAddrTable = (TGetIpAddrTable) GetProcAddress (hIphlpapi, 117 GNGetIpAddrTable =
117 "GetIpAddrTable"); 118 (TGetIpAddrTable) GetProcAddress (hIphlpapi, "GetIpAddrTable");
118 GNGetIfTable = (TGetIfTable) GetProcAddress (hIphlpapi, "GetIfTable"); 119 GNGetIfTable = (TGetIfTable) GetProcAddress (hIphlpapi, "GetIfTable");
119 GNGetBestInterface = (TGetBestInterface) GetProcAddress (hIphlpapi, 120 GNGetBestInterface =
120 "GetBestInterface"); 121 (TGetBestInterface) GetProcAddress (hIphlpapi, "GetBestInterface");
121 GGetAdaptersInfo = (TGetAdaptersInfo) GetProcAddress (hIphlpapi, 122 GGetAdaptersInfo =
122 "GetAdaptersInfo"); 123 (TGetAdaptersInfo) GetProcAddress (hIphlpapi, "GetAdaptersInfo");
123 } 124 }
124 else 125 else
125 { 126 {
@@ -134,51 +135,57 @@ GNInitWinEnv ()
134 hAdvapi = LoadLibrary ("advapi32.dll"); 135 hAdvapi = LoadLibrary ("advapi32.dll");
135 if (hAdvapi) 136 if (hAdvapi)
136 { 137 {
137 GNOpenSCManager = (TOpenSCManager) 138 GNOpenSCManager =
138 GetProcAddress (hAdvapi, "OpenSCManagerA"); 139 (TOpenSCManager) GetProcAddress (hAdvapi, "OpenSCManagerA");
139 GNCreateService = (TCreateService) 140 GNCreateService =
140 GetProcAddress (hAdvapi, "CreateServiceA"); 141 (TCreateService) GetProcAddress (hAdvapi, "CreateServiceA");
141 GNCloseServiceHandle = (TCloseServiceHandle) 142 GNCloseServiceHandle =
142 GetProcAddress (hAdvapi, "CloseServiceHandle"); 143 (TCloseServiceHandle) GetProcAddress (hAdvapi, "CloseServiceHandle");
143 GNDeleteService = (TDeleteService) 144 GNDeleteService =
144 GetProcAddress (hAdvapi, "DeleteService"); 145 (TDeleteService) GetProcAddress (hAdvapi, "DeleteService");
145 GNRegisterServiceCtrlHandler = (TRegisterServiceCtrlHandler) 146 GNRegisterServiceCtrlHandler =
146 GetProcAddress (hAdvapi, "RegisterServiceCtrlHandlerA"); 147 (TRegisterServiceCtrlHandler) GetProcAddress (hAdvapi,
147 GNSetServiceStatus = (TSetServiceStatus) 148 "RegisterServiceCtrlHandlerA");
148 GetProcAddress (hAdvapi, "SetServiceStatus"); 149 GNSetServiceStatus =
149 GNStartServiceCtrlDispatcher = (TStartServiceCtrlDispatcher) 150 (TSetServiceStatus) GetProcAddress (hAdvapi, "SetServiceStatus");
150 GetProcAddress (hAdvapi, "StartServiceCtrlDispatcherA"); 151 GNStartServiceCtrlDispatcher =
151 GNControlService = (TControlService) 152 (TStartServiceCtrlDispatcher) GetProcAddress (hAdvapi,
152 GetProcAddress (hAdvapi, "ControlService"); 153 "StartServiceCtrlDispatcherA");
154 GNControlService =
155 (TControlService) GetProcAddress (hAdvapi, "ControlService");
153 GNOpenService = (TOpenService) GetProcAddress (hAdvapi, "OpenServiceA"); 156 GNOpenService = (TOpenService) GetProcAddress (hAdvapi, "OpenServiceA");
154 157
155 GNLsaOpenPolicy = (TLsaOpenPolicy) 158 GNLsaOpenPolicy =
156 GetProcAddress (hAdvapi, "LsaOpenPolicy"); 159 (TLsaOpenPolicy) GetProcAddress (hAdvapi, "LsaOpenPolicy");
157 GNLsaAddAccountRights = (TLsaAddAccountRights) 160 GNLsaAddAccountRights =
158 GetProcAddress (hAdvapi, "LsaAddAccountRights"); 161 (TLsaAddAccountRights) GetProcAddress (hAdvapi, "LsaAddAccountRights");
159 GNLsaRemoveAccountRights = (TLsaRemoveAccountRights) 162 GNLsaRemoveAccountRights =
160 GetProcAddress (hAdvapi, "LsaRemoveAccountRights"); 163 (TLsaRemoveAccountRights) GetProcAddress (hAdvapi,
164 "LsaRemoveAccountRights");
161 GNLsaClose = (TLsaClose) GetProcAddress (hAdvapi, "LsaClose"); 165 GNLsaClose = (TLsaClose) GetProcAddress (hAdvapi, "LsaClose");
162 GNLookupAccountName = (TLookupAccountName) 166 GNLookupAccountName =
163 GetProcAddress (hAdvapi, "LookupAccountNameA"); 167 (TLookupAccountName) GetProcAddress (hAdvapi, "LookupAccountNameA");
164 168
165 GNGetFileSecurity = (TGetFileSecurity) 169 GNGetFileSecurity =
166 GetProcAddress (hAdvapi, "GetFileSecurityA"); 170 (TGetFileSecurity) GetProcAddress (hAdvapi, "GetFileSecurityA");
167 GNInitializeSecurityDescriptor = (TInitializeSecurityDescriptor) 171 GNInitializeSecurityDescriptor =
168 GetProcAddress (hAdvapi, "InitializeSecurityDescriptor"); 172 (TInitializeSecurityDescriptor) GetProcAddress (hAdvapi,
169 GNGetSecurityDescriptorDacl = (TGetSecurityDescriptorDacl) 173 "InitializeSecurityDescriptor");
170 GetProcAddress (hAdvapi, "GetSecurityDescriptorDacl"); 174 GNGetSecurityDescriptorDacl =
171 GNGetAclInformation = (TGetAclInformation) 175 (TGetSecurityDescriptorDacl) GetProcAddress (hAdvapi,
172 GetProcAddress (hAdvapi, "GetAclInformation"); 176 "GetSecurityDescriptorDacl");
173 GNInitializeAcl = (TInitializeAcl) 177 GNGetAclInformation =
174 GetProcAddress (hAdvapi, "InitializeAcl"); 178 (TGetAclInformation) GetProcAddress (hAdvapi, "GetAclInformation");
179 GNInitializeAcl =
180 (TInitializeAcl) GetProcAddress (hAdvapi, "InitializeAcl");
175 GNGetAce = (TGetAce) GetProcAddress (hAdvapi, "GetAce"); 181 GNGetAce = (TGetAce) GetProcAddress (hAdvapi, "GetAce");
176 GNEqualSid = (TEqualSid) GetProcAddress (hAdvapi, "EqualSid"); 182 GNEqualSid = (TEqualSid) GetProcAddress (hAdvapi, "EqualSid");
177 GNAddAce = (TAddAce) GetProcAddress (hAdvapi, "AddAce"); 183 GNAddAce = (TAddAce) GetProcAddress (hAdvapi, "AddAce");
178 GNAddAccessAllowedAce = (TAddAccessAllowedAce) 184 GNAddAccessAllowedAce =
179 GetProcAddress (hAdvapi, "AddAccessAllowedAce"); 185 (TAddAccessAllowedAce) GetProcAddress (hAdvapi, "AddAccessAllowedAce");
180 GNSetNamedSecurityInfo = (TSetNamedSecurityInfo) 186 GNSetNamedSecurityInfo =
181 GetProcAddress (hAdvapi, "SetNamedSecurityInfoA"); 187 (TSetNamedSecurityInfo) GetProcAddress (hAdvapi,
188 "SetNamedSecurityInfoA");
182 } 189 }
183 else 190 else
184 { 191 {
@@ -215,8 +222,8 @@ GNInitWinEnv ()
215 if (hNetapi) 222 if (hNetapi)
216 { 223 {
217 GNNetUserAdd = (TNetUserAdd) GetProcAddress (hNetapi, "NetUserAdd"); 224 GNNetUserAdd = (TNetUserAdd) GetProcAddress (hNetapi, "NetUserAdd");
218 GNNetUserSetInfo = (TNetUserSetInfo) 225 GNNetUserSetInfo =
219 GetProcAddress (hNetapi, "NetUserSetInfo"); 226 (TNetUserSetInfo) GetProcAddress (hNetapi, "NetUserSetInfo");
220 } 227 }
221 else 228 else
222 { 229 {
diff --git a/src/vpn/gnunet-daemon-exit.c b/src/vpn/gnunet-daemon-exit.c
index de906af3b..324c136b0 100644
--- a/src/vpn/gnunet-daemon-exit.c
+++ b/src/vpn/gnunet-daemon-exit.c
@@ -522,8 +522,7 @@ tcp_from_helper (struct tcp_pkt *tcp, unsigned char *dadr, size_t addrlen,
522 * Receive packets from the helper-process 522 * Receive packets from the helper-process
523 */ 523 */
524static void 524static void
525message_token (void *cls __attribute__ ((unused)), 525message_token (void *cls __attribute__ ((unused)), void *client
526 void *client
527 __attribute__ ((unused)), 526 __attribute__ ((unused)),
528 const struct GNUNET_MessageHeader *message) 527 const struct GNUNET_MessageHeader *message)
529{ 528{
@@ -612,8 +611,8 @@ read_service_conf (void *cls __attribute__ ((unused)), const char *section)
612 "TCP_REDIRECTS", &cpy))) 611 "TCP_REDIRECTS", &cpy)))
613 goto next; 612 goto next;
614 613
615 for (redirect = strtok (cpy, " "); redirect != NULL; redirect = strtok 614 for (redirect = strtok (cpy, " "); redirect != NULL;
616 (NULL, " ")) 615 redirect = strtok (NULL, " "))
617 { 616 {
618 if (NULL == (hostname = strstr (redirect, ":"))) 617 if (NULL == (hostname = strstr (redirect, ":")))
619 { 618 {
@@ -654,8 +653,7 @@ read_service_conf (void *cls __attribute__ ((unused)), const char *section)
654 char *ip4addr; 653 char *ip4addr;
655 654
656 GNUNET_assert (GNUNET_OK == 655 GNUNET_assert (GNUNET_OK ==
657 GNUNET_CONFIGURATION_get_value_string (cfg, 656 GNUNET_CONFIGURATION_get_value_string (cfg, "exit",
658 "exit",
659 "IPV4ADDR", 657 "IPV4ADDR",
660 &ip4addr)); 658 &ip4addr));
661 GNUNET_assert (1 == inet_pton (AF_INET, ip4addr, serv->v4.ip4address)); 659 GNUNET_assert (1 == inet_pton (AF_INET, ip4addr, serv->v4.ip4address));
@@ -668,8 +666,7 @@ read_service_conf (void *cls __attribute__ ((unused)), const char *section)
668 char *ip6addr; 666 char *ip6addr;
669 667
670 GNUNET_assert (GNUNET_OK == 668 GNUNET_assert (GNUNET_OK ==
671 GNUNET_CONFIGURATION_get_value_string (cfg, 669 GNUNET_CONFIGURATION_get_value_string (cfg, "exit",
672 "exit",
673 "IPV6ADDR", 670 "IPV6ADDR",
674 &ip6addr)); 671 &ip6addr));
675 GNUNET_assert (1 == inet_pton (AF_INET6, ip6addr, serv->v6.ip6address)); 672 GNUNET_assert (1 == inet_pton (AF_INET6, ip6addr, serv->v6.ip6address));
@@ -774,13 +771,10 @@ start_helper_and_schedule (void *cls,
774 * When the helper dies, this function will be called again with the 771 * When the helper dies, this function will be called again with the
775 * helper_handle as cls. 772 * helper_handle as cls.
776 */ 773 */
777 helper_handle = start_helper (ifname, 774 helper_handle =
778 ipv6addr, 775 start_helper (ifname, ipv6addr, ipv6prefix, ipv4addr, ipv4mask,
779 ipv6prefix, 776 "exit-gnunet", start_helper_and_schedule, message_token,
780 ipv4addr, 777 NULL);
781 ipv4mask,
782 "exit-gnunet",
783 start_helper_and_schedule, message_token, NULL);
784 778
785 GNUNET_free (ipv6addr); 779 GNUNET_free (ipv6addr);
786 GNUNET_free (ipv6prefix); 780 GNUNET_free (ipv6prefix);
@@ -822,11 +816,11 @@ prepare_ipv4_packet (ssize_t len, ssize_t pktlen, void *payload,
822 char *ipv4mask; 816 char *ipv4mask;
823 817
824 GNUNET_assert (GNUNET_OK == 818 GNUNET_assert (GNUNET_OK ==
825 GNUNET_CONFIGURATION_get_value_string (cfg, "exit", 819 GNUNET_CONFIGURATION_get_value_string (cfg, "exit", "IPV4ADDR",
826 "IPV4ADDR", &ipv4addr)); 820 &ipv4addr));
827 GNUNET_assert (GNUNET_OK == 821 GNUNET_assert (GNUNET_OK ==
828 GNUNET_CONFIGURATION_get_value_string (cfg, "exit", 822 GNUNET_CONFIGURATION_get_value_string (cfg, "exit", "IPV4MASK",
829 "IPV4MASK", &ipv4mask)); 823 &ipv4mask));
830 inet_pton (AF_INET, ipv4addr, &tmp); 824 inet_pton (AF_INET, ipv4addr, &tmp);
831 inet_pton (AF_INET, ipv4mask, &tmp2); 825 inet_pton (AF_INET, ipv4mask, &tmp2);
832 GNUNET_free (ipv4addr); 826 GNUNET_free (ipv4addr);
@@ -910,8 +904,8 @@ prepare_ipv6_packet (ssize_t len, ssize_t pktlen, void *payload,
910 unsigned long long ipv6prefix; 904 unsigned long long ipv6prefix;
911 905
912 GNUNET_assert (GNUNET_OK == 906 GNUNET_assert (GNUNET_OK ==
913 GNUNET_CONFIGURATION_get_value_string (cfg, "exit", 907 GNUNET_CONFIGURATION_get_value_string (cfg, "exit", "IPV6ADDR",
914 "IPV6ADDR", &ipv6addr)); 908 &ipv6addr));
915 GNUNET_assert (GNUNET_OK == 909 GNUNET_assert (GNUNET_OK ==
916 GNUNET_CONFIGURATION_get_value_number (cfg, "exit", 910 GNUNET_CONFIGURATION_get_value_number (cfg, "exit",
917 "IPV6PREFIX", 911 "IPV6PREFIX",
@@ -987,9 +981,10 @@ prepare_ipv6_packet (ssize_t len, ssize_t pktlen, void *payload,
987 * The messages are one GNUNET_HashCode for the service followed by a struct tcp_pkt 981 * The messages are one GNUNET_HashCode for the service followed by a struct tcp_pkt
988 */ 982 */
989static int 983static int
990receive_tcp_service (void *cls __attribute__ ((unused)), 984receive_tcp_service (void *cls
991 struct GNUNET_MESH_Tunnel *tunnel, 985 __attribute__ ((unused)),
992 void **tunnel_ctx __attribute__ ((unused)), 986 struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx
987 __attribute__ ((unused)),
993 const struct GNUNET_PeerIdentity *sender 988 const struct GNUNET_PeerIdentity *sender
994 __attribute__ ((unused)), 989 __attribute__ ((unused)),
995 const struct GNUNET_MessageHeader *message, 990 const struct GNUNET_MessageHeader *message,
@@ -999,9 +994,9 @@ receive_tcp_service (void *cls __attribute__ ((unused)),
999 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received TCP-Packet\n"); 994 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received TCP-Packet\n");
1000 GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); 995 GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
1001 struct tcp_pkt *pkt = (struct tcp_pkt *) (desc + 1); 996 struct tcp_pkt *pkt = (struct tcp_pkt *) (desc + 1);
1002 unsigned int pkt_len = ntohs (message->size) - sizeof (struct 997 unsigned int pkt_len =
1003 GNUNET_MessageHeader) 998 ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) -
1004 - sizeof (GNUNET_HashCode); 999 sizeof (GNUNET_HashCode);
1005 1000
1006 /** Get the configuration from the services-hashmap. 1001 /** Get the configuration from the services-hashmap.
1007 * 1002 *
@@ -1018,8 +1013,8 @@ receive_tcp_service (void *cls __attribute__ ((unused)),
1018 1013
1019 if (NULL == serv) 1014 if (NULL == serv)
1020 { 1015 {
1021 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1016 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "No service found for TCP dpt %d!\n",
1022 "No service found for TCP dpt %d!\n", *tcp_desc); 1017 *tcp_desc);
1023 return GNUNET_YES; 1018 return GNUNET_YES;
1024 } 1019 }
1025 1020
@@ -1045,7 +1040,8 @@ receive_tcp_service (void *cls __attribute__ ((unused)),
1045 state->hashmap = tcp_connections; 1040 state->hashmap = tcp_connections;
1046 memcpy (&state->desc, desc, sizeof (GNUNET_HashCode)); 1041 memcpy (&state->desc, desc, sizeof (GNUNET_HashCode));
1047 1042
1048 len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) + 1043 len =
1044 sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) +
1049 sizeof (struct ip6_hdr) + pkt_len; 1045 sizeof (struct ip6_hdr) + pkt_len;
1050 buf = alloca (len); 1046 buf = alloca (len);
1051 1047
@@ -1055,13 +1051,13 @@ receive_tcp_service (void *cls __attribute__ ((unused)),
1055 { 1051 {
1056 case 4: 1052 case 4:
1057 prepare_ipv4_packet (len, pkt_len, pkt, 0x06, /* TCP */ 1053 prepare_ipv4_packet (len, pkt_len, pkt, 0x06, /* TCP */
1058 &serv->v4.ip4address, 1054 &serv->v4.ip4address, tunnel, state,
1059 tunnel, state, (struct ip_pkt *) buf); 1055 (struct ip_pkt *) buf);
1060 break; 1056 break;
1061 case 6: 1057 case 6:
1062 prepare_ipv6_packet (len, pkt_len, pkt, 0x06, /* TCP */ 1058 prepare_ipv6_packet (len, pkt_len, pkt, 0x06, /* TCP */
1063 &serv->v6.ip6address, 1059 &serv->v6.ip6address, tunnel, state,
1064 tunnel, state, (struct ip6_pkt *) buf); 1060 (struct ip6_pkt *) buf);
1065 1061
1066 break; 1062 break;
1067 default: 1063 default:
@@ -1094,9 +1090,10 @@ receive_tcp_service (void *cls __attribute__ ((unused)),
1094} 1090}
1095 1091
1096static int 1092static int
1097receive_tcp_remote (void *cls __attribute__ ((unused)), 1093receive_tcp_remote (void *cls
1098 struct GNUNET_MESH_Tunnel *tunnel, 1094 __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel,
1099 void **tunnel_ctx __attribute__ ((unused)), 1095 void **tunnel_ctx
1096 __attribute__ ((unused)),
1100 const struct GNUNET_PeerIdentity *sender 1097 const struct GNUNET_PeerIdentity *sender
1101 __attribute__ ((unused)), 1098 __attribute__ ((unused)),
1102 const struct GNUNET_MessageHeader *message, 1099 const struct GNUNET_MessageHeader *message,
@@ -1120,7 +1117,8 @@ receive_tcp_remote (void *cls __attribute__ ((unused)),
1120 state->hashmap = tcp_connections; 1117 state->hashmap = tcp_connections;
1121 memcpy (&state->remote, s, sizeof (struct remote_addr)); 1118 memcpy (&state->remote, s, sizeof (struct remote_addr));
1122 1119
1123 len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) + 1120 len =
1121 sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) +
1124 sizeof (struct ip6_hdr) + pkt_len; 1122 sizeof (struct ip6_hdr) + pkt_len;
1125 buf = alloca (len); 1123 buf = alloca (len);
1126 1124
@@ -1169,9 +1167,10 @@ receive_tcp_remote (void *cls __attribute__ ((unused)),
1169} 1167}
1170 1168
1171static int 1169static int
1172receive_udp_remote (void *cls __attribute__ ((unused)), 1170receive_udp_remote (void *cls
1173 struct GNUNET_MESH_Tunnel *tunnel, 1171 __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel,
1174 void **tunnel_ctx __attribute__ ((unused)), 1172 void **tunnel_ctx
1173 __attribute__ ((unused)),
1175 const struct GNUNET_PeerIdentity *sender 1174 const struct GNUNET_PeerIdentity *sender
1176 __attribute__ ((unused)), 1175 __attribute__ ((unused)),
1177 const struct GNUNET_MessageHeader *message, 1176 const struct GNUNET_MessageHeader *message,
@@ -1185,8 +1184,7 @@ receive_udp_remote (void *cls __attribute__ ((unused)),
1185 size_t len; 1184 size_t len;
1186 1185
1187 GNUNET_assert (ntohs (pkt->len) == 1186 GNUNET_assert (ntohs (pkt->len) ==
1188 ntohs (message->size) - 1187 ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) -
1189 sizeof (struct GNUNET_MessageHeader) -
1190 sizeof (GNUNET_HashCode)); 1188 sizeof (GNUNET_HashCode));
1191 1189
1192 /* Prepare the state. 1190 /* Prepare the state.
@@ -1201,7 +1199,8 @@ receive_udp_remote (void *cls __attribute__ ((unused)),
1201 state->type = REMOTE; 1199 state->type = REMOTE;
1202 memcpy (&state->remote, s, sizeof (struct remote_addr)); 1200 memcpy (&state->remote, s, sizeof (struct remote_addr));
1203 1201
1204 len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) + 1202 len =
1203 sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) +
1205 sizeof (struct ip6_hdr) + ntohs (pkt->len); 1204 sizeof (struct ip6_hdr) + ntohs (pkt->len);
1206 buf = alloca (len); 1205 buf = alloca (len);
1207 1206
@@ -1249,9 +1248,10 @@ receive_udp_remote (void *cls __attribute__ ((unused)),
1249 * The messages are one GNUNET_HashCode for the service, followed by a struct udp_pkt 1248 * The messages are one GNUNET_HashCode for the service, followed by a struct udp_pkt
1250 */ 1249 */
1251static int 1250static int
1252receive_udp_service (void *cls __attribute__ ((unused)), 1251receive_udp_service (void *cls
1253 struct GNUNET_MESH_Tunnel *tunnel, 1252 __attribute__ ((unused)),
1254 void **tunnel_ctx __attribute__ ((unused)), 1253 struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx
1254 __attribute__ ((unused)),
1255 const struct GNUNET_PeerIdentity *sender 1255 const struct GNUNET_PeerIdentity *sender
1256 __attribute__ ((unused)), 1256 __attribute__ ((unused)),
1257 const struct GNUNET_MessageHeader *message, 1257 const struct GNUNET_MessageHeader *message,
@@ -1262,8 +1262,7 @@ receive_udp_service (void *cls __attribute__ ((unused)),
1262 struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1); 1262 struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1);
1263 1263
1264 GNUNET_assert (ntohs (pkt->len) == 1264 GNUNET_assert (ntohs (pkt->len) ==
1265 ntohs (message->size) - 1265 ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) -
1266 sizeof (struct GNUNET_MessageHeader) -
1267 sizeof (GNUNET_HashCode)); 1266 sizeof (GNUNET_HashCode));
1268 1267
1269 /* Get the configuration from the hashmap */ 1268 /* Get the configuration from the hashmap */
@@ -1277,8 +1276,8 @@ receive_udp_service (void *cls __attribute__ ((unused)),
1277 1276
1278 if (NULL == serv) 1277 if (NULL == serv)
1279 { 1278 {
1280 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1279 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "No service found for UDP dpt %d!\n",
1281 "No service found for UDP dpt %d!\n", *udp_desc); 1280 *udp_desc);
1282 return GNUNET_YES; 1281 return GNUNET_YES;
1283 } 1282 }
1284 1283
@@ -1304,7 +1303,8 @@ receive_udp_service (void *cls __attribute__ ((unused)),
1304 state->hashmap = udp_connections; 1303 state->hashmap = udp_connections;
1305 memcpy (&state->desc, desc, sizeof (GNUNET_HashCode)); 1304 memcpy (&state->desc, desc, sizeof (GNUNET_HashCode));
1306 1305
1307 len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) + 1306 len =
1307 sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) +
1308 sizeof (struct ip6_hdr) + ntohs (pkt->len); 1308 sizeof (struct ip6_hdr) + ntohs (pkt->len);
1309 buf = alloca (len); 1309 buf = alloca (len);
1310 1310
@@ -1314,13 +1314,13 @@ receive_udp_service (void *cls __attribute__ ((unused)),
1314 { 1314 {
1315 case 4: 1315 case 4:
1316 prepare_ipv4_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */ 1316 prepare_ipv4_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */
1317 &serv->v4.ip4address, 1317 &serv->v4.ip4address, tunnel, state,
1318 tunnel, state, (struct ip_pkt *) buf); 1318 (struct ip_pkt *) buf);
1319 break; 1319 break;
1320 case 6: 1320 case 6:
1321 prepare_ipv6_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */ 1321 prepare_ipv6_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */
1322 &serv->v6.ip6address, 1322 &serv->v6.ip6address, tunnel, state,
1323 tunnel, state, (struct ip6_pkt *) buf); 1323 (struct ip6_pkt *) buf);
1324 1324
1325 break; 1325 break;
1326 default: 1326 default:
@@ -1410,9 +1410,7 @@ connect_to_mesh ()
1410 * @param cfg_ configuration 1410 * @param cfg_ configuration
1411 */ 1411 */
1412static void 1412static void
1413run (void *cls, 1413run (void *cls, char *const *args __attribute__ ((unused)), const char *cfgfile
1414 char *const *args __attribute__ ((unused)),
1415 const char *cfgfile
1416 __attribute__ ((unused)), const struct GNUNET_CONFIGURATION_Handle *cfg_) 1414 __attribute__ ((unused)), const struct GNUNET_CONFIGURATION_Handle *cfg_)
1417{ 1415{
1418 cfg = cfg_; 1416 cfg = cfg_;
@@ -1454,10 +1452,7 @@ main (int argc, char *const *argv)
1454 }; 1452 };
1455 1453
1456 return (GNUNET_OK == 1454 return (GNUNET_OK ==
1457 GNUNET_PROGRAM_run (argc, 1455 GNUNET_PROGRAM_run (argc, argv, "exit", gettext_noop ("help text"),
1458 argv,
1459 "exit",
1460 gettext_noop ("help text"),
1461 options, &run, NULL)) ? ret : 1; 1456 options, &run, NULL)) ? ret : 1;
1462} 1457}
1463 1458
diff --git a/src/vpn/gnunet-daemon-vpn-dns.c b/src/vpn/gnunet-daemon-vpn-dns.c
index d6f842e34..9ee81011e 100644
--- a/src/vpn/gnunet-daemon-vpn-dns.c
+++ b/src/vpn/gnunet-daemon-vpn-dns.c
@@ -120,7 +120,8 @@ send_query (void *cls __attribute__ ((unused)), size_t size, void *buf)
120 * Connect to the service-dns 120 * Connect to the service-dns
121 */ 121 */
122void 122void
123connect_to_service_dns (void *cls __attribute__ ((unused)), 123connect_to_service_dns (void *cls
124 __attribute__ ((unused)),
124 const struct GNUNET_SCHEDULER_TaskContext *tc) 125 const struct GNUNET_SCHEDULER_TaskContext *tc)
125{ 126{
126 conn_task = GNUNET_SCHEDULER_NO_TASK; 127 conn_task = GNUNET_SCHEDULER_NO_TASK;
@@ -167,8 +168,9 @@ dns_answer_handler (void *cls
167 { 168 {
168 GNUNET_CLIENT_disconnect (dns_connection, GNUNET_NO); 169 GNUNET_CLIENT_disconnect (dns_connection, GNUNET_NO);
169 dns_connection = NULL; 170 dns_connection = NULL;
170 conn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 171 conn_task =
171 &connect_to_service_dns, NULL); 172 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
173 &connect_to_service_dns, NULL);
172 return; 174 return;
173 } 175 }
174 176
diff --git a/src/vpn/gnunet-daemon-vpn-helper.c b/src/vpn/gnunet-daemon-vpn-helper.c
index 65e92b8f9..71fdefc0a 100644
--- a/src/vpn/gnunet-daemon-vpn-helper.c
+++ b/src/vpn/gnunet-daemon-vpn-helper.c
@@ -122,13 +122,10 @@ start_helper_and_schedule (void *cls,
122 * When the helper dies, this function will be called again with the 122 * When the helper dies, this function will be called again with the
123 * helper_handle as cls. 123 * helper_handle as cls.
124 */ 124 */
125 helper_handle = start_helper (ifname, 125 helper_handle =
126 ipv6addr, 126 start_helper (ifname, ipv6addr, ipv6prefix, ipv4addr, ipv4mask,
127 ipv6prefix, 127 "vpn-gnunet", start_helper_and_schedule, message_token,
128 ipv4addr, 128 NULL);
129 ipv4mask,
130 "vpn-gnunet",
131 start_helper_and_schedule, message_token, NULL);
132 129
133 GNUNET_free (ipv6addr); 130 GNUNET_free (ipv6addr);
134 GNUNET_free (ipv6prefix); 131 GNUNET_free (ipv6prefix);
@@ -230,16 +227,15 @@ helper_write (void *cls
230 /* if more packets are available, reschedule */ 227 /* if more packets are available, reschedule */
231 if (answer_proc_head != NULL) 228 if (answer_proc_head != NULL)
232 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, 229 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
233 helper_handle->fh_to_helper, 230 helper_handle->fh_to_helper, &helper_write,
234 &helper_write, NULL); 231 NULL);
235} 232}
236 233
237/** 234/**
238 * Receive packets from the helper-process 235 * Receive packets from the helper-process
239 */ 236 */
240void 237void
241message_token (void *cls __attribute__ ((unused)), 238message_token (void *cls __attribute__ ((unused)), void *client
242 void *client
243 __attribute__ ((unused)), 239 __attribute__ ((unused)),
244 const struct GNUNET_MessageHeader *message) 240 const struct GNUNET_MessageHeader *message)
245{ 241{
@@ -274,17 +270,17 @@ message_token (void *cls __attribute__ ((unused)),
274 270
275 size_t size = 271 size_t size =
276 sizeof (struct GNUNET_MESH_Tunnel *) + 272 sizeof (struct GNUNET_MESH_Tunnel *) +
277 sizeof (struct GNUNET_MessageHeader) + 273 sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) +
278 sizeof (GNUNET_HashCode) + ntohs (pkt6->ip6_hdr.paylgth); 274 ntohs (pkt6->ip6_hdr.paylgth);
279 275
280 struct GNUNET_MESH_Tunnel **cls = GNUNET_malloc (size); 276 struct GNUNET_MESH_Tunnel **cls = GNUNET_malloc (size);
281 struct GNUNET_MessageHeader *hdr = 277 struct GNUNET_MessageHeader *hdr =
282 (struct GNUNET_MessageHeader *) (cls + 1); 278 (struct GNUNET_MessageHeader *) (cls + 1);
283 GNUNET_HashCode *hc = (GNUNET_HashCode *) (hdr + 1); 279 GNUNET_HashCode *hc = (GNUNET_HashCode *) (hdr + 1);
284 280
285 hdr->size = htons (sizeof (struct GNUNET_MessageHeader) + 281 hdr->size =
286 sizeof (GNUNET_HashCode) + 282 htons (sizeof (struct GNUNET_MessageHeader) +
287 ntohs (pkt6->ip6_hdr.paylgth)); 283 sizeof (GNUNET_HashCode) + ntohs (pkt6->ip6_hdr.paylgth));
288 284
289 GNUNET_MESH_ApplicationType app_type; 285 GNUNET_MESH_ApplicationType app_type;
290 286
@@ -295,21 +291,19 @@ message_token (void *cls __attribute__ ((unused)),
295 /* This is a mapping to a gnunet-service */ 291 /* This is a mapping to a gnunet-service */
296 memcpy (hc, &me->desc.service_descriptor, sizeof (GNUNET_HashCode)); 292 memcpy (hc, &me->desc.service_descriptor, sizeof (GNUNET_HashCode));
297 293
298 if (0x11 == pkt6->ip6_hdr.nxthdr 294 if (0x11 == pkt6->ip6_hdr.nxthdr &&
299 && (me->desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP)) 295 (me->desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP)) &&
300 && (port_in_ports (me->desc.ports, pkt6_udp->udp_hdr.dpt) 296 (port_in_ports (me->desc.ports, pkt6_udp->udp_hdr.dpt) ||
301 || testBit (me->additional_ports, 297 testBit (me->additional_ports, ntohs (pkt6_udp->udp_hdr.dpt))))
302 ntohs (pkt6_udp->udp_hdr.dpt))))
303 { 298 {
304 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP); 299 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP);
305 300
306 memcpy (hc + 1, &pkt6_udp->udp_hdr, ntohs (pkt6_udp->udp_hdr.len)); 301 memcpy (hc + 1, &pkt6_udp->udp_hdr, ntohs (pkt6_udp->udp_hdr.len));
307 302
308 } 303 }
309 else if (0x06 == pkt6->ip6_hdr.nxthdr 304 else if (0x06 == pkt6->ip6_hdr.nxthdr &&
310 && (me->desc. 305 (me->desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP))
311 service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP)) && 306 && (port_in_ports (me->desc.ports, pkt6_tcp->tcp_hdr.dpt)))
312 (port_in_ports (me->desc.ports, pkt6_tcp->tcp_hdr.dpt)))
313 { 307 {
314 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP); 308 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP);
315 309
@@ -323,10 +317,10 @@ message_token (void *cls __attribute__ ((unused)),
323 GNUNET_TIME_UNIT_FOREVER_REL, 317 GNUNET_TIME_UNIT_FOREVER_REL,
324 1, 318 1,
325 (struct 319 (struct
326 GNUNET_PeerIdentity 320 GNUNET_PeerIdentity *)
327 *) &me->desc.peer, 321 &me->desc.peer,
328 send_pkt_to_peer, 322 send_pkt_to_peer, NULL,
329 NULL, cls); 323 cls);
330 me->tunnel = *cls; 324 me->tunnel = *cls;
331 } 325 }
332 else if (NULL != cls) 326 else if (NULL != cls)
@@ -364,11 +358,12 @@ message_token (void *cls __attribute__ ((unused)),
364 } 358 }
365 if (me->tunnel == NULL && NULL != cls) 359 if (me->tunnel == NULL && NULL != cls)
366 { 360 {
367 *cls = GNUNET_MESH_peer_request_connect_by_type (mesh_handle, 361 *cls =
368 GNUNET_TIME_UNIT_FOREVER_REL, 362 GNUNET_MESH_peer_request_connect_by_type (mesh_handle,
369 app_type, 363 GNUNET_TIME_UNIT_FOREVER_REL,
370 send_pkt_to_peer, 364 app_type,
371 NULL, cls); 365 send_pkt_to_peer,
366 NULL, cls);
372 me->tunnel = *cls; 367 me->tunnel = *cls;
373 if (GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY == app_type) 368 if (GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY == app_type)
374 udp_tunnel = *cls; 369 udp_tunnel = *cls;
@@ -400,8 +395,8 @@ message_token (void *cls __attribute__ ((unused)),
400 /* ICMPv6 */ 395 /* ICMPv6 */
401 pkt6_icmp = (struct ip6_icmp *) pkt6; 396 pkt6_icmp = (struct ip6_icmp *) pkt6;
402 /* If this packet is an icmp-echo-request and a mapping exists, answer */ 397 /* If this packet is an icmp-echo-request and a mapping exists, answer */
403 if (pkt6_icmp->icmp_hdr.type == 0x80 398 if (pkt6_icmp->icmp_hdr.type == 0x80 &&
404 && (key = address6_mapping_exists (pkt6->ip6_hdr.dadr)) != NULL) 399 (key = address6_mapping_exists (pkt6->ip6_hdr.dadr)) != NULL)
405 { 400 {
406 GNUNET_free (key); 401 GNUNET_free (key);
407 pkt6_icmp = GNUNET_malloc (ntohs (pkt6->shdr.size)); 402 pkt6_icmp = GNUNET_malloc (ntohs (pkt6->shdr.size));
@@ -442,8 +437,7 @@ message_token (void *cls __attribute__ ((unused)),
442 GNUNET_assert (head != NULL); 437 GNUNET_assert (head != NULL);
443 438
444 if (dns_connection != NULL) 439 if (dns_connection != NULL)
445 GNUNET_CLIENT_notify_transmit_ready (dns_connection, 440 GNUNET_CLIENT_notify_transmit_ready (dns_connection, len,
446 len,
447 GNUNET_TIME_UNIT_FOREVER_REL, 441 GNUNET_TIME_UNIT_FOREVER_REL,
448 GNUNET_YES, &send_query, NULL); 442 GNUNET_YES, &send_query, NULL);
449 } 443 }
@@ -470,9 +464,8 @@ message_token (void *cls __attribute__ ((unused)),
470 464
471 size_t size = 465 size_t size =
472 sizeof (struct GNUNET_MESH_Tunnel *) + 466 sizeof (struct GNUNET_MESH_Tunnel *) +
473 sizeof (struct GNUNET_MessageHeader) + 467 sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) +
474 sizeof (GNUNET_HashCode) + ntohs (pkt->ip_hdr.tot_lngth) - 468 ntohs (pkt->ip_hdr.tot_lngth) - 4 * pkt->ip_hdr.hdr_lngth;
475 4 * pkt->ip_hdr.hdr_lngth;
476 469
477 struct GNUNET_MESH_Tunnel **cls = GNUNET_malloc (size); 470 struct GNUNET_MESH_Tunnel **cls = GNUNET_malloc (size);
478 struct GNUNET_MessageHeader *hdr = 471 struct GNUNET_MessageHeader *hdr =
@@ -493,20 +486,19 @@ message_token (void *cls __attribute__ ((unused)),
493 /* This is a mapping to a gnunet-service */ 486 /* This is a mapping to a gnunet-service */
494 memcpy (hc, &me->desc.service_descriptor, sizeof (GNUNET_HashCode)); 487 memcpy (hc, &me->desc.service_descriptor, sizeof (GNUNET_HashCode));
495 488
496 if (0x11 == pkt->ip_hdr.proto 489 if (0x11 == pkt->ip_hdr.proto &&
497 && (me->desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP)) 490 (me->desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP)) &&
498 && (port_in_ports (me->desc.ports, pkt_udp->udp_hdr.dpt) 491 (port_in_ports (me->desc.ports, pkt_udp->udp_hdr.dpt) ||
499 || testBit (me->additional_ports, 492 testBit (me->additional_ports, ntohs (pkt_udp->udp_hdr.dpt))))
500 ntohs (pkt_udp->udp_hdr.dpt))))
501 { 493 {
502 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP); 494 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP);
503 495
504 memcpy (hc + 1, &pkt_udp->udp_hdr, ntohs (pkt_udp->udp_hdr.len)); 496 memcpy (hc + 1, &pkt_udp->udp_hdr, ntohs (pkt_udp->udp_hdr.len));
505 497
506 } 498 }
507 else if (0x06 == pkt->ip_hdr.proto 499 else if (0x06 == pkt->ip_hdr.proto &&
508 && (me->desc.service_type & 500 (me->desc.
509 htonl (GNUNET_DNS_SERVICE_TYPE_TCP)) && 501 service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP)) &&
510 (port_in_ports (me->desc.ports, pkt_tcp->tcp_hdr.dpt))) 502 (port_in_ports (me->desc.ports, pkt_tcp->tcp_hdr.dpt)))
511 { 503 {
512 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP); 504 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP);
@@ -523,10 +515,10 @@ message_token (void *cls __attribute__ ((unused)),
523 GNUNET_TIME_UNIT_FOREVER_REL, 515 GNUNET_TIME_UNIT_FOREVER_REL,
524 1, 516 1,
525 (struct 517 (struct
526 GNUNET_PeerIdentity 518 GNUNET_PeerIdentity *)
527 *) &me->desc.peer, 519 &me->desc.peer,
528 send_pkt_to_peer, 520 send_pkt_to_peer, NULL,
529 NULL, cls); 521 cls);
530 me->tunnel = *cls; 522 me->tunnel = *cls;
531 } 523 }
532 else if (NULL != cls) 524 else if (NULL != cls)
@@ -563,11 +555,12 @@ message_token (void *cls __attribute__ ((unused)),
563 } 555 }
564 if (me->tunnel == NULL && NULL != cls) 556 if (me->tunnel == NULL && NULL != cls)
565 { 557 {
566 *cls = GNUNET_MESH_peer_request_connect_by_type (mesh_handle, 558 *cls =
567 GNUNET_TIME_UNIT_FOREVER_REL, 559 GNUNET_MESH_peer_request_connect_by_type (mesh_handle,
568 app_type, 560 GNUNET_TIME_UNIT_FOREVER_REL,
569 send_pkt_to_peer, 561 app_type,
570 NULL, cls); 562 send_pkt_to_peer,
563 NULL, cls);
571 me->tunnel = *cls; 564 me->tunnel = *cls;
572 } 565 }
573 else if (NULL != cls) 566 else if (NULL != cls)
diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c
index 3673b72c6..301ba90be 100644
--- a/src/vpn/gnunet-daemon-vpn.c
+++ b/src/vpn/gnunet-daemon-vpn.c
@@ -332,8 +332,7 @@ port_in_ports (uint64_t ports, uint16_t port)
332} 332}
333 333
334void 334void
335send_pkt_to_peer (void *cls, 335send_pkt_to_peer (void *cls, const struct GNUNET_PeerIdentity *peer,
336 const struct GNUNET_PeerIdentity *peer,
337 const struct GNUNET_TRANSPORT_ATS_Information *atsi 336 const struct GNUNET_TRANSPORT_ATS_Information *atsi
338 __attribute__ ((unused))) 337 __attribute__ ((unused)))
339{ 338{
@@ -429,8 +428,8 @@ new_ip6addr_remote (unsigned char *buf, unsigned char *addr, char addrlen)
429 unsigned long long ipv6prefix; 428 unsigned long long ipv6prefix;
430 429
431 GNUNET_assert (GNUNET_OK == 430 GNUNET_assert (GNUNET_OK ==
432 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", 431 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV6ADDR",
433 "IPV6ADDR", &ipv6addr)); 432 &ipv6addr));
434 GNUNET_assert (GNUNET_OK == 433 GNUNET_assert (GNUNET_OK ==
435 GNUNET_CONFIGURATION_get_value_number (cfg, "vpn", 434 GNUNET_CONFIGURATION_get_value_number (cfg, "vpn",
436 "IPV6PREFIX", 435 "IPV6PREFIX",
@@ -458,11 +457,11 @@ new_ip4addr_remote (unsigned char *buf, unsigned char *addr, char addrlen)
458 char *ipv4mask; 457 char *ipv4mask;
459 458
460 GNUNET_assert (GNUNET_OK == 459 GNUNET_assert (GNUNET_OK ==
461 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", 460 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV4ADDR",
462 "IPV4ADDR", &ipv4addr)); 461 &ipv4addr));
463 GNUNET_assert (GNUNET_OK == 462 GNUNET_assert (GNUNET_OK ==
464 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", 463 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV4MASK",
465 "IPV4MASK", &ipv4mask)); 464 &ipv4mask));
466 uint32_t mask; 465 uint32_t mask;
467 466
468 inet_pton (AF_INET, ipv4addr, buf); 467 inet_pton (AF_INET, ipv4addr, buf);
@@ -568,9 +567,9 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
568 GNUNET_CONTAINER_multihashmap_put (hashmap, &key, value, 567 GNUNET_CONTAINER_multihashmap_put (hashmap, &key, value,
569 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 568 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
570 569
571 value->heap_node = GNUNET_CONTAINER_heap_insert (heap, value, 570 value->heap_node =
572 GNUNET_TIME_absolute_get 571 GNUNET_CONTAINER_heap_insert (heap, value,
573 ().abs_value); 572 GNUNET_TIME_absolute_get ().abs_value);
574 if (GNUNET_CONTAINER_heap_get_size (heap) > max_mappings) 573 if (GNUNET_CONTAINER_heap_get_size (heap) > max_mappings)
575 GNUNET_SCHEDULER_add_now (collect_mappings, NULL); 574 GNUNET_SCHEDULER_add_now (collect_mappings, NULL);
576 } 575 }
@@ -696,9 +695,9 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
696 { 695 {
697 GNUNET_CONTAINER_multihashmap_put (hashmap, &key, value, 696 GNUNET_CONTAINER_multihashmap_put (hashmap, &key, value,
698 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 697 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
699 value->heap_node = GNUNET_CONTAINER_heap_insert (heap, value, 698 value->heap_node =
700 GNUNET_TIME_absolute_get 699 GNUNET_CONTAINER_heap_insert (heap, value,
701 ().abs_value); 700 GNUNET_TIME_absolute_get ().abs_value);
702 if (GNUNET_CONTAINER_heap_get_size (heap) > max_mappings) 701 if (GNUNET_CONTAINER_heap_get_size (heap) > max_mappings)
703 GNUNET_SCHEDULER_add_now (collect_mappings, NULL); 702 GNUNET_SCHEDULER_add_now (collect_mappings, NULL);
704 } 703 }
@@ -722,8 +721,8 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
722 unsigned char *c = ((unsigned char *) pkt) + ntohs (pkt->addroffset); 721 unsigned char *c = ((unsigned char *) pkt) + ntohs (pkt->addroffset);
723 722
724 new_ip4addr_remote (c, pkt->addr, pkt->addrsize); 723 new_ip4addr_remote (c, pkt->addr, pkt->addrsize);
725 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New mapping to %d.%d.%d.%d\n", 724 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New mapping to %d.%d.%d.%d\n", c[0],
726 c[0], c[1], c[2], c[3]); 725 c[1], c[2], c[3]);
727 unsigned char *k = (unsigned char *) &key; 726 unsigned char *k = (unsigned char *) &key;
728 727
729 /* 728 /*
@@ -755,9 +754,9 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
755 { 754 {
756 GNUNET_CONTAINER_multihashmap_put (hashmap, &key, value, 755 GNUNET_CONTAINER_multihashmap_put (hashmap, &key, value,
757 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 756 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
758 value->heap_node = GNUNET_CONTAINER_heap_insert (heap, value, 757 value->heap_node =
759 GNUNET_TIME_absolute_get 758 GNUNET_CONTAINER_heap_insert (heap, value,
760 ().abs_value); 759 GNUNET_TIME_absolute_get ().abs_value);
761 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 760 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
762 "Mapping is saved in the hashmap with key %08x.\n", 761 "Mapping is saved in the hashmap with key %08x.\n",
763 *((uint32_t *) (&key))); 762 *((uint32_t *) (&key)));
@@ -860,7 +859,8 @@ add_additional_port (struct map_entry *me, uint16_t port)
860static int 859static int
861receive_udp_back (void *cls 860receive_udp_back (void *cls
862 __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel, 861 __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel,
863 void **tunnel_ctx __attribute__ ((unused)), 862 void **tunnel_ctx
863 __attribute__ ((unused)),
864 const struct GNUNET_PeerIdentity *sender 864 const struct GNUNET_PeerIdentity *sender
865 __attribute__ ((unused)), 865 __attribute__ ((unused)),
866 const struct GNUNET_MessageHeader *message, 866 const struct GNUNET_MessageHeader *message,
@@ -931,8 +931,8 @@ receive_udp_back (void *cls
931 GNUNET_assert (me != NULL); 931 GNUNET_assert (me != NULL);
932 if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK) 932 if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK)
933 { 933 {
934 GNUNET_assert (me->desc. 934 GNUNET_assert (me->
935 service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP)); 935 desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP));
936 if (!port_in_ports (me->desc.ports, pkt6->udp_hdr.spt) && 936 if (!port_in_ports (me->desc.ports, pkt6->udp_hdr.spt) &&
937 !testBit (me->additional_ports, ntohs (pkt6->udp_hdr.spt))) 937 !testBit (me->additional_ports, ntohs (pkt6->udp_hdr.spt)))
938 { 938 {
@@ -1109,8 +1109,8 @@ receive_tcp_back (void *cls
1109 1109
1110 GNUNET_assert (me != NULL); 1110 GNUNET_assert (me != NULL);
1111 if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK) 1111 if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK)
1112 GNUNET_assert (me->desc. 1112 GNUNET_assert (me->
1113 service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP)); 1113 desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP));
1114 1114
1115 pkt6->tcp_hdr.crc = 0; 1115 pkt6->tcp_hdr.crc = 0;
1116 uint32_t sum = 0; 1116 uint32_t sum = 0;
@@ -1228,10 +1228,8 @@ receive_tcp_back (void *cls
1228 * @param cfg_ configuration 1228 * @param cfg_ configuration
1229 */ 1229 */
1230static void 1230static void
1231run (void *cls, 1231run (void *cls, char *const *args __attribute__ ((unused)), const char *cfgfilep
1232 char *const *args __attribute__ ((unused)), 1232 __attribute__ ((unused)), const struct GNUNET_CONFIGURATION_Handle *cfg_)
1233 const char *cfgfilep __attribute__ ((unused)),
1234 const struct GNUNET_CONFIGURATION_Handle *cfg_)
1235{ 1233{
1236 static const struct GNUNET_MESH_MessageHandler handlers[] = { 1234 static const struct GNUNET_MESH_MessageHandler handlers[] = {
1237 {receive_udp_back, GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK, 0}, 1235 {receive_udp_back, GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK, 0},
@@ -1274,10 +1272,7 @@ main (int argc, char *const *argv)
1274 }; 1272 };
1275 1273
1276 return (GNUNET_OK == 1274 return (GNUNET_OK ==
1277 GNUNET_PROGRAM_run (argc, 1275 GNUNET_PROGRAM_run (argc, argv, "vpn", gettext_noop ("help text"),
1278 argv,
1279 "vpn",
1280 gettext_noop ("help text"),
1281 options, &run, NULL)) ? ret : 1; 1276 options, &run, NULL)) ? ret : 1;
1282} 1277}
1283 1278
diff --git a/src/vpn/gnunet-dns-parser.c b/src/vpn/gnunet-dns-parser.c
index 70551af52..df0e63ed7 100644
--- a/src/vpn/gnunet-dns-parser.c
+++ b/src/vpn/gnunet-dns-parser.c
@@ -51,8 +51,8 @@ parse_dns_name (char *d, const unsigned char *src, unsigned short idx)
51 */ 51 */
52static unsigned short 52static unsigned short
53parse_dns_record (unsigned char *data, /*{{{ */ 53parse_dns_record (unsigned char *data, /*{{{ */
54 struct dns_record **dst, 54 struct dns_record **dst, unsigned short count,
55 unsigned short count, unsigned short idx) 55 unsigned short idx)
56{ 56{
57 int i; 57 int i;
58 unsigned short _idx; 58 unsigned short _idx;
diff --git a/src/vpn/gnunet-helper-vpn-api.c b/src/vpn/gnunet-helper-vpn-api.c
index 16bfcbd2e..379e75765 100644
--- a/src/vpn/gnunet-helper-vpn-api.c
+++ b/src/vpn/gnunet-helper-vpn-api.c
@@ -74,8 +74,9 @@ helper_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tsdkctx)
74 stop_helper (handle); 74 stop_helper (handle);
75 75
76 /* Restart the helper */ 76 /* Restart the helper */
77 shs_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 77 shs_task =
78 handle->restart_task, handle); 78 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
79 handle->restart_task, handle);
79 return; 80 return;
80 } 81 }
81 82
@@ -86,8 +87,9 @@ helper_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tsdkctx)
86 stop_helper (handle); 87 stop_helper (handle);
87 88
88 /* Restart the helper */ 89 /* Restart the helper */
89 shs_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 90 shs_task =
90 handle->restart_task, handle); 91 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
92 handle->restart_task, handle);
91 return; 93 return;
92 94
93 } 95 }
@@ -104,12 +106,9 @@ cleanup_helper (struct GNUNET_VPN_HELPER_Handle *handle)
104} 106}
105 107
106struct GNUNET_VPN_HELPER_Handle * 108struct GNUNET_VPN_HELPER_Handle *
107start_helper (const char *ifname, 109start_helper (const char *ifname, const char *ipv6addr, const char *ipv6prefix,
108 const char *ipv6addr, 110 const char *ipv4addr, const char *ipv4mask,
109 const char *ipv6prefix, 111 const char *process_name, GNUNET_SCHEDULER_Task restart_task,
110 const char *ipv4addr,
111 const char *ipv4mask, const char *process_name,
112 GNUNET_SCHEDULER_Task restart_task,
113 GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls) 112 GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls)
114{ 113{
115 struct GNUNET_VPN_HELPER_Handle *handle = 114 struct GNUNET_VPN_HELPER_Handle *handle =
diff --git a/src/vpn/gnunet-helper-vpn.c b/src/vpn/gnunet-helper-vpn.c
index 698c46f1d..ed97770cf 100644
--- a/src/vpn/gnunet-helper-vpn.c
+++ b/src/vpn/gnunet-helper-vpn.c
@@ -81,8 +81,8 @@ init_tun (char *dev)
81 81
82 if (-1 == (fd = open ("/dev/net/tun", O_RDWR))) 82 if (-1 == (fd = open ("/dev/net/tun", O_RDWR)))
83 { 83 {
84 fprintf (stderr, 84 fprintf (stderr, "Error opening `%s': %s\n", "/dev/net/tun",
85 "Error opening `%s': %s\n", "/dev/net/tun", strerror (errno)); 85 strerror (errno));
86 return -1; 86 return -1;
87 } 87 }
88 88
@@ -100,9 +100,8 @@ init_tun (char *dev)
100 100
101 if (-1 == ioctl (fd, TUNSETIFF, (void *) &ifr)) 101 if (-1 == ioctl (fd, TUNSETIFF, (void *) &ifr))
102 { 102 {
103 fprintf (stderr, 103 fprintf (stderr, "Error with ioctl on `%s': %s\n", "/dev/net/tun",
104 "Error with ioctl on `%s': %s\n", 104 strerror (errno));
105 "/dev/net/tun", strerror (errno));
106 close (fd); 105 close (fd);
107 return -1; 106 return -1;
108 } 107 }
@@ -132,8 +131,8 @@ set_address6 (const char *dev, const char *address, unsigned long prefix_len)
132 memset (&sa6, 0, sizeof (struct sockaddr_in6)); 131 memset (&sa6, 0, sizeof (struct sockaddr_in6));
133 if (1 != inet_pton (AF_INET6, address, sa6.sin6_addr.s6_addr)) 132 if (1 != inet_pton (AF_INET6, address, sa6.sin6_addr.s6_addr))
134 { 133 {
135 fprintf (stderr, 134 fprintf (stderr, "Failed to parse address `%s': %s\n", address,
136 "Failed to parse address `%s': %s\n", address, strerror (errno)); 135 strerror (errno));
137 exit (1); 136 exit (1);
138 } 137 }
139 138
@@ -165,8 +164,8 @@ set_address6 (const char *dev, const char *address, unsigned long prefix_len)
165 */ 164 */
166 if (-1 == ioctl (fd, SIOCSIFADDR, &ifr6)) 165 if (-1 == ioctl (fd, SIOCSIFADDR, &ifr6))
167 { 166 {
168 fprintf (stderr, 167 fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__,
169 "ioctl failed at line %d: %s\n", __LINE__, strerror (errno)); 168 strerror (errno));
170 exit (1); 169 exit (1);
171 } 170 }
172 171
@@ -175,8 +174,8 @@ set_address6 (const char *dev, const char *address, unsigned long prefix_len)
175 */ 174 */
176 if (-1 == ioctl (fd, SIOCGIFFLAGS, &ifr)) 175 if (-1 == ioctl (fd, SIOCGIFFLAGS, &ifr))
177 { 176 {
178 fprintf (stderr, 177 fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__,
179 "ioctl failed at line %d: %s\n", __LINE__, strerror (errno)); 178 strerror (errno));
180 exit (1); 179 exit (1);
181 } 180 }
182 181
@@ -186,8 +185,8 @@ set_address6 (const char *dev, const char *address, unsigned long prefix_len)
186 ifr.ifr_flags |= IFF_UP | IFF_RUNNING; 185 ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
187 if (-1 == ioctl (fd, SIOCSIFFLAGS, &ifr)) 186 if (-1 == ioctl (fd, SIOCSIFFLAGS, &ifr))
188 { 187 {
189 fprintf (stderr, 188 fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__,
190 "ioctl failed at line %d: %s\n", __LINE__, strerror (errno)); 189 strerror (errno));
191 exit (1); 190 exit (1);
192 } 191 }
193 192
@@ -224,8 +223,8 @@ set_address4 (const char *dev, const char *address, const char *mask)
224 */ 223 */
225 if (1 != inet_pton (AF_INET, address, &addr->sin_addr.s_addr)) 224 if (1 != inet_pton (AF_INET, address, &addr->sin_addr.s_addr))
226 { 225 {
227 fprintf (stderr, 226 fprintf (stderr, "Failed to parse address `%s': %s\n", address,
228 "Failed to parse address `%s': %s\n", address, strerror (errno)); 227 strerror (errno));
229 exit (1); 228 exit (1);
230 } 229 }
231 230
@@ -253,8 +252,8 @@ set_address4 (const char *dev, const char *address, const char *mask)
253 addr = (struct sockaddr_in *) &(ifr.ifr_netmask); 252 addr = (struct sockaddr_in *) &(ifr.ifr_netmask);
254 if (1 != inet_pton (AF_INET, mask, &addr->sin_addr.s_addr)) 253 if (1 != inet_pton (AF_INET, mask, &addr->sin_addr.s_addr))
255 { 254 {
256 fprintf (stderr, 255 fprintf (stderr, "Failed to parse address `%s': %s\n", mask,
257 "Failed to parse address `%s': %s\n", mask, strerror (errno)); 256 strerror (errno));
258 exit (1); 257 exit (1);
259 } 258 }
260 259
@@ -263,8 +262,8 @@ set_address4 (const char *dev, const char *address, const char *mask)
263 */ 262 */
264 if (-1 == ioctl (fd, SIOCSIFNETMASK, &ifr)) 263 if (-1 == ioctl (fd, SIOCSIFNETMASK, &ifr))
265 { 264 {
266 fprintf (stderr, 265 fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__,
267 "ioctl failed at line %d: %s\n", __LINE__, strerror (errno)); 266 strerror (errno));
268 exit (1); 267 exit (1);
269 } 268 }
270 269
@@ -273,8 +272,8 @@ set_address4 (const char *dev, const char *address, const char *mask)
273 */ 272 */
274 if (-1 == ioctl (fd, SIOCGIFFLAGS, &ifr)) 273 if (-1 == ioctl (fd, SIOCGIFFLAGS, &ifr))
275 { 274 {
276 fprintf (stderr, 275 fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__,
277 "ioctl failed at line %d: %s\n", __LINE__, strerror (errno)); 276 strerror (errno));
278 exit (1); 277 exit (1);
279 } 278 }
280 279
@@ -284,8 +283,8 @@ set_address4 (const char *dev, const char *address, const char *mask)
284 ifr.ifr_flags |= IFF_UP | IFF_RUNNING; 283 ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
285 if (-1 == ioctl (fd, SIOCSIFFLAGS, &ifr)) 284 if (-1 == ioctl (fd, SIOCSIFFLAGS, &ifr))
286 { 285 {
287 fprintf (stderr, 286 fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__,
288 "ioctl failed at line %d: %s\n", __LINE__, strerror (errno)); 287 strerror (errno));
289 exit (1); 288 exit (1);
290 } 289 }
291 290
@@ -545,8 +544,8 @@ main (int argc, char **argv)
545 if (0 != setresuid (uid, uid, uid)) 544 if (0 != setresuid (uid, uid, uid))
546 fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno)); 545 fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno));
547 if (SIG_ERR == signal (SIGPIPE, SIG_IGN)) 546 if (SIG_ERR == signal (SIGPIPE, SIG_IGN))
548 fprintf (stderr, 547 fprintf (stderr, "Failed to protect against SIGPIPE: %s\n",
549 "Failed to protect against SIGPIPE: %s\n", strerror (errno)); 548 strerror (errno));
550 run (fd_tun); 549 run (fd_tun);
551 close (fd_tun); 550 close (fd_tun);
552 return 0; 551 return 0;
diff --git a/src/vpn/gnunet-service-dns.c b/src/vpn/gnunet-service-dns.c
index 9959e9564..a267cab0d 100644
--- a/src/vpn/gnunet-service-dns.c
+++ b/src/vpn/gnunet-service-dns.c
@@ -146,11 +146,10 @@ hijack (void *cls
146 146
147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hijacking, port is %d\n", dnsoutport); 147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hijacking, port is %d\n", dnsoutport);
148 snprintf (port_s, 6, "%d", dnsoutport); 148 snprintf (port_s, 6, "%d", dnsoutport);
149 if (NULL != (proc = GNUNET_OS_start_process (NULL, 149 if (NULL !=
150 NULL, 150 (proc =
151 "gnunet-helper-hijack-dns", 151 GNUNET_OS_start_process (NULL, NULL, "gnunet-helper-hijack-dns",
152 "gnunet-hijack-dns", 152 "gnunet-hijack-dns", port_s, virt_dns, NULL)))
153 port_s, virt_dns, NULL)))
154 GNUNET_OS_process_close (proc); 153 GNUNET_OS_process_close (proc);
155 GNUNET_free (virt_dns); 154 GNUNET_free (virt_dns);
156} 155}
@@ -175,11 +174,11 @@ unhijack (unsigned short port)
175 174
176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "unHijacking, port is %d\n", port); 175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "unHijacking, port is %d\n", port);
177 snprintf (port_s, 6, "%d", port); 176 snprintf (port_s, 6, "%d", port);
178 if (NULL != (proc = GNUNET_OS_start_process (NULL, 177 if (NULL !=
179 NULL, 178 (proc =
180 "gnunet-helper-hijack-dns", 179 GNUNET_OS_start_process (NULL, NULL, "gnunet-helper-hijack-dns",
181 "gnunet-hijack-dns", 180 "gnunet-hijack-dns", "-d", port_s, virt_dns,
182 "-d", port_s, virt_dns, NULL))) 181 NULL)))
183 GNUNET_OS_process_close (proc); 182 GNUNET_OS_process_close (proc);
184 GNUNET_free (virt_dns); 183 GNUNET_free (virt_dns);
185} 184}
@@ -204,8 +203,7 @@ send_answer (void *cls, size_t size, void *buf)
204 203
205 /* When more data is to be sent, reschedule */ 204 /* When more data is to be sent, reschedule */
206 if (head != NULL) 205 if (head != NULL)
207 GNUNET_SERVER_notify_transmit_ready (cls, 206 GNUNET_SERVER_notify_transmit_ready (cls, ntohs (head->pkt.hdr.size),
208 ntohs (head->pkt.hdr.size),
209 GNUNET_TIME_UNIT_FOREVER_REL, 207 GNUNET_TIME_UNIT_FOREVER_REL,
210 &send_answer, cls); 208 &send_answer, cls);
211 209
@@ -371,19 +369,20 @@ send_mesh_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
371 369
372 struct tunnel_cls *cls_ = (struct tunnel_cls *) cls; 370 struct tunnel_cls *cls_ = (struct tunnel_cls *) cls;
373 371
374 cls_->tunnel = GNUNET_MESH_peer_request_connect_by_type (mesh_handle, 372 cls_->tunnel =
375 GNUNET_TIME_UNIT_HOURS, 373 GNUNET_MESH_peer_request_connect_by_type (mesh_handle,
376 GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER, 374 GNUNET_TIME_UNIT_HOURS,
377 mesh_connect, 375 GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER,
378 NULL, cls_); 376 mesh_connect, NULL, cls_);
379 377
380 remote_pending[cls_->dns.s.id] = cls_; 378 remote_pending[cls_->dns.s.id] = cls_;
381} 379}
382 380
383static int 381static int
384receive_mesh_query (void *cls __attribute__ ((unused)), 382receive_mesh_query (void *cls
385 struct GNUNET_MESH_Tunnel *tunnel, 383 __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel,
386 void **ctx __attribute__ ((unused)), 384 void **ctx
385 __attribute__ ((unused)),
387 const struct GNUNET_PeerIdentity *sender 386 const struct GNUNET_PeerIdentity *sender
388 __attribute__ ((unused)), 387 __attribute__ ((unused)),
389 const struct GNUNET_MessageHeader *message, 388 const struct GNUNET_MessageHeader *message,
@@ -404,8 +403,7 @@ receive_mesh_query (void *cls __attribute__ ((unused)),
404 query_states[dns->s.id].tunnel = tunnel; 403 query_states[dns->s.id].tunnel = tunnel;
405 query_states[dns->s.id].valid = GNUNET_YES; 404 query_states[dns->s.id].valid = GNUNET_YES;
406 405
407 GNUNET_NETWORK_socket_sendto (dnsout, 406 GNUNET_NETWORK_socket_sendto (dnsout, dns,
408 dns,
409 ntohs (message->size) - 407 ntohs (message->size) -
410 sizeof (struct GNUNET_MessageHeader), 408 sizeof (struct GNUNET_MessageHeader),
411 (struct sockaddr *) &dest, sizeof dest); 409 (struct sockaddr *) &dest, sizeof dest);
@@ -414,9 +412,10 @@ receive_mesh_query (void *cls __attribute__ ((unused)),
414} 412}
415 413
416static int 414static int
417receive_mesh_answer (void *cls __attribute__ ((unused)), 415receive_mesh_answer (void *cls
418 struct GNUNET_MESH_Tunnel *tunnel, 416 __attribute__ ((unused)),
419 void **ctx __attribute__ ((unused)), 417 struct GNUNET_MESH_Tunnel *tunnel, void **ctx
418 __attribute__ ((unused)),
420 const struct GNUNET_PeerIdentity *sender, 419 const struct GNUNET_PeerIdentity *sender,
421 const struct GNUNET_MessageHeader *message, 420 const struct GNUNET_MessageHeader *message,
422 const struct GNUNET_TRANSPORT_ATS_Information *atsi 421 const struct GNUNET_TRANSPORT_ATS_Information *atsi
@@ -426,8 +425,8 @@ receive_mesh_answer (void *cls __attribute__ ((unused)),
426 struct dns_pkt *dns = (struct dns_pkt *) (message + 1); 425 struct dns_pkt *dns = (struct dns_pkt *) (message + 1);
427 426
428 /* They sent us a packet we were not waiting for */ 427 /* They sent us a packet we were not waiting for */
429 if (remote_pending[dns->s.id] == NULL 428 if (remote_pending[dns->s.id] == NULL ||
430 || remote_pending[dns->s.id]->tunnel != tunnel) 429 remote_pending[dns->s.id]->tunnel != tunnel)
431 return GNUNET_OK; 430 return GNUNET_OK;
432 431
433 GNUNET_free (remote_pending[dns->s.id]); 432 GNUNET_free (remote_pending[dns->s.id]);
@@ -526,8 +525,7 @@ receive_mesh_answer (void *cls __attribute__ ((unused)),
526 525
527 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer); 526 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer);
528 527
529 GNUNET_SERVER_notify_transmit_ready (query_states[dns->s.id].client, 528 GNUNET_SERVER_notify_transmit_ready (query_states[dns->s.id].client, len,
530 len,
531 GNUNET_TIME_UNIT_FOREVER_REL, 529 GNUNET_TIME_UNIT_FOREVER_REL,
532 &send_answer, 530 &send_answer,
533 query_states[dns->s.id].client); 531 query_states[dns->s.id].client);
@@ -561,8 +559,8 @@ send_rev_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
561 559
562 size_t len = sizeof (struct answer_packet) - 1 + sizeof (struct dns_static) + 74 /* this is the length of a reverse ipv6-lookup */ 560 size_t len = sizeof (struct answer_packet) - 1 + sizeof (struct dns_static) + 74 /* this is the length of a reverse ipv6-lookup */
563 + sizeof (struct dns_query_line) + 2 /* To hold the pointer (as defined in RFC1035) to the name */ 561 + sizeof (struct dns_query_line) + 2 /* To hold the pointer (as defined in RFC1035) to the name */
564 + sizeof (struct dns_record_line) - 1 562 + sizeof (struct dns_record_line) - 1 -
565 - 2 /* We do not know the lenght of the answer yet */ ; 563 2 /* We do not know the lenght of the answer yet */ ;
566 564
567 struct answer_packet_list *answer = 565 struct answer_packet_list *answer =
568 GNUNET_malloc (len + 2 * sizeof (struct answer_packet_list *)); 566 GNUNET_malloc (len + 2 * sizeof (struct answer_packet_list *));
@@ -619,8 +617,7 @@ send_rev_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
619 617
620 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer); 618 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer);
621 619
622 GNUNET_SERVER_notify_transmit_ready (query_states[id].client, 620 GNUNET_SERVER_notify_transmit_ready (query_states[id].client, len,
623 len,
624 GNUNET_TIME_UNIT_FOREVER_REL, 621 GNUNET_TIME_UNIT_FOREVER_REL,
625 &send_answer, query_states[id].client); 622 &send_answer, query_states[id].client);
626} 623}
@@ -629,9 +626,9 @@ send_rev_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
629 * Receive a block from the dht. 626 * Receive a block from the dht.
630 */ 627 */
631static void 628static void
632receive_dht (void *cls, 629receive_dht (void *cls, struct GNUNET_TIME_Absolute exp
633 struct GNUNET_TIME_Absolute exp __attribute__ ((unused)), 630 __attribute__ ((unused)), const GNUNET_HashCode * key
634 const GNUNET_HashCode * key __attribute__ ((unused)), 631 __attribute__ ((unused)),
635 const struct GNUNET_PeerIdentity *const *get_path 632 const struct GNUNET_PeerIdentity *const *get_path
636 __attribute__ ((unused)), 633 __attribute__ ((unused)),
637 const struct GNUNET_PeerIdentity *const *put_path 634 const struct GNUNET_PeerIdentity *const *put_path
@@ -654,8 +651,7 @@ receive_dht (void *cls,
654 const struct GNUNET_DNS_Record *rec = data; 651 const struct GNUNET_DNS_Record *rec = data;
655 652
656 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 653 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
657 "Got block of size %d, peer: %08x, desc: %08x\n", 654 "Got block of size %d, peer: %08x, desc: %08x\n", size,
658 size,
659 *((unsigned int *) &rec->peer), 655 *((unsigned int *) &rec->peer),
660 *((unsigned int *) &rec->service_descriptor)); 656 *((unsigned int *) &rec->service_descriptor));
661 657
@@ -676,8 +672,8 @@ receive_dht (void *cls,
676 672
677 memcpy (&answer->pkt.service_descr.service_descriptor, 673 memcpy (&answer->pkt.service_descr.service_descriptor,
678 &rec->service_descriptor, sizeof (GNUNET_HashCode)); 674 &rec->service_descriptor, sizeof (GNUNET_HashCode));
679 memcpy (&answer->pkt.service_descr.service_type, 675 memcpy (&answer->pkt.service_descr.service_type, &rec->service_type,
680 &rec->service_type, sizeof (answer->pkt.service_descr.service_type)); 676 sizeof (answer->pkt.service_descr.service_type));
681 memcpy (&answer->pkt.service_descr.ports, &rec->ports, 677 memcpy (&answer->pkt.service_descr.ports, &rec->ports,
682 sizeof (answer->pkt.service_descr.ports)); 678 sizeof (answer->pkt.service_descr.ports));
683 679
@@ -730,8 +726,7 @@ receive_dht (void *cls,
730 726
731 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer); 727 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer);
732 728
733 GNUNET_SERVER_notify_transmit_ready (query_states[id].client, 729 GNUNET_SERVER_notify_transmit_ready (query_states[id].client, len,
734 len,
735 GNUNET_TIME_UNIT_FOREVER_REL, 730 GNUNET_TIME_UNIT_FOREVER_REL,
736 &send_answer, query_states[id].client); 731 &send_answer, query_states[id].client);
737 732
@@ -742,8 +737,8 @@ receive_dht (void *cls,
742 * This receives a GNUNET_MESSAGE_TYPE_REHIJACK and rehijacks the DNS 737 * This receives a GNUNET_MESSAGE_TYPE_REHIJACK and rehijacks the DNS
743 */ 738 */
744static void 739static void
745rehijack (void *cls __attribute__ ((unused)), 740rehijack (void *cls
746 struct GNUNET_SERVER_Client *client, 741 __attribute__ ((unused)), struct GNUNET_SERVER_Client *client,
747 const struct GNUNET_MessageHeader *message __attribute__ ((unused))) 742 const struct GNUNET_MessageHeader *message __attribute__ ((unused)))
748{ 743{
749 unhijack (dnsoutport); 744 unhijack (dnsoutport);
@@ -756,8 +751,8 @@ rehijack (void *cls __attribute__ ((unused)),
756 * This receives the dns-payload from the daemon-vpn and sends it on over the udp-socket 751 * This receives the dns-payload from the daemon-vpn and sends it on over the udp-socket
757 */ 752 */
758static void 753static void
759receive_query (void *cls __attribute__ ((unused)), 754receive_query (void *cls
760 struct GNUNET_SERVER_Client *client, 755 __attribute__ ((unused)), struct GNUNET_SERVER_Client *client,
761 const struct GNUNET_MessageHeader *message) 756 const struct GNUNET_MessageHeader *message)
762{ 757{
763 struct query_packet *pkt = (struct query_packet *) message; 758 struct query_packet *pkt = (struct query_packet *) message;
@@ -788,21 +783,18 @@ receive_query (void *cls __attribute__ ((unused)),
788 GNUNET_CRYPTO_hash (pdns->queries[0]->name, pdns->queries[0]->namelen, 783 GNUNET_CRYPTO_hash (pdns->queries[0]->name, pdns->queries[0]->namelen,
789 &key); 784 &key);
790 785
791 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 786 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Getting with key %08x, len is %d\n",
792 "Getting with key %08x, len is %d\n",
793 *((unsigned int *) &key), pdns->queries[0]->namelen); 787 *((unsigned int *) &key), pdns->queries[0]->namelen);
794 788
795 struct receive_dht_cls *cls = 789 struct receive_dht_cls *cls =
796 GNUNET_malloc (sizeof (struct receive_dht_cls)); 790 GNUNET_malloc (sizeof (struct receive_dht_cls));
797 cls->id = dns->s.id; 791 cls->id = dns->s.id;
798 792
799 cls->handle = GNUNET_DHT_get_start (dht, 793 cls->handle =
800 GNUNET_TIME_UNIT_MINUTES, 794 GNUNET_DHT_get_start (dht, GNUNET_TIME_UNIT_MINUTES,
801 GNUNET_BLOCK_TYPE_DNS, 795 GNUNET_BLOCK_TYPE_DNS, &key,
802 &key, 796 DEFAULT_GET_REPLICATION, GNUNET_DHT_RO_NONE, NULL,
803 DEFAULT_GET_REPLICATION, 797 0, NULL, 0, receive_dht, cls);
804 GNUNET_DHT_RO_NONE,
805 NULL, 0, NULL, 0, receive_dht, cls);
806 798
807 goto outfree; 799 goto outfree;
808 } 800 }
@@ -881,8 +873,8 @@ receive_query (void *cls __attribute__ ((unused)),
881 873
882 if (1 != inet_pton (AF_INET, virt_dns, &virt_dns_bytes)) 874 if (1 != inet_pton (AF_INET, virt_dns, &virt_dns_bytes))
883 { 875 {
884 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 876 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing 'VIRTDNS': %s; %m!\n",
885 "Error parsing 'VIRTDNS': %s; %m!\n", virt_dns); 877 virt_dns);
886 exit (1); 878 exit (1);
887 } 879 }
888 880
@@ -923,8 +915,7 @@ receive_query (void *cls __attribute__ ((unused)),
923 dest.sin_port = htons (53); 915 dest.sin_port = htons (53);
924 dest.sin_addr.s_addr = pkt->orig_to; 916 dest.sin_addr.s_addr = pkt->orig_to;
925 917
926 GNUNET_NETWORK_socket_sendto (dnsout, 918 GNUNET_NETWORK_socket_sendto (dnsout, dns,
927 dns,
928 ntohs (pkt->hdr.size) - 919 ntohs (pkt->hdr.size) -
929 sizeof (struct query_packet) + 1, 920 sizeof (struct query_packet) + 1,
930 (struct sockaddr *) &dest, sizeof dest); 921 (struct sockaddr *) &dest, sizeof dest);
@@ -963,8 +954,9 @@ open_port ()
963 /* Read the port we bound to */ 954 /* Read the port we bound to */
964 socklen_t addrlen = sizeof (struct sockaddr_in); 955 socklen_t addrlen = sizeof (struct sockaddr_in);
965 956
966 err = getsockname (GNUNET_NETWORK_get_fd (dnsout), 957 err =
967 (struct sockaddr *) &addr, &addrlen); 958 getsockname (GNUNET_NETWORK_get_fd (dnsout), (struct sockaddr *) &addr,
959 &addrlen);
968 960
969 dnsoutport = htons (addr.sin_port); 961 dnsoutport = htons (addr.sin_port);
970 962
@@ -1010,9 +1002,7 @@ read_response (void *cls
1010 unsigned char buf[len]; 1002 unsigned char buf[len];
1011 struct dns_pkt *dns = (struct dns_pkt *) buf; 1003 struct dns_pkt *dns = (struct dns_pkt *) buf;
1012 1004
1013 r = GNUNET_NETWORK_socket_recvfrom (dnsout, 1005 r = GNUNET_NETWORK_socket_recvfrom (dnsout, buf, sizeof (buf),
1014 buf,
1015 sizeof (buf),
1016 (struct sockaddr *) &addr, &addrlen); 1006 (struct sockaddr *) &addr, &addrlen);
1017 1007
1018 if (r < 0) 1008 if (r < 0)
@@ -1093,16 +1083,15 @@ read_response (void *cls
1093 1083
1094 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer); 1084 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer);
1095 1085
1096 GNUNET_SERVER_notify_transmit_ready (query_states 1086 GNUNET_SERVER_notify_transmit_ready (query_states[dns->s.id].client,
1097 [dns->s.id].client, len, 1087 len, GNUNET_TIME_UNIT_FOREVER_REL,
1098 GNUNET_TIME_UNIT_FOREVER_REL,
1099 &send_answer, 1088 &send_answer,
1100 query_states[dns->s.id].client); 1089 query_states[dns->s.id].client);
1101 } 1090 }
1102 } 1091 }
1103 } 1092 }
1104 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 1093 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, dnsout,
1105 dnsout, &read_response, NULL); 1094 &read_response, NULL);
1106} 1095}
1107 1096
1108 1097
@@ -1113,7 +1102,8 @@ read_response (void *cls
1113 * @param tc unused 1102 * @param tc unused
1114 */ 1103 */
1115static void 1104static void
1116cleanup_task (void *cls __attribute__ ((unused)), 1105cleanup_task (void *cls
1106 __attribute__ ((unused)),
1117 const struct GNUNET_SCHEDULER_TaskContext *tc) 1107 const struct GNUNET_SCHEDULER_TaskContext *tc)
1118{ 1108{
1119 GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)); 1109 GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN));
@@ -1236,23 +1226,18 @@ publish_name (const char *name, uint64_t ports, uint32_t service_type,
1236 (GNUNET_TIME_UNIT_HOURS, 2)); 1226 (GNUNET_TIME_UNIT_HOURS, 2));
1237 1227
1238 /* Sign the block */ 1228 /* Sign the block */
1239 if (GNUNET_OK != GNUNET_CRYPTO_rsa_sign (my_private_key, 1229 if (GNUNET_OK !=
1240 &data.purpose, &data.signature)) 1230 GNUNET_CRYPTO_rsa_sign (my_private_key, &data.purpose, &data.signature))
1241 { 1231 {
1242 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not sign DNS_Record\n"); 1232 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not sign DNS_Record\n");
1243 return; 1233 return;
1244 } 1234 }
1245 1235
1246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting with key %08x, size = %d\n",
1247 "Putting with key %08x, size = %d\n",
1248 *((unsigned int *) &data.service_descriptor), size); 1237 *((unsigned int *) &data.service_descriptor), size);
1249 1238
1250 GNUNET_DHT_put (dht, 1239 GNUNET_DHT_put (dht, &data.service_descriptor, DEFAULT_PUT_REPLICATION,
1251 &data.service_descriptor, 1240 GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_DNS, size,
1252 DEFAULT_PUT_REPLICATION,
1253 GNUNET_DHT_RO_NONE,
1254 GNUNET_BLOCK_TYPE_DNS,
1255 size,
1256 (char *) &data, 1241 (char *) &data,
1257 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS), 1242 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS),
1258 GNUNET_TIME_UNIT_MINUTES, NULL, NULL); 1243 GNUNET_TIME_UNIT_MINUTES, NULL, NULL);
@@ -1276,14 +1261,14 @@ publish_iterate (void *cls __attribute__ ((unused)), const char *section)
1276 char *udp_redirects, *tcp_redirects, *alternative_names, *alternative_name, 1261 char *udp_redirects, *tcp_redirects, *alternative_names, *alternative_name,
1277 *keyfile; 1262 *keyfile;
1278 1263
1279 GNUNET_CONFIGURATION_get_value_string (cfg, section, 1264 GNUNET_CONFIGURATION_get_value_string (cfg, section, "UDP_REDIRECTS",
1280 "UDP_REDIRECTS", &udp_redirects); 1265 &udp_redirects);
1281 GNUNET_CONFIGURATION_get_value_string (cfg, section, "TCP_REDIRECTS", 1266 GNUNET_CONFIGURATION_get_value_string (cfg, section, "TCP_REDIRECTS",
1282 &tcp_redirects); 1267 &tcp_redirects);
1283 1268
1284 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "GNUNETD", 1269 if (GNUNET_OK !=
1285 "HOSTKEY", 1270 GNUNET_CONFIGURATION_get_value_filename (cfg, "GNUNETD", "HOSTKEY",
1286 &keyfile)) 1271 &keyfile))
1287 { 1272 {
1288 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not read keyfile-value\n"); 1273 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not read keyfile-value\n");
1289 if (keyfile != NULL) 1274 if (keyfile != NULL)
@@ -1310,8 +1295,7 @@ publish_iterate (void *cls __attribute__ ((unused)), const char *section)
1310 1295
1311 publish_name (section, ports, service_type, my_private_key); 1296 publish_name (section, ports, service_type, my_private_key);
1312 1297
1313 GNUNET_CONFIGURATION_get_value_string (cfg, section, 1298 GNUNET_CONFIGURATION_get_value_string (cfg, section, "ALTERNATIVE_NAMES",
1314 "ALTERNATIVE_NAMES",
1315 &alternative_names); 1299 &alternative_names);
1316 for (alternative_name = strtok (alternative_names, " "); 1300 for (alternative_name = strtok (alternative_names, " ");
1317 alternative_name != NULL; alternative_name = strtok (NULL, " ")) 1301 alternative_name != NULL; alternative_name = strtok (NULL, " "))
@@ -1335,7 +1319,8 @@ publish_iterate (void *cls __attribute__ ((unused)), const char *section)
1335 * Publish a DNS-record in the DHT. 1319 * Publish a DNS-record in the DHT.
1336 */ 1320 */
1337static void 1321static void
1338publish_names (void *cls __attribute__ ((unused)), 1322publish_names (void *cls
1323 __attribute__ ((unused)),
1339 const struct GNUNET_SCHEDULER_TaskContext *tc) 1324 const struct GNUNET_SCHEDULER_TaskContext *tc)
1340{ 1325{
1341 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1326 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
@@ -1352,8 +1337,7 @@ publish_names (void *cls __attribute__ ((unused)),
1352 * @param cfg_ configuration to use 1337 * @param cfg_ configuration to use
1353 */ 1338 */
1354static void 1339static void
1355run (void *cls, 1340run (void *cls, struct GNUNET_SERVER_Handle *server,
1356 struct GNUNET_SERVER_Handle *server,
1357 const struct GNUNET_CONFIGURATION_Handle *cfg_) 1341 const struct GNUNET_CONFIGURATION_Handle *cfg_)
1358{ 1342{
1359 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 1343 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
@@ -1401,8 +1385,8 @@ run (void *cls,
1401 GNUNET_SCHEDULER_add_now (publish_names, NULL); 1385 GNUNET_SCHEDULER_add_now (publish_names, NULL);
1402 1386
1403 GNUNET_SERVER_add_handlers (server, handlers); 1387 GNUNET_SERVER_add_handlers (server, handlers);
1404 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 1388 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
1405 &cleanup_task, cls); 1389 cls);
1406} 1390}
1407 1391
1408/** 1392/**
@@ -1416,8 +1400,6 @@ int
1416main (int argc, char *const *argv) 1400main (int argc, char *const *argv)
1417{ 1401{
1418 return (GNUNET_OK == 1402 return (GNUNET_OK ==
1419 GNUNET_SERVICE_run (argc, 1403 GNUNET_SERVICE_run (argc, argv, "dns", GNUNET_SERVICE_OPTION_NONE,
1420 argv, 1404 &run, NULL)) ? 0 : 1;
1421 "dns",
1422 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
1423} 1405}