aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-11-04 14:00:32 +0000
committerChristian Grothoff <christian@grothoff.org>2011-11-04 14:00:32 +0000
commit83b19539f4d322b43683f5838b72e9ec2c8e6073 (patch)
treed0ab9329fcbefe360d9d14e2ace21a6b3396dfe9
parent28a2eb43281a1f08a67954f07beb9af3a9bc9a35 (diff)
downloadgnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.tar.gz
gnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.zip
curly wars / auto-indentation
-rw-r--r--src/ats-test/test_transport_ats_multiple_peers.c3
-rw-r--r--src/ats/ats.h53
-rw-r--r--src/ats/ats_api.c160
-rw-r--r--src/ats/ats_api_peer_change_preference.c51
-rw-r--r--src/ats/ats_api_performance.c225
-rw-r--r--src/ats/ats_api_scheduling.c302
-rw-r--r--src/ats/gnunet-service-ats.c49
-rw-r--r--src/ats/gnunet-service-ats_addresses.c236
-rw-r--r--src/ats/gnunet-service-ats_addresses.h20
-rw-r--r--src/ats/gnunet-service-ats_math.h9
-rw-r--r--src/ats/gnunet-service-ats_performance.c109
-rw-r--r--src/ats/gnunet-service-ats_performance.h20
-rw-r--r--src/ats/gnunet-service-ats_reservations.c56
-rw-r--r--src/ats/gnunet-service-ats_reservations.h7
-rw-r--r--src/ats/gnunet-service-ats_scheduling.c177
-rw-r--r--src/ats/gnunet-service-ats_scheduling.h27
-rw-r--r--src/ats/test_ats_api_bandwidth_consumption.c131
-rw-r--r--src/ats/test_ats_api_scheduling.c105
-rw-r--r--src/ats/test_ats_api_update_address.c3
-rw-r--r--src/block/block.c25
-rw-r--r--src/block/plugin_block_dht.c24
-rw-r--r--src/block/plugin_block_dns.c3
-rw-r--r--src/block/plugin_block_fs.c48
-rw-r--r--src/block/plugin_block_test.c14
-rw-r--r--src/chat/gnunet-service-chat.c27
-rw-r--r--src/core/core_api.c29
-rw-r--r--src/core/core_api_iterate_peers.c6
-rw-r--r--src/core/gnunet-core-list-connections.c2
-rw-r--r--src/core/gnunet-service-core.c8
-rw-r--r--src/core/gnunet-service-core.h2
-rw-r--r--src/core/gnunet-service-core_clients.c281
-rw-r--r--src/core/gnunet-service-core_clients.h39
-rw-r--r--src/core/gnunet-service-core_kx.c378
-rw-r--r--src/core/gnunet-service-core_kx.h25
-rw-r--r--src/core/gnunet-service-core_neighbours.c58
-rw-r--r--src/core/gnunet-service-core_neighbours.h6
-rw-r--r--src/core/gnunet-service-core_sessions.c242
-rw-r--r--src/core/gnunet-service-core_sessions.h25
-rw-r--r--src/core/gnunet-service-core_typemap.c60
-rw-r--r--src/core/gnunet-service-core_typemap.h20
-rw-r--r--src/core/test_core_api.c23
-rw-r--r--src/core/test_core_api_reliability.c19
-rw-r--r--src/core/test_core_api_send_to_self.c4
-rw-r--r--src/core/test_core_api_start_only.c15
-rw-r--r--src/core/test_core_quota_compliance.c76
-rw-r--r--src/datacache/datacache.c14
-rw-r--r--src/datacache/plugin_datacache_sqlite.c85
-rw-r--r--src/datastore/plugin_datastore_sqlite.c30
-rw-r--r--src/datastore/test_datastore_api.c6
-rw-r--r--src/dht/dht_api.c52
-rw-r--r--src/dht/gnunet-dht-get.c12
-rw-r--r--src/dht/gnunet-dht-put.c6
-rw-r--r--src/dht/gnunet-service-dht.c44
-rw-r--r--src/dht/gnunet-service-dht_clients.c491
-rw-r--r--src/dht/gnunet-service-dht_clients.h17
-rw-r--r--src/dht/gnunet-service-dht_datacache.c121
-rw-r--r--src/dht/gnunet-service-dht_datacache.h28
-rw-r--r--src/dht/gnunet-service-dht_hello.c36
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c982
-rw-r--r--src/dht/gnunet-service-dht_neighbours.h52
-rw-r--r--src/dht/gnunet-service-dht_nse.c10
-rw-r--r--src/dht/gnunet-service-dht_routing.c144
-rw-r--r--src/dht/gnunet-service-dht_routing.h27
-rw-r--r--src/dht/test_dht_2dtorus.c208
-rw-r--r--src/dht/test_dht_api.c16
-rw-r--r--src/dht/test_dht_multipeer.c210
-rw-r--r--src/dht/test_dht_twopeer.c30
-rw-r--r--src/dht/test_dht_twopeer_get_put.c22
-rw-r--r--src/dht/test_dht_twopeer_path_tracking.c24
-rw-r--r--src/dht/test_dht_twopeer_put_get.c21
-rw-r--r--src/dv/gnunet-service-dv.c40
-rw-r--r--src/dv/plugin_transport_dv.c4
-rw-r--r--src/dv/test_transport_api_dv.c12
-rw-r--r--src/fragmentation/fragmentation.c2
-rw-r--r--src/fragmentation/test_fragmentation.c8
-rw-r--r--src/fs/fs_file_information.c112
-rw-r--r--src/fs/fs_uri.c22
-rw-r--r--src/fs/gnunet-fs.c27
-rw-r--r--src/fs/gnunet-service-fs.c42
-rw-r--r--src/fs/gnunet-service-fs_cp.c85
-rw-r--r--src/fs/gnunet-service-fs_cp.h7
-rw-r--r--src/fs/gnunet-service-fs_indexing.c9
-rw-r--r--src/fs/gnunet-service-fs_lc.c3
-rw-r--r--src/fs/gnunet-service-fs_pe.c90
-rw-r--r--src/fs/gnunet-service-fs_pr.c91
-rw-r--r--src/fs/gnunet-service-fs_pr.h4
-rw-r--r--src/fs/gnunet-service-fs_put.c6
-rw-r--r--src/hello/hello.c4
-rw-r--r--src/hostlist/gnunet-daemon-hostlist.c4
-rw-r--r--src/hostlist/hostlist-client.c4
-rw-r--r--src/hostlist/hostlist-server.c2
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist.c3
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist_learning.c6
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist_reconnect.c3
-rw-r--r--src/include/gnunet_ats_service.h185
-rw-r--r--src/include/gnunet_block_lib.h4
-rw-r--r--src/include/gnunet_common.h8
-rw-r--r--src/include/gnunet_core_service.h14
-rw-r--r--src/include/gnunet_dht_service.h11
-rw-r--r--src/include/gnunet_mesh_service.h8
-rw-r--r--src/include/gnunet_plugin_lib.h14
-rw-r--r--src/include/gnunet_server_lib.h3
-rw-r--r--src/include/gnunet_strings_lib.h4
-rw-r--r--src/include/gnunet_transport_service.h10
-rw-r--r--src/mesh/gnunet-service-mesh.c905
-rw-r--r--src/mesh/mesh_api.c40
-rw-r--r--src/mesh/mesh_protocol.h2
-rw-r--r--src/mesh/mesh_tunnel_tree.c334
-rw-r--r--src/mesh/mesh_tunnel_tree.h49
-rw-r--r--src/mesh/test_mesh_api.c3
-rw-r--r--src/mesh/test_mesh_local_2.c7
-rw-r--r--src/mesh/test_mesh_small.c335
-rw-r--r--src/mesh/test_mesh_small_unicast_far.c111
-rw-r--r--src/mesh/test_mesh_tree_api.c142
-rw-r--r--src/nat/nat.c6
-rw-r--r--src/nat/test_nat_test.c3
-rw-r--r--src/nse/gnunet-nse-profiler.c12
-rw-r--r--src/nse/gnunet-service-nse.c17
-rw-r--r--src/statistics/statistics_api.c702
-rw-r--r--src/testing/test_testing_connect.c6
-rw-r--r--src/testing/test_testing_reconnect.c12
-rw-r--r--src/testing/test_testing_topology.c11
-rw-r--r--src/testing/testing.c7
-rw-r--r--src/testing/testing_group.c25
-rw-r--r--src/testing/testing_peergroup.c7
-rw-r--r--src/topology/gnunet-daemon-topology.c13
-rw-r--r--src/transport/gnunet-service-transport.c146
-rw-r--r--src/transport/gnunet-service-transport_blacklist.c4
-rw-r--r--src/transport/gnunet-service-transport_clients.c46
-rw-r--r--src/transport/gnunet-service-transport_hello.c3
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c886
-rw-r--r--src/transport/gnunet-service-transport_neighbours.h68
-rw-r--r--src/transport/gnunet-service-transport_validation.c53
-rw-r--r--src/transport/gnunet-transport-connect-running-peers.c24
-rw-r--r--src/transport/gnunet-transport-wlan-helper.c4
-rw-r--r--src/transport/gnunet-transport.c242
-rw-r--r--src/transport/gnunet_wlan_sender.c254
-rw-r--r--src/transport/plugin_transport_http.c263
-rw-r--r--src/transport/plugin_transport_http.h20
-rw-r--r--src/transport/plugin_transport_http_client.c181
-rw-r--r--src/transport/plugin_transport_http_server.c327
-rw-r--r--src/transport/plugin_transport_sat_constants.h20
-rw-r--r--src/transport/plugin_transport_tcp.c31
-rw-r--r--src/transport/plugin_transport_udp.c477
-rw-r--r--src/transport/plugin_transport_udp_new.c222
-rw-r--r--src/transport/plugin_transport_unix.c5
-rw-r--r--src/transport/plugin_transport_wlan.c413
-rw-r--r--src/transport/test_quota_compliance.c161
-rw-r--r--src/transport/test_transport_api.c82
-rw-r--r--src/transport/test_transport_api_disconnect.c98
-rw-r--r--src/transport/test_transport_api_limited_sockets.c28
-rw-r--r--src/transport/test_transport_api_reliability.c88
-rw-r--r--src/transport/test_transport_api_timeout.c43
-rw-r--r--src/transport/test_transport_api_unreliability.c45
-rw-r--r--src/transport/test_transport_api_unreliability_constant.c41
-rw-r--r--src/transport/test_transport_startonly.c14
-rw-r--r--src/transport/test_transport_testing.c68
-rw-r--r--src/transport/transport-testing.c134
-rw-r--r--src/transport/transport-testing.h36
-rw-r--r--src/transport/transport_api.c4
-rw-r--r--src/transport/transport_api_address_iterate.c5
-rw-r--r--src/util/bandwidth.c141
-rw-r--r--src/util/bio.c253
-rw-r--r--src/util/client.c804
-rw-r--r--src/util/common_allocation.c56
-rw-r--r--src/util/common_logging.c400
-rw-r--r--src/util/configuration.c768
-rw-r--r--src/util/connection.c1015
-rw-r--r--src/util/container_bloomfilter.c260
-rw-r--r--src/util/container_heap.c201
-rw-r--r--src/util/container_meta_data.c792
-rw-r--r--src/util/container_multihashmap.c235
-rw-r--r--src/util/container_slist.c72
-rw-r--r--src/util/crypto_aes.c77
-rw-r--r--src/util/crypto_crc.c12
-rw-r--r--src/util/crypto_hash.c214
-rw-r--r--src/util/crypto_hkdf.c118
-rw-r--r--src/util/crypto_kdf.c14
-rw-r--r--src/util/crypto_ksk.c513
-rw-r--r--src/util/crypto_random.c199
-rw-r--r--src/util/crypto_rsa.c753
-rw-r--r--src/util/disk.c1437
-rw-r--r--src/util/getopt.c1018
-rw-r--r--src/util/getopt_helpers.c171
-rw-r--r--src/util/gnunet-config-diff.c8
-rw-r--r--src/util/gnunet-resolver.c6
-rw-r--r--src/util/gnunet-service-resolver.c411
-rw-r--r--src/util/load.c46
-rw-r--r--src/util/network.c1072
-rw-r--r--src/util/os_installation.c274
-rw-r--r--src/util/os_network.c365
-rw-r--r--src/util/os_priority.c1110
-rw-r--r--src/util/peer.c102
-rw-r--r--src/util/perf_crypto_hash.c20
-rw-r--r--src/util/plugin.c143
-rw-r--r--src/util/program.c108
-rw-r--r--src/util/pseudonym.c277
-rw-r--r--src/util/resolver_api.c598
-rw-r--r--src/util/scheduler.c825
-rw-r--r--src/util/server.c769
-rw-r--r--src/util/server_mst.c264
-rw-r--r--src/util/server_nc.c205
-rw-r--r--src/util/server_tc.c76
-rw-r--r--src/util/service.c1406
-rw-r--r--src/util/signal.c16
-rw-r--r--src/util/strings.c404
-rw-r--r--src/util/test_bio.c55
-rw-r--r--src/util/test_client.c56
-rw-r--r--src/util/test_common_allocation.c24
-rw-r--r--src/util/test_common_logging.c53
-rw-r--r--src/util/test_common_logging_dummy.c4
-rw-r--r--src/util/test_common_logging_runtime_loglevels.c364
-rw-r--r--src/util/test_configuration.c477
-rw-r--r--src/util/test_connection.c64
-rw-r--r--src/util/test_connection_addressing.c69
-rw-r--r--src/util/test_connection_receive_cancel.c22
-rw-r--r--src/util/test_connection_timeout.c43
-rw-r--r--src/util/test_connection_timeout_no_connect.c16
-rw-r--r--src/util/test_connection_transmit_cancel.c15
-rw-r--r--src/util/test_container_bloomfilter.c206
-rw-r--r--src/util/test_container_heap.c14
-rw-r--r--src/util/test_container_meta_data.c256
-rw-r--r--src/util/test_container_multihashmap.c29
-rw-r--r--src/util/test_container_slist.c93
-rw-r--r--src/util/test_crypto_aes.c120
-rw-r--r--src/util/test_crypto_aes_weak.c127
-rw-r--r--src/util/test_crypto_hash.c13
-rw-r--r--src/util/test_crypto_hkdf.c94
-rw-r--r--src/util/test_crypto_ksk.c192
-rw-r--r--src/util/test_crypto_random.c18
-rw-r--r--src/util/test_crypto_rsa.c210
-rw-r--r--src/util/test_disk.c101
-rw-r--r--src/util/test_getopt.c68
-rw-r--r--src/util/test_os_network.c8
-rw-r--r--src/util/test_os_priority.c12
-rw-r--r--src/util/test_os_start_process.c78
-rw-r--r--src/util/test_peer.c46
-rw-r--r--src/util/test_plugin.c6
-rw-r--r--src/util/test_program.c18
-rw-r--r--src/util/test_pseudonym.c46
-rw-r--r--src/util/test_resolver_api.c267
-rw-r--r--src/util/test_scheduler.c16
-rw-r--r--src/util/test_scheduler_delay.c20
-rw-r--r--src/util/test_server.c45
-rw-r--r--src/util/test_server_disconnect.c21
-rw-r--r--src/util/test_server_with_client.c58
-rw-r--r--src/util/test_server_with_client_unix.c52
-rw-r--r--src/util/test_service.c77
-rw-r--r--src/util/test_strings.c24
-rw-r--r--src/util/test_time.c52
-rw-r--r--src/util/time.c62
-rw-r--r--src/util/winproc.c227
-rw-r--r--src/vpn/gnunet-daemon-exit.c178
-rw-r--r--src/vpn/gnunet-daemon-vpn-dns.c41
-rw-r--r--src/vpn/gnunet-daemon-vpn-helper.c315
-rw-r--r--src/vpn/gnunet-daemon-vpn.c111
-rw-r--r--src/vpn/gnunet-dns-parser.c182
-rw-r--r--src/vpn/gnunet-service-dns-p.h3
-rw-r--r--src/vpn/gnunet-service-dns.c676
259 files changed, 18265 insertions, 19233 deletions
diff --git a/src/ats-test/test_transport_ats_multiple_peers.c b/src/ats-test/test_transport_ats_multiple_peers.c
index c79454411..4d32dc462 100644
--- a/src/ats-test/test_transport_ats_multiple_peers.c
+++ b/src/ats-test/test_transport_ats_multiple_peers.c
@@ -605,8 +605,7 @@ send_task_f (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
605 605
606static void 606static void
607notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, 607notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
608 const struct GNUNET_ATS_Information *ats, 608 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
609 uint32_t ats_count)
610{ 609{
611 send_task = GNUNET_SCHEDULER_add_now (&send_task_f, NULL); 610 send_task = GNUNET_SCHEDULER_add_now (&send_task_f, NULL);
612} 611}
diff --git a/src/ats/ats.h b/src/ats/ats.h
index 3ae6fdb65..5b9fa8696 100644
--- a/src/ats/ats.h
+++ b/src/ats/ats.h
@@ -31,13 +31,12 @@
31 31
32enum StartFlag 32enum StartFlag
33{ 33{
34 34
35 START_FLAG_SCHEDULING = 0, 35 START_FLAG_SCHEDULING = 0,
36 36
37 START_FLAG_PERFORMANCE_WITH_PIC = 1, 37 START_FLAG_PERFORMANCE_WITH_PIC = 1,
38 38
39 START_FLAG_PERFORMANCE_NO_PIC = 2 39 START_FLAG_PERFORMANCE_NO_PIC = 2
40
41}; 40};
42 41
43 42
@@ -55,7 +54,7 @@ struct ClientStartMessage
55struct RequestAddressMessage 54struct RequestAddressMessage
56{ 55{
57 struct GNUNET_MessageHeader header; 56 struct GNUNET_MessageHeader header;
58 57
59 uint32_t reserved GNUNET_PACKED; 58 uint32_t reserved GNUNET_PACKED;
60 59
61 struct GNUNET_PeerIdentity peer; 60 struct GNUNET_PeerIdentity peer;
@@ -77,10 +76,10 @@ struct AddressUpdateMessage
77 uint32_t session_id GNUNET_PACKED; 76 uint32_t session_id GNUNET_PACKED;
78 77
79 /* followed by: 78 /* followed by:
80 - struct GNUNET_ATS_Information [ats_count]; 79 * - struct GNUNET_ATS_Information [ats_count];
81 - char address[address_length] 80 * - char address[address_length]
82 - char plugin_name[plugin_name_length] (including '\0'-termination). 81 * - char plugin_name[plugin_name_length] (including '\0'-termination).
83 */ 82 */
84 83
85}; 84};
86 85
@@ -99,9 +98,9 @@ struct AddressUseMessage
99 uint32_t session_id GNUNET_PACKED; 98 uint32_t session_id GNUNET_PACKED;
100 99
101 /* followed by: 100 /* followed by:
102 - char address[address_length] 101 * - char address[address_length]
103 - char plugin_name[plugin_name_length] (including '\0'-termination). 102 * - char plugin_name[plugin_name_length] (including '\0'-termination).
104 */ 103 */
105 104
106}; 105};
107 106
@@ -121,9 +120,9 @@ struct AddressDestroyedMessage
121 uint32_t session_id GNUNET_PACKED; 120 uint32_t session_id GNUNET_PACKED;
122 121
123 /* followed by: 122 /* followed by:
124 - char address[address_length] 123 * - char address[address_length]
125 - char plugin_name[plugin_name_length] (including '\0'-termination). 124 * - char plugin_name[plugin_name_length] (including '\0'-termination).
126 */ 125 */
127 126
128}; 127};
129 128
@@ -143,14 +142,14 @@ struct AddressSuggestionMessage
143 uint32_t session_id GNUNET_PACKED; 142 uint32_t session_id GNUNET_PACKED;
144 143
145 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out; 144 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
146 145
147 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; 146 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
148 147
149 /* followed by: 148 /* followed by:
150 - struct GNUNET_ATS_Information [ats_count]; 149 * - struct GNUNET_ATS_Information [ats_count];
151 - char address[address_length] 150 * - char address[address_length]
152 - char plugin_name[plugin_name_length] (including '\0'-termination). 151 * - char plugin_name[plugin_name_length] (including '\0'-termination).
153 */ 152 */
154 153
155}; 154};
156 155
@@ -168,14 +167,14 @@ struct PeerInformationMessage
168 uint16_t plugin_name_length GNUNET_PACKED; 167 uint16_t plugin_name_length GNUNET_PACKED;
169 168
170 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out; 169 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
171 170
172 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; 171 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
173 172
174 /* followed by: 173 /* followed by:
175 - struct GNUNET_ATS_Information [ats_count]; 174 * - struct GNUNET_ATS_Information [ats_count];
176 - char address[address_length] 175 * - char address[address_length]
177 - char plugin_name[plugin_name_length] (including '\0'-termination). 176 * - char plugin_name[plugin_name_length] (including '\0'-termination).
178 */ 177 */
179 178
180}; 179};
181 180
@@ -222,7 +221,7 @@ struct PreferenceInformation
222 uint32_t preference_kind GNUNET_PACKED; 221 uint32_t preference_kind GNUNET_PACKED;
223 222
224 float preference_value GNUNET_PACKED; 223 float preference_value GNUNET_PACKED;
225 224
226}; 225};
227 226
228 227
@@ -234,8 +233,8 @@ struct ChangePreferenceMessage
234 233
235 struct GNUNET_PeerIdentity peer; 234 struct GNUNET_PeerIdentity peer;
236 235
237 /* followed by 'num_preferences' 236 /* followed by 'num_preferences'
238 struct PreferenceInformation values */ 237 * struct PreferenceInformation values */
239}; 238};
240 239
241 240
diff --git a/src/ats/ats_api.c b/src/ats/ats_api.c
index 61d3895d2..e25f9a8ec 100644
--- a/src/ats/ats_api.c
+++ b/src/ats/ats_api.c
@@ -138,26 +138,22 @@ set_bw_connections (void *cls, const GNUNET_HashCode * key, void *value)
138 138
139 GNUNET_assert (GNUNET_SYSERR != ar->connected); 139 GNUNET_assert (GNUNET_SYSERR != ar->connected);
140 /* FIXME: ||1 because we currently NEVER get 'connected' events... */ 140 /* FIXME: ||1 because we currently NEVER get 'connected' events... */
141 if ( (GNUNET_YES == ar->connected) || 1) 141 if ((GNUNET_YES == ar->connected) || 1)
142 { 142 {
143 ar->bandwidth_in = sbc->bw_in; 143 ar->bandwidth_in = sbc->bw_in;
144 ar->bandwidth_out = sbc->bw_out; 144 ar->bandwidth_out = sbc->bw_out;
145 GNUNET_BANDWIDTH_tracker_update_quota (&ar->available_recv_window, 145 GNUNET_BANDWIDTH_tracker_update_quota (&ar->available_recv_window,
146 ar->bandwidth_in); 146 ar->bandwidth_in);
147 LOG (GNUNET_ERROR_TYPE_DEBUG, 147 LOG (GNUNET_ERROR_TYPE_DEBUG,
148 "Bandwidth assigned to peer %s is i:%u/o:%u bytes/s\n", 148 "Bandwidth assigned to peer %s is i:%u/o:%u bytes/s\n",
149 GNUNET_i2s ((const struct GNUNET_PeerIdentity *) key), 149 GNUNET_i2s ((const struct GNUNET_PeerIdentity *) key),
150 ntohl (ar->bandwidth_in.value__), 150 ntohl (ar->bandwidth_in.value__), ntohl (ar->bandwidth_out.value__));
151 ntohl (ar->bandwidth_out.value__));
152 if (NULL != sbc->atc->alloc_cb) 151 if (NULL != sbc->atc->alloc_cb)
153 sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls, 152 sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
154 (const struct GNUNET_PeerIdentity *) key, 153 (const struct GNUNET_PeerIdentity *) key,
155 ar->plugin_name, ar->plugin_addr, 154 ar->plugin_name, ar->plugin_addr, ar->plugin_addr_len,
156 ar->plugin_addr_len, 155 ar->session, ar->bandwidth_out, ar->bandwidth_in,
157 ar->session, 156 NULL, 0);
158 ar->bandwidth_out,
159 ar->bandwidth_in,
160 NULL, 0);
161 } 157 }
162 else if (ntohl (ar->bandwidth_out.value__) > 0) 158 else if (ntohl (ar->bandwidth_out.value__) > 0)
163 { 159 {
@@ -166,17 +162,16 @@ set_bw_connections (void *cls, const GNUNET_HashCode * key, void *value)
166 if (NULL != sbc->atc->alloc_cb) 162 if (NULL != sbc->atc->alloc_cb)
167 sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls, 163 sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
168 (const struct GNUNET_PeerIdentity *) key, 164 (const struct GNUNET_PeerIdentity *) key,
169 ar->plugin_name, ar->plugin_addr, 165 ar->plugin_name, ar->plugin_addr, ar->plugin_addr_len,
170 ar->plugin_addr_len, ar->session, ar->bandwidth_out, 166 ar->session, ar->bandwidth_out, ar->bandwidth_in,
171 ar->bandwidth_in, NULL, 0); 167 NULL, 0);
172 } 168 }
173 else 169 else
174 LOG (GNUNET_ERROR_TYPE_DEBUG, 170 LOG (GNUNET_ERROR_TYPE_DEBUG,
175 "Not communicating bandwidth assigned to peer %s: not connected and bw is: i:%u/o:%u bytes/s\n", 171 "Not communicating bandwidth assigned to peer %s: not connected and bw is: i:%u/o:%u bytes/s\n",
176 GNUNET_i2s ((const struct GNUNET_PeerIdentity *) key), 172 GNUNET_i2s ((const struct GNUNET_PeerIdentity *) key),
177 ntohl (ar->bandwidth_in.value__), 173 ntohl (ar->bandwidth_in.value__), ntohl (ar->bandwidth_out.value__));
178 ntohl (ar->bandwidth_out.value__)); 174
179
180 return GNUNET_YES; 175 return GNUNET_YES;
181} 176}
182 177
@@ -205,9 +200,8 @@ update_bandwidth_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
205 bwc.bw_out = GNUNET_BANDWIDTH_value_init (atc->total_bps_out / ac); 200 bwc.bw_out = GNUNET_BANDWIDTH_value_init (atc->total_bps_out / ac);
206 LOG (GNUNET_ERROR_TYPE_DEBUG, 201 LOG (GNUNET_ERROR_TYPE_DEBUG,
207 "Trivial implementation: bandwidth assigned to each peer is i:%u/o:%u bytes/s\n", 202 "Trivial implementation: bandwidth assigned to each peer is i:%u/o:%u bytes/s\n",
208 ntohl (bwc.bw_in.value__), 203 ntohl (bwc.bw_in.value__), ntohl (bwc.bw_out.value__));
209 ntohl (bwc.bw_out.value__)); 204 GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &set_bw_connections, &bwc);
210 GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &set_bw_connections, &bwc);
211} 205}
212 206
213 207
@@ -244,9 +238,8 @@ suggest_address (void *cls, const GNUNET_HashCode * key, void *value)
244#if DEBUG_ATS 238#if DEBUG_ATS
245 LOG (GNUNET_ERROR_TYPE_DEBUG, 239 LOG (GNUNET_ERROR_TYPE_DEBUG,
246 "Suggesting address for peer `%s', starting with i:%u/o:%u bytes/s\n", 240 "Suggesting address for peer `%s', starting with i:%u/o:%u bytes/s\n",
247 GNUNET_h2s (key), 241 GNUNET_h2s (key), asc->atc->total_bps_in / 32,
248 asc->atc->total_bps_in/32, 242 asc->atc->total_bps_out / 32);
249 asc->atc->total_bps_out/32);
250#endif 243#endif
251 244
252 /* trivial strategy: pick first available address... */ 245 /* trivial strategy: pick first available address... */
@@ -285,8 +278,8 @@ GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *atc,
285 struct GNUNET_ATS_SuggestionContext *asc; 278 struct GNUNET_ATS_SuggestionContext *asc;
286 279
287#if DEBUG_ATS 280#if DEBUG_ATS
288 LOG (GNUNET_ERROR_TYPE_DEBUG, 281 LOG (GNUNET_ERROR_TYPE_DEBUG, "Looking up suggested address for peer `%s'\n",
289 "Looking up suggested address for peer `%s'\n", GNUNET_i2s (peer)); 282 GNUNET_i2s (peer));
290#endif 283#endif
291 asc = GNUNET_malloc (sizeof (struct GNUNET_ATS_SuggestionContext)); 284 asc = GNUNET_malloc (sizeof (struct GNUNET_ATS_SuggestionContext));
292 asc->cb = cb; 285 asc->cb = cb;
@@ -441,70 +434,70 @@ update_session (void *cls, const GNUNET_HashCode * key, void *value)
441 434
442 if (0 != strcmp (arnew->plugin_name, arold->plugin_name)) 435 if (0 != strcmp (arnew->plugin_name, arold->plugin_name))
443 return GNUNET_YES; 436 return GNUNET_YES;
444 if (! (((arnew->session == arold->session) && (arnew->session != NULL)) || 437 if (!
445 ((arold->session == NULL) && 438 (((arnew->session == arold->session) && (arnew->session != NULL)) ||
446 (arold->plugin_addr_len == arnew->plugin_addr_len) && 439 ((arold->session == NULL) &&
447 (0 == 440 (arold->plugin_addr_len == arnew->plugin_addr_len) &&
448 memcmp (arold->plugin_addr, arnew->plugin_addr, 441 (0 ==
449 arnew->plugin_addr_len))))) 442 memcmp (arold->plugin_addr, arnew->plugin_addr,
450 return GNUNET_YES; /* no match */ 443 arnew->plugin_addr_len)))))
444 return GNUNET_YES; /* no match */
451 /* records match */ 445 /* records match */
452#if DEBUG_ATS 446#if DEBUG_ATS
453 LOG (GNUNET_ERROR_TYPE_DEBUG, 447 LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating session for peer `%s' plugin `%s'\n",
454 "Updating session for peer `%s' plugin `%s'\n", GNUNET_h2s (key), 448 GNUNET_h2s (key), arold->plugin_name);
455 arold->plugin_name);
456#endif 449#endif
457 if (arnew->session != arold->session) 450 if (arnew->session != arold->session)
458 { 451 {
459 arold->session = arnew->session; 452 arold->session = arnew->session;
460 } 453 }
461 if ((arnew->connected == GNUNET_YES) && (arold->connected == GNUNET_NO)) 454 if ((arnew->connected == GNUNET_YES) && (arold->connected == GNUNET_NO))
462 { 455 {
463 arold->connected = GNUNET_YES; 456 arold->connected = GNUNET_YES;
464 } 457 }
465 458
466 /* Update existing value */ 459 /* Update existing value */
467 c_new = 0; 460 c_new = 0;
468 while (c_new < arnew->ats_count) 461 while (c_new < arnew->ats_count)
462 {
463 c_old = 0;
464 found = GNUNET_NO;
465 while (c_old < arold->ats_count)
469 { 466 {
470 c_old = 0; 467 if (arold->ats[c_old].type == arnew->ats[c_new].type)
471 found = GNUNET_NO;
472 while (c_old < arold->ats_count)
473 { 468 {
474 if (arold->ats[c_old].type == arnew->ats[c_new].type)
475 {
476#if DEBUG_ATS 469#if DEBUG_ATS
477 LOG (GNUNET_ERROR_TYPE_DEBUG, 470 LOG (GNUNET_ERROR_TYPE_DEBUG,
478 "Found type %i, old value=%i new value=%i\n", 471 "Found type %i, old value=%i new value=%i\n",
479 ntohl (arold->ats[c_old].type), ntohl (arold->ats[c_old].value), 472 ntohl (arold->ats[c_old].type), ntohl (arold->ats[c_old].value),
480 ntohl (arnew->ats[c_new].value)); 473 ntohl (arnew->ats[c_new].value));
481#endif 474#endif
482 arold->ats[c_old].value = arnew->ats[c_new].value; 475 arold->ats[c_old].value = arnew->ats[c_new].value;
483 found = GNUNET_YES; 476 found = GNUNET_YES;
484 }
485 c_old++;
486 } 477 }
487 /* Add new value */ 478 c_old++;
488 if (found == GNUNET_NO) 479 }
489 { 480 /* Add new value */
481 if (found == GNUNET_NO)
482 {
490#if DEBUG_ATS 483#if DEBUG_ATS
491 LOG (GNUNET_ERROR_TYPE_DEBUG, "Added new type %i new value=%i\n", 484 LOG (GNUNET_ERROR_TYPE_DEBUG, "Added new type %i new value=%i\n",
492 ntohl (arnew->ats[c_new].type), ntohl (arnew->ats[c_new].value)); 485 ntohl (arnew->ats[c_new].type), ntohl (arnew->ats[c_new].value));
493 LOG (GNUNET_ERROR_TYPE_DEBUG, "Old array size: %u\n", arold->ats_count); 486 LOG (GNUNET_ERROR_TYPE_DEBUG, "Old array size: %u\n", arold->ats_count);
494#endif 487#endif
495 GNUNET_array_grow (arold->ats, arold->ats_count, arold->ats_count + 1); 488 GNUNET_array_grow (arold->ats, arold->ats_count, arold->ats_count + 1);
496 GNUNET_assert (arold->ats_count >= 2); 489 GNUNET_assert (arold->ats_count >= 2);
497 arold->ats[arold->ats_count - 2].type = arnew->ats[c_new].type; 490 arold->ats[arold->ats_count - 2].type = arnew->ats[c_new].type;
498 arold->ats[arold->ats_count - 2].value = arnew->ats[c_new].value; 491 arold->ats[arold->ats_count - 2].value = arnew->ats[c_new].value;
499 arold->ats[arold->ats_count - 1].type = htonl (0); 492 arold->ats[arold->ats_count - 1].type = htonl (0);
500 arold->ats[arold->ats_count - 1].value = htonl (0); 493 arold->ats[arold->ats_count - 1].value = htonl (0);
501#if DEBUG_ATS 494#if DEBUG_ATS
502 LOG (GNUNET_ERROR_TYPE_DEBUG, "New array size: %i\n", arold->ats_count); 495 LOG (GNUNET_ERROR_TYPE_DEBUG, "New array size: %i\n", arold->ats_count);
503#endif 496#endif
504 }
505 c_new++;
506 } 497 }
507 498 c_new++;
499 }
500
508 update_bandwidth_assignment (usc->atc, arold); 501 update_bandwidth_assignment (usc->atc, arold);
509 return GNUNET_NO; 502 return GNUNET_NO;
510} 503}
@@ -538,9 +531,8 @@ create_allocation_record (const char *plugin_name, struct Session *session,
538 MAX_WINDOW_TIME_S); 531 MAX_WINDOW_TIME_S);
539 GNUNET_assert (ats_count > 0); 532 GNUNET_assert (ats_count > 0);
540 GNUNET_array_grow (ar->ats, ar->ats_count, ats_count); 533 GNUNET_array_grow (ar->ats, ar->ats_count, ats_count);
541 memcpy (ar->ats, ats, 534 memcpy (ar->ats, ats, ats_count * sizeof (struct GNUNET_ATS_Information));
542 ats_count * sizeof (struct GNUNET_ATS_Information)); 535 ar->connected = GNUNET_SYSERR; /* aka: not known / no change */
543 ar->connected = GNUNET_SYSERR; /* aka: not known / no change */
544 return ar; 536 return ar;
545} 537}
546 538
@@ -594,11 +586,9 @@ GNUNET_ATS_peer_connect (struct GNUNET_ATS_SchedulingHandle *atc,
594 struct UpdateSessionContext usc; 586 struct UpdateSessionContext usc;
595 587
596#if DEBUG_ATS 588#if DEBUG_ATS
597 LOG (GNUNET_ERROR_TYPE_DEBUG, 589 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connected to peer %s\n", GNUNET_i2s (peer));
598 "Connected to peer %s\n",
599 GNUNET_i2s (peer));
600#endif 590#endif
601 591
602 (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &disconnect_peer, 592 (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &disconnect_peer,
603 atc); 593 atc);
604 ar = create_allocation_record (plugin_name, session, plugin_addr, 594 ar = create_allocation_record (plugin_name, session, plugin_addr,
@@ -632,8 +622,7 @@ GNUNET_ATS_peer_disconnect (struct GNUNET_ATS_SchedulingHandle *atc,
632 const struct GNUNET_PeerIdentity *peer) 622 const struct GNUNET_PeerIdentity *peer)
633{ 623{
634#if DEBUG_ATS 624#if DEBUG_ATS
635 LOG (GNUNET_ERROR_TYPE_DEBUG, 625 LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnected from peer %s\n",
636 "Disconnected from peer %s\n",
637 GNUNET_i2s (peer)); 626 GNUNET_i2s (peer));
638#endif 627#endif
639 (void) GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers, 628 (void) GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers,
@@ -768,9 +757,8 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *atc,
768 struct UpdateSessionContext usc; 757 struct UpdateSessionContext usc;
769 758
770#if DEBUG_ATS 759#if DEBUG_ATS
771 LOG (GNUNET_ERROR_TYPE_DEBUG, 760 LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating address for peer `%s', plugin `%s'\n",
772 "Updating address for peer `%s', plugin `%s'\n", GNUNET_i2s (peer), 761 GNUNET_i2s (peer), plugin_name);
773 plugin_name);
774#endif 762#endif
775 ar = create_allocation_record (plugin_name, session, plugin_addr, 763 ar = create_allocation_record (plugin_name, session, plugin_addr,
776 plugin_addr_len, ats, ats_count); 764 plugin_addr_len, ats, ats_count);
@@ -783,7 +771,7 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *atc,
783 return; 771 return;
784 } 772 }
785#if DEBUG_ATS 773#if DEBUG_ATS
786 LOG (GNUNET_ERROR_TYPE_DEBUG, 774 LOG (GNUNET_ERROR_TYPE_DEBUG,
787 "Adding new address for peer `%s', plugin `%s'\n", GNUNET_i2s (peer), 775 "Adding new address for peer `%s', plugin `%s'\n", GNUNET_i2s (peer),
788 plugin_name); 776 plugin_name);
789#endif 777#endif
diff --git a/src/ats/ats_api_peer_change_preference.c b/src/ats/ats_api_peer_change_preference.c
index 322727e63..7290ebb7a 100644
--- a/src/ats/ats_api_peer_change_preference.c
+++ b/src/ats/ats_api_peer_change_preference.c
@@ -49,17 +49,16 @@ struct GNUNET_ATS_InformationRequestContext
49 GNUNET_ATS_PeerConfigurationInfoCallback info; 49 GNUNET_ATS_PeerConfigurationInfoCallback info;
50 50
51 void *info_cls; 51 void *info_cls;
52 52
53 struct GNUNET_PeerIdentity peer; 53 struct GNUNET_PeerIdentity peer;
54 54
55 GNUNET_SCHEDULER_TaskIdentifier task; 55 GNUNET_SCHEDULER_TaskIdentifier task;
56 56
57}; 57};
58 58
59 59
60static void 60static void
61exec_pcp (void *cls, 61exec_pcp (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
62 const struct GNUNET_SCHEDULER_TaskContext *tc)
63{ 62{
64 struct GNUNET_ATS_InformationRequestContext *irc = cls; 63 struct GNUNET_ATS_InformationRequestContext *irc = cls;
65 int32_t want_reserv; 64 int32_t want_reserv;
@@ -69,16 +68,13 @@ exec_pcp (void *cls,
69 68
70 rdelay = GNUNET_TIME_UNIT_ZERO; 69 rdelay = GNUNET_TIME_UNIT_ZERO;
71 want_reserv = irc->amount; 70 want_reserv = irc->amount;
72 ar = GNUNET_CONTAINER_multihashmap_get (irc->h->peers, &irc->peer.hashPubKey); 71 ar = GNUNET_CONTAINER_multihashmap_get (irc->h->peers, &irc->peer.hashPubKey);
73 if (NULL == ar) 72 if (NULL == ar)
74 { 73 {
75 /* attempt to change preference on peer that is not connected */ 74 /* attempt to change preference on peer that is not connected */
76 /* FIXME: this can happen if the 'service' didn't yet tell us about 75 /* FIXME: this can happen if the 'service' didn't yet tell us about
77 a new connection, fake it! */ 76 * a new connection, fake it! */
78 irc->info (irc->info_cls, 77 irc->info (irc->info_cls, &irc->peer, want_reserv, rdelay);
79 &irc->peer,
80 want_reserv,
81 rdelay);
82 GNUNET_free (irc); 78 GNUNET_free (irc);
83 return; 79 return;
84 } 80 }
@@ -89,21 +85,18 @@ exec_pcp (void *cls,
89 else if (want_reserv > 0) 85 else if (want_reserv > 0)
90 { 86 {
91 rdelay = 87 rdelay =
92 GNUNET_BANDWIDTH_tracker_get_delay (&ar->available_recv_window, 88 GNUNET_BANDWIDTH_tracker_get_delay (&ar->available_recv_window,
93 want_reserv); 89 want_reserv);
94 if (rdelay.rel_value == 0) 90 if (rdelay.rel_value == 0)
95 got_reserv = want_reserv; 91 got_reserv = want_reserv;
96 else 92 else
97 got_reserv = 0; /* all or nothing */ 93 got_reserv = 0; /* all or nothing */
98 } 94 }
99 else 95 else
100 got_reserv = 0; 96 got_reserv = 0;
101 GNUNET_BANDWIDTH_tracker_consume (&ar->available_recv_window, got_reserv); 97 GNUNET_BANDWIDTH_tracker_consume (&ar->available_recv_window, got_reserv);
102 98
103 irc->info (irc->info_cls, 99 irc->info (irc->info_cls, &irc->peer, got_reserv, rdelay);
104 &irc->peer,
105 got_reserv,
106 rdelay);
107 GNUNET_free (irc); 100 GNUNET_free (irc);
108} 101}
109 102
@@ -125,10 +118,10 @@ exec_pcp (void *cls,
125 */ 118 */
126struct GNUNET_ATS_InformationRequestContext * 119struct GNUNET_ATS_InformationRequestContext *
127GNUNET_ATS_peer_change_preference (struct GNUNET_ATS_SchedulingHandle *h, 120GNUNET_ATS_peer_change_preference (struct GNUNET_ATS_SchedulingHandle *h,
128 const struct GNUNET_PeerIdentity *peer, 121 const struct GNUNET_PeerIdentity *peer,
129 int32_t amount, uint64_t preference, 122 int32_t amount, uint64_t preference,
130 GNUNET_ATS_PeerConfigurationInfoCallback 123 GNUNET_ATS_PeerConfigurationInfoCallback
131 info, void *info_cls) 124 info, void *info_cls)
132{ 125{
133 struct GNUNET_ATS_InformationRequestContext *irc; 126 struct GNUNET_ATS_InformationRequestContext *irc;
134 127
@@ -157,8 +150,8 @@ GNUNET_ATS_peer_change_preference (struct GNUNET_ATS_SchedulingHandle *h,
157 */ 150 */
158void 151void
159GNUNET_ATS_peer_change_preference_cancel (struct 152GNUNET_ATS_peer_change_preference_cancel (struct
160 GNUNET_ATS_InformationRequestContext 153 GNUNET_ATS_InformationRequestContext
161 *irc) 154 *irc)
162{ 155{
163 GNUNET_SCHEDULER_cancel (irc->task); 156 GNUNET_SCHEDULER_cancel (irc->task);
164 GNUNET_free (irc); 157 GNUNET_free (irc);
@@ -219,10 +212,10 @@ change_preference_send_continuation (void *cls, int success)
219 */ 212 */
220struct GNUNET_ATS_InformationRequestContext * 213struct GNUNET_ATS_InformationRequestContext *
221GNUNET_ATS_peer_change_preference (struct GNUNET_ATS_SchedulingHandle *h, 214GNUNET_ATS_peer_change_preference (struct GNUNET_ATS_SchedulingHandle *h,
222 const struct GNUNET_PeerIdentity *peer, 215 const struct GNUNET_PeerIdentity *peer,
223 int32_t amount, uint64_t preference, 216 int32_t amount, uint64_t preference,
224 GNUNET_ATS_PeerConfigurationInfoCallback 217 GNUNET_ATS_PeerConfigurationInfoCallback
225 info, void *info_cls) 218 info, void *info_cls)
226{ 219{
227 struct GNUNET_ATS_InformationRequestContext *irc; 220 struct GNUNET_ATS_InformationRequestContext *irc;
228 struct PeerRecord *pr; 221 struct PeerRecord *pr;
@@ -287,8 +280,8 @@ GNUNET_ATS_peer_change_preference (struct GNUNET_ATS_SchedulingHandle *h,
287 */ 280 */
288void 281void
289GNUNET_ATS_peer_change_preference_cancel (struct 282GNUNET_ATS_peer_change_preference_cancel (struct
290 GNUNET_ATS_InformationRequestContext 283 GNUNET_ATS_InformationRequestContext
291 *irc) 284 *irc)
292{ 285{
293 struct GNUNET_ATS_SchedulingHandle *h = irc->h; 286 struct GNUNET_ATS_SchedulingHandle *h = irc->h;
294 struct PeerRecord *pr = irc->pr; 287 struct PeerRecord *pr = irc->pr;
diff --git a/src/ats/ats_api_performance.c b/src/ats/ats_api_performance.c
index ba124fe21..ca489e4a6 100644
--- a/src/ats/ats_api_performance.c
+++ b/src/ats/ats_api_performance.c
@@ -37,12 +37,12 @@ struct PendingMessage
37 37
38 /** 38 /**
39 * Kept in a DLL. 39 * Kept in a DLL.
40 */ 40 */
41 struct PendingMessage *next; 41 struct PendingMessage *next;
42 42
43 /** 43 /**
44 * Kept in a DLL. 44 * Kept in a DLL.
45 */ 45 */
46 struct PendingMessage *prev; 46 struct PendingMessage *prev;
47 47
48 /** 48 /**
@@ -52,7 +52,7 @@ struct PendingMessage
52 52
53 /** 53 /**
54 * Is this the 'ATS_START' message? 54 * Is this the 'ATS_START' message?
55 */ 55 */
56 int is_init; 56 int is_init;
57}; 57};
58 58
@@ -65,19 +65,19 @@ struct GNUNET_ATS_ReservationContext
65 65
66 /** 66 /**
67 * Kept in a DLL. 67 * Kept in a DLL.
68 */ 68 */
69 struct GNUNET_ATS_ReservationContext *next; 69 struct GNUNET_ATS_ReservationContext *next;
70 70
71 /** 71 /**
72 * Kept in a DLL. 72 * Kept in a DLL.
73 */ 73 */
74 struct GNUNET_ATS_ReservationContext *prev; 74 struct GNUNET_ATS_ReservationContext *prev;
75 75
76 /** 76 /**
77 * Target peer. 77 * Target peer.
78 */ 78 */
79 struct GNUNET_PeerIdentity peer; 79 struct GNUNET_PeerIdentity peer;
80 80
81 /** 81 /**
82 * Desired reservation 82 * Desired reservation
83 */ 83 */
@@ -110,7 +110,7 @@ struct GNUNET_ATS_ReservationContext
110 */ 110 */
111struct GNUNET_ATS_PerformanceHandle 111struct GNUNET_ATS_PerformanceHandle
112{ 112{
113 113
114 /** 114 /**
115 * Our configuration. 115 * Our configuration.
116 */ 116 */
@@ -120,7 +120,7 @@ struct GNUNET_ATS_PerformanceHandle
120 * Callback to invoke on performance changes. 120 * Callback to invoke on performance changes.
121 */ 121 */
122 GNUNET_ATS_PeerInformationCallback infocb; 122 GNUNET_ATS_PeerInformationCallback infocb;
123 123
124 /** 124 /**
125 * Closure for 'infocb'. 125 * Closure for 'infocb'.
126 */ 126 */
@@ -158,9 +158,9 @@ struct GNUNET_ATS_PerformanceHandle
158 158
159 /** 159 /**
160 * Task to trigger reconnect. 160 * Task to trigger reconnect.
161 */ 161 */
162 GNUNET_SCHEDULER_TaskIdentifier task; 162 GNUNET_SCHEDULER_TaskIdentifier task;
163 163
164}; 164};
165 165
166 166
@@ -180,8 +180,7 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph);
180 * @param tc scheduler context 180 * @param tc scheduler context
181 */ 181 */
182static void 182static void
183reconnect_task (void *cls, 183reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
184 const struct GNUNET_SCHEDULER_TaskContext *tc)
185{ 184{
186 struct GNUNET_ATS_PerformanceHandle *ph = cls; 185 struct GNUNET_ATS_PerformanceHandle *ph = cls;
187 186
@@ -209,9 +208,7 @@ do_transmit (struct GNUNET_ATS_PerformanceHandle *ph);
209 * @return number of bytes copied into buf 208 * @return number of bytes copied into buf
210 */ 209 */
211static size_t 210static size_t
212transmit_message_to_ats (void *cls, 211transmit_message_to_ats (void *cls, size_t size, void *buf)
213 size_t size,
214 void *buf)
215{ 212{
216 struct GNUNET_ATS_PerformanceHandle *ph = cls; 213 struct GNUNET_ATS_PerformanceHandle *ph = cls;
217 struct PendingMessage *p; 214 struct PendingMessage *p;
@@ -221,15 +218,12 @@ transmit_message_to_ats (void *cls,
221 ph->th = NULL; 218 ph->th = NULL;
222 ret = 0; 219 ret = 0;
223 cbuf = buf; 220 cbuf = buf;
224 while ( (NULL != (p = ph->pending_head)) && 221 while ((NULL != (p = ph->pending_head)) && (p->size <= size))
225 (p->size <= size) )
226 { 222 {
227 memcpy (&cbuf[ret], &p[1], p->size); 223 memcpy (&cbuf[ret], &p[1], p->size);
228 ret += p->size; 224 ret += p->size;
229 size -= p->size; 225 size -= p->size;
230 GNUNET_CONTAINER_DLL_remove (ph->pending_head, 226 GNUNET_CONTAINER_DLL_remove (ph->pending_head, ph->pending_tail, p);
231 ph->pending_tail,
232 p);
233 GNUNET_free (p); 227 GNUNET_free (p);
234 } 228 }
235 do_transmit (ph); 229 do_transmit (ph);
@@ -253,12 +247,12 @@ do_transmit (struct GNUNET_ATS_PerformanceHandle *ph)
253 if (NULL == (p = ph->pending_head)) 247 if (NULL == (p = ph->pending_head))
254 return; 248 return;
255 if (NULL == ph->client) 249 if (NULL == ph->client)
256 return; /* currently reconnecting */ 250 return; /* currently reconnecting */
257 ph->th = GNUNET_CLIENT_notify_transmit_ready (ph->client, 251 ph->th =
258 p->size, 252 GNUNET_CLIENT_notify_transmit_ready (ph->client, p->size,
259 GNUNET_TIME_UNIT_FOREVER_REL, 253 GNUNET_TIME_UNIT_FOREVER_REL,
260 GNUNET_YES, 254 GNUNET_YES, &transmit_message_to_ats,
261 &transmit_message_to_ats, ph); 255 ph);
262} 256}
263 257
264 258
@@ -271,7 +265,7 @@ do_transmit (struct GNUNET_ATS_PerformanceHandle *ph)
271 */ 265 */
272static int 266static int
273process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, 267process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph,
274 const struct GNUNET_MessageHeader *msg) 268 const struct GNUNET_MessageHeader *msg)
275{ 269{
276 const struct PeerInformationMessage *pi; 270 const struct PeerInformationMessage *pi;
277 const struct GNUNET_ATS_Information *atsi; 271 const struct GNUNET_ATS_Information *atsi;
@@ -285,37 +279,31 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph,
285 { 279 {
286 GNUNET_break (0); 280 GNUNET_break (0);
287 return GNUNET_SYSERR; 281 return GNUNET_SYSERR;
288 } 282 }
289 if (ntohs (msg->size) < sizeof (struct PeerInformationMessage)) 283 if (ntohs (msg->size) < sizeof (struct PeerInformationMessage))
290 { 284 {
291 GNUNET_break (0); 285 GNUNET_break (0);
292 return GNUNET_SYSERR; 286 return GNUNET_SYSERR;
293 } 287 }
294 pi = (const struct PeerInformationMessage*) msg; 288 pi = (const struct PeerInformationMessage *) msg;
295 ats_count = ntohl (pi->ats_count); 289 ats_count = ntohl (pi->ats_count);
296 address_length = ntohs (pi->address_length); 290 address_length = ntohs (pi->address_length);
297 plugin_name_length = ntohs (pi->plugin_name_length); 291 plugin_name_length = ntohs (pi->plugin_name_length);
298 atsi = (const struct GNUNET_ATS_Information*) &pi[1]; 292 atsi = (const struct GNUNET_ATS_Information *) &pi[1];
299 address = (const char*) &atsi[ats_count]; 293 address = (const char *) &atsi[ats_count];
300 plugin_name = &address[address_length]; 294 plugin_name = &address[address_length];
301 if ( (address_length + 295 if ((address_length + plugin_name_length +
302 plugin_name_length + 296 ats_count * sizeof (struct GNUNET_ATS_Information) +
303 ats_count * sizeof (struct GNUNET_ATS_Information) + 297 sizeof (struct PeerInformationMessage) != ntohs (msg->size)) ||
304 sizeof (struct PeerInformationMessage) != ntohs (msg->size)) || 298 (ats_count >
305 (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) || 299 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information))
306 (plugin_name[plugin_name_length - 1] != '\0') ) 300 || (plugin_name[plugin_name_length - 1] != '\0'))
307 { 301 {
308 GNUNET_break (0); 302 GNUNET_break (0);
309 return GNUNET_SYSERR; 303 return GNUNET_SYSERR;
310 } 304 }
311 ph->infocb (ph->infocb_cls, 305 ph->infocb (ph->infocb_cls, &pi->peer, plugin_name, address, address_length,
312 &pi->peer, 306 pi->bandwidth_out, pi->bandwidth_in, atsi, ats_count);
313 plugin_name,
314 address, address_length,
315 pi->bandwidth_out,
316 pi->bandwidth_in,
317 atsi,
318 ats_count);
319 return GNUNET_OK; 307 return GNUNET_OK;
320} 308}
321 309
@@ -329,7 +317,7 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph,
329 */ 317 */
330static int 318static int
331process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph, 319process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph,
332 const struct GNUNET_MessageHeader *msg) 320 const struct GNUNET_MessageHeader *msg)
333{ 321{
334 const struct ReservationResultMessage *rr; 322 const struct ReservationResultMessage *rr;
335 struct GNUNET_ATS_ReservationContext *rc; 323 struct GNUNET_ATS_ReservationContext *rc;
@@ -340,28 +328,21 @@ process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph,
340 GNUNET_break (0); 328 GNUNET_break (0);
341 return GNUNET_SYSERR; 329 return GNUNET_SYSERR;
342 } 330 }
343 rr = (const struct ReservationResultMessage*) msg; 331 rr = (const struct ReservationResultMessage *) msg;
344 amount = ntohl (rr->amount); 332 amount = ntohl (rr->amount);
345 rc = ph->reservation_head; 333 rc = ph->reservation_head;
346 if (0 != memcmp (&rr->peer, 334 if (0 != memcmp (&rr->peer, &rc->peer, sizeof (struct GNUNET_PeerIdentity)))
347 &rc->peer,
348 sizeof (struct GNUNET_PeerIdentity)))
349 { 335 {
350 GNUNET_break (0); 336 GNUNET_break (0);
351 return GNUNET_SYSERR; 337 return GNUNET_SYSERR;
352 } 338 }
353 GNUNET_CONTAINER_DLL_remove (ph->reservation_head, 339 GNUNET_CONTAINER_DLL_remove (ph->reservation_head, ph->reservation_tail, rc);
354 ph->reservation_tail, 340 if ((amount == 0) || (rc->rcb != NULL))
355 rc);
356 if ( (amount == 0) ||
357 (rc->rcb != NULL) )
358 { 341 {
359 /* tell client if not cancelled */ 342 /* tell client if not cancelled */
360 if (rc->rcb != NULL) 343 if (rc->rcb != NULL)
361 rc->rcb (rc->rcb_cls, 344 rc->rcb (rc->rcb_cls, &rr->peer, amount,
362 &rr->peer, 345 GNUNET_TIME_relative_ntoh (rr->res_delay));
363 amount,
364 GNUNET_TIME_relative_ntoh (rr->res_delay));
365 GNUNET_free (rc); 346 GNUNET_free (rc);
366 return GNUNET_OK; 347 return GNUNET_OK;
367 } 348 }
@@ -369,7 +350,7 @@ process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph,
369 if (GNUNET_YES != rc->undo) 350 if (GNUNET_YES != rc->undo)
370 { 351 {
371 GNUNET_free (rc); 352 GNUNET_free (rc);
372 return GNUNET_OK; /* do not try to undo failed undos or negative amounts */ 353 return GNUNET_OK; /* do not try to undo failed undos or negative amounts */
373 } 354 }
374 GNUNET_free (rc); 355 GNUNET_free (rc);
375 (void) GNUNET_ATS_reserve_bandwidth (ph, &rr->peer, -amount, NULL, NULL); 356 (void) GNUNET_ATS_reserve_bandwidth (ph, &rr->peer, -amount, NULL, NULL);
@@ -385,12 +366,11 @@ process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph,
385 * @param msg message received, NULL on timeout or fatal error 366 * @param msg message received, NULL on timeout or fatal error
386 */ 367 */
387static void 368static void
388process_ats_message (void *cls, 369process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg)
389 const struct GNUNET_MessageHeader *msg)
390{ 370{
391 struct GNUNET_ATS_PerformanceHandle *ph = cls; 371 struct GNUNET_ATS_PerformanceHandle *ph = cls;
392 372
393 if (NULL == msg) 373 if (NULL == msg)
394 goto reconnect; 374 goto reconnect;
395 switch (ntohs (msg->type)) 375 switch (ntohs (msg->type))
396 { 376 {
@@ -400,22 +380,22 @@ process_ats_message (void *cls,
400 break; 380 break;
401 case GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT: 381 case GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT:
402 if (GNUNET_OK != process_rr_message (ph, msg)) 382 if (GNUNET_OK != process_rr_message (ph, msg))
403 goto reconnect; 383 goto reconnect;
404 break; 384 break;
405 default: 385 default:
406 GNUNET_break (0); 386 GNUNET_break (0);
407 goto reconnect; 387 goto reconnect;
408 return; 388 return;
409 } 389 }
410 GNUNET_CLIENT_receive (ph->client, 390 GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph,
411 &process_ats_message, ph, 391 GNUNET_TIME_UNIT_FOREVER_REL);
412 GNUNET_TIME_UNIT_FOREVER_REL);
413 return; 392 return;
414 reconnect: 393reconnect:
415 GNUNET_CLIENT_disconnect (ph->client, GNUNET_NO); 394 GNUNET_CLIENT_disconnect (ph->client, GNUNET_NO);
416 ph->client = NULL; 395 ph->client = NULL;
417 ph->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 396 ph->task =
418 &reconnect_task, ph); 397 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect_task,
398 ph);
419} 399}
420 400
421 401
@@ -433,25 +413,22 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph)
433 GNUNET_assert (NULL == ph->client); 413 GNUNET_assert (NULL == ph->client);
434 ph->client = GNUNET_CLIENT_connect ("ats", ph->cfg); 414 ph->client = GNUNET_CLIENT_connect ("ats", ph->cfg);
435 GNUNET_assert (NULL != ph->client); 415 GNUNET_assert (NULL != ph->client);
436 GNUNET_CLIENT_receive (ph->client, 416 GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph,
437 &process_ats_message, ph, 417 GNUNET_TIME_UNIT_FOREVER_REL);
438 GNUNET_TIME_UNIT_FOREVER_REL); 418 if ((NULL == (p = ph->pending_head)) || (GNUNET_YES != p->is_init))
439 if ( (NULL == (p = ph->pending_head)) ||
440 (GNUNET_YES != p->is_init) )
441 { 419 {
442 p = GNUNET_malloc (sizeof (struct PendingMessage) + 420 p = GNUNET_malloc (sizeof (struct PendingMessage) +
443 sizeof (struct ClientStartMessage)); 421 sizeof (struct ClientStartMessage));
444 p->size = sizeof (struct ClientStartMessage); 422 p->size = sizeof (struct ClientStartMessage);
445 p->is_init = GNUNET_YES; 423 p->is_init = GNUNET_YES;
446 init = (struct ClientStartMessage *) &p[1]; 424 init = (struct ClientStartMessage *) &p[1];
447 init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START); 425 init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START);
448 init->header.size = htons (sizeof (struct ClientStartMessage)); 426 init->header.size = htons (sizeof (struct ClientStartMessage));
449 init->start_flag = htonl ((ph->infocb == NULL) 427 init->start_flag =
450 ? START_FLAG_PERFORMANCE_NO_PIC 428 htonl ((ph->infocb ==
451 : START_FLAG_PERFORMANCE_WITH_PIC); 429 NULL) ? START_FLAG_PERFORMANCE_NO_PIC :
452 GNUNET_CONTAINER_DLL_insert (ph->pending_head, 430 START_FLAG_PERFORMANCE_WITH_PIC);
453 ph->pending_tail, 431 GNUNET_CONTAINER_DLL_insert (ph->pending_head, ph->pending_tail, p);
454 p);
455 } 432 }
456 do_transmit (ph); 433 do_transmit (ph);
457} 434}
@@ -468,8 +445,8 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph)
468 */ 445 */
469struct GNUNET_ATS_PerformanceHandle * 446struct GNUNET_ATS_PerformanceHandle *
470GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, 447GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
471 GNUNET_ATS_PeerInformationCallback infocb, 448 GNUNET_ATS_PeerInformationCallback infocb,
472 void *infocb_cls) 449 void *infocb_cls)
473{ 450{
474 struct GNUNET_ATS_PerformanceHandle *ph; 451 struct GNUNET_ATS_PerformanceHandle *ph;
475 452
@@ -492,22 +469,19 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph)
492{ 469{
493 struct PendingMessage *p; 470 struct PendingMessage *p;
494 struct GNUNET_ATS_ReservationContext *rc; 471 struct GNUNET_ATS_ReservationContext *rc;
495 472
496 while (NULL != (p = ph->pending_head)) 473 while (NULL != (p = ph->pending_head))
497 { 474 {
498 GNUNET_CONTAINER_DLL_remove (ph->pending_head, 475 GNUNET_CONTAINER_DLL_remove (ph->pending_head, ph->pending_tail, p);
499 ph->pending_tail,
500 p);
501 GNUNET_free (p); 476 GNUNET_free (p);
502 } 477 }
503 while (NULL != (rc = ph->reservation_head)) 478 while (NULL != (rc = ph->reservation_head))
504 { 479 {
505 GNUNET_CONTAINER_DLL_remove (ph->reservation_head, 480 GNUNET_CONTAINER_DLL_remove (ph->reservation_head, ph->reservation_tail,
506 ph->reservation_tail, 481 rc);
507 rc);
508 GNUNET_break (NULL == rc->rcb); 482 GNUNET_break (NULL == rc->rcb);
509 GNUNET_free (rc); 483 GNUNET_free (rc);
510 } 484 }
511 if (GNUNET_SCHEDULER_NO_TASK != ph->task) 485 if (GNUNET_SCHEDULER_NO_TASK != ph->task)
512 { 486 {
513 GNUNET_SCHEDULER_cancel (ph->task); 487 GNUNET_SCHEDULER_cancel (ph->task);
@@ -538,10 +512,9 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph)
538 */ 512 */
539struct GNUNET_ATS_ReservationContext * 513struct GNUNET_ATS_ReservationContext *
540GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph, 514GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
541 const struct GNUNET_PeerIdentity *peer, 515 const struct GNUNET_PeerIdentity *peer,
542 int32_t amount, 516 int32_t amount,
543 GNUNET_ATS_ReservationCallback rcb, 517 GNUNET_ATS_ReservationCallback rcb, void *rcb_cls)
544 void *rcb_cls)
545{ 518{
546 struct GNUNET_ATS_ReservationContext *rc; 519 struct GNUNET_ATS_ReservationContext *rc;
547 struct PendingMessage *p; 520 struct PendingMessage *p;
@@ -552,24 +525,21 @@ GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
552 rc->peer = *peer; 525 rc->peer = *peer;
553 rc->rcb = rcb; 526 rc->rcb = rcb;
554 rc->rcb_cls = rcb_cls; 527 rc->rcb_cls = rcb_cls;
555 if ( (rcb != NULL) && (amount > 0) ) 528 if ((rcb != NULL) && (amount > 0))
556 rc->undo = GNUNET_YES; 529 rc->undo = GNUNET_YES;
557 GNUNET_CONTAINER_DLL_insert_tail (ph->reservation_head, 530 GNUNET_CONTAINER_DLL_insert_tail (ph->reservation_head, ph->reservation_tail,
558 ph->reservation_tail, 531 rc);
559 rc); 532
560 533 p = GNUNET_malloc (sizeof (struct PendingMessage) +
561 p = GNUNET_malloc (sizeof (struct PendingMessage) + 534 sizeof (struct ReservationRequestMessage));
562 sizeof (struct ReservationRequestMessage));
563 p->size = sizeof (struct ReservationRequestMessage); 535 p->size = sizeof (struct ReservationRequestMessage);
564 p->is_init = GNUNET_NO; 536 p->is_init = GNUNET_NO;
565 m = (struct ReservationRequestMessage*) &p[1]; 537 m = (struct ReservationRequestMessage *) &p[1];
566 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST); 538 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST);
567 m->header.size = htons (sizeof (struct ReservationRequestMessage)); 539 m->header.size = htons (sizeof (struct ReservationRequestMessage));
568 m->amount = htonl (amount); 540 m->amount = htonl (amount);
569 m->peer = *peer; 541 m->peer = *peer;
570 GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, 542 GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, ph->pending_tail, p);
571 ph->pending_tail,
572 p);
573 do_transmit (ph); 543 do_transmit (ph);
574 return rc; 544 return rc;
575} 545}
@@ -581,8 +551,7 @@ GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
581 * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call 551 * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call
582 */ 552 */
583void 553void
584GNUNET_ATS_reserve_bandwidth_cancel (struct 554GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc)
585 GNUNET_ATS_ReservationContext *rc)
586{ 555{
587 rc->rcb = NULL; 556 rc->rcb = NULL;
588} 557}
@@ -591,15 +560,14 @@ GNUNET_ATS_reserve_bandwidth_cancel (struct
591/** 560/**
592 * Change preferences for the given peer. Preference changes are forgotten if peers 561 * Change preferences for the given peer. Preference changes are forgotten if peers
593 * disconnect. 562 * disconnect.
594 * 563 *
595 * @param ph performance handle 564 * @param ph performance handle
596 * @param peer identifies the peer 565 * @param peer identifies the peer
597 * @param ... 0-terminated specification of the desired changes 566 * @param ... 0-terminated specification of the desired changes
598 */ 567 */
599void 568void
600GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *ph, 569GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *ph,
601 const struct GNUNET_PeerIdentity *peer, 570 const struct GNUNET_PeerIdentity *peer, ...)
602 ...)
603{ 571{
604 struct PendingMessage *p; 572 struct PendingMessage *p;
605 struct ChangePreferenceMessage *m; 573 struct ChangePreferenceMessage *m;
@@ -611,60 +579,63 @@ GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *ph,
611 579
612 count = 0; 580 count = 0;
613 va_start (ap, peer); 581 va_start (ap, peer);
614 while (GNUNET_ATS_PREFERENCE_END != (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind))) 582 while (GNUNET_ATS_PREFERENCE_END !=
583 (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind)))
615 { 584 {
616 switch (kind) 585 switch (kind)
617 { 586 {
618 case GNUNET_ATS_PREFERENCE_BANDWIDTH: 587 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
619 count++; 588 count++;
620 (void) va_arg (ap, double); 589 (void) va_arg (ap, double);
590
621 break; 591 break;
622 case GNUNET_ATS_PREFERENCE_LATENCY: 592 case GNUNET_ATS_PREFERENCE_LATENCY:
623 count++; 593 count++;
624 (void) va_arg (ap, double); 594 (void) va_arg (ap, double);
595
625 break; 596 break;
626 default: 597 default:
627 GNUNET_assert (0); 598 GNUNET_assert (0);
628 } 599 }
629 } 600 }
630 va_end (ap); 601 va_end (ap);
631 msize = count * sizeof (struct PreferenceInformation) + 602 msize =
632 sizeof (struct ChangePreferenceMessage); 603 count * sizeof (struct PreferenceInformation) +
633 p = GNUNET_malloc (sizeof (struct PendingMessage) + 604 sizeof (struct ChangePreferenceMessage);
634 msize); 605 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
635 p->size = msize; 606 p->size = msize;
636 p->is_init = GNUNET_NO; 607 p->is_init = GNUNET_NO;
637 m = (struct ChangePreferenceMessage*) &p[1]; 608 m = (struct ChangePreferenceMessage *) &p[1];
638 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE); 609 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE);
639 m->header.size = htons (msize); 610 m->header.size = htons (msize);
640 m->num_preferences = htonl (count); 611 m->num_preferences = htonl (count);
641 m->peer = *peer; 612 m->peer = *peer;
642 pi = (struct PreferenceInformation*) &m[1]; 613 pi = (struct PreferenceInformation *) &m[1];
643 count = 0; 614 count = 0;
644 va_start (ap, peer); 615 va_start (ap, peer);
645 while (GNUNET_ATS_PREFERENCE_END != (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind))) 616 while (GNUNET_ATS_PREFERENCE_END !=
617 (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind)))
646 { 618 {
647 pi[count].preference_kind = htonl (kind); 619 pi[count].preference_kind = htonl (kind);
648 switch (kind) 620 switch (kind)
649 { 621 {
650 case GNUNET_ATS_PREFERENCE_BANDWIDTH: 622 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
651 pi[count].preference_value = (float) va_arg (ap, double); 623 pi[count].preference_value = (float) va_arg (ap, double);
624
652 count++; 625 count++;
653 break; 626 break;
654 case GNUNET_ATS_PREFERENCE_LATENCY: 627 case GNUNET_ATS_PREFERENCE_LATENCY:
655 pi[count].preference_value = (float) va_arg (ap, double); 628 pi[count].preference_value = (float) va_arg (ap, double);
629
656 count++; 630 count++;
657 break; 631 break;
658 default: 632 default:
659 GNUNET_assert (0); 633 GNUNET_assert (0);
660 } 634 }
661 } 635 }
662 va_end (ap); 636 va_end (ap);
663 GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, 637 GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, ph->pending_tail, p);
664 ph->pending_tail,
665 p);
666 do_transmit (ph); 638 do_transmit (ph);
667} 639}
668 640
669/* end of ats_api_performance.c */ 641/* end of ats_api_performance.c */
670
diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c
index b342d9657..2eeb99dad 100644
--- a/src/ats/ats_api_scheduling.c
+++ b/src/ats/ats_api_scheduling.c
@@ -37,12 +37,12 @@ struct PendingMessage
37 37
38 /** 38 /**
39 * Kept in a DLL. 39 * Kept in a DLL.
40 */ 40 */
41 struct PendingMessage *next; 41 struct PendingMessage *next;
42 42
43 /** 43 /**
44 * Kept in a DLL. 44 * Kept in a DLL.
45 */ 45 */
46 struct PendingMessage *prev; 46 struct PendingMessage *prev;
47 47
48 /** 48 /**
@@ -52,7 +52,7 @@ struct PendingMessage
52 52
53 /** 53 /**
54 * Is this the 'ATS_START' message? 54 * Is this the 'ATS_START' message?
55 */ 55 */
56 int is_init; 56 int is_init;
57}; 57};
58 58
@@ -84,7 +84,7 @@ struct SessionRecord
84 */ 84 */
85struct GNUNET_ATS_SchedulingHandle 85struct GNUNET_ATS_SchedulingHandle
86{ 86{
87 87
88 /** 88 /**
89 * Our configuration. 89 * Our configuration.
90 */ 90 */
@@ -94,7 +94,7 @@ struct GNUNET_ATS_SchedulingHandle
94 * Callback to invoke on suggestions. 94 * Callback to invoke on suggestions.
95 */ 95 */
96 GNUNET_ATS_AddressSuggestionCallback suggest_cb; 96 GNUNET_ATS_AddressSuggestionCallback suggest_cb;
97 97
98 /** 98 /**
99 * Closure for 'suggest_cb'. 99 * Closure for 'suggest_cb'.
100 */ 100 */
@@ -130,9 +130,9 @@ struct GNUNET_ATS_SchedulingHandle
130 130
131 /** 131 /**
132 * Task to trigger reconnect. 132 * Task to trigger reconnect.
133 */ 133 */
134 GNUNET_SCHEDULER_TaskIdentifier task; 134 GNUNET_SCHEDULER_TaskIdentifier task;
135 135
136 /** 136 /**
137 * Size of the session array. 137 * Size of the session array.
138 */ 138 */
@@ -161,8 +161,7 @@ reconnect (struct GNUNET_ATS_SchedulingHandle *sh);
161 * @param tc scheduler context 161 * @param tc scheduler context
162 */ 162 */
163static void 163static void
164reconnect_task (void *cls, 164reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
165 const struct GNUNET_SCHEDULER_TaskContext *tc)
166{ 165{
167 struct GNUNET_ATS_SchedulingHandle *sh = cls; 166 struct GNUNET_ATS_SchedulingHandle *sh = cls;
168 167
@@ -182,8 +181,9 @@ force_reconnect (struct GNUNET_ATS_SchedulingHandle *sh)
182 sh->reconnect = GNUNET_NO; 181 sh->reconnect = GNUNET_NO;
183 GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO); 182 GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO);
184 sh->client = NULL; 183 sh->client = NULL;
185 sh->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 184 sh->task =
186 &reconnect_task, sh); 185 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect_task,
186 sh);
187} 187}
188 188
189 189
@@ -205,8 +205,7 @@ do_transmit (struct GNUNET_ATS_SchedulingHandle *sh);
205 * @param msg message received, NULL on timeout or fatal error 205 * @param msg message received, NULL on timeout or fatal error
206 */ 206 */
207static void 207static void
208process_ats_message (void *cls, 208process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg);
209 const struct GNUNET_MessageHeader *msg);
210 209
211 210
212/** 211/**
@@ -218,9 +217,7 @@ process_ats_message (void *cls,
218 * @return number of bytes copied into buf 217 * @return number of bytes copied into buf
219 */ 218 */
220static size_t 219static size_t
221transmit_message_to_ats (void *cls, 220transmit_message_to_ats (void *cls, size_t size, void *buf)
222 size_t size,
223 void *buf)
224{ 221{
225 struct GNUNET_ATS_SchedulingHandle *sh = cls; 222 struct GNUNET_ATS_SchedulingHandle *sh = cls;
226 struct PendingMessage *p; 223 struct PendingMessage *p;
@@ -228,26 +225,22 @@ transmit_message_to_ats (void *cls,
228 char *cbuf; 225 char *cbuf;
229 226
230 sh->th = NULL; 227 sh->th = NULL;
231 if ( (size == 0) || (buf == NULL)) 228 if ((size == 0) || (buf == NULL))
232 { 229 {
233 force_reconnect (sh); 230 force_reconnect (sh);
234 return 0; 231 return 0;
235 } 232 }
236 ret = 0; 233 ret = 0;
237 cbuf = buf; 234 cbuf = buf;
238 while ( (NULL != (p = sh->pending_head)) && 235 while ((NULL != (p = sh->pending_head)) && (p->size <= size))
239 (p->size <= size) )
240 { 236 {
241 memcpy (&cbuf[ret], &p[1], p->size); 237 memcpy (&cbuf[ret], &p[1], p->size);
242 ret += p->size; 238 ret += p->size;
243 size -= p->size; 239 size -= p->size;
244 GNUNET_CONTAINER_DLL_remove (sh->pending_head, 240 GNUNET_CONTAINER_DLL_remove (sh->pending_head, sh->pending_tail, p);
245 sh->pending_tail,
246 p);
247 if (GNUNET_YES == p->is_init) 241 if (GNUNET_YES == p->is_init)
248 GNUNET_CLIENT_receive (sh->client, 242 GNUNET_CLIENT_receive (sh->client, &process_ats_message, sh,
249 &process_ats_message, sh, 243 GNUNET_TIME_UNIT_FOREVER_REL);
250 GNUNET_TIME_UNIT_FOREVER_REL);
251 GNUNET_free (p); 244 GNUNET_free (p);
252 } 245 }
253 do_transmit (sh); 246 do_transmit (sh);
@@ -271,12 +264,12 @@ do_transmit (struct GNUNET_ATS_SchedulingHandle *sh)
271 if (NULL == (p = sh->pending_head)) 264 if (NULL == (p = sh->pending_head))
272 return; 265 return;
273 if (NULL == sh->client) 266 if (NULL == sh->client)
274 return; /* currently reconnecting */ 267 return; /* currently reconnecting */
275 sh->th = GNUNET_CLIENT_notify_transmit_ready (sh->client, 268 sh->th =
276 p->size, 269 GNUNET_CLIENT_notify_transmit_ready (sh->client, p->size,
277 GNUNET_TIME_UNIT_FOREVER_REL, 270 GNUNET_TIME_UNIT_FOREVER_REL,
278 GNUNET_NO, 271 GNUNET_NO, &transmit_message_to_ats,
279 &transmit_message_to_ats, sh); 272 sh);
280} 273}
281 274
282 275
@@ -288,10 +281,9 @@ do_transmit (struct GNUNET_ATS_SchedulingHandle *sh)
288 * @param peer peer the session belongs to 281 * @param peer peer the session belongs to
289 * @return the session object (or NULL) 282 * @return the session object (or NULL)
290 */ 283 */
291static struct Session* 284static struct Session *
292find_session (struct GNUNET_ATS_SchedulingHandle *sh, 285find_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id,
293 uint32_t session_id, 286 const struct GNUNET_PeerIdentity *peer)
294 const struct GNUNET_PeerIdentity *peer)
295{ 287{
296 if (session_id >= sh->session_array_size) 288 if (session_id >= sh->session_array_size)
297 { 289 {
@@ -300,9 +292,9 @@ find_session (struct GNUNET_ATS_SchedulingHandle *sh,
300 } 292 }
301 if (session_id == 0) 293 if (session_id == 0)
302 return NULL; 294 return NULL;
303 if (0 != memcmp (peer, 295 if (0 !=
304 &sh->session_array[session_id].peer, 296 memcmp (peer, &sh->session_array[session_id].peer,
305 sizeof (struct GNUNET_PeerIdentity))) 297 sizeof (struct GNUNET_PeerIdentity)))
306 { 298 {
307 GNUNET_break (0); 299 GNUNET_break (0);
308 sh->reconnect = GNUNET_YES; 300 sh->reconnect = GNUNET_YES;
@@ -321,36 +313,33 @@ find_session (struct GNUNET_ATS_SchedulingHandle *sh,
321 * @param peer peer the session belongs to 313 * @param peer peer the session belongs to
322 * @return the session id 314 * @return the session id
323 */ 315 */
324static uint32_t 316static uint32_t
325get_session_id (struct GNUNET_ATS_SchedulingHandle *sh, 317get_session_id (struct GNUNET_ATS_SchedulingHandle *sh, struct Session *session,
326 struct Session *session, 318 const struct GNUNET_PeerIdentity *peer)
327 const struct GNUNET_PeerIdentity *peer)
328{ 319{
329 unsigned int i; 320 unsigned int i;
330 unsigned int f; 321 unsigned int f;
331 322
332 if (NULL == session) 323 if (NULL == session)
333 return 0; 324 return 0;
334 f = 0; 325 f = 0;
335 for (i=1;i<sh->session_array_size;i++) 326 for (i = 1; i < sh->session_array_size; i++)
336 { 327 {
337 if (session == sh->session_array[i].session) 328 if (session == sh->session_array[i].session)
338 { 329 {
339 GNUNET_assert (0 == memcmp (peer, 330 GNUNET_assert (0 ==
340 &sh->session_array[i].peer, 331 memcmp (peer, &sh->session_array[i].peer,
341 sizeof (struct GNUNET_PeerIdentity))); 332 sizeof (struct GNUNET_PeerIdentity)));
342 return i; 333 return i;
343 } 334 }
344 if ( (f == 0) && 335 if ((f == 0) && (sh->session_array[i].slot_used == GNUNET_NO))
345 (sh->session_array[i].slot_used == GNUNET_NO) )
346 f = i; 336 f = i;
347 } 337 }
348 if (f == 0) 338 if (f == 0)
349 { 339 {
350 f = sh->session_array_size; 340 f = sh->session_array_size;
351 GNUNET_array_grow (sh->session_array, 341 GNUNET_array_grow (sh->session_array, sh->session_array_size,
352 sh->session_array_size, 342 sh->session_array_size * 2);
353 sh->session_array_size * 2);
354 } 343 }
355 GNUNET_assert (f > 0); 344 GNUNET_assert (f > 0);
356 sh->session_array[f].session = session; 345 sh->session_array[f].session = session;
@@ -369,17 +358,16 @@ get_session_id (struct GNUNET_ATS_SchedulingHandle *sh,
369 * @param peer peer the session belongs to 358 * @param peer peer the session belongs to
370 */ 359 */
371static void 360static void
372remove_session (struct GNUNET_ATS_SchedulingHandle *sh, 361remove_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id,
373 uint32_t session_id, 362 const struct GNUNET_PeerIdentity *peer)
374 const struct GNUNET_PeerIdentity *peer)
375{ 363{
376 if (0 == session_id) 364 if (0 == session_id)
377 return; 365 return;
378 GNUNET_assert (session_id < sh->session_array_size); 366 GNUNET_assert (session_id < sh->session_array_size);
379 GNUNET_assert (GNUNET_YES == sh->session_array[session_id].slot_used); 367 GNUNET_assert (GNUNET_YES == sh->session_array[session_id].slot_used);
380 GNUNET_assert (0 == memcmp (peer, 368 GNUNET_assert (0 ==
381 &sh->session_array[session_id].peer, 369 memcmp (peer, &sh->session_array[session_id].peer,
382 sizeof (struct GNUNET_PeerIdentity))); 370 sizeof (struct GNUNET_PeerIdentity)));
383 sh->session_array[session_id].session = NULL; 371 sh->session_array[session_id].session = NULL;
384} 372}
385 373
@@ -393,9 +381,8 @@ remove_session (struct GNUNET_ATS_SchedulingHandle *sh,
393 * @param peer peer the session belongs to 381 * @param peer peer the session belongs to
394 */ 382 */
395static void 383static void
396release_session (struct GNUNET_ATS_SchedulingHandle *sh, 384release_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id,
397 uint32_t session_id, 385 const struct GNUNET_PeerIdentity *peer)
398 const struct GNUNET_PeerIdentity *peer)
399{ 386{
400 if (session_id >= sh->session_array_size) 387 if (session_id >= sh->session_array_size)
401 { 388 {
@@ -403,28 +390,25 @@ release_session (struct GNUNET_ATS_SchedulingHandle *sh,
403 sh->reconnect = GNUNET_YES; 390 sh->reconnect = GNUNET_YES;
404 return; 391 return;
405 } 392 }
406 if (0 != memcmp (peer, 393 if (0 !=
407 &sh->session_array[session_id].peer, 394 memcmp (peer, &sh->session_array[session_id].peer,
408 sizeof (struct GNUNET_PeerIdentity))) 395 sizeof (struct GNUNET_PeerIdentity)))
409 { 396 {
410 GNUNET_break (0); 397 GNUNET_break (0);
411 sh->reconnect = GNUNET_YES; 398 sh->reconnect = GNUNET_YES;
412 return; 399 return;
413 } 400 }
414 sh->session_array[session_id].slot_used = GNUNET_NO; 401 sh->session_array[session_id].slot_used = GNUNET_NO;
415 memset (&sh->session_array[session_id].peer, 402 memset (&sh->session_array[session_id].peer, 0,
416 0, 403 sizeof (struct GNUNET_PeerIdentity));
417 sizeof (struct GNUNET_PeerIdentity));
418} 404}
419 405
420 406
421static void 407static void
422process_release_message (struct GNUNET_ATS_SchedulingHandle *sh, 408process_release_message (struct GNUNET_ATS_SchedulingHandle *sh,
423 const struct SessionReleaseMessage *srm) 409 const struct SessionReleaseMessage *srm)
424{ 410{
425 release_session (sh, 411 release_session (sh, ntohl (srm->session_id), &srm->peer);
426 ntohl (srm->session_id),
427 &srm->peer);
428} 412}
429 413
430 414
@@ -436,8 +420,7 @@ process_release_message (struct GNUNET_ATS_SchedulingHandle *sh,
436 * @param msg message received, NULL on timeout or fatal error 420 * @param msg message received, NULL on timeout or fatal error
437 */ 421 */
438static void 422static void
439process_ats_message (void *cls, 423process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg)
440 const struct GNUNET_MessageHeader *msg)
441{ 424{
442 struct GNUNET_ATS_SchedulingHandle *sh = cls; 425 struct GNUNET_ATS_SchedulingHandle *sh = cls;
443 const struct AddressSuggestionMessage *m; 426 const struct AddressSuggestionMessage *m;
@@ -448,60 +431,52 @@ process_ats_message (void *cls,
448 uint16_t plugin_name_length; 431 uint16_t plugin_name_length;
449 uint32_t ats_count; 432 uint32_t ats_count;
450 433
451 if (NULL == msg) 434 if (NULL == msg)
452 { 435 {
453 force_reconnect (sh); 436 force_reconnect (sh);
454 return; 437 return;
455 } 438 }
456 if ( (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE) && 439 if ((ntohs (msg->type) == GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE) &&
457 (ntohs (msg->size) == sizeof (struct SessionReleaseMessage)) ) 440 (ntohs (msg->size) == sizeof (struct SessionReleaseMessage)))
458 { 441 {
459 process_release_message (sh, 442 process_release_message (sh, (const struct SessionReleaseMessage *) msg);
460 (const struct SessionReleaseMessage*) msg); 443 GNUNET_CLIENT_receive (sh->client, &process_ats_message, sh,
461 GNUNET_CLIENT_receive (sh->client, 444 GNUNET_TIME_UNIT_FOREVER_REL);
462 &process_ats_message, sh,
463 GNUNET_TIME_UNIT_FOREVER_REL);
464 if (GNUNET_YES == sh->reconnect) 445 if (GNUNET_YES == sh->reconnect)
465 force_reconnect (sh); 446 force_reconnect (sh);
466 return; 447 return;
467 } 448 }
468 if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION) || 449 if ((ntohs (msg->type) != GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION) ||
469 (ntohs (msg->size) <= sizeof (struct AddressSuggestionMessage)) ) 450 (ntohs (msg->size) <= sizeof (struct AddressSuggestionMessage)))
470 { 451 {
471 GNUNET_break (0); 452 GNUNET_break (0);
472 force_reconnect (sh); 453 force_reconnect (sh);
473 return; 454 return;
474 } 455 }
475 m = (const struct AddressSuggestionMessage*) msg; 456 m = (const struct AddressSuggestionMessage *) msg;
476 ats_count = ntohl (m->ats_count); 457 ats_count = ntohl (m->ats_count);
477 address_length = ntohs (m->address_length); 458 address_length = ntohs (m->address_length);
478 atsi = (const struct GNUNET_ATS_Information*) &m[1]; 459 atsi = (const struct GNUNET_ATS_Information *) &m[1];
479 address = (const char*) &atsi[ats_count]; 460 address = (const char *) &atsi[ats_count];
480 plugin_name = &address[address_length]; 461 plugin_name = &address[address_length];
481 plugin_name_length = ntohs (m->plugin_name_length); 462 plugin_name_length = ntohs (m->plugin_name_length);
482 if ( (address_length + 463 if ((address_length + plugin_name_length +
483 plugin_name_length + 464 ats_count * sizeof (struct GNUNET_ATS_Information) +
484 ats_count * sizeof (struct GNUNET_ATS_Information) + 465 sizeof (struct AddressSuggestionMessage) != ntohs (msg->size)) ||
485 sizeof (struct AddressSuggestionMessage) != ntohs (msg->size)) || 466 (ats_count >
486 (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) || 467 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information))
487 (plugin_name[plugin_name_length - 1] != '\0') ) 468 || (plugin_name[plugin_name_length - 1] != '\0'))
488 { 469 {
489 GNUNET_break (0); 470 GNUNET_break (0);
490 force_reconnect (sh); 471 force_reconnect (sh);
491 return; 472 return;
492 } 473 }
493 sh->suggest_cb (sh->suggest_cb_cls, 474 sh->suggest_cb (sh->suggest_cb_cls, &m->peer, plugin_name, address,
494 &m->peer, 475 address_length, find_session (sh, ntohl (m->session_id),
495 plugin_name, 476 &m->peer), m->bandwidth_out,
496 address, address_length, 477 m->bandwidth_in, atsi, ats_count);
497 find_session (sh, ntohl (m->session_id), &m->peer), 478 GNUNET_CLIENT_receive (sh->client, &process_ats_message, sh,
498 m->bandwidth_out, 479 GNUNET_TIME_UNIT_FOREVER_REL);
499 m->bandwidth_in,
500 atsi,
501 ats_count);
502 GNUNET_CLIENT_receive (sh->client,
503 &process_ats_message, sh,
504 GNUNET_TIME_UNIT_FOREVER_REL);
505 if (GNUNET_YES == sh->reconnect) 480 if (GNUNET_YES == sh->reconnect)
506 force_reconnect (sh); 481 force_reconnect (sh);
507} 482}
@@ -521,20 +496,17 @@ reconnect (struct GNUNET_ATS_SchedulingHandle *sh)
521 GNUNET_assert (NULL == sh->client); 496 GNUNET_assert (NULL == sh->client);
522 sh->client = GNUNET_CLIENT_connect ("ats", sh->cfg); 497 sh->client = GNUNET_CLIENT_connect ("ats", sh->cfg);
523 GNUNET_assert (NULL != sh->client); 498 GNUNET_assert (NULL != sh->client);
524 if ( (NULL == (p = sh->pending_head)) || 499 if ((NULL == (p = sh->pending_head)) || (GNUNET_YES != p->is_init))
525 (GNUNET_YES != p->is_init) )
526 { 500 {
527 p = GNUNET_malloc (sizeof (struct PendingMessage) + 501 p = GNUNET_malloc (sizeof (struct PendingMessage) +
528 sizeof (struct ClientStartMessage)); 502 sizeof (struct ClientStartMessage));
529 p->size = sizeof (struct ClientStartMessage); 503 p->size = sizeof (struct ClientStartMessage);
530 p->is_init = GNUNET_YES; 504 p->is_init = GNUNET_YES;
531 init = (struct ClientStartMessage *) &p[1]; 505 init = (struct ClientStartMessage *) &p[1];
532 init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START); 506 init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START);
533 init->header.size = htons (sizeof (struct ClientStartMessage)); 507 init->header.size = htons (sizeof (struct ClientStartMessage));
534 init->start_flag = htonl (START_FLAG_SCHEDULING); 508 init->start_flag = htonl (START_FLAG_SCHEDULING);
535 GNUNET_CONTAINER_DLL_insert (sh->pending_head, 509 GNUNET_CONTAINER_DLL_insert (sh->pending_head, sh->pending_tail, p);
536 sh->pending_tail,
537 p);
538 } 510 }
539 do_transmit (sh); 511 do_transmit (sh);
540} 512}
@@ -550,8 +522,8 @@ reconnect (struct GNUNET_ATS_SchedulingHandle *sh)
550 */ 522 */
551struct GNUNET_ATS_SchedulingHandle * 523struct GNUNET_ATS_SchedulingHandle *
552GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg, 524GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
553 GNUNET_ATS_AddressSuggestionCallback suggest_cb, 525 GNUNET_ATS_AddressSuggestionCallback suggest_cb,
554 void *suggest_cb_cls) 526 void *suggest_cb_cls)
555{ 527{
556 struct GNUNET_ATS_SchedulingHandle *sh; 528 struct GNUNET_ATS_SchedulingHandle *sh;
557 529
@@ -559,9 +531,7 @@ GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
559 sh->cfg = cfg; 531 sh->cfg = cfg;
560 sh->suggest_cb = suggest_cb; 532 sh->suggest_cb = suggest_cb;
561 sh->suggest_cb_cls = suggest_cb_cls; 533 sh->suggest_cb_cls = suggest_cb_cls;
562 GNUNET_array_grow (sh->session_array, 534 GNUNET_array_grow (sh->session_array, sh->session_array_size, 4);
563 sh->session_array_size,
564 4);
565 reconnect (sh); 535 reconnect (sh);
566 return sh; 536 return sh;
567} 537}
@@ -579,9 +549,7 @@ GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh)
579 549
580 while (NULL != (p = sh->pending_head)) 550 while (NULL != (p = sh->pending_head))
581 { 551 {
582 GNUNET_CONTAINER_DLL_remove (sh->pending_head, 552 GNUNET_CONTAINER_DLL_remove (sh->pending_head, sh->pending_tail, p);
583 sh->pending_tail,
584 p);
585 GNUNET_free (p); 553 GNUNET_free (p);
586 } 554 }
587 if (NULL != sh->client) 555 if (NULL != sh->client)
@@ -594,9 +562,7 @@ GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh)
594 GNUNET_SCHEDULER_cancel (sh->task); 562 GNUNET_SCHEDULER_cancel (sh->task);
595 sh->task = GNUNET_SCHEDULER_NO_TASK; 563 sh->task = GNUNET_SCHEDULER_NO_TASK;
596 } 564 }
597 GNUNET_array_grow (sh->session_array, 565 GNUNET_array_grow (sh->session_array, sh->session_array_size, 0);
598 sh->session_array_size,
599 0);
600 GNUNET_free (sh); 566 GNUNET_free (sh);
601} 567}
602 568
@@ -616,17 +582,15 @@ GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh,
616 struct RequestAddressMessage *m; 582 struct RequestAddressMessage *m;
617 583
618 p = GNUNET_malloc (sizeof (struct PendingMessage) + 584 p = GNUNET_malloc (sizeof (struct PendingMessage) +
619 sizeof (struct RequestAddressMessage)); 585 sizeof (struct RequestAddressMessage));
620 p->size = sizeof (struct RequestAddressMessage); 586 p->size = sizeof (struct RequestAddressMessage);
621 p->is_init = GNUNET_NO; 587 p->is_init = GNUNET_NO;
622 m = (struct RequestAddressMessage*) &p[1]; 588 m = (struct RequestAddressMessage *) &p[1];
623 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS); 589 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS);
624 m->header.size = htons (sizeof (struct RequestAddressMessage)); 590 m->header.size = htons (sizeof (struct RequestAddressMessage));
625 m->reserved = htonl (0); 591 m->reserved = htonl (0);
626 m->peer = *peer; 592 m->peer = *peer;
627 GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, 593 GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p);
628 sh->pending_tail,
629 p);
630 do_transmit (sh); 594 do_transmit (sh);
631} 595}
632 596
@@ -651,9 +615,8 @@ GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh,
651void 615void
652GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh, 616GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
653 const struct GNUNET_PeerIdentity *peer, 617 const struct GNUNET_PeerIdentity *peer,
654 const char *plugin_name, 618 const char *plugin_name, const void *plugin_addr,
655 const void *plugin_addr, size_t plugin_addr_len, 619 size_t plugin_addr_len, struct Session *session,
656 struct Session *session,
657 const struct GNUNET_ATS_Information *ats, 620 const struct GNUNET_ATS_Information *ats,
658 uint32_t ats_count) 621 uint32_t ats_count)
659{ 622{
@@ -664,21 +627,23 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
664 size_t namelen; 627 size_t namelen;
665 size_t msize; 628 size_t msize;
666 629
667 namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1; 630 namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1;
668 msize = sizeof (struct AddressUpdateMessage) + plugin_addr_len + 631 msize =
669 ats_count * sizeof (struct GNUNET_ATS_Information) + namelen; 632 sizeof (struct AddressUpdateMessage) + plugin_addr_len +
670 if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 633 ats_count * sizeof (struct GNUNET_ATS_Information) + namelen;
671 (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 634 if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
672 (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 635 (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
673 (ats_count >= GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) ) 636 (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
637 (ats_count >=
638 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)))
674 { 639 {
675 GNUNET_break (0); 640 GNUNET_break (0);
676 return; 641 return;
677 } 642 }
678 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); 643 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
679 p->size = msize; 644 p->size = msize;
680 p->is_init = GNUNET_NO; 645 p->is_init = GNUNET_NO;
681 m = (struct AddressUpdateMessage*) &p[1]; 646 m = (struct AddressUpdateMessage *) &p[1];
682 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE); 647 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE);
683 m->header.size = htons (msize); 648 m->header.size = htons (msize);
684 m->ats_count = htonl (ats_count); 649 m->ats_count = htonl (ats_count);
@@ -686,14 +651,12 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
686 m->address_length = htons (plugin_addr_len); 651 m->address_length = htons (plugin_addr_len);
687 m->plugin_name_length = htons (namelen); 652 m->plugin_name_length = htons (namelen);
688 m->session_id = htonl (get_session_id (sh, session, peer)); 653 m->session_id = htonl (get_session_id (sh, session, peer));
689 am = (struct GNUNET_ATS_Information*) &m[1]; 654 am = (struct GNUNET_ATS_Information *) &m[1];
690 memcpy (am, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); 655 memcpy (am, ats, ats_count * sizeof (struct GNUNET_ATS_Information));
691 pm = (char *) &am[ats_count]; 656 pm = (char *) &am[ats_count];
692 memcpy (pm, plugin_addr, plugin_addr_len); 657 memcpy (pm, plugin_addr, plugin_addr_len);
693 memcpy (&pm[plugin_addr_len], plugin_name, namelen); 658 memcpy (&pm[plugin_addr_len], plugin_name, namelen);
694 GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, 659 GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p);
695 sh->pending_tail,
696 p);
697 do_transmit (sh); 660 do_transmit (sh);
698} 661}
699 662
@@ -712,12 +675,10 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
712 */ 675 */
713void 676void
714GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh, 677GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
715 const struct GNUNET_PeerIdentity *peer, 678 const struct GNUNET_PeerIdentity *peer,
716 const char *plugin_name, 679 const char *plugin_name, const void *plugin_addr,
717 const void *plugin_addr, 680 size_t plugin_addr_len, struct Session *session,
718 size_t plugin_addr_len, 681 int in_use)
719 struct Session *session,
720 int in_use)
721{ 682{
722 struct PendingMessage *p; 683 struct PendingMessage *p;
723 struct AddressUseMessage *m; 684 struct AddressUseMessage *m;
@@ -727,30 +688,28 @@ GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
727 688
728 namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1; 689 namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1;
729 msize = sizeof (struct AddressUseMessage) + plugin_addr_len + namelen; 690 msize = sizeof (struct AddressUseMessage) + plugin_addr_len + namelen;
730 if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 691 if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
731 (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 692 (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
732 (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ) 693 (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE))
733 { 694 {
734 GNUNET_break (0); 695 GNUNET_break (0);
735 return; 696 return;
736 } 697 }
737 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); 698 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
738 p->size = msize; 699 p->size = msize;
739 p->is_init = GNUNET_NO; 700 p->is_init = GNUNET_NO;
740 m = (struct AddressUseMessage*) &p[1]; 701 m = (struct AddressUseMessage *) &p[1];
741 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE); 702 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE);
742 m->header.size = htons (msize); 703 m->header.size = htons (msize);
743 m->peer = *peer; 704 m->peer = *peer;
744 m->in_use = htons(in_use); 705 m->in_use = htons (in_use);
745 m->address_length = htons (plugin_addr_len); 706 m->address_length = htons (plugin_addr_len);
746 m->plugin_name_length = htons (namelen); 707 m->plugin_name_length = htons (namelen);
747 m->session_id = htonl (get_session_id (sh, session, peer)); 708 m->session_id = htonl (get_session_id (sh, session, peer));
748 pm = (char *) &m[1]; 709 pm = (char *) &m[1];
749 memcpy (pm, plugin_addr, plugin_addr_len); 710 memcpy (pm, plugin_addr, plugin_addr_len);
750 memcpy (&pm[plugin_addr_len], plugin_name, namelen); 711 memcpy (&pm[plugin_addr_len], plugin_name, namelen);
751 GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, 712 GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p);
752 sh->pending_tail,
753 p);
754 713
755 do_transmit (sh); 714 do_transmit (sh);
756} 715}
@@ -768,10 +727,8 @@ GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
768void 727void
769GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh, 728GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
770 const struct GNUNET_PeerIdentity *peer, 729 const struct GNUNET_PeerIdentity *peer,
771 const char *plugin_name, 730 const char *plugin_name, const void *plugin_addr,
772 const void *plugin_addr, 731 size_t plugin_addr_len, struct Session *session)
773 size_t plugin_addr_len,
774 struct Session *session)
775{ 732{
776 struct PendingMessage *p; 733 struct PendingMessage *p;
777 struct AddressDestroyedMessage *m; 734 struct AddressDestroyedMessage *m;
@@ -780,20 +737,19 @@ GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
780 size_t msize; 737 size_t msize;
781 uint32_t session_id; 738 uint32_t session_id;
782 739
783 namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1; 740 namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1;
784 msize = sizeof (struct AddressDestroyedMessage) + plugin_addr_len + 741 msize = sizeof (struct AddressDestroyedMessage) + plugin_addr_len + namelen;
785 namelen; 742 if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
786 if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 743 (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
787 (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 744 (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE))
788 (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) )
789 { 745 {
790 GNUNET_break (0); 746 GNUNET_break (0);
791 return; 747 return;
792 } 748 }
793 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); 749 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
794 p->size = msize; 750 p->size = msize;
795 p->is_init = GNUNET_NO; 751 p->is_init = GNUNET_NO;
796 m = (struct AddressDestroyedMessage*) &p[1]; 752 m = (struct AddressDestroyedMessage *) &p[1];
797 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED); 753 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED);
798 m->header.size = htons (msize); 754 m->header.size = htons (msize);
799 m->reserved = htonl (0); 755 m->reserved = htonl (0);
@@ -804,9 +760,7 @@ GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
804 pm = (char *) &m[1]; 760 pm = (char *) &m[1];
805 memcpy (pm, plugin_addr, plugin_addr_len); 761 memcpy (pm, plugin_addr, plugin_addr_len);
806 memcpy (&pm[plugin_addr_len], plugin_name, namelen); 762 memcpy (&pm[plugin_addr_len], plugin_name, namelen);
807 GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, 763 GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p);
808 sh->pending_tail,
809 p);
810 do_transmit (sh); 764 do_transmit (sh);
811 remove_session (sh, session_id, peer); 765 remove_session (sh, session_id, peer);
812} 766}
diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c
index 563550ece..ec374aef8 100644
--- a/src/ats/gnunet-service-ats.c
+++ b/src/ats/gnunet-service-ats.c
@@ -48,14 +48,13 @@ struct GNUNET_STATISTICS_Handle *GSA_stats;
48 */ 48 */
49static void 49static void
50handle_ats_start (void *cls, struct GNUNET_SERVER_Client *client, 50handle_ats_start (void *cls, struct GNUNET_SERVER_Client *client,
51 const struct GNUNET_MessageHeader *message) 51 const struct GNUNET_MessageHeader *message)
52{ 52{
53 const struct ClientStartMessage * msg = (const struct ClientStartMessage *) message; 53 const struct ClientStartMessage *msg =
54 (const struct ClientStartMessage *) message;
54 enum StartFlag flag; 55 enum StartFlag flag;
55 56
56 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 57 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ATS_START");
57 "Received `%s' message\n",
58 "ATS_START");
59 flag = ntohl (msg->start_flag); 58 flag = ntohl (msg->start_flag);
60 switch (flag) 59 switch (flag)
61 { 60 {
@@ -77,7 +76,7 @@ handle_ats_start (void *cls, struct GNUNET_SERVER_Client *client,
77 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 76 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
78 return; 77 return;
79 } 78 }
80 GNUNET_SERVER_receive_done (client, GNUNET_OK); 79 GNUNET_SERVER_receive_done (client, GNUNET_OK);
81} 80}
82 81
83 82
@@ -131,20 +130,22 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
131 const struct GNUNET_CONFIGURATION_Handle *cfg) 130 const struct GNUNET_CONFIGURATION_Handle *cfg)
132{ 131{
133 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 132 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
134 { &handle_ats_start, NULL, 133 {&handle_ats_start, NULL,
135 GNUNET_MESSAGE_TYPE_ATS_START, sizeof (struct ClientStartMessage)}, 134 GNUNET_MESSAGE_TYPE_ATS_START, sizeof (struct ClientStartMessage)},
136 { &GAS_handle_request_address, NULL, 135 {&GAS_handle_request_address, NULL,
137 GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS, sizeof (struct RequestAddressMessage)}, 136 GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS,
138 { &GAS_handle_address_update, NULL, 137 sizeof (struct RequestAddressMessage)},
139 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE, 0}, 138 {&GAS_handle_address_update, NULL,
140 { &GAS_handle_address_in_use, NULL, 139 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE, 0},
141 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE, 0}, 140 {&GAS_handle_address_in_use, NULL,
142 { &GAS_handle_address_destroyed, NULL, 141 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE, 0},
143 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED, 0}, 142 {&GAS_handle_address_destroyed, NULL,
144 { &GAS_handle_reservation_request, NULL, 143 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED, 0},
145 GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST, sizeof (struct ReservationRequestMessage)}, 144 {&GAS_handle_reservation_request, NULL,
146 { &GAS_handle_preference_change, NULL, 145 GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST,
147 GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE, 0}, 146 sizeof (struct ReservationRequestMessage)},
147 {&GAS_handle_preference_change, NULL,
148 GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE, 0},
148 {NULL, NULL, 0, 0} 149 {NULL, NULL, 0, 0}
149 }; 150 };
150 GSA_stats = GNUNET_STATISTICS_create ("ats", cfg); 151 GSA_stats = GNUNET_STATISTICS_create ("ats", cfg);
@@ -152,9 +153,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
152 GAS_performance_init (server); 153 GAS_performance_init (server);
153 GAS_scheduling_init (server); 154 GAS_scheduling_init (server);
154 GAS_addresses_init (cfg); 155 GAS_addresses_init (cfg);
155 GNUNET_SERVER_disconnect_notify (server, 156 GNUNET_SERVER_disconnect_notify (server, &client_disconnect_handler, NULL);
156 &client_disconnect_handler,
157 NULL);
158 GNUNET_SERVER_add_handlers (server, handlers); 157 GNUNET_SERVER_add_handlers (server, handlers);
159 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, 158 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
160 NULL); 159 NULL);
@@ -172,8 +171,8 @@ int
172main (int argc, char *const *argv) 171main (int argc, char *const *argv)
173{ 172{
174 return (GNUNET_OK == 173 return (GNUNET_OK ==
175 GNUNET_SERVICE_run (argc, argv, "ats", 174 GNUNET_SERVICE_run (argc, argv, "ats", GNUNET_SERVICE_OPTION_NONE,
176 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; 175 &run, NULL)) ? 0 : 1;
177} 176}
178 177
179/* end of gnunet-service-ats.c */ 178/* end of gnunet-service-ats.c */
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c
index 99dc0e17a..22304aa6d 100644
--- a/src/ats/gnunet-service-ats_addresses.c
+++ b/src/ats/gnunet-service-ats_addresses.c
@@ -42,11 +42,11 @@ struct ATS_Address
42 42
43 uint32_t ats_count; 43 uint32_t ats_count;
44 44
45 const void * addr; 45 const void *addr;
46 46
47 char * plugin; 47 char *plugin;
48 48
49 struct GNUNET_ATS_Information * ats; 49 struct GNUNET_ATS_Information *ats;
50 50
51 struct GNUNET_TIME_Relative atsp_latency; 51 struct GNUNET_TIME_Relative atsp_latency;
52 52
@@ -74,7 +74,7 @@ struct ATS_Address
74}; 74};
75 75
76 76
77static struct GNUNET_CONTAINER_MultiHashMap * addresses; 77static struct GNUNET_CONTAINER_MultiHashMap *addresses;
78 78
79static unsigned long long total_quota_in; 79static unsigned long long total_quota_in;
80 80
@@ -92,10 +92,8 @@ static unsigned int active_addr_count;
92 * @param value the 'struct ATS_Address' 92 * @param value the 'struct ATS_Address'
93 * @return GNUNET_OK (continue to iterate) 93 * @return GNUNET_OK (continue to iterate)
94 */ 94 */
95static int 95static int
96update_bw_it (void *cls, 96update_bw_it (void *cls, const GNUNET_HashCode * key, void *value)
97 const GNUNET_HashCode * key,
98 void *value)
99{ 97{
100 struct ATS_Address *aa = value; 98 struct ATS_Address *aa = value;
101 99
@@ -104,24 +102,18 @@ update_bw_it (void *cls,
104 GNUNET_assert (active_addr_count > 0); 102 GNUNET_assert (active_addr_count > 0);
105 aa->assigned_bw_in.value__ = htonl (total_quota_in / active_addr_count); 103 aa->assigned_bw_in.value__ = htonl (total_quota_in / active_addr_count);
106 aa->assigned_bw_out.value__ = htonl (total_quota_out / active_addr_count); 104 aa->assigned_bw_out.value__ = htonl (total_quota_out / active_addr_count);
107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 105 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New bandwidth for peer %s is %u/%u\n",
108 "New bandwidth for peer %s is %u/%u\n", 106 GNUNET_i2s (&aa->peer), ntohl (aa->assigned_bw_in.value__),
109 GNUNET_i2s (&aa->peer), 107 ntohl (aa->assigned_bw_out.value__));
110 ntohl (aa->assigned_bw_in.value__), 108 GAS_scheduling_transmit_address_suggestion (&aa->peer, aa->plugin, aa->addr,
111 ntohl (aa->assigned_bw_out.value__)); 109 aa->addr_len, aa->session_id,
112 GAS_scheduling_transmit_address_suggestion (&aa->peer, 110 aa->ats, aa->ats_count,
113 aa->plugin, 111 aa->assigned_bw_out,
114 aa->addr, aa->addr_len, 112 aa->assigned_bw_in);
115 aa->session_id, 113 GAS_reservations_set_bandwidth (&aa->peer, aa->assigned_bw_in);
116 aa->ats, aa->ats_count, 114 GAS_performance_notify_clients (&aa->peer, aa->plugin, aa->addr, aa->addr_len,
117 aa->assigned_bw_out, aa->assigned_bw_in); 115 aa->ats, aa->ats_count, aa->assigned_bw_out,
118 GAS_reservations_set_bandwidth (&aa->peer, 116 aa->assigned_bw_in);
119 aa->assigned_bw_in);
120 GAS_performance_notify_clients (&aa->peer,
121 aa->plugin,
122 aa->addr, aa->addr_len,
123 aa->ats, aa->ats_count,
124 aa->assigned_bw_out, aa->assigned_bw_in);
125 return GNUNET_OK; 117 return GNUNET_OK;
126} 118}
127 119
@@ -134,18 +126,12 @@ static void
134recalculate_assigned_bw () 126recalculate_assigned_bw ()
135{ 127{
136 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
137 "Recalculating bandwidth for all active connections\n"); 129 "Recalculating bandwidth for all active connections\n");
138 GNUNET_STATISTICS_update (GSA_stats, 130 GNUNET_STATISTICS_update (GSA_stats, "# bandwidth recalculations performed",
139 "# bandwidth recalculations performed", 131 1, GNUNET_NO);
140 1, 132 GNUNET_STATISTICS_set (GSA_stats, "# active addresses", active_addr_count,
141 GNUNET_NO); 133 GNUNET_NO);
142 GNUNET_STATISTICS_set (GSA_stats, 134 GNUNET_CONTAINER_multihashmap_iterate (addresses, &update_bw_it, NULL);
143 "# active addresses",
144 active_addr_count,
145 GNUNET_NO);
146 GNUNET_CONTAINER_multihashmap_iterate (addresses,
147 &update_bw_it,
148 NULL);
149} 135}
150 136
151 137
@@ -161,10 +147,10 @@ destroy_address (struct ATS_Address *addr)
161 int ret; 147 int ret;
162 148
163 ret = GNUNET_NO; 149 ret = GNUNET_NO;
164 GNUNET_assert (GNUNET_YES == 150 GNUNET_assert (GNUNET_YES ==
165 GNUNET_CONTAINER_multihashmap_remove(addresses, 151 GNUNET_CONTAINER_multihashmap_remove (addresses,
166 &addr->peer.hashPubKey, 152 &addr->peer.hashPubKey,
167 addr)); 153 addr));
168 if (GNUNET_YES == addr->active) 154 if (GNUNET_YES == addr->active)
169 { 155 {
170 active_addr_count--; 156 active_addr_count--;
@@ -180,24 +166,22 @@ destroy_address (struct ATS_Address *addr)
180 166
181struct CompareAddressContext 167struct CompareAddressContext
182{ 168{
183 const struct ATS_Address * search; 169 const struct ATS_Address *search;
184 struct ATS_Address * result; 170 struct ATS_Address *result;
185}; 171};
186 172
187 173
188static int 174static int
189compare_address_it (void *cls, 175compare_address_it (void *cls, const GNUNET_HashCode * key, void *value)
190 const GNUNET_HashCode * key,
191 void *value)
192{ 176{
193 struct CompareAddressContext * cac = cls; 177 struct CompareAddressContext *cac = cls;
194 struct ATS_Address * aa = value; 178 struct ATS_Address *aa = value;
195 179
196 if ( ( (aa->addr_len != cac->search->addr_len) || 180 if (((aa->addr_len != cac->search->addr_len) ||
197 (0 != strcmp(aa->plugin, cac->search->plugin)) || 181 (0 != strcmp (aa->plugin, cac->search->plugin)) ||
198 (0 != memcmp (aa->addr, cac->search->addr, aa->addr_len)) ) && 182 (0 != memcmp (aa->addr, cac->search->addr, aa->addr_len))) &&
199 ( (aa->session_id != cac->search->session_id) || 183 ((aa->session_id != cac->search->session_id) ||
200 (cac->search->session_id == 0) )) 184 (cac->search->session_id == 0)))
201 return GNUNET_YES; 185 return GNUNET_YES;
202 cac->result = aa; 186 cac->result = aa;
203 return GNUNET_NO; 187 return GNUNET_NO;
@@ -205,7 +189,7 @@ compare_address_it (void *cls,
205 189
206 190
207/** 191/**
208 * Find an existing equivalent address record. 192 * Find an existing equivalent address record.
209 * Compares by peer identity and network address OR by session ID 193 * Compares by peer identity and network address OR by session ID
210 * (one of the two must match). 194 * (one of the two must match).
211 * 195 *
@@ -215,34 +199,31 @@ compare_address_it (void *cls,
215 */ 199 */
216struct ATS_Address * 200struct ATS_Address *
217find_address (const struct GNUNET_PeerIdentity *peer, 201find_address (const struct GNUNET_PeerIdentity *peer,
218 const struct ATS_Address * addr) 202 const struct ATS_Address *addr)
219{ 203{
220 struct CompareAddressContext cac; 204 struct CompareAddressContext cac;
221 205
222 cac.result = NULL; 206 cac.result = NULL;
223 cac.search = addr; 207 cac.search = addr;
224 GNUNET_CONTAINER_multihashmap_get_multiple(addresses, 208 GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey,
225 &peer->hashPubKey, 209 compare_address_it, &cac);
226 compare_address_it,
227 &cac);
228 return cac.result; 210 return cac.result;
229} 211}
230 212
231 213
232void 214void
233GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, 215GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
234 const char *plugin_name, 216 const char *plugin_name, const void *plugin_addr,
235 const void *plugin_addr, size_t plugin_addr_len, 217 size_t plugin_addr_len, uint32_t session_id,
236 uint32_t session_id, 218 const struct GNUNET_ATS_Information *atsi,
237 const struct GNUNET_ATS_Information *atsi, 219 uint32_t atsi_count)
238 uint32_t atsi_count)
239{ 220{
240 struct ATS_Address * aa; 221 struct ATS_Address *aa;
241 struct ATS_Address * old; 222 struct ATS_Address *old;
242 uint32_t i; 223 uint32_t i;
243 224
244 aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len); 225 aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len);
245 aa->ats = GNUNET_malloc(atsi_count * sizeof (struct GNUNET_ATS_Information)); 226 aa->ats = GNUNET_malloc (atsi_count * sizeof (struct GNUNET_ATS_Information));
246 aa->peer = *peer; 227 aa->peer = *peer;
247 aa->addr_len = plugin_addr_len; 228 aa->addr_len = plugin_addr_len;
248 aa->ats_count = atsi_count; 229 aa->ats_count = atsi_count;
@@ -256,19 +237,17 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
256 { 237 {
257 GNUNET_assert (GNUNET_OK == 238 GNUNET_assert (GNUNET_OK ==
258 GNUNET_CONTAINER_multihashmap_put (addresses, 239 GNUNET_CONTAINER_multihashmap_put (addresses,
259 &peer->hashPubKey, 240 &peer->hashPubKey, aa,
260 aa, 241 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
261 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added new address for peer `%s' %X\n",
262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 243 GNUNET_i2s (peer), aa);
263 "Added new address for peer `%s' %X\n",
264 GNUNET_i2s (peer), aa);
265 old = aa; 244 old = aa;
266 } 245 }
267 else 246 else
268 { 247 {
269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 248 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
270 "Updated existing address for peer `%s' %X \n", 249 "Updated existing address for peer `%s' %X \n",
271 GNUNET_i2s (peer), old); 250 GNUNET_i2s (peer), old);
272 GNUNET_free_non_null (old->ats); 251 GNUNET_free_non_null (old->ats);
273 old->session_id = session_id; 252 old->session_id = session_id;
274 old->ats = NULL; 253 old->ats = NULL;
@@ -278,7 +257,7 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
278 GNUNET_free (aa->plugin); 257 GNUNET_free (aa->plugin);
279 GNUNET_free (aa); 258 GNUNET_free (aa);
280 } 259 }
281 for (i=0;i<atsi_count;i++) 260 for (i = 0; i < atsi_count; i++)
282 switch (ntohl (atsi[i].type)) 261 switch (ntohl (atsi[i].type))
283 { 262 {
284 case GNUNET_ATS_UTILIZATION_UP: 263 case GNUNET_ATS_UTILIZATION_UP:
@@ -304,8 +283,7 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
304 break; 283 break;
305 default: 284 default:
306 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 285 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
307 "Received unsupported ATS type %u\n", 286 "Received unsupported ATS type %u\n", ntohl (atsi[i].type));
308 ntohl (atsi[i].type));
309 GNUNET_break (0); 287 GNUNET_break (0);
310 break; 288 break;
311 } 289 }
@@ -314,9 +292,8 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
314 292
315void 293void
316GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer, 294GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
317 const char *plugin_name, 295 const char *plugin_name, const void *plugin_addr,
318 const void *plugin_addr, size_t plugin_addr_len, 296 size_t plugin_addr_len, uint32_t session_id)
319 uint32_t session_id)
320{ 297{
321 struct ATS_Address aa; 298 struct ATS_Address aa;
322 struct ATS_Address *res; 299 struct ATS_Address *res;
@@ -324,20 +301,18 @@ GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
324 aa.peer = *peer; 301 aa.peer = *peer;
325 aa.addr_len = plugin_addr_len; 302 aa.addr_len = plugin_addr_len;
326 aa.addr = plugin_addr; 303 aa.addr = plugin_addr;
327 aa.plugin = (char*) plugin_name; 304 aa.plugin = (char *) plugin_name;
328 aa.session_id = session_id; 305 aa.session_id = session_id;
329 res = find_address (peer, &aa); 306 res = find_address (peer, &aa);
330 if (res == NULL) 307 if (res == NULL)
331 { 308 {
332 /* we don't even know this one, can this happen? */ 309 /* we don't even know this one, can this happen? */
333 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 310 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
334 "Asked to delete unknown address for peer `%s'\n", 311 "Asked to delete unknown address for peer `%s'\n",
335 GNUNET_i2s (peer)); 312 GNUNET_i2s (peer));
336 return; 313 return;
337 } 314 }
338 if ( (aa.session_id == session_id) && 315 if ((aa.session_id == session_id) && (session_id != 0) && (res->addr_len > 0))
339 (session_id != 0) &&
340 (res->addr_len > 0) )
341 { 316 {
342 /* just session died */ 317 /* just session died */
343 res->session_id = 0; 318 res->session_id = 0;
@@ -350,10 +325,9 @@ GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
350 return; 325 return;
351 } 326 }
352 /* destroy address entirely (either was only session or was 327 /* destroy address entirely (either was only session or was
353 not even with a session) */ 328 * not even with a session) */
354 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 329 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting address for peer `%s': `%s'\n",
355 "Deleting address for peer `%s': `%s'\n", 330 GNUNET_i2s (peer), plugin_name);
356 GNUNET_i2s (peer), plugin_name);
357 if (GNUNET_YES == destroy_address (res)) 331 if (GNUNET_YES == destroy_address (res))
358 recalculate_assigned_bw (); 332 recalculate_assigned_bw ();
359} 333}
@@ -362,29 +336,27 @@ GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
362/** 336/**
363 * Find a "good" address to use for a peer. If we already have an existing 337 * Find a "good" address to use for a peer. If we already have an existing
364 * address, we stick to it. Otherwise, we pick by lowest distance and then 338 * address, we stick to it. Otherwise, we pick by lowest distance and then
365 * by lowest latency. 339 * by lowest latency.
366 * 340 *
367 * @param cls the 'struct ATS_Address**' where we store the result 341 * @param cls the 'struct ATS_Address**' where we store the result
368 * @param key unused 342 * @param key unused
369 * @param value another 'struct ATS_Address*' to consider using 343 * @param value another 'struct ATS_Address*' to consider using
370 * @return GNUNET_OK (continue to iterate) 344 * @return GNUNET_OK (continue to iterate)
371 */ 345 */
372static int 346static int
373find_address_it (void *cls, 347find_address_it (void *cls, const GNUNET_HashCode * key, void *value)
374 const GNUNET_HashCode * key,
375 void *value)
376{ 348{
377 struct ATS_Address **ap = cls; 349 struct ATS_Address **ap = cls;
378 struct ATS_Address * aa = (struct ATS_Address *) value; 350 struct ATS_Address *aa = (struct ATS_Address *) value;
379 struct ATS_Address * ab = *ap; 351 struct ATS_Address *ab = *ap;
380 352
381 if (NULL == ab) 353 if (NULL == ab)
382 { 354 {
383 *ap = aa; 355 *ap = aa;
384 return GNUNET_OK; 356 return GNUNET_OK;
385 } 357 }
386 if ( (ntohl (ab->assigned_bw_in.value__) == 0) && 358 if ((ntohl (ab->assigned_bw_in.value__) == 0) &&
387 (ntohl (aa->assigned_bw_in.value__) > 0) ) 359 (ntohl (aa->assigned_bw_in.value__) > 0))
388 { 360 {
389 /* stick to existing connection */ 361 /* stick to existing connection */
390 *ap = aa; 362 *ap = aa;
@@ -410,19 +382,16 @@ find_address_it (void *cls,
410void 382void
411GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer) 383GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer)
412{ 384{
413 struct ATS_Address * aa; 385 struct ATS_Address *aa;
414 386
415 aa = NULL; 387 aa = NULL;
416 GNUNET_CONTAINER_multihashmap_get_multiple (addresses, 388 GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey,
417 &peer->hashPubKey, 389 &find_address_it, &aa);
418 &find_address_it,
419 &aa);
420 if (aa == NULL) 390 if (aa == NULL)
421 { 391 {
422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
423 "Cannot suggest address for peer `%s'\n", 393 "Cannot suggest address for peer `%s'\n", GNUNET_i2s (peer));
424 GNUNET_i2s (peer)); 394 return;
425 return;
426 } 395 }
427 if (aa->active == GNUNET_NO) 396 if (aa->active == GNUNET_NO)
428 { 397 {
@@ -433,11 +402,11 @@ GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer)
433 else 402 else
434 { 403 {
435 /* just to be sure... */ 404 /* just to be sure... */
436 GAS_scheduling_transmit_address_suggestion (peer, aa->plugin, 405 GAS_scheduling_transmit_address_suggestion (peer, aa->plugin, aa->addr,
437 aa->addr, aa->addr_len, 406 aa->addr_len, aa->session_id,
438 aa->session_id, 407 aa->ats, aa->ats_count,
439 aa->ats, aa->ats_count, 408 aa->assigned_bw_out,
440 aa->assigned_bw_out, aa->assigned_bw_in); 409 aa->assigned_bw_in);
441 } 410 }
442} 411}
443 412
@@ -446,8 +415,8 @@ GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer)
446// not with 'addresses' in the future... 415// not with 'addresses' in the future...
447void 416void
448GAS_addresses_change_preference (const struct GNUNET_PeerIdentity *peer, 417GAS_addresses_change_preference (const struct GNUNET_PeerIdentity *peer,
449 enum GNUNET_ATS_PreferenceKind kind, 418 enum GNUNET_ATS_PreferenceKind kind,
450 float score) 419 float score)
451{ 420{
452 // do nothing for now... 421 // do nothing for now...
453} 422}
@@ -462,16 +431,14 @@ void
462GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg) 431GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
463{ 432{
464 GNUNET_assert (GNUNET_OK == 433 GNUNET_assert (GNUNET_OK ==
465 GNUNET_CONFIGURATION_get_value_number (cfg, 434 GNUNET_CONFIGURATION_get_value_number (cfg, "core",
466 "core", 435 "TOTAL_QUOTA_IN",
467 "TOTAL_QUOTA_IN", 436 &total_quota_in));
468 &total_quota_in));
469 GNUNET_assert (GNUNET_OK == 437 GNUNET_assert (GNUNET_OK ==
470 GNUNET_CONFIGURATION_get_value_number (cfg, 438 GNUNET_CONFIGURATION_get_value_number (cfg, "core",
471 "core", 439 "TOTAL_QUOTA_OUT",
472 "TOTAL_QUOTA_OUT", 440 &total_quota_out));
473 &total_quota_out)); 441 addresses = GNUNET_CONTAINER_multihashmap_create (128);
474 addresses = GNUNET_CONTAINER_multihashmap_create(128);
475} 442}
476 443
477 444
@@ -483,12 +450,10 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
483 * @param value the 'struct ATS_Address' to free 450 * @param value the 'struct ATS_Address' to free
484 * @return GNUNET_OK (continue to iterate) 451 * @return GNUNET_OK (continue to iterate)
485 */ 452 */
486static int 453static int
487free_address_it (void *cls, 454free_address_it (void *cls, const GNUNET_HashCode * key, void *value)
488 const GNUNET_HashCode * key,
489 void *value)
490{ 455{
491 struct ATS_Address * aa = value; 456 struct ATS_Address *aa = value;
492 457
493 destroy_address (aa); 458 destroy_address (aa);
494 return GNUNET_OK; 459 return GNUNET_OK;
@@ -499,8 +464,7 @@ void
499GAS_addresses_destroy_all () 464GAS_addresses_destroy_all ()
500{ 465{
501 if (addresses != NULL) 466 if (addresses != NULL)
502 GNUNET_CONTAINER_multihashmap_iterate(addresses, 467 GNUNET_CONTAINER_multihashmap_iterate (addresses, &free_address_it, NULL);
503 &free_address_it, NULL);
504 GNUNET_assert (active_addr_count == 0); 468 GNUNET_assert (active_addr_count == 0);
505} 469}
506 470
diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h
index 1d218ba57..7fde42d96 100644
--- a/src/ats/gnunet-service-ats_addresses.h
+++ b/src/ats/gnunet-service-ats_addresses.h
@@ -28,7 +28,7 @@
28#define GNUNET_SERVICE_ATS_ADDRESSES_H 28#define GNUNET_SERVICE_ATS_ADDRESSES_H
29 29
30#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
31#include "gnunet_ats_service.h" 31#include "gnunet_ats_service.h"
32#include "ats.h" 32#include "ats.h"
33 33
34/** 34/**
@@ -48,18 +48,16 @@ GAS_addresses_done (void);
48 48
49void 49void
50GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, 50GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
51 const char *plugin_name, 51 const char *plugin_name, const void *plugin_addr,
52 const void *plugin_addr, size_t plugin_addr_len, 52 size_t plugin_addr_len, uint32_t session_id,
53 uint32_t session_id, 53 const struct GNUNET_ATS_Information *atsi,
54 const struct GNUNET_ATS_Information *atsi, 54 uint32_t atsi_count);
55 uint32_t atsi_count);
56 55
57 56
58void 57void
59GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer, 58GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
60 const char *plugin_name, 59 const char *plugin_name, const void *plugin_addr,
61 const void *plugin_addr, size_t plugin_addr_len, 60 size_t plugin_addr_len, uint32_t session_id);
62 uint32_t session_id);
63 61
64 62
65void 63void
@@ -78,8 +76,8 @@ GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer);
78// not with 'addresses' in the future... 76// not with 'addresses' in the future...
79void 77void
80GAS_addresses_change_preference (const struct GNUNET_PeerIdentity *peer, 78GAS_addresses_change_preference (const struct GNUNET_PeerIdentity *peer,
81 enum GNUNET_ATS_PreferenceKind kind, 79 enum GNUNET_ATS_PreferenceKind kind,
82 float score); 80 float score);
83 81
84 82
85/* FIXME: add performance request API */ 83/* FIXME: add performance request API */
diff --git a/src/ats/gnunet-service-ats_math.h b/src/ats/gnunet-service-ats_math.h
index 1324c30d0..0ec85f3f0 100644
--- a/src/ats/gnunet-service-ats_math.h
+++ b/src/ats/gnunet-service-ats_math.h
@@ -67,11 +67,10 @@
67struct ATS_mechanism; 67struct ATS_mechanism;
68struct ATS_peer; 68struct ATS_peer;
69 69
70typedef void (*GNUNET_ATS_AddressNotification) (struct ATS_peer ** 70typedef void (*GNUNET_ATS_AddressNotification) (struct ATS_peer ** peers,
71 peers, int *c_p, 71 int *c_p,
72 struct ATS_mechanism 72 struct ATS_mechanism **
73 ** mechanisms, 73 mechanisms, int *c_m);
74 int *c_m);
75 74
76typedef void (*GNUNET_ATS_ResultCallback) (void); 75typedef void (*GNUNET_ATS_ResultCallback) (void);
77 76
diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c
index 0fa08ac4b..4b8d23720 100644
--- a/src/ats/gnunet-service-ats_performance.c
+++ b/src/ats/gnunet-service-ats_performance.c
@@ -40,13 +40,13 @@ struct PerformanceClient
40 /** 40 /**
41 * Next in doubly-linked list. 41 * Next in doubly-linked list.
42 */ 42 */
43 struct PerformanceClient * next; 43 struct PerformanceClient *next;
44 44
45 /** 45 /**
46 * Previous in doubly-linked list. 46 * Previous in doubly-linked list.
47 */ 47 */
48 struct PerformanceClient * prev; 48 struct PerformanceClient *prev;
49 49
50 /** 50 /**
51 * Actual handle to the client. 51 * Actual handle to the client.
52 */ 52 */
@@ -69,7 +69,7 @@ static struct PerformanceClient *pc_head;
69 * Tail of linked list of all clients to this service. 69 * Tail of linked list of all clients to this service.
70 */ 70 */
71static struct PerformanceClient *pc_tail; 71static struct PerformanceClient *pc_tail;
72 72
73/** 73/**
74 * Context for sending messages to performance clients. 74 * Context for sending messages to performance clients.
75 */ 75 */
@@ -82,10 +82,10 @@ static struct GNUNET_SERVER_NotificationContext *nc;
82 * @param client server handle 82 * @param client server handle
83 * @return internal handle 83 * @return internal handle
84 */ 84 */
85static struct PerformanceClient * 85static struct PerformanceClient *
86find_client (struct GNUNET_SERVER_Client *client) 86find_client (struct GNUNET_SERVER_Client *client)
87{ 87{
88 struct PerformanceClient * pc; 88 struct PerformanceClient *pc;
89 89
90 for (pc = pc_head; pc != NULL; pc = pc->next) 90 for (pc = pc_head; pc != NULL; pc = pc->next)
91 if (pc->client == client) 91 if (pc->client == client)
@@ -101,9 +101,9 @@ find_client (struct GNUNET_SERVER_Client *client)
101 */ 101 */
102void 102void
103GAS_performance_add_client (struct GNUNET_SERVER_Client *client, 103GAS_performance_add_client (struct GNUNET_SERVER_Client *client,
104 enum StartFlag flag) 104 enum StartFlag flag)
105{ 105{
106 struct PerformanceClient * pc; 106 struct PerformanceClient *pc;
107 107
108 GNUNET_break (NULL == find_client (client)); 108 GNUNET_break (NULL == find_client (client));
109 pc = GNUNET_malloc (sizeof (struct PerformanceClient)); 109 pc = GNUNET_malloc (sizeof (struct PerformanceClient));
@@ -111,7 +111,7 @@ GAS_performance_add_client (struct GNUNET_SERVER_Client *client,
111 pc->flag = flag; 111 pc->flag = flag;
112 GNUNET_SERVER_notification_context_add (nc, client); 112 GNUNET_SERVER_notification_context_add (nc, client);
113 GNUNET_SERVER_client_keep (client); 113 GNUNET_SERVER_client_keep (client);
114 GNUNET_CONTAINER_DLL_insert(pc_head, pc_tail, pc); 114 GNUNET_CONTAINER_DLL_insert (pc_head, pc_tail, pc);
115} 115}
116 116
117 117
@@ -124,7 +124,7 @@ GAS_performance_add_client (struct GNUNET_SERVER_Client *client,
124void 124void
125GAS_performance_remove_client (struct GNUNET_SERVER_Client *client) 125GAS_performance_remove_client (struct GNUNET_SERVER_Client *client)
126{ 126{
127 struct PerformanceClient * pc; 127 struct PerformanceClient *pc;
128 128
129 pc = find_client (client); 129 pc = find_client (client);
130 if (NULL == pc) 130 if (NULL == pc)
@@ -150,25 +150,30 @@ GAS_performance_remove_client (struct GNUNET_SERVER_Client *client)
150 */ 150 */
151void 151void
152GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer, 152GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer,
153 const char *plugin_name, 153 const char *plugin_name,
154 const void *plugin_addr, size_t plugin_addr_len, 154 const void *plugin_addr, size_t plugin_addr_len,
155 const struct GNUNET_ATS_Information *atsi, 155 const struct GNUNET_ATS_Information *atsi,
156 uint32_t atsi_count, 156 uint32_t atsi_count,
157 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 157 struct GNUNET_BANDWIDTH_Value32NBO
158 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 158 bandwidth_out,
159 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
159{ 160{
160 struct PerformanceClient *pc; 161 struct PerformanceClient *pc;
161 struct PeerInformationMessage *msg; 162 struct PeerInformationMessage *msg;
162 size_t plugin_name_length = strlen (plugin_name) + 1; 163 size_t plugin_name_length = strlen (plugin_name) + 1;
163 size_t msize = sizeof (struct PeerInformationMessage) + atsi_count * sizeof (struct GNUNET_ATS_Information) 164 size_t msize =
164 + plugin_addr_len + plugin_name_length; 165 sizeof (struct PeerInformationMessage) +
166 atsi_count * sizeof (struct GNUNET_ATS_Information) + plugin_addr_len +
167 plugin_name_length;
165 char buf[msize]; 168 char buf[msize];
166 struct GNUNET_ATS_Information *atsp; 169 struct GNUNET_ATS_Information *atsp;
167 char *addrp; 170 char *addrp;
168 171
169 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); 172 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
170 GNUNET_assert (atsi_count < GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)); 173 GNUNET_assert (atsi_count <
171 msg = (struct PeerInformationMessage*) buf; 174 GNUNET_SERVER_MAX_MESSAGE_SIZE /
175 sizeof (struct GNUNET_ATS_Information));
176 msg = (struct PeerInformationMessage *) buf;
172 msg->header.size = htons (msize); 177 msg->header.size = htons (msize);
173 msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION); 178 msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION);
174 msg->ats_count = htonl (atsi_count); 179 msg->ats_count = htonl (atsi_count);
@@ -177,22 +182,19 @@ GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer,
177 msg->plugin_name_length = htons (plugin_name_length); 182 msg->plugin_name_length = htons (plugin_name_length);
178 msg->bandwidth_out = bandwidth_out; 183 msg->bandwidth_out = bandwidth_out;
179 msg->bandwidth_in = bandwidth_in; 184 msg->bandwidth_in = bandwidth_in;
180 atsp = (struct GNUNET_ATS_Information* ) &msg[1]; 185 atsp = (struct GNUNET_ATS_Information *) &msg[1];
181 memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count); 186 memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
182 addrp = (char*) &atsp[atsi_count]; 187 addrp = (char *) &atsp[atsi_count];
183 memcpy (addrp, plugin_addr, plugin_addr_len); 188 memcpy (addrp, plugin_addr, plugin_addr_len);
184 strcpy (&addrp[plugin_addr_len], plugin_name); 189 strcpy (&addrp[plugin_addr_len], plugin_name);
185 for (pc = pc_head; pc != NULL; pc = pc->next) 190 for (pc = pc_head; pc != NULL; pc = pc->next)
186 if (pc->flag == START_FLAG_PERFORMANCE_WITH_PIC) 191 if (pc->flag == START_FLAG_PERFORMANCE_WITH_PIC)
187 { 192 {
188 GNUNET_SERVER_notification_context_unicast (nc, 193 GNUNET_SERVER_notification_context_unicast (nc, pc->client, &msg->header,
189 pc->client, 194 GNUNET_YES);
190 &msg->header,
191 GNUNET_YES);
192 GNUNET_STATISTICS_update (GSA_stats, 195 GNUNET_STATISTICS_update (GSA_stats,
193 "# performance updates given to clients", 196 "# performance updates given to clients", 1,
194 1, 197 GNUNET_NO);
195 GNUNET_NO);
196 } 198 }
197} 199}
198 200
@@ -206,9 +208,10 @@ GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer,
206 */ 208 */
207void 209void
208GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client, 210GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client,
209 const struct GNUNET_MessageHeader *message) 211 const struct GNUNET_MessageHeader *message)
210{ 212{
211 const struct ReservationRequestMessage * msg = (const struct ReservationRequestMessage *) message; 213 const struct ReservationRequestMessage *msg =
214 (const struct ReservationRequestMessage *) message;
212 struct ReservationResultMessage result; 215 struct ReservationResultMessage result;
213 int32_t amount; 216 int32_t amount;
214 struct GNUNET_TIME_Relative res_delay; 217 struct GNUNET_TIME_Relative res_delay;
@@ -220,12 +223,10 @@ GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client,
220 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 223 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
221 return; 224 return;
222 } 225 }
223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
224 "Received `%s' message\n", 227 "RESERVATION_REQUEST");
225 "RESERVATION_REQUEST");
226 amount = (int32_t) ntohl (msg->amount); 228 amount = (int32_t) ntohl (msg->amount);
227 res_delay = GAS_reservations_reserve (&msg->peer, 229 res_delay = GAS_reservations_reserve (&msg->peer, amount);
228 amount);
229 if (res_delay.rel_value > 0) 230 if (res_delay.rel_value > 0)
230 amount = 0; 231 amount = 0;
231 result.header.size = htons (sizeof (struct ReservationResultMessage)); 232 result.header.size = htons (sizeof (struct ReservationResultMessage));
@@ -233,14 +234,10 @@ GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client,
233 result.amount = htonl (amount); 234 result.amount = htonl (amount);
234 result.peer = msg->peer; 235 result.peer = msg->peer;
235 result.res_delay = GNUNET_TIME_relative_hton (res_delay); 236 result.res_delay = GNUNET_TIME_relative_hton (res_delay);
236 GNUNET_STATISTICS_update (GSA_stats, 237 GNUNET_STATISTICS_update (GSA_stats, "# reservation requests processed", 1,
237 "# reservation requests processed", 238 GNUNET_NO);
238 1, 239 GNUNET_SERVER_notification_context_unicast (nc, client, &result.header,
239 GNUNET_NO); 240 GNUNET_NO);
240 GNUNET_SERVER_notification_context_unicast (nc,
241 client,
242 &result.header,
243 GNUNET_NO);
244 GNUNET_SERVER_receive_done (client, GNUNET_OK); 241 GNUNET_SERVER_receive_done (client, GNUNET_OK);
245} 242}
246 243
@@ -254,15 +251,16 @@ GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client,
254 */ 251 */
255void 252void
256GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client, 253GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client,
257 const struct GNUNET_MessageHeader *message) 254 const struct GNUNET_MessageHeader *message)
258{ 255{
259 const struct ChangePreferenceMessage * msg; 256 const struct ChangePreferenceMessage *msg;
260 const struct PreferenceInformation *pi; 257 const struct PreferenceInformation *pi;
261 uint16_t msize; 258 uint16_t msize;
262 uint32_t nump; 259 uint32_t nump;
263 uint32_t i; 260 uint32_t i;
264 261
265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "PREFERENCE_CHANGE"); 262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
263 "PREFERENCE_CHANGE");
266 msize = ntohs (message->size); 264 msize = ntohs (message->size);
267 if (msize < sizeof (struct ChangePreferenceMessage)) 265 if (msize < sizeof (struct ChangePreferenceMessage))
268 { 266 {
@@ -272,21 +270,22 @@ GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client,
272 } 270 }
273 msg = (const struct ChangePreferenceMessage *) message; 271 msg = (const struct ChangePreferenceMessage *) message;
274 nump = ntohl (msg->num_preferences); 272 nump = ntohl (msg->num_preferences);
275 if (msize != sizeof (struct ChangePreferenceMessage) + nump * sizeof (struct PreferenceInformation)) 273 if (msize !=
274 sizeof (struct ChangePreferenceMessage) +
275 nump * sizeof (struct PreferenceInformation))
276 { 276 {
277 GNUNET_break (0); 277 GNUNET_break (0);
278 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 278 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
279 return; 279 return;
280 } 280 }
281 GNUNET_STATISTICS_update (GSA_stats, 281 GNUNET_STATISTICS_update (GSA_stats, "# preference change requests processed",
282 "# preference change requests processed", 282 1, GNUNET_NO);
283 1,
284 GNUNET_NO);
285 pi = (const struct PreferenceInformation *) &msg[1]; 283 pi = (const struct PreferenceInformation *) &msg[1];
286 for (i=0;i<nump;i++) 284 for (i = 0; i < nump; i++)
287 GAS_addresses_change_preference (&msg->peer, 285 GAS_addresses_change_preference (&msg->peer,
288 (enum GNUNET_ATS_PreferenceKind) ntohl (pi[i].preference_kind), 286 (enum GNUNET_ATS_PreferenceKind)
289 pi[i].preference_value); 287 ntohl (pi[i].preference_kind),
288 pi[i].preference_value);
290 GNUNET_SERVER_receive_done (client, GNUNET_OK); 289 GNUNET_SERVER_receive_done (client, GNUNET_OK);
291} 290}
292 291
diff --git a/src/ats/gnunet-service-ats_performance.h b/src/ats/gnunet-service-ats_performance.h
index 5988bff44..44d02452b 100644
--- a/src/ats/gnunet-service-ats_performance.h
+++ b/src/ats/gnunet-service-ats_performance.h
@@ -39,7 +39,7 @@
39 */ 39 */
40void 40void
41GAS_performance_add_client (struct GNUNET_SERVER_Client *client, 41GAS_performance_add_client (struct GNUNET_SERVER_Client *client,
42 enum StartFlag flag); 42 enum StartFlag flag);
43 43
44 44
45/** 45/**
@@ -67,12 +67,14 @@ GAS_performance_remove_client (struct GNUNET_SERVER_Client *client);
67 */ 67 */
68void 68void
69GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer, 69GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer,
70 const char *plugin_name, 70 const char *plugin_name,
71 const void *plugin_addr, size_t plugin_addr_len, 71 const void *plugin_addr, size_t plugin_addr_len,
72 const struct GNUNET_ATS_Information *atsi, 72 const struct GNUNET_ATS_Information *atsi,
73 uint32_t atsi_count, 73 uint32_t atsi_count,
74 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 74 struct GNUNET_BANDWIDTH_Value32NBO
75 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in); 75 bandwidth_out,
76 struct GNUNET_BANDWIDTH_Value32NBO
77 bandwidth_in);
76 78
77 79
78/** 80/**
@@ -84,7 +86,7 @@ GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer,
84 */ 86 */
85void 87void
86GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client, 88GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client,
87 const struct GNUNET_MessageHeader *message); 89 const struct GNUNET_MessageHeader *message);
88 90
89 91
90/** 92/**
@@ -96,7 +98,7 @@ GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client,
96 */ 98 */
97void 99void
98GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client, 100GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client,
99 const struct GNUNET_MessageHeader *message); 101 const struct GNUNET_MessageHeader *message);
100 102
101 103
102/** 104/**
diff --git a/src/ats/gnunet-service-ats_reservations.c b/src/ats/gnunet-service-ats_reservations.c
index 492751254..f40e54516 100644
--- a/src/ats/gnunet-service-ats_reservations.c
+++ b/src/ats/gnunet-service-ats_reservations.c
@@ -27,7 +27,7 @@
27#include "gnunet-service-ats_reservations.h" 27#include "gnunet-service-ats_reservations.h"
28 28
29/** 29/**
30 * Number of seconds that available bandwidth carries over 30 * Number of seconds that available bandwidth carries over
31 * (can accumulate). 31 * (can accumulate).
32 */ 32 */
33#define MAX_BANDWIDTH_CARRY_S 5 33#define MAX_BANDWIDTH_CARRY_S 5
@@ -52,32 +52,27 @@ static struct GNUNET_CONTAINER_MultiHashMap *trackers;
52 */ 52 */
53struct GNUNET_TIME_Relative 53struct GNUNET_TIME_Relative
54GAS_reservations_reserve (const struct GNUNET_PeerIdentity *peer, 54GAS_reservations_reserve (const struct GNUNET_PeerIdentity *peer,
55 int32_t amount) 55 int32_t amount)
56{ 56{
57 struct GNUNET_BANDWIDTH_Tracker *tracker; 57 struct GNUNET_BANDWIDTH_Tracker *tracker;
58 struct GNUNET_TIME_Relative ret; 58 struct GNUNET_TIME_Relative ret;
59 59
60 tracker = GNUNET_CONTAINER_multihashmap_get (trackers, 60 tracker = GNUNET_CONTAINER_multihashmap_get (trackers, &peer->hashPubKey);
61 &peer->hashPubKey);
62 if (NULL == tracker) 61 if (NULL == tracker)
63 return GNUNET_TIME_UNIT_ZERO; /* not connected, satisfy now */ 62 return GNUNET_TIME_UNIT_ZERO; /* not connected, satisfy now */
64 if (amount >= 0) 63 if (amount >= 0)
65 { 64 {
66 ret = GNUNET_BANDWIDTH_tracker_get_delay (tracker, 65 ret = GNUNET_BANDWIDTH_tracker_get_delay (tracker, amount);
67 amount);
68 if (ret.rel_value > 0) 66 if (ret.rel_value > 0)
69 { 67 {
70 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 68 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
71 "Delay to satisfy reservation for %d bytes is %llu ms\n", 69 "Delay to satisfy reservation for %d bytes is %llu ms\n",
72 (int) amount, 70 (int) amount, (unsigned long long) ret.rel_value);
73 (unsigned long long) ret.rel_value);
74 return ret; 71 return ret;
75 } 72 }
76 } 73 }
77 (void) GNUNET_BANDWIDTH_tracker_consume (tracker, amount); 74 (void) GNUNET_BANDWIDTH_tracker_consume (tracker, amount);
78 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 75 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reserved %d bytes\n", (int) amount);
79 "Reserved %d bytes\n",
80 (int) amount);
81 return GNUNET_TIME_UNIT_ZERO; 76 return GNUNET_TIME_UNIT_ZERO;
82} 77}
83 78
@@ -85,42 +80,37 @@ GAS_reservations_reserve (const struct GNUNET_PeerIdentity *peer,
85/** 80/**
86 * Set the amount of bandwidth the other peer could currently transmit 81 * Set the amount of bandwidth the other peer could currently transmit
87 * to us (as far as we know) to the given value. 82 * to us (as far as we know) to the given value.
88 * 83 *
89 * @param peer identity of the peer 84 * @param peer identity of the peer
90 * @param bandwidth_in currently available bandwidth from that peer to 85 * @param bandwidth_in currently available bandwidth from that peer to
91 * this peer (estimate) 86 * this peer (estimate)
92 */ 87 */
93void 88void
94GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer, 89GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer,
95 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 90 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
96{ 91{
97 struct GNUNET_BANDWIDTH_Tracker *tracker; 92 struct GNUNET_BANDWIDTH_Tracker *tracker;
98 93
99 tracker = GNUNET_CONTAINER_multihashmap_get (trackers, 94 tracker = GNUNET_CONTAINER_multihashmap_get (trackers, &peer->hashPubKey);
100 &peer->hashPubKey);
101 if (0 == ntohl (bandwidth_in.value__)) 95 if (0 == ntohl (bandwidth_in.value__))
102 { 96 {
103 GNUNET_assert (GNUNET_YES == 97 GNUNET_assert (GNUNET_YES ==
104 GNUNET_CONTAINER_multihashmap_remove (trackers, 98 GNUNET_CONTAINER_multihashmap_remove (trackers,
105 &peer->hashPubKey, 99 &peer->hashPubKey,
106 tracker)); 100 tracker));
107 GNUNET_free (tracker); 101 GNUNET_free (tracker);
108 return; 102 return;
109 } 103 }
110 if (NULL == tracker) 104 if (NULL == tracker)
111 { 105 {
112 tracker = GNUNET_malloc (sizeof (struct GNUNET_BANDWIDTH_Tracker)); 106 tracker = GNUNET_malloc (sizeof (struct GNUNET_BANDWIDTH_Tracker));
113 GNUNET_BANDWIDTH_tracker_init (tracker, 107 GNUNET_BANDWIDTH_tracker_init (tracker, bandwidth_in,
114 bandwidth_in, 108 MAX_BANDWIDTH_CARRY_S);
115 MAX_BANDWIDTH_CARRY_S); 109 GNUNET_CONTAINER_multihashmap_put (trackers, &peer->hashPubKey, tracker,
116 GNUNET_CONTAINER_multihashmap_put (trackers, 110 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
117 &peer->hashPubKey,
118 tracker,
119 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
120 return; 111 return;
121 } 112 }
122 GNUNET_BANDWIDTH_tracker_update_quota (tracker, 113 GNUNET_BANDWIDTH_tracker_update_quota (tracker, bandwidth_in);
123 bandwidth_in);
124} 114}
125 115
126 116
@@ -130,7 +120,7 @@ GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer,
130void 120void
131GAS_reservations_init () 121GAS_reservations_init ()
132{ 122{
133 trackers = GNUNET_CONTAINER_multihashmap_create(128); 123 trackers = GNUNET_CONTAINER_multihashmap_create (128);
134} 124}
135 125
136 126
@@ -142,10 +132,8 @@ GAS_reservations_init ()
142 * @param value the 'struct GNUNET_BANDWIDTH_Tracker' to free 132 * @param value the 'struct GNUNET_BANDWIDTH_Tracker' to free
143 * @return GNUNET_OK (continue to iterate) 133 * @return GNUNET_OK (continue to iterate)
144 */ 134 */
145static int 135static int
146free_tracker (void *cls, 136free_tracker (void *cls, const GNUNET_HashCode * key, void *value)
147 const GNUNET_HashCode * key,
148 void *value)
149{ 137{
150 struct GNUNET_BANDWIDTH_Tracker *tracker = value; 138 struct GNUNET_BANDWIDTH_Tracker *tracker = value;
151 139
diff --git a/src/ats/gnunet-service-ats_reservations.h b/src/ats/gnunet-service-ats_reservations.h
index 5112f8213..5ddec9bd6 100644
--- a/src/ats/gnunet-service-ats_reservations.h
+++ b/src/ats/gnunet-service-ats_reservations.h
@@ -32,14 +32,15 @@
32/** 32/**
33 * Set the amount of bandwidth the other peer could currently transmit 33 * Set the amount of bandwidth the other peer could currently transmit
34 * to us (as far as we know) to the given value. 34 * to us (as far as we know) to the given value.
35 * 35 *
36 * @param peer identity of the peer 36 * @param peer identity of the peer
37 * @param bandwidth_in currently available bandwidth from that peer to 37 * @param bandwidth_in currently available bandwidth from that peer to
38 * this peer (estimate) 38 * this peer (estimate)
39 */ 39 */
40void 40void
41GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer, 41GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer,
42 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in); 42 struct GNUNET_BANDWIDTH_Value32NBO
43 bandwidth_in);
43 44
44 45
45/** 46/**
@@ -55,7 +56,7 @@ GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer,
55 */ 56 */
56struct GNUNET_TIME_Relative 57struct GNUNET_TIME_Relative
57GAS_reservations_reserve (const struct GNUNET_PeerIdentity *peer, 58GAS_reservations_reserve (const struct GNUNET_PeerIdentity *peer,
58 int32_t amount); 59 int32_t amount);
59 60
60 61
61/** 62/**
diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c
index bb95182c8..4af44e29b 100644
--- a/src/ats/gnunet-service-ats_scheduling.c
+++ b/src/ats/gnunet-service-ats_scheduling.c
@@ -46,7 +46,7 @@ static struct GNUNET_SERVER_Client *my_client;
46 * Register a new scheduling client. 46 * Register a new scheduling client.
47 * 47 *
48 * @param client handle of the new client 48 * @param client handle of the new client
49 * @return GNUNET_OK on success, GNUNET_SYSERR on error 49 * @return GNUNET_OK on success, GNUNET_SYSERR on error
50 */ 50 */
51int 51int
52GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client) 52GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client)
@@ -54,7 +54,7 @@ GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client)
54 if (my_client != NULL) 54 if (my_client != NULL)
55 { 55 {
56 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 56 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
57 "This ATS already has a scheduling client, refusing new scheduling client for now.\n"); 57 "This ATS already has a scheduling client, refusing new scheduling client for now.\n");
58 return GNUNET_SYSERR; 58 return GNUNET_SYSERR;
59 } 59 }
60 my_client = client; 60 my_client = client;
@@ -96,32 +96,37 @@ GAS_scheduling_remove_client (struct GNUNET_SERVER_Client *client)
96 * @param bandwidth_in assigned inbound bandwidth 96 * @param bandwidth_in assigned inbound bandwidth
97 */ 97 */
98void 98void
99GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *peer, 99GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity
100 const char *plugin_name, 100 *peer, const char *plugin_name,
101 const void *plugin_addr, size_t plugin_addr_len, 101 const void *plugin_addr,
102 uint32_t session_id, 102 size_t plugin_addr_len,
103 const struct GNUNET_ATS_Information *atsi, 103 uint32_t session_id,
104 uint32_t atsi_count, 104 const struct GNUNET_ATS_Information
105 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 105 *atsi, uint32_t atsi_count,
106 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 106 struct GNUNET_BANDWIDTH_Value32NBO
107 bandwidth_out,
108 struct GNUNET_BANDWIDTH_Value32NBO
109 bandwidth_in)
107{ 110{
108 struct AddressSuggestionMessage *msg; 111 struct AddressSuggestionMessage *msg;
109 size_t plugin_name_length = strlen (plugin_name) + 1; 112 size_t plugin_name_length = strlen (plugin_name) + 1;
110 size_t msize = sizeof (struct AddressSuggestionMessage) + atsi_count * sizeof (struct GNUNET_ATS_Information) 113 size_t msize =
111 + plugin_addr_len + plugin_name_length; 114 sizeof (struct AddressSuggestionMessage) +
115 atsi_count * sizeof (struct GNUNET_ATS_Information) + plugin_addr_len +
116 plugin_name_length;
112 char buf[msize]; 117 char buf[msize];
113 struct GNUNET_ATS_Information *atsp; 118 struct GNUNET_ATS_Information *atsp;
114 char *addrp; 119 char *addrp;
115 120
116 if (my_client == NULL) 121 if (my_client == NULL)
117 return; 122 return;
118 GNUNET_STATISTICS_update (GSA_stats, 123 GNUNET_STATISTICS_update (GSA_stats, "# address suggestions made", 1,
119 "# address suggestions made", 124 GNUNET_NO);
120 1,
121 GNUNET_NO);
122 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); 125 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
123 GNUNET_assert (atsi_count < GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)); 126 GNUNET_assert (atsi_count <
124 msg = (struct AddressSuggestionMessage*) buf; 127 GNUNET_SERVER_MAX_MESSAGE_SIZE /
128 sizeof (struct GNUNET_ATS_Information));
129 msg = (struct AddressSuggestionMessage *) buf;
125 msg->header.size = htons (msize); 130 msg->header.size = htons (msize);
126 msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION); 131 msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION);
127 msg->ats_count = htonl (atsi_count); 132 msg->ats_count = htonl (atsi_count);
@@ -131,15 +136,13 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *pe
131 msg->session_id = htonl (session_id); 136 msg->session_id = htonl (session_id);
132 msg->bandwidth_out = bandwidth_out; 137 msg->bandwidth_out = bandwidth_out;
133 msg->bandwidth_in = bandwidth_in; 138 msg->bandwidth_in = bandwidth_in;
134 atsp = (struct GNUNET_ATS_Information* ) &msg[1]; 139 atsp = (struct GNUNET_ATS_Information *) &msg[1];
135 memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count); 140 memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
136 addrp = (char*) &atsp[atsi_count]; 141 addrp = (char *) &atsp[atsi_count];
137 memcpy (addrp, plugin_addr, plugin_addr_len); 142 memcpy (addrp, plugin_addr, plugin_addr_len);
138 strcpy (&addrp[plugin_addr_len], plugin_name); 143 strcpy (&addrp[plugin_addr_len], plugin_name);
139 GNUNET_SERVER_notification_context_unicast (nc, 144 GNUNET_SERVER_notification_context_unicast (nc, my_client, &msg->header,
140 my_client, 145 GNUNET_YES);
141 &msg->header,
142 GNUNET_YES);
143} 146}
144 147
145 148
@@ -152,16 +155,15 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *pe
152 */ 155 */
153void 156void
154GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client, 157GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client,
155 const struct GNUNET_MessageHeader *message) 158 const struct GNUNET_MessageHeader *message)
156
157{ 159{
158 const struct RequestAddressMessage * msg = (const struct RequestAddressMessage *) message; 160 const struct RequestAddressMessage *msg =
161 (const struct RequestAddressMessage *) message;
159 162
160 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "REQUEST_ADDRESS"); 163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
161 GNUNET_STATISTICS_update (GSA_stats, 164 "REQUEST_ADDRESS");
162 "# address requests received", 165 GNUNET_STATISTICS_update (GSA_stats, "# address requests received", 1,
163 1, 166 GNUNET_NO);
164 GNUNET_NO);
165 GNUNET_break (0 == ntohl (msg->reserved)); 167 GNUNET_break (0 == ntohl (msg->reserved));
166 GAS_addresses_request_address (&msg->peer); 168 GAS_addresses_request_address (&msg->peer);
167 GNUNET_SERVER_receive_done (client, GNUNET_OK); 169 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -177,9 +179,9 @@ GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client,
177 */ 179 */
178void 180void
179GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client, 181GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client,
180 const struct GNUNET_MessageHeader *message) 182 const struct GNUNET_MessageHeader *message)
181{ 183{
182 const struct AddressUpdateMessage * m; 184 const struct AddressUpdateMessage *m;
183 const struct GNUNET_ATS_Information *atsi; 185 const struct GNUNET_ATS_Information *atsi;
184 const char *address; 186 const char *address;
185 const char *plugin_name; 187 const char *plugin_name;
@@ -188,9 +190,8 @@ GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client,
188 uint32_t ats_count; 190 uint32_t ats_count;
189 uint16_t size; 191 uint16_t size;
190 192
191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
192 "Received `%s' message\n", 194 "ADDRESS_UPDATE");
193 "ADDRESS_UPDATE");
194 size = ntohs (message->size); 195 size = ntohs (message->size);
195 if (size < sizeof (struct AddressUpdateMessage)) 196 if (size < sizeof (struct AddressUpdateMessage))
196 { 197 {
@@ -198,38 +199,31 @@ GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client,
198 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 199 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
199 return; 200 return;
200 } 201 }
201 m = (const struct AddressUpdateMessage*) message; 202 m = (const struct AddressUpdateMessage *) message;
202 ats_count = ntohl (m->ats_count); 203 ats_count = ntohl (m->ats_count);
203 address_length = ntohs (m->address_length); 204 address_length = ntohs (m->address_length);
204 plugin_name_length = ntohs (m->plugin_name_length); 205 plugin_name_length = ntohs (m->plugin_name_length);
205 atsi = (const struct GNUNET_ATS_Information*) &m[1]; 206 atsi = (const struct GNUNET_ATS_Information *) &m[1];
206 address = (const char*) &atsi[ats_count]; 207 address = (const char *) &atsi[ats_count];
207 if (plugin_name_length != 0) 208 if (plugin_name_length != 0)
208 plugin_name = &address[address_length]; 209 plugin_name = &address[address_length];
209 else 210 else
210 plugin_name = ""; 211 plugin_name = "";
211 if ( (address_length + 212 if ((address_length + plugin_name_length +
212 plugin_name_length + 213 ats_count * sizeof (struct GNUNET_ATS_Information) +
213 ats_count * sizeof (struct GNUNET_ATS_Information) + 214 sizeof (struct AddressUpdateMessage) != ntohs (message->size)) ||
214 sizeof (struct AddressUpdateMessage) != ntohs (message->size)) || 215 (ats_count >
215 (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) || 216 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information))
216 (plugin_name[plugin_name_length - 1] != '\0') ) 217 || (plugin_name[plugin_name_length - 1] != '\0'))
217 { 218 {
218 GNUNET_break (0); 219 GNUNET_break (0);
219 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 220 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
220 return; 221 return;
221 } 222 }
222 GNUNET_STATISTICS_update (GSA_stats, 223 GNUNET_STATISTICS_update (GSA_stats, "# address updates received", 1,
223 "# address updates received", 224 GNUNET_NO);
224 1, 225 GAS_addresses_update (&m->peer, plugin_name, address, address_length,
225 GNUNET_NO); 226 ntohl (m->session_id), atsi, ats_count);
226 GAS_addresses_update (&m->peer,
227 plugin_name,
228 address,
229 address_length,
230 ntohl (m->session_id),
231 atsi,
232 ats_count);
233 GNUNET_SERVER_receive_done (client, GNUNET_OK); 227 GNUNET_SERVER_receive_done (client, GNUNET_OK);
234} 228}
235 229
@@ -245,7 +239,7 @@ void
245GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client, 239GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client,
246 const struct GNUNET_MessageHeader *message) 240 const struct GNUNET_MessageHeader *message)
247{ 241{
248 const struct AddressUseMessage * m; 242 const struct AddressUseMessage *m;
249 const char *address; 243 const char *address;
250 const char *plugin_name; 244 const char *plugin_name;
251 uint16_t address_length; 245 uint16_t address_length;
@@ -253,8 +247,7 @@ GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client,
253 247
254 uint16_t size; 248 uint16_t size;
255 249
256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
257 "Received `%s' message\n",
258 "ADDRESS_IN_USE"); 251 "ADDRESS_IN_USE");
259 size = ntohs (message->size); 252 size = ntohs (message->size);
260 if (size < sizeof (struct AddressUseMessage)) 253 if (size < sizeof (struct AddressUseMessage))
@@ -263,21 +256,20 @@ GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client,
263 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 256 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
264 return; 257 return;
265 } 258 }
266 m = (const struct AddressUseMessage*) message; 259 m = (const struct AddressUseMessage *) message;
267 260
268 address_length = ntohs (m->address_length); 261 address_length = ntohs (m->address_length);
269 plugin_name_length = ntohs (m->plugin_name_length); 262 plugin_name_length = ntohs (m->plugin_name_length);
270 263
271 address = (const char*) &m[1]; 264 address = (const char *) &m[1];
272 if (plugin_name_length != 0) 265 if (plugin_name_length != 0)
273 plugin_name = &address[address_length]; 266 plugin_name = &address[address_length];
274 else 267 else
275 plugin_name = ""; 268 plugin_name = "";
276 269
277 if ( (address_length + 270 if ((address_length + plugin_name_length +
278 plugin_name_length + 271 sizeof (struct AddressUseMessage) != ntohs (message->size)) ||
279 sizeof (struct AddressUseMessage) != ntohs (message->size)) || 272 (plugin_name[plugin_name_length - 1] != '\0'))
280 (plugin_name[plugin_name_length - 1] != '\0') )
281 { 273 {
282 GNUNET_break (0); 274 GNUNET_break (0);
283 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 275 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -306,10 +298,9 @@ GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client,
306 */ 298 */
307void 299void
308GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client, 300GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client,
309 const struct GNUNET_MessageHeader *message) 301 const struct GNUNET_MessageHeader *message)
310
311{ 302{
312 const struct AddressDestroyedMessage * m; 303 const struct AddressDestroyedMessage *m;
313 struct SessionReleaseMessage srm; 304 struct SessionReleaseMessage srm;
314 const char *address; 305 const char *address;
315 const char *plugin_name; 306 const char *plugin_name;
@@ -317,60 +308,50 @@ GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client,
317 uint16_t plugin_name_length; 308 uint16_t plugin_name_length;
318 uint16_t size; 309 uint16_t size;
319 310
320 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message of size %u %u\n",
321 "Received `%s' message of size %u %u\n", 312 "ADDRESS_DESTROYED", ntohs (message->size),
322 "ADDRESS_DESTROYED", ntohs (message->size), sizeof (struct AddressDestroyedMessage)); 313 sizeof (struct AddressDestroyedMessage));
323 size = ntohs (message->size); 314 size = ntohs (message->size);
324 if ( (size < sizeof (struct AddressDestroyedMessage)) || 315 if ((size < sizeof (struct AddressDestroyedMessage)) || (client != my_client))
325 (client != my_client) )
326 { 316 {
327 GNUNET_break (0); 317 GNUNET_break (0);
328 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 318 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
329 return; 319 return;
330 } 320 }
331 m = (const struct AddressDestroyedMessage*) message; 321 m = (const struct AddressDestroyedMessage *) message;
332 GNUNET_break (0 == ntohl (m->reserved)); 322 GNUNET_break (0 == ntohl (m->reserved));
333 address_length = ntohs (m->address_length); 323 address_length = ntohs (m->address_length);
334 plugin_name_length = ntohs (m->plugin_name_length); 324 plugin_name_length = ntohs (m->plugin_name_length);
335 address = (const char*) &m[1]; 325 address = (const char *) &m[1];
336 if (plugin_name_length != 0) 326 if (plugin_name_length != 0)
337 plugin_name = &address[address_length]; 327 plugin_name = &address[address_length];
338 else 328 else
339 plugin_name = ""; 329 plugin_name = "";
340 if ( (address_length + 330 if ((address_length + plugin_name_length +
341 plugin_name_length + 331 sizeof (struct AddressDestroyedMessage) != ntohs (message->size)))
342 sizeof (struct AddressDestroyedMessage) != ntohs (message->size)))
343 { 332 {
344 GNUNET_break (0); 333 GNUNET_break (0);
345 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 334 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
346 return; 335 return;
347 } 336 }
348 if ( (plugin_name_length != 0) && 337 if ((plugin_name_length != 0) &&
349 (plugin_name[plugin_name_length - 1] != '\0') ) 338 (plugin_name[plugin_name_length - 1] != '\0'))
350 { 339 {
351 GNUNET_break (0); 340 GNUNET_break (0);
352 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 341 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
353 return; 342 return;
354 } 343 }
355 GNUNET_STATISTICS_update (GSA_stats, 344 GNUNET_STATISTICS_update (GSA_stats, "# addresses destroyed", 1, GNUNET_NO);
356 "# addresses destroyed", 345 GAS_addresses_destroy (&m->peer, plugin_name, address, address_length,
357 1, 346 ntohl (m->session_id));
358 GNUNET_NO);
359 GAS_addresses_destroy (&m->peer,
360 plugin_name,
361 address,
362 address_length,
363 ntohl (m->session_id));
364 if (0 != ntohl (m->session_id)) 347 if (0 != ntohl (m->session_id))
365 { 348 {
366 srm.header.type = ntohs (GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE); 349 srm.header.type = ntohs (GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE);
367 srm.header.size = ntohs (sizeof (struct SessionReleaseMessage)); 350 srm.header.size = ntohs (sizeof (struct SessionReleaseMessage));
368 srm.session_id = m->session_id; 351 srm.session_id = m->session_id;
369 srm.peer = m->peer; 352 srm.peer = m->peer;
370 GNUNET_SERVER_notification_context_unicast (nc, 353 GNUNET_SERVER_notification_context_unicast (nc, client, &srm.header,
371 client, 354 GNUNET_NO);
372 &srm.header,
373 GNUNET_NO);
374 } 355 }
375 GNUNET_SERVER_receive_done (client, GNUNET_OK); 356 GNUNET_SERVER_receive_done (client, GNUNET_OK);
376} 357}
@@ -382,7 +363,7 @@ GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client,
382 * @param server handle to our server 363 * @param server handle to our server
383 */ 364 */
384void 365void
385GAS_scheduling_init (struct GNUNET_SERVER_Handle *server) 366GAS_scheduling_init (struct GNUNET_SERVER_Handle *server)
386{ 367{
387 nc = GNUNET_SERVER_notification_context_create (server, 128); 368 nc = GNUNET_SERVER_notification_context_create (server, 128);
388} 369}
diff --git a/src/ats/gnunet-service-ats_scheduling.h b/src/ats/gnunet-service-ats_scheduling.h
index 7eeaba8b3..44ac705e3 100644
--- a/src/ats/gnunet-service-ats_scheduling.h
+++ b/src/ats/gnunet-service-ats_scheduling.h
@@ -34,7 +34,7 @@
34 * Register a new scheduling client. 34 * Register a new scheduling client.
35 * 35 *
36 * @param client handle of the new client 36 * @param client handle of the new client
37 * @return GNUNET_OK on success, GNUNET_SYSERR on error 37 * @return GNUNET_OK on success, GNUNET_SYSERR on error
38 */ 38 */
39int 39int
40GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client); 40GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client);
@@ -65,14 +65,17 @@ GAS_scheduling_remove_client (struct GNUNET_SERVER_Client *client);
65 * @param bandwidth_in assigned inbound bandwidth 65 * @param bandwidth_in assigned inbound bandwidth
66 */ 66 */
67void 67void
68GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *peer, 68GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity
69 const char *plugin_name, 69 *peer, const char *plugin_name,
70 const void *plugin_addr, size_t plugin_addr_len, 70 const void *plugin_addr,
71 uint32_t session_id, 71 size_t plugin_addr_len,
72 const struct GNUNET_ATS_Information *atsi, 72 uint32_t session_id,
73 uint32_t atsi_count, 73 const struct GNUNET_ATS_Information
74 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 74 *atsi, uint32_t atsi_count,
75 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in); 75 struct GNUNET_BANDWIDTH_Value32NBO
76 bandwidth_out,
77 struct GNUNET_BANDWIDTH_Value32NBO
78 bandwidth_in);
76 79
77 80
78/** 81/**
@@ -84,7 +87,7 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *pe
84 */ 87 */
85void 88void
86GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client, 89GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client,
87 const struct GNUNET_MessageHeader *message); 90 const struct GNUNET_MessageHeader *message);
88 91
89 92
90 93
@@ -97,7 +100,7 @@ GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client,
97 */ 100 */
98void 101void
99GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client, 102GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client,
100 const struct GNUNET_MessageHeader *message); 103 const struct GNUNET_MessageHeader *message);
101 104
102 105
103/** 106/**
@@ -120,7 +123,7 @@ GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client,
120 */ 123 */
121void 124void
122GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client, 125GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client,
123 const struct GNUNET_MessageHeader *message); 126 const struct GNUNET_MessageHeader *message);
124 127
125 128
126/** 129/**
diff --git a/src/ats/test_ats_api_bandwidth_consumption.c b/src/ats/test_ats_api_bandwidth_consumption.c
index d2a7b53dc..1eb57fcc8 100644
--- a/src/ats/test_ats_api_bandwidth_consumption.c
+++ b/src/ats/test_ats_api_bandwidth_consumption.c
@@ -44,9 +44,9 @@ static struct GNUNET_ATS_PerformanceHandle *atp;
44 44
45struct GNUNET_ATS_ReservationContext *sh; 45struct GNUNET_ATS_ReservationContext *sh;
46 46
47static struct GNUNET_OS_Process * arm_proc; 47static struct GNUNET_OS_Process *arm_proc;
48 48
49static struct PeerContext * p; 49static struct PeerContext *p;
50 50
51static uint32_t bw_in; 51static uint32_t bw_in;
52 52
@@ -56,23 +56,23 @@ static int ret;
56 56
57struct Address 57struct Address
58{ 58{
59 char * plugin; 59 char *plugin;
60 size_t plugin_len; 60 size_t plugin_len;
61 61
62 void * addr; 62 void *addr;
63 size_t addr_len; 63 size_t addr_len;
64 64
65 struct GNUNET_ATS_Information * ats; 65 struct GNUNET_ATS_Information *ats;
66 int ats_count; 66 int ats_count;
67 67
68 void *session; 68 void *session;
69}; 69};
70 70
71struct PeerContext 71struct PeerContext
72{ 72{
73 struct GNUNET_PeerIdentity id; 73 struct GNUNET_PeerIdentity id;
74 74
75 struct Address * addr; 75 struct Address *addr;
76}; 76};
77 77
78 78
@@ -94,12 +94,12 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
94 94
95 if (consume_task != GNUNET_SCHEDULER_NO_TASK) 95 if (consume_task != GNUNET_SCHEDULER_NO_TASK)
96 { 96 {
97 GNUNET_SCHEDULER_cancel(consume_task); 97 GNUNET_SCHEDULER_cancel (consume_task);
98 consume_task = GNUNET_SCHEDULER_NO_TASK; 98 consume_task = GNUNET_SCHEDULER_NO_TASK;
99 } 99 }
100 100
101 if (sh != NULL) 101 if (sh != NULL)
102 GNUNET_ATS_reserve_bandwidth_cancel(sh); 102 GNUNET_ATS_reserve_bandwidth_cancel (sh);
103 103
104 if (ats != NULL) 104 if (ats != NULL)
105 GNUNET_ATS_scheduling_done (ats); 105 GNUNET_ATS_scheduling_done (ats);
@@ -120,13 +120,13 @@ end ()
120{ 120{
121 if (die_task != GNUNET_SCHEDULER_NO_TASK) 121 if (die_task != GNUNET_SCHEDULER_NO_TASK)
122 { 122 {
123 GNUNET_SCHEDULER_cancel(die_task); 123 GNUNET_SCHEDULER_cancel (die_task);
124 die_task = GNUNET_SCHEDULER_NO_TASK; 124 die_task = GNUNET_SCHEDULER_NO_TASK;
125 } 125 }
126 126
127 if (consume_task != GNUNET_SCHEDULER_NO_TASK) 127 if (consume_task != GNUNET_SCHEDULER_NO_TASK)
128 { 128 {
129 GNUNET_SCHEDULER_cancel(consume_task); 129 GNUNET_SCHEDULER_cancel (consume_task);
130 consume_task = GNUNET_SCHEDULER_NO_TASK; 130 consume_task = GNUNET_SCHEDULER_NO_TASK;
131 } 131 }
132 132
@@ -142,41 +142,25 @@ end ()
142 stop_arm (); 142 stop_arm ();
143} 143}
144 144
145void performance_cb (void *cls, 145void
146 const struct 146performance_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
147 GNUNET_PeerIdentity * 147 const char *plugin_name, const void *plugin_addr,
148 peer, 148 size_t plugin_addr_len,
149 const char *plugin_name, 149 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
150 const void *plugin_addr, 150 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
151 size_t plugin_addr_len, 151 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
152 struct
153 GNUNET_BANDWIDTH_Value32NBO
154 bandwidth_out,
155 struct
156 GNUNET_BANDWIDTH_Value32NBO
157 bandwidth_in,
158 const struct
159 GNUNET_ATS_Information
160 * ats,
161 uint32_t ats_count)
162{ 152{
163 153
164} 154}
165 155
166void reservation_cb (void *cls, 156void
167 const struct 157reservation_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
168 GNUNET_PeerIdentity * 158 int32_t amount, struct GNUNET_TIME_Relative res_delay)
169 peer,
170 int32_t amount,
171 struct
172 GNUNET_TIME_Relative
173 res_delay)
174{ 159{
175 sh = NULL; 160 sh = NULL;
176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS reserved bandwidth of %i to peer `%s' in %llu ms\n", 161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
177 amount, 162 "ATS reserved bandwidth of %i to peer `%s' in %llu ms\n", amount,
178 GNUNET_i2s (peer), 163 GNUNET_i2s (peer), res_delay.rel_value);
179 res_delay.rel_value);
180} 164}
181 165
182static void 166static void
@@ -184,51 +168,43 @@ consume_bandwidth (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
184{ 168{
185 consume_task = GNUNET_SCHEDULER_NO_TASK; 169 consume_task = GNUNET_SCHEDULER_NO_TASK;
186 int32_t to_reserve = 500; 170 int32_t to_reserve = 500;
187 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to reserver bandwidth of %i to peer `%s' in %llu ms\n",
188 to_reserve,
189 GNUNET_i2s (&p->id));
190 171
191 sh = GNUNET_ATS_reserve_bandwidth (atp, &p->id, to_reserve, &reservation_cb, NULL); 172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
173 "Trying to reserver bandwidth of %i to peer `%s' in %llu ms\n",
174 to_reserve, GNUNET_i2s (&p->id));
175
176 sh = GNUNET_ATS_reserve_bandwidth (atp, &p->id, to_reserve, &reservation_cb,
177 NULL);
192} 178}
193 179
194static void 180static void
195address_suggest_cb (void *cls, 181address_suggest_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
196 const struct 182 const char *plugin_name, const void *plugin_addr,
197 GNUNET_PeerIdentity * 183 size_t plugin_addr_len, struct Session *session,
198 peer, 184 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
199 const char *plugin_name, 185 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
200 const void *plugin_addr, 186 const struct GNUNET_ATS_Information *ats,
201 size_t plugin_addr_len,
202 struct Session * session,
203 struct
204 GNUNET_BANDWIDTH_Value32NBO
205 bandwidth_out,
206 struct
207 GNUNET_BANDWIDTH_Value32NBO
208 bandwidth_in,
209 const struct
210 GNUNET_ATS_Information
211 * ats,
212 uint32_t ats_count) 187 uint32_t ats_count)
213
214{ 188{
215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggested address for peer `%s'\n", GNUNET_i2s (peer)); 189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggested address for peer `%s'\n",
190 GNUNET_i2s (peer));
216 191
217 bw_in = ntohl (bandwidth_in.value__); 192 bw_in = ntohl (bandwidth_in.value__);
218 bw_out = ntohl (bandwidth_out.value__); 193 bw_out = ntohl (bandwidth_out.value__);
219 194
220 consume_task = GNUNET_SCHEDULER_add_now(&consume_bandwidth, NULL); 195 consume_task = GNUNET_SCHEDULER_add_now (&consume_bandwidth, NULL);
221} 196}
222 197
223void 198void
224start_arm (const char *cfgname) 199start_arm (const char *cfgname)
225{ 200{
226 arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 201 arm_proc =
227 "gnunet-service-arm", 202 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
203 "gnunet-service-arm",
228#if VERBOSE_ARM 204#if VERBOSE_ARM
229 "-L", "DEBUG", 205 "-L", "DEBUG",
230#endif 206#endif
231 "-c", cfgname, NULL); 207 "-c", cfgname, NULL);
232} 208}
233 209
234static void 210static void
@@ -238,7 +214,7 @@ check (void *cls, char *const *args, const char *cfgfile,
238 ret = GNUNET_SYSERR; 214 ret = GNUNET_SYSERR;
239 struct Address *addr; 215 struct Address *addr;
240 216
241 die_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_badly, NULL); 217 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
242 start_arm (cfgfile); 218 start_arm (cfgfile);
243 219
244 ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); 220 ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
@@ -257,25 +233,28 @@ check (void *cls, char *const *args, const char *cfgfile,
257 { 233 {
258 ret = GNUNET_SYSERR; 234 ret = GNUNET_SYSERR;
259 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to init ATS performance\n"); 235 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to init ATS performance\n");
260 end_badly(NULL, NULL); 236 end_badly (NULL, NULL);
261 GNUNET_free (p); 237 GNUNET_free (p);
262 GNUNET_free (addr); 238 GNUNET_free (addr);
263 return; 239 return;
264 } 240 }
265 241
266 /* set up peer */ 242 /* set up peer */
267 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p->id.hashPubKey); 243 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
244 &p->id.hashPubKey);
268 245
269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s (&p->id)); 246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
247 GNUNET_i2s (&p->id));
270 p->addr = addr; 248 p->addr = addr;
271 addr->plugin = "test"; 249 addr->plugin = "test";
272 addr->session = NULL; 250 addr->session = NULL;
273 addr->addr = NULL; 251 addr->addr = NULL;
274 addr->addr_len = 0; 252 addr->addr_len = 0;
275 253
276 GNUNET_ATS_address_update(ats, &p->id, addr->plugin, addr->addr, addr->addr_len, addr->session, NULL, 0); 254 GNUNET_ATS_address_update (ats, &p->id, addr->plugin, addr->addr,
255 addr->addr_len, addr->session, NULL, 0);
277 256
278 GNUNET_ATS_suggest_address(ats, &p->id); 257 GNUNET_ATS_suggest_address (ats, &p->id);
279} 258}
280 259
281int 260int
@@ -297,8 +276,8 @@ main (int argc, char *argv[])
297 }; 276 };
298 277
299 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, 278 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
300 "test_ats_api_bandwidth_consumption", "nohelp", options, &check, 279 "test_ats_api_bandwidth_consumption", "nohelp", options,
301 NULL); 280 &check, NULL);
302 281
303 282
304 return ret; 283 return ret;
diff --git a/src/ats/test_ats_api_scheduling.c b/src/ats/test_ats_api_scheduling.c
index 201855283..a2ee7f060 100644
--- a/src/ats/test_ats_api_scheduling.c
+++ b/src/ats/test_ats_api_scheduling.c
@@ -44,7 +44,7 @@ static GNUNET_SCHEDULER_TaskIdentifier die_task;
44 44
45static struct GNUNET_ATS_SchedulingHandle *ats; 45static struct GNUNET_ATS_SchedulingHandle *ats;
46 46
47struct GNUNET_OS_Process * arm_proc; 47struct GNUNET_OS_Process *arm_proc;
48 48
49 49
50 50
@@ -52,23 +52,23 @@ static int ret;
52 52
53struct Address 53struct Address
54{ 54{
55 char * plugin; 55 char *plugin;
56 size_t plugin_len; 56 size_t plugin_len;
57 57
58 void * addr; 58 void *addr;
59 size_t addr_len; 59 size_t addr_len;
60 60
61 struct GNUNET_ATS_Information * ats; 61 struct GNUNET_ATS_Information *ats;
62 int ats_count; 62 int ats_count;
63 63
64 void *session; 64 void *session;
65}; 65};
66 66
67struct PeerContext 67struct PeerContext
68{ 68{
69 struct GNUNET_PeerIdentity id; 69 struct GNUNET_PeerIdentity id;
70 70
71 struct Address * addr; 71 struct Address *addr;
72}; 72};
73 73
74struct Address addr[2]; 74struct Address addr[2];
@@ -105,7 +105,7 @@ end ()
105 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); 105 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n");
106 if (die_task != GNUNET_SCHEDULER_NO_TASK) 106 if (die_task != GNUNET_SCHEDULER_NO_TASK)
107 { 107 {
108 GNUNET_SCHEDULER_cancel(die_task); 108 GNUNET_SCHEDULER_cancel (die_task);
109 die_task = GNUNET_SCHEDULER_NO_TASK; 109 die_task = GNUNET_SCHEDULER_NO_TASK;
110 } 110 }
111 111
@@ -118,29 +118,19 @@ end ()
118 118
119 119
120static void 120static void
121address_suggest_cb (void *cls, 121address_suggest_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
122 const struct 122 const char *plugin_name, const void *plugin_addr,
123 GNUNET_PeerIdentity * 123 size_t plugin_addr_len, struct Session *session,
124 peer, 124 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
125 const char *plugin_name, 125 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
126 const void *plugin_addr, 126 const struct GNUNET_ATS_Information *ats,
127 size_t plugin_addr_len,
128 struct Session * session,
129 struct
130 GNUNET_BANDWIDTH_Value32NBO
131 bandwidth_out,
132 struct
133 GNUNET_BANDWIDTH_Value32NBO
134 bandwidth_in,
135 const struct
136 GNUNET_ATS_Information
137 * ats,
138 uint32_t ats_count) 127 uint32_t ats_count)
139
140{ 128{
141 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggests address `%s'\n", GNUNET_i2s (peer)); 129 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggests address `%s'\n",
130 GNUNET_i2s (peer));
142 131
143 GNUNET_assert (0 == memcmp (peer, &p[0].id, sizeof (struct GNUNET_PeerIdentity))); 132 GNUNET_assert (0 ==
133 memcmp (peer, &p[0].id, sizeof (struct GNUNET_PeerIdentity)));
144 GNUNET_assert (0 == strcmp (plugin_name, addr[0].plugin)); 134 GNUNET_assert (0 == strcmp (plugin_name, addr[0].plugin));
145 GNUNET_assert (plugin_addr_len == addr[0].addr_len); 135 GNUNET_assert (plugin_addr_len == addr[0].addr_len);
146 GNUNET_assert (0 == memcmp (plugin_addr, addr[0].plugin, plugin_addr_len)); 136 GNUNET_assert (0 == memcmp (plugin_addr, addr[0].plugin, plugin_addr_len));
@@ -148,27 +138,28 @@ address_suggest_cb (void *cls,
148 138
149 139
150 /* TODO ats merge 140 /* TODO ats merge
151 GNUNET_assert (ats_count == 2); 141 * GNUNET_assert (ats_count == 2);
152 GNUNET_assert (atsi[0].type == htons (1)); 142 * GNUNET_assert (atsi[0].type == htons (1));
153 GNUNET_assert (atsi[0].type == htons (2)); 143 * GNUNET_assert (atsi[0].type == htons (2));
154 GNUNET_assert (atsi[1].type == htons (2)); 144 * GNUNET_assert (atsi[1].type == htons (2));
155 GNUNET_assert (atsi[1].type == htons (2)); 145 * GNUNET_assert (atsi[1].type == htons (2));
156 */ 146 */
157 147
158 ret = 0; 148 ret = 0;
159 149
160 GNUNET_SCHEDULER_add_now(&end, NULL); 150 GNUNET_SCHEDULER_add_now (&end, NULL);
161} 151}
162 152
163void 153void
164start_arm (const char *cfgname) 154start_arm (const char *cfgname)
165{ 155{
166 arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 156 arm_proc =
167 "gnunet-service-arm", 157 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
158 "gnunet-service-arm",
168#if VERBOSE_ARM 159#if VERBOSE_ARM
169 "-L", "DEBUG", 160 "-L", "DEBUG",
170#endif 161#endif
171 "-c", cfgname, NULL); 162 "-c", cfgname, NULL);
172} 163}
173 164
174static void 165static void
@@ -177,7 +168,7 @@ check (void *cls, char *const *args, const char *cfgfile,
177{ 168{
178 ret = GNUNET_SYSERR; 169 ret = GNUNET_SYSERR;
179 170
180 die_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_badly, NULL); 171 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
181 start_arm (cfgfile); 172 start_arm (cfgfile);
182 173
183 ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); 174 ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
@@ -190,27 +181,33 @@ check (void *cls, char *const *args, const char *cfgfile,
190 } 181 }
191 182
192 /* set up peer */ 183 /* set up peer */
193 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p[0].id.hashPubKey); 184 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s (&p[0].id)); 185 &p[0].id.hashPubKey);
186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
187 GNUNET_i2s (&p[0].id));
195 188
196 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p[1].id.hashPubKey); 189 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s (&p[1].id)); 190 &p[1].id.hashPubKey);
191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
192 GNUNET_i2s (&p[1].id));
198 193
199 addr[0].plugin = "test"; 194 addr[0].plugin = "test";
200 addr[0].session = NULL; 195 addr[0].session = NULL;
201 addr[0].addr = strdup("test"); 196 addr[0].addr = strdup ("test");
202 addr[0].addr_len = 4; 197 addr[0].addr_len = 4;
203 198
204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing address creation\n"); 199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing address creation\n");
205 200
206 GNUNET_ATS_address_update(ats, &p[0].id, addr[0].plugin, addr[0].addr, addr[0].addr_len, addr[0].session, NULL, 0); 201 GNUNET_ATS_address_update (ats, &p[0].id, addr[0].plugin, addr[0].addr,
202 addr[0].addr_len, addr[0].session, NULL, 0);
207 203
208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing ATS info creation\n"); 204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing ATS info creation\n");
209 205
210 atsi[0].type = htonl (GNUNET_ATS_UTILIZATION_UP); 206 atsi[0].type = htonl (GNUNET_ATS_UTILIZATION_UP);
211 atsi[0].value = htonl (1024); 207 atsi[0].value = htonl (1024);
212 208
213 GNUNET_ATS_address_update(ats, &p[0].id, addr[0].plugin, addr[0].addr, addr[0].addr_len, addr[0].session, atsi, 1); 209 GNUNET_ATS_address_update (ats, &p[0].id, addr[0].plugin, addr[0].addr,
210 addr[0].addr_len, addr[0].session, atsi, 1);
214 211
215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing ATS info update\n"); 212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing ATS info update\n");
216 213
@@ -220,14 +217,18 @@ check (void *cls, char *const *args, const char *cfgfile,
220 atsi[1].type = htonl (GNUNET_ATS_UTILIZATION_DOWN); 217 atsi[1].type = htonl (GNUNET_ATS_UTILIZATION_DOWN);
221 atsi[1].value = htonl (1024); 218 atsi[1].value = htonl (1024);
222 219
223 GNUNET_ATS_address_update(ats, &p[0].id, addr[0].plugin, addr[0].addr, addr[0].addr_len, addr[0].session, atsi, 2); 220 GNUNET_ATS_address_update (ats, &p[0].id, addr[0].plugin, addr[0].addr,
221 addr[0].addr_len, addr[0].session, atsi, 2);
224 222
225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing manual address deletion \n"); 223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing manual address deletion \n");
226 GNUNET_ATS_address_update(ats, &p[1].id, addr[0].plugin, addr[0].addr, addr[0].addr_len, addr[0].session, NULL, 0); 224 GNUNET_ATS_address_update (ats, &p[1].id, addr[0].plugin, addr[0].addr,
227 GNUNET_ATS_address_destroyed (ats, &p[1].id, addr[0].plugin, addr[0].addr, addr[0].addr_len, addr[0].session ); 225 addr[0].addr_len, addr[0].session, NULL, 0);
228 226 GNUNET_ATS_address_destroyed (ats, &p[1].id, addr[0].plugin, addr[0].addr,
229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting peer `%s'\n", GNUNET_i2s (&p[0].id)); 227 addr[0].addr_len, addr[0].session);
230 GNUNET_ATS_suggest_address(ats, &p[0].id); 228
229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting peer `%s'\n",
230 GNUNET_i2s (&p[0].id));
231 GNUNET_ATS_suggest_address (ats, &p[0].id);
231} 232}
232 233
233int 234int
diff --git a/src/ats/test_ats_api_update_address.c b/src/ats/test_ats_api_update_address.c
index 78011d492..f23747962 100644
--- a/src/ats/test_ats_api_update_address.c
+++ b/src/ats/test_ats_api_update_address.c
@@ -121,8 +121,7 @@ suggest_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
121 const char *plugin_name, const void *plugin_addr, 121 const char *plugin_name, const void *plugin_addr,
122 size_t plugin_addr_len, struct Session *session, 122 size_t plugin_addr_len, struct Session *session,
123 struct GNUNET_BANDWIDTH_Value32NBO bandwidth, 123 struct GNUNET_BANDWIDTH_Value32NBO bandwidth,
124 const struct GNUNET_ATS_Information *ats, 124 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
125 uint32_t ats_count)
126{ 125{
127 struct ExpectedValues *ex = cls; 126 struct ExpectedValues *ex = cls;
128 127
diff --git a/src/block/block.c b/src/block/block.c
index 582c13eb3..7c447f072 100644
--- a/src/block/block.c
+++ b/src/block/block.c
@@ -96,17 +96,14 @@ GNUNET_BLOCK_mingle_hash (const GNUNET_HashCode * in, uint32_t mingle_number,
96 * @param lib_ret the plugin API 96 * @param lib_ret the plugin API
97 */ 97 */
98static void 98static void
99add_plugin (void *cls, 99add_plugin (void *cls, const char *library_name, void *lib_ret)
100 const char *library_name,
101 void *lib_ret)
102{ 100{
103 struct GNUNET_BLOCK_Context *ctx = cls; 101 struct GNUNET_BLOCK_Context *ctx = cls;
104 struct GNUNET_BLOCK_PluginFunctions *api = lib_ret; 102 struct GNUNET_BLOCK_PluginFunctions *api = lib_ret;
105 struct Plugin *plugin; 103 struct Plugin *plugin;
106 104
107 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 105 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading block plugin `%s'\n"),
108 _("Loading block plugin `%s'\n"), 106 library_name);
109 library_name);
110 plugin = GNUNET_malloc (sizeof (struct Plugin)); 107 plugin = GNUNET_malloc (sizeof (struct Plugin));
111 plugin->api = api; 108 plugin->api = api;
112 plugin->library_name = GNUNET_strdup (library_name); 109 plugin->library_name = GNUNET_strdup (library_name);
@@ -128,10 +125,7 @@ GNUNET_BLOCK_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg)
128 125
129 ctx = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_Context)); 126 ctx = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_Context));
130 ctx->cfg = cfg; 127 ctx->cfg = cfg;
131 GNUNET_PLUGIN_load_all ("libgnunet_plugin_block_", 128 GNUNET_PLUGIN_load_all ("libgnunet_plugin_block_", NULL, &add_plugin, ctx);
132 NULL,
133 &add_plugin,
134 ctx);
135 return ctx; 129 return ctx;
136} 130}
137 131
@@ -147,7 +141,7 @@ GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx)
147 unsigned int i; 141 unsigned int i;
148 struct Plugin *plugin; 142 struct Plugin *plugin;
149 143
150 for (i = 0; i<ctx->num_plugins;i++) 144 for (i = 0; i < ctx->num_plugins; i++)
151 { 145 {
152 plugin = ctx->plugins[i]; 146 plugin = ctx->plugins[i];
153 GNUNET_break (NULL == 147 GNUNET_break (NULL ==
@@ -174,7 +168,7 @@ find_plugin (struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type)
174 unsigned int i; 168 unsigned int i;
175 unsigned int j; 169 unsigned int j;
176 170
177 for (i=0;i<ctx->num_plugins;i++) 171 for (i = 0; i < ctx->num_plugins; i++)
178 { 172 {
179 plugin = ctx->plugins[i]; 173 plugin = ctx->plugins[i];
180 j = 0; 174 j = 0;
@@ -291,8 +285,8 @@ compute_bloomfilter_size (unsigned int entry_count)
291 */ 285 */
292struct GNUNET_CONTAINER_BloomFilter * 286struct GNUNET_CONTAINER_BloomFilter *
293GNUNET_BLOCK_construct_bloomfilter (int32_t bf_mutator, 287GNUNET_BLOCK_construct_bloomfilter (int32_t bf_mutator,
294 const GNUNET_HashCode *seen_results, 288 const GNUNET_HashCode * seen_results,
295 unsigned int seen_results_count) 289 unsigned int seen_results_count)
296{ 290{
297 struct GNUNET_CONTAINER_BloomFilter *bf; 291 struct GNUNET_CONTAINER_BloomFilter *bf;
298 GNUNET_HashCode mhash; 292 GNUNET_HashCode mhash;
@@ -300,7 +294,8 @@ GNUNET_BLOCK_construct_bloomfilter (int32_t bf_mutator,
300 size_t nsize; 294 size_t nsize;
301 295
302 nsize = compute_bloomfilter_size (seen_results_count); 296 nsize = compute_bloomfilter_size (seen_results_count);
303 bf = GNUNET_CONTAINER_bloomfilter_init (NULL, nsize, GNUNET_CONSTANTS_BLOOMFILTER_K); 297 bf = GNUNET_CONTAINER_bloomfilter_init (NULL, nsize,
298 GNUNET_CONSTANTS_BLOOMFILTER_K);
304 for (i = 0; i < seen_results_count; i++) 299 for (i = 0; i < seen_results_count; i++)
305 { 300 {
306 GNUNET_BLOCK_mingle_hash (&seen_results[i], bf_mutator, &mhash); 301 GNUNET_BLOCK_mingle_hash (&seen_results[i], bf_mutator, &mhash);
diff --git a/src/block/plugin_block_dht.c b/src/block/plugin_block_dht.c
index c58615b72..f574e6d06 100644
--- a/src/block/plugin_block_dht.c
+++ b/src/block/plugin_block_dht.c
@@ -77,19 +77,21 @@ block_plugin_dht_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
77 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) 77 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid))
78 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 78 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
79 if (NULL != bf) 79 if (NULL != bf)
80 {
81 GNUNET_BLOCK_mingle_hash (&pid.hashPubKey, bf_mutator, &mhash);
82 if (NULL != *bf)
83 {
84 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
85 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
86 }
87 else
80 { 88 {
81 GNUNET_BLOCK_mingle_hash (&pid.hashPubKey, bf_mutator, &mhash); 89 *bf =
82 if (NULL != *bf) 90 GNUNET_CONTAINER_bloomfilter_init (NULL, 8,
83 { 91 GNUNET_CONSTANTS_BLOOMFILTER_K);
84 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
85 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
86 }
87 else
88 {
89 *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, GNUNET_CONSTANTS_BLOOMFILTER_K);
90 }
91 GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
92 } 92 }
93 GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
94 }
93 return GNUNET_BLOCK_EVALUATION_OK_MORE; 95 return GNUNET_BLOCK_EVALUATION_OK_MORE;
94} 96}
95 97
diff --git a/src/block/plugin_block_dns.c b/src/block/plugin_block_dns.c
index 8e8aa3047..b33b3798a 100644
--- a/src/block/plugin_block_dns.c
+++ b/src/block/plugin_block_dns.c
@@ -86,7 +86,8 @@ block_plugin_dns_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
86 } 86 }
87 87
88 if (GNUNET_TIME_relative_get_zero ().rel_value == 88 if (GNUNET_TIME_relative_get_zero ().rel_value ==
89 GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (rec->expiration_time)).rel_value) 89 GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh
90 (rec->expiration_time)).rel_value)
90 { 91 {
91 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DNS-Block is invalid: Timeout\n"); 92 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DNS-Block is invalid: Timeout\n");
92 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 93 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
diff --git a/src/block/plugin_block_fs.c b/src/block/plugin_block_fs.c
index 5a0e90a92..c1b4ad7c8 100644
--- a/src/block/plugin_block_fs.c
+++ b/src/block/plugin_block_fs.c
@@ -91,20 +91,20 @@ block_plugin_fs_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
91 if (reply_block == NULL) 91 if (reply_block == NULL)
92 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 92 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
93 if (NULL != bf) 93 if (NULL != bf)
94 {
95 GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash);
96 GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash);
97 if (NULL != *bf)
98 {
99 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
100 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
101 }
102 else
94 { 103 {
95 GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash); 104 *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K);
96 GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash);
97 if (NULL != *bf)
98 {
99 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
100 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
101 }
102 else
103 {
104 *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K);
105 }
106 GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
107 } 105 }
106 GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
107 }
108 return GNUNET_BLOCK_EVALUATION_OK_MORE; 108 return GNUNET_BLOCK_EVALUATION_OK_MORE;
109 case GNUNET_BLOCK_TYPE_FS_SBLOCK: 109 case GNUNET_BLOCK_TYPE_FS_SBLOCK:
110 if (xquery_size != sizeof (GNUNET_HashCode)) 110 if (xquery_size != sizeof (GNUNET_HashCode))
@@ -132,20 +132,20 @@ block_plugin_fs_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
132 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 132 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
133 } 133 }
134 if (NULL != bf) 134 if (NULL != bf)
135 {
136 GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash);
137 GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash);
138 if (NULL != *bf)
139 {
140 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
141 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
142 }
143 else
135 { 144 {
136 GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash); 145 *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K);
137 GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash);
138 if (NULL != *bf)
139 {
140 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
141 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
142 }
143 else
144 {
145 *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K);
146 }
147 GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
148 } 146 }
147 GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
148 }
149 return GNUNET_BLOCK_EVALUATION_OK_MORE; 149 return GNUNET_BLOCK_EVALUATION_OK_MORE;
150 default: 150 default:
151 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; 151 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
diff --git a/src/block/plugin_block_test.c b/src/block/plugin_block_test.c
index 0c769b837..08d3096dc 100644
--- a/src/block/plugin_block_test.c
+++ b/src/block/plugin_block_test.c
@@ -75,14 +75,14 @@ block_plugin_test_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
75 GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash); 75 GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash);
76 GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash); 76 GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash);
77 if (NULL != *bf) 77 if (NULL != *bf)
78 { 78 {
79 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash)) 79 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
80 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; 80 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
81 } 81 }
82 else 82 else
83 { 83 {
84 *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K); 84 *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K);
85 } 85 }
86 GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash); 86 GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
87 } 87 }
88 return GNUNET_BLOCK_EVALUATION_OK_MORE; 88 return GNUNET_BLOCK_EVALUATION_OK_MORE;
diff --git a/src/chat/gnunet-service-chat.c b/src/chat/gnunet-service-chat.c
index a3637e454..fb127b2f0 100644
--- a/src/chat/gnunet-service-chat.c
+++ b/src/chat/gnunet-service-chat.c
@@ -989,9 +989,8 @@ static int
989handle_p2p_join_notification (void *cls, 989handle_p2p_join_notification (void *cls,
990 const struct GNUNET_PeerIdentity *other, 990 const struct GNUNET_PeerIdentity *other,
991 const struct GNUNET_MessageHeader *message, 991 const struct GNUNET_MessageHeader *message,
992 const struct GNUNET_ATS_Information 992 const struct GNUNET_ATS_Information *atsi,
993 *atsi, 993 unsigned int atsi_count)
994 unsigned int atsi_count)
995{ 994{
996 const struct P2PJoinNotificationMessage *p2p_jnmsg; 995 const struct P2PJoinNotificationMessage *p2p_jnmsg;
997 char *room_name; 996 char *room_name;
@@ -1107,9 +1106,8 @@ static int
1107handle_p2p_leave_notification (void *cls, 1106handle_p2p_leave_notification (void *cls,
1108 const struct GNUNET_PeerIdentity *other, 1107 const struct GNUNET_PeerIdentity *other,
1109 const struct GNUNET_MessageHeader *message, 1108 const struct GNUNET_MessageHeader *message,
1110 const struct GNUNET_ATS_Information 1109 const struct GNUNET_ATS_Information *atsi,
1111 *atsi, 1110 unsigned int atsi_count)
1112 unsigned int atsi_count)
1113{ 1111{
1114 const struct P2PLeaveNotificationMessage *p2p_lnmsg; 1112 const struct P2PLeaveNotificationMessage *p2p_lnmsg;
1115 GNUNET_HashCode id; 1113 GNUNET_HashCode id;
@@ -1190,9 +1188,8 @@ static int
1190handle_p2p_message_notification (void *cls, 1188handle_p2p_message_notification (void *cls,
1191 const struct GNUNET_PeerIdentity *other, 1189 const struct GNUNET_PeerIdentity *other,
1192 const struct GNUNET_MessageHeader *message, 1190 const struct GNUNET_MessageHeader *message,
1193 const struct GNUNET_ATS_Information 1191 const struct GNUNET_ATS_Information *atsi,
1194 *atsi, 1192 unsigned int atsi_count)
1195 unsigned int atsi_count)
1196{ 1193{
1197 const struct P2PReceiveNotificationMessage *p2p_rnmsg; 1194 const struct P2PReceiveNotificationMessage *p2p_rnmsg;
1198 struct P2PReceiveNotificationMessage *my_p2p_rnmsg; 1195 struct P2PReceiveNotificationMessage *my_p2p_rnmsg;
@@ -1343,7 +1340,7 @@ static int
1343handle_p2p_sync_request (void *cls, const struct GNUNET_PeerIdentity *other, 1340handle_p2p_sync_request (void *cls, const struct GNUNET_PeerIdentity *other,
1344 const struct GNUNET_MessageHeader *message, 1341 const struct GNUNET_MessageHeader *message,
1345 const struct GNUNET_ATS_Information *atsi, 1342 const struct GNUNET_ATS_Information *atsi,
1346 unsigned int atsi_count) 1343 unsigned int atsi_count)
1347{ 1344{
1348 struct ChatClient *entry; 1345 struct ChatClient *entry;
1349 struct GNUNET_CORE_TransmitHandle *th; 1346 struct GNUNET_CORE_TransmitHandle *th;
@@ -1386,9 +1383,8 @@ static int
1386handle_p2p_confirmation_receipt (void *cls, 1383handle_p2p_confirmation_receipt (void *cls,
1387 const struct GNUNET_PeerIdentity *other, 1384 const struct GNUNET_PeerIdentity *other,
1388 const struct GNUNET_MessageHeader *message, 1385 const struct GNUNET_MessageHeader *message,
1389 const struct GNUNET_ATS_Information 1386 const struct GNUNET_ATS_Information *atsi,
1390 *atsi, 1387 unsigned int atsi_count)
1391 unsigned int atsi_count)
1392{ 1388{
1393 const struct P2PConfirmationReceiptMessage *p2p_crmsg; 1389 const struct P2PConfirmationReceiptMessage *p2p_crmsg;
1394 struct P2PConfirmationReceiptMessage *my_p2p_crmsg; 1390 struct P2PConfirmationReceiptMessage *my_p2p_crmsg;
@@ -1530,7 +1526,7 @@ transmit_sync_request_to_peer (void *cls, size_t size, void *buf)
1530static void 1526static void
1531peer_connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer, 1527peer_connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
1532 const struct GNUNET_ATS_Information *atsi, 1528 const struct GNUNET_ATS_Information *atsi,
1533 unsigned int atsi_count) 1529 unsigned int atsi_count)
1534{ 1530{
1535 struct ConnectedPeer *cp; 1531 struct ConnectedPeer *cp;
1536 struct GNUNET_CORE_TransmitHandle *th; 1532 struct GNUNET_CORE_TransmitHandle *th;
@@ -1716,8 +1712,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1716 core = 1712 core =
1717 GNUNET_CORE_connect (cfg, QUEUE_SIZE, NULL, &core_init, 1713 GNUNET_CORE_connect (cfg, QUEUE_SIZE, NULL, &core_init,
1718 &peer_connect_handler, &peer_disconnect_handler, 1714 &peer_connect_handler, &peer_disconnect_handler,
1719 NULL, GNUNET_NO, NULL, GNUNET_NO, 1715 NULL, GNUNET_NO, NULL, GNUNET_NO, p2p_handlers);
1720 p2p_handlers);
1721 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); 1716 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
1722 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, 1717 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
1723 NULL); 1718 NULL);
diff --git a/src/core/core_api.c b/src/core/core_api.c
index 57c2932a2..f3f4cea54 100644
--- a/src/core/core_api.c
+++ b/src/core/core_api.c
@@ -781,7 +781,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
781 const struct GNUNET_MessageHeader *em; 781 const struct GNUNET_MessageHeader *em;
782 const struct SendMessageReady *smr; 782 const struct SendMessageReady *smr;
783 const struct GNUNET_CORE_MessageHandler *mh; 783 const struct GNUNET_CORE_MessageHandler *mh;
784 const struct GNUNET_ATS_Information* ats; 784 const struct GNUNET_ATS_Information *ats;
785 GNUNET_CORE_StartupCallback init; 785 GNUNET_CORE_StartupCallback init;
786 struct PeerRecord *pr; 786 struct PeerRecord *pr;
787 struct GNUNET_CORE_TransmitHandle *th; 787 struct GNUNET_CORE_TransmitHandle *th;
@@ -864,8 +864,8 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
864 cnm = (const struct ConnectNotifyMessage *) msg; 864 cnm = (const struct ConnectNotifyMessage *) msg;
865 ats_count = ntohl (cnm->ats_count); 865 ats_count = ntohl (cnm->ats_count);
866 if (msize != 866 if (msize !=
867 sizeof (struct ConnectNotifyMessage) + 867 sizeof (struct ConnectNotifyMessage) +
868 ats_count * sizeof (struct GNUNET_ATS_Information)) 868 ats_count * sizeof (struct GNUNET_ATS_Information))
869 { 869 {
870 GNUNET_break (0); 870 GNUNET_break (0);
871 reconnect_later (h); 871 reconnect_later (h);
@@ -896,11 +896,9 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
896 GNUNET_CONTAINER_multihashmap_put (h->peers, 896 GNUNET_CONTAINER_multihashmap_put (h->peers,
897 &cnm->peer.hashPubKey, pr, 897 &cnm->peer.hashPubKey, pr,
898 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); 898 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
899 ats = (const struct GNUNET_ATS_Information*) &cnm[1]; 899 ats = (const struct GNUNET_ATS_Information *) &cnm[1];
900 if (NULL != h->connects) 900 if (NULL != h->connects)
901 h->connects (h->cls, &cnm->peer, 901 h->connects (h->cls, &cnm->peer, ats, ats_count);
902 ats,
903 ats_count);
904 break; 902 break;
905 case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT: 903 case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT:
906 if (msize != sizeof (struct DisconnectNotifyMessage)) 904 if (msize != sizeof (struct DisconnectNotifyMessage))
@@ -949,8 +947,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
949 sizeof (struct NotifyTrafficMessage) + 947 sizeof (struct NotifyTrafficMessage) +
950 ats_count * sizeof (struct GNUNET_ATS_Information) + 948 ats_count * sizeof (struct GNUNET_ATS_Information) +
951 sizeof (struct GNUNET_MessageHeader)) || 949 sizeof (struct GNUNET_MessageHeader)) ||
952 (GNUNET_ATS_ARRAY_TERMINATOR != 950 (GNUNET_ATS_ARRAY_TERMINATOR != ntohl ((&ntm->ats)[ats_count].type)))
953 ntohl ((&ntm->ats)[ats_count].type)))
954 { 951 {
955 GNUNET_break (0); 952 GNUNET_break (0);
956 reconnect_later (h); 953 reconnect_later (h);
@@ -986,23 +983,22 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
986 continue; 983 continue;
987 if ((mh->expected_size != ntohs (em->size)) && (mh->expected_size != 0)) 984 if ((mh->expected_size != ntohs (em->size)) && (mh->expected_size != 0))
988 { 985 {
989 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 986 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
990 "Unexpected message size for message of type %u\n", 987 "Unexpected message size for message of type %u\n",
991 mh->type); 988 mh->type);
992 GNUNET_break_op (0); 989 GNUNET_break_op (0);
993 continue; 990 continue;
994 } 991 }
995 if (GNUNET_OK != 992 if (GNUNET_OK !=
996 h->handlers[hpos].callback (h->cls, &ntm->peer, em, &ntm->ats, 993 h->handlers[hpos].callback (h->cls, &ntm->peer, em, &ntm->ats,
997 ats_count)) 994 ats_count))
998 { 995 {
999 /* error in processing, do not process other messages! */ 996 /* error in processing, do not process other messages! */
1000 break; 997 break;
1001 } 998 }
1002 } 999 }
1003 if (NULL != h->inbound_notify) 1000 if (NULL != h->inbound_notify)
1004 h->inbound_notify (h->cls, &ntm->peer, em, &ntm->ats, 1001 h->inbound_notify (h->cls, &ntm->peer, em, &ntm->ats, ats_count);
1005 ats_count);
1006 break; 1002 break;
1007 case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND: 1003 case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND:
1008 if (msize < sizeof (struct NotifyTrafficMessage)) 1004 if (msize < sizeof (struct NotifyTrafficMessage))
@@ -1023,8 +1019,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
1023 sizeof (struct NotifyTrafficMessage) + 1019 sizeof (struct NotifyTrafficMessage) +
1024 ats_count * sizeof (struct GNUNET_ATS_Information) + 1020 ats_count * sizeof (struct GNUNET_ATS_Information) +
1025 sizeof (struct GNUNET_MessageHeader)) || 1021 sizeof (struct GNUNET_MessageHeader)) ||
1026 (GNUNET_ATS_ARRAY_TERMINATOR != 1022 (GNUNET_ATS_ARRAY_TERMINATOR != ntohl ((&ntm->ats)[ats_count].type)))
1027 ntohl ((&ntm->ats)[ats_count].type)))
1028 { 1023 {
1029 GNUNET_break (0); 1024 GNUNET_break (0);
1030 reconnect_later (h); 1025 reconnect_later (h);
diff --git a/src/core/core_api_iterate_peers.c b/src/core/core_api_iterate_peers.c
index 7bf40a678..7b28842fd 100644
--- a/src/core/core_api_iterate_peers.c
+++ b/src/core/core_api_iterate_peers.c
@@ -101,7 +101,7 @@ receive_info (void *cls, const struct GNUNET_MessageHeader *msg)
101 ats_count = ntohl (connect_message->ats_count); 101 ats_count = ntohl (connect_message->ats_count);
102 if (msize != 102 if (msize !=
103 sizeof (struct ConnectNotifyMessage) + 103 sizeof (struct ConnectNotifyMessage) +
104 ats_count * sizeof (struct GNUNET_ATS_Information)) 104 ats_count * sizeof (struct GNUNET_ATS_Information))
105 { 105 {
106 GNUNET_break (0); 106 GNUNET_break (0);
107 if (request_context->peer_cb != NULL) 107 if (request_context->peer_cb != NULL)
@@ -113,8 +113,8 @@ receive_info (void *cls, const struct GNUNET_MessageHeader *msg)
113 /* Normal case */ 113 /* Normal case */
114 if (request_context->peer_cb != NULL) 114 if (request_context->peer_cb != NULL)
115 request_context->peer_cb (request_context->cb_cls, &connect_message->peer, 115 request_context->peer_cb (request_context->cb_cls, &connect_message->peer,
116 (const struct GNUNET_ATS_Information *) &connect_message[1], 116 (const struct GNUNET_ATS_Information *)
117 ats_count); 117 &connect_message[1], ats_count);
118 GNUNET_CLIENT_receive (request_context->client, &receive_info, 118 GNUNET_CLIENT_receive (request_context->client, &receive_info,
119 request_context, GNUNET_TIME_UNIT_FOREVER_REL); 119 request_context, GNUNET_TIME_UNIT_FOREVER_REL);
120} 120}
diff --git a/src/core/gnunet-core-list-connections.c b/src/core/gnunet-core-list-connections.c
index 9665110a3..79490bcc5 100644
--- a/src/core/gnunet-core-list-connections.c
+++ b/src/core/gnunet-core-list-connections.c
@@ -124,7 +124,7 @@ process_resolved_address (void *cls, const char *address)
124static void 124static void
125connected_peer_callback (void *cls, const struct GNUNET_PeerIdentity *peer, 125connected_peer_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
126 const struct GNUNET_ATS_Information *atsi, 126 const struct GNUNET_ATS_Information *atsi,
127 unsigned int atsi_count) 127 unsigned int atsi_count)
128{ 128{
129 struct PrintContext *pc; 129 struct PrintContext *pc;
130 130
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c
index 5bec671ec..2eb71c257 100644
--- a/src/core/gnunet-service-core.c
+++ b/src/core/gnunet-service-core.c
@@ -57,8 +57,7 @@ static void
57cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 57cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
58{ 58{
59#if DEBUG_CORE 59#if DEBUG_CORE
60 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 60 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service shutting down.\n");
61 "Core service shutting down.\n");
62#endif 61#endif
63 GSC_CLIENTS_done (); 62 GSC_CLIENTS_done ();
64 GSC_NEIGHBOURS_done (); 63 GSC_NEIGHBOURS_done ();
@@ -85,13 +84,12 @@ static void
85run (void *cls, struct GNUNET_SERVER_Handle *server, 84run (void *cls, struct GNUNET_SERVER_Handle *server,
86 const struct GNUNET_CONFIGURATION_Handle *c) 85 const struct GNUNET_CONFIGURATION_Handle *c)
87{ 86{
88 GSC_cfg = c; 87 GSC_cfg = c;
89 GSC_stats = GNUNET_STATISTICS_create ("core", GSC_cfg); 88 GSC_stats = GNUNET_STATISTICS_create ("core", GSC_cfg);
90 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task, 89 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task,
91 NULL); 90 NULL);
92 GSC_TYPEMAP_init (); 91 GSC_TYPEMAP_init ();
93 if ( (GNUNET_OK != GSC_KX_init ()) || 92 if ((GNUNET_OK != GSC_KX_init ()) || (GNUNET_OK != GSC_NEIGHBOURS_init ()))
94 (GNUNET_OK != GSC_NEIGHBOURS_init ()) )
95 { 93 {
96 GNUNET_SCHEDULER_shutdown (); 94 GNUNET_SCHEDULER_shutdown ();
97 return; 95 return;
diff --git a/src/core/gnunet-service-core.h b/src/core/gnunet-service-core.h
index d4e43a457..e48ad8bad 100644
--- a/src/core/gnunet-service-core.h
+++ b/src/core/gnunet-service-core.h
@@ -37,7 +37,7 @@ struct GSC_Client;
37 37
38/** 38/**
39 * Record kept for each request for transmission issued by a 39 * Record kept for each request for transmission issued by a
40 * client that is still pending. (This struct is used by 40 * client that is still pending. (This struct is used by
41 * both the 'CLIENTS' and 'SESSIONS' subsystems.) 41 * both the 'CLIENTS' and 'SESSIONS' subsystems.)
42 */ 42 */
43struct GSC_ClientActiveRequest 43struct GSC_ClientActiveRequest
diff --git a/src/core/gnunet-service-core_clients.c b/src/core/gnunet-service-core_clients.c
index 22201514a..3201b71f0 100644
--- a/src/core/gnunet-service-core_clients.c
+++ b/src/core/gnunet-service-core_clients.c
@@ -146,9 +146,8 @@ find_client (struct GNUNET_SERVER_Client *client)
146 * client's queue is getting too large? 146 * client's queue is getting too large?
147 */ 147 */
148static void 148static void
149send_to_client (struct GSC_Client *client, 149send_to_client (struct GSC_Client *client,
150 const struct GNUNET_MessageHeader *msg, 150 const struct GNUNET_MessageHeader *msg, int can_drop)
151 int can_drop)
152{ 151{
153#if DEBUG_CORE 152#if DEBUG_CORE
154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -171,8 +170,8 @@ send_to_client (struct GSC_Client *client,
171 */ 170 */
172void 171void
173GSC_CLIENTS_send_to_client (struct GNUNET_SERVER_Client *client, 172GSC_CLIENTS_send_to_client (struct GNUNET_SERVER_Client *client,
174 const struct GNUNET_MessageHeader *msg, 173 const struct GNUNET_MessageHeader *msg,
175 int can_drop) 174 int can_drop)
176{ 175{
177 struct GSC_Client *c; 176 struct GSC_Client *c;
178 177
@@ -194,14 +193,13 @@ GSC_CLIENTS_send_to_client (struct GNUNET_SERVER_Client *client,
194 * @return GNUNET_YES if 'c' is interested, GNUNET_NO if not. 193 * @return GNUNET_YES if 'c' is interested, GNUNET_NO if not.
195 */ 194 */
196static int 195static int
197type_match (uint16_t type, 196type_match (uint16_t type, struct GSC_Client *c)
198 struct GSC_Client *c)
199{ 197{
200 unsigned int i; 198 unsigned int i;
201 199
202 if (c->tcnt == 0) 200 if (c->tcnt == 0)
203 return GNUNET_YES; /* peer without handlers matches ALL */ 201 return GNUNET_YES; /* peer without handlers matches ALL */
204 for (i=0;i<c->tcnt;i++) 202 for (i = 0; i < c->tcnt; i++)
205 if (type == c->types[i]) 203 if (type == c->types[i])
206 return GNUNET_YES; 204 return GNUNET_YES;
207 return GNUNET_NO; 205 return GNUNET_NO;
@@ -219,30 +217,27 @@ type_match (uint16_t type,
219 */ 217 */
220static void 218static void
221send_to_all_clients (const struct GNUNET_PeerIdentity *sender, 219send_to_all_clients (const struct GNUNET_PeerIdentity *sender,
222 const struct GNUNET_MessageHeader *msg, 220 const struct GNUNET_MessageHeader *msg, int can_drop,
223 int can_drop, 221 int options, uint16_t type)
224 int options,
225 uint16_t type)
226{ 222{
227 struct GSC_Client *c; 223 struct GSC_Client *c;
228 224
229 for (c = client_head; c != NULL; c = c->next) 225 for (c = client_head; c != NULL; c = c->next)
230 { 226 {
231 if ( (0 == (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) && 227 if ((0 == (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) &&
232 (GNUNET_YES == type_match (type, c)) ) 228 (GNUNET_YES == type_match (type, c)))
233 continue; /* not the full message, but we'd like the full one! */ 229 continue; /* not the full message, but we'd like the full one! */
234 if ( (0 == (c->options & options)) && 230 if ((0 == (c->options & options)) && (GNUNET_YES != type_match (type, c)))
235 (GNUNET_YES != type_match (type, c)) ) 231 continue; /* neither options nor type match permit the message */
236 continue; /* neither options nor type match permit the message */
237#if DEBUG_CORE 232#if DEBUG_CORE
238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
239 "Sending message to client interested in messages of type %u.\n", 234 "Sending message to client interested in messages of type %u.\n",
240 (unsigned int) type); 235 (unsigned int) type);
241#endif 236#endif
242#if DEBUG_CONNECTS 237#if DEBUG_CONNECTS
243 GNUNET_assert (GNUNET_YES == 238 GNUNET_assert (GNUNET_YES ==
244 GNUNET_CONTAINER_multihashmap_contains (c->connectmap, 239 GNUNET_CONTAINER_multihashmap_contains (c->connectmap,
245 &sender->hashPubKey)); 240 &sender->hashPubKey));
246#endif 241#endif
247 send_to_client (c, msg, can_drop); 242 send_to_client (c, msg, can_drop);
248 } 243 }
@@ -295,22 +290,20 @@ handle_client_init (void *cls, struct GNUNET_SERVER_Client *client,
295#if DEBUG_CONNECTS 290#if DEBUG_CONNECTS
296 c->connectmap = GNUNET_CONTAINER_multihashmap_create (16); 291 c->connectmap = GNUNET_CONTAINER_multihashmap_create (16);
297 GNUNET_assert (GNUNET_YES == 292 GNUNET_assert (GNUNET_YES ==
298 GNUNET_CONTAINER_multihashmap_put (c->connectmap, 293 GNUNET_CONTAINER_multihashmap_put (c->connectmap,
299 &GSC_my_identity.hashPubKey, 294 &GSC_my_identity.hashPubKey,
300 NULL, 295 NULL,
301 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 296 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
302#endif 297#endif
303 298
304 wtypes = (uint16_t *) & c[1]; 299 wtypes = (uint16_t *) & c[1];
305 for (i = 0; i < c->tcnt; i++) 300 for (i = 0; i < c->tcnt; i++)
306 wtypes[i] = ntohs (types[i]); 301 wtypes[i] = ntohs (types[i]);
307 GSC_TYPEMAP_add (wtypes, c->tcnt); 302 GSC_TYPEMAP_add (wtypes, c->tcnt);
308 GNUNET_CONTAINER_DLL_insert (client_head, 303 GNUNET_CONTAINER_DLL_insert (client_head, client_tail, c);
309 client_tail,
310 c);
311#if DEBUG_CORE 304#if DEBUG_CORE
312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
313 "Client connecting to core service is interested in %u message types\n", 306 "Client connecting to core service is interested in %u message types\n",
314 (unsigned int) c->tcnt); 307 (unsigned int) c->tcnt);
315#endif 308#endif
316 /* send init reply message */ 309 /* send init reply message */
@@ -352,8 +345,8 @@ handle_client_send_request (void *cls, struct GNUNET_SERVER_Client *client,
352 c->requests = GNUNET_CONTAINER_multihashmap_create (16); 345 c->requests = GNUNET_CONTAINER_multihashmap_create (16);
353#if DEBUG_CORE 346#if DEBUG_CORE
354 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 347 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
355 "Client asked for transmission to `%s'\n", 348 "Client asked for transmission to `%s'\n",
356 GNUNET_i2s (&req->peer)); 349 GNUNET_i2s (&req->peer));
357#endif 350#endif
358 car = GNUNET_CONTAINER_multihashmap_get (c->requests, &req->peer.hashPubKey); 351 car = GNUNET_CONTAINER_multihashmap_get (c->requests, &req->peer.hashPubKey);
359 if (car == NULL) 352 if (car == NULL)
@@ -378,7 +371,8 @@ handle_client_send_request (void *cls, struct GNUNET_SERVER_Client *client,
378 car->smr_id = req->smr_id; 371 car->smr_id = req->smr_id;
379 car->was_solicited = GNUNET_NO; 372 car->was_solicited = GNUNET_NO;
380 if (0 == 373 if (0 ==
381 memcmp (&req->peer, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity))) 374 memcmp (&req->peer, &GSC_my_identity,
375 sizeof (struct GNUNET_PeerIdentity)))
382 GSC_CLIENTS_solicit_request (car); 376 GSC_CLIENTS_solicit_request (car);
383 else 377 else
384 GSC_SESSIONS_queue_request (car); 378 GSC_SESSIONS_queue_request (car);
@@ -394,7 +388,7 @@ struct TokenizerContext
394 388
395 /** 389 /**
396 * Active request handle for the message. 390 * Active request handle for the message.
397 */ 391 */
398 struct GSC_ClientActiveRequest *car; 392 struct GSC_ClientActiveRequest *car;
399 393
400 /** 394 /**
@@ -440,42 +434,39 @@ handle_client_send (void *cls, struct GNUNET_SERVER_Client *client,
440 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 434 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
441 return; 435 return;
442 } 436 }
443 tc.car = GNUNET_CONTAINER_multihashmap_get (c->requests, &sm->peer.hashPubKey); 437 tc.car =
438 GNUNET_CONTAINER_multihashmap_get (c->requests, &sm->peer.hashPubKey);
444 if (NULL == tc.car) 439 if (NULL == tc.car)
445 { 440 {
446 /* Must have been that we first approved the request, then got disconnected 441 /* Must have been that we first approved the request, then got disconnected
447 (which triggered removal of the 'car') and now the client gives us a message 442 * (which triggered removal of the 'car') and now the client gives us a message
448 just *before* the client learns about the disconnect. Theoretically, we 443 * just *before* the client learns about the disconnect. Theoretically, we
449 might also now be *again* connected. So this can happen (but should be 444 * might also now be *again* connected. So this can happen (but should be
450 rare). If it does happen, the message is discarded. */ 445 * rare). If it does happen, the message is discarded. */
451 GNUNET_STATISTICS_update (GSC_stats, 446 GNUNET_STATISTICS_update (GSC_stats,
452 gettext_noop ("# messages discarded (session disconnected)"), 447 gettext_noop
453 1, 448 ("# messages discarded (session disconnected)"),
454 GNUNET_NO); 449 1, GNUNET_NO);
455 GNUNET_SERVER_receive_done (client, GNUNET_OK); 450 GNUNET_SERVER_receive_done (client, GNUNET_OK);
456 return; 451 return;
457 } 452 }
458 GNUNET_assert (GNUNET_YES == 453 GNUNET_assert (GNUNET_YES ==
459 GNUNET_CONTAINER_multihashmap_remove (c->requests, 454 GNUNET_CONTAINER_multihashmap_remove (c->requests,
460 &sm->peer.hashPubKey, 455 &sm->peer.hashPubKey,
461 tc.car)); 456 tc.car));
462 tc.cork = ntohl (sm->cork); 457 tc.cork = ntohl (sm->cork);
463#if DEBUG_CORE 458#if DEBUG_CORE
464 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 459 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
465 "Client asked for transmission of %u bytes to `%s' %s\n", 460 "Client asked for transmission of %u bytes to `%s' %s\n", msize,
466 msize, 461 GNUNET_i2s (&sm->peer), tc.cork ? "now" : "");
467 GNUNET_i2s (&sm->peer),
468 tc.cork ? "now" : "");
469#endif 462#endif
470 GNUNET_SERVER_mst_receive (client_mst, 463 GNUNET_SERVER_mst_receive (client_mst, &tc, (const char *) &sm[1], msize,
471 &tc, 464 GNUNET_YES, GNUNET_NO);
472 (const char*) &sm[1], msize,
473 GNUNET_YES,
474 GNUNET_NO);
475 if (0 != 465 if (0 !=
476 memcmp (&tc.car->target, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity))) 466 memcmp (&tc.car->target, &GSC_my_identity,
467 sizeof (struct GNUNET_PeerIdentity)))
477 GSC_SESSIONS_dequeue_request (tc.car); 468 GSC_SESSIONS_dequeue_request (tc.car);
478 GNUNET_free (tc.car); 469 GNUNET_free (tc.car);
479 GNUNET_SERVER_receive_done (client, GNUNET_OK); 470 GNUNET_SERVER_receive_done (client, GNUNET_OK);
480} 471}
481 472
@@ -492,37 +483,35 @@ handle_client_send (void *cls, struct GNUNET_SERVER_Client *client,
492 */ 483 */
493static void 484static void
494client_tokenizer_callback (void *cls, void *client, 485client_tokenizer_callback (void *cls, void *client,
495 const struct GNUNET_MessageHeader *message) 486 const struct GNUNET_MessageHeader *message)
496{ 487{
497 struct TokenizerContext *tc = client; 488 struct TokenizerContext *tc = client;
498 struct GSC_ClientActiveRequest *car = tc->car; 489 struct GSC_ClientActiveRequest *car = tc->car;
499 490
500 if (0 == 491 if (0 ==
501 memcmp (&car->target, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity))) 492 memcmp (&car->target, &GSC_my_identity,
493 sizeof (struct GNUNET_PeerIdentity)))
502 { 494 {
503#if DEBUG_CORE 495#if DEBUG_CORE
504 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 496 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
505 "Delivering message of type %u to myself\n", 497 "Delivering message of type %u to myself\n",
506 ntohs (message->type)); 498 ntohs (message->type));
507#endif 499#endif
508 GSC_CLIENTS_deliver_message (&GSC_my_identity, 500 GSC_CLIENTS_deliver_message (&GSC_my_identity, NULL, 0, message,
509 NULL, 0, 501 ntohs (message->size),
510 message, 502 GNUNET_CORE_OPTION_SEND_FULL_INBOUND |
511 ntohs (message->size), 503 GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND);
512 GNUNET_CORE_OPTION_SEND_FULL_INBOUND | GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND); 504 GSC_CLIENTS_deliver_message (&GSC_my_identity, NULL, 0, message,
513 GSC_CLIENTS_deliver_message (&GSC_my_identity, 505 sizeof (struct GNUNET_MessageHeader),
514 NULL, 0, 506 GNUNET_CORE_OPTION_SEND_HDR_INBOUND |
515 message, 507 GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND);
516 sizeof (struct GNUNET_MessageHeader),
517 GNUNET_CORE_OPTION_SEND_HDR_INBOUND | GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND);
518 } 508 }
519 else 509 else
520 { 510 {
521#if DEBUG_CORE 511#if DEBUG_CORE
522 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 512 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
523 "Delivering message of type %u to %s\n", 513 "Delivering message of type %u to %s\n", ntohs (message->type),
524 ntohs (message->type), 514 GNUNET_i2s (&car->target));
525 GNUNET_i2s (&car->target));
526#endif 515#endif
527 GSC_SESSIONS_transmit (car, message, tc->cork); 516 GSC_SESSIONS_transmit (car, message, tc->cork);
528 } 517 }
@@ -544,9 +533,10 @@ destroy_active_client_request (void *cls, const GNUNET_HashCode * key,
544 struct GSC_ClientActiveRequest *car = value; 533 struct GSC_ClientActiveRequest *car = value;
545 534
546 GNUNET_assert (GNUNET_YES == 535 GNUNET_assert (GNUNET_YES ==
547 GNUNET_CONTAINER_multihashmap_remove (car->client_handle->requests, 536 GNUNET_CONTAINER_multihashmap_remove (car->
548 &car->target.hashPubKey, 537 client_handle->requests,
549 car)); 538 &car->target.hashPubKey,
539 car));
550 GSC_SESSIONS_dequeue_request (car); 540 GSC_SESSIONS_dequeue_request (car);
551 GNUNET_free (car); 541 GNUNET_free (car);
552 return GNUNET_YES; 542 return GNUNET_YES;
@@ -560,8 +550,7 @@ destroy_active_client_request (void *cls, const GNUNET_HashCode * key,
560 * @param client identification of the client 550 * @param client identification of the client
561 */ 551 */
562static void 552static void
563handle_client_disconnect (void *cls, 553handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
564 struct GNUNET_SERVER_Client *client)
565{ 554{
566 struct GSC_Client *c; 555 struct GSC_Client *c;
567 556
@@ -573,10 +562,8 @@ handle_client_disconnect (void *cls,
573#endif 562#endif
574 c = find_client (client); 563 c = find_client (client);
575 if (c == NULL) 564 if (c == NULL)
576 return; /* client never sent INIT */ 565 return; /* client never sent INIT */
577 GNUNET_CONTAINER_DLL_remove (client_head, 566 GNUNET_CONTAINER_DLL_remove (client_head, client_tail, c);
578 client_tail,
579 c);
580 if (c->requests != NULL) 567 if (c->requests != NULL)
581 { 568 {
582 GNUNET_CONTAINER_multihashmap_iterate (c->requests, 569 GNUNET_CONTAINER_multihashmap_iterate (c->requests,
@@ -613,8 +600,9 @@ GSC_CLIENTS_solicit_request (struct GSC_ClientActiveRequest *car)
613 smr.peer = car->target; 600 smr.peer = car->target;
614#if DEBUG_CONNECTS 601#if DEBUG_CONNECTS
615 GNUNET_assert (GNUNET_YES == 602 GNUNET_assert (GNUNET_YES ==
616 GNUNET_CONTAINER_multihashmap_contains (c->connectmap, 603 GNUNET_CONTAINER_multihashmap_contains (c->connectmap,
617 &car->target.hashPubKey)); 604 &car->
605 target.hashPubKey));
618#endif 606#endif
619 send_to_client (c, &smr.header, GNUNET_NO); 607 send_to_client (c, &smr.header, GNUNET_NO);
620} 608}
@@ -632,9 +620,10 @@ void
632GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car) 620GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car)
633{ 621{
634 GNUNET_assert (GNUNET_YES == 622 GNUNET_assert (GNUNET_YES ==
635 GNUNET_CONTAINER_multihashmap_remove (car->client_handle->requests, 623 GNUNET_CONTAINER_multihashmap_remove (car->
636 &car->target.hashPubKey, 624 client_handle->requests,
637 car)); 625 &car->target.hashPubKey,
626 car));
638 GNUNET_free (car); 627 GNUNET_free (car);
639} 628}
640 629
@@ -654,11 +643,12 @@ GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car)
654 */ 643 */
655void 644void
656GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client, 645GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
657 const struct GNUNET_PeerIdentity *neighbour, 646 const struct GNUNET_PeerIdentity
658 const struct GNUNET_ATS_Information *atsi, 647 *neighbour,
659 unsigned int atsi_count, 648 const struct GNUNET_ATS_Information
660 const struct GSC_TypeMap *tmap_old, 649 *atsi, unsigned int atsi_count,
661 const struct GSC_TypeMap *tmap_new) 650 const struct GSC_TypeMap *tmap_old,
651 const struct GSC_TypeMap *tmap_new)
662{ 652{
663 struct ConnectNotifyMessage *cnm; 653 struct ConnectNotifyMessage *cnm;
664 size_t size; 654 size_t size;
@@ -673,43 +663,41 @@ GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
673 if (old_match == new_match) 663 if (old_match == new_match)
674 { 664 {
675 GNUNET_assert (old_match == 665 GNUNET_assert (old_match ==
676 GNUNET_CONTAINER_multihashmap_contains (client->connectmap, 666 GNUNET_CONTAINER_multihashmap_contains (client->connectmap,
677 &neighbour->hashPubKey)); 667 &neighbour->hashPubKey));
678 return; /* no change */ 668 return; /* no change */
679 } 669 }
680 if (old_match == GNUNET_NO) 670 if (old_match == GNUNET_NO)
681 { 671 {
682 /* send connect */ 672 /* send connect */
683#if DEBUG_CONNECTS 673#if DEBUG_CONNECTS
684 GNUNET_assert (GNUNET_NO == 674 GNUNET_assert (GNUNET_NO ==
685 GNUNET_CONTAINER_multihashmap_contains (client->connectmap, 675 GNUNET_CONTAINER_multihashmap_contains (client->connectmap,
686 &neighbour->hashPubKey)); 676 &neighbour->hashPubKey));
687 GNUNET_assert (GNUNET_YES == 677 GNUNET_assert (GNUNET_YES ==
688 GNUNET_CONTAINER_multihashmap_put (client->connectmap, 678 GNUNET_CONTAINER_multihashmap_put (client->connectmap,
689 &neighbour->hashPubKey, 679 &neighbour->hashPubKey,
690 NULL, 680 NULL,
691 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 681 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
692#endif 682#endif
693 size = 683 size =
694 sizeof (struct ConnectNotifyMessage) + 684 sizeof (struct ConnectNotifyMessage) +
695 (atsi_count) * sizeof (struct GNUNET_ATS_Information); 685 (atsi_count) * sizeof (struct GNUNET_ATS_Information);
696 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 686 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
697 { 687 {
698 GNUNET_break (0); 688 GNUNET_break (0);
699 /* recovery strategy: throw away performance data */ 689 /* recovery strategy: throw away performance data */
700 atsi_count = 0; 690 atsi_count = 0;
701 size = sizeof (struct ConnectNotifyMessage); 691 size = sizeof (struct ConnectNotifyMessage);
702 } 692 }
703 cnm = (struct ConnectNotifyMessage *) buf; 693 cnm = (struct ConnectNotifyMessage *) buf;
704 cnm->header.size = htons (size); 694 cnm->header.size = htons (size);
705 cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); 695 cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
706 cnm->ats_count = htonl (atsi_count); 696 cnm->ats_count = htonl (atsi_count);
707 a = (struct GNUNET_ATS_Information* ) &cnm[1]; 697 a = (struct GNUNET_ATS_Information *) &cnm[1];
708 memcpy (a, atsi, 698 memcpy (a, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
709 sizeof (struct GNUNET_ATS_Information) * atsi_count);
710#if DEBUG_CORE 699#if DEBUG_CORE
711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 700 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message to client.\n",
712 "Sending `%s' message to client.\n",
713 "NOTIFY_CONNECT"); 701 "NOTIFY_CONNECT");
714#endif 702#endif
715 cnm->peer = *neighbour; 703 cnm->peer = *neighbour;
@@ -720,12 +708,12 @@ GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
720 /* send disconnect */ 708 /* send disconnect */
721#if DEBUG_CONNECTS 709#if DEBUG_CONNECTS
722 GNUNET_assert (GNUNET_YES == 710 GNUNET_assert (GNUNET_YES ==
723 GNUNET_CONTAINER_multihashmap_contains (client->connectmap, 711 GNUNET_CONTAINER_multihashmap_contains (client->connectmap,
724 &neighbour->hashPubKey)); 712 &neighbour->hashPubKey));
725 GNUNET_assert (GNUNET_YES == 713 GNUNET_assert (GNUNET_YES ==
726 GNUNET_CONTAINER_multihashmap_remove (client->connectmap, 714 GNUNET_CONTAINER_multihashmap_remove (client->connectmap,
727 &neighbour->hashPubKey, 715 &neighbour->hashPubKey,
728 NULL)); 716 NULL));
729#endif 717#endif
730 dcm.header.size = htons (sizeof (struct DisconnectNotifyMessage)); 718 dcm.header.size = htons (sizeof (struct DisconnectNotifyMessage));
731 dcm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT); 719 dcm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT);
@@ -748,27 +736,27 @@ GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
748 * @param tmap_new updated type map for the neighbour, NULL for disconnect 736 * @param tmap_new updated type map for the neighbour, NULL for disconnect
749 */ 737 */
750void 738void
751GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *neighbour, 739GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity
752 const struct GNUNET_ATS_Information *atsi, 740 *neighbour,
753 unsigned int atsi_count, 741 const struct GNUNET_ATS_Information
754 const struct GSC_TypeMap *tmap_old, 742 *atsi, unsigned int atsi_count,
755 const struct GSC_TypeMap *tmap_new) 743 const struct GSC_TypeMap *tmap_old,
744 const struct GSC_TypeMap *tmap_new)
756{ 745{
757 struct GSC_Client *c; 746 struct GSC_Client *c;
758 747
759 for (c = client_head; c != NULL; c = c->next) 748 for (c = client_head; c != NULL; c = c->next)
760 GSC_CLIENTS_notify_client_about_neighbour (c, neighbour, atsi, 749 GSC_CLIENTS_notify_client_about_neighbour (c, neighbour, atsi, atsi_count,
761 atsi_count, 750 tmap_old, tmap_new);
762 tmap_old, tmap_new);
763} 751}
764 752
765 753
766/** 754/**
767 * Deliver P2P message to interested clients. Caller must have checked 755 * Deliver P2P message to interested clients. Caller must have checked
768 * that the sending peer actually lists the given message type as one 756 * that the sending peer actually lists the given message type as one
769 * of its types. 757 * of its types.
770 * 758 *
771 * @param sender peer who sent us the message 759 * @param sender peer who sent us the message
772 * @param atsi performance information about neighbour 760 * @param atsi performance information about neighbour
773 * @param atsi_count number of entries in 'ats' array 761 * @param atsi_count number of entries in 'ats' array
774 * @param msg the message 762 * @param msg the message
@@ -778,13 +766,13 @@ GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *ne
778 */ 766 */
779void 767void
780GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender, 768GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
781 const struct GNUNET_ATS_Information *atsi, 769 const struct GNUNET_ATS_Information *atsi,
782 unsigned int atsi_count, 770 unsigned int atsi_count,
783 const struct GNUNET_MessageHeader *msg, 771 const struct GNUNET_MessageHeader *msg,
784 uint16_t msize, 772 uint16_t msize, int options)
785 int options)
786{ 773{
787 size_t size = msize + sizeof (struct NotifyTrafficMessage) + 774 size_t size =
775 msize + sizeof (struct NotifyTrafficMessage) +
788 atsi_count * sizeof (struct GNUNET_ATS_Information); 776 atsi_count * sizeof (struct GNUNET_ATS_Information);
789 char buf[size]; 777 char buf[size];
790 struct NotifyTrafficMessage *ntm; 778 struct NotifyTrafficMessage *ntm;
@@ -793,8 +781,8 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
793 if (0 == options) 781 if (0 == options)
794 { 782 {
795 GNUNET_snprintf (buf, sizeof (buf), 783 GNUNET_snprintf (buf, sizeof (buf),
796 gettext_noop ("# bytes of messages of type %u received"), 784 gettext_noop ("# bytes of messages of type %u received"),
797 (unsigned int) ntohs (msg->type)); 785 (unsigned int) ntohs (msg->type));
798 GNUNET_STATISTICS_update (GSC_stats, buf, msize, GNUNET_NO); 786 GNUNET_STATISTICS_update (GSC_stats, buf, msize, GNUNET_NO);
799 } 787 }
800 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 788 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
@@ -807,8 +795,7 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
807#if DEBUG_CORE 795#if DEBUG_CORE
808 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 796 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
809 "Core service passes message from `%4s' of type %u to client.\n", 797 "Core service passes message from `%4s' of type %u to client.\n",
810 GNUNET_i2s (sender), 798 GNUNET_i2s (sender), (unsigned int) ntohs (msg->type));
811 (unsigned int) ntohs (msg->type));
812#endif 799#endif
813 GSC_SESSIONS_add_to_typemap (sender, ntohs (msg->type)); 800 GSC_SESSIONS_add_to_typemap (sender, ntohs (msg->type));
814 ntm = (struct NotifyTrafficMessage *) buf; 801 ntm = (struct NotifyTrafficMessage *) buf;
@@ -817,14 +804,12 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
817 ntm->ats_count = htonl (atsi_count); 804 ntm->ats_count = htonl (atsi_count);
818 ntm->peer = *sender; 805 ntm->peer = *sender;
819 a = &ntm->ats; 806 a = &ntm->ats;
820 memcpy (a, atsi, 807 memcpy (a, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
821 sizeof (struct GNUNET_ATS_Information) * atsi_count);
822 a[atsi_count].type = htonl (GNUNET_ATS_ARRAY_TERMINATOR); 808 a[atsi_count].type = htonl (GNUNET_ATS_ARRAY_TERMINATOR);
823 a[atsi_count].value = htonl (0); 809 a[atsi_count].value = htonl (0);
824 memcpy (&a[atsi_count + 1], msg, msize); 810 memcpy (&a[atsi_count + 1], msg, msize);
825 send_to_all_clients (sender, 811 send_to_all_clients (sender, &ntm->header, GNUNET_YES, options,
826 &ntm->header, GNUNET_YES, 812 ntohs (msg->type));
827 options, ntohs (msg->type));
828} 813}
829 814
830 815
@@ -871,7 +856,7 @@ GSC_CLIENTS_done ()
871{ 856{
872 struct GSC_Client *c; 857 struct GSC_Client *c;
873 858
874 while (NULL != (c = client_head)) 859 while (NULL != (c = client_head))
875 handle_client_disconnect (NULL, c->client_handle); 860 handle_client_disconnect (NULL, c->client_handle);
876 if (NULL != notifier) 861 if (NULL != notifier)
877 { 862 {
diff --git a/src/core/gnunet-service-core_clients.h b/src/core/gnunet-service-core_clients.h
index 2385efc05..bdad20da8 100644
--- a/src/core/gnunet-service-core_clients.h
+++ b/src/core/gnunet-service-core_clients.h
@@ -41,8 +41,8 @@
41 */ 41 */
42void 42void
43GSC_CLIENTS_send_to_client (struct GNUNET_SERVER_Client *client, 43GSC_CLIENTS_send_to_client (struct GNUNET_SERVER_Client *client,
44 const struct GNUNET_MessageHeader *msg, 44 const struct GNUNET_MessageHeader *msg,
45 int can_drop); 45 int can_drop);
46 46
47 47
48/** 48/**
@@ -59,11 +59,12 @@ GSC_CLIENTS_send_to_client (struct GNUNET_SERVER_Client *client,
59 */ 59 */
60void 60void
61GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client, 61GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
62 const struct GNUNET_PeerIdentity *neighbour, 62 const struct GNUNET_PeerIdentity
63 const struct GNUNET_ATS_Information *atsi, 63 *neighbour,
64 unsigned int atsi_count, 64 const struct GNUNET_ATS_Information
65 const struct GSC_TypeMap *tmap_old, 65 *atsi, unsigned int atsi_count,
66 const struct GSC_TypeMap *tmap_new); 66 const struct GSC_TypeMap *tmap_old,
67 const struct GSC_TypeMap *tmap_new);
67 68
68 69
69/** 70/**
@@ -78,19 +79,20 @@ GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
78 * @param tmap_new updated type map for the neighbour, NULL for disconnect 79 * @param tmap_new updated type map for the neighbour, NULL for disconnect
79 */ 80 */
80void 81void
81GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *neighbour, 82GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity
82 const struct GNUNET_ATS_Information *atsi, 83 *neighbour,
83 unsigned int atsi_count, 84 const struct GNUNET_ATS_Information
84 const struct GSC_TypeMap *tmap_old, 85 *atsi, unsigned int atsi_count,
85 const struct GSC_TypeMap *tmap_new); 86 const struct GSC_TypeMap *tmap_old,
87 const struct GSC_TypeMap *tmap_new);
86 88
87 89
88/** 90/**
89 * Deliver P2P message to interested clients. Caller must have checked 91 * Deliver P2P message to interested clients. Caller must have checked
90 * that the sending peer actually lists the given message type as one 92 * that the sending peer actually lists the given message type as one
91 * of its types. 93 * of its types.
92 * 94 *
93 * @param sender peer who sent us the message 95 * @param sender peer who sent us the message
94 * @param atsi performance information about neighbour 96 * @param atsi performance information about neighbour
95 * @param atsi_count number of entries in 'ats' array 97 * @param atsi_count number of entries in 'ats' array
96 * @param msg the message 98 * @param msg the message
@@ -100,11 +102,10 @@ GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *ne
100 */ 102 */
101void 103void
102GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender, 104GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
103 const struct GNUNET_ATS_Information *atsi, 105 const struct GNUNET_ATS_Information *atsi,
104 unsigned int atsi_count, 106 unsigned int atsi_count,
105 const struct GNUNET_MessageHeader *msg, 107 const struct GNUNET_MessageHeader *msg,
106 uint16_t msize, 108 uint16_t msize, int options);
107 int options);
108 109
109 110
110/** 111/**
diff --git a/src/core/gnunet-service-core_kx.c b/src/core/gnunet-service-core_kx.c
index 7d27378ac..d49e06e2a 100644
--- a/src/core/gnunet-service-core_kx.c
+++ b/src/core/gnunet-service-core_kx.c
@@ -112,7 +112,7 @@ struct PongMessage
112 * first field after header (this is where we start to encrypt!). 112 * first field after header (this is where we start to encrypt!).
113 */ 113 */
114 uint32_t challenge GNUNET_PACKED; 114 uint32_t challenge GNUNET_PACKED;
115 115
116 /** 116 /**
117 * Reserved, always 'GNUNET_BANDWIDTH_VALUE_MAX'. 117 * Reserved, always 'GNUNET_BANDWIDTH_VALUE_MAX'.
118 */ 118 */
@@ -495,8 +495,8 @@ do_encrypt (struct GSC_KeyExchangeInfo *kx,
495 "Encrypted %u bytes for `%4s' using key %u, IV %u\n", 495 "Encrypted %u bytes for `%4s' using key %u, IV %u\n",
496 (unsigned int) size, GNUNET_i2s (&kx->peer), 496 (unsigned int) size, GNUNET_i2s (&kx->peer),
497 (unsigned int) kx->encrypt_key.crc32, GNUNET_CRYPTO_crc32_n (iv, 497 (unsigned int) kx->encrypt_key.crc32, GNUNET_CRYPTO_crc32_n (iv,
498 sizeof 498 sizeof
499 (iv))); 499 (iv)));
500#endif 500#endif
501 return GNUNET_OK; 501 return GNUNET_OK;
502} 502}
@@ -526,14 +526,14 @@ do_decrypt (struct GSC_KeyExchangeInfo *kx,
526 GNUNET_break (0); 526 GNUNET_break (0);
527 return GNUNET_NO; 527 return GNUNET_NO;
528 } 528 }
529 if ((kx->status != KX_STATE_KEY_RECEIVED) && 529 if ((kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP))
530 (kx->status != KX_STATE_UP))
531 { 530 {
532 GNUNET_break_op (0); 531 GNUNET_break_op (0);
533 return GNUNET_SYSERR; 532 return GNUNET_SYSERR;
534 } 533 }
535 if (size != 534 if (size !=
536 GNUNET_CRYPTO_aes_decrypt (in, (uint16_t) size, &kx->decrypt_key, iv, out)) 535 GNUNET_CRYPTO_aes_decrypt (in, (uint16_t) size, &kx->decrypt_key, iv,
536 out))
537 { 537 {
538 GNUNET_break (0); 538 GNUNET_break (0);
539 return GNUNET_SYSERR; 539 return GNUNET_SYSERR;
@@ -545,8 +545,8 @@ do_decrypt (struct GSC_KeyExchangeInfo *kx,
545 "Decrypted %u bytes from `%4s' using key %u, IV %u\n", 545 "Decrypted %u bytes from `%4s' using key %u, IV %u\n",
546 (unsigned int) size, GNUNET_i2s (&kx->peer), 546 (unsigned int) size, GNUNET_i2s (&kx->peer),
547 (unsigned int) kx->decrypt_key.crc32, GNUNET_CRYPTO_crc32_n (iv, 547 (unsigned int) kx->decrypt_key.crc32, GNUNET_CRYPTO_crc32_n (iv,
548 sizeof 548 sizeof
549 (*iv))); 549 (*iv)));
550#endif 550#endif
551 return GNUNET_OK; 551 return GNUNET_OK;
552} 552}
@@ -573,7 +573,8 @@ set_key_retry_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
573 struct GSC_KeyExchangeInfo *kx = cls; 573 struct GSC_KeyExchangeInfo *kx = cls;
574 574
575 kx->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; 575 kx->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
576 kx->set_key_retry_frequency = GNUNET_TIME_relative_multiply (kx->set_key_retry_frequency, 2); 576 kx->set_key_retry_frequency =
577 GNUNET_TIME_relative_multiply (kx->set_key_retry_frequency, 2);
577 send_key (kx); 578 send_key (kx);
578} 579}
579 580
@@ -590,8 +591,7 @@ set_key_retry_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
590 */ 591 */
591static void 592static void
592process_hello (void *cls, const struct GNUNET_PeerIdentity *peer, 593process_hello (void *cls, const struct GNUNET_PeerIdentity *peer,
593 const struct GNUNET_HELLO_Message *hello, 594 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
594 const char *err_msg)
595{ 595{
596 struct GSC_KeyExchangeInfo *kx = cls; 596 struct GSC_KeyExchangeInfo *kx = cls;
597 struct SetKeyMessage *skm; 597 struct SetKeyMessage *skm;
@@ -607,19 +607,19 @@ process_hello (void *cls, const struct GNUNET_PeerIdentity *peer,
607 { 607 {
608 kx->pitr = NULL; 608 kx->pitr = NULL;
609 if (kx->public_key != NULL) 609 if (kx->public_key != NULL)
610 return; /* done here */ 610 return; /* done here */
611#if DEBUG_CORE 611#if DEBUG_CORE
612 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 612 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
613 "Failed to obtain public key for peer `%4s', delaying processing of SET_KEY\n", 613 "Failed to obtain public key for peer `%4s', delaying processing of SET_KEY\n",
614 GNUNET_i2s (&kx->peer)); 614 GNUNET_i2s (&kx->peer));
615#endif 615#endif
616 GNUNET_STATISTICS_update (GSC_stats, 616 GNUNET_STATISTICS_update (GSC_stats,
617 gettext_noop 617 gettext_noop
618 ("# Delayed connecting due to lack of public key"), 618 ("# Delayed connecting due to lack of public key"),
619 1, GNUNET_NO); 619 1, GNUNET_NO);
620 kx->retry_set_key_task = 620 kx->retry_set_key_task =
621 GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency, 621 GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency,
622 &set_key_retry_task, kx); 622 &set_key_retry_task, kx);
623 return; 623 return;
624 } 624 }
625 if (kx->public_key != NULL) 625 if (kx->public_key != NULL)
@@ -661,22 +661,19 @@ GSC_KX_start (const struct GNUNET_PeerIdentity *pid)
661 struct GSC_KeyExchangeInfo *kx; 661 struct GSC_KeyExchangeInfo *kx;
662 662
663#if DEBUG_CORE 663#if DEBUG_CORE
664 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 664 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initiating key exchange with `%s'\n",
665 "Initiating key exchange with `%s'\n", 665 GNUNET_i2s (pid));
666 GNUNET_i2s (pid));
667#endif 666#endif
668 GNUNET_STATISTICS_update (GSC_stats, 667 GNUNET_STATISTICS_update (GSC_stats,
669 gettext_noop ("# key exchanges initiated"), 668 gettext_noop ("# key exchanges initiated"), 1,
670 1, 669 GNUNET_NO);
671 GNUNET_NO);
672 kx = GNUNET_malloc (sizeof (struct GSC_KeyExchangeInfo)); 670 kx = GNUNET_malloc (sizeof (struct GSC_KeyExchangeInfo));
673 kx->peer = *pid; 671 kx->peer = *pid;
674 kx->set_key_retry_frequency = INITIAL_SET_KEY_RETRY_FREQUENCY; 672 kx->set_key_retry_frequency = INITIAL_SET_KEY_RETRY_FREQUENCY;
675 kx->pitr = GNUNET_PEERINFO_iterate (peerinfo, 673 kx->pitr =
676 pid, 674 GNUNET_PEERINFO_iterate (peerinfo, pid,
677 GNUNET_TIME_UNIT_FOREVER_REL /* timeout? */, 675 GNUNET_TIME_UNIT_FOREVER_REL /* timeout? */ ,
678 &process_hello, 676 &process_hello, kx);
679 kx);
680 return kx; 677 return kx;
681} 678}
682 679
@@ -689,10 +686,8 @@ GSC_KX_start (const struct GNUNET_PeerIdentity *pid)
689void 686void
690GSC_KX_stop (struct GSC_KeyExchangeInfo *kx) 687GSC_KX_stop (struct GSC_KeyExchangeInfo *kx)
691{ 688{
692 GNUNET_STATISTICS_update (GSC_stats, 689 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# key exchanges stopped"),
693 gettext_noop ("# key exchanges stopped"), 690 1, GNUNET_NO);
694 1,
695 GNUNET_NO);
696 if (kx->pitr != NULL) 691 if (kx->pitr != NULL)
697 { 692 {
698 GNUNET_PEERINFO_iterate_cancel (kx->pitr); 693 GNUNET_PEERINFO_iterate_cancel (kx->pitr);
@@ -726,7 +721,7 @@ GSC_KX_stop (struct GSC_KeyExchangeInfo *kx)
726 */ 721 */
727void 722void
728GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, 723GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx,
729 const struct GNUNET_MessageHeader *msg) 724 const struct GNUNET_MessageHeader *msg)
730{ 725{
731 const struct SetKeyMessage *m; 726 const struct SetKeyMessage *m;
732 struct GNUNET_TIME_Absolute t; 727 struct GNUNET_TIME_Absolute t;
@@ -735,16 +730,16 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx,
735 struct PongMessage *pong; 730 struct PongMessage *pong;
736 enum KxStateMachine sender_status; 731 enum KxStateMachine sender_status;
737 uint16_t size; 732 uint16_t size;
738 733
739 size = ntohs (msg->size); 734 size = ntohs (msg->size);
740 if (size != sizeof (struct SetKeyMessage)) 735 if (size != sizeof (struct SetKeyMessage))
741 { 736 {
742 GNUNET_break_op (0); 737 GNUNET_break_op (0);
743 return; 738 return;
744 } 739 }
745 m = (const struct SetKeyMessage*) msg; 740 m = (const struct SetKeyMessage *) msg;
746 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# session keys received"), 741 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# session keys received"),
747 1, GNUNET_NO); 742 1, GNUNET_NO);
748 743
749#if DEBUG_CORE 744#if DEBUG_CORE
750 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 745 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -754,15 +749,16 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx,
754 if (kx->public_key == NULL) 749 if (kx->public_key == NULL)
755 { 750 {
756 GNUNET_free_non_null (kx->skm_received); 751 GNUNET_free_non_null (kx->skm_received);
757 kx->skm_received = (struct SetKeyMessage*) GNUNET_copy_message (msg); 752 kx->skm_received = (struct SetKeyMessage *) GNUNET_copy_message (msg);
758 return; 753 return;
759 } 754 }
760 if (0 != 755 if (0 !=
761 memcmp (&m->target, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity))) 756 memcmp (&m->target, &GSC_my_identity,
757 sizeof (struct GNUNET_PeerIdentity)))
762 { 758 {
763 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 759 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
764 _("`%s' is for `%s', not for me. Ignoring.\n"), 760 _("`%s' is for `%s', not for me. Ignoring.\n"), "SET_KEY",
765 "SET_KEY", GNUNET_i2s (&m->target)); 761 GNUNET_i2s (&m->target));
766 return; 762 return;
767 } 763 }
768 if ((ntohl (m->purpose.size) != 764 if ((ntohl (m->purpose.size) !=
@@ -779,8 +775,7 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx,
779 return; 775 return;
780 } 776 }
781 t = GNUNET_TIME_absolute_ntoh (m->creation_time); 777 t = GNUNET_TIME_absolute_ntoh (m->creation_time);
782 if (((kx->status == KX_STATE_KEY_RECEIVED) || 778 if (((kx->status == KX_STATE_KEY_RECEIVED) || (kx->status == KX_STATE_UP)) &&
783 (kx->status == KX_STATE_UP)) &&
784 (t.abs_value < kx->decrypt_key_created.abs_value)) 779 (t.abs_value < kx->decrypt_key_created.abs_value))
785 { 780 {
786 /* this could rarely happen due to massive re-ordering of 781 /* this could rarely happen due to massive re-ordering of
@@ -803,9 +798,8 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx,
803 gettext_noop ("# SET_KEY messages decrypted"), 1, 798 gettext_noop ("# SET_KEY messages decrypted"), 1,
804 GNUNET_NO); 799 GNUNET_NO);
805#if DEBUG_CORE 800#if DEBUG_CORE
806 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 801 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received SET_KEY from `%s'\n",
807 "Received SET_KEY from `%s'\n", 802 GNUNET_i2s (&kx->peer));
808 GNUNET_i2s (&kx->peer));
809#endif 803#endif
810 kx->decrypt_key = k; 804 kx->decrypt_key = k;
811 if (kx->decrypt_key_created.abs_value != t.abs_value) 805 if (kx->decrypt_key_created.abs_value != t.abs_value)
@@ -831,9 +825,9 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx,
831 /* we're not up, so we are already doing 'send_key' */ 825 /* we're not up, so we are already doing 'send_key' */
832 break; 826 break;
833 case KX_STATE_UP: 827 case KX_STATE_UP:
834 if ( (sender_status == KX_STATE_DOWN) || 828 if ((sender_status == KX_STATE_DOWN) ||
835 (sender_status == KX_STATE_KEY_SENT) ) 829 (sender_status == KX_STATE_KEY_SENT))
836 send_key (kx); /* we are up, but other peer is not! */ 830 send_key (kx); /* we are up, but other peer is not! */
837 break; 831 break;
838 default: 832 default:
839 GNUNET_break (0); 833 GNUNET_break (0);
@@ -865,7 +859,7 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx,
865 */ 859 */
866void 860void
867GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx, 861GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx,
868 const struct GNUNET_MessageHeader *msg) 862 const struct GNUNET_MessageHeader *msg)
869{ 863{
870 const struct PingMessage *m; 864 const struct PingMessage *m;
871 struct PingMessage t; 865 struct PingMessage t;
@@ -876,22 +870,21 @@ GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx,
876 870
877 msize = ntohs (msg->size); 871 msize = ntohs (msg->size);
878 if (msize != sizeof (struct PingMessage)) 872 if (msize != sizeof (struct PingMessage))
879 { 873 {
880 GNUNET_break_op (0); 874 GNUNET_break_op (0);
881 return; 875 return;
882 } 876 }
883 GNUNET_STATISTICS_update (GSC_stats, 877 GNUNET_STATISTICS_update (GSC_stats,
884 gettext_noop ("# PING messages received"), 878 gettext_noop ("# PING messages received"), 1,
885 1, GNUNET_NO); 879 GNUNET_NO);
886 if ( (kx->status != KX_STATE_KEY_RECEIVED) && 880 if ((kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP))
887 (kx->status != KX_STATE_UP) ) 881 {
888 { 882 /* defer */
889 /* defer */ 883 GNUNET_free_non_null (kx->ping_received);
890 GNUNET_free_non_null (kx->ping_received); 884 kx->ping_received = (struct PingMessage *) GNUNET_copy_message (msg);
891 kx->ping_received = (struct PingMessage*) GNUNET_copy_message (msg); 885 return;
892 return; 886 }
893 } 887 m = (const struct PingMessage *) msg;
894 m = (const struct PingMessage*) msg;
895#if DEBUG_CORE 888#if DEBUG_CORE
896 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
897 "Core service receives `%s' request from `%4s'.\n", "PING", 890 "Core service receives `%s' request from `%4s'.\n", "PING",
@@ -915,15 +908,15 @@ GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx,
915 GNUNET_snprintf (sender, sizeof (sender), "%8s", GNUNET_i2s (&kx->peer)); 908 GNUNET_snprintf (sender, sizeof (sender), "%8s", GNUNET_i2s (&kx->peer));
916 GNUNET_snprintf (peer, sizeof (peer), "%8s", GNUNET_i2s (&t.target)); 909 GNUNET_snprintf (peer, sizeof (peer), "%8s", GNUNET_i2s (&t.target));
917 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 910 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
918 _("Received PING from `%s' for different identity: I am `%s', PONG identity: `%s'\n"), 911 _
912 ("Received PING from `%s' for different identity: I am `%s', PONG identity: `%s'\n"),
919 sender, GNUNET_i2s (&GSC_my_identity), peer); 913 sender, GNUNET_i2s (&GSC_my_identity), peer);
920 GNUNET_break_op (0); 914 GNUNET_break_op (0);
921 return; 915 return;
922 } 916 }
923#if DEBUG_CORE 917#if DEBUG_CORE
924 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 918 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received PING from `%s'\n",
925 "Received PING from `%s'\n", 919 GNUNET_i2s (&kx->peer));
926 GNUNET_i2s (&kx->peer));
927#endif 920#endif
928 /* construct PONG */ 921 /* construct PONG */
929 tx.reserved = GNUNET_BANDWIDTH_VALUE_MAX; 922 tx.reserved = GNUNET_BANDWIDTH_VALUE_MAX;
@@ -937,12 +930,10 @@ GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx,
937 do_encrypt (kx, &iv, &tx.challenge, &tp.challenge, 930 do_encrypt (kx, &iv, &tx.challenge, &tp.challenge,
938 sizeof (struct PongMessage) - ((void *) &tp.challenge - 931 sizeof (struct PongMessage) - ((void *) &tp.challenge -
939 (void *) &tp)); 932 (void *) &tp));
940 GNUNET_STATISTICS_update (GSC_stats, 933 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# PONG messages created"),
941 gettext_noop ("# PONG messages created"), 1, 934 1, GNUNET_NO);
942 GNUNET_NO); 935 GSC_NEIGHBOURS_transmit (&kx->peer, &tp.header,
943 GSC_NEIGHBOURS_transmit (&kx->peer, 936 GNUNET_TIME_UNIT_FOREVER_REL /* FIXME: timeout */ );
944 &tp.header,
945 GNUNET_TIME_UNIT_FOREVER_REL /* FIXME: timeout */);
946} 937}
947 938
948 939
@@ -963,21 +954,22 @@ setup_fresh_setkey (struct GSC_KeyExchangeInfo *kx)
963 skm->header.size = htons (sizeof (struct SetKeyMessage)); 954 skm->header.size = htons (sizeof (struct SetKeyMessage));
964 skm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SET_KEY); 955 skm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SET_KEY);
965 skm->purpose.size = 956 skm->purpose.size =
966 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + 957 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
967 sizeof (struct GNUNET_TIME_AbsoluteNBO) + 958 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
968 sizeof (struct GNUNET_CRYPTO_RsaEncryptedData) + 959 sizeof (struct GNUNET_CRYPTO_RsaEncryptedData) +
969 sizeof (struct GNUNET_PeerIdentity)); 960 sizeof (struct GNUNET_PeerIdentity));
970 skm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_SET_KEY); 961 skm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_SET_KEY);
971 skm->creation_time = GNUNET_TIME_absolute_hton (kx->encrypt_key_created); 962 skm->creation_time = GNUNET_TIME_absolute_hton (kx->encrypt_key_created);
972 skm->target = kx->peer; 963 skm->target = kx->peer;
973 GNUNET_assert (GNUNET_OK == 964 GNUNET_assert (GNUNET_OK ==
974 GNUNET_CRYPTO_rsa_encrypt (&kx->encrypt_key, 965 GNUNET_CRYPTO_rsa_encrypt (&kx->encrypt_key,
975 sizeof (struct 966 sizeof (struct
976 GNUNET_CRYPTO_AesSessionKey), 967 GNUNET_CRYPTO_AesSessionKey),
977 kx->public_key, &skm->encrypted_key)); 968 kx->public_key,
969 &skm->encrypted_key));
978 GNUNET_assert (GNUNET_OK == 970 GNUNET_assert (GNUNET_OK ==
979 GNUNET_CRYPTO_rsa_sign (my_private_key, &skm->purpose, 971 GNUNET_CRYPTO_rsa_sign (my_private_key, &skm->purpose,
980 &skm->signature)); 972 &skm->signature));
981} 973}
982 974
983 975
@@ -997,13 +989,13 @@ setup_fresh_ping (struct GSC_KeyExchangeInfo *kx)
997 pm->header.size = htons (sizeof (struct PingMessage)); 989 pm->header.size = htons (sizeof (struct PingMessage));
998 pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); 990 pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING);
999 pm->iv_seed = 991 pm->iv_seed =
1000 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); 992 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
1001 derive_iv (&iv, &kx->encrypt_key, pm->iv_seed, &kx->peer); 993 derive_iv (&iv, &kx->encrypt_key, pm->iv_seed, &kx->peer);
1002 pp.challenge = kx->ping_challenge; 994 pp.challenge = kx->ping_challenge;
1003 pp.target = kx->peer; 995 pp.target = kx->peer;
1004 do_encrypt (kx, &iv, &pp.target, &pm->target, 996 do_encrypt (kx, &iv, &pp.target, &pm->target,
1005 sizeof (struct PingMessage) - ((void *) &pm->target - 997 sizeof (struct PingMessage) - ((void *) &pm->target -
1006 (void *) pm)); 998 (void *) pm));
1007} 999}
1008 1000
1009 1001
@@ -1024,33 +1016,29 @@ send_keep_alive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1024 kx->keep_alive_task = GNUNET_SCHEDULER_NO_TASK; 1016 kx->keep_alive_task = GNUNET_SCHEDULER_NO_TASK;
1025 left = GNUNET_TIME_absolute_get_remaining (kx->timeout); 1017 left = GNUNET_TIME_absolute_get_remaining (kx->timeout);
1026 if (left.rel_value == 0) 1018 if (left.rel_value == 0)
1027 { 1019 {
1028 GNUNET_STATISTICS_update (GSC_stats, 1020 GNUNET_STATISTICS_update (GSC_stats,
1029 gettext_noop ("# sessions terminated by timeout"), 1021 gettext_noop ("# sessions terminated by timeout"),
1030 1, 1022 1, GNUNET_NO);
1031 GNUNET_NO);
1032 GSC_SESSIONS_end (&kx->peer); 1023 GSC_SESSIONS_end (&kx->peer);
1033 kx->status = KX_STATE_DOWN; 1024 kx->status = KX_STATE_DOWN;
1034 return; 1025 return;
1035 } 1026 }
1036#if DEBUG_CORE 1027#if DEBUG_CORE
1037 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1028 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending KEEPALIVE to `%s'\n",
1038 "Sending KEEPALIVE to `%s'\n", 1029 GNUNET_i2s (&kx->peer));
1039 GNUNET_i2s (&kx->peer));
1040#endif 1030#endif
1041 GNUNET_STATISTICS_update (GSC_stats, 1031 GNUNET_STATISTICS_update (GSC_stats,
1042 gettext_noop ("# keepalive messages sent"), 1032 gettext_noop ("# keepalive messages sent"), 1,
1043 1, 1033 GNUNET_NO);
1044 GNUNET_NO);
1045 setup_fresh_ping (kx); 1034 setup_fresh_ping (kx);
1046 GSC_NEIGHBOURS_transmit (&kx->peer, 1035 GSC_NEIGHBOURS_transmit (&kx->peer, &kx->ping.header,
1047 &kx->ping.header, 1036 kx->set_key_retry_frequency);
1048 kx->set_key_retry_frequency);
1049 retry = 1037 retry =
1050 GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2), 1038 GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2),
1051 MIN_PING_FREQUENCY); 1039 MIN_PING_FREQUENCY);
1052 kx->keep_alive_task = 1040 kx->keep_alive_task =
1053 GNUNET_SCHEDULER_add_delayed (retry, &send_keep_alive, kx); 1041 GNUNET_SCHEDULER_add_delayed (retry, &send_keep_alive, kx);
1054} 1042}
1055 1043
1056 1044
@@ -1064,13 +1052,15 @@ send_keep_alive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1064static void 1052static void
1065update_timeout (struct GSC_KeyExchangeInfo *kx) 1053update_timeout (struct GSC_KeyExchangeInfo *kx)
1066{ 1054{
1067 kx->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 1055 kx->timeout =
1056 GNUNET_TIME_relative_to_absolute
1057 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1068 if (kx->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) 1058 if (kx->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
1069 GNUNET_SCHEDULER_cancel (kx->keep_alive_task); 1059 GNUNET_SCHEDULER_cancel (kx->keep_alive_task);
1070 kx->keep_alive_task = 1060 kx->keep_alive_task =
1071 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide 1061 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
1072 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1062 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1073 2), &send_keep_alive, kx); 1063 2), &send_keep_alive, kx);
1074} 1064}
1075 1065
1076 1066
@@ -1081,7 +1071,8 @@ update_timeout (struct GSC_KeyExchangeInfo *kx)
1081 * @param m the encrypted PONG message itself 1071 * @param m the encrypted PONG message itself
1082 */ 1072 */
1083void 1073void
1084GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, const struct GNUNET_MessageHeader *msg) 1074GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx,
1075 const struct GNUNET_MessageHeader *msg)
1085{ 1076{
1086 const struct PongMessage *m; 1077 const struct PongMessage *m;
1087 struct PongMessage t; 1078 struct PongMessage t;
@@ -1095,19 +1086,19 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, const struct GNUNET_MessageH
1095 GNUNET_break_op (0); 1086 GNUNET_break_op (0);
1096 return; 1087 return;
1097 } 1088 }
1098 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# PONG messages received"), 1089 GNUNET_STATISTICS_update (GSC_stats,
1099 1, GNUNET_NO); 1090 gettext_noop ("# PONG messages received"), 1,
1100 if ( (kx->status != KX_STATE_KEY_RECEIVED) && 1091 GNUNET_NO);
1101 (kx->status != KX_STATE_UP) ) 1092 if ((kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP))
1102 { 1093 {
1103 if (kx->status == KX_STATE_KEY_SENT) 1094 if (kx->status == KX_STATE_KEY_SENT)
1104 { 1095 {
1105 GNUNET_free_non_null (kx->pong_received); 1096 GNUNET_free_non_null (kx->pong_received);
1106 kx->pong_received = (struct PongMessage*) GNUNET_copy_message (msg); 1097 kx->pong_received = (struct PongMessage *) GNUNET_copy_message (msg);
1107 } 1098 }
1108 return; 1099 return;
1109 } 1100 }
1110 m = (const struct PongMessage*) msg; 1101 m = (const struct PongMessage *) msg;
1111#if DEBUG_HANDSHAKE 1102#if DEBUG_HANDSHAKE
1112 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1113 "Core service receives `%s' response from `%4s'.\n", "PONG", 1104 "Core service receives `%s' response from `%4s'.\n", "PONG",
@@ -1125,8 +1116,9 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, const struct GNUNET_MessageH
1125 GNUNET_break_op (0); 1116 GNUNET_break_op (0);
1126 return; 1117 return;
1127 } 1118 }
1128 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# PONG messages decrypted"), 1119 GNUNET_STATISTICS_update (GSC_stats,
1129 1, GNUNET_NO); 1120 gettext_noop ("# PONG messages decrypted"), 1,
1121 GNUNET_NO);
1130 if ((0 != memcmp (&t.target, &kx->peer, sizeof (struct GNUNET_PeerIdentity))) 1122 if ((0 != memcmp (&t.target, &kx->peer, sizeof (struct GNUNET_PeerIdentity)))
1131 || (kx->ping_challenge != t.challenge)) 1123 || (kx->ping_challenge != t.challenge))
1132 { 1124 {
@@ -1143,9 +1135,8 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, const struct GNUNET_MessageH
1143 return; 1135 return;
1144 } 1136 }
1145#if DEBUG_CORE 1137#if DEBUG_CORE
1146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received PONG from `%s'\n",
1147 "Received PONG from `%s'\n", 1139 GNUNET_i2s (&kx->peer));
1148 GNUNET_i2s (&kx->peer));
1149#endif 1140#endif
1150 switch (kx->status) 1141 switch (kx->status)
1151 { 1142 {
@@ -1170,7 +1161,8 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, const struct GNUNET_MessageH
1170 { 1161 {
1171 emsg = kx->emsg_received; 1162 emsg = kx->emsg_received;
1172 kx->emsg_received = NULL; 1163 kx->emsg_received = NULL;
1173 GSC_KX_handle_encrypted_message (kx, &emsg->header, NULL, 0 /* FIXME: ATSI */); 1164 GSC_KX_handle_encrypted_message (kx, &emsg->header, NULL,
1165 0 /* FIXME: ATSI */ );
1174 GNUNET_free (emsg); 1166 GNUNET_free (emsg);
1175 } 1167 }
1176 update_timeout (kx); 1168 update_timeout (kx);
@@ -1194,20 +1186,20 @@ static void
1194send_key (struct GSC_KeyExchangeInfo *kx) 1186send_key (struct GSC_KeyExchangeInfo *kx)
1195{ 1187{
1196 GNUNET_assert (kx->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK); 1188 GNUNET_assert (kx->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK);
1197 if (KX_STATE_UP == kx->status) 1189 if (KX_STATE_UP == kx->status)
1198 return; /* nothing to do */ 1190 return; /* nothing to do */
1199 if (kx->public_key == NULL) 1191 if (kx->public_key == NULL)
1200 { 1192 {
1201 /* lookup public key, then try again */ 1193 /* lookup public key, then try again */
1202#if DEBUG_CORE 1194#if DEBUG_CORE
1203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1195 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1204 "Trying to obtain public key for `%s'\n", 1196 "Trying to obtain public key for `%s'\n",
1205 GNUNET_i2s (&kx->peer)); 1197 GNUNET_i2s (&kx->peer));
1206#endif 1198#endif
1207 kx->pitr = 1199 kx->pitr =
1208 GNUNET_PEERINFO_iterate (peerinfo, &kx->peer, 1200 GNUNET_PEERINFO_iterate (peerinfo, &kx->peer,
1209 GNUNET_TIME_UNIT_FOREVER_REL /* timeout? */, 1201 GNUNET_TIME_UNIT_FOREVER_REL /* timeout? */ ,
1210 &process_hello, kx); 1202 &process_hello, kx);
1211 return; 1203 return;
1212 } 1204 }
1213 1205
@@ -1215,14 +1207,14 @@ send_key (struct GSC_KeyExchangeInfo *kx)
1215 switch (kx->status) 1207 switch (kx->status)
1216 { 1208 {
1217 case KX_STATE_DOWN: 1209 case KX_STATE_DOWN:
1218 kx->status = KX_STATE_KEY_SENT; 1210 kx->status = KX_STATE_KEY_SENT;
1219 /* setup SET KEY message */ 1211 /* setup SET KEY message */
1220 setup_fresh_setkey (kx); 1212 setup_fresh_setkey (kx);
1221 setup_fresh_ping (kx); 1213 setup_fresh_ping (kx);
1222 GNUNET_STATISTICS_update (GSC_stats, 1214 GNUNET_STATISTICS_update (GSC_stats,
1223 gettext_noop 1215 gettext_noop
1224 ("# SET_KEY and PING messages created"), 1, 1216 ("# SET_KEY and PING messages created"), 1,
1225 GNUNET_NO); 1217 GNUNET_NO);
1226 break; 1218 break;
1227 case KX_STATE_KEY_SENT: 1219 case KX_STATE_KEY_SENT:
1228 break; 1220 break;
@@ -1239,19 +1231,16 @@ send_key (struct GSC_KeyExchangeInfo *kx)
1239 /* always update sender status in SET KEY message */ 1231 /* always update sender status in SET KEY message */
1240 kx->skm.sender_status = htonl ((int32_t) kx->status); 1232 kx->skm.sender_status = htonl ((int32_t) kx->status);
1241#if DEBUG_CORE 1233#if DEBUG_CORE
1242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SET_KEY and PING to `%s'\n",
1243 "Sending SET_KEY and PING to `%s'\n", 1235 GNUNET_i2s (&kx->peer));
1244 GNUNET_i2s (&kx->peer));
1245#endif 1236#endif
1246 GSC_NEIGHBOURS_transmit (&kx->peer, 1237 GSC_NEIGHBOURS_transmit (&kx->peer, &kx->skm.header,
1247 &kx->skm.header, 1238 kx->set_key_retry_frequency);
1248 kx->set_key_retry_frequency); 1239 GSC_NEIGHBOURS_transmit (&kx->peer, &kx->ping.header,
1249 GSC_NEIGHBOURS_transmit (&kx->peer, 1240 kx->set_key_retry_frequency);
1250 &kx->ping.header,
1251 kx->set_key_retry_frequency);
1252 kx->retry_set_key_task = 1241 kx->retry_set_key_task =
1253 GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency, 1242 GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency,
1254 &set_key_retry_task, kx); 1243 &set_key_retry_task, kx);
1255} 1244}
1256 1245
1257 1246
@@ -1264,18 +1253,17 @@ send_key (struct GSC_KeyExchangeInfo *kx)
1264 */ 1253 */
1265void 1254void
1266GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, 1255GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx,
1267 const void *payload, 1256 const void *payload, size_t payload_size)
1268 size_t payload_size)
1269{ 1257{
1270 size_t used = payload_size + sizeof (struct EncryptedMessage); 1258 size_t used = payload_size + sizeof (struct EncryptedMessage);
1271 char pbuf[used]; /* plaintext */ 1259 char pbuf[used]; /* plaintext */
1272 char cbuf[used]; /* ciphertext */ 1260 char cbuf[used]; /* ciphertext */
1273 struct EncryptedMessage *em; /* encrypted message */ 1261 struct EncryptedMessage *em; /* encrypted message */
1274 struct EncryptedMessage *ph; /* plaintext header */ 1262 struct EncryptedMessage *ph; /* plaintext header */
1275 struct GNUNET_CRYPTO_AesInitializationVector iv; 1263 struct GNUNET_CRYPTO_AesInitializationVector iv;
1276 struct GNUNET_CRYPTO_AuthKey auth_key; 1264 struct GNUNET_CRYPTO_AuthKey auth_key;
1277 1265
1278 ph = (struct EncryptedMessage*) pbuf; 1266 ph = (struct EncryptedMessage *) pbuf;
1279 ph->iv_seed = 1267 ph->iv_seed =
1280 htonl (GNUNET_CRYPTO_random_u32 1268 htonl (GNUNET_CRYPTO_random_u32
1281 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX)); 1269 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX));
@@ -1290,22 +1278,20 @@ GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx,
1290 em->iv_seed = ph->iv_seed; 1278 em->iv_seed = ph->iv_seed;
1291 derive_iv (&iv, &kx->encrypt_key, ph->iv_seed, &kx->peer); 1279 derive_iv (&iv, &kx->encrypt_key, ph->iv_seed, &kx->peer);
1292 GNUNET_assert (GNUNET_OK == 1280 GNUNET_assert (GNUNET_OK ==
1293 do_encrypt (kx, &iv, &ph->sequence_number, &em->sequence_number, 1281 do_encrypt (kx, &iv, &ph->sequence_number,
1282 &em->sequence_number,
1294 used - ENCRYPTED_HEADER_SIZE)); 1283 used - ENCRYPTED_HEADER_SIZE));
1295#if DEBUG_CORE 1284#if DEBUG_CORE
1296 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1285 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted %u bytes for %s\n",
1297 "Encrypted %u bytes for %s\n", 1286 used - ENCRYPTED_HEADER_SIZE, GNUNET_i2s (&kx->peer));
1298 used - ENCRYPTED_HEADER_SIZE,
1299 GNUNET_i2s (&kx->peer));
1300#endif 1287#endif
1301 derive_auth_key (&auth_key, &kx->encrypt_key, ph->iv_seed, 1288 derive_auth_key (&auth_key, &kx->encrypt_key, ph->iv_seed,
1302 kx->encrypt_key_created); 1289 kx->encrypt_key_created);
1303 GNUNET_CRYPTO_hmac (&auth_key, &em->sequence_number, 1290 GNUNET_CRYPTO_hmac (&auth_key, &em->sequence_number,
1304 used - ENCRYPTED_HEADER_SIZE, &em->hmac); 1291 used - ENCRYPTED_HEADER_SIZE, &em->hmac);
1305 GSC_NEIGHBOURS_transmit (&kx->peer, 1292 GSC_NEIGHBOURS_transmit (&kx->peer, &em->header,
1306 &em->header, 1293 GNUNET_TIME_UNIT_FOREVER_REL);
1307 GNUNET_TIME_UNIT_FOREVER_REL); 1294}
1308}
1309 1295
1310 1296
1311/** 1297/**
@@ -1313,7 +1299,7 @@ GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx,
1313 */ 1299 */
1314struct DeliverMessageContext 1300struct DeliverMessageContext
1315{ 1301{
1316 1302
1317 /** 1303 /**
1318 * Performance information for the connection. 1304 * Performance information for the connection.
1319 */ 1305 */
@@ -1330,7 +1316,7 @@ struct DeliverMessageContext
1330 uint32_t atsi_count; 1316 uint32_t atsi_count;
1331}; 1317};
1332 1318
1333 1319
1334/** 1320/**
1335 * We received an encrypted message. Decrypt, validate and 1321 * We received an encrypted message. Decrypt, validate and
1336 * pass on to the appropriate clients. 1322 * pass on to the appropriate clients.
@@ -1341,10 +1327,10 @@ struct DeliverMessageContext
1341 * @param atsi_count number of entries in ats (excluding 0-termination) 1327 * @param atsi_count number of entries in ats (excluding 0-termination)
1342 */ 1328 */
1343void 1329void
1344GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx, 1330GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx,
1345 const struct GNUNET_MessageHeader *msg, 1331 const struct GNUNET_MessageHeader *msg,
1346 const struct GNUNET_ATS_Information *atsi, 1332 const struct GNUNET_ATS_Information *atsi,
1347 uint32_t atsi_count) 1333 uint32_t atsi_count)
1348{ 1334{
1349 const struct EncryptedMessage *m; 1335 const struct EncryptedMessage *m;
1350 struct EncryptedMessage *pt; /* plaintext */ 1336 struct EncryptedMessage *pt; /* plaintext */
@@ -1363,21 +1349,20 @@ GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx,
1363 GNUNET_break_op (0); 1349 GNUNET_break_op (0);
1364 return; 1350 return;
1365 } 1351 }
1366 m = (const struct EncryptedMessage*) msg; 1352 m = (const struct EncryptedMessage *) msg;
1367 if ( (kx->status != KX_STATE_KEY_RECEIVED) && 1353 if ((kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP))
1368 (kx->status != KX_STATE_UP) )
1369 { 1354 {
1370 GNUNET_STATISTICS_update (GSC_stats, 1355 GNUNET_STATISTICS_update (GSC_stats,
1371 gettext_noop 1356 gettext_noop
1372 ("# failed to decrypt message (no session key)"), 1357 ("# failed to decrypt message (no session key)"),
1373 1, GNUNET_NO); 1358 1, GNUNET_NO);
1374 return; 1359 return;
1375 } 1360 }
1376 if (kx->status == KX_STATE_KEY_RECEIVED) 1361 if (kx->status == KX_STATE_KEY_RECEIVED)
1377 { 1362 {
1378 /* defer */ 1363 /* defer */
1379 GNUNET_free_non_null (kx->ping_received); 1364 GNUNET_free_non_null (kx->ping_received);
1380 kx->emsg_received = (struct EncryptedMessage*) GNUNET_copy_message (msg); 1365 kx->emsg_received = (struct EncryptedMessage *) GNUNET_copy_message (msg);
1381 return; 1366 return;
1382 } 1367 }
1383 /* validate hash */ 1368 /* validate hash */
@@ -1398,10 +1383,8 @@ GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx,
1398 size - ENCRYPTED_HEADER_SIZE)) 1383 size - ENCRYPTED_HEADER_SIZE))
1399 return; 1384 return;
1400#if DEBUG_CORE 1385#if DEBUG_CORE
1401 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1386 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypted %u bytes from %s\n",
1402 "Decrypted %u bytes from %s\n", 1387 size - ENCRYPTED_HEADER_SIZE, GNUNET_i2s (&kx->peer));
1403 size - ENCRYPTED_HEADER_SIZE,
1404 GNUNET_i2s (&kx->peer));
1405#endif 1388#endif
1406 pt = (struct EncryptedMessage *) buf; 1389 pt = (struct EncryptedMessage *) buf;
1407 1390
@@ -1480,7 +1463,8 @@ GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx,
1480 dmc.atsi_count = atsi_count; 1463 dmc.atsi_count = atsi_count;
1481 dmc.peer = &kx->peer; 1464 dmc.peer = &kx->peer;
1482 if (GNUNET_OK != 1465 if (GNUNET_OK !=
1483 GNUNET_SERVER_mst_receive (mst, &dmc, &buf[sizeof (struct EncryptedMessage)], 1466 GNUNET_SERVER_mst_receive (mst, &dmc,
1467 &buf[sizeof (struct EncryptedMessage)],
1484 size - sizeof (struct EncryptedMessage), 1468 size - sizeof (struct EncryptedMessage),
1485 GNUNET_YES, GNUNET_NO)) 1469 GNUNET_YES, GNUNET_NO))
1486 GNUNET_break_op (0); 1470 GNUNET_break_op (0);
@@ -1490,7 +1474,7 @@ GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx,
1490/** 1474/**
1491 * Deliver P2P message to interested clients. 1475 * Deliver P2P message to interested clients.
1492 * Invokes send twice, once for clients that want the full message, and once 1476 * Invokes send twice, once for clients that want the full message, and once
1493 * for clients that only want the header 1477 * for clients that only want the header
1494 * 1478 *
1495 * @param cls always NULL 1479 * @param cls always NULL
1496 * @param client who sent us the message (struct GSC_KeyExchangeInfo) 1480 * @param client who sent us the message (struct GSC_KeyExchangeInfo)
@@ -1505,20 +1489,15 @@ deliver_message (void *cls, void *client, const struct GNUNET_MessageHeader *m)
1505 { 1489 {
1506 case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP: 1490 case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP:
1507 case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP: 1491 case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP:
1508 GSC_SESSIONS_set_typemap (dmc->peer, 1492 GSC_SESSIONS_set_typemap (dmc->peer, m);
1509 m);
1510 return; 1493 return;
1511 default: 1494 default:
1512 GSC_CLIENTS_deliver_message (dmc->peer, 1495 GSC_CLIENTS_deliver_message (dmc->peer, dmc->atsi, dmc->atsi_count, m,
1513 dmc->atsi, dmc->atsi_count, 1496 ntohs (m->size),
1514 m, 1497 GNUNET_CORE_OPTION_SEND_FULL_INBOUND);
1515 ntohs (m->size), 1498 GSC_CLIENTS_deliver_message (dmc->peer, dmc->atsi, dmc->atsi_count, m,
1516 GNUNET_CORE_OPTION_SEND_FULL_INBOUND); 1499 sizeof (struct GNUNET_MessageHeader),
1517 GSC_CLIENTS_deliver_message (dmc->peer, 1500 GNUNET_CORE_OPTION_SEND_HDR_INBOUND);
1518 dmc->atsi, dmc->atsi_count,
1519 m,
1520 sizeof (struct GNUNET_MessageHeader),
1521 GNUNET_CORE_OPTION_SEND_HDR_INBOUND);
1522 } 1501 }
1523} 1502}
1524 1503
@@ -1528,17 +1507,18 @@ deliver_message (void *cls, void *client, const struct GNUNET_MessageHeader *m)
1528 * 1507 *
1529 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 1508 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
1530 */ 1509 */
1531int 1510int
1532GSC_KX_init () 1511GSC_KX_init ()
1533{ 1512{
1534 char *keyfile; 1513 char *keyfile;
1535 1514
1536 if (GNUNET_OK != 1515 if (GNUNET_OK !=
1537 GNUNET_CONFIGURATION_get_value_filename (GSC_cfg, "GNUNETD", "HOSTKEY", 1516 GNUNET_CONFIGURATION_get_value_filename (GSC_cfg, "GNUNETD", "HOSTKEY",
1538 &keyfile)) 1517 &keyfile))
1539 { 1518 {
1540 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1519 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1541 _("Core service is lacking HOSTKEY configuration setting. Exiting.\n")); 1520 _
1521 ("Core service is lacking HOSTKEY configuration setting. Exiting.\n"));
1542 return GNUNET_SYSERR; 1522 return GNUNET_SYSERR;
1543 } 1523 }
1544 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); 1524 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
@@ -1569,7 +1549,7 @@ GSC_KX_init ()
1569/** 1549/**
1570 * Shutdown KX subsystem. 1550 * Shutdown KX subsystem.
1571 */ 1551 */
1572void 1552void
1573GSC_KX_done () 1553GSC_KX_done ()
1574{ 1554{
1575 if (my_private_key != NULL) 1555 if (my_private_key != NULL)
diff --git a/src/core/gnunet-service-core_kx.h b/src/core/gnunet-service-core_kx.h
index 0e963ef7a..5ecd2c17f 100644
--- a/src/core/gnunet-service-core_kx.h
+++ b/src/core/gnunet-service-core_kx.h
@@ -44,8 +44,8 @@ struct GSC_KeyExchangeInfo;
44 * @param msg the set key message we received 44 * @param msg the set key message we received
45 */ 45 */
46void 46void
47GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, 47GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx,
48 const struct GNUNET_MessageHeader *msg); 48 const struct GNUNET_MessageHeader *msg);
49 49
50 50
51/** 51/**
@@ -56,8 +56,8 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx,
56 * @param msg the encrypted PING message itself 56 * @param msg the encrypted PING message itself
57 */ 57 */
58void 58void
59GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx, 59GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx,
60 const struct GNUNET_MessageHeader *msg); 60 const struct GNUNET_MessageHeader *msg);
61 61
62 62
63/** 63/**
@@ -68,7 +68,7 @@ GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx,
68 */ 68 */
69void 69void
70GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, 70GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx,
71 const struct GNUNET_MessageHeader *msg); 71 const struct GNUNET_MessageHeader *msg);
72 72
73 73
74/** 74/**
@@ -80,8 +80,7 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx,
80 */ 80 */
81void 81void
82GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, 82GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx,
83 const void *payload, 83 const void *payload, size_t payload_size);
84 size_t payload_size);
85 84
86 85
87/** 86/**
@@ -94,10 +93,10 @@ GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx,
94 * @param atsi_count number of entries in ats (excluding 0-termination) 93 * @param atsi_count number of entries in ats (excluding 0-termination)
95 */ 94 */
96void 95void
97GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx, 96GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx,
98 const struct GNUNET_MessageHeader *msg, 97 const struct GNUNET_MessageHeader *msg,
99 const struct GNUNET_ATS_Information *atsi, 98 const struct GNUNET_ATS_Information *atsi,
100 uint32_t atsi_count); 99 uint32_t atsi_count);
101 100
102 101
103/** 102/**
@@ -124,14 +123,14 @@ GSC_KX_stop (struct GSC_KeyExchangeInfo *kx);
124 * 123 *
125 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 124 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
126 */ 125 */
127int 126int
128GSC_KX_init (void); 127GSC_KX_init (void);
129 128
130 129
131/** 130/**
132 * Shutdown KX subsystem. 131 * Shutdown KX subsystem.
133 */ 132 */
134void 133void
135GSC_KX_done (void); 134GSC_KX_done (void);
136 135
137#endif 136#endif
diff --git a/src/core/gnunet-service-core_neighbours.c b/src/core/gnunet-service-core_neighbours.c
index d7ce91a88..5014298bf 100644
--- a/src/core/gnunet-service-core_neighbours.c
+++ b/src/core/gnunet-service-core_neighbours.c
@@ -158,10 +158,10 @@ free_neighbour (struct Neighbour *n)
158 GNUNET_TRANSPORT_notify_transmit_ready_cancel (n->th); 158 GNUNET_TRANSPORT_notify_transmit_ready_cancel (n->th);
159 n->th = NULL; 159 n->th = NULL;
160 } 160 }
161 GNUNET_STATISTICS_update (GSC_stats, 161 GNUNET_STATISTICS_update (GSC_stats,
162 gettext_noop ("# sessions terminated by transport disconnect"), 162 gettext_noop
163 1, 163 ("# sessions terminated by transport disconnect"),
164 GNUNET_NO); 164 1, GNUNET_NO);
165 GSC_SESSIONS_end (&n->peer); 165 GSC_SESSIONS_end (&n->peer);
166 if (NULL != n->kxinfo) 166 if (NULL != n->kxinfo)
167 { 167 {
@@ -175,8 +175,9 @@ free_neighbour (struct Neighbour *n)
175 } 175 }
176 GNUNET_assert (GNUNET_OK == 176 GNUNET_assert (GNUNET_OK ==
177 GNUNET_CONTAINER_multihashmap_remove (neighbours, 177 GNUNET_CONTAINER_multihashmap_remove (neighbours,
178 &n->peer.hashPubKey, n)); 178 &n->peer.hashPubKey, n));
179 GNUNET_STATISTICS_set (GSC_stats, gettext_noop ("# neighbour entries allocated"), 179 GNUNET_STATISTICS_set (GSC_stats,
180 gettext_noop ("# neighbour entries allocated"),
180 GNUNET_CONTAINER_multihashmap_size (neighbours), 181 GNUNET_CONTAINER_multihashmap_size (neighbours),
181 GNUNET_NO); 182 GNUNET_NO);
182 GNUNET_free (n); 183 GNUNET_free (n);
@@ -239,10 +240,10 @@ transmit_ready (void *cls, size_t size, void *buf)
239 ret = m->size; 240 ret = m->size;
240#if DEBUG_CORE 241#if DEBUG_CORE
241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
242 "Copied message of type %u and size %u into transport buffer for `%4s'\n", 243 "Copied message of type %u and size %u into transport buffer for `%4s'\n",
243 (unsigned int) 244 (unsigned int)
244 ntohs (((struct GNUNET_MessageHeader *) &m[1])->type), 245 ntohs (((struct GNUNET_MessageHeader *) &m[1])->type),
245 (unsigned int) ret, GNUNET_i2s (&n->peer)); 246 (unsigned int) ret, GNUNET_i2s (&n->peer));
246#endif 247#endif
247 GNUNET_free (m); 248 GNUNET_free (m);
248 process_queue (n); 249 process_queue (n);
@@ -271,7 +272,7 @@ process_queue (struct Neighbour *n)
271 if (m == NULL) 272 if (m == NULL)
272 { 273 {
273 /* notify sessions that the queue is empty and more messages 274 /* notify sessions that the queue is empty and more messages
274 could thus be queued now */ 275 * could thus be queued now */
275 GSC_SESSIONS_solicit (&n->peer); 276 GSC_SESSIONS_solicit (&n->peer);
276 return; 277 return;
277 } 278 }
@@ -283,12 +284,10 @@ process_queue (struct Neighbour *n)
283 GNUNET_TIME_absolute_get_remaining (m->deadline).rel_value); 284 GNUNET_TIME_absolute_get_remaining (m->deadline).rel_value);
284#endif 285#endif
285 n->th = 286 n->th =
286 GNUNET_TRANSPORT_notify_transmit_ready (transport, &n->peer, m->size, 287 GNUNET_TRANSPORT_notify_transmit_ready (transport, &n->peer, m->size, 0,
287 0, 288 GNUNET_TIME_absolute_get_remaining
288 GNUNET_TIME_absolute_get_remaining 289 (m->deadline), &transmit_ready,
289 (m->deadline), 290 n);
290 &transmit_ready,
291 n);
292 if (n->th != NULL) 291 if (n->th != NULL)
293 return; 292 return;
294 /* message request too large or duplicate request */ 293 /* message request too large or duplicate request */
@@ -313,8 +312,8 @@ process_queue (struct Neighbour *n)
313static void 312static void
314handle_transport_notify_connect (void *cls, 313handle_transport_notify_connect (void *cls,
315 const struct GNUNET_PeerIdentity *peer, 314 const struct GNUNET_PeerIdentity *peer,
316 const struct GNUNET_ATS_Information 315 const struct GNUNET_ATS_Information *atsi,
317 *atsi, uint32_t atsi_count) 316 uint32_t atsi_count)
318{ 317{
319 struct Neighbour *n; 318 struct Neighbour *n;
320 319
@@ -340,7 +339,8 @@ handle_transport_notify_connect (void *cls,
340 GNUNET_CONTAINER_multihashmap_put (neighbours, 339 GNUNET_CONTAINER_multihashmap_put (neighbours,
341 &n->peer.hashPubKey, n, 340 &n->peer.hashPubKey, n,
342 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 341 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
343 GNUNET_STATISTICS_set (GSC_stats, gettext_noop ("# neighbour entries allocated"), 342 GNUNET_STATISTICS_set (GSC_stats,
343 gettext_noop ("# neighbour entries allocated"),
344 GNUNET_CONTAINER_multihashmap_size (neighbours), 344 GNUNET_CONTAINER_multihashmap_size (neighbours),
345 GNUNET_NO); 345 GNUNET_NO);
346 n->kxinfo = GSC_KX_start (peer); 346 n->kxinfo = GSC_KX_start (peer);
@@ -423,9 +423,7 @@ handle_transport_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
423 GSC_KX_handle_pong (n->kxinfo, message); 423 GSC_KX_handle_pong (n->kxinfo, message);
424 break; 424 break;
425 case GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE: 425 case GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE:
426 GSC_KX_handle_encrypted_message (n->kxinfo, 426 GSC_KX_handle_encrypted_message (n->kxinfo, message, atsi, atsi_count);
427 message, atsi,
428 atsi_count);
429 break; 427 break;
430 default: 428 default:
431 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 429 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -438,15 +436,15 @@ handle_transport_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
438 436
439/** 437/**
440 * Transmit the given message to the given target. 438 * Transmit the given message to the given target.
441 * 439 *
442 * @param target peer that should receive the message (must be connected) 440 * @param target peer that should receive the message (must be connected)
443 * @param msg message to transmit 441 * @param msg message to transmit
444 * @param timeout by when should the transmission be done? 442 * @param timeout by when should the transmission be done?
445 */ 443 */
446void 444void
447GSC_NEIGHBOURS_transmit (const struct GNUNET_PeerIdentity *target, 445GSC_NEIGHBOURS_transmit (const struct GNUNET_PeerIdentity *target,
448 const struct GNUNET_MessageHeader *msg, 446 const struct GNUNET_MessageHeader *msg,
449 struct GNUNET_TIME_Relative timeout) 447 struct GNUNET_TIME_Relative timeout)
450{ 448{
451 struct NeighbourMessageEntry *me; 449 struct NeighbourMessageEntry *me;
452 struct Neighbour *n; 450 struct Neighbour *n;
@@ -463,9 +461,7 @@ GSC_NEIGHBOURS_transmit (const struct GNUNET_PeerIdentity *target,
463 me->deadline = GNUNET_TIME_relative_to_absolute (timeout); 461 me->deadline = GNUNET_TIME_relative_to_absolute (timeout);
464 me->size = msize; 462 me->size = msize;
465 memcpy (&me[1], msg, msize); 463 memcpy (&me[1], msg, msize);
466 GNUNET_CONTAINER_DLL_insert_tail (n->message_head, 464 GNUNET_CONTAINER_DLL_insert_tail (n->message_head, n->message_tail, me);
467 n->message_tail,
468 me);
469 process_queue (n); 465 process_queue (n);
470} 466}
471 467
@@ -478,8 +474,7 @@ GSC_NEIGHBOURS_init ()
478{ 474{
479 neighbours = GNUNET_CONTAINER_multihashmap_create (128); 475 neighbours = GNUNET_CONTAINER_multihashmap_create (128);
480 transport = 476 transport =
481 GNUNET_TRANSPORT_connect (GSC_cfg, 477 GNUNET_TRANSPORT_connect (GSC_cfg, &GSC_my_identity, NULL,
482 &GSC_my_identity, NULL,
483 &handle_transport_receive, 478 &handle_transport_receive,
484 &handle_transport_notify_connect, 479 &handle_transport_notify_connect,
485 &handle_transport_notify_disconnect); 480 &handle_transport_notify_disconnect);
@@ -530,4 +525,3 @@ GSC_NEIGHBOURS_done ()
530} 525}
531 526
532/* end of gnunet-service-core_neighbours.c */ 527/* end of gnunet-service-core_neighbours.c */
533
diff --git a/src/core/gnunet-service-core_neighbours.h b/src/core/gnunet-service-core_neighbours.h
index 36682770e..d613c46a5 100644
--- a/src/core/gnunet-service-core_neighbours.h
+++ b/src/core/gnunet-service-core_neighbours.h
@@ -35,15 +35,15 @@
35 * when the message queue is empty). Outbound quotas and memory 35 * when the message queue is empty). Outbound quotas and memory
36 * bounds will then be enfoced (as GSC_SESSION_solicit is only called 36 * bounds will then be enfoced (as GSC_SESSION_solicit is only called
37 * if sufficient banwdith is available). 37 * if sufficient banwdith is available).
38 * 38 *
39 * @param target peer that should receive the message (must be connected) 39 * @param target peer that should receive the message (must be connected)
40 * @param msg message to transmit 40 * @param msg message to transmit
41 * @param timeout by when should the transmission be done? 41 * @param timeout by when should the transmission be done?
42 */ 42 */
43void 43void
44GSC_NEIGHBOURS_transmit (const struct GNUNET_PeerIdentity *target, 44GSC_NEIGHBOURS_transmit (const struct GNUNET_PeerIdentity *target,
45 const struct GNUNET_MessageHeader *msg, 45 const struct GNUNET_MessageHeader *msg,
46 struct GNUNET_TIME_Relative timeout); 46 struct GNUNET_TIME_Relative timeout);
47 47
48 48
49/** 49/**
diff --git a/src/core/gnunet-service-core_sessions.c b/src/core/gnunet-service-core_sessions.c
index a8f7bf6bf..108fd47cf 100644
--- a/src/core/gnunet-service-core_sessions.c
+++ b/src/core/gnunet-service-core_sessions.c
@@ -20,7 +20,7 @@
20 20
21/** 21/**
22 * @file core/gnunet-service-core_sessions.c 22 * @file core/gnunet-service-core_sessions.c
23 * @brief code for managing of 'encrypted' sessions (key exchange done) 23 * @brief code for managing of 'encrypted' sessions (key exchange done)
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
@@ -133,7 +133,7 @@ struct Session
133 133
134 /** 134 /**
135 * Is the neighbour queue empty and thus ready for us 135 * Is the neighbour queue empty and thus ready for us
136 * to transmit an encrypted message? 136 * to transmit an encrypted message?
137 */ 137 */
138 int ready_to_transmit; 138 int ready_to_transmit;
139 139
@@ -162,7 +162,7 @@ find_session (const struct GNUNET_PeerIdentity *peer)
162 162
163/** 163/**
164 * End the session with the given peer (we are no longer 164 * End the session with the given peer (we are no longer
165 * connected). 165 * connected).
166 * 166 *
167 * @param pid identity of peer to kill session with 167 * @param pid identity of peer to kill session with
168 */ 168 */
@@ -176,8 +176,7 @@ GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid)
176 if (NULL == session) 176 if (NULL == session)
177 return; 177 return;
178#if DEBUG_CORE 178#if DEBUG_CORE
179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying session for peer `%4s'\n",
180 "Destroying session for peer `%4s'\n",
181 GNUNET_i2s (&session->peer)); 180 GNUNET_i2s (&session->peer));
182#endif 181#endif
183 if (GNUNET_SCHEDULER_NO_TASK != session->cork_task) 182 if (GNUNET_SCHEDULER_NO_TASK != session->cork_task)
@@ -188,22 +187,21 @@ GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid)
188 while (NULL != (car = session->active_client_request_head)) 187 while (NULL != (car = session->active_client_request_head))
189 { 188 {
190 GNUNET_CONTAINER_DLL_remove (session->active_client_request_head, 189 GNUNET_CONTAINER_DLL_remove (session->active_client_request_head,
191 session->active_client_request_tail, 190 session->active_client_request_tail, car);
192 car);
193 GSC_CLIENTS_reject_request (car); 191 GSC_CLIENTS_reject_request (car);
194 } 192 }
195 GNUNET_SCHEDULER_cancel (session->typemap_task); 193 GNUNET_SCHEDULER_cancel (session->typemap_task);
196 GSC_CLIENTS_notify_clients_about_neighbour (&session->peer, 194 GSC_CLIENTS_notify_clients_about_neighbour (&session->peer, NULL,
197 NULL, 0 /* FIXME: ATSI */, 195 0 /* FIXME: ATSI */ ,
198 session->tmap, 196 session->tmap, NULL);
199 NULL);
200 GNUNET_assert (GNUNET_YES == 197 GNUNET_assert (GNUNET_YES ==
201 GNUNET_CONTAINER_multihashmap_remove (sessions, 198 GNUNET_CONTAINER_multihashmap_remove (sessions,
202 &session->peer.hashPubKey, session)); 199 &session->
203 GNUNET_STATISTICS_set (GSC_stats, 200 peer.hashPubKey,
204 gettext_noop ("# entries in session map"), 201 session));
205 GNUNET_CONTAINER_multihashmap_size (sessions), 202 GNUNET_STATISTICS_set (GSC_stats, gettext_noop ("# entries in session map"),
206 GNUNET_NO); 203 GNUNET_CONTAINER_multihashmap_size (sessions),
204 GNUNET_NO);
207 GSC_TYPEMAP_destroy (session->tmap); 205 GSC_TYPEMAP_destroy (session->tmap);
208 session->tmap = NULL; 206 session->tmap = NULL;
209 GNUNET_free (session); 207 GNUNET_free (session);
@@ -216,10 +214,9 @@ GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid)
216 * 214 *
217 * @param cls the 'struct Session*' 215 * @param cls the 'struct Session*'
218 * @param tc unused 216 * @param tc unused
219 */ 217 */
220static void 218static void
221transmit_typemap_task (void *cls, 219transmit_typemap_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
222 const struct GNUNET_SCHEDULER_TaskContext *tc)
223{ 220{
224 struct Session *session = cls; 221 struct Session *session = cls;
225 struct GNUNET_MessageHeader *hdr; 222 struct GNUNET_MessageHeader *hdr;
@@ -227,19 +224,15 @@ transmit_typemap_task (void *cls,
227 224
228 delay = TYPEMAP_FREQUENCY; 225 delay = TYPEMAP_FREQUENCY;
229 /* randomize a bit to avoid spont. sync */ 226 /* randomize a bit to avoid spont. sync */
230 delay.rel_value += GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 227 delay.rel_value +=
231 1000); 228 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000);
232 session->typemap_task = GNUNET_SCHEDULER_add_delayed (delay, 229 session->typemap_task =
233 &transmit_typemap_task, 230 GNUNET_SCHEDULER_add_delayed (delay, &transmit_typemap_task, session);
234 session); 231 GNUNET_STATISTICS_update (GSC_stats,
235 GNUNET_STATISTICS_update (GSC_stats, 232 gettext_noop ("# type map refreshes sent"), 1,
236 gettext_noop ("# type map refreshes sent"), 233 GNUNET_NO);
237 1,
238 GNUNET_NO);
239 hdr = GSC_TYPEMAP_compute_type_map_message (); 234 hdr = GSC_TYPEMAP_compute_type_map_message ();
240 GSC_KX_encrypt_and_transmit (session->kxinfo, 235 GSC_KX_encrypt_and_transmit (session->kxinfo, hdr, ntohs (hdr->size));
241 hdr,
242 ntohs (hdr->size));
243 GNUNET_free (hdr); 236 GNUNET_free (hdr);
244} 237}
245 238
@@ -252,33 +245,30 @@ transmit_typemap_task (void *cls,
252 */ 245 */
253void 246void
254GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer, 247GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer,
255 struct GSC_KeyExchangeInfo *kx) 248 struct GSC_KeyExchangeInfo *kx)
256{ 249{
257 struct Session *session; 250 struct Session *session;
258 251
259#if DEBUG_CORE 252#if DEBUG_CORE
260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating session for peer `%4s'\n",
261 "Creating session for peer `%4s'\n", GNUNET_i2s (peer)); 254 GNUNET_i2s (peer));
262#endif 255#endif
263 session = GNUNET_malloc (sizeof (struct Session)); 256 session = GNUNET_malloc (sizeof (struct Session));
264 session->tmap = GSC_TYPEMAP_create (); 257 session->tmap = GSC_TYPEMAP_create ();
265 session->peer = *peer; 258 session->peer = *peer;
266 session->kxinfo = kx; 259 session->kxinfo = kx;
267 session->time_established = GNUNET_TIME_absolute_get (); 260 session->time_established = GNUNET_TIME_absolute_get ();
268 session->typemap_task = GNUNET_SCHEDULER_add_now (&transmit_typemap_task, 261 session->typemap_task =
269 session); 262 GNUNET_SCHEDULER_add_now (&transmit_typemap_task, session);
270 GNUNET_assert (GNUNET_OK == 263 GNUNET_assert (GNUNET_OK ==
271 GNUNET_CONTAINER_multihashmap_put (sessions, 264 GNUNET_CONTAINER_multihashmap_put (sessions, &peer->hashPubKey,
272 &peer->hashPubKey, session, 265 session,
273 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 266 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
274 GNUNET_STATISTICS_set (GSC_stats, 267 GNUNET_STATISTICS_set (GSC_stats, gettext_noop ("# entries in session map"),
275 gettext_noop ("# entries in session map"), 268 GNUNET_CONTAINER_multihashmap_size (sessions),
276 GNUNET_CONTAINER_multihashmap_size (sessions), 269 GNUNET_NO);
277 GNUNET_NO); 270 GSC_CLIENTS_notify_clients_about_neighbour (peer, NULL, 0 /* FIXME: ATSI */ ,
278 GSC_CLIENTS_notify_clients_about_neighbour (peer, 271 NULL, session->tmap);
279 NULL, 0 /* FIXME: ATSI */,
280 NULL,
281 session->tmap);
282} 272}
283 273
284 274
@@ -286,23 +276,20 @@ GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer,
286 * Notify the given client about the session (client is new). 276 * Notify the given client about the session (client is new).
287 * 277 *
288 * @param cls the 'struct GSC_Client' 278 * @param cls the 'struct GSC_Client'
289 * @param key peer identity 279 * @param key peer identity
290 * @param value the 'struct Session' 280 * @param value the 'struct Session'
291 * @return GNUNET_OK (continue to iterate) 281 * @return GNUNET_OK (continue to iterate)
292 */ 282 */
293static int 283static int
294notify_client_about_session (void *cls, 284notify_client_about_session (void *cls, const GNUNET_HashCode * key,
295 const GNUNET_HashCode *key, 285 void *value)
296 void *value)
297{ 286{
298 struct GSC_Client *client = cls; 287 struct GSC_Client *client = cls;
299 struct Session *session = value; 288 struct Session *session = value;
300 289
301 GSC_CLIENTS_notify_client_about_neighbour (client, 290 GSC_CLIENTS_notify_client_about_neighbour (client, &session->peer, NULL, 0, /* FIXME: ATS!? */
302 &session->peer, 291 NULL, /* old TMAP: none */
303 NULL, 0, /* FIXME: ATS!? */ 292 session->tmap);
304 NULL, /* old TMAP: none */
305 session->tmap);
306 return GNUNET_OK; 293 return GNUNET_OK;
307} 294}
308 295
@@ -316,8 +303,8 @@ void
316GSC_SESSIONS_notify_client_about_sessions (struct GSC_Client *client) 303GSC_SESSIONS_notify_client_about_sessions (struct GSC_Client *client)
317{ 304{
318 /* notify new client about existing sessions */ 305 /* notify new client about existing sessions */
319 GNUNET_CONTAINER_multihashmap_iterate (sessions, 306 GNUNET_CONTAINER_multihashmap_iterate (sessions, &notify_client_about_session,
320 &notify_client_about_session, client); 307 client);
321} 308}
322 309
323 310
@@ -373,7 +360,7 @@ GSC_SESSIONS_queue_request (struct GSC_ClientActiveRequest *car)
373 "Received client transmission request. queueing\n"); 360 "Received client transmission request. queueing\n");
374#endif 361#endif
375 GNUNET_CONTAINER_DLL_insert (session->active_client_request_head, 362 GNUNET_CONTAINER_DLL_insert (session->active_client_request_head,
376 session->active_client_request_tail, car); 363 session->active_client_request_tail, car);
377 try_transmission (session); 364 try_transmission (session);
378} 365}
379 366
@@ -389,11 +376,11 @@ GSC_SESSIONS_dequeue_request (struct GSC_ClientActiveRequest *car)
389{ 376{
390 struct Session *s; 377 struct Session *s;
391 378
392 if (0 == memcmp (&car->target, 379 if (0 ==
393 &GSC_my_identity, 380 memcmp (&car->target, &GSC_my_identity,
394 sizeof (struct GNUNET_PeerIdentity))) 381 sizeof (struct GNUNET_PeerIdentity)))
395 return; 382 return;
396 s = find_session (&car->target); 383 s = find_session (&car->target);
397 GNUNET_assert (NULL != s); 384 GNUNET_assert (NULL != s);
398 GNUNET_CONTAINER_DLL_remove (s->active_client_request_head, 385 GNUNET_CONTAINER_DLL_remove (s->active_client_request_head,
399 s->active_client_request_tail, car); 386 s->active_client_request_tail, car);
@@ -411,7 +398,7 @@ discard_expired_requests (struct Session *session)
411 struct GSC_ClientActiveRequest *pos; 398 struct GSC_ClientActiveRequest *pos;
412 struct GSC_ClientActiveRequest *nxt; 399 struct GSC_ClientActiveRequest *nxt;
413 struct GNUNET_TIME_Absolute now; 400 struct GNUNET_TIME_Absolute now;
414 401
415 now = GNUNET_TIME_absolute_get (); 402 now = GNUNET_TIME_absolute_get ();
416 pos = NULL; 403 pos = NULL;
417 nxt = session->active_client_request_head; 404 nxt = session->active_client_request_head;
@@ -419,16 +406,15 @@ discard_expired_requests (struct Session *session)
419 { 406 {
420 pos = nxt; 407 pos = nxt;
421 nxt = pos->next; 408 nxt = pos->next;
422 if ( (pos->deadline.abs_value < now.abs_value) && 409 if ((pos->deadline.abs_value < now.abs_value) &&
423 (GNUNET_YES != pos->was_solicited) ) 410 (GNUNET_YES != pos->was_solicited))
424 { 411 {
425 GNUNET_STATISTICS_update (GSC_stats, 412 GNUNET_STATISTICS_update (GSC_stats,
426 gettext_noop 413 gettext_noop
427 ("# messages discarded (expired prior to transmission)"), 414 ("# messages discarded (expired prior to transmission)"),
428 1, GNUNET_NO); 415 1, GNUNET_NO);
429 GNUNET_CONTAINER_DLL_remove (session->active_client_request_head, 416 GNUNET_CONTAINER_DLL_remove (session->active_client_request_head,
430 session->active_client_request_tail, 417 session->active_client_request_tail, pos);
431 pos);
432 GSC_CLIENTS_reject_request (pos); 418 GSC_CLIENTS_reject_request (pos);
433 } 419 }
434 } 420 }
@@ -446,7 +432,7 @@ solicit_messages (struct Session *session)
446 struct GSC_ClientActiveRequest *car; 432 struct GSC_ClientActiveRequest *car;
447 size_t so_size; 433 size_t so_size;
448 434
449 discard_expired_requests (session); 435 discard_expired_requests (session);
450 so_size = 0; 436 so_size = 0;
451 for (car = session->active_client_request_head; NULL != car; car = car->next) 437 for (car = session->active_client_request_head; NULL != car; car = car->next)
452 { 438 {
@@ -462,15 +448,14 @@ solicit_messages (struct Session *session)
462 448
463 449
464/** 450/**
465 * Some messages were delayed (corked), but the timeout has now expired. 451 * Some messages were delayed (corked), but the timeout has now expired.
466 * Send them now. 452 * Send them now.
467 * 453 *
468 * @param cls 'struct Session' with the messages to transmit now 454 * @param cls 'struct Session' with the messages to transmit now
469 * @param tc scheduler context (unused) 455 * @param tc scheduler context (unused)
470 */ 456 */
471static void 457static void
472pop_cork_task (void *cls, 458pop_cork_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
473 const struct GNUNET_SCHEDULER_TaskContext *tc)
474{ 459{
475 struct Session *session = cls; 460 struct Session *session = cls;
476 461
@@ -499,31 +484,31 @@ try_transmission (struct Session *session)
499 min_deadline = GNUNET_TIME_UNIT_FOREVER_ABS; 484 min_deadline = GNUNET_TIME_UNIT_FOREVER_ABS;
500 /* check 'ready' messages */ 485 /* check 'ready' messages */
501 pos = session->sme_head; 486 pos = session->sme_head;
502 while ( (NULL != pos) && 487 while ((NULL != pos) &&
503 (msize + pos->size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) ) 488 (msize + pos->size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE))
504 { 489 {
505 GNUNET_assert (pos->size < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE); 490 GNUNET_assert (pos->size < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE);
506 msize += pos->size; 491 msize += pos->size;
507 min_deadline = GNUNET_TIME_absolute_min (min_deadline, 492 min_deadline = GNUNET_TIME_absolute_min (min_deadline, pos->deadline);
508 pos->deadline);
509 pos = pos->next; 493 pos = pos->next;
510 } 494 }
511 now = GNUNET_TIME_absolute_get (); 495 now = GNUNET_TIME_absolute_get ();
512 if ( (msize == 0) || 496 if ((msize == 0) ||
513 ( (msize < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE / 2) && 497 ((msize < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE / 2) &&
514 (min_deadline.abs_value > now.abs_value) ) ) 498 (min_deadline.abs_value > now.abs_value)))
515 { 499 {
516 /* not enough ready yet, try to solicit more */ 500 /* not enough ready yet, try to solicit more */
517 solicit_messages (session); 501 solicit_messages (session);
518 if (msize > 0) 502 if (msize > 0)
519 { 503 {
520 /* if there is data to send, just not yet, make sure we do transmit 504 /* if there is data to send, just not yet, make sure we do transmit
521 it once the deadline is reached */ 505 * it once the deadline is reached */
522 if (session->cork_task != GNUNET_SCHEDULER_NO_TASK) 506 if (session->cork_task != GNUNET_SCHEDULER_NO_TASK)
523 GNUNET_SCHEDULER_cancel (session->cork_task); 507 GNUNET_SCHEDULER_cancel (session->cork_task);
524 session->cork_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (min_deadline), 508 session->cork_task =
525 &pop_cork_task, 509 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
526 session); 510 (min_deadline), &pop_cork_task,
511 session);
527 } 512 }
528 return; 513 return;
529 } 514 }
@@ -531,18 +516,15 @@ try_transmission (struct Session *session)
531 { 516 {
532 static unsigned long long total_bytes; 517 static unsigned long long total_bytes;
533 static unsigned int total_msgs; 518 static unsigned int total_msgs;
534 char pbuf[msize]; /* plaintext */ 519 char pbuf[msize]; /* plaintext */
535 size_t used; 520 size_t used;
536 521
537 used = 0; 522 used = 0;
538 while ( (NULL != (pos = session->sme_head)) && 523 while ((NULL != (pos = session->sme_head)) && (used + pos->size <= msize))
539 (used + pos->size <= msize) )
540 { 524 {
541 memcpy (&pbuf[used], &pos[1], pos->size); 525 memcpy (&pbuf[used], &pos[1], pos->size);
542 used += pos->size; 526 used += pos->size;
543 GNUNET_CONTAINER_DLL_remove (session->sme_head, 527 GNUNET_CONTAINER_DLL_remove (session->sme_head, session->sme_tail, pos);
544 session->sme_tail,
545 pos);
546 GNUNET_free (pos); 528 GNUNET_free (pos);
547 } 529 }
548 /* compute average payload size */ 530 /* compute average payload size */
@@ -554,15 +536,11 @@ try_transmission (struct Session *session)
554 total_msgs = 1; 536 total_msgs = 1;
555 total_bytes = used; 537 total_bytes = used;
556 } 538 }
557 GNUNET_STATISTICS_set (GSC_stats, 539 GNUNET_STATISTICS_set (GSC_stats, "# avg payload per encrypted message",
558 "# avg payload per encrypted message", 540 total_bytes / total_msgs, GNUNET_NO);
559 total_bytes / total_msgs,
560 GNUNET_NO);
561 /* now actually transmit... */ 541 /* now actually transmit... */
562 session->ready_to_transmit = GNUNET_NO; 542 session->ready_to_transmit = GNUNET_NO;
563 GSC_KX_encrypt_and_transmit (session->kxinfo, 543 GSC_KX_encrypt_and_transmit (session->kxinfo, pbuf, used);
564 pbuf,
565 used);
566 } 544 }
567} 545}
568 546
@@ -587,9 +565,7 @@ do_send_message (void *cls, const GNUNET_HashCode * key, void *value)
587 m = GNUNET_malloc (sizeof (struct SessionMessageEntry) + size); 565 m = GNUNET_malloc (sizeof (struct SessionMessageEntry) + size);
588 memcpy (&m[1], hdr, size); 566 memcpy (&m[1], hdr, size);
589 m->size = size; 567 m->size = size;
590 GNUNET_CONTAINER_DLL_insert (session->sme_head, 568 GNUNET_CONTAINER_DLL_insert (session->sme_head, session->sme_tail, m);
591 session->sme_tail,
592 m);
593 try_transmission (session); 569 try_transmission (session);
594 return GNUNET_OK; 570 return GNUNET_OK;
595} 571}
@@ -605,8 +581,8 @@ GSC_SESSIONS_broadcast (const struct GNUNET_MessageHeader *msg)
605{ 581{
606 if (NULL == sessions) 582 if (NULL == sessions)
607 return; 583 return;
608 GNUNET_CONTAINER_multihashmap_iterate (sessions, 584 GNUNET_CONTAINER_multihashmap_iterate (sessions, &do_send_message,
609 &do_send_message, (void*) msg); 585 (void *) msg);
610} 586}
611 587
612 588
@@ -640,8 +616,7 @@ GSC_SESSIONS_solicit (const struct GNUNET_PeerIdentity *pid)
640 */ 616 */
641void 617void
642GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car, 618GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car,
643 const struct GNUNET_MessageHeader *msg, 619 const struct GNUNET_MessageHeader *msg, int cork)
644 int cork)
645{ 620{
646 struct Session *session; 621 struct Session *session;
647 struct SessionMessageEntry *sme; 622 struct SessionMessageEntry *sme;
@@ -655,10 +630,9 @@ GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car,
655 memcpy (&sme[1], msg, msize); 630 memcpy (&sme[1], msg, msize);
656 sme->size = msize; 631 sme->size = msize;
657 if (GNUNET_YES == cork) 632 if (GNUNET_YES == cork)
658 sme->deadline = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_MAX_CORK_DELAY); 633 sme->deadline =
659 GNUNET_CONTAINER_DLL_insert_tail (session->sme_head, 634 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_MAX_CORK_DELAY);
660 session->sme_tail, 635 GNUNET_CONTAINER_DLL_insert_tail (session->sme_head, session->sme_tail, sme);
661 sme);
662 try_transmission (session); 636 try_transmission (session);
663} 637}
664 638
@@ -678,7 +652,7 @@ queue_connect_message (void *cls, const GNUNET_HashCode * key, void *value)
678 struct GNUNET_SERVER_TransmitContext *tc = cls; 652 struct GNUNET_SERVER_TransmitContext *tc = cls;
679 struct Session *session = value; 653 struct Session *session = value;
680 struct ConnectNotifyMessage cnm; 654 struct ConnectNotifyMessage cnm;
681 655
682 /* FIXME: code duplication with clients... */ 656 /* FIXME: code duplication with clients... */
683 cnm.header.size = htons (sizeof (struct ConnectNotifyMessage)); 657 cnm.header.size = htons (sizeof (struct ConnectNotifyMessage));
684 cnm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); 658 cnm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
@@ -693,23 +667,23 @@ queue_connect_message (void *cls, const GNUNET_HashCode * key, void *value)
693/** 667/**
694 * Handle CORE_ITERATE_PEERS request. For this request type, the client 668 * Handle CORE_ITERATE_PEERS request. For this request type, the client
695 * does not have to have transmitted an INIT request. All current peers 669 * does not have to have transmitted an INIT request. All current peers
696 * are returned, regardless of which message types they accept. 670 * are returned, regardless of which message types they accept.
697 * 671 *
698 * @param cls unused 672 * @param cls unused
699 * @param client client sending the iteration request 673 * @param client client sending the iteration request
700 * @param message iteration request message 674 * @param message iteration request message
701 */ 675 */
702void 676void
703GSC_SESSIONS_handle_client_iterate_peers (void *cls, struct GNUNET_SERVER_Client *client, 677GSC_SESSIONS_handle_client_iterate_peers (void *cls,
704 const struct GNUNET_MessageHeader *message) 678 struct GNUNET_SERVER_Client *client,
679 const struct GNUNET_MessageHeader
680 *message)
705{ 681{
706 struct GNUNET_MessageHeader done_msg; 682 struct GNUNET_MessageHeader done_msg;
707 struct GNUNET_SERVER_TransmitContext *tc; 683 struct GNUNET_SERVER_TransmitContext *tc;
708 684
709 tc = GNUNET_SERVER_transmit_context_create (client); 685 tc = GNUNET_SERVER_transmit_context_create (client);
710 GNUNET_CONTAINER_multihashmap_iterate (sessions, 686 GNUNET_CONTAINER_multihashmap_iterate (sessions, &queue_connect_message, tc);
711 &queue_connect_message,
712 tc);
713 done_msg.size = htons (sizeof (struct GNUNET_MessageHeader)); 687 done_msg.size = htons (sizeof (struct GNUNET_MessageHeader));
714 done_msg.type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END); 688 done_msg.type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END);
715 GNUNET_SERVER_transmit_context_append_message (tc, &done_msg); 689 GNUNET_SERVER_transmit_context_append_message (tc, &done_msg);
@@ -728,14 +702,16 @@ GSC_SESSIONS_handle_client_iterate_peers (void *cls, struct GNUNET_SERVER_Client
728 * @param message iteration request message 702 * @param message iteration request message
729 */ 703 */
730void 704void
731GSC_SESSIONS_handle_client_have_peer (void *cls, struct GNUNET_SERVER_Client *client, 705GSC_SESSIONS_handle_client_have_peer (void *cls,
732 const struct GNUNET_MessageHeader *message) 706 struct GNUNET_SERVER_Client *client,
707 const struct GNUNET_MessageHeader
708 *message)
733{ 709{
734 struct GNUNET_MessageHeader done_msg; 710 struct GNUNET_MessageHeader done_msg;
735 struct GNUNET_SERVER_TransmitContext *tc; 711 struct GNUNET_SERVER_TransmitContext *tc;
736 const struct GNUNET_PeerIdentity *peer; 712 const struct GNUNET_PeerIdentity *peer;
737 713
738 peer = (const struct GNUNET_PeerIdentity *) &message[1]; // YUCK! 714 peer = (const struct GNUNET_PeerIdentity *) &message[1]; // YUCK!
739 tc = GNUNET_SERVER_transmit_context_create (client); 715 tc = GNUNET_SERVER_transmit_context_create (client);
740 GNUNET_CONTAINER_multihashmap_get_multiple (sessions, &peer->hashPubKey, 716 GNUNET_CONTAINER_multihashmap_get_multiple (sessions, &peer->hashPubKey,
741 &queue_connect_message, tc); 717 &queue_connect_message, tc);
@@ -755,24 +731,22 @@ GSC_SESSIONS_handle_client_have_peer (void *cls, struct GNUNET_SERVER_Client *cl
755 */ 731 */
756void 732void
757GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer, 733GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer,
758 const struct GNUNET_MessageHeader *msg) 734 const struct GNUNET_MessageHeader *msg)
759{ 735{
760 struct Session *session; 736 struct Session *session;
761 struct GSC_TypeMap *nmap; 737 struct GSC_TypeMap *nmap;
762 738
763 nmap = GSC_TYPEMAP_get_from_message (msg); 739 nmap = GSC_TYPEMAP_get_from_message (msg);
764 if (NULL == nmap) 740 if (NULL == nmap)
765 return; /* malformed */ 741 return; /* malformed */
766 session = find_session (peer); 742 session = find_session (peer);
767 if (NULL == session) 743 if (NULL == session)
768 { 744 {
769 GNUNET_break (0); 745 GNUNET_break (0);
770 return; 746 return;
771 } 747 }
772 GSC_CLIENTS_notify_clients_about_neighbour (peer, 748 GSC_CLIENTS_notify_clients_about_neighbour (peer, NULL, 0, /* FIXME: ATS */
773 NULL, 0, /* FIXME: ATS */ 749 session->tmap, nmap);
774 session->tmap,
775 nmap);
776 GSC_TYPEMAP_destroy (session->tmap); 750 GSC_TYPEMAP_destroy (session->tmap);
777 session->tmap = nmap; 751 session->tmap = nmap;
778} 752}
@@ -788,7 +762,7 @@ GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer,
788 */ 762 */
789void 763void
790GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer, 764GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer,
791 uint16_t type) 765 uint16_t type)
792{ 766{
793 struct Session *session; 767 struct Session *session;
794 struct GSC_TypeMap *nmap; 768 struct GSC_TypeMap *nmap;
@@ -797,16 +771,11 @@ GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer,
797 return; 771 return;
798 session = find_session (peer); 772 session = find_session (peer);
799 GNUNET_assert (NULL != session); 773 GNUNET_assert (NULL != session);
800 if (GNUNET_YES == 774 if (GNUNET_YES == GSC_TYPEMAP_test_match (session->tmap, &type, 1))
801 GSC_TYPEMAP_test_match (session->tmap, 775 return; /* already in it */
802 &type, 1)) 776 nmap = GSC_TYPEMAP_extend (session->tmap, &type, 1);
803 return; /* already in it */ 777 GSC_CLIENTS_notify_clients_about_neighbour (peer, NULL, 0, /* FIXME: ATS */
804 nmap = GSC_TYPEMAP_extend (session->tmap, 778 session->tmap, nmap);
805 &type, 1);
806 GSC_CLIENTS_notify_clients_about_neighbour (peer,
807 NULL, 0, /* FIXME: ATS */
808 session->tmap,
809 nmap);
810 GSC_TYPEMAP_destroy (session->tmap); 779 GSC_TYPEMAP_destroy (session->tmap);
811 session->tmap = nmap; 780 session->tmap = nmap;
812} 781}
@@ -846,12 +815,9 @@ free_session_helper (void *cls, const GNUNET_HashCode * key, void *value)
846void 815void
847GSC_SESSIONS_done () 816GSC_SESSIONS_done ()
848{ 817{
849 GNUNET_CONTAINER_multihashmap_iterate (sessions, 818 GNUNET_CONTAINER_multihashmap_iterate (sessions, &free_session_helper, NULL);
850 &free_session_helper,
851 NULL);
852 GNUNET_CONTAINER_multihashmap_destroy (sessions); 819 GNUNET_CONTAINER_multihashmap_destroy (sessions);
853 sessions = NULL; 820 sessions = NULL;
854} 821}
855 822
856/* end of gnunet-service-core_sessions.c */ 823/* end of gnunet-service-core_sessions.c */
857
diff --git a/src/core/gnunet-service-core_sessions.h b/src/core/gnunet-service-core_sessions.h
index b70bd59fd..e09cf500e 100644
--- a/src/core/gnunet-service-core_sessions.h
+++ b/src/core/gnunet-service-core_sessions.h
@@ -20,7 +20,7 @@
20 20
21/** 21/**
22 * @file core/gnunet-service-core_neighbours.h 22 * @file core/gnunet-service-core_neighbours.h
23 * @brief code for managing of 'encrypted' sessions (key exchange done) 23 * @brief code for managing of 'encrypted' sessions (key exchange done)
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26#ifndef GNUNET_SERVICE_CORE_SESSIONS_H 26#ifndef GNUNET_SERVICE_CORE_SESSIONS_H
@@ -38,12 +38,12 @@
38 */ 38 */
39void 39void
40GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer, 40GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer,
41 struct GSC_KeyExchangeInfo *kx); 41 struct GSC_KeyExchangeInfo *kx);
42 42
43 43
44/** 44/**
45 * End the session with the given peer (we are no longer 45 * End the session with the given peer (we are no longer
46 * connected). 46 * connected).
47 * 47 *
48 * @param pid identity of peer to kill session with 48 * @param pid identity of peer to kill session with
49 */ 49 */
@@ -95,8 +95,7 @@ GSC_SESSIONS_dequeue_request (struct GSC_ClientActiveRequest *car);
95 */ 95 */
96void 96void
97GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car, 97GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car,
98 const struct GNUNET_MessageHeader *msg, 98 const struct GNUNET_MessageHeader *msg, int cork);
99 int cork);
100 99
101 100
102/** 101/**
@@ -125,7 +124,7 @@ GSC_SESSIONS_notify_client_about_sessions (struct GSC_Client *client);
125 */ 124 */
126void 125void
127GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer, 126GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer,
128 const struct GNUNET_MessageHeader *msg); 127 const struct GNUNET_MessageHeader *msg);
129 128
130 129
131/** 130/**
@@ -138,7 +137,7 @@ GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer,
138 */ 137 */
139void 138void
140GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer, 139GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer,
141 uint16_t type); 140 uint16_t type);
142 141
143 142
144/** 143/**
@@ -151,8 +150,10 @@ GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer,
151 * @param message iteration request message 150 * @param message iteration request message
152 */ 151 */
153void 152void
154GSC_SESSIONS_handle_client_iterate_peers (void *cls, struct GNUNET_SERVER_Client *client, 153GSC_SESSIONS_handle_client_iterate_peers (void *cls,
155 const struct GNUNET_MessageHeader *message); 154 struct GNUNET_SERVER_Client *client,
155 const struct GNUNET_MessageHeader
156 *message);
156 157
157 158
158/** 159/**
@@ -166,8 +167,10 @@ GSC_SESSIONS_handle_client_iterate_peers (void *cls, struct GNUNET_SERVER_Client
166 * @param message iteration request message 167 * @param message iteration request message
167 */ 168 */
168void 169void
169GSC_SESSIONS_handle_client_have_peer (void *cls, struct GNUNET_SERVER_Client *client, 170GSC_SESSIONS_handle_client_have_peer (void *cls,
170 const struct GNUNET_MessageHeader *message); 171 struct GNUNET_SERVER_Client *client,
172 const struct GNUNET_MessageHeader
173 *message);
171 174
172 175
173 176
diff --git a/src/core/gnunet-service-core_typemap.c b/src/core/gnunet-service-core_typemap.c
index c54e446c6..d3214ea67 100644
--- a/src/core/gnunet-service-core_typemap.c
+++ b/src/core/gnunet-service-core_typemap.c
@@ -36,7 +36,7 @@
36 * A type map describing which messages a given neighbour is able 36 * A type map describing which messages a given neighbour is able
37 * to process. 37 * to process.
38 */ 38 */
39struct GSC_TypeMap 39struct GSC_TypeMap
40{ 40{
41 uint32_t bits[(UINT16_MAX + 1) / 32]; 41 uint32_t bits[(UINT16_MAX + 1) / 32];
42}; 42};
@@ -107,10 +107,8 @@ GSC_TYPEMAP_get_from_message (const struct GNUNET_MessageHeader *msg)
107 switch (ntohs (msg->type)) 107 switch (ntohs (msg->type))
108 { 108 {
109 case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP: 109 case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP:
110 GNUNET_STATISTICS_update (GSC_stats, 110 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# type maps received"),
111 gettext_noop ("# type maps received"), 111 1, GNUNET_NO);
112 1,
113 GNUNET_NO);
114 if (size != sizeof (struct GSC_TypeMap)) 112 if (size != sizeof (struct GSC_TypeMap))
115 { 113 {
116 GNUNET_break_op (0); 114 GNUNET_break_op (0);
@@ -120,16 +118,13 @@ GSC_TYPEMAP_get_from_message (const struct GNUNET_MessageHeader *msg)
120 memcpy (ret, &msg[1], sizeof (struct GSC_TypeMap)); 118 memcpy (ret, &msg[1], sizeof (struct GSC_TypeMap));
121 return ret; 119 return ret;
122 case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP: 120 case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP:
123 GNUNET_STATISTICS_update (GSC_stats, 121 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# type maps received"),
124 gettext_noop ("# type maps received"), 122 1, GNUNET_NO);
125 1,
126 GNUNET_NO);
127 ret = GNUNET_malloc (sizeof (struct GSC_TypeMap)); 123 ret = GNUNET_malloc (sizeof (struct GSC_TypeMap));
128 dlen = sizeof (struct GSC_TypeMap); 124 dlen = sizeof (struct GSC_TypeMap);
129 if ( (Z_OK != 125 if ((Z_OK !=
130 uncompress ((Bytef*) ret, &dlen, 126 uncompress ((Bytef *) ret, &dlen, (const Bytef *) &msg[1],
131 (const Bytef*) &msg[1], (uLong) size)) || 127 (uLong) size)) || (dlen != sizeof (struct GSC_TypeMap)))
132 (dlen != sizeof (struct GSC_TypeMap) ) )
133 { 128 {
134 GNUNET_break_op (0); 129 GNUNET_break_op (0);
135 GNUNET_free (ret); 130 GNUNET_free (ret);
@@ -152,10 +147,9 @@ broadcast_my_type_map ()
152 struct GNUNET_MessageHeader *hdr; 147 struct GNUNET_MessageHeader *hdr;
153 148
154 hdr = GSC_TYPEMAP_compute_type_map_message (); 149 hdr = GSC_TYPEMAP_compute_type_map_message ();
155 GNUNET_STATISTICS_update (GSC_stats, 150 GNUNET_STATISTICS_update (GSC_stats,
156 gettext_noop ("# updates to my type map"), 151 gettext_noop ("# updates to my type map"), 1,
157 1, 152 GNUNET_NO);
158 GNUNET_NO);
159 GSC_SESSIONS_broadcast (hdr); 153 GSC_SESSIONS_broadcast (hdr);
160 GNUNET_free (hdr); 154 GNUNET_free (hdr);
161} 155}
@@ -165,14 +159,13 @@ broadcast_my_type_map ()
165 * Add a set of types to our type map. 159 * Add a set of types to our type map.
166 */ 160 */
167void 161void
168GSC_TYPEMAP_add (const uint16_t *types, 162GSC_TYPEMAP_add (const uint16_t * types, unsigned int tlen)
169 unsigned int tlen)
170{ 163{
171 unsigned int i; 164 unsigned int i;
172 int changed; 165 int changed;
173 166
174 changed = GNUNET_NO; 167 changed = GNUNET_NO;
175 for (i=0;i<tlen;i++) 168 for (i = 0; i < tlen; i++)
176 { 169 {
177 if (0 == map_counters[types[i]]++) 170 if (0 == map_counters[types[i]]++)
178 { 171 {
@@ -189,14 +182,13 @@ GSC_TYPEMAP_add (const uint16_t *types,
189 * Remove a set of types from our type map. 182 * Remove a set of types from our type map.
190 */ 183 */
191void 184void
192GSC_TYPEMAP_remove (const uint16_t *types, 185GSC_TYPEMAP_remove (const uint16_t * types, unsigned int tlen)
193 unsigned int tlen)
194{ 186{
195 unsigned int i; 187 unsigned int i;
196 int changed; 188 int changed;
197 189
198 changed = GNUNET_NO; 190 changed = GNUNET_NO;
199 for (i=0;i<tlen;i++) 191 for (i = 0; i < tlen; i++)
200 { 192 {
201 if (0 == --map_counters[types[i]]) 193 if (0 == --map_counters[types[i]])
202 { 194 {
@@ -217,19 +209,18 @@ GSC_TYPEMAP_remove (const uint16_t *types,
217 * @param types array of types 209 * @param types array of types
218 * @param tcnt number of entries in types 210 * @param tcnt number of entries in types
219 * @return GNUNET_YES if a type is in the map, GNUNET_NO if not 211 * @return GNUNET_YES if a type is in the map, GNUNET_NO if not
220 */ 212 */
221int 213int
222GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap, 214GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap, const uint16_t * types,
223 const uint16_t *types, 215 unsigned int tcnt)
224 unsigned int tcnt) 216{
225{
226 unsigned int i; 217 unsigned int i;
227 218
228 if (NULL == tmap) 219 if (NULL == tmap)
229 return GNUNET_NO; 220 return GNUNET_NO;
230 if (0 == tcnt) 221 if (0 == tcnt)
231 return GNUNET_YES; /* matches all */ 222 return GNUNET_YES; /* matches all */
232 for (i=0;i<tcnt;i++) 223 for (i = 0; i < tcnt; i++)
233 if (0 != (tmap->bits[types[i] / 32] & (1 << (types[i] % 32)))) 224 if (0 != (tmap->bits[types[i] / 32] & (1 << (types[i] % 32))))
234 return GNUNET_YES; 225 return GNUNET_YES;
235 return GNUNET_NO; 226 return GNUNET_NO;
@@ -243,11 +234,10 @@ GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap,
243 * @param types array of types to add 234 * @param types array of types to add
244 * @param tcnt number of entries in types 235 * @param tcnt number of entries in types
245 * @return updated type map (fresh copy) 236 * @return updated type map (fresh copy)
246 */ 237 */
247struct GSC_TypeMap * 238struct GSC_TypeMap *
248GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap, 239GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap, const uint16_t * types,
249 const uint16_t *types, 240 unsigned int tcnt)
250 unsigned int tcnt)
251{ 241{
252 struct GSC_TypeMap *ret; 242 struct GSC_TypeMap *ret;
253 unsigned int i; 243 unsigned int i;
@@ -255,7 +245,7 @@ GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap,
255 ret = GNUNET_malloc (sizeof (struct GSC_TypeMap)); 245 ret = GNUNET_malloc (sizeof (struct GSC_TypeMap));
256 if (NULL != tmap) 246 if (NULL != tmap)
257 memcpy (ret, tmap, sizeof (struct GSC_TypeMap)); 247 memcpy (ret, tmap, sizeof (struct GSC_TypeMap));
258 for (i=0;i<tcnt;i++) 248 for (i = 0; i < tcnt; i++)
259 ret->bits[types[i] / 32] |= (1 << (types[i] % 32)); 249 ret->bits[types[i] / 32] |= (1 << (types[i] % 32));
260 return ret; 250 return ret;
261} 251}
diff --git a/src/core/gnunet-service-core_typemap.h b/src/core/gnunet-service-core_typemap.h
index d589c0b1c..ab106a161 100644
--- a/src/core/gnunet-service-core_typemap.h
+++ b/src/core/gnunet-service-core_typemap.h
@@ -39,16 +39,14 @@ struct GSC_TypeMap;
39 * Add a set of types to our type map. 39 * Add a set of types to our type map.
40 */ 40 */
41void 41void
42GSC_TYPEMAP_add (const uint16_t *types, 42GSC_TYPEMAP_add (const uint16_t * types, unsigned int tlen);
43 unsigned int tlen);
44 43
45 44
46/** 45/**
47 * Remove a set of types from our type map. 46 * Remove a set of types from our type map.
48 */ 47 */
49void 48void
50GSC_TYPEMAP_remove (const uint16_t *types, 49GSC_TYPEMAP_remove (const uint16_t * types, unsigned int tlen);
51 unsigned int tlen);
52 50
53 51
54/** 52/**
@@ -78,11 +76,10 @@ GSC_TYPEMAP_get_from_message (const struct GNUNET_MessageHeader *msg);
78 * @param types array of types 76 * @param types array of types
79 * @param tcnt number of entries in types 77 * @param tcnt number of entries in types
80 * @return GNUNET_YES if a type is in the map, GNUNET_NO if not 78 * @return GNUNET_YES if a type is in the map, GNUNET_NO if not
81 */ 79 */
82int 80int
83GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap, 81GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap, const uint16_t * types,
84 const uint16_t *types, 82 unsigned int tcnt);
85 unsigned int tcnt);
86 83
87 84
88/** 85/**
@@ -92,11 +89,10 @@ GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap,
92 * @param types array of types to add 89 * @param types array of types to add
93 * @param tcnt number of entries in types 90 * @param tcnt number of entries in types
94 * @return updated type map (fresh copy) 91 * @return updated type map (fresh copy)
95 */ 92 */
96struct GSC_TypeMap * 93struct GSC_TypeMap *
97GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap, 94GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap, const uint16_t * types,
98 const uint16_t *types, 95 unsigned int tcnt);
99 unsigned int tcnt);
100 96
101/** 97/**
102 * Create an empty type map. 98 * Create an empty type map.
diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c
index be3edf974..e63fc9f9d 100644
--- a/src/core/test_core_api.c
+++ b/src/core/test_core_api.c
@@ -76,7 +76,7 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message)
76 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 76 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
77 "Received (my) `%s' from transport service\n", "HELLO"); 77 "Received (my) `%s' from transport service\n", "HELLO");
78 GNUNET_assert (message != NULL); 78 GNUNET_assert (message != NULL);
79 if ((p == &p1) && (p2.th != NULL)) 79 if ((p == &p1) && (p2.th != NULL))
80 GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL); 80 GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL);
81 if ((p == &p2) && (p1.th != NULL)) 81 if ((p == &p2) && (p1.th != NULL))
82 GNUNET_TRANSPORT_offer_hello (p1.th, message, NULL, NULL); 82 GNUNET_TRANSPORT_offer_hello (p1.th, message, NULL, NULL);
@@ -165,7 +165,8 @@ transmit_ready (void *cls, size_t size, void *buf)
165 165
166static void 166static void
167connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, 167connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
168 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) 168 const struct GNUNET_ATS_Information *atsi,
169 unsigned int atsi_count)
169{ 170{
170 struct PeerContext *pc = cls; 171 struct PeerContext *pc = cls;
171 172
@@ -218,7 +219,8 @@ disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
218static int 219static int
219inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, 220inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
220 const struct GNUNET_MessageHeader *message, 221 const struct GNUNET_MessageHeader *message,
221 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) 222 const struct GNUNET_ATS_Information *atsi,
223 unsigned int atsi_count)
222{ 224{
223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
224 "Core provides inbound data from `%4s'.\n", GNUNET_i2s (other)); 226 "Core provides inbound data from `%4s'.\n", GNUNET_i2s (other));
@@ -229,7 +231,8 @@ inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
229static int 231static int
230outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, 232outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
231 const struct GNUNET_MessageHeader *message, 233 const struct GNUNET_MessageHeader *message,
232 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) 234 const struct GNUNET_ATS_Information *atsi,
235 unsigned int atsi_count)
233{ 236{
234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 237 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
235 "Core notifies about outbound data for `%4s'.\n", 238 "Core notifies about outbound data for `%4s'.\n",
@@ -242,7 +245,8 @@ outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
242static int 245static int
243process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer, 246process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
244 const struct GNUNET_MessageHeader *message, 247 const struct GNUNET_MessageHeader *message,
245 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) 248 const struct GNUNET_ATS_Information *atsi,
249 unsigned int atsi_count)
246{ 250{
247 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving message from `%4s'.\n", 251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving message from `%4s'.\n",
248 GNUNET_i2s (peer)); 252 GNUNET_i2s (peer));
@@ -296,9 +300,8 @@ init_notify (void *cls, struct GNUNET_CORE_Handle *server,
296 /* connect p2 */ 300 /* connect p2 */
297 p2.ch = 301 p2.ch =
298 GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify, 302 GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify,
299 &disconnect_notify, &inbound_notify, 303 &disconnect_notify, &inbound_notify, GNUNET_YES,
300 GNUNET_YES, &outbound_notify, GNUNET_YES, 304 &outbound_notify, GNUNET_YES, handlers);
301 handlers);
302 } 305 }
303 else 306 else
304 { 307 {
@@ -344,8 +347,8 @@ run (void *cls, char *const *args, const char *cfgfile,
344 &terminate_task_error, NULL); 347 &terminate_task_error, NULL);
345 p1.ch = 348 p1.ch =
346 GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify, 349 GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify,
347 &disconnect_notify, &inbound_notify, 350 &disconnect_notify, &inbound_notify, GNUNET_YES,
348 GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); 351 &outbound_notify, GNUNET_YES, handlers);
349} 352}
350 353
351 354
diff --git a/src/core/test_core_api_reliability.c b/src/core/test_core_api_reliability.c
index 6a764c126..b2079ba35 100644
--- a/src/core/test_core_api_reliability.c
+++ b/src/core/test_core_api_reliability.c
@@ -156,7 +156,7 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
156 GNUNET_CORE_disconnect (p2.ch); 156 GNUNET_CORE_disconnect (p2.ch);
157 p2.ch = NULL; 157 p2.ch = NULL;
158 } 158 }
159 if (connect_task != GNUNET_SCHEDULER_NO_TASK) 159 if (connect_task != GNUNET_SCHEDULER_NO_TASK)
160 GNUNET_SCHEDULER_cancel (connect_task); 160 GNUNET_SCHEDULER_cancel (connect_task);
161 if (p1.th != NULL) 161 if (p1.th != NULL)
162 { 162 {
@@ -177,8 +177,9 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
177static void 177static void
178try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 178try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
179{ 179{
180 connect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 180 connect_task =
181 &try_connect, NULL); 181 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect,
182 NULL);
182 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id); 183 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id);
183} 184}
184 185
@@ -239,7 +240,8 @@ transmit_ready (void *cls, size_t size, void *buf)
239 240
240static void 241static void
241connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, 242connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
242 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) 243 const struct GNUNET_ATS_Information *atsi,
244 unsigned int atsi_count)
243{ 245{
244 struct PeerContext *pc = cls; 246 struct PeerContext *pc = cls;
245 247
@@ -284,7 +286,8 @@ disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
284static int 286static int
285inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, 287inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
286 const struct GNUNET_MessageHeader *message, 288 const struct GNUNET_MessageHeader *message,
287 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) 289 const struct GNUNET_ATS_Information *atsi,
290 unsigned int atsi_count)
288{ 291{
289#if VERBOSE 292#if VERBOSE
290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -297,7 +300,8 @@ inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
297static int 300static int
298outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, 301outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
299 const struct GNUNET_MessageHeader *message, 302 const struct GNUNET_MessageHeader *message,
300 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) 303 const struct GNUNET_ATS_Information *atsi,
304 unsigned int atsi_count)
301{ 305{
302#if VERBOSE 306#if VERBOSE
303 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -314,7 +318,8 @@ transmit_ready (void *cls, size_t size, void *buf);
314static int 318static int
315process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer, 319process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
316 const struct GNUNET_MessageHeader *message, 320 const struct GNUNET_MessageHeader *message,
317 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) 321 const struct GNUNET_ATS_Information *atsi,
322 unsigned int atsi_count)
318{ 323{
319 static int n; 324 static int n;
320 unsigned int s; 325 unsigned int s;
diff --git a/src/core/test_core_api_send_to_self.c b/src/core/test_core_api_send_to_self.c
index cf9608ede..29b1f75f3 100644
--- a/src/core/test_core_api_send_to_self.c
+++ b/src/core/test_core_api_send_to_self.c
@@ -182,8 +182,8 @@ run (void *cls, char *const *args, const char *cfgfile,
182 "test_core_api_peer1.conf")); 182 "test_core_api_peer1.conf"));
183 183
184 core = 184 core =
185 GNUNET_CORE_connect (core_cfg, 42, NULL, &init, &connect_cb, NULL, 185 GNUNET_CORE_connect (core_cfg, 42, NULL, &init, &connect_cb, NULL, NULL,
186 NULL, 0, NULL, 0, handlers); 186 0, NULL, 0, handlers);
187 187
188 die_task = 188 die_task =
189 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 189 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
diff --git a/src/core/test_core_api_start_only.c b/src/core/test_core_api_start_only.c
index f27866c19..b06b97899 100644
--- a/src/core/test_core_api_start_only.c
+++ b/src/core/test_core_api_start_only.c
@@ -68,7 +68,7 @@ static int ok;
68static void 68static void
69connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, 69connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
70 const struct GNUNET_ATS_Information *atsi, 70 const struct GNUNET_ATS_Information *atsi,
71 unsigned int atsi_count) 71 unsigned int atsi_count)
72{ 72{
73} 73}
74 74
@@ -83,7 +83,7 @@ static int
83inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, 83inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
84 const struct GNUNET_MessageHeader *message, 84 const struct GNUNET_MessageHeader *message,
85 const struct GNUNET_ATS_Information *atsi, 85 const struct GNUNET_ATS_Information *atsi,
86 unsigned int atsi_count) 86 unsigned int atsi_count)
87{ 87{
88 return GNUNET_OK; 88 return GNUNET_OK;
89} 89}
@@ -93,7 +93,7 @@ static int
93outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, 93outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
94 const struct GNUNET_MessageHeader *message, 94 const struct GNUNET_MessageHeader *message,
95 const struct GNUNET_ATS_Information *atsi, 95 const struct GNUNET_ATS_Information *atsi,
96 unsigned int atsi_count) 96 unsigned int atsi_count)
97{ 97{
98 return GNUNET_OK; 98 return GNUNET_OK;
99} 99}
@@ -130,9 +130,8 @@ init_notify (void *cls, struct GNUNET_CORE_Handle *server,
130 /* connect p2 */ 130 /* connect p2 */
131 p2.ch = 131 p2.ch =
132 GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify, 132 GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify,
133 &disconnect_notify, &inbound_notify, 133 &disconnect_notify, &inbound_notify, GNUNET_YES,
134 GNUNET_YES, &outbound_notify, GNUNET_YES, 134 &outbound_notify, GNUNET_YES, handlers);
135 handlers);
136 } 135 }
137 else 136 else
138 { 137 {
@@ -193,8 +192,8 @@ run (void *cls, char *const *args, const char *cfgfile,
193 &timeout_task, NULL); 192 &timeout_task, NULL);
194 p1.ch = 193 p1.ch =
195 GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify, 194 GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify,
196 &disconnect_notify, &inbound_notify, 195 &disconnect_notify, &inbound_notify, GNUNET_YES,
197 GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); 196 &outbound_notify, GNUNET_YES, handlers);
198} 197}
199 198
200 199
diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c
index be875c235..856ed13fd 100644
--- a/src/core/test_core_quota_compliance.c
+++ b/src/core/test_core_quota_compliance.c
@@ -185,8 +185,9 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
185static void 185static void
186try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 186try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
187{ 187{
188 connect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 188 connect_task =
189 &try_connect, NULL); 189 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect,
190 NULL);
190 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id); 191 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id);
191 GNUNET_TRANSPORT_try_connect (p2.th, &p1.id); 192 GNUNET_TRANSPORT_try_connect (p2.th, &p1.id);
192} 193}
@@ -231,13 +232,11 @@ measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
231 232
232 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; 233 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value;
233 234
234 throughput_out = total_bytes_sent * 1000 / delta; /* convert to bytes/s */ 235 throughput_out = total_bytes_sent * 1000 / delta; /* convert to bytes/s */
235 throughput_in = total_bytes_recv * 1000 / delta; /* convert to bytes/s */ 236 throughput_in = total_bytes_recv * 1000 / delta; /* convert to bytes/s */
236 237
237 max_quota_in = GNUNET_MIN (current_quota_p1_in, 238 max_quota_in = GNUNET_MIN (current_quota_p1_in, current_quota_p2_in);
238 current_quota_p2_in); 239 max_quota_out = GNUNET_MIN (current_quota_p1_out, current_quota_p2_out);
239 max_quota_out = GNUNET_MIN (current_quota_p1_out,
240 current_quota_p2_out);
241 if (max_quota_out < max_quota_in) 240 if (max_quota_out < max_quota_in)
242 quota_delta = max_quota_in / 5; 241 quota_delta = max_quota_in / 5;
243 else 242 else
@@ -274,7 +273,7 @@ measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
274 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2); 273 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);
275 274
276 if (ok != 0) 275 if (ok != 0)
277 kind = GNUNET_ERROR_TYPE_ERROR; 276 kind = GNUNET_ERROR_TYPE_ERROR;
278 switch (test) 277 switch (test)
279 { 278 {
280 case SYMMETRIC: 279 case SYMMETRIC:
@@ -294,12 +293,10 @@ measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
294 }; 293 };
295 GNUNET_log (kind, "Peer 1 send rate: %llu b/s (%llu bytes in %llu ms)\n", 294 GNUNET_log (kind, "Peer 1 send rate: %llu b/s (%llu bytes in %llu ms)\n",
296 throughput_out, total_bytes_sent, delta); 295 throughput_out, total_bytes_sent, delta);
297 GNUNET_log (kind, "Peer 1 send quota: %llu b/s\n", 296 GNUNET_log (kind, "Peer 1 send quota: %llu b/s\n", current_quota_p1_out);
298 current_quota_p1_out);
299 GNUNET_log (kind, "Peer 2 receive rate: %llu b/s (%llu bytes in %llu ms)\n", 297 GNUNET_log (kind, "Peer 2 receive rate: %llu b/s (%llu bytes in %llu ms)\n",
300 throughput_in, total_bytes_recv, delta); 298 throughput_in, total_bytes_recv, delta);
301 GNUNET_log (kind, "Peer 2 receive quota: %llu b/s\n", 299 GNUNET_log (kind, "Peer 2 receive quota: %llu b/s\n", current_quota_p2_in);
302 current_quota_p2_in);
303/* 300/*
304 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound quota allowed: %llu b/s\n",max_quota_in ); 301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound quota allowed: %llu b/s\n",max_quota_in );
305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu b/s\n",max_quota_out); 302 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu b/s\n",max_quota_out);
@@ -322,10 +319,11 @@ transmit_ready (void *cls, size_t size, void *buf)
322 { 319 {
323 if ((p1.ch != NULL) && (p1.connect_status == 1)) 320 if ((p1.ch != NULL) && (p1.connect_status == 1))
324 GNUNET_break (NULL != 321 GNUNET_break (NULL !=
325 (p1.nth = GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0, 322 (p1.nth =
326 FAST_TIMEOUT, &p2.id, 323 GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0,
327 MESSAGESIZE, 324 FAST_TIMEOUT, &p2.id,
328 &transmit_ready, &p1))); 325 MESSAGESIZE,
326 &transmit_ready, &p1)));
329 return 0; 327 return 0;
330 } 328 }
331 GNUNET_assert (tr_n < TOTAL_MSGS); 329 GNUNET_assert (tr_n < TOTAL_MSGS);
@@ -364,12 +362,13 @@ transmit_ready (void *cls, size_t size, void *buf)
364 362
365static void 363static void
366connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, 364connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
367 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) 365 const struct GNUNET_ATS_Information *atsi,
366 unsigned int atsi_count)
368{ 367{
369 struct PeerContext *pc = cls; 368 struct PeerContext *pc = cls;
370 369
371 if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) 370 if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
372 return; /* loopback */ 371 return; /* loopback */
373 GNUNET_assert (pc->connect_status == 0); 372 GNUNET_assert (pc->connect_status == 0);
374 pc->connect_status = 1; 373 pc->connect_status = 1;
375 if (pc == &p1) 374 if (pc == &p1)
@@ -393,10 +392,11 @@ connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
393 NULL); 392 NULL);
394 393
395 GNUNET_break (NULL != 394 GNUNET_break (NULL !=
396 (p1.nth = GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0, 395 (p1.nth =
397 TIMEOUT, &p2.id, 396 GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0,
398 MESSAGESIZE, 397 TIMEOUT, &p2.id,
399 &transmit_ready, &p1))); 398 MESSAGESIZE,
399 &transmit_ready, &p1)));
400 } 400 }
401} 401}
402 402
@@ -407,12 +407,12 @@ disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
407 struct PeerContext *pc = cls; 407 struct PeerContext *pc = cls;
408 408
409 if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) 409 if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
410 return; /* loopback */ 410 return; /* loopback */
411 pc->connect_status = 0; 411 pc->connect_status = 0;
412 if (GNUNET_SCHEDULER_NO_TASK != measure_task) 412 if (GNUNET_SCHEDULER_NO_TASK != measure_task)
413 { 413 {
414 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 414 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
415 "Measurement aborted due to disconnect!\n"); 415 "Measurement aborted due to disconnect!\n");
416 GNUNET_SCHEDULER_cancel (measure_task); 416 GNUNET_SCHEDULER_cancel (measure_task);
417 measure_task = GNUNET_SCHEDULER_NO_TASK; 417 measure_task = GNUNET_SCHEDULER_NO_TASK;
418 } 418 }
@@ -431,7 +431,8 @@ disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
431static int 431static int
432inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, 432inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
433 const struct GNUNET_MessageHeader *message, 433 const struct GNUNET_MessageHeader *message,
434 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) 434 const struct GNUNET_ATS_Information *atsi,
435 unsigned int atsi_count)
435{ 436{
436#if DEBUG_TRANSMISSION 437#if DEBUG_TRANSMISSION
437 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 438 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -446,7 +447,8 @@ inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
446static int 447static int
447outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, 448outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
448 const struct GNUNET_MessageHeader *message, 449 const struct GNUNET_MessageHeader *message,
449 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) 450 const struct GNUNET_ATS_Information *atsi,
451 unsigned int atsi_count)
450{ 452{
451#if DEBUG_TRANSMISSION 453#if DEBUG_TRANSMISSION
452 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 454 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -463,7 +465,8 @@ transmit_ready (void *cls, size_t size, void *buf);
463static int 465static int
464process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer, 466process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
465 const struct GNUNET_MessageHeader *message, 467 const struct GNUNET_MessageHeader *message,
466 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) 468 const struct GNUNET_ATS_Information *atsi,
469 unsigned int atsi_count)
467{ 470{
468 static int n; 471 static int n;
469 const struct TestMessage *hdr; 472 const struct TestMessage *hdr;
@@ -532,9 +535,10 @@ init_notify (void *cls, struct GNUNET_CORE_Handle *server,
532 GNUNET_assert (ok == 2); 535 GNUNET_assert (ok == 2);
533 OKPP; 536 OKPP;
534 /* connect p2 */ 537 /* connect p2 */
535 p2.ch = GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify, 538 p2.ch =
536 &disconnect_notify, &inbound_notify, GNUNET_YES, 539 GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify,
537 &outbound_notify, GNUNET_YES, handlers); 540 &disconnect_notify, &inbound_notify, GNUNET_YES,
541 &outbound_notify, GNUNET_YES, handlers);
538 } 542 }
539 else 543 else
540 { 544 {
@@ -546,8 +550,7 @@ init_notify (void *cls, struct GNUNET_CORE_Handle *server,
546 "Asking core (1) to connect to peer `%4s'\n", 550 "Asking core (1) to connect to peer `%4s'\n",
547 GNUNET_i2s (&p2.id)); 551 GNUNET_i2s (&p2.id));
548#endif 552#endif
549 connect_task = GNUNET_SCHEDULER_add_now (&try_connect, 553 connect_task = GNUNET_SCHEDULER_add_now (&try_connect, NULL);
550 NULL);
551 } 554 }
552} 555}
553 556
@@ -642,9 +645,10 @@ run (void *cls, char *const *args, const char *cfgfile,
642 "TOTAL_QUOTA_OUT", 645 "TOTAL_QUOTA_OUT",
643 &current_quota_p2_out)); 646 &current_quota_p2_out));
644 647
645 p1.ch = GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify, 648 p1.ch =
646 &disconnect_notify, &inbound_notify, GNUNET_YES, 649 GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify,
647 &outbound_notify, GNUNET_YES, handlers); 650 &disconnect_notify, &inbound_notify, GNUNET_YES,
651 &outbound_notify, GNUNET_YES, handlers);
648} 652}
649 653
650 654
diff --git a/src/datacache/datacache.c b/src/datacache/datacache.c
index 324ab78ef..d68ba72b5 100644
--- a/src/datacache/datacache.c
+++ b/src/datacache/datacache.c
@@ -109,8 +109,7 @@ env_delete_notify (void *cls, const GNUNET_HashCode * key, size_t size)
109 struct GNUNET_DATACACHE_Handle *h = cls; 109 struct GNUNET_DATACACHE_Handle *h = cls;
110 110
111#if DEBUG_DATACACHE 111#if DEBUG_DATACACHE
112 LOG (GNUNET_ERROR_TYPE_DEBUG, 112 LOG (GNUNET_ERROR_TYPE_DEBUG, "Content under key `%s' discarded\n",
113 "Content under key `%s' discarded\n",
114 GNUNET_h2s (key)); 113 GNUNET_h2s (key));
115#endif 114#endif
116 GNUNET_assert (h->utilization >= size); 115 GNUNET_assert (h->utilization >= size);
@@ -243,8 +242,7 @@ GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
243 return GNUNET_SYSERR; 242 return GNUNET_SYSERR;
244 } 243 }
245#if DEBUG_DATACACHE 244#if DEBUG_DATACACHE
246 LOG (GNUNET_ERROR_TYPE_DEBUG, 245 LOG (GNUNET_ERROR_TYPE_DEBUG, "Stored data under key `%s' in cache\n",
247 "Stored data under key `%s' in cache\n",
248 GNUNET_h2s (key)); 246 GNUNET_h2s (key));
249#endif 247#endif
250 GNUNET_STATISTICS_update (h->stats, gettext_noop ("# bytes stored"), size, 248 GNUNET_STATISTICS_update (h->stats, gettext_noop ("# bytes stored"), size,
@@ -276,8 +274,7 @@ GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h,
276 GNUNET_STATISTICS_update (h->stats, gettext_noop ("# requests received"), 1, 274 GNUNET_STATISTICS_update (h->stats, gettext_noop ("# requests received"), 1,
277 GNUNET_NO); 275 GNUNET_NO);
278#if DEBUG_DATACACHE 276#if DEBUG_DATACACHE
279 LOG (GNUNET_ERROR_TYPE_DEBUG, 277 LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing request for key `%s'\n",
280 "Processing request for key `%s'\n",
281 GNUNET_h2s (key)); 278 GNUNET_h2s (key));
282#endif 279#endif
283 if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_test (h->filter, key)) 280 if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_test (h->filter, key))
@@ -287,9 +284,8 @@ GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h,
287 ("# requests filtered by bloom filter"), 1, 284 ("# requests filtered by bloom filter"), 1,
288 GNUNET_NO); 285 GNUNET_NO);
289#if DEBUG_DATACACHE 286#if DEBUG_DATACACHE
290 LOG (GNUNET_ERROR_TYPE_DEBUG, 287 LOG (GNUNET_ERROR_TYPE_DEBUG, "Bloomfilter filters request for key `%s'\n",
291 "Bloomfilter filters request for key `%s'\n", 288 GNUNET_h2s (key));
292 GNUNET_h2s (key));
293#endif 289#endif
294 return 0; /* can not be present */ 290 return 0; /* can not be present */
295 } 291 }
diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c
index 44799be63..f852d3b06 100644
--- a/src/datacache/plugin_datacache_sqlite.c
+++ b/src/datacache/plugin_datacache_sqlite.c
@@ -123,9 +123,8 @@ sqlite_plugin_put (void *cls, const GNUNET_HashCode * key, size_t size,
123 "INSERT INTO ds090 (type, expire, key, value) VALUES (?, ?, ?, ?)", 123 "INSERT INTO ds090 (type, expire, key, value) VALUES (?, ?, ?, ?)",
124 &stmt) != SQLITE_OK) 124 &stmt) != SQLITE_OK)
125 { 125 {
126 LOG_SQLITE (plugin->dbh, 126 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
127 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 127 "sq_prepare");
128 "sq_prepare");
129 return 0; 128 return 0;
130 } 129 }
131 if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) || 130 if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) ||
@@ -192,9 +191,8 @@ sqlite_plugin_get (void *cls, const GNUNET_HashCode * key,
192 "SELECT count(*) FROM ds090 WHERE key=? AND type=? AND expire >= ?", 191 "SELECT count(*) FROM ds090 WHERE key=? AND type=? AND expire >= ?",
193 &stmt) != SQLITE_OK) 192 &stmt) != SQLITE_OK)
194 { 193 {
195 LOG_SQLITE (plugin->dbh, 194 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
196 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 195 "sq_prepare");
197 "sq_prepare");
198 return 0; 196 return 0;
199 } 197 }
200 ntime = (int64_t) now.abs_value; 198 ntime = (int64_t) now.abs_value;
@@ -218,8 +216,8 @@ sqlite_plugin_get (void *cls, const GNUNET_HashCode * key,
218 sqlite3_finalize (stmt); 216 sqlite3_finalize (stmt);
219#if DEBUG_DATACACHE_SQLITE 217#if DEBUG_DATACACHE_SQLITE
220 LOG (GNUNET_ERROR_TYPE_DEBUG, 218 LOG (GNUNET_ERROR_TYPE_DEBUG,
221 "No content found when processing `%s' for key `%4s'\n", 219 "No content found when processing `%s' for key `%4s'\n", "GET",
222 "GET", GNUNET_h2s (key)); 220 GNUNET_h2s (key));
223#endif 221#endif
224 return 0; 222 return 0;
225 } 223 }
@@ -230,8 +228,8 @@ sqlite_plugin_get (void *cls, const GNUNET_HashCode * key,
230#if DEBUG_DATACACHE_SQLITE 228#if DEBUG_DATACACHE_SQLITE
231 if (0 == total) 229 if (0 == total)
232 LOG (GNUNET_ERROR_TYPE_DEBUG, 230 LOG (GNUNET_ERROR_TYPE_DEBUG,
233 "No content found when processing `%s' for key `%4s'\n", 231 "No content found when processing `%s' for key `%4s'\n", "GET",
234 "GET", GNUNET_h2s (key)); 232 GNUNET_h2s (key));
235#endif 233#endif
236 return total; 234 return total;
237 } 235 }
@@ -246,9 +244,8 @@ sqlite_plugin_get (void *cls, const GNUNET_HashCode * key,
246 off); 244 off);
247 if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK) 245 if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK)
248 { 246 {
249 LOG_SQLITE (plugin->dbh, 247 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
250 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 248 "sq_prepare");
251 "sq_prepare");
252 return cnt; 249 return cnt;
253 } 250 }
254 if ((SQLITE_OK != 251 if ((SQLITE_OK !=
@@ -273,10 +270,8 @@ sqlite_plugin_get (void *cls, const GNUNET_HashCode * key,
273 cnt++; 270 cnt++;
274#if DEBUG_DATACACHE_SQLITE 271#if DEBUG_DATACACHE_SQLITE
275 LOG (GNUNET_ERROR_TYPE_DEBUG, 272 LOG (GNUNET_ERROR_TYPE_DEBUG,
276 "Found %u-byte result when processing `%s' for key `%4s'\n", 273 "Found %u-byte result when processing `%s' for key `%4s'\n",
277 (unsigned int) size, 274 (unsigned int) size, "GET", GNUNET_h2s (key));
278 "GET",
279 GNUNET_h2s (key));
280#endif 275#endif
281 if (GNUNET_OK != iter (iter_cls, exp, key, size, dat, type)) 276 if (GNUNET_OK != iter (iter_cls, exp, key, size, dat, type))
282 { 277 {
@@ -316,18 +311,16 @@ sqlite_plugin_del (void *cls)
316 "SELECT _ROWID_,key,value FROM ds090 ORDER BY expire ASC LIMIT 1", 311 "SELECT _ROWID_,key,value FROM ds090 ORDER BY expire ASC LIMIT 1",
317 &stmt) != SQLITE_OK) 312 &stmt) != SQLITE_OK)
318 { 313 {
319 LOG_SQLITE (plugin->dbh, 314 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
320 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 315 "sq_prepare");
321 "sq_prepare");
322 if (stmt != NULL) 316 if (stmt != NULL)
323 (void) sqlite3_finalize (stmt); 317 (void) sqlite3_finalize (stmt);
324 return GNUNET_SYSERR; 318 return GNUNET_SYSERR;
325 } 319 }
326 if (SQLITE_ROW != sqlite3_step (stmt)) 320 if (SQLITE_ROW != sqlite3_step (stmt))
327 { 321 {
328 LOG_SQLITE (plugin->dbh, 322 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
329 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 323 "sqlite3_step");
330 "sqlite3_step");
331 (void) sqlite3_finalize (stmt); 324 (void) sqlite3_finalize (stmt);
332 return GNUNET_SYSERR; 325 return GNUNET_SYSERR;
333 } 326 }
@@ -336,42 +329,35 @@ sqlite_plugin_del (void *cls)
336 memcpy (&hc, sqlite3_column_blob (stmt, 1), sizeof (GNUNET_HashCode)); 329 memcpy (&hc, sqlite3_column_blob (stmt, 1), sizeof (GNUNET_HashCode));
337 dsize = sqlite3_column_bytes (stmt, 2); 330 dsize = sqlite3_column_bytes (stmt, 2);
338 if (SQLITE_OK != sqlite3_finalize (stmt)) 331 if (SQLITE_OK != sqlite3_finalize (stmt))
339 LOG_SQLITE (plugin->dbh, 332 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
340 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 333 "sqlite3_step");
341 "sqlite3_step"); 334 if (sq_prepare (plugin->dbh, "DELETE FROM ds090 WHERE _ROWID_=?", &dstmt) !=
342 if (sq_prepare 335 SQLITE_OK)
343 (plugin->dbh, "DELETE FROM ds090 WHERE _ROWID_=?",
344 &dstmt) != SQLITE_OK)
345 { 336 {
346 LOG_SQLITE (plugin->dbh, 337 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
347 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 338 "sq_prepare");
348 "sq_prepare");
349 if (stmt != NULL) 339 if (stmt != NULL)
350 (void) sqlite3_finalize (stmt); 340 (void) sqlite3_finalize (stmt);
351 return GNUNET_SYSERR; 341 return GNUNET_SYSERR;
352 } 342 }
353 if (SQLITE_OK != 343 if (SQLITE_OK != sqlite3_bind_int64 (dstmt, 1, rowid))
354 sqlite3_bind_int64 (dstmt, 1, rowid))
355 { 344 {
356 LOG_SQLITE (plugin->dbh, 345 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
357 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 346 "sqlite3_bind");
358 "sqlite3_bind");
359 (void) sqlite3_finalize (dstmt); 347 (void) sqlite3_finalize (dstmt);
360 return GNUNET_SYSERR; 348 return GNUNET_SYSERR;
361 } 349 }
362 if (sqlite3_step (dstmt) != SQLITE_DONE) 350 if (sqlite3_step (dstmt) != SQLITE_DONE)
363 { 351 {
364 LOG_SQLITE (plugin->dbh, 352 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
365 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 353 "sqlite3_step");
366 "sqlite3_step");
367 (void) sqlite3_finalize (dstmt); 354 (void) sqlite3_finalize (dstmt);
368 return GNUNET_SYSERR; 355 return GNUNET_SYSERR;
369 } 356 }
370 plugin->env->delete_notify (plugin->env->cls, &hc, dsize + OVERHEAD); 357 plugin->env->delete_notify (plugin->env->cls, &hc, dsize + OVERHEAD);
371 if (SQLITE_OK != sqlite3_finalize (dstmt)) 358 if (SQLITE_OK != sqlite3_finalize (dstmt))
372 LOG_SQLITE (plugin->dbh, 359 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
373 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 360 "sqlite3_finalize");
374 "sqlite3_finalize");
375 return GNUNET_OK; 361 return GNUNET_OK;
376} 362}
377 363
@@ -435,8 +421,7 @@ libgnunet_plugin_datacache_sqlite_init (void *cls)
435 api->get = &sqlite_plugin_get; 421 api->get = &sqlite_plugin_get;
436 api->put = &sqlite_plugin_put; 422 api->put = &sqlite_plugin_put;
437 api->del = &sqlite_plugin_del; 423 api->del = &sqlite_plugin_del;
438 LOG (GNUNET_ERROR_TYPE_INFO, 424 LOG (GNUNET_ERROR_TYPE_INFO, _("Sqlite datacache running\n"));
439 _("Sqlite datacache running\n"));
440 return api; 425 return api;
441} 426}
442 427
@@ -468,19 +453,19 @@ libgnunet_plugin_datacache_sqlite_done (void *cls)
468 if (result == SQLITE_BUSY) 453 if (result == SQLITE_BUSY)
469 { 454 {
470 LOG (GNUNET_ERROR_TYPE_WARNING, 455 LOG (GNUNET_ERROR_TYPE_WARNING,
471 _("Tried to close sqlite without finalizing all prepared statements.\n")); 456 _
457 ("Tried to close sqlite without finalizing all prepared statements.\n"));
472 stmt = sqlite3_next_stmt (plugin->dbh, NULL); 458 stmt = sqlite3_next_stmt (plugin->dbh, NULL);
473 while (stmt != NULL) 459 while (stmt != NULL)
474 { 460 {
475#if DEBUG_SQLITE 461#if DEBUG_SQLITE
476 LOG (GNUNET_ERROR_TYPE_DEBUG, 462 LOG (GNUNET_ERROR_TYPE_DEBUG, "Closing statement %p\n", stmt);
477 "Closing statement %p\n", stmt);
478#endif 463#endif
479 result = sqlite3_finalize (stmt); 464 result = sqlite3_finalize (stmt);
480#if DEBUG_SQLITE 465#if DEBUG_SQLITE
481 if (result != SQLITE_OK) 466 if (result != SQLITE_OK)
482 LOG (GNUNET_ERROR_TYPE_DEBUG, 467 LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to close statement %p: %d\n",
483 "Failed to close statement %p: %d\n", stmt, result); 468 stmt, result);
484#endif 469#endif
485 stmt = sqlite3_next_stmt (plugin->dbh, NULL); 470 stmt = sqlite3_next_stmt (plugin->dbh, NULL);
486 } 471 }
diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c
index 318c22cf5..6d3d56c02 100644
--- a/src/datastore/plugin_datastore_sqlite.c
+++ b/src/datastore/plugin_datastore_sqlite.c
@@ -325,41 +325,35 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
325 &plugin->updRepl) != SQLITE_OK) || 325 &plugin->updRepl) != SQLITE_OK) ||
326 (sq_prepare 326 (sq_prepare
327 (plugin->dbh, 327 (plugin->dbh,
328 "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " 328 "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " "FROM gn090 "
329 "FROM gn090 "
330#if SQLITE_VERSION_NUMBER >= 3007000 329#if SQLITE_VERSION_NUMBER >= 3007000
331 "INDEXED BY idx_repl_rvalue " 330 "INDEXED BY idx_repl_rvalue "
332#endif 331#endif
333 "WHERE repl=?2 AND " 332 "WHERE repl=?2 AND " " (rvalue>=?1 OR "
334 " (rvalue>=?1 OR "
335 " NOT EXISTS (SELECT 1 FROM gn090 " 333 " NOT EXISTS (SELECT 1 FROM gn090 "
336#if SQLITE_VERSION_NUMBER >= 3007000 334#if SQLITE_VERSION_NUMBER >= 3007000
337 "INDEXED BY idx_repl_rvalue " 335 "INDEXED BY idx_repl_rvalue "
338#endif 336#endif
339 "WHERE repl=?2 AND rvalue>=?1 LIMIT 1) ) " 337 "WHERE repl=?2 AND rvalue>=?1 LIMIT 1) ) "
340 "ORDER BY rvalue ASC LIMIT 1", &plugin->selRepl) != SQLITE_OK) || 338 "ORDER BY rvalue ASC LIMIT 1", &plugin->selRepl) != SQLITE_OK) ||
341 (sq_prepare 339 (sq_prepare (plugin->dbh, "SELECT MAX(repl) FROM gn090"
342 (plugin->dbh, "SELECT MAX(repl) FROM gn090"
343#if SQLITE_VERSION_NUMBER >= 3007000 340#if SQLITE_VERSION_NUMBER >= 3007000
344 " INDEXED BY idx_repl_rvalue" 341 " INDEXED BY idx_repl_rvalue"
345#endif 342#endif
346 "", 343 "", &plugin->maxRepl) != SQLITE_OK) ||
347 &plugin->maxRepl) != SQLITE_OK) ||
348 (sq_prepare 344 (sq_prepare
349 (plugin->dbh, 345 (plugin->dbh,
350 "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " 346 "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " "FROM gn090 "
351 "FROM gn090 "
352#if SQLITE_VERSION_NUMBER >= 3007000 347#if SQLITE_VERSION_NUMBER >= 3007000
353 "INDEXED BY idx_expire " 348 "INDEXED BY idx_expire "
354#endif 349#endif
355 "WHERE NOT EXISTS (SELECT 1 FROM gn090 WHERE expire < ?1 LIMIT 1) OR (expire < ?1) " 350 "WHERE NOT EXISTS (SELECT 1 FROM gn090 WHERE expire < ?1 LIMIT 1) OR (expire < ?1) "
356 "ORDER BY expire ASC LIMIT 1", &plugin->selExpi) != SQLITE_OK) || 351 "ORDER BY expire ASC LIMIT 1", &plugin->selExpi) != SQLITE_OK) ||
357 (sq_prepare 352 (sq_prepare
358 (plugin->dbh, 353 (plugin->dbh,
359 "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " 354 "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " "FROM gn090 "
360 "FROM gn090 "
361#if SQLITE_VERSION_NUMBER >= 3007000 355#if SQLITE_VERSION_NUMBER >= 3007000
362 "INDEXED BY idx_anon_type_hash " 356 "INDEXED BY idx_anon_type_hash "
363#endif 357#endif
364 "WHERE (anonLevel = 0 AND type=?1) " 358 "WHERE (anonLevel = 0 AND type=?1) "
365 "ORDER BY hash DESC LIMIT 1 OFFSET ?2", 359 "ORDER BY hash DESC LIMIT 1 OFFSET ?2",
diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c
index b1dd0e5de..0309a6592 100644
--- a/src/datastore/test_datastore_api.c
+++ b/src/datastore/test_datastore_api.c
@@ -185,11 +185,11 @@ check_value (void *cls, const GNUNET_HashCode * key, size_t size,
185 if (NULL == key) 185 if (NULL == key)
186 { 186 {
187 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 187 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
188 "Value check failed (got NULL key) in %d/%d\n", 188 "Value check failed (got NULL key) in %d/%d\n", crc->phase,
189 crc->phase, crc->i); 189 crc->i);
190 crc->phase = RP_ERROR; 190 crc->phase = RP_ERROR;
191 GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, 191 GNUNET_SCHEDULER_add_continuation (&run_continuation, crc,
192 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 192 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
193 return; 193 return;
194 } 194 }
195#if 0 195#if 0
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c
index 720e82a41..ac69b7a4e 100644
--- a/src/dht/dht_api.c
+++ b/src/dht/dht_api.c
@@ -249,12 +249,11 @@ add_request_to_pending (void *cls, const GNUNET_HashCode * key, void *value)
249 struct GNUNET_DHT_GetHandle *rh = value; 249 struct GNUNET_DHT_GetHandle *rh = value;
250 250
251 if (GNUNET_NO == rh->message->in_pending_queue) 251 if (GNUNET_NO == rh->message->in_pending_queue)
252 { 252 {
253#if DEBUG_DHT 253#if DEBUG_DHT
254 LOG (GNUNET_ERROR_TYPE_DEBUG, 254 LOG (GNUNET_ERROR_TYPE_DEBUG,
255 "Retransmitting request related to %s to DHT %p\n", 255 "Retransmitting request related to %s to DHT %p\n", GNUNET_h2s (key),
256 GNUNET_h2s (key), 256 handle);
257 handle);
258#endif 257#endif
259 GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail, 258 GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail,
260 rh->message); 259 rh->message);
@@ -284,9 +283,7 @@ try_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
284 struct GNUNET_DHT_Handle *handle = cls; 283 struct GNUNET_DHT_Handle *handle = cls;
285 284
286#if DEBUG_DHT 285#if DEBUG_DHT
287 LOG (GNUNET_ERROR_TYPE_DEBUG, 286 LOG (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting with DHT %p\n", handle);
288 "Reconnecting with DHT %p\n",
289 handle);
290#endif 287#endif
291 handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; 288 handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
292 if (handle->retry_time.rel_value < GNUNET_CONSTANTS_SERVICE_RETRY.rel_value) 289 if (handle->retry_time.rel_value < GNUNET_CONSTANTS_SERVICE_RETRY.rel_value)
@@ -324,8 +321,8 @@ do_disconnect (struct GNUNET_DHT_Handle *handle)
324 GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th); 321 GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th);
325 handle->th = NULL; 322 handle->th = NULL;
326 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 323 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
327 "Disconnecting from DHT service, will try to reconnect in %llu ms\n", 324 "Disconnecting from DHT service, will try to reconnect in %llu ms\n",
328 (unsigned long long) handle->retry_time.rel_value); 325 (unsigned long long) handle->retry_time.rel_value);
329 GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO); 326 GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO);
330 handle->client = NULL; 327 handle->client = NULL;
331 handle->reconnect_task = 328 handle->reconnect_task =
@@ -351,7 +348,7 @@ process_pending_messages (struct GNUNET_DHT_Handle *handle)
351 if (handle->client == NULL) 348 if (handle->client == NULL)
352 { 349 {
353 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 350 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
354 "process_pending_messages called, but client is null, reconnecting\n"); 351 "process_pending_messages called, but client is null, reconnecting\n");
355 do_disconnect (handle); 352 do_disconnect (handle);
356 return; 353 return;
357 } 354 }
@@ -368,7 +365,7 @@ process_pending_messages (struct GNUNET_DHT_Handle *handle)
368 if (NULL != handle->th) 365 if (NULL != handle->th)
369 return; 366 return;
370 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
371 "notify_transmit_ready returned NULL, reconnecting\n"); 368 "notify_transmit_ready returned NULL, reconnecting\n");
372 do_disconnect (handle); 369 do_disconnect (handle);
373} 370}
374 371
@@ -432,7 +429,7 @@ transmit_pending (void *cls, size_t size, void *buf)
432#endif 429#endif
433 handle->in_receive = GNUNET_YES; 430 handle->in_receive = GNUNET_YES;
434 GNUNET_CLIENT_receive (handle->client, &service_message_handler, handle, 431 GNUNET_CLIENT_receive (handle->client, &service_message_handler, handle,
435 GNUNET_TIME_UNIT_FOREVER_REL); 432 GNUNET_TIME_UNIT_FOREVER_REL);
436 } 433 }
437 return tsize; 434 return tsize;
438} 435}
@@ -466,9 +463,8 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value)
466 { 463 {
467 /* UID mismatch */ 464 /* UID mismatch */
468#if DEBUG_DHT 465#if DEBUG_DHT
469 LOG (GNUNET_ERROR_TYPE_DEBUG, 466 LOG (GNUNET_ERROR_TYPE_DEBUG,
470 "Ignoring reply for %s: UID mismatch: %llu/%llu\n", 467 "Ignoring reply for %s: UID mismatch: %llu/%llu\n", GNUNET_h2s (key),
471 GNUNET_h2s (key),
472 dht_msg->unique_id, get_handle->unique_id); 468 dht_msg->unique_id, get_handle->unique_id);
473#endif 469#endif
474 return GNUNET_YES; 470 return GNUNET_YES;
@@ -490,10 +486,8 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value)
490 } 486 }
491 data_length = msize - meta_length; 487 data_length = msize - meta_length;
492#if DEBUG_DHT 488#if DEBUG_DHT
493 LOG (GNUNET_ERROR_TYPE_DEBUG, 489 LOG (GNUNET_ERROR_TYPE_DEBUG, "Giving %u byte reply for %s to application\n",
494 "Giving %u byte reply for %s to application\n", 490 (unsigned int) data_length, GNUNET_h2s (key));
495 (unsigned int) data_length,
496 GNUNET_h2s (key));
497#endif 491#endif
498 put_path = (const struct GNUNET_PeerIdentity *) &dht_msg[1]; 492 put_path = (const struct GNUNET_PeerIdentity *) &dht_msg[1];
499 get_path = &put_path[put_path_length]; 493 get_path = &put_path[put_path_length];
@@ -542,10 +536,8 @@ service_message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
542 } 536 }
543 dht_msg = (const struct GNUNET_DHT_ClientResultMessage *) msg; 537 dht_msg = (const struct GNUNET_DHT_ClientResultMessage *) msg;
544#if DEBUG_DHT 538#if DEBUG_DHT
545 LOG (GNUNET_ERROR_TYPE_DEBUG, 539 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received reply for `%s' from DHT service %p\n",
546 "Received reply for `%s' from DHT service %p\n", 540 GNUNET_h2s (&dht_msg->key), handle);
547 GNUNET_h2s (&dht_msg->key),
548 handle);
549#endif 541#endif
550 GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_requests, 542 GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_requests,
551 &dht_msg->key, &process_reply, 543 &dht_msg->key, &process_reply,
@@ -641,7 +633,7 @@ timeout_put_request (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
641 struct GNUNET_DHT_Handle *handle; 633 struct GNUNET_DHT_Handle *handle;
642 634
643 handle = pending->handle; 635 handle = pending->handle;
644 GNUNET_assert (GNUNET_YES == pending->in_pending_queue); 636 GNUNET_assert (GNUNET_YES == pending->in_pending_queue);
645 GNUNET_CONTAINER_DLL_remove (handle->pending_head, handle->pending_tail, 637 GNUNET_CONTAINER_DLL_remove (handle->pending_head, handle->pending_tail,
646 pending); 638 pending);
647 pending->in_pending_queue = GNUNET_NO; 639 pending->in_pending_queue = GNUNET_NO;
@@ -752,10 +744,8 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle,
752 return NULL; 744 return NULL;
753 } 745 }
754#if DEBUG_DHT 746#if DEBUG_DHT
755 LOG (GNUNET_ERROR_TYPE_DEBUG, 747 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending query for %s to DHT %p\n",
756 "Sending query for %s to DHT %p\n", 748 GNUNET_h2s (key), handle);
757 GNUNET_h2s (key),
758 handle);
759#endif 749#endif
760 pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize); 750 pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
761 get_msg = (struct GNUNET_DHT_ClientGetMessage *) &pending[1]; 751 get_msg = (struct GNUNET_DHT_ClientGetMessage *) &pending[1];
@@ -803,10 +793,8 @@ GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle)
803 get_msg = 793 get_msg =
804 (const struct GNUNET_DHT_ClientGetMessage *) get_handle->message->msg; 794 (const struct GNUNET_DHT_ClientGetMessage *) get_handle->message->msg;
805#if DEBUG_DHT 795#if DEBUG_DHT
806 LOG (GNUNET_ERROR_TYPE_DEBUG, 796 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending STOP for %s to DHT via %p\n",
807 "Sending STOP for %s to DHT via %p\n", 797 GNUNET_h2s (&get_msg->key), handle);
808 GNUNET_h2s (&get_msg->key),
809 handle);
810#endif 798#endif
811 /* generate STOP */ 799 /* generate STOP */
812 pending = 800 pending =
diff --git a/src/dht/gnunet-dht-get.c b/src/dht/gnunet-dht-get.c
index 8720e76aa..763ff8e6f 100644
--- a/src/dht/gnunet-dht-get.c
+++ b/src/dht/gnunet-dht-get.c
@@ -124,10 +124,10 @@ static void
124get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, 124get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
125 const GNUNET_HashCode * key, 125 const GNUNET_HashCode * key,
126 const struct GNUNET_PeerIdentity *get_path, 126 const struct GNUNET_PeerIdentity *get_path,
127 unsigned int get_path_length, 127 unsigned int get_path_length,
128 const struct GNUNET_PeerIdentity *put_path, 128 const struct GNUNET_PeerIdentity *put_path,
129 unsigned int put_path_length, 129 unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
130 enum GNUNET_BLOCK_Type type, size_t size, const void *data) 130 size_t size, const void *data)
131{ 131{
132 fprintf (stdout, "Result %d, type %d:\n%.*s\n", result_count, type, 132 fprintf (stdout, "Result %d, type %d:\n%.*s\n", result_count, type,
133 (unsigned int) size, (char *) data); 133 (unsigned int) size, (char *) data);
@@ -186,9 +186,9 @@ run (void *cls, char *const *args, const char *cfgfile,
186 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining 186 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
187 (absolute_timeout), &cleanup_task, NULL); 187 (absolute_timeout), &cleanup_task, NULL);
188 get_handle = 188 get_handle =
189 GNUNET_DHT_get_start (dht_handle, timeout, query_type, &key, 189 GNUNET_DHT_get_start (dht_handle, timeout, query_type, &key, replication,
190 replication, GNUNET_DHT_RO_NONE, NULL, 190 GNUNET_DHT_RO_NONE, NULL, 0, &get_result_iterator,
191 0, &get_result_iterator, NULL); 191 NULL);
192 192
193} 193}
194 194
diff --git a/src/dht/gnunet-dht-put.c b/src/dht/gnunet-dht-put.c
index f165aa4a4..079a8866e 100644
--- a/src/dht/gnunet-dht-put.c
+++ b/src/dht/gnunet-dht-put.c
@@ -151,9 +151,9 @@ run (void *cls, char *const *args, const char *cfgfile,
151 if (verbose) 151 if (verbose)
152 fprintf (stderr, _("Issuing put request for `%s' with data `%s'!\n"), 152 fprintf (stderr, _("Issuing put request for `%s' with data `%s'!\n"),
153 query_key, data); 153 query_key, data);
154 GNUNET_DHT_put (dht_handle, &key, replication, GNUNET_DHT_RO_NONE, 154 GNUNET_DHT_put (dht_handle, &key, replication, GNUNET_DHT_RO_NONE, query_type,
155 query_type, strlen (data), data, expiration, timeout, 155 strlen (data), data, expiration, timeout, &message_sent_cont,
156 &message_sent_cont, NULL); 156 NULL);
157 157
158} 158}
159 159
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c
index 3e0f3c8d9..72575acae 100644
--- a/src/dht/gnunet-service-dht.c
+++ b/src/dht/gnunet-service-dht.c
@@ -81,8 +81,7 @@ static struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
81 * @param message HELLO message of peer 81 * @param message HELLO message of peer
82 */ 82 */
83static void 83static void
84process_hello (void *cls, 84process_hello (void *cls, const struct GNUNET_MessageHeader *message)
85 const struct GNUNET_MessageHeader *message)
86{ 85{
87 GNUNET_assert (message != NULL); 86 GNUNET_assert (message != NULL);
88 GNUNET_free_non_null (GDS_my_hello); 87 GNUNET_free_non_null (GDS_my_hello);
@@ -149,24 +148,22 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
149 GDS_DATACACHE_init (); 148 GDS_DATACACHE_init ();
150 GDS_HELLO_init (); 149 GDS_HELLO_init ();
151 GDS_CLIENTS_init (server); 150 GDS_CLIENTS_init (server);
152 if (GNUNET_OK != 151 if (GNUNET_OK != GDS_NEIGHBOURS_init ())
153 GDS_NEIGHBOURS_init ()) 152 {
154 { 153 shutdown_task (NULL, NULL);
155 shutdown_task (NULL, NULL); 154 return;
156 return; 155 }
157 } 156 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
158 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 157 NULL);
159 &shutdown_task, NULL);
160 GDS_transport_handle = 158 GDS_transport_handle =
161 GNUNET_TRANSPORT_connect (GDS_cfg, NULL, NULL, NULL, NULL, NULL); 159 GNUNET_TRANSPORT_connect (GDS_cfg, NULL, NULL, NULL, NULL, NULL);
162 if (GDS_transport_handle == NULL) 160 if (GDS_transport_handle == NULL)
163 { 161 {
164 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 162 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
165 _("Failed to connect to transport service!\n")); 163 _("Failed to connect to transport service!\n"));
166 return; 164 return;
167 } 165 }
168 ghh = GNUNET_TRANSPORT_get_hello (GDS_transport_handle, 166 ghh = GNUNET_TRANSPORT_get_hello (GDS_transport_handle, &process_hello, NULL);
169 &process_hello, NULL);
170} 167}
171 168
172 169
@@ -181,12 +178,11 @@ int
181main (int argc, char *const *argv) 178main (int argc, char *const *argv)
182{ 179{
183 int ret; 180 int ret;
184 181
185 ret = (GNUNET_OK == 182 ret =
186 GNUNET_SERVICE_run (argc, argv, 183 (GNUNET_OK ==
187 "dht", 184 GNUNET_SERVICE_run (argc, argv, "dht", GNUNET_SERVICE_OPTION_NONE, &run,
188 GNUNET_SERVICE_OPTION_NONE, 185 NULL)) ? 0 : 1;
189 &run, NULL)) ? 0 : 1;
190 GDS_CLIENTS_done (); 186 GDS_CLIENTS_done ();
191 return ret; 187 return ret;
192} 188}
diff --git a/src/dht/gnunet-service-dht_clients.c b/src/dht/gnunet-service-dht_clients.c
index 4b9eecc58..dde8c6d7a 100644
--- a/src/dht/gnunet-service-dht_clients.c
+++ b/src/dht/gnunet-service-dht_clients.c
@@ -53,7 +53,7 @@ struct PendingMessage
53 53
54 /** 54 /**
55 * Actual message to be sent, allocated at the end of the struct: 55 * Actual message to be sent, allocated at the end of the struct:
56 * // msg = (cast) &pm[1]; 56 * // msg = (cast) &pm[1];
57 * // memcpy (&pm[1], data, len); 57 * // memcpy (&pm[1], data, len);
58 */ 58 */
59 const struct GNUNET_MessageHeader *msg; 59 const struct GNUNET_MessageHeader *msg;
@@ -224,15 +224,13 @@ find_active_client (struct GNUNET_SERVER_Client *client)
224 } 224 }
225 ret = GNUNET_malloc (sizeof (struct ClientList)); 225 ret = GNUNET_malloc (sizeof (struct ClientList));
226 ret->client_handle = client; 226 ret->client_handle = client;
227 GNUNET_CONTAINER_DLL_insert (client_head, 227 GNUNET_CONTAINER_DLL_insert (client_head, client_tail, ret);
228 client_tail,
229 ret);
230 return ret; 228 return ret;
231} 229}
232 230
233 231
234/** 232/**
235 * Iterator over hash map entries that frees all entries 233 * Iterator over hash map entries that frees all entries
236 * associated with the given client. 234 * associated with the given client.
237 * 235 *
238 * @param cls client to search for in source routes 236 * @param cls client to search for in source routes
@@ -250,18 +248,15 @@ remove_client_records (void *cls, const GNUNET_HashCode * key, void *value)
250 return GNUNET_YES; 248 return GNUNET_YES;
251#if DEBUG_DHT 249#if DEBUG_DHT
252 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
253 "Removing client %p's record for key %s\n", 251 "Removing client %p's record for key %s\n", client,
254 client, 252 GNUNET_h2s (key));
255 GNUNET_h2s (key));
256#endif 253#endif
257 GNUNET_assert (GNUNET_YES == 254 GNUNET_assert (GNUNET_YES ==
258 GNUNET_CONTAINER_multihashmap_remove (forward_map, 255 GNUNET_CONTAINER_multihashmap_remove (forward_map, key,
259 key, record)); 256 record));
260 if (NULL != record->hnode) 257 if (NULL != record->hnode)
261 GNUNET_CONTAINER_heap_remove_node (record->hnode); 258 GNUNET_CONTAINER_heap_remove_node (record->hnode);
262 GNUNET_array_grow (record->seen_replies, 259 GNUNET_array_grow (record->seen_replies, record->seen_replies_count, 0);
263 record->seen_replies_count,
264 0);
265 GNUNET_free (record); 260 GNUNET_free (record);
266 return GNUNET_YES; 261 return GNUNET_YES;
267} 262}
@@ -276,37 +271,31 @@ remove_client_records (void *cls, const GNUNET_HashCode * key, void *value)
276 * for the last call when the server is destroyed 271 * for the last call when the server is destroyed
277 */ 272 */
278static void 273static void
279handle_client_disconnect (void *cls, 274handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
280 struct GNUNET_SERVER_Client *client)
281{ 275{
282 struct ClientList *pos; 276 struct ClientList *pos;
283 struct PendingMessage *reply; 277 struct PendingMessage *reply;
284 278
285#if DEBUG_DHT 279#if DEBUG_DHT
286 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 280 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Local client %p disconnects\n", client);
287 "Local client %p disconnects\n",
288 client);
289#endif 281#endif
290 pos = find_active_client (client); 282 pos = find_active_client (client);
291 GNUNET_CONTAINER_DLL_remove (client_head, 283 GNUNET_CONTAINER_DLL_remove (client_head, client_tail, pos);
292 client_tail,
293 pos);
294 if (pos->transmit_handle != NULL) 284 if (pos->transmit_handle != NULL)
295 GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->transmit_handle); 285 GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->transmit_handle);
296 while (NULL != (reply = pos->pending_head)) 286 while (NULL != (reply = pos->pending_head))
297 { 287 {
298 GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, 288 GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, reply);
299 reply); 289 GNUNET_free (reply);
300 GNUNET_free (reply); 290 }
301 } 291 GNUNET_CONTAINER_multihashmap_iterate (forward_map, &remove_client_records,
302 GNUNET_CONTAINER_multihashmap_iterate (forward_map, 292 pos);
303 &remove_client_records, pos);
304 GNUNET_free (pos); 293 GNUNET_free (pos);
305} 294}
306 295
307 296
308/** 297/**
309 * Route the given request via the DHT. This includes updating 298 * Route the given request via the DHT. This includes updating
310 * the bloom filter and retransmission times, building the P2P 299 * the bloom filter and retransmission times, building the P2P
311 * message and initiating the routing operation. 300 * message and initiating the routing operation.
312 */ 301 */
@@ -318,33 +307,30 @@ transmit_request (struct ClientQueryRecord *cqr)
318 struct GNUNET_CONTAINER_BloomFilter *peer_bf; 307 struct GNUNET_CONTAINER_BloomFilter *peer_bf;
319 308
320 GNUNET_STATISTICS_update (GDS_stats, 309 GNUNET_STATISTICS_update (GDS_stats,
321 gettext_noop ("# GET requests from clients injected"), 1, 310 gettext_noop
311 ("# GET requests from clients injected"), 1,
322 GNUNET_NO); 312 GNUNET_NO);
323 reply_bf_mutator = (int32_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 313 reply_bf_mutator =
324 UINT32_MAX); 314 (int32_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
325 reply_bf = GNUNET_BLOCK_construct_bloomfilter (reply_bf_mutator, 315 UINT32_MAX);
326 cqr->seen_replies, 316 reply_bf =
327 cqr->seen_replies_count); 317 GNUNET_BLOCK_construct_bloomfilter (reply_bf_mutator, cqr->seen_replies,
328 peer_bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 318 cqr->seen_replies_count);
329 DHT_BLOOM_SIZE, 319 peer_bf =
330 GNUNET_CONSTANTS_BLOOMFILTER_K); 320 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE,
331 GDS_NEIGHBOURS_handle_get (cqr->type, 321 GNUNET_CONSTANTS_BLOOMFILTER_K);
332 cqr->msg_options, 322 GDS_NEIGHBOURS_handle_get (cqr->type, cqr->msg_options, cqr->replication,
333 cqr->replication, 323 0 /* hop count */ ,
334 0 /* hop count */, 324 &cqr->key, cqr->xquery, cqr->xquery_size, reply_bf,
335 &cqr->key, 325 reply_bf_mutator, peer_bf);
336 cqr->xquery,
337 cqr->xquery_size,
338 reply_bf,
339 reply_bf_mutator,
340 peer_bf);
341 GNUNET_CONTAINER_bloomfilter_free (reply_bf); 326 GNUNET_CONTAINER_bloomfilter_free (reply_bf);
342 GNUNET_CONTAINER_bloomfilter_free (peer_bf); 327 GNUNET_CONTAINER_bloomfilter_free (peer_bf);
343 328
344 /* exponential back-off for retries, max 1h */ 329 /* exponential back-off for retries, max 1h */
345 cqr->retry_frequency = 330 cqr->retry_frequency =
346 GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_HOURS, 331 GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_HOURS,
347 GNUNET_TIME_relative_multiply (cqr->retry_frequency, 2)); 332 GNUNET_TIME_relative_multiply
333 (cqr->retry_frequency, 2));
348 cqr->retry_time = GNUNET_TIME_relative_to_absolute (cqr->retry_frequency); 334 cqr->retry_time = GNUNET_TIME_relative_to_absolute (cqr->retry_frequency);
349} 335}
350 336
@@ -359,7 +345,7 @@ transmit_request (struct ClientQueryRecord *cqr)
359 */ 345 */
360static void 346static void
361transmit_next_request_task (void *cls, 347transmit_next_request_task (void *cls,
362 const struct GNUNET_SCHEDULER_TaskContext *tc) 348 const struct GNUNET_SCHEDULER_TaskContext *tc)
363{ 349{
364 struct ClientQueryRecord *cqr; 350 struct ClientQueryRecord *cqr;
365 struct GNUNET_TIME_Relative delay; 351 struct GNUNET_TIME_Relative delay;
@@ -368,22 +354,24 @@ transmit_next_request_task (void *cls,
368 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 354 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
369 return; 355 return;
370 while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root (retry_heap))) 356 while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root (retry_heap)))
357 {
358 cqr->hnode = NULL;
359 delay = GNUNET_TIME_absolute_get_remaining (cqr->retry_time);
360 if (delay.rel_value > 0)
371 { 361 {
372 cqr->hnode = NULL; 362 cqr->hnode =
373 delay = GNUNET_TIME_absolute_get_remaining (cqr->retry_time); 363 GNUNET_CONTAINER_heap_insert (retry_heap, cqr,
374 if (delay.rel_value > 0) 364 cqr->retry_time.abs_value);
375 { 365 retry_task =
376 cqr->hnode = GNUNET_CONTAINER_heap_insert (retry_heap, cqr, 366 GNUNET_SCHEDULER_add_delayed (delay, &transmit_next_request_task,
377 cqr->retry_time.abs_value); 367 NULL);
378 retry_task = GNUNET_SCHEDULER_add_delayed (delay, 368 return;
379 &transmit_next_request_task,
380 NULL);
381 return;
382 }
383 transmit_request (cqr);
384 cqr->hnode = GNUNET_CONTAINER_heap_insert (retry_heap, cqr,
385 cqr->retry_time.abs_value);
386 } 369 }
370 transmit_request (cqr);
371 cqr->hnode =
372 GNUNET_CONTAINER_heap_insert (retry_heap, cqr,
373 cqr->retry_time.abs_value);
374 }
387} 375}
388 376
389 377
@@ -396,58 +384,52 @@ transmit_next_request_task (void *cls,
396 */ 384 */
397static void 385static void
398handle_dht_local_put (void *cls, struct GNUNET_SERVER_Client *client, 386handle_dht_local_put (void *cls, struct GNUNET_SERVER_Client *client,
399 const struct GNUNET_MessageHeader *message) 387 const struct GNUNET_MessageHeader *message)
400{ 388{
401 const struct GNUNET_DHT_ClientPutMessage *dht_msg; 389 const struct GNUNET_DHT_ClientPutMessage *dht_msg;
402 struct GNUNET_CONTAINER_BloomFilter *peer_bf; 390 struct GNUNET_CONTAINER_BloomFilter *peer_bf;
403 uint16_t size; 391 uint16_t size;
404 392
405 size = ntohs (message->size); 393 size = ntohs (message->size);
406 if (size < sizeof (struct GNUNET_DHT_ClientPutMessage)) 394 if (size < sizeof (struct GNUNET_DHT_ClientPutMessage))
407 { 395 {
408 GNUNET_break (0); 396 GNUNET_break (0);
409 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 397 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
410 return; 398 return;
411 } 399 }
412 GNUNET_STATISTICS_update (GDS_stats, 400 GNUNET_STATISTICS_update (GDS_stats,
413 gettext_noop ("# PUT requests received from clients"), 1, 401 gettext_noop
402 ("# PUT requests received from clients"), 1,
414 GNUNET_NO); 403 GNUNET_NO);
415 dht_msg = (const struct GNUNET_DHT_ClientPutMessage *) message; 404 dht_msg = (const struct GNUNET_DHT_ClientPutMessage *) message;
416 /* give to local clients */ 405 /* give to local clients */
417#if DEBUG_DHT 406#if DEBUG_DHT
418 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
419 "Handling local PUT of %u-bytes for query %s\n", 408 "Handling local PUT of %u-bytes for query %s\n",
420 size - sizeof (struct GNUNET_DHT_ClientPutMessage), 409 size - sizeof (struct GNUNET_DHT_ClientPutMessage),
421 GNUNET_h2s (&dht_msg->key)); 410 GNUNET_h2s (&dht_msg->key));
422#endif 411#endif
423 GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (dht_msg->expiration), 412 GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (dht_msg->expiration),
424 &dht_msg->key, 413 &dht_msg->key, 0, NULL, 0, NULL,
425 0, NULL, 414 ntohl (dht_msg->type),
426 0, NULL, 415 size - sizeof (struct GNUNET_DHT_ClientPutMessage),
427 ntohl (dht_msg->type), 416 &dht_msg[1]);
428 size - sizeof (struct GNUNET_DHT_ClientPutMessage),
429 &dht_msg[1]);
430 /* store locally */ 417 /* store locally */
431 GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (dht_msg->expiration), 418 GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (dht_msg->expiration),
432 &dht_msg->key, 419 &dht_msg->key, 0, NULL, ntohl (dht_msg->type),
433 0, NULL, 420 size - sizeof (struct GNUNET_DHT_ClientPutMessage),
434 ntohl (dht_msg->type), 421 &dht_msg[1]);
435 size - sizeof (struct GNUNET_DHT_ClientPutMessage),
436 &dht_msg[1]);
437 /* route to other peers */ 422 /* route to other peers */
438 peer_bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 423 peer_bf =
439 DHT_BLOOM_SIZE, 424 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE,
440 GNUNET_CONSTANTS_BLOOMFILTER_K); 425 GNUNET_CONSTANTS_BLOOMFILTER_K);
441 GDS_NEIGHBOURS_handle_put (ntohl (dht_msg->type), 426 GDS_NEIGHBOURS_handle_put (ntohl (dht_msg->type), ntohl (dht_msg->options),
442 ntohl (dht_msg->options), 427 ntohl (dht_msg->desired_replication_level),
443 ntohl (dht_msg->desired_replication_level), 428 GNUNET_TIME_absolute_ntoh (dht_msg->expiration),
444 GNUNET_TIME_absolute_ntoh (dht_msg->expiration), 429 0 /* hop count */ ,
445 0 /* hop count */, 430 peer_bf, &dht_msg->key, 0, NULL, &dht_msg[1],
446 peer_bf, 431 size -
447 &dht_msg->key, 432 sizeof (struct GNUNET_DHT_ClientPutMessage));
448 0, NULL,
449 &dht_msg[1],
450 size - sizeof (struct GNUNET_DHT_ClientPutMessage));
451 GNUNET_CONTAINER_bloomfilter_free (peer_bf); 433 GNUNET_CONTAINER_bloomfilter_free (peer_bf);
452 GNUNET_SERVER_receive_done (client, GNUNET_OK); 434 GNUNET_SERVER_receive_done (client, GNUNET_OK);
453} 435}
@@ -464,58 +446,55 @@ handle_dht_local_put (void *cls, struct GNUNET_SERVER_Client *client,
464 */ 446 */
465static void 447static void
466handle_dht_local_get (void *cls, struct GNUNET_SERVER_Client *client, 448handle_dht_local_get (void *cls, struct GNUNET_SERVER_Client *client,
467 const struct GNUNET_MessageHeader *message) 449 const struct GNUNET_MessageHeader *message)
468{ 450{
469 const struct GNUNET_DHT_ClientGetMessage *get; 451 const struct GNUNET_DHT_ClientGetMessage *get;
470 struct ClientQueryRecord *cqr; 452 struct ClientQueryRecord *cqr;
471 size_t xquery_size; 453 size_t xquery_size;
472 const char* xquery; 454 const char *xquery;
473 uint16_t size; 455 uint16_t size;
474 456
475 size = ntohs (message->size); 457 size = ntohs (message->size);
476 if (size < sizeof (struct GNUNET_DHT_ClientGetMessage)) 458 if (size < sizeof (struct GNUNET_DHT_ClientGetMessage))
477 { 459 {
478 GNUNET_break (0); 460 GNUNET_break (0);
479 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 461 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
480 return; 462 return;
481 } 463 }
482 xquery_size = size - sizeof (struct GNUNET_DHT_ClientGetMessage); 464 xquery_size = size - sizeof (struct GNUNET_DHT_ClientGetMessage);
483 get = (const struct GNUNET_DHT_ClientGetMessage *) message; 465 get = (const struct GNUNET_DHT_ClientGetMessage *) message;
484 xquery = (const char*) &get[1]; 466 xquery = (const char *) &get[1];
485 GNUNET_STATISTICS_update (GDS_stats, 467 GNUNET_STATISTICS_update (GDS_stats,
486 gettext_noop ("# GET requests received from clients"), 1, 468 gettext_noop
469 ("# GET requests received from clients"), 1,
487 GNUNET_NO); 470 GNUNET_NO);
488#if DEBUG_DHT 471#if DEBUG_DHT
489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 472 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
490 "Received request for %s from local client %p\n", 473 "Received request for %s from local client %p\n",
491 GNUNET_h2s (&get->key), 474 GNUNET_h2s (&get->key), client);
492 client);
493#endif 475#endif
494 cqr = GNUNET_malloc (sizeof (struct ClientQueryRecord) + xquery_size); 476 cqr = GNUNET_malloc (sizeof (struct ClientQueryRecord) + xquery_size);
495 cqr->key = get->key; 477 cqr->key = get->key;
496 cqr->client = find_active_client (client); 478 cqr->client = find_active_client (client);
497 cqr->xquery = (void*) &cqr[1]; 479 cqr->xquery = (void *) &cqr[1];
498 memcpy (&cqr[1], xquery, xquery_size); 480 memcpy (&cqr[1], xquery, xquery_size);
499 cqr->hnode = GNUNET_CONTAINER_heap_insert (retry_heap, cqr, 0); 481 cqr->hnode = GNUNET_CONTAINER_heap_insert (retry_heap, cqr, 0);
500 cqr->retry_frequency = GNUNET_TIME_UNIT_MILLISECONDS; 482 cqr->retry_frequency = GNUNET_TIME_UNIT_MILLISECONDS;
501 cqr->retry_time = GNUNET_TIME_absolute_get (); 483 cqr->retry_time = GNUNET_TIME_absolute_get ();
502 cqr->unique_id = get->unique_id; 484 cqr->unique_id = get->unique_id;
503 cqr->xquery_size = xquery_size; 485 cqr->xquery_size = xquery_size;
504 cqr->replication = ntohl (get->desired_replication_level); 486 cqr->replication = ntohl (get->desired_replication_level);
505 cqr->msg_options = ntohl (get->options); 487 cqr->msg_options = ntohl (get->options);
506 cqr->type = ntohl (get->type); 488 cqr->type = ntohl (get->type);
507 GNUNET_CONTAINER_multihashmap_put (forward_map, &get->key, cqr, 489 GNUNET_CONTAINER_multihashmap_put (forward_map, &get->key, cqr,
508 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 490 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
509 /* start remote requests */ 491 /* start remote requests */
510 if (GNUNET_SCHEDULER_NO_TASK != retry_task) 492 if (GNUNET_SCHEDULER_NO_TASK != retry_task)
511 GNUNET_SCHEDULER_cancel (retry_task); 493 GNUNET_SCHEDULER_cancel (retry_task);
512 retry_task = GNUNET_SCHEDULER_add_now (&transmit_next_request_task, NULL); 494 retry_task = GNUNET_SCHEDULER_add_now (&transmit_next_request_task, NULL);
513 /* perform local lookup */ 495 /* perform local lookup */
514 GDS_DATACACHE_handle_get (&get->key, 496 GDS_DATACACHE_handle_get (&get->key, cqr->type, cqr->xquery, xquery_size,
515 cqr->type, 497 NULL, 0);
516 cqr->xquery,
517 xquery_size,
518 NULL, 0);
519 GNUNET_SERVER_receive_done (client, GNUNET_OK); 498 GNUNET_SERVER_receive_done (client, GNUNET_OK);
520} 499}
521 500
@@ -538,7 +517,7 @@ struct RemoveByUniqueIdContext
538 517
539 518
540/** 519/**
541 * Iterator over hash map entries that frees all entries 520 * Iterator over hash map entries that frees all entries
542 * that match the given client and unique ID. 521 * that match the given client and unique ID.
543 * 522 *
544 * @param cls unique ID and client to search for in source routes 523 * @param cls unique ID and client to search for in source routes
@@ -556,9 +535,8 @@ remove_by_unique_id (void *cls, const GNUNET_HashCode * key, void *value)
556 return GNUNET_YES; 535 return GNUNET_YES;
557#if DEBUG_DHT 536#if DEBUG_DHT
558 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 537 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
559 "Removing client %p's record for key %s (by unique id)\n", 538 "Removing client %p's record for key %s (by unique id)\n",
560 ctx->client->client_handle, 539 ctx->client->client_handle, GNUNET_h2s (key));
561 GNUNET_h2s (key));
562#endif 540#endif
563 return remove_client_records (ctx->client, key, record); 541 return remove_client_records (ctx->client, key, record);
564} 542}
@@ -575,27 +553,24 @@ remove_by_unique_id (void *cls, const GNUNET_HashCode * key, void *value)
575 */ 553 */
576static void 554static void
577handle_dht_local_get_stop (void *cls, struct GNUNET_SERVER_Client *client, 555handle_dht_local_get_stop (void *cls, struct GNUNET_SERVER_Client *client,
578 const struct GNUNET_MessageHeader *message) 556 const struct GNUNET_MessageHeader *message)
579{ 557{
580 const struct GNUNET_DHT_ClientGetStopMessage *dht_stop_msg = 558 const struct GNUNET_DHT_ClientGetStopMessage *dht_stop_msg =
581 (const struct GNUNET_DHT_ClientGetStopMessage *) message; 559 (const struct GNUNET_DHT_ClientGetStopMessage *) message;
582 struct RemoveByUniqueIdContext ctx; 560 struct RemoveByUniqueIdContext ctx;
583 561
584 GNUNET_STATISTICS_update (GDS_stats, 562 GNUNET_STATISTICS_update (GDS_stats,
585 gettext_noop ("# GET STOP requests received from clients"), 1, 563 gettext_noop
564 ("# GET STOP requests received from clients"), 1,
586 GNUNET_NO); 565 GNUNET_NO);
587#if DEBUG_DHT 566#if DEBUG_DHT
588 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 567 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p stopped request for key %s\n",
589 "Client %p stopped request for key %s\n", 568 client, GNUNET_h2s (&dht_stop_msg->key));
590 client,
591 GNUNET_h2s (&dht_stop_msg->key));
592#endif 569#endif
593 ctx.client = find_active_client (client); 570 ctx.client = find_active_client (client);
594 ctx.unique_id = dht_stop_msg->unique_id; 571 ctx.unique_id = dht_stop_msg->unique_id;
595 GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, 572 GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, &dht_stop_msg->key,
596 &dht_stop_msg->key, 573 &remove_by_unique_id, &ctx);
597 &remove_by_unique_id,
598 &ctx);
599 GNUNET_SERVER_receive_done (client, GNUNET_OK); 574 GNUNET_SERVER_receive_done (client, GNUNET_OK);
600} 575}
601 576
@@ -636,8 +611,8 @@ send_reply_to_client (void *cls, size_t size, void *buf)
636 /* client disconnected */ 611 /* client disconnected */
637#if DEBUG_DHT 612#if DEBUG_DHT
638 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 613 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
639 "Client %p disconnected, pending messages will be discarded\n", 614 "Client %p disconnected, pending messages will be discarded\n",
640 client->client_handle); 615 client->client_handle);
641#endif 616#endif
642 return 0; 617 return 0;
643 } 618 }
@@ -650,20 +625,15 @@ send_reply_to_client (void *cls, size_t size, void *buf)
650 memcpy (&cbuf[off], reply->msg, msize); 625 memcpy (&cbuf[off], reply->msg, msize);
651 GNUNET_free (reply); 626 GNUNET_free (reply);
652#if DEBUG_DHT 627#if DEBUG_DHT
653 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 628 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting %u bytes to client %p\n",
654 "Transmitting %u bytes to client %p\n", 629 msize, client->client_handle);
655 msize,
656 client->client_handle);
657#endif 630#endif
658 off += msize; 631 off += msize;
659 } 632 }
660 process_pending_messages (client); 633 process_pending_messages (client);
661#if DEBUG_DHT 634#if DEBUG_DHT
662 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 635 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitted %u/%u bytes to client %p\n",
663 "Transmitted %u/%u bytes to client %p\n", 636 (unsigned int) off, (unsigned int) size, client->client_handle);
664 (unsigned int) off,
665 (unsigned int) size,
666 client->client_handle);
667#endif 637#endif
668 return off; 638 return off;
669} 639}
@@ -681,20 +651,17 @@ process_pending_messages (struct ClientList *client)
681 { 651 {
682#if DEBUG_DHT 652#if DEBUG_DHT
683 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 653 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
684 "Not asking for transmission to %p now: %s\n", 654 "Not asking for transmission to %p now: %s\n",
685 client->client_handle, 655 client->client_handle,
686 client->pending_head == NULL 656 client->pending_head ==
687 ? "no more messages" 657 NULL ? "no more messages" : "request already pending");
688 : "request already pending");
689#endif 658#endif
690 return; 659 return;
691 } 660 }
692#if DEBUG_DHT 661#if DEBUG_DHT
693 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 662 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
694 "Asking for transmission of %u bytes to client %p\n", 663 "Asking for transmission of %u bytes to client %p\n",
695 ntohs (client->pending_head-> 664 ntohs (client->pending_head->msg->size), client->client_handle);
696 msg->size),
697 client->client_handle);
698#endif 665#endif
699 client->transmit_handle = 666 client->transmit_handle =
700 GNUNET_SERVER_notify_transmit_ready (client->client_handle, 667 GNUNET_SERVER_notify_transmit_ready (client->client_handle,
@@ -716,7 +683,7 @@ add_pending_message (struct ClientList *client,
716 struct PendingMessage *pending_message) 683 struct PendingMessage *pending_message)
717{ 684{
718 GNUNET_CONTAINER_DLL_insert_tail (client->pending_head, client->pending_tail, 685 GNUNET_CONTAINER_DLL_insert_tail (client->pending_head, client->pending_tail,
719 pending_message); 686 pending_message);
720 process_pending_messages (client); 687 process_pending_messages (client);
721} 688}
722 689
@@ -728,7 +695,7 @@ struct ForwardReplyContext
728{ 695{
729 696
730 /** 697 /**
731 * Actual message to send to matching clients. 698 * Actual message to send to matching clients.
732 */ 699 */
733 struct PendingMessage *pm; 700 struct PendingMessage *pm;
734 701
@@ -777,51 +744,43 @@ forward_reply (void *cls, const GNUNET_HashCode * key, void *value)
777 int do_free; 744 int do_free;
778 GNUNET_HashCode ch; 745 GNUNET_HashCode ch;
779 unsigned int i; 746 unsigned int i;
780 747
781 if ( (record->type != GNUNET_BLOCK_TYPE_ANY) && 748 if ((record->type != GNUNET_BLOCK_TYPE_ANY) && (record->type != frc->type))
782 (record->type != frc->type) ) 749 {
750#if DEBUG_DHT
751 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
752 "Record type missmatch, not passing request for key %s to local client\n",
753 GNUNET_h2s (key));
754#endif
755 GNUNET_STATISTICS_update (GDS_stats,
756 gettext_noop
757 ("# Key match, type mismatches in REPLY to CLIENT"),
758 1, GNUNET_NO);
759 return GNUNET_YES; /* type mismatch */
760 }
761 GNUNET_CRYPTO_hash (frc->data, frc->data_size, &ch);
762 for (i = 0; i < record->seen_replies_count; i++)
763 if (0 == memcmp (&record->seen_replies[i], &ch, sizeof (GNUNET_HashCode)))
783 { 764 {
784#if DEBUG_DHT 765#if DEBUG_DHT
785 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 766 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
786 "Record type missmatch, not passing request for key %s to local client\n", 767 "Duplicate reply, not passing request for key %s to local client\n",
787 GNUNET_h2s (key)); 768 GNUNET_h2s (key));
788#endif 769#endif
789 GNUNET_STATISTICS_update (GDS_stats, 770 GNUNET_STATISTICS_update (GDS_stats,
790 gettext_noop ("# Key match, type mismatches in REPLY to CLIENT"), 1, 771 gettext_noop
791 GNUNET_NO); 772 ("# Duplicate REPLIES to CLIENT request dropped"),
792 return GNUNET_YES; /* type mismatch */ 773 1, GNUNET_NO);
774 return GNUNET_YES; /* duplicate */
793 } 775 }
794 GNUNET_CRYPTO_hash (frc->data,
795 frc->data_size,
796 &ch);
797 for (i=0;i<record->seen_replies_count;i++)
798 if (0 == memcmp (&record->seen_replies[i],
799 &ch,
800 sizeof (GNUNET_HashCode)))
801 {
802#if DEBUG_DHT
803 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
804 "Duplicate reply, not passing request for key %s to local client\n",
805 GNUNET_h2s (key));
806#endif
807 GNUNET_STATISTICS_update (GDS_stats,
808 gettext_noop ("# Duplicate REPLIES to CLIENT request dropped"), 1,
809 GNUNET_NO);
810 return GNUNET_YES; /* duplicate */
811 }
812 eval = 776 eval =
813 GNUNET_BLOCK_evaluate (GDS_block_context, 777 GNUNET_BLOCK_evaluate (GDS_block_context, record->type, key, NULL, 0,
814 record->type, key, 778 record->xquery, record->xquery_size, frc->data,
815 NULL, 0, 779 frc->data_size);
816 record->xquery,
817 record->xquery_size,
818 frc->data,
819 frc->data_size);
820#if DEBUG_DHT 780#if DEBUG_DHT
821 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 781 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
822 "Evaluation result is %d for key %s for local client's query\n", 782 "Evaluation result is %d for key %s for local client's query\n",
823 (int) eval, 783 (int) eval, GNUNET_h2s (key));
824 GNUNET_h2s (key));
825#endif 784#endif
826 switch (eval) 785 switch (eval)
827 { 786 {
@@ -829,9 +788,7 @@ forward_reply (void *cls, const GNUNET_HashCode * key, void *value)
829 do_free = GNUNET_YES; 788 do_free = GNUNET_YES;
830 break; 789 break;
831 case GNUNET_BLOCK_EVALUATION_OK_MORE: 790 case GNUNET_BLOCK_EVALUATION_OK_MORE:
832 GNUNET_array_append (record->seen_replies, 791 GNUNET_array_append (record->seen_replies, record->seen_replies_count, ch);
833 record->seen_replies_count,
834 ch);
835 do_free = GNUNET_NO; 792 do_free = GNUNET_NO;
836 break; 793 break;
837 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: 794 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
@@ -849,38 +806,36 @@ forward_reply (void *cls, const GNUNET_HashCode * key, void *value)
849 return GNUNET_NO; 806 return GNUNET_NO;
850 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: 807 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
851 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 808 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
852 _("Unsupported block type (%u) in request!\n"), 809 _("Unsupported block type (%u) in request!\n"), record->type);
853 record->type);
854 return GNUNET_NO; 810 return GNUNET_NO;
855 default: 811 default:
856 GNUNET_break (0); 812 GNUNET_break (0);
857 return GNUNET_NO; 813 return GNUNET_NO;
858 } 814 }
859 if (GNUNET_NO == frc->do_copy) 815 if (GNUNET_NO == frc->do_copy)
860 { 816 {
861 /* first time, we can use the original data */ 817 /* first time, we can use the original data */
862 pm = frc->pm; 818 pm = frc->pm;
863 frc->do_copy = GNUNET_YES; 819 frc->do_copy = GNUNET_YES;
864 } 820 }
865 else 821 else
866 { 822 {
867 /* two clients waiting for same reply, must copy for queueing */ 823 /* two clients waiting for same reply, must copy for queueing */
868 pm = GNUNET_malloc (sizeof (struct PendingMessage) + 824 pm = GNUNET_malloc (sizeof (struct PendingMessage) +
869 ntohs (frc->pm->msg->size)); 825 ntohs (frc->pm->msg->size));
870 memcpy (pm, frc->pm, 826 memcpy (pm, frc->pm,
871 sizeof (struct PendingMessage) + ntohs (frc->pm->msg->size)); 827 sizeof (struct PendingMessage) + ntohs (frc->pm->msg->size));
872 pm->next = pm->prev = NULL; 828 pm->next = pm->prev = NULL;
873 } 829 }
874 GNUNET_STATISTICS_update (GDS_stats, 830 GNUNET_STATISTICS_update (GDS_stats,
875 gettext_noop ("# RESULTS queued for clients"), 1, 831 gettext_noop ("# RESULTS queued for clients"), 1,
876 GNUNET_NO); 832 GNUNET_NO);
877 reply = (struct GNUNET_DHT_ClientResultMessage*) &pm[1]; 833 reply = (struct GNUNET_DHT_ClientResultMessage *) &pm[1];
878 reply->unique_id = record->unique_id; 834 reply->unique_id = record->unique_id;
879#if DEBUG_DHT 835#if DEBUG_DHT
880 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 836 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
881 "Queueing reply to query %s for client %p\n", 837 "Queueing reply to query %s for client %p\n", GNUNET_h2s (key),
882 GNUNET_h2s (key), 838 record->client->client_handle);
883 record->client->client_handle);
884#endif 839#endif
885 add_pending_message (record->client, pm); 840 add_pending_message (record->client, pm);
886 if (GNUNET_YES == do_free) 841 if (GNUNET_YES == do_free)
@@ -906,14 +861,13 @@ forward_reply (void *cls, const GNUNET_HashCode * key, void *value)
906 */ 861 */
907void 862void
908GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, 863GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration,
909 const GNUNET_HashCode *key, 864 const GNUNET_HashCode * key,
910 unsigned int get_path_length, 865 unsigned int get_path_length,
911 const struct GNUNET_PeerIdentity *get_path, 866 const struct GNUNET_PeerIdentity *get_path,
912 unsigned int put_path_length, 867 unsigned int put_path_length,
913 const struct GNUNET_PeerIdentity *put_path, 868 const struct GNUNET_PeerIdentity *put_path,
914 enum GNUNET_BLOCK_Type type, 869 enum GNUNET_BLOCK_Type type, size_t data_size,
915 size_t data_size, 870 const void *data)
916 const void *data)
917{ 871{
918 struct ForwardReplyContext frc; 872 struct ForwardReplyContext frc;
919 struct PendingMessage *pm; 873 struct PendingMessage *pm;
@@ -921,57 +875,57 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration,
921 struct GNUNET_PeerIdentity *paths; 875 struct GNUNET_PeerIdentity *paths;
922 size_t msize; 876 size_t msize;
923 877
924 if (NULL == 878 if (NULL == GNUNET_CONTAINER_multihashmap_get (forward_map, key))
925 GNUNET_CONTAINER_multihashmap_get (forward_map, key))
926 { 879 {
927 GNUNET_STATISTICS_update (GDS_stats, 880 GNUNET_STATISTICS_update (GDS_stats,
928 gettext_noop ("# REPLIES ignored for CLIENTS (no match)"), 1, 881 gettext_noop
929 GNUNET_NO); 882 ("# REPLIES ignored for CLIENTS (no match)"), 1,
930 return; /* no matching request, fast exit! */ 883 GNUNET_NO);
884 return; /* no matching request, fast exit! */
931 } 885 }
932 msize = sizeof(struct GNUNET_DHT_ClientResultMessage) + data_size + 886 msize =
933 (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity); 887 sizeof (struct GNUNET_DHT_ClientResultMessage) + data_size +
888 (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity);
934 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 889 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
935 { 890 {
936 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 891 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
937 _("Could not pass reply to client, message too big!\n")); 892 _("Could not pass reply to client, message too big!\n"));
938 return; 893 return;
939 } 894 }
940 pm = (struct PendingMessage *) GNUNET_malloc (msize + sizeof (struct PendingMessage)); 895 pm = (struct PendingMessage *) GNUNET_malloc (msize +
941 reply = (struct GNUNET_DHT_ClientResultMessage*) &pm[1]; 896 sizeof (struct PendingMessage));
897 reply = (struct GNUNET_DHT_ClientResultMessage *) &pm[1];
942 pm->msg = &reply->header; 898 pm->msg = &reply->header;
943 reply->header.size = htons ((uint16_t) msize); 899 reply->header.size = htons ((uint16_t) msize);
944 reply->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT); 900 reply->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT);
945 reply->type = htonl (type); 901 reply->type = htonl (type);
946 reply->get_path_length = htonl (get_path_length); 902 reply->get_path_length = htonl (get_path_length);
947 reply->put_path_length = htonl (put_path_length); 903 reply->put_path_length = htonl (put_path_length);
948 reply->unique_id = 0; /* filled in later */ 904 reply->unique_id = 0; /* filled in later */
949 reply->expiration = GNUNET_TIME_absolute_hton (expiration); 905 reply->expiration = GNUNET_TIME_absolute_hton (expiration);
950 reply->key = *key; 906 reply->key = *key;
951 paths = (struct GNUNET_PeerIdentity*) &reply[1]; 907 paths = (struct GNUNET_PeerIdentity *) &reply[1];
952 memcpy (paths, put_path, 908 memcpy (paths, put_path,
953 sizeof (struct GNUNET_PeerIdentity) * put_path_length); 909 sizeof (struct GNUNET_PeerIdentity) * put_path_length);
954 memcpy (&paths[put_path_length], 910 memcpy (&paths[put_path_length], get_path,
955 get_path, sizeof (struct GNUNET_PeerIdentity) * get_path_length); 911 sizeof (struct GNUNET_PeerIdentity) * get_path_length);
956 memcpy (&paths[get_path_length + put_path_length], 912 memcpy (&paths[get_path_length + put_path_length], data, data_size);
957 data,
958 data_size);
959 frc.do_copy = GNUNET_NO; 913 frc.do_copy = GNUNET_NO;
960 frc.pm = pm; 914 frc.pm = pm;
961 frc.data = data; 915 frc.data = data;
962 frc.data_size = data_size; 916 frc.data_size = data_size;
963 frc.type = type; 917 frc.type = type;
964 GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, key, 918 GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, key, &forward_reply,
965 &forward_reply, 919 &frc);
966 &frc);
967 if (GNUNET_NO == frc.do_copy) 920 if (GNUNET_NO == frc.do_copy)
968 { 921 {
969 /* did not match any of the requests, free! */ 922 /* did not match any of the requests, free! */
970 GNUNET_STATISTICS_update (GDS_stats, 923 GNUNET_STATISTICS_update (GDS_stats,
971 gettext_noop ("# REPLIES ignored for CLIENTS (no match)"), 1, 924 gettext_noop
972 GNUNET_NO); 925 ("# REPLIES ignored for CLIENTS (no match)"), 1,
973 GNUNET_free (pm); 926 GNUNET_NO);
974 } 927 GNUNET_free (pm);
928 }
975} 929}
976 930
977 931
@@ -980,17 +934,17 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration,
980 * 934 *
981 * @param server the initialized server 935 * @param server the initialized server
982 */ 936 */
983void 937void
984GDS_CLIENTS_init (struct GNUNET_SERVER_Handle *server) 938GDS_CLIENTS_init (struct GNUNET_SERVER_Handle *server)
985{ 939{
986 static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { 940 static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = {
987 {&handle_dht_local_put, NULL, 941 {&handle_dht_local_put, NULL,
988 GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT, 0}, 942 GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT, 0},
989 {&handle_dht_local_get, NULL, 943 {&handle_dht_local_get, NULL,
990 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET, 0}, 944 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET, 0},
991 {&handle_dht_local_get_stop, NULL, 945 {&handle_dht_local_get_stop, NULL,
992 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP, 946 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP,
993 sizeof (struct GNUNET_DHT_ClientGetStopMessage) }, 947 sizeof (struct GNUNET_DHT_ClientGetStopMessage)},
994 {NULL, NULL, 0, 0} 948 {NULL, NULL, 0, 0}
995 }; 949 };
996 forward_map = GNUNET_CONTAINER_multihashmap_create (1024); 950 forward_map = GNUNET_CONTAINER_multihashmap_create (1024);
@@ -1009,10 +963,10 @@ GDS_CLIENTS_done ()
1009 GNUNET_assert (client_head == NULL); 963 GNUNET_assert (client_head == NULL);
1010 GNUNET_assert (client_tail == NULL); 964 GNUNET_assert (client_tail == NULL);
1011 if (GNUNET_SCHEDULER_NO_TASK != retry_task) 965 if (GNUNET_SCHEDULER_NO_TASK != retry_task)
1012 { 966 {
1013 GNUNET_SCHEDULER_cancel (retry_task); 967 GNUNET_SCHEDULER_cancel (retry_task);
1014 retry_task = GNUNET_SCHEDULER_NO_TASK; 968 retry_task = GNUNET_SCHEDULER_NO_TASK;
1015 } 969 }
1016 GNUNET_assert (0 == GNUNET_CONTAINER_heap_get_size (retry_heap)); 970 GNUNET_assert (0 == GNUNET_CONTAINER_heap_get_size (retry_heap));
1017 GNUNET_CONTAINER_heap_destroy (retry_heap); 971 GNUNET_CONTAINER_heap_destroy (retry_heap);
1018 retry_heap = NULL; 972 retry_heap = NULL;
@@ -1022,4 +976,3 @@ GDS_CLIENTS_done ()
1022} 976}
1023 977
1024/* end of gnunet-service-dht_clients.c */ 978/* end of gnunet-service-dht_clients.c */
1025
diff --git a/src/dht/gnunet-service-dht_clients.h b/src/dht/gnunet-service-dht_clients.h
index 66fa433c0..21b2343e7 100644
--- a/src/dht/gnunet-service-dht_clients.h
+++ b/src/dht/gnunet-service-dht_clients.h
@@ -47,14 +47,13 @@
47 */ 47 */
48void 48void
49GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, 49GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration,
50 const GNUNET_HashCode *key, 50 const GNUNET_HashCode * key,
51 unsigned int get_path_length, 51 unsigned int get_path_length,
52 const struct GNUNET_PeerIdentity *get_path, 52 const struct GNUNET_PeerIdentity *get_path,
53 unsigned int put_path_length, 53 unsigned int put_path_length,
54 const struct GNUNET_PeerIdentity *put_path, 54 const struct GNUNET_PeerIdentity *put_path,
55 enum GNUNET_BLOCK_Type type, 55 enum GNUNET_BLOCK_Type type, size_t data_size,
56 size_t data_size, 56 const void *data);
57 const void *data);
58 57
59 58
60/** 59/**
@@ -62,7 +61,7 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration,
62 * 61 *
63 * @param server the initialized server 62 * @param server the initialized server
64 */ 63 */
65void 64void
66GDS_CLIENTS_init (struct GNUNET_SERVER_Handle *server); 65GDS_CLIENTS_init (struct GNUNET_SERVER_Handle *server);
67 66
68 67
diff --git a/src/dht/gnunet-service-dht_datacache.c b/src/dht/gnunet-service-dht_datacache.c
index f3b2e5b2f..82cd06727 100644
--- a/src/dht/gnunet-service-dht_datacache.c
+++ b/src/dht/gnunet-service-dht_datacache.c
@@ -74,44 +74,42 @@ struct DHTPutEntry
74 */ 74 */
75void 75void
76GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, 76GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration,
77 const GNUNET_HashCode *key, 77 const GNUNET_HashCode * key,
78 unsigned int put_path_length, 78 unsigned int put_path_length,
79 const struct GNUNET_PeerIdentity *put_path, 79 const struct GNUNET_PeerIdentity *put_path,
80 enum GNUNET_BLOCK_Type type, 80 enum GNUNET_BLOCK_Type type, size_t data_size,
81 size_t data_size, 81 const void *data)
82 const void *data)
83{ 82{
84 size_t plen = data_size + put_path_length * sizeof(struct GNUNET_PeerIdentity) + sizeof(struct DHTPutEntry); 83 size_t plen =
84 data_size + put_path_length * sizeof (struct GNUNET_PeerIdentity) +
85 sizeof (struct DHTPutEntry);
85 char buf[plen]; 86 char buf[plen];
86 struct DHTPutEntry *pe; 87 struct DHTPutEntry *pe;
87 struct GNUNET_PeerIdentity *pp; 88 struct GNUNET_PeerIdentity *pp;
88 89
89 if (datacache == NULL) 90 if (datacache == NULL)
90 { 91 {
91 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 92 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
92 _("%s request received, but have no datacache!\n"), 93 _("%s request received, but have no datacache!\n"), "PUT");
93 "PUT"); 94 return;
94 return; 95 }
95 }
96 if (data_size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 96 if (data_size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
97 { 97 {
98 GNUNET_break (0); 98 GNUNET_break (0);
99 return; 99 return;
100 } 100 }
101 /* Put size is actual data size plus struct overhead plus path length (if any) */ 101 /* Put size is actual data size plus struct overhead plus path length (if any) */
102 GNUNET_STATISTICS_update (GDS_stats, 102 GNUNET_STATISTICS_update (GDS_stats,
103 gettext_noop ("# ITEMS stored in datacache"), 1, 103 gettext_noop ("# ITEMS stored in datacache"), 1,
104 GNUNET_NO); 104 GNUNET_NO);
105 pe = (struct DHTPutEntry *) buf; 105 pe = (struct DHTPutEntry *) buf;
106 pe->data_size = htons (data_size); 106 pe->data_size = htons (data_size);
107 pe->path_length = htons ((uint16_t) put_path_length); 107 pe->path_length = htons ((uint16_t) put_path_length);
108 pp = (struct GNUNET_PeerIdentity *) &pe[1]; 108 pp = (struct GNUNET_PeerIdentity *) &pe[1];
109 memcpy (pp, put_path, put_path_length * sizeof (struct GNUNET_PeerIdentity)); 109 memcpy (pp, put_path, put_path_length * sizeof (struct GNUNET_PeerIdentity));
110 memcpy (&pp[put_path_length], 110 memcpy (&pp[put_path_length], data, data_size);
111 data, data_size); 111 (void) GNUNET_DATACACHE_put (datacache, key, plen, (const char *) pe, type,
112 (void) GNUNET_DATACACHE_put (datacache, key, 112 expiration);
113 plen, (const char *) pe, type,
114 expiration);
115} 113}
116 114
117 115
@@ -190,20 +188,15 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
190 return GNUNET_OK; 188 return GNUNET_OK;
191 } 189 }
192 pp = (const struct GNUNET_PeerIdentity *) &pe[1]; 190 pp = (const struct GNUNET_PeerIdentity *) &pe[1];
193 rdata = (const char*) &pp[put_path_length]; 191 rdata = (const char *) &pp[put_path_length];
194 eval = 192 eval =
195 GNUNET_BLOCK_evaluate (GDS_block_context, type, key, 193 GNUNET_BLOCK_evaluate (GDS_block_context, type, key, ctx->reply_bf,
196 ctx->reply_bf, 194 ctx->reply_bf_mutator, ctx->xquery,
197 ctx->reply_bf_mutator, 195 ctx->xquery_size, rdata, rdata_size);
198 ctx->xquery,
199 ctx->xquery_size,
200 rdata,
201 rdata_size);
202#if DEBUG_DHT 196#if DEBUG_DHT
203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
204 "Found reply for query %s in datacache, evaluation result is %d\n", 198 "Found reply for query %s in datacache, evaluation result is %d\n",
205 GNUNET_h2s (key), 199 GNUNET_h2s (key), (int) eval);
206 (int) eval);
207#endif 200#endif
208 ctx->eval = eval; 201 ctx->eval = eval;
209 switch (eval) 202 switch (eval)
@@ -212,27 +205,26 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
212 case GNUNET_BLOCK_EVALUATION_OK_MORE: 205 case GNUNET_BLOCK_EVALUATION_OK_MORE:
213 /* forward to local clients */ 206 /* forward to local clients */
214 GNUNET_STATISTICS_update (GDS_stats, 207 GNUNET_STATISTICS_update (GDS_stats,
215 gettext_noop ("# Good RESULTS found in datacache"), 1, 208 gettext_noop
216 GNUNET_NO); 209 ("# Good RESULTS found in datacache"), 1,
217 GDS_CLIENTS_handle_reply (exp, 210 GNUNET_NO);
218 key, 211 GDS_CLIENTS_handle_reply (exp, key, 0, NULL, put_path_length, pp, type,
219 0, NULL, 212 rdata_size, rdata);
220 put_path_length, pp,
221 type, rdata_size, rdata);
222 /* forward to other peers */ 213 /* forward to other peers */
223 GDS_ROUTING_process (type, exp, 214 GDS_ROUTING_process (type, exp, key, put_path_length, pp, 0, NULL, rdata,
224 key, put_path_length, pp, 215 rdata_size);
225 0, NULL, rdata, rdata_size);
226 break; 216 break;
227 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: 217 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
228 GNUNET_STATISTICS_update (GDS_stats, 218 GNUNET_STATISTICS_update (GDS_stats,
229 gettext_noop ("# Duplicate RESULTS found in datacache"), 1, 219 gettext_noop
230 GNUNET_NO); 220 ("# Duplicate RESULTS found in datacache"), 1,
221 GNUNET_NO);
231 break; 222 break;
232 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: 223 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
233 GNUNET_STATISTICS_update (GDS_stats, 224 GNUNET_STATISTICS_update (GDS_stats,
234 gettext_noop ("# Invalid RESULTS found in datacache"), 1, 225 gettext_noop
235 GNUNET_NO); 226 ("# Invalid RESULTS found in datacache"), 1,
227 GNUNET_NO);
236 break; 228 break;
237 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: 229 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
238 GNUNET_break (0); 230 GNUNET_break (0);
@@ -242,11 +234,11 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
242 return GNUNET_SYSERR; 234 return GNUNET_SYSERR;
243 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: 235 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
244 GNUNET_STATISTICS_update (GDS_stats, 236 GNUNET_STATISTICS_update (GDS_stats,
245 gettext_noop ("# Unsupported RESULTS found in datacache"), 1, 237 gettext_noop
246 GNUNET_NO); 238 ("# Unsupported RESULTS found in datacache"), 1,
239 GNUNET_NO);
247 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 240 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
248 _("Unsupported block type (%u) in local response!\n"), 241 _("Unsupported block type (%u) in local response!\n"), type);
249 type);
250 break; 242 break;
251 } 243 }
252 return (eval == GNUNET_BLOCK_EVALUATION_OK_LAST) ? GNUNET_NO : GNUNET_OK; 244 return (eval == GNUNET_BLOCK_EVALUATION_OK_LAST) ? GNUNET_NO : GNUNET_OK;
@@ -256,7 +248,7 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
256/** 248/**
257 * Handle a GET request we've received from another peer. 249 * Handle a GET request we've received from another peer.
258 * 250 *
259 * @param key the query 251 * @param key the query
260 * @param type requested data type 252 * @param type requested data type
261 * @param xquery extended query 253 * @param xquery extended query
262 * @param xquery_size number of bytes in xquery 254 * @param xquery_size number of bytes in xquery
@@ -265,28 +257,27 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
265 * @return evaluation result for the local replies 257 * @return evaluation result for the local replies
266 */ 258 */
267enum GNUNET_BLOCK_EvaluationResult 259enum GNUNET_BLOCK_EvaluationResult
268GDS_DATACACHE_handle_get (const GNUNET_HashCode *key, 260GDS_DATACACHE_handle_get (const GNUNET_HashCode * key,
269 enum GNUNET_BLOCK_Type type, 261 enum GNUNET_BLOCK_Type type, const void *xquery,
270 const void *xquery, 262 size_t xquery_size,
271 size_t xquery_size, 263 struct GNUNET_CONTAINER_BloomFilter **reply_bf,
272 struct GNUNET_CONTAINER_BloomFilter **reply_bf, 264 uint32_t reply_bf_mutator)
273 uint32_t reply_bf_mutator)
274{ 265{
275 struct GetRequestContext ctx; 266 struct GetRequestContext ctx;
276 267
277 if (datacache == NULL) 268 if (datacache == NULL)
278 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 269 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
279 GNUNET_STATISTICS_update (GDS_stats, 270 GNUNET_STATISTICS_update (GDS_stats,
280 gettext_noop ("# GET requests given to datacache"), 1, 271 gettext_noop ("# GET requests given to datacache"),
281 GNUNET_NO); 272 1, GNUNET_NO);
282 ctx.eval = GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 273 ctx.eval = GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
283 ctx.key = *key; 274 ctx.key = *key;
284 ctx.xquery = xquery; 275 ctx.xquery = xquery;
285 ctx.xquery_size = xquery_size; 276 ctx.xquery_size = xquery_size;
286 ctx.reply_bf = reply_bf; 277 ctx.reply_bf = reply_bf;
287 ctx.reply_bf_mutator = reply_bf_mutator; 278 ctx.reply_bf_mutator = reply_bf_mutator;
288 (void) GNUNET_DATACACHE_get (datacache, key, type, 279 (void) GNUNET_DATACACHE_get (datacache, key, type, &datacache_get_iterator,
289 &datacache_get_iterator, &ctx); 280 &ctx);
290 return ctx.eval; 281 return ctx.eval;
291} 282}
292 283
@@ -294,7 +285,7 @@ GDS_DATACACHE_handle_get (const GNUNET_HashCode *key,
294/** 285/**
295 * Initialize datacache subsystem. 286 * Initialize datacache subsystem.
296 */ 287 */
297void 288void
298GDS_DATACACHE_init () 289GDS_DATACACHE_init ()
299{ 290{
300 datacache = GNUNET_DATACACHE_create (GDS_cfg, "dhtcache"); 291 datacache = GNUNET_DATACACHE_create (GDS_cfg, "dhtcache");
diff --git a/src/dht/gnunet-service-dht_datacache.h b/src/dht/gnunet-service-dht_datacache.h
index ccd854570..926ad5326 100644
--- a/src/dht/gnunet-service-dht_datacache.h
+++ b/src/dht/gnunet-service-dht_datacache.h
@@ -44,18 +44,17 @@
44 */ 44 */
45void 45void
46GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, 46GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration,
47 const GNUNET_HashCode *key, 47 const GNUNET_HashCode * key,
48 unsigned int put_path_length, 48 unsigned int put_path_length,
49 const struct GNUNET_PeerIdentity *put_path, 49 const struct GNUNET_PeerIdentity *put_path,
50 enum GNUNET_BLOCK_Type type, 50 enum GNUNET_BLOCK_Type type, size_t data_size,
51 size_t data_size, 51 const void *data);
52 const void *data);
53 52
54 53
55/** 54/**
56 * Handle a GET request we've received from another peer. 55 * Handle a GET request we've received from another peer.
57 * 56 *
58 * @param key the query 57 * @param key the query
59 * @param type requested data type 58 * @param type requested data type
60 * @param xquery extended query 59 * @param xquery extended query
61 * @param xquery_size number of bytes in xquery 60 * @param xquery_size number of bytes in xquery
@@ -63,19 +62,18 @@ GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration,
63 * @param reply_bf_mutator mutation value for reply_bf 62 * @param reply_bf_mutator mutation value for reply_bf
64 * @return evaluation result for the local replies 63 * @return evaluation result for the local replies
65 */ 64 */
66enum GNUNET_BLOCK_EvaluationResult 65enum GNUNET_BLOCK_EvaluationResult
67GDS_DATACACHE_handle_get (const GNUNET_HashCode *key, 66GDS_DATACACHE_handle_get (const GNUNET_HashCode * key,
68 enum GNUNET_BLOCK_Type type, 67 enum GNUNET_BLOCK_Type type, const void *xquery,
69 const void *xquery, 68 size_t xquery_size,
70 size_t xquery_size, 69 struct GNUNET_CONTAINER_BloomFilter **reply_bf,
71 struct GNUNET_CONTAINER_BloomFilter **reply_bf, 70 uint32_t reply_bf_mutator);
72 uint32_t reply_bf_mutator);
73 71
74 72
75/** 73/**
76 * Initialize datacache subsystem. 74 * Initialize datacache subsystem.
77 */ 75 */
78void 76void
79GDS_DATACACHE_init (void); 77GDS_DATACACHE_init (void);
80 78
81 79
diff --git a/src/dht/gnunet-service-dht_hello.c b/src/dht/gnunet-service-dht_hello.c
index 5be0cbfec..578e651f8 100644
--- a/src/dht/gnunet-service-dht_hello.c
+++ b/src/dht/gnunet-service-dht_hello.c
@@ -54,8 +54,7 @@ GDS_HELLO_get (const struct GNUNET_PeerIdentity *peer)
54{ 54{
55 if (NULL == peer_to_hello) 55 if (NULL == peer_to_hello)
56 return NULL; 56 return NULL;
57 return GNUNET_CONTAINER_multihashmap_get (peer_to_hello, 57 return GNUNET_CONTAINER_multihashmap_get (peer_to_hello, &peer->hashPubKey);
58 &peer->hashPubKey);
59} 58}
60 59
61 60
@@ -68,11 +67,8 @@ GDS_HELLO_get (const struct GNUNET_PeerIdentity *peer)
68 * @param error message 67 * @param error message
69 */ 68 */
70static void 69static void
71process_hello (void *cls, 70process_hello (void *cls, const struct GNUNET_PeerIdentity *peer,
72 const struct GNUNET_PeerIdentity * 71 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
73 peer,
74 const struct GNUNET_HELLO_Message *
75 hello, const char *err_msg)
76{ 72{
77 struct GNUNET_TIME_Absolute ex; 73 struct GNUNET_TIME_Absolute ex;
78 struct GNUNET_HELLO_Message *hm; 74 struct GNUNET_HELLO_Message *hm;
@@ -83,18 +79,16 @@ process_hello (void *cls,
83 if (GNUNET_TIME_absolute_get_remaining (ex).rel_value == 0) 79 if (GNUNET_TIME_absolute_get_remaining (ex).rel_value == 0)
84 return; 80 return;
85 GNUNET_STATISTICS_update (GDS_stats, 81 GNUNET_STATISTICS_update (GDS_stats,
86 gettext_noop ("# HELLOs obtained from peerinfo"), 1, 82 gettext_noop ("# HELLOs obtained from peerinfo"), 1,
87 GNUNET_NO); 83 GNUNET_NO);
88 hm = GNUNET_CONTAINER_multihashmap_get (peer_to_hello, 84 hm = GNUNET_CONTAINER_multihashmap_get (peer_to_hello, &peer->hashPubKey);
89 &peer->hashPubKey);
90 GNUNET_free_non_null (hm); 85 GNUNET_free_non_null (hm);
91 hm = GNUNET_malloc (GNUNET_HELLO_size (hello)); 86 hm = GNUNET_malloc (GNUNET_HELLO_size (hello));
92 memcpy (hm, hello, GNUNET_HELLO_size (hello)); 87 memcpy (hm, hello, GNUNET_HELLO_size (hello));
93 GNUNET_assert (GNUNET_SYSERR != 88 GNUNET_assert (GNUNET_SYSERR !=
94 GNUNET_CONTAINER_multihashmap_put (peer_to_hello, 89 GNUNET_CONTAINER_multihashmap_put (peer_to_hello,
95 &peer->hashPubKey, 90 &peer->hashPubKey, hm,
96 hm, 91 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
97 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
98} 92}
99 93
100 94
@@ -104,9 +98,7 @@ process_hello (void *cls,
104void 98void
105GDS_HELLO_init () 99GDS_HELLO_init ()
106{ 100{
107 pnc = GNUNET_PEERINFO_notify (GDS_cfg, 101 pnc = GNUNET_PEERINFO_notify (GDS_cfg, &process_hello, NULL);
108 &process_hello,
109 NULL);
110 peer_to_hello = GNUNET_CONTAINER_multihashmap_create (256); 102 peer_to_hello = GNUNET_CONTAINER_multihashmap_create (256);
111} 103}
112 104
@@ -115,9 +107,7 @@ GDS_HELLO_init ()
115 * Free memory occopied by the HELLO. 107 * Free memory occopied by the HELLO.
116 */ 108 */
117static int 109static int
118free_hello (void *cls, 110free_hello (void *cls, const GNUNET_HashCode * key, void *hello)
119 const GNUNET_HashCode *key,
120 void *hello)
121{ 111{
122 GNUNET_free (hello); 112 GNUNET_free (hello);
123 return GNUNET_OK; 113 return GNUNET_OK;
@@ -137,9 +127,7 @@ GDS_HELLO_done ()
137 } 127 }
138 if (NULL != peer_to_hello) 128 if (NULL != peer_to_hello)
139 { 129 {
140 GNUNET_CONTAINER_multihashmap_iterate (peer_to_hello, 130 GNUNET_CONTAINER_multihashmap_iterate (peer_to_hello, &free_hello, NULL);
141 &free_hello,
142 NULL);
143 GNUNET_CONTAINER_multihashmap_destroy (peer_to_hello); 131 GNUNET_CONTAINER_multihashmap_destroy (peer_to_hello);
144 } 132 }
145} 133}
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c
index 02124b488..9ebf16400 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -275,7 +275,7 @@ struct P2PPendingMessage
275 275
276 /** 276 /**
277 * Actual message to be sent, allocated at the end of the struct: 277 * Actual message to be sent, allocated at the end of the struct:
278 * // msg = (cast) &pm[1]; 278 * // msg = (cast) &pm[1];
279 * // memcpy (&pm[1], data, len); 279 * // memcpy (&pm[1], data, len);
280 */ 280 */
281 const struct GNUNET_MessageHeader *msg; 281 const struct GNUNET_MessageHeader *msg;
@@ -399,7 +399,7 @@ static GNUNET_SCHEDULER_TaskIdentifier find_peer_task;
399 399
400/** 400/**
401 * Identity of this peer. 401 * Identity of this peer.
402 */ 402 */
403static struct GNUNET_PeerIdentity my_identity; 403static struct GNUNET_PeerIdentity my_identity;
404 404
405/** 405/**
@@ -428,11 +428,11 @@ find_bucket (const GNUNET_HashCode * hc)
428 428
429 bits = GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey, hc); 429 bits = GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey, hc);
430 if (bits == MAX_BUCKETS) 430 if (bits == MAX_BUCKETS)
431 { 431 {
432 /* How can all bits match? Got my own ID? */ 432 /* How can all bits match? Got my own ID? */
433 GNUNET_break (0); 433 GNUNET_break (0);
434 return GNUNET_SYSERR; 434 return GNUNET_SYSERR;
435 } 435 }
436 return MAX_BUCKETS - bits - 1; 436 return MAX_BUCKETS - bits - 1;
437} 437}
438 438
@@ -442,7 +442,7 @@ find_bucket (const GNUNET_HashCode * hc)
442 * 442 *
443 * @param cls the 'struct PeerInfo' of the peer 443 * @param cls the 'struct PeerInfo' of the peer
444 * @param tc scheduler context. 444 * @param tc scheduler context.
445 */ 445 */
446static void 446static void
447update_core_preference (void *cls, 447update_core_preference (void *cls,
448 const struct GNUNET_SCHEDULER_TaskContext *tc) 448 const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -454,10 +454,10 @@ update_core_preference (void *cls,
454 454
455 peer->preference_task = GNUNET_SCHEDULER_NO_TASK; 455 peer->preference_task = GNUNET_SCHEDULER_NO_TASK;
456 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 456 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
457 return; 457 return;
458 matching = 458 matching =
459 GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey, 459 GNUNET_CRYPTO_hash_matching_bits (&my_identity.hashPubKey,
460 &peer->id.hashPubKey); 460 &peer->id.hashPubKey);
461 if (matching >= 64) 461 if (matching >= 64)
462 matching = 63; 462 matching = 63;
463 bucket = find_bucket (&peer->id.hashPubKey); 463 bucket = find_bucket (&peer->id.hashPubKey);
@@ -469,22 +469,21 @@ update_core_preference (void *cls,
469 preference = (1LL << matching) / k_buckets[bucket].peers_size; 469 preference = (1LL << matching) / k_buckets[bucket].peers_size;
470 } 470 }
471 if (preference == 0) 471 if (preference == 0)
472 { 472 {
473 peer->preference_task 473 peer->preference_task =
474 = GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL, 474 GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL,
475 &update_core_preference, peer); 475 &update_core_preference, peer);
476 return; 476 return;
477 } 477 }
478 GNUNET_STATISTICS_update (GDS_stats, 478 GNUNET_STATISTICS_update (GDS_stats,
479 gettext_noop ("# Preference updates given to core"), 1, 479 gettext_noop ("# Preference updates given to core"),
480 GNUNET_NO); 480 1, GNUNET_NO);
481 GNUNET_ATS_change_preference (atsAPI, &peer->id, 481 GNUNET_ATS_change_preference (atsAPI, &peer->id,
482 GNUNET_ATS_PREFERENCE_BANDWIDTH, 482 GNUNET_ATS_PREFERENCE_BANDWIDTH,
483 (double) preference, 483 (double) preference, GNUNET_ATS_PREFERENCE_END);
484 GNUNET_ATS_PREFERENCE_END); 484 peer->preference_task =
485 peer->preference_task 485 GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL,
486 = GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL, 486 &update_core_preference, peer);
487 &update_core_preference, peer);
488 487
489 488
490} 489}
@@ -525,9 +524,8 @@ add_known_to_bloom (void *cls, const GNUNET_HashCode * key, void *value)
525 GNUNET_BLOCK_mingle_hash (key, ctx->bf_mutator, &mh); 524 GNUNET_BLOCK_mingle_hash (key, ctx->bf_mutator, &mh);
526#if DEBUG_DHT 525#if DEBUG_DHT
527 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 526 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
528 "Adding known peer (%s) to bloomfilter for FIND PEER with mutation %u\n", 527 "Adding known peer (%s) to bloomfilter for FIND PEER with mutation %u\n",
529 GNUNET_h2s (key), 528 GNUNET_h2s (key), ctx->bf_mutator);
530 ctx->bf_mutator);
531#endif 529#endif
532 GNUNET_CONTAINER_bloomfilter_add (ctx->bloom, &mh); 530 GNUNET_CONTAINER_bloomfilter_add (ctx->bloom, &mh);
533 return GNUNET_YES; 531 return GNUNET_YES;
@@ -553,46 +551,46 @@ send_find_peer_message (void *cls,
553 find_peer_task = GNUNET_SCHEDULER_NO_TASK; 551 find_peer_task = GNUNET_SCHEDULER_NO_TASK;
554 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 552 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
555 return; 553 return;
556 if (newly_found_peers > bucket_size) 554 if (newly_found_peers > bucket_size)
557 { 555 {
558 /* If we are finding many peers already, no need to send out our request right now! */ 556 /* If we are finding many peers already, no need to send out our request right now! */
559 find_peer_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 557 find_peer_task =
560 &send_find_peer_message, NULL); 558 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
559 &send_find_peer_message, NULL);
561 newly_found_peers = 0; 560 newly_found_peers = 0;
562 return; 561 return;
563 } 562 }
564 bcc.bf_mutator = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); 563 bcc.bf_mutator =
564 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
565 bcc.bloom = 565 bcc.bloom =
566 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, GNUNET_CONSTANTS_BLOOMFILTER_K); 566 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE,
567 GNUNET_CONTAINER_multihashmap_iterate (all_known_peers, 567 GNUNET_CONSTANTS_BLOOMFILTER_K);
568 &add_known_to_bloom, 568 GNUNET_CONTAINER_multihashmap_iterate (all_known_peers, &add_known_to_bloom,
569 &bcc); 569 &bcc);
570 GNUNET_STATISTICS_update (GDS_stats, 570 GNUNET_STATISTICS_update (GDS_stats,
571 gettext_noop ("# FIND PEER messages initiated"), 1, 571 gettext_noop ("# FIND PEER messages initiated"), 1,
572 GNUNET_NO); 572 GNUNET_NO);
573 peer_bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 573 peer_bf =
574 DHT_BLOOM_SIZE, 574 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE,
575 GNUNET_CONSTANTS_BLOOMFILTER_K); 575 GNUNET_CONSTANTS_BLOOMFILTER_K);
576 // FIXME: pass priority!? 576 // FIXME: pass priority!?
577 GDS_NEIGHBOURS_handle_get (GNUNET_BLOCK_TYPE_DHT_HELLO, 577 GDS_NEIGHBOURS_handle_get (GNUNET_BLOCK_TYPE_DHT_HELLO,
578 GNUNET_DHT_RO_FIND_PEER, 578 GNUNET_DHT_RO_FIND_PEER,
579 FIND_PEER_REPLICATION_LEVEL, 579 FIND_PEER_REPLICATION_LEVEL, 0,
580 0, 580 &my_identity.hashPubKey, NULL, 0, bcc.bloom,
581 &my_identity.hashPubKey, 581 bcc.bf_mutator, peer_bf);
582 NULL, 0,
583 bcc.bloom, bcc.bf_mutator,
584 peer_bf);
585 GNUNET_CONTAINER_bloomfilter_free (peer_bf); 582 GNUNET_CONTAINER_bloomfilter_free (peer_bf);
586 GNUNET_CONTAINER_bloomfilter_free (bcc.bloom); 583 GNUNET_CONTAINER_bloomfilter_free (bcc.bloom);
587 /* schedule next round */ 584 /* schedule next round */
588 next_send_time.rel_value = 585 next_send_time.rel_value =
589 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value + 586 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value +
590 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 587 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
591 DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value / (newly_found_peers+1)); 588 DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value /
589 (newly_found_peers + 1));
592 newly_found_peers = 0; 590 newly_found_peers = 0;
593 find_peer_task = GNUNET_SCHEDULER_add_delayed (next_send_time, 591 find_peer_task =
594 &send_find_peer_message, 592 GNUNET_SCHEDULER_add_delayed (next_send_time, &send_find_peer_message,
595 NULL); 593 NULL);
596} 594}
597 595
598 596
@@ -607,7 +605,7 @@ send_find_peer_message (void *cls,
607static void 605static void
608handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, 606handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
609 const struct GNUNET_ATS_Information *atsi, 607 const struct GNUNET_ATS_Information *atsi,
610 unsigned int atsi_count) 608 unsigned int atsi_count)
611{ 609{
612 struct PeerInfo *ret; 610 struct PeerInfo *ret;
613 int peer_bucket; 611 int peer_bucket;
@@ -616,10 +614,8 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
616 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) 614 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
617 return; 615 return;
618#if DEBUG_DHT 616#if DEBUG_DHT
619 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 617 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected %s to %s\n",
620 "Connected %s to %s\n", 618 GNUNET_i2s (&my_identity), GNUNET_h2s (&peer->hashPubKey));
621 GNUNET_i2s (&my_identity),
622 GNUNET_h2s (&peer->hashPubKey));
623#endif 619#endif
624 if (GNUNET_YES == 620 if (GNUNET_YES ==
625 GNUNET_CONTAINER_multihashmap_contains (all_known_peers, 621 GNUNET_CONTAINER_multihashmap_contains (all_known_peers,
@@ -628,11 +624,10 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
628 GNUNET_break (0); 624 GNUNET_break (0);
629 return; 625 return;
630 } 626 }
631 GNUNET_STATISTICS_update (GDS_stats, 627 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# Peers connected"), 1,
632 gettext_noop ("# Peers connected"), 1, 628 GNUNET_NO);
633 GNUNET_NO);
634 peer_bucket = find_bucket (&peer->hashPubKey); 629 peer_bucket = find_bucket (&peer->hashPubKey);
635 GNUNET_assert ( (peer_bucket >= 0) && (peer_bucket < MAX_BUCKETS) ); 630 GNUNET_assert ((peer_bucket >= 0) && (peer_bucket < MAX_BUCKETS));
636 ret = GNUNET_malloc (sizeof (struct PeerInfo)); 631 ret = GNUNET_malloc (sizeof (struct PeerInfo));
637#if 0 632#if 0
638 ret->latency = latency; 633 ret->latency = latency;
@@ -640,25 +635,23 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
640#endif 635#endif
641 ret->id = *peer; 636 ret->id = *peer;
642 GNUNET_CONTAINER_DLL_insert_tail (k_buckets[peer_bucket].head, 637 GNUNET_CONTAINER_DLL_insert_tail (k_buckets[peer_bucket].head,
643 k_buckets[peer_bucket].tail, ret); 638 k_buckets[peer_bucket].tail, ret);
644 k_buckets[peer_bucket].peers_size++; 639 k_buckets[peer_bucket].peers_size++;
645 closest_bucket = GNUNET_MAX (closest_bucket, 640 closest_bucket = GNUNET_MAX (closest_bucket, peer_bucket);
646 peer_bucket); 641 if ((peer_bucket > 0) && (k_buckets[peer_bucket].peers_size <= bucket_size))
647 if ( (peer_bucket > 0) &&
648 (k_buckets[peer_bucket].peers_size <= bucket_size) )
649 { 642 {
650 ret->preference_task = GNUNET_SCHEDULER_add_now (&update_core_preference, ret); 643 ret->preference_task =
644 GNUNET_SCHEDULER_add_now (&update_core_preference, ret);
651 newly_found_peers++; 645 newly_found_peers++;
652 } 646 }
653 GNUNET_assert (GNUNET_OK == 647 GNUNET_assert (GNUNET_OK ==
654 GNUNET_CONTAINER_multihashmap_put (all_known_peers, 648 GNUNET_CONTAINER_multihashmap_put (all_known_peers,
655 &peer->hashPubKey, ret, 649 &peer->hashPubKey, ret,
656 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 650 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
657 if (1 == GNUNET_CONTAINER_multihashmap_size (all_known_peers)) 651 if (1 == GNUNET_CONTAINER_multihashmap_size (all_known_peers))
658 { 652 {
659 /* got a first connection, good time to start with FIND PEER requests... */ 653 /* got a first connection, good time to start with FIND PEER requests... */
660 find_peer_task = GNUNET_SCHEDULER_add_now (&send_find_peer_message, 654 find_peer_task = GNUNET_SCHEDULER_add_now (&send_find_peer_message, NULL);
661 NULL);
662 } 655 }
663} 656}
664 657
@@ -681,21 +674,18 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
681 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) 674 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
682 return; 675 return;
683#if DEBUG_DHT 676#if DEBUG_DHT
684 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 677 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnected %s from %s\n",
685 "Disconnected %s from %s\n", 678 GNUNET_i2s (&my_identity), GNUNET_h2s (&peer->hashPubKey));
686 GNUNET_i2s (&my_identity),
687 GNUNET_h2s (&peer->hashPubKey));
688#endif 679#endif
689 to_remove = 680 to_remove =
690 GNUNET_CONTAINER_multihashmap_get (all_known_peers, &peer->hashPubKey); 681 GNUNET_CONTAINER_multihashmap_get (all_known_peers, &peer->hashPubKey);
691 if (NULL == to_remove) 682 if (NULL == to_remove)
692 { 683 {
693 GNUNET_break (0); 684 GNUNET_break (0);
694 return; 685 return;
695 } 686 }
696 GNUNET_STATISTICS_update (GDS_stats, 687 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# Peers connected"), -1,
697 gettext_noop ("# Peers connected"), -1, 688 GNUNET_NO);
698 GNUNET_NO);
699 GNUNET_assert (GNUNET_YES == 689 GNUNET_assert (GNUNET_YES ==
700 GNUNET_CONTAINER_multihashmap_remove (all_known_peers, 690 GNUNET_CONTAINER_multihashmap_remove (all_known_peers,
701 &peer->hashPubKey, 691 &peer->hashPubKey,
@@ -708,15 +698,13 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
708 current_bucket = find_bucket (&to_remove->id.hashPubKey); 698 current_bucket = find_bucket (&to_remove->id.hashPubKey);
709 GNUNET_assert (current_bucket >= 0); 699 GNUNET_assert (current_bucket >= 0);
710 GNUNET_CONTAINER_DLL_remove (k_buckets[current_bucket].head, 700 GNUNET_CONTAINER_DLL_remove (k_buckets[current_bucket].head,
711 k_buckets[current_bucket].tail, 701 k_buckets[current_bucket].tail, to_remove);
712 to_remove);
713 GNUNET_assert (k_buckets[current_bucket].peers_size > 0); 702 GNUNET_assert (k_buckets[current_bucket].peers_size > 0);
714 k_buckets[current_bucket].peers_size--; 703 k_buckets[current_bucket].peers_size--;
715 while ( (closest_bucket > 0) && 704 while ((closest_bucket > 0) && (k_buckets[closest_bucket].peers_size == 0))
716 (k_buckets[closest_bucket].peers_size == 0) )
717 closest_bucket--; 705 closest_bucket--;
718 706
719 if (to_remove->th != NULL) 707 if (to_remove->th != NULL)
720 { 708 {
721 GNUNET_CORE_notify_transmit_ready_cancel (to_remove->th); 709 GNUNET_CORE_notify_transmit_ready_cancel (to_remove->th);
722 to_remove->th = NULL; 710 to_remove->th = NULL;
@@ -724,15 +712,14 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
724 discarded = 0; 712 discarded = 0;
725 while (NULL != (pos = to_remove->head)) 713 while (NULL != (pos = to_remove->head))
726 { 714 {
727 GNUNET_CONTAINER_DLL_remove (to_remove->head, 715 GNUNET_CONTAINER_DLL_remove (to_remove->head, to_remove->tail, pos);
728 to_remove->tail,
729 pos);
730 discarded++; 716 discarded++;
731 GNUNET_free (pos); 717 GNUNET_free (pos);
732 } 718 }
733 GNUNET_STATISTICS_update (GDS_stats, 719 GNUNET_STATISTICS_update (GDS_stats,
734 gettext_noop ("# Queued messages discarded (peer disconnected)"), discarded, 720 gettext_noop
735 GNUNET_NO); 721 ("# Queued messages discarded (peer disconnected)"),
722 discarded, GNUNET_NO);
736 GNUNET_free (to_remove); 723 GNUNET_free (to_remove);
737} 724}
738 725
@@ -756,8 +743,8 @@ core_transmit_notify (void *cls, size_t size, void *buf)
756 size_t msize; 743 size_t msize;
757 744
758 peer->th = NULL; 745 peer->th = NULL;
759 while ( (NULL != (pending = peer->head)) && 746 while ((NULL != (pending = peer->head)) &&
760 (GNUNET_TIME_absolute_get_remaining (pending->timeout).rel_value == 0) ) 747 (GNUNET_TIME_absolute_get_remaining (pending->timeout).rel_value == 0))
761 { 748 {
762 peer->pending_count--; 749 peer->pending_count--;
763 GNUNET_CONTAINER_DLL_remove (peer->head, peer->tail, pending); 750 GNUNET_CONTAINER_DLL_remove (peer->head, peer->tail, pending);
@@ -770,22 +757,24 @@ core_transmit_notify (void *cls, size_t size, void *buf)
770 } 757 }
771 if (buf == NULL) 758 if (buf == NULL)
772 { 759 {
773 peer->th 760 peer->th =
774 = GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, 761 GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES,
775 pending->importance, 762 pending->importance,
776 GNUNET_TIME_absolute_get_remaining (pending->timeout), 763 GNUNET_TIME_absolute_get_remaining
777 &peer->id, ntohs (pending->msg->size), 764 (pending->timeout), &peer->id,
778 &core_transmit_notify, peer); 765 ntohs (pending->msg->size),
766 &core_transmit_notify, peer);
779 GNUNET_break (NULL != peer->th); 767 GNUNET_break (NULL != peer->th);
780 return 0; 768 return 0;
781 } 769 }
782 off = 0; 770 off = 0;
783 while ( (NULL != (pending = peer->head)) && 771 while ((NULL != (pending = peer->head)) &&
784 (size - off >= (msize = ntohs (pending->msg->size))) ) 772 (size - off >= (msize = ntohs (pending->msg->size))))
785 { 773 {
786 GNUNET_STATISTICS_update (GDS_stats, 774 GNUNET_STATISTICS_update (GDS_stats,
787 gettext_noop ("# Bytes transmitted to other peers"), msize, 775 gettext_noop
788 GNUNET_NO); 776 ("# Bytes transmitted to other peers"), msize,
777 GNUNET_NO);
789 memcpy (&cbuf[off], pending->msg, msize); 778 memcpy (&cbuf[off], pending->msg, msize);
790 off += msize; 779 off += msize;
791 peer->pending_count--; 780 peer->pending_count--;
@@ -794,12 +783,12 @@ core_transmit_notify (void *cls, size_t size, void *buf)
794 } 783 }
795 if (peer->head != NULL) 784 if (peer->head != NULL)
796 { 785 {
797 peer->th 786 peer->th =
798 = GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, 787 GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES,
799 pending->importance, 788 pending->importance,
800 GNUNET_TIME_absolute_get_remaining (pending->timeout), 789 GNUNET_TIME_absolute_get_remaining
801 &peer->id, msize, 790 (pending->timeout), &peer->id, msize,
802 &core_transmit_notify, peer); 791 &core_transmit_notify, peer);
803 GNUNET_break (NULL != peer->th); 792 GNUNET_break (NULL != peer->th);
804 } 793 }
805 return off; 794 return off;
@@ -821,16 +810,16 @@ process_peer_queue (struct PeerInfo *peer)
821 if (NULL != peer->th) 810 if (NULL != peer->th)
822 return; 811 return;
823 GNUNET_STATISTICS_update (GDS_stats, 812 GNUNET_STATISTICS_update (GDS_stats,
824 gettext_noop ("# Bytes of bandwdith requested from core"), 813 gettext_noop
825 ntohs (pending->msg->size), 814 ("# Bytes of bandwdith requested from core"),
826 GNUNET_NO); 815 ntohs (pending->msg->size), GNUNET_NO);
827 peer->th 816 peer->th =
828 = GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, 817 GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES,
829 pending->importance, 818 pending->importance,
830 GNUNET_TIME_absolute_get_remaining (pending->timeout), 819 GNUNET_TIME_absolute_get_remaining
831 &peer->id, 820 (pending->timeout), &peer->id,
832 ntohs (pending->msg->size), 821 ntohs (pending->msg->size),
833 &core_transmit_notify, peer); 822 &core_transmit_notify, peer);
834 GNUNET_break (NULL != peer->th); 823 GNUNET_break (NULL != peer->th);
835} 824}
836 825
@@ -844,8 +833,7 @@ process_peer_queue (struct PeerInfo *peer)
844 * @return Some number of peers to forward the message to 833 * @return Some number of peers to forward the message to
845 */ 834 */
846static unsigned int 835static unsigned int
847get_forward_count (uint32_t hop_count, 836get_forward_count (uint32_t hop_count, uint32_t target_replication)
848 uint32_t target_replication)
849{ 837{
850 uint32_t random_value; 838 uint32_t random_value;
851 uint32_t forward_count; 839 uint32_t forward_count;
@@ -862,18 +850,18 @@ get_forward_count (uint32_t hop_count,
862 return 1; 850 return 1;
863 } 851 }
864 /* bound by system-wide maximum */ 852 /* bound by system-wide maximum */
865 target_replication = GNUNET_MIN (MAXIMUM_REPLICATION_LEVEL, 853 target_replication =
866 target_replication); 854 GNUNET_MIN (MAXIMUM_REPLICATION_LEVEL, target_replication);
867 target_value = 855 target_value =
868 1 + (target_replication - 1.0) / (GDS_NSE_get () + 856 1 + (target_replication - 1.0) / (GDS_NSE_get () +
869 ((float) (target_replication - 1.0) * 857 ((float) (target_replication - 1.0) *
870 hop_count)); 858 hop_count));
871 /* Set forward count to floor of target_value */ 859 /* Set forward count to floor of target_value */
872 forward_count = (uint32_t) target_value; 860 forward_count = (uint32_t) target_value;
873 /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */ 861 /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */
874 target_value = target_value - forward_count; 862 target_value = target_value - forward_count;
875 random_value = 863 random_value =
876 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); 864 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
877 if (random_value < (target_value * UINT32_MAX)) 865 if (random_value < (target_value * UINT32_MAX))
878 forward_count++; 866 forward_count++;
879 return forward_count; 867 return forward_count;
@@ -950,7 +938,7 @@ get_distance (const GNUNET_HashCode * target, const GNUNET_HashCode * have)
950 * GNUNET_NO otherwise. 938 * GNUNET_NO otherwise.
951 */ 939 */
952static int 940static int
953am_closest_peer (const GNUNET_HashCode *key, 941am_closest_peer (const GNUNET_HashCode * key,
954 const struct GNUNET_CONTAINER_BloomFilter *bloom) 942 const struct GNUNET_CONTAINER_BloomFilter *bloom)
955{ 943{
956 int bits; 944 int bits;
@@ -978,7 +966,7 @@ am_closest_peer (const GNUNET_HashCode *key,
978 other_bits = GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey, key); 966 other_bits = GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey, key);
979 if (other_bits > bits) 967 if (other_bits > bits)
980 return GNUNET_NO; 968 return GNUNET_NO;
981 if (other_bits == bits) /* We match the same number of bits */ 969 if (other_bits == bits) /* We match the same number of bits */
982 return GNUNET_YES; 970 return GNUNET_YES;
983 pos = pos->next; 971 pos = pos->next;
984 } 972 }
@@ -997,7 +985,7 @@ am_closest_peer (const GNUNET_HashCode *key,
997 * exponentially declining probability. 985 * exponentially declining probability.
998 * 986 *
999 * FIXME: double-check that this is fine 987 * FIXME: double-check that this is fine
1000 * 988 *
1001 * 989 *
1002 * @param key the key we are selecting a peer to route to 990 * @param key the key we are selecting a peer to route to
1003 * @param bloom a bloomfilter containing entries this request has seen already 991 * @param bloom a bloomfilter containing entries this request has seen already
@@ -1005,9 +993,8 @@ am_closest_peer (const GNUNET_HashCode *key,
1005 * @return Peer to route to, or NULL on error 993 * @return Peer to route to, or NULL on error
1006 */ 994 */
1007static struct PeerInfo * 995static struct PeerInfo *
1008select_peer (const GNUNET_HashCode *key, 996select_peer (const GNUNET_HashCode * key,
1009 const struct GNUNET_CONTAINER_BloomFilter *bloom, 997 const struct GNUNET_CONTAINER_BloomFilter *bloom, uint32_t hops)
1010 uint32_t hops)
1011{ 998{
1012 unsigned int bc; 999 unsigned int bc;
1013 unsigned int count; 1000 unsigned int count;
@@ -1028,10 +1015,10 @@ select_peer (const GNUNET_HashCode *key,
1028 count = 0; 1015 count = 0;
1029 while ((pos != NULL) && (count < bucket_size)) 1016 while ((pos != NULL) && (count < bucket_size))
1030 { 1017 {
1031 if ( (bloom == NULL) || 1018 if ((bloom == NULL) ||
1032 (GNUNET_NO == 1019 (GNUNET_NO ==
1033 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) ) 1020 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)))
1034 { 1021 {
1035 dist = get_distance (key, &pos->id.hashPubKey); 1022 dist = get_distance (key, &pos->id.hashPubKey);
1036 if (dist < smallest_distance) 1023 if (dist < smallest_distance)
1037 { 1024 {
@@ -1040,25 +1027,25 @@ select_peer (const GNUNET_HashCode *key,
1040 } 1027 }
1041 } 1028 }
1042 else 1029 else
1043 { 1030 {
1044#if DEBUG_DHT 1031#if DEBUG_DHT
1045 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1032 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1046 "Excluded peer `%s' due to BF match in greedy routing for %s\n", 1033 "Excluded peer `%s' due to BF match in greedy routing for %s\n",
1047 GNUNET_i2s (&pos->id), 1034 GNUNET_i2s (&pos->id), GNUNET_h2s (key));
1048 GNUNET_h2s (key));
1049#endif 1035#endif
1050 GNUNET_STATISTICS_update (GDS_stats, 1036 GNUNET_STATISTICS_update (GDS_stats,
1051 gettext_noop ("# Peers excluded from routing due to Bloomfilter"), 1, 1037 gettext_noop
1052 GNUNET_NO); 1038 ("# Peers excluded from routing due to Bloomfilter"),
1053 } 1039 1, GNUNET_NO);
1040 }
1054 count++; 1041 count++;
1055 pos = pos->next; 1042 pos = pos->next;
1056 } 1043 }
1057 } 1044 }
1058 if (NULL == chosen) 1045 if (NULL == chosen)
1059 GNUNET_STATISTICS_update (GDS_stats, 1046 GNUNET_STATISTICS_update (GDS_stats,
1060 gettext_noop ("# Peer selection failed"), 1, 1047 gettext_noop ("# Peer selection failed"), 1,
1061 GNUNET_NO); 1048 GNUNET_NO);
1062 return chosen; 1049 return chosen;
1063 } 1050 }
1064 1051
@@ -1070,18 +1057,18 @@ select_peer (const GNUNET_HashCode *key,
1070 pos = k_buckets[bc].head; 1057 pos = k_buckets[bc].head;
1071 while ((pos != NULL) && (count < bucket_size)) 1058 while ((pos != NULL) && (count < bucket_size))
1072 { 1059 {
1073 if ( (bloom != NULL) && 1060 if ((bloom != NULL) &&
1074 (GNUNET_YES == 1061 (GNUNET_YES ==
1075 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) ) 1062 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)))
1076 { 1063 {
1077 GNUNET_STATISTICS_update (GDS_stats, 1064 GNUNET_STATISTICS_update (GDS_stats,
1078 gettext_noop ("# Peers excluded from routing due to Bloomfilter"), 1, 1065 gettext_noop
1079 GNUNET_NO); 1066 ("# Peers excluded from routing due to Bloomfilter"),
1067 1, GNUNET_NO);
1080#if DEBUG_DHT 1068#if DEBUG_DHT
1081 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1069 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1082 "Excluded peer `%s' due to BF match in random routing for %s\n", 1070 "Excluded peer `%s' due to BF match in random routing for %s\n",
1083 GNUNET_i2s (&pos->id), 1071 GNUNET_i2s (&pos->id), GNUNET_h2s (key));
1084 GNUNET_h2s (key));
1085#endif 1072#endif
1086 pos = pos->next; 1073 pos = pos->next;
1087 continue; /* Ignore bloomfiltered peers */ 1074 continue; /* Ignore bloomfiltered peers */
@@ -1093,8 +1080,8 @@ select_peer (const GNUNET_HashCode *key,
1093 if (count == 0) /* No peers to select from! */ 1080 if (count == 0) /* No peers to select from! */
1094 { 1081 {
1095 GNUNET_STATISTICS_update (GDS_stats, 1082 GNUNET_STATISTICS_update (GDS_stats,
1096 gettext_noop ("# Peer selection failed"), 1, 1083 gettext_noop ("# Peer selection failed"), 1,
1097 GNUNET_NO); 1084 GNUNET_NO);
1098 return NULL; 1085 return NULL;
1099 } 1086 }
1100 /* Now actually choose a peer */ 1087 /* Now actually choose a peer */
@@ -1105,9 +1092,9 @@ select_peer (const GNUNET_HashCode *key,
1105 pos = k_buckets[bc].head; 1092 pos = k_buckets[bc].head;
1106 while ((pos != NULL) && (count < bucket_size)) 1093 while ((pos != NULL) && (count < bucket_size))
1107 { 1094 {
1108 if ( (bloom != NULL) && 1095 if ((bloom != NULL) &&
1109 (GNUNET_YES == 1096 (GNUNET_YES ==
1110 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) ) 1097 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)))
1111 { 1098 {
1112 pos = pos->next; 1099 pos = pos->next;
1113 continue; /* Ignore bloomfiltered peers */ 1100 continue; /* Ignore bloomfiltered peers */
@@ -1136,11 +1123,10 @@ select_peer (const GNUNET_HashCode *key,
1136 * @return number of peers returned in 'targets'. 1123 * @return number of peers returned in 'targets'.
1137 */ 1124 */
1138static unsigned int 1125static unsigned int
1139get_target_peers (const GNUNET_HashCode *key, 1126get_target_peers (const GNUNET_HashCode * key,
1140 struct GNUNET_CONTAINER_BloomFilter *bloom, 1127 struct GNUNET_CONTAINER_BloomFilter *bloom,
1141 uint32_t hop_count, 1128 uint32_t hop_count, uint32_t target_replication,
1142 uint32_t target_replication, 1129 struct PeerInfo ***targets)
1143 struct PeerInfo ***targets)
1144{ 1130{
1145 unsigned int ret; 1131 unsigned int ret;
1146 unsigned int off; 1132 unsigned int off;
@@ -1154,25 +1140,23 @@ get_target_peers (const GNUNET_HashCode *key,
1154 *targets = NULL; 1140 *targets = NULL;
1155 return 0; 1141 return 0;
1156 } 1142 }
1157 rtargets = GNUNET_malloc (sizeof (struct PeerInfo*) * ret); 1143 rtargets = GNUNET_malloc (sizeof (struct PeerInfo *) * ret);
1158 for (off = 0; off < ret; off++) 1144 for (off = 0; off < ret; off++)
1159 { 1145 {
1160 nxt = select_peer (key, bloom, hop_count); 1146 nxt = select_peer (key, bloom, hop_count);
1161 if (nxt == NULL) 1147 if (nxt == NULL)
1162 break; 1148 break;
1163 rtargets[off] = nxt; 1149 rtargets[off] = nxt;
1164 GNUNET_break (GNUNET_NO == 1150 GNUNET_break (GNUNET_NO ==
1165 GNUNET_CONTAINER_bloomfilter_test (bloom, &nxt->id.hashPubKey)); 1151 GNUNET_CONTAINER_bloomfilter_test (bloom,
1152 &nxt->id.hashPubKey));
1166 GNUNET_CONTAINER_bloomfilter_add (bloom, &rtargets[off]->id.hashPubKey); 1153 GNUNET_CONTAINER_bloomfilter_add (bloom, &rtargets[off]->id.hashPubKey);
1167 } 1154 }
1168#if DEBUG_DHT 1155#if DEBUG_DHT
1169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1170 "Selected %u/%u peers at hop %u for %s (target was %u)\n", 1157 "Selected %u/%u peers at hop %u for %s (target was %u)\n", off,
1171 off, 1158 GNUNET_CONTAINER_multihashmap_size (all_known_peers),
1172 GNUNET_CONTAINER_multihashmap_size (all_known_peers), 1159 (unsigned int) hop_count, GNUNET_h2s (key), ret);
1173 (unsigned int) hop_count,
1174 GNUNET_h2s (key),
1175 ret);
1176#endif 1160#endif
1177 if (0 == off) 1161 if (0 == off)
1178 { 1162 {
@@ -1206,16 +1190,15 @@ get_target_peers (const GNUNET_HashCode *key,
1206 */ 1190 */
1207void 1191void
1208GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, 1192GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
1209 enum GNUNET_DHT_RouteOption options, 1193 enum GNUNET_DHT_RouteOption options,
1210 uint32_t desired_replication_level, 1194 uint32_t desired_replication_level,
1211 struct GNUNET_TIME_Absolute expiration_time, 1195 struct GNUNET_TIME_Absolute expiration_time,
1212 uint32_t hop_count, 1196 uint32_t hop_count,
1213 struct GNUNET_CONTAINER_BloomFilter *bf, 1197 struct GNUNET_CONTAINER_BloomFilter *bf,
1214 const GNUNET_HashCode *key, 1198 const GNUNET_HashCode * key,
1215 unsigned int put_path_length, 1199 unsigned int put_path_length,
1216 struct GNUNET_PeerIdentity *put_path, 1200 struct GNUNET_PeerIdentity *put_path,
1217 const void *data, 1201 const void *data, size_t data_size)
1218 size_t data_size)
1219{ 1202{
1220 unsigned int target_count; 1203 unsigned int target_count;
1221 unsigned int i; 1204 unsigned int i;
@@ -1225,33 +1208,32 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
1225 size_t msize; 1208 size_t msize;
1226 struct PeerPutMessage *ppm; 1209 struct PeerPutMessage *ppm;
1227 struct GNUNET_PeerIdentity *pp; 1210 struct GNUNET_PeerIdentity *pp;
1228 1211
1229 GNUNET_assert (NULL != bf); 1212 GNUNET_assert (NULL != bf);
1230#if DEBUG_DHT 1213#if DEBUG_DHT
1231 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1232 "Adding myself (%s) to PUT bloomfilter for %s\n", 1215 "Adding myself (%s) to PUT bloomfilter for %s\n",
1233 GNUNET_i2s (&my_identity), 1216 GNUNET_i2s (&my_identity), GNUNET_h2s (key));
1234 GNUNET_h2s (key));
1235#endif 1217#endif
1236 GNUNET_CONTAINER_bloomfilter_add (bf, &my_identity.hashPubKey); 1218 GNUNET_CONTAINER_bloomfilter_add (bf, &my_identity.hashPubKey);
1237 GNUNET_STATISTICS_update (GDS_stats, 1219 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# PUT requests routed"),
1238 gettext_noop ("# PUT requests routed"), 1, 1220 1, GNUNET_NO);
1239 GNUNET_NO); 1221 target_count =
1240 target_count = get_target_peers (key, bf, hop_count, 1222 get_target_peers (key, bf, hop_count, desired_replication_level,
1241 desired_replication_level, 1223 &targets);
1242 &targets);
1243 if (0 == target_count) 1224 if (0 == target_count)
1244 { 1225 {
1245#if DEBUG_DHT 1226#if DEBUG_DHT
1246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1247 "Routing PUT for %s terminates after %u hops at %s\n", 1228 "Routing PUT for %s terminates after %u hops at %s\n",
1248 GNUNET_h2s (key), 1229 GNUNET_h2s (key), (unsigned int) hop_count,
1249 (unsigned int) hop_count, 1230 GNUNET_i2s (&my_identity));
1250 GNUNET_i2s (&my_identity));
1251#endif 1231#endif
1252 return; 1232 return;
1253 } 1233 }
1254 msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + sizeof (struct PeerPutMessage); 1234 msize =
1235 put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size +
1236 sizeof (struct PeerPutMessage);
1255 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 1237 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1256 { 1238 {
1257 put_path_length = 0; 1239 put_path_length = 0;
@@ -1264,22 +1246,21 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
1264 return; 1246 return;
1265 } 1247 }
1266 GNUNET_STATISTICS_update (GDS_stats, 1248 GNUNET_STATISTICS_update (GDS_stats,
1267 gettext_noop ("# PUT messages queued for transmission"), target_count, 1249 gettext_noop
1268 GNUNET_NO); 1250 ("# PUT messages queued for transmission"),
1269 for (i=0;i<target_count;i++) 1251 target_count, GNUNET_NO);
1252 for (i = 0; i < target_count; i++)
1270 { 1253 {
1271 target = targets[i]; 1254 target = targets[i];
1272#if DEBUG_DHT 1255#if DEBUG_DHT
1273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1274 "Routing PUT for %s after %u hops to %s\n", 1257 "Routing PUT for %s after %u hops to %s\n", GNUNET_h2s (key),
1275 GNUNET_h2s (key), 1258 (unsigned int) hop_count, GNUNET_i2s (&target->id));
1276 (unsigned int) hop_count,
1277 GNUNET_i2s (&target->id));
1278#endif 1259#endif
1279 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 1260 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
1280 pending->importance = 0; /* FIXME */ 1261 pending->importance = 0; /* FIXME */
1281 pending->timeout = expiration_time; 1262 pending->timeout = expiration_time;
1282 ppm = (struct PeerPutMessage*) &pending[1]; 1263 ppm = (struct PeerPutMessage *) &pending[1];
1283 pending->msg = &ppm->header; 1264 pending->msg = &ppm->header;
1284 ppm->header.size = htons (msize); 1265 ppm->header.size = htons (msize);
1285 ppm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_PUT); 1266 ppm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_PUT);
@@ -1289,18 +1270,19 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
1289 ppm->desired_replication_level = htonl (desired_replication_level); 1270 ppm->desired_replication_level = htonl (desired_replication_level);
1290 ppm->put_path_length = htonl (put_path_length); 1271 ppm->put_path_length = htonl (put_path_length);
1291 ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); 1272 ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time);
1292 GNUNET_break (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &target->id.hashPubKey)); 1273 GNUNET_break (GNUNET_YES ==
1274 GNUNET_CONTAINER_bloomfilter_test (bf,
1275 &target->id.hashPubKey));
1293 GNUNET_assert (GNUNET_OK == 1276 GNUNET_assert (GNUNET_OK ==
1294 GNUNET_CONTAINER_bloomfilter_get_raw_data (bf, 1277 GNUNET_CONTAINER_bloomfilter_get_raw_data (bf,
1295 ppm->bloomfilter, 1278 ppm->bloomfilter,
1296 DHT_BLOOM_SIZE)); 1279 DHT_BLOOM_SIZE));
1297 ppm->key = *key; 1280 ppm->key = *key;
1298 pp = (struct GNUNET_PeerIdentity*) &ppm[1]; 1281 pp = (struct GNUNET_PeerIdentity *) &ppm[1];
1299 memcpy (pp, put_path, sizeof (struct GNUNET_PeerIdentity) * put_path_length); 1282 memcpy (pp, put_path,
1283 sizeof (struct GNUNET_PeerIdentity) * put_path_length);
1300 memcpy (&pp[put_path_length], data, data_size); 1284 memcpy (&pp[put_path_length], data, data_size);
1301 GNUNET_CONTAINER_DLL_insert_tail (target->head, 1285 GNUNET_CONTAINER_DLL_insert_tail (target->head, target->tail, pending);
1302 target->tail,
1303 pending);
1304 target->pending_count++; 1286 target->pending_count++;
1305 process_peer_queue (target); 1287 process_peer_queue (target);
1306 } 1288 }
@@ -1327,15 +1309,13 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
1327 */ 1309 */
1328void 1310void
1329GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, 1311GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1330 enum GNUNET_DHT_RouteOption options, 1312 enum GNUNET_DHT_RouteOption options,
1331 uint32_t desired_replication_level, 1313 uint32_t desired_replication_level,
1332 uint32_t hop_count, 1314 uint32_t hop_count, const GNUNET_HashCode * key,
1333 const GNUNET_HashCode *key, 1315 const void *xquery, size_t xquery_size,
1334 const void *xquery, 1316 const struct GNUNET_CONTAINER_BloomFilter *reply_bf,
1335 size_t xquery_size, 1317 uint32_t reply_bf_mutator,
1336 const struct GNUNET_CONTAINER_BloomFilter *reply_bf, 1318 struct GNUNET_CONTAINER_BloomFilter *peer_bf)
1337 uint32_t reply_bf_mutator,
1338 struct GNUNET_CONTAINER_BloomFilter *peer_bf)
1339{ 1319{
1340 unsigned int target_count; 1320 unsigned int target_count;
1341 unsigned int i; 1321 unsigned int i;
@@ -1347,28 +1327,25 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1347 char *xq; 1327 char *xq;
1348 size_t reply_bf_size; 1328 size_t reply_bf_size;
1349 1329
1350 GNUNET_assert (NULL != peer_bf); 1330 GNUNET_assert (NULL != peer_bf);
1351 GNUNET_STATISTICS_update (GDS_stats, 1331 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# GET requests routed"),
1352 gettext_noop ("# GET requests routed"), 1, 1332 1, GNUNET_NO);
1353 GNUNET_NO); 1333 target_count =
1354 target_count = get_target_peers (key, peer_bf, hop_count, 1334 get_target_peers (key, peer_bf, hop_count, desired_replication_level,
1355 desired_replication_level, 1335 &targets);
1356 &targets);
1357#if DEBUG_DHT 1336#if DEBUG_DHT
1358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1359 "Adding myself (%s) to GET bloomfilter for %s\n", 1338 "Adding myself (%s) to GET bloomfilter for %s\n",
1360 GNUNET_i2s (&my_identity), 1339 GNUNET_i2s (&my_identity), GNUNET_h2s (key));
1361 GNUNET_h2s (key));
1362#endif 1340#endif
1363 GNUNET_CONTAINER_bloomfilter_add (peer_bf, &my_identity.hashPubKey); 1341 GNUNET_CONTAINER_bloomfilter_add (peer_bf, &my_identity.hashPubKey);
1364 if (0 == target_count) 1342 if (0 == target_count)
1365 { 1343 {
1366#if DEBUG_DHT 1344#if DEBUG_DHT
1367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1368 "Routing GET for %s terminates after %u hops at %s\n", 1346 "Routing GET for %s terminates after %u hops at %s\n",
1369 GNUNET_h2s (key), 1347 GNUNET_h2s (key), (unsigned int) hop_count,
1370 (unsigned int) hop_count, 1348 GNUNET_i2s (&my_identity));
1371 GNUNET_i2s (&my_identity));
1372#endif 1349#endif
1373 return; 1350 return;
1374 } 1351 }
@@ -1381,23 +1358,22 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1381 return; 1358 return;
1382 } 1359 }
1383 GNUNET_STATISTICS_update (GDS_stats, 1360 GNUNET_STATISTICS_update (GDS_stats,
1384 gettext_noop ("# GET messages queued for transmission"), target_count, 1361 gettext_noop
1385 GNUNET_NO); 1362 ("# GET messages queued for transmission"),
1363 target_count, GNUNET_NO);
1386 /* forward request */ 1364 /* forward request */
1387 for (i=0;i<target_count;i++) 1365 for (i = 0; i < target_count; i++)
1388 { 1366 {
1389 target = targets[i]; 1367 target = targets[i];
1390#if DEBUG_DHT 1368#if DEBUG_DHT
1391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1369 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1392 "Routing GET for %s after %u hops to %s\n", 1370 "Routing GET for %s after %u hops to %s\n", GNUNET_h2s (key),
1393 GNUNET_h2s (key), 1371 (unsigned int) hop_count, GNUNET_i2s (&target->id));
1394 (unsigned int) hop_count,
1395 GNUNET_i2s (&target->id));
1396#endif 1372#endif
1397 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 1373 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
1398 pending->importance = 0; /* FIXME */ 1374 pending->importance = 0; /* FIXME */
1399 pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); 1375 pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT);
1400 pgm = (struct PeerGetMessage*) &pending[1]; 1376 pgm = (struct PeerGetMessage *) &pending[1];
1401 pending->msg = &pgm->header; 1377 pending->msg = &pgm->header;
1402 pgm->header.size = htons (msize); 1378 pgm->header.size = htons (msize);
1403 pgm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_GET); 1379 pgm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_GET);
@@ -1406,23 +1382,24 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1406 pgm->hop_count = htonl (hop_count + 1); 1382 pgm->hop_count = htonl (hop_count + 1);
1407 pgm->desired_replication_level = htonl (desired_replication_level); 1383 pgm->desired_replication_level = htonl (desired_replication_level);
1408 pgm->xquery_size = htonl (xquery_size); 1384 pgm->xquery_size = htonl (xquery_size);
1409 pgm->bf_mutator = reply_bf_mutator; 1385 pgm->bf_mutator = reply_bf_mutator;
1410 GNUNET_break (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (peer_bf, &target->id.hashPubKey)); 1386 GNUNET_break (GNUNET_YES ==
1387 GNUNET_CONTAINER_bloomfilter_test (peer_bf,
1388 &target->id.hashPubKey));
1411 GNUNET_assert (GNUNET_OK == 1389 GNUNET_assert (GNUNET_OK ==
1412 GNUNET_CONTAINER_bloomfilter_get_raw_data (peer_bf, 1390 GNUNET_CONTAINER_bloomfilter_get_raw_data (peer_bf,
1413 pgm->bloomfilter, 1391 pgm->bloomfilter,
1414 DHT_BLOOM_SIZE)); 1392 DHT_BLOOM_SIZE));
1415 pgm->key = *key; 1393 pgm->key = *key;
1416 xq = (char *) &pgm[1]; 1394 xq = (char *) &pgm[1];
1417 memcpy (xq, xquery, xquery_size); 1395 memcpy (xq, xquery, xquery_size);
1418 if (NULL != reply_bf) 1396 if (NULL != reply_bf)
1419 GNUNET_assert (GNUNET_OK == 1397 GNUNET_assert (GNUNET_OK ==
1420 GNUNET_CONTAINER_bloomfilter_get_raw_data (reply_bf, 1398 GNUNET_CONTAINER_bloomfilter_get_raw_data (reply_bf,
1421 &xq[xquery_size], 1399 &xq
1422 reply_bf_size)); 1400 [xquery_size],
1423 GNUNET_CONTAINER_DLL_insert_tail (target->head, 1401 reply_bf_size));
1424 target->tail, 1402 GNUNET_CONTAINER_DLL_insert_tail (target->head, target->tail, pending);
1425 pending);
1426 target->pending_count++; 1403 target->pending_count++;
1427 process_peer_queue (target); 1404 process_peer_queue (target);
1428 } 1405 }
@@ -1448,46 +1425,49 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1448 */ 1425 */
1449void 1426void
1450GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, 1427GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target,
1451 enum GNUNET_BLOCK_Type type, 1428 enum GNUNET_BLOCK_Type type,
1452 struct GNUNET_TIME_Absolute expiration_time, 1429 struct GNUNET_TIME_Absolute expiration_time,
1453 const GNUNET_HashCode *key, 1430 const GNUNET_HashCode * key,
1454 unsigned int put_path_length, 1431 unsigned int put_path_length,
1455 const struct GNUNET_PeerIdentity *put_path, 1432 const struct GNUNET_PeerIdentity *put_path,
1456 unsigned int get_path_length, 1433 unsigned int get_path_length,
1457 const struct GNUNET_PeerIdentity *get_path, 1434 const struct GNUNET_PeerIdentity *get_path,
1458 const void *data, 1435 const void *data, size_t data_size)
1459 size_t data_size)
1460{ 1436{
1461 struct PeerInfo *pi; 1437 struct PeerInfo *pi;
1462 struct P2PPendingMessage *pending; 1438 struct P2PPendingMessage *pending;
1463 size_t msize; 1439 size_t msize;
1464 struct PeerResultMessage *prm; 1440 struct PeerResultMessage *prm;
1465 struct GNUNET_PeerIdentity *paths; 1441 struct GNUNET_PeerIdentity *paths;
1466 1442
1467 msize = data_size + sizeof (struct PeerResultMessage) + 1443 msize =
1468 (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity); 1444 data_size + sizeof (struct PeerResultMessage) + (get_path_length +
1469 if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 1445 put_path_length) *
1470 (get_path_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || 1446 sizeof (struct GNUNET_PeerIdentity);
1471 (put_path_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || 1447 if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
1472 (data_size > GNUNET_SERVER_MAX_MESSAGE_SIZE) ) 1448 (get_path_length >
1449 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ||
1450 (put_path_length >
1451 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ||
1452 (data_size > GNUNET_SERVER_MAX_MESSAGE_SIZE))
1473 { 1453 {
1474 GNUNET_break (0); 1454 GNUNET_break (0);
1475 return; 1455 return;
1476 } 1456 }
1477 pi = GNUNET_CONTAINER_multihashmap_get (all_known_peers, 1457 pi = GNUNET_CONTAINER_multihashmap_get (all_known_peers, &target->hashPubKey);
1478 &target->hashPubKey);
1479 if (NULL == pi) 1458 if (NULL == pi)
1480 { 1459 {
1481 /* peer disconnected in the meantime, drop reply */ 1460 /* peer disconnected in the meantime, drop reply */
1482 return; 1461 return;
1483 } 1462 }
1484 GNUNET_STATISTICS_update (GDS_stats, 1463 GNUNET_STATISTICS_update (GDS_stats,
1485 gettext_noop ("# RESULT messages queued for transmission"), 1, 1464 gettext_noop
1486 GNUNET_NO); 1465 ("# RESULT messages queued for transmission"), 1,
1487 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 1466 GNUNET_NO);
1488 pending->importance = 0; /* FIXME */ 1467 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
1468 pending->importance = 0; /* FIXME */
1489 pending->timeout = expiration_time; 1469 pending->timeout = expiration_time;
1490 prm = (struct PeerResultMessage*) &pending[1]; 1470 prm = (struct PeerResultMessage *) &pending[1];
1491 pending->msg = &prm->header; 1471 pending->msg = &prm->header;
1492 prm->header.size = htons (msize); 1472 prm->header.size = htons (msize);
1493 prm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT); 1473 prm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT);
@@ -1496,15 +1476,13 @@ GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target,
1496 prm->get_path_length = htonl (get_path_length); 1476 prm->get_path_length = htonl (get_path_length);
1497 prm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); 1477 prm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time);
1498 prm->key = *key; 1478 prm->key = *key;
1499 paths = (struct GNUNET_PeerIdentity*) &prm[1]; 1479 paths = (struct GNUNET_PeerIdentity *) &prm[1];
1500 memcpy (paths, put_path, put_path_length * sizeof (struct GNUNET_PeerIdentity)); 1480 memcpy (paths, put_path,
1501 memcpy (&paths[put_path_length], 1481 put_path_length * sizeof (struct GNUNET_PeerIdentity));
1502 get_path, get_path_length * sizeof (struct GNUNET_PeerIdentity)); 1482 memcpy (&paths[put_path_length], get_path,
1503 memcpy (&paths[put_path_length + get_path_length], 1483 get_path_length * sizeof (struct GNUNET_PeerIdentity));
1504 data, data_size); 1484 memcpy (&paths[put_path_length + get_path_length], data, data_size);
1505 GNUNET_CONTAINER_DLL_insert (pi->head, 1485 GNUNET_CONTAINER_DLL_insert (pi->head, pi->tail, pending);
1506 pi->tail,
1507 pending);
1508 pi->pending_count++; 1486 pi->pending_count++;
1509 process_peer_queue (pi); 1487 process_peer_queue (pi);
1510} 1488}
@@ -1539,12 +1517,10 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server,
1539 * GNUNET_SYSERR to close it (signal serious error) 1517 * GNUNET_SYSERR to close it (signal serious error)
1540 */ 1518 */
1541static int 1519static int
1542handle_dht_p2p_put (void *cls, 1520handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
1543 const struct GNUNET_PeerIdentity *peer, 1521 const struct GNUNET_MessageHeader *message,
1544 const struct GNUNET_MessageHeader *message, 1522 const struct GNUNET_ATS_Information *atsi,
1545 const struct GNUNET_ATS_Information 1523 unsigned int atsi_count)
1546 *atsi,
1547 unsigned int atsi_count)
1548{ 1524{
1549 const struct PeerPutMessage *put; 1525 const struct PeerPutMessage *put;
1550 const struct GNUNET_PeerIdentity *put_path; 1526 const struct GNUNET_PeerIdentity *put_path;
@@ -1555,33 +1531,36 @@ handle_dht_p2p_put (void *cls,
1555 enum GNUNET_DHT_RouteOption options; 1531 enum GNUNET_DHT_RouteOption options;
1556 struct GNUNET_CONTAINER_BloomFilter *bf; 1532 struct GNUNET_CONTAINER_BloomFilter *bf;
1557 GNUNET_HashCode test_key; 1533 GNUNET_HashCode test_key;
1558 1534
1559 msize = ntohs (message->size); 1535 msize = ntohs (message->size);
1560 if (msize < sizeof (struct PeerPutMessage)) 1536 if (msize < sizeof (struct PeerPutMessage))
1561 { 1537 {
1562 GNUNET_break_op (0); 1538 GNUNET_break_op (0);
1563 return GNUNET_YES; 1539 return GNUNET_YES;
1564 } 1540 }
1565 put = (const struct PeerPutMessage*) message; 1541 put = (const struct PeerPutMessage *) message;
1566 putlen = ntohl (put->put_path_length); 1542 putlen = ntohl (put->put_path_length);
1567 if ( (msize < sizeof (struct PeerPutMessage) + putlen * sizeof (struct GNUNET_PeerIdentity)) || 1543 if ((msize <
1568 (putlen > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ) 1544 sizeof (struct PeerPutMessage) +
1569 { 1545 putlen * sizeof (struct GNUNET_PeerIdentity)) ||
1570 GNUNET_break_op (0); 1546 (putlen >
1571 return GNUNET_YES; 1547 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)))
1572 } 1548 {
1549 GNUNET_break_op (0);
1550 return GNUNET_YES;
1551 }
1573 GNUNET_STATISTICS_update (GDS_stats, 1552 GNUNET_STATISTICS_update (GDS_stats,
1574 gettext_noop ("# P2P PUT requests received"), 1, 1553 gettext_noop ("# P2P PUT requests received"), 1,
1575 GNUNET_NO); 1554 GNUNET_NO);
1576 put_path = (const struct GNUNET_PeerIdentity*) &put[1]; 1555 put_path = (const struct GNUNET_PeerIdentity *) &put[1];
1577 payload = &put_path[putlen]; 1556 payload = &put_path[putlen];
1578 options = ntohl (put->options); 1557 options = ntohl (put->options);
1579 payload_size = msize - (sizeof (struct PeerPutMessage) + 1558 payload_size =
1580 putlen * sizeof (struct GNUNET_PeerIdentity)); 1559 msize - (sizeof (struct PeerPutMessage) +
1581 switch (GNUNET_BLOCK_get_key (GDS_block_context, 1560 putlen * sizeof (struct GNUNET_PeerIdentity));
1582 ntohl (put->type), 1561 switch (GNUNET_BLOCK_get_key
1583 payload, payload_size, 1562 (GDS_block_context, ntohl (put->type), payload, payload_size,
1584 &test_key)) 1563 &test_key))
1585 { 1564 {
1586 case GNUNET_YES: 1565 case GNUNET_YES:
1587 if (0 != memcmp (&test_key, &put->key, sizeof (GNUNET_HashCode))) 1566 if (0 != memcmp (&test_key, &put->key, sizeof (GNUNET_HashCode)))
@@ -1598,18 +1577,16 @@ handle_dht_p2p_put (void *cls,
1598 break; 1577 break;
1599 } 1578 }
1600#if DEBUG_DHT 1579#if DEBUG_DHT
1601 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1580 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "PUT for %s at %s\n",
1602 "PUT for %s at %s\n", 1581 GNUNET_h2s (&put->key), GNUNET_i2s (&my_identity));
1603 GNUNET_h2s (&put->key),
1604 GNUNET_i2s (&my_identity));
1605#endif 1582#endif
1606 bf = GNUNET_CONTAINER_bloomfilter_init (put->bloomfilter, 1583 bf = GNUNET_CONTAINER_bloomfilter_init (put->bloomfilter, DHT_BLOOM_SIZE,
1607 DHT_BLOOM_SIZE, 1584 GNUNET_CONSTANTS_BLOOMFILTER_K);
1608 GNUNET_CONSTANTS_BLOOMFILTER_K); 1585 GNUNET_break_op (GNUNET_YES ==
1609 GNUNET_break_op (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &peer->hashPubKey)); 1586 GNUNET_CONTAINER_bloomfilter_test (bf, &peer->hashPubKey));
1610 { 1587 {
1611 struct GNUNET_PeerIdentity pp[putlen+1]; 1588 struct GNUNET_PeerIdentity pp[putlen + 1];
1612 1589
1613 /* extend 'put path' by sender */ 1590 /* extend 'put path' by sender */
1614 if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) 1591 if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE))
1615 { 1592 {
@@ -1619,37 +1596,23 @@ handle_dht_p2p_put (void *cls,
1619 } 1596 }
1620 else 1597 else
1621 putlen = 0; 1598 putlen = 0;
1622 1599
1623 /* give to local clients */ 1600 /* give to local clients */
1624 GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (put->expiration_time), 1601 GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (put->expiration_time),
1625 &put->key, 1602 &put->key, 0, NULL, putlen, pp, ntohl (put->type),
1626 0, NULL, 1603 payload_size, payload);
1627 putlen,
1628 pp,
1629 ntohl (put->type),
1630 payload_size,
1631 payload);
1632 /* store locally */ 1604 /* store locally */
1633 if ( (0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || 1605 if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) ||
1634 (am_closest_peer (&put->key, 1606 (am_closest_peer (&put->key, bf)))
1635 bf) ) ) 1607 GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh
1636 GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put->expiration_time), 1608 (put->expiration_time), &put->key, putlen, pp,
1637 &put->key, 1609 ntohl (put->type), payload_size, payload);
1638 putlen, pp,
1639 ntohl (put->type),
1640 payload_size,
1641 payload);
1642 /* route to other peers */ 1610 /* route to other peers */
1643 GDS_NEIGHBOURS_handle_put (ntohl (put->type), 1611 GDS_NEIGHBOURS_handle_put (ntohl (put->type), options,
1644 options, 1612 ntohl (put->desired_replication_level),
1645 ntohl (put->desired_replication_level), 1613 GNUNET_TIME_absolute_ntoh (put->expiration_time),
1646 GNUNET_TIME_absolute_ntoh (put->expiration_time), 1614 ntohl (put->hop_count), bf, &put->key, putlen,
1647 ntohl (put->hop_count), 1615 pp, payload, payload_size);
1648 bf,
1649 &put->key,
1650 putlen, pp,
1651 payload,
1652 payload_size);
1653 } 1616 }
1654 GNUNET_CONTAINER_bloomfilter_free (bf); 1617 GNUNET_CONTAINER_bloomfilter_free (bf);
1655 return GNUNET_YES; 1618 return GNUNET_YES;
@@ -1667,9 +1630,8 @@ handle_dht_p2p_put (void *cls,
1667 */ 1630 */
1668static void 1631static void
1669handle_find_peer (const struct GNUNET_PeerIdentity *sender, 1632handle_find_peer (const struct GNUNET_PeerIdentity *sender,
1670 const GNUNET_HashCode *key, 1633 const GNUNET_HashCode * key,
1671 struct GNUNET_CONTAINER_BloomFilter *bf, 1634 struct GNUNET_CONTAINER_BloomFilter *bf, uint32_t bf_mutator)
1672 uint32_t bf_mutator)
1673{ 1635{
1674 int bucket_idx; 1636 int bucket_idx;
1675 struct PeerBucket *bucket; 1637 struct PeerBucket *bucket;
@@ -1682,30 +1644,31 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender,
1682 if (NULL != GDS_my_hello) 1644 if (NULL != GDS_my_hello)
1683 { 1645 {
1684 GNUNET_BLOCK_mingle_hash (&my_identity.hashPubKey, bf_mutator, &mhash); 1646 GNUNET_BLOCK_mingle_hash (&my_identity.hashPubKey, bf_mutator, &mhash);
1685 if ( (NULL == bf) || 1647 if ((NULL == bf) ||
1686 (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (bf, &mhash)) ) 1648 (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (bf, &mhash)))
1687 { 1649 {
1688 GDS_NEIGHBOURS_handle_reply (sender, 1650 GDS_NEIGHBOURS_handle_reply (sender, GNUNET_BLOCK_TYPE_DHT_HELLO,
1689 GNUNET_BLOCK_TYPE_DHT_HELLO, 1651 GNUNET_TIME_relative_to_absolute
1690 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION), 1652 (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION),
1691 key, 1653 key, 0, NULL, 0, NULL, GDS_my_hello,
1692 0, NULL, 1654 GNUNET_HELLO_size ((const struct
1693 0, NULL, 1655 GNUNET_HELLO_Message *)
1694 GDS_my_hello, 1656 GDS_my_hello));
1695 GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message*) GDS_my_hello));
1696 } 1657 }
1697 else 1658 else
1698 { 1659 {
1699 GNUNET_STATISTICS_update (GDS_stats, 1660 GNUNET_STATISTICS_update (GDS_stats,
1700 gettext_noop ("# FIND PEER requests ignored due to Bloomfilter"), 1, 1661 gettext_noop
1701 GNUNET_NO); 1662 ("# FIND PEER requests ignored due to Bloomfilter"),
1663 1, GNUNET_NO);
1702 } 1664 }
1703 } 1665 }
1704 else 1666 else
1705 { 1667 {
1706 GNUNET_STATISTICS_update (GDS_stats, 1668 GNUNET_STATISTICS_update (GDS_stats,
1707 gettext_noop ("# FIND PEER requests ignored due to lack of HELLO"), 1, 1669 gettext_noop
1708 GNUNET_NO); 1670 ("# FIND PEER requests ignored due to lack of HELLO"),
1671 1, GNUNET_NO);
1709 } 1672 }
1710 1673
1711 /* then, also consider sending a random HELLO from the closest bucket */ 1674 /* then, also consider sending a random HELLO from the closest bucket */
@@ -1718,8 +1681,8 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender,
1718 bucket = &k_buckets[bucket_idx]; 1681 bucket = &k_buckets[bucket_idx];
1719 if (bucket->peers_size == 0) 1682 if (bucket->peers_size == 0)
1720 return; 1683 return;
1721 choice = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1684 choice =
1722 bucket->peers_size); 1685 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, bucket->peers_size);
1723 peer = bucket->head; 1686 peer = bucket->head;
1724 while (choice > 0) 1687 while (choice > 0)
1725 { 1688 {
@@ -1729,25 +1692,22 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender,
1729 } 1692 }
1730 choice = bucket->peers_size; 1693 choice = bucket->peers_size;
1731 do 1694 do
1732 { 1695 {
1733 peer = peer->next; 1696 peer = peer->next;
1734 if (choice-- == 0) 1697 if (choice-- == 0)
1735 return; /* no non-masked peer available */ 1698 return; /* no non-masked peer available */
1736 if (peer == NULL) 1699 if (peer == NULL)
1737 peer = bucket->head; 1700 peer = bucket->head;
1738 GNUNET_BLOCK_mingle_hash (&peer->id.hashPubKey, bf_mutator, &mhash); 1701 GNUNET_BLOCK_mingle_hash (&peer->id.hashPubKey, bf_mutator, &mhash);
1739 hello = GDS_HELLO_get (&peer->id); 1702 hello = GDS_HELLO_get (&peer->id);
1740 } 1703 }
1741 while ( (hello == NULL) || 1704 while ((hello == NULL) ||
1742 (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &mhash)) ); 1705 (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &mhash)));
1743 GDS_NEIGHBOURS_handle_reply (sender, 1706 GDS_NEIGHBOURS_handle_reply (sender, GNUNET_BLOCK_TYPE_DHT_HELLO,
1744 GNUNET_BLOCK_TYPE_DHT_HELLO, 1707 GNUNET_TIME_relative_to_absolute
1745 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION), 1708 (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION), key,
1746 key, 1709 0, NULL, 0, NULL, hello,
1747 0, NULL, 1710 GNUNET_HELLO_size (hello));
1748 0, NULL,
1749 hello,
1750 GNUNET_HELLO_size (hello));
1751} 1711}
1752 1712
1753 1713
@@ -1765,10 +1725,9 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender,
1765 */ 1725 */
1766static int 1726static int
1767handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, 1727handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
1768 const struct GNUNET_MessageHeader *message, 1728 const struct GNUNET_MessageHeader *message,
1769 const struct GNUNET_ATS_Information 1729 const struct GNUNET_ATS_Information *atsi,
1770 *atsi, 1730 unsigned int atsi_count)
1771 unsigned int atsi_count)
1772{ 1731{
1773 struct PeerGetMessage *get; 1732 struct PeerGetMessage *get;
1774 uint32_t xquery_size; 1733 uint32_t xquery_size;
@@ -1781,7 +1740,9 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
1781 struct GNUNET_CONTAINER_BloomFilter *peer_bf; 1740 struct GNUNET_CONTAINER_BloomFilter *peer_bf;
1782 const char *xquery; 1741 const char *xquery;
1783 1742
1784 GNUNET_break (0 != memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity))); 1743 GNUNET_break (0 !=
1744 memcmp (peer, &my_identity,
1745 sizeof (struct GNUNET_PeerIdentity)));
1785 /* parse and validate message */ 1746 /* parse and validate message */
1786 msize = ntohs (message->size); 1747 msize = ntohs (message->size);
1787 if (msize < sizeof (struct PeerGetMessage)) 1748 if (msize < sizeof (struct PeerGetMessage))
@@ -1797,24 +1758,20 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
1797 return GNUNET_YES; 1758 return GNUNET_YES;
1798 } 1759 }
1799 GNUNET_STATISTICS_update (GDS_stats, 1760 GNUNET_STATISTICS_update (GDS_stats,
1800 gettext_noop ("# P2P GET requests received"), 1, 1761 gettext_noop ("# P2P GET requests received"), 1,
1801 GNUNET_NO); 1762 GNUNET_NO);
1802 reply_bf_size = msize - (sizeof (struct PeerGetMessage) + xquery_size); 1763 reply_bf_size = msize - (sizeof (struct PeerGetMessage) + xquery_size);
1803 type = ntohl (get->type); 1764 type = ntohl (get->type);
1804 options = ntohl (get->options); 1765 options = ntohl (get->options);
1805 xquery = (const char*) &get[1]; 1766 xquery = (const char *) &get[1];
1806 reply_bf = NULL; 1767 reply_bf = NULL;
1807 if (reply_bf_size > 0) 1768 if (reply_bf_size > 0)
1808 reply_bf = GNUNET_CONTAINER_bloomfilter_init (&xquery[xquery_size], 1769 reply_bf =
1809 reply_bf_size, 1770 GNUNET_CONTAINER_bloomfilter_init (&xquery[xquery_size], reply_bf_size,
1810 GNUNET_CONSTANTS_BLOOMFILTER_K); 1771 GNUNET_CONSTANTS_BLOOMFILTER_K);
1811 eval = GNUNET_BLOCK_evaluate (GDS_block_context, 1772 eval =
1812 type, 1773 GNUNET_BLOCK_evaluate (GDS_block_context, type, &get->key, &reply_bf,
1813 &get->key, 1774 get->bf_mutator, xquery, xquery_size, NULL, 0);
1814 &reply_bf,
1815 get->bf_mutator,
1816 xquery, xquery_size,
1817 NULL, 0);
1818 if (eval != GNUNET_BLOCK_EVALUATION_REQUEST_VALID) 1775 if (eval != GNUNET_BLOCK_EVALUATION_REQUEST_VALID)
1819 { 1776 {
1820 /* request invalid or block type not supported */ 1777 /* request invalid or block type not supported */
@@ -1824,70 +1781,55 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
1824 return GNUNET_YES; 1781 return GNUNET_YES;
1825 } 1782 }
1826 peer_bf = 1783 peer_bf =
1827 GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter, 1784 GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter, DHT_BLOOM_SIZE,
1828 DHT_BLOOM_SIZE, 1785 GNUNET_CONSTANTS_BLOOMFILTER_K);
1829 GNUNET_CONSTANTS_BLOOMFILTER_K); 1786 GNUNET_break_op (GNUNET_YES ==
1830 GNUNET_break_op (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (peer_bf, &peer->hashPubKey)); 1787 GNUNET_CONTAINER_bloomfilter_test (peer_bf,
1788 &peer->hashPubKey));
1831 /* remember request for routing replies */ 1789 /* remember request for routing replies */
1832 GDS_ROUTING_add (peer, 1790 GDS_ROUTING_add (peer, type, options, &get->key, xquery, xquery_size,
1833 type, 1791 reply_bf, get->bf_mutator);
1834 options,
1835 &get->key,
1836 xquery, xquery_size,
1837 reply_bf, get->bf_mutator);
1838#if DEBUG_DHT 1792#if DEBUG_DHT
1839 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1793 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GET for %s at %s after %u hops\n",
1840 "GET for %s at %s after %u hops\n", 1794 GNUNET_h2s (&get->key), GNUNET_i2s (&my_identity),
1841 GNUNET_h2s (&get->key), 1795 (unsigned int) ntohl (get->hop_count));
1842 GNUNET_i2s (&my_identity),
1843 (unsigned int) ntohl (get->hop_count));
1844#endif 1796#endif
1845 /* local lookup (this may update the reply_bf) */ 1797 /* local lookup (this may update the reply_bf) */
1846 if ( (0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || 1798 if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) ||
1847 (am_closest_peer (&get->key, 1799 (am_closest_peer (&get->key, peer_bf)))
1848 peer_bf) ) ) 1800 {
1849 { 1801 if ((0 != (options & GNUNET_DHT_RO_FIND_PEER)))
1850 if ( (0 != (options & GNUNET_DHT_RO_FIND_PEER)))
1851 { 1802 {
1852 GNUNET_STATISTICS_update (GDS_stats, 1803 GNUNET_STATISTICS_update (GDS_stats,
1853 gettext_noop ("# P2P FIND PEER requests processed"), 1, 1804 gettext_noop
1854 GNUNET_NO); 1805 ("# P2P FIND PEER requests processed"), 1,
1855 handle_find_peer (peer, 1806 GNUNET_NO);
1856 &get->key, 1807 handle_find_peer (peer, &get->key, reply_bf, get->bf_mutator);
1857 reply_bf,
1858 get->bf_mutator);
1859 } 1808 }
1860 else 1809 else
1861 { 1810 {
1862 eval = GDS_DATACACHE_handle_get (&get->key, 1811 eval =
1863 type, 1812 GDS_DATACACHE_handle_get (&get->key, type, xquery, xquery_size,
1864 xquery, xquery_size, 1813 &reply_bf, get->bf_mutator);
1865 &reply_bf,
1866 get->bf_mutator);
1867 } 1814 }
1868 } 1815 }
1869 else 1816 else
1870 { 1817 {
1871 GNUNET_STATISTICS_update (GDS_stats, 1818 GNUNET_STATISTICS_update (GDS_stats,
1872 gettext_noop ("# P2P GET requests ONLY routed"), 1, 1819 gettext_noop ("# P2P GET requests ONLY routed"),
1873 GNUNET_NO); 1820 1, GNUNET_NO);
1874 } 1821 }
1875 1822
1876 /* P2P forwarding */ 1823 /* P2P forwarding */
1877 if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST) 1824 if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST)
1878 GDS_NEIGHBOURS_handle_get (type, 1825 GDS_NEIGHBOURS_handle_get (type, options,
1879 options, 1826 ntohl (get->desired_replication_level),
1880 ntohl (get->desired_replication_level), 1827 ntohl (get->hop_count), &get->key, xquery,
1881 ntohl (get->hop_count), 1828 xquery_size, reply_bf, get->bf_mutator, peer_bf);
1882 &get->key,
1883 xquery, xquery_size,
1884 reply_bf,
1885 get->bf_mutator,
1886 peer_bf);
1887 /* clean up */ 1829 /* clean up */
1888 if (NULL != reply_bf) 1830 if (NULL != reply_bf)
1889 GNUNET_CONTAINER_bloomfilter_free (reply_bf); 1831 GNUNET_CONTAINER_bloomfilter_free (reply_bf);
1890 GNUNET_CONTAINER_bloomfilter_free (peer_bf); 1832 GNUNET_CONTAINER_bloomfilter_free (peer_bf);
1891 return GNUNET_YES; 1833 return GNUNET_YES;
1892} 1834}
1893 1835
@@ -1904,10 +1846,9 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
1904 */ 1846 */
1905static int 1847static int
1906handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer, 1848handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer,
1907 const struct GNUNET_MessageHeader *message, 1849 const struct GNUNET_MessageHeader *message,
1908 const struct GNUNET_ATS_Information 1850 const struct GNUNET_ATS_Information *atsi,
1909 *atsi, 1851 unsigned int atsi_count)
1910 unsigned int atsi_count)
1911{ 1852{
1912 const struct PeerResultMessage *prm; 1853 const struct PeerResultMessage *prm;
1913 const struct GNUNET_PeerIdentity *put_path; 1854 const struct GNUNET_PeerIdentity *put_path;
@@ -1918,7 +1859,7 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer,
1918 uint16_t msize; 1859 uint16_t msize;
1919 size_t data_size; 1860 size_t data_size;
1920 enum GNUNET_BLOCK_Type type; 1861 enum GNUNET_BLOCK_Type type;
1921 1862
1922 /* parse and validate message */ 1863 /* parse and validate message */
1923 msize = ntohs (message->size); 1864 msize = ntohs (message->size);
1924 if (msize < sizeof (struct PeerResultMessage)) 1865 if (msize < sizeof (struct PeerResultMessage))
@@ -1929,23 +1870,28 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer,
1929 prm = (struct PeerResultMessage *) message; 1870 prm = (struct PeerResultMessage *) message;
1930 put_path_length = ntohl (prm->put_path_length); 1871 put_path_length = ntohl (prm->put_path_length);
1931 get_path_length = ntohl (prm->get_path_length); 1872 get_path_length = ntohl (prm->get_path_length);
1932 if ( (msize < sizeof (struct PeerResultMessage) + 1873 if ((msize <
1933 (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity)) || 1874 sizeof (struct PeerResultMessage) + (get_path_length +
1934 (get_path_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || 1875 put_path_length) *
1935 (put_path_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ) 1876 sizeof (struct GNUNET_PeerIdentity)) ||
1877 (get_path_length >
1878 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ||
1879 (put_path_length >
1880 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)))
1936 { 1881 {
1937 GNUNET_break_op (0); 1882 GNUNET_break_op (0);
1938 return GNUNET_YES; 1883 return GNUNET_YES;
1939 } 1884 }
1940 GNUNET_STATISTICS_update (GDS_stats, 1885 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P RESULTS received"),
1941 gettext_noop ("# P2P RESULTS received"), 1, 1886 1, GNUNET_NO);
1942 GNUNET_NO); 1887 put_path = (const struct GNUNET_PeerIdentity *) &prm[1];
1943 put_path = (const struct GNUNET_PeerIdentity*) &prm[1];
1944 get_path = &put_path[put_path_length]; 1888 get_path = &put_path[put_path_length];
1945 type = ntohl (prm->type); 1889 type = ntohl (prm->type);
1946 data = (const void*) &get_path[get_path_length]; 1890 data = (const void *) &get_path[get_path_length];
1947 data_size = msize - (sizeof (struct PeerResultMessage) + 1891 data_size =
1948 (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity)); 1892 msize - (sizeof (struct PeerResultMessage) +
1893 (get_path_length +
1894 put_path_length) * sizeof (struct GNUNET_PeerIdentity));
1949 1895
1950 /* if we got a HELLO, consider it for our own routing table */ 1896 /* if we got a HELLO, consider it for our own routing table */
1951 if (type == GNUNET_BLOCK_TYPE_DHT_HELLO) 1897 if (type == GNUNET_BLOCK_TYPE_DHT_HELLO)
@@ -1967,8 +1913,7 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer,
1967 return GNUNET_YES; 1913 return GNUNET_YES;
1968 } 1914 }
1969 if (GNUNET_OK != 1915 if (GNUNET_OK !=
1970 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message*) h, 1916 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) h, &pid))
1971 &pid))
1972 { 1917 {
1973 GNUNET_break_op (0); 1918 GNUNET_break_op (0);
1974 return GNUNET_YES; 1919 return GNUNET_YES;
@@ -1976,49 +1921,35 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer,
1976 if (0 != memcmp (&my_identity, &pid, sizeof (struct GNUNET_PeerIdentity))) 1921 if (0 != memcmp (&my_identity, &pid, sizeof (struct GNUNET_PeerIdentity)))
1977 { 1922 {
1978 bucket = find_bucket (&pid.hashPubKey); 1923 bucket = find_bucket (&pid.hashPubKey);
1979 if ( (bucket >= 0) && 1924 if ((bucket >= 0) && (k_buckets[bucket].peers_size < bucket_size))
1980 (k_buckets[bucket].peers_size < bucket_size) ) 1925 {
1981 { 1926 if (NULL != GDS_transport_handle)
1982 if (NULL != GDS_transport_handle) 1927 {
1983 { 1928 GNUNET_TRANSPORT_offer_hello (GDS_transport_handle, h, NULL, NULL);
1984 GNUNET_TRANSPORT_offer_hello (GDS_transport_handle, 1929 GNUNET_TRANSPORT_try_connect (GDS_transport_handle, &pid);
1985 h, NULL, NULL); 1930 }
1986 GNUNET_TRANSPORT_try_connect (GDS_transport_handle, 1931 }
1987 &pid);
1988 }
1989 }
1990 } 1932 }
1991 } 1933 }
1992 1934
1993 /* append 'peer' to 'get_path' */ 1935 /* append 'peer' to 'get_path' */
1994 { 1936 {
1995 struct GNUNET_PeerIdentity xget_path[get_path_length+1]; 1937 struct GNUNET_PeerIdentity xget_path[get_path_length + 1];
1996 1938
1997 memcpy (xget_path, get_path, get_path_length * sizeof (struct GNUNET_PeerIdentity)); 1939 memcpy (xget_path, get_path,
1940 get_path_length * sizeof (struct GNUNET_PeerIdentity));
1998 xget_path[get_path_length] = *peer; 1941 xget_path[get_path_length] = *peer;
1999 get_path_length++; 1942 get_path_length++;
2000 1943
2001 /* forward to local clients */ 1944 /* forward to local clients */
2002 GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (prm->expiration_time), 1945 GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (prm->expiration_time),
2003 &prm->key, 1946 &prm->key, get_path_length, xget_path,
2004 get_path_length, 1947 put_path_length, put_path, type, data_size, data);
2005 xget_path,
2006 put_path_length,
2007 put_path,
2008 type,
2009 data_size,
2010 data);
2011 1948
2012 /* forward to other peers */ 1949 /* forward to other peers */
2013 GDS_ROUTING_process (type, 1950 GDS_ROUTING_process (type, GNUNET_TIME_absolute_ntoh (prm->expiration_time),
2014 GNUNET_TIME_absolute_ntoh (prm->expiration_time), 1951 &prm->key, put_path_length, put_path, get_path_length,
2015 &prm->key, 1952 xget_path, data, data_size);
2016 put_path_length,
2017 put_path,
2018 get_path_length,
2019 xget_path,
2020 data,
2021 data_size);
2022 } 1953 }
2023 return GNUNET_YES; 1954 return GNUNET_YES;
2024} 1955}
@@ -2039,21 +1970,16 @@ GDS_NEIGHBOURS_init ()
2039 {NULL, 0, 0} 1970 {NULL, 0, 0}
2040 }; 1971 };
2041 unsigned long long temp_config_num; 1972 unsigned long long temp_config_num;
2042 1973
2043 if (GNUNET_OK == 1974 if (GNUNET_OK ==
2044 GNUNET_CONFIGURATION_get_value_number (GDS_cfg, "DHT", "bucket_size", 1975 GNUNET_CONFIGURATION_get_value_number (GDS_cfg, "DHT", "bucket_size",
2045 &temp_config_num)) 1976 &temp_config_num))
2046 bucket_size = (unsigned int) temp_config_num; 1977 bucket_size = (unsigned int) temp_config_num;
2047 atsAPI = GNUNET_ATS_performance_init (GDS_cfg, NULL, NULL); 1978 atsAPI = GNUNET_ATS_performance_init (GDS_cfg, NULL, NULL);
2048 coreAPI = GNUNET_CORE_connect (GDS_cfg, 1979 coreAPI =
2049 1, 1980 GNUNET_CORE_connect (GDS_cfg, 1, NULL, &core_init, &handle_core_connect,
2050 NULL, 1981 &handle_core_disconnect, NULL, GNUNET_NO, NULL,
2051 &core_init, 1982 GNUNET_NO, core_handlers);
2052 &handle_core_connect,
2053 &handle_core_disconnect,
2054 NULL, GNUNET_NO,
2055 NULL, GNUNET_NO,
2056 core_handlers);
2057 if (coreAPI == NULL) 1983 if (coreAPI == NULL)
2058 return GNUNET_SYSERR; 1984 return GNUNET_SYSERR;
2059 all_known_peers = GNUNET_CONTAINER_multihashmap_create (256); 1985 all_known_peers = GNUNET_CONTAINER_multihashmap_create (256);
@@ -2070,9 +1996,9 @@ GDS_NEIGHBOURS_done ()
2070 if (coreAPI == NULL) 1996 if (coreAPI == NULL)
2071 return; 1997 return;
2072 GNUNET_CORE_disconnect (coreAPI); 1998 GNUNET_CORE_disconnect (coreAPI);
2073 coreAPI = NULL; 1999 coreAPI = NULL;
2074 GNUNET_ATS_performance_done (atsAPI); 2000 GNUNET_ATS_performance_done (atsAPI);
2075 atsAPI = NULL; 2001 atsAPI = NULL;
2076 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (all_known_peers)); 2002 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (all_known_peers));
2077 GNUNET_CONTAINER_multihashmap_destroy (all_known_peers); 2003 GNUNET_CONTAINER_multihashmap_destroy (all_known_peers);
2078 all_known_peers = NULL; 2004 all_known_peers = NULL;
diff --git a/src/dht/gnunet-service-dht_neighbours.h b/src/dht/gnunet-service-dht_neighbours.h
index d23ea10ab..b6e0f0ec0 100644
--- a/src/dht/gnunet-service-dht_neighbours.h
+++ b/src/dht/gnunet-service-dht_neighbours.h
@@ -52,16 +52,15 @@
52 */ 52 */
53void 53void
54GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, 54GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
55 enum GNUNET_DHT_RouteOption options, 55 enum GNUNET_DHT_RouteOption options,
56 uint32_t desired_replication_level, 56 uint32_t desired_replication_level,
57 struct GNUNET_TIME_Absolute expiration_time, 57 struct GNUNET_TIME_Absolute expiration_time,
58 uint32_t hop_count, 58 uint32_t hop_count,
59 struct GNUNET_CONTAINER_BloomFilter *bf, 59 struct GNUNET_CONTAINER_BloomFilter *bf,
60 const GNUNET_HashCode *key, 60 const GNUNET_HashCode * key,
61 unsigned int put_path_length, 61 unsigned int put_path_length,
62 struct GNUNET_PeerIdentity *put_path, 62 struct GNUNET_PeerIdentity *put_path,
63 const void *data, 63 const void *data, size_t data_size);
64 size_t data_size);
65 64
66 65
67/** 66/**
@@ -83,15 +82,13 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
83 */ 82 */
84void 83void
85GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, 84GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
86 enum GNUNET_DHT_RouteOption options, 85 enum GNUNET_DHT_RouteOption options,
87 uint32_t desired_replication_level, 86 uint32_t desired_replication_level,
88 uint32_t hop_count, 87 uint32_t hop_count, const GNUNET_HashCode * key,
89 const GNUNET_HashCode *key, 88 const void *xquery, size_t xquery_size,
90 const void *xquery, 89 const struct GNUNET_CONTAINER_BloomFilter *reply_bf,
91 size_t xquery_size, 90 uint32_t reply_bf_mutator,
92 const struct GNUNET_CONTAINER_BloomFilter *reply_bf, 91 struct GNUNET_CONTAINER_BloomFilter *peer_bf);
93 uint32_t reply_bf_mutator,
94 struct GNUNET_CONTAINER_BloomFilter *peer_bf);
95 92
96 93
97/** 94/**
@@ -112,15 +109,14 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
112 */ 109 */
113void 110void
114GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, 111GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target,
115 enum GNUNET_BLOCK_Type type, 112 enum GNUNET_BLOCK_Type type,
116 struct GNUNET_TIME_Absolute expiration_time, 113 struct GNUNET_TIME_Absolute expiration_time,
117 const GNUNET_HashCode *key, 114 const GNUNET_HashCode * key,
118 unsigned int put_path_length, 115 unsigned int put_path_length,
119 const struct GNUNET_PeerIdentity *put_path, 116 const struct GNUNET_PeerIdentity *put_path,
120 unsigned int get_path_length, 117 unsigned int get_path_length,
121 const struct GNUNET_PeerIdentity *get_path, 118 const struct GNUNET_PeerIdentity *get_path,
122 const void *data, 119 const void *data, size_t data_size);
123 size_t data_size);
124 120
125 121
126/** 122/**
diff --git a/src/dht/gnunet-service-dht_nse.c b/src/dht/gnunet-service-dht_nse.c
index 0a662ec7b..777998967 100644
--- a/src/dht/gnunet-service-dht_nse.c
+++ b/src/dht/gnunet-service-dht_nse.c
@@ -56,10 +56,10 @@ update_network_size_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp,
56 double logestimate, double std_dev) 56 double logestimate, double std_dev)
57{ 57{
58 GNUNET_STATISTICS_update (GDS_stats, 58 GNUNET_STATISTICS_update (GDS_stats,
59 gettext_noop ("# Network size estimates received"), 1, 59 gettext_noop ("# Network size estimates received"),
60 GNUNET_NO); 60 1, GNUNET_NO);
61 /* do not allow estimates < 0.5 */ 61 /* do not allow estimates < 0.5 */
62 log_of_network_size_estimate = GNUNET_MAX (0.5, logestimate); 62 log_of_network_size_estimate = GNUNET_MAX (0.5, logestimate);
63} 63}
64 64
65 65
@@ -90,9 +90,9 @@ GDS_NSE_init ()
90 */ 90 */
91void 91void
92GDS_NSE_done () 92GDS_NSE_done ()
93{ 93{
94 if (NULL != nse) 94 if (NULL != nse)
95 { 95 {
96 GNUNET_NSE_disconnect (nse); 96 GNUNET_NSE_disconnect (nse);
97 nse = NULL; 97 nse = NULL;
98 } 98 }
diff --git a/src/dht/gnunet-service-dht_routing.c b/src/dht/gnunet-service-dht_routing.c
index 607c756c6..a880bf7cd 100644
--- a/src/dht/gnunet-service-dht_routing.c
+++ b/src/dht/gnunet-service-dht_routing.c
@@ -66,7 +66,7 @@ struct RecentRequest
66 * Type of the requested block. 66 * Type of the requested block.
67 */ 67 */
68 enum GNUNET_BLOCK_Type type; 68 enum GNUNET_BLOCK_Type type;
69 69
70 /** 70 /**
71 * extended query (see gnunet_block_lib.h). Allocated at the 71 * extended query (see gnunet_block_lib.h). Allocated at the
72 * end of this struct. 72 * end of this struct.
@@ -114,7 +114,7 @@ struct ProcessContext
114 114
115 /** 115 /**
116 * Path of the reply. 116 * Path of the reply.
117 */ 117 */
118 const struct GNUNET_PeerIdentity *get_path; 118 const struct GNUNET_PeerIdentity *get_path;
119 119
120 /** 120 /**
@@ -156,13 +156,11 @@ struct ProcessContext
156 * @param cls the 'struct ProcessContext' with the result 156 * @param cls the 'struct ProcessContext' with the result
157 * @param key the query 157 * @param key the query
158 * @param value the 'struct RecentRequest' with the request 158 * @param value the 'struct RecentRequest' with the request
159 * @return GNUNET_OK (continue to iterate), 159 * @return GNUNET_OK (continue to iterate),
160 * GNUNET_SYSERR if the result is malformed or type unsupported 160 * GNUNET_SYSERR if the result is malformed or type unsupported
161 */ 161 */
162static int 162static int
163process (void *cls, 163process (void *cls, const GNUNET_HashCode * key, void *value)
164 const GNUNET_HashCode *key,
165 void *value)
166{ 164{
167 struct ProcessContext *pc = cls; 165 struct ProcessContext *pc = cls;
168 struct RecentRequest *rr = value; 166 struct RecentRequest *rr = value;
@@ -172,9 +170,8 @@ process (void *cls,
172 GNUNET_HashCode hc; 170 GNUNET_HashCode hc;
173 const GNUNET_HashCode *eval_key; 171 const GNUNET_HashCode *eval_key;
174 172
175 if ( (rr->type != GNUNET_BLOCK_TYPE_ANY) && 173 if ((rr->type != GNUNET_BLOCK_TYPE_ANY) && (rr->type != pc->type))
176 (rr->type != pc->type) ) 174 return GNUNET_OK; /* type missmatch */
177 return GNUNET_OK; /* type missmatch */
178 175
179 if (0 != (rr->options & GNUNET_DHT_RO_RECORD_ROUTE)) 176 if (0 != (rr->options & GNUNET_DHT_RO_RECORD_ROUTE))
180 { 177 {
@@ -186,59 +183,48 @@ process (void *cls,
186 gpl = 0; 183 gpl = 0;
187 ppl = 0; 184 ppl = 0;
188 } 185 }
189 if ( (0 != (rr->options & GNUNET_DHT_RO_FIND_PEER)) && 186 if ((0 != (rr->options & GNUNET_DHT_RO_FIND_PEER)) &&
190 (pc->type == GNUNET_BLOCK_TYPE_DHT_HELLO) ) 187 (pc->type == GNUNET_BLOCK_TYPE_DHT_HELLO))
191 { 188 {
192 /* key may not match HELLO, which is OK since 189 /* key may not match HELLO, which is OK since
193 the search is approximate. Still, the evaluation 190 * the search is approximate. Still, the evaluation
194 would fail since the match is not exact. So 191 * would fail since the match is not exact. So
195 we fake it by changing the key to the actual PID ... */ 192 * we fake it by changing the key to the actual PID ... */
196 GNUNET_BLOCK_get_key (GDS_block_context, 193 GNUNET_BLOCK_get_key (GDS_block_context, GNUNET_BLOCK_TYPE_DHT_HELLO,
197 GNUNET_BLOCK_TYPE_DHT_HELLO, 194 pc->data, pc->data_size, &hc);
198 pc->data, pc->data_size,
199 &hc);
200 eval_key = &hc; 195 eval_key = &hc;
201 } 196 }
202 else 197 else
203 { 198 {
204 eval_key = key; 199 eval_key = key;
205 } 200 }
206 eval = GNUNET_BLOCK_evaluate (GDS_block_context, 201 eval =
207 pc->type, 202 GNUNET_BLOCK_evaluate (GDS_block_context, pc->type, eval_key,
208 eval_key, 203 &rr->reply_bf, rr->reply_bf_mutator, rr->xquery,
209 &rr->reply_bf, 204 rr->xquery_size, pc->data, pc->data_size);
210 rr->reply_bf_mutator,
211 rr->xquery,
212 rr->xquery_size,
213 pc->data,
214 pc->data_size);
215 switch (eval) 205 switch (eval)
216 { 206 {
217 case GNUNET_BLOCK_EVALUATION_OK_MORE: 207 case GNUNET_BLOCK_EVALUATION_OK_MORE:
218 case GNUNET_BLOCK_EVALUATION_OK_LAST: 208 case GNUNET_BLOCK_EVALUATION_OK_LAST:
219 GNUNET_STATISTICS_update (GDS_stats, 209 GNUNET_STATISTICS_update (GDS_stats,
220 gettext_noop ("# Good REPLIES matched against routing table"), 1, 210 gettext_noop
221 GNUNET_NO); 211 ("# Good REPLIES matched against routing table"),
222 GDS_NEIGHBOURS_handle_reply (&rr->peer, 212 1, GNUNET_NO);
223 pc->type, 213 GDS_NEIGHBOURS_handle_reply (&rr->peer, pc->type, pc->expiration_time, key,
224 pc->expiration_time, 214 ppl, pc->put_path, gpl, pc->get_path, pc->data,
225 key, 215 pc->data_size);
226 ppl,
227 pc->put_path,
228 gpl,
229 pc->get_path,
230 pc->data,
231 pc->data_size);
232 break; 216 break;
233 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: 217 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
234 GNUNET_STATISTICS_update (GDS_stats, 218 GNUNET_STATISTICS_update (GDS_stats,
235 gettext_noop ("# Duplicate REPLIES matched against routing table"), 1, 219 gettext_noop
236 GNUNET_NO); 220 ("# Duplicate REPLIES matched against routing table"),
221 1, GNUNET_NO);
237 return GNUNET_OK; 222 return GNUNET_OK;
238 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: 223 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
239 GNUNET_STATISTICS_update (GDS_stats, 224 GNUNET_STATISTICS_update (GDS_stats,
240 gettext_noop ("# Invalid REPLIES matched against routing table"), 1, 225 gettext_noop
241 GNUNET_NO); 226 ("# Invalid REPLIES matched against routing table"),
227 1, GNUNET_NO);
242 return GNUNET_SYSERR; 228 return GNUNET_SYSERR;
243 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: 229 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
244 case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: 230 case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID:
@@ -246,12 +232,13 @@ process (void *cls,
246 return GNUNET_OK; 232 return GNUNET_OK;
247 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: 233 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
248 GNUNET_STATISTICS_update (GDS_stats, 234 GNUNET_STATISTICS_update (GDS_stats,
249 gettext_noop ("# Unsupported REPLIES matched against routing table"), 1, 235 gettext_noop
250 GNUNET_NO); 236 ("# Unsupported REPLIES matched against routing table"),
237 1, GNUNET_NO);
251 return GNUNET_SYSERR; 238 return GNUNET_SYSERR;
252 default: 239 default:
253 GNUNET_break (0); 240 GNUNET_break (0);
254 return GNUNET_SYSERR; 241 return GNUNET_SYSERR;
255 } 242 }
256 return GNUNET_OK; 243 return GNUNET_OK;
257} 244}
@@ -276,14 +263,12 @@ process (void *cls,
276 */ 263 */
277void 264void
278GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, 265GDS_ROUTING_process (enum GNUNET_BLOCK_Type type,
279 struct GNUNET_TIME_Absolute expiration_time, 266 struct GNUNET_TIME_Absolute expiration_time,
280 const GNUNET_HashCode *key, 267 const GNUNET_HashCode * key, unsigned int put_path_length,
281 unsigned int put_path_length, 268 const struct GNUNET_PeerIdentity *put_path,
282 const struct GNUNET_PeerIdentity *put_path, 269 unsigned int get_path_length,
283 unsigned int get_path_length, 270 const struct GNUNET_PeerIdentity *get_path,
284 const struct GNUNET_PeerIdentity *get_path, 271 const void *data, size_t data_size)
285 const void *data,
286 size_t data_size)
287{ 272{
288 struct ProcessContext pc; 273 struct ProcessContext pc;
289 274
@@ -295,10 +280,7 @@ GDS_ROUTING_process (enum GNUNET_BLOCK_Type type,
295 pc.get_path = get_path; 280 pc.get_path = get_path;
296 pc.data = data; 281 pc.data = data;
297 pc.data_size = data_size; 282 pc.data_size = data_size;
298 GNUNET_CONTAINER_multihashmap_get_multiple (recent_map, 283 GNUNET_CONTAINER_multihashmap_get_multiple (recent_map, key, &process, &pc);
299 key,
300 &process,
301 &pc);
302} 284}
303 285
304 286
@@ -316,21 +298,21 @@ GDS_ROUTING_process (enum GNUNET_BLOCK_Type type,
316*/ 298*/
317void 299void
318GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender, 300GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender,
319 enum GNUNET_BLOCK_Type type, 301 enum GNUNET_BLOCK_Type type,
320 enum GNUNET_DHT_RouteOption options, 302 enum GNUNET_DHT_RouteOption options,
321 const GNUNET_HashCode *key, 303 const GNUNET_HashCode * key, const void *xquery,
322 const void *xquery, 304 size_t xquery_size,
323 size_t xquery_size, 305 const struct GNUNET_CONTAINER_BloomFilter *reply_bf,
324 const struct GNUNET_CONTAINER_BloomFilter *reply_bf, 306 uint32_t reply_bf_mutator)
325 uint32_t reply_bf_mutator)
326{ 307{
327 struct RecentRequest *recent_req; 308 struct RecentRequest *recent_req;
328 309
329 while (GNUNET_CONTAINER_heap_get_size (recent_heap) >= DHT_MAX_RECENT) 310 while (GNUNET_CONTAINER_heap_get_size (recent_heap) >= DHT_MAX_RECENT)
330 { 311 {
331 GNUNET_STATISTICS_update (GDS_stats, 312 GNUNET_STATISTICS_update (GDS_stats,
332 gettext_noop ("# Entries removed from routing table"), 1, 313 gettext_noop
333 GNUNET_NO); 314 ("# Entries removed from routing table"), 1,
315 GNUNET_NO);
334 recent_req = GNUNET_CONTAINER_heap_peek (recent_heap); 316 recent_req = GNUNET_CONTAINER_heap_peek (recent_heap);
335 GNUNET_assert (recent_req != NULL); 317 GNUNET_assert (recent_req != NULL);
336 GNUNET_CONTAINER_heap_remove_node (recent_req->heap_node); 318 GNUNET_CONTAINER_heap_remove_node (recent_req->heap_node);
@@ -339,25 +321,22 @@ GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender,
339 } 321 }
340 322
341 GNUNET_STATISTICS_update (GDS_stats, 323 GNUNET_STATISTICS_update (GDS_stats,
342 gettext_noop ("# Entries added to routing table"), 1, 324 gettext_noop ("# Entries added to routing table"),
343 GNUNET_NO); 325 1, GNUNET_NO);
344 recent_req = GNUNET_malloc (sizeof (struct RecentRequest) + xquery_size); 326 recent_req = GNUNET_malloc (sizeof (struct RecentRequest) + xquery_size);
345 recent_req->peer = *sender; 327 recent_req->peer = *sender;
346 recent_req->key = *key; 328 recent_req->key = *key;
347 recent_req->heap_node = 329 recent_req->heap_node =
348 GNUNET_CONTAINER_heap_insert (recent_heap, recent_req, 330 GNUNET_CONTAINER_heap_insert (recent_heap, recent_req,
349 GNUNET_TIME_absolute_get ().abs_value); 331 GNUNET_TIME_absolute_get ().abs_value);
350 recent_req->reply_bf = 332 recent_req->reply_bf = GNUNET_CONTAINER_bloomfilter_copy (reply_bf);
351 GNUNET_CONTAINER_bloomfilter_copy (reply_bf);
352 recent_req->type = type; 333 recent_req->type = type;
353 recent_req->options = options; 334 recent_req->options = options;
354 recent_req->xquery = &recent_req[1]; 335 recent_req->xquery = &recent_req[1];
355 recent_req->xquery_size = xquery_size; 336 recent_req->xquery_size = xquery_size;
356 recent_req->reply_bf_mutator = reply_bf_mutator; 337 recent_req->reply_bf_mutator = reply_bf_mutator;
357 GNUNET_CONTAINER_multihashmap_put (recent_map, 338 GNUNET_CONTAINER_multihashmap_put (recent_map, key, recent_req,
358 key, 339 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
359 recent_req,
360 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
361 340
362 341
363} 342}
@@ -369,10 +348,8 @@ GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender,
369void 348void
370GDS_ROUTING_init () 349GDS_ROUTING_init ()
371{ 350{
372 recent_heap = 351 recent_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
373 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 352 recent_map = GNUNET_CONTAINER_multihashmap_create (DHT_MAX_RECENT * 4 / 3);
374 recent_map =
375 GNUNET_CONTAINER_multihashmap_create (DHT_MAX_RECENT * 4 / 3);
376} 353}
377 354
378 355
@@ -387,8 +364,9 @@ GDS_ROUTING_done ()
387 while (GNUNET_CONTAINER_heap_get_size (recent_heap) > 0) 364 while (GNUNET_CONTAINER_heap_get_size (recent_heap) > 0)
388 { 365 {
389 GNUNET_STATISTICS_update (GDS_stats, 366 GNUNET_STATISTICS_update (GDS_stats,
390 gettext_noop ("# Entries removed from routing table"), 1, 367 gettext_noop
391 GNUNET_NO); 368 ("# Entries removed from routing table"), 1,
369 GNUNET_NO);
392 recent_req = GNUNET_CONTAINER_heap_peek (recent_heap); 370 recent_req = GNUNET_CONTAINER_heap_peek (recent_heap);
393 GNUNET_assert (recent_req != NULL); 371 GNUNET_assert (recent_req != NULL);
394 GNUNET_CONTAINER_heap_remove_node (recent_req->heap_node); 372 GNUNET_CONTAINER_heap_remove_node (recent_req->heap_node);
diff --git a/src/dht/gnunet-service-dht_routing.h b/src/dht/gnunet-service-dht_routing.h
index a2576a3bb..9b12c71de 100644
--- a/src/dht/gnunet-service-dht_routing.h
+++ b/src/dht/gnunet-service-dht_routing.h
@@ -50,14 +50,12 @@
50 */ 50 */
51void 51void
52GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, 52GDS_ROUTING_process (enum GNUNET_BLOCK_Type type,
53 struct GNUNET_TIME_Absolute expiration_time, 53 struct GNUNET_TIME_Absolute expiration_time,
54 const GNUNET_HashCode *key, 54 const GNUNET_HashCode * key, unsigned int put_path_length,
55 unsigned int put_path_length, 55 const struct GNUNET_PeerIdentity *put_path,
56 const struct GNUNET_PeerIdentity *put_path, 56 unsigned int get_path_length,
57 unsigned int get_path_length, 57 const struct GNUNET_PeerIdentity *get_path,
58 const struct GNUNET_PeerIdentity *get_path, 58 const void *data, size_t data_size);
59 const void *data,
60 size_t data_size);
61 59
62 60
63/** 61/**
@@ -74,13 +72,12 @@ GDS_ROUTING_process (enum GNUNET_BLOCK_Type type,
74*/ 72*/
75void 73void
76GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender, 74GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender,
77 enum GNUNET_BLOCK_Type type, 75 enum GNUNET_BLOCK_Type type,
78 enum GNUNET_DHT_RouteOption options, 76 enum GNUNET_DHT_RouteOption options,
79 const GNUNET_HashCode *key, 77 const GNUNET_HashCode * key, const void *xquery,
80 const void *xquery, 78 size_t xquery_size,
81 size_t xquery_size, 79 const struct GNUNET_CONTAINER_BloomFilter *reply_bf,
82 const struct GNUNET_CONTAINER_BloomFilter *reply_bf, 80 uint32_t reply_bf_mutator);
83 uint32_t reply_bf_mutator);
84 81
85 82
86/** 83/**
diff --git a/src/dht/test_dht_2dtorus.c b/src/dht/test_dht_2dtorus.c
index 220554e15..1db351841 100644
--- a/src/dht/test_dht_2dtorus.c
+++ b/src/dht/test_dht_2dtorus.c
@@ -138,7 +138,8 @@ shutdown_callback (void *cls, const char *emsg)
138 else 138 else
139 { 139 {
140#if VERBOSE 140#if VERBOSE
141 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: All peers successfully shut down!\n"); 141 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
142 "test: All peers successfully shut down!\n");
142#endif 143#endif
143 } 144 }
144} 145}
@@ -169,22 +170,21 @@ disconnect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
169{ 170{
170 unsigned int i; 171 unsigned int i;
171 172
172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: disconnecting peers\n");
173 "test: disconnecting peers\n");
174 disconnect_task = GNUNET_SCHEDULER_NO_TASK; 174 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
175 GNUNET_SCHEDULER_cancel (put_task); 175 GNUNET_SCHEDULER_cancel (put_task);
176 if (NULL != get_h) 176 if (NULL != get_h)
177 GNUNET_DHT_get_stop(get_h); 177 GNUNET_DHT_get_stop (get_h);
178 if (NULL != get_h_2) 178 if (NULL != get_h_2)
179 GNUNET_DHT_get_stop(get_h_2); 179 GNUNET_DHT_get_stop (get_h_2);
180 if (NULL != get_h_far) 180 if (NULL != get_h_far)
181 GNUNET_DHT_get_stop(get_h_far); 181 GNUNET_DHT_get_stop (get_h_far);
182 for (i = 0; i < num_peers; i++) 182 for (i = 0; i < num_peers; i++)
183 { 183 {
184 GNUNET_DHT_disconnect(hs[i]); 184 GNUNET_DHT_disconnect (hs[i]);
185 } 185 }
186 GNUNET_SCHEDULER_cancel (shutdown_handle); 186 GNUNET_SCHEDULER_cancel (shutdown_handle);
187 shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); 187 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
188} 188}
189 189
190static void 190static void
@@ -193,44 +193,39 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
193 const struct GNUNET_PeerIdentity *get_path, 193 const struct GNUNET_PeerIdentity *get_path,
194 unsigned int get_path_length, 194 unsigned int get_path_length,
195 const struct GNUNET_PeerIdentity *put_path, 195 const struct GNUNET_PeerIdentity *put_path,
196 unsigned int put_path_length, 196 unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
197 enum GNUNET_BLOCK_Type type, size_t size, const void *data) 197 size_t size, const void *data)
198{ 198{
199 int i; 199 int i;
200 200
201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
202 "test: ************* FOUND!!! ***********\n"); 202 "test: ************* FOUND!!! ***********\n");
203 if (sizeof(GNUNET_HashCode) == size) 203 if (sizeof (GNUNET_HashCode) == size)
204 { 204 {
205 const GNUNET_HashCode *h = data; 205 const GNUNET_HashCode *h = data;
206 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 206
207 "test: Contents: %s\n", 207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Contents: %s\n",
208 GNUNET_h2s_full (h)); 208 GNUNET_h2s_full (h));
209 209
210 } 210 }
211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: PATH: (get %u, put %u)\n",
212 "test: PATH: (get %u, put %u)\n", 212 get_path_length, put_path_length);
213 get_path_length, 213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: LOCAL\n");
214 put_path_length);
215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
216 "test: LOCAL\n");
217 for (i = get_path_length - 1; i >= 0; i--) 214 for (i = get_path_length - 1; i >= 0; i--)
218 { 215 {
219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: %s\n",
220 "test: %s\n", 217 GNUNET_i2s (&get_path[i]));
221 GNUNET_i2s (&get_path[i]));
222 } 218 }
223 for (i = put_path_length - 1; i >= 0; i--) 219 for (i = put_path_length - 1; i >= 0; i--)
224 { 220 {
225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: %s\n",
226 "test: %s\n", 222 GNUNET_i2s (&put_path[i]));
227 GNUNET_i2s (&put_path[i]));
228 } 223 }
229 found++; 224 found++;
230 if (found < 3) 225 if (found < 3)
231 return; 226 return;
232 ok = 0; 227 ok = 0;
233 GNUNET_SCHEDULER_cancel(disconnect_task); 228 GNUNET_SCHEDULER_cancel (disconnect_task);
234 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL); 229 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL);
235} 230}
236 231
@@ -263,7 +258,7 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
263 if (strcmp (id_aux, id_near2) == 0) 258 if (strcmp (id_aux, id_near2) == 0)
264 d2 = aux; 259 d2 = aux;
265 } 260 }
266 if ( (NULL == o) || (NULL == d) || (NULL == d2) || (NULL == d_far)) 261 if ((NULL == o) || (NULL == d) || (NULL == d2) || (NULL == d_far))
267 { 262 {
268 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 263 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
269 "test: Peers not found (hostkey file changed?)\n"); 264 "test: Peers not found (hostkey file changed?)\n");
@@ -272,55 +267,39 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
272 return; 267 return;
273 } 268 }
274 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n"); 269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n");
275 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n",
276 "test: looking for %s\n",
277 GNUNET_h2s_full (&d->id.hashPubKey)); 271 GNUNET_h2s_full (&d->id.hashPubKey));
278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n",
279 "test: looking for %s\n",
280 GNUNET_h2s_full (&d2->id.hashPubKey)); 273 GNUNET_h2s_full (&d2->id.hashPubKey));
281 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 274 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n",
282 "test: looking for %s\n",
283 GNUNET_h2s_full (&d_far->id.hashPubKey)); 275 GNUNET_h2s_full (&d_far->id.hashPubKey));
284 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 276 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: from %s\n",
285 "test: from %s\n",
286 GNUNET_h2s_full (&o->id.hashPubKey)); 277 GNUNET_h2s_full (&o->id.hashPubKey));
287 found = 0; 278 found = 0;
288 get_h = GNUNET_DHT_get_start (hs[0], 279 get_h = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
289 GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ 280 GNUNET_BLOCK_TYPE_TEST, /* type */
290 GNUNET_BLOCK_TYPE_TEST, /* type */ 281 &d->id.hashPubKey, /*key to search */
291 &d->id.hashPubKey, /*key to search */ 282 4U, /* replication level */
292 4U, /* replication level */ 283 GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */
293 GNUNET_DHT_RO_RECORD_ROUTE | 284 0, /* xquery bits */
294 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 285 &dht_get_id_handler, NULL);
295 NULL, /* xquery */ 286 get_h_2 = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
296 0, /* xquery bits */ 287 GNUNET_BLOCK_TYPE_TEST, /* type */
297 &dht_get_id_handler,
298 NULL);
299 get_h_2 = GNUNET_DHT_get_start (hs[0],
300 GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
301 GNUNET_BLOCK_TYPE_TEST, /* type */
302 &d2->id.hashPubKey, /*key to search */ 288 &d2->id.hashPubKey, /*key to search */
303 4U, /* replication level */ 289 4U, /* replication level */
304 GNUNET_DHT_RO_RECORD_ROUTE | 290 GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */
305 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 291 0, /* xquery bits */
306 NULL, /* xquery */ 292 &dht_get_id_handler, NULL);
307 0, /* xquery bits */ 293 get_h_far = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
308 &dht_get_id_handler, 294 GNUNET_BLOCK_TYPE_TEST, /* type */
309 NULL); 295 &d_far->id.hashPubKey, /*key to search */
310 get_h_far = GNUNET_DHT_get_start (hs[0], 296 4U, /* replication level */
311 GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ 297 GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */
312 GNUNET_BLOCK_TYPE_TEST, /* type */ 298 0, /* xquery bits */
313 &d_far->id.hashPubKey, /*key to search */ 299 &dht_get_id_handler, NULL);
314 4U, /* replication level */
315 GNUNET_DHT_RO_RECORD_ROUTE |
316 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
317 NULL, /* xquery */
318 0, /* xquery bits */
319 &dht_get_id_handler,
320 NULL);
321 GNUNET_SCHEDULER_cancel (disconnect_task); 300 GNUNET_SCHEDULER_cancel (disconnect_task);
322 disconnect_task = GNUNET_SCHEDULER_add_delayed(GET_TIMEOUT, 301 disconnect_task =
323 &disconnect_peers, NULL); 302 GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &disconnect_peers, NULL);
324} 303}
325 304
326 305
@@ -331,28 +310,20 @@ put_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
331 unsigned int i; 310 unsigned int i;
332 311
333 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: putting id's in DHT\n"); 312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: putting id's in DHT\n");
334 for (i = 0; i < num_peers; i++) 313 for (i = 0; i < num_peers; i++)
335 { 314 {
336 d = GNUNET_TESTING_daemon_get (pg, i); 315 d = GNUNET_TESTING_daemon_get (pg, i);
337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 316 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: putting into DHT: %s\n",
338 "test: putting into DHT: %s\n",
339 GNUNET_h2s_full (&d->id.hashPubKey)); 317 GNUNET_h2s_full (&d->id.hashPubKey));
340 GNUNET_DHT_put(hs[i], 318 GNUNET_DHT_put (hs[i], &d->id.hashPubKey, 10U,
341 &d->id.hashPubKey, 319 GNUNET_DHT_RO_RECORD_ROUTE |
342 10U, 320 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
343 GNUNET_DHT_RO_RECORD_ROUTE | 321 GNUNET_BLOCK_TYPE_TEST, sizeof (struct GNUNET_PeerIdentity),
344 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 322 (const char *) &d->id, GNUNET_TIME_UNIT_FOREVER_ABS,
345 GNUNET_BLOCK_TYPE_TEST, 323 GNUNET_TIME_UNIT_FOREVER_REL, NULL, NULL);
346 sizeof(struct GNUNET_PeerIdentity),
347 (const char *) &d->id,
348 GNUNET_TIME_UNIT_FOREVER_ABS,
349 GNUNET_TIME_UNIT_FOREVER_REL,
350 NULL,
351 NULL);
352 324
353 } 325 }
354 put_task = GNUNET_SCHEDULER_add_delayed(PUT_FREQUENCY, 326 put_task = GNUNET_SCHEDULER_add_delayed (PUT_FREQUENCY, &put_id, NULL);
355 &put_id, NULL);
356} 327}
357 328
358 329
@@ -373,8 +344,8 @@ peergroup_ready (void *cls, const char *emsg)
373 { 344 {
374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
375 "test: Peergroup callback called with error, aborting test!\n"); 346 "test: Peergroup callback called with error, aborting test!\n");
376 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 347 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Error from testing: `%s'\n",
377 "test: Error from testing: `%s'\n", emsg); 348 emsg);
378 ok++; 349 ok++;
379 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 350 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
380 return; 351 return;
@@ -384,8 +355,7 @@ peergroup_ready (void *cls, const char *emsg)
384 "************************************************************\n"); 355 "************************************************************\n");
385 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 356 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
386 "test: Peer Group started successfully!\n"); 357 "test: Peer Group started successfully!\n");
387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Have %u connections\n",
388 "test: Have %u connections\n",
389 total_connections); 359 total_connections);
390#endif 360#endif
391 361
@@ -398,24 +368,22 @@ peergroup_ready (void *cls, const char *emsg)
398 GNUNET_free (buf); 368 GNUNET_free (buf);
399 } 369 }
400 peers_running = GNUNET_TESTING_daemons_running (pg); 370 peers_running = GNUNET_TESTING_daemons_running (pg);
401 371
402 GNUNET_assert (peers_running == num_peers); 372 GNUNET_assert (peers_running == num_peers);
403 hs = GNUNET_malloc (num_peers * sizeof(struct GNUNET_DHT_Handle *)); 373 hs = GNUNET_malloc (num_peers * sizeof (struct GNUNET_DHT_Handle *));
404 for (i = 0; i < num_peers; i++) 374 for (i = 0; i < num_peers; i++)
405 { 375 {
406 d = GNUNET_TESTING_daemon_get (pg, i); 376 d = GNUNET_TESTING_daemon_get (pg, i);
407 hs[i] = GNUNET_DHT_connect(d->cfg, 32); 377 hs[i] = GNUNET_DHT_connect (d->cfg, 32);
408 } 378 }
409 379
410 put_task = GNUNET_SCHEDULER_add_now(&put_id, NULL); 380 put_task = GNUNET_SCHEDULER_add_now (&put_id, NULL);
411 test_task = 381 test_task =
412 GNUNET_SCHEDULER_add_delayed( 382 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
413 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), 383 (GNUNET_TIME_UNIT_SECONDS, 2), &do_test,
414 &do_test, NULL);
415 disconnect_task =
416 GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT,
417 &disconnect_peers,
418 NULL); 384 NULL);
385 disconnect_task =
386 GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &disconnect_peers, NULL);
419 387
420} 388}
421 389
@@ -446,14 +414,13 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *first,
446 if (emsg == NULL) 414 if (emsg == NULL)
447 { 415 {
448 total_connections++; 416 total_connections++;
449 GNUNET_PEER_intern(first); 417 GNUNET_PEER_intern (first);
450 GNUNET_PEER_intern(second); 418 GNUNET_PEER_intern (second);
451 } 419 }
452 else 420 else
453 { 421 {
454 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
455 "test: Problem with new connection (%s)\n", 423 "test: Problem with new connection (%s)\n", emsg);
456 emsg);
457 } 424 }
458 425
459} 426}
@@ -496,7 +463,7 @@ run (void *cls, char *const *args, const char *cfgfile,
496 "num_peers", &num_peers)) 463 "num_peers", &num_peers))
497 { 464 {
498 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 465 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
499 "Option TESTING:NUM_PEERS is required!\n"); 466 "Option TESTING:NUM_PEERS is required!\n");
500 return; 467 return;
501 } 468 }
502 469
@@ -516,17 +483,17 @@ run (void *cls, char *const *args, const char *cfgfile,
516 &data_filename)) 483 &data_filename))
517 { 484 {
518 data_file = 485 data_file =
519 GNUNET_DISK_file_open (data_filename, 486 GNUNET_DISK_file_open (data_filename,
520 GNUNET_DISK_OPEN_READWRITE | 487 GNUNET_DISK_OPEN_READWRITE |
521 GNUNET_DISK_OPEN_CREATE, 488 GNUNET_DISK_OPEN_CREATE,
522 GNUNET_DISK_PERM_USER_READ | 489 GNUNET_DISK_PERM_USER_READ |
523 GNUNET_DISK_PERM_USER_WRITE); 490 GNUNET_DISK_PERM_USER_WRITE);
524 if (data_file == NULL) 491 if (data_file == NULL)
525 { 492 {
526 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", 493 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
527 data_filename); 494 data_filename);
528 GNUNET_free (data_filename); 495 GNUNET_free (data_filename);
529 } 496 }
530 } 497 }
531 498
532 if (GNUNET_YES == 499 if (GNUNET_YES ==
@@ -552,7 +519,7 @@ run (void *cls, char *const *args, const char *cfgfile,
552 hosts); 519 hosts);
553 GNUNET_assert (pg != NULL); 520 GNUNET_assert (pg != NULL);
554 shutdown_handle = 521 shutdown_handle =
555 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 522 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
556 &shutdown_task, NULL); 523 &shutdown_task, NULL);
557} 524}
558 525
@@ -584,7 +551,8 @@ main (int xargc, char *xargv[])
584 NULL 551 NULL
585 }; 552 };
586 553
587 GNUNET_PROGRAM_run (sizeof(argv)/sizeof(char*) - 1, argv, "test_dht_2dtorus", 554 GNUNET_PROGRAM_run (sizeof (argv) / sizeof (char *) - 1, argv,
555 "test_dht_2dtorus",
588 gettext_noop ("Test dht in a small 2D torus."), options, 556 gettext_noop ("Test dht in a small 2D torus."), options,
589 &run, NULL); 557 &run, NULL);
590#if REMOVE_DIR 558#if REMOVE_DIR
diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c
index 51f7d947c..e636c08ba 100644
--- a/src/dht/test_dht_api.c
+++ b/src/dht/test_dht_api.c
@@ -179,10 +179,10 @@ static void
179test_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, 179test_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
180 const GNUNET_HashCode * key, 180 const GNUNET_HashCode * key,
181 const struct GNUNET_PeerIdentity *get_path, 181 const struct GNUNET_PeerIdentity *get_path,
182 unsigned int get_path_length, 182 unsigned int get_path_length,
183 const struct GNUNET_PeerIdentity *put_path, 183 const struct GNUNET_PeerIdentity *put_path,
184 unsigned int put_path_length, 184 unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
185 enum GNUNET_BLOCK_Type type, size_t size, const void *data) 185 size_t size, const void *data)
186{ 186{
187 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 187 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
188 "test_get_iterator called (we got a result), stopping get request!\n"); 188 "test_get_iterator called (we got a result), stopping get request!\n");
@@ -213,9 +213,9 @@ test_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
213 213
214 peer->get_handle = 214 peer->get_handle =
215 GNUNET_DHT_get_start (peer->dht_handle, TOTAL_TIMEOUT, 215 GNUNET_DHT_get_start (peer->dht_handle, TOTAL_TIMEOUT,
216 GNUNET_BLOCK_TYPE_TEST, &hash, 216 GNUNET_BLOCK_TYPE_TEST, &hash, 1,
217 1, GNUNET_DHT_RO_NONE, NULL, 217 GNUNET_DHT_RO_NONE, NULL, 0, &test_get_iterator,
218 0, &test_get_iterator, NULL); 218 NULL);
219 219
220 if (peer->get_handle == NULL) 220 if (peer->get_handle == NULL)
221 { 221 {
@@ -250,8 +250,8 @@ test_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
250 250
251 GNUNET_assert (peer->dht_handle != NULL); 251 GNUNET_assert (peer->dht_handle != NULL);
252 252
253 GNUNET_DHT_put (peer->dht_handle, &hash, 1, 253 GNUNET_DHT_put (peer->dht_handle, &hash, 1, GNUNET_DHT_RO_NONE,
254 GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST, data_size, data, 254 GNUNET_BLOCK_TYPE_TEST, data_size, data,
255 GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT), 255 GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT),
256 TOTAL_TIMEOUT, &test_get, &p1); 256 TOTAL_TIMEOUT, &test_get, &p1);
257 GNUNET_free (data); 257 GNUNET_free (data);
diff --git a/src/dht/test_dht_multipeer.c b/src/dht/test_dht_multipeer.c
index 62833a583..f6519239b 100644
--- a/src/dht/test_dht_multipeer.c
+++ b/src/dht/test_dht_multipeer.c
@@ -95,12 +95,12 @@ struct TestPutContext
95struct TestGetContext 95struct TestGetContext
96{ 96{
97 /** 97 /**
98 * This is a linked list 98 * This is a linked list
99 */ 99 */
100 struct TestGetContext *next; 100 struct TestGetContext *next;
101 101
102 /** 102 /**
103 * This is a linked list 103 * This is a linked list
104 */ 104 */
105 struct TestGetContext *prev; 105 struct TestGetContext *prev;
106 106
@@ -220,9 +220,7 @@ shutdown_callback (void *cls, const char *emsg)
220{ 220{
221 if (emsg != NULL) 221 if (emsg != NULL)
222 { 222 {
223 fprintf (stderr, 223 fprintf (stderr, "Failed to shutdown testing topology: %s\n", emsg);
224 "Failed to shutdown testing topology: %s\n",
225 emsg);
226 if (ok == 0) 224 if (ok == 0)
227 ok = 2; 225 ok = 2;
228 } 226 }
@@ -370,18 +368,18 @@ stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
370 GNUNET_free (sm); 368 GNUNET_free (sm);
371 i = 0; 369 i = 0;
372 while (stats[i].name != NULL) 370 while (stats[i].name != NULL)
373 { 371 {
374 fprintf (stderr, "Total : %12s/%50s = %12llu\n", stats[i].subsystem, 372 fprintf (stderr, "Total : %12s/%50s = %12llu\n", stats[i].subsystem,
375 stats[i].name, (unsigned long long) stats[i].total); 373 stats[i].name, (unsigned long long) stats[i].total);
376 i++; 374 i++;
377 } 375 }
378 die_task = GNUNET_SCHEDULER_add_now (&do_stop, NULL); 376 die_task = GNUNET_SCHEDULER_add_now (&do_stop, NULL);
379 return; 377 return;
380 } 378 }
381 sm->stat = 379 sm->stat =
382 GNUNET_STATISTICS_create ("<driver>", 380 GNUNET_STATISTICS_create ("<driver>",
383 GNUNET_TESTING_daemon_get (pg, 381 GNUNET_TESTING_daemon_get (pg,
384 sm->daemon)->cfg); 382 sm->daemon)->cfg);
385 die_task = GNUNET_SCHEDULER_add_now (&stat_run, sm); 383 die_task = GNUNET_SCHEDULER_add_now (&stat_run, sm);
386} 384}
387 385
@@ -404,9 +402,7 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
404 GNUNET_SCHEDULER_cancel (test_put->task); 402 GNUNET_SCHEDULER_cancel (test_put->task);
405 if (test_put->dht_handle != NULL) 403 if (test_put->dht_handle != NULL)
406 GNUNET_DHT_disconnect (test_put->dht_handle); 404 GNUNET_DHT_disconnect (test_put->dht_handle);
407 GNUNET_CONTAINER_DLL_remove (all_puts_head, 405 GNUNET_CONTAINER_DLL_remove (all_puts_head, all_puts_tail, test_put);
408 all_puts_tail,
409 test_put);
410 GNUNET_free (test_put); 406 GNUNET_free (test_put);
411 } 407 }
412 408
@@ -418,16 +414,14 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
418 GNUNET_DHT_get_stop (test_get->get_handle); 414 GNUNET_DHT_get_stop (test_get->get_handle);
419 if (test_get->dht_handle != NULL) 415 if (test_get->dht_handle != NULL)
420 GNUNET_DHT_disconnect (test_get->dht_handle); 416 GNUNET_DHT_disconnect (test_get->dht_handle);
421 GNUNET_CONTAINER_DLL_remove (all_gets_head, 417 GNUNET_CONTAINER_DLL_remove (all_gets_head, all_gets_tail, test_get);
422 all_gets_tail,
423 test_get);
424 GNUNET_free (test_get); 418 GNUNET_free (test_get);
425 } 419 }
426 sm = GNUNET_malloc (sizeof (struct StatMaster)); 420 sm = GNUNET_malloc (sizeof (struct StatMaster));
427 sm->stat = 421 sm->stat =
428 GNUNET_STATISTICS_create ("<driver>", 422 GNUNET_STATISTICS_create ("<driver>",
429 GNUNET_TESTING_daemon_get (pg, 423 GNUNET_TESTING_daemon_get (pg,
430 sm->daemon)->cfg); 424 sm->daemon)->cfg);
431 die_task = GNUNET_SCHEDULER_add_now (&stat_run, sm); 425 die_task = GNUNET_SCHEDULER_add_now (&stat_run, sm);
432} 426}
433 427
@@ -445,18 +439,14 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
445 struct TestGetContext *test_get; 439 struct TestGetContext *test_get;
446 440
447 die_task = GNUNET_SCHEDULER_NO_TASK; 441 die_task = GNUNET_SCHEDULER_NO_TASK;
448 fprintf (stderr, 442 fprintf (stderr, "Failing test with error: `%s'!\n", emsg);
449 "Failing test with error: `%s'!\n",
450 emsg);
451 while (NULL != (test_put = all_puts_head)) 443 while (NULL != (test_put = all_puts_head))
452 { 444 {
453 if (test_put->task != GNUNET_SCHEDULER_NO_TASK) 445 if (test_put->task != GNUNET_SCHEDULER_NO_TASK)
454 GNUNET_SCHEDULER_cancel (test_put->task); 446 GNUNET_SCHEDULER_cancel (test_put->task);
455 if (test_put->dht_handle != NULL) 447 if (test_put->dht_handle != NULL)
456 GNUNET_DHT_disconnect (test_put->dht_handle); 448 GNUNET_DHT_disconnect (test_put->dht_handle);
457 GNUNET_CONTAINER_DLL_remove (all_puts_head, 449 GNUNET_CONTAINER_DLL_remove (all_puts_head, all_puts_tail, test_put);
458 all_puts_tail,
459 test_put);
460 GNUNET_free (test_put); 450 GNUNET_free (test_put);
461 } 451 }
462 452
@@ -468,9 +458,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
468 GNUNET_DHT_get_stop (test_get->get_handle); 458 GNUNET_DHT_get_stop (test_get->get_handle);
469 if (test_get->dht_handle != NULL) 459 if (test_get->dht_handle != NULL)
470 GNUNET_DHT_disconnect (test_get->dht_handle); 460 GNUNET_DHT_disconnect (test_get->dht_handle);
471 GNUNET_CONTAINER_DLL_remove (all_gets_head, 461 GNUNET_CONTAINER_DLL_remove (all_gets_head, all_gets_tail, test_get);
472 all_gets_tail,
473 test_get);
474 GNUNET_free (test_get); 462 GNUNET_free (test_get);
475 } 463 }
476 ok = 1; 464 ok = 1;
@@ -495,10 +483,8 @@ get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
495 if (test_get->succeeded != GNUNET_YES) 483 if (test_get->succeeded != GNUNET_YES)
496 { 484 {
497 gets_failed++; 485 gets_failed++;
498 fprintf (stderr, 486 fprintf (stderr, "Get from peer %s for key %s failed!\n",
499 "Get from peer %s for key %s failed!\n", 487 GNUNET_i2s (&test_get->daemon->id), GNUNET_h2s (&search_key));
500 GNUNET_i2s (&test_get->daemon->id),
501 GNUNET_h2s (&search_key));
502 } 488 }
503 GNUNET_assert (test_get->get_handle != NULL); 489 GNUNET_assert (test_get->get_handle != NULL);
504 GNUNET_DHT_get_stop (test_get->get_handle); 490 GNUNET_DHT_get_stop (test_get->get_handle);
@@ -508,29 +494,25 @@ get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
508 GNUNET_DHT_disconnect (test_get->dht_handle); 494 GNUNET_DHT_disconnect (test_get->dht_handle);
509 test_get->dht_handle = NULL; 495 test_get->dht_handle = NULL;
510 496
511 GNUNET_CONTAINER_DLL_remove (all_gets_head, 497 GNUNET_CONTAINER_DLL_remove (all_gets_head, all_gets_tail, test_get);
512 all_gets_tail,
513 test_get);
514 GNUNET_free (test_get); 498 GNUNET_free (test_get);
515 if ((gets_failed > 10) && (outstanding_gets == 0)) 499 if ((gets_failed > 10) && (outstanding_gets == 0))
516 { 500 {
517 /* Had more than 10% failures */ 501 /* Had more than 10% failures */
518 fprintf (stderr, 502 fprintf (stderr, "%llu gets succeeded, %llu gets failed!\n", gets_completed,
519 "%llu gets succeeded, %llu gets failed!\n", 503 gets_failed);
520 gets_completed, gets_failed);
521 GNUNET_SCHEDULER_cancel (die_task); 504 GNUNET_SCHEDULER_cancel (die_task);
522 ok = 1; 505 ok = 1;
523 die_task = GNUNET_SCHEDULER_add_now (&finish_testing, "not all gets succeeded"); 506 die_task =
507 GNUNET_SCHEDULER_add_now (&finish_testing, "not all gets succeeded");
524 return; 508 return;
525 } 509 }
526 if ( (gets_completed + gets_failed == num_peers * num_peers) && 510 if ((gets_completed + gets_failed == num_peers * num_peers) && (outstanding_gets == 0)) /* All gets successful */
527 (outstanding_gets == 0) ) /* All gets successful */
528 { 511 {
529 fprintf (stderr, 512 fprintf (stderr, "%llu gets succeeded, %llu gets failed!\n", gets_completed,
530 "%llu gets succeeded, %llu gets failed!\n", 513 gets_failed);
531 gets_completed, gets_failed);
532 GNUNET_SCHEDULER_cancel (die_task); 514 GNUNET_SCHEDULER_cancel (die_task);
533 ok = 0; 515 ok = 0;
534 die_task = GNUNET_SCHEDULER_add_now (&finish_testing, NULL); 516 die_task = GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
535 } 517 }
536} 518}
@@ -550,10 +532,10 @@ static void
550get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, 532get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
551 const GNUNET_HashCode * key, 533 const GNUNET_HashCode * key,
552 const struct GNUNET_PeerIdentity *get_path, 534 const struct GNUNET_PeerIdentity *get_path,
553 unsigned int get_path_length, 535 unsigned int get_path_length,
554 const struct GNUNET_PeerIdentity *put_path, 536 const struct GNUNET_PeerIdentity *put_path,
555 unsigned int put_path_length, 537 unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
556 enum GNUNET_BLOCK_Type type, size_t size, const void *data) 538 size_t size, const void *data)
557{ 539{
558 struct TestGetContext *test_get = cls; 540 struct TestGetContext *test_get = cls;
559 GNUNET_HashCode search_key; /* Key stored under */ 541 GNUNET_HashCode search_key; /* Key stored under */
@@ -569,9 +551,8 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
569 { 551 {
570 unsigned int i; 552 unsigned int i;
571 553
572 fprintf (stderr, "PUT (%u) Path: ", 554 fprintf (stderr, "PUT (%u) Path: ", test_get->uid);
573 test_get->uid); 555 for (i = 0; i < put_path_length; i++)
574 for (i = 0; i<put_path_length; i++)
575 fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&put_path[i])); 556 fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&put_path[i]));
576 fprintf (stderr, "\n"); 557 fprintf (stderr, "\n");
577 } 558 }
@@ -579,25 +560,22 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
579 { 560 {
580 unsigned int i; 561 unsigned int i;
581 562
582 fprintf (stderr, "GET (%u) Path: ", 563 fprintf (stderr, "GET (%u) Path: ", test_get->uid);
583 test_get->uid);
584 for (i = 0; i < get_path_length; i++) 564 for (i = 0; i < get_path_length; i++)
585 fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&get_path[i])); 565 fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&get_path[i]));
586 fprintf (stderr, "%s%s\n", 566 fprintf (stderr, "%s%s\n", get_path_length > 0 ? "->" : "",
587 get_path_length > 0 ? "->":"", 567 GNUNET_i2s (&test_get->daemon->id));
588 GNUNET_i2s (&test_get->daemon->id));
589 } 568 }
590#endif 569#endif
591 570
592 if ((0 != memcmp (&search_key, key, sizeof (GNUNET_HashCode))) || 571 if ((0 != memcmp (&search_key, key, sizeof (GNUNET_HashCode))) ||
593 (0 != memcmp (original_data, data, sizeof (original_data)))) 572 (0 != memcmp (original_data, data, sizeof (original_data))))
594 { 573 {
595 fprintf (stderr, 574 fprintf (stderr, "Key or data is not the same as was inserted!\n");
596 "Key or data is not the same as was inserted!\n");
597 return; 575 return;
598 } 576 }
599 gets_completed++; 577 gets_completed++;
600 test_get->succeeded = GNUNET_YES; 578 test_get->succeeded = GNUNET_YES;
601 GNUNET_SCHEDULER_cancel (test_get->task); 579 GNUNET_SCHEDULER_cancel (test_get->task);
602 test_get->task = GNUNET_SCHEDULER_add_now (&get_stop_task, test_get); 580 test_get->task = GNUNET_SCHEDULER_add_now (&get_stop_task, test_get);
603} 581}
@@ -615,7 +593,8 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
615 593
616 if (outstanding_gets > MAX_OUTSTANDING_GETS) 594 if (outstanding_gets > MAX_OUTSTANDING_GETS)
617 { 595 {
618 test_get->task = GNUNET_SCHEDULER_add_delayed (GET_DELAY, &do_get, test_get); 596 test_get->task =
597 GNUNET_SCHEDULER_add_delayed (GET_DELAY, &do_get, test_get);
619 return; 598 return;
620 } 599 }
621 memset (data, test_get->uid, sizeof (data)); 600 memset (data, test_get->uid, sizeof (data));
@@ -624,12 +603,11 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
624 GNUNET_assert (test_get->dht_handle != NULL); 603 GNUNET_assert (test_get->dht_handle != NULL);
625 outstanding_gets++; 604 outstanding_gets++;
626 test_get->get_handle = 605 test_get->get_handle =
627 GNUNET_DHT_get_start (test_get->dht_handle, GNUNET_TIME_UNIT_FOREVER_REL, 606 GNUNET_DHT_get_start (test_get->dht_handle, GNUNET_TIME_UNIT_FOREVER_REL,
628 GNUNET_BLOCK_TYPE_TEST, &key, 607 GNUNET_BLOCK_TYPE_TEST, &key, 1, route_option, NULL,
629 1, route_option, NULL, 0, 608 0, &get_result_iterator, test_get);
630 &get_result_iterator, test_get);
631 test_get->task = 609 test_get->task =
632 GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &get_stop_task, test_get); 610 GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &get_stop_task, test_get);
633} 611}
634 612
635 613
@@ -644,9 +622,7 @@ put_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
644 test_put->task = GNUNET_SCHEDULER_NO_TASK; 622 test_put->task = GNUNET_SCHEDULER_NO_TASK;
645 GNUNET_DHT_disconnect (test_put->dht_handle); 623 GNUNET_DHT_disconnect (test_put->dht_handle);
646 test_put->dht_handle = NULL; 624 test_put->dht_handle = NULL;
647 GNUNET_CONTAINER_DLL_remove (all_puts_head, 625 GNUNET_CONTAINER_DLL_remove (all_puts_head, all_puts_tail, test_put);
648 all_puts_tail,
649 test_put);
650 GNUNET_free (test_put); 626 GNUNET_free (test_put);
651} 627}
652 628
@@ -661,23 +637,19 @@ start_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
661 unsigned long long j; 637 unsigned long long j;
662 struct TestGetContext *test_get; 638 struct TestGetContext *test_get;
663 639
664#if VERBOSE 640#if VERBOSE
665 fprintf (stderr, 641 fprintf (stderr, "Issuing %llu GETs\n",
666 "Issuing %llu GETs\n", 642 (unsigned long long) (num_peers * num_peers));
667 (unsigned long long) (num_peers * num_peers));
668#endif 643#endif
669 for (i = 0; i < num_peers; i++) 644 for (i = 0; i < num_peers; i++)
670 for (j = 0; j < num_peers; j++) 645 for (j = 0; j < num_peers; j++)
671 { 646 {
672 test_get = GNUNET_malloc (sizeof (struct TestGetContext)); 647 test_get = GNUNET_malloc (sizeof (struct TestGetContext));
673 test_get->uid = i + j*num_peers; 648 test_get->uid = i + j * num_peers;
674 test_get->daemon = GNUNET_TESTING_daemon_get (pg, j); 649 test_get->daemon = GNUNET_TESTING_daemon_get (pg, j);
675 GNUNET_CONTAINER_DLL_insert (all_gets_head, 650 GNUNET_CONTAINER_DLL_insert (all_gets_head, all_gets_tail, test_get);
676 all_gets_tail, 651 test_get->task = GNUNET_SCHEDULER_add_now (&do_get, test_get);
677 test_get); 652 }
678 test_get->task = GNUNET_SCHEDULER_add_now (&do_get,
679 test_get);
680 }
681} 653}
682 654
683 655
@@ -692,15 +664,12 @@ put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
692 outstanding_puts--; 664 outstanding_puts--;
693 puts_completed++; 665 puts_completed++;
694 GNUNET_SCHEDULER_cancel (test_put->task); 666 GNUNET_SCHEDULER_cancel (test_put->task);
695 test_put->task = 667 test_put->task = GNUNET_SCHEDULER_add_now (&put_disconnect_task, test_put);
696 GNUNET_SCHEDULER_add_now (&put_disconnect_task, test_put);
697 if (puts_completed != num_peers * num_peers) 668 if (puts_completed != num_peers * num_peers)
698 return; 669 return;
699 670
700 GNUNET_assert (outstanding_puts == 0); 671 GNUNET_assert (outstanding_puts == 0);
701 GNUNET_SCHEDULER_add_delayed (START_DELAY, 672 GNUNET_SCHEDULER_add_delayed (START_DELAY, &start_gets, NULL);
702 &start_gets,
703 NULL);
704} 673}
705 674
706 675
@@ -717,7 +686,8 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
717 test_put->task = GNUNET_SCHEDULER_NO_TASK; 686 test_put->task = GNUNET_SCHEDULER_NO_TASK;
718 if (outstanding_puts > MAX_OUTSTANDING_PUTS) 687 if (outstanding_puts > MAX_OUTSTANDING_PUTS)
719 { 688 {
720 test_put->task = GNUNET_SCHEDULER_add_delayed (PUT_DELAY, &do_put, test_put); 689 test_put->task =
690 GNUNET_SCHEDULER_add_delayed (PUT_DELAY, &do_put, test_put);
721 return; 691 return;
722 } 692 }
723 memset (data, test_put->uid, sizeof (data)); 693 memset (data, test_put->uid, sizeof (data));
@@ -726,46 +696,43 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
726 GNUNET_assert (test_put->dht_handle != NULL); 696 GNUNET_assert (test_put->dht_handle != NULL);
727 outstanding_puts++; 697 outstanding_puts++;
728#if VERBOSE > 2 698#if VERBOSE > 2
729 fprintf (stderr, "PUT %u at `%s'\n", 699 fprintf (stderr, "PUT %u at `%s'\n", test_put->uid,
730 test_put->uid, 700 GNUNET_i2s (&test_put->daemon->id));
731 GNUNET_i2s (&test_put->daemon->id));
732#endif 701#endif
733 GNUNET_DHT_put (test_put->dht_handle, &key, 1, 702 GNUNET_DHT_put (test_put->dht_handle, &key, 1, route_option,
734 route_option, GNUNET_BLOCK_TYPE_TEST, sizeof (data), data, 703 GNUNET_BLOCK_TYPE_TEST, sizeof (data), data,
735 GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL, 704 GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL,
736 &put_finished, test_put); 705 &put_finished, test_put);
737 test_put->task = 706 test_put->task =
738 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 707 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
739 &put_disconnect_task, test_put); 708 &put_disconnect_task, test_put);
740} 709}
741 710
742 711
743static void 712static void
744run_dht_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 713run_dht_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
745{ 714{
746 unsigned long long i; 715 unsigned long long i;
747 struct TestPutContext *test_put; 716 struct TestPutContext *test_put;
748 717
749#if PATH_TRACKING 718#if PATH_TRACKING
750 route_option = GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE; 719 route_option =
720 GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE;
751#else 721#else
752 route_option = GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE; 722 route_option = GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE;
753#endif 723#endif
754 die_task = 724 die_task =
755 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, 725 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
756 "from setup puts/gets"); 726 "from setup puts/gets");
757 fprintf (stderr, 727 fprintf (stderr, "Issuing %llu PUTs (one per peer)\n",
758 "Issuing %llu PUTs (one per peer)\n", 728 (unsigned long long) (num_peers * num_peers));
759 (unsigned long long) (num_peers * num_peers));
760 for (i = 0; i < num_peers * num_peers; i++) 729 for (i = 0; i < num_peers * num_peers; i++)
761 { 730 {
762 test_put = GNUNET_malloc (sizeof (struct TestPutContext)); 731 test_put = GNUNET_malloc (sizeof (struct TestPutContext));
763 test_put->uid = i; 732 test_put->uid = i;
764 test_put->daemon = GNUNET_TESTING_daemon_get (pg, i % num_peers); 733 test_put->daemon = GNUNET_TESTING_daemon_get (pg, i % num_peers);
765 test_put->task = GNUNET_SCHEDULER_add_now (&do_put, test_put); 734 test_put->task = GNUNET_SCHEDULER_add_now (&do_put, test_put);
766 GNUNET_CONTAINER_DLL_insert (all_puts_head, 735 GNUNET_CONTAINER_DLL_insert (all_puts_head, all_puts_tail, test_put);
767 all_puts_tail,
768 test_put);
769 } 736 }
770} 737}
771 738
@@ -782,17 +749,13 @@ startup_done (void *cls, const char *emsg)
782{ 749{
783 if (emsg != NULL) 750 if (emsg != NULL)
784 { 751 {
785 fprintf (stderr, 752 fprintf (stderr, "Failed to setup topology: %s\n", emsg);
786 "Failed to setup topology: %s\n", 753 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "topology setup failed");
787 emsg);
788 die_task =
789 GNUNET_SCHEDULER_add_now (&end_badly,
790 "topology setup failed");
791 return; 754 return;
792 } 755 }
793 die_task = 756 die_task =
794 GNUNET_SCHEDULER_add_delayed (START_DELAY, &run_dht_test, 757 GNUNET_SCHEDULER_add_delayed (START_DELAY, &run_dht_test,
795 "from setup puts/gets"); 758 "from setup puts/gets");
796} 759}
797 760
798 761
@@ -813,13 +776,8 @@ run (void *cls, char *const *args, const char *cfgfile,
813 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers", 776 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
814 &num_peers)) 777 &num_peers))
815 num_peers = DEFAULT_NUM_PEERS; 778 num_peers = DEFAULT_NUM_PEERS;
816 pg = GNUNET_TESTING_peergroup_start (cfg, 779 pg = GNUNET_TESTING_peergroup_start (cfg, num_peers, TIMEOUT, NULL,
817 num_peers, 780 &startup_done, NULL, NULL);
818 TIMEOUT,
819 NULL,
820 &startup_done,
821 NULL,
822 NULL);
823 GNUNET_assert (NULL != pg); 781 GNUNET_assert (NULL != pg);
824} 782}
825 783
diff --git a/src/dht/test_dht_twopeer.c b/src/dht/test_dht_twopeer.c
index 8947739c4..04198b48b 100644
--- a/src/dht/test_dht_twopeer.c
+++ b/src/dht/test_dht_twopeer.c
@@ -138,9 +138,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
138{ 138{
139 const char *emsg = cls; 139 const char *emsg = cls;
140 140
141 fprintf (stderr, 141 fprintf (stderr, "Error: %s\n", emsg);
142 "Error: %s\n",
143 emsg);
144 if (curr_get_ctx.retry_task != GNUNET_SCHEDULER_NO_TASK) 142 if (curr_get_ctx.retry_task != GNUNET_SCHEDULER_NO_TASK)
145 { 143 {
146 GNUNET_SCHEDULER_cancel (curr_get_ctx.retry_task); 144 GNUNET_SCHEDULER_cancel (curr_get_ctx.retry_task);
@@ -175,10 +173,10 @@ static void
175get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, 173get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
176 const GNUNET_HashCode * key, 174 const GNUNET_HashCode * key,
177 const struct GNUNET_PeerIdentity *get_path, 175 const struct GNUNET_PeerIdentity *get_path,
178 unsigned int get_path_length, 176 unsigned int get_path_length,
179 const struct GNUNET_PeerIdentity *put_path, 177 const struct GNUNET_PeerIdentity *put_path,
180 unsigned int put_path_length, 178 unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
181 enum GNUNET_BLOCK_Type type, size_t size, const void *data) 179 size_t size, const void *data)
182{ 180{
183 struct PeerGetContext *get_context = cls; 181 struct PeerGetContext *get_context = cls;
184 182
@@ -257,9 +255,9 @@ get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
257 GNUNET_TIME_relative_multiply 255 GNUNET_TIME_relative_multiply
258 (GNUNET_TIME_UNIT_SECONDS, 5), 256 (GNUNET_TIME_UNIT_SECONDS, 5),
259 GNUNET_BLOCK_TYPE_DHT_HELLO, 257 GNUNET_BLOCK_TYPE_DHT_HELLO,
260 &get_context->peer->hashPubKey, 258 &get_context->peer->hashPubKey, 1,
261 1, GNUNET_DHT_RO_NONE, NULL, 259 GNUNET_DHT_RO_NONE, NULL, 0, &get_result_iterator,
262 0, &get_result_iterator, get_context); 260 get_context);
263} 261}
264 262
265 263
@@ -292,9 +290,9 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
292 GNUNET_TIME_relative_multiply 290 GNUNET_TIME_relative_multiply
293 (GNUNET_TIME_UNIT_SECONDS, 5), 291 (GNUNET_TIME_UNIT_SECONDS, 5),
294 GNUNET_BLOCK_TYPE_DHT_HELLO, 292 GNUNET_BLOCK_TYPE_DHT_HELLO,
295 &get_context->peer->hashPubKey, 293 &get_context->peer->hashPubKey, 1,
296 1, GNUNET_DHT_RO_FIND_PEER, NULL, 294 GNUNET_DHT_RO_FIND_PEER, NULL, 0,
297 0, &get_result_iterator, get_context); 295 &get_result_iterator, get_context);
298} 296}
299 297
300 298
@@ -335,8 +333,8 @@ topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
335#endif 333#endif
336 GNUNET_SCHEDULER_cancel (die_task); 334 GNUNET_SCHEDULER_cancel (die_task);
337 die_task = 335 die_task =
338 GNUNET_SCHEDULER_add_delayed (TIMEOUT, 336 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
339 &end_badly, "Timeout trying to GET"); 337 "Timeout trying to GET");
340 338
341 curr_get_ctx.dht_handle = peer1dht; 339 curr_get_ctx.dht_handle = peer1dht;
342 curr_get_ctx.peer = &peer2id; 340 curr_get_ctx.peer = &peer2id;
@@ -383,9 +381,7 @@ peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
383{ 381{
384 if (emsg != NULL) 382 if (emsg != NULL)
385 { 383 {
386 fprintf (stderr, 384 fprintf (stderr, "Failed to start daemon: `%s'\n", emsg);
387 "Failed to start daemon: `%s'\n",
388 emsg);
389 return; 385 return;
390 } 386 }
391 GNUNET_assert (id != NULL); 387 GNUNET_assert (id != NULL);
diff --git a/src/dht/test_dht_twopeer_get_put.c b/src/dht/test_dht_twopeer_get_put.c
index 2a79c9ffb..d0da778ea 100644
--- a/src/dht/test_dht_twopeer_get_put.c
+++ b/src/dht/test_dht_twopeer_get_put.c
@@ -215,12 +215,11 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
215void 215void
216get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, 216get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
217 const GNUNET_HashCode * key, 217 const GNUNET_HashCode * key,
218 const struct GNUNET_PeerIdentity *get_path, 218 const struct GNUNET_PeerIdentity *get_path,
219 unsigned int get_path_size, 219 unsigned int get_path_size,
220 const struct GNUNET_PeerIdentity *put_path, 220 const struct GNUNET_PeerIdentity *put_path,
221 unsigned int put_path_size, 221 unsigned int put_path_size, enum GNUNET_BLOCK_Type type,
222 enum GNUNET_BLOCK_Type type, size_t size, 222 size_t size, const void *result_data)
223 const void *result_data)
224{ 223{
225 GNUNET_HashCode original_key; /* Key data was stored data under */ 224 GNUNET_HashCode original_key; /* Key data was stored data under */
226 char original_data[4]; /* Made up data that was stored */ 225 char original_data[4]; /* Made up data that was stored */
@@ -279,8 +278,8 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
279#else 278#else
280 GNUNET_BLOCK_TYPE_TEST, 279 GNUNET_BLOCK_TYPE_TEST,
281#endif 280#endif
282 &key, 1, GNUNET_DHT_RO_NONE, 281 &key, 1, GNUNET_DHT_RO_NONE, NULL, 0,
283 NULL, 0, &get_result_iterator, NULL); 282 &get_result_iterator, NULL);
284 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 283 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
285 (GNUNET_TIME_UNIT_SECONDS, 10), &do_put, NULL); 284 (GNUNET_TIME_UNIT_SECONDS, 10), &do_put, NULL);
286} 285}
@@ -313,10 +312,9 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
313 memset (data, 43, sizeof (data)); 312 memset (data, 43, sizeof (data));
314 313
315 /* Insert the data at the first peer */ 314 /* Insert the data at the first peer */
316 GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_NONE, 315 GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST,
317 GNUNET_BLOCK_TYPE_TEST, sizeof (data), data, 316 sizeof (data), data, GNUNET_TIME_UNIT_FOREVER_ABS,
318 GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL, 317 GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, NULL);
319 &put_finished, NULL);
320} 318}
321#else 319#else
322 320
diff --git a/src/dht/test_dht_twopeer_path_tracking.c b/src/dht/test_dht_twopeer_path_tracking.c
index f2d86e38e..61a3df0a4 100644
--- a/src/dht/test_dht_twopeer_path_tracking.c
+++ b/src/dht/test_dht_twopeer_path_tracking.c
@@ -191,10 +191,10 @@ static void
191get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, 191get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
192 const GNUNET_HashCode * key, 192 const GNUNET_HashCode * key,
193 const struct GNUNET_PeerIdentity *get_path, 193 const struct GNUNET_PeerIdentity *get_path,
194 unsigned int get_path_length, 194 unsigned int get_path_length,
195 const struct GNUNET_PeerIdentity *put_path, 195 const struct GNUNET_PeerIdentity *put_path,
196 unsigned int put_path_length, 196 unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
197 enum GNUNET_BLOCK_Type type, size_t size, const void *data) 197 size_t size, const void *data)
198{ 198{
199 GNUNET_HashCode original_key; /* Key data was stored data under */ 199 GNUNET_HashCode original_key; /* Key data was stored data under */
200 char original_data[4]; /* Made up data that was stored */ 200 char original_data[4]; /* Made up data that was stored */
@@ -220,14 +220,14 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
220 if (put_path != NULL) 220 if (put_path != NULL)
221 { 221 {
222 fprintf (stderr, "PUT Path: "); 222 fprintf (stderr, "PUT Path: ");
223 for (i = 0; i<put_path_length; i++) 223 for (i = 0; i < put_path_length; i++)
224 fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&put_path[i])); 224 fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&put_path[i]));
225 fprintf (stderr, "\n"); 225 fprintf (stderr, "\n");
226 } 226 }
227 if (get_path != NULL) 227 if (get_path != NULL)
228 { 228 {
229 fprintf (stderr, "GET Path: "); 229 fprintf (stderr, "GET Path: ");
230 for (i = 0; i<get_path_length; i++) 230 for (i = 0; i < get_path_length; i++)
231 fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&get_path[i])); 231 fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&get_path[i]));
232 fprintf (stderr, "\n"); 232 fprintf (stderr, "\n");
233 } 233 }
@@ -256,9 +256,9 @@ put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
256 memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to the same thing as when data was inserted */ 256 memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to the same thing as when data was inserted */
257 global_get_handle = 257 global_get_handle =
258 GNUNET_DHT_get_start (peer2dht, GNUNET_TIME_relative_get_forever (), 258 GNUNET_DHT_get_start (peer2dht, GNUNET_TIME_relative_get_forever (),
259 GNUNET_BLOCK_TYPE_TEST, &key, 259 GNUNET_BLOCK_TYPE_TEST, &key, 1,
260 1, GNUNET_DHT_RO_RECORD_ROUTE, 260 GNUNET_DHT_RO_RECORD_ROUTE, NULL, 0,
261 NULL, 0, &get_result_iterator, NULL); 261 &get_result_iterator, NULL);
262} 262}
263 263
264/** 264/**
@@ -274,10 +274,10 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
274 memset (data, 43, sizeof (data)); 274 memset (data, 43, sizeof (data));
275 275
276 /* Insert the data at the first peer */ 276 /* Insert the data at the first peer */
277 GNUNET_DHT_put (peer1dht, &key, 1, 277 GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_RECORD_ROUTE,
278 GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_BLOCK_TYPE_TEST, 278 GNUNET_BLOCK_TYPE_TEST, sizeof (data), data,
279 sizeof (data), data, GNUNET_TIME_UNIT_FOREVER_ABS, 279 GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL,
280 GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, NULL); 280 &put_finished, NULL);
281} 281}
282 282
283/** 283/**
diff --git a/src/dht/test_dht_twopeer_put_get.c b/src/dht/test_dht_twopeer_put_get.c
index 44009c257..275a01a32 100644
--- a/src/dht/test_dht_twopeer_put_get.c
+++ b/src/dht/test_dht_twopeer_put_get.c
@@ -207,11 +207,10 @@ static void
207get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, 207get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
208 const GNUNET_HashCode * key, 208 const GNUNET_HashCode * key,
209 const struct GNUNET_PeerIdentity *get_path, 209 const struct GNUNET_PeerIdentity *get_path,
210 unsigned int get_path_size, 210 unsigned int get_path_size,
211 const struct GNUNET_PeerIdentity *put_path, 211 const struct GNUNET_PeerIdentity *put_path,
212 unsigned int put_path_size, 212 unsigned int put_path_size, enum GNUNET_BLOCK_Type type,
213 enum GNUNET_BLOCK_Type type, size_t size, 213 size_t size, const void *result_data)
214 const void *result_data)
215{ 214{
216 GNUNET_HashCode original_key; /* Key data was stored data under */ 215 GNUNET_HashCode original_key; /* Key data was stored data under */
217 char original_data[4]; /* Made up data that was stored */ 216 char original_data[4]; /* Made up data that was stored */
@@ -254,10 +253,9 @@ put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
254 253
255 memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to the same thing as when data was inserted */ 254 memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to the same thing as when data was inserted */
256 global_get_handle = 255 global_get_handle =
257 GNUNET_DHT_get_start (peer2dht, GNUNET_TIME_UNIT_FOREVER_REL, 256 GNUNET_DHT_get_start (peer2dht, GNUNET_TIME_UNIT_FOREVER_REL,
258 GNUNET_BLOCK_TYPE_TEST, 257 GNUNET_BLOCK_TYPE_TEST, &key, 1, GNUNET_DHT_RO_NONE,
259 &key, 1, GNUNET_DHT_RO_NONE, 258 NULL, 0, &get_result_iterator, NULL);
260 NULL, 0, &get_result_iterator, NULL);
261} 259}
262 260
263 261
@@ -274,10 +272,9 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
274 memset (data, 43, sizeof (data)); 272 memset (data, 43, sizeof (data));
275 273
276 /* Insert the data at the first peer */ 274 /* Insert the data at the first peer */
277 GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_NONE, 275 GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST,
278 GNUNET_BLOCK_TYPE_TEST, sizeof (data), data, 276 sizeof (data), data, GNUNET_TIME_UNIT_FOREVER_ABS,
279 GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL, 277 GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, NULL);
280 &put_finished, NULL);
281} 278}
282 279
283 280
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c
index 7d86fc24c..60745070c 100644
--- a/src/dv/gnunet-service-dv.c
+++ b/src/dv/gnunet-service-dv.c
@@ -1349,13 +1349,13 @@ send_message_delayed (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1349 */ 1349 */
1350static uint32_t 1350static uint32_t
1351get_atsi_distance (const struct GNUNET_ATS_Information *atsi, 1351get_atsi_distance (const struct GNUNET_ATS_Information *atsi,
1352 unsigned int atsi_count) 1352 unsigned int atsi_count)
1353{ 1353{
1354 unsigned int i; 1354 unsigned int i;
1355 1355
1356 for (i=0;i<atsi_count;i++) 1356 for (i = 0; i < atsi_count; i++)
1357 if (ntohl (atsi[i].type) == GNUNET_ATS_QUALITY_NET_DISTANCE) 1357 if (ntohl (atsi[i].type) == GNUNET_ATS_QUALITY_NET_DISTANCE)
1358 return ntohl (atsi->value); 1358 return ntohl (atsi->value);
1359 /* FIXME: we do not have distance data? Assume direct neighbor. */ 1359 /* FIXME: we do not have distance data? Assume direct neighbor. */
1360 return DIRECT_NEIGHBOR_COST; 1360 return DIRECT_NEIGHBOR_COST;
1361} 1361}
@@ -1369,14 +1369,14 @@ get_atsi_distance (const struct GNUNET_ATS_Information *atsi,
1369 */ 1369 */
1370static struct GNUNET_TIME_Relative 1370static struct GNUNET_TIME_Relative
1371get_atsi_latency (const struct GNUNET_ATS_Information *atsi, 1371get_atsi_latency (const struct GNUNET_ATS_Information *atsi,
1372 unsigned int atsi_count) 1372 unsigned int atsi_count)
1373{ 1373{
1374 unsigned int i; 1374 unsigned int i;
1375 1375
1376 for (i=0;i<atsi_count;i++) 1376 for (i = 0; i < atsi_count; i++)
1377 if (ntohl (atsi[i].type) == GNUNET_ATS_QUALITY_NET_DELAY) 1377 if (ntohl (atsi[i].type) == GNUNET_ATS_QUALITY_NET_DELAY)
1378 return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 1378 return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
1379 ntohl (atsi->value)); 1379 ntohl (atsi->value));
1380 GNUNET_break (0); 1380 GNUNET_break (0);
1381 /* how can we not have latency data? */ 1381 /* how can we not have latency data? */
1382 return GNUNET_TIME_UNIT_SECONDS; 1382 return GNUNET_TIME_UNIT_SECONDS;
@@ -1398,7 +1398,7 @@ static int
1398handle_dv_data_message (void *cls, const struct GNUNET_PeerIdentity *peer, 1398handle_dv_data_message (void *cls, const struct GNUNET_PeerIdentity *peer,
1399 const struct GNUNET_MessageHeader *message, 1399 const struct GNUNET_MessageHeader *message,
1400 const struct GNUNET_ATS_Information *atsi, 1400 const struct GNUNET_ATS_Information *atsi,
1401 unsigned int atsi_count) 1401 unsigned int atsi_count)
1402{ 1402{
1403 const p2p_dv_MESSAGE_Data *incoming = (const p2p_dv_MESSAGE_Data *) message; 1403 const p2p_dv_MESSAGE_Data *incoming = (const p2p_dv_MESSAGE_Data *) message;
1404 const struct GNUNET_MessageHeader *packed_message; 1404 const struct GNUNET_MessageHeader *packed_message;
@@ -2076,14 +2076,13 @@ static int
2076handle_dv_gossip_message (void *cls, const struct GNUNET_PeerIdentity *peer, 2076handle_dv_gossip_message (void *cls, const struct GNUNET_PeerIdentity *peer,
2077 const struct GNUNET_MessageHeader *message, 2077 const struct GNUNET_MessageHeader *message,
2078 const struct GNUNET_ATS_Information *atsi, 2078 const struct GNUNET_ATS_Information *atsi,
2079 unsigned int atsi_count); 2079 unsigned int atsi_count);
2080 2080
2081static int 2081static int
2082handle_dv_disconnect_message (void *cls, const struct GNUNET_PeerIdentity *peer, 2082handle_dv_disconnect_message (void *cls, const struct GNUNET_PeerIdentity *peer,
2083 const struct GNUNET_MessageHeader *message, 2083 const struct GNUNET_MessageHeader *message,
2084 const struct GNUNET_ATS_Information 2084 const struct GNUNET_ATS_Information *atsi,
2085 *atsi, 2085 unsigned int atsi_count);
2086 unsigned int atsi_count);
2087/** End forward declarations **/ 2086/** End forward declarations **/
2088 2087
2089 2088
@@ -2658,10 +2657,10 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity *peer,
2658 atsi[1].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY); 2657 atsi[1].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
2659 atsi[1].value = 2658 atsi[1].value =
2660 htonl ((uint32_t) referrer->pending_messages[i]. 2659 htonl ((uint32_t) referrer->pending_messages[i].
2661 latency.rel_value); 2660 latency.rel_value);
2662 handle_dv_data_message (NULL, &referrer->pending_messages[i].sender, 2661 handle_dv_data_message (NULL, &referrer->pending_messages[i].sender,
2663 referrer->pending_messages[i].message, 2662 referrer->pending_messages[i].message, atsi,
2664 atsi, 2); 2663 2);
2665 GNUNET_free (referrer->pending_messages[i].message); 2664 GNUNET_free (referrer->pending_messages[i].message);
2666 referrer->pending_messages[i].sender_id = 0; 2665 referrer->pending_messages[i].sender_id = 0;
2667 } 2666 }
@@ -2732,9 +2731,8 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity *peer,
2732static int 2731static int
2733handle_dv_disconnect_message (void *cls, const struct GNUNET_PeerIdentity *peer, 2732handle_dv_disconnect_message (void *cls, const struct GNUNET_PeerIdentity *peer,
2734 const struct GNUNET_MessageHeader *message, 2733 const struct GNUNET_MessageHeader *message,
2735 const struct GNUNET_ATS_Information 2734 const struct GNUNET_ATS_Information *atsi,
2736 *atsi, 2735 unsigned int atsi_count)
2737 unsigned int atsi_count)
2738{ 2736{
2739 struct DirectNeighbor *referrer; 2737 struct DirectNeighbor *referrer;
2740 struct DistantNeighbor *distant; 2738 struct DistantNeighbor *distant;
@@ -2784,7 +2782,7 @@ static int
2784handle_dv_gossip_message (void *cls, const struct GNUNET_PeerIdentity *peer, 2782handle_dv_gossip_message (void *cls, const struct GNUNET_PeerIdentity *peer,
2785 const struct GNUNET_MessageHeader *message, 2783 const struct GNUNET_MessageHeader *message,
2786 const struct GNUNET_ATS_Information *atsi, 2784 const struct GNUNET_ATS_Information *atsi,
2787 unsigned int atsi_count) 2785 unsigned int atsi_count)
2788{ 2786{
2789 struct DirectNeighbor *referrer; 2787 struct DirectNeighbor *referrer;
2790 p2p_dv_MESSAGE_NeighborInfo *enc_message = 2788 p2p_dv_MESSAGE_NeighborInfo *enc_message =
@@ -3087,7 +3085,7 @@ process_peerinfo (void *cls, const struct GNUNET_PeerIdentity *peer,
3087static void 3085static void
3088handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, 3086handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
3089 const struct GNUNET_ATS_Information *atsi, 3087 const struct GNUNET_ATS_Information *atsi,
3090 unsigned int atsi_count) 3088 unsigned int atsi_count)
3091{ 3089{
3092 struct DirectNeighbor *neighbor; 3090 struct DirectNeighbor *neighbor;
3093 struct DistantNeighbor *about; 3091 struct DistantNeighbor *about;
@@ -3294,8 +3292,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
3294 GNUNET_SERVER_add_handlers (server, plugin_handlers); 3292 GNUNET_SERVER_add_handlers (server, plugin_handlers);
3295 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? */
3296 &core_init, &handle_core_connect, 3294 &core_init, &handle_core_connect,
3297 &handle_core_disconnect, NULL, GNUNET_NO, 3295 &handle_core_disconnect, NULL, GNUNET_NO, NULL,
3298 NULL, GNUNET_NO, core_handlers); 3296 GNUNET_NO, core_handlers);
3299 3297
3300 if (coreAPI == NULL) 3298 if (coreAPI == NULL)
3301 return; 3299 return;
diff --git a/src/dv/plugin_transport_dv.c b/src/dv/plugin_transport_dv.c
index 5e2a6bd6c..6b585f6cc 100644
--- a/src/dv/plugin_transport_dv.c
+++ b/src/dv/plugin_transport_dv.c
@@ -171,8 +171,8 @@ handle_dv_message_received (void *cls, struct GNUNET_PeerIdentity *sender,
171 171
172 plugin->env->receive (plugin->env->cls, sender, 172 plugin->env->receive (plugin->env->cls, sender,
173 (struct GNUNET_MessageHeader *) msg, 173 (struct GNUNET_MessageHeader *) msg,
174 (const struct GNUNET_ATS_Information *) &ats, 174 (const struct GNUNET_ATS_Information *) &ats, 2, NULL,
175 2, NULL, sender_address, sender_address_len); 175 sender_address, sender_address_len);
176 176
177} 177}
178 178
diff --git a/src/dv/test_transport_api_dv.c b/src/dv/test_transport_api_dv.c
index 82b3cb235..0a3bbaa51 100644
--- a/src/dv/test_transport_api_dv.c
+++ b/src/dv/test_transport_api_dv.c
@@ -596,8 +596,8 @@ connect_notify_peer1 (void *cls, const struct GNUNET_PeerIdentity *peer,
596 */ 596 */
597 pos->peer2handle = 597 pos->peer2handle =
598 GNUNET_CORE_connect (pos->peer2->cfg, 1, pos, &init_notify_peer2, 598 GNUNET_CORE_connect (pos->peer2->cfg, 1, pos, &init_notify_peer2,
599 &connect_notify_peer2, NULL, NULL, 599 &connect_notify_peer2, NULL, NULL, GNUNET_YES,
600 GNUNET_YES, NULL, GNUNET_YES, handlers); 600 NULL, GNUNET_YES, handlers);
601 } 601 }
602} 602}
603 603
@@ -646,8 +646,8 @@ send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
646 */ 646 */
647 pos->peer1handle = 647 pos->peer1handle =
648 GNUNET_CORE_connect (pos->peer1->cfg, 1, pos, &init_notify_peer1, 648 GNUNET_CORE_connect (pos->peer1->cfg, 1, pos, &init_notify_peer1,
649 &connect_notify_peer1, NULL, NULL, GNUNET_NO, 649 &connect_notify_peer1, NULL, NULL, GNUNET_NO, NULL,
650 NULL, GNUNET_NO, no_handlers); 650 GNUNET_NO, no_handlers);
651 651
652 GNUNET_assert (pos->peer1handle != NULL); 652 GNUNET_assert (pos->peer1handle != NULL);
653 653
@@ -936,8 +936,8 @@ peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
936 936
937 new_peer = GNUNET_malloc (sizeof (struct PeerContext)); 937 new_peer = GNUNET_malloc (sizeof (struct PeerContext));
938 new_peer->peer_handle = 938 new_peer->peer_handle =
939 GNUNET_CORE_connect (cfg, 1, d, NULL, &all_connect_handler, NULL, 939 GNUNET_CORE_connect (cfg, 1, d, NULL, &all_connect_handler, NULL, NULL,
940 NULL, GNUNET_NO, NULL, GNUNET_NO, no_handlers); 940 GNUNET_NO, NULL, GNUNET_NO, no_handlers);
941 new_peer->daemon = d; 941 new_peer->daemon = d;
942 new_peer->next = all_peers; 942 new_peer->next = all_peers;
943 all_peers = new_peer; 943 all_peers = new_peer;
diff --git a/src/fragmentation/fragmentation.c b/src/fragmentation/fragmentation.c
index ef3a57a87..47b8a1929 100644
--- a/src/fragmentation/fragmentation.c
+++ b/src/fragmentation/fragmentation.c
@@ -152,7 +152,7 @@ transmit_next (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
152 size = ntohs (fc->msg->size); 152 size = ntohs (fc->msg->size);
153 if (bit == size / (fc->mtu - sizeof (struct FragmentHeader))) 153 if (bit == size / (fc->mtu - sizeof (struct FragmentHeader)))
154 fsize = 154 fsize =
155 (size % (fc->mtu - sizeof (struct FragmentHeader))) + 155 (size % (fc->mtu - sizeof (struct FragmentHeader))) +
156 sizeof (struct FragmentHeader); 156 sizeof (struct FragmentHeader);
157 else 157 else
158 fsize = fc->mtu; 158 fsize = fc->mtu;
diff --git a/src/fragmentation/test_fragmentation.c b/src/fragmentation/test_fragmentation.c
index 8f0be87a5..1f7a1776a 100644
--- a/src/fragmentation/test_fragmentation.c
+++ b/src/fragmentation/test_fragmentation.c
@@ -65,8 +65,7 @@ static struct GNUNET_FRAGMENT_Context *frags[NUM_MSGS];
65static GNUNET_SCHEDULER_TaskIdentifier shutdown_task; 65static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
66 66
67static void 67static void
68do_shutdown (void *cls, 68do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
69 const struct GNUNET_SCHEDULER_TaskContext *tc)
70{ 69{
71 unsigned int i; 70 unsigned int i;
72 71
@@ -80,7 +79,7 @@ do_shutdown (void *cls,
80 continue; 79 continue;
81 GNUNET_FRAGMENT_context_destroy (frags[i]); 80 GNUNET_FRAGMENT_context_destroy (frags[i]);
82 frags[i] = NULL; 81 frags[i] = NULL;
83 } 82 }
84} 83}
85 84
86 85
@@ -103,8 +102,7 @@ proc_msgs (void *cls, const struct GNUNET_MessageHeader *hdr)
103 fprintf (stderr, "."); 102 fprintf (stderr, ".");
104#endif 103#endif
105 /* tolerate 10% loss, i.e. due to duplicate fragment IDs */ 104 /* tolerate 10% loss, i.e. due to duplicate fragment IDs */
106 if ( (total >= NUM_MSGS - (NUM_MSGS / 10)) && 105 if ((total >= NUM_MSGS - (NUM_MSGS / 10)) && (ret != 0))
107 (ret != 0) )
108 { 106 {
109 if (GNUNET_SCHEDULER_NO_TASK == shutdown_task) 107 if (GNUNET_SCHEDULER_NO_TASK == shutdown_task)
110 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 108 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
diff --git a/src/fs/fs_file_information.c b/src/fs/fs_file_information.c
index ce4f189a9..bb84b948e 100644
--- a/src/fs/fs_file_information.c
+++ b/src/fs/fs_file_information.c
@@ -437,7 +437,7 @@ GNUNET_FS_directory_scanner_default (void *cls, struct GNUNET_FS_Handle *h,
437 */ 437 */
438struct MetaValueInformation 438struct MetaValueInformation
439{ 439{
440 440
441 /** 441 /**
442 * Mime-type of data. 442 * Mime-type of data.
443 */ 443 */
@@ -481,21 +481,17 @@ struct MetaValueInformation
481 * used in the main libextractor library and yielding 481 * used in the main libextractor library and yielding
482 * meta data). 482 * meta data).
483 * @param type libextractor-type describing the meta data 483 * @param type libextractor-type describing the meta data
484 * @param format basic format information about data 484 * @param format basic format information about data
485 * @param data_mime_type mime-type of data (not of the original file); 485 * @param data_mime_type mime-type of data (not of the original file);
486 * can be NULL (if mime-type is not known) 486 * can be NULL (if mime-type is not known)
487 * @param data actual meta-data found 487 * @param data actual meta-data found
488 * @param data_len number of bytes in data 488 * @param data_len number of bytes in data
489 * @return 0 to continue extracting / iterating 489 * @return 0 to continue extracting / iterating
490 */ 490 */
491static int 491static int
492update_metamap (void *cls, 492update_metamap (void *cls, const char *plugin_name,
493 const char *plugin_name, 493 enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format,
494 enum EXTRACTOR_MetaType type, 494 const char *data_mime_type, const char *data, size_t data_len)
495 enum EXTRACTOR_MetaFormat format,
496 const char *data_mime_type,
497 const char *data,
498 size_t data_len)
499{ 495{
500 struct GNUNET_CONTAINER_MultiHashMap *map = cls; 496 struct GNUNET_CONTAINER_MultiHashMap *map = cls;
501 GNUNET_HashCode key; 497 GNUNET_HashCode key;
@@ -512,10 +508,10 @@ update_metamap (void *cls,
512 mvi->type = type; 508 mvi->type = type;
513 mvi->format = format; 509 mvi->format = format;
514 GNUNET_CONTAINER_multihashmap_put (map, &key, mvi, 510 GNUNET_CONTAINER_multihashmap_put (map, &key, mvi,
515 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 511 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
516 } 512 }
517 mvi->frequency++; 513 mvi->frequency++;
518 return 0; 514 return 0;
519} 515}
520 516
521 517
@@ -524,7 +520,7 @@ update_metamap (void *cls,
524 */ 520 */
525struct KeywordInformation 521struct KeywordInformation
526{ 522{
527 523
528 /** 524 /**
529 * Mime-type of keyword. 525 * Mime-type of keyword.
530 */ 526 */
@@ -581,37 +577,35 @@ struct EntryProcCls
581 * @param fi information for publishing the file 577 * @param fi information for publishing the file
582 */ 578 */
583static void 579static void
584dirproc_add (void *cls, const char *filename, 580dirproc_add (void *cls, const char *filename,
585 struct GNUNET_FS_FileInformation *fi) 581 struct GNUNET_FS_FileInformation *fi)
586{ 582{
587 struct EntryProcCls *dc = cls; 583 struct EntryProcCls *dc = cls;
588 unsigned int i; 584 unsigned int i;
589 const char *kw; 585 const char *kw;
590 struct KeywordInformation *ki; 586 struct KeywordInformation *ki;
591 GNUNET_HashCode key; 587 GNUNET_HashCode key;
592 588
593 GNUNET_assert (fi->next == NULL); 589 GNUNET_assert (fi->next == NULL);
594 GNUNET_assert (fi->dir == NULL); 590 GNUNET_assert (fi->dir == NULL);
595 fi->next = dc->entries; 591 fi->next = dc->entries;
596 dc->entries = fi; 592 dc->entries = fi;
597 dc->count++; 593 dc->count++;
598 if (NULL != fi->meta) 594 if (NULL != fi->meta)
599 GNUNET_CONTAINER_meta_data_iterate (fi->meta, 595 GNUNET_CONTAINER_meta_data_iterate (fi->meta, &update_metamap, dc->metamap);
600 &update_metamap, 596 for (i = 0; i < fi->keywords->data.ksk.keywordCount; i++)
601 dc->metamap);
602 for (i=0;i<fi->keywords->data.ksk.keywordCount;i++)
603 { 597 {
604 kw = fi->keywords->data.ksk.keywords[i]; 598 kw = fi->keywords->data.ksk.keywords[i];
605 GNUNET_CRYPTO_hash (kw, strlen(kw), &key); 599 GNUNET_CRYPTO_hash (kw, strlen (kw), &key);
606 ki = GNUNET_CONTAINER_multihashmap_get (dc->keywordmap, &key); 600 ki = GNUNET_CONTAINER_multihashmap_get (dc->keywordmap, &key);
607 if (ki == NULL) 601 if (ki == NULL)
608 { 602 {
609 ki = GNUNET_malloc (sizeof (struct KeywordInformation)); 603 ki = GNUNET_malloc (sizeof (struct KeywordInformation));
610 ki->keyword = &kw[1]; 604 ki->keyword = &kw[1];
611 GNUNET_CONTAINER_multihashmap_put (dc->keywordmap, &key, ki, 605 GNUNET_CONTAINER_multihashmap_put (dc->keywordmap, &key, ki,
612 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 606 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
613 } 607 }
614 ki->frequency++; 608 ki->frequency++;
615 } 609 }
616} 610}
617 611
@@ -633,7 +627,7 @@ struct ComputeDirectoryMetadataContext
633 627
634 /** 628 /**
635 * Threshold to apply for adding meta data. 629 * Threshold to apply for adding meta data.
636 */ 630 */
637 unsigned int threshold; 631 unsigned int threshold;
638}; 632};
639 633
@@ -650,29 +644,22 @@ struct ComputeDirectoryMetadataContext
650 * @return GNUNET_OK 644 * @return GNUNET_OK
651 */ 645 */
652static int 646static int
653compute_directory_metadata (void *cls, 647compute_directory_metadata (void *cls, const GNUNET_HashCode * key, void *value)
654 const GNUNET_HashCode *key,
655 void *value)
656{ 648{
657 struct ComputeDirectoryMetadataContext *cdmc = cls; 649 struct ComputeDirectoryMetadataContext *cdmc = cls;
658 struct MetaValueInformation *mvi = value; 650 struct MetaValueInformation *mvi = value;
659 651
660 if (mvi->frequency > cdmc->threshold) 652 if (mvi->frequency > cdmc->threshold)
661 { 653 {
662 if (mvi->type != EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME) 654 if (mvi->type != EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME)
663 (void) GNUNET_CONTAINER_meta_data_insert (cdmc->meta, 655 (void) GNUNET_CONTAINER_meta_data_insert (cdmc->meta, "<children>",
664 "<children>", 656 mvi->type, mvi->format,
665 mvi->type, 657 mvi->mime_type, mvi->data,
666 mvi->format, 658 mvi->data_size);
667 mvi->mime_type, 659 if ((mvi->format == EXTRACTOR_METAFORMAT_UTF8) ||
668 mvi->data, 660 (mvi->format == EXTRACTOR_METAFORMAT_C_STRING))
669 mvi->data_size); 661 GNUNET_FS_uri_ksk_add_keyword (cdmc->ksk, mvi->data, GNUNET_NO);
670 if ( (mvi->format == EXTRACTOR_METAFORMAT_UTF8) || 662 }
671 (mvi->format == EXTRACTOR_METAFORMAT_C_STRING) )
672 GNUNET_FS_uri_ksk_add_keyword (cdmc->ksk,
673 mvi->data,
674 GNUNET_NO);
675 }
676 GNUNET_free (mvi); 663 GNUNET_free (mvi);
677 return GNUNET_OK; 664 return GNUNET_OK;
678} 665}
@@ -680,7 +667,7 @@ compute_directory_metadata (void *cls,
680 667
681/** 668/**
682 * Add keywords that occur in more than the threshold entries of the 669 * Add keywords that occur in more than the threshold entries of the
683 * directory to the directory itself. 670 * directory to the directory itself.
684 * 671 *
685 * @param cls the 'struct ComputeDirectoryMetadataContext' 672 * @param cls the 'struct ComputeDirectoryMetadataContext'
686 * @param key unused 673 * @param key unused
@@ -688,17 +675,13 @@ compute_directory_metadata (void *cls,
688 * @return GNUNET_OK 675 * @return GNUNET_OK
689 */ 676 */
690static int 677static int
691compute_directory_keywords (void *cls, 678compute_directory_keywords (void *cls, const GNUNET_HashCode * key, void *value)
692 const GNUNET_HashCode *key,
693 void *value)
694{ 679{
695 struct ComputeDirectoryMetadataContext *cdmc = cls; 680 struct ComputeDirectoryMetadataContext *cdmc = cls;
696 struct KeywordInformation *ki = value; 681 struct KeywordInformation *ki = value;
697 682
698 if (ki->frequency > cdmc->threshold) 683 if (ki->frequency > cdmc->threshold)
699 (void) GNUNET_FS_uri_ksk_add_keyword (cdmc->ksk, 684 (void) GNUNET_FS_uri_ksk_add_keyword (cdmc->ksk, ki->keyword, GNUNET_NO);
700 ki->keyword,
701 GNUNET_NO);
702 GNUNET_free (ki); 685 GNUNET_free (ki);
703 return GNUNET_OK; 686 return GNUNET_OK;
704} 687}
@@ -751,36 +734,31 @@ GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h,
751 dc.metamap = GNUNET_CONTAINER_multihashmap_create (64); 734 dc.metamap = GNUNET_CONTAINER_multihashmap_create (64);
752 dc.keywordmap = GNUNET_CONTAINER_multihashmap_create (64); 735 dc.keywordmap = GNUNET_CONTAINER_multihashmap_create (64);
753 /* update children to point to directory and generate statistics 736 /* update children to point to directory and generate statistics
754 on all meta data in children */ 737 * on all meta data in children */
755 scanner (scanner_cls, h, filename, do_index, bo, &dirproc_add, &dc, emsg); 738 scanner (scanner_cls, h, filename, do_index, bo, &dirproc_add, &dc, emsg);
756 cdmc.meta = GNUNET_CONTAINER_meta_data_create (); 739 cdmc.meta = GNUNET_CONTAINER_meta_data_create ();
757 cdmc.ksk = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); 740 cdmc.ksk = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
758 cdmc.ksk->type = ksk; 741 cdmc.ksk->type = ksk;
759 cdmc.threshold = 1 + dc.count / 2; /* 50% threshold for now */ 742 cdmc.threshold = 1 + dc.count / 2; /* 50% threshold for now */
760 GNUNET_FS_meta_data_make_directory (cdmc.meta); 743 GNUNET_FS_meta_data_make_directory (cdmc.meta);
761 GNUNET_CONTAINER_multihashmap_iterate (dc.metamap, 744 GNUNET_CONTAINER_multihashmap_iterate (dc.metamap,
762 &compute_directory_metadata, 745 &compute_directory_metadata, &cdmc);
763 &cdmc);
764 GNUNET_CONTAINER_multihashmap_iterate (dc.keywordmap, 746 GNUNET_CONTAINER_multihashmap_iterate (dc.keywordmap,
765 &compute_directory_keywords, 747 &compute_directory_keywords, &cdmc);
766 &cdmc);
767 GNUNET_CONTAINER_multihashmap_destroy (dc.metamap); 748 GNUNET_CONTAINER_multihashmap_destroy (dc.metamap);
768 GNUNET_CONTAINER_multihashmap_destroy (dc.keywordmap); 749 GNUNET_CONTAINER_multihashmap_destroy (dc.keywordmap);
769 GNUNET_FS_uri_ksk_add_keyword (cdmc.ksk, 750 GNUNET_FS_uri_ksk_add_keyword (cdmc.ksk, GNUNET_FS_DIRECTORY_MIME, GNUNET_NO);
770 GNUNET_FS_DIRECTORY_MIME,
771 GNUNET_NO);
772 cksk = GNUNET_FS_uri_ksk_canonicalize (cdmc.ksk); 751 cksk = GNUNET_FS_uri_ksk_canonicalize (cdmc.ksk);
773 752
774 /* remove keywords in children that are already in the 753 /* remove keywords in children that are already in the
775 parent */ 754 * parent */
776 for (epos = dc.entries; NULL != epos; epos = epos->next) 755 for (epos = dc.entries; NULL != epos; epos = epos->next)
777 { 756 {
778 for (i=0;i<cksk->data.ksk.keywordCount;i++) 757 for (i = 0; i < cksk->data.ksk.keywordCount; i++)
779 { 758 {
780 kw = cksk->data.ksk.keywords[i]; 759 kw = cksk->data.ksk.keywords[i];
781 GNUNET_FS_uri_ksk_remove_keyword (epos->keywords, 760 GNUNET_FS_uri_ksk_remove_keyword (epos->keywords, &kw[1]);
782 &kw[1]); 761 }
783 }
784 } 762 }
785 ret = 763 ret =
786 GNUNET_FS_file_information_create_empty_directory (h, client_info, cksk, 764 GNUNET_FS_file_information_create_empty_directory (h, client_info, cksk,
diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c
index 2057a18f6..48fabc1fb 100644
--- a/src/fs/fs_uri.c
+++ b/src/fs/fs_uri.c
@@ -1033,9 +1033,8 @@ canonicalize_keyword (const char *in)
1033 wpos++; 1033 wpos++;
1034 break; 1034 break;
1035 default: 1035 default:
1036 if (isspace ((unsigned char) *rpos) || 1036 if (isspace ((unsigned char) *rpos) || isdigit ((unsigned char) *rpos))
1037 isdigit ((unsigned char) *rpos) ) 1037 break;
1038 break;
1039 /* replace characters listed above with '_' */ 1038 /* replace characters listed above with '_' */
1040 *wpos = '_'; 1039 *wpos = '_';
1041 wpos++; 1040 wpos++;
@@ -1073,24 +1072,19 @@ GNUNET_FS_uri_ksk_canonicalize (const struct GNUNET_FS_Uri *uri)
1073 for (i = 0; i < kc; i++) 1072 for (i = 0; i < kc; i++)
1074 { 1073 {
1075 in = uri->data.ksk.keywords[i]; 1074 in = uri->data.ksk.keywords[i];
1076 GNUNET_FS_uri_ksk_add_keyword (ret, 1075 GNUNET_FS_uri_ksk_add_keyword (ret, &in[1],
1077 &in[1], 1076 (in[0] == '+') ? GNUNET_YES : GNUNET_NO);
1078 (in[0] == '+') ? GNUNET_YES : GNUNET_NO);
1079 sb = GNUNET_strdup (&in[1]); 1077 sb = GNUNET_strdup (&in[1]);
1080#define DELIMS " \\|\"'`/&@-_,.;!?+-*^$#~=[]{}()<>" 1078#define DELIMS " \\|\"'`/&@-_,.;!?+-*^$#~=[]{}()<>"
1081 for (tok = strtok (sb, DELIMS); NULL != tok; tok = strtok (NULL, DELIMS)) 1079 for (tok = strtok (sb, DELIMS); NULL != tok; tok = strtok (NULL, DELIMS))
1082#undef DELIMS 1080#undef DELIMS
1083 { 1081 {
1084 if (strlen(tok) < 3) 1082 if (strlen (tok) < 3)
1085 continue; 1083 continue;
1086 GNUNET_FS_uri_ksk_add_keyword (ret, 1084 GNUNET_FS_uri_ksk_add_keyword (ret, tok, GNUNET_NO);
1087 tok,
1088 GNUNET_NO);
1089 cc = canonicalize_keyword (tok); 1085 cc = canonicalize_keyword (tok);
1090 if (strlen (cc) > 2) 1086 if (strlen (cc) > 2)
1091 GNUNET_FS_uri_ksk_add_keyword (ret, 1087 GNUNET_FS_uri_ksk_add_keyword (ret, cc, GNUNET_NO);
1092 cc,
1093 GNUNET_NO);
1094 } 1088 }
1095 GNUNET_free (sb); 1089 GNUNET_free (sb);
1096 } 1090 }
diff --git a/src/fs/gnunet-fs.c b/src/fs/gnunet-fs.c
index 9b3602d73..310c8a1ae 100644
--- a/src/fs/gnunet-fs.c
+++ b/src/fs/gnunet-fs.c
@@ -53,8 +53,7 @@ static int verbose;
53 * @param tc unused 53 * @param tc unused
54 */ 54 */
55static void 55static void
56do_shutdown (void *cls, 56do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
57 const struct GNUNET_SCHEDULER_TaskContext *tc)
58{ 57{
59 GNUNET_FS_stop (fs); 58 GNUNET_FS_stop (fs);
60 fs = NULL; 59 fs = NULL;
@@ -70,18 +69,12 @@ do_shutdown (void *cls,
70 * @return GNUNET_OK to continue iteration 69 * @return GNUNET_OK to continue iteration
71 */ 70 */
72static int 71static int
73print_indexed (void *cls, const char *filename, 72print_indexed (void *cls, const char *filename, const GNUNET_HashCode * file_id)
74 const GNUNET_HashCode * file_id)
75{ 73{
76 if (verbose) 74 if (verbose)
77 fprintf (stdout, 75 fprintf (stdout, "%s: %s\n", GNUNET_h2s (file_id), filename);
78 "%s: %s\n",
79 GNUNET_h2s (file_id),
80 filename);
81 else 76 else
82 fprintf (stdout, 77 fprintf (stdout, "%s\n", filename);
83 "%s\n",
84 filename);
85 return GNUNET_OK; 78 return GNUNET_OK;
86} 79}
87 80
@@ -100,18 +93,13 @@ run (void *cls, char *const *args, const char *cfgfile,
100{ 93{
101 if (list_indexed_files) 94 if (list_indexed_files)
102 { 95 {
103 fs = GNUNET_FS_start (cfg, 96 fs = GNUNET_FS_start (cfg, "gnunet-fs", NULL, NULL, GNUNET_FS_FLAGS_NONE);
104 "gnunet-fs",
105 NULL, NULL,
106 GNUNET_FS_FLAGS_NONE);
107 if (NULL == fs) 97 if (NULL == fs)
108 { 98 {
109 ret = 1; 99 ret = 1;
110 return; 100 return;
111 } 101 }
112 GNUNET_FS_get_indexed_files (fs, 102 GNUNET_FS_get_indexed_files (fs, &print_indexed, NULL, &do_shutdown, NULL);
113 &print_indexed, NULL,
114 &do_shutdown, NULL);
115 } 103 }
116} 104}
117 105
@@ -134,8 +122,7 @@ main (int argc, char *const *argv)
134 }; 122 };
135 return (GNUNET_OK == 123 return (GNUNET_OK ==
136 GNUNET_PROGRAM_run (argc, argv, "gnunet-fs [OPTIONS]", 124 GNUNET_PROGRAM_run (argc, argv, "gnunet-fs [OPTIONS]",
137 gettext_noop 125 gettext_noop ("Special file-sharing operations"),
138 ("Special file-sharing operations"),
139 options, &run, NULL)) ? ret : 1; 126 options, &run, NULL)) ? ret : 1;
140} 127}
141 128
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c
index 404993130..f588ee9c4 100644
--- a/src/fs/gnunet-service-fs.c
+++ b/src/fs/gnunet-service-fs.c
@@ -226,19 +226,20 @@ GSF_test_get_load_too_high_ (uint32_t priority)
226 */ 226 */
227static void 227static void
228update_latencies (const struct GNUNET_ATS_Information *atsi, 228update_latencies (const struct GNUNET_ATS_Information *atsi,
229 unsigned int atsi_count) 229 unsigned int atsi_count)
230{ 230{
231 unsigned int i; 231 unsigned int i;
232 232
233 for (i=0;i<atsi_count;i++) 233 for (i = 0; i < atsi_count; i++)
234 { 234 {
235 if (ntohl(atsi[i].type) == GNUNET_ATS_QUALITY_NET_DELAY) 235 if (ntohl (atsi[i].type) == GNUNET_ATS_QUALITY_NET_DELAY)
236 { 236 {
237 GSF_avg_latency.rel_value = (GSF_avg_latency.rel_value * 31 + ntohl (atsi[i].value)) / 32; 237 GSF_avg_latency.rel_value =
238 (GSF_avg_latency.rel_value * 31 + ntohl (atsi[i].value)) / 32;
238 GNUNET_STATISTICS_set (GSF_stats, 239 GNUNET_STATISTICS_set (GSF_stats,
239 gettext_noop ("# running average P2P latency (ms)"), 240 gettext_noop
240 GSF_avg_latency.rel_value, 241 ("# running average P2P latency (ms)"),
241 GNUNET_NO); 242 GSF_avg_latency.rel_value, GNUNET_NO);
242 break; 243 break;
243 } 244 }
244 } 245 }
@@ -261,7 +262,7 @@ static int
261handle_p2p_put (void *cls, const struct GNUNET_PeerIdentity *other, 262handle_p2p_put (void *cls, const struct GNUNET_PeerIdentity *other,
262 const struct GNUNET_MessageHeader *message, 263 const struct GNUNET_MessageHeader *message,
263 const struct GNUNET_ATS_Information *atsi, 264 const struct GNUNET_ATS_Information *atsi,
264 unsigned int atsi_count) 265 unsigned int atsi_count)
265{ 266{
266 struct GSF_ConnectedPeer *cp; 267 struct GSF_ConnectedPeer *cp;
267 268
@@ -294,13 +295,11 @@ consider_request_for_forwarding (void *cls,
294{ 295{
295 struct GSF_PendingRequest *pr = cls; 296 struct GSF_PendingRequest *pr = cls;
296 297
297 if (GNUNET_YES != 298 if (GNUNET_YES != GSF_pending_request_test_target_ (pr, peer))
298 GSF_pending_request_test_target_ (pr,
299 peer))
300 { 299 {
301 GNUNET_STATISTICS_update (GSF_stats, 300 GNUNET_STATISTICS_update (GSF_stats,
302 gettext_noop ("# Loopback routes suppressed"), 1, 301 gettext_noop ("# Loopback routes suppressed"), 1,
303 GNUNET_NO); 302 GNUNET_NO);
304 return; 303 return;
305 } 304 }
306 GSF_plan_add_ (cp, pr); 305 GSF_plan_add_ (cp, pr);
@@ -343,7 +342,7 @@ static int
343handle_p2p_get (void *cls, const struct GNUNET_PeerIdentity *other, 342handle_p2p_get (void *cls, const struct GNUNET_PeerIdentity *other,
344 const struct GNUNET_MessageHeader *message, 343 const struct GNUNET_MessageHeader *message,
345 const struct GNUNET_ATS_Information *atsi, 344 const struct GNUNET_ATS_Information *atsi,
346 unsigned int atsi_count) 345 unsigned int atsi_count)
347{ 346{
348 struct GSF_PendingRequest *pr; 347 struct GSF_PendingRequest *pr;
349 348
@@ -475,13 +474,11 @@ consider_peer_for_forwarding (void *cls, const GNUNET_HashCode * key,
475 struct GNUNET_PeerIdentity pid; 474 struct GNUNET_PeerIdentity pid;
476 475
477 GSF_connected_peer_get_identity_ (cp, &pid); 476 GSF_connected_peer_get_identity_ (cp, &pid);
478 if (GNUNET_YES != 477 if (GNUNET_YES != GSF_pending_request_test_target_ (pr, &pid))
479 GSF_pending_request_test_target_ (pr,
480 &pid))
481 { 478 {
482 GNUNET_STATISTICS_update (GSF_stats, 479 GNUNET_STATISTICS_update (GSF_stats,
483 gettext_noop ("# Loopback routes suppressed"), 1, 480 gettext_noop ("# Loopback routes suppressed"), 1,
484 GNUNET_NO); 481 GNUNET_NO);
485 return GNUNET_YES; 482 return GNUNET_YES;
486 } 483 }
487 GSF_plan_add_ (cp, pr); 484 GSF_plan_add_ (cp, pr);
@@ -500,7 +497,7 @@ consider_peer_for_forwarding (void *cls, const GNUNET_HashCode * key,
500static void 497static void
501peer_connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer, 498peer_connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
502 const struct GNUNET_ATS_Information *atsi, 499 const struct GNUNET_ATS_Information *atsi,
503 unsigned int atsi_count) 500 unsigned int atsi_count)
504{ 501{
505 struct GSF_ConnectedPeer *cp; 502 struct GSF_ConnectedPeer *cp;
506 503
@@ -568,9 +565,8 @@ main_init (struct GNUNET_SERVER_Handle *server,
568 GSF_core = GNUNET_CORE_connect (GSF_cfg, 2, /* larger? */ 565 GSF_core = GNUNET_CORE_connect (GSF_cfg, 2, /* larger? */
569 NULL, &peer_init_handler, 566 NULL, &peer_init_handler,
570 &peer_connect_handler, 567 &peer_connect_handler,
571 &GSF_peer_disconnect_handler_, 568 &GSF_peer_disconnect_handler_, NULL,
572 NULL, GNUNET_NO, 569 GNUNET_NO, NULL, GNUNET_NO, p2p_handlers);
573 NULL, GNUNET_NO, p2p_handlers);
574 if (NULL == GSF_core) 570 if (NULL == GSF_core)
575 { 571 {
576 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 572 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c
index 859d9275f..d4c81d509 100644
--- a/src/fs/gnunet-service-fs_cp.c
+++ b/src/fs/gnunet-service-fs_cp.c
@@ -332,15 +332,14 @@ get_trust_filename (const struct GNUNET_PeerIdentity *id)
332 * @return connection latency 332 * @return connection latency
333 */ 333 */
334static struct GNUNET_TIME_Relative 334static struct GNUNET_TIME_Relative
335get_latency (const struct GNUNET_ATS_Information *atsi, 335get_latency (const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count)
336 unsigned int atsi_count)
337{ 336{
338 unsigned int i; 337 unsigned int i;
339 338
340 for (i=0;i<atsi_count;i++) 339 for (i = 0; i < atsi_count; i++)
341 if (ntohl (atsi->type) == GNUNET_ATS_QUALITY_NET_DELAY) 340 if (ntohl (atsi->type) == GNUNET_ATS_QUALITY_NET_DELAY)
342 return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 341 return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
343 ntohl (atsi->value)); 342 ntohl (atsi->value));
344 return GNUNET_TIME_UNIT_SECONDS; 343 return GNUNET_TIME_UNIT_SECONDS;
345} 344}
346 345
@@ -354,8 +353,7 @@ get_latency (const struct GNUNET_ATS_Information *atsi,
354 */ 353 */
355static void 354static void
356update_atsi (struct GSF_ConnectedPeer *cp, 355update_atsi (struct GSF_ConnectedPeer *cp,
357 const struct GNUNET_ATS_Information *atsi, 356 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count)
358 unsigned int atsi_count)
359{ 357{
360 struct GNUNET_TIME_Relative latency; 358 struct GNUNET_TIME_Relative latency;
361 359
@@ -402,7 +400,7 @@ peer_transmit_ready_cb (void *cls, size_t size, void *buf);
402 */ 400 */
403static void 401static void
404ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer, 402ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
405 int32_t amount, struct GNUNET_TIME_Relative res_delay); 403 int32_t amount, struct GNUNET_TIME_Relative res_delay);
406 404
407 405
408/** 406/**
@@ -425,11 +423,9 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth)
425 423
426 if (0 != cp->inc_preference) 424 if (0 != cp->inc_preference)
427 { 425 {
428 GNUNET_ATS_change_preference (ats, 426 GNUNET_ATS_change_preference (ats, &target, GNUNET_ATS_PREFERENCE_BANDWIDTH,
429 &target, 427 (double) cp->inc_preference,
430 GNUNET_ATS_PREFERENCE_BANDWIDTH, 428 GNUNET_ATS_PREFERENCE_END);
431 (double) cp->inc_preference,
432 GNUNET_ATS_PREFERENCE_END);
433 cp->inc_preference = 0; 429 cp->inc_preference = 0;
434 } 430 }
435 431
@@ -442,9 +438,8 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth)
442 /* reservation already done! */ 438 /* reservation already done! */
443 pth->was_reserved = GNUNET_YES; 439 pth->was_reserved = GNUNET_YES;
444 cp->rc = 440 cp->rc =
445 GNUNET_ATS_reserve_bandwidth (ats, &target, 441 GNUNET_ATS_reserve_bandwidth (ats, &target, DBLOCK_SIZE,
446 DBLOCK_SIZE, 442 &ats_reserve_callback, cp);
447 &ats_reserve_callback, cp);
448 } 443 }
449 GNUNET_assert (pth->cth == NULL); 444 GNUNET_assert (pth->cth == NULL);
450 pth->cth_in_progress++; 445 pth->cth_in_progress++;
@@ -525,9 +520,8 @@ retry_reservation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
525 GNUNET_PEER_resolve (cp->ppd.pid, &target); 520 GNUNET_PEER_resolve (cp->ppd.pid, &target);
526 cp->rc_delay_task = GNUNET_SCHEDULER_NO_TASK; 521 cp->rc_delay_task = GNUNET_SCHEDULER_NO_TASK;
527 cp->rc = 522 cp->rc =
528 GNUNET_ATS_reserve_bandwidth (ats, &target, 523 GNUNET_ATS_reserve_bandwidth (ats, &target, DBLOCK_SIZE,
529 DBLOCK_SIZE, 524 &ats_reserve_callback, cp);
530 &ats_reserve_callback, cp);
531} 525}
532 526
533 527
@@ -543,15 +537,14 @@ retry_reservation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
543 */ 537 */
544static void 538static void
545ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer, 539ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
546 int32_t amount, struct GNUNET_TIME_Relative res_delay) 540 int32_t amount, struct GNUNET_TIME_Relative res_delay)
547{ 541{
548 struct GSF_ConnectedPeer *cp = cls; 542 struct GSF_ConnectedPeer *cp = cls;
549 struct GSF_PeerTransmitHandle *pth; 543 struct GSF_PeerTransmitHandle *pth;
550 544
551 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 545 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
552 "Reserved %d bytes / need to wait %llu ms for reservation\n", 546 "Reserved %d bytes / need to wait %llu ms for reservation\n",
553 (int) amount, 547 (int) amount, (unsigned long long) res_delay.rel_value);
554 (unsigned long long) res_delay.rel_value);
555 cp->rc = NULL; 548 cp->rc = NULL;
556 if (0 == amount) 549 if (0 == amount)
557 { 550 {
@@ -587,22 +580,20 @@ ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
587struct GSF_ConnectedPeer * 580struct GSF_ConnectedPeer *
588GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer, 581GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
589 const struct GNUNET_ATS_Information *atsi, 582 const struct GNUNET_ATS_Information *atsi,
590 unsigned int atsi_count) 583 unsigned int atsi_count)
591{ 584{
592 struct GSF_ConnectedPeer *cp; 585 struct GSF_ConnectedPeer *cp;
593 char *fn; 586 char *fn;
594 uint32_t trust; 587 uint32_t trust;
595 588
596 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 589 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected to peer %s\n",
597 "Connected to peer %s\n", 590 GNUNET_i2s (peer));
598 GNUNET_i2s (peer));
599 cp = GNUNET_malloc (sizeof (struct GSF_ConnectedPeer)); 591 cp = GNUNET_malloc (sizeof (struct GSF_ConnectedPeer));
600 cp->ppd.pid = GNUNET_PEER_intern (peer); 592 cp->ppd.pid = GNUNET_PEER_intern (peer);
601 cp->ppd.transmission_delay = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_ZERO); 593 cp->ppd.transmission_delay = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_ZERO);
602 cp->rc = 594 cp->rc =
603 GNUNET_ATS_reserve_bandwidth (ats, peer, 595 GNUNET_ATS_reserve_bandwidth (ats, peer, DBLOCK_SIZE,
604 DBLOCK_SIZE, 596 &ats_reserve_callback, cp);
605 &ats_reserve_callback, cp);
606 fn = get_trust_filename (peer); 597 fn = get_trust_filename (peer);
607 if ((GNUNET_DISK_file_test (fn) == GNUNET_YES) && 598 if ((GNUNET_DISK_file_test (fn) == GNUNET_YES) &&
608 (sizeof (trust) == GNUNET_DISK_fn_read (fn, &trust, sizeof (trust)))) 599 (sizeof (trust) == GNUNET_DISK_fn_read (fn, &trust, sizeof (trust))))
@@ -613,11 +604,9 @@ GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
613 GNUNET_CONTAINER_multihashmap_put (cp_map, &peer->hashPubKey, 604 GNUNET_CONTAINER_multihashmap_put (cp_map, &peer->hashPubKey,
614 cp, 605 cp,
615 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 606 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
616 GNUNET_STATISTICS_set (GSF_stats, 607 GNUNET_STATISTICS_set (GSF_stats, gettext_noop ("# peers connected"),
617 gettext_noop 608 GNUNET_CONTAINER_multihashmap_size (cp_map),
618 ("# peers connected"), 609 GNUNET_NO);
619 GNUNET_CONTAINER_multihashmap_size (cp_map),
620 GNUNET_NO);
621 update_atsi (cp, atsi, atsi_count); 610 update_atsi (cp, atsi, atsi_count);
622 GSF_push_start_ (cp); 611 GSF_push_start_ (cp);
623 return cp; 612 return cp;
@@ -681,9 +670,8 @@ int
681GSF_handle_p2p_migration_stop_ (void *cls, 670GSF_handle_p2p_migration_stop_ (void *cls,
682 const struct GNUNET_PeerIdentity *other, 671 const struct GNUNET_PeerIdentity *other,
683 const struct GNUNET_MessageHeader *message, 672 const struct GNUNET_MessageHeader *message,
684 const struct GNUNET_ATS_Information 673 const struct GNUNET_ATS_Information *atsi,
685 *atsi, 674 unsigned int atsi_count)
686 unsigned int atsi_count)
687{ 675{
688 struct GSF_ConnectedPeer *cp; 676 struct GSF_ConnectedPeer *cp;
689 const struct MigrationStopMessage *msm; 677 const struct MigrationStopMessage *msm;
@@ -697,9 +685,8 @@ GSF_handle_p2p_migration_stop_ (void *cls,
697 return GNUNET_OK; 685 return GNUNET_OK;
698 } 686 }
699 GNUNET_STATISTICS_update (GSF_stats, 687 GNUNET_STATISTICS_update (GSF_stats,
700 gettext_noop 688 gettext_noop ("# migration stop messages received"),
701 ("# migration stop messages received"), 689 1, GNUNET_NO);
702 1, GNUNET_NO);
703 bt = GNUNET_TIME_relative_ntoh (msm->duration); 690 bt = GNUNET_TIME_relative_ntoh (msm->duration);
704 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 691 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
705 _("Migration of content to peer `%s' blocked for %llu ms\n"), 692 _("Migration of content to peer `%s' blocked for %llu ms\n"),
@@ -841,8 +828,8 @@ get_randomized_delay ()
841 ret = 828 ret =
842 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 829 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
843 GNUNET_CRYPTO_random_u32 830 GNUNET_CRYPTO_random_u32
844 (GNUNET_CRYPTO_QUALITY_WEAK, 831 (GNUNET_CRYPTO_QUALITY_WEAK,
845 2 * GSF_avg_latency.rel_value + 1)); 832 2 * GSF_avg_latency.rel_value + 1));
846 GNUNET_STATISTICS_update (GSF_stats, 833 GNUNET_STATISTICS_update (GSF_stats,
847 gettext_noop 834 gettext_noop
848 ("# artificial delays introduced (ms)"), 835 ("# artificial delays introduced (ms)"),
@@ -1179,7 +1166,7 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
1179 return NULL; 1166 return NULL;
1180 } 1167 }
1181 if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO)) 1168 if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO))
1182 cp = GSF_peer_get_ ((const struct GNUNET_PeerIdentity*) &opt[bits++]); 1169 cp = GSF_peer_get_ ((const struct GNUNET_PeerIdentity *) &opt[bits++]);
1183 else 1170 else
1184 cp = cps; 1171 cp = cps;
1185 if (cp == NULL) 1172 if (cp == NULL)
@@ -1323,9 +1310,7 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
1323 0) ? (const char *) &opt[bits] : NULL, 1310 0) ? (const char *) &opt[bits] : NULL,
1324 bfsize, ntohl (gm->filter_mutator), 1311 bfsize, ntohl (gm->filter_mutator),
1325 1 /* anonymity */ , 1312 1 /* anonymity */ ,
1326 (uint32_t) priority, ttl, spid, 1313 (uint32_t) priority, ttl, spid, GNUNET_PEER_intern (other), NULL, 0, /* replies_seen */
1327 GNUNET_PEER_intern (other),
1328 NULL, 0, /* replies_seen */
1329 &handle_p2p_reply, peerreq); 1314 &handle_p2p_reply, peerreq);
1330 GNUNET_assert (NULL != pr); 1315 GNUNET_assert (NULL != pr);
1331 peerreq->pr = pr; 1316 peerreq->pr = pr;
@@ -1547,11 +1532,9 @@ GSF_peer_disconnect_handler_ (void *cls, const struct GNUNET_PeerIdentity *peer)
1547 GNUNET_assert (GNUNET_YES == 1532 GNUNET_assert (GNUNET_YES ==
1548 GNUNET_CONTAINER_multihashmap_remove (cp_map, 1533 GNUNET_CONTAINER_multihashmap_remove (cp_map,
1549 &peer->hashPubKey, cp)); 1534 &peer->hashPubKey, cp));
1550 GNUNET_STATISTICS_set (GSF_stats, 1535 GNUNET_STATISTICS_set (GSF_stats, gettext_noop ("# peers connected"),
1551 gettext_noop 1536 GNUNET_CONTAINER_multihashmap_size (cp_map),
1552 ("# peers connected"), 1537 GNUNET_NO);
1553 GNUNET_CONTAINER_multihashmap_size (cp_map),
1554 GNUNET_NO);
1555 if (NULL != cp->migration_pth) 1538 if (NULL != cp->migration_pth)
1556 { 1539 {
1557 GSF_peer_transmit_cancel_ (cp->migration_pth); 1540 GSF_peer_transmit_cancel_ (cp->migration_pth);
diff --git a/src/fs/gnunet-service-fs_cp.h b/src/fs/gnunet-service-fs_cp.h
index 8923513c7..a2cc5232c 100644
--- a/src/fs/gnunet-service-fs_cp.h
+++ b/src/fs/gnunet-service-fs_cp.h
@@ -174,7 +174,7 @@ struct GSF_PeerTransmitHandle;
174struct GSF_ConnectedPeer * 174struct GSF_ConnectedPeer *
175GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer, 175GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
176 const struct GNUNET_ATS_Information *atsi, 176 const struct GNUNET_ATS_Information *atsi,
177 unsigned int atsi_count); 177 unsigned int atsi_count);
178 178
179 179
180/** 180/**
@@ -270,9 +270,8 @@ int
270GSF_handle_p2p_migration_stop_ (void *cls, 270GSF_handle_p2p_migration_stop_ (void *cls,
271 const struct GNUNET_PeerIdentity *other, 271 const struct GNUNET_PeerIdentity *other,
272 const struct GNUNET_MessageHeader *message, 272 const struct GNUNET_MessageHeader *message,
273 const struct GNUNET_ATS_Information 273 const struct GNUNET_ATS_Information *atsi,
274 *atsi, 274 unsigned int atsi_count);
275 unsigned int atsi_count);
276 275
277 276
278/** 277/**
diff --git a/src/fs/gnunet-service-fs_indexing.c b/src/fs/gnunet-service-fs_indexing.c
index 5978e4d66..41a40e125 100644
--- a/src/fs/gnunet-service-fs_indexing.c
+++ b/src/fs/gnunet-service-fs_indexing.c
@@ -538,13 +538,12 @@ GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key, uint32_t size,
538 odb = (const struct OnDemandBlock *) data; 538 odb = (const struct OnDemandBlock *) data;
539 off = GNUNET_ntohll (odb->offset); 539 off = GNUNET_ntohll (odb->offset);
540 fn = (const char *) GNUNET_CONTAINER_multihashmap_get (ifm, &odb->file_id); 540 fn = (const char *) GNUNET_CONTAINER_multihashmap_get (ifm, &odb->file_id);
541 if ( (NULL == fn) || 541 if ((NULL == fn) || (0 != ACCESS (fn, R_OK)))
542 (0 != ACCESS (fn, R_OK)) )
543 { 542 {
544 GNUNET_STATISTICS_update (GSF_stats, 543 GNUNET_STATISTICS_update (GSF_stats,
545 gettext_noop ("# index blocks removed: original file inaccessible"), 544 gettext_noop
546 1, 545 ("# index blocks removed: original file inaccessible"),
547 GNUNET_YES); 546 1, GNUNET_YES);
548 GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, 547 GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1,
549 GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL); 548 GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL);
550 return GNUNET_SYSERR; 549 return GNUNET_SYSERR;
diff --git a/src/fs/gnunet-service-fs_lc.c b/src/fs/gnunet-service-fs_lc.c
index 9f284ed8f..30a7f57d6 100644
--- a/src/fs/gnunet-service-fs_lc.c
+++ b/src/fs/gnunet-service-fs_lc.c
@@ -375,7 +375,8 @@ GSF_local_client_start_search_handler_ (struct GNUNET_SERVER_Client *client,
375 ntohl (sm->anonymity_level), 375 ntohl (sm->anonymity_level),
376 0 /* priority */ , 376 0 /* priority */ ,
377 0 /* ttl */ , 377 0 /* ttl */ ,
378 0 /* sender PID */ , 0 /* origin PID */, 378 0 /* sender PID */ ,
379 0 /* origin PID */ ,
379 (const GNUNET_HashCode *) &sm[1], sc, 380 (const GNUNET_HashCode *) &sm[1], sc,
380 &client_response_handler, cr); 381 &client_response_handler, cr);
381 return cr->pr; 382 return cr->pr;
diff --git a/src/fs/gnunet-service-fs_pe.c b/src/fs/gnunet-service-fs_pe.c
index 088a3dc11..41dd61a64 100644
--- a/src/fs/gnunet-service-fs_pe.c
+++ b/src/fs/gnunet-service-fs_pe.c
@@ -263,22 +263,25 @@ plan (struct PeerPlan *pp, struct GSF_RequestPlan *rp)
263 if (rp->transmission_counter < 8) 263 if (rp->transmission_counter < 8)
264 delay = 264 delay =
265 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 265 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
266 rp->transmission_counter); 266 rp->transmission_counter);
267 else if (rp->transmission_counter < 32) 267 else if (rp->transmission_counter < 32)
268 delay = 268 delay =
269 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 269 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
270 8 + (1LL << (rp->transmission_counter - 8))); 270 8 +
271 (1LL << (rp->transmission_counter - 8)));
271 else 272 else
272 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 273 delay =
273 8 + (1LL << 24)); 274 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
274 delay.rel_value = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 275 8 + (1LL << 24));
275 delay.rel_value + 1); 276 delay.rel_value =
277 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
278 delay.rel_value + 1);
276 if (rp->transmission_counter != 0) 279 if (rp->transmission_counter != 0)
277 delay.rel_value += TTL_DECREMENT; 280 delay.rel_value += TTL_DECREMENT;
278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 281 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
279 "Considering (re)transmission number %u in %llu ms\n", 282 "Considering (re)transmission number %u in %llu ms\n",
280 (unsigned int) rp->transmission_counter, 283 (unsigned int) rp->transmission_counter,
281 (unsigned long long) delay.rel_value); 284 (unsigned long long) delay.rel_value);
282 rp->earliest_transmission = GNUNET_TIME_relative_to_absolute (delay); 285 rp->earliest_transmission = GNUNET_TIME_relative_to_absolute (delay);
283#if DEBUG_FS 286#if DEBUG_FS
284 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 287 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -295,9 +298,9 @@ plan (struct PeerPlan *pp, struct GSF_RequestPlan *rp)
295 GNUNET_CONTAINER_heap_insert (pp->delay_heap, rp, 298 GNUNET_CONTAINER_heap_insert (pp->delay_heap, rp,
296 rp->earliest_transmission.abs_value); 299 rp->earliest_transmission.abs_value);
297 GNUNET_assert (GNUNET_YES == 300 GNUNET_assert (GNUNET_YES ==
298 GNUNET_CONTAINER_multihashmap_contains_value (pp->plan_map, 301 GNUNET_CONTAINER_multihashmap_contains_value (pp->plan_map,
299 get_rp_key (rp), 302 get_rp_key (rp),
300 rp)); 303 rp));
301 if (GNUNET_SCHEDULER_NO_TASK != pp->task) 304 if (GNUNET_SCHEDULER_NO_TASK != pp->task)
302 GNUNET_SCHEDULER_cancel (pp->task); 305 GNUNET_SCHEDULER_cancel (pp->task);
303 pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp); 306 pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp);
@@ -351,8 +354,9 @@ transmit_message_callback (void *cls, size_t buf_size, void *buf)
351 /* failed, try again... */ 354 /* failed, try again... */
352 pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp); 355 pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp);
353 GNUNET_STATISTICS_update (GSF_stats, 356 GNUNET_STATISTICS_update (GSF_stats,
354 gettext_noop ("# transmission failed (core has no bandwidth)"), 1, 357 gettext_noop
355 GNUNET_NO); 358 ("# transmission failed (core has no bandwidth)"),
359 1, GNUNET_NO);
356 return 0; 360 return 0;
357 } 361 }
358 rp = GNUNET_CONTAINER_heap_peek (pp->priority_heap); 362 rp = GNUNET_CONTAINER_heap_peek (pp->priority_heap);
@@ -433,22 +437,17 @@ schedule_peer_transmission (void *cls,
433#if DEBUG_FS 437#if DEBUG_FS
434 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 438 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
435 "Sleeping for %llu ms before retrying requests on plan %p.\n", 439 "Sleeping for %llu ms before retrying requests on plan %p.\n",
436 (unsigned long long) 440 (unsigned long long) delay.rel_value, pp);
437 delay.rel_value, pp);
438#endif 441#endif
439 GNUNET_STATISTICS_set (GSF_stats, 442 GNUNET_STATISTICS_set (GSF_stats, gettext_noop ("# delay heap timeout"),
440 gettext_noop ("# delay heap timeout"), 443 delay.rel_value, GNUNET_NO);
441 delay.rel_value, 444
442 GNUNET_NO);
443
444 pp->task = 445 pp->task =
445 GNUNET_SCHEDULER_add_delayed (delay, 446 GNUNET_SCHEDULER_add_delayed (delay, &schedule_peer_transmission, pp);
446 &schedule_peer_transmission, pp);
447 return; 447 return;
448 } 448 }
449 GNUNET_STATISTICS_update (GSF_stats, 449 GNUNET_STATISTICS_update (GSF_stats, gettext_noop ("# query plans executed"),
450 gettext_noop ("# query plans executed"), 1, 450 1, GNUNET_NO);
451 GNUNET_NO);
452 /* process from priority heap */ 451 /* process from priority heap */
453 rp = GNUNET_CONTAINER_heap_peek (pp->priority_heap); 452 rp = GNUNET_CONTAINER_heap_peek (pp->priority_heap);
454#if DEBUG_FS > 1 453#if DEBUG_FS > 1
@@ -488,9 +487,7 @@ struct MergeContext
488 * GNUNET_NO if not (merge success) 487 * GNUNET_NO if not (merge success)
489 */ 488 */
490static int 489static int
491merge_pr (void *cls, 490merge_pr (void *cls, const GNUNET_HashCode * query, void *element)
492 const GNUNET_HashCode *query,
493 void *element)
494{ 491{
495 struct MergeContext *mpr = cls; 492 struct MergeContext *mpr = cls;
496 struct GSF_RequestPlan *rp = element; 493 struct GSF_RequestPlan *rp = element;
@@ -550,8 +547,7 @@ GSF_plan_add_ (struct GSF_ConnectedPeer *cp, struct GSF_PendingRequest *pr)
550 if (NULL == pp) 547 if (NULL == pp)
551 { 548 {
552 pp = GNUNET_malloc (sizeof (struct PeerPlan)); 549 pp = GNUNET_malloc (sizeof (struct PeerPlan));
553 pp->plan_map = 550 pp->plan_map = GNUNET_CONTAINER_multihashmap_create (128);
554 GNUNET_CONTAINER_multihashmap_create (128);
555 pp->priority_heap = 551 pp->priority_heap =
556 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX); 552 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX);
557 pp->delay_heap = 553 pp->delay_heap =
@@ -563,13 +559,13 @@ GSF_plan_add_ (struct GSF_ConnectedPeer *cp, struct GSF_PendingRequest *pr)
563 mpc.merged = GNUNET_NO; 559 mpc.merged = GNUNET_NO;
564 mpc.pr = pr; 560 mpc.pr = pr;
565 GNUNET_CONTAINER_multihashmap_get_multiple (pp->plan_map, 561 GNUNET_CONTAINER_multihashmap_get_multiple (pp->plan_map,
566 &GSF_pending_request_get_data_ (pr)->query, 562 &GSF_pending_request_get_data_
567 &merge_pr, &mpc); 563 (pr)->query, &merge_pr, &mpc);
568 if (mpc.merged != GNUNET_NO) 564 if (mpc.merged != GNUNET_NO)
569 return; 565 return;
570 GNUNET_CONTAINER_multihashmap_get_multiple (pp->plan_map, 566 GNUNET_CONTAINER_multihashmap_get_multiple (pp->plan_map,
571 &GSF_pending_request_get_data_ (pr)->query, 567 &GSF_pending_request_get_data_
572 &merge_pr, &mpc); 568 (pr)->query, &merge_pr, &mpc);
573 if (mpc.merged != GNUNET_NO) 569 if (mpc.merged != GNUNET_NO)
574 return; 570 return;
575 plan_count++; 571 plan_count++;
@@ -592,10 +588,9 @@ GSF_plan_add_ (struct GSF_ConnectedPeer *cp, struct GSF_PendingRequest *pr)
592 GNUNET_CONTAINER_DLL_insert (rp->prl_head, rp->prl_tail, prl); 588 GNUNET_CONTAINER_DLL_insert (rp->prl_head, rp->prl_tail, prl);
593 rp->pp = pp; 589 rp->pp = pp;
594 GNUNET_assert (GNUNET_YES == 590 GNUNET_assert (GNUNET_YES ==
595 GNUNET_CONTAINER_multihashmap_put (pp->plan_map, 591 GNUNET_CONTAINER_multihashmap_put (pp->plan_map,
596 get_rp_key (rp), 592 get_rp_key (rp), rp,
597 rp, 593 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
598 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
599 plan (pp, rp); 594 plan (pp, rp);
600} 595}
601 596
@@ -632,9 +627,8 @@ GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp)
632 while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root (pp->priority_heap))) 627 while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root (pp->priority_heap)))
633 { 628 {
634 GNUNET_break (GNUNET_YES == 629 GNUNET_break (GNUNET_YES ==
635 GNUNET_CONTAINER_multihashmap_remove (pp->plan_map, 630 GNUNET_CONTAINER_multihashmap_remove (pp->plan_map,
636 get_rp_key (rp), 631 get_rp_key (rp), rp));
637 rp));
638 while (NULL != (prl = rp->prl_head)) 632 while (NULL != (prl = rp->prl_head))
639 { 633 {
640 GNUNET_CONTAINER_DLL_remove (rp->prl_head, rp->prl_tail, prl); 634 GNUNET_CONTAINER_DLL_remove (rp->prl_head, rp->prl_tail, prl);
@@ -649,9 +643,8 @@ GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp)
649 while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root (pp->delay_heap))) 643 while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root (pp->delay_heap)))
650 { 644 {
651 GNUNET_break (GNUNET_YES == 645 GNUNET_break (GNUNET_YES ==
652 GNUNET_CONTAINER_multihashmap_remove (pp->plan_map, 646 GNUNET_CONTAINER_multihashmap_remove (pp->plan_map,
653 get_rp_key (rp), 647 get_rp_key (rp), rp));
654 rp));
655 while (NULL != (prl = rp->prl_head)) 648 while (NULL != (prl = rp->prl_head))
656 { 649 {
657 GNUNET_CONTAINER_DLL_remove (rp->prl_head, rp->prl_tail, prl); 650 GNUNET_CONTAINER_DLL_remove (rp->prl_head, rp->prl_tail, prl);
@@ -695,9 +688,10 @@ GSF_plan_notify_request_done_ (struct GSF_PendingRequest *pr)
695 GNUNET_CONTAINER_heap_remove_node (rp->hn); 688 GNUNET_CONTAINER_heap_remove_node (rp->hn);
696 plan_count--; 689 plan_count--;
697 GNUNET_break (GNUNET_YES == 690 GNUNET_break (GNUNET_YES ==
698 GNUNET_CONTAINER_multihashmap_remove (rp->pp->plan_map, 691 GNUNET_CONTAINER_multihashmap_remove (rp->pp->plan_map,
699 &GSF_pending_request_get_data_ (rpr->prl->pr)->query, 692 &GSF_pending_request_get_data_
700 rp)); 693 (rpr->prl->pr)->query,
694 rp));
701 GNUNET_free (rp); 695 GNUNET_free (rp);
702 } 696 }
703 GNUNET_free (rpr->prl); 697 GNUNET_free (rpr->prl);
diff --git a/src/fs/gnunet-service-fs_pr.c b/src/fs/gnunet-service-fs_pr.c
index 63ae3a75f..ac183a980 100644
--- a/src/fs/gnunet-service-fs_pr.c
+++ b/src/fs/gnunet-service-fs_pr.c
@@ -216,10 +216,10 @@ refresh_bloomfilter (struct GSF_PendingRequest *pr)
216 if (pr->bf != NULL) 216 if (pr->bf != NULL)
217 GNUNET_CONTAINER_bloomfilter_free (pr->bf); 217 GNUNET_CONTAINER_bloomfilter_free (pr->bf);
218 pr->mingle = 218 pr->mingle =
219 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); 219 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
220 pr->bf = GNUNET_BLOCK_construct_bloomfilter (pr->mingle, 220 pr->bf =
221 pr->replies_seen, 221 GNUNET_BLOCK_construct_bloomfilter (pr->mingle, pr->replies_seen,
222 pr->replies_seen_count); 222 pr->replies_seen_count);
223} 223}
224 224
225 225
@@ -319,7 +319,8 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
319 if (NULL != bf_data) 319 if (NULL != bf_data)
320 { 320 {
321 pr->bf = 321 pr->bf =
322 GNUNET_CONTAINER_bloomfilter_init (bf_data, bf_size, GNUNET_CONSTANTS_BLOOMFILTER_K); 322 GNUNET_CONTAINER_bloomfilter_init (bf_data, bf_size,
323 GNUNET_CONSTANTS_BLOOMFILTER_K);
323 pr->mingle = mingle; 324 pr->mingle = mingle;
324 } 325 }
325 else if ((replies_seen_count > 0) && 326 else if ((replies_seen_count > 0) &&
@@ -433,17 +434,16 @@ GSF_pending_request_update_ (struct GSF_PendingRequest *pr,
433 pr->mingle = 434 pr->mingle =
434 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); 435 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
435 pr->bf = 436 pr->bf =
436 GNUNET_BLOCK_construct_bloomfilter (pr->mingle, 437 GNUNET_BLOCK_construct_bloomfilter (pr->mingle, replies_seen,
437 replies_seen, 438 replies_seen_count);
438 replies_seen_count); 439 }
439 }
440 else 440 else
441 { 441 {
442 for (i = 0; i < pr->replies_seen_count; i++) 442 for (i = 0; i < pr->replies_seen_count; i++)
443 { 443 {
444 GNUNET_BLOCK_mingle_hash (&replies_seen[i], pr->mingle, &mhash); 444 GNUNET_BLOCK_mingle_hash (&replies_seen[i], pr->mingle, &mhash);
445 GNUNET_CONTAINER_bloomfilter_add (pr->bf, &mhash); 445 GNUNET_CONTAINER_bloomfilter_add (pr->bf, &mhash);
446 } 446 }
447 } 447 }
448 } 448 }
449} 449}
@@ -970,10 +970,10 @@ static void
970handle_dht_reply (void *cls, struct GNUNET_TIME_Absolute exp, 970handle_dht_reply (void *cls, struct GNUNET_TIME_Absolute exp,
971 const GNUNET_HashCode * key, 971 const GNUNET_HashCode * key,
972 const struct GNUNET_PeerIdentity *get_path, 972 const struct GNUNET_PeerIdentity *get_path,
973 unsigned int get_path_length, 973 unsigned int get_path_length,
974 const struct GNUNET_PeerIdentity *put_path, 974 const struct GNUNET_PeerIdentity *put_path,
975 unsigned int put_path_length, 975 unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
976 enum GNUNET_BLOCK_Type type, size_t size, const void *data) 976 size_t size, const void *data)
977{ 977{
978 struct GSF_PendingRequest *pr = cls; 978 struct GSF_PendingRequest *pr = cls;
979 struct ProcessReplyClosure prq; 979 struct ProcessReplyClosure prq;
@@ -1051,11 +1051,10 @@ GSF_dht_lookup_ (struct GSF_PendingRequest *pr)
1051 pr->gh = 1051 pr->gh =
1052 GNUNET_DHT_get_start (GSF_dht, GNUNET_TIME_UNIT_FOREVER_REL, 1052 GNUNET_DHT_get_start (GSF_dht, GNUNET_TIME_UNIT_FOREVER_REL,
1053 pr->public_data.type, &pr->public_data.query, 1053 pr->public_data.type, &pr->public_data.query,
1054 5 /* DEFAULT_GET_REPLICATION */, 1054 5 /* DEFAULT_GET_REPLICATION */ ,
1055 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 1055 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
1056 /* FIXME: can no longer pass pr->bf/pr->mingle... */ 1056 /* FIXME: can no longer pass pr->bf/pr->mingle... */
1057 xquery, xquery_size, &handle_dht_reply, 1057 xquery, xquery_size, &handle_dht_reply, pr);
1058 pr);
1059} 1058}
1060 1059
1061 1060
@@ -1231,16 +1230,17 @@ process_local_reply (void *cls, const GNUNET_HashCode * key, size_t size,
1231 /* queue priority */ , 1230 /* queue priority */ ,
1232 (0 != 1231 (0 !=
1233 (GSF_PRO_PRIORITY_UNLIMITED & 1232 (GSF_PRO_PRIORITY_UNLIMITED &
1234 pr->public_data.options)) ? UINT_MAX : datastore_queue_size 1233 pr->public_data.options)) ? UINT_MAX :
1234 datastore_queue_size
1235 /* max queue size */ , 1235 /* max queue size */ ,
1236 GNUNET_TIME_UNIT_FOREVER_REL, 1236 GNUNET_TIME_UNIT_FOREVER_REL,
1237 &process_local_reply, pr); 1237 &process_local_reply, pr);
1238 if (NULL != pr->qe) 1238 if (NULL != pr->qe)
1239 return; /* we're done */ 1239 return; /* we're done */
1240 GNUNET_STATISTICS_update (GSF_stats, 1240 GNUNET_STATISTICS_update (GSF_stats,
1241 gettext_noop 1241 gettext_noop
1242 ("# Datastore lookups concluded (error queueing)"), 1242 ("# Datastore lookups concluded (error queueing)"),
1243 1, GNUNET_NO); 1243 1, GNUNET_NO);
1244 goto check_error_and_continue; 1244 goto check_error_and_continue;
1245 } 1245 }
1246 old_rf = pr->public_data.results_found; 1246 old_rf = pr->public_data.results_found;
@@ -1270,7 +1270,8 @@ process_local_reply (void *cls, const GNUNET_HashCode * key, size_t size,
1270 /* queue priority */ , 1270 /* queue priority */ ,
1271 (0 != 1271 (0 !=
1272 (GSF_PRO_PRIORITY_UNLIMITED & 1272 (GSF_PRO_PRIORITY_UNLIMITED &
1273 pr->public_data.options)) ? UINT_MAX : datastore_queue_size 1273 pr->public_data.options)) ? UINT_MAX :
1274 datastore_queue_size
1274 /* max queue size */ , 1275 /* max queue size */ ,
1275 GNUNET_TIME_UNIT_FOREVER_REL, 1276 GNUNET_TIME_UNIT_FOREVER_REL,
1276 &process_local_reply, pr); 1277 &process_local_reply, pr);
@@ -1329,7 +1330,8 @@ process_local_reply (void *cls, const GNUNET_HashCode * key, size_t size,
1329 /* queue priority */ , 1330 /* queue priority */ ,
1330 (0 != 1331 (0 !=
1331 (GSF_PRO_PRIORITY_UNLIMITED & pr-> 1332 (GSF_PRO_PRIORITY_UNLIMITED & pr->
1332 public_data.options)) ? UINT_MAX : datastore_queue_size 1333 public_data.options)) ? UINT_MAX :
1334 datastore_queue_size
1333 /* max queue size */ , 1335 /* max queue size */ ,
1334 GNUNET_TIME_UNIT_FOREVER_REL, 1336 GNUNET_TIME_UNIT_FOREVER_REL,
1335 &process_local_reply, pr); 1337 &process_local_reply, pr);
@@ -1353,21 +1355,24 @@ check_error_and_continue:
1353 1355
1354/** 1356/**
1355 * Is the given target a legitimate peer for forwarding the given request? 1357 * Is the given target a legitimate peer for forwarding the given request?
1356 * 1358 *
1357 * @param pr request 1359 * @param pr request
1358 * @param target 1360 * @param target
1359 * @return GNUNET_YES if this request could be forwarded to the given peer 1361 * @return GNUNET_YES if this request could be forwarded to the given peer
1360 */ 1362 */
1361int 1363int
1362GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr, 1364GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr,
1363 const struct GNUNET_PeerIdentity *target) 1365 const struct GNUNET_PeerIdentity *target)
1364{ 1366{
1365 struct GNUNET_PeerIdentity pi; 1367 struct GNUNET_PeerIdentity pi;
1366 1368
1367 if (0 == pr->origin_pid) 1369 if (0 == pr->origin_pid)
1368 return GNUNET_YES; 1370 return GNUNET_YES;
1369 GNUNET_PEER_resolve (pr->origin_pid, &pi); 1371 GNUNET_PEER_resolve (pr->origin_pid, &pi);
1370 return (0 == memcmp (&pi, target, sizeof (struct GNUNET_PeerIdentity))) ? GNUNET_NO :GNUNET_YES; 1372 return (0 ==
1373 memcmp (&pi, target,
1374 sizeof (struct GNUNET_PeerIdentity))) ? GNUNET_NO :
1375 GNUNET_YES;
1371} 1376}
1372 1377
1373 1378
@@ -1405,16 +1410,17 @@ GSF_local_lookup_ (struct GSF_PendingRequest *pr,
1405 /* queue priority */ , 1410 /* queue priority */ ,
1406 (0 != 1411 (0 !=
1407 (GSF_PRO_PRIORITY_UNLIMITED & pr-> 1412 (GSF_PRO_PRIORITY_UNLIMITED & pr->
1408 public_data.options)) ? UINT_MAX : datastore_queue_size 1413 public_data.options)) ? UINT_MAX :
1414 datastore_queue_size
1409 /* max queue size */ , 1415 /* max queue size */ ,
1410 GNUNET_TIME_UNIT_FOREVER_REL, 1416 GNUNET_TIME_UNIT_FOREVER_REL,
1411 &process_local_reply, pr); 1417 &process_local_reply, pr);
1412 if (NULL != pr->qe) 1418 if (NULL != pr->qe)
1413 return; 1419 return;
1414 GNUNET_STATISTICS_update (GSF_stats, 1420 GNUNET_STATISTICS_update (GSF_stats,
1415 gettext_noop 1421 gettext_noop
1416 ("# Datastore lookups concluded (error queueing)"), 1422 ("# Datastore lookups concluded (error queueing)"),
1417 1, GNUNET_NO); 1423 1, GNUNET_NO);
1418 GNUNET_SCHEDULER_cancel (pr->warn_task); 1424 GNUNET_SCHEDULER_cancel (pr->warn_task);
1419 pr->warn_task = GNUNET_SCHEDULER_NO_TASK; 1425 pr->warn_task = GNUNET_SCHEDULER_NO_TASK;
1420 pr->llc_cont = NULL; 1426 pr->llc_cont = NULL;
@@ -1566,10 +1572,8 @@ GSF_pending_request_init_ ()
1566 "MAX_PENDING_REQUESTS"); 1572 "MAX_PENDING_REQUESTS");
1567 } 1573 }
1568 if (GNUNET_OK != 1574 if (GNUNET_OK !=
1569 GNUNET_CONFIGURATION_get_value_number (GSF_cfg, 1575 GNUNET_CONFIGURATION_get_value_number (GSF_cfg, "core", "TOTAL_QUOTA_OUT",
1570 "core", 1576 &bps))
1571 "TOTAL_QUOTA_OUT",
1572 &bps))
1573 { 1577 {
1574 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1578 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1575 _ 1579 _
@@ -1578,9 +1582,10 @@ GSF_pending_request_init_ ()
1578 bps = 65536; 1582 bps = 65536;
1579 } 1583 }
1580 /* queue size should be #queries we can have pending and satisfy within 1584 /* queue size should be #queries we can have pending and satisfy within
1581 a carry interval: */ 1585 * a carry interval: */
1582 datastore_queue_size = bps * GNUNET_CONSTANTS_MAX_BANDWIDTH_CARRY_S / DBLOCK_SIZE; 1586 datastore_queue_size =
1583 1587 bps * GNUNET_CONSTANTS_MAX_BANDWIDTH_CARRY_S / DBLOCK_SIZE;
1588
1584 active_to_migration = 1589 active_to_migration =
1585 GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, "FS", "CONTENT_CACHING"); 1590 GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, "FS", "CONTENT_CACHING");
1586 datastore_put_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE); 1591 datastore_put_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE);
diff --git a/src/fs/gnunet-service-fs_pr.h b/src/fs/gnunet-service-fs_pr.h
index 538a38248..00249afcf 100644
--- a/src/fs/gnunet-service-fs_pr.h
+++ b/src/fs/gnunet-service-fs_pr.h
@@ -359,14 +359,14 @@ GSF_local_lookup_ (struct GSF_PendingRequest *pr,
359 359
360/** 360/**
361 * Is the given target a legitimate peer for forwarding the given request? 361 * Is the given target a legitimate peer for forwarding the given request?
362 * 362 *
363 * @param pr request 363 * @param pr request
364 * @param target 364 * @param target
365 * @return GNUNET_YES if this request could be forwarded to the given peer 365 * @return GNUNET_YES if this request could be forwarded to the given peer
366 */ 366 */
367int 367int
368GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr, 368GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr,
369 const struct GNUNET_PeerIdentity *target); 369 const struct GNUNET_PeerIdentity *target);
370 370
371 371
372 372
diff --git a/src/fs/gnunet-service-fs_put.c b/src/fs/gnunet-service-fs_put.c
index c029b4141..07d32ef31 100644
--- a/src/fs/gnunet-service-fs_put.c
+++ b/src/fs/gnunet-service-fs_put.c
@@ -161,9 +161,9 @@ process_dht_put_content (void *cls, const GNUNET_HashCode * key, size_t size,
161 "Retrieved block `%s' of type %u for DHT PUT\n", GNUNET_h2s (key), 161 "Retrieved block `%s' of type %u for DHT PUT\n", GNUNET_h2s (key),
162 type); 162 type);
163#endif 163#endif
164 GNUNET_DHT_put (GSF_dht, key, 5 /* DEFAULT_PUT_REPLICATION */, 164 GNUNET_DHT_put (GSF_dht, key, 5 /* DEFAULT_PUT_REPLICATION */ ,
165 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 165 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, type, size, data,
166 type, size, data, expiration, GNUNET_TIME_UNIT_FOREVER_REL, 166 expiration, GNUNET_TIME_UNIT_FOREVER_REL,
167 &delay_dht_put_blocks, po); 167 &delay_dht_put_blocks, po);
168} 168}
169 169
diff --git a/src/hello/hello.c b/src/hello/hello.c
index c7db77a18..a0c26d1ab 100644
--- a/src/hello/hello.c
+++ b/src/hello/hello.c
@@ -632,8 +632,8 @@ GNUNET_HELLO_equals (const struct GNUNET_HELLO_Message *h1,
632 632
633static int 633static int
634find_min_expire (void *cls, const char *tname, 634find_min_expire (void *cls, const char *tname,
635 struct GNUNET_TIME_Absolute expiration, const void *addr, 635 struct GNUNET_TIME_Absolute expiration, const void *addr,
636 uint16_t addrlen) 636 uint16_t addrlen)
637{ 637{
638 struct GNUNET_TIME_Absolute *min = cls; 638 struct GNUNET_TIME_Absolute *min = cls;
639 639
diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c
index 2ef807444..b0fb03e29 100644
--- a/src/hostlist/gnunet-daemon-hostlist.c
+++ b/src/hostlist/gnunet-daemon-hostlist.c
@@ -143,7 +143,7 @@ static int
143advertisement_handler (void *cls, const struct GNUNET_PeerIdentity *peer, 143advertisement_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
144 const struct GNUNET_MessageHeader *message, 144 const struct GNUNET_MessageHeader *message,
145 const struct GNUNET_ATS_Information *atsi, 145 const struct GNUNET_ATS_Information *atsi,
146 unsigned int atsi_count) 146 unsigned int atsi_count)
147{ 147{
148 GNUNET_assert (NULL != client_adv_handler); 148 GNUNET_assert (NULL != client_adv_handler);
149 return (*client_adv_handler) (cls, peer, message, atsi, atsi_count); 149 return (*client_adv_handler) (cls, peer, message, atsi, atsi_count);
@@ -161,7 +161,7 @@ advertisement_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
161static void 161static void
162connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer, 162connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
163 const struct GNUNET_ATS_Information *atsi, 163 const struct GNUNET_ATS_Information *atsi,
164 unsigned int atsi_count) 164 unsigned int atsi_count)
165{ 165{
166 if (0 == memcmp (&me, peer, sizeof (struct GNUNET_PeerIdentity))) 166 if (0 == memcmp (&me, peer, sizeof (struct GNUNET_PeerIdentity)))
167 return; 167 return;
diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c
index ba5093779..350a0baee 100644
--- a/src/hostlist/hostlist-client.c
+++ b/src/hostlist/hostlist-client.c
@@ -1112,7 +1112,7 @@ task_hostlist_saving (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1112static void 1112static void
1113handler_connect (void *cls, const struct GNUNET_PeerIdentity *peer, 1113handler_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
1114 const struct GNUNET_ATS_Information *atsi, 1114 const struct GNUNET_ATS_Information *atsi,
1115 unsigned int atsi_count) 1115 unsigned int atsi_count)
1116{ 1116{
1117 GNUNET_assert (stat_connection_count < UINT_MAX); 1117 GNUNET_assert (stat_connection_count < UINT_MAX);
1118 stat_connection_count++; 1118 stat_connection_count++;
@@ -1152,7 +1152,7 @@ static int
1152handler_advertisement (void *cls, const struct GNUNET_PeerIdentity *peer, 1152handler_advertisement (void *cls, const struct GNUNET_PeerIdentity *peer,
1153 const struct GNUNET_MessageHeader *message, 1153 const struct GNUNET_MessageHeader *message,
1154 const struct GNUNET_ATS_Information *atsi, 1154 const struct GNUNET_ATS_Information *atsi,
1155 unsigned int atsi_count) 1155 unsigned int atsi_count)
1156{ 1156{
1157 size_t size; 1157 size_t size;
1158 size_t uri_size; 1158 size_t uri_size;
diff --git a/src/hostlist/hostlist-server.c b/src/hostlist/hostlist-server.c
index a6d9c126c..69d83b4d4 100644
--- a/src/hostlist/hostlist-server.c
+++ b/src/hostlist/hostlist-server.c
@@ -367,7 +367,7 @@ adv_transmit_ready (void *cls, size_t size, void *buf)
367static void 367static void
368connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer, 368connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
369 const struct GNUNET_ATS_Information *atsi, 369 const struct GNUNET_ATS_Information *atsi,
370 unsigned int atsi_count) 370 unsigned int atsi_count)
371{ 371{
372 size_t size; 372 size_t size;
373 373
diff --git a/src/hostlist/test_gnunet_daemon_hostlist.c b/src/hostlist/test_gnunet_daemon_hostlist.c
index bcb302978..cac2cc67a 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist.c
+++ b/src/hostlist/test_gnunet_daemon_hostlist.c
@@ -97,8 +97,7 @@ timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
97 */ 97 */
98static void 98static void
99notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, 99notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
100 const struct GNUNET_ATS_Information *ats, 100 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
101 uint32_t ats_count)
102{ 101{
103 if (peer == NULL) 102 if (peer == NULL)
104 return; 103 return;
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_learning.c b/src/hostlist/test_gnunet_daemon_hostlist_learning.c
index dfeca8d57..670fecc76 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist_learning.c
+++ b/src/hostlist/test_gnunet_daemon_hostlist_learning.c
@@ -299,7 +299,7 @@ static int
299ad_arrive_handler (void *cls, const struct GNUNET_PeerIdentity *peer, 299ad_arrive_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
300 const struct GNUNET_MessageHeader *message, 300 const struct GNUNET_MessageHeader *message,
301 const struct GNUNET_ATS_Information *atsi, 301 const struct GNUNET_ATS_Information *atsi,
302 unsigned int atsi_count) 302 unsigned int atsi_count)
303{ 303{
304 char *hostname; 304 char *hostname;
305 char *expected_uri; 305 char *expected_uri;
@@ -392,8 +392,8 @@ setup_learn_peer (struct PeerContext *p, const char *cfgname)
392 GNUNET_free (filename); 392 GNUNET_free (filename);
393 } 393 }
394 p->core = 394 p->core =
395 GNUNET_CORE_connect (p->cfg, 1, NULL, NULL, NULL, NULL, NULL, 395 GNUNET_CORE_connect (p->cfg, 1, NULL, NULL, NULL, NULL, NULL, GNUNET_NO,
396 GNUNET_NO, NULL, GNUNET_NO, learn_handlers); 396 NULL, GNUNET_NO, learn_handlers);
397 GNUNET_assert (NULL != p->core); 397 GNUNET_assert (NULL != p->core);
398 p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg); 398 p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg);
399 GNUNET_assert (NULL != p->stats); 399 GNUNET_assert (NULL != p->stats);
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
index 18757a79e..5dce8df10 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
+++ b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
@@ -108,8 +108,7 @@ timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
108 */ 108 */
109static void 109static void
110notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, 110notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
111 const struct GNUNET_ATS_Information *ats, 111 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
112 uint32_t ats_count)
113{ 112{
114 if (peer == NULL) 113 if (peer == NULL)
115 return; 114 return;
diff --git a/src/include/gnunet_ats_service.h b/src/include/gnunet_ats_service.h
index ed5631a33..ac963ce1d 100644
--- a/src/include/gnunet_ats_service.h
+++ b/src/include/gnunet_ats_service.h
@@ -49,14 +49,14 @@ enum GNUNET_ATS_Property
49 49
50 /** 50 /**
51 * Actual traffic on this connection from the other peer to this peer. 51 * Actual traffic on this connection from the other peer to this peer.
52 * 52 *
53 * Unit: [bytes/second] 53 * Unit: [bytes/second]
54 */ 54 */
55 GNUNET_ATS_UTILIZATION_UP, 55 GNUNET_ATS_UTILIZATION_UP,
56 56
57 /** 57 /**
58 * Actual traffic on this connection from this peer to the other peer. 58 * Actual traffic on this connection from this peer to the other peer.
59 * 59 *
60 * Unit: [bytes/second] 60 * Unit: [bytes/second]
61 */ 61 */
62 GNUNET_ATS_UTILIZATION_DOWN, 62 GNUNET_ATS_UTILIZATION_DOWN,
@@ -74,14 +74,14 @@ enum GNUNET_ATS_Property
74 * Dialup: 500 74 * Dialup: 500
75 */ 75 */
76 GNUNET_ATS_QUALITY_NET_DELAY, 76 GNUNET_ATS_QUALITY_NET_DELAY,
77 77
78 /** 78 /**
79 * Distance on network layer (required for distance-vector routing). 79 * Distance on network layer (required for distance-vector routing).
80 * 80 *
81 * Unit: [DV-hops] 81 * Unit: [DV-hops]
82 */ 82 */
83 GNUNET_ATS_QUALITY_NET_DISTANCE, 83 GNUNET_ATS_QUALITY_NET_DISTANCE,
84 84
85 /** 85 /**
86 * Network overhead on WAN (Wide-Area Network) 86 * Network overhead on WAN (Wide-Area Network)
87 * 87 *
@@ -102,7 +102,7 @@ enum GNUNET_ATS_Property
102 * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb] 102 * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
103 */ 103 */
104 GNUNET_ATS_COST_WAN, 104 GNUNET_ATS_COST_WAN,
105 105
106 /** 106 /**
107 * Network overhead on LAN (Local-Area Network) 107 * Network overhead on LAN (Local-Area Network)
108 * 108 *
@@ -123,7 +123,7 @@ enum GNUNET_ATS_Property
123 * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb] 123 * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
124 */ 124 */
125 GNUNET_ATS_COST_LAN, 125 GNUNET_ATS_COST_LAN,
126 126
127 /** 127 /**
128 * Network overhead on WLAN (Wireless Local Area Network) 128 * Network overhead on WLAN (Wireless Local Area Network)
129 * 129 *
@@ -144,12 +144,8 @@ enum GNUNET_ATS_Property
144 * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb] 144 * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
145 */ 145 */
146 GNUNET_ATS_COST_WLAN 146 GNUNET_ATS_COST_WLAN
147 147 /* Cost related values */
148 148 /* =================== */
149
150 /* Cost related values */
151 /* =================== */
152
153 /** 149 /**
154 * Volume based cost in financial units to transmit data 150 * Volume based cost in financial units to transmit data
155 * 151 *
@@ -166,8 +162,7 @@ enum GNUNET_ATS_Property
166 * LAN: 0 [cent/MB] 162 * LAN: 0 [cent/MB]
167 * 2G : 10 [cent/MB] 163 * 2G : 10 [cent/MB]
168 */ 164 */
169 // GNUNET_ATS_COST_FINANCIAL_PER_VOLUME = 1, 165 // GNUNET_ATS_COST_FINANCIAL_PER_VOLUME = 1,
170
171 /** 166 /**
172 * Time based cost in financial units to transmit data 167 * Time based cost in financial units to transmit data
173 * 168 *
@@ -184,8 +179,7 @@ enum GNUNET_ATS_Property
184 * LAN : 0 [cent/h] 179 * LAN : 0 [cent/h]
185 * Dialup: 10 [cent/h] 180 * Dialup: 10 [cent/h]
186 */ 181 */
187 // GNUNET_ATS_COST_FINANCIAL_PER_TIME = 2, 182 // GNUNET_ATS_COST_FINANCIAL_PER_TIME = 2,
188
189 /** 183 /**
190 * Computational costs 184 * Computational costs
191 * 185 *
@@ -204,8 +198,7 @@ enum GNUNET_ATS_Property
204 * HTTPS with AES CBC-128: 5,279 198 * HTTPS with AES CBC-128: 5,279
205 * HTTPS with RC4-1024: 2,652 199 * HTTPS with RC4-1024: 2,652
206 */ 200 */
207 // GNUNET_ATS_COST_COMPUTATIONAL = 3, 201 // GNUNET_ATS_COST_COMPUTATIONAL = 3,
208
209 /** 202 /**
210 * Energy consumption 203 * Energy consumption
211 * 204 *
@@ -233,8 +226,7 @@ enum GNUNET_ATS_Property
233 * WLAN: 89 (600 mW @ 802.11g /w 54 MBit/s) 226 * WLAN: 89 (600 mW @ 802.11g /w 54 MBit/s)
234 * Bluetooth: 267 (100 mW @ BT2.0 EDR /w 3 MBit/s) 227 * Bluetooth: 267 (100 mW @ BT2.0 EDR /w 3 MBit/s)
235 */ 228 */
236 // GNUNET_ATS_COST_ENERGY_CONSUMPTION = 4, 229 // GNUNET_ATS_COST_ENERGY_CONSUMPTION = 4,
237
238 /** 230 /**
239 * Connect cost 231 * Connect cost
240 * How many bytes are transmitted to initiate a new connection using 232 * How many bytes are transmitted to initiate a new connection using
@@ -256,8 +248,7 @@ enum GNUNET_ATS_Property
256 * 2129 bytes Ethernet, 1975 bytes TCP/IP, 1755 bytes TCP, 1403 bytes HTTPS 248 * 2129 bytes Ethernet, 1975 bytes TCP/IP, 1755 bytes TCP, 1403 bytes HTTPS
257 * 249 *
258 * */ 250 * */
259 // GNUNET_ATS_COST_CONNECT = 5, 251 // GNUNET_ATS_COST_CONNECT = 5,
260
261 /** 252 /**
262 * Bandwidth cost 253 * Bandwidth cost
263 * 254 *
@@ -274,8 +265,7 @@ enum GNUNET_ATS_Property
274 * Dial-up: 8 (64 Kbit/s) 265 * Dial-up: 8 (64 Kbit/s)
275 * 266 *
276 */ 267 */
277 // GNUNET_ATS_COST_BANDWITH_AVAILABLE = 6, 268 // GNUNET_ATS_COST_BANDWITH_AVAILABLE = 6,
278
279 /** 269 /**
280 * Network overhead 270 * Network overhead
281 * 271 *
@@ -295,35 +285,28 @@ enum GNUNET_ATS_Property
295 * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8 = 1090 [bytes/kb] 285 * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8 = 1090 [bytes/kb]
296 * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb] 286 * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
297 */ 287 */
298 // GNUNET_ATS_COST_NETWORK_OVERHEAD = 7, 288 // GNUNET_ATS_COST_NETWORK_OVERHEAD = 7,
299 289 /* Quality related values */
300 290 /* ====================== */
301 /* Quality related values */ 291 /* Physical layer quality properties */
302 /* ====================== */
303
304 /* Physical layer quality properties */
305
306 /** 292 /**
307 * Signal strength on physical layer 293 * Signal strength on physical layer
308 * 294 *
309 * Unit: [dBm] 295 * Unit: [dBm]
310 */ 296 */
311 // GNUNET_ATS_QUALITY_PHY_SIGNAL_STRENGTH = 1025, 297 // GNUNET_ATS_QUALITY_PHY_SIGNAL_STRENGTH = 1025,
312
313 /** 298 /**
314 * Collision rate on physical layer 299 * Collision rate on physical layer
315 * 300 *
316 * Unit: [B/s] 301 * Unit: [B/s]
317 */ 302 */
318 // GNUNET_ATS_QUALITY_PHY_COLLISION_RATE = 1026, 303 // GNUNET_ATS_QUALITY_PHY_COLLISION_RATE = 1026,
319
320 /** 304 /**
321 * Error rate on physical layer 305 * Error rate on physical layer
322 * 306 *
323 * Unit: [B/s] 307 * Unit: [B/s]
324 */ 308 */
325 // GNUNET_ATS_QUALITY_PHY_ERROR_RATE = 1027, 309 // GNUNET_ATS_QUALITY_PHY_ERROR_RATE = 1027,
326
327 /** 310 /**
328 * Jitter 311 * Jitter
329 * Time variations of the delay 312 * Time variations of the delay
@@ -331,8 +314,7 @@ enum GNUNET_ATS_Property
331 * 314 *
332 * Unit: [ms] 315 * Unit: [ms]
333 */ 316 */
334 // GNUNET_ATS_QUALITY_NET_JITTER = 1029, 317 // GNUNET_ATS_QUALITY_NET_JITTER = 1029,
335
336 /** 318 /**
337 * Error rate on network layer 319 * Error rate on network layer
338 * 320 *
@@ -346,8 +328,7 @@ enum GNUNET_ATS_Property
346 * Note: This numbers are just assumptions as an example, not 328 * Note: This numbers are just assumptions as an example, not
347 * measured or somehow determined 329 * measured or somehow determined
348 */ 330 */
349 // GNUNET_ATS_QUALITY_NET_ERRORRATE = 1030, 331 // GNUNET_ATS_QUALITY_NET_ERRORRATE = 1030,
350
351 /** 332 /**
352 * Drop rate on network layer 333 * Drop rate on network layer
353 * Bytes actively dismissed by a network component during transmission 334 * Bytes actively dismissed by a network component during transmission
@@ -363,8 +344,7 @@ enum GNUNET_ATS_Property
363 * Note: This numbers are just assumptions as an example, not 344 * Note: This numbers are just assumptions as an example, not
364 * measured or somehow determined 345 * measured or somehow determined
365 */ 346 */
366 // GNUNET_ATS_QUALITY_NET_DROPRATE = 1031, 347 // GNUNET_ATS_QUALITY_NET_DROPRATE = 1031,
367
368 /** 348 /**
369 * Loss rate on network layer 349 * Loss rate on network layer
370 * Bytes lost during transmission 350 * Bytes lost during transmission
@@ -380,8 +360,7 @@ enum GNUNET_ATS_Property
380 * Note: This numbers are just assumptions as an example, not measured 360 * Note: This numbers are just assumptions as an example, not measured
381 * or somehow determined 361 * or somehow determined
382 */ 362 */
383 // GNUNET_ATS_QUALITY_NET_LOSSRATE = 1032, 363 // GNUNET_ATS_QUALITY_NET_LOSSRATE = 1032,
384
385 /** 364 /**
386 * Throughput on network layer 365 * Throughput on network layer
387 * 366 *
@@ -394,21 +373,17 @@ enum GNUNET_ATS_Property
394 * Dialup: 4 373 * Dialup: 4
395 * 374 *
396 */ 375 */
397 // GNUNET_ATS_QUALITY_NET_THROUGHPUT = 1033, 376 // GNUNET_ATS_QUALITY_NET_THROUGHPUT = 1033,
398 377 /* Availability related values */
399 378 /* =========================== */
400 /* Availability related values */
401 /* =========================== */
402
403 /** 379 /**
404 * Is a peer reachable? 380 * Is a peer reachable?
405 */ 381 */
406 // GNUNET_ATS_AVAILABILITY_REACHABLE = 2048, 382 // GNUNET_ATS_AVAILABILITY_REACHABLE = 2048,
407
408 /** 383 /**
409 * Is there a connection established to a peer using this transport 384 * Is there a connection established to a peer using this transport
410 */ 385 */
411 // GNUNET_ATS_AVAILABILITY_CONNECTED = 2049 386 // GNUNET_ATS_AVAILABILITY_CONNECTED = 2049
412}; 387};
413 388
414 389
@@ -461,7 +436,7 @@ struct Session;
461 436
462/** 437/**
463 * Signature of a function called by ATS with the current bandwidth 438 * Signature of a function called by ATS with the current bandwidth
464 * and address preferences as determined by ATS. 439 * and address preferences as determined by ATS.
465 * 440 *
466 * @param cls closure 441 * @param cls closure
467 * @param peer identity of the new peer 442 * @param peer identity of the new peer
@@ -488,10 +463,9 @@ typedef void (*GNUNET_ATS_AddressSuggestionCallback) (void *cls,
488 struct 463 struct
489 GNUNET_BANDWIDTH_Value32NBO 464 GNUNET_BANDWIDTH_Value32NBO
490 bandwidth_in, 465 bandwidth_in,
491 const struct 466 const struct
492 GNUNET_ATS_Information 467 GNUNET_ATS_Information *
493 * ats, 468 ats, uint32_t ats_count);
494 uint32_t ats_count);
495 469
496 470
497/** 471/**
@@ -504,8 +478,8 @@ typedef void (*GNUNET_ATS_AddressSuggestionCallback) (void *cls,
504 */ 478 */
505struct GNUNET_ATS_SchedulingHandle * 479struct GNUNET_ATS_SchedulingHandle *
506GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg, 480GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
507 GNUNET_ATS_AddressSuggestionCallback suggest_cb, 481 GNUNET_ATS_AddressSuggestionCallback suggest_cb,
508 void *suggest_cb_cls); 482 void *suggest_cb_cls);
509 483
510 484
511/** 485/**
@@ -549,9 +523,8 @@ GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh,
549void 523void
550GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh, 524GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
551 const struct GNUNET_PeerIdentity *peer, 525 const struct GNUNET_PeerIdentity *peer,
552 const char *plugin_name, 526 const char *plugin_name, const void *plugin_addr,
553 const void *plugin_addr, size_t plugin_addr_len, 527 size_t plugin_addr_len, struct Session *session,
554 struct Session *session,
555 const struct GNUNET_ATS_Information *ats, 528 const struct GNUNET_ATS_Information *ats,
556 uint32_t ats_count); 529 uint32_t ats_count);
557 530
@@ -570,12 +543,10 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
570 */ 543 */
571void 544void
572GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh, 545GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
573 const struct GNUNET_PeerIdentity *peer, 546 const struct GNUNET_PeerIdentity *peer,
574 const char *plugin_name, 547 const char *plugin_name, const void *plugin_addr,
575 const void *plugin_addr, 548 size_t plugin_addr_len, struct Session *session,
576 size_t plugin_addr_len, 549 int in_use);
577 struct Session *session,
578 int in_use);
579 550
580/** 551/**
581 * A session got destroyed, stop including it as a valid address. 552 * A session got destroyed, stop including it as a valid address.
@@ -590,10 +561,8 @@ GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
590void 561void
591GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh, 562GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
592 const struct GNUNET_PeerIdentity *peer, 563 const struct GNUNET_PeerIdentity *peer,
593 const char *plugin_name, 564 const char *plugin_name, const void *plugin_addr,
594 const void *plugin_addr, 565 size_t plugin_addr_len, struct Session *session);
595 size_t plugin_addr_len,
596 struct Session *session);
597 566
598 567
599/* ******************************** Performance API ***************************** */ 568/* ******************************** Performance API ***************************** */
@@ -618,22 +587,20 @@ struct GNUNET_ATS_PerformanceHandle;
618 * @param ats_count number of performance records in 'ats' 587 * @param ats_count number of performance records in 'ats'
619 */ 588 */
620typedef void (*GNUNET_ATS_PeerInformationCallback) (void *cls, 589typedef void (*GNUNET_ATS_PeerInformationCallback) (void *cls,
621 const struct 590 const struct
622 GNUNET_PeerIdentity * 591 GNUNET_PeerIdentity * peer,
623 peer, 592 const char *plugin_name,
624 const char *plugin_name, 593 const void *plugin_addr,
625 const void *plugin_addr, 594 size_t plugin_addr_len,
626 size_t plugin_addr_len, 595 struct
627 struct 596 GNUNET_BANDWIDTH_Value32NBO
628 GNUNET_BANDWIDTH_Value32NBO 597 bandwidth_out,
629 bandwidth_out, 598 struct
630 struct 599 GNUNET_BANDWIDTH_Value32NBO
631 GNUNET_BANDWIDTH_Value32NBO 600 bandwidth_in,
632 bandwidth_in, 601 const struct
633 const struct 602 GNUNET_ATS_Information *
634 GNUNET_ATS_Information 603 ats, uint32_t ats_count);
635 * ats,
636 uint32_t ats_count);
637 604
638 605
639/** 606/**
@@ -646,8 +613,8 @@ typedef void (*GNUNET_ATS_PeerInformationCallback) (void *cls,
646 */ 613 */
647struct GNUNET_ATS_PerformanceHandle * 614struct GNUNET_ATS_PerformanceHandle *
648GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, 615GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
649 GNUNET_ATS_PeerInformationCallback infocb, 616 GNUNET_ATS_PeerInformationCallback infocb,
650 void *infocb_cls); 617 void *infocb_cls);
651 618
652 619
653/** 620/**
@@ -670,13 +637,10 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph);
670 * long should the client wait until re-trying? 637 * long should the client wait until re-trying?
671 */ 638 */
672typedef void (*GNUNET_ATS_ReservationCallback) (void *cls, 639typedef void (*GNUNET_ATS_ReservationCallback) (void *cls,
673 const struct 640 const struct GNUNET_PeerIdentity
674 GNUNET_PeerIdentity * 641 * peer, int32_t amount,
675 peer, 642 struct GNUNET_TIME_Relative
676 int32_t amount, 643 res_delay);
677 struct
678 GNUNET_TIME_Relative
679 res_delay);
680 644
681 645
682 646
@@ -702,10 +666,10 @@ struct GNUNET_ATS_ReservationContext;
702 */ 666 */
703struct GNUNET_ATS_ReservationContext * 667struct GNUNET_ATS_ReservationContext *
704GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph, 668GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
705 const struct GNUNET_PeerIdentity *peer, 669 const struct GNUNET_PeerIdentity *peer,
706 int32_t amount, 670 int32_t amount,
707 GNUNET_ATS_ReservationCallback rcb, 671 GNUNET_ATS_ReservationCallback rcb,
708 void *rcb_cls); 672 void *rcb_cls);
709 673
710 674
711/** 675/**
@@ -714,8 +678,7 @@ GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
714 * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call 678 * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call
715 */ 679 */
716void 680void
717GNUNET_ATS_reserve_bandwidth_cancel (struct 681GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc);
718 GNUNET_ATS_ReservationContext *rc);
719 682
720 683
721 684
@@ -734,7 +697,7 @@ enum GNUNET_ATS_PreferenceKind
734 * Change the peer's bandwidth value (value per byte of bandwidth in 697 * Change the peer's bandwidth value (value per byte of bandwidth in
735 * the goal function) to the given amount. The argument is followed 698 * the goal function) to the given amount. The argument is followed
736 * by a double value giving the desired value (can be negative). 699 * by a double value giving the desired value (can be negative).
737 * Preference changes are forgotten if peers disconnect. 700 * Preference changes are forgotten if peers disconnect.
738 */ 701 */
739 GNUNET_ATS_PREFERENCE_BANDWIDTH, 702 GNUNET_ATS_PREFERENCE_BANDWIDTH,
740 703
@@ -746,22 +709,20 @@ enum GNUNET_ATS_PreferenceKind
746 * the latency preferences. 709 * the latency preferences.
747 */ 710 */
748 GNUNET_ATS_PREFERENCE_LATENCY 711 GNUNET_ATS_PREFERENCE_LATENCY
749
750}; 712};
751 713
752 714
753/** 715/**
754 * Change preferences for the given peer. Preference changes are forgotten if peers 716 * Change preferences for the given peer. Preference changes are forgotten if peers
755 * disconnect. 717 * disconnect.
756 * 718 *
757 * @param ph performance handle 719 * @param ph performance handle
758 * @param peer identifies the peer 720 * @param peer identifies the peer
759 * @param ... 0-terminated specification of the desired changes 721 * @param ... 0-terminated specification of the desired changes
760 */ 722 */
761void 723void
762GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *ph, 724GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *ph,
763 const struct GNUNET_PeerIdentity *peer, 725 const struct GNUNET_PeerIdentity *peer, ...);
764 ...);
765 726
766 727
767 728
diff --git a/src/include/gnunet_block_lib.h b/src/include/gnunet_block_lib.h
index 8e7a59c8b..5e6eca76c 100644
--- a/src/include/gnunet_block_lib.h
+++ b/src/include/gnunet_block_lib.h
@@ -238,8 +238,8 @@ GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx,
238 */ 238 */
239struct GNUNET_CONTAINER_BloomFilter * 239struct GNUNET_CONTAINER_BloomFilter *
240GNUNET_BLOCK_construct_bloomfilter (int32_t bf_mutator, 240GNUNET_BLOCK_construct_bloomfilter (int32_t bf_mutator,
241 const GNUNET_HashCode *seen_results, 241 const GNUNET_HashCode * seen_results,
242 unsigned int seen_results_count); 242 unsigned int seen_results_count);
243 243
244 244
245#if 0 /* keep Emacsens' auto-indent happy */ 245#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index a46badc74..08c1f96c9 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -167,9 +167,11 @@ typedef void (*GNUNET_Logger) (void *cls, enum GNUNET_ErrorType kind,
167 * Number of log calls to ignore. 167 * Number of log calls to ignore.
168 */ 168 */
169extern unsigned int skip_log; 169extern unsigned int skip_log;
170
170#if !defined(GNUNET_CULL_LOGGING) 171#if !defined(GNUNET_CULL_LOGGING)
171int 172int
172GNUNET_get_log_call_status (int caller_level, const char *comp, const char *file, const char *function, int line); 173GNUNET_get_log_call_status (int caller_level, const char *comp,
174 const char *file, const char *function, int line);
173#endif 175#endif
174/** 176/**
175 * Main log function. 177 * Main log function.
@@ -214,7 +216,7 @@ GNUNET_log_nocheck (enum GNUNET_ErrorType kind, const char *message, ...);
214 */ 216 */
215void 217void
216GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, const char *comp, 218GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, const char *comp,
217 const char *message, ...); 219 const char *message, ...);
218 220
219#if !defined(GNUNET_CULL_LOGGING) 221#if !defined(GNUNET_CULL_LOGGING)
220#define GNUNET_log_from(kind,comp,...) do { int log_line = __LINE__;\ 222#define GNUNET_log_from(kind,comp,...) do { int log_line = __LINE__;\
diff --git a/src/include/gnunet_core_service.h b/src/include/gnunet_core_service.h
index 24c9aa598..1f6c0f329 100644
--- a/src/include/gnunet_core_service.h
+++ b/src/include/gnunet_core_service.h
@@ -63,9 +63,8 @@ typedef void (*GNUNET_CORE_ConnectEventHandler) (void *cls,
63 const struct 63 const struct
64 GNUNET_PeerIdentity * peer, 64 GNUNET_PeerIdentity * peer,
65 const struct 65 const struct
66 GNUNET_ATS_Information 66 GNUNET_ATS_Information * atsi,
67 * atsi, 67 unsigned int atsi_count);
68 unsigned int atsi_count);
69 68
70 69
71/** 70/**
@@ -97,10 +96,8 @@ typedef int (*GNUNET_CORE_MessageCallback) (void *cls,
97 other, 96 other,
98 const struct GNUNET_MessageHeader * 97 const struct GNUNET_MessageHeader *
99 message, 98 message,
100 const struct 99 const struct GNUNET_ATS_Information
101 GNUNET_ATS_Information * 100 * atsi, unsigned int atsi_count);
102 atsi,
103 unsigned int atsi_count);
104 101
105 102
106/** 103/**
@@ -142,7 +139,8 @@ struct GNUNET_CORE_MessageHandler
142 */ 139 */
143typedef void (*GNUNET_CORE_StartupCallback) (void *cls, 140typedef void (*GNUNET_CORE_StartupCallback) (void *cls,
144 struct GNUNET_CORE_Handle * server, 141 struct GNUNET_CORE_Handle * server,
145 const struct GNUNET_PeerIdentity *my_identity); 142 const struct GNUNET_PeerIdentity *
143 my_identity);
146 144
147 145
148/** 146/**
diff --git a/src/include/gnunet_dht_service.h b/src/include/gnunet_dht_service.h
index fcbc8df47..f047bd8f8 100644
--- a/src/include/gnunet_dht_service.h
+++ b/src/include/gnunet_dht_service.h
@@ -165,10 +165,10 @@ GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, const GNUNET_HashCode * key,
165typedef void (*GNUNET_DHT_GetIterator) (void *cls, 165typedef void (*GNUNET_DHT_GetIterator) (void *cls,
166 struct GNUNET_TIME_Absolute exp, 166 struct GNUNET_TIME_Absolute exp,
167 const GNUNET_HashCode * key, 167 const GNUNET_HashCode * key,
168 const struct GNUNET_PeerIdentity *get_path, 168 const struct GNUNET_PeerIdentity *
169 unsigned int get_path_length, 169 get_path, unsigned int get_path_length,
170 const struct GNUNET_PeerIdentity *put_path, 170 const struct GNUNET_PeerIdentity *
171 unsigned int put_path_length, 171 put_path, unsigned int put_path_length,
172 enum GNUNET_BLOCK_Type type, 172 enum GNUNET_BLOCK_Type type,
173 size_t size, const void *data); 173 size_t size, const void *data);
174 174
@@ -197,8 +197,7 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle,
197 struct GNUNET_TIME_Relative timeout, 197 struct GNUNET_TIME_Relative timeout,
198 enum GNUNET_BLOCK_Type type, const GNUNET_HashCode * key, 198 enum GNUNET_BLOCK_Type type, const GNUNET_HashCode * key,
199 uint32_t desired_replication_level, 199 uint32_t desired_replication_level,
200 enum GNUNET_DHT_RouteOption options, 200 enum GNUNET_DHT_RouteOption options, const void *xquery,
201 const void *xquery,
202 size_t xquery_size, GNUNET_DHT_GetIterator iter, 201 size_t xquery_size, GNUNET_DHT_GetIterator iter,
203 void *iter_cls); 202 void *iter_cls);
204 203
diff --git a/src/include/gnunet_mesh_service.h b/src/include/gnunet_mesh_service.h
index 0497cee2f..b9e95b46d 100644
--- a/src/include/gnunet_mesh_service.h
+++ b/src/include/gnunet_mesh_service.h
@@ -74,9 +74,8 @@ typedef int (*GNUNET_MESH_MessageCallback) (void *cls,
74 sender, 74 sender,
75 const struct GNUNET_MessageHeader * 75 const struct GNUNET_MessageHeader *
76 message, 76 message,
77 const struct 77 const struct GNUNET_ATS_Information
78 GNUNET_ATS_Information * 78 * atsi);
79 atsi);
80 79
81 80
82/** 81/**
@@ -208,8 +207,7 @@ typedef void (*GNUNET_MESH_PeerConnectHandler) (void *cls,
208 const struct GNUNET_PeerIdentity 207 const struct GNUNET_PeerIdentity
209 * peer, 208 * peer,
210 const struct 209 const struct
211 GNUNET_ATS_Information 210 GNUNET_ATS_Information * atsi);
212 * atsi);
213 211
214 212
215 213
diff --git a/src/include/gnunet_plugin_lib.h b/src/include/gnunet_plugin_lib.h
index ff795d975..387ca381c 100644
--- a/src/include/gnunet_plugin_lib.h
+++ b/src/include/gnunet_plugin_lib.h
@@ -89,9 +89,9 @@ GNUNET_PLUGIN_load (const char *library_name, void *arg);
89 * of the library (same as what 'GNUNET_PLUGIN_load' would 89 * of the library (same as what 'GNUNET_PLUGIN_load' would
90 * have returned for the given library name) 90 * have returned for the given library name)
91 */ 91 */
92typedef void (*GNUNET_PLUGIN_LoaderCallback)(void *cls, 92typedef void (*GNUNET_PLUGIN_LoaderCallback) (void *cls,
93 const char *library_name, 93 const char *library_name,
94 void *lib_ret); 94 void *lib_ret);
95 95
96 96
97/** 97/**
@@ -106,11 +106,9 @@ typedef void (*GNUNET_PLUGIN_LoaderCallback)(void *cls,
106 * @param cb function to call for each plugin found 106 * @param cb function to call for each plugin found
107 * @param cb_cls closure for 'cb' 107 * @param cb_cls closure for 'cb'
108 */ 108 */
109void 109void
110GNUNET_PLUGIN_load_all (const char *basename, 110GNUNET_PLUGIN_load_all (const char *basename, void *arg,
111 void *arg, 111 GNUNET_PLUGIN_LoaderCallback cb, void *cb_cls);
112 GNUNET_PLUGIN_LoaderCallback cb,
113 void *cb_cls);
114 112
115 113
116/** 114/**
diff --git a/src/include/gnunet_server_lib.h b/src/include/gnunet_server_lib.h
index 5289a6270..c39349c92 100644
--- a/src/include/gnunet_server_lib.h
+++ b/src/include/gnunet_server_lib.h
@@ -489,8 +489,7 @@ GNUNET_SERVER_transmit_context_run (struct GNUNET_SERVER_TransmitContext *tc,
489 */ 489 */
490void 490void
491GNUNET_SERVER_transmit_context_destroy (struct GNUNET_SERVER_TransmitContext 491GNUNET_SERVER_transmit_context_destroy (struct GNUNET_SERVER_TransmitContext
492 *tc, 492 *tc, int success);
493 int success);
494 493
495 494
496/** 495/**
diff --git a/src/include/gnunet_strings_lib.h b/src/include/gnunet_strings_lib.h
index 5a4996c3b..4efecc863 100644
--- a/src/include/gnunet_strings_lib.h
+++ b/src/include/gnunet_strings_lib.h
@@ -59,7 +59,7 @@ extern "C"
59 */ 59 */
60int 60int
61GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size, 61GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size,
62 unsigned long long *size); 62 unsigned long long *size);
63 63
64 64
65/** 65/**
@@ -72,7 +72,7 @@ GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size,
72 */ 72 */
73int 73int
74GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_size, 74GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_size,
75 struct GNUNET_TIME_Relative *rtime); 75 struct GNUNET_TIME_Relative *rtime);
76 76
77 77
78/** 78/**
diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h
index 2d6e515fa..de764e7a6 100644
--- a/src/include/gnunet_transport_service.h
+++ b/src/include/gnunet_transport_service.h
@@ -51,7 +51,7 @@ extern "C"
51 * @param peer (claimed) identity of the other peer 51 * @param peer (claimed) identity of the other peer
52 * @param message the message 52 * @param message the message
53 * @param ats performance data 53 * @param ats performance data
54 * @param ats_count number of entries in ats 54 * @param ats_count number of entries in ats
55 */ 55 */
56typedef void (*GNUNET_TRANSPORT_ReceiveCallback) (void *cls, 56typedef void (*GNUNET_TRANSPORT_ReceiveCallback) (void *cls,
57 const struct 57 const struct
@@ -60,8 +60,8 @@ typedef void (*GNUNET_TRANSPORT_ReceiveCallback) (void *cls,
60 GNUNET_MessageHeader * 60 GNUNET_MessageHeader *
61 message, 61 message,
62 const struct 62 const struct
63 GNUNET_ATS_Information 63 GNUNET_ATS_Information * ats,
64 * ats, uint32_t ats_count); 64 uint32_t ats_count);
65 65
66 66
67/** 67/**
@@ -83,8 +83,8 @@ typedef void (*GNUNET_TRANSPORT_NotifyConnect) (void *cls,
83 const struct GNUNET_PeerIdentity 83 const struct GNUNET_PeerIdentity
84 * peer, 84 * peer,
85 const struct 85 const struct
86 GNUNET_ATS_Information 86 GNUNET_ATS_Information * ats,
87 * ats, uint32_t ats_count); 87 uint32_t ats_count);
88 88
89/** 89/**
90 * Function called to notify transport users that another 90 * Function called to notify transport users that another
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index c0a7852e0..a5113e52b 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -342,7 +342,7 @@ struct MeshPathInfo
342 * Path itself 342 * Path itself
343 */ 343 */
344 struct MeshPeerPath *path; 344 struct MeshPeerPath *path;
345 345
346 /** 346 /**
347 * Position in peer's transmit queue 347 * Position in peer's transmit queue
348 */ 348 */
@@ -479,7 +479,7 @@ static struct GNUNET_PeerIdentity my_full_id;
479/** 479/**
480 * Own private key 480 * Own private key
481 */ 481 */
482static struct GNUNET_CRYPTO_RsaPrivateKey* my_private_key; 482static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key;
483 483
484/** 484/**
485 * Own public key. 485 * Own public key.
@@ -546,12 +546,9 @@ static int
546announce_application (void *cls, const GNUNET_HashCode * key, void *value) 546announce_application (void *cls, const GNUNET_HashCode * key, void *value)
547{ 547{
548 /* FIXME are hashes in multihash map equal on all aquitectures? */ 548 /* FIXME are hashes in multihash map equal on all aquitectures? */
549 GNUNET_DHT_put (dht_handle, 549 GNUNET_DHT_put (dht_handle, key, 10U,
550 key,
551 10U,
552 GNUNET_DHT_RO_RECORD_ROUTE | 550 GNUNET_DHT_RO_RECORD_ROUTE |
553 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 551 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, GNUNET_BLOCK_TYPE_TEST,
554 GNUNET_BLOCK_TYPE_TEST,
555 sizeof (struct GNUNET_PeerIdentity), 552 sizeof (struct GNUNET_PeerIdentity),
556 (const char *) &my_full_id, 553 (const char *) &my_full_id,
557#if MESH_DEBUG 554#if MESH_DEBUG
@@ -620,11 +617,10 @@ announce_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
620 GNUNET_DHT_put (dht_handle, /* DHT handle */ 617 GNUNET_DHT_put (dht_handle, /* DHT handle */
621 &my_full_id.hashPubKey, /* Key to use */ 618 &my_full_id.hashPubKey, /* Key to use */
622 10U, /* Replication level */ 619 10U, /* Replication level */
623 GNUNET_DHT_RO_RECORD_ROUTE | 620 GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */
624 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */
625 GNUNET_BLOCK_TYPE_TEST, /* Block type */ 621 GNUNET_BLOCK_TYPE_TEST, /* Block type */
626 sizeof(my_full_id), /* Size of the data */ 622 sizeof (my_full_id), /* Size of the data */
627 (char *)&my_full_id, /* Data itself */ 623 (char *) &my_full_id, /* Data itself */
628 GNUNET_TIME_absolute_get_forever (), /* Data expiration */ 624 GNUNET_TIME_absolute_get_forever (), /* Data expiration */
629 GNUNET_TIME_UNIT_FOREVER_REL, /* Retry time */ 625 GNUNET_TIME_UNIT_FOREVER_REL, /* Retry time */
630#if MESH_DEBUG_DHT 626#if MESH_DEBUG_DHT
@@ -656,8 +652,8 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
656 const struct GNUNET_PeerIdentity *get_path, 652 const struct GNUNET_PeerIdentity *get_path,
657 unsigned int get_path_length, 653 unsigned int get_path_length,
658 const struct GNUNET_PeerIdentity *put_path, 654 const struct GNUNET_PeerIdentity *put_path,
659 unsigned int put_path_length, 655 unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
660 enum GNUNET_BLOCK_Type type, size_t size, const void *data); 656 size_t size, const void *data);
661 657
662 658
663/******************************************************************************/ 659/******************************************************************************/
@@ -711,12 +707,12 @@ client_is_subscribed (uint16_t message_type, struct MeshClient *c)
711 * Allow a client to send more data after transmitting a multicast message 707 * Allow a client to send more data after transmitting a multicast message
712 * which some neighbor has not yet accepted altough a reasonable time has 708 * which some neighbor has not yet accepted altough a reasonable time has
713 * passed. 709 * passed.
714 * 710 *
715 * @param cls Closure (DataDescriptor containing the task identifier) 711 * @param cls Closure (DataDescriptor containing the task identifier)
716 * @param tc Task Context 712 * @param tc Task Context
717 */ 713 */
718static void 714static void
719client_allow_send(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 715client_allow_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
720{ 716{
721 struct MeshDataDescriptor *info = cls; 717 struct MeshDataDescriptor *info = cls;
722 718
@@ -728,7 +724,7 @@ client_allow_send(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
728 *(info->copies)); 724 *(info->copies));
729#endif 725#endif
730 *(info->timeout_task) = GNUNET_SCHEDULER_NO_TASK; 726 *(info->timeout_task) = GNUNET_SCHEDULER_NO_TASK;
731 GNUNET_SERVER_receive_done(info->client, GNUNET_OK); 727 GNUNET_SERVER_receive_done (info->client, GNUNET_OK);
732} 728}
733 729
734 730
@@ -756,8 +752,7 @@ tunnel_get (struct GNUNET_PeerIdentity *oid, MESH_TunnelNumber tid);
756 * 0 if the tunnel remained unaffected. 752 * 0 if the tunnel remained unaffected.
757 */ 753 */
758static GNUNET_PEER_Id 754static GNUNET_PEER_Id
759tunnel_notify_connection_broken (struct MeshTunnel *t, 755tunnel_notify_connection_broken (struct MeshTunnel *t, GNUNET_PEER_Id p1,
760 GNUNET_PEER_Id p1,
761 GNUNET_PEER_Id p2); 756 GNUNET_PEER_Id p2);
762 757
763 758
@@ -777,39 +772,39 @@ send_subscribed_clients (const struct GNUNET_MessageHeader *msg,
777 MESH_TunnelNumber *tid; 772 MESH_TunnelNumber *tid;
778 unsigned int count; 773 unsigned int count;
779 uint16_t type; 774 uint16_t type;
780 char cbuf[htons(msg->size)]; 775 char cbuf[htons (msg->size)];
781 776
782 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Sending to clients...\n"); 777 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Sending to clients...\n");
783 type = ntohs (payload->type); 778 type = ntohs (payload->type);
784 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: message of type %u\n", type); 779 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: message of type %u\n", type);
785 780
786 memcpy (cbuf, msg, sizeof(cbuf)); 781 memcpy (cbuf, msg, sizeof (cbuf));
787 switch (htons(msg->type)) 782 switch (htons (msg->type))
788 { 783 {
789 struct GNUNET_MESH_Unicast *uc; 784 struct GNUNET_MESH_Unicast *uc;
790 struct GNUNET_MESH_Multicast *mc; 785 struct GNUNET_MESH_Multicast *mc;
791 struct GNUNET_MESH_ToOrigin *to; 786 struct GNUNET_MESH_ToOrigin *to;
792 787
793 case GNUNET_MESSAGE_TYPE_MESH_UNICAST: 788 case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
794 uc = (struct GNUNET_MESH_Unicast *) cbuf; 789 uc = (struct GNUNET_MESH_Unicast *) cbuf;
795 tid = &uc->tid; 790 tid = &uc->tid;
796 oid = &uc->oid; 791 oid = &uc->oid;
797 break; 792 break;
798 case GNUNET_MESSAGE_TYPE_MESH_MULTICAST: 793 case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
799 mc = (struct GNUNET_MESH_Multicast *) cbuf; 794 mc = (struct GNUNET_MESH_Multicast *) cbuf;
800 tid = &mc->tid; 795 tid = &mc->tid;
801 oid = &mc->oid; 796 oid = &mc->oid;
802 break; 797 break;
803 case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: 798 case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
804 to = (struct GNUNET_MESH_ToOrigin *) cbuf; 799 to = (struct GNUNET_MESH_ToOrigin *) cbuf;
805 tid = &to->tid; 800 tid = &to->tid;
806 oid = &to->oid; 801 oid = &to->oid;
807 break; 802 break;
808 default: 803 default:
809 GNUNET_break (0); 804 GNUNET_break (0);
810 return 0; 805 return 0;
811 } 806 }
812 t = tunnel_get (oid, ntohl(*tid)); 807 t = tunnel_get (oid, ntohl (*tid));
813 if (NULL == t) 808 if (NULL == t)
814 { 809 {
815 GNUNET_break (0); 810 GNUNET_break (0);
@@ -823,11 +818,9 @@ send_subscribed_clients (const struct GNUNET_MessageHeader *msg,
823 { 818 {
824 count++; 819 count++;
825 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: sending\n"); 820 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: sending\n");
826 GNUNET_SERVER_notification_context_unicast ( 821 GNUNET_SERVER_notification_context_unicast (nc, c->handle,
827 nc, 822 (struct GNUNET_MessageHeader
828 c->handle, 823 *) cbuf, GNUNET_YES);
829 (struct GNUNET_MessageHeader *) cbuf,
830 GNUNET_YES);
831 } 824 }
832 } 825 }
833 return count; 826 return count;
@@ -837,7 +830,7 @@ send_subscribed_clients (const struct GNUNET_MessageHeader *msg,
837/** 830/**
838 * Notify the client that owns the tunnel that a peer has connected to it 831 * Notify the client that owns the tunnel that a peer has connected to it
839 * (the requested path to it has been confirmed). 832 * (the requested path to it has been confirmed).
840 * 833 *
841 * @param t Tunnel whose owner to notify 834 * @param t Tunnel whose owner to notify
842 * @param id Short id of the peer that has connected 835 * @param id Short id of the peer that has connected
843 */ 836 */
@@ -850,26 +843,26 @@ send_client_peer_connected (const struct MeshTunnel *t, const GNUNET_PEER_Id id)
850 pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); 843 pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
851 pc.tunnel_id = htonl (t->local_tid); 844 pc.tunnel_id = htonl (t->local_tid);
852 GNUNET_PEER_resolve (id, &pc.peer); 845 GNUNET_PEER_resolve (id, &pc.peer);
853 GNUNET_SERVER_notification_context_unicast (nc, t->client->handle, 846 GNUNET_SERVER_notification_context_unicast (nc, t->client->handle, &pc.header,
854 &pc.header, GNUNET_NO); 847 GNUNET_NO);
855} 848}
856 849
857 850
858/** 851/**
859 * Notify all clients (not depending on registration status) that the incoming 852 * Notify all clients (not depending on registration status) that the incoming
860 * tunnel is no longer valid. 853 * tunnel is no longer valid.
861 * 854 *
862 * @param t Tunnel that was destroyed. 855 * @param t Tunnel that was destroyed.
863 */ 856 */
864static void 857static void
865send_clients_tunnel_destroy (struct MeshTunnel *t) 858send_clients_tunnel_destroy (struct MeshTunnel *t)
866{ 859{
867 struct GNUNET_MESH_TunnelMessage msg; 860 struct GNUNET_MESH_TunnelMessage msg;
868 861
869 msg.header.size = htons (sizeof (msg)); 862 msg.header.size = htons (sizeof (msg));
870 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); 863 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY);
871 msg.tunnel_id = htonl (t->local_tid); 864 msg.tunnel_id = htonl (t->local_tid);
872 GNUNET_SERVER_notification_context_broadcast(nc, &msg.header, GNUNET_NO); 865 GNUNET_SERVER_notification_context_broadcast (nc, &msg.header, GNUNET_NO);
873} 866}
874 867
875 868
@@ -906,7 +899,7 @@ send_core_data_multicast (void *cls, size_t size, void *buf);
906 899
907/** 900/**
908 * Decrements the reference counter and frees all resources if needed 901 * Decrements the reference counter and frees all resources if needed
909 * 902 *
910 * @param dd Data Descriptor used in a multicast message 903 * @param dd Data Descriptor used in a multicast message
911 */ 904 */
912static void 905static void
@@ -922,7 +915,7 @@ data_descriptor_decrement_multicast (struct MeshDataDescriptor *dd)
922 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 915 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
923 "MESH: cancelling client timeout (%u)...\n", 916 "MESH: cancelling client timeout (%u)...\n",
924 *(dd->timeout_task)); 917 *(dd->timeout_task));
925 GNUNET_SCHEDULER_cancel(*(dd->timeout_task)); 918 GNUNET_SCHEDULER_cancel (*(dd->timeout_task));
926 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: notifying client...\n"); 919 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: notifying client...\n");
927 GNUNET_SERVER_receive_done (dd->client, GNUNET_OK); 920 GNUNET_SERVER_receive_done (dd->client, GNUNET_OK);
928 } 921 }
@@ -937,12 +930,12 @@ data_descriptor_decrement_multicast (struct MeshDataDescriptor *dd)
937/** 930/**
938 * Cancel a core transmission that was already requested and free all resources 931 * Cancel a core transmission that was already requested and free all resources
939 * associated to the request. 932 * associated to the request.
940 * 933 *
941 * @param peer PeeInfo of the peer whose transmission is cancelled. 934 * @param peer PeeInfo of the peer whose transmission is cancelled.
942 * @param i Position of the transmission to be cancelled. 935 * @param i Position of the transmission to be cancelled.
943 */ 936 */
944static void 937static void
945peer_info_cancel_transmission(struct MeshPeerInfo *peer, unsigned int i) 938peer_info_cancel_transmission (struct MeshPeerInfo *peer, unsigned int i)
946{ 939{
947 if (NULL != peer->core_transmit[i]) 940 if (NULL != peer->core_transmit[i])
948 { 941 {
@@ -956,36 +949,34 @@ peer_info_cancel_transmission(struct MeshPeerInfo *peer, unsigned int i)
956 GNUNET_PEER_resolve (peer->id, &id); 949 GNUNET_PEER_resolve (peer->id, &id);
957 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 950 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
958 "MESH: Cancelling data transmission at %s [%u]\n", 951 "MESH: Cancelling data transmission at %s [%u]\n",
959 GNUNET_i2s (&id), 952 GNUNET_i2s (&id), i);
960 i); 953 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: message type %u\n",
961 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
962 "MESH: message type %u\n",
963 peer->types[i]); 954 peer->types[i]);
964 } 955 }
965#endif 956#endif
966 /* TODO: notify that tranmission has failed */ 957 /* TODO: notify that tranmission has failed */
967 switch (peer->types[i]) 958 switch (peer->types[i])
968 { 959 {
969 case GNUNET_MESSAGE_TYPE_MESH_MULTICAST: 960 case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
970 case GNUNET_MESSAGE_TYPE_MESH_UNICAST: 961 case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
971 case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: 962 case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
972 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type payload\n"); 963 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type payload\n");
973 dd = peer->infos[i]; 964 dd = peer->infos[i];
974 data_descriptor_decrement_multicast (dd); 965 data_descriptor_decrement_multicast (dd);
975 break; 966 break;
976 case GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE: 967 case GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE:
977 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type create path\n"); 968 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type create path\n");
978 path_info = peer->infos[i]; 969 path_info = peer->infos[i];
979 path_destroy(path_info->path); 970 path_destroy (path_info->path);
980 break; 971 break;
981 default: 972 default:
982 GNUNET_break (0); 973 GNUNET_break (0);
983 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type unknown!\n"); 974 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type unknown!\n");
984 } 975 }
985 GNUNET_CORE_notify_transmit_ready_cancel (peer->core_transmit[i]); 976 GNUNET_CORE_notify_transmit_ready_cancel (peer->core_transmit[i]);
986 peer->core_transmit[i] = NULL; 977 peer->core_transmit[i] = NULL;
987 GNUNET_free (peer->infos[i]); 978 GNUNET_free (peer->infos[i]);
988 } 979 }
989} 980}
990 981
991 982
@@ -1008,7 +999,7 @@ peer_info_transmit_slot (struct MeshPeerInfo *peer)
1008 { 999 {
1009 /* All positions are taken! Overwriting! */ 1000 /* All positions are taken! Overwriting! */
1010 GNUNET_break (0); 1001 GNUNET_break (0);
1011 peer_info_cancel_transmission(peer, 0); 1002 peer_info_cancel_transmission (peer, 0);
1012 return 0; 1003 return 0;
1013 } 1004 }
1014 } 1005 }
@@ -1056,8 +1047,8 @@ peer_info_get_short (const GNUNET_PEER_Id peer)
1056{ 1047{
1057 struct GNUNET_PeerIdentity id; 1048 struct GNUNET_PeerIdentity id;
1058 1049
1059 GNUNET_PEER_resolve(peer, &id); 1050 GNUNET_PEER_resolve (peer, &id);
1060 return peer_info_get(&id); 1051 return peer_info_get (&id);
1061} 1052}
1062 1053
1063 1054
@@ -1072,7 +1063,7 @@ peer_info_get_short (const GNUNET_PEER_Id peer)
1072 * @return always GNUNET_YES, to keep iterating 1063 * @return always GNUNET_YES, to keep iterating
1073 */ 1064 */
1074static int 1065static int
1075peer_info_delete_tunnel (void* cls, const GNUNET_HashCode* key, void* value) 1066peer_info_delete_tunnel (void *cls, const GNUNET_HashCode * key, void *value)
1076{ 1067{
1077 struct MeshTunnel *t = cls; 1068 struct MeshTunnel *t = cls;
1078 struct MeshPeerInfo *peer = value; 1069 struct MeshPeerInfo *peer = value;
@@ -1080,9 +1071,8 @@ peer_info_delete_tunnel (void* cls, const GNUNET_HashCode* key, void* value)
1080 1071
1081 for (i = 0; i < peer->ntunnels; i++) 1072 for (i = 0; i < peer->ntunnels; i++)
1082 { 1073 {
1083 if (0 == memcmp(&peer->tunnels[i]->id, 1074 if (0 ==
1084 &t->id, 1075 memcmp (&peer->tunnels[i]->id, &t->id, sizeof (struct MESH_TunnelID)))
1085 sizeof(struct MESH_TunnelID)))
1086 { 1076 {
1087 peer->ntunnels--; 1077 peer->ntunnels--;
1088 peer->tunnels[i] = peer->tunnels[peer->ntunnels]; 1078 peer->tunnels[i] = peer->tunnels[peer->ntunnels];
@@ -1095,12 +1085,12 @@ peer_info_delete_tunnel (void* cls, const GNUNET_HashCode* key, void* value)
1095 1085
1096 1086
1097/** 1087/**
1098 * Core callback to write a 1088 * Core callback to write a
1099 * 1089 *
1100 * @param cls Closure (MeshDataDescriptor with data in "data" member). 1090 * @param cls Closure (MeshDataDescriptor with data in "data" member).
1101 * @param size Number of bytes available in buf. 1091 * @param size Number of bytes available in buf.
1102 * @param buf Where the to write the message. 1092 * @param buf Where the to write the message.
1103 * 1093 *
1104 * @return number of bytes written to buf 1094 * @return number of bytes written to buf
1105 */ 1095 */
1106static size_t 1096static size_t
@@ -1121,15 +1111,10 @@ send_core_data_raw (void *cls, size_t size, void *buf)
1121 1111
1122 GNUNET_PEER_resolve (info->peer->id, &id); 1112 GNUNET_PEER_resolve (info->peer->id, &id);
1123 info->peer->core_transmit[info->handler_n] = 1113 info->peer->core_transmit[info->handler_n] =
1124 GNUNET_CORE_notify_transmit_ready(core_handle, 1114 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 100,
1125 0, 1115 GNUNET_TIME_UNIT_FOREVER_REL, &id,
1126 100, 1116 size, &send_core_data_raw, info);
1127 GNUNET_TIME_UNIT_FOREVER_REL, 1117 return 0;
1128 &id,
1129 size,
1130 &send_core_data_raw,
1131 info);
1132 return 0;
1133 } 1118 }
1134 info->peer->core_transmit[info->handler_n] = NULL; 1119 info->peer->core_transmit[info->handler_n] = NULL;
1135 memcpy (buf, msg, total_size); 1120 memcpy (buf, msg, total_size);
@@ -1181,14 +1166,9 @@ send_message (const struct GNUNET_MessageHeader *message,
1181 neighbor->types[i] = GNUNET_MESSAGE_TYPE_MESH_UNICAST; 1166 neighbor->types[i] = GNUNET_MESSAGE_TYPE_MESH_UNICAST;
1182 neighbor->infos[i] = info; 1167 neighbor->infos[i] = info;
1183 neighbor->core_transmit[i] = 1168 neighbor->core_transmit[i] =
1184 GNUNET_CORE_notify_transmit_ready(core_handle, 1169 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 100,
1185 0, 1170 GNUNET_TIME_UNIT_FOREVER_REL, peer,
1186 100, 1171 size, &send_core_data_raw, info);
1187 GNUNET_TIME_UNIT_FOREVER_REL,
1188 peer,
1189 size,
1190 &send_core_data_raw,
1191 info);
1192 1172
1193} 1173}
1194 1174
@@ -1196,14 +1176,13 @@ send_message (const struct GNUNET_MessageHeader *message,
1196/** 1176/**
1197 * Sends a CREATE PATH message for a path to a peer, properly registrating 1177 * Sends a CREATE PATH message for a path to a peer, properly registrating
1198 * all used resources. 1178 * all used resources.
1199 * 1179 *
1200 * @param peer PeerInfo of the final peer for whom this path is being created. 1180 * @param peer PeerInfo of the final peer for whom this path is being created.
1201 * @param p Path itself. 1181 * @param p Path itself.
1202 * @param t Tunnel for which the path is created. 1182 * @param t Tunnel for which the path is created.
1203 */ 1183 */
1204static void 1184static void
1205send_create_path (struct MeshPeerInfo *peer, 1185send_create_path (struct MeshPeerInfo *peer, struct MeshPeerPath *p,
1206 struct MeshPeerPath *p,
1207 struct MeshTunnel *t) 1186 struct MeshTunnel *t)
1208{ 1187{
1209 struct GNUNET_PeerIdentity id; 1188 struct GNUNET_PeerIdentity id;
@@ -1213,7 +1192,7 @@ send_create_path (struct MeshPeerInfo *peer,
1213 1192
1214 if (NULL == p) 1193 if (NULL == p)
1215 { 1194 {
1216 p = tree_get_path_to_peer(t->tree, peer->id); 1195 p = tree_get_path_to_peer (t->tree, peer->id);
1217 if (NULL == p) 1196 if (NULL == p)
1218 { 1197 {
1219 GNUNET_break (0); 1198 GNUNET_break (0);
@@ -1227,37 +1206,34 @@ send_create_path (struct MeshPeerInfo *peer,
1227 } 1206 }
1228 if (i >= p->length - 1) 1207 if (i >= p->length - 1)
1229 { 1208 {
1230 path_destroy(p); 1209 path_destroy (p);
1231 GNUNET_break (0); 1210 GNUNET_break (0);
1232 return; 1211 return;
1233 } 1212 }
1234 GNUNET_PEER_resolve(p->peers[i + 1], &id); 1213 GNUNET_PEER_resolve (p->peers[i + 1], &id);
1235 1214
1236 path_info = GNUNET_malloc (sizeof (struct MeshPathInfo)); 1215 path_info = GNUNET_malloc (sizeof (struct MeshPathInfo));
1237 path_info->path = p; 1216 path_info->path = p;
1238 path_info->t = t; 1217 path_info->t = t;
1239 neighbor = peer_info_get(&id); 1218 neighbor = peer_info_get (&id);
1240 path_info->peer = neighbor; 1219 path_info->peer = neighbor;
1241 path_info->pos = peer_info_transmit_slot(neighbor); 1220 path_info->pos = peer_info_transmit_slot (neighbor);
1242 neighbor->types[path_info->pos] = GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE; 1221 neighbor->types[path_info->pos] = GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE;
1243 neighbor->infos[path_info->pos] = path_info; 1222 neighbor->infos[path_info->pos] = path_info;
1244 neighbor->core_transmit[path_info->pos] = 1223 neighbor->core_transmit[path_info->pos] = GNUNET_CORE_notify_transmit_ready (core_handle, /* handle */
1245 GNUNET_CORE_notify_transmit_ready ( 1224 0, /* cork */
1246 core_handle, /* handle */ 1225 0, /* priority */
1247 0, /* cork */ 1226 GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
1248 0, /* priority */ 1227 &id, /* target */
1249 GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ 1228 sizeof (struct GNUNET_MESH_ManipulatePath) + (p->length * sizeof (struct GNUNET_PeerIdentity)), /*size */
1250 &id, /* target */ 1229 &send_core_create_path, /* callback */
1251 sizeof (struct GNUNET_MESH_ManipulatePath) 1230 path_info); /* cls */
1252 + (p->length * sizeof (struct GNUNET_PeerIdentity)), /*size */
1253 &send_core_create_path, /* callback */
1254 path_info); /* cls */
1255} 1231}
1256 1232
1257 1233
1258/** 1234/**
1259 * Sends a DESTROY PATH message to free resources for a path in a tunnel 1235 * Sends a DESTROY PATH message to free resources for a path in a tunnel
1260 * 1236 *
1261 * @param t Tunnel whose path to destroy. 1237 * @param t Tunnel whose path to destroy.
1262 * @param destination Short ID of the peer to whom the path to destroy. 1238 * @param destination Short ID of the peer to whom the path to destroy.
1263 */ 1239 */
@@ -1267,7 +1243,7 @@ send_destroy_path (struct MeshTunnel *t, GNUNET_PEER_Id destination)
1267 struct MeshPeerPath *p; 1243 struct MeshPeerPath *p;
1268 size_t size; 1244 size_t size;
1269 1245
1270 p = tree_get_path_to_peer(t->tree, destination); 1246 p = tree_get_path_to_peer (t->tree, destination);
1271 if (NULL == p) 1247 if (NULL == p)
1272 { 1248 {
1273 GNUNET_break (0); 1249 GNUNET_break (0);
@@ -1288,9 +1264,9 @@ send_destroy_path (struct MeshTunnel *t, GNUNET_PEER_Id destination)
1288 pi = (struct GNUNET_PeerIdentity *) &msg[1]; 1264 pi = (struct GNUNET_PeerIdentity *) &msg[1];
1289 for (i = 0; i < p->length; i++) 1265 for (i = 0; i < p->length; i++)
1290 { 1266 {
1291 GNUNET_PEER_resolve(p->peers[i], &pi[i]); 1267 GNUNET_PEER_resolve (p->peers[i], &pi[i]);
1292 } 1268 }
1293 send_message (&msg->header, path_get_first_hop(t->tree, destination)); 1269 send_message (&msg->header, path_get_first_hop (t->tree, destination));
1294 } 1270 }
1295 path_destroy (p); 1271 path_destroy (p);
1296} 1272}
@@ -1299,7 +1275,7 @@ send_destroy_path (struct MeshTunnel *t, GNUNET_PEER_Id destination)
1299/** 1275/**
1300 * Try to establish a new connection to this peer. 1276 * Try to establish a new connection to this peer.
1301 * Use the best path for the given tunnel. 1277 * Use the best path for the given tunnel.
1302 * If the peer doesn't have any path to it yet, try to get one. 1278 * If the peer doesn't have any path to it yet, try to get one.
1303 * If the peer already has some path, send a CREATE PATH towards it. 1279 * If the peer already has some path, send a CREATE PATH towards it.
1304 * 1280 *
1305 * @param peer PeerInfo of the peer. 1281 * @param peer PeerInfo of the peer.
@@ -1313,7 +1289,7 @@ peer_info_connect (struct MeshPeerInfo *peer, struct MeshTunnel *t)
1313 1289
1314 if (NULL != peer->path_head) 1290 if (NULL != peer->path_head)
1315 { 1291 {
1316 p = tree_get_path_to_peer(t->tree, peer->id); 1292 p = tree_get_path_to_peer (t->tree, peer->id);
1317 if (NULL == p) 1293 if (NULL == p)
1318 { 1294 {
1319 GNUNET_break (0); 1295 GNUNET_break (0);
@@ -1322,38 +1298,33 @@ peer_info_connect (struct MeshPeerInfo *peer, struct MeshTunnel *t)
1322 1298
1323 if (p->length > 1) 1299 if (p->length > 1)
1324 { 1300 {
1325 send_create_path(peer, p, t); 1301 send_create_path (peer, p, t);
1326 } 1302 }
1327 else 1303 else
1328 { 1304 {
1329 path_destroy(p); 1305 path_destroy (p);
1330 send_client_peer_connected(t, myid); 1306 send_client_peer_connected (t, myid);
1331 } 1307 }
1332 } 1308 }
1333 else if (NULL == peer->dhtget) 1309 else if (NULL == peer->dhtget)
1334 { 1310 {
1335 struct GNUNET_PeerIdentity id; 1311 struct GNUNET_PeerIdentity id;
1336 1312
1337 GNUNET_PEER_resolve(peer->id, &id); 1313 GNUNET_PEER_resolve (peer->id, &id);
1338 path_info = GNUNET_malloc(sizeof(struct MeshPathInfo)); 1314 path_info = GNUNET_malloc (sizeof (struct MeshPathInfo));
1339 path_info->peer = peer; 1315 path_info->peer = peer;
1340 path_info->t = t; 1316 path_info->t = t;
1341 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1317 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1342 "MESH: Starting DHT GET for peer %s\n", 1318 "MESH: Starting DHT GET for peer %s\n", GNUNET_i2s (&id));
1343 GNUNET_i2s (&id));
1344 peer->dhtgetcls = path_info; 1319 peer->dhtgetcls = path_info;
1345 peer->dhtget = 1320 peer->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */
1346 GNUNET_DHT_get_start(dht_handle, /* handle */ 1321 GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
1347 GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ 1322 GNUNET_BLOCK_TYPE_TEST, /* type */
1348 GNUNET_BLOCK_TYPE_TEST, /* type */ 1323 &id.hashPubKey, /* key to search */
1349 &id.hashPubKey, /* key to search */ 1324 4, /* replication level */
1350 4, /* replication level */ 1325 GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */
1351 GNUNET_DHT_RO_RECORD_ROUTE | 1326 0, /* xquery bits */
1352 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 1327 &dht_get_id_handler, path_info);
1353 NULL, /* xquery */
1354 0, /* xquery bits */
1355 &dht_get_id_handler,
1356 path_info);
1357 } 1328 }
1358 /* Otherwise, there is no path but the DHT get is already started. */ 1329 /* Otherwise, there is no path but the DHT get is already started. */
1359} 1330}
@@ -1384,9 +1355,9 @@ peer_info_connect_task (void *cls,
1384 1355
1385/** 1356/**
1386 * Destroy the peer_info and free any allocated resources linked to it 1357 * Destroy the peer_info and free any allocated resources linked to it
1387 * 1358 *
1388 * @param pi The peer_info to destroy. 1359 * @param pi The peer_info to destroy.
1389 * 1360 *
1390 * @return GNUNET_OK on success 1361 * @return GNUNET_OK on success
1391 */ 1362 */
1392static int 1363static int
@@ -1401,21 +1372,20 @@ peer_info_destroy (struct MeshPeerInfo *pi)
1401 GNUNET_PEER_change_rc (pi->id, -1); 1372 GNUNET_PEER_change_rc (pi->id, -1);
1402 1373
1403 if (GNUNET_YES != 1374 if (GNUNET_YES !=
1404 GNUNET_CONTAINER_multihashmap_remove (peers,&id.hashPubKey, pi)) 1375 GNUNET_CONTAINER_multihashmap_remove (peers, &id.hashPubKey, pi))
1405 { 1376 {
1406 GNUNET_break (0); 1377 GNUNET_break (0);
1407 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1378 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1408 "MESH: removing peer %s, not in hashmap\n", 1379 "MESH: removing peer %s, not in hashmap\n", GNUNET_i2s (&id));
1409 GNUNET_i2s (&id));
1410 } 1380 }
1411 if (NULL != pi->dhtget) 1381 if (NULL != pi->dhtget)
1412 { 1382 {
1413 GNUNET_DHT_get_stop(pi->dhtget); 1383 GNUNET_DHT_get_stop (pi->dhtget);
1414 GNUNET_free (pi->dhtgetcls); 1384 GNUNET_free (pi->dhtgetcls);
1415 } 1385 }
1416 for (i = 0; i < CORE_QUEUE_SIZE; i++) 1386 for (i = 0; i < CORE_QUEUE_SIZE; i++)
1417 { 1387 {
1418 peer_info_cancel_transmission(pi, i); 1388 peer_info_cancel_transmission (pi, i);
1419 } 1389 }
1420 p = pi->path_head; 1390 p = pi->path_head;
1421 while (NULL != p) 1391 while (NULL != p)
@@ -1442,8 +1412,7 @@ peer_info_destroy (struct MeshPeerInfo *pi)
1442 * TODO: optimize (see below) 1412 * TODO: optimize (see below)
1443 */ 1413 */
1444static void 1414static void
1445peer_info_remove_path (struct MeshPeerInfo *peer, 1415peer_info_remove_path (struct MeshPeerInfo *peer, GNUNET_PEER_Id p1,
1446 GNUNET_PEER_Id p1,
1447 GNUNET_PEER_Id p2) 1416 GNUNET_PEER_Id p2)
1448{ 1417{
1449 struct MeshPeerPath *p; 1418 struct MeshPeerPath *p;
@@ -1486,16 +1455,16 @@ peer_info_remove_path (struct MeshPeerInfo *peer,
1486 * Some of them might already have a path to reach them that does not 1455 * Some of them might already have a path to reach them that does not
1487 * involve p1 and p2. Adding all anew might render in a better tree than 1456 * involve p1 and p2. Adding all anew might render in a better tree than
1488 * the trivial immediate fix. 1457 * the trivial immediate fix.
1489 * 1458 *
1490 * Trivial immiediate fix: try to reconnect to the disconnected node. All 1459 * Trivial immiediate fix: try to reconnect to the disconnected node. All
1491 * its children will be reachable trough him. 1460 * its children will be reachable trough him.
1492 */ 1461 */
1493 peer_d = peer_info_get_short(d); 1462 peer_d = peer_info_get_short (d);
1494 best = UINT_MAX; 1463 best = UINT_MAX;
1495 aux = NULL; 1464 aux = NULL;
1496 for (p = peer_d->path_head; NULL != p; p = p->next) 1465 for (p = peer_d->path_head; NULL != p; p = p->next)
1497 { 1466 {
1498 if ((cost = path_get_cost(peer->tunnels[i]->tree, p)) < best) 1467 if ((cost = path_get_cost (peer->tunnels[i]->tree, p)) < best)
1499 { 1468 {
1500 best = cost; 1469 best = cost;
1501 aux = p; 1470 aux = p;
@@ -1504,7 +1473,7 @@ peer_info_remove_path (struct MeshPeerInfo *peer,
1504 if (NULL != aux) 1473 if (NULL != aux)
1505 { 1474 {
1506 /* No callback, as peer will be already disconnected */ 1475 /* No callback, as peer will be already disconnected */
1507 tree_add_path(peer->tunnels[i]->tree, aux, NULL, NULL); 1476 tree_add_path (peer->tunnels[i]->tree, aux, NULL, NULL);
1508 } 1477 }
1509 else 1478 else
1510 { 1479 {
@@ -1524,8 +1493,7 @@ peer_info_remove_path (struct MeshPeerInfo *peer,
1524 * @param trusted Do we trust that this path is real? 1493 * @param trusted Do we trust that this path is real?
1525 */ 1494 */
1526void 1495void
1527peer_info_add_path (struct MeshPeerInfo *peer_info, 1496peer_info_add_path (struct MeshPeerInfo *peer_info, struct MeshPeerPath *path,
1528 struct MeshPeerPath *path,
1529 int trusted) 1497 int trusted)
1530{ 1498{
1531 struct MeshPeerPath *aux; 1499 struct MeshPeerPath *aux;
@@ -1549,28 +1517,24 @@ peer_info_add_path (struct MeshPeerInfo *peer_info,
1549 { 1517 {
1550 if (path->peers[l] == myid) 1518 if (path->peers[l] == myid)
1551 { 1519 {
1552 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1520 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: shortening path by %u\n", l);
1553 "MESH: shortening path by %u\n", 1521 for (l2 = 0; l2 < path->length - l - 1; l2++)
1554 l);
1555 for (l2 = 0; l2 < path->length - l - 1 ; l2++)
1556 { 1522 {
1557 path->peers[l2] = path->peers[l + l2]; 1523 path->peers[l2] = path->peers[l + l2];
1558 } 1524 }
1559 path->length -= l; 1525 path->length -= l;
1560 l = 1; 1526 l = 1;
1561 path->peers = GNUNET_realloc (path->peers, 1527 path->peers =
1562 path->length * sizeof (GNUNET_PEER_Id)); 1528 GNUNET_realloc (path->peers, path->length * sizeof (GNUNET_PEER_Id));
1563 } 1529 }
1564 } 1530 }
1565#if MESH_DEBUG 1531#if MESH_DEBUG
1566 { 1532 {
1567 struct GNUNET_PeerIdentity id; 1533 struct GNUNET_PeerIdentity id;
1568 1534
1569 GNUNET_PEER_resolve (peer_info->id, &id); 1535 GNUNET_PEER_resolve (peer_info->id, &id);
1570 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1536 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: adding path [%u] to peer %s\n",
1571 "MESH: adding path [%u] to peer %s\n", 1537 path->length, GNUNET_i2s (&id));
1572 path->length,
1573 GNUNET_i2s (&id));
1574 } 1538 }
1575#endif 1539#endif
1576 l = path_get_length (path); 1540 l = path_get_length (path);
@@ -1587,22 +1551,19 @@ peer_info_add_path (struct MeshPeerInfo *peer_info,
1587 if (l2 > l) 1551 if (l2 > l)
1588 { 1552 {
1589 GNUNET_CONTAINER_DLL_insert_before (peer_info->path_head, 1553 GNUNET_CONTAINER_DLL_insert_before (peer_info->path_head,
1590 peer_info->path_tail, 1554 peer_info->path_tail, aux, path);
1591 aux,
1592 path);
1593 return; 1555 return;
1594 } 1556 }
1595 else 1557 else
1596 { 1558 {
1597 if (l2 == l && memcmp(path->peers, aux->peers, l) == 0) 1559 if (l2 == l && memcmp (path->peers, aux->peers, l) == 0)
1598 { 1560 {
1599 path_destroy(path); 1561 path_destroy (path);
1600 return; 1562 return;
1601 } 1563 }
1602 } 1564 }
1603 } 1565 }
1604 GNUNET_CONTAINER_DLL_insert_tail (peer_info->path_head, 1566 GNUNET_CONTAINER_DLL_insert_tail (peer_info->path_head, peer_info->path_tail,
1605 peer_info->path_tail,
1606 path); 1567 path);
1607 return; 1568 return;
1608} 1569}
@@ -1620,10 +1581,9 @@ peer_info_add_path (struct MeshPeerInfo *peer_info,
1620 */ 1581 */
1621static void 1582static void
1622peer_info_add_path_to_origin (struct MeshPeerInfo *peer_info, 1583peer_info_add_path_to_origin (struct MeshPeerInfo *peer_info,
1623 struct MeshPeerPath *path, 1584 struct MeshPeerPath *path, int trusted)
1624 int trusted)
1625{ 1585{
1626 path_invert(path); 1586 path_invert (path);
1627 peer_info_add_path (peer_info, path, trusted); 1587 peer_info_add_path (peer_info, path, trusted);
1628} 1588}
1629 1589
@@ -1646,29 +1606,28 @@ path_build_from_dht (const struct GNUNET_PeerIdentity *get_path,
1646 1606
1647 p = path_new (1); 1607 p = path_new (1);
1648 p->peers[0] = myid; 1608 p->peers[0] = myid;
1649 GNUNET_PEER_change_rc(myid, 1); 1609 GNUNET_PEER_change_rc (myid, 1);
1650 i = get_path_length; 1610 i = get_path_length;
1651 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: GET has %d hops.\n", i); 1611 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: GET has %d hops.\n", i);
1652 for (i--; i >= 0; i--) 1612 for (i--; i >= 0; i--)
1653 { 1613 {
1654 id = GNUNET_PEER_intern (&get_path[i]); 1614 id = GNUNET_PEER_intern (&get_path[i]);
1655 if (p->length > 0 && id == p->peers[p->length - 1]) 1615 if (p->length > 0 && id == p->peers[p->length - 1])
1656 { 1616 {
1657 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: Optimizing 1 hop out.\n"); 1617 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Optimizing 1 hop out.\n");
1658 GNUNET_PEER_change_rc(id, -1); 1618 GNUNET_PEER_change_rc (id, -1);
1659 } 1619 }
1660 else 1620 else
1661 { 1621 {
1662 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1622 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Adding from GET: %s.\n",
1663 "MESH: Adding from GET: %s.\n", 1623 GNUNET_i2s (&get_path[i]));
1664 GNUNET_i2s(&get_path[i]));
1665 p->length++; 1624 p->length++;
1666 p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * p->length); 1625 p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * p->length);
1667 p->peers[p->length - 1] = id; 1626 p->peers[p->length - 1] = id;
1668 } 1627 }
1669 } 1628 }
1670 i = put_path_length; 1629 i = put_path_length;
1671 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: PUT has %d hops.\n", i); 1630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: PUT has %d hops.\n", i);
1672 for (i--; i >= 0; i--) 1631 for (i--; i >= 0; i--)
1673 { 1632 {
1674 id = GNUNET_PEER_intern (&put_path[i]); 1633 id = GNUNET_PEER_intern (&put_path[i]);
@@ -1682,14 +1641,13 @@ path_build_from_dht (const struct GNUNET_PeerIdentity *get_path,
1682 } 1641 }
1683 if (p->length > 0 && id == p->peers[p->length - 1]) 1642 if (p->length > 0 && id == p->peers[p->length - 1])
1684 { 1643 {
1685 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: Optimizing 1 hop out.\n"); 1644 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Optimizing 1 hop out.\n");
1686 GNUNET_PEER_change_rc(id, -1); 1645 GNUNET_PEER_change_rc (id, -1);
1687 } 1646 }
1688 else 1647 else
1689 { 1648 {
1690 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1649 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Adding from PUT: %s.\n",
1691 "MESH: Adding from PUT: %s.\n", 1650 GNUNET_i2s (&put_path[i]));
1692 GNUNET_i2s(&put_path[i]));
1693 p->length++; 1651 p->length++;
1694 p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * p->length); 1652 p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * p->length);
1695 p->peers[p->length - 1] = id; 1653 p->peers[p->length - 1] = id;
@@ -1697,25 +1655,20 @@ path_build_from_dht (const struct GNUNET_PeerIdentity *get_path,
1697 } 1655 }
1698#if MESH_DEBUG 1656#if MESH_DEBUG
1699 if (get_path_length > 0) 1657 if (get_path_length > 0)
1700 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1658 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: (first of GET: %s)\n",
1701 "MESH: (first of GET: %s)\n", 1659 GNUNET_i2s (&get_path[0]));
1702 GNUNET_i2s(&get_path[0]));
1703 if (put_path_length > 0) 1660 if (put_path_length > 0)
1704 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1661 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: (first of PUT: %s)\n",
1705 "MESH: (first of PUT: %s)\n", 1662 GNUNET_i2s (&put_path[0]));
1706 GNUNET_i2s(&put_path[0])); 1663 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: In total: %d hops\n",
1707 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1708 "MESH: In total: %d hops\n",
1709 p->length); 1664 p->length);
1710 for (i = 0; i < p->length; i++) 1665 for (i = 0; i < p->length; i++)
1711 { 1666 {
1712 struct GNUNET_PeerIdentity peer_id; 1667 struct GNUNET_PeerIdentity peer_id;
1713 1668
1714 GNUNET_PEER_resolve(p->peers[i], &peer_id); 1669 GNUNET_PEER_resolve (p->peers[i], &peer_id);
1715 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1670 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %u: %s\n", p->peers[i],
1716 "MESH: %u: %s\n", 1671 GNUNET_i2s (&peer_id));
1717 p->peers[i],
1718 GNUNET_i2s(&peer_id));
1719 } 1672 }
1720#endif 1673#endif
1721 return p; 1674 return p;
@@ -1831,6 +1784,7 @@ notify_peer_disconnected (void *cls, GNUNET_PEER_Id peer_id)
1831 if (NULL != t->client && NULL != nc) 1784 if (NULL != t->client && NULL != nc)
1832 { 1785 {
1833 struct GNUNET_MESH_PeerControl msg; 1786 struct GNUNET_MESH_PeerControl msg;
1787
1834 msg.header.size = htons (sizeof (msg)); 1788 msg.header.size = htons (sizeof (msg));
1835 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL); 1789 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL);
1836 msg.tunnel_id = htonl (t->local_tid); 1790 msg.tunnel_id = htonl (t->local_tid);
@@ -1838,11 +1792,11 @@ notify_peer_disconnected (void *cls, GNUNET_PEER_Id peer_id)
1838 GNUNET_SERVER_notification_context_unicast (nc, t->client->handle, 1792 GNUNET_SERVER_notification_context_unicast (nc, t->client->handle,
1839 &msg.header, GNUNET_NO); 1793 &msg.header, GNUNET_NO);
1840 } 1794 }
1841 peer = peer_info_get_short(peer_id); 1795 peer = peer_info_get_short (peer_id);
1842 path_info = GNUNET_malloc (sizeof (struct MeshPathInfo)); 1796 path_info = GNUNET_malloc (sizeof (struct MeshPathInfo));
1843 path_info->peer = peer; 1797 path_info->peer = peer;
1844 path_info->t = t; 1798 path_info->t = t;
1845 GNUNET_SCHEDULER_add_now(&peer_info_connect_task, path_info); 1799 GNUNET_SCHEDULER_add_now (&peer_info_connect_task, path_info);
1846} 1800}
1847 1801
1848 1802
@@ -1864,23 +1818,22 @@ tunnel_add_peer (struct MeshTunnel *t, struct MeshPeerInfo *peer)
1864 unsigned int best_cost; 1818 unsigned int best_cost;
1865 unsigned int cost; 1819 unsigned int cost;
1866 1820
1867 GNUNET_PEER_resolve(peer->id, &id); 1821 GNUNET_PEER_resolve (peer->id, &id);
1868 if (GNUNET_NO == 1822 if (GNUNET_NO ==
1869 GNUNET_CONTAINER_multihashmap_contains(t->peers, &id.hashPubKey)) 1823 GNUNET_CONTAINER_multihashmap_contains (t->peers, &id.hashPubKey))
1870 { 1824 {
1871 t->peers_total++; 1825 t->peers_total++;
1872 GNUNET_array_append (peer->tunnels, peer->ntunnels, t); 1826 GNUNET_array_append (peer->tunnels, peer->ntunnels, t);
1873 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put( 1827 GNUNET_assert (GNUNET_OK ==
1874 t->peers, 1828 GNUNET_CONTAINER_multihashmap_put (t->peers, &id.hashPubKey,
1875 &id.hashPubKey, 1829 peer,
1876 peer, 1830 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
1877 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
1878 } 1831 }
1879 1832
1880 if (NULL != (p = peer->path_head)) 1833 if (NULL != (p = peer->path_head))
1881 { 1834 {
1882 best_p = p; 1835 best_p = p;
1883 best_cost = path_get_cost(t->tree, p); 1836 best_cost = path_get_cost (t->tree, p);
1884 while (NULL != p) 1837 while (NULL != p)
1885 { 1838 {
1886 if ((cost = path_get_cost (t->tree, p)) < best_cost) 1839 if ((cost = path_get_cost (t->tree, p)) < best_cost)
@@ -1898,7 +1851,7 @@ tunnel_add_peer (struct MeshTunnel *t, struct MeshPeerInfo *peer)
1898 else 1851 else
1899 { 1852 {
1900 /* Start a DHT get if necessary */ 1853 /* Start a DHT get if necessary */
1901 peer_info_connect(peer, t); 1854 peer_info_connect (peer, t);
1902 } 1855 }
1903} 1856}
1904 1857
@@ -1913,22 +1866,19 @@ tunnel_add_peer (struct MeshTunnel *t, struct MeshPeerInfo *peer)
1913 * 1866 *
1914 */ 1867 */
1915static void 1868static void
1916tunnel_add_path (struct MeshTunnel *t, 1869tunnel_add_path (struct MeshTunnel *t, struct MeshPeerPath *p,
1917 struct MeshPeerPath *p,
1918 unsigned int own_pos) 1870 unsigned int own_pos)
1919{ 1871{
1920 struct GNUNET_PeerIdentity id; 1872 struct GNUNET_PeerIdentity id;
1921 1873
1922 GNUNET_assert (0 != own_pos); 1874 GNUNET_assert (0 != own_pos);
1923 tree_add_path(t->tree, p, NULL, NULL); 1875 tree_add_path (t->tree, p, NULL, NULL);
1924 if (tree_get_me (t->tree) == 0) 1876 if (tree_get_me (t->tree) == 0)
1925 tree_set_me (t->tree, p->peers[own_pos]); 1877 tree_set_me (t->tree, p->peers[own_pos]);
1926 if (own_pos < p->length - 1) 1878 if (own_pos < p->length - 1)
1927 { 1879 {
1928 GNUNET_PEER_resolve (p->peers[own_pos + 1], &id); 1880 GNUNET_PEER_resolve (p->peers[own_pos + 1], &id);
1929 tree_update_first_hops(t->tree, 1881 tree_update_first_hops (t->tree, tree_get_me (t->tree), &id);
1930 tree_get_me (t->tree),
1931 &id);
1932 } 1882 }
1933} 1883}
1934 1884
@@ -1947,24 +1897,21 @@ tunnel_add_path (struct MeshTunnel *t,
1947 * 0 if the tunnel remained unaffected. 1897 * 0 if the tunnel remained unaffected.
1948 */ 1898 */
1949static GNUNET_PEER_Id 1899static GNUNET_PEER_Id
1950tunnel_notify_connection_broken (struct MeshTunnel *t, 1900tunnel_notify_connection_broken (struct MeshTunnel *t, GNUNET_PEER_Id p1,
1951 GNUNET_PEER_Id p1,
1952 GNUNET_PEER_Id p2) 1901 GNUNET_PEER_Id p2)
1953{ 1902{
1954 GNUNET_PEER_Id pid; 1903 GNUNET_PEER_Id pid;
1955 1904
1956 pid = tree_notify_connection_broken (t->tree, 1905 pid =
1957 p1, 1906 tree_notify_connection_broken (t->tree, p1, p2, &notify_peer_disconnected,
1958 p2, 1907 t);
1959 &notify_peer_disconnected,
1960 t);
1961 if (myid != p1 && myid != p2) 1908 if (myid != p1 && myid != p2)
1962 { 1909 {
1963 return pid; 1910 return pid;
1964 } 1911 }
1965 if (pid != myid) 1912 if (pid != myid)
1966 { 1913 {
1967 if (tree_get_predecessor(t->tree) != 0) 1914 if (tree_get_predecessor (t->tree) != 0)
1968 { 1915 {
1969 /* We are the peer still connected, notify owner of the disconnection. */ 1916 /* We are the peer still connected, notify owner of the disconnection. */
1970 struct GNUNET_MESH_PathBroken msg; 1917 struct GNUNET_MESH_PathBroken msg;
@@ -2002,8 +1949,7 @@ struct MeshMulticastData
2002 * Send a multicast packet to a neighbor. 1949 * Send a multicast packet to a neighbor.
2003 */ 1950 */
2004static void 1951static void
2005tunnel_send_multicast_iterator (void *cls, 1952tunnel_send_multicast_iterator (void *cls, GNUNET_PEER_Id neighbor_id)
2006 GNUNET_PEER_Id neighbor_id)
2007{ 1953{
2008 struct MeshMulticastData *mdata = cls; 1954 struct MeshMulticastData *mdata = cls;
2009 struct MeshDataDescriptor *info; 1955 struct MeshDataDescriptor *info;
@@ -2025,24 +1971,20 @@ tunnel_send_multicast_iterator (void *cls,
2025 info->destination = neighbor_id; 1971 info->destination = neighbor_id;
2026 GNUNET_PEER_resolve (neighbor_id, &neighbor); 1972 GNUNET_PEER_resolve (neighbor_id, &neighbor);
2027#if MESH_DEBUG 1973#if MESH_DEBUG
2028 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1974 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: sending to %s...\n",
2029 "MESH: sending to %s...\n", 1975 GNUNET_i2s (&neighbor));
2030 GNUNET_i2s (&neighbor));
2031#endif 1976#endif
2032 info->peer = peer_info_get(&neighbor); 1977 info->peer = peer_info_get (&neighbor);
2033 GNUNET_assert (NULL != info->peer); 1978 GNUNET_assert (NULL != info->peer);
2034 i = peer_info_transmit_slot(info->peer); 1979 i = peer_info_transmit_slot (info->peer);
2035 info->handler_n = i; 1980 info->handler_n = i;
2036 info->peer->infos[i] = info; 1981 info->peer->infos[i] = info;
2037 info->peer->types[i] = GNUNET_MESSAGE_TYPE_MESH_MULTICAST; 1982 info->peer->types[i] = GNUNET_MESSAGE_TYPE_MESH_MULTICAST;
2038 info->peer->core_transmit[i] = 1983 info->peer->core_transmit[i] =
2039 GNUNET_CORE_notify_transmit_ready (core_handle, 1984 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
2040 0, 1985 GNUNET_TIME_UNIT_FOREVER_REL,
2041 0, 1986 &neighbor, info->size,
2042 GNUNET_TIME_UNIT_FOREVER_REL, 1987 &send_core_data_multicast, info);
2043 &neighbor,
2044 info->size,
2045 &send_core_data_multicast, info);
2046} 1988}
2047 1989
2048/** 1990/**
@@ -2072,9 +2014,9 @@ tunnel_send_multicast (struct MeshTunnel *t,
2072 if (NULL != t->client) 2014 if (NULL != t->client)
2073 { 2015 {
2074 mdata->task = GNUNET_malloc (sizeof (GNUNET_SCHEDULER_TaskIdentifier)); 2016 mdata->task = GNUNET_malloc (sizeof (GNUNET_SCHEDULER_TaskIdentifier));
2075 *(mdata->task) = GNUNET_SCHEDULER_add_delayed (UNACKNOWLEDGED_WAIT, 2017 *(mdata->task) =
2076 &client_allow_send, 2018 GNUNET_SCHEDULER_add_delayed (UNACKNOWLEDGED_WAIT, &client_allow_send,
2077 t->client->handle); 2019 t->client->handle);
2078 } 2020 }
2079 2021
2080 tree_iterate_children (t->tree, &tunnel_send_multicast_iterator, mdata); 2022 tree_iterate_children (t->tree, &tunnel_send_multicast_iterator, mdata);
@@ -2140,11 +2082,9 @@ tunnel_destroy (struct MeshTunnel *t)
2140 { 2082 {
2141 struct GNUNET_PeerIdentity id; 2083 struct GNUNET_PeerIdentity id;
2142 2084
2143 GNUNET_PEER_resolve(t->id.oid, &id); 2085 GNUNET_PEER_resolve (t->id.oid, &id);
2144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2086 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: destroying tunnel %s [%x]\n",
2145 "MESH: destroying tunnel %s [%x]\n", 2087 GNUNET_i2s (&id), t->id.tid);
2146 GNUNET_i2s (&id),
2147 t->id.tid);
2148 if (NULL != c) 2088 if (NULL != c)
2149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: by client %u\n", c->id); 2089 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: by client %u\n", c->id);
2150 } 2090 }
@@ -2166,12 +2106,13 @@ tunnel_destroy (struct MeshTunnel *t)
2166 { 2106 {
2167 GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash); 2107 GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash);
2168 GNUNET_break (GNUNET_YES == 2108 GNUNET_break (GNUNET_YES ==
2169 GNUNET_CONTAINER_multihashmap_remove (incoming_tunnels, &hash, t)); 2109 GNUNET_CONTAINER_multihashmap_remove (incoming_tunnels, &hash,
2110 t));
2170 } 2111 }
2171 if (NULL != t->peers) 2112 if (NULL != t->peers)
2172 { 2113 {
2173 GNUNET_CONTAINER_multihashmap_iterate(t->peers, 2114 GNUNET_CONTAINER_multihashmap_iterate (t->peers, &peer_info_delete_tunnel,
2174 &peer_info_delete_tunnel, t); 2115 t);
2175 GNUNET_CONTAINER_multihashmap_destroy (t->peers); 2116 GNUNET_CONTAINER_multihashmap_destroy (t->peers);
2176 } 2117 }
2177 q = t->queue_head; 2118 q = t->queue_head;
@@ -2184,13 +2125,13 @@ tunnel_destroy (struct MeshTunnel *t)
2184 q = qn; 2125 q = qn;
2185 /* TODO cancel core transmit ready in case it was active */ 2126 /* TODO cancel core transmit ready in case it was active */
2186 } 2127 }
2187 tree_destroy(t->tree); 2128 tree_destroy (t->tree);
2188 if (NULL != t->dht_get_type) 2129 if (NULL != t->dht_get_type)
2189 GNUNET_DHT_get_stop(t->dht_get_type); 2130 GNUNET_DHT_get_stop (t->dht_get_type);
2190 if (GNUNET_SCHEDULER_NO_TASK != t->timeout_task) 2131 if (GNUNET_SCHEDULER_NO_TASK != t->timeout_task)
2191 GNUNET_SCHEDULER_cancel(t->timeout_task); 2132 GNUNET_SCHEDULER_cancel (t->timeout_task);
2192 if (GNUNET_SCHEDULER_NO_TASK != t->path_refresh_task) 2133 if (GNUNET_SCHEDULER_NO_TASK != t->path_refresh_task)
2193 GNUNET_SCHEDULER_cancel(t->path_refresh_task); 2134 GNUNET_SCHEDULER_cancel (t->path_refresh_task);
2194 GNUNET_free (t); 2135 GNUNET_free (t);
2195 return r; 2136 return r;
2196} 2137}
@@ -2205,8 +2146,7 @@ tunnel_destroy (struct MeshTunnel *t)
2205 * @param p Peer which should be removed. 2146 * @param p Peer which should be removed.
2206 */ 2147 */
2207static void 2148static void
2208tunnel_delete_peer (struct MeshTunnel *t, 2149tunnel_delete_peer (struct MeshTunnel *t, GNUNET_PEER_Id peer)
2209 GNUNET_PEER_Id peer)
2210{ 2150{
2211 if (GNUNET_NO == tree_del_peer (t->tree, peer, NULL, NULL)) 2151 if (GNUNET_NO == tree_del_peer (t->tree, peer, NULL, NULL))
2212 tunnel_destroy (t); 2152 tunnel_destroy (t);
@@ -2216,11 +2156,11 @@ tunnel_delete_peer (struct MeshTunnel *t,
2216/** 2156/**
2217 * tunnel_destroy_iterator: iterator for deleting each tunnel that belongs to a 2157 * tunnel_destroy_iterator: iterator for deleting each tunnel that belongs to a
2218 * client when the client disconnects. 2158 * client when the client disconnects.
2219 * 2159 *
2220 * @param cls closure (client that is disconnecting) 2160 * @param cls closure (client that is disconnecting)
2221 * @param key the hash of the local tunnel id (used to access the hashmap) 2161 * @param key the hash of the local tunnel id (used to access the hashmap)
2222 * @param value the value stored at the key (tunnel to destroy) 2162 * @param value the value stored at the key (tunnel to destroy)
2223 * 2163 *
2224 * @return GNUNET_OK on success 2164 * @return GNUNET_OK on success
2225 */ 2165 */
2226static int 2166static int
@@ -2261,10 +2201,9 @@ tunnel_reset_timeout (struct MeshTunnel *t)
2261{ 2201{
2262 if (GNUNET_SCHEDULER_NO_TASK != t->timeout_task) 2202 if (GNUNET_SCHEDULER_NO_TASK != t->timeout_task)
2263 GNUNET_SCHEDULER_cancel (t->timeout_task); 2203 GNUNET_SCHEDULER_cancel (t->timeout_task);
2264 t->timeout_task = GNUNET_SCHEDULER_add_delayed ( 2204 t->timeout_task =
2265 GNUNET_TIME_relative_multiply(REFRESH_PATH_TIME, 4), 2205 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2266 &tunnel_timeout, 2206 (REFRESH_PATH_TIME, 4), &tunnel_timeout, t);
2267 t);
2268} 2207}
2269 2208
2270 2209
@@ -2295,8 +2234,7 @@ send_core_create_path (void *cls, size_t size, void *buf)
2295 size_t size_needed; 2234 size_t size_needed;
2296 int i; 2235 int i;
2297 2236
2298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2237 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: CREATE PATH sending...\n");
2299 "MESH: CREATE PATH sending...\n");
2300 size_needed = 2238 size_needed =
2301 sizeof (struct GNUNET_MESH_ManipulatePath) + 2239 sizeof (struct GNUNET_MESH_ManipulatePath) +
2302 p->length * sizeof (struct GNUNET_PeerIdentity); 2240 p->length * sizeof (struct GNUNET_PeerIdentity);
@@ -2305,15 +2243,15 @@ send_core_create_path (void *cls, size_t size, void *buf)
2305 { 2243 {
2306 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: create path retransmit!\n"); 2244 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: create path retransmit!\n");
2307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: buf: %p\n", buf); 2245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: buf: %p\n", buf);
2308 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: size: (%u/%u)\n", 2246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: size: (%u/%u)\n", size,
2309 size, size_needed); 2247 size_needed);
2310 info->peer->core_transmit[info->pos] = 2248 info->peer->core_transmit[info->pos] =
2311 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0, 2249 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
2312 GNUNET_TIME_UNIT_FOREVER_REL, 2250 GNUNET_TIME_UNIT_FOREVER_REL,
2313 path_get_first_hop (t->tree, peer->id), 2251 path_get_first_hop (t->tree,
2314 size_needed, 2252 peer->id),
2315 &send_core_create_path, 2253 size_needed, &send_core_create_path,
2316 info); 2254 info);
2317 return 0; 2255 return 0;
2318 } 2256 }
2319 info->peer->core_transmit[info->pos] = NULL; 2257 info->peer->core_transmit[info->pos] = NULL;
@@ -2324,8 +2262,7 @@ send_core_create_path (void *cls, size_t size, void *buf)
2324 GNUNET_PEER_resolve (peer->id, &id); 2262 GNUNET_PEER_resolve (peer->id, &id);
2325 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2326 "MESH: setting core_transmit %s [%u] to NULL\n", 2264 "MESH: setting core_transmit %s [%u] to NULL\n",
2327 GNUNET_i2s (&id), 2265 GNUNET_i2s (&id), info->pos);
2328 info->pos);
2329 } 2266 }
2330#endif 2267#endif
2331 msg = (struct GNUNET_MESH_ManipulatePath *) buf; 2268 msg = (struct GNUNET_MESH_ManipulatePath *) buf;
@@ -2343,8 +2280,7 @@ send_core_create_path (void *cls, size_t size, void *buf)
2343 GNUNET_free (info); 2280 GNUNET_free (info);
2344 2281
2345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2282 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2346 "MESH: CREATE PATH (%u bytes long) sent!\n", 2283 "MESH: CREATE PATH (%u bytes long) sent!\n", size_needed);
2347 size_needed);
2348 return size_needed; 2284 return size_needed;
2349} 2285}
2350 2286
@@ -2358,7 +2294,7 @@ send_core_create_path (void *cls, size_t size, void *buf)
2358 * @param cls closure (data itself) 2294 * @param cls closure (data itself)
2359 * @param size number of bytes available in buf 2295 * @param size number of bytes available in buf
2360 * @param buf where the callee should write the message 2296 * @param buf where the callee should write the message
2361 * 2297 *
2362 * @return number of bytes written to buf 2298 * @return number of bytes written to buf
2363 */ 2299 */
2364static size_t 2300static size_t
@@ -2379,18 +2315,14 @@ send_core_data_multicast (void *cls, size_t size, void *buf)
2379 struct GNUNET_PeerIdentity id; 2315 struct GNUNET_PeerIdentity id;
2380 2316
2381 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2317 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2382 "MESH: Multicast: retransmitting... (%u/%u)\n", 2318 "MESH: Multicast: retransmitting... (%u/%u)\n", size,
2383 size, total_size); 2319 total_size);
2384 GNUNET_PEER_resolve(info->peer->id, &id); 2320 GNUNET_PEER_resolve (info->peer->id, &id);
2385 info->peer->core_transmit[info->handler_n] = 2321 info->peer->core_transmit[info->handler_n] =
2386 GNUNET_CORE_notify_transmit_ready (core_handle, 2322 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
2387 0, 2323 GNUNET_TIME_UNIT_FOREVER_REL, &id,
2388 0, 2324 total_size,
2389 GNUNET_TIME_UNIT_FOREVER_REL, 2325 &send_core_data_multicast, info);
2390 &id,
2391 total_size,
2392 &send_core_data_multicast,
2393 info);
2394 return 0; 2326 return 0;
2395 } 2327 }
2396 info->peer->core_transmit[info->handler_n] = NULL; 2328 info->peer->core_transmit[info->handler_n] = NULL;
@@ -2408,16 +2340,13 @@ send_core_data_multicast (void *cls, size_t size, void *buf)
2408 mc = (struct GNUNET_MESH_Multicast *) mh; 2340 mc = (struct GNUNET_MESH_Multicast *) mh;
2409 mh = (struct GNUNET_MessageHeader *) &mc[1]; 2341 mh = (struct GNUNET_MessageHeader *) &mc[1];
2410 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2342 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2411 "MESH: multicast, payload type %u\n", 2343 "MESH: multicast, payload type %u\n", ntohs (mh->type));
2412 ntohs (mh->type));
2413 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2414 "MESH: multicast, payload size %u\n", 2345 "MESH: multicast, payload size %u\n", ntohs (mh->size));
2415 ntohs (mh->size));
2416 } 2346 }
2417 else 2347 else
2418 { 2348 {
2419 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2349 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type %u\n",
2420 "MESH: type %u\n",
2421 ntohs (mh->type)); 2350 ntohs (mh->type));
2422 } 2351 }
2423 } 2352 }
@@ -2483,7 +2412,7 @@ send_core_path_ack (void *cls, size_t size, void *buf)
2483 * @param peer peer identity this notification is about 2412 * @param peer peer identity this notification is about
2484 * @param atsi performance data 2413 * @param atsi performance data
2485 * @param atsi_count number of records in 'atsi' 2414 * @param atsi_count number of records in 'atsi'
2486 * 2415 *
2487 * @return GNUNET_OK to keep the connection open, 2416 * @return GNUNET_OK to keep the connection open,
2488 * GNUNET_SYSERR to close it (signal serious error) 2417 * GNUNET_SYSERR to close it (signal serious error)
2489 */ 2418 */
@@ -2491,7 +2420,7 @@ static int
2491handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, 2420handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
2492 const struct GNUNET_MessageHeader *message, 2421 const struct GNUNET_MessageHeader *message,
2493 const struct GNUNET_ATS_Information *atsi, 2422 const struct GNUNET_ATS_Information *atsi,
2494 unsigned int atsi_count) 2423 unsigned int atsi_count)
2495{ 2424{
2496 unsigned int own_pos; 2425 unsigned int own_pos;
2497 uint16_t size; 2426 uint16_t size;
@@ -2507,7 +2436,7 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
2507 2436
2508 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2437 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2509 "MESH: Received a path create msg [%s]\n", 2438 "MESH: Received a path create msg [%s]\n",
2510 GNUNET_i2s(&my_full_id)); 2439 GNUNET_i2s (&my_full_id));
2511 size = ntohs (message->size); 2440 size = ntohs (message->size);
2512 if (size < sizeof (struct GNUNET_MESH_ManipulatePath)) 2441 if (size < sizeof (struct GNUNET_MESH_ManipulatePath))
2513 { 2442 {
@@ -2527,18 +2456,14 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
2527 GNUNET_break_op (0); 2456 GNUNET_break_op (0);
2528 return GNUNET_OK; 2457 return GNUNET_OK;
2529 } 2458 }
2530 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2459 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: path has %u hops.\n", size);
2531 "MESH: path has %u hops.\n",
2532 size);
2533 msg = (struct GNUNET_MESH_ManipulatePath *) message; 2460 msg = (struct GNUNET_MESH_ManipulatePath *) message;
2534 2461
2535 tid = ntohl (msg->tid); 2462 tid = ntohl (msg->tid);
2536 pi = (struct GNUNET_PeerIdentity *) &msg[1]; 2463 pi = (struct GNUNET_PeerIdentity *) &msg[1];
2537 t = tunnel_get (pi, tid); 2464 t = tunnel_get (pi, tid);
2538 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2465 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2539 "MESH: path is for tunnel %s [%X].\n", 2466 "MESH: path is for tunnel %s [%X].\n", GNUNET_i2s (pi), tid);
2540 GNUNET_i2s(pi),
2541 tid);
2542 if (NULL == t) 2467 if (NULL == t)
2543 { 2468 {
2544 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Creating tunnel\n"); 2469 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Creating tunnel\n");
@@ -2549,15 +2474,12 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
2549 next_local_tid = (next_local_tid + 1) | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV; 2474 next_local_tid = (next_local_tid + 1) | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV;
2550 t->local_tid = next_local_tid++; 2475 t->local_tid = next_local_tid++;
2551 next_local_tid = next_local_tid | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV; 2476 next_local_tid = next_local_tid | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV;
2552 t->tree = tree_new(t->id.oid); 2477 t->tree = tree_new (t->id.oid);
2553 2478
2554 GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); 2479 GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash);
2555 if (GNUNET_OK != 2480 if (GNUNET_OK !=
2556 GNUNET_CONTAINER_multihashmap_put ( 2481 GNUNET_CONTAINER_multihashmap_put (tunnels, &hash, t,
2557 tunnels, 2482 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
2558 &hash,
2559 t,
2560 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
2561 { 2483 {
2562 tunnel_destroy (t); 2484 tunnel_destroy (t);
2563 GNUNET_break (0); 2485 GNUNET_break (0);
@@ -2566,11 +2488,8 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
2566 tunnel_reset_timeout (t); 2488 tunnel_reset_timeout (t);
2567 GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash); 2489 GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash);
2568 if (GNUNET_OK != 2490 if (GNUNET_OK !=
2569 GNUNET_CONTAINER_multihashmap_put ( 2491 GNUNET_CONTAINER_multihashmap_put (incoming_tunnels, &hash, t,
2570 incoming_tunnels, 2492 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
2571 &hash,
2572 t,
2573 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
2574 { 2493 {
2575 tunnel_destroy (t); 2494 tunnel_destroy (t);
2576 GNUNET_break (0); 2495 GNUNET_break (0);
@@ -2604,15 +2523,13 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
2604 own_pos = 0; 2523 own_pos = 0;
2605 for (i = 0; i < size; i++) 2524 for (i = 0; i < size; i++)
2606 { 2525 {
2607 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2526 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: ... adding %s\n",
2608 "MESH: ... adding %s\n", 2527 GNUNET_i2s (&pi[i]));
2609 GNUNET_i2s(&pi[i]));
2610 path->peers[i] = GNUNET_PEER_intern (&pi[i]); 2528 path->peers[i] = GNUNET_PEER_intern (&pi[i]);
2611 if (path->peers[i] == myid) 2529 if (path->peers[i] == myid)
2612 own_pos = i; 2530 own_pos = i;
2613 } 2531 }
2614 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Own position: %u\n", own_pos);
2615 "MESH: Own position: %u\n", own_pos);
2616 if (own_pos == 0) 2533 if (own_pos == 0)
2617 { 2534 {
2618 /* cannot be self, must be 'not found' */ 2535 /* cannot be self, must be 'not found' */
@@ -2630,22 +2547,22 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
2630 struct MeshDataDescriptor *info; 2547 struct MeshDataDescriptor *info;
2631 unsigned int j; 2548 unsigned int j;
2632 2549
2633 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: It's for us!\n");
2634 "MESH: It's for us!\n");
2635 peer_info_add_path_to_origin (orig_peer_info, path, GNUNET_NO); 2551 peer_info_add_path_to_origin (orig_peer_info, path, GNUNET_NO);
2636 if (NULL == t->peers) 2552 if (NULL == t->peers)
2637 t->peers = GNUNET_CONTAINER_multihashmap_create(4); 2553 t->peers = GNUNET_CONTAINER_multihashmap_create (4);
2638 GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put ( 2554 GNUNET_break (GNUNET_OK ==
2639 t->peers, 2555 GNUNET_CONTAINER_multihashmap_put (t->peers,
2640 &my_full_id.hashPubKey, 2556 &my_full_id.hashPubKey,
2641 peer_info_get(&my_full_id), 2557 peer_info_get
2642 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); 2558 (&my_full_id),
2559 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
2643 /* FIXME use send_message */ 2560 /* FIXME use send_message */
2644 info = GNUNET_malloc (sizeof (struct MeshDataDescriptor)); 2561 info = GNUNET_malloc (sizeof (struct MeshDataDescriptor));
2645 info->origin = &t->id; 2562 info->origin = &t->id;
2646 info->peer = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); 2563 info->peer = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
2647 GNUNET_assert (NULL != info->peer); 2564 GNUNET_assert (NULL != info->peer);
2648 j = peer_info_transmit_slot(info->peer); 2565 j = peer_info_transmit_slot (info->peer);
2649 info->handler_n = j; 2566 info->handler_n = j;
2650 info->peer->types[j] = GNUNET_MESSAGE_TYPE_MESH_PATH_ACK; 2567 info->peer->types[j] = GNUNET_MESSAGE_TYPE_MESH_PATH_ACK;
2651 info->peer->infos[j] = info; 2568 info->peer->infos[j] = info;
@@ -2654,24 +2571,23 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
2654 GNUNET_TIME_UNIT_FOREVER_REL, peer, 2571 GNUNET_TIME_UNIT_FOREVER_REL, peer,
2655 sizeof (struct GNUNET_MESH_PathACK), 2572 sizeof (struct GNUNET_MESH_PathACK),
2656 &send_core_path_ack, info); 2573 &send_core_path_ack, info);
2657 cmsg.header.size = htons(sizeof(cmsg)); 2574 cmsg.header.size = htons (sizeof (cmsg));
2658 cmsg.header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE); 2575 cmsg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE);
2659 GNUNET_PEER_resolve(t->id.oid, &cmsg.peer); 2576 GNUNET_PEER_resolve (t->id.oid, &cmsg.peer);
2660 cmsg.tunnel_id = htonl(t->local_tid); 2577 cmsg.tunnel_id = htonl (t->local_tid);
2661 GNUNET_SERVER_notification_context_broadcast(nc, &cmsg.header, GNUNET_NO); 2578 GNUNET_SERVER_notification_context_broadcast (nc, &cmsg.header, GNUNET_NO);
2662 } 2579 }
2663 else 2580 else
2664 { 2581 {
2665 struct MeshPeerPath *path2; 2582 struct MeshPeerPath *path2;
2666 2583
2667 /* It's for somebody else! Retransmit. */ 2584 /* It's for somebody else! Retransmit. */
2668 path2 = path_duplicate(path); 2585 path2 = path_duplicate (path);
2669 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2586 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Retransmitting.\n");
2670 "MESH: Retransmitting.\n"); 2587 peer_info_add_path (dest_peer_info, path2, GNUNET_NO);
2671 peer_info_add_path(dest_peer_info, path2, GNUNET_NO); 2588 path2 = path_duplicate (path);
2672 path2 = path_duplicate(path); 2589 peer_info_add_path_to_origin (orig_peer_info, path2, GNUNET_NO);
2673 peer_info_add_path_to_origin(orig_peer_info, path2, GNUNET_NO); 2590 send_create_path (dest_peer_info, path, t);
2674 send_create_path(dest_peer_info, path, t);
2675 } 2591 }
2676 return GNUNET_OK; 2592 return GNUNET_OK;
2677} 2593}
@@ -2693,7 +2609,7 @@ static int
2693handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, 2609handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
2694 const struct GNUNET_MessageHeader *message, 2610 const struct GNUNET_MessageHeader *message,
2695 const struct GNUNET_ATS_Information *atsi, 2611 const struct GNUNET_ATS_Information *atsi,
2696 unsigned int atsi_count) 2612 unsigned int atsi_count)
2697{ 2613{
2698 struct GNUNET_MESH_ManipulatePath *msg; 2614 struct GNUNET_MESH_ManipulatePath *msg;
2699 struct GNUNET_PeerIdentity *pi; 2615 struct GNUNET_PeerIdentity *pi;
@@ -2704,8 +2620,7 @@ handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
2704 size_t size; 2620 size_t size;
2705 2621
2706 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2622 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2707 "MESH: Received a PATH DESTROY msg from %s\n", 2623 "MESH: Received a PATH DESTROY msg from %s\n", GNUNET_i2s (peer));
2708 GNUNET_i2s(peer));
2709 size = ntohs (message->size); 2624 size = ntohs (message->size);
2710 if (size < sizeof (struct GNUNET_MESH_ManipulatePath)) 2625 if (size < sizeof (struct GNUNET_MESH_ManipulatePath))
2711 { 2626 {
@@ -2725,15 +2640,12 @@ handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
2725 GNUNET_break_op (0); 2640 GNUNET_break_op (0);
2726 return GNUNET_OK; 2641 return GNUNET_OK;
2727 } 2642 }
2728 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2643 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: path has %u hops.\n", size);
2729 "MESH: path has %u hops.\n",
2730 size);
2731 2644
2732 msg = (struct GNUNET_MESH_ManipulatePath *) message; 2645 msg = (struct GNUNET_MESH_ManipulatePath *) message;
2733 pi = (struct GNUNET_PeerIdentity *) &msg[1]; 2646 pi = (struct GNUNET_PeerIdentity *) &msg[1];
2734 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2647 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2735 "MESH: path is for tunnel %s [%X].\n", 2648 "MESH: path is for tunnel %s [%X].\n", GNUNET_i2s (pi),
2736 GNUNET_i2s(pi),
2737 msg->tid); 2649 msg->tid);
2738 t = tunnel_get (pi, ntohl (msg->tid)); 2650 t = tunnel_get (pi, ntohl (msg->tid));
2739 if (NULL == t) 2651 if (NULL == t)
@@ -2747,15 +2659,13 @@ handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
2747 own_pos = 0; 2659 own_pos = 0;
2748 for (i = 0; i < size; i++) 2660 for (i = 0; i < size; i++)
2749 { 2661 {
2750 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2662 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: ... adding %s\n",
2751 "MESH: ... adding %s\n", 2663 GNUNET_i2s (&pi[i]));
2752 GNUNET_i2s(&pi[i]));
2753 path->peers[i] = GNUNET_PEER_intern (&pi[i]); 2664 path->peers[i] = GNUNET_PEER_intern (&pi[i]);
2754 if (path->peers[i] == myid) 2665 if (path->peers[i] == myid)
2755 own_pos = i; 2666 own_pos = i;
2756 } 2667 }
2757 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2668 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Own position: %u\n", own_pos);
2758 "MESH: Own position: %u\n", own_pos);
2759 if (own_pos < path->length - 1) 2669 if (own_pos < path->length - 1)
2760 send_message (message, &pi[own_pos + 1]); 2670 send_message (message, &pi[own_pos + 1]);
2761 tunnel_delete_peer (t, path->peers[path->length - 1]); 2671 tunnel_delete_peer (t, path->peers[path->length - 1]);
@@ -2778,32 +2688,28 @@ handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
2778 */ 2688 */
2779static int 2689static int
2780handle_mesh_path_broken (void *cls, const struct GNUNET_PeerIdentity *peer, 2690handle_mesh_path_broken (void *cls, const struct GNUNET_PeerIdentity *peer,
2781 const struct GNUNET_MessageHeader *message, 2691 const struct GNUNET_MessageHeader *message,
2782 const struct GNUNET_ATS_Information *atsi, 2692 const struct GNUNET_ATS_Information *atsi,
2783 unsigned int atsi_count) 2693 unsigned int atsi_count)
2784{ 2694{
2785 struct GNUNET_MESH_PathBroken *msg; 2695 struct GNUNET_MESH_PathBroken *msg;
2786 struct MeshTunnel *t; 2696 struct MeshTunnel *t;
2787 2697
2788 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2698 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2789 "MESH: Received a PATH BROKEN msg from %s\n", 2699 "MESH: Received a PATH BROKEN msg from %s\n", GNUNET_i2s (peer));
2790 GNUNET_i2s(peer));
2791 msg = (struct GNUNET_MESH_PathBroken *) message; 2700 msg = (struct GNUNET_MESH_PathBroken *) message;
2792 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2701 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: regarding %s\n",
2793 "MESH: regarding %s\n", 2702 GNUNET_i2s (&msg->peer1));
2794 GNUNET_i2s(&msg->peer1)); 2703 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: regarding %s\n",
2795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2704 GNUNET_i2s (&msg->peer2));
2796 "MESH: regarding %s\n", 2705 t = tunnel_get (&msg->oid, ntohl (msg->tid));
2797 GNUNET_i2s(&msg->peer2));
2798 t = tunnel_get(&msg->oid, ntohl (msg->tid));
2799 if (NULL == t) 2706 if (NULL == t)
2800 { 2707 {
2801 GNUNET_break_op (0); 2708 GNUNET_break_op (0);
2802 return GNUNET_OK; 2709 return GNUNET_OK;
2803 } 2710 }
2804 tunnel_notify_connection_broken(t, 2711 tunnel_notify_connection_broken (t, GNUNET_PEER_search (&msg->peer1),
2805 GNUNET_PEER_search(&msg->peer1), 2712 GNUNET_PEER_search (&msg->peer2));
2806 GNUNET_PEER_search(&msg->peer2));
2807 return GNUNET_OK; 2713 return GNUNET_OK;
2808 2714
2809} 2715}
@@ -2825,19 +2731,16 @@ static int
2825handle_mesh_tunnel_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, 2731handle_mesh_tunnel_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
2826 const struct GNUNET_MessageHeader *message, 2732 const struct GNUNET_MessageHeader *message,
2827 const struct GNUNET_ATS_Information *atsi, 2733 const struct GNUNET_ATS_Information *atsi,
2828 unsigned int atsi_count) 2734 unsigned int atsi_count)
2829{ 2735{
2830 struct GNUNET_MESH_TunnelDestroy *msg; 2736 struct GNUNET_MESH_TunnelDestroy *msg;
2831 struct MeshTunnel *t; 2737 struct MeshTunnel *t;
2832 2738
2833 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2739 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2834 "MESH: Got a TUNNEL DESTROY packet from %s\n", 2740 "MESH: Got a TUNNEL DESTROY packet from %s\n", GNUNET_i2s (peer));
2835 GNUNET_i2s (peer));
2836 msg = (struct GNUNET_MESH_TunnelDestroy *) message; 2741 msg = (struct GNUNET_MESH_TunnelDestroy *) message;
2837 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2742 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: for tunnel %s [%u]\n",
2838 "MESH: for tunnel %s [%u]\n", 2743 GNUNET_i2s (&msg->oid), ntohl (msg->tid));
2839 GNUNET_i2s (&msg->oid),
2840 ntohl (msg->tid));
2841 t = tunnel_get (&msg->oid, ntohl (msg->tid)); 2744 t = tunnel_get (&msg->oid, ntohl (msg->tid));
2842 if (NULL == t) 2745 if (NULL == t)
2843 { 2746 {
@@ -2878,15 +2781,14 @@ static int
2878handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer, 2781handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
2879 const struct GNUNET_MessageHeader *message, 2782 const struct GNUNET_MessageHeader *message,
2880 const struct GNUNET_ATS_Information *atsi, 2783 const struct GNUNET_ATS_Information *atsi,
2881 unsigned int atsi_count) 2784 unsigned int atsi_count)
2882{ 2785{
2883 struct GNUNET_MESH_Unicast *msg; 2786 struct GNUNET_MESH_Unicast *msg;
2884 struct MeshTunnel *t; 2787 struct MeshTunnel *t;
2885 GNUNET_PEER_Id pid; 2788 GNUNET_PEER_Id pid;
2886 size_t size; 2789 size_t size;
2887 2790
2888 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2791 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: got a unicast packet from %s\n",
2889 "MESH: got a unicast packet from %s\n",
2890 GNUNET_i2s (peer)); 2792 GNUNET_i2s (peer));
2891 size = ntohs (message->size); 2793 size = ntohs (message->size);
2892 if (size < 2794 if (size <
@@ -2897,8 +2799,7 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
2897 return GNUNET_OK; 2799 return GNUNET_OK;
2898 } 2800 }
2899 msg = (struct GNUNET_MESH_Unicast *) message; 2801 msg = (struct GNUNET_MESH_Unicast *) message;
2900 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2802 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: of type %u\n",
2901 "MESH: of type %u\n",
2902 ntohs (msg[1].header.type)); 2803 ntohs (msg[1].header.type));
2903 t = tunnel_get (&msg->oid, ntohl (msg->tid)); 2804 t = tunnel_get (&msg->oid, ntohl (msg->tid));
2904 if (NULL == t) 2805 if (NULL == t)
@@ -2908,7 +2809,7 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
2908 return GNUNET_OK; 2809 return GNUNET_OK;
2909 } 2810 }
2910 tunnel_reset_timeout (t); 2811 tunnel_reset_timeout (t);
2911 pid = GNUNET_PEER_search(&msg->destination); 2812 pid = GNUNET_PEER_search (&msg->destination);
2912 if (pid == myid) 2813 if (pid == myid)
2913 { 2814 {
2914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2815 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -2918,7 +2819,7 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
2918 } 2819 }
2919 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2820 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2920 "MESH: not for us, retransmitting...\n"); 2821 "MESH: not for us, retransmitting...\n");
2921 send_message (message, path_get_first_hop(t->tree, pid)); 2822 send_message (message, path_get_first_hop (t->tree, pid));
2922 return GNUNET_OK; 2823 return GNUNET_OK;
2923} 2824}
2924 2825
@@ -2940,14 +2841,13 @@ static int
2940handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer, 2841handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer,
2941 const struct GNUNET_MessageHeader *message, 2842 const struct GNUNET_MessageHeader *message,
2942 const struct GNUNET_ATS_Information *atsi, 2843 const struct GNUNET_ATS_Information *atsi,
2943 unsigned int atsi_count) 2844 unsigned int atsi_count)
2944{ 2845{
2945 struct GNUNET_MESH_Multicast *msg; 2846 struct GNUNET_MESH_Multicast *msg;
2946 struct MeshTunnel *t; 2847 struct MeshTunnel *t;
2947 size_t size; 2848 size_t size;
2948 2849
2949 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2850 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: got a multicast packet from %s\n",
2950 "MESH: got a multicast packet from %s\n",
2951 GNUNET_i2s (peer)); 2851 GNUNET_i2s (peer));
2952 size = ntohs (message->size); 2852 size = ntohs (message->size);
2953 if (sizeof (struct GNUNET_MESH_Multicast) + 2853 if (sizeof (struct GNUNET_MESH_Multicast) +
@@ -2973,7 +2873,7 @@ handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer,
2973 { 2873 {
2974 send_subscribed_clients (message, &msg[1].header); 2874 send_subscribed_clients (message, &msg[1].header);
2975 } 2875 }
2976 tunnel_send_multicast(t, message); 2876 tunnel_send_multicast (t, message);
2977 return GNUNET_OK; 2877 return GNUNET_OK;
2978} 2878}
2979 2879
@@ -2994,7 +2894,7 @@ static int
2994handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer, 2894handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer,
2995 const struct GNUNET_MessageHeader *message, 2895 const struct GNUNET_MessageHeader *message,
2996 const struct GNUNET_ATS_Information *atsi, 2896 const struct GNUNET_ATS_Information *atsi,
2997 unsigned int atsi_count) 2897 unsigned int atsi_count)
2998{ 2898{
2999 struct GNUNET_MESH_ToOrigin *msg; 2899 struct GNUNET_MESH_ToOrigin *msg;
3000 struct GNUNET_PeerIdentity id; 2900 struct GNUNET_PeerIdentity id;
@@ -3002,8 +2902,7 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer,
3002 struct MeshTunnel *t; 2902 struct MeshTunnel *t;
3003 size_t size; 2903 size_t size;
3004 2904
3005 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2905 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: got a ToOrigin packet from %s\n",
3006 "MESH: got a ToOrigin packet from %s\n",
3007 GNUNET_i2s (peer)); 2906 GNUNET_i2s (peer));
3008 size = ntohs (message->size); 2907 size = ntohs (message->size);
3009 if (size < sizeof (struct GNUNET_MESH_ToOrigin) + /* Payload must be */ 2908 if (size < sizeof (struct GNUNET_MESH_ToOrigin) + /* Payload must be */
@@ -3013,8 +2912,7 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer,
3013 return GNUNET_OK; 2912 return GNUNET_OK;
3014 } 2913 }
3015 msg = (struct GNUNET_MESH_ToOrigin *) message; 2914 msg = (struct GNUNET_MESH_ToOrigin *) message;
3016 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2915 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: of type %u\n",
3017 "MESH: of type %u\n",
3018 ntohs (msg[1].header.type)); 2916 ntohs (msg[1].header.type));
3019 t = tunnel_get (&msg->oid, ntohl (msg->tid)); 2917 t = tunnel_get (&msg->oid, ntohl (msg->tid));
3020 2918
@@ -3035,8 +2933,7 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer,
3035 if (NULL == t->client) 2933 if (NULL == t->client)
3036 { 2934 {
3037 /* got data packet for ownerless tunnel */ 2935 /* got data packet for ownerless tunnel */
3038 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2936 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: no clients!\n");
3039 "MESH: no clients!\n");
3040 GNUNET_break_op (0); 2937 GNUNET_break_op (0);
3041 return GNUNET_OK; 2938 return GNUNET_OK;
3042 } 2939 }
@@ -3044,10 +2941,8 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer,
3044 memcpy (cbuf, message, size); 2941 memcpy (cbuf, message, size);
3045 copy = (struct GNUNET_MESH_ToOrigin *) cbuf; 2942 copy = (struct GNUNET_MESH_ToOrigin *) cbuf;
3046 copy->tid = htonl (t->local_tid); 2943 copy->tid = htonl (t->local_tid);
3047 GNUNET_SERVER_notification_context_unicast (nc, 2944 GNUNET_SERVER_notification_context_unicast (nc, t->client->handle,
3048 t->client->handle, 2945 &copy->header, GNUNET_YES);
3049 &copy->header,
3050 GNUNET_YES);
3051 return GNUNET_OK; 2946 return GNUNET_OK;
3052 } 2947 }
3053 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2948 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -3060,7 +2955,7 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer,
3060 GNUNET_break (0); 2955 GNUNET_break (0);
3061 return GNUNET_OK; 2956 return GNUNET_OK;
3062 } 2957 }
3063 GNUNET_PEER_resolve (tree_get_predecessor(t->tree), &id); 2958 GNUNET_PEER_resolve (tree_get_predecessor (t->tree), &id);
3064 send_message (message, &id); 2959 send_message (message, &id);
3065 2960
3066 return GNUNET_OK; 2961 return GNUNET_OK;
@@ -3083,16 +2978,15 @@ static int
3083handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer, 2978handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
3084 const struct GNUNET_MessageHeader *message, 2979 const struct GNUNET_MessageHeader *message,
3085 const struct GNUNET_ATS_Information *atsi, 2980 const struct GNUNET_ATS_Information *atsi,
3086 unsigned int atsi_count) 2981 unsigned int atsi_count)
3087{ 2982{
3088 struct GNUNET_MESH_PathACK *msg; 2983 struct GNUNET_MESH_PathACK *msg;
3089 struct GNUNET_PeerIdentity id; 2984 struct GNUNET_PeerIdentity id;
3090 struct MeshPeerInfo *peer_info; 2985 struct MeshPeerInfo *peer_info;
3091 struct MeshTunnel *t; 2986 struct MeshTunnel *t;
3092 2987
3093 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2988 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Received a path ACK msg [%s]\n",
3094 "MESH: Received a path ACK msg [%s]\n", 2989 GNUNET_i2s (&my_full_id));
3095 GNUNET_i2s(&my_full_id));
3096 msg = (struct GNUNET_MESH_PathACK *) message; 2990 msg = (struct GNUNET_MESH_PathACK *) message;
3097 t = tunnel_get (&msg->oid, msg->tid); 2991 t = tunnel_get (&msg->oid, msg->tid);
3098 if (NULL == t) 2992 if (NULL == t)
@@ -3116,14 +3010,14 @@ handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
3116 t->dht_get_type = NULL; 3010 t->dht_get_type = NULL;
3117 } 3011 }
3118 peer_info = peer_info_get (&msg->peer_id); 3012 peer_info = peer_info_get (&msg->peer_id);
3119 tree_set_status(t->tree, peer_info->id, MESH_PEER_READY); 3013 tree_set_status (t->tree, peer_info->id, MESH_PEER_READY);
3120 send_client_peer_connected(t, peer_info->id); 3014 send_client_peer_connected (t, peer_info->id);
3121 return GNUNET_OK; 3015 return GNUNET_OK;
3122 } 3016 }
3123 3017
3124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3018 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3125 "MESH: not for us, retransmitting...\n"); 3019 "MESH: not for us, retransmitting...\n");
3126 GNUNET_PEER_resolve(tree_get_predecessor(t->tree), &id); 3020 GNUNET_PEER_resolve (tree_get_predecessor (t->tree), &id);
3127 peer_info = peer_info_get (&msg->oid); 3021 peer_info = peer_info_get (&msg->oid);
3128 if (NULL == peer_info) 3022 if (NULL == peer_info)
3129 { 3023 {
@@ -3143,13 +3037,13 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = {
3143 {&handle_mesh_path_create, GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE, 0}, 3037 {&handle_mesh_path_create, GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE, 0},
3144 {&handle_mesh_path_destroy, GNUNET_MESSAGE_TYPE_MESH_PATH_DESTROY, 0}, 3038 {&handle_mesh_path_destroy, GNUNET_MESSAGE_TYPE_MESH_PATH_DESTROY, 0},
3145 {&handle_mesh_path_broken, GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN, 3039 {&handle_mesh_path_broken, GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN,
3146 sizeof (struct GNUNET_MESH_PathBroken)}, 3040 sizeof (struct GNUNET_MESH_PathBroken)},
3147 {&handle_mesh_tunnel_destroy, GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY, 0}, 3041 {&handle_mesh_tunnel_destroy, GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY, 0},
3148 {&handle_mesh_data_unicast, GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0}, 3042 {&handle_mesh_data_unicast, GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0},
3149 {&handle_mesh_data_multicast, GNUNET_MESSAGE_TYPE_MESH_MULTICAST, 0}, 3043 {&handle_mesh_data_multicast, GNUNET_MESSAGE_TYPE_MESH_MULTICAST, 0},
3150 {&handle_mesh_data_to_orig, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0}, 3044 {&handle_mesh_data_to_orig, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0},
3151 {&handle_mesh_path_ack, GNUNET_MESSAGE_TYPE_MESH_PATH_ACK, 3045 {&handle_mesh_path_ack, GNUNET_MESSAGE_TYPE_MESH_PATH_ACK,
3152 sizeof (struct GNUNET_MESH_PathACK)}, 3046 sizeof (struct GNUNET_MESH_PathACK)},
3153 {NULL, 0, 0} 3047 {NULL, 0, 0}
3154}; 3048};
3155 3049
@@ -3161,18 +3055,19 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = {
3161 3055
3162/** 3056/**
3163 * deregister_app: iterator for removing each application registered by a client 3057 * deregister_app: iterator for removing each application registered by a client
3164 * 3058 *
3165 * @param cls closure 3059 * @param cls closure
3166 * @param key the hash of the application id (used to access the hashmap) 3060 * @param key the hash of the application id (used to access the hashmap)
3167 * @param value the value stored at the key (client) 3061 * @param value the value stored at the key (client)
3168 * 3062 *
3169 * @return GNUNET_OK on success 3063 * @return GNUNET_OK on success
3170 */ 3064 */
3171static int 3065static int
3172deregister_app (void *cls, const GNUNET_HashCode * key, void *value) 3066deregister_app (void *cls, const GNUNET_HashCode * key, void *value)
3173{ 3067{
3174 GNUNET_break (GNUNET_YES == 3068 GNUNET_break (GNUNET_YES ==
3175 GNUNET_CONTAINER_multihashmap_remove (applications, key, value)); 3069 GNUNET_CONTAINER_multihashmap_remove (applications, key,
3070 value));
3176 return GNUNET_OK; 3071 return GNUNET_OK;
3177} 3072}
3178 3073
@@ -3230,8 +3125,9 @@ path_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3230 struct MeshTunnel *t = cls; 3125 struct MeshTunnel *t = cls;
3231 struct GNUNET_MessageHeader *payload; 3126 struct GNUNET_MessageHeader *payload;
3232 struct GNUNET_MESH_Multicast *msg; 3127 struct GNUNET_MESH_Multicast *msg;
3233 size_t size = sizeof(struct GNUNET_MESH_Multicast) + 3128 size_t size =
3234 sizeof(struct GNUNET_MessageHeader); 3129 sizeof (struct GNUNET_MESH_Multicast) +
3130 sizeof (struct GNUNET_MessageHeader);
3235 char cbuf[size]; 3131 char cbuf[size];
3236 3132
3237 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) 3133 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
@@ -3241,16 +3137,15 @@ path_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3241 t->path_refresh_task = GNUNET_SCHEDULER_NO_TASK; 3137 t->path_refresh_task = GNUNET_SCHEDULER_NO_TASK;
3242 3138
3243 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3244 "MESH: sending keepalive for tunnel %d\n", 3140 "MESH: sending keepalive for tunnel %d\n", t->id.tid);
3245 t->id.tid);
3246 3141
3247 msg = (struct GNUNET_MESH_Multicast *) cbuf; 3142 msg = (struct GNUNET_MESH_Multicast *) cbuf;
3248 msg->header.size = htons (size); 3143 msg->header.size = htons (size);
3249 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST); 3144 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST);
3250 msg->oid = my_full_id; 3145 msg->oid = my_full_id;
3251 msg->tid = htonl(t->id.tid); 3146 msg->tid = htonl (t->id.tid);
3252 payload = (struct GNUNET_MessageHeader *) &msg[1]; 3147 payload = (struct GNUNET_MessageHeader *) &msg[1];
3253 payload->size = htons (sizeof(struct GNUNET_MessageHeader)); 3148 payload->size = htons (sizeof (struct GNUNET_MessageHeader));
3254 payload->type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_KEEPALIVE); 3149 payload->type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_KEEPALIVE);
3255 tunnel_send_multicast (t, &msg->header); 3150 tunnel_send_multicast (t, &msg->header);
3256 3151
@@ -3280,30 +3175,27 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
3280 const struct GNUNET_PeerIdentity *get_path, 3175 const struct GNUNET_PeerIdentity *get_path,
3281 unsigned int get_path_length, 3176 unsigned int get_path_length,
3282 const struct GNUNET_PeerIdentity *put_path, 3177 const struct GNUNET_PeerIdentity *put_path,
3283 unsigned int put_path_length, 3178 unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
3284 enum GNUNET_BLOCK_Type type, size_t size, const void *data) 3179 size_t size, const void *data)
3285{ 3180{
3286 struct MeshPathInfo *path_info = cls; 3181 struct MeshPathInfo *path_info = cls;
3287 struct MeshPeerPath *p; 3182 struct MeshPeerPath *p;
3288 struct GNUNET_PeerIdentity pi; 3183 struct GNUNET_PeerIdentity pi;
3289 int i; 3184 int i;
3290 3185
3291 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Got results from DHT!\n");
3292 "MESH: Got results from DHT!\n");
3293 GNUNET_PEER_resolve (path_info->peer->id, &pi); 3187 GNUNET_PEER_resolve (path_info->peer->id, &pi);
3294 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: for %s\n", GNUNET_i2s (&pi));
3295 "MESH: for %s\n",
3296 GNUNET_i2s(&pi));
3297// GNUNET_DHT_get_stop(path_info->peer->dhtget); 3189// GNUNET_DHT_get_stop(path_info->peer->dhtget);
3298// path_info->peer->dhtget = NULL; 3190// path_info->peer->dhtget = NULL;
3299 3191
3300 p = path_build_from_dht (get_path, get_path_length, 3192 p = path_build_from_dht (get_path, get_path_length, put_path,
3301 put_path, put_path_length); 3193 put_path_length);
3302 peer_info_add_path (path_info->peer, p, GNUNET_NO); 3194 peer_info_add_path (path_info->peer, p, GNUNET_NO);
3303 for (i = 0; i < path_info->peer->ntunnels; i++) 3195 for (i = 0; i < path_info->peer->ntunnels; i++)
3304 { 3196 {
3305 tunnel_add_peer (path_info->peer->tunnels[i], path_info->peer); 3197 tunnel_add_peer (path_info->peer->tunnels[i], path_info->peer);
3306 peer_info_connect(path_info->peer, path_info->t); 3198 peer_info_connect (path_info->peer, path_info->t);
3307 } 3199 }
3308// GNUNET_free (path_info); 3200// GNUNET_free (path_info);
3309 3201
@@ -3327,11 +3219,10 @@ static void
3327dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp, 3219dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp,
3328 const GNUNET_HashCode * key, 3220 const GNUNET_HashCode * key,
3329 const struct GNUNET_PeerIdentity *get_path, 3221 const struct GNUNET_PeerIdentity *get_path,
3330 unsigned int get_path_length, 3222 unsigned int get_path_length,
3331 const struct GNUNET_PeerIdentity *put_path, 3223 const struct GNUNET_PeerIdentity *put_path,
3332 unsigned int put_path_length, 3224 unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
3333 enum GNUNET_BLOCK_Type type, size_t size, 3225 size_t size, const void *data)
3334 const void *data)
3335{ 3226{
3336 const struct GNUNET_PeerIdentity *pi = data; 3227 const struct GNUNET_PeerIdentity *pi = data;
3337 struct MeshTunnel *t = cls; 3228 struct MeshTunnel *t = cls;
@@ -3345,16 +3236,14 @@ dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp,
3345 } 3236 }
3346 GNUNET_assert (NULL != t->client); 3237 GNUNET_assert (NULL != t->client);
3347 peer_info = peer_info_get (pi); 3238 peer_info = peer_info_get (pi);
3348 (void) GNUNET_CONTAINER_multihashmap_put ( 3239 (void) GNUNET_CONTAINER_multihashmap_put (t->peers, &pi->hashPubKey,
3349 t->peers, 3240 peer_info,
3350 &pi->hashPubKey, 3241 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
3351 peer_info, 3242
3352 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); 3243 p = path_build_from_dht (get_path, get_path_length, put_path,
3353 3244 put_path_length);
3354 p = path_build_from_dht (get_path, get_path_length,
3355 put_path, put_path_length);
3356 peer_info_add_path (peer_info, p, GNUNET_NO); 3245 peer_info_add_path (peer_info, p, GNUNET_NO);
3357 tunnel_add_peer(t, peer_info); 3246 tunnel_add_peer (t, peer_info);
3358 peer_info_connect (peer_info, t); 3247 peer_info_connect (peer_info, t);
3359} 3248}
3360 3249
@@ -3397,8 +3286,7 @@ handle_local_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
3397 if (NULL != c->tunnels) 3286 if (NULL != c->tunnels)
3398 { 3287 {
3399 GNUNET_CONTAINER_multihashmap_iterate (c->tunnels, 3288 GNUNET_CONTAINER_multihashmap_iterate (c->tunnels,
3400 &tunnel_destroy_iterator, 3289 &tunnel_destroy_iterator, c);
3401 c);
3402 GNUNET_CONTAINER_multihashmap_destroy (c->tunnels); 3290 GNUNET_CONTAINER_multihashmap_destroy (c->tunnels);
3403 } 3291 }
3404 3292
@@ -3467,7 +3355,8 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client,
3467#if MESH_DEBUG 3355#if MESH_DEBUG
3468 c->id = next_client_id++; 3356 c->id = next_client_id++;
3469#endif 3357#endif
3470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: CLIENT NEW %u at %p\n", c->id, c); 3358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: CLIENT NEW %u at %p\n", c->id,
3359 c);
3471 c->handle = client; 3360 c->handle = client;
3472 GNUNET_SERVER_client_keep (client); 3361 GNUNET_SERVER_client_keep (client);
3473 a = (GNUNET_MESH_ApplicationType *) &cc_msg[1]; 3362 a = (GNUNET_MESH_ApplicationType *) &cc_msg[1];
@@ -3589,20 +3478,16 @@ handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client,
3589 t->id.oid = myid; 3478 t->id.oid = myid;
3590 t->local_tid = ntohl (t_msg->tunnel_id); 3479 t->local_tid = ntohl (t_msg->tunnel_id);
3591#if MESH_DEBUG 3480#if MESH_DEBUG
3592 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3481 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: CREATED TUNNEL %s [%x] (%x)\n",
3593 "MESH: CREATED TUNNEL %s [%x] (%x)\n", 3482 GNUNET_i2s (&my_full_id), t->id.tid, t->local_tid);
3594 GNUNET_i2s (&my_full_id),
3595 t->id.tid,
3596 t->local_tid);
3597#endif 3483#endif
3598 t->client = c; 3484 t->client = c;
3599 t->peers = GNUNET_CONTAINER_multihashmap_create (32); 3485 t->peers = GNUNET_CONTAINER_multihashmap_create (32);
3600 3486
3601 GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash); 3487 GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash);
3602 if (GNUNET_OK != 3488 if (GNUNET_OK !=
3603 GNUNET_CONTAINER_multihashmap_put ( 3489 GNUNET_CONTAINER_multihashmap_put (c->tunnels, &hash, t,
3604 c->tunnels, &hash, t, 3490 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
3605 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
3606 { 3491 {
3607 GNUNET_break (0); 3492 GNUNET_break (0);
3608 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 3493 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -3611,16 +3496,15 @@ handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client,
3611 3496
3612 GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); 3497 GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash);
3613 if (GNUNET_OK != 3498 if (GNUNET_OK !=
3614 GNUNET_CONTAINER_multihashmap_put ( 3499 GNUNET_CONTAINER_multihashmap_put (tunnels, &hash, t,
3615 tunnels, &hash, t, 3500 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
3616 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
3617 { 3501 {
3618 GNUNET_break (0); 3502 GNUNET_break (0);
3619 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 3503 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3620 return; 3504 return;
3621 } 3505 }
3622 t->tree = tree_new (myid); 3506 t->tree = tree_new (myid);
3623 tree_set_me(t->tree, myid); 3507 tree_set_me (t->tree, myid);
3624 3508
3625 GNUNET_SERVER_receive_done (client, GNUNET_OK); 3509 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3626 return; 3510 return;
@@ -3673,11 +3557,11 @@ handle_local_tunnel_destroy (void *cls, struct GNUNET_SERVER_Client *client,
3673 GNUNET_CRYPTO_hash (&tid, sizeof (MESH_TunnelNumber), &hash); 3557 GNUNET_CRYPTO_hash (&tid, sizeof (MESH_TunnelNumber), &hash);
3674 t = GNUNET_CONTAINER_multihashmap_get (c->tunnels, &hash); 3558 t = GNUNET_CONTAINER_multihashmap_get (c->tunnels, &hash);
3675 GNUNET_assert (GNUNET_YES == 3559 GNUNET_assert (GNUNET_YES ==
3676 GNUNET_CONTAINER_multihashmap_remove (c->tunnels, &hash, t)); 3560 GNUNET_CONTAINER_multihashmap_remove (c->tunnels, &hash, t));
3677 3561
3678 t->client = NULL; 3562 t->client = NULL;
3679 tunnel_send_destroy (t); 3563 tunnel_send_destroy (t);
3680 tunnel_destroy(t); 3564 tunnel_destroy (t);
3681 GNUNET_SERVER_receive_done (client, GNUNET_OK); 3565 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3682 return; 3566 return;
3683} 3567}
@@ -3700,7 +3584,7 @@ handle_local_connect_add (void *cls, struct GNUNET_SERVER_Client *client,
3700 struct MeshTunnel *t; 3584 struct MeshTunnel *t;
3701 MESH_TunnelNumber tid; 3585 MESH_TunnelNumber tid;
3702 3586
3703 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: Got connection request\n"); 3587 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Got connection request\n");
3704 /* Sanity check for client registration */ 3588 /* Sanity check for client registration */
3705 if (NULL == (c = client_get (client))) 3589 if (NULL == (c = client_get (client)))
3706 { 3590 {
@@ -3735,12 +3619,12 @@ handle_local_connect_add (void *cls, struct GNUNET_SERVER_Client *client,
3735 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 3619 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3736 return; 3620 return;
3737 } 3621 }
3738 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: for %s\n", 3622 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: for %s\n",
3739 GNUNET_i2s(&peer_msg->peer)); 3623 GNUNET_i2s (&peer_msg->peer));
3740 peer_info = peer_info_get (&peer_msg->peer); 3624 peer_info = peer_info_get (&peer_msg->peer);
3741 3625
3742 tunnel_add_peer(t, peer_info); 3626 tunnel_add_peer (t, peer_info);
3743 peer_info_connect(peer_info, t); 3627 peer_info_connect (peer_info, t);
3744 3628
3745 GNUNET_SERVER_receive_done (client, GNUNET_OK); 3629 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3746 return; 3630 return;
@@ -3800,12 +3684,11 @@ handle_local_connect_del (void *cls, struct GNUNET_SERVER_Client *client,
3800 return; 3684 return;
3801 } 3685 }
3802 3686
3803 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: for peer %s\n",
3804 "MESH: for peer %s\n", 3688 GNUNET_i2s (&peer_msg->peer));
3805 GNUNET_i2s(&peer_msg->peer));
3806 /* Is the peer in the tunnel? */ 3689 /* Is the peer in the tunnel? */
3807 peer_info = GNUNET_CONTAINER_multihashmap_get(t->peers, 3690 peer_info =
3808 &peer_msg->peer.hashPubKey); 3691 GNUNET_CONTAINER_multihashmap_get (t->peers, &peer_msg->peer.hashPubKey);
3809 if (NULL == peer_info) 3692 if (NULL == peer_info)
3810 { 3693 {
3811 GNUNET_break (0); 3694 GNUNET_break (0);
@@ -3818,7 +3701,7 @@ handle_local_connect_del (void *cls, struct GNUNET_SERVER_Client *client,
3818 &peer_msg->peer.hashPubKey); 3701 &peer_msg->peer.hashPubKey);
3819 3702
3820 send_destroy_path (t, peer_info->id); 3703 send_destroy_path (t, peer_info->id);
3821 tunnel_delete_peer(t, peer_info->id); 3704 tunnel_delete_peer (t, peer_info->id);
3822 GNUNET_SERVER_receive_done (client, GNUNET_OK); 3705 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3823 return; 3706 return;
3824} 3707}
@@ -3894,7 +3777,7 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client,
3894 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 3777 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
3895 3778
3896 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: notifying client\n"); 3779 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: notifying client\n");
3897 send_client_peer_connected(t, myid); 3780 send_client_peer_connected (t, myid);
3898 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Done\n"); 3781 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Done\n");
3899 GNUNET_SERVER_receive_done (client, GNUNET_OK); 3782 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3900 return; 3783 return;
@@ -3907,14 +3790,10 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client,
3907 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: looking in DHT for %s\n", 3790 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: looking in DHT for %s\n",
3908 GNUNET_h2s (&hash)); 3791 GNUNET_h2s (&hash));
3909 t->dht_get_type = 3792 t->dht_get_type =
3910 GNUNET_DHT_get_start (dht_handle, 3793 GNUNET_DHT_get_start (dht_handle, GNUNET_TIME_UNIT_FOREVER_REL,
3911 GNUNET_TIME_UNIT_FOREVER_REL, 3794 GNUNET_BLOCK_TYPE_TEST, &hash, 10U,
3912 GNUNET_BLOCK_TYPE_TEST,
3913 &hash,
3914 10U,
3915 GNUNET_DHT_RO_RECORD_ROUTE | 3795 GNUNET_DHT_RO_RECORD_ROUTE |
3916 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 3796 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, 0,
3917 NULL, 0,
3918 &dht_get_type_handler, t); 3797 &dht_get_type_handler, t);
3919 3798
3920 GNUNET_SERVER_receive_done (client, GNUNET_OK); 3799 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -3972,8 +3851,7 @@ handle_local_unicast (void *cls, struct GNUNET_SERVER_Client *client,
3972 } 3851 }
3973 3852
3974 /* Is it a local tunnel? Then, does client own the tunnel? */ 3853 /* Is it a local tunnel? Then, does client own the tunnel? */
3975 if (NULL != t->client && 3854 if (NULL != t->client && NULL != t->client->handle &&
3976 NULL != t->client->handle &&
3977 t->client->handle != client) 3855 t->client->handle != client)
3978 { 3856 {
3979 GNUNET_break (0); 3857 GNUNET_break (0);
@@ -4074,7 +3952,7 @@ handle_local_to_origin (void *cls, struct GNUNET_SERVER_Client *client,
4074 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 3952 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
4075 return; 3953 return;
4076 } 3954 }
4077 GNUNET_PEER_resolve(t->id.oid, &id); 3955 GNUNET_PEER_resolve (t->id.oid, &id);
4078 3956
4079 /* Ok, everything is correct, send the message 3957 /* Ok, everything is correct, send the message
4080 * (pretend we got it from a mesh peer) 3958 * (pretend we got it from a mesh peer)
@@ -4153,16 +4031,16 @@ handle_local_multicast (void *cls, struct GNUNET_SERVER_Client *client,
4153 } 4031 }
4154 4032
4155 { 4033 {
4156 char buf[ntohs(message->size)]; 4034 char buf[ntohs (message->size)];
4157 struct GNUNET_MESH_Multicast *copy; 4035 struct GNUNET_MESH_Multicast *copy;
4158 4036
4159 copy = (struct GNUNET_MESH_Multicast *)buf; 4037 copy = (struct GNUNET_MESH_Multicast *) buf;
4160 memcpy(buf, message, ntohs(message->size)); 4038 memcpy (buf, message, ntohs (message->size));
4161 copy->oid = my_full_id; 4039 copy->oid = my_full_id;
4162 copy->tid = htonl(t->id.tid); 4040 copy->tid = htonl (t->id.tid);
4163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4041 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4164 "MESH: calling generic handler...\n"); 4042 "MESH: calling generic handler...\n");
4165 handle_mesh_data_multicast(client, &my_full_id, &copy->header, NULL, 0); 4043 handle_mesh_data_multicast (client, &my_full_id, &copy->header, NULL, 0);
4166 } 4044 }
4167 4045
4168 /* receive done gets called when last copy is sent to a neighbor */ 4046 /* receive done gets called when last copy is sent to a neighbor */
@@ -4213,10 +4091,11 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server,
4213{ 4091{
4214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Core init\n"); 4092 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Core init\n");
4215 core_handle = server; 4093 core_handle = server;
4216 if (0 != memcmp(identity, &my_full_id, sizeof(my_full_id)) || NULL == server) 4094 if (0 != memcmp (identity, &my_full_id, sizeof (my_full_id)) ||
4095 NULL == server)
4217 { 4096 {
4218 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("MESH: Wrong CORE service\n")); 4097 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("MESH: Wrong CORE service\n"));
4219 GNUNET_SCHEDULER_shutdown(); 4098 GNUNET_SCHEDULER_shutdown ();
4220 } 4099 }
4221 return; 4100 return;
4222} 4101}
@@ -4240,7 +4119,7 @@ core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
4240#if MESH_DEBUG_CONNECTION 4119#if MESH_DEBUG_CONNECTION
4241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Peer connected\n"); 4120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Peer connected\n");
4242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n", 4121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n",
4243 GNUNET_i2s(&my_full_id)); 4122 GNUNET_i2s (&my_full_id));
4244#endif 4123#endif
4245 peer_info = peer_info_get (peer); 4124 peer_info = peer_info_get (peer);
4246 if (myid == peer_info->id) 4125 if (myid == peer_info->id)
@@ -4253,15 +4132,14 @@ core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
4253#if MESH_DEBUG_CONNECTION 4132#if MESH_DEBUG_CONNECTION
4254 else 4133 else
4255 { 4134 {
4256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n", 4135 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n", GNUNET_i2s (peer));
4257 GNUNET_i2s(peer));
4258 } 4136 }
4259#endif 4137#endif
4260 path = path_new (2); 4138 path = path_new (2);
4261 path->peers[0] = myid; 4139 path->peers[0] = myid;
4262 path->peers[1] = peer_info->id; 4140 path->peers[1] = peer_info->id;
4263 GNUNET_PEER_change_rc(myid, 1); 4141 GNUNET_PEER_change_rc (myid, 1);
4264 GNUNET_PEER_change_rc(peer_info->id, 1); 4142 GNUNET_PEER_change_rc (peer_info->id, 1);
4265 peer_info_add_path (peer_info, path, GNUNET_YES); 4143 peer_info_add_path (peer_info, path, GNUNET_YES);
4266 return; 4144 return;
4267} 4145}
@@ -4290,7 +4168,7 @@ core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
4290 for (i = 0; i < CORE_QUEUE_SIZE; i++) 4168 for (i = 0; i < CORE_QUEUE_SIZE; i++)
4291 { 4169 {
4292 /* TODO: notify that the transmission failed */ 4170 /* TODO: notify that the transmission failed */
4293 peer_info_cancel_transmission(pi, i); 4171 peer_info_cancel_transmission (pi, i);
4294 } 4172 }
4295 peer_info_remove_path (pi, pi->id, myid); 4173 peer_info_remove_path (pi, pi->id, myid);
4296#if MESH_DEBUG_CONNECTION 4174#if MESH_DEBUG_CONNECTION
@@ -4320,7 +4198,8 @@ static int
4320shutdown_tunnel (void *cls, const GNUNET_HashCode * key, void *value) 4198shutdown_tunnel (void *cls, const GNUNET_HashCode * key, void *value)
4321{ 4199{
4322 struct MeshTunnel *t = value; 4200 struct MeshTunnel *t = value;
4323 tunnel_destroy(t); 4201
4202 tunnel_destroy (t);
4324 return GNUNET_YES; 4203 return GNUNET_YES;
4325} 4204}
4326 4205
@@ -4337,6 +4216,7 @@ static int
4337shutdown_peer (void *cls, const GNUNET_HashCode * key, void *value) 4216shutdown_peer (void *cls, const GNUNET_HashCode * key, void *value)
4338{ 4217{
4339 struct MeshPeerInfo *p = value; 4218 struct MeshPeerInfo *p = value;
4219
4340 peer_info_destroy (p); 4220 peer_info_destroy (p);
4341 return GNUNET_YES; 4221 return GNUNET_YES;
4342} 4222}
@@ -4357,8 +4237,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
4357 GNUNET_CORE_disconnect (core_handle); 4237 GNUNET_CORE_disconnect (core_handle);
4358 core_handle = NULL; 4238 core_handle = NULL;
4359 } 4239 }
4360 GNUNET_CONTAINER_multihashmap_iterate(tunnels, &shutdown_tunnel, NULL); 4240 GNUNET_CONTAINER_multihashmap_iterate (tunnels, &shutdown_tunnel, NULL);
4361 GNUNET_CONTAINER_multihashmap_iterate(peers, &shutdown_peer, NULL); 4241 GNUNET_CONTAINER_multihashmap_iterate (peers, &shutdown_peer, NULL);
4362 if (dht_handle != NULL) 4242 if (dht_handle != NULL)
4363 { 4243 {
4364 GNUNET_DHT_disconnect (dht_handle); 4244 GNUNET_DHT_disconnect (dht_handle);
@@ -4414,8 +4294,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
4414 } 4294 }
4415 4295
4416 if (GNUNET_OK != 4296 if (GNUNET_OK !=
4417 GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY", 4297 GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY",
4418 &keyfile)) 4298 &keyfile))
4419 { 4299 {
4420 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 4300 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
4421 _ 4301 _
@@ -4463,8 +4343,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
4463 nc = GNUNET_SERVER_notification_context_create (server_handle, 4343 nc = GNUNET_SERVER_notification_context_create (server_handle,
4464 LOCAL_QUEUE_SIZE); 4344 LOCAL_QUEUE_SIZE);
4465 GNUNET_SERVER_disconnect_notify (server_handle, 4345 GNUNET_SERVER_disconnect_notify (server_handle,
4466 &handle_local_client_disconnect, 4346 &handle_local_client_disconnect, NULL);
4467 NULL);
4468 4347
4469 4348
4470 clients = NULL; 4349 clients = NULL;
@@ -4477,11 +4356,11 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
4477 announce_id_task = GNUNET_SCHEDULER_add_now (&announce_id, cls); 4356 announce_id_task = GNUNET_SCHEDULER_add_now (&announce_id, cls);
4478 4357
4479 /* Create a peer_info for the local peer */ 4358 /* Create a peer_info for the local peer */
4480 peer = peer_info_get(&my_full_id); 4359 peer = peer_info_get (&my_full_id);
4481 p = path_new (1); 4360 p = path_new (1);
4482 p->peers[0] = myid; 4361 p->peers[0] = myid;
4483 GNUNET_PEER_change_rc (myid, 1); 4362 GNUNET_PEER_change_rc (myid, 1);
4484 peer_info_add_path(peer, p, GNUNET_YES); 4363 peer_info_add_path (peer, p, GNUNET_YES);
4485 4364
4486 /* Scheduled the task to clean up when shutdown is called */ 4365 /* Scheduled the task to clean up when shutdown is called */
4487 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, 4366 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c
index 33cb41179..35bbab3a1 100644
--- a/src/mesh/mesh_api.c
+++ b/src/mesh/mesh_api.c
@@ -903,10 +903,8 @@ process_incoming_data (struct GNUNET_MESH_Handle *h,
903 t = retrieve_tunnel (h, ntohl (ucast->tid)); 903 t = retrieve_tunnel (h, ntohl (ucast->tid));
904 payload = (struct GNUNET_MessageHeader *) &ucast[1]; 904 payload = (struct GNUNET_MessageHeader *) &ucast[1];
905 peer = &ucast->oid; 905 peer = &ucast->oid;
906 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 906 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: on tunnel %s [%x]\n",
907 "mesh: on tunnel %s [%x]\n", 907 GNUNET_i2s (peer), ntohl (ucast->tid));
908 GNUNET_i2s (peer),
909 ntohl (ucast->tid));
910 break; 908 break;
911 case GNUNET_MESSAGE_TYPE_MESH_MULTICAST: 909 case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
912 mcast = (struct GNUNET_MESH_Multicast *) message; 910 mcast = (struct GNUNET_MESH_Multicast *) message;
@@ -1053,11 +1051,9 @@ send_callback (void *cls, size_t size, void *buf)
1053 1051
1054 GNUNET_assert (size >= th->size); 1052 GNUNET_assert (size >= th->size);
1055 mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (to)]; 1053 mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (to)];
1056 psize = 1054 psize = th->notify (th->notify_cls, size - sizeof (to), mh);
1057 th->notify (th->notify_cls, size - sizeof (to), mh); 1055 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: to origin, type %u\n",
1058 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1056 ntohs (mh->type));
1059 "mesh: to origin, type %u\n",
1060 ntohs (mh->type));
1061 if (psize > 0) 1057 if (psize > 0)
1062 { 1058 {
1063 psize += sizeof (to); 1059 psize += sizeof (to);
@@ -1078,10 +1074,8 @@ send_callback (void *cls, size_t size, void *buf)
1078 1074
1079 GNUNET_assert (size >= th->size); 1075 GNUNET_assert (size >= th->size);
1080 mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (mc)]; 1076 mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (mc)];
1081 psize = 1077 psize = th->notify (th->notify_cls, size - sizeof (mc), mh);
1082 th->notify (th->notify_cls, size - sizeof (mc), mh); 1078 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: multicast, type %u\n",
1083 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1084 "mesh: multicast, type %u\n",
1085 ntohs (mh->type)); 1079 ntohs (mh->type));
1086 if (psize > 0) 1080 if (psize > 0)
1087 { 1081 {
@@ -1102,11 +1096,9 @@ send_callback (void *cls, size_t size, void *buf)
1102 1096
1103 GNUNET_assert (size >= th->size); 1097 GNUNET_assert (size >= th->size);
1104 mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (uc)]; 1098 mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (uc)];
1105 psize = 1099 psize = th->notify (th->notify_cls, size - sizeof (uc), mh);
1106 th->notify (th->notify_cls, size - sizeof (uc), mh); 1100 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: unicast, type %u\n",
1107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1101 ntohs (mh->type));
1108 "mesh: unicast, type %u\n",
1109 ntohs (mh->type));
1110 if (psize > 0) 1102 if (psize > 0)
1111 { 1103 {
1112 psize += sizeof (uc); 1104 psize += sizeof (uc);
@@ -1482,12 +1474,10 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork,
1482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1474 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1483 "mesh: mesh notify transmit ready called\n"); 1475 "mesh: mesh notify transmit ready called\n");
1484 if (NULL != target) 1476 if (NULL != target)
1485 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1477 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: target %s\n",
1486 "mesh: target %s\n",
1487 GNUNET_i2s (target)); 1478 GNUNET_i2s (target));
1488 else 1479 else
1489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1480 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: target multicast\n");
1490 "mesh: target multicast\n");
1491#endif 1481#endif
1492 GNUNET_assert (NULL != notify); 1482 GNUNET_assert (NULL != notify);
1493 if (tunnel->mesh->npackets >= tunnel->mesh->max_queue_size && 1483 if (tunnel->mesh->npackets >= tunnel->mesh->max_queue_size &&
@@ -1541,11 +1531,9 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork,
1541 if (NULL != tunnel->mesh->th) 1531 if (NULL != tunnel->mesh->th)
1542 return th; 1532 return th;
1543 tunnel->mesh->th = 1533 tunnel->mesh->th =
1544 GNUNET_CLIENT_notify_transmit_ready (tunnel->mesh->client, 1534 GNUNET_CLIENT_notify_transmit_ready (tunnel->mesh->client, th->size,
1545 th->size,
1546 GNUNET_TIME_UNIT_FOREVER_REL, 1535 GNUNET_TIME_UNIT_FOREVER_REL,
1547 GNUNET_YES, 1536 GNUNET_YES, &send_callback,
1548 &send_callback,
1549 tunnel->mesh); 1537 tunnel->mesh);
1550 return th; 1538 return th;
1551} 1539}
diff --git a/src/mesh/mesh_protocol.h b/src/mesh/mesh_protocol.h
index e16f32093..180ba453f 100644
--- a/src/mesh/mesh_protocol.h
+++ b/src/mesh/mesh_protocol.h
@@ -206,7 +206,7 @@ struct GNUNET_MESH_PathBroken
206 * ID of the endpoint 206 * ID of the endpoint
207 */ 207 */
208 struct GNUNET_PeerIdentity peer1; 208 struct GNUNET_PeerIdentity peer1;
209 209
210 /** 210 /**
211 * ID of the endpoint 211 * ID of the endpoint
212 */ 212 */
diff --git a/src/mesh/mesh_tunnel_tree.c b/src/mesh/mesh_tunnel_tree.c
index 332a022c1..cfe6a46a8 100644
--- a/src/mesh/mesh_tunnel_tree.c
+++ b/src/mesh/mesh_tunnel_tree.c
@@ -119,11 +119,11 @@ path_new (unsigned int length)
119{ 119{
120 struct MeshPeerPath *p; 120 struct MeshPeerPath *p;
121 121
122 p = GNUNET_malloc (sizeof(struct MeshPeerPath)); 122 p = GNUNET_malloc (sizeof (struct MeshPeerPath));
123 if (length > 0) 123 if (length > 0)
124 { 124 {
125 p->length = length; 125 p->length = length;
126 p->peers = GNUNET_malloc (length * sizeof(GNUNET_PEER_Id)); 126 p->peers = GNUNET_malloc (length * sizeof (GNUNET_PEER_Id));
127 } 127 }
128 return p; 128 return p;
129} 129}
@@ -160,10 +160,10 @@ path_duplicate (struct MeshPeerPath *path)
160 struct MeshPeerPath *aux; 160 struct MeshPeerPath *aux;
161 unsigned int i; 161 unsigned int i;
162 162
163 aux = path_new(path->length); 163 aux = path_new (path->length);
164 memcpy (aux->peers, path->peers, path->length * sizeof(GNUNET_PEER_Id)); 164 memcpy (aux->peers, path->peers, path->length * sizeof (GNUNET_PEER_Id));
165 for (i = 0; i < path->length; i++) 165 for (i = 0; i < path->length; i++)
166 GNUNET_PEER_change_rc(path->peers[i], 1); 166 GNUNET_PEER_change_rc (path->peers[i], 1);
167 return aux; 167 return aux;
168} 168}
169 169
@@ -202,18 +202,17 @@ path_get_first_hop (struct MeshTunnelTree *t, GNUNET_PEER_Id peer)
202 { 202 {
203 struct MeshTunnelTreeNode *n; 203 struct MeshTunnelTreeNode *n;
204 204
205 n = tree_find_peer(t, peer); 205 n = tree_find_peer (t, peer);
206 if (NULL != t->me && NULL != n) 206 if (NULL != t->me && NULL != n)
207 { 207 {
208 tree_node_update_first_hops(t, n, NULL); 208 tree_node_update_first_hops (t, n, NULL);
209 r = GNUNET_CONTAINER_multihashmap_get (t->first_hops, &id.hashPubKey); 209 r = GNUNET_CONTAINER_multihashmap_get (t->first_hops, &id.hashPubKey);
210 GNUNET_assert (NULL != r); 210 GNUNET_assert (NULL != r);
211 } 211 }
212 else 212 else
213 { 213 {
214 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 214 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
215 "Tree structure inconsistent! me: %p, n: %p", 215 "Tree structure inconsistent! me: %p, n: %p", t->me, n);
216 t->me, n);
217 GNUNET_break (0); 216 GNUNET_break (0);
218 } 217 }
219 } 218 }
@@ -287,18 +286,17 @@ path_destroy (struct MeshPeerPath *p)
287 * @return Newly allocated node 286 * @return Newly allocated node
288 */ 287 */
289static struct MeshTunnelTreeNode * 288static struct MeshTunnelTreeNode *
290tree_node_new(struct MeshTunnelTreeNode *parent, GNUNET_PEER_Id peer) 289tree_node_new (struct MeshTunnelTreeNode *parent, GNUNET_PEER_Id peer)
291{ 290{
292 struct MeshTunnelTreeNode *node; 291 struct MeshTunnelTreeNode *node;
293 292
294 node = GNUNET_malloc(sizeof(struct MeshTunnelTreeNode)); 293 node = GNUNET_malloc (sizeof (struct MeshTunnelTreeNode));
295 node->peer = peer; 294 node->peer = peer;
296 GNUNET_PEER_change_rc(peer, 1); 295 GNUNET_PEER_change_rc (peer, 1);
297 node->parent = parent; 296 node->parent = parent;
298 if (NULL != parent) 297 if (NULL != parent)
299 GNUNET_CONTAINER_DLL_insert(parent->children_head, 298 GNUNET_CONTAINER_DLL_insert (parent->children_head, parent->children_tail,
300 parent->children_tail, 299 node);
301 node);
302 300
303 return node; 301 return node;
304} 302}
@@ -313,8 +311,7 @@ tree_node_new(struct MeshTunnelTreeNode *parent, GNUNET_PEER_Id peer)
313 * @return Pointer to the node of the peer. NULL if not found. 311 * @return Pointer to the node of the peer. NULL if not found.
314 */ 312 */
315static struct MeshTunnelTreeNode * 313static struct MeshTunnelTreeNode *
316tree_node_find_peer (struct MeshTunnelTreeNode *parent, 314tree_node_find_peer (struct MeshTunnelTreeNode *parent, GNUNET_PEER_Id peer_id)
317 GNUNET_PEER_Id peer_id)
318{ 315{
319 struct MeshTunnelTreeNode *n; 316 struct MeshTunnelTreeNode *n;
320 struct MeshTunnelTreeNode *r; 317 struct MeshTunnelTreeNode *r;
@@ -350,10 +347,9 @@ tree_node_update_first_hops (struct MeshTunnelTree *tree,
350 struct MeshTunnelTreeNode *n; 347 struct MeshTunnelTreeNode *n;
351 348
352#if MESH_TREE_DEBUG 349#if MESH_TREE_DEBUG
353 GNUNET_PEER_resolve(parent->peer, &id); 350 GNUNET_PEER_resolve (parent->peer, &id);
354 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 351 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Finding first hop for %s.\n",
355 "tree: Finding first hop for %s.\n", 352 GNUNET_i2s (&id));
356 GNUNET_i2s (&id));
357#endif 353#endif
358 if (NULL == hop) 354 if (NULL == hop)
359 { 355 {
@@ -364,35 +360,31 @@ tree_node_update_first_hops (struct MeshTunnelTree *tree,
364 while (aux != tree->me) 360 while (aux != tree->me)
365 { 361 {
366#if MESH_TREE_DEBUG 362#if MESH_TREE_DEBUG
367 GNUNET_PEER_resolve(old->peer, &id); 363 GNUNET_PEER_resolve (old->peer, &id);
368 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: ... its not %s.\n",
369 "tree: ... its not %s.\n", 365 GNUNET_i2s (&id));
370 GNUNET_i2s (&id));
371#endif 366#endif
372 old = aux; 367 old = aux;
373 aux = aux->parent; 368 aux = aux->parent;
374 GNUNET_assert(NULL != aux); 369 GNUNET_assert (NULL != aux);
375 } 370 }
376#if MESH_TREE_DEBUG 371#if MESH_TREE_DEBUG
377 GNUNET_PEER_resolve(old->peer, &id); 372 GNUNET_PEER_resolve (old->peer, &id);
378 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 373 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: It's %s!\n",
379 "tree: It's %s!\n", 374 GNUNET_i2s (&id));
380 GNUNET_i2s (&id));
381#endif 375#endif
382 hop = &pi; 376 hop = &pi;
383 GNUNET_PEER_resolve(old->peer, hop); 377 GNUNET_PEER_resolve (old->peer, hop);
384 } 378 }
385 GNUNET_PEER_resolve(parent->peer, &id); 379 GNUNET_PEER_resolve (parent->peer, &id);
386 copy = GNUNET_CONTAINER_multihashmap_get (tree->first_hops, &id.hashPubKey); 380 copy = GNUNET_CONTAINER_multihashmap_get (tree->first_hops, &id.hashPubKey);
387 if (NULL == copy) 381 if (NULL == copy)
388 copy = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); 382 copy = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
389 *copy = *hop; 383 *copy = *hop;
390 384
391 (void) GNUNET_CONTAINER_multihashmap_put( 385 (void) GNUNET_CONTAINER_multihashmap_put (tree->first_hops, &id.hashPubKey,
392 tree->first_hops, 386 copy,
393 &id.hashPubKey, 387 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
394 copy,
395 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
396 388
397 for (n = parent->children_head; NULL != n; n = n->next) 389 for (n = parent->children_head; NULL != n; n = n->next)
398 { 390 {
@@ -402,34 +394,34 @@ tree_node_update_first_hops (struct MeshTunnelTree *tree,
402 394
403 395
404static void 396static void
405tree_node_debug(struct MeshTunnelTreeNode *n, uint16_t level) 397tree_node_debug (struct MeshTunnelTreeNode *n, uint16_t level)
406{ 398{
407 struct MeshTunnelTreeNode *c; 399 struct MeshTunnelTreeNode *c;
408 struct GNUNET_PeerIdentity id;; 400 struct GNUNET_PeerIdentity id;;
409 uint16_t i; 401 uint16_t i;
410 402
411 for (i = 0; i < level; i++) 403 for (i = 0; i < level; i++)
412 fprintf(stderr, " "); 404 fprintf (stderr, " ");
413 if (n->status == MESH_PEER_READY) 405 if (n->status == MESH_PEER_READY)
414 fprintf(stderr, "#"); 406 fprintf (stderr, "#");
415 if (n->status == MESH_PEER_SEARCHING) 407 if (n->status == MESH_PEER_SEARCHING)
416 fprintf(stderr, "+"); 408 fprintf (stderr, "+");
417 if (n->status == MESH_PEER_RELAY) 409 if (n->status == MESH_PEER_RELAY)
418 fprintf(stderr, "-"); 410 fprintf (stderr, "-");
419 if (n->status == MESH_PEER_RECONNECTING) 411 if (n->status == MESH_PEER_RECONNECTING)
420 fprintf(stderr, "*"); 412 fprintf (stderr, "*");
421 413
422 GNUNET_PEER_resolve(n->peer, &id); 414 GNUNET_PEER_resolve (n->peer, &id);
423 fprintf(stderr, "%s, [%u, %p] ", GNUNET_i2s (&id), n->peer, n); 415 fprintf (stderr, "%s, [%u, %p] ", GNUNET_i2s (&id), n->peer, n);
424 if (NULL != n->parent) 416 if (NULL != n->parent)
425 { 417 {
426 GNUNET_PEER_resolve(n->parent->peer, &id); 418 GNUNET_PEER_resolve (n->parent->peer, &id);
427 fprintf(stderr, "(-> %s [%u])\n", GNUNET_i2s(&id), n->parent->peer); 419 fprintf (stderr, "(-> %s [%u])\n", GNUNET_i2s (&id), n->parent->peer);
428 } 420 }
429 else 421 else
430 fprintf(stderr, "(root)\n"); 422 fprintf (stderr, "(root)\n");
431 for (c = n->children_head; NULL != c; c = c->next) 423 for (c = n->children_head; NULL != c; c = c->next)
432 tree_node_debug(c, level + 1); 424 tree_node_debug (c, level + 1);
433} 425}
434 426
435 427
@@ -443,30 +435,27 @@ tree_node_destroy (struct MeshTunnelTreeNode *parent)
443{ 435{
444 struct MeshTunnelTreeNode *n; 436 struct MeshTunnelTreeNode *n;
445 struct MeshTunnelTreeNode *next; 437 struct MeshTunnelTreeNode *next;
438
446#if MESH_TREE_DEBUG 439#if MESH_TREE_DEBUG
447 struct GNUNET_PeerIdentity id; 440 struct GNUNET_PeerIdentity id;
448 441
449 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 442 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Destroying node %u\n",
450 "tree: Destroying node %u\n",
451 parent->peer); 443 parent->peer);
452 GNUNET_PEER_resolve (parent->peer, &id); 444 GNUNET_PEER_resolve (parent->peer, &id);
453 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 445 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: (%s)\n", GNUNET_i2s (&id));
454 "tree: (%s)\n",
455 GNUNET_i2s (&id));
456#endif 446#endif
457 n = parent->children_head; 447 n = parent->children_head;
458 while (NULL != n) 448 while (NULL != n)
459 { 449 {
460 next = n->next; 450 next = n->next;
461 tree_node_destroy(n); 451 tree_node_destroy (n);
462 n = next; 452 n = next;
463 } 453 }
464 GNUNET_PEER_change_rc(parent->peer, -1); 454 GNUNET_PEER_change_rc (parent->peer, -1);
465 if (NULL != parent->parent) 455 if (NULL != parent->parent)
466 GNUNET_CONTAINER_DLL_remove(parent->parent->children_head, 456 GNUNET_CONTAINER_DLL_remove (parent->parent->children_head,
467 parent->parent->children_tail, 457 parent->parent->children_tail, parent);
468 parent); 458 GNUNET_free (parent);
469 GNUNET_free(parent);
470} 459}
471 460
472 461
@@ -484,9 +473,9 @@ tree_new (GNUNET_PEER_Id peer)
484{ 473{
485 struct MeshTunnelTree *tree; 474 struct MeshTunnelTree *tree;
486 475
487 tree = GNUNET_malloc(sizeof (struct MeshTunnelTree)); 476 tree = GNUNET_malloc (sizeof (struct MeshTunnelTree));
488 tree->first_hops = GNUNET_CONTAINER_multihashmap_create(32); 477 tree->first_hops = GNUNET_CONTAINER_multihashmap_create (32);
489 tree->root = tree_node_new(NULL, peer); 478 tree->root = tree_node_new (NULL, peer);
490 tree->root->status = MESH_PEER_ROOT; 479 tree->root->status = MESH_PEER_ROOT;
491 480
492 return tree; 481 return tree;
@@ -502,7 +491,7 @@ tree_new (GNUNET_PEER_Id peer)
502void 491void
503tree_set_me (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer) 492tree_set_me (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer)
504{ 493{
505 tree->me = tree_find_peer(tree, peer); 494 tree->me = tree_find_peer (tree, peer);
506} 495}
507 496
508 497
@@ -529,13 +518,12 @@ tree_get_me (struct MeshTunnelTree *tree)
529 * @param peer A short peer id of local peer. 518 * @param peer A short peer id of local peer.
530 */ 519 */
531void 520void
532tree_set_status (struct MeshTunnelTree *tree, 521tree_set_status (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer,
533 GNUNET_PEER_Id peer,
534 enum MeshPeerState status) 522 enum MeshPeerState status)
535{ 523{
536 struct MeshTunnelTreeNode *n; 524 struct MeshTunnelTreeNode *n;
537 525
538 n = tree_find_peer(tree, peer); 526 n = tree_find_peer (tree, peer);
539 if (NULL == n) 527 if (NULL == n)
540 return; 528 return;
541 n->status = status; 529 n->status = status;
@@ -554,7 +542,7 @@ tree_get_status (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer)
554{ 542{
555 struct MeshTunnelTreeNode *n; 543 struct MeshTunnelTreeNode *n;
556 544
557 n = tree_find_peer(tree, peer); 545 n = tree_find_peer (tree, peer);
558 if (NULL == n) 546 if (NULL == n)
559 return MESH_PEER_INVALID; 547 return MESH_PEER_INVALID;
560 return n->status; 548 return n->status;
@@ -589,7 +577,7 @@ tree_get_predecessor (struct MeshTunnelTree *tree)
589struct MeshTunnelTreeNode * 577struct MeshTunnelTreeNode *
590tree_find_peer (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer_id) 578tree_find_peer (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer_id)
591{ 579{
592 return tree_node_find_peer(tree->root, peer_id); 580 return tree_node_find_peer (tree->root, peer_id);
593} 581}
594 582
595 583
@@ -603,8 +591,7 @@ tree_find_peer (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer_id)
603static void 591static void
604tree_mark_peers_disconnected (struct MeshTunnelTree *tree, 592tree_mark_peers_disconnected (struct MeshTunnelTree *tree,
605 struct MeshTunnelTreeNode *parent, 593 struct MeshTunnelTreeNode *parent,
606 MeshTreeCallback cb, 594 MeshTreeCallback cb, void *cbcls)
607 void *cbcls)
608{ 595{
609 struct GNUNET_PeerIdentity *pi; 596 struct GNUNET_PeerIdentity *pi;
610 struct GNUNET_PeerIdentity id; 597 struct GNUNET_PeerIdentity id;
@@ -622,24 +609,23 @@ tree_mark_peers_disconnected (struct MeshTunnelTree *tree,
622 } 609 }
623 610
624 /* Remove and free info about first hop */ 611 /* Remove and free info about first hop */
625 GNUNET_PEER_resolve(parent->peer, &id); 612 GNUNET_PEER_resolve (parent->peer, &id);
626 pi = GNUNET_CONTAINER_multihashmap_get(tree->first_hops, &id.hashPubKey); 613 pi = GNUNET_CONTAINER_multihashmap_get (tree->first_hops, &id.hashPubKey);
627 GNUNET_CONTAINER_multihashmap_remove_all(tree->first_hops, &id.hashPubKey); 614 GNUNET_CONTAINER_multihashmap_remove_all (tree->first_hops, &id.hashPubKey);
628 if (NULL != pi) 615 if (NULL != pi)
629 GNUNET_free(pi); 616 GNUNET_free (pi);
630} 617}
631 618
632 619
633/** 620/**
634 * Iterate over all children of the local node. 621 * Iterate over all children of the local node.
635 * 622 *
636 * @param tree Tree to use. Must have "me" set. 623 * @param tree Tree to use. Must have "me" set.
637 * @param cb Callback to call over each child. 624 * @param cb Callback to call over each child.
638 * @param cls Closure. 625 * @param cls Closure.
639 */ 626 */
640void 627void
641tree_iterate_children (struct MeshTunnelTree *tree, 628tree_iterate_children (struct MeshTunnelTree *tree, MeshTreeCallback cb,
642 MeshTreeCallback cb,
643 void *cls) 629 void *cls)
644{ 630{
645 struct MeshTunnelTreeNode *n; 631 struct MeshTunnelTreeNode *n;
@@ -665,13 +651,10 @@ tree_iterate_children (struct MeshTunnelTree *tree,
665 * If not known, NULL to find out and pass on children. 651 * If not known, NULL to find out and pass on children.
666 */ 652 */
667void 653void
668tree_update_first_hops (struct MeshTunnelTree *tree, 654tree_update_first_hops (struct MeshTunnelTree *tree, GNUNET_PEER_Id parent_id,
669 GNUNET_PEER_Id parent_id,
670 struct GNUNET_PeerIdentity *hop) 655 struct GNUNET_PeerIdentity *hop)
671{ 656{
672 tree_node_update_first_hops(tree, 657 tree_node_update_first_hops (tree, tree_find_peer (tree, parent_id), hop);
673 tree_find_peer(tree, parent_id),
674 hop);
675} 658}
676 659
677 660
@@ -689,10 +672,8 @@ tree_update_first_hops (struct MeshTunnelTree *tree,
689 * NULL when not found 672 * NULL when not found
690 */ 673 */
691struct MeshTunnelTreeNode * 674struct MeshTunnelTreeNode *
692tree_del_path (struct MeshTunnelTree *t, 675tree_del_path (struct MeshTunnelTree *t, GNUNET_PEER_Id peer_id,
693 GNUNET_PEER_Id peer_id, 676 MeshTreeCallback cb, void *cbcls)
694 MeshTreeCallback cb,
695 void *cbcls)
696{ 677{
697 struct MeshTunnelTreeNode *parent; 678 struct MeshTunnelTreeNode *parent;
698 struct MeshTunnelTreeNode *node; 679 struct MeshTunnelTreeNode *node;
@@ -700,10 +681,10 @@ tree_del_path (struct MeshTunnelTree *t,
700 681
701#if MESH_TREE_DEBUG 682#if MESH_TREE_DEBUG
702 struct GNUNET_PeerIdentity id; 683 struct GNUNET_PeerIdentity id;
703 GNUNET_PEER_resolve(peer_id, &id); 684
704 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 685 GNUNET_PEER_resolve (peer_id, &id);
705 "tree: Deleting path to %s.\n", 686 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Deleting path to %s.\n",
706 GNUNET_i2s (&id)); 687 GNUNET_i2s (&id));
707#endif 688#endif
708 if (peer_id == t->root->peer) 689 if (peer_id == t->root->peer)
709 return NULL; 690 return NULL;
@@ -713,8 +694,7 @@ tree_del_path (struct MeshTunnelTree *t,
713 if (n->peer == peer_id) 694 if (n->peer == peer_id)
714 { 695 {
715 /* Was already pathless, waiting for reconnection */ 696 /* Was already pathless, waiting for reconnection */
716 GNUNET_CONTAINER_DLL_remove (t->disconnected_head, 697 GNUNET_CONTAINER_DLL_remove (t->disconnected_head, t->disconnected_tail,
717 t->disconnected_tail,
718 n); 698 n);
719 return n; 699 return n;
720 } 700 }
@@ -725,26 +705,24 @@ tree_del_path (struct MeshTunnelTree *t,
725 node = n; 705 node = n;
726 706
727 parent = n->parent; 707 parent = n->parent;
728 GNUNET_CONTAINER_DLL_remove(parent->children_head, parent->children_tail, n); 708 GNUNET_CONTAINER_DLL_remove (parent->children_head, parent->children_tail, n);
729 n->parent = NULL; 709 n->parent = NULL;
730 710
731 while (MESH_PEER_RELAY == parent->status && NULL == parent->children_head) 711 while (MESH_PEER_RELAY == parent->status && NULL == parent->children_head)
732 { 712 {
733#if MESH_TREE_DEBUG 713#if MESH_TREE_DEBUG
734 GNUNET_PEER_resolve(parent->peer, &id); 714 GNUNET_PEER_resolve (parent->peer, &id);
735 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 715 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Deleting node %s.\n",
736 "tree: Deleting node %s.\n", 716 GNUNET_i2s (&id));
737 GNUNET_i2s (&id));
738#endif 717#endif
739 n = parent->parent; 718 n = parent->parent;
740 tree_node_destroy(parent); 719 tree_node_destroy (parent);
741 parent = n; 720 parent = n;
742 } 721 }
743#if MESH_TREE_DEBUG 722#if MESH_TREE_DEBUG
744 GNUNET_PEER_resolve(parent->peer, &id); 723 GNUNET_PEER_resolve (parent->peer, &id);
745 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 724 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Not deleted peer %s.\n",
746 "tree: Not deleted peer %s.\n", 725 GNUNET_i2s (&id));
747 GNUNET_i2s (&id));
748#endif 726#endif
749 727
750 tree_mark_peers_disconnected (t, node, cb, cbcls); 728 tree_mark_peers_disconnected (t, node, cb, cbcls);
@@ -764,30 +742,30 @@ tree_del_path (struct MeshTunnelTree *t,
764 * Path must be destroyed afterwards. 742 * Path must be destroyed afterwards.
765 */ 743 */
766struct MeshPeerPath * 744struct MeshPeerPath *
767tree_get_path_to_peer(struct MeshTunnelTree *t, GNUNET_PEER_Id peer) 745tree_get_path_to_peer (struct MeshTunnelTree *t, GNUNET_PEER_Id peer)
768{ 746{
769 struct MeshTunnelTreeNode *n; 747 struct MeshTunnelTreeNode *n;
770 struct MeshPeerPath *p; 748 struct MeshPeerPath *p;
771 GNUNET_PEER_Id myid = t->me->peer; 749 GNUNET_PEER_Id myid = t->me->peer;
772 750
773 n = tree_find_peer(t, peer); 751 n = tree_find_peer (t, peer);
774 if (NULL == n) 752 if (NULL == n)
775 return NULL; 753 return NULL;
776 p = path_new(0); 754 p = path_new (0);
777 755
778 /* Building the path (inverted!) */ 756 /* Building the path (inverted!) */
779 while (n->peer != myid) 757 while (n->peer != myid)
780 { 758 {
781 GNUNET_array_append(p->peers, p->length, n->peer); 759 GNUNET_array_append (p->peers, p->length, n->peer);
782 GNUNET_PEER_change_rc(n->peer, 1); 760 GNUNET_PEER_change_rc (n->peer, 1);
783 n = n->parent; 761 n = n->parent;
784 if (NULL == n) 762 if (NULL == n)
785 return NULL; 763 return NULL;
786 } 764 }
787 GNUNET_array_append(p->peers, p->length, myid); 765 GNUNET_array_append (p->peers, p->length, myid);
788 GNUNET_PEER_change_rc(myid, 1); 766 GNUNET_PEER_change_rc (myid, 1);
789 767
790 path_invert(p); 768 path_invert (p);
791 769
792 return p; 770 return p;
793} 771}
@@ -816,10 +794,8 @@ tree_get_path_to_peer(struct MeshTunnelTree *t, GNUNET_PEER_Id peer)
816 * - do not disconnect peers until new path is created & connected 794 * - do not disconnect peers until new path is created & connected
817 */ 795 */
818int 796int
819tree_add_path (struct MeshTunnelTree *t, 797tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p,
820 const struct MeshPeerPath *p, 798 MeshTreeCallback cb, void *cbcls)
821 MeshTreeCallback cb,
822 void *cbcls)
823{ 799{
824 struct MeshTunnelTreeNode *parent; 800 struct MeshTunnelTreeNode *parent;
825 struct MeshTunnelTreeNode *oldnode; 801 struct MeshTunnelTreeNode *oldnode;
@@ -831,18 +807,17 @@ tree_add_path (struct MeshTunnelTree *t,
831 unsigned int i; 807 unsigned int i;
832 808
833#if MESH_TREE_DEBUG 809#if MESH_TREE_DEBUG
834 GNUNET_PEER_resolve(p->peers[p->length - 1], &id); 810 GNUNET_PEER_resolve (p->peers[p->length - 1], &id);
835 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 811 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
836 "tree: Adding path [%u] towards peer %s.\n", 812 "tree: Adding path [%u] towards peer %s.\n", p->length,
837 p->length, 813 GNUNET_i2s (&id));
838 GNUNET_i2s (&id));
839#endif 814#endif
840 815
841 if (NULL != t->me) 816 if (NULL != t->me)
842 myid = t->me->peer; 817 myid = t->me->peer;
843 else 818 else
844 myid = 0; 819 myid = 0;
845 GNUNET_assert(0 != p->length); 820 GNUNET_assert (0 != p->length);
846 parent = n = t->root; 821 parent = n = t->root;
847 if (n->peer != p->peers[0]) 822 if (n->peer != p->peers[0])
848 { 823 {
@@ -862,10 +837,9 @@ tree_add_path (struct MeshTunnelTree *t,
862 for (i = 1; i < p->length; i++) 837 for (i = 1; i < p->length; i++)
863 { 838 {
864#if MESH_TREE_DEBUG 839#if MESH_TREE_DEBUG
865 GNUNET_PEER_resolve(p->peers[i], &id); 840 GNUNET_PEER_resolve (p->peers[i], &id);
866 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 841 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Looking for peer %s.\n",
867 "tree: Looking for peer %s.\n", 842 GNUNET_i2s (&id));
868 GNUNET_i2s (&id));
869#endif 843#endif
870 parent = n; 844 parent = n;
871 if (p->peers[i] == myid) 845 if (p->peers[i] == myid)
@@ -875,10 +849,9 @@ tree_add_path (struct MeshTunnelTree *t,
875 if (c->peer == p->peers[i]) 849 if (c->peer == p->peers[i])
876 { 850 {
877#if MESH_TREE_DEBUG 851#if MESH_TREE_DEBUG
878 GNUNET_PEER_resolve(parent->peer, &id); 852 GNUNET_PEER_resolve (parent->peer, &id);
879 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 853 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
880 "tree: Found in children of %s.\n", 854 "tree: Found in children of %s.\n", GNUNET_i2s (&id));
881 GNUNET_i2s (&id));
882#endif 855#endif
883 n = c; 856 n = c;
884 break; 857 break;
@@ -890,45 +863,40 @@ tree_add_path (struct MeshTunnelTree *t,
890 break; 863 break;
891 } 864 }
892#if MESH_TREE_DEBUG 865#if MESH_TREE_DEBUG
893 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 866 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: All childen visited.\n");
894 "tree: All childen visited.\n");
895#endif 867#endif
896 /* Add the rest of the path as a branch from parent. */ 868 /* Add the rest of the path as a branch from parent. */
897 while (i < p->length) 869 while (i < p->length)
898 { 870 {
899#if MESH_TREE_DEBUG 871#if MESH_TREE_DEBUG
900 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 872 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Adding peer %u to %u.\n",
901 "tree: Adding peer %u to %u.\n", 873 p->peers[i], parent->peer);
902 p->peers[i], parent->peer); 874 GNUNET_PEER_resolve (p->peers[i], &id);
903 GNUNET_PEER_resolve(p->peers[i], &id); 875 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Adding peer %s.\n",
904 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 876 GNUNET_i2s (&id));
905 "tree: Adding peer %s.\n", 877 GNUNET_PEER_resolve (parent->peer, &id);
906 GNUNET_i2s (&id)); 878 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: to %s.\n",
907 GNUNET_PEER_resolve(parent->peer, &id); 879 GNUNET_i2s (&id));
908 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
909 "tree: to %s.\n",
910 GNUNET_i2s (&id));
911#endif 880#endif
912 881
913 if (i == p->length - 1 && NULL != oldnode) 882 if (i == p->length - 1 && NULL != oldnode)
914 { 883 {
915#if MESH_TREE_DEBUG 884#if MESH_TREE_DEBUG
916 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 885 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
917 "tree: Putting old node into place.\n"); 886 "tree: Putting old node into place.\n");
918#endif 887#endif
919 oldnode->parent = parent; 888 oldnode->parent = parent;
920 GNUNET_CONTAINER_DLL_insert(parent->children_head, 889 GNUNET_CONTAINER_DLL_insert (parent->children_head, parent->children_tail,
921 parent->children_tail, 890 oldnode);
922 oldnode);
923 tree_node_update_first_hops (t, oldnode, NULL); 891 tree_node_update_first_hops (t, oldnode, NULL);
924 n = oldnode; 892 n = oldnode;
925 } 893 }
926 else 894 else
927 { 895 {
928#if MESH_TREE_DEBUG 896#if MESH_TREE_DEBUG
929 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: Creating new node.\n"); 897 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Creating new node.\n");
930#endif 898#endif
931 n = tree_node_new(parent, p->peers[i]); 899 n = tree_node_new (parent, p->peers[i]);
932 n->status = MESH_PEER_RELAY; 900 n->status = MESH_PEER_RELAY;
933 if (n->peer == myid) 901 if (n->peer == myid)
934 t->me = n; 902 t->me = n;
@@ -943,16 +911,14 @@ tree_add_path (struct MeshTunnelTree *t,
943 { 911 {
944#if MESH_TREE_DEBUG 912#if MESH_TREE_DEBUG
945 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 913 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
946 "MESH: finding first hop (own pos %d/%u)\n", 914 "MESH: finding first hop (own pos %d/%u)\n", me,
947 me, p->length - 1); 915 p->length - 1);
948#endif 916#endif
949 GNUNET_PEER_resolve (p->peers[me + 1], &id); 917 GNUNET_PEER_resolve (p->peers[me + 1], &id);
950 tree_update_first_hops(t, 918 tree_update_first_hops (t, p->peers[p->length - 1], &id);
951 p->peers[p->length - 1],
952 &id);
953 } 919 }
954#if MESH_TREE_DEBUG 920#if MESH_TREE_DEBUG
955 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: New node added.\n"); 921 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: New node added.\n");
956#endif 922#endif
957 return GNUNET_OK; 923 return GNUNET_OK;
958} 924}
@@ -971,40 +937,32 @@ tree_add_path (struct MeshTunnelTree *t,
971 * @return Short ID of the first disconnected peer in the tree. 937 * @return Short ID of the first disconnected peer in the tree.
972 */ 938 */
973GNUNET_PEER_Id 939GNUNET_PEER_Id
974tree_notify_connection_broken (struct MeshTunnelTree *t, 940tree_notify_connection_broken (struct MeshTunnelTree *t, GNUNET_PEER_Id p1,
975 GNUNET_PEER_Id p1, 941 GNUNET_PEER_Id p2, MeshTreeCallback cb,
976 GNUNET_PEER_Id p2,
977 MeshTreeCallback cb,
978 void *cbcls) 942 void *cbcls)
979{ 943{
980 struct MeshTunnelTreeNode *n; 944 struct MeshTunnelTreeNode *n;
981 struct MeshTunnelTreeNode *c; 945 struct MeshTunnelTreeNode *c;
982 946
983 n = tree_find_peer(t, p1); 947 n = tree_find_peer (t, p1);
984 if (NULL == n) 948 if (NULL == n)
985 return 0; 949 return 0;
986 if (NULL != n->parent && n->parent->peer == p2) 950 if (NULL != n->parent && n->parent->peer == p2)
987 { 951 {
988 tree_mark_peers_disconnected(t, n, cb, cbcls); 952 tree_mark_peers_disconnected (t, n, cb, cbcls);
989 GNUNET_CONTAINER_DLL_remove(n->parent->children_head, 953 GNUNET_CONTAINER_DLL_remove (n->parent->children_head,
990 n->parent->children_tail, 954 n->parent->children_tail, n);
991 n); 955 GNUNET_CONTAINER_DLL_insert (t->disconnected_head, t->disconnected_tail, n);
992 GNUNET_CONTAINER_DLL_insert(t->disconnected_head,
993 t->disconnected_tail,
994 n);
995 return p1; 956 return p1;
996 } 957 }
997 for (c = n->children_head; NULL != c; c = c->next) 958 for (c = n->children_head; NULL != c; c = c->next)
998 { 959 {
999 if (c->peer == p2) 960 if (c->peer == p2)
1000 { 961 {
1001 tree_mark_peers_disconnected(t, c, cb, cbcls); 962 tree_mark_peers_disconnected (t, c, cb, cbcls);
1002 GNUNET_CONTAINER_DLL_remove(n->children_head, 963 GNUNET_CONTAINER_DLL_remove (n->children_head, n->children_tail, c);
1003 n->children_tail, 964 GNUNET_CONTAINER_DLL_insert (t->disconnected_head, t->disconnected_tail,
1004 c); 965 c);
1005 GNUNET_CONTAINER_DLL_insert(t->disconnected_head,
1006 t->disconnected_tail,
1007 c);
1008 return p2; 966 return p2;
1009 } 967 }
1010 } 968 }
@@ -1026,21 +984,19 @@ tree_notify_connection_broken (struct MeshTunnelTree *t,
1026 * @return GNUNET_OK or GNUNET_SYSERR 984 * @return GNUNET_OK or GNUNET_SYSERR
1027 */ 985 */
1028int 986int
1029tree_del_peer (struct MeshTunnelTree *t, 987tree_del_peer (struct MeshTunnelTree *t, GNUNET_PEER_Id peer,
1030 GNUNET_PEER_Id peer, 988 MeshTreeCallback cb, void *cbcls)
1031 MeshTreeCallback cb,
1032 void *cbcls)
1033{ 989{
1034 struct MeshTunnelTreeNode *n; 990 struct MeshTunnelTreeNode *n;
1035 991
1036 n = tree_del_path(t, peer, cb, cbcls); 992 n = tree_del_path (t, peer, cb, cbcls);
1037 if (NULL == n) 993 if (NULL == n)
1038 { 994 {
1039 GNUNET_break (0); 995 GNUNET_break (0);
1040 return GNUNET_YES; 996 return GNUNET_YES;
1041 } 997 }
1042 GNUNET_break_op (NULL == n->children_head); 998 GNUNET_break_op (NULL == n->children_head);
1043 tree_node_destroy(n); 999 tree_node_destroy (n);
1044 if (NULL == t->root->children_head && t->me != t->root) 1000 if (NULL == t->root->children_head && t->me != t->root)
1045 { 1001 {
1046 tree_node_destroy (t->root); 1002 tree_node_destroy (t->root);
@@ -1057,9 +1013,9 @@ tree_del_peer (struct MeshTunnelTree *t,
1057 * @param t The tree 1013 * @param t The tree
1058 */ 1014 */
1059void 1015void
1060tree_debug(struct MeshTunnelTree *t) 1016tree_debug (struct MeshTunnelTree *t)
1061{ 1017{
1062 tree_node_debug(t->root, 0); 1018 tree_node_debug (t->root, 0);
1063} 1019}
1064 1020
1065 1021
@@ -1075,14 +1031,14 @@ tree_debug(struct MeshTunnelTree *t)
1075static int 1031static int
1076iterate_free (void *cls, const GNUNET_HashCode * key, void *value) 1032iterate_free (void *cls, const GNUNET_HashCode * key, void *value)
1077{ 1033{
1078 GNUNET_free(value); 1034 GNUNET_free (value);
1079 return GNUNET_YES; 1035 return GNUNET_YES;
1080} 1036}
1081 1037
1082 1038
1083/** 1039/**
1084 * Destroy the whole tree and free all used memory and Peer_Ids 1040 * Destroy the whole tree and free all used memory and Peer_Ids
1085 * 1041 *
1086 * @param t Tree to be destroyed 1042 * @param t Tree to be destroyed
1087 */ 1043 */
1088void 1044void
@@ -1091,8 +1047,8 @@ tree_destroy (struct MeshTunnelTree *t)
1091#if MESH_TREE_DEBUG 1047#if MESH_TREE_DEBUG
1092 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Destroying tree\n"); 1048 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Destroying tree\n");
1093#endif 1049#endif
1094 tree_node_destroy(t->root); 1050 tree_node_destroy (t->root);
1095 GNUNET_CONTAINER_multihashmap_iterate(t->first_hops, &iterate_free, NULL); 1051 GNUNET_CONTAINER_multihashmap_iterate (t->first_hops, &iterate_free, NULL);
1096 GNUNET_CONTAINER_multihashmap_destroy(t->first_hops); 1052 GNUNET_CONTAINER_multihashmap_destroy (t->first_hops);
1097 GNUNET_free(t); 1053 GNUNET_free (t);
1098} 1054}
diff --git a/src/mesh/mesh_tunnel_tree.h b/src/mesh/mesh_tunnel_tree.h
index e946259da..094a617cb 100644
--- a/src/mesh/mesh_tunnel_tree.h
+++ b/src/mesh/mesh_tunnel_tree.h
@@ -110,8 +110,7 @@ path_duplicate (struct MeshPeerPath *path);
110 * NULL on error 110 * NULL on error
111 */ 111 */
112struct GNUNET_PeerIdentity * 112struct GNUNET_PeerIdentity *
113path_get_first_hop (struct MeshTunnelTree *t, 113path_get_first_hop (struct MeshTunnelTree *t, GNUNET_PEER_Id peer);
114 GNUNET_PEER_Id peer);
115 114
116 115
117/** 116/**
@@ -136,8 +135,7 @@ path_get_length (struct MeshPeerPath *p);
136 * in the path 135 * in the path
137 */ 136 */
138unsigned int 137unsigned int
139path_get_cost (struct MeshTunnelTree *t, 138path_get_cost (struct MeshTunnelTree *t, struct MeshPeerPath *path);
140 struct MeshPeerPath *path);
141 139
142 140
143/** 141/**
@@ -159,8 +157,7 @@ path_destroy (struct MeshPeerPath *p);
159 * @param cls Closure. 157 * @param cls Closure.
160 * @param peer_id short ID of peer that is no longer reachable. 158 * @param peer_id short ID of peer that is no longer reachable.
161 */ 159 */
162typedef void (*MeshTreeCallback) (void *cls, 160typedef void (*MeshTreeCallback) (void *cls, GNUNET_PEER_Id peer_id);
163 GNUNET_PEER_Id peer_id);
164 161
165 162
166/** 163/**
@@ -202,8 +199,7 @@ tree_get_me (struct MeshTunnelTree *tree);
202 * @param peer A short peer id of local peer. 199 * @param peer A short peer id of local peer.
203 */ 200 */
204void 201void
205tree_set_status (struct MeshTunnelTree *tree, 202tree_set_status (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer,
206 GNUNET_PEER_Id peer,
207 enum MeshPeerState status); 203 enum MeshPeerState status);
208 204
209 205
@@ -243,14 +239,13 @@ tree_find_peer (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer_id);
243 239
244/** 240/**
245 * Iterate over all children of the local node. 241 * Iterate over all children of the local node.
246 * 242 *
247 * @param tree Tree to use. Must have "me" set. 243 * @param tree Tree to use. Must have "me" set.
248 * @param cb Callback to call over each child. 244 * @param cb Callback to call over each child.
249 * @param cls Closure. 245 * @param cls Closure.
250 */ 246 */
251void 247void
252tree_iterate_children (struct MeshTunnelTree *tree, 248tree_iterate_children (struct MeshTunnelTree *tree, MeshTreeCallback cb,
253 MeshTreeCallback cb,
254 void *cls); 249 void *cls);
255 250
256 251
@@ -263,8 +258,7 @@ tree_iterate_children (struct MeshTunnelTree *tree,
263 * If not known, NULL to find out and pass on children. 258 * If not known, NULL to find out and pass on children.
264 */ 259 */
265void 260void
266tree_update_first_hops (struct MeshTunnelTree *tree, 261tree_update_first_hops (struct MeshTunnelTree *tree, GNUNET_PEER_Id parent_id,
267 GNUNET_PEER_Id parent_id,
268 struct GNUNET_PeerIdentity *hop); 262 struct GNUNET_PeerIdentity *hop);
269 263
270/** 264/**
@@ -282,10 +276,8 @@ tree_update_first_hops (struct MeshTunnelTree *tree,
282 * NULL when not found 276 * NULL when not found
283 */ 277 */
284struct MeshTunnelTreeNode * 278struct MeshTunnelTreeNode *
285tree_del_path (struct MeshTunnelTree *t, 279tree_del_path (struct MeshTunnelTree *t, GNUNET_PEER_Id peer,
286 GNUNET_PEER_Id peer, 280 MeshTreeCallback cb, void *cbcls);
287 MeshTreeCallback cb,
288 void *cbcls);
289 281
290 282
291/** 283/**
@@ -299,8 +291,7 @@ tree_del_path (struct MeshTunnelTree *t,
299 * Path must be destroyed afterwards. 291 * Path must be destroyed afterwards.
300 */ 292 */
301struct MeshPeerPath * 293struct MeshPeerPath *
302tree_get_path_to_peer(struct MeshTunnelTree *t, 294tree_get_path_to_peer (struct MeshTunnelTree *t, GNUNET_PEER_Id peer);
303 GNUNET_PEER_Id peer);
304 295
305 296
306/** 297/**
@@ -315,10 +306,8 @@ tree_get_path_to_peer(struct MeshTunnelTree *t,
315 * GNUNET_SYSERR in case of error. 306 * GNUNET_SYSERR in case of error.
316 */ 307 */
317int 308int
318tree_add_path (struct MeshTunnelTree *t, 309tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p,
319 const struct MeshPeerPath *p, 310 MeshTreeCallback cb, void *cbcls);
320 MeshTreeCallback cb,
321 void *cbcls);
322 311
323 312
324/** 313/**
@@ -334,10 +323,8 @@ tree_add_path (struct MeshTunnelTree *t,
334 * @return Short ID of the first disconnected peer in the tree. 323 * @return Short ID of the first disconnected peer in the tree.
335 */ 324 */
336GNUNET_PEER_Id 325GNUNET_PEER_Id
337tree_notify_connection_broken (struct MeshTunnelTree *t, 326tree_notify_connection_broken (struct MeshTunnelTree *t, GNUNET_PEER_Id p1,
338 GNUNET_PEER_Id p1, 327 GNUNET_PEER_Id p2, MeshTreeCallback cb,
339 GNUNET_PEER_Id p2,
340 MeshTreeCallback cb,
341 void *cbcls); 328 void *cbcls);
342 329
343 330
@@ -355,10 +342,8 @@ tree_notify_connection_broken (struct MeshTunnelTree *t,
355 * @return GNUNET_YES if the tunnel still has nodes 342 * @return GNUNET_YES if the tunnel still has nodes
356 */ 343 */
357int 344int
358tree_del_peer (struct MeshTunnelTree *t, 345tree_del_peer (struct MeshTunnelTree *t, GNUNET_PEER_Id peer,
359 GNUNET_PEER_Id peer, 346 MeshTreeCallback cb, void *cbcls);
360 MeshTreeCallback cb,
361 void *cbcls);
362 347
363/** 348/**
364 * Print the tree on stderr 349 * Print the tree on stderr
@@ -366,7 +351,7 @@ tree_del_peer (struct MeshTunnelTree *t,
366 * @param t The tree 351 * @param t The tree
367 */ 352 */
368void 353void
369tree_debug(struct MeshTunnelTree *t); 354tree_debug (struct MeshTunnelTree *t);
370 355
371 356
372/** 357/**
diff --git a/src/mesh/test_mesh_api.c b/src/mesh/test_mesh_api.c
index 10e16bd42..6fcc8c7ff 100644
--- a/src/mesh/test_mesh_api.c
+++ b/src/mesh/test_mesh_api.c
@@ -122,7 +122,8 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
122 } 122 }
123 123
124 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 124 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
125 (GNUNET_TIME_UNIT_SECONDS, 5), &do_shutdown, NULL); 125 (GNUNET_TIME_UNIT_SECONDS, 5), &do_shutdown,
126 NULL);
126} 127}
127 128
128 129
diff --git a/src/mesh/test_mesh_local_2.c b/src/mesh/test_mesh_local_2.c
index a2f5dd759..c91548052 100644
--- a/src/mesh/test_mesh_local_2.c
+++ b/src/mesh/test_mesh_local_2.c
@@ -268,10 +268,9 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
268 &peer_disconnected, (void *) &two); 268 &peer_disconnected, (void *) &two);
269 GNUNET_MESH_peer_request_connect_by_type (t, 1); 269 GNUNET_MESH_peer_request_connect_by_type (t, 1);
270 test_task = 270 test_task =
271 GNUNET_SCHEDULER_add_delayed ( 271 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
272 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), 272 (GNUNET_TIME_UNIT_SECONDS, 5),
273 &do_connect_peer_1, 273 &do_connect_peer_1, cfg);
274 cfg);
275} 274}
276 275
277 276
diff --git a/src/mesh/test_mesh_small.c b/src/mesh/test_mesh_small.c
index 68fc9cc24..42390e1a6 100644
--- a/src/mesh/test_mesh_small.c
+++ b/src/mesh/test_mesh_small.c
@@ -171,14 +171,16 @@ shutdown_callback (void *cls, const char *emsg)
171 if (emsg != NULL) 171 if (emsg != NULL)
172 { 172 {
173#if VERBOSE 173#if VERBOSE
174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: Shutdown of peers failed!\n"); 174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
175 "***************** test: Shutdown of peers failed!\n");
175#endif 176#endif
176 ok--; 177 ok--;
177 } 178 }
178 else 179 else
179 { 180 {
180#if VERBOSE 181#if VERBOSE
181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: All peers successfully shut down!\n"); 182 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
183 "***************** test: All peers successfully shut down!\n");
182#endif 184#endif
183 } 185 }
184} 186}
@@ -188,7 +190,8 @@ static void
188shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 190shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
189{ 191{
190#if VERBOSE 192#if VERBOSE
191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: Ending test.\n"); 193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
194 "***************** test: Ending test.\n");
192#endif 195#endif
193 196
194 if (disconnect_task != GNUNET_SCHEDULER_NO_TASK) 197 if (disconnect_task != GNUNET_SCHEDULER_NO_TASK)
@@ -210,14 +213,14 @@ disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
211 "***************** test: disconnecting mesh service of peers\n"); 214 "***************** test: disconnecting mesh service of peers\n");
212 disconnect_task = GNUNET_SCHEDULER_NO_TASK; 215 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
213 GNUNET_MESH_disconnect(h1); 216 GNUNET_MESH_disconnect (h1);
214 GNUNET_MESH_disconnect(h2); 217 GNUNET_MESH_disconnect (h2);
215 if (test == MULTICAST) 218 if (test == MULTICAST)
216 GNUNET_MESH_disconnect(h3); 219 GNUNET_MESH_disconnect (h3);
217 if (GNUNET_SCHEDULER_NO_TASK != shutdown_handle) 220 if (GNUNET_SCHEDULER_NO_TASK != shutdown_handle)
218 { 221 {
219 GNUNET_SCHEDULER_cancel (shutdown_handle); 222 GNUNET_SCHEDULER_cancel (shutdown_handle);
220 shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); 223 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
221 } 224 }
222} 225}
223 226
@@ -230,12 +233,13 @@ tmt_rdy (void *cls, size_t size, void *buf)
230{ 233{
231 struct GNUNET_MessageHeader *msg = buf; 234 struct GNUNET_MessageHeader *msg = buf;
232 235
233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: tmt_rdy called\n"); 236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
234 if (size < sizeof(struct GNUNET_MessageHeader) || NULL == buf) 237 "***************** test: tmt_rdy called\n");
238 if (size < sizeof (struct GNUNET_MessageHeader) || NULL == buf)
235 return 0; 239 return 0;
236 msg->size = htons (sizeof(struct GNUNET_MessageHeader)); 240 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
237 msg->type = htons ((long) cls); 241 msg->type = htons ((long) cls);
238 return sizeof(struct GNUNET_MessageHeader); 242 return sizeof (struct GNUNET_MessageHeader);
239} 243}
240 244
241 245
@@ -252,57 +256,51 @@ tmt_rdy (void *cls, size_t size, void *buf)
252 * GNUNET_SYSERR to close it (signal serious error) 256 * GNUNET_SYSERR to close it (signal serious error)
253 */ 257 */
254int 258int
255data_callback (void *cls, 259data_callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx,
256 struct GNUNET_MESH_Tunnel * tunnel, 260 const struct GNUNET_PeerIdentity *sender,
257 void **tunnel_ctx, 261 const struct GNUNET_MessageHeader *message,
258 const struct GNUNET_PeerIdentity *sender, 262 const struct GNUNET_ATS_Information *atsi)
259 const struct GNUNET_MessageHeader *message,
260 const struct GNUNET_ATS_Information *atsi)
261{ 263{
262 long client = (long) cls; 264 long client = (long) cls;
263 265
264 switch (client) 266 switch (client)
265 { 267 {
266 case 1L: 268 case 1L:
267 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
268 "***************** test: Origin client got a response!\n"); 270 "***************** test: Origin client got a response!\n");
269 ok++; 271 ok++;
270 peers_responded++; 272 peers_responded++;
271 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) 273 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
272 { 274 {
273 GNUNET_SCHEDULER_cancel (disconnect_task); 275 GNUNET_SCHEDULER_cancel (disconnect_task);
274 disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME, 276 disconnect_task =
275 &disconnect_mesh_peers, 277 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers,
276 NULL); 278 NULL);
277 } 279 }
278 if (test == MULTICAST && peers_responded < 2) 280 if (test == MULTICAST && peers_responded < 2)
279 return GNUNET_OK; 281 return GNUNET_OK;
280 GNUNET_MESH_tunnel_destroy (tunnel); 282 GNUNET_MESH_tunnel_destroy (tunnel);
281 break; 283 break;
282 case 2L: 284 case 2L:
283 case 3L: 285 case 3L:
284 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 286 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
285 "***************** test: Destination client %u got a message.\n", 287 "***************** test: Destination client %u got a message.\n",
286 client); 288 client);
287 ok++; 289 ok++;
288 GNUNET_MESH_notify_transmit_ready(tunnel, 290 GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO, 0,
289 GNUNET_NO, 291 GNUNET_TIME_UNIT_FOREVER_REL, sender,
290 0, 292 sizeof (struct GNUNET_MessageHeader),
291 GNUNET_TIME_UNIT_FOREVER_REL, 293 &tmt_rdy, (void *) 1L);
292 sender, 294 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
293 sizeof(struct GNUNET_MessageHeader), 295 {
294 &tmt_rdy, 296 GNUNET_SCHEDULER_cancel (disconnect_task);
295 (void *) 1L); 297 disconnect_task =
296 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) 298 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers,
297 { 299 NULL);
298 GNUNET_SCHEDULER_cancel (disconnect_task); 300 }
299 disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME, 301 break;
300 &disconnect_mesh_peers, 302 default:
301 NULL); 303 break;
302 }
303 break;
304 default:
305 break;
306 } 304 }
307 return GNUNET_OK; 305 return GNUNET_OK;
308} 306}
@@ -312,7 +310,7 @@ data_callback (void *cls,
312 * Handlers, for diverse services 310 * Handlers, for diverse services
313 */ 311 */
314static struct GNUNET_MESH_MessageHandler handlers[] = { 312static struct GNUNET_MESH_MessageHandler handlers[] = {
315 {&data_callback, 1, sizeof(struct GNUNET_MessageHeader)}, 313 {&data_callback, 1, sizeof (struct GNUNET_MessageHeader)},
316 {NULL, 0, 0} 314 {NULL, 0, 0}
317}; 315};
318 316
@@ -329,15 +327,13 @@ static struct GNUNET_MESH_MessageHandler handlers[] = {
329 * (can be NULL -- that's not an error) 327 * (can be NULL -- that's not an error)
330 */ 328 */
331static void * 329static void *
332incoming_tunnel (void *cls, 330incoming_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel,
333 struct GNUNET_MESH_Tunnel * tunnel, 331 const struct GNUNET_PeerIdentity *initiator,
334 const struct GNUNET_PeerIdentity * initiator, 332 const struct GNUNET_ATS_Information *atsi)
335 const struct GNUNET_ATS_Information * atsi)
336{ 333{
337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 334 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
338 "***************** test: Incoming tunnel from %s to peer %d\n", 335 "***************** test: Incoming tunnel from %s to peer %d\n",
339 GNUNET_i2s(initiator), 336 GNUNET_i2s (initiator), (long) cls);
340 (long) cls);
341 ok++; 337 ok++;
342 if ((long) cls == 1L) 338 if ((long) cls == 1L)
343 incoming_t = tunnel; 339 incoming_t = tunnel;
@@ -346,9 +342,8 @@ incoming_tunnel (void *cls,
346 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) 342 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
347 { 343 {
348 GNUNET_SCHEDULER_cancel (disconnect_task); 344 GNUNET_SCHEDULER_cancel (disconnect_task);
349 disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME, 345 disconnect_task =
350 &disconnect_mesh_peers, 346 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers, NULL);
351 NULL);
352 } 347 }
353 return NULL; 348 return NULL;
354} 349}
@@ -377,8 +372,7 @@ tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel,
377 ok++; 372 ok++;
378 else 373 else
379 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
380 "***************** test: Unknown peer! %d\n", 375 "***************** test: Unknown peer! %d\n", i);
381 i);
382 peers_in_tunnel--; 376 peers_in_tunnel--;
383 if (peers_in_tunnel > 0) 377 if (peers_in_tunnel > 0)
384 return; 378 return;
@@ -404,7 +398,7 @@ dh (void *cls, const struct GNUNET_PeerIdentity *peer)
404{ 398{
405 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
406 "***************** test: peer %s disconnected\n", 400 "***************** test: peer %s disconnected\n",
407 GNUNET_i2s(peer)); 401 GNUNET_i2s (peer));
408 return; 402 return;
409} 403}
410 404
@@ -423,51 +417,46 @@ ch (void *cls, const struct GNUNET_PeerIdentity *peer,
423 struct GNUNET_PeerIdentity *dest; 417 struct GNUNET_PeerIdentity *dest;
424 418
425 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 419 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
426 "***************** test: peer %s connected\n", 420 "***************** test: peer %s connected\n", GNUNET_i2s (peer));
427 GNUNET_i2s(peer));
428 421
429 if (0 == memcmp(&d2->id, peer, sizeof(d2->id)) && (long) cls == 1L) 422 if (0 == memcmp (&d2->id, peer, sizeof (d2->id)) && (long) cls == 1L)
430 ok++; 423 ok++;
431 if (test == MULTICAST && 424 if (test == MULTICAST && 0 == memcmp (&d3->id, peer, sizeof (d3->id)) &&
432 0 == memcmp(&d3->id, peer, sizeof(d3->id)) &&
433 (long) cls == 1L) 425 (long) cls == 1L)
434 ok++; 426 ok++;
435 switch (test) 427 switch (test)
436 { 428 {
437 case UNICAST: 429 case UNICAST:
438 dest = &d2->id; 430 dest = &d2->id;
439 break; 431 break;
440 case MULTICAST: 432 case MULTICAST:
441 peers_in_tunnel++; 433 peers_in_tunnel++;
442 if (peers_in_tunnel < 2) 434 if (peers_in_tunnel < 2)
443 return;
444 dest = NULL;
445 break;
446 default:
447 return; 435 return;
436 dest = NULL;
437 break;
438 default:
439 return;
448 } 440 }
449 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) 441 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
450 { 442 {
451 GNUNET_SCHEDULER_cancel (disconnect_task); 443 GNUNET_SCHEDULER_cancel (disconnect_task);
452 disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME, 444 disconnect_task =
453 &disconnect_mesh_peers, 445 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_mesh_peers, NULL);
454 NULL);
455 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
456 "***************** test: Sending data...\n"); 447 "***************** test: Sending data...\n");
457 peers_responded = 0; 448 peers_responded = 0;
458 GNUNET_MESH_notify_transmit_ready(t, 449 GNUNET_MESH_notify_transmit_ready (t, GNUNET_NO, 0,
459 GNUNET_NO, 450 GNUNET_TIME_UNIT_FOREVER_REL, dest,
460 0, 451 sizeof (struct GNUNET_MessageHeader),
461 GNUNET_TIME_UNIT_FOREVER_REL, 452 &tmt_rdy, (void *) 1L);
462 dest,
463 sizeof(struct GNUNET_MessageHeader),
464 &tmt_rdy,
465 (void *) 1L);
466 } 453 }
467 else 454 else
468 { 455 {
469 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: Disconnect already run?\n"); 456 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: Aborting...\n"); 457 "***************** test: Disconnect already run?\n");
458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
459 "***************** test: Aborting...\n");
471 } 460 }
472 return; 461 return;
473} 462}
@@ -481,20 +470,19 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
481 { 470 {
482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
483 "***************** test: add peer 3\n"); 472 "***************** test: add peer 3\n");
484 GNUNET_MESH_peer_request_connect_add(t, &d3->id); 473 GNUNET_MESH_peer_request_connect_add (t, &d3->id);
485 } 474 }
486 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: add peer 2\n");
487 "***************** test: add peer 2\n"); 476 GNUNET_MESH_peer_request_connect_add (t, &d2->id);
488 GNUNET_MESH_peer_request_connect_add(t, &d2->id);
489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 477 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
490 "***************** test: schedule timeout in 30s\n"); 478 "***************** test: schedule timeout in 30s\n");
491 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) 479 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
492 { 480 {
493 GNUNET_SCHEDULER_cancel (disconnect_task); 481 GNUNET_SCHEDULER_cancel (disconnect_task);
494 disconnect_task = GNUNET_SCHEDULER_add_delayed( 482 disconnect_task =
495 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30), 483 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
496 &disconnect_mesh_peers, 484 (GNUNET_TIME_UNIT_SECONDS, 30),
497 NULL); 485 &disconnect_mesh_peers, NULL);
498 } 486 }
499} 487}
500 488
@@ -510,50 +498,46 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
510 * @param emsg error message (NULL on success) 498 * @param emsg error message (NULL on success)
511 */ 499 */
512void 500void
513topo_cb (void *cls, 501topo_cb (void *cls, const struct GNUNET_PeerIdentity *first,
514 const struct GNUNET_PeerIdentity* first, 502 const struct GNUNET_PeerIdentity *second, const char *emsg)
515 const struct GNUNET_PeerIdentity* second,
516 const char *emsg)
517{ 503{
518 GNUNET_PEER_Id p1; 504 GNUNET_PEER_Id p1;
519 GNUNET_PEER_Id p2; 505 GNUNET_PEER_Id p2;
520 struct GNUNET_PeerIdentity id; 506 struct GNUNET_PeerIdentity id;
521 507
522 GNUNET_PEER_resolve(1, &id); 508 GNUNET_PEER_resolve (1, &id);
523 p1 = GNUNET_PEER_search(first); 509 p1 = GNUNET_PEER_search (first);
524 if (p1 == pid1) 510 if (p1 == pid1)
525 { 511 {
526 p2 = GNUNET_PEER_search(second); 512 p2 = GNUNET_PEER_search (second);
527 if (p2 == 0 || p2 > num_peers) 513 if (p2 == 0 || p2 > num_peers)
528 { 514 {
529 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 515 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
530 "***************** test: %s is UNKNOWN!? (%u)\n", 516 "***************** test: %s is UNKNOWN!? (%u)\n",
531 GNUNET_i2s(second), 517 GNUNET_i2s (second), p2);
532 p2);
533 return; 518 return;
534 } 519 }
535 mesh_peers[p2]++; 520 mesh_peers[p2]++;
536 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
537 "***************** test: %s IS a neighbor\n", 522 "***************** test: %s IS a neighbor\n",
538 GNUNET_i2s(second)); 523 GNUNET_i2s (second));
539 return; 524 return;
540 } 525 }
541 p1 = GNUNET_PEER_search(second); 526 p1 = GNUNET_PEER_search (second);
542 if (p1 == pid1) 527 if (p1 == pid1)
543 { 528 {
544 p2 = GNUNET_PEER_search(first); 529 p2 = GNUNET_PEER_search (first);
545 if (p2 == 0 || p2 > num_peers) 530 if (p2 == 0 || p2 > num_peers)
546 { 531 {
547 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 532 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
548 "***************** test: %s is UNKNOWN!? (%u)\n", 533 "***************** test: %s is UNKNOWN!? (%u)\n",
549 GNUNET_i2s(first), 534 GNUNET_i2s (first), p2);
550 p2);
551 return; 535 return;
552 } 536 }
553 mesh_peers[p2]++; 537 mesh_peers[p2]++;
554 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 538 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
555 "***************** test: %s IS a neighbor\n", 539 "***************** test: %s IS a neighbor\n",
556 GNUNET_i2s(first)); 540 GNUNET_i2s (first));
557 return; 541 return;
558 } 542 }
559} 543}
@@ -569,15 +553,15 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
569 unsigned int i; 553 unsigned int i;
570 struct GNUNET_PeerIdentity id; 554 struct GNUNET_PeerIdentity id;
571 555
572 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: connect_mesh_service\n"); 556 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
557 "***************** test: connect_mesh_service\n");
573 558
574 for (i = 1; i <= num_peers; i++) 559 for (i = 1; i <= num_peers; i++)
575 { 560 {
576 GNUNET_PEER_resolve(i, &id); 561 GNUNET_PEER_resolve (i, &id);
577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 562 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
578 "***************** test: peer %s has %u conns to d1\n", 563 "***************** test: peer %s has %u conns to d1\n",
579 GNUNET_i2s (&id), 564 GNUNET_i2s (&id), mesh_peers[i]);
580 mesh_peers[i]);
581 if (mesh_peers[i] == 0) 565 if (mesh_peers[i] == 0)
582 break; 566 break;
583 } 567 }
@@ -587,11 +571,10 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
587 { 571 {
588 for (i++; i <= num_peers; i++) 572 for (i++; i <= num_peers; i++)
589 { 573 {
590 GNUNET_PEER_resolve(i, &id); 574 GNUNET_PEER_resolve (i, &id);
591 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 575 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
592 "***************** test: peer %s has %u conns to d1\n", 576 "***************** test: peer %s has %u conns to d1\n",
593 GNUNET_i2s (&id), 577 GNUNET_i2s (&id), mesh_peers[i]);
594 mesh_peers[i]);
595 if (mesh_peers[i] == 0) 578 if (mesh_peers[i] == 0)
596 break; 579 break;
597 } 580 }
@@ -603,50 +586,32 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
603#if VERBOSE 586#if VERBOSE
604 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 587 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
605 "***************** test: connecting to mesh service of peer %s (%u)\n", 588 "***************** test: connecting to mesh service of peer %s (%u)\n",
606 GNUNET_i2s (&d1->id), 589 GNUNET_i2s (&d1->id), mesh_peers[0]);
607 mesh_peers[0]);
608 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 590 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
609 "***************** test: connecting to mesh service of peer %s (%u)\n", 591 "***************** test: connecting to mesh service of peer %s (%u)\n",
610 GNUNET_i2s (&d2->id), 592 GNUNET_i2s (&d2->id), i);
611 i);
612 if (test == MULTICAST) 593 if (test == MULTICAST)
613 { 594 {
614 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 595 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
615 "***************** test: connecting to mesh service of peer %s (%u)\n", 596 "***************** test: connecting to mesh service of peer %s (%u)\n",
616 GNUNET_i2s (&d3->id), 597 GNUNET_i2s (&d3->id), i);
617 i);
618 } 598 }
619#endif 599#endif
620 h1 = GNUNET_MESH_connect (d1->cfg, 600 h1 = GNUNET_MESH_connect (d1->cfg, 10, (void *) 1L, NULL, &tunnel_cleaner,
621 10, 601 handlers, &app);
622 (void *) 1L, 602 h2 = GNUNET_MESH_connect (d2->cfg, 10, (void *) 2L, &incoming_tunnel,
623 NULL, 603 &tunnel_cleaner, handlers, &app);
624 &tunnel_cleaner,
625 handlers,
626 &app);
627 h2 = GNUNET_MESH_connect (d2->cfg,
628 10,
629 (void *) 2L,
630 &incoming_tunnel,
631 &tunnel_cleaner,
632 handlers,
633 &app);
634 if (test == MULTICAST) 604 if (test == MULTICAST)
635 { 605 {
636 h3 = GNUNET_MESH_connect (d3->cfg, 606 h3 = GNUNET_MESH_connect (d3->cfg, 10, (void *) 3L, &incoming_tunnel,
637 10, 607 &tunnel_cleaner, handlers, &app);
638 (void *) 3L,
639 &incoming_tunnel,
640 &tunnel_cleaner,
641 handlers,
642 &app);
643 } 608 }
644 t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, (void *) 1L); 609 t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, (void *) 1L);
645 peers_in_tunnel = 0; 610 peers_in_tunnel = 0;
646 test_task = 611 test_task =
647 GNUNET_SCHEDULER_add_delayed( 612 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
648 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 6), 613 (GNUNET_TIME_UNIT_SECONDS, 6), &do_test,
649 &do_test, NULL); 614 NULL);
650} 615}
651 616
652 617
@@ -697,25 +662,21 @@ peergroup_ready (void *cls, const char *emsg)
697 GNUNET_PEER_Id peer_id; 662 GNUNET_PEER_Id peer_id;
698 663
699 d1 = GNUNET_TESTING_daemon_get (pg, i); 664 d1 = GNUNET_TESTING_daemon_get (pg, i);
700 peer_id = GNUNET_PEER_intern(&d1->id); 665 peer_id = GNUNET_PEER_intern (&d1->id);
701 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 666 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: %u: %s\n",
702 "***************** test: %u: %s\n", 667 peer_id, GNUNET_i2s (&d1->id));
703 peer_id,
704 GNUNET_i2s (&d1->id));
705 } 668 }
706 d1 = GNUNET_TESTING_daemon_get (pg, 0); 669 d1 = GNUNET_TESTING_daemon_get (pg, 0);
707 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 670 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
708 "***************** test: Peer looking: %s\n", 671 "***************** test: Peer looking: %s\n",
709 GNUNET_i2s (&d1->id)); 672 GNUNET_i2s (&d1->id));
710 pid1 = GNUNET_PEER_intern(&d1->id); 673 pid1 = GNUNET_PEER_intern (&d1->id);
711 mesh_peers[pid1] = 100; 674 mesh_peers[pid1] = 100;
712 GNUNET_TESTING_get_topology(pg, &topo_cb, NULL); 675 GNUNET_TESTING_get_topology (pg, &topo_cb, NULL);
713 676
714 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply( 677 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
715 GNUNET_TIME_UNIT_SECONDS, 678 (GNUNET_TIME_UNIT_SECONDS, 4),
716 4), 679 &connect_mesh_service, NULL);
717 &connect_mesh_service,
718 NULL);
719 disconnect_task = 680 disconnect_task =
720 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL); 681 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL);
721 682
@@ -753,11 +714,9 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *first,
753 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 714 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
754 "***************** test: Problem with new connection (%s)\n", 715 "***************** test: Problem with new connection (%s)\n",
755 emsg); 716 emsg);
756 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 717 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: (%s)\n",
757 "***************** test: (%s)\n",
758 GNUNET_i2s (first)); 718 GNUNET_i2s (first));
759 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 719 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: (%s)\n",
760 "***************** test: (%s)\n",
761 GNUNET_i2s (second)); 720 GNUNET_i2s (second));
762 } 721 }
763 722
@@ -792,7 +751,8 @@ run (void *cls, char *const *args, const char *cfgfile,
792 NULL); 751 NULL);
793 752
794#if VERBOSE 753#if VERBOSE
795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: Starting daemons.\n"); 754 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
755 "***************** test: Starting daemons.\n");
796 GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing", 756 GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing",
797 "use_progressbars", "YES"); 757 "use_progressbars", "YES");
798#endif 758#endif
@@ -806,7 +766,7 @@ run (void *cls, char *const *args, const char *cfgfile,
806 return; 766 return;
807 } 767 }
808 768
809 mesh_peers = GNUNET_malloc (sizeof(uint16_t) * (num_peers + 1)); 769 mesh_peers = GNUNET_malloc (sizeof (uint16_t) * (num_peers + 1));
810 770
811 if (GNUNET_OK != 771 if (GNUNET_OK !=
812 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small", 772 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small",
@@ -833,15 +793,15 @@ run (void *cls, char *const *args, const char *cfgfile,
833 &data_filename)) 793 &data_filename))
834 { 794 {
835 data_file = 795 data_file =
836 GNUNET_DISK_file_open (data_filename, 796 GNUNET_DISK_file_open (data_filename,
837 GNUNET_DISK_OPEN_READWRITE | 797 GNUNET_DISK_OPEN_READWRITE |
838 GNUNET_DISK_OPEN_CREATE, 798 GNUNET_DISK_OPEN_CREATE,
839 GNUNET_DISK_PERM_USER_READ | 799 GNUNET_DISK_PERM_USER_READ |
840 GNUNET_DISK_PERM_USER_WRITE); 800 GNUNET_DISK_PERM_USER_WRITE);
841 if (data_file == NULL) 801 if (data_file == NULL)
842 { 802 {
843 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", 803 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
844 data_filename); 804 data_filename);
845 GNUNET_free (data_filename); 805 GNUNET_free (data_filename);
846 } 806 }
847 } 807 }
@@ -939,8 +899,8 @@ main (int argc, char *argv[])
939 899
940 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, 900 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
941 "test_mesh_small", 901 "test_mesh_small",
942 gettext_noop ("Test mesh in a small network."), 902 gettext_noop ("Test mesh in a small network."), options,
943 options, &run, NULL); 903 &run, NULL);
944#if REMOVE_DIR 904#if REMOVE_DIR
945 GNUNET_DISK_directory_remove ("/tmp/test_mesh_small"); 905 GNUNET_DISK_directory_remove ("/tmp/test_mesh_small");
946#endif 906#endif
@@ -950,8 +910,7 @@ main (int argc, char *argv[])
950 "***************** test: FAILED! (%d/%d)\n", ok, ok_goal); 910 "***************** test: FAILED! (%d/%d)\n", ok, ok_goal);
951 return 1; 911 return 1;
952 } 912 }
953 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 913 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: success\n");
954 "***************** test: success\n");
955 return 0; 914 return 0;
956} 915}
957 916
diff --git a/src/mesh/test_mesh_small_unicast_far.c b/src/mesh/test_mesh_small_unicast_far.c
index e35922929..cc9995b48 100644
--- a/src/mesh/test_mesh_small_unicast_far.c
+++ b/src/mesh/test_mesh_small_unicast_far.c
@@ -148,7 +148,8 @@ shutdown_callback (void *cls, const char *emsg)
148 else 148 else
149 { 149 {
150#if VERBOSE 150#if VERBOSE
151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: All peers successfully shut down!\n"); 151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
152 "test: All peers successfully shut down!\n");
152#endif 153#endif
153 } 154 }
154} 155}
@@ -189,10 +190,10 @@ disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
190 "test: disconnecting mesh service of peers\n"); 191 "test: disconnecting mesh service of peers\n");
191 disconnect_task = GNUNET_SCHEDULER_NO_TASK; 192 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
192 GNUNET_MESH_disconnect(h1); 193 GNUNET_MESH_disconnect (h1);
193 GNUNET_MESH_disconnect(h2); 194 GNUNET_MESH_disconnect (h2);
194 GNUNET_SCHEDULER_cancel (shutdown_handle); 195 GNUNET_SCHEDULER_cancel (shutdown_handle);
195 shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); 196 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
196} 197}
197 198
198 199
@@ -208,16 +209,14 @@ disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
208 * (can be NULL -- that's not an error) 209 * (can be NULL -- that's not an error)
209 */ 210 */
210static void * 211static void *
211incoming_tunnel (void *cls, 212incoming_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel,
212 struct GNUNET_MESH_Tunnel * tunnel, 213 const struct GNUNET_PeerIdentity *initiator,
213 const struct GNUNET_PeerIdentity * initiator, 214 const struct GNUNET_ATS_Information *atsi)
214 const struct GNUNET_ATS_Information * atsi)
215{ 215{
216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Incoming tunnel from %s\n",
217 "test: Incoming tunnel from %s\n", 217 GNUNET_i2s (initiator));
218 GNUNET_i2s(initiator));
219 GNUNET_SCHEDULER_cancel (disconnect_task); 218 GNUNET_SCHEDULER_cancel (disconnect_task);
220 disconnect_task = GNUNET_SCHEDULER_add_now(&disconnect_mesh_peers, NULL); 219 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_mesh_peers, NULL);
221 ok = 0; 220 ok = 0;
222 return NULL; 221 return NULL;
223} 222}
@@ -238,7 +237,7 @@ tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel,
238#if VERBOSE 237#if VERBOSE
239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: tunnel disconnected\n"); 238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: tunnel disconnected\n");
240#endif 239#endif
241 240
242 return; 241 return;
243} 242}
244 243
@@ -251,9 +250,8 @@ tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel,
251static void 250static void
252dh (void *cls, const struct GNUNET_PeerIdentity *peer) 251dh (void *cls, const struct GNUNET_PeerIdentity *peer)
253{ 252{
254 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: peer %s disconnected\n",
255 "test: peer %s disconnected\n", 254 GNUNET_i2s (peer));
256 GNUNET_i2s(peer));
257 return; 255 return;
258} 256}
259 257
@@ -269,9 +267,8 @@ static void
269ch (void *cls, const struct GNUNET_PeerIdentity *peer, 267ch (void *cls, const struct GNUNET_PeerIdentity *peer,
270 const struct GNUNET_ATS_Information *atsi) 268 const struct GNUNET_ATS_Information *atsi)
271{ 269{
272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: peer %s connected\n",
273 "test: peer %s connected\n", 271 GNUNET_i2s (peer));
274 GNUNET_i2s(peer));
275 return; 272 return;
276} 273}
277 274
@@ -280,11 +277,12 @@ static void
280do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 277do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
281{ 278{
282 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n"); 279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n");
283 GNUNET_MESH_peer_request_connect_add(t, &d2->id); 280 GNUNET_MESH_peer_request_connect_add (t, &d2->id);
284 GNUNET_SCHEDULER_cancel (disconnect_task); 281 GNUNET_SCHEDULER_cancel (disconnect_task);
285 disconnect_task = GNUNET_SCHEDULER_add_delayed( 282 disconnect_task =
286 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30), 283 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
287 &disconnect_mesh_peers, NULL); 284 (GNUNET_TIME_UNIT_SECONDS, 30),
285 &disconnect_mesh_peers, NULL);
288} 286}
289 287
290 288
@@ -300,10 +298,9 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
300 298
301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: connect_mesh_service\n"); 299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: connect_mesh_service\n");
302 300
303 GNUNET_PEER_resolve(11, &id); 301 GNUNET_PEER_resolve (11, &id);
304 d2 = GNUNET_TESTING_daemon_get_by_id (pg, &id); 302 d2 = GNUNET_TESTING_daemon_get_by_id (pg, &id);
305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 303 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Peer searched: %s\n",
306 "test: Peer searched: %s\n",
307 GNUNET_i2s (&d2->id)); 304 GNUNET_i2s (&d2->id));
308 app = (GNUNET_MESH_ApplicationType) 0; 305 app = (GNUNET_MESH_ApplicationType) 0;
309 306
@@ -315,20 +312,10 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
315 "test: connecting to mesh service of peer %s\n", 312 "test: connecting to mesh service of peer %s\n",
316 GNUNET_i2s (&d2->id)); 313 GNUNET_i2s (&d2->id));
317#endif 314#endif
318 h1 = GNUNET_MESH_connect (d1->cfg, 315 h1 = GNUNET_MESH_connect (d1->cfg, 10, NULL, NULL, &tunnel_cleaner, handlers,
319 10,
320 NULL,
321 NULL,
322 &tunnel_cleaner,
323 handlers,
324 &app);
325 h2 = GNUNET_MESH_connect (d2->cfg,
326 10,
327 NULL,
328 &incoming_tunnel,
329 &tunnel_cleaner,
330 handlers,
331 &app); 316 &app);
317 h2 = GNUNET_MESH_connect (d2->cfg, 10, NULL, &incoming_tunnel,
318 &tunnel_cleaner, handlers, &app);
332#if VERBOSE 319#if VERBOSE
333 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 320 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
334 "test: connected to mesh service of peer %s\n", 321 "test: connected to mesh service of peer %s\n",
@@ -339,9 +326,9 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
339#endif 326#endif
340 t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, NULL); 327 t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, NULL);
341 test_task = 328 test_task =
342 GNUNET_SCHEDULER_add_delayed( 329 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
343 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 6), 330 (GNUNET_TIME_UNIT_SECONDS, 6), &do_test,
344 &do_test, NULL); 331 NULL);
345} 332}
346 333
347 334
@@ -362,8 +349,8 @@ peergroup_ready (void *cls, const char *emsg)
362 { 349 {
363 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 350 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
364 "test: Peergroup callback called with error, aborting test!\n"); 351 "test: Peergroup callback called with error, aborting test!\n");
365 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 352 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Error from testing: `%s'\n",
366 "test: Error from testing: `%s'\n", emsg); 353 emsg);
367 ok++; 354 ok++;
368 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 355 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
369 return; 356 return;
@@ -373,8 +360,7 @@ peergroup_ready (void *cls, const char *emsg)
373 "************************************************************\n"); 360 "************************************************************\n");
374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
375 "test: Peer Group started successfully!\n"); 362 "test: Peer Group started successfully!\n");
376 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 363 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Have %u connections\n",
377 "test: Have %u connections\n",
378 total_connections); 364 total_connections);
379#endif 365#endif
380 366
@@ -390,18 +376,14 @@ peergroup_ready (void *cls, const char *emsg)
390 for (i = 0; i < num_peers; i++) 376 for (i = 0; i < num_peers; i++)
391 { 377 {
392 d1 = GNUNET_TESTING_daemon_get (pg, i); 378 d1 = GNUNET_TESTING_daemon_get (pg, i);
393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 379 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: %u: %s\n",
394 "test: %u: %s\n", 380 GNUNET_PEER_intern (&d1->id), GNUNET_i2s (&d1->id));
395 GNUNET_PEER_intern(&d1->id),
396 GNUNET_i2s (&d1->id));
397 } 381 }
398 d1 = GNUNET_TESTING_daemon_get (pg, 0); 382 d1 = GNUNET_TESTING_daemon_get (pg, 0);
399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 383 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Peer looking: %s\n",
400 "test: Peer looking: %s\n",
401 GNUNET_i2s (&d1->id)); 384 GNUNET_i2s (&d1->id));
402 385
403 GNUNET_SCHEDULER_add_now (&connect_mesh_service, 386 GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL);
404 NULL);
405 disconnect_task = 387 disconnect_task =
406 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL); 388 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL);
407 389
@@ -437,8 +419,7 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *first,
437 else 419 else
438 { 420 {
439 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 421 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
440 "test: Problem with new connection (%s)\n", 422 "test: Problem with new connection (%s)\n", emsg);
441 emsg);
442 } 423 }
443 424
444} 425}
@@ -495,7 +476,7 @@ run (void *cls, char *const *args, const char *cfgfile,
495 } 476 }
496 } 477 }
497 478
498 mesh_peers = GNUNET_malloc (sizeof(GNUNET_PEER_Id) * (num_peers + 1)); 479 mesh_peers = GNUNET_malloc (sizeof (GNUNET_PEER_Id) * (num_peers + 1));
499 480
500 if (GNUNET_OK != 481 if (GNUNET_OK !=
501 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small", 482 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small",
@@ -522,15 +503,15 @@ run (void *cls, char *const *args, const char *cfgfile,
522 &data_filename)) 503 &data_filename))
523 { 504 {
524 data_file = 505 data_file =
525 GNUNET_DISK_file_open (data_filename, 506 GNUNET_DISK_file_open (data_filename,
526 GNUNET_DISK_OPEN_READWRITE | 507 GNUNET_DISK_OPEN_READWRITE |
527 GNUNET_DISK_OPEN_CREATE, 508 GNUNET_DISK_OPEN_CREATE,
528 GNUNET_DISK_PERM_USER_READ | 509 GNUNET_DISK_PERM_USER_READ |
529 GNUNET_DISK_PERM_USER_WRITE); 510 GNUNET_DISK_PERM_USER_WRITE);
530 if (data_file == NULL) 511 if (data_file == NULL)
531 { 512 {
532 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", 513 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
533 data_filename); 514 data_filename);
534 GNUNET_free (data_filename); 515 GNUNET_free (data_filename);
535 } 516 }
536 } 517 }
@@ -585,8 +566,8 @@ int
585main (int argc, char *argv[]) 566main (int argc, char *argv[])
586{ 567{
587 GNUNET_PROGRAM_run (argc, argv, "test_mesh_small_unicast", 568 GNUNET_PROGRAM_run (argc, argv, "test_mesh_small_unicast",
588 gettext_noop ("Test mesh unicast in a small network."), options, 569 gettext_noop ("Test mesh unicast in a small network."),
589 &run, NULL); 570 options, &run, NULL);
590#if REMOVE_DIR 571#if REMOVE_DIR
591 GNUNET_DISK_directory_remove ("/tmp/test_mesh_small_unicast"); 572 GNUNET_DISK_directory_remove ("/tmp/test_mesh_small_unicast");
592#endif 573#endif
diff --git a/src/mesh/test_mesh_tree_api.c b/src/mesh/test_mesh_tree_api.c
index 8df8fe19b..b1bdcd693 100644
--- a/src/mesh/test_mesh_tree_api.c
+++ b/src/mesh/test_mesh_tree_api.c
@@ -39,16 +39,16 @@
39 39
40int failed; 40int failed;
41int cb_call; 41int cb_call;
42struct GNUNET_PeerIdentity* pi[10]; 42struct GNUNET_PeerIdentity *pi[10];
43struct MeshTunnelTree *tree; 43struct MeshTunnelTree *tree;
44 44
45static void 45static void
46cb (void *cls, GNUNET_PEER_Id peer_id) 46cb (void *cls, GNUNET_PEER_Id peer_id)
47{ 47{
48 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: CB: Disconnected %u\n", peer_id); 48 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: CB: Disconnected %u\n", peer_id);
49 if(0 == cb_call) 49 if (0 == cb_call)
50 { 50 {
51 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: and it shouldn't!\n"); 51 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: and it shouldn't!\n");
52 failed++; 52 failed++;
53 } 53 }
54 cb_call--; 54 cb_call--;
@@ -64,10 +64,8 @@ cb (void *cls, GNUNET_PEER_Id peer_id)
64 * @param first_hop Short ID of the expected first hop towards the peer. 64 * @param first_hop Short ID of the expected first hop towards the peer.
65 */ 65 */
66static void 66static void
67test_assert (GNUNET_PEER_Id peer_id, 67test_assert (GNUNET_PEER_Id peer_id, enum MeshPeerState status,
68 enum MeshPeerState status, 68 unsigned int children, GNUNET_PEER_Id first_hop)
69 unsigned int children,
70 GNUNET_PEER_Id first_hop)
71{ 69{
72 struct MeshTunnelTreeNode *n; 70 struct MeshTunnelTreeNode *n;
73 struct MeshTunnelTreeNode *c; 71 struct MeshTunnelTreeNode *c;
@@ -75,58 +73,57 @@ test_assert (GNUNET_PEER_Id peer_id,
75 int pre_failed; 73 int pre_failed;
76 74
77 pre_failed = failed; 75 pre_failed = failed;
78 n = tree_find_peer(tree, peer_id); 76 n = tree_find_peer (tree, peer_id);
79 if (n->peer != peer_id) 77 if (n->peer != peer_id)
80 { 78 {
81 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 79 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
82 "Retrieved peer has wrong ID! (%u, %u)\n", 80 "Retrieved peer has wrong ID! (%u, %u)\n", n->peer, peer_id);
83 n->peer, peer_id);
84 failed++; 81 failed++;
85 } 82 }
86 if (n->status != status) 83 if (n->status != status)
87 { 84 {
88 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 85 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
89 "Retrieved peer has wrong status! (%u, %u)\n", 86 "Retrieved peer has wrong status! (%u, %u)\n", n->status,
90 n->status, status); 87 status);
91 failed++; 88 failed++;
92 } 89 }
93 for (c = n->children_head, i = 0; NULL != c; c = c->next, i++); 90 for (c = n->children_head, i = 0; NULL != c; c = c->next, i++) ;
94 if (i != children) 91 if (i != children)
95 { 92 {
96 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 93 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
97 "Retrieved peer wrong has number of children! (%u, %u)\n", 94 "Retrieved peer wrong has number of children! (%u, %u)\n", i,
98 i, children); 95 children);
99 failed++; 96 failed++;
100 } 97 }
101 if (0 != first_hop && 98 if (0 != first_hop &&
102 GNUNET_PEER_search(path_get_first_hop(tree, peer_id)) != first_hop) 99 GNUNET_PEER_search (path_get_first_hop (tree, peer_id)) != first_hop)
103 { 100 {
104 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 101 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Wrong first hop! (%u, %u)\n",
105 "Wrong first hop! (%u, %u)\n", 102 GNUNET_PEER_search (path_get_first_hop (tree, peer_id)),
106 GNUNET_PEER_search(path_get_first_hop(tree, peer_id)), 103 first_hop);
107 first_hop);
108 failed++; 104 failed++;
109 } 105 }
110 if (pre_failed != failed) 106 if (pre_failed != failed)
111 { 107 {
112 struct GNUNET_PeerIdentity id; 108 struct GNUNET_PeerIdentity id;
109
113 GNUNET_PEER_resolve (peer_id, &id); 110 GNUNET_PEER_resolve (peer_id, &id);
114 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 111 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
115 "*** Peer %s (%u) has failed %d checks! (real, expected)\n", 112 "*** Peer %s (%u) has failed %d checks! (real, expected)\n",
116 GNUNET_i2s (&id), peer_id, failed - pre_failed); 113 GNUNET_i2s (&id), peer_id, failed - pre_failed);
117 } 114 }
118} 115}
119 116
120 117
121static void 118static void
122finish(void) 119finish (void)
123{ 120{
124 unsigned int i; 121 unsigned int i;
125 122
126 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Finishing...\n"); 123 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Finishing...\n");
127 for (i = 0; i < 10; i++) 124 for (i = 0; i < 10; i++)
128 { 125 {
129 GNUNET_free(pi[i]); 126 GNUNET_free (pi[i]);
130 } 127 }
131} 128}
132 129
@@ -138,7 +135,7 @@ get_pi (uint32_t id)
138{ 135{
139 struct GNUNET_PeerIdentity *pi; 136 struct GNUNET_PeerIdentity *pi;
140 137
141 pi = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); 138 pi = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
142 pi->hashPubKey.bits[0] = id + 1; 139 pi->hashPubKey.bits[0] = id + 1;
143 return pi; 140 return pi;
144} 141}
@@ -164,11 +161,10 @@ main (int argc, char *argv[])
164 NULL); 161 NULL);
165 for (i = 0; i < 10; i++) 162 for (i = 0; i < 10; i++)
166 { 163 {
167 pi[i] = get_pi(i); 164 pi[i] = get_pi (i);
168 GNUNET_break (i + 1 == GNUNET_PEER_intern(pi[i])); 165 GNUNET_break (i + 1 == GNUNET_PEER_intern (pi[i]));
169 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Peer %u: %s\n", 166 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer %u: %s\n", i + 1,
170 i + 1, 167 GNUNET_h2s (&pi[i]->hashPubKey));
171 GNUNET_h2s(&pi[i]->hashPubKey));
172 } 168 }
173 tree = tree_new (1); 169 tree = tree_new (1);
174 tree->me = tree->root; 170 tree->me = tree->root;
@@ -179,37 +175,37 @@ main (int argc, char *argv[])
179 path->peers[3] = 4; 175 path->peers[3] = 4;
180 path->length = 4; 176 path->length = 4;
181 177
182 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3 4\n"); 178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3 4\n");
183 tree_add_path(tree, path, &cb, NULL); 179 tree_add_path (tree, path, &cb, NULL);
184 tree_debug(tree); 180 tree_debug (tree);
185 path1 = tree_get_path_to_peer(tree, 4); 181 path1 = tree_get_path_to_peer (tree, 4);
186 if (path->length != path1->length || 182 if (path->length != path1->length ||
187 memcmp(path->peers, path1->peers, path->length) != 0) 183 memcmp (path->peers, path1->peers, path->length) != 0)
188 { 184 {
189 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved path != original\n"); 185 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Retrieved path != original\n");
190 failed++; 186 failed++;
191 } 187 }
192 path_destroy(path1); 188 path_destroy (path1);
193 test_assert (4, MESH_PEER_SEARCHING, 0, 2); 189 test_assert (4, MESH_PEER_SEARCHING, 0, 2);
194 test_assert (3, MESH_PEER_RELAY, 1, 0); 190 test_assert (3, MESH_PEER_RELAY, 1, 0);
195 test_assert (2, MESH_PEER_RELAY, 1, 0); 191 test_assert (2, MESH_PEER_RELAY, 1, 0);
196 test_assert (1, MESH_PEER_ROOT, 1, 0); 192 test_assert (1, MESH_PEER_ROOT, 1, 0);
197 193
198 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding second path: 1 2 3\n"); 194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding second path: 1 2 3\n");
199 path->length--; 195 path->length--;
200 tree_add_path(tree, path, &cb, NULL); 196 tree_add_path (tree, path, &cb, NULL);
201 tree_debug(tree); 197 tree_debug (tree);
202 198
203 test_assert (4, MESH_PEER_SEARCHING, 0, 2); 199 test_assert (4, MESH_PEER_SEARCHING, 0, 2);
204 test_assert (3, MESH_PEER_SEARCHING, 1, 2); 200 test_assert (3, MESH_PEER_SEARCHING, 1, 2);
205 test_assert (2, MESH_PEER_RELAY, 1, 0); 201 test_assert (2, MESH_PEER_RELAY, 1, 0);
206 test_assert (1, MESH_PEER_ROOT, 1, 0); 202 test_assert (1, MESH_PEER_ROOT, 1, 0);
207 203
208 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding third path...\n"); 204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding third path...\n");
209 path->length++; 205 path->length++;
210 path->peers[3] = 5; 206 path->peers[3] = 5;
211 tree_add_path(tree, path, &cb, NULL); 207 tree_add_path (tree, path, &cb, NULL);
212 tree_debug(tree); 208 tree_debug (tree);
213 209
214 test_assert (5, MESH_PEER_SEARCHING, 0, 2); 210 test_assert (5, MESH_PEER_SEARCHING, 0, 2);
215 test_assert (4, MESH_PEER_SEARCHING, 0, 2); 211 test_assert (4, MESH_PEER_SEARCHING, 0, 2);
@@ -217,20 +213,20 @@ main (int argc, char *argv[])
217 test_assert (2, MESH_PEER_RELAY, 1, 0); 213 test_assert (2, MESH_PEER_RELAY, 1, 0);
218 test_assert (1, MESH_PEER_ROOT, 1, 0); 214 test_assert (1, MESH_PEER_ROOT, 1, 0);
219 215
220 node = tree_find_peer(tree, 5); 216 node = tree_find_peer (tree, 5);
221 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Deleting third path...\n"); 217 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Deleting third path...\n");
222 node->status = MESH_PEER_READY; 218 node->status = MESH_PEER_READY;
223 cb_call = 1; 219 cb_call = 1;
224 node2 = tree_del_path(tree, 5, &cb, NULL); 220 node2 = tree_del_path (tree, 5, &cb, NULL);
225 tree_debug(tree); 221 tree_debug (tree);
226 if (cb_call != 0) 222 if (cb_call != 0)
227 { 223 {
228 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call); 224 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call);
229 failed++; 225 failed++;
230 } 226 }
231 if (node2->peer != 5) 227 if (node2->peer != 5)
232 { 228 {
233 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); 229 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
234 failed++; 230 failed++;
235 } 231 }
236 232
@@ -239,20 +235,20 @@ main (int argc, char *argv[])
239 test_assert (2, MESH_PEER_RELAY, 1, 0); 235 test_assert (2, MESH_PEER_RELAY, 1, 0);
240 test_assert (1, MESH_PEER_ROOT, 1, 0); 236 test_assert (1, MESH_PEER_ROOT, 1, 0);
241 237
242 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Destroying node copy...\n"); 238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Destroying node copy...\n");
243 GNUNET_free (node2); 239 GNUNET_free (node2);
244 240
245 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
246 "test: Adding new shorter first path...\n"); 242 "test: Adding new shorter first path...\n");
247 path->length = 2; 243 path->length = 2;
248 path->peers[1] = 4; 244 path->peers[1] = 4;
249 cb_call = 1; 245 cb_call = 1;
250 tree_find_peer(tree, 4)->status = MESH_PEER_READY; 246 tree_find_peer (tree, 4)->status = MESH_PEER_READY;
251 tree_add_path(tree, path, &cb, NULL); 247 tree_add_path (tree, path, &cb, NULL);
252 tree_debug(tree); 248 tree_debug (tree);
253 if (cb_call != 0) 249 if (cb_call != 0)
254 { 250 {
255 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call); 251 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call);
256 failed++; 252 failed++;
257 } 253 }
258 254
@@ -265,35 +261,35 @@ main (int argc, char *argv[])
265 GNUNET_free (path); 261 GNUNET_free (path);
266 tree_destroy (tree); 262 tree_destroy (tree);
267 263
268 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test:\n"); 264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test:\n");
269 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Testing relay trees\n"); 265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Testing relay trees\n");
270 for (i = 0; i < 10; i++) 266 for (i = 0; i < 10; i++)
271 { 267 {
272 GNUNET_break (i + 1 == GNUNET_PEER_intern(pi[i])); 268 GNUNET_break (i + 1 == GNUNET_PEER_intern (pi[i]));
273 } 269 }
274 tree = tree_new(1); 270 tree = tree_new (1);
275 path = path_new (3); 271 path = path_new (3);
276 path->peers[0] = 1; 272 path->peers[0] = 1;
277 path->peers[1] = 2; 273 path->peers[1] = 2;
278 path->peers[2] = 3; 274 path->peers[2] = 3;
279 path->length = 3; 275 path->length = 3;
280 276
281 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3\n"); 277 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3\n");
282 tree_add_path(tree, path, &cb, NULL); 278 tree_add_path (tree, path, &cb, NULL);
283 tree_debug(tree); 279 tree_debug (tree);
284 tree_set_me (tree, 2); 280 tree_set_me (tree, 2);
285 281
286 test_assert (3, MESH_PEER_SEARCHING, 0, 3); 282 test_assert (3, MESH_PEER_SEARCHING, 0, 3);
287 test_assert (2, MESH_PEER_RELAY, 1, 0); 283 test_assert (2, MESH_PEER_RELAY, 1, 0);
288 test_assert (1, MESH_PEER_ROOT, 1, 0); 284 test_assert (1, MESH_PEER_ROOT, 1, 0);
289 285
290 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding same path: 1 2 3\n"); 286 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Adding same path: 1 2 3\n");
291 tree_add_path(tree, path, &cb, NULL); 287 tree_add_path (tree, path, &cb, NULL);
292 288
293 GNUNET_free (path->peers); 289 GNUNET_free (path->peers);
294 GNUNET_free (path); 290 GNUNET_free (path);
295 tree_destroy (tree); 291 tree_destroy (tree);
296 finish(); 292 finish ();
297 if (failed > 0) 293 if (failed > 0)
298 { 294 {
299 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u tests failed\n", failed); 295 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u tests failed\n", failed);
diff --git a/src/nat/nat.c b/src/nat/nat.c
index 2040451d5..802b241e4 100644
--- a/src/nat/nat.c
+++ b/src/nat/nat.c
@@ -649,8 +649,9 @@ process_interfaces (void *cls, const char *name, int isDefault,
649 ip = &s4->sin_addr; 649 ip = &s4->sin_addr;
650 650
651 /* Check if address is in 127.0.0.0/8 */ 651 /* Check if address is in 127.0.0.0/8 */
652 uint32_t address = ntohl((in_addr_t)(s4->sin_addr.s_addr)); 652 uint32_t address = ntohl ((in_addr_t) (s4->sin_addr.s_addr));
653 uint32_t value = (address & 0xFF000000) ^ 0x7F000000; 653 uint32_t value = (address & 0xFF000000) ^ 0x7F000000;
654
654 if ((h->return_localaddress == GNUNET_NO) && (value == 0)) 655 if ((h->return_localaddress == GNUNET_NO) && (value == 0))
655 { 656 {
656 return GNUNET_OK; 657 return GNUNET_OK;
@@ -1139,7 +1140,8 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, int is_tcp,
1139 h->use_localaddresses = 1140 h->use_localaddresses =
1140 GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "USE_LOCALADDR"); 1141 GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "USE_LOCALADDR");
1141 h->return_localaddress = 1142 h->return_localaddress =
1142 GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "RETURN_LOCAL_ADDRESSES"); 1143 GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat",
1144 "RETURN_LOCAL_ADDRESSES");
1143 1145
1144 h->use_hostname = 1146 h->use_hostname =
1145 GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "USE_HOSTNAME"); 1147 GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "USE_HOSTNAME");
diff --git a/src/nat/test_nat_test.c b/src/nat/test_nat_test.c
index 0786bb04b..c080e8ff3 100644
--- a/src/nat/test_nat_test.c
+++ b/src/nat/test_nat_test.c
@@ -111,7 +111,8 @@ main (int argc, char *const argv[])
111 nat_res = GNUNET_OS_check_helper_binary ("gnunet-nat-server"); 111 nat_res = GNUNET_OS_check_helper_binary ("gnunet-nat-server");
112 if (GNUNET_SYSERR == nat_res) 112 if (GNUNET_SYSERR == nat_res)
113 { 113 {
114 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Cannot run NAT test: `%s' file not found\n", 114 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
115 "Cannot run NAT test: `%s' file not found\n",
115 "gnunet-nat-server"); 116 "gnunet-nat-server");
116 return 0; 117 return 0;
117 } 118 }
diff --git a/src/nse/gnunet-nse-profiler.c b/src/nse/gnunet-nse-profiler.c
index ecd594e86..4ad689be9 100644
--- a/src/nse/gnunet-nse-profiler.c
+++ b/src/nse/gnunet-nse-profiler.c
@@ -589,14 +589,14 @@ run (void *cls, char *const *args, const char *cfgfile,
589 &data_filename)) 589 &data_filename))
590 { 590 {
591 data_file = 591 data_file =
592 GNUNET_DISK_file_open (data_filename, 592 GNUNET_DISK_file_open (data_filename,
593 GNUNET_DISK_OPEN_READWRITE | 593 GNUNET_DISK_OPEN_READWRITE |
594 GNUNET_DISK_OPEN_CREATE, 594 GNUNET_DISK_OPEN_CREATE,
595 GNUNET_DISK_PERM_USER_READ | 595 GNUNET_DISK_PERM_USER_READ |
596 GNUNET_DISK_PERM_USER_WRITE); 596 GNUNET_DISK_PERM_USER_WRITE);
597 if (data_file == NULL) 597 if (data_file == NULL)
598 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", 598 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
599 data_filename); 599 data_filename);
600 GNUNET_free (data_filename); 600 GNUNET_free (data_filename);
601 } 601 }
602 602
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c
index d9687acd2..a0e7923ac 100644
--- a/src/nse/gnunet-service-nse.c
+++ b/src/nse/gnunet-service-nse.c
@@ -339,7 +339,7 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em)
339 std_dev = sqrt (variance); 339 std_dev = sqrt (variance);
340 current_std_dev = std_dev; 340 current_std_dev = std_dev;
341 current_size_estimate = mean; 341 current_size_estimate = mean;
342 342
343 em->header.size = htons (sizeof (struct GNUNET_NSE_ClientMessage)); 343 em->header.size = htons (sizeof (struct GNUNET_NSE_ClientMessage));
344 em->header.type = htons (GNUNET_MESSAGE_TYPE_NSE_ESTIMATE); 344 em->header.type = htons (GNUNET_MESSAGE_TYPE_NSE_ESTIMATE);
345 em->reserved = htonl (0); 345 em->reserved = htonl (0);
@@ -637,7 +637,8 @@ setup_flood_message (unsigned int slot, struct GNUNET_TIME_Absolute ts)
637 fm->pkey = my_public_key; 637 fm->pkey = my_public_key;
638 fm->proof_of_work = my_proof; 638 fm->proof_of_work = my_proof;
639 GNUNET_assert (GNUNET_OK == 639 GNUNET_assert (GNUNET_OK ==
640 GNUNET_CRYPTO_rsa_sign (my_private_key, &fm->purpose, &fm->signature)); 640 GNUNET_CRYPTO_rsa_sign (my_private_key, &fm->purpose,
641 &fm->signature));
641} 642}
642 643
643 644
@@ -826,9 +827,11 @@ find_proof (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
826 { 827 {
827 size_estimate_messages[i].proof_of_work = my_proof; 828 size_estimate_messages[i].proof_of_work = my_proof;
828 GNUNET_assert (GNUNET_OK == 829 GNUNET_assert (GNUNET_OK ==
829 GNUNET_CRYPTO_rsa_sign (my_private_key, 830 GNUNET_CRYPTO_rsa_sign (my_private_key,
830 &size_estimate_messages[i].purpose, 831 &size_estimate_messages
831 &size_estimate_messages[i].signature)); 832 [i].purpose,
833 &size_estimate_messages
834 [i].signature));
832 } 835 }
833 write_proof (); 836 write_proof ();
834 return; 837 return;
@@ -944,7 +947,7 @@ static int
944handle_p2p_size_estimate (void *cls, const struct GNUNET_PeerIdentity *peer, 947handle_p2p_size_estimate (void *cls, const struct GNUNET_PeerIdentity *peer,
945 const struct GNUNET_MessageHeader *message, 948 const struct GNUNET_MessageHeader *message,
946 const struct GNUNET_ATS_Information *atsi, 949 const struct GNUNET_ATS_Information *atsi,
947 unsigned int atsi_count) 950 unsigned int atsi_count)
948{ 951{
949 const struct GNUNET_NSE_FloodMessage *incoming_flood; 952 const struct GNUNET_NSE_FloodMessage *incoming_flood;
950 struct GNUNET_TIME_Absolute ts; 953 struct GNUNET_TIME_Absolute ts;
@@ -1100,7 +1103,7 @@ handle_p2p_size_estimate (void *cls, const struct GNUNET_PeerIdentity *peer,
1100static void 1103static void
1101handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, 1104handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
1102 const struct GNUNET_ATS_Information *atsi, 1105 const struct GNUNET_ATS_Information *atsi,
1103 unsigned int atsi_count) 1106 unsigned int atsi_count)
1104{ 1107{
1105 struct NSEPeerEntry *peer_entry; 1108 struct NSEPeerEntry *peer_entry;
1106 1109
diff --git a/src/statistics/statistics_api.c b/src/statistics/statistics_api.c
index 5d419f637..8e80a4d75 100644
--- a/src/statistics/statistics_api.c
+++ b/src/statistics/statistics_api.c
@@ -243,22 +243,24 @@ struct GNUNET_STATISTICS_Handle
243/** 243/**
244 * Schedule the next action to be performed. 244 * Schedule the next action to be performed.
245 */ 245 */
246static void schedule_action (struct GNUNET_STATISTICS_Handle *h); 246static void
247schedule_action (struct GNUNET_STATISTICS_Handle *h);
247 248
248/** 249/**
249 * Try to (re)connect to the statistics service. 250 * Try to (re)connect to the statistics service.
250 * 251 *
251 * @return GNUNET_YES on success, GNUNET_NO on failure. 252 * @return GNUNET_YES on success, GNUNET_NO on failure.
252 */ 253 */
253static int try_connect (struct GNUNET_STATISTICS_Handle *ret); 254static int
255try_connect (struct GNUNET_STATISTICS_Handle *ret);
254 256
255 257
256static void 258static void
257insert_ai (struct GNUNET_STATISTICS_Handle *h, 259insert_ai (struct GNUNET_STATISTICS_Handle *h,
258 struct GNUNET_STATISTICS_GetHandle *ai) 260 struct GNUNET_STATISTICS_GetHandle *ai)
259{ 261{
260 GNUNET_CONTAINER_DLL_insert_after (h->action_head, h->action_tail, 262 GNUNET_CONTAINER_DLL_insert_after (h->action_head, h->action_tail,
261 h->action_tail, ai); 263 h->action_tail, ai);
262 if (h->action_head == ai) 264 if (h->action_head == ai)
263 schedule_action (h); 265 schedule_action (h);
264} 266}
@@ -266,7 +268,7 @@ insert_ai (struct GNUNET_STATISTICS_Handle *h,
266 268
267static void 269static void
268schedule_watch_request (struct GNUNET_STATISTICS_Handle *h, 270schedule_watch_request (struct GNUNET_STATISTICS_Handle *h,
269 struct GNUNET_STATISTICS_WatchEntry *watch) 271 struct GNUNET_STATISTICS_WatchEntry *watch)
270{ 272{
271 273
272 struct GNUNET_STATISTICS_GetHandle *ai; 274 struct GNUNET_STATISTICS_GetHandle *ai;
@@ -276,18 +278,18 @@ schedule_watch_request (struct GNUNET_STATISTICS_Handle *h,
276 278
277 GNUNET_assert (h != NULL); 279 GNUNET_assert (h != NULL);
278 if (GNUNET_YES != try_connect (h)) 280 if (GNUNET_YES != try_connect (h))
279 { 281 {
280 schedule_action (h); 282 schedule_action (h);
281 return; 283 return;
282 } 284 }
283 slen = strlen (watch->subsystem) + 1; 285 slen = strlen (watch->subsystem) + 1;
284 nlen = strlen (watch->name) + 1; 286 nlen = strlen (watch->name) + 1;
285 nsize = sizeof (struct GNUNET_MessageHeader) + slen + nlen; 287 nsize = sizeof (struct GNUNET_MessageHeader) + slen + nlen;
286 if (nsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 288 if (nsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
287 { 289 {
288 GNUNET_break (0); 290 GNUNET_break (0);
289 return; 291 return;
290 } 292 }
291 ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle)); 293 ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle));
292 ai->sh = h; 294 ai->sh = h;
293 ai->subsystem = GNUNET_strdup (watch->subsystem); 295 ai->subsystem = GNUNET_strdup (watch->subsystem);
@@ -315,11 +317,11 @@ try_connect (struct GNUNET_STATISTICS_Handle *ret)
315 return GNUNET_YES; 317 return GNUNET_YES;
316 ret->client = GNUNET_CLIENT_connect ("statistics", ret->cfg); 318 ret->client = GNUNET_CLIENT_connect ("statistics", ret->cfg);
317 if (ret->client != NULL) 319 if (ret->client != NULL)
318 { 320 {
319 for (i = 0; i < ret->watches_size; i++) 321 for (i = 0; i < ret->watches_size; i++)
320 schedule_watch_request (ret, ret->watches[i]); 322 schedule_watch_request (ret, ret->watches[i]);
321 return GNUNET_YES; 323 return GNUNET_YES;
322 } 324 }
323#if DEBUG_STATISTICS 325#if DEBUG_STATISTICS
324 LOG (GNUNET_ERROR_TYPE_DEBUG, 326 LOG (GNUNET_ERROR_TYPE_DEBUG,
325 _("Failed to connect to statistics service!\n")); 327 _("Failed to connect to statistics service!\n"));
@@ -351,11 +353,11 @@ finish (struct GNUNET_STATISTICS_Handle *h, int code)
351 h->current = NULL; 353 h->current = NULL;
352 schedule_action (h); 354 schedule_action (h);
353 if (pos != NULL) 355 if (pos != NULL)
354 { 356 {
355 if (pos->cont != NULL) 357 if (pos->cont != NULL)
356 pos->cont (pos->cls, code); 358 pos->cont (pos->cls, code);
357 free_action_item (pos); 359 free_action_item (pos);
358 } 360 }
359} 361}
360 362
361 363
@@ -366,7 +368,7 @@ finish (struct GNUNET_STATISTICS_Handle *h, int code)
366 */ 368 */
367static int 369static int
368process_message (struct GNUNET_STATISTICS_Handle *h, 370process_message (struct GNUNET_STATISTICS_Handle *h,
369 const struct GNUNET_MessageHeader *msg) 371 const struct GNUNET_MessageHeader *msg)
370{ 372{
371 char *service; 373 char *service;
372 char *name; 374 char *name;
@@ -374,45 +376,43 @@ process_message (struct GNUNET_STATISTICS_Handle *h,
374 uint16_t size; 376 uint16_t size;
375 377
376 if (h->current->aborted) 378 if (h->current->aborted)
377 { 379 {
378#if DEBUG_STATISTICS 380#if DEBUG_STATISTICS
379 LOG (GNUNET_ERROR_TYPE_DEBUG, 381 LOG (GNUNET_ERROR_TYPE_DEBUG, "Iteration was aborted, ignoring VALUE\n");
380 "Iteration was aborted, ignoring VALUE\n");
381#endif 382#endif
382 return GNUNET_OK; /* don't bother */ 383 return GNUNET_OK; /* don't bother */
383 } 384 }
384 size = ntohs (msg->size); 385 size = ntohs (msg->size);
385 if (size < sizeof (struct GNUNET_STATISTICS_ReplyMessage)) 386 if (size < sizeof (struct GNUNET_STATISTICS_ReplyMessage))
386 { 387 {
387 GNUNET_break (0); 388 GNUNET_break (0);
388 return GNUNET_SYSERR; 389 return GNUNET_SYSERR;
389 } 390 }
390 smsg = (const struct GNUNET_STATISTICS_ReplyMessage *) msg; 391 smsg = (const struct GNUNET_STATISTICS_ReplyMessage *) msg;
391 size -= sizeof (struct GNUNET_STATISTICS_ReplyMessage); 392 size -= sizeof (struct GNUNET_STATISTICS_ReplyMessage);
392 if (size != 393 if (size !=
393 GNUNET_STRINGS_buffer_tokenize ((const char *) &smsg[1], size, 2, 394 GNUNET_STRINGS_buffer_tokenize ((const char *) &smsg[1], size, 2,
394 &service, &name)) 395 &service, &name))
395 { 396 {
396 GNUNET_break (0); 397 GNUNET_break (0);
397 return GNUNET_SYSERR; 398 return GNUNET_SYSERR;
398 } 399 }
399#if DEBUG_STATISTICS 400#if DEBUG_STATISTICS
400 LOG (GNUNET_ERROR_TYPE_DEBUG, 401 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received valid statistic on `%s:%s': %llu\n",
401 "Received valid statistic on `%s:%s': %llu\n", service, name, 402 service, name, GNUNET_ntohll (smsg->value));
402 GNUNET_ntohll (smsg->value));
403#endif 403#endif
404 if (GNUNET_OK != 404 if (GNUNET_OK !=
405 h->current->proc (h->current->cls, service, name, 405 h->current->proc (h->current->cls, service, name,
406 GNUNET_ntohll (smsg->value), 406 GNUNET_ntohll (smsg->value),
407 0 != 407 0 !=
408 (ntohl (smsg->uid) & GNUNET_STATISTICS_PERSIST_BIT))) 408 (ntohl (smsg->uid) & GNUNET_STATISTICS_PERSIST_BIT)))
409 { 409 {
410#if DEBUG_STATISTICS 410#if DEBUG_STATISTICS
411 LOG (GNUNET_ERROR_TYPE_DEBUG, 411 LOG (GNUNET_ERROR_TYPE_DEBUG,
412 "Processing of remaining statistics aborted by client.\n"); 412 "Processing of remaining statistics aborted by client.\n");
413#endif 413#endif
414 h->current->aborted = GNUNET_YES; 414 h->current->aborted = GNUNET_YES;
415 } 415 }
416#if DEBUG_STATISTICS 416#if DEBUG_STATISTICS
417 LOG (GNUNET_ERROR_TYPE_DEBUG, "VALUE processed successfully\n"); 417 LOG (GNUNET_ERROR_TYPE_DEBUG, "VALUE processed successfully\n");
418#endif 418#endif
@@ -422,30 +422,29 @@ process_message (struct GNUNET_STATISTICS_Handle *h,
422 422
423static int 423static int
424process_watch_value (struct GNUNET_STATISTICS_Handle *h, 424process_watch_value (struct GNUNET_STATISTICS_Handle *h,
425 const struct GNUNET_MessageHeader *msg) 425 const struct GNUNET_MessageHeader *msg)
426{ 426{
427 const struct GNUNET_STATISTICS_WatchValueMessage *wvm; 427 const struct GNUNET_STATISTICS_WatchValueMessage *wvm;
428 struct GNUNET_STATISTICS_WatchEntry *w; 428 struct GNUNET_STATISTICS_WatchEntry *w;
429 uint32_t wid; 429 uint32_t wid;
430 430
431 if (sizeof (struct GNUNET_STATISTICS_WatchValueMessage) != 431 if (sizeof (struct GNUNET_STATISTICS_WatchValueMessage) != ntohs (msg->size))
432 ntohs (msg->size)) 432 {
433 { 433 GNUNET_break (0);
434 GNUNET_break (0); 434 return GNUNET_SYSERR;
435 return GNUNET_SYSERR; 435 }
436 }
437 wvm = (const struct GNUNET_STATISTICS_WatchValueMessage *) msg; 436 wvm = (const struct GNUNET_STATISTICS_WatchValueMessage *) msg;
438 GNUNET_break (0 == ntohl (wvm->reserved)); 437 GNUNET_break (0 == ntohl (wvm->reserved));
439 wid = ntohl (wvm->wid); 438 wid = ntohl (wvm->wid);
440 if (wid >= h->watches_size) 439 if (wid >= h->watches_size)
441 { 440 {
442 GNUNET_break (0); 441 GNUNET_break (0);
443 return GNUNET_SYSERR; 442 return GNUNET_SYSERR;
444 } 443 }
445 w = h->watches[wid]; 444 w = h->watches[wid];
446 (void) w->proc (w->proc_cls, w->subsystem, w->name, 445 (void) w->proc (w->proc_cls, w->subsystem, w->name,
447 GNUNET_ntohll (wvm->value), 446 GNUNET_ntohll (wvm->value),
448 0 != (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT)); 447 0 != (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT));
449 return GNUNET_OK; 448 return GNUNET_OK;
450} 449}
451 450
@@ -462,73 +461,73 @@ receive_stats (void *cls, const struct GNUNET_MessageHeader *msg)
462 struct GNUNET_STATISTICS_Handle *h = cls; 461 struct GNUNET_STATISTICS_Handle *h = cls;
463 462
464 if (msg == NULL) 463 if (msg == NULL)
464 {
465 if (NULL != h->client)
465 { 466 {
466 if (NULL != h->client) 467 GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
467 { 468 h->client = NULL;
468 GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); 469 }
469 h->client = NULL;
470 }
471#if DEBUG_STATISTICS 470#if DEBUG_STATISTICS
472 LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 471 LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
473 "Error receiving statistics from service, is the service running?\n"); 472 "Error receiving statistics from service, is the service running?\n");
474#endif 473#endif
475 finish (h, GNUNET_SYSERR); 474 finish (h, GNUNET_SYSERR);
476 return; 475 return;
477 } 476 }
478 switch (ntohs (msg->type)) 477 switch (ntohs (msg->type))
478 {
479 case GNUNET_MESSAGE_TYPE_STATISTICS_END:
480#if DEBUG_STATISTICS
481 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received end of statistics marker\n");
482#endif
483 h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
484 if (h->watches_size > 0)
479 { 485 {
480 case GNUNET_MESSAGE_TYPE_STATISTICS_END: 486 GNUNET_CLIENT_receive (h->client, &receive_stats, h,
487 GNUNET_TIME_UNIT_FOREVER_REL);
488 }
489 else
490 {
491 h->receiving = GNUNET_NO;
492 }
493 finish (h, GNUNET_OK);
494 return;
495 case GNUNET_MESSAGE_TYPE_STATISTICS_VALUE:
496 if (GNUNET_OK == process_message (h, msg))
497 {
498 /* finally, look for more! */
481#if DEBUG_STATISTICS 499#if DEBUG_STATISTICS
482 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received end of statistics marker\n"); 500 LOG (GNUNET_ERROR_TYPE_DEBUG,
501 "Processing VALUE done, now reading more\n");
483#endif 502#endif
503 GNUNET_CLIENT_receive (h->client, &receive_stats, h,
504 GNUNET_TIME_absolute_get_remaining (h->
505 current->timeout));
484 h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; 506 h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
485 if (h->watches_size > 0)
486 {
487 GNUNET_CLIENT_receive (h->client, &receive_stats, h,
488 GNUNET_TIME_UNIT_FOREVER_REL);
489 }
490 else
491 {
492 h->receiving = GNUNET_NO;
493 }
494 finish (h, GNUNET_OK);
495 return; 507 return;
496 case GNUNET_MESSAGE_TYPE_STATISTICS_VALUE:
497 if (GNUNET_OK == process_message (h, msg))
498 {
499 /* finally, look for more! */
500#if DEBUG_STATISTICS
501 LOG (GNUNET_ERROR_TYPE_DEBUG,
502 "Processing VALUE done, now reading more\n");
503#endif
504 GNUNET_CLIENT_receive (h->client, &receive_stats, h,
505 GNUNET_TIME_absolute_get_remaining
506 (h->current->timeout));
507 h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
508 return;
509 }
510 GNUNET_break (0);
511 break;
512 case GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE:
513 if (GNUNET_OK == process_watch_value (h, msg))
514 {
515 h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
516 GNUNET_assert (h->watches_size > 0);
517 GNUNET_CLIENT_receive (h->client, &receive_stats, h,
518 GNUNET_TIME_UNIT_FOREVER_REL);
519 return;
520 }
521 GNUNET_break (0);
522 break;
523 default:
524 GNUNET_break (0);
525 break;
526 } 508 }
527 if (NULL != h->client) 509 GNUNET_break (0);
510 break;
511 case GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE:
512 if (GNUNET_OK == process_watch_value (h, msg))
528 { 513 {
529 GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); 514 h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
530 h->client = NULL; 515 GNUNET_assert (h->watches_size > 0);
516 GNUNET_CLIENT_receive (h->client, &receive_stats, h,
517 GNUNET_TIME_UNIT_FOREVER_REL);
518 return;
531 } 519 }
520 GNUNET_break (0);
521 break;
522 default:
523 GNUNET_break (0);
524 break;
525 }
526 if (NULL != h->client)
527 {
528 GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
529 h->client = NULL;
530 }
532 finish (h, GNUNET_SYSERR); 531 finish (h, GNUNET_SYSERR);
533} 532}
534 533
@@ -546,15 +545,15 @@ transmit_get (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf)
546 uint16_t msize; 545 uint16_t msize;
547 546
548 if (buf == NULL) 547 if (buf == NULL)
549 { 548 {
550 /* timeout / error */ 549 /* timeout / error */
551#if DEBUG_STATISTICS 550#if DEBUG_STATISTICS
552 LOG (GNUNET_ERROR_TYPE_DEBUG, 551 LOG (GNUNET_ERROR_TYPE_DEBUG,
553 "Transmission of request for statistics failed!\n"); 552 "Transmission of request for statistics failed!\n");
554#endif 553#endif
555 finish (handle, GNUNET_SYSERR); 554 finish (handle, GNUNET_SYSERR);
556 return 0; 555 return 0;
557 } 556 }
558 slen1 = strlen (handle->current->subsystem) + 1; 557 slen1 = strlen (handle->current->subsystem) + 1;
559 slen2 = strlen (handle->current->name) + 1; 558 slen2 = strlen (handle->current->name) + 1;
560 msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader); 559 msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader);
@@ -563,20 +562,20 @@ transmit_get (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf)
563 hdr->size = htons (msize); 562 hdr->size = htons (msize);
564 hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_GET); 563 hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_GET);
565 GNUNET_assert (slen1 + slen2 == 564 GNUNET_assert (slen1 + slen2 ==
566 GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], slen1 + slen2, 565 GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], slen1 + slen2, 2,
567 2, handle->current->subsystem, 566 handle->current->subsystem,
568 handle->current->name)); 567 handle->current->name));
569 if (!handle->receiving) 568 if (!handle->receiving)
570 { 569 {
571#if DEBUG_STATISTICS 570#if DEBUG_STATISTICS
572 LOG (GNUNET_ERROR_TYPE_DEBUG, 571 LOG (GNUNET_ERROR_TYPE_DEBUG,
573 "Transmission of GET done, now reading response\n"); 572 "Transmission of GET done, now reading response\n");
574#endif 573#endif
575 handle->receiving = GNUNET_YES; 574 handle->receiving = GNUNET_YES;
576 GNUNET_CLIENT_receive (handle->client, &receive_stats, handle, 575 GNUNET_CLIENT_receive (handle->client, &receive_stats, handle,
577 GNUNET_TIME_absolute_get_remaining 576 GNUNET_TIME_absolute_get_remaining (handle->
578 (handle->current->timeout)); 577 current->timeout));
579 } 578 }
580 return msize; 579 return msize;
581} 580}
582 581
@@ -586,8 +585,7 @@ transmit_get (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf)
586 * the response). 585 * the response).
587 */ 586 */
588static size_t 587static size_t
589transmit_watch (struct GNUNET_STATISTICS_Handle *handle, size_t size, 588transmit_watch (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf)
590 void *buf)
591{ 589{
592 struct GNUNET_MessageHeader *hdr; 590 struct GNUNET_MessageHeader *hdr;
593 size_t slen1; 591 size_t slen1;
@@ -595,15 +593,15 @@ transmit_watch (struct GNUNET_STATISTICS_Handle *handle, size_t size,
595 uint16_t msize; 593 uint16_t msize;
596 594
597 if (buf == NULL) 595 if (buf == NULL)
598 { 596 {
599 /* timeout / error */ 597 /* timeout / error */
600#if DEBUG_STATISTICS 598#if DEBUG_STATISTICS
601 LOG (GNUNET_ERROR_TYPE_DEBUG, 599 LOG (GNUNET_ERROR_TYPE_DEBUG,
602 "Transmission of request for statistics failed!\n"); 600 "Transmission of request for statistics failed!\n");
603#endif 601#endif
604 finish (handle, GNUNET_SYSERR); 602 finish (handle, GNUNET_SYSERR);
605 return 0; 603 return 0;
606 } 604 }
607#if DEBUG_STATISTICS 605#if DEBUG_STATISTICS
608 LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting watch request for `%s'\n", 606 LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting watch request for `%s'\n",
609 handle->current->name); 607 handle->current->name);
@@ -616,15 +614,15 @@ transmit_watch (struct GNUNET_STATISTICS_Handle *handle, size_t size,
616 hdr->size = htons (msize); 614 hdr->size = htons (msize);
617 hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_WATCH); 615 hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_WATCH);
618 GNUNET_assert (slen1 + slen2 == 616 GNUNET_assert (slen1 + slen2 ==
619 GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], slen1 + slen2, 617 GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], slen1 + slen2, 2,
620 2, handle->current->subsystem, 618 handle->current->subsystem,
621 handle->current->name)); 619 handle->current->name));
622 if (GNUNET_YES != handle->receiving) 620 if (GNUNET_YES != handle->receiving)
623 { 621 {
624 handle->receiving = GNUNET_YES; 622 handle->receiving = GNUNET_YES;
625 GNUNET_CLIENT_receive (handle->client, &receive_stats, handle, 623 GNUNET_CLIENT_receive (handle->client, &receive_stats, handle,
626 GNUNET_TIME_UNIT_FOREVER_REL); 624 GNUNET_TIME_UNIT_FOREVER_REL);
627 } 625 }
628 finish (handle, GNUNET_OK); 626 finish (handle, GNUNET_OK);
629 return msize; 627 return msize;
630} 628}
@@ -642,20 +640,20 @@ transmit_set (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf)
642 size_t nsize; 640 size_t nsize;
643 641
644 if (NULL == buf) 642 if (NULL == buf)
645 { 643 {
646 finish (handle, GNUNET_SYSERR); 644 finish (handle, GNUNET_SYSERR);
647 return 0; 645 return 0;
648 } 646 }
649 647
650 slen = strlen (handle->current->subsystem) + 1; 648 slen = strlen (handle->current->subsystem) + 1;
651 nlen = strlen (handle->current->name) + 1; 649 nlen = strlen (handle->current->name) + 1;
652 nsize = sizeof (struct GNUNET_STATISTICS_SetMessage) + slen + nlen; 650 nsize = sizeof (struct GNUNET_STATISTICS_SetMessage) + slen + nlen;
653 if (size < nsize) 651 if (size < nsize)
654 { 652 {
655 GNUNET_break (0); 653 GNUNET_break (0);
656 finish (handle, GNUNET_SYSERR); 654 finish (handle, GNUNET_SYSERR);
657 return 0; 655 return 0;
658 } 656 }
659 r = buf; 657 r = buf;
660 r->header.size = htons (nsize); 658 r->header.size = htons (nsize);
661 r->header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_SET); 659 r->header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_SET);
@@ -666,9 +664,9 @@ transmit_set (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf)
666 if (handle->current->type == ACTION_UPDATE) 664 if (handle->current->type == ACTION_UPDATE)
667 r->flags |= htonl (GNUNET_STATISTICS_SETFLAG_RELATIVE); 665 r->flags |= htonl (GNUNET_STATISTICS_SETFLAG_RELATIVE);
668 GNUNET_assert (slen + nlen == 666 GNUNET_assert (slen + nlen ==
669 GNUNET_STRINGS_buffer_fill ((char *) &r[1], slen + nlen, 2, 667 GNUNET_STRINGS_buffer_fill ((char *) &r[1], slen + nlen, 2,
670 handle->current->subsystem, 668 handle->current->subsystem,
671 handle->current->name)); 669 handle->current->name));
672 finish (handle, GNUNET_OK); 670 finish (handle, GNUNET_OK);
673 return nsize; 671 return nsize;
674} 672}
@@ -682,22 +680,22 @@ transmit_action (void *cls, size_t size, void *buf)
682 680
683 handle->th = NULL; 681 handle->th = NULL;
684 switch (handle->current->type) 682 switch (handle->current->type)
685 { 683 {
686 case ACTION_GET: 684 case ACTION_GET:
687 ret = transmit_get (handle, size, buf); 685 ret = transmit_get (handle, size, buf);
688 break; 686 break;
689 case ACTION_SET: 687 case ACTION_SET:
690 case ACTION_UPDATE: 688 case ACTION_UPDATE:
691 ret = transmit_set (handle, size, buf); 689 ret = transmit_set (handle, size, buf);
692 break; 690 break;
693 case ACTION_WATCH: 691 case ACTION_WATCH:
694 ret = transmit_watch (handle, size, buf); 692 ret = transmit_watch (handle, size, buf);
695 break; 693 break;
696 default: 694 default:
697 ret = 0; 695 ret = 0;
698 GNUNET_break (0); 696 GNUNET_break (0);
699 break; 697 break;
700 } 698 }
701 return ret; 699 return ret;
702} 700}
703 701
@@ -711,7 +709,7 @@ transmit_action (void *cls, size_t size, void *buf)
711 */ 709 */
712struct GNUNET_STATISTICS_Handle * 710struct GNUNET_STATISTICS_Handle *
713GNUNET_STATISTICS_create (const char *subsystem, 711GNUNET_STATISTICS_create (const char *subsystem,
714 const struct GNUNET_CONFIGURATION_Handle *cfg) 712 const struct GNUNET_CONFIGURATION_Handle *cfg)
715{ 713{
716 struct GNUNET_STATISTICS_Handle *ret; 714 struct GNUNET_STATISTICS_Handle *ret;
717 715
@@ -722,11 +720,11 @@ GNUNET_STATISTICS_create (const char *subsystem,
722 ret->subsystem = GNUNET_strdup (subsystem); 720 ret->subsystem = GNUNET_strdup (subsystem);
723 ret->backoff = GNUNET_TIME_UNIT_MILLISECONDS; 721 ret->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
724 if (GNUNET_YES != try_connect (ret)) 722 if (GNUNET_YES != try_connect (ret))
725 { 723 {
726 GNUNET_free (ret->subsystem); 724 GNUNET_free (ret->subsystem);
727 GNUNET_free (ret); 725 GNUNET_free (ret);
728 return NULL; 726 return NULL;
729 } 727 }
730 return ret; 728 return ret;
731} 729}
732 730
@@ -753,83 +751,83 @@ GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, int sync_first)
753 if (GNUNET_SCHEDULER_NO_TASK != h->backoff_task) 751 if (GNUNET_SCHEDULER_NO_TASK != h->backoff_task)
754 GNUNET_SCHEDULER_cancel (h->backoff_task); 752 GNUNET_SCHEDULER_cancel (h->backoff_task);
755 if (sync_first) 753 if (sync_first)
754 {
755 if (h->current != NULL)
756 { 756 {
757 if (h->current != NULL) 757 if (h->current->type == ACTION_GET)
758 { 758 {
759 if (h->current->type == ACTION_GET) 759 GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
760 { 760 h->th = NULL;
761 GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); 761 free_action_item (h->current);
762 h->th = NULL; 762 h->current = NULL;
763 free_action_item (h->current); 763 }
764 h->current = NULL;
765 }
766 }
767 pos = h->action_head;
768 prev = NULL;
769 while (pos != NULL)
770 {
771 next = pos->next;
772 if (pos->type == ACTION_GET)
773 {
774 if (prev == NULL)
775 h->action_head = next;
776 else
777 prev->next = next;
778 free_action_item (pos);
779 }
780 else
781 {
782 prev = pos;
783 }
784 pos = next;
785 }
786 h->action_tail = prev;
787 if (h->current == NULL)
788 {
789 h->current = h->action_head;
790 if (h->action_head != NULL)
791 {
792 h->action_head = h->action_head->next;
793 if (h->action_head == NULL)
794 h->action_tail = NULL;
795 }
796 }
797 h->do_destroy = GNUNET_YES;
798 if ((h->current != NULL) && (h->th == NULL))
799 {
800 timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout);
801 h->th =
802 GNUNET_CLIENT_notify_transmit_ready (h->client, h->current->msize,
803 timeout, GNUNET_YES,
804 &transmit_action, h);
805 GNUNET_assert (NULL != h->th);
806 }
807 if (h->th != NULL)
808 return;
809 } 764 }
810 if (NULL != h->th) 765 pos = h->action_head;
766 prev = NULL;
767 while (pos != NULL)
811 { 768 {
812 GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); 769 next = pos->next;
813 h->th = NULL; 770 if (pos->type == ACTION_GET)
771 {
772 if (prev == NULL)
773 h->action_head = next;
774 else
775 prev->next = next;
776 free_action_item (pos);
777 }
778 else
779 {
780 prev = pos;
781 }
782 pos = next;
814 } 783 }
815 if (h->current != NULL) 784 h->action_tail = prev;
816 free_action_item (h->current); 785 if (h->current == NULL)
817 while (NULL != (pos = h->action_head))
818 { 786 {
819 h->action_head = pos->next; 787 h->current = h->action_head;
820 free_action_item (pos); 788 if (h->action_head != NULL)
789 {
790 h->action_head = h->action_head->next;
791 if (h->action_head == NULL)
792 h->action_tail = NULL;
793 }
821 } 794 }
822 if (h->client != NULL) 795 h->do_destroy = GNUNET_YES;
796 if ((h->current != NULL) && (h->th == NULL))
823 { 797 {
824 GNUNET_CLIENT_disconnect (h->client, GNUNET_YES); 798 timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout);
825 h->client = NULL; 799 h->th =
800 GNUNET_CLIENT_notify_transmit_ready (h->client, h->current->msize,
801 timeout, GNUNET_YES,
802 &transmit_action, h);
803 GNUNET_assert (NULL != h->th);
826 } 804 }
805 if (h->th != NULL)
806 return;
807 }
808 if (NULL != h->th)
809 {
810 GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
811 h->th = NULL;
812 }
813 if (h->current != NULL)
814 free_action_item (h->current);
815 while (NULL != (pos = h->action_head))
816 {
817 h->action_head = pos->next;
818 free_action_item (pos);
819 }
820 if (h->client != NULL)
821 {
822 GNUNET_CLIENT_disconnect (h->client, GNUNET_YES);
823 h->client = NULL;
824 }
827 for (i = 0; i < h->watches_size; i++) 825 for (i = 0; i < h->watches_size; i++)
828 { 826 {
829 GNUNET_free (h->watches[i]->subsystem); 827 GNUNET_free (h->watches[i]->subsystem);
830 GNUNET_free (h->watches[i]->name); 828 GNUNET_free (h->watches[i]->name);
831 GNUNET_free (h->watches[i]); 829 GNUNET_free (h->watches[i]);
832 } 830 }
833 GNUNET_array_grow (h->watches, h->watches_size, 0); 831 GNUNET_array_grow (h->watches, h->watches_size, 0);
834 GNUNET_free (h->subsystem); 832 GNUNET_free (h->subsystem);
835 GNUNET_free (h); 833 GNUNET_free (h);
@@ -855,43 +853,42 @@ schedule_action (struct GNUNET_STATISTICS_Handle *h)
855 struct GNUNET_TIME_Relative timeout; 853 struct GNUNET_TIME_Relative timeout;
856 854
857 if (h->current != NULL) 855 if (h->current != NULL)
858 return; /* action already pending */ 856 return; /* action already pending */
859 if (GNUNET_YES != try_connect (h)) 857 if (GNUNET_YES != try_connect (h))
860 { 858 {
861 h->backoff_task = 859 h->backoff_task =
862 GNUNET_SCHEDULER_add_delayed (h->backoff, &finish_task, h); 860 GNUNET_SCHEDULER_add_delayed (h->backoff, &finish_task, h);
863 h->backoff = GNUNET_TIME_relative_multiply (h->backoff, 2); 861 h->backoff = GNUNET_TIME_relative_multiply (h->backoff, 2);
864 h->backoff = 862 h->backoff =
865 GNUNET_TIME_relative_min (h->backoff, 863 GNUNET_TIME_relative_min (h->backoff, GNUNET_CONSTANTS_SERVICE_TIMEOUT);
866 GNUNET_CONSTANTS_SERVICE_TIMEOUT); 864 return;
867 return; 865 }
868 }
869 866
870 /* schedule next action */ 867 /* schedule next action */
871 h->current = h->action_head; 868 h->current = h->action_head;
872 if (NULL == h->current) 869 if (NULL == h->current)
870 {
871 if (h->do_destroy)
873 { 872 {
874 if (h->do_destroy) 873 h->do_destroy = GNUNET_NO;
875 { 874 GNUNET_STATISTICS_destroy (h, GNUNET_YES);
876 h->do_destroy = GNUNET_NO;
877 GNUNET_STATISTICS_destroy (h, GNUNET_YES);
878 }
879 return;
880 } 875 }
876 return;
877 }
881 GNUNET_CONTAINER_DLL_remove (h->action_head, h->action_tail, h->current); 878 GNUNET_CONTAINER_DLL_remove (h->action_head, h->action_tail, h->current);
882 timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout); 879 timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout);
883 if (NULL == 880 if (NULL ==
884 (h->th = 881 (h->th =
885 GNUNET_CLIENT_notify_transmit_ready (h->client, h->current->msize, 882 GNUNET_CLIENT_notify_transmit_ready (h->client, h->current->msize,
886 timeout, GNUNET_YES, 883 timeout, GNUNET_YES,
887 &transmit_action, h))) 884 &transmit_action, h)))
888 { 885 {
889#if DEBUG_STATISTICS 886#if DEBUG_STATISTICS
890 LOG (GNUNET_ERROR_TYPE_DEBUG, 887 LOG (GNUNET_ERROR_TYPE_DEBUG,
891 "Failed to transmit request to statistics service.\n"); 888 "Failed to transmit request to statistics service.\n");
892#endif 889#endif
893 finish (h, GNUNET_SYSERR); 890 finish (h, GNUNET_SYSERR);
894 } 891 }
895} 892}
896 893
897 894
@@ -910,10 +907,10 @@ schedule_action (struct GNUNET_STATISTICS_Handle *h)
910 */ 907 */
911struct GNUNET_STATISTICS_GetHandle * 908struct GNUNET_STATISTICS_GetHandle *
912GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, 909GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle,
913 const char *subsystem, const char *name, 910 const char *subsystem, const char *name,
914 struct GNUNET_TIME_Relative timeout, 911 struct GNUNET_TIME_Relative timeout,
915 GNUNET_STATISTICS_Callback cont, 912 GNUNET_STATISTICS_Callback cont,
916 GNUNET_STATISTICS_Iterator proc, void *cls) 913 GNUNET_STATISTICS_Iterator proc, void *cls)
917{ 914{
918 size_t slen1; 915 size_t slen1;
919 size_t slen2; 916 size_t slen2;
@@ -923,14 +920,14 @@ GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle,
923 GNUNET_assert (proc != NULL); 920 GNUNET_assert (proc != NULL);
924 GNUNET_assert (GNUNET_NO == handle->do_destroy); 921 GNUNET_assert (GNUNET_NO == handle->do_destroy);
925 if (GNUNET_YES != try_connect (handle)) 922 if (GNUNET_YES != try_connect (handle))
926 { 923 {
927#if DEBUG_STATISTICS 924#if DEBUG_STATISTICS
928 LOG (GNUNET_ERROR_TYPE_DEBUG, 925 LOG (GNUNET_ERROR_TYPE_DEBUG,
929 "Failed to connect to statistics service, can not get value `%s:%s'.\n", 926 "Failed to connect to statistics service, can not get value `%s:%s'.\n",
930 strlen (subsystem) ? subsystem : "*", strlen (name) ? name : "*"); 927 strlen (subsystem) ? subsystem : "*", strlen (name) ? name : "*");
931#endif 928#endif
932 return NULL; 929 return NULL;
933 } 930 }
934 if (subsystem == NULL) 931 if (subsystem == NULL)
935 subsystem = ""; 932 subsystem = "";
936 if (name == NULL) 933 if (name == NULL)
@@ -938,7 +935,7 @@ GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle,
938 slen1 = strlen (subsystem) + 1; 935 slen1 = strlen (subsystem) + 1;
939 slen2 = strlen (name) + 1; 936 slen2 = strlen (name) + 1;
940 GNUNET_assert (slen1 + slen2 + sizeof (struct GNUNET_MessageHeader) < 937 GNUNET_assert (slen1 + slen2 + sizeof (struct GNUNET_MessageHeader) <
941 GNUNET_SERVER_MAX_MESSAGE_SIZE); 938 GNUNET_SERVER_MAX_MESSAGE_SIZE);
942 ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle)); 939 ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle));
943 ai->sh = handle; 940 ai->sh = handle;
944 ai->subsystem = GNUNET_strdup (subsystem); 941 ai->subsystem = GNUNET_strdup (subsystem);
@@ -964,17 +961,16 @@ void
964GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh) 961GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh)
965{ 962{
966 if (gh->sh->current == gh) 963 if (gh->sh->current == gh)
967 { 964 {
968 gh->aborted = GNUNET_YES; 965 gh->aborted = GNUNET_YES;
969 } 966 }
970 else 967 else
971 { 968 {
972 GNUNET_CONTAINER_DLL_remove (gh->sh->action_head, gh->sh->action_tail, 969 GNUNET_CONTAINER_DLL_remove (gh->sh->action_head, gh->sh->action_tail, gh);
973 gh); 970 GNUNET_free (gh->name);
974 GNUNET_free (gh->name); 971 GNUNET_free (gh->subsystem);
975 GNUNET_free (gh->subsystem); 972 GNUNET_free (gh);
976 GNUNET_free (gh); 973 }
977 }
978} 974}
979 975
980 976
@@ -992,8 +988,8 @@ GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh)
992 */ 988 */
993int 989int
994GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle, 990GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle,
995 const char *subsystem, const char *name, 991 const char *subsystem, const char *name,
996 GNUNET_STATISTICS_Iterator proc, void *proc_cls) 992 GNUNET_STATISTICS_Iterator proc, void *proc_cls)
997{ 993{
998 struct GNUNET_STATISTICS_WatchEntry *w; 994 struct GNUNET_STATISTICS_WatchEntry *w;
999 995
@@ -1012,7 +1008,7 @@ GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle,
1012 1008
1013static void 1009static void
1014add_setter_action (struct GNUNET_STATISTICS_Handle *h, const char *name, 1010add_setter_action (struct GNUNET_STATISTICS_Handle *h, const char *name,
1015 int make_persistent, uint64_t value, enum ActionType type) 1011 int make_persistent, uint64_t value, enum ActionType type)
1016{ 1012{
1017 struct GNUNET_STATISTICS_GetHandle *ai; 1013 struct GNUNET_STATISTICS_GetHandle *ai;
1018 size_t slen; 1014 size_t slen;
@@ -1028,59 +1024,58 @@ add_setter_action (struct GNUNET_STATISTICS_Handle *h, const char *name,
1028 nlen = strlen (name) + 1; 1024 nlen = strlen (name) + 1;
1029 nsize = sizeof (struct GNUNET_STATISTICS_SetMessage) + slen + nlen; 1025 nsize = sizeof (struct GNUNET_STATISTICS_SetMessage) + slen + nlen;
1030 if (nsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 1026 if (nsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1031 { 1027 {
1032 GNUNET_break (0); 1028 GNUNET_break (0);
1033 return; 1029 return;
1034 } 1030 }
1035 ai = h->action_head; 1031 ai = h->action_head;
1036 while (ai != NULL) 1032 while (ai != NULL)
1033 {
1034 if ((0 == strcmp (ai->subsystem, h->subsystem)) &&
1035 (0 == strcmp (ai->name, name)) && ((ai->type == ACTION_UPDATE) ||
1036 (ai->type == ACTION_SET)))
1037 { 1037 {
1038 if ((0 == strcmp (ai->subsystem, h->subsystem)) && 1038 if (ai->type == ACTION_SET)
1039 (0 == strcmp (ai->name, name)) && ((ai->type == ACTION_UPDATE) || 1039 {
1040 (ai->type == ACTION_SET))) 1040 if (type == ACTION_UPDATE)
1041 { 1041 {
1042 if (ai->type == ACTION_SET) 1042 delta = (int64_t) value;
1043 { 1043 if (delta > 0)
1044 if (type == ACTION_UPDATE) 1044 {
1045 { 1045 ai->value += delta;
1046 delta = (int64_t) value; 1046 }
1047 if (delta > 0) 1047 else
1048 { 1048 {
1049 ai->value += delta; 1049 if (ai->value < -delta)
1050 } 1050 ai->value = 0;
1051 else 1051 else
1052 { 1052 ai->value += delta;
1053 if (ai->value < -delta) 1053 }
1054 ai->value = 0; 1054 }
1055 else 1055 else
1056 ai->value += delta; 1056 {
1057 } 1057 ai->value = value;
1058 } 1058 }
1059 else 1059 }
1060 { 1060 else
1061 ai->value = value; 1061 {
1062 } 1062 if (type == ACTION_UPDATE)
1063 } 1063 {
1064 else 1064 delta = (int64_t) value;
1065 { 1065 ai->value += delta;
1066 if (type == ACTION_UPDATE) 1066 }
1067 { 1067 else
1068 delta = (int64_t) value; 1068 {
1069 ai->value += delta; 1069 ai->value = value;
1070 } 1070 ai->type = type;
1071 else 1071 }
1072 { 1072 }
1073 ai->value = value; 1073 ai->timeout = GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT);
1074 ai->type = type; 1074 ai->make_persistent = make_persistent;
1075 } 1075 return;
1076 }
1077 ai->timeout =
1078 GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT);
1079 ai->make_persistent = make_persistent;
1080 return;
1081 }
1082 ai = ai->next;
1083 } 1076 }
1077 ai = ai->next;
1078 }
1084 ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle)); 1079 ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle));
1085 ai->sh = h; 1080 ai->sh = h;
1086 ai->subsystem = GNUNET_strdup (h->subsystem); 1081 ai->subsystem = GNUNET_strdup (h->subsystem);
@@ -1105,7 +1100,7 @@ add_setter_action (struct GNUNET_STATISTICS_Handle *h, const char *name,
1105 */ 1100 */
1106void 1101void
1107GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle, 1102GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle,
1108 const char *name, uint64_t value, int make_persistent) 1103 const char *name, uint64_t value, int make_persistent)
1109{ 1104{
1110 if (handle == NULL) 1105 if (handle == NULL)
1111 return; 1106 return;
@@ -1125,8 +1120,7 @@ GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle,
1125 */ 1120 */
1126void 1121void
1127GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle, 1122GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle,
1128 const char *name, int64_t delta, 1123 const char *name, int64_t delta, int make_persistent)
1129 int make_persistent)
1130{ 1124{
1131 if (handle == NULL) 1125 if (handle == NULL)
1132 return; 1126 return;
@@ -1134,7 +1128,7 @@ GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle,
1134 return; 1128 return;
1135 GNUNET_assert (GNUNET_NO == handle->do_destroy); 1129 GNUNET_assert (GNUNET_NO == handle->do_destroy);
1136 add_setter_action (handle, name, make_persistent, (uint64_t) delta, 1130 add_setter_action (handle, name, make_persistent, (uint64_t) delta,
1137 ACTION_UPDATE); 1131 ACTION_UPDATE);
1138} 1132}
1139 1133
1140 1134
diff --git a/src/testing/test_testing_connect.c b/src/testing/test_testing_connect.c
index f32e2e40f..87501469d 100644
--- a/src/testing/test_testing_connect.c
+++ b/src/testing/test_testing_connect.c
@@ -148,10 +148,12 @@ run (void *cls, char *const *args, const char *cfgfile,
148#endif 148#endif
149 c1 = GNUNET_CONFIGURATION_create (); 149 c1 = GNUNET_CONFIGURATION_create ();
150 GNUNET_assert (GNUNET_OK == 150 GNUNET_assert (GNUNET_OK ==
151 GNUNET_CONFIGURATION_load (c1, "test_testing_connect_peer1.conf")); 151 GNUNET_CONFIGURATION_load (c1,
152 "test_testing_connect_peer1.conf"));
152 c2 = GNUNET_CONFIGURATION_create (); 153 c2 = GNUNET_CONFIGURATION_create ();
153 GNUNET_assert (GNUNET_OK == 154 GNUNET_assert (GNUNET_OK ==
154 GNUNET_CONFIGURATION_load (c2, "test_testing_connect_peer2.conf")); 155 GNUNET_CONFIGURATION_load (c2,
156 "test_testing_connect_peer2.conf"));
155 d1 = GNUNET_TESTING_daemon_start (c1, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL, 157 d1 = GNUNET_TESTING_daemon_start (c1, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL,
156 NULL, NULL, &my_cb1, NULL); 158 NULL, NULL, &my_cb1, NULL);
157 GNUNET_assert (d1 != NULL); 159 GNUNET_assert (d1 != NULL);
diff --git a/src/testing/test_testing_reconnect.c b/src/testing/test_testing_reconnect.c
index f317040fb..20c628c6a 100644
--- a/src/testing/test_testing_reconnect.c
+++ b/src/testing/test_testing_reconnect.c
@@ -101,8 +101,8 @@ end1_cb (void *cls, const char *emsg)
101 if (d2 != NULL) 101 if (d2 != NULL)
102 { 102 {
103 GNUNET_TESTING_daemon_stop (d2, TIMEOUT, &end2_cb, NULL, 103 GNUNET_TESTING_daemon_stop (d2, TIMEOUT, &end2_cb, NULL,
104 (phase == NUM_PHASES) ? GNUNET_YES : GNUNET_NO, 104 (phase == NUM_PHASES) ? GNUNET_YES : GNUNET_NO,
105 GNUNET_NO); 105 GNUNET_NO);
106 d2 = NULL; 106 d2 = NULL;
107 } 107 }
108} 108}
@@ -192,9 +192,13 @@ run (void *cls, char *const *args, const char *cfgfile,
192 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemon.\n"); 192 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemon.\n");
193#endif 193#endif
194 c1 = GNUNET_CONFIGURATION_create (); 194 c1 = GNUNET_CONFIGURATION_create ();
195 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (c1, "test_testing_connect_peer1.conf")); 195 GNUNET_assert (GNUNET_OK ==
196 GNUNET_CONFIGURATION_load (c1,
197 "test_testing_connect_peer1.conf"));
196 c2 = GNUNET_CONFIGURATION_create (); 198 c2 = GNUNET_CONFIGURATION_create ();
197 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (c2, "test_testing_connect_peer2.conf")); 199 GNUNET_assert (GNUNET_OK ==
200 GNUNET_CONFIGURATION_load (c2,
201 "test_testing_connect_peer2.conf"));
198 run_phase (); 202 run_phase ();
199} 203}
200 204
diff --git a/src/testing/test_testing_topology.c b/src/testing/test_testing_topology.c
index e563f4d64..deaeae457 100644
--- a/src/testing/test_testing_topology.c
+++ b/src/testing/test_testing_topology.c
@@ -349,7 +349,7 @@ static int
349process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer, 349process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
350 const struct GNUNET_MessageHeader *message, 350 const struct GNUNET_MessageHeader *message,
351 const struct GNUNET_ATS_Information *atsi, 351 const struct GNUNET_ATS_Information *atsi,
352 unsigned int atsi_count) 352 unsigned int atsi_count)
353{ 353{
354 char *dotOutFileNameFinished; 354 char *dotOutFileNameFinished;
355 FILE *dotOutFileFinished; 355 FILE *dotOutFileFinished;
@@ -543,7 +543,7 @@ init_notify_peer2 (void *cls, struct GNUNET_CORE_Handle *server,
543static void 543static void
544connect_notify_peers (void *cls, const struct GNUNET_PeerIdentity *peer, 544connect_notify_peers (void *cls, const struct GNUNET_PeerIdentity *peer,
545 const struct GNUNET_ATS_Information *atsi, 545 const struct GNUNET_ATS_Information *atsi,
546 unsigned int atsi_count) 546 unsigned int atsi_count)
547{ 547{
548 struct TestMessageContext *pos = cls; 548 struct TestMessageContext *pos = cls;
549 549
@@ -604,8 +604,7 @@ init_notify_peer1 (void *cls, struct GNUNET_CORE_Handle *server,
604 */ 604 */
605 pos->peer2handle = 605 pos->peer2handle =
606 GNUNET_CORE_connect (pos->peer2->cfg, 1, pos, &init_notify_peer2, NULL, 606 GNUNET_CORE_connect (pos->peer2->cfg, 1, pos, &init_notify_peer2, NULL,
607 NULL, NULL, GNUNET_YES, NULL, GNUNET_YES, 607 NULL, NULL, GNUNET_YES, NULL, GNUNET_YES, handlers);
608 handlers);
609 608
610} 609}
611 610
@@ -643,8 +642,8 @@ send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
643 */ 642 */
644 pos->peer1handle = 643 pos->peer1handle =
645 GNUNET_CORE_connect (pos->peer1->cfg, 1, pos, &init_notify_peer1, 644 GNUNET_CORE_connect (pos->peer1->cfg, 1, pos, &init_notify_peer1,
646 &connect_notify_peers, NULL, NULL, GNUNET_NO, 645 &connect_notify_peers, NULL, NULL, GNUNET_NO, NULL,
647 NULL, GNUNET_NO, no_handlers); 646 GNUNET_NO, no_handlers);
648 647
649 GNUNET_assert (pos->peer1handle != NULL); 648 GNUNET_assert (pos->peer1handle != NULL);
650 649
diff --git a/src/testing/testing.c b/src/testing/testing.c
index e81a92fb5..6edc1fc8c 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -1888,7 +1888,7 @@ notify_connect_result (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1888static void 1888static void
1889connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, 1889connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
1890 const struct GNUNET_ATS_Information *atsi, 1890 const struct GNUNET_ATS_Information *atsi,
1891 unsigned int atsi_count) 1891 unsigned int atsi_count)
1892{ 1892{
1893 struct GNUNET_TESTING_ConnectContext *ctx = cls; 1893 struct GNUNET_TESTING_ConnectContext *ctx = cls;
1894 1894
@@ -1965,8 +1965,7 @@ core_init_notify (void *cls, struct GNUNET_CORE_Handle *server,
1965 1965
1966 if (connect_ctx->send_hello == GNUNET_NO) 1966 if (connect_ctx->send_hello == GNUNET_NO)
1967 { 1967 {
1968 GNUNET_TRANSPORT_try_connect (connect_ctx->d1th, 1968 GNUNET_TRANSPORT_try_connect (connect_ctx->d1th, &connect_ctx->d2->id);
1969 &connect_ctx->d2->id);
1970#if DEBUG_TESTING 1969#if DEBUG_TESTING
1971 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1970 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1972 "Sending connect request to TRANSPORT of %s for peer %s\n", 1971 "Sending connect request to TRANSPORT of %s for peer %s\n",
@@ -2088,7 +2087,7 @@ reattempt_daemons_connect (void *cls,
2088static void 2087static void
2089core_initial_iteration (void *cls, const struct GNUNET_PeerIdentity *peer, 2088core_initial_iteration (void *cls, const struct GNUNET_PeerIdentity *peer,
2090 const struct GNUNET_ATS_Information *atsi, 2089 const struct GNUNET_ATS_Information *atsi,
2091 unsigned int atsi_count) 2090 unsigned int atsi_count)
2092{ 2091{
2093 struct GNUNET_TESTING_ConnectContext *ctx = cls; 2092 struct GNUNET_TESTING_ConnectContext *ctx = cls;
2094 2093
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c
index 04c2cfd00..171cf1c48 100644
--- a/src/testing/testing_group.c
+++ b/src/testing/testing_group.c
@@ -2669,8 +2669,8 @@ create_from_file (struct GNUNET_TESTING_PeerGroup *pg, char *filename,
2669 return connect_attempts; 2669 return connect_attempts;
2670 } 2670 }
2671#if DEBUG_TESTING 2671#if DEBUG_TESTING
2672 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2672 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u total peers in topology\n",
2673 "Found %u total peers in topology\n", total_peers); 2673 total_peers);
2674#endif 2674#endif
2675 GNUNET_assert (total_peers == pg->total); 2675 GNUNET_assert (total_peers == pg->total);
2676 curr_state = PEER_INDEX; 2676 curr_state = PEER_INDEX;
@@ -3348,7 +3348,9 @@ send_core_connect_requests (void *cls,
3348 while (conn != NULL) 3348 while (conn != NULL)
3349 { 3349 {
3350 GNUNET_TRANSPORT_try_connect (send_hello_context->peer->daemon->th, 3350 GNUNET_TRANSPORT_try_connect (send_hello_context->peer->daemon->th,
3351 &send_hello_context->pg->peers[conn->index].daemon->id); 3351 &send_hello_context->pg->peers[conn->
3352 index].daemon->
3353 id);
3352 conn = conn->next; 3354 conn = conn->next;
3353 } 3355 }
3354 send_hello_context->core_connect_task = 3356 send_hello_context->core_connect_task =
@@ -3486,7 +3488,7 @@ core_connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
3486 */ 3488 */
3487void 3489void
3488core_init (void *cls, struct GNUNET_CORE_Handle *server, 3490core_init (void *cls, struct GNUNET_CORE_Handle *server,
3489 struct GNUNET_PeerIdentity *my_identity) 3491 struct GNUNET_PeerIdentity *my_identity)
3490{ 3492{
3491 struct SendHelloContext *send_hello_context = cls; 3493 struct SendHelloContext *send_hello_context = cls;
3492 3494
@@ -4878,7 +4880,7 @@ perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num)
4878static void 4880static void
4879internal_topology_callback (void *cls, const struct GNUNET_PeerIdentity *peer, 4881internal_topology_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
4880 const struct GNUNET_ATS_Information *atsi, 4882 const struct GNUNET_ATS_Information *atsi,
4881 unsigned int atsi_count) 4883 unsigned int atsi_count)
4882{ 4884{
4883 struct CoreContext *core_ctx = cls; 4885 struct CoreContext *core_ctx = cls;
4884 struct TopologyIterateContext *iter_ctx = core_ctx->iter_context; 4886 struct TopologyIterateContext *iter_ctx = core_ctx->iter_context;
@@ -5835,9 +5837,8 @@ start_peer_helper (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
5835 "peerStartHelper.pl", tempdir, NULL); 5837 "peerStartHelper.pl", tempdir, NULL);
5836 GNUNET_assert (helper->proc != NULL); 5838 GNUNET_assert (helper->proc != NULL);
5837#if DEBUG_TESTING 5839#if DEBUG_TESTING
5838 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5840 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting peers with cmd ssh %s %s %s\n",
5839 "starting peers with cmd ssh %s %s %s\n", arg, 5841 arg, "peerStartHelper.pl", tempdir);
5840 "peerStartHelper.pl", tempdir);
5841#endif 5842#endif
5842 GNUNET_SCHEDULER_add_now (&check_peers_started, helper); 5843 GNUNET_SCHEDULER_add_now (&check_peers_started, helper);
5843 GNUNET_free (tempdir); 5844 GNUNET_free (tempdir);
@@ -6109,8 +6110,7 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
6109 fs = 0; 6110 fs = 0;
6110#if DEBUG_TESTING 6111#if DEBUG_TESTING
6111 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6112 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6112 "Found file size %llu for hostkeys\n", 6113 "Found file size %llu for hostkeys\n", fs);
6113 fs);
6114#endif 6114#endif
6115 if (0 != (fs % HOSTKEYFILESIZE)) 6115 if (0 != (fs % HOSTKEYFILESIZE))
6116 { 6116 {
@@ -6784,9 +6784,8 @@ GNUNET_TESTING_daemons_start_service (struct GNUNET_TESTING_PeerGroup *pg,
6784 for (i = 0; i < pg->total; i++) 6784 for (i = 0; i < pg->total; i++)
6785 { 6785 {
6786#if DEBUG_START 6786#if DEBUG_START
6787 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6787 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting up service %s on peer %d!\n",
6788 "Starting up service %s on peer %d!\n", service, 6788 service, stopped_arr[stopped_permute[i]]);
6789 stopped_arr[stopped_permute[i]]);
6790#endif 6789#endif
6791 peer_start_ctx = GNUNET_malloc (sizeof (struct PeerServiceStartContext)); 6790 peer_start_ctx = GNUNET_malloc (sizeof (struct PeerServiceStartContext));
6792 peer_start_ctx->start_ctx = start_ctx; 6791 peer_start_ctx->start_ctx = start_ctx;
diff --git a/src/testing/testing_peergroup.c b/src/testing/testing_peergroup.c
index 470fdf8fa..a46e1bfb2 100644
--- a/src/testing/testing_peergroup.c
+++ b/src/testing/testing_peergroup.c
@@ -591,8 +591,8 @@ internal_hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id,
591 591
592 GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task); 592 GNUNET_SCHEDULER_cancel (pg_start_ctx->die_task);
593 GNUNET_free_non_null (pg_start_ctx->fail_reason); 593 GNUNET_free_non_null (pg_start_ctx->fail_reason);
594 pg_start_ctx->fail_reason = 594 pg_start_ctx->fail_reason =
595 GNUNET_strdup ("from continue startup (timeout)"); 595 GNUNET_strdup ("from continue startup (timeout)");
596 pg_start_ctx->die_task = 596 pg_start_ctx->die_task =
597 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining 597 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
598 (pg_start_ctx->timeout), &end_badly, 598 (pg_start_ctx->timeout), &end_badly,
@@ -928,7 +928,8 @@ GNUNET_TESTING_peergroup_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
928 /* Make compilers happy */ 928 /* Make compilers happy */
929 reset_meter (pg_start_ctx->peer_start_meter); 929 reset_meter (pg_start_ctx->peer_start_meter);
930 pg_start_ctx->fail_reason = 930 pg_start_ctx->fail_reason =
931 GNUNET_strdup ("didn't generate all hostkeys within allowed startup time!"); 931 GNUNET_strdup
932 ("didn't generate all hostkeys within allowed startup time!");
932 pg_start_ctx->die_task = 933 pg_start_ctx->die_task =
933 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining 934 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
934 (pg_start_ctx->timeout), &end_badly, 935 (pg_start_ctx->timeout), &end_badly,
diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c
index 625923cdf..3e4fd2685 100644
--- a/src/topology/gnunet-daemon-topology.c
+++ b/src/topology/gnunet-daemon-topology.c
@@ -376,8 +376,9 @@ attempt_connect (struct Peer *pos)
376 GNUNET_i2s (&pos->pid)); 376 GNUNET_i2s (&pos->pid));
377#endif 377#endif
378 GNUNET_STATISTICS_update (stats, 378 GNUNET_STATISTICS_update (stats,
379 gettext_noop ("# connect requests issued to transport"), 379 gettext_noop
380 1, GNUNET_NO); 380 ("# connect requests issued to transport"), 1,
381 GNUNET_NO);
381 GNUNET_TRANSPORT_try_connect (transport, &pos->pid); 382 GNUNET_TRANSPORT_try_connect (transport, &pos->pid);
382} 383}
383 384
@@ -637,7 +638,7 @@ reschedule_hellos (void *cls, const GNUNET_HashCode * pid, void *value)
637static void 638static void
638connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, 639connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
639 const struct GNUNET_ATS_Information *atsi, 640 const struct GNUNET_ATS_Information *atsi,
640 unsigned int atsi_count) 641 unsigned int atsi_count)
641{ 642{
642 struct Peer *pos; 643 struct Peer *pos;
643 644
@@ -1110,7 +1111,7 @@ static int
1110handle_encrypted_hello (void *cls, const struct GNUNET_PeerIdentity *other, 1111handle_encrypted_hello (void *cls, const struct GNUNET_PeerIdentity *other,
1111 const struct GNUNET_MessageHeader *message, 1112 const struct GNUNET_MessageHeader *message,
1112 const struct GNUNET_ATS_Information *atsi, 1113 const struct GNUNET_ATS_Information *atsi,
1113 unsigned int atsi_count) 1114 unsigned int atsi_count)
1114{ 1115{
1115 struct Peer *peer; 1116 struct Peer *peer;
1116 struct GNUNET_PeerIdentity pid; 1117 struct GNUNET_PeerIdentity pid;
@@ -1282,8 +1283,8 @@ run (void *cls, char *const *args, const char *cfgfile,
1282 transport = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL, NULL, NULL); 1283 transport = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL, NULL, NULL);
1283 handle = 1284 handle =
1284 GNUNET_CORE_connect (cfg, 1, NULL, &core_init, &connect_notify, 1285 GNUNET_CORE_connect (cfg, 1, NULL, &core_init, &connect_notify,
1285 &disconnect_notify, NULL, GNUNET_NO, NULL, 1286 &disconnect_notify, NULL, GNUNET_NO, NULL, GNUNET_NO,
1286 GNUNET_NO, handlers); 1287 handlers);
1287 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task, 1288 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task,
1288 NULL); 1289 NULL);
1289 if (NULL == transport) 1290 if (NULL == transport)
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index 10c1c68a8..878ab2618 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -90,9 +90,7 @@ struct GNUNET_ATS_SchedulingHandle *GST_ats;
90static void 90static void
91transmit_our_hello (void *cls, const struct GNUNET_PeerIdentity *target, 91transmit_our_hello (void *cls, const struct GNUNET_PeerIdentity *target,
92 const struct GNUNET_ATS_Information *ats, 92 const struct GNUNET_ATS_Information *ats,
93 uint32_t ats_count, 93 uint32_t ats_count, const char *transport, const void *addr,
94 const char * transport,
95 const void * addr,
96 size_t addrlen) 94 size_t addrlen)
97{ 95{
98 const struct GNUNET_MessageHeader *hello = cls; 96 const struct GNUNET_MessageHeader *hello = cls;
@@ -118,7 +116,7 @@ process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello)
118 116
119 117
120/** 118/**
121 * We received some payload. Prepare to pass it on to our clients. 119 * We received some payload. Prepare to pass it on to our clients.
122 * 120 *
123 * @param peer (claimed) identity of the other peer 121 * @param peer (claimed) identity of the other peer
124 * @param message the message, never NULL 122 * @param message the message, never NULL
@@ -128,48 +126,45 @@ process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello)
128 */ 126 */
129static struct GNUNET_TIME_Relative 127static struct GNUNET_TIME_Relative
130process_payload (const struct GNUNET_PeerIdentity *peer, 128process_payload (const struct GNUNET_PeerIdentity *peer,
131 const struct GNUNET_MessageHeader *message, 129 const struct GNUNET_MessageHeader *message,
132 const struct GNUNET_ATS_Information *ats, 130 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
133 uint32_t ats_count)
134{ 131{
135 struct GNUNET_TIME_Relative ret; 132 struct GNUNET_TIME_Relative ret;
136 int do_forward; 133 int do_forward;
137 struct InboundMessage *im; 134 struct InboundMessage *im;
138 size_t msg_size = ntohs (message->size); 135 size_t msg_size = ntohs (message->size);
139 size_t size = sizeof (struct InboundMessage) + msg_size + sizeof (struct GNUNET_ATS_Information) * ats_count; 136 size_t size =
137 sizeof (struct InboundMessage) + msg_size +
138 sizeof (struct GNUNET_ATS_Information) * ats_count;
140 char buf[size]; 139 char buf[size];
141 struct GNUNET_ATS_Information *ap; 140 struct GNUNET_ATS_Information *ap;
142 141
143 ret = GNUNET_TIME_UNIT_ZERO; 142 ret = GNUNET_TIME_UNIT_ZERO;
144 do_forward = GNUNET_SYSERR; 143 do_forward = GNUNET_SYSERR;
145 ret = 144 ret = GST_neighbours_calculate_receive_delay (peer, msg_size, &do_forward);
146 GST_neighbours_calculate_receive_delay (peer,
147 msg_size,
148 &do_forward);
149 145
150 if (!GST_neighbours_test_connected (peer)) 146 if (!GST_neighbours_test_connected (peer))
151 { 147 {
152 148
153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Discarded %u bytes type %u payload from peer `%s'\n", 149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
154 msg_size, 150 "Discarded %u bytes type %u payload from peer `%s'\n", msg_size,
155 ntohs (message->type), 151 ntohs (message->type), GNUNET_i2s (peer));
156 GNUNET_i2s (peer));
157 152
158 GNUNET_STATISTICS_update (GST_stats, 153 GNUNET_STATISTICS_update (GST_stats,
159 gettext_noop ("# bytes payload discarded due to not connected peer "), 154 gettext_noop
160 msg_size, 155 ("# bytes payload discarded due to not connected peer "),
161 GNUNET_NO); 156 msg_size, GNUNET_NO);
162 return ret; 157 return ret;
163 } 158 }
164 159
165 if (do_forward != GNUNET_YES) 160 if (do_forward != GNUNET_YES)
166 return ret; 161 return ret;
167 im = (struct InboundMessage*) buf; 162 im = (struct InboundMessage *) buf;
168 im->header.size = htons (size); 163 im->header.size = htons (size);
169 im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); 164 im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
170 im->ats_count = htonl (ats_count); 165 im->ats_count = htonl (ats_count);
171 im->peer = *peer; 166 im->peer = *peer;
172 ap = (struct GNUNET_ATS_Information*) &im[1]; 167 ap = (struct GNUNET_ATS_Information *) &im[1];
173 memcpy (ap, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); 168 memcpy (ap, ats, ats_count * sizeof (struct GNUNET_ATS_Information));
174 memcpy (&ap[ats_count], message, ntohs (message->size)); 169 memcpy (&ap[ats_count], message, ntohs (message->size));
175 170
@@ -213,7 +208,7 @@ plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
213 const char *plugin_name = cls; 208 const char *plugin_name = cls;
214 struct GNUNET_TIME_Relative ret; 209 struct GNUNET_TIME_Relative ret;
215 uint16_t type; 210 uint16_t type;
216 211
217 ret = GNUNET_TIME_UNIT_ZERO; 212 ret = GNUNET_TIME_UNIT_ZERO;
218 if (NULL == message) 213 if (NULL == message)
219 goto end; 214 goto end;
@@ -231,43 +226,38 @@ plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
231 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING: 226 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
232#if DEBUG_TRANSPORT 227#if DEBUG_TRANSPORT
233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 228 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
234 "Processing `%s' from `%s'\n", "PING", 229 "Processing `%s' from `%s'\n", "PING",
235 (sender_address != NULL) ? GST_plugins_a2s (plugin_name, 230 (sender_address != NULL) ? GST_plugins_a2s (plugin_name,
236 sender_address, 231 sender_address,
237 sender_address_len) 232 sender_address_len)
238 : "<inbound>"); 233 : "<inbound>");
239#endif 234#endif
240 GST_validation_handle_ping (peer, message, plugin_name, session, 235 GST_validation_handle_ping (peer, message, plugin_name, session,
241 sender_address, sender_address_len); 236 sender_address, sender_address_len);
242 break; 237 break;
243 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: 238 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG:
244#if DEBUG_TRANSPORT 239#if DEBUG_TRANSPORT
245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 240 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
246 "Processing `%s' from `%s'\n", "PONG", 241 "Processing `%s' from `%s'\n", "PONG",
247 (sender_address != NULL) ? GST_plugins_a2s (plugin_name, 242 (sender_address != NULL) ? GST_plugins_a2s (plugin_name,
248 sender_address, 243 sender_address,
249 sender_address_len) 244 sender_address_len)
250 : "<inbound>"); 245 : "<inbound>");
251#endif 246#endif
252 GST_validation_handle_pong (peer, message); 247 GST_validation_handle_pong (peer, message);
253 break; 248 break;
254 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT: 249 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT:
255 GST_neighbours_handle_connect (message, 250 GST_neighbours_handle_connect (message, peer, plugin_name, sender_address,
256 peer, 251 sender_address_len, session, ats, ats_count);
257 plugin_name, sender_address, sender_address_len,
258 session, ats, ats_count);
259 break; 252 break;
260 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK: 253 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK:
261 GST_neighbours_handle_connect_ack (message, 254 GST_neighbours_handle_connect_ack (message, peer, plugin_name,
262 peer, 255 sender_address, sender_address_len,
263 plugin_name, sender_address, sender_address_len, 256 session, ats, ats_count);
264 session, ats, ats_count);
265 break; 257 break;
266 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK: 258 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK:
267 GST_neighbours_handle_ack (message, 259 GST_neighbours_handle_ack (message, peer, plugin_name, sender_address,
268 peer, 260 sender_address_len, session, ats, ats_count);
269 plugin_name, sender_address, sender_address_len,
270 session, ats, ats_count);
271 break; 261 break;
272 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: 262 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT:
273 GST_neighbours_handle_disconnect_message (peer, message); 263 GST_neighbours_handle_disconnect_message (peer, message);
@@ -277,25 +267,20 @@ plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
277 break; 267 break;
278 default: 268 default:
279 /* should be payload */ 269 /* should be payload */
280 ret = process_payload (peer, 270 ret = process_payload (peer, message, ats, ats_count);
281 message,
282 ats, ats_count);
283 break; 271 break;
284 } 272 }
285 end: 273end:
286#if 1 274#if 1
287 /* FIXME: this should not be needed, and not sure it's good to have it, but without 275 /* FIXME: this should not be needed, and not sure it's good to have it, but without
288 this connections seem to go extra-slow */ 276 * this connections seem to go extra-slow */
289 GNUNET_ATS_address_update (GST_ats, peer, 277 GNUNET_ATS_address_update (GST_ats, peer, plugin_name, sender_address,
290 plugin_name, sender_address, sender_address_len, 278 sender_address_len, session, ats, ats_count);
291 session,
292 ats, ats_count);
293#endif 279#endif
294#if DEBUG_TRANSPORT 280#if DEBUG_TRANSPORT
295 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 281 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
296 "Allowing receive from peer %s to continue in %llu ms\n", 282 "Allowing receive from peer %s to continue in %llu ms\n",
297 GNUNET_i2s (peer), 283 GNUNET_i2s (peer), (unsigned long long) ret.rel_value);
298 (unsigned long long) ret.rel_value);
299#endif 284#endif
300 return ret; 285 return ret;
301} 286}
@@ -340,16 +325,14 @@ plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
340 struct Session *session) 325 struct Session *session)
341{ 326{
342#if DEBUG_TRANSPORT 327#if DEBUG_TRANSPORT
343 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 328 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Session %X to peer `%s' ended \n",
344 "Session %X to peer `%s' ended \n",
345 session, GNUNET_i2s (peer)); 329 session, GNUNET_i2s (peer));
346#endif 330#endif
347 if (NULL != session) 331 if (NULL != session)
348 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, 332 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
349 "transport-ats", 333 "transport-ats",
350 "Telling ATS to destroy session %p from peer %s\n", 334 "Telling ATS to destroy session %p from peer %s\n",
351 session, 335 session, GNUNET_i2s (peer));
352 GNUNET_i2s (peer));
353 GNUNET_ATS_address_destroyed (GST_ats, peer, NULL, NULL, 0, session); 336 GNUNET_ATS_address_destroyed (GST_ats, peer, NULL, NULL, 0, session);
354 GST_neighbours_session_terminated (peer, session); 337 GST_neighbours_session_terminated (peer, session);
355} 338}
@@ -373,32 +356,32 @@ plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
373 */ 356 */
374static void 357static void
375ats_request_address_change (void *cls, const struct GNUNET_PeerIdentity *peer, 358ats_request_address_change (void *cls, const struct GNUNET_PeerIdentity *peer,
376 const char *plugin_name, 359 const char *plugin_name, const void *plugin_addr,
377 const void *plugin_addr, size_t plugin_addr_len, 360 size_t plugin_addr_len, struct Session *session,
378 struct Session *session,
379 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 361 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
380 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 362 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
381 const struct GNUNET_ATS_Information * ats, 363 const struct GNUNET_ATS_Information *ats,
382 uint32_t ats_count) 364 uint32_t ats_count)
383{ 365{
384 uint32_t bw_in = ntohl (bandwidth_in.value__); 366 uint32_t bw_in = ntohl (bandwidth_in.value__);
385 uint32_t bw_out = ntohl (bandwidth_out.value__); 367 uint32_t bw_out = ntohl (bandwidth_out.value__);
386 368
387 /* ATS tells me to disconnect from peer*/ 369 /* ATS tells me to disconnect from peer */
388 if ((bw_in == 0) && (bw_out == 0)) 370 if ((bw_in == 0) && (bw_out == 0))
389 { 371 {
390#if DEBUG_TRANSPORT 372#if DEBUG_TRANSPORT
391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 373 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
392 "ATS tells me to disconnect from peer `%s'\n", 374 "ATS tells me to disconnect from peer `%s'\n",
393 GNUNET_i2s (peer)); 375 GNUNET_i2s (peer));
394#endif 376#endif
395 GST_neighbours_force_disconnect(peer); 377 GST_neighbours_force_disconnect (peer);
396 return; 378 return;
397 } 379 }
398 /* will never return GNUNET_YES since connection is to be established */ 380 /* will never return GNUNET_YES since connection is to be established */
399 GST_neighbours_switch_to_address_3way (peer, plugin_name, plugin_addr, 381 GST_neighbours_switch_to_address_3way (peer, plugin_name, plugin_addr,
400 plugin_addr_len, session, ats, ats_count, 382 plugin_addr_len, session, ats,
401 bandwidth_in, bandwidth_out); 383 ats_count, bandwidth_in,
384 bandwidth_out);
402} 385}
403 386
404 387
@@ -414,10 +397,11 @@ ats_request_address_change (void *cls, const struct GNUNET_PeerIdentity *peer,
414static void 397static void
415neighbours_connect_notification (void *cls, 398neighbours_connect_notification (void *cls,
416 const struct GNUNET_PeerIdentity *peer, 399 const struct GNUNET_PeerIdentity *peer,
417 const struct GNUNET_ATS_Information 400 const struct GNUNET_ATS_Information *ats,
418 *ats, uint32_t ats_count) 401 uint32_t ats_count)
419{ 402{
420 size_t len = sizeof (struct ConnectInfoMessage) + 403 size_t len =
404 sizeof (struct ConnectInfoMessage) +
421 ats_count * sizeof (struct GNUNET_ATS_Information); 405 ats_count * sizeof (struct GNUNET_ATS_Information);
422 char buf[len]; 406 char buf[len];
423 struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf; 407 struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf;
@@ -428,8 +412,7 @@ neighbours_connect_notification (void *cls,
428 connect_msg->ats_count = htonl (ats_count); 412 connect_msg->ats_count = htonl (ats_count);
429 connect_msg->id = *peer; 413 connect_msg->id = *peer;
430 ap = (struct GNUNET_ATS_Information *) &connect_msg[1]; 414 ap = (struct GNUNET_ATS_Information *) &connect_msg[1];
431 memcpy (ap, ats, 415 memcpy (ap, ats, ats_count * sizeof (struct GNUNET_ATS_Information));
432 ats_count * sizeof (struct GNUNET_ATS_Information));
433 GST_clients_broadcast (&connect_msg->header, GNUNET_NO); 416 GST_clients_broadcast (&connect_msg->header, GNUNET_NO);
434} 417}
435 418
@@ -548,7 +531,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
548 GST_plugins_load (&plugin_env_receive_callback, 531 GST_plugins_load (&plugin_env_receive_callback,
549 &plugin_env_address_change_notification, 532 &plugin_env_address_change_notification,
550 &plugin_env_session_end); 533 &plugin_env_session_end);
551 GST_ats = GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL); 534 GST_ats =
535 GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL);
552 GST_neighbours_start (NULL, &neighbours_connect_notification, 536 GST_neighbours_start (NULL, &neighbours_connect_notification,
553 &neighbours_disconnect_notification); 537 &neighbours_disconnect_notification);
554 GST_clients_start (server); 538 GST_clients_start (server);
diff --git a/src/transport/gnunet-service-transport_blacklist.c b/src/transport/gnunet-service-transport_blacklist.c
index 45d01e1e2..78eea2ff9 100644
--- a/src/transport/gnunet-service-transport_blacklist.c
+++ b/src/transport/gnunet-service-transport_blacklist.c
@@ -557,9 +557,7 @@ struct TestConnectionContext
557static void 557static void
558test_connection_ok (void *cls, const struct GNUNET_PeerIdentity *neighbour, 558test_connection_ok (void *cls, const struct GNUNET_PeerIdentity *neighbour,
559 const struct GNUNET_ATS_Information *ats, 559 const struct GNUNET_ATS_Information *ats,
560 uint32_t ats_count, 560 uint32_t ats_count, const char *transport, const void *addr,
561 const char * transport,
562 const void * addr,
563 size_t addrlen) 561 size_t addrlen)
564{ 562{
565 struct TestConnectionContext *tcc = cls; 563 struct TestConnectionContext *tcc = cls;
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c
index 8b022ef7e..ebab72db6 100644
--- a/src/transport/gnunet-service-transport_clients.c
+++ b/src/transport/gnunet-service-transport_clients.c
@@ -165,8 +165,7 @@ setup_client (struct GNUNET_SERVER_Client *client)
165 GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, tc); 165 GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, tc);
166 166
167#if DEBUG_TRANSPORT 167#if DEBUG_TRANSPORT
168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %X connected\n", tc);
169 "Client %X connected\n", tc);
170#endif 169#endif
171 return tc; 170 return tc;
172} 171}
@@ -333,29 +332,26 @@ client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
333static void 332static void
334notify_client_about_neighbour (void *cls, 333notify_client_about_neighbour (void *cls,
335 const struct GNUNET_PeerIdentity *peer, 334 const struct GNUNET_PeerIdentity *peer,
336 const struct GNUNET_ATS_Information 335 const struct GNUNET_ATS_Information *ats,
337 *ats, uint32_t ats_count, 336 uint32_t ats_count, const char *transport,
338 const char * transport, 337 const void *addr, size_t addrlen)
339 const void * addr,
340 size_t addrlen)
341{ 338{
342 struct TransportClient *tc = cls; 339 struct TransportClient *tc = cls;
343 struct ConnectInfoMessage *cim; 340 struct ConnectInfoMessage *cim;
344 struct GNUNET_ATS_Information *ap; 341 struct GNUNET_ATS_Information *ap;
345 size_t size = 342 size_t size =
346 sizeof (struct ConnectInfoMessage) + 343 sizeof (struct ConnectInfoMessage) +
347 ats_count * sizeof (struct GNUNET_ATS_Information); 344 ats_count * sizeof (struct GNUNET_ATS_Information);
348 char buf[size]; 345 char buf[size];
349 346
350 GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE); 347 GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
351 cim = (struct ConnectInfoMessage*) buf; 348 cim = (struct ConnectInfoMessage *) buf;
352 cim->header.size = htons (size); 349 cim->header.size = htons (size);
353 cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 350 cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
354 cim->ats_count = htonl (ats_count); 351 cim->ats_count = htonl (ats_count);
355 cim->id = *peer; 352 cim->id = *peer;
356 ap = (struct GNUNET_ATS_Information *) &cim[1]; 353 ap = (struct GNUNET_ATS_Information *) &cim[1];
357 memcpy (ap, ats, 354 memcpy (ap, ats, ats_count * sizeof (struct GNUNET_ATS_Information));
358 ats_count * sizeof (struct GNUNET_ATS_Information));
359 unicast (tc, &cim->header, GNUNET_NO); 355 unicast (tc, &cim->header, GNUNET_NO);
360} 356}
361 357
@@ -401,10 +397,10 @@ clients_handle_start (void *cls, struct GNUNET_SERVER_Client *client,
401 } 397 }
402 start = (const struct StartMessage *) message; 398 start = (const struct StartMessage *) message;
403 options = ntohl (start->options); 399 options = ntohl (start->options);
404 if ((0 != (1 & options) ) && 400 if ((0 != (1 & options)) &&
405 (0 != 401 (0 !=
406 memcmp (&start->self, &GST_my_identity, 402 memcmp (&start->self, &GST_my_identity,
407 sizeof (struct GNUNET_PeerIdentity)))) 403 sizeof (struct GNUNET_PeerIdentity))))
408 { 404 {
409 /* client thinks this is a different peer, reject */ 405 /* client thinks this is a different peer, reject */
410 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 406 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -799,26 +795,23 @@ clients_handle_peer_address_lookup (void *cls,
799 */ 795 */
800static void 796static void
801output_addresses (void *cls, const struct GNUNET_PeerIdentity *peer, 797output_addresses (void *cls, const struct GNUNET_PeerIdentity *peer,
802 const struct GNUNET_ATS_Information *ats, 798 const struct GNUNET_ATS_Information *ats, uint32_t ats_count,
803 uint32_t ats_count, 799 const char *transport, const void *addr, size_t addrlen)
804 const char * transport,
805 const void * addr,
806 size_t addrlen)
807{ 800{
808 struct GNUNET_SERVER_TransmitContext *tc = cls; 801 struct GNUNET_SERVER_TransmitContext *tc = cls;
809 struct AddressIterateResponseMessage * msg; 802 struct AddressIterateResponseMessage *msg;
810 size_t size; 803 size_t size;
811 804
812 size = 805 size =
813 (sizeof (struct AddressIterateResponseMessage) + strlen(transport) + 1); 806 (sizeof (struct AddressIterateResponseMessage) + strlen (transport) + 1);
814 msg = GNUNET_malloc (size); 807 msg = GNUNET_malloc (size);
815 memcpy (&msg->peer, peer, sizeof (struct GNUNET_PeerIdentity)); 808 memcpy (&msg->peer, peer, sizeof (struct GNUNET_PeerIdentity));
816 memcpy (&msg[0], transport, strlen(transport)+1); 809 memcpy (&msg[0], transport, strlen (transport) + 1);
817 msg->addrlen = ntohs (addrlen); 810 msg->addrlen = ntohs (addrlen);
818 msg->pluginlen = ntohs (strlen(transport)+1); 811 msg->pluginlen = ntohs (strlen (transport) + 1);
819 812
820 transmit_binary_to_client (tc, msg, size); 813 transmit_binary_to_client (tc, msg, size);
821 GNUNET_free(msg); 814 GNUNET_free (msg);
822} 815}
823 816
824 817
@@ -908,9 +901,8 @@ GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, int may_drop)
908 901
909 for (tc = clients_head; tc != NULL; tc = tc->next) 902 for (tc = clients_head; tc != NULL; tc = tc->next)
910 { 903 {
911 if ( (GNUNET_YES == may_drop) && 904 if ((GNUNET_YES == may_drop) && (GNUNET_YES != tc->send_payload))
912 (GNUNET_YES != tc->send_payload) ) 905 continue; /* skip, this client does not care about payload */
913 continue; /* skip, this client does not care about payload */
914 unicast (tc, msg, may_drop); 906 unicast (tc, msg, may_drop);
915 } 907 }
916} 908}
diff --git a/src/transport/gnunet-service-transport_hello.c b/src/transport/gnunet-service-transport_hello.c
index a1c721857..45fdf0a26 100644
--- a/src/transport/gnunet-service-transport_hello.c
+++ b/src/transport/gnunet-service-transport_hello.c
@@ -166,7 +166,8 @@ refresh_hello_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
166 hello_task = GNUNET_SCHEDULER_NO_TASK; 166 hello_task = GNUNET_SCHEDULER_NO_TASK;
167 gc.addr_pos = oal_head; 167 gc.addr_pos = oal_head;
168 gc.expiration = 168 gc.expiration =
169 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION); 169 GNUNET_TIME_relative_to_absolute
170 (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION);
170 GNUNET_free (our_hello); 171 GNUNET_free (our_hello);
171 our_hello = GNUNET_HELLO_create (&GST_my_public_key, &address_generator, &gc); 172 our_hello = GNUNET_HELLO_create (&GST_my_public_key, &address_generator, &gc);
172#if DEBUG_TRANSPORT 173#if DEBUG_TRANSPORT
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index d0d5b099c..0ceba53bc 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -122,7 +122,7 @@ struct SessionDisconnectMessage
122 * Public key of the sender. 122 * Public key of the sender.
123 */ 123 */
124 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key; 124 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
125 125
126 /** 126 /**
127 * Signature of the peer that sends us the disconnect. Only 127 * Signature of the peer that sends us the disconnect. Only
128 * valid if the timestamp is AFTER the timestamp from the 128 * valid if the timestamp is AFTER the timestamp from the
@@ -186,18 +186,18 @@ struct MessageQueue
186 186
187enum State 187enum State
188{ 188{
189 /* fresh peer or completely disconnected */ 189 /* fresh peer or completely disconnected */
190 S_NOT_CONNECTED = 0, 190 S_NOT_CONNECTED = 0,
191 /* sent CONNECT message to other peer, waiting for CONNECT_ACK */ 191 /* sent CONNECT message to other peer, waiting for CONNECT_ACK */
192 S_CONNECT_SENT = 1, 192 S_CONNECT_SENT = 1,
193 /* received CONNECT message to other peer, sending CONNECT_ACK */ 193 /* received CONNECT message to other peer, sending CONNECT_ACK */
194 S_CONNECT_RECV = 4, 194 S_CONNECT_RECV = 4,
195 /* sent CONNECT_ACK message to other peer, wait for ACK or payload */ 195 /* sent CONNECT_ACK message to other peer, wait for ACK or payload */
196 S_CONNECT_RECV_ACK_SENT = 8, 196 S_CONNECT_RECV_ACK_SENT = 8,
197 /* received ACK or payload */ 197 /* received ACK or payload */
198 S_CONNECTED = 16, 198 S_CONNECTED = 16,
199 /* Disconnect in progress */ 199 /* Disconnect in progress */
200 S_DISCONNECT = 32 200 S_DISCONNECT = 32
201}; 201};
202 202
203/** 203/**
@@ -359,7 +359,7 @@ lookup_neighbour (const struct GNUNET_PeerIdentity *pid)
359#define change_state(n, state, ...) change (n, state, __LINE__) 359#define change_state(n, state, ...) change (n, state, __LINE__)
360 360
361static int 361static int
362is_connecting (struct NeighbourMapEntry * n) 362is_connecting (struct NeighbourMapEntry *n)
363{ 363{
364 if ((n->state > S_NOT_CONNECTED) && (n->state < S_CONNECTED)) 364 if ((n->state > S_NOT_CONNECTED) && (n->state < S_CONNECTED))
365 return GNUNET_YES; 365 return GNUNET_YES;
@@ -367,7 +367,7 @@ is_connecting (struct NeighbourMapEntry * n)
367} 367}
368 368
369static int 369static int
370is_connected (struct NeighbourMapEntry * n) 370is_connected (struct NeighbourMapEntry *n)
371{ 371{
372 if (n->state == S_CONNECTED) 372 if (n->state == S_CONNECTED)
373 return GNUNET_YES; 373 return GNUNET_YES;
@@ -375,7 +375,7 @@ is_connected (struct NeighbourMapEntry * n)
375} 375}
376 376
377static int 377static int
378is_disconnecting (struct NeighbourMapEntry * n) 378is_disconnecting (struct NeighbourMapEntry *n)
379{ 379{
380 if (n->state == S_DISCONNECT) 380 if (n->state == S_DISCONNECT)
381 return GNUNET_YES; 381 return GNUNET_YES;
@@ -385,84 +385,85 @@ is_disconnecting (struct NeighbourMapEntry * n)
385static const char * 385static const char *
386print_state (int state) 386print_state (int state)
387{ 387{
388 switch (state) { 388 switch (state)
389 case S_CONNECTED: 389 {
390 return "S_CONNECTED"; 390 case S_CONNECTED:
391 break; 391 return "S_CONNECTED";
392 case S_CONNECT_RECV: 392 break;
393 return "S_CONNECT_RECV"; 393 case S_CONNECT_RECV:
394 break; 394 return "S_CONNECT_RECV";
395 case S_CONNECT_RECV_ACK_SENT: 395 break;
396 return"S_CONNECT_RECV_ACK_SENT"; 396 case S_CONNECT_RECV_ACK_SENT:
397 break; 397 return "S_CONNECT_RECV_ACK_SENT";
398 case S_CONNECT_SENT: 398 break;
399 return "S_CONNECT_SENT"; 399 case S_CONNECT_SENT:
400 break; 400 return "S_CONNECT_SENT";
401 case S_DISCONNECT: 401 break;
402 return "S_DISCONNECT"; 402 case S_DISCONNECT:
403 break; 403 return "S_DISCONNECT";
404 case S_NOT_CONNECTED: 404 break;
405 return "S_NOT_CONNECTED"; 405 case S_NOT_CONNECTED:
406 break; 406 return "S_NOT_CONNECTED";
407 default: 407 break;
408 GNUNET_break (0); 408 default:
409 break; 409 GNUNET_break (0);
410 break;
410 } 411 }
411 return NULL; 412 return NULL;
412} 413}
413 414
414static int 415static int
415change (struct NeighbourMapEntry * n, int state, int line); 416change (struct NeighbourMapEntry *n, int state, int line);
416 417
417static void 418static void
418ats_suggest_cancel (void *cls, 419ats_suggest_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
419 const struct GNUNET_SCHEDULER_TaskContext *tc);
420 420
421static void 421static void
422reset_task (void *cls, 422reset_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
423 const struct GNUNET_SCHEDULER_TaskContext *tc)
424{ 423{
425 struct NeighbourMapEntry * n = cls; 424 struct NeighbourMapEntry *n = cls;
426 425
427 n->state_reset = GNUNET_SCHEDULER_NO_TASK; 426 n->state_reset = GNUNET_SCHEDULER_NO_TASK;
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 "Connection to peer `%s' %s failed in state `%s', resetting connection attempt \n", 430 "Connection to peer `%s' %s failed in state `%s', resetting connection attempt \n",
432 GNUNET_i2s (&n->id), GST_plugins_a2s(n->plugin_name, n->addr, n->addrlen), print_state(n->state)); 431 GNUNET_i2s (&n->id), GST_plugins_a2s (n->plugin_name, n->addr,
432 n->addrlen),
433 print_state (n->state));
433#endif 434#endif
434 GNUNET_STATISTICS_update (GST_stats, 435 GNUNET_STATISTICS_update (GST_stats,
435 gettext_noop ("# failed connection attempts due to timeout"), 436 gettext_noop
436 1, 437 ("# failed connection attempts due to timeout"), 1,
437 GNUNET_NO); 438 GNUNET_NO);
438 439
439 /* resetting state */ 440 /* resetting state */
440 n->state = S_NOT_CONNECTED; 441 n->state = S_NOT_CONNECTED;
441 442
442 /* destroying address */ 443 /* destroying address */
443 GNUNET_ATS_address_destroyed (GST_ats, 444 GNUNET_ATS_address_destroyed (GST_ats, &n->id, n->plugin_name, n->addr,
444 &n->id, 445 n->addrlen, NULL);
445 n->plugin_name,
446 n->addr,
447 n->addrlen,
448 NULL);
449 446
450 /* request new address */ 447 /* request new address */
451 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) 448 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
452 GNUNET_SCHEDULER_cancel(n->ats_suggest); 449 GNUNET_SCHEDULER_cancel (n->ats_suggest);
453 n->ats_suggest = GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, n); 450 n->ats_suggest =
454 GNUNET_ATS_suggest_address(GST_ats, &n->id); 451 GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel,
452 n);
453 GNUNET_ATS_suggest_address (GST_ats, &n->id);
455} 454}
456 455
457static int 456static int
458change (struct NeighbourMapEntry * n, int state, int line) 457change (struct NeighbourMapEntry *n, int state, int line)
459{ 458{
460 char * old = strdup(print_state(n->state)); 459 char *old = strdup (print_state (n->state));
461 char * new = strdup(print_state(state)); 460 char *new = strdup (print_state (state));
462 461
463 /* allowed transitions */ 462 /* allowed transitions */
464 int allowed = GNUNET_NO; 463 int allowed = GNUNET_NO;
465 switch (n->state) { 464
465 switch (n->state)
466 {
466 case S_NOT_CONNECTED: 467 case S_NOT_CONNECTED:
467 if ((state == S_CONNECT_RECV) || (state == S_CONNECT_SENT) || 468 if ((state == S_CONNECT_RECV) || (state == S_CONNECT_SENT) ||
468 (state == S_DISCONNECT)) 469 (state == S_DISCONNECT))
@@ -470,10 +471,12 @@ change (struct NeighbourMapEntry * n, int state, int line)
470 allowed = GNUNET_YES; 471 allowed = GNUNET_YES;
471 472
472 /* Schedule reset task */ 473 /* Schedule reset task */
473 if ((state == S_CONNECT_RECV) || (state == S_CONNECT_SENT) ) 474 if ((state == S_CONNECT_RECV) || (state == S_CONNECT_SENT))
474 { 475 {
475 GNUNET_assert (n->state_reset == GNUNET_SCHEDULER_NO_TASK); 476 GNUNET_assert (n->state_reset == GNUNET_SCHEDULER_NO_TASK);
476 n->state_reset = GNUNET_SCHEDULER_add_delayed (SETUP_CONNECTION_TIMEOUT, &reset_task, n); 477 n->state_reset =
478 GNUNET_SCHEDULER_add_delayed (SETUP_CONNECTION_TIMEOUT, &reset_task,
479 n);
477 } 480 }
478 481
479 break; 482 break;
@@ -481,14 +484,18 @@ change (struct NeighbourMapEntry * n, int state, int line)
481 break; 484 break;
482 case S_CONNECT_RECV: 485 case S_CONNECT_RECV:
483 if ((state == S_NOT_CONNECTED) || (state == S_DISCONNECT) || 486 if ((state == S_NOT_CONNECTED) || (state == S_DISCONNECT) ||
484 (state == S_CONNECTED) || /* FIXME SENT -> RECV ISSUE!*/ (state == S_CONNECT_SENT)) 487 (state == S_CONNECTED) ||
488 /* FIXME SENT -> RECV ISSUE! */ (state == S_CONNECT_SENT))
485 { 489 {
486 if ((state == S_CONNECTED) || (state == S_DISCONNECT) || (state == S_NOT_CONNECTED)) 490 if ((state == S_CONNECTED) || (state == S_DISCONNECT) ||
491 (state == S_NOT_CONNECTED))
487 { 492 {
488#if DEBUG_TRANSPORT 493#if DEBUG_TRANSPORT
489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
490 "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n", 495 "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n",
491 GNUNET_i2s (&n->id), GST_plugins_a2s(n->plugin_name, n->addr, n->addrlen), print_state(n->state), print_state(state)); 496 GNUNET_i2s (&n->id), GST_plugins_a2s (n->plugin_name,
497 n->addr, n->addrlen),
498 print_state (n->state), print_state (state));
492#endif 499#endif
493 GNUNET_assert (n->state_reset != GNUNET_SCHEDULER_NO_TASK); 500 GNUNET_assert (n->state_reset != GNUNET_SCHEDULER_NO_TASK);
494 GNUNET_SCHEDULER_cancel (n->state_reset); 501 GNUNET_SCHEDULER_cancel (n->state_reset);
@@ -501,14 +508,18 @@ change (struct NeighbourMapEntry * n, int state, int line)
501 break; 508 break;
502 case S_CONNECT_SENT: 509 case S_CONNECT_SENT:
503 if ((state == S_NOT_CONNECTED) || (state == S_CONNECTED) || 510 if ((state == S_NOT_CONNECTED) || (state == S_CONNECTED) ||
504 (state == S_DISCONNECT) || /* FIXME SENT -> RECV ISSUE!*/ (state == S_CONNECT_RECV)) 511 (state == S_DISCONNECT) ||
512 /* FIXME SENT -> RECV ISSUE! */ (state == S_CONNECT_RECV))
505 { 513 {
506 if ((state == S_CONNECTED) || (state == S_DISCONNECT) || (state == S_NOT_CONNECTED)) 514 if ((state == S_CONNECTED) || (state == S_DISCONNECT) ||
515 (state == S_NOT_CONNECTED))
507 { 516 {
508#if DEBUG_TRANSPORT 517#if DEBUG_TRANSPORT
509 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 518 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
510 "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n", 519 "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n",
511 GNUNET_i2s (&n->id), GST_plugins_a2s(n->plugin_name, n->addr, n->addrlen), print_state(n->state), print_state(state)); 520 GNUNET_i2s (&n->id), GST_plugins_a2s (n->plugin_name,
521 n->addr, n->addrlen),
522 print_state (n->state), print_state (state));
512#endif 523#endif
513 GNUNET_assert (n->state_reset != GNUNET_SCHEDULER_NO_TASK); 524 GNUNET_assert (n->state_reset != GNUNET_SCHEDULER_NO_TASK);
514 GNUNET_SCHEDULER_cancel (n->state_reset); 525 GNUNET_SCHEDULER_cancel (n->state_reset);
@@ -528,11 +539,11 @@ change (struct NeighbourMapEntry * n, int state, int line)
528 break; 539 break;
529 case S_DISCONNECT: 540 case S_DISCONNECT:
530 /* 541 /*
531 if (state == S_NOT_CONNECTED) 542 * if (state == S_NOT_CONNECTED)
532 { 543 * {
533 allowed = GNUNET_YES; 544 * allowed = GNUNET_YES;
534 break; 545 * break;
535 }*/ 546 * } */
536 break; 547 break;
537 default: 548 default:
538 GNUNET_break (0); 549 GNUNET_break (0);
@@ -543,8 +554,8 @@ change (struct NeighbourMapEntry * n, int state, int line)
543 if (allowed == GNUNET_NO) 554 if (allowed == GNUNET_NO)
544 { 555 {
545 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 556 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
546 "Illegal state transition from `%s' to `%s' in line %u \n", 557 "Illegal state transition from `%s' to `%s' in line %u \n", old,
547 old, new, line); 558 new, line);
548 GNUNET_break (0); 559 GNUNET_break (0);
549 GNUNET_free (old); 560 GNUNET_free (old);
550 GNUNET_free (new); 561 GNUNET_free (new);
@@ -553,8 +564,9 @@ change (struct NeighbourMapEntry * n, int state, int line)
553 564
554 n->state = state; 565 n->state = state;
555#if DEBUG_TRANSPORT 566#if DEBUG_TRANSPORT
556 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "State for neighbour `%s' %X changed from `%s' to `%s' in line %u\n", 567 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
557 GNUNET_i2s (&n->id), n, old, new, line); 568 "State for neighbour `%s' %X changed from `%s' to `%s' in line %u\n",
569 GNUNET_i2s (&n->id), n, old, new, line);
558#endif 570#endif
559 GNUNET_free (old); 571 GNUNET_free (old);
560 GNUNET_free (new); 572 GNUNET_free (new);
@@ -562,19 +574,12 @@ change (struct NeighbourMapEntry * n, int state, int line)
562} 574}
563 575
564static ssize_t 576static ssize_t
565send_with_plugin ( const struct GNUNET_PeerIdentity * target, 577send_with_plugin (const struct GNUNET_PeerIdentity *target, const char *msgbuf,
566 const char *msgbuf, 578 size_t msgbuf_size, uint32_t priority,
567 size_t msgbuf_size, 579 struct GNUNET_TIME_Relative timeout, struct Session *session,
568 uint32_t priority, 580 const char *plugin_name, const void *addr, size_t addrlen,
569 struct GNUNET_TIME_Relative timeout, 581 int force_address, GNUNET_TRANSPORT_TransmitContinuation cont,
570 struct Session * session, 582 void *cont_cls)
571 const char * plugin_name,
572 const void *addr,
573 size_t addrlen,
574 int force_address,
575 GNUNET_TRANSPORT_TransmitContinuation cont,
576 void *cont_cls)
577
578{ 583{
579 struct GNUNET_TRANSPORT_PluginFunctions *papi; 584 struct GNUNET_TRANSPORT_PluginFunctions *papi;
580 size_t ret = GNUNET_SYSERR; 585 size_t ret = GNUNET_SYSERR;
@@ -602,15 +607,9 @@ send_with_plugin ( const struct GNUNET_PeerIdentity * target,
602 return GNUNET_SYSERR; 607 return GNUNET_SYSERR;
603 } 608 }
604 609
605 ret = papi->send (papi->cls, 610 ret =
606 target, 611 papi->send (papi->cls, target, msgbuf, msgbuf_size, 0, timeout, session,
607 msgbuf, msgbuf_size, 612 addr, addrlen, GNUNET_YES, cont, cont_cls);
608 0,
609 timeout,
610 session,
611 addr, addrlen,
612 GNUNET_YES,
613 cont, cont_cls);
614 613
615 if (ret == -1) 614 if (ret == -1)
616 { 615 {
@@ -713,7 +712,7 @@ try_transmission_to_peer (struct NeighbourMapEntry *n)
713 n->is_active = mq; 712 n->is_active = mq;
714 mq->n = n; 713 mq->n = n;
715 714
716 if ((n->session == NULL) && (n->addr == NULL) && (n->addrlen == 0)) 715 if ((n->session == NULL) && (n->addr == NULL) && (n->addrlen == 0))
717 { 716 {
718 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No address for peer `%s'\n", 717 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No address for peer `%s'\n",
719 GNUNET_i2s (&n->id)); 718 GNUNET_i2s (&n->id));
@@ -723,12 +722,11 @@ try_transmission_to_peer (struct NeighbourMapEntry *n)
723 return; 722 return;
724 } 723 }
725 724
726 ret = send_with_plugin (&n->id, 725 ret =
727 mq->message_buf, mq->message_buf_size, 0, 726 send_with_plugin (&n->id, mq->message_buf, mq->message_buf_size, 0,
728 timeout, 727 timeout, n->session, n->plugin_name, n->addr,
729 n->session, n->plugin_name, n->addr, n->addrlen, 728 n->addrlen, GNUNET_YES, &transmit_send_continuation,
730 GNUNET_YES, 729 mq);
731 &transmit_send_continuation, mq);
732 if (ret == -1) 730 if (ret == -1)
733 { 731 {
734 /* failure, but 'send' would not call continuation in this case, 732 /* failure, but 'send' would not call continuation in this case,
@@ -749,7 +747,8 @@ static void
749transmission_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 747transmission_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
750{ 748{
751 struct NeighbourMapEntry *n = cls; 749 struct NeighbourMapEntry *n = cls;
752 GNUNET_assert (NULL != lookup_neighbour(&n->id)); 750
751 GNUNET_assert (NULL != lookup_neighbour (&n->id));
753 n->transmission_task = GNUNET_SCHEDULER_NO_TASK; 752 n->transmission_task = GNUNET_SCHEDULER_NO_TASK;
754 try_transmission_to_peer (n); 753 try_transmission_to_peer (n);
755} 754}
@@ -774,56 +773,61 @@ GST_neighbours_start (void *cls, GNUNET_TRANSPORT_NotifyConnect connect_cb,
774 773
775 774
776static void 775static void
777send_disconnect_cont (void *cls, 776send_disconnect_cont (void *cls, const struct GNUNET_PeerIdentity *target,
778 const struct GNUNET_PeerIdentity * target, 777 int result)
779 int result)
780{ 778{
781#if DEBUG_TRANSPORT 779#if DEBUG_TRANSPORT
782 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending DISCONNECT message to peer `%4s': %i\n", 780 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
781 "Sending DISCONNECT message to peer `%4s': %i\n",
783 GNUNET_i2s (target), result); 782 GNUNET_i2s (target), result);
784#endif 783#endif
785} 784}
786 785
787 786
788static int 787static int
789send_disconnect (const struct GNUNET_PeerIdentity * target, 788send_disconnect (const struct GNUNET_PeerIdentity *target,
790 const char *plugin_name, 789 const char *plugin_name, const char *sender_address,
791 const char *sender_address, uint16_t sender_address_len, 790 uint16_t sender_address_len, struct Session *session)
792 struct Session *session)
793{ 791{
794 size_t ret; 792 size_t ret;
795 struct SessionDisconnectMessage disconnect_msg; 793 struct SessionDisconnectMessage disconnect_msg;
796 794
797#if DEBUG_TRANSPORT 795#if DEBUG_TRANSPORT
798 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending DISCONNECT message to peer `%4s'\n", 796 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
797 "Sending DISCONNECT message to peer `%4s'\n",
799 GNUNET_i2s (target)); 798 GNUNET_i2s (target));
800#endif 799#endif
801 800
802 disconnect_msg.header.size = htons (sizeof (struct SessionDisconnectMessage)); 801 disconnect_msg.header.size = htons (sizeof (struct SessionDisconnectMessage));
803 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); 802 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
804 disconnect_msg.reserved = htonl (0); 803 disconnect_msg.reserved = htonl (0);
805 disconnect_msg.purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + 804 disconnect_msg.purpose.size =
806 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + 805 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
807 sizeof (struct GNUNET_TIME_AbsoluteNBO) ); 806 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
808 disconnect_msg.purpose.purpose = htonl (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT); 807 sizeof (struct GNUNET_TIME_AbsoluteNBO));
809 disconnect_msg.timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); 808 disconnect_msg.purpose.purpose =
809 htonl (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT);
810 disconnect_msg.timestamp =
811 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
810 disconnect_msg.public_key = GST_my_public_key; 812 disconnect_msg.public_key = GST_my_public_key;
811 GNUNET_assert (GNUNET_OK == 813 GNUNET_assert (GNUNET_OK ==
812 GNUNET_CRYPTO_rsa_sign (GST_my_private_key, 814 GNUNET_CRYPTO_rsa_sign (GST_my_private_key,
813 &disconnect_msg.purpose, 815 &disconnect_msg.purpose,
814 &disconnect_msg.signature)); 816 &disconnect_msg.signature));
815 817
816 ret = send_with_plugin(target, 818 ret =
817 (const char *) &disconnect_msg, sizeof (disconnect_msg), 819 send_with_plugin (target, (const char *) &disconnect_msg,
818 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, 820 sizeof (disconnect_msg), UINT32_MAX,
819 session, plugin_name, sender_address, sender_address_len, 821 GNUNET_TIME_UNIT_FOREVER_REL, session, plugin_name,
820 GNUNET_YES, &send_disconnect_cont, NULL); 822 sender_address, sender_address_len, GNUNET_YES,
823 &send_disconnect_cont, NULL);
821 824
822 if (ret == GNUNET_SYSERR) 825 if (ret == GNUNET_SYSERR)
823 return GNUNET_SYSERR; 826 return GNUNET_SYSERR;
824 827
825 GNUNET_STATISTICS_update (GST_stats, 828 GNUNET_STATISTICS_update (GST_stats,
826 gettext_noop ("# peers disconnected due to external request"), 1, 829 gettext_noop
830 ("# peers disconnected due to external request"), 1,
827 GNUNET_NO); 831 GNUNET_NO);
828 return GNUNET_OK; 832 return GNUNET_OK;
829} 833}
@@ -837,21 +841,24 @@ static void
837disconnect_neighbour (struct NeighbourMapEntry *n) 841disconnect_neighbour (struct NeighbourMapEntry *n)
838{ 842{
839 struct MessageQueue *mq; 843 struct MessageQueue *mq;
840 int was_connected = is_connected(n); 844 int was_connected = is_connected (n);
841 845
842 /* send DISCONNECT MESSAGE */ 846 /* send DISCONNECT MESSAGE */
843 if (is_connected(n) || is_connecting(n)) 847 if (is_connected (n) || is_connecting (n))
844 { 848 {
845 if (GNUNET_OK == send_disconnect(&n->id, n->plugin_name, n->addr, n->addrlen, n->session)) 849 if (GNUNET_OK ==
850 send_disconnect (&n->id, n->plugin_name, n->addr, n->addrlen,
851 n->session))
846 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent DISCONNECT_MSG to `%s'\n", 852 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent DISCONNECT_MSG to `%s'\n",
847 GNUNET_i2s (&n->id)); 853 GNUNET_i2s (&n->id));
848 else 854 else
849 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could not send DISCONNECT_MSG to `%s'\n", 855 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
856 "Could not send DISCONNECT_MSG to `%s'\n",
850 GNUNET_i2s (&n->id)); 857 GNUNET_i2s (&n->id));
851 } 858 }
852 859
853 860
854 if (is_disconnecting(n)) 861 if (is_disconnecting (n))
855 return; 862 return;
856 change_state (n, S_DISCONNECT); 863 change_state (n, S_DISCONNECT);
857 864
@@ -871,7 +878,7 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
871 { 878 {
872 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != n->keepalive_task); 879 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != n->keepalive_task);
873 GNUNET_SCHEDULER_cancel (n->keepalive_task); 880 GNUNET_SCHEDULER_cancel (n->keepalive_task);
874 n->keepalive_task = GNUNET_SCHEDULER_NO_TASK; 881 n->keepalive_task = GNUNET_SCHEDULER_NO_TASK;
875 GNUNET_assert (neighbours_connected > 0); 882 GNUNET_assert (neighbours_connected > 0);
876 neighbours_connected--; 883 neighbours_connected--;
877 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), -1, 884 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), -1,
@@ -929,7 +936,8 @@ neighbour_timeout_task (void *cls,
929 n->timeout_task = GNUNET_SCHEDULER_NO_TASK; 936 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
930 937
931 GNUNET_STATISTICS_update (GST_stats, 938 GNUNET_STATISTICS_update (GST_stats,
932 gettext_noop ("# peers disconnected due to timeout"), 1, 939 gettext_noop
940 ("# peers disconnected due to timeout"), 1,
933 GNUNET_NO); 941 GNUNET_NO);
934 disconnect_neighbour (n); 942 disconnect_neighbour (n);
935} 943}
@@ -943,27 +951,24 @@ neighbour_timeout_task (void *cls,
943 */ 951 */
944static void 952static void
945neighbour_keepalive_task (void *cls, 953neighbour_keepalive_task (void *cls,
946 const struct GNUNET_SCHEDULER_TaskContext *tc) 954 const struct GNUNET_SCHEDULER_TaskContext *tc)
947{ 955{
948 struct NeighbourMapEntry *n = cls; 956 struct NeighbourMapEntry *n = cls;
949 struct GNUNET_MessageHeader m; 957 struct GNUNET_MessageHeader m;
950 958
951 n->keepalive_task = GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY, 959 n->keepalive_task =
952 &neighbour_keepalive_task, 960 GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY,
953 n); 961 &neighbour_keepalive_task, n);
954 GNUNET_assert (is_connected(n)); 962 GNUNET_assert (is_connected (n));
955 GNUNET_STATISTICS_update (GST_stats, 963 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# keepalives sent"), 1,
956 gettext_noop ("# keepalives sent"), 1, 964 GNUNET_NO);
957 GNUNET_NO);
958 m.size = htons (sizeof (struct GNUNET_MessageHeader)); 965 m.size = htons (sizeof (struct GNUNET_MessageHeader));
959 m.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE); 966 m.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE);
960 967
961 send_with_plugin(&n->id, (const void *) &m, 968 send_with_plugin (&n->id, (const void *) &m, sizeof (m),
962 sizeof (m), 969 UINT32_MAX /* priority */ ,
963 UINT32_MAX /* priority */ , 970 GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->plugin_name,
964 GNUNET_TIME_UNIT_FOREVER_REL, 971 n->addr, n->addrlen, GNUNET_YES, NULL, NULL);
965 n->session, n->plugin_name, n->addr, n->addrlen,
966 GNUNET_YES, NULL, NULL);
967} 972}
968 973
969 974
@@ -983,18 +988,18 @@ disconnect_all_neighbours (void *cls, const GNUNET_HashCode * key, void *value)
983 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s', %s\n", 988 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s', %s\n",
984 GNUNET_i2s (&n->id), "SHUTDOWN_TASK"); 989 GNUNET_i2s (&n->id), "SHUTDOWN_TASK");
985#endif 990#endif
986 if (is_connected(n)) 991 if (is_connected (n))
987 GNUNET_STATISTICS_update (GST_stats, 992 GNUNET_STATISTICS_update (GST_stats,
988 gettext_noop ("# peers disconnected due to global disconnect"), 1, 993 gettext_noop
989 GNUNET_NO); 994 ("# peers disconnected due to global disconnect"),
995 1, GNUNET_NO);
990 disconnect_neighbour (n); 996 disconnect_neighbour (n);
991 return GNUNET_OK; 997 return GNUNET_OK;
992} 998}
993 999
994 1000
995static void 1001static void
996ats_suggest_cancel (void *cls, 1002ats_suggest_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
997 const struct GNUNET_SCHEDULER_TaskContext *tc)
998{ 1003{
999 struct NeighbourMapEntry *n = cls; 1004 struct NeighbourMapEntry *n = cls;
1000 1005
@@ -1004,7 +1009,7 @@ ats_suggest_cancel (void *cls,
1004 " ATS did not suggested address to connect to peer `%s'\n", 1009 " ATS did not suggested address to connect to peer `%s'\n",
1005 GNUNET_i2s (&n->id)); 1010 GNUNET_i2s (&n->id));
1006 1011
1007 disconnect_neighbour(n); 1012 disconnect_neighbour (n);
1008} 1013}
1009 1014
1010/** 1015/**
@@ -1039,44 +1044,39 @@ GST_neighbours_stop ()
1039 * @param success GNUNET_OK on success 1044 * @param success GNUNET_OK on success
1040 */ 1045 */
1041static void 1046static void
1042send_connect_continuation (void *cls, 1047send_connect_continuation (void *cls, const struct GNUNET_PeerIdentity *target,
1043 const struct GNUNET_PeerIdentity * target, 1048 int success)
1044 int success)
1045
1046{ 1049{
1047 struct NeighbourMapEntry *n = cls; 1050 struct NeighbourMapEntry *n = cls;
1048 1051
1049 GNUNET_assert (n != NULL); 1052 GNUNET_assert (n != NULL);
1050 GNUNET_assert (!is_connected(n)); 1053 GNUNET_assert (!is_connected (n));
1051 1054
1052 if (is_disconnecting(n)) 1055 if (is_disconnecting (n))
1053 return; /* neighbour is going away */ 1056 return; /* neighbour is going away */
1054 1057
1055 if (GNUNET_YES != success) 1058 if (GNUNET_YES != success)
1056 { 1059 {
1057#if DEBUG_TRANSPORT 1060#if DEBUG_TRANSPORT
1058 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1061 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1059 "Failed to send CONNECT_MSG to peer `%4s' with plugin `%s' address '%s' session %X, asking ATS for new address \n", 1062 "Failed to send CONNECT_MSG to peer `%4s' with plugin `%s' address '%s' session %X, asking ATS for new address \n",
1060 GNUNET_i2s (&n->id), n->plugin_name, 1063 GNUNET_i2s (&n->id), n->plugin_name,
1061 (n->addrlen == 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, 1064 (n->addrlen ==
1062 n->addr, 1065 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, n->addr,
1063 n->addrlen), 1066 n->addrlen), n->session);
1064 n->session);
1065#endif 1067#endif
1066 1068
1067 GNUNET_ATS_address_destroyed (GST_ats, 1069 GNUNET_ATS_address_destroyed (GST_ats, &n->id, n->plugin_name, n->addr,
1068 &n->id, 1070 n->addrlen, NULL);
1069 n->plugin_name,
1070 n->addr,
1071 n->addrlen,
1072 NULL);
1073 1071
1074 change_state(n, S_NOT_CONNECTED); 1072 change_state (n, S_NOT_CONNECTED);
1075 1073
1076 if (n->ats_suggest!= GNUNET_SCHEDULER_NO_TASK) 1074 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
1077 GNUNET_SCHEDULER_cancel(n->ats_suggest); 1075 GNUNET_SCHEDULER_cancel (n->ats_suggest);
1078 n->ats_suggest = GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, n); 1076 n->ats_suggest =
1079 GNUNET_ATS_suggest_address(GST_ats, &n->id); 1077 GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel,
1078 n);
1079 GNUNET_ATS_suggest_address (GST_ats, &n->id);
1080 return; 1080 return;
1081 } 1081 }
1082 1082
@@ -1093,40 +1093,36 @@ send_connect_continuation (void *cls,
1093 */ 1093 */
1094static void 1094static void
1095send_switch_address_continuation (void *cls, 1095send_switch_address_continuation (void *cls,
1096 const struct GNUNET_PeerIdentity * target, 1096 const struct GNUNET_PeerIdentity *target,
1097 int success) 1097 int success)
1098
1099{ 1098{
1100 struct NeighbourMapEntry *n = cls; 1099 struct NeighbourMapEntry *n = cls;
1101 1100
1102 GNUNET_assert (n != NULL); 1101 GNUNET_assert (n != NULL);
1103 if (is_disconnecting(n)) 1102 if (is_disconnecting (n))
1104 return; /* neighbour is going away */ 1103 return; /* neighbour is going away */
1105 1104
1106 GNUNET_assert (n->state == S_CONNECTED); 1105 GNUNET_assert (n->state == S_CONNECTED);
1107 if (GNUNET_YES != success) 1106 if (GNUNET_YES != success)
1108 { 1107 {
1109#if DEBUG_TRANSPORT 1108#if DEBUG_TRANSPORT
1110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1109 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1111 "Failed to switch connected peer `%s' to plugin `%s' address '%s' session %X, asking ATS for new address \n", 1110 "Failed to switch connected peer `%s' to plugin `%s' address '%s' session %X, asking ATS for new address \n",
1112 GNUNET_i2s (&n->id), n->plugin_name, 1111 GNUNET_i2s (&n->id), n->plugin_name,
1113 (n->addrlen == 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, 1112 (n->addrlen ==
1114 n->addr, 1113 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, n->addr,
1115 n->addrlen), 1114 n->addrlen), n->session);
1116 n->session);
1117#endif 1115#endif
1118 1116
1119 GNUNET_ATS_address_destroyed (GST_ats, 1117 GNUNET_ATS_address_destroyed (GST_ats, &n->id, n->plugin_name, n->addr,
1120 &n->id, 1118 n->addrlen, NULL);
1121 n->plugin_name,
1122 n->addr,
1123 n->addrlen,
1124 NULL);
1125 1119
1126 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) 1120 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
1127 GNUNET_SCHEDULER_cancel(n->ats_suggest); 1121 GNUNET_SCHEDULER_cancel (n->ats_suggest);
1128 n->ats_suggest = GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, n); 1122 n->ats_suggest =
1129 GNUNET_ATS_suggest_address(GST_ats, &n->id); 1123 GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel,
1124 n);
1125 GNUNET_ATS_suggest_address (GST_ats, &n->id);
1130 return; 1126 return;
1131 } 1127 }
1132} 1128}
@@ -1141,40 +1137,37 @@ send_switch_address_continuation (void *cls,
1141 */ 1137 */
1142static void 1138static void
1143send_connect_ack_continuation (void *cls, 1139send_connect_ack_continuation (void *cls,
1144 const struct GNUNET_PeerIdentity * target, 1140 const struct GNUNET_PeerIdentity *target,
1145 int success) 1141 int success)
1146
1147{ 1142{
1148 struct NeighbourMapEntry *n = cls; 1143 struct NeighbourMapEntry *n = cls;
1149 1144
1150 GNUNET_assert (n != NULL); 1145 GNUNET_assert (n != NULL);
1151 1146
1152 if (GNUNET_YES == success) 1147 if (GNUNET_YES == success)
1153 return; /* sending successful */ 1148 return; /* sending successful */
1154 1149
1155 /* sending failed, ask for next address */ 1150 /* sending failed, ask for next address */
1156#if DEBUG_TRANSPORT 1151#if DEBUG_TRANSPORT
1157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1158 "Failed to send CONNECT_MSG to peer `%4s' with plugin `%s' address '%s' session %X, asking ATS for new address \n", 1153 "Failed to send CONNECT_MSG to peer `%4s' with plugin `%s' address '%s' session %X, asking ATS for new address \n",
1159 GNUNET_i2s (&n->id), n->plugin_name, 1154 GNUNET_i2s (&n->id), n->plugin_name,
1160 (n->addrlen == 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, 1155 (n->addrlen == 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name,
1161 n->addr, 1156 n->addr,
1162 n->addrlen), 1157 n->addrlen),
1163 n->session); 1158 n->session);
1164#endif 1159#endif
1165 change_state(n, S_NOT_CONNECTED); 1160 change_state (n, S_NOT_CONNECTED);
1166 1161
1167 GNUNET_ATS_address_destroyed (GST_ats, 1162 GNUNET_ATS_address_destroyed (GST_ats, &n->id, n->plugin_name, n->addr,
1168 &n->id, 1163 n->addrlen, NULL);
1169 n->plugin_name,
1170 n->addr,
1171 n->addrlen,
1172 NULL);
1173 1164
1174 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) 1165 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
1175 GNUNET_SCHEDULER_cancel(n->ats_suggest); 1166 GNUNET_SCHEDULER_cancel (n->ats_suggest);
1176 n->ats_suggest = GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, n); 1167 n->ats_suggest =
1177 GNUNET_ATS_suggest_address(GST_ats, &n->id); 1168 GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel,
1169 n);
1170 GNUNET_ATS_suggest_address (GST_ats, &n->id);
1178} 1171}
1179 1172
1180/** 1173/**
@@ -1194,12 +1187,15 @@ send_connect_ack_continuation (void *cls,
1194 */ 1187 */
1195int 1188int
1196GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, 1189GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1197 const char *plugin_name, const void *address, 1190 const char *plugin_name,
1198 size_t address_len, struct Session *session, 1191 const void *address, size_t address_len,
1199 const struct GNUNET_ATS_Information 1192 struct Session *session,
1200 *ats, uint32_t ats_count, 1193 const struct GNUNET_ATS_Information *ats,
1201 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 1194 uint32_t ats_count,
1202 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 1195 struct GNUNET_BANDWIDTH_Value32NBO
1196 bandwidth_in,
1197 struct GNUNET_BANDWIDTH_Value32NBO
1198 bandwidth_out)
1203{ 1199{
1204 struct NeighbourMapEntry *n; 1200 struct NeighbourMapEntry *n;
1205 struct SessionConnectMessage connect_msg; 1201 struct SessionConnectMessage connect_msg;
@@ -1219,14 +1215,14 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1219 { 1215 {
1220 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1216 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1221 "ATS offered suggested us empty address: plugin NULL"); 1217 "ATS offered suggested us empty address: plugin NULL");
1222 GNUNET_break_op(0); 1218 GNUNET_break_op (0);
1223 checks_failed = GNUNET_YES; 1219 checks_failed = GNUNET_YES;
1224 } 1220 }
1225 if ((address == NULL) && (address_len == 0 ) && (session == NULL)) 1221 if ((address == NULL) && (address_len == 0) && (session == NULL))
1226 { 1222 {
1227 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1223 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1228 "ATS offered suggested us empty address: address NULL & session NULL"); 1224 "ATS offered suggested us empty address: address NULL & session NULL");
1229 GNUNET_break_op(0); 1225 GNUNET_break_op (0);
1230 checks_failed = GNUNET_YES; 1226 checks_failed = GNUNET_YES;
1231 } 1227 }
1232 1228
@@ -1236,12 +1232,10 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1236 1232
1237 if (checks_failed == GNUNET_YES) 1233 if (checks_failed == GNUNET_YES)
1238 { 1234 {
1239 GNUNET_ATS_address_destroyed (GST_ats, 1235 GNUNET_ATS_address_destroyed (GST_ats, peer, plugin_name, address,
1240 peer, 1236 address_len, session);
1241 plugin_name, address,
1242 address_len, session);
1243 if (n != NULL) 1237 if (n != NULL)
1244 GNUNET_ATS_suggest_address(GST_ats, peer); 1238 GNUNET_ATS_suggest_address (GST_ats, peer);
1245 return GNUNET_NO; 1239 return GNUNET_NO;
1246 } 1240 }
1247 1241
@@ -1253,18 +1247,18 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1253 (address_len == 0) ? "<inbound>" : GST_plugins_a2s (plugin_name, 1247 (address_len == 0) ? "<inbound>" : GST_plugins_a2s (plugin_name,
1254 address, 1248 address,
1255 address_len), 1249 address_len),
1256 session, (is_connected(n) ? "CONNECTED" : "NOT CONNECTED"), 1250 session, (is_connected (n) ? "CONNECTED" : "NOT CONNECTED"),
1257 GNUNET_i2s (peer)); 1251 GNUNET_i2s (peer));
1258#endif 1252#endif
1259 1253
1260 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) 1254 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
1261 { 1255 {
1262 GNUNET_SCHEDULER_cancel(n->ats_suggest); 1256 GNUNET_SCHEDULER_cancel (n->ats_suggest);
1263 n->ats_suggest = GNUNET_SCHEDULER_NO_TASK; 1257 n->ats_suggest = GNUNET_SCHEDULER_NO_TASK;
1264 } 1258 }
1265 1259
1266 // do not switch addresses just update quotas 1260 // do not switch addresses just update quotas
1267 if ((is_connected(n)) && (address_len == n->addrlen)) 1261 if ((is_connected (n)) && (address_len == n->addrlen))
1268 { 1262 {
1269 if ((0 == memcmp (address, n->addr, address_len)) && 1263 if ((0 == memcmp (address, n->addr, address_len)) &&
1270 (n->session == session)) 1264 (n->session == session))
@@ -1272,16 +1266,15 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1272 struct QuotaSetMessage q_msg; 1266 struct QuotaSetMessage q_msg;
1273 1267
1274#if DEBUG_TRANSPORT 1268#if DEBUG_TRANSPORT
1275GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1276 "Sending outbound quota of %u Bps and inbound quota of %u Bps for peer `%s' to all clients\n", 1270 "Sending outbound quota of %u Bps and inbound quota of %u Bps for peer `%s' to all clients\n",
1277 ntohl (n->bandwidth_out.value__), 1271 ntohl (n->bandwidth_out.value__),
1278 ntohl (n->bandwidth_in.value__), 1272 ntohl (n->bandwidth_in.value__), GNUNET_i2s (peer));
1279 GNUNET_i2s (peer));
1280#endif 1273#endif
1281 1274
1282 n->bandwidth_in = bandwidth_in; 1275 n->bandwidth_in = bandwidth_in;
1283 n->bandwidth_out = bandwidth_out; 1276 n->bandwidth_out = bandwidth_out;
1284 GST_neighbours_set_incoming_quota(&n->id, n->bandwidth_in); 1277 GST_neighbours_set_incoming_quota (&n->id, n->bandwidth_in);
1285 1278
1286 q_msg.header.size = htons (sizeof (struct QuotaSetMessage)); 1279 q_msg.header.size = htons (sizeof (struct QuotaSetMessage));
1287 q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA); 1280 q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA);
@@ -1324,9 +1317,11 @@ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1324 1317
1325 change_state (n, S_CONNECT_SENT); 1318 change_state (n, S_CONNECT_SENT);
1326 1319
1327 ret = send_with_plugin (peer, (const char *) &connect_msg, msg_len, UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, 1320 ret =
1328 session, plugin_name, address, address_len, 1321 send_with_plugin (peer, (const char *) &connect_msg, msg_len,
1329 GNUNET_YES, &send_connect_continuation, n); 1322 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session,
1323 plugin_name, address, address_len, GNUNET_YES,
1324 &send_connect_continuation, n);
1330 1325
1331 return GNUNET_NO; 1326 return GNUNET_NO;
1332 } 1327 }
@@ -1336,13 +1331,16 @@ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1336 msg_len = sizeof (struct SessionConnectMessage); 1331 msg_len = sizeof (struct SessionConnectMessage);
1337 connect_msg.header.size = htons (msg_len); 1332 connect_msg.header.size = htons (msg_len);
1338 connect_msg.header.type = 1333 connect_msg.header.type =
1339 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK); 1334 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK);
1340 connect_msg.reserved = htonl (0); 1335 connect_msg.reserved = htonl (0);
1341 connect_msg.timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); 1336 connect_msg.timestamp =
1337 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
1342 1338
1343 ret = send_with_plugin(&n->id, (const void *) &connect_msg, msg_len, UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, 1339 ret =
1344 session, plugin_name, address, address_len, 1340 send_with_plugin (&n->id, (const void *) &connect_msg, msg_len,
1345 GNUNET_YES, &send_connect_ack_continuation, n); 1341 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session,
1342 plugin_name, address, address_len, GNUNET_YES,
1343 &send_connect_ack_continuation, n);
1346 return GNUNET_NO; 1344 return GNUNET_NO;
1347 } 1345 }
1348 /* connected peer is switching addresses */ 1346 /* connected peer is switching addresses */
@@ -1356,26 +1354,28 @@ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1356 connect_msg.timestamp = 1354 connect_msg.timestamp =
1357 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); 1355 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
1358 1356
1359 ret = send_with_plugin (peer, (const char *) &connect_msg, msg_len, UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, 1357 ret =
1360 session, plugin_name, address, address_len, 1358 send_with_plugin (peer, (const char *) &connect_msg, msg_len,
1361 GNUNET_YES, &send_switch_address_continuation, n); 1359 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session,
1360 plugin_name, address, address_len, GNUNET_YES,
1361 &send_switch_address_continuation, n);
1362 if (ret == GNUNET_SYSERR) 1362 if (ret == GNUNET_SYSERR)
1363 { 1363 {
1364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1365 "Failed to send CONNECT_MESSAGE to `%4s' using plugin `%s' address '%s' session %X\n", 1365 "Failed to send CONNECT_MESSAGE to `%4s' using plugin `%s' address '%s' session %X\n",
1366 GNUNET_i2s (peer), plugin_name, 1366 GNUNET_i2s (peer), plugin_name,
1367 (address_len == 0) ? "<inbound>" : GST_plugins_a2s (plugin_name, 1367 (address_len ==
1368 address, 1368 0) ? "<inbound>" : GST_plugins_a2s (plugin_name, address,
1369 address_len), 1369 address_len), session);
1370 session);
1371 } 1370 }
1372 return GNUNET_NO; 1371 return GNUNET_NO;
1373 } 1372 }
1374 else if (n->state == S_CONNECT_SENT) 1373 else if (n->state == S_CONNECT_SENT)
1375 { 1374 {
1376 return GNUNET_NO; 1375 return GNUNET_NO;
1377 } 1376 }
1378 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid connection state to switch addresses %u \n", n->state); 1377 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1378 "Invalid connection state to switch addresses %u \n", n->state);
1379 GNUNET_break_op (0); 1379 GNUNET_break_op (0);
1380 return GNUNET_NO; 1380 return GNUNET_NO;
1381} 1381}
@@ -1383,7 +1383,7 @@ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1383 1383
1384/** 1384/**
1385 * Create an entry in the neighbour map for the given peer 1385 * Create an entry in the neighbour map for the given peer
1386 * 1386 *
1387 * @param peer peer to create an entry for 1387 * @param peer peer to create an entry for
1388 * @return new neighbour map entry 1388 * @return new neighbour map entry
1389 */ 1389 */
@@ -1394,22 +1394,21 @@ setup_neighbour (const struct GNUNET_PeerIdentity *peer)
1394 1394
1395#if DEBUG_TRANSPORT 1395#if DEBUG_TRANSPORT
1396 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1396 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1397 "Unknown peer `%s', creating new neighbour\n", 1397 "Unknown peer `%s', creating new neighbour\n", GNUNET_i2s (peer));
1398 GNUNET_i2s (peer));
1399#endif 1398#endif
1400 n = GNUNET_malloc (sizeof (struct NeighbourMapEntry)); 1399 n = GNUNET_malloc (sizeof (struct NeighbourMapEntry));
1401 n->id = *peer; 1400 n->id = *peer;
1402 n->state = S_NOT_CONNECTED; 1401 n->state = S_NOT_CONNECTED;
1403 GNUNET_BANDWIDTH_tracker_init (&n->in_tracker, 1402 GNUNET_BANDWIDTH_tracker_init (&n->in_tracker,
1404 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, 1403 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
1405 MAX_BANDWIDTH_CARRY_S); 1404 MAX_BANDWIDTH_CARRY_S);
1406 n->timeout_task = 1405 n->timeout_task =
1407 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1406 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1408 &neighbour_timeout_task, n); 1407 &neighbour_timeout_task, n);
1409 GNUNET_assert (GNUNET_OK == 1408 GNUNET_assert (GNUNET_OK ==
1410 GNUNET_CONTAINER_multihashmap_put (neighbours, 1409 GNUNET_CONTAINER_multihashmap_put (neighbours,
1411 &n->id.hashPubKey, n, 1410 &n->id.hashPubKey, n,
1412 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1411 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1413 return n; 1412 return n;
1414} 1413}
1415 1414
@@ -1433,8 +1432,8 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
1433 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to connect to peer `%s'\n", 1432 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to connect to peer `%s'\n",
1434 GNUNET_i2s (target)); 1433 GNUNET_i2s (target));
1435#endif 1434#endif
1436 if (0 == memcmp (target, &GST_my_identity, 1435 if (0 ==
1437 sizeof (struct GNUNET_PeerIdentity))) 1436 memcmp (target, &GST_my_identity, sizeof (struct GNUNET_PeerIdentity)))
1438 { 1437 {
1439 /* my own hello */ 1438 /* my own hello */
1440 return; 1439 return;
@@ -1443,9 +1442,9 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
1443 1442
1444 if (NULL != n) 1443 if (NULL != n)
1445 { 1444 {
1446 if ((is_connected(n)) || (is_connecting(n))) 1445 if ((is_connected (n)) || (is_connecting (n)))
1447 return; /* already connecting or connected */ 1446 return; /* already connecting or connected */
1448 if (is_disconnecting(n)) 1447 if (is_disconnecting (n))
1449 change_state (n, S_NOT_CONNECTED); 1448 change_state (n, S_NOT_CONNECTED);
1450 } 1449 }
1451 1450
@@ -1458,7 +1457,7 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
1458 GNUNET_i2s (&n->id)); 1457 GNUNET_i2s (&n->id));
1459#endif 1458#endif
1460 1459
1461 GNUNET_ATS_suggest_address (GST_ats, &n->id); 1460 GNUNET_ATS_suggest_address (GST_ats, &n->id);
1462} 1461}
1463 1462
1464/** 1463/**
@@ -1480,7 +1479,7 @@ GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target)
1480 1479
1481 n = lookup_neighbour (target); 1480 n = lookup_neighbour (target);
1482 1481
1483 if ((NULL == n) || (!is_connected(n))) 1482 if ((NULL == n) || (!is_connected (n)))
1484 return GNUNET_NO; /* not connected */ 1483 return GNUNET_NO; /* not connected */
1485 return GNUNET_YES; 1484 return GNUNET_YES;
1486} 1485}
@@ -1505,8 +1504,7 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
1505 } 1504 }
1506 1505
1507#if DEBUG_TRANSPORT 1506#if DEBUG_TRANSPORT
1508 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1507 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Session %X to peer `%s' ended \n",
1509 "Session %X to peer `%s' ended \n",
1510 session, GNUNET_i2s (peer)); 1508 session, GNUNET_i2s (peer));
1511#endif 1509#endif
1512 1510
@@ -1522,7 +1520,7 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
1522 n->addrlen = 0; 1520 n->addrlen = 0;
1523 1521
1524 /* not connected anymore anyway, shouldn't matter */ 1522 /* not connected anymore anyway, shouldn't matter */
1525 if ((!is_connected(n)) && (!is_connecting(n))) 1523 if ((!is_connected (n)) && (!is_connecting (n)))
1526 return; 1524 return;
1527 1525
1528 /* We are connected, so ask ATS to switch addresses */ 1526 /* We are connected, so ask ATS to switch addresses */
@@ -1532,8 +1530,10 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
1532 &neighbour_timeout_task, n); 1530 &neighbour_timeout_task, n);
1533 /* try QUICKLY to re-establish a connection, reduce timeout! */ 1531 /* try QUICKLY to re-establish a connection, reduce timeout! */
1534 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) 1532 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
1535 GNUNET_SCHEDULER_cancel(n->ats_suggest); 1533 GNUNET_SCHEDULER_cancel (n->ats_suggest);
1536 n->ats_suggest = GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, n); 1534 n->ats_suggest =
1535 GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel,
1536 n);
1537 GNUNET_ATS_suggest_address (GST_ats, peer); 1537 GNUNET_ATS_suggest_address (GST_ats, peer);
1538} 1538}
1539 1539
@@ -1563,7 +1563,7 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg,
1563 } 1563 }
1564 1564
1565 n = lookup_neighbour (target); 1565 n = lookup_neighbour (target);
1566 if ((n == NULL) || (!is_connected(n))) 1566 if ((n == NULL) || (!is_connected (n)))
1567 { 1567 {
1568 GNUNET_STATISTICS_update (GST_stats, 1568 GNUNET_STATISTICS_update (GST_stats,
1569 gettext_noop 1569 gettext_noop
@@ -1574,7 +1574,7 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg,
1574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1575 "Could not send message to peer `%s': unknown neighbour", 1575 "Could not send message to peer `%s': unknown neighbour",
1576 GNUNET_i2s (target)); 1576 GNUNET_i2s (target));
1577 else if (!is_connected(n)) 1577 else if (!is_connected (n))
1578 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1578 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1579 "Could not send message to peer `%s': not connected\n", 1579 "Could not send message to peer `%s': not connected\n",
1580 GNUNET_i2s (target)); 1580 GNUNET_i2s (target));
@@ -1584,16 +1584,16 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg,
1584 return; 1584 return;
1585 } 1585 }
1586 1586
1587 if ((n->session == NULL) && (n->addr == NULL) && (n->addrlen ==0)) 1587 if ((n->session == NULL) && (n->addr == NULL) && (n->addrlen == 0))
1588 { 1588 {
1589 GNUNET_STATISTICS_update (GST_stats, 1589 GNUNET_STATISTICS_update (GST_stats,
1590 gettext_noop 1590 gettext_noop
1591 ("# messages not sent (no such peer or not connected)"), 1591 ("# messages not sent (no such peer or not connected)"),
1592 1, GNUNET_NO); 1592 1, GNUNET_NO);
1593#if DEBUG_TRANSPORT 1593#if DEBUG_TRANSPORT
1594 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1594 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1595 "Could not send message to peer `%s': no address available\n", 1595 "Could not send message to peer `%s': no address available\n",
1596 GNUNET_i2s (target)); 1596 GNUNET_i2s (target));
1597#endif 1597#endif
1598 1598
1599 if (NULL != cont) 1599 if (NULL != cont)
@@ -1655,14 +1655,14 @@ GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity
1655 if (NULL == n) 1655 if (NULL == n)
1656 { 1656 {
1657 GNUNET_STATISTICS_update (GST_stats, 1657 GNUNET_STATISTICS_update (GST_stats,
1658 gettext_noop 1658 gettext_noop
1659 ("# messages discarded due to lack of neighbour record"), 1659 ("# messages discarded due to lack of neighbour record"),
1660 1, GNUNET_NO); 1660 1, GNUNET_NO);
1661 *do_forward = GNUNET_NO; 1661 *do_forward = GNUNET_NO;
1662 return GNUNET_TIME_UNIT_ZERO; 1662 return GNUNET_TIME_UNIT_ZERO;
1663 } 1663 }
1664 } 1664 }
1665 if (!is_connected(n)) 1665 if (!is_connected (n))
1666 { 1666 {
1667 *do_forward = GNUNET_SYSERR; 1667 *do_forward = GNUNET_SYSERR;
1668 return GNUNET_TIME_UNIT_ZERO; 1668 return GNUNET_TIME_UNIT_ZERO;
@@ -1784,10 +1784,10 @@ GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour,
1784 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s' due to `%s'\n", 1784 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s' due to `%s'\n",
1785 GNUNET_i2s (&n->id), "SET_QUOTA"); 1785 GNUNET_i2s (&n->id), "SET_QUOTA");
1786#endif 1786#endif
1787 if (is_connected(n)) 1787 if (is_connected (n))
1788 GNUNET_STATISTICS_update (GST_stats, 1788 GNUNET_STATISTICS_update (GST_stats,
1789 gettext_noop ("# disconnects due to quota of 0"), 1, 1789 gettext_noop ("# disconnects due to quota of 0"),
1790 GNUNET_NO); 1790 1, GNUNET_NO);
1791 disconnect_neighbour (n); 1791 disconnect_neighbour (n);
1792} 1792}
1793 1793
@@ -1823,7 +1823,7 @@ neighbours_iterate (void *cls, const GNUNET_HashCode * key, void *value)
1823 struct IteratorContext *ic = cls; 1823 struct IteratorContext *ic = cls;
1824 struct NeighbourMapEntry *n = value; 1824 struct NeighbourMapEntry *n = value;
1825 1825
1826 if (!is_connected(n)) 1826 if (!is_connected (n))
1827 return GNUNET_OK; 1827 return GNUNET_OK;
1828 1828
1829 ic->cb (ic->cb_cls, &n->id, NULL, 0, n->plugin_name, n->addr, n->addrlen); 1829 ic->cb (ic->cb_cls, &n->id, NULL, 0, n->plugin_name, n->addr, n->addrlen);
@@ -1872,13 +1872,13 @@ GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target)
1872 n = lookup_neighbour (target); 1872 n = lookup_neighbour (target);
1873 if (NULL == n) 1873 if (NULL == n)
1874 return; /* not active */ 1874 return; /* not active */
1875 if (is_connected(n)) 1875 if (is_connected (n))
1876 { 1876 {
1877 send_disconnect(&n->id, n->plugin_name, n->addr, n->addrlen, n->session); 1877 send_disconnect (&n->id, n->plugin_name, n->addr, n->addrlen, n->session);
1878 1878
1879 n = lookup_neighbour (target); 1879 n = lookup_neighbour (target);
1880 if (NULL == n) 1880 if (NULL == n)
1881 return; /* gone already */ 1881 return; /* gone already */
1882 } 1882 }
1883 disconnect_neighbour (n); 1883 disconnect_neighbour (n);
1884} 1884}
@@ -1887,13 +1887,15 @@ GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target)
1887/** 1887/**
1888 * We received a disconnect message from the given peer, 1888 * We received a disconnect message from the given peer,
1889 * validate and process. 1889 * validate and process.
1890 * 1890 *
1891 * @param peer sender of the message 1891 * @param peer sender of the message
1892 * @param msg the disconnect message 1892 * @param msg the disconnect message
1893 */ 1893 */
1894void 1894void
1895GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer, 1895GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity
1896 const struct GNUNET_MessageHeader *msg) 1896 *peer,
1897 const struct GNUNET_MessageHeader
1898 *msg)
1897{ 1899{
1898 struct NeighbourMapEntry *n; 1900 struct NeighbourMapEntry *n;
1899 const struct SessionDisconnectMessage *sdm; 1901 const struct SessionDisconnectMessage *sdm;
@@ -1901,18 +1903,20 @@ GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer
1901 1903
1902#if DEBUG_TRANSPORT 1904#if DEBUG_TRANSPORT
1903 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1905 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1904 "Received DISCONNECT message from peer `%s'\n", GNUNET_i2s (peer)); 1906 "Received DISCONNECT message from peer `%s'\n",
1907 GNUNET_i2s (peer));
1905#endif 1908#endif
1906 1909
1907 if (ntohs (msg->size) != sizeof (struct SessionDisconnectMessage)) 1910 if (ntohs (msg->size) != sizeof (struct SessionDisconnectMessage))
1908 { 1911 {
1909 // GNUNET_break_op (0); 1912 // GNUNET_break_op (0);
1910 GNUNET_STATISTICS_update (GST_stats, 1913 GNUNET_STATISTICS_update (GST_stats,
1911 gettext_noop ("# disconnect messages ignored (old format)"), 1, 1914 gettext_noop
1912 GNUNET_NO); 1915 ("# disconnect messages ignored (old format)"), 1,
1916 GNUNET_NO);
1913 return; 1917 return;
1914 } 1918 }
1915 sdm = (const struct SessionDisconnectMessage* ) msg; 1919 sdm = (const struct SessionDisconnectMessage *) msg;
1916 n = lookup_neighbour (peer); 1920 n = lookup_neighbour (peer);
1917 if (NULL == n) 1921 if (NULL == n)
1918 return; /* gone already */ 1922 return; /* gone already */
@@ -1920,21 +1924,20 @@ GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer
1920 n->connect_ts.abs_value) 1924 n->connect_ts.abs_value)
1921 { 1925 {
1922 GNUNET_STATISTICS_update (GST_stats, 1926 GNUNET_STATISTICS_update (GST_stats,
1923 gettext_noop ("# disconnect messages ignored (timestamp)"), 1, 1927 gettext_noop
1924 GNUNET_NO); 1928 ("# disconnect messages ignored (timestamp)"), 1,
1929 GNUNET_NO);
1925 return; 1930 return;
1926 } 1931 }
1927 GNUNET_CRYPTO_hash (&sdm->public_key, 1932 GNUNET_CRYPTO_hash (&sdm->public_key,
1928 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 1933 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1929 &hc); 1934 &hc);
1930 if (0 != memcmp (peer, 1935 if (0 != memcmp (peer, &hc, sizeof (struct GNUNET_PeerIdentity)))
1931 &hc,
1932 sizeof (struct GNUNET_PeerIdentity)))
1933 { 1936 {
1934 GNUNET_break_op (0); 1937 GNUNET_break_op (0);
1935 return; 1938 return;
1936 } 1939 }
1937 if (ntohl (sdm->purpose.size) != 1940 if (ntohl (sdm->purpose.size) !=
1938 sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + 1941 sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
1939 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + 1942 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
1940 sizeof (struct GNUNET_TIME_AbsoluteNBO)) 1943 sizeof (struct GNUNET_TIME_AbsoluteNBO))
@@ -1943,10 +1946,9 @@ GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer
1943 return; 1946 return;
1944 } 1947 }
1945 if (GNUNET_OK != 1948 if (GNUNET_OK !=
1946 GNUNET_CRYPTO_rsa_verify (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT, 1949 GNUNET_CRYPTO_rsa_verify
1947 &sdm->purpose, 1950 (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT, &sdm->purpose,
1948 &sdm->signature, 1951 &sdm->signature, &sdm->public_key))
1949 &sdm->public_key))
1950 { 1952 {
1951 GNUNET_break_op (0); 1953 GNUNET_break_op (0);
1952 return; 1954 return;
@@ -1970,12 +1972,13 @@ GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer
1970 */ 1972 */
1971void 1973void
1972GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message, 1974GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
1973 const struct GNUNET_PeerIdentity *peer, 1975 const struct GNUNET_PeerIdentity *peer,
1974 const char *plugin_name, 1976 const char *plugin_name,
1975 const char *sender_address, uint16_t sender_address_len, 1977 const char *sender_address,
1976 struct Session *session, 1978 uint16_t sender_address_len,
1977 const struct GNUNET_ATS_Information *ats, 1979 struct Session *session,
1978 uint32_t ats_count) 1980 const struct GNUNET_ATS_Information *ats,
1981 uint32_t ats_count)
1979{ 1982{
1980 const struct SessionConnectMessage *scm; 1983 const struct SessionConnectMessage *scm;
1981 struct QuotaSetMessage q_msg; 1984 struct QuotaSetMessage q_msg;
@@ -1987,7 +1990,8 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
1987 1990
1988#if DEBUG_TRANSPORT 1991#if DEBUG_TRANSPORT
1989 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1992 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1990 "Received CONNECT_ACK message from peer `%s'\n", GNUNET_i2s (peer)); 1993 "Received CONNECT_ACK message from peer `%s'\n",
1994 GNUNET_i2s (peer));
1991#endif 1995#endif
1992 1996
1993 if (ntohs (message->size) != sizeof (struct SessionConnectMessage)) 1997 if (ntohs (message->size) != sizeof (struct SessionConnectMessage))
@@ -2013,104 +2017,94 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2013 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 2017 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
2014 "transport-ats", 2018 "transport-ats",
2015 "Giving ATS session %p of plugin %s for peer %s\n", 2019 "Giving ATS session %p of plugin %s for peer %s\n",
2016 session, 2020 session, plugin_name, GNUNET_i2s (peer));
2017 plugin_name, 2021 GNUNET_ATS_address_update (GST_ats, peer, plugin_name, sender_address,
2018 GNUNET_i2s (peer)); 2022 sender_address_len, session, ats, ats_count);
2019 GNUNET_ATS_address_update (GST_ats, 2023
2020 peer, 2024 was_connected = is_connected (n);
2021 plugin_name, sender_address, sender_address_len, 2025 if (!is_connected (n))
2022 session, ats, ats_count);
2023
2024 was_connected = is_connected(n);
2025 if (!is_connected(n))
2026 change_state (n, S_CONNECTED); 2026 change_state (n, S_CONNECTED);
2027 2027
2028 GNUNET_ATS_address_in_use (GST_ats, 2028 GNUNET_ATS_address_in_use (GST_ats, peer, plugin_name, sender_address,
2029 peer, 2029 sender_address_len, session, GNUNET_YES);
2030 plugin_name,
2031 sender_address,
2032 sender_address_len,
2033 session,
2034 GNUNET_YES);
2035 2030
2036#if DEBUG_TRANSPORT 2031#if DEBUG_TRANSPORT
2037 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2032 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2038 "Setting inbound quota of %u for peer `%s' to \n", 2033 "Setting inbound quota of %u for peer `%s' to \n",
2039 ntohl (n->bandwidth_in.value__), GNUNET_i2s (&n->id)); 2034 ntohl (n->bandwidth_in.value__), GNUNET_i2s (&n->id));
2040#endif 2035#endif
2041 GST_neighbours_set_incoming_quota(&n->id, n->bandwidth_in); 2036 GST_neighbours_set_incoming_quota (&n->id, n->bandwidth_in);
2042 2037
2043 /* send ACK (ACK)*/ 2038 /* send ACK (ACK) */
2044 msg_len = sizeof (msg); 2039 msg_len = sizeof (msg);
2045 msg.size = htons (msg_len); 2040 msg.size = htons (msg_len);
2046 msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK); 2041 msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK);
2047 2042
2048 ret = send_with_plugin (&n->id, (const char *) &msg, msg_len, UINT32_MAX, 2043 ret =
2049 GNUNET_TIME_UNIT_FOREVER_REL, 2044 send_with_plugin (&n->id, (const char *) &msg, msg_len, UINT32_MAX,
2050 n->session, n->plugin_name, n->addr, n->addrlen, 2045 GNUNET_TIME_UNIT_FOREVER_REL, n->session,
2051 GNUNET_YES, NULL, NULL); 2046 n->plugin_name, n->addr, n->addrlen, GNUNET_YES, NULL,
2047 NULL);
2052 2048
2053 if (ret == GNUNET_SYSERR) 2049 if (ret == GNUNET_SYSERR)
2054 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2050 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2055 "Failed to send SESSION_ACK to `%4s' using plugin `%s' address '%s' session %X\n", 2051 "Failed to send SESSION_ACK to `%4s' using plugin `%s' address '%s' session %X\n",
2056 GNUNET_i2s (&n->id), n->plugin_name, 2052 GNUNET_i2s (&n->id), n->plugin_name,
2057 (n->addrlen == 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, 2053 (n->addrlen ==
2058 n->addr, 2054 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, n->addr,
2059 n->addrlen), 2055 n->addrlen), n->session);
2060 n->session);
2061 2056
2062 2057
2063 if (!was_connected) 2058 if (!was_connected)
2064 { 2059 {
2065 if (n->keepalive_task == GNUNET_SCHEDULER_NO_TASK) 2060 if (n->keepalive_task == GNUNET_SCHEDULER_NO_TASK)
2066 n->keepalive_task = GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY, 2061 n->keepalive_task =
2067 &neighbour_keepalive_task, 2062 GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY,
2068 n); 2063 &neighbour_keepalive_task, n);
2069 2064
2070 neighbours_connected++; 2065 neighbours_connected++;
2071 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1, 2066 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1,
2072 GNUNET_NO); 2067 GNUNET_NO);
2073#if DEBUG_TRANSPORT 2068#if DEBUG_TRANSPORT
2074 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2069 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2075 "Notify about connect of `%4s' using plugin `%s' address '%s' session %X LINE %u\n", 2070 "Notify about connect of `%4s' using plugin `%s' address '%s' session %X LINE %u\n",
2076 GNUNET_i2s (&n->id), n->plugin_name, 2071 GNUNET_i2s (&n->id), n->plugin_name,
2077 (n->addrlen == 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, 2072 (n->addrlen ==
2078 n->addr, 2073 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, n->addr,
2079 n->addrlen), 2074 n->addrlen), n->session,
2080 n->session, __LINE__); 2075 __LINE__);
2081#endif 2076#endif
2082 connect_notify_cb (callback_cls, &n->id, ats, ats_count); 2077 connect_notify_cb (callback_cls, &n->id, ats, ats_count);
2083 } 2078 }
2084 2079
2085#if DEBUG_TRANSPORT 2080#if DEBUG_TRANSPORT
2086 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2081 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2087 "Sending outbound quota of %u Bps for peer `%s' to all clients\n", 2082 "Sending outbound quota of %u Bps for peer `%s' to all clients\n",
2088 ntohl (n->bandwidth_out.value__), GNUNET_i2s (peer)); 2083 ntohl (n->bandwidth_out.value__), GNUNET_i2s (peer));
2089#endif 2084#endif
2090 q_msg.header.size = htons (sizeof (struct QuotaSetMessage)); 2085 q_msg.header.size = htons (sizeof (struct QuotaSetMessage));
2091 q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA); 2086 q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA);
2092 q_msg.quota = n->bandwidth_out; 2087 q_msg.quota = n->bandwidth_out;
2093 q_msg.peer = (*peer); 2088 q_msg.peer = (*peer);
2094 GST_clients_broadcast (&q_msg.header, GNUNET_NO); 2089 GST_clients_broadcast (&q_msg.header, GNUNET_NO);
2095 2090
2096} 2091}
2097 2092
2098void 2093void
2099GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message, 2094GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message,
2100 const struct GNUNET_PeerIdentity *peer, 2095 const struct GNUNET_PeerIdentity *peer,
2101 const char *plugin_name, 2096 const char *plugin_name, const char *sender_address,
2102 const char *sender_address, uint16_t sender_address_len, 2097 uint16_t sender_address_len, struct Session *session,
2103 struct Session *session, 2098 const struct GNUNET_ATS_Information *ats,
2104 const struct GNUNET_ATS_Information *ats, 2099 uint32_t ats_count)
2105 uint32_t ats_count)
2106{ 2100{
2107 struct NeighbourMapEntry *n; 2101 struct NeighbourMapEntry *n;
2108 struct QuotaSetMessage q_msg; 2102 struct QuotaSetMessage q_msg;
2109 int was_connected; 2103 int was_connected;
2110 2104
2111#if DEBUG_TRANSPORT 2105#if DEBUG_TRANSPORT
2112 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2106 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ACK message from peer `%s'\n",
2113 "Received ACK message from peer `%s'\n", GNUNET_i2s (peer)); 2107 GNUNET_i2s (peer));
2114#endif 2108#endif
2115 2109
2116 if (ntohs (message->size) != sizeof (struct GNUNET_MessageHeader)) 2110 if (ntohs (message->size) != sizeof (struct GNUNET_MessageHeader))
@@ -2122,60 +2116,52 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message,
2122 n = lookup_neighbour (peer); 2116 n = lookup_neighbour (peer);
2123 if (NULL == n) 2117 if (NULL == n)
2124 { 2118 {
2125 send_disconnect(peer, plugin_name, sender_address, sender_address_len, session); 2119 send_disconnect (peer, plugin_name, sender_address, sender_address_len,
2120 session);
2126 GNUNET_break (0); 2121 GNUNET_break (0);
2127 return; 2122 return;
2128 } 2123 }
2129 2124
2130 if (is_connected(n)) 2125 if (is_connected (n))
2131 return; 2126 return;
2132 2127
2133 if (NULL != session) 2128 if (NULL != session)
2134 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 2129 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
2135 "transport-ats", 2130 "transport-ats",
2136 "Giving ATS session %p of plugin %s for peer %s\n", 2131 "Giving ATS session %p of plugin %s for peer %s\n",
2137 session, 2132 session, plugin_name, GNUNET_i2s (peer));
2138 plugin_name, 2133 GNUNET_ATS_address_update (GST_ats, peer, plugin_name, sender_address,
2139 GNUNET_i2s (peer)); 2134 sender_address_len, session, ats, ats_count);
2140 GNUNET_ATS_address_update (GST_ats, 2135
2141 peer, 2136 was_connected = is_connected (n);
2142 plugin_name, sender_address, sender_address_len,
2143 session, ats, ats_count);
2144
2145 was_connected = is_connected(n);
2146 change_state (n, S_CONNECTED); 2137 change_state (n, S_CONNECTED);
2147 2138
2148 GNUNET_ATS_address_in_use (GST_ats, 2139 GNUNET_ATS_address_in_use (GST_ats, peer, plugin_name, sender_address,
2149 peer, 2140 sender_address_len, session, GNUNET_YES);
2150 plugin_name,
2151 sender_address,
2152 sender_address_len,
2153 session,
2154 GNUNET_YES);
2155 2141
2156 GST_neighbours_set_incoming_quota(&n->id, n->bandwidth_in); 2142 GST_neighbours_set_incoming_quota (&n->id, n->bandwidth_in);
2157 2143
2158 if (n->keepalive_task == GNUNET_SCHEDULER_NO_TASK) 2144 if (n->keepalive_task == GNUNET_SCHEDULER_NO_TASK)
2159 n->keepalive_task = GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY, 2145 n->keepalive_task =
2160 &neighbour_keepalive_task, 2146 GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY,
2161 n); 2147 &neighbour_keepalive_task, n);
2162 2148
2163 if (!was_connected) 2149 if (!was_connected)
2164 { 2150 {
2165 neighbours_connected++; 2151 neighbours_connected++;
2166 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1, 2152 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1,
2167 GNUNET_NO); 2153 GNUNET_NO);
2168 2154
2169#if DEBUG_TRANSPORT 2155#if DEBUG_TRANSPORT
2170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2171 "Notify about connect of `%4s' using plugin `%s' address '%s' session %X LINE %u\n", 2157 "Notify about connect of `%4s' using plugin `%s' address '%s' session %X LINE %u\n",
2172 GNUNET_i2s (&n->id), n->plugin_name, 2158 GNUNET_i2s (&n->id), n->plugin_name,
2173 (n->addrlen == 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, 2159 (n->addrlen ==
2174 n->addr, 2160 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, n->addr,
2175 n->addrlen), 2161 n->addrlen), n->session,
2176 n->session, __LINE__); 2162 __LINE__);
2177#endif 2163#endif
2178 connect_notify_cb (callback_cls, &n->id, ats, ats_count); 2164 connect_notify_cb (callback_cls, &n->id, ats, ats_count);
2179 } 2165 }
2180#if DEBUG_TRANSPORT 2166#if DEBUG_TRANSPORT
2181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2167 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -2209,15 +2195,17 @@ struct BlackListCheckContext
2209 2195
2210static void 2196static void
2211handle_connect_blacklist_cont (void *cls, 2197handle_connect_blacklist_cont (void *cls,
2212 const struct GNUNET_PeerIdentity 2198 const struct GNUNET_PeerIdentity *peer,
2213 * peer, int result) 2199 int result)
2214{ 2200{
2215 struct NeighbourMapEntry *n; 2201 struct NeighbourMapEntry *n;
2216 struct BlackListCheckContext * bcc = cls; 2202 struct BlackListCheckContext *bcc = cls;
2217 2203
2218#if DEBUG_TRANSPORT 2204#if DEBUG_TRANSPORT
2219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2205 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2220 "Blacklist check due to CONNECT message: `%s'\n", GNUNET_i2s (peer), (result == GNUNET_OK) ? "ALLOWED" : "FORBIDDEN"); 2206 "Blacklist check due to CONNECT message: `%s'\n",
2207 GNUNET_i2s (peer),
2208 (result == GNUNET_OK) ? "ALLOWED" : "FORBIDDEN");
2221#endif 2209#endif
2222 2210
2223 /* not allowed */ 2211 /* not allowed */
@@ -2237,13 +2225,12 @@ handle_connect_blacklist_cont (void *cls,
2237 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 2225 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
2238 "transport-ats", 2226 "transport-ats",
2239 "Giving ATS session %p of plugin %s address `%s' for peer %s\n", 2227 "Giving ATS session %p of plugin %s address `%s' for peer %s\n",
2240 bcc->session, 2228 bcc->session, bcc->plugin_name,
2241 bcc->plugin_name, 2229 GST_plugins_a2s (bcc->plugin_name, bcc->sender_address,
2242 GST_plugins_a2s (bcc->plugin_name, bcc->sender_address, bcc->sender_address_len), 2230 bcc->sender_address_len),
2243 GNUNET_i2s (peer)); 2231 GNUNET_i2s (peer));
2244 GNUNET_ATS_address_update (GST_ats, 2232 GNUNET_ATS_address_update (GST_ats, peer, bcc->plugin_name,
2245 peer, 2233 bcc->sender_address, bcc->sender_address_len,
2246 bcc->plugin_name, bcc->sender_address, bcc->sender_address_len,
2247 bcc->session, bcc->ats, bcc->ats_count); 2234 bcc->session, bcc->ats, bcc->ats_count);
2248 n->connect_ts = bcc->ts; 2235 n->connect_ts = bcc->ts;
2249 } 2236 }
@@ -2251,13 +2238,15 @@ handle_connect_blacklist_cont (void *cls,
2251 GNUNET_free (bcc); 2238 GNUNET_free (bcc);
2252 2239
2253 if (n->state != S_CONNECT_RECV) 2240 if (n->state != S_CONNECT_RECV)
2254 change_state (n, S_CONNECT_RECV); 2241 change_state (n, S_CONNECT_RECV);
2255 2242
2256 /* Ask ATS for an address to connect via that address */ 2243 /* Ask ATS for an address to connect via that address */
2257 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) 2244 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
2258 GNUNET_SCHEDULER_cancel(n->ats_suggest); 2245 GNUNET_SCHEDULER_cancel (n->ats_suggest);
2259 n->ats_suggest = GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, n); 2246 n->ats_suggest =
2260 GNUNET_ATS_suggest_address(GST_ats, peer); 2247 GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel,
2248 n);
2249 GNUNET_ATS_suggest_address (GST_ats, peer);
2261} 2250}
2262 2251
2263/** 2252/**
@@ -2276,20 +2265,21 @@ handle_connect_blacklist_cont (void *cls,
2276 */ 2265 */
2277void 2266void
2278GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message, 2267GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
2279 const struct GNUNET_PeerIdentity *peer, 2268 const struct GNUNET_PeerIdentity *peer,
2280 const char *plugin_name, 2269 const char *plugin_name,
2281 const char *sender_address, uint16_t sender_address_len, 2270 const char *sender_address,
2282 struct Session *session, 2271 uint16_t sender_address_len,
2283 const struct GNUNET_ATS_Information *ats, 2272 struct Session *session,
2284 uint32_t ats_count) 2273 const struct GNUNET_ATS_Information *ats,
2274 uint32_t ats_count)
2285{ 2275{
2286 const struct SessionConnectMessage *scm; 2276 const struct SessionConnectMessage *scm;
2287 struct NeighbourMapEntry * n; 2277 struct NeighbourMapEntry *n;
2288 struct BlackListCheckContext * bcc = NULL; 2278 struct BlackListCheckContext *bcc = NULL;
2289 2279
2290#if DEBUG_TRANSPORT 2280#if DEBUG_TRANSPORT
2291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2281 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2292 "Received CONNECT message from peer `%s'\n", GNUNET_i2s (peer)); 2282 "Received CONNECT message from peer `%s'\n", GNUNET_i2s (peer));
2293#endif 2283#endif
2294 2284
2295 if (ntohs (message->size) != sizeof (struct SessionConnectMessage)) 2285 if (ntohs (message->size) != sizeof (struct SessionConnectMessage))
@@ -2301,23 +2291,24 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
2301 scm = (const struct SessionConnectMessage *) message; 2291 scm = (const struct SessionConnectMessage *) message;
2302 GNUNET_break_op (ntohl (scm->reserved) == 0); 2292 GNUNET_break_op (ntohl (scm->reserved) == 0);
2303 2293
2304 n = lookup_neighbour(peer); 2294 n = lookup_neighbour (peer);
2305 if (n != NULL) 2295 if (n != NULL)
2306 { 2296 {
2307 /* connected peer switches addresses */ 2297 /* connected peer switches addresses */
2308 if (is_connected(n)) 2298 if (is_connected (n))
2309 { 2299 {
2310 GNUNET_ATS_address_update(GST_ats, peer, plugin_name, sender_address, sender_address_len, session, ats, ats_count); 2300 GNUNET_ATS_address_update (GST_ats, peer, plugin_name, sender_address,
2301 sender_address_len, session, ats, ats_count);
2311 return; 2302 return;
2312 } 2303 }
2313 } 2304 }
2314 2305
2315 /* we are not connected to this peer */ 2306 /* we are not connected to this peer */
2316 /* do blacklist check*/ 2307 /* do blacklist check */
2317 bcc = GNUNET_malloc (sizeof (struct BlackListCheckContext) + 2308 bcc =
2318 sizeof (struct GNUNET_ATS_Information) * ats_count + 2309 GNUNET_malloc (sizeof (struct BlackListCheckContext) +
2319 sender_address_len + 2310 sizeof (struct GNUNET_ATS_Information) * ats_count +
2320 strlen (plugin_name)+1); 2311 sender_address_len + strlen (plugin_name) + 1);
2321 2312
2322 bcc->ts = GNUNET_TIME_absolute_ntoh (scm->timestamp); 2313 bcc->ts = GNUNET_TIME_absolute_ntoh (scm->timestamp);
2323 2314
@@ -2326,15 +2317,16 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
2326 bcc->session = session; 2317 bcc->session = session;
2327 2318
2328 bcc->ats = (struct GNUNET_ATS_Information *) &bcc[1]; 2319 bcc->ats = (struct GNUNET_ATS_Information *) &bcc[1];
2329 memcpy (bcc->ats, ats,sizeof (struct GNUNET_ATS_Information) * ats_count ); 2320 memcpy (bcc->ats, ats, sizeof (struct GNUNET_ATS_Information) * ats_count);
2330 2321
2331 bcc->sender_address = (char *) &bcc->ats[ats_count]; 2322 bcc->sender_address = (char *) &bcc->ats[ats_count];
2332 memcpy (bcc->sender_address, sender_address , sender_address_len); 2323 memcpy (bcc->sender_address, sender_address, sender_address_len);
2333 2324
2334 bcc->plugin_name = &bcc->sender_address[sender_address_len]; 2325 bcc->plugin_name = &bcc->sender_address[sender_address_len];
2335 strcpy (bcc->plugin_name, plugin_name); 2326 strcpy (bcc->plugin_name, plugin_name);
2336 2327
2337 GST_blacklist_test_allowed (peer, plugin_name, handle_connect_blacklist_cont, bcc); 2328 GST_blacklist_test_allowed (peer, plugin_name, handle_connect_blacklist_cont,
2329 bcc);
2338} 2330}
2339 2331
2340 2332
diff --git a/src/transport/gnunet-service-transport_neighbours.h b/src/transport/gnunet-service-transport_neighbours.h
index 3868ef2cf..3aafc3d55 100644
--- a/src/transport/gnunet-service-transport_neighbours.h
+++ b/src/transport/gnunet-service-transport_neighbours.h
@@ -159,11 +159,9 @@ GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target);
159typedef void (*GST_NeighbourIterator) (void *cls, 159typedef void (*GST_NeighbourIterator) (void *cls,
160 const struct GNUNET_PeerIdentity * 160 const struct GNUNET_PeerIdentity *
161 neighbour, 161 neighbour,
162 const struct 162 const struct GNUNET_ATS_Information *
163 GNUNET_ATS_Information * ats, 163 ats, uint32_t ats_count,
164 uint32_t ats_count, 164 const char *transport, const void *addr,
165 const char * transport,
166 const void * addr,
167 size_t addrlen); 165 size_t addrlen);
168 166
169 167
@@ -209,17 +207,20 @@ int
209GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, 207GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
210 const char *plugin_name, const void *address, 208 const char *plugin_name, const void *address,
211 size_t address_len, struct Session *session, 209 size_t address_len, struct Session *session,
212 const struct GNUNET_ATS_Information 210 const struct GNUNET_ATS_Information *ats,
213 *ats, uint32_t ats_count); 211 uint32_t ats_count);
214 212
215int 213int
216GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, 214GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
217 const char *plugin_name, const void *address, 215 const char *plugin_name,
218 size_t address_len, struct Session *session, 216 const void *address, size_t address_len,
219 const struct GNUNET_ATS_Information 217 struct Session *session,
220 *ats, uint32_t ats_count, 218 const struct GNUNET_ATS_Information *ats,
221 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 219 uint32_t ats_count,
222 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out); 220 struct GNUNET_BANDWIDTH_Value32NBO
221 bandwidth_in,
222 struct GNUNET_BANDWIDTH_Value32NBO
223 bandwidth_out);
223 224
224 225
225/** 226/**
@@ -238,41 +239,44 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
238 */ 239 */
239void 240void
240GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message, 241GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
241 const struct GNUNET_PeerIdentity *peer,
242 const char *plugin_name,
243 const char *sender_address, uint16_t sender_address_len,
244 struct Session *session,
245 const struct GNUNET_ATS_Information *ats,
246 uint32_t ats_count);
247
248void
249GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
250 const struct GNUNET_PeerIdentity *peer, 242 const struct GNUNET_PeerIdentity *peer,
251 const char *plugin_name, 243 const char *plugin_name,
252 const char *sender_address, uint16_t sender_address_len, 244 const char *sender_address,
245 uint16_t sender_address_len,
253 struct Session *session, 246 struct Session *session,
254 const struct GNUNET_ATS_Information *ats, 247 const struct GNUNET_ATS_Information *ats,
255 uint32_t ats_count); 248 uint32_t ats_count);
256 249
257void 250void
251GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
252 const struct GNUNET_PeerIdentity *peer,
253 const char *plugin_name,
254 const char *sender_address,
255 uint16_t sender_address_len,
256 struct Session *session,
257 const struct GNUNET_ATS_Information *ats,
258 uint32_t ats_count);
259
260void
258GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message, 261GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message,
259 const struct GNUNET_PeerIdentity *peer, 262 const struct GNUNET_PeerIdentity *peer,
260 const char *plugin_name, 263 const char *plugin_name, const char *sender_address,
261 const char *sender_address, uint16_t sender_address_len, 264 uint16_t sender_address_len, struct Session *session,
262 struct Session *session, 265 const struct GNUNET_ATS_Information *ats,
263 const struct GNUNET_ATS_Information *ats, 266 uint32_t ats_count);
264 uint32_t ats_count);
265 267
266/** 268/**
267 * We received a disconnect message from the given peer, 269 * We received a disconnect message from the given peer,
268 * validate and process. 270 * validate and process.
269 * 271 *
270 * @param peer sender of the message 272 * @param peer sender of the message
271 * @param msg the disconnect message 273 * @param msg the disconnect message
272 */ 274 */
273void 275void
274GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer, 276GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity
275 const struct GNUNET_MessageHeader *msg); 277 *peer,
278 const struct GNUNET_MessageHeader
279 *msg);
276 280
277 281
278#endif 282#endif
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c
index 5758ebfbb..d7b4929b2 100644
--- a/src/transport/gnunet-service-transport_validation.c
+++ b/src/transport/gnunet-service-transport_validation.c
@@ -405,8 +405,8 @@ add_valid_address (void *cls, const char *tname,
405 } 405 }
406 ve = find_validation_entry (&public_key, &pid, tname, addr, addrlen); 406 ve = find_validation_entry (&public_key, &pid, tname, addr, addrlen);
407 ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, expiration); 407 ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, expiration);
408 GNUNET_ATS_address_update (GST_ats, &pid, tname, addr, 408 GNUNET_ATS_address_update (GST_ats, &pid, tname, addr, addrlen, NULL, NULL,
409 addrlen, NULL, NULL, 0); 409 0);
410 return GNUNET_OK; 410 return GNUNET_OK;
411} 411}
412 412
@@ -595,7 +595,8 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
595 sizeof (struct GNUNET_PeerIdentity))) 595 sizeof (struct GNUNET_PeerIdentity)))
596 { 596 {
597 GNUNET_STATISTICS_update (GST_stats, 597 GNUNET_STATISTICS_update (GST_stats,
598 gettext_noop ("# PING message for different peer received"), 1, 598 gettext_noop
599 ("# PING message for different peer received"), 1,
599 GNUNET_NO); 600 GNUNET_NO);
600 return; 601 return;
601 } 602 }
@@ -614,27 +615,28 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
614 { 615 {
615 addrend = memchr (addr, '\0', alen); 616 addrend = memchr (addr, '\0', alen);
616 if (NULL == addrend) 617 if (NULL == addrend)
617 { 618 {
618 GNUNET_break_op (0); 619 GNUNET_break_op (0);
619 return; 620 return;
620 } 621 }
621 addrend++; 622 addrend++;
622 slen = strlen (addr) + 1; 623 slen = strlen (addr) + 1;
623 alen -= slen; 624 alen -= slen;
624 625
625 if (GNUNET_YES != 626 if (GNUNET_YES !=
626 GST_hello_test_address (addr, addrend, alen, &sig_cache, &sig_cache_exp)) 627 GST_hello_test_address (addr, addrend, alen, &sig_cache,
628 &sig_cache_exp))
627 { 629 {
628 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 630 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
629 _ 631 _
630 ("Not confirming PING with address `%s' since I cannot confirm having this address.\n"), 632 ("Not confirming PING with address `%s' since I cannot confirm having this address.\n"),
631 GST_plugins_a2s (addr, addrend, alen)); 633 GST_plugins_a2s (addr, addrend, alen));
632 return; 634 return;
633 } 635 }
634 } 636 }
635 else 637 else
636 { 638 {
637 addrend = NULL; /* make gcc happy */ 639 addrend = NULL; /* make gcc happy */
638 slen = 0; 640 slen = 0;
639 static struct GNUNET_CRYPTO_RsaSignature no_address_signature; 641 static struct GNUNET_CRYPTO_RsaSignature no_address_signature;
640 static struct GNUNET_TIME_Absolute no_address_signature_expiration; 642 static struct GNUNET_TIME_Absolute no_address_signature_expiration;
@@ -751,7 +753,8 @@ transmit_ping_if_allowed (void *cls, const struct GNUNET_PeerIdentity *pid,
751 753
752 ve->bc = NULL; 754 ve->bc = NULL;
753 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting plain PING to `%s' %s\n", 755 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting plain PING to `%s' %s\n",
754 GNUNET_i2s (pid), GST_plugins_a2s (ve->transport_name, ve->addr, ve->addrlen)); 756 GNUNET_i2s (pid), GST_plugins_a2s (ve->transport_name, ve->addr,
757 ve->addrlen));
755 758
756 slen = strlen (ve->transport_name) + 1; 759 slen = strlen (ve->transport_name) + 1;
757 hello = GST_hello_get (); 760 hello = GST_hello_get ();
@@ -996,12 +999,13 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
996 struct GNUNET_ATS_Information ats; 999 struct GNUNET_ATS_Information ats;
997 1000
998 ats.type = htonl (GNUNET_ATS_QUALITY_NET_DELAY); 1001 ats.type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
999 ats.value = htonl ((uint32_t) GNUNET_TIME_absolute_get_duration (ve->send_time).rel_value); 1002 ats.value =
1000 GNUNET_ATS_address_update (GST_ats, &ve->pid, 1003 htonl ((uint32_t)
1001 ve->transport_name,ve->addr, ve->addrlen, NULL, 1004 GNUNET_TIME_absolute_get_duration (ve->send_time).rel_value);
1002 &ats, 1); 1005 GNUNET_ATS_address_update (GST_ats, &ve->pid, ve->transport_name, ve->addr,
1006 ve->addrlen, NULL, &ats, 1);
1003 } 1007 }
1004 1008
1005 /* build HELLO to store in PEERINFO */ 1009 /* build HELLO to store in PEERINFO */
1006 ve->copied = GNUNET_NO; 1010 ve->copied = GNUNET_NO;
1007 hello = GNUNET_HELLO_create (&ve->public_key, &add_valid_peer_address, ve); 1011 hello = GNUNET_HELLO_create (&ve->public_key, &add_valid_peer_address, ve);
@@ -1043,17 +1047,16 @@ GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello)
1043 GNUNET_break (0); 1047 GNUNET_break (0);
1044 return; 1048 return;
1045 } 1049 }
1046 if (0 == memcmp (&GST_my_identity, &vac.pid, sizeof (struct GNUNET_PeerIdentity))) 1050 if (0 ==
1051 memcmp (&GST_my_identity, &vac.pid, sizeof (struct GNUNET_PeerIdentity)))
1047 return; 1052 return;
1048 /* Add peer identity without addresses to peerinfo service */ 1053 /* Add peer identity without addresses to peerinfo service */
1049 h = GNUNET_HELLO_create (&vac.public_key, NULL, NULL); 1054 h = GNUNET_HELLO_create (&vac.public_key, NULL, NULL);
1050 GNUNET_PEERINFO_add_peer (GST_peerinfo, h); 1055 GNUNET_PEERINFO_add_peer (GST_peerinfo, h);
1051#if VERBOSE_VALIDATION 1056#if VERBOSE_VALIDATION
1052 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1057 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1053 _ 1058 _("Adding `%s' without addresses for peer `%s'\n"), "HELLO",
1054 ("Adding `%s' without addresses for peer `%s'\n"), 1059 GNUNET_i2s (&vac.pid));
1055 "HELLO",
1056 GNUNET_i2s(&vac.pid));
1057#endif 1060#endif
1058 GNUNET_free (h); 1061 GNUNET_free (h);
1059 1062
diff --git a/src/transport/gnunet-transport-connect-running-peers.c b/src/transport/gnunet-transport-connect-running-peers.c
index a0e3b93a2..172f34b27 100644
--- a/src/transport/gnunet-transport-connect-running-peers.c
+++ b/src/transport/gnunet-transport-connect-running-peers.c
@@ -174,24 +174,23 @@ sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
174 "Press <q> to quit or <1> to send from p1 to p2, <2> to send from p2 to p1, <enter> repeat\n"); 174 "Press <q> to quit or <1> to send from p1 to p2, <2> to send from p2 to p1, <enter> repeat\n");
175 175
176read: 176read:
177 t = getchar(); 177 t = getchar ();
178 if (t == '1') 178 if (t == '1')
179 { 179 {
180 th = GNUNET_TRANSPORT_notify_transmit_ready (p1->th, &p2->id, 256, 0, TIMEOUT, 180 th = GNUNET_TRANSPORT_notify_transmit_ready (p1->th, &p2->id, 256, 0,
181 &notify_ready, p1); 181 TIMEOUT, &notify_ready, p1);
182 return; 182 return;
183 } 183 }
184 if (t == '2') 184 if (t == '2')
185 { 185 {
186 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, 256, 0, TIMEOUT, 186 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, 256, 0,
187 &notify_ready, p2); 187 TIMEOUT, &notify_ready, p2);
188 return; 188 return;
189 } 189 }
190 if (t == 'q') 190 if (t == 'q')
191 { 191 {
192 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 192 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Exiting %c!\n", t);
193 "Exiting %c!\n", t); 193 GNUNET_SCHEDULER_add_now (&end, NULL);
194 GNUNET_SCHEDULER_add_now(&end, NULL);
195 return; 194 return;
196 } 195 }
197 goto read; 196 goto read;
@@ -200,8 +199,7 @@ read:
200static void 199static void
201notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 200notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
202 const struct GNUNET_MessageHeader *message, 201 const struct GNUNET_MessageHeader *message,
203 const struct GNUNET_ATS_Information *ats, 202 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
204 uint32_t ats_count)
205{ 203{
206 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
207 "Received message of type %d from peer %s!\n", 205 "Received message of type %d from peer %s!\n",
@@ -210,8 +208,7 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
210 if ((MTYPE == ntohs (message->type)) && 208 if ((MTYPE == ntohs (message->type)) &&
211 (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) 209 (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)))
212 { 210 {
213 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 211 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Successfully received message\n");
214 "Successfully received message\n");
215 212
216 send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); 213 send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL);
217 } 214 }
@@ -219,8 +216,7 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
219 216
220static void 217static void
221notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, 218notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
222 const struct GNUNET_ATS_Information *ats, 219 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
223 uint32_t ats_count)
224{ 220{
225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n", 221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n",
226 GNUNET_i2s (peer), cls); 222 GNUNET_i2s (peer), cls);
diff --git a/src/transport/gnunet-transport-wlan-helper.c b/src/transport/gnunet-transport-wlan-helper.c
index 016aa29dd..25e55e510 100644
--- a/src/transport/gnunet-transport-wlan-helper.c
+++ b/src/transport/gnunet-transport-wlan-helper.c
@@ -1016,7 +1016,9 @@ getFrequencyFromChannel (int channel)
1016 6050, 6055, 6060, 6065, 6070, 6075, 6080, 6085, 6090, 6095, 6100 1016 6050, 6055, 6060, 6065, 6070, 6075, 6080, 6085, 6090, 6095, 6100
1017 }; 1017 };
1018 1018
1019 return ( (channel > 0) && (channel < sizeof(frequencies) / sizeof(int)) ) ? frequencies[channel] : -1; 1019 return ((channel > 0) &&
1020 (channel <
1021 sizeof (frequencies) / sizeof (int))) ? frequencies[channel] : -1;
1020} 1022}
1021 1023
1022/** 1024/**
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c
index 686423a3d..4d2912c34 100644
--- a/src/transport/gnunet-transport.c
+++ b/src/transport/gnunet-transport.c
@@ -162,15 +162,11 @@ display_test_result (struct TestContext *tc, int result)
162{ 162{
163 if (GNUNET_YES != result) 163 if (GNUNET_YES != result)
164 { 164 {
165 fprintf (stderr, 165 fprintf (stderr, "Configuration for plugin `%s' did not work!\n", tc->name);
166 "Configuration for plugin `%s' did not work!\n",
167 tc->name);
168 } 166 }
169 else 167 else
170 { 168 {
171 fprintf (stderr, 169 fprintf (stderr, "Configuration for plugin `%s' is working!\n", tc->name);
172 "Configuration for plugin `%s' is working!\n",
173 tc->name);
174 } 170 }
175 if (GNUNET_SCHEDULER_NO_TASK != tc->tsk) 171 if (GNUNET_SCHEDULER_NO_TASK != tc->tsk)
176 { 172 {
@@ -184,8 +180,7 @@ display_test_result (struct TestContext *tc, int result)
184 } 180 }
185 GNUNET_free (tc); 181 GNUNET_free (tc);
186 resolver_users--; 182 resolver_users--;
187 if ( (0 == resolver_users) && 183 if ((0 == resolver_users) && (NULL != resolver))
188 (NULL != resolver) )
189 { 184 {
190 GNUNET_break (0 == GNUNET_OS_process_kill (resolver, SIGTERM)); 185 GNUNET_break (0 == GNUNET_OS_process_kill (resolver, SIGTERM));
191 GNUNET_OS_process_close (resolver); 186 GNUNET_OS_process_close (resolver);
@@ -242,52 +237,46 @@ do_test_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg)
242 struct TestContext *tc; 237 struct TestContext *tc;
243 238
244 if (GNUNET_OK != 239 if (GNUNET_OK !=
245 GNUNET_CONFIGURATION_get_value_string (cfg, 240 GNUNET_CONFIGURATION_get_value_string (cfg, "transport", "plugins",
246 "transport", 241 &plugins))
247 "plugins",
248 &plugins))
249 { 242 {
250 fprintf (stderr, 243 fprintf (stderr,
251 _("No transport plugins configured, peer will never communicate\n")); 244 _
245 ("No transport plugins configured, peer will never communicate\n"));
252 ret = 4; 246 ret = 4;
253 return; 247 return;
254 } 248 }
255 for (tok = strtok (plugins, " "); tok != NULL; tok = strtok (NULL, " ")) 249 for (tok = strtok (plugins, " "); tok != NULL; tok = strtok (NULL, " "))
256 { 250 {
257 char section[12+strlen(tok)]; 251 char section[12 + strlen (tok)];
258 252
259 GNUNET_snprintf (section, 253 GNUNET_snprintf (section, sizeof (section), "transport-%s", tok);
260 sizeof (section),
261 "transport-%s",
262 tok);
263 if (GNUNET_OK != 254 if (GNUNET_OK !=
264 GNUNET_CONFIGURATION_get_value_number (cfg, section, "PORT", 255 GNUNET_CONFIGURATION_get_value_number (cfg, section, "PORT", &bnd_port))
265 &bnd_port)) 256 {
266 { 257 fprintf (stderr,
267 fprintf (stderr, 258 _("No port configured for plugin `%s', cannot test it\n"), tok);
268 _("No port configured for plugin `%s', cannot test it\n"), 259 continue;
269 tok); 260 }
270 continue;
271 }
272 if (GNUNET_OK != 261 if (GNUNET_OK !=
273 GNUNET_CONFIGURATION_get_value_number (cfg, section, 262 GNUNET_CONFIGURATION_get_value_number (cfg, section, "ADVERTISED_PORT",
274 "ADVERTISED_PORT", &adv_port)) 263 &adv_port))
275 adv_port = bnd_port; 264 adv_port = bnd_port;
276 if (NULL == resolver) 265 if (NULL == resolver)
277 resolver = 266 resolver =
278 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-resolver", 267 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-resolver",
279 "gnunet-service-resolver", NULL); 268 "gnunet-service-resolver", NULL);
280 resolver_users++; 269 resolver_users++;
281 GNUNET_RESOLVER_connect (cfg); 270 GNUNET_RESOLVER_connect (cfg);
282 tc = GNUNET_malloc (sizeof (struct TestContext)); 271 tc = GNUNET_malloc (sizeof (struct TestContext));
283 tc->name = GNUNET_strdup (tok); 272 tc->name = GNUNET_strdup (tok);
284 tc->tst = 273 tc->tst =
285 GNUNET_NAT_test_start (cfg, 274 GNUNET_NAT_test_start (cfg,
286 (0 == strcasecmp (tok, "udp")) 275 (0 ==
287 ? GNUNET_NO 276 strcasecmp (tok,
288 : GNUNET_YES, 277 "udp")) ? GNUNET_NO : GNUNET_YES,
289 (uint16_t) bnd_port, 278 (uint16_t) bnd_port, (uint16_t) adv_port,
290 (uint16_t) adv_port, &result_callback, tc); 279 &result_callback, tc);
291 if (NULL == tc->tst) 280 if (NULL == tc->tst)
292 { 281 {
293 display_test_result (tc, GNUNET_SYSERR); 282 display_test_result (tc, GNUNET_SYSERR);
@@ -303,8 +292,7 @@ do_test_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg)
303 * Shutdown, print statistics. 292 * Shutdown, print statistics.
304 */ 293 */
305static void 294static void
306do_disconnect (void *cls, 295do_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
307 const struct GNUNET_SCHEDULER_TaskContext *tc)
308{ 296{
309 struct GNUNET_TIME_Relative duration; 297 struct GNUNET_TIME_Relative duration;
310 298
@@ -317,20 +305,16 @@ do_disconnect (void *cls,
317 if (benchmark_receive) 305 if (benchmark_receive)
318 { 306 {
319 duration = GNUNET_TIME_absolute_get_duration (start_time); 307 duration = GNUNET_TIME_absolute_get_duration (start_time);
320 fprintf (stdout, 308 fprintf (stdout, _("Received %llu bytes/s (%llu bytes in %llu ms)\n"),
321 _("Received %llu bytes/s (%llu bytes in %llu ms)\n"), 309 1000 * traffic_received / (1 + duration.rel_value),
322 1000 * traffic_received / (1+duration.rel_value), 310 traffic_received, (unsigned long long) duration.rel_value);
323 traffic_received,
324 (unsigned long long) duration.rel_value);
325 } 311 }
326 if (benchmark_send) 312 if (benchmark_send)
327 { 313 {
328 duration = GNUNET_TIME_absolute_get_duration (start_time); 314 duration = GNUNET_TIME_absolute_get_duration (start_time);
329 fprintf (stdout, 315 fprintf (stdout, _("Transmitted %llu bytes/s (%llu bytes in %llu ms)\n"),
330 _("Transmitted %llu bytes/s (%llu bytes in %llu ms)\n"), 316 1000 * traffic_sent / (1 + duration.rel_value), traffic_sent,
331 1000 * traffic_sent / (1+duration.rel_value), 317 (unsigned long long) duration.rel_value);
332 traffic_sent,
333 (unsigned long long) duration.rel_value);
334 } 318 }
335} 319}
336 320
@@ -347,8 +331,7 @@ do_disconnect (void *cls,
347 * @return number of bytes written to buf 331 * @return number of bytes written to buf
348 */ 332 */
349static size_t 333static size_t
350transmit_data (void *cls, size_t size, 334transmit_data (void *cls, size_t size, void *buf)
351 void *buf)
352{ 335{
353 struct GNUNET_MessageHeader *m = buf; 336 struct GNUNET_MessageHeader *m = buf;
354 337
@@ -358,17 +341,12 @@ transmit_data (void *cls, size_t size,
358 m->type = ntohs (GNUNET_MESSAGE_TYPE_DUMMY); 341 m->type = ntohs (GNUNET_MESSAGE_TYPE_DUMMY);
359 memset (&m[1], 52, size - sizeof (struct GNUNET_MessageHeader)); 342 memset (&m[1], 52, size - sizeof (struct GNUNET_MessageHeader));
360 traffic_sent += size; 343 traffic_sent += size;
361 th = GNUNET_TRANSPORT_notify_transmit_ready (handle, 344 th = GNUNET_TRANSPORT_notify_transmit_ready (handle, &pid, 32 * 1024, 0,
362 &pid, 345 GNUNET_TIME_UNIT_FOREVER_REL,
363 32 * 1024, 346 &transmit_data, NULL);
364 0,
365 GNUNET_TIME_UNIT_FOREVER_REL,
366 &transmit_data, NULL);
367 if (verbosity > 0) 347 if (verbosity > 0)
368 fprintf (stdout, 348 fprintf (stdout, _("Transmitting %u bytes to %s\n"), (unsigned int) size,
369 _("Transmitting %u bytes to %s\n"), 349 GNUNET_i2s (&pid));
370 (unsigned int) size,
371 GNUNET_i2s (&pid));
372 return size; 350 return size;
373} 351}
374 352
@@ -383,39 +361,27 @@ transmit_data (void *cls, size_t size,
383 * @param ats_count number of entries in ats (excluding 0-termination) 361 * @param ats_count number of entries in ats (excluding 0-termination)
384 */ 362 */
385static void 363static void
386notify_connect (void *cls, 364notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
387 const struct GNUNET_PeerIdentity 365 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
388 * peer,
389 const struct
390 GNUNET_ATS_Information
391 * ats, uint32_t ats_count)
392{ 366{
393 if (verbosity > 0) 367 if (verbosity > 0)
394 fprintf (stdout, 368 fprintf (stdout, _("Connected to %s\n"), GNUNET_i2s (peer));
395 _("Connected to %s\n"), 369 if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity)))
396 GNUNET_i2s (peer));
397 if (0 != memcmp (&pid,
398 peer,
399 sizeof (struct GNUNET_PeerIdentity)))
400 return; 370 return;
401 ret = 0; 371 ret = 0;
402 if (benchmark_send) 372 if (benchmark_send)
403 { 373 {
404 start_time = GNUNET_TIME_absolute_get (); 374 start_time = GNUNET_TIME_absolute_get ();
405 th = GNUNET_TRANSPORT_notify_transmit_ready (handle, 375 th = GNUNET_TRANSPORT_notify_transmit_ready (handle, peer, 32 * 1024, 0,
406 peer, 376 GNUNET_TIME_UNIT_FOREVER_REL,
407 32 * 1024, 377 &transmit_data, NULL);
408 0,
409 GNUNET_TIME_UNIT_FOREVER_REL,
410 &transmit_data, NULL);
411 } 378 }
412 else 379 else
413 { 380 {
414 /* all done, terminate instantly */ 381 /* all done, terminate instantly */
415 GNUNET_SCHEDULER_cancel (end); 382 GNUNET_SCHEDULER_cancel (end);
416 end = GNUNET_SCHEDULER_add_now (&do_disconnect, 383 end = GNUNET_SCHEDULER_add_now (&do_disconnect, NULL);
417 NULL); 384 }
418 }
419} 385}
420 386
421 387
@@ -427,24 +393,17 @@ notify_connect (void *cls,
427 * @param peer the peer that disconnected 393 * @param peer the peer that disconnected
428 */ 394 */
429static void 395static void
430notify_disconnect (void *cls, 396notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
431 const struct
432 GNUNET_PeerIdentity * peer)
433{ 397{
434 if (verbosity > 0) 398 if (verbosity > 0)
435 fprintf (stdout, 399 fprintf (stdout, _("Disconnected from %s\n"), GNUNET_i2s (peer));
436 _("Disconnected from %s\n"), 400 if ((0 == memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) &&
437 GNUNET_i2s (peer)); 401 (NULL != th))
438 if ( (0 == memcmp (&pid,
439 peer,
440 sizeof (struct GNUNET_PeerIdentity))) &&
441 (NULL != th) )
442 { 402 {
443 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); 403 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
444 th = NULL; 404 th = NULL;
445 GNUNET_SCHEDULER_cancel (end); 405 GNUNET_SCHEDULER_cancel (end);
446 end = GNUNET_SCHEDULER_add_now (&do_disconnect, 406 end = GNUNET_SCHEDULER_add_now (&do_disconnect, NULL);
447 NULL);
448 } 407 }
449} 408}
450 409
@@ -456,26 +415,18 @@ notify_disconnect (void *cls,
456 * @param peer (claimed) identity of the other peer 415 * @param peer (claimed) identity of the other peer
457 * @param message the message 416 * @param message the message
458 * @param ats performance data 417 * @param ats performance data
459 * @param ats_count number of entries in ats 418 * @param ats_count number of entries in ats
460 */ 419 */
461static void 420static void
462notify_receive (void *cls, 421notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
463 const struct 422 const struct GNUNET_MessageHeader *message,
464 GNUNET_PeerIdentity * peer, 423 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
465 const struct
466 GNUNET_MessageHeader *
467 message,
468 const struct
469 GNUNET_ATS_Information
470 * ats, uint32_t ats_count)
471{ 424{
472 if (! benchmark_receive) 425 if (!benchmark_receive)
473 return; 426 return;
474 if (verbosity > 0) 427 if (verbosity > 0)
475 fprintf (stdout, 428 fprintf (stdout, _("Received %u bytes from %s\n"),
476 _("Received %u bytes from %s\n"), 429 (unsigned int) ntohs (message->size), GNUNET_i2s (peer));
477 (unsigned int) ntohs (message->size),
478 GNUNET_i2s (peer));
479 if (traffic_received == 0) 430 if (traffic_received == 0)
480 start_time = GNUNET_TIME_absolute_get (); 431 start_time = GNUNET_TIME_absolute_get ();
481 traffic_received += ntohs (message->size); 432 traffic_received += ntohs (message->size);
@@ -494,11 +445,12 @@ process_address (void *cls, const struct GNUNET_PeerIdentity *peer,
494{ 445{
495 if ((peer != NULL) || (transport != NULL) || 446 if ((peer != NULL) || (transport != NULL) ||
496 ((addr != NULL) && (addrlen > 0))) 447 ((addr != NULL) && (addrlen > 0)))
497 fprintf (stdout, 448 fprintf (stdout, _("Peer `%s' plugin: `%s' address `%s'\n"),
498 _("Peer `%s' plugin: `%s' address `%s'\n"),
499 (peer != NULL) ? GNUNET_i2s (peer) : "<unknown>", 449 (peer != NULL) ? GNUNET_i2s (peer) : "<unknown>",
500 (transport != NULL) ? transport : "<unknown>", 450 (transport != NULL) ? transport : "<unknown>", ((addr != NULL) &&
501 ((addr != NULL) && (addrlen > 0) && (transport != NULL)) ? 451 (addrlen > 0) &&
452 (transport !=
453 NULL)) ?
502 "how do i resolve the name without transport service?" : 454 "how do i resolve the name without transport service?" :
503 "<unknown>"); 455 "<unknown>");
504} 456}
@@ -523,45 +475,41 @@ run (void *cls, char *const *args, const char *cfgfile,
523 if (benchmark_send && (NULL == cpid)) 475 if (benchmark_send && (NULL == cpid))
524 { 476 {
525 fprintf (stderr, _("Option `%s' makes no sense without option `%s'.\n"), 477 fprintf (stderr, _("Option `%s' makes no sense without option `%s'.\n"),
526 "-s", "-C"); 478 "-s", "-C");
527 return; 479 return;
528 } 480 }
529 if (NULL != cpid) 481 if (NULL != cpid)
530 { 482 {
531 ret = 1; 483 ret = 1;
532 if (GNUNET_OK != 484 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (cpid, &pid.hashPubKey))
533 GNUNET_CRYPTO_hash_from_string (cpid, &pid.hashPubKey))
534 { 485 {
535 fprintf (stderr, 486 fprintf (stderr, _("Failed to parse peer identity `%s'\n"), cpid);
536 _("Failed to parse peer identity `%s'\n"),
537 cpid);
538 return; 487 return;
539 } 488 }
540 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, 489 handle =
541 &notify_receive, 490 GNUNET_TRANSPORT_connect (cfg, NULL, NULL, &notify_receive,
542 &notify_connect, 491 &notify_connect, &notify_disconnect);
543 &notify_disconnect);
544 GNUNET_TRANSPORT_try_connect (handle, &pid); 492 GNUNET_TRANSPORT_try_connect (handle, &pid);
545 end = GNUNET_SCHEDULER_add_delayed (benchmark_send 493 end =
546 ? GNUNET_TIME_UNIT_FOREVER_REL 494 GNUNET_SCHEDULER_add_delayed (benchmark_send ?
547 : GNUNET_TIME_UNIT_SECONDS, 495 GNUNET_TIME_UNIT_FOREVER_REL :
548 &do_disconnect, 496 GNUNET_TIME_UNIT_SECONDS, &do_disconnect,
549 NULL); 497 NULL);
550 } else if (benchmark_receive) 498 }
499 else if (benchmark_receive)
551 { 500 {
552 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, 501 handle =
553 &notify_receive, 502 GNUNET_TRANSPORT_connect (cfg, NULL, NULL, &notify_receive,
554 &notify_connect, 503 &notify_connect, &notify_disconnect);
555 &notify_disconnect);
556 GNUNET_TRANSPORT_try_connect (handle, &pid); 504 GNUNET_TRANSPORT_try_connect (handle, &pid);
557 end = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 505 end =
558 &do_disconnect, 506 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
559 NULL); 507 &do_disconnect, NULL);
560 } 508 }
561 if (iterate_connections) 509 if (iterate_connections)
562 { 510 {
563 GNUNET_TRANSPORT_address_iterate (cfg, GNUNET_TIME_UNIT_MINUTES, 511 GNUNET_TRANSPORT_address_iterate (cfg, GNUNET_TIME_UNIT_MINUTES,
564 &process_address, NULL); 512 &process_address, NULL);
565 } 513 }
566} 514}
567 515
@@ -578,20 +526,22 @@ main (int argc, char *const *argv)
578 1, &GNUNET_GETOPT_set_string, &cpid}, 526 1, &GNUNET_GETOPT_set_string, &cpid},
579 {'i', "information", NULL, 527 {'i', "information", NULL,
580 gettext_noop ("provide information about all current connections (once)"), 528 gettext_noop ("provide information about all current connections (once)"),
581 0, &GNUNET_GETOPT_set_one, &iterate_connections}, 529 0, &GNUNET_GETOPT_set_one, &iterate_connections},
582 {'s', "send", NULL, 530 {'s', "send", NULL,
583 gettext_noop ("send data for benchmarking to the other peer (until CTRL-C)"), 531 gettext_noop
584 0, &GNUNET_GETOPT_set_one, &benchmark_send}, 532 ("send data for benchmarking to the other peer (until CTRL-C)"),
533 0, &GNUNET_GETOPT_set_one, &benchmark_send},
585 {'t', "test", NULL, 534 {'t', "test", NULL,
586 gettext_noop ("test transport configuration (involves external server)"), 535 gettext_noop ("test transport configuration (involves external server)"),
587 0, &GNUNET_GETOPT_set_one, &test_configuration}, 536 0, &GNUNET_GETOPT_set_one, &test_configuration},
588 GNUNET_GETOPT_OPTION_VERBOSE(&verbosity), 537 GNUNET_GETOPT_OPTION_VERBOSE (&verbosity),
589 GNUNET_GETOPT_OPTION_END 538 GNUNET_GETOPT_OPTION_END
590 }; 539 };
591 return (GNUNET_OK == 540 return (GNUNET_OK ==
592 GNUNET_PROGRAM_run (argc, argv, "gnunet-transport", 541 GNUNET_PROGRAM_run (argc, argv, "gnunet-transport",
593 gettext_noop ("Direct access to transport service."), 542 gettext_noop
594 options, &run, NULL)) ? ret : 1; 543 ("Direct access to transport service."), options,
544 &run, NULL)) ? ret : 1;
595} 545}
596 546
597 547
diff --git a/src/transport/gnunet_wlan_sender.c b/src/transport/gnunet_wlan_sender.c
index 3aa32fb1c..f1a90178b 100644
--- a/src/transport/gnunet_wlan_sender.c
+++ b/src/transport/gnunet_wlan_sender.c
@@ -78,13 +78,13 @@ struct ieee80211_frame
78 * @return GNUNET_YES at success 78 * @return GNUNET_YES at success
79 */ 79 */
80static int 80static int
81getRadiotapHeader ( struct Radiotap_Send *header) 81getRadiotapHeader (struct Radiotap_Send *header)
82{ 82{
83 83
84 84
85 header->rate = 255; 85 header->rate = 255;
86 header->tx_power = 0; 86 header->tx_power = 0;
87 header->antenna = 0; 87 header->antenna = 0;
88 88
89 return GNUNET_YES; 89 return GNUNET_YES;
90} 90}
@@ -98,9 +98,8 @@ getRadiotapHeader ( struct Radiotap_Send *header)
98 * @return GNUNET_YES if there was no error 98 * @return GNUNET_YES if there was no error
99 */ 99 */
100static int 100static int
101getWlanHeader (struct ieee80211_frame *Header, 101getWlanHeader (struct ieee80211_frame *Header, const char *to_mac_addr,
102 const char *to_mac_addr, const char *mac, 102 const char *mac, unsigned int size)
103 unsigned int size)
104{ 103{
105 uint16_t *tmp16; 104 uint16_t *tmp16;
106 const int rate = 11000000; 105 const int rate = 11000000;
@@ -108,8 +107,7 @@ getWlanHeader (struct ieee80211_frame *Header,
108 Header->i_fc[0] = IEEE80211_FC0_TYPE_DATA; 107 Header->i_fc[0] = IEEE80211_FC0_TYPE_DATA;
109 Header->i_fc[1] = 0x00; 108 Header->i_fc[1] = 0x00;
110 memcpy (&Header->i_addr3, &mac_bssid, sizeof (mac_bssid)); 109 memcpy (&Header->i_addr3, &mac_bssid, sizeof (mac_bssid));
111 memcpy (&Header->i_addr2, mac, 110 memcpy (&Header->i_addr2, mac, sizeof (mac_bssid));
112 sizeof (mac_bssid));
113 memcpy (&Header->i_addr1, to_mac_addr, sizeof (mac_bssid)); 111 memcpy (&Header->i_addr1, to_mac_addr, sizeof (mac_bssid));
114 112
115 tmp16 = (uint16_t *) Header->i_dur; 113 tmp16 = (uint16_t *) Header->i_dur;
@@ -120,115 +118,133 @@ getWlanHeader (struct ieee80211_frame *Header,
120 return GNUNET_YES; 118 return GNUNET_YES;
121} 119}
122 120
123int main(int argc, char *argv[]){ 121int
122main (int argc, char *argv[])
123{
124 char msg_buf[WLAN_MTU]; 124 char msg_buf[WLAN_MTU];
125 struct GNUNET_MessageHeader *msg; 125 struct GNUNET_MessageHeader *msg;
126 struct ieee80211_frame *wlan_header; 126 struct ieee80211_frame *wlan_header;
127 struct Radiotap_Send *radiotap; 127 struct Radiotap_Send *radiotap;
128 128
129 unsigned int temp[6]; 129 unsigned int temp[6];
130 char inmac[6]; 130 char inmac[6];
131 char outmac[6]; 131 char outmac[6];
132 int pos; 132 int pos;
133 long long count; 133 long long count;
134 double bytes_per_s; 134 double bytes_per_s;
135 time_t start; 135 time_t start;
136 time_t akt; 136 time_t akt;
137 int i; 137 int i;
138 138
139 if (4 != argc) { 139 if (4 != argc)
140 fprintf( 140 {
141 stderr, 141 fprintf (stderr,
142 "This program must be started with the interface and the targets and source mac as argument.\nThis program was compiled at ----- %s ----\n", 142 "This program must be started with the interface and the targets and source mac as argument.\nThis program was compiled at ----- %s ----\n",
143 __TIMESTAMP__); 143 __TIMESTAMP__);
144 fprintf(stderr, "Usage: interface-name mac-target mac-source\n" "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); 144 fprintf (stderr,
145 return 1; 145 "Usage: interface-name mac-target mac-source\n"
146 } 146 "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n");
147 if (6 != 147 return 1;
148 sscanf(argv[3], "%x-%x-%x-%x-%x-%x", &temp[0],&temp[1],&temp[2],&temp[3],&temp[4],&temp[5])) 148 }
149 { 149 if (6 !=
150 fprintf(stderr, "Usage: interface-name mac-target mac-source\n" "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); 150 sscanf (argv[3], "%x-%x-%x-%x-%x-%x", &temp[0], &temp[1], &temp[2],
151 return 1; 151 &temp[3], &temp[4], &temp[5]))
152 } 152 {
153 if (6 != 153 fprintf (stderr,
154 sscanf(argv[2], "%x-%x-%x-%x-%x-%x", &temp[0],&temp[1],&temp[2],&temp[3],&temp[4],&temp[5])) 154 "Usage: interface-name mac-target mac-source\n"
155 { 155 "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n");
156 fprintf(stderr, "Usage: interface-name mac-target mac-source\n" "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); 156 return 1;
157 return 1; 157 }
158 } 158 if (6 !=
159 for (i = 0; i < 6; i++) 159 sscanf (argv[2], "%x-%x-%x-%x-%x-%x", &temp[0], &temp[1], &temp[2],
160 { 160 &temp[3], &temp[4], &temp[5]))
161 inmac[i] = temp[i]; 161 {
162 } 162 fprintf (stderr,
163 for (i = 0; i < 6; i++) 163 "Usage: interface-name mac-target mac-source\n"
164 { 164 "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n");
165 outmac[i] = temp[i]; 165 return 1;
166 } 166 }
167 167 for (i = 0; i < 6; i++)
168 168 {
169 pid_t pid; 169 inmac[i] = temp[i];
170 int commpipe[2]; /* This holds the fd for the input & output of the pipe */ 170 }
171 171 for (i = 0; i < 6; i++)
172 /* Setup communication pipeline first */ 172 {
173 if(pipe(commpipe)){ 173 outmac[i] = temp[i];
174 fprintf(stderr,"Pipe error!\n"); 174 }
175 exit(1); 175
176 } 176
177 177 pid_t pid;
178 /* Attempt to fork and check for errors */ 178 int commpipe[2]; /* This holds the fd for the input & output of the pipe */
179 if( (pid=fork()) == -1){ 179
180 fprintf(stderr,"Fork error. Exiting.\n"); /* something went wrong */ 180 /* Setup communication pipeline first */
181 exit(1); 181 if (pipe (commpipe))
182 } 182 {
183 183 fprintf (stderr, "Pipe error!\n");
184 if(pid){ 184 exit (1);
185 /* A positive (non-negative) PID indicates the parent process */ 185 }
186 close(commpipe[0]); /* Close unused side of pipe (in side) */ 186
187 setvbuf(stdout,(char*)NULL,_IONBF,0); /* Set non-buffered output on stdout */ 187 /* Attempt to fork and check for errors */
188 188 if ((pid = fork ()) == -1)
189 189 {
190 msg = (struct GNUNET_MessageHeader*) msg_buf; 190 fprintf (stderr, "Fork error. Exiting.\n"); /* something went wrong */
191 msg->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); 191 exit (1);
192 msg->size = htons (WLAN_MTU); 192 }
193 radiotap = (struct Radiotap_Send *) &msg[1]; 193
194 wlan_header = (struct ieee80211_frame *) &radiotap[1]; 194 if (pid)
195 pos = 0; 195 {
196 196 /* A positive (non-negative) PID indicates the parent process */
197 getRadiotapHeader(radiotap); 197 close (commpipe[0]); /* Close unused side of pipe (in side) */
198 getWlanHeader(wlan_header, outmac, inmac, WLAN_MTU - sizeof(struct GNUNET_MessageHeader)); 198 setvbuf (stdout, (char *) NULL, _IONBF, 0); /* Set non-buffered output on stdout */
199 199
200 start = time(NULL); 200
201 count = 0; 201 msg = (struct GNUNET_MessageHeader *) msg_buf;
202 while (1){ 202 msg->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
203 pos += write(commpipe[1], msg, WLAN_MTU - pos); 203 msg->size = htons (WLAN_MTU);
204 if (pos % WLAN_MTU == 0){ 204 radiotap = (struct Radiotap_Send *) &msg[1];
205 pos = 0; 205 wlan_header = (struct ieee80211_frame *) &radiotap[1];
206 count ++; 206 pos = 0;
207 207
208 if (count % 1000 == 0){ 208 getRadiotapHeader (radiotap);
209 akt = time(NULL); 209 getWlanHeader (wlan_header, outmac, inmac,
210 bytes_per_s = count * WLAN_MTU / (akt - start); 210 WLAN_MTU - sizeof (struct GNUNET_MessageHeader));
211 bytes_per_s /= 1024; 211
212 printf("send %f kbytes/s\n", bytes_per_s); 212 start = time (NULL);
213 } 213 count = 0;
214 } 214 while (1)
215 215 {
216 } 216 pos += write (commpipe[1], msg, WLAN_MTU - pos);
217 } 217 if (pos % WLAN_MTU == 0)
218 else{ 218 {
219 /* A zero PID indicates that this is the child process */ 219 pos = 0;
220 (void) close(0); 220 count++;
221 if (-1 == dup2(commpipe[0],0)) /* Replace stdin with the in side of the pipe */ 221
222 fprintf (stderr, 222 if (count % 1000 == 0)
223 "dup2 failed: %s\n", 223 {
224 strerror (errno)); 224 akt = time (NULL);
225 (void) close(commpipe[1]); /* Close unused side of pipe (out side) */ 225 bytes_per_s = count * WLAN_MTU / (akt - start);
226 /* Replace the child fork with a new process */ 226 bytes_per_s /= 1024;
227 if (execl("gnunet-transport-wlan-helper","gnunet-transport-wlan-helper", argv[1], NULL) == -1) 227 printf ("send %f kbytes/s\n", bytes_per_s);
228 { 228 }
229 fprintf(stderr,"Could not start gnunet-transport-wlan-helper!"); 229 }
230 _exit(1); 230
231 } 231 }
232 } 232 }
233 return 0; 233 else
234 {
235 /* A zero PID indicates that this is the child process */
236 (void) close (0);
237 if (-1 == dup2 (commpipe[0], 0)) /* Replace stdin with the in side of the pipe */
238 fprintf (stderr, "dup2 failed: %s\n", strerror (errno));
239 (void) close (commpipe[1]); /* Close unused side of pipe (out side) */
240 /* Replace the child fork with a new process */
241 if (execl
242 ("gnunet-transport-wlan-helper", "gnunet-transport-wlan-helper",
243 argv[1], NULL) == -1)
244 {
245 fprintf (stderr, "Could not start gnunet-transport-wlan-helper!");
246 _exit (1);
247 }
248 }
249 return 0;
234} 250}
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index 784dd3002..9008b958d 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -155,18 +155,20 @@ http_plugin_address_pretty_printer (void *cls, const char *type,
155 struct PrettyPrinterContext *ppc; 155 struct PrettyPrinterContext *ppc;
156 const void *sb; 156 const void *sb;
157 size_t sbs; 157 size_t sbs;
158 uint16_t port = 0 ; 158 uint16_t port = 0;
159 159
160 if (addrlen == sizeof (struct IPv6HttpAddress)) 160 if (addrlen == sizeof (struct IPv6HttpAddress))
161 { 161 {
162 struct IPv6HttpAddress * a6 = (struct IPv6HttpAddress *) addr; 162 struct IPv6HttpAddress *a6 = (struct IPv6HttpAddress *) addr;
163
163 sb = &a6->ipv6_addr; 164 sb = &a6->ipv6_addr;
164 sbs = sizeof (struct in6_addr); 165 sbs = sizeof (struct in6_addr);
165 port = ntohs (a6->u6_port); 166 port = ntohs (a6->u6_port);
166 } 167 }
167 else if (addrlen == sizeof (struct IPv4HttpAddress)) 168 else if (addrlen == sizeof (struct IPv4HttpAddress))
168 { 169 {
169 struct IPv4HttpAddress * a4 = (struct IPv4HttpAddress *) addr; 170 struct IPv4HttpAddress *a4 = (struct IPv4HttpAddress *) addr;
171
170 sb = &a4->ipv4_addr; 172 sb = &a4->ipv4_addr;
171 sbs = sizeof (struct in_addr); 173 sbs = sizeof (struct in_addr);
172 port = ntohs (a4->u4_port); 174 port = ntohs (a4->u4_port);
@@ -218,9 +220,12 @@ http_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
218 if (addrlen == sizeof (struct IPv4HttpAddress)) 220 if (addrlen == sizeof (struct IPv4HttpAddress))
219 { 221 {
220 struct IPv4HttpAddress *a4 = (struct IPv4HttpAddress *) addr; 222 struct IPv4HttpAddress *a4 = (struct IPv4HttpAddress *) addr;
223
221 while (w_tv4 != NULL) 224 while (w_tv4 != NULL)
222 { 225 {
223 if ((0 == memcmp (&w_tv4->addr.ipv4_addr, &a4->ipv4_addr, sizeof (struct in_addr))) && 226 if ((0 ==
227 memcmp (&w_tv4->addr.ipv4_addr, &a4->ipv4_addr,
228 sizeof (struct in_addr))) &&
224 (w_tv4->addr.u4_port == a4->u4_port)) 229 (w_tv4->addr.u4_port == a4->u4_port))
225 break; 230 break;
226 w_tv4 = w_tv4->next; 231 w_tv4 = w_tv4->next;
@@ -233,9 +238,12 @@ http_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
233 if (addrlen == sizeof (struct sockaddr_in6)) 238 if (addrlen == sizeof (struct sockaddr_in6))
234 { 239 {
235 struct IPv6HttpAddress *a6 = (struct IPv6HttpAddress *) addr; 240 struct IPv6HttpAddress *a6 = (struct IPv6HttpAddress *) addr;
241
236 while (w_tv6 != NULL) 242 while (w_tv6 != NULL)
237 { 243 {
238 if ((0 == memcmp (&w_tv6->addr6.ipv6_addr, &a6->ipv6_addr, sizeof (struct in6_addr))) && 244 if ((0 ==
245 memcmp (&w_tv6->addr6.ipv6_addr, &a6->ipv6_addr,
246 sizeof (struct in6_addr))) &&
239 (w_tv6->addr6.u6_port == a6->u6_port)) 247 (w_tv6->addr6.u6_port == a6->u6_port))
240 break; 248 break;
241 w_tv6 = w_tv6->next; 249 w_tv6 = w_tv6->next;
@@ -249,11 +257,10 @@ http_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
249} 257}
250 258
251struct GNUNET_TIME_Relative 259struct GNUNET_TIME_Relative
252http_plugin_receive (void *cls, const struct GNUNET_PeerIdentity * peer, 260http_plugin_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
253 const struct GNUNET_MessageHeader * message, 261 const struct GNUNET_MessageHeader *message,
254 struct Session * session, 262 struct Session *session, const char *sender_address,
255 const char *sender_address, 263 uint16_t sender_address_len)
256 uint16_t sender_address_len)
257{ 264{
258 struct Session *s = cls; 265 struct Session *s = cls;
259 struct Plugin *plugin = s->plugin; 266 struct Plugin *plugin = s->plugin;
@@ -263,7 +270,10 @@ http_plugin_receive (void *cls, const struct GNUNET_PeerIdentity * peer,
263 distance.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); 270 distance.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
264 distance.value = htonl (1); 271 distance.value = htonl (1);
265 272
266 delay = plugin->env->receive (plugin->env->cls, &s->target, message, (const struct GNUNET_ATS_Information*) &distance, 1, s, s->addr, s->addrlen); 273 delay =
274 plugin->env->receive (plugin->env->cls, &s->target, message,
275 (const struct GNUNET_ATS_Information *) &distance,
276 1, s, s->addr, s->addrlen);
267 return delay; 277 return delay;
268} 278}
269 279
@@ -293,14 +303,18 @@ http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
293 { 303 {
294 a6 = (struct IPv6HttpAddress *) addr; 304 a6 = (struct IPv6HttpAddress *) addr;
295 address = GNUNET_malloc (INET6_ADDRSTRLEN); 305 address = GNUNET_malloc (INET6_ADDRSTRLEN);
296 GNUNET_assert(NULL != inet_ntop (AF_INET6, &a6->ipv6_addr, address, INET6_ADDRSTRLEN)); 306 GNUNET_assert (NULL !=
307 inet_ntop (AF_INET6, &a6->ipv6_addr, address,
308 INET6_ADDRSTRLEN));
297 port = ntohs (a6->u6_port); 309 port = ntohs (a6->u6_port);
298 } 310 }
299 else if (addrlen == sizeof (struct IPv4HttpAddress)) 311 else if (addrlen == sizeof (struct IPv4HttpAddress))
300 { 312 {
301 a4 = (struct IPv4HttpAddress *) addr; 313 a4 = (struct IPv4HttpAddress *) addr;
302 address = GNUNET_malloc (INET_ADDRSTRLEN); 314 address = GNUNET_malloc (INET_ADDRSTRLEN);
303 GNUNET_assert(NULL != inet_ntop (AF_INET, &(a4->ipv4_addr), address, INET_ADDRSTRLEN)); 315 GNUNET_assert (NULL !=
316 inet_ntop (AF_INET, &(a4->ipv4_addr), address,
317 INET_ADDRSTRLEN));
304 port = ntohs (a4->u4_port); 318 port = ntohs (a4->u4_port);
305 } 319 }
306 else 320 else
@@ -309,17 +323,21 @@ http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
309 GNUNET_break (0); 323 GNUNET_break (0);
310 return NULL; 324 return NULL;
311 } 325 }
312#if !BUILD_HTTPS 326#if !BUILD_HTTPS
313 char * protocol = "http"; 327 char *protocol = "http";
314#else 328#else
315 char * protocol = "https"; 329 char *protocol = "https";
316#endif 330#endif
317 331
318 GNUNET_assert (strlen (address) + 7 < (INET6_ADDRSTRLEN + 13)); 332 GNUNET_assert (strlen (address) + 7 < (INET6_ADDRSTRLEN + 13));
319 if (addrlen == sizeof (struct IPv6HttpAddress)) 333 if (addrlen == sizeof (struct IPv6HttpAddress))
320 res = GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://[%s]:%u/", protocol, address, port); 334 res =
335 GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://[%s]:%u/", protocol,
336 address, port);
321 else if (addrlen == sizeof (struct IPv4HttpAddress)) 337 else if (addrlen == sizeof (struct IPv4HttpAddress))
322 res = GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://%s:%u/", protocol, address, port); 338 res =
339 GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://%s:%u/", protocol, address,
340 port);
323 341
324 GNUNET_free (address); 342 GNUNET_free (address);
325 GNUNET_assert (res != 0); 343 GNUNET_assert (res != 0);
@@ -328,8 +346,8 @@ http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
328 346
329struct Session * 347struct Session *
330lookup_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, 348lookup_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
331 struct Session * session, 349 struct Session *session, const void *addr, size_t addrlen,
332 const void *addr, size_t addrlen, int force_address) 350 int force_address)
333{ 351{
334 struct Session *s = NULL; 352 struct Session *s = NULL;
335 struct Session *t = NULL; 353 struct Session *t = NULL;
@@ -343,9 +361,15 @@ lookup_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
343 { 361 {
344#if 0 362#if 0
345 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, 363 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
346 "Comparing peer `%s' address `%s' len %i session %X to \n", GNUNET_i2s(target), GNUNET_a2s(addr,addrlen), addrlen, session); 364 "Comparing peer `%s' address `%s' len %i session %X to \n",
347 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,"peer `%s' address `%s' len %i session %X \n\n", GNUNET_i2s(&t->target), GNUNET_a2s(t->addr,t->addrlen), t->addrlen, t); 365 GNUNET_i2s (target), GNUNET_a2s (addr, addrlen), addrlen,
348 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,"memcmp %i \n", memcmp (addr, t->addr, addrlen)); 366 session);
367 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
368 "peer `%s' address `%s' len %i session %X \n\n",
369 GNUNET_i2s (&t->target), GNUNET_a2s (t->addr, t->addrlen),
370 t->addrlen, t);
371 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, "memcmp %i \n",
372 memcmp (addr, t->addr, addrlen));
349#endif 373#endif
350 e_peer = GNUNET_NO; 374 e_peer = GNUNET_NO;
351 e_addr = GNUNET_NO; 375 e_addr = GNUNET_NO;
@@ -362,13 +386,13 @@ lookup_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
362 } 386 }
363 if ((t == session)) 387 if ((t == session))
364 { 388 {
365 if(t->addrlen == session->addrlen) 389 if (t->addrlen == session->addrlen)
366 {
367 if (0 == memcmp (session->addr, t->addr, t->addrlen))
368 { 390 {
369 e_addr = GNUNET_YES; 391 if (0 == memcmp (session->addr, t->addr, t->addrlen))
392 {
393 e_addr = GNUNET_YES;
394 }
370 } 395 }
371 }
372 } 396 }
373 } 397 }
374 398
@@ -377,7 +401,8 @@ lookup_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
377 s = t; 401 s = t;
378 break; 402 break;
379 } 403 }
380 if ((e_peer == GNUNET_YES) && (force_address == GNUNET_YES) && (e_addr == GNUNET_YES)) 404 if ((e_peer == GNUNET_YES) && (force_address == GNUNET_YES) &&
405 (e_addr == GNUNET_YES))
381 { 406 {
382 s = t; 407 s = t;
383 break; 408 break;
@@ -405,8 +430,8 @@ delete_session (struct Session *s)
405 s->msg_tk = NULL; 430 s->msg_tk = NULL;
406 } 431 }
407 GNUNET_free (s->addr); 432 GNUNET_free (s->addr);
408 GNUNET_free_non_null(s->server_recv); 433 GNUNET_free_non_null (s->server_recv);
409 GNUNET_free_non_null(s->server_send); 434 GNUNET_free_non_null (s->server_send);
410 GNUNET_free (s); 435 GNUNET_free (s);
411} 436}
412 437
@@ -416,7 +441,9 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
416 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) 441 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
417{ 442{
418 struct Session *s = NULL; 443 struct Session *s = NULL;
419 GNUNET_assert ((addrlen == sizeof (struct IPv6HttpAddress)) || (addrlen == sizeof (struct IPv4HttpAddress))); 444
445 GNUNET_assert ((addrlen == sizeof (struct IPv6HttpAddress)) ||
446 (addrlen == sizeof (struct IPv4HttpAddress)));
420 s = GNUNET_malloc (sizeof (struct Session)); 447 s = GNUNET_malloc (sizeof (struct Session));
421 memcpy (&s->target, target, sizeof (struct GNUNET_PeerIdentity)); 448 memcpy (&s->target, target, sizeof (struct GNUNET_PeerIdentity));
422 s->plugin = plugin; 449 s->plugin = plugin;
@@ -424,14 +451,13 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
424 memcpy (s->addr, addr, addrlen); 451 memcpy (s->addr, addr, addrlen);
425 s->addrlen = addrlen; 452 s->addrlen = addrlen;
426 s->next = NULL; 453 s->next = NULL;
427 s->next_receive = GNUNET_TIME_absolute_get_zero(); 454 s->next_receive = GNUNET_TIME_absolute_get_zero ();
428 return s; 455 return s;
429} 456}
430 457
431void 458void
432notify_session_end (void *cls, 459notify_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
433 const struct GNUNET_PeerIdentity * 460 struct Session *s)
434 peer, struct Session * s)
435{ 461{
436 struct Plugin *plugin = cls; 462 struct Plugin *plugin = cls;
437 463
@@ -486,28 +512,38 @@ http_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
486{ 512{
487 struct Plugin *plugin = cls; 513 struct Plugin *plugin = cls;
488 struct HTTP_Message *msg; 514 struct HTTP_Message *msg;
515
489 GNUNET_assert (plugin != NULL); 516 GNUNET_assert (plugin != NULL);
490 517
491 int res = GNUNET_SYSERR; 518 int res = GNUNET_SYSERR;
492 519
493#if DEBUG_HTTP 520#if DEBUG_HTTP
494 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 521 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
495 "Sending %u bytes to peer `%s' on address `%s' %X %i\n", msgbuf_size, 522 "Sending %u bytes to peer `%s' on address `%s' %X %i\n",
496 GNUNET_i2s (target), ((addr != NULL) && (addrlen != 0)) ? http_plugin_address_to_string(plugin, addr, addrlen) : "<inbound>", session, force_address); 523 msgbuf_size, GNUNET_i2s (target), ((addr != NULL) &&
524 (addrlen !=
525 0)) ?
526 http_plugin_address_to_string (plugin, addr,
527 addrlen) : "<inbound>",
528 session, force_address);
497#endif 529#endif
498 530
499 struct Session *s = NULL; 531 struct Session *s = NULL;
500 532
501 533
502 if (addrlen != 0) 534 if (addrlen != 0)
503 GNUNET_assert ((addrlen == sizeof (struct IPv4HttpAddress)) || 535 GNUNET_assert ((addrlen == sizeof (struct IPv4HttpAddress)) ||
504 (addrlen == sizeof (struct IPv6HttpAddress))); 536 (addrlen == sizeof (struct IPv6HttpAddress)));
505 537
506 /* look for existing connection */ 538 /* look for existing connection */
507 s = lookup_session (plugin, target, session, addr, addrlen, 1); 539 s = lookup_session (plugin, target, session, addr, addrlen, 1);
508#if DEBUG_HTTP 540#if DEBUG_HTTP
509 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 541 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
510 "%s existing session: %s\n", (s!=NULL) ? "Found" : "NOT Found", ((s != NULL) && (s->inbound == GNUNET_YES)) ? "inbound" : "outbound"); 542 "%s existing session: %s\n",
543 (s != NULL) ? "Found" : "NOT Found", ((s != NULL) &&
544 (s->inbound ==
545 GNUNET_YES)) ?
546 "inbound" : "outbound");
511#endif 547#endif
512 548
513 /* create new outbound connection */ 549 /* create new outbound connection */
@@ -517,8 +553,7 @@ http_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
517 { 553 {
518 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name, 554 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name,
519 "Maximum number of connections reached, " 555 "Maximum number of connections reached, "
520 "cannot connect to peer `%s'\n", 556 "cannot connect to peer `%s'\n", GNUNET_i2s (target));
521 GNUNET_i2s (target));
522 return res; 557 return res;
523 } 558 }
524 559
@@ -554,8 +589,8 @@ http_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
554 "Using outbound client session to send to `%s'\n", 589 "Using outbound client session to send to `%s'\n",
555 GNUNET_i2s (target)); 590 GNUNET_i2s (target));
556#endif 591#endif
557 client_send (s, msg); 592 client_send (s, msg);
558 res = msgbuf_size; 593 res = msgbuf_size;
559 } 594 }
560 if (s->inbound == GNUNET_YES) 595 if (s->inbound == GNUNET_YES)
561 { 596 {
@@ -621,14 +656,16 @@ nat_add_address (void *cls, int add_remove, const struct sockaddr *addr,
621 case AF_INET: 656 case AF_INET:
622 w_t4 = plugin->ipv4_addr_head; 657 w_t4 = plugin->ipv4_addr_head;
623 struct sockaddr_in *a4 = (struct sockaddr_in *) addr; 658 struct sockaddr_in *a4 = (struct sockaddr_in *) addr;
659
624 while (w_t4 != NULL) 660 while (w_t4 != NULL)
625 { 661 {
626 int res = memcmp (&w_t4->addr.ipv4_addr, 662 int res = memcmp (&w_t4->addr.ipv4_addr,
627 &a4->sin_addr, 663 &a4->sin_addr,
628 sizeof (struct in_addr)); 664 sizeof (struct in_addr));
665
629 if (res == 0) 666 if (res == 0)
630 { 667 {
631 if (a4->sin_port!= w_t4->addr.u4_port) 668 if (a4->sin_port != w_t4->addr.u4_port)
632 res = -1; 669 res = -1;
633 } 670 }
634 671
@@ -639,8 +676,7 @@ nat_add_address (void *cls, int add_remove, const struct sockaddr *addr,
639 if (w_t4 == NULL) 676 if (w_t4 == NULL)
640 { 677 {
641 w_t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddressWrapper)); 678 w_t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddressWrapper));
642 memcpy (&w_t4->addr.ipv4_addr, &a4->sin_addr, 679 memcpy (&w_t4->addr.ipv4_addr, &a4->sin_addr, sizeof (struct in_addr));
643 sizeof (struct in_addr));
644 w_t4->addr.u4_port = a4->sin_port; 680 w_t4->addr.u4_port = a4->sin_port;
645 681
646 GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head, 682 GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head,
@@ -649,18 +685,23 @@ nat_add_address (void *cls, int add_remove, const struct sockaddr *addr,
649#if DEBUG_HTTP 685#if DEBUG_HTTP
650 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 686 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
651 "Notifying transport to add IPv4 address `%s'\n", 687 "Notifying transport to add IPv4 address `%s'\n",
652 http_plugin_address_to_string(NULL, &w_t4->addr, sizeof (struct IPv4HttpAddress))); 688 http_plugin_address_to_string (NULL, &w_t4->addr,
689 sizeof (struct
690 IPv4HttpAddress)));
653#endif 691#endif
654 plugin->env->notify_address (plugin->env->cls, add_remove, &w_t4->addr, sizeof (struct IPv4HttpAddress)); 692 plugin->env->notify_address (plugin->env->cls, add_remove, &w_t4->addr,
693 sizeof (struct IPv4HttpAddress));
655 694
656 break; 695 break;
657 case AF_INET6: 696 case AF_INET6:
658 w_t6 = plugin->ipv6_addr_head; 697 w_t6 = plugin->ipv6_addr_head;
659 struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr; 698 struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr;
699
660 while (w_t6) 700 while (w_t6)
661 { 701 {
662 int res = memcmp (&w_t6->addr6.ipv6_addr, &a6->sin6_addr, 702 int res = memcmp (&w_t6->addr6.ipv6_addr, &a6->sin6_addr,
663 sizeof (struct in6_addr)); 703 sizeof (struct in6_addr));
704
664 if (res == 0) 705 if (res == 0)
665 { 706 {
666 if (a6->sin6_port != w_t6->addr6.u6_port) 707 if (a6->sin6_port != w_t6->addr6.u6_port)
@@ -674,8 +715,7 @@ nat_add_address (void *cls, int add_remove, const struct sockaddr *addr,
674 { 715 {
675 w_t6 = GNUNET_malloc (sizeof (struct IPv6HttpAddressWrapper)); 716 w_t6 = GNUNET_malloc (sizeof (struct IPv6HttpAddressWrapper));
676 717
677 memcpy (&w_t6->addr6.ipv6_addr, &a6->sin6_addr, 718 memcpy (&w_t6->addr6.ipv6_addr, &a6->sin6_addr, sizeof (struct in6_addr));
678 sizeof (struct in6_addr));
679 w_t6->addr6.u6_port = a6->sin6_port; 719 w_t6->addr6.u6_port = a6->sin6_port;
680 720
681 GNUNET_CONTAINER_DLL_insert (plugin->ipv6_addr_head, 721 GNUNET_CONTAINER_DLL_insert (plugin->ipv6_addr_head,
@@ -684,9 +724,12 @@ nat_add_address (void *cls, int add_remove, const struct sockaddr *addr,
684#if DEBUG_HTTP 724#if DEBUG_HTTP
685 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 725 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
686 "Notifying transport to add IPv6 address `%s'\n", 726 "Notifying transport to add IPv6 address `%s'\n",
687 http_plugin_address_to_string(NULL, &w_t6->addr6, sizeof (struct IPv6HttpAddress))); 727 http_plugin_address_to_string (NULL, &w_t6->addr6,
728 sizeof (struct
729 IPv6HttpAddress)));
688#endif 730#endif
689 plugin->env->notify_address (plugin->env->cls, add_remove, &w_t6->addr6, sizeof (struct IPv6HttpAddress)); 731 plugin->env->notify_address (plugin->env->cls, add_remove, &w_t6->addr6,
732 sizeof (struct IPv6HttpAddress));
690 break; 733 break;
691 default: 734 default:
692 return; 735 return;
@@ -709,14 +752,16 @@ nat_remove_address (void *cls, int add_remove, const struct sockaddr *addr,
709 case AF_INET: 752 case AF_INET:
710 w_t4 = plugin->ipv4_addr_head; 753 w_t4 = plugin->ipv4_addr_head;
711 struct sockaddr_in *a4 = (struct sockaddr_in *) addr; 754 struct sockaddr_in *a4 = (struct sockaddr_in *) addr;
755
712 while (w_t4 != NULL) 756 while (w_t4 != NULL)
713 { 757 {
714 int res = memcmp (&w_t4->addr.ipv4_addr, 758 int res = memcmp (&w_t4->addr.ipv4_addr,
715 &a4->sin_addr, 759 &a4->sin_addr,
716 sizeof (struct in_addr)); 760 sizeof (struct in_addr));
761
717 if (res == 0) 762 if (res == 0)
718 { 763 {
719 if (a4->sin_port!= w_t4->addr.u4_port) 764 if (a4->sin_port != w_t4->addr.u4_port)
720 res = -1; 765 res = -1;
721 } 766 }
722 767
@@ -730,7 +775,9 @@ nat_remove_address (void *cls, int add_remove, const struct sockaddr *addr,
730#if DEBUG_HTTP 775#if DEBUG_HTTP
731 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 776 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
732 "Notifying transport to remove IPv4 address `%s'\n", 777 "Notifying transport to remove IPv4 address `%s'\n",
733 http_plugin_address_to_string(NULL, &w_t4->addr, sizeof (struct IPv4HttpAddress))); 778 http_plugin_address_to_string (NULL, &w_t4->addr,
779 sizeof (struct
780 IPv4HttpAddress)));
734#endif 781#endif
735 plugin->env->notify_address (plugin->env->cls, add_remove, &w_t4->addr, 782 plugin->env->notify_address (plugin->env->cls, add_remove, &w_t4->addr,
736 sizeof (struct IPv4HttpAddress)); 783 sizeof (struct IPv4HttpAddress));
@@ -742,10 +789,12 @@ nat_remove_address (void *cls, int add_remove, const struct sockaddr *addr,
742 case AF_INET6: 789 case AF_INET6:
743 w_t6 = plugin->ipv6_addr_head; 790 w_t6 = plugin->ipv6_addr_head;
744 struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr; 791 struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr;
792
745 while (w_t6) 793 while (w_t6)
746 { 794 {
747 int res = memcmp (&w_t6->addr6.ipv6_addr, &a6->sin6_addr, 795 int res = memcmp (&w_t6->addr6.ipv6_addr, &a6->sin6_addr,
748 sizeof (struct in6_addr)); 796 sizeof (struct in6_addr));
797
749 if (res == 0) 798 if (res == 0)
750 { 799 {
751 if (a6->sin6_port != w_t6->addr6.u6_port) 800 if (a6->sin6_port != w_t6->addr6.u6_port)
@@ -760,7 +809,9 @@ nat_remove_address (void *cls, int add_remove, const struct sockaddr *addr,
760#if DEBUG_HTTP 809#if DEBUG_HTTP
761 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 810 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
762 "Notifying transport to remove IPv6 address `%s'\n", 811 "Notifying transport to remove IPv6 address `%s'\n",
763 http_plugin_address_to_string(NULL, &w_t6->addr6, sizeof (struct IPv6HttpAddress))); 812 http_plugin_address_to_string (NULL, &w_t6->addr6,
813 sizeof (struct
814 IPv6HttpAddress)));
764#endif 815#endif
765 plugin->env->notify_address (plugin->env->cls, add_remove, &w_t6->addr6, 816 plugin->env->notify_address (plugin->env->cls, add_remove, &w_t6->addr6,
766 sizeof (struct IPv6HttpAddress)); 817 sizeof (struct IPv6HttpAddress));
@@ -801,7 +852,7 @@ nat_port_map_callback (void *cls, int add_remove, const struct sockaddr *addr,
801 switch (add_remove) 852 switch (add_remove)
802 { 853 {
803 case GNUNET_YES: 854 case GNUNET_YES:
804 nat_add_address (cls, add_remove, addr, addrlen); 855 nat_add_address (cls, add_remove, addr, addrlen);
805 break; 856 break;
806 case GNUNET_NO: 857 case GNUNET_NO:
807 nat_remove_address (cls, add_remove, addr, addrlen); 858 nat_remove_address (cls, add_remove, addr, addrlen);
@@ -813,6 +864,7 @@ void
813http_check_ipv6 (struct Plugin *plugin) 864http_check_ipv6 (struct Plugin *plugin)
814{ 865{
815 struct GNUNET_NETWORK_Handle *desc = NULL; 866 struct GNUNET_NETWORK_Handle *desc = NULL;
867
816 if (plugin->ipv6 == GNUNET_YES) 868 if (plugin->ipv6 == GNUNET_YES)
817 { 869 {
818 /* probe IPv6 support */ 870 /* probe IPv6 support */
@@ -825,8 +877,8 @@ http_check_ipv6 (struct Plugin *plugin)
825 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); 877 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
826 } 878 }
827 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name, 879 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name,
828 _ 880 _
829 ("Disabling IPv6 since it is not supported on this system!\n")); 881 ("Disabling IPv6 since it is not supported on this system!\n"));
830 plugin->ipv6 = GNUNET_NO; 882 plugin->ipv6 = GNUNET_NO;
831 } 883 }
832 else 884 else
@@ -835,17 +887,16 @@ http_check_ipv6 (struct Plugin *plugin)
835 desc = NULL; 887 desc = NULL;
836 } 888 }
837 889
838 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 890 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
839 "Testing IPv6 on this system: %s\n", (plugin->ipv6 == GNUNET_YES) ? "successful" : "failed"); 891 "Testing IPv6 on this system: %s\n",
892 (plugin->ipv6 == GNUNET_YES) ? "successful" : "failed");
840 } 893 }
841} 894}
842 895
843int 896int
844http_get_addresses (struct Plugin *plugin, 897http_get_addresses (struct Plugin *plugin, const char *serviceName,
845 const char *serviceName, 898 const struct GNUNET_CONFIGURATION_Handle *cfg,
846 const struct GNUNET_CONFIGURATION_Handle 899 struct sockaddr ***addrs, socklen_t ** addr_lens)
847 *cfg, struct sockaddr ***addrs,
848 socklen_t ** addr_lens)
849{ 900{
850 int disablev6; 901 int disablev6;
851 unsigned long long port; 902 unsigned long long port;
@@ -892,8 +943,8 @@ http_get_addresses (struct Plugin *plugin,
892 if (hostname != NULL) 943 if (hostname != NULL)
893 { 944 {
894 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 945 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
895 "Resolving `%s' since that is where `%s' will bind to.\n", 946 "Resolving `%s' since that is where `%s' will bind to.\n",
896 hostname, serviceName); 947 hostname, serviceName);
897 memset (&hints, 0, sizeof (struct addrinfo)); 948 memset (&hints, 0, sizeof (struct addrinfo));
898 if (disablev6) 949 if (disablev6)
899 hints.ai_family = AF_INET; 950 hints.ai_family = AF_INET;
@@ -938,8 +989,8 @@ http_get_addresses (struct Plugin *plugin,
938 if ((pos->ai_socktype != SOCK_STREAM) && (pos->ai_socktype != 0)) 989 if ((pos->ai_socktype != SOCK_STREAM) && (pos->ai_socktype != 0))
939 continue; /* huh? */ 990 continue; /* huh? */
940 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 991 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
941 "Service will bind to `%s'\n", 992 "Service will bind to `%s'\n", GNUNET_a2s (pos->ai_addr,
942 GNUNET_a2s (pos->ai_addr, pos->ai_addrlen)); 993 pos->ai_addrlen));
943 if (pos->ai_family == AF_INET) 994 if (pos->ai_family == AF_INET)
944 { 995 {
945 GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in)); 996 GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in));
@@ -1019,10 +1070,10 @@ start_report_addresses (struct Plugin *plugin)
1019 socklen_t *addrlens; 1070 socklen_t *addrlens;
1020 1071
1021 res = 1072 res =
1022 http_get_addresses (plugin, plugin->name, plugin->env->cfg, 1073 http_get_addresses (plugin, plugin->name, plugin->env->cfg, &addrs,
1023 &addrs, &addrlens); 1074 &addrlens);
1024 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1075 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1025 _("Found %u addresses to report to NAT service\n"),res); 1076 _("Found %u addresses to report to NAT service\n"), res);
1026 1077
1027 if (res != GNUNET_SYSERR) 1078 if (res != GNUNET_SYSERR)
1028 { 1079 {
@@ -1030,14 +1081,12 @@ start_report_addresses (struct Plugin *plugin)
1030 GNUNET_NAT_register (plugin->env->cfg, GNUNET_YES, plugin->port, 1081 GNUNET_NAT_register (plugin->env->cfg, GNUNET_YES, plugin->port,
1031 (unsigned int) res, 1082 (unsigned int) res,
1032 (const struct sockaddr **) addrs, addrlens, 1083 (const struct sockaddr **) addrs, addrlens,
1033 &nat_port_map_callback, NULL, 1084 &nat_port_map_callback, NULL, plugin);
1034 plugin);
1035 while (res > 0) 1085 while (res > 0)
1036 { 1086 {
1037 res--; 1087 res--;
1038#if 0 1088#if 0
1039 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, 1089 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, _("FREEING %s\n"),
1040 _("FREEING %s\n"),
1041 GNUNET_a2s (addrs[res], addrlens[res])); 1090 GNUNET_a2s (addrs[res], addrlens[res]));
1042#endif 1091#endif
1043 GNUNET_assert (addrs[res] != NULL); 1092 GNUNET_assert (addrs[res] != NULL);
@@ -1136,24 +1185,28 @@ configure_plugin (struct Plugin *plugin)
1136 if (plugin->port == 0) 1185 if (plugin->port == 0)
1137 { 1186 {
1138 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1187 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1139 _("Port 0, client only mode\n")); 1188 _("Port 0, client only mode\n"));
1140 plugin->client_only = GNUNET_YES; 1189 plugin->client_only = GNUNET_YES;
1141 } 1190 }
1142 1191
1143 char * bind4_address = NULL; 1192 char *bind4_address = NULL;
1144 if ((plugin->ipv4 == GNUNET_YES) && (GNUNET_YES == 1193
1145 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name, 1194 if ((plugin->ipv4 == GNUNET_YES) &&
1146 "BINDTO", &bind4_address))) 1195 (GNUNET_YES ==
1196 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name,
1197 "BINDTO", &bind4_address)))
1147 { 1198 {
1148 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1199 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1149 "Binding %s plugin to specific IPv4 address: `%s'\n", 1200 "Binding %s plugin to specific IPv4 address: `%s'\n",
1150 plugin->protocol, bind4_address); 1201 plugin->protocol, bind4_address);
1151 plugin->server_addr_v4 = GNUNET_malloc (sizeof (struct sockaddr_in)); 1202 plugin->server_addr_v4 = GNUNET_malloc (sizeof (struct sockaddr_in));
1152 if (1 != inet_pton (AF_INET, bind4_address, &plugin->server_addr_v4->sin_addr)) 1203 if (1 !=
1204 inet_pton (AF_INET, bind4_address, &plugin->server_addr_v4->sin_addr))
1153 { 1205 {
1154 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, 1206 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
1155 _("Specific IPv4 address `%s' for plugin %s in configuration file is invalid! Binding to all addresses!\n"), 1207 _
1156 bind4_address, plugin->protocol); 1208 ("Specific IPv4 address `%s' for plugin %s in configuration file is invalid! Binding to all addresses!\n"),
1209 bind4_address, plugin->protocol);
1157 GNUNET_free (plugin->server_addr_v4); 1210 GNUNET_free (plugin->server_addr_v4);
1158 plugin->server_addr_v4 = NULL; 1211 plugin->server_addr_v4 = NULL;
1159 } 1212 }
@@ -1166,20 +1219,24 @@ configure_plugin (struct Plugin *plugin)
1166 } 1219 }
1167 1220
1168 1221
1169 char * bind6_address = NULL; 1222 char *bind6_address = NULL;
1170 if ((plugin->ipv6 == GNUNET_YES) && (GNUNET_YES == 1223
1171 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name, 1224 if ((plugin->ipv6 == GNUNET_YES) &&
1172 "BINDTO6", &bind6_address))) 1225 (GNUNET_YES ==
1226 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name,
1227 "BINDTO6", &bind6_address)))
1173 { 1228 {
1174 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1229 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1175 "Binding %s plugin to specific IPv6 address: `%s'\n", 1230 "Binding %s plugin to specific IPv6 address: `%s'\n",
1176 plugin->protocol, bind6_address); 1231 plugin->protocol, bind6_address);
1177 plugin->server_addr_v6 = GNUNET_malloc (sizeof (struct sockaddr_in6)); 1232 plugin->server_addr_v6 = GNUNET_malloc (sizeof (struct sockaddr_in6));
1178 if (1 != inet_pton (AF_INET6, bind6_address, &plugin->server_addr_v6->sin6_addr)) 1233 if (1 !=
1234 inet_pton (AF_INET6, bind6_address, &plugin->server_addr_v6->sin6_addr))
1179 { 1235 {
1180 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, 1236 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
1181 _("Specific IPv6 address `%s' for plugin %s in configuration file is invalid! Binding to all addresses!\n"), 1237 _
1182 bind6_address, plugin->protocol); 1238 ("Specific IPv6 address `%s' for plugin %s in configuration file is invalid! Binding to all addresses!\n"),
1239 bind6_address, plugin->protocol);
1183 GNUNET_free (plugin->server_addr_v6); 1240 GNUNET_free (plugin->server_addr_v6);
1184 plugin->server_addr_v6 = NULL; 1241 plugin->server_addr_v6 = NULL;
1185 } 1242 }
@@ -1194,6 +1251,7 @@ configure_plugin (struct Plugin *plugin)
1194 1251
1195 /* Optional parameters */ 1252 /* Optional parameters */
1196 unsigned long long maxneigh; 1253 unsigned long long maxneigh;
1254
1197 if (GNUNET_OK != 1255 if (GNUNET_OK !=
1198 GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, plugin->name, 1256 GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, plugin->name,
1199 "MAX_CONNECTIONS", &maxneigh)) 1257 "MAX_CONNECTIONS", &maxneigh))
@@ -1303,8 +1361,8 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
1303 while (s != NULL) 1361 while (s != NULL)
1304 { 1362 {
1305#if DEBUG_HTTP 1363#if DEBUG_HTTP
1306 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1364 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1307 "Disconnecting `%s' \n", GNUNET_i2s (&s->target)); 1365 "Disconnecting `%s' \n", GNUNET_i2s (&s->target));
1308#endif 1366#endif
1309 if (s->inbound == GNUNET_NO) 1367 if (s->inbound == GNUNET_NO)
1310 GNUNET_assert (GNUNET_OK == client_disconnect (s)); 1368 GNUNET_assert (GNUNET_OK == client_disconnect (s));
@@ -1314,15 +1372,13 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
1314 } 1372 }
1315 1373
1316#if DEBUG_HTTP 1374#if DEBUG_HTTP
1317 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1375 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Stopping server\n");
1318 "Stopping server\n");
1319#endif 1376#endif
1320 /* Stop server */ 1377 /* Stop server */
1321 server_stop (plugin); 1378 server_stop (plugin);
1322 1379
1323#if DEBUG_HTTP 1380#if DEBUG_HTTP
1324 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1381 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Stopping client\n");
1325 "Stopping client\n");
1326#endif 1382#endif
1327 /* Stop client */ 1383 /* Stop client */
1328 client_stop (plugin); 1384 client_stop (plugin);
@@ -1332,6 +1388,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
1332 while (s != NULL) 1388 while (s != NULL)
1333 { 1389 {
1334 struct Session *t = s->next; 1390 struct Session *t = s->next;
1391
1335 GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s); 1392 GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
1336 delete_session (s); 1393 delete_session (s);
1337 s = t; 1394 s = t;
diff --git a/src/transport/plugin_transport_http.h b/src/transport/plugin_transport_http.h
index dd0bc4b9d..7ace96cb6 100644
--- a/src/transport/plugin_transport_http.h
+++ b/src/transport/plugin_transport_http.h
@@ -228,12 +228,12 @@ struct Plugin
228 /** 228 /**
229 * IPv4 server socket to bind to 229 * IPv4 server socket to bind to
230 */ 230 */
231 struct sockaddr_in * server_addr_v4; 231 struct sockaddr_in *server_addr_v4;
232 232
233 /** 233 /**
234 * IPv6 server socket to bind to 234 * IPv6 server socket to bind to
235 */ 235 */
236 struct sockaddr_in6 * server_addr_v6; 236 struct sockaddr_in6 *server_addr_v6;
237 237
238 /** 238 /**
239 * Server semi connections 239 * Server semi connections
@@ -455,11 +455,10 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
455 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls); 455 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls);
456 456
457struct GNUNET_TIME_Relative 457struct GNUNET_TIME_Relative
458http_plugin_receive (void *cls, const struct GNUNET_PeerIdentity * peer, 458http_plugin_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
459 const struct GNUNET_MessageHeader * message, 459 const struct GNUNET_MessageHeader *message,
460 struct Session * session, 460 struct Session *session, const char *sender_address,
461 const char *sender_address, 461 uint16_t sender_address_len);
462 uint16_t sender_address_len);
463 462
464const char * 463const char *
465http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen); 464http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen);
@@ -483,7 +482,7 @@ int
483server_disconnect (struct Session *s); 482server_disconnect (struct Session *s);
484 483
485int 484int
486server_send (struct Session *s, struct HTTP_Message * msg); 485server_send (struct Session *s, struct HTTP_Message *msg);
487 486
488int 487int
489server_start (struct Plugin *plugin); 488server_start (struct Plugin *plugin);
@@ -492,8 +491,7 @@ void
492server_stop (struct Plugin *plugin); 491server_stop (struct Plugin *plugin);
493 492
494void 493void
495notify_session_end (void *cls, 494notify_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
496 const struct GNUNET_PeerIdentity * 495 struct Session *s);
497 peer, struct Session * s);
498 496
499/* end of plugin_transport_http.h */ 497/* end of plugin_transport_http.h */
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c
index a2024953c..62be281ab 100644
--- a/src/transport/plugin_transport_http_client.c
+++ b/src/transport/plugin_transport_http_client.c
@@ -52,11 +52,11 @@ client_log (CURL * curl, curl_infotype type, char *data, size_t size, void *cls)
52 text[size + 1] = '\0'; 52 text[size + 1] = '\0';
53 } 53 }
54#if BUILD_HTTPS 54#if BUILD_HTTPS
55 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 55 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-https",
56 "transport-https", "Client: %X - %s", cls, text); 56 "Client: %X - %s", cls, text);
57#else 57#else
58 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 58 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-http",
59 "transport-http", "Client: %X - %s", cls, text); 59 "Client: %X - %s", cls, text);
60#endif 60#endif
61 } 61 }
62 return 0; 62 return 0;
@@ -91,7 +91,7 @@ client_schedule (struct Plugin *plugin, int now)
91 struct GNUNET_TIME_Relative timeout; 91 struct GNUNET_TIME_Relative timeout;
92 92
93 /* Cancel previous scheduled task */ 93 /* Cancel previous scheduled task */
94 if (plugin->client_perform_task!= GNUNET_SCHEDULER_NO_TASK) 94 if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK)
95 { 95 {
96 GNUNET_SCHEDULER_cancel (plugin->client_perform_task); 96 GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
97 plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK; 97 plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK;
@@ -132,12 +132,8 @@ client_schedule (struct Plugin *plugin, int now)
132 132
133 plugin->client_perform_task = 133 plugin->client_perform_task =
134 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 134 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
135 GNUNET_SCHEDULER_NO_TASK, 135 GNUNET_SCHEDULER_NO_TASK, timeout, grs, gws,
136 timeout, 136 &client_run, plugin);
137 grs,
138 gws,
139 &client_run,
140 plugin);
141 GNUNET_NETWORK_fdset_destroy (gws); 137 GNUNET_NETWORK_fdset_destroy (gws);
142 GNUNET_NETWORK_fdset_destroy (grs); 138 GNUNET_NETWORK_fdset_destroy (grs);
143 return GNUNET_OK; 139 return GNUNET_OK;
@@ -153,10 +149,10 @@ client_send (struct Session *s, struct HTTP_Message *msg)
153 { 149 {
154#if VERBOSE_CLIENT 150#if VERBOSE_CLIENT
155 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, 151 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name,
156 "Client: %X was suspended, unpausing\n", s->client_put); 152 "Client: %X was suspended, unpausing\n", s->client_put);
157#endif 153#endif
158 s->client_put_paused = GNUNET_NO; 154 s->client_put_paused = GNUNET_NO;
159 curl_easy_pause(s->client_put, CURLPAUSE_CONT); 155 curl_easy_pause (s->client_put, CURLPAUSE_CONT);
160 } 156 }
161 157
162 client_schedule (s->plugin, GNUNET_YES); 158 client_schedule (s->plugin, GNUNET_YES);
@@ -189,43 +185,45 @@ client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
189 running = 0; 185 running = 0;
190 mret = curl_multi_perform (plugin->client_mh, &running); 186 mret = curl_multi_perform (plugin->client_mh, &running);
191 187
192 CURLMsg * msg; 188 CURLMsg *msg;
193 int msgs_left; 189 int msgs_left;
194 while ((msg = curl_multi_info_read(plugin->client_mh, &msgs_left))) 190
191 while ((msg = curl_multi_info_read (plugin->client_mh, &msgs_left)))
195 { 192 {
196 CURL *easy_h = msg->easy_handle; 193 CURL *easy_h = msg->easy_handle;
197 struct Session *s = NULL; 194 struct Session *s = NULL;
198 char * d = (char *) s; 195 char *d = (char *) s;
199 196
200 197
201 //GNUNET_assert (easy_h != NULL); 198 //GNUNET_assert (easy_h != NULL);
202 if (easy_h == NULL) 199 if (easy_h == NULL)
203 { 200 {
204 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 201 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
205 "Client: connection to ended with reason %i: `%s', %i handles running\n", 202 "Client: connection to ended with reason %i: `%s', %i handles running\n",
206 msg->data.result, 203 msg->data.result,
207 curl_easy_strerror(msg->data.result), 204 curl_easy_strerror (msg->data.result), running);
208 running); 205 continue;
209 continue; 206 }
210 } 207
211 208 GNUNET_assert (CURLE_OK ==
212 GNUNET_assert (CURLE_OK == curl_easy_getinfo(easy_h, CURLINFO_PRIVATE, &d)); 209 curl_easy_getinfo (easy_h, CURLINFO_PRIVATE, &d));
213 s = (struct Session *) d; 210 s = (struct Session *) d;
214 GNUNET_assert (s != NULL); 211 GNUNET_assert (s != NULL);
215 212
216 if (msg->msg == CURLMSG_DONE) 213 if (msg->msg == CURLMSG_DONE)
217 { 214 {
218 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 215 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
219 "Client: %X connection to '%s' %s ended with reason %i: `%s'\n", 216 "Client: %X connection to '%s' %s ended with reason %i: `%s'\n",
220 msg->easy_handle, GNUNET_i2s(&s->target), 217 msg->easy_handle, GNUNET_i2s (&s->target),
221 http_plugin_address_to_string (NULL, s->addr, s->addrlen), 218 http_plugin_address_to_string (NULL, s->addr,
222 msg->data.result, 219 s->addrlen),
223 curl_easy_strerror(msg->data.result)); 220 msg->data.result,
224 221 curl_easy_strerror (msg->data.result));
225 client_disconnect(s); 222
226 //GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,"Notifying about ended session to peer `%s' `%s'\n", GNUNET_i2s (&s->target), http_plugin_address_to_string (plugin, s->addr, s->addrlen)); 223 client_disconnect (s);
227 notify_session_end (plugin, &s->target, s); 224 //GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,"Notifying about ended session to peer `%s' `%s'\n", GNUNET_i2s (&s->target), http_plugin_address_to_string (plugin, s->addr, s->addrlen));
228 } 225 notify_session_end (plugin, &s->target, s);
226 }
229 } 227 }
230 } 228 }
231 while (mret == CURLM_CALL_MULTI_PERFORM); 229 while (mret == CURLM_CALL_MULTI_PERFORM);
@@ -238,18 +236,17 @@ client_disconnect (struct Session *s)
238 int res = GNUNET_OK; 236 int res = GNUNET_OK;
239 CURLMcode mret; 237 CURLMcode mret;
240 struct Plugin *plugin = s->plugin; 238 struct Plugin *plugin = s->plugin;
241 struct HTTP_Message * msg; 239 struct HTTP_Message *msg;
242 struct HTTP_Message * t; 240 struct HTTP_Message *t;
243 241
244 242
245 243
246 if (s->client_put != NULL) 244 if (s->client_put != NULL)
247 { 245 {
248#if DEBUG_HTTP 246#if DEBUG_HTTP
249 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 247 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
250 "Client: %X Deleting outbound PUT session to peer `%s'\n", 248 "Client: %X Deleting outbound PUT session to peer `%s'\n",
251 s->client_put, 249 s->client_put, GNUNET_i2s (&s->target));
252 GNUNET_i2s (&s->target));
253#endif 250#endif
254 251
255 mret = curl_multi_remove_handle (plugin->client_mh, s->client_put); 252 mret = curl_multi_remove_handle (plugin->client_mh, s->client_put);
@@ -266,17 +263,16 @@ client_disconnect (struct Session *s)
266 263
267 if (s->recv_wakeup_task != GNUNET_SCHEDULER_NO_TASK) 264 if (s->recv_wakeup_task != GNUNET_SCHEDULER_NO_TASK)
268 { 265 {
269 GNUNET_SCHEDULER_cancel (s->recv_wakeup_task); 266 GNUNET_SCHEDULER_cancel (s->recv_wakeup_task);
270 s->recv_wakeup_task = GNUNET_SCHEDULER_NO_TASK; 267 s->recv_wakeup_task = GNUNET_SCHEDULER_NO_TASK;
271 } 268 }
272 269
273 if (s->client_get != NULL) 270 if (s->client_get != NULL)
274 { 271 {
275#if DEBUG_HTTP 272#if DEBUG_HTTP
276 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 273 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
277 "Client: %X Deleting outbound GET session to peer `%s'\n", 274 "Client: %X Deleting outbound GET session to peer `%s'\n",
278 s->client_get, 275 s->client_get, GNUNET_i2s (&s->target));
279 GNUNET_i2s (&s->target));
280#endif 276#endif
281 277
282 mret = curl_multi_remove_handle (plugin->client_mh, s->client_get); 278 mret = curl_multi_remove_handle (plugin->client_mh, s->client_get);
@@ -296,7 +292,7 @@ client_disconnect (struct Session *s)
296 t = msg->next; 292 t = msg->next;
297 if (NULL != msg->transmit_cont) 293 if (NULL != msg->transmit_cont)
298 msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_SYSERR); 294 msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_SYSERR);
299 GNUNET_CONTAINER_DLL_remove(s->msg_head, s->msg_tail, msg); 295 GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
300 GNUNET_free (msg); 296 GNUNET_free (msg);
301 msg = t; 297 msg = t;
302 } 298 }
@@ -316,24 +312,28 @@ client_disconnect (struct Session *s)
316 312
317static void 313static void
318client_receive_mst_cb (void *cls, void *client, 314client_receive_mst_cb (void *cls, void *client,
319 const struct GNUNET_MessageHeader *message) 315 const struct GNUNET_MessageHeader *message)
320{ 316{
321 struct Session *s = cls; 317 struct Session *s = cls;
322 struct GNUNET_TIME_Relative delay; 318 struct GNUNET_TIME_Relative delay;
323 319
324 delay = http_plugin_receive (s, &s->target, message, s, s->addr, s->addrlen); 320 delay = http_plugin_receive (s, &s->target, message, s, s->addr, s->addrlen);
325 s->next_receive = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), delay); 321 s->next_receive =
322 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), delay);
326 323
327 if (GNUNET_TIME_absolute_get().abs_value < s->next_receive.abs_value) 324 if (GNUNET_TIME_absolute_get ().abs_value < s->next_receive.abs_value)
328 { 325 {
329#if VERBOSE_CLIENT 326#if VERBOSE_CLIENT
330 struct Plugin *plugin = s->plugin; 327 struct Plugin *plugin = s->plugin;
328
331 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 329 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
332 "Client: peer `%s' address `%s' next read delayed for %llu ms\n", 330 "Client: peer `%s' address `%s' next read delayed for %llu ms\n",
333 GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen), delay); 331 GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen),
332 delay);
334#endif 333#endif
335 } 334 }
336} 335}
336
337static void 337static void
338client_wake_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 338client_wake_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
339{ 339{
@@ -345,11 +345,10 @@ client_wake_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
345 return; 345 return;
346 346
347 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, 347 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name,
348 "Client: %X Waking up receive handle\n", 348 "Client: %X Waking up receive handle\n", s->client_get);
349 s->client_get);
350 349
351 if (s->client_get != NULL) 350 if (s->client_get != NULL)
352 curl_easy_pause(s->client_get, CURLPAUSE_CONT); 351 curl_easy_pause (s->client_get, CURLPAUSE_CONT);
353 352
354} 353}
355 354
@@ -372,37 +371,38 @@ client_receive (void *stream, size_t size, size_t nmemb, void *cls)
372 371
373#if VERBOSE_CLIENT 372#if VERBOSE_CLIENT
374 struct Plugin *plugin = s->plugin; 373 struct Plugin *plugin = s->plugin;
374
375 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 375 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
376 "Client: Received %Zu bytes from peer `%s'\n", 376 "Client: Received %Zu bytes from peer `%s'\n", len,
377 len,
378 GNUNET_i2s (&s->target)); 377 GNUNET_i2s (&s->target));
379#endif 378#endif
380 379
381 now = GNUNET_TIME_absolute_get(); 380 now = GNUNET_TIME_absolute_get ();
382 if (now.abs_value < s->next_receive.abs_value) 381 if (now.abs_value < s->next_receive.abs_value)
383 { 382 {
384 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); 383 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
385 struct GNUNET_TIME_Relative delta = GNUNET_TIME_absolute_get_difference(now, s->next_receive); 384 struct GNUNET_TIME_Relative delta =
385 GNUNET_TIME_absolute_get_difference (now, s->next_receive);
386#if DEBUG_CLIENT 386#if DEBUG_CLIENT
387 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 387 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
388 "Client: %X No inbound bandwidth available! Next read was delayed for %llu ms\n", 388 "Client: %X No inbound bandwidth available! Next read was delayed for %llu ms\n",
389 s->client_get, delta.rel_value); 389 s->client_get, delta.rel_value);
390#endif 390#endif
391 if (s->recv_wakeup_task != GNUNET_SCHEDULER_NO_TASK) 391 if (s->recv_wakeup_task != GNUNET_SCHEDULER_NO_TASK)
392 { 392 {
393 GNUNET_SCHEDULER_cancel (s->recv_wakeup_task); 393 GNUNET_SCHEDULER_cancel (s->recv_wakeup_task);
394 s->recv_wakeup_task = GNUNET_SCHEDULER_NO_TASK; 394 s->recv_wakeup_task = GNUNET_SCHEDULER_NO_TASK;
395 } 395 }
396 s->recv_wakeup_task = GNUNET_SCHEDULER_add_delayed (delta, &client_wake_up, s); 396 s->recv_wakeup_task =
397 GNUNET_SCHEDULER_add_delayed (delta, &client_wake_up, s);
397 return CURLPAUSE_ALL; 398 return CURLPAUSE_ALL;
398 } 399 }
399 400
400 401
401 if (s->msg_tk == NULL) 402 if (s->msg_tk == NULL)
402 s->msg_tk = GNUNET_SERVER_mst_create (&client_receive_mst_cb, s); 403 s->msg_tk = GNUNET_SERVER_mst_create (&client_receive_mst_cb, s);
403 404
404 GNUNET_SERVER_mst_receive (s->msg_tk, s, stream, len, GNUNET_NO, 405 GNUNET_SERVER_mst_receive (s->msg_tk, s, stream, len, GNUNET_NO, GNUNET_NO);
405 GNUNET_NO);
406 406
407 return len; 407 return len;
408} 408}
@@ -420,6 +420,7 @@ static size_t
420client_send_cb (void *stream, size_t size, size_t nmemb, void *cls) 420client_send_cb (void *stream, size_t size, size_t nmemb, void *cls)
421{ 421{
422 struct Session *s = cls; 422 struct Session *s = cls;
423
423#if VERBOSE_CLIENT 424#if VERBOSE_CLIENT
424 struct Plugin *plugin = s->plugin; 425 struct Plugin *plugin = s->plugin;
425#endif 426#endif
@@ -432,7 +433,8 @@ client_send_cb (void *stream, size_t size, size_t nmemb, void *cls)
432 { 433 {
433#if VERBOSE_CLIENT 434#if VERBOSE_CLIENT
434 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 435 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
435 "Client: %X Nothing to send! Suspending PUT handle!\n", s->client_put); 436 "Client: %X Nothing to send! Suspending PUT handle!\n",
437 s->client_put);
436#endif 438#endif
437 s->client_put_paused = GNUNET_YES; 439 s->client_put_paused = GNUNET_YES;
438 return CURL_READFUNC_PAUSE; 440 return CURL_READFUNC_PAUSE;
@@ -469,13 +471,13 @@ client_send_cb (void *stream, size_t size, size_t nmemb, void *cls)
469 { 471 {
470#if VERBOSE_CLIENT 472#if VERBOSE_CLIENT
471 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 473 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
472 "Client: %X Message with %u bytes sent, removing message from queue\n", 474 "Client: %X Message with %u bytes sent, removing message from queue\n",
473 s->client_put, msg->size, msg->pos); 475 s->client_put, msg->size, msg->pos);
474#endif 476#endif
475 /* Calling transmit continuation */ 477 /* Calling transmit continuation */
476 if (NULL != msg->transmit_cont) 478 if (NULL != msg->transmit_cont)
477 msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK); 479 msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK);
478 GNUNET_CONTAINER_DLL_remove(s->msg_head, s->msg_tail, msg); 480 GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
479 GNUNET_free (msg); 481 GNUNET_free (msg);
480 } 482 }
481 return bytes_sent; 483 return bytes_sent;
@@ -500,12 +502,11 @@ client_connect (struct Session *s)
500 plugin->last_tag++; 502 plugin->last_tag++;
501 /* create url */ 503 /* create url */
502 GNUNET_asprintf (&url, "%s%s;%u", 504 GNUNET_asprintf (&url, "%s%s;%u",
503 http_plugin_address_to_string (plugin, s->addr, s->addrlen), 505 http_plugin_address_to_string (plugin, s->addr, s->addrlen),
504 GNUNET_h2s_full (&plugin->env->my_identity->hashPubKey),plugin->last_tag); 506 GNUNET_h2s_full (&plugin->env->my_identity->hashPubKey),
507 plugin->last_tag);
505#if 0 508#if 0
506 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 509 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "URL `%s'\n", url);
507 "URL `%s'\n",
508 url);
509#endif 510#endif
510 /* create get connection */ 511 /* create get connection */
511 s->client_get = curl_easy_init (); 512 s->client_get = curl_easy_init ();
@@ -592,7 +593,7 @@ client_connect (struct Session *s)
592 plugin->cur_connections += 2; 593 plugin->cur_connections += 2;
593 594
594 /* Re-schedule since handles have changed */ 595 /* Re-schedule since handles have changed */
595 if (plugin->client_perform_task!= GNUNET_SCHEDULER_NO_TASK) 596 if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK)
596 { 597 {
597 GNUNET_SCHEDULER_cancel (plugin->client_perform_task); 598 GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
598 plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK; 599 plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK;
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c
index e5b20cfb4..48c8739d5 100644
--- a/src/transport/plugin_transport_http_server.c
+++ b/src/transport/plugin_transport_http_server.c
@@ -39,7 +39,7 @@ struct ServerConnection
39 int disconnect; 39 int disconnect;
40 40
41 struct Session *session; 41 struct Session *session;
42 struct MHD_Connection * mhd_conn; 42 struct MHD_Connection *mhd_conn;
43}; 43};
44 44
45/** 45/**
@@ -50,7 +50,8 @@ struct ServerConnection
50 * @return gnunet task identifier 50 * @return gnunet task identifier
51 */ 51 */
52static GNUNET_SCHEDULER_TaskIdentifier 52static GNUNET_SCHEDULER_TaskIdentifier
53server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle, int now); 53server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle,
54 int now);
54 55
55static void 56static void
56server_log (void *arg, const char *fmt, va_list ap) 57server_log (void *arg, const char *fmt, va_list ap)
@@ -74,13 +75,14 @@ server_log (void *arg, const char *fmt, va_list ap)
74static int 75static int
75server_accept_cb (void *cls, const struct sockaddr *addr, socklen_t addr_len) 76server_accept_cb (void *cls, const struct sockaddr *addr, socklen_t addr_len)
76{ 77{
77 struct Plugin * plugin = cls; 78 struct Plugin *plugin = cls;
78 79
79 if (plugin->cur_connections <= plugin->max_connections) 80 if (plugin->cur_connections <= plugin->max_connections)
80 return MHD_YES; 81 return MHD_YES;
81 else 82 else
82 { 83 {
83 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Server: Cannot accept new connections\n"); 84 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
85 "Server: Cannot accept new connections\n");
84 return MHD_NO; 86 return MHD_NO;
85 } 87 }
86} 88}
@@ -131,8 +133,11 @@ server_load_certificate (struct Plugin *plugin)
131 /* Get crypto init string from config 133 /* Get crypto init string from config
132 * If not present just use default values */ 134 * If not present just use default values */
133 135
134 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name, 136 GNUNET_assert (GNUNET_OK ==
135 "CRYPTO_INIT", &plugin->crypto_init)); 137 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
138 plugin->name,
139 "CRYPTO_INIT",
140 &plugin->crypto_init));
136 141
137 if (GNUNET_OK != 142 if (GNUNET_OK !=
138 GNUNET_CONFIGURATION_get_value_filename (plugin->env->cfg, plugin->name, 143 GNUNET_CONFIGURATION_get_value_filename (plugin->env->cfg, plugin->name,
@@ -145,7 +150,7 @@ server_load_certificate (struct Plugin *plugin)
145 GNUNET_CONFIGURATION_get_value_filename (plugin->env->cfg, plugin->name, 150 GNUNET_CONFIGURATION_get_value_filename (plugin->env->cfg, plugin->name,
146 "CERT_FILE", &cert_file)) 151 "CERT_FILE", &cert_file))
147 { 152 {
148 GNUNET_asprintf(&cert_file, "%s", "https_cert.crt"); 153 GNUNET_asprintf (&cert_file, "%s", "https_cert.crt");
149 } 154 }
150 155
151 /* read key & certificates from file */ 156 /* read key & certificates from file */
@@ -244,7 +249,7 @@ server_reschedule (struct Plugin *plugin, int now)
244 { 249 {
245 if (plugin->server_v4_task != GNUNET_SCHEDULER_NO_TASK) 250 if (plugin->server_v4_task != GNUNET_SCHEDULER_NO_TASK)
246 { 251 {
247 GNUNET_SCHEDULER_cancel(plugin->server_v4_task); 252 GNUNET_SCHEDULER_cancel (plugin->server_v4_task);
248 plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK; 253 plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK;
249 } 254 }
250 plugin->server_v4_task = server_schedule (plugin, plugin->server_v4, now); 255 plugin->server_v4_task = server_schedule (plugin, plugin->server_v4, now);
@@ -252,12 +257,12 @@ server_reschedule (struct Plugin *plugin, int now)
252 257
253 if (plugin->server_v6 != NULL) 258 if (plugin->server_v6 != NULL)
254 { 259 {
255 if (plugin->server_v6_task != GNUNET_SCHEDULER_NO_TASK) 260 if (plugin->server_v6_task != GNUNET_SCHEDULER_NO_TASK)
256 { 261 {
257 GNUNET_SCHEDULER_cancel(plugin->server_v6_task); 262 GNUNET_SCHEDULER_cancel (plugin->server_v6_task);
258 plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK; 263 plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK;
259 } 264 }
260 plugin->server_v6_task = server_schedule (plugin, plugin->server_v6, now); 265 plugin->server_v6_task = server_schedule (plugin, plugin->server_v6, now);
261 } 266 }
262} 267}
263 268
@@ -269,9 +274,10 @@ server_reschedule (struct Plugin *plugin, int now)
269 */ 274 */
270static void 275static void
271server_receive_mst_cb (void *cls, void *client, 276server_receive_mst_cb (void *cls, void *client,
272 const struct GNUNET_MessageHeader *message) 277 const struct GNUNET_MessageHeader *message)
273{ 278{
274 struct Session *s = cls; 279 struct Session *s = cls;
280
275#if VERBOSE_SERVER 281#if VERBOSE_SERVER
276 struct Plugin *plugin = s->plugin; 282 struct Plugin *plugin = s->plugin;
277#endif 283#endif
@@ -279,13 +285,16 @@ server_receive_mst_cb (void *cls, void *client,
279 285
280 delay = http_plugin_receive (s, &s->target, message, s, s->addr, s->addrlen); 286 delay = http_plugin_receive (s, &s->target, message, s, s->addr, s->addrlen);
281 287
282 s->next_receive = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), delay); 288 s->next_receive =
289 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), delay);
283 290
284 if (delay.rel_value > 0) 291 if (delay.rel_value > 0)
285 { 292 {
286#if VERBOSE_CLIENT 293#if VERBOSE_CLIENT
287 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Server: peer `%s' address `%s' next read delayed for %llu ms\n", 294 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
288 GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen), delay); 295 "Server: peer `%s' address `%s' next read delayed for %llu ms\n",
296 GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen),
297 delay);
289#endif 298#endif
290 } 299 }
291} 300}
@@ -305,6 +314,7 @@ server_send_callback (void *cls, uint64_t pos, char *buf, size_t max)
305 314
306 struct HTTP_Message *msg; 315 struct HTTP_Message *msg;
307 int bytes_read = 0; 316 int bytes_read = 0;
317
308 //static int c = 0; 318 //static int c = 0;
309 msg = s->msg_head; 319 msg = s->msg_head;
310 if (msg != NULL) 320 if (msg != NULL)
@@ -328,54 +338,58 @@ server_send_callback (void *cls, uint64_t pos, char *buf, size_t max)
328 { 338 {
329 if (NULL != msg->transmit_cont) 339 if (NULL != msg->transmit_cont)
330 msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK); 340 msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK);
331 GNUNET_CONTAINER_DLL_remove(s->msg_head, s->msg_tail, msg); 341 GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
332 GNUNET_free (msg); 342 GNUNET_free (msg);
333 } 343 }
334 } 344 }
335 345
336#if VERBOSE_CLIENT 346#if VERBOSE_CLIENT
337 struct Plugin *plugin = s->plugin; 347 struct Plugin *plugin = s->plugin;
348
338 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 349 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
339 "Server: %X: sent %u bytes\n", 350 "Server: %X: sent %u bytes\n", s, bytes_read);
340 s, bytes_read);
341#endif 351#endif
342 return bytes_read; 352 return bytes_read;
343} 353}
344 354
345static struct ServerConnection * 355static struct ServerConnection *
346server_lookup_session (struct Plugin *plugin, 356server_lookup_session (struct Plugin *plugin,
347 struct MHD_Connection *mhd_connection, 357 struct MHD_Connection *mhd_connection, const char *url,
348 const char * url, 358 const char *method)
349 const char *method)
350{ 359{
351 struct Session *s = NULL; 360 struct Session *s = NULL;
352 struct Session * t; 361 struct Session *t;
353 struct ServerConnection *sc = NULL; 362 struct ServerConnection *sc = NULL;
354 const union MHD_ConnectionInfo *conn_info; 363 const union MHD_ConnectionInfo *conn_info;
355 364
356 struct IPv4HttpAddress a4; 365 struct IPv4HttpAddress a4;
357 struct IPv6HttpAddress a6; 366 struct IPv6HttpAddress a6;
358 struct sockaddr_in * s4; 367 struct sockaddr_in *s4;
359 struct sockaddr_in6 * s6; 368 struct sockaddr_in6 *s6;
360 void * a; 369 void *a;
361 size_t a_len; 370 size_t a_len;
362 struct GNUNET_PeerIdentity target; 371 struct GNUNET_PeerIdentity target;
363 int check = GNUNET_NO; 372 int check = GNUNET_NO;
364 uint32_t tag = 0; 373 uint32_t tag = 0;
365 int direction; 374 int direction;
366 375
367 conn_info = MHD_get_connection_info (mhd_connection, MHD_CONNECTION_INFO_CLIENT_ADDRESS); 376 conn_info =
368 if ((conn_info->client_addr->sa_family != AF_INET) && (conn_info->client_addr->sa_family != AF_INET6)) 377 MHD_get_connection_info (mhd_connection,
378 MHD_CONNECTION_INFO_CLIENT_ADDRESS);
379 if ((conn_info->client_addr->sa_family != AF_INET) &&
380 (conn_info->client_addr->sa_family != AF_INET6))
369 return MHD_NO; 381 return MHD_NO;
370 382
371 if ((strlen(&url[1]) >= 105) && (url[104] == ';')) 383 if ((strlen (&url[1]) >= 105) && (url[104] == ';'))
372 { 384 {
373 char hash[104]; 385 char hash[104];
374 char * tagc = (char *) &url[105]; 386 char *tagc = (char *) &url[105];
375 memcpy(&hash, &url[1], 103); 387
376 hash [103] = '\0'; 388 memcpy (&hash, &url[1], 103);
377 if (GNUNET_OK == GNUNET_CRYPTO_hash_from_string ((const char *) &hash, 389 hash[103] = '\0';
378 &(target.hashPubKey))) 390 if (GNUNET_OK ==
391 GNUNET_CRYPTO_hash_from_string ((const char *) &hash,
392 &(target.hashPubKey)))
379 { 393 {
380 tag = strtoul (tagc, NULL, 10); 394 tag = strtoul (tagc, NULL, 10);
381 if (tagc > 0) 395 if (tagc > 0)
@@ -395,7 +409,8 @@ server_lookup_session (struct Plugin *plugin,
395 409
396#if VERBOSE_SERVER 410#if VERBOSE_SERVER
397 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 411 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
398 "Server: New inbound connection from %s with tag %u\n", GNUNET_i2s(&target), tag); 412 "Server: New inbound connection from %s with tag %u\n",
413 GNUNET_i2s (&target), tag);
399#endif 414#endif
400 /* find duplicate session */ 415 /* find duplicate session */
401 416
@@ -403,17 +418,20 @@ server_lookup_session (struct Plugin *plugin,
403 418
404 while (t != NULL) 419 while (t != NULL)
405 { 420 {
406 if ((t->inbound) && (0 == memcmp (&t->target, &target, sizeof (struct GNUNET_PeerIdentity))) && 421 if ((t->inbound) &&
422 (0 == memcmp (&t->target, &target, sizeof (struct GNUNET_PeerIdentity)))
423 &&
407 /* FIXME add source address comparison */ 424 /* FIXME add source address comparison */
408 (t->tag == tag)) 425 (t->tag == tag))
409 break; 426 break;
410 t = t->next; 427 t = t->next;
411 } 428 }
412 if (t != NULL) 429 if (t != NULL)
413 { 430 {
414#if VERBOSE_SERVER 431#if VERBOSE_SERVER
415 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 432 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
416 "Server: Duplicate session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target)); 433 "Server: Duplicate session, dismissing new connection from peer `%s'\n",
434 GNUNET_i2s (&target));
417#endif 435#endif
418 goto error; 436 goto error;
419 } 437 }
@@ -424,8 +442,8 @@ server_lookup_session (struct Plugin *plugin,
424 while (t != NULL) 442 while (t != NULL)
425 { 443 {
426 /* FIXME add source address comparison */ 444 /* FIXME add source address comparison */
427 if ((0 == memcmp (&t->target, &target, sizeof (struct GNUNET_PeerIdentity))) && 445 if ((0 == memcmp (&t->target, &target, sizeof (struct GNUNET_PeerIdentity)))
428 (t->tag == tag)) 446 && (t->tag == tag))
429 { 447 {
430 break; 448 break;
431 } 449 }
@@ -437,25 +455,29 @@ server_lookup_session (struct Plugin *plugin,
437 455
438#if VERBOSE_SERVER 456#if VERBOSE_SERVER
439 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 457 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
440 "Server: Found existing semi-session for `%s'\n", GNUNET_i2s (&target)); 458 "Server: Found existing semi-session for `%s'\n",
459 GNUNET_i2s (&target));
441#endif 460#endif
442 461
443 if ((direction == _SEND) && (t->server_send != NULL)) 462 if ((direction == _SEND) && (t->server_send != NULL))
444 { 463 {
445#if VERBOSE_SERVER 464#if VERBOSE_SERVER
446 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 465 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
447 "Server: Duplicate GET session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target)); 466 "Server: Duplicate GET session, dismissing new connection from peer `%s'\n",
467 GNUNET_i2s (&target));
448#endif 468#endif
449 goto error; 469 goto error;
450 } 470 }
451 else 471 else
452 { 472 {
453 s = t; 473 s = t;
454 GNUNET_CONTAINER_DLL_remove(plugin->server_semi_head, plugin->server_semi_tail, s); 474 GNUNET_CONTAINER_DLL_remove (plugin->server_semi_head,
455 GNUNET_CONTAINER_DLL_insert(plugin->head, plugin->tail, s); 475 plugin->server_semi_tail, s);
476 GNUNET_CONTAINER_DLL_insert (plugin->head, plugin->tail, s);
456#if VERBOSE_SERVER 477#if VERBOSE_SERVER
457 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 478 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
458 "Server: Found matching semi-session, merging session for peer `%s'\n", GNUNET_i2s (&target)); 479 "Server: Found matching semi-session, merging session for peer `%s'\n",
480 GNUNET_i2s (&target));
459#endif 481#endif
460 482
461 goto found; 483 goto found;
@@ -464,18 +486,21 @@ server_lookup_session (struct Plugin *plugin,
464 { 486 {
465#if VERBOSE_SERVER 487#if VERBOSE_SERVER
466 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 488 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
467 "Server: Duplicate PUT session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target)); 489 "Server: Duplicate PUT session, dismissing new connection from peer `%s'\n",
490 GNUNET_i2s (&target));
468#endif 491#endif
469 goto error; 492 goto error;
470 } 493 }
471 else 494 else
472 { 495 {
473 s = t; 496 s = t;
474 GNUNET_CONTAINER_DLL_remove(plugin->server_semi_head, plugin->server_semi_tail, s); 497 GNUNET_CONTAINER_DLL_remove (plugin->server_semi_head,
475 GNUNET_CONTAINER_DLL_insert(plugin->head, plugin->tail, s); 498 plugin->server_semi_tail, s);
499 GNUNET_CONTAINER_DLL_insert (plugin->head, plugin->tail, s);
476#if VERBOSE_SERVER 500#if VERBOSE_SERVER
477 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 501 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
478 "Server: Found matching semi-session, merging session for peer `%s'\n", GNUNET_i2s (&target)); 502 "Server: Found matching semi-session, merging session for peer `%s'\n",
503 GNUNET_i2s (&target));
479#endif 504#endif
480 goto found; 505 goto found;
481 } 506 }
@@ -484,53 +509,48 @@ create:
484/* create new session */ 509/* create new session */
485#if VERBOSE_SERVER 510#if VERBOSE_SERVER
486 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 511 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
487 "Server: Creating new session for peer `%s' \n", GNUNET_i2s (&target)); 512 "Server: Creating new session for peer `%s' \n",
513 GNUNET_i2s (&target));
488#endif 514#endif
489 515
490 switch (conn_info->client_addr->sa_family) 516 switch (conn_info->client_addr->sa_family)
491 { 517 {
492 case (AF_INET): 518 case (AF_INET):
493 s4 = ((struct sockaddr_in * ) conn_info->client_addr); 519 s4 = ((struct sockaddr_in *) conn_info->client_addr);
494 a4.u4_port = s4->sin_port; 520 a4.u4_port = s4->sin_port;
495 memcpy (&a4.ipv4_addr, &s4->sin_addr, 521 memcpy (&a4.ipv4_addr, &s4->sin_addr, sizeof (struct in_addr));
496 sizeof (struct in_addr)); 522 a = &a4;
497 a = &a4; 523 a_len = sizeof (struct IPv4HttpAddress);
498 a_len = sizeof (struct IPv4HttpAddress); 524 break;
499 break;
500 case (AF_INET6): 525 case (AF_INET6):
501 s6 = ((struct sockaddr_in6 * ) conn_info->client_addr); 526 s6 = ((struct sockaddr_in6 *) conn_info->client_addr);
502 a6.u6_port = s6->sin6_port; 527 a6.u6_port = s6->sin6_port;
503 memcpy (&a6.ipv6_addr, &s6->sin6_addr, 528 memcpy (&a6.ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr));
504 sizeof (struct in6_addr)); 529 a = &a6;
505 a = &a6; 530 a_len = sizeof (struct IPv6HttpAddress);
506 a_len = sizeof (struct IPv6HttpAddress); 531 break;
507 break;
508 default: 532 default:
509 GNUNET_break (0); 533 GNUNET_break (0);
510 goto error; 534 goto error;
511 } 535 }
512 536
513 s = create_session (plugin, 537 s = create_session (plugin, &target, a, a_len, NULL, NULL);
514 &target,
515 a,
516 a_len,
517 NULL,
518 NULL);
519 538
520 s->inbound = GNUNET_YES; 539 s->inbound = GNUNET_YES;
521 s->next_receive = GNUNET_TIME_absolute_get_zero(); 540 s->next_receive = GNUNET_TIME_absolute_get_zero ();
522 s->tag= tag; 541 s->tag = tag;
523 if (0 == strcmp (MHD_HTTP_METHOD_PUT, method)) 542 if (0 == strcmp (MHD_HTTP_METHOD_PUT, method))
524 s->server_recv = s; 543 s->server_recv = s;
525 if (0 == strcmp (MHD_HTTP_METHOD_GET, method)) 544 if (0 == strcmp (MHD_HTTP_METHOD_GET, method))
526 s->server_send = s; 545 s->server_send = s;
527 GNUNET_CONTAINER_DLL_insert (plugin->server_semi_head, plugin->server_semi_tail, s); 546 GNUNET_CONTAINER_DLL_insert (plugin->server_semi_head,
547 plugin->server_semi_tail, s);
528 goto found; 548 goto found;
529 549
530error: 550error:
531#if VERBOSE_SERVER 551#if VERBOSE_SERVER
532 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 552 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
533 "Server: Invalid connection request\n"); 553 "Server: Invalid connection request\n");
534#endif 554#endif
535 return NULL; 555 return NULL;
536 556
@@ -546,6 +566,7 @@ found:
546 566
547#if MHD_VERSION >= 0x00090E00 567#if MHD_VERSION >= 0x00090E00
548 int to = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000); 568 int to = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000);
569
549#if VERBOSE_SERVER 570#if VERBOSE_SERVER
550 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 571 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
551 "Server: Setting timeout for %X to %u sec.\n", sc, to); 572 "Server: Setting timeout for %X to %u sec.\n", sc, to);
@@ -581,12 +602,14 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
581 /* new connection */ 602 /* new connection */
582 if (sc == NULL) 603 if (sc == NULL)
583 { 604 {
584 sc = server_lookup_session(plugin, mhd_connection, url, method); 605 sc = server_lookup_session (plugin, mhd_connection, url, method);
585 if (sc != NULL) 606 if (sc != NULL)
586 (*httpSessionCache) = sc; 607 (*httpSessionCache) = sc;
587 else 608 else
588 { 609 {
589 response = MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE),HTTP_ERROR_RESPONSE, MHD_NO, MHD_NO); 610 response =
611 MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE),
612 HTTP_ERROR_RESPONSE, MHD_NO, MHD_NO);
590 res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response); 613 res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response);
591 MHD_destroy_response (response); 614 MHD_destroy_response (response);
592 return res; 615 return res;
@@ -597,10 +620,12 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
597 sc = (*httpSessionCache); 620 sc = (*httpSessionCache);
598 s = sc->session; 621 s = sc->session;
599 622
600 /* connection is to be disconnected*/ 623 /* connection is to be disconnected */
601 if (sc->disconnect == GNUNET_YES) 624 if (sc->disconnect == GNUNET_YES)
602 { 625 {
603 response = MHD_create_response_from_data (strlen ("Thank you!"), "Thank you!", MHD_NO, MHD_NO); 626 response =
627 MHD_create_response_from_data (strlen ("Thank you!"), "Thank you!",
628 MHD_NO, MHD_NO);
604 res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); 629 res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
605#if VERBOSE_SERVER 630#if VERBOSE_SERVER
606 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 631 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -613,7 +638,8 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
613 GNUNET_assert (s != NULL); 638 GNUNET_assert (s != NULL);
614 if (sc->direction == _SEND) 639 if (sc->direction == _SEND)
615 { 640 {
616 response = MHD_create_response_from_callback (-1, 32 * 1024, &server_send_callback, 641 response =
642 MHD_create_response_from_callback (-1, 32 * 1024, &server_send_callback,
617 s, NULL); 643 s, NULL);
618 res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); 644 res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
619 MHD_destroy_response (response); 645 MHD_destroy_response (response);
@@ -624,9 +650,10 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
624 if (*upload_data_size == 0) 650 if (*upload_data_size == 0)
625 { 651 {
626#if VERBOSE_SERVER 652#if VERBOSE_SERVER
627 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 653 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
628 "Server: Peer `%s' PUT on address `%s' connected\n", 654 "Server: Peer `%s' PUT on address `%s' connected\n",
629 GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen)); 655 GNUNET_i2s (&s->target), GNUNET_a2s (s->addr,
656 s->addrlen));
630#endif 657#endif
631 return MHD_YES; 658 return MHD_YES;
632 } 659 }
@@ -635,23 +662,28 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
635 if ((*upload_data_size > 0)) 662 if ((*upload_data_size > 0))
636 { 663 {
637#if VERBOSE_SERVER 664#if VERBOSE_SERVER
638 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 665 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
639 "Server: peer `%s' PUT on address `%s' received %Zu bytes\n", 666 "Server: peer `%s' PUT on address `%s' received %Zu bytes\n",
640 GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen), *upload_data_size); 667 GNUNET_i2s (&s->target), GNUNET_a2s (s->addr,
668 s->addrlen),
669 *upload_data_size);
641#endif 670#endif
642 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); 671 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
643 if (( s->next_receive.abs_value <= now.abs_value)) 672
673 if ((s->next_receive.abs_value <= now.abs_value))
644 { 674 {
645#if VERBOSE_SERVER 675#if VERBOSE_SERVER
646 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 676 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
647 "Server: %X: PUT with %u bytes forwarded to MST\n", s, 677 "Server: %X: PUT with %u bytes forwarded to MST\n", s,
648 *upload_data_size); 678 *upload_data_size);
649#endif 679#endif
650 if (s->msg_tk == NULL) 680 if (s->msg_tk == NULL)
651 { 681 {
652 s->msg_tk = GNUNET_SERVER_mst_create (&server_receive_mst_cb, s); 682 s->msg_tk = GNUNET_SERVER_mst_create (&server_receive_mst_cb, s);
653 } 683 }
654 res = GNUNET_SERVER_mst_receive (s->msg_tk, s, upload_data, *upload_data_size, GNUNET_NO, GNUNET_NO); 684 res =
685 GNUNET_SERVER_mst_receive (s->msg_tk, s, upload_data,
686 *upload_data_size, GNUNET_NO, GNUNET_NO);
655 687
656#if MHD_VERSION >= 0x00090E00 688#if MHD_VERSION >= 0x00090E00
657 int to = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000); 689 int to = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000);
@@ -668,18 +700,22 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
668 t = s->server_recv; 700 t = s->server_recv;
669#if VERBOSE_SERVER 701#if VERBOSE_SERVER
670 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 702 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
671 "Server: Setting timeout for %X to %u sec.\n", t, to); 703 "Server: Setting timeout for %X to %u sec.\n", t,
704 to);
672#endif 705#endif
673 MHD_set_connection_option (t->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, to); 706 MHD_set_connection_option (t->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT,
707 to);
674 } 708 }
675 if (s->server_send != NULL) 709 if (s->server_send != NULL)
676 { 710 {
677 t = s->server_send; 711 t = s->server_send;
678#if VERBOSE_SERVER 712#if VERBOSE_SERVER
679 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 713 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
680 "Server: Setting timeout for %X to %u sec.\n", t, to); 714 "Server: Setting timeout for %X to %u sec.\n", t,
715 to);
681#endif 716#endif
682 MHD_set_connection_option (t->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, to); 717 MHD_set_connection_option (t->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT,
718 to);
683 } 719 }
684 server_reschedule (plugin, GNUNET_NO); 720 server_reschedule (plugin, GNUNET_NO);
685#endif 721#endif
@@ -688,8 +724,9 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
688 else 724 else
689 { 725 {
690#if DEBUG_HTTP 726#if DEBUG_HTTP
691 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 727 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
692 "Server: %X no inbound bandwidth available! Next read was delayed by %llu ms\n", s, now.abs_value - s->next_receive.abs_value); 728 "Server: %X no inbound bandwidth available! Next read was delayed by %llu ms\n",
729 s, now.abs_value - s->next_receive.abs_value);
693#endif 730#endif
694 } 731 }
695 return MHD_YES; 732 return MHD_YES;
@@ -706,22 +743,22 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection,
706{ 743{
707 struct ServerConnection *sc = *httpSessionCache; 744 struct ServerConnection *sc = *httpSessionCache;
708 struct ServerConnection *tc = *httpSessionCache; 745 struct ServerConnection *tc = *httpSessionCache;
709 struct Session * s = NULL; 746 struct Session *s = NULL;
710 struct Session * t = NULL; 747 struct Session *t = NULL;
711 struct Plugin * plugin = NULL; 748 struct Plugin *plugin = NULL;
712 749
713 if (sc == NULL) 750 if (sc == NULL)
714 return; 751 return;
715 752
716 s = sc->session; 753 s = sc->session;
717 plugin = s-> plugin; 754 plugin = s->plugin;
718 if (sc->direction == _SEND) 755 if (sc->direction == _SEND)
719 { 756 {
720#if VERBOSE_SERVER 757#if VERBOSE_SERVER
721 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, 758 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
722 "Server: %X peer `%s' GET on address `%s' disconnected\n", 759 "Server: %X peer `%s' GET on address `%s' disconnected\n",
723 s->server_send, 760 s->server_send, GNUNET_i2s (&s->target),
724 GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen)); 761 GNUNET_a2s (s->addr, s->addrlen));
725#endif 762#endif
726 s->server_send = NULL; 763 s->server_send = NULL;
727 764
@@ -730,17 +767,18 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection,
730 tc = s->server_recv; 767 tc = s->server_recv;
731 tc->disconnect = GNUNET_YES; 768 tc->disconnect = GNUNET_YES;
732#if MHD_VERSION >= 0x00090E00 769#if MHD_VERSION >= 0x00090E00
733 MHD_set_connection_option (sc->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, 1); 770 MHD_set_connection_option (sc->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT,
771 1);
734#endif 772#endif
735 } 773 }
736 } 774 }
737 if (sc->direction == _RECEIVE) 775 if (sc->direction == _RECEIVE)
738 { 776 {
739#if VERBOSE_SERVER 777#if VERBOSE_SERVER
740 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, 778 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
741 "Server: %X peer `%s' PUT on address `%s' disconnected\n", 779 "Server: %X peer `%s' PUT on address `%s' disconnected\n",
742 s->server_recv, 780 s->server_recv, GNUNET_i2s (&s->target),
743 GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen)); 781 GNUNET_a2s (s->addr, s->addrlen));
744#endif 782#endif
745 s->server_recv = NULL; 783 s->server_recv = NULL;
746 if (s->server_send != NULL) 784 if (s->server_send != NULL)
@@ -748,13 +786,14 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection,
748 tc = s->server_send; 786 tc = s->server_send;
749 tc->disconnect = GNUNET_YES; 787 tc->disconnect = GNUNET_YES;
750#if MHD_VERSION >= 0x00090E00 788#if MHD_VERSION >= 0x00090E00
751 MHD_set_connection_option (sc->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, 1); 789 MHD_set_connection_option (sc->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT,
790 1);
752#endif 791#endif
753 } 792 }
754 if (s->msg_tk != NULL) 793 if (s->msg_tk != NULL)
755 { 794 {
756 GNUNET_SERVER_mst_destroy(s->msg_tk); 795 GNUNET_SERVER_mst_destroy (s->msg_tk);
757 s->msg_tk = NULL; 796 s->msg_tk = NULL;
758 } 797 }
759 } 798 }
760 GNUNET_free (sc); 799 GNUNET_free (sc);
@@ -764,8 +803,9 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection,
764 { 803 {
765 if (t == s) 804 if (t == s)
766 { 805 {
767 GNUNET_CONTAINER_DLL_remove(plugin->server_semi_head, plugin->server_semi_tail, s); 806 GNUNET_CONTAINER_DLL_remove (plugin->server_semi_head,
768 GNUNET_CONTAINER_DLL_insert(plugin->head, plugin->tail, s); 807 plugin->server_semi_tail, s);
808 GNUNET_CONTAINER_DLL_insert (plugin->head, plugin->tail, s);
769 break; 809 break;
770 } 810 }
771 t = t->next; 811 t = t->next;
@@ -777,17 +817,17 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection,
777 if ((s->server_send == NULL) && (s->server_recv == NULL)) 817 if ((s->server_send == NULL) && (s->server_recv == NULL))
778 { 818 {
779#if VERBOSE_SERVER 819#if VERBOSE_SERVER
780 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 820 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
781 "Server: peer `%s' on address `%s' disconnected\n", 821 "Server: peer `%s' on address `%s' disconnected\n",
782 GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen)); 822 GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen));
783#endif 823#endif
784 if (s->msg_tk != NULL) 824 if (s->msg_tk != NULL)
785 { 825 {
786 GNUNET_SERVER_mst_destroy(s->msg_tk); 826 GNUNET_SERVER_mst_destroy (s->msg_tk);
787 s->msg_tk = NULL; 827 s->msg_tk = NULL;
788 } 828 }
789 829
790 notify_session_end(s->plugin, &s->target, s); 830 notify_session_end (s->plugin, &s->target, s);
791 } 831 }
792} 832}
793 833
@@ -818,7 +858,7 @@ server_disconnect (struct Session *s)
818} 858}
819 859
820int 860int
821server_send (struct Session *s, struct HTTP_Message * msg) 861server_send (struct Session *s, struct HTTP_Message *msg)
822{ 862{
823 GNUNET_CONTAINER_DLL_insert (s->msg_head, s->msg_tail, msg); 863 GNUNET_CONTAINER_DLL_insert (s->msg_head, s->msg_tail, msg);
824 server_reschedule (s->plugin, GNUNET_YES); 864 server_reschedule (s->plugin, GNUNET_YES);
@@ -834,10 +874,10 @@ server_send (struct Session *s, struct HTTP_Message * msg)
834 * @param tc task context 874 * @param tc task context
835 */ 875 */
836static void 876static void
837server_v4_run (void *cls, 877server_v4_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
838 const struct GNUNET_SCHEDULER_TaskContext *tc)
839{ 878{
840 struct Plugin *plugin = cls; 879 struct Plugin *plugin = cls;
880
841 GNUNET_assert (cls != NULL); 881 GNUNET_assert (cls != NULL);
842 882
843 plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK; 883 plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK;
@@ -847,7 +887,8 @@ server_v4_run (void *cls,
847 887
848 GNUNET_assert (MHD_YES == MHD_run (plugin->server_v4)); 888 GNUNET_assert (MHD_YES == MHD_run (plugin->server_v4));
849 if (plugin->server_v4 != NULL) 889 if (plugin->server_v4 != NULL)
850 plugin->server_v4_task = server_schedule (plugin, plugin->server_v4, GNUNET_NO); 890 plugin->server_v4_task =
891 server_schedule (plugin, plugin->server_v4, GNUNET_NO);
851} 892}
852 893
853 894
@@ -858,10 +899,10 @@ server_v4_run (void *cls,
858 * @param tc task context 899 * @param tc task context
859 */ 900 */
860static void 901static void
861server_v6_run (void *cls, 902server_v6_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
862 const struct GNUNET_SCHEDULER_TaskContext *tc)
863{ 903{
864 struct Plugin *plugin = cls; 904 struct Plugin *plugin = cls;
905
865 GNUNET_assert (cls != NULL); 906 GNUNET_assert (cls != NULL);
866 907
867 plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK; 908 plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK;
@@ -871,7 +912,8 @@ server_v6_run (void *cls,
871 912
872 GNUNET_assert (MHD_YES == MHD_run (plugin->server_v6)); 913 GNUNET_assert (MHD_YES == MHD_run (plugin->server_v6));
873 if (plugin->server_v6 != NULL) 914 if (plugin->server_v6 != NULL)
874 plugin->server_v6_task = server_schedule (plugin, plugin->server_v6, GNUNET_NO); 915 plugin->server_v6_task =
916 server_schedule (plugin, plugin->server_v6, GNUNET_NO);
875} 917}
876 918
877/** 919/**
@@ -882,7 +924,8 @@ server_v6_run (void *cls,
882 * @return gnunet task identifier 924 * @return gnunet task identifier
883 */ 925 */
884static GNUNET_SCHEDULER_TaskIdentifier 926static GNUNET_SCHEDULER_TaskIdentifier
885server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle, int now) 927server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle,
928 int now)
886{ 929{
887 GNUNET_SCHEDULER_TaskIdentifier ret; 930 GNUNET_SCHEDULER_TaskIdentifier ret;
888 fd_set rs; 931 fd_set rs;
@@ -909,7 +952,7 @@ server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle, int no
909 GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max)); 952 GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max));
910 haveto = MHD_get_timeout (daemon_handle, &timeout); 953 haveto = MHD_get_timeout (daemon_handle, &timeout);
911 if (haveto == MHD_YES) 954 if (haveto == MHD_YES)
912 { 955 {
913 if (timeout != last_timeout) 956 if (timeout != last_timeout)
914 { 957 {
915#if VERBOSE_SERVER 958#if VERBOSE_SERVER
@@ -920,7 +963,7 @@ server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle, int no
920 last_timeout = timeout; 963 last_timeout = timeout;
921 } 964 }
922 tv.rel_value = (uint64_t) timeout; 965 tv.rel_value = (uint64_t) timeout;
923 } 966 }
924 else 967 else
925 tv = GNUNET_TIME_UNIT_SECONDS; 968 tv = GNUNET_TIME_UNIT_SECONDS;
926 /* Force immediate run, since we have outbound data to send */ 969 /* Force immediate run, since we have outbound data to send */
@@ -972,7 +1015,7 @@ server_start (struct Plugin *plugin)
972 if (res == GNUNET_SYSERR) 1015 if (res == GNUNET_SYSERR)
973 { 1016 {
974 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, 1017 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
975 "Could not load or create server certificate! Loading plugin failed!\n"); 1018 "Could not load or create server certificate! Loading plugin failed!\n");
976 return res; 1019 return res;
977 } 1020 }
978#endif 1021#endif
@@ -981,11 +1024,13 @@ server_start (struct Plugin *plugin)
981#if MHD_VERSION >= 0x00090E00 1024#if MHD_VERSION >= 0x00090E00
982 timeout = GNUNET_CONSTANTS_DISCONNECT_SESSION_TIMEOUT.rel_value / 1000; 1025 timeout = GNUNET_CONSTANTS_DISCONNECT_SESSION_TIMEOUT.rel_value / 1000;
983 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1026 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
984 "MHD can set timeout per connection! Default time out %u sec.\n", timeout); 1027 "MHD can set timeout per connection! Default time out %u sec.\n",
1028 timeout);
985#else 1029#else
986 timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000; 1030 timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000;
987 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name, 1031 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name,
988 "MHD cannot set timeout per connection! Default time out %u sec.\n", timeout); 1032 "MHD cannot set timeout per connection! Default time out %u sec.\n",
1033 timeout);
989#endif 1034#endif
990 plugin->server_v4 = NULL; 1035 plugin->server_v4 = NULL;
991 if (plugin->ipv4 == GNUNET_YES) 1036 if (plugin->ipv4 == GNUNET_YES)
@@ -1015,7 +1060,7 @@ server_start (struct Plugin *plugin)
1015 plugin->cert, 1060 plugin->cert,
1016#endif 1061#endif
1017 MHD_OPTION_CONNECTION_TIMEOUT, 1062 MHD_OPTION_CONNECTION_TIMEOUT,
1018 timeout , 1063 timeout,
1019 MHD_OPTION_CONNECTION_MEMORY_LIMIT, 1064 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
1020 (size_t) (2 * 1065 (size_t) (2 *
1021 GNUNET_SERVER_MAX_MESSAGE_SIZE), 1066 GNUNET_SERVER_MAX_MESSAGE_SIZE),
@@ -1066,15 +1111,15 @@ server_start (struct Plugin *plugin)
1066 if ((plugin->ipv4 == GNUNET_YES) && (plugin->server_v4 == NULL)) 1111 if ((plugin->ipv4 == GNUNET_YES) && (plugin->server_v4 == NULL))
1067 { 1112 {
1068 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, 1113 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
1069 "Failed to start %s IPv4 server component on port %u\n", plugin->name, 1114 "Failed to start %s IPv4 server component on port %u\n",
1070 plugin->port); 1115 plugin->name, plugin->port);
1071 return GNUNET_SYSERR; 1116 return GNUNET_SYSERR;
1072 } 1117 }
1073 if ((plugin->ipv6 == GNUNET_YES) && (plugin->server_v6 == NULL)) 1118 if ((plugin->ipv6 == GNUNET_YES) && (plugin->server_v6 == NULL))
1074 { 1119 {
1075 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, 1120 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
1076 "Failed to start %s IPv6 server component on port %u\n", plugin->name, 1121 "Failed to start %s IPv6 server component on port %u\n",
1077 plugin->port); 1122 plugin->name, plugin->port);
1078 return GNUNET_SYSERR; 1123 return GNUNET_SYSERR;
1079 } 1124 }
1080 1125
@@ -1095,8 +1140,10 @@ server_stop (struct Plugin *plugin)
1095 struct Session *t = NULL; 1140 struct Session *t = NULL;
1096 1141
1097 struct MHD_Daemon *server_v4_tmp = plugin->server_v4; 1142 struct MHD_Daemon *server_v4_tmp = plugin->server_v4;
1143
1098 plugin->server_v4 = NULL; 1144 plugin->server_v4 = NULL;
1099 struct MHD_Daemon *server_v6_tmp = plugin->server_v6; 1145 struct MHD_Daemon *server_v6_tmp = plugin->server_v6;
1146
1100 plugin->server_v6 = NULL; 1147 plugin->server_v6 = NULL;
1101 1148
1102 if (plugin->server_v4_task != GNUNET_SCHEDULER_NO_TASK) 1149 if (plugin->server_v4_task != GNUNET_SCHEDULER_NO_TASK)
diff --git a/src/transport/plugin_transport_sat_constants.h b/src/transport/plugin_transport_sat_constants.h
index a9ee9227c..bd64c5d2b 100644
--- a/src/transport/plugin_transport_sat_constants.h
+++ b/src/transport/plugin_transport_sat_constants.h
@@ -32,22 +32,26 @@
32 32
33typedef struct MacAdress 33typedef struct MacAdress
34{ 34{
35 uint8_t mac[6]; 35 uint8_t mac[6];
36}MacAdress; 36} MacAdress;
37 37
38//praeamble 38//praeamble
39static const struct char praeambel[56] = 39static const struct char praeambel[56] =
40{{1,0,1,0,10,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0}}; 40 { {1, 0, 1, 0, 10, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
41 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
42 0, 1, 0, 1, 0, 1, 0}
43};
41 44
42//start of frame 45//start of frame
43static const struct char sof[8]= 46static const struct char sof[8] = { {1, 0, 1, 0, 1, 0, 1, 1} }
44{{1,0,1,0,1,0,1,1}}
45 47
46// broadcast mac 48// broadcast mac
47static const struct MacAddress bc_all_mac = 49static const struct MacAddress bc_all_mac =
48 { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }; 50 { {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} };
49 51
50//crc polynom 52//crc polynom
51static const struct char ploynom[32] = 53static const struct char ploynom[32] =
52 {{1,1,1,0,1,1,0,1,1,0,1,1,1,0,0,0,1,0,0,0,0,0,1,1,0,0,1,0,0,0,0,1}}; 54 { {1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1,
55 0, 0, 1, 0, 0, 0, 0, 1}
56};
53#endif 57#endif
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index 04ba348b3..9c6535988 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -696,10 +696,9 @@ do_transmit (void *cls, size_t size, void *buf)
696 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, 696 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
697 session->pending_messages_tail, pos); 697 session->pending_messages_tail, pos);
698 GNUNET_assert (size >= pos->message_size); 698 GNUNET_assert (size >= pos->message_size);
699 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 699 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
700 "tcp", 700 "Transmitting message of type %u\n",
701 "Transmitting message of type %u\n", 701 ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type));
702 ntohs (((struct GNUNET_MessageHeader*)pos->msg)->type));
703 /* FIXME: this memcpy can be up to 7% of our total runtime */ 702 /* FIXME: this memcpy can be up to 7% of our total runtime */
704 memcpy (cbuf, pos->msg, pos->message_size); 703 memcpy (cbuf, pos->msg, pos->message_size);
705 cbuf += pos->message_size; 704 cbuf += pos->message_size;
@@ -1002,7 +1001,7 @@ tcp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
1002 { 1001 {
1003 if (addrlen == sizeof (struct IPv6TcpAddress)) 1002 if (addrlen == sizeof (struct IPv6TcpAddress))
1004 { 1003 {
1005 GNUNET_assert (NULL != addr); /* make static analysis happy */ 1004 GNUNET_assert (NULL != addr); /* make static analysis happy */
1006 t6 = addr; 1005 t6 = addr;
1007 af = AF_INET6; 1006 af = AF_INET6;
1008 memset (&a6, 0, sizeof (a6)); 1007 memset (&a6, 0, sizeof (a6));
@@ -1019,7 +1018,7 @@ tcp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
1019 } 1018 }
1020 else if (addrlen == sizeof (struct IPv4TcpAddress)) 1019 else if (addrlen == sizeof (struct IPv4TcpAddress))
1021 { 1020 {
1022 GNUNET_assert (NULL != addr); /* make static analysis happy */ 1021 GNUNET_assert (NULL != addr); /* make static analysis happy */
1023 t4 = addr; 1022 t4 = addr;
1024 af = AF_INET; 1023 af = AF_INET;
1025 memset (&a4, 0, sizeof (a4)); 1024 memset (&a4, 0, sizeof (a4));
@@ -1073,7 +1072,7 @@ tcp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
1073 1072
1074 /* append pm to pending_messages list */ 1073 /* append pm to pending_messages list */
1075 GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head, 1074 GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head,
1076 session->pending_messages_tail, pm); 1075 session->pending_messages_tail, pm);
1077 1076
1078 GNUNET_assert (GNUNET_CONTAINER_multihashmap_put 1077 GNUNET_assert (GNUNET_CONTAINER_multihashmap_put
1079 (plugin->nat_wait_conns, &target->hashPubKey, session, 1078 (plugin->nat_wait_conns, &target->hashPubKey, session,
@@ -1129,16 +1128,14 @@ tcp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
1129 /* check if session is valid */ 1128 /* check if session is valid */
1130 struct Session *ses = plugin->sessions; 1129 struct Session *ses = plugin->sessions;
1131 1130
1132 if (0 != memcmp (target, 1131 if (0 !=
1133 &session->target, 1132 memcmp (target, &session->target, sizeof (struct GNUNET_PeerIdentity)))
1134 sizeof (struct GNUNET_PeerIdentity)))
1135 { 1133 {
1136 GNUNET_break (0); 1134 GNUNET_break (0);
1137 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1135 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1138 "Got session %p for `%s', but should be for peer `%s'!\n", 1136 "Got session %p for `%s', but should be for peer `%s'!\n",
1139 session, 1137 session, GNUNET_i2s (&session->target),
1140 GNUNET_i2s (&session->target), 1138 GNUNET_h2s (&target->hashPubKey));
1141 GNUNET_h2s (&target->hashPubKey));
1142 return -1; 1139 return -1;
1143 } 1140 }
1144 1141
@@ -1170,7 +1167,7 @@ tcp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
1170 1167
1171 /* append pm to pending_messages list */ 1168 /* append pm to pending_messages list */
1172 GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head, 1169 GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head,
1173 session->pending_messages_tail, pm); 1170 session->pending_messages_tail, pm);
1174#if DEBUG_TCP 1171#if DEBUG_TCP
1175 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 1172 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
1176 "Asked to transmit %u bytes to `%s', added message to list.\n", 1173 "Asked to transmit %u bytes to `%s', added message to list.\n",
@@ -1741,8 +1738,8 @@ handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client,
1741 distance.value = htonl (1); 1738 distance.value = htonl (1);
1742 delay = 1739 delay =
1743 plugin->env->receive (plugin->env->cls, &session->target, message, 1740 plugin->env->receive (plugin->env->cls, &session->target, message,
1744 (const struct GNUNET_ATS_Information *) 1741 (const struct GNUNET_ATS_Information *) &distance,
1745 &distance, 1, session, 1742 1, session,
1746 (GNUNET_YES == 1743 (GNUNET_YES ==
1747 session->inbound) ? NULL : session->connect_addr, 1744 session->inbound) ? NULL : session->connect_addr,
1748 (GNUNET_YES == 1745 (GNUNET_YES ==
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index cf6e01306..667af25be 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -120,12 +120,12 @@ struct UDP_Beacon_Message
120 /** 120 /**
121 * Message header. 121 * Message header.
122 */ 122 */
123 struct GNUNET_MessageHeader header; 123 struct GNUNET_MessageHeader header;
124 124
125 /** 125 /**
126 * What is the identity of the sender 126 * What is the identity of the sender
127 */ 127 */
128 struct GNUNET_PeerIdentity sender; 128 struct GNUNET_PeerIdentity sender;
129}; 129};
130 130
131 131
@@ -396,8 +396,8 @@ struct Plugin
396 396
397struct PeerSessionIteratorContext 397struct PeerSessionIteratorContext
398{ 398{
399 struct Session * result; 399 struct Session *result;
400 const void * addr; 400 const void *addr;
401 size_t addrlen; 401 size_t addrlen;
402}; 402};
403 403
@@ -417,13 +417,12 @@ find_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *peer)
417} 417}
418 418
419 419
420static int 420static int
421inbound_session_iterator (void *cls, 421inbound_session_iterator (void *cls, const GNUNET_HashCode * key, void *value)
422 const GNUNET_HashCode * key,
423 void *value)
424{ 422{
425 struct PeerSessionIteratorContext *psc = cls; 423 struct PeerSessionIteratorContext *psc = cls;
426 struct Session *s = value; 424 struct Session *s = value;
425
427 if (s->addrlen == psc->addrlen) 426 if (s->addrlen == psc->addrlen)
428 { 427 {
429 if (0 == memcmp (&s[1], psc->addr, s->addrlen)) 428 if (0 == memcmp (&s[1], psc->addr, s->addrlen))
@@ -444,26 +443,29 @@ inbound_session_iterator (void *cls,
444 */ 443 */
445static struct Session * 444static struct Session *
446find_inbound_session (struct Plugin *plugin, 445find_inbound_session (struct Plugin *plugin,
447 const struct GNUNET_PeerIdentity *peer, 446 const struct GNUNET_PeerIdentity *peer, const void *addr,
448 const void * addr, size_t addrlen) 447 size_t addrlen)
449{ 448{
450 struct PeerSessionIteratorContext psc; 449 struct PeerSessionIteratorContext psc;
450
451 psc.result = NULL; 451 psc.result = NULL;
452 psc.addrlen = addrlen; 452 psc.addrlen = addrlen;
453 psc.addr = addr; 453 psc.addr = addr;
454 454
455 GNUNET_CONTAINER_multihashmap_get_multiple(plugin->inbound_sessions, &peer->hashPubKey, &inbound_session_iterator, &psc); 455 GNUNET_CONTAINER_multihashmap_get_multiple (plugin->inbound_sessions,
456 &peer->hashPubKey,
457 &inbound_session_iterator, &psc);
456 return psc.result; 458 return psc.result;
457} 459}
458 460
459 461
460static int 462static int
461inbound_session_by_addr_iterator (void *cls, 463inbound_session_by_addr_iterator (void *cls, const GNUNET_HashCode * key,
462 const GNUNET_HashCode * key, 464 void *value)
463 void *value)
464{ 465{
465 struct PeerSessionIteratorContext *psc = cls; 466 struct PeerSessionIteratorContext *psc = cls;
466 struct Session *s = value; 467 struct Session *s = value;
468
467 if (s->addrlen == psc->addrlen) 469 if (s->addrlen == psc->addrlen)
468 { 470 {
469 if (0 == memcmp (&s[1], psc->addr, s->addrlen)) 471 if (0 == memcmp (&s[1], psc->addr, s->addrlen))
@@ -484,14 +486,18 @@ inbound_session_by_addr_iterator (void *cls,
484 * @return NULL if we have no session 486 * @return NULL if we have no session
485 */ 487 */
486static struct Session * 488static struct Session *
487find_inbound_session_by_addr (struct Plugin *plugin, const void * addr, size_t addrlen) 489find_inbound_session_by_addr (struct Plugin *plugin, const void *addr,
490 size_t addrlen)
488{ 491{
489 struct PeerSessionIteratorContext psc; 492 struct PeerSessionIteratorContext psc;
493
490 psc.result = NULL; 494 psc.result = NULL;
491 psc.addrlen = addrlen; 495 psc.addrlen = addrlen;
492 psc.addr = addr; 496 psc.addr = addr;
493 497
494 GNUNET_CONTAINER_multihashmap_iterate (plugin->inbound_sessions, &inbound_session_by_addr_iterator, &psc); 498 GNUNET_CONTAINER_multihashmap_iterate (plugin->inbound_sessions,
499 &inbound_session_by_addr_iterator,
500 &psc);
495 return psc.result; 501 return psc.result;
496} 502}
497 503
@@ -531,7 +537,7 @@ destroy_inbound_session (void *cls, const GNUNET_HashCode * key, void *value)
531 struct Session *s = value; 537 struct Session *s = value;
532 538
533 if (s->invalidation_task != GNUNET_SCHEDULER_NO_TASK) 539 if (s->invalidation_task != GNUNET_SCHEDULER_NO_TASK)
534 GNUNET_SCHEDULER_cancel(s->invalidation_task); 540 GNUNET_SCHEDULER_cancel (s->invalidation_task);
535 if (GNUNET_SCHEDULER_NO_TASK != s->delayed_cont_task) 541 if (GNUNET_SCHEDULER_NO_TASK != s->delayed_cont_task)
536 GNUNET_SCHEDULER_cancel (s->delayed_cont_task); 542 GNUNET_SCHEDULER_cancel (s->delayed_cont_task);
537 GNUNET_free (s); 543 GNUNET_free (s);
@@ -560,11 +566,10 @@ udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
560 session)); 566 session));
561 567
562 GNUNET_CONTAINER_multihashmap_get_multiple (plugin->inbound_sessions, 568 GNUNET_CONTAINER_multihashmap_get_multiple (plugin->inbound_sessions,
563 &target->hashPubKey, 569 &target->hashPubKey,
564 &destroy_inbound_session, NULL); 570 &destroy_inbound_session, NULL);
565 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto"); 571 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto");
566 LOG (GNUNET_ERROR_TYPE_ERROR, 572 LOG (GNUNET_ERROR_TYPE_ERROR, "UDP DISCONNECT\n");
567 "UDP DISCONNECT\n");
568 573
569 plugin->last_expected_delay = GNUNET_FRAGMENT_context_destroy (session->frag); 574 plugin->last_expected_delay = GNUNET_FRAGMENT_context_destroy (session->frag);
570 if (GNUNET_SCHEDULER_NO_TASK != session->delayed_cont_task) 575 if (GNUNET_SCHEDULER_NO_TASK != session->delayed_cont_task)
@@ -614,15 +619,15 @@ udp_send (struct Plugin *plugin, const struct sockaddr *sa,
614 { 619 {
615 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto"); 620 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto");
616 LOG (GNUNET_ERROR_TYPE_ERROR, 621 LOG (GNUNET_ERROR_TYPE_ERROR,
617 "UDP transmited %u-byte message to %s (%d: %s)\n", 622 "UDP transmited %u-byte message to %s (%d: %s)\n",
618 (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen), 623 (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen), (int) sent,
619 (int) sent, (sent < 0) ? STRERROR (errno) : "ok"); 624 (sent < 0) ? STRERROR (errno) : "ok");
620 625
621 } 626 }
622 LOG (GNUNET_ERROR_TYPE_DEBUG, 627 LOG (GNUNET_ERROR_TYPE_DEBUG,
623 "UDP transmited %u-byte message to %s (%d: %s)\n", 628 "UDP transmited %u-byte message to %s (%d: %s)\n",
624 (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen), 629 (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen), (int) sent,
625 (int) sent, (sent < 0) ? STRERROR (errno) : "ok"); 630 (sent < 0) ? STRERROR (errno) : "ok");
626 return sent; 631 return sent;
627} 632}
628 633
@@ -648,10 +653,10 @@ send_fragment (void *cls, const struct GNUNET_MessageHeader *msg)
648 653
649static struct Session * 654static struct Session *
650create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, 655create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
651 const void *addr, size_t addrlen, 656 const void *addr, size_t addrlen,
652 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) 657 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
653{ 658{
654 struct Session * peer_session; 659 struct Session *peer_session;
655 const struct IPv4UdpAddress *t4; 660 const struct IPv4UdpAddress *t4;
656 const struct IPv6UdpAddress *t6; 661 const struct IPv6UdpAddress *t6;
657 struct sockaddr_in *v4; 662 struct sockaddr_in *v4;
@@ -667,8 +672,7 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
667 } 672 }
668 t4 = addr; 673 t4 = addr;
669 peer_session = 674 peer_session =
670 GNUNET_malloc (sizeof (struct Session) + 675 GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in));
671 sizeof (struct sockaddr_in));
672 len = sizeof (struct sockaddr_in); 676 len = sizeof (struct sockaddr_in);
673 v4 = (struct sockaddr_in *) &peer_session[1]; 677 v4 = (struct sockaddr_in *) &peer_session[1];
674 v4->sin_family = AF_INET; 678 v4->sin_family = AF_INET;
@@ -685,8 +689,7 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
685 } 689 }
686 t6 = addr; 690 t6 = addr;
687 peer_session = 691 peer_session =
688 GNUNET_malloc (sizeof (struct Session) + 692 GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in6));
689 sizeof (struct sockaddr_in6));
690 len = sizeof (struct sockaddr_in6); 693 len = sizeof (struct sockaddr_in6);
691 v6 = (struct sockaddr_in6 *) &peer_session[1]; 694 v6 = (struct sockaddr_in6 *) &peer_session[1];
692 v6->sin6_family = AF_INET6; 695 v6->sin6_family = AF_INET6;
@@ -719,8 +722,7 @@ udp_address_to_string (void *cls, const void *addr, size_t addrlen);
719 722
720 723
721static void 724static void
722udp_call_continuation (void *cls, 725udp_call_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
723 const struct GNUNET_SCHEDULER_TaskContext *tc)
724{ 726{
725 struct Session *s = cls; 727 struct Session *s = cls;
726 GNUNET_TRANSPORT_TransmitContinuation cont = s->cont; 728 GNUNET_TRANSPORT_TransmitContinuation cont = s->cont;
@@ -779,10 +781,10 @@ udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
779 } 781 }
780 782
781 LOG (GNUNET_ERROR_TYPE_DEBUG, 783 LOG (GNUNET_ERROR_TYPE_DEBUG,
782 "UDP transmits %u-byte message to `%s' using address `%s' session 0x%X mode %i\n", 784 "UDP transmits %u-byte message to `%s' using address `%s' session 0x%X mode %i\n",
783 msgbuf_size, GNUNET_i2s (target), 785 msgbuf_size, GNUNET_i2s (target), udp_address_to_string (NULL, addr,
784 udp_address_to_string (NULL, addr, addrlen), 786 addrlen),
785 session, force_address); 787 session, force_address);
786 788
787 if ((force_address == GNUNET_SYSERR) && (session == NULL)) 789 if ((force_address == GNUNET_SYSERR) && (session == NULL))
788 return GNUNET_SYSERR; 790 return GNUNET_SYSERR;
@@ -792,10 +794,11 @@ udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
792 if ((session != NULL) && (addr != NULL) && (addrlen != 0)) 794 if ((session != NULL) && (addr != NULL) && (addrlen != 0))
793 { 795 {
794 s = session; 796 s = session;
795 GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains_value ( 797 GNUNET_assert (GNUNET_YES ==
796 plugin->inbound_sessions, &target->hashPubKey, s)); 798 GNUNET_CONTAINER_multihashmap_contains_value
799 (plugin->inbound_sessions, &target->hashPubKey, s));
797 800
798 if (0 != memcmp (&s->target, target, sizeof (struct GNUNET_PeerIdentity))) 801 if (0 != memcmp (&s->target, target, sizeof (struct GNUNET_PeerIdentity)))
799 return GNUNET_SYSERR; 802 return GNUNET_SYSERR;
800 switch (addrlen) 803 switch (addrlen)
801 { 804 {
@@ -810,10 +813,13 @@ udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
810 if (s->addrlen != (sizeof (struct sockaddr_in))) 813 if (s->addrlen != (sizeof (struct sockaddr_in)))
811 return GNUNET_SYSERR; 814 return GNUNET_SYSERR;
812 struct sockaddr_in *a4 = (struct sockaddr_in *) s->sock_addr; 815 struct sockaddr_in *a4 = (struct sockaddr_in *) s->sock_addr;
816
813 GNUNET_assert (a4->sin_port == t4->u4_port); 817 GNUNET_assert (a4->sin_port == t4->u4_port);
814 GNUNET_assert (0 == memcmp(&a4->sin_addr, &t4->ipv4_addr, sizeof (struct in_addr))); 818 GNUNET_assert (0 ==
815 LOG (GNUNET_ERROR_TYPE_DEBUG, 819 memcmp (&a4->sin_addr, &t4->ipv4_addr,
816 "Session 0x%X successfully checked!\n", session); 820 sizeof (struct in_addr)));
821 LOG (GNUNET_ERROR_TYPE_DEBUG, "Session 0x%X successfully checked!\n",
822 session);
817 break; 823 break;
818 case sizeof (struct IPv6UdpAddress): 824 case sizeof (struct IPv6UdpAddress):
819 if (NULL == plugin->sockv6) 825 if (NULL == plugin->sockv6)
@@ -825,10 +831,13 @@ udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
825 t6 = addr; 831 t6 = addr;
826 GNUNET_assert (s->addrlen == sizeof (struct sockaddr_in6)); 832 GNUNET_assert (s->addrlen == sizeof (struct sockaddr_in6));
827 struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) s->sock_addr; 833 struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) s->sock_addr;
834
828 GNUNET_assert (a6->sin6_port == t6->u6_port); 835 GNUNET_assert (a6->sin6_port == t6->u6_port);
829 GNUNET_assert (0 == memcmp(&a6->sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr))); 836 GNUNET_assert (0 ==
830 LOG (GNUNET_ERROR_TYPE_DEBUG, 837 memcmp (&a6->sin6_addr, &t6->ipv6_addr,
831 "Session 0x%X successfully checked!\n", session); 838 sizeof (struct in6_addr)));
839 LOG (GNUNET_ERROR_TYPE_DEBUG, "Session 0x%X successfully checked!\n",
840 session);
832 break; 841 break;
833 default: 842 default:
834 /* Must have a valid address to send to */ 843 /* Must have a valid address to send to */
@@ -854,7 +863,7 @@ udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
854 udp->sender = *plugin->env->my_identity; 863 udp->sender = *plugin->env->my_identity;
855 memcpy (&udp[1], msgbuf, msgbuf_size); 864 memcpy (&udp[1], msgbuf, msgbuf_size);
856 865
857 if (s != NULL) 866 if (s != NULL)
858 delta = GNUNET_TIME_absolute_get_remaining (s->flow_delay_from_other_peer); 867 delta = GNUNET_TIME_absolute_get_remaining (s->flow_delay_from_other_peer);
859 else 868 else
860 delta = GNUNET_TIME_UNIT_ZERO; 869 delta = GNUNET_TIME_UNIT_ZERO;
@@ -863,17 +872,15 @@ udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
863 mlen = udp_send (plugin, peer_session->sock_addr, &udp->header); 872 mlen = udp_send (plugin, peer_session->sock_addr, &udp->header);
864 if (cont != NULL) 873 if (cont != NULL)
865 { 874 {
866 if ( (delta.rel_value > 0) && 875 if ((delta.rel_value > 0) && (mlen > 0))
867 (mlen > 0) )
868 { 876 {
869 s->cont = cont; 877 s->cont = cont;
870 s->cont_cls = cont_cls; 878 s->cont_cls = cont_cls;
871 s->delayed_cont_task = GNUNET_SCHEDULER_add_delayed (delta, 879 s->delayed_cont_task =
872 &udp_call_continuation, 880 GNUNET_SCHEDULER_add_delayed (delta, &udp_call_continuation, s);
873 s);
874 } 881 }
875 else 882 else
876 cont (cont_cls, target, (mlen > 0) ? GNUNET_OK : GNUNET_SYSERR); 883 cont (cont_cls, target, (mlen > 0) ? GNUNET_OK : GNUNET_SYSERR);
877 } 884 }
878 GNUNET_free_non_null (peer_session); 885 GNUNET_free_non_null (peer_session);
879 } 886 }
@@ -915,7 +922,7 @@ struct SourceInformation
915 */ 922 */
916 size_t args; 923 size_t args;
917 924
918 struct Session * session; 925 struct Session *session;
919}; 926};
920 927
921 928
@@ -940,23 +947,29 @@ process_inbound_tokenized_messages (void *cls, void *client,
940 distance.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); 947 distance.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
941 distance.value = htonl (1); 948 distance.value = htonl (1);
942 949
943 LOG (GNUNET_ERROR_TYPE_DEBUG, 950 LOG (GNUNET_ERROR_TYPE_DEBUG, "Giving Session %X %s to transport\n",
944 "Giving Session %X %s to transport\n", si->session, GNUNET_i2s(&si->session->target)); 951 si->session, GNUNET_i2s (&si->session->target));
945 delay = plugin->env->receive (plugin->env->cls, &si->sender, hdr, &distance, 1, si->session, 952 delay =
946 si->arg, si->args); 953 plugin->env->receive (plugin->env->cls, &si->sender, hdr, &distance, 1,
954 si->session, si->arg, si->args);
947 si->session->flow_delay_for_other_peer = delay; 955 si->session->flow_delay_for_other_peer = delay;
948} 956}
949 957
950static void 958static void
951invalidation_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 959invalidation_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
952{ 960{
953 struct Session * s = cls; 961 struct Session *s = cls;
954 s->invalidation_task = GNUNET_SCHEDULER_NO_TASK;
955 LOG (GNUNET_ERROR_TYPE_ERROR,
956 "Session %X (`%s') is now invalid\n", s, GNUNET_a2s (s->sock_addr,s->addrlen));
957 962
958 s->plugin->env->session_end(s->plugin->env->cls, &s->target, s); 963 s->invalidation_task = GNUNET_SCHEDULER_NO_TASK;
959 GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(s->plugin->inbound_sessions, &s->target.hashPubKey, s)); 964 LOG (GNUNET_ERROR_TYPE_ERROR, "Session %X (`%s') is now invalid\n", s,
965 GNUNET_a2s (s->sock_addr, s->addrlen));
966
967 s->plugin->env->session_end (s->plugin->env->cls, &s->target, s);
968 GNUNET_assert (GNUNET_YES ==
969 GNUNET_CONTAINER_multihashmap_remove (s->
970 plugin->inbound_sessions,
971 &s->target.hashPubKey,
972 s));
960 GNUNET_free (s); 973 GNUNET_free (s);
961} 974}
962 975
@@ -1015,54 +1028,54 @@ process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg,
1015 } 1028 }
1016#if DEBUG_UDP 1029#if DEBUG_UDP
1017 LOG (GNUNET_ERROR_TYPE_DEBUG, 1030 LOG (GNUNET_ERROR_TYPE_DEBUG,
1018 "Received message with %u bytes from peer `%s' at `%s'\n", 1031 "Received message with %u bytes from peer `%s' at `%s'\n",
1019 (unsigned int) ntohs (msg->header.size), 1032 (unsigned int) ntohs (msg->header.size), GNUNET_i2s (&msg->sender),
1020 GNUNET_i2s (&msg->sender), GNUNET_a2s (sender_addr, 1033 GNUNET_a2s (sender_addr, sender_addr_len));
1021 sender_addr_len));
1022#endif 1034#endif
1023 1035
1024 /* create a session for inbound connections */ 1036 /* create a session for inbound connections */
1025 const struct UDPMessage * udp_msg = (const struct UDPMessage *) msg; 1037 const struct UDPMessage *udp_msg = (const struct UDPMessage *) msg;
1038
1026 LOG (GNUNET_ERROR_TYPE_DEBUG, 1039 LOG (GNUNET_ERROR_TYPE_DEBUG,
1027 "Lookup inbound UDP sessions for peer `%s' address `%s'\n", 1040 "Lookup inbound UDP sessions for peer `%s' address `%s'\n",
1028 GNUNET_i2s (&udp_msg->sender), 1041 GNUNET_i2s (&udp_msg->sender), udp_address_to_string (NULL, arg, args));
1029 udp_address_to_string(NULL, arg, args));
1030 1042
1031 struct Session * s = NULL; 1043 struct Session *s = NULL;
1032 s = find_inbound_session (plugin, &udp_msg->sender, sender_addr, sender_addr_len); 1044
1045 s = find_inbound_session (plugin, &udp_msg->sender, sender_addr,
1046 sender_addr_len);
1033 1047
1034 if (s != NULL) 1048 if (s != NULL)
1035 { 1049 {
1036 LOG (GNUNET_ERROR_TYPE_DEBUG, 1050 LOG (GNUNET_ERROR_TYPE_DEBUG,
1037 "Found existing inbound UDP sessions 0x%X for peer `%s' address `%s'\n", 1051 "Found existing inbound UDP sessions 0x%X for peer `%s' address `%s'\n",
1038 s, 1052 s, GNUNET_i2s (&s->target), udp_address_to_string (NULL, arg, args));
1039 GNUNET_i2s (&s->target),
1040 udp_address_to_string(NULL, arg, args));
1041 } 1053 }
1042 else 1054 else
1043 { 1055 {
1044 s = create_session (plugin, &udp_msg->sender, arg, args, NULL, NULL); 1056 s = create_session (plugin, &udp_msg->sender, arg, args, NULL, NULL);
1045 LOG (GNUNET_ERROR_TYPE_DEBUG, 1057 LOG (GNUNET_ERROR_TYPE_DEBUG,
1046 "Creating inbound UDP sessions 0x%X for peer `%s' address `%s'\n", 1058 "Creating inbound UDP sessions 0x%X for peer `%s' address `%s'\n", s,
1047 s, 1059 GNUNET_i2s (&s->target), udp_address_to_string (NULL, arg, args));
1048 GNUNET_i2s (&s->target), 1060
1049 udp_address_to_string(NULL, arg, args)); 1061 GNUNET_assert (GNUNET_OK ==
1050 1062 GNUNET_CONTAINER_multihashmap_put (plugin->inbound_sessions,
1051 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (plugin->inbound_sessions, 1063 &s->target.hashPubKey, s,
1052 &s->target.hashPubKey, 1064 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
1053 s,
1054 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
1055 } 1065 }
1056 s->valid_until = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 1066 s->valid_until =
1067 GNUNET_TIME_relative_to_absolute
1068 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1057 if (s->invalidation_task != GNUNET_SCHEDULER_NO_TASK) 1069 if (s->invalidation_task != GNUNET_SCHEDULER_NO_TASK)
1058 { 1070 {
1059 GNUNET_SCHEDULER_cancel(s->invalidation_task); 1071 GNUNET_SCHEDULER_cancel (s->invalidation_task);
1060 s->invalidation_task = GNUNET_SCHEDULER_NO_TASK; 1072 s->invalidation_task = GNUNET_SCHEDULER_NO_TASK;
1061 LOG (GNUNET_ERROR_TYPE_DEBUG, 1073 LOG (GNUNET_ERROR_TYPE_DEBUG, "Rescheduling %X' `%s'\n", s,
1062 "Rescheduling %X' `%s'\n", 1074 udp_address_to_string (NULL, arg, args));
1063 s, udp_address_to_string(NULL, arg, args));
1064 } 1075 }
1065 s->invalidation_task = GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &invalidation_task, s); 1076 s->invalidation_task =
1077 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1078 &invalidation_task, s);
1066 /* iterate over all embedded messages */ 1079 /* iterate over all embedded messages */
1067 si.sender = msg->sender; 1080 si.sender = msg->sender;
1068 si.arg = arg; 1081 si.arg = arg;
@@ -1118,6 +1131,7 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
1118 uint32_t delay = 0; 1131 uint32_t delay = 0;
1119 1132
1120 struct Session *s; 1133 struct Session *s;
1134
1121 s = find_inbound_session_by_addr (rc->plugin, rc->src_addr, rc->addr_len); 1135 s = find_inbound_session_by_addr (rc->plugin, rc->src_addr, rc->addr_len);
1122 if (s != NULL) 1136 if (s != NULL)
1123 { 1137 {
@@ -1129,12 +1143,13 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
1129 1143
1130 1144
1131#if DEBUG_UDP 1145#if DEBUG_UDP
1132 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ACK to `%s' including delay of %u ms\n", 1146 LOG (GNUNET_ERROR_TYPE_DEBUG,
1133 GNUNET_a2s (rc->src_addr, 1147 "Sending ACK to `%s' including delay of %u ms\n",
1134 (rc->src_addr->sa_family == 1148 GNUNET_a2s (rc->src_addr,
1135 AF_INET) ? sizeof (struct sockaddr_in) : 1149 (rc->src_addr->sa_family ==
1136 sizeof (struct sockaddr_in6)), 1150 AF_INET) ? sizeof (struct sockaddr_in) : sizeof (struct
1137 delay); 1151 sockaddr_in6)),
1152 delay);
1138#endif 1153#endif
1139 udp_ack = (struct UDP_ACK_Message *) buf; 1154 udp_ack = (struct UDP_ACK_Message *) buf;
1140 udp_ack->header.size = htons ((uint16_t) msize); 1155 udp_ack->header.size = htons ((uint16_t) msize);
@@ -1166,7 +1181,7 @@ struct FindReceiveContext
1166 */ 1181 */
1167 socklen_t addr_len; 1182 socklen_t addr_len;
1168 1183
1169 struct Session * session; 1184 struct Session *session;
1170}; 1185};
1171 1186
1172 1187
@@ -1217,7 +1232,7 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
1217 struct ReceiveContext *rc; 1232 struct ReceiveContext *rc;
1218 struct GNUNET_TIME_Absolute now; 1233 struct GNUNET_TIME_Absolute now;
1219 struct FindReceiveContext frc; 1234 struct FindReceiveContext frc;
1220 struct Session * s = NULL; 1235 struct Session *s = NULL;
1221 struct GNUNET_TIME_Relative flow_delay; 1236 struct GNUNET_TIME_Relative flow_delay;
1222 1237
1223 fromlen = sizeof (addr); 1238 fromlen = sizeof (addr);
@@ -1233,8 +1248,8 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
1233 msg = (const struct GNUNET_MessageHeader *) buf; 1248 msg = (const struct GNUNET_MessageHeader *) buf;
1234 1249
1235 LOG (GNUNET_ERROR_TYPE_DEBUG, 1250 LOG (GNUNET_ERROR_TYPE_DEBUG,
1236 "UDP received %u-byte message from `%s' type %i\n", (unsigned int) ret, 1251 "UDP received %u-byte message from `%s' type %i\n", (unsigned int) ret,
1237 GNUNET_a2s ((const struct sockaddr *) addr, fromlen), ntohs(msg->type)); 1252 GNUNET_a2s ((const struct sockaddr *) addr, fromlen), ntohs (msg->type));
1238 1253
1239 if (ret != ntohs (msg->size)) 1254 if (ret != ntohs (msg->size))
1240 { 1255 {
@@ -1261,27 +1276,29 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
1261 return; 1276 return;
1262 } 1277 }
1263 udp_ack = (const struct UDP_ACK_Message *) msg; 1278 udp_ack = (const struct UDP_ACK_Message *) msg;
1264 s = find_inbound_session(plugin, &udp_ack->sender, addr, fromlen); 1279 s = find_inbound_session (plugin, &udp_ack->sender, addr, fromlen);
1265 if (s != NULL) 1280 if (s != NULL)
1266 { 1281 {
1267 flow_delay.rel_value = (uint64_t) ntohl(udp_ack->delay); 1282 flow_delay.rel_value = (uint64_t) ntohl (udp_ack->delay);
1268 1283
1269 LOG (GNUNET_ERROR_TYPE_DEBUG, 1284 LOG (GNUNET_ERROR_TYPE_DEBUG, "We received a sending delay of %llu\n",
1270 "We received a sending delay of %llu\n", flow_delay.rel_value); 1285 flow_delay.rel_value);
1271 1286
1272 s->flow_delay_from_other_peer = GNUNET_TIME_relative_to_absolute (flow_delay); 1287 s->flow_delay_from_other_peer =
1288 GNUNET_TIME_relative_to_absolute (flow_delay);
1273 } 1289 }
1274 ack = (const struct GNUNET_MessageHeader *) &udp_ack[1]; 1290 ack = (const struct GNUNET_MessageHeader *) &udp_ack[1];
1275 if (ntohs (ack->size) != ntohs (msg->size) - sizeof (struct UDP_ACK_Message)) 1291 if (ntohs (ack->size) !=
1292 ntohs (msg->size) - sizeof (struct UDP_ACK_Message))
1276 { 1293 {
1277 GNUNET_break_op (0); 1294 GNUNET_break_op (0);
1278 return; 1295 return;
1279 } 1296 }
1280#if DEBUG_UDP 1297#if DEBUG_UDP
1281 LOG (GNUNET_ERROR_TYPE_DEBUG, 1298 LOG (GNUNET_ERROR_TYPE_DEBUG,
1282 "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", 1299 "UDP processes %u-byte acknowledgement from `%s' at `%s'\n",
1283 (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp_ack->sender), 1300 (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp_ack->sender),
1284 GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); 1301 GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
1285#endif 1302#endif
1286 1303
1287 peer_session = find_session (plugin, &udp_ack->sender); 1304 peer_session = find_session (plugin, &udp_ack->sender);
@@ -1289,7 +1306,7 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
1289 { 1306 {
1290#if DEBUG_UDP 1307#if DEBUG_UDP
1291 LOG (GNUNET_ERROR_TYPE_DEBUG, 1308 LOG (GNUNET_ERROR_TYPE_DEBUG,
1292 "Session for ACK not found, dropping ACK!\n"); 1309 "Session for ACK not found, dropping ACK!\n");
1293#endif 1310#endif
1294 return; 1311 return;
1295 } 1312 }
@@ -1332,10 +1349,9 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
1332 now.abs_value); 1349 now.abs_value);
1333 } 1350 }
1334#if DEBUG_UDP 1351#if DEBUG_UDP
1335 LOG (GNUNET_ERROR_TYPE_DEBUG, 1352 LOG (GNUNET_ERROR_TYPE_DEBUG, "UDP processes %u-byte fragment from `%s'\n",
1336 "UDP processes %u-byte fragment from `%s'\n", 1353 (unsigned int) ntohs (msg->size),
1337 (unsigned int) ntohs (msg->size), 1354 GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
1338 GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
1339#endif 1355#endif
1340 1356
1341 if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (rc->defrag, msg)) 1357 if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (rc->defrag, msg))
@@ -1395,40 +1411,43 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1395 1411
1396struct MstContext 1412struct MstContext
1397{ 1413{
1398 struct Plugin * plugin; 1414 struct Plugin *plugin;
1399 1415
1400 struct IPv4UdpAddress addr; 1416 struct IPv4UdpAddress addr;
1401}; 1417};
1402 1418
1403void udp_broadcast_mst_cb (void *cls, void *client, 1419void
1404 const struct 1420udp_broadcast_mst_cb (void *cls, void *client,
1405 GNUNET_MessageHeader * 1421 const struct GNUNET_MessageHeader *message)
1406 message)
1407{ 1422{
1408 struct Plugin * plugin = cls; 1423 struct Plugin *plugin = cls;
1409 struct MstContext * mc = client; 1424 struct MstContext *mc = client;
1410 const struct GNUNET_MessageHeader* hello; 1425 const struct GNUNET_MessageHeader *hello;
1411 struct UDP_Beacon_Message * msg; 1426 struct UDP_Beacon_Message *msg;
1427
1412 msg = (struct UDP_Beacon_Message *) message; 1428 msg = (struct UDP_Beacon_Message *) message;
1413 1429
1414 if (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON != ntohs(msg->header.type)) 1430 if (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON !=
1431 ntohs (msg->header.type))
1415 return; 1432 return;
1416 1433
1417 LOG (GNUNET_ERROR_TYPE_ERROR, 1434 LOG (GNUNET_ERROR_TYPE_ERROR,
1418 "Received beacon with %u bytes from peer `%s' via address `%s'\n", 1435 "Received beacon with %u bytes from peer `%s' via address `%s'\n",
1419 ntohs(msg->header.size), 1436 ntohs (msg->header.size), GNUNET_i2s (&msg->sender),
1420 GNUNET_i2s (&msg->sender), 1437 udp_address_to_string (NULL, &mc->addr, sizeof (mc->addr)));
1421 udp_address_to_string(NULL, &mc->addr, sizeof (mc->addr)));
1422 1438
1423 struct GNUNET_ATS_Information ats; 1439 struct GNUNET_ATS_Information ats;
1440
1424 ats.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); 1441 ats.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
1425 ats.value = htonl (1); 1442 ats.value = htonl (1);
1426 1443
1427 hello = (struct GNUNET_MessageHeader *) &msg[1]; 1444 hello = (struct GNUNET_MessageHeader *) &msg[1];
1428 plugin->env->receive (plugin->env->cls, &msg->sender, hello, &ats, 1, NULL, (const char *) &mc->addr, sizeof (mc->addr)); 1445 plugin->env->receive (plugin->env->cls, &msg->sender, hello, &ats, 1, NULL,
1446 (const char *) &mc->addr, sizeof (mc->addr));
1429 1447
1430 GNUNET_STATISTICS_update(plugin->env->stats, 1448 GNUNET_STATISTICS_update (plugin->env->stats,
1431 _("# HELLO beacons received via udp"), 1, GNUNET_NO); 1449 _("# HELLO beacons received via udp"), 1,
1450 GNUNET_NO);
1432 GNUNET_free (mc); 1451 GNUNET_free (mc);
1433} 1452}
1434 1453
@@ -1445,54 +1464,61 @@ udp_broadcast_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
1445 char addr[32]; 1464 char addr[32];
1446 char buf[65536]; 1465 char buf[65536];
1447 ssize_t ret; 1466 ssize_t ret;
1448 struct MstContext * mc; 1467 struct MstContext *mc;
1449 1468
1450 1469
1451 fromlen = sizeof (addr); 1470 fromlen = sizeof (addr);
1452 memset (&addr, 0, sizeof (addr)); 1471 memset (&addr, 0, sizeof (addr));
1453 ret = GNUNET_NETWORK_socket_recvfrom (rsock, buf, sizeof (buf), (struct sockaddr *) &addr, &fromlen); 1472 ret =
1473 GNUNET_NETWORK_socket_recvfrom (rsock, buf, sizeof (buf),
1474 (struct sockaddr *) &addr, &fromlen);
1454 if (ret < sizeof (struct GNUNET_MessageHeader)) 1475 if (ret < sizeof (struct GNUNET_MessageHeader))
1455 { 1476 {
1456 /* malformed beacon, just throw it away */ 1477 /* malformed beacon, just throw it away */
1457 return; 1478 return;
1458 } 1479 }
1459 1480
1460 mc = GNUNET_malloc(sizeof (struct MstContext)); 1481 mc = GNUNET_malloc (sizeof (struct MstContext));
1482
1483 struct sockaddr_in *av4 = (struct sockaddr_in *) &addr;
1461 1484
1462 struct sockaddr_in * av4 = (struct sockaddr_in *) &addr;
1463 mc->addr.ipv4_addr = av4->sin_addr.s_addr; 1485 mc->addr.ipv4_addr = av4->sin_addr.s_addr;
1464 mc->addr.u4_port = av4->sin_port; 1486 mc->addr.u4_port = av4->sin_port;
1465 1487
1466 if (GNUNET_OK != GNUNET_SERVER_mst_receive(plugin->broadcast_mst, mc, buf, ret, GNUNET_NO, GNUNET_NO)) 1488 if (GNUNET_OK !=
1489 GNUNET_SERVER_mst_receive (plugin->broadcast_mst, mc, buf, ret, GNUNET_NO,
1490 GNUNET_NO))
1467 GNUNET_free (mc); 1491 GNUNET_free (mc);
1468} 1492}
1469 1493
1470 1494
1471static void 1495static void
1472udp_broadcast_send (void *cls, 1496udp_broadcast_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1473 const struct GNUNET_SCHEDULER_TaskContext *tc)
1474{ 1497{
1475 struct Plugin * plugin = cls; 1498 struct Plugin *plugin = cls;
1476 int sent; 1499 int sent;
1477 uint16_t msg_size; 1500 uint16_t msg_size;
1478 uint16_t hello_size; 1501 uint16_t hello_size;
1479 char buf[65536]; 1502 char buf[65536];
1503
1480// /ssize_t ret; 1504// /ssize_t ret;
1481 const struct GNUNET_MessageHeader *hello; 1505 const struct GNUNET_MessageHeader *hello;
1482 struct UDP_Beacon_Message * msg; 1506 struct UDP_Beacon_Message *msg;
1483 1507
1484 plugin->send_broadcast_task = GNUNET_SCHEDULER_NO_TASK; 1508 plugin->send_broadcast_task = GNUNET_SCHEDULER_NO_TASK;
1485 1509
1486 struct sockaddr_in baddr; 1510 struct sockaddr_in baddr;
1511
1487 baddr.sin_family = AF_INET; 1512 baddr.sin_family = AF_INET;
1488 baddr.sin_port = htons (plugin->broadcast_port); 1513 baddr.sin_port = htons (plugin->broadcast_port);
1489 baddr.sin_addr.s_addr=htonl(-1); /* send message to 255.255.255.255 */ 1514 baddr.sin_addr.s_addr = htonl (-1); /* send message to 255.255.255.255 */
1490 1515
1491 hello = plugin->env->get_our_hello (); 1516 hello = plugin->env->get_our_hello ();
1492 hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello); 1517 hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
1493 msg_size = hello_size + sizeof (struct UDP_Beacon_Message); 1518 msg_size = hello_size + sizeof (struct UDP_Beacon_Message);
1494 1519
1495 if (hello_size < (sizeof (struct GNUNET_MessageHeader)) ||(msg_size > (UDP_MTU))) 1520 if (hello_size < (sizeof (struct GNUNET_MessageHeader)) ||
1521 (msg_size > (UDP_MTU)))
1496 return; 1522 return;
1497 1523
1498 msg = (struct UDP_Beacon_Message *) buf; 1524 msg = (struct UDP_Beacon_Message *) buf;
@@ -1501,13 +1527,17 @@ udp_broadcast_send (void *cls,
1501 msg->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON); 1527 msg->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON);
1502 memcpy (&msg[1], hello, hello_size); 1528 memcpy (&msg[1], hello, hello_size);
1503 1529
1504 sent = GNUNET_NETWORK_socket_sendto (plugin->sockv4_broadcast, msg, msg_size, 1530 sent =
1505 (const struct sockaddr *) &baddr, sizeof (struct sockaddr_in)); 1531 GNUNET_NETWORK_socket_sendto (plugin->sockv4_broadcast, msg, msg_size,
1532 (const struct sockaddr *) &baddr,
1533 sizeof (struct sockaddr_in));
1506 1534
1507 LOG (GNUNET_ERROR_TYPE_DEBUG, 1535 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sent HELLO beacon broadcast with %i bytes\n",
1508 "Sent HELLO beacon broadcast with %i bytes\n", sent); 1536 sent);
1509 1537
1510 plugin->send_broadcast_task = GNUNET_SCHEDULER_add_delayed(plugin->broadcast_interval, &udp_broadcast_send, plugin); 1538 plugin->send_broadcast_task =
1539 GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval,
1540 &udp_broadcast_send, plugin);
1511 1541
1512} 1542}
1513 1543
@@ -1520,7 +1550,8 @@ udp_broadcast_send (void *cls,
1520 * @param tc the scheduling context (for rescheduling this function again) 1550 * @param tc the scheduling context (for rescheduling this function again)
1521 */ 1551 */
1522static void 1552static void
1523udp_plugin_broadcast_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 1553udp_plugin_broadcast_select (void *cls,
1554 const struct GNUNET_SCHEDULER_TaskContext *tc)
1524{ 1555{
1525 struct Plugin *plugin = cls; 1556 struct Plugin *plugin = cls;
1526 1557
@@ -1535,8 +1566,9 @@ udp_plugin_broadcast_select (void *cls, const struct GNUNET_SCHEDULER_TaskContex
1535 plugin->select_broadcast_task = 1566 plugin->select_broadcast_task =
1536 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 1567 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1537 GNUNET_SCHEDULER_NO_TASK, 1568 GNUNET_SCHEDULER_NO_TASK,
1538 GNUNET_TIME_UNIT_FOREVER_REL, plugin->broadcast_rs, 1569 GNUNET_TIME_UNIT_FOREVER_REL,
1539 NULL, &udp_plugin_broadcast_select, plugin); 1570 plugin->broadcast_rs, NULL,
1571 &udp_plugin_broadcast_select, plugin);
1540} 1572}
1541 1573
1542 1574
@@ -1664,7 +1696,7 @@ udp_address_to_string (void *cls, const void *addr, size_t addrlen)
1664 } 1696 }
1665 inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); 1697 inet_ntop (af, sb, buf, INET6_ADDRSTRLEN);
1666 GNUNET_snprintf (rbuf, sizeof (rbuf), (af == AF_INET6) ? "[%s]:%u" : "%s:%u", 1698 GNUNET_snprintf (rbuf, sizeof (rbuf), (af == AF_INET6) ? "[%s]:%u" : "%s:%u",
1667 buf, port); 1699 buf, port);
1668 return rbuf; 1700 return rbuf;
1669} 1701}
1670 1702
@@ -1868,16 +1900,20 @@ libgnunet_plugin_transport_udp_init (void *cls)
1868 &port)) 1900 &port))
1869 port = 2086; 1901 port = 2086;
1870 1902
1871 broadcast = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "transport-udp", "BROADCAST"); 1903 broadcast =
1872 if (broadcast == GNUNET_SYSERR) 1904 GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "transport-udp",
1873 broadcast = GNUNET_NO; 1905 "BROADCAST");
1906 if (broadcast == GNUNET_SYSERR)
1907 broadcast = GNUNET_NO;
1874 1908
1875 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (env->cfg, "transport-udp", "BROADCAST_INTERVAL", &interval)) 1909 if (GNUNET_SYSERR ==
1876 interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10); 1910 GNUNET_CONFIGURATION_get_value_time (env->cfg, "transport-udp",
1911 "BROADCAST_INTERVAL", &interval))
1912 interval = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10);
1877 1913
1878 if (GNUNET_OK != 1914 if (GNUNET_OK !=
1879 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", "BROADCAST_PORT", 1915 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp",
1880 &bport)) 1916 "BROADCAST_PORT", &bport))
1881 bport = 20086; 1917 bport = 20086;
1882 1918
1883 if (GNUNET_OK != 1919 if (GNUNET_OK !=
@@ -1891,8 +1927,8 @@ libgnunet_plugin_transport_udp_init (void *cls)
1891 if (port > 65535) 1927 if (port > 65535)
1892 { 1928 {
1893 LOG (GNUNET_ERROR_TYPE_WARNING, 1929 LOG (GNUNET_ERROR_TYPE_WARNING,
1894 _("Given `%s' option is out of range: %llu > %u\n"), "PORT", 1930 _("Given `%s' option is out of range: %llu > %u\n"), "PORT", port,
1895 port, 65535); 1931 65535);
1896 return NULL; 1932 return NULL;
1897 } 1933 }
1898 memset (&serverAddrv6, 0, sizeof (serverAddrv6)); 1934 memset (&serverAddrv6, 0, sizeof (serverAddrv6));
@@ -1923,8 +1959,8 @@ libgnunet_plugin_transport_udp_init (void *cls)
1923 "BINDTO", &plugin->bind4_address)) 1959 "BINDTO", &plugin->bind4_address))
1924 { 1960 {
1925 LOG (GNUNET_ERROR_TYPE_DEBUG, 1961 LOG (GNUNET_ERROR_TYPE_DEBUG,
1926 "Binding udp plugin to specific address: `%s'\n", 1962 "Binding udp plugin to specific address: `%s'\n",
1927 plugin->bind4_address); 1963 plugin->bind4_address);
1928 if (1 != inet_pton (AF_INET, plugin->bind4_address, &serverAddrv4.sin_addr)) 1964 if (1 != inet_pton (AF_INET, plugin->bind4_address, &serverAddrv4.sin_addr))
1929 { 1965 {
1930 GNUNET_free (plugin->bind4_address); 1966 GNUNET_free (plugin->bind4_address);
@@ -1939,13 +1975,13 @@ libgnunet_plugin_transport_udp_init (void *cls)
1939 "BINDTO6", &plugin->bind6_address)) 1975 "BINDTO6", &plugin->bind6_address))
1940 { 1976 {
1941 LOG (GNUNET_ERROR_TYPE_DEBUG, 1977 LOG (GNUNET_ERROR_TYPE_DEBUG,
1942 "Binding udp plugin to specific address: `%s'\n", 1978 "Binding udp plugin to specific address: `%s'\n",
1943 plugin->bind6_address); 1979 plugin->bind6_address);
1944 if (1 != 1980 if (1 !=
1945 inet_pton (AF_INET6, plugin->bind6_address, &serverAddrv6.sin6_addr)) 1981 inet_pton (AF_INET6, plugin->bind6_address, &serverAddrv6.sin6_addr))
1946 { 1982 {
1947 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid IPv6 address: `%s'\n"), 1983 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid IPv6 address: `%s'\n"),
1948 plugin->bind6_address); 1984 plugin->bind6_address);
1949 GNUNET_free_non_null (plugin->bind4_address); 1985 GNUNET_free_non_null (plugin->bind4_address);
1950 GNUNET_free (plugin->bind6_address); 1986 GNUNET_free (plugin->bind6_address);
1951 GNUNET_free (plugin); 1987 GNUNET_free (plugin);
@@ -1984,7 +2020,7 @@ libgnunet_plugin_transport_udp_init (void *cls)
1984 serverAddr = (struct sockaddr *) &serverAddrv6; 2020 serverAddr = (struct sockaddr *) &serverAddrv6;
1985#if DEBUG_UDP 2021#if DEBUG_UDP
1986 LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv6 port %d\n", 2022 LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv6 port %d\n",
1987 ntohs (serverAddrv6.sin6_port)); 2023 ntohs (serverAddrv6.sin6_port));
1988#endif 2024#endif
1989 tries = 0; 2025 tries = 0;
1990 while (GNUNET_NETWORK_socket_bind (plugin->sockv6, serverAddr, addrlen) != 2026 while (GNUNET_NETWORK_socket_bind (plugin->sockv6, serverAddr, addrlen) !=
@@ -1993,8 +2029,8 @@ libgnunet_plugin_transport_udp_init (void *cls)
1993 serverAddrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ 2029 serverAddrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */
1994#if DEBUG_UDP 2030#if DEBUG_UDP
1995 LOG (GNUNET_ERROR_TYPE_DEBUG, 2031 LOG (GNUNET_ERROR_TYPE_DEBUG,
1996 "IPv6 Binding failed, trying new port %d\n", 2032 "IPv6 Binding failed, trying new port %d\n",
1997 ntohs (serverAddrv6.sin6_port)); 2033 ntohs (serverAddrv6.sin6_port));
1998#endif 2034#endif
1999 tries++; 2035 tries++;
2000 if (tries > 10) 2036 if (tries > 10)
@@ -2032,7 +2068,7 @@ libgnunet_plugin_transport_udp_init (void *cls)
2032 serverAddr = (struct sockaddr *) &serverAddrv4; 2068 serverAddr = (struct sockaddr *) &serverAddrv4;
2033#if DEBUG_UDP 2069#if DEBUG_UDP
2034 LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv4 port %d\n", 2070 LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv4 port %d\n",
2035 ntohs (serverAddrv4.sin_port)); 2071 ntohs (serverAddrv4.sin_port));
2036#endif 2072#endif
2037 tries = 0; 2073 tries = 0;
2038 while (GNUNET_NETWORK_socket_bind (plugin->sockv4, serverAddr, addrlen) != 2074 while (GNUNET_NETWORK_socket_bind (plugin->sockv4, serverAddr, addrlen) !=
@@ -2040,9 +2076,8 @@ libgnunet_plugin_transport_udp_init (void *cls)
2040 { 2076 {
2041 serverAddrv4.sin_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ 2077 serverAddrv4.sin_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */
2042#if DEBUG_UDP 2078#if DEBUG_UDP
2043 LOG (GNUNET_ERROR_TYPE_DEBUG, 2079 LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv4 Binding failed, trying new port %d\n",
2044 "IPv4 Binding failed, trying new port %d\n", 2080 ntohs (serverAddrv4.sin_port));
2045 ntohs (serverAddrv4.sin_port));
2046#endif 2081#endif
2047 tries++; 2082 tries++;
2048 if (tries > 10) 2083 if (tries > 10)
@@ -2077,47 +2112,56 @@ libgnunet_plugin_transport_udp_init (void *cls)
2077 /* create broadcast socket */ 2112 /* create broadcast socket */
2078 if (broadcast) 2113 if (broadcast)
2079 { 2114 {
2080 plugin->sockv4_broadcast = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0); 2115 plugin->sockv4_broadcast =
2116 GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0);
2081 if (NULL == plugin->sockv4_broadcast) 2117 if (NULL == plugin->sockv4_broadcast)
2082 { 2118 {
2083 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket"); 2119 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
2084 } 2120 }
2085 else 2121 else
2086 { 2122 {
2087 #if HAVE_SOCKADDR_IN_SIN_LEN 2123#if HAVE_SOCKADDR_IN_SIN_LEN
2088 serverAddrv4.sin_len = sizeof (serverAddrv4); 2124 serverAddrv4.sin_len = sizeof (serverAddrv4);
2089 #endif 2125#endif
2090 serverAddrv4.sin_family = AF_INET; 2126 serverAddrv4.sin_family = AF_INET;
2091 serverAddrv4.sin_addr.s_addr = INADDR_ANY; 2127 serverAddrv4.sin_addr.s_addr = INADDR_ANY;
2092 serverAddrv4.sin_port = htons (plugin->broadcast_port); 2128 serverAddrv4.sin_port = htons (plugin->broadcast_port);
2093 addrlen = sizeof (serverAddrv4); 2129 addrlen = sizeof (serverAddrv4);
2094 serverAddr = (struct sockaddr *) &serverAddrv4; 2130 serverAddr = (struct sockaddr *) &serverAddrv4;
2095 #if DEBUG_UDP 2131#if DEBUG_UDP
2096 #endif 2132#endif
2097 LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding Broadcast to IPv4 port %d\n", 2133 LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding Broadcast to IPv4 port %d\n",
2098 ntohs (serverAddrv4.sin_port)); 2134 ntohs (serverAddrv4.sin_port));
2099 2135
2100 if (GNUNET_NETWORK_socket_bind (plugin->sockv4_broadcast, serverAddr, addrlen) != GNUNET_OK) 2136 if (GNUNET_NETWORK_socket_bind
2137 (plugin->sockv4_broadcast, serverAddr, addrlen) != GNUNET_OK)
2101 { 2138 {
2102 LOG (GNUNET_ERROR_TYPE_WARNING, _("Failed to create IPv4 broadcast socket on port %d\n"), 2139 LOG (GNUNET_ERROR_TYPE_WARNING,
2103 ntohs (serverAddrv4.sin_port)); 2140 _("Failed to create IPv4 broadcast socket on port %d\n"),
2104 GNUNET_NETWORK_socket_close (plugin->sockv4_broadcast); 2141 ntohs (serverAddrv4.sin_port));
2105 plugin->sockv4_broadcast = NULL; 2142 GNUNET_NETWORK_socket_close (plugin->sockv4_broadcast);
2143 plugin->sockv4_broadcast = NULL;
2106 } 2144 }
2107 if (plugin->sockv4_broadcast != NULL) 2145 if (plugin->sockv4_broadcast != NULL)
2108 { 2146 {
2109 int yes = 1; 2147 int yes = 1;
2110 if (GNUNET_NETWORK_socket_setsockopt (plugin->sockv4_broadcast, SOL_SOCKET, SO_BROADCAST, &yes, sizeof(int)) != GNUNET_OK) 2148
2149 if (GNUNET_NETWORK_socket_setsockopt
2150 (plugin->sockv4_broadcast, SOL_SOCKET, SO_BROADCAST, &yes,
2151 sizeof (int)) != GNUNET_OK)
2111 { 2152 {
2112 LOG (GNUNET_ERROR_TYPE_WARNING, _("Failed to set IPv4 broadcast option for broadcast socket on port %d\n"), 2153 LOG (GNUNET_ERROR_TYPE_WARNING,
2113 ntohs (serverAddrv4.sin_port)); 2154 _
2114 GNUNET_NETWORK_socket_close(plugin->sockv4_broadcast); 2155 ("Failed to set IPv4 broadcast option for broadcast socket on port %d\n"),
2156 ntohs (serverAddrv4.sin_port));
2157 GNUNET_NETWORK_socket_close (plugin->sockv4_broadcast);
2115 plugin->sockv4_broadcast = NULL; 2158 plugin->sockv4_broadcast = NULL;
2116 } 2159 }
2117 else 2160 else
2118 { 2161 {
2119 plugin->broadcast_rs = GNUNET_NETWORK_fdset_create (); 2162 plugin->broadcast_rs = GNUNET_NETWORK_fdset_create ();
2120 GNUNET_NETWORK_fdset_set (plugin->broadcast_rs, plugin->sockv4_broadcast); 2163 GNUNET_NETWORK_fdset_set (plugin->broadcast_rs,
2164 plugin->sockv4_broadcast);
2121 } 2165 }
2122 } 2166 }
2123 } 2167 }
@@ -2125,16 +2169,20 @@ libgnunet_plugin_transport_udp_init (void *cls)
2125 if (plugin->sockv4_broadcast != NULL) 2169 if (plugin->sockv4_broadcast != NULL)
2126 { 2170 {
2127 plugin->broadcast = GNUNET_YES; 2171 plugin->broadcast = GNUNET_YES;
2128 plugin->broadcast_mst = GNUNET_SERVER_mst_create (udp_broadcast_mst_cb, plugin); 2172 plugin->broadcast_mst =
2129 GNUNET_STATISTICS_update(plugin->env->stats, 2173 GNUNET_SERVER_mst_create (udp_broadcast_mst_cb, plugin);
2130 _("# HELLO beacons received via udp"), 1, GNUNET_NO); 2174 GNUNET_STATISTICS_update (plugin->env->stats,
2175 _("# HELLO beacons received via udp"), 1,
2176 GNUNET_NO);
2131 plugin->select_broadcast_task = 2177 plugin->select_broadcast_task =
2132 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 2178 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
2133 GNUNET_SCHEDULER_NO_TASK, 2179 GNUNET_SCHEDULER_NO_TASK,
2134 GNUNET_TIME_UNIT_FOREVER_REL, plugin->broadcast_rs, 2180 GNUNET_TIME_UNIT_FOREVER_REL,
2135 NULL, &udp_plugin_broadcast_select, plugin); 2181 plugin->broadcast_rs, NULL,
2136 2182 &udp_plugin_broadcast_select, plugin);
2137 plugin->send_broadcast_task = GNUNET_SCHEDULER_add_now (&udp_broadcast_send, plugin); 2183
2184 plugin->send_broadcast_task =
2185 GNUNET_SCHEDULER_add_now (&udp_broadcast_send, plugin);
2138 } 2186 }
2139 else 2187 else
2140 plugin->broadcast = GNUNET_NO; 2188 plugin->broadcast = GNUNET_NO;
@@ -2167,8 +2215,8 @@ libgnunet_plugin_transport_udp_done (void *cls)
2167 NULL); 2215 NULL);
2168 GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions); 2216 GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions);
2169 plugin->sessions = NULL; 2217 plugin->sessions = NULL;
2170 GNUNET_CONTAINER_multihashmap_iterate (plugin->inbound_sessions, &destroy_inbound_session, 2218 GNUNET_CONTAINER_multihashmap_iterate (plugin->inbound_sessions,
2171 NULL); 2219 &destroy_inbound_session, NULL);
2172 GNUNET_CONTAINER_multihashmap_destroy (plugin->inbound_sessions); 2220 GNUNET_CONTAINER_multihashmap_destroy (plugin->inbound_sessions);
2173 plugin->inbound_sessions = NULL; 2221 plugin->inbound_sessions = NULL;
2174 while (NULL != (rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags))) 2222 while (NULL != (rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags)))
@@ -2201,16 +2249,17 @@ libgnunet_plugin_transport_udp_done (void *cls)
2201 GNUNET_SCHEDULER_cancel (plugin->select_broadcast_task); 2249 GNUNET_SCHEDULER_cancel (plugin->select_broadcast_task);
2202 plugin->select_broadcast_task = GNUNET_SCHEDULER_NO_TASK; 2250 plugin->select_broadcast_task = GNUNET_SCHEDULER_NO_TASK;
2203 } 2251 }
2204 if (plugin->send_broadcast_task != GNUNET_SCHEDULER_NO_TASK) 2252 if (plugin->send_broadcast_task != GNUNET_SCHEDULER_NO_TASK)
2205 { 2253 {
2206 GNUNET_SCHEDULER_cancel (plugin->send_broadcast_task ); 2254 GNUNET_SCHEDULER_cancel (plugin->send_broadcast_task);
2207 plugin->send_broadcast_task = GNUNET_SCHEDULER_NO_TASK; 2255 plugin->send_broadcast_task = GNUNET_SCHEDULER_NO_TASK;
2208 } 2256 }
2209 if (plugin->broadcast_mst != NULL) 2257 if (plugin->broadcast_mst != NULL)
2210 GNUNET_SERVER_mst_destroy(plugin->broadcast_mst); 2258 GNUNET_SERVER_mst_destroy (plugin->broadcast_mst);
2211 if (plugin->sockv4_broadcast != NULL) 2259 if (plugin->sockv4_broadcast != NULL)
2212 { 2260 {
2213 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4_broadcast)); 2261 GNUNET_break (GNUNET_OK ==
2262 GNUNET_NETWORK_socket_close (plugin->sockv4_broadcast));
2214 plugin->sockv4_broadcast = NULL; 2263 plugin->sockv4_broadcast = NULL;
2215 } 2264 }
2216 GNUNET_NETWORK_fdset_destroy (plugin->broadcast_rs); 2265 GNUNET_NETWORK_fdset_destroy (plugin->broadcast_rs);
diff --git a/src/transport/plugin_transport_udp_new.c b/src/transport/plugin_transport_udp_new.c
index 325c5d893..7eb4cbe87 100644
--- a/src/transport/plugin_transport_udp_new.c
+++ b/src/transport/plugin_transport_udp_new.c
@@ -299,21 +299,22 @@ struct Plugin
299 299
300}; 300};
301 301
302int delete_session_iterator (void *cls, 302int
303 const GNUNET_HashCode * key, 303delete_session_iterator (void *cls, const GNUNET_HashCode * key, void *value)
304 void *value)
305{ 304{
306 struct Session *s = (struct Session *) value; 305 struct Session *s = (struct Session *) value;
306
307 if (s->invalidation_task != GNUNET_SCHEDULER_NO_TASK) 307 if (s->invalidation_task != GNUNET_SCHEDULER_NO_TASK)
308 { 308 {
309 GNUNET_SCHEDULER_cancel(s->invalidation_task); 309 GNUNET_SCHEDULER_cancel (s->invalidation_task);
310 s->invalidation_task = GNUNET_SCHEDULER_NO_TASK; 310 s->invalidation_task = GNUNET_SCHEDULER_NO_TASK;
311 } 311 }
312 GNUNET_CONTAINER_multihashmap_remove(s->plugin->sessions, key, s); 312 GNUNET_CONTAINER_multihashmap_remove (s->plugin->sessions, key, s);
313 313
314 GNUNET_free (s); 314 GNUNET_free (s);
315 return GNUNET_YES; 315 return GNUNET_YES;
316} 316}
317
317/** 318/**
318 * Disconnect from a remote node. Clean up session if we have one for this peer 319 * Disconnect from a remote node. Clean up session if we have one for this peer
319 * 320 *
@@ -326,7 +327,8 @@ udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
326{ 327{
327 struct Plugin *plugin = cls; 328 struct Plugin *plugin = cls;
328 329
329 GNUNET_CONTAINER_multihashmap_get_multiple(plugin, &target->hashPubKey, &delete_session_iterator, NULL); 330 GNUNET_CONTAINER_multihashmap_get_multiple (plugin, &target->hashPubKey,
331 &delete_session_iterator, NULL);
330 332
331} 333}
332 334
@@ -370,25 +372,25 @@ udp_send (struct Plugin *plugin, const struct sockaddr *sa,
370 { 372 {
371 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto"); 373 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto");
372 LOG (GNUNET_ERROR_TYPE_ERROR, 374 LOG (GNUNET_ERROR_TYPE_ERROR,
373 "UDP transmited %u-byte message to %s (%d: %s)\n", 375 "UDP transmited %u-byte message to %s (%d: %s)\n",
374 (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen), 376 (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen), (int) sent,
375 (int) sent, (sent < 0) ? STRERROR (errno) : "ok"); 377 (sent < 0) ? STRERROR (errno) : "ok");
376 378
377 } 379 }
378 LOG (GNUNET_ERROR_TYPE_DEBUG, 380 LOG (GNUNET_ERROR_TYPE_DEBUG,
379 "UDP transmited %u-byte message to %s (%d: %s)\n", 381 "UDP transmited %u-byte message to %s (%d: %s)\n",
380 (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen), 382 (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen), (int) sent,
381 (int) sent, (sent < 0) ? STRERROR (errno) : "ok"); 383 (sent < 0) ? STRERROR (errno) : "ok");
382 return sent; 384 return sent;
383} 385}
384 386
385 387
386static struct Session * 388static struct Session *
387create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, 389create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
388 const void *addr, size_t addrlen, 390 const void *addr, size_t addrlen,
389 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) 391 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
390{ 392{
391 struct Session * s; 393 struct Session *s;
392 const struct IPv4UdpAddress *t4; 394 const struct IPv4UdpAddress *t4;
393 const struct IPv6UdpAddress *t6; 395 const struct IPv6UdpAddress *t6;
394 struct sockaddr_in *v4; 396 struct sockaddr_in *v4;
@@ -403,9 +405,7 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
403 return NULL; 405 return NULL;
404 } 406 }
405 t4 = addr; 407 t4 = addr;
406 s = 408 s = GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in));
407 GNUNET_malloc (sizeof (struct Session) +
408 sizeof (struct sockaddr_in));
409 len = sizeof (struct sockaddr_in); 409 len = sizeof (struct sockaddr_in);
410 v4 = (struct sockaddr_in *) &s[1]; 410 v4 = (struct sockaddr_in *) &s[1];
411 v4->sin_family = AF_INET; 411 v4->sin_family = AF_INET;
@@ -421,9 +421,7 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
421 return NULL; 421 return NULL;
422 } 422 }
423 t6 = addr; 423 t6 = addr;
424 s = 424 s = GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in6));
425 GNUNET_malloc (sizeof (struct Session) +
426 sizeof (struct sockaddr_in6));
427 len = sizeof (struct sockaddr_in6); 425 len = sizeof (struct sockaddr_in6);
428 v6 = (struct sockaddr_in6 *) &s[1]; 426 v6 = (struct sockaddr_in6 *) &s[1];
429 v6->sin6_family = AF_INET6; 427 v6->sin6_family = AF_INET6;
@@ -457,13 +455,17 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
457static void 455static void
458invalidation_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 456invalidation_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
459{ 457{
460 struct Session * s = cls; 458 struct Session *s = cls;
461 s->invalidation_task = GNUNET_SCHEDULER_NO_TASK;
462 LOG (GNUNET_ERROR_TYPE_ERROR,
463 "Session %X (`%s') is now invalid\n", s, GNUNET_a2s (s->sock_addr,s->addrlen));
464 459
465 s->plugin->env->session_end(s->plugin->env->cls, &s->target, s); 460 s->invalidation_task = GNUNET_SCHEDULER_NO_TASK;
466 GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(s->plugin->sessions, &s->target.hashPubKey, s)); 461 LOG (GNUNET_ERROR_TYPE_ERROR, "Session %X (`%s') is now invalid\n", s,
462 GNUNET_a2s (s->sock_addr, s->addrlen));
463
464 s->plugin->env->session_end (s->plugin->env->cls, &s->target, s);
465 GNUNET_assert (GNUNET_YES ==
466 GNUNET_CONTAINER_multihashmap_remove (s->plugin->sessions,
467 &s->target.hashPubKey,
468 s));
467 GNUNET_free (s); 469 GNUNET_free (s);
468} 470}
469 471
@@ -534,10 +536,10 @@ udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
534 } 536 }
535 537
536 LOG (GNUNET_ERROR_TYPE_DEBUG, 538 LOG (GNUNET_ERROR_TYPE_DEBUG,
537 "UDP transmits %u-byte message to `%s' using address `%s' session 0x%X mode %i\n", 539 "UDP transmits %u-byte message to `%s' using address `%s' session 0x%X mode %i\n",
538 msgbuf_size, GNUNET_i2s (target), 540 msgbuf_size, GNUNET_i2s (target), udp_address_to_string (NULL, addr,
539 udp_address_to_string (NULL, addr, addrlen), 541 addrlen),
540 session, force_address); 542 session, force_address);
541 543
542 /* no valid address given */ 544 /* no valid address given */
543 if ((addr = NULL) || (addrlen == 0)) 545 if ((addr = NULL) || (addrlen == 0))
@@ -562,10 +564,13 @@ udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
562 if (force_address == GNUNET_SYSERR) 564 if (force_address == GNUNET_SYSERR)
563 return GNUNET_SYSERR; 565 return GNUNET_SYSERR;
564 /* create new session */ 566 /* create new session */
565 s = create_session(plugin, target, addr, addrlen, cont, cont_cls); 567 s = create_session (plugin, target, addr, addrlen, cont, cont_cls);
566 GNUNET_CONTAINER_multihashmap_put(plugin->sessions, &target->hashPubKey, s, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 568 GNUNET_CONTAINER_multihashmap_put (plugin->sessions, &target->hashPubKey, s,
569 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
567 /* schedule invalidation task */ 570 /* schedule invalidation task */
568 s->invalidation_task = GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &invalidation_task, NULL); 571 s->invalidation_task =
572 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
573 &invalidation_task, NULL);
569 } 574 }
570 575
571 /* Message */ 576 /* Message */
@@ -576,12 +581,16 @@ udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
576 udp->sender = *plugin->env->my_identity; 581 udp->sender = *plugin->env->my_identity;
577 memcpy (&udp[1], msgbuf, msgbuf_size); 582 memcpy (&udp[1], msgbuf, msgbuf_size);
578 583
579 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); 584 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
585
580 if (s->flow_delay_from_other_peer.abs_value > now.abs_value) 586 if (s->flow_delay_from_other_peer.abs_value > now.abs_value)
581 { 587 {
582 struct GNUNET_TIME_Relative delta = GNUNET_TIME_absolute_get_difference(now, s->flow_delay_from_other_peer); 588 struct GNUNET_TIME_Relative delta =
583 LOG (GNUNET_ERROR_TYPE_DEBUG, 589 GNUNET_TIME_absolute_get_difference (now,
584 "We try to send to early! Should in %llu!\n", delta.rel_value); 590 s->flow_delay_from_other_peer);
591
592 LOG (GNUNET_ERROR_TYPE_DEBUG, "We try to send to early! Should in %llu!\n",
593 delta.rel_value);
585 } 594 }
586 else 595 else
587 LOG (GNUNET_ERROR_TYPE_DEBUG, "We can send!\n"); 596 LOG (GNUNET_ERROR_TYPE_DEBUG, "We can send!\n");
@@ -598,11 +607,11 @@ udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
598 /* send with fragmentation */ 607 /* send with fragmentation */
599 else 608 else
600 { 609 {
601 s->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats, UDP_MTU, 610 s->frag =
611 GNUNET_FRAGMENT_context_create (plugin->env->stats, UDP_MTU,
602 &plugin->tracker, 612 &plugin->tracker,
603 plugin->last_expected_delay, 613 plugin->last_expected_delay,
604 &udp->header, &send_fragment, 614 &udp->header, &send_fragment, s);
605 s);
606 } 615 }
607 return mlen; 616 return mlen;
608} 617}
@@ -621,7 +630,7 @@ process_inbound_tokenized_messages (void *cls, void *client,
621 const struct GNUNET_MessageHeader *hdr) 630 const struct GNUNET_MessageHeader *hdr)
622{ 631{
623 struct Plugin *plugin = cls; 632 struct Plugin *plugin = cls;
624 struct Session * s = client; 633 struct Session *s = client;
625 struct GNUNET_ATS_Information distance; 634 struct GNUNET_ATS_Information distance;
626 struct GNUNET_TIME_Relative delay; 635 struct GNUNET_TIME_Relative delay;
627 636
@@ -629,11 +638,12 @@ process_inbound_tokenized_messages (void *cls, void *client,
629 distance.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); 638 distance.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
630 distance.value = htonl (1); 639 distance.value = htonl (1);
631 640
632 LOG (GNUNET_ERROR_TYPE_DEBUG, 641 LOG (GNUNET_ERROR_TYPE_DEBUG, "Giving Session %X %s to transport\n",
633 "Giving Session %X %s to transport\n", s->session, GNUNET_i2s(&s->target)); 642 s->session, GNUNET_i2s (&s->target));
634 delay = plugin->env->receive (plugin->env->cls, &s->target, hdr, &distance, 1, s, 643 delay =
635 // FIXME: USE UDP ADDRESSES!!!! 644 plugin->env->receive (plugin->env->cls, &s->target, hdr, &distance, 1, s,
636 s->sock_addr, s->addrlen); 645 // FIXME: USE UDP ADDRESSES!!!!
646 s->sock_addr, s->addrlen);
637 s->flow_delay_for_other_peer = delay; 647 s->flow_delay_for_other_peer = delay;
638} 648}
639 649
@@ -691,54 +701,54 @@ process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg,
691 } 701 }
692#if DEBUG_UDP 702#if DEBUG_UDP
693 LOG (GNUNET_ERROR_TYPE_DEBUG, 703 LOG (GNUNET_ERROR_TYPE_DEBUG,
694 "Received message with %u bytes from peer `%s' at `%s'\n", 704 "Received message with %u bytes from peer `%s' at `%s'\n",
695 (unsigned int) ntohs (msg->header.size), 705 (unsigned int) ntohs (msg->header.size), GNUNET_i2s (&msg->sender),
696 GNUNET_i2s (&msg->sender), GNUNET_a2s (sender_addr, 706 GNUNET_a2s (sender_addr, sender_addr_len));
697 sender_addr_len));
698#endif 707#endif
699 708
700 const struct UDPMessage * udp_msg = (const struct UDPMessage *) msg; 709 const struct UDPMessage *udp_msg = (const struct UDPMessage *) msg;
710
701 LOG (GNUNET_ERROR_TYPE_DEBUG, 711 LOG (GNUNET_ERROR_TYPE_DEBUG,
702 "Lookup inbound UDP sessions for peer `%s' address `%s'\n", 712 "Lookup inbound UDP sessions for peer `%s' address `%s'\n",
703 GNUNET_i2s (&udp_msg->sender), 713 GNUNET_i2s (&udp_msg->sender), udp_address_to_string (NULL, arg, args));
704 udp_address_to_string(NULL, arg, args));
705 714
706 /* create a session for inbound connections */ 715 /* create a session for inbound connections */
707 struct Session * s = NULL; 716 struct Session *s = NULL;
708 s = find_inbound_session (plugin, &udp_msg->sender, sender_addr, sender_addr_len); 717
718 s = find_inbound_session (plugin, &udp_msg->sender, sender_addr,
719 sender_addr_len);
709 720
710 if (s != NULL) 721 if (s != NULL)
711 { 722 {
712 LOG (GNUNET_ERROR_TYPE_DEBUG, 723 LOG (GNUNET_ERROR_TYPE_DEBUG,
713 "Found existing inbound UDP sessions 0x%X for peer `%s' address `%s'\n", 724 "Found existing inbound UDP sessions 0x%X for peer `%s' address `%s'\n",
714 s, 725 s, GNUNET_i2s (&s->target), udp_address_to_string (NULL, arg, args));
715 GNUNET_i2s (&s->target),
716 udp_address_to_string(NULL, arg, args));
717 } 726 }
718 else 727 else
719 { 728 {
720 s = create_session (plugin, &udp_msg->sender, arg, args, NULL, NULL); 729 s = create_session (plugin, &udp_msg->sender, arg, args, NULL, NULL);
721 LOG (GNUNET_ERROR_TYPE_DEBUG, 730 LOG (GNUNET_ERROR_TYPE_DEBUG,
722 "Creating inbound UDP sessions 0x%X for peer `%s' address `%s'\n", 731 "Creating inbound UDP sessions 0x%X for peer `%s' address `%s'\n", s,
723 s, 732 GNUNET_i2s (&s->target), udp_address_to_string (NULL, arg, args));
724 GNUNET_i2s (&s->target), 733
725 udp_address_to_string(NULL, arg, args)); 734 GNUNET_assert (GNUNET_OK ==
726 735 GNUNET_CONTAINER_multihashmap_put (plugin->sessions,
727 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (plugin->sessions, 736 &s->target.hashPubKey, s,
728 &s->target.hashPubKey, 737 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
729 s,
730 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
731 } 738 }
732 s->valid_until = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 739 s->valid_until =
740 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
741 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
733 if (s->invalidation_task != GNUNET_SCHEDULER_NO_TASK) 742 if (s->invalidation_task != GNUNET_SCHEDULER_NO_TASK)
734 { 743 {
735 GNUNET_SCHEDULER_cancel(s->invalidation_task); 744 GNUNET_SCHEDULER_cancel (s->invalidation_task);
736 s->invalidation_task = GNUNET_SCHEDULER_NO_TASK; 745 s->invalidation_task = GNUNET_SCHEDULER_NO_TASK;
737 LOG (GNUNET_ERROR_TYPE_DEBUG, 746 LOG (GNUNET_ERROR_TYPE_DEBUG, "Rescheduling %X' `%s'\n", s,
738 "Rescheduling %X' `%s'\n", 747 udp_address_to_string (NULL, arg, args));
739 s, udp_address_to_string(NULL, arg, args));
740 } 748 }
741 s->invalidation_task = GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &invalidation_task, s); 749 s->invalidation_task =
750 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
751 &invalidation_task, s);
742 /* we received from peer, so session is bidirectional and reliable */ 752 /* we received from peer, so session is bidirectional and reliable */
743 s->bidirectional = GNUNET_YES; 753 s->bidirectional = GNUNET_YES;
744 754
@@ -768,7 +778,7 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
768 struct ReceiveContext *rc; 778 struct ReceiveContext *rc;
769 struct GNUNET_TIME_Absolute now; 779 struct GNUNET_TIME_Absolute now;
770 struct FindReceiveContext frc; 780 struct FindReceiveContext frc;
771 struct Session * s = NULL; 781 struct Session *s = NULL;
772 struct GNUNET_TIME_Relative flow_delay; 782 struct GNUNET_TIME_Relative flow_delay;
773 783
774 fromlen = sizeof (addr); 784 fromlen = sizeof (addr);
@@ -784,8 +794,8 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
784 msg = (const struct GNUNET_MessageHeader *) buf; 794 msg = (const struct GNUNET_MessageHeader *) buf;
785 795
786 LOG (GNUNET_ERROR_TYPE_DEBUG, 796 LOG (GNUNET_ERROR_TYPE_DEBUG,
787 "UDP received %u-byte message from `%s' type %i\n", (unsigned int) ret, 797 "UDP received %u-byte message from `%s' type %i\n", (unsigned int) ret,
788 GNUNET_a2s ((const struct sockaddr *) addr, fromlen), ntohs(msg->type)); 798 GNUNET_a2s ((const struct sockaddr *) addr, fromlen), ntohs (msg->type));
789 799
790 if (ret != ntohs (msg->size)) 800 if (ret != ntohs (msg->size))
791 { 801 {
@@ -814,26 +824,25 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
814 } 824 }
815 udp_ack = (const struct UDP_ACK_Message *) msg; 825 udp_ack = (const struct UDP_ACK_Message *) msg;
816 LOG (GNUNET_ERROR_TYPE_DEBUG, 826 LOG (GNUNET_ERROR_TYPE_DEBUG,
817 "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", 827 "UDP processes %u-byte acknowledgement from `%s' at `%s'\n",
818 (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp->sender), 828 (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp->sender),
819 GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); 829 GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
820 830
821 // TODO Guess a session from address, give it defragmenter and check in process_udp if guess was right 831 // TODO Guess a session from address, give it defragmenter and check in process_udp if guess was right
822 s = guess_session (plugin->sessions, addr, addrlen); 832 s = guess_session (plugin->sessions, addr, addrlen);
823 if (GNUNET_OK != GNUNET_FRAGMENT_process_ack (peer_session->frag, ack)) 833 if (GNUNET_OK != GNUNET_FRAGMENT_process_ack (peer_session->frag, ack))
824 // ... other stuff 834 // ... other stuff
825 return; 835 return;
826 836
827 case GNUNET_MESSAGE_TYPE_FRAGMENT: 837 case GNUNET_MESSAGE_TYPE_FRAGMENT:
828 LOG (GNUNET_ERROR_TYPE_DEBUG, 838 LOG (GNUNET_ERROR_TYPE_DEBUG, "UDP processes %u-byte fragment from `%s'\n",
829 "UDP processes %u-byte fragment from `%s'\n", 839 (unsigned int) ntohs (msg->size),
830 (unsigned int) ntohs (msg->size), 840 GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
831 GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
832 // TODO Guess a session from address, give it defragmenter and check in process_udp if guess was right 841 // TODO Guess a session from address, give it defragmenter and check in process_udp if guess was right
833 s = guess_session (plugin->sessions, addr, addrlen); 842 s = guess_session (plugin->sessions, addr, addrlen);
834 if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (rc->defrag, msg)) 843 if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (rc->defrag, msg))
835 // other stuff 844 // other stuff
836 return; 845 return;
837 default: 846 default:
838 GNUNET_break_op (0); 847 GNUNET_break_op (0);
839 return; 848 return;
@@ -995,7 +1004,7 @@ udp_address_to_string (void *cls, const void *addr, size_t addrlen)
995 } 1004 }
996 inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); 1005 inet_ntop (af, sb, buf, INET6_ADDRSTRLEN);
997 GNUNET_snprintf (rbuf, sizeof (rbuf), (af == AF_INET6) ? "[%s]:%u" : "%s:%u", 1006 GNUNET_snprintf (rbuf, sizeof (rbuf), (af == AF_INET6) ? "[%s]:%u" : "%s:%u",
998 buf, port); 1007 buf, port);
999 return rbuf; 1008 return rbuf;
1000} 1009}
1001 1010
@@ -1206,8 +1215,8 @@ libgnunet_plugin_transport_udp_init (void *cls)
1206 if (port > 65535) 1215 if (port > 65535)
1207 { 1216 {
1208 LOG (GNUNET_ERROR_TYPE_WARNING, 1217 LOG (GNUNET_ERROR_TYPE_WARNING,
1209 _("Given `%s' option is out of range: %llu > %u\n"), "PORT", 1218 _("Given `%s' option is out of range: %llu > %u\n"), "PORT", port,
1210 port, 65535); 1219 65535);
1211 return NULL; 1220 return NULL;
1212 } 1221 }
1213 memset (&serverAddrv6, 0, sizeof (serverAddrv6)); 1222 memset (&serverAddrv6, 0, sizeof (serverAddrv6));
@@ -1235,8 +1244,8 @@ libgnunet_plugin_transport_udp_init (void *cls)
1235 "BINDTO", &plugin->bind4_address)) 1244 "BINDTO", &plugin->bind4_address))
1236 { 1245 {
1237 LOG (GNUNET_ERROR_TYPE_DEBUG, 1246 LOG (GNUNET_ERROR_TYPE_DEBUG,
1238 "Binding udp plugin to specific address: `%s'\n", 1247 "Binding udp plugin to specific address: `%s'\n",
1239 plugin->bind4_address); 1248 plugin->bind4_address);
1240 if (1 != inet_pton (AF_INET, plugin->bind4_address, &serverAddrv4.sin_addr)) 1249 if (1 != inet_pton (AF_INET, plugin->bind4_address, &serverAddrv4.sin_addr))
1241 { 1250 {
1242 GNUNET_free (plugin->bind4_address); 1251 GNUNET_free (plugin->bind4_address);
@@ -1251,13 +1260,13 @@ libgnunet_plugin_transport_udp_init (void *cls)
1251 "BINDTO6", &plugin->bind6_address)) 1260 "BINDTO6", &plugin->bind6_address))
1252 { 1261 {
1253 LOG (GNUNET_ERROR_TYPE_DEBUG, 1262 LOG (GNUNET_ERROR_TYPE_DEBUG,
1254 "Binding udp plugin to specific address: `%s'\n", 1263 "Binding udp plugin to specific address: `%s'\n",
1255 plugin->bind6_address); 1264 plugin->bind6_address);
1256 if (1 != 1265 if (1 !=
1257 inet_pton (AF_INET6, plugin->bind6_address, &serverAddrv6.sin6_addr)) 1266 inet_pton (AF_INET6, plugin->bind6_address, &serverAddrv6.sin6_addr))
1258 { 1267 {
1259 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid IPv6 address: `%s'\n"), 1268 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid IPv6 address: `%s'\n"),
1260 plugin->bind6_address); 1269 plugin->bind6_address);
1261 GNUNET_free_non_null (plugin->bind4_address); 1270 GNUNET_free_non_null (plugin->bind4_address);
1262 GNUNET_free (plugin->bind6_address); 1271 GNUNET_free (plugin->bind6_address);
1263 GNUNET_free (plugin); 1272 GNUNET_free (plugin);
@@ -1296,7 +1305,7 @@ libgnunet_plugin_transport_udp_init (void *cls)
1296 serverAddr = (struct sockaddr *) &serverAddrv6; 1305 serverAddr = (struct sockaddr *) &serverAddrv6;
1297#if DEBUG_UDP 1306#if DEBUG_UDP
1298 LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv6 port %d\n", 1307 LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv6 port %d\n",
1299 ntohs (serverAddrv6.sin6_port)); 1308 ntohs (serverAddrv6.sin6_port));
1300#endif 1309#endif
1301 tries = 0; 1310 tries = 0;
1302 while (GNUNET_NETWORK_socket_bind (plugin->sockv6, serverAddr, addrlen) != 1311 while (GNUNET_NETWORK_socket_bind (plugin->sockv6, serverAddr, addrlen) !=
@@ -1305,8 +1314,8 @@ libgnunet_plugin_transport_udp_init (void *cls)
1305 serverAddrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ 1314 serverAddrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */
1306#if DEBUG_UDP 1315#if DEBUG_UDP
1307 LOG (GNUNET_ERROR_TYPE_DEBUG, 1316 LOG (GNUNET_ERROR_TYPE_DEBUG,
1308 "IPv6 Binding failed, trying new port %d\n", 1317 "IPv6 Binding failed, trying new port %d\n",
1309 ntohs (serverAddrv6.sin6_port)); 1318 ntohs (serverAddrv6.sin6_port));
1310#endif 1319#endif
1311 tries++; 1320 tries++;
1312 if (tries > 10) 1321 if (tries > 10)
@@ -1344,7 +1353,7 @@ libgnunet_plugin_transport_udp_init (void *cls)
1344 serverAddr = (struct sockaddr *) &serverAddrv4; 1353 serverAddr = (struct sockaddr *) &serverAddrv4;
1345#if DEBUG_UDP 1354#if DEBUG_UDP
1346 LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv4 port %d\n", 1355 LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv4 port %d\n",
1347 ntohs (serverAddrv4.sin_port)); 1356 ntohs (serverAddrv4.sin_port));
1348#endif 1357#endif
1349 tries = 0; 1358 tries = 0;
1350 while (GNUNET_NETWORK_socket_bind (plugin->sockv4, serverAddr, addrlen) != 1359 while (GNUNET_NETWORK_socket_bind (plugin->sockv4, serverAddr, addrlen) !=
@@ -1352,9 +1361,8 @@ libgnunet_plugin_transport_udp_init (void *cls)
1352 { 1361 {
1353 serverAddrv4.sin_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ 1362 serverAddrv4.sin_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */
1354#if DEBUG_UDP 1363#if DEBUG_UDP
1355 LOG (GNUNET_ERROR_TYPE_DEBUG, 1364 LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv4 Binding failed, trying new port %d\n",
1356 "IPv4 Binding failed, trying new port %d\n", 1365 ntohs (serverAddrv4.sin_port));
1357 ntohs (serverAddrv4.sin_port));
1358#endif 1366#endif
1359 tries++; 1367 tries++;
1360 if (tries > 10) 1368 if (tries > 10)
@@ -1411,8 +1419,8 @@ libgnunet_plugin_transport_udp_done (void *cls)
1411 NULL); 1419 NULL);
1412 GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions); 1420 GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions);
1413 plugin->sessions = NULL; 1421 plugin->sessions = NULL;
1414 GNUNET_CONTAINER_multihashmap_iterate (plugin->inbound_sessions, &destroy_inbound_session, 1422 GNUNET_CONTAINER_multihashmap_iterate (plugin->inbound_sessions,
1415 NULL); 1423 &destroy_inbound_session, NULL);
1416 GNUNET_CONTAINER_multihashmap_destroy (plugin->inbound_sessions); 1424 GNUNET_CONTAINER_multihashmap_destroy (plugin->inbound_sessions);
1417 plugin->inbound_sessions = NULL; 1425 plugin->inbound_sessions = NULL;
1418 while (NULL != (rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags))) 1426 while (NULL != (rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags)))
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c
index 32f047d65..270829e68 100644
--- a/src/transport/plugin_transport_unix.c
+++ b/src/transport/plugin_transport_unix.c
@@ -731,9 +731,8 @@ unix_demultiplexer (struct Plugin *plugin, struct GNUNET_PeerIdentity *sender,
731 un->sun_path); 731 un->sun_path);
732#endif 732#endif
733 plugin->env->receive (plugin->env->cls, sender, currhdr, 733 plugin->env->receive (plugin->env->cls, sender, currhdr,
734 (const struct GNUNET_ATS_Information *) 734 (const struct GNUNET_ATS_Information *) &distance, 1,
735 &distance, 1, NULL, un->sun_path, 735 NULL, un->sun_path, strlen (un->sun_path) + 1);
736 strlen (un->sun_path) + 1);
737} 736}
738 737
739 738
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c
index 041e80f86..cbab8cb0f 100644
--- a/src/transport/plugin_transport_wlan.c
+++ b/src/transport/plugin_transport_wlan.c
@@ -862,7 +862,7 @@ session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
862 struct Sessionqueue *queue = cls; 862 struct Sessionqueue *queue = cls;
863 863
864 GNUNET_assert (queue != NULL); 864 GNUNET_assert (queue != NULL);
865 GNUNET_assert(queue->content != NULL); 865 GNUNET_assert (queue->content != NULL);
866 queue->content->timeout_task = GNUNET_SCHEDULER_NO_TASK; 866 queue->content->timeout_task = GNUNET_SCHEDULER_NO_TASK;
867 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) 867 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
868 { 868 {
@@ -873,9 +873,10 @@ session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
873 (queue->content->last_activity, SESSION_TIMEOUT)).rel_value == 0) 873 (queue->content->last_activity, SESSION_TIMEOUT)).rel_value == 0)
874 { 874 {
875 875
876 GNUNET_assert(queue->content->mac != NULL); 876 GNUNET_assert (queue->content->mac != NULL);
877 GNUNET_assert(queue->content->mac->plugin != NULL); 877 GNUNET_assert (queue->content->mac->plugin != NULL);
878 GNUNET_STATISTICS_update (queue->content->mac->plugin->env->stats, _("# wlan session timeouts"), 1, GNUNET_NO); 878 GNUNET_STATISTICS_update (queue->content->mac->plugin->env->stats,
879 _("# wlan session timeouts"), 1, GNUNET_NO);
879 free_session (queue->content->mac->plugin, queue, GNUNET_YES); 880 free_session (queue->content->mac->plugin, queue, GNUNET_YES);
880 } 881 }
881 else 882 else
@@ -900,7 +901,8 @@ create_session (struct Plugin *plugin, struct MacEndpoint *endpoint,
900{ 901{
901 GNUNET_assert (endpoint != NULL); 902 GNUNET_assert (endpoint != NULL);
902 GNUNET_assert (plugin != NULL); 903 GNUNET_assert (plugin != NULL);
903 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan session created"), 1, GNUNET_NO); 904 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan session created"), 1,
905 GNUNET_NO);
904 struct Sessionqueue *queue = 906 struct Sessionqueue *queue =
905 GNUNET_malloc (sizeof (struct Sessionqueue) + sizeof (struct Session)); 907 GNUNET_malloc (sizeof (struct Sessionqueue) + sizeof (struct Session));
906 908
@@ -983,7 +985,8 @@ queue_session (struct Plugin *plugin, struct Session *session)
983 GNUNET_CONTAINER_DLL_insert_tail (plugin->pending_Sessions_head, 985 GNUNET_CONTAINER_DLL_insert_tail (plugin->pending_Sessions_head,
984 plugin->pending_Sessions_tail, queue); 986 plugin->pending_Sessions_tail, queue);
985 plugin->pendingsessions++; 987 plugin->pendingsessions++;
986 GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending sessions"), plugin->pendingsessions, GNUNET_NO); 988 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
989 plugin->pendingsessions, GNUNET_NO);
987 } 990 }
988 991
989} 992}
@@ -1132,24 +1135,25 @@ get_next_queue_session (struct Plugin *plugin)
1132 pm = session->pending_message_head; 1135 pm = session->pending_message_head;
1133 1136
1134 if (pm == NULL) 1137 if (pm == NULL)
1135 { 1138 {
1136#if DEBUG_wlan 1139#if DEBUG_wlan
1137 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME, 1140 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1138 "pending message is empty, should not happen. session %p\n", 1141 "pending message is empty, should not happen. session %p\n",
1139 session); 1142 session);
1140#endif 1143#endif
1141 sessionqueue_alt = sessionqueue; 1144 sessionqueue_alt = sessionqueue;
1142 sessionqueue = sessionqueue->next; 1145 sessionqueue = sessionqueue->next;
1143 plugin->pendingsessions--; 1146 plugin->pendingsessions--;
1144 GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending sessions"), plugin->pendingsessions, GNUNET_NO); 1147 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
1145 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head, 1148 plugin->pendingsessions, GNUNET_NO);
1146 plugin->pending_Sessions_tail, 1149 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1147 sessionqueue_alt); 1150 plugin->pending_Sessions_tail,
1151 sessionqueue_alt);
1148 1152
1149 GNUNET_free (sessionqueue_alt); 1153 GNUNET_free (sessionqueue_alt);
1150 continue; 1154 continue;
1151 1155
1152 } 1156 }
1153 1157
1154 //check for message timeout 1158 //check for message timeout
1155 if (GNUNET_TIME_absolute_get_remaining (pm->timeout).rel_value > 0) 1159 if (GNUNET_TIME_absolute_get_remaining (pm->timeout).rel_value > 0)
@@ -1161,7 +1165,8 @@ get_next_queue_session (struct Plugin *plugin)
1161 FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION)) 1165 FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION))
1162 { 1166 {
1163 plugin->pendingsessions--; 1167 plugin->pendingsessions--;
1164 GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending sessions"), plugin->pendingsessions, GNUNET_NO); 1168 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
1169 plugin->pendingsessions, GNUNET_NO);
1165 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head, 1170 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1166 plugin->pending_Sessions_tail, 1171 plugin->pending_Sessions_tail,
1167 sessionqueue); 1172 sessionqueue);
@@ -1191,7 +1196,8 @@ get_next_queue_session (struct Plugin *plugin)
1191 sessionqueue_alt = sessionqueue; 1196 sessionqueue_alt = sessionqueue;
1192 sessionqueue = sessionqueue->next; 1197 sessionqueue = sessionqueue->next;
1193 plugin->pendingsessions--; 1198 plugin->pendingsessions--;
1194 GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending sessions"), plugin->pendingsessions, GNUNET_NO); 1199 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
1200 plugin->pendingsessions, GNUNET_NO);
1195 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head, 1201 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1196 plugin->pending_Sessions_tail, 1202 plugin->pending_Sessions_tail,
1197 sessionqueue_alt); 1203 sessionqueue_alt);
@@ -1217,38 +1223,40 @@ free_fragment_message (struct Plugin *plugin, struct FragmentMessage *fm)
1217 struct FragmentMessage_queue *fmq; 1223 struct FragmentMessage_queue *fmq;
1218 struct FragmentMessage_queue *fmq_next; 1224 struct FragmentMessage_queue *fmq_next;
1219 1225
1220 fmq = plugin->sending_messages_head; 1226 fmq = plugin->sending_messages_head;
1221 while (fmq != NULL) 1227 while (fmq != NULL)
1228 {
1229 fmq_next = fmq->next;
1230 if (fmq->content == fm)
1222 { 1231 {
1223 fmq_next = fmq->next; 1232 GNUNET_CONTAINER_DLL_remove (plugin->sending_messages_head,
1224 if (fmq->content == fm) 1233 plugin->sending_messages_tail, fmq);
1225 { 1234 GNUNET_free (fmq);
1226 GNUNET_CONTAINER_DLL_remove (plugin->sending_messages_head,
1227 plugin->sending_messages_tail, fmq);
1228 GNUNET_free (fmq);
1229 }
1230 fmq = fmq_next;
1231 } 1235 }
1236 fmq = fmq_next;
1237 }
1232 1238
1233 (session->mac->fragment_messages_out_count)--; 1239 (session->mac->fragment_messages_out_count)--;
1234 session->fragment_messages_out_count--; 1240 session->fragment_messages_out_count--;
1235 plugin->pending_Fragment_Messages--; 1241 plugin->pending_Fragment_Messages--;
1236 GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending fragments"), plugin->pending_Fragment_Messages, GNUNET_NO); 1242 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending fragments"),
1237 GNUNET_CONTAINER_DLL_remove (endpoint->sending_messages_head, 1243 plugin->pending_Fragment_Messages, GNUNET_NO);
1238 endpoint->sending_messages_tail, fm); 1244 GNUNET_CONTAINER_DLL_remove (endpoint->sending_messages_head,
1239 GNUNET_FRAGMENT_context_destroy (fm->fragcontext); 1245 endpoint->sending_messages_tail, fm);
1240 if (fm->timeout_task != GNUNET_SCHEDULER_NO_TASK){ 1246 GNUNET_FRAGMENT_context_destroy (fm->fragcontext);
1241 GNUNET_SCHEDULER_cancel (fm->timeout_task); 1247 if (fm->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1242 fm->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1248 {
1243 } 1249 GNUNET_SCHEDULER_cancel (fm->timeout_task);
1250 fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1251 }
1244 1252
1245 GNUNET_free (fm); 1253 GNUNET_free (fm);
1246 1254
1247 queue_session (plugin, session); 1255 queue_session (plugin, session);
1248#if DEBUG_wlan 1256#if DEBUG_wlan
1249 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 1257 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1250 "Free pending fragment messages %p, session %p\n", fm, 1258 "Free pending fragment messages %p, session %p\n", fm,
1251 session); 1259 session);
1252#endif 1260#endif
1253} 1261}
1254 1262
@@ -1499,15 +1507,17 @@ wlan_transport_start_wlan_helper (struct Plugin *plugin)
1499 else 1507 else
1500 { 1508 {
1501 char cwd[FILENAME_MAX]; 1509 char cwd[FILENAME_MAX];
1502 GNUNET_assert (getcwd(cwd, sizeof(cwd)) != NULL);
1503 1510
1504 GNUNET_asprintf (&absolute_filename, "%s%s%s", cwd, DIR_SEPARATOR_STR, filenameloopback); 1511 GNUNET_assert (getcwd (cwd, sizeof (cwd)) != NULL);
1512
1513 GNUNET_asprintf (&absolute_filename, "%s%s%s", cwd, DIR_SEPARATOR_STR,
1514 filenameloopback);
1505 1515
1506 if (GNUNET_DISK_file_test (filenameloopback) != GNUNET_YES) 1516 if (GNUNET_DISK_file_test (filenameloopback) != GNUNET_YES)
1507 { 1517 {
1508 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME, 1518 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1509 "Helper `%s' not found! %i\n", absolute_filename); 1519 "Helper `%s' not found! %i\n", absolute_filename);
1510 GNUNET_break(0); 1520 GNUNET_break (0);
1511 } 1521 }
1512 } 1522 }
1513 } 1523 }
@@ -1552,14 +1562,16 @@ wlan_transport_start_wlan_helper (struct Plugin *plugin)
1552 "Starting gnunet-wlan-helper loopback 1 process cmd: %s %s %i\n", 1562 "Starting gnunet-wlan-helper loopback 1 process cmd: %s %s %i\n",
1553 absolute_filename, plugin->interface, plugin->testmode); 1563 absolute_filename, plugin->interface, plugin->testmode);
1554#endif 1564#endif
1555 plugin->server_proc = GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout, 1565 plugin->server_proc =
1556 absolute_filename, absolute_filename, "1", 1566 GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout,
1557 NULL); 1567 absolute_filename, absolute_filename, "1",
1568 NULL);
1558 if (plugin->server_proc == NULL) 1569 if (plugin->server_proc == NULL)
1559 { 1570 {
1560 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME, 1571 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1561 "`%s' not found, please look if it exists and is in the $PATH variable!\n", absolute_filename); 1572 "`%s' not found, please look if it exists and is in the $PATH variable!\n",
1562 GNUNET_break (0); 1573 absolute_filename);
1574 GNUNET_break (0);
1563 } 1575 }
1564 } 1576 }
1565 else if (plugin->testmode == 2) 1577 else if (plugin->testmode == 2)
@@ -1570,18 +1582,20 @@ wlan_transport_start_wlan_helper (struct Plugin *plugin)
1570 absolute_filename, plugin->interface, plugin->testmode); 1582 absolute_filename, plugin->interface, plugin->testmode);
1571#endif 1583#endif
1572 1584
1573 plugin->server_proc = GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout, 1585 plugin->server_proc =
1574 absolute_filename, absolute_filename, "2", 1586 GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout,
1575 NULL); 1587 absolute_filename, absolute_filename, "2",
1576 if (plugin->server_proc == NULL) 1588 NULL);
1577 { 1589 if (plugin->server_proc == NULL)
1578 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME, 1590 {
1579 "`%s' not found, please look if it exists and is in the $PATH variable!\n", absolute_filename); 1591 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1592 "`%s' not found, please look if it exists and is in the $PATH variable!\n",
1593 absolute_filename);
1580 GNUNET_break (0); 1594 GNUNET_break (0);
1581 } 1595 }
1582 } 1596 }
1583 if (absolute_filename != NULL) 1597 if (absolute_filename != NULL)
1584 GNUNET_free(absolute_filename); 1598 GNUNET_free (absolute_filename);
1585 if (plugin->server_proc == NULL) 1599 if (plugin->server_proc == NULL)
1586 { 1600 {
1587#if DEBUG_wlan 1601#if DEBUG_wlan
@@ -1632,8 +1646,8 @@ static int
1632wlan_transport_stop_wlan_helper (struct Plugin *plugin) 1646wlan_transport_stop_wlan_helper (struct Plugin *plugin)
1633{ 1647{
1634#if DEBUG_wlan 1648#if DEBUG_wlan
1635 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 1649 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1636 "Stoping WLAN helper process\n"); 1650 "Stoping WLAN helper process\n");
1637#endif 1651#endif
1638 1652
1639 if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK) 1653 if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK)
@@ -1657,7 +1671,7 @@ wlan_transport_stop_wlan_helper (struct Plugin *plugin)
1657 GNUNET_DISK_pipe_close (plugin->server_stdout); 1671 GNUNET_DISK_pipe_close (plugin->server_stdout);
1658 GNUNET_DISK_pipe_close (plugin->server_stdin); 1672 GNUNET_DISK_pipe_close (plugin->server_stdin);
1659 GNUNET_OS_process_kill (plugin->server_proc, SIGKILL); 1673 GNUNET_OS_process_kill (plugin->server_proc, SIGKILL);
1660 GNUNET_OS_process_wait(plugin->server_proc); 1674 GNUNET_OS_process_wait (plugin->server_proc);
1661 GNUNET_OS_process_close (plugin->server_proc); 1675 GNUNET_OS_process_close (plugin->server_proc);
1662 1676
1663 return GNUNET_YES; 1677 return GNUNET_YES;
@@ -1673,31 +1687,32 @@ delay_restart_helper (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1673{ 1687{
1674 struct Finish_send *finish = cls; 1688 struct Finish_send *finish = cls;
1675 struct Plugin *plugin; 1689 struct Plugin *plugin;
1690
1676 plugin = finish->plugin; 1691 plugin = finish->plugin;
1677 1692
1678 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK; 1693 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
1679 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) 1694 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
1680 { 1695 {
1681 GNUNET_free_non_null(finish->msgstart); 1696 GNUNET_free_non_null (finish->msgstart);
1682 GNUNET_free (finish); 1697 GNUNET_free (finish);
1683 return; 1698 return;
1684 } 1699 }
1685 1700
1686 wlan_transport_start_wlan_helper(plugin); 1701 wlan_transport_start_wlan_helper (plugin);
1687 1702
1688 if (finish->size != 0) 1703 if (finish->size != 0)
1689 { 1704 {
1690 plugin->server_write_task = 1705 plugin->server_write_task =
1691 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, 1706 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1692 plugin->server_stdin_handle, 1707 plugin->server_stdin_handle,
1693 &finish_sending, finish); 1708 &finish_sending, finish);
1694 } 1709 }
1695 else 1710 else
1696 { 1711 {
1697 set_next_send (plugin); 1712 set_next_send (plugin);
1698 GNUNET_free_non_null(finish->msgstart); 1713 GNUNET_free_non_null (finish->msgstart);
1699 GNUNET_free (finish); 1714 GNUNET_free (finish);
1700 } 1715 }
1701 1716
1702} 1717}
1703 1718
@@ -1707,14 +1722,15 @@ delay_restart_helper (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1707 * @param finish pointer to the Finish_send struct to finish 1722 * @param finish pointer to the Finish_send struct to finish
1708 */ 1723 */
1709static void 1724static void
1710restart_helper(struct Plugin *plugin, struct Finish_send *finish) 1725restart_helper (struct Plugin *plugin, struct Finish_send *finish)
1711{ 1726{
1712 static struct GNUNET_TIME_Relative next_try = {1000}; 1727 static struct GNUNET_TIME_Relative next_try = { 1000 };
1713 GNUNET_assert(finish != NULL); 1728 GNUNET_assert (finish != NULL);
1714 1729
1715 wlan_transport_stop_wlan_helper(plugin); 1730 wlan_transport_stop_wlan_helper (plugin);
1716 plugin->server_write_task = GNUNET_SCHEDULER_add_delayed (next_try, &delay_restart_helper, finish); 1731 plugin->server_write_task =
1717 GNUNET_TIME_relative_multiply(next_try, HELPER_RESTART_SCALING_FACTOR); 1732 GNUNET_SCHEDULER_add_delayed (next_try, &delay_restart_helper, finish);
1733 GNUNET_TIME_relative_multiply (next_try, HELPER_RESTART_SCALING_FACTOR);
1718 1734
1719} 1735}
1720 1736
@@ -1740,24 +1756,24 @@ finish_sending (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1740 return; 1756 return;
1741 } 1757 }
1742 bytes = 1758 bytes =
1743 GNUNET_DISK_file_write (plugin->server_stdin_handle, finish->head_of_next_write, 1759 GNUNET_DISK_file_write (plugin->server_stdin_handle,
1744 finish->size); 1760 finish->head_of_next_write, finish->size);
1745 1761
1746 if (bytes != finish->size) 1762 if (bytes != finish->size)
1747 { 1763 {
1748 if (bytes != GNUNET_SYSERR) 1764 if (bytes != GNUNET_SYSERR)
1749 { 1765 {
1750 finish->head_of_next_write += bytes; 1766 finish->head_of_next_write += bytes;
1751 finish->size -= bytes; 1767 finish->size -= bytes;
1752 plugin->server_write_task = 1768 plugin->server_write_task =
1753 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, 1769 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1754 plugin->server_stdin_handle, 1770 plugin->server_stdin_handle,
1755 &finish_sending, finish); 1771 &finish_sending, finish);
1756 } 1772 }
1757 else 1773 else
1758 { 1774 {
1759 restart_helper(plugin, finish); 1775 restart_helper (plugin, finish);
1760 } 1776 }
1761 } 1777 }
1762 else 1778 else
1763 { 1779 {
@@ -1788,11 +1804,12 @@ send_hello_beacon (struct Plugin *plugin)
1788 struct Radiotap_Send *radioHeader; 1804 struct Radiotap_Send *radioHeader;
1789 struct GNUNET_MessageHeader *msgheader2; 1805 struct GNUNET_MessageHeader *msgheader2;
1790 const struct GNUNET_MessageHeader *hello; 1806 const struct GNUNET_MessageHeader *hello;
1791 struct Finish_send * finish; 1807 struct Finish_send *finish;
1792 1808
1793 GNUNET_assert (plugin != NULL); 1809 GNUNET_assert (plugin != NULL);
1794 1810
1795 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan hello beacons send"), 1, GNUNET_NO); 1811 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan hello beacons send"),
1812 1, GNUNET_NO);
1796 1813
1797 hello = plugin->env->get_our_hello (); 1814 hello = plugin->env->get_our_hello ();
1798 hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello); 1815 hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
@@ -1812,10 +1829,10 @@ send_hello_beacon (struct Plugin *plugin)
1812 1829
1813 msgheader2 = (struct GNUNET_MessageHeader *) &ieeewlanheader[1]; 1830 msgheader2 = (struct GNUNET_MessageHeader *) &ieeewlanheader[1];
1814 /*msgheader2->size = 1831 /*msgheader2->size =
1815 htons (GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello) + 1832 * htons (GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello) +
1816 sizeof (struct GNUNET_MessageHeader)); 1833 * sizeof (struct GNUNET_MessageHeader));
1817 1834 *
1818 msgheader2->type = htons (GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT);*/ 1835 * msgheader2->type = htons (GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT); */
1819 memcpy (msgheader2, hello, hello_size); 1836 memcpy (msgheader2, hello, hello_size);
1820 1837
1821 bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle, msgheader, size); 1838 bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle, msgheader, size);
@@ -1831,17 +1848,17 @@ send_hello_beacon (struct Plugin *plugin)
1831 finish->head_of_next_write = NULL; 1848 finish->head_of_next_write = NULL;
1832 finish->size = 0; 1849 finish->size = 0;
1833 finish->msgstart = NULL; 1850 finish->msgstart = NULL;
1834 restart_helper(plugin, finish); 1851 restart_helper (plugin, finish);
1835 1852
1836 set_next_beacon_time (plugin); 1853 set_next_beacon_time (plugin);
1837 1854
1838 } 1855 }
1839 else 1856 else
1840 { 1857 {
1841 GNUNET_assert (bytes == size); 1858 GNUNET_assert (bytes == size);
1842 set_next_beacon_time (plugin); 1859 set_next_beacon_time (plugin);
1843 set_next_send (plugin); 1860 set_next_send (plugin);
1844 } 1861 }
1845 GNUNET_free (msgheader); 1862 GNUNET_free (msgheader);
1846 1863
1847 1864
@@ -1951,7 +1968,8 @@ check_fragment_queue (struct Plugin *plugin)
1951 session->mac->fragment_messages_out_count++; 1968 session->mac->fragment_messages_out_count++;
1952 session->fragment_messages_out_count++; 1969 session->fragment_messages_out_count++;
1953 plugin->pending_Fragment_Messages++; 1970 plugin->pending_Fragment_Messages++;
1954 GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending fragments"), plugin->pending_Fragment_Messages, GNUNET_NO); 1971 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending fragments"),
1972 plugin->pending_Fragment_Messages, GNUNET_NO);
1955 1973
1956 fm = GNUNET_malloc (sizeof (struct FragmentMessage)); 1974 fm = GNUNET_malloc (sizeof (struct FragmentMessage));
1957 fm->session = session; 1975 fm->session = session;
@@ -2012,7 +2030,7 @@ send_ack (struct Plugin *plugin)
2012 2030
2013 ssize_t bytes; 2031 ssize_t bytes;
2014 struct AckSendQueue *ack; 2032 struct AckSendQueue *ack;
2015 struct Finish_send * finish; 2033 struct Finish_send *finish;
2016 2034
2017 ack = plugin->ack_send_queue_head; 2035 ack = plugin->ack_send_queue_head;
2018 2036
@@ -2025,7 +2043,8 @@ send_ack (struct Plugin *plugin)
2025#endif 2043#endif
2026 2044
2027 GNUNET_assert (plugin != NULL); 2045 GNUNET_assert (plugin != NULL);
2028 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan acks send"), 1, GNUNET_NO); 2046 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan acks send"), 1,
2047 GNUNET_NO);
2029 2048
2030 getRadiotapHeader (plugin, ack->endpoint, ack->radioHeader); 2049 getRadiotapHeader (plugin, ack->endpoint, ack->radioHeader);
2031 getWlanHeader (ack->ieeewlanheader, &ack->endpoint->addr, plugin, 2050 getWlanHeader (ack->ieeewlanheader, &ack->endpoint->addr, plugin,
@@ -2045,7 +2064,7 @@ send_ack (struct Plugin *plugin)
2045 finish->head_of_next_write = NULL; 2064 finish->head_of_next_write = NULL;
2046 finish->size = 0; 2065 finish->size = 0;
2047 finish->msgstart = NULL; 2066 finish->msgstart = NULL;
2048 restart_helper(plugin, finish); 2067 restart_helper (plugin, finish);
2049 } 2068 }
2050 else 2069 else
2051 { 2070 {
@@ -2067,6 +2086,7 @@ static void
2067do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 2086do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2068{ 2087{
2069 struct Plugin *plugin = cls; 2088 struct Plugin *plugin = cls;
2089
2070 GNUNET_assert (plugin != NULL); 2090 GNUNET_assert (plugin != NULL);
2071 2091
2072 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK; 2092 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
@@ -2094,7 +2114,8 @@ do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2094 2114
2095 if (plugin->sending_messages_head != NULL) 2115 if (plugin->sending_messages_head != NULL)
2096 { 2116 {
2097 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan fragments send"), 1, GNUNET_NO); 2117 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan fragments send"), 1,
2118 GNUNET_NO);
2098 2119
2099 fmq = plugin->sending_messages_head; 2120 fmq = plugin->sending_messages_head;
2100 fm = fmq->content; 2121 fm = fmq->content;
@@ -2136,16 +2157,16 @@ do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2136 2157
2137 finish->head_of_next_write = fm->frag; 2158 finish->head_of_next_write = fm->frag;
2138 finish->size = fm->size; 2159 finish->size = fm->size;
2139 restart_helper(plugin, finish); 2160 restart_helper (plugin, finish);
2140 } 2161 }
2141 else 2162 else
2142 { 2163 {
2143 finish->head_of_next_write = fm->frag + bytes; 2164 finish->head_of_next_write = fm->frag + bytes;
2144 finish->size = fm->size - bytes; 2165 finish->size = fm->size - bytes;
2145 plugin->server_write_task = 2166 plugin->server_write_task =
2146 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, 2167 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
2147 plugin->server_stdin_handle, 2168 plugin->server_stdin_handle,
2148 &finish_sending, finish); 2169 &finish_sending, finish);
2149 } 2170 }
2150 2171
2151 fm->frag = NULL; 2172 fm->frag = NULL;
@@ -2192,13 +2213,15 @@ wlan_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
2192 /* TODO check for bad addresses like multicast, broadcast, etc */ 2213 /* TODO check for bad addresses like multicast, broadcast, etc */
2193#if DEBUG_wlan 2214#if DEBUG_wlan
2194 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2215 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2195 "wlan_plugin_address_suggested got good address, size %u!\n", addrlen); 2216 "wlan_plugin_address_suggested got good address, size %u!\n",
2217 addrlen);
2196#endif 2218#endif
2197 return GNUNET_OK; 2219 return GNUNET_OK;
2198 } 2220 }
2199#if DEBUG_wlan 2221#if DEBUG_wlan
2200 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2222 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2201 "wlan_plugin_address_suggested got bad address, size %u!\n", addrlen); 2223 "wlan_plugin_address_suggested got bad address, size %u!\n",
2224 addrlen);
2202#endif 2225#endif
2203 return GNUNET_SYSERR; 2226 return GNUNET_SYSERR;
2204} 2227}
@@ -2239,6 +2262,7 @@ wlan_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
2239 struct Plugin *plugin = cls; 2262 struct Plugin *plugin = cls;
2240 struct PendingMessage *newmsg; 2263 struct PendingMessage *newmsg;
2241 struct WlanHeader *wlanheader; 2264 struct WlanHeader *wlanheader;
2265
2242 GNUNET_assert (plugin != NULL); 2266 GNUNET_assert (plugin != NULL);
2243 //check if msglen > 0 2267 //check if msglen > 0
2244 GNUNET_assert (msgbuf_size > 0); 2268 GNUNET_assert (msgbuf_size > 0);
@@ -2258,7 +2282,8 @@ wlan_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
2258 } 2282 }
2259 } 2283 }
2260 2284
2261 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan messages queued"), 1, GNUNET_NO); 2285 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan messages queued"), 1,
2286 GNUNET_NO);
2262 2287
2263 //queue message: 2288 //queue message:
2264 2289
@@ -2348,7 +2373,8 @@ free_macendpoint (struct Plugin *plugin, struct MacEndpoint *endpoint)
2348 endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK; 2373 endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2349 } 2374 }
2350 plugin->mac_count--; 2375 plugin->mac_count--;
2351 GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan mac endpoints"), plugin->mac_count, GNUNET_NO); 2376 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan mac endpoints"),
2377 plugin->mac_count, GNUNET_NO);
2352 GNUNET_free (endpoint); 2378 GNUNET_free (endpoint);
2353 2379
2354} 2380}
@@ -2386,7 +2412,8 @@ free_session (struct Plugin *plugin, struct Sessionqueue *queue,
2386 if (pendingsession_tmp->content == queue->content) 2412 if (pendingsession_tmp->content == queue->content)
2387 { 2413 {
2388 plugin->pendingsessions--; 2414 plugin->pendingsessions--;
2389 GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending sessions"), plugin->pendingsessions, GNUNET_NO); 2415 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
2416 plugin->pendingsessions, GNUNET_NO);
2390 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head, 2417 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
2391 plugin->pending_Sessions_tail, 2418 plugin->pending_Sessions_tail,
2392 pendingsession_tmp); 2419 pendingsession_tmp);
@@ -2423,12 +2450,14 @@ free_session (struct Plugin *plugin, struct Sessionqueue *queue,
2423 GNUNET_CONTAINER_DLL_remove (endpoint->sessions_head, endpoint->sessions_tail, 2450 GNUNET_CONTAINER_DLL_remove (endpoint->sessions_head, endpoint->sessions_tail,
2424 queue); 2451 queue);
2425 //Check that no ohter session on this endpoint for this session exits 2452 //Check that no ohter session on this endpoint for this session exits
2426 GNUNET_assert(search_session(plugin, endpoint, &queue->content->target) == NULL); 2453 GNUNET_assert (search_session (plugin, endpoint, &queue->content->target) ==
2454 NULL);
2427 if (endpoint->sessions_head == NULL && do_free_macendpoint == GNUNET_YES) 2455 if (endpoint->sessions_head == NULL && do_free_macendpoint == GNUNET_YES)
2428 { 2456 {
2429 free_macendpoint (plugin, endpoint); 2457 free_macendpoint (plugin, endpoint);
2430 //check if no endpoint with the same address exists 2458 //check if no endpoint with the same address exists
2431 GNUNET_assert(get_macendpoint(plugin, &endpoint->addr, GNUNET_NO) == NULL); 2459 GNUNET_assert (get_macendpoint (plugin, &endpoint->addr, GNUNET_NO) ==
2460 NULL);
2432 } 2461 }
2433 2462
2434 if (queue->content->timeout_task != GNUNET_SCHEDULER_NO_TASK) 2463 if (queue->content->timeout_task != GNUNET_SCHEDULER_NO_TASK)
@@ -2507,31 +2536,31 @@ wlan_plugin_address_pretty_printer (void *cls, const char *type,
2507 const unsigned char *input; 2536 const unsigned char *input;
2508 2537
2509 //GNUNET_assert(cls !=NULL); 2538 //GNUNET_assert(cls !=NULL);
2510 if (addrlen != sizeof(struct MacAddress)) 2539 if (addrlen != sizeof (struct MacAddress))
2511 { 2540 {
2512 /* invalid address (MAC addresses have 6 bytes) */ 2541 /* invalid address (MAC addresses have 6 bytes) */
2513 //GNUNET_break (0); 2542 //GNUNET_break (0);
2514#if DEBUG_wlan 2543#if DEBUG_wlan
2515 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2544 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2516 "Func wlan_plugin_address_pretty_printer got size: %u, worng size!\n", 2545 "Func wlan_plugin_address_pretty_printer got size: %u, worng size!\n",
2517 addrlen); 2546 addrlen);
2518#endif 2547#endif
2519 asc(asc_cls, NULL); 2548 asc (asc_cls, NULL);
2520 return; 2549 return;
2521 } 2550 }
2522 input = (const unsigned char *) addr; 2551 input = (const unsigned char *) addr;
2523 GNUNET_asprintf (&ret, 2552 GNUNET_asprintf (&ret,
2524 "Transport %s: %s Mac-Address %.2X:%.2X:%.2X:%.2X:%.2X:%.2X",type, 2553 "Transport %s: %s Mac-Address %.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
2525 PROTOCOL_PREFIX, input[0], input[1], input[2], input[3], 2554 type, PROTOCOL_PREFIX, input[0], input[1], input[2],
2526 input[4], input[5]); 2555 input[3], input[4], input[5]);
2527#if DEBUG_wlan 2556#if DEBUG_wlan
2528 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2557 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2529 "Func wlan_plugin_address_pretty_printer got size: %u, nummeric %u, type %s; made string: %s\n", 2558 "Func wlan_plugin_address_pretty_printer got size: %u, nummeric %u, type %s; made string: %s\n",
2530 addrlen, numeric, type, ret); 2559 addrlen, numeric, type, ret);
2531#endif 2560#endif
2532 asc ( asc_cls, ret); 2561 asc (asc_cls, ret);
2533 //only one mac address per plugin 2562 //only one mac address per plugin
2534 asc ( asc_cls, NULL); 2563 asc (asc_cls, NULL);
2535} 2564}
2536 2565
2537 2566
@@ -2571,7 +2600,9 @@ wlan_data_message_handler (void *cls, const struct GNUNET_MessageHeader *hdr)
2571 return; 2600 return;
2572 } 2601 }
2573 2602
2574 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan whole messages received"), 1, GNUNET_NO); 2603 GNUNET_STATISTICS_update (plugin->env->stats,
2604 _("# wlan whole messages received"), 1,
2605 GNUNET_NO);
2575 wlanheader = (struct WlanHeader *) hdr; 2606 wlanheader = (struct WlanHeader *) hdr;
2576 2607
2577 session = search_session (plugin, endpoint, &wlanheader->source); 2608 session = search_session (plugin, endpoint, &wlanheader->source);
@@ -2711,9 +2742,8 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
2711#endif 2742#endif
2712 2743
2713 plugin->env->receive (plugin->env->cls, &(session->target), hdr, 2744 plugin->env->receive (plugin->env->cls, &(session->target), hdr,
2714 (const struct GNUNET_ATS_Information *) 2745 (const struct GNUNET_ATS_Information *) &distance, 1,
2715 &distance, 1, session, 2746 session, (const char *) &session->mac->addr,
2716 (const char *) &session->mac->addr,
2717 sizeof (session->mac->addr)); 2747 sizeof (session->mac->addr));
2718} 2748}
2719 2749
@@ -2735,7 +2765,7 @@ wlan_data_helper (void *cls, struct Session_light *session_light,
2735 struct FragmentMessage *fm2; 2765 struct FragmentMessage *fm2;
2736 struct GNUNET_PeerIdentity tmpsource; 2766 struct GNUNET_PeerIdentity tmpsource;
2737 2767
2738 GNUNET_assert(plugin != NULL); 2768 GNUNET_assert (plugin != NULL);
2739 2769
2740 //ADVERTISEMENT 2770 //ADVERTISEMENT
2741 if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_HELLO) 2771 if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_HELLO)
@@ -2761,18 +2791,22 @@ wlan_data_helper (void *cls, struct Session_light *session_light,
2761 2791
2762 2792
2763 if (GNUNET_HELLO_get_id 2793 if (GNUNET_HELLO_get_id
2764 ((const struct GNUNET_HELLO_Message *) hdr, 2794 ((const struct GNUNET_HELLO_Message *) hdr, &tmpsource) == GNUNET_OK)
2765 &tmpsource) == GNUNET_OK)
2766 { 2795 {
2767 session_light->session = search_session (plugin, session_light->macendpoint, &tmpsource); 2796 session_light->session =
2797 search_session (plugin, session_light->macendpoint, &tmpsource);
2768 if (session_light->session == NULL) 2798 if (session_light->session == NULL)
2769 { 2799 {
2770 session_light->session = create_session (plugin, session_light->macendpoint, &tmpsource); 2800 session_light->session =
2771 } 2801 create_session (plugin, session_light->macendpoint, &tmpsource);
2772 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan hello messages received"), 1, GNUNET_NO); 2802 }
2773 plugin->env->receive(plugin->env->cls,&session_light->session->target,hdr, NULL, 0, session_light->session, 2803 GNUNET_STATISTICS_update (plugin->env->stats,
2774 (const char *) &session_light->session->mac->addr, 2804 _("# wlan hello messages received"), 1,
2775 sizeof (session_light->session->mac->addr)); 2805 GNUNET_NO);
2806 plugin->env->receive (plugin->env->cls, &session_light->session->target,
2807 hdr, NULL, 0, session_light->session,
2808 (const char *) &session_light->session->mac->addr,
2809 sizeof (session_light->session->mac->addr));
2776 } 2810 }
2777 else 2811 else
2778 { 2812 {
@@ -2803,7 +2837,8 @@ wlan_data_helper (void *cls, struct Session_light *session_light,
2803 6)); 2837 6));
2804#endif 2838#endif
2805 2839
2806 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan fragments received"), 1, GNUNET_NO); 2840 GNUNET_STATISTICS_update (plugin->env->stats,
2841 _("# wlan fragments received"), 1, GNUNET_NO);
2807 int ret = 2842 int ret =
2808 GNUNET_DEFRAGMENT_process_fragment (session_light->macendpoint->defrag, 2843 GNUNET_DEFRAGMENT_process_fragment (session_light->macendpoint->defrag,
2809 hdr); 2844 hdr);
@@ -2855,7 +2890,8 @@ wlan_data_helper (void *cls, struct Session_light *session_light,
2855 while (fm != NULL) 2890 while (fm != NULL)
2856 { 2891 {
2857 fm2 = fm->next; 2892 fm2 = fm->next;
2858 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan acks received"), 1, GNUNET_NO); 2893 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan acks received"),
2894 1, GNUNET_NO);
2859 int ret = GNUNET_FRAGMENT_process_ack (fm->fragcontext, hdr); 2895 int ret = GNUNET_FRAGMENT_process_ack (fm->fragcontext, hdr);
2860 2896
2861 if (ret == GNUNET_OK) 2897 if (ret == GNUNET_OK)
@@ -2947,8 +2983,9 @@ macendpoint_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2947 (GNUNET_TIME_absolute_add 2983 (GNUNET_TIME_absolute_add
2948 (endpoint->last_activity, MACENDPOINT_TIMEOUT)).rel_value == 0) 2984 (endpoint->last_activity, MACENDPOINT_TIMEOUT)).rel_value == 0)
2949 { 2985 {
2950 GNUNET_assert(endpoint->plugin != NULL); 2986 GNUNET_assert (endpoint->plugin != NULL);
2951 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# wlan mac endpoints timeouts"), 1, GNUNET_NO); 2987 GNUNET_STATISTICS_update (endpoint->plugin->env->stats,
2988 _("# wlan mac endpoints timeouts"), 1, GNUNET_NO);
2952 free_macendpoint (endpoint->plugin, endpoint); 2989 free_macendpoint (endpoint->plugin, endpoint);
2953 } 2990 }
2954 else 2991 else
@@ -2970,8 +3007,9 @@ create_macendpoint (struct Plugin *plugin, const struct MacAddress *addr)
2970{ 3007{
2971 struct MacEndpoint *newend = GNUNET_malloc (sizeof (struct MacEndpoint)); 3008 struct MacEndpoint *newend = GNUNET_malloc (sizeof (struct MacEndpoint));
2972 3009
2973 GNUNET_assert(plugin != NULL); 3010 GNUNET_assert (plugin != NULL);
2974 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan mac endpoints created"), 1, GNUNET_NO); 3011 GNUNET_STATISTICS_update (plugin->env->stats,
3012 _("# wlan mac endpoints created"), 1, GNUNET_NO);
2975 newend->addr = *addr; 3013 newend->addr = *addr;
2976 newend->plugin = plugin; 3014 newend->plugin = plugin;
2977 newend->addr = *addr; 3015 newend->addr = *addr;
@@ -2987,7 +3025,8 @@ create_macendpoint (struct Plugin *plugin, const struct MacAddress *addr)
2987 newend); 3025 newend);
2988 3026
2989 plugin->mac_count++; 3027 plugin->mac_count++;
2990 GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan mac endpoints"), plugin->mac_count, GNUNET_NO); 3028 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan mac endpoints"),
3029 plugin->mac_count, GNUNET_NO);
2991 GNUNET_CONTAINER_DLL_insert_tail (plugin->mac_head, plugin->mac_tail, newend); 3030 GNUNET_CONTAINER_DLL_insert_tail (plugin->mac_head, plugin->mac_tail, newend);
2992#if DEBUG_wlan 3031#if DEBUG_wlan
2993 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 3032 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
@@ -3017,7 +3056,7 @@ wlan_process_helper (void *cls, void *client,
3017 int datasize = 0; 3056 int datasize = 0;
3018 int pos; 3057 int pos;
3019 3058
3020 GNUNET_assert(plugin != NULL); 3059 GNUNET_assert (plugin != NULL);
3021 switch (ntohs (hdr->type)) 3060 switch (ntohs (hdr->type))
3022 { 3061 {
3023 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA: 3062 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA:
@@ -3027,11 +3066,13 @@ wlan_process_helper (void *cls, void *client,
3027 ntohs (hdr->size)); 3066 ntohs (hdr->size));
3028#endif 3067#endif
3029 3068
3030 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan WLAN_HELPER_DATA received"), 1, GNUNET_NO); 3069 GNUNET_STATISTICS_update (plugin->env->stats,
3070 _("# wlan WLAN_HELPER_DATA received"), 1,
3071 GNUNET_NO);
3031 //call wlan_process_helper with the message inside, later with wlan: analyze signal 3072 //call wlan_process_helper with the message inside, later with wlan: analyze signal
3032 if (ntohs (hdr->size) < 3073 if (ntohs (hdr->size) <
3033 sizeof (struct ieee80211_frame) + 2*sizeof (struct GNUNET_MessageHeader) + 3074 sizeof (struct ieee80211_frame) +
3034 sizeof (struct Radiotap_rx)) 3075 2 * sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_rx))
3035 { 3076 {
3036#if DEBUG_wlan 3077#if DEBUG_wlan
3037 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 3078 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
@@ -3057,16 +3098,19 @@ wlan_process_helper (void *cls, void *client,
3057 { 3098 {
3058 //check for broadcast or mac 3099 //check for broadcast or mac
3059 if ((memcmp 3100 if ((memcmp
3060 (&(wlanIeeeHeader->i_addr1), &bc_all_mac, 3101 (&(wlanIeeeHeader->i_addr1), &bc_all_mac,
3061 sizeof (struct MacAddress)) == 0) || 3102 sizeof (struct MacAddress)) == 0) ||
3062 (memcmp (&(wlanIeeeHeader->i_addr1), &(plugin->mac_address), 3103 (memcmp
3063 sizeof (struct MacAddress)) == 0)) 3104 (&(wlanIeeeHeader->i_addr1), &(plugin->mac_address),
3105 sizeof (struct MacAddress)) == 0))
3064 { 3106 {
3065 //if packet is from us return 3107 //if packet is from us return
3066 if ((memcmp (&(wlanIeeeHeader->i_addr2), &(plugin->mac_address), 3108 if ((memcmp
3067 sizeof (struct MacAddress)) == 0)){ 3109 (&(wlanIeeeHeader->i_addr2), &(plugin->mac_address),
3068 return; 3110 sizeof (struct MacAddress)) == 0))
3069 } 3111 {
3112 return;
3113 }
3070 // process the inner data 3114 // process the inner data
3071 3115
3072 3116
@@ -3078,25 +3122,30 @@ wlan_process_helper (void *cls, void *client,
3078 memcpy (&session_light->addr, &(wlanIeeeHeader->i_addr2), 3122 memcpy (&session_light->addr, &(wlanIeeeHeader->i_addr2),
3079 sizeof (struct MacAddress)); 3123 sizeof (struct MacAddress));
3080 //session_light->session = search_session(plugin,session_light->addr); 3124 //session_light->session = search_session(plugin,session_light->addr);
3081 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan messages for this client received"), 1, GNUNET_NO); 3125 GNUNET_STATISTICS_update (plugin->env->stats,
3126 _("# wlan messages for this client received"),
3127 1, GNUNET_NO);
3082 3128
3083 pos = 0; 3129 pos = 0;
3084 while (pos < datasize) 3130 while (pos < datasize)
3085 { 3131 {
3086 temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1] + pos; 3132 temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1] + pos;
3087 if (ntohs(temp_hdr->size) <= datasize + pos) 3133 if (ntohs (temp_hdr->size) <= datasize + pos)
3088 { 3134 {
3089 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan messages inside WLAN_HELPER_DATA received"), 1, GNUNET_NO); 3135 GNUNET_STATISTICS_update (plugin->env->stats,
3090 wlan_data_helper (plugin, session_light, temp_hdr, rxinfo); 3136 _
3091 } 3137 ("# wlan messages inside WLAN_HELPER_DATA received"),
3138 1, GNUNET_NO);
3139 wlan_data_helper (plugin, session_light, temp_hdr, rxinfo);
3140 }
3092 else 3141 else
3093 { 3142 {
3094#if DEBUG_wlan 3143#if DEBUG_wlan
3095 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 3144 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3096 "Size of packet is too small; size: %u > size of packet: %u\n", 3145 "Size of packet is too small; size: %u > size of packet: %u\n",
3097 ntohs(temp_hdr->size),datasize + pos); 3146 ntohs (temp_hdr->size), datasize + pos);
3098#endif 3147#endif
3099 } 3148 }
3100 pos += ntohs (temp_hdr->size); 3149 pos += ntohs (temp_hdr->size);
3101 3150
3102 } 3151 }
@@ -3176,7 +3225,7 @@ libgnunet_plugin_transport_wlan_done (void *cls)
3176 "libgnunet_plugin_transport_wlan_done started\n"); 3225 "libgnunet_plugin_transport_wlan_done started\n");
3177#endif 3226#endif
3178 3227
3179 wlan_transport_stop_wlan_helper(plugin); 3228 wlan_transport_stop_wlan_helper (plugin);
3180 3229
3181 GNUNET_assert (cls != NULL); 3230 GNUNET_assert (cls != NULL);
3182 //free sessions 3231 //free sessions
@@ -3220,9 +3269,11 @@ libgnunet_plugin_transport_wlan_init (void *cls)
3220 plugin = GNUNET_malloc (sizeof (struct Plugin)); 3269 plugin = GNUNET_malloc (sizeof (struct Plugin));
3221 plugin->env = env; 3270 plugin->env = env;
3222 plugin->pendingsessions = 0; 3271 plugin->pendingsessions = 0;
3223 GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending sessions"), plugin->pendingsessions, GNUNET_NO); 3272 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
3273 plugin->pendingsessions, GNUNET_NO);
3224 plugin->mac_count = 0; 3274 plugin->mac_count = 0;
3225 GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan mac endpoints"), plugin->mac_count, GNUNET_NO); 3275 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan mac endpoints"),
3276 plugin->mac_count, GNUNET_NO);
3226 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK; 3277 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
3227 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK; 3278 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
3228 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK; 3279 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
@@ -3253,7 +3304,7 @@ libgnunet_plugin_transport_wlan_init (void *cls)
3253 if (GNUNET_SYSERR == 3304 if (GNUNET_SYSERR ==
3254 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-wlan", 3305 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-wlan",
3255 "TESTMODE", &(plugin->testmode))) 3306 "TESTMODE", &(plugin->testmode)))
3256 plugin->testmode = 0; //default value 3307 plugin->testmode = 0; //default value
3257 } 3308 }
3258 3309
3259 if (GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "INTERFACE")) 3310 if (GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "INTERFACE"))
@@ -3270,7 +3321,7 @@ libgnunet_plugin_transport_wlan_init (void *cls)
3270 //start the plugin 3321 //start the plugin
3271 wlan_transport_start_wlan_helper (plugin); 3322 wlan_transport_start_wlan_helper (plugin);
3272 set_next_beacon_time (plugin); 3323 set_next_beacon_time (plugin);
3273 set_next_send(plugin); 3324 set_next_send (plugin);
3274#if DEBUG_wlan 3325#if DEBUG_wlan
3275 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 3326 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3276 "wlan init finished\n"); 3327 "wlan init finished\n");
diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c
index 1c6bba0d5..7d28820cb 100644
--- a/src/transport/test_quota_compliance.c
+++ b/src/transport/test_quota_compliance.c
@@ -70,9 +70,9 @@ struct PeerContext *p1;
70 70
71struct PeerContext *p2; 71struct PeerContext *p2;
72 72
73struct PeerContext * sender; 73struct PeerContext *sender;
74 74
75struct PeerContext * receiver; 75struct PeerContext *receiver;
76 76
77struct GNUNET_TRANSPORT_TransmitHandle *th; 77struct GNUNET_TRANSPORT_TransmitHandle *th;
78 78
@@ -86,7 +86,7 @@ char *gen_cfg_p1;
86unsigned long long quota_in_p2; 86unsigned long long quota_in_p2;
87unsigned long long quota_out_p2; 87unsigned long long quota_out_p2;
88 88
89struct GNUNET_TRANSPORT_TESTING_handle * tth; 89struct GNUNET_TRANSPORT_TESTING_handle *tth;
90 90
91static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; 91static GNUNET_TRANSPORT_TESTING_ConnectRequest cc;
92 92
@@ -144,26 +144,28 @@ end ()
144 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; 144 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value;
145 datarate = (total_bytes_sent * 1000) / delta; 145 datarate = (total_bytes_sent * 1000) / delta;
146 146
147 fprintf (stderr, "Throughput was %llu b/s\n", 147 fprintf (stderr, "Throughput was %llu b/s\n", datarate);
148 datarate);
149 148
150 test_failed = GNUNET_NO; 149 test_failed = GNUNET_NO;
151 if (datarate > quota_in_p2) 150 if (datarate > quota_in_p2)
152 { 151 {
153 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 152 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
154 "Datarate of %llu b/s higher than allowed inbound quota of %llu b/s\n", datarate, quota_in_p2); 153 "Datarate of %llu b/s higher than allowed inbound quota of %llu b/s\n",
154 datarate, quota_in_p2);
155 test_failed = GNUNET_YES; 155 test_failed = GNUNET_YES;
156 } 156 }
157 if (datarate > quota_out_p1) 157 if (datarate > quota_out_p1)
158 { 158 {
159 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 159 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
160 "Datarate of %llu b/s higher than allowed outbound quota of %llu b/s\n", datarate, quota_out_p1); 160 "Datarate of %llu b/s higher than allowed outbound quota of %llu b/s\n",
161 datarate, quota_out_p1);
161 test_failed = GNUNET_YES; 162 test_failed = GNUNET_YES;
162 } 163 }
163 if (test_failed == GNUNET_NO) 164 if (test_failed == GNUNET_NO)
164 { 165 {
165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
166 "Datarate of %llu b/s complied to allowed outbound quota of %llu b/s and inbound quota of %llu b/s\n", datarate, quota_out_p1, quota_in_p2); 167 "Datarate of %llu b/s complied to allowed outbound quota of %llu b/s and inbound quota of %llu b/s\n",
168 datarate, quota_out_p1, quota_in_p2);
167 } 169 }
168 170
169 if (die_task != GNUNET_SCHEDULER_NO_TASK) 171 if (die_task != GNUNET_SCHEDULER_NO_TASK)
@@ -174,7 +176,7 @@ end ()
174 th = NULL; 176 th = NULL;
175 177
176 if (cc != NULL) 178 if (cc != NULL)
177 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc); 179 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
178 180
179 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); 181 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
180 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); 182 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
@@ -200,7 +202,7 @@ end_badly ()
200 th = NULL; 202 th = NULL;
201 203
202 if (cc != NULL) 204 if (cc != NULL)
203 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc); 205 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
204 206
205 if (p1 != NULL) 207 if (p1 != NULL)
206 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); 208 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
@@ -224,8 +226,7 @@ get_size (unsigned int iter)
224static void 226static void
225notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 227notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
226 const struct GNUNET_MessageHeader *message, 228 const struct GNUNET_MessageHeader *message,
227 const struct GNUNET_ATS_Information *ats, 229 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
228 uint32_t ats_count)
229{ 230{
230 static int n; 231 static int n;
231 unsigned int s; 232 unsigned int s;
@@ -269,17 +270,19 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
269 if (die_task != GNUNET_SCHEDULER_NO_TASK) 270 if (die_task != GNUNET_SCHEDULER_NO_TASK)
270 GNUNET_SCHEDULER_cancel (die_task); 271 GNUNET_SCHEDULER_cancel (die_task);
271 test_failed = GNUNET_YES; 272 test_failed = GNUNET_YES;
272 die_task = GNUNET_SCHEDULER_add_now (&end_badly, 273 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
273 NULL);
274 return; 274 return;
275 } 275 }
276#if VERBOSE 276#if VERBOSE
277 if (ntohl (hdr->num) % 5000 == 0) 277 if (ntohl (hdr->num) % 5000 == 0)
278 { 278 {
279 struct PeerContext *p = cls; 279 struct PeerContext *p = cls;
280 char * ps = strdup(GNUNET_i2s(&p->id)); 280 char *ps = strdup (GNUNET_i2s (&p->id));
281 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", 281
282 p->no, ps, ntohl (hdr->num), ntohs (message->size), GNUNET_i2s(peer)); 282 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
283 "Peer %u (`%s') got message %u of size %u from peer (`%s')\n",
284 p->no, ps, ntohl (hdr->num), ntohs (message->size),
285 GNUNET_i2s (peer));
283 GNUNET_free (ps); 286 GNUNET_free (ps);
284 } 287 }
285#endif 288#endif
@@ -300,7 +303,8 @@ notify_ready (void *cls, size_t size, void *buf)
300 if (buf == NULL) 303 if (buf == NULL)
301 { 304 {
302 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 305 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
303 "Timeout occurred while waiting for transmit_ready for message %u of %u\n", msg_scheduled, TOTAL_MSGS); 306 "Timeout occurred while waiting for transmit_ready for message %u of %u\n",
307 msg_scheduled, TOTAL_MSGS);
304 if (GNUNET_SCHEDULER_NO_TASK != die_task) 308 if (GNUNET_SCHEDULER_NO_TASK != die_task)
305 GNUNET_SCHEDULER_cancel (die_task); 309 GNUNET_SCHEDULER_cancel (die_task);
306 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); 310 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
@@ -327,12 +331,12 @@ notify_ready (void *cls, size_t size, void *buf)
327 if (n % 5000 == 0) 331 if (n % 5000 == 0)
328 { 332 {
329 333
330 char * receiver_s = strdup(GNUNET_i2s (&receiver->id)); 334 char *receiver_s = strdup (GNUNET_i2s (&receiver->id));
335
331 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
332 "Sending message of size %u from peer %u (`%4s') -> peer %u (`%s') !\n", 337 "Sending message of size %u from peer %u (`%4s') -> peer %u (`%s') !\n",
333 n, 338 n, sender->no, GNUNET_i2s (&sender->id), receiver->no,
334 sender->no, 339 receiver_s);
335 GNUNET_i2s (&sender->id), receiver->no, receiver_s);
336 GNUNET_free (receiver_s); 340 GNUNET_free (receiver_s);
337 } 341 }
338#endif 342#endif
@@ -367,11 +371,11 @@ notify_ready (void *cls, size_t size, void *buf)
367 371
368static void 372static void
369notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, 373notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
370 const struct GNUNET_ATS_Information *ats, 374 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
371 uint32_t ats_count)
372{ 375{
373 376
374 struct PeerContext *p = cls; 377 struct PeerContext *p = cls;
378
375 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') connected to us!\n", 379 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') connected to us!\n",
376 p->no, GNUNET_i2s (peer)); 380 p->no, GNUNET_i2s (peer));
377} 381}
@@ -381,8 +385,9 @@ static void
381notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 385notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
382{ 386{
383 struct PeerContext *p = cls; 387 struct PeerContext *p = cls;
384 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') disconnected!\n", 388
385 p->no, GNUNET_i2s (peer)); 389 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') disconnected!\n", p->no,
390 GNUNET_i2s (peer));
386 if (th != NULL) 391 if (th != NULL)
387 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); 392 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
388 th = NULL; 393 th = NULL;
@@ -403,10 +408,11 @@ static void
403measure (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 408measure (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
404{ 409{
405 static int counter; 410 static int counter;
411
406 measure_task = GNUNET_SCHEDULER_NO_TASK; 412 measure_task = GNUNET_SCHEDULER_NO_TASK;
407 413
408 counter++; 414 counter++;
409 if ((DURATION.rel_value / 1000) < counter ) 415 if ((DURATION.rel_value / 1000) < counter)
410 { 416 {
411 fprintf (stderr, ".\n"); 417 fprintf (stderr, ".\n");
412 GNUNET_SCHEDULER_add_now (&end, NULL); 418 GNUNET_SCHEDULER_add_now (&end, NULL);
@@ -414,7 +420,8 @@ measure (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
414 else 420 else
415 { 421 {
416 fprintf (stderr, "."); 422 fprintf (stderr, ".");
417 measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &measure, NULL); 423 measure_task =
424 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &measure, NULL);
418 } 425 }
419} 426}
420 427
@@ -423,28 +430,29 @@ static void
423testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) 430testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
424{ 431{
425 char *p1_c = strdup (GNUNET_i2s (&p1->id)); 432 char *p1_c = strdup (GNUNET_i2s (&p1->id));
433
426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n", 434 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n",
427 p1->no, p1_c, 435 p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id));
428 p2->no, GNUNET_i2s (&p2->id));
429 GNUNET_free (p1_c); 436 GNUNET_free (p1_c);
430 437
431 cc = NULL; 438 cc = NULL;
432 test_connected = GNUNET_YES; 439 test_connected = GNUNET_YES;
433 440
434 measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &measure, NULL); 441 measure_task =
442 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &measure, NULL);
435 GNUNET_SCHEDULER_add_now (&sendtask, NULL); 443 GNUNET_SCHEDULER_add_now (&sendtask, NULL);
436 444
437} 445}
438 446
439void start_cb (struct PeerContext * p, 447void
440 void *cls) 448start_cb (struct PeerContext *p, void *cls)
441{ 449{
442 static int started; 450 static int started;
451
443 started++; 452 started++;
444 453
445 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", 454 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no,
446 p->no, 455 GNUNET_i2s (&p->id));
447 GNUNET_i2s (&p->id));
448 456
449 if (started != 2) 457 if (started != 2)
450 return; 458 return;
@@ -455,61 +463,66 @@ void start_cb (struct PeerContext * p,
455 receiver = p1; 463 receiver = p1;
456 464
457 char *sender_c = strdup (GNUNET_i2s (&sender->id)); 465 char *sender_c = strdup (GNUNET_i2s (&sender->id));
458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test tries to send from %u (%s) -> peer %u (%s)\n",
459 sender->no, sender_c,
460 receiver->no, GNUNET_i2s (&receiver->id));
461 466
462 cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, NULL); 467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
468 "Test tries to send from %u (%s) -> peer %u (%s)\n", sender->no,
469 sender_c, receiver->no, GNUNET_i2s (&receiver->id));
470
471 cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb,
472 NULL);
463 473
464} 474}
465 475
466static char * 476static char *
467generate_config (char * cfg_file, unsigned long long quota_in, unsigned long long quota_out) 477generate_config (char *cfg_file, unsigned long long quota_in,
478 unsigned long long quota_out)
468{ 479{
469 char * fname = NULL; 480 char *fname = NULL;
470 struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create(); 481 struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create ();
482
471 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, cfg_file)); 483 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, cfg_file));
472 GNUNET_asprintf (&fname, "q_in_%llu_q_out_%llu_%s", quota_in, quota_out, cfg_file); 484 GNUNET_asprintf (&fname, "q_in_%llu_q_out_%llu_%s", quota_in, quota_out,
473 GNUNET_CONFIGURATION_set_value_string(cfg, "PATHS", "DEFAULTCONFIG", fname); 485 cfg_file);
474 GNUNET_CONFIGURATION_set_value_number(cfg, "core", "TOTAL_QUOTA_OUT", quota_out); 486 GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG", fname);
475 GNUNET_CONFIGURATION_set_value_number(cfg, "core", "TOTAL_QUOTA_IN", quota_in); 487 GNUNET_CONFIGURATION_set_value_number (cfg, "core", "TOTAL_QUOTA_OUT",
476 GNUNET_CONFIGURATION_set_value_number(cfg, "ats", "TOTAL_QUOTA_IN", quota_in); 488 quota_out);
477 GNUNET_CONFIGURATION_set_value_number(cfg, "ats", "TOTAL_QUOTA_OUT", quota_out); 489 GNUNET_CONFIGURATION_set_value_number (cfg, "core", "TOTAL_QUOTA_IN",
478 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write(cfg, fname)); 490 quota_in);
479 GNUNET_CONFIGURATION_destroy(cfg); 491 GNUNET_CONFIGURATION_set_value_number (cfg, "ats", "TOTAL_QUOTA_IN",
492 quota_in);
493 GNUNET_CONFIGURATION_set_value_number (cfg, "ats", "TOTAL_QUOTA_OUT",
494 quota_out);
495 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write (cfg, fname));
496 GNUNET_CONFIGURATION_destroy (cfg);
480 return fname; 497 return fname;
481} 498}
482 499
483static void 500static void
484run_measurement (unsigned long long p1_quota_in, unsigned long long p1_quota_out, 501run_measurement (unsigned long long p1_quota_in,
485 unsigned long long p2_quota_in, unsigned long long p2_quota_out) 502 unsigned long long p1_quota_out,
503 unsigned long long p2_quota_in,
504 unsigned long long p2_quota_out)
486{ 505{
487 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); 506 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
488 507
489 /* setting ATS quota */ 508 /* setting ATS quota */
490 quota_out_p1 = p1_quota_out; 509 quota_out_p1 = p1_quota_out;
491 gen_cfg_p1 = generate_config(cfg_file_p1, p1_quota_in, p1_quota_out); 510 gen_cfg_p1 = generate_config (cfg_file_p1, p1_quota_in, p1_quota_out);
492 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 511 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Generated config file `%s'\n",
493 "Generated config file `%s'\n", 512 gen_cfg_p1);
494 gen_cfg_p1);
495 513
496 quota_in_p2 = p2_quota_in; 514 quota_in_p2 = p2_quota_in;
497 gen_cfg_p2 = generate_config(cfg_file_p2, p2_quota_in, p2_quota_out); 515 gen_cfg_p2 = generate_config (cfg_file_p2, p2_quota_in, p2_quota_out);
498 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 516 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Generated config file `%s'\n",
499 "Generated config file `%s'\n", 517 gen_cfg_p2);
500 gen_cfg_p2);
501 518
502 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, gen_cfg_p1, 1, 519 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, gen_cfg_p1, 1, &notify_receive,
503 &notify_receive,
504 &notify_connect, &notify_disconnect, 520 &notify_connect, &notify_disconnect,
505 &start_cb, 521 &start_cb, NULL);
506 NULL);
507 522
508 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, gen_cfg_p2, 2, 523 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, gen_cfg_p2, 2, &notify_receive,
509 &notify_receive,
510 &notify_connect, &notify_disconnect, 524 &notify_connect, &notify_disconnect,
511 &start_cb, 525 &start_cb, NULL);
512 NULL);
513 526
514 if ((p1 == NULL) || (p2 == NULL)) 527 if ((p1 == NULL) || (p2 == NULL))
515 { 528 {
@@ -530,19 +543,19 @@ run (void *cls, char *const *args, const char *cfgfile,
530 unsigned long long p2_quota_in = 10000; 543 unsigned long long p2_quota_in = 10000;
531 unsigned long long p2_quota_out = 10000; 544 unsigned long long p2_quota_out = 10000;
532 545
533 if (NULL != strstr (test_name,"asymmetric")) 546 if (NULL != strstr (test_name, "asymmetric"))
534 { 547 {
535 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 548 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
536 "Running asymmetric test with sending peer unlimited, receiving peer (in/out): %llu/%llu b/s \n", 549 "Running asymmetric test with sending peer unlimited, receiving peer (in/out): %llu/%llu b/s \n",
537 p2_quota_in, p2_quota_out); 550 p2_quota_in, p2_quota_out);
538 p1_quota_out = 1024 * 1024 * 1024; 551 p1_quota_out = 1024 * 1024 * 1024;
539 p1_quota_in = 1024 * 1024 * 1024; 552 p1_quota_in = 1024 * 1024 * 1024;
540 } 553 }
541 else 554 else
542 { 555 {
543 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 556 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
544 "Running symmetric test with (in/out) %llu/%llu b/s \n", 557 "Running symmetric test with (in/out) %llu/%llu b/s \n",
545 p2_quota_in, p2_quota_out); 558 p2_quota_in, p2_quota_out);
546 } 559 }
547 run_measurement (p1_quota_in, p1_quota_out, p2_quota_in, p2_quota_out); 560 run_measurement (p1_quota_in, p1_quota_out, p2_quota_in, p2_quota_out);
548} 561}
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c
index 6b6cc0c0e..47686f8d9 100644
--- a/src/transport/test_transport_api.c
+++ b/src/transport/test_transport_api.c
@@ -74,7 +74,7 @@ static GNUNET_TRANSPORT_TESTING_ConnectRequest cc;
74 74
75struct GNUNET_TRANSPORT_TransmitHandle *th; 75struct GNUNET_TRANSPORT_TransmitHandle *th;
76 76
77struct GNUNET_TRANSPORT_TESTING_handle * tth; 77struct GNUNET_TRANSPORT_TESTING_handle *tth;
78 78
79char *cfg_file_p1; 79char *cfg_file_p1;
80 80
@@ -140,10 +140,9 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
140static void 140static void
141notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 141notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
142 const struct GNUNET_MessageHeader *message, 142 const struct GNUNET_MessageHeader *message,
143 const struct GNUNET_ATS_Information *ats, 143 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
144 uint32_t ats_count)
145{ 144{
146 struct PeerContext * p = cls; 145 struct PeerContext *p = cls;
147 struct PeerContext *t = NULL; 146 struct PeerContext *t = NULL;
148 147
149 if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) 148 if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity)))
@@ -152,11 +151,12 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
152 t = p2; 151 t = p2;
153 GNUNET_assert (t != NULL); 152 GNUNET_assert (t != NULL);
154 153
155 char * ps = strdup (GNUNET_i2s(&p->id)); 154 char *ps = strdup (GNUNET_i2s (&p->id));
156 155
157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
158 "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n", 157 "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n",
159 p->no, ps, ntohs (message->type), ntohs (message->size), t->no, GNUNET_i2s (&t->id)); 158 p->no, ps, ntohs (message->type), ntohs (message->size), t->no,
159 GNUNET_i2s (&t->id));
160 160
161 if ((MTYPE == ntohs (message->type)) && 161 if ((MTYPE == ntohs (message->type)) &&
162 (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) 162 (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)))
@@ -200,13 +200,12 @@ notify_ready (void *cls, size_t size, void *buf)
200 hdr->size = htons (sizeof (struct GNUNET_MessageHeader)); 200 hdr->size = htons (sizeof (struct GNUNET_MessageHeader));
201 hdr->type = htons (MTYPE); 201 hdr->type = htons (MTYPE);
202 } 202 }
203 char * ps = strdup (GNUNET_i2s(&p2->id)); 203 char *ps = strdup (GNUNET_i2s (&p2->id));
204
204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 205 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
205 "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n", 206 "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n",
206 p2->no, 207 p2->no, ps, ntohs (hdr->type), ntohs (hdr->size), p->no,
207 ps, 208 GNUNET_i2s (&p->id));
208 ntohs (hdr->type),
209 ntohs (hdr->size), p->no, GNUNET_i2s (&p->id));
210 GNUNET_free (ps); 209 GNUNET_free (ps);
211 return sizeof (struct GNUNET_MessageHeader); 210 return sizeof (struct GNUNET_MessageHeader);
212} 211}
@@ -219,11 +218,11 @@ sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
219 218
220 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 219 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
221 return; 220 return;
222 char * receiver_s = strdup(GNUNET_i2s (&p1->id)); 221 char *receiver_s = strdup (GNUNET_i2s (&p1->id));
222
223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
224 "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", 224 "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n",
225 p2->no, 225 p2->no, GNUNET_i2s (&p2->id), p1->no, receiver_s);
226 GNUNET_i2s (&p2->id), p1->no, receiver_s);
227 GNUNET_free (receiver_s); 226 GNUNET_free (receiver_s);
228 227
229 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, 256, 0, 228 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, 256, 0,
@@ -234,10 +233,10 @@ sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
234 233
235static void 234static void
236notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, 235notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
237 const struct GNUNET_ATS_Information *ats, 236 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
238 uint32_t ats_count)
239{ 237{
240 static int c; 238 static int c;
239
241 c++; 240 c++;
242 struct PeerContext *p = cls; 241 struct PeerContext *p = cls;
243 struct PeerContext *t = NULL; 242 struct PeerContext *t = NULL;
@@ -246,11 +245,12 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
246 t = p1; 245 t = p1;
247 if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) 246 if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity)))
248 t = p2; 247 t = p2;
249 GNUNET_assert (t!=NULL); 248 GNUNET_assert (t != NULL);
249
250 char *ps = strdup (GNUNET_i2s (&p->id));
250 251
251 char * ps = strdup (GNUNET_i2s(&p->id)); 252 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
252 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", 253 "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", p->no, ps,
253 p->no, ps,
254 t->no, GNUNET_i2s (peer)); 254 t->no, GNUNET_i2s (peer));
255 GNUNET_free (ps); 255 GNUNET_free (ps);
256} 256}
@@ -260,9 +260,11 @@ static void
260notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 260notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
261{ 261{
262 struct PeerContext *p = cls; 262 struct PeerContext *p = cls;
263 char * ps = strdup (GNUNET_i2s(&p->id)); 263 char *ps = strdup (GNUNET_i2s (&p->id));
264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", 264
265 p->no, ps, GNUNET_i2s (peer)); 265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
266 "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", p->no, ps,
267 GNUNET_i2s (peer));
266 268
267 if (th != NULL) 269 if (th != NULL)
268 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); 270 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
@@ -276,8 +278,7 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
276 char *p1_c = strdup (GNUNET_i2s (&p1->id)); 278 char *p1_c = strdup (GNUNET_i2s (&p1->id));
277 279
278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n", 280 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n",
279 p1->no, p1_c, 281 p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id));
280 p2->no, GNUNET_i2s (&p2->id));
281 GNUNET_free (p1_c); 282 GNUNET_free (p1_c);
282 283
283 send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); 284 send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL);
@@ -285,23 +286,24 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
285 286
286 287
287 288
288void start_cb (struct PeerContext * p, 289void
289 void *cls) 290start_cb (struct PeerContext *p, void *cls)
290{ 291{
291 static int started; 292 static int started;
293
292 started++; 294 started++;
293 295
294 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", 296 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no,
295 p->no, 297 GNUNET_i2s (&p->id));
296 GNUNET_i2s (&p->id));
297 298
298 if (started != 2) 299 if (started != 2)
299 return; 300 return;
300 301
301 char *sender_c = strdup (GNUNET_i2s (&p1->id)); 302 char *sender_c = strdup (GNUNET_i2s (&p1->id));
302 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", 303
303 p1->no, sender_c, 304 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
304 p2->no, GNUNET_i2s (&p2->id)); 305 "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
306 p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id));
305 307
306 cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, 308 cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb,
307 NULL); 309 NULL);
@@ -315,17 +317,13 @@ run (void *cls, char *const *args, const char *cfgfile,
315 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); 317 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
316 318
317 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, 319 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
318 &notify_receive, 320 &notify_receive, &notify_connect,
319 &notify_connect, 321 &notify_disconnect, &start_cb,
320 &notify_disconnect, 322 NULL);
321 &start_cb,
322 NULL);
323 323
324 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, 324 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
325 &notify_receive, 325 &notify_receive, &notify_connect,
326 &notify_connect, 326 &notify_disconnect, &start_cb,
327 &notify_disconnect,
328 &start_cb,
329 NULL); 327 NULL);
330 328
331 if ((p1 == NULL) || (p2 == NULL)) 329 if ((p1 == NULL) || (p2 == NULL))
diff --git a/src/transport/test_transport_api_disconnect.c b/src/transport/test_transport_api_disconnect.c
index 0be922e93..f97c449fc 100644
--- a/src/transport/test_transport_api_disconnect.c
+++ b/src/transport/test_transport_api_disconnect.c
@@ -71,7 +71,7 @@ static GNUNET_TRANSPORT_TESTING_ConnectRequest cc;
71 71
72struct GNUNET_TRANSPORT_TransmitHandle *th; 72struct GNUNET_TRANSPORT_TransmitHandle *th;
73 73
74struct GNUNET_TRANSPORT_TESTING_handle * tth; 74struct GNUNET_TRANSPORT_TESTING_handle *tth;
75 75
76int shutdown_; 76int shutdown_;
77 77
@@ -148,9 +148,11 @@ static void
148notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 148notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
149{ 149{
150 struct PeerContext *p = cls; 150 struct PeerContext *p = cls;
151 char * ps = strdup (GNUNET_i2s(&p->id)); 151 char *ps = strdup (GNUNET_i2s (&p->id));
152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", 152
153 p->no, ps, GNUNET_i2s (peer)); 153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
154 "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", p->no, ps,
155 GNUNET_i2s (peer));
154 156
155 if (th != NULL) 157 if (th != NULL)
156 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); 158 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
@@ -158,8 +160,8 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
158 160
159 if (shutdown_ == GNUNET_YES) 161 if (shutdown_ == GNUNET_YES)
160 { 162 {
161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Complete, shutting down...\n"); 163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Complete, shutting down...\n");
162 GNUNET_SCHEDULER_add_now (&end, NULL); 164 GNUNET_SCHEDULER_add_now (&end, NULL);
163 } 165 }
164} 166}
165 167
@@ -170,12 +172,12 @@ stop_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
170 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 172 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
171 return; 173 return;
172 174
173 struct PeerContext * p = cls; 175 struct PeerContext *p = cls;
174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down peer %u (`%s')\n", 176
175 p->no, 177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down peer %u (`%s')\n", p->no,
176 GNUNET_i2s (&p->id)); 178 GNUNET_i2s (&p->id));
177 shutdown_ = GNUNET_YES; 179 shutdown_ = GNUNET_YES;
178 GNUNET_TRANSPORT_TESTING_stop_peer(tth, p2); 180 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
179 p2 = NULL; 181 p2 = NULL;
180 GNUNET_assert (p2 == NULL); 182 GNUNET_assert (p2 == NULL);
181} 183}
@@ -183,10 +185,9 @@ stop_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
183static void 185static void
184notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 186notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
185 const struct GNUNET_MessageHeader *message, 187 const struct GNUNET_MessageHeader *message,
186 const struct GNUNET_ATS_Information *ats, 188 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
187 uint32_t ats_count)
188{ 189{
189 struct PeerContext * p = cls; 190 struct PeerContext *p = cls;
190 struct PeerContext *t = NULL; 191 struct PeerContext *t = NULL;
191 192
192 if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) 193 if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity)))
@@ -195,17 +196,18 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
195 t = p2; 196 t = p2;
196 GNUNET_assert (t != NULL); 197 GNUNET_assert (t != NULL);
197 198
198 char * ps = strdup (GNUNET_i2s(&p->id)); 199 char *ps = strdup (GNUNET_i2s (&p->id));
199 200
200 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
201 "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n", 202 "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n",
202 p->no, ps, ntohs (message->type), ntohs (message->size), t->no, GNUNET_i2s (&t->id)); 203 p->no, ps, ntohs (message->type), ntohs (message->size), t->no,
204 GNUNET_i2s (&t->id));
203 205
204 if ((MTYPE == ntohs (message->type)) && 206 if ((MTYPE == ntohs (message->type)) &&
205 (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) 207 (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)))
206 { 208 {
207 ok = 1; 209 ok = 1;
208 GNUNET_SCHEDULER_add_now(stop_peer, p2); 210 GNUNET_SCHEDULER_add_now (stop_peer, p2);
209 return; 211 return;
210 } 212 }
211} 213}
@@ -238,13 +240,12 @@ notify_ready (void *cls, size_t size, void *buf)
238 hdr->size = htons (sizeof (struct GNUNET_MessageHeader)); 240 hdr->size = htons (sizeof (struct GNUNET_MessageHeader));
239 hdr->type = htons (MTYPE); 241 hdr->type = htons (MTYPE);
240 } 242 }
241 char * ps = strdup (GNUNET_i2s(&p2->id)); 243 char *ps = strdup (GNUNET_i2s (&p2->id));
244
242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
243 "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n", 246 "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n",
244 p2->no, 247 p2->no, ps, ntohs (hdr->type), ntohs (hdr->size), p->no,
245 ps, 248 GNUNET_i2s (&p->id));
246 ntohs (hdr->type),
247 ntohs (hdr->size), p->no, GNUNET_i2s (&p->id));
248 GNUNET_free (ps); 249 GNUNET_free (ps);
249 return sizeof (struct GNUNET_MessageHeader); 250 return sizeof (struct GNUNET_MessageHeader);
250} 251}
@@ -257,11 +258,11 @@ sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
257 258
258 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 259 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
259 return; 260 return;
260 char * receiver_s = strdup(GNUNET_i2s (&p1->id)); 261 char *receiver_s = strdup (GNUNET_i2s (&p1->id));
262
261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
262 "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", 264 "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n",
263 p2->no, 265 p2->no, GNUNET_i2s (&p2->id), p1->no, receiver_s);
264 GNUNET_i2s (&p2->id), p1->no, receiver_s);
265 GNUNET_free (receiver_s); 266 GNUNET_free (receiver_s);
266 267
267 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, 256, 0, 268 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, 256, 0,
@@ -272,10 +273,10 @@ sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
272 273
273static void 274static void
274notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, 275notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
275 const struct GNUNET_ATS_Information *ats, 276 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
276 uint32_t ats_count)
277{ 277{
278 static int c; 278 static int c;
279
279 c++; 280 c++;
280 struct PeerContext *p = cls; 281 struct PeerContext *p = cls;
281 struct PeerContext *t = NULL; 282 struct PeerContext *t = NULL;
@@ -284,11 +285,12 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
284 t = p1; 285 t = p1;
285 if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) 286 if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity)))
286 t = p2; 287 t = p2;
287 GNUNET_assert (t!=NULL); 288 GNUNET_assert (t != NULL);
289
290 char *ps = strdup (GNUNET_i2s (&p->id));
288 291
289 char * ps = strdup (GNUNET_i2s(&p->id)); 292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", 293 "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", p->no, ps,
291 p->no, ps,
292 t->no, GNUNET_i2s (peer)); 294 t->no, GNUNET_i2s (peer));
293 GNUNET_free (ps); 295 GNUNET_free (ps);
294} 296}
@@ -301,8 +303,7 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
301 char *p1_c = strdup (GNUNET_i2s (&p1->id)); 303 char *p1_c = strdup (GNUNET_i2s (&p1->id));
302 304
303 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n", 305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n",
304 p1->no, p1_c, 306 p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id));
305 p2->no, GNUNET_i2s (&p2->id));
306 GNUNET_free (p1_c); 307 GNUNET_free (p1_c);
307 308
308 send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); 309 send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL);
@@ -310,23 +311,24 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
310 311
311 312
312 313
313void start_cb (struct PeerContext * p, 314void
314 void *cls) 315start_cb (struct PeerContext *p, void *cls)
315{ 316{
316 static int started; 317 static int started;
318
317 started++; 319 started++;
318 320
319 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", 321 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no,
320 p->no, 322 GNUNET_i2s (&p->id));
321 GNUNET_i2s (&p->id));
322 323
323 if (started != 2) 324 if (started != 2)
324 return; 325 return;
325 326
326 char *sender_c = strdup (GNUNET_i2s (&p1->id)); 327 char *sender_c = strdup (GNUNET_i2s (&p1->id));
327 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", 328
328 p1->no, sender_c, 329 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
329 p2->no, GNUNET_i2s (&p2->id)); 330 "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
331 p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id));
330 332
331 cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, 333 cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb,
332 NULL); 334 NULL);
@@ -340,17 +342,13 @@ run (void *cls, char *const *args, const char *cfgfile,
340 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); 342 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
341 343
342 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, 344 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
343 &notify_receive, 345 &notify_receive, &notify_connect,
344 &notify_connect, 346 &notify_disconnect, &start_cb,
345 &notify_disconnect, 347 NULL);
346 &start_cb,
347 NULL);
348 348
349 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, 349 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
350 &notify_receive, 350 &notify_receive, &notify_connect,
351 &notify_connect, 351 &notify_disconnect, &start_cb,
352 &notify_disconnect,
353 &start_cb,
354 NULL); 352 NULL);
355 353
356 if ((p1 == NULL) || (p2 == NULL)) 354 if ((p1 == NULL) || (p2 == NULL))
diff --git a/src/transport/test_transport_api_limited_sockets.c b/src/transport/test_transport_api_limited_sockets.c
index 20dc3ed2e..f165a5771 100644
--- a/src/transport/test_transport_api_limited_sockets.c
+++ b/src/transport/test_transport_api_limited_sockets.c
@@ -77,7 +77,7 @@ static GNUNET_TRANSPORT_TESTING_ConnectRequest cc;
77 77
78struct GNUNET_TRANSPORT_TransmitHandle *th; 78struct GNUNET_TRANSPORT_TransmitHandle *th;
79 79
80struct GNUNET_TRANSPORT_TESTING_handle * tth; 80struct GNUNET_TRANSPORT_TESTING_handle *tth;
81 81
82char *cfg_file_p1; 82char *cfg_file_p1;
83 83
@@ -138,8 +138,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
138static void 138static void
139notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 139notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
140 const struct GNUNET_MessageHeader *message, 140 const struct GNUNET_MessageHeader *message,
141 const struct GNUNET_ATS_Information *ats, 141 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
142 uint32_t ats_count)
143{ 142{
144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
145 "Received message of type %d from peer %s!\n", 144 "Received message of type %d from peer %s!\n",
@@ -185,8 +184,7 @@ notify_ready (void *cls, size_t size, void *buf)
185 184
186static void 185static void
187notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, 186notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
188 const struct GNUNET_ATS_Information *ats, 187 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
189 uint32_t ats_count)
190{ 188{
191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n", 189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n",
192 GNUNET_i2s (peer), cls); 190 GNUNET_i2s (peer), cls);
@@ -230,15 +228,15 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
230 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL); 228 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL);
231} 229}
232 230
233void start_cb (struct PeerContext * p, 231void
234 void *cls) 232start_cb (struct PeerContext *p, void *cls)
235{ 233{
236 static int started; 234 static int started;
235
237 started++; 236 started++;
238 237
239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", 238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no,
240 p->no, 239 GNUNET_i2s (&p->id));
241 GNUNET_i2s (&p->id));
242 240
243 if (started != 2) 241 if (started != 2)
244 return; 242 return;
@@ -257,14 +255,12 @@ run (void *cls, char *const *args, const char *cfgfile,
257 tth = GNUNET_TRANSPORT_TESTING_init (); 255 tth = GNUNET_TRANSPORT_TESTING_init ();
258 256
259 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, 257 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
260 &notify_receive, 258 &notify_receive, &notify_connect,
261 &notify_connect, &notify_disconnect, 259 &notify_disconnect, &start_cb,
262 &start_cb,
263 NULL); 260 NULL);
264 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, 261 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
265 &notify_receive, 262 &notify_receive, &notify_connect,
266 &notify_connect, &notify_disconnect, 263 &notify_disconnect, &start_cb,
267 &start_cb,
268 NULL); 264 NULL);
269 if ((p1 == NULL) || (p2 == NULL)) 265 if ((p1 == NULL) || (p2 == NULL))
270 { 266 {
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c
index e4b635905..5bbff2550 100644
--- a/src/transport/test_transport_api_reliability.c
+++ b/src/transport/test_transport_api_reliability.c
@@ -69,9 +69,9 @@ struct PeerContext *p1;
69 69
70struct PeerContext *p2; 70struct PeerContext *p2;
71 71
72struct PeerContext * sender; 72struct PeerContext *sender;
73 73
74struct PeerContext * receiver; 74struct PeerContext *receiver;
75 75
76struct GNUNET_TRANSPORT_TransmitHandle *th; 76struct GNUNET_TRANSPORT_TransmitHandle *th;
77 77
@@ -79,7 +79,7 @@ char *cfg_file_p1;
79 79
80char *cfg_file_p2; 80char *cfg_file_p2;
81 81
82struct GNUNET_TRANSPORT_TESTING_handle * tth; 82struct GNUNET_TRANSPORT_TESTING_handle *tth;
83 83
84static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; 84static GNUNET_TRANSPORT_TESTING_ConnectRequest cc;
85 85
@@ -151,7 +151,7 @@ end ()
151 th = NULL; 151 th = NULL;
152 152
153 if (cc != NULL) 153 if (cc != NULL)
154 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc); 154 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
155 155
156 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); 156 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
157 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); 157 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
@@ -175,7 +175,7 @@ end_badly ()
175 th = NULL; 175 th = NULL;
176 176
177 if (cc != NULL) 177 if (cc != NULL)
178 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc); 178 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
179 179
180 if (p1 != NULL) 180 if (p1 != NULL)
181 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); 181 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
@@ -201,8 +201,7 @@ get_size (unsigned int iter)
201static void 201static void
202notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 202notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
203 const struct GNUNET_MessageHeader *message, 203 const struct GNUNET_MessageHeader *message,
204 const struct GNUNET_ATS_Information *ats, 204 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
205 uint32_t ats_count)
206{ 205{
207 static int n; 206 static int n;
208 unsigned int s; 207 unsigned int s;
@@ -253,9 +252,12 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
253 if (ntohl (hdr->num) % 5000 == 0) 252 if (ntohl (hdr->num) % 5000 == 0)
254 { 253 {
255 struct PeerContext *p = cls; 254 struct PeerContext *p = cls;
256 char * ps = strdup(GNUNET_i2s(&p->id)); 255 char *ps = strdup (GNUNET_i2s (&p->id));
257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", 256
258 p->no, ps, ntohl (hdr->num), ntohs (message->size), GNUNET_i2s(peer)); 257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
258 "Peer %u (`%s') got message %u of size %u from peer (`%s')\n",
259 p->no, ps, ntohl (hdr->num), ntohs (message->size),
260 GNUNET_i2s (peer));
259 GNUNET_free (ps); 261 GNUNET_free (ps);
260 } 262 }
261#endif 263#endif
@@ -289,7 +291,8 @@ notify_ready (void *cls, size_t size, void *buf)
289 if (buf == NULL) 291 if (buf == NULL)
290 { 292 {
291 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 293 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
292 "Timeout occurred while waiting for transmit_ready for message %u of %u\n", msg_scheduled, TOTAL_MSGS); 294 "Timeout occurred while waiting for transmit_ready for message %u of %u\n",
295 msg_scheduled, TOTAL_MSGS);
293 if (GNUNET_SCHEDULER_NO_TASK != die_task) 296 if (GNUNET_SCHEDULER_NO_TASK != die_task)
294 GNUNET_SCHEDULER_cancel (die_task); 297 GNUNET_SCHEDULER_cancel (die_task);
295 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); 298 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
@@ -316,12 +319,12 @@ notify_ready (void *cls, size_t size, void *buf)
316 if (n % 5000 == 0) 319 if (n % 5000 == 0)
317 { 320 {
318 321
319 char * receiver_s = strdup(GNUNET_i2s (&receiver->id)); 322 char *receiver_s = strdup (GNUNET_i2s (&receiver->id));
323
320 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 324 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
321 "Sending message of size %u from peer %u (`%4s') -> peer %u (`%s') !\n", 325 "Sending message of size %u from peer %u (`%4s') -> peer %u (`%s') !\n",
322 n, 326 n, sender->no, GNUNET_i2s (&sender->id), receiver->no,
323 sender->no, 327 receiver_s);
324 GNUNET_i2s (&sender->id), receiver->no, receiver_s);
325 GNUNET_free (receiver_s); 328 GNUNET_free (receiver_s);
326 } 329 }
327#endif 330#endif
@@ -356,11 +359,11 @@ notify_ready (void *cls, size_t size, void *buf)
356 359
357static void 360static void
358notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, 361notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
359 const struct GNUNET_ATS_Information *ats, 362 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
360 uint32_t ats_count)
361{ 363{
362 364
363 struct PeerContext *p = cls; 365 struct PeerContext *p = cls;
366
364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') connected to us!\n", 367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') connected to us!\n",
365 p->no, GNUNET_i2s (peer)); 368 p->no, GNUNET_i2s (peer));
366} 369}
@@ -370,8 +373,9 @@ static void
370notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 373notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
371{ 374{
372 struct PeerContext *p = cls; 375 struct PeerContext *p = cls;
373 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') disconnected!\n", 376
374 p->no, GNUNET_i2s (peer)); 377 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') disconnected!\n", p->no,
378 GNUNET_i2s (peer));
375 if (th != NULL) 379 if (th != NULL)
376 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); 380 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
377 th = NULL; 381 th = NULL;
@@ -391,9 +395,9 @@ static void
391testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) 395testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
392{ 396{
393 char *p1_c = strdup (GNUNET_i2s (&p1->id)); 397 char *p1_c = strdup (GNUNET_i2s (&p1->id));
398
394 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n", 399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n",
395 p1->no, p1_c, 400 p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id));
396 p2->no, GNUNET_i2s (&p2->id));
397 GNUNET_free (p1_c); 401 GNUNET_free (p1_c);
398 402
399 cc = NULL; 403 cc = NULL;
@@ -402,37 +406,39 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
402 406
403} 407}
404 408
405void start_cb (struct PeerContext * p, 409void
406 void *cls) 410start_cb (struct PeerContext *p, void *cls)
407{ 411{
408 static int started; 412 static int started;
413
409 started++; 414 started++;
410 415
411 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", 416 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no,
412 p->no, 417 GNUNET_i2s (&p->id));
413 GNUNET_i2s (&p->id));
414 418
415 if (started != 2) 419 if (started != 2)
416 return; 420 return;
417 421
418 test_connected = GNUNET_NO; 422 test_connected = GNUNET_NO;
419 423
420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u: `%s' using configuration file `%s'\n", 424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
421 p1->no, 425 "Peer %u: `%s' using configuration file `%s'\n", p1->no,
422 GNUNET_i2s (&p1->id), cfg_file_p1); 426 GNUNET_i2s (&p1->id), cfg_file_p1);
423 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u: `%s' using configuration file `%s'\n", 427 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
424 p2->no, 428 "Peer %u: `%s' using configuration file `%s'\n", p2->no,
425 GNUNET_i2s (&p2->id), cfg_file_p2); 429 GNUNET_i2s (&p2->id), cfg_file_p2);
426 430
427 sender = p2; 431 sender = p2;
428 receiver = p1; 432 receiver = p1;
429 433
430 char *sender_c = strdup (GNUNET_i2s (&sender->id)); 434 char *sender_c = strdup (GNUNET_i2s (&sender->id));
431 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test triest to send from %u (%s) -> peer %u (%s)\n",
432 sender->no, sender_c,
433 receiver->no, GNUNET_i2s (&receiver->id));
434 435
435 cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, NULL); 436 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
437 "Test triest to send from %u (%s) -> peer %u (%s)\n", sender->no,
438 sender_c, receiver->no, GNUNET_i2s (&receiver->id));
439
440 cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb,
441 NULL);
436 442
437} 443}
438 444
@@ -444,14 +450,12 @@ run (void *cls, char *const *args, const char *cfgfile,
444 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); 450 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
445 451
446 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, 452 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
447 &notify_receive, 453 &notify_receive, &notify_connect,
448 &notify_connect, &notify_disconnect, 454 &notify_disconnect, &start_cb,
449 &start_cb,
450 NULL); 455 NULL);
451 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, 456 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
452 &notify_receive, 457 &notify_receive, &notify_connect,
453 &notify_connect, &notify_disconnect, 458 &notify_disconnect, &start_cb,
454 &start_cb,
455 NULL); 459 NULL);
456 460
457 if ((p1 == NULL) || (p2 == NULL)) 461 if ((p1 == NULL) || (p2 == NULL))
diff --git a/src/transport/test_transport_api_timeout.c b/src/transport/test_transport_api_timeout.c
index aff36853a..79a90ba0e 100644
--- a/src/transport/test_transport_api_timeout.c
+++ b/src/transport/test_transport_api_timeout.c
@@ -65,7 +65,7 @@ static GNUNET_SCHEDULER_TaskIdentifier die_task;
65 65
66static GNUNET_SCHEDULER_TaskIdentifier timer_task; 66static GNUNET_SCHEDULER_TaskIdentifier timer_task;
67 67
68struct GNUNET_TRANSPORT_TESTING_handle * tth; 68struct GNUNET_TRANSPORT_TESTING_handle *tth;
69 69
70struct PeerContext *p1; 70struct PeerContext *p1;
71 71
@@ -161,8 +161,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
161static void 161static void
162notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 162notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
163 const struct GNUNET_MessageHeader *message, 163 const struct GNUNET_MessageHeader *message,
164 const struct GNUNET_ATS_Information *ats, 164 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
165 uint32_t ats_count)
166{ 165{
167 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
168 "Received message of type %d from peer %s!\n", 167 "Received message of type %d from peer %s!\n",
@@ -171,8 +170,7 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
171 170
172static void 171static void
173notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, 172notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
174 const struct GNUNET_ATS_Information *ats, 173 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
175 uint32_t ats_count)
176{ 174{
177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n", 175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n",
178 GNUNET_i2s (peer), cls); 176 GNUNET_i2s (peer), cls);
@@ -240,23 +238,24 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
240 timer_task = GNUNET_SCHEDULER_add_now (&timer, NULL); 238 timer_task = GNUNET_SCHEDULER_add_now (&timer, NULL);
241} 239}
242 240
243void start_cb (struct PeerContext * p, 241void
244 void *cls) 242start_cb (struct PeerContext *p, void *cls)
245{ 243{
246 static int started; 244 static int started;
245
247 started++; 246 started++;
248 247
249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", 248 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no,
250 p->no, 249 GNUNET_i2s (&p->id));
251 GNUNET_i2s (&p->id));
252 250
253 if (started != 2) 251 if (started != 2)
254 return; 252 return;
255 253
256 char *sender_c = strdup (GNUNET_i2s (&p1->id)); 254 char *sender_c = strdup (GNUNET_i2s (&p1->id));
257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", 255
258 p1->no, sender_c, 256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
259 p2->no, GNUNET_i2s (&p2->id)); 257 "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
258 p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id));
260 259
261 cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, 260 cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb,
262 NULL); 261 NULL);
@@ -269,17 +268,13 @@ run (void *cls, char *const *args, const char *cfgfile,
269{ 268{
270 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); 269 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
271 270
272 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, 271 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
273 &notify_receive, 272 &notify_receive, &notify_connect,
274 &notify_connect, 273 &notify_disconnect, &start_cb,
275 &notify_disconnect,
276 &start_cb,
277 NULL); 274 NULL);
278 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, 275 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
279 &notify_receive, 276 &notify_receive, &notify_connect,
280 &notify_connect, 277 &notify_disconnect, &start_cb,
281 &notify_disconnect,
282 &start_cb,
283 NULL); 278 NULL);
284 279
285 if ((p1 == NULL) || (p2 == NULL)) 280 if ((p1 == NULL) || (p2 == NULL))
@@ -314,8 +309,8 @@ check ()
314 309
315 ok = 1; 310 ok = 1;
316 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, 311 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
317 "test-transport-api-timeout", "nohelp", options, 312 "test-transport-api-timeout", "nohelp", options, &run,
318 &run, &ok); 313 &ok);
319 314
320 return ok; 315 return ok;
321} 316}
diff --git a/src/transport/test_transport_api_unreliability.c b/src/transport/test_transport_api_unreliability.c
index 90b5280ce..3077eaae6 100644
--- a/src/transport/test_transport_api_unreliability.c
+++ b/src/transport/test_transport_api_unreliability.c
@@ -78,7 +78,7 @@ char *cfg_file_p2;
78uint32_t max_bps_p1; 78uint32_t max_bps_p1;
79uint32_t max_bps_p2; 79uint32_t max_bps_p2;
80 80
81struct GNUNET_TRANSPORT_TESTING_handle * tth; 81struct GNUNET_TRANSPORT_TESTING_handle *tth;
82 82
83/* 83/*
84 * Testcase specific declarations 84 * Testcase specific declarations
@@ -156,7 +156,7 @@ end ()
156 th = NULL; 156 th = NULL;
157 157
158 if (cc != NULL) 158 if (cc != NULL)
159 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc); 159 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
160 cc = NULL; 160 cc = NULL;
161 161
162 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); 162 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
@@ -190,13 +190,15 @@ end_badly ()
190 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers got NOT connected\n"); 190 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers got NOT connected\n");
191 191
192 if (test_sending == GNUNET_NO) 192 if (test_sending == GNUNET_NO)
193 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testcase did not send any messages timeout\n"); 193 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
194 "Testcase did not send any messages timeout\n");
194 else 195 else
195 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 196 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
196 "Reliability failed: Last message sent %u, Next message scheduled %u, Last message received %u, Message expected %u\n", 197 "Reliability failed: Last message sent %u, Next message scheduled %u, Last message received %u, Message expected %u\n",
197 msg_sent, msg_scheduled, msg_recv, msg_recv_expected); 198 msg_sent, msg_scheduled, msg_recv, msg_recv_expected);
198 if (test_send_timeout == GNUNET_YES) 199 if (test_send_timeout == GNUNET_YES)
199 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test had timeout while waiting to send data\n"); 200 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
201 "Test had timeout while waiting to send data\n");
200 202
201 203
202 if (th != NULL) 204 if (th != NULL)
@@ -204,7 +206,7 @@ end_badly ()
204 th = NULL; 206 th = NULL;
205 207
206 if (cc != NULL) 208 if (cc != NULL)
207 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc); 209 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
208 cc = NULL; 210 cc = NULL;
209 211
210 if (p1 != NULL) 212 if (p1 != NULL)
@@ -273,8 +275,7 @@ get_bit (const char *map, unsigned int bit)
273static void 275static void
274notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 276notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
275 const struct GNUNET_MessageHeader *message, 277 const struct GNUNET_MessageHeader *message,
276 const struct GNUNET_ATS_Information *ats, 278 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
277 uint32_t ats_count)
278{ 279{
279 static int n; 280 static int n;
280 281
@@ -400,8 +401,7 @@ notify_ready (void *cls, size_t size, void *buf)
400 else 401 else
401 { 402 {
402 fprintf (stderr, "\n"); 403 fprintf (stderr, "\n");
403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 404 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All messages scheduled to be sent\n");
404 "All messages scheduled to be sent\n");
405 if (GNUNET_SCHEDULER_NO_TASK != die_task) 405 if (GNUNET_SCHEDULER_NO_TASK != die_task)
406 GNUNET_SCHEDULER_cancel (die_task); 406 GNUNET_SCHEDULER_cancel (die_task);
407 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); 407 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
@@ -418,8 +418,7 @@ notify_ready (void *cls, size_t size, void *buf)
418 418
419static void 419static void
420notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, 420notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
421 const struct GNUNET_ATS_Information *ats, 421 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
422 uint32_t ats_count)
423{ 422{
424 423
425 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n", 424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n",
@@ -450,6 +449,7 @@ static void
450testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) 449testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
451{ 450{
452 char *p1_c = strdup (GNUNET_i2s (&p1->id)); 451 char *p1_c = strdup (GNUNET_i2s (&p1->id));
452
453 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n", p1_c, 453 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n", p1_c,
454 GNUNET_i2s (&p2->id)); 454 GNUNET_i2s (&p2->id));
455 GNUNET_free (p1_c); 455 GNUNET_free (p1_c);
@@ -460,21 +460,22 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
460 GNUNET_SCHEDULER_add_now (&sendtask, NULL); 460 GNUNET_SCHEDULER_add_now (&sendtask, NULL);
461} 461}
462 462
463void start_cb (struct PeerContext * p, 463void
464 void *cls) 464start_cb (struct PeerContext *p, void *cls)
465{ 465{
466 static int started; 466 static int started;
467
467 started++; 468 started++;
468 469
469 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", 470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no,
470 p->no, 471 GNUNET_i2s (&p->id));
471 GNUNET_i2s (&p->id));
472 472
473 if (started != 2) 473 if (started != 2)
474 return; 474 return;
475 475
476 test_connected = GNUNET_NO; 476 test_connected = GNUNET_NO;
477 cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, NULL); 477 cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb,
478 NULL);
478 479
479} 480}
480 481
@@ -487,14 +488,12 @@ run (void *cls, char *const *args, const char *cfgfile,
487 488
488 489
489 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, 490 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
490 &notify_receive, 491 &notify_receive, &notify_connect,
491 &notify_connect, &notify_disconnect, 492 &notify_disconnect, &start_cb,
492 &start_cb,
493 NULL); 493 NULL);
494 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, 494 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
495 &notify_receive, 495 &notify_receive, &notify_connect,
496 &notify_connect, &notify_disconnect, 496 &notify_disconnect, &start_cb,
497 &start_cb,
498 NULL); 497 NULL);
499 498
500 499
diff --git a/src/transport/test_transport_api_unreliability_constant.c b/src/transport/test_transport_api_unreliability_constant.c
index c8638cd23..3ce256017 100644
--- a/src/transport/test_transport_api_unreliability_constant.c
+++ b/src/transport/test_transport_api_unreliability_constant.c
@@ -71,7 +71,7 @@ struct PeerContext *p2;
71 71
72struct GNUNET_TRANSPORT_TransmitHandle *th; 72struct GNUNET_TRANSPORT_TransmitHandle *th;
73 73
74struct GNUNET_TRANSPORT_TESTING_handle * tth; 74struct GNUNET_TRANSPORT_TESTING_handle *tth;
75 75
76char *cfg_file_p1; 76char *cfg_file_p1;
77 77
@@ -154,7 +154,7 @@ end ()
154 th = NULL; 154 th = NULL;
155 155
156 if (cc != NULL) 156 if (cc != NULL)
157 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc); 157 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
158 cc = NULL; 158 cc = NULL;
159 159
160 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); 160 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
@@ -165,7 +165,8 @@ end ()
165 ok = 0; 165 ok = 0;
166 if (test_failed == GNUNET_NO) 166 if (test_failed == GNUNET_NO)
167 ok = GNUNET_SYSERR; 167 ok = GNUNET_SYSERR;
168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GOT %u of %u messages\n", msg_recv, TOTAL_MSGS); 168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GOT %u of %u messages\n", msg_recv,
169 TOTAL_MSGS);
169} 170}
170 171
171static void 172static void
@@ -186,7 +187,7 @@ end_badly ()
186 th = NULL; 187 th = NULL;
187 188
188 if (cc != NULL) 189 if (cc != NULL)
189 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc); 190 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
190 cc = NULL; 191 cc = NULL;
191 192
192 if (p1 != NULL) 193 if (p1 != NULL)
@@ -217,8 +218,7 @@ get_size (unsigned int iter)
217static void 218static void
218notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 219notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
219 const struct GNUNET_MessageHeader *message, 220 const struct GNUNET_MessageHeader *message,
220 const struct GNUNET_ATS_Information *ats, 221 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
221 uint32_t ats_count)
222{ 222{
223 static int n; 223 static int n;
224 224
@@ -234,8 +234,7 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
234 msg_recv = ntohl (hdr->num); 234 msg_recv = ntohl (hdr->num);
235 if (msg_recv_expected != msg_recv) 235 if (msg_recv_expected != msg_recv)
236 { 236 {
237 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 237 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expected message no %u, got %u\n",
238 "Expected message no %u, got %u\n",
239 msg_recv_expected, msg_recv); 238 msg_recv_expected, msg_recv);
240 if (GNUNET_SCHEDULER_NO_TASK != die_task) 239 if (GNUNET_SCHEDULER_NO_TASK != die_task)
241 GNUNET_SCHEDULER_cancel (die_task); 240 GNUNET_SCHEDULER_cancel (die_task);
@@ -373,8 +372,7 @@ notify_ready (void *cls, size_t size, void *buf)
373 372
374static void 373static void
375notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, 374notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
376 const struct GNUNET_ATS_Information *ats, 375 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
377 uint32_t ats_count)
378{ 376{
379 377
380 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n", 378 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n",
@@ -415,20 +413,21 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
415 GNUNET_SCHEDULER_add_now (&sendtask, NULL); 413 GNUNET_SCHEDULER_add_now (&sendtask, NULL);
416} 414}
417 415
418void start_cb (struct PeerContext * p, 416void
419 void *cls) 417start_cb (struct PeerContext *p, void *cls)
420{ 418{
421 static int started; 419 static int started;
420
422 started++; 421 started++;
423 422
424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", 423 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no,
425 p->no, 424 GNUNET_i2s (&p->id));
426 GNUNET_i2s (&p->id));
427 425
428 if (started != 2) 426 if (started != 2)
429 return; 427 return;
430 428
431 cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, NULL); 429 cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb,
430 NULL);
432} 431}
433 432
434static void 433static void
@@ -438,14 +437,12 @@ run (void *cls, char *const *args, const char *cfgfile,
438 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); 437 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
439 438
440 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, 439 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
441 &notify_receive, 440 &notify_receive, &notify_connect,
442 &notify_connect, &notify_disconnect, 441 &notify_disconnect, &start_cb,
443 &start_cb,
444 NULL); 442 NULL);
445 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, 443 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
446 &notify_receive, 444 &notify_receive, &notify_connect,
447 &notify_connect, &notify_disconnect, 445 &notify_disconnect, &start_cb,
448 &start_cb,
449 NULL); 446 NULL);
450 447
451 if ((p1 == NULL) || (p2 == NULL)) 448 if ((p1 == NULL) || (p2 == NULL))
diff --git a/src/transport/test_transport_startonly.c b/src/transport/test_transport_startonly.c
index 1349a0c4d..c6215c9bc 100644
--- a/src/transport/test_transport_startonly.c
+++ b/src/transport/test_transport_startonly.c
@@ -54,7 +54,7 @@ GNUNET_SCHEDULER_TaskIdentifier timeout_task;
54 54
55static struct PeerContext *p1; 55static struct PeerContext *p1;
56 56
57struct GNUNET_TRANSPORT_TESTING_handle * tth; 57struct GNUNET_TRANSPORT_TESTING_handle *tth;
58 58
59static int connected = GNUNET_NO; 59static int connected = GNUNET_NO;
60 60
@@ -92,8 +92,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
92 92
93static void 93static void
94notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, 94notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
95 const struct GNUNET_ATS_Information *ats, 95 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
96 uint32_t ats_count)
97{ 96{
98 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' connected \n", 97 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' connected \n",
99 GNUNET_i2s (peer)); 98 GNUNET_i2s (peer));
@@ -110,8 +109,7 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
110static void 109static void
111notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 110notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
112 const struct GNUNET_MessageHeader *message, 111 const struct GNUNET_MessageHeader *message,
113 const struct GNUNET_ATS_Information *ats, 112 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
114 uint32_t ats_count)
115{ 113{
116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving\n"); 114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving\n");
117} 115}
@@ -130,8 +128,10 @@ run (void *cls, char *const *args, const char *cfgfile,
130 while (i <= ITERATIONS) 128 while (i <= ITERATIONS)
131 { 129 {
132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting peer\n"); 130 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting peer\n");
133 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_startonly.conf", 1, 131 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
134 &notify_receive, &notify_connect, 132 "test_transport_startonly.conf",
133 1, &notify_receive,
134 &notify_connect,
135 &notify_disconnect, NULL, p1); 135 &notify_disconnect, NULL, p1);
136 136
137 137
diff --git a/src/transport/test_transport_testing.c b/src/transport/test_transport_testing.c
index 266933580..996ea0543 100644
--- a/src/transport/test_transport_testing.c
+++ b/src/transport/test_transport_testing.c
@@ -55,7 +55,7 @@ static struct PeerContext *p2;
55 55
56static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; 56static GNUNET_TRANSPORT_TESTING_ConnectRequest cc;
57 57
58struct GNUNET_TRANSPORT_TESTING_handle * tth; 58struct GNUNET_TRANSPORT_TESTING_handle *tth;
59 59
60static int connected = GNUNET_NO; 60static int connected = GNUNET_NO;
61 61
@@ -94,9 +94,10 @@ end_badly ()
94static void 94static void
95testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) 95testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
96{ 96{
97 char * ps = strdup (GNUNET_i2s(&p1->id)); 97 char *ps = strdup (GNUNET_i2s (&p1->id));
98 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') connected to peer %u (`%s')!\n", 98
99 p1->no, ps, 99 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
100 "Peer %u (`%4s') connected to peer %u (`%s')!\n", p1->no, ps,
100 p2->no, GNUNET_i2s (&p2->id)); 101 p2->no, GNUNET_i2s (&p2->id));
101 GNUNET_free (ps); 102 GNUNET_free (ps);
102 GNUNET_SCHEDULER_add_now (&end, NULL); 103 GNUNET_SCHEDULER_add_now (&end, NULL);
@@ -104,8 +105,7 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
104 105
105static void 106static void
106notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, 107notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
107 const struct GNUNET_ATS_Information *ats, 108 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
108 uint32_t ats_count)
109{ 109{
110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' connected \n", 110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' connected \n",
111 GNUNET_i2s (peer)); 111 GNUNET_i2s (peer));
@@ -122,29 +122,29 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
122static void 122static void
123notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 123notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
124 const struct GNUNET_MessageHeader *message, 124 const struct GNUNET_MessageHeader *message,
125 const struct GNUNET_ATS_Information *ats, 125 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
126 uint32_t ats_count)
127{ 126{
128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving\n"); 127 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving\n");
129} 128}
130 129
131void start_cb (struct PeerContext * p, 130void
132 void *cls) 131start_cb (struct PeerContext *p, void *cls)
133{ 132{
134 static int started; 133 static int started;
134
135 started++; 135 started++;
136 136
137 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", 137 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no,
138 p->no, 138 GNUNET_i2s (&p->id));
139 GNUNET_i2s (&p->id));
140 139
141 if (started != 2) 140 if (started != 2)
142 return; 141 return;
143 142
144 char *sender_c = strdup (GNUNET_i2s (&p1->id)); 143 char *sender_c = strdup (GNUNET_i2s (&p1->id));
145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", 144
146 p1->no, sender_c, 145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
147 p2->no, GNUNET_i2s (&p2->id)); 146 "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
147 p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id));
148 148
149 cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, 149 cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb,
150 NULL); 150 NULL);
@@ -161,34 +161,30 @@ run (void *cls, char *const *args, const char *cfgfile,
161 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &end_badly, NULL); 161 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &end_badly, NULL);
162 162
163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting peer\n"); 163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting peer\n");
164 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_api_tcp_peer1.conf", 164 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
165 1, 165 "test_transport_api_tcp_peer1.conf",
166 &notify_receive, &notify_connect, 166 1, &notify_receive, &notify_connect,
167 &notify_disconnect, 167 &notify_disconnect, &start_cb, p1);
168 &start_cb, 168 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
169 p1); 169 "test_transport_api_tcp_peer2.conf",
170 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_api_tcp_peer2.conf", 170 2, &notify_receive, &notify_connect,
171 2, 171 &notify_disconnect, &start_cb, p2);
172 &notify_receive, &notify_connect,
173 &notify_disconnect,
174 &start_cb,
175 p2);
176 172
177 if (p1 == NULL) 173 if (p1 == NULL)
178 { 174 {
179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer1 was not started successfully\n"); 175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
176 "Peer1 was not started successfully\n");
180 if (timeout_task != GNUNET_SCHEDULER_NO_TASK) 177 if (timeout_task != GNUNET_SCHEDULER_NO_TASK)
181 GNUNET_SCHEDULER_cancel(timeout_task); 178 GNUNET_SCHEDULER_cancel (timeout_task);
182 timeout_task = 179 timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
183 GNUNET_SCHEDULER_add_now (&end_badly, NULL);
184 } 180 }
185 if (p2 == NULL) 181 if (p2 == NULL)
186 { 182 {
187 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer2 was not started successfully\n"); 183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
184 "Peer2 was not started successfully\n");
188 if (timeout_task != GNUNET_SCHEDULER_NO_TASK) 185 if (timeout_task != GNUNET_SCHEDULER_NO_TASK)
189 GNUNET_SCHEDULER_cancel(timeout_task); 186 GNUNET_SCHEDULER_cancel (timeout_task);
190 timeout_task = 187 timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
191 GNUNET_SCHEDULER_add_now (&end_badly, NULL);
192 } 188 }
193} 189}
194 190
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c
index a4eba609d..b23879032 100644
--- a/src/transport/transport-testing.c
+++ b/src/transport/transport-testing.c
@@ -31,11 +31,11 @@
31 31
32 32
33static struct PeerContext * 33static struct PeerContext *
34find_peer_context ( struct GNUNET_TRANSPORT_TESTING_handle *tth, 34find_peer_context (struct GNUNET_TRANSPORT_TESTING_handle *tth,
35 const struct GNUNET_PeerIdentity *peer) 35 const struct GNUNET_PeerIdentity *peer)
36{ 36{
37 GNUNET_assert (tth != NULL); 37 GNUNET_assert (tth != NULL);
38 struct PeerContext * t = tth->p_head; 38 struct PeerContext *t = tth->p_head;
39 39
40 while (t != NULL) 40 while (t != NULL)
41 { 41 {
@@ -48,17 +48,16 @@ find_peer_context ( struct GNUNET_TRANSPORT_TESTING_handle *tth,
48} 48}
49 49
50struct ConnectingContext * 50struct ConnectingContext *
51find_connecting_context ( struct GNUNET_TRANSPORT_TESTING_handle *tth, 51find_connecting_context (struct GNUNET_TRANSPORT_TESTING_handle *tth,
52 struct PeerContext *p1, 52 struct PeerContext *p1, struct PeerContext *p2)
53 struct PeerContext * p2)
54{ 53{
55 GNUNET_assert (tth != NULL); 54 GNUNET_assert (tth != NULL);
56 struct ConnectingContext * cc = tth->cc_head; 55 struct ConnectingContext *cc = tth->cc_head;
57 56
58 while (cc != NULL) 57 while (cc != NULL)
59 { 58 {
60 if ((cc->p1 == p1) && (cc->p2 == p2)) 59 if ((cc->p1 == p1) && (cc->p2 == p2))
61 break; 60 break;
62 if ((cc->p1 == p2) && (cc->p2 == p1)) 61 if ((cc->p1 == p2) && (cc->p2 == p1))
63 break; 62 break;
64 cc = cc->next; 63 cc = cc->next;
@@ -69,14 +68,14 @@ find_connecting_context ( struct GNUNET_TRANSPORT_TESTING_handle *tth,
69 68
70static void 69static void
71notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, 70notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
72 const struct GNUNET_ATS_Information *ats, 71 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
73 uint32_t ats_count)
74{ 72{
75 struct PeerContext *p = cls; 73 struct PeerContext *p = cls;
74
76 /* Find PeerContext */ 75 /* Find PeerContext */
77 GNUNET_assert (p != 0); 76 GNUNET_assert (p != 0);
78 GNUNET_assert (p->tth != NULL); 77 GNUNET_assert (p->tth != NULL);
79 struct PeerContext * p2 = find_peer_context (p->tth, peer); 78 struct PeerContext *p2 = find_peer_context (p->tth, peer);
80 79
81 if (p == NULL) 80 if (p == NULL)
82 return; 81 return;
@@ -84,21 +83,22 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
84 p->nc (p->cb_cls, peer, ats, ats_count); 83 p->nc (p->cb_cls, peer, ats, ats_count);
85 84
86#if VERBOSE 85#if VERBOSE
87 char * p2_s; 86 char *p2_s;
87
88 if (p2 != NULL) 88 if (p2 != NULL)
89 GNUNET_asprintf(&p2_s, "%u (`%s')", p2->no, GNUNET_i2s (&p2->id)); 89 GNUNET_asprintf (&p2_s, "%u (`%s')", p2->no, GNUNET_i2s (&p2->id));
90 else 90 else
91 GNUNET_asprintf(&p2_s, "`%s'", GNUNET_i2s (peer)); 91 GNUNET_asprintf (&p2_s, "`%s'", GNUNET_i2s (peer));
92 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", 92 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
93 "Peers %s connected to peer %u (`%s')\n", 93 "Peers %s connected to peer %u (`%s')\n", p2_s, p->no,
94 p2_s, 94 GNUNET_i2s (&p->id));
95 p->no, GNUNET_i2s (&p->id));
96 GNUNET_free (p2_s); 95 GNUNET_free (p2_s);
97#endif 96#endif
98 97
99 98
100 /* Find ConnectingContext */ 99 /* Find ConnectingContext */
101 struct ConnectingContext * cc = find_connecting_context(p->tth, p, p2); 100 struct ConnectingContext *cc = find_connecting_context (p->tth, p, p2);
101
102 if (cc == NULL) 102 if (cc == NULL)
103 return; 103 return;
104 104
@@ -106,12 +106,12 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
106 cc->p1_c = GNUNET_YES; 106 cc->p1_c = GNUNET_YES;
107 107
108 if (p == cc->p2) 108 if (p == cc->p2)
109 cc->p2_c = GNUNET_YES; 109 cc->p2_c = GNUNET_YES;
110 110
111 if ((cc->p1_c == GNUNET_YES) && (cc->p2_c == GNUNET_YES)) 111 if ((cc->p1_c == GNUNET_YES) && (cc->p2_c == GNUNET_YES))
112 { 112 {
113 cc->cb (cc->p1, cc->p2, cc->cb_cls); 113 cc->cb (cc->p1, cc->p2, cc->cb_cls);
114 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(p->tth, cc); 114 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (p->tth, cc);
115 } 115 }
116} 116}
117 117
@@ -119,9 +119,10 @@ static void
119notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 119notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
120{ 120{
121 struct PeerContext *p = cls; 121 struct PeerContext *p = cls;
122
122 /* Find PeerContext */ 123 /* Find PeerContext */
123 int no = 0; 124 int no = 0;
124 struct PeerContext * p2 = NULL; 125 struct PeerContext *p2 = NULL;
125 126
126 if (p != NULL) 127 if (p != NULL)
127 { 128 {
@@ -130,15 +131,15 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
130 no = p->no; 131 no = p->no;
131 } 132 }
132 133
133 char * p2_s; 134 char *p2_s;
135
134 if (p2 != NULL) 136 if (p2 != NULL)
135 GNUNET_asprintf(&p2_s, "%u (`%s')", p2->no, GNUNET_i2s (&p2->id)); 137 GNUNET_asprintf (&p2_s, "%u (`%s')", p2->no, GNUNET_i2s (&p2->id));
136 else 138 else
137 GNUNET_asprintf(&p2_s, "`%s'", GNUNET_i2s (peer)); 139 GNUNET_asprintf (&p2_s, "`%s'", GNUNET_i2s (peer));
138 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", 140 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
139 "Peers %s disconnected from peer %u (`%s')\n", 141 "Peers %s disconnected from peer %u (`%s')\n", p2_s, no,
140 p2_s, 142 GNUNET_i2s (&p->id));
141 no , GNUNET_i2s (&p->id));
142 GNUNET_free (p2_s); 143 GNUNET_free (p2_s);
143 144
144 if (p == NULL) 145 if (p == NULL)
@@ -150,8 +151,7 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
150static void 151static void
151notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 152notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
152 const struct GNUNET_MessageHeader *message, 153 const struct GNUNET_MessageHeader *message,
153 const struct GNUNET_ATS_Information *ats, 154 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
154 uint32_t ats_count)
155{ 155{
156 struct PeerContext *p = cls; 156 struct PeerContext *p = cls;
157 157
@@ -170,25 +170,25 @@ get_hello (void *cb_cls, const struct GNUNET_MessageHeader *message)
170 GNUNET_assert (GNUNET_OK == 170 GNUNET_assert (GNUNET_OK ==
171 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) 171 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
172 message, &p->id)); 172 message, &p->id));
173 size_t size = GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *) message); 173 size_t size =
174 GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *) message);
174 GNUNET_free_non_null (p->hello); 175 GNUNET_free_non_null (p->hello);
175 p->hello = (struct GNUNET_HELLO_Message*) GNUNET_copy_message (message); 176 p->hello = (struct GNUNET_HELLO_Message *) GNUNET_copy_message (message);
176 177
177#if VERBOSE 178#if VERBOSE
178 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 179 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
179 "transport-testing", 180 "New HELLO for peer %u (`%s') with size %u\n", p->no,
180 "New HELLO for peer %u (`%s') with size %u\n", 181 GNUNET_i2s (&p->id), size);
181 p->no, GNUNET_i2s (&p->id), size);
182#endif 182#endif
183 183
184 if (p->start_cb != NULL) 184 if (p->start_cb != NULL)
185 { 185 {
186#if VERBOSE 186#if VERBOSE
187 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", 187 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
188 "Peer %u (`%s') successfully started\n", 188 "Peer %u (`%s') successfully started\n", p->no,
189 p->no, GNUNET_i2s (&p->id)); 189 GNUNET_i2s (&p->id));
190#endif 190#endif
191 p->start_cb(p, p->cb_cls); 191 p->start_cb (p, p->cb_cls);
192 p->start_cb = NULL; 192 p->start_cb = NULL;
193 } 193 }
194} 194}
@@ -205,15 +205,17 @@ try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
205 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 205 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
206 return; 206 return;
207 207
208 char * p2_s = GNUNET_strdup(GNUNET_i2s (&p2->id)); 208 char *p2_s = GNUNET_strdup (GNUNET_i2s (&p2->id));
209
209 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", 210 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
210 "Asking peer %u (`%s') to connect peer %u (`%s'), providing HELLO with %u bytes\n", 211 "Asking peer %u (`%s') to connect peer %u (`%s'), providing HELLO with %u bytes\n",
211 p1->no, GNUNET_i2s (&p1->id), p2->no, p2_s, 212 p1->no, GNUNET_i2s (&p1->id), p2->no, p2_s,
212 GNUNET_HELLO_size (cc->p2->hello)); 213 GNUNET_HELLO_size (cc->p2->hello));
213 GNUNET_free (p2_s); 214 GNUNET_free (p2_s);
214 215
215 GNUNET_TRANSPORT_offer_hello (cc->th_p1, 216 GNUNET_TRANSPORT_offer_hello (cc->th_p1,
216 (const struct GNUNET_MessageHeader *) cc->p2->hello, NULL, NULL); 217 (const struct GNUNET_MessageHeader *) cc->
218 p2->hello, NULL, NULL);
217 GNUNET_TRANSPORT_try_connect (cc->th_p1, &p2->id); 219 GNUNET_TRANSPORT_try_connect (cc->th_p1, &p2->id);
218 220
219 cc->tct = 221 cc->tct =
@@ -230,9 +232,8 @@ try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
230 * @return the peer context 232 * @return the peer context
231 */ 233 */
232struct PeerContext * 234struct PeerContext *
233GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle * tth, 235GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle
234 const char *cfgname, 236 *tth, const char *cfgname, int peer_id,
235 int peer_id,
236 GNUNET_TRANSPORT_ReceiveCallback rec, 237 GNUNET_TRANSPORT_ReceiveCallback rec,
237 GNUNET_TRANSPORT_NotifyConnect nc, 238 GNUNET_TRANSPORT_NotifyConnect nc,
238 GNUNET_TRANSPORT_NotifyDisconnect nd, 239 GNUNET_TRANSPORT_NotifyDisconnect nd,
@@ -243,7 +244,7 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle * tt
243 if (GNUNET_DISK_file_test (cfgname) == GNUNET_NO) 244 if (GNUNET_DISK_file_test (cfgname) == GNUNET_NO)
244 { 245 {
245 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", 246 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing",
246 "File not found: `%s' \n", cfgname); 247 "File not found: `%s' \n", cfgname);
247 return NULL; 248 return NULL;
248 } 249 }
249 250
@@ -253,8 +254,10 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle * tt
253 254
254 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 255 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
255 if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME")) 256 if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME"))
256 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME", 257 GNUNET_assert (GNUNET_OK ==
257 &p->servicehome)); 258 GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS",
259 "SERVICEHOME",
260 &p->servicehome));
258 if (NULL != p->servicehome) 261 if (NULL != p->servicehome)
259 GNUNET_DISK_directory_remove (p->servicehome); 262 GNUNET_DISK_directory_remove (p->servicehome);
260 p->arm_proc = 263 p->arm_proc =
@@ -286,7 +289,7 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle * tt
286 p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &get_hello, p); 289 p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &get_hello, p);
287 GNUNET_assert (p->ghh != NULL); 290 GNUNET_assert (p->ghh != NULL);
288 291
289 GNUNET_CONTAINER_DLL_insert(tth->p_head, tth->p_tail, p); 292 GNUNET_CONTAINER_DLL_insert (tth->p_head, tth->p_tail, p);
290 293
291 return p; 294 return p;
292} 295}
@@ -296,7 +299,7 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle * tt
296 * @param p the peer 299 * @param p the peer
297 */ 300 */
298void 301void
299GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle * tth, 302GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth,
300 struct PeerContext *p) 303 struct PeerContext *p)
301{ 304{
302 GNUNET_assert (p != NULL); 305 GNUNET_assert (p != NULL);
@@ -346,12 +349,11 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle * tth
346 * @return connect context 349 * @return connect context
347 */ 350 */
348GNUNET_TRANSPORT_TESTING_ConnectRequest 351GNUNET_TRANSPORT_TESTING_ConnectRequest
349GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle * tth, 352GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle
350 struct PeerContext *p1, 353 *tth, struct PeerContext *p1,
351 struct PeerContext *p2, 354 struct PeerContext *p2,
352 GNUNET_TRANSPORT_TESTING_connect_cb cb, 355 GNUNET_TRANSPORT_TESTING_connect_cb cb,
353 void *cb_cls) 356 void *cb_cls)
354
355{ 357{
356 GNUNET_assert (tth != NULL); 358 GNUNET_assert (tth != NULL);
357 359
@@ -377,7 +379,7 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle *
377 379
378 cc->tct = GNUNET_SCHEDULER_add_now (&try_connect, cc); 380 cc->tct = GNUNET_SCHEDULER_add_now (&try_connect, cc);
379 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", 381 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
380 "New connect request %X\n", cc); 382 "New connect request %X\n", cc);
381 383
382 return cc; 384 return cc;
383} 385}
@@ -387,16 +389,19 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle *
387 * Tou MUST cancel the request if you stop the peers before the peers connected succesfully 389 * Tou MUST cancel the request if you stop the peers before the peers connected succesfully
388 * @param cc a connect request handle 390 * @param cc a connect request handle
389 */ 391 */
390void GNUNET_TRANSPORT_TESTING_connect_peers_cancel 392void
391 (struct GNUNET_TRANSPORT_TESTING_handle * tth, 393GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct
392 GNUNET_TRANSPORT_TESTING_ConnectRequest ccr) 394 GNUNET_TRANSPORT_TESTING_handle
395 *tth,
396 GNUNET_TRANSPORT_TESTING_ConnectRequest
397 ccr)
393{ 398{
394 struct ConnectingContext *cc = ccr; 399 struct ConnectingContext *cc = ccr;
395 400
396 GNUNET_assert (tth != NULL); 401 GNUNET_assert (tth != NULL);
397 402
398 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", 403 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
399 "Canceling connect request %X!\n", cc); 404 "Canceling connect request %X!\n", cc);
400 if (cc->tct != GNUNET_SCHEDULER_NO_TASK) 405 if (cc->tct != GNUNET_SCHEDULER_NO_TASK)
401 GNUNET_SCHEDULER_cancel (cc->tct); 406 GNUNET_SCHEDULER_cancel (cc->tct);
402 407
@@ -412,7 +417,7 @@ void GNUNET_TRANSPORT_TESTING_connect_peers_cancel
412 * @param tth transport testing handle 417 * @param tth transport testing handle
413 */ 418 */
414void 419void
415GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle * tth) 420GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle *tth)
416{ 421{
417 struct ConnectingContext *cc = tth->cc_head; 422 struct ConnectingContext *cc = tth->cc_head;
418 struct ConnectingContext *ct = NULL; 423 struct ConnectingContext *ct = NULL;
@@ -425,8 +430,8 @@ GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle * tth)
425 { 430 {
426 ct = cc->next; 431 ct = cc->next;
427 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", 432 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing",
428 "Developer forgot to cancel connect request %X!\n", cc); 433 "Developer forgot to cancel connect request %X!\n", cc);
429 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc); 434 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc);
430 cc = ct; 435 cc = ct;
431 } 436 }
432 437
@@ -434,7 +439,7 @@ GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle * tth)
434 { 439 {
435 t = p->next; 440 t = p->next;
436 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", 441 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing",
437 "Developer forgot to stop peer!\n"); 442 "Developer forgot to stop peer!\n");
438 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); 443 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p);
439 p = t; 444 p = t;
440 } 445 }
@@ -450,7 +455,8 @@ GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle * tth)
450struct GNUNET_TRANSPORT_TESTING_handle * 455struct GNUNET_TRANSPORT_TESTING_handle *
451GNUNET_TRANSPORT_TESTING_init () 456GNUNET_TRANSPORT_TESTING_init ()
452{ 457{
453 struct GNUNET_TRANSPORT_TESTING_handle * tth = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TESTING_handle)); 458 struct GNUNET_TRANSPORT_TESTING_handle *tth =
459 GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TESTING_handle));
454 460
455 return tth; 461 return tth;
456} 462}
diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h
index ed9238ecb..8e5d55dcd 100644
--- a/src/transport/transport-testing.h
+++ b/src/transport/transport-testing.h
@@ -65,10 +65,10 @@ struct GNUNET_TRANSPORT_TESTING_handle;
65 */ 65 */
66struct PeerContext 66struct PeerContext
67{ 67{
68 struct PeerContext * next; 68 struct PeerContext *next;
69 struct PeerContext * prev; 69 struct PeerContext *prev;
70 70
71 struct GNUNET_TRANSPORT_TESTING_handle * tth; 71 struct GNUNET_TRANSPORT_TESTING_handle *tth;
72 72
73 struct GNUNET_CONFIGURATION_Handle *cfg; 73 struct GNUNET_CONFIGURATION_Handle *cfg;
74 74
@@ -100,8 +100,8 @@ struct PeerContext
100 100
101struct ConnectingContext 101struct ConnectingContext
102{ 102{
103 struct ConnectingContext * next; 103 struct ConnectingContext *next;
104 struct ConnectingContext * prev; 104 struct ConnectingContext *prev;
105 struct PeerContext *p1; 105 struct PeerContext *p1;
106 struct PeerContext *p2; 106 struct PeerContext *p2;
107 GNUNET_SCHEDULER_TaskIdentifier tct; 107 GNUNET_SCHEDULER_TaskIdentifier tct;
@@ -115,11 +115,11 @@ struct ConnectingContext
115 115
116struct GNUNET_TRANSPORT_TESTING_handle 116struct GNUNET_TRANSPORT_TESTING_handle
117{ 117{
118 struct ConnectingContext * cc_head; 118 struct ConnectingContext *cc_head;
119 struct ConnectingContext * cc_tail; 119 struct ConnectingContext *cc_tail;
120 120
121 struct PeerContext * p_head; 121 struct PeerContext *p_head;
122 struct PeerContext * p_tail; 122 struct PeerContext *p_tail;
123}; 123};
124 124
125 125
@@ -134,9 +134,8 @@ struct GNUNET_TRANSPORT_TESTING_handle
134 * @return the peer context 134 * @return the peer context
135 */ 135 */
136struct PeerContext * 136struct PeerContext *
137GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle * tth, 137GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle
138 const char *cfgname, 138 *tth, const char *cfgname, int peer_id,
139 int peer_id,
140 GNUNET_TRANSPORT_ReceiveCallback rec, 139 GNUNET_TRANSPORT_ReceiveCallback rec,
141 GNUNET_TRANSPORT_NotifyConnect nc, 140 GNUNET_TRANSPORT_NotifyConnect nc,
142 GNUNET_TRANSPORT_NotifyDisconnect nd, 141 GNUNET_TRANSPORT_NotifyDisconnect nd,
@@ -150,7 +149,7 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle * tt
150 */ 149 */
151 150
152void 151void
153GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle * tth, 152GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth,
154 struct PeerContext *pc); 153 struct PeerContext *pc);
155 154
156 155
@@ -165,8 +164,8 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle * tth
165 * @return a connect request handle 164 * @return a connect request handle
166 */ 165 */
167GNUNET_TRANSPORT_TESTING_ConnectRequest 166GNUNET_TRANSPORT_TESTING_ConnectRequest
168GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle * tth, 167GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle
169 struct PeerContext *p1, 168 *tth, struct PeerContext *p1,
170 struct PeerContext *p2, 169 struct PeerContext *p2,
171 GNUNET_TRANSPORT_TESTING_connect_cb cb, 170 GNUNET_TRANSPORT_TESTING_connect_cb cb,
172 void *cls); 171 void *cls);
@@ -177,15 +176,16 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle *
177 * @param cc a connect request handle 176 * @param cc a connect request handle
178 */ 177 */
179void 178void
180GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_handle *, 179GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct
181 void *cc); 180 GNUNET_TRANSPORT_TESTING_handle
181 *, void *cc);
182 182
183/** 183/**
184 * Clean up the transport testing 184 * Clean up the transport testing
185 * @param tth transport testing handle 185 * @param tth transport testing handle
186 */ 186 */
187void 187void
188GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle * tth); 188GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle *tth);
189 189
190/** 190/**
191 * Initialize the transport testing 191 * Initialize the transport testing
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c
index cff967b19..b7704e512 100644
--- a/src/transport/transport_api.c
+++ b/src/transport/transport_api.c
@@ -473,7 +473,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
473 GNUNET_break (0); 473 GNUNET_break (0);
474 break; 474 break;
475 } 475 }
476 ats = (const struct GNUNET_ATS_Information*) &cim[1]; 476 ats = (const struct GNUNET_ATS_Information *) &cim[1];
477#if DEBUG_TRANSPORT_API 477#if DEBUG_TRANSPORT_API
478 LOG (GNUNET_ERROR_TYPE_DEBUG, "Receiving `%s' message for `%4s'.\n", 478 LOG (GNUNET_ERROR_TYPE_DEBUG, "Receiving `%s' message for `%4s'.\n",
479 "CONNECT", GNUNET_i2s (&cim->id)); 479 "CONNECT", GNUNET_i2s (&cim->id));
@@ -547,7 +547,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
547 } 547 }
548 im = (const struct InboundMessage *) msg; 548 im = (const struct InboundMessage *) msg;
549 ats_count = ntohl (im->ats_count); 549 ats_count = ntohl (im->ats_count);
550 ats = (const struct GNUNET_ATS_Information*) &im[1]; 550 ats = (const struct GNUNET_ATS_Information *) &im[1];
551 imm = (const struct GNUNET_MessageHeader *) &ats[ats_count]; 551 imm = (const struct GNUNET_MessageHeader *) &ats[ats_count];
552 if (ntohs (imm->size) + sizeof (struct InboundMessage) + 552 if (ntohs (imm->size) + sizeof (struct InboundMessage) +
553 ats_count * sizeof (struct GNUNET_ATS_Information) != size) 553 ats_count * sizeof (struct GNUNET_ATS_Information) != size)
diff --git a/src/transport/transport_api_address_iterate.c b/src/transport/transport_api_address_iterate.c
index 2ffe1ada8..3c3f97c28 100644
--- a/src/transport/transport_api_address_iterate.c
+++ b/src/transport/transport_api_address_iterate.c
@@ -80,7 +80,8 @@ peer_address_response_processor (void *cls,
80 struct AddressLookupCtx *alucb = cls; 80 struct AddressLookupCtx *alucb = cls;
81 struct AddressIterateResponseMessage *address; 81 struct AddressIterateResponseMessage *address;
82 uint16_t size; 82 uint16_t size;
83 char * transport; 83 char *transport;
84
84 //size_t transport_len; 85 //size_t transport_len;
85 //void * addr; 86 //void * addr;
86 size_t addrlen; 87 size_t addrlen;
@@ -120,7 +121,7 @@ peer_address_response_processor (void *cls,
120 121
121 transport = (char *) &address[0]; 122 transport = (char *) &address[0];
122 //transport_len = ntohs(address->pluginlen); 123 //transport_len = ntohs(address->pluginlen);
123 addrlen = ntohs(address->addrlen); 124 addrlen = ntohs (address->addrlen);
124 125
125 /* expect more replies */ 126 /* expect more replies */
126 GNUNET_CLIENT_receive (alucb->client, &peer_address_response_processor, alucb, 127 GNUNET_CLIENT_receive (alucb->client, &peer_address_response_processor, alucb,
diff --git a/src/util/bandwidth.c b/src/util/bandwidth.c
index a736b7607..0920362f5 100644
--- a/src/util/bandwidth.c
+++ b/src/util/bandwidth.c
@@ -60,11 +60,11 @@ GNUNET_BANDWIDTH_value_init (uint32_t bytes_per_second)
60 */ 60 */
61struct GNUNET_BANDWIDTH_Value32NBO 61struct GNUNET_BANDWIDTH_Value32NBO
62GNUNET_BANDWIDTH_value_min (struct GNUNET_BANDWIDTH_Value32NBO b1, 62GNUNET_BANDWIDTH_value_min (struct GNUNET_BANDWIDTH_Value32NBO b1,
63 struct GNUNET_BANDWIDTH_Value32NBO b2) 63 struct GNUNET_BANDWIDTH_Value32NBO b2)
64{ 64{
65 return 65 return
66 GNUNET_BANDWIDTH_value_init (GNUNET_MIN 66 GNUNET_BANDWIDTH_value_init (GNUNET_MIN
67 (ntohl (b1.value__), ntohl (b2.value__))); 67 (ntohl (b1.value__), ntohl (b2.value__)));
68} 68}
69 69
70 70
@@ -78,9 +78,9 @@ GNUNET_BANDWIDTH_value_min (struct GNUNET_BANDWIDTH_Value32NBO b1,
78 */ 78 */
79uint64_t 79uint64_t
80GNUNET_BANDWIDTH_value_get_available_until (struct GNUNET_BANDWIDTH_Value32NBO 80GNUNET_BANDWIDTH_value_get_available_until (struct GNUNET_BANDWIDTH_Value32NBO
81 bps, 81 bps,
82 struct GNUNET_TIME_Relative 82 struct GNUNET_TIME_Relative
83 deadline) 83 deadline)
84{ 84{
85 uint64_t b; 85 uint64_t b;
86 86
@@ -105,20 +105,20 @@ GNUNET_BANDWIDTH_value_get_available_until (struct GNUNET_BANDWIDTH_Value32NBO
105 */ 105 */
106struct GNUNET_TIME_Relative 106struct GNUNET_TIME_Relative
107GNUNET_BANDWIDTH_value_get_delay_for (struct GNUNET_BANDWIDTH_Value32NBO bps, 107GNUNET_BANDWIDTH_value_get_delay_for (struct GNUNET_BANDWIDTH_Value32NBO bps,
108 uint64_t size) 108 uint64_t size)
109{ 109{
110 uint64_t b; 110 uint64_t b;
111 struct GNUNET_TIME_Relative ret; 111 struct GNUNET_TIME_Relative ret;
112 112
113 b = ntohl (bps.value__); 113 b = ntohl (bps.value__);
114 if (b == 0) 114 if (b == 0)
115 { 115 {
116#if DEBUG_BANDWIDTH 116#if DEBUG_BANDWIDTH
117 LOG (GNUNET_ERROR_TYPE_DEBUG, 117 LOG (GNUNET_ERROR_TYPE_DEBUG,
118 "Bandwidth suggests delay of infinity (zero bandwidth)\n"); 118 "Bandwidth suggests delay of infinity (zero bandwidth)\n");
119#endif 119#endif
120 return GNUNET_TIME_UNIT_FOREVER_REL; 120 return GNUNET_TIME_UNIT_FOREVER_REL;
121 } 121 }
122 ret.rel_value = size * 1000LL / b; 122 ret.rel_value = size * 1000LL / b;
123#if DEBUG_BANDWIDTH 123#if DEBUG_BANDWIDTH
124 LOG (GNUNET_ERROR_TYPE_DEBUG, 124 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -145,8 +145,8 @@ GNUNET_BANDWIDTH_value_get_delay_for (struct GNUNET_BANDWIDTH_Value32NBO bps,
145 */ 145 */
146void 146void
147GNUNET_BANDWIDTH_tracker_init (struct GNUNET_BANDWIDTH_Tracker *av, 147GNUNET_BANDWIDTH_tracker_init (struct GNUNET_BANDWIDTH_Tracker *av,
148 struct GNUNET_BANDWIDTH_Value32NBO 148 struct GNUNET_BANDWIDTH_Value32NBO
149 bytes_per_second_limit, uint32_t max_carry_s) 149 bytes_per_second_limit, uint32_t max_carry_s)
150{ 150{
151 av->consumption_since_last_update__ = 0; 151 av->consumption_since_last_update__ = 0;
152 av->last_update__ = GNUNET_TIME_absolute_get (); 152 av->last_update__ = GNUNET_TIME_absolute_get ();
@@ -155,8 +155,7 @@ GNUNET_BANDWIDTH_tracker_init (struct GNUNET_BANDWIDTH_Tracker *av,
155#if DEBUG_BANDWIDTH 155#if DEBUG_BANDWIDTH
156 LOG (GNUNET_ERROR_TYPE_DEBUG, 156 LOG (GNUNET_ERROR_TYPE_DEBUG,
157 "Tracker %p initialized with %u Bps and max carry %u\n", av, 157 "Tracker %p initialized with %u Bps and max carry %u\n", av,
158 (unsigned int) av->available_bytes_per_s__, 158 (unsigned int) av->available_bytes_per_s__, (unsigned int) max_carry_s);
159 (unsigned int) max_carry_s);
160#endif 159#endif
161} 160}
162 161
@@ -179,25 +178,25 @@ update_tracker (struct GNUNET_BANDWIDTH_Tracker *av)
179 now = GNUNET_TIME_absolute_get (); 178 now = GNUNET_TIME_absolute_get ();
180 delta_time = now.abs_value - av->last_update__.abs_value; 179 delta_time = now.abs_value - av->last_update__.abs_value;
181 delta_avail = 180 delta_avail =
182 (delta_time * ((unsigned long long) av->available_bytes_per_s__) + 181 (delta_time * ((unsigned long long) av->available_bytes_per_s__) +
183 500LL) / 1000LL; 182 500LL) / 1000LL;
184 av->consumption_since_last_update__ -= delta_avail; 183 av->consumption_since_last_update__ -= delta_avail;
185 av->last_update__ = now; 184 av->last_update__ = now;
186 if (av->consumption_since_last_update__ < 0) 185 if (av->consumption_since_last_update__ < 0)
187 { 186 {
188 left_bytes = -av->consumption_since_last_update__; 187 left_bytes = -av->consumption_since_last_update__;
189 max_carry = av->available_bytes_per_s__ * av->max_carry_s__; 188 max_carry = av->available_bytes_per_s__ * av->max_carry_s__;
190 if (max_carry < GNUNET_SERVER_MAX_MESSAGE_SIZE) 189 if (max_carry < GNUNET_SERVER_MAX_MESSAGE_SIZE)
191 max_carry = GNUNET_SERVER_MAX_MESSAGE_SIZE; 190 max_carry = GNUNET_SERVER_MAX_MESSAGE_SIZE;
192 if (max_carry > left_bytes) 191 if (max_carry > left_bytes)
193 av->consumption_since_last_update__ = -left_bytes; 192 av->consumption_since_last_update__ = -left_bytes;
194 else 193 else
195 av->consumption_since_last_update__ = -max_carry; 194 av->consumption_since_last_update__ = -max_carry;
196 } 195 }
197#if DEBUG_BANDWIDTH 196#if DEBUG_BANDWIDTH
198 LOG (GNUNET_ERROR_TYPE_DEBUG, 197 LOG (GNUNET_ERROR_TYPE_DEBUG,
199 "Tracker %p updated, have %u Bps, last update was %llu ms ago\n", 198 "Tracker %p updated, have %u Bps, last update was %llu ms ago\n", av,
200 av, (unsigned int) av->available_bytes_per_s__, 199 (unsigned int) av->available_bytes_per_s__,
201 (unsigned long long) delta_time); 200 (unsigned long long) delta_time);
202#endif 201#endif
203 202
@@ -217,7 +216,7 @@ update_tracker (struct GNUNET_BANDWIDTH_Tracker *av)
217 */ 216 */
218int 217int
219GNUNET_BANDWIDTH_tracker_consume (struct GNUNET_BANDWIDTH_Tracker *av, 218GNUNET_BANDWIDTH_tracker_consume (struct GNUNET_BANDWIDTH_Tracker *av,
220 ssize_t size) 219 ssize_t size)
221{ 220{
222 int64_t nc; 221 int64_t nc;
223 222
@@ -226,29 +225,29 @@ GNUNET_BANDWIDTH_tracker_consume (struct GNUNET_BANDWIDTH_Tracker *av,
226 (int) size); 225 (int) size);
227#endif 226#endif
228 if (size > 0) 227 if (size > 0)
228 {
229 nc = av->consumption_since_last_update__ + size;
230 if (nc < av->consumption_since_last_update__)
231 {
232 GNUNET_break (0);
233 return GNUNET_SYSERR;
234 }
235 av->consumption_since_last_update__ = nc;
236 update_tracker (av);
237 if (av->consumption_since_last_update__ > 0)
229 { 238 {
230 nc = av->consumption_since_last_update__ + size;
231 if (nc < av->consumption_since_last_update__)
232 {
233 GNUNET_break (0);
234 return GNUNET_SYSERR;
235 }
236 av->consumption_since_last_update__ = nc;
237 update_tracker (av);
238 if (av->consumption_since_last_update__ > 0)
239 {
240#if DEBUG_BANDWIDTH 239#if DEBUG_BANDWIDTH
241 LOG (GNUNET_ERROR_TYPE_DEBUG, 240 LOG (GNUNET_ERROR_TYPE_DEBUG,
242 "Tracker %p consumption %llu bytes above limit\n", av, 241 "Tracker %p consumption %llu bytes above limit\n", av,
243 (unsigned long long) av->consumption_since_last_update__); 242 (unsigned long long) av->consumption_since_last_update__);
244#endif 243#endif
245 return GNUNET_YES; 244 return GNUNET_YES;
246 }
247 } 245 }
246 }
248 else 247 else
249 { 248 {
250 av->consumption_since_last_update__ += size; 249 av->consumption_since_last_update__ += size;
251 } 250 }
252 return GNUNET_NO; 251 return GNUNET_NO;
253} 252}
254 253
@@ -264,35 +263,34 @@ GNUNET_BANDWIDTH_tracker_consume (struct GNUNET_BANDWIDTH_Tracker *av,
264 */ 263 */
265struct GNUNET_TIME_Relative 264struct GNUNET_TIME_Relative
266GNUNET_BANDWIDTH_tracker_get_delay (struct GNUNET_BANDWIDTH_Tracker *av, 265GNUNET_BANDWIDTH_tracker_get_delay (struct GNUNET_BANDWIDTH_Tracker *av,
267 size_t size) 266 size_t size)
268{ 267{
269 struct GNUNET_TIME_Relative ret; 268 struct GNUNET_TIME_Relative ret;
270 int64_t bytes_needed; 269 int64_t bytes_needed;
271 270
272 if (av->available_bytes_per_s__ == 0) 271 if (av->available_bytes_per_s__ == 0)
273 { 272 {
274#if DEBUG_BANDWIDTH 273#if DEBUG_BANDWIDTH
275 LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p delay is infinity\n", av); 274 LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p delay is infinity\n", av);
276#endif 275#endif
277 return GNUNET_TIME_UNIT_FOREVER_REL; 276 return GNUNET_TIME_UNIT_FOREVER_REL;
278 } 277 }
279 update_tracker (av); 278 update_tracker (av);
280 bytes_needed = size + av->consumption_since_last_update__; 279 bytes_needed = size + av->consumption_since_last_update__;
281 if (bytes_needed <= 0) 280 if (bytes_needed <= 0)
282 { 281 {
283#if DEBUG_BANDWIDTH 282#if DEBUG_BANDWIDTH
284 LOG (GNUNET_ERROR_TYPE_DEBUG, 283 LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p delay for %u bytes is zero\n", av,
285 "Tracker %p delay for %u bytes is zero\n", av, 284 (unsigned int) size);
286 (unsigned int) size);
287#endif 285#endif
288 return GNUNET_TIME_UNIT_ZERO; 286 return GNUNET_TIME_UNIT_ZERO;
289 } 287 }
290 ret.rel_value = 288 ret.rel_value =
291 (1000LL * bytes_needed) / (unsigned long long) av->available_bytes_per_s__; 289 (1000LL * bytes_needed) /
290 (unsigned long long) av->available_bytes_per_s__;
292#if DEBUG_BANDWIDTH 291#if DEBUG_BANDWIDTH
293 LOG (GNUNET_ERROR_TYPE_DEBUG, 292 LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p delay for %u bytes is %llu ms\n",
294 "Tracker %p delay for %u bytes is %llu ms\n", av, 293 av, (unsigned int) size, (unsigned long long) ret.rel_value);
295 (unsigned int) size, (unsigned long long) ret.rel_value);
296#endif 294#endif
297 return ret; 295 return ret;
298} 296}
@@ -315,9 +313,9 @@ GNUNET_BANDWIDTH_tracker_get_available (struct GNUNET_BANDWIDTH_Tracker * av)
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 = 315 avail =
318 GNUNET_BANDWIDTH_value_get_available_until (bps, 316 GNUNET_BANDWIDTH_value_get_available_until (bps,
319 GNUNET_TIME_absolute_get_duration 317 GNUNET_TIME_absolute_get_duration
320 (av->last_update__)); 318 (av->last_update__));
321 used = av->consumption_since_last_update__; 319 used = av->consumption_since_last_update__;
322#if DEBUG_BANDWIDTH 320#if DEBUG_BANDWIDTH
323 LOG (GNUNET_ERROR_TYPE_DEBUG, 321 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -336,23 +334,22 @@ GNUNET_BANDWIDTH_tracker_get_available (struct GNUNET_BANDWIDTH_Tracker * av)
336 */ 334 */
337void 335void
338GNUNET_BANDWIDTH_tracker_update_quota (struct GNUNET_BANDWIDTH_Tracker *av, 336GNUNET_BANDWIDTH_tracker_update_quota (struct GNUNET_BANDWIDTH_Tracker *av,
339 struct GNUNET_BANDWIDTH_Value32NBO 337 struct GNUNET_BANDWIDTH_Value32NBO
340 bytes_per_second_limit) 338 bytes_per_second_limit)
341{ 339{
342 uint32_t old_limit; 340 uint32_t old_limit;
343 uint32_t new_limit; 341 uint32_t new_limit;
344 342
345 new_limit = ntohl (bytes_per_second_limit.value__); 343 new_limit = ntohl (bytes_per_second_limit.value__);
346#if DEBUG_BANDWIDTH 344#if DEBUG_BANDWIDTH
347 LOG (GNUNET_ERROR_TYPE_DEBUG, 345 LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p bandwidth changed to %u Bps\n", av,
348 "Tracker %p bandwidth changed to %u Bps\n", av,
349 (unsigned int) new_limit); 346 (unsigned int) new_limit);
350#endif 347#endif
351 update_tracker (av); 348 update_tracker (av);
352 old_limit = av->available_bytes_per_s__; 349 old_limit = av->available_bytes_per_s__;
353 av->available_bytes_per_s__ = new_limit; 350 av->available_bytes_per_s__ = new_limit;
354 if (old_limit > new_limit) 351 if (old_limit > new_limit)
355 update_tracker (av); /* maximum excess might be less now */ 352 update_tracker (av); /* maximum excess might be less now */
356} 353}
357 354
358 355
diff --git a/src/util/bio.c b/src/util/bio.c
index 9c2b9d0dd..41ad5fd5d 100644
--- a/src/util/bio.c
+++ b/src/util/bio.c
@@ -58,8 +58,7 @@ GNUNET_BIO_read_open (const char *fn)
58 struct GNUNET_DISK_FileHandle *fd; 58 struct GNUNET_DISK_FileHandle *fd;
59 struct GNUNET_BIO_ReadHandle *h; 59 struct GNUNET_BIO_ReadHandle *h;
60 60
61 fd = 61 fd = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE);
62 GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE);
63 if (NULL == fd) 62 if (NULL == fd)
64 return NULL; 63 return NULL;
65 h = GNUNET_malloc (sizeof (struct GNUNET_BIO_ReadHandle) + BIO_BUFFER_SIZE); 64 h = GNUNET_malloc (sizeof (struct GNUNET_BIO_ReadHandle) + BIO_BUFFER_SIZE);
@@ -105,7 +104,7 @@ GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg)
105 */ 104 */
106int 105int
107GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, const char *what, 106GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, const char *what,
108 void *result, size_t len) 107 void *result, size_t len)
109{ 108{
110 char *dst = result; 109 char *dst = result;
111 size_t min; 110 size_t min;
@@ -116,38 +115,38 @@ GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, const char *what,
116 return GNUNET_SYSERR; 115 return GNUNET_SYSERR;
117 pos = 0; 116 pos = 0;
118 do 117 do
118 {
119 /* first, use buffer */
120 min = h->have - h->pos;
121 if (min > 0)
119 { 122 {
120 /* first, use buffer */ 123 if (min > len - pos)
121 min = h->have - h->pos; 124 min = len - pos;
122 if (min > 0) 125 memcpy (&dst[pos], &h->buffer[h->pos], min);
123 { 126 h->pos += min;
124 if (min > len - pos) 127 pos += min;
125 min = len - pos; 128 }
126 memcpy (&dst[pos], &h->buffer[h->pos], min); 129 if (pos == len)
127 h->pos += min; 130 return GNUNET_OK; /* done! */
128 pos += min; 131 GNUNET_assert (h->have == h->pos);
129 } 132 /* fill buffer */
130 if (pos == len) 133 ret = GNUNET_DISK_file_read (h->fd, h->buffer, h->size);
131 return GNUNET_OK; /* done! */ 134 if (ret == -1)
132 GNUNET_assert (h->have == h->pos); 135 {
133 /* fill buffer */ 136 GNUNET_asprintf (&h->emsg, _("Error reading `%s': %s"), what,
134 ret = GNUNET_DISK_file_read (h->fd, h->buffer, h->size); 137 STRERROR (errno));
135 if (ret == -1) 138 return GNUNET_SYSERR;
136 { 139 }
137 GNUNET_asprintf (&h->emsg, _("Error reading `%s': %s"), what, 140 if (ret == 0)
138 STRERROR (errno)); 141 {
139 return GNUNET_SYSERR; 142 GNUNET_asprintf (&h->emsg, _("Error reading `%s': %s"), what,
140 } 143 _("End of file"));
141 if (ret == 0) 144 return GNUNET_SYSERR;
142 {
143 GNUNET_asprintf (&h->emsg, _("Error reading `%s': %s"), what,
144 _("End of file"));
145 return GNUNET_SYSERR;
146 }
147 h->pos = 0;
148 h->have = ret;
149 } 145 }
150 while (pos < len); /* should always be true */ 146 h->pos = 0;
147 h->have = ret;
148 }
149 while (pos < len); /* should always be true */
151 return GNUNET_OK; 150 return GNUNET_OK;
152} 151}
153 152
@@ -163,8 +162,8 @@ GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, const char *what,
163 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 162 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
164 */ 163 */
165int 164int
166GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h, const char *file, 165GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h, const char *file, int line,
167 int line, void *result, size_t len) 166 void *result, size_t len)
168{ 167{
169 char what[1024]; 168 char what[1024];
170 169
@@ -185,41 +184,39 @@ GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h, const char *file,
185 */ 184 */
186int 185int
187GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, const char *what, 186GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, const char *what,
188 char **result, size_t maxLen) 187 char **result, size_t maxLen)
189{ 188{
190 char *buf; 189 char *buf;
191 uint32_t big; 190 uint32_t big;
192 191
193 if (GNUNET_OK != GNUNET_BIO_read_int32 (h, &big)) 192 if (GNUNET_OK != GNUNET_BIO_read_int32 (h, &big))
194 { 193 {
195 GNUNET_free_non_null (h->emsg); 194 GNUNET_free_non_null (h->emsg);
196 GNUNET_asprintf (&h->emsg, _("Error reading length of string `%s'"), 195 GNUNET_asprintf (&h->emsg, _("Error reading length of string `%s'"), what);
197 what); 196 return GNUNET_SYSERR;
198 return GNUNET_SYSERR; 197 }
199 }
200 if (big == 0) 198 if (big == 0)
201 { 199 {
202 *result = NULL; 200 *result = NULL;
203 return GNUNET_OK; 201 return GNUNET_OK;
204 } 202 }
205 if (big > maxLen) 203 if (big > maxLen)
206 { 204 {
207 GNUNET_asprintf (&h->emsg, 205 GNUNET_asprintf (&h->emsg, _("String `%s' longer than allowed (%u > %u)"),
208 _("String `%s' longer than allowed (%u > %u)"), what, 206 what, big, maxLen);
209 big, maxLen); 207 return GNUNET_SYSERR;
210 return GNUNET_SYSERR; 208 }
211 }
212 buf = GNUNET_malloc (big); 209 buf = GNUNET_malloc (big);
213 *result = buf; 210 *result = buf;
214 buf[--big] = '\0'; 211 buf[--big] = '\0';
215 if (big == 0) 212 if (big == 0)
216 return GNUNET_OK; 213 return GNUNET_OK;
217 if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, big)) 214 if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, big))
218 { 215 {
219 GNUNET_free (buf); 216 GNUNET_free (buf);
220 *result = NULL; 217 *result = NULL;
221 return GNUNET_SYSERR; 218 return GNUNET_SYSERR;
222 } 219 }
223 return GNUNET_OK; 220 return GNUNET_OK;
224} 221}
225 222
@@ -234,7 +231,7 @@ GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, const char *what,
234 */ 231 */
235int 232int
236GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, const char *what, 233GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, const char *what,
237 struct GNUNET_CONTAINER_MetaData **result) 234 struct GNUNET_CONTAINER_MetaData **result)
238{ 235{
239 uint32_t size; 236 uint32_t size;
240 char *buf; 237 char *buf;
@@ -243,32 +240,30 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, const char *what,
243 if (GNUNET_BIO_read_int32 (h, (int32_t *) & size) != GNUNET_OK) 240 if (GNUNET_BIO_read_int32 (h, (int32_t *) & size) != GNUNET_OK)
244 return GNUNET_SYSERR; 241 return GNUNET_SYSERR;
245 if (size == 0) 242 if (size == 0)
246 { 243 {
247 *result = NULL; 244 *result = NULL;
248 return GNUNET_OK; 245 return GNUNET_OK;
249 } 246 }
250 if (size > MAX_META_DATA) 247 if (size > MAX_META_DATA)
251 { 248 {
252 GNUNET_asprintf (&h->emsg, 249 GNUNET_asprintf (&h->emsg,
253 _ 250 _("Serialized metadata `%s' larger than allowed (%u>%u)"),
254 ("Serialized metadata `%s' larger than allowed (%u>%u)"), 251 what, size, MAX_META_DATA);
255 what, size, MAX_META_DATA); 252 return GNUNET_SYSERR;
256 return GNUNET_SYSERR; 253 }
257 }
258 buf = GNUNET_malloc (size); 254 buf = GNUNET_malloc (size);
259 if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, size)) 255 if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, size))
260 { 256 {
261 GNUNET_free (buf); 257 GNUNET_free (buf);
262 return GNUNET_SYSERR; 258 return GNUNET_SYSERR;
263 } 259 }
264 meta = GNUNET_CONTAINER_meta_data_deserialize (buf, size); 260 meta = GNUNET_CONTAINER_meta_data_deserialize (buf, size);
265 if (meta == NULL) 261 if (meta == NULL)
266 { 262 {
267 GNUNET_free (buf); 263 GNUNET_free (buf);
268 GNUNET_asprintf (&h->emsg, _("Metadata `%s' failed to deserialize"), 264 GNUNET_asprintf (&h->emsg, _("Metadata `%s' failed to deserialize"), what);
269 what); 265 return GNUNET_SYSERR;
270 return GNUNET_SYSERR; 266 }
271 }
272 GNUNET_free (buf); 267 GNUNET_free (buf);
273 *result = meta; 268 *result = meta;
274 return GNUNET_OK; 269 return GNUNET_OK;
@@ -286,7 +281,7 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, const char *what,
286 */ 281 */
287int 282int
288GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, const char *file, 283GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, const char *file,
289 int line, int32_t * i) 284 int line, int32_t * i)
290{ 285{
291 int32_t big; 286 int32_t big;
292 287
@@ -308,7 +303,7 @@ GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, const char *file,
308 */ 303 */
309int 304int
310GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h, const char *file, 305GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h, const char *file,
311 int line, int64_t * i) 306 int line, int64_t * i)
312{ 307{
313 int64_t big; 308 int64_t big;
314 309
@@ -344,15 +339,13 @@ GNUNET_BIO_write_open (const char *fn)
344 struct GNUNET_BIO_WriteHandle *h; 339 struct GNUNET_BIO_WriteHandle *h;
345 340
346 fd = GNUNET_DISK_file_open (fn, 341 fd = GNUNET_DISK_file_open (fn,
347 GNUNET_DISK_OPEN_WRITE | 342 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE
348 GNUNET_DISK_OPEN_TRUNCATE | 343 | GNUNET_DISK_OPEN_CREATE,
349 GNUNET_DISK_OPEN_CREATE, 344 GNUNET_DISK_PERM_USER_READ |
350 GNUNET_DISK_PERM_USER_READ | 345 GNUNET_DISK_PERM_USER_WRITE);
351 GNUNET_DISK_PERM_USER_WRITE);
352 if (NULL == fd) 346 if (NULL == fd)
353 return NULL; 347 return NULL;
354 h = 348 h = GNUNET_malloc (sizeof (struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE);
355 GNUNET_malloc (sizeof (struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE);
356 h->buffer = (char *) &h[1]; 349 h->buffer = (char *) &h[1];
357 h->size = BIO_BUFFER_SIZE; 350 h->size = BIO_BUFFER_SIZE;
358 h->fd = fd; 351 h->fd = fd;
@@ -374,18 +367,18 @@ GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h)
374 int ret; 367 int ret;
375 368
376 if (NULL == h->fd) 369 if (NULL == h->fd)
377 { 370 {
378 ret = GNUNET_SYSERR; 371 ret = GNUNET_SYSERR;
379 } 372 }
380 else 373 else
381 { 374 {
382 wrt = GNUNET_DISK_file_write (h->fd, h->buffer, h->have); 375 wrt = GNUNET_DISK_file_write (h->fd, h->buffer, h->have);
383 if (wrt == h->have) 376 if (wrt == h->have)
384 ret = GNUNET_OK; 377 ret = GNUNET_OK;
385 else 378 else
386 ret = GNUNET_SYSERR; 379 ret = GNUNET_SYSERR;
387 GNUNET_DISK_file_close (h->fd); 380 GNUNET_DISK_file_close (h->fd);
388 } 381 }
389 GNUNET_free (h); 382 GNUNET_free (h);
390 return ret; 383 return ret;
391} 384}
@@ -401,7 +394,7 @@ GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h)
401 */ 394 */
402int 395int
403GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, const void *buffer, 396GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, const void *buffer,
404 size_t n) 397 size_t n)
405{ 398{
406 const char *src = buffer; 399 const char *src = buffer;
407 size_t min; 400 size_t min;
@@ -412,27 +405,27 @@ GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, const void *buffer,
412 return GNUNET_SYSERR; 405 return GNUNET_SYSERR;
413 pos = 0; 406 pos = 0;
414 do 407 do
408 {
409 /* first, just use buffer */
410 min = h->size - h->have;
411 if (min > n - pos)
412 min = n - pos;
413 memcpy (&h->buffer[h->have], &src[pos], min);
414 pos += min;
415 h->have += min;
416 if (pos == n)
417 return GNUNET_OK; /* done */
418 GNUNET_assert (h->have == h->size);
419 ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->size);
420 if (ret != h->size)
415 { 421 {
416 /* first, just use buffer */ 422 GNUNET_DISK_file_close (h->fd);
417 min = h->size - h->have; 423 h->fd = NULL;
418 if (min > n - pos) 424 return GNUNET_SYSERR; /* error */
419 min = n - pos;
420 memcpy (&h->buffer[h->have], &src[pos], min);
421 pos += min;
422 h->have += min;
423 if (pos == n)
424 return GNUNET_OK; /* done */
425 GNUNET_assert (h->have == h->size);
426 ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->size);
427 if (ret != h->size)
428 {
429 GNUNET_DISK_file_close (h->fd);
430 h->fd = NULL;
431 return GNUNET_SYSERR; /* error */
432 }
433 h->have = 0;
434 } 425 }
435 while (pos < n); /* should always be true */ 426 h->have = 0;
427 }
428 while (pos < n); /* should always be true */
436 GNUNET_break (0); 429 GNUNET_break (0);
437 return GNUNET_OK; 430 return GNUNET_OK;
438} 431}
@@ -468,7 +461,7 @@ GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, const char *s)
468 */ 461 */
469int 462int
470GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h, 463GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
471 const struct GNUNET_CONTAINER_MetaData *m) 464 const struct GNUNET_CONTAINER_MetaData *m)
472{ 465{
473 ssize_t size; 466 ssize_t size;
474 char *buf; 467 char *buf;
@@ -477,19 +470,19 @@ GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
477 return GNUNET_BIO_write_int32 (h, 0); 470 return GNUNET_BIO_write_int32 (h, 0);
478 buf = NULL; 471 buf = NULL;
479 size = 472 size =
480 GNUNET_CONTAINER_meta_data_serialize (m, &buf, MAX_META_DATA, 473 GNUNET_CONTAINER_meta_data_serialize (m, &buf, MAX_META_DATA,
481 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); 474 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
482 if (size == -1) 475 if (size == -1)
483 { 476 {
484 GNUNET_free (buf); 477 GNUNET_free (buf);
485 return GNUNET_SYSERR; 478 return GNUNET_SYSERR;
486 } 479 }
487 if ((GNUNET_OK != GNUNET_BIO_write_int32 (h, (uint32_t) size)) || 480 if ((GNUNET_OK != GNUNET_BIO_write_int32 (h, (uint32_t) size)) ||
488 (GNUNET_OK != GNUNET_BIO_write (h, buf, size))) 481 (GNUNET_OK != GNUNET_BIO_write (h, buf, size)))
489 { 482 {
490 GNUNET_free (buf); 483 GNUNET_free (buf);
491 return GNUNET_SYSERR; 484 return GNUNET_SYSERR;
492 } 485 }
493 GNUNET_free (buf); 486 GNUNET_free (buf);
494 return GNUNET_OK; 487 return GNUNET_OK;
495} 488}
diff --git a/src/util/client.c b/src/util/client.c
index d2f347947..e71ccdf39 100644
--- a/src/util/client.c
+++ b/src/util/client.c
@@ -259,8 +259,7 @@ struct GNUNET_CLIENT_Connection
259 */ 259 */
260static struct GNUNET_CONNECTION_Handle * 260static struct GNUNET_CONNECTION_Handle *
261do_connect (const char *service_name, 261do_connect (const char *service_name,
262 const struct GNUNET_CONFIGURATION_Handle *cfg, 262 const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned int attempt)
263 unsigned int attempt)
264{ 263{
265 struct GNUNET_CONNECTION_Handle *sock; 264 struct GNUNET_CONNECTION_Handle *sock;
266 char *hostname; 265 char *hostname;
@@ -270,80 +269,78 @@ do_connect (const char *service_name,
270 sock = NULL; 269 sock = NULL;
271#if AF_UNIX 270#if AF_UNIX
272 if (0 == (attempt % 2)) 271 if (0 == (attempt % 2))
272 {
273 /* on even rounds, try UNIX */
274 unixpath = NULL;
275 if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "UNIXPATH", &unixpath)) && (0 < strlen (unixpath))) /* We have a non-NULL unixpath, does that mean it's valid? */
273 { 276 {
274 /* on even rounds, try UNIX */ 277 sock = GNUNET_CONNECTION_create_from_connect_to_unixpath (cfg, unixpath);
275 unixpath = NULL; 278 if (sock != NULL)
276 if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "UNIXPATH", &unixpath)) && (0 < strlen (unixpath))) /* We have a non-NULL unixpath, does that mean it's valid? */ 279 {
277 {
278 sock =
279 GNUNET_CONNECTION_create_from_connect_to_unixpath (cfg, unixpath);
280 if (sock != NULL)
281 {
282#if DEBUG_CLIENT 280#if DEBUG_CLIENT
283 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connected to unixpath `%s'!\n", 281 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connected to unixpath `%s'!\n",
284 unixpath); 282 unixpath);
285#endif 283#endif
286 GNUNET_free (unixpath); 284 GNUNET_free (unixpath);
287 return sock; 285 return sock;
288 } 286 }
289 }
290 GNUNET_free_non_null (unixpath);
291 } 287 }
288 GNUNET_free_non_null (unixpath);
289 }
292#endif 290#endif
293 291
294 if ((GNUNET_OK != 292 if ((GNUNET_OK !=
295 GNUNET_CONFIGURATION_get_value_number (cfg, service_name, "PORT", 293 GNUNET_CONFIGURATION_get_value_number (cfg, service_name, "PORT", &port))
296 &port)) || (port > 65535) 294 || (port > 65535) ||
297 || (GNUNET_OK != 295 (GNUNET_OK !=
298 GNUNET_CONFIGURATION_get_value_string (cfg, service_name, 296 GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "HOSTNAME",
299 "HOSTNAME", &hostname))) 297 &hostname)))
300 { 298 {
301 LOG (GNUNET_ERROR_TYPE_WARNING, 299 LOG (GNUNET_ERROR_TYPE_WARNING,
302 _ 300 _
303 ("Could not determine valid hostname and port for service `%s' from configuration.\n"), 301 ("Could not determine valid hostname and port for service `%s' from configuration.\n"),
304 service_name); 302 service_name);
305 return NULL; 303 return NULL;
306 } 304 }
307 if (0 == strlen (hostname)) 305 if (0 == strlen (hostname))
308 { 306 {
309 GNUNET_free (hostname); 307 GNUNET_free (hostname);
310 LOG (GNUNET_ERROR_TYPE_WARNING, 308 LOG (GNUNET_ERROR_TYPE_WARNING,
311 _("Need a non-empty hostname for service `%s'.\n"), service_name); 309 _("Need a non-empty hostname for service `%s'.\n"), service_name);
312 return NULL; 310 return NULL;
313 } 311 }
314 if (port == 0) 312 if (port == 0)
315 { 313 {
316#if AF_UNIX 314#if AF_UNIX
317 if (0 != (attempt % 2)) 315 if (0 != (attempt % 2))
318 { 316 {
319 /* try UNIX */ 317 /* try UNIX */
320 unixpath = NULL; 318 unixpath = NULL;
321 if ((GNUNET_OK == 319 if ((GNUNET_OK ==
322 GNUNET_CONFIGURATION_get_value_string (cfg, service_name, 320 GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "UNIXPATH",
323 "UNIXPATH", &unixpath)) 321 &unixpath)) &&
324 && (0 < strlen (unixpath))) 322 (0 < strlen (unixpath)))
325 { 323 {
326 sock = 324 sock =
327 GNUNET_CONNECTION_create_from_connect_to_unixpath (cfg, 325 GNUNET_CONNECTION_create_from_connect_to_unixpath (cfg, unixpath);
328 unixpath); 326 if (sock != NULL)
329 if (sock != NULL) 327 {
330 { 328 GNUNET_free (unixpath);
331 GNUNET_free (unixpath); 329 GNUNET_free (hostname);
332 GNUNET_free (hostname); 330 return sock;
333 return sock; 331 }
334 } 332 }
335 } 333 GNUNET_free_non_null (unixpath);
336 GNUNET_free_non_null (unixpath); 334 }
337 }
338#endif 335#endif
339#if DEBUG_CLIENT 336#if DEBUG_CLIENT
340 LOG (GNUNET_ERROR_TYPE_DEBUG, 337 LOG (GNUNET_ERROR_TYPE_DEBUG,
341 "Port is 0 for service `%s', UNIXPATH did not work, returning NULL!\n", 338 "Port is 0 for service `%s', UNIXPATH did not work, returning NULL!\n",
342 service_name); 339 service_name);
343#endif 340#endif
344 GNUNET_free (hostname); 341 GNUNET_free (hostname);
345 return NULL; 342 return NULL;
346 } 343 }
347 344
348 sock = GNUNET_CONNECTION_create_from_connect (cfg, hostname, port); 345 sock = GNUNET_CONNECTION_create_from_connect (cfg, hostname, port);
349 GNUNET_free (hostname); 346 GNUNET_free (hostname);
@@ -360,7 +357,7 @@ do_connect (const char *service_name,
360 */ 357 */
361struct GNUNET_CLIENT_Connection * 358struct GNUNET_CLIENT_Connection *
362GNUNET_CLIENT_connect (const char *service_name, 359GNUNET_CLIENT_connect (const char *service_name,
363 const struct GNUNET_CONFIGURATION_Handle *cfg) 360 const struct GNUNET_CONFIGURATION_Handle *cfg)
364{ 361{
365 struct GNUNET_CLIENT_Connection *ret; 362 struct GNUNET_CLIENT_Connection *ret;
366 struct GNUNET_CONNECTION_Handle *sock; 363 struct GNUNET_CONNECTION_Handle *sock;
@@ -393,33 +390,33 @@ GNUNET_CLIENT_connect (const char *service_name,
393 */ 390 */
394void 391void
395GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *sock, 392GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *sock,
396 int finish_pending_write) 393 int finish_pending_write)
397{ 394{
398 if (sock->in_receive == GNUNET_YES) 395 if (sock->in_receive == GNUNET_YES)
399 { 396 {
400 GNUNET_CONNECTION_receive_cancel (sock->sock); 397 GNUNET_CONNECTION_receive_cancel (sock->sock);
401 sock->in_receive = GNUNET_NO; 398 sock->in_receive = GNUNET_NO;
402 } 399 }
403 if (sock->th != NULL) 400 if (sock->th != NULL)
404 { 401 {
405 GNUNET_CLIENT_notify_transmit_ready_cancel (sock->th); 402 GNUNET_CLIENT_notify_transmit_ready_cancel (sock->th);
406 sock->th = NULL; 403 sock->th = NULL;
407 } 404 }
408 if (NULL != sock->sock) 405 if (NULL != sock->sock)
409 { 406 {
410 GNUNET_CONNECTION_destroy (sock->sock, finish_pending_write); 407 GNUNET_CONNECTION_destroy (sock->sock, finish_pending_write);
411 sock->sock = NULL; 408 sock->sock = NULL;
412 } 409 }
413 if (sock->receive_task != GNUNET_SCHEDULER_NO_TASK) 410 if (sock->receive_task != GNUNET_SCHEDULER_NO_TASK)
414 { 411 {
415 GNUNET_SCHEDULER_cancel (sock->receive_task); 412 GNUNET_SCHEDULER_cancel (sock->receive_task);
416 sock->receive_task = GNUNET_SCHEDULER_NO_TASK; 413 sock->receive_task = GNUNET_SCHEDULER_NO_TASK;
417 } 414 }
418 if (sock->tag != NULL) 415 if (sock->tag != NULL)
419 { 416 {
420 GNUNET_free (sock->tag); 417 GNUNET_free (sock->tag);
421 sock->tag = NULL; 418 sock->tag = NULL;
422 } 419 }
423 sock->receiver_handler = NULL; 420 sock->receiver_handler = NULL;
424 GNUNET_array_grow (sock->received_buf, sock->received_size, 0); 421 GNUNET_array_grow (sock->received_buf, sock->received_size, 0);
425 GNUNET_free (sock->service_name); 422 GNUNET_free (sock->service_name);
@@ -436,7 +433,7 @@ check_complete (struct GNUNET_CLIENT_Connection *conn)
436 if ((conn->received_pos >= sizeof (struct GNUNET_MessageHeader)) && 433 if ((conn->received_pos >= sizeof (struct GNUNET_MessageHeader)) &&
437 (conn->received_pos >= 434 (conn->received_pos >=
438 ntohs (((const struct GNUNET_MessageHeader *) conn->received_buf)-> 435 ntohs (((const struct GNUNET_MessageHeader *) conn->received_buf)->
439 size))) 436 size)))
440 conn->msg_complete = GNUNET_YES; 437 conn->msg_complete = GNUNET_YES;
441} 438}
442 439
@@ -455,7 +452,7 @@ check_complete (struct GNUNET_CLIENT_Connection *conn)
455 */ 452 */
456static void 453static void
457receive_helper (void *cls, const void *buf, size_t available, 454receive_helper (void *cls, const void *buf, size_t available,
458 const struct sockaddr *addr, socklen_t addrlen, int errCode) 455 const struct sockaddr *addr, socklen_t addrlen, int errCode)
459{ 456{
460 struct GNUNET_CLIENT_Connection *conn = cls; 457 struct GNUNET_CLIENT_Connection *conn = cls;
461 struct GNUNET_TIME_Relative remaining; 458 struct GNUNET_TIME_Relative remaining;
@@ -465,22 +462,22 @@ receive_helper (void *cls, const void *buf, size_t available,
465 GNUNET_assert (conn->msg_complete == GNUNET_NO); 462 GNUNET_assert (conn->msg_complete == GNUNET_NO);
466 conn->in_receive = GNUNET_NO; 463 conn->in_receive = GNUNET_NO;
467 if ((available == 0) || (conn->sock == NULL) || (errCode != 0)) 464 if ((available == 0) || (conn->sock == NULL) || (errCode != 0))
468 { 465 {
469 /* signal timeout! */ 466 /* signal timeout! */
470#if DEBUG_CLIENT 467#if DEBUG_CLIENT
471 LOG (GNUNET_ERROR_TYPE_DEBUG, 468 LOG (GNUNET_ERROR_TYPE_DEBUG,
472 "Timeout in receive_helper, available %u, conn->sock %s, errCode `%s'\n", 469 "Timeout in receive_helper, available %u, conn->sock %s, errCode `%s'\n",
473 (unsigned int) available, 470 (unsigned int) available, conn->sock == NULL ? "NULL" : "non-NULL",
474 conn->sock == NULL ? "NULL" : "non-NULL", STRERROR (errCode)); 471 STRERROR (errCode));
475#endif 472#endif
476 if (NULL != (receive_handler = conn->receiver_handler)) 473 if (NULL != (receive_handler = conn->receiver_handler))
477 { 474 {
478 receive_handler_cls = conn->receiver_handler_cls; 475 receive_handler_cls = conn->receiver_handler_cls;
479 conn->receiver_handler = NULL; 476 conn->receiver_handler = NULL;
480 receive_handler (receive_handler_cls, NULL); 477 receive_handler (receive_handler_cls, NULL);
481 }
482 return;
483 } 478 }
479 return;
480 }
484 481
485 /* FIXME: optimize for common fast case where buf contains the 482 /* FIXME: optimize for common fast case where buf contains the
486 * entire message and we need no copying... */ 483 * entire message and we need no copying... */
@@ -489,22 +486,22 @@ receive_helper (void *cls, const void *buf, size_t available,
489 /* slow path: append to array */ 486 /* slow path: append to array */
490 if (conn->received_size < conn->received_pos + available) 487 if (conn->received_size < conn->received_pos + available)
491 GNUNET_array_grow (conn->received_buf, conn->received_size, 488 GNUNET_array_grow (conn->received_buf, conn->received_size,
492 conn->received_pos + available); 489 conn->received_pos + available);
493 memcpy (&conn->received_buf[conn->received_pos], buf, available); 490 memcpy (&conn->received_buf[conn->received_pos], buf, available);
494 conn->received_pos += available; 491 conn->received_pos += available;
495 check_complete (conn); 492 check_complete (conn);
496 /* check for timeout */ 493 /* check for timeout */
497 remaining = GNUNET_TIME_absolute_get_remaining (conn->receive_timeout); 494 remaining = GNUNET_TIME_absolute_get_remaining (conn->receive_timeout);
498 if (remaining.rel_value == 0) 495 if (remaining.rel_value == 0)
499 { 496 {
500 /* signal timeout! */ 497 /* signal timeout! */
501 if (NULL != conn->receiver_handler) 498 if (NULL != conn->receiver_handler)
502 conn->receiver_handler (conn->receiver_handler_cls, NULL); 499 conn->receiver_handler (conn->receiver_handler_cls, NULL);
503 return; 500 return;
504 } 501 }
505 /* back to receive -- either for more data or to call callback! */ 502 /* back to receive -- either for more data or to call callback! */
506 GNUNET_CLIENT_receive (conn, conn->receiver_handler, 503 GNUNET_CLIENT_receive (conn, conn->receiver_handler,
507 conn->receiver_handler_cls, remaining); 504 conn->receiver_handler_cls, remaining);
508} 505}
509 506
510 507
@@ -520,23 +517,22 @@ receive_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
520 struct GNUNET_CLIENT_Connection *sock = cls; 517 struct GNUNET_CLIENT_Connection *sock = cls;
521 GNUNET_CLIENT_MessageHandler handler = sock->receiver_handler; 518 GNUNET_CLIENT_MessageHandler handler = sock->receiver_handler;
522 const struct GNUNET_MessageHeader *cmsg = 519 const struct GNUNET_MessageHeader *cmsg =
523 (const struct GNUNET_MessageHeader *) sock->received_buf; 520 (const struct GNUNET_MessageHeader *) sock->received_buf;
524 void *handler_cls = sock->receiver_handler_cls; 521 void *handler_cls = sock->receiver_handler_cls;
525 uint16_t msize = ntohs (cmsg->size); 522 uint16_t msize = ntohs (cmsg->size);
526 char mbuf[msize]; 523 char mbuf[msize];
527 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) mbuf; 524 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) mbuf;
528 525
529#if DEBUG_CLIENT 526#if DEBUG_CLIENT
530 LOG (GNUNET_ERROR_TYPE_DEBUG, 527 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %u and size %u\n",
531 "Received message of type %u and size %u\n", ntohs (cmsg->type), 528 ntohs (cmsg->type), msize);
532 msize);
533#endif 529#endif
534 sock->receive_task = GNUNET_SCHEDULER_NO_TASK; 530 sock->receive_task = GNUNET_SCHEDULER_NO_TASK;
535 GNUNET_assert (GNUNET_YES == sock->msg_complete); 531 GNUNET_assert (GNUNET_YES == sock->msg_complete);
536 GNUNET_assert (sock->received_pos >= msize); 532 GNUNET_assert (sock->received_pos >= msize);
537 memcpy (msg, cmsg, msize); 533 memcpy (msg, cmsg, msize);
538 memmove (sock->received_buf, &sock->received_buf[msize], 534 memmove (sock->received_buf, &sock->received_buf[msize],
539 sock->received_pos - msize); 535 sock->received_pos - msize);
540 sock->received_pos -= msize; 536 sock->received_pos -= msize;
541 sock->msg_complete = GNUNET_NO; 537 sock->msg_complete = GNUNET_NO;
542 sock->receiver_handler = NULL; 538 sock->receiver_handler = NULL;
@@ -556,36 +552,35 @@ receive_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
556 */ 552 */
557void 553void
558GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *sock, 554GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *sock,
559 GNUNET_CLIENT_MessageHandler handler, 555 GNUNET_CLIENT_MessageHandler handler, void *handler_cls,
560 void *handler_cls, struct GNUNET_TIME_Relative timeout) 556 struct GNUNET_TIME_Relative timeout)
561{ 557{
562 if (sock->sock == NULL) 558 if (sock->sock == NULL)
563 { 559 {
564 /* already disconnected, fail instantly! */ 560 /* already disconnected, fail instantly! */
565 GNUNET_break (0); /* this should not happen in well-written code! */ 561 GNUNET_break (0); /* this should not happen in well-written code! */
566 if (NULL != handler) 562 if (NULL != handler)
567 handler (handler_cls, NULL); 563 handler (handler_cls, NULL);
568 return; 564 return;
569 } 565 }
570 sock->receiver_handler = handler; 566 sock->receiver_handler = handler;
571 sock->receiver_handler_cls = handler_cls; 567 sock->receiver_handler_cls = handler_cls;
572 sock->receive_timeout = GNUNET_TIME_relative_to_absolute (timeout); 568 sock->receive_timeout = GNUNET_TIME_relative_to_absolute (timeout);
573 if (GNUNET_YES == sock->msg_complete) 569 if (GNUNET_YES == sock->msg_complete)
574 { 570 {
575 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->receive_task); 571 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->receive_task);
576 sock->receive_task = GNUNET_SCHEDULER_add_now (&receive_task, sock); 572 sock->receive_task = GNUNET_SCHEDULER_add_now (&receive_task, sock);
577 } 573 }
578 else 574 else
579 { 575 {
580 GNUNET_assert (sock->in_receive == GNUNET_NO); 576 GNUNET_assert (sock->in_receive == GNUNET_NO);
581 sock->in_receive = GNUNET_YES; 577 sock->in_receive = GNUNET_YES;
582#if DEBUG_CLIENT 578#if DEBUG_CLIENT
583 LOG (GNUNET_ERROR_TYPE_DEBUG, "calling GNUNET_CONNECTION_receive\n"); 579 LOG (GNUNET_ERROR_TYPE_DEBUG, "calling GNUNET_CONNECTION_receive\n");
584#endif 580#endif
585 GNUNET_CONNECTION_receive (sock->sock, 581 GNUNET_CONNECTION_receive (sock->sock, GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
586 GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, timeout, 582 timeout, &receive_helper, sock);
587 &receive_helper, sock); 583 }
588 }
589} 584}
590 585
591 586
@@ -596,7 +591,7 @@ static void
596service_test_error (GNUNET_SCHEDULER_Task task, void *task_cls) 591service_test_error (GNUNET_SCHEDULER_Task task, void *task_cls)
597{ 592{
598 GNUNET_SCHEDULER_add_continuation (task, task_cls, 593 GNUNET_SCHEDULER_add_continuation (task, task_cls,
599 GNUNET_SCHEDULER_REASON_TIMEOUT); 594 GNUNET_SCHEDULER_REASON_TIMEOUT);
600} 595}
601 596
602 597
@@ -615,18 +610,18 @@ confirm_handler (void *cls, const struct GNUNET_MessageHeader *msg)
615 * detail in the future, for example, is this the 610 * detail in the future, for example, is this the
616 * correct service? FIXME! */ 611 * correct service? FIXME! */
617 if (msg != NULL) 612 if (msg != NULL)
618 { 613 {
619#if DEBUG_CLIENT 614#if DEBUG_CLIENT
620 LOG (GNUNET_ERROR_TYPE_DEBUG, 615 LOG (GNUNET_ERROR_TYPE_DEBUG,
621 "Received confirmation that service is running.\n"); 616 "Received confirmation that service is running.\n");
622#endif 617#endif
623 GNUNET_SCHEDULER_add_continuation (conn->test_cb, conn->test_cb_cls, 618 GNUNET_SCHEDULER_add_continuation (conn->test_cb, conn->test_cb_cls,
624 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 619 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
625 } 620 }
626 else 621 else
627 { 622 {
628 service_test_error (conn->test_cb, conn->test_cb_cls); 623 service_test_error (conn->test_cb, conn->test_cb_cls);
629 } 624 }
630 GNUNET_CLIENT_disconnect (conn, GNUNET_NO); 625 GNUNET_CLIENT_disconnect (conn, GNUNET_NO);
631} 626}
632 627
@@ -647,14 +642,14 @@ write_test (void *cls, size_t size, void *buf)
647 struct GNUNET_MessageHeader *msg; 642 struct GNUNET_MessageHeader *msg;
648 643
649 if (size < sizeof (struct GNUNET_MessageHeader)) 644 if (size < sizeof (struct GNUNET_MessageHeader))
650 { 645 {
651#if DEBUG_CLIENT 646#if DEBUG_CLIENT
652 LOG (GNUNET_ERROR_TYPE_DEBUG, _("Failure to transmit TEST request.\n")); 647 LOG (GNUNET_ERROR_TYPE_DEBUG, _("Failure to transmit TEST request.\n"));
653#endif 648#endif
654 service_test_error (conn->test_cb, conn->test_cb_cls); 649 service_test_error (conn->test_cb, conn->test_cb_cls);
655 GNUNET_CLIENT_disconnect (conn, GNUNET_NO); 650 GNUNET_CLIENT_disconnect (conn, GNUNET_NO);
656 return 0; /* client disconnected */ 651 return 0; /* client disconnected */
657 } 652 }
658#if DEBUG_CLIENT 653#if DEBUG_CLIENT
659 LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' request.\n", "TEST"); 654 LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' request.\n", "TEST");
660#endif 655#endif
@@ -662,8 +657,8 @@ write_test (void *cls, size_t size, void *buf)
662 msg->type = htons (GNUNET_MESSAGE_TYPE_TEST); 657 msg->type = htons (GNUNET_MESSAGE_TYPE_TEST);
663 msg->size = htons (sizeof (struct GNUNET_MessageHeader)); 658 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
664 GNUNET_CLIENT_receive (conn, &confirm_handler, conn, 659 GNUNET_CLIENT_receive (conn, &confirm_handler, conn,
665 GNUNET_TIME_absolute_get_remaining 660 GNUNET_TIME_absolute_get_remaining
666 (conn->test_deadline)); 661 (conn->test_deadline));
667 return sizeof (struct GNUNET_MessageHeader); 662 return sizeof (struct GNUNET_MessageHeader);
668} 663}
669 664
@@ -683,9 +678,9 @@ write_test (void *cls, size_t size, void *buf)
683 */ 678 */
684void 679void
685GNUNET_CLIENT_service_test (const char *service, 680GNUNET_CLIENT_service_test (const char *service,
686 const struct GNUNET_CONFIGURATION_Handle *cfg, 681 const struct GNUNET_CONFIGURATION_Handle *cfg,
687 struct GNUNET_TIME_Relative timeout, 682 struct GNUNET_TIME_Relative timeout,
688 GNUNET_SCHEDULER_Task task, void *task_cls) 683 GNUNET_SCHEDULER_Task task, void *task_cls)
689{ 684{
690 char *hostname; 685 char *hostname;
691 unsigned long long port; 686 unsigned long long port;
@@ -704,50 +699,49 @@ GNUNET_CLIENT_service_test (const char *service,
704 char *unixpath; 699 char *unixpath;
705 700
706 unixpath = NULL; 701 unixpath = NULL;
707 if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, service, "UNIXPATH", &unixpath)) && (0 < strlen (unixpath))) /* We have a non-NULL unixpath, does that mean it's valid? */ 702 if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, service, "UNIXPATH", &unixpath)) && (0 < strlen (unixpath))) /* We have a non-NULL unixpath, does that mean it's valid? */
703 {
704 if (strlen (unixpath) >= sizeof (s_un.sun_path))
705 {
706 LOG (GNUNET_ERROR_TYPE_WARNING,
707 _("UNIXPATH `%s' too long, maximum length is %llu\n"), unixpath,
708 sizeof (s_un.sun_path));
709 }
710 else
708 { 711 {
709 if (strlen (unixpath) >= sizeof (s_un.sun_path)) 712 sock = GNUNET_NETWORK_socket_create (PF_UNIX, SOCK_STREAM, 0);
710 { 713 if (sock != NULL)
711 LOG (GNUNET_ERROR_TYPE_WARNING, 714 {
712 _("UNIXPATH `%s' too long, maximum length is %llu\n"), 715 memset (&s_un, 0, sizeof (s_un));
713 unixpath, sizeof (s_un.sun_path)); 716 s_un.sun_family = AF_UNIX;
714 } 717 slen = strlen (unixpath) + 1;
715 else 718 if (slen >= sizeof (s_un.sun_path))
716 { 719 slen = sizeof (s_un.sun_path) - 1;
717 sock = GNUNET_NETWORK_socket_create (PF_UNIX, SOCK_STREAM, 0); 720 memcpy (s_un.sun_path, unixpath, slen);
718 if (sock != NULL) 721 s_un.sun_path[slen] = '\0';
719 { 722 slen = sizeof (struct sockaddr_un);
720 memset (&s_un, 0, sizeof (s_un));
721 s_un.sun_family = AF_UNIX;
722 slen = strlen (unixpath) + 1;
723 if (slen >= sizeof (s_un.sun_path))
724 slen = sizeof (s_un.sun_path) - 1;
725 memcpy (s_un.sun_path, unixpath, slen);
726 s_un.sun_path[slen] = '\0';
727 slen = sizeof (struct sockaddr_un);
728#if LINUX 723#if LINUX
729 s_un.sun_path[0] = '\0'; 724 s_un.sun_path[0] = '\0';
730#endif 725#endif
731#if HAVE_SOCKADDR_IN_SIN_LEN 726#if HAVE_SOCKADDR_IN_SIN_LEN
732 s_un.sun_len = (u_char) slen; 727 s_un.sun_len = (u_char) slen;
733#endif 728#endif
734 if (GNUNET_OK != 729 if (GNUNET_OK !=
735 GNUNET_NETWORK_socket_bind (sock, 730 GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_un,
736 (const struct sockaddr *) 731 slen))
737 &s_un, slen)) 732 {
738 { 733 /* failed to bind => service must be running */
739 /* failed to bind => service must be running */ 734 GNUNET_free (unixpath);
740 GNUNET_free (unixpath); 735 (void) GNUNET_NETWORK_socket_close (sock);
741 (void) GNUNET_NETWORK_socket_close (sock); 736 GNUNET_SCHEDULER_add_continuation (task, task_cls,
742 GNUNET_SCHEDULER_add_continuation (task, task_cls, 737 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
743 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 738 return;
744 return; 739 }
745 } 740 (void) GNUNET_NETWORK_socket_close (sock);
746 (void) GNUNET_NETWORK_socket_close (sock); 741 }
747 } 742 /* let's try IP */
748 /* let's try IP */
749 }
750 } 743 }
744 }
751 GNUNET_free_non_null (unixpath); 745 GNUNET_free_non_null (unixpath);
752 } 746 }
753#endif 747#endif
@@ -758,124 +752,121 @@ GNUNET_CLIENT_service_test (const char *service,
758 (port > 65535) || 752 (port > 65535) ||
759 (GNUNET_OK != 753 (GNUNET_OK !=
760 GNUNET_CONFIGURATION_get_value_string (cfg, service, "HOSTNAME", 754 GNUNET_CONFIGURATION_get_value_string (cfg, service, "HOSTNAME",
761 &hostname))) 755 &hostname)))
762 { 756 {
763 /* UNIXPATH failed (if possible) AND IP failed => error */ 757 /* UNIXPATH failed (if possible) AND IP failed => error */
764 service_test_error (task, task_cls); 758 service_test_error (task, task_cls);
765 return; 759 return;
766 } 760 }
767 761
768 if (0 == strcmp ("localhost", hostname) 762 if (0 == strcmp ("localhost", hostname)
769#if !LINUX 763#if !LINUX
770 && 0 764 && 0
771#endif 765#endif
772 ) 766 )
773 { 767 {
774 /* can test using 'bind' */ 768 /* can test using 'bind' */
775 struct sockaddr_in s_in; 769 struct sockaddr_in s_in;
776 770
777 memset (&s_in, 0, sizeof (s_in)); 771 memset (&s_in, 0, sizeof (s_in));
778#if HAVE_SOCKADDR_IN_SIN_LEN 772#if HAVE_SOCKADDR_IN_SIN_LEN
779 s_in.sin_len = sizeof (struct sockaddr_in); 773 s_in.sin_len = sizeof (struct sockaddr_in);
780#endif 774#endif
781 s_in.sin_family = AF_INET; 775 s_in.sin_family = AF_INET;
782 s_in.sin_port = htons (port); 776 s_in.sin_port = htons (port);
783 777
784 sock = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0); 778 sock = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0);
785 if (sock != NULL) 779 if (sock != NULL)
786 { 780 {
787 if (GNUNET_OK != 781 if (GNUNET_OK !=
788 GNUNET_NETWORK_socket_bind (sock, 782 GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_in,
789 (const struct sockaddr *) &s_in, 783 sizeof (s_in)))
790 sizeof (s_in))) 784 {
791 { 785 /* failed to bind => service must be running */
792 /* failed to bind => service must be running */ 786 GNUNET_free (hostname);
793 GNUNET_free (hostname); 787 (void) GNUNET_NETWORK_socket_close (sock);
794 (void) GNUNET_NETWORK_socket_close (sock); 788 GNUNET_SCHEDULER_add_continuation (task, task_cls,
795 GNUNET_SCHEDULER_add_continuation (task, task_cls, 789 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
796 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 790 return;
797 return; 791 }
798 } 792 (void) GNUNET_NETWORK_socket_close (sock);
799 (void) GNUNET_NETWORK_socket_close (sock);
800 }
801 } 793 }
794 }
802 795
803 if (0 == strcmp ("ip6-localhost", hostname) 796 if (0 == strcmp ("ip6-localhost", hostname)
804#if !LINUX 797#if !LINUX
805 && 0 798 && 0
806#endif 799#endif
807 ) 800 )
808 { 801 {
809 /* can test using 'bind' */ 802 /* can test using 'bind' */
810 struct sockaddr_in6 s_in6; 803 struct sockaddr_in6 s_in6;
811 804
812 memset (&s_in6, 0, sizeof (s_in6)); 805 memset (&s_in6, 0, sizeof (s_in6));
813#if HAVE_SOCKADDR_IN_SIN_LEN 806#if HAVE_SOCKADDR_IN_SIN_LEN
814 s_in6.sin6_len = sizeof (struct sockaddr_in6); 807 s_in6.sin6_len = sizeof (struct sockaddr_in6);
815#endif 808#endif
816 s_in6.sin6_family = AF_INET6; 809 s_in6.sin6_family = AF_INET6;
817 s_in6.sin6_port = htons (port); 810 s_in6.sin6_port = htons (port);
818 811
819 sock = GNUNET_NETWORK_socket_create (AF_INET6, SOCK_STREAM, 0); 812 sock = GNUNET_NETWORK_socket_create (AF_INET6, SOCK_STREAM, 0);
820 if (sock != NULL) 813 if (sock != NULL)
821 { 814 {
822 if (GNUNET_OK != 815 if (GNUNET_OK !=
823 GNUNET_NETWORK_socket_bind (sock, 816 GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_in6,
824 (const struct sockaddr *) &s_in6, 817 sizeof (s_in6)))
825 sizeof (s_in6))) 818 {
826 { 819 /* failed to bind => service must be running */
827 /* failed to bind => service must be running */ 820 GNUNET_free (hostname);
828 GNUNET_free (hostname); 821 (void) GNUNET_NETWORK_socket_close (sock);
829 (void) GNUNET_NETWORK_socket_close (sock); 822 GNUNET_SCHEDULER_add_continuation (task, task_cls,
830 GNUNET_SCHEDULER_add_continuation (task, task_cls, 823 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
831 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 824 return;
832 return; 825 }
833 } 826 (void) GNUNET_NETWORK_socket_close (sock);
834 (void) GNUNET_NETWORK_socket_close (sock);
835 }
836 } 827 }
828 }
837 829
838 if (((0 == strcmp ("localhost", hostname)) || 830 if (((0 == strcmp ("localhost", hostname)) ||
839 (0 == strcmp ("ip6-localhost", hostname))) 831 (0 == strcmp ("ip6-localhost", hostname)))
840#if !LINUX 832#if !LINUX
841 && 0 833 && 0
842#endif 834#endif
843 ) 835 )
844 { 836 {
845 /* all binds succeeded => claim service not running right now */ 837 /* all binds succeeded => claim service not running right now */
846 GNUNET_free_non_null (hostname); 838 GNUNET_free_non_null (hostname);
847 service_test_error (task, task_cls); 839 service_test_error (task, task_cls);
848 return; 840 return;
849 } 841 }
850 GNUNET_free_non_null (hostname); 842 GNUNET_free_non_null (hostname);
851 843
852 /* non-localhost, try 'connect' method */ 844 /* non-localhost, try 'connect' method */
853 conn = GNUNET_CLIENT_connect (service, cfg); 845 conn = GNUNET_CLIENT_connect (service, cfg);
854 if (conn == NULL) 846 if (conn == NULL)
855 { 847 {
856 LOG (GNUNET_ERROR_TYPE_INFO, 848 LOG (GNUNET_ERROR_TYPE_INFO,
857 _("Could not connect to service `%s', must not be running.\n"), 849 _("Could not connect to service `%s', must not be running.\n"),
858 service); 850 service);
859 service_test_error (task, task_cls); 851 service_test_error (task, task_cls);
860 return; 852 return;
861 } 853 }
862 conn->test_cb = task; 854 conn->test_cb = task;
863 conn->test_cb_cls = task_cls; 855 conn->test_cb_cls = task_cls;
864 conn->test_deadline = GNUNET_TIME_relative_to_absolute (timeout); 856 conn->test_deadline = GNUNET_TIME_relative_to_absolute (timeout);
865 857
866 if (NULL == 858 if (NULL ==
867 GNUNET_CLIENT_notify_transmit_ready (conn, 859 GNUNET_CLIENT_notify_transmit_ready (conn,
868 sizeof (struct 860 sizeof (struct GNUNET_MessageHeader),
869 GNUNET_MessageHeader), 861 timeout, GNUNET_YES, &write_test,
870 timeout, GNUNET_YES, &write_test, 862 conn))
871 conn)) 863 {
872 { 864 LOG (GNUNET_ERROR_TYPE_WARNING,
873 LOG (GNUNET_ERROR_TYPE_WARNING, 865 _("Failure to transmit request to service `%s'\n"), service);
874 _("Failure to transmit request to service `%s'\n"), service); 866 service_test_error (task, task_cls);
875 service_test_error (task, task_cls); 867 GNUNET_CLIENT_disconnect (conn, GNUNET_NO);
876 GNUNET_CLIENT_disconnect (conn, GNUNET_NO); 868 return;
877 return; 869 }
878 }
879} 870}
880 871
881 872
@@ -889,7 +880,8 @@ GNUNET_CLIENT_service_test (const char *service,
889 * @param buf where to write them 880 * @param buf where to write them
890 * @return number of bytes written to buf 881 * @return number of bytes written to buf
891 */ 882 */
892static size_t client_notify (void *cls, size_t size, void *buf); 883static size_t
884client_notify (void *cls, size_t size, void *buf);
893 885
894 886
895/** 887/**
@@ -900,58 +892,57 @@ static size_t client_notify (void *cls, size_t size, void *buf);
900 * @param tc unused 892 * @param tc unused
901 */ 893 */
902static void 894static void
903client_delayed_retry (void *cls, 895client_delayed_retry (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
904 const struct GNUNET_SCHEDULER_TaskContext *tc)
905{ 896{
906 struct GNUNET_CLIENT_TransmitHandle *th = cls; 897 struct GNUNET_CLIENT_TransmitHandle *th = cls;
907 struct GNUNET_TIME_Relative delay; 898 struct GNUNET_TIME_Relative delay;
908 899
909 th->reconnect_task = GNUNET_SCHEDULER_NO_TASK; 900 th->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
910 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 901 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
911 { 902 {
912#if DEBUG_CLIENT 903#if DEBUG_CLIENT
913 LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmission failed due to shutdown.\n"); 904 LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmission failed due to shutdown.\n");
914#endif 905#endif
915 th->sock->th = NULL; 906 th->sock->th = NULL;
916 th->notify (th->notify_cls, 0, NULL); 907 th->notify (th->notify_cls, 0, NULL);
917 GNUNET_free (th); 908 GNUNET_free (th);
918 return; 909 return;
919 } 910 }
920 th->sock->sock = 911 th->sock->sock =
921 do_connect (th->sock->service_name, th->sock->cfg, th->sock->attempts++); 912 do_connect (th->sock->service_name, th->sock->cfg, th->sock->attempts++);
922 if (NULL == th->sock->sock) 913 if (NULL == th->sock->sock)
923 { 914 {
924 /* could happen if we're out of sockets */ 915 /* could happen if we're out of sockets */
925 delay = 916 delay =
926 GNUNET_TIME_relative_min (GNUNET_TIME_absolute_get_remaining 917 GNUNET_TIME_relative_min (GNUNET_TIME_absolute_get_remaining
927 (th->timeout), th->sock->back_off); 918 (th->timeout), th->sock->back_off);
928 th->sock->back_off = 919 th->sock->back_off =
929 GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply 920 GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply
930 (th->sock->back_off, 2), 921 (th->sock->back_off, 2),
931 GNUNET_TIME_UNIT_SECONDS); 922 GNUNET_TIME_UNIT_SECONDS);
932#if DEBUG_CLIENT 923#if DEBUG_CLIENT
933 LOG (GNUNET_ERROR_TYPE_DEBUG, 924 LOG (GNUNET_ERROR_TYPE_DEBUG,
934 "Transmission failed %u times, trying again in %llums.\n", 925 "Transmission failed %u times, trying again in %llums.\n",
935 MAX_ATTEMPTS - th->attempts_left, 926 MAX_ATTEMPTS - th->attempts_left,
936 (unsigned long long) delay.rel_value); 927 (unsigned long long) delay.rel_value);
937#endif 928#endif
938 th->reconnect_task = 929 th->reconnect_task =
939 GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th); 930 GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th);
940 return; 931 return;
941 } 932 }
942 th->th = 933 th->th =
943 GNUNET_CONNECTION_notify_transmit_ready (th->sock->sock, th->size, 934 GNUNET_CONNECTION_notify_transmit_ready (th->sock->sock, th->size,
944 GNUNET_TIME_absolute_get_remaining 935 GNUNET_TIME_absolute_get_remaining
945 (th->timeout), &client_notify, 936 (th->timeout), &client_notify,
946 th); 937 th);
947 if (th->th == NULL) 938 if (th->th == NULL)
948 { 939 {
949 GNUNET_break (0); 940 GNUNET_break (0);
950 th->sock->th = NULL; 941 th->sock->th = NULL;
951 th->notify (th->notify_cls, 0, NULL); 942 th->notify (th->notify_cls, 0, NULL);
952 GNUNET_free (th); 943 GNUNET_free (th);
953 return; 944 return;
954 } 945 }
955} 946}
956 947
957 948
@@ -974,47 +965,47 @@ client_notify (void *cls, size_t size, void *buf)
974 th->th = NULL; 965 th->th = NULL;
975 th->sock->th = NULL; 966 th->sock->th = NULL;
976 if (buf == NULL) 967 if (buf == NULL)
968 {
969 delay = GNUNET_TIME_absolute_get_remaining (th->timeout);
970 delay.rel_value /= 2;
971 if ((0 !=
972 (GNUNET_SCHEDULER_REASON_SHUTDOWN & GNUNET_SCHEDULER_get_reason ())) ||
973 (GNUNET_YES != th->auto_retry) || (0 == --th->attempts_left) ||
974 (delay.rel_value < 1))
977 { 975 {
978 delay = GNUNET_TIME_absolute_get_remaining (th->timeout);
979 delay.rel_value /= 2;
980 if ((0 !=
981 (GNUNET_SCHEDULER_REASON_SHUTDOWN &
982 GNUNET_SCHEDULER_get_reason ())) || (GNUNET_YES != th->auto_retry)
983 || (0 == --th->attempts_left) || (delay.rel_value < 1))
984 {
985#if DEBUG_CLIENT 976#if DEBUG_CLIENT
986 LOG (GNUNET_ERROR_TYPE_DEBUG, 977 LOG (GNUNET_ERROR_TYPE_DEBUG,
987 "Transmission failed %u times, giving up.\n", 978 "Transmission failed %u times, giving up.\n",
988 MAX_ATTEMPTS - th->attempts_left); 979 MAX_ATTEMPTS - th->attempts_left);
989#endif 980#endif
990 GNUNET_break (0 == th->notify (th->notify_cls, 0, NULL)); 981 GNUNET_break (0 == th->notify (th->notify_cls, 0, NULL));
991 GNUNET_free (th); 982 GNUNET_free (th);
992 return 0; 983 return 0;
993 } 984 }
994 /* auto-retry */ 985 /* auto-retry */
995#if DEBUG_CLIENT 986#if DEBUG_CLIENT
996 LOG (GNUNET_ERROR_TYPE_DEBUG, 987 LOG (GNUNET_ERROR_TYPE_DEBUG,
997 "Failed to connect to `%s', automatically trying again.\n", 988 "Failed to connect to `%s', automatically trying again.\n",
998 th->sock->service_name); 989 th->sock->service_name);
999#endif 990#endif
1000 GNUNET_CONNECTION_destroy (th->sock->sock, GNUNET_NO); 991 GNUNET_CONNECTION_destroy (th->sock->sock, GNUNET_NO);
1001 th->sock->sock = NULL; 992 th->sock->sock = NULL;
1002 delay = GNUNET_TIME_relative_min (delay, th->sock->back_off); 993 delay = GNUNET_TIME_relative_min (delay, th->sock->back_off);
1003 th->sock->back_off = 994 th->sock->back_off =
1004 GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply 995 GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply
1005 (th->sock->back_off, 2), 996 (th->sock->back_off, 2),
1006 GNUNET_TIME_UNIT_SECONDS); 997 GNUNET_TIME_UNIT_SECONDS);
1007#if DEBUG_CLIENT 998#if DEBUG_CLIENT
1008 LOG (GNUNET_ERROR_TYPE_DEBUG, 999 LOG (GNUNET_ERROR_TYPE_DEBUG,
1009 "Transmission failed %u times, trying again in %llums.\n", 1000 "Transmission failed %u times, trying again in %llums.\n",
1010 MAX_ATTEMPTS - th->attempts_left, 1001 MAX_ATTEMPTS - th->attempts_left,
1011 (unsigned long long) delay.rel_value); 1002 (unsigned long long) delay.rel_value);
1012#endif 1003#endif
1013 th->sock->th = th; 1004 th->sock->th = th;
1014 th->reconnect_task = 1005 th->reconnect_task =
1015 GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th); 1006 GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th);
1016 return 0; 1007 return 0;
1017 } 1008 }
1018 GNUNET_assert (size >= th->size); 1009 GNUNET_assert (size >= th->size);
1019 ret = th->notify (th->notify_cls, size, buf); 1010 ret = th->notify (th->notify_cls, size, buf);
1020 GNUNET_free (th); 1011 GNUNET_free (th);
@@ -1043,21 +1034,21 @@ client_notify (void *cls, size_t size, void *buf)
1043 */ 1034 */
1044struct GNUNET_CLIENT_TransmitHandle * 1035struct GNUNET_CLIENT_TransmitHandle *
1045GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *sock, 1036GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *sock,
1046 size_t size, 1037 size_t size,
1047 struct GNUNET_TIME_Relative timeout, 1038 struct GNUNET_TIME_Relative timeout,
1048 int auto_retry, 1039 int auto_retry,
1049 GNUNET_CONNECTION_TransmitReadyNotify 1040 GNUNET_CONNECTION_TransmitReadyNotify
1050 notify, void *notify_cls) 1041 notify, void *notify_cls)
1051{ 1042{
1052 struct GNUNET_CLIENT_TransmitHandle *th; 1043 struct GNUNET_CLIENT_TransmitHandle *th;
1053 1044
1054 if (NULL != sock->th) 1045 if (NULL != sock->th)
1055 { 1046 {
1056 /* If this breaks, you most likley called this function twice without waiting 1047 /* If this breaks, you most likley called this function twice without waiting
1057 * for completion or canceling the request */ 1048 * for completion or canceling the request */
1058 GNUNET_break (0); 1049 GNUNET_break (0);
1059 return NULL; 1050 return NULL;
1060 } 1051 }
1061 th = GNUNET_malloc (sizeof (struct GNUNET_CLIENT_TransmitHandle)); 1052 th = GNUNET_malloc (sizeof (struct GNUNET_CLIENT_TransmitHandle));
1062 th->sock = sock; 1053 th->sock = sock;
1063 th->size = size; 1054 th->size = size;
@@ -1068,25 +1059,25 @@ GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *sock,
1068 th->attempts_left = MAX_ATTEMPTS; 1059 th->attempts_left = MAX_ATTEMPTS;
1069 sock->th = th; 1060 sock->th = th;
1070 if (sock->sock == NULL) 1061 if (sock->sock == NULL)
1071 { 1062 {
1072 th->reconnect_task = 1063 th->reconnect_task =
1073 GNUNET_SCHEDULER_add_delayed (sock->back_off, &client_delayed_retry, 1064 GNUNET_SCHEDULER_add_delayed (sock->back_off, &client_delayed_retry,
1074 th); 1065 th);
1075 1066
1076 } 1067 }
1077 else 1068 else
1069 {
1070 th->th =
1071 GNUNET_CONNECTION_notify_transmit_ready (sock->sock, size, timeout,
1072 &client_notify, th);
1073 if (NULL == th->th)
1078 { 1074 {
1079 th->th = 1075 GNUNET_break (0);
1080 GNUNET_CONNECTION_notify_transmit_ready (sock->sock, size, timeout, 1076 GNUNET_free (th);
1081 &client_notify, th); 1077 sock->th = NULL;
1082 if (NULL == th->th) 1078 return NULL;
1083 {
1084 GNUNET_break (0);
1085 GNUNET_free (th);
1086 sock->th = NULL;
1087 return NULL;
1088 }
1089 } 1079 }
1080 }
1090 return th; 1081 return th;
1091} 1082}
1092 1083
@@ -1097,20 +1088,20 @@ GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *sock,
1097 * @param th handle from the original request. 1088 * @param th handle from the original request.
1098 */ 1089 */
1099void 1090void
1100GNUNET_CLIENT_notify_transmit_ready_cancel (struct 1091GNUNET_CLIENT_notify_transmit_ready_cancel (struct GNUNET_CLIENT_TransmitHandle
1101 GNUNET_CLIENT_TransmitHandle *th) 1092 *th)
1102{ 1093{
1103 if (th->reconnect_task != GNUNET_SCHEDULER_NO_TASK) 1094 if (th->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
1104 { 1095 {
1105 GNUNET_assert (NULL == th->th); 1096 GNUNET_assert (NULL == th->th);
1106 GNUNET_SCHEDULER_cancel (th->reconnect_task); 1097 GNUNET_SCHEDULER_cancel (th->reconnect_task);
1107 th->reconnect_task = GNUNET_SCHEDULER_NO_TASK; 1098 th->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
1108 } 1099 }
1109 else 1100 else
1110 { 1101 {
1111 GNUNET_assert (NULL != th->th); 1102 GNUNET_assert (NULL != th->th);
1112 GNUNET_CONNECTION_notify_transmit_ready_cancel (th->th); 1103 GNUNET_CONNECTION_notify_transmit_ready_cancel (th->th);
1113 } 1104 }
1114 th->sock->th = NULL; 1105 th->sock->th = NULL;
1115 GNUNET_free (th); 1106 GNUNET_free (th);
1116} 1107}
@@ -1136,21 +1127,20 @@ transmit_for_response (void *cls, size_t size, void *buf)
1136 tc->sock->tag = NULL; 1127 tc->sock->tag = NULL;
1137 msize = ntohs (tc->hdr->size); 1128 msize = ntohs (tc->hdr->size);
1138 if (NULL == buf) 1129 if (NULL == buf)
1139 { 1130 {
1140#if DEBUG_CLIENT 1131#if DEBUG_CLIENT
1141 LOG (GNUNET_ERROR_TYPE_DEBUG, 1132 LOG (GNUNET_ERROR_TYPE_DEBUG,
1142 _ 1133 _("Could not submit request, not expecting to receive a response.\n"));
1143 ("Could not submit request, not expecting to receive a response.\n"));
1144#endif 1134#endif
1145 if (NULL != tc->rn) 1135 if (NULL != tc->rn)
1146 tc->rn (tc->rn_cls, NULL); 1136 tc->rn (tc->rn_cls, NULL);
1147 GNUNET_free (tc); 1137 GNUNET_free (tc);
1148 return 0; 1138 return 0;
1149 } 1139 }
1150 GNUNET_assert (size >= msize); 1140 GNUNET_assert (size >= msize);
1151 memcpy (buf, tc->hdr, msize); 1141 memcpy (buf, tc->hdr, msize);
1152 GNUNET_CLIENT_receive (tc->sock, tc->rn, tc->rn_cls, 1142 GNUNET_CLIENT_receive (tc->sock, tc->rn, tc->rn_cls,
1153 GNUNET_TIME_absolute_get_remaining (tc->timeout)); 1143 GNUNET_TIME_absolute_get_remaining (tc->timeout));
1154 GNUNET_free (tc); 1144 GNUNET_free (tc);
1155 return msize; 1145 return msize;
1156} 1146}
@@ -1178,14 +1168,12 @@ transmit_for_response (void *cls, size_t size, void *buf)
1178 * is already pending 1168 * is already pending
1179 */ 1169 */
1180int 1170int
1181GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection 1171GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection *sock,
1182 *sock, 1172 const struct GNUNET_MessageHeader *hdr,
1183 const struct GNUNET_MessageHeader 1173 struct GNUNET_TIME_Relative timeout,
1184 *hdr, 1174 int auto_retry,
1185 struct GNUNET_TIME_Relative timeout, 1175 GNUNET_CLIENT_MessageHandler rn,
1186 int auto_retry, 1176 void *rn_cls)
1187 GNUNET_CLIENT_MessageHandler rn,
1188 void *rn_cls)
1189{ 1177{
1190 struct TransmitGetResponseContext *tc; 1178 struct TransmitGetResponseContext *tc;
1191 uint16_t msize; 1179 uint16_t msize;
@@ -1203,12 +1191,12 @@ GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection
1203 tc->rn_cls = rn_cls; 1191 tc->rn_cls = rn_cls;
1204 if (NULL == 1192 if (NULL ==
1205 GNUNET_CLIENT_notify_transmit_ready (sock, msize, timeout, auto_retry, 1193 GNUNET_CLIENT_notify_transmit_ready (sock, msize, timeout, auto_retry,
1206 &transmit_for_response, tc)) 1194 &transmit_for_response, tc))
1207 { 1195 {
1208 GNUNET_break (0); 1196 GNUNET_break (0);
1209 GNUNET_free (tc); 1197 GNUNET_free (tc);
1210 return GNUNET_SYSERR; 1198 return GNUNET_SYSERR;
1211 } 1199 }
1212 sock->tag = tc; 1200 sock->tag = tc;
1213 return GNUNET_OK; 1201 return GNUNET_OK;
1214} 1202}
diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c
index 31da5829b..340ad5334 100644
--- a/src/util/common_allocation.c
+++ b/src/util/common_allocation.c
@@ -65,10 +65,10 @@ GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber)
65 GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber); 65 GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber);
66 ret = GNUNET_xmalloc_unchecked_ (size, filename, linenumber); 66 ret = GNUNET_xmalloc_unchecked_ (size, filename, linenumber);
67 if (ret == NULL) 67 if (ret == NULL)
68 { 68 {
69 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "malloc"); 69 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "malloc");
70 abort (); 70 abort ();
71 } 71 }
72 return ret; 72 return ret;
73} 73}
74 74
@@ -86,7 +86,7 @@ GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber)
86 */ 86 */
87void * 87void *
88GNUNET_xmemdup_ (const void *buf, size_t size, const char *filename, 88GNUNET_xmemdup_ (const void *buf, size_t size, const char *filename,
89 int linenumber) 89 int linenumber)
90{ 90{
91 void *ret; 91 void *ret;
92 92
@@ -101,10 +101,10 @@ GNUNET_xmemdup_ (const void *buf, size_t size, const char *filename,
101 GNUNET_assert_at (size < INT_MAX, filename, linenumber); 101 GNUNET_assert_at (size < INT_MAX, filename, linenumber);
102 ret = malloc (size); 102 ret = malloc (size);
103 if (ret == NULL) 103 if (ret == NULL)
104 { 104 {
105 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "malloc"); 105 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "malloc");
106 abort (); 106 abort ();
107 } 107 }
108#ifdef W32_MEM_LIMIT 108#ifdef W32_MEM_LIMIT
109 *((size_t *) ret) = size; 109 *((size_t *) ret) = size;
110 ret = &((size_t *) ret)[1]; 110 ret = &((size_t *) ret)[1];
@@ -172,10 +172,10 @@ GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber)
172#endif 172#endif
173 ptr = realloc (ptr, n); 173 ptr = realloc (ptr, n);
174 if ((NULL == ptr) && (n > 0)) 174 if ((NULL == ptr) && (n > 0))
175 { 175 {
176 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "realloc"); 176 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "realloc");
177 abort (); 177 abort ();
178 } 178 }
179#ifdef W32_MEM_LIMIT 179#ifdef W32_MEM_LIMIT
180 ptr = &((size_t *) ptr)[1]; 180 ptr = &((size_t *) ptr)[1];
181#endif 181#endif
@@ -233,7 +233,7 @@ GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber)
233 */ 233 */
234char * 234char *
235GNUNET_xstrndup_ (const char *str, size_t len, const char *filename, 235GNUNET_xstrndup_ (const char *str, size_t len, const char *filename,
236 int linenumber) 236 int linenumber)
237{ 237{
238 char *res; 238 char *res;
239 239
@@ -260,7 +260,7 @@ GNUNET_xstrndup_ (const char *str, size_t len, const char *filename,
260 */ 260 */
261void 261void
262GNUNET_xgrow_ (void **old, size_t elementSize, unsigned int *oldCount, 262GNUNET_xgrow_ (void **old, size_t elementSize, unsigned int *oldCount,
263 unsigned int newCount, const char *filename, int linenumber) 263 unsigned int newCount, const char *filename, int linenumber)
264{ 264{
265 void *tmp; 265 void *tmp;
266 size_t size; 266 size_t size;
@@ -268,22 +268,22 @@ GNUNET_xgrow_ (void **old, size_t elementSize, unsigned int *oldCount,
268 GNUNET_assert_at (INT_MAX / elementSize > newCount, filename, linenumber); 268 GNUNET_assert_at (INT_MAX / elementSize > newCount, filename, linenumber);
269 size = newCount * elementSize; 269 size = newCount * elementSize;
270 if (size == 0) 270 if (size == 0)
271 { 271 {
272 tmp = NULL; 272 tmp = NULL;
273 } 273 }
274 else 274 else
275 { 275 {
276 tmp = GNUNET_xmalloc_ (size, filename, linenumber); 276 tmp = GNUNET_xmalloc_ (size, filename, linenumber);
277 memset (tmp, 0, size); /* client code should not rely on this, though... */ 277 memset (tmp, 0, size); /* client code should not rely on this, though... */
278 if (*oldCount > newCount) 278 if (*oldCount > newCount)
279 *oldCount = newCount; /* shrink is also allowed! */ 279 *oldCount = newCount; /* shrink is also allowed! */
280 memcpy (tmp, *old, elementSize * (*oldCount)); 280 memcpy (tmp, *old, elementSize * (*oldCount));
281 } 281 }
282 282
283 if (*old != NULL) 283 if (*old != NULL)
284 { 284 {
285 GNUNET_xfree_ (*old, filename, linenumber); 285 GNUNET_xfree_ (*old, filename, linenumber);
286 } 286 }
287 *old = tmp; 287 *old = tmp;
288 *oldCount = newCount; 288 *oldCount = newCount;
289} 289}
diff --git a/src/util/common_logging.c b/src/util/common_logging.c
index 1d3843cfd..0b7d06bab 100644
--- a/src/util/common_logging.c
+++ b/src/util/common_logging.c
@@ -276,22 +276,21 @@ resize_logdefs ()
276 */ 276 */
277static void 277static void
278add_definition (char *component, char *file, char *function, int from_line, 278add_definition (char *component, char *file, char *function, int from_line,
279 int to_line, int level, int force) 279 int to_line, int level, int force)
280{ 280{
281 if (logdefs_size == logdefs_len) 281 if (logdefs_size == logdefs_len)
282 resize_logdefs (); 282 resize_logdefs ();
283 struct LogDef n; 283 struct LogDef n;
284
284 memset (&n, 0, sizeof (n)); 285 memset (&n, 0, sizeof (n));
285 if (strlen (component) > 0 && component[0] != '*') 286 if (strlen (component) > 0 && component[0] != '*')
286 n.component = GNUNET_strdup (component); 287 n.component = GNUNET_strdup (component);
287 if (strlen (file) > 0 && file[0] != '*') 288 if (strlen (file) > 0 && file[0] != '*')
288 { 289 {
289 n.file = GNUNET_strdup (file); 290 n.file = GNUNET_strdup (file);
290 n.strlen_file = strlen (file); 291 n.strlen_file = strlen (file);
291 } 292 }
292 if ( (NULL != function) && 293 if ((NULL != function) && (strlen (function) > 0) && (function[0] != '*'))
293 (strlen (function) > 0) &&
294 (function[0] != '*') )
295 n.function = GNUNET_strdup (function); 294 n.function = GNUNET_strdup (function);
296 n.from_line = from_line; 295 n.from_line = from_line;
297 n.to_line = to_line; 296 n.to_line = to_line;
@@ -316,7 +315,7 @@ add_definition (char *component, char *file, char *function, int from_line,
316 */ 315 */
317int 316int
318GNUNET_get_log_call_status (int caller_level, const char *comp, 317GNUNET_get_log_call_status (int caller_level, const char *comp,
319 const char *file, const char *function, int line) 318 const char *file, const char *function, int line)
320{ 319{
321 struct LogDef *ld; 320 struct LogDef *ld;
322 int i; 321 int i;
@@ -337,20 +336,22 @@ GNUNET_get_log_call_status (int caller_level, const char *comp,
337 force_only = min_level >= 0; 336 force_only = min_level >= 0;
338 strlen_file = strlen (file); 337 strlen_file = strlen (file);
339 for (i = 0; i < logdefs_len; i++) 338 for (i = 0; i < logdefs_len; i++)
339 {
340 ld = &logdefs[i];
341 if ((!force_only || ld->force) &&
342 (line >= ld->from_line && line <= ld->to_line) && (ld->component == NULL
343 || strcmp (comp,
344 ld->component)
345 == 0) &&
346 (ld->file == NULL ||
347 (ld->strlen_file <= strlen_file &&
348 strcmp (&file[strlen_file - ld->strlen_file], ld->file) == 0)) &&
349 (ld->function == NULL || strcmp (function, ld->function) == 0))
340 { 350 {
341 ld = &logdefs[i]; 351 /* We're finished */
342 if ((!force_only || ld->force) && 352 return caller_level <= ld->level;
343 (line >= ld->from_line && line <= ld->to_line) &&
344 (ld->component == NULL || strcmp (comp, ld->component) == 0) &&
345 (ld->file == NULL ||
346 (ld->strlen_file <= strlen_file &&
347 strcmp (&file[strlen_file - ld->strlen_file], ld->file) == 0)) &&
348 (ld->function == NULL || strcmp (function, ld->function) == 0))
349 {
350 /* We're finished */
351 return caller_level <= ld->level;
352 }
353 } 353 }
354 }
354 /* No matches - use global level, if defined */ 355 /* No matches - use global level, if defined */
355 if (min_level >= 0) 356 if (min_level >= 0)
356 return caller_level <= min_level; 357 return caller_level <= min_level;
@@ -400,6 +401,7 @@ parse_definitions (const char *constname, int force)
400 int from_line, to_line; 401 int from_line, to_line;
401 int counter = 0; 402 int counter = 0;
402 int keep_looking = 1; 403 int keep_looking = 1;
404
403 tmp = getenv (constname); 405 tmp = getenv (constname);
404 if (tmp == NULL) 406 if (tmp == NULL)
405 return 0; 407 return 0;
@@ -408,85 +410,84 @@ parse_definitions (const char *constname, int force)
408 from_line = 0; 410 from_line = 0;
409 to_line = INT_MAX; 411 to_line = INT_MAX;
410 for (p = def, state = 0, start = def; keep_looking; p++) 412 for (p = def, state = 0, start = def; keep_looking; p++)
413 {
414 switch (p[0])
411 { 415 {
412 switch (p[0]) 416 case ';': /* found a field separator */
413 { 417 p[0] = '\0';
414 case ';': /* found a field separator */ 418 switch (state)
415 p[0] = '\0'; 419 {
416 switch (state) 420 case 0: /* within a component name */
417 { 421 comp = start;
418 case 0: /* within a component name */ 422 break;
419 comp = start; 423 case 1: /* within a file name */
420 break; 424 file = start;
421 case 1: /* within a file name */ 425 break;
422 file = start; 426 case 2: /* within a function name */
423 break; 427 /* after a file name there must be a function name */
424 case 2: /* within a function name */ 428 function = start;
425 /* after a file name there must be a function name */ 429 break;
426 function = start; 430 case 3: /* within a from-to line range */
427 break; 431 if (strlen (start) > 0)
428 case 3: /* within a from-to line range */ 432 {
429 if (strlen (start) > 0) 433 errno = 0;
430 { 434 from_line = strtol (start, &t, 10);
431 errno = 0; 435 if (errno != 0 || from_line < 0)
432 from_line = strtol (start, &t, 10); 436 {
433 if (errno != 0 || from_line < 0) 437 free (def);
434 { 438 return counter;
435 free (def); 439 }
436 return counter; 440 if (t < p && t[0] == '-')
437 } 441 {
438 if (t < p && t[0] == '-') 442 errno = 0;
439 { 443 start = t + 1;
440 errno = 0; 444 to_line = strtol (start, &t, 10);
441 start = t + 1; 445 if (errno != 0 || to_line < 0 || t != p)
442 to_line = strtol (start, &t, 10); 446 {
443 if (errno != 0 || to_line < 0 || t != p) 447 free (def);
444 { 448 return counter;
445 free (def); 449 }
446 return counter; 450 }
447 } 451 else /* one number means "match this line only" */
448 } 452 to_line = from_line;
449 else /* one number means "match this line only" */ 453 }
450 to_line = from_line; 454 else /* default to 0-max */
451 } 455 {
452 else /* default to 0-max */ 456 from_line = 0;
453 { 457 to_line = INT_MAX;
454 from_line = 0; 458 }
455 to_line = INT_MAX; 459 break;
456 } 460 }
457 break; 461 start = p + 1;
458 } 462 state += 1;
459 start = p + 1; 463 break;
460 state += 1; 464 case '\0': /* found EOL */
461 break; 465 keep_looking = 0;
462 case '\0': /* found EOL */ 466 /* fall through to '/' */
463 keep_looking = 0; 467 case '/': /* found a definition separator */
464 /* fall through to '/' */ 468 switch (state)
465 case '/': /* found a definition separator */ 469 {
466 switch (state) 470 case 4: /* within a log level */
467 { 471 p[0] = '\0';
468 case 4: /* within a log level */ 472 state = 0;
469 p[0] = '\0'; 473 level = get_type ((const char *) start);
470 state = 0; 474 if (level == GNUNET_ERROR_TYPE_INVALID ||
471 level = get_type ((const char *) start); 475 level == GNUNET_ERROR_TYPE_UNSPECIFIED)
472 if (level == GNUNET_ERROR_TYPE_INVALID 476 {
473 || level == GNUNET_ERROR_TYPE_UNSPECIFIED) 477 free (def);
474 { 478 return counter;
475 free (def); 479 }
476 return counter; 480 add_definition (comp, file, function, from_line, to_line, level, force);
477 } 481 counter += 1;
478 add_definition (comp, file, function, from_line, to_line, level, 482 start = p + 1;
479 force); 483 break;
480 counter += 1; 484 default:
481 start = p + 1; 485 break;
482 break; 486 }
483 default: 487 default:
484 break; 488 break;
485 }
486 default:
487 break;
488 }
489 } 489 }
490 }
490 free (def); 491 free (def);
491 return counter; 492 return counter;
492} 493}
@@ -502,7 +503,7 @@ parse_all_definitions ()
502 gnunet_log_parsed = GNUNET_YES; 503 gnunet_log_parsed = GNUNET_YES;
503 if (gnunet_force_log_parsed == GNUNET_NO) 504 if (gnunet_force_log_parsed == GNUNET_NO)
504 gnunet_force_log_present = 505 gnunet_force_log_present =
505 parse_definitions ("GNUNET_FORCE_LOG", 1) > 0 ? GNUNET_YES : GNUNET_NO; 506 parse_definitions ("GNUNET_FORCE_LOG", 1) > 0 ? GNUNET_YES : GNUNET_NO;
506 gnunet_force_log_parsed = GNUNET_YES; 507 gnunet_force_log_parsed = GNUNET_YES;
507} 508}
508#endif 509#endif
@@ -546,16 +547,15 @@ GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile)
546 dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)); 547 dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
547 altlog = FOPEN (fn, "a"); 548 altlog = FOPEN (fn, "a");
548 if (altlog == NULL) 549 if (altlog == NULL)
549 { 550 {
550 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn); 551 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn);
551 if (dirwarn) 552 if (dirwarn)
552 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 553 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
553 _ 554 _("Failed to create or access directory for log file `%s'\n"),
554 ("Failed to create or access directory for log file `%s'\n"), 555 fn);
555 fn); 556 GNUNET_free (fn);
556 GNUNET_free (fn); 557 return GNUNET_SYSERR;
557 return GNUNET_SYSERR; 558 }
558 }
559 GNUNET_free (fn); 559 GNUNET_free (fn);
560 if (GNUNET_stderr != NULL) 560 if (GNUNET_stderr != NULL)
561 fclose (GNUNET_stderr); 561 fclose (GNUNET_stderr);
@@ -596,11 +596,11 @@ GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls)
596 prev = NULL; 596 prev = NULL;
597 pos = loggers; 597 pos = loggers;
598 while ((pos != NULL) && 598 while ((pos != NULL) &&
599 ((pos->logger != logger) || (pos->logger_cls != logger_cls))) 599 ((pos->logger != logger) || (pos->logger_cls != logger_cls)))
600 { 600 {
601 prev = pos; 601 prev = pos;
602 pos = pos->next; 602 pos = pos->next;
603 } 603 }
604 GNUNET_assert (pos != NULL); 604 GNUNET_assert (pos != NULL);
605 if (prev == NULL) 605 if (prev == NULL)
606 loggers = pos->next; 606 loggers = pos->next;
@@ -620,22 +620,22 @@ GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls)
620 */ 620 */
621static void 621static void
622output_message (enum GNUNET_ErrorType kind, const char *comp, 622output_message (enum GNUNET_ErrorType kind, const char *comp,
623 const char *datestr, const char *msg) 623 const char *datestr, const char *msg)
624{ 624{
625 struct CustomLogger *pos; 625 struct CustomLogger *pos;
626 626
627 if (GNUNET_stderr != NULL) 627 if (GNUNET_stderr != NULL)
628 { 628 {
629 fprintf (GNUNET_stderr, "%s %s %s %s", datestr, comp, 629 fprintf (GNUNET_stderr, "%s %s %s %s", datestr, comp,
630 GNUNET_error_type_to_string (kind), msg); 630 GNUNET_error_type_to_string (kind), msg);
631 fflush (GNUNET_stderr); 631 fflush (GNUNET_stderr);
632 } 632 }
633 pos = loggers; 633 pos = loggers;
634 while (pos != NULL) 634 while (pos != NULL)
635 { 635 {
636 pos->logger (pos->logger_cls, kind, comp, datestr, msg); 636 pos->logger (pos->logger_cls, kind, comp, datestr, msg);
637 pos = pos->next; 637 pos = pos->next;
638 } 638 }
639} 639}
640 640
641 641
@@ -661,16 +661,15 @@ flush_bulk (const char *datestr)
661 else if (last != last_bulk) 661 else if (last != last_bulk)
662 last--; 662 last--;
663 if (last[0] == '\n') 663 if (last[0] == '\n')
664 { 664 {
665 rev = 1; 665 rev = 1;
666 last[0] = '\0'; 666 last[0] = '\0';
667 } 667 }
668 ft = 668 ft = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration
669 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration 669 (last_bulk_time));
670 (last_bulk_time));
671 snprintf (msg, sizeof (msg), 670 snprintf (msg, sizeof (msg),
672 _("Message `%.*s' repeated %u times in the last %s\n"), 671 _("Message `%.*s' repeated %u times in the last %s\n"),
673 BULK_TRACK_SIZE, last_bulk, last_bulk_repeat, ft); 672 BULK_TRACK_SIZE, last_bulk, last_bulk_repeat, ft);
674 GNUNET_free (ft); 673 GNUNET_free (ft);
675 if (rev == 1) 674 if (rev == 1)
676 last[0] = '\n'; 675 last[0] = '\n';
@@ -690,14 +689,14 @@ void
690GNUNET_log_skip (unsigned int n, int check_reset) 689GNUNET_log_skip (unsigned int n, int check_reset)
691{ 690{
692 if (n == 0) 691 if (n == 0)
693 { 692 {
694 int ok; 693 int ok;
695 694
696 ok = (0 == skip_log); 695 ok = (0 == skip_log);
697 skip_log = 0; 696 skip_log = 0;
698 if (check_reset) 697 if (check_reset)
699 GNUNET_assert (ok); 698 GNUNET_assert (ok);
700 } 699 }
701 else 700 else
702 skip_log += n; 701 skip_log += n;
703} 702}
@@ -736,34 +735,33 @@ mylog (enum GNUNET_ErrorType kind, const char *comp, const char *message,
736 tmptr = localtime (&timetmp); 735 tmptr = localtime (&timetmp);
737 gettimeofday (&timeofday, NULL); 736 gettimeofday (&timeofday, NULL);
738 if (NULL != tmptr) 737 if (NULL != tmptr)
739 { 738 {
740#ifdef WINDOWS 739#ifdef WINDOWS
741 LARGE_INTEGER pc; 740 LARGE_INTEGER pc;
742 741
743 pc.QuadPart = 0; 742 pc.QuadPart = 0;
744 QueryPerformanceCounter (&pc); 743 QueryPerformanceCounter (&pc);
745 strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%020llu", tmptr); 744 strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%020llu", tmptr);
746 snprintf (date, sizeof (date), date2, 745 snprintf (date, sizeof (date), date2,
747 (long long) (pc.QuadPart / 746 (long long) (pc.QuadPart /
748 (performance_frequency.QuadPart / 1000))); 747 (performance_frequency.QuadPart / 1000)));
749#else 748#else
750 strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%06u", tmptr); 749 strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%06u", tmptr);
751 snprintf (date, sizeof (date), date2, timeofday.tv_usec); 750 snprintf (date, sizeof (date), date2, timeofday.tv_usec);
752#endif 751#endif
753 } 752 }
754 else 753 else
755 strcpy (date, "localtime error"); 754 strcpy (date, "localtime error");
756 if ((0 != (kind & GNUNET_ERROR_TYPE_BULK)) 755 if ((0 != (kind & GNUNET_ERROR_TYPE_BULK)) &&
757 && (last_bulk_time.abs_value != 0) 756 (last_bulk_time.abs_value != 0) &&
758 && (0 == strncmp (buf, last_bulk, sizeof (last_bulk)))) 757 (0 == strncmp (buf, last_bulk, sizeof (last_bulk))))
759 { 758 {
760 last_bulk_repeat++; 759 last_bulk_repeat++;
761 if ((GNUNET_TIME_absolute_get_duration (last_bulk_time).rel_value > 760 if ((GNUNET_TIME_absolute_get_duration (last_bulk_time).rel_value >
762 BULK_DELAY_THRESHOLD) 761 BULK_DELAY_THRESHOLD) || (last_bulk_repeat > BULK_REPEAT_THRESHOLD))
763 || (last_bulk_repeat > BULK_REPEAT_THRESHOLD)) 762 flush_bulk (date);
764 flush_bulk (date); 763 return;
765 return; 764 }
766 }
767 flush_bulk (date); 765 flush_bulk (date);
768 strncpy (last_bulk, buf, sizeof (last_bulk)); 766 strncpy (last_bulk, buf, sizeof (last_bulk));
769 last_bulk_repeat = 0; 767 last_bulk_repeat = 0;
@@ -804,7 +802,7 @@ GNUNET_log_nocheck (enum GNUNET_ErrorType kind, const char *message, ...)
804 */ 802 */
805void 803void
806GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, const char *comp, 804GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, const char *comp,
807 const char *message, ...) 805 const char *message, ...)
808{ 806{
809 va_list va; 807 va_list va;
810 char comp_w_pid[128]; 808 char comp_w_pid[128];
@@ -922,44 +920,44 @@ GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen)
922 if (addr == NULL) 920 if (addr == NULL)
923 return _("unknown address"); 921 return _("unknown address");
924 switch (addr->sa_family) 922 switch (addr->sa_family)
925 { 923 {
926 case AF_INET: 924 case AF_INET:
927 if (addrlen != sizeof (struct sockaddr_in)) 925 if (addrlen != sizeof (struct sockaddr_in))
928 return "<invalid v4 address>"; 926 return "<invalid v4 address>";
929 v4 = (const struct sockaddr_in *) addr; 927 v4 = (const struct sockaddr_in *) addr;
930 inet_ntop (AF_INET, &v4->sin_addr, buf, INET_ADDRSTRLEN); 928 inet_ntop (AF_INET, &v4->sin_addr, buf, INET_ADDRSTRLEN);
931 if (0 == ntohs (v4->sin_port)) 929 if (0 == ntohs (v4->sin_port))
932 return buf;
933 strcat (buf, ":");
934 GNUNET_snprintf (b2, sizeof (b2), "%u", ntohs (v4->sin_port));
935 strcat (buf, b2);
936 return buf;
937 case AF_INET6:
938 if (addrlen != sizeof (struct sockaddr_in6))
939 return "<invalid v4 address>";
940 v6 = (const struct sockaddr_in6 *) addr;
941 buf[0] = '[';
942 inet_ntop (AF_INET6, &v6->sin6_addr, &buf[1], INET6_ADDRSTRLEN);
943 if (0 == ntohs (v6->sin6_port))
944 return &buf[1];
945 strcat (buf, "]:");
946 GNUNET_snprintf (b2, sizeof (b2), "%u", ntohs (v6->sin6_port));
947 strcat (buf, b2);
948 return buf;
949 case AF_UNIX:
950 if (addrlen <= sizeof (sa_family_t))
951 return "<unbound UNIX client>";
952 un = (const struct sockaddr_un *) addr;
953 off = 0;
954 if (un->sun_path[0] == '\0')
955 off++;
956 snprintf (buf, sizeof (buf), "%s%.*s", (off == 1) ? "@" : "",
957 (int) (addrlen - sizeof (sa_family_t) - 1 - off),
958 &un->sun_path[off]);
959 return buf; 930 return buf;
960 default: 931 strcat (buf, ":");
961 return _("invalid address"); 932 GNUNET_snprintf (b2, sizeof (b2), "%u", ntohs (v4->sin_port));
962 } 933 strcat (buf, b2);
934 return buf;
935 case AF_INET6:
936 if (addrlen != sizeof (struct sockaddr_in6))
937 return "<invalid v4 address>";
938 v6 = (const struct sockaddr_in6 *) addr;
939 buf[0] = '[';
940 inet_ntop (AF_INET6, &v6->sin6_addr, &buf[1], INET6_ADDRSTRLEN);
941 if (0 == ntohs (v6->sin6_port))
942 return &buf[1];
943 strcat (buf, "]:");
944 GNUNET_snprintf (b2, sizeof (b2), "%u", ntohs (v6->sin6_port));
945 strcat (buf, b2);
946 return buf;
947 case AF_UNIX:
948 if (addrlen <= sizeof (sa_family_t))
949 return "<unbound UNIX client>";
950 un = (const struct sockaddr_un *) addr;
951 off = 0;
952 if (un->sun_path[0] == '\0')
953 off++;
954 snprintf (buf, sizeof (buf), "%s%.*s", (off == 1) ? "@" : "",
955 (int) (addrlen - sizeof (sa_family_t) - 1 - off),
956 &un->sun_path[off]);
957 return buf;
958 default:
959 return _("invalid address");
960 }
963} 961}
964 962
965 963
diff --git a/src/util/configuration.c b/src/util/configuration.c
index 9a131fb50..41a4e1975 100644
--- a/src/util/configuration.c
+++ b/src/util/configuration.c
@@ -150,7 +150,7 @@ GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg)
150 */ 150 */
151int 151int
152GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, 152GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
153 const char *filename) 153 const char *filename)
154{ 154{
155 int dirty; 155 int dirty;
156 char line[256]; 156 char line[256];
@@ -167,89 +167,87 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
167 fn = GNUNET_STRINGS_filename_expand (filename); 167 fn = GNUNET_STRINGS_filename_expand (filename);
168 if (fn == NULL) 168 if (fn == NULL)
169 return GNUNET_SYSERR; 169 return GNUNET_SYSERR;
170 dirty = cfg->dirty; /* back up value! */ 170 dirty = cfg->dirty; /* back up value! */
171 if (NULL == (fp = FOPEN (fn, "r"))) 171 if (NULL == (fp = FOPEN (fn, "r")))
172 { 172 {
173 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fopen", fn); 173 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fopen", fn);
174 GNUNET_free (fn); 174 GNUNET_free (fn);
175 return GNUNET_SYSERR; 175 return GNUNET_SYSERR;
176 } 176 }
177 GNUNET_free (fn); 177 GNUNET_free (fn);
178 ret = GNUNET_OK; 178 ret = GNUNET_OK;
179 section = GNUNET_strdup (""); 179 section = GNUNET_strdup ("");
180 memset (line, 0, 256); 180 memset (line, 0, 256);
181 nr = 0; 181 nr = 0;
182 while (NULL != fgets (line, 255, fp)) 182 while (NULL != fgets (line, 255, fp))
183 {
184 nr++;
185 for (i = 0; i < 255; i++)
186 if (line[i] == '\t')
187 line[i] = ' ';
188 if (line[0] == '\n' || line[0] == '#' || line[0] == '%' || line[0] == '\r')
189 continue;
190 emptyline = 1;
191 for (i = 0; (i < 255 && line[i] != 0); i++)
192 if (line[i] != ' ' && line[i] != '\n' && line[i] != '\r')
193 emptyline = 0;
194 if (emptyline == 1)
195 continue;
196 /* remove tailing whitespace */
197 for (i = strlen (line) - 1; (i >= 0) && (isspace ((unsigned char) line[i]));
198 i--)
199 line[i] = '\0';
200 if (1 == sscanf (line, "@INLINE@ %191[^\n]", value))
183 { 201 {
184 nr++; 202 /* @INLINE@ value */
185 for (i = 0; i < 255; i++) 203 if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, value))
186 if (line[i] == '\t') 204 ret = GNUNET_SYSERR; /* failed to parse included config */
187 line[i] = ' '; 205 }
188 if (line[0] == '\n' || line[0] == '#' || line[0] == '%' 206 else if (1 == sscanf (line, "[%99[^]]]", value))
189 || line[0] == '\r') 207 {
190 continue; 208 /* [value] */
191 emptyline = 1; 209 GNUNET_free (section);
192 for (i = 0; (i < 255 && line[i] != 0); i++) 210 section = GNUNET_strdup (value);
193 if (line[i] != ' ' && line[i] != '\n' && line[i] != '\r') 211 }
194 emptyline = 0; 212 else if (2 == sscanf (line, " %63[^= ] = %191[^\n]", tag, value))
195 if (emptyline == 1) 213 {
196 continue; 214 /* tag = value */
197 /* remove tailing whitespace */ 215 /* Strip LF */
198 for (i = strlen (line) - 1; 216 i = strlen (value) - 1;
199 (i >= 0) && (isspace ((unsigned char) line[i])); i--) 217 while ((i >= 0) && (isspace ((unsigned char) value[i])))
200 line[i] = '\0'; 218 value[i--] = '\0';
201 if (1 == sscanf (line, "@INLINE@ %191[^\n]", value)) 219 /* remove quotes */
202 { 220 i = 0;
203 /* @INLINE@ value */ 221 if (value[0] == '"')
204 if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, value)) 222 {
205 ret = GNUNET_SYSERR; /* failed to parse included config */ 223 i = 1;
206 } 224 while ((value[i] != '\0') && (value[i] != '"'))
207 else if (1 == sscanf (line, "[%99[^]]]", value)) 225 i++;
208 { 226 if (value[i] == '"')
209 /* [value] */ 227 {
210 GNUNET_free (section); 228 value[i] = '\0';
211 section = GNUNET_strdup (value); 229 i = 1;
212 } 230 }
213 else if (2 == sscanf (line, " %63[^= ] = %191[^\n]", tag, value)) 231 else
214 { 232 i = 0;
215 /* tag = value */ 233 }
216 /* Strip LF */ 234 GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, &value[i]);
217 i = strlen (value) - 1; 235 }
218 while ((i >= 0) && (isspace ((unsigned char) value[i]))) 236 else if (1 == sscanf (line, " %63[^= ] =[^\n]", tag))
219 value[i--] = '\0'; 237 {
220 /* remove quotes */ 238 /* tag = */
221 i = 0; 239 GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, "");
222 if (value[0] == '"') 240 }
223 { 241 else
224 i = 1; 242 {
225 while ((value[i] != '\0') && (value[i] != '"')) 243 /* parse error */
226 i++; 244 LOG (GNUNET_ERROR_TYPE_WARNING,
227 if (value[i] == '"') 245 _("Syntax error in configuration file `%s' at line %u.\n"), filename,
228 { 246 nr);
229 value[i] = '\0'; 247 ret = GNUNET_SYSERR;
230 i = 1; 248 break;
231 }
232 else
233 i = 0;
234 }
235 GNUNET_CONFIGURATION_set_value_string (cfg, section, tag,
236 &value[i]);
237 }
238 else if (1 == sscanf (line, " %63[^= ] =[^\n]", tag))
239 {
240 /* tag = */
241 GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, "");
242 }
243 else
244 {
245 /* parse error */
246 LOG (GNUNET_ERROR_TYPE_WARNING,
247 _("Syntax error in configuration file `%s' at line %u.\n"),
248 filename, nr);
249 ret = GNUNET_SYSERR;
250 break;
251 }
252 } 249 }
250 }
253 GNUNET_assert (0 == fclose (fp)); 251 GNUNET_assert (0 == fclose (fp));
254 /* restore dirty flag - anything we set in the meantime 252 /* restore dirty flag - anything we set in the meantime
255 * came from disk */ 253 * came from disk */
@@ -282,7 +280,7 @@ GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg)
282 */ 280 */
283int 281int
284GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, 282GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
285 const char *filename) 283 const char *filename)
286{ 284{
287 struct ConfigSection *sec; 285 struct ConfigSection *sec;
288 struct ConfigEntry *ent; 286 struct ConfigEntry *ent;
@@ -296,67 +294,67 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
296 if (fn == NULL) 294 if (fn == NULL)
297 return GNUNET_SYSERR; 295 return GNUNET_SYSERR;
298 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)) 296 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn))
299 { 297 {
300 GNUNET_free (fn); 298 GNUNET_free (fn);
301 return GNUNET_SYSERR; 299 return GNUNET_SYSERR;
302 } 300 }
303 if (NULL == (fp = FOPEN (fn, "w"))) 301 if (NULL == (fp = FOPEN (fn, "w")))
304 { 302 {
305 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fopen", fn); 303 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fopen", fn);
306 GNUNET_free (fn); 304 GNUNET_free (fn);
307 return GNUNET_SYSERR; 305 return GNUNET_SYSERR;
308 } 306 }
309 GNUNET_free (fn); 307 GNUNET_free (fn);
310 error = 0; 308 error = 0;
311 sec = cfg->sections; 309 sec = cfg->sections;
312 while (sec != NULL) 310 while (sec != NULL)
311 {
312 if (0 > fprintf (fp, "[%s]\n", sec->name))
313 { 313 {
314 if (0 > fprintf (fp, "[%s]\n", sec->name)) 314 error = 1;
315 { 315 break;
316 error = 1;
317 break;
318 }
319 ent = sec->entries;
320 while (ent != NULL)
321 {
322 if (ent->val != NULL)
323 {
324 val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
325 strcpy (val, ent->val);
326 while (NULL != (pos = strstr (val, "\n")))
327 {
328 memmove (&pos[2], &pos[1], strlen (&pos[1]));
329 pos[0] = '\\';
330 pos[1] = 'n';
331 }
332 if (0 > fprintf (fp, "%s = %s\n", ent->key, val))
333 {
334 error = 1;
335 GNUNET_free (val);
336 break;
337 }
338 GNUNET_free (val);
339 }
340 ent = ent->next;
341 }
342 if (error != 0)
343 break;
344 if (0 > fprintf (fp, "\n"))
345 {
346 error = 1;
347 break;
348 }
349 sec = sec->next;
350 } 316 }
317 ent = sec->entries;
318 while (ent != NULL)
319 {
320 if (ent->val != NULL)
321 {
322 val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
323 strcpy (val, ent->val);
324 while (NULL != (pos = strstr (val, "\n")))
325 {
326 memmove (&pos[2], &pos[1], strlen (&pos[1]));
327 pos[0] = '\\';
328 pos[1] = 'n';
329 }
330 if (0 > fprintf (fp, "%s = %s\n", ent->key, val))
331 {
332 error = 1;
333 GNUNET_free (val);
334 break;
335 }
336 GNUNET_free (val);
337 }
338 ent = ent->next;
339 }
340 if (error != 0)
341 break;
342 if (0 > fprintf (fp, "\n"))
343 {
344 error = 1;
345 break;
346 }
347 sec = sec->next;
348 }
351 if (error != 0) 349 if (error != 0)
352 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", filename); 350 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", filename);
353 GNUNET_assert (0 == fclose (fp)); 351 GNUNET_assert (0 == fclose (fp));
354 if (error != 0) 352 if (error != 0)
355 { 353 {
356 cfg->dirty = GNUNET_SYSERR; /* last write failed */ 354 cfg->dirty = GNUNET_SYSERR; /* last write failed */
357 return GNUNET_SYSERR; 355 return GNUNET_SYSERR;
358 } 356 }
359 cfg->dirty = GNUNET_NO; /* last write succeeded */ 357 cfg->dirty = GNUNET_NO; /* last write succeeded */
360 return GNUNET_OK; 358 return GNUNET_OK;
361} 359}
362 360
@@ -370,23 +368,23 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
370 */ 368 */
371void 369void
372GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, 370GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
373 GNUNET_CONFIGURATION_Iterator iter, 371 GNUNET_CONFIGURATION_Iterator iter,
374 void *iter_cls) 372 void *iter_cls)
375{ 373{
376 struct ConfigSection *spos; 374 struct ConfigSection *spos;
377 struct ConfigEntry *epos; 375 struct ConfigEntry *epos;
378 376
379 spos = cfg->sections; 377 spos = cfg->sections;
380 while (spos != NULL) 378 while (spos != NULL)
379 {
380 epos = spos->entries;
381 while (epos != NULL)
381 { 382 {
382 epos = spos->entries; 383 iter (iter_cls, spos->name, epos->key, epos->val);
383 while (epos != NULL) 384 epos = epos->next;
384 {
385 iter (iter_cls, spos->name, epos->key, epos->val);
386 epos = epos->next;
387 }
388 spos = spos->next;
389 } 385 }
386 spos = spos->next;
387 }
390} 388}
391 389
392 390
@@ -400,10 +398,10 @@ GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
400 */ 398 */
401void 399void
402GNUNET_CONFIGURATION_iterate_section_values (const struct 400GNUNET_CONFIGURATION_iterate_section_values (const struct
403 GNUNET_CONFIGURATION_Handle *cfg, 401 GNUNET_CONFIGURATION_Handle *cfg,
404 const char *section, 402 const char *section,
405 GNUNET_CONFIGURATION_Iterator 403 GNUNET_CONFIGURATION_Iterator iter,
406 iter, void *iter_cls) 404 void *iter_cls)
407{ 405{
408 struct ConfigSection *spos; 406 struct ConfigSection *spos;
409 struct ConfigEntry *epos; 407 struct ConfigEntry *epos;
@@ -417,10 +415,10 @@ GNUNET_CONFIGURATION_iterate_section_values (const struct
417 415
418 epos = spos->entries; 416 epos = spos->entries;
419 while (epos != NULL) 417 while (epos != NULL)
420 { 418 {
421 iter (iter_cls, spos->name, epos->key, epos->val); 419 iter (iter_cls, spos->name, epos->key, epos->val);
422 epos = epos->next; 420 epos = epos->next;
423 } 421 }
424} 422}
425 423
426 424
@@ -432,21 +430,21 @@ GNUNET_CONFIGURATION_iterate_section_values (const struct
432 * @param iter_cls closure for iter 430 * @param iter_cls closure for iter
433 */ 431 */
434void 432void
435GNUNET_CONFIGURATION_iterate_sections (const struct 433GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle
436 GNUNET_CONFIGURATION_Handle *cfg, 434 *cfg,
437 GNUNET_CONFIGURATION_Section_Iterator 435 GNUNET_CONFIGURATION_Section_Iterator
438 iter, void *iter_cls) 436 iter, void *iter_cls)
439{ 437{
440 struct ConfigSection *spos; 438 struct ConfigSection *spos;
441 struct ConfigSection *next; 439 struct ConfigSection *next;
442 440
443 next = cfg->sections; 441 next = cfg->sections;
444 while (next != NULL) 442 while (next != NULL)
445 { 443 {
446 spos = next; 444 spos = next;
447 next = spos->next; 445 next = spos->next;
448 iter (iter_cls, spos->name); 446 iter (iter_cls, spos->name);
449 } 447 }
450} 448}
451 449
452/** 450/**
@@ -457,7 +455,7 @@ GNUNET_CONFIGURATION_iterate_sections (const struct
457 */ 455 */
458void 456void
459GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, 457GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
460 const char *section) 458 const char *section)
461{ 459{
462 struct ConfigSection *spos; 460 struct ConfigSection *spos;
463 struct ConfigSection *prev; 461 struct ConfigSection *prev;
@@ -466,28 +464,28 @@ GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
466 prev = NULL; 464 prev = NULL;
467 spos = cfg->sections; 465 spos = cfg->sections;
468 while (spos != NULL) 466 while (spos != NULL)
467 {
468 if (0 == strcmp (section, spos->name))
469 { 469 {
470 if (0 == strcmp (section, spos->name)) 470 if (prev == NULL)
471 { 471 cfg->sections = spos->next;
472 if (prev == NULL) 472 else
473 cfg->sections = spos->next; 473 prev->next = spos->next;
474 else 474 while (NULL != (ent = spos->entries))
475 prev->next = spos->next; 475 {
476 while (NULL != (ent = spos->entries)) 476 spos->entries = ent->next;
477 { 477 GNUNET_free (ent->key);
478 spos->entries = ent->next; 478 GNUNET_free_non_null (ent->val);
479 GNUNET_free (ent->key); 479 GNUNET_free (ent);
480 GNUNET_free_non_null (ent->val); 480 cfg->dirty = GNUNET_YES;
481 GNUNET_free (ent); 481 }
482 cfg->dirty = GNUNET_YES; 482 GNUNET_free (spos->name);
483 } 483 GNUNET_free (spos);
484 GNUNET_free (spos->name); 484 return;
485 GNUNET_free (spos);
486 return;
487 }
488 prev = spos;
489 spos = spos->next;
490 } 485 }
486 prev = spos;
487 spos = spos->next;
488 }
491} 489}
492 490
493 491
@@ -502,7 +500,7 @@ GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
502 */ 500 */
503static void 501static void
504copy_entry (void *cls, const char *section, const char *option, 502copy_entry (void *cls, const char *section, const char *option,
505 const char *value) 503 const char *value)
506{ 504{
507 struct GNUNET_CONFIGURATION_Handle *dst = cls; 505 struct GNUNET_CONFIGURATION_Handle *dst = cls;
508 506
@@ -535,8 +533,7 @@ GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg)
535 * @return matching entry, NULL if not found 533 * @return matching entry, NULL if not found
536 */ 534 */
537static struct ConfigSection * 535static struct ConfigSection *
538findSection (const struct GNUNET_CONFIGURATION_Handle *cfg, 536findSection (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
539 const char *section)
540{ 537{
541 struct ConfigSection *pos; 538 struct ConfigSection *pos;
542 539
@@ -557,7 +554,7 @@ findSection (const struct GNUNET_CONFIGURATION_Handle *cfg,
557 */ 554 */
558static struct ConfigEntry * 555static struct ConfigEntry *
559findEntry (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, 556findEntry (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section,
560 const char *key) 557 const char *key)
561{ 558{
562 struct ConfigSection *sec; 559 struct ConfigSection *sec;
563 struct ConfigEntry *pos; 560 struct ConfigEntry *pos;
@@ -584,7 +581,7 @@ findEntry (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section,
584 */ 581 */
585static void 582static void
586compareEntries (void *cls, const char *section, const char *option, 583compareEntries (void *cls, const char *section, const char *option,
587 const char *value) 584 const char *value)
588{ 585{
589 struct DiffHandle *dh = cls; 586 struct DiffHandle *dh = cls;
590 struct ConfigEntry *entNew; 587 struct ConfigEntry *entNew;
@@ -605,9 +602,9 @@ compareEntries (void *cls, const char *section, const char *option,
605 */ 602 */
606int 603int
607GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle 604GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle
608 *cfgDefault, 605 *cfgDefault,
609 const struct GNUNET_CONFIGURATION_Handle 606 const struct GNUNET_CONFIGURATION_Handle
610 *cfgNew, const char *filename) 607 *cfgNew, const char *filename)
611{ 608{
612 int ret; 609 int ret;
613 struct DiffHandle diffHandle; 610 struct DiffHandle diffHandle;
@@ -630,28 +627,28 @@ GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle
630 * @param value value to set 627 * @param value value to set
631 */ 628 */
632void 629void
633GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle 630GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
634 *cfg, const char *section, 631 const char *section, const char *option,
635 const char *option, const char *value) 632 const char *value)
636{ 633{
637 struct ConfigSection *sec; 634 struct ConfigSection *sec;
638 struct ConfigEntry *e; 635 struct ConfigEntry *e;
639 636
640 e = findEntry (cfg, section, option); 637 e = findEntry (cfg, section, option);
641 if (e != NULL) 638 if (e != NULL)
642 { 639 {
643 GNUNET_free_non_null (e->val); 640 GNUNET_free_non_null (e->val);
644 e->val = GNUNET_strdup (value); 641 e->val = GNUNET_strdup (value);
645 return; 642 return;
646 } 643 }
647 sec = findSection (cfg, section); 644 sec = findSection (cfg, section);
648 if (sec == NULL) 645 if (sec == NULL)
649 { 646 {
650 sec = GNUNET_malloc (sizeof (struct ConfigSection)); 647 sec = GNUNET_malloc (sizeof (struct ConfigSection));
651 sec->name = GNUNET_strdup (section); 648 sec->name = GNUNET_strdup (section);
652 sec->next = cfg->sections; 649 sec->next = cfg->sections;
653 cfg->sections = sec; 650 cfg->sections = sec;
654 } 651 }
655 e = GNUNET_malloc (sizeof (struct ConfigEntry)); 652 e = GNUNET_malloc (sizeof (struct ConfigEntry));
656 e->key = GNUNET_strdup (option); 653 e->key = GNUNET_strdup (option);
657 e->val = GNUNET_strdup (value); 654 e->val = GNUNET_strdup (value);
@@ -669,10 +666,9 @@ GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle
669 * @param number value to set 666 * @param number value to set
670 */ 667 */
671void 668void
672GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle 669GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
673 *cfg, const char *section, 670 const char *section, const char *option,
674 const char *option, 671 unsigned long long number)
675 unsigned long long number)
676{ 672{
677 char s[64]; 673 char s[64];
678 674
@@ -691,11 +687,10 @@ GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle
691 * @return GNUNET_OK on success, GNUNET_SYSERR on error 687 * @return GNUNET_OK on success, GNUNET_SYSERR on error
692 */ 688 */
693int 689int
694GNUNET_CONFIGURATION_get_value_number (const struct 690GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle
695 GNUNET_CONFIGURATION_Handle *cfg, 691 *cfg, const char *section,
696 const char *section, 692 const char *option,
697 const char *option, 693 unsigned long long *number)
698 unsigned long long *number)
699{ 694{
700 struct ConfigEntry *e; 695 struct ConfigEntry *e;
701 696
@@ -719,9 +714,9 @@ GNUNET_CONFIGURATION_get_value_number (const struct
719 */ 714 */
720int 715int
721GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle 716GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle
722 *cfg, const char *section, 717 *cfg, const char *section,
723 const char *option, 718 const char *option,
724 struct GNUNET_TIME_Relative *time) 719 struct GNUNET_TIME_Relative *time)
725{ 720{
726 struct ConfigEntry *e; 721 struct ConfigEntry *e;
727 722
@@ -729,8 +724,7 @@ GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle
729 if (e == NULL) 724 if (e == NULL)
730 return GNUNET_SYSERR; 725 return GNUNET_SYSERR;
731 726
732 return GNUNET_STRINGS_fancy_time_to_relative (e->val, 727 return GNUNET_STRINGS_fancy_time_to_relative (e->val, time);
733 time);
734} 728}
735 729
736 730
@@ -754,8 +748,7 @@ GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle
754 e = findEntry (cfg, section, option); 748 e = findEntry (cfg, section, option);
755 if (e == NULL) 749 if (e == NULL)
756 return GNUNET_SYSERR; 750 return GNUNET_SYSERR;
757 return GNUNET_STRINGS_fancy_size_to_bytes (e->val, 751 return GNUNET_STRINGS_fancy_size_to_bytes (e->val, size);
758 size);
759} 752}
760 753
761 754
@@ -770,19 +763,18 @@ GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle
770 * @return GNUNET_OK on success, GNUNET_SYSERR on error 763 * @return GNUNET_OK on success, GNUNET_SYSERR on error
771 */ 764 */
772int 765int
773GNUNET_CONFIGURATION_get_value_string (const struct 766GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle
774 GNUNET_CONFIGURATION_Handle *cfg, 767 *cfg, const char *section,
775 const char *section, 768 const char *option, char **value)
776 const char *option, char **value)
777{ 769{
778 struct ConfigEntry *e; 770 struct ConfigEntry *e;
779 771
780 e = findEntry (cfg, section, option); 772 e = findEntry (cfg, section, option);
781 if ((e == NULL) || (e->val == NULL)) 773 if ((e == NULL) || (e->val == NULL))
782 { 774 {
783 *value = NULL; 775 *value = NULL;
784 return GNUNET_SYSERR; 776 return GNUNET_SYSERR;
785 } 777 }
786 *value = GNUNET_strdup (e->val); 778 *value = GNUNET_strdup (e->val);
787 return GNUNET_OK; 779 return GNUNET_OK;
788} 780}
@@ -801,12 +793,10 @@ GNUNET_CONFIGURATION_get_value_string (const struct
801 * @return GNUNET_OK on success, GNUNET_SYSERR on error 793 * @return GNUNET_OK on success, GNUNET_SYSERR on error
802 */ 794 */
803int 795int
804GNUNET_CONFIGURATION_get_value_choice (const struct 796GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle
805 GNUNET_CONFIGURATION_Handle *cfg, 797 *cfg, const char *section,
806 const char *section, 798 const char *option, const char **choices,
807 const char *option, 799 const char **value)
808 const char **choices,
809 const char **value)
810{ 800{
811 struct ConfigEntry *e; 801 struct ConfigEntry *e;
812 int i; 802 int i;
@@ -816,19 +806,19 @@ GNUNET_CONFIGURATION_get_value_choice (const struct
816 return GNUNET_SYSERR; 806 return GNUNET_SYSERR;
817 i = 0; 807 i = 0;
818 while (choices[i] != NULL) 808 while (choices[i] != NULL)
819 { 809 {
820 if (0 == strcasecmp (choices[i], e->val)) 810 if (0 == strcasecmp (choices[i], e->val))
821 break; 811 break;
822 i++; 812 i++;
823 } 813 }
824 if (choices[i] == NULL) 814 if (choices[i] == NULL)
825 { 815 {
826 LOG (GNUNET_ERROR_TYPE_ERROR, 816 LOG (GNUNET_ERROR_TYPE_ERROR,
827 _("Configuration value '%s' for '%s'" 817 _("Configuration value '%s' for '%s'"
828 " in section '%s' is not in set of legal choices\n"), e->val, 818 " in section '%s' is not in set of legal choices\n"), e->val, option,
829 option, section); 819 section);
830 return GNUNET_SYSERR; 820 return GNUNET_SYSERR;
831 } 821 }
832 *value = choices[i]; 822 *value = choices[i];
833 return GNUNET_OK; 823 return GNUNET_OK;
834} 824}
@@ -842,9 +832,8 @@ GNUNET_CONFIGURATION_get_value_choice (const struct
842 * @return GNUNET_YES if so, GNUNET_NO if not. 832 * @return GNUNET_YES if so, GNUNET_NO if not.
843 */ 833 */
844int 834int
845GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle 835GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
846 *cfg, const char *section, 836 const char *section, const char *option)
847 const char *option)
848{ 837{
849 struct ConfigEntry *e; 838 struct ConfigEntry *e;
850 839
@@ -865,7 +854,7 @@ GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle
865 */ 854 */
866char * 855char *
867GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle 856GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle
868 *cfg, char *orig) 857 *cfg, char *orig)
869{ 858{
870 int i; 859 int i;
871 char *prefix; 860 char *prefix;
@@ -879,25 +868,24 @@ GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle
879 while ((orig[i] != '/') && (orig[i] != '\\') && (orig[i] != '\0')) 868 while ((orig[i] != '/') && (orig[i] != '\\') && (orig[i] != '\0'))
880 i++; 869 i++;
881 if (orig[i] == '\0') 870 if (orig[i] == '\0')
882 { 871 {
883 post = ""; 872 post = "";
884 } 873 }
885 else 874 else
886 { 875 {
887 orig[i] = '\0'; 876 orig[i] = '\0';
888 post = &orig[i + 1]; 877 post = &orig[i + 1];
889 } 878 }
890 if (GNUNET_OK != 879 if (GNUNET_OK !=
891 GNUNET_CONFIGURATION_get_value_filename (cfg, "PATHS", &orig[1], 880 GNUNET_CONFIGURATION_get_value_filename (cfg, "PATHS", &orig[1], &prefix))
892 &prefix)) 881 {
882 if (NULL == (env = getenv (&orig[1])))
893 { 883 {
894 if (NULL == (env = getenv (&orig[1]))) 884 orig[i] = DIR_SEPARATOR;
895 { 885 return orig;
896 orig[i] = DIR_SEPARATOR;
897 return orig;
898 }
899 prefix = GNUNET_strdup (env);
900 } 886 }
887 prefix = GNUNET_strdup (env);
888 }
901 result = GNUNET_malloc (strlen (prefix) + strlen (post) + 2); 889 result = GNUNET_malloc (strlen (prefix) + strlen (post) + 2);
902 strcpy (result, prefix); 890 strcpy (result, prefix);
903 if ((strlen (prefix) == 0) || 891 if ((strlen (prefix) == 0) ||
@@ -922,18 +910,18 @@ GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle
922 */ 910 */
923int 911int
924GNUNET_CONFIGURATION_get_value_filename (const struct 912GNUNET_CONFIGURATION_get_value_filename (const struct
925 GNUNET_CONFIGURATION_Handle *cfg, 913 GNUNET_CONFIGURATION_Handle *cfg,
926 const char *section, 914 const char *section,
927 const char *option, char **value) 915 const char *option, char **value)
928{ 916{
929 char *tmp; 917 char *tmp;
930 918
931 if (GNUNET_OK != 919 if (GNUNET_OK !=
932 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &tmp)) 920 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &tmp))
933 { 921 {
934 *value = NULL; 922 *value = NULL;
935 return GNUNET_SYSERR; 923 return GNUNET_SYSERR;
936 } 924 }
937 tmp = GNUNET_CONFIGURATION_expand_dollar (cfg, tmp); 925 tmp = GNUNET_CONFIGURATION_expand_dollar (cfg, tmp);
938 *value = GNUNET_STRINGS_filename_expand (tmp); 926 *value = GNUNET_STRINGS_filename_expand (tmp);
939 GNUNET_free (tmp); 927 GNUNET_free (tmp);
@@ -954,15 +942,15 @@ GNUNET_CONFIGURATION_get_value_filename (const struct
954 */ 942 */
955int 943int
956GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle 944GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle
957 *cfg, const char *section, 945 *cfg, const char *section,
958 const char *option) 946 const char *option)
959{ 947{
960 static const char *yesno[] = { "YES", "NO", NULL }; 948 static const char *yesno[] = { "YES", "NO", NULL };
961 const char *val; 949 const char *val;
962 int ret; 950 int ret;
963 951
964 ret = 952 ret =
965 GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val); 953 GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val);
966 if (ret == GNUNET_SYSERR) 954 if (ret == GNUNET_SYSERR)
967 return ret; 955 return ret;
968 if (val == yesno[0]) 956 if (val == yesno[0])
@@ -983,11 +971,11 @@ GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle
983 */ 971 */
984int 972int
985GNUNET_CONFIGURATION_iterate_value_filenames (const struct 973GNUNET_CONFIGURATION_iterate_value_filenames (const struct
986 GNUNET_CONFIGURATION_Handle 974 GNUNET_CONFIGURATION_Handle *cfg,
987 *cfg, const char *section, 975 const char *section,
988 const char *option, 976 const char *option,
989 GNUNET_FileNameCallback cb, 977 GNUNET_FileNameCallback cb,
990 void *cb_cls) 978 void *cb_cls)
991{ 979{
992 char *list; 980 char *list;
993 char *pos; 981 char *pos;
@@ -1002,46 +990,46 @@ GNUNET_CONFIGURATION_iterate_value_filenames (const struct
1002 ret = 0; 990 ret = 0;
1003 pos = list; 991 pos = list;
1004 while (1) 992 while (1)
993 {
994 while (pos[0] == ' ')
995 pos++;
996 if (strlen (pos) == 0)
997 break;
998 end = pos + 1;
999 while ((end[0] != ' ') && (end[0] != '\0'))
1005 { 1000 {
1006 while (pos[0] == ' ') 1001 if (end[0] == '\\')
1007 pos++; 1002 {
1008 if (strlen (pos) == 0) 1003 switch (end[1])
1009 break; 1004 {
1010 end = pos + 1; 1005 case '\\':
1011 while ((end[0] != ' ') && (end[0] != '\0')) 1006 case ' ':
1012 { 1007 memmove (end, &end[1], strlen (&end[1]) + 1);
1013 if (end[0] == '\\') 1008 case '\0':
1014 { 1009 /* illegal, but just keep it */
1015 switch (end[1]) 1010 break;
1016 { 1011 default:
1017 case '\\': 1012 /* illegal, but just ignore that there was a '/' */
1018 case ' ': 1013 break;
1019 memmove (end, &end[1], strlen (&end[1]) + 1); 1014 }
1020 case '\0': 1015 }
1021 /* illegal, but just keep it */ 1016 end++;
1022 break;
1023 default:
1024 /* illegal, but just ignore that there was a '/' */
1025 break;
1026 }
1027 }
1028 end++;
1029 }
1030 old = end[0];
1031 end[0] = '\0';
1032 if (strlen (pos) > 0)
1033 {
1034 ret++;
1035 if ((cb != NULL) && (GNUNET_OK != cb (cb_cls, pos)))
1036 {
1037 ret = GNUNET_SYSERR;
1038 break;
1039 }
1040 }
1041 if (old == '\0')
1042 break;
1043 pos = end + 1;
1044 } 1017 }
1018 old = end[0];
1019 end[0] = '\0';
1020 if (strlen (pos) > 0)
1021 {
1022 ret++;
1023 if ((cb != NULL) && (GNUNET_OK != cb (cb_cls, pos)))
1024 {
1025 ret = GNUNET_SYSERR;
1026 break;
1027 }
1028 }
1029 if (old == '\0')
1030 break;
1031 pos = end + 1;
1032 }
1045 GNUNET_free (list); 1033 GNUNET_free (list);
1046 return ret; 1034 return ret;
1047} 1035}
@@ -1065,21 +1053,21 @@ escape_name (const char *value)
1065 rpos = value; 1053 rpos = value;
1066 wpos = escaped; 1054 wpos = escaped;
1067 while (rpos[0] != '\0') 1055 while (rpos[0] != '\0')
1056 {
1057 switch (rpos[0])
1068 { 1058 {
1069 switch (rpos[0]) 1059 case '\\':
1070 { 1060 case ' ':
1071 case '\\': 1061 wpos[0] = '\\';
1072 case ' ': 1062 wpos[1] = rpos[0];
1073 wpos[0] = '\\'; 1063 wpos += 2;
1074 wpos[1] = rpos[0]; 1064 break;
1075 wpos += 2; 1065 default:
1076 break; 1066 wpos[0] = rpos[0];
1077 default: 1067 wpos++;
1078 wpos[0] = rpos[0];
1079 wpos++;
1080 }
1081 rpos++;
1082 } 1068 }
1069 rpos++;
1070 }
1083 return escaped; 1071 return escaped;
1084} 1072}
1085 1073
@@ -1114,9 +1102,9 @@ test_match (void *cls, const char *fn)
1114 */ 1102 */
1115int 1103int
1116GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle 1104GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle
1117 *cfg, const char *section, 1105 *cfg, const char *section,
1118 const char *option, 1106 const char *option,
1119 const char *value) 1107 const char *value)
1120{ 1108{
1121 char *escaped; 1109 char *escaped;
1122 char *old; 1110 char *old;
@@ -1124,9 +1112,9 @@ GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle
1124 1112
1125 if (GNUNET_SYSERR == 1113 if (GNUNET_SYSERR ==
1126 GNUNET_CONFIGURATION_iterate_value_filenames (cfg, section, option, 1114 GNUNET_CONFIGURATION_iterate_value_filenames (cfg, section, option,
1127 &test_match, 1115 &test_match,
1128 (void *) value)) 1116 (void *) value))
1129 return GNUNET_NO; /* already exists */ 1117 return GNUNET_NO; /* already exists */
1130 if (GNUNET_OK != 1118 if (GNUNET_OK !=
1131 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old)) 1119 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old))
1132 old = GNUNET_strdup (""); 1120 old = GNUNET_strdup ("");
@@ -1158,9 +1146,9 @@ GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle
1158 */ 1146 */
1159int 1147int
1160GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle 1148GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle
1161 *cfg, const char *section, 1149 *cfg, const char *section,
1162 const char *option, 1150 const char *option,
1163 const char *value) 1151 const char *value)
1164{ 1152{
1165 char *list; 1153 char *list;
1166 char *pos; 1154 char *pos;
@@ -1174,55 +1162,55 @@ GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle
1174 match = escape_name (value); 1162 match = escape_name (value);
1175 pos = list; 1163 pos = list;
1176 while (1) 1164 while (1)
1165 {
1166 while (pos[0] == ' ')
1167 pos++;
1168 if (strlen (pos) == 0)
1169 break;
1170 end = pos + 1;
1171 while ((end[0] != ' ') && (end[0] != '\0'))
1172 {
1173 if (end[0] == '\\')
1174 {
1175 switch (end[1])
1176 {
1177 case '\\':
1178 case ' ':
1179 end++;
1180 break;
1181 case '\0':
1182 /* illegal, but just keep it */
1183 break;
1184 default:
1185 /* illegal, but just ignore that there was a '/' */
1186 break;
1187 }
1188 }
1189 end++;
1190 }
1191 old = end[0];
1192 end[0] = '\0';
1193 if (0 == strcmp (pos, match))
1177 { 1194 {
1178 while (pos[0] == ' ') 1195 if (old != '\0')
1179 pos++; 1196 memmove (pos, &end[1], strlen (&end[1]) + 1);
1180 if (strlen (pos) == 0) 1197 else
1181 break; 1198 {
1182 end = pos + 1; 1199 if (pos != list)
1183 while ((end[0] != ' ') && (end[0] != '\0')) 1200 pos[-1] = '\0';
1184 { 1201 else
1185 if (end[0] == '\\') 1202 pos[0] = '\0';
1186 { 1203 }
1187 switch (end[1]) 1204 GNUNET_CONFIGURATION_set_value_string (cfg, section, option, list);
1188 { 1205 GNUNET_free (list);
1189 case '\\': 1206 GNUNET_free (match);
1190 case ' ': 1207 return GNUNET_OK;
1191 end++;
1192 break;
1193 case '\0':
1194 /* illegal, but just keep it */
1195 break;
1196 default:
1197 /* illegal, but just ignore that there was a '/' */
1198 break;
1199 }
1200 }
1201 end++;
1202 }
1203 old = end[0];
1204 end[0] = '\0';
1205 if (0 == strcmp (pos, match))
1206 {
1207 if (old != '\0')
1208 memmove (pos, &end[1], strlen (&end[1]) + 1);
1209 else
1210 {
1211 if (pos != list)
1212 pos[-1] = '\0';
1213 else
1214 pos[0] = '\0';
1215 }
1216 GNUNET_CONFIGURATION_set_value_string (cfg, section, option, list);
1217 GNUNET_free (list);
1218 GNUNET_free (match);
1219 return GNUNET_OK;
1220 }
1221 if (old == '\0')
1222 break;
1223 end[0] = old;
1224 pos = end + 1;
1225 } 1208 }
1209 if (old == '\0')
1210 break;
1211 end[0] = old;
1212 pos = end + 1;
1213 }
1226 GNUNET_free (list); 1214 GNUNET_free (list);
1227 GNUNET_free (match); 1215 GNUNET_free (match);
1228 return GNUNET_NO; 1216 return GNUNET_NO;
@@ -1237,8 +1225,7 @@ GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle
1237 * @return GNUNET_OK on success 1225 * @return GNUNET_OK on success
1238 */ 1226 */
1239static int 1227static int
1240parse_configuration_file (void *cls, 1228parse_configuration_file (void *cls, const char *filename)
1241 const char *filename)
1242{ 1229{
1243 struct GNUNET_CONFIGURATION_Handle *cfg = cls; 1230 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
1244 int ret; 1231 int ret;
@@ -1258,7 +1245,7 @@ parse_configuration_file (void *cls,
1258 */ 1245 */
1259int 1246int
1260GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, 1247GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
1261 const char *filename) 1248 const char *filename)
1262{ 1249{
1263 char *baseconfig; 1250 char *baseconfig;
1264 char *ipath; 1251 char *ipath;
@@ -1267,29 +1254,26 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
1267 if (ipath == NULL) 1254 if (ipath == NULL)
1268 return GNUNET_SYSERR; 1255 return GNUNET_SYSERR;
1269 baseconfig = NULL; 1256 baseconfig = NULL;
1270 GNUNET_asprintf (&baseconfig, "%s%s", ipath, 1257 GNUNET_asprintf (&baseconfig, "%s%s", ipath, "config.d");
1271 "config.d");
1272 GNUNET_free (ipath); 1258 GNUNET_free (ipath);
1273 if (GNUNET_SYSERR == 1259 if (GNUNET_SYSERR ==
1274 GNUNET_DISK_directory_scan (baseconfig, 1260 GNUNET_DISK_directory_scan (baseconfig, &parse_configuration_file, cfg))
1275 &parse_configuration_file,
1276 cfg))
1277 { 1261 {
1278 GNUNET_free (baseconfig); 1262 GNUNET_free (baseconfig);
1279 return GNUNET_SYSERR; /* no configuration at all found */ 1263 return GNUNET_SYSERR; /* no configuration at all found */
1280 } 1264 }
1281 GNUNET_free (baseconfig); 1265 GNUNET_free (baseconfig);
1282 if ( (filename != NULL) && 1266 if ((filename != NULL) &&
1283 (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, filename)) ) 1267 (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, filename)))
1284 { 1268 {
1285 /* specified configuration not found */ 1269 /* specified configuration not found */
1286 return GNUNET_SYSERR; 1270 return GNUNET_SYSERR;
1287 } 1271 }
1288 if (((GNUNET_YES != 1272 if (((GNUNET_YES !=
1289 GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "DEFAULTCONFIG"))) && 1273 GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "DEFAULTCONFIG"))) &&
1290 (filename != NULL)) 1274 (filename != NULL))
1291 GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG", 1275 GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG",
1292 filename); 1276 filename);
1293 if ((GNUNET_YES == 1277 if ((GNUNET_YES ==
1294 GNUNET_CONFIGURATION_have_value (cfg, "TESTING", "WEAKRANDOM")) && 1278 GNUNET_CONFIGURATION_have_value (cfg, "TESTING", "WEAKRANDOM")) &&
1295 (GNUNET_YES == 1279 (GNUNET_YES ==
diff --git a/src/util/connection.c b/src/util/connection.c
index cd0035a8f..61c26673b 100644
--- a/src/util/connection.c
+++ b/src/util/connection.c
@@ -333,8 +333,7 @@ GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *sock)
333 * @return the boxed socket handle 333 * @return the boxed socket handle
334 */ 334 */
335struct GNUNET_CONNECTION_Handle * 335struct GNUNET_CONNECTION_Handle *
336GNUNET_CONNECTION_create_from_existing (struct GNUNET_NETWORK_Handle 336GNUNET_CONNECTION_create_from_existing (struct GNUNET_NETWORK_Handle *osSocket)
337 *osSocket)
338{ 337{
339 struct GNUNET_CONNECTION_Handle *ret; 338 struct GNUNET_CONNECTION_Handle *ret;
340 339
@@ -357,8 +356,8 @@ GNUNET_CONNECTION_create_from_existing (struct GNUNET_NETWORK_Handle
357 */ 356 */
358struct GNUNET_CONNECTION_Handle * 357struct GNUNET_CONNECTION_Handle *
359GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access, 358GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access,
360 void *access_cls, 359 void *access_cls,
361 struct GNUNET_NETWORK_Handle *lsock) 360 struct GNUNET_NETWORK_Handle *lsock)
362{ 361{
363 struct GNUNET_CONNECTION_Handle *ret; 362 struct GNUNET_CONNECTION_Handle *ret;
364 char addr[128]; 363 char addr[128];
@@ -379,94 +378,94 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access,
379 378
380 addrlen = sizeof (addr); 379 addrlen = sizeof (addr);
381 sock = 380 sock =
382 GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen); 381 GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen);
383 if (NULL == sock) 382 if (NULL == sock)
384 { 383 {
385 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "accept"); 384 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "accept");
386 return NULL; 385 return NULL;
387 } 386 }
388 if ((addrlen > sizeof (addr)) || (addrlen < sizeof (sa_family_t))) 387 if ((addrlen > sizeof (addr)) || (addrlen < sizeof (sa_family_t)))
389 { 388 {
390 GNUNET_break (0); 389 GNUNET_break (0);
391 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); 390 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
392 return NULL; 391 return NULL;
393 } 392 }
394 393
395 sa = (struct sockaddr *) addr; 394 sa = (struct sockaddr *) addr;
396 v6 = (struct sockaddr_in6 *) addr; 395 v6 = (struct sockaddr_in6 *) addr;
397 if ((sa->sa_family == AF_INET6) && (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr))) 396 if ((sa->sa_family == AF_INET6) && (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr)))
398 { 397 {
399 /* convert to V4 address */ 398 /* convert to V4 address */
400 v4 = GNUNET_malloc (sizeof (struct sockaddr_in)); 399 v4 = GNUNET_malloc (sizeof (struct sockaddr_in));
401 memset (v4, 0, sizeof (struct sockaddr_in)); 400 memset (v4, 0, sizeof (struct sockaddr_in));
402 v4->sin_family = AF_INET; 401 v4->sin_family = AF_INET;
403#if HAVE_SOCKADDR_IN_SIN_LEN 402#if HAVE_SOCKADDR_IN_SIN_LEN
404 v4->sin_len = (u_char) sizeof (struct sockaddr_in); 403 v4->sin_len = (u_char) sizeof (struct sockaddr_in);
405#endif 404#endif
406 memcpy (&v4->sin_addr, 405 memcpy (&v4->sin_addr,
407 &((char *) &v6->sin6_addr)[sizeof (struct in6_addr) - 406 &((char *) &v6->sin6_addr)[sizeof (struct in6_addr) -
408 sizeof (struct in_addr)], 407 sizeof (struct in_addr)],
409 sizeof (struct in_addr)); 408 sizeof (struct in_addr));
410 v4->sin_port = v6->sin6_port; 409 v4->sin_port = v6->sin6_port;
411 uaddr = v4; 410 uaddr = v4;
412 addrlen = sizeof (struct sockaddr_in); 411 addrlen = sizeof (struct sockaddr_in);
413 } 412 }
414 else 413 else
415 { 414 {
416 uaddr = GNUNET_malloc (addrlen); 415 uaddr = GNUNET_malloc (addrlen);
417 memcpy (uaddr, addr, addrlen); 416 memcpy (uaddr, addr, addrlen);
418 } 417 }
419 gcp = NULL; 418 gcp = NULL;
420 gc.uid = 0; 419 gc.uid = 0;
421 gc.gid = 0; 420 gc.gid = 0;
422 if (sa->sa_family == AF_UNIX) 421 if (sa->sa_family == AF_UNIX)
423 { 422 {
424#if HAVE_GETPEEREID 423#if HAVE_GETPEEREID
425 /* most BSDs */ 424 /* most BSDs */
426 if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), &gc.uid, &gc.gid)) 425 if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), &gc.uid, &gc.gid))
427 gcp = &gc; 426 gcp = &gc;
428#else 427#else
429#ifdef SO_PEERCRED 428#ifdef SO_PEERCRED
430 /* largely traditional GNU/Linux */ 429 /* largely traditional GNU/Linux */
431 olen = sizeof (uc); 430 olen = sizeof (uc);
432 if ((0 == 431 if ((0 ==
433 getsockopt (GNUNET_NETWORK_get_fd (sock), SOL_SOCKET, SO_PEERCRED, 432 getsockopt (GNUNET_NETWORK_get_fd (sock), SOL_SOCKET, SO_PEERCRED, &uc,
434 &uc, &olen)) && (olen == sizeof (uc))) 433 &olen)) && (olen == sizeof (uc)))
435 { 434 {
436 gc.uid = uc.uid; 435 gc.uid = uc.uid;
437 gc.gid = uc.gid; 436 gc.gid = uc.gid;
438 gcp = &gc; 437 gcp = &gc;
439 } 438 }
440#else 439#else
441#if HAVE_GETPEERUCRED 440#if HAVE_GETPEERUCRED
442 /* this is for Solaris 10 */ 441 /* this is for Solaris 10 */
443 ucred_t *uc; 442 ucred_t *uc;
444 443
445 uc = NULL; 444 uc = NULL;
446 if (0 == getpeerucred (GNUNET_NETWORK_get_fd (sock), &uc)) 445 if (0 == getpeerucred (GNUNET_NETWORK_get_fd (sock), &uc))
447 { 446 {
448 gc.uid = ucred_geteuid (uc); 447 gc.uid = ucred_geteuid (uc);
449 gc.gid = ucred_getegid (uc); 448 gc.gid = ucred_getegid (uc);
450 gcp = &gc; 449 gcp = &gc;
451 } 450 }
452 ucred_free (uc); 451 ucred_free (uc);
453#endif 452#endif
454#endif 453#endif
455#endif 454#endif
456 } 455 }
457 456
458 if ((access != NULL) && 457 if ((access != NULL) &&
459 (GNUNET_YES != (aret = access (access_cls, gcp, uaddr, addrlen)))) 458 (GNUNET_YES != (aret = access (access_cls, gcp, uaddr, addrlen))))
460 { 459 {
461 if (aret == GNUNET_NO) 460 if (aret == GNUNET_NO)
462 LOG (GNUNET_ERROR_TYPE_INFO, _("Access denied to `%s'\n"), 461 LOG (GNUNET_ERROR_TYPE_INFO, _("Access denied to `%s'\n"),
463 GNUNET_a2s (uaddr, addrlen)); 462 GNUNET_a2s (uaddr, addrlen));
464 GNUNET_break (GNUNET_OK == 463 GNUNET_break (GNUNET_OK ==
465 GNUNET_NETWORK_socket_shutdown (sock, SHUT_RDWR)); 464 GNUNET_NETWORK_socket_shutdown (sock, SHUT_RDWR));
466 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); 465 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
467 GNUNET_free (uaddr); 466 GNUNET_free (uaddr);
468 return NULL; 467 return NULL;
469 } 468 }
470 ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle)); 469 ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle));
471 ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE; 470 ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE;
472 ret->write_buffer = GNUNET_malloc (ret->write_buffer_size); 471 ret->write_buffer = GNUNET_malloc (ret->write_buffer_size);
@@ -490,7 +489,7 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access,
490 */ 489 */
491int 490int
492GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *sock, 491GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *sock,
493 void **addr, size_t * addrlen) 492 void **addr, size_t * addrlen)
494{ 493{
495 if ((sock->addr == NULL) || (sock->addrlen == 0)) 494 if ((sock->addr == NULL) || (sock->addrlen == 0))
496 return GNUNET_NO; 495 return GNUNET_NO;
@@ -523,8 +522,7 @@ receive_again (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
523 * @param tc unused 522 * @param tc unused
524 */ 523 */
525static void 524static void
526destroy_continuation (void *cls, 525destroy_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
527 const struct GNUNET_SCHEDULER_TaskContext *tc)
528{ 526{
529 struct GNUNET_CONNECTION_Handle *sock = cls; 527 struct GNUNET_CONNECTION_Handle *sock = cls;
530 GNUNET_CONNECTION_TransmitReadyNotify notify; 528 GNUNET_CONNECTION_TransmitReadyNotify notify;
@@ -533,78 +531,77 @@ destroy_continuation (void *cls,
533 sock->destroy_task = GNUNET_SCHEDULER_NO_TASK; 531 sock->destroy_task = GNUNET_SCHEDULER_NO_TASK;
534 GNUNET_assert (sock->dns_active == NULL); 532 GNUNET_assert (sock->dns_active == NULL);
535 if (0 != (sock->ccs & COCO_TRANSMIT_READY)) 533 if (0 != (sock->ccs & COCO_TRANSMIT_READY))
536 { 534 {
537#if DEBUG_CONNECTION 535#if DEBUG_CONNECTION
538 LOG (GNUNET_ERROR_TYPE_DEBUG, 536 LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroy waits for CCS-TR to be done (%p)\n",
539 "Destroy waits for CCS-TR to be done (%p)\n", sock); 537 sock);
540#endif 538#endif
541 sock->ccs |= COCO_DESTROY_CONTINUATION; 539 sock->ccs |= COCO_DESTROY_CONTINUATION;
542 return; 540 return;
543 } 541 }
544 if (sock->write_task != GNUNET_SCHEDULER_NO_TASK) 542 if (sock->write_task != GNUNET_SCHEDULER_NO_TASK)
545 { 543 {
546#if DEBUG_CONNECTION 544#if DEBUG_CONNECTION
547 LOG (GNUNET_ERROR_TYPE_DEBUG, 545 LOG (GNUNET_ERROR_TYPE_DEBUG,
548 "Destroy waits for write_task to be done (%p)\n", sock); 546 "Destroy waits for write_task to be done (%p)\n", sock);
549#endif 547#endif
550 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); 548 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task);
551 sock->destroy_task = 549 sock->destroy_task =
552 GNUNET_SCHEDULER_add_after (sock->write_task, &destroy_continuation, 550 GNUNET_SCHEDULER_add_after (sock->write_task, &destroy_continuation,
553 sock); 551 sock);
554 return; 552 return;
555 } 553 }
556 if (0 != (sock->ccs & COCO_RECEIVE_AGAIN)) 554 if (0 != (sock->ccs & COCO_RECEIVE_AGAIN))
557 { 555 {
558 sock->ccs |= COCO_DESTROY_CONTINUATION; 556 sock->ccs |= COCO_DESTROY_CONTINUATION;
559 return; 557 return;
560 } 558 }
561 if (sock->sock != NULL) 559 if (sock->sock != NULL)
562 { 560 {
563#if DEBUG_CONNECTION 561#if DEBUG_CONNECTION
564 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down socket (%p)\n", sock); 562 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down socket (%p)\n", sock);
565#endif 563#endif
566 if (sock->persist != GNUNET_YES) 564 if (sock->persist != GNUNET_YES)
567 {
568 if ((GNUNET_YES !=
569 GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR))
570 && (errno != ENOTCONN) && (errno != ECONNRESET))
571 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "shutdown");
572 }
573 }
574 if (sock->read_task != GNUNET_SCHEDULER_NO_TASK)
575 { 565 {
576 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); 566 if ((GNUNET_YES != GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR))
577 sock->destroy_task = 567 && (errno != ENOTCONN) && (errno != ECONNRESET))
578 GNUNET_SCHEDULER_add_after (sock->read_task, &destroy_continuation, 568 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "shutdown");
579 sock);
580 return;
581 } 569 }
570 }
571 if (sock->read_task != GNUNET_SCHEDULER_NO_TASK)
572 {
573 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task);
574 sock->destroy_task =
575 GNUNET_SCHEDULER_add_after (sock->read_task, &destroy_continuation,
576 sock);
577 return;
578 }
582#if DEBUG_CONNECTION 579#if DEBUG_CONNECTION
583 LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroy actually runs (%p)!\n", sock); 580 LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroy actually runs (%p)!\n", sock);
584#endif 581#endif
585 while (NULL != (pos = sock->ap_head)) 582 while (NULL != (pos = sock->ap_head))
586 { 583 {
587 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); 584 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock));
588 GNUNET_SCHEDULER_cancel (pos->task); 585 GNUNET_SCHEDULER_cancel (pos->task);
589 GNUNET_CONTAINER_DLL_remove (sock->ap_head, sock->ap_tail, pos); 586 GNUNET_CONTAINER_DLL_remove (sock->ap_head, sock->ap_tail, pos);
590 GNUNET_free (pos); 587 GNUNET_free (pos);
591 } 588 }
592 GNUNET_assert (sock->nth.timeout_task == GNUNET_SCHEDULER_NO_TASK); 589 GNUNET_assert (sock->nth.timeout_task == GNUNET_SCHEDULER_NO_TASK);
593 GNUNET_assert (sock->ccs == COCO_NONE); 590 GNUNET_assert (sock->ccs == COCO_NONE);
594 if (NULL != (notify = sock->nth.notify_ready)) 591 if (NULL != (notify = sock->nth.notify_ready))
595 { 592 {
596 sock->nth.notify_ready = NULL; 593 sock->nth.notify_ready = NULL;
597 notify (sock->nth.notify_ready_cls, 0, NULL); 594 notify (sock->nth.notify_ready_cls, 0, NULL);
598 } 595 }
599 596
600 if (sock->sock != NULL) 597 if (sock->sock != NULL)
601 { 598 {
602 if (sock->persist != GNUNET_YES) 599 if (sock->persist != GNUNET_YES)
603 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock)); 600 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock));
604 else 601 else
605 GNUNET_free (sock->sock); /* at least no memory leak (we deliberately 602 GNUNET_free (sock->sock); /* at least no memory leak (we deliberately
606 * leak the socket in this special case) ... */ 603 * leak the socket in this special case) ... */
607 } 604 }
608 GNUNET_free_non_null (sock->addr); 605 GNUNET_free_non_null (sock->addr);
609 GNUNET_free_non_null (sock->hostname); 606 GNUNET_free_non_null (sock->hostname);
610 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); 607 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task);
@@ -639,9 +636,8 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *h)
639{ 636{
640#if DEBUG_CONNECTION 637#if DEBUG_CONNECTION
641 LOG ((0 != 638 LOG ((0 !=
642 strncmp (h->hostname, "localhost:", 639 strncmp (h->hostname, "localhost:",
643 10)) ? GNUNET_ERROR_TYPE_INFO : 640 10)) ? GNUNET_ERROR_TYPE_INFO : GNUNET_ERROR_TYPE_WARNING,
644 GNUNET_ERROR_TYPE_WARNING,
645 _ 641 _
646 ("Failed to establish TCP connection to `%s:%u', no further addresses to try.\n"), 642 ("Failed to establish TCP connection to `%s:%u', no further addresses to try.\n"),
647 h->hostname, h->port); 643 h->hostname, h->port);
@@ -654,39 +650,39 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *h)
654 650
655 /* trigger jobs that used to wait on "connect_task" */ 651 /* trigger jobs that used to wait on "connect_task" */
656 if (0 != (h->ccs & COCO_RECEIVE_AGAIN)) 652 if (0 != (h->ccs & COCO_RECEIVE_AGAIN))
657 { 653 {
658#if DEBUG_CONNECTION 654#if DEBUG_CONNECTION
659 LOG (GNUNET_ERROR_TYPE_DEBUG, 655 LOG (GNUNET_ERROR_TYPE_DEBUG,
660 "connect_fail_continuation triggers receive_again (%p)\n", h); 656 "connect_fail_continuation triggers receive_again (%p)\n", h);
661#endif 657#endif
662 h->ccs -= COCO_RECEIVE_AGAIN; 658 h->ccs -= COCO_RECEIVE_AGAIN;
663 h->read_task = GNUNET_SCHEDULER_add_now (&receive_again, h); 659 h->read_task = GNUNET_SCHEDULER_add_now (&receive_again, h);
664 } 660 }
665 if (0 != (h->ccs & COCO_TRANSMIT_READY)) 661 if (0 != (h->ccs & COCO_TRANSMIT_READY))
666 { 662 {
667#if DEBUG_CONNECTION 663#if DEBUG_CONNECTION
668 LOG (GNUNET_ERROR_TYPE_DEBUG, 664 LOG (GNUNET_ERROR_TYPE_DEBUG,
669 "connect_fail_continuation cancels timeout_task, triggers transmit_ready (%p)\n", 665 "connect_fail_continuation cancels timeout_task, triggers transmit_ready (%p)\n",
670 h); 666 h);
671#endif 667#endif
672 GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK); 668 GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK);
673 GNUNET_SCHEDULER_cancel (h->nth.timeout_task); 669 GNUNET_SCHEDULER_cancel (h->nth.timeout_task);
674 h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; 670 h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK;
675 h->ccs -= COCO_TRANSMIT_READY; 671 h->ccs -= COCO_TRANSMIT_READY;
676 GNUNET_assert (h->nth.notify_ready != NULL); 672 GNUNET_assert (h->nth.notify_ready != NULL);
677 GNUNET_assert (h->write_task == GNUNET_SCHEDULER_NO_TASK); 673 GNUNET_assert (h->write_task == GNUNET_SCHEDULER_NO_TASK);
678 h->write_task = GNUNET_SCHEDULER_add_now (&transmit_ready, h); 674 h->write_task = GNUNET_SCHEDULER_add_now (&transmit_ready, h);
679 } 675 }
680 if (0 != (h->ccs & COCO_DESTROY_CONTINUATION)) 676 if (0 != (h->ccs & COCO_DESTROY_CONTINUATION))
681 { 677 {
682#if DEBUG_CONNECTION 678#if DEBUG_CONNECTION
683 LOG (GNUNET_ERROR_TYPE_DEBUG, 679 LOG (GNUNET_ERROR_TYPE_DEBUG,
684 "connect_fail_continuation runs destroy_continuation (%p)\n", h); 680 "connect_fail_continuation runs destroy_continuation (%p)\n", h);
685#endif 681#endif
686 h->ccs -= COCO_DESTROY_CONTINUATION; 682 h->ccs -= COCO_DESTROY_CONTINUATION;
687 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->destroy_task); 683 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->destroy_task);
688 h->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, h); 684 h->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, h);
689 } 685 }
690} 686}
691 687
692 688
@@ -704,43 +700,42 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *h)
704#endif 700#endif
705 /* trigger jobs that waited for the connection */ 701 /* trigger jobs that waited for the connection */
706 if (0 != (h->ccs & COCO_RECEIVE_AGAIN)) 702 if (0 != (h->ccs & COCO_RECEIVE_AGAIN))
707 { 703 {
708#if DEBUG_CONNECTION 704#if DEBUG_CONNECTION
709 LOG (GNUNET_ERROR_TYPE_DEBUG, 705 LOG (GNUNET_ERROR_TYPE_DEBUG,
710 "connect_success_continuation runs receive_again (%p)\n", h); 706 "connect_success_continuation runs receive_again (%p)\n", h);
711#endif 707#endif
712 h->ccs -= COCO_RECEIVE_AGAIN; 708 h->ccs -= COCO_RECEIVE_AGAIN;
713 h->read_task = GNUNET_SCHEDULER_add_now (&receive_again, h); 709 h->read_task = GNUNET_SCHEDULER_add_now (&receive_again, h);
714 } 710 }
715 if (0 != (h->ccs & COCO_TRANSMIT_READY)) 711 if (0 != (h->ccs & COCO_TRANSMIT_READY))
716 { 712 {
717#if DEBUG_CONNECTION 713#if DEBUG_CONNECTION
718 LOG (GNUNET_ERROR_TYPE_DEBUG, 714 LOG (GNUNET_ERROR_TYPE_DEBUG,
719 "connect_success_continuation runs transmit_ready, cancels timeout_task (%p)\n", 715 "connect_success_continuation runs transmit_ready, cancels timeout_task (%p)\n",
720 h); 716 h);
721#endif 717#endif
722 GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK); 718 GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK);
723 GNUNET_SCHEDULER_cancel (h->nth.timeout_task); 719 GNUNET_SCHEDULER_cancel (h->nth.timeout_task);
724 h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; 720 h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK;
725 h->ccs -= COCO_TRANSMIT_READY; 721 h->ccs -= COCO_TRANSMIT_READY;
726 GNUNET_assert (h->write_task == GNUNET_SCHEDULER_NO_TASK); 722 GNUNET_assert (h->write_task == GNUNET_SCHEDULER_NO_TASK);
727 GNUNET_assert (h->nth.notify_ready != NULL); 723 GNUNET_assert (h->nth.notify_ready != NULL);
728 h->write_task = 724 h->write_task =
729 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining 725 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining
730 (h->nth.transmit_timeout), h->sock, 726 (h->nth.transmit_timeout), h->sock,
731 &transmit_ready, h); 727 &transmit_ready, h);
732 } 728 }
733 if (0 != (h->ccs & COCO_DESTROY_CONTINUATION)) 729 if (0 != (h->ccs & COCO_DESTROY_CONTINUATION))
734 { 730 {
735#if DEBUG_CONNECTION 731#if DEBUG_CONNECTION
736 LOG (GNUNET_ERROR_TYPE_DEBUG, 732 LOG (GNUNET_ERROR_TYPE_DEBUG,
737 "connect_success_continuation runs destroy_continuation (%p)\n", 733 "connect_success_continuation runs destroy_continuation (%p)\n", h);
738 h);
739#endif 734#endif
740 h->ccs -= COCO_DESTROY_CONTINUATION; 735 h->ccs -= COCO_DESTROY_CONTINUATION;
741 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->destroy_task); 736 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->destroy_task);
742 h->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, h); 737 h->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, h);
743 } 738 }
744} 739}
745 740
746 741
@@ -753,7 +748,7 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *h)
753 */ 748 */
754static void 749static void
755connect_probe_continuation (void *cls, 750connect_probe_continuation (void *cls,
756 const struct GNUNET_SCHEDULER_TaskContext *tc) 751 const struct GNUNET_SCHEDULER_TaskContext *tc)
757{ 752{
758 struct AddressProbe *ap = cls; 753 struct AddressProbe *ap = cls;
759 struct GNUNET_CONNECTION_Handle *h = ap->h; 754 struct GNUNET_CONNECTION_Handle *h = ap->h;
@@ -768,15 +763,15 @@ connect_probe_continuation (void *cls,
768 error = 0; 763 error = 0;
769 if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) || 764 if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) ||
770 (GNUNET_OK != 765 (GNUNET_OK !=
771 GNUNET_NETWORK_socket_getsockopt (ap->sock, SOL_SOCKET, SO_ERROR, 766 GNUNET_NETWORK_socket_getsockopt (ap->sock, SOL_SOCKET, SO_ERROR, &error,
772 &error, &len)) || (error != 0)) 767 &len)) || (error != 0))
773 { 768 {
774 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); 769 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock));
775 GNUNET_free (ap); 770 GNUNET_free (ap);
776 if ((NULL == h->ap_head) && (h->dns_active == GNUNET_NO)) 771 if ((NULL == h->ap_head) && (h->dns_active == GNUNET_NO))
777 connect_fail_continuation (h); 772 connect_fail_continuation (h);
778 return; 773 return;
779 } 774 }
780 GNUNET_assert (h->sock == NULL); 775 GNUNET_assert (h->sock == NULL);
781 h->sock = ap->sock; 776 h->sock = ap->sock;
782 GNUNET_assert (h->addr == NULL); 777 GNUNET_assert (h->addr == NULL);
@@ -786,12 +781,12 @@ connect_probe_continuation (void *cls,
786 GNUNET_free (ap); 781 GNUNET_free (ap);
787 /* cancel all other attempts */ 782 /* cancel all other attempts */
788 while (NULL != (pos = h->ap_head)) 783 while (NULL != (pos = h->ap_head))
789 { 784 {
790 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); 785 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock));
791 GNUNET_SCHEDULER_cancel (pos->task); 786 GNUNET_SCHEDULER_cancel (pos->task);
792 GNUNET_CONTAINER_DLL_remove (h->ap_head, h->ap_tail, pos); 787 GNUNET_CONTAINER_DLL_remove (h->ap_head, h->ap_tail, pos);
793 GNUNET_free (pos); 788 GNUNET_free (pos);
794 } 789 }
795 connect_success_continuation (h); 790 connect_success_continuation (h);
796} 791}
797 792
@@ -806,27 +801,27 @@ connect_probe_continuation (void *cls,
806 */ 801 */
807static void 802static void
808try_connect_using_address (void *cls, const struct sockaddr *addr, 803try_connect_using_address (void *cls, const struct sockaddr *addr,
809 socklen_t addrlen) 804 socklen_t addrlen)
810{ 805{
811 struct GNUNET_CONNECTION_Handle *h = cls; 806 struct GNUNET_CONNECTION_Handle *h = cls;
812 struct AddressProbe *ap; 807 struct AddressProbe *ap;
813 struct GNUNET_TIME_Relative delay; 808 struct GNUNET_TIME_Relative delay;
814 809
815 if (addr == NULL) 810 if (addr == NULL)
816 { 811 {
817 h->dns_active = NULL; 812 h->dns_active = NULL;
818 if ((NULL == h->ap_head) && (NULL == h->sock)) 813 if ((NULL == h->ap_head) && (NULL == h->sock))
819 connect_fail_continuation (h); 814 connect_fail_continuation (h);
820 return; 815 return;
821 } 816 }
822 if (h->sock != NULL) 817 if (h->sock != NULL)
823 return; /* already connected */ 818 return; /* already connected */
824 GNUNET_assert (h->addr == NULL); 819 GNUNET_assert (h->addr == NULL);
825 /* try to connect */ 820 /* try to connect */
826#if DEBUG_CONNECTION 821#if DEBUG_CONNECTION
827 LOG (GNUNET_ERROR_TYPE_DEBUG, 822 LOG (GNUNET_ERROR_TYPE_DEBUG,
828 "Trying to connect using address `%s:%u/%s:%u'\n", h->hostname, 823 "Trying to connect using address `%s:%u/%s:%u'\n", h->hostname, h->port,
829 h->port, GNUNET_a2s (addr, addrlen), h->port); 824 GNUNET_a2s (addr, addrlen), h->port);
830#endif 825#endif
831 ap = GNUNET_malloc (sizeof (struct AddressProbe) + addrlen); 826 ap = GNUNET_malloc (sizeof (struct AddressProbe) + addrlen);
832 ap->addr = (const struct sockaddr *) &ap[1]; 827 ap->addr = (const struct sockaddr *) &ap[1];
@@ -835,25 +830,24 @@ try_connect_using_address (void *cls, const struct sockaddr *addr,
835 ap->h = h; 830 ap->h = h;
836 831
837 switch (ap->addr->sa_family) 832 switch (ap->addr->sa_family)
838 { 833 {
839 case AF_INET: 834 case AF_INET:
840 ((struct sockaddr_in *) ap->addr)->sin_port = htons (h->port); 835 ((struct sockaddr_in *) ap->addr)->sin_port = htons (h->port);
841 break; 836 break;
842 case AF_INET6: 837 case AF_INET6:
843 ((struct sockaddr_in6 *) ap->addr)->sin6_port = htons (h->port); 838 ((struct sockaddr_in6 *) ap->addr)->sin6_port = htons (h->port);
844 break; 839 break;
845 default: 840 default:
846 GNUNET_break (0); 841 GNUNET_break (0);
847 GNUNET_free (ap); 842 GNUNET_free (ap);
848 return; /* not supported by us */ 843 return; /* not supported by us */
849 } 844 }
850 ap->sock = 845 ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, SOCK_STREAM, 0);
851 GNUNET_NETWORK_socket_create (ap->addr->sa_family, SOCK_STREAM, 0);
852 if (ap->sock == NULL) 846 if (ap->sock == NULL)
853 { 847 {
854 GNUNET_free (ap); 848 GNUNET_free (ap);
855 return; /* not supported by OS */ 849 return; /* not supported by OS */
856 } 850 }
857#if DEBUG_CONNECTION 851#if DEBUG_CONNECTION
858 LOG (GNUNET_ERROR_TYPE_INFO, _("Trying to connect to `%s' (%p)\n"), 852 LOG (GNUNET_ERROR_TYPE_INFO, _("Trying to connect to `%s' (%p)\n"),
859 GNUNET_a2s (ap->addr, ap->addrlen), h); 853 GNUNET_a2s (ap->addr, ap->addrlen), h);
@@ -861,33 +855,32 @@ try_connect_using_address (void *cls, const struct sockaddr *addr,
861 if ((GNUNET_OK != 855 if ((GNUNET_OK !=
862 GNUNET_NETWORK_socket_connect (ap->sock, ap->addr, ap->addrlen)) && 856 GNUNET_NETWORK_socket_connect (ap->sock, ap->addr, ap->addrlen)) &&
863 (errno != EINPROGRESS)) 857 (errno != EINPROGRESS))
864 { 858 {
865 /* maybe refused / unsupported address, try next */ 859 /* maybe refused / unsupported address, try next */
866 LOG_STRERROR (GNUNET_ERROR_TYPE_INFO, "connect"); 860 LOG_STRERROR (GNUNET_ERROR_TYPE_INFO, "connect");
867#if 0 861#if 0
868 LOG (GNUNET_ERROR_TYPE_INFO, 862 LOG (GNUNET_ERROR_TYPE_INFO, _("Failed to connect to `%s' (%p)\n"),
869 _("Failed to connect to `%s' (%p)\n"), 863 GNUNET_a2s (ap->addr, ap->addrlen), h);
870 GNUNET_a2s (ap->addr, ap->addrlen), h);
871#endif 864#endif
872 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); 865 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock));
873 GNUNET_free (ap); 866 GNUNET_free (ap);
874 return; 867 return;
875 } 868 }
876 GNUNET_CONTAINER_DLL_insert (h->ap_head, h->ap_tail, ap); 869 GNUNET_CONTAINER_DLL_insert (h->ap_head, h->ap_tail, ap);
877 delay = GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT; 870 delay = GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT;
878 if (h->nth.notify_ready != NULL) 871 if (h->nth.notify_ready != NULL)
879 delay = 872 delay =
880 GNUNET_TIME_relative_min (delay, 873 GNUNET_TIME_relative_min (delay,
881 GNUNET_TIME_absolute_get_remaining (h-> 874 GNUNET_TIME_absolute_get_remaining (h->
882 nth.transmit_timeout)); 875 nth.transmit_timeout));
883 if (h->receiver != NULL) 876 if (h->receiver != NULL)
884 delay = 877 delay =
885 GNUNET_TIME_relative_min (delay, 878 GNUNET_TIME_relative_min (delay,
886 GNUNET_TIME_absolute_get_remaining 879 GNUNET_TIME_absolute_get_remaining
887 (h->receive_timeout)); 880 (h->receive_timeout));
888 ap->task = 881 ap->task =
889 GNUNET_SCHEDULER_add_write_net (delay, ap->sock, 882 GNUNET_SCHEDULER_add_write_net (delay, ap->sock,
890 &connect_probe_continuation, ap); 883 &connect_probe_continuation, ap);
891} 884}
892 885
893 886
@@ -902,13 +895,13 @@ try_connect_using_address (void *cls, const struct sockaddr *addr,
902 * @return the socket handle 895 * @return the socket handle
903 */ 896 */
904struct GNUNET_CONNECTION_Handle * 897struct GNUNET_CONNECTION_Handle *
905GNUNET_CONNECTION_create_from_connect (const struct 898GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle
906 GNUNET_CONFIGURATION_Handle *cfg, 899 *cfg, const char *hostname,
907 const char *hostname, uint16_t port) 900 uint16_t port)
908{ 901{
909 struct GNUNET_CONNECTION_Handle *ret; 902 struct GNUNET_CONNECTION_Handle *ret;
910 903
911 GNUNET_assert (0 < strlen (hostname)); /* sanity check */ 904 GNUNET_assert (0 < strlen (hostname)); /* sanity check */
912 ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle)); 905 ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle));
913 ret->cfg = cfg; 906 ret->cfg = cfg;
914 ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE; 907 ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE;
@@ -916,9 +909,9 @@ GNUNET_CONNECTION_create_from_connect (const struct
916 ret->port = port; 909 ret->port = port;
917 ret->hostname = GNUNET_strdup (hostname); 910 ret->hostname = GNUNET_strdup (hostname);
918 ret->dns_active = 911 ret->dns_active =
919 GNUNET_RESOLVER_ip_get (ret->hostname, AF_UNSPEC, 912 GNUNET_RESOLVER_ip_get (ret->hostname, AF_UNSPEC,
920 GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT, 913 GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT,
921 &try_connect_using_address, ret); 914 &try_connect_using_address, ret);
922 return ret; 915 return ret;
923} 916}
924 917
@@ -934,15 +927,15 @@ GNUNET_CONNECTION_create_from_connect (const struct
934 */ 927 */
935struct GNUNET_CONNECTION_Handle * 928struct GNUNET_CONNECTION_Handle *
936GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct 929GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct
937 GNUNET_CONFIGURATION_Handle 930 GNUNET_CONFIGURATION_Handle
938 *cfg, const char *unixpath) 931 *cfg, const char *unixpath)
939{ 932{
940#ifdef AF_UNIX 933#ifdef AF_UNIX
941 struct GNUNET_CONNECTION_Handle *ret; 934 struct GNUNET_CONNECTION_Handle *ret;
942 struct sockaddr_un *un; 935 struct sockaddr_un *un;
943 size_t slen; 936 size_t slen;
944 937
945 GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ 938 GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
946 un = GNUNET_malloc (sizeof (struct sockaddr_un)); 939 un = GNUNET_malloc (sizeof (struct sockaddr_un));
947 un->sun_family = AF_UNIX; 940 un->sun_family = AF_UNIX;
948 slen = strlen (unixpath); 941 slen = strlen (unixpath);
@@ -967,20 +960,20 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct
967 ret->addrlen = slen; 960 ret->addrlen = slen;
968 ret->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); 961 ret->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
969 if (NULL == ret->sock) 962 if (NULL == ret->sock)
970 { 963 {
971 GNUNET_free (ret->addr); 964 GNUNET_free (ret->addr);
972 GNUNET_free (ret->write_buffer); 965 GNUNET_free (ret->write_buffer);
973 GNUNET_free (ret); 966 GNUNET_free (ret);
974 return NULL; 967 return NULL;
975 } 968 }
976 if (GNUNET_OK != 969 if (GNUNET_OK !=
977 GNUNET_NETWORK_socket_connect (ret->sock, ret->addr, ret->addrlen)) 970 GNUNET_NETWORK_socket_connect (ret->sock, ret->addr, ret->addrlen))
978 { 971 {
979 /* Just return; we expect everything to work eventually so don't fail HARD */ 972 /* Just return; we expect everything to work eventually so don't fail HARD */
980 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret->sock)); 973 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret->sock));
981 ret->sock = NULL; 974 ret->sock = NULL;
982 return ret; 975 return ret;
983 } 976 }
984 connect_success_continuation (ret); 977 connect_success_continuation (ret);
985 return ret; 978 return ret;
986#else 979#else
@@ -1001,8 +994,8 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct
1001 */ 994 */
1002struct GNUNET_CONNECTION_Handle * 995struct GNUNET_CONNECTION_Handle *
1003GNUNET_CONNECTION_create_from_sockaddr (int af_family, 996GNUNET_CONNECTION_create_from_sockaddr (int af_family,
1004 const struct sockaddr *serv_addr, 997 const struct sockaddr *serv_addr,
1005 socklen_t addrlen) 998 socklen_t addrlen)
1006{ 999{
1007 struct GNUNET_NETWORK_Handle *s; 1000 struct GNUNET_NETWORK_Handle *s;
1008 struct GNUNET_CONNECTION_Handle *ret; 1001 struct GNUNET_CONNECTION_Handle *ret;
@@ -1010,22 +1003,20 @@ GNUNET_CONNECTION_create_from_sockaddr (int af_family,
1010 1003
1011 s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0); 1004 s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0);
1012 if (s == NULL) 1005 if (s == NULL)
1013 { 1006 {
1014 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, 1007 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "socket");
1015 "socket"); 1008 return NULL;
1016 return NULL; 1009 }
1017 }
1018 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) && 1010 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) &&
1019 (errno != EINPROGRESS)) 1011 (errno != EINPROGRESS))
1020 { 1012 {
1021 /* maybe refused / unsupported address, try next */ 1013 /* maybe refused / unsupported address, try next */
1022 LOG_STRERROR (GNUNET_ERROR_TYPE_INFO, "connect"); 1014 LOG_STRERROR (GNUNET_ERROR_TYPE_INFO, "connect");
1023 LOG (GNUNET_ERROR_TYPE_INFO, 1015 LOG (GNUNET_ERROR_TYPE_INFO, _("Attempt to connect to `%s' failed\n"),
1024 _("Attempt to connect to `%s' failed\n"), GNUNET_a2s (serv_addr, 1016 GNUNET_a2s (serv_addr, addrlen));
1025 addrlen)); 1017 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s));
1026 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); 1018 return NULL;
1027 return NULL; 1019 }
1028 }
1029 ret = GNUNET_CONNECTION_create_from_existing (s); 1020 ret = GNUNET_CONNECTION_create_from_existing (s);
1030 ret->addr = GNUNET_malloc (addrlen); 1021 ret->addr = GNUNET_malloc (addrlen);
1031 memcpy (ret->addr, serv_addr, addrlen); 1022 memcpy (ret->addr, serv_addr, addrlen);
@@ -1050,7 +1041,7 @@ int
1050GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *sock) 1041GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *sock)
1051{ 1042{
1052 if ((sock->ap_head != NULL) || (sock->dns_active != NULL)) 1043 if ((sock->ap_head != NULL) || (sock->dns_active != NULL))
1053 return GNUNET_YES; /* still trying to connect */ 1044 return GNUNET_YES; /* still trying to connect */
1054 return (sock->sock == NULL) ? GNUNET_NO : GNUNET_YES; 1045 return (sock->sock == NULL) ? GNUNET_NO : GNUNET_YES;
1055} 1046}
1056 1047
@@ -1070,23 +1061,23 @@ GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *sock)
1070 */ 1061 */
1071void 1062void
1072GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock, 1063GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock,
1073 int finish_pending_write) 1064 int finish_pending_write)
1074{ 1065{
1075 if (GNUNET_NO == finish_pending_write) 1066 if (GNUNET_NO == finish_pending_write)
1067 {
1068 if (sock->write_task != GNUNET_SCHEDULER_NO_TASK)
1076 { 1069 {
1077 if (sock->write_task != GNUNET_SCHEDULER_NO_TASK) 1070 GNUNET_SCHEDULER_cancel (sock->write_task);
1078 { 1071 sock->write_task = GNUNET_SCHEDULER_NO_TASK;
1079 GNUNET_SCHEDULER_cancel (sock->write_task); 1072 sock->write_buffer_off = 0;
1080 sock->write_task = GNUNET_SCHEDULER_NO_TASK;
1081 sock->write_buffer_off = 0;
1082 }
1083 sock->nth.notify_ready = NULL;
1084 } 1073 }
1074 sock->nth.notify_ready = NULL;
1075 }
1085 if ((sock->write_buffer_off == 0) && (sock->dns_active != NULL)) 1076 if ((sock->write_buffer_off == 0) && (sock->dns_active != NULL))
1086 { 1077 {
1087 GNUNET_RESOLVER_request_cancel (sock->dns_active); 1078 GNUNET_RESOLVER_request_cancel (sock->dns_active);
1088 sock->dns_active = NULL; 1079 sock->dns_active = NULL;
1089 } 1080 }
1090 1081
1091 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); 1082 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task);
1092 sock->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, sock); 1083 sock->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, sock);
@@ -1102,8 +1093,8 @@ signal_timeout (struct GNUNET_CONNECTION_Handle *sh)
1102 GNUNET_CONNECTION_Receiver receiver; 1093 GNUNET_CONNECTION_Receiver receiver;
1103 1094
1104#if DEBUG_CONNECTION 1095#if DEBUG_CONNECTION
1105 LOG (GNUNET_ERROR_TYPE_DEBUG, 1096 LOG (GNUNET_ERROR_TYPE_DEBUG, "Network signals time out to receiver (%p)!\n",
1106 "Network signals time out to receiver (%p)!\n", sh); 1097 sh);
1107#endif 1098#endif
1108 GNUNET_assert (NULL != (receiver = sh->receiver)); 1099 GNUNET_assert (NULL != (receiver = sh->receiver));
1109 sh->receiver = NULL; 1100 sh->receiver = NULL;
@@ -1141,62 +1132,61 @@ receive_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1141 sh->read_task = GNUNET_SCHEDULER_NO_TASK; 1132 sh->read_task = GNUNET_SCHEDULER_NO_TASK;
1142 if ((GNUNET_YES == sh->ignore_shutdown) && 1133 if ((GNUNET_YES == sh->ignore_shutdown) &&
1143 (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))) 1134 (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)))
1144 { 1135 {
1145 /* ignore shutdown request, go again immediately */ 1136 /* ignore shutdown request, go again immediately */
1146#if DEBUG_CONNECTION 1137#if DEBUG_CONNECTION
1147 LOG (GNUNET_ERROR_TYPE_DEBUG, 1138 LOG (GNUNET_ERROR_TYPE_DEBUG,
1148 "Ignoring shutdown signal per configuration\n"); 1139 "Ignoring shutdown signal per configuration\n");
1149#endif 1140#endif
1150 sh->read_task = 1141 sh->read_task =
1151 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining 1142 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining
1152 (sh->receive_timeout), sh->sock, 1143 (sh->receive_timeout), sh->sock,
1153 &receive_ready, sh); 1144 &receive_ready, sh);
1154 return; 1145 return;
1155 } 1146 }
1156 now = GNUNET_TIME_absolute_get (); 1147 now = GNUNET_TIME_absolute_get ();
1157 if ((now.abs_value > sh->receive_timeout.abs_value) || 1148 if ((now.abs_value > sh->receive_timeout.abs_value) ||
1158 (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) || 1149 (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) ||
1159 (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))) 1150 (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)))
1160 { 1151 {
1161#if DEBUG_CONNECTION 1152#if DEBUG_CONNECTION
1162 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1153 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1163 LOG (GNUNET_ERROR_TYPE_DEBUG, 1154 LOG (GNUNET_ERROR_TYPE_DEBUG,
1164 "Receive from `%s' encounters error: time out by %llums... (%p)\n", 1155 "Receive from `%s' encounters error: time out by %llums... (%p)\n",
1165 GNUNET_a2s (sh->addr, sh->addrlen), 1156 GNUNET_a2s (sh->addr, sh->addrlen),
1166 GNUNET_TIME_absolute_get_duration (sh->receive_timeout). 1157 GNUNET_TIME_absolute_get_duration (sh->receive_timeout).rel_value,
1167 rel_value, sh); 1158 sh);
1168#endif 1159#endif
1169 signal_timeout (sh); 1160 signal_timeout (sh);
1170 return; 1161 return;
1171 } 1162 }
1172 if (sh->sock == NULL) 1163 if (sh->sock == NULL)
1173 { 1164 {
1174 /* connect failed for good */ 1165 /* connect failed for good */
1175#if DEBUG_CONNECTION 1166#if DEBUG_CONNECTION
1176 LOG (GNUNET_ERROR_TYPE_DEBUG, 1167 LOG (GNUNET_ERROR_TYPE_DEBUG,
1177 "Receive encounters error, socket closed... (%p)\n", sh); 1168 "Receive encounters error, socket closed... (%p)\n", sh);
1178#endif 1169#endif
1179 signal_error (sh, ECONNREFUSED); 1170 signal_error (sh, ECONNREFUSED);
1180 return; 1171 return;
1181 } 1172 }
1182 GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, sh->sock)); 1173 GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, sh->sock));
1183RETRY: 1174RETRY:
1184 ret = GNUNET_NETWORK_socket_recv (sh->sock, buffer, sh->max); 1175 ret = GNUNET_NETWORK_socket_recv (sh->sock, buffer, sh->max);
1185 if (ret == -1) 1176 if (ret == -1)
1186 { 1177 {
1187 if (errno == EINTR) 1178 if (errno == EINTR)
1188 goto RETRY; 1179 goto RETRY;
1189#if DEBUG_CONNECTION 1180#if DEBUG_CONNECTION
1190 LOG (GNUNET_ERROR_TYPE_DEBUG, "Error receiving: %s\n", 1181 LOG (GNUNET_ERROR_TYPE_DEBUG, "Error receiving: %s\n", STRERROR (errno));
1191 STRERROR (errno));
1192#endif 1182#endif
1193 signal_error (sh, errno); 1183 signal_error (sh, errno);
1194 return; 1184 return;
1195 } 1185 }
1196#if DEBUG_CONNECTION 1186#if DEBUG_CONNECTION
1197 LOG (GNUNET_ERROR_TYPE_DEBUG, 1187 LOG (GNUNET_ERROR_TYPE_DEBUG,
1198 "receive_ready read %u/%u bytes from `%s' (%p)!\n", 1188 "receive_ready read %u/%u bytes from `%s' (%p)!\n", (unsigned int) ret,
1199 (unsigned int) ret, sh->max, GNUNET_a2s (sh->addr, sh->addrlen), sh); 1189 sh->max, GNUNET_a2s (sh->addr, sh->addrlen), sh);
1200#endif 1190#endif
1201 GNUNET_assert (NULL != (receiver = sh->receiver)); 1191 GNUNET_assert (NULL != (receiver = sh->receiver));
1202 sh->receiver = NULL; 1192 sh->receiver = NULL;
@@ -1222,32 +1212,32 @@ receive_again (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1222 1212
1223 sh->read_task = GNUNET_SCHEDULER_NO_TASK; 1213 sh->read_task = GNUNET_SCHEDULER_NO_TASK;
1224 if (sh->sock == NULL) 1214 if (sh->sock == NULL)
1225 { 1215 {
1226 /* not connected and no longer trying */ 1216 /* not connected and no longer trying */
1227#if DEBUG_CONNECTION 1217#if DEBUG_CONNECTION
1228 LOG (GNUNET_ERROR_TYPE_DEBUG, 1218 LOG (GNUNET_ERROR_TYPE_DEBUG,
1229 "Receive encounters error, socket closed (%p)...\n", sh); 1219 "Receive encounters error, socket closed (%p)...\n", sh);
1230#endif 1220#endif
1231 signal_error (sh, ECONNREFUSED); 1221 signal_error (sh, ECONNREFUSED);
1232 return; 1222 return;
1233 } 1223 }
1234 now = GNUNET_TIME_absolute_get (); 1224 now = GNUNET_TIME_absolute_get ();
1235 if ((now.abs_value > sh->receive_timeout.abs_value) || 1225 if ((now.abs_value > sh->receive_timeout.abs_value) ||
1236 (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))) 1226 (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)))
1237 { 1227 {
1238#if DEBUG_CONNECTION 1228#if DEBUG_CONNECTION
1239 LOG (GNUNET_ERROR_TYPE_DEBUG, 1229 LOG (GNUNET_ERROR_TYPE_DEBUG,
1240 "Receive encounters error: time out (%p)...\n", sh); 1230 "Receive encounters error: time out (%p)...\n", sh);
1241#endif 1231#endif
1242 signal_timeout (sh); 1232 signal_timeout (sh);
1243 return; 1233 return;
1244 } 1234 }
1245 GNUNET_assert (sh->sock != NULL); 1235 GNUNET_assert (sh->sock != NULL);
1246 /* connect succeeded, wait for data! */ 1236 /* connect succeeded, wait for data! */
1247 sh->read_task = 1237 sh->read_task =
1248 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining 1238 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining
1249 (sh->receive_timeout), sh->sock, 1239 (sh->receive_timeout), sh->sock,
1250 &receive_ready, sh); 1240 &receive_ready, sh);
1251} 1241}
1252 1242
1253 1243
@@ -1266,31 +1256,31 @@ receive_again (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1266 */ 1256 */
1267void 1257void
1268GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *sock, size_t max, 1258GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *sock, size_t max,
1269 struct GNUNET_TIME_Relative timeout, 1259 struct GNUNET_TIME_Relative timeout,
1270 GNUNET_CONNECTION_Receiver receiver, 1260 GNUNET_CONNECTION_Receiver receiver,
1271 void *receiver_cls) 1261 void *receiver_cls)
1272{ 1262{
1273 struct GNUNET_SCHEDULER_TaskContext tc; 1263 struct GNUNET_SCHEDULER_TaskContext tc;
1274 1264
1275 GNUNET_assert ((sock->read_task == GNUNET_SCHEDULER_NO_TASK) && 1265 GNUNET_assert ((sock->read_task == GNUNET_SCHEDULER_NO_TASK) &&
1276 (0 == (sock->ccs & COCO_RECEIVE_AGAIN)) && 1266 (0 == (sock->ccs & COCO_RECEIVE_AGAIN)) &&
1277 (sock->receiver == NULL)); 1267 (sock->receiver == NULL));
1278 sock->receiver = receiver; 1268 sock->receiver = receiver;
1279 sock->receiver_cls = receiver_cls; 1269 sock->receiver_cls = receiver_cls;
1280 sock->receive_timeout = GNUNET_TIME_relative_to_absolute (timeout); 1270 sock->receive_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1281 sock->max = max; 1271 sock->max = max;
1282 if (sock->sock != NULL) 1272 if (sock->sock != NULL)
1283 { 1273 {
1284 memset (&tc, 0, sizeof (tc)); 1274 memset (&tc, 0, sizeof (tc));
1285 tc.reason = GNUNET_SCHEDULER_REASON_PREREQ_DONE; 1275 tc.reason = GNUNET_SCHEDULER_REASON_PREREQ_DONE;
1286 receive_again (sock, &tc); 1276 receive_again (sock, &tc);
1287 return; 1277 return;
1288 } 1278 }
1289 if ((sock->dns_active == NULL) && (sock->ap_head == NULL)) 1279 if ((sock->dns_active == NULL) && (sock->ap_head == NULL))
1290 { 1280 {
1291 receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT); 1281 receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT);
1292 return; 1282 return;
1293 } 1283 }
1294 sock->ccs += COCO_RECEIVE_AGAIN; 1284 sock->ccs += COCO_RECEIVE_AGAIN;
1295} 1285}
1296 1286
@@ -1303,7 +1293,7 @@ GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *sock, size_t max,
1303 */ 1293 */
1304void 1294void
1305GNUNET_CONNECTION_ignore_shutdown (struct GNUNET_CONNECTION_Handle *sock, 1295GNUNET_CONNECTION_ignore_shutdown (struct GNUNET_CONNECTION_Handle *sock,
1306 int do_ignore) 1296 int do_ignore)
1307{ 1297{
1308 sock->ignore_shutdown = do_ignore; 1298 sock->ignore_shutdown = do_ignore;
1309} 1299}
@@ -1321,15 +1311,15 @@ void *
1321GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *sock) 1311GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *sock)
1322{ 1312{
1323 if (sock->read_task != GNUNET_SCHEDULER_NO_TASK) 1313 if (sock->read_task != GNUNET_SCHEDULER_NO_TASK)
1324 { 1314 {
1325 GNUNET_assert (sock == GNUNET_SCHEDULER_cancel (sock->read_task)); 1315 GNUNET_assert (sock == GNUNET_SCHEDULER_cancel (sock->read_task));
1326 sock->read_task = GNUNET_SCHEDULER_NO_TASK; 1316 sock->read_task = GNUNET_SCHEDULER_NO_TASK;
1327 } 1317 }
1328 else 1318 else
1329 { 1319 {
1330 GNUNET_assert (0 != (sock->ccs & COCO_RECEIVE_AGAIN)); 1320 GNUNET_assert (0 != (sock->ccs & COCO_RECEIVE_AGAIN));
1331 sock->ccs -= COCO_RECEIVE_AGAIN; 1321 sock->ccs -= COCO_RECEIVE_AGAIN;
1332 } 1322 }
1333 sock->receiver = NULL; 1323 sock->receiver = NULL;
1334 return sock->receiver_cls; 1324 return sock->receiver_cls;
1335} 1325}
@@ -1360,18 +1350,18 @@ process_notify (struct GNUNET_CONNECTION_Handle *sock)
1360 return GNUNET_NO; 1350 return GNUNET_NO;
1361 sock->nth.notify_ready = NULL; 1351 sock->nth.notify_ready = NULL;
1362 if (sock->write_buffer_size - sock->write_buffer_off < size) 1352 if (sock->write_buffer_size - sock->write_buffer_off < size)
1363 { 1353 {
1364 /* need to compact */ 1354 /* need to compact */
1365 memmove (sock->write_buffer, 1355 memmove (sock->write_buffer, &sock->write_buffer[sock->write_buffer_pos],
1366 &sock->write_buffer[sock->write_buffer_pos], used); 1356 used);
1367 sock->write_buffer_off -= sock->write_buffer_pos; 1357 sock->write_buffer_off -= sock->write_buffer_pos;
1368 sock->write_buffer_pos = 0; 1358 sock->write_buffer_pos = 0;
1369 } 1359 }
1370 avail = sock->write_buffer_size - sock->write_buffer_off; 1360 avail = sock->write_buffer_size - sock->write_buffer_off;
1371 GNUNET_assert (avail >= size); 1361 GNUNET_assert (avail >= size);
1372 size = 1362 size =
1373 notify (sock->nth.notify_ready_cls, avail, 1363 notify (sock->nth.notify_ready_cls, avail,
1374 &sock->write_buffer[sock->write_buffer_off]); 1364 &sock->write_buffer[sock->write_buffer_off]);
1375 GNUNET_assert (size <= avail); 1365 GNUNET_assert (size <= avail);
1376 sock->write_buffer_off += size; 1366 sock->write_buffer_off += size;
1377 return GNUNET_YES; 1367 return GNUNET_YES;
@@ -1401,12 +1391,11 @@ transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1401 sock->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; 1391 sock->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK;
1402#if DEBUG_CONNECTION 1392#if DEBUG_CONNECTION
1403 LOG (GNUNET_ERROR_TYPE_DEBUG, 1393 LOG (GNUNET_ERROR_TYPE_DEBUG,
1404 "Transmit to `%s:%u/%s' fails, time out reached (%p).\n", 1394 "Transmit to `%s:%u/%s' fails, time out reached (%p).\n", sock->hostname,
1405 sock->hostname, sock->port, GNUNET_a2s (sock->addr, 1395 sock->port, GNUNET_a2s (sock->addr, sock->addrlen), sock);
1406 sock->addrlen), sock);
1407#endif 1396#endif
1408 GNUNET_assert (0 != (sock->ccs & COCO_TRANSMIT_READY)); 1397 GNUNET_assert (0 != (sock->ccs & COCO_TRANSMIT_READY));
1409 sock->ccs -= COCO_TRANSMIT_READY; /* remove request */ 1398 sock->ccs -= COCO_TRANSMIT_READY; /* remove request */
1410 notify = sock->nth.notify_ready; 1399 notify = sock->nth.notify_ready;
1411 sock->nth.notify_ready = NULL; 1400 sock->nth.notify_ready = NULL;
1412 notify (sock->nth.notify_ready_cls, 0, NULL); 1401 notify (sock->nth.notify_ready_cls, 0, NULL);
@@ -1451,20 +1440,20 @@ transmit_error (struct GNUNET_CONNECTION_Handle *sock)
1451 GNUNET_CONNECTION_TransmitReadyNotify notify; 1440 GNUNET_CONNECTION_TransmitReadyNotify notify;
1452 1441
1453 if (NULL != sock->sock) 1442 if (NULL != sock->sock)
1454 { 1443 {
1455 GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR); 1444 GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR);
1456 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock)); 1445 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock));
1457 sock->sock = NULL; 1446 sock->sock = NULL;
1458 } 1447 }
1459 if (sock->read_task != GNUNET_SCHEDULER_NO_TASK) 1448 if (sock->read_task != GNUNET_SCHEDULER_NO_TASK)
1460 { 1449 {
1461 GNUNET_SCHEDULER_cancel (sock->read_task); 1450 GNUNET_SCHEDULER_cancel (sock->read_task);
1462 sock->read_task = GNUNET_SCHEDULER_NO_TASK; 1451 sock->read_task = GNUNET_SCHEDULER_NO_TASK;
1463 signal_timeout (sock); 1452 signal_timeout (sock);
1464 return; 1453 return;
1465 } 1454 }
1466 if (sock->nth.notify_ready == NULL) 1455 if (sock->nth.notify_ready == NULL)
1467 return; /* nobody to tell about it */ 1456 return; /* nobody to tell about it */
1468 notify = sock->nth.notify_ready; 1457 notify = sock->nth.notify_ready;
1469 sock->nth.notify_ready = NULL; 1458 sock->nth.notify_ready = NULL;
1470 notify (sock->nth.notify_ready_cls, 0, NULL); 1459 notify (sock->nth.notify_ready_cls, 0, NULL);
@@ -1494,109 +1483,107 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1494 sock->write_task = GNUNET_SCHEDULER_NO_TASK; 1483 sock->write_task = GNUNET_SCHEDULER_NO_TASK;
1495 GNUNET_assert (sock->nth.timeout_task == GNUNET_SCHEDULER_NO_TASK); 1484 GNUNET_assert (sock->nth.timeout_task == GNUNET_SCHEDULER_NO_TASK);
1496 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1485 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1497 { 1486 {
1498 if ( (sock->ignore_shutdown == GNUNET_YES) && 1487 if ((sock->ignore_shutdown == GNUNET_YES) && (NULL != sock->sock))
1499 (NULL != sock->sock) ) 1488 goto SCHEDULE_WRITE; /* ignore shutdown, go again immediately */
1500 goto SCHEDULE_WRITE; /* ignore shutdown, go again immediately */
1501#if DEBUG_CONNECTION 1489#if DEBUG_CONNECTION
1502 LOG (GNUNET_ERROR_TYPE_DEBUG, 1490 LOG (GNUNET_ERROR_TYPE_DEBUG,
1503 "Transmit to `%s' fails, shutdown happened (%p).\n", 1491 "Transmit to `%s' fails, shutdown happened (%p).\n",
1504 GNUNET_a2s (sock->addr, sock->addrlen), sock); 1492 GNUNET_a2s (sock->addr, sock->addrlen), sock);
1505#endif 1493#endif
1506 notify = sock->nth.notify_ready; 1494 notify = sock->nth.notify_ready;
1507 if (NULL != notify) 1495 if (NULL != notify)
1508 {
1509 sock->nth.notify_ready = NULL;
1510 notify (sock->nth.notify_ready_cls, 0, NULL);
1511 }
1512 return;
1513 }
1514 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
1515 { 1496 {
1516#if DEBUG_CONNECTION
1517 LOG (GNUNET_ERROR_TYPE_DEBUG,
1518 "Transmit to `%s' fails, time out reached (%p).\n",
1519 GNUNET_a2s (sock->addr, sock->addrlen), sock);
1520#endif
1521 notify = sock->nth.notify_ready;
1522 GNUNET_assert (NULL != notify);
1523 sock->nth.notify_ready = NULL; 1497 sock->nth.notify_ready = NULL;
1524 notify (sock->nth.notify_ready_cls, 0, NULL); 1498 notify (sock->nth.notify_ready_cls, 0, NULL);
1525 return;
1526 } 1499 }
1500 return;
1501 }
1502 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
1503 {
1504#if DEBUG_CONNECTION
1505 LOG (GNUNET_ERROR_TYPE_DEBUG,
1506 "Transmit to `%s' fails, time out reached (%p).\n",
1507 GNUNET_a2s (sock->addr, sock->addrlen), sock);
1508#endif
1509 notify = sock->nth.notify_ready;
1510 GNUNET_assert (NULL != notify);
1511 sock->nth.notify_ready = NULL;
1512 notify (sock->nth.notify_ready_cls, 0, NULL);
1513 return;
1514 }
1527 GNUNET_assert (NULL != sock->sock); 1515 GNUNET_assert (NULL != sock->sock);
1528 if (tc->write_ready == NULL) 1516 if (tc->write_ready == NULL)
1529 { 1517 {
1530 /* special circumstances (in particular, 1518 /* special circumstances (in particular,
1531 * PREREQ_DONE after connect): not yet ready to write, 1519 * PREREQ_DONE after connect): not yet ready to write,
1532 * but no "fatal" error either. Hence retry. */ 1520 * but no "fatal" error either. Hence retry. */
1533 goto SCHEDULE_WRITE; 1521 goto SCHEDULE_WRITE;
1534 } 1522 }
1535 if (!GNUNET_NETWORK_fdset_isset (tc->write_ready, sock->sock)) 1523 if (!GNUNET_NETWORK_fdset_isset (tc->write_ready, sock->sock))
1536 { 1524 {
1537#if DEBUG_CONNECTION 1525#if DEBUG_CONNECTION
1538 LOG (GNUNET_ERROR_TYPE_INFO, 1526 LOG (GNUNET_ERROR_TYPE_INFO,
1539 _ 1527 _
1540 ("Could not satisfy pending transmission request, socket closed or connect failed (%p).\n"), 1528 ("Could not satisfy pending transmission request, socket closed or connect failed (%p).\n"),
1541 sock); 1529 sock);
1542#endif 1530#endif
1543 transmit_error (sock); 1531 transmit_error (sock);
1544 return; /* connect failed for good, we're finished */ 1532 return; /* connect failed for good, we're finished */
1545 } 1533 }
1546 GNUNET_assert (sock->write_buffer_off >= sock->write_buffer_pos); 1534 GNUNET_assert (sock->write_buffer_off >= sock->write_buffer_pos);
1547 if ((sock->nth.notify_ready != NULL) && 1535 if ((sock->nth.notify_ready != NULL) &&
1548 (sock->write_buffer_size < sock->nth.notify_size)) 1536 (sock->write_buffer_size < sock->nth.notify_size))
1549 { 1537 {
1550 sock->write_buffer = 1538 sock->write_buffer =
1551 GNUNET_realloc (sock->write_buffer, sock->nth.notify_size); 1539 GNUNET_realloc (sock->write_buffer, sock->nth.notify_size);
1552 sock->write_buffer_size = sock->nth.notify_size; 1540 sock->write_buffer_size = sock->nth.notify_size;
1553 } 1541 }
1554 process_notify (sock); 1542 process_notify (sock);
1555 have = sock->write_buffer_off - sock->write_buffer_pos; 1543 have = sock->write_buffer_off - sock->write_buffer_pos;
1556 if (have == 0) 1544 if (have == 0)
1557 { 1545 {
1558 /* no data ready for writing, terminate write loop */ 1546 /* no data ready for writing, terminate write loop */
1559 return; 1547 return;
1560 } 1548 }
1561 GNUNET_assert (have <= sock->write_buffer_size); 1549 GNUNET_assert (have <= sock->write_buffer_size);
1562 GNUNET_assert (have + sock->write_buffer_pos <= sock->write_buffer_size); 1550 GNUNET_assert (have + sock->write_buffer_pos <= sock->write_buffer_size);
1563 GNUNET_assert (sock->write_buffer_pos <= sock->write_buffer_size); 1551 GNUNET_assert (sock->write_buffer_pos <= sock->write_buffer_size);
1564RETRY: 1552RETRY:
1565 ret = 1553 ret =
1566 GNUNET_NETWORK_socket_send (sock->sock, 1554 GNUNET_NETWORK_socket_send (sock->sock,
1567 &sock->write_buffer[sock->write_buffer_pos], 1555 &sock->write_buffer[sock->write_buffer_pos],
1568 have); 1556 have);
1569 if (ret == -1) 1557 if (ret == -1)
1570 { 1558 {
1571 if (errno == EINTR) 1559 if (errno == EINTR)
1572 goto RETRY; 1560 goto RETRY;
1573#if 0 1561#if 0
1574 int en = errno; 1562 int en = errno;
1575 1563
1576 LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to send to `%s': %s\n"), 1564 LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to send to `%s': %s\n"),
1577 GNUNET_a2s (sock->addr, sock->addrlen), STRERROR (en)); 1565 GNUNET_a2s (sock->addr, sock->addrlen), STRERROR (en));
1578#endif 1566#endif
1579#if DEBUG_CONNECTION 1567#if DEBUG_CONNECTION
1580 LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "send"); 1568 LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "send");
1581#endif 1569#endif
1582 transmit_error (sock); 1570 transmit_error (sock);
1583 return; 1571 return;
1584 } 1572 }
1585#if DEBUG_CONNECTION 1573#if DEBUG_CONNECTION
1586 LOG (GNUNET_ERROR_TYPE_DEBUG, 1574 LOG (GNUNET_ERROR_TYPE_DEBUG,
1587 "transmit_ready transmitted %u/%u bytes to `%s' (%p)\n", 1575 "transmit_ready transmitted %u/%u bytes to `%s' (%p)\n",
1588 (unsigned int) ret, have, GNUNET_a2s (sock->addr, sock->addrlen), 1576 (unsigned int) ret, have, GNUNET_a2s (sock->addr, sock->addrlen), sock);
1589 sock);
1590#endif 1577#endif
1591 sock->write_buffer_pos += ret; 1578 sock->write_buffer_pos += ret;
1592 if (sock->write_buffer_pos == sock->write_buffer_off) 1579 if (sock->write_buffer_pos == sock->write_buffer_off)
1593 { 1580 {
1594 /* transmitted all pending data */ 1581 /* transmitted all pending data */
1595 sock->write_buffer_pos = 0; 1582 sock->write_buffer_pos = 0;
1596 sock->write_buffer_off = 0; 1583 sock->write_buffer_off = 0;
1597 } 1584 }
1598 if ((sock->write_buffer_off == 0) && (NULL == sock->nth.notify_ready)) 1585 if ((sock->write_buffer_off == 0) && (NULL == sock->nth.notify_ready))
1599 return; /* all data sent! */ 1586 return; /* all data sent! */
1600 /* not done writing, schedule more */ 1587 /* not done writing, schedule more */
1601SCHEDULE_WRITE: 1588SCHEDULE_WRITE:
1602#if DEBUG_CONNECTION 1589#if DEBUG_CONNECTION
@@ -1607,11 +1594,11 @@ SCHEDULE_WRITE:
1607 GNUNET_assert ((sock->nth.notify_ready != NULL) || (have > 0)); 1594 GNUNET_assert ((sock->nth.notify_ready != NULL) || (have > 0));
1608 if (sock->write_task == GNUNET_SCHEDULER_NO_TASK) 1595 if (sock->write_task == GNUNET_SCHEDULER_NO_TASK)
1609 sock->write_task = 1596 sock->write_task =
1610 GNUNET_SCHEDULER_add_write_net ((sock->nth.notify_ready == 1597 GNUNET_SCHEDULER_add_write_net ((sock->nth.notify_ready ==
1611 NULL) ? GNUNET_TIME_UNIT_FOREVER_REL : 1598 NULL) ? GNUNET_TIME_UNIT_FOREVER_REL :
1612 GNUNET_TIME_absolute_get_remaining 1599 GNUNET_TIME_absolute_get_remaining
1613 (sock->nth.transmit_timeout), 1600 (sock->nth.transmit_timeout),
1614 sock->sock, &transmit_ready, sock); 1601 sock->sock, &transmit_ready, sock);
1615} 1602}
1616 1603
1617 1604
@@ -1630,17 +1617,17 @@ SCHEDULE_WRITE:
1630 * NULL if we are already going to notify someone else (busy) 1617 * NULL if we are already going to notify someone else (busy)
1631 */ 1618 */
1632struct GNUNET_CONNECTION_TransmitHandle * 1619struct GNUNET_CONNECTION_TransmitHandle *
1633GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle 1620GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *sock,
1634 *sock, size_t size, 1621 size_t size,
1635 struct GNUNET_TIME_Relative timeout, 1622 struct GNUNET_TIME_Relative timeout,
1636 GNUNET_CONNECTION_TransmitReadyNotify 1623 GNUNET_CONNECTION_TransmitReadyNotify
1637 notify, void *notify_cls) 1624 notify, void *notify_cls)
1638{ 1625{
1639 if (sock->nth.notify_ready != NULL) 1626 if (sock->nth.notify_ready != NULL)
1640 { 1627 {
1641 GNUNET_assert (0); 1628 GNUNET_assert (0);
1642 return NULL; 1629 return NULL;
1643 } 1630 }
1644 GNUNET_assert (notify != NULL); 1631 GNUNET_assert (notify != NULL);
1645 GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE); 1632 GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
1646 GNUNET_assert (sock->write_buffer_off <= sock->write_buffer_size); 1633 GNUNET_assert (sock->write_buffer_off <= sock->write_buffer_size);
@@ -1654,36 +1641,34 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle
1654 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->nth.timeout_task); 1641 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->nth.timeout_task);
1655 if ((sock->sock == NULL) && (sock->ap_head == NULL) && 1642 if ((sock->sock == NULL) && (sock->ap_head == NULL) &&
1656 (sock->dns_active == NULL)) 1643 (sock->dns_active == NULL))
1657 { 1644 {
1658 if (sock->write_task != GNUNET_SCHEDULER_NO_TASK) 1645 if (sock->write_task != GNUNET_SCHEDULER_NO_TASK)
1659 GNUNET_SCHEDULER_cancel (sock->write_task); 1646 GNUNET_SCHEDULER_cancel (sock->write_task);
1660 sock->write_task = GNUNET_SCHEDULER_add_now (&connect_error, sock); 1647 sock->write_task = GNUNET_SCHEDULER_add_now (&connect_error, sock);
1661 return &sock->nth; 1648 return &sock->nth;
1662 } 1649 }
1663 if (GNUNET_SCHEDULER_NO_TASK != sock->write_task) 1650 if (GNUNET_SCHEDULER_NO_TASK != sock->write_task)
1664 return &sock->nth; 1651 return &sock->nth;
1665 if (sock->sock != NULL) 1652 if (sock->sock != NULL)
1666 { 1653 {
1667#if DEBUG_CONNECTION 1654#if DEBUG_CONNECTION
1668 LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduling transmit_ready (%p).\n", 1655 LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduling transmit_ready (%p).\n", sock);
1669 sock);
1670#endif 1656#endif
1671 sock->write_task = 1657 sock->write_task =
1672 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining 1658 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining
1673 (sock->nth.transmit_timeout), 1659 (sock->nth.transmit_timeout),
1674 sock->sock, &transmit_ready, sock); 1660 sock->sock, &transmit_ready, sock);
1675 } 1661 }
1676 else 1662 else
1677 { 1663 {
1678#if DEBUG_CONNECTION 1664#if DEBUG_CONNECTION
1679 LOG (GNUNET_ERROR_TYPE_DEBUG, 1665 LOG (GNUNET_ERROR_TYPE_DEBUG,
1680 "CCS-Scheduling transmit_ready, adding timeout task (%p).\n", 1666 "CCS-Scheduling transmit_ready, adding timeout task (%p).\n", sock);
1681 sock);
1682#endif 1667#endif
1683 sock->ccs |= COCO_TRANSMIT_READY; 1668 sock->ccs |= COCO_TRANSMIT_READY;
1684 sock->nth.timeout_task = 1669 sock->nth.timeout_task =
1685 GNUNET_SCHEDULER_add_delayed (timeout, &transmit_timeout, sock); 1670 GNUNET_SCHEDULER_add_delayed (timeout, &transmit_timeout, sock);
1686 } 1671 }
1687 return &sock->nth; 1672 return &sock->nth;
1688} 1673}
1689 1674
@@ -1695,28 +1680,28 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle
1695 */ 1680 */
1696void 1681void
1697GNUNET_CONNECTION_notify_transmit_ready_cancel (struct 1682GNUNET_CONNECTION_notify_transmit_ready_cancel (struct
1698 GNUNET_CONNECTION_TransmitHandle 1683 GNUNET_CONNECTION_TransmitHandle
1699 *th) 1684 *th)
1700{ 1685{
1701 GNUNET_assert (th->notify_ready != NULL); 1686 GNUNET_assert (th->notify_ready != NULL);
1702 if (0 != (th->sh->ccs & COCO_TRANSMIT_READY)) 1687 if (0 != (th->sh->ccs & COCO_TRANSMIT_READY))
1703 { 1688 {
1704#if DEBUG_CONNECTION 1689#if DEBUG_CONNECTION
1705 LOG (GNUNET_ERROR_TYPE_DEBUG, 1690 LOG (GNUNET_ERROR_TYPE_DEBUG,
1706 "notify_transmit_ready_cancel cancels timeout_task (%p)\n", th); 1691 "notify_transmit_ready_cancel cancels timeout_task (%p)\n", th);
1707#endif 1692#endif
1708 GNUNET_SCHEDULER_cancel (th->timeout_task); 1693 GNUNET_SCHEDULER_cancel (th->timeout_task);
1709 th->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1694 th->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1710 th->sh->ccs -= COCO_TRANSMIT_READY; 1695 th->sh->ccs -= COCO_TRANSMIT_READY;
1711 } 1696 }
1712 else 1697 else
1698 {
1699 if (th->sh->write_task != GNUNET_SCHEDULER_NO_TASK)
1713 { 1700 {
1714 if (th->sh->write_task != GNUNET_SCHEDULER_NO_TASK) 1701 GNUNET_SCHEDULER_cancel (th->sh->write_task);
1715 { 1702 th->sh->write_task = GNUNET_SCHEDULER_NO_TASK;
1716 GNUNET_SCHEDULER_cancel (th->sh->write_task);
1717 th->sh->write_task = GNUNET_SCHEDULER_NO_TASK;
1718 }
1719 } 1703 }
1704 }
1720 th->notify_ready = NULL; 1705 th->notify_ready = NULL;
1721} 1706}
1722 1707
diff --git a/src/util/container_bloomfilter.c b/src/util/container_bloomfilter.c
index a33b619ff..180aab4c3 100644
--- a/src/util/container_bloomfilter.c
+++ b/src/util/container_bloomfilter.c
@@ -89,8 +89,8 @@ struct GNUNET_CONTAINER_BloomFilter
89 * @return number of bytes used for the data of the bloom filter 89 * @return number of bytes used for the data of the bloom filter
90 */ 90 */
91size_t 91size_t
92GNUNET_CONTAINER_bloomfilter_get_size (const struct 92GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter
93 GNUNET_CONTAINER_BloomFilter *bf) 93 *bf)
94{ 94{
95 if (bf == NULL) 95 if (bf == NULL)
96 return 0; 96 return 0;
@@ -106,10 +106,10 @@ GNUNET_CONTAINER_bloomfilter_get_size (const struct
106 */ 106 */
107struct GNUNET_CONTAINER_BloomFilter * 107struct GNUNET_CONTAINER_BloomFilter *
108GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter 108GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter
109 *bf) 109 *bf)
110{ 110{
111 return GNUNET_CONTAINER_bloomfilter_init (bf->bitArray, bf->bitArraySize, 111 return GNUNET_CONTAINER_bloomfilter_init (bf->bitArray, bf->bitArraySize,
112 bf->addressesPerElement); 112 bf->addressesPerElement);
113} 113}
114 114
115 115
@@ -181,7 +181,7 @@ testBit (char *bitArray, unsigned int bitIdx)
181 */ 181 */
182static void 182static void
183incrementBit (char *bitArray, unsigned int bitIdx, 183incrementBit (char *bitArray, unsigned int bitIdx,
184 const struct GNUNET_DISK_FileHandle *fh) 184 const struct GNUNET_DISK_FileHandle *fh)
185{ 185{
186 off_t fileSlot; 186 off_t fileSlot;
187 unsigned char value; 187 unsigned char value;
@@ -197,25 +197,25 @@ incrementBit (char *bitArray, unsigned int bitIdx,
197 targetLoc = bitIdx % 2; 197 targetLoc = bitIdx % 2;
198 198
199 GNUNET_assert (fileSlot == 199 GNUNET_assert (fileSlot ==
200 GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET)); 200 GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET));
201 if (1 != GNUNET_DISK_file_read (fh, &value, 1)) 201 if (1 != GNUNET_DISK_file_read (fh, &value, 1))
202 value = 0; 202 value = 0;
203 low = value & 0xF; 203 low = value & 0xF;
204 high = (value & (~0xF)) >> 4; 204 high = (value & (~0xF)) >> 4;
205 205
206 if (targetLoc == 0) 206 if (targetLoc == 0)
207 { 207 {
208 if (low < 0xF) 208 if (low < 0xF)
209 low++; 209 low++;
210 } 210 }
211 else 211 else
212 { 212 {
213 if (high < 0xF) 213 if (high < 0xF)
214 high++; 214 high++;
215 } 215 }
216 value = ((high << 4) | low); 216 value = ((high << 4) | low);
217 GNUNET_assert (fileSlot == 217 GNUNET_assert (fileSlot ==
218 GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET)); 218 GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET));
219 GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1)); 219 GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1));
220} 220}
221 221
@@ -229,7 +229,7 @@ incrementBit (char *bitArray, unsigned int bitIdx,
229 */ 229 */
230static void 230static void
231decrementBit (char *bitArray, unsigned int bitIdx, 231decrementBit (char *bitArray, unsigned int bitIdx,
232 const struct GNUNET_DISK_FileHandle *fh) 232 const struct GNUNET_DISK_FileHandle *fh)
233{ 233{
234 off_t fileSlot; 234 off_t fileSlot;
235 unsigned char value; 235 unsigned char value;
@@ -238,7 +238,7 @@ decrementBit (char *bitArray, unsigned int bitIdx,
238 unsigned int targetLoc; 238 unsigned int targetLoc;
239 239
240 if (GNUNET_DISK_handle_invalid (fh)) 240 if (GNUNET_DISK_handle_invalid (fh))
241 return; /* cannot decrement! */ 241 return; /* cannot decrement! */
242 /* Each char slot in the counter file holds two 4 bit counters */ 242 /* Each char slot in the counter file holds two 4 bit counters */
243 fileSlot = bitIdx / 2; 243 fileSlot = bitIdx / 2;
244 targetLoc = bitIdx % 2; 244 targetLoc = bitIdx % 2;
@@ -250,23 +250,23 @@ decrementBit (char *bitArray, unsigned int bitIdx,
250 250
251 /* decrement, but once we have reached the max, never go back! */ 251 /* decrement, but once we have reached the max, never go back! */
252 if (targetLoc == 0) 252 if (targetLoc == 0)
253 {
254 if ((low > 0) && (low < 0xF))
255 low--;
256 if (low == 0)
253 { 257 {
254 if ((low > 0) && (low < 0xF)) 258 clearBit (bitArray, bitIdx);
255 low--;
256 if (low == 0)
257 {
258 clearBit (bitArray, bitIdx);
259 }
260 } 259 }
260 }
261 else 261 else
262 {
263 if ((high > 0) && (high < 0xF))
264 high--;
265 if (high == 0)
262 { 266 {
263 if ((high > 0) && (high < 0xF)) 267 clearBit (bitArray, bitIdx);
264 high--;
265 if (high == 0)
266 {
267 clearBit (bitArray, bitIdx);
268 }
269 } 268 }
269 }
270 value = ((high << 4) | low); 270 value = ((high << 4) | low);
271 GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET); 271 GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET);
272 GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1)); 272 GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1));
@@ -295,19 +295,19 @@ makeEmptyFile (const struct GNUNET_DISK_FileHandle *fh, size_t size)
295 GNUNET_DISK_file_seek (fh, 0, GNUNET_DISK_SEEK_SET); 295 GNUNET_DISK_file_seek (fh, 0, GNUNET_DISK_SEEK_SET);
296 296
297 while (bytesleft > 0) 297 while (bytesleft > 0)
298 {
299 if (bytesleft > BUFFSIZE)
298 { 300 {
299 if (bytesleft > BUFFSIZE) 301 res = GNUNET_DISK_file_write (fh, buffer, BUFFSIZE);
300 { 302 bytesleft -= BUFFSIZE;
301 res = GNUNET_DISK_file_write (fh, buffer, BUFFSIZE);
302 bytesleft -= BUFFSIZE;
303 }
304 else
305 {
306 res = GNUNET_DISK_file_write (fh, buffer, bytesleft);
307 bytesleft = 0;
308 }
309 GNUNET_assert (res != GNUNET_SYSERR);
310 } 303 }
304 else
305 {
306 res = GNUNET_DISK_file_write (fh, buffer, bytesleft);
307 bytesleft = 0;
308 }
309 GNUNET_assert (res != GNUNET_SYSERR);
310 }
311 GNUNET_free (buffer); 311 GNUNET_free (buffer);
312 return GNUNET_OK; 312 return GNUNET_OK;
313} 313}
@@ -325,8 +325,8 @@ makeEmptyFile (const struct GNUNET_DISK_FileHandle *fh, size_t size)
325 * @return GNUNET_YES to continue, GNUNET_NO to stop early 325 * @return GNUNET_YES to continue, GNUNET_NO to stop early
326 */ 326 */
327typedef int (*BitIterator) (void *cls, 327typedef int (*BitIterator) (void *cls,
328 const struct GNUNET_CONTAINER_BloomFilter * bf, 328 const struct GNUNET_CONTAINER_BloomFilter * bf,
329 unsigned int bit); 329 unsigned int bit);
330 330
331 331
332/** 332/**
@@ -340,7 +340,7 @@ typedef int (*BitIterator) (void *cls,
340 */ 340 */
341static void 341static void
342iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf, 342iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf,
343 BitIterator callback, void *arg, const GNUNET_HashCode * key) 343 BitIterator callback, void *arg, const GNUNET_HashCode * key)
344{ 344{
345 GNUNET_HashCode tmp[2]; 345 GNUNET_HashCode tmp[2];
346 int bitCount; 346 int bitCount;
@@ -351,27 +351,27 @@ iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf,
351 tmp[0] = *key; 351 tmp[0] = *key;
352 round = 0; 352 round = 0;
353 while (bitCount > 0) 353 while (bitCount > 0)
354 {
355 while (slot < (sizeof (GNUNET_HashCode) / sizeof (uint32_t)))
354 { 356 {
355 while (slot < (sizeof (GNUNET_HashCode) / sizeof (uint32_t))) 357 if (GNUNET_YES !=
356 { 358 callback (arg, bf,
357 if (GNUNET_YES != 359 (((uint32_t *) & tmp[round & 1])[slot]) &
358 callback (arg, bf, 360 ((bf->bitArraySize * 8) - 1)))
359 (((uint32_t *) & tmp[round & 1])[slot]) & 361 return;
360 ((bf->bitArraySize * 8) - 1))) 362 slot++;
361 return; 363 bitCount--;
362 slot++; 364 if (bitCount == 0)
363 bitCount--; 365 break;
364 if (bitCount == 0)
365 break;
366 }
367 if (bitCount > 0)
368 {
369 GNUNET_CRYPTO_hash (&tmp[round & 1], sizeof (GNUNET_HashCode),
370 &tmp[(round + 1) & 1]);
371 round++;
372 slot = 0;
373 }
374 } 366 }
367 if (bitCount > 0)
368 {
369 GNUNET_CRYPTO_hash (&tmp[round & 1], sizeof (GNUNET_HashCode),
370 &tmp[(round + 1) & 1]);
371 round++;
372 slot = 0;
373 }
374 }
375} 375}
376 376
377 377
@@ -384,9 +384,8 @@ iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf,
384 * @return GNUNET_YES 384 * @return GNUNET_YES
385 */ 385 */
386static int 386static int
387incrementBitCallback (void *cls, 387incrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf,
388 const struct GNUNET_CONTAINER_BloomFilter *bf, 388 unsigned int bit)
389 unsigned int bit)
390{ 389{
391 struct GNUNET_CONTAINER_BloomFilter *b = cls; 390 struct GNUNET_CONTAINER_BloomFilter *b = cls;
392 391
@@ -404,9 +403,8 @@ incrementBitCallback (void *cls,
404 * @return GNUNET_YES 403 * @return GNUNET_YES
405 */ 404 */
406static int 405static int
407decrementBitCallback (void *cls, 406decrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf,
408 const struct GNUNET_CONTAINER_BloomFilter *bf, 407 unsigned int bit)
409 unsigned int bit)
410{ 408{
411 struct GNUNET_CONTAINER_BloomFilter *b = cls; 409 struct GNUNET_CONTAINER_BloomFilter *b = cls;
412 410
@@ -425,15 +423,15 @@ decrementBitCallback (void *cls,
425 */ 423 */
426static int 424static int
427testBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, 425testBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf,
428 unsigned int bit) 426 unsigned int bit)
429{ 427{
430 int *arg = cls; 428 int *arg = cls;
431 429
432 if (GNUNET_NO == testBit (bf->bitArray, bit)) 430 if (GNUNET_NO == testBit (bf->bitArray, bit))
433 { 431 {
434 *arg = GNUNET_NO; 432 *arg = GNUNET_NO;
435 return GNUNET_NO; 433 return GNUNET_NO;
436 } 434 }
437 return GNUNET_YES; 435 return GNUNET_YES;
438} 436}
439 437
@@ -451,7 +449,7 @@ testBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf,
451 */ 449 */
452struct GNUNET_CONTAINER_BloomFilter * 450struct GNUNET_CONTAINER_BloomFilter *
453GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, 451GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
454 unsigned int k) 452 unsigned int k)
455{ 453{
456 struct GNUNET_CONTAINER_BloomFilter *bf; 454 struct GNUNET_CONTAINER_BloomFilter *bf;
457 char *rbuff; 455 char *rbuff;
@@ -467,32 +465,32 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
467 ui = 1; 465 ui = 1;
468 while (ui < size) 466 while (ui < size)
469 ui *= 2; 467 ui *= 2;
470 size = ui; /* make sure it's a power of 2 */ 468 size = ui; /* make sure it's a power of 2 */
471 469
472 bf = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_BloomFilter)); 470 bf = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_BloomFilter));
473 /* Try to open a bloomfilter file */ 471 /* Try to open a bloomfilter file */
474 bf->fh = 472 bf->fh =
475 GNUNET_DISK_file_open (filename, 473 GNUNET_DISK_file_open (filename,
476 GNUNET_DISK_OPEN_READWRITE | 474 GNUNET_DISK_OPEN_READWRITE |
477 GNUNET_DISK_OPEN_CREATE, 475 GNUNET_DISK_OPEN_CREATE,
478 GNUNET_DISK_PERM_USER_READ | 476 GNUNET_DISK_PERM_USER_READ |
479 GNUNET_DISK_PERM_USER_WRITE); 477 GNUNET_DISK_PERM_USER_WRITE);
480 if (NULL == bf->fh) 478 if (NULL == bf->fh)
481 { 479 {
482 GNUNET_free (bf); 480 GNUNET_free (bf);
483 return NULL; 481 return NULL;
484 } 482 }
485 bf->filename = GNUNET_strdup (filename); 483 bf->filename = GNUNET_strdup (filename);
486 /* Alloc block */ 484 /* Alloc block */
487 bf->bitArray = GNUNET_malloc_large (size); 485 bf->bitArray = GNUNET_malloc_large (size);
488 if (bf->bitArray == NULL) 486 if (bf->bitArray == NULL)
489 { 487 {
490 if (bf->fh != NULL) 488 if (bf->fh != NULL)
491 GNUNET_DISK_file_close (bf->fh); 489 GNUNET_DISK_file_close (bf->fh);
492 GNUNET_free (bf->filename); 490 GNUNET_free (bf->filename);
493 GNUNET_free (bf); 491 GNUNET_free (bf);
494 return NULL; 492 return NULL;
495 } 493 }
496 bf->bitArraySize = size; 494 bf->bitArraySize = size;
497 bf->addressesPerElement = k; 495 bf->addressesPerElement = k;
498 memset (bf->bitArray, 0, bf->bitArraySize); 496 memset (bf->bitArray, 0, bf->bitArraySize);
@@ -501,27 +499,27 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
501 rbuff = GNUNET_malloc (BUFFSIZE); 499 rbuff = GNUNET_malloc (BUFFSIZE);
502 pos = 0; 500 pos = 0;
503 while (pos < size * 8) 501 while (pos < size * 8)
502 {
503 int res;
504
505 res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE);
506 if (res == -1)
507 {
508 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", bf->filename);
509 }
510 if (res == 0)
511 break; /* is ok! we just did not use that many bits yet */
512 for (i = 0; i < res; i++)
504 { 513 {
505 int res; 514 if ((rbuff[i] & 0x0F) != 0)
506 515 setBit (bf->bitArray, pos + i * 2);
507 res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE); 516 if ((rbuff[i] & 0xF0) != 0)
508 if (res == -1) 517 setBit (bf->bitArray, pos + i * 2 + 1);
509 {
510 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", bf->filename);
511 }
512 if (res == 0)
513 break; /* is ok! we just did not use that many bits yet */
514 for (i = 0; i < res; i++)
515 {
516 if ((rbuff[i] & 0x0F) != 0)
517 setBit (bf->bitArray, pos + i * 2);
518 if ((rbuff[i] & 0xF0) != 0)
519 setBit (bf->bitArray, pos + i * 2 + 1);
520 }
521 if (res < BUFFSIZE)
522 break;
523 pos += BUFFSIZE * 2; /* 2 bits per byte in the buffer */
524 } 518 }
519 if (res < BUFFSIZE)
520 break;
521 pos += BUFFSIZE * 2; /* 2 bits per byte in the buffer */
522 }
525 GNUNET_free (rbuff); 523 GNUNET_free (rbuff);
526 return bf; 524 return bf;
527} 525}
@@ -542,7 +540,7 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
542 */ 540 */
543struct GNUNET_CONTAINER_BloomFilter * 541struct GNUNET_CONTAINER_BloomFilter *
544GNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size, 542GNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size,
545 unsigned int k) 543 unsigned int k)
546{ 544{
547 struct GNUNET_CONTAINER_BloomFilter *bf; 545 struct GNUNET_CONTAINER_BloomFilter *bf;
548 size_t ui; 546 size_t ui;
@@ -553,19 +551,19 @@ GNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size,
553 while (ui < size) 551 while (ui < size)
554 ui *= 2; 552 ui *= 2;
555 if (size != ui) 553 if (size != ui)
556 { 554 {
557 GNUNET_break (0); 555 GNUNET_break (0);
558 return NULL; 556 return NULL;
559 } 557 }
560 bf = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_BloomFilter)); 558 bf = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_BloomFilter));
561 bf->filename = NULL; 559 bf->filename = NULL;
562 bf->fh = NULL; 560 bf->fh = NULL;
563 bf->bitArray = GNUNET_malloc_large (size); 561 bf->bitArray = GNUNET_malloc_large (size);
564 if (bf->bitArray == NULL) 562 if (bf->bitArray == NULL)
565 { 563 {
566 GNUNET_free (bf); 564 GNUNET_free (bf);
567 return NULL; 565 return NULL;
568 } 566 }
569 bf->bitArraySize = size; 567 bf->bitArraySize = size;
570 bf->addressesPerElement = k; 568 bf->addressesPerElement = k;
571 if (data != NULL) 569 if (data != NULL)
@@ -587,8 +585,8 @@ GNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size,
587 */ 585 */
588int 586int
589GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct 587GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct
590 GNUNET_CONTAINER_BloomFilter *bf, 588 GNUNET_CONTAINER_BloomFilter *bf,
591 char *data, size_t size) 589 char *data, size_t size)
592{ 590{
593 if (NULL == bf) 591 if (NULL == bf)
594 return GNUNET_SYSERR; 592 return GNUNET_SYSERR;
@@ -645,7 +643,7 @@ GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter *bf)
645 */ 643 */
646int 644int
647GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter 645GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter
648 *bf, const GNUNET_HashCode * e) 646 *bf, const GNUNET_HashCode * e)
649{ 647{
650 int res; 648 int res;
651 649
@@ -665,7 +663,7 @@ GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter
665 */ 663 */
666void 664void
667GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf, 665GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf,
668 const GNUNET_HashCode * e) 666 const GNUNET_HashCode * e)
669{ 667{
670 if (NULL == bf) 668 if (NULL == bf)
671 return; 669 return;
@@ -685,7 +683,7 @@ GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf,
685 */ 683 */
686int 684int
687GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, 685GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
688 const char *data, size_t size) 686 const char *data, size_t size)
689{ 687{
690 unsigned int i; 688 unsigned int i;
691 unsigned int n; 689 unsigned int n;
@@ -719,8 +717,8 @@ GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
719 */ 717 */
720int 718int
721GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf, 719GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf,
722 const struct GNUNET_CONTAINER_BloomFilter 720 const struct GNUNET_CONTAINER_BloomFilter
723 *to_or, size_t size) 721 *to_or, size_t size)
724{ 722{
725 unsigned int i; 723 unsigned int i;
726 unsigned int n; 724 unsigned int n;
@@ -750,7 +748,7 @@ GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf,
750 */ 748 */
751void 749void
752GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf, 750GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf,
753 const GNUNET_HashCode * e) 751 const GNUNET_HashCode * e)
754{ 752{
755 if (NULL == bf) 753 if (NULL == bf)
756 return; 754 return;
@@ -772,9 +770,9 @@ GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf,
772 */ 770 */
773void 771void
774GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf, 772GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf,
775 GNUNET_HashCodeIterator iterator, 773 GNUNET_HashCodeIterator iterator,
776 void *iterator_cls, size_t size, 774 void *iterator_cls, size_t size,
777 unsigned int k) 775 unsigned int k)
778{ 776{
779 GNUNET_HashCode hc; 777 GNUNET_HashCode hc;
780 unsigned int i; 778 unsigned int i;
@@ -783,7 +781,7 @@ GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf,
783 i = 1; 781 i = 1;
784 while (i < size) 782 while (i < size)
785 i *= 2; 783 i *= 2;
786 size = i; /* make sure it's a power of 2 */ 784 size = i; /* make sure it's a power of 2 */
787 785
788 bf->bitArraySize = size; 786 bf->bitArraySize = size;
789 bf->bitArray = GNUNET_malloc (size); 787 bf->bitArray = GNUNET_malloc (size);
diff --git a/src/util/container_heap.c b/src/util/container_heap.c
index 051b85a25..c34e220ce 100644
--- a/src/util/container_heap.c
+++ b/src/util/container_heap.c
@@ -116,10 +116,10 @@ check (const struct GNUNET_CONTAINER_HeapNode *node)
116 if (NULL == node) 116 if (NULL == node)
117 return; 117 return;
118 GNUNET_assert (node->tree_size == 118 GNUNET_assert (node->tree_size ==
119 ((node->left_child == 119 ((node->left_child ==
120 NULL) ? 0 : 1 + node->left_child->tree_size) + 120 NULL) ? 0 : 1 + node->left_child->tree_size) +
121 ((node->right_child == 121 ((node->right_child ==
122 NULL) ? 0 : 1 + node->right_child->tree_size)); 122 NULL) ? 0 : 1 + node->right_child->tree_size));
123 check (node->left_child); 123 check (node->left_child);
124 check (node->right_child); 124 check (node->right_child);
125} 125}
@@ -198,7 +198,7 @@ GNUNET_CONTAINER_heap_get_size (const struct GNUNET_CONTAINER_Heap *heap)
198 */ 198 */
199GNUNET_CONTAINER_HeapCostType 199GNUNET_CONTAINER_HeapCostType
200GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode 200GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode
201 * node) 201 *node)
202{ 202{
203 return node->cost; 203 return node->cost;
204} 204}
@@ -214,8 +214,8 @@ GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode
214 */ 214 */
215static int 215static int
216node_iterator (const struct GNUNET_CONTAINER_Heap *heap, 216node_iterator (const struct GNUNET_CONTAINER_Heap *heap,
217 struct GNUNET_CONTAINER_HeapNode *node, 217 struct GNUNET_CONTAINER_HeapNode *node,
218 GNUNET_CONTAINER_HeapIterator iterator, void *iterator_cls) 218 GNUNET_CONTAINER_HeapIterator iterator, void *iterator_cls)
219{ 219{
220 if (node == NULL) 220 if (node == NULL)
221 return GNUNET_YES; 221 return GNUNET_YES;
@@ -238,8 +238,8 @@ node_iterator (const struct GNUNET_CONTAINER_Heap *heap,
238 */ 238 */
239void 239void
240GNUNET_CONTAINER_heap_iterate (const struct GNUNET_CONTAINER_Heap *heap, 240GNUNET_CONTAINER_heap_iterate (const struct GNUNET_CONTAINER_Heap *heap,
241 GNUNET_CONTAINER_HeapIterator iterator, 241 GNUNET_CONTAINER_HeapIterator iterator,
242 void *iterator_cls) 242 void *iterator_cls)
243{ 243{
244 (void) node_iterator (heap, heap->root, iterator, iterator_cls); 244 (void) node_iterator (heap, heap->root, iterator, iterator_cls);
245} 245}
@@ -269,9 +269,9 @@ GNUNET_CONTAINER_heap_walk_get_next (struct GNUNET_CONTAINER_Heap *heap)
269 pos = heap->root; 269 pos = heap->root;
270 element = pos->element; 270 element = pos->element;
271 heap->walk_pos = 271 heap->walk_pos =
272 (0 == 272 (0 ==
273 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 273 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
274 2)) ? pos->right_child : pos->left_child; 274 2)) ? pos->right_child : pos->left_child;
275 return element; 275 return element;
276} 276}
277 277
@@ -286,51 +286,51 @@ GNUNET_CONTAINER_heap_walk_get_next (struct GNUNET_CONTAINER_Heap *heap)
286 */ 286 */
287static void 287static void
288insert_node (struct GNUNET_CONTAINER_Heap *heap, 288insert_node (struct GNUNET_CONTAINER_Heap *heap,
289 struct GNUNET_CONTAINER_HeapNode *pos, 289 struct GNUNET_CONTAINER_HeapNode *pos,
290 struct GNUNET_CONTAINER_HeapNode *node) 290 struct GNUNET_CONTAINER_HeapNode *node)
291{ 291{
292 struct GNUNET_CONTAINER_HeapNode *parent; 292 struct GNUNET_CONTAINER_HeapNode *parent;
293 293
294 GNUNET_assert (node->parent == NULL); 294 GNUNET_assert (node->parent == NULL);
295 while ((heap->order == GNUNET_CONTAINER_HEAP_ORDER_MAX) ? (pos->cost >= 295 while ((heap->order == GNUNET_CONTAINER_HEAP_ORDER_MAX) ? (pos->cost >=
296 node->cost) 296 node->cost)
297 : (pos->cost <= node->cost)) 297 : (pos->cost <= node->cost))
298 {
299 /* node is descendent of pos */
300 pos->tree_size += (1 + node->tree_size);
301 if (pos->left_child == NULL)
298 { 302 {
299 /* node is descendent of pos */ 303 pos->left_child = node;
300 pos->tree_size += (1 + node->tree_size); 304 node->parent = pos;
301 if (pos->left_child == NULL) 305 return;
302 {
303 pos->left_child = node;
304 node->parent = pos;
305 return;
306 }
307 if (pos->right_child == NULL)
308 {
309 pos->right_child = node;
310 node->parent = pos;
311 return;
312 }
313 /* keep it balanced by descending into smaller subtree */
314 if (pos->left_child->tree_size < pos->right_child->tree_size)
315 pos = pos->left_child;
316 else
317 pos = pos->right_child;
318 } 306 }
307 if (pos->right_child == NULL)
308 {
309 pos->right_child = node;
310 node->parent = pos;
311 return;
312 }
313 /* keep it balanced by descending into smaller subtree */
314 if (pos->left_child->tree_size < pos->right_child->tree_size)
315 pos = pos->left_child;
316 else
317 pos = pos->right_child;
318 }
319 /* make 'node' parent of 'pos' */ 319 /* make 'node' parent of 'pos' */
320 parent = pos->parent; 320 parent = pos->parent;
321 pos->parent = NULL; 321 pos->parent = NULL;
322 node->parent = parent; 322 node->parent = parent;
323 if (NULL == parent) 323 if (NULL == parent)
324 { 324 {
325 heap->root = node; 325 heap->root = node;
326 } 326 }
327 else 327 else
328 { 328 {
329 if (parent->left_child == pos) 329 if (parent->left_child == pos)
330 parent->left_child = node; 330 parent->left_child = node;
331 else 331 else
332 parent->right_child = node; 332 parent->right_child = node;
333 } 333 }
334 /* insert 'pos' below 'node' */ 334 /* insert 'pos' below 'node' */
335 insert_node (heap, node, pos); 335 insert_node (heap, node, pos);
336 CHECK (pos); 336 CHECK (pos);
@@ -346,9 +346,8 @@ insert_node (struct GNUNET_CONTAINER_Heap *heap,
346 * @return node for the new element 346 * @return node for the new element
347 */ 347 */
348struct GNUNET_CONTAINER_HeapNode * 348struct GNUNET_CONTAINER_HeapNode *
349GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap, 349GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap, void *element,
350 void *element, 350 GNUNET_CONTAINER_HeapCostType cost)
351 GNUNET_CONTAINER_HeapCostType cost)
352{ 351{
353 struct GNUNET_CONTAINER_HeapNode *node; 352 struct GNUNET_CONTAINER_HeapNode *node;
354 353
@@ -384,27 +383,27 @@ GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *heap)
384 heap->size--; 383 heap->size--;
385 ret = root->element; 384 ret = root->element;
386 if (root->left_child == NULL) 385 if (root->left_child == NULL)
387 { 386 {
388 heap->root = root->right_child; 387 heap->root = root->right_child;
389 if (root->right_child != NULL) 388 if (root->right_child != NULL)
390 root->right_child->parent = NULL; 389 root->right_child->parent = NULL;
391 } 390 }
392 else if (root->right_child == NULL) 391 else if (root->right_child == NULL)
393 { 392 {
394 heap->root = root->left_child; 393 heap->root = root->left_child;
395 root->left_child->parent = NULL; 394 root->left_child->parent = NULL;
396 } 395 }
397 else 396 else
398 { 397 {
399 root->left_child->parent = NULL; 398 root->left_child->parent = NULL;
400 root->right_child->parent = NULL; 399 root->right_child->parent = NULL;
401 heap->root = root->left_child; 400 heap->root = root->left_child;
402 insert_node (heap, heap->root, root->right_child); 401 insert_node (heap, heap->root, root->right_child);
403 } 402 }
404 GNUNET_free (root); 403 GNUNET_free (root);
405#if DEBUG 404#if DEBUG
406 GNUNET_assert (((heap->size == 0) && (heap->root == NULL)) || 405 GNUNET_assert (((heap->size == 0) && (heap->root == NULL)) ||
407 (heap->size == heap->root->tree_size + 1)); 406 (heap->size == heap->root->tree_size + 1));
408 CHECK (heap->root); 407 CHECK (heap->root);
409#endif 408#endif
410 return ret; 409 return ret;
@@ -436,43 +435,43 @@ remove_node (struct GNUNET_CONTAINER_HeapNode *node)
436 435
437 /* unlink 'node' itself and insert children in its place */ 436 /* unlink 'node' itself and insert children in its place */
438 if (node->parent == NULL) 437 if (node->parent == NULL)
438 {
439 if (node->left_child != NULL)
439 { 440 {
440 if (node->left_child != NULL) 441 heap->root = node->left_child;
441 { 442 node->left_child->parent = NULL;
442 heap->root = node->left_child; 443 if (node->right_child != NULL)
443 node->left_child->parent = NULL; 444 {
444 if (node->right_child != NULL) 445 node->right_child->parent = NULL;
445 { 446 insert_node (heap, heap->root, node->right_child);
446 node->right_child->parent = NULL; 447 }
447 insert_node (heap, heap->root, node->right_child);
448 }
449 }
450 else
451 {
452 heap->root = node->right_child;
453 if (node->right_child != NULL)
454 node->right_child->parent = NULL;
455 }
456 } 448 }
457 else 449 else
458 { 450 {
459 if (node->parent->left_child == node) 451 heap->root = node->right_child;
460 node->parent->left_child = NULL;
461 else
462 node->parent->right_child = NULL;
463 if (node->left_child != NULL)
464 {
465 node->left_child->parent = NULL;
466 node->parent->tree_size -= (1 + node->left_child->tree_size);
467 insert_node (heap, node->parent, node->left_child);
468 }
469 if (node->right_child != NULL) 452 if (node->right_child != NULL)
470 { 453 node->right_child->parent = NULL;
471 node->right_child->parent = NULL; 454 }
472 node->parent->tree_size -= (1 + node->right_child->tree_size); 455 }
473 insert_node (heap, node->parent, node->right_child); 456 else
474 } 457 {
458 if (node->parent->left_child == node)
459 node->parent->left_child = NULL;
460 else
461 node->parent->right_child = NULL;
462 if (node->left_child != NULL)
463 {
464 node->left_child->parent = NULL;
465 node->parent->tree_size -= (1 + node->left_child->tree_size);
466 insert_node (heap, node->parent, node->left_child);
467 }
468 if (node->right_child != NULL)
469 {
470 node->right_child->parent = NULL;
471 node->parent->tree_size -= (1 + node->right_child->tree_size);
472 insert_node (heap, node->parent, node->right_child);
475 } 473 }
474 }
476 node->parent = NULL; 475 node->parent = NULL;
477 node->left_child = NULL; 476 node->left_child = NULL;
478 node->right_child = NULL; 477 node->right_child = NULL;
@@ -506,7 +505,7 @@ GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_HeapNode *node)
506#if DEBUG 505#if DEBUG
507 CHECK (heap->root); 506 CHECK (heap->root);
508 GNUNET_assert (((heap->size == 0) && (heap->root == NULL)) || 507 GNUNET_assert (((heap->size == 0) && (heap->root == NULL)) ||
509 (heap->size == heap->root->tree_size + 1)); 508 (heap->size == heap->root->tree_size + 1));
510#endif 509#endif
511 return ret; 510 return ret;
512} 511}
@@ -521,19 +520,19 @@ GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_HeapNode *node)
521 */ 520 */
522void 521void
523GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap, 522GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap,
524 struct GNUNET_CONTAINER_HeapNode *node, 523 struct GNUNET_CONTAINER_HeapNode *node,
525 GNUNET_CONTAINER_HeapCostType new_cost) 524 GNUNET_CONTAINER_HeapCostType new_cost)
526{ 525{
527#if DEBUG 526#if DEBUG
528 GNUNET_assert (((heap->size == 0) && (heap->root == NULL)) || 527 GNUNET_assert (((heap->size == 0) && (heap->root == NULL)) ||
529 (heap->size == heap->root->tree_size + 1)); 528 (heap->size == heap->root->tree_size + 1));
530 CHECK (heap->root); 529 CHECK (heap->root);
531#endif 530#endif
532 remove_node (node); 531 remove_node (node);
533#if DEBUG 532#if DEBUG
534 CHECK (heap->root); 533 CHECK (heap->root);
535 GNUNET_assert (((heap->size == 1) && (heap->root == NULL)) || 534 GNUNET_assert (((heap->size == 1) && (heap->root == NULL)) ||
536 (heap->size == heap->root->tree_size + 2)); 535 (heap->size == heap->root->tree_size + 2));
537#endif 536#endif
538 node->cost = new_cost; 537 node->cost = new_cost;
539 if (heap->root == NULL) 538 if (heap->root == NULL)
@@ -543,7 +542,7 @@ GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap,
543#if DEBUG 542#if DEBUG
544 CHECK (heap->root); 543 CHECK (heap->root);
545 GNUNET_assert (((heap->size == 0) && (heap->root == NULL)) || 544 GNUNET_assert (((heap->size == 0) && (heap->root == NULL)) ||
546 (heap->size == heap->root->tree_size + 1)); 545 (heap->size == heap->root->tree_size + 1));
547#endif 546#endif
548} 547}
549 548
diff --git a/src/util/container_meta_data.c b/src/util/container_meta_data.c
index 1ea77f63a..c2ec01c04 100644
--- a/src/util/container_meta_data.c
+++ b/src/util/container_meta_data.c
@@ -162,10 +162,10 @@ GNUNET_CONTAINER_meta_data_destroy (struct GNUNET_CONTAINER_MetaData *md)
162 if (md == NULL) 162 if (md == NULL)
163 return; 163 return;
164 while (NULL != (item = md->items)) 164 while (NULL != (item = md->items))
165 { 165 {
166 md->items = item->next; 166 md->items = item->next;
167 meta_item_free (item); 167 meta_item_free (item);
168 } 168 }
169 GNUNET_free_non_null (md->sbuf); 169 GNUNET_free_non_null (md->sbuf);
170 GNUNET_free (md); 170 GNUNET_free (md);
171} 171}
@@ -184,10 +184,10 @@ GNUNET_CONTAINER_meta_data_clear (struct GNUNET_CONTAINER_MetaData *md)
184 if (md == NULL) 184 if (md == NULL)
185 return; 185 return;
186 while (NULL != (item = md->items)) 186 while (NULL != (item = md->items))
187 { 187 {
188 md->items = item->next; 188 md->items = item->next;
189 meta_item_free (item); 189 meta_item_free (item);
190 } 190 }
191 GNUNET_free_non_null (md->sbuf); 191 GNUNET_free_non_null (md->sbuf);
192 memset (md, 0, sizeof (struct GNUNET_CONTAINER_MetaData)); 192 memset (md, 0, sizeof (struct GNUNET_CONTAINER_MetaData));
193} 193}
@@ -206,9 +206,9 @@ GNUNET_CONTAINER_meta_data_clear (struct GNUNET_CONTAINER_MetaData *md)
206 */ 206 */
207int 207int
208GNUNET_CONTAINER_meta_data_test_equal (const struct GNUNET_CONTAINER_MetaData 208GNUNET_CONTAINER_meta_data_test_equal (const struct GNUNET_CONTAINER_MetaData
209 *md1, 209 *md1,
210 const struct GNUNET_CONTAINER_MetaData 210 const struct GNUNET_CONTAINER_MetaData
211 *md2) 211 *md2)
212{ 212{
213 struct MetaItem *i; 213 struct MetaItem *i;
214 struct MetaItem *j; 214 struct MetaItem *j;
@@ -221,24 +221,24 @@ GNUNET_CONTAINER_meta_data_test_equal (const struct GNUNET_CONTAINER_MetaData
221 221
222 i = md1->items; 222 i = md1->items;
223 while (NULL != i) 223 while (NULL != i)
224 {
225 found = GNUNET_NO;
226 j = md2->items;
227 while (NULL != j)
224 { 228 {
225 found = GNUNET_NO; 229 if ((i->type == j->type) && (i->format == j->format) &&
226 j = md2->items; 230 (i->data_size == j->data_size) &&
227 while (NULL != j) 231 (0 == memcmp (i->data, j->data, i->data_size)))
228 { 232 {
229 if ((i->type == j->type) && (i->format == j->format) && 233 found = GNUNET_YES;
230 (i->data_size == j->data_size) && 234 break;
231 (0 == memcmp (i->data, j->data, i->data_size))) 235 }
232 { 236 j = j->next;
233 found = GNUNET_YES;
234 break;
235 }
236 j = j->next;
237 }
238 if (found == GNUNET_NO)
239 return GNUNET_NO;
240 i = i->next;
241 } 237 }
238 if (found == GNUNET_NO)
239 return GNUNET_NO;
240 i = i->next;
241 }
242 return GNUNET_YES; 242 return GNUNET_YES;
243} 243}
244 244
@@ -263,11 +263,11 @@ GNUNET_CONTAINER_meta_data_test_equal (const struct GNUNET_CONTAINER_MetaData
263 */ 263 */
264int 264int
265GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md, 265GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md,
266 const char *plugin_name, 266 const char *plugin_name,
267 enum EXTRACTOR_MetaType type, 267 enum EXTRACTOR_MetaType type,
268 enum EXTRACTOR_MetaFormat format, 268 enum EXTRACTOR_MetaFormat format,
269 const char *data_mime_type, 269 const char *data_mime_type, const char *data,
270 const char *data, size_t data_len) 270 size_t data_len)
271{ 271{
272 struct MetaItem *prev; 272 struct MetaItem *prev;
273 struct MetaItem *pos; 273 struct MetaItem *pos;
@@ -277,28 +277,28 @@ GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md,
277 prev = NULL; 277 prev = NULL;
278 pos = md->items; 278 pos = md->items;
279 while (NULL != pos) 279 while (NULL != pos)
280 {
281 if (pos->data_size < data_len)
282 break;
283 if ((pos->type == type) && (pos->data_size == data_len) &&
284 (0 == memcmp (pos->data, data, data_len)))
280 { 285 {
281 if (pos->data_size < data_len) 286 if ((pos->mime_type == NULL) && (data_mime_type != NULL))
282 break; 287 {
283 if ((pos->type == type) && (pos->data_size == data_len) && 288 pos->mime_type = GNUNET_strdup (data_mime_type);
284 (0 == memcmp (pos->data, data, data_len))) 289 invalidate_sbuf (md);
285 { 290 }
286 if ((pos->mime_type == NULL) && (data_mime_type != NULL)) 291 if ((pos->format == EXTRACTOR_METAFORMAT_C_STRING) &&
287 { 292 (format == EXTRACTOR_METAFORMAT_UTF8))
288 pos->mime_type = GNUNET_strdup (data_mime_type); 293 {
289 invalidate_sbuf (md); 294 pos->format = EXTRACTOR_METAFORMAT_UTF8;
290 } 295 invalidate_sbuf (md);
291 if ((pos->format == EXTRACTOR_METAFORMAT_C_STRING) && 296 }
292 (format == EXTRACTOR_METAFORMAT_UTF8)) 297 return GNUNET_SYSERR;
293 {
294 pos->format = EXTRACTOR_METAFORMAT_UTF8;
295 invalidate_sbuf (md);
296 }
297 return GNUNET_SYSERR;
298 }
299 prev = pos;
300 pos = pos->next;
301 } 298 }
299 prev = pos;
300 pos = pos->next;
301 }
302 md->item_count++; 302 md->item_count++;
303 i = GNUNET_malloc (sizeof (struct MetaItem)); 303 i = GNUNET_malloc (sizeof (struct MetaItem));
304 i->type = type; 304 i->type = type;
@@ -310,23 +310,23 @@ GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md,
310 else 310 else
311 prev->next = i; 311 prev->next = i;
312 i->mime_type = 312 i->mime_type =
313 (data_mime_type == NULL) ? NULL : GNUNET_strdup (data_mime_type); 313 (data_mime_type == NULL) ? NULL : GNUNET_strdup (data_mime_type);
314 i->plugin_name = (plugin_name == NULL) ? NULL : GNUNET_strdup (plugin_name); 314 i->plugin_name = (plugin_name == NULL) ? NULL : GNUNET_strdup (plugin_name);
315 i->data = GNUNET_malloc (data_len); 315 i->data = GNUNET_malloc (data_len);
316 memcpy (i->data, data, data_len); 316 memcpy (i->data, data, data_len);
317 /* change OS native dir separators to unix '/' and others to '_' */ 317 /* change OS native dir separators to unix '/' and others to '_' */
318 if (type == EXTRACTOR_METATYPE_FILENAME) 318 if (type == EXTRACTOR_METATYPE_FILENAME)
319 {
320 p = i->data;
321 while ((*p != '\0') && (p < i->data + data_len))
319 { 322 {
320 p = i->data; 323 if (*p == DIR_SEPARATOR)
321 while ((*p != '\0') && (p < i->data + data_len)) 324 *p = '/';
322 { 325 else if (*p == '\\')
323 if (*p == DIR_SEPARATOR) 326 *p = '_';
324 *p = '/'; 327 p++;
325 else if (*p == '\\')
326 *p = '_';
327 p++;
328 }
329 } 328 }
329 }
330 invalidate_sbuf (md); 330 invalidate_sbuf (md);
331 return GNUNET_OK; 331 return GNUNET_OK;
332} 332}
@@ -349,14 +349,14 @@ GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md,
349 * @return 0 (to continue) 349 * @return 0 (to continue)
350 */ 350 */
351static int 351static int
352merge_helper (void *cls, const char *plugin_name, 352merge_helper (void *cls, const char *plugin_name, enum EXTRACTOR_MetaType type,
353 enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, 353 enum EXTRACTOR_MetaFormat format, const char *data_mime_type,
354 const char *data_mime_type, const char *data, size_t data_len) 354 const char *data, size_t data_len)
355{ 355{
356 struct GNUNET_CONTAINER_MetaData *md = cls; 356 struct GNUNET_CONTAINER_MetaData *md = cls;
357 357
358 (void) GNUNET_CONTAINER_meta_data_insert (md, plugin_name, type, format, 358 (void) GNUNET_CONTAINER_meta_data_insert (md, plugin_name, type, format,
359 data_mime_type, data, data_len); 359 data_mime_type, data, data_len);
360 return 0; 360 return 0;
361} 361}
362 362
@@ -370,7 +370,7 @@ merge_helper (void *cls, const char *plugin_name,
370 */ 370 */
371void 371void
372GNUNET_CONTAINER_meta_data_merge (struct GNUNET_CONTAINER_MetaData *md, 372GNUNET_CONTAINER_meta_data_merge (struct GNUNET_CONTAINER_MetaData *md,
373 const struct GNUNET_CONTAINER_MetaData *in) 373 const struct GNUNET_CONTAINER_MetaData *in)
374{ 374{
375 GNUNET_CONTAINER_meta_data_iterate (in, &merge_helper, md); 375 GNUNET_CONTAINER_meta_data_iterate (in, &merge_helper, md);
376} 376}
@@ -388,8 +388,8 @@ GNUNET_CONTAINER_meta_data_merge (struct GNUNET_CONTAINER_MetaData *md,
388 */ 388 */
389int 389int
390GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md, 390GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md,
391 enum EXTRACTOR_MetaType type, 391 enum EXTRACTOR_MetaType type,
392 const char *data, size_t data_len) 392 const char *data, size_t data_len)
393{ 393{
394 struct MetaItem *pos; 394 struct MetaItem *pos;
395 struct MetaItem *prev; 395 struct MetaItem *prev;
@@ -397,24 +397,24 @@ GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md,
397 prev = NULL; 397 prev = NULL;
398 pos = md->items; 398 pos = md->items;
399 while (NULL != pos) 399 while (NULL != pos)
400 {
401 if ((pos->type == type) &&
402 ((data == NULL) ||
403 ((pos->data_size == data_len) &&
404 (0 == memcmp (pos->data, data, data_len)))))
400 { 405 {
401 if ((pos->type == type) && 406 if (prev == NULL)
402 ((data == NULL) || 407 md->items = pos->next;
403 ((pos->data_size == data_len) && 408 else
404 (0 == memcmp (pos->data, data, data_len))))) 409 prev->next = pos->next;
405 { 410 meta_item_free (pos);
406 if (prev == NULL) 411 md->item_count--;
407 md->items = pos->next; 412 invalidate_sbuf (md);
408 else 413 return GNUNET_OK;
409 prev->next = pos->next;
410 meta_item_free (pos);
411 md->item_count--;
412 invalidate_sbuf (md);
413 return GNUNET_OK;
414 }
415 prev = pos;
416 pos = pos->next;
417 } 414 }
415 prev = pos;
416 pos = pos->next;
417 }
418 return GNUNET_SYSERR; 418 return GNUNET_SYSERR;
419} 419}
420 420
@@ -427,20 +427,19 @@ GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md,
427 */ 427 */
428void 428void
429GNUNET_CONTAINER_meta_data_add_publication_date (struct 429GNUNET_CONTAINER_meta_data_add_publication_date (struct
430 GNUNET_CONTAINER_MetaData 430 GNUNET_CONTAINER_MetaData *md)
431 *md)
432{ 431{
433 char *dat; 432 char *dat;
434 struct GNUNET_TIME_Absolute t; 433 struct GNUNET_TIME_Absolute t;
435 434
436 t = GNUNET_TIME_absolute_get (); 435 t = GNUNET_TIME_absolute_get ();
437 GNUNET_CONTAINER_meta_data_delete (md, EXTRACTOR_METATYPE_PUBLICATION_DATE, 436 GNUNET_CONTAINER_meta_data_delete (md, EXTRACTOR_METATYPE_PUBLICATION_DATE,
438 NULL, 0); 437 NULL, 0);
439 dat = GNUNET_STRINGS_absolute_time_to_string (t); 438 dat = GNUNET_STRINGS_absolute_time_to_string (t);
440 GNUNET_CONTAINER_meta_data_insert (md, "<gnunet>", 439 GNUNET_CONTAINER_meta_data_insert (md, "<gnunet>",
441 EXTRACTOR_METATYPE_PUBLICATION_DATE, 440 EXTRACTOR_METATYPE_PUBLICATION_DATE,
442 EXTRACTOR_METAFORMAT_UTF8, "text/plain", 441 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
443 dat, strlen (dat) + 1); 442 dat, strlen (dat) + 1);
444 GNUNET_free (dat); 443 GNUNET_free (dat);
445} 444}
446 445
@@ -454,9 +453,9 @@ GNUNET_CONTAINER_meta_data_add_publication_date (struct
454 * @return number of entries 453 * @return number of entries
455 */ 454 */
456int 455int
457GNUNET_CONTAINER_meta_data_iterate (const struct GNUNET_CONTAINER_MetaData 456GNUNET_CONTAINER_meta_data_iterate (const struct GNUNET_CONTAINER_MetaData *md,
458 *md, EXTRACTOR_MetaDataProcessor iter, 457 EXTRACTOR_MetaDataProcessor iter,
459 void *iter_cls) 458 void *iter_cls)
460{ 459{
461 struct MetaItem *pos; 460 struct MetaItem *pos;
462 461
@@ -466,13 +465,13 @@ GNUNET_CONTAINER_meta_data_iterate (const struct GNUNET_CONTAINER_MetaData
466 return md->item_count; 465 return md->item_count;
467 pos = md->items; 466 pos = md->items;
468 while (NULL != pos) 467 while (NULL != pos)
469 { 468 {
470 if (0 != 469 if (0 !=
471 iter (iter_cls, pos->plugin_name, pos->type, pos->format, 470 iter (iter_cls, pos->plugin_name, pos->type, pos->format,
472 pos->mime_type, pos->data, pos->data_size)) 471 pos->mime_type, pos->data, pos->data_size))
473 return md->item_count; 472 return md->item_count;
474 pos = pos->next; 473 pos = pos->next;
475 } 474 }
476 return md->item_count; 475 return md->item_count;
477} 476}
478 477
@@ -489,7 +488,7 @@ GNUNET_CONTAINER_meta_data_iterate (const struct GNUNET_CONTAINER_MetaData
489 */ 488 */
490char * 489char *
491GNUNET_CONTAINER_meta_data_get_by_type (const struct GNUNET_CONTAINER_MetaData 490GNUNET_CONTAINER_meta_data_get_by_type (const struct GNUNET_CONTAINER_MetaData
492 *md, enum EXTRACTOR_MetaType type) 491 *md, enum EXTRACTOR_MetaType type)
493{ 492{
494 struct MetaItem *pos; 493 struct MetaItem *pos;
495 494
@@ -497,13 +496,13 @@ GNUNET_CONTAINER_meta_data_get_by_type (const struct GNUNET_CONTAINER_MetaData
497 return NULL; 496 return NULL;
498 pos = md->items; 497 pos = md->items;
499 while (NULL != pos) 498 while (NULL != pos)
500 { 499 {
501 if ((type == pos->type) && 500 if ((type == pos->type) &&
502 ((pos->format == EXTRACTOR_METAFORMAT_UTF8) || 501 ((pos->format == EXTRACTOR_METAFORMAT_UTF8) ||
503 (pos->format == EXTRACTOR_METAFORMAT_C_STRING))) 502 (pos->format == EXTRACTOR_METAFORMAT_C_STRING)))
504 return GNUNET_strdup (pos->data); 503 return GNUNET_strdup (pos->data);
505 pos = pos->next; 504 pos = pos->next;
506 } 505 }
507 return NULL; 506 return NULL;
508} 507}
509 508
@@ -521,8 +520,8 @@ GNUNET_CONTAINER_meta_data_get_by_type (const struct GNUNET_CONTAINER_MetaData
521 */ 520 */
522char * 521char *
523GNUNET_CONTAINER_meta_data_get_first_by_types (const struct 522GNUNET_CONTAINER_meta_data_get_first_by_types (const struct
524 GNUNET_CONTAINER_MetaData *md, 523 GNUNET_CONTAINER_MetaData *md,
525 ...) 524 ...)
526{ 525{
527 char *ret; 526 char *ret;
528 va_list args; 527 va_list args;
@@ -533,15 +532,15 @@ GNUNET_CONTAINER_meta_data_get_first_by_types (const struct
533 ret = NULL; 532 ret = NULL;
534 va_start (args, md); 533 va_start (args, md);
535 while (1) 534 while (1)
536 { 535 {
537 type = va_arg (args, enum EXTRACTOR_MetaType); 536 type = va_arg (args, enum EXTRACTOR_MetaType);
538 537
539 if (type == -1) 538 if (type == -1)
540 break; 539 break;
541 ret = GNUNET_CONTAINER_meta_data_get_by_type (md, type); 540 ret = GNUNET_CONTAINER_meta_data_get_by_type (md, type);
542 if (ret != NULL) 541 if (ret != NULL)
543 break; 542 break;
544 } 543 }
545 va_end (args); 544 va_end (args);
546 return ret; 545 return ret;
547} 546}
@@ -556,9 +555,8 @@ GNUNET_CONTAINER_meta_data_get_first_by_types (const struct
556 * @return number of bytes in thumbnail, 0 if not available 555 * @return number of bytes in thumbnail, 0 if not available
557 */ 556 */
558size_t 557size_t
559GNUNET_CONTAINER_meta_data_get_thumbnail (const struct 558GNUNET_CONTAINER_meta_data_get_thumbnail (const struct GNUNET_CONTAINER_MetaData
560 GNUNET_CONTAINER_MetaData * md, 559 * md, unsigned char **thumb)
561 unsigned char **thumb)
562{ 560{
563 struct MetaItem *pos; 561 struct MetaItem *pos;
564 struct MetaItem *match; 562 struct MetaItem *match;
@@ -568,19 +566,19 @@ GNUNET_CONTAINER_meta_data_get_thumbnail (const struct
568 match = NULL; 566 match = NULL;
569 pos = md->items; 567 pos = md->items;
570 while (NULL != pos) 568 while (NULL != pos)
569 {
570 if ((NULL != pos->mime_type) &&
571 (0 == strncasecmp ("image/", pos->mime_type, strlen ("image/"))) &&
572 (pos->format == EXTRACTOR_METAFORMAT_BINARY))
571 { 573 {
572 if ((NULL != pos->mime_type) && 574 if (match == NULL)
573 (0 == strncasecmp ("image/", pos->mime_type, strlen ("image/"))) && 575 match = pos;
574 (pos->format == EXTRACTOR_METAFORMAT_BINARY)) 576 else if ((match->type != EXTRACTOR_METATYPE_THUMBNAIL) &&
575 { 577 (pos->type == EXTRACTOR_METATYPE_THUMBNAIL))
576 if (match == NULL) 578 match = pos;
577 match = pos;
578 else if ((match->type != EXTRACTOR_METATYPE_THUMBNAIL) &&
579 (pos->type == EXTRACTOR_METATYPE_THUMBNAIL))
580 match = pos;
581 }
582 pos = pos->next;
583 } 579 }
580 pos = pos->next;
581 }
584 if ((match == NULL) || (match->data_size == 0)) 582 if ((match == NULL) || (match->data_size == 0))
585 return 0; 583 return 0;
586 *thumb = GNUNET_malloc (match->data_size); 584 *thumb = GNUNET_malloc (match->data_size);
@@ -597,7 +595,7 @@ GNUNET_CONTAINER_meta_data_get_thumbnail (const struct
597 */ 595 */
598struct GNUNET_CONTAINER_MetaData * 596struct GNUNET_CONTAINER_MetaData *
599GNUNET_CONTAINER_meta_data_duplicate (const struct GNUNET_CONTAINER_MetaData 597GNUNET_CONTAINER_meta_data_duplicate (const struct GNUNET_CONTAINER_MetaData
600 *md) 598 *md)
601{ 599{
602 struct GNUNET_CONTAINER_MetaData *ret; 600 struct GNUNET_CONTAINER_MetaData *ret;
603 struct MetaItem *pos; 601 struct MetaItem *pos;
@@ -607,12 +605,12 @@ GNUNET_CONTAINER_meta_data_duplicate (const struct GNUNET_CONTAINER_MetaData
607 ret = GNUNET_CONTAINER_meta_data_create (); 605 ret = GNUNET_CONTAINER_meta_data_create ();
608 pos = md->items; 606 pos = md->items;
609 while (NULL != pos) 607 while (NULL != pos)
610 { 608 {
611 GNUNET_CONTAINER_meta_data_insert (ret, pos->plugin_name, pos->type, 609 GNUNET_CONTAINER_meta_data_insert (ret, pos->plugin_name, pos->type,
612 pos->format, pos->mime_type, 610 pos->format, pos->mime_type, pos->data,
613 pos->data, pos->data_size); 611 pos->data_size);
614 pos = pos->next; 612 pos = pos->next;
615 } 613 }
616 return ret; 614 return ret;
617} 615}
618 616
@@ -633,7 +631,7 @@ GNUNET_CONTAINER_meta_data_duplicate (const struct GNUNET_CONTAINER_MetaData
633 */ 631 */
634static int 632static int
635try_compression (const char *data, size_t oldSize, char **result, 633try_compression (const char *data, size_t oldSize, char **result,
636 size_t * newSize) 634 size_t * newSize)
637{ 635{
638 char *tmp; 636 char *tmp;
639 uLongf dlen; 637 uLongf dlen;
@@ -648,14 +646,14 @@ try_compression (const char *data, size_t oldSize, char **result,
648 tmp = GNUNET_malloc (dlen); 646 tmp = GNUNET_malloc (dlen);
649 if (Z_OK == 647 if (Z_OK ==
650 compress2 ((Bytef *) tmp, &dlen, (const Bytef *) data, oldSize, 9)) 648 compress2 ((Bytef *) tmp, &dlen, (const Bytef *) data, oldSize, 9))
649 {
650 if (dlen < oldSize)
651 { 651 {
652 if (dlen < oldSize) 652 *result = tmp;
653 { 653 *newSize = dlen;
654 *result = tmp; 654 return GNUNET_YES;
655 *newSize = dlen;
656 return GNUNET_YES;
657 }
658 } 655 }
656 }
659 GNUNET_free (tmp); 657 GNUNET_free (tmp);
660 return GNUNET_NO; 658 return GNUNET_NO;
661} 659}
@@ -756,10 +754,10 @@ struct MetaDataEntry
756 */ 754 */
757ssize_t 755ssize_t
758GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData 756GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData
759 *md, char **target, size_t max, 757 *md, char **target, size_t max,
760 enum 758 enum
761 GNUNET_CONTAINER_MetaDataSerializationOptions 759 GNUNET_CONTAINER_MetaDataSerializationOptions
762 opt) 760 opt)
763{ 761{
764 struct GNUNET_CONTAINER_MetaData *vmd; 762 struct GNUNET_CONTAINER_MetaData *vmd;
765 struct MetaItem *pos; 763 struct MetaItem *pos;
@@ -781,79 +779,79 @@ GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData
781 int comp; 779 int comp;
782 780
783 if (max < sizeof (struct MetaDataHeader)) 781 if (max < sizeof (struct MetaDataHeader))
784 return GNUNET_SYSERR; /* far too small */ 782 return GNUNET_SYSERR; /* far too small */
785 if (md == NULL) 783 if (md == NULL)
786 return 0; 784 return 0;
787 785
788 if (md->sbuf != NULL) 786 if (md->sbuf != NULL)
787 {
788 /* try to use serialization cache */
789 if (md->sbuf_size <= max)
789 { 790 {
790 /* try to use serialization cache */ 791 if (NULL == *target)
791 if (md->sbuf_size <= max) 792 *target = GNUNET_malloc (md->sbuf_size);
792 { 793 memcpy (*target, md->sbuf, md->sbuf_size);
793 if (NULL == *target) 794 return md->sbuf_size;
794 *target = GNUNET_malloc (md->sbuf_size);
795 memcpy (*target, md->sbuf, md->sbuf_size);
796 return md->sbuf_size;
797 }
798 if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_PART))
799 return GNUNET_SYSERR; /* can say that this will fail */
800 /* need to compute a partial serialization, sbuf useless ... */
801 } 795 }
796 if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_PART))
797 return GNUNET_SYSERR; /* can say that this will fail */
798 /* need to compute a partial serialization, sbuf useless ... */
799 }
802 dst = NULL; 800 dst = NULL;
803 msize = 0; 801 msize = 0;
804 pos = md->items; 802 pos = md->items;
805 while (NULL != pos) 803 while (NULL != pos)
806 { 804 {
807 msize += sizeof (struct MetaDataEntry); 805 msize += sizeof (struct MetaDataEntry);
808 msize += pos->data_size; 806 msize += pos->data_size;
809 if (pos->plugin_name != NULL) 807 if (pos->plugin_name != NULL)
810 msize += strlen (pos->plugin_name) + 1; 808 msize += strlen (pos->plugin_name) + 1;
811 if (pos->mime_type != NULL) 809 if (pos->mime_type != NULL)
812 msize += strlen (pos->mime_type) + 1; 810 msize += strlen (pos->mime_type) + 1;
813 pos = pos->next; 811 pos = pos->next;
814 } 812 }
815 size = (size_t) msize; 813 size = (size_t) msize;
816 if (size != msize) 814 if (size != msize)
817 { 815 {
818 GNUNET_break (0); /* integer overflow */ 816 GNUNET_break (0); /* integer overflow */
819 return GNUNET_SYSERR; 817 return GNUNET_SYSERR;
820 } 818 }
821 if (size >= GNUNET_MAX_MALLOC_CHECKED) 819 if (size >= GNUNET_MAX_MALLOC_CHECKED)
822 { 820 {
823 /* too large to be processed */ 821 /* too large to be processed */
824 return GNUNET_SYSERR; 822 return GNUNET_SYSERR;
825 } 823 }
826 ent = GNUNET_malloc (size); 824 ent = GNUNET_malloc (size);
827 mdata = (char *) &ent[md->item_count]; 825 mdata = (char *) &ent[md->item_count];
828 off = size - (md->item_count * sizeof (struct MetaDataEntry)); 826 off = size - (md->item_count * sizeof (struct MetaDataEntry));
829 i = 0; 827 i = 0;
830 pos = md->items; 828 pos = md->items;
831 while (NULL != pos) 829 while (NULL != pos)
832 { 830 {
833 ent[i].type = htonl ((uint32_t) pos->type); 831 ent[i].type = htonl ((uint32_t) pos->type);
834 ent[i].format = htonl ((uint32_t) pos->format); 832 ent[i].format = htonl ((uint32_t) pos->format);
835 ent[i].data_size = htonl ((uint32_t) pos->data_size); 833 ent[i].data_size = htonl ((uint32_t) pos->data_size);
836 if (pos->plugin_name == NULL) 834 if (pos->plugin_name == NULL)
837 plen = 0; 835 plen = 0;
838 else 836 else
839 plen = strlen (pos->plugin_name) + 1; 837 plen = strlen (pos->plugin_name) + 1;
840 ent[i].plugin_name_len = htonl ((uint32_t) plen); 838 ent[i].plugin_name_len = htonl ((uint32_t) plen);
841 if (pos->mime_type == NULL) 839 if (pos->mime_type == NULL)
842 mlen = 0; 840 mlen = 0;
843 else 841 else
844 mlen = strlen (pos->mime_type) + 1; 842 mlen = strlen (pos->mime_type) + 1;
845 ent[i].mime_type_len = htonl ((uint32_t) mlen); 843 ent[i].mime_type_len = htonl ((uint32_t) mlen);
846 off -= pos->data_size; 844 off -= pos->data_size;
847 memcpy (&mdata[off], pos->data, pos->data_size); 845 memcpy (&mdata[off], pos->data, pos->data_size);
848 off -= plen; 846 off -= plen;
849 if (pos->plugin_name != NULL) 847 if (pos->plugin_name != NULL)
850 memcpy (&mdata[off], pos->plugin_name, plen); 848 memcpy (&mdata[off], pos->plugin_name, plen);
851 off -= mlen; 849 off -= mlen;
852 if (pos->mime_type != NULL) 850 if (pos->mime_type != NULL)
853 memcpy (&mdata[off], pos->mime_type, mlen); 851 memcpy (&mdata[off], pos->mime_type, mlen);
854 i++; 852 i++;
855 pos = pos->next; 853 pos = pos->next;
856 } 854 }
857 GNUNET_assert (off == 0); 855 GNUNET_assert (off == 0);
858 856
859 clen = 0; 857 clen = 0;
@@ -862,95 +860,95 @@ GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData
862 i = 0; 860 i = 0;
863 pos = md->items; 861 pos = md->items;
864 while (pos != NULL) 862 while (pos != NULL)
863 {
864 comp = GNUNET_NO;
865 if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS))
866 comp = try_compression ((const char *) &ent[i], left, &cdata, &clen);
867
868 if ((md->sbuf == NULL) && (i == 0))
869 {
870 /* fill 'sbuf'; this "modifies" md, but since this is only
871 * an internal cache we will cast away the 'const' instead
872 * of making the API look strange. */
873 vmd = (struct GNUNET_CONTAINER_MetaData *) md;
874 hdr = GNUNET_malloc (left + sizeof (struct MetaDataHeader));
875 hdr->size = htonl (left);
876 hdr->entries = htonl (md->item_count);
877 if (GNUNET_YES == comp)
878 {
879 GNUNET_assert (clen < left);
880 hdr->version = htonl (2 | HEADER_COMPRESSED);
881 memcpy (&hdr[1], cdata, clen);
882 vmd->sbuf_size = clen + sizeof (struct MetaDataHeader);
883 }
884 else
885 {
886 hdr->version = htonl (2);
887 memcpy (&hdr[1], &ent[0], left);
888 vmd->sbuf_size = left + sizeof (struct MetaDataHeader);
889 }
890 vmd->sbuf = (char *) hdr;
891 }
892
893 if (((left + sizeof (struct MetaDataHeader)) <= max) ||
894 ((comp == GNUNET_YES) && (clen <= max)))
895 {
896 /* success, this now fits! */
897 if (GNUNET_YES == comp)
898 {
899 if (dst == NULL)
900 dst = GNUNET_malloc (clen + sizeof (struct MetaDataHeader));
901 hdr = (struct MetaDataHeader *) dst;
902 hdr->version = htonl (2 | HEADER_COMPRESSED);
903 hdr->size = htonl (left);
904 hdr->entries = htonl (md->item_count - i);
905 memcpy (&dst[sizeof (struct MetaDataHeader)], cdata, clen);
906 GNUNET_free (cdata);
907 GNUNET_free (ent);
908 rlen = clen + sizeof (struct MetaDataHeader);
909 }
910 else
911 {
912 if (dst == NULL)
913 dst = GNUNET_malloc (left + sizeof (struct MetaDataHeader));
914 hdr = (struct MetaDataHeader *) dst;
915 hdr->version = htonl (2);
916 hdr->entries = htonl (md->item_count - i);
917 hdr->size = htonl (left);
918 memcpy (&dst[sizeof (struct MetaDataHeader)], &ent[i], left);
919 GNUNET_free (ent);
920 rlen = left + sizeof (struct MetaDataHeader);
921 }
922 if (NULL != *target)
923 {
924 memcpy (*target, dst, clen + sizeof (struct MetaDataHeader));
925 GNUNET_free (dst);
926 }
927 else
928 {
929 *target = dst;
930 }
931 return rlen;
932 }
933
934 if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_PART))
865 { 935 {
866 comp = GNUNET_NO; 936 /* does not fit! */
867 if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS)) 937 GNUNET_free (ent);
868 comp = try_compression ((const char *) &ent[i], left, &cdata, &clen); 938 return GNUNET_SYSERR;
869
870 if ((md->sbuf == NULL) && (i == 0))
871 {
872 /* fill 'sbuf'; this "modifies" md, but since this is only
873 * an internal cache we will cast away the 'const' instead
874 * of making the API look strange. */
875 vmd = (struct GNUNET_CONTAINER_MetaData *) md;
876 hdr = GNUNET_malloc (left + sizeof (struct MetaDataHeader));
877 hdr->size = htonl (left);
878 hdr->entries = htonl (md->item_count);
879 if (GNUNET_YES == comp)
880 {
881 GNUNET_assert (clen < left);
882 hdr->version = htonl (2 | HEADER_COMPRESSED);
883 memcpy (&hdr[1], cdata, clen);
884 vmd->sbuf_size = clen + sizeof (struct MetaDataHeader);
885 }
886 else
887 {
888 hdr->version = htonl (2);
889 memcpy (&hdr[1], &ent[0], left);
890 vmd->sbuf_size = left + sizeof (struct MetaDataHeader);
891 }
892 vmd->sbuf = (char *) hdr;
893 }
894
895 if (((left + sizeof (struct MetaDataHeader)) <= max) ||
896 ((comp == GNUNET_YES) && (clen <= max)))
897 {
898 /* success, this now fits! */
899 if (GNUNET_YES == comp)
900 {
901 if (dst == NULL)
902 dst = GNUNET_malloc (clen + sizeof (struct MetaDataHeader));
903 hdr = (struct MetaDataHeader *) dst;
904 hdr->version = htonl (2 | HEADER_COMPRESSED);
905 hdr->size = htonl (left);
906 hdr->entries = htonl (md->item_count - i);
907 memcpy (&dst[sizeof (struct MetaDataHeader)], cdata, clen);
908 GNUNET_free (cdata);
909 GNUNET_free (ent);
910 rlen = clen + sizeof (struct MetaDataHeader);
911 }
912 else
913 {
914 if (dst == NULL)
915 dst = GNUNET_malloc (left + sizeof (struct MetaDataHeader));
916 hdr = (struct MetaDataHeader *) dst;
917 hdr->version = htonl (2);
918 hdr->entries = htonl (md->item_count - i);
919 hdr->size = htonl (left);
920 memcpy (&dst[sizeof (struct MetaDataHeader)], &ent[i], left);
921 GNUNET_free (ent);
922 rlen = left + sizeof (struct MetaDataHeader);
923 }
924 if (NULL != *target)
925 {
926 memcpy (*target, dst, clen + sizeof (struct MetaDataHeader));
927 GNUNET_free (dst);
928 }
929 else
930 {
931 *target = dst;
932 }
933 return rlen;
934 }
935
936 if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_PART))
937 {
938 /* does not fit! */
939 GNUNET_free (ent);
940 return GNUNET_SYSERR;
941 }
942
943 /* next iteration: ignore the corresponding meta data at the
944 * end and try again without it */
945 left -= sizeof (struct MetaDataEntry);
946 left -= pos->data_size;
947 if (pos->plugin_name != NULL)
948 left -= strlen (pos->plugin_name) + 1;
949 if (pos->mime_type != NULL)
950 left -= strlen (pos->mime_type) + 1;
951 pos = pos->next;
952 i++;
953 } 939 }
940
941 /* next iteration: ignore the corresponding meta data at the
942 * end and try again without it */
943 left -= sizeof (struct MetaDataEntry);
944 left -= pos->data_size;
945 if (pos->plugin_name != NULL)
946 left -= strlen (pos->plugin_name) + 1;
947 if (pos->mime_type != NULL)
948 left -= strlen (pos->mime_type) + 1;
949 pos = pos->next;
950 i++;
951 }
954 GNUNET_free (ent); 952 GNUNET_free (ent);
955 953
956 /* nothing fit, only write header! */ 954 /* nothing fit, only write header! */
@@ -972,7 +970,7 @@ GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData
972 */ 970 */
973ssize_t 971ssize_t
974GNUNET_CONTAINER_meta_data_get_serialized_size (const struct 972GNUNET_CONTAINER_meta_data_get_serialized_size (const struct
975 GNUNET_CONTAINER_MetaData *md) 973 GNUNET_CONTAINER_MetaData *md)
976{ 974{
977 ssize_t ret; 975 ssize_t ret;
978 char *ptr; 976 char *ptr;
@@ -981,8 +979,8 @@ GNUNET_CONTAINER_meta_data_get_serialized_size (const struct
981 return md->sbuf_size; 979 return md->sbuf_size;
982 ptr = NULL; 980 ptr = NULL;
983 ret = 981 ret =
984 GNUNET_CONTAINER_meta_data_serialize (md, &ptr, GNUNET_MAX_MALLOC_CHECKED, 982 GNUNET_CONTAINER_meta_data_serialize (md, &ptr, GNUNET_MAX_MALLOC_CHECKED,
985 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL); 983 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL);
986 if (ret != -1) 984 if (ret != -1)
987 GNUNET_free (ptr); 985 GNUNET_free (ptr);
988 return ret; 986 return ret;
@@ -1009,14 +1007,14 @@ decompress (const char *input, size_t inputSize, size_t outputSize)
1009 output = GNUNET_malloc (olen); 1007 output = GNUNET_malloc (olen);
1010 if (Z_OK == 1008 if (Z_OK ==
1011 uncompress ((Bytef *) output, &olen, (const Bytef *) input, inputSize)) 1009 uncompress ((Bytef *) output, &olen, (const Bytef *) input, inputSize))
1012 { 1010 {
1013 return output; 1011 return output;
1014 } 1012 }
1015 else 1013 else
1016 { 1014 {
1017 GNUNET_free (output); 1015 GNUNET_free (output);
1018 return NULL; 1016 return NULL;
1019 } 1017 }
1020} 1018}
1021 1019
1022 1020
@@ -1058,121 +1056,121 @@ GNUNET_CONTAINER_meta_data_deserialize (const char *input, size_t size)
1058 compressed = (ntohl (hdr.version) & HEADER_COMPRESSED) != 0; 1056 compressed = (ntohl (hdr.version) & HEADER_COMPRESSED) != 0;
1059 1057
1060 if (version == 1) 1058 if (version == 1)
1061 return NULL; /* null pointer */ 1059 return NULL; /* null pointer */
1062 if (version != 2) 1060 if (version != 2)
1063 { 1061 {
1064 GNUNET_break_op (0); /* unsupported version */ 1062 GNUNET_break_op (0); /* unsupported version */
1065 return NULL; 1063 return NULL;
1066 } 1064 }
1067 1065
1068 ic = ntohl (hdr.entries); 1066 ic = ntohl (hdr.entries);
1069 dataSize = ntohl (hdr.size); 1067 dataSize = ntohl (hdr.size);
1070 if ((sizeof (struct MetaDataEntry) * ic) > dataSize) 1068 if ((sizeof (struct MetaDataEntry) * ic) > dataSize)
1069 {
1070 GNUNET_break_op (0);
1071 return NULL;
1072 }
1073
1074 if (compressed)
1075 {
1076 if (dataSize >= GNUNET_MAX_MALLOC_CHECKED)
1071 { 1077 {
1078 /* make sure we don't blow our memory limit because of a mal-formed
1079 * message... */
1072 GNUNET_break_op (0); 1080 GNUNET_break_op (0);
1073 return NULL; 1081 return NULL;
1074 } 1082 }
1075 1083 data =
1076 if (compressed) 1084 decompress ((const char *) &input[sizeof (struct MetaDataHeader)],
1085 size - sizeof (struct MetaDataHeader), dataSize);
1086 if (data == NULL)
1077 { 1087 {
1078 if (dataSize >= GNUNET_MAX_MALLOC_CHECKED) 1088 GNUNET_break_op (0);
1079 { 1089 return NULL;
1080 /* make sure we don't blow our memory limit because of a mal-formed
1081 * message... */
1082 GNUNET_break_op (0);
1083 return NULL;
1084 }
1085 data =
1086 decompress ((const char *) &input[sizeof (struct MetaDataHeader)],
1087 size - sizeof (struct MetaDataHeader), dataSize);
1088 if (data == NULL)
1089 {
1090 GNUNET_break_op (0);
1091 return NULL;
1092 }
1093 cdata = data;
1094 } 1090 }
1091 cdata = data;
1092 }
1095 else 1093 else
1094 {
1095 data = NULL;
1096 cdata = (const char *) &input[sizeof (struct MetaDataHeader)];
1097 if (dataSize != size - sizeof (struct MetaDataHeader))
1096 { 1098 {
1097 data = NULL; 1099 GNUNET_break_op (0);
1098 cdata = (const char *) &input[sizeof (struct MetaDataHeader)]; 1100 return NULL;
1099 if (dataSize != size - sizeof (struct MetaDataHeader))
1100 {
1101 GNUNET_break_op (0);
1102 return NULL;
1103 }
1104 } 1101 }
1102 }
1105 1103
1106 md = GNUNET_CONTAINER_meta_data_create (); 1104 md = GNUNET_CONTAINER_meta_data_create ();
1107 left = dataSize - ic * sizeof (struct MetaDataEntry); 1105 left = dataSize - ic * sizeof (struct MetaDataEntry);
1108 mdata = &cdata[ic * sizeof (struct MetaDataEntry)]; 1106 mdata = &cdata[ic * sizeof (struct MetaDataEntry)];
1109 for (i = 0; i < ic; i++) 1107 for (i = 0; i < ic; i++)
1108 {
1109 memcpy (&ent, &cdata[i * sizeof (struct MetaDataEntry)],
1110 sizeof (struct MetaDataEntry));
1111 format = (enum EXTRACTOR_MetaFormat) ntohl (ent.format);
1112 if ((format != EXTRACTOR_METAFORMAT_UTF8) &&
1113 (format != EXTRACTOR_METAFORMAT_C_STRING) &&
1114 (format != EXTRACTOR_METAFORMAT_BINARY))
1110 { 1115 {
1111 memcpy (&ent, &cdata[i * sizeof (struct MetaDataEntry)], 1116 GNUNET_break_op (0);
1112 sizeof (struct MetaDataEntry)); 1117 break;
1113 format = (enum EXTRACTOR_MetaFormat) ntohl (ent.format); 1118 }
1114 if ((format != EXTRACTOR_METAFORMAT_UTF8) && 1119 dlen = ntohl (ent.data_size);
1115 (format != EXTRACTOR_METAFORMAT_C_STRING) && 1120 plen = ntohl (ent.plugin_name_len);
1116 (format != EXTRACTOR_METAFORMAT_BINARY)) 1121 mlen = ntohl (ent.mime_type_len);
1117 { 1122 if (dlen > left)
1118 GNUNET_break_op (0); 1123 {
1119 break; 1124 GNUNET_break_op (0);
1120 } 1125 break;
1121 dlen = ntohl (ent.data_size); 1126 }
1122 plen = ntohl (ent.plugin_name_len); 1127 left -= dlen;
1123 mlen = ntohl (ent.mime_type_len); 1128 meta_data = &mdata[left];
1124 if (dlen > left) 1129 if ((format == EXTRACTOR_METAFORMAT_UTF8) ||
1125 { 1130 (format == EXTRACTOR_METAFORMAT_C_STRING))
1126 GNUNET_break_op (0); 1131 {
1127 break; 1132 if ((dlen == 0) || (mdata[left + dlen - 1] != '\0'))
1128 } 1133 {
1129 left -= dlen; 1134 GNUNET_break_op (0);
1130 meta_data = &mdata[left]; 1135 break;
1131 if ((format == EXTRACTOR_METAFORMAT_UTF8) || 1136 }
1132 (format == EXTRACTOR_METAFORMAT_C_STRING)) 1137 }
1133 { 1138 if (plen > left)
1134 if ((dlen == 0) || (mdata[left + dlen - 1] != '\0')) 1139 {
1135 { 1140 GNUNET_break_op (0);
1136 GNUNET_break_op (0); 1141 break;
1137 break; 1142 }
1138 } 1143 left -= plen;
1139 } 1144 if ((plen > 0) && (mdata[left + plen - 1] != '\0'))
1140 if (plen > left) 1145 {
1141 { 1146 GNUNET_break_op (0);
1142 GNUNET_break_op (0); 1147 break;
1143 break; 1148 }
1144 } 1149 if (plen == 0)
1145 left -= plen; 1150 plugin_name = NULL;
1146 if ((plen > 0) && (mdata[left + plen - 1] != '\0')) 1151 else
1147 { 1152 plugin_name = &mdata[left];
1148 GNUNET_break_op (0); 1153
1149 break; 1154 if (mlen > left)
1150 } 1155 {
1151 if (plen == 0) 1156 GNUNET_break_op (0);
1152 plugin_name = NULL; 1157 break;
1153 else 1158 }
1154 plugin_name = &mdata[left]; 1159 left -= mlen;
1155 1160 if ((mlen > 0) && (mdata[left + mlen - 1] != '\0'))
1156 if (mlen > left) 1161 {
1157 { 1162 GNUNET_break_op (0);
1158 GNUNET_break_op (0); 1163 break;
1159 break;
1160 }
1161 left -= mlen;
1162 if ((mlen > 0) && (mdata[left + mlen - 1] != '\0'))
1163 {
1164 GNUNET_break_op (0);
1165 break;
1166 }
1167 if (mlen == 0)
1168 mime_type = NULL;
1169 else
1170 mime_type = &mdata[left];
1171 GNUNET_CONTAINER_meta_data_insert (md, plugin_name,
1172 (enum EXTRACTOR_MetaType)
1173 ntohl (ent.type), format, mime_type,
1174 meta_data, dlen);
1175 } 1164 }
1165 if (mlen == 0)
1166 mime_type = NULL;
1167 else
1168 mime_type = &mdata[left];
1169 GNUNET_CONTAINER_meta_data_insert (md, plugin_name,
1170 (enum EXTRACTOR_MetaType)
1171 ntohl (ent.type), format, mime_type,
1172 meta_data, dlen);
1173 }
1176 GNUNET_free_non_null (data); 1174 GNUNET_free_non_null (data);
1177 return md; 1175 return md;
1178} 1176}
diff --git a/src/util/container_multihashmap.c b/src/util/container_multihashmap.c
index 60d4a43d5..7e53a6440 100644
--- a/src/util/container_multihashmap.c
+++ b/src/util/container_multihashmap.c
@@ -103,19 +103,19 @@ GNUNET_CONTAINER_multihashmap_create (unsigned int len)
103 */ 103 */
104void 104void
105GNUNET_CONTAINER_multihashmap_destroy (struct GNUNET_CONTAINER_MultiHashMap 105GNUNET_CONTAINER_multihashmap_destroy (struct GNUNET_CONTAINER_MultiHashMap
106 *map) 106 *map)
107{ 107{
108 unsigned int i; 108 unsigned int i;
109 struct MapEntry *e; 109 struct MapEntry *e;
110 110
111 for (i = 0; i < map->map_length; i++) 111 for (i = 0; i < map->map_length; i++)
112 {
113 while (NULL != (e = map->map[i]))
112 { 114 {
113 while (NULL != (e = map->map[i])) 115 map->map[i] = e->next;
114 { 116 GNUNET_free (e);
115 map->map[i] = e->next;
116 GNUNET_free (e);
117 }
118 } 117 }
118 }
119 GNUNET_free (map->map); 119 GNUNET_free (map->map);
120 GNUNET_free (map); 120 GNUNET_free (map);
121} 121}
@@ -130,7 +130,7 @@ GNUNET_CONTAINER_multihashmap_destroy (struct GNUNET_CONTAINER_MultiHashMap
130 */ 130 */
131static unsigned int 131static unsigned int
132idx_of (const struct GNUNET_CONTAINER_MultiHashMap *m, 132idx_of (const struct GNUNET_CONTAINER_MultiHashMap *m,
133 const GNUNET_HashCode * key) 133 const GNUNET_HashCode * key)
134{ 134{
135 GNUNET_assert (m != NULL); 135 GNUNET_assert (m != NULL);
136 return (*(unsigned int *) key) % m->map_length; 136 return (*(unsigned int *) key) % m->map_length;
@@ -145,7 +145,7 @@ idx_of (const struct GNUNET_CONTAINER_MultiHashMap *m,
145 */ 145 */
146unsigned int 146unsigned int
147GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap 147GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap
148 *map) 148 *map)
149{ 149{
150 return map->size; 150 return map->size;
151} 151}
@@ -163,17 +163,17 @@ GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap
163 */ 163 */
164void * 164void *
165GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap 165GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap
166 *map, const GNUNET_HashCode * key) 166 *map, const GNUNET_HashCode * key)
167{ 167{
168 struct MapEntry *e; 168 struct MapEntry *e;
169 169
170 e = map->map[idx_of (map, key)]; 170 e = map->map[idx_of (map, key)];
171 while (e != NULL) 171 while (e != NULL)
172 { 172 {
173 if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) 173 if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode)))
174 return e->value; 174 return e->value;
175 e = e->next; 175 e = e->next;
176 } 176 }
177 return NULL; 177 return NULL;
178} 178}
179 179
@@ -189,9 +189,9 @@ GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap
189 */ 189 */
190int 190int
191GNUNET_CONTAINER_multihashmap_iterate (const struct 191GNUNET_CONTAINER_multihashmap_iterate (const struct
192 GNUNET_CONTAINER_MultiHashMap *map, 192 GNUNET_CONTAINER_MultiHashMap *map,
193 GNUNET_CONTAINER_HashMapIterator it, 193 GNUNET_CONTAINER_HashMapIterator it,
194 void *it_cls) 194 void *it_cls)
195{ 195{
196 int count; 196 int count;
197 unsigned int i; 197 unsigned int i;
@@ -202,20 +202,20 @@ GNUNET_CONTAINER_multihashmap_iterate (const struct
202 count = 0; 202 count = 0;
203 GNUNET_assert (map != NULL); 203 GNUNET_assert (map != NULL);
204 for (i = 0; i < map->map_length; i++) 204 for (i = 0; i < map->map_length; i++)
205 {
206 n = map->map[i];
207 while (NULL != (e = n))
205 { 208 {
206 n = map->map[i]; 209 n = e->next;
207 while (NULL != (e = n)) 210 if (NULL != it)
208 { 211 {
209 n = e->next; 212 kc = e->key;
210 if (NULL != it) 213 if (GNUNET_OK != it (it_cls, &kc, e->value))
211 { 214 return GNUNET_SYSERR;
212 kc = e->key; 215 }
213 if (GNUNET_OK != it (it_cls, &kc, e->value)) 216 count++;
214 return GNUNET_SYSERR;
215 }
216 count++;
217 }
218 } 217 }
218 }
219 return count; 219 return count;
220} 220}
221 221
@@ -232,9 +232,8 @@ GNUNET_CONTAINER_multihashmap_iterate (const struct
232 * is not in the map 232 * is not in the map
233 */ 233 */
234int 234int
235GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap 235GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map,
236 *map, const GNUNET_HashCode * key, 236 const GNUNET_HashCode * key, void *value)
237 void *value)
238{ 237{
239 struct MapEntry *e; 238 struct MapEntry *e;
240 struct MapEntry *p; 239 struct MapEntry *p;
@@ -244,21 +243,21 @@ GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap
244 p = NULL; 243 p = NULL;
245 e = map->map[i]; 244 e = map->map[i];
246 while (e != NULL) 245 while (e != NULL)
246 {
247 if ((0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) &&
248 (value == e->value))
247 { 249 {
248 if ((0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) && 250 if (p == NULL)
249 (value == e->value)) 251 map->map[i] = e->next;
250 { 252 else
251 if (p == NULL) 253 p->next = e->next;
252 map->map[i] = e->next; 254 GNUNET_free (e);
253 else 255 map->size--;
254 p->next = e->next; 256 return GNUNET_YES;
255 GNUNET_free (e);
256 map->size--;
257 return GNUNET_YES;
258 }
259 p = e;
260 e = e->next;
261 } 257 }
258 p = e;
259 e = e->next;
260 }
262 return GNUNET_NO; 261 return GNUNET_NO;
263} 262}
264 263
@@ -273,7 +272,7 @@ GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap
273 */ 272 */
274int 273int
275GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap 274GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap
276 *map, const GNUNET_HashCode * key) 275 *map, const GNUNET_HashCode * key)
277{ 276{
278 struct MapEntry *e; 277 struct MapEntry *e;
279 struct MapEntry *p; 278 struct MapEntry *p;
@@ -285,27 +284,27 @@ GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap
285 p = NULL; 284 p = NULL;
286 e = map->map[i]; 285 e = map->map[i];
287 while (e != NULL) 286 while (e != NULL)
287 {
288 if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode)))
288 { 289 {
289 if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) 290 if (p == NULL)
290 { 291 map->map[i] = e->next;
291 if (p == NULL)
292 map->map[i] = e->next;
293 else
294 p->next = e->next;
295 GNUNET_free (e);
296 map->size--;
297 if (p == NULL)
298 e = map->map[i];
299 else
300 e = p->next;
301 ret++;
302 }
303 else 292 else
304 { 293 p->next = e->next;
305 p = e; 294 GNUNET_free (e);
306 e = e->next; 295 map->size--;
307 } 296 if (p == NULL)
297 e = map->map[i];
298 else
299 e = p->next;
300 ret++;
301 }
302 else
303 {
304 p = e;
305 e = e->next;
308 } 306 }
307 }
309 return ret; 308 return ret;
310} 309}
311 310
@@ -321,18 +320,18 @@ GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap
321 */ 320 */
322int 321int
323GNUNET_CONTAINER_multihashmap_contains (const struct 322GNUNET_CONTAINER_multihashmap_contains (const struct
324 GNUNET_CONTAINER_MultiHashMap *map, 323 GNUNET_CONTAINER_MultiHashMap *map,
325 const GNUNET_HashCode * key) 324 const GNUNET_HashCode * key)
326{ 325{
327 struct MapEntry *e; 326 struct MapEntry *e;
328 327
329 e = map->map[idx_of (map, key)]; 328 e = map->map[idx_of (map, key)];
330 while (e != NULL) 329 while (e != NULL)
331 { 330 {
332 if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) 331 if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode)))
333 return GNUNET_YES; 332 return GNUNET_YES;
334 e = e->next; 333 e = e->next;
335 } 334 }
336 return GNUNET_NO; 335 return GNUNET_NO;
337} 336}
338 337
@@ -349,21 +348,20 @@ GNUNET_CONTAINER_multihashmap_contains (const struct
349 */ 348 */
350int 349int
351GNUNET_CONTAINER_multihashmap_contains_value (const struct 350GNUNET_CONTAINER_multihashmap_contains_value (const struct
352 GNUNET_CONTAINER_MultiHashMap 351 GNUNET_CONTAINER_MultiHashMap
353 *map, 352 *map, const GNUNET_HashCode * key,
354 const GNUNET_HashCode * key, 353 const void *value)
355 const void *value)
356{ 354{
357 struct MapEntry *e; 355 struct MapEntry *e;
358 356
359 e = map->map[idx_of (map, key)]; 357 e = map->map[idx_of (map, key)];
360 while (e != NULL) 358 while (e != NULL)
361 { 359 {
362 if ((0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) && 360 if ((0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) &&
363 (e->value == value)) 361 (e->value == value))
364 return GNUNET_YES; 362 return GNUNET_YES;
365 e = e->next; 363 e = e->next;
366 } 364 }
367 return GNUNET_NO; 365 return GNUNET_NO;
368} 366}
369 367
@@ -391,15 +389,15 @@ grow (struct GNUNET_CONTAINER_MultiHashMap *map)
391 map->map_length = new_len; 389 map->map_length = new_len;
392 map->map = new_map; 390 map->map = new_map;
393 for (i = 0; i < old_len; i++) 391 for (i = 0; i < old_len; i++)
392 {
393 while (NULL != (e = old_map[i]))
394 { 394 {
395 while (NULL != (e = old_map[i])) 395 old_map[i] = e->next;
396 { 396 idx = idx_of (map, &e->key);
397 old_map[i] = e->next; 397 e->next = new_map[idx];
398 idx = idx_of (map, &e->key); 398 new_map[idx] = e;
399 e->next = new_map[idx];
400 new_map[idx] = e;
401 }
402 } 399 }
400 }
403 GNUNET_free (old_map); 401 GNUNET_free (old_map);
404} 402}
405 403
@@ -418,9 +416,8 @@ grow (struct GNUNET_CONTAINER_MultiHashMap *map)
418 */ 416 */
419int 417int
420GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map, 418GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map,
421 const GNUNET_HashCode * key, void *value, 419 const GNUNET_HashCode * key, void *value,
422 enum GNUNET_CONTAINER_MultiHashMapOption 420 enum GNUNET_CONTAINER_MultiHashMapOption opt)
423 opt)
424{ 421{
425 struct MapEntry *e; 422 struct MapEntry *e;
426 unsigned int i; 423 unsigned int i;
@@ -428,25 +425,25 @@ GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map,
428 i = idx_of (map, key); 425 i = idx_of (map, key);
429 if ((opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE) && 426 if ((opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE) &&
430 (opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) 427 (opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
428 {
429 e = map->map[i];
430 while (e != NULL)
431 { 431 {
432 e = map->map[i]; 432 if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode)))
433 while (e != NULL) 433 {
434 { 434 if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)
435 if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) 435 return GNUNET_SYSERR;
436 { 436 e->value = value;
437 if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) 437 return GNUNET_NO;
438 return GNUNET_SYSERR; 438 }
439 e->value = value; 439 e = e->next;
440 return GNUNET_NO;
441 }
442 e = e->next;
443 }
444 } 440 }
441 }
445 if (map->size / 3 >= map->map_length / 4) 442 if (map->size / 3 >= map->map_length / 4)
446 { 443 {
447 grow (map); 444 grow (map);
448 i = idx_of (map, key); 445 i = idx_of (map, key);
449 } 446 }
450 e = GNUNET_malloc (sizeof (struct MapEntry)); 447 e = GNUNET_malloc (sizeof (struct MapEntry));
451 e->key = *key; 448 e->key = *key;
452 e->value = value; 449 e->value = value;
@@ -469,10 +466,10 @@ GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map,
469 */ 466 */
470int 467int
471GNUNET_CONTAINER_multihashmap_get_multiple (const struct 468GNUNET_CONTAINER_multihashmap_get_multiple (const struct
472 GNUNET_CONTAINER_MultiHashMap 469 GNUNET_CONTAINER_MultiHashMap *map,
473 *map, const GNUNET_HashCode * key, 470 const GNUNET_HashCode * key,
474 GNUNET_CONTAINER_HashMapIterator 471 GNUNET_CONTAINER_HashMapIterator it,
475 it, void *it_cls) 472 void *it_cls)
476{ 473{
477 int count; 474 int count;
478 struct MapEntry *e; 475 struct MapEntry *e;
@@ -481,14 +478,14 @@ GNUNET_CONTAINER_multihashmap_get_multiple (const struct
481 count = 0; 478 count = 0;
482 n = map->map[idx_of (map, key)]; 479 n = map->map[idx_of (map, key)];
483 while (NULL != (e = n)) 480 while (NULL != (e = n))
484 { 481 {
485 n = e->next; 482 n = e->next;
486 if (0 != memcmp (key, &e->key, sizeof (GNUNET_HashCode))) 483 if (0 != memcmp (key, &e->key, sizeof (GNUNET_HashCode)))
487 continue; 484 continue;
488 if ((it != NULL) && (GNUNET_OK != it (it_cls, key, e->value))) 485 if ((it != NULL) && (GNUNET_OK != it (it_cls, key, e->value)))
489 return GNUNET_SYSERR; 486 return GNUNET_SYSERR;
490 count++; 487 count++;
491 } 488 }
492 return count; 489 return count;
493} 490}
494 491
diff --git a/src/util/container_slist.c b/src/util/container_slist.c
index 2704713d4..7b85dc877 100644
--- a/src/util/container_slist.c
+++ b/src/util/container_slist.c
@@ -89,21 +89,21 @@ struct GNUNET_CONTAINER_SList
89 */ 89 */
90static struct GNUNET_CONTAINER_SList_Elem * 90static struct GNUNET_CONTAINER_SList_Elem *
91create_elem (enum GNUNET_CONTAINER_SListDisposition disp, const void *buf, 91create_elem (enum GNUNET_CONTAINER_SListDisposition disp, const void *buf,
92 size_t len) 92 size_t len)
93{ 93{
94 struct GNUNET_CONTAINER_SList_Elem *e; 94 struct GNUNET_CONTAINER_SList_Elem *e;
95 95
96 if (disp == GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT) 96 if (disp == GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT)
97 { 97 {
98 e = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Elem) + len); 98 e = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Elem) + len);
99 memcpy (&e[1], buf, len); 99 memcpy (&e[1], buf, len);
100 e->elem = (void *) &e[1]; 100 e->elem = (void *) &e[1];
101 } 101 }
102 else 102 else
103 { 103 {
104 e = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Elem)); 104 e = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Elem));
105 e->elem = (void *) buf; 105 e->elem = (void *) buf;
106 } 106 }
107 e->disp = disp; 107 e->disp = disp;
108 e->len = len; 108 e->len = len;
109 return e; 109 return e;
@@ -119,8 +119,8 @@ create_elem (enum GNUNET_CONTAINER_SListDisposition disp, const void *buf,
119 */ 119 */
120void 120void
121GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l, 121GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l,
122 enum GNUNET_CONTAINER_SListDisposition disp, 122 enum GNUNET_CONTAINER_SListDisposition disp,
123 const void *buf, size_t len) 123 const void *buf, size_t len)
124{ 124{
125 struct GNUNET_CONTAINER_SList_Elem *e; 125 struct GNUNET_CONTAINER_SList_Elem *e;
126 126
@@ -141,8 +141,8 @@ GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l,
141 */ 141 */
142void 142void
143GNUNET_CONTAINER_slist_add_end (struct GNUNET_CONTAINER_SList *l, 143GNUNET_CONTAINER_slist_add_end (struct GNUNET_CONTAINER_SList *l,
144 enum GNUNET_CONTAINER_SListDisposition disp, 144 enum GNUNET_CONTAINER_SListDisposition disp,
145 const void *buf, size_t len) 145 const void *buf, size_t len)
146{ 146{
147 struct GNUNET_CONTAINER_SList_Elem *e; 147 struct GNUNET_CONTAINER_SList_Elem *e;
148 148
@@ -163,7 +163,7 @@ GNUNET_CONTAINER_slist_add_end (struct GNUNET_CONTAINER_SList *l,
163 */ 163 */
164void 164void
165GNUNET_CONTAINER_slist_append (struct GNUNET_CONTAINER_SList *dst, 165GNUNET_CONTAINER_slist_append (struct GNUNET_CONTAINER_SList *dst,
166 struct GNUNET_CONTAINER_SList *src) 166 struct GNUNET_CONTAINER_SList *src)
167{ 167{
168 struct GNUNET_CONTAINER_SList_Iterator i; 168 struct GNUNET_CONTAINER_SList_Iterator i;
169 169
@@ -171,15 +171,14 @@ GNUNET_CONTAINER_slist_append (struct GNUNET_CONTAINER_SList *dst,
171 GNUNET_CONTAINER_slist_end (&i) != GNUNET_YES; 171 GNUNET_CONTAINER_slist_end (&i) != GNUNET_YES;
172 GNUNET_CONTAINER_slist_next (&i)) 172 GNUNET_CONTAINER_slist_next (&i))
173 173
174 { 174 {
175 GNUNET_CONTAINER_slist_add (dst, 175 GNUNET_CONTAINER_slist_add (dst,
176 (i.elem->disp == 176 (i.elem->disp ==
177 GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC) 177 GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC) ?
178 ? GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC 178 GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC :
179 : 179 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
180 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, 180 i.elem->elem, i.elem->len);
181 i.elem->elem, i.elem->len); 181 }
182 }
183 GNUNET_CONTAINER_slist_iter_destroy (&i); 182 GNUNET_CONTAINER_slist_iter_destroy (&i);
184} 183}
185 184
@@ -236,13 +235,13 @@ GNUNET_CONTAINER_slist_clear (struct GNUNET_CONTAINER_SList *l)
236 235
237 e = l->head; 236 e = l->head;
238 while (e != NULL) 237 while (e != NULL)
239 { 238 {
240 n = e->next; 239 n = e->next;
241 if (e->disp == GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC) 240 if (e->disp == GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC)
242 GNUNET_free (e->elem); 241 GNUNET_free (e->elem);
243 GNUNET_free (e); 242 GNUNET_free (e);
244 e = n; 243 e = n;
245 } 244 }
246 l->head = NULL; 245 l->head = NULL;
247 l->tail = NULL; 246 l->tail = NULL;
248 l->length = 0; 247 l->length = 0;
@@ -258,7 +257,7 @@ GNUNET_CONTAINER_slist_clear (struct GNUNET_CONTAINER_SList *l)
258 */ 257 */
259int 258int
260GNUNET_CONTAINER_slist_contains (const struct GNUNET_CONTAINER_SList *l, 259GNUNET_CONTAINER_slist_contains (const struct GNUNET_CONTAINER_SList *l,
261 const void *buf, size_t len) 260 const void *buf, size_t len)
262{ 261{
263 struct GNUNET_CONTAINER_SList_Elem *e; 262 struct GNUNET_CONTAINER_SList_Elem *e;
264 263
@@ -315,8 +314,8 @@ GNUNET_CONTAINER_slist_erase (struct GNUNET_CONTAINER_SList_Iterator *i)
315 */ 314 */
316void 315void
317GNUNET_CONTAINER_slist_insert (struct GNUNET_CONTAINER_SList_Iterator *before, 316GNUNET_CONTAINER_slist_insert (struct GNUNET_CONTAINER_SList_Iterator *before,
318 enum GNUNET_CONTAINER_SListDisposition disp, 317 enum GNUNET_CONTAINER_SListDisposition disp,
319 const void *buf, size_t len) 318 const void *buf, size_t len)
320{ 319{
321 struct GNUNET_CONTAINER_SList_Elem *e; 320 struct GNUNET_CONTAINER_SList_Elem *e;
322 321
@@ -369,7 +368,7 @@ GNUNET_CONTAINER_slist_end (struct GNUNET_CONTAINER_SList_Iterator *i)
369 */ 368 */
370void * 369void *
371GNUNET_CONTAINER_slist_get (const struct GNUNET_CONTAINER_SList_Iterator *i, 370GNUNET_CONTAINER_slist_get (const struct GNUNET_CONTAINER_SList_Iterator *i,
372 size_t * len) 371 size_t * len)
373{ 372{
374 if (len) 373 if (len)
375 *len = i->elem->len; 374 *len = i->elem->len;
@@ -381,8 +380,7 @@ GNUNET_CONTAINER_slist_get (const struct GNUNET_CONTAINER_SList_Iterator *i,
381 * @param i iterator 380 * @param i iterator
382 */ 381 */
383void 382void
384GNUNET_CONTAINER_slist_iter_destroy (struct GNUNET_CONTAINER_SList_Iterator 383GNUNET_CONTAINER_slist_iter_destroy (struct GNUNET_CONTAINER_SList_Iterator *i)
385 *i)
386{ 384{
387} 385}
388 386
diff --git a/src/util/crypto_aes.c b/src/util/crypto_aes.c
index 9e194094c..8b031f367 100644
--- a/src/util/crypto_aes.c
+++ b/src/util/crypto_aes.c
@@ -39,9 +39,9 @@ void
39GNUNET_CRYPTO_aes_create_session_key (struct GNUNET_CRYPTO_AesSessionKey *key) 39GNUNET_CRYPTO_aes_create_session_key (struct GNUNET_CRYPTO_AesSessionKey *key)
40{ 40{
41 gcry_randomize (&key->key[0], GNUNET_CRYPTO_AES_KEY_LENGTH, 41 gcry_randomize (&key->key[0], GNUNET_CRYPTO_AES_KEY_LENGTH,
42 GCRY_STRONG_RANDOM); 42 GCRY_STRONG_RANDOM);
43 key->crc32 = 43 key->crc32 =
44 htonl (GNUNET_CRYPTO_crc32_n (key, GNUNET_CRYPTO_AES_KEY_LENGTH)); 44 htonl (GNUNET_CRYPTO_crc32_n (key, GNUNET_CRYPTO_AES_KEY_LENGTH));
45} 45}
46 46
47/** 47/**
@@ -51,7 +51,7 @@ GNUNET_CRYPTO_aes_create_session_key (struct GNUNET_CRYPTO_AesSessionKey *key)
51 */ 51 */
52int 52int
53GNUNET_CRYPTO_aes_check_session_key (const struct GNUNET_CRYPTO_AesSessionKey 53GNUNET_CRYPTO_aes_check_session_key (const struct GNUNET_CRYPTO_AesSessionKey
54 *key) 54 *key)
55{ 55{
56 uint32_t crc; 56 uint32_t crc;
57 57
@@ -76,29 +76,28 @@ GNUNET_CRYPTO_aes_check_session_key (const struct GNUNET_CRYPTO_AesSessionKey
76 */ 76 */
77ssize_t 77ssize_t
78GNUNET_CRYPTO_aes_encrypt (const void *block, size_t len, 78GNUNET_CRYPTO_aes_encrypt (const void *block, size_t len,
79 const struct GNUNET_CRYPTO_AesSessionKey * 79 const struct GNUNET_CRYPTO_AesSessionKey *
80 sessionkey, 80 sessionkey,
81 const struct GNUNET_CRYPTO_AesInitializationVector 81 const struct GNUNET_CRYPTO_AesInitializationVector *
82 * iv, void *result) 82 iv, void *result)
83{ 83{
84 gcry_cipher_hd_t handle; 84 gcry_cipher_hd_t handle;
85 int rc; 85 int rc;
86 86
87 if (sessionkey->crc32 != 87 if (sessionkey->crc32 !=
88 htonl (GNUNET_CRYPTO_crc32_n 88 htonl (GNUNET_CRYPTO_crc32_n (sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH)))
89 (sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH))) 89 {
90 { 90 GNUNET_break (0);
91 GNUNET_break (0); 91 return -1;
92 return -1; 92 }
93 }
94 GNUNET_assert (0 == 93 GNUNET_assert (0 ==
95 gcry_cipher_open (&handle, GCRY_CIPHER_AES256, 94 gcry_cipher_open (&handle, GCRY_CIPHER_AES256,
96 GCRY_CIPHER_MODE_CFB, 0)); 95 GCRY_CIPHER_MODE_CFB, 0));
97 rc = gcry_cipher_setkey (handle, sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH); 96 rc = gcry_cipher_setkey (handle, sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH);
98 GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); 97 GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
99 rc = gcry_cipher_setiv (handle, iv, 98 rc = gcry_cipher_setiv (handle, iv,
100 sizeof (struct 99 sizeof (struct
101 GNUNET_CRYPTO_AesInitializationVector)); 100 GNUNET_CRYPTO_AesInitializationVector));
102 GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); 101 GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
103 GNUNET_assert (0 == gcry_cipher_encrypt (handle, result, len, block, len)); 102 GNUNET_assert (0 == gcry_cipher_encrypt (handle, result, len, block, len));
104 gcry_cipher_close (handle); 103 gcry_cipher_close (handle);
@@ -118,32 +117,30 @@ GNUNET_CRYPTO_aes_encrypt (const void *block, size_t len,
118 */ 117 */
119ssize_t 118ssize_t
120GNUNET_CRYPTO_aes_decrypt (const void *block, size_t size, 119GNUNET_CRYPTO_aes_decrypt (const void *block, size_t size,
121 const struct GNUNET_CRYPTO_AesSessionKey * 120 const struct GNUNET_CRYPTO_AesSessionKey *
122 sessionkey, 121 sessionkey,
123 const struct GNUNET_CRYPTO_AesInitializationVector 122 const struct GNUNET_CRYPTO_AesInitializationVector *
124 * iv, void *result) 123 iv, void *result)
125{ 124{
126 gcry_cipher_hd_t handle; 125 gcry_cipher_hd_t handle;
127 int rc; 126 int rc;
128 127
129 if (sessionkey->crc32 != 128 if (sessionkey->crc32 !=
130 htonl (GNUNET_CRYPTO_crc32_n 129 htonl (GNUNET_CRYPTO_crc32_n (sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH)))
131 (sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH))) 130 {
132 { 131 GNUNET_break (0);
133 GNUNET_break (0); 132 return -1;
134 return -1; 133 }
135 }
136 GNUNET_assert (0 == 134 GNUNET_assert (0 ==
137 gcry_cipher_open (&handle, GCRY_CIPHER_AES256, 135 gcry_cipher_open (&handle, GCRY_CIPHER_AES256,
138 GCRY_CIPHER_MODE_CFB, 0)); 136 GCRY_CIPHER_MODE_CFB, 0));
139 rc = gcry_cipher_setkey (handle, sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH); 137 rc = gcry_cipher_setkey (handle, sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH);
140 GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); 138 GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
141 rc = gcry_cipher_setiv (handle, iv, 139 rc = gcry_cipher_setiv (handle, iv,
142 sizeof (struct 140 sizeof (struct
143 GNUNET_CRYPTO_AesInitializationVector)); 141 GNUNET_CRYPTO_AesInitializationVector));
144 GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); 142 GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
145 GNUNET_assert (0 == 143 GNUNET_assert (0 == gcry_cipher_decrypt (handle, result, size, block, size));
146 gcry_cipher_decrypt (handle, result, size, block, size));
147 gcry_cipher_close (handle); 144 gcry_cipher_close (handle);
148 return size; 145 return size;
149} 146}
@@ -158,8 +155,8 @@ GNUNET_CRYPTO_aes_decrypt (const void *block, size_t size,
158 */ 155 */
159void 156void
160GNUNET_CRYPTO_aes_derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv, 157GNUNET_CRYPTO_aes_derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv,
161 const struct GNUNET_CRYPTO_AesSessionKey *skey, 158 const struct GNUNET_CRYPTO_AesSessionKey *skey,
162 const void *salt, size_t salt_len, ...) 159 const void *salt, size_t salt_len, ...)
163{ 160{
164 va_list argp; 161 va_list argp;
165 162
@@ -177,14 +174,12 @@ GNUNET_CRYPTO_aes_derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv,
177 * @param argp pairs of void * & size_t for context chunks, terminated by NULL 174 * @param argp pairs of void * & size_t for context chunks, terminated by NULL
178 */ 175 */
179void 176void
180GNUNET_CRYPTO_aes_derive_iv_v (struct GNUNET_CRYPTO_AesInitializationVector 177GNUNET_CRYPTO_aes_derive_iv_v (struct GNUNET_CRYPTO_AesInitializationVector *iv,
181 *iv, 178 const struct GNUNET_CRYPTO_AesSessionKey *skey,
182 const struct GNUNET_CRYPTO_AesSessionKey *skey, 179 const void *salt, size_t salt_len, va_list argp)
183 const void *salt, size_t salt_len,
184 va_list argp)
185{ 180{
186 GNUNET_CRYPTO_kdf_v (iv->iv, sizeof (iv->iv), salt, salt_len, skey->key, 181 GNUNET_CRYPTO_kdf_v (iv->iv, sizeof (iv->iv), salt, salt_len, skey->key,
187 sizeof (skey->key), argp); 182 sizeof (skey->key), argp);
188} 183}
189 184
190/* end of crypto_aes.c */ 185/* end of crypto_aes.c */
diff --git a/src/util/crypto_crc.c b/src/util/crypto_crc.c
index 5920ddc93..698d8d450 100644
--- a/src/util/crypto_crc.c
+++ b/src/util/crypto_crc.c
@@ -66,12 +66,12 @@ crc_init ()
66 once = 1; 66 once = 1;
67 crc_table[0] = 0; 67 crc_table[0] = 0;
68 for (i = 128; i; i >>= 1) 68 for (i = 128; i; i >>= 1)
69 { 69 {
70 h = (h >> 1) ^ ((h & 1) ? POLYNOMIAL : 0); 70 h = (h >> 1) ^ ((h & 1) ? POLYNOMIAL : 0);
71 /* h is now crc_table[i] */ 71 /* h is now crc_table[i] */
72 for (j = 0; j < 256; j += 2 * i) 72 for (j = 0; j < 256; j += 2 * i)
73 crc_table[i + j] = crc_table[j] ^ h; 73 crc_table[i + j] = crc_table[j] ^ h;
74 } 74 }
75} 75}
76 76
77/* 77/*
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c
index b8c9a8082..2ab682494 100644
--- a/src/util/crypto_hash.c
+++ b/src/util/crypto_hash.c
@@ -119,14 +119,14 @@ struct GNUNET_CRYPTO_FileHashContext
119 */ 119 */
120static void 120static void
121file_hash_finish (struct GNUNET_CRYPTO_FileHashContext *fhc, 121file_hash_finish (struct GNUNET_CRYPTO_FileHashContext *fhc,
122 const GNUNET_HashCode * res) 122 const GNUNET_HashCode * res)
123{ 123{
124 fhc->callback (fhc->callback_cls, res); 124 fhc->callback (fhc->callback_cls, res);
125 GNUNET_free (fhc->filename); 125 GNUNET_free (fhc->filename);
126 if (!GNUNET_DISK_handle_invalid (fhc->fh)) 126 if (!GNUNET_DISK_handle_invalid (fhc->fh))
127 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fhc->fh)); 127 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fhc->fh));
128 gcry_md_close (fhc->md); 128 gcry_md_close (fhc->md);
129 GNUNET_free (fhc); /* also frees fhc->buffer */ 129 GNUNET_free (fhc); /* also frees fhc->buffer */
130} 130}
131 131
132 132
@@ -149,19 +149,19 @@ file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
149 if (fhc->fsize - fhc->offset < delta) 149 if (fhc->fsize - fhc->offset < delta)
150 delta = fhc->fsize - fhc->offset; 150 delta = fhc->fsize - fhc->offset;
151 if (delta != GNUNET_DISK_file_read (fhc->fh, fhc->buffer, delta)) 151 if (delta != GNUNET_DISK_file_read (fhc->fh, fhc->buffer, delta))
152 { 152 {
153 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", fhc->filename); 153 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", fhc->filename);
154 file_hash_finish (fhc, NULL); 154 file_hash_finish (fhc, NULL);
155 return; 155 return;
156 } 156 }
157 gcry_md_write (fhc->md, fhc->buffer, delta); 157 gcry_md_write (fhc->md, fhc->buffer, delta);
158 fhc->offset += delta; 158 fhc->offset += delta;
159 if (fhc->offset == fhc->fsize) 159 if (fhc->offset == fhc->fsize)
160 { 160 {
161 res = (GNUNET_HashCode *) gcry_md_read (fhc->md, GCRY_MD_SHA512); 161 res = (GNUNET_HashCode *) gcry_md_read (fhc->md, GCRY_MD_SHA512);
162 file_hash_finish (fhc, res); 162 file_hash_finish (fhc, res);
163 return; 163 return;
164 } 164 }
165 fhc->task = GNUNET_SCHEDULER_add_now (&file_hash_task, fhc); 165 fhc->task = GNUNET_SCHEDULER_add_now (&file_hash_task, fhc);
166} 166}
167 167
@@ -178,43 +178,43 @@ file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
178 */ 178 */
179struct GNUNET_CRYPTO_FileHashContext * 179struct GNUNET_CRYPTO_FileHashContext *
180GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority, 180GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority,
181 const char *filename, size_t blocksize, 181 const char *filename, size_t blocksize,
182 GNUNET_CRYPTO_HashCompletedCallback callback, 182 GNUNET_CRYPTO_HashCompletedCallback callback,
183 void *callback_cls) 183 void *callback_cls)
184{ 184{
185 struct GNUNET_CRYPTO_FileHashContext *fhc; 185 struct GNUNET_CRYPTO_FileHashContext *fhc;
186 186
187 GNUNET_assert (blocksize > 0); 187 GNUNET_assert (blocksize > 0);
188 fhc = 188 fhc =
189 GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_FileHashContext) + blocksize); 189 GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_FileHashContext) + blocksize);
190 fhc->callback = callback; 190 fhc->callback = callback;
191 fhc->callback_cls = callback_cls; 191 fhc->callback_cls = callback_cls;
192 fhc->buffer = (unsigned char *) &fhc[1]; 192 fhc->buffer = (unsigned char *) &fhc[1];
193 fhc->filename = GNUNET_strdup (filename); 193 fhc->filename = GNUNET_strdup (filename);
194 if (GPG_ERR_NO_ERROR != gcry_md_open (&fhc->md, GCRY_MD_SHA512, 0)) 194 if (GPG_ERR_NO_ERROR != gcry_md_open (&fhc->md, GCRY_MD_SHA512, 0))
195 { 195 {
196 GNUNET_break (0); 196 GNUNET_break (0);
197 GNUNET_free (fhc); 197 GNUNET_free (fhc);
198 return NULL; 198 return NULL;
199 } 199 }
200 fhc->bsize = blocksize; 200 fhc->bsize = blocksize;
201 if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fhc->fsize, GNUNET_NO)) 201 if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fhc->fsize, GNUNET_NO))
202 { 202 {
203 GNUNET_free (fhc->filename); 203 GNUNET_free (fhc->filename);
204 GNUNET_free (fhc); 204 GNUNET_free (fhc);
205 return NULL; 205 return NULL;
206 } 206 }
207 fhc->fh = 207 fhc->fh =
208 GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, 208 GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ,
209 GNUNET_DISK_PERM_NONE); 209 GNUNET_DISK_PERM_NONE);
210 if (!fhc->fh) 210 if (!fhc->fh)
211 { 211 {
212 GNUNET_free (fhc->filename); 212 GNUNET_free (fhc->filename);
213 GNUNET_free (fhc); 213 GNUNET_free (fhc);
214 return NULL; 214 return NULL;
215 } 215 }
216 fhc->task = 216 fhc->task =
217 GNUNET_SCHEDULER_add_with_priority (priority, &file_hash_task, fhc); 217 GNUNET_SCHEDULER_add_with_priority (priority, &file_hash_task, fhc);
218 return fhc; 218 return fhc;
219} 219}
220 220
@@ -260,7 +260,7 @@ getValue__ (unsigned char a)
260 */ 260 */
261void 261void
262GNUNET_CRYPTO_hash_to_enc (const GNUNET_HashCode * block, 262GNUNET_CRYPTO_hash_to_enc (const GNUNET_HashCode * block,
263 struct GNUNET_CRYPTO_HashAsciiEncoded *result) 263 struct GNUNET_CRYPTO_HashAsciiEncoded *result)
264{ 264{
265 /** 265 /**
266 * 32 characters for encoding (GNUNET_CRYPTO_hash => 32 characters) 266 * 32 characters for encoding (GNUNET_CRYPTO_hash => 32 characters)
@@ -278,23 +278,22 @@ GNUNET_CRYPTO_hash_to_enc (const GNUNET_HashCode * block,
278 rpos = 0; 278 rpos = 0;
279 bits = 0; 279 bits = 0;
280 while ((rpos < sizeof (GNUNET_HashCode)) || (vbit > 0)) 280 while ((rpos < sizeof (GNUNET_HashCode)) || (vbit > 0))
281 {
282 if ((rpos < sizeof (GNUNET_HashCode)) && (vbit < 5))
283 {
284 bits = (bits << 8) | ((unsigned char *) block)[rpos++]; /* eat 8 more bits */
285 vbit += 8;
286 }
287 if (vbit < 5)
281 { 288 {
282 if ((rpos < sizeof (GNUNET_HashCode)) && (vbit < 5)) 289 bits <<= (5 - vbit); /* zero-padding */
283 { 290 GNUNET_assert (vbit == 2); /* padding by 3: 512+3 mod 5 == 0 */
284 bits = (bits << 8) | ((unsigned char *) block)[rpos++]; /* eat 8 more bits */ 291 vbit = 5;
285 vbit += 8;
286 }
287 if (vbit < 5)
288 {
289 bits <<= (5 - vbit); /* zero-padding */
290 GNUNET_assert (vbit == 2); /* padding by 3: 512+3 mod 5 == 0 */
291 vbit = 5;
292 }
293 GNUNET_assert (wpos <
294 sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1);
295 result->encoding[wpos++] = encTable__[(bits >> (vbit - 5)) & 31];
296 vbit -= 5;
297 } 292 }
293 GNUNET_assert (wpos < sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1);
294 result->encoding[wpos++] = encTable__[(bits >> (vbit - 5)) & 31];
295 vbit -= 5;
296 }
298 GNUNET_assert (wpos == sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1); 297 GNUNET_assert (wpos == sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1);
299 GNUNET_assert (vbit == 0); 298 GNUNET_assert (vbit == 0);
300 result->encoding[wpos] = '\0'; 299 result->encoding[wpos] = '\0';
@@ -318,22 +317,22 @@ GNUNET_CRYPTO_hash_from_string (const char *enc, GNUNET_HashCode * result)
318 if (strlen (enc) != sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1) 317 if (strlen (enc) != sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1)
319 return GNUNET_SYSERR; 318 return GNUNET_SYSERR;
320 319
321 vbit = 2; /* padding! */ 320 vbit = 2; /* padding! */
322 wpos = sizeof (GNUNET_HashCode); 321 wpos = sizeof (GNUNET_HashCode);
323 rpos = sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1; 322 rpos = sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1;
324 bits = getValue__ (enc[--rpos]) >> 3; 323 bits = getValue__ (enc[--rpos]) >> 3;
325 while (wpos > 0) 324 while (wpos > 0)
325 {
326 GNUNET_assert (rpos > 0);
327 bits = (getValue__ (enc[--rpos]) << vbit) | bits;
328 vbit += 5;
329 if (vbit >= 8)
326 { 330 {
327 GNUNET_assert (rpos > 0); 331 ((unsigned char *) result)[--wpos] = (unsigned char) bits;
328 bits = (getValue__ (enc[--rpos]) << vbit) | bits; 332 bits >>= 8;
329 vbit += 5; 333 vbit -= 8;
330 if (vbit >= 8)
331 {
332 ((unsigned char *) result)[--wpos] = (unsigned char) bits;
333 bits >>= 8;
334 vbit -= 8;
335 }
336 } 334 }
335 }
337 GNUNET_assert (rpos == 0); 336 GNUNET_assert (rpos == 0);
338 GNUNET_assert (vbit == 0); 337 GNUNET_assert (vbit == 0);
339 return GNUNET_OK; 338 return GNUNET_OK;
@@ -352,7 +351,7 @@ GNUNET_CRYPTO_hash_from_string (const char *enc, GNUNET_HashCode * result)
352 */ 351 */
353unsigned int 352unsigned int
354GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a, 353GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a,
355 const GNUNET_HashCode * b) 354 const GNUNET_HashCode * b)
356{ 355{
357 unsigned int x1 = (a->bits[1] - b->bits[1]) >> 16; 356 unsigned int x1 = (a->bits[1] - b->bits[1]) >> 16;
358 unsigned int x2 = (b->bits[1] - a->bits[1]) >> 16; 357 unsigned int x2 = (b->bits[1] - a->bits[1]) >> 16;
@@ -362,7 +361,7 @@ GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a,
362 361
363void 362void
364GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode, 363GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode,
365 GNUNET_HashCode * result) 364 GNUNET_HashCode * result)
366{ 365{
367 int i; 366 int i;
368 367
@@ -372,37 +371,33 @@ GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode,
372 371
373void 372void
374GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a, 373GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a,
375 const GNUNET_HashCode * b, 374 const GNUNET_HashCode * b,
376 GNUNET_HashCode * result) 375 GNUNET_HashCode * result)
377{ 376{
378 int i; 377 int i;
379 378
380 for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; 379 for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--)
381 i--)
382 result->bits[i] = b->bits[i] - a->bits[i]; 380 result->bits[i] = b->bits[i] - a->bits[i];
383} 381}
384 382
385void 383void
386GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a, 384GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a,
387 const GNUNET_HashCode * delta, 385 const GNUNET_HashCode * delta, GNUNET_HashCode * result)
388 GNUNET_HashCode * result)
389{ 386{
390 int i; 387 int i;
391 388
392 for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; 389 for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--)
393 i--)
394 result->bits[i] = delta->bits[i] + a->bits[i]; 390 result->bits[i] = delta->bits[i] + a->bits[i];
395} 391}
396 392
397 393
398void 394void
399GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, const GNUNET_HashCode * b, 395GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, const GNUNET_HashCode * b,
400 GNUNET_HashCode * result) 396 GNUNET_HashCode * result)
401{ 397{
402 int i; 398 int i;
403 399
404 for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; 400 for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--)
405 i--)
406 result->bits[i] = a->bits[i] ^ b->bits[i]; 401 result->bits[i] = a->bits[i] ^ b->bits[i];
407} 402}
408 403
@@ -412,18 +407,17 @@ GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, const GNUNET_HashCode * b,
412 */ 407 */
413void 408void
414GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc, 409GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc,
415 struct GNUNET_CRYPTO_AesSessionKey *skey, 410 struct GNUNET_CRYPTO_AesSessionKey *skey,
416 struct GNUNET_CRYPTO_AesInitializationVector 411 struct GNUNET_CRYPTO_AesInitializationVector *iv)
417 *iv)
418{ 412{
419 GNUNET_assert (sizeof (GNUNET_HashCode) >= 413 GNUNET_assert (sizeof (GNUNET_HashCode) >=
420 GNUNET_CRYPTO_AES_KEY_LENGTH + 414 GNUNET_CRYPTO_AES_KEY_LENGTH +
421 sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); 415 sizeof (struct GNUNET_CRYPTO_AesInitializationVector));
422 memcpy (skey, hc, GNUNET_CRYPTO_AES_KEY_LENGTH); 416 memcpy (skey, hc, GNUNET_CRYPTO_AES_KEY_LENGTH);
423 skey->crc32 = 417 skey->crc32 =
424 htonl (GNUNET_CRYPTO_crc32_n (skey, GNUNET_CRYPTO_AES_KEY_LENGTH)); 418 htonl (GNUNET_CRYPTO_crc32_n (skey, GNUNET_CRYPTO_AES_KEY_LENGTH));
425 memcpy (iv, &((char *) hc)[GNUNET_CRYPTO_AES_KEY_LENGTH], 419 memcpy (iv, &((char *) hc)[GNUNET_CRYPTO_AES_KEY_LENGTH],
426 sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); 420 sizeof (struct GNUNET_CRYPTO_AesInitializationVector));
427} 421}
428 422
429 423
@@ -454,13 +448,13 @@ GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, unsigned int bit)
454 */ 448 */
455unsigned int 449unsigned int
456GNUNET_CRYPTO_hash_matching_bits (const GNUNET_HashCode * first, 450GNUNET_CRYPTO_hash_matching_bits (const GNUNET_HashCode * first,
457 const GNUNET_HashCode * second) 451 const GNUNET_HashCode * second)
458{ 452{
459 unsigned int i; 453 unsigned int i;
460 454
461 for (i = 0; i < sizeof (GNUNET_HashCode) * 8; i++) 455 for (i = 0; i < sizeof (GNUNET_HashCode) * 8; i++)
462 if (GNUNET_CRYPTO_hash_get_bit (first, i) != 456 if (GNUNET_CRYPTO_hash_get_bit (first, i) !=
463 GNUNET_CRYPTO_hash_get_bit (second, i)) 457 GNUNET_CRYPTO_hash_get_bit (second, i))
464 return i; 458 return i;
465 return sizeof (GNUNET_HashCode) * 8; 459 return sizeof (GNUNET_HashCode) * 8;
466} 460}
@@ -472,8 +466,7 @@ GNUNET_CRYPTO_hash_matching_bits (const GNUNET_HashCode * first,
472 * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2. 466 * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2.
473 */ 467 */
474int 468int
475GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, 469GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, const GNUNET_HashCode * h2)
476 const GNUNET_HashCode * h2)
477{ 470{
478 unsigned int *i1; 471 unsigned int *i1;
479 unsigned int *i2; 472 unsigned int *i2;
@@ -481,14 +474,13 @@ GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1,
481 474
482 i1 = (unsigned int *) h1; 475 i1 = (unsigned int *) h1;
483 i2 = (unsigned int *) h2; 476 i2 = (unsigned int *) h2;
484 for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; 477 for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--)
485 i--) 478 {
486 { 479 if (i1[i] > i2[i])
487 if (i1[i] > i2[i]) 480 return 1;
488 return 1; 481 if (i1[i] < i2[i])
489 if (i1[i] < i2[i]) 482 return -1;
490 return -1; 483 }
491 }
492 return 0; 484 return 0;
493} 485}
494 486
@@ -500,22 +492,22 @@ GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1,
500 */ 492 */
501int 493int
502GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1, 494GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1,
503 const GNUNET_HashCode * h2, 495 const GNUNET_HashCode * h2,
504 const GNUNET_HashCode * target) 496 const GNUNET_HashCode * target)
505{ 497{
506 int i; 498 int i;
507 unsigned int d1; 499 unsigned int d1;
508 unsigned int d2; 500 unsigned int d2;
509 501
510 for (i = sizeof (GNUNET_HashCode) / sizeof (unsigned int) - 1; i >= 0; i--) 502 for (i = sizeof (GNUNET_HashCode) / sizeof (unsigned int) - 1; i >= 0; i--)
511 { 503 {
512 d1 = ((unsigned int *) h1)[i] ^ ((unsigned int *) target)[i]; 504 d1 = ((unsigned int *) h1)[i] ^ ((unsigned int *) target)[i];
513 d2 = ((unsigned int *) h2)[i] ^ ((unsigned int *) target)[i]; 505 d2 = ((unsigned int *) h2)[i] ^ ((unsigned int *) target)[i];
514 if (d1 > d2) 506 if (d1 > d2)
515 return 1; 507 return 1;
516 else if (d1 < d2) 508 else if (d1 < d2)
517 return -1; 509 return -1;
518 } 510 }
519 return 0; 511 return 0;
520} 512}
521 513
@@ -530,8 +522,8 @@ GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1,
530 */ 522 */
531void 523void
532GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key, 524GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key,
533 const struct GNUNET_CRYPTO_AesSessionKey *rkey, 525 const struct GNUNET_CRYPTO_AesSessionKey *rkey,
534 const void *salt, size_t salt_len, ...) 526 const void *salt, size_t salt_len, ...)
535{ 527{
536 va_list argp; 528 va_list argp;
537 529
@@ -551,12 +543,12 @@ GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key,
551 */ 543 */
552void 544void
553GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key, 545GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key,
554 const struct GNUNET_CRYPTO_AesSessionKey 546 const struct GNUNET_CRYPTO_AesSessionKey *rkey,
555 *rkey, const void *salt, size_t salt_len, 547 const void *salt, size_t salt_len,
556 va_list argp) 548 va_list argp)
557{ 549{
558 GNUNET_CRYPTO_kdf_v (key->key, sizeof (key->key), salt, salt_len, rkey->key, 550 GNUNET_CRYPTO_kdf_v (key->key, sizeof (key->key), salt, salt_len, rkey->key,
559 sizeof (rkey->key), argp); 551 sizeof (rkey->key), argp);
560} 552}
561 553
562 554
@@ -570,14 +562,14 @@ GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key,
570 */ 562 */
571void 563void
572GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key, 564GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
573 const void *plaintext, size_t plaintext_len, 565 const void *plaintext, size_t plaintext_len,
574 GNUNET_HashCode * hmac) 566 GNUNET_HashCode * hmac)
575{ 567{
576 gcry_md_hd_t md; 568 gcry_md_hd_t md;
577 const unsigned char *mc; 569 const unsigned char *mc;
578 570
579 GNUNET_assert (GPG_ERR_NO_ERROR == 571 GNUNET_assert (GPG_ERR_NO_ERROR ==
580 gcry_md_open (&md, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC)); 572 gcry_md_open (&md, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC));
581 gcry_md_setkey (md, key->key, sizeof (key->key)); 573 gcry_md_setkey (md, key->key, sizeof (key->key));
582 gcry_md_write (md, plaintext, plaintext_len); 574 gcry_md_write (md, plaintext, plaintext_len);
583 mc = gcry_md_read (md, GCRY_MD_SHA512); 575 mc = gcry_md_read (md, GCRY_MD_SHA512);
diff --git a/src/util/crypto_hkdf.c b/src/util/crypto_hkdf.c
index 6af76ba68..40bfa6774 100644
--- a/src/util/crypto_hkdf.c
+++ b/src/util/crypto_hkdf.c
@@ -74,7 +74,7 @@
74 */ 74 */
75static const void * 75static const void *
76doHMAC (gcry_md_hd_t mac, const void *key, size_t key_len, const void *buf, 76doHMAC (gcry_md_hd_t mac, const void *key, size_t key_len, const void *buf,
77 size_t buf_len) 77 size_t buf_len)
78{ 78{
79 gcry_md_setkey (mac, key, key_len); 79 gcry_md_setkey (mac, key, key_len);
80 gcry_md_write (mac, buf, buf_len); 80 gcry_md_write (mac, buf, buf_len);
@@ -94,7 +94,7 @@ doHMAC (gcry_md_hd_t mac, const void *key, size_t key_len, const void *buf,
94 */ 94 */
95static int 95static int
96getPRK (gcry_md_hd_t mac, const void *xts, size_t xts_len, const void *skm, 96getPRK (gcry_md_hd_t mac, const void *xts, size_t xts_len, const void *skm,
97 size_t skm_len, void *prk) 97 size_t skm_len, void *prk)
98{ 98{
99 const void *ret; 99 const void *ret;
100 100
@@ -115,9 +115,9 @@ dump (const char *src, const void *p, unsigned int l)
115 115
116 printf ("\n%s: ", src); 116 printf ("\n%s: ", src);
117 for (i = 0; i < l; i++) 117 for (i = 0; i < l; i++)
118 { 118 {
119 printf ("%2x", (int) ((const unsigned char *) p)[i]); 119 printf ("%2x", (int) ((const unsigned char *) p)[i]);
120 } 120 }
121 printf ("\n"); 121 printf ("\n");
122} 122}
123#endif 123#endif
@@ -137,9 +137,9 @@ dump (const char *src, const void *p, unsigned int l)
137 * @return GNUNET_YES on success 137 * @return GNUNET_YES on success
138 */ 138 */
139int 139int
140GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, 140GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, int prf_algo,
141 int prf_algo, const void *xts, size_t xts_len, 141 const void *xts, size_t xts_len, const void *skm,
142 const void *skm, size_t skm_len, va_list argp) 142 size_t skm_len, va_list argp)
143{ 143{
144 const void *hc; 144 const void *hc;
145 unsigned long i, t, d; 145 unsigned long i, t, d;
@@ -158,16 +158,16 @@ GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo,
158 return GNUNET_SYSERR; 158 return GNUNET_SYSERR;
159 159
160 if (gcry_md_open (&prf, prf_algo, GCRY_MD_FLAG_HMAC) != GPG_ERR_NO_ERROR) 160 if (gcry_md_open (&prf, prf_algo, GCRY_MD_FLAG_HMAC) != GPG_ERR_NO_ERROR)
161 { 161 {
162 gcry_md_close (xtr); 162 gcry_md_close (xtr);
163 return GNUNET_SYSERR; 163 return GNUNET_SYSERR;
164 } 164 }
165 165
166 va_copy (args, argp); 166 va_copy (args, argp);
167 167
168 ctx_len = 0; 168 ctx_len = 0;
169 while (NULL != va_arg (args, void *)) 169 while (NULL != va_arg (args, void *))
170 ctx_len += va_arg (args, size_t); 170 ctx_len += va_arg (args, size_t);
171 171
172 va_end (args); 172 va_end (args);
173 173
@@ -191,65 +191,65 @@ GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo,
191 dst = plain + k; 191 dst = plain + k;
192 va_copy (args, argp); 192 va_copy (args, argp);
193 while ((ctx = va_arg (args, void *))) 193 while ((ctx = va_arg (args, void *)))
194 { 194 {
195 size_t len; 195 size_t len;
196 196
197 len = va_arg (args, size_t); 197 len = va_arg (args, size_t);
198 memcpy (dst, ctx, len); 198 memcpy (dst, ctx, len);
199 dst += len; 199 dst += len;
200 } 200 }
201 va_end (args); 201 va_end (args);
202 202
203 if (t > 0) 203 if (t > 0)
204 { 204 {
205 memset (plain + k + ctx_len, 1, 1); 205 memset (plain + k + ctx_len, 1, 1);
206#if DEBUG_HKDF 206#if DEBUG_HKDF
207 dump ("K(1)", plain, plain_len); 207 dump ("K(1)", plain, plain_len);
208#endif 208#endif
209 hc = doHMAC (prf, prk, xtr_len, &plain[k], ctx_len + 1); 209 hc = doHMAC (prf, prk, xtr_len, &plain[k], ctx_len + 1);
210 if (hc == NULL) 210 if (hc == NULL)
211 goto hkdf_error; 211 goto hkdf_error;
212 memcpy (result, hc, k); 212 memcpy (result, hc, k);
213 result += k; 213 result += k;
214 } 214 }
215 215
216 /* K(i+1) */ 216 /* K(i+1) */
217 for (i = 1; i < t; i++) 217 for (i = 1; i < t; i++)
218 { 218 {
219 memcpy (plain, result - k, k); 219 memcpy (plain, result - k, k);
220 memset (plain + k + ctx_len, i + 1, 1); 220 memset (plain + k + ctx_len, i + 1, 1);
221 gcry_md_reset (prf); 221 gcry_md_reset (prf);
222#if DEBUG_HKDF 222#if DEBUG_HKDF
223 dump ("K(i+1)", plain, plain_len); 223 dump ("K(i+1)", plain, plain_len);
224#endif 224#endif
225 hc = doHMAC (prf, prk, xtr_len, plain, plain_len); 225 hc = doHMAC (prf, prk, xtr_len, plain, plain_len);
226 if (hc == NULL) 226 if (hc == NULL)
227 goto hkdf_error; 227 goto hkdf_error;
228 memcpy (result, hc, k); 228 memcpy (result, hc, k);
229 result += k; 229 result += k;
230 } 230 }
231 231
232 /* K(t):d */ 232 /* K(t):d */
233 if (d > 0) 233 if (d > 0)
234 {
235 if (t > 0)
234 { 236 {
235 if (t > 0) 237 memcpy (plain, result - k, k);
236 { 238 i++;
237 memcpy (plain, result - k, k); 239 }
238 i++; 240 memset (plain + k + ctx_len, i, 1);
239 } 241 gcry_md_reset (prf);
240 memset (plain + k + ctx_len, i, 1);
241 gcry_md_reset (prf);
242#if DEBUG_HKDF 242#if DEBUG_HKDF
243 dump ("K(t):d", plain, plain_len); 243 dump ("K(t):d", plain, plain_len);
244#endif 244#endif
245 if (t > 0) 245 if (t > 0)
246 hc = doHMAC (prf, prk, xtr_len, plain, plain_len); 246 hc = doHMAC (prf, prk, xtr_len, plain, plain_len);
247 else 247 else
248 hc = doHMAC (prf, prk, xtr_len, plain + k, plain_len - k); 248 hc = doHMAC (prf, prk, xtr_len, plain + k, plain_len - k);
249 if (hc == NULL) 249 if (hc == NULL)
250 goto hkdf_error; 250 goto hkdf_error;
251 memcpy (result, hc, d); 251 memcpy (result, hc, d);
252 } 252 }
253#if DEBUG_HKDF 253#if DEBUG_HKDF
254 dump ("result", result - k, out_len); 254 dump ("result", result - k, out_len);
255#endif 255#endif
@@ -281,16 +281,16 @@ hkdf_ok:
281 */ 281 */
282int 282int
283GNUNET_CRYPTO_hkdf (void *result, size_t out_len, int xtr_algo, int prf_algo, 283GNUNET_CRYPTO_hkdf (void *result, size_t out_len, int xtr_algo, int prf_algo,
284 const void *xts, size_t xts_len, const void *skm, 284 const void *xts, size_t xts_len, const void *skm,
285 size_t skm_len, ...) 285 size_t skm_len, ...)
286{ 286{
287 va_list argp; 287 va_list argp;
288 int ret; 288 int ret;
289 289
290 va_start (argp, skm_len); 290 va_start (argp, skm_len);
291 ret = 291 ret =
292 GNUNET_CRYPTO_hkdf_v (result, out_len, xtr_algo, prf_algo, xts, xts_len, 292 GNUNET_CRYPTO_hkdf_v (result, out_len, xtr_algo, prf_algo, xts, xts_len,
293 skm, skm_len, argp); 293 skm, skm_len, argp);
294 va_end (argp); 294 va_end (argp);
295 295
296 return ret; 296 return ret;
diff --git a/src/util/crypto_kdf.c b/src/util/crypto_kdf.c
index d8fcbd866..0e7fbbbec 100644
--- a/src/util/crypto_kdf.c
+++ b/src/util/crypto_kdf.c
@@ -44,8 +44,8 @@
44 */ 44 */
45int 45int
46GNUNET_CRYPTO_kdf_v (void *result, size_t out_len, const void *xts, 46GNUNET_CRYPTO_kdf_v (void *result, size_t out_len, const void *xts,
47 size_t xts_len, const void *skm, size_t skm_len, 47 size_t xts_len, const void *skm, size_t skm_len,
48 va_list argp) 48 va_list argp)
49{ 49{
50 /* 50 /*
51 * "Finally, we point out to a particularly advantageous instantiation using 51 * "Finally, we point out to a particularly advantageous instantiation using
@@ -59,9 +59,8 @@ GNUNET_CRYPTO_kdf_v (void *result, size_t out_len, const void *xts,
59 * http://eprint.iacr.org/2010/264 59 * http://eprint.iacr.org/2010/264
60 */ 60 */
61 61
62 return GNUNET_CRYPTO_hkdf_v (result, out_len, GCRY_MD_SHA512, 62 return GNUNET_CRYPTO_hkdf_v (result, out_len, GCRY_MD_SHA512, GCRY_MD_SHA256,
63 GCRY_MD_SHA256, xts, xts_len, skm, skm_len, 63 xts, xts_len, skm, skm_len, argp);
64 argp);
65} 64}
66 65
67/** 66/**
@@ -77,14 +76,13 @@ GNUNET_CRYPTO_kdf_v (void *result, size_t out_len, const void *xts,
77 */ 76 */
78int 77int
79GNUNET_CRYPTO_kdf (void *result, size_t out_len, const void *xts, 78GNUNET_CRYPTO_kdf (void *result, size_t out_len, const void *xts,
80 size_t xts_len, const void *skm, size_t skm_len, ...) 79 size_t xts_len, const void *skm, size_t skm_len, ...)
81{ 80{
82 va_list argp; 81 va_list argp;
83 int ret; 82 int ret;
84 83
85 va_start (argp, skm_len); 84 va_start (argp, skm_len);
86 ret = 85 ret = GNUNET_CRYPTO_kdf_v (result, out_len, xts, xts_len, skm, skm_len, argp);
87 GNUNET_CRYPTO_kdf_v (result, out_len, xts, xts_len, skm, skm_len, argp);
88 va_end (argp); 86 va_end (argp);
89 87
90 return ret; 88 return ret;
diff --git a/src/util/crypto_ksk.c b/src/util/crypto_ksk.c
index 3d40ce27b..60639a709 100644
--- a/src/util/crypto_ksk.c
+++ b/src/util/crypto_ksk.c
@@ -51,12 +51,12 @@
51 51
52typedef struct 52typedef struct
53{ 53{
54 gcry_mpi_t n; /* public modulus */ 54 gcry_mpi_t n; /* public modulus */
55 gcry_mpi_t e; /* public exponent */ 55 gcry_mpi_t e; /* public exponent */
56 gcry_mpi_t d; /* exponent */ 56 gcry_mpi_t d; /* exponent */
57 gcry_mpi_t p; /* prime p. */ 57 gcry_mpi_t p; /* prime p. */
58 gcry_mpi_t q; /* prime q. */ 58 gcry_mpi_t q; /* prime q. */
59 gcry_mpi_t u; /* inverse of p mod q. */ 59 gcry_mpi_t u; /* inverse of p mod q. */
60} KBlock_secret_key; 60} KBlock_secret_key;
61 61
62/** 62/**
@@ -84,23 +84,23 @@ mpz_randomize (gcry_mpi_t n, unsigned int nbits, GNUNET_HashCode * rnd)
84 84
85 tmp = *rnd; 85 tmp = *rnd;
86 for (i = 0; i < cnt; i++) 86 for (i = 0; i < cnt; i++)
87 { 87 {
88 int j; 88 int j;
89 89
90 if (i > 0) 90 if (i > 0)
91 GNUNET_CRYPTO_hash (&hc, sizeof (GNUNET_HashCode), &tmp); 91 GNUNET_CRYPTO_hash (&hc, sizeof (GNUNET_HashCode), &tmp);
92 for (j = 0; j < sizeof (GNUNET_HashCode) / sizeof (uint32_t); j++) 92 for (j = 0; j < sizeof (GNUNET_HashCode) / sizeof (uint32_t); j++)
93 { 93 {
94#if HAVE_GCRY_MPI_LSHIFT 94#if HAVE_GCRY_MPI_LSHIFT
95 gcry_mpi_lshift (n, n, sizeof (uint32_t) * 8); 95 gcry_mpi_lshift (n, n, sizeof (uint32_t) * 8);
96#else 96#else
97 gcry_mpi_mul_ui (n, n, 1 << (sizeof (uint32_t) * 4)); 97 gcry_mpi_mul_ui (n, n, 1 << (sizeof (uint32_t) * 4));
98 gcry_mpi_mul_ui (n, n, 1 << (sizeof (uint32_t) * 4)); 98 gcry_mpi_mul_ui (n, n, 1 << (sizeof (uint32_t) * 4));
99#endif 99#endif
100 gcry_mpi_add_ui (n, n, ntohl (((uint32_t *) & tmp)[j])); 100 gcry_mpi_add_ui (n, n, ntohl (((uint32_t *) & tmp)[j]));
101 }
102 hc = tmp;
103 } 101 }
102 hc = tmp;
103 }
104 GNUNET_CRYPTO_hash (&hc, sizeof (GNUNET_HashCode), rnd); 104 GNUNET_CRYPTO_hash (&hc, sizeof (GNUNET_HashCode), rnd);
105 i = gcry_mpi_get_nbits (n); 105 i = gcry_mpi_get_nbits (n);
106 while (i > nbits) 106 while (i > nbits)
@@ -114,10 +114,10 @@ mpz_trailing_zeroes (gcry_mpi_t n)
114 114
115 cnt = gcry_mpi_get_nbits (n); 115 cnt = gcry_mpi_get_nbits (n);
116 for (idx = 0; idx < cnt; idx++) 116 for (idx = 0; idx < cnt; idx++)
117 { 117 {
118 if (gcry_mpi_test_bit (n, idx) == 0) 118 if (gcry_mpi_test_bit (n, idx) == 0)
119 return idx; 119 return idx;
120 } 120 }
121 121
122 return ULONG_MAX; 122 return ULONG_MAX;
123} 123}
@@ -164,31 +164,31 @@ is_prime (gcry_mpi_t n, int steps, GNUNET_HashCode * hc)
164 mpz_tdiv_q_2exp (q, q, k); 164 mpz_tdiv_q_2exp (q, q, k);
165 165
166 for (i = 0; i < steps; i++) 166 for (i = 0; i < steps; i++)
167 {
168 if (!i)
167 { 169 {
168 if (!i) 170 gcry_mpi_set_ui (x, 2);
169 {
170 gcry_mpi_set_ui (x, 2);
171 }
172 else
173 {
174 mpz_randomize (x, nbits - 1, hc);
175 GNUNET_assert (gcry_mpi_cmp (x, nminus1) < 0);
176 GNUNET_assert (gcry_mpi_cmp_ui (x, 1) > 0);
177 }
178 gcry_mpi_powm (y, x, q, n);
179 if (gcry_mpi_cmp_ui (y, 1) && gcry_mpi_cmp (y, nminus1))
180 {
181 for (j = 1; j < k && gcry_mpi_cmp (y, nminus1); j++)
182 {
183 gcry_mpi_powm (y, y, a2, n);
184 if (!gcry_mpi_cmp_ui (y, 1))
185 goto leave; /* Not a prime. */
186 }
187 if (gcry_mpi_cmp (y, nminus1))
188 goto leave; /* Not a prime. */
189 }
190 } 171 }
191 rc = 1; /* May be a prime. */ 172 else
173 {
174 mpz_randomize (x, nbits - 1, hc);
175 GNUNET_assert (gcry_mpi_cmp (x, nminus1) < 0);
176 GNUNET_assert (gcry_mpi_cmp_ui (x, 1) > 0);
177 }
178 gcry_mpi_powm (y, x, q, n);
179 if (gcry_mpi_cmp_ui (y, 1) && gcry_mpi_cmp (y, nminus1))
180 {
181 for (j = 1; j < k && gcry_mpi_cmp (y, nminus1); j++)
182 {
183 gcry_mpi_powm (y, y, a2, n);
184 if (!gcry_mpi_cmp_ui (y, 1))
185 goto leave; /* Not a prime. */
186 }
187 if (gcry_mpi_cmp (y, nminus1))
188 goto leave; /* Not a prime. */
189 }
190 }
191 rc = 1; /* May be a prime. */
192 192
193leave: 193leave:
194 gcry_mpi_release (x); 194 gcry_mpi_release (x);
@@ -210,10 +210,10 @@ static void
210adjust (unsigned char *buf, size_t size, size_t target) 210adjust (unsigned char *buf, size_t size, size_t target)
211{ 211{
212 if (size < target) 212 if (size < target)
213 { 213 {
214 memmove (&buf[target - size], buf, size); 214 memmove (&buf[target - size], buf, size);
215 memset (buf, 0, target - size); 215 memset (buf, 0, target - size);
216 } 216 }
217} 217}
218 218
219 219
@@ -326,70 +326,70 @@ gen_prime (gcry_mpi_t * ptest, unsigned int nbits, GNUNET_HashCode * hc)
326 tmp = gcry_mpi_new (0); 326 tmp = gcry_mpi_new (0);
327 sp = gcry_mpi_new (0); 327 sp = gcry_mpi_new (0);
328 while (1) 328 while (1)
329 {
330 /* generate a random number */
331 mpz_randomize (prime, nbits, hc);
332 /* Set high order bit to 1, set low order bit to 1. If we are
333 * generating a secret prime we are most probably doing that
334 * for RSA, to make sure that the modulus does have the
335 * requested key size we set the 2 high order bits. */
336 gcry_mpi_set_bit (prime, nbits - 1);
337 gcry_mpi_set_bit (prime, nbits - 2);
338 gcry_mpi_set_bit (prime, 0);
339
340 /* Calculate all remainders. */
341 for (i = 0; i < no_of_small_prime_numbers; i++)
329 { 342 {
330 /* generate a random number */ 343 size_t written;
331 mpz_randomize (prime, nbits, hc); 344
332 /* Set high order bit to 1, set low order bit to 1. If we are 345 gcry_mpi_set_ui (sp, small_prime_numbers[i]);
333 * generating a secret prime we are most probably doing that 346 gcry_mpi_div (NULL, tmp, prime, sp, -1);
334 * for RSA, to make sure that the modulus does have the 347 mods[i] = 0;
335 * requested key size we set the 2 high order bits. */ 348 written = sizeof (unsigned int);
336 gcry_mpi_set_bit (prime, nbits - 1); 349 GNUNET_assert (0 ==
337 gcry_mpi_set_bit (prime, nbits - 2); 350 gcry_mpi_print (GCRYMPI_FMT_USG,
338 gcry_mpi_set_bit (prime, 0); 351 (unsigned char *) &mods[i], written,
339 352 &written, tmp));
340 /* Calculate all remainders. */ 353 adjust ((unsigned char *) &mods[i], written, sizeof (unsigned int));
354 mods[i] = ntohl (mods[i]);
355 }
356 /* Now try some primes starting with prime. */
357 for (step = 0; step < 20000; step += 2)
358 {
359 /* Check against all the small primes we have in mods. */
341 for (i = 0; i < no_of_small_prime_numbers; i++) 360 for (i = 0; i < no_of_small_prime_numbers; i++)
342 { 361 {
343 size_t written; 362 uint16_t x = small_prime_numbers[i];
344 363
345 gcry_mpi_set_ui (sp, small_prime_numbers[i]); 364 while (mods[i] + step >= x)
346 gcry_mpi_div (NULL, tmp, prime, sp, -1); 365 mods[i] -= x;
347 mods[i] = 0; 366 if (!(mods[i] + step))
348 written = sizeof (unsigned int); 367 break;
349 GNUNET_assert (0 == 368 }
350 gcry_mpi_print (GCRYMPI_FMT_USG, 369 if (i < no_of_small_prime_numbers)
351 (unsigned char *) &mods[i], written, 370 continue; /* Found a multiple of an already known prime. */
352 &written, tmp)); 371
353 adjust ((unsigned char *) &mods[i], written, sizeof (unsigned int)); 372 gcry_mpi_add_ui (*ptest, prime, step);
354 mods[i] = ntohl (mods[i]); 373 if (!gcry_mpi_test_bit (*ptest, nbits - 2))
355 } 374 break;
356 /* Now try some primes starting with prime. */ 375
357 for (step = 0; step < 20000; step += 2) 376 /* Do a fast Fermat test now. */
358 { 377 gcry_mpi_sub_ui (pminus1, *ptest, 1);
359 /* Check against all the small primes we have in mods. */ 378 gcry_mpi_powm (result, val_2, pminus1, *ptest);
360 for (i = 0; i < no_of_small_prime_numbers; i++) 379 if ((!gcry_mpi_cmp_ui (result, 1)) && (is_prime (*ptest, 5, hc)))
361 { 380 {
362 uint16_t x = small_prime_numbers[i]; 381 /* Got it. */
363 382 gcry_mpi_release (sp);
364 while (mods[i] + step >= x) 383 gcry_mpi_release (tmp);
365 mods[i] -= x; 384 gcry_mpi_release (val_2);
366 if (!(mods[i] + step)) 385 gcry_mpi_release (val_3);
367 break; 386 gcry_mpi_release (result);
368 } 387 gcry_mpi_release (pminus1);
369 if (i < no_of_small_prime_numbers) 388 gcry_mpi_release (prime);
370 continue; /* Found a multiple of an already known prime. */ 389 return;
371 390 }
372 gcry_mpi_add_ui (*ptest, prime, step);
373 if (!gcry_mpi_test_bit (*ptest, nbits - 2))
374 break;
375
376 /* Do a fast Fermat test now. */
377 gcry_mpi_sub_ui (pminus1, *ptest, 1);
378 gcry_mpi_powm (result, val_2, pminus1, *ptest);
379 if ((!gcry_mpi_cmp_ui (result, 1)) && (is_prime (*ptest, 5, hc)))
380 {
381 /* Got it. */
382 gcry_mpi_release (sp);
383 gcry_mpi_release (tmp);
384 gcry_mpi_release (val_2);
385 gcry_mpi_release (val_3);
386 gcry_mpi_release (result);
387 gcry_mpi_release (pminus1);
388 gcry_mpi_release (prime);
389 return;
390 }
391 }
392 } 391 }
392 }
393} 393}
394 394
395/** 395/**
@@ -399,11 +399,11 @@ gen_prime (gcry_mpi_t * ptest, unsigned int nbits, GNUNET_HashCode * hc)
399 * @param hc the HC to use for PRNG (modified!) 399 * @param hc the HC to use for PRNG (modified!)
400 */ 400 */
401static void 401static void
402generate_kblock_key (KBlock_secret_key * sk, unsigned int nbits, 402generate_kblock_key (KBlock_secret_key *sk, unsigned int nbits,
403 GNUNET_HashCode * hc) 403 GNUNET_HashCode * hc)
404{ 404{
405 gcry_mpi_t t1, t2; 405 gcry_mpi_t t1, t2;
406 gcry_mpi_t phi; /* helper: (p-1)(q-1) */ 406 gcry_mpi_t phi; /* helper: (p-1)(q-1) */
407 gcry_mpi_t g; 407 gcry_mpi_t g;
408 gcry_mpi_t f; 408 gcry_mpi_t f;
409 409
@@ -425,36 +425,36 @@ generate_kblock_key (KBlock_secret_key * sk, unsigned int nbits,
425 f = gcry_mpi_new (0); 425 f = gcry_mpi_new (0);
426 426
427 do 427 do
428 {
429 do
428 { 430 {
429 do 431 gcry_mpi_release (sk->p);
430 { 432 gcry_mpi_release (sk->q);
431 gcry_mpi_release (sk->p); 433 gen_prime (&sk->p, nbits / 2, hc);
432 gcry_mpi_release (sk->q); 434 gen_prime (&sk->q, nbits / 2, hc);
433 gen_prime (&sk->p, nbits / 2, hc); 435
434 gen_prime (&sk->q, nbits / 2, hc); 436 if (gcry_mpi_cmp (sk->p, sk->q) > 0) /* p shall be smaller than q (for calc of u) */
435 437 gcry_mpi_swap (sk->p, sk->q);
436 if (gcry_mpi_cmp (sk->p, sk->q) > 0) /* p shall be smaller than q (for calc of u) */ 438 /* calculate the modulus */
437 gcry_mpi_swap (sk->p, sk->q); 439 gcry_mpi_mul (sk->n, sk->p, sk->q);
438 /* calculate the modulus */ 440 }
439 gcry_mpi_mul (sk->n, sk->p, sk->q); 441 while (gcry_mpi_get_nbits (sk->n) != nbits);
440 } 442
441 while (gcry_mpi_get_nbits (sk->n) != nbits); 443 /* calculate Euler totient: phi = (p-1)(q-1) */
442 444 gcry_mpi_sub_ui (t1, sk->p, 1);
443 /* calculate Euler totient: phi = (p-1)(q-1) */ 445 gcry_mpi_sub_ui (t2, sk->q, 1);
444 gcry_mpi_sub_ui (t1, sk->p, 1); 446 gcry_mpi_mul (phi, t1, t2);
445 gcry_mpi_sub_ui (t2, sk->q, 1); 447 gcry_mpi_gcd (g, t1, t2);
446 gcry_mpi_mul (phi, t1, t2); 448 gcry_mpi_div (f, NULL, phi, g, 0);
447 gcry_mpi_gcd (g, t1, t2); 449 while (0 == gcry_mpi_gcd (t1, sk->e, phi))
448 gcry_mpi_div (f, NULL, phi, g, 0); 450 { /* (while gcd is not 1) */
449 while (0 == gcry_mpi_gcd (t1, sk->e, phi)) 451 gcry_mpi_add_ui (sk->e, sk->e, 2);
450 { /* (while gcd is not 1) */
451 gcry_mpi_add_ui (sk->e, sk->e, 2);
452 }
453
454 /* calculate the secret key d = e^1 mod phi */
455 } 452 }
453
454 /* calculate the secret key d = e^1 mod phi */
455 }
456 while ((0 == gcry_mpi_invm (sk->d, sk->e, f)) || 456 while ((0 == gcry_mpi_invm (sk->d, sk->e, f)) ||
457 (0 == gcry_mpi_invm (sk->u, sk->p, sk->q))); 457 (0 == gcry_mpi_invm (sk->u, sk->p, sk->q)));
458 458
459 gcry_mpi_release (t1); 459 gcry_mpi_release (t1);
460 gcry_mpi_release (t2); 460 gcry_mpi_release (t2);
@@ -473,13 +473,13 @@ struct KskRsaPrivateKeyBinaryEncoded
473 * Total size of the structure, in bytes, in big-endian! 473 * Total size of the structure, in bytes, in big-endian!
474 */ 474 */
475 uint16_t len GNUNET_PACKED; 475 uint16_t len GNUNET_PACKED;
476 uint16_t sizen GNUNET_PACKED; /* in big-endian! */ 476 uint16_t sizen GNUNET_PACKED; /* in big-endian! */
477 uint16_t sizee GNUNET_PACKED; /* in big-endian! */ 477 uint16_t sizee GNUNET_PACKED; /* in big-endian! */
478 uint16_t sized GNUNET_PACKED; /* in big-endian! */ 478 uint16_t sized GNUNET_PACKED; /* in big-endian! */
479 uint16_t sizep GNUNET_PACKED; /* in big-endian! */ 479 uint16_t sizep GNUNET_PACKED; /* in big-endian! */
480 uint16_t sizeq GNUNET_PACKED; /* in big-endian! */ 480 uint16_t sizeq GNUNET_PACKED; /* in big-endian! */
481 uint16_t sizedmp1 GNUNET_PACKED; /* in big-endian! */ 481 uint16_t sizedmp1 GNUNET_PACKED; /* in big-endian! */
482 uint16_t sizedmq1 GNUNET_PACKED; /* in big-endian! */ 482 uint16_t sizedmq1 GNUNET_PACKED; /* in big-endian! */
483 /* followed by the actual values */ 483 /* followed by the actual values */
484}; 484};
485 485
@@ -501,16 +501,16 @@ makeKblockKeyInternal (const GNUNET_HashCode * hc)
501 size_t size; 501 size_t size;
502 502
503 hx = *hc; 503 hx = *hc;
504 generate_kblock_key (&sk, 1024, /* at least 10x as fast than 2048 bits 504 generate_kblock_key (&sk, 1024, /* at least 10x as fast than 2048 bits
505 * -- we simply cannot afford 2048 bits 505 * -- we simply cannot afford 2048 bits
506 * even on modern hardware, and especially 506 * even on modern hardware, and especially
507 * not since clearly a dictionary attack 507 * not since clearly a dictionary attack
508 * will still be much cheaper 508 * will still be much cheaper
509 * than breaking a 1024 bit RSA key. 509 * than breaking a 1024 bit RSA key.
510 * If an adversary can spend the time to 510 * If an adversary can spend the time to
511 * break a 1024 bit RSA key just to forge 511 * break a 1024 bit RSA key just to forge
512 * a signature -- SO BE IT. [ CG, 6/2005 ] */ 512 * a signature -- SO BE IT. [ CG, 6/2005 ] */
513 &hx); 513 &hx);
514 pkv[0] = &sk.n; 514 pkv[0] = &sk.n;
515 pkv[1] = &sk.e; 515 pkv[1] = &sk.e;
516 pkv[2] = &sk.d; 516 pkv[2] = &sk.d;
@@ -519,10 +519,10 @@ makeKblockKeyInternal (const GNUNET_HashCode * hc)
519 pkv[5] = &sk.u; 519 pkv[5] = &sk.u;
520 size = sizeof (struct KskRsaPrivateKeyBinaryEncoded); 520 size = sizeof (struct KskRsaPrivateKeyBinaryEncoded);
521 for (i = 0; i < 6; i++) 521 for (i = 0; i < 6; i++)
522 { 522 {
523 gcry_mpi_aprint (GCRYMPI_FMT_STD, &pbu[i], &sizes[i], *pkv[i]); 523 gcry_mpi_aprint (GCRYMPI_FMT_STD, &pbu[i], &sizes[i], *pkv[i]);
524 size += sizes[i]; 524 size += sizes[i];
525 } 525 }
526 GNUNET_assert (size < 65536); 526 GNUNET_assert (size < 65536);
527 retval = GNUNET_malloc (size); 527 retval = GNUNET_malloc (size);
528 retval->len = htons (size); 528 retval->len = htons (size);
@@ -547,10 +547,10 @@ makeKblockKeyInternal (const GNUNET_HashCode * hc)
547 retval->sizedmq1 = htons (0); 547 retval->sizedmq1 = htons (0);
548 memcpy (&((char *) &retval[1])[i], pbu[5], sizes[5]); 548 memcpy (&((char *) &retval[1])[i], pbu[5], sizes[5]);
549 for (i = 0; i < 6; i++) 549 for (i = 0; i < 6; i++)
550 { 550 {
551 gcry_mpi_release (*pkv[i]); 551 gcry_mpi_release (*pkv[i]);
552 free (pbu[i]); 552 free (pbu[i]);
553 } 553 }
554 return retval; 554 return retval;
555} 555}
556 556
@@ -572,123 +572,122 @@ ksk_decode_key (const struct KskRsaPrivateKeyBinaryEncoded *encoding)
572 pos = 0; 572 pos = 0;
573 size = ntohs (encoding->sizen); 573 size = ntohs (encoding->sizen);
574 rc = gcry_mpi_scan (&n, GCRYMPI_FMT_USG, 574 rc = gcry_mpi_scan (&n, GCRYMPI_FMT_USG,
575 &((const unsigned char *) (&encoding[1]))[pos], size, 575 &((const unsigned char *) (&encoding[1]))[pos], size,
576 &size); 576 &size);
577 pos += ntohs (encoding->sizen); 577 pos += ntohs (encoding->sizen);
578 if (rc) 578 if (rc)
579 { 579 {
580 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); 580 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
581 return NULL; 581 return NULL;
582 } 582 }
583 size = ntohs (encoding->sizee); 583 size = ntohs (encoding->sizee);
584 rc = gcry_mpi_scan (&e, GCRYMPI_FMT_USG, 584 rc = gcry_mpi_scan (&e, GCRYMPI_FMT_USG,
585 &((const unsigned char *) (&encoding[1]))[pos], size, 585 &((const unsigned char *) (&encoding[1]))[pos], size,
586 &size); 586 &size);
587 pos += ntohs (encoding->sizee); 587 pos += ntohs (encoding->sizee);
588 if (rc) 588 if (rc)
589 { 589 {
590 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); 590 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
591 gcry_mpi_release (n); 591 gcry_mpi_release (n);
592 return NULL; 592 return NULL;
593 } 593 }
594 size = ntohs (encoding->sized); 594 size = ntohs (encoding->sized);
595 rc = gcry_mpi_scan (&d, GCRYMPI_FMT_USG, 595 rc = gcry_mpi_scan (&d, GCRYMPI_FMT_USG,
596 &((const unsigned char *) (&encoding[1]))[pos], size, 596 &((const unsigned char *) (&encoding[1]))[pos], size,
597 &size); 597 &size);
598 pos += ntohs (encoding->sized); 598 pos += ntohs (encoding->sized);
599 if (rc) 599 if (rc)
600 {
601 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
602 gcry_mpi_release (n);
603 gcry_mpi_release (e);
604 return NULL;
605 }
606 /* swap p and q! */
607 size = ntohs (encoding->sizep);
608 if (size > 0)
609 {
610 rc = gcry_mpi_scan (&q, GCRYMPI_FMT_USG,
611 &((const unsigned char *) (&encoding[1]))[pos], size,
612 &size);
613 pos += ntohs (encoding->sizep);
614 if (rc)
600 { 615 {
601 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); 616 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
602 gcry_mpi_release (n); 617 gcry_mpi_release (n);
603 gcry_mpi_release (e); 618 gcry_mpi_release (e);
619 gcry_mpi_release (d);
604 return NULL; 620 return NULL;
605 } 621 }
606 /* swap p and q! */ 622 }
607 size = ntohs (encoding->sizep);
608 if (size > 0)
609 {
610 rc = gcry_mpi_scan (&q, GCRYMPI_FMT_USG,
611 &((const unsigned char *) (&encoding[1]))[pos],
612 size, &size);
613 pos += ntohs (encoding->sizep);
614 if (rc)
615 {
616 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
617 gcry_mpi_release (n);
618 gcry_mpi_release (e);
619 gcry_mpi_release (d);
620 return NULL;
621 }
622 }
623 else 623 else
624 q = NULL; 624 q = NULL;
625 size = ntohs (encoding->sizeq); 625 size = ntohs (encoding->sizeq);
626 if (size > 0) 626 if (size > 0)
627 {
628 rc = gcry_mpi_scan (&p, GCRYMPI_FMT_USG,
629 &((const unsigned char *) (&encoding[1]))[pos], size,
630 &size);
631 pos += ntohs (encoding->sizeq);
632 if (rc)
627 { 633 {
628 rc = gcry_mpi_scan (&p, GCRYMPI_FMT_USG, 634 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
629 &((const unsigned char *) (&encoding[1]))[pos], 635 gcry_mpi_release (n);
630 size, &size); 636 gcry_mpi_release (e);
631 pos += ntohs (encoding->sizeq); 637 gcry_mpi_release (d);
632 if (rc) 638 if (q != NULL)
633 { 639 gcry_mpi_release (q);
634 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); 640 return NULL;
635 gcry_mpi_release (n);
636 gcry_mpi_release (e);
637 gcry_mpi_release (d);
638 if (q != NULL)
639 gcry_mpi_release (q);
640 return NULL;
641 }
642 } 641 }
642 }
643 else 643 else
644 p = NULL; 644 p = NULL;
645 pos += ntohs (encoding->sizedmp1); 645 pos += ntohs (encoding->sizedmp1);
646 pos += ntohs (encoding->sizedmq1); 646 pos += ntohs (encoding->sizedmq1);
647 size = 647 size =
648 ntohs (encoding->len) - sizeof (struct KskRsaPrivateKeyBinaryEncoded) - 648 ntohs (encoding->len) - sizeof (struct KskRsaPrivateKeyBinaryEncoded) -
649 pos; 649 pos;
650 if (size > 0) 650 if (size > 0)
651 {
652 rc = gcry_mpi_scan (&u, GCRYMPI_FMT_USG,
653 &((const unsigned char *) (&encoding[1]))[pos], size,
654 &size);
655 if (rc)
651 { 656 {
652 rc = gcry_mpi_scan (&u, GCRYMPI_FMT_USG, 657 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
653 &((const unsigned char *) (&encoding[1]))[pos], 658 gcry_mpi_release (n);
654 size, &size); 659 gcry_mpi_release (e);
655 if (rc) 660 gcry_mpi_release (d);
656 { 661 if (p != NULL)
657 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); 662 gcry_mpi_release (p);
658 gcry_mpi_release (n); 663 if (q != NULL)
659 gcry_mpi_release (e); 664 gcry_mpi_release (q);
660 gcry_mpi_release (d); 665 return NULL;
661 if (p != NULL)
662 gcry_mpi_release (p);
663 if (q != NULL)
664 gcry_mpi_release (q);
665 return NULL;
666 }
667 } 666 }
667 }
668 else 668 else
669 u = NULL; 669 u = NULL;
670 670
671 if ((p != NULL) && (q != NULL) && (u != NULL)) 671 if ((p != NULL) && (q != NULL) && (u != NULL))
672 {
673 rc = gcry_sexp_build (&res, &size, /* erroff */
674 "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)(u %m)))",
675 n, e, d, p, q, u);
676 }
677 else
678 {
679 if ((p != NULL) && (q != NULL))
672 { 680 {
673 rc = gcry_sexp_build (&res, &size, /* erroff */ 681 rc = gcry_sexp_build (&res, &size, /* erroff */
674 "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)(u %m)))", 682 "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)))",
675 n, e, d, p, q, u); 683 n, e, d, p, q);
676 } 684 }
677 else 685 else
678 { 686 {
679 if ((p != NULL) && (q != NULL)) 687 rc = gcry_sexp_build (&res, &size, /* erroff */
680 { 688 "(private-key(rsa(n %m)(e %m)(d %m)))", n, e, d);
681 rc = gcry_sexp_build (&res, &size, /* erroff */
682 "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)))",
683 n, e, d, p, q);
684 }
685 else
686 {
687 rc = gcry_sexp_build (&res, &size, /* erroff */
688 "(private-key(rsa(n %m)(e %m)(d %m)))", n, e,
689 d);
690 }
691 } 689 }
690 }
692 gcry_mpi_release (n); 691 gcry_mpi_release (n);
693 gcry_mpi_release (e); 692 gcry_mpi_release (e);
694 gcry_mpi_release (d); 693 gcry_mpi_release (d);
@@ -703,10 +702,10 @@ ksk_decode_key (const struct KskRsaPrivateKeyBinaryEncoded *encoding)
703 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc); 702 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc);
704#if EXTRA_CHECKS 703#if EXTRA_CHECKS
705 if (gcry_pk_testkey (res)) 704 if (gcry_pk_testkey (res))
706 { 705 {
707 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc); 706 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc);
708 return NULL; 707 return NULL;
709 } 708 }
710#endif 709#endif
711 ret = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPrivateKey)); 710 ret = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPrivateKey));
712 ret->sexp = res; 711 ret->sexp = res;
@@ -736,13 +735,13 @@ GNUNET_CRYPTO_rsa_key_create_from_hash (const GNUNET_HashCode * hc)
736 unsigned int i; 735 unsigned int i;
737 736
738 for (i = 0; i < cacheSize; i++) 737 for (i = 0; i < cacheSize; i++)
738 {
739 if (0 == memcmp (hc, &cache[i]->hc, sizeof (GNUNET_HashCode)))
739 { 740 {
740 if (0 == memcmp (hc, &cache[i]->hc, sizeof (GNUNET_HashCode))) 741 ret = ksk_decode_key (cache[i]->pke);
741 { 742 return ret;
742 ret = ksk_decode_key (cache[i]->pke);
743 return ret;
744 }
745 } 743 }
744 }
746 745
747 line = GNUNET_malloc (sizeof (struct KBlockKeyCacheLine)); 746 line = GNUNET_malloc (sizeof (struct KBlockKeyCacheLine));
748 line->hc = *hc; 747 line->hc = *hc;
@@ -758,10 +757,10 @@ void __attribute__ ((destructor)) GNUNET_CRYPTO_ksk_fini ()
758 unsigned int i; 757 unsigned int i;
759 758
760 for (i = 0; i < cacheSize; i++) 759 for (i = 0; i < cacheSize; i++)
761 { 760 {
762 GNUNET_free (cache[i]->pke); 761 GNUNET_free (cache[i]->pke);
763 GNUNET_free (cache[i]); 762 GNUNET_free (cache[i]);
764 } 763 }
765 GNUNET_array_grow (cache, cacheSize, 0); 764 GNUNET_array_grow (cache, cacheSize, 0);
766} 765}
767 766
diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c
index 7fb2d1428..c74d60f4f 100644
--- a/src/util/crypto_random.c
+++ b/src/util/crypto_random.c
@@ -65,37 +65,37 @@ GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i)
65 GNUNET_assert (i > 0); 65 GNUNET_assert (i > 0);
66 66
67 switch (mode) 67 switch (mode)
68 { 68 {
69 case GNUNET_CRYPTO_QUALITY_STRONG: 69 case GNUNET_CRYPTO_QUALITY_STRONG:
70 /* see http://lists.gnupg.org/pipermail/gcrypt-devel/2004-May/000613.html */ 70 /* see http://lists.gnupg.org/pipermail/gcrypt-devel/2004-May/000613.html */
71#ifdef gcry_fast_random_poll 71#ifdef gcry_fast_random_poll
72 if ((invokeCount++ % 256) == 0) 72 if ((invokeCount++ % 256) == 0)
73 gcry_fast_random_poll (); 73 gcry_fast_random_poll ();
74#endif 74#endif
75 ul = UINT32_MAX - (UINT32_MAX % i); 75 ul = UINT32_MAX - (UINT32_MAX % i);
76 do 76 do
77 { 77 {
78 gcry_randomize ((unsigned char *) &ret, sizeof (uint32_t), 78 gcry_randomize ((unsigned char *) &ret, sizeof (uint32_t),
79 GCRY_STRONG_RANDOM); 79 GCRY_STRONG_RANDOM);
80 } 80 }
81 while (ret >= ul); 81 while (ret >= ul);
82 return ret % i; 82 return ret % i;
83 case GNUNET_CRYPTO_QUALITY_NONCE: 83 case GNUNET_CRYPTO_QUALITY_NONCE:
84 ul = UINT32_MAX - (UINT32_MAX % i); 84 ul = UINT32_MAX - (UINT32_MAX % i);
85 do 85 do
86 { 86 {
87 gcry_create_nonce (&ret, sizeof (ret)); 87 gcry_create_nonce (&ret, sizeof (ret));
88 }
89 while (ret >= ul);
90 return ret % i;
91 case GNUNET_CRYPTO_QUALITY_WEAK:
92 ret = i * weak_random ();
93 if (ret >= i)
94 ret = i - 1;
95 return ret;
96 default:
97 GNUNET_assert (0);
98 } 88 }
89 while (ret >= ul);
90 return ret % i;
91 case GNUNET_CRYPTO_QUALITY_WEAK:
92 ret = i * weak_random ();
93 if (ret >= i)
94 ret = i - 1;
95 return ret;
96 default:
97 GNUNET_assert (0);
98 }
99 return 0; 99 return 0;
100} 100}
101 101
@@ -121,12 +121,12 @@ GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, unsigned int n)
121 for (i = 0; i < n; i++) 121 for (i = 0; i < n; i++)
122 ret[i] = i; 122 ret[i] = i;
123 for (i = n - 1; i > 0; i--) 123 for (i = n - 1; i > 0; i--)
124 { 124 {
125 x = GNUNET_CRYPTO_random_u32 (mode, i + 1); 125 x = GNUNET_CRYPTO_random_u32 (mode, i + 1);
126 tmp = ret[x]; 126 tmp = ret[x];
127 ret[x] = ret[i]; 127 ret[x] = ret[i];
128 ret[i] = tmp; 128 ret[i] = tmp;
129 } 129 }
130 return ret; 130 return ret;
131} 131}
132 132
@@ -146,33 +146,33 @@ GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max)
146 146
147 GNUNET_assert (max > 0); 147 GNUNET_assert (max > 0);
148 switch (mode) 148 switch (mode)
149 {
150 case GNUNET_CRYPTO_QUALITY_STRONG:
151 ul = UINT64_MAX - (UINT64_MAX % max);
152 do
149 { 153 {
150 case GNUNET_CRYPTO_QUALITY_STRONG: 154 gcry_randomize ((unsigned char *) &ret, sizeof (uint64_t),
151 ul = UINT64_MAX - (UINT64_MAX % max); 155 GCRY_STRONG_RANDOM);
152 do
153 {
154 gcry_randomize ((unsigned char *) &ret, sizeof (uint64_t),
155 GCRY_STRONG_RANDOM);
156 }
157 while (ret >= ul);
158 return ret % max;
159 case GNUNET_CRYPTO_QUALITY_NONCE:
160 ul = UINT64_MAX - (UINT64_MAX % max);
161 do
162 {
163 gcry_create_nonce (&ret, sizeof (ret));
164 }
165 while (ret >= ul);
166
167 return ret % max;
168 case GNUNET_CRYPTO_QUALITY_WEAK:
169 ret = max * weak_random ();
170 if (ret >= max)
171 ret = max - 1;
172 return ret;
173 default:
174 GNUNET_assert (0);
175 } 156 }
157 while (ret >= ul);
158 return ret % max;
159 case GNUNET_CRYPTO_QUALITY_NONCE:
160 ul = UINT64_MAX - (UINT64_MAX % max);
161 do
162 {
163 gcry_create_nonce (&ret, sizeof (ret));
164 }
165 while (ret >= ul);
166
167 return ret % max;
168 case GNUNET_CRYPTO_QUALITY_WEAK:
169 ret = max * weak_random ();
170 if (ret >= max)
171 ret = max - 1;
172 return ret;
173 default:
174 GNUNET_assert (0);
175 }
176 return 0; 176 return 0;
177} 177}
178 178
@@ -200,7 +200,7 @@ static struct GNUNET_OS_Process *genproc;
200 */ 200 */
201static void 201static void
202entropy_generator (void *cls, const char *what, int printchar, int current, 202entropy_generator (void *cls, const char *what, int printchar, int current,
203 int total) 203 int total)
204{ 204{
205 unsigned long code; 205 unsigned long code;
206 enum GNUNET_OS_ProcessStatusType type; 206 enum GNUNET_OS_ProcessStatusType type;
@@ -209,39 +209,39 @@ entropy_generator (void *cls, const char *what, int printchar, int current,
209 if (0 != strcmp (what, "need_entropy")) 209 if (0 != strcmp (what, "need_entropy"))
210 return; 210 return;
211 if (current == total) 211 if (current == total)
212 {
213 if (genproc != NULL)
212 { 214 {
213 if (genproc != NULL)
214 {
215 if (0 != GNUNET_OS_process_kill (genproc, SIGTERM))
216 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "kill");
217 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc));
218 GNUNET_OS_process_close (genproc);
219 genproc = NULL;
220 }
221 return;
222 }
223 if (genproc != NULL)
224 {
225 ret = GNUNET_OS_process_status (genproc, &type, &code);
226 if (ret == GNUNET_NO)
227 return; /* still running */
228 if (ret == GNUNET_SYSERR)
229 {
230 GNUNET_break (0);
231 return;
232 }
233 if (0 != GNUNET_OS_process_kill (genproc, SIGTERM)) 215 if (0 != GNUNET_OS_process_kill (genproc, SIGTERM))
234 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "kill"); 216 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "kill");
235 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc)); 217 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc));
236 GNUNET_OS_process_close (genproc); 218 GNUNET_OS_process_close (genproc);
237 genproc = NULL; 219 genproc = NULL;
238 } 220 }
239 LOG (GNUNET_ERROR_TYPE_INFO, 221 return;
240 _("Starting `%s' process to generate entropy\n"), "find"); 222 }
223 if (genproc != NULL)
224 {
225 ret = GNUNET_OS_process_status (genproc, &type, &code);
226 if (ret == GNUNET_NO)
227 return; /* still running */
228 if (ret == GNUNET_SYSERR)
229 {
230 GNUNET_break (0);
231 return;
232 }
233 if (0 != GNUNET_OS_process_kill (genproc, SIGTERM))
234 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "kill");
235 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc));
236 GNUNET_OS_process_close (genproc);
237 genproc = NULL;
238 }
239 LOG (GNUNET_ERROR_TYPE_INFO, _("Starting `%s' process to generate entropy\n"),
240 "find");
241 genproc = 241 genproc =
242 GNUNET_OS_start_process (NULL, NULL, "sh", "sh", "-c", 242 GNUNET_OS_start_process (NULL, NULL, "sh", "sh", "-c",
243 "exec find / -mount -type f -exec cp {} /dev/null \\; 2>/dev/null", 243 "exec find / -mount -type f -exec cp {} /dev/null \\; 2>/dev/null",
244 NULL); 244 NULL);
245} 245}
246 246
247 247
@@ -249,11 +249,11 @@ static void
249killfind () 249killfind ()
250{ 250{
251 if (genproc != NULL) 251 if (genproc != NULL)
252 { 252 {
253 GNUNET_OS_process_kill (genproc, SIGKILL); 253 GNUNET_OS_process_kill (genproc, SIGKILL);
254 GNUNET_OS_process_close (genproc); 254 GNUNET_OS_process_close (genproc);
255 genproc = NULL; 255 genproc = NULL;
256 } 256 }
257} 257}
258 258
259 259
@@ -261,21 +261,20 @@ void __attribute__ ((constructor)) GNUNET_CRYPTO_random_init ()
261{ 261{
262 gcry_control (GCRYCTL_DISABLE_SECMEM, 0); 262 gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
263 if (!gcry_check_version (GCRYPT_VERSION)) 263 if (!gcry_check_version (GCRYPT_VERSION))
264 { 264 {
265 fprintf (stderr, 265 fprintf (stderr,
266 _ 266 _
267 ("libgcrypt has not the expected version (version %s is required).\n"), 267 ("libgcrypt has not the expected version (version %s is required).\n"),
268 GCRYPT_VERSION); 268 GCRYPT_VERSION);
269 abort (); 269 abort ();
270 } 270 }
271#ifdef gcry_fast_random_poll 271#ifdef gcry_fast_random_poll
272 gcry_fast_random_poll (); 272 gcry_fast_random_poll ();
273#endif 273#endif
274 gcry_set_progress_handler (&entropy_generator, NULL); 274 gcry_set_progress_handler (&entropy_generator, NULL);
275 atexit (&killfind); 275 atexit (&killfind);
276 SRANDOM (time (NULL) ^ 276 SRANDOM (time (NULL) ^
277 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 277 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX));
278 UINT32_MAX));
279} 278}
280 279
281 280
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c
index 7f0c81692..d29566ac8 100644
--- a/src/util/crypto_rsa.c
+++ b/src/util/crypto_rsa.c
@@ -66,13 +66,13 @@ struct RsaPrivateKeyBinaryEncoded
66 * Total size of the structure, in bytes, in big-endian! 66 * Total size of the structure, in bytes, in big-endian!
67 */ 67 */
68 uint16_t len GNUNET_PACKED; 68 uint16_t len GNUNET_PACKED;
69 uint16_t sizen GNUNET_PACKED; /* in big-endian! */ 69 uint16_t sizen GNUNET_PACKED; /* in big-endian! */
70 uint16_t sizee GNUNET_PACKED; /* in big-endian! */ 70 uint16_t sizee GNUNET_PACKED; /* in big-endian! */
71 uint16_t sized GNUNET_PACKED; /* in big-endian! */ 71 uint16_t sized GNUNET_PACKED; /* in big-endian! */
72 uint16_t sizep GNUNET_PACKED; /* in big-endian! */ 72 uint16_t sizep GNUNET_PACKED; /* in big-endian! */
73 uint16_t sizeq GNUNET_PACKED; /* in big-endian! */ 73 uint16_t sizeq GNUNET_PACKED; /* in big-endian! */
74 uint16_t sizedmp1 GNUNET_PACKED; /* in big-endian! */ 74 uint16_t sizedmp1 GNUNET_PACKED; /* in big-endian! */
75 uint16_t sizedmq1 GNUNET_PACKED; /* in big-endian! */ 75 uint16_t sizedmq1 GNUNET_PACKED; /* in big-endian! */
76 /* followed by the actual values */ 76 /* followed by the actual values */
77}; 77};
78 78
@@ -98,10 +98,10 @@ static void
98adjust (unsigned char *buf, size_t size, size_t target) 98adjust (unsigned char *buf, size_t size, size_t target)
99{ 99{
100 if (size < target) 100 if (size < target)
101 { 101 {
102 memmove (&buf[target - size], buf, size); 102 memmove (&buf[target - size], buf, size);
103 memset (buf, 0, target - size); 103 memset (buf, 0, target - size);
104 } 104 }
105} 105}
106 106
107/** 107/**
@@ -115,9 +115,9 @@ GNUNET_CRYPTO_rsa_key_create ()
115 gcry_sexp_t s_keyparam; 115 gcry_sexp_t s_keyparam;
116 116
117 GNUNET_assert (0 == 117 GNUNET_assert (0 ==
118 gcry_sexp_build (&s_keyparam, NULL, 118 gcry_sexp_build (&s_keyparam, NULL,
119 "(genkey(rsa(nbits %d)(rsa-use-e 3:257)))", 119 "(genkey(rsa(nbits %d)(rsa-use-e 3:257)))",
120 HOSTKEY_LEN)); 120 HOSTKEY_LEN));
121 GNUNET_assert (0 == gcry_pk_genkey (&s_key, s_keyparam)); 121 GNUNET_assert (0 == gcry_pk_genkey (&s_key, s_keyparam));
122 gcry_sexp_release (s_keyparam); 122 gcry_sexp_release (s_keyparam);
123#if EXTRA_CHECKS 123#if EXTRA_CHECKS
@@ -140,7 +140,7 @@ GNUNET_CRYPTO_rsa_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey)
140 140
141static int 141static int
142key_from_sexp (gcry_mpi_t * array, gcry_sexp_t sexp, const char *topname, 142key_from_sexp (gcry_mpi_t * array, gcry_sexp_t sexp, const char *topname,
143 const char *elems) 143 const char *elems)
144{ 144{
145 gcry_sexp_t list, l2; 145 gcry_sexp_t list, l2;
146 const char *s; 146 const char *s;
@@ -148,44 +148,44 @@ key_from_sexp (gcry_mpi_t * array, gcry_sexp_t sexp, const char *topname,
148 148
149 list = gcry_sexp_find_token (sexp, topname, 0); 149 list = gcry_sexp_find_token (sexp, topname, 0);
150 if (!list) 150 if (!list)
151 { 151 {
152 return 1; 152 return 1;
153 } 153 }
154 l2 = gcry_sexp_cadr (list); 154 l2 = gcry_sexp_cadr (list);
155 gcry_sexp_release (list); 155 gcry_sexp_release (list);
156 list = l2; 156 list = l2;
157 if (!list) 157 if (!list)
158 { 158 {
159 return 2; 159 return 2;
160 } 160 }
161 161
162 idx = 0; 162 idx = 0;
163 for (s = elems; *s; s++, idx++) 163 for (s = elems; *s; s++, idx++)
164 {
165 l2 = gcry_sexp_find_token (list, s, 1);
166 if (!l2)
164 { 167 {
165 l2 = gcry_sexp_find_token (list, s, 1); 168 for (i = 0; i < idx; i++)
166 if (!l2) 169 {
167 { 170 gcry_free (array[i]);
168 for (i = 0; i < idx; i++) 171 array[i] = NULL;
169 { 172 }
170 gcry_free (array[i]); 173 gcry_sexp_release (list);
171 array[i] = NULL; 174 return 3; /* required parameter not found */
172 }
173 gcry_sexp_release (list);
174 return 3; /* required parameter not found */
175 }
176 array[idx] = gcry_sexp_nth_mpi (l2, 1, GCRYMPI_FMT_USG);
177 gcry_sexp_release (l2);
178 if (!array[idx])
179 {
180 for (i = 0; i < idx; i++)
181 {
182 gcry_free (array[i]);
183 array[i] = NULL;
184 }
185 gcry_sexp_release (list);
186 return 4; /* required parameter is invalid */
187 }
188 } 175 }
176 array[idx] = gcry_sexp_nth_mpi (l2, 1, GCRYMPI_FMT_USG);
177 gcry_sexp_release (l2);
178 if (!array[idx])
179 {
180 for (i = 0; i < idx; i++)
181 {
182 gcry_free (array[i]);
183 array[i] = NULL;
184 }
185 gcry_sexp_release (list);
186 return 4; /* required parameter is invalid */
187 }
188 }
189 gcry_sexp_release (list); 189 gcry_sexp_release (list);
190 return 0; 190 return 0;
191} 191}
@@ -197,10 +197,9 @@ key_from_sexp (gcry_mpi_t * array, gcry_sexp_t sexp, const char *topname,
197 */ 197 */
198void 198void
199GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey 199GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey
200 *priv, 200 *priv,
201 struct 201 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
202 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded 202 *pub)
203 *pub)
204{ 203{
205 gcry_mpi_t skey[2]; 204 gcry_mpi_t skey[2];
206 size_t size; 205 size_t size;
@@ -213,25 +212,24 @@ GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey
213 rc = key_from_sexp (skey, priv->sexp, "rsa", "ne"); 212 rc = key_from_sexp (skey, priv->sexp, "rsa", "ne");
214 GNUNET_assert (0 == rc); 213 GNUNET_assert (0 == rc);
215 pub->len = 214 pub->len =
216 htons (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) - 215 htons (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) -
217 sizeof (pub->padding)); 216 sizeof (pub->padding));
218 pub->sizen = htons (GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH); 217 pub->sizen = htons (GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH);
219 pub->padding = 0; 218 pub->padding = 0;
220 size = GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH; 219 size = GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH;
221 GNUNET_assert (0 == 220 GNUNET_assert (0 ==
222 gcry_mpi_print (GCRYMPI_FMT_USG, &pub->key[0], size, &size, 221 gcry_mpi_print (GCRYMPI_FMT_USG, &pub->key[0], size, &size,
223 skey[0])); 222 skey[0]));
224 adjust (&pub->key[0], size, GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH); 223 adjust (&pub->key[0], size, GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH);
225 size = 224 size = GNUNET_CRYPTO_RSA_KEY_LENGTH - GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH;
226 GNUNET_CRYPTO_RSA_KEY_LENGTH - GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH;
227 GNUNET_assert (0 == 225 GNUNET_assert (0 ==
228 gcry_mpi_print (GCRYMPI_FMT_USG, 226 gcry_mpi_print (GCRYMPI_FMT_USG,
229 &pub->key 227 &pub->key
230 [GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH], 228 [GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH], size,
231 size, &size, skey[1])); 229 &size, skey[1]));
232 adjust (&pub->key[GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH], size, 230 adjust (&pub->key[GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH], size,
233 GNUNET_CRYPTO_RSA_KEY_LENGTH - 231 GNUNET_CRYPTO_RSA_KEY_LENGTH -
234 GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH); 232 GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH);
235 gcry_mpi_release (skey[0]); 233 gcry_mpi_release (skey[0]);
236 gcry_mpi_release (skey[1]); 234 gcry_mpi_release (skey[1]);
237} 235}
@@ -245,7 +243,7 @@ GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey
245 */ 243 */
246static struct GNUNET_CRYPTO_RsaPrivateKey * 244static struct GNUNET_CRYPTO_RsaPrivateKey *
247public2PrivateKey (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded 245public2PrivateKey (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
248 *publicKey) 246 *publicKey)
249{ 247{
250 struct GNUNET_CRYPTO_RsaPrivateKey *ret; 248 struct GNUNET_CRYPTO_RsaPrivateKey *ret;
251 gcry_sexp_t result; 249 gcry_sexp_t result;
@@ -259,38 +257,36 @@ public2PrivateKey (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
259 (ntohs (publicKey->len) != 257 (ntohs (publicKey->len) !=
260 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) - 258 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) -
261 sizeof (publicKey->padding))) 259 sizeof (publicKey->padding)))
262 { 260 {
263 GNUNET_break (0); 261 GNUNET_break (0);
264 return NULL; 262 return NULL;
265 } 263 }
266 size = GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH; 264 size = GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH;
267 rc = gcry_mpi_scan (&n, GCRYMPI_FMT_USG, &publicKey->key[0], size, &size); 265 rc = gcry_mpi_scan (&n, GCRYMPI_FMT_USG, &publicKey->key[0], size, &size);
268 if (rc) 266 if (rc)
269 { 267 {
270 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); 268 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
271 return NULL; 269 return NULL;
272 } 270 }
273 size = 271 size = GNUNET_CRYPTO_RSA_KEY_LENGTH - GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH;
274 GNUNET_CRYPTO_RSA_KEY_LENGTH - GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH; 272 rc = gcry_mpi_scan (&e, GCRYMPI_FMT_USG,
275 rc = 273 &publicKey->key[GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH],
276 gcry_mpi_scan (&e, GCRYMPI_FMT_USG, 274 size, &size);
277 &publicKey->key[GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH],
278 size, &size);
279 if (rc) 275 if (rc)
280 { 276 {
281 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); 277 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
282 gcry_mpi_release (n); 278 gcry_mpi_release (n);
283 return NULL; 279 return NULL;
284 } 280 }
285 rc = gcry_sexp_build (&result, &erroff, "(public-key(rsa(n %m)(e %m)))", n, 281 rc = gcry_sexp_build (&result, &erroff, "(public-key(rsa(n %m)(e %m)))", n,
286 e); 282 e);
287 gcry_mpi_release (n); 283 gcry_mpi_release (n);
288 gcry_mpi_release (e); 284 gcry_mpi_release (e);
289 if (rc) 285 if (rc)
290 { 286 {
291 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc); /* erroff gives more info */ 287 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc); /* erroff gives more info */
292 return NULL; 288 return NULL;
293 } 289 }
294 ret = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPrivateKey)); 290 ret = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPrivateKey));
295 ret->sexp = result; 291 ret->sexp = result;
296 return ret; 292 return ret;
@@ -316,10 +312,10 @@ rsa_encode_key (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey)
316 312
317#if EXTRA_CHECKS 313#if EXTRA_CHECKS
318 if (gcry_pk_testkey (hostkey->sexp)) 314 if (gcry_pk_testkey (hostkey->sexp))
319 { 315 {
320 GNUNET_break (0); 316 GNUNET_break (0);
321 return NULL; 317 return NULL;
322 } 318 }
323#endif 319#endif
324 320
325 memset (pkv, 0, sizeof (gcry_mpi_t) * 6); 321 memset (pkv, 0, sizeof (gcry_mpi_t) * 6);
@@ -337,21 +333,21 @@ rsa_encode_key (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey)
337 GNUNET_assert (0 == rc); 333 GNUNET_assert (0 == rc);
338 size = sizeof (struct RsaPrivateKeyBinaryEncoded); 334 size = sizeof (struct RsaPrivateKeyBinaryEncoded);
339 for (i = 0; i < 6; i++) 335 for (i = 0; i < 6; i++)
336 {
337 if (pkv[i] != NULL)
340 { 338 {
341 if (pkv[i] != NULL) 339 GNUNET_assert (0 ==
342 { 340 gcry_mpi_aprint (GCRYMPI_FMT_USG,
343 GNUNET_assert (0 == 341 (unsigned char **) &pbu[i], &sizes[i],
344 gcry_mpi_aprint (GCRYMPI_FMT_USG, 342 pkv[i]));
345 (unsigned char **) &pbu[i], 343 size += sizes[i];
346 &sizes[i], pkv[i]));
347 size += sizes[i];
348 }
349 else
350 {
351 pbu[i] = NULL;
352 sizes[i] = 0;
353 }
354 } 344 }
345 else
346 {
347 pbu[i] = NULL;
348 sizes[i] = 0;
349 }
350 }
355 GNUNET_assert (size < 65536); 351 GNUNET_assert (size < 65536);
356 retval = GNUNET_malloc (size); 352 retval = GNUNET_malloc (size);
357 retval->len = htons (size); 353 retval->len = htons (size);
@@ -376,12 +372,12 @@ rsa_encode_key (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey)
376 retval->sizedmq1 = htons (0); 372 retval->sizedmq1 = htons (0);
377 memcpy (&((char *) (&retval[1]))[i], pbu[5], sizes[5]); 373 memcpy (&((char *) (&retval[1]))[i], pbu[5], sizes[5]);
378 for (i = 0; i < 6; i++) 374 for (i = 0; i < 6; i++)
379 { 375 {
380 if (pkv[i] != NULL) 376 if (pkv[i] != NULL)
381 gcry_mpi_release (pkv[i]); 377 gcry_mpi_release (pkv[i]);
382 if (pbu[i] != NULL) 378 if (pbu[i] != NULL)
383 free (pbu[i]); 379 free (pbu[i]);
384 } 380 }
385 return retval; 381 return retval;
386} 382}
387 383
@@ -397,7 +393,7 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len)
397{ 393{
398 struct GNUNET_CRYPTO_RsaPrivateKey *ret; 394 struct GNUNET_CRYPTO_RsaPrivateKey *ret;
399 const struct RsaPrivateKeyBinaryEncoded *encoding = 395 const struct RsaPrivateKeyBinaryEncoded *encoding =
400 (const struct RsaPrivateKeyBinaryEncoded *) buf; 396 (const struct RsaPrivateKeyBinaryEncoded *) buf;
401 gcry_sexp_t res; 397 gcry_sexp_t res;
402 gcry_mpi_t n, e, d, p, q, u; 398 gcry_mpi_t n, e, d, p, q, u;
403 int rc; 399 int rc;
@@ -412,122 +408,121 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len)
412 pos = 0; 408 pos = 0;
413 size = ntohs (encoding->sizen); 409 size = ntohs (encoding->sizen);
414 rc = gcry_mpi_scan (&n, GCRYMPI_FMT_USG, 410 rc = gcry_mpi_scan (&n, GCRYMPI_FMT_USG,
415 &((const unsigned char *) (&encoding[1]))[pos], size, 411 &((const unsigned char *) (&encoding[1]))[pos], size,
416 &size); 412 &size);
417 pos += ntohs (encoding->sizen); 413 pos += ntohs (encoding->sizen);
418 if (rc) 414 if (rc)
419 { 415 {
420 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); 416 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
421 return NULL; 417 return NULL;
422 } 418 }
423 size = ntohs (encoding->sizee); 419 size = ntohs (encoding->sizee);
424 rc = gcry_mpi_scan (&e, GCRYMPI_FMT_USG, 420 rc = gcry_mpi_scan (&e, GCRYMPI_FMT_USG,
425 &((const unsigned char *) (&encoding[1]))[pos], size, 421 &((const unsigned char *) (&encoding[1]))[pos], size,
426 &size); 422 &size);
427 pos += ntohs (encoding->sizee); 423 pos += ntohs (encoding->sizee);
428 if (rc) 424 if (rc)
429 { 425 {
430 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); 426 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
431 gcry_mpi_release (n); 427 gcry_mpi_release (n);
432 return NULL; 428 return NULL;
433 } 429 }
434 size = ntohs (encoding->sized); 430 size = ntohs (encoding->sized);
435 rc = gcry_mpi_scan (&d, GCRYMPI_FMT_USG, 431 rc = gcry_mpi_scan (&d, GCRYMPI_FMT_USG,
436 &((const unsigned char *) (&encoding[1]))[pos], size, 432 &((const unsigned char *) (&encoding[1]))[pos], size,
437 &size); 433 &size);
438 pos += ntohs (encoding->sized); 434 pos += ntohs (encoding->sized);
439 if (rc) 435 if (rc)
436 {
437 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
438 gcry_mpi_release (n);
439 gcry_mpi_release (e);
440 return NULL;
441 }
442 /* swap p and q! */
443 size = ntohs (encoding->sizep);
444 if (size > 0)
445 {
446 rc = gcry_mpi_scan (&q, GCRYMPI_FMT_USG,
447 &((const unsigned char *) (&encoding[1]))[pos], size,
448 &size);
449 pos += ntohs (encoding->sizep);
450 if (rc)
440 { 451 {
441 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); 452 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
442 gcry_mpi_release (n); 453 gcry_mpi_release (n);
443 gcry_mpi_release (e); 454 gcry_mpi_release (e);
455 gcry_mpi_release (d);
444 return NULL; 456 return NULL;
445 } 457 }
446 /* swap p and q! */ 458 }
447 size = ntohs (encoding->sizep);
448 if (size > 0)
449 {
450 rc = gcry_mpi_scan (&q, GCRYMPI_FMT_USG,
451 &((const unsigned char *) (&encoding[1]))[pos],
452 size, &size);
453 pos += ntohs (encoding->sizep);
454 if (rc)
455 {
456 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
457 gcry_mpi_release (n);
458 gcry_mpi_release (e);
459 gcry_mpi_release (d);
460 return NULL;
461 }
462 }
463 else 459 else
464 q = NULL; 460 q = NULL;
465 size = ntohs (encoding->sizeq); 461 size = ntohs (encoding->sizeq);
466 if (size > 0) 462 if (size > 0)
463 {
464 rc = gcry_mpi_scan (&p, GCRYMPI_FMT_USG,
465 &((const unsigned char *) (&encoding[1]))[pos], size,
466 &size);
467 pos += ntohs (encoding->sizeq);
468 if (rc)
467 { 469 {
468 rc = gcry_mpi_scan (&p, GCRYMPI_FMT_USG, 470 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
469 &((const unsigned char *) (&encoding[1]))[pos], 471 gcry_mpi_release (n);
470 size, &size); 472 gcry_mpi_release (e);
471 pos += ntohs (encoding->sizeq); 473 gcry_mpi_release (d);
472 if (rc) 474 if (q != NULL)
473 { 475 gcry_mpi_release (q);
474 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); 476 return NULL;
475 gcry_mpi_release (n);
476 gcry_mpi_release (e);
477 gcry_mpi_release (d);
478 if (q != NULL)
479 gcry_mpi_release (q);
480 return NULL;
481 }
482 } 477 }
478 }
483 else 479 else
484 p = NULL; 480 p = NULL;
485 pos += ntohs (encoding->sizedmp1); 481 pos += ntohs (encoding->sizedmp1);
486 pos += ntohs (encoding->sizedmq1); 482 pos += ntohs (encoding->sizedmq1);
487 size = 483 size =
488 ntohs (encoding->len) - sizeof (struct RsaPrivateKeyBinaryEncoded) - pos; 484 ntohs (encoding->len) - sizeof (struct RsaPrivateKeyBinaryEncoded) - pos;
489 if (size > 0) 485 if (size > 0)
486 {
487 rc = gcry_mpi_scan (&u, GCRYMPI_FMT_USG,
488 &((const unsigned char *) (&encoding[1]))[pos], size,
489 &size);
490 if (rc)
490 { 491 {
491 rc = gcry_mpi_scan (&u, GCRYMPI_FMT_USG, 492 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
492 &((const unsigned char *) (&encoding[1]))[pos], 493 gcry_mpi_release (n);
493 size, &size); 494 gcry_mpi_release (e);
494 if (rc) 495 gcry_mpi_release (d);
495 { 496 if (p != NULL)
496 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); 497 gcry_mpi_release (p);
497 gcry_mpi_release (n); 498 if (q != NULL)
498 gcry_mpi_release (e); 499 gcry_mpi_release (q);
499 gcry_mpi_release (d); 500 return NULL;
500 if (p != NULL)
501 gcry_mpi_release (p);
502 if (q != NULL)
503 gcry_mpi_release (q);
504 return NULL;
505 }
506 } 501 }
502 }
507 else 503 else
508 u = NULL; 504 u = NULL;
509 505
510 if ((p != NULL) && (q != NULL) && (u != NULL)) 506 if ((p != NULL) && (q != NULL) && (u != NULL))
507 {
508 rc = gcry_sexp_build (&res, &size, /* erroff */
509 "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)(u %m)))",
510 n, e, d, p, q, u);
511 }
512 else
513 {
514 if ((p != NULL) && (q != NULL))
511 { 515 {
512 rc = gcry_sexp_build (&res, &size, /* erroff */ 516 rc = gcry_sexp_build (&res, &size, /* erroff */
513 "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)(u %m)))", 517 "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)))",
514 n, e, d, p, q, u); 518 n, e, d, p, q);
515 } 519 }
516 else 520 else
517 { 521 {
518 if ((p != NULL) && (q != NULL)) 522 rc = gcry_sexp_build (&res, &size, /* erroff */
519 { 523 "(private-key(rsa(n %m)(e %m)(d %m)))", n, e, d);
520 rc = gcry_sexp_build (&res, &size, /* erroff */
521 "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)))",
522 n, e, d, p, q);
523 }
524 else
525 {
526 rc = gcry_sexp_build (&res, &size, /* erroff */
527 "(private-key(rsa(n %m)(e %m)(d %m)))", n, e,
528 d);
529 }
530 } 524 }
525 }
531 gcry_mpi_release (n); 526 gcry_mpi_release (n);
532 gcry_mpi_release (e); 527 gcry_mpi_release (e);
533 gcry_mpi_release (d); 528 gcry_mpi_release (d);
@@ -542,10 +537,10 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len)
542 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc); 537 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc);
543#if EXTRA_CHECKS 538#if EXTRA_CHECKS
544 if (gcry_pk_testkey (res)) 539 if (gcry_pk_testkey (res))
545 { 540 {
546 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc); 541 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc);
547 return NULL; 542 return NULL;
548 } 543 }
549#endif 544#endif
550 ret = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPrivateKey)); 545 ret = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPrivateKey));
551 ret->sexp = res; 546 ret->sexp = res;
@@ -582,172 +577,165 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
582 if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename)) 577 if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename))
583 return NULL; 578 return NULL;
584 while (GNUNET_YES != GNUNET_DISK_file_test (filename)) 579 while (GNUNET_YES != GNUNET_DISK_file_test (filename))
580 {
581 fd = GNUNET_DISK_file_open (filename,
582 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE
583 | GNUNET_DISK_OPEN_FAILIFEXISTS,
584 GNUNET_DISK_PERM_USER_READ |
585 GNUNET_DISK_PERM_USER_WRITE);
586 if (NULL == fd)
585 { 587 {
586 fd = GNUNET_DISK_file_open (filename, 588 if (errno == EEXIST)
587 GNUNET_DISK_OPEN_WRITE | 589 {
588 GNUNET_DISK_OPEN_CREATE | 590 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
589 GNUNET_DISK_OPEN_FAILIFEXISTS, 591 {
590 GNUNET_DISK_PERM_USER_READ | 592 /* must exist but not be accessible, fail for good! */
591 GNUNET_DISK_PERM_USER_WRITE); 593 if (0 != ACCESS (filename, R_OK))
592 if (NULL == fd) 594 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", filename);
593 { 595 else
594 if (errno == EEXIST) 596 GNUNET_break (0); /* what is going on!? */
595 { 597 return NULL;
596 if (GNUNET_YES != GNUNET_DISK_file_test (filename)) 598 }
597 { 599 continue;
598 /* must exist but not be accessible, fail for good! */ 600 }
599 if (0 != ACCESS (filename, R_OK)) 601 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename);
600 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", 602 return NULL;
601 filename); 603 }
602 else 604 cnt = 0;
603 GNUNET_break (0); /* what is going on!? */ 605
604 return NULL; 606 while (GNUNET_YES !=
605 } 607 GNUNET_DISK_file_lock (fd, 0,
606 continue; 608 sizeof (struct RsaPrivateKeyBinaryEncoded),
607 } 609 GNUNET_YES))
608 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename); 610 {
609 return NULL; 611 sleep (1);
610 } 612 if (0 == ++cnt % 10)
611 cnt = 0; 613 {
612 614 ec = errno;
613 while (GNUNET_YES != 615 LOG (GNUNET_ERROR_TYPE_ERROR,
614 GNUNET_DISK_file_lock (fd, 0, 616 _("Could not aquire lock on file `%s': %s...\n"), filename,
615 sizeof (struct 617 STRERROR (ec));
616 RsaPrivateKeyBinaryEncoded), 618 }
617 GNUNET_YES))
618 {
619 sleep (1);
620 if (0 == ++cnt % 10)
621 {
622 ec = errno;
623 LOG (GNUNET_ERROR_TYPE_ERROR,
624 _("Could not aquire lock on file `%s': %s...\n"), filename,
625 STRERROR (ec));
626 }
627 }
628 LOG (GNUNET_ERROR_TYPE_INFO,
629 _("Creating a new private key. This may take a while.\n"));
630 ret = GNUNET_CRYPTO_rsa_key_create ();
631 GNUNET_assert (ret != NULL);
632 enc = rsa_encode_key (ret);
633 GNUNET_assert (enc != NULL);
634 GNUNET_assert (ntohs (enc->len) ==
635 GNUNET_DISK_file_write (fd, enc, ntohs (enc->len)));
636 GNUNET_free (enc);
637
638 GNUNET_DISK_file_sync (fd);
639 if (GNUNET_YES !=
640 GNUNET_DISK_file_unlock (fd, 0,
641 sizeof (struct
642 RsaPrivateKeyBinaryEncoded)))
643 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
644 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
645 GNUNET_CRYPTO_rsa_key_get_public (ret, &pub);
646 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey);
647 LOG (GNUNET_ERROR_TYPE_INFO,
648 _("I am host `%s'. Stored new private key in `%s'.\n"),
649 GNUNET_i2s (&pid), filename);
650 return ret;
651 } 619 }
620 LOG (GNUNET_ERROR_TYPE_INFO,
621 _("Creating a new private key. This may take a while.\n"));
622 ret = GNUNET_CRYPTO_rsa_key_create ();
623 GNUNET_assert (ret != NULL);
624 enc = rsa_encode_key (ret);
625 GNUNET_assert (enc != NULL);
626 GNUNET_assert (ntohs (enc->len) ==
627 GNUNET_DISK_file_write (fd, enc, ntohs (enc->len)));
628 GNUNET_free (enc);
629
630 GNUNET_DISK_file_sync (fd);
631 if (GNUNET_YES !=
632 GNUNET_DISK_file_unlock (fd, 0,
633 sizeof (struct RsaPrivateKeyBinaryEncoded)))
634 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
635 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
636 GNUNET_CRYPTO_rsa_key_get_public (ret, &pub);
637 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey);
638 LOG (GNUNET_ERROR_TYPE_INFO,
639 _("I am host `%s'. Stored new private key in `%s'.\n"),
640 GNUNET_i2s (&pid), filename);
641 return ret;
642 }
652 /* hostkey file exists already, read it! */ 643 /* hostkey file exists already, read it! */
653 fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, 644 fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ,
654 GNUNET_DISK_PERM_NONE); 645 GNUNET_DISK_PERM_NONE);
655 if (NULL == fd) 646 if (NULL == fd)
647 {
648 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename);
649 return NULL;
650 }
651 cnt = 0;
652 while (1)
653 {
654 if (GNUNET_YES !=
655 GNUNET_DISK_file_lock (fd, 0,
656 sizeof (struct RsaPrivateKeyBinaryEncoded),
657 GNUNET_NO))
656 { 658 {
657 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename); 659 if (0 == ++cnt % 60)
660 {
661 ec = errno;
662 LOG (GNUNET_ERROR_TYPE_ERROR,
663 _("Could not aquire lock on file `%s': %s...\n"), filename,
664 STRERROR (ec));
665 LOG (GNUNET_ERROR_TYPE_ERROR,
666 _
667 ("This may be ok if someone is currently generating a hostkey.\n"));
668 }
669 sleep (1);
670 continue;
671 }
672 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
673 {
674 /* eh, what!? File we opened is now gone!? */
675 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
676 if (GNUNET_YES !=
677 GNUNET_DISK_file_unlock (fd, 0,
678 sizeof (struct RsaPrivateKeyBinaryEncoded)))
679 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
680 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd));
681
658 return NULL; 682 return NULL;
659 } 683 }
660 cnt = 0; 684 if (GNUNET_YES != GNUNET_DISK_file_size (filename, &fs, GNUNET_YES))
661 while (1) 685 fs = 0;
686 if (fs < sizeof (struct RsaPrivateKeyBinaryEncoded))
662 { 687 {
688 /* maybe we got the read lock before the hostkey generating
689 * process had a chance to get the write lock; give it up! */
663 if (GNUNET_YES != 690 if (GNUNET_YES !=
664 GNUNET_DISK_file_lock (fd, 0, 691 GNUNET_DISK_file_unlock (fd, 0,
665 sizeof (struct RsaPrivateKeyBinaryEncoded), 692 sizeof (struct RsaPrivateKeyBinaryEncoded)))
666 GNUNET_NO)) 693 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
667 { 694 if (0 == ++cnt % 10)
668 if (0 == ++cnt % 60) 695 {
669 { 696 LOG (GNUNET_ERROR_TYPE_ERROR,
670 ec = errno; 697 _
671 LOG (GNUNET_ERROR_TYPE_ERROR, 698 ("When trying to read hostkey file `%s' I found %u bytes but I need at least %u.\n"),
672 _("Could not aquire lock on file `%s': %s...\n"), filename, 699 filename, (unsigned int) fs,
673 STRERROR (ec)); 700 (unsigned int) sizeof (struct RsaPrivateKeyBinaryEncoded));
674 LOG (GNUNET_ERROR_TYPE_ERROR, 701 LOG (GNUNET_ERROR_TYPE_ERROR,
675 _ 702 _
676 ("This may be ok if someone is currently generating a hostkey.\n")); 703 ("This may be ok if someone is currently generating a hostkey.\n"));
677 } 704 }
678 sleep (1); 705 sleep (2); /* wait a bit longer! */
679 continue; 706 continue;
680 }
681 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
682 {
683 /* eh, what!? File we opened is now gone!? */
684 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
685 if (GNUNET_YES !=
686 GNUNET_DISK_file_unlock (fd, 0,
687 sizeof (struct
688 RsaPrivateKeyBinaryEncoded)))
689 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
690 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd));
691
692 return NULL;
693 }
694 if (GNUNET_YES != GNUNET_DISK_file_size (filename, &fs, GNUNET_YES))
695 fs = 0;
696 if (fs < sizeof (struct RsaPrivateKeyBinaryEncoded))
697 {
698 /* maybe we got the read lock before the hostkey generating
699 * process had a chance to get the write lock; give it up! */
700 if (GNUNET_YES !=
701 GNUNET_DISK_file_unlock (fd, 0,
702 sizeof (struct
703 RsaPrivateKeyBinaryEncoded)))
704 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
705 if (0 == ++cnt % 10)
706 {
707 LOG (GNUNET_ERROR_TYPE_ERROR,
708 _
709 ("When trying to read hostkey file `%s' I found %u bytes but I need at least %u.\n"),
710 filename, (unsigned int) fs,
711 (unsigned int) sizeof (struct RsaPrivateKeyBinaryEncoded));
712 LOG (GNUNET_ERROR_TYPE_ERROR,
713 _
714 ("This may be ok if someone is currently generating a hostkey.\n"));
715 }
716 sleep (2); /* wait a bit longer! */
717 continue;
718 }
719 break;
720 } 707 }
708 break;
709 }
721 enc = GNUNET_malloc (fs); 710 enc = GNUNET_malloc (fs);
722 GNUNET_assert (fs == GNUNET_DISK_file_read (fd, enc, fs)); 711 GNUNET_assert (fs == GNUNET_DISK_file_read (fd, enc, fs));
723 len = ntohs (enc->len); 712 len = ntohs (enc->len);
724 ret = NULL; 713 ret = NULL;
725 if ((len != fs) || 714 if ((len != fs) ||
726 (NULL == (ret = GNUNET_CRYPTO_rsa_decode_key ((char *) enc, len)))) 715 (NULL == (ret = GNUNET_CRYPTO_rsa_decode_key ((char *) enc, len))))
716 {
717 LOG (GNUNET_ERROR_TYPE_ERROR,
718 _("File `%s' does not contain a valid private key. Deleting it.\n"),
719 filename);
720 if (0 != UNLINK (filename))
727 { 721 {
728 LOG (GNUNET_ERROR_TYPE_ERROR, 722 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
729 _
730 ("File `%s' does not contain a valid private key. Deleting it.\n"),
731 filename);
732 if (0 != UNLINK (filename))
733 {
734 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
735 }
736 } 723 }
724 }
737 GNUNET_free (enc); 725 GNUNET_free (enc);
738 if (GNUNET_YES != 726 if (GNUNET_YES !=
739 GNUNET_DISK_file_unlock (fd, 0, 727 GNUNET_DISK_file_unlock (fd, 0,
740 sizeof (struct RsaPrivateKeyBinaryEncoded))) 728 sizeof (struct RsaPrivateKeyBinaryEncoded)))
741 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); 729 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
742 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); 730 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
743 if (ret != NULL) 731 if (ret != NULL)
744 { 732 {
745 GNUNET_CRYPTO_rsa_key_get_public (ret, &pub); 733 GNUNET_CRYPTO_rsa_key_get_public (ret, &pub);
746 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey); 734 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey);
747 LOG (GNUNET_ERROR_TYPE_INFO, 735 LOG (GNUNET_ERROR_TYPE_INFO,
748 _("I am host `%s'. Read private key from `%s'.\n"), 736 _("I am host `%s'. Read private key from `%s'.\n"), GNUNET_i2s (&pid),
749 GNUNET_i2s (&pid), filename); 737 filename);
750 } 738 }
751 return ret; 739 return ret;
752} 740}
753 741
@@ -764,9 +752,9 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
764 */ 752 */
765int 753int
766GNUNET_CRYPTO_rsa_encrypt (const void *block, size_t size, 754GNUNET_CRYPTO_rsa_encrypt (const void *block, size_t size,
767 const struct 755 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
768 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey, 756 *publicKey,
769 struct GNUNET_CRYPTO_RsaEncryptedData *target) 757 struct GNUNET_CRYPTO_RsaEncryptedData *target)
770{ 758{
771 gcry_sexp_t result; 759 gcry_sexp_t result;
772 gcry_sexp_t data; 760 gcry_sexp_t data;
@@ -782,10 +770,10 @@ GNUNET_CRYPTO_rsa_encrypt (const void *block, size_t size,
782 return GNUNET_SYSERR; 770 return GNUNET_SYSERR;
783 isize = size; 771 isize = size;
784 GNUNET_assert (0 == 772 GNUNET_assert (0 ==
785 gcry_mpi_scan (&val, GCRYMPI_FMT_USG, block, isize, &isize)); 773 gcry_mpi_scan (&val, GCRYMPI_FMT_USG, block, isize, &isize));
786 GNUNET_assert (0 == 774 GNUNET_assert (0 ==
787 gcry_sexp_build (&data, &erroff, 775 gcry_sexp_build (&data, &erroff,
788 "(data (flags pkcs1)(value %m))", val)); 776 "(data (flags pkcs1)(value %m))", val));
789 gcry_mpi_release (val); 777 gcry_mpi_release (val);
790 GNUNET_assert (0 == gcry_pk_encrypt (&result, data, pubkey->sexp)); 778 GNUNET_assert (0 == gcry_pk_encrypt (&result, data, pubkey->sexp));
791 gcry_sexp_release (data); 779 gcry_sexp_release (data);
@@ -795,11 +783,11 @@ GNUNET_CRYPTO_rsa_encrypt (const void *block, size_t size,
795 gcry_sexp_release (result); 783 gcry_sexp_release (result);
796 isize = sizeof (struct GNUNET_CRYPTO_RsaEncryptedData); 784 isize = sizeof (struct GNUNET_CRYPTO_RsaEncryptedData);
797 GNUNET_assert (0 == 785 GNUNET_assert (0 ==
798 gcry_mpi_print (GCRYMPI_FMT_USG, (unsigned char *) target, 786 gcry_mpi_print (GCRYMPI_FMT_USG, (unsigned char *) target,
799 isize, &isize, rval)); 787 isize, &isize, rval));
800 gcry_mpi_release (rval); 788 gcry_mpi_release (rval);
801 adjust (&target->encoding[0], isize, 789 adjust (&target->encoding[0], isize,
802 sizeof (struct GNUNET_CRYPTO_RsaEncryptedData)); 790 sizeof (struct GNUNET_CRYPTO_RsaEncryptedData));
803 return GNUNET_OK; 791 return GNUNET_OK;
804} 792}
805 793
@@ -815,8 +803,8 @@ GNUNET_CRYPTO_rsa_encrypt (const void *block, size_t size,
815 */ 803 */
816ssize_t 804ssize_t
817GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey * key, 805GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey * key,
818 const struct GNUNET_CRYPTO_RsaEncryptedData * 806 const struct GNUNET_CRYPTO_RsaEncryptedData * block,
819 block, void *result, size_t max) 807 void *result, size_t max)
820{ 808{
821 gcry_sexp_t resultsexp; 809 gcry_sexp_t resultsexp;
822 gcry_sexp_t data; 810 gcry_sexp_t data;
@@ -831,22 +819,21 @@ GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey * key,
831#endif 819#endif
832 size = sizeof (struct GNUNET_CRYPTO_RsaEncryptedData); 820 size = sizeof (struct GNUNET_CRYPTO_RsaEncryptedData);
833 GNUNET_assert (0 == 821 GNUNET_assert (0 ==
834 gcry_mpi_scan (&val, GCRYMPI_FMT_USG, &block->encoding[0], 822 gcry_mpi_scan (&val, GCRYMPI_FMT_USG, &block->encoding[0],
835 size, &size)); 823 size, &size));
836 GNUNET_assert (0 == 824 GNUNET_assert (0 ==
837 gcry_sexp_build (&data, &erroff, 825 gcry_sexp_build (&data, &erroff, "(enc-val(flags)(rsa(a %m)))",
838 "(enc-val(flags)(rsa(a %m)))", val)); 826 val));
839 gcry_mpi_release (val); 827 gcry_mpi_release (val);
840 GNUNET_assert (0 == gcry_pk_decrypt (&resultsexp, data, key->sexp)); 828 GNUNET_assert (0 == gcry_pk_decrypt (&resultsexp, data, key->sexp));
841 gcry_sexp_release (data); 829 gcry_sexp_release (data);
842 /* resultsexp has format "(value %m)" */ 830 /* resultsexp has format "(value %m)" */
843 GNUNET_assert (NULL != 831 GNUNET_assert (NULL !=
844 (val = gcry_sexp_nth_mpi (resultsexp, 1, GCRYMPI_FMT_USG))); 832 (val = gcry_sexp_nth_mpi (resultsexp, 1, GCRYMPI_FMT_USG)));
845 gcry_sexp_release (resultsexp); 833 gcry_sexp_release (resultsexp);
846 tmp = GNUNET_malloc (max + HOSTKEY_LEN / 8); 834 tmp = GNUNET_malloc (max + HOSTKEY_LEN / 8);
847 size = max + HOSTKEY_LEN / 8; 835 size = max + HOSTKEY_LEN / 8;
848 GNUNET_assert (0 == 836 GNUNET_assert (0 == gcry_mpi_print (GCRYMPI_FMT_USG, tmp, size, &size, val));
849 gcry_mpi_print (GCRYMPI_FMT_USG, tmp, size, &size, val));
850 gcry_mpi_release (val); 837 gcry_mpi_release (val);
851 endp = tmp; 838 endp = tmp;
852 endp += (size - max); 839 endp += (size - max);
@@ -867,8 +854,8 @@ GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey * key,
867 */ 854 */
868int 855int
869GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key, 856GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
870 const struct GNUNET_CRYPTO_RsaSignaturePurpose 857 const struct GNUNET_CRYPTO_RsaSignaturePurpose *purpose,
871 *purpose, struct GNUNET_CRYPTO_RsaSignature *sig) 858 struct GNUNET_CRYPTO_RsaSignature *sig)
872{ 859{
873 gcry_sexp_t result; 860 gcry_sexp_t result;
874 gcry_sexp_t data; 861 gcry_sexp_t data;
@@ -884,10 +871,10 @@ GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
884 buff = GNUNET_malloc (bufSize); 871 buff = GNUNET_malloc (bufSize);
885 memcpy (buff, FORMATSTRING, bufSize); 872 memcpy (buff, FORMATSTRING, bufSize);
886 memcpy (&buff 873 memcpy (&buff
887 [bufSize - 874 [bufSize -
888 strlen 875 strlen
889 ("0123456789012345678901234567890123456789012345678901234567890123))") 876 ("0123456789012345678901234567890123456789012345678901234567890123))")
890 - 1], &hc, sizeof (GNUNET_HashCode)); 877 - 1], &hc, sizeof (GNUNET_HashCode));
891 GNUNET_assert (0 == gcry_sexp_new (&data, buff, bufSize, 0)); 878 GNUNET_assert (0 == gcry_sexp_new (&data, buff, bufSize, 0));
892 GNUNET_free (buff); 879 GNUNET_free (buff);
893 GNUNET_assert (0 == gcry_pk_sign (&result, data, key->sexp)); 880 GNUNET_assert (0 == gcry_pk_sign (&result, data, key->sexp));
@@ -896,8 +883,8 @@ GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
896 gcry_sexp_release (result); 883 gcry_sexp_release (result);
897 ssize = sizeof (struct GNUNET_CRYPTO_RsaSignature); 884 ssize = sizeof (struct GNUNET_CRYPTO_RsaSignature);
898 GNUNET_assert (0 == 885 GNUNET_assert (0 ==
899 gcry_mpi_print (GCRYMPI_FMT_USG, (unsigned char *) sig, 886 gcry_mpi_print (GCRYMPI_FMT_USG, (unsigned char *) sig, ssize,
900 ssize, &ssize, rval)); 887 &ssize, rval));
901 gcry_mpi_release (rval); 888 gcry_mpi_release (rval);
902 adjust (sig->sig, ssize, sizeof (struct GNUNET_CRYPTO_RsaSignature)); 889 adjust (sig->sig, ssize, sizeof (struct GNUNET_CRYPTO_RsaSignature));
903 return GNUNET_OK; 890 return GNUNET_OK;
@@ -915,11 +902,11 @@ GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
915 */ 902 */
916int 903int
917GNUNET_CRYPTO_rsa_verify (uint32_t purpose, 904GNUNET_CRYPTO_rsa_verify (uint32_t purpose,
918 const struct GNUNET_CRYPTO_RsaSignaturePurpose 905 const struct GNUNET_CRYPTO_RsaSignaturePurpose
919 *validate, 906 *validate,
920 const struct GNUNET_CRYPTO_RsaSignature *sig, 907 const struct GNUNET_CRYPTO_RsaSignature *sig,
921 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded 908 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
922 *publicKey) 909 *publicKey)
923{ 910{
924 gcry_sexp_t data; 911 gcry_sexp_t data;
925 gcry_sexp_t sigdata; 912 gcry_sexp_t sigdata;
@@ -933,44 +920,44 @@ GNUNET_CRYPTO_rsa_verify (uint32_t purpose,
933 int rc; 920 int rc;
934 921
935 if (purpose != ntohl (validate->purpose)) 922 if (purpose != ntohl (validate->purpose))
936 return GNUNET_SYSERR; /* purpose mismatch */ 923 return GNUNET_SYSERR; /* purpose mismatch */
937 GNUNET_CRYPTO_hash (validate, ntohl (validate->size), &hc); 924 GNUNET_CRYPTO_hash (validate, ntohl (validate->size), &hc);
938 size = sizeof (struct GNUNET_CRYPTO_RsaSignature); 925 size = sizeof (struct GNUNET_CRYPTO_RsaSignature);
939 GNUNET_assert (0 == 926 GNUNET_assert (0 ==
940 gcry_mpi_scan (&val, GCRYMPI_FMT_USG, 927 gcry_mpi_scan (&val, GCRYMPI_FMT_USG,
941 (const unsigned char *) sig, size, &size)); 928 (const unsigned char *) sig, size, &size));
942 GNUNET_assert (0 == 929 GNUNET_assert (0 ==
943 gcry_sexp_build (&sigdata, &erroff, "(sig-val(rsa(s %m)))", 930 gcry_sexp_build (&sigdata, &erroff, "(sig-val(rsa(s %m)))",
944 val)); 931 val));
945 gcry_mpi_release (val); 932 gcry_mpi_release (val);
946 bufSize = strlen (FORMATSTRING) + 1; 933 bufSize = strlen (FORMATSTRING) + 1;
947 buff = GNUNET_malloc (bufSize); 934 buff = GNUNET_malloc (bufSize);
948 memcpy (buff, FORMATSTRING, bufSize); 935 memcpy (buff, FORMATSTRING, bufSize);
949 memcpy (&buff 936 memcpy (&buff
950 [strlen (FORMATSTRING) - 937 [strlen (FORMATSTRING) -
951 strlen 938 strlen
952 ("0123456789012345678901234567890123456789012345678901234567890123))")], 939 ("0123456789012345678901234567890123456789012345678901234567890123))")],
953 &hc, sizeof (GNUNET_HashCode)); 940 &hc, sizeof (GNUNET_HashCode));
954 GNUNET_assert (0 == gcry_sexp_new (&data, buff, bufSize, 0)); 941 GNUNET_assert (0 == gcry_sexp_new (&data, buff, bufSize, 0));
955 GNUNET_free (buff); 942 GNUNET_free (buff);
956 hostkey = public2PrivateKey (publicKey); 943 hostkey = public2PrivateKey (publicKey);
957 if (hostkey == NULL) 944 if (hostkey == NULL)
958 { 945 {
959 gcry_sexp_release (data); 946 gcry_sexp_release (data);
960 gcry_sexp_release (sigdata); 947 gcry_sexp_release (sigdata);
961 return GNUNET_SYSERR; 948 return GNUNET_SYSERR;
962 } 949 }
963 rc = gcry_pk_verify (sigdata, data, hostkey->sexp); 950 rc = gcry_pk_verify (sigdata, data, hostkey->sexp);
964 GNUNET_CRYPTO_rsa_key_free (hostkey); 951 GNUNET_CRYPTO_rsa_key_free (hostkey);
965 gcry_sexp_release (data); 952 gcry_sexp_release (data);
966 gcry_sexp_release (sigdata); 953 gcry_sexp_release (sigdata);
967 if (rc) 954 if (rc)
968 { 955 {
969 LOG (GNUNET_ERROR_TYPE_WARNING, 956 LOG (GNUNET_ERROR_TYPE_WARNING,
970 _("RSA signature verification failed at %s:%d: %s\n"), __FILE__, 957 _("RSA signature verification failed at %s:%d: %s\n"), __FILE__,
971 __LINE__, gcry_strerror (rc)); 958 __LINE__, gcry_strerror (rc));
972 return GNUNET_SYSERR; 959 return GNUNET_SYSERR;
973 } 960 }
974 return GNUNET_OK; 961 return GNUNET_OK;
975} 962}
976 963
diff --git a/src/util/disk.c b/src/util/disk.c
index 12f985791..2bdcf3262 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -67,8 +67,8 @@
67#define PIPE_BUF 512 67#define PIPE_BUF 512
68ULONG PipeSerialNumber; 68ULONG PipeSerialNumber;
69#endif 69#endif
70#define _IFMT 0170000 /* type of file */ 70#define _IFMT 0170000 /* type of file */
71#define _IFLNK 0120000 /* symbolic link */ 71#define _IFLNK 0120000 /* symbolic link */
72#define S_ISLNK(m) (((m)&_IFMT) == _IFLNK) 72#define S_ISLNK(m) (((m)&_IFMT) == _IFLNK)
73#else 73#else
74#error PORT-ME: need to port statfs (how much space is left on the drive?) 74#error PORT-ME: need to port statfs (how much space is left on the drive?)
@@ -165,25 +165,25 @@ getSizeRec (void *cls, const char *fn)
165 165
166#ifdef HAVE_STAT64 166#ifdef HAVE_STAT64
167 if (0 != STAT64 (fn, &buf)) 167 if (0 != STAT64 (fn, &buf))
168 { 168 {
169 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat64", fn); 169 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat64", fn);
170 return GNUNET_SYSERR; 170 return GNUNET_SYSERR;
171 } 171 }
172#else 172#else
173 if (0 != STAT (fn, &buf)) 173 if (0 != STAT (fn, &buf))
174 { 174 {
175 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", fn); 175 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", fn);
176 return GNUNET_SYSERR; 176 return GNUNET_SYSERR;
177 } 177 }
178#endif 178#endif
179 if ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES)) 179 if ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES))
180 gfsd->total += buf.st_size; 180 gfsd->total += buf.st_size;
181 if ((S_ISDIR (buf.st_mode)) && (0 == ACCESS (fn, X_OK)) && 181 if ((S_ISDIR (buf.st_mode)) && (0 == ACCESS (fn, X_OK)) &&
182 ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES))) 182 ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES)))
183 { 183 {
184 if (GNUNET_SYSERR == GNUNET_DISK_directory_scan (fn, &getSizeRec, gfsd)) 184 if (GNUNET_SYSERR == GNUNET_DISK_directory_scan (fn, &getSizeRec, gfsd))
185 return GNUNET_SYSERR; 185 return GNUNET_SYSERR;
186 } 186 }
187 return GNUNET_OK; 187 return GNUNET_OK;
188} 188}
189 189
@@ -215,13 +215,13 @@ GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h)
215 */ 215 */
216off_t 216off_t
217GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle * h, off_t offset, 217GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle * h, off_t offset,
218 enum GNUNET_DISK_Seek whence) 218 enum GNUNET_DISK_Seek whence)
219{ 219{
220 if (h == NULL) 220 if (h == NULL)
221 { 221 {
222 errno = EINVAL; 222 errno = EINVAL;
223 return GNUNET_SYSERR; 223 return GNUNET_SYSERR;
224 } 224 }
225 225
226#ifdef MINGW 226#ifdef MINGW
227 DWORD ret; 227 DWORD ret;
@@ -232,10 +232,10 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle * h, off_t offset,
232 232
233 ret = SetFilePointer (h->h, offset, NULL, t[whence]); 233 ret = SetFilePointer (h->h, offset, NULL, t[whence]);
234 if (ret == INVALID_SET_FILE_POINTER) 234 if (ret == INVALID_SET_FILE_POINTER)
235 { 235 {
236 SetErrnoFromWinError (GetLastError ()); 236 SetErrnoFromWinError (GetLastError ());
237 return GNUNET_SYSERR; 237 return GNUNET_SYSERR;
238 } 238 }
239 return ret; 239 return ret;
240#else 240#else
241 static int t[] = {[GNUNET_DISK_SEEK_SET] = SEEK_SET, 241 static int t[] = {[GNUNET_DISK_SEEK_SET] = SEEK_SET,
@@ -261,7 +261,7 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle * h, off_t offset,
261 */ 261 */
262int 262int
263GNUNET_DISK_file_size (const char *filename, uint64_t * size, 263GNUNET_DISK_file_size (const char *filename, uint64_t * size,
264 int includeSymLinks) 264 int includeSymLinks)
265{ 265{
266 struct GetFileSizeData gfsd; 266 struct GetFileSizeData gfsd;
267 int ret; 267 int ret;
@@ -292,29 +292,29 @@ GNUNET_DISK_file_size (const char *filename, uint64_t * size,
292 */ 292 */
293int 293int
294GNUNET_DISK_file_get_identifiers (const char *filename, uint64_t * dev, 294GNUNET_DISK_file_get_identifiers (const char *filename, uint64_t * dev,
295 uint64_t * ino) 295 uint64_t * ino)
296{ 296{
297#if LINUX 297#if LINUX
298 struct stat sbuf; 298 struct stat sbuf;
299 struct statvfs fbuf; 299 struct statvfs fbuf;
300 300
301 if ((0 == stat (filename, &sbuf)) && (0 == statvfs (filename, &fbuf))) 301 if ((0 == stat (filename, &sbuf)) && (0 == statvfs (filename, &fbuf)))
302 { 302 {
303 *dev = (uint64_t) fbuf.f_fsid; 303 *dev = (uint64_t) fbuf.f_fsid;
304 *ino = (uint64_t) sbuf.st_ino; 304 *ino = (uint64_t) sbuf.st_ino;
305 return GNUNET_OK; 305 return GNUNET_OK;
306 } 306 }
307#elif SOMEBSD 307#elif SOMEBSD
308 struct stat sbuf; 308 struct stat sbuf;
309 struct statfs fbuf; 309 struct statfs fbuf;
310 310
311 if ((0 == stat (filename, &sbuf)) && (0 == statfs (filename, &fbuf))) 311 if ((0 == stat (filename, &sbuf)) && (0 == statfs (filename, &fbuf)))
312 { 312 {
313 *dev = ((uint64_t) fbuf.f_fsid.val[0]) << 32 || 313 *dev = ((uint64_t) fbuf.f_fsid.val[0]) << 32 ||
314 ((uint64_t) fbuf.f_fsid.val[1]); 314 ((uint64_t) fbuf.f_fsid.val[1]);
315 *ino = (uint64_t) sbuf.st_ino; 315 *ino = (uint64_t) sbuf.st_ino;
316 return GNUNET_OK; 316 return GNUNET_OK;
317 } 317 }
318#elif WINDOWS 318#elif WINDOWS
319 // FIXME NILS: test this 319 // FIXME NILS: test this
320 struct GNUNET_DISK_FileHandle *fh; 320 struct GNUNET_DISK_FileHandle *fh;
@@ -327,11 +327,11 @@ GNUNET_DISK_file_get_identifiers (const char *filename, uint64_t * dev,
327 succ = GetFileInformationByHandle (fh->h, &info); 327 succ = GetFileInformationByHandle (fh->h, &info);
328 GNUNET_DISK_file_close (fh); 328 GNUNET_DISK_file_close (fh);
329 if (succ) 329 if (succ)
330 { 330 {
331 *dev = info.dwVolumeSerialNumber; 331 *dev = info.dwVolumeSerialNumber;
332 *ino = ((info.nFileIndexHigh << sizeof (DWORD)) | info.nFileIndexLow); 332 *ino = ((info.nFileIndexHigh << sizeof (DWORD)) | info.nFileIndexLow);
333 return GNUNET_OK; 333 return GNUNET_OK;
334 } 334 }
335 else 335 else
336 return GNUNET_SYSERR; 336 return GNUNET_SYSERR;
337 337
@@ -363,35 +363,35 @@ GNUNET_DISK_mktemp (const char *t)
363#if WINDOWS 363#if WINDOWS
364 && !(isalpha ((int) t[0]) && (t[0] != '\0') && (t[1] == ':')) 364 && !(isalpha ((int) t[0]) && (t[0] != '\0') && (t[1] == ':'))
365#endif 365#endif
366 ) 366 )
367 { 367 {
368 tmpdir = getenv ("TMPDIR"); 368 tmpdir = getenv ("TMPDIR");
369 tmpdir = tmpdir ? tmpdir : "/tmp"; 369 tmpdir = tmpdir ? tmpdir : "/tmp";
370 GNUNET_asprintf (&tmpl, "%s/%s%s", tmpdir, t, "XXXXXX"); 370 GNUNET_asprintf (&tmpl, "%s/%s%s", tmpdir, t, "XXXXXX");
371 } 371 }
372 else 372 else
373 { 373 {
374 GNUNET_asprintf (&tmpl, "%s%s", t, "XXXXXX"); 374 GNUNET_asprintf (&tmpl, "%s%s", t, "XXXXXX");
375 } 375 }
376#ifdef MINGW 376#ifdef MINGW
377 fn = (char *) GNUNET_malloc (MAX_PATH + 1); 377 fn = (char *) GNUNET_malloc (MAX_PATH + 1);
378 if (ERROR_SUCCESS != plibc_conv_to_win_path (tmpl, fn)) 378 if (ERROR_SUCCESS != plibc_conv_to_win_path (tmpl, fn))
379 { 379 {
380 GNUNET_free (fn); 380 GNUNET_free (fn);
381 GNUNET_free (tmpl); 381 GNUNET_free (tmpl);
382 return NULL; 382 return NULL;
383 } 383 }
384 GNUNET_free (tmpl); 384 GNUNET_free (tmpl);
385#else 385#else
386 fn = tmpl; 386 fn = tmpl;
387#endif 387#endif
388 fd = mkstemp (fn); 388 fd = mkstemp (fn);
389 if (fd == -1) 389 if (fd == -1)
390 { 390 {
391 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "mkstemp", fn); 391 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "mkstemp", fn);
392 GNUNET_free (fn); 392 GNUNET_free (fn);
393 return NULL; 393 return NULL;
394 } 394 }
395 if (0 != CLOSE (fd)) 395 if (0 != CLOSE (fd))
396 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "close", fn); 396 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "close", fn);
397 return fn; 397 return fn;
@@ -412,10 +412,10 @@ GNUNET_DISK_get_blocks_available (const char *part)
412 struct statvfs buf; 412 struct statvfs buf;
413 413
414 if (0 != statvfs (part, &buf)) 414 if (0 != statvfs (part, &buf))
415 { 415 {
416 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "statfs", part); 416 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "statfs", part);
417 return -1; 417 return -1;
418 } 418 }
419 return buf.f_bavail; 419 return buf.f_bavail;
420#elif MINGW 420#elif MINGW
421 DWORD dwDummy; 421 DWORD dwDummy;
@@ -430,22 +430,21 @@ GNUNET_DISK_get_blocks_available (const char *part)
430 GNUNET_free (path); 430 GNUNET_free (path);
431 szDrive[3] = 0; 431 szDrive[3] = 0;
432 if (!GetDiskFreeSpace (szDrive, &dwDummy, &dwDummy, &dwBlocks, &dwDummy)) 432 if (!GetDiskFreeSpace (szDrive, &dwDummy, &dwDummy, &dwBlocks, &dwDummy))
433 { 433 {
434 LOG (GNUNET_ERROR_TYPE_WARNING, 434 LOG (GNUNET_ERROR_TYPE_WARNING, _("`%s' failed for drive `%s': %u\n"),
435 _("`%s' failed for drive `%s': %u\n"), "GetDiskFreeSpace", 435 "GetDiskFreeSpace", szDrive, GetLastError ());
436 szDrive, GetLastError ());
437 436
438 return -1; 437 return -1;
439 } 438 }
440 return dwBlocks; 439 return dwBlocks;
441#else 440#else
442 struct statfs s; 441 struct statfs s;
443 442
444 if (0 != statfs (part, &s)) 443 if (0 != statfs (part, &s))
445 { 444 {
446 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "statfs", part); 445 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "statfs", part);
447 return -1; 446 return -1;
448 } 447 }
449 return s.f_bavail; 448 return s.f_bavail;
450#endif 449#endif
451} 450}
@@ -469,21 +468,21 @@ GNUNET_DISK_directory_test (const char *fil)
469 468
470 ret = STAT (fil, &filestat); 469 ret = STAT (fil, &filestat);
471 if (ret != 0) 470 if (ret != 0)
471 {
472 if (errno != ENOENT)
472 { 473 {
473 if (errno != ENOENT) 474 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", fil);
474 { 475 return GNUNET_SYSERR;
475 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", fil);
476 return GNUNET_SYSERR;
477 }
478 return GNUNET_NO;
479 } 476 }
477 return GNUNET_NO;
478 }
480 if (!S_ISDIR (filestat.st_mode)) 479 if (!S_ISDIR (filestat.st_mode))
481 return GNUNET_NO; 480 return GNUNET_NO;
482 if (ACCESS (fil, R_OK | X_OK) < 0) 481 if (ACCESS (fil, R_OK | X_OK) < 0)
483 { 482 {
484 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", fil); 483 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", fil);
485 return GNUNET_SYSERR; 484 return GNUNET_SYSERR;
486 } 485 }
487 return GNUNET_YES; 486 return GNUNET_YES;
488} 487}
489 488
@@ -508,27 +507,27 @@ GNUNET_DISK_file_test (const char *fil)
508 507
509 ret = STAT (rdir, &filestat); 508 ret = STAT (rdir, &filestat);
510 if (ret != 0) 509 if (ret != 0)
510 {
511 if (errno != ENOENT)
511 { 512 {
512 if (errno != ENOENT) 513 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", rdir);
513 {
514 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", rdir);
515 GNUNET_free (rdir);
516 return GNUNET_SYSERR;
517 }
518 GNUNET_free (rdir); 514 GNUNET_free (rdir);
519 return GNUNET_NO; 515 return GNUNET_SYSERR;
520 } 516 }
517 GNUNET_free (rdir);
518 return GNUNET_NO;
519 }
521 if (!S_ISREG (filestat.st_mode)) 520 if (!S_ISREG (filestat.st_mode))
522 { 521 {
523 GNUNET_free (rdir); 522 GNUNET_free (rdir);
524 return GNUNET_NO; 523 return GNUNET_NO;
525 } 524 }
526 if (ACCESS (rdir, R_OK) < 0) 525 if (ACCESS (rdir, R_OK) < 0)
527 { 526 {
528 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", rdir); 527 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", rdir);
529 GNUNET_free (rdir); 528 GNUNET_free (rdir);
530 return GNUNET_SYSERR; 529 return GNUNET_SYSERR;
531 } 530 }
532 GNUNET_free (rdir); 531 GNUNET_free (rdir);
533 return GNUNET_YES; 532 return GNUNET_YES;
534} 533}
@@ -553,56 +552,56 @@ GNUNET_DISK_directory_create (const char *dir)
553 552
554 len = strlen (rdir); 553 len = strlen (rdir);
555#ifndef MINGW 554#ifndef MINGW
556 pos = 1; /* skip heading '/' */ 555 pos = 1; /* skip heading '/' */
557#else 556#else
558 /* Local or Network path? */ 557 /* Local or Network path? */
559 if (strncmp (rdir, "\\\\", 2) == 0) 558 if (strncmp (rdir, "\\\\", 2) == 0)
559 {
560 pos = 2;
561 while (rdir[pos])
560 { 562 {
561 pos = 2; 563 if (rdir[pos] == '\\')
562 while (rdir[pos]) 564 {
563 { 565 pos++;
564 if (rdir[pos] == '\\') 566 break;
565 { 567 }
566 pos++; 568 pos++;
567 break;
568 }
569 pos++;
570 }
571 } 569 }
570 }
572 else 571 else
573 { 572 {
574 pos = 3; /* strlen("C:\\") */ 573 pos = 3; /* strlen("C:\\") */
575 } 574 }
576#endif 575#endif
577 while (pos <= len) 576 while (pos <= len)
577 {
578 if ((rdir[pos] == DIR_SEPARATOR) || (pos == len))
578 { 579 {
579 if ((rdir[pos] == DIR_SEPARATOR) || (pos == len)) 580 rdir[pos] = '\0';
580 { 581 ret = GNUNET_DISK_directory_test (rdir);
581 rdir[pos] = '\0'; 582 if (ret == GNUNET_SYSERR)
582 ret = GNUNET_DISK_directory_test (rdir); 583 {
583 if (ret == GNUNET_SYSERR) 584 GNUNET_free (rdir);
584 { 585 return GNUNET_SYSERR;
585 GNUNET_free (rdir); 586 }
586 return GNUNET_SYSERR; 587 if (ret == GNUNET_NO)
587 } 588 {
588 if (ret == GNUNET_NO)
589 {
590#ifndef MINGW 589#ifndef MINGW
591 ret = mkdir (rdir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); /* 755 */ 590 ret = mkdir (rdir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); /* 755 */
592#else 591#else
593 ret = mkdir (rdir); 592 ret = mkdir (rdir);
594#endif 593#endif
595 if ((ret != 0) && (errno != EEXIST)) 594 if ((ret != 0) && (errno != EEXIST))
596 { 595 {
597 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "mkdir", rdir); 596 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "mkdir", rdir);
598 GNUNET_free (rdir); 597 GNUNET_free (rdir);
599 return GNUNET_SYSERR; 598 return GNUNET_SYSERR;
600 } 599 }
601 } 600 }
602 rdir[pos] = DIR_SEPARATOR; 601 rdir[pos] = DIR_SEPARATOR;
603 }
604 pos++;
605 } 602 }
603 pos++;
604 }
606 GNUNET_free (rdir); 605 GNUNET_free (rdir);
607 return GNUNET_OK; 606 return GNUNET_OK;
608} 607}
@@ -649,37 +648,37 @@ GNUNET_DISK_directory_create_for_file (const char *filename)
649 */ 648 */
650ssize_t 649ssize_t
651GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle * h, void *result, 650GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle * h, void *result,
652 size_t len) 651 size_t len)
653{ 652{
654 if (h == NULL) 653 if (h == NULL)
655 { 654 {
656 errno = EINVAL; 655 errno = EINVAL;
657 return GNUNET_SYSERR; 656 return GNUNET_SYSERR;
658 } 657 }
659 658
660#ifdef MINGW 659#ifdef MINGW
661 DWORD bytesRead; 660 DWORD bytesRead;
662 661
663 if (h->type != GNUNET_PIPE) 662 if (h->type != GNUNET_PIPE)
663 {
664 if (!ReadFile (h->h, result, len, &bytesRead, NULL))
664 { 665 {
665 if (!ReadFile (h->h, result, len, &bytesRead, NULL)) 666 SetErrnoFromWinError (GetLastError ());
666 { 667 return GNUNET_SYSERR;
667 SetErrnoFromWinError (GetLastError ());
668 return GNUNET_SYSERR;
669 }
670 } 668 }
669 }
671 else 670 else
671 {
672 if (!ReadFile (h->h, result, len, NULL, h->oOverlapRead))
672 { 673 {
673 if (!ReadFile (h->h, result, len, NULL, h->oOverlapRead)) 674 if (GetLastError () != ERROR_IO_PENDING)
674 { 675 {
675 if (GetLastError () != ERROR_IO_PENDING) 676 SetErrnoFromWinError (GetLastError ());
676 { 677 return GNUNET_SYSERR;
677 SetErrnoFromWinError (GetLastError ()); 678 }
678 return GNUNET_SYSERR;
679 }
680 }
681 GetOverlappedResult (h->h, h->oOverlapRead, &bytesRead, TRUE);
682 } 679 }
680 GetOverlappedResult (h->h, h->oOverlapRead, &bytesRead, TRUE);
681 }
683 return bytesRead; 682 return bytesRead;
684#else 683#else
685 return read (h->fd, result, len); 684 return read (h->fd, result, len);
@@ -701,8 +700,7 @@ GNUNET_DISK_fn_read (const char *fn, void *result, size_t len)
701 struct GNUNET_DISK_FileHandle *fh; 700 struct GNUNET_DISK_FileHandle *fh;
702 ssize_t ret; 701 ssize_t ret;
703 702
704 fh = 703 fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE);
705 GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE);
706 if (!fh) 704 if (!fh)
707 return GNUNET_SYSERR; 705 return GNUNET_SYSERR;
708 ret = GNUNET_DISK_file_read (fh, result, len); 706 ret = GNUNET_DISK_file_read (fh, result, len);
@@ -721,46 +719,46 @@ GNUNET_DISK_fn_read (const char *fn, void *result, size_t len)
721 */ 719 */
722ssize_t 720ssize_t
723GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h, 721GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h,
724 const void *buffer, size_t n) 722 const void *buffer, size_t n)
725{ 723{
726 if (h == NULL) 724 if (h == NULL)
727 { 725 {
728 errno = EINVAL; 726 errno = EINVAL;
729 return GNUNET_SYSERR; 727 return GNUNET_SYSERR;
730 } 728 }
731 729
732#ifdef MINGW 730#ifdef MINGW
733 DWORD bytesWritten; 731 DWORD bytesWritten;
734 732
735 if (h->type != GNUNET_PIPE) 733 if (h->type != GNUNET_PIPE)
734 {
735 if (!WriteFile (h->h, buffer, n, &bytesWritten, NULL))
736 { 736 {
737 if (!WriteFile (h->h, buffer, n, &bytesWritten, NULL)) 737 SetErrnoFromWinError (GetLastError ());
738 { 738 return GNUNET_SYSERR;
739 SetErrnoFromWinError (GetLastError ());
740 return GNUNET_SYSERR;
741 }
742 } 739 }
740 }
743 else 741 else
744 { 742 {
745#if DEBUG_PIPE 743#if DEBUG_PIPE
746 LOG (GNUNET_ERROR_TYPE_DEBUG, "It is a pipe trying to write\n"); 744 LOG (GNUNET_ERROR_TYPE_DEBUG, "It is a pipe trying to write\n");
747#endif 745#endif
748 if (!WriteFile (h->h, buffer, n, NULL, h->oOverlapWrite)) 746 if (!WriteFile (h->h, buffer, n, NULL, h->oOverlapWrite))
749 { 747 {
750 if (GetLastError () != ERROR_IO_PENDING) 748 if (GetLastError () != ERROR_IO_PENDING)
751 { 749 {
752 SetErrnoFromWinError (GetLastError ()); 750 SetErrnoFromWinError (GetLastError ());
753#if DEBUG_PIPE 751#if DEBUG_PIPE
754 LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe\n"); 752 LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe\n");
755#endif 753#endif
756 return GNUNET_SYSERR; 754 return GNUNET_SYSERR;
757 } 755 }
758 } 756 }
759#if DEBUG_PIPE 757#if DEBUG_PIPE
760 LOG (GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n"); 758 LOG (GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n");
761#endif 759#endif
762 GetOverlappedResult (h->h, h->oOverlapWrite, &bytesWritten, TRUE); 760 GetOverlappedResult (h->h, h->oOverlapWrite, &bytesWritten, TRUE);
763 } 761 }
764 return bytesWritten; 762 return bytesWritten;
765#else 763#else
766 return write (h->fd, buffer, n); 764 return write (h->fd, buffer, n);
@@ -779,15 +777,14 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h,
779 */ 777 */
780ssize_t 778ssize_t
781GNUNET_DISK_fn_write (const char *fn, const void *buffer, size_t n, 779GNUNET_DISK_fn_write (const char *fn, const void *buffer, size_t n,
782 enum GNUNET_DISK_AccessPermissions mode) 780 enum GNUNET_DISK_AccessPermissions mode)
783{ 781{
784 struct GNUNET_DISK_FileHandle *fh; 782 struct GNUNET_DISK_FileHandle *fh;
785 ssize_t ret; 783 ssize_t ret;
786 784
787 fh = GNUNET_DISK_file_open (fn, 785 fh = GNUNET_DISK_file_open (fn,
788 GNUNET_DISK_OPEN_WRITE | 786 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE
789 GNUNET_DISK_OPEN_TRUNCATE | 787 | GNUNET_DISK_OPEN_CREATE, mode);
790 GNUNET_DISK_OPEN_CREATE, mode);
791 if (!fh) 788 if (!fh)
792 return GNUNET_SYSERR; 789 return GNUNET_SYSERR;
793 ret = GNUNET_DISK_file_write (fh, buffer, n); 790 ret = GNUNET_DISK_file_write (fh, buffer, n);
@@ -808,8 +805,8 @@ GNUNET_DISK_fn_write (const char *fn, const void *buffer, size_t n,
808 */ 805 */
809int 806int
810GNUNET_DISK_directory_scan (const char *dirName, 807GNUNET_DISK_directory_scan (const char *dirName,
811 GNUNET_FileNameCallback callback, 808 GNUNET_FileNameCallback callback,
812 void *callback_cls) 809 void *callback_cls)
813{ 810{
814 DIR *dinfo; 811 DIR *dinfo;
815 struct dirent *finfo; 812 struct dirent *finfo;
@@ -827,61 +824,61 @@ GNUNET_DISK_directory_scan (const char *dirName,
827 while ((strlen (dname) > 0) && (dname[strlen (dname) - 1] == DIR_SEPARATOR)) 824 while ((strlen (dname) > 0) && (dname[strlen (dname) - 1] == DIR_SEPARATOR))
828 dname[strlen (dname) - 1] = '\0'; 825 dname[strlen (dname) - 1] = '\0';
829 if (0 != STAT (dname, &istat)) 826 if (0 != STAT (dname, &istat))
830 { 827 {
831 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", dname); 828 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", dname);
832 GNUNET_free (dname); 829 GNUNET_free (dname);
833 return GNUNET_SYSERR; 830 return GNUNET_SYSERR;
834 } 831 }
835 if (!S_ISDIR (istat.st_mode)) 832 if (!S_ISDIR (istat.st_mode))
836 { 833 {
837 LOG (GNUNET_ERROR_TYPE_WARNING, 834 LOG (GNUNET_ERROR_TYPE_WARNING, _("Expected `%s' to be a directory!\n"),
838 _("Expected `%s' to be a directory!\n"), dirName); 835 dirName);
839 GNUNET_free (dname); 836 GNUNET_free (dname);
840 return GNUNET_SYSERR; 837 return GNUNET_SYSERR;
841 } 838 }
842 errno = 0; 839 errno = 0;
843 dinfo = OPENDIR (dname); 840 dinfo = OPENDIR (dname);
844 if ((errno == EACCES) || (dinfo == NULL)) 841 if ((errno == EACCES) || (dinfo == NULL))
845 { 842 {
846 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "opendir", dname); 843 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "opendir", dname);
847 if (dinfo != NULL) 844 if (dinfo != NULL)
848 closedir (dinfo); 845 closedir (dinfo);
849 GNUNET_free (dname); 846 GNUNET_free (dname);
850 return GNUNET_SYSERR; 847 return GNUNET_SYSERR;
851 } 848 }
852 name_len = 256; 849 name_len = 256;
853 n_size = strlen (dname) + name_len + 2; 850 n_size = strlen (dname) + name_len + 2;
854 name = GNUNET_malloc (n_size); 851 name = GNUNET_malloc (n_size);
855 while ((finfo = readdir (dinfo)) != NULL) 852 while ((finfo = readdir (dinfo)) != NULL)
853 {
854 if ((0 == strcmp (finfo->d_name, ".")) ||
855 (0 == strcmp (finfo->d_name, "..")))
856 continue;
857 if (callback != NULL)
856 { 858 {
857 if ((0 == strcmp (finfo->d_name, ".")) || 859 if (name_len < strlen (finfo->d_name))
858 (0 == strcmp (finfo->d_name, ".."))) 860 {
859 continue; 861 GNUNET_free (name);
860 if (callback != NULL) 862 name_len = strlen (finfo->d_name);
861 { 863 n_size = strlen (dname) + name_len + 2;
862 if (name_len < strlen (finfo->d_name)) 864 name = GNUNET_malloc (n_size);
863 { 865 }
864 GNUNET_free (name); 866 /* dname can end in "/" only if dname == "/";
865 name_len = strlen (finfo->d_name); 867 * if dname does not end in "/", we need to add
866 n_size = strlen (dname) + name_len + 2; 868 * a "/" (otherwise, we must not!) */
867 name = GNUNET_malloc (n_size); 869 GNUNET_snprintf (name, n_size, "%s%s%s", dname,
868 } 870 (strcmp (dname, DIR_SEPARATOR_STR) ==
869 /* dname can end in "/" only if dname == "/"; 871 0) ? "" : DIR_SEPARATOR_STR, finfo->d_name);
870 * if dname does not end in "/", we need to add 872 if (GNUNET_OK != callback (callback_cls, name))
871 * a "/" (otherwise, we must not!) */ 873 {
872 GNUNET_snprintf (name, n_size, "%s%s%s", dname, 874 closedir (dinfo);
873 (strcmp (dname, DIR_SEPARATOR_STR) == 875 GNUNET_free (name);
874 0) ? "" : DIR_SEPARATOR_STR, finfo->d_name); 876 GNUNET_free (dname);
875 if (GNUNET_OK != callback (callback_cls, name)) 877 return GNUNET_SYSERR;
876 { 878 }
877 closedir (dinfo);
878 GNUNET_free (name);
879 GNUNET_free (dname);
880 return GNUNET_SYSERR;
881 }
882 }
883 count++;
884 } 879 }
880 count++;
881 }
885 closedir (dinfo); 882 closedir (dinfo);
886 GNUNET_free (name); 883 GNUNET_free (name);
887 GNUNET_free (dname); 884 GNUNET_free (dname);
@@ -933,7 +930,7 @@ struct GNUNET_DISK_DirectoryIterator
933 */ 930 */
934static void 931static void
935directory_iterator_task (void *cls, 932directory_iterator_task (void *cls,
936 const struct GNUNET_SCHEDULER_TaskContext *tc) 933 const struct GNUNET_SCHEDULER_TaskContext *tc)
937{ 934{
938 struct GNUNET_DISK_DirectoryIterator *iter = cls; 935 struct GNUNET_DISK_DirectoryIterator *iter = cls;
939 char *name; 936 char *name;
@@ -958,35 +955,35 @@ directory_iterator_task (void *cls,
958 * GNUNET_SYSERR if abort was YES 955 * GNUNET_SYSERR if abort was YES
959 */ 956 */
960int 957int
961GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator 958GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator *iter,
962 *iter, int can) 959 int can)
963{ 960{
964 struct dirent *finfo; 961 struct dirent *finfo;
965 962
966 GNUNET_assert (iter->next_name == NULL); 963 GNUNET_assert (iter->next_name == NULL);
967 if (can == GNUNET_YES) 964 if (can == GNUNET_YES)
968 { 965 {
969 closedir (iter->directory); 966 closedir (iter->directory);
970 GNUNET_free (iter->dirname); 967 GNUNET_free (iter->dirname);
971 GNUNET_free (iter); 968 GNUNET_free (iter);
972 return GNUNET_SYSERR; 969 return GNUNET_SYSERR;
973 } 970 }
974 while (NULL != (finfo = readdir (iter->directory))) 971 while (NULL != (finfo = readdir (iter->directory)))
975 { 972 {
976 if ((0 == strcmp (finfo->d_name, ".")) || 973 if ((0 == strcmp (finfo->d_name, ".")) ||
977 (0 == strcmp (finfo->d_name, ".."))) 974 (0 == strcmp (finfo->d_name, "..")))
978 continue; 975 continue;
979 GNUNET_asprintf (&iter->next_name, "%s%s%s", iter->dirname, 976 GNUNET_asprintf (&iter->next_name, "%s%s%s", iter->dirname,
980 DIR_SEPARATOR_STR, finfo->d_name); 977 DIR_SEPARATOR_STR, finfo->d_name);
981 break; 978 break;
982 } 979 }
983 if (finfo == NULL) 980 if (finfo == NULL)
984 { 981 {
985 GNUNET_DISK_directory_iterator_next (iter, GNUNET_YES); 982 GNUNET_DISK_directory_iterator_next (iter, GNUNET_YES);
986 return GNUNET_NO; 983 return GNUNET_NO;
987 } 984 }
988 GNUNET_SCHEDULER_add_with_priority (iter->priority, 985 GNUNET_SCHEDULER_add_with_priority (iter->priority, &directory_iterator_task,
989 &directory_iterator_task, iter); 986 iter);
990 return GNUNET_YES; 987 return GNUNET_YES;
991} 988}
992 989
@@ -1004,9 +1001,9 @@ GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator
1004 */ 1001 */
1005void 1002void
1006GNUNET_DISK_directory_iterator_start (enum GNUNET_SCHEDULER_Priority prio, 1003GNUNET_DISK_directory_iterator_start (enum GNUNET_SCHEDULER_Priority prio,
1007 const char *dirName, 1004 const char *dirName,
1008 GNUNET_DISK_DirectoryIteratorCallback 1005 GNUNET_DISK_DirectoryIteratorCallback
1009 callback, void *callback_cls) 1006 callback, void *callback_cls)
1010{ 1007{
1011 struct GNUNET_DISK_DirectoryIterator *di; 1008 struct GNUNET_DISK_DirectoryIterator *di;
1012 1009
@@ -1015,11 +1012,11 @@ GNUNET_DISK_directory_iterator_start (enum GNUNET_SCHEDULER_Priority prio,
1015 di->callback_cls = callback_cls; 1012 di->callback_cls = callback_cls;
1016 di->directory = OPENDIR (dirName); 1013 di->directory = OPENDIR (dirName);
1017 if (di->directory == NULL) 1014 if (di->directory == NULL)
1018 { 1015 {
1019 GNUNET_free (di); 1016 GNUNET_free (di);
1020 callback (callback_cls, NULL, NULL, NULL); 1017 callback (callback_cls, NULL, NULL, NULL);
1021 return; 1018 return;
1022 } 1019 }
1023 di->dirname = GNUNET_strdup (dirName); 1020 di->dirname = GNUNET_strdup (dirName);
1024 di->priority = prio; 1021 di->priority = prio;
1025 GNUNET_DISK_directory_iterator_next (di, GNUNET_NO); 1022 GNUNET_DISK_directory_iterator_next (di, GNUNET_NO);
@@ -1056,7 +1053,7 @@ GNUNET_DISK_directory_remove (const char *fileName)
1056 struct stat istat; 1053 struct stat istat;
1057 1054
1058 if (0 != LSTAT (fileName, &istat)) 1055 if (0 != LSTAT (fileName, &istat))
1059 return GNUNET_NO; /* file may not exist... */ 1056 return GNUNET_NO; /* file may not exist... */
1060 CHMOD (fileName, S_IWUSR | S_IRUSR | S_IXUSR); 1057 CHMOD (fileName, S_IWUSR | S_IRUSR | S_IXUSR);
1061 if (UNLINK (fileName) == 0) 1058 if (UNLINK (fileName) == 0)
1062 return GNUNET_OK; 1059 return GNUNET_OK;
@@ -1065,18 +1062,18 @@ GNUNET_DISK_directory_remove (const char *fileName)
1065 * sticky /tmp directory may result in EPERM on BSD. 1062 * sticky /tmp directory may result in EPERM on BSD.
1066 * So we also explicitly check "isDirectory" */ 1063 * So we also explicitly check "isDirectory" */
1067 (GNUNET_YES != GNUNET_DISK_directory_test (fileName))) 1064 (GNUNET_YES != GNUNET_DISK_directory_test (fileName)))
1068 { 1065 {
1069 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "rmdir", fileName); 1066 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "rmdir", fileName);
1070 return GNUNET_SYSERR; 1067 return GNUNET_SYSERR;
1071 } 1068 }
1072 if (GNUNET_SYSERR == 1069 if (GNUNET_SYSERR ==
1073 GNUNET_DISK_directory_scan (fileName, &remove_helper, NULL)) 1070 GNUNET_DISK_directory_scan (fileName, &remove_helper, NULL))
1074 return GNUNET_SYSERR; 1071 return GNUNET_SYSERR;
1075 if (0 != RMDIR (fileName)) 1072 if (0 != RMDIR (fileName))
1076 { 1073 {
1077 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "rmdir", fileName); 1074 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "rmdir", fileName);
1078 return GNUNET_SYSERR; 1075 return GNUNET_SYSERR;
1079 } 1076 }
1080 return GNUNET_OK; 1077 return GNUNET_OK;
1081} 1078}
1082 1079
@@ -1102,34 +1099,34 @@ GNUNET_DISK_file_copy (const char *src, const char *dst)
1102 return GNUNET_SYSERR; 1099 return GNUNET_SYSERR;
1103 pos = 0; 1100 pos = 0;
1104 in = GNUNET_DISK_file_open (src, GNUNET_DISK_OPEN_READ, 1101 in = GNUNET_DISK_file_open (src, GNUNET_DISK_OPEN_READ,
1105 GNUNET_DISK_PERM_NONE); 1102 GNUNET_DISK_PERM_NONE);
1106 if (!in) 1103 if (!in)
1107 return GNUNET_SYSERR; 1104 return GNUNET_SYSERR;
1108 out = 1105 out =
1109 GNUNET_DISK_file_open (dst, 1106 GNUNET_DISK_file_open (dst,
1110 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE | 1107 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE |
1111 GNUNET_DISK_OPEN_FAILIFEXISTS, 1108 GNUNET_DISK_OPEN_FAILIFEXISTS,
1112 GNUNET_DISK_PERM_USER_READ | 1109 GNUNET_DISK_PERM_USER_READ |
1113 GNUNET_DISK_PERM_USER_WRITE | 1110 GNUNET_DISK_PERM_USER_WRITE |
1114 GNUNET_DISK_PERM_GROUP_READ | 1111 GNUNET_DISK_PERM_GROUP_READ |
1115 GNUNET_DISK_PERM_GROUP_WRITE); 1112 GNUNET_DISK_PERM_GROUP_WRITE);
1116 if (!out) 1113 if (!out)
1117 { 1114 {
1118 GNUNET_DISK_file_close (in); 1115 GNUNET_DISK_file_close (in);
1119 return GNUNET_SYSERR; 1116 return GNUNET_SYSERR;
1120 } 1117 }
1121 buf = GNUNET_malloc (COPY_BLK_SIZE); 1118 buf = GNUNET_malloc (COPY_BLK_SIZE);
1122 while (pos < size) 1119 while (pos < size)
1123 { 1120 {
1124 len = COPY_BLK_SIZE; 1121 len = COPY_BLK_SIZE;
1125 if (len > size - pos) 1122 if (len > size - pos)
1126 len = size - pos; 1123 len = size - pos;
1127 if (len != GNUNET_DISK_file_read (in, buf, len)) 1124 if (len != GNUNET_DISK_file_read (in, buf, len))
1128 goto FAIL; 1125 goto FAIL;
1129 if (len != GNUNET_DISK_file_write (out, buf, len)) 1126 if (len != GNUNET_DISK_file_write (out, buf, len))
1130 goto FAIL; 1127 goto FAIL;
1131 pos += len; 1128 pos += len;
1132 } 1129 }
1133 GNUNET_free (buf); 1130 GNUNET_free (buf);
1134 GNUNET_DISK_file_close (in); 1131 GNUNET_DISK_file_close (in);
1135 GNUNET_DISK_file_close (out); 1132 GNUNET_DISK_file_close (out);
@@ -1154,17 +1151,17 @@ GNUNET_DISK_filename_canonicalize (char *fn)
1154 1151
1155 idx = fn; 1152 idx = fn;
1156 while (*idx) 1153 while (*idx)
1157 { 1154 {
1158 c = *idx; 1155 c = *idx;
1159
1160 if (c == '/' || c == '\\' || c == ':' || c == '*' || c == '?'
1161 || c == '"' || c == '<' || c == '>' || c == '|')
1162 {
1163 *idx = '_';
1164 }
1165 1156
1166 idx++; 1157 if (c == '/' || c == '\\' || c == ':' || c == '*' || c == '?' || c == '"' ||
1158 c == '<' || c == '>' || c == '|')
1159 {
1160 *idx = '_';
1167 } 1161 }
1162
1163 idx++;
1164 }
1168} 1165}
1169 1166
1170 1167
@@ -1184,12 +1181,12 @@ GNUNET_DISK_file_change_owner (const char *filename, const char *user)
1184 1181
1185 pws = getpwnam (user); 1182 pws = getpwnam (user);
1186 if (pws == NULL) 1183 if (pws == NULL)
1187 { 1184 {
1188 LOG (GNUNET_ERROR_TYPE_ERROR, 1185 LOG (GNUNET_ERROR_TYPE_ERROR,
1189 _("Cannot obtain information about user `%s': %s\n"), user, 1186 _("Cannot obtain information about user `%s': %s\n"), user,
1190 STRERROR (errno)); 1187 STRERROR (errno));
1191 return GNUNET_SYSERR; 1188 return GNUNET_SYSERR;
1192 } 1189 }
1193 if (0 != chown (filename, pws->pw_uid, pws->pw_gid)) 1190 if (0 != chown (filename, pws->pw_uid, pws->pw_gid))
1194 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "chown", filename); 1191 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "chown", filename);
1195#endif 1192#endif
@@ -1207,13 +1204,13 @@ GNUNET_DISK_file_change_owner (const char *filename, const char *user)
1207 */ 1204 */
1208int 1205int
1209GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart, 1206GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart,
1210 off_t lockEnd, int excl) 1207 off_t lockEnd, int excl)
1211{ 1208{
1212 if (fh == NULL) 1209 if (fh == NULL)
1213 { 1210 {
1214 errno = EINVAL; 1211 errno = EINVAL;
1215 return GNUNET_SYSERR; 1212 return GNUNET_SYSERR;
1216 } 1213 }
1217 1214
1218#ifndef MINGW 1215#ifndef MINGW
1219 struct flock fl; 1216 struct flock fl;
@@ -1232,13 +1229,12 @@ GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart,
1232 o.Offset = lockStart; 1229 o.Offset = lockStart;
1233 1230
1234 if (!LockFileEx 1231 if (!LockFileEx
1235 (fh->h, 1232 (fh->h, (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0) | LOCKFILE_FAIL_IMMEDIATELY,
1236 (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0) | LOCKFILE_FAIL_IMMEDIATELY, 0, 1233 0, lockEnd - lockStart, 0, &o))
1237 lockEnd - lockStart, 0, &o)) 1234 {
1238 { 1235 SetErrnoFromWinError (GetLastError ());
1239 SetErrnoFromWinError (GetLastError ()); 1236 return GNUNET_SYSERR;
1240 return GNUNET_SYSERR; 1237 }
1241 }
1242 1238
1243 return GNUNET_OK; 1239 return GNUNET_OK;
1244#endif 1240#endif
@@ -1254,13 +1250,13 @@ GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart,
1254 */ 1250 */
1255int 1251int
1256GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, off_t unlockStart, 1252GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, off_t unlockStart,
1257 off_t unlockEnd) 1253 off_t unlockEnd)
1258{ 1254{
1259 if (fh == NULL) 1255 if (fh == NULL)
1260 { 1256 {
1261 errno = EINVAL; 1257 errno = EINVAL;
1262 return GNUNET_SYSERR; 1258 return GNUNET_SYSERR;
1263 } 1259 }
1264 1260
1265#ifndef MINGW 1261#ifndef MINGW
1266 struct flock fl; 1262 struct flock fl;
@@ -1279,10 +1275,10 @@ GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, off_t unlockStart,
1279 o.Offset = unlockStart; 1275 o.Offset = unlockStart;
1280 1276
1281 if (!UnlockFileEx (fh->h, 0, unlockEnd - unlockStart, 0, &o)) 1277 if (!UnlockFileEx (fh->h, 0, unlockEnd - unlockStart, 0, &o))
1282 { 1278 {
1283 SetErrnoFromWinError (GetLastError ()); 1279 SetErrnoFromWinError (GetLastError ());
1284 return GNUNET_SYSERR; 1280 return GNUNET_SYSERR;
1285 } 1281 }
1286 1282
1287 return GNUNET_OK; 1283 return GNUNET_OK;
1288#endif 1284#endif
@@ -1303,7 +1299,7 @@ GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, off_t unlockStart,
1303 */ 1299 */
1304struct GNUNET_DISK_FileHandle * 1300struct GNUNET_DISK_FileHandle *
1305GNUNET_DISK_file_open (const char *fn, enum GNUNET_DISK_OpenFlags flags, 1301GNUNET_DISK_file_open (const char *fn, enum GNUNET_DISK_OpenFlags flags,
1306 enum GNUNET_DISK_AccessPermissions perm) 1302 enum GNUNET_DISK_AccessPermissions perm)
1307{ 1303{
1308 char *expfn; 1304 char *expfn;
1309 struct GNUNET_DISK_FileHandle *ret; 1305 struct GNUNET_DISK_FileHandle *ret;
@@ -1324,17 +1320,17 @@ GNUNET_DISK_file_open (const char *fn, enum GNUNET_DISK_OpenFlags flags,
1324#ifndef MINGW 1320#ifndef MINGW
1325 mode = 0; 1321 mode = 0;
1326 if (GNUNET_DISK_OPEN_READWRITE == (flags & GNUNET_DISK_OPEN_READWRITE)) 1322 if (GNUNET_DISK_OPEN_READWRITE == (flags & GNUNET_DISK_OPEN_READWRITE))
1327 oflags = O_RDWR; /* note: O_RDWR is NOT always O_RDONLY | O_WRONLY */ 1323 oflags = O_RDWR; /* note: O_RDWR is NOT always O_RDONLY | O_WRONLY */
1328 else if (flags & GNUNET_DISK_OPEN_READ) 1324 else if (flags & GNUNET_DISK_OPEN_READ)
1329 oflags = O_RDONLY; 1325 oflags = O_RDONLY;
1330 else if (flags & GNUNET_DISK_OPEN_WRITE) 1326 else if (flags & GNUNET_DISK_OPEN_WRITE)
1331 oflags = O_WRONLY; 1327 oflags = O_WRONLY;
1332 else 1328 else
1333 { 1329 {
1334 GNUNET_break (0); 1330 GNUNET_break (0);
1335 GNUNET_free (expfn); 1331 GNUNET_free (expfn);
1336 return NULL; 1332 return NULL;
1337 } 1333 }
1338 if (flags & GNUNET_DISK_OPEN_FAILIFEXISTS) 1334 if (flags & GNUNET_DISK_OPEN_FAILIFEXISTS)
1339 oflags |= (O_CREAT | O_EXCL); 1335 oflags |= (O_CREAT | O_EXCL);
1340 if (flags & GNUNET_DISK_OPEN_TRUNCATE) 1336 if (flags & GNUNET_DISK_OPEN_TRUNCATE)
@@ -1342,22 +1338,22 @@ GNUNET_DISK_file_open (const char *fn, enum GNUNET_DISK_OpenFlags flags,
1342 if (flags & GNUNET_DISK_OPEN_APPEND) 1338 if (flags & GNUNET_DISK_OPEN_APPEND)
1343 oflags |= O_APPEND; 1339 oflags |= O_APPEND;
1344 if (flags & GNUNET_DISK_OPEN_CREATE) 1340 if (flags & GNUNET_DISK_OPEN_CREATE)
1345 { 1341 {
1346 (void) GNUNET_DISK_directory_create_for_file (expfn); 1342 (void) GNUNET_DISK_directory_create_for_file (expfn);
1347 oflags |= O_CREAT; 1343 oflags |= O_CREAT;
1348 mode = translate_unix_perms (perm); 1344 mode = translate_unix_perms (perm);
1349 } 1345 }
1350 1346
1351 fd = open (expfn, oflags | O_LARGEFILE, mode); 1347 fd = open (expfn, oflags | O_LARGEFILE, mode);
1352 if (fd == -1) 1348 if (fd == -1)
1353 { 1349 {
1354 if (0 == (flags & GNUNET_DISK_OPEN_FAILIFEXISTS)) 1350 if (0 == (flags & GNUNET_DISK_OPEN_FAILIFEXISTS))
1355 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", expfn); 1351 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", expfn);
1356 else 1352 else
1357 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_DEBUG, "open", expfn); 1353 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_DEBUG, "open", expfn);
1358 GNUNET_free (expfn); 1354 GNUNET_free (expfn);
1359 return NULL; 1355 return NULL;
1360 } 1356 }
1361#else 1357#else
1362 access = 0; 1358 access = 0;
1363 disp = OPEN_ALWAYS; 1359 disp = OPEN_ALWAYS;
@@ -1370,48 +1366,47 @@ GNUNET_DISK_file_open (const char *fn, enum GNUNET_DISK_OpenFlags flags,
1370 access = FILE_WRITE_DATA; 1366 access = FILE_WRITE_DATA;
1371 1367
1372 if (flags & GNUNET_DISK_OPEN_FAILIFEXISTS) 1368 if (flags & GNUNET_DISK_OPEN_FAILIFEXISTS)
1373 { 1369 {
1374 disp = CREATE_NEW; 1370 disp = CREATE_NEW;
1375 } 1371 }
1376 else if (flags & GNUNET_DISK_OPEN_CREATE) 1372 else if (flags & GNUNET_DISK_OPEN_CREATE)
1377 { 1373 {
1378 (void) GNUNET_DISK_directory_create_for_file (expfn); 1374 (void) GNUNET_DISK_directory_create_for_file (expfn);
1379 if (flags & GNUNET_DISK_OPEN_TRUNCATE) 1375 if (flags & GNUNET_DISK_OPEN_TRUNCATE)
1380 disp = CREATE_ALWAYS; 1376 disp = CREATE_ALWAYS;
1381 else 1377 else
1382 disp = OPEN_ALWAYS; 1378 disp = OPEN_ALWAYS;
1383 } 1379 }
1384 else if (flags & GNUNET_DISK_OPEN_TRUNCATE) 1380 else if (flags & GNUNET_DISK_OPEN_TRUNCATE)
1385 { 1381 {
1386 disp = TRUNCATE_EXISTING; 1382 disp = TRUNCATE_EXISTING;
1387 } 1383 }
1388 else 1384 else
1389 { 1385 {
1390 disp = OPEN_EXISTING; 1386 disp = OPEN_EXISTING;
1391 } 1387 }
1392 1388
1393 /* TODO: access priviledges? */ 1389 /* TODO: access priviledges? */
1394 h = CreateFile (expfn, access, 1390 h = CreateFile (expfn, access,
1395 FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, 1391 FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
1396 NULL, disp, FILE_ATTRIBUTE_NORMAL, NULL); 1392 disp, FILE_ATTRIBUTE_NORMAL, NULL);
1397 if (h == INVALID_HANDLE_VALUE) 1393 if (h == INVALID_HANDLE_VALUE)
1394 {
1395 SetErrnoFromWinError (GetLastError ());
1396 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", expfn);
1397 GNUNET_free (expfn);
1398 return NULL;
1399 }
1400
1401 if (flags & GNUNET_DISK_OPEN_APPEND)
1402 if (SetFilePointer (h, 0, 0, FILE_END) == INVALID_SET_FILE_POINTER)
1398 { 1403 {
1399 SetErrnoFromWinError (GetLastError ()); 1404 SetErrnoFromWinError (GetLastError ());
1400 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", expfn); 1405 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "SetFilePointer", expfn);
1406 CloseHandle (h);
1401 GNUNET_free (expfn); 1407 GNUNET_free (expfn);
1402 return NULL; 1408 return NULL;
1403 } 1409 }
1404
1405 if (flags & GNUNET_DISK_OPEN_APPEND)
1406 if (SetFilePointer (h, 0, 0, FILE_END) == INVALID_SET_FILE_POINTER)
1407 {
1408 SetErrnoFromWinError (GetLastError ());
1409 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "SetFilePointer",
1410 expfn);
1411 CloseHandle (h);
1412 GNUNET_free (expfn);
1413 return NULL;
1414 }
1415#endif 1410#endif
1416 1411
1417 ret = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileHandle)); 1412 ret = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileHandle));
@@ -1435,28 +1430,28 @@ int
1435GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h) 1430GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h)
1436{ 1431{
1437 if (h == NULL) 1432 if (h == NULL)
1438 { 1433 {
1439 errno = EINVAL; 1434 errno = EINVAL;
1440 return GNUNET_SYSERR; 1435 return GNUNET_SYSERR;
1441 } 1436 }
1442 1437
1443#if MINGW 1438#if MINGW
1444 if (!CloseHandle (h->h)) 1439 if (!CloseHandle (h->h))
1445 { 1440 {
1446 SetErrnoFromWinError (GetLastError ()); 1441 SetErrnoFromWinError (GetLastError ());
1447 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "close"); 1442 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "close");
1448 GNUNET_free (h->oOverlapRead); 1443 GNUNET_free (h->oOverlapRead);
1449 GNUNET_free (h->oOverlapWrite); 1444 GNUNET_free (h->oOverlapWrite);
1450 GNUNET_free (h); 1445 GNUNET_free (h);
1451 return GNUNET_SYSERR; 1446 return GNUNET_SYSERR;
1452 } 1447 }
1453#else 1448#else
1454 if (close (h->fd) != 0) 1449 if (close (h->fd) != 0)
1455 { 1450 {
1456 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "close"); 1451 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "close");
1457 GNUNET_free (h); 1452 GNUNET_free (h);
1458 return GNUNET_SYSERR; 1453 return GNUNET_SYSERR;
1459 } 1454 }
1460#endif 1455#endif
1461 GNUNET_free (h); 1456 GNUNET_free (h);
1462 return GNUNET_OK; 1457 return GNUNET_OK;
@@ -1479,7 +1474,7 @@ GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h)
1479 */ 1474 */
1480char * 1475char *
1481GNUNET_DISK_get_home_filename (const struct GNUNET_CONFIGURATION_Handle *cfg, 1476GNUNET_DISK_get_home_filename (const struct GNUNET_CONFIGURATION_Handle *cfg,
1482 const char *serviceName, ...) 1477 const char *serviceName, ...)
1483{ 1478{
1484 const char *c; 1479 const char *c;
1485 char *pfx; 1480 char *pfx;
@@ -1488,45 +1483,44 @@ GNUNET_DISK_get_home_filename (const struct GNUNET_CONFIGURATION_Handle *cfg,
1488 unsigned int needed; 1483 unsigned int needed;
1489 1484
1490 if (GNUNET_OK != 1485 if (GNUNET_OK !=
1491 GNUNET_CONFIGURATION_get_value_filename (cfg, serviceName, "HOME", 1486 GNUNET_CONFIGURATION_get_value_filename (cfg, serviceName, "HOME", &pfx))
1492 &pfx))
1493 return NULL; 1487 return NULL;
1494 if (pfx == NULL) 1488 if (pfx == NULL)
1495 { 1489 {
1496 LOG (GNUNET_ERROR_TYPE_WARNING, 1490 LOG (GNUNET_ERROR_TYPE_WARNING,
1497 _("No `%s' specified for service `%s' in configuration.\n"), 1491 _("No `%s' specified for service `%s' in configuration.\n"), "HOME",
1498 "HOME", serviceName); 1492 serviceName);
1499 return NULL; 1493 return NULL;
1500 } 1494 }
1501 needed = strlen (pfx) + 2; 1495 needed = strlen (pfx) + 2;
1502 if ((pfx[strlen (pfx) - 1] != '/') && (pfx[strlen (pfx) - 1] != '\\')) 1496 if ((pfx[strlen (pfx) - 1] != '/') && (pfx[strlen (pfx) - 1] != '\\'))
1503 needed++; 1497 needed++;
1504 va_start (ap, serviceName); 1498 va_start (ap, serviceName);
1505 while (1) 1499 while (1)
1506 { 1500 {
1507 c = va_arg (ap, const char *); 1501 c = va_arg (ap, const char *);
1508 1502
1509 if (c == NULL) 1503 if (c == NULL)
1510 break; 1504 break;
1511 needed += strlen (c); 1505 needed += strlen (c);
1512 if ((c[strlen (c) - 1] != '/') && (c[strlen (c) - 1] != '\\')) 1506 if ((c[strlen (c) - 1] != '/') && (c[strlen (c) - 1] != '\\'))
1513 needed++; 1507 needed++;
1514 } 1508 }
1515 va_end (ap); 1509 va_end (ap);
1516 ret = GNUNET_malloc (needed); 1510 ret = GNUNET_malloc (needed);
1517 strcpy (ret, pfx); 1511 strcpy (ret, pfx);
1518 GNUNET_free (pfx); 1512 GNUNET_free (pfx);
1519 va_start (ap, serviceName); 1513 va_start (ap, serviceName);
1520 while (1) 1514 while (1)
1521 { 1515 {
1522 c = va_arg (ap, const char *); 1516 c = va_arg (ap, const char *);
1523 1517
1524 if (c == NULL) 1518 if (c == NULL)
1525 break; 1519 break;
1526 if ((c[strlen (c) - 1] != '/') && (c[strlen (c) - 1] != '\\')) 1520 if ((c[strlen (c) - 1] != '/') && (c[strlen (c) - 1] != '\\'))
1527 strcat (ret, DIR_SEPARATOR_STR); 1521 strcat (ret, DIR_SEPARATOR_STR);
1528 strcat (ret, c); 1522 strcat (ret, c);
1529 } 1523 }
1530 va_end (ap); 1524 va_end (ap);
1531 if ((ret[strlen (ret) - 1] != '/') && (ret[strlen (ret) - 1] != '\\')) 1525 if ((ret[strlen (ret) - 1] != '/') && (ret[strlen (ret) - 1] != '\\'))
1532 (void) GNUNET_DISK_directory_create_for_file (ret); 1526 (void) GNUNET_DISK_directory_create_for_file (ret);
@@ -1575,56 +1569,56 @@ struct GNUNET_DISK_MapHandle
1575 */ 1569 */
1576void * 1570void *
1577GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h, 1571GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h,
1578 struct GNUNET_DISK_MapHandle **m, 1572 struct GNUNET_DISK_MapHandle **m,
1579 enum GNUNET_DISK_MapType access, size_t len) 1573 enum GNUNET_DISK_MapType access, size_t len)
1580{ 1574{
1581 if (h == NULL) 1575 if (h == NULL)
1582 { 1576 {
1583 errno = EINVAL; 1577 errno = EINVAL;
1584 return NULL; 1578 return NULL;
1585 } 1579 }
1586 1580
1587#ifdef MINGW 1581#ifdef MINGW
1588 DWORD mapAccess, protect; 1582 DWORD mapAccess, protect;
1589 1583
1590 if ((access & GNUNET_DISK_MAP_TYPE_READ) && 1584 if ((access & GNUNET_DISK_MAP_TYPE_READ) &&
1591 (access & GNUNET_DISK_MAP_TYPE_WRITE)) 1585 (access & GNUNET_DISK_MAP_TYPE_WRITE))
1592 { 1586 {
1593 protect = PAGE_READWRITE; 1587 protect = PAGE_READWRITE;
1594 mapAccess = FILE_MAP_ALL_ACCESS; 1588 mapAccess = FILE_MAP_ALL_ACCESS;
1595 } 1589 }
1596 else if (access & GNUNET_DISK_MAP_TYPE_READ) 1590 else if (access & GNUNET_DISK_MAP_TYPE_READ)
1597 { 1591 {
1598 protect = PAGE_READONLY; 1592 protect = PAGE_READONLY;
1599 mapAccess = FILE_MAP_READ; 1593 mapAccess = FILE_MAP_READ;
1600 } 1594 }
1601 else if (access & GNUNET_DISK_MAP_TYPE_WRITE) 1595 else if (access & GNUNET_DISK_MAP_TYPE_WRITE)
1602 { 1596 {
1603 protect = PAGE_READWRITE; 1597 protect = PAGE_READWRITE;
1604 mapAccess = FILE_MAP_WRITE; 1598 mapAccess = FILE_MAP_WRITE;
1605 } 1599 }
1606 else 1600 else
1607 { 1601 {
1608 GNUNET_break (0); 1602 GNUNET_break (0);
1609 return NULL; 1603 return NULL;
1610 } 1604 }
1611 1605
1612 *m = GNUNET_malloc (sizeof (struct GNUNET_DISK_MapHandle)); 1606 *m = GNUNET_malloc (sizeof (struct GNUNET_DISK_MapHandle));
1613 (*m)->h = CreateFileMapping (h->h, NULL, protect, 0, 0, NULL); 1607 (*m)->h = CreateFileMapping (h->h, NULL, protect, 0, 0, NULL);
1614 if ((*m)->h == INVALID_HANDLE_VALUE) 1608 if ((*m)->h == INVALID_HANDLE_VALUE)
1615 { 1609 {
1616 SetErrnoFromWinError (GetLastError ()); 1610 SetErrnoFromWinError (GetLastError ());
1617 GNUNET_free (*m); 1611 GNUNET_free (*m);
1618 return NULL; 1612 return NULL;
1619 } 1613 }
1620 1614
1621 (*m)->addr = MapViewOfFile ((*m)->h, mapAccess, 0, 0, len); 1615 (*m)->addr = MapViewOfFile ((*m)->h, mapAccess, 0, 0, len);
1622 if (!(*m)->addr) 1616 if (!(*m)->addr)
1623 { 1617 {
1624 SetErrnoFromWinError (GetLastError ()); 1618 SetErrnoFromWinError (GetLastError ());
1625 CloseHandle ((*m)->h); 1619 CloseHandle ((*m)->h);
1626 GNUNET_free (*m); 1620 GNUNET_free (*m);
1627 } 1621 }
1628 1622
1629 return (*m)->addr; 1623 return (*m)->addr;
1630#else 1624#else
@@ -1639,10 +1633,10 @@ GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h,
1639 (*m)->addr = mmap (NULL, len, prot, MAP_SHARED, h->fd, 0); 1633 (*m)->addr = mmap (NULL, len, prot, MAP_SHARED, h->fd, 0);
1640 GNUNET_assert (NULL != (*m)->addr); 1634 GNUNET_assert (NULL != (*m)->addr);
1641 if (MAP_FAILED == (*m)->addr) 1635 if (MAP_FAILED == (*m)->addr)
1642 { 1636 {
1643 GNUNET_free (*m); 1637 GNUNET_free (*m);
1644 return NULL; 1638 return NULL;
1645 } 1639 }
1646 (*m)->len = len; 1640 (*m)->len = len;
1647 return (*m)->addr; 1641 return (*m)->addr;
1648#endif 1642#endif
@@ -1659,20 +1653,20 @@ GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h)
1659 int ret; 1653 int ret;
1660 1654
1661 if (h == NULL) 1655 if (h == NULL)
1662 { 1656 {
1663 errno = EINVAL; 1657 errno = EINVAL;
1664 return GNUNET_SYSERR; 1658 return GNUNET_SYSERR;
1665 } 1659 }
1666 1660
1667#ifdef MINGW 1661#ifdef MINGW
1668 ret = UnmapViewOfFile (h->addr) ? GNUNET_OK : GNUNET_SYSERR; 1662 ret = UnmapViewOfFile (h->addr) ? GNUNET_OK : GNUNET_SYSERR;
1669 if (ret != GNUNET_OK) 1663 if (ret != GNUNET_OK)
1670 SetErrnoFromWinError (GetLastError ()); 1664 SetErrnoFromWinError (GetLastError ());
1671 if (!CloseHandle (h->h) && (ret == GNUNET_OK)) 1665 if (!CloseHandle (h->h) && (ret == GNUNET_OK))
1672 { 1666 {
1673 ret = GNUNET_SYSERR; 1667 ret = GNUNET_SYSERR;
1674 SetErrnoFromWinError (GetLastError ()); 1668 SetErrnoFromWinError (GetLastError ());
1675 } 1669 }
1676#else 1670#else
1677 ret = munmap (h->addr, h->len) != -1 ? GNUNET_OK : GNUNET_SYSERR; 1671 ret = munmap (h->addr, h->len) != -1 ? GNUNET_OK : GNUNET_SYSERR;
1678#endif 1672#endif
@@ -1690,10 +1684,10 @@ int
1690GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h) 1684GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h)
1691{ 1685{
1692 if (h == NULL) 1686 if (h == NULL)
1693 { 1687 {
1694 errno = EINVAL; 1688 errno = EINVAL;
1695 return GNUNET_SYSERR; 1689 return GNUNET_SYSERR;
1696 } 1690 }
1697 1691
1698#ifdef MINGW 1692#ifdef MINGW
1699 int ret; 1693 int ret;
@@ -1722,8 +1716,8 @@ GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h)
1722 unlike CreatePipe, which returns a bool for success or failure. */ 1716 unlike CreatePipe, which returns a bool for success or failure. */
1723static int 1717static int
1724create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr, 1718create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr,
1725 LPSECURITY_ATTRIBUTES sa_ptr, DWORD psize, 1719 LPSECURITY_ATTRIBUTES sa_ptr, DWORD psize,
1726 DWORD dwReadMode, DWORD dwWriteMode) 1720 DWORD dwReadMode, DWORD dwWriteMode)
1727{ 1721{
1728 /* Default to error. */ 1722 /* Default to error. */
1729 *read_pipe_ptr = *write_pipe_ptr = INVALID_HANDLE_VALUE; 1723 *read_pipe_ptr = *write_pipe_ptr = INVALID_HANDLE_VALUE;
@@ -1740,103 +1734,103 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr,
1740 * Retrying will probably never be necessary, but we want 1734 * Retrying will probably never be necessary, but we want
1741 * to be as robust as possible. */ 1735 * to be as robust as possible. */
1742 while (1) 1736 while (1)
1743 { 1737 {
1744 static volatile LONG pipe_unique_id; 1738 static volatile LONG pipe_unique_id;
1745 1739
1746 snprintf (pipename, sizeof pipename, "\\\\.\\pipe\\gnunet-%d-%ld", 1740 snprintf (pipename, sizeof pipename, "\\\\.\\pipe\\gnunet-%d-%ld",
1747 getpid (), InterlockedIncrement ((LONG *) & pipe_unique_id)); 1741 getpid (), InterlockedIncrement ((LONG *) & pipe_unique_id));
1748#if DEBUG_PIPE 1742#if DEBUG_PIPE
1749 LOG (GNUNET_ERROR_TYPE_DEBUG, 1743 LOG (GNUNET_ERROR_TYPE_DEBUG, "CreateNamedPipe: name = %s, size = %lu\n",
1750 "CreateNamedPipe: name = %s, size = %lu\n", pipename, psize); 1744 pipename, psize);
1751#endif 1745#endif
1752 /* Use CreateNamedPipe instead of CreatePipe, because the latter 1746 /* Use CreateNamedPipe instead of CreatePipe, because the latter
1753 * returns a write handle that does not permit FILE_READ_ATTRIBUTES 1747 * returns a write handle that does not permit FILE_READ_ATTRIBUTES
1754 * access, on versions of win32 earlier than WinXP SP2. 1748 * access, on versions of win32 earlier than WinXP SP2.
1755 * CreatePipe also stupidly creates a full duplex pipe, which is 1749 * CreatePipe also stupidly creates a full duplex pipe, which is
1756 * a waste, since only a single direction is actually used. 1750 * a waste, since only a single direction is actually used.
1757 * It's important to only allow a single instance, to ensure that 1751 * It's important to only allow a single instance, to ensure that
1758 * the pipe was not created earlier by some other process, even if 1752 * the pipe was not created earlier by some other process, even if
1759 * the pid has been reused. We avoid FILE_FLAG_FIRST_PIPE_INSTANCE 1753 * the pid has been reused. We avoid FILE_FLAG_FIRST_PIPE_INSTANCE
1760 * because that is only available for Win2k SP2 and WinXP. */ 1754 * because that is only available for Win2k SP2 and WinXP. */
1761 read_pipe = CreateNamedPipeA (pipename, PIPE_ACCESS_INBOUND | dwReadMode, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 1, /* max instances */ 1755 read_pipe = CreateNamedPipeA (pipename, PIPE_ACCESS_INBOUND | dwReadMode, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 1, /* max instances */
1762 psize, /* output buffer size */ 1756 psize, /* output buffer size */
1763 psize, /* input buffer size */ 1757 psize, /* input buffer size */
1764 NMPWAIT_USE_DEFAULT_WAIT, sa_ptr); 1758 NMPWAIT_USE_DEFAULT_WAIT, sa_ptr);
1765 1759
1766 if (read_pipe != INVALID_HANDLE_VALUE) 1760 if (read_pipe != INVALID_HANDLE_VALUE)
1767 { 1761 {
1768#if DEBUG_PIPE 1762#if DEBUG_PIPE
1769 LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p\n", read_pipe); 1763 LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p\n", read_pipe);
1770#endif 1764#endif
1771 break; 1765 break;
1772 } 1766 }
1773 1767
1774 DWORD err = GetLastError (); 1768 DWORD err = GetLastError ();
1775 1769
1776 switch (err) 1770 switch (err)
1777 { 1771 {
1778 case ERROR_PIPE_BUSY: 1772 case ERROR_PIPE_BUSY:
1779 /* The pipe is already open with compatible parameters. 1773 /* The pipe is already open with compatible parameters.
1780 * Pick a new name and retry. */ 1774 * Pick a new name and retry. */
1781#if DEBUG_PIPE 1775#if DEBUG_PIPE
1782 LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe busy, retrying\n"); 1776 LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe busy, retrying\n");
1783#endif 1777#endif
1784 continue; 1778 continue;
1785 case ERROR_ACCESS_DENIED: 1779 case ERROR_ACCESS_DENIED:
1786 /* The pipe is already open with incompatible parameters. 1780 /* The pipe is already open with incompatible parameters.
1787 * Pick a new name and retry. */ 1781 * Pick a new name and retry. */
1788#if DEBUG_PIPE 1782#if DEBUG_PIPE
1789 LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe access denied, retrying\n"); 1783 LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe access denied, retrying\n");
1790#endif 1784#endif
1791 continue; 1785 continue;
1792 case ERROR_CALL_NOT_IMPLEMENTED: 1786 case ERROR_CALL_NOT_IMPLEMENTED:
1793 /* We are on an older Win9x platform without named pipes. 1787 /* We are on an older Win9x platform without named pipes.
1794 * Return an anonymous pipe as the best approximation. */ 1788 * Return an anonymous pipe as the best approximation. */
1795#if DEBUG_PIPE 1789#if DEBUG_PIPE
1796 LOG (GNUNET_ERROR_TYPE_DEBUG, 1790 LOG (GNUNET_ERROR_TYPE_DEBUG,
1797 "CreateNamedPipe not implemented, resorting to " 1791 "CreateNamedPipe not implemented, resorting to "
1798 "CreatePipe: size = %lu\n", psize); 1792 "CreatePipe: size = %lu\n", psize);
1799#endif 1793#endif
1800 if (CreatePipe (read_pipe_ptr, write_pipe_ptr, sa_ptr, psize)) 1794 if (CreatePipe (read_pipe_ptr, write_pipe_ptr, sa_ptr, psize))
1801 { 1795 {
1802#if DEBUG_PIPE 1796#if DEBUG_PIPE
1803 LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p\n", 1797 LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p\n",
1804 *read_pipe_ptr); 1798 *read_pipe_ptr);
1805 LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe write handle = %p\n", 1799 LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe write handle = %p\n",
1806 *write_pipe_ptr); 1800 *write_pipe_ptr);
1807#endif 1801#endif
1808 return GNUNET_OK; 1802 return GNUNET_OK;
1809 } 1803 }
1810 err = GetLastError (); 1804 err = GetLastError ();
1811 LOG (GNUNET_ERROR_TYPE_ERROR, "CreatePipe failed: %d\n", err); 1805 LOG (GNUNET_ERROR_TYPE_ERROR, "CreatePipe failed: %d\n", err);
1812 return err; 1806 return err;
1813 default: 1807 default:
1814 LOG (GNUNET_ERROR_TYPE_ERROR, "CreateNamedPipe failed: %d\n", err); 1808 LOG (GNUNET_ERROR_TYPE_ERROR, "CreateNamedPipe failed: %d\n", err);
1815 return err; 1809 return err;
1816 }
1817 /* NOTREACHED */
1818 } 1810 }
1811 /* NOTREACHED */
1812 }
1819#if DEBUG_PIPE 1813#if DEBUG_PIPE
1820 LOG (GNUNET_ERROR_TYPE_DEBUG, "CreateFile: name = %s\n", pipename); 1814 LOG (GNUNET_ERROR_TYPE_DEBUG, "CreateFile: name = %s\n", pipename);
1821#endif 1815#endif
1822 1816
1823 /* Open the named pipe for writing. 1817 /* Open the named pipe for writing.
1824 * Be sure to permit FILE_READ_ATTRIBUTES access. */ 1818 * Be sure to permit FILE_READ_ATTRIBUTES access. */
1825 write_pipe = CreateFileA (pipename, GENERIC_WRITE | FILE_READ_ATTRIBUTES, 0, /* share mode */ 1819 write_pipe = CreateFileA (pipename, GENERIC_WRITE | FILE_READ_ATTRIBUTES, 0, /* share mode */
1826 sa_ptr, OPEN_EXISTING, dwWriteMode, /* flags and attributes */ 1820 sa_ptr, OPEN_EXISTING, dwWriteMode, /* flags and attributes */
1827 0); /* handle to template file */ 1821 0); /* handle to template file */
1828 1822
1829 if (write_pipe == INVALID_HANDLE_VALUE) 1823 if (write_pipe == INVALID_HANDLE_VALUE)
1830 { 1824 {
1831 /* Failure. */ 1825 /* Failure. */
1832 DWORD err = GetLastError (); 1826 DWORD err = GetLastError ();
1833 1827
1834#if DEBUG_PIPE 1828#if DEBUG_PIPE
1835 LOG (GNUNET_ERROR_TYPE_DEBUG, "CreateFile failed: %d\n", err); 1829 LOG (GNUNET_ERROR_TYPE_DEBUG, "CreateFile failed: %d\n", err);
1836#endif 1830#endif
1837 CloseHandle (read_pipe); 1831 CloseHandle (read_pipe);
1838 return err; 1832 return err;
1839 } 1833 }
1840#if DEBUG_PIPE 1834#if DEBUG_PIPE
1841 LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe write handle = %p\n", write_pipe); 1835 LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe write handle = %p\n", write_pipe);
1842#endif 1836#endif
@@ -1863,7 +1857,7 @@ GNUNET_DISK_pipe (int blocking, int inherit_read, int inherit_write)
1863 struct GNUNET_DISK_FileHandle *fds; 1857 struct GNUNET_DISK_FileHandle *fds;
1864 1858
1865 p = GNUNET_malloc (sizeof (struct GNUNET_DISK_PipeHandle) + 1859 p = GNUNET_malloc (sizeof (struct GNUNET_DISK_PipeHandle) +
1866 2 * sizeof (struct GNUNET_DISK_FileHandle)); 1860 2 * sizeof (struct GNUNET_DISK_FileHandle));
1867 fds = (struct GNUNET_DISK_FileHandle *) &p[1]; 1861 fds = (struct GNUNET_DISK_FileHandle *) &p[1];
1868 p->fd[0] = &fds[0]; 1862 p->fd[0] = &fds[0];
1869 p->fd[1] = &fds[1]; 1863 p->fd[1] = &fds[1];
@@ -1875,13 +1869,13 @@ GNUNET_DISK_pipe (int blocking, int inherit_read, int inherit_write)
1875 1869
1876 ret = pipe (fd); 1870 ret = pipe (fd);
1877 if (ret == -1) 1871 if (ret == -1)
1878 { 1872 {
1879 eno = errno; 1873 eno = errno;
1880 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe"); 1874 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe");
1881 GNUNET_free (p); 1875 GNUNET_free (p);
1882 errno = eno; 1876 errno = eno;
1883 return NULL; 1877 return NULL;
1884 } 1878 }
1885 p->fd[0]->fd = fd[0]; 1879 p->fd[0]->fd = fd[0];
1886 p->fd[1]->fd = fd[1]; 1880 p->fd[1]->fd = fd[1];
1887 ret = 0; 1881 ret = 0;
@@ -1905,62 +1899,62 @@ GNUNET_DISK_pipe (int blocking, int inherit_read, int inherit_write)
1905 if (0 > fcntl (fd[1], F_SETFD, flags)) 1899 if (0 > fcntl (fd[1], F_SETFD, flags))
1906 ret = -1; 1900 ret = -1;
1907 if (ret == -1) 1901 if (ret == -1)
1908 { 1902 {
1909 eno = errno; 1903 eno = errno;
1910 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fcntl"); 1904 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fcntl");
1911 GNUNET_break (0 == close (p->fd[0]->fd)); 1905 GNUNET_break (0 == close (p->fd[0]->fd));
1912 GNUNET_break (0 == close (p->fd[1]->fd)); 1906 GNUNET_break (0 == close (p->fd[1]->fd));
1913 GNUNET_free (p); 1907 GNUNET_free (p);
1914 errno = eno; 1908 errno = eno;
1915 return NULL; 1909 return NULL;
1916 } 1910 }
1917#else 1911#else
1918 BOOL ret; 1912 BOOL ret;
1919 HANDLE tmp_handle; 1913 HANDLE tmp_handle;
1920 1914
1921 ret = 1915 ret =
1922 create_selectable_pipe (&p->fd[0]->h, &p->fd[1]->h, NULL, 0, 1916 create_selectable_pipe (&p->fd[0]->h, &p->fd[1]->h, NULL, 0,
1923 FILE_FLAG_OVERLAPPED, FILE_FLAG_OVERLAPPED); 1917 FILE_FLAG_OVERLAPPED, FILE_FLAG_OVERLAPPED);
1924 if (!ret) 1918 if (!ret)
1925 { 1919 {
1926 GNUNET_free (p); 1920 GNUNET_free (p);
1927 SetErrnoFromWinError (GetLastError ()); 1921 SetErrnoFromWinError (GetLastError ());
1928 return NULL; 1922 return NULL;
1929 } 1923 }
1930 if (!DuplicateHandle 1924 if (!DuplicateHandle
1931 (GetCurrentProcess (), p->fd[0]->h, GetCurrentProcess (), &tmp_handle, 1925 (GetCurrentProcess (), p->fd[0]->h, GetCurrentProcess (), &tmp_handle, 0,
1932 0, inherit_read == GNUNET_YES ? TRUE : FALSE, DUPLICATE_SAME_ACCESS)) 1926 inherit_read == GNUNET_YES ? TRUE : FALSE, DUPLICATE_SAME_ACCESS))
1933 { 1927 {
1934 SetErrnoFromWinError (GetLastError ()); 1928 SetErrnoFromWinError (GetLastError ());
1935 CloseHandle (p->fd[0]->h); 1929 CloseHandle (p->fd[0]->h);
1936 CloseHandle (p->fd[1]->h); 1930 CloseHandle (p->fd[1]->h);
1937 GNUNET_free (p); 1931 GNUNET_free (p);
1938 return NULL; 1932 return NULL;
1939 } 1933 }
1940 CloseHandle (p->fd[0]->h); 1934 CloseHandle (p->fd[0]->h);
1941 p->fd[0]->h = tmp_handle; 1935 p->fd[0]->h = tmp_handle;
1942 1936
1943 if (!DuplicateHandle 1937 if (!DuplicateHandle
1944 (GetCurrentProcess (), p->fd[1]->h, GetCurrentProcess (), &tmp_handle, 1938 (GetCurrentProcess (), p->fd[1]->h, GetCurrentProcess (), &tmp_handle, 0,
1945 0, inherit_write == GNUNET_YES ? TRUE : FALSE, DUPLICATE_SAME_ACCESS)) 1939 inherit_write == GNUNET_YES ? TRUE : FALSE, DUPLICATE_SAME_ACCESS))
1946 { 1940 {
1947 SetErrnoFromWinError (GetLastError ()); 1941 SetErrnoFromWinError (GetLastError ());
1948 CloseHandle (p->fd[0]->h); 1942 CloseHandle (p->fd[0]->h);
1949 CloseHandle (p->fd[1]->h); 1943 CloseHandle (p->fd[1]->h);
1950 GNUNET_free (p); 1944 GNUNET_free (p);
1951 return NULL; 1945 return NULL;
1952 } 1946 }
1953 CloseHandle (p->fd[1]->h); 1947 CloseHandle (p->fd[1]->h);
1954 p->fd[1]->h = tmp_handle; 1948 p->fd[1]->h = tmp_handle;
1955 if (!blocking) 1949 if (!blocking)
1956 { 1950 {
1957 DWORD mode; 1951 DWORD mode;
1958 1952
1959 mode = PIPE_NOWAIT; 1953 mode = PIPE_NOWAIT;
1960 SetNamedPipeHandleState (p->fd[0]->h, &mode, NULL, NULL); 1954 SetNamedPipeHandleState (p->fd[0]->h, &mode, NULL, NULL);
1961 SetNamedPipeHandleState (p->fd[1]->h, &mode, NULL, NULL); 1955 SetNamedPipeHandleState (p->fd[1]->h, &mode, NULL, NULL);
1962 /* this always fails on Windows 95, so we don't care about error handling */ 1956 /* this always fails on Windows 95, so we don't care about error handling */
1963 } 1957 }
1964 p->fd[0]->type = GNUNET_PIPE; 1958 p->fd[0]->type = GNUNET_PIPE;
1965 p->fd[1]->type = GNUNET_PIPE; 1959 p->fd[1]->type = GNUNET_PIPE;
1966 1960
@@ -1989,51 +1983,51 @@ GNUNET_DISK_pipe (int blocking, int inherit_read, int inherit_write)
1989 */ 1983 */
1990int 1984int
1991GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p, 1985GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p,
1992 enum GNUNET_DISK_PipeEnd end) 1986 enum GNUNET_DISK_PipeEnd end)
1993{ 1987{
1994 int ret = GNUNET_OK; 1988 int ret = GNUNET_OK;
1995 int save; 1989 int save;
1996 1990
1997#ifdef MINGW 1991#ifdef MINGW
1998 if (end == GNUNET_DISK_PIPE_END_READ) 1992 if (end == GNUNET_DISK_PIPE_END_READ)
1993 {
1994 if (!CloseHandle (p->fd[0]->h))
1999 { 1995 {
2000 if (!CloseHandle (p->fd[0]->h)) 1996 SetErrnoFromWinError (GetLastError ());
2001 { 1997 ret = GNUNET_SYSERR;
2002 SetErrnoFromWinError (GetLastError ());
2003 ret = GNUNET_SYSERR;
2004 }
2005 p->fd[0]->h = INVALID_HANDLE_VALUE;
2006 } 1998 }
1999 p->fd[0]->h = INVALID_HANDLE_VALUE;
2000 }
2007 else if (end == GNUNET_DISK_PIPE_END_WRITE) 2001 else if (end == GNUNET_DISK_PIPE_END_WRITE)
2002 {
2003 if (!CloseHandle (p->fd[1]->h))
2008 { 2004 {
2009 if (!CloseHandle (p->fd[1]->h)) 2005 SetErrnoFromWinError (GetLastError ());
2010 { 2006 ret = GNUNET_SYSERR;
2011 SetErrnoFromWinError (GetLastError ());
2012 ret = GNUNET_SYSERR;
2013 }
2014 p->fd[1]->h = INVALID_HANDLE_VALUE;
2015 } 2007 }
2008 p->fd[1]->h = INVALID_HANDLE_VALUE;
2009 }
2016 save = errno; 2010 save = errno;
2017#else 2011#else
2018 save = 0; 2012 save = 0;
2019 if (end == GNUNET_DISK_PIPE_END_READ) 2013 if (end == GNUNET_DISK_PIPE_END_READ)
2014 {
2015 if (0 != close (p->fd[0]->fd))
2020 { 2016 {
2021 if (0 != close (p->fd[0]->fd)) 2017 ret = GNUNET_SYSERR;
2022 { 2018 save = errno;
2023 ret = GNUNET_SYSERR;
2024 save = errno;
2025 }
2026 p->fd[0]->fd = -1;
2027 } 2019 }
2020 p->fd[0]->fd = -1;
2021 }
2028 else if (end == GNUNET_DISK_PIPE_END_WRITE) 2022 else if (end == GNUNET_DISK_PIPE_END_WRITE)
2023 {
2024 if (0 != close (p->fd[1]->fd))
2029 { 2025 {
2030 if (0 != close (p->fd[1]->fd)) 2026 ret = GNUNET_SYSERR;
2031 { 2027 save = errno;
2032 ret = GNUNET_SYSERR;
2033 save = errno;
2034 }
2035 p->fd[1]->fd = -1;
2036 } 2028 }
2029 p->fd[1]->fd = -1;
2030 }
2037#endif 2031#endif
2038 errno = save; 2032 errno = save;
2039 return ret; 2033 return ret;
@@ -2053,35 +2047,35 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p)
2053 2047
2054#ifdef MINGW 2048#ifdef MINGW
2055 if (!CloseHandle (p->fd[0]->h)) 2049 if (!CloseHandle (p->fd[0]->h))
2056 { 2050 {
2057 SetErrnoFromWinError (GetLastError ()); 2051 SetErrnoFromWinError (GetLastError ());
2058 ret = GNUNET_SYSERR; 2052 ret = GNUNET_SYSERR;
2059 } 2053 }
2060 if (!CloseHandle (p->fd[1]->h)) 2054 if (!CloseHandle (p->fd[1]->h))
2061 { 2055 {
2062 SetErrnoFromWinError (GetLastError ()); 2056 SetErrnoFromWinError (GetLastError ());
2063 ret = GNUNET_SYSERR; 2057 ret = GNUNET_SYSERR;
2064 } 2058 }
2065 save = errno; 2059 save = errno;
2066#else 2060#else
2067 save = 0; 2061 save = 0;
2068 if (p->fd[0]->fd != -1) 2062 if (p->fd[0]->fd != -1)
2063 {
2064 if (0 != close (p->fd[0]->fd))
2069 { 2065 {
2070 if (0 != close (p->fd[0]->fd)) 2066 ret = GNUNET_SYSERR;
2071 { 2067 save = errno;
2072 ret = GNUNET_SYSERR;
2073 save = errno;
2074 }
2075 } 2068 }
2069 }
2076 2070
2077 if (p->fd[1]->fd != -1) 2071 if (p->fd[1]->fd != -1)
2072 {
2073 if (0 != close (p->fd[1]->fd))
2078 { 2074 {
2079 if (0 != close (p->fd[1]->fd)) 2075 ret = GNUNET_SYSERR;
2080 { 2076 save = errno;
2081 ret = GNUNET_SYSERR;
2082 save = errno;
2083 }
2084 } 2077 }
2078 }
2085#endif 2079#endif
2086 GNUNET_free (p); 2080 GNUNET_free (p);
2087 errno = save; 2081 errno = save;
@@ -2098,7 +2092,7 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p)
2098 */ 2092 */
2099struct GNUNET_DISK_FileHandle * 2093struct GNUNET_DISK_FileHandle *
2100GNUNET_DISK_npipe_create (char **fn, enum GNUNET_DISK_OpenFlags flags, 2094GNUNET_DISK_npipe_create (char **fn, enum GNUNET_DISK_OpenFlags flags,
2101 enum GNUNET_DISK_AccessPermissions perm) 2095 enum GNUNET_DISK_AccessPermissions perm)
2102{ 2096{
2103#ifdef MINGW 2097#ifdef MINGW
2104 struct GNUNET_DISK_FileHandle *ret; 2098 struct GNUNET_DISK_FileHandle *ret;
@@ -2118,71 +2112,70 @@ GNUNET_DISK_npipe_create (char **fn, enum GNUNET_DISK_OpenFlags flags,
2118 openMode |= FILE_FLAG_FIRST_PIPE_INSTANCE; 2112 openMode |= FILE_FLAG_FIRST_PIPE_INSTANCE;
2119 2113
2120 while (h == NULL) 2114 while (h == NULL)
2121 { 2115 {
2122 DWORD error_code; 2116 DWORD error_code;
2123 2117
2124 name = NULL; 2118 name = NULL;
2125 if (*fn != NULL) 2119 if (*fn != NULL)
2126 { 2120 {
2127 GNUNET_asprintf (&name, "\\\\.\\pipe\\%.246s", fn); 2121 GNUNET_asprintf (&name, "\\\\.\\pipe\\%.246s", fn);
2128#if DEBUG_NPIPE 2122#if DEBUG_NPIPE
2129 LOG (GNUNET_ERROR_TYPE_DEBUG, 2123 LOG (GNUNET_ERROR_TYPE_DEBUG,
2130 "Trying to create an instance of named pipe `%s'\n", name); 2124 "Trying to create an instance of named pipe `%s'\n", name);
2131#endif 2125#endif
2132 h = CreateNamedPipe (name, openMode | FILE_FLAG_OVERLAPPED, 2126 h = CreateNamedPipe (name, openMode | FILE_FLAG_OVERLAPPED,
2133 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 2, 1, 1, 2127 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 2, 1, 1, 0,
2134 0, NULL); 2128 NULL);
2135 } 2129 }
2136 else 2130 else
2137 { 2131 {
2138 GNUNET_asprintf (fn, "\\\\.\\pipe\\gnunet-%llu", 2132 GNUNET_asprintf (fn, "\\\\.\\pipe\\gnunet-%llu",
2139 GNUNET_CRYPTO_random_u64 2133 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
2140 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX)); 2134 UINT64_MAX));
2141#if DEBUG_NPIPE 2135#if DEBUG_NPIPE
2142 LOG (GNUNET_ERROR_TYPE_DEBUG, 2136 LOG (GNUNET_ERROR_TYPE_DEBUG, "Trying to create unique named pipe `%s'\n",
2143 "Trying to create unique named pipe `%s'\n", *fn); 2137 *fn);
2144#endif 2138#endif
2145 h = CreateNamedPipe (*fn, 2139 h = CreateNamedPipe (*fn,
2146 openMode | FILE_FLAG_OVERLAPPED | 2140 openMode | FILE_FLAG_OVERLAPPED |
2147 FILE_FLAG_FIRST_PIPE_INSTANCE, 2141 FILE_FLAG_FIRST_PIPE_INSTANCE,
2148 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 2, 1, 1, 2142 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 2, 1, 1, 0,
2149 0, NULL); 2143 NULL);
2150 } 2144 }
2151 error_code = GetLastError (); 2145 error_code = GetLastError ();
2152 if (name) 2146 if (name)
2153 GNUNET_free (name); 2147 GNUNET_free (name);
2154 /* don't re-set name to NULL yet */ 2148 /* don't re-set name to NULL yet */
2155 if (h == INVALID_HANDLE_VALUE) 2149 if (h == INVALID_HANDLE_VALUE)
2156 { 2150 {
2157 SetErrnoFromWinError (error_code); 2151 SetErrnoFromWinError (error_code);
2158#if DEBUG_NPIPE 2152#if DEBUG_NPIPE
2159 LOG (GNUNET_ERROR_TYPE_DEBUG, 2153 LOG (GNUNET_ERROR_TYPE_DEBUG,
2160 "Pipe creation have failed because of %d, errno is %d\n", 2154 "Pipe creation have failed because of %d, errno is %d\n", error_code,
2161 error_code, errno); 2155 errno);
2162#endif 2156#endif
2163 if (name == NULL) 2157 if (name == NULL)
2164 { 2158 {
2165#if DEBUG_NPIPE 2159#if DEBUG_NPIPE
2166 LOG (GNUNET_ERROR_TYPE_DEBUG, 2160 LOG (GNUNET_ERROR_TYPE_DEBUG,
2167 "Pipe was to be unique, considering re-creation\n"); 2161 "Pipe was to be unique, considering re-creation\n");
2168#endif 2162#endif
2169 GNUNET_free (*fn); 2163 GNUNET_free (*fn);
2170 *fn = NULL; 2164 *fn = NULL;
2171 if (error_code != ERROR_ACCESS_DENIED 2165 if (error_code != ERROR_ACCESS_DENIED && error_code != ERROR_PIPE_BUSY)
2172 && error_code != ERROR_PIPE_BUSY) 2166 {
2173 { 2167 return NULL;
2174 return NULL; 2168 }
2175 }
2176#if DEBUG_NPIPE 2169#if DEBUG_NPIPE
2177 LOG (GNUNET_ERROR_TYPE_DEBUG, 2170 LOG (GNUNET_ERROR_TYPE_DEBUG,
2178 "Pipe name was not unique, trying again\n"); 2171 "Pipe name was not unique, trying again\n");
2179#endif 2172#endif
2180 h = NULL; 2173 h = NULL;
2181 } 2174 }
2182 else 2175 else
2183 return NULL; 2176 return NULL;
2184 }
2185 } 2177 }
2178 }
2186 errno = 0; 2179 errno = 0;
2187 2180
2188 ret = GNUNET_malloc (sizeof (*ret)); 2181 ret = GNUNET_malloc (sizeof (*ret));
@@ -2198,22 +2191,22 @@ GNUNET_DISK_npipe_create (char **fn, enum GNUNET_DISK_OpenFlags flags,
2198 return ret; 2191 return ret;
2199#else 2192#else
2200 if (*fn == NULL) 2193 if (*fn == NULL)
2194 {
2195 char dir[] = "/tmp/gnunet-pipe-XXXXXX";
2196
2197 if (mkdtemp (dir) == NULL)
2201 { 2198 {
2202 char dir[] = "/tmp/gnunet-pipe-XXXXXX"; 2199 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "mkdtemp");
2203 2200 return NULL;
2204 if (mkdtemp (dir) == NULL)
2205 {
2206 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "mkdtemp");
2207 return NULL;
2208 }
2209 GNUNET_asprintf (fn, "%s/child-control", dir);
2210 } 2201 }
2202 GNUNET_asprintf (fn, "%s/child-control", dir);
2203 }
2211 2204
2212 if (mkfifo (*fn, translate_unix_perms (perm)) == -1) 2205 if (mkfifo (*fn, translate_unix_perms (perm)) == -1)
2213 { 2206 {
2214 if ((errno != EEXIST) || (0 != (flags & GNUNET_DISK_OPEN_FAILIFEXISTS))) 2207 if ((errno != EEXIST) || (0 != (flags & GNUNET_DISK_OPEN_FAILIFEXISTS)))
2215 return NULL; 2208 return NULL;
2216 } 2209 }
2217 2210
2218 flags = flags & (~GNUNET_DISK_OPEN_FAILIFEXISTS); 2211 flags = flags & (~GNUNET_DISK_OPEN_FAILIFEXISTS);
2219 return GNUNET_DISK_file_open (*fn, flags, perm); 2212 return GNUNET_DISK_file_open (*fn, flags, perm);
@@ -2231,7 +2224,7 @@ GNUNET_DISK_npipe_create (char **fn, enum GNUNET_DISK_OpenFlags flags,
2231 */ 2224 */
2232struct GNUNET_DISK_FileHandle * 2225struct GNUNET_DISK_FileHandle *
2233GNUNET_DISK_npipe_open (const char *fn, enum GNUNET_DISK_OpenFlags flags, 2226GNUNET_DISK_npipe_open (const char *fn, enum GNUNET_DISK_OpenFlags flags,
2234 enum GNUNET_DISK_AccessPermissions perm) 2227 enum GNUNET_DISK_AccessPermissions perm)
2235{ 2228{
2236#ifdef MINGW 2229#ifdef MINGW
2237 struct GNUNET_DISK_FileHandle *ret; 2230 struct GNUNET_DISK_FileHandle *ret;
@@ -2247,12 +2240,12 @@ GNUNET_DISK_npipe_open (const char *fn, enum GNUNET_DISK_OpenFlags flags,
2247 openMode = GENERIC_WRITE; 2240 openMode = GENERIC_WRITE;
2248 2241
2249 h = CreateFile (fn, openMode, 0, NULL, OPEN_EXISTING, 2242 h = CreateFile (fn, openMode, 0, NULL, OPEN_EXISTING,
2250 FILE_FLAG_OVERLAPPED | FILE_READ_ATTRIBUTES, NULL); 2243 FILE_FLAG_OVERLAPPED | FILE_READ_ATTRIBUTES, NULL);
2251 if (h == INVALID_HANDLE_VALUE) 2244 if (h == INVALID_HANDLE_VALUE)
2252 { 2245 {
2253 SetErrnoFromWinError (GetLastError ()); 2246 SetErrnoFromWinError (GetLastError ());
2254 return NULL; 2247 return NULL;
2255 } 2248 }
2256 2249
2257 ret = GNUNET_malloc (sizeof (*ret)); 2250 ret = GNUNET_malloc (sizeof (*ret));
2258 ret->h = h; 2251 ret->h = h;
@@ -2284,10 +2277,10 @@ GNUNET_DISK_npipe_close (struct GNUNET_DISK_FileHandle *pipe)
2284 2277
2285 ret = CloseHandle (pipe->h); 2278 ret = CloseHandle (pipe->h);
2286 if (!ret) 2279 if (!ret)
2287 { 2280 {
2288 SetErrnoFromWinError (GetLastError ()); 2281 SetErrnoFromWinError (GetLastError ());
2289 return GNUNET_SYSERR; 2282 return GNUNET_SYSERR;
2290 } 2283 }
2291 else 2284 else
2292 return GNUNET_OK; 2285 return GNUNET_OK;
2293#endif 2286#endif
@@ -2303,17 +2296,17 @@ GNUNET_DISK_npipe_close (struct GNUNET_DISK_FileHandle *pipe)
2303 */ 2296 */
2304const struct GNUNET_DISK_FileHandle * 2297const struct GNUNET_DISK_FileHandle *
2305GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p, 2298GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p,
2306 enum GNUNET_DISK_PipeEnd n) 2299 enum GNUNET_DISK_PipeEnd n)
2307{ 2300{
2308 switch (n) 2301 switch (n)
2309 { 2302 {
2310 case GNUNET_DISK_PIPE_END_READ: 2303 case GNUNET_DISK_PIPE_END_READ:
2311 case GNUNET_DISK_PIPE_END_WRITE: 2304 case GNUNET_DISK_PIPE_END_WRITE:
2312 return p->fd[n]; 2305 return p->fd[n];
2313 default: 2306 default:
2314 GNUNET_break (0); 2307 GNUNET_break (0);
2315 return NULL; 2308 return NULL;
2316 } 2309 }
2317} 2310}
2318 2311
2319 2312
@@ -2327,7 +2320,7 @@ GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p,
2327 */ 2320 */
2328int 2321int
2329GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh, 2322GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh,
2330 void *dst, size_t dst_len) 2323 void *dst, size_t dst_len)
2331{ 2324{
2332#ifdef MINGW 2325#ifdef MINGW
2333 if (dst_len < sizeof (HANDLE)) 2326 if (dst_len < sizeof (HANDLE))
diff --git a/src/util/getopt.c b/src/util/getopt.c
index 4a36678b2..317bc0748 100644
--- a/src/util/getopt.c
+++ b/src/util/getopt.c
@@ -198,19 +198,20 @@ static char *posixly_correct;
198/* Avoid depending on library functions or files 198/* Avoid depending on library functions or files
199 whose names are inconsistent. */ 199 whose names are inconsistent. */
200 200
201char *getenv (); 201char *
202getenv ();
202 203
203static char * 204static char *
204my_index (str, chr) 205my_index (str, chr)
205 const char *str; 206 const char *str;
206 int chr; 207 int chr;
207{ 208{
208 while (*str) 209 while (*str)
209 { 210 {
210 if (*str == chr) 211 if (*str == chr)
211 return (char *) str; 212 return (char *) str;
212 str++; 213 str++;
213 } 214 }
214 return 0; 215 return 0;
215} 216}
216 217
@@ -222,7 +223,8 @@ my_index (str, chr)
222#if !defined (__STDC__) || !__STDC__ 223#if !defined (__STDC__) || !__STDC__
223/* gcc with -traditional declares the built-in strlen to return int, 224/* gcc with -traditional declares the built-in strlen to return int,
224 and has done so at least since version 2.4.5. -- rms. */ 225 and has done so at least since version 2.4.5. -- rms. */
225extern int strlen (const char *); 226extern int
227strlen (const char *);
226#endif /* not __STDC__ */ 228#endif /* not __STDC__ */
227#endif /* __GNUC__ */ 229#endif /* __GNUC__ */
228 230
@@ -256,7 +258,7 @@ extern pid_t __libc_pid;
256 is valid for the getopt call we must make sure that the ARGV passed 258 is valid for the getopt call we must make sure that the ARGV passed
257 to getopt is that one passed to the process. */ 259 to getopt is that one passed to the process. */
258static void 260static void
259 __attribute__ ((unused)) store_args_and_env (int argc, char *const *argv) 261 __attribute__ ((unused)) store_args_and_env (int argc, char *const *argv)
260{ 262{
261 /* XXX This is no good solution. We should rather copy the args so 263 /* XXX This is no good solution. We should rather copy the args so
262 * that we can compare them later. But we must not use malloc(3). */ 264 * that we can compare them later. But we must not use malloc(3). */
@@ -287,12 +289,13 @@ text_set_element (__libc_subinit, store_args_and_env);
287 the new indices of the non-options in ARGV after they are moved. */ 289 the new indices of the non-options in ARGV after they are moved. */
288 290
289#if defined (__STDC__) && __STDC__ 291#if defined (__STDC__) && __STDC__
290static void exchange (char **); 292static void
293exchange (char **);
291#endif 294#endif
292 295
293static void 296static void
294exchange (argv) 297exchange (argv)
295 char **argv; 298 char **argv;
296{ 299{
297 int bottom = first_nonopt; 300 int bottom = first_nonopt;
298 int middle = last_nonopt; 301 int middle = last_nonopt;
@@ -309,61 +312,61 @@ exchange (argv)
309 * string can work normally. Our top argument must be in the range 312 * string can work normally. Our top argument must be in the range
310 * of the string. */ 313 * of the string. */
311 if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len) 314 if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len)
312 { 315 {
313 /* We must extend the array. The user plays games with us and 316 /* We must extend the array. The user plays games with us and
314 * presents new arguments. */ 317 * presents new arguments. */
315 char *new_str = malloc (top + 1); 318 char *new_str = malloc (top + 1);
316 319
317 if (new_str == NULL) 320 if (new_str == NULL)
318 nonoption_flags_len = nonoption_flags_max_len = 0; 321 nonoption_flags_len = nonoption_flags_max_len = 0;
319 else 322 else
320 { 323 {
321 memcpy (new_str, __getopt_nonoption_flags, nonoption_flags_max_len); 324 memcpy (new_str, __getopt_nonoption_flags, nonoption_flags_max_len);
322 memset (&new_str[nonoption_flags_max_len], '\0', 325 memset (&new_str[nonoption_flags_max_len], '\0',
323 top + 1 - nonoption_flags_max_len); 326 top + 1 - nonoption_flags_max_len);
324 nonoption_flags_max_len = top + 1; 327 nonoption_flags_max_len = top + 1;
325 __getopt_nonoption_flags = new_str; 328 __getopt_nonoption_flags = new_str;
326 }
327 } 329 }
330 }
328#endif 331#endif
329 332
330 while (top > middle && middle > bottom) 333 while (top > middle && middle > bottom)
334 {
335 if (top - middle > middle - bottom)
331 { 336 {
332 if (top - middle > middle - bottom) 337 /* Bottom segment is the short one. */
333 { 338 int len = middle - bottom;
334 /* Bottom segment is the short one. */ 339 register int i;
335 int len = middle - bottom; 340
336 register int i; 341 /* Swap it with the top part of the top segment. */
337 342 for (i = 0; i < len; i++)
338 /* Swap it with the top part of the top segment. */ 343 {
339 for (i = 0; i < len; i++) 344 tem = argv[bottom + i];
340 { 345 argv[bottom + i] = argv[top - (middle - bottom) + i];
341 tem = argv[bottom + i]; 346 argv[top - (middle - bottom) + i] = tem;
342 argv[bottom + i] = argv[top - (middle - bottom) + i]; 347 SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
343 argv[top - (middle - bottom) + i] = tem; 348 }
344 SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); 349 /* Exclude the moved bottom segment from further swapping. */
345 } 350 top -= len;
346 /* Exclude the moved bottom segment from further swapping. */ 351 }
347 top -= len; 352 else
348 } 353 {
349 else 354 /* Top segment is the short one. */
350 { 355 int len = top - middle;
351 /* Top segment is the short one. */ 356 register int i;
352 int len = top - middle; 357
353 register int i; 358 /* Swap it with the bottom part of the bottom segment. */
354 359 for (i = 0; i < len; i++)
355 /* Swap it with the bottom part of the bottom segment. */ 360 {
356 for (i = 0; i < len; i++) 361 tem = argv[bottom + i];
357 { 362 argv[bottom + i] = argv[middle + i];
358 tem = argv[bottom + i]; 363 argv[middle + i] = tem;
359 argv[bottom + i] = argv[middle + i]; 364 SWAP_FLAGS (bottom + i, middle + i);
360 argv[middle + i] = tem; 365 }
361 SWAP_FLAGS (bottom + i, middle + i); 366 /* Exclude the moved top segment from further swapping. */
362 } 367 bottom += len;
363 /* Exclude the moved top segment from further swapping. */
364 bottom += len;
365 }
366 } 368 }
369 }
367 370
368 /* Update records for the slots the non-options now occupy. */ 371 /* Update records for the slots the non-options now occupy. */
369 372
@@ -374,13 +377,14 @@ exchange (argv)
374/* Initialize the internal data when the first call is made. */ 377/* Initialize the internal data when the first call is made. */
375 378
376#if defined (__STDC__) && __STDC__ 379#if defined (__STDC__) && __STDC__
377static const char *_getopt_initialize (int, char *const *, const char *); 380static const char *
381_getopt_initialize (int, char *const *, const char *);
378#endif 382#endif
379static const char * 383static const char *
380_getopt_initialize (argc, argv, optstring) 384_getopt_initialize (argc, argv, optstring)
381 int argc; 385 int argc;
382 char *const *argv; 386 char *const *argv;
383 const char *optstring; 387 const char *optstring;
384{ 388{
385 /* Start processing options with ARGV-element 1 (since ARGV-element 0 389 /* Start processing options with ARGV-element 1 (since ARGV-element 0
386 * is the program name); the sequence of previously skipped 390 * is the program name); the sequence of previously skipped
@@ -395,50 +399,48 @@ _getopt_initialize (argc, argv, optstring)
395 /* Determine how to handle the ordering of options and nonoptions. */ 399 /* Determine how to handle the ordering of options and nonoptions. */
396 400
397 if (optstring[0] == '-') 401 if (optstring[0] == '-')
398 { 402 {
399 ordering = RETURN_IN_ORDER; 403 ordering = RETURN_IN_ORDER;
400 ++optstring; 404 ++optstring;
401 } 405 }
402 else if (optstring[0] == '+') 406 else if (optstring[0] == '+')
403 { 407 {
404 ordering = REQUIRE_ORDER; 408 ordering = REQUIRE_ORDER;
405 ++optstring; 409 ++optstring;
406 } 410 }
407 else if (posixly_correct != NULL) 411 else if (posixly_correct != NULL)
408 ordering = REQUIRE_ORDER; 412 ordering = REQUIRE_ORDER;
409 else 413 else
410 ordering = PERMUTE; 414 ordering = PERMUTE;
411 415
412#ifdef _LIBC 416#ifdef _LIBC
413 if (posixly_correct == NULL && argc == original_argc 417 if (posixly_correct == NULL && argc == original_argc && argv == original_argv)
414 && argv == original_argv) 418 {
419 if (nonoption_flags_max_len == 0)
415 { 420 {
416 if (nonoption_flags_max_len == 0) 421 if (__getopt_nonoption_flags == NULL ||
417 { 422 __getopt_nonoption_flags[0] == '\0')
418 if (__getopt_nonoption_flags == NULL || 423 nonoption_flags_max_len = -1;
419 __getopt_nonoption_flags[0] == '\0') 424 else
420 nonoption_flags_max_len = -1; 425 {
421 else 426 const char *orig_str = __getopt_nonoption_flags;
422 { 427 int len = nonoption_flags_max_len = strlen (orig_str);
423 const char *orig_str = __getopt_nonoption_flags; 428
424 int len = nonoption_flags_max_len = strlen (orig_str); 429 if (nonoption_flags_max_len < argc)
425 430 nonoption_flags_max_len = argc;
426 if (nonoption_flags_max_len < argc) 431 __getopt_nonoption_flags = (char *) malloc (nonoption_flags_max_len);
427 nonoption_flags_max_len = argc; 432 if (__getopt_nonoption_flags == NULL)
428 __getopt_nonoption_flags = 433 nonoption_flags_max_len = -1;
429 (char *) malloc (nonoption_flags_max_len); 434 else
430 if (__getopt_nonoption_flags == NULL) 435 {
431 nonoption_flags_max_len = -1; 436 memcpy (__getopt_nonoption_flags, orig_str, len);
432 else 437 memset (&__getopt_nonoption_flags[len], '\0',
433 { 438 nonoption_flags_max_len - len);
434 memcpy (__getopt_nonoption_flags, orig_str, len); 439 }
435 memset (&__getopt_nonoption_flags[len], '\0', 440 }
436 nonoption_flags_max_len - len);
437 }
438 }
439 }
440 nonoption_flags_len = nonoption_flags_max_len;
441 } 441 }
442 nonoption_flags_len = nonoption_flags_max_len;
443 }
442 else 444 else
443 nonoption_flags_len = 0; 445 nonoption_flags_len = 0;
444#endif 446#endif
@@ -504,8 +506,8 @@ _getopt_initialize (argc, argv, optstring)
504 506
505static int 507static int
506GN_getopt_internal (int argc, char *const *argv, const char *optstring, 508GN_getopt_internal (int argc, char *const *argv, const char *optstring,
507 const struct GNoption *longopts, int *longind, 509 const struct GNoption *longopts, int *longind,
508 int long_only) 510 int long_only)
509{ 511{
510 static int __getopt_initialized = 0; 512 static int __getopt_initialized = 0;
511 static int GNopterr = 1; 513 static int GNopterr = 1;
@@ -513,12 +515,12 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring,
513 GNoptarg = NULL; 515 GNoptarg = NULL;
514 516
515 if (GNoptind == 0 || !__getopt_initialized) 517 if (GNoptind == 0 || !__getopt_initialized)
516 { 518 {
517 if (GNoptind == 0) 519 if (GNoptind == 0)
518 GNoptind = 1; /* Don't scan ARGV[0], the program name. */ 520 GNoptind = 1; /* Don't scan ARGV[0], the program name. */
519 optstring = _getopt_initialize (argc, argv, optstring); 521 optstring = _getopt_initialize (argc, argv, optstring);
520 __getopt_initialized = 1; 522 __getopt_initialized = 1;
521 } 523 }
522 524
523 /* Test whether ARGV[GNoptind] points to a non-option argument. 525 /* Test whether ARGV[GNoptind] points to a non-option argument.
524 * Either it does not have option syntax, or there is an environment flag 526 * Either it does not have option syntax, or there is an environment flag
@@ -533,81 +535,81 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring,
533#endif 535#endif
534 536
535 if (nextchar == NULL || *nextchar == '\0') 537 if (nextchar == NULL || *nextchar == '\0')
538 {
539 /* Advance to the next ARGV-element. */
540
541 /* Give FIRST_NONOPT & LAST_NONOPT rational values if GNoptind has been
542 * moved back by the user (who may also have changed the arguments). */
543 if (last_nonopt > GNoptind)
544 last_nonopt = GNoptind;
545 if (first_nonopt > GNoptind)
546 first_nonopt = GNoptind;
547
548 if (ordering == PERMUTE)
536 { 549 {
537 /* Advance to the next ARGV-element. */ 550 /* If we have just processed some options following some non-options,
538 551 * exchange them so that the options come first. */
539 /* Give FIRST_NONOPT & LAST_NONOPT rational values if GNoptind has been 552
540 * moved back by the user (who may also have changed the arguments). */ 553 if (first_nonopt != last_nonopt && last_nonopt != GNoptind)
541 if (last_nonopt > GNoptind) 554 exchange ((char **) argv);
542 last_nonopt = GNoptind; 555 else if (last_nonopt != GNoptind)
543 if (first_nonopt > GNoptind) 556 first_nonopt = GNoptind;
544 first_nonopt = GNoptind; 557
545 558 /* Skip any additional non-options
546 if (ordering == PERMUTE) 559 * and extend the range of non-options previously skipped. */
547 { 560
548 /* If we have just processed some options following some non-options, 561 while (GNoptind < argc && NONOPTION_P)
549 * exchange them so that the options come first. */ 562 GNoptind++;
550 563 last_nonopt = GNoptind;
551 if (first_nonopt != last_nonopt && last_nonopt != GNoptind) 564 }
552 exchange ((char **) argv); 565
553 else if (last_nonopt != GNoptind) 566 /* The special ARGV-element `--' means premature end of options.
554 first_nonopt = GNoptind; 567 * Skip it like a null option,
555 568 * then exchange with previous non-options as if it were an option,
556 /* Skip any additional non-options 569 * then skip everything else like a non-option. */
557 * and extend the range of non-options previously skipped. */ 570 if (GNoptind != argc && !strcmp (argv[GNoptind], "--"))
558 571 {
559 while (GNoptind < argc && NONOPTION_P) 572 GNoptind++;
560 GNoptind++; 573
561 last_nonopt = GNoptind; 574 if (first_nonopt != last_nonopt && last_nonopt != GNoptind)
562 } 575 exchange ((char **) argv);
563 576 else if (first_nonopt == last_nonopt)
564 /* The special ARGV-element `--' means premature end of options. 577 first_nonopt = GNoptind;
565 * Skip it like a null option, 578 last_nonopt = argc;
566 * then exchange with previous non-options as if it were an option, 579
567 * then skip everything else like a non-option. */ 580 GNoptind = argc;
568 if (GNoptind != argc && !strcmp (argv[GNoptind], "--"))
569 {
570 GNoptind++;
571
572 if (first_nonopt != last_nonopt && last_nonopt != GNoptind)
573 exchange ((char **) argv);
574 else if (first_nonopt == last_nonopt)
575 first_nonopt = GNoptind;
576 last_nonopt = argc;
577
578 GNoptind = argc;
579 }
580
581 /* If we have done all the ARGV-elements, stop the scan
582 * and back over any non-options that we skipped and permuted. */
583
584 if (GNoptind == argc)
585 {
586 /* Set the next-arg-index to point at the non-options
587 * that we previously skipped, so the caller will digest them. */
588 if (first_nonopt != last_nonopt)
589 GNoptind = first_nonopt;
590 return -1;
591 }
592
593 /* If we have come to a non-option and did not permute it,
594 * either stop the scan or describe it to the caller and pass it by. */
595
596 if (NONOPTION_P)
597 {
598 if (ordering == REQUIRE_ORDER)
599 return -1;
600 GNoptarg = argv[GNoptind++];
601 return 1;
602 }
603
604 /* We have found another option-ARGV-element.
605 * Skip the initial punctuation. */
606
607 nextchar =
608 (argv[GNoptind] + 1 + (longopts != NULL && argv[GNoptind][1] == '-'));
609 } 581 }
610 582
583 /* If we have done all the ARGV-elements, stop the scan
584 * and back over any non-options that we skipped and permuted. */
585
586 if (GNoptind == argc)
587 {
588 /* Set the next-arg-index to point at the non-options
589 * that we previously skipped, so the caller will digest them. */
590 if (first_nonopt != last_nonopt)
591 GNoptind = first_nonopt;
592 return -1;
593 }
594
595 /* If we have come to a non-option and did not permute it,
596 * either stop the scan or describe it to the caller and pass it by. */
597
598 if (NONOPTION_P)
599 {
600 if (ordering == REQUIRE_ORDER)
601 return -1;
602 GNoptarg = argv[GNoptind++];
603 return 1;
604 }
605
606 /* We have found another option-ARGV-element.
607 * Skip the initial punctuation. */
608
609 nextchar =
610 (argv[GNoptind] + 1 + (longopts != NULL && argv[GNoptind][1] == '-'));
611 }
612
611 /* Decode the current option-ARGV-element. */ 613 /* Decode the current option-ARGV-element. */
612 614
613 /* Check whether the ARGV-element is a long option. 615 /* Check whether the ARGV-element is a long option.
@@ -626,138 +628,134 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring,
626 if (longopts != NULL && 628 if (longopts != NULL &&
627 (argv[GNoptind][1] == '-' || 629 (argv[GNoptind][1] == '-' ||
628 (long_only && 630 (long_only &&
629 (argv[GNoptind][2] || !my_index (optstring, argv[GNoptind][1]))))) 631 (argv[GNoptind][2] || !my_index (optstring, argv[GNoptind][1])))))
630 { 632 {
631 char *nameend; 633 char *nameend;
632 const struct GNoption *p; 634 const struct GNoption *p;
633 const struct GNoption *pfound = NULL; 635 const struct GNoption *pfound = NULL;
634 int exact = 0; 636 int exact = 0;
635 int ambig = 0; 637 int ambig = 0;
636 int indfound = -1; 638 int indfound = -1;
637 int option_index; 639 int option_index;
638 640
639 for (nameend = nextchar; *nameend && *nameend != '='; nameend++) 641 for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
640 /* Do nothing. */ ; 642 /* Do nothing. */ ;
643
644 /* Test all long options for either exact match
645 * or abbreviated matches. */
646 for (p = longopts, option_index = 0; p->name; p++, option_index++)
647 if (!strncmp (p->name, nextchar, nameend - nextchar))
648 {
649 if ((unsigned int) (nameend - nextchar) ==
650 (unsigned int) strlen (p->name))
651 {
652 /* Exact match found. */
653 pfound = p;
654 indfound = option_index;
655 exact = 1;
656 break;
657 }
658 else if (pfound == NULL)
659 {
660 /* First nonexact match found. */
661 pfound = p;
662 indfound = option_index;
663 }
664 else
665 /* Second or later nonexact match found. */
666 ambig = 1;
667 }
641 668
642 /* Test all long options for either exact match 669 if (ambig && !exact)
643 * or abbreviated matches. */ 670 {
644 for (p = longopts, option_index = 0; p->name; p++, option_index++) 671 if (GNopterr)
645 if (!strncmp (p->name, nextchar, nameend - nextchar)) 672 fprintf (stderr, _("%s: option `%s' is ambiguous\n"), argv[0],
646 { 673 argv[GNoptind]);
647 if ((unsigned int) (nameend - nextchar) == 674 nextchar += strlen (nextchar);
648 (unsigned int) strlen (p->name)) 675 GNoptind++;
649 { 676 return '?';
650 /* Exact match found. */ 677 }
651 pfound = p;
652 indfound = option_index;
653 exact = 1;
654 break;
655 }
656 else if (pfound == NULL)
657 {
658 /* First nonexact match found. */
659 pfound = p;
660 indfound = option_index;
661 }
662 else
663 /* Second or later nonexact match found. */
664 ambig = 1;
665 }
666 678
667 if (ambig && !exact) 679 if (pfound != NULL)
668 { 680 {
669 if (GNopterr) 681 option_index = indfound;
670 fprintf (stderr, _("%s: option `%s' is ambiguous\n"), argv[0], 682 GNoptind++;
671 argv[GNoptind]); 683 if (*nameend)
672 nextchar += strlen (nextchar); 684 {
673 GNoptind++; 685 /* Don't test has_arg with >, because some C compilers don't
674 return '?'; 686 * allow it to be used on enums. */
675 } 687 if (pfound->has_arg)
688 GNoptarg = nameend + 1;
689 else
690 {
691 if (GNopterr)
692 {
693 if (argv[GNoptind - 1][1] == '-')
694 /* --option */
695 fprintf (stderr,
696 _("%s: option `--%s' does not allow an argument\n"),
697 argv[0], pfound->name);
698 else
699 /* +option or -option */
700 fprintf (stderr,
701 _("%s: option `%c%s' does not allow an argument\n"),
702 argv[0], argv[GNoptind - 1][0], pfound->name);
703 }
704 nextchar += strlen (nextchar);
705 return '?';
706 }
707 }
708 else if (pfound->has_arg == 1)
709 {
710 if (GNoptind < argc)
711 {
712 GNoptarg = argv[GNoptind++];
713 }
714 else
715 {
716 if (GNopterr)
717 {
718 fprintf (stderr, _("%s: option `%s' requires an argument\n"),
719 argv[0], argv[GNoptind - 1]);
720 }
721 nextchar += strlen (nextchar);
722 return (optstring[0] == ':') ? ':' : '?';
723 }
724 }
725 nextchar += strlen (nextchar);
726 if (longind != NULL)
727 *longind = option_index;
728 if (pfound->flag)
729 {
730 *(pfound->flag) = pfound->val;
731 return 0;
732 }
733 return pfound->val;
734 }
676 735
677 if (pfound != NULL) 736 /* Can't find it as a long option. If this is not getopt_long_only,
678 { 737 * or the option starts with '--' or is not a valid short
679 option_index = indfound; 738 * option, then it's an error.
680 GNoptind++; 739 * Otherwise interpret it as a short option. */
681 if (*nameend) 740 if (!long_only || argv[GNoptind][1] == '-' ||
682 { 741 my_index (optstring, *nextchar) == NULL)
683 /* Don't test has_arg with >, because some C compilers don't 742 {
684 * allow it to be used on enums. */ 743 if (GNopterr)
685 if (pfound->has_arg) 744 {
686 GNoptarg = nameend + 1; 745 if (argv[GNoptind][1] == '-')
687 else 746 /* --option */
688 { 747 fprintf (stderr, _("%s: unrecognized option `--%s'\n"), argv[0],
689 if (GNopterr) 748 nextchar);
690 { 749 else
691 if (argv[GNoptind - 1][1] == '-') 750 /* +option or -option */
692 /* --option */ 751 fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), argv[0],
693 fprintf (stderr, 752 argv[GNoptind][0], nextchar);
694 _ 753 }
695 ("%s: option `--%s' does not allow an argument\n"), 754 nextchar = (char *) "";
696 argv[0], pfound->name); 755 GNoptind++;
697 else 756 return '?';
698 /* +option or -option */
699 fprintf (stderr,
700 _
701 ("%s: option `%c%s' does not allow an argument\n"),
702 argv[0], argv[GNoptind - 1][0],
703 pfound->name);
704 }
705 nextchar += strlen (nextchar);
706 return '?';
707 }
708 }
709 else if (pfound->has_arg == 1)
710 {
711 if (GNoptind < argc)
712 {
713 GNoptarg = argv[GNoptind++];
714 }
715 else
716 {
717 if (GNopterr)
718 {
719 fprintf (stderr,
720 _("%s: option `%s' requires an argument\n"),
721 argv[0], argv[GNoptind - 1]);
722 }
723 nextchar += strlen (nextchar);
724 return (optstring[0] == ':') ? ':' : '?';
725 }
726 }
727 nextchar += strlen (nextchar);
728 if (longind != NULL)
729 *longind = option_index;
730 if (pfound->flag)
731 {
732 *(pfound->flag) = pfound->val;
733 return 0;
734 }
735 return pfound->val;
736 }
737
738 /* Can't find it as a long option. If this is not getopt_long_only,
739 * or the option starts with '--' or is not a valid short
740 * option, then it's an error.
741 * Otherwise interpret it as a short option. */
742 if (!long_only || argv[GNoptind][1] == '-' ||
743 my_index (optstring, *nextchar) == NULL)
744 {
745 if (GNopterr)
746 {
747 if (argv[GNoptind][1] == '-')
748 /* --option */
749 fprintf (stderr, _("%s: unrecognized option `--%s'\n"),
750 argv[0], nextchar);
751 else
752 /* +option or -option */
753 fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
754 argv[0], argv[GNoptind][0], nextchar);
755 }
756 nextchar = (char *) "";
757 GNoptind++;
758 return '?';
759 }
760 } 757 }
758 }
761 759
762 /* Look at and handle the next short option-character. */ 760 /* Look at and handle the next short option-character. */
763 761
@@ -770,193 +768,191 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring,
770 ++GNoptind; 768 ++GNoptind;
771 769
772 if (temp == NULL || c == ':') 770 if (temp == NULL || c == ':')
771 {
772 if (GNopterr)
773 { 773 {
774 if (GNopterr) 774 if (posixly_correct)
775 { 775 /* 1003.2 specifies the format of this message. */
776 if (posixly_correct) 776 fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c);
777 /* 1003.2 specifies the format of this message. */ 777 else
778 fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c); 778 fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c);
779 else
780 fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c);
781 }
782 return '?';
783 } 779 }
780 return '?';
781 }
784 /* Convenience. Treat POSIX -W foo same as long option --foo */ 782 /* Convenience. Treat POSIX -W foo same as long option --foo */
785 if (temp[0] == 'W' && temp[1] == ';') 783 if (temp[0] == 'W' && temp[1] == ';')
784 {
785 char *nameend;
786 const struct GNoption *p;
787 const struct GNoption *pfound = NULL;
788 int exact = 0;
789 int ambig = 0;
790 int indfound = 0;
791 int option_index;
792
793 /* This is an option that requires an argument. */
794 if (*nextchar != '\0')
786 { 795 {
787 char *nameend; 796 GNoptarg = nextchar;
788 const struct GNoption *p; 797 /* If we end this ARGV-element by taking the rest as an arg,
789 const struct GNoption *pfound = NULL; 798 * we must advance to the next element now. */
790 int exact = 0; 799 GNoptind++;
791 int ambig = 0; 800 }
792 int indfound = 0; 801 else if (GNoptind == argc)
793 int option_index; 802 {
794 803 if (GNopterr)
795 /* This is an option that requires an argument. */ 804 {
796 if (*nextchar != '\0') 805 /* 1003.2 specifies the format of this message. */
797 { 806 fprintf (stderr, _("%s: option requires an argument -- %c\n"),
798 GNoptarg = nextchar; 807 argv[0], c);
799 /* If we end this ARGV-element by taking the rest as an arg, 808 }
800 * we must advance to the next element now. */ 809 if (optstring[0] == ':')
801 GNoptind++; 810 c = ':';
802 } 811 else
803 else if (GNoptind == argc) 812 c = '?';
804 { 813 return c;
805 if (GNopterr) 814 }
806 { 815 else
807 /* 1003.2 specifies the format of this message. */ 816 /* We already incremented `GNoptind' once;
808 fprintf (stderr, _("%s: option requires an argument -- %c\n"), 817 * increment it again when taking next ARGV-elt as argument. */
809 argv[0], c); 818 GNoptarg = argv[GNoptind++];
810 } 819
811 if (optstring[0] == ':') 820 /* GNoptarg is now the argument, see if it's in the
812 c = ':'; 821 * table of longopts. */
813 else 822
814 c = '?'; 823 for (nextchar = nameend = GNoptarg; *nameend && *nameend != '=';
815 return c; 824 nameend++)
816 } 825 /* Do nothing. */ ;
817 else 826
818 /* We already incremented `GNoptind' once; 827 /* Test all long options for either exact match
819 * increment it again when taking next ARGV-elt as argument. */ 828 * or abbreviated matches. */
820 GNoptarg = argv[GNoptind++]; 829 if (longopts != NULL)
821 830 for (p = longopts, option_index = 0; p->name; p++, option_index++)
822 /* GNoptarg is now the argument, see if it's in the 831 if (!strncmp (p->name, nextchar, nameend - nextchar))
823 * table of longopts. */ 832 {
824 833 if ((unsigned int) (nameend - nextchar) == strlen (p->name))
825 for (nextchar = nameend = GNoptarg; *nameend && *nameend != '='; 834 {
826 nameend++) 835 /* Exact match found. */
827 /* Do nothing. */ ; 836 pfound = p;
828 837 indfound = option_index;
829 /* Test all long options for either exact match 838 exact = 1;
830 * or abbreviated matches. */ 839 break;
831 if (longopts != NULL) 840 }
832 for (p = longopts, option_index = 0; p->name; p++, option_index++) 841 else if (pfound == NULL)
833 if (!strncmp (p->name, nextchar, nameend - nextchar)) 842 {
834 { 843 /* First nonexact match found. */
835 if ((unsigned int) (nameend - nextchar) == strlen (p->name)) 844 pfound = p;
836 { 845 indfound = option_index;
837 /* Exact match found. */ 846 }
838 pfound = p; 847 else
839 indfound = option_index; 848 /* Second or later nonexact match found. */
840 exact = 1; 849 ambig = 1;
841 break; 850 }
842 } 851 if (ambig && !exact)
843 else if (pfound == NULL) 852 {
844 { 853 if (GNopterr)
845 /* First nonexact match found. */ 854 fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), argv[0],
846 pfound = p; 855 argv[GNoptind]);
847 indfound = option_index; 856 nextchar += strlen (nextchar);
848 } 857 GNoptind++;
849 else 858 return '?';
850 /* Second or later nonexact match found. */ 859 }
851 ambig = 1; 860 if (pfound != NULL)
852 } 861 {
853 if (ambig && !exact) 862 option_index = indfound;
854 { 863 if (*nameend)
855 if (GNopterr) 864 {
856 fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), 865 /* Don't test has_arg with >, because some C compilers don't
857 argv[0], argv[GNoptind]); 866 * allow it to be used on enums. */
858 nextchar += strlen (nextchar); 867 if (pfound->has_arg)
859 GNoptind++; 868 GNoptarg = nameend + 1;
860 return '?'; 869 else
861 } 870 {
862 if (pfound != NULL) 871 if (GNopterr)
863 { 872 fprintf (stderr, _("\
864 option_index = indfound;
865 if (*nameend)
866 {
867 /* Don't test has_arg with >, because some C compilers don't
868 * allow it to be used on enums. */
869 if (pfound->has_arg)
870 GNoptarg = nameend + 1;
871 else
872 {
873 if (GNopterr)
874 fprintf (stderr, _("\
875%s: option `-W %s' does not allow an argument\n"), argv[0], pfound->name); 873%s: option `-W %s' does not allow an argument\n"), argv[0], pfound->name);
876 874
877 nextchar += strlen (nextchar); 875 nextchar += strlen (nextchar);
878 return '?'; 876 return '?';
879 } 877 }
880 } 878 }
881 else if (pfound->has_arg == 1) 879 else if (pfound->has_arg == 1)
882 { 880 {
883 if (GNoptind < argc) 881 if (GNoptind < argc)
884 GNoptarg = argv[GNoptind++]; 882 GNoptarg = argv[GNoptind++];
885 else 883 else
886 { 884 {
887 if (GNopterr) 885 if (GNopterr)
888 fprintf (stderr, 886 fprintf (stderr, _("%s: option `%s' requires an argument\n"),
889 _("%s: option `%s' requires an argument\n"), 887 argv[0], argv[GNoptind - 1]);
890 argv[0], argv[GNoptind - 1]); 888 nextchar += strlen (nextchar);
891 nextchar += strlen (nextchar); 889 return optstring[0] == ':' ? ':' : '?';
892 return optstring[0] == ':' ? ':' : '?'; 890 }
893 } 891 }
894 } 892 nextchar += strlen (nextchar);
895 nextchar += strlen (nextchar); 893 if (longind != NULL)
896 if (longind != NULL) 894 *longind = option_index;
897 *longind = option_index; 895 if (pfound->flag)
898 if (pfound->flag) 896 {
899 { 897 *(pfound->flag) = pfound->val;
900 *(pfound->flag) = pfound->val; 898 return 0;
901 return 0; 899 }
902 } 900 return pfound->val;
903 return pfound->val;
904 }
905 nextchar = NULL;
906 return 'W'; /* Let the application handle it. */
907 } 901 }
902 nextchar = NULL;
903 return 'W'; /* Let the application handle it. */
904 }
908 if (temp[1] == ':') 905 if (temp[1] == ':')
906 {
907 if (temp[2] == ':')
909 { 908 {
910 if (temp[2] == ':') 909 /* This is an option that accepts an argument optionally. */
911 { 910 if (*nextchar != '\0')
912 /* This is an option that accepts an argument optionally. */ 911 {
913 if (*nextchar != '\0') 912 GNoptarg = nextchar;
914 { 913 GNoptind++;
915 GNoptarg = nextchar; 914 }
916 GNoptind++; 915 else
917 } 916 GNoptarg = NULL;
918 else 917 nextchar = NULL;
919 GNoptarg = NULL;
920 nextchar = NULL;
921 }
922 else
923 {
924 /* This is an option that requires an argument. */
925 if (*nextchar != '\0')
926 {
927 GNoptarg = nextchar;
928 /* If we end this ARGV-element by taking the rest as an arg,
929 * we must advance to the next element now. */
930 GNoptind++;
931 }
932 else if (GNoptind == argc)
933 {
934 if (GNopterr)
935 {
936 /* 1003.2 specifies the format of this message. */
937 fprintf (stderr,
938 _("%s: option requires an argument -- %c\n"),
939 argv[0], c);
940 }
941 if (optstring[0] == ':')
942 c = ':';
943 else
944 c = '?';
945 }
946 else
947 /* We already incremented `GNoptind' once;
948 * increment it again when taking next ARGV-elt as argument. */
949 GNoptarg = argv[GNoptind++];
950 nextchar = NULL;
951 }
952 } 918 }
919 else
920 {
921 /* This is an option that requires an argument. */
922 if (*nextchar != '\0')
923 {
924 GNoptarg = nextchar;
925 /* If we end this ARGV-element by taking the rest as an arg,
926 * we must advance to the next element now. */
927 GNoptind++;
928 }
929 else if (GNoptind == argc)
930 {
931 if (GNopterr)
932 {
933 /* 1003.2 specifies the format of this message. */
934 fprintf (stderr, _("%s: option requires an argument -- %c\n"),
935 argv[0], c);
936 }
937 if (optstring[0] == ':')
938 c = ':';
939 else
940 c = '?';
941 }
942 else
943 /* We already incremented `GNoptind' once;
944 * increment it again when taking next ARGV-elt as argument. */
945 GNoptarg = argv[GNoptind++];
946 nextchar = NULL;
947 }
948 }
953 return c; 949 return c;
954 } 950 }
955} 951}
956 952
957static int 953static int
958GNgetopt_long (int argc, char *const *argv, const char *options, 954GNgetopt_long (int argc, char *const *argv, const char *options,
959 const struct GNoption *long_options, int *opt_index) 955 const struct GNoption *long_options, int *opt_index)
960{ 956{
961 return GN_getopt_internal (argc, argv, options, long_options, opt_index, 0); 957 return GN_getopt_internal (argc, argv, options, long_options, opt_index, 0);
962} 958}
@@ -975,8 +971,8 @@ GNgetopt_long (int argc, char *const *argv, const char *options,
975 */ 971 */
976int 972int
977GNUNET_GETOPT_run (const char *binaryOptions, 973GNUNET_GETOPT_run (const char *binaryOptions,
978 const struct GNUNET_GETOPT_CommandLineOption *allOptions, 974 const struct GNUNET_GETOPT_CommandLineOption *allOptions,
979 unsigned int argc, char *const *argv) 975 unsigned int argc, char *const *argv)
980{ 976{
981 struct GNoption *long_options; 977 struct GNoption *long_options;
982 struct GNUNET_GETOPT_CommandLineProcessorContext clpc; 978 struct GNUNET_GETOPT_CommandLineProcessorContext clpc;
@@ -1001,15 +997,15 @@ GNUNET_GETOPT_run (const char *binaryOptions,
1001 shorts = GNUNET_malloc (count * 2 + 1); 997 shorts = GNUNET_malloc (count * 2 + 1);
1002 spos = 0; 998 spos = 0;
1003 for (i = 0; i < count; i++) 999 for (i = 0; i < count; i++)
1004 { 1000 {
1005 long_options[i].name = allOptions[i].name; 1001 long_options[i].name = allOptions[i].name;
1006 long_options[i].has_arg = allOptions[i].require_argument; 1002 long_options[i].has_arg = allOptions[i].require_argument;
1007 long_options[i].flag = NULL; 1003 long_options[i].flag = NULL;
1008 long_options[i].val = allOptions[i].shortName; 1004 long_options[i].val = allOptions[i].shortName;
1009 shorts[spos++] = allOptions[i].shortName; 1005 shorts[spos++] = allOptions[i].shortName;
1010 if (allOptions[i].require_argument != 0) 1006 if (allOptions[i].require_argument != 0)
1011 shorts[spos++] = ':'; 1007 shorts[spos++] = ':';
1012 } 1008 }
1013 long_options[count].name = NULL; 1009 long_options[count].name = NULL;
1014 long_options[count].has_arg = 0; 1010 long_options[count].has_arg = 0;
1015 long_options[count].flag = NULL; 1011 long_options[count].flag = NULL;
@@ -1018,31 +1014,31 @@ GNUNET_GETOPT_run (const char *binaryOptions,
1018 cont = GNUNET_OK; 1014 cont = GNUNET_OK;
1019 /* main getopt loop */ 1015 /* main getopt loop */
1020 while (cont == GNUNET_OK) 1016 while (cont == GNUNET_OK)
1017 {
1018 int option_index = 0;
1019
1020 c = GNgetopt_long (argc, argv, shorts, long_options, &option_index);
1021
1022 if (c == GNUNET_SYSERR)
1023 break; /* No more flags to process */
1024
1025 for (i = 0; i < count; i++)
1026 {
1027 clpc.currentArgument = GNoptind - 1;
1028 if ((char) c == allOptions[i].shortName)
1029 {
1030 cont =
1031 allOptions[i].processor (&clpc, allOptions[i].scls,
1032 allOptions[i].name, GNoptarg);
1033 break;
1034 }
1035 }
1036 if (i == count)
1021 { 1037 {
1022 int option_index = 0; 1038 fprintf (stderr, _("Use --help to get a list of options.\n"));
1023 1039 cont = GNUNET_SYSERR;
1024 c = GNgetopt_long (argc, argv, shorts, long_options, &option_index);
1025
1026 if (c == GNUNET_SYSERR)
1027 break; /* No more flags to process */
1028
1029 for (i = 0; i < count; i++)
1030 {
1031 clpc.currentArgument = GNoptind - 1;
1032 if ((char) c == allOptions[i].shortName)
1033 {
1034 cont =
1035 allOptions[i].processor (&clpc, allOptions[i].scls,
1036 allOptions[i].name, GNoptarg);
1037 break;
1038 }
1039 }
1040 if (i == count)
1041 {
1042 fprintf (stderr, _("Use --help to get a list of options.\n"));
1043 cont = GNUNET_SYSERR;
1044 }
1045 } 1040 }
1041 }
1046 1042
1047 GNUNET_free (shorts); 1043 GNUNET_free (shorts);
1048 GNUNET_free (long_options); 1044 GNUNET_free (long_options);
diff --git a/src/util/getopt_helpers.c b/src/util/getopt_helpers.c
index 8564d591f..8b49c5907 100644
--- a/src/util/getopt_helpers.c
+++ b/src/util/getopt_helpers.c
@@ -42,8 +42,8 @@
42 */ 42 */
43int 43int
44GNUNET_GETOPT_print_version_ (struct GNUNET_GETOPT_CommandLineProcessorContext 44GNUNET_GETOPT_print_version_ (struct GNUNET_GETOPT_CommandLineProcessorContext
45 *ctx, void *scls, const char *option, 45 *ctx, void *scls, const char *option,
46 const char *value) 46 const char *value)
47{ 47{
48 const char *version = scls; 48 const char *version = scls;
49 49
@@ -66,8 +66,8 @@ GNUNET_GETOPT_print_version_ (struct GNUNET_GETOPT_CommandLineProcessorContext
66 */ 66 */
67int 67int
68GNUNET_GETOPT_format_help_ (struct GNUNET_GETOPT_CommandLineProcessorContext 68GNUNET_GETOPT_format_help_ (struct GNUNET_GETOPT_CommandLineProcessorContext
69 *ctx, void *scls, const char *option, 69 *ctx, void *scls, const char *option,
70 const char *value) 70 const char *value)
71{ 71{
72 const char *about = scls; 72 const char *about = scls;
73 size_t slen; 73 size_t slen;
@@ -81,74 +81,74 @@ GNUNET_GETOPT_format_help_ (struct GNUNET_GETOPT_CommandLineProcessorContext
81 81
82 printf ("%s\n%s\n", ctx->binaryOptions, gettext (about)); 82 printf ("%s\n%s\n", ctx->binaryOptions, gettext (about));
83 printf (_ 83 printf (_
84 ("Arguments mandatory for long options are also mandatory for short options.\n")); 84 ("Arguments mandatory for long options are also mandatory for short options.\n"));
85 i = 0; 85 i = 0;
86 opt = ctx->allOptions; 86 opt = ctx->allOptions;
87 while (opt[i].description != NULL) 87 while (opt[i].description != NULL)
88 {
89 if (opt[i].shortName == '\0')
90 printf (" ");
91 else
92 printf (" -%c, ", opt[i].shortName);
93 printf ("--%s", opt[i].name);
94 slen = 8 + strlen (opt[i].name);
95 if (opt[i].argumentHelp != NULL)
88 { 96 {
89 if (opt[i].shortName == '\0') 97 printf ("=%s", opt[i].argumentHelp);
90 printf (" "); 98 slen += 1 + strlen (opt[i].argumentHelp);
91 else
92 printf (" -%c, ", opt[i].shortName);
93 printf ("--%s", opt[i].name);
94 slen = 8 + strlen (opt[i].name);
95 if (opt[i].argumentHelp != NULL)
96 {
97 printf ("=%s", opt[i].argumentHelp);
98 slen += 1 + strlen (opt[i].argumentHelp);
99 }
100 if (slen > BORDER)
101 {
102 printf ("\n%*s", BORDER, "");
103 slen = BORDER;
104 }
105 if (slen < BORDER)
106 {
107 printf ("%*s", (int) (BORDER - slen), "");
108 slen = BORDER;
109 }
110 if (0 < strlen (opt[i].description))
111 trans = gettext (opt[i].description);
112 else
113 trans = "";
114 ml = strlen (trans);
115 p = 0;
116 OUTER:
117 while (ml - p > 78 - slen)
118 {
119 for (j = p + 78 - slen; j > p; j--)
120 {
121 if (isspace ((unsigned char) trans[j]))
122 {
123 scp = GNUNET_malloc (j - p + 1);
124 memcpy (scp, &trans[p], j - p);
125 scp[j - p] = '\0';
126 printf ("%s\n%*s", scp, BORDER + 2, "");
127 GNUNET_free (scp);
128 p = j + 1;
129 slen = BORDER + 2;
130 goto OUTER;
131 }
132 }
133 /* could not find space to break line */
134 scp = GNUNET_malloc (78 - slen + 1);
135 memcpy (scp, &trans[p], 78 - slen);
136 scp[78 - slen] = '\0';
137 printf ("%s\n%*s", scp, BORDER + 2, "");
138 GNUNET_free (scp);
139 slen = BORDER + 2;
140 p = p + 78 - slen;
141 }
142 /* print rest */
143 if (p < ml)
144 printf ("%s\n", &trans[p]);
145 if (strlen (trans) == 0)
146 printf ("\n");
147 i++;
148 } 99 }
100 if (slen > BORDER)
101 {
102 printf ("\n%*s", BORDER, "");
103 slen = BORDER;
104 }
105 if (slen < BORDER)
106 {
107 printf ("%*s", (int) (BORDER - slen), "");
108 slen = BORDER;
109 }
110 if (0 < strlen (opt[i].description))
111 trans = gettext (opt[i].description);
112 else
113 trans = "";
114 ml = strlen (trans);
115 p = 0;
116OUTER:
117 while (ml - p > 78 - slen)
118 {
119 for (j = p + 78 - slen; j > p; j--)
120 {
121 if (isspace ((unsigned char) trans[j]))
122 {
123 scp = GNUNET_malloc (j - p + 1);
124 memcpy (scp, &trans[p], j - p);
125 scp[j - p] = '\0';
126 printf ("%s\n%*s", scp, BORDER + 2, "");
127 GNUNET_free (scp);
128 p = j + 1;
129 slen = BORDER + 2;
130 goto OUTER;
131 }
132 }
133 /* could not find space to break line */
134 scp = GNUNET_malloc (78 - slen + 1);
135 memcpy (scp, &trans[p], 78 - slen);
136 scp[78 - slen] = '\0';
137 printf ("%s\n%*s", scp, BORDER + 2, "");
138 GNUNET_free (scp);
139 slen = BORDER + 2;
140 p = p + 78 - slen;
141 }
142 /* print rest */
143 if (p < ml)
144 printf ("%s\n", &trans[p]);
145 if (strlen (trans) == 0)
146 printf ("\n");
147 i++;
148 }
149 printf ("Report bugs to gnunet-developers@gnu.org.\n" 149 printf ("Report bugs to gnunet-developers@gnu.org.\n"
150 "GNUnet home page: http://www.gnu.org/software/gnunet/\n" 150 "GNUnet home page: http://www.gnu.org/software/gnunet/\n"
151 "General help using GNU software: http://www.gnu.org/gethelp/\n"); 151 "General help using GNU software: http://www.gnu.org/gethelp/\n");
152 return GNUNET_SYSERR; 152 return GNUNET_SYSERR;
153} 153}
154 154
@@ -168,10 +168,9 @@ GNUNET_GETOPT_format_help_ (struct GNUNET_GETOPT_CommandLineProcessorContext
168 * @return GNUNET_OK 168 * @return GNUNET_OK
169 */ 169 */
170int 170int
171GNUNET_GETOPT_increment_value (struct 171GNUNET_GETOPT_increment_value (struct GNUNET_GETOPT_CommandLineProcessorContext
172 GNUNET_GETOPT_CommandLineProcessorContext *ctx, 172 *ctx, void *scls, const char *option,
173 void *scls, const char *option, 173 const char *value)
174 const char *value)
175{ 174{
176 int *val = scls; 175 int *val = scls;
177 176
@@ -196,7 +195,7 @@ GNUNET_GETOPT_increment_value (struct
196 */ 195 */
197int 196int
198GNUNET_GETOPT_set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, 197GNUNET_GETOPT_set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
199 void *scls, const char *option, const char *value) 198 void *scls, const char *option, const char *value)
200{ 199{
201 int *val = scls; 200 int *val = scls;
202 201
@@ -220,9 +219,8 @@ GNUNET_GETOPT_set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
220 * @return GNUNET_OK 219 * @return GNUNET_OK
221 */ 220 */
222int 221int
223GNUNET_GETOPT_set_string (struct GNUNET_GETOPT_CommandLineProcessorContext 222GNUNET_GETOPT_set_string (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
224 *ctx, void *scls, const char *option, 223 void *scls, const char *option, const char *value)
225 const char *value)
226{ 224{
227 char **val = scls; 225 char **val = scls;
228 226
@@ -247,18 +245,16 @@ GNUNET_GETOPT_set_string (struct GNUNET_GETOPT_CommandLineProcessorContext
247 * @return GNUNET_OK if parsing the value worked 245 * @return GNUNET_OK if parsing the value worked
248 */ 246 */
249int 247int
250GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext 248GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
251 *ctx, void *scls, const char *option, 249 void *scls, const char *option, const char *value)
252 const char *value)
253{ 250{
254 unsigned long long *val = scls; 251 unsigned long long *val = scls;
255 252
256 if (1 != SSCANF (value, "%llu", val)) 253 if (1 != SSCANF (value, "%llu", val))
257 { 254 {
258 fprintf (stderr, _("You must pass a number to the `%s' option.\n"), 255 fprintf (stderr, _("You must pass a number to the `%s' option.\n"), option);
259 option); 256 return GNUNET_SYSERR;
260 return GNUNET_SYSERR; 257 }
261 }
262 return GNUNET_OK; 258 return GNUNET_OK;
263} 259}
264 260
@@ -278,16 +274,15 @@ GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext
278 */ 274 */
279int 275int
280GNUNET_GETOPT_set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, 276GNUNET_GETOPT_set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
281 void *scls, const char *option, const char *value) 277 void *scls, const char *option, const char *value)
282{ 278{
283 unsigned int *val = scls; 279 unsigned int *val = scls;
284 280
285 if (1 != SSCANF (value, "%u", val)) 281 if (1 != SSCANF (value, "%u", val))
286 { 282 {
287 fprintf (stderr, _("You must pass a number to the `%s' option.\n"), 283 fprintf (stderr, _("You must pass a number to the `%s' option.\n"), option);
288 option); 284 return GNUNET_SYSERR;
289 return GNUNET_SYSERR; 285 }
290 }
291 return GNUNET_OK; 286 return GNUNET_OK;
292} 287}
293 288
diff --git a/src/util/gnunet-config-diff.c b/src/util/gnunet-config-diff.c
index 992480a30..207b9518a 100644
--- a/src/util/gnunet-config-diff.c
+++ b/src/util/gnunet-config-diff.c
@@ -8,10 +8,10 @@ main (int argc, char **argv)
8 struct GNUNET_CONFIGURATION_Handle *i2; 8 struct GNUNET_CONFIGURATION_Handle *i2;
9 9
10 if (argc != 3) 10 if (argc != 3)
11 { 11 {
12 fprintf (stderr, "Invoke using `%s DEFAULTS-IN DIFFS'\n", argv[0]); 12 fprintf (stderr, "Invoke using `%s DEFAULTS-IN DIFFS'\n", argv[0]);
13 return 1; 13 return 1;
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 != GNUNET_CONFIGURATION_load (i1, argv[1])) || 17 if ((GNUNET_OK != GNUNET_CONFIGURATION_load (i1, argv[1])) ||
diff --git a/src/util/gnunet-resolver.c b/src/util/gnunet-resolver.c
index e97793114..131693dd1 100644
--- a/src/util/gnunet-resolver.c
+++ b/src/util/gnunet-resolver.c
@@ -72,9 +72,9 @@ main (int argc, char *const *argv)
72 GNUNET_GETOPT_OPTION_END 72 GNUNET_GETOPT_OPTION_END
73 }; 73 };
74 return (GNUNET_OK == 74 return (GNUNET_OK ==
75 GNUNET_PROGRAM_run (argc, argv, "gnunet-resolver [hostname]", 75 GNUNET_PROGRAM_run (argc, argv, "gnunet-resolver [hostname]",
76 gettext_noop ("Test GNUnet DNS resolver code."), 76 gettext_noop ("Test GNUnet DNS resolver code."),
77 options, &run, NULL)) ? 0 : 1; 77 options, &run, NULL)) ? 0 : 1;
78} 78}
79 79
80/* end of gnunet-resolver.c */ 80/* end of gnunet-resolver.c */
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c
index c15f0d3f5..5d4c5c224 100644
--- a/src/util/gnunet-service-resolver.c
+++ b/src/util/gnunet-service-resolver.c
@@ -89,7 +89,7 @@ getnameinfo_resolve (struct IPCache *cache)
89 89
90 if (0 == 90 if (0 ==
91 getnameinfo (cache->sa, cache->salen, hostname, sizeof (hostname), NULL, 91 getnameinfo (cache->sa, cache->salen, hostname, sizeof (hostname), NULL,
92 0, 0)) 92 0, 0))
93 cache->addr = GNUNET_strdup (hostname); 93 cache->addr = GNUNET_strdup (hostname);
94} 94}
95#endif 95#endif
@@ -107,20 +107,20 @@ gethostbyaddr_resolve (struct IPCache *cache)
107 struct hostent *ent; 107 struct hostent *ent;
108 108
109 switch (cache->sa->sa_family) 109 switch (cache->sa->sa_family)
110 { 110 {
111 case AF_INET: 111 case AF_INET:
112 ent = 112 ent =
113 gethostbyaddr (&((struct sockaddr_in *) cache->sa)->sin_addr, 113 gethostbyaddr (&((struct sockaddr_in *) cache->sa)->sin_addr,
114 sizeof (struct in_addr), AF_INET); 114 sizeof (struct in_addr), AF_INET);
115 break; 115 break;
116 case AF_INET6: 116 case AF_INET6:
117 ent = 117 ent =
118 gethostbyaddr (&((struct sockaddr_in6 *) cache->sa)->sin6_addr, 118 gethostbyaddr (&((struct sockaddr_in6 *) cache->sa)->sin6_addr,
119 sizeof (struct in6_addr), AF_INET6); 119 sizeof (struct in6_addr), AF_INET6);
120 break; 120 break;
121 default: 121 default:
122 ent = NULL; 122 ent = NULL;
123 } 123 }
124 if (ent != NULL) 124 if (ent != NULL)
125 cache->addr = GNUNET_strdup (ent->h_name); 125 cache->addr = GNUNET_strdup (ent->h_name);
126} 126}
@@ -158,7 +158,7 @@ cache_resolve (struct IPCache *cache)
158 */ 158 */
159static void 159static void
160get_ip_as_string (struct GNUNET_SERVER_Client *client, 160get_ip_as_string (struct GNUNET_SERVER_Client *client,
161 const struct sockaddr *sa, socklen_t salen) 161 const struct sockaddr *sa, socklen_t salen)
162{ 162{
163 struct IPCache *cache; 163 struct IPCache *cache;
164 struct IPCache *prev; 164 struct IPCache *prev;
@@ -166,73 +166,73 @@ get_ip_as_string (struct GNUNET_SERVER_Client *client,
166 struct GNUNET_SERVER_TransmitContext *tc; 166 struct GNUNET_SERVER_TransmitContext *tc;
167 167
168 if (salen < sizeof (struct sockaddr)) 168 if (salen < sizeof (struct sockaddr))
169 { 169 {
170 GNUNET_break (0); 170 GNUNET_break (0);
171 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 171 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
172 return; 172 return;
173 } 173 }
174 now = GNUNET_TIME_absolute_get (); 174 now = GNUNET_TIME_absolute_get ();
175 cache = head; 175 cache = head;
176 prev = NULL; 176 prev = NULL;
177 while ((cache != NULL) && 177 while ((cache != NULL) &&
178 ((cache->salen != salen) || (0 != memcmp (cache->sa, sa, salen)))) 178 ((cache->salen != salen) || (0 != memcmp (cache->sa, sa, salen))))
179 {
180 if (GNUNET_TIME_absolute_get_duration (cache->last_request).rel_value <
181 60 * 60 * 1000)
179 { 182 {
180 if (GNUNET_TIME_absolute_get_duration (cache->last_request).rel_value < 183 if (prev != NULL)
181 60 * 60 * 1000) 184 {
182 { 185 prev->next = cache->next;
183 if (prev != NULL) 186 GNUNET_free_non_null (cache->addr);
184 { 187 GNUNET_free (cache->sa);
185 prev->next = cache->next; 188 GNUNET_free (cache);
186 GNUNET_free_non_null (cache->addr); 189 cache = prev->next;
187 GNUNET_free (cache->sa); 190 }
188 GNUNET_free (cache); 191 else
189 cache = prev->next; 192 {
190 } 193 head = cache->next;
191 else 194 GNUNET_free_non_null (cache->addr);
192 { 195 GNUNET_free (cache->sa);
193 head = cache->next; 196 GNUNET_free (cache);
194 GNUNET_free_non_null (cache->addr); 197 cache = head;
195 GNUNET_free (cache->sa); 198 }
196 GNUNET_free (cache); 199 continue;
197 cache = head;
198 }
199 continue;
200 }
201 prev = cache;
202 cache = cache->next;
203 } 200 }
201 prev = cache;
202 cache = cache->next;
203 }
204 if (cache != NULL) 204 if (cache != NULL)
205 {
206 cache->last_request = now;
207 if (GNUNET_TIME_absolute_get_duration (cache->last_request).rel_value <
208 60 * 60 * 1000)
205 { 209 {
206 cache->last_request = now; 210 GNUNET_free_non_null (cache->addr);
207 if (GNUNET_TIME_absolute_get_duration (cache->last_request).rel_value <
208 60 * 60 * 1000)
209 {
210 GNUNET_free_non_null (cache->addr);
211 cache->addr = NULL;
212 cache->salen = 0;
213 cache_resolve (cache);
214 }
215 }
216 else
217 {
218 cache = GNUNET_malloc (sizeof (struct IPCache));
219 cache->next = head;
220 cache->salen = salen;
221 cache->sa = GNUNET_malloc (salen);
222 memcpy (cache->sa, sa, salen);
223 cache->last_request = GNUNET_TIME_absolute_get ();
224 cache->last_refresh = GNUNET_TIME_absolute_get ();
225 cache->addr = NULL; 211 cache->addr = NULL;
212 cache->salen = 0;
226 cache_resolve (cache); 213 cache_resolve (cache);
227 head = cache;
228 } 214 }
215 }
216 else
217 {
218 cache = GNUNET_malloc (sizeof (struct IPCache));
219 cache->next = head;
220 cache->salen = salen;
221 cache->sa = GNUNET_malloc (salen);
222 memcpy (cache->sa, sa, salen);
223 cache->last_request = GNUNET_TIME_absolute_get ();
224 cache->last_refresh = GNUNET_TIME_absolute_get ();
225 cache->addr = NULL;
226 cache_resolve (cache);
227 head = cache;
228 }
229 tc = GNUNET_SERVER_transmit_context_create (client); 229 tc = GNUNET_SERVER_transmit_context_create (client);
230 if (cache->addr != NULL) 230 if (cache->addr != NULL)
231 GNUNET_SERVER_transmit_context_append_data (tc, cache->addr, 231 GNUNET_SERVER_transmit_context_append_data (tc, cache->addr,
232 strlen (cache->addr) + 1, 232 strlen (cache->addr) + 1,
233 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 233 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
234 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 234 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
235 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 235 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
236 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); 236 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
237} 237}
238 238
@@ -240,7 +240,7 @@ get_ip_as_string (struct GNUNET_SERVER_Client *client,
240#if HAVE_GETADDRINFO 240#if HAVE_GETADDRINFO
241static int 241static int
242getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc, 242getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc,
243 const char *hostname, int domain) 243 const char *hostname, int domain)
244{ 244{
245 int s; 245 int s;
246 struct addrinfo hints; 246 struct addrinfo hints;
@@ -254,37 +254,36 @@ getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc,
254#else 254#else
255 hints.ai_family = AF_INET; 255 hints.ai_family = AF_INET;
256#endif 256#endif
257 hints.ai_socktype = SOCK_STREAM; /* go for TCP */ 257 hints.ai_socktype = SOCK_STREAM; /* go for TCP */
258 258
259 if (0 != (s = getaddrinfo (hostname, NULL, &hints, &result))) 259 if (0 != (s = getaddrinfo (hostname, NULL, &hints, &result)))
260 { 260 {
261 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 261 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Could not resolve `%s' (%s): %s\n"),
262 _("Could not resolve `%s' (%s): %s\n"), hostname, 262 hostname,
263 (domain == 263 (domain ==
264 AF_INET) ? "IPv4" : ((domain == 264 AF_INET) ? "IPv4" : ((domain == AF_INET6) ? "IPv6" : "any"),
265 AF_INET6) ? "IPv6" : "any"), 265 gai_strerror (s));
266 gai_strerror (s)); 266 if ((s == EAI_BADFLAGS) || (s == EAI_MEMORY)
267 if ((s == EAI_BADFLAGS) || (s == EAI_MEMORY)
268#ifndef MINGW 267#ifndef MINGW
269 || (s == EAI_SYSTEM) 268 || (s == EAI_SYSTEM)
270#else 269#else
271 // FIXME NILS 270 // FIXME NILS
272 || 1 271 || 1
273#endif 272#endif
274 ) 273 )
275 return GNUNET_NO; /* other function may still succeed */ 274 return GNUNET_NO; /* other function may still succeed */
276 return GNUNET_SYSERR; 275 return GNUNET_SYSERR;
277 } 276 }
278 if (result == NULL) 277 if (result == NULL)
279 return GNUNET_SYSERR; 278 return GNUNET_SYSERR;
280 pos = result; 279 pos = result;
281 while (pos != NULL) 280 while (pos != NULL)
282 { 281 {
283 GNUNET_SERVER_transmit_context_append_data (tc, pos->ai_addr, 282 GNUNET_SERVER_transmit_context_append_data (tc, pos->ai_addr,
284 pos->ai_addrlen, 283 pos->ai_addrlen,
285 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 284 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
286 pos = pos->ai_next; 285 pos = pos->ai_next;
287 } 286 }
288 freeaddrinfo (result); 287 freeaddrinfo (result);
289 return GNUNET_OK; 288 return GNUNET_OK;
290} 289}
@@ -293,7 +292,7 @@ getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc,
293#if HAVE_GETHOSTBYNAME2 292#if HAVE_GETHOSTBYNAME2
294static int 293static int
295gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc, 294gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc,
296 const char *hostname, int domain) 295 const char *hostname, int domain)
297{ 296{
298 struct hostent *hp; 297 struct hostent *hp;
299 struct sockaddr_in a4; 298 struct sockaddr_in a4;
@@ -302,48 +301,48 @@ gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc,
302 int ret2; 301 int ret2;
303 302
304 if (domain == AF_UNSPEC) 303 if (domain == AF_UNSPEC)
305 { 304 {
306 ret1 = gethostbyname2_resolve (tc, hostname, AF_INET); 305 ret1 = gethostbyname2_resolve (tc, hostname, AF_INET);
307 ret2 = gethostbyname2_resolve (tc, hostname, AF_INET6); 306 ret2 = gethostbyname2_resolve (tc, hostname, AF_INET6);
308 if ((ret1 == GNUNET_OK) || (ret2 == GNUNET_OK)) 307 if ((ret1 == GNUNET_OK) || (ret2 == GNUNET_OK))
309 return GNUNET_OK; 308 return GNUNET_OK;
310 if ((ret1 == GNUNET_SYSERR) || (ret2 == GNUNET_SYSERR)) 309 if ((ret1 == GNUNET_SYSERR) || (ret2 == GNUNET_SYSERR))
311 return GNUNET_SYSERR; 310 return GNUNET_SYSERR;
312 return GNUNET_NO; 311 return GNUNET_NO;
313 } 312 }
314 hp = gethostbyname2 (hostname, domain); 313 hp = gethostbyname2 (hostname, domain);
315 if (hp == NULL) 314 if (hp == NULL)
316 { 315 {
317 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 316 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
318 _("Could not find IP of host `%s': %s\n"), hostname, 317 _("Could not find IP of host `%s': %s\n"), hostname,
319 hstrerror (h_errno)); 318 hstrerror (h_errno));
320 return GNUNET_SYSERR; 319 return GNUNET_SYSERR;
321 } 320 }
322 GNUNET_assert (hp->h_addrtype == domain); 321 GNUNET_assert (hp->h_addrtype == domain);
323 if (domain == AF_INET) 322 if (domain == AF_INET)
324 { 323 {
325 GNUNET_assert (hp->h_length == sizeof (struct in_addr)); 324 GNUNET_assert (hp->h_length == sizeof (struct in_addr));
326 memset (&a4, 0, sizeof (a4)); 325 memset (&a4, 0, sizeof (a4));
327 a4.sin_family = AF_INET; 326 a4.sin_family = AF_INET;
328#if HAVE_SOCKADDR_IN_SIN_LEN 327#if HAVE_SOCKADDR_IN_SIN_LEN
329 a4.sin_len = (u_char) sizeof (struct sockaddr_in); 328 a4.sin_len = (u_char) sizeof (struct sockaddr_in);
330#endif 329#endif
331 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);
332 GNUNET_SERVER_transmit_context_append_data (tc, &a4, sizeof (a4), 331 GNUNET_SERVER_transmit_context_append_data (tc, &a4, sizeof (a4),
333 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 332 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
334 } 333 }
335 else 334 else
336 { 335 {
337 GNUNET_assert (hp->h_length == sizeof (struct in6_addr)); 336 GNUNET_assert (hp->h_length == sizeof (struct in6_addr));
338 memset (&a6, 0, sizeof (a6)); 337 memset (&a6, 0, sizeof (a6));
339 a6.sin6_family = AF_INET6; 338 a6.sin6_family = AF_INET6;
340#if HAVE_SOCKADDR_IN_SIN_LEN 339#if HAVE_SOCKADDR_IN_SIN_LEN
341 a6.sin6_len = (u_char) sizeof (struct sockaddr_in6); 340 a6.sin6_len = (u_char) sizeof (struct sockaddr_in6);
342#endif 341#endif
343 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);
344 GNUNET_SERVER_transmit_context_append_data (tc, &a6, sizeof (a6), 343 GNUNET_SERVER_transmit_context_append_data (tc, &a6, sizeof (a6),
345 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 344 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
346 } 345 }
347 return GNUNET_OK; 346 return GNUNET_OK;
348} 347}
349#endif 348#endif
@@ -351,24 +350,24 @@ gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc,
351#if HAVE_GETHOSTBYNAME 350#if HAVE_GETHOSTBYNAME
352static int 351static int
353gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc, 352gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc,
354 const char *hostname) 353 const char *hostname)
355{ 354{
356 struct hostent *hp; 355 struct hostent *hp;
357 struct sockaddr_in addr; 356 struct sockaddr_in addr;
358 357
359 hp = GETHOSTBYNAME (hostname); 358 hp = GETHOSTBYNAME (hostname);
360 if (hp == NULL) 359 if (hp == NULL)
361 { 360 {
362 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 361 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
363 _("Could not find IP of host `%s': %s\n"), hostname, 362 _("Could not find IP of host `%s': %s\n"), hostname,
364 hstrerror (h_errno)); 363 hstrerror (h_errno));
365 return GNUNET_SYSERR; 364 return GNUNET_SYSERR;
366 } 365 }
367 if (hp->h_addrtype != AF_INET) 366 if (hp->h_addrtype != AF_INET)
368 { 367 {
369 GNUNET_break (0); 368 GNUNET_break (0);
370 return GNUNET_SYSERR; 369 return GNUNET_SYSERR;
371 } 370 }
372 GNUNET_assert (hp->h_length == sizeof (struct in_addr)); 371 GNUNET_assert (hp->h_length == sizeof (struct in_addr));
373 memset (&addr, 0, sizeof (addr)); 372 memset (&addr, 0, sizeof (addr));
374 addr.sin_family = AF_INET; 373 addr.sin_family = AF_INET;
@@ -377,7 +376,7 @@ gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc,
377#endif 376#endif
378 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);
379 GNUNET_SERVER_transmit_context_append_data (tc, &addr, sizeof (addr), 378 GNUNET_SERVER_transmit_context_append_data (tc, &addr, sizeof (addr),
380 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 379 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
381 return GNUNET_OK; 380 return GNUNET_OK;
382} 381}
383#endif 382#endif
@@ -391,8 +390,8 @@ gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc,
391 * @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"
392 */ 391 */
393static void 392static void
394get_ip_from_hostname (struct GNUNET_SERVER_Client *client, 393get_ip_from_hostname (struct GNUNET_SERVER_Client *client, const char *hostname,
395 const char *hostname, int domain) 394 int domain)
396{ 395{
397 int ret; 396 int ret;
398 struct GNUNET_SERVER_TransmitContext *tc; 397 struct GNUNET_SERVER_TransmitContext *tc;
@@ -412,7 +411,7 @@ get_ip_from_hostname (struct GNUNET_SERVER_Client *client,
412 gethostbyname_resolve (tc, hostname); 411 gethostbyname_resolve (tc, hostname);
413#endif 412#endif
414 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 413 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
415 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 414 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
416 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); 415 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
417} 416}
418 417
@@ -426,7 +425,7 @@ get_ip_from_hostname (struct GNUNET_SERVER_Client *client,
426 */ 425 */
427static void 426static void
428handle_get (void *cls, struct GNUNET_SERVER_Client *client, 427handle_get (void *cls, struct GNUNET_SERVER_Client *client,
429 const struct GNUNET_MessageHeader *message) 428 const struct GNUNET_MessageHeader *message)
430{ 429{
431 uint16_t msize; 430 uint16_t msize;
432 const struct GNUNET_RESOLVER_GetMessage *msg; 431 const struct GNUNET_RESOLVER_GetMessage *msg;
@@ -438,78 +437,78 @@ handle_get (void *cls, struct GNUNET_SERVER_Client *client,
438 437
439 msize = ntohs (message->size); 438 msize = ntohs (message->size);
440 if (msize < sizeof (struct GNUNET_RESOLVER_GetMessage)) 439 if (msize < sizeof (struct GNUNET_RESOLVER_GetMessage))
441 { 440 {
442 GNUNET_break (0); 441 GNUNET_break (0);
443 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 442 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
444 return; 443 return;
445 } 444 }
446 msg = (const struct GNUNET_RESOLVER_GetMessage *) message; 445 msg = (const struct GNUNET_RESOLVER_GetMessage *) message;
447 size = msize - sizeof (struct GNUNET_RESOLVER_GetMessage); 446 size = msize - sizeof (struct GNUNET_RESOLVER_GetMessage);
448 direction = ntohl (msg->direction); 447 direction = ntohl (msg->direction);
449 domain = ntohl (msg->domain); 448 domain = ntohl (msg->domain);
450 if (direction == GNUNET_NO) 449 if (direction == GNUNET_NO)
450 {
451 /* IP from hostname */
452 hostname = (const char *) &msg[1];
453 if (hostname[size - 1] != '\0')
451 { 454 {
452 /* IP from hostname */ 455 GNUNET_break (0);
453 hostname = (const char *) &msg[1]; 456 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
454 if (hostname[size - 1] != '\0') 457 return;
455 { 458 }
456 GNUNET_break (0);
457 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
458 return;
459 }
460#if DEBUG_RESOLVER 459#if DEBUG_RESOLVER
461 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 460 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolver asked to look up `%s'.\n"),
462 _("Resolver asked to look up `%s'.\n"), hostname); 461 hostname);
463#endif 462#endif
464 get_ip_from_hostname (client, hostname, domain); 463 get_ip_from_hostname (client, hostname, domain);
465 } 464 }
466 else 465 else
467 { 466 {
468#if DEBUG_RESOLVER 467#if DEBUG_RESOLVER
469 char buf[INET6_ADDRSTRLEN]; 468 char buf[INET6_ADDRSTRLEN];
470#endif 469#endif
471 if (size < sizeof (struct sockaddr)) 470 if (size < sizeof (struct sockaddr))
472 { 471 {
473 GNUNET_break (0); 472 GNUNET_break (0);
474 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 473 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
475 return; 474 return;
476 } 475 }
477 sa = (const struct sockaddr *) &msg[1]; 476 sa = (const struct sockaddr *) &msg[1];
478 switch (sa->sa_family) 477 switch (sa->sa_family)
479 { 478 {
480 case AF_INET: 479 case AF_INET:
481 if (size != sizeof (struct sockaddr_in)) 480 if (size != sizeof (struct sockaddr_in))
482 { 481 {
483 GNUNET_break (0); 482 GNUNET_break (0);
484 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 483 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
485 return; 484 return;
486 } 485 }
487#if DEBUG_RESOLVER 486#if DEBUG_RESOLVER
488 inet_ntop (AF_INET, sa, buf, size); 487 inet_ntop (AF_INET, sa, buf, size);
489#endif 488#endif
490 break; 489 break;
491 case AF_INET6: 490 case AF_INET6:
492 if (size != sizeof (struct sockaddr_in6)) 491 if (size != sizeof (struct sockaddr_in6))
493 { 492 {
494 GNUNET_break (0); 493 GNUNET_break (0);
495 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 494 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
496 return; 495 return;
497 } 496 }
498#if DEBUG_RESOLVER 497#if DEBUG_RESOLVER
499 inet_ntop (AF_INET6, sa, buf, size); 498 inet_ntop (AF_INET6, sa, buf, size);
500#endif 499#endif
501 break; 500 break;
502 default: 501 default:
503 GNUNET_break (0); 502 GNUNET_break (0);
504 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 503 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
505 return; 504 return;
506 } 505 }
507#if DEBUG_RESOLVER 506#if DEBUG_RESOLVER
508 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 507 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
509 _("Resolver asked to look up IP address `%s'.\n"), buf); 508 _("Resolver asked to look up IP address `%s'.\n"), buf);
510#endif 509#endif
511 get_ip_as_string (client, sa, size); 510 get_ip_as_string (client, sa, size);
512 } 511 }
513} 512}
514 513
515 514
@@ -546,18 +545,18 @@ main (int argc, char *const *argv)
546 struct IPCache *pos; 545 struct IPCache *pos;
547 546
548 ret = 547 ret =
549 (GNUNET_OK == 548 (GNUNET_OK ==
550 GNUNET_SERVICE_run (argc, argv, "resolver", GNUNET_SERVICE_OPTION_NONE, 549 GNUNET_SERVICE_run (argc, argv, "resolver", GNUNET_SERVICE_OPTION_NONE,
551 &run, NULL)) ? 0 : 1; 550 &run, NULL)) ? 0 : 1;
552 551
553 while (head != NULL) 552 while (head != NULL)
554 { 553 {
555 pos = head->next; 554 pos = head->next;
556 GNUNET_free_non_null (head->addr); 555 GNUNET_free_non_null (head->addr);
557 GNUNET_free (head->sa); 556 GNUNET_free (head->sa);
558 GNUNET_free (head); 557 GNUNET_free (head);
559 head = pos; 558 head = pos;
560 } 559 }
561 return ret; 560 return ret;
562} 561}
563 562
diff --git a/src/util/load.c b/src/util/load.c
index 1df1abc7c..e978a950d 100644
--- a/src/util/load.c
+++ b/src/util/load.c
@@ -94,23 +94,23 @@ internal_update (struct GNUNET_LOAD_Value *load)
94 if (delta.rel_value < load->autodecline.rel_value) 94 if (delta.rel_value < load->autodecline.rel_value)
95 return; 95 return;
96 if (load->autodecline.rel_value == 0) 96 if (load->autodecline.rel_value == 0)
97 { 97 {
98 load->runavg_delay = 0.0; 98 load->runavg_delay = 0.0;
99 load->load = 0; 99 load->load = 0;
100 return; 100 return;
101 } 101 }
102 n = delta.rel_value / load->autodecline.rel_value; 102 n = delta.rel_value / load->autodecline.rel_value;
103 if (n > 16) 103 if (n > 16)
104 { 104 {
105 load->runavg_delay = 0.0; 105 load->runavg_delay = 0.0;
106 load->load = 0; 106 load->load = 0;
107 return; 107 return;
108 } 108 }
109 while (n > 0) 109 while (n > 0)
110 { 110 {
111 n--; 111 n--;
112 load->runavg_delay = (load->runavg_delay * 7.0) / 8.0; 112 load->runavg_delay = (load->runavg_delay * 7.0) / 8.0;
113 } 113 }
114} 114}
115 115
116 116
@@ -142,7 +142,7 @@ GNUNET_LOAD_value_init (struct GNUNET_TIME_Relative autodecline)
142 */ 142 */
143void 143void
144GNUNET_LOAD_value_set_decline (struct GNUNET_LOAD_Value *load, 144GNUNET_LOAD_value_set_decline (struct GNUNET_LOAD_Value *load,
145 struct GNUNET_TIME_Relative autodecline) 145 struct GNUNET_TIME_Relative autodecline)
146{ 146{
147 internal_update (load); 147 internal_update (load);
148 load->autodecline = autodecline; 148 load->autodecline = autodecline;
@@ -177,10 +177,10 @@ calculate_load (struct GNUNET_LOAD_Value *load)
177 nm1 = n - 1.0; 177 nm1 = n - 1.0;
178 avgdel = sum_val_i / n; 178 avgdel = sum_val_i / n;
179 stddev = 179 stddev =
180 (((double) load->cummulative_squared_delay) - 2.0 * avgdel * sum_val_i + 180 (((double) load->cummulative_squared_delay) - 2.0 * avgdel * sum_val_i +
181 n * avgdel * avgdel) / nm1; 181 n * avgdel * avgdel) / nm1;
182 if (stddev <= 0) 182 if (stddev <= 0)
183 stddev = 0.01; /* must have been rounding error or zero; prevent division by zero */ 183 stddev = 0.01; /* must have been rounding error or zero; prevent division by zero */
184 /* now calculate load based on how far out we are from 184 /* now calculate load based on how far out we are from
185 * std dev; or if we are below average, simply assume load zero */ 185 * std dev; or if we are below average, simply assume load zero */
186 if (load->runavg_delay < avgdel) 186 if (load->runavg_delay < avgdel)
@@ -243,11 +243,11 @@ GNUNET_LOAD_update (struct GNUNET_LOAD_Value *load, uint64_t data)
243 internal_update (load); 243 internal_update (load);
244 load->last_update = GNUNET_TIME_absolute_get (); 244 load->last_update = GNUNET_TIME_absolute_get ();
245 if (data > 64 * 1024) 245 if (data > 64 * 1024)
246 { 246 {
247 /* very large */ 247 /* very large */
248 load->load = 100.0; 248 load->load = 100.0;
249 return; 249 return;
250 } 250 }
251 dv = (uint32_t) data; 251 dv = (uint32_t) data;
252 load->cummulative_delay += dv; 252 load->cummulative_delay += dv;
253 load->cummulative_squared_delay += dv * dv; 253 load->cummulative_squared_delay += dv * dv;
diff --git a/src/util/network.c b/src/util/network.c
index 3fc71e666..180adc164 100644
--- a/src/util/network.c
+++ b/src/util/network.c
@@ -90,11 +90,11 @@ socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, int doBlock)
90 mode = !doBlock; 90 mode = !doBlock;
91 if (ioctlsocket (fd->fd, FIONBIO, &mode) == SOCKET_ERROR) 91 if (ioctlsocket (fd->fd, FIONBIO, &mode) == SOCKET_ERROR)
92 92
93 { 93 {
94 SetErrnoFromWinsockError (WSAGetLastError ()); 94 SetErrnoFromWinsockError (WSAGetLastError ());
95 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "ioctlsocket"); 95 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "ioctlsocket");
96 return GNUNET_SYSERR; 96 return GNUNET_SYSERR;
97 } 97 }
98 return GNUNET_OK; 98 return GNUNET_OK;
99 99
100#else 100#else
@@ -103,10 +103,10 @@ socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, int doBlock)
103 103
104 if (flags == -1) 104 if (flags == -1)
105 105
106 { 106 {
107 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "fcntl"); 107 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "fcntl");
108 return GNUNET_SYSERR; 108 return GNUNET_SYSERR;
109 } 109 }
110 if (doBlock) 110 if (doBlock)
111 flags &= ~O_NONBLOCK; 111 flags &= ~O_NONBLOCK;
112 112
@@ -114,10 +114,10 @@ socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, int doBlock)
114 flags |= O_NONBLOCK; 114 flags |= O_NONBLOCK;
115 if (0 != fcntl (fd->fd, F_SETFL, flags)) 115 if (0 != fcntl (fd->fd, F_SETFL, flags))
116 116
117 { 117 {
118 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "fcntl"); 118 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "fcntl");
119 return GNUNET_SYSERR; 119 return GNUNET_SYSERR;
120 } 120 }
121 return GNUNET_OK; 121 return GNUNET_OK;
122#endif 122#endif
123} 123}
@@ -162,7 +162,7 @@ socket_set_nosigpipe (const struct GNUNET_NETWORK_Handle *h)
162 162
163 if (0 != 163 if (0 !=
164 setsockopt (h->fd, SOL_SOCKET, SO_NOSIGPIPE, &abs_value, 164 setsockopt (h->fd, SOL_SOCKET, SO_NOSIGPIPE, &abs_value,
165 sizeof (abs_value))) 165 sizeof (abs_value)))
166 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); 166 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
167} 167}
168#endif 168#endif
@@ -181,15 +181,14 @@ socket_set_nodelay (const struct GNUNET_NETWORK_Handle *h)
181#ifndef WINDOWS 181#ifndef WINDOWS
182 int value = 1; 182 int value = 1;
183 183
184 if (0 != 184 if (0 != setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, &value, sizeof (value)))
185 setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, &value, sizeof (value)))
186 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); 185 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
187#else 186#else
188 const char *abs_value = "1"; 187 const char *abs_value = "1";
189 188
190 if (0 != 189 if (0 !=
191 setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, abs_value, 190 setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, abs_value,
192 sizeof (abs_value))) 191 sizeof (abs_value)))
193 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); 192 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
194#endif 193#endif
195} 194}
@@ -205,8 +204,7 @@ socket_set_nodelay (const struct GNUNET_NETWORK_Handle *h)
205 */ 204 */
206struct GNUNET_NETWORK_Handle * 205struct GNUNET_NETWORK_Handle *
207GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, 206GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc,
208 struct sockaddr *address, 207 struct sockaddr *address, socklen_t * address_len)
209 socklen_t * address_len)
210{ 208{
211 struct GNUNET_NETWORK_Handle *ret; 209 struct GNUNET_NETWORK_Handle *ret;
212 210
@@ -219,7 +217,7 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc,
219 217
220 if (gsn == 0) 218 if (gsn == 0)
221 LOG (GNUNET_ERROR_TYPE_DEBUG, "Accepting connection on `%s'\n", 219 LOG (GNUNET_ERROR_TYPE_DEBUG, "Accepting connection on `%s'\n",
222 GNUNET_a2s (&name, namelen)); 220 GNUNET_a2s (&name, namelen));
223 } 221 }
224#endif 222#endif
225 ret->fd = accept (desc->fd, address, address_len); 223 ret->fd = accept (desc->fd, address, address_len);
@@ -228,36 +226,36 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc,
228 else 226 else
229 ret->af = desc->af; 227 ret->af = desc->af;
230 if (ret->fd == INVALID_SOCKET) 228 if (ret->fd == INVALID_SOCKET)
231 { 229 {
232#ifdef MINGW 230#ifdef MINGW
233 SetErrnoFromWinsockError (WSAGetLastError ()); 231 SetErrnoFromWinsockError (WSAGetLastError ());
234#endif 232#endif
235 GNUNET_free (ret); 233 GNUNET_free (ret);
236 return NULL; 234 return NULL;
237 } 235 }
238#ifndef MINGW 236#ifndef MINGW
239 if (ret->fd >= FD_SETSIZE) 237 if (ret->fd >= FD_SETSIZE)
240 { 238 {
241 GNUNET_break (0 == close (ret->fd)); 239 GNUNET_break (0 == close (ret->fd));
242 GNUNET_free (ret); 240 GNUNET_free (ret);
243 errno = EMFILE; 241 errno = EMFILE;
244 return NULL; 242 return NULL;
245 } 243 }
246#endif 244#endif
247 if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO)) 245 if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO))
248 246
249 { 247 {
250 248
251 /* we might want to treat this one as fatal... */ 249 /* we might want to treat this one as fatal... */
252 GNUNET_break (0); 250 GNUNET_break (0);
253 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret)); 251 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret));
254 return NULL; 252 return NULL;
255 } 253 }
256 254
257#ifndef MINGW 255#ifndef MINGW
258 if (GNUNET_OK != socket_set_inheritable (ret)) 256 if (GNUNET_OK != socket_set_inheritable (ret))
259 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 257 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
260 "socket_set_inheritable"); 258 "socket_set_inheritable");
261#endif 259#endif
262#ifdef DARWIN 260#ifdef DARWIN
263 socket_set_nosigpipe (ret); 261 socket_set_nosigpipe (ret);
@@ -279,8 +277,8 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc,
279 */ 277 */
280int 278int
281GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, 279GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc,
282 const struct sockaddr *address, 280 const struct sockaddr *address,
283 socklen_t address_len) 281 socklen_t address_len)
284{ 282{
285 int ret; 283 int ret;
286 284
@@ -289,8 +287,7 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc,
289 const int on = 1; 287 const int on = 1;
290 288
291 if (desc->af == AF_INET6) 289 if (desc->af == AF_INET6)
292 if (0 != 290 if (0 != setsockopt (desc->fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on)))
293 setsockopt (desc->fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on)))
294 LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "setsockopt"); 291 LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "setsockopt");
295#endif 292#endif
296#endif 293#endif
@@ -302,11 +299,11 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc,
302#ifndef LINUX 299#ifndef LINUX
303#ifndef MINGW 300#ifndef MINGW
304 if (address->sa_family == AF_UNIX) 301 if (address->sa_family == AF_UNIX)
305 { 302 {
306 const struct sockaddr_un *un = (const struct sockaddr_un *) address; 303 const struct sockaddr_un *un = (const struct sockaddr_un *) address;
307 304
308 (void) unlink (un->sun_path); 305 (void) unlink (un->sun_path);
309 } 306 }
310#endif 307#endif
311#endif 308#endif
312 ret = bind (desc->fd, address, address_len); 309 ret = bind (desc->fd, address, address_len);
@@ -341,8 +338,8 @@ GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc)
341 DWORD error = 0; 338 DWORD error = 0;
342 339
343#if DEBUG_NETWORK 340#if DEBUG_NETWORK
344 LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_NETWORK_socket_close", 341 LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_NETWORK_socket_close", "Closing 0x%x\n",
345 "Closing 0x%x\n", desc->fd); 342 desc->fd);
346#endif 343#endif
347 SetLastError (0); 344 SetLastError (0);
348 ret = closesocket (desc->fd); 345 ret = closesocket (desc->fd);
@@ -350,8 +347,8 @@ GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc)
350 SetErrnoFromWinsockError (error); 347 SetErrnoFromWinsockError (error);
351#if DEBUG_NETWORK 348#if DEBUG_NETWORK
352 LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_NETWORK_socket_close", 349 LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_NETWORK_socket_close",
353 "Closed 0x%x, closesocket() returned %d, GLE is %u\n", 350 "Closed 0x%x, closesocket() returned %d, GLE is %u\n", desc->fd, ret,
354 desc->fd, ret, error); 351 error);
355#endif 352#endif
356#else 353#else
357 ret = close (desc->fd); 354 ret = close (desc->fd);
@@ -359,12 +356,12 @@ GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc)
359#ifndef LINUX 356#ifndef LINUX
360#ifndef MINGW 357#ifndef MINGW
361 if ((desc->af == AF_UNIX) && (NULL != desc->addr)) 358 if ((desc->af == AF_UNIX) && (NULL != desc->addr))
362 { 359 {
363 const struct sockaddr_un *un = (const struct sockaddr_un *) desc->addr; 360 const struct sockaddr_un *un = (const struct sockaddr_un *) desc->addr;
364 361
365 if (0 != unlink (un->sun_path)) 362 if (0 != unlink (un->sun_path))
366 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", un->sun_path); 363 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", un->sun_path);
367 } 364 }
368#endif 365#endif
369#endif 366#endif
370 GNUNET_free_non_null (desc->addr); 367 GNUNET_free_non_null (desc->addr);
@@ -388,7 +385,7 @@ GNUNET_NETWORK_socket_box_native (int fd)
388 struct GNUNET_NETWORK_Handle *ret; 385 struct GNUNET_NETWORK_Handle *ret;
389 386
390 if (fcntl (fd, F_GETFD) < 0) 387 if (fcntl (fd, F_GETFD) < 0)
391 return NULL; /* invalid FD */ 388 return NULL; /* invalid FD */
392 ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle)); 389 ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle));
393 ret->fd = fd; 390 ret->fd = fd;
394 ret->af = AF_UNSPEC; 391 ret->af = AF_UNSPEC;
@@ -406,8 +403,8 @@ GNUNET_NETWORK_socket_box_native (int fd)
406 */ 403 */
407int 404int
408GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, 405GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc,
409 const struct sockaddr *address, 406 const struct sockaddr *address,
410 socklen_t address_len) 407 socklen_t address_len)
411{ 408{
412 int ret; 409 int ret;
413 410
@@ -415,11 +412,11 @@ GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc,
415 412
416#ifdef MINGW 413#ifdef MINGW
417 if (SOCKET_ERROR == ret) 414 if (SOCKET_ERROR == ret)
418 { 415 {
419 SetErrnoFromWinsockError (WSAGetLastError ()); 416 SetErrnoFromWinsockError (WSAGetLastError ());
420 if (errno == EWOULDBLOCK) 417 if (errno == EWOULDBLOCK)
421 errno = EINPROGRESS; 418 errno = EINPROGRESS;
422 } 419 }
423#endif 420#endif
424 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; 421 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
425} 422}
@@ -437,8 +434,8 @@ GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc,
437 */ 434 */
438int 435int
439GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc, 436GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc,
440 int level, int optname, void *optval, 437 int level, int optname, void *optval,
441 socklen_t * optlen) 438 socklen_t * optlen)
442{ 439{
443 int ret; 440 int ret;
444 441
@@ -463,7 +460,7 @@ GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc,
463 */ 460 */
464int 461int
465GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, 462GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc,
466 int backlog) 463 int backlog)
467{ 464{
468 int ret; 465 int ret;
469 466
@@ -486,7 +483,7 @@ GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc,
486 */ 483 */
487ssize_t 484ssize_t
488GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle * 485GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle *
489 desc) 486 desc)
490{ 487{
491 int error; 488 int error;
492 489
@@ -519,9 +516,8 @@ GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle *
519 */ 516 */
520ssize_t 517ssize_t
521GNUNET_NETWORK_socket_recvfrom (const struct GNUNET_NETWORK_Handle * desc, 518GNUNET_NETWORK_socket_recvfrom (const struct GNUNET_NETWORK_Handle * desc,
522 void *buffer, size_t length, 519 void *buffer, size_t length,
523 struct sockaddr * src_addr, 520 struct sockaddr * src_addr, socklen_t * addrlen)
524 socklen_t * addrlen)
525{ 521{
526 int ret; 522 int ret;
527 int flags; 523 int flags;
@@ -549,7 +545,7 @@ GNUNET_NETWORK_socket_recvfrom (const struct GNUNET_NETWORK_Handle * desc,
549 */ 545 */
550ssize_t 546ssize_t
551GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle * desc, 547GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle * desc,
552 void *buffer, size_t length) 548 void *buffer, size_t length)
553{ 549{
554 int ret; 550 int ret;
555 int flags; 551 int flags;
@@ -578,7 +574,7 @@ GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle * desc,
578 */ 574 */
579ssize_t 575ssize_t
580GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle * desc, 576GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle * desc,
581 const void *buffer, size_t length) 577 const void *buffer, size_t length)
582{ 578{
583 int ret; 579 int ret;
584 int flags; 580 int flags;
@@ -617,9 +613,9 @@ GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle * desc,
617 */ 613 */
618ssize_t 614ssize_t
619GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc, 615GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc,
620 const void *message, size_t length, 616 const void *message, size_t length,
621 const struct sockaddr * dest_addr, 617 const struct sockaddr * dest_addr,
622 socklen_t dest_len) 618 socklen_t dest_len)
623{ 619{
624 int ret; 620 int ret;
625 int flags; 621 int flags;
@@ -652,8 +648,8 @@ GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc,
652 */ 648 */
653int 649int
654GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd, int level, 650GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd, int level,
655 int option_name, const void *option_value, 651 int option_name, const void *option_value,
656 socklen_t option_len) 652 socklen_t option_len)
657{ 653{
658 int ret; 654 int ret;
659 655
@@ -685,36 +681,36 @@ GNUNET_NETWORK_socket_create (int domain, int type, int protocol)
685 ret->af = domain; 681 ret->af = domain;
686 ret->fd = socket (domain, type, protocol); 682 ret->fd = socket (domain, type, protocol);
687 if (INVALID_SOCKET == ret->fd) 683 if (INVALID_SOCKET == ret->fd)
688 { 684 {
689#ifdef MINGW 685#ifdef MINGW
690 SetErrnoFromWinsockError (WSAGetLastError ()); 686 SetErrnoFromWinsockError (WSAGetLastError ());
691#endif 687#endif
692 GNUNET_free (ret); 688 GNUNET_free (ret);
693 return NULL; 689 return NULL;
694 } 690 }
695 691
696#ifndef MINGW 692#ifndef MINGW
697 if (ret->fd >= FD_SETSIZE) 693 if (ret->fd >= FD_SETSIZE)
698 { 694 {
699 GNUNET_break (0 == close (ret->fd)); 695 GNUNET_break (0 == close (ret->fd));
700 GNUNET_free (ret); 696 GNUNET_free (ret);
701 errno = EMFILE; 697 errno = EMFILE;
702 return NULL; 698 return NULL;
703 } 699 }
704 700
705#endif 701#endif
706 if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO)) 702 if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO))
707 { 703 {
708 /* we might want to treat this one as fatal... */ 704 /* we might want to treat this one as fatal... */
709 GNUNET_break (0); 705 GNUNET_break (0);
710 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret)); 706 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret));
711 return NULL; 707 return NULL;
712 } 708 }
713 709
714#ifndef MINGW 710#ifndef MINGW
715 if (GNUNET_OK != socket_set_inheritable (ret)) 711 if (GNUNET_OK != socket_set_inheritable (ret))
716 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 712 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
717 "socket_set_inheritable"); 713 "socket_set_inheritable");
718#endif 714#endif
719#ifdef DARWIN 715#ifdef DARWIN
720 socket_set_nosigpipe (ret); 716 socket_set_nosigpipe (ret);
@@ -723,7 +719,7 @@ GNUNET_NETWORK_socket_create (int domain, int type, int protocol)
723#ifdef AF_UNIX 719#ifdef AF_UNIX
724 && (domain != AF_UNIX) 720 && (domain != AF_UNIX)
725#endif 721#endif
726 ) 722 )
727 socket_set_nodelay (ret); 723 socket_set_nodelay (ret);
728 return ret; 724 return ret;
729} 725}
@@ -762,18 +758,19 @@ int
762GNUNET_NETWORK_socket_disable_corking (struct GNUNET_NETWORK_Handle *desc) 758GNUNET_NETWORK_socket_disable_corking (struct GNUNET_NETWORK_Handle *desc)
763{ 759{
764 int ret = 0; 760 int ret = 0;
761
765#if WINDOWS 762#if WINDOWS
766 int value = 0; 763 int value = 0;
767 764
768 if (0 != 765 if (0 !=
769 (ret = 766 (ret =
770 setsockopt (desc->fd, SOL_SOCKET, SO_SNDBUF, (char *) &value, 767 setsockopt (desc->fd, SOL_SOCKET, SO_SNDBUF, (char *) &value,
771 sizeof (value)))) 768 sizeof (value))))
772 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); 769 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
773 if (0 != 770 if (0 !=
774 (ret = 771 (ret =
775 setsockopt (desc->fd, SOL_SOCKET, SO_RCVBUF, (char *) &value, 772 setsockopt (desc->fd, SOL_SOCKET, SO_RCVBUF, (char *) &value,
776 sizeof (value)))) 773 sizeof (value))))
777 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); 774 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
778#elif LINUX 775#elif LINUX
779 int value = 0; 776 int value = 0;
@@ -812,7 +809,7 @@ GNUNET_NETWORK_fdset_zero (struct GNUNET_NETWORK_FDSet *fds)
812 */ 809 */
813void 810void
814GNUNET_NETWORK_fdset_set (struct GNUNET_NETWORK_FDSet *fds, 811GNUNET_NETWORK_fdset_set (struct GNUNET_NETWORK_FDSet *fds,
815 const struct GNUNET_NETWORK_Handle *desc) 812 const struct GNUNET_NETWORK_Handle *desc)
816{ 813{
817 FD_SET (desc->fd, &fds->sds); 814 FD_SET (desc->fd, &fds->sds);
818 if (desc->fd + 1 > fds->nsds) 815 if (desc->fd + 1 > fds->nsds)
@@ -828,7 +825,7 @@ GNUNET_NETWORK_fdset_set (struct GNUNET_NETWORK_FDSet *fds,
828 */ 825 */
829int 826int
830GNUNET_NETWORK_fdset_isset (const struct GNUNET_NETWORK_FDSet *fds, 827GNUNET_NETWORK_fdset_isset (const struct GNUNET_NETWORK_FDSet *fds,
831 const struct GNUNET_NETWORK_Handle *desc) 828 const struct GNUNET_NETWORK_Handle *desc)
832{ 829{
833 return FD_ISSET (desc->fd, &fds->sds); 830 return FD_ISSET (desc->fd, &fds->sds);
834} 831}
@@ -841,18 +838,18 @@ GNUNET_NETWORK_fdset_isset (const struct GNUNET_NETWORK_FDSet *fds,
841 */ 838 */
842void 839void
843GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst, 840GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst,
844 const struct GNUNET_NETWORK_FDSet *src) 841 const struct GNUNET_NETWORK_FDSet *src)
845{ 842{
846 int nfds; 843 int nfds;
847 844
848 for (nfds = src->nsds; nfds > 0; nfds--) 845 for (nfds = src->nsds; nfds > 0; nfds--)
849 if (FD_ISSET (nfds, &src->sds)) 846 if (FD_ISSET (nfds, &src->sds))
850 847
851 { 848 {
852 FD_SET (nfds, &dst->sds); 849 FD_SET (nfds, &dst->sds);
853 if (nfds + 1 > dst->nsds) 850 if (nfds + 1 > dst->nsds)
854 dst->nsds = nfds + 1; 851 dst->nsds = nfds + 1;
855 } 852 }
856#ifdef MINGW 853#ifdef MINGW
857 GNUNET_CONTAINER_slist_append (dst->handles, src->handles); 854 GNUNET_CONTAINER_slist_append (dst->handles, src->handles);
858#endif 855#endif
@@ -867,7 +864,7 @@ GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst,
867 */ 864 */
868void 865void
869GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to, 866GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to,
870 const struct GNUNET_NETWORK_FDSet *from) 867 const struct GNUNET_NETWORK_FDSet *from)
871{ 868{
872 FD_COPY (&from->sds, &to->sds); 869 FD_COPY (&from->sds, &to->sds);
873 to->nsds = from->nsds; 870 to->nsds = from->nsds;
@@ -901,7 +898,7 @@ GNUNET_NETWORK_get_fd (struct GNUNET_NETWORK_Handle *desc)
901 */ 898 */
902void 899void
903GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to, 900GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to,
904 const fd_set * from, int nfds) 901 const fd_set * from, int nfds)
905{ 902{
906 FD_COPY (from, &to->sds); 903 FD_COPY (from, &to->sds);
907 to->nsds = nfds; 904 to->nsds = nfds;
@@ -932,7 +929,7 @@ GNUNET_NETWORK_fdset_set_native (struct GNUNET_NETWORK_FDSet *to, int nfd)
932 */ 929 */
933int 930int
934GNUNET_NETWORK_fdset_test_native (const struct GNUNET_NETWORK_FDSet *to, 931GNUNET_NETWORK_fdset_test_native (const struct GNUNET_NETWORK_FDSet *to,
935 int nfd) 932 int nfd)
936{ 933{
937 if ((nfd == -1) || (to == NULL)) 934 if ((nfd == -1) || (to == NULL))
938 return GNUNET_NO; 935 return GNUNET_NO;
@@ -947,12 +944,12 @@ GNUNET_NETWORK_fdset_test_native (const struct GNUNET_NETWORK_FDSet *to,
947 */ 944 */
948void 945void
949GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds, 946GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds,
950 const struct GNUNET_DISK_FileHandle *h) 947 const struct GNUNET_DISK_FileHandle *h)
951{ 948{
952#ifdef MINGW 949#ifdef MINGW
953 GNUNET_CONTAINER_slist_add (fds->handles, 950 GNUNET_CONTAINER_slist_add (fds->handles,
954 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, h, 951 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, h,
955 sizeof (struct GNUNET_DISK_FileHandle)); 952 sizeof (struct GNUNET_DISK_FileHandle));
956 953
957#else 954#else
958 int fd; 955 int fd;
@@ -974,13 +971,13 @@ GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds,
974 */ 971 */
975int 972int
976GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds, 973GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds,
977 const struct GNUNET_DISK_FileHandle *h) 974 const struct GNUNET_DISK_FileHandle *h)
978{ 975{
979 976
980#ifdef MINGW 977#ifdef MINGW
981 return GNUNET_CONTAINER_slist_contains (fds->handles, h, 978 return GNUNET_CONTAINER_slist_contains (fds->handles, h,
982 sizeof (struct 979 sizeof (struct
983 GNUNET_DISK_FileHandle)); 980 GNUNET_DISK_FileHandle));
984#else 981#else
985 return FD_ISSET (h->fd, &fds->sds); 982 return FD_ISSET (h->fd, &fds->sds);
986#endif 983#endif
@@ -995,7 +992,7 @@ GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds,
995 */ 992 */
996int 993int
997GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, 994GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1,
998 const struct GNUNET_NETWORK_FDSet *fds2) 995 const struct GNUNET_NETWORK_FDSet *fds2)
999{ 996{
1000#ifndef MINGW 997#ifndef MINGW
1001 int nfds; 998 int nfds;
@@ -1004,11 +1001,11 @@ GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1,
1004 if (nfds > fds2->nsds) 1001 if (nfds > fds2->nsds)
1005 nfds = fds2->nsds; 1002 nfds = fds2->nsds;
1006 while (nfds > 0) 1003 while (nfds > 0)
1007 { 1004 {
1008 nfds--; 1005 nfds--;
1009 if (FD_ISSET (nfds, &fds1->sds) && FD_ISSET (nfds, &fds2->sds)) 1006 if (FD_ISSET (nfds, &fds1->sds) && FD_ISSET (nfds, &fds2->sds))
1010 return GNUNET_YES; 1007 return GNUNET_YES;
1011 } 1008 }
1012#else 1009#else
1013 struct GNUNET_CONTAINER_SList_Iterator it; 1010 struct GNUNET_CONTAINER_SList_Iterator it;
1014 struct GNUNET_DISK_FileHandle *h; 1011 struct GNUNET_DISK_FileHandle *h;
@@ -1019,47 +1016,45 @@ GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1,
1019 * inside of fd_set; also the O(n^2) is really bad... */ 1016 * inside of fd_set; also the O(n^2) is really bad... */
1020 1017
1021 for (i = 0; i < fds1->sds.fd_count; i++) 1018 for (i = 0; i < fds1->sds.fd_count; i++)
1019 {
1020 for (j = 0; j < fds2->sds.fd_count; j++)
1022 { 1021 {
1023 for (j = 0; j < fds2->sds.fd_count; j++) 1022 if (fds1->sds.fd_array[i] == fds2->sds.fd_array[j])
1024 { 1023 return GNUNET_YES;
1025 if (fds1->sds.fd_array[i] == fds2->sds.fd_array[j])
1026 return GNUNET_YES;
1027 }
1028 } 1024 }
1025 }
1029 it = GNUNET_CONTAINER_slist_begin (fds1->handles); 1026 it = GNUNET_CONTAINER_slist_begin (fds1->handles);
1030 while (GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES) 1027 while (GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES)
1031 { 1028 {
1032#if DEBUG_NETWORK 1029#if DEBUG_NETWORK
1033 struct GNUNET_CONTAINER_SList_Iterator t; 1030 struct GNUNET_CONTAINER_SList_Iterator t;
1034#endif 1031#endif
1035 h = 1032 h = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&it,
1036 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&it, 1033 NULL);
1037 NULL);
1038#if DEBUG_NETWORK 1034#if DEBUG_NETWORK
1039 LOG (GNUNET_ERROR_TYPE_DEBUG, 1035 LOG (GNUNET_ERROR_TYPE_DEBUG, "Checking that FD 0x%x is in another set:\n",
1040 "Checking that FD 0x%x is in another set:\n", h->h); 1036 h->h);
1041 for (t = GNUNET_CONTAINER_slist_begin (fds2->handles); 1037 for (t = GNUNET_CONTAINER_slist_begin (fds2->handles);
1042 GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES; 1038 GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES;
1043 GNUNET_CONTAINER_slist_next (&t)) 1039 GNUNET_CONTAINER_slist_next (&t))
1044 { 1040 {
1045 struct GNUNET_DISK_FileHandle *fh; 1041 struct GNUNET_DISK_FileHandle *fh;
1046 1042
1047 fh = 1043 fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t,
1048 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t, 1044 NULL);
1049 NULL); 1045 LOG (GNUNET_ERROR_TYPE_DEBUG, "0x%x\n", fh->h);
1050 LOG (GNUNET_ERROR_TYPE_DEBUG, "0x%x\n", fh->h); 1046 }
1051 } 1047#endif
1052#endif 1048 if (GNUNET_CONTAINER_slist_contains
1053 if (GNUNET_CONTAINER_slist_contains 1049 (fds2->handles, h, sizeof (struct GNUNET_DISK_FileHandle)))
1054 (fds2->handles, h, sizeof (struct GNUNET_DISK_FileHandle))) 1050 {
1055 {
1056#if DEBUG_NETWORK 1051#if DEBUG_NETWORK
1057 LOG (GNUNET_ERROR_TYPE_DEBUG, "Match!\n"); 1052 LOG (GNUNET_ERROR_TYPE_DEBUG, "Match!\n");
1058#endif 1053#endif
1059 return GNUNET_YES; 1054 return GNUNET_YES;
1060 }
1061 GNUNET_CONTAINER_slist_next (&it);
1062 } 1055 }
1056 GNUNET_CONTAINER_slist_next (&it);
1057 }
1063#endif 1058#endif
1064 return GNUNET_NO; 1059 return GNUNET_NO;
1065} 1060}
@@ -1106,9 +1101,9 @@ GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds)
1106 */ 1101 */
1107int 1102int
1108GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, 1103GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
1109 struct GNUNET_NETWORK_FDSet *wfds, 1104 struct GNUNET_NETWORK_FDSet *wfds,
1110 struct GNUNET_NETWORK_FDSet *efds, 1105 struct GNUNET_NETWORK_FDSet *efds,
1111 const struct GNUNET_TIME_Relative timeout) 1106 const struct GNUNET_TIME_Relative timeout)
1112{ 1107{
1113 int nfds = 0; 1108 int nfds = 0;
1114 1109
@@ -1138,8 +1133,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
1138 DWORD newretcode = 0; 1133 DWORD newretcode = 0;
1139 int returnedpos = 0; 1134 int returnedpos = 0;
1140 1135
1141 struct GNUNET_CONTAINER_SList *handles_read, *handles_write, 1136 struct GNUNET_CONTAINER_SList *handles_read, *handles_write, *handles_except;
1142 *handles_except;
1143 1137
1144 fd_set aread, awrite, aexcept; 1138 fd_set aread, awrite, aexcept;
1145 1139
@@ -1153,68 +1147,67 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
1153 struct timeval tv; 1147 struct timeval tv;
1154#endif 1148#endif
1155 if (NULL != rfds) 1149 if (NULL != rfds)
1156 { 1150 {
1157 nfds = rfds->nsds; 1151 nfds = rfds->nsds;
1158#ifdef MINGW 1152#ifdef MINGW
1159 handles += read_handles = GNUNET_CONTAINER_slist_count (rfds->handles); 1153 handles += read_handles = GNUNET_CONTAINER_slist_count (rfds->handles);
1160#if DEBUG_NETWORK 1154#if DEBUG_NETWORK
1155 {
1156 struct GNUNET_CONTAINER_SList_Iterator t;
1157
1158 for (t = GNUNET_CONTAINER_slist_begin (rfds->handles);
1159 GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES;
1160 GNUNET_CONTAINER_slist_next (&t))
1161 { 1161 {
1162 struct GNUNET_CONTAINER_SList_Iterator t; 1162 struct GNUNET_DISK_FileHandle *fh;
1163 1163
1164 for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); 1164 fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t,
1165 GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES; 1165 NULL);
1166 GNUNET_CONTAINER_slist_next (&t)) 1166 LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x (0x%x) is SET in rfds\n", fh->h,
1167 { 1167 fh);
1168 struct GNUNET_DISK_FileHandle *fh;
1169
1170 fh =
1171 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t,
1172 NULL);
1173 LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x (0x%x) is SET in rfds\n",
1174 fh->h, fh);
1175 }
1176 } 1168 }
1169 }
1177#endif 1170#endif
1178#endif 1171#endif
1179 } 1172 }
1180 if (NULL != wfds) 1173 if (NULL != wfds)
1181 { 1174 {
1182 nfds = GNUNET_MAX (nfds, wfds->nsds); 1175 nfds = GNUNET_MAX (nfds, wfds->nsds);
1183#ifdef MINGW 1176#ifdef MINGW
1184 handles += write_handles = GNUNET_CONTAINER_slist_count (wfds->handles); 1177 handles += write_handles = GNUNET_CONTAINER_slist_count (wfds->handles);
1185#endif 1178#endif
1186 } 1179 }
1187 if (NULL != efds) 1180 if (NULL != efds)
1188 { 1181 {
1189 nfds = GNUNET_MAX (nfds, efds->nsds); 1182 nfds = GNUNET_MAX (nfds, efds->nsds);
1190#ifdef MINGW 1183#ifdef MINGW
1191 handles += ex_handles = GNUNET_CONTAINER_slist_count (efds->handles); 1184 handles += ex_handles = GNUNET_CONTAINER_slist_count (efds->handles);
1192#endif 1185#endif
1193 } 1186 }
1194 1187
1195 if ((nfds == 0) && 1188 if ((nfds == 0) &&
1196 (timeout.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value) 1189 (timeout.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
1197#ifdef MINGW 1190#ifdef MINGW
1198 && handles == 0 1191 && handles == 0
1199#endif 1192#endif
1200 ) 1193 )
1201 { 1194 {
1202 LOG (GNUNET_ERROR_TYPE_ERROR, 1195 LOG (GNUNET_ERROR_TYPE_ERROR,
1203 _ 1196 _
1204 ("Fatal internal logic error, process hangs in `%s' (abort with CTRL-C)!\n"), 1197 ("Fatal internal logic error, process hangs in `%s' (abort with CTRL-C)!\n"),
1205 "select"); 1198 "select");
1206 GNUNET_break (0); 1199 GNUNET_break (0);
1207 } 1200 }
1208#ifndef MINGW 1201#ifndef MINGW
1209 tv.tv_sec = timeout.rel_value / GNUNET_TIME_UNIT_SECONDS.rel_value; 1202 tv.tv_sec = timeout.rel_value / GNUNET_TIME_UNIT_SECONDS.rel_value;
1210 tv.tv_usec = 1203 tv.tv_usec =
1211 1000 * (timeout.rel_value - 1204 1000 * (timeout.rel_value -
1212 (tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.rel_value)); 1205 (tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.rel_value));
1213 return select (nfds, (rfds != NULL) ? &rfds->sds : NULL, 1206 return select (nfds, (rfds != NULL) ? &rfds->sds : NULL,
1214 (wfds != NULL) ? &wfds->sds : NULL, 1207 (wfds != NULL) ? &wfds->sds : NULL,
1215 (efds != NULL) ? &efds->sds : NULL, 1208 (efds != NULL) ? &efds->sds : NULL,
1216 (timeout.rel_value == 1209 (timeout.rel_value ==
1217 GNUNET_TIME_UNIT_FOREVER_REL.rel_value) ? NULL : &tv); 1210 GNUNET_TIME_UNIT_FOREVER_REL.rel_value) ? NULL : &tv);
1218 1211
1219#else 1212#else
1220#define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set)) 1213#define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set))
@@ -1225,10 +1218,10 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
1225 ms_total = timeout.rel_value / GNUNET_TIME_UNIT_MILLISECONDS.rel_value; 1218 ms_total = timeout.rel_value / GNUNET_TIME_UNIT_MILLISECONDS.rel_value;
1226 /* select() may be used as a portable way to sleep */ 1219 /* select() may be used as a portable way to sleep */
1227 if (!(rfds || wfds || efds)) 1220 if (!(rfds || wfds || efds))
1228 { 1221 {
1229 Sleep (ms_total); 1222 Sleep (ms_total);
1230 return 0; 1223 return 0;
1231 } 1224 }
1232 1225
1233 /* Events for sockets */ 1226 /* Events for sockets */
1234 if (!hEventRead) 1227 if (!hEventRead)
@@ -1264,194 +1257,184 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
1264 FD_ZERO (&bexcept); 1257 FD_ZERO (&bexcept);
1265#endif 1258#endif
1266 if (rfds) 1259 if (rfds)
1267 { 1260 {
1268 FD_COPY (&rfds->sds, &aread); 1261 FD_COPY (&rfds->sds, &aread);
1269#if DEBUG_NETWORK 1262#if DEBUG_NETWORK
1270 FD_COPY (&rfds->sds, &bread); 1263 FD_COPY (&rfds->sds, &bread);
1271#endif 1264#endif
1272 } 1265 }
1273 if (wfds) 1266 if (wfds)
1274 { 1267 {
1275 FD_COPY (&wfds->sds, &awrite); 1268 FD_COPY (&wfds->sds, &awrite);
1276#if DEBUG_NETWORK 1269#if DEBUG_NETWORK
1277 FD_COPY (&wfds->sds, &bwrite); 1270 FD_COPY (&wfds->sds, &bwrite);
1278#endif 1271#endif
1279 } 1272 }
1280 if (efds) 1273 if (efds)
1281 { 1274 {
1282 FD_COPY (&efds->sds, &aexcept); 1275 FD_COPY (&efds->sds, &aexcept);
1283#if DEBUG_NETWORK 1276#if DEBUG_NETWORK
1284 FD_COPY (&efds->sds, &bexcept); 1277 FD_COPY (&efds->sds, &bexcept);
1285#endif 1278#endif
1286 } 1279 }
1287 /* We will first Add the PIPES to the events */ 1280 /* We will first Add the PIPES to the events */
1288 /* Read Pipes */ 1281 /* Read Pipes */
1289 if (rfds && read_handles) 1282 if (rfds && read_handles)
1283 {
1284 struct GNUNET_CONTAINER_SList_Iterator i;
1285
1286 for (i = GNUNET_CONTAINER_slist_begin (rfds->handles);
1287 GNUNET_CONTAINER_slist_end (&i) != GNUNET_YES;
1288 GNUNET_CONTAINER_slist_next (&i))
1290 { 1289 {
1291 struct GNUNET_CONTAINER_SList_Iterator i; 1290 struct GNUNET_DISK_FileHandle *fh;
1292 1291
1293 for (i = GNUNET_CONTAINER_slist_begin (rfds->handles); 1292 fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&i,
1294 GNUNET_CONTAINER_slist_end (&i) != GNUNET_YES; 1293 NULL);
1295 GNUNET_CONTAINER_slist_next (&i)) 1294 if (fh->type == GNUNET_PIPE)
1296 { 1295 {
1297 struct GNUNET_DISK_FileHandle *fh; 1296 /* Read zero bytes to check the status of the pipe */
1298
1299 fh =
1300 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&i,
1301 NULL);
1302 if (fh->type == GNUNET_PIPE)
1303 {
1304 /* Read zero bytes to check the status of the pipe */
1305#if DEBUG_NETWORK 1297#if DEBUG_NETWORK
1306 LOG (GNUNET_ERROR_TYPE_DEBUG, 1298 LOG (GNUNET_ERROR_TYPE_DEBUG, "Reading 0 bytes from the pipe 0x%x\n",
1307 "Reading 0 bytes from the pipe 0x%x\n", fh->h); 1299 fh->h);
1308#endif 1300#endif
1309 if (!ReadFile (fh->h, NULL, 0, NULL, fh->oOverlapRead)) 1301 if (!ReadFile (fh->h, NULL, 0, NULL, fh->oOverlapRead))
1310 { 1302 {
1311 DWORD error_code = GetLastError (); 1303 DWORD error_code = GetLastError ();
1312 1304
1313 if (error_code == ERROR_IO_PENDING) 1305 if (error_code == ERROR_IO_PENDING)
1314 { 1306 {
1315#if DEBUG_NETWORK 1307#if DEBUG_NETWORK
1316 LOG (GNUNET_ERROR_TYPE_DEBUG, 1308 LOG (GNUNET_ERROR_TYPE_DEBUG,
1317 "Adding the pipe's 0x%x overlapped event to the array as %d\n", 1309 "Adding the pipe's 0x%x overlapped event to the array as %d\n",
1318 fh->h, nhandles); 1310 fh->h, nhandles);
1319#endif 1311#endif
1320 handle_array[nhandles++] = fh->oOverlapRead->hEvent; 1312 handle_array[nhandles++] = fh->oOverlapRead->hEvent;
1321 readArray[readPipes++] = fh; 1313 readArray[readPipes++] = fh;
1322 } 1314 }
1323 /* 1315 /*
1324 * else 1316 * else
1325 * { 1317 * {
1326 * SetErrnoFromWinError (error_code); 1318 * SetErrnoFromWinError (error_code);
1327 * } 1319 * }
1328 */ 1320 */
1329 } 1321 }
1330 else 1322 else
1331 { 1323 {
1332#if DEBUG_NETWORK 1324#if DEBUG_NETWORK
1333 LOG (GNUNET_ERROR_TYPE_DEBUG, 1325 LOG (GNUNET_ERROR_TYPE_DEBUG,
1334 "Adding the read ready event to the array as %d\n", 1326 "Adding the read ready event to the array as %d\n", nhandles);
1335 nhandles); 1327#endif
1336#endif 1328 handle_array[nhandles++] = hEventReadReady;
1337 handle_array[nhandles++] = hEventReadReady; 1329 readArray[readPipes++] = fh;
1338 readArray[readPipes++] = fh; 1330 }
1339 } 1331 }
1340 } 1332 else
1341 else 1333 {
1342 { 1334 GNUNET_CONTAINER_slist_add (handles_read,
1343 GNUNET_CONTAINER_slist_add (handles_read, 1335 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
1344 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, 1336 fh, sizeof (struct GNUNET_DISK_FileHandle));
1345 fh, 1337 }
1346 sizeof (struct
1347 GNUNET_DISK_FileHandle));
1348 }
1349 }
1350 } 1338 }
1339 }
1351 if (wfds && write_handles) 1340 if (wfds && write_handles)
1352 { 1341 {
1353#if DEBUG_NETWORK 1342#if DEBUG_NETWORK
1354 LOG (GNUNET_ERROR_TYPE_DEBUG, 1343 LOG (GNUNET_ERROR_TYPE_DEBUG,
1355 "Adding the write ready event to the array as %d\n", nhandles); 1344 "Adding the write ready event to the array as %d\n", nhandles);
1356#endif 1345#endif
1357 handle_array[nhandles++] = hEventPipeWrite; 1346 handle_array[nhandles++] = hEventPipeWrite;
1358 writePipePos = nhandles; 1347 writePipePos = nhandles;
1359 } 1348 }
1360 if (efds && ex_handles) 1349 if (efds && ex_handles)
1350 {
1351 struct GNUNET_CONTAINER_SList_Iterator i;
1352
1353 for (i = GNUNET_CONTAINER_slist_begin (efds->handles);
1354 GNUNET_CONTAINER_slist_end (&i) != GNUNET_YES;
1355 GNUNET_CONTAINER_slist_next (&i))
1361 { 1356 {
1362 struct GNUNET_CONTAINER_SList_Iterator i; 1357 struct GNUNET_DISK_FileHandle *fh;
1363 1358 DWORD dwBytes;
1364 for (i = GNUNET_CONTAINER_slist_begin (efds->handles); 1359
1365 GNUNET_CONTAINER_slist_end (&i) != GNUNET_YES; 1360 fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&i,
1366 GNUNET_CONTAINER_slist_next (&i)) 1361 NULL);
1367 { 1362 if (fh->type == GNUNET_PIPE)
1368 struct GNUNET_DISK_FileHandle *fh; 1363 {
1369 DWORD dwBytes; 1364 if (!PeekNamedPipe (fh->h, NULL, 0, NULL, &dwBytes, NULL))
1370 1365 {
1371 fh = 1366 GNUNET_CONTAINER_slist_add (handles_except,
1372 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&i, 1367 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
1373 NULL); 1368 fh,
1374 if (fh->type == GNUNET_PIPE) 1369 sizeof (struct GNUNET_DISK_FileHandle));
1375 { 1370 newretcode++;
1376 if (!PeekNamedPipe (fh->h, NULL, 0, NULL, &dwBytes, NULL)) 1371 }
1377 { 1372 }
1378 GNUNET_CONTAINER_slist_add (handles_except,
1379 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
1380 fh,
1381 sizeof (struct
1382 GNUNET_DISK_FileHandle));
1383 newretcode++;
1384 }
1385 }
1386 }
1387 } 1373 }
1374 }
1388 if (nfds > 0) 1375 if (nfds > 0)
1376 {
1377 if (rfds)
1389 { 1378 {
1390 if (rfds)
1391 {
1392#if DEBUG_NETWORK 1379#if DEBUG_NETWORK
1393 LOG (GNUNET_ERROR_TYPE_DEBUG, 1380 LOG (GNUNET_ERROR_TYPE_DEBUG,
1394 "Adding the socket read event to the array as %d\n", nhandles); 1381 "Adding the socket read event to the array as %d\n", nhandles);
1395#endif 1382#endif
1396 handle_array[nhandles++] = hEventRead; 1383 handle_array[nhandles++] = hEventRead;
1397 nSockEvents++; 1384 nSockEvents++;
1398 for (i = 0; i < rfds->sds.fd_count; i++) 1385 for (i = 0; i < rfds->sds.fd_count; i++)
1399 { 1386 {
1400 WSAEventSelect (rfds->sds.fd_array[i], hEventRead, 1387 WSAEventSelect (rfds->sds.fd_array[i], hEventRead,
1401 FD_ACCEPT | FD_READ | FD_CLOSE); 1388 FD_ACCEPT | FD_READ | FD_CLOSE);
1402 nsock++; 1389 nsock++;
1403 } 1390 }
1404 } 1391 }
1405 if (wfds) 1392 if (wfds)
1406 { 1393 {
1407 int wakeup = 0; 1394 int wakeup = 0;
1408 1395
1409#if DEBUG_NETWORK 1396#if DEBUG_NETWORK
1410 LOG (GNUNET_ERROR_TYPE_DEBUG, 1397 LOG (GNUNET_ERROR_TYPE_DEBUG,
1411 "Adding the socket write event to the array as %d\n", 1398 "Adding the socket write event to the array as %d\n", nhandles);
1412 nhandles); 1399#endif
1413#endif 1400 handle_array[nhandles++] = hEventWrite;
1414 handle_array[nhandles++] = hEventWrite; 1401 nSockEvents++;
1415 nSockEvents++; 1402 for (i = 0; i < wfds->sds.fd_count; i++)
1416 for (i = 0; i < wfds->sds.fd_count; i++) 1403 {
1417 { 1404 DWORD error;
1418 DWORD error; 1405 int status;
1419 int status; 1406
1420 1407 status = send (wfds->sds.fd_array[i], NULL, 0, 0);
1421 status = send (wfds->sds.fd_array[i], NULL, 0, 0); 1408 error = GetLastError ();
1422 error = GetLastError ();
1423#if DEBUG_NETWORK 1409#if DEBUG_NETWORK
1424 LOG (GNUNET_ERROR_TYPE_DEBUG, 1410 LOG (GNUNET_ERROR_TYPE_DEBUG,
1425 "pre-send to the socket %d returned %d (%u)\n", i, status, 1411 "pre-send to the socket %d returned %d (%u)\n", i, status, error);
1426 error); 1412#endif
1427#endif 1413 if (status == 0 || (error != WSAEWOULDBLOCK && error != WSAENOTCONN))
1428 if (status == 0 1414 wakeup = 1;
1429 || (error != WSAEWOULDBLOCK && error != WSAENOTCONN)) 1415 WSAEventSelect (wfds->sds.fd_array[i], hEventWrite,
1430 wakeup = 1; 1416 FD_WRITE | FD_CONNECT | FD_CLOSE);
1431 WSAEventSelect (wfds->sds.fd_array[i], hEventWrite, 1417 nsock++;
1432 FD_WRITE | FD_CONNECT | FD_CLOSE); 1418 }
1433 nsock++; 1419 if (wakeup)
1434 } 1420 SetEvent (hEventWrite);
1435 if (wakeup) 1421 }
1436 SetEvent (hEventWrite); 1422 if (efds)
1437 } 1423 {
1438 if (efds)
1439 {
1440#if DEBUG_NETWORK 1424#if DEBUG_NETWORK
1441 LOG (GNUNET_ERROR_TYPE_DEBUG, 1425 LOG (GNUNET_ERROR_TYPE_DEBUG,
1442 "Adding the socket error event to the array as %d\n", 1426 "Adding the socket error event to the array as %d\n", nhandles);
1443 nhandles); 1427#endif
1444#endif 1428 handle_array[nhandles++] = hEventException;
1445 handle_array[nhandles++] = hEventException; 1429 nSockEvents++;
1446 nSockEvents++; 1430 for (i = 0; i < efds->sds.fd_count; i++)
1447 for (i = 0; i < efds->sds.fd_count; i++) 1431 {
1448 { 1432 WSAEventSelect (efds->sds.fd_array[i], hEventException,
1449 WSAEventSelect (efds->sds.fd_array[i], hEventException, 1433 FD_OOB | FD_CLOSE);
1450 FD_OOB | FD_CLOSE); 1434 nsock++;
1451 nsock++; 1435 }
1452 }
1453 }
1454 } 1436 }
1437 }
1455 1438
1456 handle_array[nhandles] = NULL; 1439 handle_array[nhandles] = NULL;
1457 1440
@@ -1464,7 +1447,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
1464 1447
1465 if (nhandles) 1448 if (nhandles)
1466 returncode = 1449 returncode =
1467 WaitForMultipleObjects (nhandles, handle_array, FALSE, ms_total); 1450 WaitForMultipleObjects (nhandles, handle_array, FALSE, ms_total);
1468#if DEBUG_NETWORK 1451#if DEBUG_NETWORK
1469 LOG (GNUNET_ERROR_TYPE_DEBUG, "WaitForMultipleObjects Returned : %d\n", 1452 LOG (GNUNET_ERROR_TYPE_DEBUG, "WaitForMultipleObjects Returned : %d\n",
1470 returncode); 1453 returncode);
@@ -1481,239 +1464,230 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
1481 * GNUNET_CONTAINER_slist_append (handles_read, rfds->handles); 1464 * GNUNET_CONTAINER_slist_append (handles_read, rfds->handles);
1482 */ 1465 */
1483 if (nhandles && (returnedpos < nhandles)) 1466 if (nhandles && (returnedpos < nhandles))
1467 {
1468 DWORD waitstatus;
1469
1470 /* Do the select */
1471 if (nfds)
1484 { 1472 {
1485 DWORD waitstatus; 1473 struct timeval tvslice;
1486 1474
1487 /* Do the select */ 1475 tvslice.tv_sec = 0;
1488 if (nfds) 1476 tvslice.tv_usec = 10;
1489 { 1477 retcode = select (nfds, &aread, &awrite, &aexcept, &tvslice);
1490 struct timeval tvslice; 1478 if (retcode == -1)
1491 1479 retcode = 0;
1492 tvslice.tv_sec = 0;
1493 tvslice.tv_usec = 10;
1494 retcode = select (nfds, &aread, &awrite, &aexcept, &tvslice);
1495 if (retcode == -1)
1496 retcode = 0;
1497#if DEBUG_NETWORK 1480#if DEBUG_NETWORK
1498 LOG (GNUNET_ERROR_TYPE_DEBUG, "Select retcode : %d\n", retcode); 1481 LOG (GNUNET_ERROR_TYPE_DEBUG, "Select retcode : %d\n", retcode);
1499#endif 1482#endif
1500 } 1483 }
1501 /* FIXME: <= writePipePos? Really? */ 1484 /* FIXME: <= writePipePos? Really? */
1502 if ((writePipePos != -1) && (returnedpos <= writePipePos)) 1485 if ((writePipePos != -1) && (returnedpos <= writePipePos))
1503 { 1486 {
1504 GNUNET_CONTAINER_slist_append (handles_write, wfds->handles); 1487 GNUNET_CONTAINER_slist_append (handles_write, wfds->handles);
1505 retcode += write_handles; 1488 retcode += write_handles;
1506#if DEBUG_NETWORK 1489#if DEBUG_NETWORK
1507 LOG (GNUNET_ERROR_TYPE_DEBUG, "Added write pipe\n"); 1490 LOG (GNUNET_ERROR_TYPE_DEBUG, "Added write pipe\n");
1508#endif 1491#endif
1509 } 1492 }
1510#if DEBUG_NETWORK 1493#if DEBUG_NETWORK
1511 LOG (GNUNET_ERROR_TYPE_DEBUG, "ReadPipes is : %d\n", readPipes); 1494 LOG (GNUNET_ERROR_TYPE_DEBUG, "ReadPipes is : %d\n", readPipes);
1512#endif 1495#endif
1513 /* We have some pipes ready for read. */ 1496 /* We have some pipes ready for read. */
1514 /* FIXME: it is supposed to work !! Only choose the Pipes who fired the event, but it is not working */ 1497 /* FIXME: it is supposed to work !! Only choose the Pipes who fired the event, but it is not working */
1515 1498
1516 if (returnedpos < readPipes) 1499 if (returnedpos < readPipes)
1517 { 1500 {
1518 /* 1501 /*
1519 * for (i = 0; i < readPipes; i++) 1502 * for (i = 0; i < readPipes; i++)
1520 * { 1503 * {
1521 * waitstatus = WaitForSingleObject (handle_array[i], 0); 1504 * waitstatus = WaitForSingleObject (handle_array[i], 0);
1522 * LOG (GNUNET_ERROR_TYPE_DEBUG, "Read pipe %d wait status is : %d\n", i, waitstatus); 1505 * LOG (GNUNET_ERROR_TYPE_DEBUG, "Read pipe %d wait status is : %d\n", i, waitstatus);
1523 * if (waitstatus != WAIT_OBJECT_0) 1506 * if (waitstatus != WAIT_OBJECT_0)
1524 * continue; 1507 * continue;
1525 * GNUNET_CONTAINER_slist_add (handles_read, 1508 * GNUNET_CONTAINER_slist_add (handles_read,
1526 * GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, 1509 * GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
1527 * readArray[i], sizeof (struct GNUNET_DISK_FileHandle)); 1510 * readArray[i], sizeof (struct GNUNET_DISK_FileHandle));
1528 * retcode++; 1511 * retcode++;
1529 * LOG (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe\n"); 1512 * LOG (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe\n");
1530 * } 1513 * }
1531 */ 1514 */
1532 for (i = 0; i < readPipes; i++) 1515 for (i = 0; i < readPipes; i++)
1533 { 1516 {
1534 DWORD error; 1517 DWORD error;
1535 BOOL bret; 1518 BOOL bret;
1536 1519
1537 SetLastError (0); 1520 SetLastError (0);
1538 waitstatus = 0; 1521 waitstatus = 0;
1539 bret = 1522 bret =
1540 PeekNamedPipe (readArray[i]->h, NULL, 0, NULL, &waitstatus, 1523 PeekNamedPipe (readArray[i]->h, NULL, 0, NULL, &waitstatus, NULL);
1541 NULL); 1524 error = GetLastError ();
1542 error = GetLastError ();
1543#if DEBUG_NETWORK 1525#if DEBUG_NETWORK
1544 LOG (GNUNET_ERROR_TYPE_DEBUG, 1526 LOG (GNUNET_ERROR_TYPE_DEBUG,
1545 "Peek at read pipe %d (0x%x) returned %d (%d bytes available) GLE %u\n", 1527 "Peek at read pipe %d (0x%x) returned %d (%d bytes available) GLE %u\n",
1546 i, readArray[i]->h, bret, waitstatus, error); 1528 i, readArray[i]->h, bret, waitstatus, error);
1547#endif 1529#endif
1548 if (bret == 0) 1530 if (bret == 0)
1549 { 1531 {
1550 if (error != ERROR_BROKEN_PIPE) 1532 if (error != ERROR_BROKEN_PIPE)
1551 continue; 1533 continue;
1552 } 1534 }
1553 else if (waitstatus <= 0) 1535 else if (waitstatus <= 0)
1554 continue; 1536 continue;
1555 GNUNET_CONTAINER_slist_add (handles_read, 1537 GNUNET_CONTAINER_slist_add (handles_read,
1556 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, 1538 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
1557 readArray[i], 1539 readArray[i],
1558 sizeof (struct 1540 sizeof (struct GNUNET_DISK_FileHandle));
1559 GNUNET_DISK_FileHandle)); 1541 retcode++;
1560 retcode++;
1561#if DEBUG_NETWORK 1542#if DEBUG_NETWORK
1562 LOG (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe 0x%x (0x%x)\n", 1543 LOG (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe 0x%x (0x%x)\n",
1563 readArray[i], readArray[i]->h); 1544 readArray[i], readArray[i]->h);
1564#endif 1545#endif
1565 } 1546 }
1566 } 1547 }
1567 waitstatus = WaitForSingleObject (hEventWrite, 0); 1548 waitstatus = WaitForSingleObject (hEventWrite, 0);
1568#if DEBUG_NETWORK 1549#if DEBUG_NETWORK
1569 LOG (GNUNET_ERROR_TYPE_DEBUG, 1550 LOG (GNUNET_ERROR_TYPE_DEBUG, "Wait for the write event returned %d\n",
1570 "Wait for the write event returned %d\n", waitstatus); 1551 waitstatus);
1571#endif 1552#endif
1572 if (waitstatus == WAIT_OBJECT_0) 1553 if (waitstatus == WAIT_OBJECT_0)
1573 { 1554 {
1574 for (i = 0; i < wfds->sds.fd_count; i++) 1555 for (i = 0; i < wfds->sds.fd_count; i++)
1575 { 1556 {
1576 DWORD error; 1557 DWORD error;
1577 int status; 1558 int status;
1578 int so_error = 0; 1559 int so_error = 0;
1579 int sizeof_so_error = sizeof (so_error); 1560 int sizeof_so_error = sizeof (so_error);
1580 int gso_result = 1561 int gso_result =
1581 getsockopt (wfds->sds.fd_array[i], SOL_SOCKET, SO_ERROR, 1562 getsockopt (wfds->sds.fd_array[i], SOL_SOCKET, SO_ERROR,
1582 (char *) &so_error, &sizeof_so_error); 1563 (char *) &so_error, &sizeof_so_error);
1583 1564
1584 status = send (wfds->sds.fd_array[i], NULL, 0, 0); 1565 status = send (wfds->sds.fd_array[i], NULL, 0, 0);
1585 error = GetLastError (); 1566 error = GetLastError ();
1586#if DEBUG_NETWORK 1567#if DEBUG_NETWORK
1587 LOG (GNUNET_ERROR_TYPE_DEBUG, 1568 LOG (GNUNET_ERROR_TYPE_DEBUG,
1588 "send to the socket %d returned %d (%u)\n", i, status, 1569 "send to the socket %d returned %d (%u)\n", i, status, error);
1589 error); 1570#endif
1590#endif 1571 if (status == 0 || (error != WSAEWOULDBLOCK && error != WSAENOTCONN) ||
1591 if (status == 0 1572 (status == -1 && gso_result == 0 && error == WSAENOTCONN &&
1592 || (error != WSAEWOULDBLOCK && error != WSAENOTCONN) 1573 so_error == WSAECONNREFUSED))
1593 || (status == -1 && gso_result == 0 && error == WSAENOTCONN 1574 {
1594 && so_error == WSAECONNREFUSED)) 1575 FD_SET (wfds->sds.fd_array[i], &awrite);
1595 { 1576 retcode += 1;
1596 FD_SET (wfds->sds.fd_array[i], &awrite); 1577 }
1597 retcode += 1; 1578 }
1598 }
1599 }
1600 }
1601 } 1579 }
1580 }
1602#if DEBUG_NETWORK 1581#if DEBUG_NETWORK
1603 if (!nhandles || (returnedpos >= nhandles)) 1582 if (!nhandles || (returnedpos >= nhandles))
1604 LOG (GNUNET_ERROR_TYPE_DEBUG, "Returning from _select() with nothing!\n"); 1583 LOG (GNUNET_ERROR_TYPE_DEBUG, "Returning from _select() with nothing!\n");
1605#endif 1584#endif
1606 if (rfds) 1585 if (rfds)
1586 {
1587 struct GNUNET_CONTAINER_SList_Iterator t;
1588
1589 for (i = 0; i < rfds->sds.fd_count; i++)
1607 { 1590 {
1608 struct GNUNET_CONTAINER_SList_Iterator t; 1591 WSAEventSelect (rfds->sds.fd_array[i], hEventRead, 0);
1592 nsock++;
1593 }
1594 for (t = GNUNET_CONTAINER_slist_begin (rfds->handles);
1595 GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES;
1596 GNUNET_CONTAINER_slist_next (&t))
1597 {
1598 struct GNUNET_DISK_FileHandle *fh;
1609 1599
1610 for (i = 0; i < rfds->sds.fd_count; i++) 1600 fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t,
1611 { 1601 NULL);
1612 WSAEventSelect (rfds->sds.fd_array[i], hEventRead, 0); 1602 if (fh->type == GNUNET_PIPE)
1613 nsock++; 1603 {
1614 } 1604 CancelIo (fh->h);
1615 for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); 1605 }
1616 GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES; 1606 }
1617 GNUNET_CONTAINER_slist_next (&t))
1618 {
1619 struct GNUNET_DISK_FileHandle *fh;
1620
1621 fh =
1622 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t,
1623 NULL);
1624 if (fh->type == GNUNET_PIPE)
1625 {
1626 CancelIo (fh->h);
1627 }
1628 }
1629#if DEBUG_NETWORK 1607#if DEBUG_NETWORK
1630 LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing rfds\n"); 1608 LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing rfds\n");
1631#endif 1609#endif
1632 GNUNET_NETWORK_fdset_zero (rfds); 1610 GNUNET_NETWORK_fdset_zero (rfds);
1633 if (retcode != -1 && nhandles && (returnedpos < nhandles)) 1611 if (retcode != -1 && nhandles && (returnedpos < nhandles))
1634 GNUNET_NETWORK_fdset_copy_native (rfds, &aread, retcode); 1612 GNUNET_NETWORK_fdset_copy_native (rfds, &aread, retcode);
1635 GNUNET_CONTAINER_slist_append (rfds->handles, handles_read); 1613 GNUNET_CONTAINER_slist_append (rfds->handles, handles_read);
1636 } 1614 }
1637 if (wfds) 1615 if (wfds)
1616 {
1617 for (i = 0; i < wfds->sds.fd_count; i++)
1638 { 1618 {
1639 for (i = 0; i < wfds->sds.fd_count; i++) 1619 WSAEventSelect (wfds->sds.fd_array[i], hEventWrite, 0);
1640 { 1620 nsock++;
1641 WSAEventSelect (wfds->sds.fd_array[i], hEventWrite, 0); 1621 }
1642 nsock++;
1643 }
1644#if DEBUG_NETWORK 1622#if DEBUG_NETWORK
1645 LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing wfds\n"); 1623 LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing wfds\n");
1646#endif 1624#endif
1647 GNUNET_NETWORK_fdset_zero (wfds); 1625 GNUNET_NETWORK_fdset_zero (wfds);
1648 if (retcode != -1 && nhandles && (returnedpos < nhandles)) 1626 if (retcode != -1 && nhandles && (returnedpos < nhandles))
1649 GNUNET_NETWORK_fdset_copy_native (wfds, &awrite, retcode); 1627 GNUNET_NETWORK_fdset_copy_native (wfds, &awrite, retcode);
1650 GNUNET_CONTAINER_slist_append (wfds->handles, handles_write); 1628 GNUNET_CONTAINER_slist_append (wfds->handles, handles_write);
1651 } 1629 }
1652 if (efds) 1630 if (efds)
1631 {
1632 for (i = 0; i < efds->sds.fd_count; i++)
1653 { 1633 {
1654 for (i = 0; i < efds->sds.fd_count; i++) 1634 WSAEventSelect (efds->sds.fd_array[i], hEventException, 0);
1655 { 1635 nsock++;
1656 WSAEventSelect (efds->sds.fd_array[i], hEventException, 0); 1636 }
1657 nsock++;
1658 }
1659#if DEBUG_NETWORK 1637#if DEBUG_NETWORK
1660 LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing efds\n"); 1638 LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing efds\n");
1661#endif 1639#endif
1662 GNUNET_NETWORK_fdset_zero (efds); 1640 GNUNET_NETWORK_fdset_zero (efds);
1663 if (retcode != -1 && nhandles && (returnedpos < nhandles)) 1641 if (retcode != -1 && nhandles && (returnedpos < nhandles))
1664 GNUNET_NETWORK_fdset_copy_native (efds, &aexcept, retcode); 1642 GNUNET_NETWORK_fdset_copy_native (efds, &aexcept, retcode);
1665 GNUNET_CONTAINER_slist_append (efds->handles, handles_except); 1643 GNUNET_CONTAINER_slist_append (efds->handles, handles_except);
1666 } 1644 }
1667 GNUNET_CONTAINER_slist_destroy (handles_read); 1645 GNUNET_CONTAINER_slist_destroy (handles_read);
1668 GNUNET_CONTAINER_slist_destroy (handles_write); 1646 GNUNET_CONTAINER_slist_destroy (handles_write);
1669 GNUNET_CONTAINER_slist_destroy (handles_except); 1647 GNUNET_CONTAINER_slist_destroy (handles_except);
1670#if DEBUG_NETWORK 1648#if DEBUG_NETWORK
1671 if (rfds) 1649 if (rfds)
1650 {
1651 struct GNUNET_CONTAINER_SList_Iterator t;
1652
1653 for (i = 0; i < bread.fd_count; i++)
1672 { 1654 {
1673 struct GNUNET_CONTAINER_SList_Iterator t; 1655 if (bread.fd_array[i] != 0)
1656 LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in rfds\n",
1657 bread.fd_array[i],
1658 (SAFE_FD_ISSET (bread.fd_array[i], rfds)) ? "SET" : "NOT SET");
1659 }
1660 for (t = GNUNET_CONTAINER_slist_begin (rfds->handles);
1661 GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES;
1662 GNUNET_CONTAINER_slist_next (&t))
1663 {
1664 struct GNUNET_DISK_FileHandle *fh;
1674 1665
1675 for (i = 0; i < bread.fd_count; i++) 1666 fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t,
1676 { 1667 NULL);
1677 if (bread.fd_array[i] != 0) 1668 LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is SET in rfds\n", fh->h);
1678 LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in rfds\n",
1679 bread.fd_array[i],
1680 (SAFE_FD_ISSET (bread.fd_array[i], rfds)) ? "SET" :
1681 "NOT SET");
1682 }
1683 for (t = GNUNET_CONTAINER_slist_begin (rfds->handles);
1684 GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES;
1685 GNUNET_CONTAINER_slist_next (&t))
1686 {
1687 struct GNUNET_DISK_FileHandle *fh;
1688
1689 fh =
1690 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t,
1691 NULL);
1692 LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is SET in rfds\n", fh->h);
1693 }
1694 } 1669 }
1670 }
1695 if (wfds) 1671 if (wfds)
1672 {
1673 for (i = 0; i < bwrite.fd_count; i++)
1696 { 1674 {
1697 for (i = 0; i < bwrite.fd_count; i++) 1675 if (bwrite.fd_array[i] != 0)
1698 { 1676 LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in wfds\n",
1699 if (bwrite.fd_array[i] != 0) 1677 bwrite.fd_array[i],
1700 LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in wfds\n", 1678 (SAFE_FD_ISSET (bwrite.fd_array[i], rfds)) ? "SET" : "NOT SET");
1701 bwrite.fd_array[i],
1702 (SAFE_FD_ISSET (bwrite.fd_array[i], rfds)) ? "SET" :
1703 "NOT SET");
1704 }
1705 } 1679 }
1680 }
1706 if (efds) 1681 if (efds)
1682 {
1683 for (i = 0; i < bexcept.fd_count; i++)
1707 { 1684 {
1708 for (i = 0; i < bexcept.fd_count; i++) 1685 if (bexcept.fd_array[i] != 0)
1709 { 1686 LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in efds\n",
1710 if (bexcept.fd_array[i] != 0) 1687 bexcept.fd_array[i],
1711 LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in efds\n", 1688 (SAFE_FD_ISSET (bexcept.fd_array[i], rfds)) ? "SET" : "NOT SET");
1712 bexcept.fd_array[i],
1713 (SAFE_FD_ISSET (bexcept.fd_array[i], rfds)) ? "SET" :
1714 "NOT SET");
1715 }
1716 } 1689 }
1690 }
1717 LOG (GNUNET_ERROR_TYPE_DEBUG, "Returning %d or 0\n", retcode); 1691 LOG (GNUNET_ERROR_TYPE_DEBUG, "Returning %d or 0\n", retcode);
1718#endif 1692#endif
1719 if (nhandles && (returnedpos < nhandles)) 1693 if (nhandles && (returnedpos < nhandles))
diff --git a/src/util/os_installation.c b/src/util/os_installation.c
index 98080a3ed..a7a6ae915 100644
--- a/src/util/os_installation.c
+++ b/src/util/os_installation.c
@@ -60,16 +60,16 @@ get_path_from_proc_maps ()
60 if (f == NULL) 60 if (f == NULL)
61 return NULL; 61 return NULL;
62 while (NULL != fgets (line, sizeof (line), f)) 62 while (NULL != fgets (line, sizeof (line), f))
63 {
64 if ((1 ==
65 sscanf (line, "%*x-%*x %*c%*c%*c%*c %*x %*2u:%*2u %*u%*[ ]%s", dir)) &&
66 (NULL != (lgu = strstr (dir, "libgnunetutil"))))
63 { 67 {
64 if ((1 == 68 lgu[0] = '\0';
65 sscanf (line, "%*x-%*x %*c%*c%*c%*c %*x %*2u:%*2u %*u%*[ ]%s", 69 fclose (f);
66 dir)) && (NULL != (lgu = strstr (dir, "libgnunetutil")))) 70 return GNUNET_strdup (dir);
67 {
68 lgu[0] = '\0';
69 fclose (f);
70 return GNUNET_strdup (dir);
71 }
72 } 71 }
72 }
73 fclose (f); 73 fclose (f);
74 return NULL; 74 return NULL;
75} 75}
@@ -87,19 +87,19 @@ get_path_from_proc_exe ()
87 GNUNET_snprintf (fn, sizeof (fn), "/proc/%u/exe", getpid ()); 87 GNUNET_snprintf (fn, sizeof (fn), "/proc/%u/exe", getpid ());
88 size = readlink (fn, lnk, sizeof (lnk) - 1); 88 size = readlink (fn, lnk, sizeof (lnk) - 1);
89 if (size <= 0) 89 if (size <= 0)
90 { 90 {
91 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "readlink", fn); 91 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "readlink", fn);
92 return NULL; 92 return NULL;
93 } 93 }
94 GNUNET_assert (size < sizeof (lnk)); 94 GNUNET_assert (size < sizeof (lnk));
95 lnk[size] = '\0'; 95 lnk[size] = '\0';
96 while ((lnk[size] != '/') && (size > 0)) 96 while ((lnk[size] != '/') && (size > 0))
97 size--; 97 size--;
98 if ((size < 4) || (lnk[size - 4] != '/')) 98 if ((size < 4) || (lnk[size - 4] != '/'))
99 { 99 {
100 /* not installed in "/bin/" -- binary path probably useless */ 100 /* not installed in "/bin/" -- binary path probably useless */
101 return NULL; 101 return NULL;
102 } 102 }
103 lnk[size] = '\0'; 103 lnk[size] = '\0';
104 return GNUNET_strdup (lnk); 104 return GNUNET_strdup (lnk);
105} 105}
@@ -138,7 +138,7 @@ get_path_from_NSGetExecutablePath ()
138 138
139 path = NULL; 139 path = NULL;
140 func = 140 func =
141 (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT, "_NSGetExecutablePath"); 141 (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT, "_NSGetExecutablePath");
142 if (!func) 142 if (!func)
143 return NULL; 143 return NULL;
144 path = &zero; 144 path = &zero;
@@ -150,10 +150,10 @@ get_path_from_NSGetExecutablePath ()
150 path = GNUNET_malloc (len); 150 path = GNUNET_malloc (len);
151 ret = func (path, &len); 151 ret = func (path, &len);
152 if (ret != 0) 152 if (ret != 0)
153 { 153 {
154 GNUNET_free (path); 154 GNUNET_free (path);
155 return NULL; 155 return NULL;
156 } 156 }
157 len = strlen (path); 157 len = strlen (path);
158 while ((path[len] != '/') && (len > 0)) 158 while ((path[len] != '/') && (len > 0))
159 len--; 159 len--;
@@ -172,22 +172,22 @@ get_path_from_dyld_image ()
172 p = NULL; 172 p = NULL;
173 c = _dyld_image_count (); 173 c = _dyld_image_count ();
174 for (i = 0; i < c; i++) 174 for (i = 0; i < c; i++)
175 {
176 if (_dyld_get_image_header (i) == &_mh_dylib_header)
175 { 177 {
176 if (_dyld_get_image_header (i) == &_mh_dylib_header) 178 path = _dyld_get_image_name (i);
177 { 179 if (path != NULL && strlen (path) > 0)
178 path = _dyld_get_image_name (i); 180 {
179 if (path != NULL && strlen (path) > 0) 181 p = GNUNET_strdup (path);
180 { 182 s = p + strlen (p);
181 p = GNUNET_strdup (path); 183 while ((s > p) && (*s != '/'))
182 s = p + strlen (p); 184 s--;
183 while ((s > p) && (*s != '/')) 185 s++;
184 s--; 186 *s = '\0';
185 s++; 187 }
186 *s = '\0'; 188 break;
187 }
188 break;
189 }
190 } 189 }
190 }
191 return p; 191 return p;
192} 192}
193#endif 193#endif
@@ -211,30 +211,30 @@ get_path_from_PATH (const char *binary)
211 p = getenv ("PATH"); 211 p = getenv ("PATH");
212 if (p == NULL) 212 if (p == NULL)
213 return NULL; 213 return NULL;
214 path = GNUNET_strdup (p); /* because we write on it */ 214 path = GNUNET_strdup (p); /* because we write on it */
215 buf = GNUNET_malloc (strlen (path) + 20); 215 buf = GNUNET_malloc (strlen (path) + 20);
216 pos = path; 216 pos = path;
217 while (NULL != (end = strchr (pos, PATH_SEPARATOR))) 217 while (NULL != (end = strchr (pos, PATH_SEPARATOR)))
218 { 218 {
219 *end = '\0'; 219 *end = '\0';
220 sprintf (buf, "%s/%s", pos, binary); 220 sprintf (buf, "%s/%s", pos, binary);
221 if (GNUNET_DISK_file_test (buf) == GNUNET_YES) 221 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
222 {
223 pos = GNUNET_strdup (pos);
224 GNUNET_free (buf);
225 GNUNET_free (path);
226 return pos;
227 }
228 pos = end + 1;
229 }
230 sprintf (buf, "%s/%s", pos, binary);
231 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
232 { 222 {
233 pos = GNUNET_strdup (pos); 223 pos = GNUNET_strdup (pos);
234 GNUNET_free (buf); 224 GNUNET_free (buf);
235 GNUNET_free (path); 225 GNUNET_free (path);
236 return pos; 226 return pos;
237 } 227 }
228 pos = end + 1;
229 }
230 sprintf (buf, "%s/%s", pos, binary);
231 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
232 {
233 pos = GNUNET_strdup (pos);
234 GNUNET_free (buf);
235 GNUNET_free (path);
236 return pos;
237 }
238 GNUNET_free (buf); 238 GNUNET_free (buf);
239 GNUNET_free (path); 239 GNUNET_free (path);
240 return NULL; 240 return NULL;
@@ -359,11 +359,11 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
359 359
360 n = strlen (execpath); 360 n = strlen (execpath);
361 if (n == 0) 361 if (n == 0)
362 { 362 {
363 /* should never happen, but better safe than sorry */ 363 /* should never happen, but better safe than sorry */
364 GNUNET_free (execpath); 364 GNUNET_free (execpath);
365 return NULL; 365 return NULL;
366 } 366 }
367 /* remove filename itself */ 367 /* remove filename itself */
368 while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR)) 368 while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR))
369 execpath[--n] = '\0'; 369 execpath[--n] = '\0';
@@ -372,62 +372,59 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
372 if ((n > 5) && 372 if ((n > 5) &&
373 ((0 == strcasecmp (&execpath[n - 5], "lib32")) || 373 ((0 == strcasecmp (&execpath[n - 5], "lib32")) ||
374 (0 == strcasecmp (&execpath[n - 5], "lib64")))) 374 (0 == strcasecmp (&execpath[n - 5], "lib64"))))
375 {
376 if (dirkind != GNUNET_OS_IPK_LIBDIR)
375 { 377 {
376 if (dirkind != GNUNET_OS_IPK_LIBDIR) 378 /* strip '/lib32' or '/lib64' */
377 { 379 execpath[n - 5] = '\0';
378 /* strip '/lib32' or '/lib64' */ 380 n -= 5;
379 execpath[n - 5] = '\0';
380 n -= 5;
381 }
382 else
383 isbasedir = 0;
384 } 381 }
382 else
383 isbasedir = 0;
384 }
385 else if ((n > 3) && 385 else if ((n > 3) &&
386 ((0 == strcasecmp (&execpath[n - 3], "bin")) || 386 ((0 == strcasecmp (&execpath[n - 3], "bin")) ||
387 (0 == strcasecmp (&execpath[n - 3], "lib")))) 387 (0 == strcasecmp (&execpath[n - 3], "lib"))))
388 { 388 {
389 /* strip '/bin' or '/lib' */ 389 /* strip '/bin' or '/lib' */
390 execpath[n - 3] = '\0'; 390 execpath[n - 3] = '\0';
391 n -= 3; 391 n -= 3;
392 } 392 }
393 /* in case this was a directory named foo-bin, remove "foo-" */ 393 /* in case this was a directory named foo-bin, remove "foo-" */
394 while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR)) 394 while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR))
395 execpath[--n] = '\0'; 395 execpath[--n] = '\0';
396 switch (dirkind) 396 switch (dirkind)
397 { 397 {
398 case GNUNET_OS_IPK_PREFIX: 398 case GNUNET_OS_IPK_PREFIX:
399 case GNUNET_OS_IPK_SELF_PREFIX: 399 case GNUNET_OS_IPK_SELF_PREFIX:
400 dirname = DIR_SEPARATOR_STR; 400 dirname = DIR_SEPARATOR_STR;
401 break; 401 break;
402 case GNUNET_OS_IPK_BINDIR: 402 case GNUNET_OS_IPK_BINDIR:
403 dirname = DIR_SEPARATOR_STR "bin" DIR_SEPARATOR_STR; 403 dirname = DIR_SEPARATOR_STR "bin" DIR_SEPARATOR_STR;
404 break; 404 break;
405 case GNUNET_OS_IPK_LIBDIR: 405 case GNUNET_OS_IPK_LIBDIR:
406 if (isbasedir) 406 if (isbasedir)
407 dirname =
408 DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR "gnunet"
409 DIR_SEPARATOR_STR;
410 else
411 dirname = DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR;
412 break;
413 case GNUNET_OS_IPK_DATADIR:
414 dirname =
415 DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "gnunet"
416 DIR_SEPARATOR_STR;
417 break;
418 case GNUNET_OS_IPK_LOCALEDIR:
419 dirname =
420 DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "locale"
421 DIR_SEPARATOR_STR;
422 break;
423 case GNUNET_OS_IPK_ICONDIR:
424 dirname = 407 dirname =
425 DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "icons" DIR_SEPARATOR_STR; 408 DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR;
426 break; 409 else
427 default: 410 dirname = DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR;
428 GNUNET_free (execpath); 411 break;
429 return NULL; 412 case GNUNET_OS_IPK_DATADIR:
430 } 413 dirname =
414 DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR;
415 break;
416 case GNUNET_OS_IPK_LOCALEDIR:
417 dirname =
418 DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "locale" DIR_SEPARATOR_STR;
419 break;
420 case GNUNET_OS_IPK_ICONDIR:
421 dirname =
422 DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "icons" DIR_SEPARATOR_STR;
423 break;
424 default:
425 GNUNET_free (execpath);
426 return NULL;
427 }
431 tmp = GNUNET_malloc (strlen (execpath) + strlen (dirname) + 1); 428 tmp = GNUNET_malloc (strlen (execpath) + strlen (dirname) + 1);
432 sprintf (tmp, "%s%s", execpath, dirname); 429 sprintf (tmp, "%s%s", execpath, dirname);
433 GNUNET_free (execpath); 430 GNUNET_free (execpath);
@@ -460,59 +457,58 @@ GNUNET_OS_check_helper_binary (const char *binary)
460 GNUNET_asprintf (&binaryexe, "%s.exe", binary); 457 GNUNET_asprintf (&binaryexe, "%s.exe", binary);
461 p = get_path_from_PATH (binaryexe); 458 p = get_path_from_PATH (binaryexe);
462 if (p != NULL) 459 if (p != NULL)
463 { 460 {
464 GNUNET_asprintf (&pf, "%s/%s", p, binaryexe); 461 GNUNET_asprintf (&pf, "%s/%s", p, binaryexe);
465 GNUNET_free (p); 462 GNUNET_free (p);
466 p = pf; 463 p = pf;
467 } 464 }
468 free (binaryexe); 465 free (binaryexe);
469#else 466#else
470 p = get_path_from_PATH (binary); 467 p = get_path_from_PATH (binary);
471 if (p != NULL) 468 if (p != NULL)
472 { 469 {
473 GNUNET_asprintf (&pf, "%s/%s", p, binary); 470 GNUNET_asprintf (&pf, "%s/%s", p, binary);
474 GNUNET_free (p); 471 GNUNET_free (p);
475 p = pf; 472 p = pf;
476 } 473 }
477#endif 474#endif
478 if (p == NULL) 475 if (p == NULL)
479 { 476 {
480 LOG (GNUNET_ERROR_TYPE_INFO, 477 LOG (GNUNET_ERROR_TYPE_INFO, _("Could not find binary `%s' in PATH!\n"),
481 _("Could not find binary `%s' in PATH!\n"), binary); 478 binary);
482 return GNUNET_SYSERR; 479 return GNUNET_SYSERR;
483 } 480 }
484 if (0 != STAT (p, &statbuf)) 481 if (0 != STAT (p, &statbuf))
485 { 482 {
486 LOG (GNUNET_ERROR_TYPE_WARNING, _("stat (%s) failed: %s\n"), p, 483 LOG (GNUNET_ERROR_TYPE_WARNING, _("stat (%s) failed: %s\n"), p,
487 STRERROR (errno)); 484 STRERROR (errno));
488 GNUNET_free (p); 485 GNUNET_free (p);
489 return GNUNET_SYSERR; 486 return GNUNET_SYSERR;
490 } 487 }
491#ifndef MINGW 488#ifndef MINGW
492 if ((0 != (statbuf.st_mode & S_ISUID)) && (statbuf.st_uid == 0)) 489 if ((0 != (statbuf.st_mode & S_ISUID)) && (statbuf.st_uid == 0))
493 { 490 {
494 GNUNET_free (p); 491 GNUNET_free (p);
495 return GNUNET_YES; 492 return GNUNET_YES;
496 } 493 }
497 if (0 == ACCESS (p, X_OK)) 494 if (0 == ACCESS (p, X_OK))
498 { 495 {
499 GNUNET_free (p); 496 GNUNET_free (p);
500 return GNUNET_NO; 497 return GNUNET_NO;
501 } 498 }
502 GNUNET_free (p); 499 GNUNET_free (p);
503 return GNUNET_SYSERR; 500 return GNUNET_SYSERR;
504#else 501#else
505 GNUNET_free (p); 502 GNUNET_free (p);
506 rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP); 503 rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP);
507 if (INVALID_SOCKET == rawsock) 504 if (INVALID_SOCKET == rawsock)
508 { 505 {
509 DWORD err = GetLastError (); 506 DWORD err = GetLastError ();
510 507
511 LOG (GNUNET_ERROR_TYPE_INFO, 508 LOG (GNUNET_ERROR_TYPE_INFO,
512 "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) failed! GLE = %d\n", 509 "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) failed! GLE = %d\n", err);
513 err); 510 return GNUNET_NO; /* not running as administrator */
514 return GNUNET_NO; /* not running as administrator */ 511 }
515 }
516 closesocket (rawsock); 512 closesocket (rawsock);
517 return GNUNET_YES; 513 return GNUNET_YES;
518#endif 514#endif
diff --git a/src/util/os_network.c b/src/util/os_network.c
index 2835e6193..70d143ba1 100644
--- a/src/util/os_network.c
+++ b/src/util/os_network.c
@@ -43,7 +43,7 @@
43 */ 43 */
44void 44void
45GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc, 45GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
46 void *proc_cls) 46 void *proc_cls)
47{ 47{
48#ifdef MINGW 48#ifdef MINGW
49 PMIB_IFTABLE pTable; 49 PMIB_IFTABLE pTable;
@@ -52,121 +52,118 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
52 IPAddr theIP; 52 IPAddr theIP;
53 53
54 /* Determine our external NIC */ 54 /* Determine our external NIC */
55 theIP = inet_addr ("192.0.34.166"); /* www.example.com */ 55 theIP = inet_addr ("192.0.34.166"); /* www.example.com */
56 if ((!GNGetBestInterface) || 56 if ((!GNGetBestInterface) ||
57 (GNGetBestInterface (theIP, &dwExternalNIC) != NO_ERROR)) 57 (GNGetBestInterface (theIP, &dwExternalNIC) != NO_ERROR))
58 { 58 {
59 dwExternalNIC = 0; 59 dwExternalNIC = 0;
60 } 60 }
61 61
62 /* Enumerate NICs */ 62 /* Enumerate NICs */
63 EnumNICs (&pTable, &pAddrTable); 63 EnumNICs (&pTable, &pAddrTable);
64 64
65 if (pTable) 65 if (pTable)
66 {
67 for (dwIfIdx = 0; dwIfIdx <= pTable->dwNumEntries; dwIfIdx++)
66 { 68 {
67 for (dwIfIdx = 0; dwIfIdx <= pTable->dwNumEntries; dwIfIdx++) 69 char szEntry[1001];
68 { 70 DWORD dwIP = 0;
69 char szEntry[1001]; 71 PIP_ADAPTER_INFO pAdapterInfo;
70 DWORD dwIP = 0; 72 PIP_ADAPTER_INFO pAdapter = NULL;
71 PIP_ADAPTER_INFO pAdapterInfo; 73 DWORD dwRetVal = 0;
72 PIP_ADAPTER_INFO pAdapter = NULL; 74
73 DWORD dwRetVal = 0; 75 /* Get IP-Address */
74 76 int i;
75 /* Get IP-Address */ 77
76 int i; 78 for (i = 0; i < pAddrTable->dwNumEntries; i++)
77 79 {
78 for (i = 0; i < pAddrTable->dwNumEntries; i++) 80 if (pAddrTable->table[i].dwIndex == pTable->table[dwIfIdx].dwIndex)
79 { 81 {
80 if (pAddrTable->table[i].dwIndex == 82 dwIP = pAddrTable->table[i].dwAddr;
81 pTable->table[dwIfIdx].dwIndex) 83 break;
82 { 84 }
83 dwIP = pAddrTable->table[i].dwAddr; 85 }
84 break; 86
85 } 87 if (dwIP)
86 } 88 {
87 89 BYTE bPhysAddr[MAXLEN_PHYSADDR];
88 if (dwIP) 90 char *pszIfName = NULL;
89 { 91 char dst[INET_ADDRSTRLEN];
90 BYTE bPhysAddr[MAXLEN_PHYSADDR]; 92 struct sockaddr_in sa;
91 char *pszIfName = NULL; 93
92 char dst[INET_ADDRSTRLEN]; 94 /* Get friendly interface name */
93 struct sockaddr_in sa; 95 pAdapterInfo = (IP_ADAPTER_INFO *) malloc (sizeof (IP_ADAPTER_INFO));
94 96 ULONG ulOutBufLen = sizeof (IP_ADAPTER_INFO);
95 /* Get friendly interface name */ 97
96 pAdapterInfo = 98 /* Make an initial call to GetAdaptersInfo to get
97 (IP_ADAPTER_INFO *) malloc (sizeof (IP_ADAPTER_INFO)); 99 * the necessary size into the ulOutBufLen variable */
98 ULONG ulOutBufLen = sizeof (IP_ADAPTER_INFO); 100 if (GGetAdaptersInfo (pAdapterInfo, &ulOutBufLen) ==
99 101 ERROR_BUFFER_OVERFLOW)
100 /* Make an initial call to GetAdaptersInfo to get 102 {
101 * the necessary size into the ulOutBufLen variable */ 103 free (pAdapterInfo);
102 if (GGetAdaptersInfo (pAdapterInfo, &ulOutBufLen) == 104 pAdapterInfo = (IP_ADAPTER_INFO *) malloc (ulOutBufLen);
103 ERROR_BUFFER_OVERFLOW) 105 }
104 { 106
105 free (pAdapterInfo); 107 if ((dwRetVal =
106 pAdapterInfo = (IP_ADAPTER_INFO *) malloc (ulOutBufLen); 108 GGetAdaptersInfo (pAdapterInfo, &ulOutBufLen)) == NO_ERROR)
107 } 109 {
108 110 pAdapter = pAdapterInfo;
109 if ((dwRetVal = 111 while (pAdapter)
110 GGetAdaptersInfo (pAdapterInfo, &ulOutBufLen)) == NO_ERROR) 112 {
111 { 113 if (pTable->table[dwIfIdx].dwIndex == pAdapter->Index)
112 pAdapter = pAdapterInfo; 114 {
113 while (pAdapter) 115 char szKey[251];
114 { 116 long lLen = 250;
115 if (pTable->table[dwIfIdx].dwIndex == pAdapter->Index) 117
116 { 118 sprintf (szKey,
117 char szKey[251]; 119 "SYSTEM\\CurrentControlSet\\Control\\Network\\"
118 long lLen = 250; 120 "{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection",
119 121 pAdapter->AdapterName);
120 sprintf (szKey, 122 pszIfName = (char *) malloc (251);
121 "SYSTEM\\CurrentControlSet\\Control\\Network\\" 123 if (QueryRegistry
122 "{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection", 124 (HKEY_LOCAL_MACHINE, szKey, "Name", pszIfName,
123 pAdapter->AdapterName); 125 &lLen) != ERROR_SUCCESS)
124 pszIfName = (char *) malloc (251); 126 {
125 if (QueryRegistry 127 free (pszIfName);
126 (HKEY_LOCAL_MACHINE, szKey, "Name", pszIfName, 128 pszIfName = NULL;
127 &lLen) != ERROR_SUCCESS) 129 }
128 { 130 }
129 free (pszIfName); 131 pAdapter = pAdapter->Next;
130 pszIfName = NULL; 132 }
131 } 133 }
132 } 134 free (pAdapterInfo);
133 pAdapter = pAdapter->Next; 135
134 } 136 /* Set entry */
135 } 137 memset (bPhysAddr, 0, MAXLEN_PHYSADDR);
136 free (pAdapterInfo); 138 memcpy (bPhysAddr, pTable->table[dwIfIdx].bPhysAddr,
137 139 pTable->table[dwIfIdx].dwPhysAddrLen);
138 /* Set entry */ 140
139 memset (bPhysAddr, 0, MAXLEN_PHYSADDR); 141 snprintf (szEntry, 1000, "%s (%s - %I64u)",
140 memcpy (bPhysAddr, pTable->table[dwIfIdx].bPhysAddr, 142 pszIfName ? pszIfName : (char *) pTable->
141 pTable->table[dwIfIdx].dwPhysAddrLen); 143 table[dwIfIdx].bDescr, inet_ntop (AF_INET, &dwIP, dst,
142 144 INET_ADDRSTRLEN),
143 snprintf (szEntry, 1000, "%s (%s - %I64u)", 145 *((unsigned long long *) bPhysAddr));
144 pszIfName ? pszIfName : (char *) 146 szEntry[1000] = 0;
145 pTable->table[dwIfIdx].bDescr, inet_ntop (AF_INET, 147
146 &dwIP, dst, 148 if (pszIfName)
147 INET_ADDRSTRLEN), 149 free (pszIfName);
148 *((unsigned long long *) bPhysAddr)); 150
149 szEntry[1000] = 0; 151 sa.sin_family = AF_INET;
150
151 if (pszIfName)
152 free (pszIfName);
153
154 sa.sin_family = AF_INET;
155#if HAVE_SOCKADDR_IN_SIN_LEN 152#if HAVE_SOCKADDR_IN_SIN_LEN
156 sa.sin_len = (u_char) sizeof (struct sockaddr_in); 153 sa.sin_len = (u_char) sizeof (struct sockaddr_in);
157#endif 154#endif
158 sa.sin_addr.S_un.S_addr = dwIP; 155 sa.sin_addr.S_un.S_addr = dwIP;
159 156
160 if (GNUNET_OK != 157 if (GNUNET_OK !=
161 proc (proc_cls, szEntry, 158 proc (proc_cls, szEntry,
162 pTable->table[dwIfIdx].dwIndex == dwExternalNIC, 159 pTable->table[dwIfIdx].dwIndex == dwExternalNIC,
163 (const struct sockaddr *) &sa, sizeof (sa))) 160 (const struct sockaddr *) &sa, sizeof (sa)))
164 break; 161 break;
165 } 162 }
166 }
167 GlobalFree (pAddrTable);
168 GlobalFree (pTable);
169 } 163 }
164 GlobalFree (pAddrTable);
165 GlobalFree (pTable);
166 }
170 167
171 return; 168 return;
172 169
@@ -177,29 +174,28 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
177 socklen_t alen; 174 socklen_t alen;
178 175
179 if (getifaddrs (&ifa_first) == 0) 176 if (getifaddrs (&ifa_first) == 0)
177 {
178 for (ifa_ptr = ifa_first; ifa_ptr != NULL; ifa_ptr = ifa_ptr->ifa_next)
180 { 179 {
181 for (ifa_ptr = ifa_first; ifa_ptr != NULL; ifa_ptr = ifa_ptr->ifa_next) 180 if (ifa_ptr->ifa_name != NULL && ifa_ptr->ifa_addr != NULL &&
182 { 181 (ifa_ptr->ifa_flags & IFF_UP) != 0)
183 if (ifa_ptr->ifa_name != NULL && ifa_ptr->ifa_addr != NULL && 182 {
184 (ifa_ptr->ifa_flags & IFF_UP) != 0) 183 if ((ifa_ptr->ifa_addr->sa_family != AF_INET) &&
185 { 184 (ifa_ptr->ifa_addr->sa_family != AF_INET6))
186 if ((ifa_ptr->ifa_addr->sa_family != AF_INET) && 185 continue;
187 (ifa_ptr->ifa_addr->sa_family != AF_INET6)) 186 if (ifa_ptr->ifa_addr->sa_family == AF_INET)
188 continue; 187 alen = sizeof (struct sockaddr_in);
189 if (ifa_ptr->ifa_addr->sa_family == AF_INET) 188 else
190 alen = sizeof (struct sockaddr_in); 189 alen = sizeof (struct sockaddr_in6);
191 else 190 if (GNUNET_OK !=
192 alen = sizeof (struct sockaddr_in6); 191 proc (proc_cls, ifa_ptr->ifa_name,
193 if (GNUNET_OK != 192 0 == strcmp (ifa_ptr->ifa_name, GNUNET_DEFAULT_INTERFACE),
194 proc (proc_cls, ifa_ptr->ifa_name, 193 ifa_ptr->ifa_addr, alen))
195 0 == strcmp (ifa_ptr->ifa_name, 194 break;
196 GNUNET_DEFAULT_INTERFACE), 195 }
197 ifa_ptr->ifa_addr, alen))
198 break;
199 }
200 }
201 freeifaddrs (ifa_first);
202 } 196 }
197 freeifaddrs (ifa_first);
198 }
203#else 199#else
204 char line[1024]; 200 char line[1024];
205 const char *start; 201 const char *start;
@@ -220,76 +216,73 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
220 else 216 else
221 f = popen ("ifconfig -a 2> /dev/null", "r"); 217 f = popen ("ifconfig -a 2> /dev/null", "r");
222 if (!f) 218 if (!f)
223 { 219 {
224 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING | 220 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
225 GNUNET_ERROR_TYPE_BULK, "popen", "ifconfig"); 221 "popen", "ifconfig");
226 return; 222 return;
227 } 223 }
228 224
229 have_ifc = GNUNET_NO; 225 have_ifc = GNUNET_NO;
230 ifc[11] = '\0'; 226 ifc[11] = '\0';
231 while (NULL != fgets (line, sizeof (line), f)) 227 while (NULL != fgets (line, sizeof (line), f))
228 {
229 if (strlen (line) == 0)
230 {
231 have_ifc = GNUNET_NO;
232 continue;
233 }
234 if (!isspace (line[0]))
235 {
236 have_ifc = (1 == SSCANF (line, "%11s", ifc)) ? GNUNET_YES : GNUNET_NO;
237 /* would end with ':' on OSX, fix it! */
238 if (ifc[strlen (ifc) - 1] == ':')
239 ifc[strlen (ifc) - 1] = '\0';
240 continue;
241 }
242 if (!have_ifc)
243 continue; /* strange input, hope for the best */
244 start = line;
245 while (('\0' != *start) && (isspace (*start)))
246 start++;
247 if ( /* Linux */
248 (1 == SSCANF (start, "inet addr:%127s", addrstr)) ||
249 (1 == SSCANF (start, "inet6 addr:%127s", addrstr)) ||
250 /* Solaris, OS X */
251 (1 == SSCANF (start, "inet %127s", addrstr)) ||
252 (1 == SSCANF (start, "inet6 %127s", addrstr)))
232 { 253 {
233 if (strlen (line) == 0) 254 /* IPv4 */
234 { 255 if (1 == inet_pton (AF_INET, addrstr, &v4))
235 have_ifc = GNUNET_NO; 256 {
236 continue; 257 memset (&a4, 0, sizeof (a4));
237 } 258 a4.sin_family = AF_INET;
238 if (!isspace (line[0]))
239 {
240 have_ifc =
241 (1 == SSCANF (line, "%11s", ifc)) ? GNUNET_YES : GNUNET_NO;
242 /* would end with ':' on OSX, fix it! */
243 if (ifc[strlen (ifc) - 1] == ':')
244 ifc[strlen (ifc) - 1] = '\0';
245 continue;
246 }
247 if (!have_ifc)
248 continue; /* strange input, hope for the best */
249 start = line;
250 while (('\0' != *start) && (isspace (*start)))
251 start++;
252 if ( /* Linux */
253 (1 == SSCANF (start, "inet addr:%127s", addrstr)) ||
254 (1 == SSCANF (start, "inet6 addr:%127s", addrstr)) ||
255 /* Solaris, OS X */
256 (1 == SSCANF (start, "inet %127s", addrstr)) ||
257 (1 == SSCANF (start, "inet6 %127s", addrstr)))
258 {
259 /* IPv4 */
260 if (1 == inet_pton (AF_INET, addrstr, &v4))
261 {
262 memset (&a4, 0, sizeof (a4));
263 a4.sin_family = AF_INET;
264#if HAVE_SOCKADDR_IN_SIN_LEN 259#if HAVE_SOCKADDR_IN_SIN_LEN
265 a4.sin_len = (u_char) sizeof (struct sockaddr_in); 260 a4.sin_len = (u_char) sizeof (struct sockaddr_in);
266#endif 261#endif
267 a4.sin_addr = v4; 262 a4.sin_addr = v4;
268 if (GNUNET_OK != 263 if (GNUNET_OK !=
269 proc (proc_cls, ifc, 264 proc (proc_cls, ifc, 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE),
270 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE), 265 (const struct sockaddr *) &a4, sizeof (a4)))
271 (const struct sockaddr *) &a4, sizeof (a4))) 266 break;
272 break; 267 continue;
273 continue; 268 }
274 } 269 /* IPv6 */
275 /* IPv6 */ 270 if (1 == inet_pton (AF_INET6, addrstr, &v6))
276 if (1 == inet_pton (AF_INET6, addrstr, &v6)) 271 {
277 { 272 memset (&a6, 0, sizeof (a6));
278 memset (&a6, 0, sizeof (a6)); 273 a6.sin6_family = AF_INET6;
279 a6.sin6_family = AF_INET6;
280#if HAVE_SOCKADDR_IN_SIN_LEN 274#if HAVE_SOCKADDR_IN_SIN_LEN
281 a6.sin6_len = (u_char) sizeof (struct sockaddr_in6); 275 a6.sin6_len = (u_char) sizeof (struct sockaddr_in6);
282#endif 276#endif
283 a6.sin6_addr = v6; 277 a6.sin6_addr = v6;
284 if (GNUNET_OK != 278 if (GNUNET_OK !=
285 proc (proc_cls, ifc, 279 proc (proc_cls, ifc, 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE),
286 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE), 280 (const struct sockaddr *) &a6, sizeof (a6)))
287 (const struct sockaddr *) &a6, sizeof (a6))) 281 break;
288 break; 282 continue;
289 continue; 283 }
290 }
291 }
292 } 284 }
285 }
293 pclose (f); 286 pclose (f);
294#endif 287#endif
295} 288}
diff --git a/src/util/os_priority.c b/src/util/os_priority.c
index 4f21e7edb..a7ce0c5e5 100644
--- a/src/util/os_priority.c
+++ b/src/util/os_priority.c
@@ -59,43 +59,41 @@ static struct GNUNET_OS_Process current_process;
59 */ 59 */
60static void 60static void
61parent_control_handler (void *cls, 61parent_control_handler (void *cls,
62 const struct GNUNET_SCHEDULER_TaskContext *tc) 62 const struct GNUNET_SCHEDULER_TaskContext *tc)
63{ 63{
64 struct GNUNET_DISK_FileHandle *control_pipe = 64 struct GNUNET_DISK_FileHandle *control_pipe =
65 (struct GNUNET_DISK_FileHandle *) cls; 65 (struct GNUNET_DISK_FileHandle *) cls;
66 int sig; 66 int sig;
67 67
68#if DEBUG_OS 68#if DEBUG_OS
69 LOG (GNUNET_ERROR_TYPE_DEBUG, "`%s' invoked because of %d\n", 69 LOG (GNUNET_ERROR_TYPE_DEBUG, "`%s' invoked because of %d\n", __FUNCTION__,
70 __FUNCTION__, tc->reason); 70 tc->reason);
71#endif 71#endif
72 if (tc->reason & 72 if (tc->reason &
73 (GNUNET_SCHEDULER_REASON_SHUTDOWN | GNUNET_SCHEDULER_REASON_TIMEOUT | 73 (GNUNET_SCHEDULER_REASON_SHUTDOWN | GNUNET_SCHEDULER_REASON_TIMEOUT |
74 GNUNET_SCHEDULER_REASON_PREREQ_DONE)) 74 GNUNET_SCHEDULER_REASON_PREREQ_DONE))
75 {
76 GNUNET_DISK_npipe_close (control_pipe);
77 }
78 else
79 {
80 if (GNUNET_DISK_file_read (control_pipe, &sig, sizeof (sig)) !=
81 sizeof (sig))
75 { 82 {
83 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DISK_file_read");
76 GNUNET_DISK_npipe_close (control_pipe); 84 GNUNET_DISK_npipe_close (control_pipe);
77 } 85 }
78 else 86 else
79 { 87 {
80 if (GNUNET_DISK_file_read (control_pipe, &sig, sizeof (sig)) !=
81 sizeof (sig))
82 {
83 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DISK_file_read");
84 GNUNET_DISK_npipe_close (control_pipe);
85 }
86 else
87 {
88#if DEBUG_OS 88#if DEBUG_OS
89 LOG (GNUNET_ERROR_TYPE_DEBUG, "Got control code %d from parent\n", 89 LOG (GNUNET_ERROR_TYPE_DEBUG, "Got control code %d from parent\n", sig);
90 sig);
91#endif 90#endif
92 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 91 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
93 control_pipe, 92 control_pipe, &parent_control_handler,
94 &parent_control_handler, 93 control_pipe);
95 control_pipe); 94 raise (sig);
96 raise (sig);
97 }
98 } 95 }
96 }
99} 97}
100 98
101 99
@@ -104,35 +102,34 @@ parent_control_handler (void *cls,
104 */ 102 */
105void 103void
106GNUNET_OS_install_parent_control_handler (void *cls, 104GNUNET_OS_install_parent_control_handler (void *cls,
107 const struct 105 const struct
108 GNUNET_SCHEDULER_TaskContext *tc) 106 GNUNET_SCHEDULER_TaskContext *tc)
109{ 107{
110 const char *env_buf; 108 const char *env_buf;
111 struct GNUNET_DISK_FileHandle *control_pipe; 109 struct GNUNET_DISK_FileHandle *control_pipe;
112 110
113 env_buf = getenv (GNUNET_OS_CONTROL_PIPE); 111 env_buf = getenv (GNUNET_OS_CONTROL_PIPE);
114 if ((env_buf == NULL) || (strlen (env_buf) <= 0)) 112 if ((env_buf == NULL) || (strlen (env_buf) <= 0))
115 { 113 {
116 LOG (GNUNET_ERROR_TYPE_INFO, 114 LOG (GNUNET_ERROR_TYPE_INFO, _("Not installing a handler because $%s=%s\n"),
117 _("Not installing a handler because $%s=%s\n"), 115 GNUNET_OS_CONTROL_PIPE, env_buf);
118 GNUNET_OS_CONTROL_PIPE, env_buf); 116 return;
119 return; 117 }
120 }
121 control_pipe = 118 control_pipe =
122 GNUNET_DISK_npipe_open (env_buf, GNUNET_DISK_OPEN_READ, 119 GNUNET_DISK_npipe_open (env_buf, GNUNET_DISK_OPEN_READ,
123 GNUNET_DISK_PERM_USER_READ | 120 GNUNET_DISK_PERM_USER_READ |
124 GNUNET_DISK_PERM_USER_WRITE); 121 GNUNET_DISK_PERM_USER_WRITE);
125 if (control_pipe == NULL) 122 if (control_pipe == NULL)
126 { 123 {
127 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", env_buf); 124 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", env_buf);
128 return; 125 return;
129 } 126 }
130#if DEBUG_OS 127#if DEBUG_OS
131 LOG (GNUNET_ERROR_TYPE_DEBUG, 128 LOG (GNUNET_ERROR_TYPE_DEBUG,
132 "Adding parent control handler pipe `%s' to the scheduler\n", env_buf); 129 "Adding parent control handler pipe `%s' to the scheduler\n", env_buf);
133#endif 130#endif
134 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, control_pipe, 131 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, control_pipe,
135 &parent_control_handler, control_pipe); 132 &parent_control_handler, control_pipe);
136} 133}
137 134
138 135
@@ -166,90 +163,90 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig)
166 163
167 ret = GNUNET_DISK_file_write (proc->control_pipe, &sig, sizeof (sig)); 164 ret = GNUNET_DISK_file_write (proc->control_pipe, &sig, sizeof (sig));
168 if (ret != sizeof (sig)) 165 if (ret != sizeof (sig))
166 {
167 if (errno == ECOMM)
169 { 168 {
170 if (errno == ECOMM) 169 /* Child process is not controllable via pipe */
171 {
172 /* Child process is not controllable via pipe */
173#if DEBUG_OS 170#if DEBUG_OS
174 LOG (GNUNET_ERROR_TYPE_DEBUG, 171 LOG (GNUNET_ERROR_TYPE_DEBUG,
175 "Child process is not controllable, will kill it directly\n"); 172 "Child process is not controllable, will kill it directly\n");
176#endif 173#endif
177 } 174 }
178 else if (errno == EPIPE) 175 else if (errno == EPIPE)
179 { 176 {
180#if DEBUG_OS 177#if DEBUG_OS
181 LOG (GNUNET_ERROR_TYPE_DEBUG, 178 LOG (GNUNET_ERROR_TYPE_DEBUG,
182 "Failed to write into control pipe, because pipe is invalid (the child is most likely dead)\n"); 179 "Failed to write into control pipe, because pipe is invalid (the child is most likely dead)\n");
183#endif 180#endif
184 } 181 }
185 else 182 else
186 LOG (GNUNET_ERROR_TYPE_WARNING, 183 LOG (GNUNET_ERROR_TYPE_WARNING,
187 "Failed to write into control pipe , errno is %d\n", errno); 184 "Failed to write into control pipe , errno is %d\n", errno);
188#if WINDOWS && !defined(__CYGWIN__) 185#if WINDOWS && !defined(__CYGWIN__)
189 TerminateProcess (proc->handle, 0); 186 TerminateProcess (proc->handle, 0);
190#else 187#else
191 PLIBC_KILL (proc->pid, sig); 188 PLIBC_KILL (proc->pid, sig);
192#endif 189#endif
193 } 190 }
194 else 191 else
195 { 192 {
196#if DEBUG_OS 193#if DEBUG_OS
197 LOG (GNUNET_ERROR_TYPE_DEBUG, 194 LOG (GNUNET_ERROR_TYPE_DEBUG,
198 "Wrote control code into control pipe, now waiting\n"); 195 "Wrote control code into control pipe, now waiting\n");
199#endif 196#endif
200 197
201#if WINDOWS 198#if WINDOWS
202 /* Give it 3 seconds to die, then kill it in a nice Windows-specific way */ 199 /* Give it 3 seconds to die, then kill it in a nice Windows-specific way */
203 if (WaitForSingleObject (proc->handle, 3000) != WAIT_OBJECT_0) 200 if (WaitForSingleObject (proc->handle, 3000) != WAIT_OBJECT_0)
204 TerminateProcess (proc->handle, 0); 201 TerminateProcess (proc->handle, 0);
205 res = 0; 202 res = 0;
206#else 203#else
207 struct GNUNET_NETWORK_FDSet *rfds; 204 struct GNUNET_NETWORK_FDSet *rfds;
208 struct GNUNET_NETWORK_FDSet *efds; 205 struct GNUNET_NETWORK_FDSet *efds;
209 206
210 rfds = GNUNET_NETWORK_fdset_create (); 207 rfds = GNUNET_NETWORK_fdset_create ();
211 efds = GNUNET_NETWORK_fdset_create (); 208 efds = GNUNET_NETWORK_fdset_create ();
212 209
213 GNUNET_NETWORK_fdset_handle_set (rfds, proc->control_pipe); 210 GNUNET_NETWORK_fdset_handle_set (rfds, proc->control_pipe);
214 GNUNET_NETWORK_fdset_handle_set (efds, proc->control_pipe); 211 GNUNET_NETWORK_fdset_handle_set (efds, proc->control_pipe);
215 212
216 /* Ndurner thought this up, and i have no idea what it does. 213 /* Ndurner thought this up, and i have no idea what it does.
217 * There's have never been any code to answer the shutdown call 214 * There's have never been any code to answer the shutdown call
218 * (write a single int into the pipe, so that this function can read it). 215 * (write a single int into the pipe, so that this function can read it).
219 * On *nix select() will probably tell that pipe is ready 216 * On *nix select() will probably tell that pipe is ready
220 * for reading, once the other process shuts down, 217 * for reading, once the other process shuts down,
221 * but the read () call will fail, triggering a kill () 218 * but the read () call will fail, triggering a kill ()
222 * on the pid that is already dead. This will probably result in non-0 219 * on the pid that is already dead. This will probably result in non-0
223 * return from kill(), and therefore from this function. 220 * return from kill(), and therefore from this function.
224 */ 221 */
225 while (1) 222 while (1)
226 { 223 {
227 ret = 224 ret =
228 GNUNET_NETWORK_socket_select (rfds, NULL, efds, 225 GNUNET_NETWORK_socket_select (rfds, NULL, efds,
229 GNUNET_TIME_relative_multiply 226 GNUNET_TIME_relative_multiply
230 (GNUNET_TIME_relative_get_unit (), 227 (GNUNET_TIME_relative_get_unit (),
231 5000)); 228 5000));
232 229
233 if (ret < 1 || 230 if (ret < 1 ||
234 GNUNET_NETWORK_fdset_handle_isset (efds, proc->control_pipe)) 231 GNUNET_NETWORK_fdset_handle_isset (efds, proc->control_pipe))
235 { 232 {
236 /* Just to be sure */ 233 /* Just to be sure */
237 PLIBC_KILL (proc->pid, sig); 234 PLIBC_KILL (proc->pid, sig);
238 res = 0; 235 res = 0;
239 break; 236 break;
240 } 237 }
241 else 238 else
242 { 239 {
243 if (GNUNET_DISK_file_read 240 if (GNUNET_DISK_file_read (proc->control_pipe, &ret, sizeof (ret)) !=
244 (proc->control_pipe, &ret, sizeof (ret)) != GNUNET_OK) 241 GNUNET_OK)
245 res = PLIBC_KILL (proc->pid, sig); 242 res = PLIBC_KILL (proc->pid, sig);
246 243
247 /* Child signaled shutdown is in progress */ 244 /* Child signaled shutdown is in progress */
248 continue; 245 continue;
249 } 246 }
250 }
251#endif
252 } 247 }
248#endif
249 }
253 250
254 return res; 251 return res;
255#else 252#else
@@ -324,7 +321,7 @@ ChildWaitThread (void *arg)
324 */ 321 */
325int 322int
326GNUNET_OS_set_process_priority (struct GNUNET_OS_Process *proc, 323GNUNET_OS_set_process_priority (struct GNUNET_OS_Process *proc,
327 enum GNUNET_SCHEDULER_Priority prio) 324 enum GNUNET_SCHEDULER_Priority prio)
328{ 325{
329 int rprio; 326 int rprio;
330 327
@@ -334,51 +331,51 @@ GNUNET_OS_set_process_priority (struct GNUNET_OS_Process *proc,
334 331
335 /* convert to MINGW/Unix values */ 332 /* convert to MINGW/Unix values */
336 switch (prio) 333 switch (prio)
337 { 334 {
338 case GNUNET_SCHEDULER_PRIORITY_UI: 335 case GNUNET_SCHEDULER_PRIORITY_UI:
339 case GNUNET_SCHEDULER_PRIORITY_URGENT: 336 case GNUNET_SCHEDULER_PRIORITY_URGENT:
340#ifdef MINGW 337#ifdef MINGW
341 rprio = HIGH_PRIORITY_CLASS; 338 rprio = HIGH_PRIORITY_CLASS;
342#else 339#else
343 rprio = 0; 340 rprio = 0;
344#endif 341#endif
345 break; 342 break;
346 343
347 case GNUNET_SCHEDULER_PRIORITY_HIGH: 344 case GNUNET_SCHEDULER_PRIORITY_HIGH:
348#ifdef MINGW 345#ifdef MINGW
349 rprio = ABOVE_NORMAL_PRIORITY_CLASS; 346 rprio = ABOVE_NORMAL_PRIORITY_CLASS;
350#else 347#else
351 rprio = 5; 348 rprio = 5;
352#endif 349#endif
353 break; 350 break;
354 351
355 case GNUNET_SCHEDULER_PRIORITY_DEFAULT: 352 case GNUNET_SCHEDULER_PRIORITY_DEFAULT:
356#ifdef MINGW 353#ifdef MINGW
357 rprio = NORMAL_PRIORITY_CLASS; 354 rprio = NORMAL_PRIORITY_CLASS;
358#else 355#else
359 rprio = 7; 356 rprio = 7;
360#endif 357#endif
361 break; 358 break;
362 359
363 case GNUNET_SCHEDULER_PRIORITY_BACKGROUND: 360 case GNUNET_SCHEDULER_PRIORITY_BACKGROUND:
364#ifdef MINGW 361#ifdef MINGW
365 rprio = BELOW_NORMAL_PRIORITY_CLASS; 362 rprio = BELOW_NORMAL_PRIORITY_CLASS;
366#else 363#else
367 rprio = 10; 364 rprio = 10;
368#endif 365#endif
369 break; 366 break;
370 367
371 case GNUNET_SCHEDULER_PRIORITY_IDLE: 368 case GNUNET_SCHEDULER_PRIORITY_IDLE:
372#ifdef MINGW 369#ifdef MINGW
373 rprio = IDLE_PRIORITY_CLASS; 370 rprio = IDLE_PRIORITY_CLASS;
374#else 371#else
375 rprio = 19; 372 rprio = 19;
376#endif 373#endif
377 break; 374 break;
378 default: 375 default:
379 GNUNET_assert (0); 376 GNUNET_assert (0);
380 return GNUNET_SYSERR; 377 return GNUNET_SYSERR;
381 } 378 }
382 379
383 /* Set process priority */ 380 /* Set process priority */
384#ifdef MINGW 381#ifdef MINGW
@@ -393,27 +390,26 @@ GNUNET_OS_set_process_priority (struct GNUNET_OS_Process *proc,
393 390
394 pid = proc->pid; 391 pid = proc->pid;
395 if ((0 == pid) || (pid == getpid ())) 392 if ((0 == pid) || (pid == getpid ()))
393 {
394 int have = nice (0);
395 int delta = rprio - have;
396
397 errno = 0;
398 if ((delta != 0) && (rprio == nice (delta)) && (errno != 0))
396 { 399 {
397 int have = nice (0); 400 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "nice");
398 int delta = rprio - have; 401 return GNUNET_SYSERR;
399
400 errno = 0;
401 if ((delta != 0) && (rprio == nice (delta)) && (errno != 0))
402 {
403 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
404 "nice");
405 return GNUNET_SYSERR;
406 }
407 } 402 }
403 }
408 else 404 else
405 {
406 if (0 != setpriority (PRIO_PROCESS, pid, rprio))
409 { 407 {
410 if (0 != setpriority (PRIO_PROCESS, pid, rprio)) 408 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
411 { 409 "setpriority");
412 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, 410 return GNUNET_SYSERR;
413 "setpriority");
414 return GNUNET_SYSERR;
415 }
416 } 411 }
412 }
417#else 413#else
418#if DEBUG_OS 414#if DEBUG_OS
419 LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 415 LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
@@ -440,84 +436,84 @@ CreateCustomEnvTable (char **vars)
440 win32_env_table = GetEnvironmentStringsA (); 436 win32_env_table = GetEnvironmentStringsA ();
441 if (win32_env_table == NULL) 437 if (win32_env_table == NULL)
442 return NULL; 438 return NULL;
443 for (c = 0, var_ptr = vars; *var_ptr; var_ptr += 2, c++); 439 for (c = 0, var_ptr = vars; *var_ptr; var_ptr += 2, c++) ;
444 n_var = c; 440 n_var = c;
445 index = GNUNET_malloc (sizeof (char *) * n_var); 441 index = GNUNET_malloc (sizeof (char *) * n_var);
446 for (c = 0; c < n_var; c++) 442 for (c = 0; c < n_var; c++)
447 index[c] = 0; 443 index[c] = 0;
448 for (items_count = 0, ptr = win32_env_table; ptr[0] != 0; items_count++) 444 for (items_count = 0, ptr = win32_env_table; ptr[0] != 0; items_count++)
445 {
446 size_t len = strlen (ptr);
447 int found = 0;
448
449 for (var_ptr = vars; *var_ptr; var_ptr++)
449 { 450 {
450 size_t len = strlen (ptr); 451 var = *var_ptr++;
451 int found = 0; 452 val = *var_ptr;
452 453 var_len = strlen (var);
453 for (var_ptr = vars; *var_ptr; var_ptr++) 454 if (strncmp (var, ptr, var_len) == 0)
454 { 455 {
455 var = *var_ptr++; 456 found = 1;
456 val = *var_ptr; 457 index[c] = 1;
457 var_len = strlen (var); 458 tablesize += var_len + strlen (val) + 1;
458 if (strncmp (var, ptr, var_len) == 0) 459 break;
459 { 460 }
460 found = 1;
461 index[c] = 1;
462 tablesize += var_len + strlen (val) + 1;
463 break;
464 }
465 }
466 if (!found)
467 tablesize += len + 1;
468 ptr += len + 1;
469 } 461 }
462 if (!found)
463 tablesize += len + 1;
464 ptr += len + 1;
465 }
470 for (n_found = 0, c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++) 466 for (n_found = 0, c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++)
467 {
468 var = *var_ptr++;
469 val = *var_ptr;
470 if (index[c] != 1)
471 n_found += strlen (var) + strlen (val) + 1;
472 }
473 result = GNUNET_malloc (tablesize + n_found + 1);
474 for (result_ptr = result, ptr = win32_env_table; ptr[0] != 0;)
475 {
476 size_t len = strlen (ptr);
477 int found = 0;
478
479 for (c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++)
471 { 480 {
472 var = *var_ptr++; 481 var = *var_ptr++;
473 val = *var_ptr; 482 val = *var_ptr;
474 if (index[c] != 1) 483 var_len = strlen (var);
475 n_found += strlen (var) + strlen (val) + 1; 484 if (strncmp (var, ptr, var_len) == 0)
485 {
486 found = 1;
487 break;
488 }
476 } 489 }
477 result = GNUNET_malloc (tablesize + n_found + 1); 490 if (!found)
478 for (result_ptr = result, ptr = win32_env_table; ptr[0] != 0;)
479 { 491 {
480 size_t len = strlen (ptr); 492 strcpy (result_ptr, ptr);
481 int found = 0; 493 result_ptr += len + 1;
482 494 }
483 for (c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++) 495 else
484 { 496 {
485 var = *var_ptr++; 497 strcpy (result_ptr, var);
486 val = *var_ptr; 498 result_ptr += var_len;
487 var_len = strlen (var); 499 strcpy (result_ptr, val);
488 if (strncmp (var, ptr, var_len) == 0) 500 result_ptr += strlen (val) + 1;
489 {
490 found = 1;
491 break;
492 }
493 }
494 if (!found)
495 {
496 strcpy (result_ptr, ptr);
497 result_ptr += len + 1;
498 }
499 else
500 {
501 strcpy (result_ptr, var);
502 result_ptr += var_len;
503 strcpy (result_ptr, val);
504 result_ptr += strlen (val) + 1;
505 }
506 ptr += len + 1;
507 } 501 }
502 ptr += len + 1;
503 }
508 for (c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++) 504 for (c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++)
505 {
506 var = *var_ptr++;
507 val = *var_ptr;
508 var_len = strlen (var);
509 if (index[c] != 1)
509 { 510 {
510 var = *var_ptr++; 511 strcpy (result_ptr, var);
511 val = *var_ptr; 512 result_ptr += var_len;
512 var_len = strlen (var); 513 strcpy (result_ptr, val);
513 if (index[c] != 1) 514 result_ptr += strlen (val) + 1;
514 {
515 strcpy (result_ptr, var);
516 result_ptr += var_len;
517 strcpy (result_ptr, val);
518 result_ptr += strlen (val) + 1;
519 }
520 } 515 }
516 }
521 FreeEnvironmentStrings (win32_env_table); 517 FreeEnvironmentStrings (win32_env_table);
522 GNUNET_free (index); 518 GNUNET_free (index);
523 *result_ptr = 0; 519 *result_ptr = 0;
@@ -537,8 +533,8 @@ CreateCustomEnvTable (char **vars)
537 */ 533 */
538struct GNUNET_OS_Process * 534struct GNUNET_OS_Process *
539GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, 535GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin,
540 struct GNUNET_DISK_PipeHandle *pipe_stdout, 536 struct GNUNET_DISK_PipeHandle *pipe_stdout,
541 const char *filename, va_list va) 537 const char *filename, va_list va)
542{ 538{
543 va_list ap; 539 va_list ap;
544 540
@@ -559,9 +555,9 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin,
559 555
560#if ENABLE_WINDOWS_WORKAROUNDS 556#if ENABLE_WINDOWS_WORKAROUNDS
561 control_pipe = 557 control_pipe =
562 GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE, 558 GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE,
563 GNUNET_DISK_PERM_USER_READ | 559 GNUNET_DISK_PERM_USER_READ |
564 GNUNET_DISK_PERM_USER_WRITE); 560 GNUNET_DISK_PERM_USER_WRITE);
565 if (control_pipe == NULL) 561 if (control_pipe == NULL)
566 return NULL; 562 return NULL;
567#endif 563#endif
@@ -569,38 +565,35 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin,
569 argc = 0; 565 argc = 0;
570 va_copy (ap, va); 566 va_copy (ap, va);
571 while (NULL != va_arg (ap, char *)) 567 while (NULL != va_arg (ap, char *))
572 argc++; 568 argc++;
573 569
574 va_end (ap); 570 va_end (ap);
575 argv = GNUNET_malloc (sizeof (char *) * (argc + 1)); 571 argv = GNUNET_malloc (sizeof (char *) * (argc + 1));
576 argc = 0; 572 argc = 0;
577 va_copy (ap, va); 573 va_copy (ap, va);
578 while (NULL != (argv[argc] = va_arg (ap, char *))) 574 while (NULL != (argv[argc] = va_arg (ap, char *)))
579 argc++; 575 argc++;
580 576
581 va_end (ap); 577 va_end (ap);
582 if (pipe_stdout != NULL) 578 if (pipe_stdout != NULL)
583 { 579 {
584 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle 580 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
585 (pipe_stdout, 581 (pipe_stdout,
586 GNUNET_DISK_PIPE_END_WRITE), 582 GNUNET_DISK_PIPE_END_WRITE),
587 &fd_stdout_write, sizeof (int)); 583 &fd_stdout_write, sizeof (int));
588 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle 584 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
589 (pipe_stdout, 585 (pipe_stdout, GNUNET_DISK_PIPE_END_READ),
590 GNUNET_DISK_PIPE_END_READ), 586 &fd_stdout_read, sizeof (int));
591 &fd_stdout_read, sizeof (int)); 587 }
592 }
593 if (pipe_stdin != NULL) 588 if (pipe_stdin != NULL)
594 { 589 {
595 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle 590 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
596 (pipe_stdin, 591 (pipe_stdin, GNUNET_DISK_PIPE_END_READ),
597 GNUNET_DISK_PIPE_END_READ), 592 &fd_stdin_read, sizeof (int));
598 &fd_stdin_read, sizeof (int)); 593 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
599 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle 594 (pipe_stdin, GNUNET_DISK_PIPE_END_WRITE),
600 (pipe_stdin, 595 &fd_stdin_write, sizeof (int));
601 GNUNET_DISK_PIPE_END_WRITE), 596 }
602 &fd_stdin_write, sizeof (int));
603 }
604 597
605#if HAVE_WORKING_VFORK 598#if HAVE_WORKING_VFORK
606 ret = vfork (); 599 ret = vfork ();
@@ -608,46 +601,44 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin,
608 ret = fork (); 601 ret = fork ();
609#endif 602#endif
610 if (ret != 0) 603 if (ret != 0)
604 {
605 if (ret == -1)
611 { 606 {
612 if (ret == -1) 607 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork");
613 {
614 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork");
615#if ENABLE_WINDOWS_WORKAROUNDS 608#if ENABLE_WINDOWS_WORKAROUNDS
616 GNUNET_DISK_npipe_close (control_pipe); 609 GNUNET_DISK_npipe_close (control_pipe);
617#endif 610#endif
618 } 611 }
619 else 612 else
620 { 613 {
621 614
622#if HAVE_WORKING_VFORK 615#if HAVE_WORKING_VFORK
623 /* let's hope vfork actually works; for some extreme cases (including 616 /* let's hope vfork actually works; for some extreme cases (including
624 * a testcase) we need 'execvp' to have run before we return, since 617 * a testcase) we need 'execvp' to have run before we return, since
625 * we may send a signal to the process next and we don't want it 618 * we may send a signal to the process next and we don't want it
626 * to be caught by OUR signal handler (but either by the default 619 * to be caught by OUR signal handler (but either by the default
627 * handler or the actual handler as installed by the process itself). */ 620 * handler or the actual handler as installed by the process itself). */
628#else 621#else
629 /* let's give the child process a chance to run execvp, 1s should 622 /* let's give the child process a chance to run execvp, 1s should
630 * be plenty in practice */ 623 * be plenty in practice */
631 if (pipe_stdout != NULL) 624 if (pipe_stdout != NULL)
632 GNUNET_DISK_pipe_close_end (pipe_stdout, 625 GNUNET_DISK_pipe_close_end (pipe_stdout, GNUNET_DISK_PIPE_END_WRITE);
633 GNUNET_DISK_PIPE_END_WRITE); 626 if (pipe_stdin != NULL)
634 if (pipe_stdin != NULL) 627 GNUNET_DISK_pipe_close_end (pipe_stdin, GNUNET_DISK_PIPE_END_READ);
635 GNUNET_DISK_pipe_close_end (pipe_stdin, 628 sleep (1);
636 GNUNET_DISK_PIPE_END_READ);
637 sleep (1);
638#endif 629#endif
639 gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process)); 630 gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process));
640 gnunet_proc->pid = ret; 631 gnunet_proc->pid = ret;
641#if ENABLE_WINDOWS_WORKAROUNDS 632#if ENABLE_WINDOWS_WORKAROUNDS
642 gnunet_proc->control_pipe = control_pipe; 633 gnunet_proc->control_pipe = control_pipe;
643#endif 634#endif
644 } 635 }
645 GNUNET_free (argv); 636 GNUNET_free (argv);
646#if ENABLE_WINDOWS_WORKAROUNDS 637#if ENABLE_WINDOWS_WORKAROUNDS
647 GNUNET_free (childpipename); 638 GNUNET_free (childpipename);
648#endif 639#endif
649 return gnunet_proc; 640 return gnunet_proc;
650 } 641 }
651 642
652#if ENABLE_WINDOWS_WORKAROUNDS 643#if ENABLE_WINDOWS_WORKAROUNDS
653 setenv (GNUNET_OS_CONTROL_PIPE, childpipename, 1); 644 setenv (GNUNET_OS_CONTROL_PIPE, childpipename, 1);
@@ -655,21 +646,21 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin,
655#endif 646#endif
656 647
657 if (pipe_stdout != NULL) 648 if (pipe_stdout != NULL)
658 { 649 {
659 GNUNET_break (0 == close (fd_stdout_read)); 650 GNUNET_break (0 == close (fd_stdout_read));
660 if (-1 == dup2 (fd_stdout_write, 1)) 651 if (-1 == dup2 (fd_stdout_write, 1))
661 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2"); 652 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
662 GNUNET_break (0 == close (fd_stdout_write)); 653 GNUNET_break (0 == close (fd_stdout_write));
663 } 654 }
664 655
665 if (pipe_stdin != NULL) 656 if (pipe_stdin != NULL)
666 { 657 {
667 658
668 GNUNET_break (0 == close (fd_stdin_write)); 659 GNUNET_break (0 == close (fd_stdin_write));
669 if (-1 == dup2 (fd_stdin_read, 0)) 660 if (-1 == dup2 (fd_stdin_read, 0))
670 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2"); 661 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
671 GNUNET_break (0 == close (fd_stdin_read)); 662 GNUNET_break (0 == close (fd_stdin_read));
672 } 663 }
673 execvp (filename, argv); 664 execvp (filename, argv);
674 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "execvp", filename); 665 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "execvp", filename);
675 _exit (1); 666 _exit (1);
@@ -705,8 +696,8 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin,
705 pathbuf_len = GetEnvironmentVariableA ("PATH", (char *) &pathbuf, 0); 696 pathbuf_len = GetEnvironmentVariableA ("PATH", (char *) &pathbuf, 0);
706 697
707 alloc_len = 698 alloc_len =
708 pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 + 699 pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 +
709 strlen (libdir); 700 strlen (libdir);
710 701
711 pathbuf = GNUNET_malloc (alloc_len * sizeof (char)); 702 pathbuf = GNUNET_malloc (alloc_len * sizeof (char));
712 703
@@ -729,39 +720,39 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin,
729 if (non_const_filename[1] == ':') 720 if (non_const_filename[1] == ':')
730 snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename); 721 snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename);
731 else if (!SearchPathA 722 else if (!SearchPathA
732 (pathbuf, non_const_filename, NULL, sizeof (path) / sizeof (char), 723 (pathbuf, non_const_filename, NULL, sizeof (path) / sizeof (char),
733 path, NULL)) 724 path, NULL))
734 { 725 {
735 SetErrnoFromWinError (GetLastError ()); 726 SetErrnoFromWinError (GetLastError ());
736 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "SearchPath", 727 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "SearchPath",
737 non_const_filename); 728 non_const_filename);
738 GNUNET_free (non_const_filename); 729 GNUNET_free (non_const_filename);
739 GNUNET_free (pathbuf); 730 GNUNET_free (pathbuf);
740 return NULL; 731 return NULL;
741 } 732 }
742 GNUNET_free (pathbuf); 733 GNUNET_free (pathbuf);
743 GNUNET_free (non_const_filename); 734 GNUNET_free (non_const_filename);
744 735
745 cmdlen = 0; 736 cmdlen = 0;
746 va_copy (ap, va); 737 va_copy (ap, va);
747 while (NULL != (arg = va_arg (ap, char *))) 738 while (NULL != (arg = va_arg (ap, char *)))
748 { 739 {
749 if (cmdlen == 0) 740 if (cmdlen == 0)
750 cmdlen = cmdlen + strlen (path) + 3; 741 cmdlen = cmdlen + strlen (path) + 3;
751 else 742 else
752 cmdlen = cmdlen + strlen (arg) + 3; 743 cmdlen = cmdlen + strlen (arg) + 3;
753 } 744 }
754 va_end (ap); 745 va_end (ap);
755 746
756 cmd = idx = GNUNET_malloc (sizeof (char) * (cmdlen + 1)); 747 cmd = idx = GNUNET_malloc (sizeof (char) * (cmdlen + 1));
757 va_copy (ap, va); 748 va_copy (ap, va);
758 while (NULL != (arg = va_arg (ap, char *))) 749 while (NULL != (arg = va_arg (ap, char *)))
759 { 750 {
760 if (idx == cmd) 751 if (idx == cmd)
761 idx += sprintf (idx, "\"%s\" ", path); 752 idx += sprintf (idx, "\"%s\" ", path);
762 else 753 else
763 idx += sprintf (idx, "\"%s\" ", arg); 754 idx += sprintf (idx, "\"%s\" ", arg);
764 } 755 }
765 va_end (ap); 756 va_end (ap);
766 757
767 memset (&start, 0, sizeof (start)); 758 memset (&start, 0, sizeof (start));
@@ -771,37 +762,36 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin,
771 start.dwFlags |= STARTF_USESTDHANDLES; 762 start.dwFlags |= STARTF_USESTDHANDLES;
772 763
773 if (pipe_stdin != NULL) 764 if (pipe_stdin != NULL)
774 { 765 {
775 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle 766 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
776 (pipe_stdin, 767 (pipe_stdin, GNUNET_DISK_PIPE_END_READ),
777 GNUNET_DISK_PIPE_END_READ), 768 &stdin_handle, sizeof (HANDLE));
778 &stdin_handle, sizeof (HANDLE)); 769 start.hStdInput = stdin_handle;
779 start.hStdInput = stdin_handle; 770 }
780 }
781 771
782 if (pipe_stdout != NULL) 772 if (pipe_stdout != NULL)
783 { 773 {
784 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle 774 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
785 (pipe_stdout, 775 (pipe_stdout,
786 GNUNET_DISK_PIPE_END_WRITE), 776 GNUNET_DISK_PIPE_END_WRITE),
787 &stdout_handle, sizeof (HANDLE)); 777 &stdout_handle, sizeof (HANDLE));
788 start.hStdOutput = stdout_handle; 778 start.hStdOutput = stdout_handle;
789 } 779 }
790 780
791 control_pipe = 781 control_pipe =
792 GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE, 782 GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE,
793 GNUNET_DISK_PERM_USER_READ | 783 GNUNET_DISK_PERM_USER_READ |
794 GNUNET_DISK_PERM_USER_WRITE); 784 GNUNET_DISK_PERM_USER_WRITE);
795 if (control_pipe == NULL) 785 if (control_pipe == NULL)
796 { 786 {
797 GNUNET_free (cmd); 787 GNUNET_free (cmd);
798 GNUNET_free (path); 788 GNUNET_free (path);
799 return NULL; 789 return NULL;
800 } 790 }
801 791
802#if DEBUG_OS 792#if DEBUG_OS
803 LOG (GNUNET_ERROR_TYPE_DEBUG, 793 LOG (GNUNET_ERROR_TYPE_DEBUG, "Opened the parent end of the pipe `%s'\n",
804 "Opened the parent end of the pipe `%s'\n", childpipename); 794 childpipename);
805#endif 795#endif
806 796
807 GNUNET_asprintf (&our_env[0], "%s=", GNUNET_OS_CONTROL_PIPE); 797 GNUNET_asprintf (&our_env[0], "%s=", GNUNET_OS_CONTROL_PIPE);
@@ -814,13 +804,13 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin,
814 if (!CreateProcessA 804 if (!CreateProcessA
815 (path, cmd, NULL, NULL, TRUE, DETACHED_PROCESS | CREATE_SUSPENDED, 805 (path, cmd, NULL, NULL, TRUE, DETACHED_PROCESS | CREATE_SUSPENDED,
816 env_block, NULL, &start, &proc)) 806 env_block, NULL, &start, &proc))
817 { 807 {
818 SetErrnoFromWinError (GetLastError ()); 808 SetErrnoFromWinError (GetLastError ());
819 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "CreateProcess", path); 809 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "CreateProcess", path);
820 GNUNET_free (env_block); 810 GNUNET_free (env_block);
821 GNUNET_free (cmd); 811 GNUNET_free (cmd);
822 return NULL; 812 return NULL;
823 } 813 }
824 814
825 GNUNET_free (env_block); 815 GNUNET_free (env_block);
826 816
@@ -854,8 +844,8 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin,
854 */ 844 */
855struct GNUNET_OS_Process * 845struct GNUNET_OS_Process *
856GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, 846GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin,
857 struct GNUNET_DISK_PipeHandle *pipe_stdout, 847 struct GNUNET_DISK_PipeHandle *pipe_stdout,
858 const char *filename, ...) 848 const char *filename, ...)
859{ 849{
860 struct GNUNET_OS_Process *ret; 850 struct GNUNET_OS_Process *ret;
861 va_list ap; 851 va_list ap;
@@ -878,7 +868,7 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin,
878 */ 868 */
879struct GNUNET_OS_Process * 869struct GNUNET_OS_Process *
880GNUNET_OS_start_process_v (const int *lsocks, const char *filename, 870GNUNET_OS_start_process_v (const int *lsocks, const char *filename,
881 char *const argv[]) 871 char *const argv[])
882{ 872{
883#if ENABLE_WINDOWS_WORKAROUNDS 873#if ENABLE_WINDOWS_WORKAROUNDS
884 struct GNUNET_DISK_FileHandle *control_pipe = NULL; 874 struct GNUNET_DISK_FileHandle *control_pipe = NULL;
@@ -900,9 +890,9 @@ GNUNET_OS_start_process_v (const int *lsocks, const char *filename,
900 890
901#if ENABLE_WINDOWS_WORKAROUNDS 891#if ENABLE_WINDOWS_WORKAROUNDS
902 control_pipe = 892 control_pipe =
903 GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE, 893 GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE,
904 GNUNET_DISK_PERM_USER_READ | 894 GNUNET_DISK_PERM_USER_READ |
905 GNUNET_DISK_PERM_USER_WRITE); 895 GNUNET_DISK_PERM_USER_WRITE);
906 if (control_pipe == NULL) 896 if (control_pipe == NULL)
907 return NULL; 897 return NULL;
908#endif 898#endif
@@ -910,52 +900,52 @@ GNUNET_OS_start_process_v (const int *lsocks, const char *filename,
910 lscp = NULL; 900 lscp = NULL;
911 ls = 0; 901 ls = 0;
912 if (lsocks != NULL) 902 if (lsocks != NULL)
913 { 903 {
914 i = 0; 904 i = 0;
915 while (-1 != (k = lsocks[i++])) 905 while (-1 != (k = lsocks[i++]))
916 GNUNET_array_append (lscp, ls, k); 906 GNUNET_array_append (lscp, ls, k);
917 GNUNET_array_append (lscp, ls, -1); 907 GNUNET_array_append (lscp, ls, -1);
918 } 908 }
919#if HAVE_WORKING_VFORK 909#if HAVE_WORKING_VFORK
920 ret = vfork (); 910 ret = vfork ();
921#else 911#else
922 ret = fork (); 912 ret = fork ();
923#endif 913#endif
924 if (ret != 0) 914 if (ret != 0)
915 {
916 if (ret == -1)
925 { 917 {
926 if (ret == -1) 918 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork");
927 {
928 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork");
929#if ENABLE_WINDOWS_WORKAROUNDS 919#if ENABLE_WINDOWS_WORKAROUNDS
930 GNUNET_DISK_npipe_close (control_pipe); 920 GNUNET_DISK_npipe_close (control_pipe);
931#endif 921#endif
932 } 922 }
933 else 923 else
934 { 924 {
935#if HAVE_WORKING_VFORK 925#if HAVE_WORKING_VFORK
936 /* let's hope vfork actually works; for some extreme cases (including 926 /* let's hope vfork actually works; for some extreme cases (including
937 * a testcase) we need 'execvp' to have run before we return, since 927 * a testcase) we need 'execvp' to have run before we return, since
938 * we may send a signal to the process next and we don't want it 928 * we may send a signal to the process next and we don't want it
939 * to be caught by OUR signal handler (but either by the default 929 * to be caught by OUR signal handler (but either by the default
940 * handler or the actual handler as installed by the process itself). */ 930 * handler or the actual handler as installed by the process itself). */
941#else 931#else
942 /* let's give the child process a chance to run execvp, 1s should 932 /* let's give the child process a chance to run execvp, 1s should
943 * be plenty in practice */ 933 * be plenty in practice */
944 sleep (1); 934 sleep (1);
945#endif 935#endif
946 gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process)); 936 gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process));
947 gnunet_proc->pid = ret; 937 gnunet_proc->pid = ret;
948#if ENABLE_WINDOWS_WORKAROUNDS 938#if ENABLE_WINDOWS_WORKAROUNDS
949 gnunet_proc->control_pipe = control_pipe; 939 gnunet_proc->control_pipe = control_pipe;
950 940
951#endif 941#endif
952 } 942 }
953 GNUNET_array_grow (lscp, ls, 0); 943 GNUNET_array_grow (lscp, ls, 0);
954#if ENABLE_WINDOWS_WORKAROUNDS 944#if ENABLE_WINDOWS_WORKAROUNDS
955 GNUNET_free (childpipename); 945 GNUNET_free (childpipename);
956#endif 946#endif
957 return gnunet_proc; 947 return gnunet_proc;
958 } 948 }
959 949
960#if ENABLE_WINDOWS_WORKAROUNDS 950#if ENABLE_WINDOWS_WORKAROUNDS
961 setenv (GNUNET_OS_CONTROL_PIPE, childpipename, 1); 951 setenv (GNUNET_OS_CONTROL_PIPE, childpipename, 1);
@@ -963,47 +953,47 @@ GNUNET_OS_start_process_v (const int *lsocks, const char *filename,
963#endif 953#endif
964 954
965 if (lscp != NULL) 955 if (lscp != NULL)
956 {
957 /* read systemd documentation... */
958 GNUNET_snprintf (lpid, sizeof (lpid), "%u", getpid ());
959 setenv ("LISTEN_PID", lpid, 1);
960 i = 0;
961 tgt = 3;
962 while (-1 != lscp[i])
966 { 963 {
967 /* read systemd documentation... */ 964 j = i + 1;
968 GNUNET_snprintf (lpid, sizeof (lpid), "%u", getpid ()); 965 while (-1 != lscp[j])
969 setenv ("LISTEN_PID", lpid, 1); 966 {
970 i = 0; 967 if (lscp[j] == tgt)
971 tgt = 3; 968 {
972 while (-1 != lscp[i]) 969 /* dup away */
973 { 970 k = dup (lscp[j]);
974 j = i + 1; 971 GNUNET_assert (-1 != k);
975 while (-1 != lscp[j]) 972 GNUNET_assert (0 == close (lscp[j]));
976 { 973 lscp[j] = k;
977 if (lscp[j] == tgt) 974 break;
978 { 975 }
979 /* dup away */ 976 j++;
980 k = dup (lscp[j]); 977 }
981 GNUNET_assert (-1 != k); 978 if (lscp[i] != tgt)
982 GNUNET_assert (0 == close (lscp[j])); 979 {
983 lscp[j] = k; 980 /* Bury any existing FD, no matter what; they should all be closed
984 break; 981 * on exec anyway and the important onces have been dup'ed away */
985 } 982 (void) close (tgt);
986 j++; 983 GNUNET_assert (-1 != dup2 (lscp[i], tgt));
987 } 984 }
988 if (lscp[i] != tgt) 985 /* unset close-on-exec flag */
989 { 986 flags = fcntl (tgt, F_GETFD);
990 /* Bury any existing FD, no matter what; they should all be closed 987 GNUNET_assert (flags >= 0);
991 * on exec anyway and the important onces have been dup'ed away */ 988 flags &= ~FD_CLOEXEC;
992 (void) close (tgt); 989 fflush (stderr);
993 GNUNET_assert (-1 != dup2 (lscp[i], tgt)); 990 (void) fcntl (tgt, F_SETFD, flags);
994 } 991 tgt++;
995 /* unset close-on-exec flag */ 992 i++;
996 flags = fcntl (tgt, F_GETFD);
997 GNUNET_assert (flags >= 0);
998 flags &= ~FD_CLOEXEC;
999 fflush (stderr);
1000 (void) fcntl (tgt, F_SETFD, flags);
1001 tgt++;
1002 i++;
1003 }
1004 GNUNET_snprintf (fds, sizeof (fds), "%u", i);
1005 setenv ("LISTEN_FDS", fds, 1);
1006 } 993 }
994 GNUNET_snprintf (fds, sizeof (fds), "%u", i);
995 setenv ("LISTEN_FDS", fds, 1);
996 }
1007 GNUNET_array_grow (lscp, ls, 0); 997 GNUNET_array_grow (lscp, ls, 0);
1008 execvp (filename, argv); 998 execvp (filename, argv);
1009 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "execvp", filename); 999 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "execvp", filename);
@@ -1041,8 +1031,8 @@ GNUNET_OS_start_process_v (const int *lsocks, const char *filename,
1041 pathbuf_len = GetEnvironmentVariableA ("PATH", (char *) &pathbuf, 0); 1031 pathbuf_len = GetEnvironmentVariableA ("PATH", (char *) &pathbuf, 0);
1042 1032
1043 alloc_len = 1033 alloc_len =
1044 pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 + 1034 pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 +
1045 strlen (libdir); 1035 strlen (libdir);
1046 1036
1047 pathbuf = GNUNET_malloc (alloc_len * sizeof (char)); 1037 pathbuf = GNUNET_malloc (alloc_len * sizeof (char));
1048 1038
@@ -1054,11 +1044,11 @@ GNUNET_OS_start_process_v (const int *lsocks, const char *filename,
1054 1044
1055 alloc_len = GetEnvironmentVariableA ("PATH", ptr, pathbuf_len); 1045 alloc_len = GetEnvironmentVariableA ("PATH", ptr, pathbuf_len);
1056 if (alloc_len != pathbuf_len - 1) 1046 if (alloc_len != pathbuf_len - 1)
1057 { 1047 {
1058 GNUNET_free (pathbuf); 1048 GNUNET_free (pathbuf);
1059 errno = ENOSYS; /* PATH changed on the fly. What kind of error is that? */ 1049 errno = ENOSYS; /* PATH changed on the fly. What kind of error is that? */
1060 return NULL; 1050 return NULL;
1061 } 1051 }
1062 1052
1063 cmdlen = strlen (filename); 1053 cmdlen = strlen (filename);
1064 if (cmdlen < 5 || strcmp (&filename[cmdlen - 4], ".exe") != 0) 1054 if (cmdlen < 5 || strcmp (&filename[cmdlen - 4], ".exe") != 0)
@@ -1070,26 +1060,26 @@ GNUNET_OS_start_process_v (const int *lsocks, const char *filename,
1070 if (non_const_filename[1] == ':') 1060 if (non_const_filename[1] == ':')
1071 snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename); 1061 snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename);
1072 else if (!SearchPathA 1062 else if (!SearchPathA
1073 (pathbuf, non_const_filename, NULL, sizeof (path) / sizeof (char), 1063 (pathbuf, non_const_filename, NULL, sizeof (path) / sizeof (char),
1074 path, NULL)) 1064 path, NULL))
1075 { 1065 {
1076 SetErrnoFromWinError (GetLastError ()); 1066 SetErrnoFromWinError (GetLastError ());
1077 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "SearchPath", 1067 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "SearchPath",
1078 non_const_filename); 1068 non_const_filename);
1079 GNUNET_free (non_const_filename); 1069 GNUNET_free (non_const_filename);
1080 GNUNET_free (pathbuf); 1070 GNUNET_free (pathbuf);
1081 return NULL; 1071 return NULL;
1082 } 1072 }
1083 GNUNET_free (pathbuf); 1073 GNUNET_free (pathbuf);
1084 GNUNET_free (non_const_filename); 1074 GNUNET_free (non_const_filename);
1085 1075
1086 /* Count the number of arguments */ 1076 /* Count the number of arguments */
1087 arg = (char **) argv; 1077 arg = (char **) argv;
1088 while (*arg) 1078 while (*arg)
1089 { 1079 {
1090 arg++; 1080 arg++;
1091 argcount++; 1081 argcount++;
1092 } 1082 }
1093 1083
1094 /* Allocate a copy argv */ 1084 /* Allocate a copy argv */
1095 non_const_argv = GNUNET_malloc (sizeof (char *) * (argcount + 1)); 1085 non_const_argv = GNUNET_malloc (sizeof (char *) * (argcount + 1));
@@ -1098,33 +1088,33 @@ GNUNET_OS_start_process_v (const int *lsocks, const char *filename,
1098 argcount = 0; 1088 argcount = 0;
1099 arg = (char **) argv; 1089 arg = (char **) argv;
1100 while (*arg) 1090 while (*arg)
1101 { 1091 {
1102 if (arg == argv) 1092 if (arg == argv)
1103 non_const_argv[argcount] = GNUNET_strdup (path); 1093 non_const_argv[argcount] = GNUNET_strdup (path);
1104 else 1094 else
1105 non_const_argv[argcount] = GNUNET_strdup (*arg); 1095 non_const_argv[argcount] = GNUNET_strdup (*arg);
1106 arg++; 1096 arg++;
1107 argcount++; 1097 argcount++;
1108 } 1098 }
1109 non_const_argv[argcount] = NULL; 1099 non_const_argv[argcount] = NULL;
1110 1100
1111 /* Count cmd len */ 1101 /* Count cmd len */
1112 cmdlen = 1; 1102 cmdlen = 1;
1113 arg = non_const_argv; 1103 arg = non_const_argv;
1114 while (*arg) 1104 while (*arg)
1115 { 1105 {
1116 cmdlen = cmdlen + strlen (*arg) + 3; 1106 cmdlen = cmdlen + strlen (*arg) + 3;
1117 arg++; 1107 arg++;
1118 } 1108 }
1119 1109
1120 /* Allocate and create cmd */ 1110 /* Allocate and create cmd */
1121 cmd = idx = GNUNET_malloc (sizeof (char) * cmdlen); 1111 cmd = idx = GNUNET_malloc (sizeof (char) * cmdlen);
1122 arg = non_const_argv; 1112 arg = non_const_argv;
1123 while (*arg) 1113 while (*arg)
1124 { 1114 {
1125 idx += sprintf (idx, "\"%s\" ", *arg); 1115 idx += sprintf (idx, "\"%s\" ", *arg);
1126 arg++; 1116 arg++;
1127 } 1117 }
1128 1118
1129 while (argcount > 0) 1119 while (argcount > 0)
1130 GNUNET_free (non_const_argv[--argcount]); 1120 GNUNET_free (non_const_argv[--argcount]);
@@ -1134,19 +1124,19 @@ GNUNET_OS_start_process_v (const int *lsocks, const char *filename,
1134 start.cb = sizeof (start); 1124 start.cb = sizeof (start);
1135 1125
1136 control_pipe = 1126 control_pipe =
1137 GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE, 1127 GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE,
1138 GNUNET_DISK_PERM_USER_READ | 1128 GNUNET_DISK_PERM_USER_READ |
1139 GNUNET_DISK_PERM_USER_WRITE); 1129 GNUNET_DISK_PERM_USER_WRITE);
1140 if (control_pipe == NULL) 1130 if (control_pipe == NULL)
1141 { 1131 {
1142 GNUNET_free (cmd); 1132 GNUNET_free (cmd);
1143 GNUNET_free (path); 1133 GNUNET_free (path);
1144 return NULL; 1134 return NULL;
1145 } 1135 }
1146 1136
1147#if DEBUG_OS 1137#if DEBUG_OS
1148 LOG (GNUNET_ERROR_TYPE_DEBUG, 1138 LOG (GNUNET_ERROR_TYPE_DEBUG, "Opened the parent end of the pipe `%s'\n",
1149 "Opened the parent end of the pipe `%s'\n", childpipename); 1139 childpipename);
1150#endif 1140#endif
1151 1141
1152 GNUNET_asprintf (&our_env[0], "%s=", GNUNET_OS_CONTROL_PIPE); 1142 GNUNET_asprintf (&our_env[0], "%s=", GNUNET_OS_CONTROL_PIPE);
@@ -1159,13 +1149,13 @@ GNUNET_OS_start_process_v (const int *lsocks, const char *filename,
1159 if (!CreateProcess 1149 if (!CreateProcess
1160 (path, cmd, NULL, NULL, FALSE, DETACHED_PROCESS | CREATE_SUSPENDED, 1150 (path, cmd, NULL, NULL, FALSE, DETACHED_PROCESS | CREATE_SUSPENDED,
1161 env_block, NULL, &start, &proc)) 1151 env_block, NULL, &start, &proc))
1162 { 1152 {
1163 SetErrnoFromWinError (GetLastError ()); 1153 SetErrnoFromWinError (GetLastError ());
1164 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "CreateProcess"); 1154 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "CreateProcess");
1165 GNUNET_free (env_block); 1155 GNUNET_free (env_block);
1166 GNUNET_free (cmd); 1156 GNUNET_free (cmd);
1167 return NULL; 1157 return NULL;
1168 } 1158 }
1169 1159
1170 GNUNET_free (env_block); 1160 GNUNET_free (env_block);
1171 1161
@@ -1194,8 +1184,8 @@ GNUNET_OS_start_process_v (const int *lsocks, const char *filename,
1194 */ 1184 */
1195int 1185int
1196GNUNET_OS_process_status (struct GNUNET_OS_Process *proc, 1186GNUNET_OS_process_status (struct GNUNET_OS_Process *proc,
1197 enum GNUNET_OS_ProcessStatusType *type, 1187 enum GNUNET_OS_ProcessStatusType *type,
1198 unsigned long *code) 1188 unsigned long *code)
1199{ 1189{
1200#ifndef MINGW 1190#ifndef MINGW
1201 int status; 1191 int status;
@@ -1204,48 +1194,48 @@ GNUNET_OS_process_status (struct GNUNET_OS_Process *proc,
1204 GNUNET_assert (0 != proc); 1194 GNUNET_assert (0 != proc);
1205 ret = waitpid (proc->pid, &status, WNOHANG); 1195 ret = waitpid (proc->pid, &status, WNOHANG);
1206 if (ret < 0) 1196 if (ret < 0)
1207 { 1197 {
1208 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 1198 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid");
1209 return GNUNET_SYSERR; 1199 return GNUNET_SYSERR;
1210 } 1200 }
1211 if (0 == ret) 1201 if (0 == ret)
1212 { 1202 {
1213 *type = GNUNET_OS_PROCESS_RUNNING; 1203 *type = GNUNET_OS_PROCESS_RUNNING;
1214 *code = 0; 1204 *code = 0;
1215 return GNUNET_NO; 1205 return GNUNET_NO;
1216 } 1206 }
1217 if (proc->pid != ret) 1207 if (proc->pid != ret)
1218 { 1208 {
1219 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 1209 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid");
1220 return GNUNET_SYSERR; 1210 return GNUNET_SYSERR;
1221 } 1211 }
1222 if (WIFEXITED (status)) 1212 if (WIFEXITED (status))
1223 { 1213 {
1224 *type = GNUNET_OS_PROCESS_EXITED; 1214 *type = GNUNET_OS_PROCESS_EXITED;
1225 *code = WEXITSTATUS (status); 1215 *code = WEXITSTATUS (status);
1226 } 1216 }
1227 else if (WIFSIGNALED (status)) 1217 else if (WIFSIGNALED (status))
1228 { 1218 {
1229 *type = GNUNET_OS_PROCESS_SIGNALED; 1219 *type = GNUNET_OS_PROCESS_SIGNALED;
1230 *code = WTERMSIG (status); 1220 *code = WTERMSIG (status);
1231 } 1221 }
1232 else if (WIFSTOPPED (status)) 1222 else if (WIFSTOPPED (status))
1233 { 1223 {
1234 *type = GNUNET_OS_PROCESS_SIGNALED; 1224 *type = GNUNET_OS_PROCESS_SIGNALED;
1235 *code = WSTOPSIG (status); 1225 *code = WSTOPSIG (status);
1236 } 1226 }
1237#ifdef WIFCONTINUED 1227#ifdef WIFCONTINUED
1238 else if (WIFCONTINUED (status)) 1228 else if (WIFCONTINUED (status))
1239 { 1229 {
1240 *type = GNUNET_OS_PROCESS_RUNNING; 1230 *type = GNUNET_OS_PROCESS_RUNNING;
1241 *code = 0; 1231 *code = 0;
1242 } 1232 }
1243#endif 1233#endif
1244 else 1234 else
1245 { 1235 {
1246 *type = GNUNET_OS_PROCESS_UNKNOWN; 1236 *type = GNUNET_OS_PROCESS_UNKNOWN;
1247 *code = 0; 1237 *code = 0;
1248 } 1238 }
1249#else 1239#else
1250 HANDLE h; 1240 HANDLE h;
1251 DWORD c, error_code, ret; 1241 DWORD c, error_code, ret;
@@ -1253,11 +1243,11 @@ GNUNET_OS_process_status (struct GNUNET_OS_Process *proc,
1253 h = proc->handle; 1243 h = proc->handle;
1254 ret = proc->pid; 1244 ret = proc->pid;
1255 if (h == NULL || ret == 0) 1245 if (h == NULL || ret == 0)
1256 { 1246 {
1257 LOG (GNUNET_ERROR_TYPE_WARNING, 1247 LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid process information {%d, %08X}\n",
1258 "Invalid process information {%d, %08X}\n", ret, h); 1248 ret, h);
1259 return GNUNET_SYSERR; 1249 return GNUNET_SYSERR;
1260 } 1250 }
1261 if (h == NULL) 1251 if (h == NULL)
1262 h = GetCurrentProcess (); 1252 h = GetCurrentProcess ();
1263 1253
@@ -1265,17 +1255,17 @@ GNUNET_OS_process_status (struct GNUNET_OS_Process *proc,
1265 ret = GetExitCodeProcess (h, &c); 1255 ret = GetExitCodeProcess (h, &c);
1266 error_code = GetLastError (); 1256 error_code = GetLastError ();
1267 if (ret == 0 || error_code != NO_ERROR) 1257 if (ret == 0 || error_code != NO_ERROR)
1268 { 1258 {
1269 SetErrnoFromWinError (error_code); 1259 SetErrnoFromWinError (error_code);
1270 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "GetExitCodeProcess"); 1260 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "GetExitCodeProcess");
1271 return GNUNET_SYSERR; 1261 return GNUNET_SYSERR;
1272 } 1262 }
1273 if (STILL_ACTIVE == c) 1263 if (STILL_ACTIVE == c)
1274 { 1264 {
1275 *type = GNUNET_OS_PROCESS_RUNNING; 1265 *type = GNUNET_OS_PROCESS_RUNNING;
1276 *code = 0; 1266 *code = 0;
1277 return GNUNET_NO; 1267 return GNUNET_NO;
1278 } 1268 }
1279 *type = GNUNET_OS_PROCESS_EXITED; 1269 *type = GNUNET_OS_PROCESS_EXITED;
1280 *code = c; 1270 *code = c;
1281#endif 1271#endif
@@ -1305,19 +1295,19 @@ GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc)
1305 1295
1306 h = proc->handle; 1296 h = proc->handle;
1307 if (NULL == h) 1297 if (NULL == h)
1308 { 1298 {
1309 LOG (GNUNET_ERROR_TYPE_WARNING, 1299 LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid process information {%d, %08X}\n",
1310 "Invalid process information {%d, %08X}\n", proc->pid, h); 1300 proc->pid, h);
1311 return GNUNET_SYSERR; 1301 return GNUNET_SYSERR;
1312 } 1302 }
1313 if (h == NULL) 1303 if (h == NULL)
1314 h = GetCurrentProcess (); 1304 h = GetCurrentProcess ();
1315 1305
1316 if (WAIT_OBJECT_0 != WaitForSingleObject (h, INFINITE)) 1306 if (WAIT_OBJECT_0 != WaitForSingleObject (h, INFINITE))
1317 { 1307 {
1318 SetErrnoFromWinError (GetLastError ()); 1308 SetErrnoFromWinError (GetLastError ());
1319 ret = GNUNET_SYSERR; 1309 ret = GNUNET_SYSERR;
1320 } 1310 }
1321 else 1311 else
1322 ret = GNUNET_OK; 1312 ret = GNUNET_OK;
1323 1313
@@ -1391,10 +1381,10 @@ GNUNET_OS_command_stop (struct GNUNET_OS_CommandHandle *cmd)
1391{ 1381{
1392 1382
1393 if (cmd->proc != NULL) 1383 if (cmd->proc != NULL)
1394 { 1384 {
1395 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != cmd->rtask); 1385 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != cmd->rtask);
1396 GNUNET_SCHEDULER_cancel (cmd->rtask); 1386 GNUNET_SCHEDULER_cancel (cmd->rtask);
1397 } 1387 }
1398 (void) GNUNET_OS_process_kill (cmd->eip, SIGKILL); 1388 (void) GNUNET_OS_process_kill (cmd->eip, SIGKILL);
1399 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (cmd->eip)); 1389 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (cmd->eip));
1400 GNUNET_OS_process_close (cmd->eip); 1390 GNUNET_OS_process_close (cmd->eip);
@@ -1418,43 +1408,42 @@ cmd_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1418 ssize_t ret; 1408 ssize_t ret;
1419 1409
1420 cmd->rtask = GNUNET_SCHEDULER_NO_TASK; 1410 cmd->rtask = GNUNET_SCHEDULER_NO_TASK;
1421 if (GNUNET_YES != 1411 if (GNUNET_YES != GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, cmd->r))
1422 GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, cmd->r)) 1412 {
1423 { 1413 /* timeout, shutdown, etc. */
1424 /* timeout, shutdown, etc. */ 1414 proc = cmd->proc;
1425 proc = cmd->proc; 1415 cmd->proc = NULL;
1426 cmd->proc = NULL; 1416 proc (cmd->proc_cls, NULL);
1427 proc (cmd->proc_cls, NULL); 1417 return;
1428 return; 1418 }
1429 }
1430 ret = 1419 ret =
1431 GNUNET_DISK_file_read (cmd->r, &cmd->buf[cmd->off], 1420 GNUNET_DISK_file_read (cmd->r, &cmd->buf[cmd->off],
1432 sizeof (cmd->buf) - cmd->off); 1421 sizeof (cmd->buf) - cmd->off);
1433 if (ret <= 0) 1422 if (ret <= 0)
1423 {
1424 if ((cmd->off > 0) && (cmd->off < sizeof (cmd->buf)))
1434 { 1425 {
1435 if ((cmd->off > 0) && (cmd->off < sizeof (cmd->buf))) 1426 cmd->buf[cmd->off] = '\0';
1436 { 1427 cmd->proc (cmd->proc_cls, cmd->buf);
1437 cmd->buf[cmd->off] = '\0';
1438 cmd->proc (cmd->proc_cls, cmd->buf);
1439 }
1440 proc = cmd->proc;
1441 cmd->proc = NULL;
1442 proc (cmd->proc_cls, NULL);
1443 return;
1444 } 1428 }
1429 proc = cmd->proc;
1430 cmd->proc = NULL;
1431 proc (cmd->proc_cls, NULL);
1432 return;
1433 }
1445 end = memchr (&cmd->buf[cmd->off], '\n', ret); 1434 end = memchr (&cmd->buf[cmd->off], '\n', ret);
1446 cmd->off += ret; 1435 cmd->off += ret;
1447 while (end != NULL) 1436 while (end != NULL)
1448 { 1437 {
1449 *end = '\0'; 1438 *end = '\0';
1450 cmd->proc (cmd->proc_cls, cmd->buf); 1439 cmd->proc (cmd->proc_cls, cmd->buf);
1451 memmove (cmd->buf, end + 1, cmd->off - (end + 1 - cmd->buf)); 1440 memmove (cmd->buf, end + 1, cmd->off - (end + 1 - cmd->buf));
1452 cmd->off -= (end + 1 - cmd->buf); 1441 cmd->off -= (end + 1 - cmd->buf);
1453 end = memchr (cmd->buf, '\n', cmd->off); 1442 end = memchr (cmd->buf, '\n', cmd->off);
1454 } 1443 }
1455 cmd->rtask = 1444 cmd->rtask =
1456 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining 1445 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining
1457 (cmd->timeout), cmd->r, &cmd_read, cmd); 1446 (cmd->timeout), cmd->r, &cmd_read, cmd);
1458} 1447}
1459 1448
1460 1449
@@ -1471,8 +1460,8 @@ cmd_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1471 */ 1460 */
1472struct GNUNET_OS_CommandHandle * 1461struct GNUNET_OS_CommandHandle *
1473GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, void *proc_cls, 1462GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, void *proc_cls,
1474 struct GNUNET_TIME_Relative timeout, 1463 struct GNUNET_TIME_Relative timeout, const char *binary,
1475 const char *binary, ...) 1464 ...)
1476{ 1465{
1477 struct GNUNET_OS_CommandHandle *cmd; 1466 struct GNUNET_OS_CommandHandle *cmd;
1478 struct GNUNET_OS_Process *eip; 1467 struct GNUNET_OS_Process *eip;
@@ -1486,10 +1475,10 @@ GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, void *proc_cls,
1486 eip = GNUNET_OS_start_process_va (NULL, opipe, binary, ap); 1475 eip = GNUNET_OS_start_process_va (NULL, opipe, binary, ap);
1487 va_end (ap); 1476 va_end (ap);
1488 if (NULL == eip) 1477 if (NULL == eip)
1489 { 1478 {
1490 GNUNET_DISK_pipe_close (opipe); 1479 GNUNET_DISK_pipe_close (opipe);
1491 return NULL; 1480 return NULL;
1492 } 1481 }
1493 GNUNET_DISK_pipe_close_end (opipe, GNUNET_DISK_PIPE_END_WRITE); 1482 GNUNET_DISK_pipe_close_end (opipe, GNUNET_DISK_PIPE_END_WRITE);
1494 cmd = GNUNET_malloc (sizeof (struct GNUNET_OS_CommandHandle)); 1483 cmd = GNUNET_malloc (sizeof (struct GNUNET_OS_CommandHandle));
1495 cmd->timeout = GNUNET_TIME_relative_to_absolute (timeout); 1484 cmd->timeout = GNUNET_TIME_relative_to_absolute (timeout);
@@ -1498,8 +1487,7 @@ GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, void *proc_cls,
1498 cmd->proc = proc; 1487 cmd->proc = proc;
1499 cmd->proc_cls = proc_cls; 1488 cmd->proc_cls = proc_cls;
1500 cmd->r = GNUNET_DISK_pipe_handle (opipe, GNUNET_DISK_PIPE_END_READ); 1489 cmd->r = GNUNET_DISK_pipe_handle (opipe, GNUNET_DISK_PIPE_END_READ);
1501 cmd->rtask = 1490 cmd->rtask = GNUNET_SCHEDULER_add_read_file (timeout, cmd->r, &cmd_read, cmd);
1502 GNUNET_SCHEDULER_add_read_file (timeout, cmd->r, &cmd_read, cmd);
1503 return cmd; 1491 return cmd;
1504} 1492}
1505 1493
diff --git a/src/util/peer.c b/src/util/peer.c
index c88e03c15..2444cb9f8 100644
--- a/src/util/peer.c
+++ b/src/util/peer.c
@@ -107,7 +107,7 @@ GNUNET_PEER_search (const struct GNUNET_PeerIdentity *pid)
107 * @return the interned identity. 107 * @return the interned identity.
108 */ 108 */
109GNUNET_PEER_Id 109GNUNET_PEER_Id
110GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid) 110GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid)
111{ 111{
112 GNUNET_PEER_Id ret; 112 GNUNET_PEER_Id ret;
113 struct PeerEntry *e; 113 struct PeerEntry *e;
@@ -121,24 +121,24 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid)
121 off = (long) GNUNET_CONTAINER_multihashmap_get (map, &pid->hashPubKey); 121 off = (long) GNUNET_CONTAINER_multihashmap_get (map, &pid->hashPubKey);
122 e = (off == 0) ? NULL : &table[off]; 122 e = (off == 0) ? NULL : &table[off];
123 if (e != NULL) 123 if (e != NULL)
124 { 124 {
125 GNUNET_assert (e->rc > 0); 125 GNUNET_assert (e->rc > 0);
126 e->rc++; 126 e->rc++;
127 return e->pid; 127 return e->pid;
128 } 128 }
129 ret = free_list_start; 129 ret = free_list_start;
130 if (ret == size) 130 if (ret == size)
131 { 131 {
132 GNUNET_array_grow (table, size, size + 16); 132 GNUNET_array_grow (table, size, size + 16);
133 for (i = ret; i < size; i++) 133 for (i = ret; i < size; i++)
134 table[i].pid = i + 1; 134 table[i].pid = i + 1;
135 } 135 }
136 if (ret == 0) 136 if (ret == 0)
137 { 137 {
138 table[0].pid = 0; 138 table[0].pid = 0;
139 table[0].rc = 1; 139 table[0].rc = 1;
140 ret = 1; 140 ret = 1;
141 } 141 }
142 GNUNET_assert (ret < size); 142 GNUNET_assert (ret < size);
143 GNUNET_assert (table[ret].rc == 0); 143 GNUNET_assert (table[ret].rc == 0);
144 free_list_start = table[ret].pid; 144 free_list_start = table[ret].pid;
@@ -146,9 +146,9 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid)
146 table[ret].rc = 1; 146 table[ret].rc = 1;
147 table[ret].pid = ret; 147 table[ret].pid = ret;
148 GNUNET_break (GNUNET_OK == 148 GNUNET_break (GNUNET_OK ==
149 GNUNET_CONTAINER_multihashmap_put (map, &pid->hashPubKey, 149 GNUNET_CONTAINER_multihashmap_put (map, &pid->hashPubKey,
150 (void *) (long) ret, 150 (void *) (long) ret,
151 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 151 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
152 return ret; 152 return ret;
153} 153}
154 154
@@ -160,7 +160,7 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid)
160 * @param count size of the ids array 160 * @param count size of the ids array
161 */ 161 */
162void 162void
163GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id * ids, unsigned int count) 163GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id *ids, unsigned int count)
164{ 164{
165 int i; 165 int i;
166 GNUNET_PEER_Id id; 166 GNUNET_PEER_Id id;
@@ -168,25 +168,24 @@ GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id * ids, unsigned int count)
168 if (count == 0) 168 if (count == 0)
169 return; 169 return;
170 for (i = count - 1; i >= 0; i--) 170 for (i = count - 1; i >= 0; i--)
171 {
172 id = ids[i];
173 if (id == 0)
174 continue;
175 GNUNET_assert (id < size);
176 GNUNET_assert (table[id].rc > 0);
177 table[id].rc--;
178 if (table[id].rc == 0)
171 { 179 {
172 id = ids[i]; 180 GNUNET_break (GNUNET_OK ==
173 if (id == 0) 181 GNUNET_CONTAINER_multihashmap_remove (map,
174 continue; 182 &table[id].
175 GNUNET_assert (id < size); 183 id.hashPubKey,
176 GNUNET_assert (table[id].rc > 0); 184 (void *) (long) id));
177 table[id].rc--; 185 table[id].pid = free_list_start;
178 if (table[id].rc == 0) 186 free_list_start = id;
179 {
180 GNUNET_break (GNUNET_OK ==
181 GNUNET_CONTAINER_multihashmap_remove (map,
182 &table[id].
183 id.hashPubKey,
184 (void *) (long)
185 id));
186 table[id].pid = free_list_start;
187 free_list_start = id;
188 }
189 } 187 }
188 }
190} 189}
191 190
192 191
@@ -206,16 +205,15 @@ GNUNET_PEER_change_rc (GNUNET_PEER_Id id, int delta)
206 GNUNET_assert ((delta >= 0) || (table[id].rc >= -delta)); 205 GNUNET_assert ((delta >= 0) || (table[id].rc >= -delta));
207 table[id].rc += delta; 206 table[id].rc += delta;
208 if (table[id].rc == 0) 207 if (table[id].rc == 0)
209 { 208 {
210 GNUNET_break (GNUNET_OK == 209 GNUNET_break (GNUNET_OK ==
211 GNUNET_CONTAINER_multihashmap_remove (map, 210 GNUNET_CONTAINER_multihashmap_remove (map,
212 &table[id]. 211 &table[id].
213 id.hashPubKey, 212 id.hashPubKey,
214 (void *) (long) 213 (void *) (long) id));
215 id)); 214 table[id].pid = free_list_start;
216 table[id].pid = free_list_start; 215 free_list_start = id;
217 free_list_start = id; 216 }
218 }
219} 217}
220 218
221 219
@@ -229,11 +227,11 @@ void
229GNUNET_PEER_resolve (GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid) 227GNUNET_PEER_resolve (GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
230{ 228{
231 if (id == 0) 229 if (id == 0)
232 { 230 {
233 memset (pid, 0, sizeof (struct GNUNET_PeerIdentity)); 231 memset (pid, 0, sizeof (struct GNUNET_PeerIdentity));
234 GNUNET_break (0); 232 GNUNET_break (0);
235 return; 233 return;
236 } 234 }
237 GNUNET_assert (id < size); 235 GNUNET_assert (id < size);
238 GNUNET_assert (table[id].rc > 0); 236 GNUNET_assert (table[id].rc > 0);
239 *pid = table[id].id; 237 *pid = table[id].id;
diff --git a/src/util/perf_crypto_hash.c b/src/util/perf_crypto_hash.c
index 746b33eca..d883776b4 100644
--- a/src/util/perf_crypto_hash.c
+++ b/src/util/perf_crypto_hash.c
@@ -42,11 +42,11 @@ perfHash ()
42 memset (buf, 1, 1024 * 64); 42 memset (buf, 1, 1024 * 64);
43 GNUNET_CRYPTO_hash ("foo", 3, &hc1); 43 GNUNET_CRYPTO_hash ("foo", 3, &hc1);
44 for (i = 0; i < 1024; i++) 44 for (i = 0; i < 1024; i++)
45 { 45 {
46 GNUNET_CRYPTO_hash (&hc1, sizeof (GNUNET_HashCode), &hc2); 46 GNUNET_CRYPTO_hash (&hc1, sizeof (GNUNET_HashCode), &hc2);
47 GNUNET_CRYPTO_hash (&hc2, sizeof (GNUNET_HashCode), &hc1); 47 GNUNET_CRYPTO_hash (&hc2, sizeof (GNUNET_HashCode), &hc1);
48 GNUNET_CRYPTO_hash (buf, 1024 * 64, &hc3); 48 GNUNET_CRYPTO_hash (buf, 1024 * 64, &hc3);
49 } 49 }
50 GNUNET_free (buf); 50 GNUNET_free (buf);
51} 51}
52 52
@@ -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)
62 GNUNET_TIME_absolute_get_duration (start).rel_value); 62 GNUNET_TIME_absolute_get_duration (start).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
66 (start).rel_value), "kb/s"); 66 (start).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 dffc8ecd6..fe5fb87f9 100644
--- a/src/util/plugin.c
+++ b/src/util/plugin.c
@@ -85,30 +85,30 @@ plugin_init ()
85 85
86 err = lt_dlinit (); 86 err = lt_dlinit ();
87 if (err > 0) 87 if (err > 0)
88 { 88 {
89 fprintf (stderr, _("Initialization of plugin mechanism failed: %s!\n"), 89 fprintf (stderr, _("Initialization of plugin mechanism failed: %s!\n"),
90 lt_dlerror ()); 90 lt_dlerror ());
91 return; 91 return;
92 } 92 }
93 opath = lt_dlgetsearchpath (); 93 opath = lt_dlgetsearchpath ();
94 if (opath != NULL) 94 if (opath != NULL)
95 old_dlsearchpath = GNUNET_strdup (opath); 95 old_dlsearchpath = GNUNET_strdup (opath);
96 path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBDIR); 96 path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBDIR);
97 if (path != NULL) 97 if (path != NULL)
98 {
99 if (opath != NULL)
98 { 100 {
99 if (opath != NULL) 101 GNUNET_asprintf (&cpath, "%s:%s", opath, path);
100 { 102 lt_dlsetsearchpath (cpath);
101 GNUNET_asprintf (&cpath, "%s:%s", opath, path); 103 GNUNET_free (path);
102 lt_dlsetsearchpath (cpath); 104 GNUNET_free (cpath);
103 GNUNET_free (path);
104 GNUNET_free (cpath);
105 }
106 else
107 {
108 lt_dlsetsearchpath (path);
109 GNUNET_free (path);
110 }
111 } 105 }
106 else
107 {
108 lt_dlsetsearchpath (path);
109 GNUNET_free (path);
110 }
111 }
112} 112}
113 113
114 114
@@ -120,10 +120,10 @@ plugin_fini ()
120{ 120{
121 lt_dlsetsearchpath (old_dlsearchpath); 121 lt_dlsetsearchpath (old_dlsearchpath);
122 if (old_dlsearchpath != NULL) 122 if (old_dlsearchpath != NULL)
123 { 123 {
124 GNUNET_free (old_dlsearchpath); 124 GNUNET_free (old_dlsearchpath);
125 old_dlsearchpath = NULL; 125 old_dlsearchpath = NULL;
126 } 126 }
127 lt_dlexit (); 127 lt_dlexit ();
128} 128}
129 129
@@ -143,8 +143,8 @@ resolve_function (struct PluginList *plug, const char *name)
143 mptr = lt_dlsym (plug->handle, initName); 143 mptr = lt_dlsym (plug->handle, initName);
144 if (mptr == NULL) 144 if (mptr == NULL)
145 LOG (GNUNET_ERROR_TYPE_ERROR, 145 LOG (GNUNET_ERROR_TYPE_ERROR,
146 _("`%s' failed to resolve method '%s' with error: %s\n"), 146 _("`%s' failed to resolve method '%s' with error: %s\n"), "lt_dlsym",
147 "lt_dlsym", &initName[1], lt_dlerror ()); 147 &initName[1], lt_dlerror ());
148 GNUNET_free (initName); 148 GNUNET_free (initName);
149 return mptr; 149 return mptr;
150} 150}
@@ -166,10 +166,10 @@ GNUNET_PLUGIN_test (const char *library_name)
166 struct PluginList plug; 166 struct PluginList plug;
167 167
168 if (!initialized) 168 if (!initialized)
169 { 169 {
170 initialized = GNUNET_YES; 170 initialized = GNUNET_YES;
171 plugin_init (); 171 plugin_init ();
172 } 172 }
173 libhandle = lt_dlopenext (library_name); 173 libhandle = lt_dlopenext (library_name);
174 if (libhandle == NULL) 174 if (libhandle == NULL)
175 return GNUNET_NO; 175 return GNUNET_NO;
@@ -177,11 +177,11 @@ GNUNET_PLUGIN_test (const char *library_name)
177 plug.name = (char *) library_name; 177 plug.name = (char *) library_name;
178 init = resolve_function (&plug, "init"); 178 init = resolve_function (&plug, "init");
179 if (init == NULL) 179 if (init == NULL)
180 { 180 {
181 GNUNET_break (0); 181 GNUNET_break (0);
182 lt_dlclose (libhandle); 182 lt_dlclose (libhandle);
183 return GNUNET_NO; 183 return GNUNET_NO;
184 } 184 }
185 lt_dlclose (libhandle); 185 lt_dlclose (libhandle);
186 return GNUNET_YES; 186 return GNUNET_YES;
187} 187}
@@ -208,18 +208,18 @@ GNUNET_PLUGIN_load (const char *library_name, void *arg)
208 void *ret; 208 void *ret;
209 209
210 if (!initialized) 210 if (!initialized)
211 { 211 {
212 initialized = GNUNET_YES; 212 initialized = GNUNET_YES;
213 plugin_init (); 213 plugin_init ();
214 } 214 }
215 libhandle = lt_dlopenext (library_name); 215 libhandle = lt_dlopenext (library_name);
216 if (libhandle == NULL) 216 if (libhandle == NULL)
217 { 217 {
218 LOG (GNUNET_ERROR_TYPE_ERROR, 218 LOG (GNUNET_ERROR_TYPE_ERROR,
219 _("`%s' failed for library `%s' with error: %s\n"), 219 _("`%s' failed for library `%s' with error: %s\n"), "lt_dlopenext",
220 "lt_dlopenext", library_name, lt_dlerror ()); 220 library_name, lt_dlerror ());
221 return NULL; 221 return NULL;
222 } 222 }
223 plug = GNUNET_malloc (sizeof (struct PluginList)); 223 plug = GNUNET_malloc (sizeof (struct PluginList));
224 plug->handle = libhandle; 224 plug->handle = libhandle;
225 plug->name = GNUNET_strdup (library_name); 225 plug->name = GNUNET_strdup (library_name);
@@ -227,13 +227,13 @@ GNUNET_PLUGIN_load (const char *library_name, void *arg)
227 plugins = plug; 227 plugins = plug;
228 init = resolve_function (plug, "init"); 228 init = resolve_function (plug, "init");
229 if ((init == NULL) || (NULL == (ret = init (arg)))) 229 if ((init == NULL) || (NULL == (ret = init (arg))))
230 { 230 {
231 lt_dlclose (libhandle); 231 lt_dlclose (libhandle);
232 GNUNET_free (plug->name); 232 GNUNET_free (plug->name);
233 plugins = plug->next; 233 plugins = plug->next;
234 GNUNET_free (plug); 234 GNUNET_free (plug);
235 return NULL; 235 return NULL;
236 } 236 }
237 return ret; 237 return ret;
238} 238}
239 239
@@ -257,10 +257,10 @@ GNUNET_PLUGIN_unload (const char *library_name, void *arg)
257 prev = NULL; 257 prev = NULL;
258 pos = plugins; 258 pos = plugins;
259 while ((pos != NULL) && (0 != strcmp (pos->name, library_name))) 259 while ((pos != NULL) && (0 != strcmp (pos->name, library_name)))
260 { 260 {
261 prev = pos; 261 prev = pos;
262 pos = pos->next; 262 pos = pos->next;
263 } 263 }
264 if (pos == NULL) 264 if (pos == NULL)
265 return NULL; 265 return NULL;
266 266
@@ -276,10 +276,10 @@ GNUNET_PLUGIN_unload (const char *library_name, void *arg)
276 GNUNET_free (pos->name); 276 GNUNET_free (pos->name);
277 GNUNET_free (pos); 277 GNUNET_free (pos);
278 if (plugins == NULL) 278 if (plugins == NULL)
279 { 279 {
280 plugin_fini (); 280 plugin_fini ();
281 initialized = GNUNET_NO; 281 initialized = GNUNET_NO;
282 } 282 }
283 return ret; 283 return ret;
284} 284}
285 285
@@ -294,8 +294,7 @@ struct LoadAllContext
294 294
295 295
296static int 296static int
297find_libraries (void *cls, 297find_libraries (void *cls, const char *filename)
298 const char *filename)
299{ 298{
300 struct LoadAllContext *lac = cls; 299 struct LoadAllContext *lac = cls;
301 const char *slashpos; 300 const char *slashpos;
@@ -309,14 +308,10 @@ find_libraries (void *cls,
309 while (NULL != (slashpos = strstr (libname, DIR_SEPARATOR_STR))) 308 while (NULL != (slashpos = strstr (libname, DIR_SEPARATOR_STR)))
310 libname = slashpos + 1; 309 libname = slashpos + 1;
311 n = strlen (libname); 310 n = strlen (libname);
312 if (0 != strncmp (lac->basename, 311 if (0 != strncmp (lac->basename, libname, strlen (lac->basename)))
313 libname, 312 return GNUNET_OK; /* wrong name */
314 strlen (lac->basename))) 313 if ((n > 3) && (0 == strcmp (&libname[n - 3], ".la")))
315 return GNUNET_OK; /* wrong name */ 314 return GNUNET_OK; /* .la file */
316 if ( (n > 3) &&
317 (0 == strcmp (&libname[n-3],
318 ".la")) )
319 return GNUNET_OK; /* .la file */
320 basename = GNUNET_strdup (libname); 315 basename = GNUNET_strdup (libname);
321 if (NULL != (dot = strstr (basename, "."))) 316 if (NULL != (dot = strstr (basename, ".")))
322 *dot = '\0'; 317 *dot = '\0';
@@ -340,11 +335,9 @@ find_libraries (void *cls,
340 * @param cb function to call for each plugin found 335 * @param cb function to call for each plugin found
341 * @param cb_cls closure for 'cb' 336 * @param cb_cls closure for 'cb'
342 */ 337 */
343void 338void
344GNUNET_PLUGIN_load_all (const char *basename, 339GNUNET_PLUGIN_load_all (const char *basename, void *arg,
345 void *arg, 340 GNUNET_PLUGIN_LoaderCallback cb, void *cb_cls)
346 GNUNET_PLUGIN_LoaderCallback cb,
347 void *cb_cls)
348{ 341{
349 struct LoadAllContext lac; 342 struct LoadAllContext lac;
350 char *path; 343 char *path;
@@ -353,16 +346,14 @@ GNUNET_PLUGIN_load_all (const char *basename,
353 if (path == NULL) 346 if (path == NULL)
354 { 347 {
355 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 348 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
356 _("Could not determine plugin installation path.\n")); 349 _("Could not determine plugin installation path.\n"));
357 return; 350 return;
358 } 351 }
359 lac.basename = basename; 352 lac.basename = basename;
360 lac.arg = arg; 353 lac.arg = arg;
361 lac.cb = cb; 354 lac.cb = cb;
362 lac.cb_cls = cb_cls; 355 lac.cb_cls = cb_cls;
363 GNUNET_DISK_directory_scan (path, 356 GNUNET_DISK_directory_scan (path, &find_libraries, &lac);
364 &find_libraries,
365 &lac);
366 GNUNET_free (path); 357 GNUNET_free (path);
367} 358}
368 359
diff --git a/src/util/program.c b/src/util/program.c
index 5582f30c6..6a0e5a555 100644
--- a/src/util/program.c
+++ b/src/util/program.c
@@ -129,9 +129,9 @@ cmd_sorter (__const void *a1, __const void *a2)
129 */ 129 */
130int 130int
131GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName, 131GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName,
132 const char *binaryHelp, 132 const char *binaryHelp,
133 const struct GNUNET_GETOPT_CommandLineOption *options, 133 const struct GNUNET_GETOPT_CommandLineOption *options,
134 GNUNET_PROGRAM_Main task, void *task_cls) 134 GNUNET_PROGRAM_Main task, void *task_cls)
135{ 135{
136 struct CommandContext cc; 136 struct CommandContext cc;
137 char *path; 137 char *path;
@@ -159,29 +159,29 @@ GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName,
159 logfile = NULL; 159 logfile = NULL;
160 gargs = getenv ("GNUNET_ARGS"); 160 gargs = getenv ("GNUNET_ARGS");
161 if (gargs != NULL) 161 if (gargs != NULL)
162 { 162 {
163 char **gargv; 163 char **gargv;
164 unsigned int gargc; 164 unsigned int gargc;
165 int i; 165 int i;
166 char *tok; 166 char *tok;
167 char *cargs; 167 char *cargs;
168 168
169 gargv = NULL; 169 gargv = NULL;
170 gargc = 0; 170 gargc = 0;
171 for (i = 0; i < argc; i++) 171 for (i = 0; i < argc; i++)
172 GNUNET_array_append (gargv, gargc, GNUNET_strdup (argv[i])); 172 GNUNET_array_append (gargv, gargc, GNUNET_strdup (argv[i]));
173 cargs = GNUNET_strdup (gargs); 173 cargs = GNUNET_strdup (gargs);
174 tok = strtok (cargs, " "); 174 tok = strtok (cargs, " ");
175 while (NULL != tok) 175 while (NULL != tok)
176 { 176 {
177 GNUNET_array_append (gargv, gargc, GNUNET_strdup (tok)); 177 GNUNET_array_append (gargv, gargc, GNUNET_strdup (tok));
178 tok = strtok (NULL, " "); 178 tok = strtok (NULL, " ");
179 }
180 GNUNET_free (cargs);
181 GNUNET_array_append (gargv, gargc, NULL);
182 argv = (char *const *) gargv;
183 argc = gargc - 1;
184 } 179 }
180 GNUNET_free (cargs);
181 GNUNET_array_append (gargv, gargc, NULL);
182 argv = (char *const *) gargv;
183 argc = gargc - 1;
184 }
185 memset (&cc, 0, sizeof (cc)); 185 memset (&cc, 0, sizeof (cc));
186 loglev = NULL; 186 loglev = NULL;
187 cc.task = task; 187 cc.task = task;
@@ -193,28 +193,27 @@ GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName,
193 setlocale (LC_ALL, ""); 193 setlocale (LC_ALL, "");
194 path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR); 194 path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR);
195 if (path != NULL) 195 if (path != NULL)
196 { 196 {
197 BINDTEXTDOMAIN ("GNUnet", path); 197 BINDTEXTDOMAIN ("GNUnet", path);
198 GNUNET_free (path); 198 GNUNET_free (path);
199 } 199 }
200 textdomain ("GNUnet"); 200 textdomain ("GNUnet");
201#endif 201#endif
202 cnt = 0; 202 cnt = 0;
203 while (options[cnt].name != NULL) 203 while (options[cnt].name != NULL)
204 cnt++; 204 cnt++;
205 allopts = 205 allopts =
206 GNUNET_malloc ((cnt + 206 GNUNET_malloc ((cnt +
207 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption) + 207 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption) +
208 sizeof (defoptions)); 208 sizeof (defoptions));
209 memcpy (allopts, defoptions, sizeof (defoptions)); 209 memcpy (allopts, defoptions, sizeof (defoptions));
210 memcpy (&allopts 210 memcpy (&allopts
211 [sizeof (defoptions) / 211 [sizeof (defoptions) /
212 sizeof (struct GNUNET_GETOPT_CommandLineOption)], options, 212 sizeof (struct GNUNET_GETOPT_CommandLineOption)], options,
213 (cnt + 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption)); 213 (cnt + 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption));
214 cnt += 214 cnt += sizeof (defoptions) / sizeof (struct GNUNET_GETOPT_CommandLineOption);
215 sizeof (defoptions) / sizeof (struct GNUNET_GETOPT_CommandLineOption);
216 qsort (allopts, cnt, sizeof (struct GNUNET_GETOPT_CommandLineOption), 215 qsort (allopts, cnt, sizeof (struct GNUNET_GETOPT_CommandLineOption),
217 &cmd_sorter); 216 &cmd_sorter);
218 loglev = NULL; 217 loglev = NULL;
219 cc.cfgfile = GNUNET_strdup (GNUNET_DEFAULT_USER_CONFIG_FILE); 218 cc.cfgfile = GNUNET_strdup (GNUNET_DEFAULT_USER_CONFIG_FILE);
220 lpfx = GNUNET_strdup (binaryName); 219 lpfx = GNUNET_strdup (binaryName);
@@ -222,31 +221,30 @@ GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName,
222 *spc = '\0'; 221 *spc = '\0';
223 if ((-1 == 222 if ((-1 ==
224 (ret = 223 (ret =
225 GNUNET_GETOPT_run (binaryName, allopts, (unsigned int) argc, argv))) 224 GNUNET_GETOPT_run (binaryName, allopts, (unsigned int) argc, argv))) ||
226 || (GNUNET_OK != GNUNET_log_setup (lpfx, loglev, logfile))) 225 (GNUNET_OK != GNUNET_log_setup (lpfx, loglev, logfile)))
227 { 226 {
228 GNUNET_CONFIGURATION_destroy (cfg); 227 GNUNET_CONFIGURATION_destroy (cfg);
229 GNUNET_free_non_null (cc.cfgfile); 228 GNUNET_free_non_null (cc.cfgfile);
230 GNUNET_free_non_null (loglev); 229 GNUNET_free_non_null (loglev);
231 GNUNET_free_non_null (logfile); 230 GNUNET_free_non_null (logfile);
232 GNUNET_free (allopts); 231 GNUNET_free (allopts);
233 GNUNET_free (lpfx); 232 GNUNET_free (lpfx);
234 return GNUNET_SYSERR; 233 return GNUNET_SYSERR;
235 } 234 }
236 (void) GNUNET_CONFIGURATION_load (cfg, cc.cfgfile); 235 (void) GNUNET_CONFIGURATION_load (cfg, cc.cfgfile);
237 GNUNET_free (allopts); 236 GNUNET_free (allopts);
238 GNUNET_free (lpfx); 237 GNUNET_free (lpfx);
239 if (GNUNET_OK == 238 if (GNUNET_OK ==
240 GNUNET_CONFIGURATION_get_value_number (cc.cfg, "testing", "skew_offset", 239 GNUNET_CONFIGURATION_get_value_number (cc.cfg, "testing", "skew_offset",
241 &skew_offset) && 240 &skew_offset) &&
242 (GNUNET_OK == 241 (GNUNET_OK ==
243 GNUNET_CONFIGURATION_get_value_number (cc.cfg, "testing", 242 GNUNET_CONFIGURATION_get_value_number (cc.cfg, "testing",
244 "skew_variance", 243 "skew_variance", &skew_variance)))
245 &skew_variance))) 244 {
246 { 245 clock_offset = skew_offset - skew_variance;
247 clock_offset = skew_offset - skew_variance; 246 GNUNET_TIME_set_offset (clock_offset);
248 GNUNET_TIME_set_offset (clock_offset); 247 }
249 }
250 /* run */ 248 /* run */
251 cc.args = &argv[ret]; 249 cc.args = &argv[ret];
252 GNUNET_SCHEDULER_run (&program_main, &cc); 250 GNUNET_SCHEDULER_run (&program_main, &cc);
diff --git a/src/util/pseudonym.c b/src/util/pseudonym.c
index b6e51af18..2a736bc46 100644
--- a/src/util/pseudonym.c
+++ b/src/util/pseudonym.c
@@ -82,16 +82,16 @@ static struct DiscoveryCallback *head;
82 */ 82 */
83static void 83static void
84internal_notify (const GNUNET_HashCode * id, 84internal_notify (const GNUNET_HashCode * id,
85 const struct GNUNET_CONTAINER_MetaData *md, int rating) 85 const struct GNUNET_CONTAINER_MetaData *md, int rating)
86{ 86{
87 struct DiscoveryCallback *pos; 87 struct DiscoveryCallback *pos;
88 88
89 pos = head; 89 pos = head;
90 while (pos != NULL) 90 while (pos != NULL)
91 { 91 {
92 pos->callback (pos->closure, id, md, rating); 92 pos->callback (pos->closure, id, md, rating);
93 pos = pos->next; 93 pos = pos->next;
94 } 94 }
95} 95}
96 96
97/** 97/**
@@ -103,10 +103,9 @@ internal_notify (const GNUNET_HashCode * id,
103 */ 103 */
104int 104int
105GNUNET_PSEUDONYM_discovery_callback_register (const struct 105GNUNET_PSEUDONYM_discovery_callback_register (const struct
106 GNUNET_CONFIGURATION_Handle 106 GNUNET_CONFIGURATION_Handle *cfg,
107 *cfg, 107 GNUNET_PSEUDONYM_Iterator
108 GNUNET_PSEUDONYM_Iterator 108 iterator, void *closure)
109 iterator, void *closure)
110{ 109{
111 struct DiscoveryCallback *list; 110 struct DiscoveryCallback *list;
112 111
@@ -126,7 +125,7 @@ GNUNET_PSEUDONYM_discovery_callback_register (const struct
126 */ 125 */
127int 126int
128GNUNET_PSEUDONYM_discovery_callback_unregister (GNUNET_PSEUDONYM_Iterator 127GNUNET_PSEUDONYM_discovery_callback_unregister (GNUNET_PSEUDONYM_Iterator
129 iterator, void *closure) 128 iterator, void *closure)
130{ 129{
131 struct DiscoveryCallback *prev; 130 struct DiscoveryCallback *prev;
132 struct DiscoveryCallback *pos; 131 struct DiscoveryCallback *pos;
@@ -134,11 +133,11 @@ GNUNET_PSEUDONYM_discovery_callback_unregister (GNUNET_PSEUDONYM_Iterator
134 prev = NULL; 133 prev = NULL;
135 pos = head; 134 pos = head;
136 while ((pos != NULL) && 135 while ((pos != NULL) &&
137 ((pos->callback != iterator) || (pos->closure != closure))) 136 ((pos->callback != iterator) || (pos->closure != closure)))
138 { 137 {
139 prev = pos; 138 prev = pos;
140 pos = pos->next; 139 pos = pos->next;
141 } 140 }
142 if (pos == NULL) 141 if (pos == NULL)
143 return GNUNET_SYSERR; 142 return GNUNET_SYSERR;
144 if (prev == NULL) 143 if (prev == NULL)
@@ -160,17 +159,16 @@ GNUNET_PSEUDONYM_discovery_callback_unregister (GNUNET_PSEUDONYM_Iterator
160 */ 159 */
161static char * 160static char *
162get_data_filename (const struct GNUNET_CONFIGURATION_Handle *cfg, 161get_data_filename (const struct GNUNET_CONFIGURATION_Handle *cfg,
163 const char *prefix, const GNUNET_HashCode * psid) 162 const char *prefix, const GNUNET_HashCode * psid)
164{ 163{
165 struct GNUNET_CRYPTO_HashAsciiEncoded enc; 164 struct GNUNET_CRYPTO_HashAsciiEncoded enc;
166 165
167 if (psid != NULL) 166 if (psid != NULL)
168 GNUNET_CRYPTO_hash_to_enc (psid, &enc); 167 GNUNET_CRYPTO_hash_to_enc (psid, &enc);
169 return GNUNET_DISK_get_home_filename (cfg, GNUNET_CLIENT_SERVICE_NAME, 168 return GNUNET_DISK_get_home_filename (cfg, GNUNET_CLIENT_SERVICE_NAME, prefix,
170 prefix, 169 (psid ==
171 (psid == 170 NULL) ? NULL : (const char *) &enc,
172 NULL) ? NULL : (const char *) &enc, 171 NULL);
173 NULL);
174} 172}
175 173
176 174
@@ -184,9 +182,9 @@ get_data_filename (const struct GNUNET_CONFIGURATION_Handle *cfg,
184 */ 182 */
185static void 183static void
186write_pseudonym_info (const struct GNUNET_CONFIGURATION_Handle *cfg, 184write_pseudonym_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
187 const GNUNET_HashCode * nsid, 185 const GNUNET_HashCode * nsid,
188 const struct GNUNET_CONTAINER_MetaData *meta, 186 const struct GNUNET_CONTAINER_MetaData *meta,
189 int32_t ranking, const char *ns_name) 187 int32_t ranking, const char *ns_name)
190{ 188{
191 char *fn; 189 char *fn;
192 struct GNUNET_BIO_WriteHandle *fileW; 190 struct GNUNET_BIO_WriteHandle *fileW;
@@ -195,23 +193,23 @@ write_pseudonym_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
195 GNUNET_assert (fn != NULL); 193 GNUNET_assert (fn != NULL);
196 fileW = GNUNET_BIO_write_open (fn); 194 fileW = GNUNET_BIO_write_open (fn);
197 if (NULL != fileW) 195 if (NULL != fileW)
196 {
197 if ((GNUNET_OK != GNUNET_BIO_write_int32 (fileW, ranking)) ||
198 (GNUNET_OK != GNUNET_BIO_write_string (fileW, ns_name)) ||
199 (GNUNET_OK != GNUNET_BIO_write_meta_data (fileW, meta)))
198 { 200 {
199 if ((GNUNET_OK != GNUNET_BIO_write_int32 (fileW, ranking)) || 201 (void) GNUNET_BIO_write_close (fileW);
200 (GNUNET_OK != GNUNET_BIO_write_string (fileW, ns_name)) || 202 GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
201 (GNUNET_OK != GNUNET_BIO_write_meta_data (fileW, meta))) 203 GNUNET_free (fn);
202 { 204 return;
203 (void) GNUNET_BIO_write_close (fileW);
204 GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
205 GNUNET_free (fn);
206 return;
207 }
208 if (GNUNET_OK != GNUNET_BIO_write_close (fileW))
209 {
210 GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
211 GNUNET_free (fn);
212 return;
213 }
214 } 205 }
206 if (GNUNET_OK != GNUNET_BIO_write_close (fileW))
207 {
208 GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
209 GNUNET_free (fn);
210 return;
211 }
212 }
215 GNUNET_free (fn); 213 GNUNET_free (fn);
216 /* create entry for pseudonym name in names */ 214 /* create entry for pseudonym name in names */
217 /* FIXME: 90% of what this call does is not needed 215 /* FIXME: 90% of what this call does is not needed
@@ -230,9 +228,9 @@ write_pseudonym_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
230 */ 228 */
231static int 229static int
232read_info (const struct GNUNET_CONFIGURATION_Handle *cfg, 230read_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
233 const GNUNET_HashCode * nsid, 231 const GNUNET_HashCode * nsid,
234 struct GNUNET_CONTAINER_MetaData **meta, int32_t * ranking, 232 struct GNUNET_CONTAINER_MetaData **meta, int32_t * ranking,
235 char **ns_name) 233 char **ns_name)
236{ 234{
237 char *fn; 235 char *fn;
238 char *emsg; 236 char *emsg;
@@ -242,10 +240,10 @@ read_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
242 GNUNET_assert (fn != NULL); 240 GNUNET_assert (fn != NULL);
243 fileR = GNUNET_BIO_read_open (fn); 241 fileR = GNUNET_BIO_read_open (fn);
244 if (fileR == NULL) 242 if (fileR == NULL)
245 { 243 {
246 GNUNET_free (fn); 244 GNUNET_free (fn);
247 return GNUNET_SYSERR; 245 return GNUNET_SYSERR;
248 } 246 }
249 emsg = NULL; 247 emsg = NULL;
250 *ns_name = NULL; 248 *ns_name = NULL;
251 if ((GNUNET_OK != GNUNET_BIO_read_int32 (fileR, ranking)) || 249 if ((GNUNET_OK != GNUNET_BIO_read_int32 (fileR, ranking)) ||
@@ -253,30 +251,29 @@ read_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
253 GNUNET_BIO_read_string (fileR, "Read string error!", ns_name, 200)) || 251 GNUNET_BIO_read_string (fileR, "Read string error!", ns_name, 200)) ||
254 (GNUNET_OK != 252 (GNUNET_OK !=
255 GNUNET_BIO_read_meta_data (fileR, "Read meta data error!", meta))) 253 GNUNET_BIO_read_meta_data (fileR, "Read meta data error!", meta)))
256 { 254 {
257 (void) GNUNET_BIO_read_close (fileR, &emsg); 255 (void) GNUNET_BIO_read_close (fileR, &emsg);
258 GNUNET_free_non_null (emsg); 256 GNUNET_free_non_null (emsg);
259 GNUNET_free_non_null (*ns_name); 257 GNUNET_free_non_null (*ns_name);
260 *ns_name = NULL; 258 *ns_name = NULL;
261 GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn)); 259 GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
262 GNUNET_free (fn); 260 GNUNET_free (fn);
263 return GNUNET_SYSERR; 261 return GNUNET_SYSERR;
264 } 262 }
265 if (GNUNET_OK != GNUNET_BIO_read_close (fileR, &emsg)) 263 if (GNUNET_OK != GNUNET_BIO_read_close (fileR, &emsg))
266 { 264 {
267 LOG (GNUNET_ERROR_TYPE_WARNING, 265 LOG (GNUNET_ERROR_TYPE_WARNING,
268 _ 266 _("Failed to parse metadata about pseudonym from file `%s': %s\n"), fn,
269 ("Failed to parse metadata about pseudonym from file `%s': %s\n"), 267 emsg);
270 fn, emsg); 268 GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
271 GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn)); 269 GNUNET_CONTAINER_meta_data_destroy (*meta);
272 GNUNET_CONTAINER_meta_data_destroy (*meta); 270 *meta = NULL;
273 *meta = NULL; 271 GNUNET_free_non_null (*ns_name);
274 GNUNET_free_non_null (*ns_name); 272 *ns_name = NULL;
275 *ns_name = NULL; 273 GNUNET_free_non_null (emsg);
276 GNUNET_free_non_null (emsg); 274 GNUNET_free (fn);
277 GNUNET_free (fn); 275 return GNUNET_SYSERR;
278 return GNUNET_SYSERR; 276 }
279 }
280 GNUNET_free (fn); 277 GNUNET_free (fn);
281 return GNUNET_OK; 278 return GNUNET_OK;
282} 279}
@@ -292,7 +289,7 @@ read_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
292 */ 289 */
293char * 290char *
294GNUNET_PSEUDONYM_id_to_name (const struct GNUNET_CONFIGURATION_Handle *cfg, 291GNUNET_PSEUDONYM_id_to_name (const struct GNUNET_CONFIGURATION_Handle *cfg,
295 const GNUNET_HashCode * nsid) 292 const GNUNET_HashCode * nsid)
296{ 293{
297 struct GNUNET_CONTAINER_MetaData *meta; 294 struct GNUNET_CONTAINER_MetaData *meta;
298 char *name; 295 char *name;
@@ -310,25 +307,25 @@ GNUNET_PSEUDONYM_id_to_name (const struct GNUNET_CONFIGURATION_Handle *cfg,
310 meta = NULL; 307 meta = NULL;
311 name = NULL; 308 name = NULL;
312 if (GNUNET_OK == read_info (cfg, nsid, &meta, rank, &name)) 309 if (GNUNET_OK == read_info (cfg, nsid, &meta, rank, &name))
310 {
311 if ((meta != NULL) && (name == NULL))
312 name =
313 GNUNET_CONTAINER_meta_data_get_first_by_types (meta,
314 EXTRACTOR_METATYPE_TITLE,
315 EXTRACTOR_METATYPE_FILENAME,
316 EXTRACTOR_METATYPE_DESCRIPTION,
317 EXTRACTOR_METATYPE_SUBJECT,
318 EXTRACTOR_METATYPE_PUBLISHER,
319 EXTRACTOR_METATYPE_AUTHOR_NAME,
320 EXTRACTOR_METATYPE_COMMENT,
321 EXTRACTOR_METATYPE_SUMMARY,
322 -1);
323 if (meta != NULL)
313 { 324 {
314 if ((meta != NULL) && (name == NULL)) 325 GNUNET_CONTAINER_meta_data_destroy (meta);
315 name = 326 meta = NULL;
316 GNUNET_CONTAINER_meta_data_get_first_by_types (meta,
317 EXTRACTOR_METATYPE_TITLE,
318 EXTRACTOR_METATYPE_FILENAME,
319 EXTRACTOR_METATYPE_DESCRIPTION,
320 EXTRACTOR_METATYPE_SUBJECT,
321 EXTRACTOR_METATYPE_PUBLISHER,
322 EXTRACTOR_METATYPE_AUTHOR_NAME,
323 EXTRACTOR_METATYPE_COMMENT,
324 EXTRACTOR_METATYPE_SUMMARY,
325 -1);
326 if (meta != NULL)
327 {
328 GNUNET_CONTAINER_meta_data_destroy (meta);
329 meta = NULL;
330 }
331 } 327 }
328 }
332 if (name == NULL) 329 if (name == NULL)
333 name = GNUNET_strdup (_("no-name")); 330 name = GNUNET_strdup (_("no-name"));
334 GNUNET_CRYPTO_hash (name, strlen (name), &nh); 331 GNUNET_CRYPTO_hash (name, strlen (name), &nh);
@@ -339,31 +336,31 @@ GNUNET_PSEUDONYM_id_to_name (const struct GNUNET_CONFIGURATION_Handle *cfg,
339 if (0 == STAT (fn, &sbuf)) 336 if (0 == STAT (fn, &sbuf))
340 GNUNET_DISK_file_size (fn, &len, GNUNET_YES); 337 GNUNET_DISK_file_size (fn, &len, GNUNET_YES);
341 fh = GNUNET_DISK_file_open (fn, 338 fh = GNUNET_DISK_file_open (fn,
342 GNUNET_DISK_OPEN_CREATE | 339 GNUNET_DISK_OPEN_CREATE |
343 GNUNET_DISK_OPEN_READWRITE, 340 GNUNET_DISK_OPEN_READWRITE,
344 GNUNET_DISK_PERM_USER_READ | 341 GNUNET_DISK_PERM_USER_READ |
345 GNUNET_DISK_PERM_USER_WRITE); 342 GNUNET_DISK_PERM_USER_WRITE);
346 i = 0; 343 i = 0;
347 idx = -1; 344 idx = -1;
348 while ((len >= sizeof (GNUNET_HashCode)) && 345 while ((len >= sizeof (GNUNET_HashCode)) &&
349 (sizeof (GNUNET_HashCode) == 346 (sizeof (GNUNET_HashCode) ==
350 GNUNET_DISK_file_read (fh, &nh, sizeof (GNUNET_HashCode)))) 347 GNUNET_DISK_file_read (fh, &nh, sizeof (GNUNET_HashCode))))
351 { 348 {
352 if (0 == memcmp (&nh, nsid, sizeof (GNUNET_HashCode))) 349 if (0 == memcmp (&nh, nsid, sizeof (GNUNET_HashCode)))
353 {
354 idx = i;
355 break;
356 }
357 i++;
358 len -= sizeof (GNUNET_HashCode);
359 }
360 if (idx == -1)
361 { 350 {
362 idx = i; 351 idx = i;
363 if (sizeof (GNUNET_HashCode) != 352 break;
364 GNUNET_DISK_file_write (fh, nsid, sizeof (GNUNET_HashCode)))
365 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "write", fn);
366 } 353 }
354 i++;
355 len -= sizeof (GNUNET_HashCode);
356 }
357 if (idx == -1)
358 {
359 idx = i;
360 if (sizeof (GNUNET_HashCode) !=
361 GNUNET_DISK_file_write (fh, nsid, sizeof (GNUNET_HashCode)))
362 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "write", fn);
363 }
367 GNUNET_DISK_file_close (fh); 364 GNUNET_DISK_file_close (fh);
368 ret = GNUNET_malloc (strlen (name) + 32); 365 ret = GNUNET_malloc (strlen (name) + 32);
369 GNUNET_snprintf (ret, strlen (name) + 32, "%s-%u", name, idx); 366 GNUNET_snprintf (ret, strlen (name) + 32, "%s-%u", name, idx);
@@ -382,7 +379,7 @@ GNUNET_PSEUDONYM_id_to_name (const struct GNUNET_CONFIGURATION_Handle *cfg,
382 */ 379 */
383int 380int
384GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg, 381GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg,
385 const char *ns_uname, GNUNET_HashCode * nsid) 382 const char *ns_uname, GNUNET_HashCode * nsid)
386{ 383{
387 size_t slen; 384 size_t slen;
388 uint64_t len; 385 uint64_t len;
@@ -408,24 +405,24 @@ GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg,
408 if ((GNUNET_OK != GNUNET_DISK_file_test (fn) || 405 if ((GNUNET_OK != GNUNET_DISK_file_test (fn) ||
409 (GNUNET_OK != GNUNET_DISK_file_size (fn, &len, GNUNET_YES))) || 406 (GNUNET_OK != GNUNET_DISK_file_size (fn, &len, GNUNET_YES))) ||
410 ((idx + 1) * sizeof (GNUNET_HashCode) > len)) 407 ((idx + 1) * sizeof (GNUNET_HashCode) > len))
411 { 408 {
412 GNUNET_free (fn); 409 GNUNET_free (fn);
413 return GNUNET_SYSERR; 410 return GNUNET_SYSERR;
414 } 411 }
415 fh = GNUNET_DISK_file_open (fn, 412 fh = GNUNET_DISK_file_open (fn,
416 GNUNET_DISK_OPEN_CREATE | 413 GNUNET_DISK_OPEN_CREATE |
417 GNUNET_DISK_OPEN_READWRITE, 414 GNUNET_DISK_OPEN_READWRITE,
418 GNUNET_DISK_PERM_USER_READ | 415 GNUNET_DISK_PERM_USER_READ |
419 GNUNET_DISK_PERM_USER_WRITE); 416 GNUNET_DISK_PERM_USER_WRITE);
420 GNUNET_free (fn); 417 GNUNET_free (fn);
421 GNUNET_DISK_file_seek (fh, idx * sizeof (GNUNET_HashCode), 418 GNUNET_DISK_file_seek (fh, idx * sizeof (GNUNET_HashCode),
422 GNUNET_DISK_SEEK_SET); 419 GNUNET_DISK_SEEK_SET);
423 if (sizeof (GNUNET_HashCode) != 420 if (sizeof (GNUNET_HashCode) !=
424 GNUNET_DISK_file_read (fh, nsid, sizeof (GNUNET_HashCode))) 421 GNUNET_DISK_file_read (fh, nsid, sizeof (GNUNET_HashCode)))
425 { 422 {
426 GNUNET_DISK_file_close (fh); 423 GNUNET_DISK_file_close (fh);
427 return GNUNET_SYSERR; 424 return GNUNET_SYSERR;
428 } 425 }
429 GNUNET_DISK_file_close (fh); 426 GNUNET_DISK_file_close (fh);
430 return GNUNET_OK; 427 return GNUNET_OK;
431} 428}
@@ -475,15 +472,15 @@ list_pseudonym_helper (void *cls, const char *fullname)
475 if (strlen (fullname) < sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) 472 if (strlen (fullname) < sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded))
476 return GNUNET_OK; 473 return GNUNET_OK;
477 fn = &fullname[strlen (fullname) + 1 - 474 fn = &fullname[strlen (fullname) + 1 -
478 sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]; 475 sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)];
479 if (fn[-1] != DIR_SEPARATOR) 476 if (fn[-1] != DIR_SEPARATOR)
480 return GNUNET_OK; 477 return GNUNET_OK;
481 ret = GNUNET_OK; 478 ret = GNUNET_OK;
482 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (fn, &id)) 479 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (fn, &id))
483 return GNUNET_OK; /* invalid name */ 480 return GNUNET_OK; /* invalid name */
484 str = NULL; 481 str = NULL;
485 if (GNUNET_OK != read_info (c->cfg, &id, &meta, &rating, &str)) 482 if (GNUNET_OK != read_info (c->cfg, &id, &meta, &rating, &str))
486 return GNUNET_OK; /* ignore entry */ 483 return GNUNET_OK; /* ignore entry */
487 GNUNET_free_non_null (str); 484 GNUNET_free_non_null (str);
488 if (c->iterator != NULL) 485 if (c->iterator != NULL)
489 ret = c->iterator (c->closure, &id, meta, rating); 486 ret = c->iterator (c->closure, &id, meta, rating);
@@ -502,7 +499,7 @@ list_pseudonym_helper (void *cls, const char *fullname)
502 */ 499 */
503int 500int
504GNUNET_PSEUDONYM_list_all (const struct GNUNET_CONFIGURATION_Handle *cfg, 501GNUNET_PSEUDONYM_list_all (const struct GNUNET_CONFIGURATION_Handle *cfg,
505 GNUNET_PSEUDONYM_Iterator iterator, void *closure) 502 GNUNET_PSEUDONYM_Iterator iterator, void *closure)
506{ 503{
507 struct ListPseudonymClosure cls; 504 struct ListPseudonymClosure cls;
508 char *fn; 505 char *fn;
@@ -531,7 +528,7 @@ GNUNET_PSEUDONYM_list_all (const struct GNUNET_CONFIGURATION_Handle *cfg,
531 */ 528 */
532int 529int
533GNUNET_PSEUDONYM_rank (const struct GNUNET_CONFIGURATION_Handle *cfg, 530GNUNET_PSEUDONYM_rank (const struct GNUNET_CONFIGURATION_Handle *cfg,
534 const GNUNET_HashCode * nsid, int delta) 531 const GNUNET_HashCode * nsid, int delta)
535{ 532{
536 struct GNUNET_CONTAINER_MetaData *meta; 533 struct GNUNET_CONTAINER_MetaData *meta;
537 int ret; 534 int ret;
@@ -541,10 +538,10 @@ GNUNET_PSEUDONYM_rank (const struct GNUNET_CONFIGURATION_Handle *cfg,
541 name = NULL; 538 name = NULL;
542 ret = read_info (cfg, nsid, &meta, &ranking, &name); 539 ret = read_info (cfg, nsid, &meta, &ranking, &name);
543 if (ret == GNUNET_SYSERR) 540 if (ret == GNUNET_SYSERR)
544 { 541 {
545 ranking = 0; 542 ranking = 0;
546 meta = GNUNET_CONTAINER_meta_data_create (); 543 meta = GNUNET_CONTAINER_meta_data_create ();
547 } 544 }
548 ranking += delta; 545 ranking += delta;
549 write_pseudonym_info (cfg, nsid, meta, ranking, name); 546 write_pseudonym_info (cfg, nsid, meta, ranking, name);
550 GNUNET_CONTAINER_meta_data_destroy (meta); 547 GNUNET_CONTAINER_meta_data_destroy (meta);
@@ -564,8 +561,8 @@ GNUNET_PSEUDONYM_rank (const struct GNUNET_CONFIGURATION_Handle *cfg,
564 */ 561 */
565void 562void
566GNUNET_PSEUDONYM_add (const struct GNUNET_CONFIGURATION_Handle *cfg, 563GNUNET_PSEUDONYM_add (const struct GNUNET_CONFIGURATION_Handle *cfg,
567 const GNUNET_HashCode * id, 564 const GNUNET_HashCode * id,
568 const struct GNUNET_CONTAINER_MetaData *meta) 565 const struct GNUNET_CONTAINER_MetaData *meta)
569{ 566{
570 char *name; 567 char *name;
571 int32_t ranking; 568 int32_t ranking;
@@ -579,16 +576,16 @@ GNUNET_PSEUDONYM_add (const struct GNUNET_CONFIGURATION_Handle *cfg,
579 576
580 if ((0 == STAT (fn, &sbuf)) && 577 if ((0 == STAT (fn, &sbuf)) &&
581 (GNUNET_OK == read_info (cfg, id, &old, &ranking, &name))) 578 (GNUNET_OK == read_info (cfg, id, &old, &ranking, &name)))
582 { 579 {
583 GNUNET_CONTAINER_meta_data_merge (old, meta); 580 GNUNET_CONTAINER_meta_data_merge (old, meta);
584 write_pseudonym_info (cfg, id, old, ranking, name); 581 write_pseudonym_info (cfg, id, old, ranking, name);
585 GNUNET_CONTAINER_meta_data_destroy (old); 582 GNUNET_CONTAINER_meta_data_destroy (old);
586 GNUNET_free_non_null (name); 583 GNUNET_free_non_null (name);
587 } 584 }
588 else 585 else
589 { 586 {
590 write_pseudonym_info (cfg, id, meta, ranking, NULL); 587 write_pseudonym_info (cfg, id, meta, ranking, NULL);
591 } 588 }
592 GNUNET_free (fn); 589 GNUNET_free (fn);
593 internal_notify (id, meta, ranking); 590 internal_notify (id, meta, ranking);
594} 591}
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c
index 3bdc40143..03dc2ce89 100644
--- a/src/util/resolver_api.c
+++ b/src/util/resolver_api.c
@@ -196,26 +196,26 @@ check_config ()
196#endif 196#endif
197 if (GNUNET_OK != 197 if (GNUNET_OK !=
198 GNUNET_CONFIGURATION_get_value_string (resolver_cfg, "resolver", 198 GNUNET_CONFIGURATION_get_value_string (resolver_cfg, "resolver",
199 "HOSTNAME", &hostname)) 199 "HOSTNAME", &hostname))
200 { 200 {
201 LOG (GNUNET_ERROR_TYPE_ERROR, 201 LOG (GNUNET_ERROR_TYPE_ERROR,
202 _("Must specify `%s' for `%s' in configuration!\n"), "HOSTNAME", 202 _("Must specify `%s' for `%s' in configuration!\n"), "HOSTNAME",
203 "resolver"); 203 "resolver");
204 GNUNET_assert (0); 204 GNUNET_assert (0);
205 } 205 }
206 if ((1 != inet_pton (AF_INET, hostname, &v4)) || 206 if ((1 != inet_pton (AF_INET, hostname, &v4)) ||
207 (1 != inet_pton (AF_INET6, hostname, &v6))) 207 (1 != inet_pton (AF_INET6, hostname, &v6)))
208 {
209 GNUNET_free (hostname);
210 return;
211 }
212 i = 0;
213 while (loopback[i] != NULL)
214 if (0 == strcasecmp (loopback[i++], hostname))
208 { 215 {
209 GNUNET_free (hostname); 216 GNUNET_free (hostname);
210 return; 217 return;
211 } 218 }
212 i = 0;
213 while (loopback[i] != NULL)
214 if (0 == strcasecmp (loopback[i++], hostname))
215 {
216 GNUNET_free (hostname);
217 return;
218 }
219 LOG (GNUNET_ERROR_TYPE_ERROR, 219 LOG (GNUNET_ERROR_TYPE_ERROR,
220 _ 220 _
221 ("Must specify `%s' or numeric IP address for `%s' of `%s' in configuration!\n"), 221 ("Must specify `%s' or numeric IP address for `%s' of `%s' in configuration!\n"),
@@ -249,23 +249,23 @@ GNUNET_RESOLVER_disconnect ()
249 GNUNET_assert (NULL == req_head); 249 GNUNET_assert (NULL == req_head);
250 GNUNET_assert (NULL == req_tail); 250 GNUNET_assert (NULL == req_tail);
251 if (NULL != client) 251 if (NULL != client)
252 { 252 {
253#if DEBUG_RESOLVER 253#if DEBUG_RESOLVER
254 LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from DNS service\n"); 254 LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from DNS service\n");
255#endif 255#endif
256 GNUNET_CLIENT_disconnect (client, GNUNET_NO); 256 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
257 client = NULL; 257 client = NULL;
258 } 258 }
259 if (r_task != GNUNET_SCHEDULER_NO_TASK) 259 if (r_task != GNUNET_SCHEDULER_NO_TASK)
260 { 260 {
261 GNUNET_SCHEDULER_cancel (r_task); 261 GNUNET_SCHEDULER_cancel (r_task);
262 r_task = GNUNET_SCHEDULER_NO_TASK; 262 r_task = GNUNET_SCHEDULER_NO_TASK;
263 } 263 }
264 if (s_task != GNUNET_SCHEDULER_NO_TASK) 264 if (s_task != GNUNET_SCHEDULER_NO_TASK)
265 { 265 {
266 GNUNET_SCHEDULER_cancel (s_task); 266 GNUNET_SCHEDULER_cancel (s_task);
267 s_task = GNUNET_SCHEDULER_NO_TASK; 267 s_task = GNUNET_SCHEDULER_NO_TASK;
268 } 268 }
269} 269}
270 270
271 271
@@ -286,35 +286,35 @@ no_resolve (const struct sockaddr *sa, socklen_t salen)
286 if (salen < sizeof (struct sockaddr)) 286 if (salen < sizeof (struct sockaddr))
287 return NULL; 287 return NULL;
288 switch (sa->sa_family) 288 switch (sa->sa_family)
289 {
290 case AF_INET:
291 if (salen != sizeof (struct sockaddr_in))
292 return NULL;
293 if (NULL ==
294 inet_ntop (AF_INET, &((struct sockaddr_in *) sa)->sin_addr, inet4,
295 INET_ADDRSTRLEN))
289 { 296 {
290 case AF_INET: 297 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
291 if (salen != sizeof (struct sockaddr_in)) 298 return NULL;
292 return NULL;
293 if (NULL ==
294 inet_ntop (AF_INET, &((struct sockaddr_in *) sa)->sin_addr, inet4,
295 INET_ADDRSTRLEN))
296 {
297 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
298 return NULL;
299 }
300 ret = GNUNET_strdup (inet4);
301 break;
302 case AF_INET6:
303 if (salen != sizeof (struct sockaddr_in6))
304 return NULL;
305 if (NULL ==
306 inet_ntop (AF_INET6, &((struct sockaddr_in6 *) sa)->sin6_addr,
307 inet6, INET6_ADDRSTRLEN))
308 {
309 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
310 return NULL;
311 }
312 ret = GNUNET_strdup (inet6);
313 break;
314 default:
315 ret = NULL;
316 break;
317 } 299 }
300 ret = GNUNET_strdup (inet4);
301 break;
302 case AF_INET6:
303 if (salen != sizeof (struct sockaddr_in6))
304 return NULL;
305 if (NULL ==
306 inet_ntop (AF_INET6, &((struct sockaddr_in6 *) sa)->sin6_addr, inet6,
307 INET6_ADDRSTRLEN))
308 {
309 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
310 return NULL;
311 }
312 ret = GNUNET_strdup (inet6);
313 break;
314 default:
315 ret = NULL;
316 break;
317 }
318 return ret; 318 return ret;
319} 319}
320 320
@@ -322,13 +322,15 @@ no_resolve (const struct sockaddr *sa, socklen_t salen)
322/** 322/**
323 * Adjust exponential back-off and reconnect to the service. 323 * Adjust exponential back-off and reconnect to the service.
324 */ 324 */
325static void reconnect (); 325static void
326reconnect ();
326 327
327 328
328/** 329/**
329 * Process pending requests to the resolver. 330 * Process pending requests to the resolver.
330 */ 331 */
331static void process_requests (); 332static void
333process_requests ();
332 334
333 335
334/** 336/**
@@ -350,122 +352,120 @@ handle_response (void *cls, const struct GNUNET_MessageHeader *msg)
350 LOG (GNUNET_ERROR_TYPE_DEBUG, "Receiving response from DNS service\n"); 352 LOG (GNUNET_ERROR_TYPE_DEBUG, "Receiving response from DNS service\n");
351#endif 353#endif
352 if (msg == NULL) 354 if (msg == NULL)
355 {
356 if (NULL != rh->name_callback)
357 LOG (GNUNET_ERROR_TYPE_INFO,
358 _("Timeout trying to resolve IP address `%s'.\n"),
359 GNUNET_a2s ((const void *) &rh[1], rh->data_len));
360 else
361 LOG (GNUNET_ERROR_TYPE_INFO,
362 _("Timeout trying to resolve hostname `%s'.\n"),
363 (const char *) &rh[1]);
364 /* check if request was canceled */
365 if (rh->was_transmitted != GNUNET_SYSERR)
353 { 366 {
354 if (NULL != rh->name_callback) 367 if (NULL != rh->name_callback)
355 LOG (GNUNET_ERROR_TYPE_INFO, 368 {
356 _("Timeout trying to resolve IP address `%s'.\n"), 369 /* no reverse lookup was successful, return ip as string */
357 GNUNET_a2s ((const void *) &rh[1], rh->data_len)); 370 if (rh->received_response == GNUNET_NO)
358 else 371 rh->name_callback (rh->cls,
359 LOG (GNUNET_ERROR_TYPE_INFO, 372 no_resolve ((const struct sockaddr *) &rh[1],
360 _("Timeout trying to resolve hostname `%s'.\n"), 373 rh->data_len));
361 (const char *) &rh[1]); 374 /* at least one reverse lookup was successful */
362 /* check if request was canceled */ 375 else
363 if (rh->was_transmitted != GNUNET_SYSERR) 376 rh->name_callback (rh->cls, NULL);
364 { 377 }
365 if (NULL != rh->name_callback) 378 if (NULL != rh->addr_callback)
366 { 379 rh->addr_callback (rh->cls, NULL, 0);
367 /* no reverse lookup was successful, return ip as string */
368 if (rh->received_response == GNUNET_NO)
369 rh->name_callback (rh->cls,
370 no_resolve ((const struct sockaddr *)
371 &rh[1], rh->data_len));
372 /* at least one reverse lookup was successful */
373 else
374 rh->name_callback (rh->cls, NULL);
375 }
376 if (NULL != rh->addr_callback)
377 rh->addr_callback (rh->cls, NULL, 0);
378 }
379 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
380 GNUNET_free (rh);
381 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
382 client = NULL;
383 reconnect ();
384 return;
385 } 380 }
381 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
382 GNUNET_free (rh);
383 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
384 client = NULL;
385 reconnect ();
386 return;
387 }
386 if (GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE != ntohs (msg->type)) 388 if (GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE != ntohs (msg->type))
387 { 389 {
388 GNUNET_break (0); 390 GNUNET_break (0);
389 GNUNET_CLIENT_disconnect (client, GNUNET_NO); 391 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
390 client = NULL; 392 client = NULL;
391 reconnect (); 393 reconnect ();
392 return; 394 return;
393 } 395 }
394 size = ntohs (msg->size); 396 size = ntohs (msg->size);
395 /* message contains not data, just header */ 397 /* message contains not data, just header */
396 if (size == sizeof (struct GNUNET_MessageHeader)) 398 if (size == sizeof (struct GNUNET_MessageHeader))
399 {
400 /* check if request was canceled */
401 if (rh->was_transmitted != GNUNET_SYSERR)
402 {
403 if (NULL != rh->name_callback)
404 rh->name_callback (rh->cls, NULL);
405 if (NULL != rh->addr_callback)
406 rh->addr_callback (rh->cls, NULL, 0);
407 }
408 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
409 GNUNET_free (rh);
410 process_requests ();
411 return;
412 }
413 /* return reverse lookup results to caller */
414 if (NULL != rh->name_callback)
415 {
416 hostname = (const char *) &msg[1];
417 if (hostname[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0')
397 { 418 {
398 /* check if request was canceled */ 419 GNUNET_break (0);
399 if (rh->was_transmitted != GNUNET_SYSERR) 420 if (rh->was_transmitted != GNUNET_SYSERR)
400 { 421 rh->name_callback (rh->cls, NULL);
401 if (NULL != rh->name_callback)
402 rh->name_callback (rh->cls, NULL);
403 if (NULL != rh->addr_callback)
404 rh->addr_callback (rh->cls, NULL, 0);
405 }
406 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); 422 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
407 GNUNET_free (rh); 423 GNUNET_free (rh);
408 process_requests (); 424 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
425 client = NULL;
426 reconnect ();
409 return; 427 return;
410 } 428 }
411 /* return reverse lookup results to caller */
412 if (NULL != rh->name_callback)
413 {
414 hostname = (const char *) &msg[1];
415 if (hostname[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0')
416 {
417 GNUNET_break (0);
418 if (rh->was_transmitted != GNUNET_SYSERR)
419 rh->name_callback (rh->cls, NULL);
420 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
421 GNUNET_free (rh);
422 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
423 client = NULL;
424 reconnect ();
425 return;
426 }
427#if DEBUG_RESOLVER 429#if DEBUG_RESOLVER
428 LOG (GNUNET_ERROR_TYPE_DEBUG, _("Resolver returns `%s' for IP `%s'.\n"), 430 LOG (GNUNET_ERROR_TYPE_DEBUG, _("Resolver returns `%s' for IP `%s'.\n"),
429 hostname, GNUNET_a2s ((const void *) &rh[1], rh->data_len)); 431 hostname, GNUNET_a2s ((const void *) &rh[1], rh->data_len));
430#endif 432#endif
431 if (rh->was_transmitted != GNUNET_SYSERR) 433 if (rh->was_transmitted != GNUNET_SYSERR)
432 rh->name_callback (rh->cls, hostname); 434 rh->name_callback (rh->cls, hostname);
433 rh->received_response = GNUNET_YES; 435 rh->received_response = GNUNET_YES;
434 GNUNET_CLIENT_receive (client, &handle_response, rh, 436 GNUNET_CLIENT_receive (client, &handle_response, rh,
435 GNUNET_TIME_absolute_get_remaining 437 GNUNET_TIME_absolute_get_remaining (rh->timeout));
436 (rh->timeout)); 438 }
437 }
438 /* return lookup results to caller */ 439 /* return lookup results to caller */
439 if (NULL != rh->addr_callback) 440 if (NULL != rh->addr_callback)
441 {
442 sa = (const struct sockaddr *) &msg[1];
443 salen = size - sizeof (struct GNUNET_MessageHeader);
444 if (salen < sizeof (struct sockaddr))
440 { 445 {
441 sa = (const struct sockaddr *) &msg[1]; 446 GNUNET_break (0);
442 salen = size - sizeof (struct GNUNET_MessageHeader); 447 if (rh->was_transmitted != GNUNET_SYSERR)
443 if (salen < sizeof (struct sockaddr)) 448 rh->addr_callback (rh->cls, NULL, 0);
444 { 449 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
445 GNUNET_break (0); 450 GNUNET_free (rh);
446 if (rh->was_transmitted != GNUNET_SYSERR) 451 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
447 rh->addr_callback (rh->cls, NULL, 0); 452 client = NULL;
448 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); 453 reconnect ();
449 GNUNET_free (rh); 454 return;
450 GNUNET_CLIENT_disconnect (client, GNUNET_NO); 455 }
451 client = NULL;
452 reconnect ();
453 return;
454 }
455#if DEBUG_RESOLVER 456#if DEBUG_RESOLVER
456 { 457 {
457 char *ips = no_resolve (sa, salen); 458 char *ips = no_resolve (sa, salen);
458 459
459 LOG (GNUNET_ERROR_TYPE_DEBUG, "Resolver returns `%s' for `%s'.\n", 460 LOG (GNUNET_ERROR_TYPE_DEBUG, "Resolver returns `%s' for `%s'.\n", ips,
460 ips, (const char *) &rh[1]); 461 (const char *) &rh[1]);
461 GNUNET_free (ips); 462 GNUNET_free (ips);
462 }
463#endif
464 rh->addr_callback (rh->cls, sa, salen);
465 GNUNET_CLIENT_receive (client, &handle_response, rh,
466 GNUNET_TIME_absolute_get_remaining
467 (rh->timeout));
468 } 463 }
464#endif
465 rh->addr_callback (rh->cls, sa, salen);
466 GNUNET_CLIENT_receive (client, &handle_response, rh,
467 GNUNET_TIME_absolute_get_remaining (rh->timeout));
468 }
469} 469}
470 470
471 471
@@ -498,27 +498,26 @@ numeric_resolution (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
498 hostname = (const char *) &rh[1]; 498 hostname = (const char *) &rh[1];
499 if (((rh->domain == AF_UNSPEC) || (rh->domain == AF_INET)) && 499 if (((rh->domain == AF_UNSPEC) || (rh->domain == AF_INET)) &&
500 (1 == inet_pton (AF_INET, hostname, &v4.sin_addr))) 500 (1 == inet_pton (AF_INET, hostname, &v4.sin_addr)))
501 {
502 rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4));
503 if ((rh->domain == AF_UNSPEC) &&
504 (1 == inet_pton (AF_INET6, hostname, &v6.sin6_addr)))
501 { 505 {
502 rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4)); 506 /* this can happen on some systems IF "hostname" is "localhost" */
503 if ((rh->domain == AF_UNSPEC) && 507 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
504 (1 == inet_pton (AF_INET6, hostname, &v6.sin6_addr)))
505 {
506 /* this can happen on some systems IF "hostname" is "localhost" */
507 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6,
508 sizeof (v6));
509 }
510 rh->addr_callback (rh->cls, NULL, 0);
511 GNUNET_free (rh);
512 return;
513 } 508 }
509 rh->addr_callback (rh->cls, NULL, 0);
510 GNUNET_free (rh);
511 return;
512 }
514 if (((rh->domain == AF_UNSPEC) || (rh->domain == AF_INET6)) && 513 if (((rh->domain == AF_UNSPEC) || (rh->domain == AF_INET6)) &&
515 (1 == inet_pton (AF_INET6, hostname, &v6.sin6_addr))) 514 (1 == inet_pton (AF_INET6, hostname, &v6.sin6_addr)))
516 { 515 {
517 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6)); 516 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
518 rh->addr_callback (rh->cls, NULL, 0); 517 rh->addr_callback (rh->cls, NULL, 0);
519 GNUNET_free (rh); 518 GNUNET_free (rh);
520 return; 519 return;
521 } 520 }
522 /* why are we here? this task should not have been scheduled! */ 521 /* why are we here? this task should not have been scheduled! */
523 GNUNET_assert (0); 522 GNUNET_assert (0);
524 GNUNET_free (rh); 523 GNUNET_free (rh);
@@ -553,21 +552,21 @@ loopback_resolution (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
553#endif 552#endif
554 v6.sin6_addr = in6addr_loopback; 553 v6.sin6_addr = in6addr_loopback;
555 switch (rh->domain) 554 switch (rh->domain)
556 { 555 {
557 case AF_INET: 556 case AF_INET:
558 rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4)); 557 rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4));
559 break; 558 break;
560 case AF_INET6: 559 case AF_INET6:
561 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6)); 560 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
562 break; 561 break;
563 case AF_UNSPEC: 562 case AF_UNSPEC:
564 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6)); 563 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
565 rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4)); 564 rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4));
566 break; 565 break;
567 default: 566 default:
568 GNUNET_break (0); 567 GNUNET_break (0);
569 break; 568 break;
570 } 569 }
571 rh->addr_callback (rh->cls, NULL, 0); 570 rh->addr_callback (rh->cls, NULL, 0);
572 GNUNET_free (rh); 571 GNUNET_free (rh);
573} 572}
@@ -595,25 +594,25 @@ process_requests ()
595 struct GNUNET_RESOLVER_RequestHandle *rh; 594 struct GNUNET_RESOLVER_RequestHandle *rh;
596 595
597 if (NULL == client) 596 if (NULL == client)
598 { 597 {
599 reconnect (); 598 reconnect ();
600 return; 599 return;
601 } 600 }
602 rh = req_head; 601 rh = req_head;
603 if (NULL == rh) 602 if (NULL == rh)
604 { 603 {
605 /* nothing to do, release socket really soon if there is nothing 604 /* nothing to do, release socket really soon if there is nothing
606 * else happening... */ 605 * else happening... */
607 s_task = 606 s_task =
608 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, 607 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
609 &shutdown_task, NULL); 608 &shutdown_task, NULL);
610 return; 609 return;
611 } 610 }
612 if (GNUNET_YES == rh->was_transmitted) 611 if (GNUNET_YES == rh->was_transmitted)
613 return; /* waiting for reply */ 612 return; /* waiting for reply */
614 msg = (struct GNUNET_RESOLVER_GetMessage *) buf; 613 msg = (struct GNUNET_RESOLVER_GetMessage *) buf;
615 msg->header.size = 614 msg->header.size =
616 htons (sizeof (struct GNUNET_RESOLVER_GetMessage) + rh->data_len); 615 htons (sizeof (struct GNUNET_RESOLVER_GetMessage) + rh->data_len);
617 msg->header.type = htons (GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST); 616 msg->header.type = htons (GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST);
618 msg->direction = htonl (rh->direction); 617 msg->direction = htonl (rh->direction);
619 msg->domain = htonl (rh->domain); 618 msg->domain = htonl (rh->domain);
@@ -624,15 +623,15 @@ process_requests ()
624#endif 623#endif
625 if (GNUNET_OK != 624 if (GNUNET_OK !=
626 GNUNET_CLIENT_transmit_and_get_response (client, &msg->header, 625 GNUNET_CLIENT_transmit_and_get_response (client, &msg->header,
627 GNUNET_TIME_absolute_get_remaining 626 GNUNET_TIME_absolute_get_remaining
628 (rh->timeout), GNUNET_YES, 627 (rh->timeout), GNUNET_YES,
629 &handle_response, rh)) 628 &handle_response, rh))
630 { 629 {
631 GNUNET_CLIENT_disconnect (client, GNUNET_NO); 630 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
632 client = NULL; 631 client = NULL;
633 reconnect (); 632 reconnect ();
634 return; 633 return;
635 } 634 }
636 rh->was_transmitted = GNUNET_YES; 635 rh->was_transmitted = GNUNET_YES;
637} 636}
638 637
@@ -648,7 +647,7 @@ reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
648{ 647{
649 r_task = GNUNET_SCHEDULER_NO_TASK; 648 r_task = GNUNET_SCHEDULER_NO_TASK;
650 if (NULL == req_head) 649 if (NULL == req_head)
651 return; /* no work pending */ 650 return; /* no work pending */
652 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 651 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
653 return; 652 return;
654#if DEBUG_RESOLVER 653#if DEBUG_RESOLVER
@@ -656,12 +655,11 @@ reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
656#endif 655#endif
657 client = GNUNET_CLIENT_connect ("resolver", resolver_cfg); 656 client = GNUNET_CLIENT_connect ("resolver", resolver_cfg);
658 if (NULL == client) 657 if (NULL == client)
659 { 658 {
660 LOG (GNUNET_ERROR_TYPE_DEBUG, 659 LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect, will try again later\n");
661 "Failed to connect, will try again later\n"); 660 reconnect ();
662 reconnect (); 661 return;
663 return; 662 }
664 }
665 process_requests (); 663 process_requests ();
666} 664}
667 665
@@ -678,26 +676,26 @@ reconnect ()
678 return; 676 return;
679 GNUNET_assert (NULL == client); 677 GNUNET_assert (NULL == client);
680 if (NULL != (rh = req_head)) 678 if (NULL != (rh = req_head))
679 {
680 switch (rh->was_transmitted)
681 { 681 {
682 switch (rh->was_transmitted) 682 case GNUNET_NO:
683 { 683 /* nothing more to do */
684 case GNUNET_NO: 684 break;
685 /* nothing more to do */ 685 case GNUNET_YES:
686 break; 686 /* disconnected, transmit again! */
687 case GNUNET_YES: 687 rh->was_transmitted = GNUNET_NO;
688 /* disconnected, transmit again! */ 688 break;
689 rh->was_transmitted = GNUNET_NO; 689 case GNUNET_SYSERR:
690 break; 690 /* request was cancelled, remove entirely */
691 case GNUNET_SYSERR: 691 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
692 /* request was cancelled, remove entirely */ 692 GNUNET_free (rh);
693 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); 693 break;
694 GNUNET_free (rh); 694 default:
695 break; 695 GNUNET_assert (0);
696 default: 696 break;
697 GNUNET_assert (0);
698 break;
699 }
700 } 697 }
698 }
701#if DEBUG_RESOLVER 699#if DEBUG_RESOLVER
702 LOG (GNUNET_ERROR_TYPE_DEBUG, 700 LOG (GNUNET_ERROR_TYPE_DEBUG,
703 "Will try to connect to DNS service in %llu ms\n", 701 "Will try to connect to DNS service in %llu ms\n",
@@ -721,9 +719,9 @@ reconnect ()
721 */ 719 */
722struct GNUNET_RESOLVER_RequestHandle * 720struct GNUNET_RESOLVER_RequestHandle *
723GNUNET_RESOLVER_ip_get (const char *hostname, int domain, 721GNUNET_RESOLVER_ip_get (const char *hostname, int domain,
724 struct GNUNET_TIME_Relative timeout, 722 struct GNUNET_TIME_Relative timeout,
725 GNUNET_RESOLVER_AddressCallback callback, 723 GNUNET_RESOLVER_AddressCallback callback,
726 void *callback_cls) 724 void *callback_cls)
727{ 725{
728 struct GNUNET_RESOLVER_RequestHandle *rh; 726 struct GNUNET_RESOLVER_RequestHandle *rh;
729 size_t slen; 727 size_t slen;
@@ -734,10 +732,10 @@ GNUNET_RESOLVER_ip_get (const char *hostname, int domain,
734 slen = strlen (hostname) + 1; 732 slen = strlen (hostname) + 1;
735 if (slen + sizeof (struct GNUNET_RESOLVER_GetMessage) >= 733 if (slen + sizeof (struct GNUNET_RESOLVER_GetMessage) >=
736 GNUNET_SERVER_MAX_MESSAGE_SIZE) 734 GNUNET_SERVER_MAX_MESSAGE_SIZE)
737 { 735 {
738 GNUNET_break (0); 736 GNUNET_break (0);
739 return NULL; 737 return NULL;
740 } 738 }
741 rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen); 739 rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen);
742 rh->domain = domain; 740 rh->domain = domain;
743 rh->addr_callback = callback; 741 rh->addr_callback = callback;
@@ -751,25 +749,25 @@ GNUNET_RESOLVER_ip_get (const char *hostname, int domain,
751 ((domain == AF_INET) || (domain == AF_UNSPEC))) || 749 ((domain == AF_INET) || (domain == AF_UNSPEC))) ||
752 ((1 == inet_pton (AF_INET6, hostname, &v6)) && 750 ((1 == inet_pton (AF_INET6, hostname, &v6)) &&
753 ((domain == AF_INET6) || (domain == AF_UNSPEC)))) 751 ((domain == AF_INET6) || (domain == AF_UNSPEC))))
754 { 752 {
755 rh->task = GNUNET_SCHEDULER_add_now (&numeric_resolution, rh); 753 rh->task = GNUNET_SCHEDULER_add_now (&numeric_resolution, rh);
756 return rh; 754 return rh;
757 } 755 }
758 /* then, check if this is a loopback address */ 756 /* then, check if this is a loopback address */
759 i = 0; 757 i = 0;
760 while (loopback[i] != NULL) 758 while (loopback[i] != NULL)
761 if (0 == strcasecmp (loopback[i++], hostname)) 759 if (0 == strcasecmp (loopback[i++], hostname))
762 { 760 {
763 rh->task = GNUNET_SCHEDULER_add_now (&loopback_resolution, rh); 761 rh->task = GNUNET_SCHEDULER_add_now (&loopback_resolution, rh);
764 return rh; 762 return rh;
765 } 763 }
766 GNUNET_CONTAINER_DLL_insert_tail (req_head, req_tail, rh); 764 GNUNET_CONTAINER_DLL_insert_tail (req_head, req_tail, rh);
767 rh->was_queued = GNUNET_YES; 765 rh->was_queued = GNUNET_YES;
768 if (s_task != GNUNET_SCHEDULER_NO_TASK) 766 if (s_task != GNUNET_SCHEDULER_NO_TASK)
769 { 767 {
770 GNUNET_SCHEDULER_cancel (s_task); 768 GNUNET_SCHEDULER_cancel (s_task);
771 s_task = GNUNET_SCHEDULER_NO_TASK; 769 s_task = GNUNET_SCHEDULER_NO_TASK;
772 } 770 }
773 process_requests (); 771 process_requests ();
774 return rh; 772 return rh;
775} 773}
@@ -793,10 +791,10 @@ numeric_reverse (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
793 LOG (GNUNET_ERROR_TYPE_DEBUG, _("Resolver returns `%s'.\n"), result); 791 LOG (GNUNET_ERROR_TYPE_DEBUG, _("Resolver returns `%s'.\n"), result);
794#endif 792#endif
795 if (result != NULL) 793 if (result != NULL)
796 { 794 {
797 rh->name_callback (rh->cls, result); 795 rh->name_callback (rh->cls, result);
798 GNUNET_free (result); 796 GNUNET_free (result);
799 } 797 }
800 rh->name_callback (rh->cls, NULL); 798 rh->name_callback (rh->cls, NULL);
801 GNUNET_free (rh); 799 GNUNET_free (rh);
802} 800}
@@ -816,10 +814,10 @@ numeric_reverse (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
816 */ 814 */
817struct GNUNET_RESOLVER_RequestHandle * 815struct GNUNET_RESOLVER_RequestHandle *
818GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa, socklen_t salen, 816GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa, socklen_t salen,
819 int do_resolve, 817 int do_resolve,
820 struct GNUNET_TIME_Relative timeout, 818 struct GNUNET_TIME_Relative timeout,
821 GNUNET_RESOLVER_HostnameCallback callback, 819 GNUNET_RESOLVER_HostnameCallback callback,
822 void *cls) 820 void *cls)
823{ 821{
824 struct GNUNET_RESOLVER_RequestHandle *rh; 822 struct GNUNET_RESOLVER_RequestHandle *rh;
825 823
@@ -833,24 +831,24 @@ GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa, socklen_t salen,
833 rh->direction = GNUNET_YES; 831 rh->direction = GNUNET_YES;
834 rh->received_response = GNUNET_NO; 832 rh->received_response = GNUNET_NO;
835 if (GNUNET_NO == do_resolve) 833 if (GNUNET_NO == do_resolve)
836 { 834 {
837 rh->task = GNUNET_SCHEDULER_add_now (&numeric_reverse, rh); 835 rh->task = GNUNET_SCHEDULER_add_now (&numeric_reverse, rh);
838 return rh; 836 return rh;
839 } 837 }
840 if (salen + sizeof (struct GNUNET_RESOLVER_GetMessage) >= 838 if (salen + sizeof (struct GNUNET_RESOLVER_GetMessage) >=
841 GNUNET_SERVER_MAX_MESSAGE_SIZE) 839 GNUNET_SERVER_MAX_MESSAGE_SIZE)
842 { 840 {
843 GNUNET_break (0); 841 GNUNET_break (0);
844 GNUNET_free (rh); 842 GNUNET_free (rh);
845 return NULL; 843 return NULL;
846 } 844 }
847 GNUNET_CONTAINER_DLL_insert_tail (req_head, req_tail, rh); 845 GNUNET_CONTAINER_DLL_insert_tail (req_head, req_tail, rh);
848 rh->was_queued = GNUNET_YES; 846 rh->was_queued = GNUNET_YES;
849 if (s_task != GNUNET_SCHEDULER_NO_TASK) 847 if (s_task != GNUNET_SCHEDULER_NO_TASK)
850 { 848 {
851 GNUNET_SCHEDULER_cancel (s_task); 849 GNUNET_SCHEDULER_cancel (s_task);
852 s_task = GNUNET_SCHEDULER_NO_TASK; 850 s_task = GNUNET_SCHEDULER_NO_TASK;
853 } 851 }
854 process_requests (); 852 process_requests ();
855 return rh; 853 return rh;
856} 854}
@@ -868,21 +866,21 @@ GNUNET_RESOLVER_local_fqdn_get ()
868 char hostname[GNUNET_OS_get_hostname_max_length () + 1]; 866 char hostname[GNUNET_OS_get_hostname_max_length () + 1];
869 867
870 if (0 != gethostname (hostname, sizeof (hostname) - 1)) 868 if (0 != gethostname (hostname, sizeof (hostname) - 1))
871 { 869 {
872 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 870 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
873 "gethostname"); 871 "gethostname");
874 return NULL; 872 return NULL;
875 } 873 }
876#if DEBUG_RESOLVER 874#if DEBUG_RESOLVER
877 LOG (GNUNET_ERROR_TYPE_DEBUG, _("Resolving our FQDN `%s'\n"), hostname); 875 LOG (GNUNET_ERROR_TYPE_DEBUG, _("Resolving our FQDN `%s'\n"), hostname);
878#endif 876#endif
879 host = gethostbyname (hostname); 877 host = gethostbyname (hostname);
880 if (NULL == host) 878 if (NULL == host)
881 { 879 {
882 LOG (GNUNET_ERROR_TYPE_ERROR, _("Could not resolve our FQDN : %s\n"), 880 LOG (GNUNET_ERROR_TYPE_ERROR, _("Could not resolve our FQDN : %s\n"),
883 hstrerror (h_errno)); 881 hstrerror (h_errno));
884 return NULL; 882 return NULL;
885 } 883 }
886 return GNUNET_strdup (host->h_name); 884 return GNUNET_strdup (host->h_name);
887} 885}
888 886
@@ -898,18 +896,18 @@ GNUNET_RESOLVER_local_fqdn_get ()
898 */ 896 */
899struct GNUNET_RESOLVER_RequestHandle * 897struct GNUNET_RESOLVER_RequestHandle *
900GNUNET_RESOLVER_hostname_resolve (int domain, 898GNUNET_RESOLVER_hostname_resolve (int domain,
901 struct GNUNET_TIME_Relative timeout, 899 struct GNUNET_TIME_Relative timeout,
902 GNUNET_RESOLVER_AddressCallback callback, 900 GNUNET_RESOLVER_AddressCallback callback,
903 void *cls) 901 void *cls)
904{ 902{
905 char hostname[GNUNET_OS_get_hostname_max_length () + 1]; 903 char hostname[GNUNET_OS_get_hostname_max_length () + 1];
906 904
907 if (0 != gethostname (hostname, sizeof (hostname) - 1)) 905 if (0 != gethostname (hostname, sizeof (hostname) - 1))
908 { 906 {
909 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 907 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
910 "gethostname"); 908 "gethostname");
911 return NULL; 909 return NULL;
912 } 910 }
913#if DEBUG_RESOLVER 911#if DEBUG_RESOLVER
914 LOG (GNUNET_ERROR_TYPE_DEBUG, _("Resolving our hostname `%s'\n"), hostname); 912 LOG (GNUNET_ERROR_TYPE_DEBUG, _("Resolving our hostname `%s'\n"), hostname);
915#endif 913#endif
@@ -929,19 +927,19 @@ void
929GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *rh) 927GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *rh)
930{ 928{
931 if (rh->task != GNUNET_SCHEDULER_NO_TASK) 929 if (rh->task != GNUNET_SCHEDULER_NO_TASK)
932 { 930 {
933 GNUNET_SCHEDULER_cancel (rh->task); 931 GNUNET_SCHEDULER_cancel (rh->task);
934 rh->task = GNUNET_SCHEDULER_NO_TASK; 932 rh->task = GNUNET_SCHEDULER_NO_TASK;
935 } 933 }
936 if (rh->was_transmitted == GNUNET_NO) 934 if (rh->was_transmitted == GNUNET_NO)
937 { 935 {
938 if (rh->was_queued == GNUNET_YES) 936 if (rh->was_queued == GNUNET_YES)
939 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); 937 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
940 GNUNET_free (rh); 938 GNUNET_free (rh);
941 return; 939 return;
942 } 940 }
943 GNUNET_assert (rh->was_transmitted == GNUNET_YES); 941 GNUNET_assert (rh->was_transmitted == GNUNET_YES);
944 rh->was_transmitted = GNUNET_SYSERR; /* mark as cancelled */ 942 rh->was_transmitted = GNUNET_SYSERR; /* mark as cancelled */
945} 943}
946 944
947 945
diff --git a/src/util/scheduler.c b/src/util/scheduler.c
index 7c5077fab..0c4374471 100644
--- a/src/util/scheduler.c
+++ b/src/util/scheduler.c
@@ -269,7 +269,7 @@ static void *scheduler_select_cls;
269 */ 269 */
270void 270void
271GNUNET_SCHEDULER_set_select (GNUNET_SCHEDULER_select new_select, 271GNUNET_SCHEDULER_set_select (GNUNET_SCHEDULER_select new_select,
272 void *new_select_cls) 272 void *new_select_cls)
273{ 273{
274 scheduler_select = new_select; 274 scheduler_select = new_select;
275 scheduler_select_cls = new_select_cls; 275 scheduler_select_cls = new_select_cls;
@@ -288,7 +288,7 @@ check_priority (enum GNUNET_SCHEDULER_Priority p)
288 if ((p >= 0) && (p < GNUNET_SCHEDULER_PRIORITY_COUNT)) 288 if ((p >= 0) && (p < GNUNET_SCHEDULER_PRIORITY_COUNT))
289 return p; 289 return p;
290 GNUNET_assert (0); 290 GNUNET_assert (0);
291 return 0; /* make compiler happy */ 291 return 0; /* make compiler happy */
292} 292}
293 293
294 294
@@ -310,37 +310,37 @@ is_pending (GNUNET_SCHEDULER_TaskIdentifier id)
310 310
311 if (id < lowest_pending_id) 311 if (id < lowest_pending_id)
312 return GNUNET_NO; 312 return GNUNET_NO;
313 min = -1; /* maximum value */ 313 min = -1; /* maximum value */
314 pos = pending; 314 pos = pending;
315 while (pos != NULL) 315 while (pos != NULL)
316 { 316 {
317 if (pos->id == id) 317 if (pos->id == id)
318 return GNUNET_YES; 318 return GNUNET_YES;
319 if (pos->id < min) 319 if (pos->id < min)
320 min = pos->id; 320 min = pos->id;
321 pos = pos->next; 321 pos = pos->next;
322 } 322 }
323 pos = pending_timeout; 323 pos = pending_timeout;
324 while (pos != NULL) 324 while (pos != NULL)
325 {
326 if (pos->id == id)
327 return GNUNET_YES;
328 if (pos->id < min)
329 min = pos->id;
330 pos = pos->next;
331 }
332 for (p = 0; p < GNUNET_SCHEDULER_PRIORITY_COUNT; p++)
333 {
334 pos = ready[p];
335 while (pos != NULL)
325 { 336 {
326 if (pos->id == id) 337 if (pos->id == id)
327 return GNUNET_YES; 338 return GNUNET_YES;
328 if (pos->id < min) 339 if (pos->id < min)
329 min = pos->id; 340 min = pos->id;
330 pos = pos->next; 341 pos = pos->next;
331 } 342 }
332 for (p = 0; p < GNUNET_SCHEDULER_PRIORITY_COUNT; p++) 343 }
333 {
334 pos = ready[p];
335 while (pos != NULL)
336 {
337 if (pos->id == id)
338 return GNUNET_YES;
339 if (pos->id < min)
340 min = pos->id;
341 pos = pos->next;
342 }
343 }
344 lowest_pending_id = min; 344 lowest_pending_id = min;
345 return GNUNET_NO; 345 return GNUNET_NO;
346} 346}
@@ -355,7 +355,7 @@ is_pending (GNUNET_SCHEDULER_TaskIdentifier id)
355 */ 355 */
356static void 356static void
357update_sets (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws, 357update_sets (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws,
358 struct GNUNET_TIME_Relative *timeout) 358 struct GNUNET_TIME_Relative *timeout)
359{ 359{
360 struct Task *pos; 360 struct Task *pos;
361 struct GNUNET_TIME_Absolute now; 361 struct GNUNET_TIME_Absolute now;
@@ -364,40 +364,40 @@ update_sets (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws,
364 now = GNUNET_TIME_absolute_get (); 364 now = GNUNET_TIME_absolute_get ();
365 pos = pending_timeout; 365 pos = pending_timeout;
366 if (pos != NULL) 366 if (pos != NULL)
367 { 367 {
368 to = GNUNET_TIME_absolute_get_difference (now, pos->timeout); 368 to = GNUNET_TIME_absolute_get_difference (now, pos->timeout);
369 if (timeout->rel_value > to.rel_value) 369 if (timeout->rel_value > to.rel_value)
370 *timeout = to; 370 *timeout = to;
371 if (pos->reason != 0) 371 if (pos->reason != 0)
372 *timeout = GNUNET_TIME_UNIT_ZERO; 372 *timeout = GNUNET_TIME_UNIT_ZERO;
373 } 373 }
374 pos = pending; 374 pos = pending;
375 while (pos != NULL) 375 while (pos != NULL)
376 {
377 if ((pos->prereq_id != GNUNET_SCHEDULER_NO_TASK) &&
378 (GNUNET_YES == is_pending (pos->prereq_id)))
376 { 379 {
377 if ((pos->prereq_id != GNUNET_SCHEDULER_NO_TASK) &&
378 (GNUNET_YES == is_pending (pos->prereq_id)))
379 {
380 pos = pos->next;
381 continue;
382 }
383 if (pos->timeout.abs_value != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value)
384 {
385 to = GNUNET_TIME_absolute_get_difference (now, pos->timeout);
386 if (timeout->rel_value > to.rel_value)
387 *timeout = to;
388 }
389 if (pos->read_fd != -1)
390 GNUNET_NETWORK_fdset_set_native (rs, pos->read_fd);
391 if (pos->write_fd != -1)
392 GNUNET_NETWORK_fdset_set_native (ws, pos->write_fd);
393 if (pos->read_set != NULL)
394 GNUNET_NETWORK_fdset_add (rs, pos->read_set);
395 if (pos->write_set != NULL)
396 GNUNET_NETWORK_fdset_add (ws, pos->write_set);
397 if (pos->reason != 0)
398 *timeout = GNUNET_TIME_UNIT_ZERO;
399 pos = pos->next; 380 pos = pos->next;
381 continue;
382 }
383 if (pos->timeout.abs_value != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value)
384 {
385 to = GNUNET_TIME_absolute_get_difference (now, pos->timeout);
386 if (timeout->rel_value > to.rel_value)
387 *timeout = to;
400 } 388 }
389 if (pos->read_fd != -1)
390 GNUNET_NETWORK_fdset_set_native (rs, pos->read_fd);
391 if (pos->write_fd != -1)
392 GNUNET_NETWORK_fdset_set_native (ws, pos->write_fd);
393 if (pos->read_set != NULL)
394 GNUNET_NETWORK_fdset_add (rs, pos->read_set);
395 if (pos->write_set != NULL)
396 GNUNET_NETWORK_fdset_add (ws, pos->write_set);
397 if (pos->reason != 0)
398 *timeout = GNUNET_TIME_UNIT_ZERO;
399 pos = pos->next;
400 }
401} 401}
402 402
403 403
@@ -412,17 +412,17 @@ update_sets (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws,
412 */ 412 */
413static int 413static int
414set_overlaps (const struct GNUNET_NETWORK_FDSet *ready, 414set_overlaps (const struct GNUNET_NETWORK_FDSet *ready,
415 struct GNUNET_NETWORK_FDSet *want) 415 struct GNUNET_NETWORK_FDSet *want)
416{ 416{
417 if ((NULL == want) || (NULL == ready)) 417 if ((NULL == want) || (NULL == ready))
418 return GNUNET_NO; 418 return GNUNET_NO;
419 if (GNUNET_NETWORK_fdset_overlap (ready, want)) 419 if (GNUNET_NETWORK_fdset_overlap (ready, want))
420 { 420 {
421 /* copy all over (yes, there maybe unrelated bits, 421 /* copy all over (yes, there maybe unrelated bits,
422 * but this should not hurt well-written clients) */ 422 * but this should not hurt well-written clients) */
423 GNUNET_NETWORK_fdset_copy (want, ready); 423 GNUNET_NETWORK_fdset_copy (want, ready);
424 return GNUNET_YES; 424 return GNUNET_YES;
425 } 425 }
426 return GNUNET_NO; 426 return GNUNET_NO;
427} 427}
428 428
@@ -439,8 +439,8 @@ set_overlaps (const struct GNUNET_NETWORK_FDSet *ready,
439 */ 439 */
440static int 440static int
441is_ready (struct Task *task, struct GNUNET_TIME_Absolute now, 441is_ready (struct Task *task, struct GNUNET_TIME_Absolute now,
442 const struct GNUNET_NETWORK_FDSet *rs, 442 const struct GNUNET_NETWORK_FDSet *rs,
443 const struct GNUNET_NETWORK_FDSet *ws) 443 const struct GNUNET_NETWORK_FDSet *ws)
444{ 444{
445 enum GNUNET_SCHEDULER_Reason reason; 445 enum GNUNET_SCHEDULER_Reason reason;
446 446
@@ -449,25 +449,25 @@ is_ready (struct Task *task, struct GNUNET_TIME_Absolute now,
449 reason |= GNUNET_SCHEDULER_REASON_TIMEOUT; 449 reason |= GNUNET_SCHEDULER_REASON_TIMEOUT;
450 if ((0 == (reason & GNUNET_SCHEDULER_REASON_READ_READY)) && 450 if ((0 == (reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
451 (((task->read_fd != -1) && 451 (((task->read_fd != -1) &&
452 (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (rs, task->read_fd))) 452 (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (rs, task->read_fd))) ||
453 || (set_overlaps (rs, task->read_set)))) 453 (set_overlaps (rs, task->read_set))))
454 reason |= GNUNET_SCHEDULER_REASON_READ_READY; 454 reason |= GNUNET_SCHEDULER_REASON_READ_READY;
455 if ((0 == (reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) && 455 if ((0 == (reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) &&
456 (((task->write_fd != -1) && 456 (((task->write_fd != -1) &&
457 (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (ws, task->write_fd))) 457 (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (ws, task->write_fd)))
458 || (set_overlaps (ws, task->write_set)))) 458 || (set_overlaps (ws, task->write_set))))
459 reason |= GNUNET_SCHEDULER_REASON_WRITE_READY; 459 reason |= GNUNET_SCHEDULER_REASON_WRITE_READY;
460 if (reason == 0) 460 if (reason == 0)
461 return GNUNET_NO; /* not ready */ 461 return GNUNET_NO; /* not ready */
462 if (task->prereq_id != GNUNET_SCHEDULER_NO_TASK) 462 if (task->prereq_id != GNUNET_SCHEDULER_NO_TASK)
463 {
464 if (GNUNET_YES == is_pending (task->prereq_id))
463 { 465 {
464 if (GNUNET_YES == is_pending (task->prereq_id)) 466 task->reason = reason;
465 { 467 return GNUNET_NO; /* prereq waiting */
466 task->reason = reason;
467 return GNUNET_NO; /* prereq waiting */
468 }
469 reason |= GNUNET_SCHEDULER_REASON_PREREQ_DONE;
470 } 468 }
469 reason |= GNUNET_SCHEDULER_REASON_PREREQ_DONE;
470 }
471 task->reason = reason; 471 task->reason = reason;
472 return GNUNET_YES; 472 return GNUNET_YES;
473} 473}
@@ -500,7 +500,7 @@ queue_ready_task (struct Task *task)
500 */ 500 */
501static void 501static void
502check_ready (const struct GNUNET_NETWORK_FDSet *rs, 502check_ready (const struct GNUNET_NETWORK_FDSet *rs,
503 const struct GNUNET_NETWORK_FDSet *ws) 503 const struct GNUNET_NETWORK_FDSet *ws)
504{ 504{
505 struct Task *pos; 505 struct Task *pos;
506 struct Task *prev; 506 struct Task *prev;
@@ -511,40 +511,39 @@ check_ready (const struct GNUNET_NETWORK_FDSet *rs,
511 prev = NULL; 511 prev = NULL;
512 pos = pending_timeout; 512 pos = pending_timeout;
513 while (pos != NULL) 513 while (pos != NULL)
514 { 514 {
515 next = pos->next; 515 next = pos->next;
516 if (now.abs_value >= pos->timeout.abs_value) 516 if (now.abs_value >= pos->timeout.abs_value)
517 pos->reason |= GNUNET_SCHEDULER_REASON_TIMEOUT; 517 pos->reason |= GNUNET_SCHEDULER_REASON_TIMEOUT;
518 if (0 == pos->reason) 518 if (0 == pos->reason)
519 break; 519 break;
520 pending_timeout = next; 520 pending_timeout = next;
521 if (pending_timeout_last == pos) 521 if (pending_timeout_last == pos)
522 pending_timeout_last = NULL; 522 pending_timeout_last = NULL;
523 queue_ready_task (pos); 523 queue_ready_task (pos);
524 pos = next; 524 pos = next;
525 } 525 }
526 pos = pending; 526 pos = pending;
527 while (pos != NULL) 527 while (pos != NULL)
528 { 528 {
529#if DEBUG_TASKS 529#if DEBUG_TASKS
530 LOG (GNUNET_ERROR_TYPE_DEBUG, 530 LOG (GNUNET_ERROR_TYPE_DEBUG, "Checking readiness of task: %llu / %p\n",
531 "Checking readiness of task: %llu / %p\n", pos->id, 531 pos->id, pos->callback_cls);
532 pos->callback_cls);
533#endif 532#endif
534 next = pos->next; 533 next = pos->next;
535 if (GNUNET_YES == is_ready (pos, now, rs, ws)) 534 if (GNUNET_YES == is_ready (pos, now, rs, ws))
536 { 535 {
537 if (prev == NULL) 536 if (prev == NULL)
538 pending = next; 537 pending = next;
539 else 538 else
540 prev->next = next; 539 prev->next = next;
541 queue_ready_task (pos); 540 queue_ready_task (pos);
542 pos = next;
543 continue;
544 }
545 prev = pos;
546 pos = next; 541 pos = next;
542 continue;
547 } 543 }
544 prev = pos;
545 pos = next;
546 }
548} 547}
549 548
550 549
@@ -563,15 +562,26 @@ GNUNET_SCHEDULER_shutdown ()
563 562
564 pos = pending_timeout; 563 pos = pending_timeout;
565 while (pos != NULL) 564 while (pos != NULL)
566 { 565 {
567 pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; 566 pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN;
568 /* we don't move the task into the ready queue yet; check_ready 567 /* we don't move the task into the ready queue yet; check_ready
569 * will do that later, possibly adding additional 568 * will do that later, possibly adding additional
570 * readiness-factors */ 569 * readiness-factors */
571 pos = pos->next; 570 pos = pos->next;
572 } 571 }
573 pos = pending; 572 pos = pending;
574 while (pos != NULL) 573 while (pos != NULL)
574 {
575 pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN;
576 /* we don't move the task into the ready queue yet; check_ready
577 * will do that later, possibly adding additional
578 * readiness-factors */
579 pos = pos->next;
580 }
581 for (i = 0; i < GNUNET_SCHEDULER_PRIORITY_COUNT; i++)
582 {
583 pos = ready[i];
584 while (pos != NULL)
575 { 585 {
576 pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; 586 pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN;
577 /* we don't move the task into the ready queue yet; check_ready 587 /* we don't move the task into the ready queue yet; check_ready
@@ -579,18 +589,7 @@ GNUNET_SCHEDULER_shutdown ()
579 * readiness-factors */ 589 * readiness-factors */
580 pos = pos->next; 590 pos = pos->next;
581 } 591 }
582 for (i = 0; i < GNUNET_SCHEDULER_PRIORITY_COUNT; i++) 592 }
583 {
584 pos = ready[i];
585 while (pos != NULL)
586 {
587 pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN;
588 /* we don't move the task into the ready queue yet; check_ready
589 * will do that later, possibly adding additional
590 * readiness-factors */
591 pos = pos->next;
592 }
593 }
594} 593}
595 594
596 595
@@ -632,69 +631,68 @@ run_ready (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws)
632 631
633 max_priority_added = GNUNET_SCHEDULER_PRIORITY_KEEP; 632 max_priority_added = GNUNET_SCHEDULER_PRIORITY_KEEP;
634 do 633 do
634 {
635 if (ready_count == 0)
636 return;
637 GNUNET_assert (ready[GNUNET_SCHEDULER_PRIORITY_KEEP] == NULL);
638 /* yes, p>0 is correct, 0 is "KEEP" which should
639 * always be an empty queue (see assertion)! */
640 for (p = GNUNET_SCHEDULER_PRIORITY_COUNT - 1; p > 0; p--)
635 { 641 {
636 if (ready_count == 0) 642 pos = ready[p];
637 return; 643 if (pos != NULL)
638 GNUNET_assert (ready[GNUNET_SCHEDULER_PRIORITY_KEEP] == NULL); 644 break;
639 /* yes, p>0 is correct, 0 is "KEEP" which should 645 }
640 * always be an empty queue (see assertion)! */ 646 GNUNET_assert (pos != NULL); /* ready_count wrong? */
641 for (p = GNUNET_SCHEDULER_PRIORITY_COUNT - 1; p > 0; p--) 647 ready[p] = pos->next;
642 { 648 ready_count--;
643 pos = ready[p]; 649 if (current_priority != pos->priority)
644 if (pos != NULL) 650 {
645 break; 651 current_priority = pos->priority;
646 } 652 (void) GNUNET_OS_set_process_priority (GNUNET_OS_process_current (),
647 GNUNET_assert (pos != NULL); /* ready_count wrong? */ 653 pos->priority);
648 ready[p] = pos->next; 654 }
649 ready_count--; 655 current_lifeness = pos->lifeness;
650 if (current_priority != pos->priority) 656 active_task = pos;
651 {
652 current_priority = pos->priority;
653 (void) GNUNET_OS_set_process_priority (GNUNET_OS_process_current (),
654 pos->priority);
655 }
656 current_lifeness = pos->lifeness;
657 active_task = pos;
658#if PROFILE_DELAYS 657#if PROFILE_DELAYS
659 if (GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value > 658 if (GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value >
660 DELAY_THRESHOLD.rel_value) 659 DELAY_THRESHOLD.rel_value)
661 { 660 {
662 LOG (GNUNET_ERROR_TYPE_ERROR, 661 LOG (GNUNET_ERROR_TYPE_ERROR, "Task %llu took %llums to be scheduled\n",
663 "Task %llu took %llums to be scheduled\n", pos->id, 662 pos->id,
664 (unsigned long long) 663 (unsigned long long)
665 GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value); 664 GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value);
666 } 665 }
667#endif 666#endif
668 tc.reason = pos->reason; 667 tc.reason = pos->reason;
669 tc.read_ready = (pos->read_set == NULL) ? rs : pos->read_set; 668 tc.read_ready = (pos->read_set == NULL) ? rs : pos->read_set;
670 if ((pos->read_fd != -1) && 669 if ((pos->read_fd != -1) &&
671 (0 != (pos->reason & GNUNET_SCHEDULER_REASON_READ_READY))) 670 (0 != (pos->reason & GNUNET_SCHEDULER_REASON_READ_READY)))
672 GNUNET_NETWORK_fdset_set_native (rs, pos->read_fd); 671 GNUNET_NETWORK_fdset_set_native (rs, pos->read_fd);
673 tc.write_ready = (pos->write_set == NULL) ? ws : pos->write_set; 672 tc.write_ready = (pos->write_set == NULL) ? ws : pos->write_set;
674 if ((pos->write_fd != -1) && 673 if ((pos->write_fd != -1) &&
675 (0 != (pos->reason & GNUNET_SCHEDULER_REASON_WRITE_READY))) 674 (0 != (pos->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)))
676 GNUNET_NETWORK_fdset_set_native (ws, pos->write_fd); 675 GNUNET_NETWORK_fdset_set_native (ws, pos->write_fd);
677 if (((tc.reason & GNUNET_SCHEDULER_REASON_WRITE_READY) != 0) && 676 if (((tc.reason & GNUNET_SCHEDULER_REASON_WRITE_READY) != 0) &&
678 (pos->write_fd != -1) && 677 (pos->write_fd != -1) &&
679 (!GNUNET_NETWORK_fdset_test_native (ws, pos->write_fd))) 678 (!GNUNET_NETWORK_fdset_test_native (ws, pos->write_fd)))
680 abort (); // added to ready in previous select loop! 679 abort (); // added to ready in previous select loop!
681#if DEBUG_TASKS 680#if DEBUG_TASKS
682 LOG (GNUNET_ERROR_TYPE_DEBUG, 681 LOG (GNUNET_ERROR_TYPE_DEBUG, "Running task: %llu / %p\n", pos->id,
683 "Running task: %llu / %p\n", pos->id, pos->callback_cls); 682 pos->callback_cls);
684#endif 683#endif
685 pos->callback (pos->callback_cls, &tc); 684 pos->callback (pos->callback_cls, &tc);
686#if EXECINFO 685#if EXECINFO
687 int i; 686 int i;
688 687
689 for (i = 0; i < pos->num_backtrace_strings; i++) 688 for (i = 0; i < pos->num_backtrace_strings; i++)
690 LOG (GNUNET_ERROR_TYPE_ERROR, 689 LOG (GNUNET_ERROR_TYPE_ERROR, "Task %llu trace %d: %s\n", pos->id, i,
691 "Task %llu trace %d: %s\n", pos->id, 690 pos->backtrace_strings[i]);
692 i, pos->backtrace_strings[i]);
693#endif 691#endif
694 active_task = NULL; 692 active_task = NULL;
695 destroy_task (pos); 693 destroy_task (pos);
696 tasks_run++; 694 tasks_run++;
697 } 695 }
698 while ((pending == NULL) || (p >= max_priority_added)); 696 while ((pending == NULL) || (p >= max_priority_added));
699} 697}
700 698
@@ -720,11 +718,11 @@ static void
720sighandler_shutdown () 718sighandler_shutdown ()
721{ 719{
722 static char c; 720 static char c;
723 int old_errno = errno; /* backup errno */ 721 int old_errno = errno; /* backup errno */
724 722
725 GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle 723 GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle
726 (shutdown_pipe_handle, GNUNET_DISK_PIPE_END_WRITE), 724 (shutdown_pipe_handle, GNUNET_DISK_PIPE_END_WRITE),
727 &c, sizeof (c)); 725 &c, sizeof (c));
728 errno = old_errno; 726 errno = old_errno;
729} 727}
730 728
@@ -750,10 +748,10 @@ check_lifeness ()
750 if (t->lifeness == GNUNET_YES) 748 if (t->lifeness == GNUNET_YES)
751 return GNUNET_OK; 749 return GNUNET_OK;
752 if ((NULL != pending) || (NULL != pending_timeout)) 750 if ((NULL != pending) || (NULL != pending_timeout))
753 { 751 {
754 GNUNET_SCHEDULER_shutdown (); 752 GNUNET_SCHEDULER_shutdown ();
755 return GNUNET_OK; 753 return GNUNET_OK;
756 } 754 }
757 return GNUNET_NO; 755 return GNUNET_NO;
758} 756}
759 757
@@ -799,7 +797,7 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls)
799 shutdown_pipe_handle = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO); 797 shutdown_pipe_handle = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO);
800 GNUNET_assert (shutdown_pipe_handle != NULL); 798 GNUNET_assert (shutdown_pipe_handle != NULL);
801 pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle, 799 pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle,
802 GNUNET_DISK_PIPE_END_READ); 800 GNUNET_DISK_PIPE_END_READ);
803 GNUNET_assert (pr != NULL); 801 GNUNET_assert (pr != NULL);
804 shc_int = GNUNET_SIGNAL_handler_install (SIGINT, &sighandler_shutdown); 802 shc_int = GNUNET_SIGNAL_handler_install (SIGINT, &sighandler_shutdown);
805 shc_term = GNUNET_SIGNAL_handler_install (SIGTERM, &sighandler_shutdown); 803 shc_term = GNUNET_SIGNAL_handler_install (SIGTERM, &sighandler_shutdown);
@@ -811,77 +809,76 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls)
811 current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT; 809 current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT;
812 current_lifeness = GNUNET_YES; 810 current_lifeness = GNUNET_YES;
813 GNUNET_SCHEDULER_add_continuation (task, task_cls, 811 GNUNET_SCHEDULER_add_continuation (task, task_cls,
814 GNUNET_SCHEDULER_REASON_STARTUP); 812 GNUNET_SCHEDULER_REASON_STARTUP);
815#if ENABLE_WINDOWS_WORKAROUNDS 813#if ENABLE_WINDOWS_WORKAROUNDS
816 active_task = (void *) (long) -1; /* force passing of sanity check */ 814 active_task = (void *) (long) -1; /* force passing of sanity check */
817 GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO, 815 GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO,
818 &GNUNET_OS_install_parent_control_handler, 816 &GNUNET_OS_install_parent_control_handler,
819 NULL); 817 NULL);
820 active_task = NULL; 818 active_task = NULL;
821#endif 819#endif
822 last_tr = 0; 820 last_tr = 0;
823 busy_wait_warning = 0; 821 busy_wait_warning = 0;
824 while (GNUNET_OK == check_lifeness ()) 822 while (GNUNET_OK == check_lifeness ())
823 {
824 GNUNET_NETWORK_fdset_zero (rs);
825 GNUNET_NETWORK_fdset_zero (ws);
826 timeout = GNUNET_TIME_UNIT_FOREVER_REL;
827 update_sets (rs, ws, &timeout);
828 GNUNET_NETWORK_fdset_handle_set (rs, pr);
829 if (ready_count > 0)
825 { 830 {
826 GNUNET_NETWORK_fdset_zero (rs); 831 /* no blocking, more work already ready! */
827 GNUNET_NETWORK_fdset_zero (ws); 832 timeout = GNUNET_TIME_UNIT_ZERO;
828 timeout = GNUNET_TIME_UNIT_FOREVER_REL; 833 }
829 update_sets (rs, ws, &timeout); 834 if (NULL == scheduler_select)
830 GNUNET_NETWORK_fdset_handle_set (rs, pr); 835 ret = GNUNET_NETWORK_socket_select (rs, ws, NULL, timeout);
831 if (ready_count > 0) 836 else
832 { 837 ret = scheduler_select (scheduler_select_cls, rs, ws, NULL, timeout);
833 /* no blocking, more work already ready! */ 838 if (ret == GNUNET_SYSERR)
834 timeout = GNUNET_TIME_UNIT_ZERO; 839 {
835 } 840 if (errno == EINTR)
836 if (NULL == scheduler_select) 841 continue;
837 ret = GNUNET_NETWORK_socket_select (rs, ws, NULL, timeout);
838 else
839 ret = scheduler_select (scheduler_select_cls, rs, ws, NULL, timeout);
840 if (ret == GNUNET_SYSERR)
841 {
842 if (errno == EINTR)
843 continue;
844 842
845 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "select"); 843 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "select");
846#ifndef MINGW 844#ifndef MINGW
847#if USE_LSOF 845#if USE_LSOF
848 char lsof[512]; 846 char lsof[512];
849 847
850 snprintf (lsof, sizeof (lsof), "lsof -p %d", getpid ()); 848 snprintf (lsof, sizeof (lsof), "lsof -p %d", getpid ());
851 (void) close (1); 849 (void) close (1);
852 (void) dup2 (2, 1); 850 (void) dup2 (2, 1);
853 if (0 != system (lsof)) 851 if (0 != system (lsof))
854 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "system"); 852 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "system");
855#endif 853#endif
856#endif 854#endif
857 abort (); 855 abort ();
858 break; 856 break;
859 } 857 }
860 if ((ret == 0) && (timeout.rel_value == 0) && (busy_wait_warning > 16)) 858 if ((ret == 0) && (timeout.rel_value == 0) && (busy_wait_warning > 16))
861 { 859 {
862 LOG (GNUNET_ERROR_TYPE_WARNING, 860 LOG (GNUNET_ERROR_TYPE_WARNING, _("Looks like we're busy waiting...\n"));
863 _("Looks like we're busy waiting...\n")); 861 sleep (1); /* mitigate */
864 sleep (1); /* mitigate */ 862 }
865 } 863 check_ready (rs, ws);
866 check_ready (rs, ws); 864 run_ready (rs, ws);
867 run_ready (rs, ws); 865 if (GNUNET_NETWORK_fdset_handle_isset (rs, pr))
868 if (GNUNET_NETWORK_fdset_handle_isset (rs, pr)) 866 {
869 { 867 /* consume the signal */
870 /* consume the signal */ 868 GNUNET_DISK_file_read (pr, &c, sizeof (c));
871 GNUNET_DISK_file_read (pr, &c, sizeof (c)); 869 /* mark all active tasks as ready due to shutdown */
872 /* mark all active tasks as ready due to shutdown */ 870 GNUNET_SCHEDULER_shutdown ();
873 GNUNET_SCHEDULER_shutdown (); 871 }
874 } 872 if (last_tr == tasks_run)
875 if (last_tr == tasks_run) 873 {
876 { 874 busy_wait_warning++;
877 busy_wait_warning++; 875 }
878 } 876 else
879 else 877 {
880 { 878 last_tr = tasks_run;
881 last_tr = tasks_run; 879 busy_wait_warning = 0;
882 busy_wait_warning = 0;
883 }
884 } 880 }
881 }
885 GNUNET_SIGNAL_handler_uninstall (shc_int); 882 GNUNET_SIGNAL_handler_uninstall (shc_int);
886 GNUNET_SIGNAL_handler_uninstall (shc_term); 883 GNUNET_SIGNAL_handler_uninstall (shc_term);
887#ifndef MINGW 884#ifndef MINGW
@@ -934,10 +931,10 @@ GNUNET_SCHEDULER_get_load (enum GNUNET_SCHEDULER_Priority p)
934 ret = 0; 931 ret = 0;
935 pos = ready[check_priority (p)]; 932 pos = ready[check_priority (p)];
936 while (pos != NULL) 933 while (pos != NULL)
937 { 934 {
938 pos = pos->next; 935 pos = pos->next;
939 ret++; 936 ret++;
940 } 937 }
941 return ret; 938 return ret;
942} 939}
943 940
@@ -963,77 +960,76 @@ GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_TaskIdentifier task)
963 prev = NULL; 960 prev = NULL;
964 t = pending; 961 t = pending;
965 while (t != NULL) 962 while (t != NULL)
963 {
964 if (t->id == task)
965 break;
966 prev = t;
967 t = t->next;
968 }
969 if (t == NULL)
970 {
971 prev = NULL;
972 to = 1;
973 t = pending_timeout;
974 while (t != NULL)
966 { 975 {
967 if (t->id == task) 976 if (t->id == task)
968 break; 977 break;
969 prev = t; 978 prev = t;
970 t = t->next; 979 t = t->next;
971 } 980 }
972 if (t == NULL) 981 if (pending_timeout_last == t)
973 { 982 pending_timeout_last = NULL;
974 prev = NULL; 983 }
975 to = 1;
976 t = pending_timeout;
977 while (t != NULL)
978 {
979 if (t->id == task)
980 break;
981 prev = t;
982 t = t->next;
983 }
984 if (pending_timeout_last == t)
985 pending_timeout_last = NULL;
986 }
987 p = 0; 984 p = 0;
988 while (t == NULL) 985 while (t == NULL)
986 {
987 p++;
988 if (p >= GNUNET_SCHEDULER_PRIORITY_COUNT)
989 { 989 {
990 p++; 990 LOG (GNUNET_ERROR_TYPE_ERROR, _("Attempt to cancel dead task %llu!\n"),
991 if (p >= GNUNET_SCHEDULER_PRIORITY_COUNT) 991 (unsigned long long) task);
992 { 992 GNUNET_assert (0);
993 LOG (GNUNET_ERROR_TYPE_ERROR,
994 _("Attempt to cancel dead task %llu!\n"),
995 (unsigned long long) task);
996 GNUNET_assert (0);
997 }
998 prev = NULL;
999 t = ready[p];
1000 while (t != NULL)
1001 {
1002 if (t->id == task)
1003 {
1004 ready_count--;
1005 break;
1006 }
1007 prev = t;
1008 t = t->next;
1009 }
1010 } 993 }
994 prev = NULL;
995 t = ready[p];
996 while (t != NULL)
997 {
998 if (t->id == task)
999 {
1000 ready_count--;
1001 break;
1002 }
1003 prev = t;
1004 t = t->next;
1005 }
1006 }
1011 if (prev == NULL) 1007 if (prev == NULL)
1008 {
1009 if (p == 0)
1012 { 1010 {
1013 if (p == 0) 1011 if (to == 0)
1014 { 1012 {
1015 if (to == 0) 1013 pending = t->next;
1016 { 1014 }
1017 pending = t->next;
1018 }
1019 else
1020 {
1021 pending_timeout = t->next;
1022 }
1023 }
1024 else 1015 else
1025 { 1016 {
1026 ready[p] = t->next; 1017 pending_timeout = t->next;
1027 } 1018 }
1028 } 1019 }
1029 else 1020 else
1030 { 1021 {
1031 prev->next = t->next; 1022 ready[p] = t->next;
1032 } 1023 }
1024 }
1025 else
1026 {
1027 prev->next = t->next;
1028 }
1033 ret = t->callback_cls; 1029 ret = t->callback_cls;
1034#if DEBUG_TASKS 1030#if DEBUG_TASKS
1035 LOG (GNUNET_ERROR_TYPE_DEBUG, 1031 LOG (GNUNET_ERROR_TYPE_DEBUG, "Canceling task: %llu / %p\n", task,
1036 "Canceling task: %llu / %p\n", task, t->callback_cls); 1032 t->callback_cls);
1037#endif 1033#endif
1038 destroy_task (t); 1034 destroy_task (t);
1039 return ret; 1035 return ret;
@@ -1051,7 +1047,7 @@ GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_TaskIdentifier task)
1051 */ 1047 */
1052void 1048void
1053GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls, 1049GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls,
1054 enum GNUNET_SCHEDULER_Reason reason) 1050 enum GNUNET_SCHEDULER_Reason reason)
1055{ 1051{
1056 struct Task *t; 1052 struct Task *t;
1057 1053
@@ -1061,12 +1057,12 @@ GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls,
1061 1057
1062 GNUNET_assert (NULL != task); 1058 GNUNET_assert (NULL != task);
1063 GNUNET_assert ((active_task != NULL) || 1059 GNUNET_assert ((active_task != NULL) ||
1064 (reason == GNUNET_SCHEDULER_REASON_STARTUP)); 1060 (reason == GNUNET_SCHEDULER_REASON_STARTUP));
1065 t = GNUNET_malloc (sizeof (struct Task)); 1061 t = GNUNET_malloc (sizeof (struct Task));
1066#if EXECINFO 1062#if EXECINFO
1067 t->num_backtrace_strings = backtrace (backtrace_array, 50); 1063 t->num_backtrace_strings = backtrace (backtrace_array, 50);
1068 t->backtrace_strings = 1064 t->backtrace_strings =
1069 backtrace_symbols (backtrace_array, t->num_backtrace_strings); 1065 backtrace_symbols (backtrace_array, t->num_backtrace_strings);
1070#endif 1066#endif
1071 t->read_fd = -1; 1067 t->read_fd = -1;
1072 t->write_fd = -1; 1068 t->write_fd = -1;
@@ -1080,8 +1076,8 @@ GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls,
1080 t->priority = current_priority; 1076 t->priority = current_priority;
1081 t->lifeness = current_lifeness; 1077 t->lifeness = current_lifeness;
1082#if DEBUG_TASKS 1078#if DEBUG_TASKS
1083 LOG (GNUNET_ERROR_TYPE_DEBUG, 1079 LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding continuation task: %llu / %p\n", t->id,
1084 "Adding continuation task: %llu / %p\n", t->id, t->callback_cls); 1080 t->callback_cls);
1085#endif 1081#endif
1086 queue_ready_task (t); 1082 queue_ready_task (t);
1087} 1083}
@@ -1106,12 +1102,11 @@ GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls,
1106 */ 1102 */
1107GNUNET_SCHEDULER_TaskIdentifier 1103GNUNET_SCHEDULER_TaskIdentifier
1108GNUNET_SCHEDULER_add_after (GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, 1104GNUNET_SCHEDULER_add_after (GNUNET_SCHEDULER_TaskIdentifier prerequisite_task,
1109 GNUNET_SCHEDULER_Task task, void *task_cls) 1105 GNUNET_SCHEDULER_Task task, void *task_cls)
1110{ 1106{
1111 return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, 1107 return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP,
1112 prerequisite_task, 1108 prerequisite_task, GNUNET_TIME_UNIT_ZERO,
1113 GNUNET_TIME_UNIT_ZERO, NULL, NULL, task, 1109 NULL, NULL, task, task_cls);
1114 task_cls);
1115} 1110}
1116 1111
1117 1112
@@ -1126,12 +1121,11 @@ GNUNET_SCHEDULER_add_after (GNUNET_SCHEDULER_TaskIdentifier prerequisite_task,
1126 */ 1121 */
1127GNUNET_SCHEDULER_TaskIdentifier 1122GNUNET_SCHEDULER_TaskIdentifier
1128GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio, 1123GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio,
1129 GNUNET_SCHEDULER_Task task, 1124 GNUNET_SCHEDULER_Task task, void *task_cls)
1130 void *task_cls)
1131{ 1125{
1132 return GNUNET_SCHEDULER_add_select (prio, GNUNET_SCHEDULER_NO_TASK, 1126 return GNUNET_SCHEDULER_add_select (prio, GNUNET_SCHEDULER_NO_TASK,
1133 GNUNET_TIME_UNIT_ZERO, NULL, NULL, task, 1127 GNUNET_TIME_UNIT_ZERO, NULL, NULL, task,
1134 task_cls); 1128 task_cls);
1135} 1129}
1136 1130
1137 1131
@@ -1150,7 +1144,7 @@ GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio,
1150 */ 1144 */
1151GNUNET_SCHEDULER_TaskIdentifier 1145GNUNET_SCHEDULER_TaskIdentifier
1152GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay, 1146GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
1153 GNUNET_SCHEDULER_Task task, void *task_cls) 1147 GNUNET_SCHEDULER_Task task, void *task_cls)
1154{ 1148{
1155#if 1 1149#if 1
1156 /* new, optimized version */ 1150 /* new, optimized version */
@@ -1170,7 +1164,7 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
1170#if EXECINFO 1164#if EXECINFO
1171 t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH); 1165 t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH);
1172 t->backtrace_strings = 1166 t->backtrace_strings =
1173 backtrace_symbols (backtrace_array, t->num_backtrace_strings); 1167 backtrace_symbols (backtrace_array, t->num_backtrace_strings);
1174#endif 1168#endif
1175 t->read_fd = -1; 1169 t->read_fd = -1;
1176 t->write_fd = -1; 1170 t->write_fd = -1;
@@ -1185,24 +1179,24 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
1185 * appending to a long list of tasks with timeouts) */ 1179 * appending to a long list of tasks with timeouts) */
1186 prev = pending_timeout_last; 1180 prev = pending_timeout_last;
1187 if (prev != NULL) 1181 if (prev != NULL)
1188 { 1182 {
1189 if (prev->timeout.abs_value > t->timeout.abs_value) 1183 if (prev->timeout.abs_value > t->timeout.abs_value)
1190 prev = NULL; 1184 prev = NULL;
1191 else 1185 else
1192 pos = prev->next; /* heuristic success! */ 1186 pos = prev->next; /* heuristic success! */
1193 } 1187 }
1194 if (prev == NULL) 1188 if (prev == NULL)
1195 { 1189 {
1196 /* heuristic failed, do traversal of timeout list */ 1190 /* heuristic failed, do traversal of timeout list */
1197 pos = pending_timeout; 1191 pos = pending_timeout;
1198 } 1192 }
1199 while ((pos != NULL) && 1193 while ((pos != NULL) &&
1200 ((pos->timeout.abs_value <= t->timeout.abs_value) || 1194 ((pos->timeout.abs_value <= t->timeout.abs_value) ||
1201 (pos->reason != 0))) 1195 (pos->reason != 0)))
1202 { 1196 {
1203 prev = pos; 1197 prev = pos;
1204 pos = pos->next; 1198 pos = pos->next;
1205 } 1199 }
1206 if (prev == NULL) 1200 if (prev == NULL)
1207 pending_timeout = t; 1201 pending_timeout = t;
1208 else 1202 else
@@ -1212,23 +1206,23 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
1212 pending_timeout_last = t; 1206 pending_timeout_last = t;
1213 1207
1214#if DEBUG_TASKS 1208#if DEBUG_TASKS
1215 LOG (GNUNET_ERROR_TYPE_DEBUG, 1209 LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding task: %llu / %p\n", t->id,
1216 "Adding task: %llu / %p\n", t->id, t->callback_cls); 1210 t->callback_cls);
1217#endif 1211#endif
1218#if EXECINFO 1212#if EXECINFO
1219 int i; 1213 int i;
1220 1214
1221 for (i = 0; i < t->num_backtrace_strings; i++) 1215 for (i = 0; i < t->num_backtrace_strings; i++)
1222 LOG (GNUNET_ERROR_TYPE_DEBUG, 1216 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]); 1217 t->backtrace_strings[i]);
1224#endif 1218#endif
1225 return t->id; 1219 return t->id;
1226 1220
1227#else 1221#else
1228 /* unoptimized version */ 1222 /* unoptimized version */
1229 return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, 1223 return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP,
1230 GNUNET_SCHEDULER_NO_TASK, delay, NULL, 1224 GNUNET_SCHEDULER_NO_TASK, delay, NULL,
1231 NULL, task, task_cls); 1225 NULL, task, task_cls);
1232#endif 1226#endif
1233} 1227}
1234 1228
@@ -1247,9 +1241,9 @@ GNUNET_SCHEDULER_TaskIdentifier
1247GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_Task task, void *task_cls) 1241GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_Task task, void *task_cls)
1248{ 1242{
1249 return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, 1243 return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP,
1250 GNUNET_SCHEDULER_NO_TASK, 1244 GNUNET_SCHEDULER_NO_TASK,
1251 GNUNET_TIME_UNIT_ZERO, NULL, NULL, task, 1245 GNUNET_TIME_UNIT_ZERO, NULL, NULL, task,
1252 task_cls); 1246 task_cls);
1253} 1247}
1254 1248
1255 1249
@@ -1269,16 +1263,16 @@ GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_Task task, void *task_cls)
1269 */ 1263 */
1270GNUNET_SCHEDULER_TaskIdentifier 1264GNUNET_SCHEDULER_TaskIdentifier
1271GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness, 1265GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness,
1272 GNUNET_SCHEDULER_Task task, 1266 GNUNET_SCHEDULER_Task task,
1273 void *task_cls) 1267 void *task_cls)
1274{ 1268{
1275 GNUNET_SCHEDULER_TaskIdentifier ret; 1269 GNUNET_SCHEDULER_TaskIdentifier ret;
1276 1270
1277 ret = 1271 ret =
1278 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, 1272 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP,
1279 GNUNET_SCHEDULER_NO_TASK, 1273 GNUNET_SCHEDULER_NO_TASK,
1280 GNUNET_TIME_UNIT_ZERO, NULL, NULL, task, 1274 GNUNET_TIME_UNIT_ZERO, NULL, NULL, task,
1281 task_cls); 1275 task_cls);
1282 GNUNET_assert (pending->id == ret); 1276 GNUNET_assert (pending->id == ret);
1283 pending->lifeness = lifeness; 1277 pending->lifeness = lifeness;
1284 return ret; 1278 return ret;
@@ -1316,7 +1310,7 @@ GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness,
1316#ifndef MINGW 1310#ifndef MINGW
1317GNUNET_SCHEDULER_TaskIdentifier 1311GNUNET_SCHEDULER_TaskIdentifier
1318add_without_sets (struct GNUNET_TIME_Relative delay, int rfd, int wfd, 1312add_without_sets (struct GNUNET_TIME_Relative delay, int rfd, int wfd,
1319 GNUNET_SCHEDULER_Task task, void *task_cls) 1313 GNUNET_SCHEDULER_Task task, void *task_cls)
1320{ 1314{
1321 struct Task *t; 1315 struct Task *t;
1322 1316
@@ -1332,45 +1326,41 @@ add_without_sets (struct GNUNET_TIME_Relative delay, int rfd, int wfd,
1332#if EXECINFO 1326#if EXECINFO
1333 t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH); 1327 t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH);
1334 t->backtrace_strings = 1328 t->backtrace_strings =
1335 backtrace_symbols (backtrace_array, t->num_backtrace_strings); 1329 backtrace_symbols (backtrace_array, t->num_backtrace_strings);
1336#endif 1330#endif
1337#if DEBUG_FDS 1331#if DEBUG_FDS
1338 if (-1 != rfd) 1332 if (-1 != rfd)
1339 { 1333 {
1340 int flags = fcntl (rfd, F_GETFD); 1334 int flags = fcntl (rfd, F_GETFD);
1341 1335
1342 if ((flags == -1) && (errno == EBADF)) 1336 if ((flags == -1) && (errno == EBADF))
1343 { 1337 {
1344 LOG (GNUNET_ERROR_TYPE_ERROR, 1338 LOG (GNUNET_ERROR_TYPE_ERROR, "Got invalid file descriptor %d!\n", rfd);
1345 "Got invalid file descriptor %d!\n", rfd);
1346#if EXECINFO 1339#if EXECINFO
1347 int i; 1340 int i;
1348 1341
1349 for (i = 0; i < t->num_backtrace_strings; i++) 1342 for (i = 0; i < t->num_backtrace_strings; i++)
1350 LOG (GNUNET_ERROR_TYPE_DEBUG, 1343 LOG (GNUNET_ERROR_TYPE_DEBUG, "Trace: %s\n", t->backtrace_strings[i]);
1351 "Trace: %s\n", t->backtrace_strings[i]);
1352#endif 1344#endif
1353 GNUNET_assert (0); 1345 GNUNET_assert (0);
1354 }
1355 } 1346 }
1347 }
1356 if (-1 != wfd) 1348 if (-1 != wfd)
1357 { 1349 {
1358 int flags = fcntl (wfd, F_GETFD); 1350 int flags = fcntl (wfd, F_GETFD);
1359 1351
1360 if (flags == -1 && errno == EBADF) 1352 if (flags == -1 && errno == EBADF)
1361 { 1353 {
1362 LOG (GNUNET_ERROR_TYPE_ERROR, 1354 LOG (GNUNET_ERROR_TYPE_ERROR, "Got invalid file descriptor %d!\n", wfd);
1363 "Got invalid file descriptor %d!\n", wfd);
1364#if EXECINFO 1355#if EXECINFO
1365 int i; 1356 int i;
1366 1357
1367 for (i = 0; i < t->num_backtrace_strings; i++) 1358 for (i = 0; i < t->num_backtrace_strings; i++)
1368 LOG (GNUNET_ERROR_TYPE_DEBUG, 1359 LOG (GNUNET_ERROR_TYPE_DEBUG, "Trace: %s\n", t->backtrace_strings[i]);
1369 "Trace: %s\n", t->backtrace_strings[i]);
1370#endif 1360#endif
1371 GNUNET_assert (0); 1361 GNUNET_assert (0);
1372 }
1373 } 1362 }
1363 }
1374#endif 1364#endif
1375 t->read_fd = rfd; 1365 t->read_fd = rfd;
1376 GNUNET_assert (wfd >= -1); 1366 GNUNET_assert (wfd >= -1);
@@ -1387,15 +1377,15 @@ add_without_sets (struct GNUNET_TIME_Relative delay, int rfd, int wfd,
1387 pending = t; 1377 pending = t;
1388 max_priority_added = GNUNET_MAX (max_priority_added, t->priority); 1378 max_priority_added = GNUNET_MAX (max_priority_added, t->priority);
1389#if DEBUG_TASKS 1379#if DEBUG_TASKS
1390 LOG (GNUNET_ERROR_TYPE_DEBUG, 1380 LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding task: %llu / %p\n", t->id,
1391 "Adding task: %llu / %p\n", t->id, t->callback_cls); 1381 t->callback_cls);
1392#endif 1382#endif
1393#if EXECINFO 1383#if EXECINFO
1394 int i; 1384 int i;
1395 1385
1396 for (i = 0; i < t->num_backtrace_strings; i++) 1386 for (i = 0; i < t->num_backtrace_strings; i++)
1397 LOG (GNUNET_ERROR_TYPE_DEBUG, 1387 LOG (GNUNET_ERROR_TYPE_DEBUG, "Task %llu trace %d: %s\n", t->id, i,
1398 "Task %llu trace %d: %s\n", t->id, i, t->backtrace_strings[i]); 1388 t->backtrace_strings[i]);
1399#endif 1389#endif
1400 return t->id; 1390 return t->id;
1401} 1391}
@@ -1421,8 +1411,8 @@ add_without_sets (struct GNUNET_TIME_Relative delay, int rfd, int wfd,
1421 */ 1411 */
1422GNUNET_SCHEDULER_TaskIdentifier 1412GNUNET_SCHEDULER_TaskIdentifier
1423GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay, 1413GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay,
1424 struct GNUNET_NETWORK_Handle * rfd, 1414 struct GNUNET_NETWORK_Handle *rfd,
1425 GNUNET_SCHEDULER_Task task, void *task_cls) 1415 GNUNET_SCHEDULER_Task task, void *task_cls)
1426{ 1416{
1427#if MINGW 1417#if MINGW
1428 struct GNUNET_NETWORK_FDSet *rs; 1418 struct GNUNET_NETWORK_FDSet *rs;
@@ -1432,14 +1422,14 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay,
1432 rs = GNUNET_NETWORK_fdset_create (); 1422 rs = GNUNET_NETWORK_fdset_create ();
1433 GNUNET_NETWORK_fdset_set (rs, rfd); 1423 GNUNET_NETWORK_fdset_set (rs, rfd);
1434 ret = 1424 ret =
1435 GNUNET_SCHEDULER_add_select (check_priority (current_priority), 1425 GNUNET_SCHEDULER_add_select (check_priority (current_priority),
1436 GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL, 1426 GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL,
1437 task, task_cls); 1427 task, task_cls);
1438 GNUNET_NETWORK_fdset_destroy (rs); 1428 GNUNET_NETWORK_fdset_destroy (rs);
1439 return ret; 1429 return ret;
1440#else 1430#else
1441 return add_without_sets (delay, GNUNET_NETWORK_get_fd (rfd), -1, task, 1431 return add_without_sets (delay, GNUNET_NETWORK_get_fd (rfd), -1, task,
1442 task_cls); 1432 task_cls);
1443#endif 1433#endif
1444} 1434}
1445 1435
@@ -1462,8 +1452,8 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay,
1462 */ 1452 */
1463GNUNET_SCHEDULER_TaskIdentifier 1453GNUNET_SCHEDULER_TaskIdentifier
1464GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay, 1454GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay,
1465 struct GNUNET_NETWORK_Handle * wfd, 1455 struct GNUNET_NETWORK_Handle *wfd,
1466 GNUNET_SCHEDULER_Task task, void *task_cls) 1456 GNUNET_SCHEDULER_Task task, void *task_cls)
1467{ 1457{
1468#if MINGW 1458#if MINGW
1469 struct GNUNET_NETWORK_FDSet *ws; 1459 struct GNUNET_NETWORK_FDSet *ws;
@@ -1473,15 +1463,15 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay,
1473 ws = GNUNET_NETWORK_fdset_create (); 1463 ws = GNUNET_NETWORK_fdset_create ();
1474 GNUNET_NETWORK_fdset_set (ws, wfd); 1464 GNUNET_NETWORK_fdset_set (ws, wfd);
1475 ret = 1465 ret =
1476 GNUNET_SCHEDULER_add_select (check_priority (current_priority), 1466 GNUNET_SCHEDULER_add_select (check_priority (current_priority),
1477 GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws, 1467 GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws,
1478 task, task_cls); 1468 task, task_cls);
1479 GNUNET_NETWORK_fdset_destroy (ws); 1469 GNUNET_NETWORK_fdset_destroy (ws);
1480 return ret; 1470 return ret;
1481#else 1471#else
1482 GNUNET_assert (GNUNET_NETWORK_get_fd (wfd) >= 0); 1472 GNUNET_assert (GNUNET_NETWORK_get_fd (wfd) >= 0);
1483 return add_without_sets (delay, -1, GNUNET_NETWORK_get_fd (wfd), task, 1473 return add_without_sets (delay, -1, GNUNET_NETWORK_get_fd (wfd), task,
1484 task_cls); 1474 task_cls);
1485#endif 1475#endif
1486} 1476}
1487 1477
@@ -1504,8 +1494,8 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay,
1504 */ 1494 */
1505GNUNET_SCHEDULER_TaskIdentifier 1495GNUNET_SCHEDULER_TaskIdentifier
1506GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay, 1496GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay,
1507 const struct GNUNET_DISK_FileHandle * rfd, 1497 const struct GNUNET_DISK_FileHandle *rfd,
1508 GNUNET_SCHEDULER_Task task, void *task_cls) 1498 GNUNET_SCHEDULER_Task task, void *task_cls)
1509{ 1499{
1510#if MINGW 1500#if MINGW
1511 struct GNUNET_NETWORK_FDSet *rs; 1501 struct GNUNET_NETWORK_FDSet *rs;
@@ -1515,9 +1505,9 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay,
1515 rs = GNUNET_NETWORK_fdset_create (); 1505 rs = GNUNET_NETWORK_fdset_create ();
1516 GNUNET_NETWORK_fdset_handle_set (rs, rfd); 1506 GNUNET_NETWORK_fdset_handle_set (rs, rfd);
1517 ret = 1507 ret =
1518 GNUNET_SCHEDULER_add_select (check_priority (current_priority), 1508 GNUNET_SCHEDULER_add_select (check_priority (current_priority),
1519 GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL, 1509 GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL,
1520 task, task_cls); 1510 task, task_cls);
1521 GNUNET_NETWORK_fdset_destroy (rs); 1511 GNUNET_NETWORK_fdset_destroy (rs);
1522 return ret; 1512 return ret;
1523#else 1513#else
@@ -1548,8 +1538,8 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay,
1548 */ 1538 */
1549GNUNET_SCHEDULER_TaskIdentifier 1539GNUNET_SCHEDULER_TaskIdentifier
1550GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay, 1540GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay,
1551 const struct GNUNET_DISK_FileHandle * wfd, 1541 const struct GNUNET_DISK_FileHandle *wfd,
1552 GNUNET_SCHEDULER_Task task, void *task_cls) 1542 GNUNET_SCHEDULER_Task task, void *task_cls)
1553{ 1543{
1554#if MINGW 1544#if MINGW
1555 struct GNUNET_NETWORK_FDSet *ws; 1545 struct GNUNET_NETWORK_FDSet *ws;
@@ -1559,9 +1549,9 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay,
1559 ws = GNUNET_NETWORK_fdset_create (); 1549 ws = GNUNET_NETWORK_fdset_create ();
1560 GNUNET_NETWORK_fdset_handle_set (ws, wfd); 1550 GNUNET_NETWORK_fdset_handle_set (ws, wfd);
1561 ret = 1551 ret =
1562 GNUNET_SCHEDULER_add_select (check_priority (current_priority), 1552 GNUNET_SCHEDULER_add_select (check_priority (current_priority),
1563 GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws, 1553 GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws,
1564 task, task_cls); 1554 task, task_cls);
1565 GNUNET_NETWORK_fdset_destroy (ws); 1555 GNUNET_NETWORK_fdset_destroy (ws);
1566 return ret; 1556 return ret;
1567#else 1557#else
@@ -1610,12 +1600,11 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay,
1610 */ 1600 */
1611GNUNET_SCHEDULER_TaskIdentifier 1601GNUNET_SCHEDULER_TaskIdentifier
1612GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, 1602GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio,
1613 GNUNET_SCHEDULER_TaskIdentifier 1603 GNUNET_SCHEDULER_TaskIdentifier prerequisite_task,
1614 prerequisite_task, 1604 struct GNUNET_TIME_Relative delay,
1615 struct GNUNET_TIME_Relative delay, 1605 const struct GNUNET_NETWORK_FDSet *rs,
1616 const struct GNUNET_NETWORK_FDSet * rs, 1606 const struct GNUNET_NETWORK_FDSet *ws,
1617 const struct GNUNET_NETWORK_FDSet * ws, 1607 GNUNET_SCHEDULER_Task task, void *task_cls)
1618 GNUNET_SCHEDULER_Task task, void *task_cls)
1619{ 1608{
1620 struct Task *t; 1609 struct Task *t;
1621 1610
@@ -1631,20 +1620,20 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio,
1631#if EXECINFO 1620#if EXECINFO
1632 t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH); 1621 t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH);
1633 t->backtrace_strings = 1622 t->backtrace_strings =
1634 backtrace_symbols (backtrace_array, t->num_backtrace_strings); 1623 backtrace_symbols (backtrace_array, t->num_backtrace_strings);
1635#endif 1624#endif
1636 t->read_fd = -1; 1625 t->read_fd = -1;
1637 t->write_fd = -1; 1626 t->write_fd = -1;
1638 if (rs != NULL) 1627 if (rs != NULL)
1639 { 1628 {
1640 t->read_set = GNUNET_NETWORK_fdset_create (); 1629 t->read_set = GNUNET_NETWORK_fdset_create ();
1641 GNUNET_NETWORK_fdset_copy (t->read_set, rs); 1630 GNUNET_NETWORK_fdset_copy (t->read_set, rs);
1642 } 1631 }
1643 if (ws != NULL) 1632 if (ws != NULL)
1644 { 1633 {
1645 t->write_set = GNUNET_NETWORK_fdset_create (); 1634 t->write_set = GNUNET_NETWORK_fdset_create ();
1646 GNUNET_NETWORK_fdset_copy (t->write_set, ws); 1635 GNUNET_NETWORK_fdset_copy (t->write_set, ws);
1647 } 1636 }
1648 t->id = ++last_id; 1637 t->id = ++last_id;
1649#if PROFILE_DELAYS 1638#if PROFILE_DELAYS
1650 t->start_time = GNUNET_TIME_absolute_get (); 1639 t->start_time = GNUNET_TIME_absolute_get ();
@@ -1652,23 +1641,23 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio,
1652 t->prereq_id = prerequisite_task; 1641 t->prereq_id = prerequisite_task;
1653 t->timeout = GNUNET_TIME_relative_to_absolute (delay); 1642 t->timeout = GNUNET_TIME_relative_to_absolute (delay);
1654 t->priority = 1643 t->priority =
1655 check_priority ((prio == 1644 check_priority ((prio ==
1656 GNUNET_SCHEDULER_PRIORITY_KEEP) ? current_priority : 1645 GNUNET_SCHEDULER_PRIORITY_KEEP) ? current_priority :
1657 prio); 1646 prio);
1658 t->lifeness = current_lifeness; 1647 t->lifeness = current_lifeness;
1659 t->next = pending; 1648 t->next = pending;
1660 pending = t; 1649 pending = t;
1661 max_priority_added = GNUNET_MAX (max_priority_added, t->priority); 1650 max_priority_added = GNUNET_MAX (max_priority_added, t->priority);
1662#if DEBUG_TASKS 1651#if DEBUG_TASKS
1663 LOG (GNUNET_ERROR_TYPE_DEBUG, 1652 LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding task: %llu / %p\n", t->id,
1664 "Adding task: %llu / %p\n", t->id, t->callback_cls); 1653 t->callback_cls);
1665#endif 1654#endif
1666#if EXECINFO 1655#if EXECINFO
1667 int i; 1656 int i;
1668 1657
1669 for (i = 0; i < t->num_backtrace_strings; i++) 1658 for (i = 0; i < t->num_backtrace_strings; i++)
1670 LOG (GNUNET_ERROR_TYPE_DEBUG, 1659 LOG (GNUNET_ERROR_TYPE_DEBUG, "Task %llu trace %d: %s\n", t->id, i,
1671 "Task %llu trace %d: %s\n", t->id, i, t->backtrace_strings[i]); 1660 t->backtrace_strings[i]);
1672#endif 1661#endif
1673 return t->id; 1662 return t->id;
1674} 1663}
diff --git a/src/util/server.c b/src/util/server.c
index f792e5a67..6f1b8cdb4 100644
--- a/src/util/server.c
+++ b/src/util/server.c
@@ -264,8 +264,7 @@ struct GNUNET_SERVER_Client
264 * @param tc reason why we are running right now 264 * @param tc reason why we are running right now
265 */ 265 */
266static void 266static void
267process_listen_socket (void *cls, 267process_listen_socket (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
268 const struct GNUNET_SCHEDULER_TaskContext *tc)
269{ 268{
270 struct GNUNET_SERVER_Handle *server = cls; 269 struct GNUNET_SERVER_Handle *server = cls;
271 struct GNUNET_CONNECTION_Handle *sock; 270 struct GNUNET_CONNECTION_Handle *sock;
@@ -279,47 +278,45 @@ process_listen_socket (void *cls,
279 while (NULL != server->listen_sockets[i]) 278 while (NULL != server->listen_sockets[i])
280 GNUNET_NETWORK_fdset_set (r, server->listen_sockets[i++]); 279 GNUNET_NETWORK_fdset_set (r, server->listen_sockets[i++]);
281 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 280 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
282 { 281 {
283 /* ignore shutdown, someone else will take care of it! */ 282 /* ignore shutdown, someone else will take care of it! */
284 server->listen_task = 283 server->listen_task =
285 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, 284 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
286 GNUNET_SCHEDULER_NO_TASK, 285 GNUNET_SCHEDULER_NO_TASK,
287 GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, 286 GNUNET_TIME_UNIT_FOREVER_REL, r, NULL,
288 &process_listen_socket, server); 287 &process_listen_socket, server);
289 GNUNET_NETWORK_fdset_destroy (r); 288 GNUNET_NETWORK_fdset_destroy (r);
290 return; 289 return;
291 } 290 }
292 i = 0; 291 i = 0;
293 while (NULL != server->listen_sockets[i]) 292 while (NULL != server->listen_sockets[i])
293 {
294 if (GNUNET_NETWORK_fdset_isset (tc->read_ready, server->listen_sockets[i]))
294 { 295 {
295 if (GNUNET_NETWORK_fdset_isset 296 sock =
296 (tc->read_ready, server->listen_sockets[i])) 297 GNUNET_CONNECTION_create_from_accept (server->access,
297 { 298 server->access_cls,
298 sock = 299 server->listen_sockets[i]);
299 GNUNET_CONNECTION_create_from_accept (server->access, 300 if (sock != NULL)
300 server->access_cls, 301 {
301 server->listen_sockets[i]);
302 if (sock != NULL)
303 {
304#if DEBUG_SERVER 302#if DEBUG_SERVER
305 LOG (GNUNET_ERROR_TYPE_DEBUG, 303 LOG (GNUNET_ERROR_TYPE_DEBUG, "Server accepted incoming connection.\n");
306 "Server accepted incoming connection.\n");
307#endif 304#endif
308 client = GNUNET_SERVER_connect_socket (server, sock); 305 client = GNUNET_SERVER_connect_socket (server, sock);
309 GNUNET_CONNECTION_ignore_shutdown (sock, 306 GNUNET_CONNECTION_ignore_shutdown (sock,
310 server->clients_ignore_shutdown); 307 server->clients_ignore_shutdown);
311 /* decrement reference count, we don't keep "client" alive */ 308 /* decrement reference count, we don't keep "client" alive */
312 GNUNET_SERVER_client_drop (client); 309 GNUNET_SERVER_client_drop (client);
313 } 310 }
314 }
315 i++;
316 } 311 }
312 i++;
313 }
317 /* listen for more! */ 314 /* listen for more! */
318 server->listen_task = 315 server->listen_task =
319 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, 316 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
320 GNUNET_SCHEDULER_NO_TASK, 317 GNUNET_SCHEDULER_NO_TASK,
321 GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, 318 GNUNET_TIME_UNIT_FOREVER_REL, r, NULL,
322 &process_listen_socket, server); 319 &process_listen_socket, server);
323 GNUNET_NETWORK_fdset_destroy (r); 320 GNUNET_NETWORK_fdset_destroy (r);
324} 321}
325 322
@@ -340,87 +337,87 @@ open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen)
340 int eno; 337 int eno;
341 338
342 switch (serverAddr->sa_family) 339 switch (serverAddr->sa_family)
343 { 340 {
344 case AF_INET: 341 case AF_INET:
345 port = ntohs (((const struct sockaddr_in *) serverAddr)->sin_port); 342 port = ntohs (((const struct sockaddr_in *) serverAddr)->sin_port);
346 break; 343 break;
347 case AF_INET6: 344 case AF_INET6:
348 port = ntohs (((const struct sockaddr_in6 *) serverAddr)->sin6_port); 345 port = ntohs (((const struct sockaddr_in6 *) serverAddr)->sin6_port);
349 break; 346 break;
350 case AF_UNIX: 347 case AF_UNIX:
351 port = 0; 348 port = 0;
352 break; 349 break;
353 default: 350 default:
354 GNUNET_break (0); 351 GNUNET_break (0);
355 port = 0; 352 port = 0;
356 break; 353 break;
357 } 354 }
358 sock = GNUNET_NETWORK_socket_create (serverAddr->sa_family, SOCK_STREAM, 0); 355 sock = GNUNET_NETWORK_socket_create (serverAddr->sa_family, SOCK_STREAM, 0);
359 if (NULL == sock) 356 if (NULL == sock)
360 { 357 {
361 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket"); 358 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
362 errno = 0; 359 errno = 0;
363 return NULL; 360 return NULL;
364 } 361 }
365 if (port != 0) 362 if (port != 0)
366 { 363 {
367 if (GNUNET_NETWORK_socket_setsockopt 364 if (GNUNET_NETWORK_socket_setsockopt
368 (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) 365 (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)
369 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 366 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
370 "setsockopt"); 367 "setsockopt");
371#ifdef IPV6_V6ONLY 368#ifdef IPV6_V6ONLY
372 if ((serverAddr->sa_family == AF_INET6) && 369 if ((serverAddr->sa_family == AF_INET6) &&
373 (GNUNET_NETWORK_socket_setsockopt 370 (GNUNET_NETWORK_socket_setsockopt
374 (sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on)) != GNUNET_OK)) 371 (sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on)) != GNUNET_OK))
375 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 372 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
376 "setsockopt"); 373 "setsockopt");
377#endif 374#endif
378 } 375 }
379 /* bind the socket */ 376 /* bind the socket */
380 if (GNUNET_NETWORK_socket_bind (sock, serverAddr, socklen) != GNUNET_OK) 377 if (GNUNET_NETWORK_socket_bind (sock, serverAddr, socklen) != GNUNET_OK)
378 {
379 eno = errno;
380 if (errno != EADDRINUSE)
381 { 381 {
382 eno = errno; 382 /* we don't log 'EADDRINUSE' here since an IPv4 bind may
383 if (errno != EADDRINUSE) 383 * fail if we already took the port on IPv6; if both IPv4 and
384 { 384 * IPv6 binds fail, then our caller will log using the
385 /* we don't log 'EADDRINUSE' here since an IPv4 bind may 385 * errno preserved in 'eno' */
386 * fail if we already took the port on IPv6; if both IPv4 and 386 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "bind");
387 * IPv6 binds fail, then our caller will log using the 387 if (port != 0)
388 * errno preserved in 'eno' */ 388 LOG (GNUNET_ERROR_TYPE_ERROR, _("`%s' failed for port %d (%s).\n"),
389 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "bind"); 389 "bind", port,
390 if (port != 0) 390 (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6");
391 LOG (GNUNET_ERROR_TYPE_ERROR, 391 eno = 0;
392 _("`%s' failed for port %d (%s).\n"), "bind", port,
393 (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6");
394 eno = 0;
395 }
396 else
397 {
398 if (port != 0)
399 LOG (GNUNET_ERROR_TYPE_WARNING,
400 _("`%s' failed for port %d (%s): address already in use\n"),
401 "bind", port,
402 (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6");
403 else if (serverAddr->sa_family == AF_UNIX)
404 LOG (GNUNET_ERROR_TYPE_WARNING,
405 _("`%s' failed for `%s': address already in use\n"), "bind",
406 ((const struct sockaddr_un *) serverAddr)->sun_path);
407
408 }
409 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
410 errno = eno;
411 return NULL;
412 } 392 }
413 if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 5)) 393 else
414 { 394 {
415 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "listen"); 395 if (port != 0)
416 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); 396 LOG (GNUNET_ERROR_TYPE_WARNING,
417 errno = 0; 397 _("`%s' failed for port %d (%s): address already in use\n"),
418 return NULL; 398 "bind", port,
399 (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6");
400 else if (serverAddr->sa_family == AF_UNIX)
401 LOG (GNUNET_ERROR_TYPE_WARNING,
402 _("`%s' failed for `%s': address already in use\n"), "bind",
403 ((const struct sockaddr_un *) serverAddr)->sun_path);
404
419 } 405 }
406 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
407 errno = eno;
408 return NULL;
409 }
410 if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 5))
411 {
412 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "listen");
413 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
414 errno = 0;
415 return NULL;
416 }
420#if DEBUG_SERVER 417#if DEBUG_SERVER
421 if (port != 0) 418 if (port != 0)
422 LOG (GNUNET_ERROR_TYPE_DEBUG, 419 LOG (GNUNET_ERROR_TYPE_DEBUG, "Server starts to listen on port %u.\n",
423 "Server starts to listen on port %u.\n", port); 420 port);
424#endif 421#endif
425 return sock; 422 return sock;
426} 423}
@@ -440,10 +437,10 @@ open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen)
440 */ 437 */
441struct GNUNET_SERVER_Handle * 438struct GNUNET_SERVER_Handle *
442GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access, 439GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access,
443 void *access_cls, 440 void *access_cls,
444 struct GNUNET_NETWORK_Handle **lsocks, 441 struct GNUNET_NETWORK_Handle **lsocks,
445 struct GNUNET_TIME_Relative idle_timeout, 442 struct GNUNET_TIME_Relative idle_timeout,
446 int require_found) 443 int require_found)
447{ 444{
448 struct GNUNET_SERVER_Handle *ret; 445 struct GNUNET_SERVER_Handle *ret;
449 struct GNUNET_NETWORK_FDSet *r; 446 struct GNUNET_NETWORK_FDSet *r;
@@ -456,18 +453,18 @@ GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access,
456 ret->access_cls = access_cls; 453 ret->access_cls = access_cls;
457 ret->require_found = require_found; 454 ret->require_found = require_found;
458 if (lsocks != NULL) 455 if (lsocks != NULL)
459 { 456 {
460 r = GNUNET_NETWORK_fdset_create (); 457 r = GNUNET_NETWORK_fdset_create ();
461 i = 0; 458 i = 0;
462 while (NULL != ret->listen_sockets[i]) 459 while (NULL != ret->listen_sockets[i])
463 GNUNET_NETWORK_fdset_set (r, ret->listen_sockets[i++]); 460 GNUNET_NETWORK_fdset_set (r, ret->listen_sockets[i++]);
464 ret->listen_task = 461 ret->listen_task =
465 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, 462 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
466 GNUNET_SCHEDULER_NO_TASK, 463 GNUNET_SCHEDULER_NO_TASK,
467 GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, 464 GNUNET_TIME_UNIT_FOREVER_REL, r, NULL,
468 &process_listen_socket, ret); 465 &process_listen_socket, ret);
469 GNUNET_NETWORK_fdset_destroy (r); 466 GNUNET_NETWORK_fdset_destroy (r);
470 } 467 }
471 return ret; 468 return ret;
472} 469}
473 470
@@ -487,10 +484,10 @@ GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access,
487 */ 484 */
488struct GNUNET_SERVER_Handle * 485struct GNUNET_SERVER_Handle *
489GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access, void *access_cls, 486GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access, void *access_cls,
490 struct sockaddr *const *serverAddr, 487 struct sockaddr *const *serverAddr,
491 const socklen_t * socklen, 488 const socklen_t * socklen,
492 struct GNUNET_TIME_Relative idle_timeout, 489 struct GNUNET_TIME_Relative idle_timeout,
493 int require_found) 490 int require_found)
494{ 491{
495 struct GNUNET_NETWORK_Handle **lsocks; 492 struct GNUNET_NETWORK_Handle **lsocks;
496 unsigned int i; 493 unsigned int i;
@@ -500,32 +497,31 @@ GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access, void *access_cls,
500 while (serverAddr[i] != NULL) 497 while (serverAddr[i] != NULL)
501 i++; 498 i++;
502 if (i > 0) 499 if (i > 0)
500 {
501 lsocks = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (i + 1));
502 i = 0;
503 j = 0;
504 while (serverAddr[i] != NULL)
503 { 505 {
504 lsocks = 506 lsocks[j] = open_listen_socket (serverAddr[i], socklen[i]);
505 GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (i + 1)); 507 if (lsocks[j] != NULL)
506 i = 0; 508 j++;
507 j = 0; 509 i++;
508 while (serverAddr[i] != NULL)
509 {
510 lsocks[j] = open_listen_socket (serverAddr[i], socklen[i]);
511 if (lsocks[j] != NULL)
512 j++;
513 i++;
514 }
515 if (j == 0)
516 {
517 if (errno != 0)
518 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "bind");
519 GNUNET_free (lsocks);
520 lsocks = NULL;
521 }
522 } 510 }
523 else 511 if (j == 0)
524 { 512 {
513 if (errno != 0)
514 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "bind");
515 GNUNET_free (lsocks);
525 lsocks = NULL; 516 lsocks = NULL;
526 } 517 }
518 }
519 else
520 {
521 lsocks = NULL;
522 }
527 return GNUNET_SERVER_create_with_sockets (access, access_cls, lsocks, 523 return GNUNET_SERVER_create_with_sockets (access, access_cls, lsocks,
528 idle_timeout, require_found); 524 idle_timeout, require_found);
529} 525}
530 526
531 527
@@ -545,32 +541,32 @@ GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *s)
545 LOG (GNUNET_ERROR_TYPE_DEBUG, "Server shutting down.\n"); 541 LOG (GNUNET_ERROR_TYPE_DEBUG, "Server shutting down.\n");
546#endif 542#endif
547 if (GNUNET_SCHEDULER_NO_TASK != s->listen_task) 543 if (GNUNET_SCHEDULER_NO_TASK != s->listen_task)
548 { 544 {
549 GNUNET_SCHEDULER_cancel (s->listen_task); 545 GNUNET_SCHEDULER_cancel (s->listen_task);
550 s->listen_task = GNUNET_SCHEDULER_NO_TASK; 546 s->listen_task = GNUNET_SCHEDULER_NO_TASK;
551 } 547 }
552 if (s->listen_sockets != NULL) 548 if (s->listen_sockets != NULL)
553 { 549 {
554 i = 0; 550 i = 0;
555 while (s->listen_sockets[i] != NULL) 551 while (s->listen_sockets[i] != NULL)
556 GNUNET_break (GNUNET_OK == 552 GNUNET_break (GNUNET_OK ==
557 GNUNET_NETWORK_socket_close (s->listen_sockets[i++])); 553 GNUNET_NETWORK_socket_close (s->listen_sockets[i++]));
558 GNUNET_free (s->listen_sockets); 554 GNUNET_free (s->listen_sockets);
559 s->listen_sockets = NULL; 555 s->listen_sockets = NULL;
560 } 556 }
561 while (s->clients != NULL) 557 while (s->clients != NULL)
562 GNUNET_SERVER_client_disconnect (s->clients); 558 GNUNET_SERVER_client_disconnect (s->clients);
563 while (NULL != (hpos = s->handlers)) 559 while (NULL != (hpos = s->handlers))
564 { 560 {
565 s->handlers = hpos->next; 561 s->handlers = hpos->next;
566 GNUNET_free (hpos); 562 GNUNET_free (hpos);
567 } 563 }
568 while (NULL != (npos = s->disconnect_notify_list)) 564 while (NULL != (npos = s->disconnect_notify_list))
569 { 565 {
570 npos->callback (npos->callback_cls, NULL); 566 npos->callback (npos->callback_cls, NULL);
571 s->disconnect_notify_list = npos->next; 567 s->disconnect_notify_list = npos->next;
572 GNUNET_free (npos); 568 GNUNET_free (npos);
573 } 569 }
574 GNUNET_free (s); 570 GNUNET_free (s);
575} 571}
576 572
@@ -590,8 +586,7 @@ GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *s)
590 */ 586 */
591void 587void
592GNUNET_SERVER_add_handlers (struct GNUNET_SERVER_Handle *server, 588GNUNET_SERVER_add_handlers (struct GNUNET_SERVER_Handle *server,
593 const struct GNUNET_SERVER_MessageHandler 589 const struct GNUNET_SERVER_MessageHandler *handlers)
594 *handlers)
595{ 590{
596 struct HandlerList *p; 591 struct HandlerList *p;
597 592
@@ -609,21 +604,20 @@ GNUNET_SERVER_add_handlers (struct GNUNET_SERVER_Handle *server,
609 * @param tc scheduler context (unused) 604 * @param tc scheduler context (unused)
610 */ 605 */
611static void 606static void
612warn_no_receive_done (void *cls, 607warn_no_receive_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
613 const struct GNUNET_SCHEDULER_TaskContext *tc)
614{ 608{
615 struct GNUNET_SERVER_Client *client = cls; 609 struct GNUNET_SERVER_Client *client = cls;
616 610
617 client->warn_task = 611 client->warn_task =
618 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 612 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
619 &warn_no_receive_done, client); 613 &warn_no_receive_done, client);
620 if (0 == (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) 614 if (0 == (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
621 LOG (GNUNET_ERROR_TYPE_WARNING, 615 LOG (GNUNET_ERROR_TYPE_WARNING,
622 _ 616 _
623 ("Processing code for message of type %u did not call GNUNET_SERVER_receive_done after %llums\n"), 617 ("Processing code for message of type %u did not call GNUNET_SERVER_receive_done after %llums\n"),
624 (unsigned int) client->warn_type, 618 (unsigned int) client->warn_type,
625 (unsigned long long) 619 (unsigned long long)
626 GNUNET_TIME_absolute_get_duration (client->warn_start).rel_value); 620 GNUNET_TIME_absolute_get_duration (client->warn_start).rel_value);
627} 621}
628 622
629 623
@@ -635,14 +629,13 @@ warn_no_receive_done (void *cls,
635 * @param client client for which to disable the warning 629 * @param client client for which to disable the warning
636 */ 630 */
637void 631void
638GNUNET_SERVER_disable_receive_done_warning (struct GNUNET_SERVER_Client 632GNUNET_SERVER_disable_receive_done_warning (struct GNUNET_SERVER_Client *client)
639 *client)
640{ 633{
641 if (GNUNET_SCHEDULER_NO_TASK != client->warn_task) 634 if (GNUNET_SCHEDULER_NO_TASK != client->warn_task)
642 { 635 {
643 GNUNET_SCHEDULER_cancel (client->warn_task); 636 GNUNET_SCHEDULER_cancel (client->warn_task);
644 client->warn_task = GNUNET_SCHEDULER_NO_TASK; 637 client->warn_task = GNUNET_SCHEDULER_NO_TASK;
645 } 638 }
646} 639}
647 640
648 641
@@ -663,8 +656,8 @@ GNUNET_SERVER_disable_receive_done_warning (struct GNUNET_SERVER_Client
663 */ 656 */
664int 657int
665GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server, 658GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server,
666 struct GNUNET_SERVER_Client *sender, 659 struct GNUNET_SERVER_Client *sender,
667 const struct GNUNET_MessageHeader *message) 660 const struct GNUNET_MessageHeader *message)
668{ 661{
669 struct HandlerList *pos; 662 struct HandlerList *pos;
670 const struct GNUNET_SERVER_MessageHandler *mh; 663 const struct GNUNET_SERVER_MessageHandler *mh;
@@ -684,50 +677,49 @@ GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server,
684 pos = server->handlers; 677 pos = server->handlers;
685 found = GNUNET_NO; 678 found = GNUNET_NO;
686 while (pos != NULL) 679 while (pos != NULL)
680 {
681 i = 0;
682 while (pos->handlers[i].callback != NULL)
687 { 683 {
688 i = 0; 684 mh = &pos->handlers[i];
689 while (pos->handlers[i].callback != NULL) 685 if ((mh->type == type) || (mh->type == GNUNET_MESSAGE_TYPE_ALL))
690 { 686 {
691 mh = &pos->handlers[i]; 687 if ((mh->expected_size != 0) && (mh->expected_size != size))
692 if ((mh->type == type) || (mh->type == GNUNET_MESSAGE_TYPE_ALL)) 688 {
693 {
694 if ((mh->expected_size != 0) && (mh->expected_size != size))
695 {
696#if GNUNET8_NETWORK_IS_DEAD 689#if GNUNET8_NETWORK_IS_DEAD
697 LOG (GNUNET_ERROR_TYPE_WARNING, 690 LOG (GNUNET_ERROR_TYPE_WARNING,
698 "Expected %u bytes for message of type %u, got %u\n", 691 "Expected %u bytes for message of type %u, got %u\n",
699 mh->expected_size, mh->type, size); 692 mh->expected_size, mh->type, size);
700 GNUNET_break_op (0); 693 GNUNET_break_op (0);
701#endif 694#endif
702 return GNUNET_SYSERR; 695 return GNUNET_SYSERR;
703 } 696 }
704 if (sender != NULL) 697 if (sender != NULL)
705 { 698 {
706 if (0 == sender->suspended) 699 if (0 == sender->suspended)
707 { 700 {
708 sender->warn_start = GNUNET_TIME_absolute_get (); 701 sender->warn_start = GNUNET_TIME_absolute_get ();
709 sender->warn_task = 702 sender->warn_task =
710 GNUNET_SCHEDULER_add_delayed 703 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
711 (GNUNET_TIME_UNIT_MINUTES, &warn_no_receive_done, 704 &warn_no_receive_done, sender);
712 sender); 705 sender->warn_type = type;
713 sender->warn_type = type; 706 }
714 } 707 sender->suspended++;
715 sender->suspended++; 708 }
716 } 709 mh->callback (mh->callback_cls, sender, message);
717 mh->callback (mh->callback_cls, sender, message); 710 found = GNUNET_YES;
718 found = GNUNET_YES; 711 }
719 } 712 i++;
720 i++;
721 }
722 pos = pos->next;
723 } 713 }
714 pos = pos->next;
715 }
724 if (found == GNUNET_NO) 716 if (found == GNUNET_NO)
725 { 717 {
726 LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 718 LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
727 "Received message of unknown type %d\n", type); 719 "Received message of unknown type %d\n", type);
728 if (server->require_found == GNUNET_YES) 720 if (server->require_found == GNUNET_YES)
729 return GNUNET_SYSERR; 721 return GNUNET_SYSERR;
730 } 722 }
731 return GNUNET_OK; 723 return GNUNET_OK;
732} 724}
733 725
@@ -744,8 +736,7 @@ GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server,
744 */ 736 */
745static void 737static void
746process_incoming (void *cls, const void *buf, size_t available, 738process_incoming (void *cls, const void *buf, size_t available,
747 const struct sockaddr *addr, socklen_t addrlen, 739 const struct sockaddr *addr, socklen_t addrlen, int errCode);
748 int errCode);
749 740
750 741
751/** 742/**
@@ -765,44 +756,44 @@ static void
765process_mst (struct GNUNET_SERVER_Client *client, int ret) 756process_mst (struct GNUNET_SERVER_Client *client, int ret)
766{ 757{
767 while ((ret != GNUNET_SYSERR) && (client->server != NULL) && 758 while ((ret != GNUNET_SYSERR) && (client->server != NULL) &&
768 (GNUNET_YES != client->shutdown_now) && (0 == client->suspended)) 759 (GNUNET_YES != client->shutdown_now) && (0 == client->suspended))
760 {
761 if (ret == GNUNET_OK)
769 { 762 {
770 if (ret == GNUNET_OK) 763 client->receive_pending = GNUNET_YES;
771 {
772 client->receive_pending = GNUNET_YES;
773#if DEBUG_SERVER
774 LOG (GNUNET_ERROR_TYPE_DEBUG,
775 "Server re-enters receive loop, timeout: %llu.\n",
776 client->idle_timeout.rel_value);
777#endif
778 GNUNET_CONNECTION_receive (client->connection,
779 GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
780 client->idle_timeout, &process_incoming,
781 client);
782 break;
783 }
784#if DEBUG_SERVER 764#if DEBUG_SERVER
785 LOG (GNUNET_ERROR_TYPE_DEBUG, 765 LOG (GNUNET_ERROR_TYPE_DEBUG,
786 "Server processes additional messages instantly.\n"); 766 "Server re-enters receive loop, timeout: %llu.\n",
767 client->idle_timeout.rel_value);
787#endif 768#endif
788 ret = 769 GNUNET_CONNECTION_receive (client->connection,
789 GNUNET_SERVER_mst_receive (client->mst, client, NULL, 0, GNUNET_NO, 770 GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
790 GNUNET_YES); 771 client->idle_timeout, &process_incoming,
772 client);
773 break;
791 } 774 }
792#if DEBUG_SERVER 775#if DEBUG_SERVER
776 LOG (GNUNET_ERROR_TYPE_DEBUG,
777 "Server processes additional messages instantly.\n");
778#endif
779 ret =
780 GNUNET_SERVER_mst_receive (client->mst, client, NULL, 0, GNUNET_NO,
781 GNUNET_YES);
782 }
783#if DEBUG_SERVER
793 LOG (GNUNET_ERROR_TYPE_DEBUG, 784 LOG (GNUNET_ERROR_TYPE_DEBUG,
794 "Server leaves instant processing loop: ret = %d, server = %p, shutdown = %d, suspended = %u\n", 785 "Server leaves instant processing loop: ret = %d, server = %p, shutdown = %d, suspended = %u\n",
795 ret, client->server, client->shutdown_now, client->suspended); 786 ret, client->server, client->shutdown_now, client->suspended);
796#endif 787#endif
797 788
798 if (ret == GNUNET_NO) 789 if (ret == GNUNET_NO)
799 { 790 {
800#if DEBUG_SERVER 791#if DEBUG_SERVER
801 LOG (GNUNET_ERROR_TYPE_DEBUG, 792 LOG (GNUNET_ERROR_TYPE_DEBUG,
802 "Server has more data pending but is suspended.\n"); 793 "Server has more data pending but is suspended.\n");
803#endif 794#endif
804 client->receive_pending = GNUNET_SYSERR; /* data pending */ 795 client->receive_pending = GNUNET_SYSERR; /* data pending */
805 } 796 }
806 if ((ret == GNUNET_SYSERR) || (GNUNET_YES == client->shutdown_now)) 797 if ((ret == GNUNET_SYSERR) || (GNUNET_YES == client->shutdown_now))
807 GNUNET_SERVER_client_disconnect (client); 798 GNUNET_SERVER_client_disconnect (client);
808 GNUNET_SERVER_client_drop (client); 799 GNUNET_SERVER_client_drop (client);
@@ -821,7 +812,7 @@ process_mst (struct GNUNET_SERVER_Client *client, int ret)
821 */ 812 */
822static void 813static void
823process_incoming (void *cls, const void *buf, size_t available, 814process_incoming (void *cls, const void *buf, size_t available,
824 const struct sockaddr *addr, socklen_t addrlen, int errCode) 815 const struct sockaddr *addr, socklen_t addrlen, int errCode)
825{ 816{
826 struct GNUNET_SERVER_Client *client = cls; 817 struct GNUNET_SERVER_Client *client = cls;
827 struct GNUNET_SERVER_Handle *server = client->server; 818 struct GNUNET_SERVER_Handle *server = client->server;
@@ -832,35 +823,34 @@ process_incoming (void *cls, const void *buf, size_t available,
832 GNUNET_assert (client->receive_pending == GNUNET_YES); 823 GNUNET_assert (client->receive_pending == GNUNET_YES);
833 client->receive_pending = GNUNET_NO; 824 client->receive_pending = GNUNET_NO;
834 now = GNUNET_TIME_absolute_get (); 825 now = GNUNET_TIME_absolute_get ();
835 end = 826 end = GNUNET_TIME_absolute_add (client->last_activity, client->idle_timeout);
836 GNUNET_TIME_absolute_add (client->last_activity, client->idle_timeout);
837 827
838 if ((buf == NULL) && (available == 0) && (addr == NULL) && (errCode == 0) && 828 if ((buf == NULL) && (available == 0) && (addr == NULL) && (errCode == 0) &&
839 (client->shutdown_now != GNUNET_YES) && (server != NULL) && 829 (client->shutdown_now != GNUNET_YES) && (server != NULL) &&
840 (GNUNET_YES == GNUNET_CONNECTION_check (client->connection)) && 830 (GNUNET_YES == GNUNET_CONNECTION_check (client->connection)) &&
841 (end.abs_value > now.abs_value)) 831 (end.abs_value > now.abs_value))
842 { 832 {
843 /* wait longer, timeout changed (i.e. due to us sending) */ 833 /* wait longer, timeout changed (i.e. due to us sending) */
844#if DEBUG_SERVER 834#if DEBUG_SERVER
845 LOG (GNUNET_ERROR_TYPE_DEBUG, 835 LOG (GNUNET_ERROR_TYPE_DEBUG,
846 "Receive time out, but no disconnect due to sending (%p)\n", 836 "Receive time out, but no disconnect due to sending (%p)\n",
847 GNUNET_a2s (addr, addrlen)); 837 GNUNET_a2s (addr, addrlen));
848#endif 838#endif
849 client->receive_pending = GNUNET_YES; 839 client->receive_pending = GNUNET_YES;
850 GNUNET_CONNECTION_receive (client->connection, 840 GNUNET_CONNECTION_receive (client->connection,
851 GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, 841 GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
852 GNUNET_TIME_absolute_get_remaining (end), 842 GNUNET_TIME_absolute_get_remaining (end),
853 &process_incoming, client); 843 &process_incoming, client);
854 return; 844 return;
855 } 845 }
856 if ((buf == NULL) || (available == 0) || (errCode != 0) || (server == NULL) 846 if ((buf == NULL) || (available == 0) || (errCode != 0) || (server == NULL) ||
857 || (client->shutdown_now == GNUNET_YES) 847 (client->shutdown_now == GNUNET_YES) ||
858 || (GNUNET_YES != GNUNET_CONNECTION_check (client->connection))) 848 (GNUNET_YES != GNUNET_CONNECTION_check (client->connection)))
859 { 849 {
860 /* other side closed connection, error connecting, etc. */ 850 /* other side closed connection, error connecting, etc. */
861 GNUNET_SERVER_client_disconnect (client); 851 GNUNET_SERVER_client_disconnect (client);
862 return; 852 return;
863 } 853 }
864#if DEBUG_SERVER 854#if DEBUG_SERVER
865 LOG (GNUNET_ERROR_TYPE_DEBUG, "Server receives %u bytes from `%s'.\n", 855 LOG (GNUNET_ERROR_TYPE_DEBUG, "Server receives %u bytes from `%s'.\n",
866 (unsigned int) available, GNUNET_a2s (addr, addrlen)); 856 (unsigned int) available, GNUNET_a2s (addr, addrlen));
@@ -868,8 +858,8 @@ process_incoming (void *cls, const void *buf, size_t available,
868 GNUNET_SERVER_client_keep (client); 858 GNUNET_SERVER_client_keep (client);
869 client->last_activity = now; 859 client->last_activity = now;
870 ret = 860 ret =
871 GNUNET_SERVER_mst_receive (client->mst, client, buf, available, GNUNET_NO, 861 GNUNET_SERVER_mst_receive (client->mst, client, buf, available, GNUNET_NO,
872 GNUNET_YES); 862 GNUNET_YES);
873 process_mst (client, ret); 863 process_mst (client, ret);
874} 864}
875 865
@@ -890,23 +880,21 @@ restart_processing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
890 client->restart_task = GNUNET_SCHEDULER_NO_TASK; 880 client->restart_task = GNUNET_SCHEDULER_NO_TASK;
891 if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) && 881 if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) &&
892 (GNUNET_NO == server->clients_ignore_shutdown)) 882 (GNUNET_NO == server->clients_ignore_shutdown))
893 { 883 {
894 GNUNET_SERVER_client_disconnect (client); 884 GNUNET_SERVER_client_disconnect (client);
895 return; 885 return;
896 } 886 }
897 if (client->receive_pending == GNUNET_NO) 887 if (client->receive_pending == GNUNET_NO)
898 { 888 {
899#if DEBUG_SERVER 889#if DEBUG_SERVER
900 LOG (GNUNET_ERROR_TYPE_DEBUG, 890 LOG (GNUNET_ERROR_TYPE_DEBUG, "Server begins to read again from client.\n");
901 "Server begins to read again from client.\n");
902#endif 891#endif
903 client->receive_pending = GNUNET_YES; 892 client->receive_pending = GNUNET_YES;
904 GNUNET_CONNECTION_receive (client->connection, 893 GNUNET_CONNECTION_receive (client->connection,
905 GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, 894 GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
906 client->idle_timeout, &process_incoming, 895 client->idle_timeout, &process_incoming, client);
907 client); 896 return;
908 return; 897 }
909 }
910#if DEBUG_SERVER 898#if DEBUG_SERVER
911 LOG (GNUNET_ERROR_TYPE_DEBUG, 899 LOG (GNUNET_ERROR_TYPE_DEBUG,
912 "Server continues processing messages still in the buffer.\n"); 900 "Server continues processing messages still in the buffer.\n");
@@ -927,7 +915,7 @@ restart_processing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
927 */ 915 */
928static void 916static void
929client_message_tokenizer_callback (void *cls, void *client, 917client_message_tokenizer_callback (void *cls, void *client,
930 const struct GNUNET_MessageHeader *message) 918 const struct GNUNET_MessageHeader *message)
931{ 919{
932 struct GNUNET_SERVER_Handle *server = cls; 920 struct GNUNET_SERVER_Handle *server = cls;
933 struct GNUNET_SERVER_Client *sender = client; 921 struct GNUNET_SERVER_Client *sender = client;
@@ -961,14 +949,14 @@ client_message_tokenizer_callback (void *cls, void *client,
961 */ 949 */
962struct GNUNET_SERVER_Client * 950struct GNUNET_SERVER_Client *
963GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server, 951GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server,
964 struct GNUNET_CONNECTION_Handle *connection) 952 struct GNUNET_CONNECTION_Handle *connection)
965{ 953{
966 struct GNUNET_SERVER_Client *client; 954 struct GNUNET_SERVER_Client *client;
967 955
968 client = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Client)); 956 client = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Client));
969 client->connection = connection; 957 client->connection = connection;
970 client->mst = 958 client->mst =
971 GNUNET_SERVER_mst_create (&client_message_tokenizer_callback, server); 959 GNUNET_SERVER_mst_create (&client_message_tokenizer_callback, server);
972 client->reference_count = 1; 960 client->reference_count = 1;
973 client->server = server; 961 client->server = server;
974 client->last_activity = GNUNET_TIME_absolute_get (); 962 client->last_activity = GNUNET_TIME_absolute_get ();
@@ -979,8 +967,8 @@ GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server,
979 client->callback = NULL; 967 client->callback = NULL;
980 client->callback_cls = NULL; 968 client->callback_cls = NULL;
981 GNUNET_CONNECTION_receive (client->connection, 969 GNUNET_CONNECTION_receive (client->connection,
982 GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, 970 GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
983 client->idle_timeout, &process_incoming, client); 971 client->idle_timeout, &process_incoming, client);
984 return client; 972 return client;
985} 973}
986 974
@@ -995,7 +983,7 @@ GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server,
995 */ 983 */
996void 984void
997GNUNET_SERVER_client_set_timeout (struct GNUNET_SERVER_Client *client, 985GNUNET_SERVER_client_set_timeout (struct GNUNET_SERVER_Client *client,
998 struct GNUNET_TIME_Relative timeout) 986 struct GNUNET_TIME_Relative timeout)
999{ 987{
1000 client->idle_timeout = timeout; 988 client->idle_timeout = timeout;
1001} 989}
@@ -1043,7 +1031,7 @@ GNUNET_SERVER_client_drop (struct GNUNET_SERVER_Client *client)
1043 */ 1031 */
1044int 1032int
1045GNUNET_SERVER_client_get_address (struct GNUNET_SERVER_Client *client, 1033GNUNET_SERVER_client_get_address (struct GNUNET_SERVER_Client *client,
1046 void **addr, size_t * addrlen) 1034 void **addr, size_t * addrlen)
1047{ 1035{
1048 return GNUNET_CONNECTION_get_address (client->connection, addr, addrlen); 1036 return GNUNET_CONNECTION_get_address (client->connection, addr, addrlen);
1049} 1037}
@@ -1061,8 +1049,8 @@ GNUNET_SERVER_client_get_address (struct GNUNET_SERVER_Client *client,
1061 */ 1049 */
1062void 1050void
1063GNUNET_SERVER_disconnect_notify (struct GNUNET_SERVER_Handle *server, 1051GNUNET_SERVER_disconnect_notify (struct GNUNET_SERVER_Handle *server,
1064 GNUNET_SERVER_DisconnectCallback callback, 1052 GNUNET_SERVER_DisconnectCallback callback,
1065 void *callback_cls) 1053 void *callback_cls)
1066{ 1054{
1067 struct NotifyList *n; 1055 struct NotifyList *n;
1068 1056
@@ -1083,8 +1071,8 @@ GNUNET_SERVER_disconnect_notify (struct GNUNET_SERVER_Handle *server,
1083 */ 1071 */
1084void 1072void
1085GNUNET_SERVER_disconnect_notify_cancel (struct GNUNET_SERVER_Handle *server, 1073GNUNET_SERVER_disconnect_notify_cancel (struct GNUNET_SERVER_Handle *server,
1086 GNUNET_SERVER_DisconnectCallback 1074 GNUNET_SERVER_DisconnectCallback
1087 callback, void *callback_cls) 1075 callback, void *callback_cls)
1088{ 1076{
1089 struct NotifyList *pos; 1077 struct NotifyList *pos;
1090 struct NotifyList *prev; 1078 struct NotifyList *prev;
@@ -1092,17 +1080,17 @@ GNUNET_SERVER_disconnect_notify_cancel (struct GNUNET_SERVER_Handle *server,
1092 prev = NULL; 1080 prev = NULL;
1093 pos = server->disconnect_notify_list; 1081 pos = server->disconnect_notify_list;
1094 while (pos != NULL) 1082 while (pos != NULL)
1095 { 1083 {
1096 if ((pos->callback == callback) && (pos->callback_cls == callback_cls)) 1084 if ((pos->callback == callback) && (pos->callback_cls == callback_cls))
1097 break; 1085 break;
1098 prev = pos; 1086 prev = pos;
1099 pos = pos->next; 1087 pos = pos->next;
1100 } 1088 }
1101 if (pos == NULL) 1089 if (pos == NULL)
1102 { 1090 {
1103 GNUNET_break (0); 1091 GNUNET_break (0);
1104 return; 1092 return;
1105 } 1093 }
1106 if (prev == NULL) 1094 if (prev == NULL)
1107 server->disconnect_notify_list = pos->next; 1095 server->disconnect_notify_list = pos->next;
1108 else 1096 else
@@ -1133,72 +1121,72 @@ GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client)
1133 "Client is being disconnected from the server.\n"); 1121 "Client is being disconnected from the server.\n");
1134#endif 1122#endif
1135 if (client->restart_task != GNUNET_SCHEDULER_NO_TASK) 1123 if (client->restart_task != GNUNET_SCHEDULER_NO_TASK)
1124 {
1125 GNUNET_SCHEDULER_cancel (client->restart_task);
1126 client->restart_task = GNUNET_SCHEDULER_NO_TASK;
1127 }
1128 if (client->warn_task != GNUNET_SCHEDULER_NO_TASK)
1129 {
1130 GNUNET_SCHEDULER_cancel (client->warn_task);
1131 client->warn_task = GNUNET_SCHEDULER_NO_TASK;
1132 }
1133 if (GNUNET_YES == client->receive_pending)
1134 {
1135 GNUNET_CONNECTION_receive_cancel (client->connection);
1136 client->receive_pending = GNUNET_NO;
1137 }
1138
1139 rc = client->reference_count;
1140 if (client->server != NULL)
1141 {
1142 server = client->server;
1143 client->server = NULL;
1144 client->shutdown_now = GNUNET_YES;
1145 prev = NULL;
1146 pos = server->clients;
1147 while ((pos != NULL) && (pos != client))
1148 {
1149 prev = pos;
1150 pos = pos->next;
1151 }
1152 GNUNET_assert (pos != NULL);
1153 if (prev == NULL)
1154 server->clients = pos->next;
1155 else
1156 prev->next = pos->next;
1157 if (client->restart_task != GNUNET_SCHEDULER_NO_TASK)
1136 { 1158 {
1137 GNUNET_SCHEDULER_cancel (client->restart_task); 1159 GNUNET_SCHEDULER_cancel (client->restart_task);
1138 client->restart_task = GNUNET_SCHEDULER_NO_TASK; 1160 client->restart_task = GNUNET_SCHEDULER_NO_TASK;
1139 } 1161 }
1140 if (client->warn_task != GNUNET_SCHEDULER_NO_TASK) 1162 if (client->warn_task != GNUNET_SCHEDULER_NO_TASK)
1141 { 1163 {
1142 GNUNET_SCHEDULER_cancel (client->warn_task); 1164 GNUNET_SCHEDULER_cancel (client->warn_task);
1143 client->warn_task = GNUNET_SCHEDULER_NO_TASK; 1165 client->warn_task = GNUNET_SCHEDULER_NO_TASK;
1144 } 1166 }
1145 if (GNUNET_YES == client->receive_pending) 1167 n = server->disconnect_notify_list;
1146 { 1168 while (n != NULL)
1147 GNUNET_CONNECTION_receive_cancel (client->connection);
1148 client->receive_pending = GNUNET_NO;
1149 }
1150
1151 rc = client->reference_count;
1152 if (client->server != NULL)
1153 { 1169 {
1154 server = client->server; 1170 n->callback (n->callback_cls, client);
1155 client->server = NULL; 1171 n = n->next;
1156 client->shutdown_now = GNUNET_YES;
1157 prev = NULL;
1158 pos = server->clients;
1159 while ((pos != NULL) && (pos != client))
1160 {
1161 prev = pos;
1162 pos = pos->next;
1163 }
1164 GNUNET_assert (pos != NULL);
1165 if (prev == NULL)
1166 server->clients = pos->next;
1167 else
1168 prev->next = pos->next;
1169 if (client->restart_task != GNUNET_SCHEDULER_NO_TASK)
1170 {
1171 GNUNET_SCHEDULER_cancel (client->restart_task);
1172 client->restart_task = GNUNET_SCHEDULER_NO_TASK;
1173 }
1174 if (client->warn_task != GNUNET_SCHEDULER_NO_TASK)
1175 {
1176 GNUNET_SCHEDULER_cancel (client->warn_task);
1177 client->warn_task = GNUNET_SCHEDULER_NO_TASK;
1178 }
1179 n = server->disconnect_notify_list;
1180 while (n != NULL)
1181 {
1182 n->callback (n->callback_cls, client);
1183 n = n->next;
1184 }
1185 } 1172 }
1173 }
1186 if (rc > 0) 1174 if (rc > 0)
1187 { 1175 {
1188#if DEBUG_SERVER 1176#if DEBUG_SERVER
1189 LOG (GNUNET_ERROR_TYPE_DEBUG, 1177 LOG (GNUNET_ERROR_TYPE_DEBUG,
1190 "RC still positive, not destroying everything.\n"); 1178 "RC still positive, not destroying everything.\n");
1191#endif 1179#endif
1192 return; 1180 return;
1193 } 1181 }
1194 if (client->in_process_client_buffer == GNUNET_YES) 1182 if (client->in_process_client_buffer == GNUNET_YES)
1195 { 1183 {
1196#if DEBUG_SERVER 1184#if DEBUG_SERVER
1197 LOG (GNUNET_ERROR_TYPE_DEBUG, 1185 LOG (GNUNET_ERROR_TYPE_DEBUG,
1198 "Still processing inputs, not destroying everything.\n"); 1186 "Still processing inputs, not destroying everything.\n");
1199#endif 1187#endif
1200 return; 1188 return;
1201 } 1189 }
1202 1190
1203 if (client->persist == GNUNET_YES) 1191 if (client->persist == GNUNET_YES)
1204 GNUNET_CONNECTION_persist_ (client->connection); 1192 GNUNET_CONNECTION_persist_ (client->connection);
@@ -1262,17 +1250,17 @@ transmit_ready_callback_wrapper (void *cls, size_t size, void *buf)
1262 */ 1250 */
1263struct GNUNET_CONNECTION_TransmitHandle * 1251struct GNUNET_CONNECTION_TransmitHandle *
1264GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client, 1252GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client,
1265 size_t size, 1253 size_t size,
1266 struct GNUNET_TIME_Relative timeout, 1254 struct GNUNET_TIME_Relative timeout,
1267 GNUNET_CONNECTION_TransmitReadyNotify 1255 GNUNET_CONNECTION_TransmitReadyNotify
1268 callback, void *callback_cls) 1256 callback, void *callback_cls)
1269{ 1257{
1270 client->callback_cls = callback_cls; 1258 client->callback_cls = callback_cls;
1271 client->callback = callback; 1259 client->callback = callback;
1272 return GNUNET_CONNECTION_notify_transmit_ready (client->connection, size, 1260 return GNUNET_CONNECTION_notify_transmit_ready (client->connection, size,
1273 timeout, 1261 timeout,
1274 &transmit_ready_callback_wrapper, 1262 &transmit_ready_callback_wrapper,
1275 client); 1263 client);
1276} 1264}
1277 1265
1278 1266
@@ -1309,47 +1297,46 @@ GNUNET_SERVER_receive_done (struct GNUNET_SERVER_Client *client, int success)
1309 GNUNET_assert (client->suspended > 0); 1297 GNUNET_assert (client->suspended > 0);
1310 client->suspended--; 1298 client->suspended--;
1311 if (success != GNUNET_OK) 1299 if (success != GNUNET_OK)
1312 { 1300 {
1313#if DEBUG_SERVER 1301#if DEBUG_SERVER
1314 LOG (GNUNET_ERROR_TYPE_DEBUG, 1302 LOG (GNUNET_ERROR_TYPE_DEBUG,
1315 "GNUNET_SERVER_receive_done called with failure indication\n"); 1303 "GNUNET_SERVER_receive_done called with failure indication\n");
1316#endif 1304#endif
1317 GNUNET_SERVER_client_disconnect (client); 1305 GNUNET_SERVER_client_disconnect (client);
1318 return; 1306 return;
1319 } 1307 }
1320 if (client->suspended > 0) 1308 if (client->suspended > 0)
1321 { 1309 {
1322#if DEBUG_SERVER 1310#if DEBUG_SERVER
1323 LOG (GNUNET_ERROR_TYPE_DEBUG, 1311 LOG (GNUNET_ERROR_TYPE_DEBUG,
1324 "GNUNET_SERVER_receive_done called, but more clients pending\n"); 1312 "GNUNET_SERVER_receive_done called, but more clients pending\n");
1325#endif 1313#endif
1326 return; 1314 return;
1327 } 1315 }
1328 if (GNUNET_SCHEDULER_NO_TASK != client->warn_task) 1316 if (GNUNET_SCHEDULER_NO_TASK != client->warn_task)
1329 { 1317 {
1330 GNUNET_SCHEDULER_cancel (client->warn_task); 1318 GNUNET_SCHEDULER_cancel (client->warn_task);
1331 client->warn_task = GNUNET_SCHEDULER_NO_TASK; 1319 client->warn_task = GNUNET_SCHEDULER_NO_TASK;
1332 } 1320 }
1333 if (client->in_process_client_buffer == GNUNET_YES) 1321 if (client->in_process_client_buffer == GNUNET_YES)
1334 { 1322 {
1335#if DEBUG_SERVER 1323#if DEBUG_SERVER
1336 LOG (GNUNET_ERROR_TYPE_DEBUG, 1324 LOG (GNUNET_ERROR_TYPE_DEBUG,
1337 "GNUNET_SERVER_receive_done called while still in processing loop\n"); 1325 "GNUNET_SERVER_receive_done called while still in processing loop\n");
1338#endif 1326#endif
1339 return; 1327 return;
1340 } 1328 }
1341 if (client->server == NULL) 1329 if (client->server == NULL)
1342 { 1330 {
1343 GNUNET_SERVER_client_disconnect (client); 1331 GNUNET_SERVER_client_disconnect (client);
1344 return; 1332 return;
1345 } 1333 }
1346#if DEBUG_SERVER 1334#if DEBUG_SERVER
1347 LOG (GNUNET_ERROR_TYPE_DEBUG, 1335 LOG (GNUNET_ERROR_TYPE_DEBUG,
1348 "GNUNET_SERVER_receive_done causes restart in reading from the socket\n"); 1336 "GNUNET_SERVER_receive_done causes restart in reading from the socket\n");
1349#endif 1337#endif
1350 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == client->restart_task); 1338 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == client->restart_task);
1351 client->restart_task = 1339 client->restart_task = GNUNET_SCHEDULER_add_now (&restart_processing, client);
1352 GNUNET_SCHEDULER_add_now (&restart_processing, client);
1353} 1340}
1354 1341
1355 1342
diff --git a/src/util/server_mst.c b/src/util/server_mst.c
index 6fd2647d7..dcb8c4810 100644
--- a/src/util/server_mst.c
+++ b/src/util/server_mst.c
@@ -91,7 +91,7 @@ struct GNUNET_SERVER_MessageStreamTokenizer
91 */ 91 */
92struct GNUNET_SERVER_MessageStreamTokenizer * 92struct GNUNET_SERVER_MessageStreamTokenizer *
93GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb, 93GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb,
94 void *cb_cls) 94 void *cb_cls)
95{ 95{
96 struct GNUNET_SERVER_MessageStreamTokenizer *ret; 96 struct GNUNET_SERVER_MessageStreamTokenizer *ret;
97 97
@@ -121,8 +121,8 @@ GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb,
121 */ 121 */
122int 122int
123GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst, 123GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
124 void *client_identity, const char *buf, 124 void *client_identity, const char *buf, size_t size,
125 size_t size, int purge, int one_shot) 125 int purge, int one_shot)
126{ 126{
127 const struct GNUNET_MessageHeader *hdr; 127 const struct GNUNET_MessageHeader *hdr;
128 size_t delta; 128 size_t delta;
@@ -140,148 +140,148 @@ GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
140 ret = GNUNET_OK; 140 ret = GNUNET_OK;
141 ibuf = (char *) mst->hdr; 141 ibuf = (char *) mst->hdr;
142 while (mst->pos > 0) 142 while (mst->pos > 0)
143 {
144do_align:
145 if ((mst->curr_buf - mst->off < sizeof (struct GNUNET_MessageHeader)) ||
146 (0 != (mst->off % ALIGN_FACTOR)))
143 { 147 {
144 do_align: 148 /* need to align or need more space */
145 if ((mst->curr_buf - mst->off < sizeof (struct GNUNET_MessageHeader)) || 149 mst->pos -= mst->off;
146 (0 != (mst->off % ALIGN_FACTOR))) 150 memmove (ibuf, &ibuf[mst->off], mst->pos);
147 { 151 mst->off = 0;
148 /* need to align or need more space */ 152 }
149 mst->pos -= mst->off; 153 if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader))
150 memmove (ibuf, &ibuf[mst->off], mst->pos); 154 {
151 mst->off = 0; 155 delta =
152 } 156 GNUNET_MIN (sizeof (struct GNUNET_MessageHeader) -
153 if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader)) 157 (mst->pos - mst->off), size);
154 { 158 memcpy (&ibuf[mst->pos], buf, delta);
155 delta = 159 mst->pos += delta;
156 GNUNET_MIN (sizeof (struct GNUNET_MessageHeader) - 160 buf += delta;
157 (mst->pos - mst->off), size); 161 size -= delta;
158 memcpy (&ibuf[mst->pos], buf, delta); 162 }
159 mst->pos += delta; 163 if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader))
160 buf += delta; 164 {
161 size -= delta; 165 if (purge)
162 } 166 {
163 if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader)) 167 mst->off = 0;
164 { 168 mst->pos = 0;
165 if (purge) 169 }
166 { 170 return GNUNET_OK;
167 mst->off = 0; 171 }
168 mst->pos = 0; 172 hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
169 } 173 want = ntohs (hdr->size);
170 return GNUNET_OK; 174 if (want < sizeof (struct GNUNET_MessageHeader))
171 } 175 {
172 hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off]; 176 GNUNET_break_op (0);
177 return GNUNET_SYSERR;
178 }
179 if (mst->curr_buf - mst->off < want)
180 {
181 /* need more space */
182 mst->pos -= mst->off;
183 memmove (ibuf, &ibuf[mst->off], mst->pos);
184 mst->off = 0;
185 }
186 if (want > mst->curr_buf)
187 {
188 mst->hdr = GNUNET_realloc (mst->hdr, want);
189 ibuf = (char *) mst->hdr;
190 mst->curr_buf = want;
191 }
192 hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
193 if (mst->pos - mst->off < want)
194 {
195 delta = GNUNET_MIN (want - (mst->pos - mst->off), size);
196 memcpy (&ibuf[mst->pos], buf, delta);
197 mst->pos += delta;
198 buf += delta;
199 size -= delta;
200 }
201 if (mst->pos - mst->off < want)
202 {
203 if (purge)
204 {
205 mst->off = 0;
206 mst->pos = 0;
207 }
208 return GNUNET_OK;
209 }
210 if (one_shot == GNUNET_SYSERR)
211 {
212 /* cannot call callback again, but return value saying that
213 * we have another full message in the buffer */
214 ret = GNUNET_NO;
215 goto copy;
216 }
217 if (one_shot == GNUNET_YES)
218 one_shot = GNUNET_SYSERR;
219 mst->cb (mst->cb_cls, client_identity, hdr);
220 mst->off += want;
221 if (mst->off == mst->pos)
222 {
223 /* reset to beginning of buffer, it's free right now! */
224 mst->off = 0;
225 mst->pos = 0;
226 }
227 }
228 while (size > 0)
229 {
230#if DEBUG_SERVER_MST
231 LOG (GNUNET_ERROR_TYPE_DEBUG,
232 "Server-mst has %u bytes left in inbound buffer\n",
233 (unsigned int) size);
234#endif
235 if (size < sizeof (struct GNUNET_MessageHeader))
236 break;
237 offset = (unsigned long) buf;
238 need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO;
239 if (GNUNET_NO == need_align)
240 {
241 /* can try to do zero-copy and process directly from original buffer */
242 hdr = (const struct GNUNET_MessageHeader *) buf;
173 want = ntohs (hdr->size); 243 want = ntohs (hdr->size);
174 if (want < sizeof (struct GNUNET_MessageHeader)) 244 if (want < sizeof (struct GNUNET_MessageHeader))
175 { 245 {
176 GNUNET_break_op (0); 246 GNUNET_break_op (0);
177 return GNUNET_SYSERR; 247 mst->off = 0;
178 } 248 return GNUNET_SYSERR;
179 if (mst->curr_buf - mst->off < want) 249 }
180 { 250 if (size < want)
181 /* need more space */ 251 break; /* or not, buffer incomplete, so copy to private buffer... */
182 mst->pos -= mst->off;
183 memmove (ibuf, &ibuf[mst->off], mst->pos);
184 mst->off = 0;
185 }
186 if (want > mst->curr_buf)
187 {
188 mst->hdr = GNUNET_realloc (mst->hdr, want);
189 ibuf = (char *) mst->hdr;
190 mst->curr_buf = want;
191 }
192 hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
193 if (mst->pos - mst->off < want)
194 {
195 delta = GNUNET_MIN (want - (mst->pos - mst->off), size);
196 memcpy (&ibuf[mst->pos], buf, delta);
197 mst->pos += delta;
198 buf += delta;
199 size -= delta;
200 }
201 if (mst->pos - mst->off < want)
202 {
203 if (purge)
204 {
205 mst->off = 0;
206 mst->pos = 0;
207 }
208 return GNUNET_OK;
209 }
210 if (one_shot == GNUNET_SYSERR) 252 if (one_shot == GNUNET_SYSERR)
211 { 253 {
212 /* cannot call callback again, but return value saying that 254 /* cannot call callback again, but return value saying that
213 * we have another full message in the buffer */ 255 * we have another full message in the buffer */
214 ret = GNUNET_NO; 256 ret = GNUNET_NO;
215 goto copy; 257 goto copy;
216 } 258 }
217 if (one_shot == GNUNET_YES) 259 if (one_shot == GNUNET_YES)
218 one_shot = GNUNET_SYSERR; 260 one_shot = GNUNET_SYSERR;
219 mst->cb (mst->cb_cls, client_identity, hdr); 261 mst->cb (mst->cb_cls, client_identity, hdr);
220 mst->off += want; 262 buf += want;
221 if (mst->off == mst->pos) 263 size -= want;
222 {
223 /* reset to beginning of buffer, it's free right now! */
224 mst->off = 0;
225 mst->pos = 0;
226 }
227 } 264 }
228 while (size > 0) 265 else
229 { 266 {
230#if DEBUG_SERVER_MST 267 /* need to copy to private buffer to align;
231 LOG (GNUNET_ERROR_TYPE_DEBUG, 268 * yes, we go a bit more spagetti than usual here */
232 "Server-mst has %u bytes left in inbound buffer\n", 269 goto do_align;
233 (unsigned int) size);
234#endif
235 if (size < sizeof (struct GNUNET_MessageHeader))
236 break;
237 offset = (unsigned long) buf;
238 need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO;
239 if (GNUNET_NO == need_align)
240 {
241 /* can try to do zero-copy and process directly from original buffer */
242 hdr = (const struct GNUNET_MessageHeader *) buf;
243 want = ntohs (hdr->size);
244 if (want < sizeof (struct GNUNET_MessageHeader))
245 {
246 GNUNET_break_op (0);
247 mst->off = 0;
248 return GNUNET_SYSERR;
249 }
250 if (size < want)
251 break; /* or not, buffer incomplete, so copy to private buffer... */
252 if (one_shot == GNUNET_SYSERR)
253 {
254 /* cannot call callback again, but return value saying that
255 * we have another full message in the buffer */
256 ret = GNUNET_NO;
257 goto copy;
258 }
259 if (one_shot == GNUNET_YES)
260 one_shot = GNUNET_SYSERR;
261 mst->cb (mst->cb_cls, client_identity, hdr);
262 buf += want;
263 size -= want;
264 }
265 else
266 {
267 /* need to copy to private buffer to align;
268 * yes, we go a bit more spagetti than usual here */
269 goto do_align;
270 }
271 } 270 }
271 }
272copy: 272copy:
273 if ((size > 0) && (!purge)) 273 if ((size > 0) && (!purge))
274 {
275 if (size + mst->pos > mst->curr_buf)
274 { 276 {
275 if (size + mst->pos > mst->curr_buf) 277 mst->hdr = GNUNET_realloc (mst->hdr, size + mst->pos);
276 { 278 ibuf = (char *) mst->hdr;
277 mst->hdr = GNUNET_realloc (mst->hdr, size + mst->pos); 279 mst->curr_buf = size + mst->pos;
278 ibuf = (char *) mst->hdr;
279 mst->curr_buf = size + mst->pos;
280 }
281 GNUNET_assert (mst->pos + size <= mst->curr_buf);
282 memcpy (&ibuf[mst->pos], buf, size);
283 mst->pos += size;
284 } 280 }
281 GNUNET_assert (mst->pos + size <= mst->curr_buf);
282 memcpy (&ibuf[mst->pos], buf, size);
283 mst->pos += size;
284 }
285 if (purge) 285 if (purge)
286 mst->off = 0; 286 mst->off = 0;
287#if DEBUG_SERVER_MST 287#if DEBUG_SERVER_MST
diff --git a/src/util/server_nc.c b/src/util/server_nc.c
index cbe98a014..a36fa0c50 100644
--- a/src/util/server_nc.c
+++ b/src/util/server_nc.c
@@ -156,19 +156,19 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
156 struct PendingMessageList *pml; 156 struct PendingMessageList *pml;
157 157
158 if (client == NULL) 158 if (client == NULL)
159 { 159 {
160 nc->server = NULL; 160 nc->server = NULL;
161 return; 161 return;
162 } 162 }
163 prev = NULL; 163 prev = NULL;
164 pos = nc->clients; 164 pos = nc->clients;
165 while (NULL != pos) 165 while (NULL != pos)
166 { 166 {
167 if (pos->client == client) 167 if (pos->client == client)
168 break; 168 break;
169 prev = pos; 169 prev = pos;
170 pos = pos->next; 170 pos = pos->next;
171 } 171 }
172 if (pos == NULL) 172 if (pos == NULL)
173 return; 173 return;
174#if DEBUG_SERVER_NC 174#if DEBUG_SERVER_NC
@@ -181,15 +181,15 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
181 else 181 else
182 prev->next = pos->next; 182 prev->next = pos->next;
183 while (NULL != (pml = pos->pending_head)) 183 while (NULL != (pml = pos->pending_head))
184 { 184 {
185 GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, pml); 185 GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, pml);
186 GNUNET_free (pml); 186 GNUNET_free (pml);
187 } 187 }
188 if (pos->th != NULL) 188 if (pos->th != NULL)
189 { 189 {
190 GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->th); 190 GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->th);
191 pos->th = NULL; 191 pos->th = NULL;
192 } 192 }
193 GNUNET_SERVER_client_drop (client); 193 GNUNET_SERVER_client_drop (client);
194 GNUNET_free (pos); 194 GNUNET_free (pos);
195} 195}
@@ -205,8 +205,8 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
205 * @return handle to the notification context 205 * @return handle to the notification context
206 */ 206 */
207struct GNUNET_SERVER_NotificationContext * 207struct GNUNET_SERVER_NotificationContext *
208GNUNET_SERVER_notification_context_create (struct GNUNET_SERVER_Handle 208GNUNET_SERVER_notification_context_create (struct GNUNET_SERVER_Handle *server,
209 *server, unsigned int queue_length) 209 unsigned int queue_length)
210{ 210{
211 struct GNUNET_SERVER_NotificationContext *ret; 211 struct GNUNET_SERVER_NotificationContext *ret;
212 212
@@ -225,27 +225,26 @@ GNUNET_SERVER_notification_context_create (struct GNUNET_SERVER_Handle
225 */ 225 */
226void 226void
227GNUNET_SERVER_notification_context_destroy (struct 227GNUNET_SERVER_notification_context_destroy (struct
228 GNUNET_SERVER_NotificationContext 228 GNUNET_SERVER_NotificationContext
229 *nc) 229 *nc)
230{ 230{
231 struct ClientList *pos; 231 struct ClientList *pos;
232 struct PendingMessageList *pml; 232 struct PendingMessageList *pml;
233 233
234 while (NULL != (pos = nc->clients)) 234 while (NULL != (pos = nc->clients))
235 {
236 nc->clients = pos->next;
237 GNUNET_SERVER_client_drop (pos->client);
238 while (NULL != (pml = pos->pending_head))
235 { 239 {
236 nc->clients = pos->next; 240 GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, pml);
237 GNUNET_SERVER_client_drop (pos->client); 241 GNUNET_free (pml);
238 while (NULL != (pml = pos->pending_head))
239 {
240 GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail,
241 pml);
242 GNUNET_free (pml);
243 }
244 GNUNET_free (pos);
245 } 242 }
243 GNUNET_free (pos);
244 }
246 if (nc->server != NULL) 245 if (nc->server != NULL)
247 GNUNET_SERVER_disconnect_notify_cancel (nc->server, 246 GNUNET_SERVER_disconnect_notify_cancel (nc->server,
248 &handle_client_disconnect, nc); 247 &handle_client_disconnect, nc);
249 GNUNET_free (nc); 248 GNUNET_free (nc);
250} 249}
251 250
@@ -257,9 +256,9 @@ GNUNET_SERVER_notification_context_destroy (struct
257 * @param client client to add 256 * @param client client to add
258 */ 257 */
259void 258void
260GNUNET_SERVER_notification_context_add (struct 259GNUNET_SERVER_notification_context_add (struct GNUNET_SERVER_NotificationContext
261 GNUNET_SERVER_NotificationContext *nc, 260 *nc,
262 struct GNUNET_SERVER_Client *client) 261 struct GNUNET_SERVER_Client *client)
263{ 262{
264 struct ClientList *cl; 263 struct ClientList *cl;
265 264
@@ -293,45 +292,44 @@ transmit_message (void *cls, size_t size, void *buf)
293 292
294 cl->th = NULL; 293 cl->th = NULL;
295 if (buf == NULL) 294 if (buf == NULL)
296 { 295 {
297 /* 'cl' should be freed via disconnect notification shortly */ 296 /* 'cl' should be freed via disconnect notification shortly */
298#if DEBUG_SERVER_NC 297#if DEBUG_SERVER_NC
299 LOG (GNUNET_ERROR_TYPE_DEBUG, 298 LOG (GNUNET_ERROR_TYPE_DEBUG,
300 "Failed to transmit message from NC queue to client\n"); 299 "Failed to transmit message from NC queue to client\n");
301#endif 300#endif
302 return 0; 301 return 0;
303 } 302 }
304 ret = 0; 303 ret = 0;
305 while (NULL != (pml = cl->pending_head)) 304 while (NULL != (pml = cl->pending_head))
306 { 305 {
307 msize = ntohs (pml->msg->size); 306 msize = ntohs (pml->msg->size);
308 if (size < msize) 307 if (size < msize)
309 break; 308 break;
310 GNUNET_CONTAINER_DLL_remove (cl->pending_head, cl->pending_tail, pml); 309 GNUNET_CONTAINER_DLL_remove (cl->pending_head, cl->pending_tail, pml);
311#if DEBUG_SERVER_NC 310#if DEBUG_SERVER_NC
312 LOG (GNUNET_ERROR_TYPE_DEBUG, 311 LOG (GNUNET_ERROR_TYPE_DEBUG,
313 "Copying message of type %u and size %u from pending queue to transmission buffer\n", 312 "Copying message of type %u and size %u from pending queue to transmission buffer\n",
314 ntohs (pml->msg->type), msize); 313 ntohs (pml->msg->type), msize);
315#endif 314#endif
316 memcpy (&cbuf[ret], pml->msg, msize); 315 memcpy (&cbuf[ret], pml->msg, msize);
317 ret += msize; 316 ret += msize;
318 size -= msize; 317 size -= msize;
319 GNUNET_free (pml); 318 GNUNET_free (pml);
320 cl->num_pending--; 319 cl->num_pending--;
321 } 320 }
322 if (pml != NULL) 321 if (pml != NULL)
323 { 322 {
324#if DEBUG_SERVER_NC 323#if DEBUG_SERVER_NC
325 LOG (GNUNET_ERROR_TYPE_DEBUG, 324 LOG (GNUNET_ERROR_TYPE_DEBUG,
326 "Have %u messages left in NC queue, will try transmission again\n", 325 "Have %u messages left in NC queue, will try transmission again\n",
327 cl->num_pending); 326 cl->num_pending);
328#endif 327#endif
329 cl->th = 328 cl->th =
330 GNUNET_SERVER_notify_transmit_ready (cl->client, 329 GNUNET_SERVER_notify_transmit_ready (cl->client, ntohs (pml->msg->size),
331 ntohs (pml->msg->size), 330 GNUNET_TIME_UNIT_FOREVER_REL,
332 GNUNET_TIME_UNIT_FOREVER_REL, 331 &transmit_message, cl);
333 &transmit_message, cl); 332 }
334 }
335 else 333 else
336 GNUNET_assert (cl->num_pending == 0); 334 GNUNET_assert (cl->num_pending == 0);
337 return ret; 335 return ret;
@@ -348,25 +346,24 @@ transmit_message (void *cls, size_t size, void *buf)
348 */ 346 */
349static void 347static void
350do_unicast (struct GNUNET_SERVER_NotificationContext *nc, 348do_unicast (struct GNUNET_SERVER_NotificationContext *nc,
351 struct ClientList *client, const struct GNUNET_MessageHeader *msg, 349 struct ClientList *client, const struct GNUNET_MessageHeader *msg,
352 int can_drop) 350 int can_drop)
353{ 351{
354 struct PendingMessageList *pml; 352 struct PendingMessageList *pml;
355 uint16_t size; 353 uint16_t size;
356 354
357 if ((client->num_pending > nc->queue_length) && (GNUNET_YES == can_drop)) 355 if ((client->num_pending > nc->queue_length) && (GNUNET_YES == can_drop))
358 { 356 {
359 LOG (GNUNET_ERROR_TYPE_INFO, 357 LOG (GNUNET_ERROR_TYPE_INFO,
360 "Dropping message of type %u and size %u due to full queue (%u entries)\n", 358 "Dropping message of type %u and size %u due to full queue (%u entries)\n",
361 ntohs (msg->type), ntohs (msg->size), 359 ntohs (msg->type), ntohs (msg->size), (unsigned int) nc->queue_length);
362 (unsigned int) nc->queue_length); 360 return; /* drop! */
363 return; /* drop! */ 361 }
364 }
365 if (client->num_pending > nc->queue_length) 362 if (client->num_pending > nc->queue_length)
366 { 363 {
367 /* FIXME: consider checking for other messages in the 364 /* FIXME: consider checking for other messages in the
368 * queue that are 'droppable' */ 365 * queue that are 'droppable' */
369 } 366 }
370 client->num_pending++; 367 client->num_pending++;
371 size = ntohs (msg->size); 368 size = ntohs (msg->size);
372 pml = GNUNET_malloc (sizeof (struct PendingMessageList) + size); 369 pml = GNUNET_malloc (sizeof (struct PendingMessageList) + size);
@@ -379,15 +376,15 @@ do_unicast (struct GNUNET_SERVER_NotificationContext *nc,
379#endif 376#endif
380 memcpy (&pml[1], msg, size); 377 memcpy (&pml[1], msg, size);
381 /* append */ 378 /* append */
382 GNUNET_CONTAINER_DLL_insert_tail (client->pending_head, 379 GNUNET_CONTAINER_DLL_insert_tail (client->pending_head, client->pending_tail,
383 client->pending_tail, pml); 380 pml);
384 if (client->th == NULL) 381 if (client->th == NULL)
385 client->th = 382 client->th =
386 GNUNET_SERVER_notify_transmit_ready (client->client, 383 GNUNET_SERVER_notify_transmit_ready (client->client,
387 ntohs (client->pending_head-> 384 ntohs (client->pending_head->
388 msg->size), 385 msg->size),
389 GNUNET_TIME_UNIT_FOREVER_REL, 386 GNUNET_TIME_UNIT_FOREVER_REL,
390 &transmit_message, client); 387 &transmit_message, client);
391} 388}
392 389
393 390
@@ -402,22 +399,21 @@ do_unicast (struct GNUNET_SERVER_NotificationContext *nc,
402 */ 399 */
403void 400void
404GNUNET_SERVER_notification_context_unicast (struct 401GNUNET_SERVER_notification_context_unicast (struct
405 GNUNET_SERVER_NotificationContext 402 GNUNET_SERVER_NotificationContext
406 *nc, 403 *nc,
407 struct GNUNET_SERVER_Client 404 struct GNUNET_SERVER_Client *client,
408 *client, 405 const struct GNUNET_MessageHeader
409 const struct GNUNET_MessageHeader 406 *msg, int can_drop)
410 *msg, int can_drop)
411{ 407{
412 struct ClientList *pos; 408 struct ClientList *pos;
413 409
414 pos = nc->clients; 410 pos = nc->clients;
415 while (NULL != pos) 411 while (NULL != pos)
416 { 412 {
417 if (pos->client == client) 413 if (pos->client == client)
418 break; 414 break;
419 pos = pos->next; 415 pos = pos->next;
420 } 416 }
421 GNUNET_assert (pos != NULL); 417 GNUNET_assert (pos != NULL);
422 do_unicast (nc, pos, msg, can_drop); 418 do_unicast (nc, pos, msg, can_drop);
423} 419}
@@ -432,20 +428,19 @@ GNUNET_SERVER_notification_context_unicast (struct
432 */ 428 */
433void 429void
434GNUNET_SERVER_notification_context_broadcast (struct 430GNUNET_SERVER_notification_context_broadcast (struct
435 GNUNET_SERVER_NotificationContext 431 GNUNET_SERVER_NotificationContext
436 *nc, 432 *nc,
437 const struct 433 const struct GNUNET_MessageHeader
438 GNUNET_MessageHeader *msg, 434 *msg, int can_drop)
439 int can_drop)
440{ 435{
441 struct ClientList *pos; 436 struct ClientList *pos;
442 437
443 pos = nc->clients; 438 pos = nc->clients;
444 while (NULL != pos) 439 while (NULL != pos)
445 { 440 {
446 do_unicast (nc, pos, msg, can_drop); 441 do_unicast (nc, pos, msg, can_drop);
447 pos = pos->next; 442 pos = pos->next;
448 } 443 }
449} 444}
450 445
451 446
diff --git a/src/util/server_tc.c b/src/util/server_tc.c
index 020fd86db..ce40db19c 100644
--- a/src/util/server_tc.c
+++ b/src/util/server_tc.c
@@ -83,10 +83,10 @@ transmit_response (void *cls, size_t size, void *buf)
83 size_t msize; 83 size_t msize;
84 84
85 if (buf == NULL) 85 if (buf == NULL)
86 { 86 {
87 GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR); 87 GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR);
88 return 0; 88 return 0;
89 } 89 }
90 if (tc->total - tc->off > size) 90 if (tc->total - tc->off > size)
91 msize = size; 91 msize = size;
92 else 92 else
@@ -94,28 +94,27 @@ transmit_response (void *cls, size_t size, void *buf)
94 memcpy (buf, &tc->buf[tc->off], msize); 94 memcpy (buf, &tc->buf[tc->off], msize);
95 tc->off += msize; 95 tc->off += msize;
96 if (tc->total == tc->off) 96 if (tc->total == tc->off)
97 { 97 {
98 98
99 GNUNET_SERVER_receive_done (tc->client, GNUNET_OK); 99 GNUNET_SERVER_receive_done (tc->client, GNUNET_OK);
100 GNUNET_SERVER_client_drop (tc->client); 100 GNUNET_SERVER_client_drop (tc->client);
101 GNUNET_free_non_null (tc->buf); 101 GNUNET_free_non_null (tc->buf);
102 GNUNET_free (tc); 102 GNUNET_free (tc);
103 } 103 }
104 else 104 else
105 {
106 if (NULL ==
107 GNUNET_SERVER_notify_transmit_ready (tc->client,
108 GNUNET_MIN (MIN_BLOCK_SIZE,
109 tc->total - tc->off),
110 GNUNET_TIME_absolute_get_remaining
111 (tc->timeout), &transmit_response,
112 tc))
105 { 113 {
106 if (NULL == 114 GNUNET_break (0);
107 GNUNET_SERVER_notify_transmit_ready (tc->client, 115 GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR);
108 GNUNET_MIN (MIN_BLOCK_SIZE,
109 tc->total -
110 tc->off),
111 GNUNET_TIME_absolute_get_remaining
112 (tc->timeout),
113 &transmit_response, tc))
114 {
115 GNUNET_break (0);
116 GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR);
117 }
118 } 116 }
117 }
119 return msize; 118 return msize;
120} 119}
121 120
@@ -151,10 +150,9 @@ GNUNET_SERVER_transmit_context_create (struct GNUNET_SERVER_Client *client)
151 * @param type type of the message 150 * @param type type of the message
152 */ 151 */
153void 152void
154GNUNET_SERVER_transmit_context_append_data (struct 153GNUNET_SERVER_transmit_context_append_data (struct GNUNET_SERVER_TransmitContext
155 GNUNET_SERVER_TransmitContext *tc, 154 *tc, const void *data,
156 const void *data, size_t length, 155 size_t length, uint16_t type)
157 uint16_t type)
158{ 156{
159 struct GNUNET_MessageHeader *msg; 157 struct GNUNET_MessageHeader *msg;
160 size_t size; 158 size_t size;
@@ -181,10 +179,10 @@ GNUNET_SERVER_transmit_context_append_data (struct
181 */ 179 */
182void 180void
183GNUNET_SERVER_transmit_context_append_message (struct 181GNUNET_SERVER_transmit_context_append_message (struct
184 GNUNET_SERVER_TransmitContext 182 GNUNET_SERVER_TransmitContext
185 *tc, 183 *tc,
186 const struct 184 const struct GNUNET_MessageHeader
187 GNUNET_MessageHeader *msg) 185 *msg)
188{ 186{
189 struct GNUNET_MessageHeader *m; 187 struct GNUNET_MessageHeader *m;
190 uint16_t size; 188 uint16_t size;
@@ -208,18 +206,18 @@ GNUNET_SERVER_transmit_context_append_message (struct
208 */ 206 */
209void 207void
210GNUNET_SERVER_transmit_context_run (struct GNUNET_SERVER_TransmitContext *tc, 208GNUNET_SERVER_transmit_context_run (struct GNUNET_SERVER_TransmitContext *tc,
211 struct GNUNET_TIME_Relative timeout) 209 struct GNUNET_TIME_Relative timeout)
212{ 210{
213 tc->timeout = GNUNET_TIME_relative_to_absolute (timeout); 211 tc->timeout = GNUNET_TIME_relative_to_absolute (timeout);
214 if (NULL == 212 if (NULL ==
215 GNUNET_SERVER_notify_transmit_ready (tc->client, 213 GNUNET_SERVER_notify_transmit_ready (tc->client,
216 GNUNET_MIN (MIN_BLOCK_SIZE, 214 GNUNET_MIN (MIN_BLOCK_SIZE,
217 tc->total), timeout, 215 tc->total), timeout,
218 &transmit_response, tc)) 216 &transmit_response, tc))
219 { 217 {
220 GNUNET_break (0); 218 GNUNET_break (0);
221 GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR); 219 GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR);
222 } 220 }
223} 221}
224 222
225 223
@@ -237,7 +235,7 @@ GNUNET_SERVER_transmit_context_run (struct GNUNET_SERVER_TransmitContext *tc,
237 */ 235 */
238void 236void
239GNUNET_SERVER_transmit_context_destroy (struct GNUNET_SERVER_TransmitContext 237GNUNET_SERVER_transmit_context_destroy (struct GNUNET_SERVER_TransmitContext
240 *tc, int success) 238 *tc, int success)
241{ 239{
242 GNUNET_SERVER_receive_done (tc->client, success); 240 GNUNET_SERVER_receive_done (tc->client, success);
243 GNUNET_SERVER_client_drop (tc->client); 241 GNUNET_SERVER_client_drop (tc->client);
diff --git a/src/util/service.c b/src/util/service.c
index 7cafe35c8..cf1002ca9 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -104,121 +104,119 @@ parse_ipv4_specification (const char *routeList)
104 i = 0; 104 i = 0;
105 pos = 0; 105 pos = 0;
106 while (i < count) 106 while (i < count)
107 {
108 cnt =
109 sscanf (&routeList[pos], "%u.%u.%u.%u/%u.%u.%u.%u;", &temps[0],
110 &temps[1], &temps[2], &temps[3], &temps[4], &temps[5],
111 &temps[6], &temps[7]);
112 if (cnt == 8)
107 { 113 {
108 cnt = 114 for (j = 0; j < 8; j++)
109 sscanf (&routeList[pos], "%u.%u.%u.%u/%u.%u.%u.%u;", &temps[0], 115 if (temps[j] > 0xFF)
110 &temps[1], &temps[2], &temps[3], &temps[4], &temps[5], 116 {
111 &temps[6], &temps[7]); 117 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"),
112 if (cnt == 8) 118 &routeList[pos]);
113 { 119 GNUNET_free (result);
114 for (j = 0; j < 8; j++) 120 return NULL;
115 if (temps[j] > 0xFF) 121 }
116 { 122 result[i].network.s_addr =
117 LOG (GNUNET_ERROR_TYPE_ERROR, 123 htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) +
118 _("Invalid format for IP: `%s'\n"), &routeList[pos]); 124 temps[3]);
119 GNUNET_free (result); 125 result[i].netmask.s_addr =
120 return NULL; 126 htonl ((temps[4] << 24) + (temps[5] << 16) + (temps[6] << 8) +
121 } 127 temps[7]);
122 result[i].network.s_addr = 128 while (routeList[pos] != ';')
123 htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + 129 pos++;
124 temps[3]); 130 pos++;
125 result[i].netmask.s_addr = 131 i++;
126 htonl ((temps[4] << 24) + (temps[5] << 16) + (temps[6] << 8) + 132 continue;
127 temps[7]);
128 while (routeList[pos] != ';')
129 pos++;
130 pos++;
131 i++;
132 continue;
133 }
134 /* try second notation */
135 cnt =
136 sscanf (&routeList[pos], "%u.%u.%u.%u/%u;", &temps[0], &temps[1],
137 &temps[2], &temps[3], &slash);
138 if (cnt == 5)
139 {
140 for (j = 0; j < 4; j++)
141 if (temps[j] > 0xFF)
142 {
143 LOG (GNUNET_ERROR_TYPE_ERROR,
144 _("Invalid format for IP: `%s'\n"), &routeList[pos]);
145 GNUNET_free (result);
146 return NULL;
147 }
148 result[i].network.s_addr =
149 htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) +
150 temps[3]);
151 if ((slash <= 32) && (slash >= 0))
152 {
153 result[i].netmask.s_addr = 0;
154 while (slash > 0)
155 {
156 result[i].netmask.s_addr =
157 (result[i].netmask.s_addr >> 1) + 0x80000000;
158 slash--;
159 }
160 result[i].netmask.s_addr = htonl (result[i].netmask.s_addr);
161 while (routeList[pos] != ';')
162 pos++;
163 pos++;
164 i++;
165 continue;
166 }
167 else
168 {
169 LOG (GNUNET_ERROR_TYPE_ERROR,
170 _
171 ("Invalid network notation ('/%d' is not legal in IPv4 CIDR)."),
172 slash);
173 GNUNET_free (result);
174 return NULL; /* error */
175 }
176 }
177 /* try third notation */
178 slash = 32;
179 cnt =
180 sscanf (&routeList[pos], "%u.%u.%u.%u;", &temps[0], &temps[1],
181 &temps[2], &temps[3]);
182 if (cnt == 4)
183 {
184 for (j = 0; j < 4; j++)
185 if (temps[j] > 0xFF)
186 {
187 LOG (GNUNET_ERROR_TYPE_ERROR,
188 _("Invalid format for IP: `%s'\n"), &routeList[pos]);
189 GNUNET_free (result);
190 return NULL;
191 }
192 result[i].network.s_addr =
193 htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) +
194 temps[3]);
195 result[i].netmask.s_addr = 0;
196 while (slash > 0)
197 {
198 result[i].netmask.s_addr =
199 (result[i].netmask.s_addr >> 1) + 0x80000000;
200 slash--;
201 }
202 result[i].netmask.s_addr = htonl (result[i].netmask.s_addr);
203 while (routeList[pos] != ';')
204 pos++;
205 pos++;
206 i++;
207 continue;
208 }
209 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"),
210 &routeList[pos]);
211 GNUNET_free (result);
212 return NULL; /* error */
213 } 133 }
214 if (pos < strlen (routeList)) 134 /* try second notation */
135 cnt =
136 sscanf (&routeList[pos], "%u.%u.%u.%u/%u;", &temps[0], &temps[1],
137 &temps[2], &temps[3], &slash);
138 if (cnt == 5)
215 { 139 {
216 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"), 140 for (j = 0; j < 4; j++)
217 &routeList[pos]); 141 if (temps[j] > 0xFF)
218 GNUNET_free (result); 142 {
219 return NULL; /* oops */ 143 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"),
144 &routeList[pos]);
145 GNUNET_free (result);
146 return NULL;
147 }
148 result[i].network.s_addr =
149 htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) +
150 temps[3]);
151 if ((slash <= 32) && (slash >= 0))
152 {
153 result[i].netmask.s_addr = 0;
154 while (slash > 0)
155 {
156 result[i].netmask.s_addr =
157 (result[i].netmask.s_addr >> 1) + 0x80000000;
158 slash--;
159 }
160 result[i].netmask.s_addr = htonl (result[i].netmask.s_addr);
161 while (routeList[pos] != ';')
162 pos++;
163 pos++;
164 i++;
165 continue;
166 }
167 else
168 {
169 LOG (GNUNET_ERROR_TYPE_ERROR,
170 _("Invalid network notation ('/%d' is not legal in IPv4 CIDR)."),
171 slash);
172 GNUNET_free (result);
173 return NULL; /* error */
174 }
220 } 175 }
221 return result; /* ok */ 176 /* try third notation */
177 slash = 32;
178 cnt =
179 sscanf (&routeList[pos], "%u.%u.%u.%u;", &temps[0], &temps[1],
180 &temps[2], &temps[3]);
181 if (cnt == 4)
182 {
183 for (j = 0; j < 4; j++)
184 if (temps[j] > 0xFF)
185 {
186 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"),
187 &routeList[pos]);
188 GNUNET_free (result);
189 return NULL;
190 }
191 result[i].network.s_addr =
192 htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) +
193 temps[3]);
194 result[i].netmask.s_addr = 0;
195 while (slash > 0)
196 {
197 result[i].netmask.s_addr = (result[i].netmask.s_addr >> 1) + 0x80000000;
198 slash--;
199 }
200 result[i].netmask.s_addr = htonl (result[i].netmask.s_addr);
201 while (routeList[pos] != ';')
202 pos++;
203 pos++;
204 i++;
205 continue;
206 }
207 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"),
208 &routeList[pos]);
209 GNUNET_free (result);
210 return NULL; /* error */
211 }
212 if (pos < strlen (routeList))
213 {
214 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid format for IP: `%s'\n"),
215 &routeList[pos]);
216 GNUNET_free (result);
217 return NULL; /* oops */
218 }
219 return result; /* ok */
222} 220}
223 221
224 222
@@ -260,85 +258,82 @@ parse_ipv6_specification (const char *routeListX)
260 if (routeList[i] == ';') 258 if (routeList[i] == ';')
261 count++; 259 count++;
262 if (routeList[len - 1] != ';') 260 if (routeList[len - 1] != ';')
263 { 261 {
264 LOG (GNUNET_ERROR_TYPE_ERROR, 262 LOG (GNUNET_ERROR_TYPE_ERROR,
265 _("Invalid network notation (does not end with ';': `%s')\n"), 263 _("Invalid network notation (does not end with ';': `%s')\n"),
266 routeList); 264 routeList);
267 GNUNET_free (routeList); 265 GNUNET_free (routeList);
268 return NULL; 266 return NULL;
269 } 267 }
270 268
271 result = GNUNET_malloc (sizeof (struct IPv6NetworkSet) * (count + 1)); 269 result = GNUNET_malloc (sizeof (struct IPv6NetworkSet) * (count + 1));
272 memset (result, 0, sizeof (struct IPv6NetworkSet) * (count + 1)); 270 memset (result, 0, sizeof (struct IPv6NetworkSet) * (count + 1));
273 i = 0; 271 i = 0;
274 pos = 0; 272 pos = 0;
275 while (i < count) 273 while (i < count)
274 {
275 start = pos;
276 while (routeList[pos] != ';')
277 pos++;
278 slash = pos;
279 while ((slash >= start) && (routeList[slash] != '/'))
280 slash--;
281 if (slash < start)
276 { 282 {
277 start = pos; 283 memset (&result[i].netmask, 0xFF, sizeof (struct in6_addr));
278 while (routeList[pos] != ';')
279 pos++;
280 slash = pos; 284 slash = pos;
281 while ((slash >= start) && (routeList[slash] != '/')) 285 }
282 slash--; 286 else
283 if (slash < start) 287 {
284 { 288 routeList[pos] = '\0';
285 memset (&result[i].netmask, 0xFF, sizeof (struct in6_addr)); 289 ret = inet_pton (AF_INET6, &routeList[slash + 1], &result[i].netmask);
286 slash = pos;
287 }
288 else
289 {
290 routeList[pos] = '\0';
291 ret =
292 inet_pton (AF_INET6, &routeList[slash + 1], &result[i].netmask);
293 if (ret <= 0)
294 {
295 save = errno;
296 if ((1 != SSCANF (&routeList[slash + 1], "%u", &bits))
297 || (bits >= 128))
298 {
299 if (ret == 0)
300 LOG (GNUNET_ERROR_TYPE_ERROR,
301 _("Wrong format `%s' for netmask\n"),
302 &routeList[slash + 1]);
303 else
304 {
305 errno = save;
306 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "inet_pton");
307 }
308 GNUNET_free (result);
309 GNUNET_free (routeList);
310 return NULL;
311 }
312 off = 0;
313 while (bits > 8)
314 {
315 result[i].netmask.s6_addr[off++] = 0xFF;
316 bits -= 8;
317 }
318 while (bits > 0)
319 {
320 result[i].netmask.s6_addr[off] =
321 (result[i].netmask.s6_addr[off] >> 1) + 0x80;
322 bits--;
323 }
324 }
325 }
326 routeList[slash] = '\0';
327 ret = inet_pton (AF_INET6, &routeList[start], &result[i].network);
328 if (ret <= 0) 290 if (ret <= 0)
329 { 291 {
330 if (ret == 0) 292 save = errno;
331 LOG (GNUNET_ERROR_TYPE_ERROR, 293 if ((1 != SSCANF (&routeList[slash + 1], "%u", &bits)) || (bits >= 128))
332 _("Wrong format `%s' for network\n"), &routeList[slash + 1]); 294 {
333 else 295 if (ret == 0)
334 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "inet_pton"); 296 LOG (GNUNET_ERROR_TYPE_ERROR, _("Wrong format `%s' for netmask\n"),
335 GNUNET_free (result); 297 &routeList[slash + 1]);
336 GNUNET_free (routeList); 298 else
337 return NULL; 299 {
338 } 300 errno = save;
339 pos++; 301 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "inet_pton");
340 i++; 302 }
303 GNUNET_free (result);
304 GNUNET_free (routeList);
305 return NULL;
306 }
307 off = 0;
308 while (bits > 8)
309 {
310 result[i].netmask.s6_addr[off++] = 0xFF;
311 bits -= 8;
312 }
313 while (bits > 0)
314 {
315 result[i].netmask.s6_addr[off] =
316 (result[i].netmask.s6_addr[off] >> 1) + 0x80;
317 bits--;
318 }
319 }
320 }
321 routeList[slash] = '\0';
322 ret = inet_pton (AF_INET6, &routeList[start], &result[i].network);
323 if (ret <= 0)
324 {
325 if (ret == 0)
326 LOG (GNUNET_ERROR_TYPE_ERROR, _("Wrong format `%s' for network\n"),
327 &routeList[slash + 1]);
328 else
329 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "inet_pton");
330 GNUNET_free (result);
331 GNUNET_free (routeList);
332 return NULL;
341 } 333 }
334 pos++;
335 i++;
336 }
342 GNUNET_free (routeList); 337 GNUNET_free (routeList);
343 return result; 338 return result;
344} 339}
@@ -352,8 +347,7 @@ parse_ipv6_specification (const char *routeListX)
352 * @return GNUNET_NO if the IP is not in the list, GNUNET_YES if it it is 347 * @return GNUNET_NO if the IP is not in the list, GNUNET_YES if it it is
353 */ 348 */
354static int 349static int
355check_ipv4_listed (const struct IPv4NetworkSet *list, 350check_ipv4_listed (const struct IPv4NetworkSet *list, const struct in_addr *add)
356 const struct in_addr *add)
357{ 351{
358 int i; 352 int i;
359 353
@@ -362,12 +356,12 @@ check_ipv4_listed (const struct IPv4NetworkSet *list,
362 return GNUNET_NO; 356 return GNUNET_NO;
363 357
364 while ((list[i].network.s_addr != 0) || (list[i].netmask.s_addr != 0)) 358 while ((list[i].network.s_addr != 0) || (list[i].netmask.s_addr != 0))
365 { 359 {
366 if ((add->s_addr & list[i].netmask.s_addr) == 360 if ((add->s_addr & list[i].netmask.s_addr) ==
367 (list[i].network.s_addr & list[i].netmask.s_addr)) 361 (list[i].network.s_addr & list[i].netmask.s_addr))
368 return GNUNET_YES; 362 return GNUNET_YES;
369 i++; 363 i++;
370 } 364 }
371 return GNUNET_NO; 365 return GNUNET_NO;
372} 366}
373 367
@@ -379,8 +373,7 @@ check_ipv4_listed (const struct IPv4NetworkSet *list,
379 * @return GNUNET_NO if the IP is not in the list, GNUNET_YES if it it is 373 * @return GNUNET_NO if the IP is not in the list, GNUNET_YES if it it is
380 */ 374 */
381static int 375static int
382check_ipv6_listed (const struct IPv6NetworkSet *list, 376check_ipv6_listed (const struct IPv6NetworkSet *list, const struct in6_addr *ip)
383 const struct in6_addr *ip)
384{ 377{
385 unsigned int i; 378 unsigned int i;
386 unsigned int j; 379 unsigned int j;
@@ -393,16 +386,16 @@ check_ipv6_listed (const struct IPv6NetworkSet *list,
393 i = 0; 386 i = 0;
394NEXT: 387NEXT:
395 while (memcmp (&zero, &list[i].network, sizeof (struct in6_addr)) != 0) 388 while (memcmp (&zero, &list[i].network, sizeof (struct in6_addr)) != 0)
396 { 389 {
397 for (j = 0; j < sizeof (struct in6_addr) / sizeof (int); j++) 390 for (j = 0; j < sizeof (struct in6_addr) / sizeof (int); j++)
398 if (((((int *) ip)[j] & ((int *) &list[i].netmask)[j])) != 391 if (((((int *) ip)[j] & ((int *) &list[i].netmask)[j])) !=
399 (((int *) &list[i].network)[j] & ((int *) &list[i].netmask)[j])) 392 (((int *) &list[i].network)[j] & ((int *) &list[i].netmask)[j]))
400 { 393 {
401 i++; 394 i++;
402 goto NEXT; 395 goto NEXT;
403 } 396 }
404 return GNUNET_YES; 397 return GNUNET_YES;
405 } 398 }
406 return GNUNET_NO; 399 return GNUNET_NO;
407} 400}
408 401
@@ -536,10 +529,10 @@ write_test (void *cls, size_t size, void *buf)
536 struct GNUNET_MessageHeader *msg; 529 struct GNUNET_MessageHeader *msg;
537 530
538 if (size < sizeof (struct GNUNET_MessageHeader)) 531 if (size < sizeof (struct GNUNET_MessageHeader))
539 { 532 {
540 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 533 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
541 return 0; /* client disconnected */ 534 return 0; /* client disconnected */
542 } 535 }
543 msg = (struct GNUNET_MessageHeader *) buf; 536 msg = (struct GNUNET_MessageHeader *) buf;
544 msg->type = htons (GNUNET_MESSAGE_TYPE_TEST); 537 msg->type = htons (GNUNET_MESSAGE_TYPE_TEST);
545 msg->size = htons (sizeof (struct GNUNET_MessageHeader)); 538 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
@@ -556,15 +549,14 @@ write_test (void *cls, size_t size, void *buf)
556 */ 549 */
557static void 550static void
558handle_test (void *cls, struct GNUNET_SERVER_Client *client, 551handle_test (void *cls, struct GNUNET_SERVER_Client *client,
559 const struct GNUNET_MessageHeader *message) 552 const struct GNUNET_MessageHeader *message)
560{ 553{
561 /* simply bounce message back to acknowledge */ 554 /* simply bounce message back to acknowledge */
562 if (NULL == 555 if (NULL ==
563 GNUNET_SERVER_notify_transmit_ready (client, 556 GNUNET_SERVER_notify_transmit_ready (client,
564 sizeof (struct 557 sizeof (struct GNUNET_MessageHeader),
565 GNUNET_MessageHeader), 558 GNUNET_TIME_UNIT_FOREVER_REL,
566 GNUNET_TIME_UNIT_FOREVER_REL, 559 &write_test, client))
567 &write_test, client))
568 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 560 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
569} 561}
570 562
@@ -597,7 +589,7 @@ static const struct GNUNET_SERVER_MessageHandler defhandlers[] = {
597 */ 589 */
598static int 590static int
599check_access (void *cls, const struct GNUNET_CONNECTION_Credentials *uc, 591check_access (void *cls, const struct GNUNET_CONNECTION_Credentials *uc,
600 const struct sockaddr *addr, socklen_t addrlen) 592 const struct sockaddr *addr, socklen_t addrlen)
601{ 593{
602 struct GNUNET_SERVICE_Context *sctx = cls; 594 struct GNUNET_SERVICE_Context *sctx = cls;
603 const struct sockaddr_in *i4; 595 const struct sockaddr_in *i4;
@@ -605,51 +597,51 @@ check_access (void *cls, const struct GNUNET_CONNECTION_Credentials *uc,
605 int ret; 597 int ret;
606 598
607 switch (addr->sa_family) 599 switch (addr->sa_family)
608 { 600 {
609 case AF_INET: 601 case AF_INET:
610 GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); 602 GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
611 i4 = (const struct sockaddr_in *) addr; 603 i4 = (const struct sockaddr_in *) addr;
612 ret = ((sctx->v4_allowed == NULL) || 604 ret = ((sctx->v4_allowed == NULL) ||
613 (check_ipv4_listed (sctx->v4_allowed, &i4->sin_addr))) && 605 (check_ipv4_listed (sctx->v4_allowed, &i4->sin_addr))) &&
614 ((sctx->v4_denied == NULL) || 606 ((sctx->v4_denied == NULL) ||
615 (!check_ipv4_listed (sctx->v4_denied, &i4->sin_addr))); 607 (!check_ipv4_listed (sctx->v4_denied, &i4->sin_addr)));
616 break; 608 break;
617 case AF_INET6: 609 case AF_INET6:
618 GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); 610 GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
619 i6 = (const struct sockaddr_in6 *) addr; 611 i6 = (const struct sockaddr_in6 *) addr;
620 ret = ((sctx->v6_allowed == NULL) || 612 ret = ((sctx->v6_allowed == NULL) ||
621 (check_ipv6_listed (sctx->v6_allowed, &i6->sin6_addr))) && 613 (check_ipv6_listed (sctx->v6_allowed, &i6->sin6_addr))) &&
622 ((sctx->v6_denied == NULL) || 614 ((sctx->v6_denied == NULL) ||
623 (!check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr))); 615 (!check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr)));
624 break; 616 break;
625#ifndef WINDOWS 617#ifndef WINDOWS
626 case AF_UNIX: 618 case AF_UNIX:
627 ret = GNUNET_OK; /* always OK for now */ 619 ret = GNUNET_OK; /* always OK for now */
628 if ((sctx->match_uid == GNUNET_YES) || (sctx->match_gid == GNUNET_YES)) 620 if ((sctx->match_uid == GNUNET_YES) || (sctx->match_gid == GNUNET_YES))
629 ret = GNUNET_NO; 621 ret = GNUNET_NO;
630 if ((uc != NULL) && 622 if ((uc != NULL) &&
631 ((sctx->match_uid != GNUNET_YES) || (uc->uid == geteuid ()) || 623 ((sctx->match_uid != GNUNET_YES) || (uc->uid == geteuid ()) ||
632 (uc->uid == getuid ())) && ((sctx->match_gid != GNUNET_YES) || 624 (uc->uid == getuid ())) && ((sctx->match_gid != GNUNET_YES) ||
633 (uc->gid == getegid ()) || 625 (uc->gid == getegid ()) ||
634 (uc->gid == getgid ()))) 626 (uc->gid == getgid ())))
635 ret = GNUNET_YES; 627 ret = GNUNET_YES;
636 else 628 else
637 LOG (GNUNET_ERROR_TYPE_WARNING, 629 LOG (GNUNET_ERROR_TYPE_WARNING, _("Access denied to UID %d / GID %d\n"),
638 _("Access denied to UID %d / GID %d\n"), 630 (uc == NULL) ? -1 : uc->uid, (uc == NULL) ? -1 : uc->gid);
639 (uc == NULL) ? -1 : uc->uid, (uc == NULL) ? -1 : uc->gid); 631 break;
640 break;
641#endif 632#endif
642 default: 633 default:
643 LOG (GNUNET_ERROR_TYPE_WARNING, _("Unknown address family %d\n"), 634 LOG (GNUNET_ERROR_TYPE_WARNING, _("Unknown address family %d\n"),
644 addr->sa_family); 635 addr->sa_family);
645 return GNUNET_SYSERR; 636 return GNUNET_SYSERR;
646 } 637 }
647 if (ret != GNUNET_OK) 638 if (ret != GNUNET_OK)
648 { 639 {
649 LOG (GNUNET_ERROR_TYPE_WARNING, 640 LOG (GNUNET_ERROR_TYPE_WARNING,
650 _("Access from `%s' denied to service `%s'\n"), 641 _("Access from `%s' denied to service `%s'\n"), GNUNET_a2s (addr,
651 GNUNET_a2s (addr, addrlen), sctx->serviceName); 642 addrlen),
652 } 643 sctx->serviceName);
644 }
653 return ret; 645 return ret;
654} 646}
655 647
@@ -666,7 +658,7 @@ get_pid_file_name (struct GNUNET_SERVICE_Context *sctx)
666 658
667 if (GNUNET_OK != 659 if (GNUNET_OK !=
668 GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, sctx->serviceName, 660 GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, sctx->serviceName,
669 "PIDFILE", &pif)) 661 "PIDFILE", &pif))
670 return NULL; 662 return NULL;
671 return pif; 663 return pif;
672} 664}
@@ -676,26 +668,25 @@ get_pid_file_name (struct GNUNET_SERVICE_Context *sctx)
676 * Parse an IPv4 access control list. 668 * Parse an IPv4 access control list.
677 */ 669 */
678static int 670static int
679process_acl4 (struct IPv4NetworkSet **ret, 671process_acl4 (struct IPv4NetworkSet **ret, struct GNUNET_SERVICE_Context *sctx,
680 struct GNUNET_SERVICE_Context *sctx, const char *option) 672 const char *option)
681{ 673{
682 char *opt; 674 char *opt;
683 675
684 if (!GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->serviceName, option)) 676 if (!GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->serviceName, option))
685 return GNUNET_OK; 677 return GNUNET_OK;
686 GNUNET_break (GNUNET_OK == 678 GNUNET_break (GNUNET_OK ==
687 GNUNET_CONFIGURATION_get_value_string (sctx->cfg, 679 GNUNET_CONFIGURATION_get_value_string (sctx->cfg,
688 sctx->serviceName, 680 sctx->serviceName,
689 option, &opt)); 681 option, &opt));
690 if (NULL == (*ret = parse_ipv4_specification (opt))) 682 if (NULL == (*ret = parse_ipv4_specification (opt)))
691 { 683 {
692 LOG (GNUNET_ERROR_TYPE_WARNING, 684 LOG (GNUNET_ERROR_TYPE_WARNING,
693 _ 685 _("Could not parse IPv4 network specification `%s' for `%s:%s'\n"),
694 ("Could not parse IPv4 network specification `%s' for `%s:%s'\n"), 686 opt, sctx->serviceName, option);
695 opt, sctx->serviceName, option); 687 GNUNET_free (opt);
696 GNUNET_free (opt); 688 return GNUNET_SYSERR;
697 return GNUNET_SYSERR; 689 }
698 }
699 GNUNET_free (opt); 690 GNUNET_free (opt);
700 return GNUNET_OK; 691 return GNUNET_OK;
701} 692}
@@ -705,26 +696,25 @@ process_acl4 (struct IPv4NetworkSet **ret,
705 * Parse an IPv4 access control list. 696 * Parse an IPv4 access control list.
706 */ 697 */
707static int 698static int
708process_acl6 (struct IPv6NetworkSet **ret, 699process_acl6 (struct IPv6NetworkSet **ret, struct GNUNET_SERVICE_Context *sctx,
709 struct GNUNET_SERVICE_Context *sctx, const char *option) 700 const char *option)
710{ 701{
711 char *opt; 702 char *opt;
712 703
713 if (!GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->serviceName, option)) 704 if (!GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->serviceName, option))
714 return GNUNET_OK; 705 return GNUNET_OK;
715 GNUNET_break (GNUNET_OK == 706 GNUNET_break (GNUNET_OK ==
716 GNUNET_CONFIGURATION_get_value_string (sctx->cfg, 707 GNUNET_CONFIGURATION_get_value_string (sctx->cfg,
717 sctx->serviceName, 708 sctx->serviceName,
718 option, &opt)); 709 option, &opt));
719 if (NULL == (*ret = parse_ipv6_specification (opt))) 710 if (NULL == (*ret = parse_ipv6_specification (opt)))
720 { 711 {
721 LOG (GNUNET_ERROR_TYPE_WARNING, 712 LOG (GNUNET_ERROR_TYPE_WARNING,
722 _ 713 _("Could not parse IPv6 network specification `%s' for `%s:%s'\n"),
723 ("Could not parse IPv6 network specification `%s' for `%s:%s'\n"), 714 opt, sctx->serviceName, option);
724 opt, sctx->serviceName, option); 715 GNUNET_free (opt);
725 GNUNET_free (opt); 716 return GNUNET_SYSERR;
726 return GNUNET_SYSERR; 717 }
727 }
728 GNUNET_free (opt); 718 GNUNET_free (opt);
729 return GNUNET_OK; 719 return GNUNET_OK;
730} 720}
@@ -739,7 +729,7 @@ process_acl6 (struct IPv6NetworkSet **ret,
739 */ 729 */
740static void 730static void
741add_unixpath (struct sockaddr **saddrs, socklen_t * saddrlens, 731add_unixpath (struct sockaddr **saddrs, socklen_t * saddrlens,
742 const char *unixpath) 732 const char *unixpath)
743{ 733{
744#ifdef AF_UNIX 734#ifdef AF_UNIX
745 struct sockaddr_un *un; 735 struct sockaddr_un *un;
@@ -791,9 +781,9 @@ add_unixpath (struct sockaddr **saddrs, socklen_t * saddrlens,
791 */ 781 */
792int 782int
793GNUNET_SERVICE_get_server_addresses (const char *serviceName, 783GNUNET_SERVICE_get_server_addresses (const char *serviceName,
794 const struct GNUNET_CONFIGURATION_Handle 784 const struct GNUNET_CONFIGURATION_Handle
795 *cfg, struct sockaddr ***addrs, 785 *cfg, struct sockaddr ***addrs,
796 socklen_t ** addr_lens) 786 socklen_t ** addr_lens)
797{ 787{
798 int disablev6; 788 int disablev6;
799 struct GNUNET_NETWORK_Handle *desc; 789 struct GNUNET_NETWORK_Handle *desc;
@@ -814,64 +804,61 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName,
814 *addr_lens = NULL; 804 *addr_lens = NULL;
815 desc = NULL; 805 desc = NULL;
816 if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "DISABLEV6")) 806 if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "DISABLEV6"))
817 { 807 {
818 if (GNUNET_SYSERR == 808 if (GNUNET_SYSERR ==
819 (disablev6 = 809 (disablev6 =
820 GNUNET_CONFIGURATION_get_value_yesno (cfg, serviceName, 810 GNUNET_CONFIGURATION_get_value_yesno (cfg, serviceName, "DISABLEV6")))
821 "DISABLEV6"))) 811 return GNUNET_SYSERR;
822 return GNUNET_SYSERR; 812 }
823 }
824 else 813 else
825 disablev6 = GNUNET_NO; 814 disablev6 = GNUNET_NO;
826 815
827 if (!disablev6) 816 if (!disablev6)
817 {
818 /* probe IPv6 support */
819 desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
820 if (NULL == desc)
828 { 821 {
829 /* probe IPv6 support */ 822 if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) ||
830 desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0); 823 (errno == EACCES))
831 if (NULL == desc) 824 {
832 { 825 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
833 if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) || 826 return GNUNET_SYSERR;
834 (errno == EACCES)) 827 }
835 { 828 LOG (GNUNET_ERROR_TYPE_INFO,
836 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket"); 829 _
837 return GNUNET_SYSERR; 830 ("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
838 } 831 serviceName, STRERROR (errno));
839 LOG (GNUNET_ERROR_TYPE_INFO, 832 disablev6 = GNUNET_YES;
840 _
841 ("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
842 serviceName, STRERROR (errno));
843 disablev6 = GNUNET_YES;
844 }
845 else
846 {
847 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
848 desc = NULL;
849 }
850 } 833 }
834 else
835 {
836 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
837 desc = NULL;
838 }
839 }
851 840
852 port = 0; 841 port = 0;
853 if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "PORT")) 842 if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "PORT"))
843 {
844 GNUNET_break (GNUNET_OK ==
845 GNUNET_CONFIGURATION_get_value_number (cfg, serviceName,
846 "PORT", &port));
847 if (port > 65535)
854 { 848 {
855 GNUNET_break (GNUNET_OK == 849 LOG (GNUNET_ERROR_TYPE_ERROR,
856 GNUNET_CONFIGURATION_get_value_number (cfg, serviceName, 850 _("Require valid port number for service `%s' in configuration!\n"),
857 "PORT", &port)); 851 serviceName);
858 if (port > 65535) 852 return GNUNET_SYSERR;
859 {
860 LOG (GNUNET_ERROR_TYPE_ERROR,
861 _
862 ("Require valid port number for service `%s' in configuration!\n"),
863 serviceName);
864 return GNUNET_SYSERR;
865 }
866 } 853 }
854 }
867 855
868 if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "BINDTO")) 856 if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "BINDTO"))
869 { 857 {
870 GNUNET_break (GNUNET_OK == 858 GNUNET_break (GNUNET_OK ==
871 GNUNET_CONFIGURATION_get_value_string (cfg, serviceName, 859 GNUNET_CONFIGURATION_get_value_string (cfg, serviceName,
872 "BINDTO", 860 "BINDTO", &hostname));
873 &hostname)); 861 }
874 }
875 else 862 else
876 hostname = NULL; 863 hostname = NULL;
877 864
@@ -881,211 +868,210 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName,
881 GNUNET_CONFIGURATION_have_value (cfg, serviceName, "UNIXPATH")) && 868 GNUNET_CONFIGURATION_have_value (cfg, serviceName, "UNIXPATH")) &&
882 (GNUNET_OK == 869 (GNUNET_OK ==
883 GNUNET_CONFIGURATION_get_value_string (cfg, serviceName, "UNIXPATH", 870 GNUNET_CONFIGURATION_get_value_string (cfg, serviceName, "UNIXPATH",
884 &unixpath)) && 871 &unixpath)) &&
885 (0 < strlen (unixpath))) 872 (0 < strlen (unixpath)))
873 {
874 /* probe UNIX support */
875 struct sockaddr_un s_un;
876
877 if (strlen (unixpath) >= sizeof (s_un.sun_path))
886 { 878 {
887 /* probe UNIX support */ 879 LOG (GNUNET_ERROR_TYPE_WARNING,
888 struct sockaddr_un s_un; 880 _("UNIXPATH `%s' too long, maximum length is %llu\n"), unixpath,
889 881 sizeof (s_un.sun_path));
890 if (strlen (unixpath) >= sizeof (s_un.sun_path)) 882 GNUNET_free_non_null (hostname);
891 { 883 GNUNET_free (unixpath);
892 LOG (GNUNET_ERROR_TYPE_WARNING, 884 return GNUNET_SYSERR;
893 _("UNIXPATH `%s' too long, maximum length is %llu\n"), 885 }
894 unixpath, sizeof (s_un.sun_path)); 886
895 GNUNET_free_non_null (hostname); 887 desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
896 GNUNET_free (unixpath); 888 if (NULL == desc)
897 return GNUNET_SYSERR; 889 {
898 } 890 if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) ||
899 891 (errno == EACCES))
900 desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); 892 {
901 if (NULL == desc) 893 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
902 { 894 GNUNET_free_non_null (hostname);
903 if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) || 895 GNUNET_free (unixpath);
904 (errno == EACCES)) 896 return GNUNET_SYSERR;
905 { 897 }
906 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket"); 898 LOG (GNUNET_ERROR_TYPE_INFO,
907 GNUNET_free_non_null (hostname); 899 _
908 GNUNET_free (unixpath); 900 ("Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
909 return GNUNET_SYSERR; 901 serviceName, STRERROR (errno));
910 } 902 GNUNET_free (unixpath);
911 LOG (GNUNET_ERROR_TYPE_INFO, 903 unixpath = NULL;
912 _ 904 }
913 ("Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), 905 else
914 serviceName, STRERROR (errno)); 906 {
915 GNUNET_free (unixpath); 907 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
916 unixpath = NULL; 908 desc = NULL;
917 }
918 else
919 {
920 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
921 desc = NULL;
922 }
923 } 909 }
910 }
924#endif 911#endif
925 912
926 if ((port == 0) && (unixpath == NULL)) 913 if ((port == 0) && (unixpath == NULL))
914 {
915 LOG (GNUNET_ERROR_TYPE_ERROR,
916 _
917 ("Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
918 serviceName);
919 GNUNET_free_non_null (hostname);
920 return GNUNET_SYSERR;
921 }
922 if (port == 0)
923 {
924 saddrs = GNUNET_malloc (2 * sizeof (struct sockaddr *));
925 saddrlens = GNUNET_malloc (2 * sizeof (socklen_t));
926 add_unixpath (saddrs, saddrlens, unixpath);
927 GNUNET_free_non_null (unixpath);
928 GNUNET_free_non_null (hostname);
929 *addrs = saddrs;
930 *addr_lens = saddrlens;
931 return 1;
932 }
933
934 if (hostname != NULL)
935 {
936#if DEBUG_SERVICE
937 LOG (GNUNET_ERROR_TYPE_DEBUG,
938 "Resolving `%s' since that is where `%s' will bind to.\n", hostname,
939 serviceName);
940#endif
941 memset (&hints, 0, sizeof (struct addrinfo));
942 if (disablev6)
943 hints.ai_family = AF_INET;
944 if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) ||
945 (res == NULL))
927 { 946 {
928 LOG (GNUNET_ERROR_TYPE_ERROR, 947 LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to resolve `%s': %s\n"), hostname,
929 _ 948 gai_strerror (ret));
930 ("Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), 949 GNUNET_free (hostname);
931 serviceName); 950 GNUNET_free_non_null (unixpath);
932 GNUNET_free_non_null (hostname);
933 return GNUNET_SYSERR; 951 return GNUNET_SYSERR;
934 } 952 }
935 if (port == 0) 953 next = res;
954 i = 0;
955 while (NULL != (pos = next))
936 { 956 {
937 saddrs = GNUNET_malloc (2 * sizeof (struct sockaddr *)); 957 next = pos->ai_next;
938 saddrlens = GNUNET_malloc (2 * sizeof (socklen_t)); 958 if ((disablev6) && (pos->ai_family == AF_INET6))
939 add_unixpath (saddrs, saddrlens, unixpath); 959 continue;
960 i++;
961 }
962 if (0 == i)
963 {
964 LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to find %saddress for `%s'.\n"),
965 disablev6 ? "IPv4 " : "", hostname);
966 freeaddrinfo (res);
967 GNUNET_free (hostname);
940 GNUNET_free_non_null (unixpath); 968 GNUNET_free_non_null (unixpath);
941 GNUNET_free_non_null (hostname); 969 return GNUNET_SYSERR;
942 *addrs = saddrs;
943 *addr_lens = saddrlens;
944 return 1;
945 } 970 }
946 971 resi = i;
947 if (hostname != NULL) 972 if (NULL != unixpath)
973 resi++;
974 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
975 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
976 i = 0;
977 if (NULL != unixpath)
948 { 978 {
979 add_unixpath (saddrs, saddrlens, unixpath);
980 i++;
981 }
982 next = res;
983 while (NULL != (pos = next))
984 {
985 next = pos->ai_next;
986 if ((disablev6) && (pos->ai_family == AF_INET6))
987 continue;
988 if ((pos->ai_protocol != IPPROTO_TCP) && (pos->ai_protocol != 0))
989 continue; /* not TCP */
990 if ((pos->ai_socktype != SOCK_STREAM) && (pos->ai_socktype != 0))
991 continue; /* huh? */
949#if DEBUG_SERVICE 992#if DEBUG_SERVICE
950 LOG (GNUNET_ERROR_TYPE_DEBUG, 993 LOG (GNUNET_ERROR_TYPE_DEBUG, "Service `%s' will bind to `%s'\n",
951 "Resolving `%s' since that is where `%s' will bind to.\n", 994 serviceName, GNUNET_a2s (pos->ai_addr, pos->ai_addrlen));
952 hostname, serviceName);
953#endif 995#endif
954 memset (&hints, 0, sizeof (struct addrinfo)); 996 if (pos->ai_family == AF_INET)
955 if (disablev6) 997 {
956 hints.ai_family = AF_INET; 998 GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in));
957 if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) || 999 saddrlens[i] = pos->ai_addrlen;
958 (res == NULL)) 1000 saddrs[i] = GNUNET_malloc (saddrlens[i]);
959 { 1001 memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
960 LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to resolve `%s': %s\n"), 1002 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
961 hostname, gai_strerror (ret)); 1003 }
962 GNUNET_free (hostname); 1004 else
963 GNUNET_free_non_null (unixpath); 1005 {
964 return GNUNET_SYSERR; 1006 GNUNET_assert (pos->ai_family == AF_INET6);
965 } 1007 GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in6));
966 next = res; 1008 saddrlens[i] = pos->ai_addrlen;
967 i = 0; 1009 saddrs[i] = GNUNET_malloc (saddrlens[i]);
968 while (NULL != (pos = next)) 1010 memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
969 { 1011 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
970 next = pos->ai_next; 1012 }
971 if ((disablev6) && (pos->ai_family == AF_INET6)) 1013 i++;
972 continue; 1014 }
973 i++; 1015 GNUNET_free (hostname);
974 } 1016 freeaddrinfo (res);
975 if (0 == i) 1017 resi = i;
976 { 1018 }
977 LOG (GNUNET_ERROR_TYPE_ERROR, 1019 else
978 _("Failed to find %saddress for `%s'.\n"), 1020 {
979 disablev6 ? "IPv4 " : "", hostname); 1021 /* will bind against everything, just set port */
980 freeaddrinfo (res); 1022 if (disablev6)
981 GNUNET_free (hostname); 1023 {
982 GNUNET_free_non_null (unixpath); 1024 /* V4-only */
983 return GNUNET_SYSERR; 1025 resi = 1;
984 }
985 resi = i;
986 if (NULL != unixpath) 1026 if (NULL != unixpath)
987 resi++; 1027 resi++;
1028 i = 0;
988 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *)); 1029 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
989 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t)); 1030 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
990 i = 0;
991 if (NULL != unixpath) 1031 if (NULL != unixpath)
992 { 1032 {
993 add_unixpath (saddrs, saddrlens, unixpath); 1033 add_unixpath (saddrs, saddrlens, unixpath);
994 i++; 1034 i++;
995 } 1035 }
996 next = res; 1036 saddrlens[i] = sizeof (struct sockaddr_in);
997 while (NULL != (pos = next)) 1037 saddrs[i] = GNUNET_malloc (saddrlens[i]);
998 { 1038#if HAVE_SOCKADDR_IN_SIN_LEN
999 next = pos->ai_next; 1039 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i];
1000 if ((disablev6) && (pos->ai_family == AF_INET6))
1001 continue;
1002 if ((pos->ai_protocol != IPPROTO_TCP) && (pos->ai_protocol != 0))
1003 continue; /* not TCP */
1004 if ((pos->ai_socktype != SOCK_STREAM) && (pos->ai_socktype != 0))
1005 continue; /* huh? */
1006#if DEBUG_SERVICE
1007 LOG (GNUNET_ERROR_TYPE_DEBUG, "Service `%s' will bind to `%s'\n",
1008 serviceName, GNUNET_a2s (pos->ai_addr, pos->ai_addrlen));
1009#endif 1040#endif
1010 if (pos->ai_family == AF_INET) 1041 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
1011 { 1042 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
1012 GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in));
1013 saddrlens[i] = pos->ai_addrlen;
1014 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1015 memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
1016 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
1017 }
1018 else
1019 {
1020 GNUNET_assert (pos->ai_family == AF_INET6);
1021 GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in6));
1022 saddrlens[i] = pos->ai_addrlen;
1023 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1024 memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
1025 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
1026 }
1027 i++;
1028 }
1029 GNUNET_free (hostname);
1030 freeaddrinfo (res);
1031 resi = i;
1032 } 1043 }
1033 else 1044 else
1034 { 1045 {
1035 /* will bind against everything, just set port */ 1046 /* dual stack */
1036 if (disablev6) 1047 resi = 2;
1037 { 1048 if (NULL != unixpath)
1038 /* V4-only */ 1049 resi++;
1039 resi = 1; 1050 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
1040 if (NULL != unixpath) 1051 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
1041 resi++; 1052 i = 0;
1042 i = 0; 1053 if (NULL != unixpath)
1043 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *)); 1054 {
1044 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t)); 1055 add_unixpath (saddrs, saddrlens, unixpath);
1045 if (NULL != unixpath) 1056 i++;
1046 { 1057 }
1047 add_unixpath (saddrs, saddrlens, unixpath); 1058 saddrlens[i] = sizeof (struct sockaddr_in6);
1048 i++; 1059 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1049 }
1050 saddrlens[i] = sizeof (struct sockaddr_in);
1051 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1052#if HAVE_SOCKADDR_IN_SIN_LEN
1053 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i];
1054#endif
1055 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
1056 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
1057 }
1058 else
1059 {
1060 /* dual stack */
1061 resi = 2;
1062 if (NULL != unixpath)
1063 resi++;
1064 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
1065 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
1066 i = 0;
1067 if (NULL != unixpath)
1068 {
1069 add_unixpath (saddrs, saddrlens, unixpath);
1070 i++;
1071 }
1072 saddrlens[i] = sizeof (struct sockaddr_in6);
1073 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1074#if HAVE_SOCKADDR_IN_SIN_LEN 1060#if HAVE_SOCKADDR_IN_SIN_LEN
1075 ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0]; 1061 ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0];
1076#endif 1062#endif
1077 ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6; 1063 ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6;
1078 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); 1064 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
1079 i++; 1065 i++;
1080 saddrlens[i] = sizeof (struct sockaddr_in); 1066 saddrlens[i] = sizeof (struct sockaddr_in);
1081 saddrs[i] = GNUNET_malloc (saddrlens[i]); 1067 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1082#if HAVE_SOCKADDR_IN_SIN_LEN 1068#if HAVE_SOCKADDR_IN_SIN_LEN
1083 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1]; 1069 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1];
1084#endif 1070#endif
1085 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; 1071 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
1086 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); 1072 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
1087 }
1088 } 1073 }
1074 }
1089 GNUNET_free_non_null (unixpath); 1075 GNUNET_free_non_null (unixpath);
1090 *addrs = saddrs; 1076 *addrs = saddrs;
1091 *addr_lens = saddrlens; 1077 *addr_lens = saddrlens;
@@ -1124,37 +1110,36 @@ setup_service (struct GNUNET_SERVICE_Context *sctx)
1124 int flags; 1110 int flags;
1125#endif 1111#endif
1126 1112
1127 if (GNUNET_CONFIGURATION_have_value 1113 if (GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->serviceName, "TIMEOUT"))
1128 (sctx->cfg, sctx->serviceName, "TIMEOUT")) 1114 {
1115 if (GNUNET_OK !=
1116 GNUNET_CONFIGURATION_get_value_time (sctx->cfg, sctx->serviceName,
1117 "TIMEOUT", &idleout))
1129 { 1118 {
1130 if (GNUNET_OK != 1119 LOG (GNUNET_ERROR_TYPE_ERROR,
1131 GNUNET_CONFIGURATION_get_value_time (sctx->cfg, sctx->serviceName, 1120 _("Specified value for `%s' of service `%s' is invalid\n"),
1132 "TIMEOUT", &idleout)) 1121 "TIMEOUT", sctx->serviceName);
1133 { 1122 return GNUNET_SYSERR;
1134 LOG (GNUNET_ERROR_TYPE_ERROR,
1135 _("Specified value for `%s' of service `%s' is invalid\n"),
1136 "TIMEOUT", sctx->serviceName);
1137 return GNUNET_SYSERR;
1138 }
1139 sctx->timeout = idleout;
1140 } 1123 }
1124 sctx->timeout = idleout;
1125 }
1141 else 1126 else
1142 sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; 1127 sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
1143 1128
1144 if (GNUNET_CONFIGURATION_have_value 1129 if (GNUNET_CONFIGURATION_have_value
1145 (sctx->cfg, sctx->serviceName, "TOLERANT")) 1130 (sctx->cfg, sctx->serviceName, "TOLERANT"))
1131 {
1132 if (GNUNET_SYSERR ==
1133 (tolerant =
1134 GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->serviceName,
1135 "TOLERANT")))
1146 { 1136 {
1147 if (GNUNET_SYSERR == 1137 LOG (GNUNET_ERROR_TYPE_ERROR,
1148 (tolerant = 1138 _("Specified value for `%s' of service `%s' is invalid\n"),
1149 GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->serviceName, 1139 "TOLERANT", sctx->serviceName);
1150 "TOLERANT"))) 1140 return GNUNET_SYSERR;
1151 {
1152 LOG (GNUNET_ERROR_TYPE_ERROR,
1153 _("Specified value for `%s' of service `%s' is invalid\n"),
1154 "TOLERANT", sctx->serviceName);
1155 return GNUNET_SYSERR;
1156 }
1157 } 1141 }
1142 }
1158 else 1143 else
1159 tolerant = GNUNET_NO; 1144 tolerant = GNUNET_NO;
1160 1145
@@ -1165,48 +1150,45 @@ setup_service (struct GNUNET_SERVICE_Context *sctx)
1165 (NULL != (nfds = getenv ("LISTEN_FDS"))) && 1150 (NULL != (nfds = getenv ("LISTEN_FDS"))) &&
1166 (1 == sscanf (nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) && 1151 (1 == sscanf (nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) &&
1167 (cnt + 4 < FD_SETSIZE)) 1152 (cnt + 4 < FD_SETSIZE))
1153 {
1154 sctx->lsocks =
1155 GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (cnt + 1));
1156 while (0 < cnt--)
1168 { 1157 {
1169 sctx->lsocks = 1158 flags = fcntl (3 + cnt, F_GETFD);
1170 GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (cnt + 1)); 1159 if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) ||
1171 while (0 < cnt--) 1160 (NULL ==
1172 { 1161 (sctx->lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt))))
1173 flags = fcntl (3 + cnt, F_GETFD); 1162 {
1174 if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) || 1163 LOG (GNUNET_ERROR_TYPE_ERROR,
1175 (NULL == 1164 _
1176 (sctx->lsocks[cnt] = 1165 ("Could not access pre-bound socket %u, will try to bind myself\n"),
1177 GNUNET_NETWORK_socket_box_native (3 + cnt)))) 1166 (unsigned int) 3 + cnt);
1178 { 1167 cnt++;
1179 LOG (GNUNET_ERROR_TYPE_ERROR, 1168 while (sctx->lsocks[cnt] != NULL)
1180 _ 1169 GNUNET_break (0 == GNUNET_NETWORK_socket_close (sctx->lsocks[cnt++]));
1181 ("Could not access pre-bound socket %u, will try to bind myself\n"), 1170 GNUNET_free (sctx->lsocks);
1182 (unsigned int) 3 + cnt); 1171 sctx->lsocks = NULL;
1183 cnt++; 1172 break;
1184 while (sctx->lsocks[cnt] != NULL) 1173 }
1185 GNUNET_break (0 ==
1186 GNUNET_NETWORK_socket_close (sctx->lsocks
1187 [cnt++]));
1188 GNUNET_free (sctx->lsocks);
1189 sctx->lsocks = NULL;
1190 break;
1191 }
1192 }
1193 unsetenv ("LISTEN_PID");
1194 unsetenv ("LISTEN_FDS");
1195 } 1174 }
1175 unsetenv ("LISTEN_PID");
1176 unsetenv ("LISTEN_FDS");
1177 }
1196#endif 1178#endif
1197 1179
1198 if ((sctx->lsocks == NULL) && 1180 if ((sctx->lsocks == NULL) &&
1199 (GNUNET_SYSERR == 1181 (GNUNET_SYSERR ==
1200 GNUNET_SERVICE_get_server_addresses (sctx->serviceName, sctx->cfg, 1182 GNUNET_SERVICE_get_server_addresses (sctx->serviceName, sctx->cfg,
1201 &sctx->addrs, &sctx->addrlens))) 1183 &sctx->addrs, &sctx->addrlens)))
1202 return GNUNET_SYSERR; 1184 return GNUNET_SYSERR;
1203 sctx->require_found = tolerant ? GNUNET_NO : GNUNET_YES; 1185 sctx->require_found = tolerant ? GNUNET_NO : GNUNET_YES;
1204 sctx->match_uid = 1186 sctx->match_uid =
1205 GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->serviceName, 1187 GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->serviceName,
1206 "UNIX_MATCH_UID"); 1188 "UNIX_MATCH_UID");
1207 sctx->match_gid = 1189 sctx->match_gid =
1208 GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->serviceName, 1190 GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->serviceName,
1209 "UNIX_MATCH_GID"); 1191 "UNIX_MATCH_GID");
1210 process_acl4 (&sctx->v4_denied, sctx, "REJECT_FROM"); 1192 process_acl4 (&sctx->v4_denied, sctx, "REJECT_FROM");
1211 process_acl4 (&sctx->v4_allowed, sctx, "ACCEPT_FROM"); 1193 process_acl4 (&sctx->v4_allowed, sctx, "ACCEPT_FROM");
1212 process_acl6 (&sctx->v6_denied, sctx, "REJECT_FROM6"); 1194 process_acl6 (&sctx->v6_denied, sctx, "REJECT_FROM6");
@@ -1228,7 +1210,7 @@ get_user_name (struct GNUNET_SERVICE_Context *sctx)
1228 1210
1229 if (GNUNET_OK != 1211 if (GNUNET_OK !=
1230 GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, sctx->serviceName, 1212 GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, sctx->serviceName,
1231 "USERNAME", &un)) 1213 "USERNAME", &un))
1232 return NULL; 1214 return NULL;
1233 return un; 1215 return un;
1234} 1216}
@@ -1246,7 +1228,7 @@ write_pid_file (struct GNUNET_SERVICE_Context *sctx, pid_t pid)
1246 int len; 1228 int len;
1247 1229
1248 if (NULL == (pif = get_pid_file_name (sctx))) 1230 if (NULL == (pif = get_pid_file_name (sctx)))
1249 return GNUNET_OK; /* no file desired */ 1231 return GNUNET_OK; /* no file desired */
1250 user = get_user_name (sctx); 1232 user = get_user_name (sctx);
1251 rdir = GNUNET_strdup (pif); 1233 rdir = GNUNET_strdup (pif);
1252 len = strlen (rdir); 1234 len = strlen (rdir);
@@ -1254,30 +1236,30 @@ write_pid_file (struct GNUNET_SERVICE_Context *sctx, pid_t pid)
1254 len--; 1236 len--;
1255 rdir[len] = '\0'; 1237 rdir[len] = '\0';
1256 if (0 != ACCESS (rdir, F_OK)) 1238 if (0 != ACCESS (rdir, F_OK))
1257 { 1239 {
1258 /* we get to create a directory -- and claim it 1240 /* we get to create a directory -- and claim it
1259 * as ours! */ 1241 * as ours! */
1260 GNUNET_DISK_directory_create (rdir); 1242 GNUNET_DISK_directory_create (rdir);
1261 if ((user != NULL) && (0 < strlen (user))) 1243 if ((user != NULL) && (0 < strlen (user)))
1262 GNUNET_DISK_file_change_owner (rdir, user); 1244 GNUNET_DISK_file_change_owner (rdir, user);
1263 } 1245 }
1264 if (0 != ACCESS (rdir, W_OK | X_OK)) 1246 if (0 != ACCESS (rdir, W_OK | X_OK))
1265 { 1247 {
1266 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", rdir); 1248 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", rdir);
1267 GNUNET_free (rdir); 1249 GNUNET_free (rdir);
1268 GNUNET_free_non_null (user); 1250 GNUNET_free_non_null (user);
1269 GNUNET_free (pif); 1251 GNUNET_free (pif);
1270 return GNUNET_SYSERR; 1252 return GNUNET_SYSERR;
1271 } 1253 }
1272 GNUNET_free (rdir); 1254 GNUNET_free (rdir);
1273 pidfd = FOPEN (pif, "w"); 1255 pidfd = FOPEN (pif, "w");
1274 if (pidfd == NULL) 1256 if (pidfd == NULL)
1275 { 1257 {
1276 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "fopen", pif); 1258 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "fopen", pif);
1277 GNUNET_free (pif); 1259 GNUNET_free (pif);
1278 GNUNET_free_non_null (user); 1260 GNUNET_free_non_null (user);
1279 return GNUNET_SYSERR; 1261 return GNUNET_SYSERR;
1280 } 1262 }
1281 if (0 > FPRINTF (pidfd, "%u", pid)) 1263 if (0 > FPRINTF (pidfd, "%u", pid))
1282 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", pif); 1264 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", pif);
1283 GNUNET_break (0 == fclose (pidfd)); 1265 GNUNET_break (0 == fclose (pidfd));
@@ -1316,35 +1298,34 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1316 GNUNET_RESOLVER_connect (sctx->cfg); 1298 GNUNET_RESOLVER_connect (sctx->cfg);
1317 if (sctx->lsocks != NULL) 1299 if (sctx->lsocks != NULL)
1318 sctx->server = 1300 sctx->server =
1319 GNUNET_SERVER_create_with_sockets (&check_access, sctx, sctx->lsocks, 1301 GNUNET_SERVER_create_with_sockets (&check_access, sctx, sctx->lsocks,
1320 sctx->timeout, sctx->require_found); 1302 sctx->timeout, sctx->require_found);
1321 else 1303 else
1322 sctx->server = 1304 sctx->server =
1323 GNUNET_SERVER_create (&check_access, sctx, sctx->addrs, sctx->addrlens, 1305 GNUNET_SERVER_create (&check_access, sctx, sctx->addrs, sctx->addrlens,
1324 sctx->timeout, sctx->require_found); 1306 sctx->timeout, sctx->require_found);
1325 if (sctx->server == NULL) 1307 if (sctx->server == NULL)
1308 {
1309 if (sctx->addrs != NULL)
1326 { 1310 {
1327 if (sctx->addrs != NULL) 1311 i = 0;
1328 { 1312 while (sctx->addrs[i] != NULL)
1329 i = 0; 1313 {
1330 while (sctx->addrs[i] != NULL) 1314 LOG (GNUNET_ERROR_TYPE_INFO, _("Failed to start `%s' at `%s'\n"),
1331 { 1315 sctx->serviceName, GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
1332 LOG (GNUNET_ERROR_TYPE_INFO, 1316 i++;
1333 _("Failed to start `%s' at `%s'\n"), sctx->serviceName, 1317 }
1334 GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
1335 i++;
1336 }
1337 }
1338 sctx->ret = GNUNET_SYSERR;
1339 return;
1340 } 1318 }
1319 sctx->ret = GNUNET_SYSERR;
1320 return;
1321 }
1341 if (0 == (sctx->options & GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN)) 1322 if (0 == (sctx->options & GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN))
1342 { 1323 {
1343 /* install a task that will kill the server 1324 /* install a task that will kill the server
1344 * process if the scheduler ever gets a shutdown signal */ 1325 * process if the scheduler ever gets a shutdown signal */
1345 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 1326 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
1346 &shutdown_task, sctx->server); 1327 sctx->server);
1347 } 1328 }
1348 sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers)); 1329 sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers));
1349 memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers)); 1330 memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers));
1350 i = 0; 1331 i = 0;
@@ -1352,23 +1333,22 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1352 sctx->my_handlers[i++].callback_cls = sctx; 1333 sctx->my_handlers[i++].callback_cls = sctx;
1353 GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers); 1334 GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers);
1354 if (sctx->ready_confirm_fd != -1) 1335 if (sctx->ready_confirm_fd != -1)
1355 { 1336 {
1356 GNUNET_break (1 == WRITE (sctx->ready_confirm_fd, ".", 1)); 1337 GNUNET_break (1 == WRITE (sctx->ready_confirm_fd, ".", 1));
1357 GNUNET_break (0 == CLOSE (sctx->ready_confirm_fd)); 1338 GNUNET_break (0 == CLOSE (sctx->ready_confirm_fd));
1358 sctx->ready_confirm_fd = -1; 1339 sctx->ready_confirm_fd = -1;
1359 write_pid_file (sctx, getpid ()); 1340 write_pid_file (sctx, getpid ());
1360 } 1341 }
1361 if (sctx->addrs != NULL) 1342 if (sctx->addrs != NULL)
1343 {
1344 i = 0;
1345 while (sctx->addrs[i] != NULL)
1362 { 1346 {
1363 i = 0; 1347 LOG (GNUNET_ERROR_TYPE_INFO, _("Service `%s' runs at %s\n"),
1364 while (sctx->addrs[i] != NULL) 1348 sctx->serviceName, GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
1365 { 1349 i++;
1366 LOG (GNUNET_ERROR_TYPE_INFO, _("Service `%s' runs at %s\n"),
1367 sctx->serviceName, GNUNET_a2s (sctx->addrs[i],
1368 sctx->addrlens[i]));
1369 i++;
1370 }
1371 } 1350 }
1351 }
1372 sctx->task (sctx->task_cls, sctx->server, sctx->cfg); 1352 sctx->task (sctx->task_cls, sctx->server, sctx->cfg);
1373} 1353}
1374 1354
@@ -1385,45 +1365,44 @@ detach_terminal (struct GNUNET_SERVICE_Context *sctx)
1385 int filedes[2]; 1365 int filedes[2];
1386 1366
1387 if (0 != PIPE (filedes)) 1367 if (0 != PIPE (filedes))
1388 { 1368 {
1389 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe"); 1369 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe");
1390 return GNUNET_SYSERR; 1370 return GNUNET_SYSERR;
1391 } 1371 }
1392 pid = fork (); 1372 pid = fork ();
1393 if (pid < 0) 1373 if (pid < 0)
1394 { 1374 {
1395 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork"); 1375 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork");
1396 return GNUNET_SYSERR; 1376 return GNUNET_SYSERR;
1397 } 1377 }
1398 if (pid != 0) 1378 if (pid != 0)
1379 {
1380 /* Parent */
1381 char c;
1382
1383 GNUNET_break (0 == CLOSE (filedes[1]));
1384 c = 'X';
1385 if (1 != READ (filedes[0], &c, sizeof (char)))
1386 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "read");
1387 fflush (stdout);
1388 switch (c)
1399 { 1389 {
1400 /* Parent */ 1390 case '.':
1401 char c; 1391 exit (0);
1402 1392 case 'I':
1403 GNUNET_break (0 == CLOSE (filedes[1])); 1393 LOG (GNUNET_ERROR_TYPE_INFO, _("Service process failed to initialize\n"));
1404 c = 'X'; 1394 break;
1405 if (1 != READ (filedes[0], &c, sizeof (char))) 1395 case 'S':
1406 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "read"); 1396 LOG (GNUNET_ERROR_TYPE_INFO,
1407 fflush (stdout); 1397 _("Service process could not initialize server function\n"));
1408 switch (c) 1398 break;
1409 { 1399 case 'X':
1410 case '.': 1400 LOG (GNUNET_ERROR_TYPE_INFO,
1411 exit (0); 1401 _("Service process failed to report status\n"));
1412 case 'I': 1402 break;
1413 LOG (GNUNET_ERROR_TYPE_INFO,
1414 _("Service process failed to initialize\n"));
1415 break;
1416 case 'S':
1417 LOG (GNUNET_ERROR_TYPE_INFO,
1418 _("Service process could not initialize server function\n"));
1419 break;
1420 case 'X':
1421 LOG (GNUNET_ERROR_TYPE_INFO,
1422 _("Service process failed to report status\n"));
1423 break;
1424 }
1425 exit (1); /* child reported error */
1426 } 1403 }
1404 exit (1); /* child reported error */
1405 }
1427 GNUNET_break (0 == CLOSE (0)); 1406 GNUNET_break (0 == CLOSE (0));
1428 GNUNET_break (0 == CLOSE (1)); 1407 GNUNET_break (0 == CLOSE (1));
1429 GNUNET_break (0 == CLOSE (filedes[0])); 1408 GNUNET_break (0 == CLOSE (filedes[0]));
@@ -1432,11 +1411,11 @@ detach_terminal (struct GNUNET_SERVICE_Context *sctx)
1432 return GNUNET_SYSERR; 1411 return GNUNET_SYSERR;
1433 /* set stdin/stdout to /dev/null */ 1412 /* set stdin/stdout to /dev/null */
1434 if ((dup2 (nullfd, 0) < 0) || (dup2 (nullfd, 1) < 0)) 1413 if ((dup2 (nullfd, 0) < 0) || (dup2 (nullfd, 1) < 0))
1435 { 1414 {
1436 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2"); 1415 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
1437 (void) CLOSE (nullfd); 1416 (void) CLOSE (nullfd);
1438 return GNUNET_SYSERR; 1417 return GNUNET_SYSERR;
1439 } 1418 }
1440 (void) CLOSE (nullfd); 1419 (void) CLOSE (nullfd);
1441 /* Detach from controlling terminal */ 1420 /* Detach from controlling terminal */
1442 pid = setsid (); 1421 pid = setsid ();
@@ -1461,36 +1440,35 @@ set_user_id (struct GNUNET_SERVICE_Context *sctx)
1461 char *user; 1440 char *user;
1462 1441
1463 if (NULL == (user = get_user_name (sctx))) 1442 if (NULL == (user = get_user_name (sctx)))
1464 return GNUNET_OK; /* keep */ 1443 return GNUNET_OK; /* keep */
1465#ifndef MINGW 1444#ifndef MINGW
1466 struct passwd *pws; 1445 struct passwd *pws;
1467 1446
1468 errno = 0; 1447 errno = 0;
1469 pws = getpwnam (user); 1448 pws = getpwnam (user);
1470 if (pws == NULL) 1449 if (pws == NULL)
1471 { 1450 {
1472 LOG (GNUNET_ERROR_TYPE_ERROR, 1451 LOG (GNUNET_ERROR_TYPE_ERROR,
1473 _("Cannot obtain information about user `%s': %s\n"), user, 1452 _("Cannot obtain information about user `%s': %s\n"), user,
1474 errno == 0 ? _("No such user") : STRERROR (errno)); 1453 errno == 0 ? _("No such user") : STRERROR (errno));
1475 GNUNET_free (user); 1454 GNUNET_free (user);
1476 return GNUNET_SYSERR; 1455 return GNUNET_SYSERR;
1477 } 1456 }
1478 if ((0 != setgid (pws->pw_gid)) || (0 != setegid (pws->pw_gid)) || 1457 if ((0 != setgid (pws->pw_gid)) || (0 != setegid (pws->pw_gid)) ||
1479#if HAVE_INITGROUPS 1458#if HAVE_INITGROUPS
1480 (0 != initgroups (user, pws->pw_gid)) || 1459 (0 != initgroups (user, pws->pw_gid)) ||
1481#endif 1460#endif
1482 (0 != setuid (pws->pw_uid)) || (0 != seteuid (pws->pw_uid))) 1461 (0 != setuid (pws->pw_uid)) || (0 != seteuid (pws->pw_uid)))
1462 {
1463 if ((0 != setregid (pws->pw_gid, pws->pw_gid)) ||
1464 (0 != setreuid (pws->pw_uid, pws->pw_uid)))
1483 { 1465 {
1484 if ((0 != setregid (pws->pw_gid, pws->pw_gid)) || 1466 LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot change user/group to `%s': %s\n"),
1485 (0 != setreuid (pws->pw_uid, pws->pw_uid))) 1467 user, STRERROR (errno));
1486 { 1468 GNUNET_free (user);
1487 LOG (GNUNET_ERROR_TYPE_ERROR, 1469 return GNUNET_SYSERR;
1488 _("Cannot change user/group to `%s': %s\n"), user,
1489 STRERROR (errno));
1490 GNUNET_free (user);
1491 return GNUNET_SYSERR;
1492 }
1493 } 1470 }
1471 }
1494#endif 1472#endif
1495 GNUNET_free (user); 1473 GNUNET_free (user);
1496 return GNUNET_OK; 1474 return GNUNET_OK;
@@ -1506,7 +1484,7 @@ pid_file_delete (struct GNUNET_SERVICE_Context *sctx)
1506 char *pif = get_pid_file_name (sctx); 1484 char *pif = get_pid_file_name (sctx);
1507 1485
1508 if (pif == NULL) 1486 if (pif == NULL)
1509 return; /* no PID file */ 1487 return; /* no PID file */
1510 if (0 != UNLINK (pif)) 1488 if (0 != UNLINK (pif))
1511 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", pif); 1489 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", pif);
1512 GNUNET_free (pif); 1490 GNUNET_free (pif);
@@ -1528,8 +1506,8 @@ pid_file_delete (struct GNUNET_SERVICE_Context *sctx)
1528 */ 1506 */
1529int 1507int
1530GNUNET_SERVICE_run (int argc, char *const *argv, const char *serviceName, 1508GNUNET_SERVICE_run (int argc, char *const *argv, const char *serviceName,
1531 enum GNUNET_SERVICE_Options opt, GNUNET_SERVICE_Main task, 1509 enum GNUNET_SERVICE_Options opt, GNUNET_SERVICE_Main task,
1532 void *task_cls) 1510 void *task_cls)
1533{ 1511{
1534#define HANDLE_ERROR do { GNUNET_break (0); goto shutdown; } while (0) 1512#define HANDLE_ERROR do { GNUNET_break (0); goto shutdown; } while (0)
1535 1513
@@ -1586,23 +1564,21 @@ GNUNET_SERVICE_run (int argc, char *const *argv, const char *serviceName,
1586 goto shutdown; 1564 goto shutdown;
1587#if DEBUG_SERVICE 1565#if DEBUG_SERVICE
1588 LOG (GNUNET_ERROR_TYPE_DEBUG, 1566 LOG (GNUNET_ERROR_TYPE_DEBUG,
1589 "Service `%s' runs with configuration from `%s'\n", serviceName, 1567 "Service `%s' runs with configuration from `%s'\n", serviceName, cfg_fn);
1590 cfg_fn);
1591#endif 1568#endif
1592 if (GNUNET_OK == 1569 if (GNUNET_OK ==
1593 GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "testing", 1570 GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "testing", "skew_offset",
1594 "skew_offset", &skew_offset) 1571 &skew_offset) &&
1595 && (GNUNET_OK == 1572 (GNUNET_OK ==
1596 GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "testing", 1573 GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "testing",
1597 "skew_variance", 1574 "skew_variance", &skew_variance)))
1598 &skew_variance))) 1575 {
1599 { 1576 clock_offset = skew_offset - skew_variance;
1600 clock_offset = skew_offset - skew_variance; 1577 GNUNET_TIME_set_offset (clock_offset);
1601 GNUNET_TIME_set_offset (clock_offset);
1602#if DEBUG_SERVICE 1578#if DEBUG_SERVICE
1603 LOG (GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll\n", clock_offset); 1579 LOG (GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll\n", clock_offset);
1604#endif 1580#endif
1605 } 1581 }
1606 /* actually run service */ 1582 /* actually run service */
1607 err = 0; 1583 err = 0;
1608 GNUNET_SCHEDULER_run (&service_task, &sctx); 1584 GNUNET_SCHEDULER_run (&service_task, &sctx);
@@ -1614,11 +1590,11 @@ GNUNET_SERVICE_run (int argc, char *const *argv, const char *serviceName,
1614 1590
1615shutdown: 1591shutdown:
1616 if (sctx.ready_confirm_fd != -1) 1592 if (sctx.ready_confirm_fd != -1)
1617 { 1593 {
1618 if (1 != WRITE (sctx.ready_confirm_fd, err ? "I" : "S", 1)) 1594 if (1 != WRITE (sctx.ready_confirm_fd, err ? "I" : "S", 1))
1619 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "write"); 1595 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "write");
1620 GNUNET_break (0 == CLOSE (sctx.ready_confirm_fd)); 1596 GNUNET_break (0 == CLOSE (sctx.ready_confirm_fd));
1621 } 1597 }
1622 1598
1623 GNUNET_CONFIGURATION_destroy (cfg); 1599 GNUNET_CONFIGURATION_destroy (cfg);
1624 i = 0; 1600 i = 0;
@@ -1649,13 +1625,13 @@ shutdown:
1649 */ 1625 */
1650struct GNUNET_SERVICE_Context * 1626struct GNUNET_SERVICE_Context *
1651GNUNET_SERVICE_start (const char *serviceName, 1627GNUNET_SERVICE_start (const char *serviceName,
1652 const struct GNUNET_CONFIGURATION_Handle *cfg) 1628 const struct GNUNET_CONFIGURATION_Handle *cfg)
1653{ 1629{
1654 int i; 1630 int i;
1655 struct GNUNET_SERVICE_Context *sctx; 1631 struct GNUNET_SERVICE_Context *sctx;
1656 1632
1657 sctx = GNUNET_malloc (sizeof (struct GNUNET_SERVICE_Context)); 1633 sctx = GNUNET_malloc (sizeof (struct GNUNET_SERVICE_Context));
1658 sctx->ready_confirm_fd = -1; /* no daemonizing */ 1634 sctx->ready_confirm_fd = -1; /* no daemonizing */
1659 sctx->ret = GNUNET_OK; 1635 sctx->ret = GNUNET_OK;
1660 sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; 1636 sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
1661 sctx->serviceName = serviceName; 1637 sctx->serviceName = serviceName;
@@ -1663,24 +1639,24 @@ GNUNET_SERVICE_start (const char *serviceName,
1663 1639
1664 /* setup subsystems */ 1640 /* setup subsystems */
1665 if (GNUNET_OK != setup_service (sctx)) 1641 if (GNUNET_OK != setup_service (sctx))
1666 { 1642 {
1667 GNUNET_SERVICE_stop (sctx); 1643 GNUNET_SERVICE_stop (sctx);
1668 return NULL; 1644 return NULL;
1669 } 1645 }
1670 if (sctx->lsocks != NULL) 1646 if (sctx->lsocks != NULL)
1671 sctx->server = 1647 sctx->server =
1672 GNUNET_SERVER_create_with_sockets (&check_access, sctx, sctx->lsocks, 1648 GNUNET_SERVER_create_with_sockets (&check_access, sctx, sctx->lsocks,
1673 sctx->timeout, sctx->require_found); 1649 sctx->timeout, sctx->require_found);
1674 else 1650 else
1675 sctx->server = 1651 sctx->server =
1676 GNUNET_SERVER_create (&check_access, sctx, sctx->addrs, sctx->addrlens, 1652 GNUNET_SERVER_create (&check_access, sctx, sctx->addrs, sctx->addrlens,
1677 sctx->timeout, sctx->require_found); 1653 sctx->timeout, sctx->require_found);
1678 1654
1679 if (NULL == sctx->server) 1655 if (NULL == sctx->server)
1680 { 1656 {
1681 GNUNET_SERVICE_stop (sctx); 1657 GNUNET_SERVICE_stop (sctx);
1682 return NULL; 1658 return NULL;
1683 } 1659 }
1684 sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers)); 1660 sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers));
1685 memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers)); 1661 memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers));
1686 i = 0; 1662 i = 0;
@@ -1718,12 +1694,12 @@ GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Context *sctx)
1718 GNUNET_SERVER_destroy (sctx->server); 1694 GNUNET_SERVER_destroy (sctx->server);
1719 GNUNET_free_non_null (sctx->my_handlers); 1695 GNUNET_free_non_null (sctx->my_handlers);
1720 if (sctx->addrs != NULL) 1696 if (sctx->addrs != NULL)
1721 { 1697 {
1722 i = 0; 1698 i = 0;
1723 while (sctx->addrs[i] != NULL) 1699 while (sctx->addrs[i] != NULL)
1724 GNUNET_free (sctx->addrs[i++]); 1700 GNUNET_free (sctx->addrs[i++]);
1725 GNUNET_free (sctx->addrs); 1701 GNUNET_free (sctx->addrs);
1726 } 1702 }
1727 GNUNET_free_non_null (sctx->addrlens); 1703 GNUNET_free_non_null (sctx->addrlens);
1728 GNUNET_free_non_null (sctx->v4_denied); 1704 GNUNET_free_non_null (sctx->v4_denied);
1729 GNUNET_free_non_null (sctx->v6_denied); 1705 GNUNET_free_non_null (sctx->v6_denied);
diff --git a/src/util/signal.c b/src/util/signal.c
index a986b6260..c3bb718bf 100644
--- a/src/util/signal.c
+++ b/src/util/signal.c
@@ -63,7 +63,7 @@ GNUNET_SIGNAL_handler_install (int signum, GNUNET_SIGNAL_Handler handler)
63 sig.sa_handler = (void *) handler; 63 sig.sa_handler = (void *) handler;
64 sigemptyset (&sig.sa_mask); 64 sigemptyset (&sig.sa_mask);
65#ifdef SA_INTERRUPT 65#ifdef SA_INTERRUPT
66 sig.sa_flags = SA_INTERRUPT; /* SunOS */ 66 sig.sa_flags = SA_INTERRUPT; /* SunOS */
67#else 67#else
68 sig.sa_flags = SA_RESTART; 68 sig.sa_flags = SA_RESTART;
69#endif 69#endif
@@ -72,15 +72,15 @@ GNUNET_SIGNAL_handler_install (int signum, GNUNET_SIGNAL_Handler handler)
72 if (signum == GNUNET_SIGCHLD) 72 if (signum == GNUNET_SIGCHLD)
73 w32_sigchld_handler = handler; 73 w32_sigchld_handler = handler;
74 else 74 else
75 { 75 {
76 __p_sig_fn_t sigret = signal (signum, (__p_sig_fn_t) handler); 76 __p_sig_fn_t sigret = signal (signum, (__p_sig_fn_t) handler);
77 77
78 if (sigret == SIG_ERR) 78 if (sigret == SIG_ERR)
79 { 79 {
80 LOG (GNUNET_ERROR_TYPE_WARNING, 80 LOG (GNUNET_ERROR_TYPE_WARNING, _("signal (%d, %p) returned %d.\n"),
81 _("signal (%d, %p) returned %d.\n"), signum, handler, sigret); 81 signum, handler, sigret);
82 }
83 } 82 }
83 }
84#endif 84#endif
85 return ret; 85 return ret;
86} 86}
diff --git a/src/util/strings.c b/src/util/strings.c
index d48d552a1..dc4037a1f 100644
--- a/src/util/strings.c
+++ b/src/util/strings.c
@@ -59,8 +59,7 @@
59 * (or number of bytes that would have been written) 59 * (or number of bytes that would have been written)
60 */ 60 */
61size_t 61size_t
62GNUNET_STRINGS_buffer_fill (char *buffer, size_t size, unsigned int count, 62GNUNET_STRINGS_buffer_fill (char *buffer, size_t size, unsigned int count, ...)
63 ...)
64{ 63{
65 size_t needed; 64 size_t needed;
66 size_t slen; 65 size_t slen;
@@ -70,18 +69,18 @@ GNUNET_STRINGS_buffer_fill (char *buffer, size_t size, unsigned int count,
70 needed = 0; 69 needed = 0;
71 va_start (ap, count); 70 va_start (ap, count);
72 while (count > 0) 71 while (count > 0)
73 { 72 {
74 s = va_arg (ap, const char *); 73 s = va_arg (ap, const char *);
75 74
76 slen = strlen (s) + 1; 75 slen = strlen (s) + 1;
77 if (buffer != NULL) 76 if (buffer != NULL)
78 { 77 {
79 GNUNET_assert (needed + slen <= size); 78 GNUNET_assert (needed + slen <= size);
80 memcpy (&buffer[needed], s, slen); 79 memcpy (&buffer[needed], s, slen);
81 }
82 needed += slen;
83 count--;
84 } 80 }
81 needed += slen;
82 count--;
83 }
85 va_end (ap); 84 va_end (ap);
86 return needed; 85 return needed;
87} 86}
@@ -102,7 +101,7 @@ GNUNET_STRINGS_buffer_fill (char *buffer, size_t size, unsigned int count,
102 */ 101 */
103unsigned int 102unsigned int
104GNUNET_STRINGS_buffer_tokenize (const char *buffer, size_t size, 103GNUNET_STRINGS_buffer_tokenize (const char *buffer, size_t size,
105 unsigned int count, ...) 104 unsigned int count, ...)
106{ 105{
107 unsigned int start; 106 unsigned int start;
108 unsigned int needed; 107 unsigned int needed;
@@ -112,21 +111,21 @@ GNUNET_STRINGS_buffer_tokenize (const char *buffer, size_t size,
112 needed = 0; 111 needed = 0;
113 va_start (ap, count); 112 va_start (ap, count);
114 while (count > 0) 113 while (count > 0)
114 {
115 r = va_arg (ap, const char **);
116
117 start = needed;
118 while ((needed < size) && (buffer[needed] != '\0'))
119 needed++;
120 if (needed == size)
115 { 121 {
116 r = va_arg (ap, const char **); 122 va_end (ap);
117 123 return 0; /* error */
118 start = needed;
119 while ((needed < size) && (buffer[needed] != '\0'))
120 needed++;
121 if (needed == size)
122 {
123 va_end (ap);
124 return 0; /* error */
125 }
126 *r = &buffer[start];
127 needed++; /* skip 0-termination */
128 count--;
129 } 124 }
125 *r = &buffer[start];
126 needed++; /* skip 0-termination */
127 count--;
128 }
130 va_end (ap); 129 va_end (ap);
131 return needed; 130 return needed;
132} 131}
@@ -145,25 +144,25 @@ GNUNET_STRINGS_byte_size_fancy (unsigned long long size)
145 char *ret; 144 char *ret;
146 145
147 if (size > 5 * 1024) 146 if (size > 5 * 1024)
147 {
148 size = size / 1024;
149 unit = "KiB";
150 if (size > 5 * 1024)
148 { 151 {
149 size = size / 1024; 152 size = size / 1024;
150 unit = "KiB"; 153 unit = "MiB";
151 if (size > 5 * 1024) 154 if (size > 5 * 1024)
152 { 155 {
153 size = size / 1024; 156 size = size / 1024;
154 unit = "MiB"; 157 unit = "GiB";
155 if (size > 5 * 1024) 158 if (size > 5 * 1024)
156 { 159 {
157 size = size / 1024; 160 size = size / 1024;
158 unit = "GiB"; 161 unit = "TiB";
159 if (size > 5 * 1024) 162 }
160 { 163 }
161 size = size / 1024;
162 unit = "TiB";
163 }
164 }
165 }
166 } 164 }
165 }
167 ret = GNUNET_malloc (32); 166 ret = GNUNET_malloc (32);
168 GNUNET_snprintf (ret, 32, "%llu %s", size, unit); 167 GNUNET_snprintf (ret, 32, "%llu %s", size, unit);
169 return ret; 168 return ret;
@@ -179,26 +178,42 @@ GNUNET_STRINGS_byte_size_fancy (unsigned long long size)
179 */ 178 */
180int 179int
181GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size, 180GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size,
182 unsigned long long *size) 181 unsigned long long *size)
183{ 182{
184 struct { 183 struct
185 const char *name; 184 {
185 const char *name;
186 unsigned long long value; 186 unsigned long long value;
187 } table[] = { 187 } table[] =
188 { "B", 1 }, 188 {
189 { "KiB", 1024 }, 189 {
190 { "kB", 1000 }, 190 "B", 1},
191 { "MiB", 1024 * 1024 }, 191 {
192 { "MB", 1000 * 1000 }, 192 "KiB", 1024},
193 { "GiB", 1024 * 1024 * 1024 }, 193 {
194 { "GB", 1000 * 1000 * 1000 }, 194 "kB", 1000},
195 { "TiB", 1024LL * 1024LL * 1024LL * 1024LL }, 195 {
196 { "TB", 1000LL * 1000LL * 1000LL * 1024LL }, 196 "MiB", 1024 * 1024},
197 { "PiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL }, 197 {
198 { "PB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL}, 198 "MB", 1000 * 1000},
199 { "EiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL}, 199 {
200 { "EB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL * 1000LL }, 200 "GiB", 1024 * 1024 * 1024},
201 { NULL, 0 } 201 {
202 "GB", 1000 * 1000 * 1000},
203 {
204 "TiB", 1024LL * 1024LL * 1024LL * 1024LL},
205 {
206 "TB", 1000LL * 1000LL * 1000LL * 1024LL},
207 {
208 "PiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL},
209 {
210 "PB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL},
211 {
212 "EiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL},
213 {
214 "EB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL * 1000LL},
215 {
216 NULL, 0}
202 }; 217 };
203 unsigned long long ret; 218 unsigned long long ret;
204 char *in; 219 char *in;
@@ -211,9 +226,8 @@ GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size,
211 in = GNUNET_strdup (fancy_size); 226 in = GNUNET_strdup (fancy_size);
212 for (tok = strtok (in, " "); tok != NULL; tok = strtok (NULL, " ")) 227 for (tok = strtok (in, " "); tok != NULL; tok = strtok (NULL, " "))
213 { 228 {
214 i=0; 229 i = 0;
215 while ( (table[i].name != NULL) && 230 while ((table[i].name != NULL) && (0 != strcasecmp (table[i].name, tok)))
216 (0 != strcasecmp (table[i].name, tok) ) )
217 i++; 231 i++;
218 if (table[i].name != NULL) 232 if (table[i].name != NULL)
219 last *= table[i].value; 233 last *= table[i].value;
@@ -222,8 +236,8 @@ GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size,
222 ret += last; 236 ret += last;
223 last = 0; 237 last = 0;
224 if (1 != sscanf (tok, "%llu", &last)) 238 if (1 != sscanf (tok, "%llu", &last))
225 return GNUNET_SYSERR; /* expected number */ 239 return GNUNET_SYSERR; /* expected number */
226 } 240 }
227 } 241 }
228 ret += last; 242 ret += last;
229 *size = ret; 243 *size = ret;
@@ -241,43 +255,54 @@ GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size,
241 */ 255 */
242int 256int
243GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_size, 257GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_size,
244 struct GNUNET_TIME_Relative *rtime) 258 struct GNUNET_TIME_Relative *rtime)
245{ 259{
246 struct { 260 struct
247 const char *name; 261 {
262 const char *name;
248 unsigned long long value; 263 unsigned long long value;
249 } table[] = { 264 } table[] =
250 { "ms", 1 }, 265 {
251 { "s", 1000 }, 266 {
252 { "\"", 1000 }, 267 "ms", 1},
253 { "min", 60 * 1000 }, 268 {
254 { "minutes", 60 * 1000 }, 269 "s", 1000},
255 { "'", 60 * 1000 }, 270 {
256 { "h", 60 * 60 * 1000 }, 271 "\"", 1000},
257 { "d", 24 * 60 * 60 * 1000 }, 272 {
258 { "a", 31557600 /* year */ }, 273 "min", 60 * 1000},
259 { NULL, 0 } 274 {
275 "minutes", 60 * 1000},
276 {
277 "'", 60 * 1000},
278 {
279 "h", 60 * 60 * 1000},
280 {
281 "d", 24 * 60 * 60 * 1000},
282 {
283 "a", 31557600 /* year */ },
284 {
285 NULL, 0}
260 }; 286 };
261 unsigned long long ret; 287 unsigned long long ret;
262 char *in; 288 char *in;
263 const char *tok; 289 const char *tok;
264 unsigned long long last; 290 unsigned long long last;
265 unsigned int i; 291 unsigned int i;
266 292
267 if ((0 == strcasecmp (fancy_size, "infinity")) || 293 if ((0 == strcasecmp (fancy_size, "infinity")) ||
268 (0 == strcasecmp (fancy_size, "forever"))) 294 (0 == strcasecmp (fancy_size, "forever")))
269 { 295 {
270 *rtime = GNUNET_TIME_UNIT_FOREVER_REL; 296 *rtime = GNUNET_TIME_UNIT_FOREVER_REL;
271 return GNUNET_OK; 297 return GNUNET_OK;
272 } 298 }
273 ret = 0; 299 ret = 0;
274 last = 0; 300 last = 0;
275 in = GNUNET_strdup (fancy_size); 301 in = GNUNET_strdup (fancy_size);
276 for (tok = strtok (in, " "); tok != NULL; tok = strtok (NULL, " ")) 302 for (tok = strtok (in, " "); tok != NULL; tok = strtok (NULL, " "))
277 { 303 {
278 i=0; 304 i = 0;
279 while ( (table[i].name != NULL) && 305 while ((table[i].name != NULL) && (0 != strcasecmp (table[i].name, tok)))
280 (0 != strcasecmp (table[i].name, tok) ) )
281 i++; 306 i++;
282 if (table[i].name != NULL) 307 if (table[i].name != NULL)
283 last *= table[i].value; 308 last *= table[i].value;
@@ -286,8 +311,8 @@ GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_size,
286 ret += last; 311 ret += last;
287 last = 0; 312 last = 0;
288 if (1 != sscanf (tok, "%llu", &last)) 313 if (1 != sscanf (tok, "%llu", &last))
289 return GNUNET_SYSERR; /* expected number */ 314 return GNUNET_SYSERR; /* expected number */
290 } 315 }
291 } 316 }
292 ret += last; 317 ret += last;
293 rtime->rel_value = (uint64_t) ret; 318 rtime->rel_value = (uint64_t) ret;
@@ -317,35 +342,35 @@ GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset)
317 342
318 cd = iconv_open ("UTF-8", charset); 343 cd = iconv_open ("UTF-8", charset);
319 if (cd == (iconv_t) - 1) 344 if (cd == (iconv_t) - 1)
320 { 345 {
321 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "iconv_open"); 346 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "iconv_open");
322 LOG (GNUNET_ERROR_TYPE_WARNING, 347 LOG (GNUNET_ERROR_TYPE_WARNING, _("Character set requested was `%s'\n"),
323 _("Character set requested was `%s'\n"), charset); 348 charset);
324 ret = GNUNET_malloc (len + 1); 349 ret = GNUNET_malloc (len + 1);
325 memcpy (ret, input, len); 350 memcpy (ret, input, len);
326 ret[len] = '\0'; 351 ret[len] = '\0';
327 return ret; 352 return ret;
328 } 353 }
329 tmpSize = 3 * len + 4; 354 tmpSize = 3 * len + 4;
330 tmp = GNUNET_malloc (tmpSize); 355 tmp = GNUNET_malloc (tmpSize);
331 itmp = tmp; 356 itmp = tmp;
332 finSize = tmpSize; 357 finSize = tmpSize;
333 if (iconv (cd, 358 if (iconv (cd,
334#if FREEBSD || DARWIN || WINDOWS 359#if FREEBSD || DARWIN || WINDOWS
335 (const char **) &input, 360 (const char **) &input,
336#else 361#else
337 (char **) &input, 362 (char **) &input,
338#endif 363#endif
339 &len, &itmp, &finSize) == SIZE_MAX) 364 &len, &itmp, &finSize) == SIZE_MAX)
340 { 365 {
341 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "iconv"); 366 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "iconv");
342 iconv_close (cd); 367 iconv_close (cd);
343 GNUNET_free (tmp); 368 GNUNET_free (tmp);
344 ret = GNUNET_malloc (len + 1); 369 ret = GNUNET_malloc (len + 1);
345 memcpy (ret, input, len); 370 memcpy (ret, input, len);
346 ret[len] = '\0'; 371 ret[len] = '\0';
347 return ret; 372 return ret;
348 } 373 }
349 ret = GNUNET_malloc (tmpSize - finSize + 1); 374 ret = GNUNET_malloc (tmpSize - finSize + 1);
350 memcpy (ret, tmp, tmpSize - finSize); 375 memcpy (ret, tmp, tmpSize - finSize);
351 ret[tmpSize - finSize] = '\0'; 376 ret[tmpSize - finSize] = '\0';
@@ -392,89 +417,88 @@ GNUNET_STRINGS_filename_expand (const char *fil)
392 /* absolute path, just copy */ 417 /* absolute path, just copy */
393 return GNUNET_strdup (fil); 418 return GNUNET_strdup (fil);
394 if (fil[0] == '~') 419 if (fil[0] == '~')
420 {
421 fm = getenv ("HOME");
422 if (fm == NULL)
395 { 423 {
396 fm = getenv ("HOME"); 424 LOG (GNUNET_ERROR_TYPE_WARNING,
397 if (fm == NULL) 425 _("Failed to expand `$HOME': environment variable `HOME' not set"));
398 { 426 return NULL;
399 LOG (GNUNET_ERROR_TYPE_WARNING,
400 _
401 ("Failed to expand `$HOME': environment variable `HOME' not set"));
402 return NULL;
403 }
404 fm = GNUNET_strdup (fm);
405 /* do not copy '~' */
406 fil_ptr = fil + 1;
407
408 /* skip over dir seperator to be consistent */
409 if (fil_ptr[0] == DIR_SEPARATOR)
410 fil_ptr++;
411 } 427 }
428 fm = GNUNET_strdup (fm);
429 /* do not copy '~' */
430 fil_ptr = fil + 1;
431
432 /* skip over dir seperator to be consistent */
433 if (fil_ptr[0] == DIR_SEPARATOR)
434 fil_ptr++;
435 }
412 else 436 else
437 {
438 /* relative path */
439 fil_ptr = fil;
440 len = 512;
441 fm = NULL;
442 while (1)
413 { 443 {
414 /* relative path */ 444 buffer = GNUNET_malloc (len);
415 fil_ptr = fil; 445 if (getcwd (buffer, len) != NULL)
416 len = 512; 446 {
417 fm = NULL; 447 fm = buffer;
418 while (1) 448 break;
419 { 449 }
420 buffer = GNUNET_malloc (len); 450 if ((errno == ERANGE) && (len < 1024 * 1024 * 4))
421 if (getcwd (buffer, len) != NULL) 451 {
422 { 452 len *= 2;
423 fm = buffer; 453 GNUNET_free (buffer);
424 break; 454 continue;
425 } 455 }
426 if ((errno == ERANGE) && (len < 1024 * 1024 * 4)) 456 GNUNET_free (buffer);
427 { 457 break;
428 len *= 2; 458 }
429 GNUNET_free (buffer); 459 if (fm == NULL)
430 continue; 460 {
431 } 461 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "getcwd");
432 GNUNET_free (buffer); 462 buffer = getenv ("PWD"); /* alternative */
433 break; 463 if (buffer != NULL)
434 } 464 fm = GNUNET_strdup (buffer);
435 if (fm == NULL)
436 {
437 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "getcwd");
438 buffer = getenv ("PWD"); /* alternative */
439 if (buffer != NULL)
440 fm = GNUNET_strdup (buffer);
441 }
442 if (fm == NULL)
443 fm = GNUNET_strdup ("./"); /* give up */
444 } 465 }
466 if (fm == NULL)
467 fm = GNUNET_strdup ("./"); /* give up */
468 }
445 n = strlen (fm) + 1 + strlen (fil_ptr) + 1; 469 n = strlen (fm) + 1 + strlen (fil_ptr) + 1;
446 buffer = GNUNET_malloc (n); 470 buffer = GNUNET_malloc (n);
447 GNUNET_snprintf (buffer, n, "%s%s%s", fm, 471 GNUNET_snprintf (buffer, n, "%s%s%s", fm,
448 (fm[strlen (fm) - 1] == 472 (fm[strlen (fm) - 1] ==
449 DIR_SEPARATOR) ? "" : DIR_SEPARATOR_STR, fil_ptr); 473 DIR_SEPARATOR) ? "" : DIR_SEPARATOR_STR, fil_ptr);
450 GNUNET_free (fm); 474 GNUNET_free (fm);
451 return buffer; 475 return buffer;
452#else 476#else
453 fn = GNUNET_malloc (MAX_PATH + 1); 477 fn = GNUNET_malloc (MAX_PATH + 1);
454 478
455 if ((lRet = plibc_conv_to_win_path (fil, fn)) != ERROR_SUCCESS) 479 if ((lRet = plibc_conv_to_win_path (fil, fn)) != ERROR_SUCCESS)
456 { 480 {
457 SetErrnoFromWinError (lRet); 481 SetErrnoFromWinError (lRet);
458 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "plibc_conv_to_win_path"); 482 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "plibc_conv_to_win_path");
459 return NULL; 483 return NULL;
460 } 484 }
461 /* is the path relative? */ 485 /* is the path relative? */
462 if ((strncmp (fn + 1, ":\\", 2) != 0) && (strncmp (fn, "\\\\", 2) != 0)) 486 if ((strncmp (fn + 1, ":\\", 2) != 0) && (strncmp (fn, "\\\\", 2) != 0))
487 {
488 char szCurDir[MAX_PATH + 1];
489
490 lRet = GetCurrentDirectory (MAX_PATH + 1, szCurDir);
491 if (lRet + strlen (fn) + 1 > (MAX_PATH + 1))
463 { 492 {
464 char szCurDir[MAX_PATH + 1]; 493 SetErrnoFromWinError (ERROR_BUFFER_OVERFLOW);
465 494 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "GetCurrentDirectory");
466 lRet = GetCurrentDirectory (MAX_PATH + 1, szCurDir); 495 return NULL;
467 if (lRet + strlen (fn) + 1 > (MAX_PATH + 1))
468 {
469 SetErrnoFromWinError (ERROR_BUFFER_OVERFLOW);
470 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "GetCurrentDirectory");
471 return NULL;
472 }
473 buffer = GNUNET_malloc (MAX_PATH + 1);
474 GNUNET_snprintf (buffer, MAX_PATH + 1, "%s\\%s", szCurDir, fn);
475 GNUNET_free (fn);
476 fn = buffer;
477 } 496 }
497 buffer = GNUNET_malloc (MAX_PATH + 1);
498 GNUNET_snprintf (buffer, MAX_PATH + 1, "%s\\%s", szCurDir, fn);
499 GNUNET_free (fn);
500 fn = buffer;
501 }
478 502
479 return fn; 503 return fn;
480#endif 504#endif
@@ -497,25 +521,25 @@ GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta)
497 if (delta.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value) 521 if (delta.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
498 return GNUNET_strdup (_("eternity")); 522 return GNUNET_strdup (_("eternity"));
499 if (dval > 5 * 1000) 523 if (dval > 5 * 1000)
524 {
525 dval = dval / 1000;
526 unit = _( /* time unit */ "s");
527 if (dval > 5 * 60)
500 { 528 {
501 dval = dval / 1000; 529 dval = dval / 60;
502 unit = _( /* time unit */ "s"); 530 unit = _( /* time unit */ "m");
503 if (dval > 5 * 60) 531 if (dval > 5 * 60)
504 { 532 {
505 dval = dval / 60; 533 dval = dval / 60;
506 unit = _( /* time unit */ "m"); 534 unit = _( /* time unit */ "h");
507 if (dval > 5 * 60) 535 if (dval > 5 * 24)
508 { 536 {
509 dval = dval / 60; 537 dval = dval / 24;
510 unit = _( /* time unit */ "h"); 538 unit = _( /* time unit */ " days");
511 if (dval > 5 * 24) 539 }
512 { 540 }
513 dval = dval / 24;
514 unit = _( /* time unit */ " days");
515 }
516 }
517 }
518 } 541 }
542 }
519 GNUNET_asprintf (&ret, "%llu %s", dval, unit); 543 GNUNET_asprintf (&ret, "%llu %s", dval, unit);
520 return ret; 544 return ret;
521} 545}
diff --git a/src/util/test_bio.c b/src/util/test_bio.c
index e72c95295..df4becdd1 100644
--- a/src/util/test_bio.c
+++ b/src/util/test_bio.c
@@ -57,17 +57,16 @@ test_normal_rw ()
57 GNUNET_assert (NULL != fileR); 57 GNUNET_assert (NULL != fileR);
58 readResultString = NULL; 58 readResultString = NULL;
59 GNUNET_assert (GNUNET_OK == 59 GNUNET_assert (GNUNET_OK ==
60 GNUNET_BIO_read_string (fileR, "Read string error", 60 GNUNET_BIO_read_string (fileR, "Read string error",
61 &readResultString, 200)); 61 &readResultString, 200));
62 GNUNET_assert (NULL != readResultString); 62 GNUNET_assert (NULL != readResultString);
63 GNUNET_assert (0 == strcmp (TESTSTRING, readResultString)); 63 GNUNET_assert (0 == strcmp (TESTSTRING, readResultString));
64 GNUNET_free (readResultString); 64 GNUNET_free (readResultString);
65 GNUNET_assert (GNUNET_OK == 65 GNUNET_assert (GNUNET_OK ==
66 GNUNET_BIO_read_meta_data (fileR, "Read meta error", 66 GNUNET_BIO_read_meta_data (fileR, "Read meta error",
67 &metaDataR)); 67 &metaDataR));
68 GNUNET_assert (GNUNET_YES == 68 GNUNET_assert (GNUNET_YES ==
69 GNUNET_CONTAINER_meta_data_test_equal (metaDataR, 69 GNUNET_CONTAINER_meta_data_test_equal (metaDataR, metaDataW));
70 metaDataW));
71 GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_int64 (fileR, &testNum)); 70 GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_int64 (fileR, &testNum));
72 GNUNET_BIO_read_close (fileR, &msg); 71 GNUNET_BIO_read_close (fileR, &msg);
73 GNUNET_CONTAINER_meta_data_destroy (metaDataW); 72 GNUNET_CONTAINER_meta_data_destroy (metaDataW);
@@ -94,8 +93,8 @@ test_nullstring_rw ()
94 fileR = GNUNET_BIO_read_open (fileName); 93 fileR = GNUNET_BIO_read_open (fileName);
95 GNUNET_assert (NULL != fileR); 94 GNUNET_assert (NULL != fileR);
96 GNUNET_assert (GNUNET_OK == 95 GNUNET_assert (GNUNET_OK ==
97 GNUNET_BIO_read_string (fileR, "Read string error", 96 GNUNET_BIO_read_string (fileR, "Read string error",
98 &readResultString, 200)); 97 &readResultString, 200));
99 GNUNET_assert (NULL == readResultString); 98 GNUNET_assert (NULL == readResultString);
100 GNUNET_BIO_read_close (fileR, &msg); 99 GNUNET_BIO_read_close (fileR, &msg);
101 GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName)); 100 GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName));
@@ -122,8 +121,8 @@ test_emptystring_rw ()
122 GNUNET_assert (NULL != fileR); 121 GNUNET_assert (NULL != fileR);
123 readResultString = NULL; 122 readResultString = NULL;
124 GNUNET_assert (GNUNET_OK == 123 GNUNET_assert (GNUNET_OK ==
125 GNUNET_BIO_read_string (fileR, "Read string error", 124 GNUNET_BIO_read_string (fileR, "Read string error",
126 &readResultString, 200)); 125 &readResultString, 200));
127 GNUNET_free (readResultString); 126 GNUNET_free (readResultString);
128 GNUNET_BIO_read_close (fileR, &msg); 127 GNUNET_BIO_read_close (fileR, &msg);
129 GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName)); 128 GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName));
@@ -149,8 +148,8 @@ test_bigstring_rw ()
149 GNUNET_assert (NULL != fileR); 148 GNUNET_assert (NULL != fileR);
150 readResultString = NULL; 149 readResultString = NULL;
151 GNUNET_assert (GNUNET_SYSERR == 150 GNUNET_assert (GNUNET_SYSERR ==
152 GNUNET_BIO_read_string (fileR, "Read string error", 151 GNUNET_BIO_read_string (fileR, "Read string error",
153 &readResultString, 1)); 152 &readResultString, 1));
154 GNUNET_assert (NULL == readResultString); 153 GNUNET_assert (NULL == readResultString);
155 msg = NULL; 154 msg = NULL;
156 GNUNET_BIO_read_close (fileR, &msg); 155 GNUNET_BIO_read_close (fileR, &msg);
@@ -182,8 +181,8 @@ test_bigmeta_rw ()
182 GNUNET_assert (NULL != fileR); 181 GNUNET_assert (NULL != fileR);
183 metaDataR = NULL; 182 metaDataR = NULL;
184 GNUNET_assert (GNUNET_SYSERR == 183 GNUNET_assert (GNUNET_SYSERR ==
185 GNUNET_BIO_read_meta_data (fileR, "Read meta error", 184 GNUNET_BIO_read_meta_data (fileR, "Read meta error",
186 &metaDataR)); 185 &metaDataR));
187 msg = NULL; 186 msg = NULL;
188 GNUNET_BIO_read_close (fileR, &msg); 187 GNUNET_BIO_read_close (fileR, &msg);
189 GNUNET_free (msg); 188 GNUNET_free (msg);
@@ -204,8 +203,8 @@ test_directory_r ()
204 fileR = GNUNET_BIO_read_open ("/dev"); 203 fileR = GNUNET_BIO_read_open ("/dev");
205 GNUNET_assert (NULL != fileR); 204 GNUNET_assert (NULL != fileR);
206 GNUNET_assert (GNUNET_SYSERR == 205 GNUNET_assert (GNUNET_SYSERR ==
207 GNUNET_BIO_read (fileR, "Read error", readResult, 206 GNUNET_BIO_read (fileR, "Read error", readResult,
208 sizeof (readResult))); 207 sizeof (readResult)));
209 msg = NULL; 208 msg = NULL;
210 GNUNET_BIO_read_close (fileR, &msg); 209 GNUNET_BIO_read_close (fileR, &msg);
211 GNUNET_free (msg); 210 GNUNET_free (msg);
@@ -268,18 +267,18 @@ test_fullfile_rw ()
268 fileR = GNUNET_BIO_read_open ("/dev/null"); 267 fileR = GNUNET_BIO_read_open ("/dev/null");
269 GNUNET_assert (NULL != fileR); 268 GNUNET_assert (NULL != fileR);
270 GNUNET_assert (GNUNET_SYSERR == 269 GNUNET_assert (GNUNET_SYSERR ==
271 GNUNET_BIO_read (fileR, "Read error", readResult, 270 GNUNET_BIO_read (fileR, "Read error", readResult,
272 sizeof (readResult))); 271 sizeof (readResult)));
273 readResultString = NULL; 272 readResultString = NULL;
274 GNUNET_assert (GNUNET_SYSERR == 273 GNUNET_assert (GNUNET_SYSERR ==
275 GNUNET_BIO_read_string (fileR, "Read string error", 274 GNUNET_BIO_read_string (fileR, "Read string error",
276 &readResultString, 200)); 275 &readResultString, 200));
277 GNUNET_assert (NULL == readResultString); 276 GNUNET_assert (NULL == readResultString);
278 GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_int64 (fileR, &testNum)); 277 GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_int64 (fileR, &testNum));
279 metaDataR = NULL; 278 metaDataR = NULL;
280 GNUNET_assert (GNUNET_SYSERR == 279 GNUNET_assert (GNUNET_SYSERR ==
281 GNUNET_BIO_read_meta_data (fileR, "Read meta error", 280 GNUNET_BIO_read_meta_data (fileR, "Read meta error",
282 &metaDataR)); 281 &metaDataR));
283 msg = NULL; 282 msg = NULL;
284 GNUNET_BIO_read_close (fileR, &msg); 283 GNUNET_BIO_read_close (fileR, &msg);
285 GNUNET_free (msg); 284 GNUNET_free (msg);
@@ -306,8 +305,8 @@ test_fakestring_rw ()
306 fileR = GNUNET_BIO_read_open (fileName); 305 fileR = GNUNET_BIO_read_open (fileName);
307 GNUNET_assert (NULL != fileR); 306 GNUNET_assert (NULL != fileR);
308 GNUNET_assert (GNUNET_SYSERR == 307 GNUNET_assert (GNUNET_SYSERR ==
309 GNUNET_BIO_read_string (fileR, "Read string error", 308 GNUNET_BIO_read_string (fileR, "Read string error",
310 &readResult, 200)); 309 &readResult, 200));
311 msg = NULL; 310 msg = NULL;
312 GNUNET_BIO_read_close (fileR, &msg); 311 GNUNET_BIO_read_close (fileR, &msg);
313 GNUNET_free (msg); 312 GNUNET_free (msg);
@@ -335,8 +334,8 @@ test_fakemeta_rw ()
335 GNUNET_assert (NULL != fileR); 334 GNUNET_assert (NULL != fileR);
336 metaDataR = NULL; 335 metaDataR = NULL;
337 GNUNET_assert (GNUNET_SYSERR == 336 GNUNET_assert (GNUNET_SYSERR ==
338 GNUNET_BIO_read_meta_data (fileR, "Read meta error", 337 GNUNET_BIO_read_meta_data (fileR, "Read meta error",
339 &metaDataR)); 338 &metaDataR));
340 GNUNET_assert (NULL == metaDataR); 339 GNUNET_assert (NULL == metaDataR);
341 msg = NULL; 340 msg = NULL;
342 GNUNET_BIO_read_close (fileR, &msg); 341 GNUNET_BIO_read_close (fileR, &msg);
@@ -365,8 +364,8 @@ test_fakebigmeta_rw ()
365 GNUNET_assert (NULL != fileR); 364 GNUNET_assert (NULL != fileR);
366 metaDataR = NULL; 365 metaDataR = NULL;
367 GNUNET_assert (GNUNET_SYSERR == 366 GNUNET_assert (GNUNET_SYSERR ==
368 GNUNET_BIO_read_meta_data (fileR, "Read meta error", 367 GNUNET_BIO_read_meta_data (fileR, "Read meta error",
369 &metaDataR)); 368 &metaDataR));
370 msg = NULL; 369 msg = NULL;
371 GNUNET_BIO_read_close (fileR, &msg); 370 GNUNET_BIO_read_close (fileR, &msg);
372 GNUNET_free (msg); 371 GNUNET_free (msg);
diff --git a/src/util/test_client.c b/src/util/test_client.c
index ad88874f2..bb7d5008a 100644
--- a/src/util/test_client.c
+++ b/src/util/test_client.c
@@ -71,25 +71,24 @@ copy_msg (void *cls, size_t size, void *buf)
71 */ 71 */
72static void 72static void
73echo_cb (void *cls, struct GNUNET_SERVER_Client *client, 73echo_cb (void *cls, struct GNUNET_SERVER_Client *client,
74 const struct GNUNET_MessageHeader *message) 74 const struct GNUNET_MessageHeader *message)
75{ 75{
76 struct CopyContext *cc; 76 struct CopyContext *cc;
77 struct GNUNET_MessageHeader *cpy; 77 struct GNUNET_MessageHeader *cpy;
78 78
79 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 79 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
80 "Receiving message from client, bouncing back\n"); 80 "Receiving message from client, bouncing back\n");
81 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == 81 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size));
82 ntohs (message->size));
83 cc = GNUNET_malloc (sizeof (struct CopyContext)); 82 cc = GNUNET_malloc (sizeof (struct CopyContext));
84 cc->client = client; 83 cc->client = client;
85 cpy = GNUNET_malloc (ntohs (message->size)); 84 cpy = GNUNET_malloc (ntohs (message->size));
86 memcpy (cpy, message, ntohs (message->size)); 85 memcpy (cpy, message, ntohs (message->size));
87 cc->cpy = cpy; 86 cc->cpy = cpy;
88 GNUNET_assert (NULL != 87 GNUNET_assert (NULL !=
89 GNUNET_SERVER_notify_transmit_ready (client, 88 GNUNET_SERVER_notify_transmit_ready (client,
90 ntohs (message->size), 89 ntohs (message->size),
91 GNUNET_TIME_UNIT_SECONDS, 90 GNUNET_TIME_UNIT_SECONDS,
92 &copy_msg, cc)); 91 &copy_msg, cc));
93} 92}
94 93
95 94
@@ -105,13 +104,11 @@ recv_bounce (void *cls, const struct GNUNET_MessageHeader *got)
105 int *ok = cls; 104 int *ok = cls;
106 struct GNUNET_MessageHeader msg; 105 struct GNUNET_MessageHeader msg;
107 106
108 GNUNET_assert (got != NULL); /* timeout */ 107 GNUNET_assert (got != NULL); /* timeout */
109 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 108 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving bounce, checking content\n");
110 "Receiving bounce, checking content\n");
111 msg.type = htons (MY_TYPE); 109 msg.type = htons (MY_TYPE);
112 msg.size = htons (sizeof (struct GNUNET_MessageHeader)); 110 msg.size = htons (sizeof (struct GNUNET_MessageHeader));
113 GNUNET_assert (0 == 111 GNUNET_assert (0 == memcmp (got, &msg, sizeof (struct GNUNET_MessageHeader)));
114 memcmp (got, &msg, sizeof (struct GNUNET_MessageHeader)));
115 GNUNET_CLIENT_disconnect (client, GNUNET_YES); 112 GNUNET_CLIENT_disconnect (client, GNUNET_YES);
116 client = NULL; 113 client = NULL;
117 GNUNET_SERVER_destroy (server); 114 GNUNET_SERVER_destroy (server);
@@ -151,9 +148,9 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
151 sa.sin_family = AF_INET; 148 sa.sin_family = AF_INET;
152 sa.sin_port = htons (PORT); 149 sa.sin_port = htons (PORT);
153 server = 150 server =
154 GNUNET_SERVER_create (NULL, NULL, sap, slens, 151 GNUNET_SERVER_create (NULL, NULL, sap, slens,
155 GNUNET_TIME_relative_multiply 152 GNUNET_TIME_relative_multiply
156 (GNUNET_TIME_UNIT_MILLISECONDS, 10000), GNUNET_NO); 153 (GNUNET_TIME_UNIT_MILLISECONDS, 10000), GNUNET_NO);
157 GNUNET_assert (server != NULL); 154 GNUNET_assert (server != NULL);
158 handlers[0].callback_cls = cls; 155 handlers[0].callback_cls = cls;
159 handlers[1].callback_cls = cls; 156 handlers[1].callback_cls = cls;
@@ -161,15 +158,15 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
161 client = GNUNET_CLIENT_connect (MYNAME, cfg); 158 client = GNUNET_CLIENT_connect (MYNAME, cfg);
162 GNUNET_assert (client != NULL); 159 GNUNET_assert (client != NULL);
163 GNUNET_assert (NULL != 160 GNUNET_assert (NULL !=
164 GNUNET_CLIENT_notify_transmit_ready (client, 161 GNUNET_CLIENT_notify_transmit_ready (client,
165 sizeof (struct 162 sizeof (struct
166 GNUNET_MessageHeader), 163 GNUNET_MessageHeader),
167 GNUNET_TIME_UNIT_SECONDS, 164 GNUNET_TIME_UNIT_SECONDS,
168 GNUNET_NO, &make_msg, 165 GNUNET_NO, &make_msg,
169 NULL)); 166 NULL));
170 GNUNET_CLIENT_receive (client, &recv_bounce, cls, 167 GNUNET_CLIENT_receive (client, &recv_bounce, cls,
171 GNUNET_TIME_relative_multiply 168 GNUNET_TIME_relative_multiply
172 (GNUNET_TIME_UNIT_MILLISECONDS, 10000)); 169 (GNUNET_TIME_UNIT_MILLISECONDS, 10000));
173} 170}
174 171
175 172
@@ -184,10 +181,9 @@ check ()
184 181
185 cfg = GNUNET_CONFIGURATION_create (); 182 cfg = GNUNET_CONFIGURATION_create ();
186 GNUNET_CONFIGURATION_set_value_number (cfg, MYNAME, "PORT", PORT); 183 GNUNET_CONFIGURATION_set_value_number (cfg, MYNAME, "PORT", PORT);
187 GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "HOSTNAME", 184 GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "HOSTNAME", "localhost");
188 "localhost");
189 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", 185 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
190 "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);
@@ -201,11 +197,11 @@ main (int argc, char *argv[])
201 197
202 GNUNET_log_setup ("test_client", 198 GNUNET_log_setup ("test_client",
203#if VERBOSE 199#if VERBOSE
204 "DEBUG", 200 "DEBUG",
205#else 201#else
206 "WARNING", 202 "WARNING",
207#endif 203#endif
208 NULL); 204 NULL);
209 ret += check (); 205 ret += check ();
210 206
211 return ret; 207 return ret;
diff --git a/src/util/test_common_allocation.c b/src/util/test_common_allocation.c
index 2fb1329b1..950f0cedb 100644
--- a/src/util/test_common_allocation.c
+++ b/src/util/test_common_allocation.c
@@ -36,21 +36,21 @@ check ()
36 unsigned int ui; 36 unsigned int ui;
37 37
38 /* GNUNET_malloc/GNUNET_free test */ 38 /* GNUNET_malloc/GNUNET_free test */
39 k = 352; /* random start value */ 39 k = 352; /* random start value */
40 for (i = 1; i < MAX_TESTVAL; i++) 40 for (i = 1; i < MAX_TESTVAL; i++)
41 { 41 {
42 ptrs[i] = GNUNET_malloc (i); 42 ptrs[i] = GNUNET_malloc (i);
43 for (j = 0; j < i; j++) 43 for (j = 0; j < i; j++)
44 ptrs[i][j] = k++; 44 ptrs[i][j] = k++;
45 } 45 }
46 46
47 for (i = MAX_TESTVAL - 1; i >= 1; i--) 47 for (i = MAX_TESTVAL - 1; i >= 1; i--)
48 { 48 {
49 for (j = i - 1; j >= 0; j--) 49 for (j = i - 1; j >= 0; j--)
50 if (ptrs[i][j] != (char) --k) 50 if (ptrs[i][j] != (char) --k)
51 return 1; 51 return 1;
52 GNUNET_free (ptrs[i]); 52 GNUNET_free (ptrs[i]);
53 } 53 }
54 54
55 /* GNUNET_free_non_null test */ 55 /* GNUNET_free_non_null test */
56 GNUNET_free_non_null (NULL); 56 GNUNET_free_non_null (NULL);
diff --git a/src/util/test_common_logging.c b/src/util/test_common_logging.c
index a940d3c07..cf291161e 100644
--- a/src/util/test_common_logging.c
+++ b/src/util/test_common_logging.c
@@ -28,7 +28,7 @@
28 28
29static void 29static void
30my_log (void *ctx, enum GNUNET_ErrorType kind, const char *component, 30my_log (void *ctx, enum GNUNET_ErrorType kind, const char *component,
31 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
@@ -44,9 +44,7 @@ main (int argc, char *argv[])
44 unsigned int logs = 0; 44 unsigned int logs = 0;
45 45
46 if (0 != setenv ("GNUNET_FORCE_LOG", "", 1)) 46 if (0 != setenv ("GNUNET_FORCE_LOG", "", 1))
47 fprintf (stderr, 47 fprintf (stderr, "Failed to setenv: %s\n", strerror (errno));
48 "Failed to setenv: %s\n",
49 strerror (errno));
50 GNUNET_log_setup ("test-common-logging", "DEBUG", "/dev/null"); 48 GNUNET_log_setup ("test-common-logging", "DEBUG", "/dev/null");
51 GNUNET_logger_add (&my_log, &logs); 49 GNUNET_logger_add (&my_log, &logs);
52 GNUNET_logger_add (&my_log, &logs); 50 GNUNET_logger_add (&my_log, &logs);
@@ -61,26 +59,23 @@ main (int argc, char *argv[])
61 /* the last 6 calls should be merged (repated bulk messages!) */ 59 /* the last 6 calls should be merged (repated bulk messages!) */
62 GNUNET_logger_remove (&my_log, &logs); 60 GNUNET_logger_remove (&my_log, &logs);
63 if (logs != 4) 61 if (logs != 4)
64 { 62 {
65 fprintf (stdout, "Expected 4 log calls, got %u\n", logs); 63 fprintf (stdout, "Expected 4 log calls, got %u\n", logs);
66 failureCount++; 64 failureCount++;
67 } 65 }
68 GNUNET_break (0 == 66 GNUNET_break (0 ==
69 strcmp (_("ERROR"), 67 strcmp (_("ERROR"),
70 GNUNET_error_type_to_string 68 GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_ERROR)));
71 (GNUNET_ERROR_TYPE_ERROR)));
72 GNUNET_break (0 == 69 GNUNET_break (0 ==
73 strcmp (_("WARNING"), 70 strcmp (_("WARNING"),
74 GNUNET_error_type_to_string 71 GNUNET_error_type_to_string
75 (GNUNET_ERROR_TYPE_WARNING))); 72 (GNUNET_ERROR_TYPE_WARNING)));
76 GNUNET_break (0 == 73 GNUNET_break (0 ==
77 strcmp (_("INFO"), 74 strcmp (_("INFO"),
78 GNUNET_error_type_to_string 75 GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_INFO)));
79 (GNUNET_ERROR_TYPE_INFO)));
80 GNUNET_break (0 == 76 GNUNET_break (0 ==
81 strcmp (_("DEBUG"), 77 strcmp (_("DEBUG"),
82 GNUNET_error_type_to_string 78 GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_DEBUG)));
83 (GNUNET_ERROR_TYPE_DEBUG)));
84 GNUNET_log_setup ("test_common_logging", "WARNING", "/dev/null"); 79 GNUNET_log_setup ("test_common_logging", "WARNING", "/dev/null");
85 logs = 0; 80 logs = 0;
86 GNUNET_logger_add (&my_log, &logs); 81 GNUNET_logger_add (&my_log, &logs);
@@ -88,17 +83,17 @@ main (int argc, char *argv[])
88 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Drop me...\n"); 83 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Drop me...\n");
89 GNUNET_logger_remove (&my_log, &logs); 84 GNUNET_logger_remove (&my_log, &logs);
90 if (logs != 1) 85 if (logs != 1)
91 { 86 {
92 fprintf (stdout, "Expected 1 log call, got %u\n", logs); 87 fprintf (stdout, "Expected 1 log call, got %u\n", logs);
93 failureCount++; 88 failureCount++;
94 } 89 }
95 90
96 if (failureCount != 0) 91 if (failureCount != 0)
97 { 92 {
98 fprintf (stdout, "%u TESTS FAILED!\n", failureCount); 93 fprintf (stdout, "%u TESTS FAILED!\n", failureCount);
99 return -1; 94 return -1;
100 } 95 }
101 return 0; 96 return 0;
102} /* end of main */ 97} /* end of main */
103 98
104/* end of test_common_logging.c */ 99/* end of test_common_logging.c */
diff --git a/src/util/test_common_logging_dummy.c b/src/util/test_common_logging_dummy.c
index d87f56d42..005b5caef 100644
--- a/src/util/test_common_logging_dummy.c
+++ b/src/util/test_common_logging_dummy.c
@@ -33,7 +33,7 @@
33 33
34static void 34static void
35my_log (void *ctx, enum GNUNET_ErrorType kind, const char *component, 35my_log (void *ctx, enum GNUNET_ErrorType kind, const char *component,
36 const char *date, const char *msg) 36 const char *date, const char *msg)
37{ 37{
38 if (strncmp ("test-common-logging-dummy", component, 25) != 0) 38 if (strncmp ("test-common-logging-dummy", component, 25) != 0)
39 return; 39 return;
@@ -87,6 +87,6 @@ main (int argc, char *argv[])
87 pr2 (GNUNET_ERROR_TYPE_INFO, "INFO"); 87 pr2 (GNUNET_ERROR_TYPE_INFO, "INFO");
88 pr2 (GNUNET_ERROR_TYPE_DEBUG, "DEBUG"); 88 pr2 (GNUNET_ERROR_TYPE_DEBUG, "DEBUG");
89 return 0; 89 return 0;
90} /* end of main */ 90} /* end of main */
91 91
92/* end of test_common_logging_dummy.c */ 92/* end of test_common_logging_dummy.c */
diff --git a/src/util/test_common_logging_runtime_loglevels.c b/src/util/test_common_logging_runtime_loglevels.c
index 6485e4e4a..5b89b7221 100644
--- a/src/util/test_common_logging_runtime_loglevels.c
+++ b/src/util/test_common_logging_runtime_loglevels.c
@@ -42,108 +42,110 @@ static struct GNUNET_DISK_PipeHandle *pipe_stdout;
42 42
43static GNUNET_SCHEDULER_TaskIdentifier die_task; 43static GNUNET_SCHEDULER_TaskIdentifier die_task;
44 44
45static void runone (); 45static void
46runone ();
46 47
47static void 48static void
48end_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 49end_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
49{ 50{
50 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending phase %d, ok is %d\n", phase, 51 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending phase %d, ok is %d\n", phase,
51 ok); 52 ok);
52 if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) 53 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
53 { 54 {
54 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 55 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
55 } 56 }
56 GNUNET_OS_process_wait (proc); 57 GNUNET_OS_process_wait (proc);
57 GNUNET_OS_process_close (proc); 58 GNUNET_OS_process_close (proc);
58 proc = NULL; 59 proc = NULL;
59 GNUNET_DISK_pipe_close (pipe_stdout); 60 GNUNET_DISK_pipe_close (pipe_stdout);
60 if (ok == 1) 61 if (ok == 1)
62 {
63 if (phase < 9)
61 { 64 {
62 if (phase < 9) 65 phase += 1;
63 { 66 runone ();
64 phase += 1;
65 runone ();
66 }
67 else
68 ok = 0;
69 } 67 }
68 else
69 ok = 0;
70 }
70 else 71 else
71 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "failing\n"); 72 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "failing\n");
72} 73}
73 74
74static char * 75static char *
75read_output_line (int phase_from1, int phase_to1, int phase_from2, 76read_output_line (int phase_from1, int phase_to1, int phase_from2,
76 int phase_to2, char c, char *expect_level, 77 int phase_to2, char c, char *expect_level,
77 long delay_morethan, long delay_lessthan, int phase, 78 long delay_morethan, long delay_lessthan, int phase, char *p,
78 char *p, int *len, long *delay, char level[8]) 79 int *len, long *delay, char level[8])
79{ 80{
80 char *r = p; 81 char *r = p;
81 char t[7]; 82 char t[7];
82 int i, j, stop = 0; 83 int i, j, stop = 0;
84
83 j = 0; 85 j = 0;
84 int stage = 0; 86 int stage = 0;
87
85 if (!(phase >= phase_from1 && phase <= phase_to1) && 88 if (!(phase >= phase_from1 && phase <= phase_to1) &&
86 !(phase >= phase_from2 && phase <= phase_to2)) 89 !(phase >= phase_from2 && phase <= phase_to2))
87 return p; 90 return p;
88#if 0 91#if 0
89 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 92 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
90 "Trying to match '%c%s \\d\\r\\n' on %s\n", c, expect_level, p); 93 "Trying to match '%c%s \\d\\r\\n' on %s\n", c, expect_level, p);
91#endif 94#endif
92 for (i = 0; i < *len && !stop; i++) 95 for (i = 0; i < *len && !stop; i++)
96 {
97 switch (stage)
93 { 98 {
94 switch (stage) 99 case 0: /* read first char */
95 { 100 if (r[i] != c)
96 case 0: /* read first char */ 101 {
97 if (r[i] != c) 102 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expected '%c', but got '%c'\n", c,
98 { 103 r[i]);
99 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 104 GNUNET_break (0);
100 "Expected '%c', but got '%c'\n", c, r[i]); 105 return NULL;
101 GNUNET_break (0); 106 }
102 return NULL; 107 stage += 1;
103 } 108 break;
104 stage += 1; 109 case 1: /* read at most 7 char-long error level string, finished by ' ' */
105 break; 110 if (r[i] == ' ')
106 case 1: /* read at most 7 char-long error level string, finished by ' ' */ 111 {
107 if (r[i] == ' ') 112 level[j] = '\0';
108 { 113 stage += 1;
109 level[j] = '\0'; 114 j = 0;
110 stage += 1; 115 }
111 j = 0; 116 else if (i == 8)
112 } 117 {
113 else if (i == 8) 118 GNUNET_break (0);
114 { 119 ok = 2;
115 GNUNET_break (0); 120 return NULL;
116 ok = 2; 121 }
117 return NULL; 122 else
118 } 123 level[j++] = r[i];
119 else 124 break;
120 level[j++] = r[i]; 125 case 2: /* read the delay, finished by '\n' */
121 break; 126 t[j++] = r[i];
122 case 2: /* read the delay, finished by '\n' */
123 t[j++] = r[i];
124#if WINDOWS 127#if WINDOWS
125 if (r[i] == '\r' && r[i + 1] == '\n') 128 if (r[i] == '\r' && r[i + 1] == '\n')
126 { 129 {
127 i += 1; 130 i += 1;
128 t[j - 1] = '\0'; 131 t[j - 1] = '\0';
129 *delay = strtol (t, NULL, 10); 132 *delay = strtol (t, NULL, 10);
130 stop = 1; 133 stop = 1;
131 } 134 }
132#else 135#else
133 if (r[i] == '\n') 136 if (r[i] == '\n')
134 { 137 {
135 t[j - 1] = '\0'; 138 t[j - 1] = '\0';
136 *delay = strtol (t, NULL, 10); 139 *delay = strtol (t, NULL, 10);
137 stop = 1; 140 stop = 1;
138 } 141 }
139#endif 142#endif
140 break; 143 break;
141 }
142 } 144 }
143 if (!stop || strcmp (expect_level, level) != 0 || *delay < 0 145 }
144 || *delay > 1000 146 if (!stop || strcmp (expect_level, level) != 0 || *delay < 0 || *delay > 1000
145 || (!((*delay < delay_lessthan) || !(*delay > delay_morethan)) 147 || (!((*delay < delay_lessthan) || !(*delay > delay_morethan)) && c != '1'
146 && c != '1' && c != '2')) 148 && c != '2'))
147 return NULL; 149 return NULL;
148 *len = *len - i; 150 *len = *len - i;
149 return &r[i]; 151 return &r[i];
@@ -162,20 +164,20 @@ read_call (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
162 long delays[8]; 164 long delays[8];
163 int rd; 165 int rd;
164 166
165 rd = 167 rd = GNUNET_DISK_file_read (stdout_read_handle, buf_ptr,
166 GNUNET_DISK_file_read (stdout_read_handle, buf_ptr, sizeof (buf) - bytes); 168 sizeof (buf) - bytes);
167 if (rd > 0) 169 if (rd > 0)
168 { 170 {
169 buf_ptr += rd; 171 buf_ptr += rd;
170 bytes += rd; 172 bytes += rd;
171#if VERBOSE 173#if VERBOSE
172 fprintf (stderr, "got %d bytes, reading more\n", rd); 174 fprintf (stderr, "got %d bytes, reading more\n", rd);
173#endif 175#endif
174 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 176 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
175 stdout_read_handle, &read_call, 177 stdout_read_handle, &read_call,
176 (void *) stdout_read_handle); 178 (void *) stdout_read_handle);
177 return; 179 return;
178 } 180 }
179 181
180#if VERBOSE 182#if VERBOSE
181 fprintf (stderr, "bytes is %d:%s\n", bytes, buf); 183 fprintf (stderr, "bytes is %d:%s\n", bytes, buf);
@@ -197,64 +199,65 @@ read_call (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
197 * | 9 * * * * 199 * | 9 * * * *
198 */ 200 */
199 char *p = buf; 201 char *p = buf;
202
200 if (bytes == 20 * 16 || 203 if (bytes == 20 * 16 ||
201 !(p = 204 !(p =
202 read_output_line (0, 3, 4, 9, 'L', "ERROR", -1, 1, phase, p, &bytes, 205 read_output_line (0, 3, 4, 9, 'L', "ERROR", -1, 1, phase, p, &bytes,
203 &delay, level)) 206 &delay, level)) ||
204 || !(p = 207 !(p =
205 read_output_line (0, 3, 4, 9, '1', "ERROR", 200, 400, phase, p, 208 read_output_line (0, 3, 4, 9, '1', "ERROR", 200, 400, phase, p, &bytes,
206 &bytes, &delays[0], level)) 209 &delays[0], level)) ||
207 || !(p = 210 !(p =
208 read_output_line (1, 3, 5, 9, 'L', "WARNING", -1, 1, phase, p, 211 read_output_line (1, 3, 5, 9, 'L', "WARNING", -1, 1, phase, p, &bytes,
209 &bytes, &delay, level)) 212 &delay, level)) ||
210 || !(p = 213 !(p =
211 read_output_line (0, 3, 4, 9, '1', "WARNING", 200, 400, phase, p, 214 read_output_line (0, 3, 4, 9, '1', "WARNING", 200, 400, phase, p,
212 &bytes, &delays[1], level)) 215 &bytes, &delays[1], level)) ||
213 || !(p = 216 !(p =
214 read_output_line (2, 3, 6, 7, 'L', "INFO", -1, 1, phase, p, &bytes, 217 read_output_line (2, 3, 6, 7, 'L', "INFO", -1, 1, phase, p, &bytes,
215 &delay, level)) 218 &delay, level)) ||
216 || !(p = 219 !(p =
217 read_output_line (0, 3, 4, 9, '1', "INFO", 200, 400, phase, p, 220 read_output_line (0, 3, 4, 9, '1', "INFO", 200, 400, phase, p, &bytes,
218 &bytes, &delays[2], level)) 221 &delays[2], level)) ||
219 || !(p = 222 !(p =
220 read_output_line (3, 3, 7, 7, 'L', "DEBUG", -1, 1, phase, p, 223 read_output_line (3, 3, 7, 7, 'L', "DEBUG", -1, 1, phase, p, &bytes,
221 &bytes, &delay, level)) 224 &delay, level)) ||
222 || !(p = 225 !(p =
223 read_output_line (0, 3, 4, 9, '1', "DEBUG", 200, 400, phase, p, 226 read_output_line (0, 3, 4, 9, '1', "DEBUG", 200, 400, phase, p, &bytes,
224 &bytes, &delays[3], level)) 227 &delays[3], level)) ||
225 || !(p = 228 !(p =
226 read_output_line (0, 3, 4, 9, 'L', "ERROR", -1, 1, phase, p, 229 read_output_line (0, 3, 4, 9, 'L', "ERROR", -1, 1, phase, p, &bytes,
227 &bytes, &delay, level)) 230 &delay, level)) ||
228 || !(p = 231 !(p =
229 read_output_line (0, 3, 4, 9, '2', "ERROR", 200, 400, phase, p, 232 read_output_line (0, 3, 4, 9, '2', "ERROR", 200, 400, phase, p, &bytes,
230 &bytes, &delays[4], level)) 233 &delays[4], level)) ||
231 || !(p = 234 !(p =
232 read_output_line (0, 3, 5, 9, 'L', "WARNING", -1, 1, phase, p, 235 read_output_line (0, 3, 5, 9, 'L', "WARNING", -1, 1, phase, p, &bytes,
233 &bytes, &delay, level)) 236 &delay, level)) ||
234 || !(p = 237 !(p =
235 read_output_line (0, 3, 4, 9, '2', "WARNING", 200, 400, phase, p, 238 read_output_line (0, 3, 4, 9, '2', "WARNING", 200, 400, phase, p,
236 &bytes, &delays[5], level)) 239 &bytes, &delays[5], level)) ||
237 || !(p = 240 !(p =
238 read_output_line (-1, -1, 6, 7, 'L', "INFO", -1, 1, phase, p, 241 read_output_line (-1, -1, 6, 7, 'L', "INFO", -1, 1, phase, p, &bytes,
239 &bytes, &delay, level)) 242 &delay, level)) ||
240 || !(p = 243 !(p =
241 read_output_line (0, 3, 4, 9, '2', "INFO", 200, 400, phase, p, 244 read_output_line (0, 3, 4, 9, '2', "INFO", 200, 400, phase, p, &bytes,
242 &bytes, &delays[6], level)) 245 &delays[6], level)) ||
243 || !(p = 246 !(p =
244 read_output_line (-1, -1, 7, 7, 'L', "DEBUG", -1, 1, phase, p, 247 read_output_line (-1, -1, 7, 7, 'L', "DEBUG", -1, 1, phase, p, &bytes,
245 &bytes, &delay, level)) 248 &delay, level)) ||
246 || !(p = 249 !(p =
247 read_output_line (0, 3, 4, 9, '2', "DEBUG", 200, 400, phase, p, 250 read_output_line (0, 3, 4, 9, '2', "DEBUG", 200, 400, phase, p, &bytes,
248 &bytes, &delays[7], level))) 251 &delays[7], level)))
249 { 252 {
250 if (bytes == 20 * 16) 253 if (bytes == 20 * 16)
251 fprintf (stderr, "Ran out of buffer space!\n"); 254 fprintf (stderr, "Ran out of buffer space!\n");
252 GNUNET_break (0); 255 GNUNET_break (0);
253 ok = 2; 256 ok = 2;
254 GNUNET_SCHEDULER_cancel (die_task); 257 GNUNET_SCHEDULER_cancel (die_task);
255 GNUNET_SCHEDULER_add_now (&end_task, NULL); 258 GNUNET_SCHEDULER_add_now (&end_task, NULL);
256 return; 259 return;
257 } 260 }
258 261
259 GNUNET_SCHEDULER_cancel (die_task); 262 GNUNET_SCHEDULER_cancel (die_task);
260 GNUNET_SCHEDULER_add_now (&end_task, NULL); 263 GNUNET_SCHEDULER_add_now (&end_task, NULL);
@@ -268,52 +271,51 @@ runone ()
268 pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES); 271 pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
269 272
270 if (pipe_stdout == NULL) 273 if (pipe_stdout == NULL)
271 { 274 {
272 GNUNET_break (0); 275 GNUNET_break (0);
273 ok = 2; 276 ok = 2;
274 return; 277 return;
275 } 278 }
276 279
277 putenv ("GNUNET_LOG="); 280 putenv ("GNUNET_LOG=");
278 putenv ("GNUNET_FORCE_LOG="); 281 putenv ("GNUNET_FORCE_LOG=");
279 switch (phase) 282 switch (phase)
280 { 283 {
281 case 0: 284 case 0:
282 putenv ("GNUNET_LOG=;;;;ERROR"); 285 putenv ("GNUNET_LOG=;;;;ERROR");
283 break; 286 break;
284 case 1: 287 case 1:
285 putenv ("GNUNET_LOG=;;;;WARNING"); 288 putenv ("GNUNET_LOG=;;;;WARNING");
286 break; 289 break;
287 case 2: 290 case 2:
288 putenv ("GNUNET_LOG=;;;;INFO"); 291 putenv ("GNUNET_LOG=;;;;INFO");
289 break; 292 break;
290 case 3: 293 case 3:
291 putenv ("GNUNET_LOG=;;;;DEBUG"); 294 putenv ("GNUNET_LOG=;;;;DEBUG");
292 break; 295 break;
293 case 4: 296 case 4:
294 putenv ("GNUNET_FORCE_LOG=;;;;ERROR"); 297 putenv ("GNUNET_FORCE_LOG=;;;;ERROR");
295 break; 298 break;
296 case 5: 299 case 5:
297 putenv ("GNUNET_FORCE_LOG=;;;;WARNING"); 300 putenv ("GNUNET_FORCE_LOG=;;;;WARNING");
298 break; 301 break;
299 case 6: 302 case 6:
300 putenv ("GNUNET_FORCE_LOG=;;;;INFO"); 303 putenv ("GNUNET_FORCE_LOG=;;;;INFO");
301 break; 304 break;
302 case 7: 305 case 7:
303 putenv ("GNUNET_FORCE_LOG=;;;;DEBUG"); 306 putenv ("GNUNET_FORCE_LOG=;;;;DEBUG");
304 break; 307 break;
305 case 8: 308 case 8:
306 putenv ("GNUNET_LOG=blah;;;;ERROR"); 309 putenv ("GNUNET_LOG=blah;;;;ERROR");
307 break; 310 break;
308 case 9: 311 case 9:
309 putenv ("GNUNET_FORCE_LOG=blah;;;;ERROR"); 312 putenv ("GNUNET_FORCE_LOG=blah;;;;ERROR");
310 break; 313 break;
311 } 314 }
312 315
313 proc = 316 proc =
314 GNUNET_OS_start_process (NULL, pipe_stdout, 317 GNUNET_OS_start_process (NULL, pipe_stdout, "./test_common_logging_dummy",
315 "./test_common_logging_dummy", 318 "test_common_logging_dummy", NULL);
316 "test_common_logging_dummy", NULL);
317 putenv ("GNUNET_FORCE_LOG="); 319 putenv ("GNUNET_FORCE_LOG=");
318 putenv ("GNUNET_LOG="); 320 putenv ("GNUNET_LOG=");
319 321
@@ -321,20 +323,20 @@ runone ()
321 GNUNET_DISK_pipe_close_end (pipe_stdout, GNUNET_DISK_PIPE_END_WRITE); 323 GNUNET_DISK_pipe_close_end (pipe_stdout, GNUNET_DISK_PIPE_END_WRITE);
322 324
323 stdout_read_handle = 325 stdout_read_handle =
324 GNUNET_DISK_pipe_handle (pipe_stdout, GNUNET_DISK_PIPE_END_READ); 326 GNUNET_DISK_pipe_handle (pipe_stdout, GNUNET_DISK_PIPE_END_READ);
325 327
326 die_task = 328 die_task =
327 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 329 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
328 (GNUNET_TIME_UNIT_SECONDS, 10), &end_task, 330 (GNUNET_TIME_UNIT_SECONDS, 10), &end_task,
329 NULL); 331 NULL);
330 332
331 bytes = 0; 333 bytes = 0;
332 buf_ptr = buf; 334 buf_ptr = buf;
333 memset (&buf, 0, sizeof (buf)); 335 memset (&buf, 0, sizeof (buf));
334 336
335 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 337 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
336 stdout_read_handle, &read_call, 338 stdout_read_handle, &read_call,
337 (void *) stdout_read_handle); 339 (void *) stdout_read_handle);
338} 340}
339 341
340static void 342static void
@@ -364,11 +366,11 @@ main (int argc, char *argv[])
364 366
365 GNUNET_log_setup ("test-common-logging-runtime-loglevels", 367 GNUNET_log_setup ("test-common-logging-runtime-loglevels",
366#if VERBOSE 368#if VERBOSE
367 "DEBUG", 369 "DEBUG",
368#else 370#else
369 "WARNING", 371 "WARNING",
370#endif 372#endif
371 NULL); 373 NULL);
372 ret = check (); 374 ret = check ();
373 375
374 return ret; 376 return ret;
diff --git a/src/util/test_configuration.c b/src/util/test_configuration.c
index 9deb4fc35..3780b3649 100644
--- a/src/util/test_configuration.c
+++ b/src/util/test_configuration.c
@@ -42,7 +42,7 @@ enum
42 REMOVE_ENTRY, 42 REMOVE_ENTRY,
43 COMPARE 43 COMPARE
44#if DEBUG 44#if DEBUG
45 , PRINT 45 , PRINT
46#endif 46#endif
47}; 47};
48 48
@@ -76,80 +76,80 @@ initDiffsCBData (struct DiffsCBData *cbData)
76*/ 76*/
77static void 77static void
78diffsCallBack (void *cls, const char *section, const char *option, 78diffsCallBack (void *cls, const char *section, const char *option,
79 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;
83 83
84 switch (cbOption) 84 switch (cbOption)
85 {
86 case EDIT_SECTION:
87 if (NULL == cbData->section)
88 cbData->section = section;
89 if (strcmp (cbData->section, section) == 0)
85 { 90 {
86 case EDIT_SECTION:
87 if (NULL == cbData->section)
88 cbData->section = section;
89 if (strcmp (cbData->section, section) == 0)
90 {
91 GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, option,
92 "new-value");
93 GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section,
94 option, "new-value");
95 }
96 break;
97 case EDIT_ALL:
98 GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, option, 91 GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, option,
99 "new-value"); 92 "new-value");
93 GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, option,
94 "new-value");
95 }
96 break;
97 case EDIT_ALL:
98 GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, option,
99 "new-value");
100 GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, option,
101 "new-value");
102 break;
103 case ADD_NEW_ENTRY:
104 {
105 static int hit = 0;
106
107 if (hit == 0)
108 {
109 hit = 1;
110 GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, "new-key",
111 "new-value");
100 GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, 112 GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section,
101 option, "new-value"); 113 "new-key", "new-value");
102 break; 114 }
103 case ADD_NEW_ENTRY: 115 break;
104 { 116 }
105 static int hit = 0; 117 case COMPARE:
106 118 {
107 if (hit == 0) 119 int ret;
108 { 120 char *diffValue;
109 hit = 1; 121
110 GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, 122 diffValue = NULL;
111 "new-key", "new-value"); 123 ret =
112 GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, 124 GNUNET_CONFIGURATION_get_value_string (cbData->cfgDiffs, section,
113 "new-key", "new-value"); 125 option, &diffValue);
114 } 126 if (NULL != diffValue)
115 break; 127 {
116 } 128 if (ret == GNUNET_SYSERR || strcmp (diffValue, value) != 0)
117 case COMPARE: 129 cbData->status = 1;
118 { 130 }
119 int ret; 131 else
120 char *diffValue; 132 cbData->status = 1;
121 133 GNUNET_free_non_null (diffValue);
122 diffValue = NULL; 134 break;
123 ret = 135 }
124 GNUNET_CONFIGURATION_get_value_string (cbData->cfgDiffs, section,
125 option, &diffValue);
126 if (NULL != diffValue)
127 {
128 if (ret == GNUNET_SYSERR || strcmp (diffValue, value) != 0)
129 cbData->status = 1;
130 }
131 else
132 cbData->status = 1;
133 GNUNET_free_non_null (diffValue);
134 break;
135 }
136#if 0 136#if 0
137 case PRINT: 137 case PRINT:
138 if (NULL == cbData->section) 138 if (NULL == cbData->section)
139 { 139 {
140 cbData->section = section; 140 cbData->section = section;
141 printf ("\nSection: %s\n", section); 141 printf ("\nSection: %s\n", section);
142 }
143 else if (strcmp (cbData->section, section) != 0)
144 {
145 cbData->section = section;
146 printf ("\nSection: %s\n", section);
147 }
148 printf ("%s = %s\n", option, value);
149#endif
150 default:
151 break;
152 } 142 }
143 else if (strcmp (cbData->section, section) != 0)
144 {
145 cbData->section = section;
146 printf ("\nSection: %s\n", section);
147 }
148 printf ("%s = %s\n", option, value);
149#endif
150 default:
151 break;
152 }
153} 153}
154 154
155 155
@@ -162,41 +162,40 @@ editConfiguration (struct GNUNET_CONFIGURATION_Handle *cfg, int option)
162 diffsCB.cfgDiffs = GNUNET_CONFIGURATION_create (); 162 diffsCB.cfgDiffs = GNUNET_CONFIGURATION_create ();
163 163
164 switch (option) 164 switch (option)
165 {
166 case EDIT_SECTION:
167 case EDIT_ALL:
168 case ADD_NEW_ENTRY:
169 diffsCB.callBackOption = option;
170 diffsCB.cfg = cfg;
171 GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &diffsCB);
172 break;
173 case EDIT_NOTHING:
174 /* Do nothing */
175 break;
176 case ADD_NEW_SECTION:
177 {
178 int i;
179 char *key;
180
181 for (i = 0; i < 5; i++)
165 { 182 {
166 case EDIT_SECTION: 183 GNUNET_asprintf (&key, "key%d", i);
167 case EDIT_ALL: 184 GNUNET_CONFIGURATION_set_value_string (cfg, "new-section", key,
168 case ADD_NEW_ENTRY: 185 "new-value");
169 diffsCB.callBackOption = option; 186 GNUNET_CONFIGURATION_set_value_string (diffsCB.cfgDiffs, "new-section",
170 diffsCB.cfg = cfg; 187 key, "new-value");
171 GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &diffsCB); 188 GNUNET_free (key);
172 break;
173 case EDIT_NOTHING:
174 /* Do nothing */
175 break;
176 case ADD_NEW_SECTION:
177 {
178 int i;
179 char *key;
180
181 for (i = 0; i < 5; i++)
182 {
183 GNUNET_asprintf (&key, "key%d", i);
184 GNUNET_CONFIGURATION_set_value_string (cfg, "new-section", key,
185 "new-value");
186 GNUNET_CONFIGURATION_set_value_string (diffsCB.cfgDiffs,
187 "new-section", key,
188 "new-value");
189 GNUNET_free (key);
190 }
191 break;
192 }
193 case REMOVE_SECTION:
194 break;
195 case REMOVE_ENTRY:
196 break;
197 default:
198 break;
199 } 189 }
190 break;
191 }
192 case REMOVE_SECTION:
193 break;
194 case REMOVE_ENTRY:
195 break;
196 default:
197 break;
198 }
200 199
201 return diffsCB.cfgDiffs; 200 return diffsCB.cfgDiffs;
202} 201}
@@ -221,37 +220,35 @@ checkDiffs (struct GNUNET_CONFIGURATION_Handle *cfgDefault, int option)
221 220
222 /* Modify configuration and save it */ 221 /* Modify configuration and save it */
223 cfgDiffs = editConfiguration (cfg, option); 222 cfgDiffs = editConfiguration (cfg, option);
224 diffsFileName = 223 diffsFileName = GNUNET_DISK_mktemp ("gnunet-test-configurations-diffs.conf");
225 GNUNET_DISK_mktemp ("gnunet-test-configurations-diffs.conf");
226 if (diffsFileName == NULL) 224 if (diffsFileName == NULL)
227 { 225 {
228 GNUNET_break (0); 226 GNUNET_break (0);
229 GNUNET_CONFIGURATION_destroy (cfg); 227 GNUNET_CONFIGURATION_destroy (cfg);
230 GNUNET_CONFIGURATION_destroy (cfgDiffs); 228 GNUNET_CONFIGURATION_destroy (cfgDiffs);
231 return 1; 229 return 1;
232 } 230 }
233 GNUNET_CONFIGURATION_write_diffs (cfgDefault, cfg, diffsFileName); 231 GNUNET_CONFIGURATION_write_diffs (cfgDefault, cfg, diffsFileName);
234 GNUNET_CONFIGURATION_destroy (cfg); 232 GNUNET_CONFIGURATION_destroy (cfg);
235 233
236 /* Compare the dumped configuration with modifications done */ 234 /* Compare the dumped configuration with modifications done */
237 cfg = GNUNET_CONFIGURATION_create (); 235 cfg = GNUNET_CONFIGURATION_create ();
238 GNUNET_assert (GNUNET_OK == 236 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_parse (cfg, diffsFileName));
239 GNUNET_CONFIGURATION_parse (cfg, diffsFileName));
240 remove (diffsFileName); 237 remove (diffsFileName);
241 cbData.callBackOption = COMPARE; 238 cbData.callBackOption = COMPARE;
242 cbData.cfgDiffs = cfgDiffs; 239 cbData.cfgDiffs = cfgDiffs;
243 GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &cbData); 240 GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &cbData);
244 if (1 == (ret = cbData.status)) 241 if (1 == (ret = cbData.status))
245 { 242 {
246 fprintf (stderr, 243 fprintf (stderr,
247 "Incorrect Configuration Diffs: Diffs may contain data not actually edited\n"); 244 "Incorrect Configuration Diffs: Diffs may contain data not actually edited\n");
248 goto housekeeping; 245 goto housekeeping;
249 } 246 }
250 cbData.cfgDiffs = cfg; 247 cbData.cfgDiffs = cfg;
251 GNUNET_CONFIGURATION_iterate (cfgDiffs, diffsCallBack, &cbData); 248 GNUNET_CONFIGURATION_iterate (cfgDiffs, diffsCallBack, &cbData);
252 if ((ret = cbData.status) == 1) 249 if ((ret = cbData.status) == 1)
253 fprintf (stderr, 250 fprintf (stderr,
254 "Incorrect Configuration Diffs: Data may be missing in diffs\n"); 251 "Incorrect Configuration Diffs: Data may be missing in diffs\n");
255 252
256housekeeping: 253housekeeping:
257#if 0 254#if 0
@@ -276,65 +273,64 @@ testConfig ()
276 char *c; 273 char *c;
277 unsigned long long l; 274 unsigned long long l;
278 275
279 if (GNUNET_OK != 276 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "test", "b", &c))
280 GNUNET_CONFIGURATION_get_value_string (cfg, "test", "b", &c))
281 return 1; 277 return 1;
282 if (0 != strcmp ("b", c)) 278 if (0 != strcmp ("b", c))
283 { 279 {
284 fprintf (stderr, "Got `%s'\n", c); 280 fprintf (stderr, "Got `%s'\n", c);
285 GNUNET_free (c); 281 GNUNET_free (c);
286 return 2; 282 return 2;
287 } 283 }
288 GNUNET_free (c); 284 GNUNET_free (c);
289 if (GNUNET_OK != 285 if (GNUNET_OK !=
290 GNUNET_CONFIGURATION_get_value_number (cfg, "test", "five", &l)) 286 GNUNET_CONFIGURATION_get_value_number (cfg, "test", "five", &l))
291 { 287 {
292 GNUNET_break (0); 288 GNUNET_break (0);
293 return 3; 289 return 3;
294 } 290 }
295 if (5 != l) 291 if (5 != l)
296 { 292 {
297 GNUNET_break (0); 293 GNUNET_break (0);
298 return 4; 294 return 4;
299 } 295 }
300 GNUNET_CONFIGURATION_set_value_string (cfg, "more", "c", "YES"); 296 GNUNET_CONFIGURATION_set_value_string (cfg, "more", "c", "YES");
301 if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_yesno (cfg, "more", "c")) 297 if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_yesno (cfg, "more", "c"))
302 { 298 {
303 GNUNET_break (0); 299 GNUNET_break (0);
304 return 5; 300 return 5;
305 } 301 }
306 GNUNET_CONFIGURATION_set_value_number (cfg, "NUMBERS", "TEN", 10); 302 GNUNET_CONFIGURATION_set_value_number (cfg, "NUMBERS", "TEN", 10);
307 if (GNUNET_OK != 303 if (GNUNET_OK !=
308 GNUNET_CONFIGURATION_get_value_string (cfg, "NUMBERS", "TEN", &c)) 304 GNUNET_CONFIGURATION_get_value_string (cfg, "NUMBERS", "TEN", &c))
309 { 305 {
310 GNUNET_break (0); 306 GNUNET_break (0);
311 return 6; 307 return 6;
312 } 308 }
313 if (0 != strcmp (c, "10")) 309 if (0 != strcmp (c, "10"))
314 { 310 {
315 GNUNET_free (c); 311 GNUNET_free (c);
316 GNUNET_break (0); 312 GNUNET_break (0);
317 return 7; 313 return 7;
318 } 314 }
319 GNUNET_free (c); 315 GNUNET_free (c);
320 316
321 if (GNUNET_OK != 317 if (GNUNET_OK !=
322 GNUNET_CONFIGURATION_get_value_filename (cfg, "last", "test", &c)) 318 GNUNET_CONFIGURATION_get_value_filename (cfg, "last", "test", &c))
323 { 319 {
324 GNUNET_break (0); 320 GNUNET_break (0);
325 return 8; 321 return 8;
326 } 322 }
327#ifndef MINGW 323#ifndef MINGW
328 if (0 != strcmp (c, "/hello/world")) 324 if (0 != strcmp (c, "/hello/world"))
329#else 325#else
330#define HI "\\hello\\world" 326#define HI "\\hello\\world"
331 if (strstr (c, HI) != c + strlen (c) - strlen (HI)) 327 if (strstr (c, HI) != c + strlen (c) - strlen (HI))
332#endif 328#endif
333 { 329 {
334 GNUNET_break (0); 330 GNUNET_break (0);
335 GNUNET_free (c); 331 GNUNET_free (c);
336 return 9; 332 return 9;
337 } 333 }
338 GNUNET_free (c); 334 GNUNET_free (c);
339 335
340 if (GNUNET_OK != 336 if (GNUNET_OK !=
@@ -365,10 +361,10 @@ check (void *data, const char *fn)
365 int *idx = data; 361 int *idx = data;
366 362
367 if (0 == strcmp (want[*idx], fn)) 363 if (0 == strcmp (want[*idx], fn))
368 { 364 {
369 (*idx)++; 365 (*idx)++;
370 return GNUNET_OK; 366 return GNUNET_OK;
371 } 367 }
372 GNUNET_break (0); 368 GNUNET_break (0);
373 return GNUNET_SYSERR; 369 return GNUNET_SYSERR;
374} 370}
@@ -381,66 +377,66 @@ testConfigFilenames ()
381 idx = 0; 377 idx = 0;
382 if (3 != 378 if (3 !=
383 GNUNET_CONFIGURATION_iterate_value_filenames (cfg, "FILENAMES", "test", 379 GNUNET_CONFIGURATION_iterate_value_filenames (cfg, "FILENAMES", "test",
384 &check, &idx)) 380 &check, &idx))
385 { 381 {
386 GNUNET_break (0); 382 GNUNET_break (0);
387 return 8; 383 return 8;
388 } 384 }
389 if (idx != 3) 385 if (idx != 3)
390 return 16; 386 return 16;
391 if (GNUNET_OK != 387 if (GNUNET_OK !=
392 GNUNET_CONFIGURATION_remove_value_filename (cfg, "FILENAMES", "test", 388 GNUNET_CONFIGURATION_remove_value_filename (cfg, "FILENAMES", "test",
393 "/File Name")) 389 "/File Name"))
394 { 390 {
395 GNUNET_break (0); 391 GNUNET_break (0);
396 return 24; 392 return 24;
397 } 393 }
398 394
399 if (GNUNET_NO != 395 if (GNUNET_NO !=
400 GNUNET_CONFIGURATION_remove_value_filename (cfg, "FILENAMES", "test", 396 GNUNET_CONFIGURATION_remove_value_filename (cfg, "FILENAMES", "test",
401 "/File Name")) 397 "/File Name"))
402 { 398 {
403 GNUNET_break (0); 399 GNUNET_break (0);
404 return 32; 400 return 32;
405 } 401 }
406 if (GNUNET_NO != 402 if (GNUNET_NO !=
407 GNUNET_CONFIGURATION_remove_value_filename (cfg, "FILENAMES", "test", 403 GNUNET_CONFIGURATION_remove_value_filename (cfg, "FILENAMES", "test",
408 "Stuff")) 404 "Stuff"))
409 { 405 {
410 GNUNET_break (0); 406 GNUNET_break (0);
411 return 40; 407 return 40;
412 } 408 }
413 409
414 if (GNUNET_NO != 410 if (GNUNET_NO !=
415 GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test", 411 GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test",
416 "/Hello")) 412 "/Hello"))
417 { 413 {
418 GNUNET_break (0); 414 GNUNET_break (0);
419 return 48; 415 return 48;
420 } 416 }
421 if (GNUNET_NO != 417 if (GNUNET_NO !=
422 GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test", 418 GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test",
423 "/World")) 419 "/World"))
424 { 420 {
425 GNUNET_break (0); 421 GNUNET_break (0);
426 return 56; 422 return 56;
427 } 423 }
428 424
429 if (GNUNET_YES != 425 if (GNUNET_YES !=
430 GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test", 426 GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test",
431 "/File 1")) 427 "/File 1"))
432 { 428 {
433 GNUNET_break (0); 429 GNUNET_break (0);
434 return 64; 430 return 64;
435 } 431 }
436 432
437 if (GNUNET_YES != 433 if (GNUNET_YES !=
438 GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test", 434 GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test",
439 "/File 2")) 435 "/File 2"))
440 { 436 {
441 GNUNET_break (0); 437 GNUNET_break (0);
442 return 72; 438 return 72;
443 } 439 }
444 440
445 idx = 0; 441 idx = 0;
446 want[1] = "/World"; 442 want[1] = "/World";
@@ -448,16 +444,16 @@ testConfigFilenames ()
448 want[3] = "/File 2"; 444 want[3] = "/File 2";
449 if (4 != 445 if (4 !=
450 GNUNET_CONFIGURATION_iterate_value_filenames (cfg, "FILENAMES", "test", 446 GNUNET_CONFIGURATION_iterate_value_filenames (cfg, "FILENAMES", "test",
451 &check, &idx)) 447 &check, &idx))
452 { 448 {
453 GNUNET_break (0); 449 GNUNET_break (0);
454 return 80; 450 return 80;
455 } 451 }
456 if (idx != 4) 452 if (idx != 4)
457 { 453 {
458 GNUNET_break (0); 454 GNUNET_break (0);
459 return 88; 455 return 88;
460 } 456 }
461 return 0; 457 return 0;
462} 458}
463 459
@@ -473,11 +469,11 @@ main (int argc, char *argv[])
473 GNUNET_assert (cfg != NULL); 469 GNUNET_assert (cfg != NULL);
474 if (GNUNET_OK != 470 if (GNUNET_OK !=
475 GNUNET_CONFIGURATION_parse (cfg, "test_configuration_data.conf")) 471 GNUNET_CONFIGURATION_parse (cfg, "test_configuration_data.conf"))
476 { 472 {
477 fprintf (stderr, "Failed to parse configuration file\n"); 473 fprintf (stderr, "Failed to parse configuration file\n");
478 GNUNET_CONFIGURATION_destroy (cfg); 474 GNUNET_CONFIGURATION_destroy (cfg);
479 return 1; 475 return 1;
480 } 476 }
481 failureCount += testConfig (); 477 failureCount += testConfig ();
482 if (failureCount > 0) 478 if (failureCount > 0)
483 goto error; 479 goto error;
@@ -487,37 +483,36 @@ main (int argc, char *argv[])
487 goto error; 483 goto error;
488 484
489 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, "/tmp/gnunet-test.conf")) 485 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, "/tmp/gnunet-test.conf"))
490 { 486 {
491 fprintf (stderr, "Failed to write configuration file\n"); 487 fprintf (stderr, "Failed to write configuration file\n");
492 GNUNET_CONFIGURATION_destroy (cfg); 488 GNUNET_CONFIGURATION_destroy (cfg);
493 return 1; 489 return 1;
494 } 490 }
495 GNUNET_CONFIGURATION_destroy (cfg); 491 GNUNET_CONFIGURATION_destroy (cfg);
496 GNUNET_assert (0 == UNLINK ("/tmp/gnunet-test.conf")); 492 GNUNET_assert (0 == UNLINK ("/tmp/gnunet-test.conf"));
497 493
498 cfg = GNUNET_CONFIGURATION_create (); 494 cfg = GNUNET_CONFIGURATION_create ();
499 if (GNUNET_OK != 495 if (GNUNET_OK !=
500 GNUNET_CONFIGURATION_load (cfg, "test_configuration_data.conf")) 496 GNUNET_CONFIGURATION_load (cfg, "test_configuration_data.conf"))
501 { 497 {
502 GNUNET_break (0); 498 GNUNET_break (0);
503 GNUNET_CONFIGURATION_destroy (cfg); 499 GNUNET_CONFIGURATION_destroy (cfg);
504 return 1; 500 return 1;
505 } 501 }
506 if (GNUNET_OK != 502 if (GNUNET_OK !=
507 GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", "WEAKRANDOM", 503 GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", "WEAKRANDOM", &c))
508 &c)) 504 {
509 { 505 GNUNET_break (0);
510 GNUNET_break (0); 506 GNUNET_CONFIGURATION_destroy (cfg);
511 GNUNET_CONFIGURATION_destroy (cfg); 507 return 1;
512 return 1; 508 }
513 }
514 if (0 != strcmp (c, "YES")) 509 if (0 != strcmp (c, "YES"))
515 { 510 {
516 GNUNET_break (0); 511 GNUNET_break (0);
517 GNUNET_free (c); 512 GNUNET_free (c);
518 GNUNET_CONFIGURATION_destroy (cfg); 513 GNUNET_CONFIGURATION_destroy (cfg);
519 return 1; 514 return 1;
520 } 515 }
521 516
522 GNUNET_free (c); 517 GNUNET_free (c);
523 GNUNET_CONFIGURATION_destroy (cfg); 518 GNUNET_CONFIGURATION_destroy (cfg);
@@ -525,11 +520,11 @@ main (int argc, char *argv[])
525 /* Testing configuration diffs */ 520 /* Testing configuration diffs */
526 cfgDefault = GNUNET_CONFIGURATION_create (); 521 cfgDefault = GNUNET_CONFIGURATION_create ();
527 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfgDefault, NULL)) 522 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfgDefault, NULL))
528 { 523 {
529 GNUNET_break (0); 524 GNUNET_break (0);
530 GNUNET_CONFIGURATION_destroy (cfgDefault); 525 GNUNET_CONFIGURATION_destroy (cfgDefault);
531 return 1; 526 return 1;
532 } 527 }
533 528
534 /* Nothing changed in the new configuration */ 529 /* Nothing changed in the new configuration */
535 failureCount += checkDiffs (cfgDefault, EDIT_NOTHING); 530 failureCount += checkDiffs (cfgDefault, EDIT_NOTHING);
@@ -550,9 +545,9 @@ main (int argc, char *argv[])
550 545
551error: 546error:
552 if (failureCount != 0) 547 if (failureCount != 0)
553 { 548 {
554 fprintf (stderr, "Test failed: %u\n", failureCount); 549 fprintf (stderr, "Test failed: %u\n", failureCount);
555 return 1; 550 return 1;
556 } 551 }
557 return 0; 552 return 0;
558} 553}
diff --git a/src/util/test_connection.c b/src/util/test_connection.c
index 1ac5b99cd..92c0cea2e 100644
--- a/src/util/test_connection.c
+++ b/src/util/test_connection.c
@@ -66,46 +66,44 @@ open_listen_socket ()
66 GNUNET_assert (desc != NULL); 66 GNUNET_assert (desc != NULL);
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, 69 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt");
70 "setsockopt");
71 GNUNET_assert (GNUNET_NETWORK_socket_bind 70 GNUNET_assert (GNUNET_NETWORK_socket_bind
72 (desc, (const struct sockaddr *) &sa, 71 (desc, (const struct sockaddr *) &sa,
73 sizeof (sa)) == GNUNET_OK); 72 sizeof (sa)) == GNUNET_OK);
74 GNUNET_NETWORK_socket_listen (desc, 5); 73 GNUNET_NETWORK_socket_listen (desc, 5);
75 return desc; 74 return desc;
76} 75}
77 76
78static void 77static void
79receive_check (void *cls, const void *buf, size_t available, 78receive_check (void *cls, const void *buf, size_t available,
80 const struct sockaddr *addr, socklen_t addrlen, int errCode) 79 const struct sockaddr *addr, socklen_t addrlen, int errCode)
81{ 80{
82 int *ok = cls; 81 int *ok = cls;
83 82
84#if VERBOSE 83#if VERBOSE
85 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receive validates incoming data\n"); 84 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receive validates incoming data\n");
86#endif 85#endif
87 GNUNET_assert (buf != NULL); /* no timeout */ 86 GNUNET_assert (buf != NULL); /* no timeout */
88 if (0 == memcmp (&"Hello World"[sofar], buf, available)) 87 if (0 == memcmp (&"Hello World"[sofar], buf, available))
89 sofar += available; 88 sofar += available;
90 if (sofar < 12) 89 if (sofar < 12)
91 { 90 {
92#if VERBOSE 91#if VERBOSE
93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receive needs more data\n"); 92 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receive needs more data\n");
94#endif 93#endif
95 GNUNET_CONNECTION_receive (asock, 1024, 94 GNUNET_CONNECTION_receive (asock, 1024,
96 GNUNET_TIME_relative_multiply 95 GNUNET_TIME_relative_multiply
97 (GNUNET_TIME_UNIT_SECONDS, 5), 96 (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check,
98 &receive_check, cls); 97 cls);
99 } 98 }
100 else 99 else
101 { 100 {
102#if VERBOSE 101#if VERBOSE
103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receive closes accepted socket\n");
104 "Receive closes accepted socket\n");
105#endif 103#endif
106 *ok = 0; 104 *ok = 0;
107 GNUNET_CONNECTION_destroy (asock, GNUNET_YES); 105 GNUNET_CONNECTION_destroy (asock, GNUNET_YES);
108 } 106 }
109} 107}
110 108
111 109
@@ -124,12 +122,12 @@ run_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
124 GNUNET_CONNECTION_destroy (lsock, GNUNET_YES); 122 GNUNET_CONNECTION_destroy (lsock, GNUNET_YES);
125#if VERBOSE 123#if VERBOSE
126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
127 "Test asks to receive on accepted socket\n"); 125 "Test asks to receive on accepted socket\n");
128#endif 126#endif
129 GNUNET_CONNECTION_receive (asock, 1024, 127 GNUNET_CONNECTION_receive (asock, 1024,
130 GNUNET_TIME_relative_multiply 128 GNUNET_TIME_relative_multiply
131 (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, 129 (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check,
132 cls); 130 cls);
133} 131}
134 132
135static size_t 133static size_t
@@ -137,7 +135,7 @@ make_hello (void *cls, size_t size, void *buf)
137{ 135{
138#if VERBOSE 136#if VERBOSE
139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 137 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
140 "Test prepares to transmit on connect socket\n"); 138 "Test prepares to transmit on connect socket\n");
141#endif 139#endif
142 GNUNET_assert (size >= 12); 140 GNUNET_assert (size >= 12);
143 strcpy ((char *) buf, "Hello World"); 141 strcpy ((char *) buf, "Hello World");
@@ -160,14 +158,14 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
160 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");
161#endif 159#endif
162 GNUNET_assert (NULL != 160 GNUNET_assert (NULL !=
163 GNUNET_CONNECTION_notify_transmit_ready (csock, 12, 161 GNUNET_CONNECTION_notify_transmit_ready (csock, 12,
164 GNUNET_TIME_UNIT_SECONDS, 162 GNUNET_TIME_UNIT_SECONDS,
165 &make_hello, NULL)); 163 &make_hello, NULL));
166#if VERBOSE 164#if VERBOSE
167 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test prepares to accept\n"); 165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test prepares to accept\n");
168#endif 166#endif
169 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, ls, 167 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, ls, &run_accept,
170 &run_accept, cls); 168 cls);
171} 169}
172 170
173 171
@@ -183,7 +181,7 @@ check ()
183 ok = 1; 181 ok = 1;
184 cfg = GNUNET_CONFIGURATION_create (); 182 cfg = GNUNET_CONFIGURATION_create ();
185 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", 183 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
186 "localhost"); 184 "localhost");
187 GNUNET_SCHEDULER_run (&task, &ok); 185 GNUNET_SCHEDULER_run (&task, &ok);
188 GNUNET_CONFIGURATION_destroy (cfg); 186 GNUNET_CONFIGURATION_destroy (cfg);
189 return ok; 187 return ok;
@@ -198,11 +196,11 @@ main (int argc, char *argv[])
198 196
199 GNUNET_log_setup ("test_connection", 197 GNUNET_log_setup ("test_connection",
200#if VERBOSE 198#if VERBOSE
201 "DEBUG", 199 "DEBUG",
202#else 200#else
203 "WARNING", 201 "WARNING",
204#endif 202#endif
205 NULL); 203 NULL);
206 ret += check (); 204 ret += check ();
207 return ret; 205 return ret;
208} 206}
diff --git a/src/util/test_connection_addressing.c b/src/util/test_connection_addressing.c
index c413c18c8..018cf61fb 100644
--- a/src/util/test_connection_addressing.c
+++ b/src/util/test_connection_addressing.c
@@ -66,16 +66,15 @@ open_listen_socket ()
66 GNUNET_assert (desc != 0); 66 GNUNET_assert (desc != 0);
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, 69 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt");
70 "setsockopt");
71 if (GNUNET_OK != 70 if (GNUNET_OK !=
72 GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) &sa, 71 GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) &sa,
73 sizeof (sa))) 72 sizeof (sa)))
74 { 73 {
75 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 74 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
76 "bind"); 75 "bind");
77 GNUNET_assert (0); 76 GNUNET_assert (0);
78 } 77 }
79 GNUNET_NETWORK_socket_listen (desc, 5); 78 GNUNET_NETWORK_socket_listen (desc, 5);
80 return desc; 79 return desc;
81} 80}
@@ -83,25 +82,25 @@ open_listen_socket ()
83 82
84static void 83static void
85receive_check (void *cls, const void *buf, size_t available, 84receive_check (void *cls, const void *buf, size_t available,
86 const struct sockaddr *addr, socklen_t addrlen, int errCode) 85 const struct sockaddr *addr, socklen_t addrlen, int errCode)
87{ 86{
88 int *ok = cls; 87 int *ok = cls;
89 88
90 GNUNET_assert (buf != NULL); /* no timeout */ 89 GNUNET_assert (buf != NULL); /* no timeout */
91 if (0 == memcmp (&"Hello World"[sofar], buf, available)) 90 if (0 == memcmp (&"Hello World"[sofar], buf, available))
92 sofar += available; 91 sofar += available;
93 if (sofar < 12) 92 if (sofar < 12)
94 { 93 {
95 GNUNET_CONNECTION_receive (asock, 1024, 94 GNUNET_CONNECTION_receive (asock, 1024,
96 GNUNET_TIME_relative_multiply 95 GNUNET_TIME_relative_multiply
97 (GNUNET_TIME_UNIT_SECONDS, 5), 96 (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check,
98 &receive_check, cls); 97 cls);
99 } 98 }
100 else 99 else
101 { 100 {
102 *ok = 0; 101 *ok = 0;
103 GNUNET_CONNECTION_destroy (asock, GNUNET_YES); 102 GNUNET_CONNECTION_destroy (asock, GNUNET_YES);
104 } 103 }
105} 104}
106 105
107 106
@@ -117,7 +116,7 @@ run_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
117 GNUNET_assert (asock != NULL); 116 GNUNET_assert (asock != NULL);
118 GNUNET_assert (GNUNET_YES == GNUNET_CONNECTION_check (asock)); 117 GNUNET_assert (GNUNET_YES == GNUNET_CONNECTION_check (asock));
119 GNUNET_assert (GNUNET_OK == 118 GNUNET_assert (GNUNET_OK ==
120 GNUNET_CONNECTION_get_address (asock, &addr, &alen)); 119 GNUNET_CONNECTION_get_address (asock, &addr, &alen));
121 GNUNET_assert (alen == sizeof (struct sockaddr_in)); 120 GNUNET_assert (alen == sizeof (struct sockaddr_in));
122 v4 = addr; 121 v4 = addr;
123 memset (&expect, 0, sizeof (expect)); 122 memset (&expect, 0, sizeof (expect));
@@ -131,9 +130,9 @@ run_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
131 GNUNET_free (addr); 130 GNUNET_free (addr);
132 GNUNET_CONNECTION_destroy (lsock, GNUNET_YES); 131 GNUNET_CONNECTION_destroy (lsock, GNUNET_YES);
133 GNUNET_CONNECTION_receive (asock, 1024, 132 GNUNET_CONNECTION_receive (asock, 1024,
134 GNUNET_TIME_relative_multiply 133 GNUNET_TIME_relative_multiply
135 (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, 134 (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check,
136 cls); 135 cls);
137} 136}
138 137
139static size_t 138static size_t
@@ -160,17 +159,17 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
160 v4.sin_port = htons (PORT); 159 v4.sin_port = htons (PORT);
161 v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK); 160 v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
162 csock = 161 csock =
163 GNUNET_CONNECTION_create_from_sockaddr (AF_INET, 162 GNUNET_CONNECTION_create_from_sockaddr (AF_INET,
164 (const struct sockaddr *) &v4, 163 (const struct sockaddr *) &v4,
165 sizeof (v4)); 164 sizeof (v4));
166 GNUNET_assert (csock != NULL); 165 GNUNET_assert (csock != NULL);
167 GNUNET_assert (NULL != 166 GNUNET_assert (NULL !=
168 GNUNET_CONNECTION_notify_transmit_ready (csock, 12, 167 GNUNET_CONNECTION_notify_transmit_ready (csock, 12,
169 GNUNET_TIME_UNIT_SECONDS, 168 GNUNET_TIME_UNIT_SECONDS,
170 &make_hello, NULL)); 169 &make_hello, NULL));
171 GNUNET_CONNECTION_destroy (csock, GNUNET_YES); 170 GNUNET_CONNECTION_destroy (csock, GNUNET_YES);
172 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, ls, 171 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, ls, &run_accept,
173 &run_accept, cls); 172 cls);
174} 173}
175 174
176 175
@@ -197,11 +196,11 @@ main (int argc, char *argv[])
197 196
198 GNUNET_log_setup ("test_connection_addressing", 197 GNUNET_log_setup ("test_connection_addressing",
199#if VERBOSE 198#if VERBOSE
200 "DEBUG", 199 "DEBUG",
201#else 200#else
202 "WARNING", 201 "WARNING",
203#endif 202#endif
204 NULL); 203 NULL);
205 ret += check (); 204 ret += check ();
206 return ret; 205 return ret;
207} 206}
diff --git a/src/util/test_connection_receive_cancel.c b/src/util/test_connection_receive_cancel.c
index bd095fdda..63829344d 100644
--- a/src/util/test_connection_receive_cancel.c
+++ b/src/util/test_connection_receive_cancel.c
@@ -65,11 +65,10 @@ open_listen_socket ()
65 GNUNET_assert (desc != NULL); 65 GNUNET_assert (desc != NULL);
66 if (GNUNET_NETWORK_socket_setsockopt 66 if (GNUNET_NETWORK_socket_setsockopt
67 (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) 67 (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)
68 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 68 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt");
69 "setsockopt");
70 GNUNET_assert (GNUNET_NETWORK_socket_bind 69 GNUNET_assert (GNUNET_NETWORK_socket_bind
71 (desc, (const struct sockaddr *) &sa, 70 (desc, (const struct sockaddr *) &sa,
72 sizeof (sa)) == GNUNET_OK); 71 sizeof (sa)) == GNUNET_OK);
73 GNUNET_NETWORK_socket_listen (desc, 5); 72 GNUNET_NETWORK_socket_listen (desc, 5);
74 return desc; 73 return desc;
75} 74}
@@ -78,7 +77,7 @@ open_listen_socket ()
78 77
79static void 78static void
80dead_receive (void *cls, const void *buf, size_t available, 79dead_receive (void *cls, const void *buf, size_t available,
81 const struct sockaddr *addr, socklen_t addrlen, int errCode) 80 const struct sockaddr *addr, socklen_t addrlen, int errCode)
82{ 81{
83 GNUNET_assert (0); 82 GNUNET_assert (0);
84} 83}
@@ -93,9 +92,8 @@ run_accept_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
93 GNUNET_assert (GNUNET_YES == GNUNET_CONNECTION_check (asock)); 92 GNUNET_assert (GNUNET_YES == GNUNET_CONNECTION_check (asock));
94 GNUNET_CONNECTION_destroy (lsock, GNUNET_YES); 93 GNUNET_CONNECTION_destroy (lsock, GNUNET_YES);
95 GNUNET_CONNECTION_receive (asock, 1024, 94 GNUNET_CONNECTION_receive (asock, 1024,
96 GNUNET_TIME_relative_multiply 95 GNUNET_TIME_relative_multiply
97 (GNUNET_TIME_UNIT_SECONDS, 5), &dead_receive, 96 (GNUNET_TIME_UNIT_SECONDS, 5), &dead_receive, cls);
98 cls);
99} 97}
100 98
101 99
@@ -121,9 +119,9 @@ task_receive_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
121 csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT); 119 csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT);
122 GNUNET_assert (csock != NULL); 120 GNUNET_assert (csock != NULL);
123 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, ls, 121 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, ls,
124 &run_accept_cancel, cls); 122 &run_accept_cancel, cls);
125 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 123 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &receive_cancel_task,
126 &receive_cancel_task, cls); 124 cls);
127} 125}
128 126
129 127
@@ -139,7 +137,7 @@ check_receive_cancel ()
139 ok = 1; 137 ok = 1;
140 cfg = GNUNET_CONFIGURATION_create (); 138 cfg = GNUNET_CONFIGURATION_create ();
141 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", 139 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
142 "localhost"); 140 "localhost");
143 GNUNET_SCHEDULER_run (&task_receive_cancel, &ok); 141 GNUNET_SCHEDULER_run (&task_receive_cancel, &ok);
144 GNUNET_CONFIGURATION_destroy (cfg); 142 GNUNET_CONFIGURATION_destroy (cfg);
145 return ok; 143 return ok;
diff --git a/src/util/test_connection_timeout.c b/src/util/test_connection_timeout.c
index 5a0bb7c3a..1700718b9 100644
--- a/src/util/test_connection_timeout.c
+++ b/src/util/test_connection_timeout.c
@@ -62,11 +62,10 @@ open_listen_socket ()
62 GNUNET_assert (desc != NULL); 62 GNUNET_assert (desc != NULL);
63 if (GNUNET_NETWORK_socket_setsockopt 63 if (GNUNET_NETWORK_socket_setsockopt
64 (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) 64 (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)
65 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 65 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt");
66 "setsockopt");
67 GNUNET_assert (GNUNET_NETWORK_socket_bind 66 GNUNET_assert (GNUNET_NETWORK_socket_bind
68 (desc, (const struct sockaddr *) &sa, 67 (desc, (const struct sockaddr *) &sa,
69 sizeof (sa)) == GNUNET_OK); 68 sizeof (sa)) == GNUNET_OK);
70 GNUNET_NETWORK_socket_listen (desc, 5); 69 GNUNET_NETWORK_socket_listen (desc, 5);
71 return desc; 70 return desc;
72} 71}
@@ -78,16 +77,16 @@ send_kilo (void *cls, size_t size, void *buf)
78 int *ok = cls; 77 int *ok = cls;
79 78
80 if (size == 0) 79 if (size == 0)
81 { 80 {
82#if VERBOSE 81#if VERBOSE
83 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got the desired timeout!\n"); 82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got the desired timeout!\n");
84#endif 83#endif
85 GNUNET_assert (buf == NULL); 84 GNUNET_assert (buf == NULL);
86 *ok = 0; 85 *ok = 0;
87 GNUNET_CONNECTION_destroy (lsock, GNUNET_YES); 86 GNUNET_CONNECTION_destroy (lsock, GNUNET_YES);
88 GNUNET_CONNECTION_destroy (csock, GNUNET_YES); 87 GNUNET_CONNECTION_destroy (csock, GNUNET_YES);
89 return 0; 88 return 0;
90 } 89 }
91#if VERBOSE 90#if VERBOSE
92 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending kilo to fill buffer.\n"); 91 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending kilo to fill buffer.\n");
93#endif 92#endif
@@ -95,9 +94,9 @@ send_kilo (void *cls, size_t size, void *buf)
95 memset (buf, 42, 1024); 94 memset (buf, 42, 1024);
96 95
97 GNUNET_assert (NULL != 96 GNUNET_assert (NULL !=
98 GNUNET_CONNECTION_notify_transmit_ready (csock, 1024, 97 GNUNET_CONNECTION_notify_transmit_ready (csock, 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;
102} 101}
103 102
@@ -112,9 +111,9 @@ 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, 1024, 114 GNUNET_CONNECTION_notify_transmit_ready (csock, 1024,
116 GNUNET_TIME_UNIT_SECONDS, 115 GNUNET_TIME_UNIT_SECONDS,
117 &send_kilo, cls)); 116 &send_kilo, cls));
118} 117}
119 118
120 119
@@ -130,7 +129,7 @@ check_timeout ()
130 ok = 1; 129 ok = 1;
131 cfg = GNUNET_CONFIGURATION_create (); 130 cfg = GNUNET_CONFIGURATION_create ();
132 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", 131 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
133 "localhost"); 132 "localhost");
134 GNUNET_SCHEDULER_run (&task_timeout, &ok); 133 GNUNET_SCHEDULER_run (&task_timeout, &ok);
135 GNUNET_CONFIGURATION_destroy (cfg); 134 GNUNET_CONFIGURATION_destroy (cfg);
136 return ok; 135 return ok;
@@ -143,11 +142,11 @@ main (int argc, char *argv[])
143 142
144 GNUNET_log_setup ("test_connection_timeout", 143 GNUNET_log_setup ("test_connection_timeout",
145#if VERBOSE 144#if VERBOSE
146 "DEBUG", 145 "DEBUG",
147#else 146#else
148 "WARNING", 147 "WARNING",
149#endif 148#endif
150 NULL); 149 NULL);
151 ret += check_timeout (); 150 ret += check_timeout ();
152 return ret; 151 return ret;
153} 152}
diff --git a/src/util/test_connection_timeout_no_connect.c b/src/util/test_connection_timeout_no_connect.c
index 00b247c52..b598907ec 100644
--- a/src/util/test_connection_timeout_no_connect.c
+++ b/src/util/test_connection_timeout_no_connect.c
@@ -57,10 +57,10 @@ task_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
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, 1024, 60 GNUNET_CONNECTION_notify_transmit_ready (csock, 1024,
61 GNUNET_TIME_UNIT_SECONDS, 61 GNUNET_TIME_UNIT_SECONDS,
62 &handle_timeout, 62 &handle_timeout,
63 cls)); 63 cls));
64} 64}
65 65
66 66
@@ -76,7 +76,7 @@ check_timeout ()
76 ok = 1; 76 ok = 1;
77 cfg = GNUNET_CONFIGURATION_create (); 77 cfg = GNUNET_CONFIGURATION_create ();
78 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", 78 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
79 "localhost"); 79 "localhost");
80 GNUNET_SCHEDULER_run (&task_timeout, &ok); 80 GNUNET_SCHEDULER_run (&task_timeout, &ok);
81 GNUNET_CONFIGURATION_destroy (cfg); 81 GNUNET_CONFIGURATION_destroy (cfg);
82 return ok; 82 return ok;
@@ -89,11 +89,11 @@ main (int argc, char *argv[])
89 89
90 GNUNET_log_setup ("test_connection_timeout_no_connect", 90 GNUNET_log_setup ("test_connection_timeout_no_connect",
91#if VERBOSE 91#if VERBOSE
92 "DEBUG", 92 "DEBUG",
93#else 93#else
94 "WARNING", 94 "WARNING",
95#endif 95#endif
96 NULL); 96 NULL);
97 ret += check_timeout (); 97 ret += check_timeout ();
98 return ret; 98 return ret;
99} 99}
diff --git a/src/util/test_connection_transmit_cancel.c b/src/util/test_connection_transmit_cancel.c
index 540d8c51d..50308a2d0 100644
--- a/src/util/test_connection_transmit_cancel.c
+++ b/src/util/test_connection_transmit_cancel.c
@@ -43,8 +43,7 @@ not_run (void *cls, size_t size, void *buf)
43 43
44 44
45static void 45static void
46task_transmit_cancel (void *cls, 46task_transmit_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
47 const struct GNUNET_SCHEDULER_TaskContext *tc)
48{ 47{
49 int *ok = cls; 48 int *ok = cls;
50 struct GNUNET_CONNECTION_TransmitHandle *th; 49 struct GNUNET_CONNECTION_TransmitHandle *th;
@@ -53,8 +52,8 @@ task_transmit_cancel (void *cls,
53 csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT); 52 csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT);
54 GNUNET_assert (csock != NULL); 53 GNUNET_assert (csock != NULL);
55 th = GNUNET_CONNECTION_notify_transmit_ready (csock, 12, 54 th = GNUNET_CONNECTION_notify_transmit_ready (csock, 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);
59 GNUNET_CONNECTION_notify_transmit_ready_cancel (th); 58 GNUNET_CONNECTION_notify_transmit_ready_cancel (th);
60 GNUNET_CONNECTION_destroy (csock, GNUNET_YES); 59 GNUNET_CONNECTION_destroy (csock, GNUNET_YES);
@@ -75,7 +74,7 @@ check_transmit_cancel ()
75 ok = 1; 74 ok = 1;
76 cfg = GNUNET_CONFIGURATION_create (); 75 cfg = GNUNET_CONFIGURATION_create ();
77 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", 76 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
78 "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;
@@ -89,11 +88,11 @@ main (int argc, char *argv[])
89 88
90 GNUNET_log_setup ("test_connection_transmit_cancel", 89 GNUNET_log_setup ("test_connection_transmit_cancel",
91#if VERBOSE 90#if VERBOSE
92 "DEBUG", 91 "DEBUG",
93#else 92#else
94 "WARNING", 93 "WARNING",
95#endif 94#endif
96 NULL); 95 NULL);
97 ret += check_transmit_cancel (); 96 ret += check_transmit_cancel ();
98 97
99 return ret; 98 return ret;
diff --git a/src/util/test_container_bloomfilter.c b/src/util/test_container_bloomfilter.c
index 04bb34889..c14adb075 100644
--- a/src/util/test_container_bloomfilter.c
+++ b/src/util/test_container_bloomfilter.c
@@ -75,30 +75,29 @@ main (int argc, char *argv[])
75 bf = GNUNET_CONTAINER_bloomfilter_load (TESTFILE, SIZE, K); 75 bf = GNUNET_CONTAINER_bloomfilter_load (TESTFILE, SIZE, K);
76 76
77 for (i = 0; i < 200; i++) 77 for (i = 0; i < 200; i++)
78 { 78 {
79 nextHC (&tmp); 79 nextHC (&tmp);
80 GNUNET_CONTAINER_bloomfilter_add (bf, &tmp); 80 GNUNET_CONTAINER_bloomfilter_add (bf, &tmp);
81 } 81 }
82 SRANDOM (1); 82 SRANDOM (1);
83 ok1 = 0; 83 ok1 = 0;
84 for (i = 0; i < 200; i++) 84 for (i = 0; i < 200; i++)
85 { 85 {
86 nextHC (&tmp); 86 nextHC (&tmp);
87 if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES) 87 if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES)
88 ok1++; 88 ok1++;
89 } 89 }
90 if (ok1 != 200) 90 if (ok1 != 200)
91 { 91 {
92 printf ("Got %d elements out of" "200 expected after insertion.\n", 92 printf ("Got %d elements out of" "200 expected after insertion.\n", ok1);
93 ok1); 93 GNUNET_CONTAINER_bloomfilter_free (bf);
94 GNUNET_CONTAINER_bloomfilter_free (bf); 94 return -1;
95 return -1; 95 }
96 }
97 if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_get_raw_data (bf, buf, SIZE)) 96 if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_get_raw_data (bf, buf, SIZE))
98 { 97 {
99 GNUNET_CONTAINER_bloomfilter_free (bf); 98 GNUNET_CONTAINER_bloomfilter_free (bf);
100 return -1; 99 return -1;
101 } 100 }
102 101
103 GNUNET_CONTAINER_bloomfilter_free (bf); 102 GNUNET_CONTAINER_bloomfilter_free (bf);
104 103
@@ -111,94 +110,93 @@ main (int argc, char *argv[])
111 ok1 = 0; 110 ok1 = 0;
112 ok2 = 0; 111 ok2 = 0;
113 for (i = 0; i < 200; i++) 112 for (i = 0; i < 200; i++)
114 { 113 {
115 nextHC (&tmp); 114 nextHC (&tmp);
116 if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES) 115 if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES)
117 ok1++; 116 ok1++;
118 if (GNUNET_CONTAINER_bloomfilter_test (bfi, &tmp) == GNUNET_YES) 117 if (GNUNET_CONTAINER_bloomfilter_test (bfi, &tmp) == GNUNET_YES)
119 ok2++; 118 ok2++;
120 } 119 }
121 if (ok1 != 200) 120 if (ok1 != 200)
122 { 121 {
123 printf ("Got %d elements out of 200 " "expected after reloading.\n", 122 printf ("Got %d elements out of 200 " "expected after reloading.\n", ok1);
124 ok1); 123 GNUNET_CONTAINER_bloomfilter_free (bf);
125 GNUNET_CONTAINER_bloomfilter_free (bf); 124 GNUNET_CONTAINER_bloomfilter_free (bfi);
126 GNUNET_CONTAINER_bloomfilter_free (bfi); 125 return -1;
127 return -1; 126 }
128 }
129 127
130 if (ok2 != 200) 128 if (ok2 != 200)
131 { 129 {
132 printf ("Got %d elements out of 200 " 130 printf ("Got %d elements out of 200 " "expected after initialization.\n",
133 "expected after initialization.\n", ok2); 131 ok2);
134 GNUNET_CONTAINER_bloomfilter_free (bf); 132 GNUNET_CONTAINER_bloomfilter_free (bf);
135 GNUNET_CONTAINER_bloomfilter_free (bfi); 133 GNUNET_CONTAINER_bloomfilter_free (bfi);
136 return -1; 134 return -1;
137 } 135 }
138 136
139 SRANDOM (1); 137 SRANDOM (1);
140 for (i = 0; i < 100; i++) 138 for (i = 0; i < 100; i++)
141 { 139 {
142 nextHC (&tmp); 140 nextHC (&tmp);
143 GNUNET_CONTAINER_bloomfilter_remove (bf, &tmp); 141 GNUNET_CONTAINER_bloomfilter_remove (bf, &tmp);
144 GNUNET_CONTAINER_bloomfilter_remove (bfi, &tmp); 142 GNUNET_CONTAINER_bloomfilter_remove (bfi, &tmp);
145 } 143 }
146 144
147 SRANDOM (1); 145 SRANDOM (1);
148 146
149 ok1 = 0; 147 ok1 = 0;
150 ok2 = 0; 148 ok2 = 0;
151 for (i = 0; i < 200; i++) 149 for (i = 0; i < 200; i++)
152 { 150 {
153 nextHC (&tmp); 151 nextHC (&tmp);
154 if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES) 152 if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES)
155 ok1++; 153 ok1++;
156 if (GNUNET_CONTAINER_bloomfilter_test (bfi, &tmp) == GNUNET_YES) 154 if (GNUNET_CONTAINER_bloomfilter_test (bfi, &tmp) == GNUNET_YES)
157 ok2++; 155 ok2++;
158 } 156 }
159 157
160 if (ok1 != 100) 158 if (ok1 != 100)
161 { 159 {
162 printf ("Expected 100 elements in loaded filter" 160 printf ("Expected 100 elements in loaded filter"
163 " after adding 200 and deleting 100, got %d\n", ok1); 161 " after adding 200 and deleting 100, got %d\n", ok1);
164 GNUNET_CONTAINER_bloomfilter_free (bf); 162 GNUNET_CONTAINER_bloomfilter_free (bf);
165 GNUNET_CONTAINER_bloomfilter_free (bfi); 163 GNUNET_CONTAINER_bloomfilter_free (bfi);
166 return -1; 164 return -1;
167 } 165 }
168 if (ok2 != 200) 166 if (ok2 != 200)
169 { 167 {
170 printf ("Expected 200 elements in initialized filter" 168 printf ("Expected 200 elements in initialized filter"
171 " after adding 200 and deleting 100 " 169 " after adding 200 and deleting 100 "
172 "(which should do nothing for a filter not backed by a file), got %d\n", 170 "(which should do nothing for a filter not backed by a file), got %d\n",
173 ok2); 171 ok2);
174 GNUNET_CONTAINER_bloomfilter_free (bf); 172 GNUNET_CONTAINER_bloomfilter_free (bf);
175 GNUNET_CONTAINER_bloomfilter_free (bfi); 173 GNUNET_CONTAINER_bloomfilter_free (bfi);
176 return -1; 174 return -1;
177 } 175 }
178 176
179 SRANDOM (3); 177 SRANDOM (3);
180 178
181 GNUNET_CONTAINER_bloomfilter_clear (bf); 179 GNUNET_CONTAINER_bloomfilter_clear (bf);
182 falseok = 0; 180 falseok = 0;
183 for (i = 0; i < 1000; i++) 181 for (i = 0; i < 1000; i++)
184 { 182 {
185 nextHC (&tmp); 183 nextHC (&tmp);
186 if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES) 184 if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES)
187 falseok++; 185 falseok++;
188 } 186 }
189 if (falseok > 0) 187 if (falseok > 0)
190 { 188 {
191 GNUNET_CONTAINER_bloomfilter_free (bf); 189 GNUNET_CONTAINER_bloomfilter_free (bf);
192 GNUNET_CONTAINER_bloomfilter_free (bfi); 190 GNUNET_CONTAINER_bloomfilter_free (bfi);
193 return -1; 191 return -1;
194 } 192 }
195 193
196 if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_or (bf, buf, SIZE)) 194 if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_or (bf, buf, SIZE))
197 { 195 {
198 GNUNET_CONTAINER_bloomfilter_free (bf); 196 GNUNET_CONTAINER_bloomfilter_free (bf);
199 GNUNET_CONTAINER_bloomfilter_free (bfi); 197 GNUNET_CONTAINER_bloomfilter_free (bfi);
200 return -1; 198 return -1;
201 } 199 }
202 200
203 SRANDOM (2); 201 SRANDOM (2);
204 i = 20; 202 i = 20;
@@ -212,30 +210,30 @@ main (int argc, char *argv[])
212 ok1 = 0; 210 ok1 = 0;
213 ok2 = 0; 211 ok2 = 0;
214 for (i = 0; i < 20; i++) 212 for (i = 0; i < 20; i++)
215 { 213 {
216 nextHC (&tmp); 214 nextHC (&tmp);
217 if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES) 215 if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES)
218 ok1++; 216 ok1++;
219 if (GNUNET_CONTAINER_bloomfilter_test (bfi, &tmp) == GNUNET_YES) 217 if (GNUNET_CONTAINER_bloomfilter_test (bfi, &tmp) == GNUNET_YES)
220 ok2++; 218 ok2++;
221 } 219 }
222 220
223 if (ok1 != 20) 221 if (ok1 != 20)
224 { 222 {
225 printf ("Expected 20 elements in resized file-backed filter" 223 printf ("Expected 20 elements in resized file-backed filter"
226 " after adding 20, got %d\n", ok1); 224 " after adding 20, got %d\n", ok1);
227 GNUNET_CONTAINER_bloomfilter_free (bf); 225 GNUNET_CONTAINER_bloomfilter_free (bf);
228 GNUNET_CONTAINER_bloomfilter_free (bfi); 226 GNUNET_CONTAINER_bloomfilter_free (bfi);
229 return -1; 227 return -1;
230 } 228 }
231 if (ok2 != 20) 229 if (ok2 != 20)
232 { 230 {
233 printf ("Expected 20 elements in resized filter" 231 printf ("Expected 20 elements in resized filter"
234 " after adding 20, got %d\n", ok2); 232 " after adding 20, got %d\n", ok2);
235 GNUNET_CONTAINER_bloomfilter_free (bf); 233 GNUNET_CONTAINER_bloomfilter_free (bf);
236 GNUNET_CONTAINER_bloomfilter_free (bfi); 234 GNUNET_CONTAINER_bloomfilter_free (bfi);
237 return -1; 235 return -1;
238 } 236 }
239 237
240 238
241 GNUNET_CONTAINER_bloomfilter_free (bf); 239 GNUNET_CONTAINER_bloomfilter_free (bf);
diff --git a/src/util/test_container_heap.c b/src/util/test_container_heap.c
index c1c4eb360..a2a004aa7 100644
--- a/src/util/test_container_heap.c
+++ b/src/util/test_container_heap.c
@@ -30,7 +30,7 @@
30 30
31static int 31static int
32iterator_callback (void *cls, struct GNUNET_CONTAINER_HeapNode *node, 32iterator_callback (void *cls, struct GNUNET_CONTAINER_HeapNode *node,
33 void *element, GNUNET_CONTAINER_HeapCostType cost) 33 void *element, GNUNET_CONTAINER_HeapCostType cost)
34{ 34{
35 return GNUNET_OK; 35 return GNUNET_OK;
36} 36}
@@ -107,15 +107,15 @@ check ()
107 n6 = GNUNET_CONTAINER_heap_insert (myHeap, "30/200", 30); 107 n6 = GNUNET_CONTAINER_heap_insert (myHeap, "30/200", 30);
108 GNUNET_assert (5 == GNUNET_CONTAINER_heap_get_size (myHeap)); 108 GNUNET_assert (5 == GNUNET_CONTAINER_heap_get_size (myHeap));
109 GNUNET_CONTAINER_heap_remove_node (n5); 109 GNUNET_CONTAINER_heap_remove_node (n5);
110 r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n1 */ 110 r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n1 */
111 GNUNET_assert (NULL != r); 111 GNUNET_assert (NULL != r);
112 GNUNET_assert (0 == strcmp ("11", r)); 112 GNUNET_assert (0 == strcmp ("11", r));
113 GNUNET_CONTAINER_heap_update_cost (myHeap, n6, 200); 113 GNUNET_CONTAINER_heap_update_cost (myHeap, n6, 200);
114 GNUNET_CONTAINER_heap_remove_node (n3); 114 GNUNET_CONTAINER_heap_remove_node (n3);
115 r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n4 */ 115 r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n4 */
116 GNUNET_assert (NULL != r); 116 GNUNET_assert (NULL != r);
117 GNUNET_assert (0 == strcmp ("50", r)); 117 GNUNET_assert (0 == strcmp ("50", r));
118 r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n6 */ 118 r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n6 */
119 GNUNET_assert (NULL != r); 119 GNUNET_assert (NULL != r);
120 GNUNET_assert (0 == strcmp ("30/200", r)); 120 GNUNET_assert (0 == strcmp ("30/200", r));
121 GNUNET_assert (0 == GNUNET_CONTAINER_heap_get_size (myHeap)); 121 GNUNET_assert (0 == GNUNET_CONTAINER_heap_get_size (myHeap));
@@ -172,9 +172,9 @@ check ()
172 172
173 GNUNET_assert (0 == nstrcmp ("20", GNUNET_CONTAINER_heap_remove_node (n2))); 173 GNUNET_assert (0 == nstrcmp ("20", GNUNET_CONTAINER_heap_remove_node (n2)));
174 GNUNET_assert (0 == 174 GNUNET_assert (0 ==
175 nstrcmp ("10", GNUNET_CONTAINER_heap_remove_root (myHeap))); 175 nstrcmp ("10", GNUNET_CONTAINER_heap_remove_root (myHeap)));
176 GNUNET_assert (0 == 176 GNUNET_assert (0 ==
177 nstrcmp ("30", GNUNET_CONTAINER_heap_remove_root (myHeap))); 177 nstrcmp ("30", GNUNET_CONTAINER_heap_remove_root (myHeap)));
178 178
179 n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); 179 n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10);
180 n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 20); 180 n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 20);
@@ -232,7 +232,7 @@ check ()
232 GNUNET_CONTAINER_heap_remove_node (n2); 232 GNUNET_CONTAINER_heap_remove_node (n2);
233 GNUNET_CONTAINER_heap_remove_node (n1); 233 GNUNET_CONTAINER_heap_remove_node (n1);
234 GNUNET_assert (0 == 234 GNUNET_assert (0 ==
235 nstrcmp ("30", GNUNET_CONTAINER_heap_remove_root (myHeap))); 235 nstrcmp ("30", GNUNET_CONTAINER_heap_remove_root (myHeap)));
236 236
237 n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); 237 n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10);
238 n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10); 238 n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10);
diff --git a/src/util/test_container_meta_data.c b/src/util/test_container_meta_data.c
index 66f90ff10..fe1dd79c1 100644
--- a/src/util/test_container_meta_data.c
+++ b/src/util/test_container_meta_data.c
@@ -41,55 +41,51 @@ testMeta (int i)
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, "<test>", 44 GNUNET_CONTAINER_meta_data_insert (m, "<test>", EXTRACTOR_METATYPE_TITLE,
45 EXTRACTOR_METATYPE_TITLE, 45 EXTRACTOR_METAFORMAT_UTF8,
46 EXTRACTOR_METAFORMAT_UTF8, 46 "text/plain", "TestTitle",
47 "text/plain", "TestTitle", 47 strlen ("TestTitle") + 1))
48 strlen ("TestTitle") + 1))
49 ABORT (m); 48 ABORT (m);
50 if (GNUNET_OK != 49 if (GNUNET_OK !=
51 GNUNET_CONTAINER_meta_data_insert (m, "<test>", 50 GNUNET_CONTAINER_meta_data_insert (m, "<test>",
52 EXTRACTOR_METATYPE_AUTHOR_NAME, 51 EXTRACTOR_METATYPE_AUTHOR_NAME,
53 EXTRACTOR_METAFORMAT_UTF8, 52 EXTRACTOR_METAFORMAT_UTF8,
54 "text/plain", "TestTitle", 53 "text/plain", "TestTitle",
55 strlen ("TestTitle") + 1)) 54 strlen ("TestTitle") + 1))
56 ABORT (m); 55 ABORT (m);
57 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! */
58 ABORT (m); 57 ABORT (m);
59 if (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (m, "<test>", EXTRACTOR_METATYPE_AUTHOR_NAME, EXTRACTOR_METAFORMAT_UTF8, "text/plain", "TestTitle", strlen ("TestTitle") + 1)) /* dup! */ 58 if (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (m, "<test>", EXTRACTOR_METATYPE_AUTHOR_NAME, EXTRACTOR_METAFORMAT_UTF8, "text/plain", "TestTitle", strlen ("TestTitle") + 1)) /* dup! */
60 ABORT (m); 59 ABORT (m);
61 if (2 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL)) 60 if (2 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL))
62 ABORT (m); 61 ABORT (m);
63 if (GNUNET_OK != 62 if (GNUNET_OK !=
64 GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_AUTHOR_NAME, 63 GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_AUTHOR_NAME,
65 "TestTitle", 64 "TestTitle", strlen ("TestTitle") + 1))
66 strlen ("TestTitle") + 1))
67 ABORT (m); 65 ABORT (m);
68 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 */
69 ABORT (m); 67 ABORT (m);
70 if (1 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL)) 68 if (1 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL))
71 ABORT (m); 69 ABORT (m);
72 if (GNUNET_OK != 70 if (GNUNET_OK !=
73 GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_TITLE, 71 GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_TITLE,
74 "TestTitle", 72 "TestTitle", strlen ("TestTitle") + 1))
75 strlen ("TestTitle") + 1))
76 ABORT (m); 73 ABORT (m);
77 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 */
78 ABORT (m); 75 ABORT (m);
79 if (0 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL)) 76 if (0 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL))
80 ABORT (m); 77 ABORT (m);
81 for (j = 0; j < i; j++) 78 for (j = 0; j < i; j++)
82 { 79 {
83 GNUNET_snprintf (val, sizeof (val), "%s.%d", 80 GNUNET_snprintf (val, sizeof (val), "%s.%d",
84 "A teststring that should compress well.", j); 81 "A teststring that should compress well.", j);
85 if (GNUNET_OK != 82 if (GNUNET_OK !=
86 GNUNET_CONTAINER_meta_data_insert (m, "<test>", 83 GNUNET_CONTAINER_meta_data_insert (m, "<test>",
87 EXTRACTOR_METATYPE_UNKNOWN, 84 EXTRACTOR_METATYPE_UNKNOWN,
88 EXTRACTOR_METAFORMAT_UTF8, 85 EXTRACTOR_METAFORMAT_UTF8,
89 "text/plain", val, 86 "text/plain", val, strlen (val) + 1))
90 strlen (val) + 1)) 87 ABORT (m);
91 ABORT (m); 88 }
92 }
93 if (i != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL)) 89 if (i != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL))
94 ABORT (m); 90 ABORT (m);
95 91
@@ -97,27 +93,27 @@ testMeta (int i)
97 sval = NULL; 93 sval = NULL;
98 if (size != 94 if (size !=
99 GNUNET_CONTAINER_meta_data_serialize (m, &sval, size, 95 GNUNET_CONTAINER_meta_data_serialize (m, &sval, size,
100 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL)) 96 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL))
101 { 97 {
102 GNUNET_free_non_null (sval); 98 GNUNET_free_non_null (sval);
103 ABORT (m); 99 ABORT (m);
104 } 100 }
105 GNUNET_CONTAINER_meta_data_destroy (m); 101 GNUNET_CONTAINER_meta_data_destroy (m);
106 m = GNUNET_CONTAINER_meta_data_deserialize (sval, size); 102 m = GNUNET_CONTAINER_meta_data_deserialize (sval, size);
107 GNUNET_free (sval); 103 GNUNET_free (sval);
108 if (m == NULL) 104 if (m == NULL)
109 ABORT (m); 105 ABORT (m);
110 for (j = 0; j < i; j++) 106 for (j = 0; j < i; j++)
107 {
108 GNUNET_snprintf (val, sizeof (val), "%s.%d",
109 "A teststring that should compress well.", j);
110 if (GNUNET_OK !=
111 GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_UNKNOWN, val,
112 strlen (val) + 1))
111 { 113 {
112 GNUNET_snprintf (val, sizeof (val), "%s.%d", 114 ABORT (m);
113 "A teststring that should compress well.", j);
114 if (GNUNET_OK !=
115 GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_UNKNOWN,
116 val, strlen (val) + 1))
117 {
118 ABORT (m);
119 }
120 } 115 }
116 }
121 if (0 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL)) 117 if (0 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL))
122 ABORT (m); 118 ABORT (m);
123 GNUNET_CONTAINER_meta_data_destroy (m); 119 GNUNET_CONTAINER_meta_data_destroy (m);
@@ -135,22 +131,22 @@ testMetaMore (int i)
135 131
136 meta = GNUNET_CONTAINER_meta_data_create (); 132 meta = GNUNET_CONTAINER_meta_data_create ();
137 for (q = 0; q <= i; q++) 133 for (q = 0; q <= i; q++)
138 { 134 {
139 GNUNET_snprintf (txt, 128, "%u -- %u\n", i, q); 135 GNUNET_snprintf (txt, 128, "%u -- %u\n", i, q);
140 GNUNET_CONTAINER_meta_data_insert (meta, "<test>", 136 GNUNET_CONTAINER_meta_data_insert (meta, "<test>",
141 q % EXTRACTOR_metatype_get_max (), 137 q % EXTRACTOR_metatype_get_max (),
142 EXTRACTOR_METAFORMAT_UTF8, 138 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
143 "text/plain", txt, strlen (txt) + 1); 139 txt, strlen (txt) + 1);
144 } 140 }
145 size = GNUNET_CONTAINER_meta_data_get_serialized_size (meta); 141 size = GNUNET_CONTAINER_meta_data_get_serialized_size (meta);
146 data = GNUNET_malloc (size * 4); 142 data = GNUNET_malloc (size * 4);
147 if (size != 143 if (size !=
148 GNUNET_CONTAINER_meta_data_serialize (meta, &data, size * 4, 144 GNUNET_CONTAINER_meta_data_serialize (meta, &data, size * 4,
149 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL)) 145 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL))
150 { 146 {
151 GNUNET_free (data); 147 GNUNET_free (data);
152 ABORT (meta); 148 ABORT (meta);
153 } 149 }
154 GNUNET_CONTAINER_meta_data_destroy (meta); 150 GNUNET_CONTAINER_meta_data_destroy (meta);
155 GNUNET_free (data); 151 GNUNET_free (data);
156 return 0; 152 return 0;
@@ -166,22 +162,22 @@ testMetaLink ()
166 m = GNUNET_CONTAINER_meta_data_create (); 162 m = GNUNET_CONTAINER_meta_data_create ();
167 if (GNUNET_OK != 163 if (GNUNET_OK !=
168 GNUNET_CONTAINER_meta_data_insert (m, "<test>", 164 GNUNET_CONTAINER_meta_data_insert (m, "<test>",
169 EXTRACTOR_METATYPE_UNKNOWN, 165 EXTRACTOR_METATYPE_UNKNOWN,
170 EXTRACTOR_METAFORMAT_UTF8, 166 EXTRACTOR_METAFORMAT_UTF8,
171 "text/plain", "link", 167 "text/plain", "link",
172 strlen ("link") + 1)) 168 strlen ("link") + 1))
173 ABORT (m); 169 ABORT (m);
174 if (GNUNET_OK != 170 if (GNUNET_OK !=
175 GNUNET_CONTAINER_meta_data_insert (m, "<test>", 171 GNUNET_CONTAINER_meta_data_insert (m, "<test>",
176 EXTRACTOR_METATYPE_FILENAME, 172 EXTRACTOR_METATYPE_FILENAME,
177 EXTRACTOR_METAFORMAT_UTF8, 173 EXTRACTOR_METAFORMAT_UTF8,
178 "text/plain", "lib-link.m4", 174 "text/plain", "lib-link.m4",
179 strlen ("lib-link.m4") + 1)) 175 strlen ("lib-link.m4") + 1))
180 ABORT (m); 176 ABORT (m);
181 val = NULL; 177 val = NULL;
182 size = 178 size =
183 GNUNET_CONTAINER_meta_data_serialize (m, &val, (size_t) - 1, 179 GNUNET_CONTAINER_meta_data_serialize (m, &val, (size_t) - 1,
184 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL); 180 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL);
185 GNUNET_CONTAINER_meta_data_destroy (m); 181 GNUNET_CONTAINER_meta_data_destroy (m);
186 m = GNUNET_CONTAINER_meta_data_deserialize (val, size); 182 m = GNUNET_CONTAINER_meta_data_deserialize (val, size);
187 GNUNET_free (val); 183 GNUNET_free (val);
@@ -205,46 +201,44 @@ check ()
205 meta = GNUNET_CONTAINER_meta_data_create (); 201 meta = GNUNET_CONTAINER_meta_data_create ();
206 meta2 = GNUNET_CONTAINER_meta_data_create (); 202 meta2 = GNUNET_CONTAINER_meta_data_create ();
207 for (q = 0; q <= i; q++) 203 for (q = 0; q <= i; q++)
208 { 204 {
209 GNUNET_snprintf (txt, 128, "%u -- %u\n", i, q); 205 GNUNET_snprintf (txt, 128, "%u -- %u\n", i, q);
210 GNUNET_CONTAINER_meta_data_insert (meta, "<test>", 206 GNUNET_CONTAINER_meta_data_insert (meta, "<test>",
211 EXTRACTOR_METATYPE_UNKNOWN, 207 EXTRACTOR_METATYPE_UNKNOWN,
212 EXTRACTOR_METAFORMAT_UTF8, 208 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
213 "text/plain", "TestTitle", 209 "TestTitle", strlen ("TestTitle") + 1);
214 strlen ("TestTitle") + 1); 210 GNUNET_CONTAINER_meta_data_insert (meta2, "<test>",
215 GNUNET_CONTAINER_meta_data_insert (meta2, "<test>", 211 EXTRACTOR_METATYPE_UNKNOWN,
216 EXTRACTOR_METATYPE_UNKNOWN, 212 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
217 EXTRACTOR_METAFORMAT_UTF8, 213 "TestTitle", strlen ("TestTitle") + 1);
218 "text/plain", "TestTitle", 214 }
219 strlen ("TestTitle") + 1);
220 }
221 215
222 //check meta_data_test_equal 216 //check meta_data_test_equal
223 if (GNUNET_YES != GNUNET_CONTAINER_meta_data_test_equal (meta, meta2)) 217 if (GNUNET_YES != GNUNET_CONTAINER_meta_data_test_equal (meta, meta2))
224 { 218 {
225 GNUNET_CONTAINER_meta_data_destroy (meta2); 219 GNUNET_CONTAINER_meta_data_destroy (meta2);
226 ABORT (meta); 220 ABORT (meta);
227 } 221 }
228 222
229 //check meta_data_clear 223 //check meta_data_clear
230 GNUNET_CONTAINER_meta_data_clear (meta2); 224 GNUNET_CONTAINER_meta_data_clear (meta2);
231 if (0 != GNUNET_CONTAINER_meta_data_iterate (meta2, NULL, NULL)) 225 if (0 != GNUNET_CONTAINER_meta_data_iterate (meta2, NULL, NULL))
232 { 226 {
233 GNUNET_CONTAINER_meta_data_destroy (meta2); 227 GNUNET_CONTAINER_meta_data_destroy (meta2);
234 ABORT (meta); 228 ABORT (meta);
235 } 229 }
236 // check equal branch in meta_data_test_equal 230 // check equal branch in meta_data_test_equal
237 if (GNUNET_YES != GNUNET_CONTAINER_meta_data_test_equal (meta, meta)) 231 if (GNUNET_YES != GNUNET_CONTAINER_meta_data_test_equal (meta, meta))
238 { 232 {
239 GNUNET_CONTAINER_meta_data_destroy (meta2); 233 GNUNET_CONTAINER_meta_data_destroy (meta2);
240 ABORT (meta); 234 ABORT (meta);
241 } 235 }
242 // check "count" branch in meta_data_test_equal 236 // check "count" branch in meta_data_test_equal
243 if (GNUNET_NO != GNUNET_CONTAINER_meta_data_test_equal (meta, meta2)) 237 if (GNUNET_NO != GNUNET_CONTAINER_meta_data_test_equal (meta, meta2))
244 { 238 {
245 GNUNET_CONTAINER_meta_data_destroy (meta2); 239 GNUNET_CONTAINER_meta_data_destroy (meta2);
246 ABORT (meta); 240 ABORT (meta);
247 } 241 }
248 242
249 // check meta_data_add_publication_date 243 // check meta_data_add_publication_date
250 GNUNET_CONTAINER_meta_data_add_publication_date (meta2); 244 GNUNET_CONTAINER_meta_data_add_publication_date (meta2);
@@ -253,74 +247,74 @@ check ()
253 GNUNET_CONTAINER_meta_data_clear (meta2); 247 GNUNET_CONTAINER_meta_data_clear (meta2);
254 GNUNET_CONTAINER_meta_data_merge (meta2, meta); 248 GNUNET_CONTAINER_meta_data_merge (meta2, meta);
255 if (100 == GNUNET_CONTAINER_meta_data_iterate (meta2, NULL, NULL)) 249 if (100 == GNUNET_CONTAINER_meta_data_iterate (meta2, NULL, NULL))
256 { 250 {
257 GNUNET_CONTAINER_meta_data_destroy (meta2); 251 GNUNET_CONTAINER_meta_data_destroy (meta2);
258 ABORT (meta); 252 ABORT (meta);
259 } 253 }
260 254
261 // check meta_data_get_by_type 255 // check meta_data_get_by_type
262 GNUNET_CONTAINER_meta_data_clear (meta2); 256 GNUNET_CONTAINER_meta_data_clear (meta2);
263 if (NULL != 257 if (NULL !=
264 (str = 258 (str =
265 GNUNET_CONTAINER_meta_data_get_by_type (meta2, 259 GNUNET_CONTAINER_meta_data_get_by_type (meta2,
266 EXTRACTOR_METATYPE_UNKNOWN))) 260 EXTRACTOR_METATYPE_UNKNOWN)))
267 { 261 {
268 GNUNET_CONTAINER_meta_data_destroy (meta2); 262 GNUNET_CONTAINER_meta_data_destroy (meta2);
269 GNUNET_free (str); 263 GNUNET_free (str);
270 ABORT (meta); 264 ABORT (meta);
271 } 265 }
272 266
273 str = 267 str =
274 GNUNET_CONTAINER_meta_data_get_by_type (meta, EXTRACTOR_METATYPE_UNKNOWN); 268 GNUNET_CONTAINER_meta_data_get_by_type (meta, EXTRACTOR_METATYPE_UNKNOWN);
275 GNUNET_assert (NULL != str); 269 GNUNET_assert (NULL != str);
276 if (str[0] != 'T') 270 if (str[0] != 'T')
277 { 271 {
278 GNUNET_CONTAINER_meta_data_destroy (meta2); 272 GNUNET_CONTAINER_meta_data_destroy (meta2);
279 GNUNET_free (str); 273 GNUNET_free (str);
280 ABORT (meta); 274 ABORT (meta);
281 } 275 }
282 GNUNET_free (str); 276 GNUNET_free (str);
283 277
284 // check branch 278 // check branch
285 if (NULL != 279 if (NULL !=
286 (str = 280 (str =
287 GNUNET_CONTAINER_meta_data_get_by_type (meta, 281 GNUNET_CONTAINER_meta_data_get_by_type (meta,
288 EXTRACTOR_METATYPE_PUBLICATION_DATE))) 282 EXTRACTOR_METATYPE_PUBLICATION_DATE)))
289 { 283 {
290 GNUNET_free (str); 284 GNUNET_free (str);
291 GNUNET_CONTAINER_meta_data_destroy (meta2); 285 GNUNET_CONTAINER_meta_data_destroy (meta2);
292 ABORT (meta); 286 ABORT (meta);
293 } 287 }
294 288
295 //check meta_data_get_first_by_types 289 //check meta_data_get_first_by_types
296 str = 290 str =
297 GNUNET_CONTAINER_meta_data_get_first_by_types (meta, 291 GNUNET_CONTAINER_meta_data_get_first_by_types (meta,
298 EXTRACTOR_METATYPE_UNKNOWN, 292 EXTRACTOR_METATYPE_UNKNOWN,
299 -1); 293 -1);
300 GNUNET_assert (NULL != str); 294 GNUNET_assert (NULL != str);
301 if (str[0] != 'T') 295 if (str[0] != 'T')
302 { 296 {
303 GNUNET_CONTAINER_meta_data_destroy (meta2); 297 GNUNET_CONTAINER_meta_data_destroy (meta2);
304 GNUNET_free (str); 298 GNUNET_free (str);
305 ABORT (meta); 299 ABORT (meta);
306 } 300 }
307 GNUNET_free (str); 301 GNUNET_free (str);
308 302
309 //check meta_data_get_thumbnail 303 //check meta_data_get_thumbnail
310 if (GNUNET_CONTAINER_meta_data_get_thumbnail (meta, &thumb) != 0) 304 if (GNUNET_CONTAINER_meta_data_get_thumbnail (meta, &thumb) != 0)
311 { 305 {
312 GNUNET_free (thumb); 306 GNUNET_free (thumb);
313 GNUNET_CONTAINER_meta_data_destroy (meta2); 307 GNUNET_CONTAINER_meta_data_destroy (meta2);
314 ABORT (meta); 308 ABORT (meta);
315 } 309 }
316 GNUNET_CONTAINER_meta_data_destroy (meta2); 310 GNUNET_CONTAINER_meta_data_destroy (meta2);
317 //check meta_data_duplicate 311 //check meta_data_duplicate
318 meta2 = GNUNET_CONTAINER_meta_data_duplicate (meta); 312 meta2 = GNUNET_CONTAINER_meta_data_duplicate (meta);
319 if (200 == GNUNET_CONTAINER_meta_data_iterate (meta2, NULL, NULL)) 313 if (200 == GNUNET_CONTAINER_meta_data_iterate (meta2, NULL, NULL))
320 { 314 {
321 GNUNET_CONTAINER_meta_data_destroy (meta2); 315 GNUNET_CONTAINER_meta_data_destroy (meta2);
322 ABORT (meta); 316 ABORT (meta);
323 } 317 }
324 GNUNET_CONTAINER_meta_data_destroy (meta2); 318 GNUNET_CONTAINER_meta_data_destroy (meta2);
325 GNUNET_CONTAINER_meta_data_destroy (meta); 319 GNUNET_CONTAINER_meta_data_destroy (meta);
326 return 0; 320 return 0;
diff --git a/src/util/test_container_multihashmap.c b/src/util/test_container_multihashmap.c
index 5732ace93..ba621c17e 100644
--- a/src/util/test_container_multihashmap.c
+++ b/src/util/test_container_multihashmap.c
@@ -52,41 +52,38 @@ testMap (int i)
52 CHECK (0 == GNUNET_CONTAINER_multihashmap_remove_all (m, &k1)); 52 CHECK (0 == GNUNET_CONTAINER_multihashmap_remove_all (m, &k1));
53 CHECK (0 == GNUNET_CONTAINER_multihashmap_size (m)); 53 CHECK (0 == GNUNET_CONTAINER_multihashmap_size (m));
54 CHECK (0 == GNUNET_CONTAINER_multihashmap_iterate (m, NULL, NULL)); 54 CHECK (0 == GNUNET_CONTAINER_multihashmap_iterate (m, NULL, NULL));
55 CHECK (0 == 55 CHECK (0 == GNUNET_CONTAINER_multihashmap_get_multiple (m, &k1, NULL, NULL));
56 GNUNET_CONTAINER_multihashmap_get_multiple (m, &k1, NULL, NULL));
57 56
58 CHECK (GNUNET_OK == 57 CHECK (GNUNET_OK ==
59 GNUNET_CONTAINER_multihashmap_put (m, &k1, "v1", 58 GNUNET_CONTAINER_multihashmap_put (m, &k1, "v1",
60 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)); 59 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 == 64 CHECK (GNUNET_NO ==
66 GNUNET_CONTAINER_multihashmap_put (m, &k1, "v1", 65 GNUNET_CONTAINER_multihashmap_put (m, &k1, "v1",
67 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)); 66 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
68 CHECK (1 == GNUNET_CONTAINER_multihashmap_size (m)); 67 CHECK (1 == GNUNET_CONTAINER_multihashmap_size (m));
69 CHECK (GNUNET_OK == 68 CHECK (GNUNET_OK ==
70 GNUNET_CONTAINER_multihashmap_put (m, &k1, "v2", 69 GNUNET_CONTAINER_multihashmap_put (m, &k1, "v2",
71 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 70 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
72 CHECK (GNUNET_OK == 71 CHECK (GNUNET_OK ==
73 GNUNET_CONTAINER_multihashmap_put (m, &k1, "v3", 72 GNUNET_CONTAINER_multihashmap_put (m, &k1, "v3",
74 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 73 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
75 CHECK (3 == GNUNET_CONTAINER_multihashmap_size (m)); 74 CHECK (3 == GNUNET_CONTAINER_multihashmap_size (m));
76 CHECK (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (m, &k1, "v3")); 75 CHECK (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (m, &k1, "v3"));
77 CHECK (2 == GNUNET_CONTAINER_multihashmap_size (m)); 76 CHECK (2 == GNUNET_CONTAINER_multihashmap_size (m));
78 CHECK (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (m, &k1)); 77 CHECK (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (m, &k1));
79 CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (m, &k2)); 78 CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (m, &k2));
80 CHECK (2 == 79 CHECK (2 == GNUNET_CONTAINER_multihashmap_get_multiple (m, &k1, NULL, NULL));
81 GNUNET_CONTAINER_multihashmap_get_multiple (m, &k1, NULL, NULL)); 80 CHECK (0 == GNUNET_CONTAINER_multihashmap_get_multiple (m, &k2, NULL, NULL));
82 CHECK (0 ==
83 GNUNET_CONTAINER_multihashmap_get_multiple (m, &k2, NULL, NULL));
84 CHECK (2 == GNUNET_CONTAINER_multihashmap_iterate (m, NULL, NULL)); 81 CHECK (2 == GNUNET_CONTAINER_multihashmap_iterate (m, NULL, NULL));
85 CHECK (2 == GNUNET_CONTAINER_multihashmap_remove_all (m, &k1)); 82 CHECK (2 == GNUNET_CONTAINER_multihashmap_remove_all (m, &k1));
86 for (j = 0; j < 1024; j++) 83 for (j = 0; j < 1024; j++)
87 CHECK (GNUNET_OK == 84 CHECK (GNUNET_OK ==
88 GNUNET_CONTAINER_multihashmap_put (m, &k1, "v2", 85 GNUNET_CONTAINER_multihashmap_put (m, &k1, "v2",
89 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 86 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
90 GNUNET_CONTAINER_multihashmap_destroy (m); 87 GNUNET_CONTAINER_multihashmap_destroy (m);
91 return 0; 88 return 0;
92} 89}
diff --git a/src/util/test_container_slist.c b/src/util/test_container_slist.c
index 394dc4cdb..1b63d3dbc 100644
--- a/src/util/test_container_slist.c
+++ b/src/util/test_container_slist.c
@@ -46,66 +46,64 @@ main (int argc, char *argv[])
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, 50 &i, sizeof (i));
51 &i, sizeof (i));
52 GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 100); 51 GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 100);
53 52
54 for (it = GNUNET_CONTAINER_slist_begin (l), i = 99; 53 for (it = GNUNET_CONTAINER_slist_begin (l), i = 99;
55 GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES; 54 GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES;
56 GNUNET_CONTAINER_slist_next (&it), i--) 55 GNUNET_CONTAINER_slist_next (&it), i--)
56 {
57 p = GNUNET_CONTAINER_slist_get (&it, &s);
58
59 if ((p == NULL) || (i != (j = *(int *) p)) || (s != sizeof (i)))
57 { 60 {
58 p = GNUNET_CONTAINER_slist_get (&it, &s); 61 GNUNET_CONTAINER_slist_iter_destroy (&it);
59 62 GNUNET_assert (0);
60 if ((p == NULL) || (i != (j = *(int *) p)) || (s != sizeof (i)))
61 {
62 GNUNET_CONTAINER_slist_iter_destroy (&it);
63 GNUNET_assert (0);
64 }
65 j *= 2;
66 GNUNET_CONTAINER_slist_insert (&it,
67 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
68 &j, sizeof (j));
69 } 63 }
64 j *= 2;
65 GNUNET_CONTAINER_slist_insert (&it,
66 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
67 &j, sizeof (j));
68 }
70 GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 200); 69 GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 200);
71 i = 198; 70 i = 198;
72 GNUNET_assert (GNUNET_CONTAINER_slist_contains (l, &i, sizeof (i))); 71 GNUNET_assert (GNUNET_CONTAINER_slist_contains (l, &i, sizeof (i)));
73 72
74 for (it = GNUNET_CONTAINER_slist_begin (l); 73 for (it = GNUNET_CONTAINER_slist_begin (l);
75 GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES;) 74 GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES;)
76 { 75 {
77 p = GNUNET_CONTAINER_slist_get (&it, &s); 76 p = GNUNET_CONTAINER_slist_get (&it, &s);
78 GNUNET_assert (p != NULL); 77 GNUNET_assert (p != NULL);
79 GNUNET_assert (s == sizeof (i)); 78 GNUNET_assert (s == sizeof (i));
80 i = *(int *) p; 79 i = *(int *) p;
81 80
82 GNUNET_assert (GNUNET_CONTAINER_slist_next (&it) == GNUNET_YES); 81 GNUNET_assert (GNUNET_CONTAINER_slist_next (&it) == GNUNET_YES);
83 GNUNET_assert (GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES); 82 GNUNET_assert (GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES);
84 83
85 p = GNUNET_CONTAINER_slist_get (&it, &s); 84 p = GNUNET_CONTAINER_slist_get (&it, &s);
86 GNUNET_assert (p != NULL); 85 GNUNET_assert (p != NULL);
87 GNUNET_assert (s == sizeof (j)); 86 GNUNET_assert (s == sizeof (j));
88 j = *(int *) p; 87 j = *(int *) p;
89 88
90 GNUNET_assert (j * 2 == i); 89 GNUNET_assert (j * 2 == i);
91 90
92 GNUNET_CONTAINER_slist_erase (&it); 91 GNUNET_CONTAINER_slist_erase (&it);
93 } 92 }
94 GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 100); 93 GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 100);
95 i = 99; 94 i = 99;
96 GNUNET_assert (GNUNET_CONTAINER_slist_contains (l, &i, sizeof (i)) == 95 GNUNET_assert (GNUNET_CONTAINER_slist_contains (l, &i, sizeof (i)) ==
97 GNUNET_NO); 96 GNUNET_NO);
98 i = 198; 97 i = 198;
99 GNUNET_assert (GNUNET_CONTAINER_slist_contains (l, &i, sizeof (i)) == 98 GNUNET_assert (GNUNET_CONTAINER_slist_contains (l, &i, sizeof (i)) ==
100 GNUNET_YES); 99 GNUNET_YES);
101 100
102 GNUNET_CONTAINER_slist_clear (l); 101 GNUNET_CONTAINER_slist_clear (l);
103 GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 0); 102 GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 0);
104 103
105 for (i = 0; i < 100; i++) 104 for (i = 0; i < 100; i++)
106 GNUNET_CONTAINER_slist_add (l, 105 GNUNET_CONTAINER_slist_add (l, GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
107 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, 106 &i, sizeof (i));
108 &i, sizeof (i));
109 /*check slist_append */ 107 /*check slist_append */
110 GNUNET_CONTAINER_slist_append (l, l); 108 GNUNET_CONTAINER_slist_append (l, l);
111 GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 200); 109 GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 200);
@@ -116,35 +114,34 @@ main (int argc, char *argv[])
116 l = GNUNET_CONTAINER_slist_create (); 114 l = GNUNET_CONTAINER_slist_create ();
117 for (i = 0; i < 100; i++) 115 for (i = 0; i < 100; i++)
118 GNUNET_CONTAINER_slist_add_end (l, 116 GNUNET_CONTAINER_slist_add_end (l,
119 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, 117 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
120 &i, sizeof (i)); 118 &i, sizeof (i));
121 119
122 GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 100); 120 GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 100);
123 121
124 for (it = GNUNET_CONTAINER_slist_begin (l), i = 0; 122 for (it = GNUNET_CONTAINER_slist_begin (l), i = 0;
125 GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES; 123 GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES;
126 GNUNET_CONTAINER_slist_next (&it), i++) 124 GNUNET_CONTAINER_slist_next (&it), i++)
127 { 125 {
128 p = GNUNET_CONTAINER_slist_get (&it, &s); 126 p = GNUNET_CONTAINER_slist_get (&it, &s);
129 127
130 if ((p == NULL) || (i != *(int *) p) || (s != sizeof (i))) 128 if ((p == NULL) || (i != *(int *) p) || (s != sizeof (i)))
131 { 129 {
132 GNUNET_assert (0); 130 GNUNET_assert (0);
133 }
134 } 131 }
132 }
135 GNUNET_CONTAINER_slist_destroy (l); 133 GNUNET_CONTAINER_slist_destroy (l);
136 134
137 /*check if disp = GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC */ 135 /*check if disp = GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC */
138 l = GNUNET_CONTAINER_slist_create (); 136 l = GNUNET_CONTAINER_slist_create ();
139 137
140 for (i = 0; i < 100; i++) 138 for (i = 0; i < 100; i++)
141 { 139 {
142 ip = GNUNET_malloc (sizeof (int)); 140 ip = GNUNET_malloc (sizeof (int));
143 *ip = i; 141 *ip = i;
144 GNUNET_CONTAINER_slist_add (l, 142 GNUNET_CONTAINER_slist_add (l, GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC,
145 GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC, 143 ip, sizeof (int));
146 ip, sizeof (int)); 144 }
147 }
148 //creat_add 145 //creat_add
149 it = GNUNET_CONTAINER_slist_begin (l); 146 it = GNUNET_CONTAINER_slist_begin (l);
150 p = GNUNET_CONTAINER_slist_get (&it, &s); 147 p = GNUNET_CONTAINER_slist_get (&it, &s);
diff --git a/src/util/test_crypto_aes.c b/src/util/test_crypto_aes.c
index e928b96a7..971e9afbe 100644
--- a/src/util/test_crypto_aes.c
+++ b/src/util/test_crypto_aes.c
@@ -40,30 +40,30 @@ testSymcipher ()
40 40
41 GNUNET_CRYPTO_aes_create_session_key (&key); 41 GNUNET_CRYPTO_aes_create_session_key (&key);
42 size = 42 size =
43 GNUNET_CRYPTO_aes_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, &key, 43 GNUNET_CRYPTO_aes_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, &key,
44 (const struct 44 (const struct
45 GNUNET_CRYPTO_AesInitializationVector *) 45 GNUNET_CRYPTO_AesInitializationVector *)
46 INITVALUE, result); 46 INITVALUE, result);
47 if (size == -1) 47 if (size == -1)
48 { 48 {
49 printf ("symciphertest failed: encryptBlock returned %d\n", size); 49 printf ("symciphertest failed: encryptBlock returned %d\n", size);
50 return 1; 50 return 1;
51 } 51 }
52 size = 52 size =
53 GNUNET_CRYPTO_aes_decrypt (result, size, &key, 53 GNUNET_CRYPTO_aes_decrypt (result, size, &key,
54 (const struct 54 (const struct
55 GNUNET_CRYPTO_AesInitializationVector *) 55 GNUNET_CRYPTO_AesInitializationVector *)
56 INITVALUE, res); 56 INITVALUE, res);
57 if (strlen (TESTSTRING) + 1 != size) 57 if (strlen (TESTSTRING) + 1 != size)
58 { 58 {
59 printf ("symciphertest failed: decryptBlock returned %d\n", size); 59 printf ("symciphertest failed: decryptBlock returned %d\n", size);
60 return 1; 60 return 1;
61 } 61 }
62 if (0 != strcmp (res, TESTSTRING)) 62 if (0 != strcmp (res, TESTSTRING))
63 { 63 {
64 printf ("symciphertest failed: %s != %s\n", res, TESTSTRING); 64 printf ("symciphertest failed: %s != %s\n", res, TESTSTRING);
65 return 1; 65 return 1;
66 } 66 }
67 else 67 else
68 return 0; 68 return 0;
69} 69}
@@ -77,16 +77,16 @@ verifyCrypto ()
77 int ret; 77 int ret;
78 78
79 unsigned char plain[] = 79 unsigned char plain[] =
80 { 29, 128, 192, 253, 74, 171, 38, 187, 84, 219, 76, 76, 209, 118, 33, 249, 80 { 29, 128, 192, 253, 74, 171, 38, 187, 84, 219, 76, 76, 209, 118, 33, 249,
81 172, 124, 96, 9, 157, 110, 8, 215, 200, 63, 69, 230, 157, 104, 247, 164 81 172, 124, 96, 9, 157, 110, 8, 215, 200, 63, 69, 230, 157, 104, 247, 164
82 }; 82 };
83 unsigned char raw_key[] = 83 unsigned char raw_key[] =
84 { 106, 74, 209, 88, 145, 55, 189, 135, 125, 180, 225, 108, 183, 54, 25, 84 { 106, 74, 209, 88, 145, 55, 189, 135, 125, 180, 225, 108, 183, 54, 25,
85 169, 129, 188, 131, 75, 227, 245, 105, 10, 225, 15, 115, 159, 148, 184, 85 169, 129, 188, 131, 75, 227, 245, 105, 10, 225, 15, 115, 159, 148, 184,
86 34, 191 86 34, 191
87 }; 87 };
88 unsigned char encrresult[] = 88 unsigned char encrresult[] =
89 { 167, 102, 230, 233, 127, 195, 176, 107, 17, 91, 199, 127, 96, 113, 75, 89 { 167, 102, 230, 233, 127, 195, 176, 107, 17, 91, 199, 127, 96, 113, 75,
90 195, 245, 217, 61, 236, 159, 165, 103, 121, 203, 99, 202, 41, 23, 222, 25, 90 195, 245, 217, 61, 236, 159, 165, 103, 121, 203, 99, 202, 41, 23, 222, 25,
91 102 91 102
92 }; 92 };
@@ -96,54 +96,54 @@ verifyCrypto ()
96 96
97 memcpy (key.key, raw_key, GNUNET_CRYPTO_AES_KEY_LENGTH); 97 memcpy (key.key, raw_key, GNUNET_CRYPTO_AES_KEY_LENGTH);
98 key.crc32 = 98 key.crc32 =
99 htonl (GNUNET_CRYPTO_crc32_n (&key, GNUNET_CRYPTO_AES_KEY_LENGTH)); 99 htonl (GNUNET_CRYPTO_crc32_n (&key, GNUNET_CRYPTO_AES_KEY_LENGTH));
100 100
101 if (ntohl (key.crc32) != (unsigned int) 38125195LL) 101 if (ntohl (key.crc32) != (unsigned int) 38125195LL)
102 { 102 {
103 printf ("Static key has different CRC: %u - %u\n", ntohl (key.crc32), 103 printf ("Static key has different CRC: %u - %u\n", ntohl (key.crc32),
104 key.crc32); 104 key.crc32);
105 105
106 ret = 1; 106 ret = 1;
107 goto error; 107 goto error;
108 } 108 }
109 109
110 if (GNUNET_CRYPTO_AES_KEY_LENGTH != 110 if (GNUNET_CRYPTO_AES_KEY_LENGTH !=
111 GNUNET_CRYPTO_aes_encrypt (plain, GNUNET_CRYPTO_AES_KEY_LENGTH, &key, 111 GNUNET_CRYPTO_aes_encrypt (plain, GNUNET_CRYPTO_AES_KEY_LENGTH, &key,
112 (const struct 112 (const struct
113 GNUNET_CRYPTO_AesInitializationVector *) 113 GNUNET_CRYPTO_AesInitializationVector *)
114 "testtesttesttest", result)) 114 "testtesttesttest", result))
115 { 115 {
116 printf ("Wrong return value from encrypt block.\n"); 116 printf ("Wrong return value from encrypt block.\n");
117 ret = 1; 117 ret = 1;
118 goto error; 118 goto error;
119 } 119 }
120 120
121 if (memcmp (encrresult, result, GNUNET_CRYPTO_AES_KEY_LENGTH) != 0) 121 if (memcmp (encrresult, result, GNUNET_CRYPTO_AES_KEY_LENGTH) != 0)
122 { 122 {
123 printf ("Encrypted result wrong.\n"); 123 printf ("Encrypted result wrong.\n");
124 ret = 1; 124 ret = 1;
125 goto error; 125 goto error;
126 } 126 }
127 127
128 res = GNUNET_malloc (GNUNET_CRYPTO_AES_KEY_LENGTH); 128 res = GNUNET_malloc (GNUNET_CRYPTO_AES_KEY_LENGTH);
129 129
130 if (GNUNET_CRYPTO_AES_KEY_LENGTH != 130 if (GNUNET_CRYPTO_AES_KEY_LENGTH !=
131 GNUNET_CRYPTO_aes_decrypt (result, GNUNET_CRYPTO_AES_KEY_LENGTH, &key, 131 GNUNET_CRYPTO_aes_decrypt (result, GNUNET_CRYPTO_AES_KEY_LENGTH, &key,
132 (const struct 132 (const struct
133 GNUNET_CRYPTO_AesInitializationVector *) 133 GNUNET_CRYPTO_AesInitializationVector *)
134 "testtesttesttest", res)) 134 "testtesttesttest", res))
135 { 135 {
136 printf ("Wrong return value from decrypt block.\n"); 136 printf ("Wrong return value from decrypt block.\n");
137 ret = 1; 137 ret = 1;
138 goto error; 138 goto error;
139 } 139 }
140 140
141 if (memcmp (res, plain, GNUNET_CRYPTO_AES_KEY_LENGTH) != 0) 141 if (memcmp (res, plain, GNUNET_CRYPTO_AES_KEY_LENGTH) != 0)
142 { 142 {
143 printf ("Decrypted result does not match input.\n"); 143 printf ("Decrypted result does not match input.\n");
144 144
145 ret = 1; 145 ret = 1;
146 } 146 }
147 147
148error: 148error:
149 149
@@ -160,15 +160,15 @@ main (int argc, char *argv[])
160 GNUNET_log_setup ("test-crypto-aes", "WARNING", NULL); 160 GNUNET_log_setup ("test-crypto-aes", "WARNING", NULL);
161 GNUNET_CRYPTO_random_disable_entropy_gathering (); 161 GNUNET_CRYPTO_random_disable_entropy_gathering ();
162 GNUNET_assert (strlen (INITVALUE) > 162 GNUNET_assert (strlen (INITVALUE) >
163 sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); 163 sizeof (struct GNUNET_CRYPTO_AesInitializationVector));
164 failureCount += testSymcipher (); 164 failureCount += testSymcipher ();
165 failureCount += verifyCrypto (); 165 failureCount += verifyCrypto ();
166 166
167 if (failureCount != 0) 167 if (failureCount != 0)
168 { 168 {
169 printf ("%d TESTS FAILED!\n", failureCount); 169 printf ("%d TESTS FAILED!\n", failureCount);
170 return -1; 170 return -1;
171 } 171 }
172 return 0; 172 return 0;
173} 173}
174 174
diff --git a/src/util/test_crypto_aes_weak.c b/src/util/test_crypto_aes_weak.c
index 25931b625..a0161b575 100644
--- a/src/util/test_crypto_aes_weak.c
+++ b/src/util/test_crypto_aes_weak.c
@@ -40,9 +40,9 @@ printWeakKey (struct GNUNET_CRYPTO_AesSessionKey *key)
40 int i; 40 int i;
41 41
42 for (i = 0; i < GNUNET_CRYPTO_AES_KEY_LENGTH; i++) 42 for (i = 0; i < GNUNET_CRYPTO_AES_KEY_LENGTH; i++)
43 { 43 {
44 printf ("%x ", (int) (key->key[i])); 44 printf ("%x ", (int) (key->key[i]));
45 } 45 }
46} 46}
47 47
48static int 48static int
@@ -55,7 +55,7 @@ testWeakKey ()
55 struct GNUNET_CRYPTO_AesInitializationVector INITVALUE; 55 struct GNUNET_CRYPTO_AesInitializationVector INITVALUE;
56 56
57 memset (&INITVALUE, 42, 57 memset (&INITVALUE, 42,
58 sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); 58 sizeof (struct GNUNET_CRYPTO_AesInitializationVector));
59 /* sorry, this is not a weak key -- I don't have 59 /* sorry, this is not a weak key -- I don't have
60 * any at the moment! */ 60 * any at the moment! */
61 weak_key.key[0] = (char) (0x4c); 61 weak_key.key[0] = (char) (0x4c);
@@ -92,31 +92,31 @@ testWeakKey ()
92 weak_key.key[31] = (char) (0xaa); 92 weak_key.key[31] = (char) (0xaa);
93 /* memset(&weak_key, 0, 32); */ 93 /* memset(&weak_key, 0, 32); */
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 = 97 size =
98 GNUNET_CRYPTO_aes_encrypt (WEAK_KEY_TESTSTRING, 98 GNUNET_CRYPTO_aes_encrypt (WEAK_KEY_TESTSTRING,
99 strlen (WEAK_KEY_TESTSTRING) + 1, &weak_key, 99 strlen (WEAK_KEY_TESTSTRING) + 1, &weak_key,
100 &INITVALUE, result); 100 &INITVALUE, result);
101 101
102 if (size == -1) 102 if (size == -1)
103 { 103 {
104 GNUNET_break (0); 104 GNUNET_break (0);
105 return 1; 105 return 1;
106 } 106 }
107 107
108 size = GNUNET_CRYPTO_aes_decrypt (result, size, &weak_key, &INITVALUE, res); 108 size = GNUNET_CRYPTO_aes_decrypt (result, size, &weak_key, &INITVALUE, res);
109 109
110 if ((strlen (WEAK_KEY_TESTSTRING) + 1) != size) 110 if ((strlen (WEAK_KEY_TESTSTRING) + 1) != size)
111 { 111 {
112 GNUNET_break (0); 112 GNUNET_break (0);
113 return 1; 113 return 1;
114 } 114 }
115 if (0 != strcmp (res, WEAK_KEY_TESTSTRING)) 115 if (0 != strcmp (res, WEAK_KEY_TESTSTRING))
116 { 116 {
117 GNUNET_break (0); 117 GNUNET_break (0);
118 return 1; 118 return 1;
119 } 119 }
120 else 120 else
121 return 0; 121 return 0;
122} 122}
@@ -133,45 +133,42 @@ getWeakKeys ()
133 133
134 for (number_of_runs = 0; number_of_runs < MAX_WEAK_KEY_TRIALS; 134 for (number_of_runs = 0; number_of_runs < MAX_WEAK_KEY_TRIALS;
135 number_of_runs++) 135 number_of_runs++)
136 {
137
138 if (number_of_runs % 1000 == 0)
139 fprintf (stderr, ".");
140 /*printf("Got to run number %d.\n", number_of_runs); */
141 GNUNET_CRYPTO_aes_create_session_key (&sessionkey);
142
143 rc = gcry_cipher_open (&handle, GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CFB,
144 0);
145
146 if (rc)
136 { 147 {
148 printf ("testweakkey: gcry_cipher_open failed on trial %d. %s\n",
149 number_of_runs, gcry_strerror (rc));
150 continue;
151 }
137 152
138 if (number_of_runs % 1000 == 0) 153 rc = gcry_cipher_setkey (handle, &sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH);
139 fprintf (stderr, ".");
140 /*printf("Got to run number %d.\n", number_of_runs); */
141 GNUNET_CRYPTO_aes_create_session_key (&sessionkey);
142
143 rc =
144 gcry_cipher_open (&handle, GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CFB,
145 0);
146
147 if (rc)
148 {
149 printf ("testweakkey: gcry_cipher_open failed on trial %d. %s\n",
150 number_of_runs, gcry_strerror (rc));
151 continue;
152 }
153
154 rc =
155 gcry_cipher_setkey (handle, &sessionkey,
156 GNUNET_CRYPTO_AES_KEY_LENGTH);
157
158 if ((char) rc == GPG_ERR_WEAK_KEY)
159 {
160 printf ("\nWeak key (in hex): ");
161 printWeakKey (&sessionkey);
162 printf ("\n");
163 number_of_weak_keys++;
164 }
165 else if (rc)
166 {
167 printf ("\nUnexpected error generating keys. Error is %s\n",
168 gcry_strerror (rc));
169 }
170
171 gcry_cipher_close (handle);
172 154
155 if ((char) rc == GPG_ERR_WEAK_KEY)
156 {
157 printf ("\nWeak key (in hex): ");
158 printWeakKey (&sessionkey);
159 printf ("\n");
160 number_of_weak_keys++;
161 }
162 else if (rc)
163 {
164 printf ("\nUnexpected error generating keys. Error is %s\n",
165 gcry_strerror (rc));
173 } 166 }
174 167
168 gcry_cipher_close (handle);
169
170 }
171
175 return number_of_weak_keys; 172 return number_of_weak_keys;
176} 173}
177 174
@@ -183,19 +180,19 @@ main (int argc, char *argv[])
183 GNUNET_log_setup ("test-crypto-aes-weak", "WARNING", NULL); 180 GNUNET_log_setup ("test-crypto-aes-weak", "WARNING", NULL);
184 GNUNET_CRYPTO_random_disable_entropy_gathering (); 181 GNUNET_CRYPTO_random_disable_entropy_gathering ();
185 if (GENERATE_WEAK_KEYS) 182 if (GENERATE_WEAK_KEYS)
183 {
184 weak_keys = getWeakKeys ();
185
186 if (weak_keys == 0)
187 {
188 printf ("\nNo weak keys found in %d runs.\n", MAX_WEAK_KEY_TRIALS);
189 }
190 else
186 { 191 {
187 weak_keys = getWeakKeys (); 192 printf ("\n%d weak keys found in %d runs.\n", weak_keys,
188 193 MAX_WEAK_KEY_TRIALS);
189 if (weak_keys == 0)
190 {
191 printf ("\nNo weak keys found in %d runs.\n", MAX_WEAK_KEY_TRIALS);
192 }
193 else
194 {
195 printf ("\n%d weak keys found in %d runs.\n", weak_keys,
196 MAX_WEAK_KEY_TRIALS);
197 }
198 } 194 }
195 }
199 196
200 if (testWeakKey () != 0) 197 if (testWeakKey () != 0)
201 return -1; 198 return -1;
diff --git a/src/util/test_crypto_hash.c b/src/util/test_crypto_hash.c
index a32a28ef0..b0fa4f332 100644
--- a/src/util/test_crypto_hash.c
+++ b/src/util/test_crypto_hash.c
@@ -42,10 +42,10 @@ test (int number)
42 memset (&h1, number, sizeof (GNUNET_HashCode)); 42 memset (&h1, number, sizeof (GNUNET_HashCode));
43 GNUNET_CRYPTO_hash_to_enc (&h1, &enc); 43 GNUNET_CRYPTO_hash_to_enc (&h1, &enc);
44 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char *) &enc, &h2)) 44 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char *) &enc, &h2))
45 { 45 {
46 printf ("enc2hash failed!\n"); 46 printf ("enc2hash failed!\n");
47 return 1; 47 return 1;
48 } 48 }
49 if (0 != memcmp (&h1, &h2, sizeof (GNUNET_HashCode))) 49 if (0 != memcmp (&h1, &h2, sizeof (GNUNET_HashCode)))
50 return 1; 50 return 1;
51 return 0; 51 return 0;
@@ -124,9 +124,8 @@ static void
124file_hasher (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 124file_hasher (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
125{ 125{
126 GNUNET_assert (NULL != 126 GNUNET_assert (NULL !=
127 GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 127 GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
128 FILENAME, 1024, &finished_task, 128 FILENAME, 1024, &finished_task, cls));
129 cls));
130} 129}
131 130
132 131
diff --git a/src/util/test_crypto_hkdf.c b/src/util/test_crypto_hkdf.c
index d5ee4d433..752116194 100644
--- a/src/util/test_crypto_hkdf.c
+++ b/src/util/test_crypto_hkdf.c
@@ -36,17 +36,17 @@ void
36tc1 () 36tc1 ()
37{ 37{
38 unsigned char ikm[22] = 38 unsigned char ikm[22] =
39 { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 39 { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
40 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b 40 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b
41 }; 41 };
42 unsigned char salt[13] = 42 unsigned char salt[13] =
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 info[10] = 46 unsigned char info[10] =
47 { 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,
51 0x5a, 0x4c, 0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4, 0xc5, 0xbf, 0x34, 0x00, 51 0x5a, 0x4c, 0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4, 0xc5, 0xbf, 0x34, 0x00,
52 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18, 0x58, 0x65 52 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18, 0x58, 0x65
@@ -56,9 +56,9 @@ tc1 ()
56 56
57 memset (result, 0, sizeof (result)); 57 memset (result, 0, sizeof (result));
58 GNUNET_assert (GNUNET_CRYPTO_hkdf 58 GNUNET_assert (GNUNET_CRYPTO_hkdf
59 (result, l, GCRY_MD_SHA256, GCRY_MD_SHA256, salt, 59 (result, l, GCRY_MD_SHA256, GCRY_MD_SHA256, salt,
60 sizeof (salt), ikm, sizeof (ikm), info, sizeof (info), 60 sizeof (salt), ikm, sizeof (ikm), info, sizeof (info),
61 NULL) == GNUNET_YES); 61 NULL) == GNUNET_YES);
62 GNUNET_assert (memcmp (result, okm, l) == 0); 62 GNUNET_assert (memcmp (result, okm, l) == 0);
63 GNUNET_assert (memcmp (result + l, "\0", 2) == 0); 63 GNUNET_assert (memcmp (result + l, "\0", 2) == 0);
64} 64}
@@ -67,7 +67,7 @@ void
67tc2 () 67tc2 ()
68{ 68{
69 unsigned char ikm[80] = 69 unsigned char ikm[80] =
70 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 70 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
71 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 71 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
72 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 72 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21,
73 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 73 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
@@ -76,7 +76,7 @@ tc2 ()
76 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f 76 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f
77 }; 77 };
78 unsigned char salt[80] = 78 unsigned char salt[80] =
79 { 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 79 { 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
80 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 80 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75,
81 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 81 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81,
82 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 82 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d,
@@ -85,7 +85,7 @@ tc2 ()
85 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf 85 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf
86 }; 86 };
87 unsigned char info[80] = 87 unsigned char info[80] =
88 { 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 88 { 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9,
89 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 89 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5,
90 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 90 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1,
91 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 91 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd,
@@ -94,7 +94,7 @@ tc2 ()
94 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 94 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
95 }; 95 };
96 unsigned char okm[82] = 96 unsigned char okm[82] =
97 { 0xb1, 0x1e, 0x39, 0x8d, 0xc8, 0x03, 0x27, 0xa1, 0xc8, 0xe7, 97 { 0xb1, 0x1e, 0x39, 0x8d, 0xc8, 0x03, 0x27, 0xa1, 0xc8, 0xe7,
98 0xf7, 0x8c, 0x59, 0x6a, 0x49, 0x34, 0x4f, 0x01, 0x2e, 0xda, 0x2d, 0x4e, 98 0xf7, 0x8c, 0x59, 0x6a, 0x49, 0x34, 0x4f, 0x01, 0x2e, 0xda, 0x2d, 0x4e,
99 0xfa, 0xd8, 0xa0, 0x50, 0xcc, 0x4c, 0x19, 0xaf, 0xa9, 0x7c, 0x59, 0x04, 99 0xfa, 0xd8, 0xa0, 0x50, 0xcc, 0x4c, 0x19, 0xaf, 0xa9, 0x7c, 0x59, 0x04,
100 0x5a, 0x99, 0xca, 0xc7, 0x82, 0x72, 0x71, 0xcb, 0x41, 0xc6, 0x5e, 0x59, 100 0x5a, 0x99, 0xca, 0xc7, 0x82, 0x72, 0x71, 0xcb, 0x41, 0xc6, 0x5e, 0x59,
@@ -107,9 +107,9 @@ tc2 ()
107 107
108 memset (result, 0, sizeof (result)); 108 memset (result, 0, sizeof (result));
109 GNUNET_assert (GNUNET_CRYPTO_hkdf 109 GNUNET_assert (GNUNET_CRYPTO_hkdf
110 (result, l, GCRY_MD_SHA256, GCRY_MD_SHA256, salt, 110 (result, l, GCRY_MD_SHA256, GCRY_MD_SHA256, salt,
111 sizeof (salt), ikm, sizeof (ikm), info, sizeof (info), 111 sizeof (salt), ikm, sizeof (ikm), info, sizeof (info),
112 NULL) == GNUNET_YES); 112 NULL) == GNUNET_YES);
113 GNUNET_assert (memcmp (result, okm, l) == 0); 113 GNUNET_assert (memcmp (result, okm, l) == 0);
114 GNUNET_assert (memcmp (result + l, "\0", 2) == 0); 114 GNUNET_assert (memcmp (result + l, "\0", 2) == 0);
115} 115}
@@ -118,11 +118,11 @@ void
118tc3 () 118tc3 ()
119{ 119{
120 unsigned char ikm[22] = 120 unsigned char ikm[22] =
121 { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 121 { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
122 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b 122 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b
123 }; 123 };
124 unsigned char okm[42] = 124 unsigned char okm[42] =
125 { 0x8d, 0xa4, 0xe7, 0x75, 0xa5, 0x63, 0xc1, 0x8f, 0x71, 0x5f, 125 { 0x8d, 0xa4, 0xe7, 0x75, 0xa5, 0x63, 0xc1, 0x8f, 0x71, 0x5f,
126 0x80, 0x2a, 0x06, 0x3c, 0x5a, 0x31, 0xb8, 0xa1, 0x1f, 0x5c, 0x5e, 0xe1, 126 0x80, 0x2a, 0x06, 0x3c, 0x5a, 0x31, 0xb8, 0xa1, 0x1f, 0x5c, 0x5e, 0xe1,
127 0x87, 0x9e, 0xc3, 0x45, 0x4e, 0x5f, 0x3c, 0x73, 0x8d, 0x2d, 0x9d, 0x20, 127 0x87, 0x9e, 0xc3, 0x45, 0x4e, 0x5f, 0x3c, 0x73, 0x8d, 0x2d, 0x9d, 0x20,
128 0x13, 0x95, 0xfa, 0xa4, 0xb6, 0x1a, 0x96, 0xc8 128 0x13, 0x95, 0xfa, 0xa4, 0xb6, 0x1a, 0x96, 0xc8
@@ -132,8 +132,8 @@ tc3 ()
132 132
133 memset (result, 0, sizeof (result)); 133 memset (result, 0, sizeof (result));
134 GNUNET_assert (GNUNET_CRYPTO_hkdf 134 GNUNET_assert (GNUNET_CRYPTO_hkdf
135 (result, l, GCRY_MD_SHA256, GCRY_MD_SHA256, NULL, 0, ikm, 135 (result, l, GCRY_MD_SHA256, GCRY_MD_SHA256, NULL, 0, ikm,
136 sizeof (ikm), NULL, 0, NULL) == GNUNET_YES); 136 sizeof (ikm), NULL, 0, NULL) == GNUNET_YES);
137 GNUNET_assert (memcmp (result, okm, l) == 0); 137 GNUNET_assert (memcmp (result, okm, l) == 0);
138 GNUNET_assert (memcmp (result + l, "\0", 2) == 0); 138 GNUNET_assert (memcmp (result + l, "\0", 2) == 0);
139} 139}
@@ -142,17 +142,17 @@ void
142tc4 () 142tc4 ()
143{ 143{
144 unsigned char ikm[11] = 144 unsigned char ikm[11] =
145 { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 145 { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
146 0x0b 146 0x0b
147 }; 147 };
148 unsigned char salt[13] = 148 unsigned char salt[13] =
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 info[10] = 152 unsigned char info[10] =
153 { 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,
157 0x09, 0x15, 0x68, 0xa9, 0xcd, 0xd4, 0xf1, 0x55, 0xfd, 0xa2, 0xc2, 0x2e, 157 0x09, 0x15, 0x68, 0xa9, 0xcd, 0xd4, 0xf1, 0x55, 0xfd, 0xa2, 0xc2, 0x2e,
158 0x42, 0x24, 0x78, 0xd3, 0x05, 0xf3, 0xf8, 0x96 158 0x42, 0x24, 0x78, 0xd3, 0x05, 0xf3, 0xf8, 0x96
@@ -162,9 +162,8 @@ tc4 ()
162 162
163 memset (result, 0, sizeof (result)); 163 memset (result, 0, sizeof (result));
164 GNUNET_assert (GNUNET_CRYPTO_hkdf 164 GNUNET_assert (GNUNET_CRYPTO_hkdf
165 (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, salt, sizeof (salt), 165 (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, salt, sizeof (salt),
166 ikm, sizeof (ikm), info, sizeof (info), 166 ikm, sizeof (ikm), info, sizeof (info), NULL) == GNUNET_YES);
167 NULL) == GNUNET_YES);
168 GNUNET_assert (memcmp (result, okm, l) == 0); 167 GNUNET_assert (memcmp (result, okm, l) == 0);
169 GNUNET_assert (memcmp (result + l, "\0", 2) == 0); 168 GNUNET_assert (memcmp (result + l, "\0", 2) == 0);
170} 169}
@@ -173,7 +172,7 @@ void
173tc5 () 172tc5 ()
174{ 173{
175 unsigned char ikm[80] = 174 unsigned char ikm[80] =
176 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 175 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
177 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 176 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
178 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 177 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21,
179 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 178 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
@@ -182,7 +181,7 @@ tc5 ()
182 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f 181 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f
183 }; 182 };
184 unsigned char salt[80] = 183 unsigned char salt[80] =
185 { 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 184 { 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
186 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 185 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75,
187 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 186 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81,
188 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 187 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d,
@@ -191,7 +190,7 @@ tc5 ()
191 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf 190 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf
192 }; 191 };
193 unsigned char info[80] = 192 unsigned char info[80] =
194 { 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 193 { 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9,
195 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 194 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5,
196 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 195 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1,
197 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 196 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd,
@@ -200,7 +199,7 @@ tc5 ()
200 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 199 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
201 }; 200 };
202 unsigned char okm[82] = 201 unsigned char okm[82] =
203 { 0x0b, 0xd7, 0x70, 0xa7, 0x4d, 0x11, 0x60, 0xf7, 0xc9, 0xf1, 202 { 0x0b, 0xd7, 0x70, 0xa7, 0x4d, 0x11, 0x60, 0xf7, 0xc9, 0xf1,
204 0x2c, 0xd5, 0x91, 0x2a, 0x06, 0xeb, 0xff, 0x6a, 0xdc, 0xae, 0x89, 0x9d, 203 0x2c, 0xd5, 0x91, 0x2a, 0x06, 0xeb, 0xff, 0x6a, 0xdc, 0xae, 0x89, 0x9d,
205 0x92, 0x19, 0x1f, 0xe4, 0x30, 0x56, 0x73, 0xba, 0x2f, 0xfe, 0x8f, 0xa3, 204 0x92, 0x19, 0x1f, 0xe4, 0x30, 0x56, 0x73, 0xba, 0x2f, 0xfe, 0x8f, 0xa3,
206 0xf1, 0xa4, 0xe5, 0xad, 0x79, 0xf3, 0xf3, 0x34, 0xb3, 0xb2, 0x02, 0xb2, 205 0xf1, 0xa4, 0xe5, 0xad, 0x79, 0xf3, 0xf3, 0x34, 0xb3, 0xb2, 0x02, 0xb2,
@@ -213,9 +212,8 @@ tc5 ()
213 212
214 memset (result, 0, sizeof (result)); 213 memset (result, 0, sizeof (result));
215 GNUNET_assert (GNUNET_CRYPTO_hkdf 214 GNUNET_assert (GNUNET_CRYPTO_hkdf
216 (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, salt, sizeof (salt), 215 (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, salt, sizeof (salt),
217 ikm, sizeof (ikm), info, sizeof (info), 216 ikm, sizeof (ikm), info, sizeof (info), NULL) == GNUNET_YES);
218 NULL) == GNUNET_YES);
219 GNUNET_assert (memcmp (result, okm, l) == 0); 217 GNUNET_assert (memcmp (result, okm, l) == 0);
220 GNUNET_assert (memcmp (result + l, "\0", 2) == 0); 218 GNUNET_assert (memcmp (result + l, "\0", 2) == 0);
221} 219}
@@ -224,11 +222,11 @@ void
224tc6 () 222tc6 ()
225{ 223{
226 unsigned char ikm[22] = 224 unsigned char ikm[22] =
227 { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 225 { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
228 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b 226 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b
229 }; 227 };
230 unsigned char okm[42] = 228 unsigned char okm[42] =
231 { 0x0a, 0xc1, 0xaf, 0x70, 0x02, 0xb3, 0xd7, 0x61, 0xd1, 0xe5, 229 { 0x0a, 0xc1, 0xaf, 0x70, 0x02, 0xb3, 0xd7, 0x61, 0xd1, 0xe5,
232 0x52, 0x98, 0xda, 0x9d, 0x05, 0x06, 0xb9, 0xae, 0x52, 0x05, 0x72, 0x20, 230 0x52, 0x98, 0xda, 0x9d, 0x05, 0x06, 0xb9, 0xae, 0x52, 0x05, 0x72, 0x20,
233 0xa3, 0x06, 0xe0, 0x7b, 0x6b, 0x87, 0xe8, 0xdf, 0x21, 0xd0, 0xea, 0x00, 231 0xa3, 0x06, 0xe0, 0x7b, 0x6b, 0x87, 0xe8, 0xdf, 0x21, 0xd0, 0xea, 0x00,
234 0x03, 0x3d, 0xe0, 0x39, 0x84, 0xd3, 0x49, 0x18 232 0x03, 0x3d, 0xe0, 0x39, 0x84, 0xd3, 0x49, 0x18
@@ -238,8 +236,8 @@ tc6 ()
238 236
239 memset (result, 0, sizeof (result)); 237 memset (result, 0, sizeof (result));
240 GNUNET_assert (GNUNET_CRYPTO_hkdf 238 GNUNET_assert (GNUNET_CRYPTO_hkdf
241 (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, NULL, 0, ikm, 239 (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, NULL, 0, ikm,
242 sizeof (ikm), NULL, 0, NULL) == GNUNET_YES); 240 sizeof (ikm), NULL, 0, NULL) == GNUNET_YES);
243 GNUNET_assert (memcmp (result, okm, l) == 0); 241 GNUNET_assert (memcmp (result, okm, l) == 0);
244 GNUNET_assert (memcmp (result + l, "\0", 2) == 0); 242 GNUNET_assert (memcmp (result + l, "\0", 2) == 0);
245} 243}
@@ -248,7 +246,7 @@ void
248tc7 () 246tc7 ()
249{ 247{
250 unsigned char ikm[80] = 248 unsigned char ikm[80] =
251 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 249 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
252 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 250 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
253 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 251 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21,
254 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 252 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
@@ -257,7 +255,7 @@ tc7 ()
257 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f 255 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f
258 }; 256 };
259 unsigned char salt[80] = 257 unsigned char salt[80] =
260 { 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 258 { 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
261 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 259 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75,
262 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 260 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81,
263 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 261 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d,
@@ -277,7 +275,7 @@ tc7 ()
277 0xfe, 0xff 275 0xfe, 0xff
278 }; 276 };
279 unsigned char okm[82] = 277 unsigned char okm[82] =
280 { 0x0b, 0xd7, 0x70, 0xa7, 0x4d, 0x11, 0x60, 0xf7, 0xc9, 0xf1, 278 { 0x0b, 0xd7, 0x70, 0xa7, 0x4d, 0x11, 0x60, 0xf7, 0xc9, 0xf1,
281 0x2c, 0xd5, 0x91, 0x2a, 0x06, 0xeb, 0xff, 0x6a, 0xdc, 0xae, 0x89, 0x9d, 279 0x2c, 0xd5, 0x91, 0x2a, 0x06, 0xeb, 0xff, 0x6a, 0xdc, 0xae, 0x89, 0x9d,
282 0x92, 0x19, 0x1f, 0xe4, 0x30, 0x56, 0x73, 0xba, 0x2f, 0xfe, 0x8f, 0xa3, 280 0x92, 0x19, 0x1f, 0xe4, 0x30, 0x56, 0x73, 0xba, 0x2f, 0xfe, 0x8f, 0xa3,
283 0xf1, 0xa4, 0xe5, 0xad, 0x79, 0xf3, 0xf3, 0x34, 0xb3, 0xb2, 0x02, 0xb2, 281 0xf1, 0xa4, 0xe5, 0xad, 0x79, 0xf3, 0xf3, 0x34, 0xb3, 0xb2, 0x02, 0xb2,
@@ -290,9 +288,9 @@ tc7 ()
290 288
291 memset (result, 0, sizeof (result)); 289 memset (result, 0, sizeof (result));
292 GNUNET_assert (GNUNET_CRYPTO_hkdf 290 GNUNET_assert (GNUNET_CRYPTO_hkdf
293 (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, salt, sizeof (salt), 291 (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, salt, sizeof (salt),
294 ikm, sizeof (ikm), info1, sizeof (info1), info2, 292 ikm, sizeof (ikm), info1, sizeof (info1), info2,
295 sizeof (info2), NULL) == GNUNET_YES); 293 sizeof (info2), NULL) == GNUNET_YES);
296 GNUNET_assert (memcmp (result, okm, l) == 0); 294 GNUNET_assert (memcmp (result, okm, l) == 0);
297 GNUNET_assert (memcmp (result + l, "\0", 2) == 0); 295 GNUNET_assert (memcmp (result + l, "\0", 2) == 0);
298} 296}
@@ -301,13 +299,13 @@ void
301tc8 () 299tc8 ()
302{ 300{
303 unsigned char ikm[32] = 301 unsigned char ikm[32] =
304 { 0xbf, 0x16, 0x6e, 0x46, 0x3a, 0x6c, 0xf3, 0x93, 0xa7, 0x72, 302 { 0xbf, 0x16, 0x6e, 0x46, 0x3a, 0x6c, 0xf3, 0x93, 0xa7, 0x72,
305 0x11, 0xa1, 0xdc, 0x0b, 0x07, 0xdb, 0x1a, 0x5e, 0xd9, 0xb9, 0x81, 0xbe, 303 0x11, 0xa1, 0xdc, 0x0b, 0x07, 0xdb, 0x1a, 0x5e, 0xd9, 0xb9, 0x81, 0xbe,
306 0xea, 0xe4, 0x31, 0x5f, 0x24, 0xff, 0xfe, 0x50, 0x8a, 0xde 304 0xea, 0xe4, 0x31, 0x5f, 0x24, 0xff, 0xfe, 0x50, 0x8a, 0xde
307 }; 305 };
308 unsigned char salt[4] = { 0xfc, 0x62, 0x76, 0x35 }; 306 unsigned char salt[4] = { 0xfc, 0x62, 0x76, 0x35 };
309 unsigned char info[86] = 307 unsigned char info[86] =
310 { 0x8c, 0x0d, 0xcf, 0xb3, 0x25, 0x6e, 0x88, 0x0d, 0xc1, 0x0b, 308 { 0x8c, 0x0d, 0xcf, 0xb3, 0x25, 0x6e, 0x88, 0x0d, 0xc1, 0x0b,
311 0x1d, 0x33, 0x15, 0x3e, 0x52, 0x0b, 0xb0, 0x77, 0xff, 0x7d, 0xc3, 0xc7, 309 0x1d, 0x33, 0x15, 0x3e, 0x52, 0x0b, 0xb0, 0x77, 0xff, 0x7d, 0xc3, 0xc7,
312 0xef, 0xe5, 0x8e, 0x3c, 0xc4, 0x4e, 0x8b, 0x41, 0x46, 0x1f, 0x02, 0x94, 310 0xef, 0xe5, 0x8e, 0x3c, 0xc4, 0x4e, 0x8b, 0x41, 0x46, 0x1f, 0x02, 0x94,
313 0x82, 0x35, 0xc5, 0xa6, 0x5e, 0x91, 0xd8, 0xa2, 0x90, 0xfd, 0x6f, 0xb4, 311 0x82, 0x35, 0xc5, 0xa6, 0x5e, 0x91, 0xd8, 0xa2, 0x90, 0xfd, 0x6f, 0xb4,
@@ -317,7 +315,7 @@ tc8 ()
317 0x74, 0x6f, 0x72, 0x00 315 0x74, 0x6f, 0x72, 0x00
318 }; 316 };
319 unsigned char okm[16] = 317 unsigned char okm[16] =
320 { 0xd6, 0x90, 0xec, 0x9e, 0x62, 0xdf, 0xb9, 0x41, 0xff, 0x92, 318 { 0xd6, 0x90, 0xec, 0x9e, 0x62, 0xdf, 0xb9, 0x41, 0xff, 0x92,
321 0x4f, 0xd2, 0xf6, 0x1d, 0x67, 0xe0 319 0x4f, 0xd2, 0xf6, 0x1d, 0x67, 0xe0
322 }; 320 };
323 char result[18]; 321 char result[18];
@@ -325,9 +323,9 @@ tc8 ()
325 323
326 memset (result, 0, sizeof (result)); 324 memset (result, 0, sizeof (result));
327 GNUNET_assert (GNUNET_CRYPTO_hkdf 325 GNUNET_assert (GNUNET_CRYPTO_hkdf
328 (result, l, GCRY_MD_SHA512, GCRY_MD_SHA256, salt, 326 (result, l, GCRY_MD_SHA512, GCRY_MD_SHA256, salt,
329 sizeof (salt), ikm, sizeof (ikm), info, sizeof (info), 327 sizeof (salt), ikm, sizeof (ikm), info, sizeof (info),
330 NULL) == GNUNET_YES); 328 NULL) == GNUNET_YES);
331 GNUNET_assert (memcmp (result, okm, l) == 0); 329 GNUNET_assert (memcmp (result, okm, l) == 0);
332 GNUNET_assert (memcmp (result + l, "\0", 2) == 0); 330 GNUNET_assert (memcmp (result + l, "\0", 2) == 0);
333} 331}
diff --git a/src/util/test_crypto_ksk.c b/src/util/test_crypto_ksk.c
index 55d2dffcb..2789f5edb 100644
--- a/src/util/test_crypto_ksk.c
+++ b/src/util/test_crypto_ksk.c
@@ -39,7 +39,7 @@ static int
39testCorrectKey () 39testCorrectKey ()
40{ 40{
41 const char *want = 41 const char *want =
42 "010601000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b73c215f7a5e6b09bec55713c901786c09324a150980e014bdb0d04426934929c3b4971a9711af5455536cd6eeb8bfa004ee904972a737455f53c752987d8c82b755bc02882b44950c4acdc1672ba74c3b94d81a4c1ea3d74e7700ae5594c3a4f3c559e4bff2df6844fac302e4b66175e14dc8bad3ce44281d2fec1a1abef06301010000"; 42 "010601000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b73c215f7a5e6b09bec55713c901786c09324a150980e014bdb0d04426934929c3b4971a9711af5455536cd6eeb8bfa004ee904972a737455f53c752987d8c82b755bc02882b44950c4acdc1672ba74c3b94d81a4c1ea3d74e7700ae5594c3a4f3c559e4bff2df6844fac302e4b66175e14dc8bad3ce44281d2fec1a1abef06301010000";
43 GNUNET_HashCode in; 43 GNUNET_HashCode in;
44 struct GNUNET_CRYPTO_RsaPrivateKey *hostkey; 44 struct GNUNET_CRYPTO_RsaPrivateKey *hostkey;
45 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; 45 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
@@ -50,29 +50,27 @@ testCorrectKey ()
50 GNUNET_CRYPTO_hash ("X", strlen ("X"), &in); 50 GNUNET_CRYPTO_hash ("X", strlen ("X"), &in);
51 hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in); 51 hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in);
52 if (hostkey == NULL) 52 if (hostkey == NULL)
53 { 53 {
54 GNUNET_break (0); 54 GNUNET_break (0);
55 return GNUNET_SYSERR; 55 return GNUNET_SYSERR;
56 } 56 }
57 GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey); 57 GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey);
58 GNUNET_CRYPTO_rsa_key_free (hostkey); 58 GNUNET_CRYPTO_rsa_key_free (hostkey);
59#if 0 59#if 0
60 for (i = 0; i < sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded); 60 for (i = 0; i < sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded); i++)
61 i++)
62 printf ("%02x", ((unsigned char *) &pkey)[i]); 61 printf ("%02x", ((unsigned char *) &pkey)[i]);
63 printf ("\n"); 62 printf ("\n");
64#endif 63#endif
65 for (i = 0; i < sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded); 64 for (i = 0; i < sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded); i++)
66 i++) 65 {
66 snprintf (out, sizeof (out), "%02x", ((unsigned char *) &pkey)[i]);
67 if (0 != strncmp (out, &want[i * 2], 2))
67 { 68 {
68 snprintf (out, sizeof (out), "%02x", ((unsigned char *) &pkey)[i]); 69 fprintf (stderr, " Failed! Wanted %.2s but got %2s at %d\n", &want[i * 2],
69 if (0 != strncmp (out, &want[i * 2], 2)) 70 out, i);
70 { 71 return GNUNET_SYSERR;
71 fprintf (stderr, " Failed! Wanted %.2s but got %2s at %d\n",
72 &want[i * 2], out, i);
73 return GNUNET_SYSERR;
74 }
75 } 72 }
73 }
76 fprintf (stderr, " OK\n"); 74 fprintf (stderr, " OK\n");
77 return GNUNET_OK; 75 return GNUNET_OK;
78} 76}
@@ -91,10 +89,10 @@ testMultiKey (const char *word)
91 GNUNET_CRYPTO_hash (word, strlen (word), &in); 89 GNUNET_CRYPTO_hash (word, strlen (word), &in);
92 hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in); 90 hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in);
93 if (hostkey == NULL) 91 if (hostkey == NULL)
94 { 92 {
95 GNUNET_break (0); 93 GNUNET_break (0);
96 return GNUNET_SYSERR; 94 return GNUNET_SYSERR;
97 } 95 }
98 GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey); 96 GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey);
99 /* 97 /*
100 * for (i=0;i<sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded);i++) 98 * for (i=0;i<sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded);i++)
@@ -102,26 +100,26 @@ testMultiKey (const char *word)
102 * printf("\n"); */ 100 * printf("\n"); */
103 GNUNET_CRYPTO_rsa_key_free (hostkey); 101 GNUNET_CRYPTO_rsa_key_free (hostkey);
104 for (i = 0; i < UNIQUE_ITER; i++) 102 for (i = 0; i < UNIQUE_ITER; i++)
103 {
104 fprintf (stderr, ".");
105 hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in);
106 if (hostkey == NULL)
105 { 107 {
106 fprintf (stderr, "."); 108 GNUNET_break (0);
107 hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in); 109 fprintf (stderr, " ERROR\n");
108 if (hostkey == NULL) 110 return GNUNET_SYSERR;
109 {
110 GNUNET_break (0);
111 fprintf (stderr, " ERROR\n");
112 return GNUNET_SYSERR;
113 }
114 GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey1);
115 GNUNET_CRYPTO_rsa_key_free (hostkey);
116 if (0 !=
117 memcmp (&pkey, &pkey1,
118 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
119 {
120 GNUNET_break (0);
121 fprintf (stderr, " ERROR\n");
122 return GNUNET_SYSERR;
123 }
124 } 111 }
112 GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey1);
113 GNUNET_CRYPTO_rsa_key_free (hostkey);
114 if (0 !=
115 memcmp (&pkey, &pkey1,
116 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
117 {
118 GNUNET_break (0);
119 fprintf (stderr, " ERROR\n");
120 return GNUNET_SYSERR;
121 }
122 }
125 fprintf (stderr, " OK\n"); 123 fprintf (stderr, " OK\n");
126 return GNUNET_OK; 124 return GNUNET_OK;
127} 125}
@@ -143,35 +141,35 @@ testEncryptDecrypt (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey)
143 ok = 0; 141 ok = 0;
144 start = GNUNET_TIME_absolute_get (); 142 start = GNUNET_TIME_absolute_get ();
145 for (i = 0; i < ITER; i++) 143 for (i = 0; i < ITER; i++)
144 {
145 fprintf (stderr, ".");
146 if (GNUNET_SYSERR ==
147 GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, &pkey,
148 &target))
149 {
150 fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n");
151 ok++;
152 continue;
153 }
154 if (-1 ==
155 GNUNET_CRYPTO_rsa_decrypt (hostkey, &target, result,
156 strlen (TESTSTRING) + 1))
146 { 157 {
147 fprintf (stderr, "."); 158 fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n");
148 if (GNUNET_SYSERR == 159 ok++;
149 GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, 160 continue;
150 &pkey, &target))
151 {
152 fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n");
153 ok++;
154 continue;
155 }
156 if (-1 ==
157 GNUNET_CRYPTO_rsa_decrypt (hostkey, &target, result,
158 strlen (TESTSTRING) + 1))
159 {
160 fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n");
161 ok++;
162 continue;
163 }
164 if (strncmp (TESTSTRING, result, strlen (TESTSTRING)) != 0)
165 {
166 printf ("%s != %.*s - testEncryptDecrypt failed!\n", TESTSTRING,
167 MAX_TESTVAL, result);
168 ok++;
169 continue;
170 }
171 } 161 }
162 if (strncmp (TESTSTRING, result, strlen (TESTSTRING)) != 0)
163 {
164 printf ("%s != %.*s - testEncryptDecrypt failed!\n", TESTSTRING,
165 MAX_TESTVAL, result);
166 ok++;
167 continue;
168 }
169 }
172 printf ("%d RSA encrypt/decrypt operations %llums (%d failures)\n", ITER, 170 printf ("%d RSA encrypt/decrypt operations %llums (%d failures)\n", ITER,
173 (unsigned long long) 171 (unsigned long long)
174 GNUNET_TIME_absolute_get_duration (start).rel_value, ok); 172 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
@@ -194,34 +192,34 @@ testSignVerify (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey)
194 purp.size = htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose)); 192 purp.size = htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose));
195 purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); 193 purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
196 for (i = 0; i < ITER; i++) 194 for (i = 0; i < ITER; i++)
195 {
196 fprintf (stderr, ".");
197 if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_sign (hostkey, &purp, &sig))
198 {
199 fprintf (stderr, "GNUNET_CRYPTO_rsa_sign returned SYSERR\n");
200 ok = GNUNET_SYSERR;
201 continue;
202 }
203 if (GNUNET_SYSERR ==
204 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TEST, &purp, &sig,
205 &pkey))
206 {
207 printf ("GNUNET_CRYPTO_rsa_verify failed!\n");
208 ok = GNUNET_SYSERR;
209 continue;
210 }
211 if (GNUNET_SYSERR !=
212 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
213 &purp, &sig, &pkey))
197 { 214 {
198 fprintf (stderr, "."); 215 printf ("GNUNET_CRYPTO_rsa_verify failed to fail!\n");
199 if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_sign (hostkey, &purp, &sig)) 216 ok = GNUNET_SYSERR;
200 { 217 continue;
201 fprintf (stderr, "GNUNET_CRYPTO_rsa_sign returned SYSERR\n");
202 ok = GNUNET_SYSERR;
203 continue;
204 }
205 if (GNUNET_SYSERR ==
206 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TEST, &purp,
207 &sig, &pkey))
208 {
209 printf ("GNUNET_CRYPTO_rsa_verify failed!\n");
210 ok = GNUNET_SYSERR;
211 continue;
212 }
213 if (GNUNET_SYSERR !=
214 GNUNET_CRYPTO_rsa_verify
215 (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, &purp, &sig, &pkey))
216 {
217 printf ("GNUNET_CRYPTO_rsa_verify failed to fail!\n");
218 ok = GNUNET_SYSERR;
219 continue;
220 }
221 } 218 }
219 }
222 printf ("%d RSA sign/verify operations %llums\n", ITER, 220 printf ("%d RSA sign/verify operations %llums\n", ITER,
223 (unsigned long long) 221 (unsigned long long)
224 GNUNET_TIME_absolute_get_duration (start).rel_value); 222 GNUNET_TIME_absolute_get_duration (start).rel_value);
225 return ok; 223 return ok;
226} 224}
227 225
@@ -239,10 +237,10 @@ main (int argc, char *argv[])
239 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &in); 237 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &in);
240 hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in); 238 hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in);
241 if (hostkey == NULL) 239 if (hostkey == NULL)
242 { 240 {
243 printf ("\nGNUNET_CRYPTO_rsa_key_create_from_hash failed!\n"); 241 printf ("\nGNUNET_CRYPTO_rsa_key_create_from_hash failed!\n");
244 return 1; 242 return 1;
245 } 243 }
246 if (GNUNET_OK != testMultiKey ("foo")) 244 if (GNUNET_OK != testMultiKey ("foo"))
247 failureCount++; 245 failureCount++;
248 if (GNUNET_OK != testMultiKey ("bar")) 246 if (GNUNET_OK != testMultiKey ("bar"))
@@ -254,9 +252,9 @@ main (int argc, char *argv[])
254 GNUNET_CRYPTO_rsa_key_free (hostkey); 252 GNUNET_CRYPTO_rsa_key_free (hostkey);
255 253
256 if (failureCount != 0) 254 if (failureCount != 0)
257 { 255 {
258 printf ("\n\n%d TESTS FAILED!\n\n", failureCount); 256 printf ("\n\n%d TESTS FAILED!\n\n", failureCount);
259 return -1; 257 return -1;
260 } 258 }
261 return 0; 259 return 0;
262} 260}
diff --git a/src/util/test_crypto_random.c b/src/util/test_crypto_random.c
index 3b86ececd..46d3ed0aa 100644
--- a/src/util/test_crypto_random.c
+++ b/src/util/test_crypto_random.c
@@ -39,19 +39,19 @@ test (enum GNUNET_CRYPTO_Quality mode)
39 for (i = 0; i < 1024; i++) 39 for (i = 0; i < 1024; i++)
40 GNUNET_break (1024 > (buf[i] = GNUNET_CRYPTO_random_u32 (mode, 1024))); 40 GNUNET_break (1024 > (buf[i] = GNUNET_CRYPTO_random_u32 (mode, 1024)));
41 for (i = 0; i < 10; i++) 41 for (i = 0; i < 10; i++)
42 {
43 b2 = GNUNET_CRYPTO_random_permute (mode, 1024);
44 if (0 == memcmp (b2, buf, sizeof (buf)))
42 { 45 {
43 b2 = GNUNET_CRYPTO_random_permute (mode, 1024); 46 fprintf (stderr, "!");
44 if (0 == memcmp (b2, buf, sizeof (buf)))
45 {
46 fprintf (stderr, "!");
47 GNUNET_free (b2);
48 continue;
49 }
50 GNUNET_free (b2); 47 GNUNET_free (b2);
51 break; 48 continue;
52 } 49 }
50 GNUNET_free (b2);
51 break;
52 }
53 if (i == 10) 53 if (i == 10)
54 return 1; /* virtually impossible... */ 54 return 1; /* virtually impossible... */
55 55
56 for (n = 10; n < 1024LL * 1024LL * 1024LL; n *= 10) 56 for (n = 10; n < 1024LL * 1024LL * 1024LL; n *= 10)
57 GNUNET_break (n > GNUNET_CRYPTO_random_u64 (mode, n)); 57 GNUNET_break (n > GNUNET_CRYPTO_random_u64 (mode, n));
diff --git a/src/util/test_crypto_rsa.c b/src/util/test_crypto_rsa.c
index 6a2c1b355..f26a76a38 100644
--- a/src/util/test_crypto_rsa.c
+++ b/src/util/test_crypto_rsa.c
@@ -54,36 +54,36 @@ testEncryptDecrypt ()
54 ok = 0; 54 ok = 0;
55 start = GNUNET_TIME_absolute_get (); 55 start = GNUNET_TIME_absolute_get ();
56 for (i = 0; i < ITER; i++) 56 for (i = 0; i < ITER; i++)
57 {
58 fprintf (stderr, ".");
59 if (GNUNET_SYSERR ==
60 GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, &pkey,
61 &target))
57 { 62 {
58 fprintf (stderr, "."); 63 fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n");
59 if (GNUNET_SYSERR == 64 ok++;
60 GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, 65 continue;
61 &pkey, &target)) 66 }
62 { 67 if (-1 ==
63 fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n"); 68 GNUNET_CRYPTO_rsa_decrypt (hostkey, &target, result,
64 ok++; 69 strlen (TESTSTRING) + 1))
65 continue; 70 {
66 } 71 fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n");
67 if (-1 == 72 ok++;
68 GNUNET_CRYPTO_rsa_decrypt (hostkey, &target, result, 73 continue;
69 strlen (TESTSTRING) + 1))
70 {
71 fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n");
72 ok++;
73 continue;
74 74
75 }
76 if (strncmp (TESTSTRING, result, strlen (TESTSTRING)) != 0)
77 {
78 printf ("%s != %.*s - testEncryptDecrypt failed!\n", TESTSTRING,
79 (int) MAX_TESTVAL, result);
80 ok++;
81 continue;
82 }
83 } 75 }
76 if (strncmp (TESTSTRING, result, strlen (TESTSTRING)) != 0)
77 {
78 printf ("%s != %.*s - testEncryptDecrypt failed!\n", TESTSTRING,
79 (int) MAX_TESTVAL, result);
80 ok++;
81 continue;
82 }
83 }
84 printf ("%d RSA encrypt/decrypt operations %llums (%d failures)\n", ITER, 84 printf ("%d RSA encrypt/decrypt operations %llums (%d failures)\n", ITER,
85 (unsigned long long) 85 (unsigned long long)
86 GNUNET_TIME_absolute_get_duration (start).rel_value, ok); 86 GNUNET_TIME_absolute_get_duration (start).rel_value, ok);
87 GNUNET_CRYPTO_rsa_key_free (hostkey); 87 GNUNET_CRYPTO_rsa_key_free (hostkey);
88 if (ok == 0) 88 if (ok == 0)
89 return GNUNET_OK; 89 return GNUNET_OK;
@@ -109,20 +109,20 @@ testEncryptPerformance ()
109 ok = 0; 109 ok = 0;
110 start = GNUNET_TIME_absolute_get (); 110 start = GNUNET_TIME_absolute_get ();
111 for (i = 0; i < ITER; i++) 111 for (i = 0; i < ITER; i++)
112 {
113 fprintf (stderr, ".");
114 if (GNUNET_SYSERR ==
115 GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, &pkey,
116 &target))
112 { 117 {
113 fprintf (stderr, "."); 118 fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n");
114 if (GNUNET_SYSERR == 119 ok++;
115 GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, 120 continue;
116 &pkey, &target))
117 {
118 fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n");
119 ok++;
120 continue;
121 }
122 } 121 }
122 }
123 printf ("%d RSA encrypt operations %llu ms (%d failures)\n", ITER, 123 printf ("%d RSA encrypt operations %llu ms (%d failures)\n", ITER,
124 (unsigned long long) 124 (unsigned long long)
125 GNUNET_TIME_absolute_get_duration (start).rel_value, ok); 125 GNUNET_TIME_absolute_get_duration (start).rel_value, ok);
126 GNUNET_CRYPTO_rsa_key_free (hostkey); 126 GNUNET_CRYPTO_rsa_key_free (hostkey);
127 if (ok != 0) 127 if (ok != 0)
128 return GNUNET_SYSERR; 128 return GNUNET_SYSERR;
@@ -149,39 +149,37 @@ testEncryptDecryptSK ()
149 ok = 0; 149 ok = 0;
150 start = GNUNET_TIME_absolute_get (); 150 start = GNUNET_TIME_absolute_get ();
151 for (i = 0; i < ITER; i++) 151 for (i = 0; i < ITER; i++)
152 {
153 fprintf (stderr, ".");
154 GNUNET_CRYPTO_aes_create_session_key (&insk);
155 if (GNUNET_SYSERR ==
156 GNUNET_CRYPTO_rsa_encrypt (&insk,
157 sizeof (struct GNUNET_CRYPTO_AesSessionKey),
158 &pkey, &target))
159 {
160 fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n");
161 ok++;
162 continue;
163 }
164 if (-1 ==
165 GNUNET_CRYPTO_rsa_decrypt (hostkey, &target, &outsk,
166 sizeof (struct GNUNET_CRYPTO_AesSessionKey)))
167 {
168 fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n");
169 ok++;
170 continue;
171 }
172 if (0 !=
173 memcmp (&insk, &outsk, sizeof (struct GNUNET_CRYPTO_AesSessionKey)))
152 { 174 {
153 fprintf (stderr, "."); 175 printf ("testEncryptDecryptSK failed!\n");
154 GNUNET_CRYPTO_aes_create_session_key (&insk); 176 ok++;
155 if (GNUNET_SYSERR == 177 continue;
156 GNUNET_CRYPTO_rsa_encrypt (&insk,
157 sizeof (struct
158 GNUNET_CRYPTO_AesSessionKey),
159 &pkey, &target))
160 {
161 fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n");
162 ok++;
163 continue;
164 }
165 if (-1 ==
166 GNUNET_CRYPTO_rsa_decrypt (hostkey, &target, &outsk,
167 sizeof (struct
168 GNUNET_CRYPTO_AesSessionKey)))
169 {
170 fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n");
171 ok++;
172 continue;
173 }
174 if (0 !=
175 memcmp (&insk, &outsk, sizeof (struct GNUNET_CRYPTO_AesSessionKey)))
176 {
177 printf ("testEncryptDecryptSK failed!\n");
178 ok++;
179 continue;
180 }
181 } 178 }
179 }
182 printf ("%d RSA encrypt/decrypt SK operations %llums (%d failures)\n", ITER, 180 printf ("%d RSA encrypt/decrypt SK operations %llums (%d failures)\n", ITER,
183 (unsigned long long) 181 (unsigned long long)
184 GNUNET_TIME_absolute_get_duration (start).rel_value, ok); 182 GNUNET_TIME_absolute_get_duration (start).rel_value, ok);
185 GNUNET_CRYPTO_rsa_key_free (hostkey); 183 GNUNET_CRYPTO_rsa_key_free (hostkey);
186 if (ok != 0) 184 if (ok != 0)
187 return GNUNET_SYSERR; 185 return GNUNET_SYSERR;
@@ -208,34 +206,34 @@ testSignVerify ()
208 purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); 206 purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
209 207
210 for (i = 0; i < ITER; i++) 208 for (i = 0; i < ITER; i++)
209 {
210 fprintf (stderr, ".");
211 if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_sign (hostkey, &purp, &sig))
212 {
213 fprintf (stderr, "GNUNET_CRYPTO_rsa_sign returned SYSERR\n");
214 ok = GNUNET_SYSERR;
215 continue;
216 }
217 if (GNUNET_SYSERR ==
218 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TEST, &purp, &sig,
219 &pkey))
211 { 220 {
212 fprintf (stderr, "."); 221 printf ("GNUNET_CRYPTO_rsa_verify failed!\n");
213 if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_sign (hostkey, &purp, &sig)) 222 ok = GNUNET_SYSERR;
214 { 223 continue;
215 fprintf (stderr, "GNUNET_CRYPTO_rsa_sign returned SYSERR\n");
216 ok = GNUNET_SYSERR;
217 continue;
218 }
219 if (GNUNET_SYSERR ==
220 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TEST, &purp,
221 &sig, &pkey))
222 {
223 printf ("GNUNET_CRYPTO_rsa_verify failed!\n");
224 ok = GNUNET_SYSERR;
225 continue;
226 }
227 if (GNUNET_SYSERR !=
228 GNUNET_CRYPTO_rsa_verify
229 (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, &purp, &sig, &pkey))
230 {
231 printf ("GNUNET_CRYPTO_rsa_verify failed to fail!\n");
232 ok = GNUNET_SYSERR;
233 continue;
234 }
235 } 224 }
225 if (GNUNET_SYSERR !=
226 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
227 &purp, &sig, &pkey))
228 {
229 printf ("GNUNET_CRYPTO_rsa_verify failed to fail!\n");
230 ok = GNUNET_SYSERR;
231 continue;
232 }
233 }
236 printf ("%d RSA sign/verify operations %llums\n", ITER, 234 printf ("%d RSA sign/verify operations %llums\n", ITER,
237 (unsigned long long) 235 (unsigned long long)
238 GNUNET_TIME_absolute_get_duration (start).rel_value); 236 GNUNET_TIME_absolute_get_duration (start).rel_value);
239 GNUNET_CRYPTO_rsa_key_free (hostkey); 237 GNUNET_CRYPTO_rsa_key_free (hostkey);
240 return ok; 238 return ok;
241} 239}
@@ -260,18 +258,18 @@ testSignPerformance ()
260 GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey); 258 GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey);
261 start = GNUNET_TIME_absolute_get (); 259 start = GNUNET_TIME_absolute_get ();
262 for (i = 0; i < ITER; i++) 260 for (i = 0; i < ITER; i++)
261 {
262 fprintf (stderr, ".");
263 if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_sign (hostkey, &purp, &sig))
263 { 264 {
264 fprintf (stderr, "."); 265 fprintf (stderr, "GNUNET_CRYPTO_rsa_sign returned SYSERR\n");
265 if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_sign (hostkey, &purp, &sig)) 266 ok = GNUNET_SYSERR;
266 { 267 continue;
267 fprintf (stderr, "GNUNET_CRYPTO_rsa_sign returned SYSERR\n");
268 ok = GNUNET_SYSERR;
269 continue;
270 }
271 } 268 }
269 }
272 printf ("%d RSA sign operations %llu ms\n", ITER, 270 printf ("%d RSA sign operations %llu ms\n", ITER,
273 (unsigned long long) 271 (unsigned long long)
274 GNUNET_TIME_absolute_get_duration (start).rel_value); 272 GNUNET_TIME_absolute_get_duration (start).rel_value);
275 GNUNET_CRYPTO_rsa_key_free (hostkey); 273 GNUNET_CRYPTO_rsa_key_free (hostkey);
276 return ok; 274 return ok;
277} 275}
@@ -328,9 +326,9 @@ main (int argc, char *argv[])
328 failureCount++; 326 failureCount++;
329 327
330 if (failureCount != 0) 328 if (failureCount != 0)
331 { 329 {
332 printf ("\n\n%d TESTS FAILED!\n\n", failureCount); 330 printf ("\n\n%d TESTS FAILED!\n\n", failureCount);
333 return -1; 331 return -1;
334 } 332 }
335 return 0; 333 return 0;
336} /* end of main */ 334} /* end of main */
diff --git a/src/util/test_disk.c b/src/util/test_disk.c
index e8ec88c9f..91154a6f5 100644
--- a/src/util/test_disk.c
+++ b/src/util/test_disk.c
@@ -38,41 +38,40 @@ testReadWrite ()
38 38
39 if (strlen (TESTSTRING) != 39 if (strlen (TESTSTRING) !=
40 GNUNET_DISK_fn_write (".testfile", TESTSTRING, strlen (TESTSTRING), 40 GNUNET_DISK_fn_write (".testfile", TESTSTRING, strlen (TESTSTRING),
41 GNUNET_DISK_PERM_USER_READ | 41 GNUNET_DISK_PERM_USER_READ |
42 GNUNET_DISK_PERM_USER_WRITE)) 42 GNUNET_DISK_PERM_USER_WRITE))
43 return 1; 43 return 1;
44 if (GNUNET_OK != GNUNET_DISK_file_test (".testfile")) 44 if (GNUNET_OK != GNUNET_DISK_file_test (".testfile"))
45 return 1; 45 return 1;
46 ret = GNUNET_DISK_fn_read (".testfile", tmp, sizeof (tmp) - 1); 46 ret = GNUNET_DISK_fn_read (".testfile", tmp, sizeof (tmp) - 1);
47 if (ret < 0) 47 if (ret < 0)
48 { 48 {
49 fprintf (stderr, "Error reading file `%s' in testReadWrite\n", 49 fprintf (stderr, "Error reading file `%s' in testReadWrite\n", ".testfile");
50 ".testfile"); 50 return 1;
51 return 1; 51 }
52 }
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, "Error in testReadWrite: *%s* != *%s* for file %s\n", 55 fprintf (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", tmp,
57 tmp, TESTSTRING, ".testfile"); 56 TESTSTRING, ".testfile");
58 return 1; 57 return 1;
59 } 58 }
60 GNUNET_DISK_file_copy (".testfile", ".testfile2"); 59 GNUNET_DISK_file_copy (".testfile", ".testfile2");
61 memset (tmp, 0, sizeof (tmp)); 60 memset (tmp, 0, sizeof (tmp));
62 ret = GNUNET_DISK_fn_read (".testfile2", tmp, sizeof (tmp) - 1); 61 ret = GNUNET_DISK_fn_read (".testfile2", tmp, sizeof (tmp) - 1);
63 if (ret < 0) 62 if (ret < 0)
64 { 63 {
65 fprintf (stderr, "Error reading file `%s' in testReadWrite\n", 64 fprintf (stderr, "Error reading file `%s' in testReadWrite\n",
66 ".testfile2"); 65 ".testfile2");
67 return 1; 66 return 1;
68 } 67 }
69 tmp[ret] = '\0'; 68 tmp[ret] = '\0';
70 if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1)) 69 if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1))
71 { 70 {
72 fprintf (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", 71 fprintf (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", tmp,
73 tmp, TESTSTRING, ".testfile2"); 72 TESTSTRING, ".testfile2");
74 return 1; 73 return 1;
75 } 74 }
76 75
77 GNUNET_break (0 == UNLINK (".testfile")); 76 GNUNET_break (0 == UNLINK (".testfile"));
78 GNUNET_break (0 == UNLINK (".testfile2")); 77 GNUNET_break (0 == UNLINK (".testfile2"));
@@ -90,15 +89,15 @@ testOpenClose ()
90 long avail; 89 long avail;
91 90
92 fh = GNUNET_DISK_file_open (".testfile", 91 fh = GNUNET_DISK_file_open (".testfile",
93 GNUNET_DISK_OPEN_READWRITE | 92 GNUNET_DISK_OPEN_READWRITE |
94 GNUNET_DISK_OPEN_CREATE, 93 GNUNET_DISK_OPEN_CREATE,
95 GNUNET_DISK_PERM_USER_READ | 94 GNUNET_DISK_PERM_USER_READ |
96 GNUNET_DISK_PERM_USER_WRITE); 95 GNUNET_DISK_PERM_USER_WRITE);
97 GNUNET_assert (GNUNET_NO == GNUNET_DISK_handle_invalid (fh)); 96 GNUNET_assert (GNUNET_NO == GNUNET_DISK_handle_invalid (fh));
98 GNUNET_break (5 == GNUNET_DISK_file_write (fh, "Hello", 5)); 97 GNUNET_break (5 == GNUNET_DISK_file_write (fh, "Hello", 5));
99 GNUNET_DISK_file_close (fh); 98 GNUNET_DISK_file_close (fh);
100 GNUNET_break (GNUNET_OK == 99 GNUNET_break (GNUNET_OK ==
101 GNUNET_DISK_file_size (".testfile", &size, GNUNET_NO)); 100 GNUNET_DISK_file_size (".testfile", &size, GNUNET_NO));
102 if (size != 5) 101 if (size != 5)
103 return 1; 102 return 1;
104 GNUNET_break (0 == UNLINK (".testfile")); 103 GNUNET_break (0 == UNLINK (".testfile"));
@@ -108,19 +107,19 @@ testOpenClose ()
108 avail = GNUNET_DISK_get_blocks_available (".testfile"); 107 avail = GNUNET_DISK_get_blocks_available (".testfile");
109 GNUNET_log_skip (0, GNUNET_NO); 108 GNUNET_log_skip (0, GNUNET_NO);
110 fh = GNUNET_DISK_file_open (".testfile", 109 fh = GNUNET_DISK_file_open (".testfile",
111 GNUNET_DISK_OPEN_READWRITE | 110 GNUNET_DISK_OPEN_READWRITE |
112 GNUNET_DISK_OPEN_CREATE, 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));
116 while ((avail == GNUNET_DISK_get_blocks_available (".testfile")) && 115 while ((avail == GNUNET_DISK_get_blocks_available (".testfile")) &&
117 (avail != -1)) 116 (avail != -1))
118 if (16 != GNUNET_DISK_file_write (fh, "HelloWorld123456", 16)) 117 if (16 != GNUNET_DISK_file_write (fh, "HelloWorld123456", 16))
119 { 118 {
120 GNUNET_DISK_file_close (fh); 119 GNUNET_DISK_file_close (fh);
121 GNUNET_break (0 == UNLINK (".testfile")); 120 GNUNET_break (0 == UNLINK (".testfile"));
122 return 1; 121 return 1;
123 } 122 }
124 GNUNET_DISK_file_close (fh); 123 GNUNET_DISK_file_close (fh);
125 GNUNET_break (0 == UNLINK (".testfile")); 124 GNUNET_break (0 == UNLINK (".testfile"));
126 125
@@ -147,7 +146,7 @@ testDirScan ()
147 GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry_more")) 146 GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry_more"))
148 return 1; 147 return 1;
149 GNUNET_DISK_directory_scan ("test", &scan_callback, 148 GNUNET_DISK_directory_scan ("test", &scan_callback,
150 "test" DIR_SEPARATOR_STR "entry"); 149 "test" DIR_SEPARATOR_STR "entry");
151 if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) 150 if (GNUNET_OK != GNUNET_DISK_directory_remove ("test"))
152 return 1; 151 return 1;
153 if (ok < 2) 152 if (ok < 2)
@@ -157,7 +156,7 @@ testDirScan ()
157 156
158static void 157static void
159iter_callback (void *cls, struct GNUNET_DISK_DirectoryIterator *di, 158iter_callback (void *cls, struct GNUNET_DISK_DirectoryIterator *di,
160 const char *filename, const char *dirname) 159 const char *filename, const char *dirname)
161{ 160{
162 int *i = cls; 161 int *i = cls;
163 162
@@ -169,7 +168,7 @@ static void
169iter_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 168iter_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
170{ 169{
171 GNUNET_DISK_directory_iterator_start (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 170 GNUNET_DISK_directory_iterator_start (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
172 "test", &iter_callback, cls); 171 "test", &iter_callback, cls);
173} 172}
174 173
175static int 174static int
@@ -203,14 +202,14 @@ testGetHome ()
203 cfg = GNUNET_CONFIGURATION_create (); 202 cfg = GNUNET_CONFIGURATION_create ();
204 GNUNET_assert (cfg != NULL); 203 GNUNET_assert (cfg != NULL);
205 GNUNET_CONFIGURATION_set_value_string (cfg, "service", "HOME", 204 GNUNET_CONFIGURATION_set_value_string (cfg, "service", "HOME",
206 "/tmp/test-gnunet-disk-a/b/c"); 205 "/tmp/test-gnunet-disk-a/b/c");
207 fn = GNUNET_DISK_get_home_filename (cfg, "service", "d", "e", NULL); 206 fn = GNUNET_DISK_get_home_filename (cfg, "service", "d", "e", NULL);
208 GNUNET_assert (fn != NULL); 207 GNUNET_assert (fn != NULL);
209 GNUNET_CONFIGURATION_destroy (cfg); 208 GNUNET_CONFIGURATION_destroy (cfg);
210 ret = strcmp ("/tmp/test-gnunet-disk-a/b/c/d/e", fn); 209 ret = strcmp ("/tmp/test-gnunet-disk-a/b/c/d/e", fn);
211 GNUNET_free (fn); 210 GNUNET_free (fn);
212 GNUNET_break (GNUNET_OK == 211 GNUNET_break (GNUNET_OK ==
213 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-disk-a")); 212 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-disk-a"));
214 return ret; 213 return ret;
215} 214}
216 215
@@ -221,10 +220,10 @@ testCanonicalize ()
221 220
222 GNUNET_DISK_filename_canonicalize (fn); 221 GNUNET_DISK_filename_canonicalize (fn);
223 if (0 != strcmp (fn, "ab____cd_ef__g_")) 222 if (0 != strcmp (fn, "ab____cd_ef__g_"))
224 { 223 {
225 GNUNET_free (fn); 224 GNUNET_free (fn);
226 return 1; 225 return 1;
227 } 226 }
228 GNUNET_free (fn); 227 GNUNET_free (fn);
229 return 0; 228 return 0;
230} 229}
@@ -276,9 +275,9 @@ main (int argc, char *argv[])
276 failureCount += testChangeOwner (); 275 failureCount += testChangeOwner ();
277 failureCount += testDirMani (); 276 failureCount += testDirMani ();
278 if (failureCount != 0) 277 if (failureCount != 0)
279 { 278 {
280 fprintf (stderr, "\n%u TESTS FAILED!\n", failureCount); 279 fprintf (stderr, "\n%u TESTS FAILED!\n", failureCount);
281 return -1; 280 return -1;
282 } 281 }
283 return 0; 282 return 0;
284} /* end of main */ 283} /* end of main */
diff --git a/src/util/test_getopt.c b/src/util/test_getopt.c
index f830454cd..a517887bf 100644
--- a/src/util/test_getopt.c
+++ b/src/util/test_getopt.c
@@ -63,15 +63,15 @@ testVerbose ()
63 }; 63 };
64 64
65 if (3 != GNUNET_GETOPT_run ("test", verboseoptionlist, 4, myargv)) 65 if (3 != GNUNET_GETOPT_run ("test", verboseoptionlist, 4, myargv))
66 { 66 {
67 GNUNET_break (0); 67 GNUNET_break (0);
68 return 1; 68 return 1;
69 } 69 }
70 if (vflags != 2) 70 if (vflags != 2)
71 { 71 {
72 GNUNET_break (0); 72 GNUNET_break (0);
73 return 1; 73 return 1;
74 } 74 }
75 return 0; 75 return 0;
76} 76}
77 77
@@ -89,10 +89,10 @@ testVersion ()
89 }; 89 };
90 90
91 if (-1 != GNUNET_GETOPT_run ("test_getopt", versionoptionlist, 2, myargv)) 91 if (-1 != GNUNET_GETOPT_run ("test_getopt", versionoptionlist, 2, myargv))
92 { 92 {
93 GNUNET_break (0); 93 GNUNET_break (0);
94 return 1; 94 return 1;
95 } 95 }
96 return 0; 96 return 0;
97} 97}
98 98
@@ -110,10 +110,10 @@ testAbout ()
110 }; 110 };
111 111
112 if (-1 != GNUNET_GETOPT_run ("test_getopt", aboutoptionlist, 2, myargv)) 112 if (-1 != GNUNET_GETOPT_run ("test_getopt", aboutoptionlist, 2, myargv))
113 { 113 {
114 GNUNET_break (0); 114 GNUNET_break (0);
115 return 1; 115 return 1;
116 } 116 }
117 return 0; 117 return 0;
118} 118}
119 119
@@ -136,18 +136,18 @@ testLogOpts ()
136 }; 136 };
137 137
138 if (5 != GNUNET_GETOPT_run ("test_getopt", logoptionlist, 5, myargv)) 138 if (5 != GNUNET_GETOPT_run ("test_getopt", logoptionlist, 5, myargv))
139 { 139 {
140 GNUNET_break (0); 140 GNUNET_break (0);
141 return 1; 141 return 1;
142 } 142 }
143 GNUNET_assert (fn != NULL); 143 GNUNET_assert (fn != NULL);
144 if ((0 != strcmp (level, "WARNING")) || (0 != strcmp (fn, "filename"))) 144 if ((0 != strcmp (level, "WARNING")) || (0 != strcmp (fn, "filename")))
145 { 145 {
146 GNUNET_break (0); 146 GNUNET_break (0);
147 GNUNET_free (level); 147 GNUNET_free (level);
148 GNUNET_free (fn); 148 GNUNET_free (fn);
149 return 1; 149 return 1;
150 } 150 }
151 GNUNET_free (level); 151 GNUNET_free (level);
152 GNUNET_free (fn); 152 GNUNET_free (fn);
153 return 0; 153 return 0;
@@ -178,15 +178,15 @@ testFlagNum ()
178 }; 178 };
179 179
180 if (6 != GNUNET_GETOPT_run ("test_getopt", logoptionlist, 6, myargv)) 180 if (6 != GNUNET_GETOPT_run ("test_getopt", logoptionlist, 6, myargv))
181 { 181 {
182 GNUNET_break (0); 182 GNUNET_break (0);
183 return 1; 183 return 1;
184 } 184 }
185 if ((1 != flag) || (42 != num) || (42 != lnum)) 185 if ((1 != flag) || (42 != num) || (42 != lnum))
186 { 186 {
187 GNUNET_break (0); 187 GNUNET_break (0);
188 return 1; 188 return 1;
189 } 189 }
190 return 0; 190 return 0;
191} 191}
192 192
diff --git a/src/util/test_os_network.c b/src/util/test_os_network.c
index 28cc9cd3a..315f97d97 100644
--- a/src/util/test_os_network.c
+++ b/src/util/test_os_network.c
@@ -44,10 +44,10 @@ proc (void *cls, const char *name, int isDefault, const struct sockaddr *addr,
44 return GNUNET_OK; 44 return GNUNET_OK;
45 45
46 inet_ntop (addr->sa_family, 46 inet_ntop (addr->sa_family,
47 (addr->sa_family == 47 (addr->sa_family ==
48 AF_INET) ? (void *) &((struct sockaddr_in *) addr)->sin_addr 48 AF_INET) ? (void *) &((struct sockaddr_in *) addr)->sin_addr
49 : (void *) &((struct sockaddr_in6 *) addr)->sin6_addr, buf, 49 : (void *) &((struct sockaddr_in6 *) addr)->sin6_addr, buf,
50 sizeof (buf)); 50 sizeof (buf));
51 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)))
52 *ok = 0; 52 *ok = 0;
53 return GNUNET_OK; 53 return GNUNET_OK;
diff --git a/src/util/test_os_priority.c b/src/util/test_os_priority.c
index 59f3ee816..94e2719a2 100644
--- a/src/util/test_os_priority.c
+++ b/src/util/test_os_priority.c
@@ -32,27 +32,27 @@ testprio ()
32{ 32{
33 if (GNUNET_OK != 33 if (GNUNET_OK !=
34 GNUNET_OS_set_process_priority (GNUNET_OS_process_current (), 34 GNUNET_OS_set_process_priority (GNUNET_OS_process_current (),
35 GNUNET_SCHEDULER_PRIORITY_DEFAULT)) 35 GNUNET_SCHEDULER_PRIORITY_DEFAULT))
36 return 1; 36 return 1;
37 if (GNUNET_OK != 37 if (GNUNET_OK !=
38 GNUNET_OS_set_process_priority (GNUNET_OS_process_current (), 38 GNUNET_OS_set_process_priority (GNUNET_OS_process_current (),
39 GNUNET_SCHEDULER_PRIORITY_UI)) 39 GNUNET_SCHEDULER_PRIORITY_UI))
40 return 1; 40 return 1;
41 if (GNUNET_OK != 41 if (GNUNET_OK !=
42 GNUNET_OS_set_process_priority (GNUNET_OS_process_current (), 42 GNUNET_OS_set_process_priority (GNUNET_OS_process_current (),
43 GNUNET_SCHEDULER_PRIORITY_IDLE)) 43 GNUNET_SCHEDULER_PRIORITY_IDLE))
44 return 1; 44 return 1;
45 if (GNUNET_OK != 45 if (GNUNET_OK !=
46 GNUNET_OS_set_process_priority (GNUNET_OS_process_current (), 46 GNUNET_OS_set_process_priority (GNUNET_OS_process_current (),
47 GNUNET_SCHEDULER_PRIORITY_BACKGROUND)) 47 GNUNET_SCHEDULER_PRIORITY_BACKGROUND))
48 return 1; 48 return 1;
49 if (GNUNET_OK != 49 if (GNUNET_OK !=
50 GNUNET_OS_set_process_priority (GNUNET_OS_process_current (), 50 GNUNET_OS_set_process_priority (GNUNET_OS_process_current (),
51 GNUNET_SCHEDULER_PRIORITY_HIGH)) 51 GNUNET_SCHEDULER_PRIORITY_HIGH))
52 return 1; 52 return 1;
53 if (GNUNET_OK != 53 if (GNUNET_OK !=
54 GNUNET_OS_set_process_priority (GNUNET_OS_process_current (), 54 GNUNET_OS_set_process_priority (GNUNET_OS_process_current (),
55 GNUNET_SCHEDULER_PRIORITY_HIGH)) 55 GNUNET_SCHEDULER_PRIORITY_HIGH))
56 return 1; 56 return 1;
57 return 0; 57 return 0;
58} 58}
diff --git a/src/util/test_os_start_process.c b/src/util/test_os_start_process.c
index 918ef1bc5..df8520546 100644
--- a/src/util/test_os_start_process.c
+++ b/src/util/test_os_start_process.c
@@ -53,9 +53,9 @@ end_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
53{ 53{
54 54
55 if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) 55 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
56 { 56 {
57 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 57 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
58 } 58 }
59 GNUNET_OS_process_wait (proc); 59 GNUNET_OS_process_wait (proc);
60 GNUNET_OS_process_close (proc); 60 GNUNET_OS_process_close (proc);
61 proc = NULL; 61 proc = NULL;
@@ -79,28 +79,28 @@ read_call (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
79#endif 79#endif
80 80
81 if (bytes < 1) 81 if (bytes < 1)
82 { 82 {
83 GNUNET_break (0); 83 GNUNET_break (0);
84 ok = 1; 84 ok = 1;
85 GNUNET_SCHEDULER_cancel (die_task); 85 GNUNET_SCHEDULER_cancel (die_task);
86 GNUNET_SCHEDULER_add_now (&end_task, NULL); 86 GNUNET_SCHEDULER_add_now (&end_task, NULL);
87 return; 87 return;
88 } 88 }
89 89
90 ok = strncmp (&buf[0], test_phrase, strlen (test_phrase)); 90 ok = strncmp (&buf[0], test_phrase, strlen (test_phrase));
91#if VERBOSE 91#if VERBOSE
92 fprintf (stderr, "read %s\n", &buf[0]); 92 fprintf (stderr, "read %s\n", &buf[0]);
93#endif 93#endif
94 if (ok == 0) 94 if (ok == 0)
95 { 95 {
96 GNUNET_SCHEDULER_cancel (die_task); 96 GNUNET_SCHEDULER_cancel (die_task);
97 GNUNET_SCHEDULER_add_now (&end_task, NULL); 97 GNUNET_SCHEDULER_add_now (&end_task, NULL);
98 return; 98 return;
99 } 99 }
100 100
101 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 101 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
102 stdout_read_handle, &read_call, 102 stdout_read_handle, &read_call,
103 stdout_read_handle); 103 stdout_read_handle);
104 104
105} 105}
106 106
@@ -118,16 +118,16 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
118 hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES); 118 hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
119 119
120 if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL)) 120 if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL))
121 { 121 {
122 GNUNET_break (0); 122 GNUNET_break (0);
123 ok = 1; 123 ok = 1;
124 GNUNET_free (fn); 124 GNUNET_free (fn);
125 return; 125 return;
126 } 126 }
127 127
128 proc = 128 proc =
129 GNUNET_OS_start_process (hello_pipe_stdin, hello_pipe_stdout, fn, 129 GNUNET_OS_start_process (hello_pipe_stdin, hello_pipe_stdout, fn,
130 "test_gnunet_echo_hello", "-", NULL); 130 "test_gnunet_echo_hello", "-", NULL);
131 GNUNET_free (fn); 131 GNUNET_free (fn);
132 132
133 /* Close the write end of the read pipe */ 133 /* Close the write end of the read pipe */
@@ -140,26 +140,26 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
140 /* Write the test_phrase to the cat process */ 140 /* Write the test_phrase to the cat process */
141 if (GNUNET_DISK_file_write (wh, test_phrase, strlen (test_phrase) + 1) != 141 if (GNUNET_DISK_file_write (wh, test_phrase, strlen (test_phrase) + 1) !=
142 strlen (test_phrase) + 1) 142 strlen (test_phrase) + 1)
143 { 143 {
144 GNUNET_break (0); 144 GNUNET_break (0);
145 ok = 1; 145 ok = 1;
146 return; 146 return;
147 } 147 }
148 148
149 /* Close the write end to end the cycle! */ 149 /* Close the write end to end the cycle! */
150 GNUNET_DISK_pipe_close_end (hello_pipe_stdin, GNUNET_DISK_PIPE_END_WRITE); 150 GNUNET_DISK_pipe_close_end (hello_pipe_stdin, GNUNET_DISK_PIPE_END_WRITE);
151 151
152 stdout_read_handle = 152 stdout_read_handle =
153 GNUNET_DISK_pipe_handle (hello_pipe_stdout, GNUNET_DISK_PIPE_END_READ); 153 GNUNET_DISK_pipe_handle (hello_pipe_stdout, GNUNET_DISK_PIPE_END_READ);
154 154
155 die_task = 155 die_task =
156 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 156 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
157 (GNUNET_TIME_UNIT_MINUTES, 1), &end_task, 157 (GNUNET_TIME_UNIT_MINUTES, 1), &end_task,
158 NULL); 158 NULL);
159 159
160 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 160 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
161 stdout_read_handle, &read_call, 161 stdout_read_handle, &read_call,
162 (void *) stdout_read_handle); 162 (void *) stdout_read_handle);
163 163
164} 164}
165 165
@@ -183,11 +183,11 @@ main (int argc, char *argv[])
183 183
184 GNUNET_log_setup ("test-os-start-process", 184 GNUNET_log_setup ("test-os-start-process",
185#if VERBOSE 185#if VERBOSE
186 "DEBUG", 186 "DEBUG",
187#else 187#else
188 "WARNING", 188 "WARNING",
189#endif 189#endif
190 NULL); 190 NULL);
191 ret = check (); 191 ret = check ();
192 192
193 return ret; 193 return ret;
diff --git a/src/util/test_peer.c b/src/util/test_peer.c
index 5bf5108bc..3817d8243 100644
--- a/src/util/test_peer.c
+++ b/src/util/test_peer.c
@@ -43,13 +43,13 @@ generatePeerIdList ()
43 int i; 43 int i;
44 44
45 for (i = 0; i < NUMBER_OF_PEERS; i++) 45 for (i = 0; i < NUMBER_OF_PEERS; i++)
46 { 46 {
47 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, 47 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
48 &pidArr[i].hashPubKey); 48 &pidArr[i].hashPubKey);
49#if DEBUG 49#if DEBUG
50 printf ("Peer %d: %s\n", i, GNUNET_i2s (&pidArr[i])); 50 printf ("Peer %d: %s\n", i, GNUNET_i2s (&pidArr[i]));
51#endif 51#endif
52 } 52 }
53} 53}
54 54
55 55
@@ -65,27 +65,25 @@ check ()
65 GNUNET_assert (0 == GNUNET_PEER_intern (NULL)); 65 GNUNET_assert (0 == GNUNET_PEER_intern (NULL));
66 /* Insert Peers into PeerEntry table and hashmap */ 66 /* Insert Peers into PeerEntry table and hashmap */
67 for (i = 0; i < NUMBER_OF_PEERS; i++) 67 for (i = 0; i < NUMBER_OF_PEERS; i++)
68 {
69 pid = GNUNET_PEER_intern (&pidArr[i]);
70 if (pid != (i + 1))
68 { 71 {
69 pid = GNUNET_PEER_intern (&pidArr[i]); 72 fprintf (stderr, "Unexpected Peer ID returned by intern function\n");
70 if (pid != (i + 1)) 73 return 1;
71 {
72 fprintf (stderr,
73 "Unexpected Peer ID returned by intern function\n");
74 return 1;
75 }
76 } 74 }
75 }
77 76
78 /* Referencing the first 3 peers once again */ 77 /* Referencing the first 3 peers once again */
79 for (i = 0; i < 3; i++) 78 for (i = 0; i < 3; i++)
79 {
80 pid = GNUNET_PEER_intern (&pidArr[i]);
81 if (pid != (i + 1))
80 { 82 {
81 pid = GNUNET_PEER_intern (&pidArr[i]); 83 fprintf (stderr, "Unexpected Peer ID returned by intern function\n");
82 if (pid != (i + 1)) 84 return 1;
83 {
84 fprintf (stderr,
85 "Unexpected Peer ID returned by intern function\n");
86 return 1;
87 }
88 } 85 }
86 }
89 87
90 /* Dereferencing the first 3 peers once [decrementing their reference count] */ 88 /* Dereferencing the first 3 peers once [decrementing their reference count] */
91 GNUNET_PEER_decrement_rcs (ids, 3); 89 GNUNET_PEER_decrement_rcs (ids, 3);
@@ -130,11 +128,11 @@ main ()
130 128
131 GNUNET_log_setup ("test-peer", "ERROR", NULL); 129 GNUNET_log_setup ("test-peer", "ERROR", NULL);
132 for (i = 0; i < 1; i++) 130 for (i = 0; i < 1; i++)
133 { 131 {
134 generatePeerIdList (); 132 generatePeerIdList ();
135 if (0 != check ()) 133 if (0 != check ())
136 return 1; 134 return 1;
137 } 135 }
138 return 0; 136 return 0;
139} 137}
140 138
diff --git a/src/util/test_plugin.c b/src/util/test_plugin.c
index bfa3cf110..4635e1357 100644
--- a/src/util/test_plugin.c
+++ b/src/util/test_plugin.c
@@ -27,9 +27,7 @@
27#define VERBOSE GNUNET_EXTRA_LOGGING 27#define VERBOSE GNUNET_EXTRA_LOGGING
28 28
29static void 29static void
30test_cb (void *cls, 30test_cb (void *cls, const char *libname, void *lib_ret)
31 const char *libname,
32 void *lib_ret)
33{ 31{
34 void *ret; 32 void *ret;
35 33
@@ -39,7 +37,7 @@ test_cb (void *cls,
39 GNUNET_assert (NULL != ret); 37 GNUNET_assert (NULL != ret);
40 GNUNET_assert (0 == strcmp (ret, "World")); 38 GNUNET_assert (0 == strcmp (ret, "World"));
41} 39}
42 40
43 41
44static int 42static int
45check () 43check ()
diff --git a/src/util/test_program.c b/src/util/test_program.c
index 0ff49b81e..faeb4e716 100644
--- a/src/util/test_program.c
+++ b/src/util/test_program.c
@@ -58,7 +58,7 @@ static struct GNUNET_GETOPT_CommandLineOption options4[] = {
58 58
59static void 59static void
60runner (void *cls, char *const *args, const char *cfgfile, 60runner (void *cls, char *const *args, const char *cfgfile,
61 const struct GNUNET_CONFIGURATION_Handle *cfg) 61 const struct GNUNET_CONFIGURATION_Handle *cfg)
62{ 62{
63 int *ok = cls; 63 int *ok = cls;
64 64
@@ -91,18 +91,18 @@ check ()
91 }; 91 };
92 92
93 GNUNET_assert (GNUNET_OK == 93 GNUNET_assert (GNUNET_OK ==
94 GNUNET_PROGRAM_run (7, argv, "test_program", "A test", 94 GNUNET_PROGRAM_run (7, argv, "test_program", "A test",
95 options1, &runner, &ok)); 95 options1, &runner, &ok));
96 96
97 GNUNET_assert (GNUNET_OK == 97 GNUNET_assert (GNUNET_OK ==
98 GNUNET_PROGRAM_run (7, argv, "test_program", "A test", 98 GNUNET_PROGRAM_run (7, argv, "test_program", "A test",
99 options2, &runner, &ok)); 99 options2, &runner, &ok));
100 GNUNET_assert (GNUNET_OK == 100 GNUNET_assert (GNUNET_OK ==
101 GNUNET_PROGRAM_run (7, argv, "test_program", "A test", 101 GNUNET_PROGRAM_run (7, argv, "test_program", "A test",
102 options3, &runner, &ok)); 102 options3, &runner, &ok));
103 GNUNET_assert (GNUNET_OK == 103 GNUNET_assert (GNUNET_OK ==
104 GNUNET_PROGRAM_run (7, argv, "test_program", "A test", 104 GNUNET_PROGRAM_run (7, argv, "test_program", "A test",
105 options4, &runner, &ok)); 105 options4, &runner, &ok));
106 106
107 return ok; 107 return ok;
108} 108}
diff --git a/src/util/test_pseudonym.c b/src/util/test_pseudonym.c
index 30a04598c..20a3d3d96 100644
--- a/src/util/test_pseudonym.c
+++ b/src/util/test_pseudonym.c
@@ -45,16 +45,16 @@ iter (void *cls, const GNUNET_HashCode * pseudonym,
45 45
46 if ((0 == memcmp (pseudonym, &id1, sizeof (GNUNET_HashCode))) && 46 if ((0 == memcmp (pseudonym, &id1, sizeof (GNUNET_HashCode))) &&
47 (!GNUNET_CONTAINER_meta_data_test_equal (md, meta))) 47 (!GNUNET_CONTAINER_meta_data_test_equal (md, meta)))
48 { 48 {
49 *ok = GNUNET_NO; 49 *ok = GNUNET_NO;
50 GNUNET_break (0); 50 GNUNET_break (0);
51 } 51 }
52 return GNUNET_OK; 52 return GNUNET_OK;
53} 53}
54 54
55static int 55static int
56noti_callback (void *cls, const GNUNET_HashCode * pseudonym, 56noti_callback (void *cls, const GNUNET_HashCode * pseudonym,
57 const struct GNUNET_CONTAINER_MetaData *md, int rating) 57 const struct GNUNET_CONTAINER_MetaData *md, int rating)
58{ 58{
59 int *ret = cls; 59 int *ret = cls;
60 60
@@ -64,7 +64,7 @@ noti_callback (void *cls, const GNUNET_HashCode * pseudonym,
64 64
65static int 65static int
66fake_noti_callback (void *cls, const GNUNET_HashCode * pseudonym, 66fake_noti_callback (void *cls, const GNUNET_HashCode * pseudonym,
67 const struct GNUNET_CONTAINER_MetaData *md, int rating) 67 const struct GNUNET_CONTAINER_MetaData *md, int rating)
68{ 68{
69 int *ret = cls; 69 int *ret = cls;
70 70
@@ -74,7 +74,7 @@ fake_noti_callback (void *cls, const GNUNET_HashCode * pseudonym,
74 74
75static int 75static int
76false_callback (void *cls, const GNUNET_HashCode * pseudonym, 76false_callback (void *cls, const GNUNET_HashCode * pseudonym,
77 const struct GNUNET_CONTAINER_MetaData *md, int rating) 77 const struct GNUNET_CONTAINER_MetaData *md, int rating)
78{ 78{
79 return GNUNET_OK; 79 return GNUNET_OK;
80} 80}
@@ -109,28 +109,28 @@ main (int argc, char *argv[])
109 (void) GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test"); 109 (void) GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test");
110 cfg = GNUNET_CONFIGURATION_create (); 110 cfg = GNUNET_CONFIGURATION_create ();
111 if (-1 == GNUNET_CONFIGURATION_parse (cfg, "test_pseudonym_data.conf")) 111 if (-1 == GNUNET_CONFIGURATION_parse (cfg, "test_pseudonym_data.conf"))
112 { 112 {
113 GNUNET_CONFIGURATION_destroy (cfg); 113 GNUNET_CONFIGURATION_destroy (cfg);
114 GNUNET_break (0); 114 GNUNET_break (0);
115 return -1; 115 return -1;
116 } 116 }
117 notiCount = 0; 117 notiCount = 0;
118 fakenotiCount = 0; 118 fakenotiCount = 0;
119 count = 0; 119 count = 0;
120 GNUNET_PSEUDONYM_discovery_callback_register (cfg, &fake_noti_callback, 120 GNUNET_PSEUDONYM_discovery_callback_register (cfg, &fake_noti_callback,
121 &fakenotiCount); 121 &fakenotiCount);
122 GNUNET_PSEUDONYM_discovery_callback_register (cfg, &noti_callback, 122 GNUNET_PSEUDONYM_discovery_callback_register (cfg, &noti_callback,
123 &notiCount); 123 &notiCount);
124 GNUNET_PSEUDONYM_discovery_callback_unregister (&false_callback, &count); 124 GNUNET_PSEUDONYM_discovery_callback_unregister (&false_callback, &count);
125 GNUNET_PSEUDONYM_discovery_callback_unregister (&fake_noti_callback, 125 GNUNET_PSEUDONYM_discovery_callback_unregister (&fake_noti_callback,
126 &fakenotiCount); 126 &fakenotiCount);
127 127
128 /* ACTUAL TEST CODE */ 128 /* ACTUAL TEST CODE */
129 old = GNUNET_PSEUDONYM_list_all (cfg, NULL, NULL); 129 old = GNUNET_PSEUDONYM_list_all (cfg, NULL, NULL);
130 meta = GNUNET_CONTAINER_meta_data_create (); 130 meta = GNUNET_CONTAINER_meta_data_create ();
131 GNUNET_CONTAINER_meta_data_insert (meta, "<test>", EXTRACTOR_METATYPE_TITLE, 131 GNUNET_CONTAINER_meta_data_insert (meta, "<test>", EXTRACTOR_METATYPE_TITLE,
132 EXTRACTOR_METAFORMAT_UTF8, "text/plain", 132 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
133 "test", strlen ("test") + 1); 133 "test", strlen ("test") + 1);
134 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id1); 134 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id1);
135 GNUNET_PSEUDONYM_add (cfg, &id1, meta); 135 GNUNET_PSEUDONYM_add (cfg, &id1, meta);
136 CHECK (notiCount == 1); 136 CHECK (notiCount == 1);
@@ -145,11 +145,11 @@ main (int argc, char *argv[])
145 newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok); 145 newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok);
146 CHECK (old < newVal); 146 CHECK (old < newVal);
147 GNUNET_assert (GNUNET_OK == 147 GNUNET_assert (GNUNET_OK ==
148 GNUNET_CONTAINER_meta_data_insert (meta, "<test>", 148 GNUNET_CONTAINER_meta_data_insert (meta, "<test>",
149 EXTRACTOR_METATYPE_COMMENT, 149 EXTRACTOR_METATYPE_COMMENT,
150 EXTRACTOR_METAFORMAT_UTF8, 150 EXTRACTOR_METAFORMAT_UTF8,
151 "text/plain", m, 151 "text/plain", m,
152 strlen (m) + 1)); 152 strlen (m) + 1));
153 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id3); 153 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id3);
154 GNUNET_PSEUDONYM_add (cfg, &id3, meta); 154 GNUNET_PSEUDONYM_add (cfg, &id3, meta);
155 name3 = GNUNET_PSEUDONYM_id_to_name (cfg, &id3); 155 name3 = GNUNET_PSEUDONYM_id_to_name (cfg, &id3);
@@ -184,7 +184,7 @@ FAILURE:
184 GNUNET_CONTAINER_meta_data_destroy (meta); 184 GNUNET_CONTAINER_meta_data_destroy (meta);
185 GNUNET_CONFIGURATION_destroy (cfg); 185 GNUNET_CONFIGURATION_destroy (cfg);
186 GNUNET_break (GNUNET_OK == 186 GNUNET_break (GNUNET_OK ==
187 GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test")); 187 GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test"));
188 return (ok == GNUNET_YES) ? 0 : 1; 188 return (ok == GNUNET_YES) ? 0 : 1;
189} 189}
190 190
diff --git a/src/util/test_resolver_api.c b/src/util/test_resolver_api.c
index 24c71b41f..4e248aa72 100644
--- a/src/util/test_resolver_api.c
+++ b/src/util/test_resolver_api.c
@@ -46,13 +46,12 @@ check_hostname (void *cls, const struct sockaddr *sa, socklen_t salen)
46 int *ok = cls; 46 int *ok = cls;
47 47
48 if (salen == 0) 48 if (salen == 0)
49 { 49 {
50 (*ok) &= ~8; 50 (*ok) &= ~8;
51 return; 51 return;
52 } 52 }
53 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 53 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Got IP address `%s' for our host.\n"),
54 _("Got IP address `%s' for our host.\n"), GNUNET_a2s (sa, 54 GNUNET_a2s (sa, salen));
55 salen));
56} 55}
57 56
58 57
@@ -64,21 +63,21 @@ check_localhost_num (void *cls, const char *hostname)
64 if (hostname == NULL) 63 if (hostname == NULL)
65 return; 64 return;
66 if (0 == strcmp (hostname, "127.0.0.1")) 65 if (0 == strcmp (hostname, "127.0.0.1"))
67 { 66 {
68#if DEBUG_RESOLVER 67#if DEBUG_RESOLVER
69 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 68 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct hostname `%s'.\n",
70 "Received correct hostname `%s'.\n", hostname); 69 hostname);
71#endif 70#endif
72 (*ok) &= ~4; 71 (*ok) &= ~4;
73 } 72 }
74 else 73 else
75 { 74 {
76#if DEBUG_RESOLVER 75#if DEBUG_RESOLVER
77 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 76 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received invalid hostname `%s'.\n",
78 "Received invalid hostname `%s'.\n", hostname); 77 hostname);
79#endif 78#endif
80 GNUNET_break (0); 79 GNUNET_break (0);
81 } 80 }
82} 81}
83 82
84 83
@@ -90,19 +89,19 @@ check_localhost (void *cls, const char *hostname)
90 if (hostname == NULL) 89 if (hostname == NULL)
91 return; 90 return;
92 if (0 == strcmp (hostname, "localhost")) 91 if (0 == strcmp (hostname, "localhost"))
93 { 92 {
94#if DEBUG_RESOLVER 93#if DEBUG_RESOLVER
95 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 94 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct hostname `%s'.\n",
96 "Received correct hostname `%s'.\n", hostname); 95 hostname);
97#endif 96#endif
98 (*ok) &= ~2; 97 (*ok) &= ~2;
99 } 98 }
100 else 99 else
101 { 100 {
102 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 101 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
103 "Received unexpected hostname `%s', expected `localhost' (this could be OK).\n", 102 "Received unexpected hostname `%s', expected `localhost' (this could be OK).\n",
104 hostname); 103 hostname);
105 } 104 }
106} 105}
107 106
108static void 107static void
@@ -115,19 +114,19 @@ check_127 (void *cls, const struct sockaddr *sa, socklen_t salen)
115 return; 114 return;
116 GNUNET_assert (sizeof (struct sockaddr_in) == salen); 115 GNUNET_assert (sizeof (struct sockaddr_in) == salen);
117 if (sai->sin_addr.s_addr == htonl (INADDR_LOOPBACK)) 116 if (sai->sin_addr.s_addr == htonl (INADDR_LOOPBACK))
118 { 117 {
119#if DEBUG_RESOLVER 118#if DEBUG_RESOLVER
120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct address.\n"); 119 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct address.\n");
121#endif 120#endif
122 (*ok) &= ~1; 121 (*ok) &= ~1;
123 } 122 }
124 else 123 else
125 { 124 {
126#if DEBUG_RESOLVER 125#if DEBUG_RESOLVER
127 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received incorrect address.\n"); 126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received incorrect address.\n");
128#endif 127#endif
129 GNUNET_break (0); 128 GNUNET_break (0);
130 } 129 }
131} 130}
132 131
133static void 132static void
@@ -139,32 +138,32 @@ check_local_fqdn (void *cls, const char *gnunet_fqdn)
139 char hostname[GNUNET_OS_get_hostname_max_length () + 1]; 138 char hostname[GNUNET_OS_get_hostname_max_length () + 1];
140 139
141 if (0 != gethostname (hostname, sizeof (hostname) - 1)) 140 if (0 != gethostname (hostname, sizeof (hostname) - 1))
142 { 141 {
143 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 142 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
144 "gethostname"); 143 "gethostname");
145 return; 144 return;
146 } 145 }
147#if DEBUG_RESOLVER 146#if DEBUG_RESOLVER
148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolving our FQDN `%s'\n"), 147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolving our FQDN `%s'\n"),
149 hostname); 148 hostname);
150#endif 149#endif
151 host = gethostbyname (hostname); 150 host = gethostbyname (hostname);
152 if (NULL == host) 151 if (NULL == host)
153 { 152 {
154 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 153 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
155 _("Could not resolve our FQDN : %s %u\n"), 154 _("Could not resolve our FQDN : %s %u\n"), hstrerror (h_errno),
156 hstrerror (h_errno), h_errno); 155 h_errno);
157 return; 156 return;
158 } 157 }
159 158
160 GNUNET_assert (0 != host); 159 GNUNET_assert (0 != host);
161 160
162 result = strcmp (host->h_name, gnunet_fqdn); 161 result = strcmp (host->h_name, gnunet_fqdn);
163 if (0 != result) 162 if (0 != result)
164 { 163 {
165 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 164 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
166 "Local resolved and resolver resolved fqdns are not equal\n"); 165 "Local resolved and resolver resolved fqdns are not equal\n");
167 } 166 }
168 GNUNET_assert (0 == result); 167 GNUNET_assert (0 == result);
169} 168}
170 169
@@ -181,21 +180,21 @@ check_rootserver_ip (void *cls, const struct sockaddr *sa, socklen_t salen)
181 GNUNET_assert (sizeof (struct sockaddr_in) == salen); 180 GNUNET_assert (sizeof (struct sockaddr_in) == salen);
182 181
183 if (0 == strcmp (inet_ntoa (sai->sin_addr), ROOTSERVER_IP)) 182 if (0 == strcmp (inet_ntoa (sai->sin_addr), ROOTSERVER_IP))
184 { 183 {
185#if DEBUG_RESOLVER 184#if DEBUG_RESOLVER
186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
187 "Received correct rootserver ip address.\n"); 186 "Received correct rootserver ip address.\n");
188#endif 187#endif
189 (*ok) &= ~1; 188 (*ok) &= ~1;
190 } 189 }
191 else 190 else
192 { 191 {
193#if DEBUG_RESOLVER 192#if DEBUG_RESOLVER
194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
195 "Received incorrect rootserver ip address.\n"); 194 "Received incorrect rootserver ip address.\n");
196#endif 195#endif
197 GNUNET_break (0); 196 GNUNET_break (0);
198 } 197 }
199} 198}
200 199
201static void 200static void
@@ -207,21 +206,21 @@ check_rootserver_name (void *cls, const char *hostname)
207 return; 206 return;
208 207
209 if (0 == strcmp (hostname, ROOTSERVER_NAME)) 208 if (0 == strcmp (hostname, ROOTSERVER_NAME))
210 { 209 {
211#if DEBUG_RESOLVER 210#if DEBUG_RESOLVER
212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
213 "Received correct rootserver hostname `%s'.\n", hostname); 212 "Received correct rootserver hostname `%s'.\n", hostname);
214#endif 213#endif
215 (*ok) &= ~2; 214 (*ok) &= ~2;
216 } 215 }
217 else 216 else
218 { 217 {
219#if DEBUG_RESOLVER 218#if DEBUG_RESOLVER
220 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
221 "Received invalid rootserver hostname `%s'.\n", hostname); 220 "Received invalid rootserver hostname `%s'.\n", hostname);
222#endif 221#endif
223 GNUNET_break (0); 222 GNUNET_break (0);
224 } 223 }
225} 224}
226 225
227static void 226static void
@@ -231,7 +230,7 @@ run (void *cls, char *const *args, const char *cfgfile,
231 int *ok = cls; 230 int *ok = cls;
232 struct sockaddr_in sa; 231 struct sockaddr_in sa;
233 struct GNUNET_TIME_Relative timeout = 232 struct GNUNET_TIME_Relative timeout =
234 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); 233 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30);
235 int count_ips = 0; 234 int count_ips = 0;
236 char *own_fqdn; 235 char *own_fqdn;
237 236
@@ -258,50 +257,50 @@ run (void *cls, char *const *args, const char *cfgfile,
258 257
259 rootserver = gethostbyname (rootserver_name); 258 rootserver = gethostbyname (rootserver_name);
260 if (rootserver == NULL) 259 if (rootserver == NULL)
261 { 260 {
262 /* Error: resolving ip addresses does not work */ 261 /* Error: resolving ip addresses does not work */
263#if DEBUG_RESOLVER 262#if DEBUG_RESOLVER
264 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 263 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
265 _("gethostbyname() could not lookup IP address: %s\n"), 264 _("gethostbyname() could not lookup IP address: %s\n"),
266 hstrerror (h_errno)); 265 hstrerror (h_errno));
267#endif 266#endif
268 fprintf (stderr, 267 fprintf (stderr,
269 "System seems to be off-line, will not run all DNS tests\n"); 268 "System seems to be off-line, will not run all DNS tests\n");
270 *ok = 0; /* mark test as passing anyway */ 269 *ok = 0; /* mark test as passing anyway */
271 return; 270 return;
272 } 271 }
273 272
274 /* Counting returned IP addresses */ 273 /* Counting returned IP addresses */
275 while (rootserver->h_addr_list[count_ips] != NULL) 274 while (rootserver->h_addr_list[count_ips] != NULL)
276 count_ips++; 275 count_ips++;
277 if (count_ips > 1) 276 if (count_ips > 1)
278 { 277 {
279#if DEBUG_RESOLVER 278#if DEBUG_RESOLVER
280 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
281 "IP received range for root name server, but a root name server has only 1 IP\n"); 280 "IP received range for root name server, but a root name server has only 1 IP\n");
282#endif 281#endif
283 GNUNET_break (0); 282 GNUNET_break (0);
284 } 283 }
285 284
286 /* 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 */
287 if (strcmp 286 if (strcmp
288 (inet_ntoa (*(struct in_addr *) rootserver->h_addr_list[0]), 287 (inet_ntoa (*(struct in_addr *) rootserver->h_addr_list[0]),
289 ROOTSERVER_IP) != 0) 288 ROOTSERVER_IP) != 0)
290 { 289 {
291#if DEBUG_RESOLVER 290#if DEBUG_RESOLVER
292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
293 "IP received and IP for root name server differ\n"); 292 "IP received and IP for root name server differ\n");
294#endif 293#endif
295 GNUNET_break (0); 294 GNUNET_break (0);
296 } 295 }
297#if DEBUG_RESOLVER 296#if DEBUG_RESOLVER
298 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 297 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
299 "System's own forward name resolution is working\n"); 298 "System's own forward name resolution is working\n");
300#endif 299#endif
301 300
302 /* Resolve the same using GNUNET */ 301 /* Resolve the same using GNUNET */
303 GNUNET_RESOLVER_ip_get (ROOTSERVER_NAME, AF_INET, timeout, 302 GNUNET_RESOLVER_ip_get (ROOTSERVER_NAME, AF_INET, timeout,
304 &check_rootserver_ip, cls); 303 &check_rootserver_ip, cls);
305 304
306 /* 305 /*
307 * Success: forward lookups work as expected 306 * Success: forward lookups work as expected
@@ -312,41 +311,41 @@ run (void *cls, char *const *args, const char *cfgfile,
312 311
313 rootserver->h_name = ""; 312 rootserver->h_name = "";
314 if (1 != inet_pton (AF_INET, ROOTSERVER_IP, &rootserver_addr)) 313 if (1 != inet_pton (AF_INET, ROOTSERVER_IP, &rootserver_addr))
315 { 314 {
316#if DEBUG_RESOLVER 315#if DEBUG_RESOLVER
317 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 316 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
318 "Could not transform root name server IP address\n"); 317 "Could not transform root name server IP address\n");
319#endif 318#endif
320 GNUNET_break (0); 319 GNUNET_break (0);
321 } 320 }
322 321
323 rootserver = 322 rootserver =
324 gethostbyaddr (&rootserver_addr, sizeof (rootserver_addr), AF_INET); 323 gethostbyaddr (&rootserver_addr, sizeof (rootserver_addr), AF_INET);
325 if (rootserver == NULL) 324 if (rootserver == NULL)
326 { 325 {
327 /* Error: resolving IP addresses does not work */ 326 /* Error: resolving IP addresses does not work */
328#if DEBUG_RESOLVER 327#if DEBUG_RESOLVER
329 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 328 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
330 _("gethostbyaddr() could not lookup hostname: %s\n"), 329 _("gethostbyaddr() could not lookup hostname: %s\n"),
331 hstrerror (h_errno)); 330 hstrerror (h_errno));
332#endif 331#endif
333 GNUNET_break (0); 332 GNUNET_break (0);
334 } 333 }
335 else 334 else
335 {
336 if (0 != strcmp (rootserver->h_name, ROOTSERVER_NAME))
336 { 337 {
337 if (0 != strcmp (rootserver->h_name, ROOTSERVER_NAME))
338 {
339#if DEBUG_RESOLVER 338#if DEBUG_RESOLVER
340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 339 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
341 "Received hostname and hostname for root name server differ\n"); 340 "Received hostname and hostname for root name server differ\n");
342#endif 341#endif
343 GNUNET_break (0); 342 GNUNET_break (0);
344 }
345 } 343 }
344 }
346 345
347#if DEBUG_RESOLVER 346#if DEBUG_RESOLVER
348 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 347 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
349 "System's own reverse name resolution is working\n"); 348 "System's own reverse name resolution is working\n");
350#endif 349#endif
351 350
352 /* Resolve the same using GNUNET */ 351 /* Resolve the same using GNUNET */
@@ -361,8 +360,8 @@ run (void *cls, char *const *args, const char *cfgfile,
361 sa.sin_addr.S_un.S_addr = inet_addr (ROOTSERVER_IP); 360 sa.sin_addr.S_un.S_addr = inet_addr (ROOTSERVER_IP);
362#endif 361#endif
363 GNUNET_RESOLVER_hostname_get ((const struct sockaddr *) &sa, 362 GNUNET_RESOLVER_hostname_get ((const struct sockaddr *) &sa,
364 sizeof (struct sockaddr), GNUNET_YES, timeout, 363 sizeof (struct sockaddr), GNUNET_YES, timeout,
365 &check_rootserver_name, cls); 364 &check_rootserver_name, cls);
366 365
367 memset (&sa, 0, sizeof (sa)); 366 memset (&sa, 0, sizeof (sa));
368 sa.sin_family = AF_INET; 367 sa.sin_family = AF_INET;
@@ -373,12 +372,12 @@ run (void *cls, char *const *args, const char *cfgfile,
373 372
374 GNUNET_RESOLVER_ip_get ("localhost", AF_INET, timeout, &check_127, cls); 373 GNUNET_RESOLVER_ip_get ("localhost", AF_INET, timeout, &check_127, cls);
375 GNUNET_RESOLVER_hostname_get ((const struct sockaddr *) &sa, 374 GNUNET_RESOLVER_hostname_get ((const struct sockaddr *) &sa,
376 sizeof (struct sockaddr), GNUNET_YES, timeout, 375 sizeof (struct sockaddr), GNUNET_YES, timeout,
377 &check_localhost, cls); 376 &check_localhost, cls);
378 377
379 GNUNET_RESOLVER_hostname_get ((const struct sockaddr *) &sa, 378 GNUNET_RESOLVER_hostname_get ((const struct sockaddr *) &sa,
380 sizeof (struct sockaddr), GNUNET_NO, timeout, 379 sizeof (struct sockaddr), GNUNET_NO, timeout,
381 &check_localhost_num, cls); 380 &check_localhost_num, cls);
382 GNUNET_RESOLVER_hostname_resolve (AF_UNSPEC, timeout, &check_hostname, cls); 381 GNUNET_RESOLVER_hostname_resolve (AF_UNSPEC, timeout, &check_hostname, cls);
383 382
384} 383}
@@ -392,33 +391,33 @@ check ()
392 struct GNUNET_OS_Process *proc; 391 struct GNUNET_OS_Process *proc;
393 392
394 char *const argv[] = 393 char *const argv[] =
395 { "test-resolver-api", "-c", "test_resolver_api_data.conf", 394 { "test-resolver-api", "-c", "test_resolver_api_data.conf",
396#if VERBOSE 395#if VERBOSE
397 "-L", "DEBUG", 396 "-L", "DEBUG",
398#endif 397#endif
399 NULL 398 NULL
400 }; 399 };
401 struct GNUNET_GETOPT_CommandLineOption options[] = 400 struct GNUNET_GETOPT_CommandLineOption options[] =
402 { GNUNET_GETOPT_OPTION_END }; 401 { GNUNET_GETOPT_OPTION_END };
403 pfx = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR); 402 pfx = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR);
404 GNUNET_asprintf (&fn, "%s%cgnunet-service-resolver", pfx, DIR_SEPARATOR); 403 GNUNET_asprintf (&fn, "%s%cgnunet-service-resolver", pfx, DIR_SEPARATOR);
405 GNUNET_free (pfx); 404 GNUNET_free (pfx);
406 proc = GNUNET_OS_start_process (NULL, NULL, fn, "gnunet-service-resolver", 405 proc = GNUNET_OS_start_process (NULL, NULL, fn, "gnunet-service-resolver",
407#if VERBOSE 406#if VERBOSE
408 "-L", "DEBUG", 407 "-L", "DEBUG",
409#endif 408#endif
410 "-c", "test_resolver_api_data.conf", NULL); 409 "-c", "test_resolver_api_data.conf", NULL);
411 GNUNET_assert (NULL != proc); 410 GNUNET_assert (NULL != proc);
412 GNUNET_free (fn); 411 GNUNET_free (fn);
413 GNUNET_assert (GNUNET_OK == 412 GNUNET_assert (GNUNET_OK ==
414 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 413 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
415 argv, "test-resolver-api", "nohelp", 414 argv, "test-resolver-api", "nohelp",
416 options, &run, &ok)); 415 options, &run, &ok));
417 if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) 416 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
418 { 417 {
419 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 418 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
420 ok = 1; 419 ok = 1;
421 } 420 }
422 GNUNET_OS_process_wait (proc); 421 GNUNET_OS_process_wait (proc);
423 GNUNET_OS_process_close (proc); 422 GNUNET_OS_process_close (proc);
424 proc = NULL; 423 proc = NULL;
@@ -434,11 +433,11 @@ main (int argc, char *argv[])
434 433
435 GNUNET_log_setup ("test-resolver-api", 434 GNUNET_log_setup ("test-resolver-api",
436#if VERBOSE 435#if VERBOSE
437 "DEBUG", 436 "DEBUG",
438#else 437#else
439 "WARNING", 438 "WARNING",
440#endif 439#endif
441 NULL); 440 NULL);
442 ret = check (); 441 ret = check ();
443 442
444 return ret; 443 return ret;
diff --git a/src/util/test_scheduler.c b/src/util/test_scheduler.c
index e2a28c1b7..788ba13fa 100644
--- a/src/util/test_scheduler.c
+++ b/src/util/test_scheduler.c
@@ -36,7 +36,7 @@ task3 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
36 36
37 /* t4 should be ready (albeit with lower priority) */ 37 /* t4 should be ready (albeit with lower priority) */
38 GNUNET_assert (1 == 38 GNUNET_assert (1 ==
39 GNUNET_SCHEDULER_get_load (GNUNET_SCHEDULER_PRIORITY_COUNT)); 39 GNUNET_SCHEDULER_get_load (GNUNET_SCHEDULER_PRIORITY_COUNT));
40 GNUNET_assert (3 == *ok); 40 GNUNET_assert (3 == *ok);
41 (*ok) = 4; 41 (*ok) = 4;
42} 42}
@@ -51,7 +51,7 @@ task2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
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, &task3, 53 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, &task3,
54 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, fds[0], 126 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, fds[0], &taskRd,
127 &taskRd, cls); 127 cls);
128 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, fds[1], 128 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, fds[1],
129 &taskWrt, cls); 129 &taskWrt, cls);
130} 130}
131 131
132 132
@@ -226,7 +226,7 @@ taskCancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
226 GNUNET_assert (1 == *ok); 226 GNUNET_assert (1 == *ok);
227 *ok = 0; 227 *ok = 0;
228 GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_add_after 228 GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_add_after
229 (GNUNET_SCHEDULER_NO_TASK, &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 20783da8d..ff6966a87 100644
--- a/src/util/test_scheduler_delay.c
+++ b/src/util/test_scheduler_delay.c
@@ -57,17 +57,17 @@ test_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
57 else 57 else
58 cumDelta += (target.abs_value - now.abs_value); 58 cumDelta += (target.abs_value - now.abs_value);
59 target = 59 target =
60 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply 60 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
61 (GNUNET_TIME_UNIT_MILLISECONDS, i)); 61 (GNUNET_TIME_UNIT_MILLISECONDS, i));
62 fprintf (stderr, "."); 62 fprintf (stderr, ".");
63 if (i > MAXV) 63 if (i > MAXV)
64 { 64 {
65 fprintf (stderr, "\n"); 65 fprintf (stderr, "\n");
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
@@ -77,10 +77,10 @@ check ()
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, "Sleep precision: %llu ms. ", 79 FPRINTF (stdout, "Sleep precision: %llu ms. ",
80 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 */
84 fprintf (stdout, "Timer precision is good.\n"); 84 fprintf (stdout, "Timer precision is good.\n");
85 else if (cumDelta > 250 * MAXV / INCR) 85 else if (cumDelta > 250 * MAXV / INCR)
86 fprintf (stdout, "Timer precision is awful.\n"); 86 fprintf (stdout, "Timer precision is awful.\n");
diff --git a/src/util/test_server.c b/src/util/test_server.c
index 8adde5346..625829042 100644
--- a/src/util/test_server.c
+++ b/src/util/test_server.c
@@ -61,7 +61,7 @@ finish_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
61 61
62static void 62static void
63recv_fin_cb (void *cls, struct GNUNET_SERVER_Client *client, 63recv_fin_cb (void *cls, struct GNUNET_SERVER_Client *client,
64 const struct GNUNET_MessageHeader *message) 64 const struct GNUNET_MessageHeader *message)
65{ 65{
66 GNUNET_assert (ok == 5); 66 GNUNET_assert (ok == 5);
67 ok = 6; 67 ok = 6;
@@ -98,20 +98,19 @@ reply_msg (void *cls, size_t size, void *buf)
98 98
99static void 99static void
100recv_cb (void *cls, struct GNUNET_SERVER_Client *client, 100recv_cb (void *cls, struct GNUNET_SERVER_Client *client,
101 const struct GNUNET_MessageHeader *message) 101 const struct GNUNET_MessageHeader *message)
102{ 102{
103 GNUNET_assert (ok == 2); 103 GNUNET_assert (ok == 2);
104 ok = 3; 104 ok = 3;
105 argclient = client; 105 argclient = client;
106 GNUNET_SERVER_client_keep (argclient); 106 GNUNET_SERVER_client_keep (argclient);
107 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == 107 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size));
108 ntohs (message->size));
109 GNUNET_assert (MY_TYPE == ntohs (message->type)); 108 GNUNET_assert (MY_TYPE == ntohs (message->type));
110 GNUNET_assert (NULL != 109 GNUNET_assert (NULL !=
111 GNUNET_SERVER_notify_transmit_ready (client, 110 GNUNET_SERVER_notify_transmit_ready (client,
112 ntohs (message->size), 111 ntohs (message->size),
113 TIMEOUT, &reply_msg, 112 TIMEOUT, &reply_msg,
114 NULL)); 113 NULL));
115} 114}
116 115
117 116
@@ -139,7 +138,7 @@ static size_t
139transmit_initial_message (void *cls, size_t size, void *buf) 138transmit_initial_message (void *cls, size_t size, void *buf)
140{ 139{
141 struct GNUNET_MessageHeader msg; 140 struct GNUNET_MessageHeader msg;
142 141
143 GNUNET_assert (ok == 1); 142 GNUNET_assert (ok == 1);
144 ok = 2; 143 ok = 2;
145 GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); 144 GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
@@ -147,12 +146,12 @@ transmit_initial_message (void *cls, size_t size, void *buf)
147 msg.size = htons (sizeof (struct GNUNET_MessageHeader)); 146 msg.size = htons (sizeof (struct GNUNET_MessageHeader));
148 memcpy (buf, &msg, sizeof (struct GNUNET_MessageHeader)); 147 memcpy (buf, &msg, sizeof (struct GNUNET_MessageHeader));
149 GNUNET_assert (NULL != 148 GNUNET_assert (NULL !=
150 GNUNET_CLIENT_notify_transmit_ready (cc, 149 GNUNET_CLIENT_notify_transmit_ready (cc,
151 sizeof (struct 150 sizeof (struct
152 GNUNET_MessageHeader), 151 GNUNET_MessageHeader),
153 TIMEOUT, GNUNET_YES, 152 TIMEOUT, GNUNET_YES,
154 &transmit_second_message, 153 &transmit_second_message,
155 NULL)); 154 NULL));
156 GNUNET_CLIENT_receive (cc, &first_reply_handler, NULL, TIMEOUT); 155 GNUNET_CLIENT_receive (cc, &first_reply_handler, NULL, TIMEOUT);
157 return sizeof (struct GNUNET_MessageHeader); 156 return sizeof (struct GNUNET_MessageHeader);
158} 157}
@@ -181,18 +180,18 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
181 cfg = GNUNET_CONFIGURATION_create (); 180 cfg = GNUNET_CONFIGURATION_create ();
182 GNUNET_CONFIGURATION_set_value_number (cfg, "test-server", "PORT", PORT); 181 GNUNET_CONFIGURATION_set_value_number (cfg, "test-server", "PORT", PORT);
183 GNUNET_CONFIGURATION_set_value_string (cfg, "test-server", "HOSTNAME", 182 GNUNET_CONFIGURATION_set_value_string (cfg, "test-server", "HOSTNAME",
184 "localhost"); 183 "localhost");
185 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", 184 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
186 "localhost"); 185 "localhost");
187 cc = GNUNET_CLIENT_connect ("test-server", cfg); 186 cc = GNUNET_CLIENT_connect ("test-server", cfg);
188 GNUNET_assert (cc != NULL); 187 GNUNET_assert (cc != NULL);
189 GNUNET_assert (NULL != 188 GNUNET_assert (NULL !=
190 GNUNET_CLIENT_notify_transmit_ready (cc, 189 GNUNET_CLIENT_notify_transmit_ready (cc,
191 sizeof (struct 190 sizeof (struct
192 GNUNET_MessageHeader), 191 GNUNET_MessageHeader),
193 TIMEOUT, GNUNET_YES, 192 TIMEOUT, GNUNET_YES,
194 &transmit_initial_message, 193 &transmit_initial_message,
195 NULL)); 194 NULL));
196} 195}
197 196
198 197
diff --git a/src/util/test_server_disconnect.c b/src/util/test_server_disconnect.c
index e38840d92..69207f81a 100644
--- a/src/util/test_server_disconnect.c
+++ b/src/util/test_server_disconnect.c
@@ -81,14 +81,13 @@ server_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
81 81
82static void 82static void
83recv_cb (void *cls, struct GNUNET_SERVER_Client *client, 83recv_cb (void *cls, struct GNUNET_SERVER_Client *client,
84 const struct GNUNET_MessageHeader *message) 84 const struct GNUNET_MessageHeader *message)
85{ 85{
86 GNUNET_assert (ok == 2); 86 GNUNET_assert (ok == 2);
87 ok = 3; 87 ok = 3;
88 GNUNET_SERVER_client_keep (client); 88 GNUNET_SERVER_client_keep (client);
89 GNUNET_SCHEDULER_add_now (&server_disconnect, client); 89 GNUNET_SCHEDULER_add_now (&server_disconnect, client);
90 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == 90 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size));
91 ntohs (message->size));
92 GNUNET_assert (MY_TYPE == ntohs (message->type)); 91 GNUNET_assert (MY_TYPE == ntohs (message->type));
93 GNUNET_SERVER_receive_done (client, GNUNET_OK); 92 GNUNET_SERVER_receive_done (client, GNUNET_OK);
94} 93}
@@ -139,18 +138,18 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
139 cfg = GNUNET_CONFIGURATION_create (); 138 cfg = GNUNET_CONFIGURATION_create ();
140 GNUNET_CONFIGURATION_set_value_number (cfg, "test-server", "PORT", PORT); 139 GNUNET_CONFIGURATION_set_value_number (cfg, "test-server", "PORT", PORT);
141 GNUNET_CONFIGURATION_set_value_string (cfg, "test-server", "HOSTNAME", 140 GNUNET_CONFIGURATION_set_value_string (cfg, "test-server", "HOSTNAME",
142 "localhost"); 141 "localhost");
143 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", 142 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
144 "localhost"); 143 "localhost");
145 cc = GNUNET_CLIENT_connect ("test-server", cfg); 144 cc = GNUNET_CLIENT_connect ("test-server", cfg);
146 GNUNET_assert (cc != NULL); 145 GNUNET_assert (cc != NULL);
147 GNUNET_assert (NULL != 146 GNUNET_assert (NULL !=
148 GNUNET_CLIENT_notify_transmit_ready (cc, 147 GNUNET_CLIENT_notify_transmit_ready (cc,
149 sizeof (struct 148 sizeof (struct
150 GNUNET_MessageHeader), 149 GNUNET_MessageHeader),
151 TIMEOUT, GNUNET_YES, 150 TIMEOUT, GNUNET_YES,
152 &transmit_initial_message, 151 &transmit_initial_message,
153 NULL)); 152 NULL));
154} 153}
155 154
156 155
diff --git a/src/util/test_server_with_client.c b/src/util/test_server_with_client.c
index 21c706b07..5b6e51718 100644
--- a/src/util/test_server_with_client.c
+++ b/src/util/test_server_with_client.c
@@ -58,7 +58,7 @@ send_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
58 58
59static void 59static void
60recv_cb (void *cls, struct GNUNET_SERVER_Client *argclient, 60recv_cb (void *cls, struct GNUNET_SERVER_Client *argclient,
61 const struct GNUNET_MessageHeader *message) 61 const struct GNUNET_MessageHeader *message)
62{ 62{
63 void *addr; 63 void *addr;
64 size_t addrlen; 64 size_t addrlen;
@@ -66,8 +66,7 @@ recv_cb (void *cls, struct GNUNET_SERVER_Client *argclient,
66 struct sockaddr_in *have; 66 struct sockaddr_in *have;
67 67
68 GNUNET_assert (GNUNET_OK == 68 GNUNET_assert (GNUNET_OK ==
69 GNUNET_SERVER_client_get_address (argclient, &addr, 69 GNUNET_SERVER_client_get_address (argclient, &addr, &addrlen));
70 &addrlen));
71 70
72 GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); 71 GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
73 have = addr; 72 have = addr;
@@ -81,21 +80,21 @@ recv_cb (void *cls, struct GNUNET_SERVER_Client *argclient,
81 GNUNET_assert (0 == memcmp (&sa, addr, addrlen)); 80 GNUNET_assert (0 == memcmp (&sa, addr, addrlen));
82 GNUNET_free (addr); 81 GNUNET_free (addr);
83 switch (ok) 82 switch (ok)
84 { 83 {
85 case 2: 84 case 2:
86 ok++; 85 ok++;
87 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 86 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
88 (GNUNET_TIME_UNIT_MILLISECONDS, 50), 87 (GNUNET_TIME_UNIT_MILLISECONDS, 50),
89 &send_done, argclient); 88 &send_done, argclient);
90 break; 89 break;
91 case 4: 90 case 4:
92 ok++; 91 ok++;
93 GNUNET_CLIENT_disconnect (client, GNUNET_YES); 92 GNUNET_CLIENT_disconnect (client, GNUNET_YES);
94 GNUNET_SERVER_receive_done (argclient, GNUNET_OK); 93 GNUNET_SERVER_receive_done (argclient, GNUNET_OK);
95 break; 94 break;
96 default: 95 default:
97 GNUNET_assert (0); 96 GNUNET_assert (0);
98 } 97 }
99 98
100} 99}
101 100
@@ -170,25 +169,24 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
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 = 171 server =
173 GNUNET_SERVER_create (NULL, NULL, sap, slens, 172 GNUNET_SERVER_create (NULL, NULL, sap, slens,
174 GNUNET_TIME_relative_multiply 173 GNUNET_TIME_relative_multiply
175 (GNUNET_TIME_UNIT_MILLISECONDS, 250), GNUNET_NO); 174 (GNUNET_TIME_UNIT_MILLISECONDS, 250), GNUNET_NO);
176 GNUNET_assert (server != NULL); 175 GNUNET_assert (server != NULL);
177 handlers[0].callback_cls = cls; 176 handlers[0].callback_cls = cls;
178 GNUNET_SERVER_add_handlers (server, handlers); 177 GNUNET_SERVER_add_handlers (server, handlers);
179 GNUNET_SERVER_disconnect_notify (server, &notify_disconnect, cls); 178 GNUNET_SERVER_disconnect_notify (server, &notify_disconnect, cls);
180 cfg = GNUNET_CONFIGURATION_create (); 179 cfg = GNUNET_CONFIGURATION_create ();
181 GNUNET_CONFIGURATION_set_value_number (cfg, "test", "PORT", PORT); 180 GNUNET_CONFIGURATION_set_value_number (cfg, "test", "PORT", PORT);
182 GNUNET_CONFIGURATION_set_value_string (cfg, "test", "HOSTNAME", 181 GNUNET_CONFIGURATION_set_value_string (cfg, "test", "HOSTNAME", "localhost");
183 "localhost");
184 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", 182 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
185 "localhost"); 183 "localhost");
186 client = GNUNET_CLIENT_connect ("test", cfg); 184 client = GNUNET_CLIENT_connect ("test", cfg);
187 GNUNET_assert (client != NULL); 185 GNUNET_assert (client != NULL);
188 GNUNET_CLIENT_notify_transmit_ready (client, 256, 186 GNUNET_CLIENT_notify_transmit_ready (client, 256,
189 GNUNET_TIME_relative_multiply 187 GNUNET_TIME_relative_multiply
190 (GNUNET_TIME_UNIT_MILLISECONDS, 250), 188 (GNUNET_TIME_UNIT_MILLISECONDS, 250),
191 GNUNET_NO, &notify_ready, NULL); 189 GNUNET_NO, &notify_ready, NULL);
192} 190}
193 191
194 192
@@ -213,11 +211,11 @@ main (int argc, char *argv[])
213 211
214 GNUNET_log_setup ("test_server_with_client", 212 GNUNET_log_setup ("test_server_with_client",
215#if VERBOSE 213#if VERBOSE
216 "DEBUG", 214 "DEBUG",
217#else 215#else
218 "WARNING", 216 "WARNING",
219#endif 217#endif
220 NULL); 218 NULL);
221 ret += check (); 219 ret += check ();
222 220
223 return ret; 221 return ret;
diff --git a/src/util/test_server_with_client_unix.c b/src/util/test_server_with_client_unix.c
index 11f731243..4f80f188c 100644
--- a/src/util/test_server_with_client_unix.c
+++ b/src/util/test_server_with_client_unix.c
@@ -56,24 +56,24 @@ send_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
56 56
57static void 57static void
58recv_cb (void *cls, struct GNUNET_SERVER_Client *argclient, 58recv_cb (void *cls, struct GNUNET_SERVER_Client *argclient,
59 const struct GNUNET_MessageHeader *message) 59 const struct GNUNET_MessageHeader *message)
60{ 60{
61 switch (ok) 61 switch (ok)
62 { 62 {
63 case 2: 63 case 2:
64 ok++; 64 ok++;
65 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 65 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
66 (GNUNET_TIME_UNIT_MILLISECONDS, 50), 66 (GNUNET_TIME_UNIT_MILLISECONDS, 50),
67 &send_done, argclient); 67 &send_done, argclient);
68 break; 68 break;
69 case 4: 69 case 4:
70 ok++; 70 ok++;
71 GNUNET_CLIENT_disconnect (client, GNUNET_YES); 71 GNUNET_CLIENT_disconnect (client, GNUNET_YES);
72 GNUNET_SERVER_receive_done (argclient, GNUNET_OK); 72 GNUNET_SERVER_receive_done (argclient, GNUNET_OK);
73 break; 73 break;
74 default: 74 default:
75 GNUNET_assert (0); 75 GNUNET_assert (0);
76 } 76 }
77 77
78} 78}
79 79
@@ -156,9 +156,9 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
156 sap[1] = NULL; 156 sap[1] = NULL;
157 slens[1] = 0; 157 slens[1] = 0;
158 server = 158 server =
159 GNUNET_SERVER_create (NULL, NULL, sap, slens, 159 GNUNET_SERVER_create (NULL, NULL, sap, slens,
160 GNUNET_TIME_relative_multiply 160 GNUNET_TIME_relative_multiply
161 (GNUNET_TIME_UNIT_MILLISECONDS, 250), GNUNET_NO); 161 (GNUNET_TIME_UNIT_MILLISECONDS, 250), GNUNET_NO);
162 GNUNET_assert (server != NULL); 162 GNUNET_assert (server != NULL);
163 handlers[0].callback_cls = cls; 163 handlers[0].callback_cls = cls;
164 GNUNET_SERVER_add_handlers (server, handlers); 164 GNUNET_SERVER_add_handlers (server, handlers);
@@ -167,14 +167,14 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
167 167
168 GNUNET_CONFIGURATION_set_value_string (cfg, "test", "UNIXPATH", unixpath); 168 GNUNET_CONFIGURATION_set_value_string (cfg, "test", "UNIXPATH", unixpath);
169 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", 169 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
170 "localhost"); 170 "localhost");
171 171
172 client = GNUNET_CLIENT_connect ("test", cfg); 172 client = GNUNET_CLIENT_connect ("test", cfg);
173 GNUNET_assert (client != NULL); 173 GNUNET_assert (client != NULL);
174 GNUNET_CLIENT_notify_transmit_ready (client, 256, 174 GNUNET_CLIENT_notify_transmit_ready (client, 256,
175 GNUNET_TIME_relative_multiply 175 GNUNET_TIME_relative_multiply
176 (GNUNET_TIME_UNIT_MILLISECONDS, 250), 176 (GNUNET_TIME_UNIT_MILLISECONDS, 250),
177 GNUNET_NO, &notify_ready, NULL); 177 GNUNET_NO, &notify_ready, NULL);
178} 178}
179 179
180 180
@@ -199,11 +199,11 @@ main (int argc, char *argv[])
199 199
200 GNUNET_log_setup ("test_server_with_client_unix", 200 GNUNET_log_setup ("test_server_with_client_unix",
201#if VERBOSE 201#if VERBOSE
202 "DEBUG", 202 "DEBUG",
203#else 203#else
204 "WARNING", 204 "WARNING",
205#endif 205#endif
206 NULL); 206 NULL);
207 ret += check (); 207 ret += check ();
208 208
209 return ret; 209 return ret;
diff --git a/src/util/test_service.c b/src/util/test_service.c
index 33d69db10..1b78932f8 100644
--- a/src/util/test_service.c
+++ b/src/util/test_service.c
@@ -68,11 +68,11 @@ ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
68 client = GNUNET_CLIENT_connect ("test_service", cfg); 68 client = GNUNET_CLIENT_connect ("test_service", cfg);
69 GNUNET_assert (client != NULL); 69 GNUNET_assert (client != NULL);
70 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 70 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
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, GNUNET_NO, 74 GNUNET_TIME_UNIT_SECONDS, GNUNET_NO,
75 &build_msg, client); 75 &build_msg, client);
76} 76}
77 77
78 78
@@ -85,7 +85,7 @@ do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
85 85
86static void 86static void
87recv_cb (void *cls, struct GNUNET_SERVER_Client *client, 87recv_cb (void *cls, struct GNUNET_SERVER_Client *client,
88 const struct GNUNET_MessageHeader *message) 88 const struct GNUNET_MessageHeader *message)
89{ 89{
90 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving client message...\n"); 90 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving client message...\n");
91 GNUNET_SERVER_receive_done (client, GNUNET_OK); 91 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -105,12 +105,12 @@ static struct GNUNET_SERVER_MessageHandler myhandlers[] = {
105 105
106static void 106static void
107runner (void *cls, struct GNUNET_SERVER_Handle *server, 107runner (void *cls, struct GNUNET_SERVER_Handle *server,
108 const struct GNUNET_CONFIGURATION_Handle *cfg) 108 const struct GNUNET_CONFIGURATION_Handle *cfg)
109{ 109{
110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service initializing\n"); 110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service initializing\n");
111 GNUNET_SERVER_add_handlers (server, myhandlers); 111 GNUNET_SERVER_add_handlers (server, myhandlers);
112 GNUNET_CLIENT_service_test ("test_service", cfg, GNUNET_TIME_UNIT_SECONDS, 112 GNUNET_CLIENT_service_test ("test_service", cfg, GNUNET_TIME_UNIT_SECONDS,
113 &ready, (void *) cfg); 113 &ready, (void *) cfg);
114} 114}
115 115
116 116
@@ -136,9 +136,8 @@ check ()
136 }; 136 };
137 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting service\n"); 137 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting service\n");
138 GNUNET_assert (GNUNET_OK == 138 GNUNET_assert (GNUNET_OK ==
139 GNUNET_SERVICE_run (5, argv, "test_service", 139 GNUNET_SERVICE_run (5, argv, "test_service",
140 GNUNET_SERVICE_OPTION_NONE, &runner, 140 GNUNET_SERVICE_OPTION_NONE, &runner, &ok));
141 &ok));
142 GNUNET_assert (0 == ok); 141 GNUNET_assert (0 == ok);
143 return ok; 142 return ok;
144} 143}
@@ -155,19 +154,19 @@ ready6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
155 GNUNET_assert (client != NULL); 154 GNUNET_assert (client != NULL);
156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "V6 client connected\n"); 155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "V6 client connected\n");
157 GNUNET_CLIENT_notify_transmit_ready (client, 156 GNUNET_CLIENT_notify_transmit_ready (client,
158 sizeof (struct GNUNET_MessageHeader), 157 sizeof (struct GNUNET_MessageHeader),
159 GNUNET_TIME_UNIT_SECONDS, GNUNET_NO, 158 GNUNET_TIME_UNIT_SECONDS, GNUNET_NO,
160 &build_msg, client); 159 &build_msg, client);
161} 160}
162 161
163static void 162static void
164runner6 (void *cls, struct GNUNET_SERVER_Handle *server, 163runner6 (void *cls, struct GNUNET_SERVER_Handle *server,
165 const struct GNUNET_CONFIGURATION_Handle *cfg) 164 const struct GNUNET_CONFIGURATION_Handle *cfg)
166{ 165{
167 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initializing v6 service\n"); 166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initializing v6 service\n");
168 GNUNET_SERVER_add_handlers (server, myhandlers); 167 GNUNET_SERVER_add_handlers (server, myhandlers);
169 GNUNET_CLIENT_service_test ("test_service6", cfg, GNUNET_TIME_UNIT_SECONDS, 168 GNUNET_CLIENT_service_test ("test_service6", cfg, GNUNET_TIME_UNIT_SECONDS,
170 &ready6, (void *) cfg); 169 &ready6, (void *) cfg);
171} 170}
172 171
173/** 172/**
@@ -191,9 +190,9 @@ check6 ()
191 }; 190 };
192 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting v6 service\n"); 191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting v6 service\n");
193 GNUNET_assert (GNUNET_OK == 192 GNUNET_assert (GNUNET_OK ==
194 GNUNET_SERVICE_run (5, argv, "test_service6", 193 GNUNET_SERVICE_run (5, argv, "test_service6",
195 GNUNET_SERVICE_OPTION_NONE, &runner6, 194 GNUNET_SERVICE_OPTION_NONE, &runner6,
196 &ok)); 195 &ok));
197 GNUNET_assert (0 == ok); 196 GNUNET_assert (0 == ok);
198 return ok; 197 return ok;
199} 198}
@@ -202,12 +201,11 @@ check6 ()
202 201
203static void 202static void
204start_stop_main (void *cls, char *const *args, const char *cfgfile, 203start_stop_main (void *cls, char *const *args, const char *cfgfile,
205 const struct GNUNET_CONFIGURATION_Handle *cfg) 204 const struct GNUNET_CONFIGURATION_Handle *cfg)
206{ 205{
207 int *ret = cls; 206 int *ret = cls;
208 207
209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting service using start method\n");
210 "Starting service using start method\n");
211 sctx = GNUNET_SERVICE_start ("test_service", cfg); 209 sctx = GNUNET_SERVICE_start ("test_service", cfg);
212 GNUNET_assert (NULL != sctx); 210 GNUNET_assert (NULL != sctx);
213 runner (cls, GNUNET_SERVICE_get_server (sctx), cfg); 211 runner (cls, GNUNET_SERVICE_get_server (sctx), cfg);
@@ -236,9 +234,8 @@ check_start_stop ()
236 int ret = 1; 234 int ret = 1;
237 235
238 GNUNET_assert (GNUNET_OK == 236 GNUNET_assert (GNUNET_OK ==
239 GNUNET_PROGRAM_run (5, argv, "test-service-program", 237 GNUNET_PROGRAM_run (5, argv, "test-service-program", "no help",
240 "no help", options, &start_stop_main, 238 options, &start_stop_main, &ret));
241 &ret));
242 239
243 GNUNET_break (0 == ret); 240 GNUNET_break (0 == ret);
244 return ret; 241 return ret;
@@ -253,11 +250,11 @@ main (int argc, char *argv[])
253 250
254 GNUNET_log_setup ("test-service", 251 GNUNET_log_setup ("test-service",
255#if VERBOSE 252#if VERBOSE
256 "DEBUG", 253 "DEBUG",
257#else 254#else
258 "WARNING", 255 "WARNING",
259#endif 256#endif
260 NULL); 257 NULL);
261 ret += check (); 258 ret += check ();
262 ret += check (); 259 ret += check ();
263 260
@@ -266,22 +263,22 @@ main (int argc, char *argv[])
266 s = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0); 263 s = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
267#endif 264#endif
268 if (NULL == s) 265 if (NULL == s)
266 {
267 if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) ||
268 (errno == EACCES))
269 { 269 {
270 if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) || 270 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
271 (errno == EACCES)) 271 return 1;
272 {
273 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
274 return 1;
275 }
276 fprintf (stderr,
277 "IPv6 support seems to not be available (%s), not testing it!\n",
278 strerror (errno));
279 } 272 }
273 fprintf (stderr,
274 "IPv6 support seems to not be available (%s), not testing it!\n",
275 strerror (errno));
276 }
280 else 277 else
281 { 278 {
282 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); 279 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s));
283 ret += check6 (); 280 ret += check6 ();
284 } 281 }
285 ret += check_start_stop (); 282 ret += check_start_stop ();
286 283
287 return ret; 284 return ret;
diff --git a/src/util/test_strings.c b/src/util/test_strings.c
index bb0e6088f..c6d604144 100644
--- a/src/util/test_strings.c
+++ b/src/util/test_strings.c
@@ -50,18 +50,18 @@ check ()
50 WANT (buf, b); 50 WANT (buf, b);
51 sprintf (buf, "4 %s", _( /* time unit */ "ms")); 51 sprintf (buf, "4 %s", _( /* time unit */ "ms"));
52 b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply 52 b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply
53 (GNUNET_TIME_UNIT_MILLISECONDS, 53 (GNUNET_TIME_UNIT_MILLISECONDS,
54 4)); 54 4));
55 WANT (buf, b); 55 WANT (buf, b);
56 sprintf (buf, "7 %s", _( /* time unit */ "s")); 56 sprintf (buf, "7 %s", _( /* time unit */ "s"));
57 b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply 57 b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply
58 (GNUNET_TIME_UNIT_MILLISECONDS, 58 (GNUNET_TIME_UNIT_MILLISECONDS,
59 7 * 1000)); 59 7 * 1000));
60 WANT (buf, b); 60 WANT (buf, b);
61 sprintf (buf, "7 %s", _( /* time unit */ "h")); 61 sprintf (buf, "7 %s", _( /* time unit */ "h"));
62 b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply 62 b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply
63 (GNUNET_TIME_UNIT_MILLISECONDS, 63 (GNUNET_TIME_UNIT_MILLISECONDS,
64 7 * 60 * 60 * 1000)); 64 7 * 60 * 60 * 1000));
65 WANT (buf, b); 65 WANT (buf, b);
66#ifndef MINGW 66#ifndef MINGW
67 hdir = getenv ("HOME"); 67 hdir = getenv ("HOME");
@@ -88,12 +88,12 @@ check ()
88 * where the details of the day and hour depend on the timezone; 88 * where the details of the day and hour depend on the timezone;
89 * however, the "0:05 19" should always be there; hence: */ 89 * however, the "0:05 19" should always be there; hence: */
90 if (NULL == strstr (r, "0:05 19")) 90 if (NULL == strstr (r, "0:05 19"))
91 { 91 {
92 fprintf (stderr, "Got %s\n", r); 92 fprintf (stderr, "Got %s\n", r);
93 GNUNET_break (0); 93 GNUNET_break (0);
94 GNUNET_free (r); 94 GNUNET_free (r);
95 return 1; 95 return 1;
96 } 96 }
97 GNUNET_free (r); 97 GNUNET_free (r);
98 b = GNUNET_STRINGS_to_utf8 ("TEST", 4, "ASCII"); 98 b = GNUNET_STRINGS_to_utf8 ("TEST", 4, "ASCII");
99 WANT ("TEST", b); 99 WANT ("TEST", b);
diff --git a/src/util/test_time.c b/src/util/test_time.c
index 80109615a..c5232ff2a 100644
--- a/src/util/test_time.c
+++ b/src/util/test_time.c
@@ -63,7 +63,7 @@ check ()
63 /*check zero */ 63 /*check zero */
64 rel.rel_value = (UINT64_MAX) - 1024; 64 rel.rel_value = (UINT64_MAX) - 1024;
65 GNUNET_assert (GNUNET_TIME_relative_get_zero ().rel_value == 65 GNUNET_assert (GNUNET_TIME_relative_get_zero ().rel_value ==
66 GNUNET_TIME_relative_multiply (rel, 0).rel_value); 66 GNUNET_TIME_relative_multiply (rel, 0).rel_value);
67 67
68 /* test infinity-check for relative to absolute */ 68 /* test infinity-check for relative to absolute */
69 GNUNET_log_skip (1, GNUNET_NO); 69 GNUNET_log_skip (1, GNUNET_NO);
@@ -74,11 +74,11 @@ check ()
74 /*check relative to absolute */ 74 /*check relative to absolute */
75 rel.rel_value = 0; 75 rel.rel_value = 0;
76 GNUNET_assert (GNUNET_TIME_absolute_get ().abs_value == 76 GNUNET_assert (GNUNET_TIME_absolute_get ().abs_value ==
77 GNUNET_TIME_relative_to_absolute (rel).abs_value); 77 GNUNET_TIME_relative_to_absolute (rel).abs_value);
78 /*check forever */ 78 /*check forever */
79 rel.rel_value = UINT64_MAX; 79 rel.rel_value = UINT64_MAX;
80 GNUNET_assert (GNUNET_TIME_absolute_get_forever ().abs_value == 80 GNUNET_assert (GNUNET_TIME_absolute_get_forever ().abs_value ==
81 GNUNET_TIME_relative_to_absolute (rel).abs_value); 81 GNUNET_TIME_relative_to_absolute (rel).abs_value);
82 /* check overflow for r2a */ 82 /* check overflow for r2a */
83 rel.rel_value = (UINT64_MAX) - 1024; 83 rel.rel_value = (UINT64_MAX) - 1024;
84 GNUNET_log_skip (1, GNUNET_NO); 84 GNUNET_log_skip (1, GNUNET_NO);
@@ -103,13 +103,13 @@ check ()
103 103
104 /* check relation check in get_duration */ 104 /* check relation check in get_duration */
105 future.abs_value = now.abs_value + 1000000; 105 future.abs_value = now.abs_value + 1000000;
106 GNUNET_assert (GNUNET_TIME_absolute_get_difference (now, future).rel_value 106 GNUNET_assert (GNUNET_TIME_absolute_get_difference (now, future).rel_value ==
107 == 1000000); 107 1000000);
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).rel_value
112 == forever.abs_value); 112 == 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);
@@ -127,7 +127,7 @@ check ()
127 GNUNET_assert (rel.rel_value <= 1000000); 127 GNUNET_assert (rel.rel_value <= 1000000);
128 forever = GNUNET_TIME_absolute_get_forever (); 128 forever = GNUNET_TIME_absolute_get_forever ();
129 GNUNET_assert (GNUNET_TIME_relative_get_forever ().rel_value == 129 GNUNET_assert (GNUNET_TIME_relative_get_forever ().rel_value ==
130 GNUNET_TIME_absolute_get_remaining (forever).rel_value); 130 GNUNET_TIME_absolute_get_remaining (forever).rel_value);
131 131
132 /* check endianess */ 132 /* check endianess */
133 reln = GNUNET_TIME_relative_hton (rel); 133 reln = GNUNET_TIME_relative_hton (rel);
@@ -152,24 +152,23 @@ check ()
152 GNUNET_assert (future.abs_value == now.abs_value); 152 GNUNET_assert (future.abs_value == now.abs_value);
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).abs_value);
157 /*check absolute subtract */ 157 /*check absolute subtract */
158 now.abs_value = 50000; 158 now.abs_value = 50000;
159 rel.rel_value = 100000; 159 rel.rel_value = 100000;
160 GNUNET_assert (GNUNET_TIME_UNIT_ZERO_ABS.abs_value == 160 GNUNET_assert (GNUNET_TIME_UNIT_ZERO_ABS.abs_value ==
161 (GNUNET_TIME_absolute_subtract (now, rel)).abs_value); 161 (GNUNET_TIME_absolute_subtract (now, rel)).abs_value);
162 rel.rel_value = 10000; 162 rel.rel_value = 10000;
163 GNUNET_assert (40000 == 163 GNUNET_assert (40000 == (GNUNET_TIME_absolute_subtract (now, rel)).abs_value);
164 (GNUNET_TIME_absolute_subtract (now, rel)).abs_value);
165 164
166 /*check relative divide */ 165 /*check relative divide */
167 GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_REL.rel_value == 166 GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_REL.rel_value ==
168 (GNUNET_TIME_relative_divide (rel, 0)).rel_value); 167 (GNUNET_TIME_relative_divide (rel, 0)).rel_value);
169 168
170 rel = GNUNET_TIME_UNIT_FOREVER_REL; 169 rel = GNUNET_TIME_UNIT_FOREVER_REL;
171 GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_REL.rel_value == 170 GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_REL.rel_value ==
172 (GNUNET_TIME_relative_divide (rel, 2)).rel_value); 171 (GNUNET_TIME_relative_divide (rel, 2)).rel_value);
173 172
174 rel = GNUNET_TIME_relative_divide (relUnit, 2); 173 rel = GNUNET_TIME_relative_divide (relUnit, 2);
175 GNUNET_assert (rel.rel_value == relUnit.rel_value / 2); 174 GNUNET_assert (rel.rel_value == relUnit.rel_value / 2);
@@ -183,51 +182,50 @@ check ()
183 forever = GNUNET_TIME_absolute_get_forever (); 182 forever = GNUNET_TIME_absolute_get_forever ();
184 forever.abs_value = forever.abs_value - 1024; 183 forever.abs_value = forever.abs_value - 1024;
185 GNUNET_assert (GNUNET_TIME_absolute_get_zero ().abs_value == 184 GNUNET_assert (GNUNET_TIME_absolute_get_zero ().abs_value ==
186 GNUNET_TIME_calculate_eta (forever, 50000, 185 GNUNET_TIME_calculate_eta (forever, 50000, 100000).rel_value);
187 100000).rel_value);
188 /* check zero */ 186 /* check zero */
189 GNUNET_log_skip (1, GNUNET_NO); 187 GNUNET_log_skip (1, GNUNET_NO);
190 GNUNET_assert (GNUNET_TIME_UNIT_ZERO.rel_value == 188 GNUNET_assert (GNUNET_TIME_UNIT_ZERO.rel_value ==
191 (GNUNET_TIME_calculate_eta (last, 60000, 50000)).rel_value); 189 (GNUNET_TIME_calculate_eta (last, 60000, 50000)).rel_value);
192 GNUNET_log_skip (0, GNUNET_YES); 190 GNUNET_log_skip (0, GNUNET_YES);
193 /*check forever */ 191 /*check forever */
194 GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_REL.rel_value == 192 GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_REL.rel_value ==
195 (GNUNET_TIME_calculate_eta (last, 0, 50000)).rel_value); 193 (GNUNET_TIME_calculate_eta (last, 0, 50000)).rel_value);
196 194
197 /*check relative subtract */ 195 /*check relative subtract */
198 now = GNUNET_TIME_absolute_get (); 196 now = GNUNET_TIME_absolute_get ();
199 rel.rel_value = now.abs_value; 197 rel.rel_value = now.abs_value;
200 relForever.rel_value = rel.rel_value + 1024; 198 relForever.rel_value = rel.rel_value + 1024;
201 GNUNET_assert (1024 == 199 GNUNET_assert (1024 ==
202 GNUNET_TIME_relative_subtract (relForever, rel).rel_value); 200 GNUNET_TIME_relative_subtract (relForever, rel).rel_value);
203 /*check zero */ 201 /*check zero */
204 GNUNET_assert (GNUNET_TIME_relative_get_zero ().rel_value == 202 GNUNET_assert (GNUNET_TIME_relative_get_zero ().rel_value ==
205 GNUNET_TIME_relative_subtract (rel, relForever).rel_value); 203 GNUNET_TIME_relative_subtract (rel, relForever).rel_value);
206 /*check forever */ 204 /*check forever */
207 rel.rel_value = UINT64_MAX; 205 rel.rel_value = UINT64_MAX;
208 GNUNET_assert (GNUNET_TIME_relative_get_forever ().rel_value == 206 GNUNET_assert (GNUNET_TIME_relative_get_forever ().rel_value ==
209 GNUNET_TIME_relative_subtract (rel, relForever).rel_value); 207 GNUNET_TIME_relative_subtract (rel, relForever).rel_value);
210 208
211 /*check GNUNET_TIME_relative_min */ 209 /*check GNUNET_TIME_relative_min */
212 now = GNUNET_TIME_absolute_get (); 210 now = GNUNET_TIME_absolute_get ();
213 rel.rel_value = now.abs_value; 211 rel.rel_value = now.abs_value;
214 relForever.rel_value = rel.rel_value - 1024; 212 relForever.rel_value = rel.rel_value - 1024;
215 GNUNET_assert (relForever.rel_value == 213 GNUNET_assert (relForever.rel_value ==
216 GNUNET_TIME_relative_min (rel, relForever).rel_value); 214 GNUNET_TIME_relative_min (rel, relForever).rel_value);
217 215
218 /*check GNUNET_TIME_relative_max */ 216 /*check GNUNET_TIME_relative_max */
219 GNUNET_assert (rel.rel_value == 217 GNUNET_assert (rel.rel_value ==
220 GNUNET_TIME_relative_max (rel, relForever).rel_value); 218 GNUNET_TIME_relative_max (rel, relForever).rel_value);
221 219
222 /*check GNUNET_TIME_absolute_min */ 220 /*check GNUNET_TIME_absolute_min */
223 now = GNUNET_TIME_absolute_get (); 221 now = GNUNET_TIME_absolute_get ();
224 last.abs_value = now.abs_value - 1024; 222 last.abs_value = now.abs_value - 1024;
225 GNUNET_assert (last.abs_value == 223 GNUNET_assert (last.abs_value ==
226 GNUNET_TIME_absolute_min (now, last).abs_value); 224 GNUNET_TIME_absolute_min (now, last).abs_value);
227 225
228 /*check GNUNET_TIME_absolute_max */ 226 /*check GNUNET_TIME_absolute_max */
229 GNUNET_assert (now.abs_value == 227 GNUNET_assert (now.abs_value ==
230 GNUNET_TIME_absolute_max (now, last).abs_value); 228 GNUNET_TIME_absolute_max (now, last).abs_value);
231 229
232 return 0; 230 return 0;
233} 231}
diff --git a/src/util/time.c b/src/util/time.c
index e48377fa3..3ee15516a 100644
--- a/src/util/time.c
+++ b/src/util/time.c
@@ -55,8 +55,8 @@ GNUNET_TIME_absolute_get ()
55 55
56 GETTIMEOFDAY (&tv, NULL); 56 GETTIMEOFDAY (&tv, NULL);
57 ret.abs_value = 57 ret.abs_value =
58 (uint64_t) (((uint64_t) tv.tv_sec * 1000LL) + 58 (uint64_t) (((uint64_t) tv.tv_sec * 1000LL) +
59 ((uint64_t) tv.tv_usec / 1000LL)) + timestamp_offset; 59 ((uint64_t) tv.tv_usec / 1000LL)) + timestamp_offset;
60 return ret; 60 return ret;
61} 61}
62 62
@@ -130,10 +130,10 @@ GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel)
130 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); 130 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
131 131
132 if (rel.rel_value + now.abs_value < rel.rel_value) 132 if (rel.rel_value + now.abs_value < rel.rel_value)
133 { 133 {
134 GNUNET_break (0); /* overflow... */ 134 GNUNET_break (0); /* overflow... */
135 return GNUNET_TIME_absolute_get_forever (); 135 return GNUNET_TIME_absolute_get_forever ();
136 } 136 }
137 ret.abs_value = rel.rel_value + now.abs_value; 137 ret.abs_value = rel.rel_value + now.abs_value;
138 return ret; 138 return ret;
139} 139}
@@ -148,7 +148,7 @@ GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel)
148 */ 148 */
149struct GNUNET_TIME_Relative 149struct GNUNET_TIME_Relative
150GNUNET_TIME_relative_min (struct GNUNET_TIME_Relative t1, 150GNUNET_TIME_relative_min (struct GNUNET_TIME_Relative t1,
151 struct GNUNET_TIME_Relative t2) 151 struct GNUNET_TIME_Relative t2)
152{ 152{
153 return (t1.rel_value < t2.rel_value) ? t1 : t2; 153 return (t1.rel_value < t2.rel_value) ? t1 : t2;
154} 154}
@@ -163,7 +163,7 @@ GNUNET_TIME_relative_min (struct GNUNET_TIME_Relative t1,
163 */ 163 */
164struct GNUNET_TIME_Relative 164struct GNUNET_TIME_Relative
165GNUNET_TIME_relative_max (struct GNUNET_TIME_Relative t1, 165GNUNET_TIME_relative_max (struct GNUNET_TIME_Relative t1,
166 struct GNUNET_TIME_Relative t2) 166 struct GNUNET_TIME_Relative t2)
167{ 167{
168 return (t1.rel_value > t2.rel_value) ? t1 : t2; 168 return (t1.rel_value > t2.rel_value) ? t1 : t2;
169} 169}
@@ -179,7 +179,7 @@ GNUNET_TIME_relative_max (struct GNUNET_TIME_Relative t1,
179 */ 179 */
180struct GNUNET_TIME_Absolute 180struct GNUNET_TIME_Absolute
181GNUNET_TIME_absolute_min (struct GNUNET_TIME_Absolute t1, 181GNUNET_TIME_absolute_min (struct GNUNET_TIME_Absolute t1,
182 struct GNUNET_TIME_Absolute t2) 182 struct GNUNET_TIME_Absolute t2)
183{ 183{
184 return (t1.abs_value < t2.abs_value) ? t1 : t2; 184 return (t1.abs_value < t2.abs_value) ? t1 : t2;
185} 185}
@@ -194,7 +194,7 @@ GNUNET_TIME_absolute_min (struct GNUNET_TIME_Absolute t1,
194 */ 194 */
195struct GNUNET_TIME_Absolute 195struct GNUNET_TIME_Absolute
196GNUNET_TIME_absolute_max (struct GNUNET_TIME_Absolute t1, 196GNUNET_TIME_absolute_max (struct GNUNET_TIME_Absolute t1,
197 struct GNUNET_TIME_Absolute t2) 197 struct GNUNET_TIME_Absolute t2)
198{ 198{
199 return (t1.abs_value > t2.abs_value) ? t1 : t2; 199 return (t1.abs_value > t2.abs_value) ? t1 : t2;
200} 200}
@@ -230,7 +230,7 @@ GNUNET_TIME_absolute_get_remaining (struct GNUNET_TIME_Absolute future)
230 */ 230 */
231struct GNUNET_TIME_Relative 231struct GNUNET_TIME_Relative
232GNUNET_TIME_absolute_get_difference (struct GNUNET_TIME_Absolute start, 232GNUNET_TIME_absolute_get_difference (struct GNUNET_TIME_Absolute start,
233 struct GNUNET_TIME_Absolute end) 233 struct GNUNET_TIME_Absolute end)
234{ 234{
235 struct GNUNET_TIME_Relative ret; 235 struct GNUNET_TIME_Relative ret;
236 236
@@ -271,17 +271,17 @@ GNUNET_TIME_absolute_get_duration (struct GNUNET_TIME_Absolute whence)
271 */ 271 */
272struct GNUNET_TIME_Absolute 272struct GNUNET_TIME_Absolute
273GNUNET_TIME_absolute_add (struct GNUNET_TIME_Absolute start, 273GNUNET_TIME_absolute_add (struct GNUNET_TIME_Absolute start,
274 struct GNUNET_TIME_Relative duration) 274 struct GNUNET_TIME_Relative duration)
275{ 275{
276 struct GNUNET_TIME_Absolute ret; 276 struct GNUNET_TIME_Absolute ret;
277 277
278 if ((start.abs_value == UINT64_MAX) || (duration.rel_value == UINT64_MAX)) 278 if ((start.abs_value == UINT64_MAX) || (duration.rel_value == UINT64_MAX))
279 return GNUNET_TIME_absolute_get_forever (); 279 return GNUNET_TIME_absolute_get_forever ();
280 if (start.abs_value + duration.rel_value < start.abs_value) 280 if (start.abs_value + duration.rel_value < start.abs_value)
281 { 281 {
282 GNUNET_break (0); 282 GNUNET_break (0);
283 return GNUNET_TIME_absolute_get_forever (); 283 return GNUNET_TIME_absolute_get_forever ();
284 } 284 }
285 ret.abs_value = start.abs_value + duration.rel_value; 285 ret.abs_value = start.abs_value + duration.rel_value;
286 return ret; 286 return ret;
287} 287}
@@ -297,7 +297,7 @@ GNUNET_TIME_absolute_add (struct GNUNET_TIME_Absolute start,
297 */ 297 */
298struct GNUNET_TIME_Absolute 298struct GNUNET_TIME_Absolute
299GNUNET_TIME_absolute_subtract (struct GNUNET_TIME_Absolute start, 299GNUNET_TIME_absolute_subtract (struct GNUNET_TIME_Absolute start,
300 struct GNUNET_TIME_Relative duration) 300 struct GNUNET_TIME_Relative duration)
301{ 301{
302 struct GNUNET_TIME_Absolute ret; 302 struct GNUNET_TIME_Absolute ret;
303 303
@@ -317,7 +317,7 @@ GNUNET_TIME_absolute_subtract (struct GNUNET_TIME_Absolute start,
317 */ 317 */
318struct GNUNET_TIME_Relative 318struct GNUNET_TIME_Relative
319GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, 319GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel,
320 unsigned int factor) 320 unsigned int factor)
321{ 321{
322 struct GNUNET_TIME_Relative ret; 322 struct GNUNET_TIME_Relative ret;
323 323
@@ -325,10 +325,10 @@ GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel,
325 return GNUNET_TIME_relative_get_zero (); 325 return GNUNET_TIME_relative_get_zero ();
326 ret.rel_value = rel.rel_value * (unsigned long long) factor; 326 ret.rel_value = rel.rel_value * (unsigned long long) factor;
327 if (ret.rel_value / factor != rel.rel_value) 327 if (ret.rel_value / factor != rel.rel_value)
328 { 328 {
329 GNUNET_break (0); 329 GNUNET_break (0);
330 return GNUNET_TIME_relative_get_forever (); 330 return GNUNET_TIME_relative_get_forever ();
331 } 331 }
332 return ret; 332 return ret;
333} 333}
334 334
@@ -342,7 +342,7 @@ GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel,
342 */ 342 */
343struct GNUNET_TIME_Relative 343struct GNUNET_TIME_Relative
344GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel, 344GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel,
345 unsigned int factor) 345 unsigned int factor)
346{ 346{
347 struct GNUNET_TIME_Relative ret; 347 struct GNUNET_TIME_Relative ret;
348 348
@@ -365,8 +365,8 @@ GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel,
365 * assuming it continues at the same speed 365 * assuming it continues at the same speed
366 */ 366 */
367struct GNUNET_TIME_Relative 367struct GNUNET_TIME_Relative
368GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start, 368GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start, uint64_t finished,
369 uint64_t finished, uint64_t total) 369 uint64_t total)
370{ 370{
371 struct GNUNET_TIME_Relative dur; 371 struct GNUNET_TIME_Relative dur;
372 double exp; 372 double exp;
@@ -393,17 +393,17 @@ GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start,
393 */ 393 */
394struct GNUNET_TIME_Relative 394struct GNUNET_TIME_Relative
395GNUNET_TIME_relative_add (struct GNUNET_TIME_Relative a1, 395GNUNET_TIME_relative_add (struct GNUNET_TIME_Relative a1,
396 struct GNUNET_TIME_Relative a2) 396 struct GNUNET_TIME_Relative a2)
397{ 397{
398 struct GNUNET_TIME_Relative ret; 398 struct GNUNET_TIME_Relative ret;
399 399
400 if ((a1.rel_value == UINT64_MAX) || (a2.rel_value == UINT64_MAX)) 400 if ((a1.rel_value == UINT64_MAX) || (a2.rel_value == UINT64_MAX))
401 return GNUNET_TIME_relative_get_forever (); 401 return GNUNET_TIME_relative_get_forever ();
402 if (a1.rel_value + a2.rel_value < a1.rel_value) 402 if (a1.rel_value + a2.rel_value < a1.rel_value)
403 { 403 {
404 GNUNET_break (0); 404 GNUNET_break (0);
405 return GNUNET_TIME_relative_get_forever (); 405 return GNUNET_TIME_relative_get_forever ();
406 } 406 }
407 ret.rel_value = a1.rel_value + a2.rel_value; 407 ret.rel_value = a1.rel_value + a2.rel_value;
408 return ret; 408 return ret;
409} 409}
@@ -418,7 +418,7 @@ GNUNET_TIME_relative_add (struct GNUNET_TIME_Relative a1,
418 */ 418 */
419struct GNUNET_TIME_Relative 419struct GNUNET_TIME_Relative
420GNUNET_TIME_relative_subtract (struct GNUNET_TIME_Relative a1, 420GNUNET_TIME_relative_subtract (struct GNUNET_TIME_Relative a1,
421 struct GNUNET_TIME_Relative a2) 421 struct GNUNET_TIME_Relative a2)
422{ 422{
423 struct GNUNET_TIME_Relative ret; 423 struct GNUNET_TIME_Relative ret;
424 424
diff --git a/src/util/winproc.c b/src/util/winproc.c
index aa4757f4a..252cacbfb 100644
--- a/src/util/winproc.c
+++ b/src/util/winproc.c
@@ -73,8 +73,7 @@ TSetNamedSecurityInfo GNSetNamedSecurityInfo;
73void 73void
74plibc_panic (int err, char *msg) 74plibc_panic (int err, char *msg)
75{ 75{
76 LOG (((err == 76 LOG (((err == INT_MAX) ? GNUNET_ERROR_TYPE_DEBUG : GNUNET_ERROR_TYPE_ERROR),
77 INT_MAX) ? GNUNET_ERROR_TYPE_DEBUG : GNUNET_ERROR_TYPE_ERROR),
78 "%s", msg); 77 "%s", msg);
79} 78}
80 79
@@ -100,139 +99,137 @@ GNInitWinEnv ()
100 99
101 /* Function to get CPU usage under Win NT */ 100 /* Function to get CPU usage under Win NT */
102 if (hNTDLL) 101 if (hNTDLL)
103 { 102 {
104 GNNtQuerySystemInformation = 103 GNNtQuerySystemInformation =
105 (TNtQuerySystemInformation) GetProcAddress (hNTDLL, 104 (TNtQuerySystemInformation) GetProcAddress (hNTDLL,
106 "NtQuerySystemInformation"); 105 "NtQuerySystemInformation");
107 } 106 }
108 else 107 else
109 { 108 {
110 GNNtQuerySystemInformation = NULL; 109 GNNtQuerySystemInformation = NULL;
111 } 110 }
112 111
113 /* Functions to get information about a network adapter */ 112 /* Functions to get information about a network adapter */
114 hIphlpapi = LoadLibrary ("iphlpapi.dll"); 113 hIphlpapi = LoadLibrary ("iphlpapi.dll");
115 if (hIphlpapi) 114 if (hIphlpapi)
116 { 115 {
117 GNGetIfEntry = (TGetIfEntry) GetProcAddress (hIphlpapi, "GetIfEntry"); 116 GNGetIfEntry = (TGetIfEntry) GetProcAddress (hIphlpapi, "GetIfEntry");
118 GNGetIpAddrTable = 117 GNGetIpAddrTable =
119 (TGetIpAddrTable) GetProcAddress (hIphlpapi, "GetIpAddrTable"); 118 (TGetIpAddrTable) GetProcAddress (hIphlpapi, "GetIpAddrTable");
120 GNGetIfTable = (TGetIfTable) GetProcAddress (hIphlpapi, "GetIfTable"); 119 GNGetIfTable = (TGetIfTable) GetProcAddress (hIphlpapi, "GetIfTable");
121 GNGetBestInterface = 120 GNGetBestInterface =
122 (TGetBestInterface) GetProcAddress (hIphlpapi, "GetBestInterface"); 121 (TGetBestInterface) GetProcAddress (hIphlpapi, "GetBestInterface");
123 GGetAdaptersInfo = 122 GGetAdaptersInfo =
124 (TGetAdaptersInfo) GetProcAddress (hIphlpapi, "GetAdaptersInfo"); 123 (TGetAdaptersInfo) GetProcAddress (hIphlpapi, "GetAdaptersInfo");
125 } 124 }
126 else 125 else
127 { 126 {
128 GNGetIfEntry = NULL; 127 GNGetIfEntry = NULL;
129 GNGetIpAddrTable = NULL; 128 GNGetIpAddrTable = NULL;
130 GNGetIfTable = NULL; 129 GNGetIfTable = NULL;
131 GNGetBestInterface = NULL; 130 GNGetBestInterface = NULL;
132 GGetAdaptersInfo = NULL; 131 GGetAdaptersInfo = NULL;
133 } 132 }
134 133
135 /* Service & Account functions */ 134 /* Service & Account functions */
136 hAdvapi = LoadLibrary ("advapi32.dll"); 135 hAdvapi = LoadLibrary ("advapi32.dll");
137 if (hAdvapi) 136 if (hAdvapi)
138 { 137 {
139 GNOpenSCManager = 138 GNOpenSCManager =
140 (TOpenSCManager) GetProcAddress (hAdvapi, "OpenSCManagerA"); 139 (TOpenSCManager) GetProcAddress (hAdvapi, "OpenSCManagerA");
141 GNCreateService = 140 GNCreateService =
142 (TCreateService) GetProcAddress (hAdvapi, "CreateServiceA"); 141 (TCreateService) GetProcAddress (hAdvapi, "CreateServiceA");
143 GNCloseServiceHandle = 142 GNCloseServiceHandle =
144 (TCloseServiceHandle) GetProcAddress (hAdvapi, "CloseServiceHandle"); 143 (TCloseServiceHandle) GetProcAddress (hAdvapi, "CloseServiceHandle");
145 GNDeleteService = 144 GNDeleteService =
146 (TDeleteService) GetProcAddress (hAdvapi, "DeleteService"); 145 (TDeleteService) GetProcAddress (hAdvapi, "DeleteService");
147 GNRegisterServiceCtrlHandler = 146 GNRegisterServiceCtrlHandler =
148 (TRegisterServiceCtrlHandler) GetProcAddress (hAdvapi, 147 (TRegisterServiceCtrlHandler) GetProcAddress (hAdvapi,
149 "RegisterServiceCtrlHandlerA"); 148 "RegisterServiceCtrlHandlerA");
150 GNSetServiceStatus = 149 GNSetServiceStatus =
151 (TSetServiceStatus) GetProcAddress (hAdvapi, "SetServiceStatus"); 150 (TSetServiceStatus) GetProcAddress (hAdvapi, "SetServiceStatus");
152 GNStartServiceCtrlDispatcher = 151 GNStartServiceCtrlDispatcher =
153 (TStartServiceCtrlDispatcher) GetProcAddress (hAdvapi, 152 (TStartServiceCtrlDispatcher) GetProcAddress (hAdvapi,
154 "StartServiceCtrlDispatcherA"); 153 "StartServiceCtrlDispatcherA");
155 GNControlService = 154 GNControlService =
156 (TControlService) GetProcAddress (hAdvapi, "ControlService"); 155 (TControlService) GetProcAddress (hAdvapi, "ControlService");
157 GNOpenService = (TOpenService) GetProcAddress (hAdvapi, "OpenServiceA"); 156 GNOpenService = (TOpenService) GetProcAddress (hAdvapi, "OpenServiceA");
158 157
159 GNLsaOpenPolicy = 158 GNLsaOpenPolicy =
160 (TLsaOpenPolicy) GetProcAddress (hAdvapi, "LsaOpenPolicy"); 159 (TLsaOpenPolicy) GetProcAddress (hAdvapi, "LsaOpenPolicy");
161 GNLsaAddAccountRights = 160 GNLsaAddAccountRights =
162 (TLsaAddAccountRights) GetProcAddress (hAdvapi, 161 (TLsaAddAccountRights) GetProcAddress (hAdvapi, "LsaAddAccountRights");
163 "LsaAddAccountRights"); 162 GNLsaRemoveAccountRights =
164 GNLsaRemoveAccountRights = 163 (TLsaRemoveAccountRights) GetProcAddress (hAdvapi,
165 (TLsaRemoveAccountRights) GetProcAddress (hAdvapi, 164 "LsaRemoveAccountRights");
166 "LsaRemoveAccountRights"); 165 GNLsaClose = (TLsaClose) GetProcAddress (hAdvapi, "LsaClose");
167 GNLsaClose = (TLsaClose) GetProcAddress (hAdvapi, "LsaClose"); 166 GNLookupAccountName =
168 GNLookupAccountName = 167 (TLookupAccountName) GetProcAddress (hAdvapi, "LookupAccountNameA");
169 (TLookupAccountName) GetProcAddress (hAdvapi, "LookupAccountNameA");
170 168
171 GNGetFileSecurity = 169 GNGetFileSecurity =
172 (TGetFileSecurity) GetProcAddress (hAdvapi, "GetFileSecurityA"); 170 (TGetFileSecurity) GetProcAddress (hAdvapi, "GetFileSecurityA");
173 GNInitializeSecurityDescriptor = 171 GNInitializeSecurityDescriptor =
174 (TInitializeSecurityDescriptor) GetProcAddress (hAdvapi, 172 (TInitializeSecurityDescriptor) GetProcAddress (hAdvapi,
175 "InitializeSecurityDescriptor"); 173 "InitializeSecurityDescriptor");
176 GNGetSecurityDescriptorDacl = 174 GNGetSecurityDescriptorDacl =
177 (TGetSecurityDescriptorDacl) GetProcAddress (hAdvapi, 175 (TGetSecurityDescriptorDacl) GetProcAddress (hAdvapi,
178 "GetSecurityDescriptorDacl"); 176 "GetSecurityDescriptorDacl");
179 GNGetAclInformation = 177 GNGetAclInformation =
180 (TGetAclInformation) GetProcAddress (hAdvapi, "GetAclInformation"); 178 (TGetAclInformation) GetProcAddress (hAdvapi, "GetAclInformation");
181 GNInitializeAcl = 179 GNInitializeAcl =
182 (TInitializeAcl) GetProcAddress (hAdvapi, "InitializeAcl"); 180 (TInitializeAcl) GetProcAddress (hAdvapi, "InitializeAcl");
183 GNGetAce = (TGetAce) GetProcAddress (hAdvapi, "GetAce"); 181 GNGetAce = (TGetAce) GetProcAddress (hAdvapi, "GetAce");
184 GNEqualSid = (TEqualSid) GetProcAddress (hAdvapi, "EqualSid"); 182 GNEqualSid = (TEqualSid) GetProcAddress (hAdvapi, "EqualSid");
185 GNAddAce = (TAddAce) GetProcAddress (hAdvapi, "AddAce"); 183 GNAddAce = (TAddAce) GetProcAddress (hAdvapi, "AddAce");
186 GNAddAccessAllowedAce = 184 GNAddAccessAllowedAce =
187 (TAddAccessAllowedAce) GetProcAddress (hAdvapi, 185 (TAddAccessAllowedAce) GetProcAddress (hAdvapi, "AddAccessAllowedAce");
188 "AddAccessAllowedAce"); 186 GNSetNamedSecurityInfo =
189 GNSetNamedSecurityInfo = 187 (TSetNamedSecurityInfo) GetProcAddress (hAdvapi,
190 (TSetNamedSecurityInfo) GetProcAddress (hAdvapi, 188 "SetNamedSecurityInfoA");
191 "SetNamedSecurityInfoA"); 189 }
192 }
193 else 190 else
194 { 191 {
195 GNOpenSCManager = NULL; 192 GNOpenSCManager = NULL;
196 GNCreateService = NULL; 193 GNCreateService = NULL;
197 GNCloseServiceHandle = NULL; 194 GNCloseServiceHandle = NULL;
198 GNDeleteService = NULL; 195 GNDeleteService = NULL;
199 GNRegisterServiceCtrlHandler = NULL; 196 GNRegisterServiceCtrlHandler = NULL;
200 GNSetServiceStatus = NULL; 197 GNSetServiceStatus = NULL;
201 GNStartServiceCtrlDispatcher = NULL; 198 GNStartServiceCtrlDispatcher = NULL;
202 GNControlService = NULL; 199 GNControlService = NULL;
203 GNOpenService = NULL; 200 GNOpenService = NULL;
204 201
205 GNLsaOpenPolicy = NULL; 202 GNLsaOpenPolicy = NULL;
206 GNLsaAddAccountRights = NULL; 203 GNLsaAddAccountRights = NULL;
207 GNLsaRemoveAccountRights = NULL; 204 GNLsaRemoveAccountRights = NULL;
208 GNLsaClose = NULL; 205 GNLsaClose = NULL;
209 GNLookupAccountName = NULL; 206 GNLookupAccountName = NULL;
210 207
211 GNGetFileSecurity = NULL; 208 GNGetFileSecurity = NULL;
212 GNInitializeSecurityDescriptor = NULL; 209 GNInitializeSecurityDescriptor = NULL;
213 GNGetSecurityDescriptorDacl = NULL; 210 GNGetSecurityDescriptorDacl = NULL;
214 GNGetAclInformation = NULL; 211 GNGetAclInformation = NULL;
215 GNInitializeAcl = NULL; 212 GNInitializeAcl = NULL;
216 GNGetAce = NULL; 213 GNGetAce = NULL;
217 GNEqualSid = NULL; 214 GNEqualSid = NULL;
218 GNAddAce = NULL; 215 GNAddAce = NULL;
219 GNAddAccessAllowedAce = NULL; 216 GNAddAccessAllowedAce = NULL;
220 GNSetNamedSecurityInfo = NULL; 217 GNSetNamedSecurityInfo = NULL;
221 } 218 }
222 219
223 /* Account function */ 220 /* Account function */
224 hNetapi = LoadLibrary ("netapi32.dll"); 221 hNetapi = LoadLibrary ("netapi32.dll");
225 if (hNetapi) 222 if (hNetapi)
226 { 223 {
227 GNNetUserAdd = (TNetUserAdd) GetProcAddress (hNetapi, "NetUserAdd"); 224 GNNetUserAdd = (TNetUserAdd) GetProcAddress (hNetapi, "NetUserAdd");
228 GNNetUserSetInfo = 225 GNNetUserSetInfo =
229 (TNetUserSetInfo) GetProcAddress (hNetapi, "NetUserSetInfo"); 226 (TNetUserSetInfo) GetProcAddress (hNetapi, "NetUserSetInfo");
230 } 227 }
231 else 228 else
232 { 229 {
233 GNNetUserAdd = NULL; 230 GNNetUserAdd = NULL;
234 GNNetUserSetInfo = NULL; 231 GNNetUserSetInfo = NULL;
235 } 232 }
236 233
237 return ret; 234 return ret;
238} 235}
diff --git a/src/vpn/gnunet-daemon-exit.c b/src/vpn/gnunet-daemon-exit.c
index 45076250d..838893882 100644
--- a/src/vpn/gnunet-daemon-exit.c
+++ b/src/vpn/gnunet-daemon-exit.c
@@ -199,24 +199,26 @@ cleanup (void *cls
199} 199}
200 200
201static void * 201static void *
202new_tunnel (void *cls __attribute__((unused)), 202new_tunnel (void *cls
203 struct GNUNET_MESH_Tunnel *tunnel, 203 __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel,
204 const struct GNUNET_PeerIdentity *initiator __attribute__((unused)), 204 const struct GNUNET_PeerIdentity *initiator
205 const struct GNUNET_ATS_Information *ats __attribute__((unused))) 205 __attribute__ ((unused)), const struct GNUNET_ATS_Information *ats
206 __attribute__ ((unused)))
206{ 207{
207 struct tunnel_state *s = GNUNET_malloc(sizeof *s); 208 struct tunnel_state *s = GNUNET_malloc (sizeof *s);
208 s->head = NULL; 209
209 s->tail = NULL; 210 s->head = NULL;
210 s->th = NULL; 211 s->tail = NULL;
211 return s; 212 s->th = NULL;
213 return s;
212} 214}
213 215
214static void 216static void
215clean_tunnel (void *cls __attribute__((unused)), 217clean_tunnel (void *cls
216 const struct GNUNET_MESH_Tunnel *tunnel, 218 __attribute__ ((unused)), const struct GNUNET_MESH_Tunnel *tunnel,
217 void *tunnel_ctx) 219 void *tunnel_ctx)
218{ 220{
219 GNUNET_free(tunnel_ctx); 221 GNUNET_free (tunnel_ctx);
220} 222}
221 223
222static void 224static void
@@ -236,7 +238,8 @@ collect_connections (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
236 /* FIXME! GNUNET_MESH_close_tunnel(state->tunnel); */ 238 /* FIXME! GNUNET_MESH_close_tunnel(state->tunnel); */
237 239
238 GNUNET_assert (GNUNET_OK == 240 GNUNET_assert (GNUNET_OK ==
239 GNUNET_CONTAINER_multihashmap_remove (state->hashmap, &state->hash, state)); 241 GNUNET_CONTAINER_multihashmap_remove (state->hashmap,
242 &state->hash, state));
240 243
241 GNUNET_free (state); 244 GNUNET_free (state);
242} 245}
@@ -275,7 +278,7 @@ send_udp_to_peer_notify_callback (void *cls, size_t size, void *buf)
275 memcpy (buf, hdr, ntohs (hdr->size)); 278 memcpy (buf, hdr, ntohs (hdr->size));
276 size = ntohs (hdr->size); 279 size = ntohs (hdr->size);
277 280
278 struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(*tunnel); 281 struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (*tunnel);
279 282
280 if (NULL != s->head) 283 if (NULL != s->head)
281 { 284 {
@@ -284,9 +287,7 @@ send_udp_to_peer_notify_callback (void *cls, size_t size, void *buf)
284 GNUNET_CONTAINER_DLL_remove (s->head, s->tail, element); 287 GNUNET_CONTAINER_DLL_remove (s->head, s->tail, element);
285 288
286 s->th = 289 s->th =
287 GNUNET_MESH_notify_transmit_ready (*tunnel, 290 GNUNET_MESH_notify_transmit_ready (*tunnel, GNUNET_NO, 42,
288 GNUNET_NO,
289 42,
290 GNUNET_TIME_relative_divide 291 GNUNET_TIME_relative_divide
291 (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), 292 (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2),
292 (const struct GNUNET_PeerIdentity *) 293 (const struct GNUNET_PeerIdentity *)
@@ -394,14 +395,13 @@ udp_from_helper (struct udp_pkt *udp, unsigned char *dadr, size_t addrlen)
394 395
395 memcpy (_udp, udp, ntohs (udp->len)); 396 memcpy (_udp, udp, ntohs (udp->len));
396 397
397 struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(tunnel); 398 struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (tunnel);
399
398 if (NULL == s->th) 400 if (NULL == s->th)
399 { 401 {
400 /* No notify is pending */ 402 /* No notify is pending */
401 s->th = 403 s->th =
402 GNUNET_MESH_notify_transmit_ready (tunnel, 404 GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO, 42,
403 GNUNET_NO,
404 42,
405 GNUNET_TIME_relative_divide 405 GNUNET_TIME_relative_divide
406 (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), 406 (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2),
407 (const struct GNUNET_PeerIdentity *) 407 (const struct GNUNET_PeerIdentity *)
@@ -502,18 +502,16 @@ tcp_from_helper (struct tcp_pkt *tcp, unsigned char *dadr, size_t addrlen,
502 memcpy (_tcp, tcp, pktlen); 502 memcpy (_tcp, tcp, pktlen);
503 503
504 struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (tunnel); 504 struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (tunnel);
505
505 if (NULL == s->th) 506 if (NULL == s->th)
506 { 507 {
507 /* No notify is pending */ 508 /* No notify is pending */
508 s->th = 509 s->th =
509 GNUNET_MESH_notify_transmit_ready (tunnel, 510 GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO, 42,
510 GNUNET_NO,
511 42,
512 GNUNET_TIME_relative_divide 511 GNUNET_TIME_relative_divide
513 (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), 512 (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2),
514 (const struct GNUNET_PeerIdentity *) 513 (const struct GNUNET_PeerIdentity *)
515 NULL, 514 NULL, len,
516 len,
517 send_udp_to_peer_notify_callback, 515 send_udp_to_peer_notify_callback,
518 ctunnel); 516 ctunnel);
519 } 517 }
@@ -684,44 +682,57 @@ read_service_conf (void *cls __attribute__ ((unused)), const char *section)
684 } 682 }
685 else 683 else
686 { 684 {
687 struct addrinfo* res; 685 struct addrinfo *res;
688 686
689 int ret = getaddrinfo(hostname, NULL, NULL, &res); 687 int ret = getaddrinfo (hostname, NULL, NULL, &res);
690 688
691 if (ret != 0) 689 if (ret != 0)
690 {
691 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No addresses found for %s!\n",
692 hostname);
693 GNUNET_free (serv);
694 continue;
695 }
696 else
697 {
698 char buf[256];
699 struct addrinfo *c = res;
700
701 if (c)
692 { 702 {
693 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No addresses found for %s!\n", hostname); 703 if (c->ai_family == AF_INET)
694 GNUNET_free (serv); 704 {
695 continue; 705 serv->version = 4;
706 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
707 "Found %s as address for %s\n",
708 inet_ntop (c->ai_family,
709 &((struct sockaddr_in *) (c->
710 ai_addr))->sin_addr,
711 (char *) &buf, 256), hostname);
712 memcpy (serv->v4.ip4address,
713 &((struct sockaddr_in *) (c->ai_addr))->sin_addr, 4);
714 }
715 else if (c->ai_family == AF_INET6)
716 {
717 serv->version = 6;
718 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
719 "Found %s as address for %s\n",
720 inet_ntop (c->ai_family,
721 &((struct sockaddr_in6 *) (c->
722 ai_addr))->sin6_addr,
723 (char *) &buf, 256), hostname);
724 memcpy (serv->v6.ip6address,
725 &((struct sockaddr_in6 *) (c->ai_addr))->sin6_addr, 16);
726 }
696 } 727 }
697 else 728 else
698 { 729 {
699 char buf[256]; 730 freeaddrinfo (res);
700 struct addrinfo* c = res; 731 GNUNET_free (serv);
701 732 continue;
702 if(c)
703 {
704 if (c->ai_family == AF_INET)
705 {
706 serv->version = 4;
707 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found %s as address for %s\n", inet_ntop(c->ai_family, &((struct sockaddr_in *)(c->ai_addr))->sin_addr, (char*)&buf, 256), hostname);
708 memcpy(serv->v4.ip4address, &((struct sockaddr_in *)(c->ai_addr))->sin_addr, 4);
709 }
710 else if (c->ai_family == AF_INET6)
711 {
712 serv->version = 6;
713 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found %s as address for %s\n", inet_ntop(c->ai_family, &((struct sockaddr_in6*)(c->ai_addr))->sin6_addr, (char*)&buf, 256), hostname);
714 memcpy(serv->v6.ip6address, &((struct sockaddr_in6 *)(c->ai_addr))->sin6_addr, 16);
715 }
716 }
717 else
718 {
719 freeaddrinfo(res);
720 GNUNET_free (serv);
721 continue;
722 }
723 freeaddrinfo(res);
724 } 733 }
734 freeaddrinfo (res);
735 }
725 } 736 }
726 serv->remote_port = atoi (hostport); 737 serv->remote_port = atoi (hostport);
727 if (UDP == proto) 738 if (UDP == proto)
@@ -1095,14 +1106,12 @@ receive_tcp_service (void *cls
1095 switch (serv->version) 1106 switch (serv->version)
1096 { 1107 {
1097 case 4: 1108 case 4:
1098 prepare_ipv4_packet (len, pkt_len, pkt, IPPROTO_TCP, 1109 prepare_ipv4_packet (len, pkt_len, pkt, IPPROTO_TCP, &serv->v4.ip4address,
1099 &serv->v4.ip4address, tunnel, state, 1110 tunnel, state, (struct ip_pkt *) buf);
1100 (struct ip_pkt *) buf);
1101 break; 1111 break;
1102 case 6: 1112 case 6:
1103 prepare_ipv6_packet (len, pkt_len, pkt, IPPROTO_TCP, 1113 prepare_ipv6_packet (len, pkt_len, pkt, IPPROTO_TCP, &serv->v6.ip6address,
1104 &serv->v6.ip6address, tunnel, state, 1114 tunnel, state, (struct ip6_pkt *) buf);
1105 (struct ip6_pkt *) buf);
1106 1115
1107 break; 1116 break;
1108 default: 1117 default:
@@ -1171,12 +1180,12 @@ receive_tcp_remote (void *cls
1171 switch (s->addrlen) 1180 switch (s->addrlen)
1172 { 1181 {
1173 case 4: 1182 case 4:
1174 prepare_ipv4_packet (len, pkt_len, pkt, IPPROTO_TCP, 1183 prepare_ipv4_packet (len, pkt_len, pkt, IPPROTO_TCP, &s->addr, tunnel,
1175 &s->addr, tunnel, state, (struct ip_pkt *) buf); 1184 state, (struct ip_pkt *) buf);
1176 break; 1185 break;
1177 case 16: 1186 case 16:
1178 prepare_ipv6_packet (len, pkt_len, pkt, IPPROTO_TCP, 1187 prepare_ipv6_packet (len, pkt_len, pkt, IPPROTO_TCP, &s->addr, tunnel,
1179 &s->addr, tunnel, state, (struct ip6_pkt *) buf); 1188 state, (struct ip6_pkt *) buf);
1180 break; 1189 break;
1181 default: 1190 default:
1182 GNUNET_free (state); 1191 GNUNET_free (state);
@@ -1252,12 +1261,12 @@ receive_udp_remote (void *cls
1252 switch (s->addrlen) 1261 switch (s->addrlen)
1253 { 1262 {
1254 case 4: 1263 case 4:
1255 prepare_ipv4_packet (len, ntohs (pkt->len), pkt, IPPROTO_UDP, 1264 prepare_ipv4_packet (len, ntohs (pkt->len), pkt, IPPROTO_UDP, &s->addr,
1256 &s->addr, tunnel, state, (struct ip_pkt *) buf); 1265 tunnel, state, (struct ip_pkt *) buf);
1257 break; 1266 break;
1258 case 16: 1267 case 16:
1259 prepare_ipv6_packet (len, ntohs (pkt->len), pkt, IPPROTO_UDP, 1268 prepare_ipv6_packet (len, ntohs (pkt->len), pkt, IPPROTO_UDP, &s->addr,
1260 &s->addr, tunnel, state, (struct ip6_pkt *) buf); 1269 tunnel, state, (struct ip6_pkt *) buf);
1261 break; 1270 break;
1262 default: 1271 default:
1263 GNUNET_assert (0); 1272 GNUNET_assert (0);
@@ -1291,12 +1300,14 @@ receive_udp_remote (void *cls
1291 * The messages are one GNUNET_HashCode for the service, followed by a struct udp_pkt 1300 * The messages are one GNUNET_HashCode for the service, followed by a struct udp_pkt
1292 */ 1301 */
1293static int 1302static int
1294receive_udp_service (void *cls __attribute__ ((unused)), 1303receive_udp_service (void *cls
1295 struct GNUNET_MESH_Tunnel *tunnel, 1304 __attribute__ ((unused)),
1296 void **tunnel_ctx, 1305 struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx,
1297 const struct GNUNET_PeerIdentity *sender __attribute__ ((unused)), 1306 const struct GNUNET_PeerIdentity *sender
1307 __attribute__ ((unused)),
1298 const struct GNUNET_MessageHeader *message, 1308 const struct GNUNET_MessageHeader *message,
1299 const struct GNUNET_ATS_Information *atsi __attribute__ ((unused))) 1309 const struct GNUNET_ATS_Information *atsi
1310 __attribute__ ((unused)))
1300{ 1311{
1301 GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); 1312 GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
1302 struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1); 1313 struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1);
@@ -1437,7 +1448,9 @@ connect_to_mesh ()
1437 app_idx++; 1448 app_idx++;
1438 } 1449 }
1439 1450
1440 mesh_handle = GNUNET_MESH_connect (cfg, 42, NULL, new_tunnel, clean_tunnel, handlers, apptypes); 1451 mesh_handle =
1452 GNUNET_MESH_connect (cfg, 42, NULL, new_tunnel, clean_tunnel, handlers,
1453 apptypes);
1441} 1454}
1442 1455
1443 1456
@@ -1468,11 +1481,11 @@ run (void *cls, char *const *args __attribute__ ((unused)), const char *cfgfile
1468 1481
1469 if (GNUNET_OK != 1482 if (GNUNET_OK !=
1470 GNUNET_CONFIGURATION_get_value_number (cfg, "exit", "MAX_UDP_CONNECTIONS", 1483 GNUNET_CONFIGURATION_get_value_number (cfg, "exit", "MAX_UDP_CONNECTIONS",
1471 &max_udp_connections)) 1484 &max_udp_connections))
1472 max_udp_connections = 1024; 1485 max_udp_connections = 1024;
1473 if (GNUNET_OK != 1486 if (GNUNET_OK !=
1474 GNUNET_CONFIGURATION_get_value_number (cfg, "exit", "MAX_TCP_CONNECTIONS", 1487 GNUNET_CONFIGURATION_get_value_number (cfg, "exit", "MAX_TCP_CONNECTIONS",
1475 &max_tcp_connections)) 1488 &max_tcp_connections))
1476 max_tcp_connections = 256; 1489 max_tcp_connections = 256;
1477 GNUNET_CONFIGURATION_iterate_sections (cfg, read_service_conf, NULL); 1490 GNUNET_CONFIGURATION_iterate_sections (cfg, read_service_conf, NULL);
1478 GNUNET_SCHEDULER_add_now (start_helper_and_schedule, NULL); 1491 GNUNET_SCHEDULER_add_now (start_helper_and_schedule, NULL);
@@ -1481,7 +1494,7 @@ run (void *cls, char *const *args __attribute__ ((unused)), const char *cfgfile
1481 1494
1482 1495
1483/** 1496/**
1484 * The main function 1497 * The main function
1485 * 1498 *
1486 * @param argc number of arguments from the command line 1499 * @param argc number of arguments from the command line
1487 * @param argv command line arguments 1500 * @param argv command line arguments
@@ -1495,8 +1508,9 @@ main (int argc, char *const *argv)
1495 }; 1508 };
1496 1509
1497 return (GNUNET_OK == 1510 return (GNUNET_OK ==
1498 GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-exit", 1511 GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-exit",
1499 gettext_noop ("Daemon to run to provide an IP exit node for the VPN"), 1512 gettext_noop
1513 ("Daemon to run to provide an IP exit node for the VPN"),
1500 options, &run, NULL)) ? ret : 1; 1514 options, &run, NULL)) ? ret : 1;
1501} 1515}
1502 1516
diff --git a/src/vpn/gnunet-daemon-vpn-dns.c b/src/vpn/gnunet-daemon-vpn-dns.c
index 7f762238c..77d900046 100644
--- a/src/vpn/gnunet-daemon-vpn-dns.c
+++ b/src/vpn/gnunet-daemon-vpn-dns.c
@@ -57,6 +57,7 @@ size_t
57send_query (void *cls __attribute__ ((unused)), size_t size, void *buf) 57send_query (void *cls __attribute__ ((unused)), size_t size, void *buf)
58{ 58{
59 size_t len; 59 size_t len;
60
60 dns_transmit_handle = NULL; 61 dns_transmit_handle = NULL;
61 62
62 /* 63 /*
@@ -100,17 +101,20 @@ send_query (void *cls __attribute__ ((unused)), size_t size, void *buf)
100 */ 101 */
101 if (head != NULL) 102 if (head != NULL)
102 { 103 {
103 dns_transmit_handle = GNUNET_CLIENT_notify_transmit_ready (dns_connection, 104 dns_transmit_handle =
104 ntohs (head->pkt.hdr.size), 105 GNUNET_CLIENT_notify_transmit_ready (dns_connection,
105 GNUNET_TIME_UNIT_FOREVER_REL, 106 ntohs (head->pkt.hdr.size),
106 GNUNET_YES, &send_query, NULL); 107 GNUNET_TIME_UNIT_FOREVER_REL,
108 GNUNET_YES, &send_query, NULL);
107 } 109 }
108 else if (restart_hijack == 1) 110 else if (restart_hijack == 1)
109 { 111 {
110 dns_transmit_handle = GNUNET_CLIENT_notify_transmit_ready (dns_connection, 112 dns_transmit_handle =
111 sizeof (struct GNUNET_MessageHeader), 113 GNUNET_CLIENT_notify_transmit_ready (dns_connection,
112 GNUNET_TIME_UNIT_FOREVER_REL, 114 sizeof (struct
113 GNUNET_YES, &send_query, NULL); 115 GNUNET_MessageHeader),
116 GNUNET_TIME_UNIT_FOREVER_REL,
117 GNUNET_YES, &send_query, NULL);
114 } 118 }
115 119
116 return len; 120 return len;
@@ -144,16 +148,19 @@ connect_to_service_dns (void *cls
144 148
145 /* If a packet is already in the list, schedule to send it */ 149 /* If a packet is already in the list, schedule to send it */
146 if (dns_transmit_handle == NULL && head != NULL) 150 if (dns_transmit_handle == NULL && head != NULL)
147 dns_transmit_handle = GNUNET_CLIENT_notify_transmit_ready (dns_connection, 151 dns_transmit_handle =
148 ntohs (head->pkt.hdr.size), 152 GNUNET_CLIENT_notify_transmit_ready (dns_connection,
149 GNUNET_TIME_UNIT_FOREVER_REL, 153 ntohs (head->pkt.hdr.size),
150 GNUNET_YES, &send_query, NULL); 154 GNUNET_TIME_UNIT_FOREVER_REL,
155 GNUNET_YES, &send_query, NULL);
151 else if (dns_transmit_handle == NULL && restart_hijack == 1) 156 else if (dns_transmit_handle == NULL && restart_hijack == 1)
152 { 157 {
153 dns_transmit_handle = GNUNET_CLIENT_notify_transmit_ready (dns_connection, 158 dns_transmit_handle =
154 sizeof (struct GNUNET_MessageHeader), 159 GNUNET_CLIENT_notify_transmit_ready (dns_connection,
155 GNUNET_TIME_UNIT_FOREVER_REL, 160 sizeof (struct
156 GNUNET_YES, &send_query, NULL); 161 GNUNET_MessageHeader),
162 GNUNET_TIME_UNIT_FOREVER_REL,
163 GNUNET_YES, &send_query, NULL);
157 } 164 }
158} 165}
159 166
@@ -170,7 +177,7 @@ dns_answer_handler (void *cls
170 if (msg == NULL) 177 if (msg == NULL)
171 { 178 {
172 if (dns_transmit_handle != NULL) 179 if (dns_transmit_handle != NULL)
173 GNUNET_CLIENT_notify_transmit_ready_cancel(dns_transmit_handle); 180 GNUNET_CLIENT_notify_transmit_ready_cancel (dns_transmit_handle);
174 dns_transmit_handle = NULL; 181 dns_transmit_handle = NULL;
175 GNUNET_CLIENT_disconnect (dns_connection, GNUNET_NO); 182 GNUNET_CLIENT_disconnect (dns_connection, GNUNET_NO);
176 dns_connection = NULL; 183 dns_connection = NULL;
diff --git a/src/vpn/gnunet-daemon-vpn-helper.c b/src/vpn/gnunet-daemon-vpn-helper.c
index 124b53bf1..29227893a 100644
--- a/src/vpn/gnunet-daemon-vpn-helper.c
+++ b/src/vpn/gnunet-daemon-vpn-helper.c
@@ -45,7 +45,7 @@
45 45
46struct GNUNET_VPN_HELPER_Handle *helper_handle; 46struct GNUNET_VPN_HELPER_Handle *helper_handle;
47 47
48extern struct GNUNET_CLIENT_TransmitHandle* dns_transmit_handle; 48extern struct GNUNET_CLIENT_TransmitHandle *dns_transmit_handle;
49 49
50/** 50/**
51 * The tunnels that will be used to send tcp- and udp-packets 51 * The tunnels that will be used to send tcp- and udp-packets
@@ -140,10 +140,12 @@ start_helper_and_schedule (void *cls,
140 */ 140 */
141 restart_hijack = 1; 141 restart_hijack = 1;
142 if (NULL != dns_connection && dns_transmit_handle == NULL) 142 if (NULL != dns_connection && dns_transmit_handle == NULL)
143 dns_transmit_handle = GNUNET_CLIENT_notify_transmit_ready (dns_connection, 143 dns_transmit_handle =
144 sizeof (struct GNUNET_MessageHeader), 144 GNUNET_CLIENT_notify_transmit_ready (dns_connection,
145 GNUNET_TIME_UNIT_FOREVER_REL, 145 sizeof (struct
146 GNUNET_YES, &send_query, NULL); 146 GNUNET_MessageHeader),
147 GNUNET_TIME_UNIT_FOREVER_REL,
148 GNUNET_YES, &send_query, NULL);
147 149
148 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, 150 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
149 helper_handle->fh_to_helper, &helper_write, 151 helper_handle->fh_to_helper, &helper_write,
@@ -152,10 +154,11 @@ start_helper_and_schedule (void *cls,
152 154
153/*}}}*/ 155/*}}}*/
154 156
155static void* 157static void *
156initialize_tunnel_state(int addrlen, struct GNUNET_MESH_TransmitHandle* th) 158initialize_tunnel_state (int addrlen, struct GNUNET_MESH_TransmitHandle *th)
157{ 159{
158 struct tunnel_state* ts = GNUNET_malloc(sizeof *ts); 160 struct tunnel_state *ts = GNUNET_malloc (sizeof *ts);
161
159 ts->addrlen = addrlen; 162 ts->addrlen = addrlen;
160 ts->th = th; 163 ts->th = th;
161 return ts; 164 return ts;
@@ -186,111 +189,115 @@ helper_write (void *cls
186 189
187 size_t data_len = len - sizeof (struct answer_packet) + 1; 190 size_t data_len = len - sizeof (struct answer_packet) + 1;
188 191
189 void* buf; 192 void *buf;
190 size_t pkt_len; 193 size_t pkt_len;
191 194
192 if (ans->pkt.addrlen == 16) 195 if (ans->pkt.addrlen == 16)
193 { 196 {
194 size_t net_len = sizeof (struct ip6_hdr) + sizeof (struct udp_dns) + data_len; 197 size_t net_len =
195 pkt_len = 198 sizeof (struct ip6_hdr) + sizeof (struct udp_dns) + data_len;
196 sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) + net_len; 199 pkt_len =
200 sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) +
201 net_len;
197 202
198 struct ip6_udp_dns *pkt = alloca (pkt_len); 203 struct ip6_udp_dns *pkt = alloca (pkt_len);
199 204
200 GNUNET_assert (pkt != NULL); 205 GNUNET_assert (pkt != NULL);
201 memset (pkt, 0, pkt_len); 206 memset (pkt, 0, pkt_len);
202 207
203 /* set the gnunet-header */ 208 /* set the gnunet-header */
204 pkt->shdr.size = htons (pkt_len); 209 pkt->shdr.size = htons (pkt_len);
205 pkt->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); 210 pkt->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
206 211
207 /* set the tun-header (no flags and ethertype of IPv4) */ 212 /* set the tun-header (no flags and ethertype of IPv4) */
208 pkt->tun.flags = 0; 213 pkt->tun.flags = 0;
209 pkt->tun.type = htons (0x86dd); 214 pkt->tun.type = htons (0x86dd);
210 215
211 memcpy(&pkt->ip6_hdr.sadr, ans->pkt.from, 16); 216 memcpy (&pkt->ip6_hdr.sadr, ans->pkt.from, 16);
212 memcpy(&pkt->ip6_hdr.dadr, ans->pkt.to, 16); 217 memcpy (&pkt->ip6_hdr.dadr, ans->pkt.to, 16);
213 218
214 /* set the udp-header */ 219 /* set the udp-header */
215 pkt->udp_dns.udp_hdr.spt = htons (53); 220 pkt->udp_dns.udp_hdr.spt = htons (53);
216 pkt->udp_dns.udp_hdr.dpt = ans->pkt.dst_port; 221 pkt->udp_dns.udp_hdr.dpt = ans->pkt.dst_port;
217 pkt->udp_dns.udp_hdr.len = htons (net_len - sizeof (struct ip6_hdr)); 222 pkt->udp_dns.udp_hdr.len = htons (net_len - sizeof (struct ip6_hdr));
218 pkt->udp_dns.udp_hdr.crc = 0; 223 pkt->udp_dns.udp_hdr.crc = 0;
219 uint32_t sum = 0; 224 uint32_t sum = 0;
220 225
221 sum = 226 sum = calculate_checksum_update (sum, (uint16_t *) & pkt->ip6_hdr.sadr, 16);
222 calculate_checksum_update (sum, (uint16_t *) & pkt->ip6_hdr.sadr, 16); 227 sum = calculate_checksum_update (sum, (uint16_t *) & pkt->ip6_hdr.dadr, 16);
223 sum = 228 uint32_t tmp = (pkt->udp_dns.udp_hdr.len & 0xffff);
224 calculate_checksum_update (sum, (uint16_t *) & pkt->ip6_hdr.dadr, 16);
225 uint32_t tmp = (pkt->udp_dns.udp_hdr.len & 0xffff);
226 229
227 sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); 230 sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
228 tmp = htons (((pkt->ip6_hdr.nxthdr & 0x00ff))); 231 tmp = htons (((pkt->ip6_hdr.nxthdr & 0x00ff)));
229 sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); 232 sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
230 233
231 sum = 234 sum =
232 calculate_checksum_update (sum, (uint16_t *) & pkt->udp_dns.udp_hdr, 235 calculate_checksum_update (sum, (uint16_t *) & pkt->udp_dns.udp_hdr,
233 ntohs (net_len - sizeof(struct ip6_hdr))); 236 ntohs (net_len - sizeof (struct ip6_hdr)));
234 pkt->udp_dns.udp_hdr.crc = calculate_checksum_end (sum); 237 pkt->udp_dns.udp_hdr.crc = calculate_checksum_end (sum);
235 238
236 pkt->ip6_hdr.version = 6; 239 pkt->ip6_hdr.version = 6;
237 pkt->ip6_hdr.paylgth = net_len - sizeof (struct ip6_hdr); 240 pkt->ip6_hdr.paylgth = net_len - sizeof (struct ip6_hdr);
238 pkt->ip6_hdr.nxthdr = IPPROTO_UDP; 241 pkt->ip6_hdr.nxthdr = IPPROTO_UDP;
239 pkt->ip6_hdr.hoplmt = 0xff; 242 pkt->ip6_hdr.hoplmt = 0xff;
240 243
241 memcpy (&pkt->udp_dns.data, ans->pkt.data, data_len); 244 memcpy (&pkt->udp_dns.data, ans->pkt.data, data_len);
242 buf = pkt; 245 buf = pkt;
243 } 246 }
244 else if (ans->pkt.addrlen == 4) 247 else if (ans->pkt.addrlen == 4)
245 { 248 {
246 size_t net_len = sizeof (struct ip_hdr) + sizeof (struct udp_dns) + data_len; 249 size_t net_len =
247 pkt_len = 250 sizeof (struct ip_hdr) + sizeof (struct udp_dns) + data_len;
248 sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) + net_len; 251 pkt_len =
249 252 sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) +
250 struct ip_udp_dns *pkt = alloca (pkt_len); 253 net_len;
251 254
252 GNUNET_assert (pkt != NULL); 255 struct ip_udp_dns *pkt = alloca (pkt_len);
253 memset (pkt, 0, pkt_len); 256
254 257 GNUNET_assert (pkt != NULL);
255 /* set the gnunet-header */ 258 memset (pkt, 0, pkt_len);
256 pkt->shdr.size = htons (pkt_len); 259
257 pkt->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); 260 /* set the gnunet-header */
258 261 pkt->shdr.size = htons (pkt_len);
259 /* set the tun-header (no flags and ethertype of IPv4) */ 262 pkt->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
260 pkt->tun.flags = 0; 263
261 pkt->tun.type = htons (0x0800); 264 /* set the tun-header (no flags and ethertype of IPv4) */
262 265 pkt->tun.flags = 0;
263 /* set the ip-header */ 266 pkt->tun.type = htons (0x0800);
264 pkt->ip_hdr.version = 4; 267
265 pkt->ip_hdr.hdr_lngth = 5; 268 /* set the ip-header */
266 pkt->ip_hdr.diff_serv = 0; 269 pkt->ip_hdr.version = 4;
267 pkt->ip_hdr.tot_lngth = htons (net_len); 270 pkt->ip_hdr.hdr_lngth = 5;
268 pkt->ip_hdr.ident = 0; 271 pkt->ip_hdr.diff_serv = 0;
269 pkt->ip_hdr.flags = 0; 272 pkt->ip_hdr.tot_lngth = htons (net_len);
270 pkt->ip_hdr.frag_off = 0; 273 pkt->ip_hdr.ident = 0;
271 pkt->ip_hdr.ttl = 255; 274 pkt->ip_hdr.flags = 0;
272 pkt->ip_hdr.proto = IPPROTO_UDP; 275 pkt->ip_hdr.frag_off = 0;
273 pkt->ip_hdr.chks = 0; /* Will be calculated later */ 276 pkt->ip_hdr.ttl = 255;
274 277 pkt->ip_hdr.proto = IPPROTO_UDP;
275 memcpy(&pkt->ip_hdr.sadr, ans->pkt.from, 4); 278 pkt->ip_hdr.chks = 0; /* Will be calculated later */
276 memcpy(&pkt->ip_hdr.dadr, ans->pkt.to, 4); 279
277 280 memcpy (&pkt->ip_hdr.sadr, ans->pkt.from, 4);
278 pkt->ip_hdr.chks = calculate_ip_checksum ((uint16_t *) & pkt->ip_hdr, 5 * 4); 281 memcpy (&pkt->ip_hdr.dadr, ans->pkt.to, 4);
279 282
280 /* set the udp-header */ 283 pkt->ip_hdr.chks =
281 pkt->udp_dns.udp_hdr.spt = htons (53); 284 calculate_ip_checksum ((uint16_t *) & pkt->ip_hdr, 5 * 4);
282 pkt->udp_dns.udp_hdr.dpt = ans->pkt.dst_port; 285
283 pkt->udp_dns.udp_hdr.len = htons (net_len - sizeof (struct ip_hdr)); 286 /* set the udp-header */
284 pkt->udp_dns.udp_hdr.crc = 0; /* Optional for IPv4 */ 287 pkt->udp_dns.udp_hdr.spt = htons (53);
285 288 pkt->udp_dns.udp_hdr.dpt = ans->pkt.dst_port;
286 memcpy (&pkt->udp_dns.data, ans->pkt.data, data_len); 289 pkt->udp_dns.udp_hdr.len = htons (net_len - sizeof (struct ip_hdr));
287 buf = pkt; 290 pkt->udp_dns.udp_hdr.crc = 0; /* Optional for IPv4 */
288 } 291
292 memcpy (&pkt->udp_dns.data, ans->pkt.data, data_len);
293 buf = pkt;
294 }
289 else 295 else
290 { 296 {
291 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Wrong addrlen = %d\n", ans->pkt.addrlen); 297 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Wrong addrlen = %d\n",
292 GNUNET_assert(0); 298 ans->pkt.addrlen);
293 } 299 GNUNET_assert (0);
300 }
294 301
295 GNUNET_CONTAINER_DLL_remove (answer_proc_head, answer_proc_tail, ans); 302 GNUNET_CONTAINER_DLL_remove (answer_proc_head, answer_proc_tail, ans);
296 GNUNET_free (ans); 303 GNUNET_free (ans);
@@ -332,37 +339,43 @@ message_token (void *cls __attribute__ ((unused)), void *client
332 struct ip6_udp *pkt6_udp; 339 struct ip6_udp *pkt6_udp;
333 struct ip6_icmp *pkt6_icmp; 340 struct ip6_icmp *pkt6_icmp;
334 341
335 pkt6_udp = NULL; /* make compiler happy */ 342 pkt6_udp = NULL; /* make compiler happy */
336 switch (pkt6->ip6_hdr.nxthdr) 343 switch (pkt6->ip6_hdr.nxthdr)
337 { 344 {
338 case IPPROTO_UDP: 345 case IPPROTO_UDP:
339 pkt6_udp = (struct ip6_udp *) pkt6; 346 pkt6_udp = (struct ip6_udp *) pkt6;
340 /* Send dns-packets to the service-dns */ 347 /* Send dns-packets to the service-dns */
341 if (ntohs (pkt6_udp->udp_hdr.dpt) == 53) 348 if (ntohs (pkt6_udp->udp_hdr.dpt) == 53)
342 { 349 {
343 /* 9 = 8 for the udp-header + 1 for the unsigned char data[1]; */ 350 /* 9 = 8 for the udp-header + 1 for the unsigned char data[1]; */
344 size_t len = sizeof (struct query_packet) + ntohs (pkt6_udp->udp_hdr.len) - 9; 351 size_t len =
345 352 sizeof (struct query_packet) + ntohs (pkt6_udp->udp_hdr.len) - 9;
346 struct query_packet_list *query = 353
347 GNUNET_malloc (len + sizeof(struct answer_packet_list) - sizeof(struct answer_packet)); 354 struct query_packet_list *query =
348 query->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_QUERY_DNS); 355 GNUNET_malloc (len + sizeof (struct answer_packet_list) -
349 query->pkt.hdr.size = htons (len); 356 sizeof (struct answer_packet));
350 memcpy(query->pkt.orig_to, &pkt6->ip6_hdr.dadr, 16); 357 query->pkt.hdr.type =
351 memcpy(query->pkt.orig_from, &pkt6->ip6_hdr.sadr, 16); 358 htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_QUERY_DNS);
352 query->pkt.addrlen = 16; 359 query->pkt.hdr.size = htons (len);
353 query->pkt.src_port = pkt6_udp->udp_hdr.spt; 360 memcpy (query->pkt.orig_to, &pkt6->ip6_hdr.dadr, 16);
354 memcpy (query->pkt.data, pkt6_udp->data, ntohs (pkt6_udp->udp_hdr.len) - 8); 361 memcpy (query->pkt.orig_from, &pkt6->ip6_hdr.sadr, 16);
355 362 query->pkt.addrlen = 16;
356 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, query); 363 query->pkt.src_port = pkt6_udp->udp_hdr.spt;
357 364 memcpy (query->pkt.data, pkt6_udp->data,
358 GNUNET_assert (head != NULL); 365 ntohs (pkt6_udp->udp_hdr.len) - 8);
359 366
360 if (dns_connection != NULL && dns_transmit_handle == NULL) 367 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, query);
361 dns_transmit_handle = GNUNET_CLIENT_notify_transmit_ready (dns_connection, len, 368
362 GNUNET_TIME_UNIT_FOREVER_REL, 369 GNUNET_assert (head != NULL);
363 GNUNET_YES, &send_query, NULL); 370
364 break; 371 if (dns_connection != NULL && dns_transmit_handle == NULL)
365 } 372 dns_transmit_handle =
373 GNUNET_CLIENT_notify_transmit_ready (dns_connection, len,
374 GNUNET_TIME_UNIT_FOREVER_REL,
375 GNUNET_YES, &send_query,
376 NULL);
377 break;
378 }
366 /* fall through */ 379 /* fall through */
367 case IPPROTO_TCP: 380 case IPPROTO_TCP:
368 pkt6_tcp = (struct ip6_tcp *) pkt6; 381 pkt6_tcp = (struct ip6_tcp *) pkt6;
@@ -418,19 +431,20 @@ message_token (void *cls __attribute__ ((unused)), void *client
418 } 431 }
419 else 432 else
420 { 433 {
421 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "pip: %d\n", port_in_ports(me->desc.ports, pkt6_tcp->tcp_hdr.dpt)); 434 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pip: %d\n",
422 GNUNET_assert(0); 435 port_in_ports (me->desc.ports, pkt6_tcp->tcp_hdr.dpt));
436 GNUNET_assert (0);
423 } 437 }
424 if (me->tunnel == NULL && NULL != cls) 438 if (me->tunnel == NULL && NULL != cls)
425 { 439 {
426 *cls = 440 *cls =
427 GNUNET_MESH_tunnel_create(mesh_handle, initialize_tunnel_state(16, NULL), 441 GNUNET_MESH_tunnel_create (mesh_handle,
428 &send_pkt_to_peer, NULL, cls); 442 initialize_tunnel_state (16, NULL),
443 &send_pkt_to_peer, NULL, cls);
429 444
430 GNUNET_MESH_peer_request_connect_add (*cls, 445 GNUNET_MESH_peer_request_connect_add (*cls,
431 (struct 446 (struct GNUNET_PeerIdentity *)
432 GNUNET_PeerIdentity *) 447 &me->desc.peer);
433 &me->desc.peer);
434 me->tunnel = *cls; 448 me->tunnel = *cls;
435 } 449 }
436 else if (NULL != cls) 450 else if (NULL != cls)
@@ -451,7 +465,7 @@ message_token (void *cls __attribute__ ((unused)), void *client
451 memcpy (s->addr, me->addr, me->addrlen); 465 memcpy (s->addr, me->addr, me->addrlen);
452 s->proto = pkt6->ip6_hdr.nxthdr; 466 s->proto = pkt6->ip6_hdr.nxthdr;
453 if (s->proto == IPPROTO_UDP) 467 if (s->proto == IPPROTO_UDP)
454 { 468 {
455 hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_REMOTE_UDP); 469 hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_REMOTE_UDP);
456 memcpy (hc + 1, &pkt6_udp->udp_hdr, ntohs (pkt6_udp->udp_hdr.len)); 470 memcpy (hc + 1, &pkt6_udp->udp_hdr, ntohs (pkt6_udp->udp_hdr.len));
457 app_type = GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY; 471 app_type = GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY;
@@ -473,11 +487,11 @@ message_token (void *cls __attribute__ ((unused)), void *client
473 if (me->tunnel == NULL && NULL != cls) 487 if (me->tunnel == NULL && NULL != cls)
474 { 488 {
475 *cls = 489 *cls =
476 GNUNET_MESH_tunnel_create(mesh_handle, initialize_tunnel_state(16, NULL), 490 GNUNET_MESH_tunnel_create (mesh_handle,
477 &send_pkt_to_peer, NULL, cls); 491 initialize_tunnel_state (16, NULL),
492 &send_pkt_to_peer, NULL, cls);
478 493
479 GNUNET_MESH_peer_request_connect_by_type (*cls, 494 GNUNET_MESH_peer_request_connect_by_type (*cls, app_type);
480 app_type);
481 me->tunnel = *cls; 495 me->tunnel = *cls;
482 if (GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY == app_type) 496 if (GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY == app_type)
483 udp_tunnel = *cls; 497 udp_tunnel = *cls;
@@ -538,11 +552,12 @@ message_token (void *cls __attribute__ ((unused)), void *client
538 size_t len = sizeof (struct query_packet) + ntohs (udp->udp_hdr.len) - 9; 552 size_t len = sizeof (struct query_packet) + ntohs (udp->udp_hdr.len) - 9;
539 553
540 struct query_packet_list *query = 554 struct query_packet_list *query =
541 GNUNET_malloc (len + sizeof(struct answer_packet_list) - sizeof(struct answer_packet)); 555 GNUNET_malloc (len + sizeof (struct answer_packet_list) -
556 sizeof (struct answer_packet));
542 query->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_QUERY_DNS); 557 query->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_QUERY_DNS);
543 query->pkt.hdr.size = htons (len); 558 query->pkt.hdr.size = htons (len);
544 memcpy(query->pkt.orig_to, &pkt->ip_hdr.dadr, 4); 559 memcpy (query->pkt.orig_to, &pkt->ip_hdr.dadr, 4);
545 memcpy(query->pkt.orig_from, &pkt->ip_hdr.sadr, 4); 560 memcpy (query->pkt.orig_from, &pkt->ip_hdr.sadr, 4);
546 query->pkt.addrlen = 4; 561 query->pkt.addrlen = 4;
547 query->pkt.src_port = udp->udp_hdr.spt; 562 query->pkt.src_port = udp->udp_hdr.spt;
548 memcpy (query->pkt.data, udp->data, ntohs (udp->udp_hdr.len) - 8); 563 memcpy (query->pkt.data, udp->data, ntohs (udp->udp_hdr.len) - 8);
@@ -552,9 +567,10 @@ message_token (void *cls __attribute__ ((unused)), void *client
552 GNUNET_assert (head != NULL); 567 GNUNET_assert (head != NULL);
553 568
554 if (dns_connection != NULL && dns_transmit_handle == NULL) 569 if (dns_connection != NULL && dns_transmit_handle == NULL)
555 dns_transmit_handle = GNUNET_CLIENT_notify_transmit_ready (dns_connection, len, 570 dns_transmit_handle =
556 GNUNET_TIME_UNIT_FOREVER_REL, 571 GNUNET_CLIENT_notify_transmit_ready (dns_connection, len,
557 GNUNET_YES, &send_query, NULL); 572 GNUNET_TIME_UNIT_FOREVER_REL,
573 GNUNET_YES, &send_query, NULL);
558 } 574 }
559 else 575 else
560 { 576 {
@@ -625,12 +641,13 @@ message_token (void *cls __attribute__ ((unused)), void *client
625 } 641 }
626 if (me->tunnel == NULL && NULL != cls) 642 if (me->tunnel == NULL && NULL != cls)
627 { 643 {
628 *cls = GNUNET_MESH_tunnel_create(mesh_handle, 644 *cls =
629 initialize_tunnel_state(4, NULL), 645 GNUNET_MESH_tunnel_create (mesh_handle,
630 send_pkt_to_peer, NULL, cls); 646 initialize_tunnel_state (4, NULL),
647 send_pkt_to_peer, NULL, cls);
631 GNUNET_MESH_peer_request_connect_add (*cls, 648 GNUNET_MESH_peer_request_connect_add (*cls,
632 (struct GNUNET_PeerIdentity *) 649 (struct GNUNET_PeerIdentity
633 &me->desc.peer); 650 *) &me->desc.peer);
634 me->tunnel = *cls; 651 me->tunnel = *cls;
635 } 652 }
636 else if (NULL != cls) 653 else if (NULL != cls)
@@ -664,13 +681,15 @@ message_token (void *cls __attribute__ ((unused)), void *client
664 ntohs (pkt->ip_hdr.tot_lngth) - 681 ntohs (pkt->ip_hdr.tot_lngth) -
665 4 * pkt->ip_hdr.hdr_lngth); 682 4 * pkt->ip_hdr.hdr_lngth);
666 app_type = GNUNET_APPLICATION_TYPE_INTERNET_TCP_GATEWAY; 683 app_type = GNUNET_APPLICATION_TYPE_INTERNET_TCP_GATEWAY;
667 } else 684 }
668 GNUNET_assert (0); 685 else
686 GNUNET_assert (0);
669 if (me->tunnel == NULL && NULL != cls) 687 if (me->tunnel == NULL && NULL != cls)
670 { 688 {
671 *cls = 689 *cls =
672 GNUNET_MESH_tunnel_create(mesh_handle, initialize_tunnel_state(4, NULL), 690 GNUNET_MESH_tunnel_create (mesh_handle,
673 send_pkt_to_peer, NULL, cls); 691 initialize_tunnel_state (4, NULL),
692 send_pkt_to_peer, NULL, cls);
674 693
675 GNUNET_MESH_peer_request_connect_by_type (*cls, app_type); 694 GNUNET_MESH_peer_request_connect_by_type (*cls, app_type);
676 me->tunnel = *cls; 695 me->tunnel = *cls;
diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c
index 1191dffe1..cc8001eae 100644
--- a/src/vpn/gnunet-daemon-vpn.c
+++ b/src/vpn/gnunet-daemon-vpn.c
@@ -183,7 +183,7 @@ collect_mappings (void *cls
183 /* FIXME! GNUNET_MESH_close_tunnel(me->tunnel); */ 183 /* FIXME! GNUNET_MESH_close_tunnel(me->tunnel); */
184 184
185 GNUNET_assert (GNUNET_YES == 185 GNUNET_assert (GNUNET_YES ==
186 GNUNET_CONTAINER_multihashmap_remove (hashmap, &me->hash, me)); 186 GNUNET_CONTAINER_multihashmap_remove (hashmap, &me->hash, me));
187 187
188 GNUNET_free (me); 188 GNUNET_free (me);
189} 189}
@@ -282,21 +282,22 @@ send_pkt_to_peer_notify_callback (void *cls, size_t size, void *buf)
282{ 282{
283 struct GNUNET_MESH_Tunnel **tunnel = cls; 283 struct GNUNET_MESH_Tunnel **tunnel = cls;
284 284
285 struct tunnel_state *ts = GNUNET_MESH_tunnel_get_data(*tunnel); 285 struct tunnel_state *ts = GNUNET_MESH_tunnel_get_data (*tunnel);
286
286 ts->th = NULL; 287 ts->th = NULL;
287 288
288 if (NULL != buf) 289 if (NULL != buf)
289 { 290 {
290 struct GNUNET_MessageHeader *hdr = 291 struct GNUNET_MessageHeader *hdr =
291 (struct GNUNET_MessageHeader *) (tunnel + 1); 292 (struct GNUNET_MessageHeader *) (tunnel + 1);
292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
293 "send_pkt_to_peer_notify_callback: buf = %x; size = %u;\n", buf, 294 "send_pkt_to_peer_notify_callback: buf = %x; size = %u;\n", buf,
294 size); 295 size);
295 GNUNET_assert (size >= ntohs (hdr->size)); 296 GNUNET_assert (size >= ntohs (hdr->size));
296 memcpy (buf, hdr, ntohs (hdr->size)); 297 memcpy (buf, hdr, ntohs (hdr->size));
297 size = ntohs (hdr->size); 298 size = ntohs (hdr->size);
298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent!\n"); 299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent!\n");
299 } 300 }
300 else 301 else
301 size = 0; 302 size = 0;
302 303
@@ -307,9 +308,7 @@ send_pkt_to_peer_notify_callback (void *cls, size_t size, void *buf)
307 GNUNET_CONTAINER_DLL_remove (ts->head, ts->tail, element); 308 GNUNET_CONTAINER_DLL_remove (ts->head, ts->tail, element);
308 309
309 ts->th = 310 ts->th =
310 GNUNET_MESH_notify_transmit_ready (*tunnel, 311 GNUNET_MESH_notify_transmit_ready (*tunnel, GNUNET_NO, 42,
311 GNUNET_NO,
312 42,
313 GNUNET_TIME_relative_divide 312 GNUNET_TIME_relative_divide
314 (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), 313 (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2),
315 (const struct GNUNET_PeerIdentity *) 314 (const struct GNUNET_PeerIdentity *)
@@ -330,12 +329,14 @@ port_in_ports (uint64_t ports, uint16_t port)
330{ 329{
331 uint16_t *ps = (uint16_t *) & ports; 330 uint16_t *ps = (uint16_t *) & ports;
332 331
333 return ports == 0 || ps[0] == port || ps[1] == port || ps[2] == port || ps[3] == port; 332 return ports == 0 || ps[0] == port || ps[1] == port || ps[2] == port ||
333 ps[3] == port;
334} 334}
335 335
336void 336void
337send_pkt_to_peer (void *cls, const struct GNUNET_PeerIdentity *peer, 337send_pkt_to_peer (void *cls, const struct GNUNET_PeerIdentity *peer,
338 const struct GNUNET_ATS_Information *atsi __attribute__ ((unused))) 338 const struct GNUNET_ATS_Information *atsi
339 __attribute__ ((unused)))
339{ 340{
340 /* peer == NULL means that all peers in this request are connected */ 341 /* peer == NULL means that all peers in this request are connected */
341 if (peer == NULL) 342 if (peer == NULL)
@@ -347,18 +348,16 @@ send_pkt_to_peer (void *cls, const struct GNUNET_PeerIdentity *peer,
347 GNUNET_assert (NULL != tunnel); 348 GNUNET_assert (NULL != tunnel);
348 GNUNET_assert (NULL != *tunnel); 349 GNUNET_assert (NULL != *tunnel);
349 350
350 struct tunnel_state *ts = GNUNET_MESH_tunnel_get_data(*tunnel); 351 struct tunnel_state *ts = GNUNET_MESH_tunnel_get_data (*tunnel);
352
351 if (NULL == ts->th) 353 if (NULL == ts->th)
352 { 354 {
353 ts->th = 355 ts->th =
354 GNUNET_MESH_notify_transmit_ready (*tunnel, 356 GNUNET_MESH_notify_transmit_ready (*tunnel, GNUNET_NO, 42,
355 GNUNET_NO,
356 42,
357 GNUNET_TIME_relative_divide 357 GNUNET_TIME_relative_divide
358 (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), 358 (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2),
359 (const struct GNUNET_PeerIdentity *) 359 (const struct GNUNET_PeerIdentity *)
360 NULL, 360 NULL, ntohs (hdr->size),
361 ntohs (hdr->size),
362 send_pkt_to_peer_notify_callback, 361 send_pkt_to_peer_notify_callback,
363 cls); 362 cls);
364 } 363 }
@@ -574,7 +573,8 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
574 573
575 list = 574 list =
576 GNUNET_malloc (htons (pkt->hdr.size) + 575 GNUNET_malloc (htons (pkt->hdr.size) +
577 sizeof(struct answer_packet_list) - sizeof(struct answer_packet)); 576 sizeof (struct answer_packet_list) -
577 sizeof (struct answer_packet));
578 578
579 memcpy (&list->pkt, pkt, htons (pkt->hdr.size)); 579 memcpy (&list->pkt, pkt, htons (pkt->hdr.size));
580 580
@@ -622,8 +622,9 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
622 char *name = (char *) (map_entry + 1); 622 char *name = (char *) (map_entry + 1);
623 623
624 list = 624 list =
625 GNUNET_malloc (sizeof(struct answer_packet_list) - sizeof(struct answer_packet) + offset + 2 + 625 GNUNET_malloc (sizeof (struct answer_packet_list) -
626 ntohs (namelen)); 626 sizeof (struct answer_packet) + offset + 2 +
627 ntohs (namelen));
627 628
628 struct answer_packet *rpkt = &list->pkt; 629 struct answer_packet *rpkt = &list->pkt;
629 630
@@ -641,7 +642,8 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
641 { 642 {
642 list = 643 list =
643 GNUNET_malloc (htons (pkt->hdr.size) + 644 GNUNET_malloc (htons (pkt->hdr.size) +
644 sizeof(struct answer_packet_list) - sizeof(struct answer_packet)); 645 sizeof (struct answer_packet_list) -
646 sizeof (struct answer_packet));
645 memcpy (&list->pkt, pkt, htons (pkt->hdr.size)); 647 memcpy (&list->pkt, pkt, htons (pkt->hdr.size));
646 } 648 }
647 else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REMOTE_AAAA) 649 else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REMOTE_AAAA)
@@ -701,7 +703,8 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
701 703
702 list = 704 list =
703 GNUNET_malloc (htons (pkt->hdr.size) + 705 GNUNET_malloc (htons (pkt->hdr.size) +
704 sizeof(struct answer_packet_list) - sizeof(struct answer_packet)); 706 sizeof (struct answer_packet_list) -
707 sizeof (struct answer_packet));
705 708
706 memcpy (&list->pkt, pkt, htons (pkt->hdr.size)); 709 memcpy (&list->pkt, pkt, htons (pkt->hdr.size));
707 } 710 }
@@ -763,7 +766,8 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
763 766
764 list = 767 list =
765 GNUNET_malloc (htons (pkt->hdr.size) + 768 GNUNET_malloc (htons (pkt->hdr.size) +
766 sizeof(struct answer_packet_list) - sizeof(struct answer_packet)); 769 sizeof (struct answer_packet_list) -
770 sizeof (struct answer_packet));
767 771
768 memcpy (&list->pkt, pkt, htons (pkt->hdr.size)); 772 memcpy (&list->pkt, pkt, htons (pkt->hdr.size));
769 } 773 }
@@ -852,12 +856,12 @@ add_additional_port (struct map_entry *me, uint16_t port)
852} 856}
853 857
854static int 858static int
855receive_udp_back (void *cls __attribute__ ((unused)), 859receive_udp_back (void *cls
856 struct GNUNET_MESH_Tunnel *tunnel, 860 __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel,
857 void **tunnel_ctx, 861 void **tunnel_ctx, const struct GNUNET_PeerIdentity *sender,
858 const struct GNUNET_PeerIdentity *sender,
859 const struct GNUNET_MessageHeader *message, 862 const struct GNUNET_MessageHeader *message,
860 const struct GNUNET_ATS_Information *atsi __attribute__ ((unused))) 863 const struct GNUNET_ATS_Information *atsi
864 __attribute__ ((unused)))
861{ 865{
862 GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); 866 GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
863 struct remote_addr *s = (struct remote_addr *) desc; 867 struct remote_addr *s = (struct remote_addr *) desc;
@@ -1029,12 +1033,13 @@ receive_udp_back (void *cls __attribute__ ((unused)),
1029} 1033}
1030 1034
1031static int 1035static int
1032receive_tcp_back (void *cls __attribute__ ((unused)), 1036receive_tcp_back (void *cls
1033 struct GNUNET_MESH_Tunnel *tunnel, 1037 __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel,
1034 void **tunnel_ctx, 1038 void **tunnel_ctx, const struct GNUNET_PeerIdentity *sender
1035 const struct GNUNET_PeerIdentity *sender __attribute__ ((unused)), 1039 __attribute__ ((unused)),
1036 const struct GNUNET_MessageHeader *message, 1040 const struct GNUNET_MessageHeader *message,
1037 const struct GNUNET_ATS_Information *atsi __attribute__ ((unused))) 1041 const struct GNUNET_ATS_Information *atsi
1042 __attribute__ ((unused)))
1038{ 1043{
1039 GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); 1044 GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
1040 struct remote_addr *s = (struct remote_addr *) desc; 1045 struct remote_addr *s = (struct remote_addr *) desc;
@@ -1046,9 +1051,10 @@ receive_tcp_back (void *cls __attribute__ ((unused)),
1046 ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) - 1051 ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) -
1047 sizeof (GNUNET_HashCode); 1052 sizeof (GNUNET_HashCode);
1048 1053
1049 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received TCP-Packet back, addrlen = %d\n", s->addrlen); 1054 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1055 "Received TCP-Packet back, addrlen = %d\n", s->addrlen);
1050 1056
1051 if (ntohs(message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP_BACK || 1057 if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP_BACK ||
1052 ts->addrlen == 16) 1058 ts->addrlen == 16)
1053 { 1059 {
1054 size_t size = pktlen + sizeof (struct ip6_tcp) - 1; 1060 size_t size = pktlen + sizeof (struct ip6_tcp) - 1;
@@ -1195,7 +1201,7 @@ receive_tcp_back (void *cls __attribute__ ((unused)),
1195 tmp = pkt4->ip_hdr.dadr; 1201 tmp = pkt4->ip_hdr.dadr;
1196 sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); 1202 sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
1197 1203
1198 tmp = (0x06 << 16) | (0xffff & pktlen); // 0x06 for TCP? 1204 tmp = (0x06 << 16) | (0xffff & pktlen); // 0x06 for TCP?
1199 1205
1200 tmp = htonl (tmp); 1206 tmp = htonl (tmp);
1201 1207
@@ -1213,22 +1219,21 @@ receive_tcp_back (void *cls __attribute__ ((unused)),
1213 return GNUNET_OK; 1219 return GNUNET_OK;
1214} 1220}
1215 1221
1216static void* new_tunnel(void* cls, 1222static void *
1217 struct GNUNET_MESH_Tunnel *tunnel, 1223new_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel,
1218 const struct GNUNET_PeerIdentity *initiator, 1224 const struct GNUNET_PeerIdentity *initiator,
1219 const struct GNUNET_ATS_Information *atsi) 1225 const struct GNUNET_ATS_Information *atsi)
1220{ 1226{
1221 /* Why should anyone open an inbound tunnel to vpn? */ 1227 /* Why should anyone open an inbound tunnel to vpn? */
1222 GNUNET_break(0); 1228 GNUNET_break (0);
1223 return NULL; 1229 return NULL;
1224} 1230}
1225 1231
1226static void cleaner(void *cls, 1232static void
1227 const struct GNUNET_MESH_Tunnel *tunnel, 1233cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel, void *tunnel_ctx)
1228 void *tunnel_ctx)
1229{ 1234{
1230 /* Why should anyone open an inbound tunnel to vpn? */ 1235 /* Why should anyone open an inbound tunnel to vpn? */
1231 GNUNET_break(0); 1236 GNUNET_break (0);
1232} 1237}
1233 1238
1234/** 1239/**
@@ -1255,7 +1260,9 @@ run (void *cls, char *const *args __attribute__ ((unused)), const char *cfgfilep
1255 GNUNET_APPLICATION_TYPE_END 1260 GNUNET_APPLICATION_TYPE_END
1256 }; 1261 };
1257 1262
1258 mesh_handle = GNUNET_MESH_connect (cfg_, 42, NULL, new_tunnel, cleaner, handlers, types); 1263 mesh_handle =
1264 GNUNET_MESH_connect (cfg_, 42, NULL, new_tunnel, cleaner, handlers,
1265 types);
1259 cfg = cfg_; 1266 cfg = cfg_;
1260 restart_hijack = 0; 1267 restart_hijack = 0;
1261 hashmap = GNUNET_CONTAINER_multihashmap_create (65536); 1268 hashmap = GNUNET_CONTAINER_multihashmap_create (65536);
diff --git a/src/vpn/gnunet-dns-parser.c b/src/vpn/gnunet-dns-parser.c
index e3b03fefd..e87109e0c 100644
--- a/src/vpn/gnunet-dns-parser.c
+++ b/src/vpn/gnunet-dns-parser.c
@@ -136,114 +136,126 @@ parse_dns_packet (struct dns_pkt *pkt)
136} /*}}} */ 136} /*}}} */
137 137
138static void 138static void
139unparse_dns_name(char* dest, char* src, size_t len) 139unparse_dns_name (char *dest, char *src, size_t len)
140{ 140{
141 char *b = dest; 141 char *b = dest;
142 char cnt = 0; 142 char cnt = 0;
143
143 dest++; 144 dest++;
144 while (*src != 0) 145 while (*src != 0)
146 {
147 while (*src != '.' && *src != 0)
145 { 148 {
146 while (*src != '.' && *src != 0) 149 *dest = *src;
147 {
148 *dest = *src;
149 src++;
150 dest++;
151 cnt++;
152 }
153 *b = cnt;
154 cnt = 0;
155 b = dest;
156 dest++;
157 src++; 150 src++;
151 dest++;
152 cnt++;
158 } 153 }
154 *b = cnt;
155 cnt = 0;
156 b = dest;
157 dest++;
158 src++;
159 }
159 *b = 0; 160 *b = 0;
160} 161}
161 162
162struct dns_pkt * 163struct dns_pkt *
163unparse_dns_packet (struct dns_pkt_parsed* ppkt) 164unparse_dns_packet (struct dns_pkt_parsed *ppkt)
164{ 165{
165 size_t size = sizeof(struct dns_pkt) - 1; 166 size_t size = sizeof (struct dns_pkt) - 1;
166 int i; 167 int i;
167 for (i = 0; i < ntohs(ppkt->s.qdcount); i++) 168
169 for (i = 0; i < ntohs (ppkt->s.qdcount); i++)
168 size += ppkt->queries[i]->namelen + 1; 170 size += ppkt->queries[i]->namelen + 1;
169 171
170 for (i = 0; i < ntohs(ppkt->s.ancount); i++) 172 for (i = 0; i < ntohs (ppkt->s.ancount); i++)
171 { 173 {
172 size += ppkt->answers[i]->namelen + 1; 174 size += ppkt->answers[i]->namelen + 1;
173 size += ppkt->answers[i]->data_len; 175 size += ppkt->answers[i]->data_len;
174 } 176 }
175 for (i = 0; i < ntohs(ppkt->s.nscount); i++) 177 for (i = 0; i < ntohs (ppkt->s.nscount); i++)
176 { 178 {
177 size += ppkt->nameservers[i]->namelen + 1; 179 size += ppkt->nameservers[i]->namelen + 1;
178 size += ppkt->nameservers[i]->data_len; 180 size += ppkt->nameservers[i]->data_len;
179 } 181 }
180 for (i = 0; i < ntohs(ppkt->s.arcount); i++) 182 for (i = 0; i < ntohs (ppkt->s.arcount); i++)
181 { 183 {
182 size += ppkt->additional[i]->namelen + 1; 184 size += ppkt->additional[i]->namelen + 1;
183 size += ppkt->additional[i]->data_len; 185 size += ppkt->additional[i]->data_len;
184 } 186 }
187
188 size +=
189 4 * ntohs (ppkt->s.qdcount) + 10 * (ntohs (ppkt->s.ancount) +
190 ntohs (ppkt->s.arcount) +
191 ntohs (ppkt->s.nscount));
185 192
186 size += 4*ntohs(ppkt->s.qdcount) + 10*( 193 struct dns_pkt *pkt = GNUNET_malloc (size);
187 ntohs(ppkt->s.ancount)+ 194 char *pkt_c = (char *) pkt;
188 ntohs(ppkt->s.arcount)+
189 ntohs(ppkt->s.nscount));
190 195
191 struct dns_pkt *pkt = GNUNET_malloc(size); 196 memcpy (&pkt->s, &ppkt->s, sizeof ppkt->s);
192 char *pkt_c = (char*)pkt;
193 memcpy(&pkt->s, &ppkt->s, sizeof ppkt->s);
194 size_t idx = sizeof ppkt->s; 197 size_t idx = sizeof ppkt->s;
195 198
196 for (i = 0; i < ntohs(ppkt->s.qdcount); i++) 199 for (i = 0; i < ntohs (ppkt->s.qdcount); i++)
197 { 200 {
198 unparse_dns_name(&pkt_c[idx], ppkt->queries[i]->name, ppkt->queries[i]->namelen); 201 unparse_dns_name (&pkt_c[idx], ppkt->queries[i]->name,
199 idx += ppkt->queries[i]->namelen; 202 ppkt->queries[i]->namelen);
200 struct dns_query_line *d = (struct dns_query_line*)&pkt_c[idx]; 203 idx += ppkt->queries[i]->namelen;
201 d->class = ppkt->queries[i]->qclass; 204 struct dns_query_line *d = (struct dns_query_line *) &pkt_c[idx];
202 d->type = ppkt->queries[i]->qtype; 205
203 idx += sizeof(struct dns_query_line); 206 d->class = ppkt->queries[i]->qclass;
204 } 207 d->type = ppkt->queries[i]->qtype;
208 idx += sizeof (struct dns_query_line);
209 }
205 210
206 for (i = 0; i < ntohs(ppkt->s.ancount); i++) 211 for (i = 0; i < ntohs (ppkt->s.ancount); i++)
207 { 212 {
208 unparse_dns_name(&pkt_c[idx], ppkt->answers[i]->name, ppkt->answers[i]->namelen); 213 unparse_dns_name (&pkt_c[idx], ppkt->answers[i]->name,
209 idx += ppkt->answers[i]->namelen; 214 ppkt->answers[i]->namelen);
210 struct dns_record_line *r = (struct dns_record_line*)&pkt_c[idx]; 215 idx += ppkt->answers[i]->namelen;
211 r->type = ppkt->answers[i]->type; 216 struct dns_record_line *r = (struct dns_record_line *) &pkt_c[idx];
212 r->class = ppkt->answers[i]->class; 217
213 r->ttl = ppkt->answers[i]->ttl; 218 r->type = ppkt->answers[i]->type;
214 r->data_len = ppkt->answers[i]->data_len; 219 r->class = ppkt->answers[i]->class;
215 idx += sizeof(struct dns_record_line); 220 r->ttl = ppkt->answers[i]->ttl;
216 memcpy(&r->data, ppkt->answers[i]->data, ppkt->answers[i]->data_len); 221 r->data_len = ppkt->answers[i]->data_len;
217 idx += ppkt->answers[i]->data_len; 222 idx += sizeof (struct dns_record_line);
218 } 223 memcpy (&r->data, ppkt->answers[i]->data, ppkt->answers[i]->data_len);
224 idx += ppkt->answers[i]->data_len;
225 }
219 226
220 for (i = 0; i < ntohs(ppkt->s.nscount); i++) 227 for (i = 0; i < ntohs (ppkt->s.nscount); i++)
221 { 228 {
222 unparse_dns_name(&pkt_c[idx], ppkt->nameservers[i]->name, ppkt->nameservers[i]->namelen); 229 unparse_dns_name (&pkt_c[idx], ppkt->nameservers[i]->name,
223 idx += ppkt->nameservers[i]->namelen; 230 ppkt->nameservers[i]->namelen);
224 struct dns_record_line *r = (struct dns_record_line*)&pkt_c[idx]; 231 idx += ppkt->nameservers[i]->namelen;
225 r->type = ppkt->nameservers[i]->type; 232 struct dns_record_line *r = (struct dns_record_line *) &pkt_c[idx];
226 r->class = ppkt->nameservers[i]->class; 233
227 r->ttl = ppkt->nameservers[i]->ttl; 234 r->type = ppkt->nameservers[i]->type;
228 r->data_len = ppkt->nameservers[i]->data_len; 235 r->class = ppkt->nameservers[i]->class;
229 idx += sizeof(struct dns_record_line); 236 r->ttl = ppkt->nameservers[i]->ttl;
230 memcpy(&r->data, ppkt->nameservers[i]->data, ppkt->nameservers[i]->data_len); 237 r->data_len = ppkt->nameservers[i]->data_len;
231 idx += ppkt->nameservers[i]->data_len; 238 idx += sizeof (struct dns_record_line);
232 } 239 memcpy (&r->data, ppkt->nameservers[i]->data,
240 ppkt->nameservers[i]->data_len);
241 idx += ppkt->nameservers[i]->data_len;
242 }
233 243
234 for (i = 0; i < ntohs(ppkt->s.arcount); i++) 244 for (i = 0; i < ntohs (ppkt->s.arcount); i++)
235 { 245 {
236 unparse_dns_name(&pkt_c[idx], ppkt->additional[i]->name, ppkt->additional[i]->namelen); 246 unparse_dns_name (&pkt_c[idx], ppkt->additional[i]->name,
237 idx += ppkt->additional[i]->namelen; 247 ppkt->additional[i]->namelen);
238 struct dns_record_line *r = (struct dns_record_line*)&pkt_c[idx]; 248 idx += ppkt->additional[i]->namelen;
239 r->type = ppkt->additional[i]->type; 249 struct dns_record_line *r = (struct dns_record_line *) &pkt_c[idx];
240 r->class = ppkt->additional[i]->class; 250
241 r->ttl = ppkt->additional[i]->ttl; 251 r->type = ppkt->additional[i]->type;
242 r->data_len = ppkt->additional[i]->data_len; 252 r->class = ppkt->additional[i]->class;
243 idx += sizeof(struct dns_record_line); 253 r->ttl = ppkt->additional[i]->ttl;
244 memcpy(&r->data, ppkt->additional[i]->data, ppkt->additional[i]->data_len); 254 r->data_len = ppkt->additional[i]->data_len;
245 idx += ppkt->additional[i]->data_len; 255 idx += sizeof (struct dns_record_line);
246 } 256 memcpy (&r->data, ppkt->additional[i]->data, ppkt->additional[i]->data_len);
257 idx += ppkt->additional[i]->data_len;
258 }
247 259
248 return pkt; 260 return pkt;
249} 261}
diff --git a/src/vpn/gnunet-service-dns-p.h b/src/vpn/gnunet-service-dns-p.h
index 13b410e2f..0519b1f84 100644
--- a/src/vpn/gnunet-service-dns-p.h
+++ b/src/vpn/gnunet-service-dns-p.h
@@ -102,7 +102,8 @@ struct answer_packet
102 unsigned char data[1]; 102 unsigned char data[1];
103}; 103};
104 104
105struct answer_packet_list { 105struct answer_packet_list
106{
106 struct answer_packet_list *next GNUNET_PACKED; 107 struct answer_packet_list *next GNUNET_PACKED;
107 struct answer_packet_list *prev GNUNET_PACKED; 108 struct answer_packet_list *prev GNUNET_PACKED;
108 struct GNUNET_SERVER_Client *client; 109 struct GNUNET_SERVER_Client *client;
diff --git a/src/vpn/gnunet-service-dns.c b/src/vpn/gnunet-service-dns.c
index 489235ed4..c8d790b56 100644
--- a/src/vpn/gnunet-service-dns.c
+++ b/src/vpn/gnunet-service-dns.c
@@ -99,7 +99,7 @@ static struct
99 char *name; 99 char *name;
100 uint8_t namelen; 100 uint8_t namelen;
101 uint16_t qtype; 101 uint16_t qtype;
102} query_states[UINT16_MAX+1]; 102} query_states[UINT16_MAX + 1];
103 103
104/** 104/**
105 * A struct used to give more than one value as 105 * A struct used to give more than one value as
@@ -122,39 +122,45 @@ struct tunnel_notify_queue
122 122
123struct tunnel_state 123struct tunnel_state
124{ 124{
125 struct tunnel_notify_queue *head,*tail; 125 struct tunnel_notify_queue *head, *tail;
126 struct GNUNET_MESH_TransmitHandle *th; 126 struct GNUNET_MESH_TransmitHandle *th;
127}; 127};
128 128
129static size_t send_answer (void *cls, size_t size, void *buf); 129static size_t
130send_answer (void *cls, size_t size, void *buf);
130 131
131static void 132static void
132client_disconnect(void* cls, struct GNUNET_SERVER_Client *client) 133client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
133{ 134{
134 if (NULL == head) return; 135 if (NULL == head)
136 return;
135 137
136 if (head->client == client) 138 if (head->client == client)
137 { 139 {
138 GNUNET_CONNECTION_notify_transmit_ready_cancel(server_notify); 140 GNUNET_CONNECTION_notify_transmit_ready_cancel (server_notify);
139 server_notify = GNUNET_SERVER_notify_transmit_ready (head->next->client, ntohs (head->next->pkt.hdr.size), 141 server_notify =
140 GNUNET_TIME_UNIT_FOREVER_REL, 142 GNUNET_SERVER_notify_transmit_ready (head->next->client,
141 &send_answer, NULL); 143 ntohs (head->next->pkt.hdr.size),
142 } 144 GNUNET_TIME_UNIT_FOREVER_REL,
145 &send_answer, NULL);
146 }
143 147
144 struct answer_packet_list *element = head; 148 struct answer_packet_list *element = head;
149
145 while (element != NULL) 150 while (element != NULL)
151 {
152 if (element->client == client)
146 { 153 {
147 if (element->client == client) 154 GNUNET_SERVER_client_drop (client);
148 { 155 GNUNET_CONTAINER_DLL_remove (head, tail, element);
149 GNUNET_SERVER_client_drop(client); 156 struct answer_packet_list *t = element;
150 GNUNET_CONTAINER_DLL_remove(head, tail, element); 157
151 struct answer_packet_list* t = element; 158 element = element->next;
152 element = element->next; 159 GNUNET_free (t);
153 GNUNET_free(t);
154 }
155 else
156 element = element->next;
157 } 160 }
161 else
162 element = element->next;
163 }
158} 164}
159 165
160/** 166/**
@@ -201,24 +207,26 @@ hijack (void *cls
201} 207}
202 208
203static void * 209static void *
204new_tunnel (void *cls __attribute__((unused)), 210new_tunnel (void *cls
205 struct GNUNET_MESH_Tunnel *tunnel, 211 __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel,
206 const struct GNUNET_PeerIdentity *initiator __attribute__((unused)), 212 const struct GNUNET_PeerIdentity *initiator
207 const struct GNUNET_ATS_Information *ats __attribute__((unused))) 213 __attribute__ ((unused)), const struct GNUNET_ATS_Information *ats
214 __attribute__ ((unused)))
208{ 215{
209 struct tunnel_state *s = GNUNET_malloc(sizeof *s); 216 struct tunnel_state *s = GNUNET_malloc (sizeof *s);
210 s->head = NULL; 217
211 s->tail = NULL; 218 s->head = NULL;
212 s->th = NULL; 219 s->tail = NULL;
213 return s; 220 s->th = NULL;
221 return s;
214} 222}
215 223
216static void 224static void
217clean_tunnel (void *cls __attribute__((unused)), 225clean_tunnel (void *cls
218 const struct GNUNET_MESH_Tunnel *tunnel, 226 __attribute__ ((unused)), const struct GNUNET_MESH_Tunnel *tunnel,
219 void *tunnel_ctx) 227 void *tunnel_ctx)
220{ 228{
221 GNUNET_free(tunnel_ctx); 229 GNUNET_free (tunnel_ctx);
222} 230}
223 231
224/** 232/**
@@ -246,10 +254,10 @@ unhijack (unsigned short port)
246 GNUNET_OS_start_process (NULL, NULL, "gnunet-helper-hijack-dns", 254 GNUNET_OS_start_process (NULL, NULL, "gnunet-helper-hijack-dns",
247 "gnunet-hijack-dns", "-d", port_s, virt_dns, 255 "gnunet-hijack-dns", "-d", port_s, virt_dns,
248 NULL))) 256 NULL)))
249 { 257 {
250 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (proc)); 258 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (proc));
251 GNUNET_OS_process_close (proc); 259 GNUNET_OS_process_close (proc);
252 } 260 }
253 GNUNET_free (virt_dns); 261 GNUNET_free (virt_dns);
254} 262}
255 263
@@ -272,11 +280,13 @@ send_answer (void *cls, size_t size, void *buf)
272 280
273 /* When more data is to be sent, reschedule */ 281 /* When more data is to be sent, reschedule */
274 if (head != NULL) 282 if (head != NULL)
275 server_notify = GNUNET_SERVER_notify_transmit_ready (head->client, ntohs (head->pkt.hdr.size), 283 server_notify =
276 GNUNET_TIME_UNIT_FOREVER_REL, 284 GNUNET_SERVER_notify_transmit_ready (head->client,
277 &send_answer, NULL); 285 ntohs (head->pkt.hdr.size),
286 GNUNET_TIME_UNIT_FOREVER_REL,
287 &send_answer, NULL);
278 288
279 GNUNET_SERVER_client_drop(query->client); 289 GNUNET_SERVER_client_drop (query->client);
280 GNUNET_free (query); 290 GNUNET_free (query);
281 return len; 291 return len;
282} 292}
@@ -311,7 +321,8 @@ mesh_send_response (void *cls, size_t size, void *buf)
311 GNUNET_assert (size >= (*sz + sizeof (struct GNUNET_MessageHeader))); 321 GNUNET_assert (size >= (*sz + sizeof (struct GNUNET_MessageHeader)));
312 322
313 memcpy (hdr + 1, dns, *sz); 323 memcpy (hdr + 1, dns, *sz);
314 struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(*tunnel); 324 struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (*tunnel);
325
315 if (NULL != s->head) 326 if (NULL != s->head)
316 { 327 {
317 struct tunnel_notify_queue *element = s->head; 328 struct tunnel_notify_queue *element = s->head;
@@ -321,14 +332,12 @@ mesh_send_response (void *cls, size_t size, void *buf)
321 GNUNET_CONTAINER_DLL_remove (head, tail, element); 332 GNUNET_CONTAINER_DLL_remove (head, tail, element);
322 333
323 s->th = 334 s->th =
324 GNUNET_MESH_notify_transmit_ready (*tunnel, 335 GNUNET_MESH_notify_transmit_ready (*tunnel, GNUNET_NO, 42,
325 GNUNET_NO,
326 42,
327 GNUNET_TIME_relative_divide 336 GNUNET_TIME_relative_divide
328 (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), 337 (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2),
329 (const struct GNUNET_PeerIdentity *) 338 (const struct GNUNET_PeerIdentity *)
330 NULL, element->len, 339 NULL, element->len, element->cb,
331 element->cb, element->cls); 340 element->cls);
332 } 341 }
333 342
334 GNUNET_free (cls); 343 GNUNET_free (cls);
@@ -350,27 +359,23 @@ mesh_send (void *cls, size_t size, void *buf)
350 359
351 memcpy (buf, &cls_->hdr, size); 360 memcpy (buf, &cls_->hdr, size);
352 361
353 struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(cls_->tunnel); 362 struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (cls_->tunnel);
363
354 if (NULL != s->head) 364 if (NULL != s->head)
355 { 365 {
356 struct tunnel_notify_queue *element = 366 struct tunnel_notify_queue *element = s->head;
357 s->head; 367 struct tunnel_notify_queue *head = s->head;
358 struct tunnel_notify_queue *head = 368 struct tunnel_notify_queue *tail = s->tail;;
359 s->head;
360 struct tunnel_notify_queue *tail =
361 s->tail;;
362 369
363 GNUNET_CONTAINER_DLL_remove (head, tail, element); 370 GNUNET_CONTAINER_DLL_remove (head, tail, element);
364 371
365 s->th = 372 s->th =
366 GNUNET_MESH_notify_transmit_ready (cls_->tunnel, 373 GNUNET_MESH_notify_transmit_ready (cls_->tunnel, GNUNET_NO, 42,
367 GNUNET_NO,
368 42,
369 GNUNET_TIME_relative_divide 374 GNUNET_TIME_relative_divide
370 (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), 375 (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2),
371 (const struct GNUNET_PeerIdentity *) 376 (const struct GNUNET_PeerIdentity *)
372 NULL, element->len, 377 NULL, element->len, element->cb,
373 element->cb, element->cls); 378 element->cls);
374 379
375 GNUNET_free (element); 380 GNUNET_free (element);
376 } 381 }
@@ -392,26 +397,20 @@ mesh_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
392 "Connected to peer %s, %x, sending query with id %d\n", 397 "Connected to peer %s, %x, sending query with id %d\n",
393 GNUNET_i2s (peer), peer, ntohs (cls_->dns.s.id)); 398 GNUNET_i2s (peer), peer, ntohs (cls_->dns.s.id));
394 399
395 struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(cls_->tunnel); 400 struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (cls_->tunnel);
401
396 if (NULL == s->head) 402 if (NULL == s->head)
397 { 403 {
398 s->th = 404 s->th =
399 GNUNET_MESH_notify_transmit_ready (cls_->tunnel, 405 GNUNET_MESH_notify_transmit_ready (cls_->tunnel, GNUNET_YES, 42,
400 GNUNET_YES, 406 GNUNET_TIME_UNIT_MINUTES, NULL,
401 42, 407 cls_->hdr.size, mesh_send, cls);
402 GNUNET_TIME_UNIT_MINUTES,
403 NULL,
404 cls_->hdr.size,
405 mesh_send,
406 cls);
407 408
408 } 409 }
409 else 410 else
410 { 411 {
411 struct tunnel_notify_queue *head = 412 struct tunnel_notify_queue *head = s->head;
412 s->head; 413 struct tunnel_notify_queue *tail = s->tail;
413 struct tunnel_notify_queue *tail =
414 s->tail;
415 414
416 struct tunnel_notify_queue *element = 415 struct tunnel_notify_queue *element =
417 GNUNET_malloc (sizeof (struct tunnel_notify_queue)); 416 GNUNET_malloc (sizeof (struct tunnel_notify_queue));
@@ -432,13 +431,14 @@ send_mesh_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
432 431
433 struct tunnel_cls *cls_ = (struct tunnel_cls *) cls; 432 struct tunnel_cls *cls_ = (struct tunnel_cls *) cls;
434 433
435 struct tunnel_state *s = GNUNET_malloc(sizeof *s); 434 struct tunnel_state *s = GNUNET_malloc (sizeof *s);
435
436 s->head = NULL; 436 s->head = NULL;
437 s->tail = NULL; 437 s->tail = NULL;
438 s->th = NULL; 438 s->th = NULL;
439 439
440 cls_->tunnel = 440 cls_->tunnel =
441 GNUNET_MESH_tunnel_create(mesh_handle, s, mesh_connect, NULL, cls_); 441 GNUNET_MESH_tunnel_create (mesh_handle, s, mesh_connect, NULL, cls_);
442 442
443 GNUNET_MESH_peer_request_connect_by_type (cls_->tunnel, 443 GNUNET_MESH_peer_request_connect_by_type (cls_->tunnel,
444 GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER); 444 GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER);
@@ -461,12 +461,15 @@ receive_mesh_query (void *cls
461 461
462 struct sockaddr_in dest; 462 struct sockaddr_in dest;
463 463
464 struct dns_pkt_parsed *pdns = parse_dns_packet(dns); 464 struct dns_pkt_parsed *pdns = parse_dns_packet (dns);
465 465
466 memset (&dest, 0, sizeof dest); 466 memset (&dest, 0, sizeof dest);
467 dest.sin_port = htons (53); 467 dest.sin_port = htons (53);
468 char *dns_resolver; 468 char *dns_resolver;
469 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, "dns", "EXTERNAL_DNS", &dns_resolver) || 469
470 if (GNUNET_OK !=
471 GNUNET_CONFIGURATION_get_value_string (cfg, "dns", "EXTERNAL_DNS",
472 &dns_resolver) ||
470 1 != inet_pton (AF_INET, dns_resolver, &dest.sin_addr)) 473 1 != inet_pton (AF_INET, dns_resolver, &dest.sin_addr))
471 inet_pton (AF_INET, "8.8.8.8", &dest.sin_addr); 474 inet_pton (AF_INET, "8.8.8.8", &dest.sin_addr);
472 475
@@ -476,16 +479,17 @@ receive_mesh_query (void *cls
476 query_states[dns->s.id].valid = GNUNET_YES; 479 query_states[dns->s.id].valid = GNUNET_YES;
477 480
478 int i; 481 int i;
479 for (i= 0; i < ntohs(pdns->s.qdcount); i++) 482
483 for (i = 0; i < ntohs (pdns->s.qdcount); i++)
484 {
485 if (pdns->queries[i]->qtype == htons (28) ||
486 pdns->queries[i]->qtype == htons (1))
480 { 487 {
481 if (pdns->queries[i]->qtype == htons(28) || 488 query_states[dns->s.id].qtype = pdns->queries[i]->qtype;
482 pdns->queries[i]->qtype == htons(1)) 489 break;
483 {
484 query_states[dns->s.id].qtype = pdns->queries[i]->qtype;
485 break;
486 }
487 } 490 }
488 free_parsed_dns_packet(pdns); 491 }
492 free_parsed_dns_packet (pdns);
489 493
490 GNUNET_NETWORK_socket_sendto (dnsout, dns, 494 GNUNET_NETWORK_socket_sendto (dnsout, dns,
491 ntohs (message->size) - 495 ntohs (message->size) -
@@ -528,7 +532,8 @@ receive_mesh_answer (void *cls
528 + sizeof (struct dns_record_line) - 1 + 16; /* To hold the IPv6-Address */ 532 + sizeof (struct dns_record_line) - 1 + 16; /* To hold the IPv6-Address */
529 533
530 struct answer_packet_list *answer = 534 struct answer_packet_list *answer =
531 GNUNET_malloc (len + sizeof(struct answer_packet_list) - sizeof(struct answer_packet)); 535 GNUNET_malloc (len + sizeof (struct answer_packet_list) -
536 sizeof (struct answer_packet));
532 537
533 answer->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS); 538 answer->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS);
534 answer->pkt.hdr.size = htons (len); 539 answer->pkt.hdr.size = htons (len);
@@ -546,17 +551,18 @@ receive_mesh_answer (void *cls
546 551
547 int i = 0; 552 int i = 0;
548 553
549 while (i < ntohs(pdns->s.ancount) && 554 while (i < ntohs (pdns->s.ancount) && ntohs (pdns->answers[i]->type) != 28 &&
550 ntohs(pdns->answers[i]->type) != 28 && 555 ntohs (pdns->answers[i]->type) != 1)
551 ntohs(pdns->answers[i]->type) != 1) 556 {
552{ 557 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Answer contains %d.\n",
553 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Answer contains %d.\n", ntohs(pdns->answers[i]->type)); 558 ntohs (pdns->answers[i]->type));
554 i++; 559 i++;
555} 560 }
556 561
557 if (i >= ntohs (pdns->s.ancount)) 562 if (i >= ntohs (pdns->s.ancount))
558 { 563 {
559 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Answer does not contain any usable answers.\n"); 564 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
565 "Answer does not contain any usable answers.\n");
560 free_parsed_dns_packet (pdns); 566 free_parsed_dns_packet (pdns);
561 GNUNET_free (answer); 567 GNUNET_free (answer);
562 return GNUNET_OK; 568 return GNUNET_OK;
@@ -568,8 +574,10 @@ receive_mesh_answer (void *cls
568 memcpy (answer->pkt.addr, pdns->answers[i]->data, 574 memcpy (answer->pkt.addr, pdns->answers[i]->data,
569 ntohs (pdns->answers[i]->data_len)); 575 ntohs (pdns->answers[i]->data_len));
570 576
571 memcpy(answer->pkt.from, query_states[dns->s.id].remote_ip, query_states[dns->s.id].addrlen); 577 memcpy (answer->pkt.from, query_states[dns->s.id].remote_ip,
572 memcpy(answer->pkt.to, query_states[dns->s.id].local_ip, query_states[dns->s.id].addrlen); 578 query_states[dns->s.id].addrlen);
579 memcpy (answer->pkt.to, query_states[dns->s.id].local_ip,
580 query_states[dns->s.id].addrlen);
573 answer->pkt.addrlen = query_states[dns->s.id].addrlen; 581 answer->pkt.addrlen = query_states[dns->s.id].addrlen;
574 answer->pkt.dst_port = query_states[dns->s.id].local_port; 582 answer->pkt.dst_port = query_states[dns->s.id].local_port;
575 583
@@ -595,14 +603,14 @@ receive_mesh_answer (void *cls
595 (struct dns_record_line *) (dpkt->data + 603 (struct dns_record_line *) (dpkt->data +
596 (query_states[dns->s.id].namelen) + 604 (query_states[dns->s.id].namelen) +
597 sizeof (struct dns_query_line) + 2); 605 sizeof (struct dns_query_line) + 2);
598 if (htons(28) == query_states[dns->s.id].qtype) 606 if (htons (28) == query_states[dns->s.id].qtype)
599 { 607 {
600 answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REMOTE_AAAA; 608 answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REMOTE_AAAA;
601 dque->type = htons (28); /* AAAA */ 609 dque->type = htons (28); /* AAAA */
602 drec_data->type = htons (28); /* AAAA */ 610 drec_data->type = htons (28); /* AAAA */
603 drec_data->data_len = htons (16); 611 drec_data->data_len = htons (16);
604 } 612 }
605 else if (htons(1) == query_states[dns->s.id].qtype) 613 else if (htons (1) == query_states[dns->s.id].qtype)
606 { 614 {
607 answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REMOTE_A; 615 answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REMOTE_A;
608 dque->type = htons (1); /* A */ 616 dque->type = htons (1); /* A */
@@ -610,10 +618,11 @@ receive_mesh_answer (void *cls
610 drec_data->data_len = htons (4); 618 drec_data->data_len = htons (4);
611 } 619 }
612 else 620 else
613 { 621 {
614 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "dns-answer with pending qtype = %d\n", query_states[dns->s.id].qtype); 622 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "dns-answer with pending qtype = %d\n",
615 GNUNET_assert(0); 623 query_states[dns->s.id].qtype);
616 } 624 GNUNET_assert (0);
625 }
617 dque->class = htons (1); /* IN */ 626 dque->class = htons (1); /* IN */
618 627
619 char *anname = 628 char *anname =
@@ -634,10 +643,10 @@ receive_mesh_answer (void *cls
634 answer->client = query_states[dns->s.id].client; 643 answer->client = query_states[dns->s.id].client;
635 644
636 if (server_notify == NULL) 645 if (server_notify == NULL)
637 server_notify = GNUNET_SERVER_notify_transmit_ready (query_states[dns->s.id].client, len, 646 server_notify =
638 GNUNET_TIME_UNIT_FOREVER_REL, 647 GNUNET_SERVER_notify_transmit_ready (query_states[dns->s.id].client,
639 &send_answer, 648 len, GNUNET_TIME_UNIT_FOREVER_REL,
640 NULL); 649 &send_answer, NULL);
641 650
642 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 651 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
643 "Sent answer of length %d on to client, addroffset = %d\n", len, 652 "Sent answer of length %d on to client, addroffset = %d\n", len,
@@ -672,14 +681,16 @@ send_rev_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
672 2 /* We do not know the lenght of the answer yet */ ; 681 2 /* We do not know the lenght of the answer yet */ ;
673 682
674 struct answer_packet_list *answer = 683 struct answer_packet_list *answer =
675 GNUNET_malloc (len + sizeof(struct answer_packet_list) - sizeof(struct answer_packet)); 684 GNUNET_malloc (len + sizeof (struct answer_packet_list) -
685 sizeof (struct answer_packet));
676 686
677 answer->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS); 687 answer->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS);
678 answer->pkt.hdr.size = htons (len); 688 answer->pkt.hdr.size = htons (len);
679 answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REV; 689 answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REV;
680 690
681 memcpy(answer->pkt.from, query_states[id].remote_ip, query_states[id].addrlen); 691 memcpy (answer->pkt.from, query_states[id].remote_ip,
682 memcpy(answer->pkt.to, query_states[id].local_ip, query_states[id].addrlen); 692 query_states[id].addrlen);
693 memcpy (answer->pkt.to, query_states[id].local_ip, query_states[id].addrlen);
683 694
684 answer->pkt.dst_port = query_states[id].local_port; 695 answer->pkt.dst_port = query_states[id].local_port;
685 696
@@ -728,9 +739,10 @@ send_rev_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
728 answer->client = query_states[id].client; 739 answer->client = query_states[id].client;
729 740
730 if (server_notify == NULL) 741 if (server_notify == NULL)
731 server_notify = GNUNET_SERVER_notify_transmit_ready (query_states[id].client, len, 742 server_notify =
732 GNUNET_TIME_UNIT_FOREVER_REL, 743 GNUNET_SERVER_notify_transmit_ready (query_states[id].client, len,
733 &send_answer, NULL); 744 GNUNET_TIME_UNIT_FOREVER_REL,
745 &send_answer, NULL);
734} 746}
735 747
736/** 748/**
@@ -740,11 +752,12 @@ static void
740receive_dht (void *cls, struct GNUNET_TIME_Absolute exp 752receive_dht (void *cls, struct GNUNET_TIME_Absolute exp
741 __attribute__ ((unused)), const GNUNET_HashCode * key 753 __attribute__ ((unused)), const GNUNET_HashCode * key
742 __attribute__ ((unused)), 754 __attribute__ ((unused)),
743 const struct GNUNET_PeerIdentity *get_path __attribute__ ((unused)), 755 const struct GNUNET_PeerIdentity *get_path
744 unsigned int get_path_length __attribute__ ((unused)), 756 __attribute__ ((unused)), unsigned int get_path_length
745 const struct GNUNET_PeerIdentity *put_path __attribute__ ((unused)), 757 __attribute__ ((unused)),
746 unsigned int put_path_length __attribute__ ((unused)), 758 const struct GNUNET_PeerIdentity *put_path
747 enum GNUNET_BLOCK_Type type, size_t size, 759 __attribute__ ((unused)), unsigned int put_path_length
760 __attribute__ ((unused)), enum GNUNET_BLOCK_Type type, size_t size,
748 const void *data) 761 const void *data)
749{ 762{
750 763
@@ -773,8 +786,8 @@ receive_dht (void *cls, struct GNUNET_TIME_Absolute exp
773 + sizeof (struct dns_record_line) - 1 + 16; /* To hold the IPv6-Address */ 786 + sizeof (struct dns_record_line) - 1 + 16; /* To hold the IPv6-Address */
774 787
775 struct answer_packet_list *answer = 788 struct answer_packet_list *answer =
776 GNUNET_malloc (len + 789 GNUNET_malloc (len + sizeof (struct answer_packet_list) -
777 sizeof(struct answer_packet_list) - sizeof(struct answer_packet)); 790 sizeof (struct answer_packet));
778 791
779 answer->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS); 792 answer->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS);
780 answer->pkt.hdr.size = htons (len); 793 answer->pkt.hdr.size = htons (len);
@@ -792,8 +805,9 @@ receive_dht (void *cls, struct GNUNET_TIME_Absolute exp
792 memcpy (&answer->pkt.service_descr.ports, &rec->ports, 805 memcpy (&answer->pkt.service_descr.ports, &rec->ports,
793 sizeof (answer->pkt.service_descr.ports)); 806 sizeof (answer->pkt.service_descr.ports));
794 807
795 memcpy(answer->pkt.from, query_states[id].remote_ip, query_states[id].addrlen); 808 memcpy (answer->pkt.from, query_states[id].remote_ip,
796 memcpy(answer->pkt.to, query_states[id].local_ip, query_states[id].addrlen); 809 query_states[id].addrlen);
810 memcpy (answer->pkt.to, query_states[id].local_ip, query_states[id].addrlen);
797 answer->pkt.addrlen = query_states[id].addrlen; 811 answer->pkt.addrlen = query_states[id].addrlen;
798 812
799 answer->pkt.dst_port = query_states[id].local_port; 813 answer->pkt.dst_port = query_states[id].local_port;
@@ -844,9 +858,10 @@ receive_dht (void *cls, struct GNUNET_TIME_Absolute exp
844 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer); 858 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer);
845 859
846 if (server_notify == NULL) 860 if (server_notify == NULL)
847 server_notify = GNUNET_SERVER_notify_transmit_ready (answer->client, len, 861 server_notify =
848 GNUNET_TIME_UNIT_FOREVER_REL, 862 GNUNET_SERVER_notify_transmit_ready (answer->client, len,
849 &send_answer, NULL); 863 GNUNET_TIME_UNIT_FOREVER_REL,
864 &send_answer, NULL);
850} 865}
851 866
852/** 867/**
@@ -877,11 +892,11 @@ receive_query (void *cls
877 892
878 query_states[dns->s.id].valid = GNUNET_YES; 893 query_states[dns->s.id].valid = GNUNET_YES;
879 query_states[dns->s.id].client = client; 894 query_states[dns->s.id].client = client;
880 GNUNET_SERVER_client_keep(client); 895 GNUNET_SERVER_client_keep (client);
881 memcpy(query_states[dns->s.id].local_ip, pkt->orig_from, pkt->addrlen); 896 memcpy (query_states[dns->s.id].local_ip, pkt->orig_from, pkt->addrlen);
882 query_states[dns->s.id].addrlen = pkt->addrlen; 897 query_states[dns->s.id].addrlen = pkt->addrlen;
883 query_states[dns->s.id].local_port = pkt->src_port; 898 query_states[dns->s.id].local_port = pkt->src_port;
884 memcpy(query_states[dns->s.id].remote_ip, pkt->orig_to, pkt->addrlen); 899 memcpy (query_states[dns->s.id].remote_ip, pkt->orig_to, pkt->addrlen);
885 query_states[dns->s.id].namelen = strlen ((char *) dns->data) + 1; 900 query_states[dns->s.id].namelen = strlen ((char *) dns->data) + 1;
886 if (query_states[dns->s.id].name != NULL) 901 if (query_states[dns->s.id].name != NULL)
887 GNUNET_free (query_states[dns->s.id].name); 902 GNUNET_free (query_states[dns->s.id].name);
@@ -891,15 +906,16 @@ receive_query (void *cls
891 query_states[dns->s.id].namelen); 906 query_states[dns->s.id].namelen);
892 907
893 int i; 908 int i;
894 for (i= 0; i < ntohs(pdns->s.qdcount); i++) 909
910 for (i = 0; i < ntohs (pdns->s.qdcount); i++)
911 {
912 if (pdns->queries[i]->qtype == htons (28) ||
913 pdns->queries[i]->qtype == htons (1))
895 { 914 {
896 if (pdns->queries[i]->qtype == htons(28) || 915 query_states[dns->s.id].qtype = pdns->queries[i]->qtype;
897 pdns->queries[i]->qtype == htons(1)) 916 break;
898 {
899 query_states[dns->s.id].qtype = pdns->queries[i]->qtype;
900 break;
901 }
902 } 917 }
918 }
903 919
904 /* The query is for a .gnunet-address */ 920 /* The query is for a .gnunet-address */
905 if (pdns->queries[0]->namelen > 9 && 921 if (pdns->queries[0]->namelen > 9 &&
@@ -922,8 +938,8 @@ receive_query (void *cls
922 cls->handle = 938 cls->handle =
923 GNUNET_DHT_get_start (dht, GNUNET_TIME_UNIT_MINUTES, 939 GNUNET_DHT_get_start (dht, GNUNET_TIME_UNIT_MINUTES,
924 GNUNET_BLOCK_TYPE_DNS, &key, 940 GNUNET_BLOCK_TYPE_DNS, &key,
925 5 /* DEFAULT_GET_REPLICATION */, GNUNET_DHT_RO_NONE, NULL, 941 5 /* DEFAULT_GET_REPLICATION */ ,
926 0, &receive_dht, cls); 942 GNUNET_DHT_RO_NONE, NULL, 0, &receive_dht, cls);
927 943
928 goto outfree; 944 goto outfree;
929 } 945 }
@@ -992,53 +1008,55 @@ receive_query (void *cls
992 unsigned char virt_dns_bytes[16]; 1008 unsigned char virt_dns_bytes[16];
993 1009
994 if (pkt->addrlen == 4) 1010 if (pkt->addrlen == 4)
995 { 1011 {
996 char *virt_dns; 1012 char *virt_dns;
997
998 if (GNUNET_SYSERR ==
999 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS", &virt_dns))
1000 {
1001 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1002 "No entry 'VIRTDNS' in configuration!\n");
1003 exit (1);
1004 }
1005
1006 if (1 != inet_pton (AF_INET, virt_dns, &virt_dns_bytes))
1007 {
1008 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing 'VIRTDNS': %s; %m!\n",
1009 virt_dns);
1010 exit (1);
1011 }
1012 1013
1013 GNUNET_free (virt_dns); 1014 if (GNUNET_SYSERR ==
1014 } 1015 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS",
1015 else if (pkt->addrlen == 16) 1016 &virt_dns))
1016 { 1017 {
1017 char *virt_dns; 1018 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1019 "No entry 'VIRTDNS' in configuration!\n");
1020 exit (1);
1021 }
1018 1022
1019 if (GNUNET_SYSERR == 1023 if (1 != inet_pton (AF_INET, virt_dns, &virt_dns_bytes))
1020 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS6", &virt_dns)) 1024 {
1021 { 1025 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing 'VIRTDNS': %s; %m!\n",
1022 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1026 virt_dns);
1023 "No entry 'VIRTDNS6' in configuration!\n"); 1027 exit (1);
1024 exit (1); 1028 }
1025 }
1026 1029
1027 if (1 != inet_pton (AF_INET6, virt_dns, &virt_dns_bytes)) 1030 GNUNET_free (virt_dns);
1028 { 1031 }
1029 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing 'VIRTDNS6': %s; %m!\n", 1032 else if (pkt->addrlen == 16)
1030 virt_dns); 1033 {
1031 exit (1); 1034 char *virt_dns;
1032 }
1033 1035
1034 GNUNET_free (virt_dns); 1036 if (GNUNET_SYSERR ==
1037 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS6",
1038 &virt_dns))
1039 {
1040 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1041 "No entry 'VIRTDNS6' in configuration!\n");
1042 exit (1);
1035 } 1043 }
1036 else 1044
1045 if (1 != inet_pton (AF_INET6, virt_dns, &virt_dns_bytes))
1037 { 1046 {
1038 GNUNET_assert(0); 1047 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1048 "Error parsing 'VIRTDNS6': %s; %m!\n", virt_dns);
1049 exit (1);
1039 } 1050 }
1040 1051
1041 if (memcmp(virt_dns_bytes,pkt->orig_to, pkt->addrlen) == 0) 1052 GNUNET_free (virt_dns);
1053 }
1054 else
1055 {
1056 GNUNET_assert (0);
1057 }
1058
1059 if (memcmp (virt_dns_bytes, pkt->orig_to, pkt->addrlen) == 0)
1042 { 1060 {
1043 /* This is a packet that was sent directly to the virtual dns-server 1061 /* This is a packet that was sent directly to the virtual dns-server
1044 * 1062 *
@@ -1061,36 +1079,36 @@ receive_query (void *cls
1061 cls_->hdr.size - sizeof (struct GNUNET_MessageHeader)); 1079 cls_->hdr.size - sizeof (struct GNUNET_MessageHeader));
1062 GNUNET_SCHEDULER_add_now (send_mesh_query, cls_); 1080 GNUNET_SCHEDULER_add_now (send_mesh_query, cls_);
1063 1081
1064 if (ntohs(pdns->s.qdcount) == 1) 1082 if (ntohs (pdns->s.qdcount) == 1)
1083 {
1084 if (ntohs (pdns->queries[0]->qtype) == 1)
1085 pdns->queries[0]->qtype = htons (28);
1086 else if (ntohs (pdns->queries[0]->qtype) == 28)
1087 pdns->queries[0]->qtype = htons (1);
1088 else
1065 { 1089 {
1066 if (ntohs(pdns->queries[0]->qtype) == 1) 1090 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "not sending second packet\n");
1067 pdns->queries[0]->qtype = htons(28); 1091 goto outfree;
1068 else if (ntohs(pdns->queries[0]->qtype) == 28) 1092 }
1069 pdns->queries[0]->qtype = htons(1); 1093 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending second packet\n");
1070 else 1094 struct dns_pkt *rdns = unparse_dns_packet (pdns);
1071{ 1095 size_t size =
1072 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "not sending second packet\n");
1073 goto outfree;
1074}
1075 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "sending second packet\n");
1076 struct dns_pkt *rdns = unparse_dns_packet (pdns);
1077 size_t size =
1078 sizeof (struct GNUNET_MESH_Tunnel *) + 1096 sizeof (struct GNUNET_MESH_Tunnel *) +
1079 sizeof (struct GNUNET_MessageHeader) + (ntohs (message->size) - 1097 sizeof (struct GNUNET_MessageHeader) + (ntohs (message->size) -
1080 sizeof (struct query_packet) + 1098 sizeof (struct query_packet) +
1081 1); 1099 1);
1082 struct tunnel_cls *cls_ = GNUNET_malloc (size); 1100 struct tunnel_cls *cls_ = GNUNET_malloc (size);
1083 1101
1084 cls_->hdr.size = size - sizeof (struct GNUNET_MESH_Tunnel *); 1102 cls_->hdr.size = size - sizeof (struct GNUNET_MESH_Tunnel *);
1085 1103
1086 cls_->hdr.type = ntohs (GNUNET_MESSAGE_TYPE_VPN_REMOTE_QUERY_DNS); 1104 cls_->hdr.type = ntohs (GNUNET_MESSAGE_TYPE_VPN_REMOTE_QUERY_DNS);
1087 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "size: %d\n", size); 1105 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "size: %d\n", size);
1088 1106
1089 memcpy (&cls_->dns, rdns, 1107 memcpy (&cls_->dns, rdns,
1090 cls_->hdr.size - sizeof (struct GNUNET_MessageHeader)); 1108 cls_->hdr.size - sizeof (struct GNUNET_MessageHeader));
1091 GNUNET_SCHEDULER_add_now (send_mesh_query, cls_); 1109 GNUNET_SCHEDULER_add_now (send_mesh_query, cls_);
1092 GNUNET_free (rdns); 1110 GNUNET_free (rdns);
1093 } 1111 }
1094 1112
1095 goto outfree; 1113 goto outfree;
1096 } 1114 }
@@ -1098,31 +1116,31 @@ receive_query (void *cls
1098 1116
1099 /* The query should be sent to the network */ 1117 /* The query should be sent to the network */
1100 if (pkt->addrlen == 4) 1118 if (pkt->addrlen == 4)
1101 { 1119 {
1102 struct sockaddr_in dest; 1120 struct sockaddr_in dest;
1103 1121
1104 memset (&dest, 0, sizeof dest); 1122 memset (&dest, 0, sizeof dest);
1105 dest.sin_port = htons (53); 1123 dest.sin_port = htons (53);
1106 memcpy(&dest.sin_addr.s_addr, pkt->orig_to, pkt->addrlen); 1124 memcpy (&dest.sin_addr.s_addr, pkt->orig_to, pkt->addrlen);
1107 1125
1108 GNUNET_NETWORK_socket_sendto (dnsout, dns, 1126 GNUNET_NETWORK_socket_sendto (dnsout, dns,
1109 ntohs (pkt->hdr.size) - 1127 ntohs (pkt->hdr.size) -
1110 sizeof (struct query_packet) + 1, 1128 sizeof (struct query_packet) + 1,
1111 (struct sockaddr *) &dest, sizeof dest); 1129 (struct sockaddr *) &dest, sizeof dest);
1112 } 1130 }
1113 else if (pkt->addrlen == 16) 1131 else if (pkt->addrlen == 16)
1114 { 1132 {
1115 struct sockaddr_in6 dest; 1133 struct sockaddr_in6 dest;
1116 1134
1117 memset (&dest, 0, sizeof dest); 1135 memset (&dest, 0, sizeof dest);
1118 dest.sin6_port = htons (53); 1136 dest.sin6_port = htons (53);
1119 memcpy(&dest.sin6_addr, pkt->orig_to, pkt->addrlen); 1137 memcpy (&dest.sin6_addr, pkt->orig_to, pkt->addrlen);
1120 1138
1121 GNUNET_NETWORK_socket_sendto (dnsout6, dns, 1139 GNUNET_NETWORK_socket_sendto (dnsout6, dns,
1122 ntohs (pkt->hdr.size) - 1140 ntohs (pkt->hdr.size) -
1123 sizeof (struct query_packet) + 1, 1141 sizeof (struct query_packet) + 1,
1124 (struct sockaddr *) &dest, sizeof dest); 1142 (struct sockaddr *) &dest, sizeof dest);
1125 } 1143 }
1126 1144
1127outfree: 1145outfree:
1128 free_parsed_dns_packet (pdns); 1146 free_parsed_dns_packet (pdns);
@@ -1144,10 +1162,10 @@ open_port6 ()
1144 1162
1145 dnsout6 = GNUNET_NETWORK_socket_create (AF_INET6, SOCK_DGRAM, 0); 1163 dnsout6 = GNUNET_NETWORK_socket_create (AF_INET6, SOCK_DGRAM, 0);
1146 if (dnsout6 == NULL) 1164 if (dnsout6 == NULL)
1147 { 1165 {
1148 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not create socket: %m\n"); 1166 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not create socket: %m\n");
1149 return GNUNET_SYSERR; 1167 return GNUNET_SYSERR;
1150 } 1168 }
1151 memset (&addr, 0, sizeof (struct sockaddr_in6)); 1169 memset (&addr, 0, sizeof (struct sockaddr_in6));
1152 1170
1153 addr.sin6_family = AF_INET6; 1171 addr.sin6_family = AF_INET6;
@@ -1205,7 +1223,9 @@ open_port ()
1205 return GNUNET_YES; 1223 return GNUNET_YES;
1206} 1224}
1207 1225
1208void handle_response(struct dns_pkt* dns, struct sockaddr *addr, socklen_t addrlen, int r); 1226void
1227handle_response (struct dns_pkt *dns, struct sockaddr *addr, socklen_t addrlen,
1228 int r);
1209 1229
1210/** 1230/**
1211 * Read a response-packet of the UDP-Socket 1231 * Read a response-packet of the UDP-Socket
@@ -1228,7 +1248,7 @@ read_response6 (void *cls
1228#ifndef MINGW 1248#ifndef MINGW
1229 if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout6), FIONREAD, &len)) 1249 if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout6), FIONREAD, &len))
1230 { 1250 {
1231 (void)open_port6 (); 1251 (void) open_port6 ();
1232 return; 1252 return;
1233 } 1253 }
1234#else 1254#else
@@ -1243,14 +1263,15 @@ read_response6 (void *cls
1243 (struct sockaddr *) &addr, &addrlen); 1263 (struct sockaddr *) &addr, &addrlen);
1244 1264
1245 if (r < 0) 1265 if (r < 0)
1246 { 1266 {
1247 (void)open_port6 (); 1267 (void) open_port6 ();
1248 return; 1268 return;
1249 } 1269 }
1270
1271 struct sockaddr *addr_ = GNUNET_malloc (sizeof addr);
1250 1272
1251 struct sockaddr *addr_ = GNUNET_malloc(sizeof addr);
1252 memcpy (addr_, &addr, sizeof addr); 1273 memcpy (addr_, &addr, sizeof addr);
1253 handle_response(dns, addr_, 4, r); 1274 handle_response (dns, addr_, 4, r);
1254 1275
1255 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, dnsout6, 1276 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, dnsout6,
1256 &read_response6, NULL); 1277 &read_response6, NULL);
@@ -1277,8 +1298,7 @@ read_response (void *cls
1277#ifndef MINGW 1298#ifndef MINGW
1278 if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout), FIONREAD, &len)) 1299 if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout), FIONREAD, &len))
1279 { 1300 {
1280 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 1301 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "ioctl");
1281 "ioctl");
1282 unhijack (dnsoutport); 1302 unhijack (dnsoutport);
1283 if (GNUNET_YES == open_port ()) 1303 if (GNUNET_YES == open_port ())
1284 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &hijack, NULL); 1304 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &hijack, NULL);
@@ -1296,114 +1316,118 @@ read_response (void *cls
1296 (struct sockaddr *) &addr, &addrlen); 1316 (struct sockaddr *) &addr, &addrlen);
1297 1317
1298 if (r < 0) 1318 if (r < 0)
1299 { 1319 {
1300 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 1320 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom");
1301 "recvfrom"); 1321 unhijack (dnsoutport);
1302 unhijack (dnsoutport); 1322 if (GNUNET_YES == open_port ())
1303 if (GNUNET_YES == open_port ()) 1323 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &hijack, NULL);
1304 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &hijack, NULL); 1324 return;
1305 return; 1325 }
1306 } 1326
1327 struct sockaddr *addr_ = GNUNET_malloc (sizeof addr);
1307 1328
1308 struct sockaddr *addr_ = GNUNET_malloc(sizeof addr);
1309 memcpy (addr_, &addr, sizeof addr); 1329 memcpy (addr_, &addr, sizeof addr);
1310 handle_response(dns, addr_, 4, r); 1330 handle_response (dns, addr_, 4, r);
1311 1331
1312 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, dnsout, 1332 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, dnsout,
1313 &read_response, NULL); 1333 &read_response, NULL);
1314} 1334}
1315 1335
1316void 1336void
1317handle_response(struct dns_pkt* dns, struct sockaddr *addr, socklen_t addrlen, int r) 1337handle_response (struct dns_pkt *dns, struct sockaddr *addr, socklen_t addrlen,
1338 int r)
1318{ 1339{
1319 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Answer to query %d\n", 1340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Answer to query %d\n",
1320 ntohs (dns->s.id)); 1341 ntohs (dns->s.id));
1321 1342
1322 1343
1323 if (query_states[dns->s.id].valid == GNUNET_YES) 1344 if (query_states[dns->s.id].valid == GNUNET_YES)
1345 {
1346 if (query_states[dns->s.id].tunnel != NULL)
1347 {
1348 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1349 "Answer to query %d for a remote peer!\n", ntohs (dns->s.id));
1350 /* This response should go through a tunnel */
1351 uint32_t *c =
1352 GNUNET_malloc (4 + sizeof (struct GNUNET_MESH_Tunnel *) + r);
1353 *c = r;
1354 struct GNUNET_MESH_Tunnel **t = (struct GNUNET_MESH_Tunnel **) (c + 1);
1355
1356 *t = query_states[dns->s.id].tunnel;
1357 memcpy (t + 1, dns, r);
1358 struct tunnel_state *s =
1359 GNUNET_MESH_tunnel_get_data (query_states[dns->s.id].tunnel);
1360 if (NULL == s->th)
1361 {
1362 s->th =
1363 GNUNET_MESH_notify_transmit_ready (query_states[dns->s.id].tunnel,
1364 GNUNET_YES, 32,
1365 GNUNET_TIME_UNIT_MINUTES, NULL,
1366 r +
1367 sizeof (struct
1368 GNUNET_MessageHeader),
1369 mesh_send_response, c);
1370 }
1371 else
1372 {
1373 struct tunnel_notify_queue *element =
1374 GNUNET_malloc (sizeof (struct tunnel_notify_queue));
1375 element->cls = c;
1376 element->len = r + sizeof (struct GNUNET_MessageHeader);
1377 element->cb = mesh_send_response;
1378
1379 GNUNET_CONTAINER_DLL_insert_tail (s->head, s->tail, element);
1380 }
1381 }
1382 else
1324 { 1383 {
1325 if (query_states[dns->s.id].tunnel != NULL) 1384 query_states[dns->s.id].valid = GNUNET_NO;
1326 { 1385
1327 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1386 size_t len = sizeof (struct answer_packet) + r - 1; /* 1 for the unsigned char data[1]; */
1328 "Answer to query %d for a remote peer!\n", 1387 struct answer_packet_list *answer =
1329 ntohs (dns->s.id)); 1388 GNUNET_malloc (len + sizeof (struct answer_packet_list) -
1330 /* This response should go through a tunnel */ 1389 (sizeof (struct answer_packet)));
1331 uint32_t *c = 1390 answer->pkt.hdr.type =
1332 GNUNET_malloc (4 + sizeof (struct GNUNET_MESH_Tunnel *) + r); 1391 htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS);
1333 *c = r; 1392 answer->pkt.hdr.size = htons (len);
1334 struct GNUNET_MESH_Tunnel **t = (struct GNUNET_MESH_Tunnel **) (c + 1); 1393 answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_IP;
1335 1394 answer->pkt.addrlen = addrlen;
1336 *t = query_states[dns->s.id].tunnel; 1395 if (addrlen == 16)
1337 memcpy (t + 1, dns, r); 1396 {
1338 struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (query_states[dns->s.id].tunnel); 1397 struct sockaddr_in6 *addr_ = (struct sockaddr_in6 *) addr;
1339 if (NULL == s->th) 1398
1340 { 1399 memcpy (answer->pkt.from, &addr_->sin6_addr, addrlen);
1341 s->th = 1400 memcpy (answer->pkt.to, query_states[dns->s.id].local_ip, addrlen);
1342 GNUNET_MESH_notify_transmit_ready (query_states[dns->s.id].tunnel, 1401 }
1343 GNUNET_YES, 1402 else if (addrlen == 4)
1344 32, 1403 {
1345 GNUNET_TIME_UNIT_MINUTES, 1404 struct sockaddr_in *addr_ = (struct sockaddr_in *) addr;
1346 NULL, 1405
1347 r + 1406 memcpy (answer->pkt.from, &addr_->sin_addr.s_addr, addrlen);
1348 sizeof (struct 1407 memcpy (answer->pkt.to, query_states[dns->s.id].local_ip, addrlen);
1349 GNUNET_MessageHeader), 1408 }
1350 mesh_send_response, c);
1351 }
1352 else
1353 {
1354 struct tunnel_notify_queue *element =
1355 GNUNET_malloc (sizeof (struct tunnel_notify_queue));
1356 element->cls = c;
1357 element->len = r + sizeof (struct GNUNET_MessageHeader);
1358 element->cb = mesh_send_response;
1359
1360 GNUNET_CONTAINER_DLL_insert_tail (s->head, s->tail, element);
1361 }
1362 }
1363 else 1409 else
1364 { 1410 {
1365 query_states[dns->s.id].valid = GNUNET_NO; 1411 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "addrlen = %d\n", addrlen);
1366 1412 GNUNET_assert (0);
1367 size_t len = sizeof (struct answer_packet) + r - 1; /* 1 for the unsigned char data[1]; */ 1413 }
1368 struct answer_packet_list *answer = 1414 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending answer with addrlen = %d\n",
1369 GNUNET_malloc (len + sizeof(struct answer_packet_list) - (sizeof(struct answer_packet))); 1415 addrlen);
1370 answer->pkt.hdr.type = 1416 answer->pkt.dst_port = query_states[dns->s.id].local_port;
1371 htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS); 1417 memcpy (answer->pkt.data, dns, r);
1372 answer->pkt.hdr.size = htons (len); 1418 answer->client = query_states[dns->s.id].client;
1373 answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_IP; 1419
1374 answer->pkt.addrlen = addrlen; 1420 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer);
1375 if (addrlen == 16) 1421
1376 { 1422 if (server_notify == NULL)
1377 struct sockaddr_in6 *addr_ = (struct sockaddr_in6*)addr; 1423 server_notify =
1378 memcpy(answer->pkt.from, &addr_->sin6_addr, addrlen); 1424 GNUNET_SERVER_notify_transmit_ready (query_states[dns->s.id].client,
1379 memcpy(answer->pkt.to, query_states[dns->s.id].local_ip, addrlen); 1425 len,
1380 } 1426 GNUNET_TIME_UNIT_FOREVER_REL,
1381 else if (addrlen == 4) 1427 &send_answer, NULL);
1382 {
1383 struct sockaddr_in *addr_ = (struct sockaddr_in*)addr;
1384 memcpy(answer->pkt.from, &addr_->sin_addr.s_addr, addrlen);
1385 memcpy(answer->pkt.to, query_states[dns->s.id].local_ip, addrlen);
1386 }
1387 else
1388 {
1389 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "addrlen = %d\n", addrlen);
1390 GNUNET_assert(0);
1391 }
1392 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "sending answer with addrlen = %d\n", addrlen);
1393 answer->pkt.dst_port = query_states[dns->s.id].local_port;
1394 memcpy (answer->pkt.data, dns, r);
1395 answer->client = query_states[dns->s.id].client;
1396
1397 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer);
1398
1399 if (server_notify == NULL)
1400 server_notify = GNUNET_SERVER_notify_transmit_ready (query_states[dns->s.id].client,
1401 len, GNUNET_TIME_UNIT_FOREVER_REL,
1402 &send_answer,
1403 NULL);
1404 }
1405 } 1428 }
1406 GNUNET_free(addr); 1429 }
1430 GNUNET_free (addr);
1407} 1431}
1408 1432
1409 1433
@@ -1535,8 +1559,9 @@ publish_name (const char *name, uint64_t ports, uint32_t service_type,
1535 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &data.peer); 1559 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &data.peer);
1536 1560
1537 data.expiration_time = 1561 data.expiration_time =
1538 GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply 1562 GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute
1539 (GNUNET_TIME_UNIT_HOURS, 2))); 1563 (GNUNET_TIME_relative_multiply
1564 (GNUNET_TIME_UNIT_HOURS, 2)));
1540 1565
1541 /* Sign the block */ 1566 /* Sign the block */
1542 if (GNUNET_OK != 1567 if (GNUNET_OK !=
@@ -1549,7 +1574,8 @@ publish_name (const char *name, uint64_t ports, uint32_t service_type,
1549 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting with key %08x, size = %d\n", 1574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting with key %08x, size = %d\n",
1550 *((unsigned int *) &data.service_descriptor), size); 1575 *((unsigned int *) &data.service_descriptor), size);
1551 1576
1552 GNUNET_DHT_put (dht, &data.service_descriptor, 5 /* DEFAULT_PUT_REPLICATION */, 1577 GNUNET_DHT_put (dht, &data.service_descriptor,
1578 5 /* DEFAULT_PUT_REPLICATION */ ,
1553 GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_DNS, size, 1579 GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_DNS, size,
1554 (char *) &data, 1580 (char *) &data,
1555 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS), 1581 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS),
@@ -1694,13 +1720,15 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1694 if (GNUNET_YES == 1720 if (GNUNET_YES ==
1695 GNUNET_CONFIGURATION_get_value_yesno (cfg_, "dns", "PROVIDE_EXIT")) 1721 GNUNET_CONFIGURATION_get_value_yesno (cfg_, "dns", "PROVIDE_EXIT"))
1696 apptypes[0] = GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER; 1722 apptypes[0] = GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER;
1697 mesh_handle = GNUNET_MESH_connect (cfg_, 42, NULL, new_tunnel, clean_tunnel, mesh_handlers, apptypes); 1723 mesh_handle =
1724 GNUNET_MESH_connect (cfg_, 42, NULL, new_tunnel, clean_tunnel,
1725 mesh_handlers, apptypes);
1698 1726
1699 cfg = cfg_; 1727 cfg = cfg_;
1700 dht = GNUNET_DHT_connect (cfg, 1024); 1728 dht = GNUNET_DHT_connect (cfg, 1024);
1701 GNUNET_SCHEDULER_add_now (publish_names, NULL); 1729 GNUNET_SCHEDULER_add_now (publish_names, NULL);
1702 GNUNET_SERVER_add_handlers (server, handlers); 1730 GNUNET_SERVER_add_handlers (server, handlers);
1703 GNUNET_SERVER_disconnect_notify(server, &client_disconnect, NULL); 1731 GNUNET_SERVER_disconnect_notify (server, &client_disconnect, NULL);
1704 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, 1732 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
1705 cls); 1733 cls);
1706} 1734}